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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u143492911 | p03767 | python | s673075688 | s304295495 | 230 | 211 | 37,084 | 37,084 | Accepted | Accepted | 8.26 | n=int(eval(input()))
a=list(map(int,input().split()))
a.sort()
a.reverse()
total=0
for i in range(n):
total+=a[i*2+1]
print(total) | n=int(eval(input()))
a=list(map(int,input().split()))
a.sort()
print((sum(a[n::2]))) | 8 | 4 | 135 | 79 | n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
a.reverse()
total = 0
for i in range(n):
total += a[i * 2 + 1]
print(total)
| n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
print((sum(a[n::2])))
| false | 50 | [
"-a.reverse()",
"-total = 0",
"-for i in range(n):",
"- total += a[i * 2 + 1]",
"-print(total)",
"+print((sum(a[n::2])))"
] | false | 0.109398 | 0.008341 | 13.115262 | [
"s673075688",
"s304295495"
] |
u462831976 | p02265 | python | s545227861 | s362877685 | 4,770 | 1,510 | 47,960 | 214,392 | Accepted | Accepted | 68.34 | # -*- coding: utf-8 -*-
import sys
import os
from collections import deque
N = int(eval(input()))
q = deque()
for i in range(N):
lst = input().split()
command = lst[0]
if command == 'insert':
v = int(lst[1])
q.appendleft(v)
elif command == 'delete':
v = int(lst[1])
try:
q.remove(v)
except Exception:
pass
elif command == 'deleteFirst':
q.popleft()
elif command == 'deleteLast':
q.pop()
print((*q)) | import sys
from collections import deque
n = int(sys.stdin.readline())
lines = sys.stdin.readlines()
Q = deque()
for i in range(n):
command = lines[i].split()
if command[0] == "insert":
Q.appendleft(command[1])
elif command[0] == "deleteFirst":
Q.popleft()
elif command[0] == "deleteLast":
Q.pop()
elif command[0] == "delete":
try:
Q.remove(command[1])
except:
pass
print((" ".join(Q)))
# 0.158sec??§?????????????¢???? | 28 | 22 | 526 | 524 | # -*- coding: utf-8 -*-
import sys
import os
from collections import deque
N = int(eval(input()))
q = deque()
for i in range(N):
lst = input().split()
command = lst[0]
if command == "insert":
v = int(lst[1])
q.appendleft(v)
elif command == "delete":
v = int(lst[1])
try:
q.remove(v)
except Exception:
pass
elif command == "deleteFirst":
q.popleft()
elif command == "deleteLast":
q.pop()
print((*q))
| import sys
from collections import deque
n = int(sys.stdin.readline())
lines = sys.stdin.readlines()
Q = deque()
for i in range(n):
command = lines[i].split()
if command[0] == "insert":
Q.appendleft(command[1])
elif command[0] == "deleteFirst":
Q.popleft()
elif command[0] == "deleteLast":
Q.pop()
elif command[0] == "delete":
try:
Q.remove(command[1])
except:
pass
print((" ".join(Q)))
# 0.158sec??§?????????????¢????
| false | 21.428571 | [
"-# -*- coding: utf-8 -*-",
"-import os",
"-N = int(eval(input()))",
"-q = deque()",
"-for i in range(N):",
"- lst = input().split()",
"- command = lst[0]",
"- if command == \"insert\":",
"- v = int(lst[1])",
"- q.appendleft(v)",
"- elif command == \"delete\":",
"- v = int(lst[1])",
"+n = int(sys.stdin.readline())",
"+lines = sys.stdin.readlines()",
"+Q = deque()",
"+for i in range(n):",
"+ command = lines[i].split()",
"+ if command[0] == \"insert\":",
"+ Q.appendleft(command[1])",
"+ elif command[0] == \"deleteFirst\":",
"+ Q.popleft()",
"+ elif command[0] == \"deleteLast\":",
"+ Q.pop()",
"+ elif command[0] == \"delete\":",
"- q.remove(v)",
"- except Exception:",
"+ Q.remove(command[1])",
"+ except:",
"- elif command == \"deleteFirst\":",
"- q.popleft()",
"- elif command == \"deleteLast\":",
"- q.pop()",
"-print((*q))",
"+print((\" \".join(Q)))",
"+# 0.158sec??§?????????????¢????"
] | false | 0.037818 | 0.038514 | 0.98193 | [
"s545227861",
"s362877685"
] |
u040599127 | p03030 | python | s236774262 | s500679022 | 197 | 170 | 39,920 | 38,256 | Accepted | Accepted | 13.71 | N = int(eval(input()))
S = [None]*N
P = [None]*N
I = [None]*N
for i in range(N):
tmp = input().split()
S[i] = tmp[0]
P[i] = int(tmp[1])
I[i] = i+1
def less(a, b):
if a[0] == b[0]:
if a[1] == b[1]:
return a[2] < b[2]
return a[1] > b[1]
return a[0] < b[0]
for i in range(N):
for j in range(i+1, N):
if not less([S[i], P[i], I[i]], [S[j], P[j], I[j]]):
S[i], S[j] = S[j], S[i]
P[i], P[j] = P[j], P[i]
I[i], I[j] = I[j], I[i]
for i in range(N):
print((I[i]))
| N = int(eval(input()))
T = [None]*N
for i in range(N):
tmp = input().split()
T[i] = (tmp[0], -int(tmp[1]), i+1)
T.sort()
for t in T:
print((t[2]))
| 28 | 9 | 583 | 160 | N = int(eval(input()))
S = [None] * N
P = [None] * N
I = [None] * N
for i in range(N):
tmp = input().split()
S[i] = tmp[0]
P[i] = int(tmp[1])
I[i] = i + 1
def less(a, b):
if a[0] == b[0]:
if a[1] == b[1]:
return a[2] < b[2]
return a[1] > b[1]
return a[0] < b[0]
for i in range(N):
for j in range(i + 1, N):
if not less([S[i], P[i], I[i]], [S[j], P[j], I[j]]):
S[i], S[j] = S[j], S[i]
P[i], P[j] = P[j], P[i]
I[i], I[j] = I[j], I[i]
for i in range(N):
print((I[i]))
| N = int(eval(input()))
T = [None] * N
for i in range(N):
tmp = input().split()
T[i] = (tmp[0], -int(tmp[1]), i + 1)
T.sort()
for t in T:
print((t[2]))
| false | 67.857143 | [
"-S = [None] * N",
"-P = [None] * N",
"-I = [None] * N",
"+T = [None] * N",
"- S[i] = tmp[0]",
"- P[i] = int(tmp[1])",
"- I[i] = i + 1",
"-",
"-",
"-def less(a, b):",
"- if a[0] == b[0]:",
"- if a[1] == b[1]:",
"- return a[2] < b[2]",
"- return a[1] > b[1]",
"- return a[0] < b[0]",
"-",
"-",
"-for i in range(N):",
"- for j in range(i + 1, N):",
"- if not less([S[i], P[i], I[i]], [S[j], P[j], I[j]]):",
"- S[i], S[j] = S[j], S[i]",
"- P[i], P[j] = P[j], P[i]",
"- I[i], I[j] = I[j], I[i]",
"-for i in range(N):",
"- print((I[i]))",
"+ T[i] = (tmp[0], -int(tmp[1]), i + 1)",
"+T.sort()",
"+for t in T:",
"+ print((t[2]))"
] | false | 0.076632 | 0.041609 | 1.841714 | [
"s236774262",
"s500679022"
] |
u077291787 | p02595 | python | s855151521 | s677924870 | 222 | 178 | 55,064 | 122,476 | Accepted | Accepted | 19.82 | # B - Distance
from math import sqrt
def main():
N, D, *XY = list(map(int, open(0).read().split()))
res = sum(sqrt(x ** 2 + y ** 2) <= D for x, y in zip(*[iter(XY)] * 2))
print(res)
if __name__ == "__main__":
main()
| # B - Distance
def main():
N, D, *XY = list(map(int, open(0).read().split()))
res = sum(x ** 2 + y ** 2 <= D ** 2 for x, y in zip(*[iter(XY)] * 2))
print(res)
if __name__ == "__main__":
main()
| 12 | 9 | 241 | 213 | # B - Distance
from math import sqrt
def main():
N, D, *XY = list(map(int, open(0).read().split()))
res = sum(sqrt(x**2 + y**2) <= D for x, y in zip(*[iter(XY)] * 2))
print(res)
if __name__ == "__main__":
main()
| # B - Distance
def main():
N, D, *XY = list(map(int, open(0).read().split()))
res = sum(x**2 + y**2 <= D**2 for x, y in zip(*[iter(XY)] * 2))
print(res)
if __name__ == "__main__":
main()
| false | 25 | [
"-from math import sqrt",
"-",
"-",
"- res = sum(sqrt(x**2 + y**2) <= D for x, y in zip(*[iter(XY)] * 2))",
"+ res = sum(x**2 + y**2 <= D**2 for x, y in zip(*[iter(XY)] * 2))"
] | false | 0.062453 | 0.077358 | 0.807316 | [
"s855151521",
"s677924870"
] |
u741397536 | p03027 | python | s462808382 | s434590025 | 1,572 | 1,436 | 63,184 | 72,924 | Accepted | Accepted | 8.65 | Q = int(eval(input()))
mod = 10**6+3
arr = []
for i in range(Q):
x, d, n = list(map(int, input().split()))
arr.append([x, d, n])
P = [1]*(mod+1)
for i in range(mod):
P[i+1] = P[i]*(i+1)%mod
def rev(a):
return pow(a,mod-2,mod)
def f(x, d, n):
if d == 0:
return pow(x, n, mod)
else:
d_r = rev(d)
if d_r * x % mod == 0:
return 0
elif (d_r*x%mod+n-1) >= mod:
return 0
else:
return (P[d_r*x%mod+n-1] * rev(P[d_r*x%mod-1])%mod)*pow(d,n,mod)%mod
for i in range(Q):
print((f(arr[i][0], arr[i][1], arr[i][2])))
| Q = int(eval(input()))
mod = 10**6+3
arr = []
for i in range(Q):
arr.append(list(map(int, input().split())))
P = [1]*(mod+1)
for i in range(mod):
P[i+1] = P[i]*(i+1)%mod
def rev(a):
return pow(a,mod-2,mod)
def f(x, d, n):
if d == 0:
return pow(x, n, mod)
else:
d_r = rev(d)
xdr = d_r * x % mod
if xdr == 0:
return 0
elif (xdr+n-1) >= mod:
return 0
else:
return (P[xdr+n-1] * rev(P[xdr-1])%mod) * pow(d,n,mod)%mod
for i in range(Q):
print((f(arr[i][0], arr[i][1], arr[i][2]))) | 28 | 28 | 623 | 607 | Q = int(eval(input()))
mod = 10**6 + 3
arr = []
for i in range(Q):
x, d, n = list(map(int, input().split()))
arr.append([x, d, n])
P = [1] * (mod + 1)
for i in range(mod):
P[i + 1] = P[i] * (i + 1) % mod
def rev(a):
return pow(a, mod - 2, mod)
def f(x, d, n):
if d == 0:
return pow(x, n, mod)
else:
d_r = rev(d)
if d_r * x % mod == 0:
return 0
elif (d_r * x % mod + n - 1) >= mod:
return 0
else:
return (
(P[d_r * x % mod + n - 1] * rev(P[d_r * x % mod - 1]) % mod)
* pow(d, n, mod)
% mod
)
for i in range(Q):
print((f(arr[i][0], arr[i][1], arr[i][2])))
| Q = int(eval(input()))
mod = 10**6 + 3
arr = []
for i in range(Q):
arr.append(list(map(int, input().split())))
P = [1] * (mod + 1)
for i in range(mod):
P[i + 1] = P[i] * (i + 1) % mod
def rev(a):
return pow(a, mod - 2, mod)
def f(x, d, n):
if d == 0:
return pow(x, n, mod)
else:
d_r = rev(d)
xdr = d_r * x % mod
if xdr == 0:
return 0
elif (xdr + n - 1) >= mod:
return 0
else:
return (P[xdr + n - 1] * rev(P[xdr - 1]) % mod) * pow(d, n, mod) % mod
for i in range(Q):
print((f(arr[i][0], arr[i][1], arr[i][2])))
| false | 0 | [
"- x, d, n = list(map(int, input().split()))",
"- arr.append([x, d, n])",
"+ arr.append(list(map(int, input().split())))",
"- if d_r * x % mod == 0:",
"+ xdr = d_r * x % mod",
"+ if xdr == 0:",
"- elif (d_r * x % mod + n - 1) >= mod:",
"+ elif (xdr + n - 1) >= mod:",
"- return (",
"- (P[d_r * x % mod + n - 1] * rev(P[d_r * x % mod - 1]) % mod)",
"- * pow(d, n, mod)",
"- % mod",
"- )",
"+ return (P[xdr + n - 1] * rev(P[xdr - 1]) % mod) * pow(d, n, mod) % mod"
] | false | 0.726029 | 0.723595 | 1.003364 | [
"s462808382",
"s434590025"
] |
u150984829 | p00510 | python | s742294207 | s566868921 | 50 | 30 | 5,692 | 5,616 | Accepted | Accepted | 40 | n=int(eval(input()))
a=s=int(eval(input()))
b=1
for _ in[0]*n:
i,o=list(map(int,input().split()))
s+=i-o
if s<0:b=0;break
if a<s:a=s
print((a*b))
| import sys
eval(input())
a=s=int(eval(input()))
b=1
for e in sys.stdin:
i,o=list(map(int,e.split()))
s+=i-o
if s<0:b=0;break
if a<s:a=s
print((a*b))
| 9 | 10 | 138 | 142 | n = int(eval(input()))
a = s = int(eval(input()))
b = 1
for _ in [0] * n:
i, o = list(map(int, input().split()))
s += i - o
if s < 0:
b = 0
break
if a < s:
a = s
print((a * b))
| import sys
eval(input())
a = s = int(eval(input()))
b = 1
for e in sys.stdin:
i, o = list(map(int, e.split()))
s += i - o
if s < 0:
b = 0
break
if a < s:
a = s
print((a * b))
| false | 10 | [
"-n = int(eval(input()))",
"+import sys",
"+",
"+eval(input())",
"-for _ in [0] * n:",
"- i, o = list(map(int, input().split()))",
"+for e in sys.stdin:",
"+ i, o = list(map(int, e.split()))"
] | false | 0.047661 | 0.047772 | 0.997683 | [
"s742294207",
"s566868921"
] |
u380772254 | p02744 | python | s836258812 | s760309889 | 612 | 376 | 64,856 | 55,768 | Accepted | Accepted | 38.56 | import sys
def I(): return int(sys.stdin.readline())
def MI(): return list(map(int, sys.stdin.readline().split()))
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
s = 'abcdefghijklmnop'
N = I()
for c1 in range(1):
if N == 1:
print((s[c1]))
continue
for c2 in range(2):
if N == 2:
print((s[c1]+s[c2]))
continue
for c3 in range(max(c1, c2) + 2):
if N == 3:
print((s[c1] + s[c2] + s[c3]))
continue
for c4 in range(max(c1, c2, c3) + 2):
if N == 4:
print((s[c1] + s[c2] + s[c3] + s[c4]))
continue
for c5 in range(max(c1, c2, c3, c4) + 2):
if N == 5:
print((s[c1] + s[c2] + s[c3] + s[c4] + s[c5] ))
continue
for c6 in range(max(c1, c2, c3, c4, c5) + 2):
if N == 6:
print((s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6]))
continue
for c7 in range(max(c1, c2, c3, c4, c5, c6) + 2):
if N == 7:
print((s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6] + s[c7] ))
continue
for c8 in range(max(c1, c2, c3, c4, c5, c6, c7) + 2):
if N == 8:
print((s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6] + s[c7] + s[c8]))
continue
for c9 in range(max(c1, c2, c3, c4, c5, c6, c7, c8) + 2):
if N == 9:
print((s[c1]+s[c2]+s[c3]+s[c4]+s[c5]+s[c6]+s[c7]+s[c8]+s[c9]))
continue
for c10 in range(max(c1, c2, c3, c4, c5, c6, c7, c8, c9) + 2):
print((s[c1]+s[c2]+s[c3]+s[c4]+s[c5]+s[c6]+s[c7]+s[c8]+s[c9]+s[c10]))
| import sys
def I(): return int(sys.stdin.readline())
def MI(): return list(map(int, sys.stdin.readline().split()))
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
s = 'abcdefghijklmnop'
N = I()
def f(n, seq, m):
for i in range(m + 1):
if n == N:
print((seq + s[i]))
else:
f(n + 1, seq + s[i], max(m, i + 1))
f(1, '', 0)
| 55 | 21 | 2,179 | 416 | import sys
def I():
return int(sys.stdin.readline())
def MI():
return list(map(int, sys.stdin.readline().split()))
def LMI():
return list(map(int, sys.stdin.readline().split()))
MOD = 10**9 + 7
s = "abcdefghijklmnop"
N = I()
for c1 in range(1):
if N == 1:
print((s[c1]))
continue
for c2 in range(2):
if N == 2:
print((s[c1] + s[c2]))
continue
for c3 in range(max(c1, c2) + 2):
if N == 3:
print((s[c1] + s[c2] + s[c3]))
continue
for c4 in range(max(c1, c2, c3) + 2):
if N == 4:
print((s[c1] + s[c2] + s[c3] + s[c4]))
continue
for c5 in range(max(c1, c2, c3, c4) + 2):
if N == 5:
print((s[c1] + s[c2] + s[c3] + s[c4] + s[c5]))
continue
for c6 in range(max(c1, c2, c3, c4, c5) + 2):
if N == 6:
print((s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6]))
continue
for c7 in range(max(c1, c2, c3, c4, c5, c6) + 2):
if N == 7:
print(
(
s[c1]
+ s[c2]
+ s[c3]
+ s[c4]
+ s[c5]
+ s[c6]
+ s[c7]
)
)
continue
for c8 in range(max(c1, c2, c3, c4, c5, c6, c7) + 2):
if N == 8:
print(
(
s[c1]
+ s[c2]
+ s[c3]
+ s[c4]
+ s[c5]
+ s[c6]
+ s[c7]
+ s[c8]
)
)
continue
for c9 in range(
max(c1, c2, c3, c4, c5, c6, c7, c8) + 2
):
if N == 9:
print(
(
s[c1]
+ s[c2]
+ s[c3]
+ s[c4]
+ s[c5]
+ s[c6]
+ s[c7]
+ s[c8]
+ s[c9]
)
)
continue
for c10 in range(
max(c1, c2, c3, c4, c5, c6, c7, c8, c9) + 2
):
print(
(
s[c1]
+ s[c2]
+ s[c3]
+ s[c4]
+ s[c5]
+ s[c6]
+ s[c7]
+ s[c8]
+ s[c9]
+ s[c10]
)
)
| import sys
def I():
return int(sys.stdin.readline())
def MI():
return list(map(int, sys.stdin.readline().split()))
def LMI():
return list(map(int, sys.stdin.readline().split()))
MOD = 10**9 + 7
s = "abcdefghijklmnop"
N = I()
def f(n, seq, m):
for i in range(m + 1):
if n == N:
print((seq + s[i]))
else:
f(n + 1, seq + s[i], max(m, i + 1))
f(1, "", 0)
| false | 61.818182 | [
"-for c1 in range(1):",
"- if N == 1:",
"- print((s[c1]))",
"- continue",
"- for c2 in range(2):",
"- if N == 2:",
"- print((s[c1] + s[c2]))",
"- continue",
"- for c3 in range(max(c1, c2) + 2):",
"- if N == 3:",
"- print((s[c1] + s[c2] + s[c3]))",
"- continue",
"- for c4 in range(max(c1, c2, c3) + 2):",
"- if N == 4:",
"- print((s[c1] + s[c2] + s[c3] + s[c4]))",
"- continue",
"- for c5 in range(max(c1, c2, c3, c4) + 2):",
"- if N == 5:",
"- print((s[c1] + s[c2] + s[c3] + s[c4] + s[c5]))",
"- continue",
"- for c6 in range(max(c1, c2, c3, c4, c5) + 2):",
"- if N == 6:",
"- print((s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6]))",
"- continue",
"- for c7 in range(max(c1, c2, c3, c4, c5, c6) + 2):",
"- if N == 7:",
"- print(",
"- (",
"- s[c1]",
"- + s[c2]",
"- + s[c3]",
"- + s[c4]",
"- + s[c5]",
"- + s[c6]",
"- + s[c7]",
"- )",
"- )",
"- continue",
"- for c8 in range(max(c1, c2, c3, c4, c5, c6, c7) + 2):",
"- if N == 8:",
"- print(",
"- (",
"- s[c1]",
"- + s[c2]",
"- + s[c3]",
"- + s[c4]",
"- + s[c5]",
"- + s[c6]",
"- + s[c7]",
"- + s[c8]",
"- )",
"- )",
"- continue",
"- for c9 in range(",
"- max(c1, c2, c3, c4, c5, c6, c7, c8) + 2",
"- ):",
"- if N == 9:",
"- print(",
"- (",
"- s[c1]",
"- + s[c2]",
"- + s[c3]",
"- + s[c4]",
"- + s[c5]",
"- + s[c6]",
"- + s[c7]",
"- + s[c8]",
"- + s[c9]",
"- )",
"- )",
"- continue",
"- for c10 in range(",
"- max(c1, c2, c3, c4, c5, c6, c7, c8, c9) + 2",
"- ):",
"- print(",
"- (",
"- s[c1]",
"- + s[c2]",
"- + s[c3]",
"- + s[c4]",
"- + s[c5]",
"- + s[c6]",
"- + s[c7]",
"- + s[c8]",
"- + s[c9]",
"- + s[c10]",
"- )",
"- )",
"+",
"+",
"+def f(n, seq, m):",
"+ for i in range(m + 1):",
"+ if n == N:",
"+ print((seq + s[i]))",
"+ else:",
"+ f(n + 1, seq + s[i], max(m, i + 1))",
"+",
"+",
"+f(1, \"\", 0)"
] | false | 0.038542 | 0.038009 | 1.014014 | [
"s836258812",
"s760309889"
] |
u548624367 | p03329 | python | s486604885 | s355213028 | 593 | 271 | 6,296 | 2,940 | Accepted | Accepted | 54.3 | n = int(eval(input()))
v = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
dp = [float("inf") for i in range(n+1)]
dp[0] = 0
for i in range(n):
for j in v:
if i + j <= n:
dp[i+j] = min(dp[i+j], dp[i]+1)
print(("{}".format(dp[n])))
| def ds(a, b):
return a if a<b else ds(a//b,b)+a%b
ans = float('inf')
n = int(eval(input()))
for i in range(n+1):
ans = min(ans,ds(i,6)+ds(n-i,9))
print(ans) | 9 | 7 | 238 | 158 | n = int(eval(input()))
v = [1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049]
dp = [float("inf") for i in range(n + 1)]
dp[0] = 0
for i in range(n):
for j in v:
if i + j <= n:
dp[i + j] = min(dp[i + j], dp[i] + 1)
print(("{}".format(dp[n])))
| def ds(a, b):
return a if a < b else ds(a // b, b) + a % b
ans = float("inf")
n = int(eval(input()))
for i in range(n + 1):
ans = min(ans, ds(i, 6) + ds(n - i, 9))
print(ans)
| false | 22.222222 | [
"+def ds(a, b):",
"+ return a if a < b else ds(a // b, b) + a % b",
"+",
"+",
"+ans = float(\"inf\")",
"-v = [1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049]",
"-dp = [float(\"inf\") for i in range(n + 1)]",
"-dp[0] = 0",
"-for i in range(n):",
"- for j in v:",
"- if i + j <= n:",
"- dp[i + j] = min(dp[i + j], dp[i] + 1)",
"-print((\"{}\".format(dp[n])))",
"+for i in range(n + 1):",
"+ ans = min(ans, ds(i, 6) + ds(n - i, 9))",
"+print(ans)"
] | false | 0.10566 | 0.121997 | 0.866087 | [
"s486604885",
"s355213028"
] |
u959682820 | p02642 | python | s549429084 | s384135331 | 1,323 | 596 | 32,300 | 31,896 | Accepted | Accepted | 54.95 | n = int(eval(input()))
a = list(map(int, input().split()))
MAX = 1000005
cnt = [0] * MAX
for x in a:
if cnt[x] > 2:
continue
#cnt配列の各倍数のところに+1
for i in range(x, MAX, x):
cnt[i] += 1
ans = 0
for x in a:
if cnt[x] == 1:
ans += 1
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
MAX = 1000005
cnt = [0] * MAX
for x in a:
if cnt[x] != 0:
cnt[x] = 2
continue
#cnt配列の各倍数のところに+1
for i in range(x, MAX, x):
cnt[i] += 1
ans = 0
for x in a:
if cnt[x] == 1:
ans += 1
print(ans) | 17 | 18 | 289 | 310 | n = int(eval(input()))
a = list(map(int, input().split()))
MAX = 1000005
cnt = [0] * MAX
for x in a:
if cnt[x] > 2:
continue
# cnt配列の各倍数のところに+1
for i in range(x, MAX, x):
cnt[i] += 1
ans = 0
for x in a:
if cnt[x] == 1:
ans += 1
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
MAX = 1000005
cnt = [0] * MAX
for x in a:
if cnt[x] != 0:
cnt[x] = 2
continue
# cnt配列の各倍数のところに+1
for i in range(x, MAX, x):
cnt[i] += 1
ans = 0
for x in a:
if cnt[x] == 1:
ans += 1
print(ans)
| false | 5.555556 | [
"- if cnt[x] > 2:",
"+ if cnt[x] != 0:",
"+ cnt[x] = 2"
] | false | 0.23989 | 0.15766 | 1.521562 | [
"s549429084",
"s384135331"
] |
u580697892 | p02899 | python | s687130739 | s203451612 | 337 | 291 | 23,348 | 24,128 | Accepted | Accepted | 13.65 | # coding: utf-8
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
A[i] = [A[i]]
A[i].append(i+1)
A.sort(key=lambda x: x[0])
for i in range(N):
print(A[i][1], end=" ")
| # coding: utf-8
N = int(input())
A = list(map(int, input().split()))
ans = [[i+1] for i in range(N)]
for i in range(N):
ans[i].append(A[i])
ans.sort(key=lambda x: x[1])
for i in range(N):
print(ans[i][0], end=" ")
| 9 | 9 | 208 | 229 | # coding: utf-8
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
A[i] = [A[i]]
A[i].append(i + 1)
A.sort(key=lambda x: x[0])
for i in range(N):
print(A[i][1], end=" ")
| # coding: utf-8
N = int(input())
A = list(map(int, input().split()))
ans = [[i + 1] for i in range(N)]
for i in range(N):
ans[i].append(A[i])
ans.sort(key=lambda x: x[1])
for i in range(N):
print(ans[i][0], end=" ")
| false | 0 | [
"+ans = [[i + 1] for i in range(N)]",
"- A[i] = [A[i]]",
"- A[i].append(i + 1)",
"-A.sort(key=lambda x: x[0])",
"+ ans[i].append(A[i])",
"+ans.sort(key=lambda x: x[1])",
"- print(A[i][1], end=\" \")",
"+ print(ans[i][0], end=\" \")"
] | false | 0.044643 | 0.047231 | 0.945198 | [
"s687130739",
"s203451612"
] |
u631277801 | p03637 | python | s503305005 | s210204870 | 85 | 65 | 14,228 | 14,168 | Accepted | Accepted | 23.53 | N = int(eval(input()))
A = list(map(int, input().split()))
odds = []
bai4 = []
for i in range(N):
odds.append(A[i]%2 == 1)
bai4.append(A[i]%4 == 0)
odd = sum(odds)
bi4 = sum(bai4)
bi2 = N - odd - bi4
if odd + bool(bi2) > bi4+1:
print("No")
else:
print("Yes") | import sys
stdin = sys.stdin
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
n = ni()
a = list(li())
mod2 = 0
odd = 0
mod0 = 0
for ai in a:
if ai%4 == 0:
mod0 += 1
elif ai%2 == 0:
mod2 = 1
else:
odd += 1
odd += mod2
if mod0 >= (odd-1):
print("Yes")
else:
print("No") | 18 | 34 | 293 | 677 | N = int(eval(input()))
A = list(map(int, input().split()))
odds = []
bai4 = []
for i in range(N):
odds.append(A[i] % 2 == 1)
bai4.append(A[i] % 4 == 0)
odd = sum(odds)
bi4 = sum(bai4)
bi2 = N - odd - bi4
if odd + bool(bi2) > bi4 + 1:
print("No")
else:
print("Yes")
| import sys
stdin = sys.stdin
def li():
return list(map(int, stdin.readline().split()))
def li_():
return [int(x) - 1 for x in stdin.readline().split()]
def lf():
return list(map(float, stdin.readline().split()))
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
n = ni()
a = list(li())
mod2 = 0
odd = 0
mod0 = 0
for ai in a:
if ai % 4 == 0:
mod0 += 1
elif ai % 2 == 0:
mod2 = 1
else:
odd += 1
odd += mod2
if mod0 >= (odd - 1):
print("Yes")
else:
print("No")
| false | 47.058824 | [
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-odds = []",
"-bai4 = []",
"-for i in range(N):",
"- odds.append(A[i] % 2 == 1)",
"- bai4.append(A[i] % 4 == 0)",
"-odd = sum(odds)",
"-bi4 = sum(bai4)",
"-bi2 = N - odd - bi4",
"-if odd + bool(bi2) > bi4 + 1:",
"+import sys",
"+",
"+stdin = sys.stdin",
"+",
"+",
"+def li():",
"+ return list(map(int, stdin.readline().split()))",
"+",
"+",
"+def li_():",
"+ return [int(x) - 1 for x in stdin.readline().split()]",
"+",
"+",
"+def lf():",
"+ return list(map(float, stdin.readline().split()))",
"+",
"+",
"+def ls():",
"+ return stdin.readline().split()",
"+",
"+",
"+def ns():",
"+ return stdin.readline().rstrip()",
"+",
"+",
"+def lc():",
"+ return list(ns())",
"+",
"+",
"+def ni():",
"+ return int(stdin.readline())",
"+",
"+",
"+def nf():",
"+ return float(stdin.readline())",
"+",
"+",
"+n = ni()",
"+a = list(li())",
"+mod2 = 0",
"+odd = 0",
"+mod0 = 0",
"+for ai in a:",
"+ if ai % 4 == 0:",
"+ mod0 += 1",
"+ elif ai % 2 == 0:",
"+ mod2 = 1",
"+ else:",
"+ odd += 1",
"+odd += mod2",
"+if mod0 >= (odd - 1):",
"+ print(\"Yes\")",
"+else:",
"-else:",
"- print(\"Yes\")"
] | false | 0.039686 | 0.038043 | 1.043174 | [
"s503305005",
"s210204870"
] |
u201234972 | p03700 | python | s808448954 | s516024069 | 1,721 | 596 | 8,948 | 51,816 | Accepted | Accepted | 65.37 | N, A, B = list(map( int, input().split()))
H = [0]*N
hmax = 0
for i in range(N):
h = int( eval(input()))
H[i] = h
hmax = max( h, hmax)
L = 0
R = hmax//B + 1
add = A-B
while L != R:
now = (L+R)//2
need = 0
for i in range(N):
if H[i] > now*B:
need += (H[i]-1-now*B)//add + 1
if need <= now:
R = now
else:
L = now+1
print(L) | N, A, B = list(map( int, input().split()))
H = [0]*N
hmax = 0
for i in range(N):
h = int( eval(input()))
H[i] = h
hmax = max( h, hmax)
L = 0
R = hmax//B + 1
add = A-B
while L != R:
now = (L+R)//2
need = 0
for i in range(N):
if H[i] > now*B:
need += (H[i]-1-now*B)//add + 1
if need <= now:#うまくいくとき
R = now
else:#うまくいかないとき
L = now+1#うまく行かないので+1している.これがないと無限ループが発生する。
print(L) | 22 | 22 | 399 | 451 | N, A, B = list(map(int, input().split()))
H = [0] * N
hmax = 0
for i in range(N):
h = int(eval(input()))
H[i] = h
hmax = max(h, hmax)
L = 0
R = hmax // B + 1
add = A - B
while L != R:
now = (L + R) // 2
need = 0
for i in range(N):
if H[i] > now * B:
need += (H[i] - 1 - now * B) // add + 1
if need <= now:
R = now
else:
L = now + 1
print(L)
| N, A, B = list(map(int, input().split()))
H = [0] * N
hmax = 0
for i in range(N):
h = int(eval(input()))
H[i] = h
hmax = max(h, hmax)
L = 0
R = hmax // B + 1
add = A - B
while L != R:
now = (L + R) // 2
need = 0
for i in range(N):
if H[i] > now * B:
need += (H[i] - 1 - now * B) // add + 1
if need <= now: # うまくいくとき
R = now
else: # うまくいかないとき
L = now + 1 # うまく行かないので+1している.これがないと無限ループが発生する。
print(L)
| false | 0 | [
"- if need <= now:",
"+ if need <= now: # うまくいくとき",
"- else:",
"- L = now + 1",
"+ else: # うまくいかないとき",
"+ L = now + 1 # うまく行かないので+1している.これがないと無限ループが発生する。"
] | false | 0.085062 | 0.04643 | 1.832021 | [
"s808448954",
"s516024069"
] |
u171366497 | p03734 | python | s829814727 | s787830093 | 177 | 36 | 3,064 | 3,064 | Accepted | Accepted | 79.66 | N,W=list(map(int,input().split()))
w0,v=list(map(int,input().split()))
goods=[[v],[],[],[]]
for i in range(N-1):
w,v=list(map(int,input().split()))
goods[w-w0].append(v)
val=[]
for x in range(4):
goods[x].sort(reverse=True)
valx=[0]*(len(goods[x])+1)
for k in range(len(goods[x])):
valx[k+1]=valx[k]+goods[x][k]
val.append(valx)
ans=0
for i in range(len(goods[0])+1):
if w0*i>W:
break
for j in range(len(goods[1])+1):
if w0*(i+j)+j>W:
break
for k in range(len(goods[2])+1):
if w0*(i+j+k)+j+2*k>W:
break
for l in range(len(goods[3])+1):
if w0*(i+j+k+l)+j+2*k+3*l>W:
break
ans=max(ans,val[0][i]+val[1][j]+val[2][k]+val[3][l])
print(ans) | N,W=list(map(int,input().split()))
goods=[[] for i in range(4)]
w1=-1
for i in range(N):
w,v=list(map(int,input().split()))
if i==0:
w1=w
goods[w-w1].append(v)
S=[]
for x in range(4):
goods[x].sort(reverse=True)
G=goods[x]
now=[0]*(len(G)+1)
for i in range(len(G)):
now[i+1]=now[i]+G[i]
S.append(now)
ans=0
for i in range(1+len(goods[0])):
for j in range(1+len(goods[1])):
for k in range(1+len(goods[2])):
wnow=W-w1*(i+j+k)-j-2*k
if wnow<0:
continue
else:
ans=max(ans,S[0][i]+S[1][j]+S[2][k]+S[3][min(len(S[3])-1,wnow//(w1+3))])
print(ans) | 28 | 26 | 811 | 680 | N, W = list(map(int, input().split()))
w0, v = list(map(int, input().split()))
goods = [[v], [], [], []]
for i in range(N - 1):
w, v = list(map(int, input().split()))
goods[w - w0].append(v)
val = []
for x in range(4):
goods[x].sort(reverse=True)
valx = [0] * (len(goods[x]) + 1)
for k in range(len(goods[x])):
valx[k + 1] = valx[k] + goods[x][k]
val.append(valx)
ans = 0
for i in range(len(goods[0]) + 1):
if w0 * i > W:
break
for j in range(len(goods[1]) + 1):
if w0 * (i + j) + j > W:
break
for k in range(len(goods[2]) + 1):
if w0 * (i + j + k) + j + 2 * k > W:
break
for l in range(len(goods[3]) + 1):
if w0 * (i + j + k + l) + j + 2 * k + 3 * l > W:
break
ans = max(ans, val[0][i] + val[1][j] + val[2][k] + val[3][l])
print(ans)
| N, W = list(map(int, input().split()))
goods = [[] for i in range(4)]
w1 = -1
for i in range(N):
w, v = list(map(int, input().split()))
if i == 0:
w1 = w
goods[w - w1].append(v)
S = []
for x in range(4):
goods[x].sort(reverse=True)
G = goods[x]
now = [0] * (len(G) + 1)
for i in range(len(G)):
now[i + 1] = now[i] + G[i]
S.append(now)
ans = 0
for i in range(1 + len(goods[0])):
for j in range(1 + len(goods[1])):
for k in range(1 + len(goods[2])):
wnow = W - w1 * (i + j + k) - j - 2 * k
if wnow < 0:
continue
else:
ans = max(
ans,
S[0][i]
+ S[1][j]
+ S[2][k]
+ S[3][min(len(S[3]) - 1, wnow // (w1 + 3))],
)
print(ans)
| false | 7.142857 | [
"-w0, v = list(map(int, input().split()))",
"-goods = [[v], [], [], []]",
"-for i in range(N - 1):",
"+goods = [[] for i in range(4)]",
"+w1 = -1",
"+for i in range(N):",
"- goods[w - w0].append(v)",
"-val = []",
"+ if i == 0:",
"+ w1 = w",
"+ goods[w - w1].append(v)",
"+S = []",
"- valx = [0] * (len(goods[x]) + 1)",
"- for k in range(len(goods[x])):",
"- valx[k + 1] = valx[k] + goods[x][k]",
"- val.append(valx)",
"+ G = goods[x]",
"+ now = [0] * (len(G) + 1)",
"+ for i in range(len(G)):",
"+ now[i + 1] = now[i] + G[i]",
"+ S.append(now)",
"-for i in range(len(goods[0]) + 1):",
"- if w0 * i > W:",
"- break",
"- for j in range(len(goods[1]) + 1):",
"- if w0 * (i + j) + j > W:",
"- break",
"- for k in range(len(goods[2]) + 1):",
"- if w0 * (i + j + k) + j + 2 * k > W:",
"- break",
"- for l in range(len(goods[3]) + 1):",
"- if w0 * (i + j + k + l) + j + 2 * k + 3 * l > W:",
"- break",
"- ans = max(ans, val[0][i] + val[1][j] + val[2][k] + val[3][l])",
"+for i in range(1 + len(goods[0])):",
"+ for j in range(1 + len(goods[1])):",
"+ for k in range(1 + len(goods[2])):",
"+ wnow = W - w1 * (i + j + k) - j - 2 * k",
"+ if wnow < 0:",
"+ continue",
"+ else:",
"+ ans = max(",
"+ ans,",
"+ S[0][i]",
"+ + S[1][j]",
"+ + S[2][k]",
"+ + S[3][min(len(S[3]) - 1, wnow // (w1 + 3))],",
"+ )"
] | false | 0.074761 | 0.076333 | 0.979408 | [
"s829814727",
"s787830093"
] |
u562935282 | p02909 | python | s802741660 | s343052196 | 169 | 17 | 38,256 | 2,940 | Accepted | Accepted | 89.94 | s = eval(input())
w = ['Sunny', 'Cloudy', 'Rainy']
print((w[(w.index(s) + 1) % 3]))
| def main():
W = ['Sunny', 'Cloudy', 'Rainy']
S = eval(input())
i = (W.index(S) + 1) % 3
print((W[i]))
if __name__ == '__main__':
main()
| 4 | 9 | 80 | 158 | s = eval(input())
w = ["Sunny", "Cloudy", "Rainy"]
print((w[(w.index(s) + 1) % 3]))
| def main():
W = ["Sunny", "Cloudy", "Rainy"]
S = eval(input())
i = (W.index(S) + 1) % 3
print((W[i]))
if __name__ == "__main__":
main()
| false | 55.555556 | [
"-s = eval(input())",
"-w = [\"Sunny\", \"Cloudy\", \"Rainy\"]",
"-print((w[(w.index(s) + 1) % 3]))",
"+def main():",
"+ W = [\"Sunny\", \"Cloudy\", \"Rainy\"]",
"+ S = eval(input())",
"+ i = (W.index(S) + 1) % 3",
"+ print((W[i]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.034087 | 0.042949 | 0.793658 | [
"s802741660",
"s343052196"
] |
u187205913 | p03476 | python | s910625759 | s414894778 | 1,662 | 499 | 32,048 | 32,236 | Accepted | Accepted | 69.98 | q = int(eval(input()))
l = [list(map(int,input().split())) for _ in range(q)]
def prime_table(n):
list = [True for _ in range(n+1)]
for i in range(2,int(n**0.5)+1):
if list[i]:
j = i*2
while j<=n:
list[j] = False
j += i
table = [i for i in range(n+1) if list[i] and i>=2]
return table
table = prime_table(10**5)
sim_sum = [0]*(10**5+1)
for i in range(len(table)):
if table[i]*2-1 in table:
sim_sum[table[i]*2-1] += 1
for i in range(1,10**5+1):
sim_sum[i] += sim_sum[i-1]
for l_ in l:
print((sim_sum[l_[1]]-sim_sum[max(l_[0]-2,0)])) | q = int(eval(input()))
l = [list(map(int,input().split())) for _ in range(q)]
def prime_table(n):
list = [True for _ in range(n+1)]
for i in range(2,int(n**0.5)+1):
if list[i]:
j = i*2
while j<=n:
list[j] = False
j += i
table = [i for i in range(n+1) if list[i] and i>=2]
return table
table = prime_table(10**5)
table_set = set(table)
sim_sum = [0]*(10**5+1)
for p in table:
if p*2-1 in table_set:
sim_sum[p*2-1] += 1
for i in range(1,10**5+1):
sim_sum[i] += sim_sum[i-1]
for l_ in l:
print((sim_sum[l_[1]]-sim_sum[max(l_[0]-2,0)])) | 24 | 25 | 649 | 651 | q = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(q)]
def prime_table(n):
list = [True for _ in range(n + 1)]
for i in range(2, int(n**0.5) + 1):
if list[i]:
j = i * 2
while j <= n:
list[j] = False
j += i
table = [i for i in range(n + 1) if list[i] and i >= 2]
return table
table = prime_table(10**5)
sim_sum = [0] * (10**5 + 1)
for i in range(len(table)):
if table[i] * 2 - 1 in table:
sim_sum[table[i] * 2 - 1] += 1
for i in range(1, 10**5 + 1):
sim_sum[i] += sim_sum[i - 1]
for l_ in l:
print((sim_sum[l_[1]] - sim_sum[max(l_[0] - 2, 0)]))
| q = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(q)]
def prime_table(n):
list = [True for _ in range(n + 1)]
for i in range(2, int(n**0.5) + 1):
if list[i]:
j = i * 2
while j <= n:
list[j] = False
j += i
table = [i for i in range(n + 1) if list[i] and i >= 2]
return table
table = prime_table(10**5)
table_set = set(table)
sim_sum = [0] * (10**5 + 1)
for p in table:
if p * 2 - 1 in table_set:
sim_sum[p * 2 - 1] += 1
for i in range(1, 10**5 + 1):
sim_sum[i] += sim_sum[i - 1]
for l_ in l:
print((sim_sum[l_[1]] - sim_sum[max(l_[0] - 2, 0)]))
| false | 4 | [
"+table_set = set(table)",
"-for i in range(len(table)):",
"- if table[i] * 2 - 1 in table:",
"- sim_sum[table[i] * 2 - 1] += 1",
"+for p in table:",
"+ if p * 2 - 1 in table_set:",
"+ sim_sum[p * 2 - 1] += 1"
] | false | 1.351127 | 0.347132 | 3.892253 | [
"s910625759",
"s414894778"
] |
u803647747 | p03804 | python | s823164756 | s845623792 | 25 | 23 | 3,064 | 3,060 | Accepted | Accepted | 8 | N, M = list(map(int, input().split()))
A_list = []
B_list = []
for _ in range(N):
A_list.append(list(eval(input())))
for _ in range(M):
B_list.append(list(eval(input())))
whole_flag = 0
for i in range(N-M+1):
for j in range(N-M+1):
flag = 0
for k in range(M):
if B_list[k] == A_list[i+k][j:j+M]:
flag += 1
else:
pass
if flag == M:
whole_flag += 1
if whole_flag == 0:
print("No")
else:
print("Yes") | N, M = list(map(int, input().split()))
A_list=[eval(input())for i in range(N)]
B_list=[eval(input())for i in range(M)]
whole_flag = 0
for i in range(N-M+1):
for j in range(N-M+1):
flag = 0
for k in range(M):
if B_list[k] == A_list[i+k][j:j+M]:
flag += 1
else:
pass
if flag == M:
whole_flag += 1
print(("Yes" if whole_flag >0 else "No")) | 25 | 17 | 534 | 442 | N, M = list(map(int, input().split()))
A_list = []
B_list = []
for _ in range(N):
A_list.append(list(eval(input())))
for _ in range(M):
B_list.append(list(eval(input())))
whole_flag = 0
for i in range(N - M + 1):
for j in range(N - M + 1):
flag = 0
for k in range(M):
if B_list[k] == A_list[i + k][j : j + M]:
flag += 1
else:
pass
if flag == M:
whole_flag += 1
if whole_flag == 0:
print("No")
else:
print("Yes")
| N, M = list(map(int, input().split()))
A_list = [eval(input()) for i in range(N)]
B_list = [eval(input()) for i in range(M)]
whole_flag = 0
for i in range(N - M + 1):
for j in range(N - M + 1):
flag = 0
for k in range(M):
if B_list[k] == A_list[i + k][j : j + M]:
flag += 1
else:
pass
if flag == M:
whole_flag += 1
print(("Yes" if whole_flag > 0 else "No"))
| false | 32 | [
"-A_list = []",
"-B_list = []",
"-for _ in range(N):",
"- A_list.append(list(eval(input())))",
"-for _ in range(M):",
"- B_list.append(list(eval(input())))",
"+A_list = [eval(input()) for i in range(N)]",
"+B_list = [eval(input()) for i in range(M)]",
"-if whole_flag == 0:",
"- print(\"No\")",
"-else:",
"- print(\"Yes\")",
"+print((\"Yes\" if whole_flag > 0 else \"No\"))"
] | false | 0.14471 | 0.088712 | 1.631232 | [
"s823164756",
"s845623792"
] |
u852690916 | p02762 | python | s016962752 | s248479173 | 1,219 | 574 | 74,248 | 61,912 | Accepted | Accepted | 52.91 | def main():
N, M, K=list(map(int, input().split()))
friend_or_block = [0] * N
parent = [-1] * N
def root(x):
p, s = parent[x], list()
while p >= 0:
s.append(x)
x, p = p, parent[p]
for c in s: parent[c] = x
return x
def same(x, y): return root(x) == root(y)
def count(x): return -parent[root(x)]
def unite(x, y):
xr, yr = root(x), root(y)
if xr == yr: return
if parent[xr] > parent[yr]: xr, yr = yr, xr
parent[xr] += parent[yr]
parent[yr] = xr
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
unite(a, b)
friend_or_block[a] += 1
friend_or_block[b] += 1
for _ in range(K):
c, d = list(map(int, input().split()))
c, d = c-1, d-1
if same(c, d):
friend_or_block[c] += 1
friend_or_block[d] += 1
print((*[count(i) - friend_or_block[i] - 1 for i in range(N)]))
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
def main():
N, M, K=list(map(int, input().split()))
friend_or_block = [0] * N
parent = [-1] * N
def root(x):
p, s = parent[x], list()
while p >= 0:
s.append(x)
x, p = p, parent[p]
for c in s: parent[c] = x
return x
def same(x, y): return root(x) == root(y)
def count(x): return -parent[root(x)]
def unite(x, y):
xr, yr = root(x), root(y)
if xr == yr: return
if parent[xr] > parent[yr]: xr, yr = yr, xr
parent[xr] += parent[yr]
parent[yr] = xr
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
unite(a, b)
friend_or_block[a] += 1
friend_or_block[b] += 1
for _ in range(K):
c, d = list(map(int, input().split()))
c, d = c-1, d-1
if same(c, d):
friend_or_block[c] += 1
friend_or_block[d] += 1
print((*[count(i) - friend_or_block[i] - 1 for i in range(N)]))
if __name__ == '__main__':
main()
| 43 | 45 | 1,071 | 1,111 | def main():
N, M, K = list(map(int, input().split()))
friend_or_block = [0] * N
parent = [-1] * N
def root(x):
p, s = parent[x], list()
while p >= 0:
s.append(x)
x, p = p, parent[p]
for c in s:
parent[c] = x
return x
def same(x, y):
return root(x) == root(y)
def count(x):
return -parent[root(x)]
def unite(x, y):
xr, yr = root(x), root(y)
if xr == yr:
return
if parent[xr] > parent[yr]:
xr, yr = yr, xr
parent[xr] += parent[yr]
parent[yr] = xr
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
unite(a, b)
friend_or_block[a] += 1
friend_or_block[b] += 1
for _ in range(K):
c, d = list(map(int, input().split()))
c, d = c - 1, d - 1
if same(c, d):
friend_or_block[c] += 1
friend_or_block[d] += 1
print((*[count(i) - friend_or_block[i] - 1 for i in range(N)]))
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
N, M, K = list(map(int, input().split()))
friend_or_block = [0] * N
parent = [-1] * N
def root(x):
p, s = parent[x], list()
while p >= 0:
s.append(x)
x, p = p, parent[p]
for c in s:
parent[c] = x
return x
def same(x, y):
return root(x) == root(y)
def count(x):
return -parent[root(x)]
def unite(x, y):
xr, yr = root(x), root(y)
if xr == yr:
return
if parent[xr] > parent[yr]:
xr, yr = yr, xr
parent[xr] += parent[yr]
parent[yr] = xr
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
unite(a, b)
friend_or_block[a] += 1
friend_or_block[b] += 1
for _ in range(K):
c, d = list(map(int, input().split()))
c, d = c - 1, d - 1
if same(c, d):
friend_or_block[c] += 1
friend_or_block[d] += 1
print((*[count(i) - friend_or_block[i] - 1 for i in range(N)]))
if __name__ == "__main__":
main()
| false | 4.444444 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+"
] | false | 0.124776 | 0.121318 | 1.028502 | [
"s016962752",
"s248479173"
] |
u263737105 | p02583 | python | s066014764 | s346169327 | 113 | 90 | 9,084 | 9,120 | Accepted | Accepted | 20.35 | import itertools as it
N = int(eval(input()))
s = list(map(int, input().split()))
s.sort()
count = 0
c = it.combinations(s, 3)
for i in c:
listed = list(i)
if listed[0] == listed[1] or listed[1] == listed[2] or listed[2] == listed[0]:
continue
if (listed[0] + listed[1]) > listed[2]:
count += 1
print(count) | import itertools as it
N = int(eval(input()))
s = list(map(int, input().split()))
s.sort()
count = 0
c = it.combinations(s, 3)
for i in c:
if i[0] == i[1] or i[1] == i[2] or i[2] == i[0]:
continue
elif (i[0] + i[1]) > i[2]:
count += 1
print(count) | 19 | 18 | 353 | 288 | import itertools as it
N = int(eval(input()))
s = list(map(int, input().split()))
s.sort()
count = 0
c = it.combinations(s, 3)
for i in c:
listed = list(i)
if listed[0] == listed[1] or listed[1] == listed[2] or listed[2] == listed[0]:
continue
if (listed[0] + listed[1]) > listed[2]:
count += 1
print(count)
| import itertools as it
N = int(eval(input()))
s = list(map(int, input().split()))
s.sort()
count = 0
c = it.combinations(s, 3)
for i in c:
if i[0] == i[1] or i[1] == i[2] or i[2] == i[0]:
continue
elif (i[0] + i[1]) > i[2]:
count += 1
print(count)
| false | 5.263158 | [
"- listed = list(i)",
"- if listed[0] == listed[1] or listed[1] == listed[2] or listed[2] == listed[0]:",
"+ if i[0] == i[1] or i[1] == i[2] or i[2] == i[0]:",
"- if (listed[0] + listed[1]) > listed[2]:",
"+ elif (i[0] + i[1]) > i[2]:"
] | false | 0.135586 | 0.047441 | 2.857988 | [
"s066014764",
"s346169327"
] |
u084261177 | p02813 | python | s889261208 | s089413327 | 49 | 37 | 8,052 | 10,228 | Accepted | Accepted | 24.49 | import itertools
if __name__ == '__main__':
# P and Q are both rearrangements of (1, 2, ..., N)).
# N! possible permutations of size N
# among them, let P and Q be the a-th and the b-th
n = int(eval(input()))
p = input().split(' ')
q = input().split(' ')
for i in range(0, len(q)):
p[i] = int(p[i])
q[i] = int(q[i])
realnums = p.copy()
realnums.sort()
perm = list(itertools.permutations(realnums))
it = 0
qplace = 0
pplace = 0
for i in perm:
if list(i) == q:
qplace = it
if list(i) == p:
pplace = it
it += 1
print((abs(qplace - pplace))) | import itertools
if __name__ == '__main__':
# P and Q are both rearrangements of (1, 2, ..., N)).
# N! possible permutations of size N
# among them, let P and Q be the a-th and the b-th
n = int(eval(input()))
p = list(map(int, input().split(' ')))
q = list(map(int, input().split(' ')))
realnums = p.copy()
realnums.sort()
perm = list(map(list, itertools.permutations(realnums)))
print((abs(perm.index(q) - perm.index(p)))) | 32 | 17 | 692 | 476 | import itertools
if __name__ == "__main__":
# P and Q are both rearrangements of (1, 2, ..., N)).
# N! possible permutations of size N
# among them, let P and Q be the a-th and the b-th
n = int(eval(input()))
p = input().split(" ")
q = input().split(" ")
for i in range(0, len(q)):
p[i] = int(p[i])
q[i] = int(q[i])
realnums = p.copy()
realnums.sort()
perm = list(itertools.permutations(realnums))
it = 0
qplace = 0
pplace = 0
for i in perm:
if list(i) == q:
qplace = it
if list(i) == p:
pplace = it
it += 1
print((abs(qplace - pplace)))
| import itertools
if __name__ == "__main__":
# P and Q are both rearrangements of (1, 2, ..., N)).
# N! possible permutations of size N
# among them, let P and Q be the a-th and the b-th
n = int(eval(input()))
p = list(map(int, input().split(" ")))
q = list(map(int, input().split(" ")))
realnums = p.copy()
realnums.sort()
perm = list(map(list, itertools.permutations(realnums)))
print((abs(perm.index(q) - perm.index(p))))
| false | 46.875 | [
"- p = input().split(\" \")",
"- q = input().split(\" \")",
"- for i in range(0, len(q)):",
"- p[i] = int(p[i])",
"- q[i] = int(q[i])",
"+ p = list(map(int, input().split(\" \")))",
"+ q = list(map(int, input().split(\" \")))",
"- perm = list(itertools.permutations(realnums))",
"- it = 0",
"- qplace = 0",
"- pplace = 0",
"- for i in perm:",
"- if list(i) == q:",
"- qplace = it",
"- if list(i) == p:",
"- pplace = it",
"- it += 1",
"- print((abs(qplace - pplace)))",
"+ perm = list(map(list, itertools.permutations(realnums)))",
"+ print((abs(perm.index(q) - perm.index(p))))"
] | false | 0.093042 | 0.037616 | 2.473488 | [
"s889261208",
"s089413327"
] |
u345966487 | p02900 | python | s770951582 | s822627564 | 282 | 196 | 65,640 | 5,712 | Accepted | Accepted | 30.5 | import math
from fractions import gcd
a,b = list(map(int,input().split()))
g = gcd(a,b)
gr = int(math.ceil(math.sqrt(g)))
facs = [1]
i = 2
while i*i <= g:
if g == 1:
break
if g % i == 0:
facs.append(i)
while g % i == 0:
g //= i
i += 1
if g != 1:
facs.append(g)
print((len(facs)))
| import sys
import fractions
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: list(map(int, sys.stdin.readline().split()))
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
# debug = lambda *a, **kw: print(*a, **kw, file=sys.stderr)
A, B = inm()
def solve():
x = fractions.gcd(A, B)
ans = 0
for k in range(2, x + 1):
if k * k > x:
break
cnt = 0
while x % k == 0:
x //= k
cnt += 1
if cnt:
ans += 1
if x > 1:
ans += 1
return ans + 1
print((solve()))
| 21 | 31 | 347 | 639 | import math
from fractions import gcd
a, b = list(map(int, input().split()))
g = gcd(a, b)
gr = int(math.ceil(math.sqrt(g)))
facs = [1]
i = 2
while i * i <= g:
if g == 1:
break
if g % i == 0:
facs.append(i)
while g % i == 0:
g //= i
i += 1
if g != 1:
facs.append(g)
print((len(facs)))
| import sys
import fractions
sys.setrecursionlimit(10**8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: list(map(int, sys.stdin.readline().split()))
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
# debug = lambda *a, **kw: print(*a, **kw, file=sys.stderr)
A, B = inm()
def solve():
x = fractions.gcd(A, B)
ans = 0
for k in range(2, x + 1):
if k * k > x:
break
cnt = 0
while x % k == 0:
x //= k
cnt += 1
if cnt:
ans += 1
if x > 1:
ans += 1
return ans + 1
print((solve()))
| false | 32.258065 | [
"-import math",
"-from fractions import gcd",
"+import sys",
"+import fractions",
"-a, b = list(map(int, input().split()))",
"-g = gcd(a, b)",
"-gr = int(math.ceil(math.sqrt(g)))",
"-facs = [1]",
"-i = 2",
"-while i * i <= g:",
"- if g == 1:",
"- break",
"- if g % i == 0:",
"- facs.append(i)",
"- while g % i == 0:",
"- g //= i",
"- i += 1",
"-if g != 1:",
"- facs.append(g)",
"-print((len(facs)))",
"+sys.setrecursionlimit(10**8)",
"+ini = lambda: int(sys.stdin.readline())",
"+inm = lambda: list(map(int, sys.stdin.readline().split()))",
"+inl = lambda: list(inm())",
"+ins = lambda: sys.stdin.readline().rstrip()",
"+# debug = lambda *a, **kw: print(*a, **kw, file=sys.stderr)",
"+A, B = inm()",
"+",
"+",
"+def solve():",
"+ x = fractions.gcd(A, B)",
"+ ans = 0",
"+ for k in range(2, x + 1):",
"+ if k * k > x:",
"+ break",
"+ cnt = 0",
"+ while x % k == 0:",
"+ x //= k",
"+ cnt += 1",
"+ if cnt:",
"+ ans += 1",
"+ if x > 1:",
"+ ans += 1",
"+ return ans + 1",
"+",
"+",
"+print((solve()))"
] | false | 0.057457 | 0.057694 | 0.995881 | [
"s770951582",
"s822627564"
] |
u044952145 | p03215 | python | s028881277 | s138390401 | 684 | 625 | 55,692 | 27,816 | Accepted | Accepted | 8.63 | import itertools
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
beautiful_num = []
for i in range(N):
temp = 0
for n in a[i:]:
temp += n
beautiful_num.append("{:040b}".format(temp))
ma_b_cnt = 0
target_set = None
result = 0
for i in range(40):
for b in beautiful_num:
if b[i] == "1":
ma_b_cnt += 1
if ma_b_cnt >= K:
result += 2**(40-i-1)
beautiful_num = [b for b in beautiful_num if b[i] == "1"]
ma_b_cnt = 0
print(result) | import itertools
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
beautiful_num = []
for i in range(N):
temp = 0
for n in a[i:]:
temp += n
beautiful_num.append(temp)
ma_b_cnt = 0
target_set = None
result = 0
for i in range(40, -1, -1):
for b in beautiful_num:
if b & 1 << i != 0:
ma_b_cnt += 1
if ma_b_cnt >= K:
result += 2**i
beautiful_num = [b for b in beautiful_num if b & 1 << i != 0]
ma_b_cnt = 0
print(result) | 26 | 26 | 574 | 565 | import itertools
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
beautiful_num = []
for i in range(N):
temp = 0
for n in a[i:]:
temp += n
beautiful_num.append("{:040b}".format(temp))
ma_b_cnt = 0
target_set = None
result = 0
for i in range(40):
for b in beautiful_num:
if b[i] == "1":
ma_b_cnt += 1
if ma_b_cnt >= K:
result += 2 ** (40 - i - 1)
beautiful_num = [b for b in beautiful_num if b[i] == "1"]
ma_b_cnt = 0
print(result)
| import itertools
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
beautiful_num = []
for i in range(N):
temp = 0
for n in a[i:]:
temp += n
beautiful_num.append(temp)
ma_b_cnt = 0
target_set = None
result = 0
for i in range(40, -1, -1):
for b in beautiful_num:
if b & 1 << i != 0:
ma_b_cnt += 1
if ma_b_cnt >= K:
result += 2**i
beautiful_num = [b for b in beautiful_num if b & 1 << i != 0]
ma_b_cnt = 0
print(result)
| false | 0 | [
"- beautiful_num.append(\"{:040b}\".format(temp))",
"+ beautiful_num.append(temp)",
"-for i in range(40):",
"+for i in range(40, -1, -1):",
"- if b[i] == \"1\":",
"+ if b & 1 << i != 0:",
"- result += 2 ** (40 - i - 1)",
"- beautiful_num = [b for b in beautiful_num if b[i] == \"1\"]",
"+ result += 2**i",
"+ beautiful_num = [b for b in beautiful_num if b & 1 << i != 0]"
] | false | 0.047045 | 0.048287 | 0.974271 | [
"s028881277",
"s138390401"
] |
u071269360 | p03448 | python | s801016178 | s164781454 | 32 | 29 | 9,228 | 9,196 | Accepted | Accepted | 9.38 | a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
cnt = 0
a_min = min( int(x/500) ,a)
for ai in range(a_min+1):
rem_a = x - (ai * 500)
if rem_a == 0:
cnt+=1
break
b_min = min( int(rem_a/100) ,b)
for bi in range(b_min+1):
rem_b = rem_a - (bi * 100)
if rem_b == 0:
cnt+=1
break
c_min = min( int(rem_b/50) ,c)
for ci in range(c_min+1):
rem_c = rem_b - (ci * 50)
if rem_c == 0:
cnt+=1
break
print(cnt) | a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
cnt = 0
a_min = min( x//500 ,a)
for ai in range(a_min+1):
rem_a = x - (ai * 500)
if rem_a == 0:
cnt+=1
break
b_min = min( rem_a//100 ,b)
for bi in range(b_min+1):
rem_b = rem_a - (bi * 100)
if rem_b == 0 :
cnt+=1
break
if (rem_b % 50 == 0 and rem_b // 50 <= c ):
cnt+=1
continue
print(cnt) | 26 | 22 | 586 | 483 | a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
cnt = 0
a_min = min(int(x / 500), a)
for ai in range(a_min + 1):
rem_a = x - (ai * 500)
if rem_a == 0:
cnt += 1
break
b_min = min(int(rem_a / 100), b)
for bi in range(b_min + 1):
rem_b = rem_a - (bi * 100)
if rem_b == 0:
cnt += 1
break
c_min = min(int(rem_b / 50), c)
for ci in range(c_min + 1):
rem_c = rem_b - (ci * 50)
if rem_c == 0:
cnt += 1
break
print(cnt)
| a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
cnt = 0
a_min = min(x // 500, a)
for ai in range(a_min + 1):
rem_a = x - (ai * 500)
if rem_a == 0:
cnt += 1
break
b_min = min(rem_a // 100, b)
for bi in range(b_min + 1):
rem_b = rem_a - (bi * 100)
if rem_b == 0:
cnt += 1
break
if rem_b % 50 == 0 and rem_b // 50 <= c:
cnt += 1
continue
print(cnt)
| false | 15.384615 | [
"-a_min = min(int(x / 500), a)",
"+a_min = min(x // 500, a)",
"- b_min = min(int(rem_a / 100), b)",
"+ b_min = min(rem_a // 100, b)",
"- c_min = min(int(rem_b / 50), c)",
"- for ci in range(c_min + 1):",
"- rem_c = rem_b - (ci * 50)",
"- if rem_c == 0:",
"- cnt += 1",
"- break",
"+ if rem_b % 50 == 0 and rem_b // 50 <= c:",
"+ cnt += 1",
"+ continue"
] | false | 0.113089 | 0.038637 | 2.926936 | [
"s801016178",
"s164781454"
] |
u128282559 | p03037 | python | s257516886 | s753431422 | 335 | 263 | 38,316 | 27,112 | Accepted | Accepted | 21.49 | n, m = list(map(int, input().split()))
a = []
for i in range(m):
a.append(input().split())
haba = a[0]
for i in a:
if int(haba[0]) <= int(i[0]) <= int(haba[1]):
haba[0] = i[0]
elif int(haba[1]) < int(i[0]):
print((0))
exit()
if int(haba[0]) <= int(i[1]) <= int(haba[1]):
haba[1] = i[1]
elif int(i[1]) < int(haba[0]):
print((0))
exit()
if n < int(haba[0]):
ans = 0
elif int(haba[0]) <= n <= int(haba[1]):
ans = n - int(haba[0]) + 1
else:
ans = int(haba[1]) - int(haba[0]) + 1
print(ans) | n, m = list(map(int, input().split()))
a = []
for i in range(m):
a.append(list(map(int, input().split())))
haba = a[0]
for i in a:
if haba[0] <= i[0] <= haba[1]:
haba[0] = i[0]
elif haba[1] < i[0]:
print((0))
exit()
if haba[0] <= i[1] <= haba[1]:
haba[1] = i[1]
elif i[1] < haba[0]:
print((0))
exit()
if n < haba[0]:
ans = 0
elif haba[0] <= n <= haba[1]:
ans = n - haba[0] + 1
else:
ans = haba[1] - haba[0] + 1
print(ans) | 23 | 23 | 577 | 513 | n, m = list(map(int, input().split()))
a = []
for i in range(m):
a.append(input().split())
haba = a[0]
for i in a:
if int(haba[0]) <= int(i[0]) <= int(haba[1]):
haba[0] = i[0]
elif int(haba[1]) < int(i[0]):
print((0))
exit()
if int(haba[0]) <= int(i[1]) <= int(haba[1]):
haba[1] = i[1]
elif int(i[1]) < int(haba[0]):
print((0))
exit()
if n < int(haba[0]):
ans = 0
elif int(haba[0]) <= n <= int(haba[1]):
ans = n - int(haba[0]) + 1
else:
ans = int(haba[1]) - int(haba[0]) + 1
print(ans)
| n, m = list(map(int, input().split()))
a = []
for i in range(m):
a.append(list(map(int, input().split())))
haba = a[0]
for i in a:
if haba[0] <= i[0] <= haba[1]:
haba[0] = i[0]
elif haba[1] < i[0]:
print((0))
exit()
if haba[0] <= i[1] <= haba[1]:
haba[1] = i[1]
elif i[1] < haba[0]:
print((0))
exit()
if n < haba[0]:
ans = 0
elif haba[0] <= n <= haba[1]:
ans = n - haba[0] + 1
else:
ans = haba[1] - haba[0] + 1
print(ans)
| false | 0 | [
"- a.append(input().split())",
"+ a.append(list(map(int, input().split())))",
"- if int(haba[0]) <= int(i[0]) <= int(haba[1]):",
"+ if haba[0] <= i[0] <= haba[1]:",
"- elif int(haba[1]) < int(i[0]):",
"+ elif haba[1] < i[0]:",
"- if int(haba[0]) <= int(i[1]) <= int(haba[1]):",
"+ if haba[0] <= i[1] <= haba[1]:",
"- elif int(i[1]) < int(haba[0]):",
"+ elif i[1] < haba[0]:",
"-if n < int(haba[0]):",
"+if n < haba[0]:",
"-elif int(haba[0]) <= n <= int(haba[1]):",
"- ans = n - int(haba[0]) + 1",
"+elif haba[0] <= n <= haba[1]:",
"+ ans = n - haba[0] + 1",
"- ans = int(haba[1]) - int(haba[0]) + 1",
"+ ans = haba[1] - haba[0] + 1"
] | false | 0.122839 | 0.045701 | 2.687889 | [
"s257516886",
"s753431422"
] |
u652656291 | p03013 | python | s711380067 | s259987664 | 191 | 77 | 12,652 | 13,940 | Accepted | Accepted | 59.69 | MOD = 10**9 + 7
N,M = list(map(int,input().split()))
dp = [0]*(N+1)
dp[0] = 1
A = set(int(eval(input())) for _ in range(M)) # 禁止地帯
for i in range(1,N+1):
if i in A:
continue
x = dp[i-1]
if i > 1:
x += dp[i-2]
dp[i] = x%MOD
answer = dp[N]
print(answer)
| n,m,*a=list(map(int,open(0).read().split()))
b=[1]*(n+1)
for i in a:
b[i]=0
for i in range(2,n+1):
b[i]=(b[i-1]+b[i-2])%1000000007*b[i]
print((b[-1]))
| 17 | 7 | 275 | 157 | MOD = 10**9 + 7
N, M = list(map(int, input().split()))
dp = [0] * (N + 1)
dp[0] = 1
A = set(int(eval(input())) for _ in range(M)) # 禁止地帯
for i in range(1, N + 1):
if i in A:
continue
x = dp[i - 1]
if i > 1:
x += dp[i - 2]
dp[i] = x % MOD
answer = dp[N]
print(answer)
| n, m, *a = list(map(int, open(0).read().split()))
b = [1] * (n + 1)
for i in a:
b[i] = 0
for i in range(2, n + 1):
b[i] = (b[i - 1] + b[i - 2]) % 1000000007 * b[i]
print((b[-1]))
| false | 58.823529 | [
"-MOD = 10**9 + 7",
"-N, M = list(map(int, input().split()))",
"-dp = [0] * (N + 1)",
"-dp[0] = 1",
"-A = set(int(eval(input())) for _ in range(M)) # 禁止地帯",
"-for i in range(1, N + 1):",
"- if i in A:",
"- continue",
"- x = dp[i - 1]",
"- if i > 1:",
"- x += dp[i - 2]",
"- dp[i] = x % MOD",
"-answer = dp[N]",
"-print(answer)",
"+n, m, *a = list(map(int, open(0).read().split()))",
"+b = [1] * (n + 1)",
"+for i in a:",
"+ b[i] = 0",
"+for i in range(2, n + 1):",
"+ b[i] = (b[i - 1] + b[i - 2]) % 1000000007 * b[i]",
"+print((b[-1]))"
] | false | 0.041908 | 0.115546 | 0.362692 | [
"s711380067",
"s259987664"
] |
u170201762 | p03504 | python | s507742677 | s360700473 | 734 | 567 | 52,156 | 21,376 | Accepted | Accepted | 22.75 | N,C = list(map(int,input().split()))
cum = [0]*(10**5+1)
tail = {}
head = {}
for i in range(10**5+1):
tail[i] = []
head[i] = []
for i in range(N):
s,t,c = list(map(int,input().split()))
if c not in tail[s] and c not in head[t-1]:
cum[s-1] += 1
cum[t] -= 1
elif c not in head[t-1]:
cum[s] += 1
cum[t] -= 1
elif c not in tail[s]:
cum[s-1] += 1
cum[t-1] -= 1
else:
cum[s] += 1
cum[t-1] -= 1
tail[t].append(c)
head[s-1].append(c)
import numpy as np
print((np.cumsum(cum).max())) | N,C = list(map(int,input().split()))
cum = [0]*(10**5+1)
st = [[] for _ in range(C)]
for _ in range(N):
s,t,c = list(map(int,input().split()))
st[c-1].append([s,t])
for c in range(C):
st[c].sort()
st_concat = [[] for _ in range(C)]
for c in range(C):
if len(st[c]) != 0:
s0,t0 = st[c].pop()
while st[c]:
s,t = st[c].pop()
if t != s0:
st_concat[c].append([s0,t0])
s0,t0 = s,t
else:
s0 = s
st_concat[c].append([s0,t0])
for c in range(C):
for s,t in st_concat[c]:
cum[s-1] += 1
cum[t] -= 1
for i in range(10**5):
cum[i+1] += cum[i]
print((max(cum))) | 26 | 30 | 590 | 712 | N, C = list(map(int, input().split()))
cum = [0] * (10**5 + 1)
tail = {}
head = {}
for i in range(10**5 + 1):
tail[i] = []
head[i] = []
for i in range(N):
s, t, c = list(map(int, input().split()))
if c not in tail[s] and c not in head[t - 1]:
cum[s - 1] += 1
cum[t] -= 1
elif c not in head[t - 1]:
cum[s] += 1
cum[t] -= 1
elif c not in tail[s]:
cum[s - 1] += 1
cum[t - 1] -= 1
else:
cum[s] += 1
cum[t - 1] -= 1
tail[t].append(c)
head[s - 1].append(c)
import numpy as np
print((np.cumsum(cum).max()))
| N, C = list(map(int, input().split()))
cum = [0] * (10**5 + 1)
st = [[] for _ in range(C)]
for _ in range(N):
s, t, c = list(map(int, input().split()))
st[c - 1].append([s, t])
for c in range(C):
st[c].sort()
st_concat = [[] for _ in range(C)]
for c in range(C):
if len(st[c]) != 0:
s0, t0 = st[c].pop()
while st[c]:
s, t = st[c].pop()
if t != s0:
st_concat[c].append([s0, t0])
s0, t0 = s, t
else:
s0 = s
st_concat[c].append([s0, t0])
for c in range(C):
for s, t in st_concat[c]:
cum[s - 1] += 1
cum[t] -= 1
for i in range(10**5):
cum[i + 1] += cum[i]
print((max(cum)))
| false | 13.333333 | [
"-tail = {}",
"-head = {}",
"-for i in range(10**5 + 1):",
"- tail[i] = []",
"- head[i] = []",
"-for i in range(N):",
"+st = [[] for _ in range(C)]",
"+for _ in range(N):",
"- if c not in tail[s] and c not in head[t - 1]:",
"+ st[c - 1].append([s, t])",
"+for c in range(C):",
"+ st[c].sort()",
"+st_concat = [[] for _ in range(C)]",
"+for c in range(C):",
"+ if len(st[c]) != 0:",
"+ s0, t0 = st[c].pop()",
"+ while st[c]:",
"+ s, t = st[c].pop()",
"+ if t != s0:",
"+ st_concat[c].append([s0, t0])",
"+ s0, t0 = s, t",
"+ else:",
"+ s0 = s",
"+ st_concat[c].append([s0, t0])",
"+for c in range(C):",
"+ for s, t in st_concat[c]:",
"- elif c not in head[t - 1]:",
"- cum[s] += 1",
"- cum[t] -= 1",
"- elif c not in tail[s]:",
"- cum[s - 1] += 1",
"- cum[t - 1] -= 1",
"- else:",
"- cum[s] += 1",
"- cum[t - 1] -= 1",
"- tail[t].append(c)",
"- head[s - 1].append(c)",
"-import numpy as np",
"-",
"-print((np.cumsum(cum).max()))",
"+for i in range(10**5):",
"+ cum[i + 1] += cum[i]",
"+print((max(cum)))"
] | false | 0.768951 | 0.224104 | 3.431223 | [
"s507742677",
"s360700473"
] |
u687044304 | p03031 | python | s085946687 | s960922164 | 26 | 22 | 3,064 | 3,064 | Accepted | Accepted | 15.38 | # -*- coding:utf-8 -*-
from itertools import product
def solve():
N, M = list(map(int, input().split()))
K, S = [], []
for _ in range(M):
_in = list(map(int, input().split()))
K.append(_in[0])
S.append(_in[1:])
P = list(map(int, input().split()))
all_stats = product((0,1), repeat=N)
ans = 0
for stat in all_stats:
is_ok = True
for switch_i, switch in enumerate(S):
on_num = 0
for i in range(len(switch)):
if stat[switch[i]-1] == 1:
on_num += 1
if on_num%2 != P[switch_i]:
is_ok = False
break
if is_ok:
ans += 1
print(ans)
if __name__ == "__main__":
solve()
| # -*- coding:utf-8 -*-
import itertools
def solve():
N, M = list(map(int, input().split()))
Ks, Ss = [], []
for i in range(M):
_in = list(map(int, input().split()))
Ks.append(_in[0])
Ss.append(_in[1:])
Ps = list(map(int, input().split()))
# 全探索でいける
switches = itertools.product([0,1], repeat=N)
ans = 0
for switch in switches:
is_ok = True
for i in range(M):
on_num = 0
for s in Ss[i]:
if switch[s-1] == 1:
on_num += 1
if on_num%2 != Ps[i]:
is_ok = False
break
if is_ok:
ans += 1
print(ans)
if __name__ == "__main__":
solve()
| 30 | 36 | 790 | 785 | # -*- coding:utf-8 -*-
from itertools import product
def solve():
N, M = list(map(int, input().split()))
K, S = [], []
for _ in range(M):
_in = list(map(int, input().split()))
K.append(_in[0])
S.append(_in[1:])
P = list(map(int, input().split()))
all_stats = product((0, 1), repeat=N)
ans = 0
for stat in all_stats:
is_ok = True
for switch_i, switch in enumerate(S):
on_num = 0
for i in range(len(switch)):
if stat[switch[i] - 1] == 1:
on_num += 1
if on_num % 2 != P[switch_i]:
is_ok = False
break
if is_ok:
ans += 1
print(ans)
if __name__ == "__main__":
solve()
| # -*- coding:utf-8 -*-
import itertools
def solve():
N, M = list(map(int, input().split()))
Ks, Ss = [], []
for i in range(M):
_in = list(map(int, input().split()))
Ks.append(_in[0])
Ss.append(_in[1:])
Ps = list(map(int, input().split()))
# 全探索でいける
switches = itertools.product([0, 1], repeat=N)
ans = 0
for switch in switches:
is_ok = True
for i in range(M):
on_num = 0
for s in Ss[i]:
if switch[s - 1] == 1:
on_num += 1
if on_num % 2 != Ps[i]:
is_ok = False
break
if is_ok:
ans += 1
print(ans)
if __name__ == "__main__":
solve()
| false | 16.666667 | [
"-from itertools import product",
"+import itertools",
"- K, S = [], []",
"- for _ in range(M):",
"+ Ks, Ss = [], []",
"+ for i in range(M):",
"- K.append(_in[0])",
"- S.append(_in[1:])",
"- P = list(map(int, input().split()))",
"- all_stats = product((0, 1), repeat=N)",
"+ Ks.append(_in[0])",
"+ Ss.append(_in[1:])",
"+ Ps = list(map(int, input().split()))",
"+ # 全探索でいける",
"+ switches = itertools.product([0, 1], repeat=N)",
"- for stat in all_stats:",
"+ for switch in switches:",
"- for switch_i, switch in enumerate(S):",
"+ for i in range(M):",
"- for i in range(len(switch)):",
"- if stat[switch[i] - 1] == 1:",
"+ for s in Ss[i]:",
"+ if switch[s - 1] == 1:",
"- if on_num % 2 != P[switch_i]:",
"+ if on_num % 2 != Ps[i]:"
] | false | 0.06423 | 0.120163 | 0.534522 | [
"s085946687",
"s960922164"
] |
u330039499 | p03814 | python | s624747487 | s907557217 | 86 | 11 | 6,400 | 2,924 | Accepted | Accepted | 87.21 | s = input()
print(len(s) - "".join(reversed(s)).index('Z') - s.index('A'))
| s = input()
print((s).rindex('Z') - s.index('A') + 1)
| 2 | 2 | 79 | 58 | s = input()
print(len(s) - "".join(reversed(s)).index("Z") - s.index("A"))
| s = input()
print((s).rindex("Z") - s.index("A") + 1)
| false | 0 | [
"-print(len(s) - \"\".join(reversed(s)).index(\"Z\") - s.index(\"A\"))",
"+print((s).rindex(\"Z\") - s.index(\"A\") + 1)"
] | false | 0.069585 | 0.037322 | 1.864473 | [
"s624747487",
"s907557217"
] |
u331327289 | p02693 | python | s589094213 | s016503560 | 701 | 530 | 109,212 | 106,264 | Accepted | Accepted | 24.39 | import sys
from numba import njit, void, i8
input = sys.stdin.buffer.readline
K = int(eval(input()))
A, B = list(map(int, input().split()))
@njit(i8(i8, i8, i8), cache=True)
def main(K, A, B):
for i in range(A, B + 1):
if i % K == 0:
print('OK')
return 0
print('NG')
return 0
if __name__ == '__main__':
main(K, A, B)
| import sys
from numba import njit, b1, i8
@njit(b1(i8, i8, i8), cache=True)
def solve(K, A, B):
for i in range(A, B + 1):
if i % K == 0:
return True
return False
def main():
input = sys.stdin.buffer.readline
K = int(eval(input()))
A, B = list(map(int, input().split()))
print(('OK' if solve(K, A, B) else 'NG'))
if __name__ == '__main__':
main()
| 21 | 23 | 379 | 410 | import sys
from numba import njit, void, i8
input = sys.stdin.buffer.readline
K = int(eval(input()))
A, B = list(map(int, input().split()))
@njit(i8(i8, i8, i8), cache=True)
def main(K, A, B):
for i in range(A, B + 1):
if i % K == 0:
print("OK")
return 0
print("NG")
return 0
if __name__ == "__main__":
main(K, A, B)
| import sys
from numba import njit, b1, i8
@njit(b1(i8, i8, i8), cache=True)
def solve(K, A, B):
for i in range(A, B + 1):
if i % K == 0:
return True
return False
def main():
input = sys.stdin.buffer.readline
K = int(eval(input()))
A, B = list(map(int, input().split()))
print(("OK" if solve(K, A, B) else "NG"))
if __name__ == "__main__":
main()
| false | 8.695652 | [
"-from numba import njit, void, i8",
"-",
"-input = sys.stdin.buffer.readline",
"-K = int(eval(input()))",
"-A, B = list(map(int, input().split()))",
"+from numba import njit, b1, i8",
"-@njit(i8(i8, i8, i8), cache=True)",
"-def main(K, A, B):",
"+@njit(b1(i8, i8, i8), cache=True)",
"+def solve(K, A, B):",
"- print(\"OK\")",
"- return 0",
"- print(\"NG\")",
"- return 0",
"+ return True",
"+ return False",
"+",
"+",
"+def main():",
"+ input = sys.stdin.buffer.readline",
"+ K = int(eval(input()))",
"+ A, B = list(map(int, input().split()))",
"+ print((\"OK\" if solve(K, A, B) else \"NG\"))",
"- main(K, A, B)",
"+ main()"
] | false | 0.036495 | 0.067283 | 0.54241 | [
"s589094213",
"s016503560"
] |
u887207211 | p03479 | python | s524598544 | s595966879 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | X, Y = list(map(int,input().split()))
ans = 0
while X <= Y:
X *= 2
ans += 1
print(ans) | X, Y = list(map(int,input().split()))
cnt = 0
while X <= Y:
X *= 2
cnt += 1
print(cnt) | 6 | 6 | 89 | 89 | X, Y = list(map(int, input().split()))
ans = 0
while X <= Y:
X *= 2
ans += 1
print(ans)
| X, Y = list(map(int, input().split()))
cnt = 0
while X <= Y:
X *= 2
cnt += 1
print(cnt)
| false | 0 | [
"-ans = 0",
"+cnt = 0",
"- ans += 1",
"-print(ans)",
"+ cnt += 1",
"+print(cnt)"
] | false | 0.048136 | 0.047974 | 1.003375 | [
"s524598544",
"s595966879"
] |
u437638594 | p03420 | python | s836229274 | s905524216 | 105 | 79 | 2,940 | 2,940 | Accepted | Accepted | 24.76 | n, k = list(map(int, input().split()))
ans = 0
for b in range(k + 1, n + 1):
ans += ((n // b) * max(0, b - k)) + max(0, (n % b) - k + 1)
if k == 0:
ans = n ** 2
print(ans)
| n, k = list(map(int, input().split()))
ans = 0
for b in range(k + 1, n + 1):
ans += ((n // b) * (b - k)) + max(0, (n % b) - k + 1)
if k == 0:
ans = n ** 2
print(ans)
| 7 | 7 | 180 | 174 | n, k = list(map(int, input().split()))
ans = 0
for b in range(k + 1, n + 1):
ans += ((n // b) * max(0, b - k)) + max(0, (n % b) - k + 1)
if k == 0:
ans = n**2
print(ans)
| n, k = list(map(int, input().split()))
ans = 0
for b in range(k + 1, n + 1):
ans += ((n // b) * (b - k)) + max(0, (n % b) - k + 1)
if k == 0:
ans = n**2
print(ans)
| false | 0 | [
"- ans += ((n // b) * max(0, b - k)) + max(0, (n % b) - k + 1)",
"+ ans += ((n // b) * (b - k)) + max(0, (n % b) - k + 1)"
] | false | 0.04196 | 0.043309 | 0.968862 | [
"s836229274",
"s905524216"
] |
u477343425 | p03136 | python | s509080145 | s141349612 | 19 | 17 | 2,940 | 3,064 | Accepted | Accepted | 10.53 | n = eval(input())
L = list(map(int, input().split()))
print(('Yes' if sum(L) > 2 * max(L) else 'No'))
| n = int(eval(input()))
l = list(map(int, input().split()))
if sum(l) > 2 * max(l):
print('Yes')
else:
print('No') | 4 | 6 | 98 | 116 | n = eval(input())
L = list(map(int, input().split()))
print(("Yes" if sum(L) > 2 * max(L) else "No"))
| n = int(eval(input()))
l = list(map(int, input().split()))
if sum(l) > 2 * max(l):
print("Yes")
else:
print("No")
| false | 33.333333 | [
"-n = eval(input())",
"-L = list(map(int, input().split()))",
"-print((\"Yes\" if sum(L) > 2 * max(L) else \"No\"))",
"+n = int(eval(input()))",
"+l = list(map(int, input().split()))",
"+if sum(l) > 2 * max(l):",
"+ print(\"Yes\")",
"+else:",
"+ print(\"No\")"
] | false | 0.071516 | 0.068442 | 1.04491 | [
"s509080145",
"s141349612"
] |
u788137651 | p03713 | python | s783832818 | s613610954 | 260 | 231 | 43,484 | 42,716 | Accepted | Accepted | 11.15 | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return list(map(int,input().split()))
def MF(): return list(map(float, input().split()))
def MI_(): return list(map(INT_,input().split()))
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in eval(input())]
def I(): return int(eval(input()))
def F(): return float(eval(input()))
def ST(): return input().replace('\n', '')
def main():
H,W = MI()
S = H*W
def solve(H,W):
ans = inf
for h in range(H):
if not (H-h)&1 or not W&1:
piece = [h*W]
piece.append(W*(H-h)/2)
ans = min(ans, max(piece)-min(piece))
else:
if (H-h)&1:
piece = [h*W]
piece.append((H-h-1)*W/2)
piece.append((H-h+1)*W/2)
ans = min(ans, max(piece)-min(piece))
if W&1:
piece = [h*W]
piece.append((W-1)*(H-h)/2)
piece.append((W+1)*(H-h)/2)
ans = min(ans, max(piece)-min(piece))
return ans
ans1 = solve(H,W)
ans2 = solve(W,H)
print((int(min(ans1,ans2))))
if __name__ == '__main__':
main()
| #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return list(map(int,input().split()))
def MF(): return list(map(float, input().split()))
def MI_(): return list(map(INT_,input().split()))
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in eval(input())]
def I(): return int(eval(input()))
def F(): return float(eval(input()))
def ST(): return input().replace('\n', '')
def main():
H,W = MI()
def solve(H,W):
ans = inf
for h in range(H):
if not (H-h)&1 or not W&1:
piece = [h*W, (W*(H-h))//2]
ans = min(ans, max(piece)-min(piece))
else:
if (H-h)&1:
piece = [h*W, ((H-h-1)*W)//2, ((H-h+1)*W)//2]
ans = min(ans, max(piece)-min(piece))
if W&1:
piece = [h*W, ((W-1)*(H-h))//2, ((W+1)*(H-h))//2]
ans = min(ans, max(piece)-min(piece))
return ans
ans1 = solve(H,W)
ans2 = solve(W,H)
print((min(ans1,ans2)))
if __name__ == '__main__':
main()
| 66 | 61 | 2,023 | 1,856 | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log # log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict
from itertools import (
accumulate,
permutations,
combinations,
product,
combinations_with_replacement,
)
from bisect import bisect_left, bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9 + 7
def INT_(n):
return int(n) - 1
def MI():
return list(map(int, input().split()))
def MF():
return list(map(float, input().split()))
def MI_():
return list(map(INT_, input().split()))
def LI():
return list(MI())
def LI_():
return [int(x) - 1 for x in input().split()]
def LF():
return list(MF())
def LIN(n: int):
return [I() for _ in range(n)]
def LLIN(n: int):
return [LI() for _ in range(n)]
def LLIN_(n: int):
return [LI_() for _ in range(n)]
def LLI():
return [list(map(int, l.split())) for l in eval(input())]
def I():
return int(eval(input()))
def F():
return float(eval(input()))
def ST():
return input().replace("\n", "")
def main():
H, W = MI()
S = H * W
def solve(H, W):
ans = inf
for h in range(H):
if not (H - h) & 1 or not W & 1:
piece = [h * W]
piece.append(W * (H - h) / 2)
ans = min(ans, max(piece) - min(piece))
else:
if (H - h) & 1:
piece = [h * W]
piece.append((H - h - 1) * W / 2)
piece.append((H - h + 1) * W / 2)
ans = min(ans, max(piece) - min(piece))
if W & 1:
piece = [h * W]
piece.append((W - 1) * (H - h) / 2)
piece.append((W + 1) * (H - h) / 2)
ans = min(ans, max(piece) - min(piece))
return ans
ans1 = solve(H, W)
ans2 = solve(W, H)
print((int(min(ans1, ans2))))
if __name__ == "__main__":
main()
| #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log # log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict
from itertools import (
accumulate,
permutations,
combinations,
product,
combinations_with_replacement,
)
from bisect import bisect_left, bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9 + 7
def INT_(n):
return int(n) - 1
def MI():
return list(map(int, input().split()))
def MF():
return list(map(float, input().split()))
def MI_():
return list(map(INT_, input().split()))
def LI():
return list(MI())
def LI_():
return [int(x) - 1 for x in input().split()]
def LF():
return list(MF())
def LIN(n: int):
return [I() for _ in range(n)]
def LLIN(n: int):
return [LI() for _ in range(n)]
def LLIN_(n: int):
return [LI_() for _ in range(n)]
def LLI():
return [list(map(int, l.split())) for l in eval(input())]
def I():
return int(eval(input()))
def F():
return float(eval(input()))
def ST():
return input().replace("\n", "")
def main():
H, W = MI()
def solve(H, W):
ans = inf
for h in range(H):
if not (H - h) & 1 or not W & 1:
piece = [h * W, (W * (H - h)) // 2]
ans = min(ans, max(piece) - min(piece))
else:
if (H - h) & 1:
piece = [h * W, ((H - h - 1) * W) // 2, ((H - h + 1) * W) // 2]
ans = min(ans, max(piece) - min(piece))
if W & 1:
piece = [h * W, ((W - 1) * (H - h)) // 2, ((W + 1) * (H - h)) // 2]
ans = min(ans, max(piece) - min(piece))
return ans
ans1 = solve(H, W)
ans2 = solve(W, H)
print((min(ans1, ans2)))
if __name__ == "__main__":
main()
| false | 7.575758 | [
"- S = H * W",
"- piece = [h * W]",
"- piece.append(W * (H - h) / 2)",
"+ piece = [h * W, (W * (H - h)) // 2]",
"- piece = [h * W]",
"- piece.append((H - h - 1) * W / 2)",
"- piece.append((H - h + 1) * W / 2)",
"+ piece = [h * W, ((H - h - 1) * W) // 2, ((H - h + 1) * W) // 2]",
"- piece = [h * W]",
"- piece.append((W - 1) * (H - h) / 2)",
"- piece.append((W + 1) * (H - h) / 2)",
"+ piece = [h * W, ((W - 1) * (H - h)) // 2, ((W + 1) * (H - h)) // 2]",
"- print((int(min(ans1, ans2))))",
"+ print((min(ans1, ans2)))"
] | false | 0.313674 | 0.256313 | 1.223793 | [
"s783832818",
"s613610954"
] |
u638456847 | p02744 | python | s691390223 | s565517278 | 128 | 88 | 15,164 | 15,128 | Accepted | Accepted | 31.25 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def dfs(N):
"""
param N:文字列の長さ
"""
result = []
stack = [("a", 1)]
while stack:
s, max_ = stack.pop()
if len(s) == N:
result.append(s)
continue
else:
for i in range(max_+1):
stack.append((s + chr(97+i), max(max_, i+1)))
return result
def main():
N = int(readline())
ans = dfs(N)
print(("\n".join(ans[::-1])))
if __name__ == "__main__":
main()
| # 深さ優先探索による全探索
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def dfs(N):
"""
param N:文字列の長さ
"""
S = "abcdefghij"
result = []
stack = ["a"]
while stack:
s = stack.pop()
if len(s) == N:
result.append(s)
continue
else:
for i in S[:len(set(s))+1]:
stack.append(s + i)
return result
def main():
N = int(readline())
ans = dfs(N)
print(("\n".join(ans[::-1])))
if __name__ == "__main__":
main()
| 35 | 37 | 619 | 624 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def dfs(N):
"""
param N:文字列の長さ
"""
result = []
stack = [("a", 1)]
while stack:
s, max_ = stack.pop()
if len(s) == N:
result.append(s)
continue
else:
for i in range(max_ + 1):
stack.append((s + chr(97 + i), max(max_, i + 1)))
return result
def main():
N = int(readline())
ans = dfs(N)
print(("\n".join(ans[::-1])))
if __name__ == "__main__":
main()
| # 深さ優先探索による全探索
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def dfs(N):
"""
param N:文字列の長さ
"""
S = "abcdefghij"
result = []
stack = ["a"]
while stack:
s = stack.pop()
if len(s) == N:
result.append(s)
continue
else:
for i in S[: len(set(s)) + 1]:
stack.append(s + i)
return result
def main():
N = int(readline())
ans = dfs(N)
print(("\n".join(ans[::-1])))
if __name__ == "__main__":
main()
| false | 5.405405 | [
"+# 深さ優先探索による全探索",
"+ S = \"abcdefghij\"",
"- stack = [(\"a\", 1)]",
"+ stack = [\"a\"]",
"- s, max_ = stack.pop()",
"+ s = stack.pop()",
"- for i in range(max_ + 1):",
"- stack.append((s + chr(97 + i), max(max_, i + 1)))",
"+ for i in S[: len(set(s)) + 1]:",
"+ stack.append(s + i)"
] | false | 0.038838 | 0.040742 | 0.953268 | [
"s691390223",
"s565517278"
] |
u546285759 | p00028 | python | s357834593 | s437483195 | 30 | 20 | 7,596 | 7,564 | Accepted | Accepted | 33.33 | import sys
from itertools import dropwhile
a = []
for v in sys.stdin:
a.append(int(v))
m = max([a.count(v) for v in set(a)])
try:
next(dropwhile(lambda x: True, (print(v) for v in set(a) if a.count(v) == m)))
except StopIteration:
pass
| a = [0] * 101
while True:
try:
a[int(eval(input()))] += 1
except:
break
maxv = max(a)
for i, v in enumerate(a):
if maxv == v:
print(i) | 11 | 10 | 258 | 173 | import sys
from itertools import dropwhile
a = []
for v in sys.stdin:
a.append(int(v))
m = max([a.count(v) for v in set(a)])
try:
next(dropwhile(lambda x: True, (print(v) for v in set(a) if a.count(v) == m)))
except StopIteration:
pass
| a = [0] * 101
while True:
try:
a[int(eval(input()))] += 1
except:
break
maxv = max(a)
for i, v in enumerate(a):
if maxv == v:
print(i)
| false | 9.090909 | [
"-import sys",
"-from itertools import dropwhile",
"-",
"-a = []",
"-for v in sys.stdin:",
"- a.append(int(v))",
"-m = max([a.count(v) for v in set(a)])",
"-try:",
"- next(dropwhile(lambda x: True, (print(v) for v in set(a) if a.count(v) == m)))",
"-except StopIteration:",
"- pass",
"+a = [0] * 101",
"+while True:",
"+ try:",
"+ a[int(eval(input()))] += 1",
"+ except:",
"+ break",
"+maxv = max(a)",
"+for i, v in enumerate(a):",
"+ if maxv == v:",
"+ print(i)"
] | false | 0.068322 | 0.05013 | 1.362894 | [
"s357834593",
"s437483195"
] |
u028973125 | p03959 | python | s611311153 | s755810635 | 331 | 137 | 89,160 | 25,324 | Accepted | Accepted | 58.61 | import sys
N = int(sys.stdin.readline().strip())
T = list(map(int, sys.stdin.readline().strip().split()))
A = list(map(int, sys.stdin.readline().strip().split()))
# i番目の山が取りうる高さの下限、上限
cand = [[1, float("inf")] for _ in range(N)]
l_max = 0
for i in range(N):
if l_max < T[i]:
l_max = T[i]
if cand[i][0] > T[i] or cand[i][1] < T[i]:
# print("here1", cand[i][0], cand[i][1], T[i])
print((0))
sys.exit()
else:
cand[i] = [T[i], T[i]]
else:
cand[i][1] = min(cand[i][1], T[i])
r_max = 0
for i in range(N-1, -1, -1):
if r_max < A[i]:
r_max = A[i]
if cand[i][0] > A[i] or cand[i][1] < A[i]:
# print("here2", cand[i][0], cand[i][1], A[i])
print((0))
sys.exit()
else:
cand[i] = [A[i], A[i]]
else:
cand[i][1] = min(cand[i][1], A[i])
# print(l_max, r_max)
if l_max != r_max:
print((0))
else:
ans = 1
for h_min, h_max in cand:
ans *= (h_max - h_min + 1)
ans %= 10**9 + 7
print(ans) | import sys
input = sys.stdin.readline
N = int(eval(input()))
T = list(map(int, input().split()))
A = list(map(int, input().split()))
if N == 1:
if T[0] == A[0]:
print((1))
else:
print((0))
sys.exit()
mod = 10**9 + 7
ans = 1
for i in range(N):
if i == 0:
if A[i] < T[i]:
print((0))
sys.exit()
elif i == N-1:
if T[i] < A[i]:
print((0))
sys.exit()
else:
if T[i-1] < T[i] and A[i+1] < A[i] and T[i] != A[i]:
print((0))
sys.exit()
else:
if T[i-1] < T[i]:
if A[i] < T[i]:
print((0))
sys.exit()
elif A[i+1] < A[i]:
if T[i] < A[i]:
print((0))
sys.exit()
else:
ans *= min(T[i], A[i])
ans %= mod
print(ans) | 46 | 44 | 1,117 | 948 | import sys
N = int(sys.stdin.readline().strip())
T = list(map(int, sys.stdin.readline().strip().split()))
A = list(map(int, sys.stdin.readline().strip().split()))
# i番目の山が取りうる高さの下限、上限
cand = [[1, float("inf")] for _ in range(N)]
l_max = 0
for i in range(N):
if l_max < T[i]:
l_max = T[i]
if cand[i][0] > T[i] or cand[i][1] < T[i]:
# print("here1", cand[i][0], cand[i][1], T[i])
print((0))
sys.exit()
else:
cand[i] = [T[i], T[i]]
else:
cand[i][1] = min(cand[i][1], T[i])
r_max = 0
for i in range(N - 1, -1, -1):
if r_max < A[i]:
r_max = A[i]
if cand[i][0] > A[i] or cand[i][1] < A[i]:
# print("here2", cand[i][0], cand[i][1], A[i])
print((0))
sys.exit()
else:
cand[i] = [A[i], A[i]]
else:
cand[i][1] = min(cand[i][1], A[i])
# print(l_max, r_max)
if l_max != r_max:
print((0))
else:
ans = 1
for h_min, h_max in cand:
ans *= h_max - h_min + 1
ans %= 10**9 + 7
print(ans)
| import sys
input = sys.stdin.readline
N = int(eval(input()))
T = list(map(int, input().split()))
A = list(map(int, input().split()))
if N == 1:
if T[0] == A[0]:
print((1))
else:
print((0))
sys.exit()
mod = 10**9 + 7
ans = 1
for i in range(N):
if i == 0:
if A[i] < T[i]:
print((0))
sys.exit()
elif i == N - 1:
if T[i] < A[i]:
print((0))
sys.exit()
else:
if T[i - 1] < T[i] and A[i + 1] < A[i] and T[i] != A[i]:
print((0))
sys.exit()
else:
if T[i - 1] < T[i]:
if A[i] < T[i]:
print((0))
sys.exit()
elif A[i + 1] < A[i]:
if T[i] < A[i]:
print((0))
sys.exit()
else:
ans *= min(T[i], A[i])
ans %= mod
print(ans)
| false | 4.347826 | [
"-N = int(sys.stdin.readline().strip())",
"-T = list(map(int, sys.stdin.readline().strip().split()))",
"-A = list(map(int, sys.stdin.readline().strip().split()))",
"-# i番目の山が取りうる高さの下限、上限",
"-cand = [[1, float(\"inf\")] for _ in range(N)]",
"-l_max = 0",
"+input = sys.stdin.readline",
"+N = int(eval(input()))",
"+T = list(map(int, input().split()))",
"+A = list(map(int, input().split()))",
"+if N == 1:",
"+ if T[0] == A[0]:",
"+ print((1))",
"+ else:",
"+ print((0))",
"+ sys.exit()",
"+mod = 10**9 + 7",
"+ans = 1",
"- if l_max < T[i]:",
"- l_max = T[i]",
"- if cand[i][0] > T[i] or cand[i][1] < T[i]:",
"- # print(\"here1\", cand[i][0], cand[i][1], T[i])",
"+ if i == 0:",
"+ if A[i] < T[i]:",
"+ print((0))",
"+ sys.exit()",
"+ elif i == N - 1:",
"+ if T[i] < A[i]:",
"+ print((0))",
"+ sys.exit()",
"+ else:",
"+ if T[i - 1] < T[i] and A[i + 1] < A[i] and T[i] != A[i]:",
"- cand[i] = [T[i], T[i]]",
"- else:",
"- cand[i][1] = min(cand[i][1], T[i])",
"-r_max = 0",
"-for i in range(N - 1, -1, -1):",
"- if r_max < A[i]:",
"- r_max = A[i]",
"- if cand[i][0] > A[i] or cand[i][1] < A[i]:",
"- # print(\"here2\", cand[i][0], cand[i][1], A[i])",
"- print((0))",
"- sys.exit()",
"- else:",
"- cand[i] = [A[i], A[i]]",
"- else:",
"- cand[i][1] = min(cand[i][1], A[i])",
"-# print(l_max, r_max)",
"-if l_max != r_max:",
"- print((0))",
"-else:",
"- ans = 1",
"- for h_min, h_max in cand:",
"- ans *= h_max - h_min + 1",
"- ans %= 10**9 + 7",
"+ if T[i - 1] < T[i]:",
"+ if A[i] < T[i]:",
"+ print((0))",
"+ sys.exit()",
"+ elif A[i + 1] < A[i]:",
"+ if T[i] < A[i]:",
"+ print((0))",
"+ sys.exit()",
"+ else:",
"+ ans *= min(T[i], A[i])",
"+ ans %= mod"
] | false | 0.029857 | 0.031621 | 0.944214 | [
"s611311153",
"s755810635"
] |
u238940874 | p02713 | python | s145263998 | s576483080 | 1,978 | 1,155 | 9,176 | 9,060 | Accepted | Accepted | 41.61 | from math import gcd
k=int(eval(input()))
ans=0
for a in range(1,k+1):
for b in range(1,k+1):
for c in range(1,k+1):
ans+=gcd(gcd(a,b),c)
print(ans) | from math import gcd
k=int(eval(input()))
ans=0
for i in range(1,k+1):
for j in range(1,k+1):
x=gcd(i,j)
for l in range(1,k+1):
ans+=gcd(x,l)
print(ans) | 8 | 9 | 173 | 186 | from math import gcd
k = int(eval(input()))
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
for c in range(1, k + 1):
ans += gcd(gcd(a, b), c)
print(ans)
| from math import gcd
k = int(eval(input()))
ans = 0
for i in range(1, k + 1):
for j in range(1, k + 1):
x = gcd(i, j)
for l in range(1, k + 1):
ans += gcd(x, l)
print(ans)
| false | 11.111111 | [
"-for a in range(1, k + 1):",
"- for b in range(1, k + 1):",
"- for c in range(1, k + 1):",
"- ans += gcd(gcd(a, b), c)",
"+for i in range(1, k + 1):",
"+ for j in range(1, k + 1):",
"+ x = gcd(i, j)",
"+ for l in range(1, k + 1):",
"+ ans += gcd(x, l)"
] | false | 0.105647 | 0.209883 | 0.503361 | [
"s145263998",
"s576483080"
] |
u849029577 | p02939 | python | s185045710 | s897749015 | 149 | 126 | 87,632 | 73,720 | Accepted | Accepted | 15.44 | s = eval(input())
ansL = [s[0]]
ans = ""
for i in s[1:]:
ans += i
if ansL[-1] != ans:
ansL.append(ans)
ans = ""
print((len(ansL)))
| s = eval(input())
a = b = ""
ans = 0
for i in s:
a += i
if a != b:
ans += 1
a, b = "", a
print(ans) | 9 | 9 | 155 | 126 | s = eval(input())
ansL = [s[0]]
ans = ""
for i in s[1:]:
ans += i
if ansL[-1] != ans:
ansL.append(ans)
ans = ""
print((len(ansL)))
| s = eval(input())
a = b = ""
ans = 0
for i in s:
a += i
if a != b:
ans += 1
a, b = "", a
print(ans)
| false | 0 | [
"-ansL = [s[0]]",
"-ans = \"\"",
"-for i in s[1:]:",
"- ans += i",
"- if ansL[-1] != ans:",
"- ansL.append(ans)",
"- ans = \"\"",
"-print((len(ansL)))",
"+a = b = \"\"",
"+ans = 0",
"+for i in s:",
"+ a += i",
"+ if a != b:",
"+ ans += 1",
"+ a, b = \"\", a",
"+print(ans)"
] | false | 0.054933 | 0.074763 | 0.734765 | [
"s185045710",
"s897749015"
] |
u380524497 | p02762 | python | s380404404 | s612647484 | 821 | 660 | 14,984 | 34,152 | Accepted | Accepted | 19.61 | import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, size):
self.parent = [-1] * size
self.rank = [1] * size
self.groups = size
def get_root(self, node):
parent = self.parent[node]
if parent == -1:
root = node
else:
root = self.get_root(parent)
self.parent[node] = root # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく
return root
def in_same_group(self, node1, node2):
root1 = self.get_root(node1)
root2 = self.get_root(node2)
return root1 == root2
def unite(self, node1, node2):
if self.in_same_group(node1, node2):
return
main_root = self.get_root(node1)
sub_root = self.get_root(node2)
if self.rank[main_root] < self.rank[sub_root]: # rankの大きい方をmain_rootにする
main_root, sub_root = sub_root, main_root
self.parent[sub_root] = main_root
self.rank[main_root] += self.rank[sub_root]
self.groups -= 1
n, m, k = list(map(int, input().split()))
uf = UnionFind(n)
minus_count = [1] * n
# friend
for _ in range(m):
a, b = list(map(int, input().split()))
uf.unite(a-1, b-1)
minus_count[a-1] += 1
minus_count[b-1] += 1
for _ in range(k):
a, b = list(map(int, input().split()))
if uf.in_same_group(a-1, b-1):
minus_count[a-1] += 1
minus_count[b-1] += 1
result = []
for i in range(n):
parent = uf.get_root(i)
count = uf.rank[parent]
ans = count - minus_count[i]
result.append(ans)
print((*result)) | def main():
import sys
from operator import itemgetter
buf = sys.stdin.buffer
class UnionFind:
def __init__(self, size):
self.parent = [-1] * size
self.rank = [1] * size
def get_root(self, node):
parent = self.parent[node]
if parent == -1:
root = node
else:
root = self.get_root(parent)
self.parent[node] = root # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく
return root
def in_same_group(self, node1, node2):
root1 = self.get_root(node1)
root2 = self.get_root(node2)
return root1 == root2
def unite(self, node1, node2):
if self.in_same_group(node1, node2):
return
main_root = self.get_root(node1)
sub_root = self.get_root(node2)
if self.rank[main_root] < self.rank[sub_root]: # rankの大きい方をmain_rootにする
main_root, sub_root = sub_root, main_root
self.parent[sub_root] = main_root
self.rank[main_root] += self.rank[sub_root]
n, m, k = list(map(int, buf.readline().split()))
uf = UnionFind(n)
minus_count = [1] * n
query = list(map(int, buf.read().split()))
def gen():
for num in query:
yield num
generator = gen()
for _ in range(m):
a, b = generator.__next__(), generator.__next__()
uf.unite(a-1, b-1)
minus_count[a-1] += 1
minus_count[b-1] += 1
for i in range(k):
a, b = generator.__next__(), generator.__next__()
if uf.in_same_group(a-1, b-1):
minus_count[a-1] += 1
minus_count[b-1] += 1
result = []
for i in range(n):
parent = uf.get_root(i)
count = uf.rank[parent]
ans = count - minus_count[i]
result.append(ans)
print((*result))
if __name__ == '__main__':
main() | 61 | 69 | 1,627 | 2,013 | import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, size):
self.parent = [-1] * size
self.rank = [1] * size
self.groups = size
def get_root(self, node):
parent = self.parent[node]
if parent == -1:
root = node
else:
root = self.get_root(parent)
self.parent[node] = root # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく
return root
def in_same_group(self, node1, node2):
root1 = self.get_root(node1)
root2 = self.get_root(node2)
return root1 == root2
def unite(self, node1, node2):
if self.in_same_group(node1, node2):
return
main_root = self.get_root(node1)
sub_root = self.get_root(node2)
if self.rank[main_root] < self.rank[sub_root]: # rankの大きい方をmain_rootにする
main_root, sub_root = sub_root, main_root
self.parent[sub_root] = main_root
self.rank[main_root] += self.rank[sub_root]
self.groups -= 1
n, m, k = list(map(int, input().split()))
uf = UnionFind(n)
minus_count = [1] * n
# friend
for _ in range(m):
a, b = list(map(int, input().split()))
uf.unite(a - 1, b - 1)
minus_count[a - 1] += 1
minus_count[b - 1] += 1
for _ in range(k):
a, b = list(map(int, input().split()))
if uf.in_same_group(a - 1, b - 1):
minus_count[a - 1] += 1
minus_count[b - 1] += 1
result = []
for i in range(n):
parent = uf.get_root(i)
count = uf.rank[parent]
ans = count - minus_count[i]
result.append(ans)
print((*result))
| def main():
import sys
from operator import itemgetter
buf = sys.stdin.buffer
class UnionFind:
def __init__(self, size):
self.parent = [-1] * size
self.rank = [1] * size
def get_root(self, node):
parent = self.parent[node]
if parent == -1:
root = node
else:
root = self.get_root(parent)
self.parent[node] = root # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく
return root
def in_same_group(self, node1, node2):
root1 = self.get_root(node1)
root2 = self.get_root(node2)
return root1 == root2
def unite(self, node1, node2):
if self.in_same_group(node1, node2):
return
main_root = self.get_root(node1)
sub_root = self.get_root(node2)
if self.rank[main_root] < self.rank[sub_root]: # rankの大きい方をmain_rootにする
main_root, sub_root = sub_root, main_root
self.parent[sub_root] = main_root
self.rank[main_root] += self.rank[sub_root]
n, m, k = list(map(int, buf.readline().split()))
uf = UnionFind(n)
minus_count = [1] * n
query = list(map(int, buf.read().split()))
def gen():
for num in query:
yield num
generator = gen()
for _ in range(m):
a, b = generator.__next__(), generator.__next__()
uf.unite(a - 1, b - 1)
minus_count[a - 1] += 1
minus_count[b - 1] += 1
for i in range(k):
a, b = generator.__next__(), generator.__next__()
if uf.in_same_group(a - 1, b - 1):
minus_count[a - 1] += 1
minus_count[b - 1] += 1
result = []
for i in range(n):
parent = uf.get_root(i)
count = uf.rank[parent]
ans = count - minus_count[i]
result.append(ans)
print((*result))
if __name__ == "__main__":
main()
| false | 11.594203 | [
"-import sys",
"+def main():",
"+ import sys",
"+ from operator import itemgetter",
"-input = sys.stdin.readline",
"+ buf = sys.stdin.buffer",
"+",
"+ class UnionFind:",
"+ def __init__(self, size):",
"+ self.parent = [-1] * size",
"+ self.rank = [1] * size",
"+",
"+ def get_root(self, node):",
"+ parent = self.parent[node]",
"+ if parent == -1:",
"+ root = node",
"+ else:",
"+ root = self.get_root(parent)",
"+ self.parent[node] = root # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく",
"+ return root",
"+",
"+ def in_same_group(self, node1, node2):",
"+ root1 = self.get_root(node1)",
"+ root2 = self.get_root(node2)",
"+ return root1 == root2",
"+",
"+ def unite(self, node1, node2):",
"+ if self.in_same_group(node1, node2):",
"+ return",
"+ main_root = self.get_root(node1)",
"+ sub_root = self.get_root(node2)",
"+ if self.rank[main_root] < self.rank[sub_root]: # rankの大きい方をmain_rootにする",
"+ main_root, sub_root = sub_root, main_root",
"+ self.parent[sub_root] = main_root",
"+ self.rank[main_root] += self.rank[sub_root]",
"+",
"+ n, m, k = list(map(int, buf.readline().split()))",
"+ uf = UnionFind(n)",
"+ minus_count = [1] * n",
"+ query = list(map(int, buf.read().split()))",
"+",
"+ def gen():",
"+ for num in query:",
"+ yield num",
"+",
"+ generator = gen()",
"+ for _ in range(m):",
"+ a, b = generator.__next__(), generator.__next__()",
"+ uf.unite(a - 1, b - 1)",
"+ minus_count[a - 1] += 1",
"+ minus_count[b - 1] += 1",
"+ for i in range(k):",
"+ a, b = generator.__next__(), generator.__next__()",
"+ if uf.in_same_group(a - 1, b - 1):",
"+ minus_count[a - 1] += 1",
"+ minus_count[b - 1] += 1",
"+ result = []",
"+ for i in range(n):",
"+ parent = uf.get_root(i)",
"+ count = uf.rank[parent]",
"+ ans = count - minus_count[i]",
"+ result.append(ans)",
"+ print((*result))",
"-class UnionFind:",
"- def __init__(self, size):",
"- self.parent = [-1] * size",
"- self.rank = [1] * size",
"- self.groups = size",
"-",
"- def get_root(self, node):",
"- parent = self.parent[node]",
"- if parent == -1:",
"- root = node",
"- else:",
"- root = self.get_root(parent)",
"- self.parent[node] = root # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく",
"- return root",
"-",
"- def in_same_group(self, node1, node2):",
"- root1 = self.get_root(node1)",
"- root2 = self.get_root(node2)",
"- return root1 == root2",
"-",
"- def unite(self, node1, node2):",
"- if self.in_same_group(node1, node2):",
"- return",
"- main_root = self.get_root(node1)",
"- sub_root = self.get_root(node2)",
"- if self.rank[main_root] < self.rank[sub_root]: # rankの大きい方をmain_rootにする",
"- main_root, sub_root = sub_root, main_root",
"- self.parent[sub_root] = main_root",
"- self.rank[main_root] += self.rank[sub_root]",
"- self.groups -= 1",
"-",
"-",
"-n, m, k = list(map(int, input().split()))",
"-uf = UnionFind(n)",
"-minus_count = [1] * n",
"-# friend",
"-for _ in range(m):",
"- a, b = list(map(int, input().split()))",
"- uf.unite(a - 1, b - 1)",
"- minus_count[a - 1] += 1",
"- minus_count[b - 1] += 1",
"-for _ in range(k):",
"- a, b = list(map(int, input().split()))",
"- if uf.in_same_group(a - 1, b - 1):",
"- minus_count[a - 1] += 1",
"- minus_count[b - 1] += 1",
"-result = []",
"-for i in range(n):",
"- parent = uf.get_root(i)",
"- count = uf.rank[parent]",
"- ans = count - minus_count[i]",
"- result.append(ans)",
"-print((*result))",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.041193 | 0.038891 | 1.0592 | [
"s380404404",
"s612647484"
] |
u506858457 | p03455 | python | s434550949 | s042754645 | 22 | 17 | 2,940 | 2,940 | Accepted | Accepted | 22.73 | a,b=list(map(int,input().split()))
if a*b%2:
print('Odd')
else:
print('Even') | a,b=list(map(int,input().split()))
if a*b%2==0:
print('Even')
else:
print('Odd') | 5 | 5 | 79 | 82 | a, b = list(map(int, input().split()))
if a * b % 2:
print("Odd")
else:
print("Even")
| a, b = list(map(int, input().split()))
if a * b % 2 == 0:
print("Even")
else:
print("Odd")
| false | 0 | [
"-if a * b % 2:",
"+if a * b % 2 == 0:",
"+ print(\"Even\")",
"+else:",
"-else:",
"- print(\"Even\")"
] | false | 0.041964 | 0.0713 | 0.588557 | [
"s434550949",
"s042754645"
] |
u133936772 | p02811 | python | s106538449 | s447403124 | 160 | 17 | 38,384 | 2,940 | Accepted | Accepted | 89.38 | k, x = list(map(int, input().split()))
print(('Yes' if x <= 500 * k else 'No')) | k,x=list(map(int,input().split()))
print(('YNeos'[x>500*k::2])) | 2 | 2 | 72 | 56 | k, x = list(map(int, input().split()))
print(("Yes" if x <= 500 * k else "No"))
| k, x = list(map(int, input().split()))
print(("YNeos"[x > 500 * k :: 2]))
| false | 0 | [
"-print((\"Yes\" if x <= 500 * k else \"No\"))",
"+print((\"YNeos\"[x > 500 * k :: 2]))"
] | false | 0.099192 | 0.032863 | 3.018359 | [
"s106538449",
"s447403124"
] |
u768559443 | p02801 | python | s198811734 | s803262115 | 169 | 17 | 38,384 | 2,940 | Accepted | Accepted | 89.94 | list=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
ans=eval(input())
for i in list:
if i==ans:
print((list[list.index(i)+1])) | C=eval(input())
i=ord(C)
print((chr(i+1))) | 6 | 3 | 186 | 36 | list = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
]
ans = eval(input())
for i in list:
if i == ans:
print((list[list.index(i) + 1]))
| C = eval(input())
i = ord(C)
print((chr(i + 1)))
| false | 50 | [
"-list = [",
"- \"a\",",
"- \"b\",",
"- \"c\",",
"- \"d\",",
"- \"e\",",
"- \"f\",",
"- \"g\",",
"- \"h\",",
"- \"i\",",
"- \"j\",",
"- \"k\",",
"- \"l\",",
"- \"m\",",
"- \"n\",",
"- \"o\",",
"- \"p\",",
"- \"q\",",
"- \"r\",",
"- \"s\",",
"- \"t\",",
"- \"u\",",
"- \"v\",",
"- \"w\",",
"- \"x\",",
"- \"y\",",
"- \"z\",",
"-]",
"-ans = eval(input())",
"-for i in list:",
"- if i == ans:",
"- print((list[list.index(i) + 1]))",
"+C = eval(input())",
"+i = ord(C)",
"+print((chr(i + 1)))"
] | false | 0.086731 | 0.034549 | 2.510369 | [
"s198811734",
"s803262115"
] |
u994988729 | p03108 | python | s153224500 | s243639469 | 771 | 592 | 37,168 | 25,576 | Accepted | Accepted | 23.22 | class UF_tree:
def __init__(self, n):
self.root = [-1] * (n + 1) # -1ならそのノードが根,で絶対値が木の要素数
self.rank = [0] * (n + 1)
def find(self, x): # xの根となる要素番号を返す
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def isSame(self, x, y):
return self.find(x) == self.find(y)
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
elif self.rank[x] < self.rank[y]:
self.root[y] += self.root[x]
self.root[x] = y
else:
self.root[x] += self.root[y]
self.root[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def getNodeLen(self, x):
return -self.root[self.find(x)]
n, m = map(int, input().split())
bridge = [list(map(int, input().split())) for _ in range(m)]
bridge = bridge[::-1]
uf = UF_tree(n)
ans = [0] * (m + 1)
ans[0] = n * (n - 1) // 2
for i in range(m):
x, y = bridge[i]
if uf.isSame(x, y):
ans[i + 1] = ans[i]
continue
tmp = uf.getNodeLen(x) * uf.getNodeLen(y)
uf.unite(x, y)
ans[i + 1] = ans[i] - tmp
ans = ans[::-1][1:]
print(*ans, sep="\n")
| import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
class UF_tree:
def __init__(self, n):
self.root = [-1] * (n + 1) # -1ならそのノードが根,で絶対値が木の要素数
self.rank = [0] * (n + 1)
def find(self, x): # xの根となる要素番号を返す
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def isSame(self, x, y):
return self.find(x) == self.find(y)
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
elif self.rank[x] < self.rank[y]:
self.root[y] += self.root[x]
self.root[x] = y
else:
self.root[x] += self.root[y]
self.root[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def getNodeLen(self, x):
return -self.root[self.find(x)]
if __name__ == "__main__":
N, M = map(int, input().split())
AB = tuple(tuple(map(int, input().split())) for _ in range(M))
score = N * (N - 1) // 2
ans = [score]
uf = UF_tree(N)
for a, b in AB[::-1]:
if uf.isSame(a, b):
ans.append(score)
continue
x = uf.getNodeLen(a)
y = uf.getNodeLen(b)
uf.unite(a, b)
score -= x * y
ans.append(score)
ans.reverse()
print(*ans[1:], sep="\n")
| 53 | 56 | 1,341 | 1,475 | class UF_tree:
def __init__(self, n):
self.root = [-1] * (n + 1) # -1ならそのノードが根,で絶対値が木の要素数
self.rank = [0] * (n + 1)
def find(self, x): # xの根となる要素番号を返す
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def isSame(self, x, y):
return self.find(x) == self.find(y)
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
elif self.rank[x] < self.rank[y]:
self.root[y] += self.root[x]
self.root[x] = y
else:
self.root[x] += self.root[y]
self.root[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def getNodeLen(self, x):
return -self.root[self.find(x)]
n, m = map(int, input().split())
bridge = [list(map(int, input().split())) for _ in range(m)]
bridge = bridge[::-1]
uf = UF_tree(n)
ans = [0] * (m + 1)
ans[0] = n * (n - 1) // 2
for i in range(m):
x, y = bridge[i]
if uf.isSame(x, y):
ans[i + 1] = ans[i]
continue
tmp = uf.getNodeLen(x) * uf.getNodeLen(y)
uf.unite(x, y)
ans[i + 1] = ans[i] - tmp
ans = ans[::-1][1:]
print(*ans, sep="\n")
| import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
class UF_tree:
def __init__(self, n):
self.root = [-1] * (n + 1) # -1ならそのノードが根,で絶対値が木の要素数
self.rank = [0] * (n + 1)
def find(self, x): # xの根となる要素番号を返す
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def isSame(self, x, y):
return self.find(x) == self.find(y)
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
elif self.rank[x] < self.rank[y]:
self.root[y] += self.root[x]
self.root[x] = y
else:
self.root[x] += self.root[y]
self.root[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def getNodeLen(self, x):
return -self.root[self.find(x)]
if __name__ == "__main__":
N, M = map(int, input().split())
AB = tuple(tuple(map(int, input().split())) for _ in range(M))
score = N * (N - 1) // 2
ans = [score]
uf = UF_tree(N)
for a, b in AB[::-1]:
if uf.isSame(a, b):
ans.append(score)
continue
x = uf.getNodeLen(a)
y = uf.getNodeLen(b)
uf.unite(a, b)
score -= x * y
ans.append(score)
ans.reverse()
print(*ans[1:], sep="\n")
| false | 5.357143 | [
"+import sys",
"+",
"+input = sys.stdin.buffer.readline",
"+sys.setrecursionlimit(10**7)",
"+",
"+",
"-n, m = map(int, input().split())",
"-bridge = [list(map(int, input().split())) for _ in range(m)]",
"-bridge = bridge[::-1]",
"-uf = UF_tree(n)",
"-ans = [0] * (m + 1)",
"-ans[0] = n * (n - 1) // 2",
"-for i in range(m):",
"- x, y = bridge[i]",
"- if uf.isSame(x, y):",
"- ans[i + 1] = ans[i]",
"- continue",
"- tmp = uf.getNodeLen(x) * uf.getNodeLen(y)",
"- uf.unite(x, y)",
"- ans[i + 1] = ans[i] - tmp",
"-ans = ans[::-1][1:]",
"-print(*ans, sep=\"\\n\")",
"+if __name__ == \"__main__\":",
"+ N, M = map(int, input().split())",
"+ AB = tuple(tuple(map(int, input().split())) for _ in range(M))",
"+ score = N * (N - 1) // 2",
"+ ans = [score]",
"+ uf = UF_tree(N)",
"+ for a, b in AB[::-1]:",
"+ if uf.isSame(a, b):",
"+ ans.append(score)",
"+ continue",
"+ x = uf.getNodeLen(a)",
"+ y = uf.getNodeLen(b)",
"+ uf.unite(a, b)",
"+ score -= x * y",
"+ ans.append(score)",
"+ ans.reverse()",
"+ print(*ans[1:], sep=\"\\n\")"
] | false | 0.04658 | 0.047031 | 0.990412 | [
"s153224500",
"s243639469"
] |
u904811150 | p02570 | python | s866261646 | s240735502 | 31 | 26 | 9,160 | 9,092 | Accepted | Accepted | 16.13 | X = input().split()
D = int(X[0])
T = int(X[1])
S = int(X[2])
time = D/S
if time <= T:
print('Yes')
else:
print('No') | INPUT = input().split()
D = int(INPUT[0])
T = int(INPUT[1])
S = int(INPUT[2])
if D/S <= T:
print("Yes")
else:
print("No") | 11 | 9 | 137 | 138 | X = input().split()
D = int(X[0])
T = int(X[1])
S = int(X[2])
time = D / S
if time <= T:
print("Yes")
else:
print("No")
| INPUT = input().split()
D = int(INPUT[0])
T = int(INPUT[1])
S = int(INPUT[2])
if D / S <= T:
print("Yes")
else:
print("No")
| false | 18.181818 | [
"-X = input().split()",
"-D = int(X[0])",
"-T = int(X[1])",
"-S = int(X[2])",
"-time = D / S",
"-if time <= T:",
"+INPUT = input().split()",
"+D = int(INPUT[0])",
"+T = int(INPUT[1])",
"+S = int(INPUT[2])",
"+if D / S <= T:"
] | false | 0.047317 | 0.165141 | 0.286523 | [
"s866261646",
"s240735502"
] |
u380524497 | p02863 | python | s353096201 | s178499428 | 659 | 248 | 117,592 | 12,772 | Accepted | Accepted | 62.37 | from collections import defaultdict
n, t = list(map(int, input().split()))
dish = []
for _ in range(n):
time, point = list(map(int, input().split()))
dish.append([time, point])
dish.sort()
DP = [[0]*t for i in range(n+1)]
ans = defaultdict(int)
for i in range(1, n+1):
time, point = dish[i-1]
for j in range(t):
DP[i][j] = max(DP[i-1][j], DP[i][j])
if j + time >= t:
ans[i] = max(DP[i-1][j]+point, ans[i])
continue
DP[i][j+time] = max((DP[i-1][j] + point), DP[i-1][j+time])
res = max(ans.values())
print(res) | import numpy as np
import sys
input = sys.stdin.readline
n, t = list(map(int, input().split()))
dish = [list(map(int, input().split())) for _ in range(n)]
dish.sort()
ans = 0
dp = np.zeros(t, dtype=int)
for time, point in dish:
ans = max(ans, dp.max()+point)
np.maximum(dp[time:], dp[:-time]+point, out=dp[time:])
print(ans) | 27 | 15 | 594 | 343 | from collections import defaultdict
n, t = list(map(int, input().split()))
dish = []
for _ in range(n):
time, point = list(map(int, input().split()))
dish.append([time, point])
dish.sort()
DP = [[0] * t for i in range(n + 1)]
ans = defaultdict(int)
for i in range(1, n + 1):
time, point = dish[i - 1]
for j in range(t):
DP[i][j] = max(DP[i - 1][j], DP[i][j])
if j + time >= t:
ans[i] = max(DP[i - 1][j] + point, ans[i])
continue
DP[i][j + time] = max((DP[i - 1][j] + point), DP[i - 1][j + time])
res = max(ans.values())
print(res)
| import numpy as np
import sys
input = sys.stdin.readline
n, t = list(map(int, input().split()))
dish = [list(map(int, input().split())) for _ in range(n)]
dish.sort()
ans = 0
dp = np.zeros(t, dtype=int)
for time, point in dish:
ans = max(ans, dp.max() + point)
np.maximum(dp[time:], dp[:-time] + point, out=dp[time:])
print(ans)
| false | 44.444444 | [
"-from collections import defaultdict",
"+import numpy as np",
"+import sys",
"+input = sys.stdin.readline",
"-dish = []",
"-for _ in range(n):",
"- time, point = list(map(int, input().split()))",
"- dish.append([time, point])",
"+dish = [list(map(int, input().split())) for _ in range(n)]",
"-DP = [[0] * t for i in range(n + 1)]",
"-ans = defaultdict(int)",
"-for i in range(1, n + 1):",
"- time, point = dish[i - 1]",
"- for j in range(t):",
"- DP[i][j] = max(DP[i - 1][j], DP[i][j])",
"- if j + time >= t:",
"- ans[i] = max(DP[i - 1][j] + point, ans[i])",
"- continue",
"- DP[i][j + time] = max((DP[i - 1][j] + point), DP[i - 1][j + time])",
"-res = max(ans.values())",
"-print(res)",
"+ans = 0",
"+dp = np.zeros(t, dtype=int)",
"+for time, point in dish:",
"+ ans = max(ans, dp.max() + point)",
"+ np.maximum(dp[time:], dp[:-time] + point, out=dp[time:])",
"+print(ans)"
] | false | 0.037849 | 0.240289 | 0.157514 | [
"s353096201",
"s178499428"
] |
u353797797 | p03111 | python | s519074262 | s317451244 | 246 | 45 | 43,372 | 5,628 | Accepted | Accepted | 81.71 | from itertools import product
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def main():
inf=10**16
n,*abc=MI()
ll=[II() for _ in range(n)]
ans=inf
for pp in product(range(4),repeat=n):
ss=[0]*3
cnt=[0]*3
for l,p in zip(ll,pp):
if p==3:continue
ss[p]+=l
cnt[p]+=1
cur=0
for i in range(3):
if cnt[i]==0:
cur=inf
break
cur+=(cnt[i]-1)*10+abs(abc[i]-ss[i])
#print(pp,cur)
ans=min(ans,cur)
print(ans)
main()
| import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def main():
inf=10**9
n,*abc=MI()
abc.sort()
a,b,c=abc
dp={(0,0,0):0}
for _ in range(n):
l=II()
ndp={}
for xyz,s in dp.items():
ndp.setdefault(xyz,inf)
ndp[xyz]=min(ndp[xyz],s)
for i in range(3):
nx=list(xyz)
ns=s+10 if nx[i] else s
nx[i]+=l
t=tuple(sorted(nx))
ndp.setdefault(t,inf)
ndp[t]=min(ndp[t],ns)
dp=ndp
ans=inf
for (x,y,z),s in dp.items():
if x*y*z==0:continue
cur=abs(x-a)+abs(y-b)+abs(z-c)+s
ans=min(ans,cur)
print(ans)
main()
| 37 | 41 | 943 | 1,085 | from itertools import product
import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
def main():
inf = 10**16
n, *abc = MI()
ll = [II() for _ in range(n)]
ans = inf
for pp in product(range(4), repeat=n):
ss = [0] * 3
cnt = [0] * 3
for l, p in zip(ll, pp):
if p == 3:
continue
ss[p] += l
cnt[p] += 1
cur = 0
for i in range(3):
if cnt[i] == 0:
cur = inf
break
cur += (cnt[i] - 1) * 10 + abs(abc[i] - ss[i])
# print(pp,cur)
ans = min(ans, cur)
print(ans)
main()
| import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
def main():
inf = 10**9
n, *abc = MI()
abc.sort()
a, b, c = abc
dp = {(0, 0, 0): 0}
for _ in range(n):
l = II()
ndp = {}
for xyz, s in dp.items():
ndp.setdefault(xyz, inf)
ndp[xyz] = min(ndp[xyz], s)
for i in range(3):
nx = list(xyz)
ns = s + 10 if nx[i] else s
nx[i] += l
t = tuple(sorted(nx))
ndp.setdefault(t, inf)
ndp[t] = min(ndp[t], ns)
dp = ndp
ans = inf
for (x, y, z), s in dp.items():
if x * y * z == 0:
continue
cur = abs(x - a) + abs(y - b) + abs(z - c) + s
ans = min(ans, cur)
print(ans)
main()
| false | 9.756098 | [
"-from itertools import product",
"- inf = 10**16",
"+ inf = 10**9",
"- ll = [II() for _ in range(n)]",
"+ abc.sort()",
"+ a, b, c = abc",
"+ dp = {(0, 0, 0): 0}",
"+ for _ in range(n):",
"+ l = II()",
"+ ndp = {}",
"+ for xyz, s in dp.items():",
"+ ndp.setdefault(xyz, inf)",
"+ ndp[xyz] = min(ndp[xyz], s)",
"+ for i in range(3):",
"+ nx = list(xyz)",
"+ ns = s + 10 if nx[i] else s",
"+ nx[i] += l",
"+ t = tuple(sorted(nx))",
"+ ndp.setdefault(t, inf)",
"+ ndp[t] = min(ndp[t], ns)",
"+ dp = ndp",
"- for pp in product(range(4), repeat=n):",
"- ss = [0] * 3",
"- cnt = [0] * 3",
"- for l, p in zip(ll, pp):",
"- if p == 3:",
"- continue",
"- ss[p] += l",
"- cnt[p] += 1",
"- cur = 0",
"- for i in range(3):",
"- if cnt[i] == 0:",
"- cur = inf",
"- break",
"- cur += (cnt[i] - 1) * 10 + abs(abc[i] - ss[i])",
"- # print(pp,cur)",
"+ for (x, y, z), s in dp.items():",
"+ if x * y * z == 0:",
"+ continue",
"+ cur = abs(x - a) + abs(y - b) + abs(z - c) + s"
] | false | 0.134066 | 0.090016 | 1.489358 | [
"s519074262",
"s317451244"
] |
u644907318 | p03380 | python | s013836795 | s383814500 | 234 | 105 | 62,704 | 86,032 | Accepted | Accepted | 55.13 | N = int(eval(input()))
A = sorted(list(map(int,input().split())))
n = A[-1]
k = A[0]
for i in range(1,N-1):
j = A[i]
if k<=n//2 and j<=n//2:
k = max(k,j)
elif k<=n//2 and j>n//2:
if k<n-j:
k = j
elif k>n//2 and j<=n//2:
if n-k<j:
k = j
elif k>n//2 and j>n//2:
if n-k<n-j:
k = j
print((n,k)) | n = int(eval(input()))
A = sorted(list(map(int,input().split())))
for i in range(n):
if A[i]*2>A[-1]:
ind = i
break
ind -= 1
a = A[ind]
b = A[-1]-A[ind+1]
if a>=b:
print((A[-1],a))
else:
print((A[-1],A[ind+1]))
| 18 | 13 | 387 | 241 | N = int(eval(input()))
A = sorted(list(map(int, input().split())))
n = A[-1]
k = A[0]
for i in range(1, N - 1):
j = A[i]
if k <= n // 2 and j <= n // 2:
k = max(k, j)
elif k <= n // 2 and j > n // 2:
if k < n - j:
k = j
elif k > n // 2 and j <= n // 2:
if n - k < j:
k = j
elif k > n // 2 and j > n // 2:
if n - k < n - j:
k = j
print((n, k))
| n = int(eval(input()))
A = sorted(list(map(int, input().split())))
for i in range(n):
if A[i] * 2 > A[-1]:
ind = i
break
ind -= 1
a = A[ind]
b = A[-1] - A[ind + 1]
if a >= b:
print((A[-1], a))
else:
print((A[-1], A[ind + 1]))
| false | 27.777778 | [
"-N = int(eval(input()))",
"+n = int(eval(input()))",
"-n = A[-1]",
"-k = A[0]",
"-for i in range(1, N - 1):",
"- j = A[i]",
"- if k <= n // 2 and j <= n // 2:",
"- k = max(k, j)",
"- elif k <= n // 2 and j > n // 2:",
"- if k < n - j:",
"- k = j",
"- elif k > n // 2 and j <= n // 2:",
"- if n - k < j:",
"- k = j",
"- elif k > n // 2 and j > n // 2:",
"- if n - k < n - j:",
"- k = j",
"-print((n, k))",
"+for i in range(n):",
"+ if A[i] * 2 > A[-1]:",
"+ ind = i",
"+ break",
"+ind -= 1",
"+a = A[ind]",
"+b = A[-1] - A[ind + 1]",
"+if a >= b:",
"+ print((A[-1], a))",
"+else:",
"+ print((A[-1], A[ind + 1]))"
] | false | 0.032244 | 0.031479 | 1.024286 | [
"s013836795",
"s383814500"
] |
u878654696 | p02553 | python | s074939612 | s275804977 | 35 | 26 | 9,172 | 9,092 | Accepted | Accepted | 25.71 | a, b, c, d = list(map(int, input().split()))
minx = min(a, b)
miny = min(c, d)
maxx = max(a, b)
maxy = max(c, d)
print((max(miny * minx, maxx * maxy, maxx * miny, minx * maxy)))
| a, b, c, d = list(map(int, input().split()))
print((max(a * c, b * d, b * c, a * d))) | 8 | 3 | 179 | 80 | a, b, c, d = list(map(int, input().split()))
minx = min(a, b)
miny = min(c, d)
maxx = max(a, b)
maxy = max(c, d)
print((max(miny * minx, maxx * maxy, maxx * miny, minx * maxy)))
| a, b, c, d = list(map(int, input().split()))
print((max(a * c, b * d, b * c, a * d)))
| false | 62.5 | [
"-minx = min(a, b)",
"-miny = min(c, d)",
"-maxx = max(a, b)",
"-maxy = max(c, d)",
"-print((max(miny * minx, maxx * maxy, maxx * miny, minx * maxy)))",
"+print((max(a * c, b * d, b * c, a * d)))"
] | false | 0.037295 | 0.037371 | 0.997986 | [
"s074939612",
"s275804977"
] |
u076917070 | p03339 | python | s413904581 | s193980113 | 200 | 139 | 29,472 | 29,472 | Accepted | Accepted | 30.5 | import sys
input=sys.stdin.readline
def main():
N = int(eval(input()))
S = input().strip()
E = [0]*N
W = [0]*N
for i in range(1,N):
E[i] = E[i-1]
if S[i-1] == "W":
E[i] += 1
for i in range(N-2,-1,-1):
W[i] = W[i+1]
if S[i+1] == "E":
W[i] += 1
X = [0]*N
for i in range(N):
X[i] = W[i] + E[i]
print((min(X)))
if __name__ == '__main__':
main()
| import sys
input=sys.stdin.readline
def main():
N = int(eval(input()))
S = input().strip()
E = [0]*N
e = 0
for i in range(0,N):
E[i] = e
if S[i] == "W":
e += 1
W = [0]*N
w = 0
for i in range(N-1,-1,-1):
W[i] = w
if S[i] == "E":
w += 1
X = [0]*N
for i in range(N):
X[i] = W[i] + E[i]
print((min(X)))
if __name__ == '__main__':
main()
| 24 | 26 | 467 | 469 | import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
S = input().strip()
E = [0] * N
W = [0] * N
for i in range(1, N):
E[i] = E[i - 1]
if S[i - 1] == "W":
E[i] += 1
for i in range(N - 2, -1, -1):
W[i] = W[i + 1]
if S[i + 1] == "E":
W[i] += 1
X = [0] * N
for i in range(N):
X[i] = W[i] + E[i]
print((min(X)))
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
S = input().strip()
E = [0] * N
e = 0
for i in range(0, N):
E[i] = e
if S[i] == "W":
e += 1
W = [0] * N
w = 0
for i in range(N - 1, -1, -1):
W[i] = w
if S[i] == "E":
w += 1
X = [0] * N
for i in range(N):
X[i] = W[i] + E[i]
print((min(X)))
if __name__ == "__main__":
main()
| false | 7.692308 | [
"+ e = 0",
"+ for i in range(0, N):",
"+ E[i] = e",
"+ if S[i] == \"W\":",
"+ e += 1",
"- for i in range(1, N):",
"- E[i] = E[i - 1]",
"- if S[i - 1] == \"W\":",
"- E[i] += 1",
"- for i in range(N - 2, -1, -1):",
"- W[i] = W[i + 1]",
"- if S[i + 1] == \"E\":",
"- W[i] += 1",
"+ w = 0",
"+ for i in range(N - 1, -1, -1):",
"+ W[i] = w",
"+ if S[i] == \"E\":",
"+ w += 1"
] | false | 0.044236 | 0.043209 | 1.023766 | [
"s413904581",
"s193980113"
] |
u227020436 | p03291 | python | s339830139 | s602001032 | 210 | 186 | 11,124 | 11,124 | Accepted | Accepted | 11.43 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
modulo = 10 ** 9 + 7
S = eval(input())
def nleft(S, c):
"""各位置について,それより左の文字列に含まれる文字 c の総数.
左に'?'が含まれるときは,それらに文字を入れて得られるすべての
文字列に渡って,文字 c の個数を合計する. """
# c の個数
n = [0 for c in S]
for i in range(1, len(S)):
n[i] = n[i-1] + (1 if S[i-1] == c else 0)
q = 0 # '?'の個数
pow3q = 1 # 3 ** q
for i in range(len(n)):
if q > 0:
n[i] *= pow3q # ?の埋め方の数だけ増やす
n[i] += pow3q1 * q # ?に入る'C'の個数
n[i] %= modulo
if S[i] == '?':
q += 1
pow3q1 = pow3q
pow3q = pow3q * 3 % modulo
return n
def nright(S, c):
# c の個数
n = [0 for c in S]
for i in range(len(S) - 1, 0, -1):
n[i-1] = n[i] + (1 if S[i] == c else 0)
q = 0 # '?'の個数
pow3q = 1 # 3 ** q
for i in range(len(n) - 1, -1, -1):
if q > 0:
n[i] *= pow3q # ?の埋め方の数だけ増やす
n[i] += pow3q1 * q # ?に入る'C'の個数
n[i] %= modulo
if S[i] == '?':
q += 1
pow3q1 = pow3q
pow3q = pow3q * 3 % modulo
return n
left = nleft (S, 'A')
right = nright(S, 'C')
# 各文字が'B'のときのABC数を計算
abc = 0
for i in range(0, len(S)):
if S[i] in 'B?':
abc += left[i] * right[i]
abc = int(abc) % modulo
print(abc) | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
modulo = 10 ** 9 + 7
S = eval(input())
def nleft(S, a, reverse=False):
"""各位置について,それより左の文字列に含まれる文字 a の総数.
左に'?'が含まれるときは,それらに文字を入れて得られるすべての
文字列に渡って,文字 a の個数を合計する. """
def rng():
if reverse: return list(range(len(S) - 1, -1, -1))
return list(range(len(S)))
# a の個数
n = [0] * len(S)
c = 0
for i in rng():
n[i] = c
if S[i] == a:
c += 1
q = 0 # '?'の個数
pow3q = 1 # 3 ** q
for i in rng():
if q > 0:
n[i] *= pow3q # ?の埋め方の数だけ増やす
n[i] += pow3q1 * q # ?に入る'C'の個数
n[i] %= modulo
if S[i] == '?':
q += 1
pow3q1 = pow3q
pow3q = pow3q * 3 % modulo
return n
left = nleft(S, 'A')
right = nleft(S, 'C', reverse=True)
# 各文字が'B'のときのABC数を計算
abc = 0
for i in range(0, len(S)):
if S[i] in 'B?':
abc += left[i] * right[i]
abc = int(abc) % modulo
print(abc)
| 61 | 48 | 1,431 | 1,042 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
modulo = 10**9 + 7
S = eval(input())
def nleft(S, c):
"""各位置について,それより左の文字列に含まれる文字 c の総数.
左に'?'が含まれるときは,それらに文字を入れて得られるすべての
文字列に渡って,文字 c の個数を合計する."""
# c の個数
n = [0 for c in S]
for i in range(1, len(S)):
n[i] = n[i - 1] + (1 if S[i - 1] == c else 0)
q = 0 # '?'の個数
pow3q = 1 # 3 ** q
for i in range(len(n)):
if q > 0:
n[i] *= pow3q # ?の埋め方の数だけ増やす
n[i] += pow3q1 * q # ?に入る'C'の個数
n[i] %= modulo
if S[i] == "?":
q += 1
pow3q1 = pow3q
pow3q = pow3q * 3 % modulo
return n
def nright(S, c):
# c の個数
n = [0 for c in S]
for i in range(len(S) - 1, 0, -1):
n[i - 1] = n[i] + (1 if S[i] == c else 0)
q = 0 # '?'の個数
pow3q = 1 # 3 ** q
for i in range(len(n) - 1, -1, -1):
if q > 0:
n[i] *= pow3q # ?の埋め方の数だけ増やす
n[i] += pow3q1 * q # ?に入る'C'の個数
n[i] %= modulo
if S[i] == "?":
q += 1
pow3q1 = pow3q
pow3q = pow3q * 3 % modulo
return n
left = nleft(S, "A")
right = nright(S, "C")
# 各文字が'B'のときのABC数を計算
abc = 0
for i in range(0, len(S)):
if S[i] in "B?":
abc += left[i] * right[i]
abc = int(abc) % modulo
print(abc)
| #!/usr/bin/env python3
# -*- coding: utf-8 -*-
modulo = 10**9 + 7
S = eval(input())
def nleft(S, a, reverse=False):
"""各位置について,それより左の文字列に含まれる文字 a の総数.
左に'?'が含まれるときは,それらに文字を入れて得られるすべての
文字列に渡って,文字 a の個数を合計する."""
def rng():
if reverse:
return list(range(len(S) - 1, -1, -1))
return list(range(len(S)))
# a の個数
n = [0] * len(S)
c = 0
for i in rng():
n[i] = c
if S[i] == a:
c += 1
q = 0 # '?'の個数
pow3q = 1 # 3 ** q
for i in rng():
if q > 0:
n[i] *= pow3q # ?の埋め方の数だけ増やす
n[i] += pow3q1 * q # ?に入る'C'の個数
n[i] %= modulo
if S[i] == "?":
q += 1
pow3q1 = pow3q
pow3q = pow3q * 3 % modulo
return n
left = nleft(S, "A")
right = nleft(S, "C", reverse=True)
# 各文字が'B'のときのABC数を計算
abc = 0
for i in range(0, len(S)):
if S[i] in "B?":
abc += left[i] * right[i]
abc = int(abc) % modulo
print(abc)
| false | 21.311475 | [
"-def nleft(S, c):",
"- \"\"\"各位置について,それより左の文字列に含まれる文字 c の総数.",
"+def nleft(S, a, reverse=False):",
"+ \"\"\"各位置について,それより左の文字列に含まれる文字 a の総数.",
"- 文字列に渡って,文字 c の個数を合計する.\"\"\"",
"- # c の個数",
"- n = [0 for c in S]",
"- for i in range(1, len(S)):",
"- n[i] = n[i - 1] + (1 if S[i - 1] == c else 0)",
"+ 文字列に渡って,文字 a の個数を合計する.\"\"\"",
"+",
"+ def rng():",
"+ if reverse:",
"+ return list(range(len(S) - 1, -1, -1))",
"+ return list(range(len(S)))",
"+",
"+ # a の個数",
"+ n = [0] * len(S)",
"+ c = 0",
"+ for i in rng():",
"+ n[i] = c",
"+ if S[i] == a:",
"+ c += 1",
"- for i in range(len(n)):",
"- if q > 0:",
"- n[i] *= pow3q # ?の埋め方の数だけ増やす",
"- n[i] += pow3q1 * q # ?に入る'C'の個数",
"- n[i] %= modulo",
"- if S[i] == \"?\":",
"- q += 1",
"- pow3q1 = pow3q",
"- pow3q = pow3q * 3 % modulo",
"- return n",
"-",
"-",
"-def nright(S, c):",
"- # c の個数",
"- n = [0 for c in S]",
"- for i in range(len(S) - 1, 0, -1):",
"- n[i - 1] = n[i] + (1 if S[i] == c else 0)",
"- q = 0 # '?'の個数",
"- pow3q = 1 # 3 ** q",
"- for i in range(len(n) - 1, -1, -1):",
"+ for i in rng():",
"-right = nright(S, \"C\")",
"+right = nleft(S, \"C\", reverse=True)"
] | false | 0.038738 | 0.067999 | 0.569692 | [
"s339830139",
"s602001032"
] |
u945181840 | p02861 | python | s392887073 | s778803200 | 416 | 17 | 21,528 | 3,064 | Accepted | Accepted | 95.91 | import sys
import numpy as np
from math import factorial, sqrt
from itertools import permutations
read = sys.stdin.read
readline = sys.stdin.readline
N = int(readline())
xy = np.array(read().split(), np.int64).reshape(N, 2)
distance = [[0.0] * N for _ in range(N)]
for i in range(N - 1):
for j in range(i + 1, N):
tmp = sqrt(np.sum((xy[i] - xy[j]) ** 2))
distance[j][i] = tmp
distance[i][j] = tmp
answer = 0
for i in permutations(list(range(N))):
for j in range(N - 1):
answer += distance[i[j]][i[j + 1]]
print((answer / factorial(N))) | import sys
from math import sqrt
read = sys.stdin.read
N, *xy = list(map(int, read().split()))
x = xy[::2]; y = xy[1::2]
distance = []
for i in range(N - 1):
for j in range(i + 1, N):
distance.append(sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2))
print((sum(distance) / N * 2)) | 23 | 14 | 593 | 298 | import sys
import numpy as np
from math import factorial, sqrt
from itertools import permutations
read = sys.stdin.read
readline = sys.stdin.readline
N = int(readline())
xy = np.array(read().split(), np.int64).reshape(N, 2)
distance = [[0.0] * N for _ in range(N)]
for i in range(N - 1):
for j in range(i + 1, N):
tmp = sqrt(np.sum((xy[i] - xy[j]) ** 2))
distance[j][i] = tmp
distance[i][j] = tmp
answer = 0
for i in permutations(list(range(N))):
for j in range(N - 1):
answer += distance[i[j]][i[j + 1]]
print((answer / factorial(N)))
| import sys
from math import sqrt
read = sys.stdin.read
N, *xy = list(map(int, read().split()))
x = xy[::2]
y = xy[1::2]
distance = []
for i in range(N - 1):
for j in range(i + 1, N):
distance.append(sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2))
print((sum(distance) / N * 2))
| false | 39.130435 | [
"-import numpy as np",
"-from math import factorial, sqrt",
"-from itertools import permutations",
"+from math import sqrt",
"-readline = sys.stdin.readline",
"-N = int(readline())",
"-xy = np.array(read().split(), np.int64).reshape(N, 2)",
"-distance = [[0.0] * N for _ in range(N)]",
"+N, *xy = list(map(int, read().split()))",
"+x = xy[::2]",
"+y = xy[1::2]",
"+distance = []",
"- tmp = sqrt(np.sum((xy[i] - xy[j]) ** 2))",
"- distance[j][i] = tmp",
"- distance[i][j] = tmp",
"-answer = 0",
"-for i in permutations(list(range(N))):",
"- for j in range(N - 1):",
"- answer += distance[i[j]][i[j + 1]]",
"-print((answer / factorial(N)))",
"+ distance.append(sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2))",
"+print((sum(distance) / N * 2))"
] | false | 0.208751 | 0.037812 | 5.520763 | [
"s392887073",
"s778803200"
] |
u077291787 | p02925 | python | s991822152 | s832761813 | 878 | 775 | 104,788 | 36,096 | Accepted | Accepted | 11.73 | # ABC139E - League
from collections import deque
def main():
N, *A = list(map(int, open(0).read().split()))
B = {}
for i in range(N):
x = i * (N - 1)
B[i + 1] = deque(A[x : x + N - 1])
cnt, cur, days = 0, [0] * (N + 1), [0] * (N + 1)
q = deque(list(range(1, N + 1)))
while q:
x = q.popleft()
if not B[x]: # player x has finished all games
continue
y = B[x].popleft()
if cur[y] == x: # player y's next game is against x and vice versa
cnt += 1
days[x] = days[y] = max(days[x], days[y]) + 1
cur[x], cur[y] = 0, 0
q.append(x), q.append(y)
else: # the opponent will do another game before playing against x
cur[x] = y
flg = cnt == N * (N - 1) // 2 # finished all scheduled games or not
print((max(days) if flg else -1))
if __name__ == "__main__":
main() | # ABC139E - League
from collections import deque
def main():
N = int(eval(input()))
A = [0] + list(deque(list(map(int, input().split()))) for _ in range(N))
cnt, cur, days = 0, [0] * (N + 1), [0] * (N + 1)
q = deque(list(range(1, N + 1)))
while q:
x = q.popleft()
if not A[x]: # player x has finished all games
continue
y = A[x].popleft() # the opponent of x
if cur[y] == x: # player y's next game is against x and vice versa
cnt += 1
days[x] = days[y] = max(days[x], days[y]) + 1 # day of playing the game
cur[x], cur[y] = 0, 0 # no next game is currently planned
q.append(x), q.append(y)
else: # the opponent will do another game before playing against x
cur[x] = y
flg = cnt == N * (N - 1) // 2 # finished all scheduled games or not
print((max(days) if flg else -1))
if __name__ == "__main__":
main() | 30 | 27 | 942 | 970 | # ABC139E - League
from collections import deque
def main():
N, *A = list(map(int, open(0).read().split()))
B = {}
for i in range(N):
x = i * (N - 1)
B[i + 1] = deque(A[x : x + N - 1])
cnt, cur, days = 0, [0] * (N + 1), [0] * (N + 1)
q = deque(list(range(1, N + 1)))
while q:
x = q.popleft()
if not B[x]: # player x has finished all games
continue
y = B[x].popleft()
if cur[y] == x: # player y's next game is against x and vice versa
cnt += 1
days[x] = days[y] = max(days[x], days[y]) + 1
cur[x], cur[y] = 0, 0
q.append(x), q.append(y)
else: # the opponent will do another game before playing against x
cur[x] = y
flg = cnt == N * (N - 1) // 2 # finished all scheduled games or not
print((max(days) if flg else -1))
if __name__ == "__main__":
main()
| # ABC139E - League
from collections import deque
def main():
N = int(eval(input()))
A = [0] + list(deque(list(map(int, input().split()))) for _ in range(N))
cnt, cur, days = 0, [0] * (N + 1), [0] * (N + 1)
q = deque(list(range(1, N + 1)))
while q:
x = q.popleft()
if not A[x]: # player x has finished all games
continue
y = A[x].popleft() # the opponent of x
if cur[y] == x: # player y's next game is against x and vice versa
cnt += 1
days[x] = days[y] = max(days[x], days[y]) + 1 # day of playing the game
cur[x], cur[y] = 0, 0 # no next game is currently planned
q.append(x), q.append(y)
else: # the opponent will do another game before playing against x
cur[x] = y
flg = cnt == N * (N - 1) // 2 # finished all scheduled games or not
print((max(days) if flg else -1))
if __name__ == "__main__":
main()
| false | 10 | [
"- N, *A = list(map(int, open(0).read().split()))",
"- B = {}",
"- for i in range(N):",
"- x = i * (N - 1)",
"- B[i + 1] = deque(A[x : x + N - 1])",
"+ N = int(eval(input()))",
"+ A = [0] + list(deque(list(map(int, input().split()))) for _ in range(N))",
"- if not B[x]: # player x has finished all games",
"+ if not A[x]: # player x has finished all games",
"- y = B[x].popleft()",
"+ y = A[x].popleft() # the opponent of x",
"- days[x] = days[y] = max(days[x], days[y]) + 1",
"- cur[x], cur[y] = 0, 0",
"+ days[x] = days[y] = max(days[x], days[y]) + 1 # day of playing the game",
"+ cur[x], cur[y] = 0, 0 # no next game is currently planned"
] | false | 0.067137 | 0.035564 | 1.887785 | [
"s991822152",
"s832761813"
] |
u440566786 | p02888 | python | s336094988 | s784397015 | 239 | 194 | 42,604 | 40,688 | Accepted | Accepted | 18.83 | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
n=int(eval(input()))
L=list(map(int,input().split()))
L.sort()
ans=0
for b in range(1,n-1):
c=b+1
for a in range(b):
while(c<n and L[a]+L[b]>L[c]): c+=1
ans+=c-b-1
print(ans)
resolve() | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
n=int(eval(input()))
L=list(map(int,input().split()))
L.sort()
C=[0]*(3001)
for l in L: C[l]+=1
for i in range(3000): C[i+1]+=C[i]
ans=0
for i in range(n):
for j in range(i+1,n):
ans+=C[L[i]+L[j]-1]-j-1
print(ans)
resolve() | 17 | 18 | 391 | 423 | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def resolve():
n = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for b in range(1, n - 1):
c = b + 1
for a in range(b):
while c < n and L[a] + L[b] > L[c]:
c += 1
ans += c - b - 1
print(ans)
resolve()
| import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def resolve():
n = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
C = [0] * (3001)
for l in L:
C[l] += 1
for i in range(3000):
C[i + 1] += C[i]
ans = 0
for i in range(n):
for j in range(i + 1, n):
ans += C[L[i] + L[j] - 1] - j - 1
print(ans)
resolve()
| false | 5.555556 | [
"+ C = [0] * (3001)",
"+ for l in L:",
"+ C[l] += 1",
"+ for i in range(3000):",
"+ C[i + 1] += C[i]",
"- for b in range(1, n - 1):",
"- c = b + 1",
"- for a in range(b):",
"- while c < n and L[a] + L[b] > L[c]:",
"- c += 1",
"- ans += c - b - 1",
"+ for i in range(n):",
"+ for j in range(i + 1, n):",
"+ ans += C[L[i] + L[j] - 1] - j - 1"
] | false | 0.035647 | 0.040715 | 0.875527 | [
"s336094988",
"s784397015"
] |
u282228874 | p03645 | python | s102832035 | s598756020 | 616 | 561 | 4,596 | 6,132 | Accepted | Accepted | 8.93 | n,m = list(map(int,input().split()))
route = [0]*(n+10)
for i in range(m):
a,b = list(map(int,input().split()))
if a == 1:
route[b] += 1
if b == n:
route[a] += 1
if 2 in route:
print("POSSIBLE")
else:
print("IMPOSSIBLE") | n,m = list(map(int,input().split()))
s = [0]*n
g = [0]*n
for i in range(m):
a,b = list(map(int,input().split()))
if a == 1:
s[b] = 1
if b == n:
g[a] = 1
for i in range(n):
if s[i] and g[i]:
print("POSSIBLE")
exit()
print("IMPOSSIBLE") | 12 | 17 | 255 | 289 | n, m = list(map(int, input().split()))
route = [0] * (n + 10)
for i in range(m):
a, b = list(map(int, input().split()))
if a == 1:
route[b] += 1
if b == n:
route[a] += 1
if 2 in route:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
| n, m = list(map(int, input().split()))
s = [0] * n
g = [0] * n
for i in range(m):
a, b = list(map(int, input().split()))
if a == 1:
s[b] = 1
if b == n:
g[a] = 1
for i in range(n):
if s[i] and g[i]:
print("POSSIBLE")
exit()
print("IMPOSSIBLE")
| false | 29.411765 | [
"-route = [0] * (n + 10)",
"+s = [0] * n",
"+g = [0] * n",
"- route[b] += 1",
"+ s[b] = 1",
"- route[a] += 1",
"-if 2 in route:",
"- print(\"POSSIBLE\")",
"-else:",
"- print(\"IMPOSSIBLE\")",
"+ g[a] = 1",
"+for i in range(n):",
"+ if s[i] and g[i]:",
"+ print(\"POSSIBLE\")",
"+ exit()",
"+print(\"IMPOSSIBLE\")"
] | false | 0.041684 | 0.042037 | 0.991595 | [
"s102832035",
"s598756020"
] |
u954153335 | p02681 | python | s013853075 | s218781067 | 23 | 21 | 9,036 | 8,796 | Accepted | Accepted | 8.7 | S=eval(input(""))
T=eval(input(""))
l=len(S)
if 1<=l and l<=10 and S.islower()==True and S==T[:-1]:
print("Yes")
else:
print("No") | S=eval(input())
T=eval(input())
l=len(S)
if S==T[:-1] and S.islower()==True and 1<=l and l<=10:
print("Yes")
else:
print("No") | 7 | 7 | 130 | 124 | S = eval(input(""))
T = eval(input(""))
l = len(S)
if 1 <= l and l <= 10 and S.islower() == True and S == T[:-1]:
print("Yes")
else:
print("No")
| S = eval(input())
T = eval(input())
l = len(S)
if S == T[:-1] and S.islower() == True and 1 <= l and l <= 10:
print("Yes")
else:
print("No")
| false | 0 | [
"-S = eval(input(\"\"))",
"-T = eval(input(\"\"))",
"+S = eval(input())",
"+T = eval(input())",
"-if 1 <= l and l <= 10 and S.islower() == True and S == T[:-1]:",
"+if S == T[:-1] and S.islower() == True and 1 <= l and l <= 10:"
] | false | 0.045069 | 0.071144 | 0.633494 | [
"s013853075",
"s218781067"
] |
u047796752 | p02616 | python | s514448802 | s319950023 | 197 | 140 | 113,004 | 115,320 | Accepted | Accepted | 28.93 | import sys
input = sys.stdin.readline
from collections import *
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10**9+7
p, n = [], []
for Ai in A:
if Ai>=0:
p.append(Ai)
else:
n.append(Ai)
if len(p)==0 and K%2==1:
if 0 in A:
print((0))
else:
n.sort(reverse=True)
ans = 1
for ni in n[:K]:
ans *= ni
ans %= MOD
print(ans)
exit()
if K==N:
ans = 1
for Ai in A:
ans *= Ai
ans %= MOD
print(ans)
exit()
p.sort(reverse=True)
n.sort()
if K%2==0:
l = []
for i in range(len(p)//2):
l.append(p[2*i]*p[2*i+1])
for i in range(len(n)//2):
l.append(n[2*i]*n[2*i+1])
l.sort(key=lambda x: abs(x), reverse=True)
ans = 1
for i in range(K//2):
ans *= l[i]
ans %= MOD
else:
ans = p[0]
p = p[1:]
l = []
for i in range(len(p)//2):
l.append(p[2*i]*p[2*i+1])
for i in range(len(n)//2):
l.append(n[2*i]*n[2*i+1])
l.sort(key=lambda x: abs(x), reverse=True)
for i in range((K-1)//2):
ans *= l[i]
ans %= MOD
print(ans)
| import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10**9+7
p, n = [], []
for Ai in A:
if Ai>=0:
p.append(Ai)
else:
n.append(Ai)
if len(n)==N and K%2==1:
n.sort(reverse=True)
ans = 1
for ni in n[:K]:
ans *= ni
ans %= MOD
print(ans)
exit()
if K==N and len(n)%2==1:
ans = 1
for Ai in A:
ans *= Ai
ans %= MOD
print(ans)
exit()
p.sort(reverse=True)
n.sort()
l = []
if K%2==1:
ans = p[0]
p = p[1:]
else:
ans = 1
for i in range(len(p)//2):
l.append(p[2*i]*p[2*i+1])
for i in range(len(n)//2):
l.append(n[2*i]*n[2*i+1])
l.sort(reverse=True)
for li in l[:K//2]:
ans *= li
ans %= MOD
print(ans)
| 75 | 58 | 1,311 | 875 | import sys
input = sys.stdin.readline
from collections import *
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
p, n = [], []
for Ai in A:
if Ai >= 0:
p.append(Ai)
else:
n.append(Ai)
if len(p) == 0 and K % 2 == 1:
if 0 in A:
print((0))
else:
n.sort(reverse=True)
ans = 1
for ni in n[:K]:
ans *= ni
ans %= MOD
print(ans)
exit()
if K == N:
ans = 1
for Ai in A:
ans *= Ai
ans %= MOD
print(ans)
exit()
p.sort(reverse=True)
n.sort()
if K % 2 == 0:
l = []
for i in range(len(p) // 2):
l.append(p[2 * i] * p[2 * i + 1])
for i in range(len(n) // 2):
l.append(n[2 * i] * n[2 * i + 1])
l.sort(key=lambda x: abs(x), reverse=True)
ans = 1
for i in range(K // 2):
ans *= l[i]
ans %= MOD
else:
ans = p[0]
p = p[1:]
l = []
for i in range(len(p) // 2):
l.append(p[2 * i] * p[2 * i + 1])
for i in range(len(n) // 2):
l.append(n[2 * i] * n[2 * i + 1])
l.sort(key=lambda x: abs(x), reverse=True)
for i in range((K - 1) // 2):
ans *= l[i]
ans %= MOD
print(ans)
| import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
p, n = [], []
for Ai in A:
if Ai >= 0:
p.append(Ai)
else:
n.append(Ai)
if len(n) == N and K % 2 == 1:
n.sort(reverse=True)
ans = 1
for ni in n[:K]:
ans *= ni
ans %= MOD
print(ans)
exit()
if K == N and len(n) % 2 == 1:
ans = 1
for Ai in A:
ans *= Ai
ans %= MOD
print(ans)
exit()
p.sort(reverse=True)
n.sort()
l = []
if K % 2 == 1:
ans = p[0]
p = p[1:]
else:
ans = 1
for i in range(len(p) // 2):
l.append(p[2 * i] * p[2 * i + 1])
for i in range(len(n) // 2):
l.append(n[2 * i] * n[2 * i + 1])
l.sort(reverse=True)
for li in l[: K // 2]:
ans *= li
ans %= MOD
print(ans)
| false | 22.666667 | [
"-from collections import *",
"-",
"-if len(p) == 0 and K % 2 == 1:",
"- if 0 in A:",
"- print((0))",
"- else:",
"- n.sort(reverse=True)",
"- ans = 1",
"- for ni in n[:K]:",
"- ans *= ni",
"- ans %= MOD",
"- print(ans)",
"+if len(n) == N and K % 2 == 1:",
"+ n.sort(reverse=True)",
"+ ans = 1",
"+ for ni in n[:K]:",
"+ ans *= ni",
"+ ans %= MOD",
"+ print(ans)",
"-if K == N:",
"+if K == N and len(n) % 2 == 1:",
"-if K % 2 == 0:",
"- l = []",
"- for i in range(len(p) // 2):",
"- l.append(p[2 * i] * p[2 * i + 1])",
"- for i in range(len(n) // 2):",
"- l.append(n[2 * i] * n[2 * i + 1])",
"- l.sort(key=lambda x: abs(x), reverse=True)",
"- ans = 1",
"- for i in range(K // 2):",
"- ans *= l[i]",
"- ans %= MOD",
"-else:",
"+l = []",
"+if K % 2 == 1:",
"- l = []",
"- for i in range(len(p) // 2):",
"- l.append(p[2 * i] * p[2 * i + 1])",
"- for i in range(len(n) // 2):",
"- l.append(n[2 * i] * n[2 * i + 1])",
"- l.sort(key=lambda x: abs(x), reverse=True)",
"- for i in range((K - 1) // 2):",
"- ans *= l[i]",
"- ans %= MOD",
"+else:",
"+ ans = 1",
"+for i in range(len(p) // 2):",
"+ l.append(p[2 * i] * p[2 * i + 1])",
"+for i in range(len(n) // 2):",
"+ l.append(n[2 * i] * n[2 * i + 1])",
"+l.sort(reverse=True)",
"+for li in l[: K // 2]:",
"+ ans *= li",
"+ ans %= MOD"
] | false | 0.208559 | 0.035483 | 5.877694 | [
"s514448802",
"s319950023"
] |
u271934630 | p03262 | python | s070588431 | s265348422 | 355 | 132 | 89,364 | 17,180 | Accepted | Accepted | 62.82 | from functools import reduce
from fractions import gcd
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
x.append(X)
town = sorted(x)
print((reduce(gcd, [town[i+1] - town[i] for i in range(len(town)-1)])))
| import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
from functools import reduce
i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()
def gcd(a,b):
while b:
a, b = b, a%b
return a
def gcd_list(l):
return reduce(gcd, l)
N, X = i_l()
x = i_l()
arr = []
for i in range(N-1):
arr.append(abs(x[i]-x[i+1]))
x = gcd_list(arr + [abs(x-X) for x in x])
print(x) | 9 | 27 | 233 | 483 | from functools import reduce
from fractions import gcd
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
x.append(X)
town = sorted(x)
print((reduce(gcd, [town[i + 1] - town[i] for i in range(len(town) - 1)])))
| import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
from functools import reduce
i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()
def gcd(a, b):
while b:
a, b = b, a % b
return a
def gcd_list(l):
return reduce(gcd, l)
N, X = i_l()
x = i_l()
arr = []
for i in range(N - 1):
arr.append(abs(x[i] - x[i + 1]))
x = gcd_list(arr + [abs(x - X) for x in x])
print(x)
| false | 66.666667 | [
"+import sys",
"+",
"+stdin = sys.stdin",
"+sys.setrecursionlimit(10**7)",
"-from fractions import gcd",
"-N, X = list(map(int, input().split()))",
"-x = list(map(int, input().split()))",
"-x.append(X)",
"-town = sorted(x)",
"-print((reduce(gcd, [town[i + 1] - town[i] for i in range(len(town) - 1)])))",
"+i_i = lambda: int(i_s())",
"+i_l = lambda: list(map(int, stdin.readline().split()))",
"+i_s = lambda: stdin.readline().rstrip()",
"+",
"+",
"+def gcd(a, b):",
"+ while b:",
"+ a, b = b, a % b",
"+ return a",
"+",
"+",
"+def gcd_list(l):",
"+ return reduce(gcd, l)",
"+",
"+",
"+N, X = i_l()",
"+x = i_l()",
"+arr = []",
"+for i in range(N - 1):",
"+ arr.append(abs(x[i] - x[i + 1]))",
"+x = gcd_list(arr + [abs(x - X) for x in x])",
"+print(x)"
] | false | 0.04676 | 0.141696 | 0.330004 | [
"s070588431",
"s265348422"
] |
u997521090 | p03128 | python | s225188170 | s671136738 | 62 | 43 | 3,448 | 3,576 | Accepted | Accepted | 30.65 | #!/usr/bin/env python
from collections import deque
import itertools as it
import sys
import math
sys.setrecursionlimit(1000000)
INF = 10 ** 18
N, M = list(map(int, input().split()))
cost = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
A = list(map(int, input().split()))
DP = [0] + [-1] * N
ans = [0] * N + [0]
for i in range(1, N + 1):
for j in range(10)[::-1]:
if not j in A:
continue
if cost[j] > i:
continue
if DP[i - cost[j]] < 0:
continue
if DP[i] < DP[i - cost[j]] + 1:
DP[i] = DP[i - cost[j]] + 1
ans[i] = j
S = ""
pos = N
while pos != 0:
S += str(ans[pos])
pos -= cost[ans[pos]]
print(S) | #!/usr/bin/env python
from collections import deque
import itertools as it
import sys
import math
sys.setrecursionlimit(1000000)
INF = 10 ** 18
N, M = list(map(int, input().split()))
cost = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
A = sorted(map(int, input().split()))
DP = [0] + [-1] * N
ans = [0, 0] * N
for i in range(1, N + 1):
for j in A:
pos = i - cost[j]
if pos < 0 or DP[pos] < 0:
continue
if DP[i] <= DP[pos] + 1:
DP[i] = DP[pos] + 1
ans[i] = j
S = ""
pos = N
while pos:
S += str(ans[pos])
pos -= cost[ans[pos]]
print(S) | 37 | 34 | 740 | 648 | #!/usr/bin/env python
from collections import deque
import itertools as it
import sys
import math
sys.setrecursionlimit(1000000)
INF = 10**18
N, M = list(map(int, input().split()))
cost = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
A = list(map(int, input().split()))
DP = [0] + [-1] * N
ans = [0] * N + [0]
for i in range(1, N + 1):
for j in range(10)[::-1]:
if not j in A:
continue
if cost[j] > i:
continue
if DP[i - cost[j]] < 0:
continue
if DP[i] < DP[i - cost[j]] + 1:
DP[i] = DP[i - cost[j]] + 1
ans[i] = j
S = ""
pos = N
while pos != 0:
S += str(ans[pos])
pos -= cost[ans[pos]]
print(S)
| #!/usr/bin/env python
from collections import deque
import itertools as it
import sys
import math
sys.setrecursionlimit(1000000)
INF = 10**18
N, M = list(map(int, input().split()))
cost = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
A = sorted(map(int, input().split()))
DP = [0] + [-1] * N
ans = [0, 0] * N
for i in range(1, N + 1):
for j in A:
pos = i - cost[j]
if pos < 0 or DP[pos] < 0:
continue
if DP[i] <= DP[pos] + 1:
DP[i] = DP[pos] + 1
ans[i] = j
S = ""
pos = N
while pos:
S += str(ans[pos])
pos -= cost[ans[pos]]
print(S)
| false | 8.108108 | [
"-A = list(map(int, input().split()))",
"+A = sorted(map(int, input().split()))",
"-ans = [0] * N + [0]",
"+ans = [0, 0] * N",
"- for j in range(10)[::-1]:",
"- if not j in A:",
"+ for j in A:",
"+ pos = i - cost[j]",
"+ if pos < 0 or DP[pos] < 0:",
"- if cost[j] > i:",
"- continue",
"- if DP[i - cost[j]] < 0:",
"- continue",
"- if DP[i] < DP[i - cost[j]] + 1:",
"- DP[i] = DP[i - cost[j]] + 1",
"+ if DP[i] <= DP[pos] + 1:",
"+ DP[i] = DP[pos] + 1",
"-while pos != 0:",
"+while pos:"
] | false | 0.036031 | 0.041871 | 0.860527 | [
"s225188170",
"s671136738"
] |
u596505843 | p02579 | python | s973100650 | s089064477 | 1,401 | 543 | 123,920 | 100,472 | Accepted | Accepted | 61.24 | import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
#from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)
import heapq
def dijkstra(start, end):
#dist = defaultdict(lambda: float('inf'))
dist = [[float('inf')]*W for _ in range(H)]
dist[start[0]][start[1]] = 0
heap = []
heapq.heappush(heap, (0, start))
while heap:
d, n = heapq.heappop(heap)
if n == end:
return d
if dist[n[0]][n[1]] != d:
continue
edges = get_edges(n)
for nn, ed in edges:
nd = d + ed
ni, nj = nn
if dist[ni][nj] > nd:
dist[ni][nj] = nd
heapq.heappush(heap, (nd, nn))
return -1
def get_edges(n):
i, j = n
edges = []
if M[i][j] == '#': return edges
for di, dj in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
ni, nj = i+di, j+dj
if not (0 <= ni < H and 0 <= nj < W): continue
if M[ni][nj] == '#': continue
edges.append(((ni, nj), 0))
for di in range(-2, +3):
for dj in range(-2, +3):
ni, nj = i+di, j+dj
if di == 0 and dj == 0: continue
if (di, dj) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
continue
if not(0 <= ni < H and 0 <= nj < W): continue
if M[ni][nj] == '#': continue
edges.append(((ni, nj), 1))
return edges
H, W = rl()
C = rl()
D = rl()
M = []
for i in range(H):
s = rs()
M.append(s)
start = tuple([C[0]-1, C[1]-1])
end = tuple([D[0]-1, D[1]-1])
d = dijkstra(start, end)
print(d)
| import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
narr = lambda d, f: narr(d[:-1], lambda: [f() for _ in range(d[-1])]) if d else f() # narr((2,3), int)
mod = 1000000007
sys.setrecursionlimit(1000000)
H, W = rl()
C = rl()
D = rl()
M = []
for i in range(H):
s = rs()
M.append(s)
start = tuple([C[0]-1, C[1]-1])
end = tuple([D[0]-1, D[1]-1])
queue = deque()
queue.append((start, 0))
visited = narr((H, W), lambda: float('inf'))
visited[start[0]][start[1]] = 0
ds = [(1,0),(-1,0),(0,1),(0,-1)]
while queue:
n, d = queue.popleft()
if n == end:
print(d)
exit()
i, j = n
if visited[i][j] != d:
continue
nd = d
for di, dj in ds:
ni, nj = i+di, j+dj
if not (0 <= ni < H and 0 <= nj < W): continue
if M[ni][nj] == '#': continue
if nd < visited[ni][nj]:
queue.appendleft(((ni,nj), nd))
visited[ni][nj] = nd
nd = d+1
for di in range(-2, 3):
for dj in range(-2, 3):
if (di, dj) == (0,0): continue
ni, nj = i+di, j+dj
if not (0 <= ni < H and 0 <= nj < W): continue
if M[ni][nj] == '#': continue
if nd < visited[ni][nj]:
queue.append(((ni,nj), nd))
visited[ni][nj] = nd
print((-1))
| 67 | 58 | 1,704 | 1,499 | import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
# from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)
import heapq
def dijkstra(start, end):
# dist = defaultdict(lambda: float('inf'))
dist = [[float("inf")] * W for _ in range(H)]
dist[start[0]][start[1]] = 0
heap = []
heapq.heappush(heap, (0, start))
while heap:
d, n = heapq.heappop(heap)
if n == end:
return d
if dist[n[0]][n[1]] != d:
continue
edges = get_edges(n)
for nn, ed in edges:
nd = d + ed
ni, nj = nn
if dist[ni][nj] > nd:
dist[ni][nj] = nd
heapq.heappush(heap, (nd, nn))
return -1
def get_edges(n):
i, j = n
edges = []
if M[i][j] == "#":
return edges
for di, dj in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
ni, nj = i + di, j + dj
if not (0 <= ni < H and 0 <= nj < W):
continue
if M[ni][nj] == "#":
continue
edges.append(((ni, nj), 0))
for di in range(-2, +3):
for dj in range(-2, +3):
ni, nj = i + di, j + dj
if di == 0 and dj == 0:
continue
if (di, dj) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
continue
if not (0 <= ni < H and 0 <= nj < W):
continue
if M[ni][nj] == "#":
continue
edges.append(((ni, nj), 1))
return edges
H, W = rl()
C = rl()
D = rl()
M = []
for i in range(H):
s = rs()
M.append(s)
start = tuple([C[0] - 1, C[1] - 1])
end = tuple([D[0] - 1, D[1] - 1])
d = dijkstra(start, end)
print(d)
| import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
narr = (
lambda d, f: narr(d[:-1], lambda: [f() for _ in range(d[-1])]) if d else f()
) # narr((2,3), int)
mod = 1000000007
sys.setrecursionlimit(1000000)
H, W = rl()
C = rl()
D = rl()
M = []
for i in range(H):
s = rs()
M.append(s)
start = tuple([C[0] - 1, C[1] - 1])
end = tuple([D[0] - 1, D[1] - 1])
queue = deque()
queue.append((start, 0))
visited = narr((H, W), lambda: float("inf"))
visited[start[0]][start[1]] = 0
ds = [(1, 0), (-1, 0), (0, 1), (0, -1)]
while queue:
n, d = queue.popleft()
if n == end:
print(d)
exit()
i, j = n
if visited[i][j] != d:
continue
nd = d
for di, dj in ds:
ni, nj = i + di, j + dj
if not (0 <= ni < H and 0 <= nj < W):
continue
if M[ni][nj] == "#":
continue
if nd < visited[ni][nj]:
queue.appendleft(((ni, nj), nd))
visited[ni][nj] = nd
nd = d + 1
for di in range(-2, 3):
for dj in range(-2, 3):
if (di, dj) == (0, 0):
continue
ni, nj = i + di, j + dj
if not (0 <= ni < H and 0 <= nj < W):
continue
if M[ni][nj] == "#":
continue
if nd < visited[ni][nj]:
queue.append(((ni, nj), nd))
visited[ni][nj] = nd
print((-1))
| false | 13.432836 | [
"-",
"-# from heapq import heappush, heappop",
"+from heapq import heappush, heappop",
"+narr = (",
"+ lambda d, f: narr(d[:-1], lambda: [f() for _ in range(d[-1])]) if d else f()",
"+) # narr((2,3), int)",
"-import heapq",
"-",
"-",
"-def dijkstra(start, end):",
"- # dist = defaultdict(lambda: float('inf'))",
"- dist = [[float(\"inf\")] * W for _ in range(H)]",
"- dist[start[0]][start[1]] = 0",
"- heap = []",
"- heapq.heappush(heap, (0, start))",
"- while heap:",
"- d, n = heapq.heappop(heap)",
"- if n == end:",
"- return d",
"- if dist[n[0]][n[1]] != d:",
"- continue",
"- edges = get_edges(n)",
"- for nn, ed in edges:",
"- nd = d + ed",
"- ni, nj = nn",
"- if dist[ni][nj] > nd:",
"- dist[ni][nj] = nd",
"- heapq.heappush(heap, (nd, nn))",
"- return -1",
"-",
"-",
"-def get_edges(n):",
"- i, j = n",
"- edges = []",
"- if M[i][j] == \"#\":",
"- return edges",
"- for di, dj in [(1, 0), (-1, 0), (0, 1), (0, -1)]:",
"- ni, nj = i + di, j + dj",
"- if not (0 <= ni < H and 0 <= nj < W):",
"- continue",
"- if M[ni][nj] == \"#\":",
"- continue",
"- edges.append(((ni, nj), 0))",
"- for di in range(-2, +3):",
"- for dj in range(-2, +3):",
"- ni, nj = i + di, j + dj",
"- if di == 0 and dj == 0:",
"- continue",
"- if (di, dj) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:",
"- continue",
"- if not (0 <= ni < H and 0 <= nj < W):",
"- continue",
"- if M[ni][nj] == \"#\":",
"- continue",
"- edges.append(((ni, nj), 1))",
"- return edges",
"-",
"-",
"-d = dijkstra(start, end)",
"-print(d)",
"+queue = deque()",
"+queue.append((start, 0))",
"+visited = narr((H, W), lambda: float(\"inf\"))",
"+visited[start[0]][start[1]] = 0",
"+ds = [(1, 0), (-1, 0), (0, 1), (0, -1)]",
"+while queue:",
"+ n, d = queue.popleft()",
"+ if n == end:",
"+ print(d)",
"+ exit()",
"+ i, j = n",
"+ if visited[i][j] != d:",
"+ continue",
"+ nd = d",
"+ for di, dj in ds:",
"+ ni, nj = i + di, j + dj",
"+ if not (0 <= ni < H and 0 <= nj < W):",
"+ continue",
"+ if M[ni][nj] == \"#\":",
"+ continue",
"+ if nd < visited[ni][nj]:",
"+ queue.appendleft(((ni, nj), nd))",
"+ visited[ni][nj] = nd",
"+ nd = d + 1",
"+ for di in range(-2, 3):",
"+ for dj in range(-2, 3):",
"+ if (di, dj) == (0, 0):",
"+ continue",
"+ ni, nj = i + di, j + dj",
"+ if not (0 <= ni < H and 0 <= nj < W):",
"+ continue",
"+ if M[ni][nj] == \"#\":",
"+ continue",
"+ if nd < visited[ni][nj]:",
"+ queue.append(((ni, nj), nd))",
"+ visited[ni][nj] = nd",
"+print((-1))"
] | false | 0.071612 | 0.070364 | 1.017744 | [
"s973100650",
"s089064477"
] |
u343675824 | p04014 | python | s020916796 | s789079615 | 353 | 216 | 3,188 | 41,584 | Accepted | Accepted | 38.81 | import math
import sys
n = int(eval(input()))
s = int(eval(input()))
def f(b, n):
if n == 0:
return 0
return f(b, n//b) + n % b
if s > n:
print((-1))
sys.exit(0)
sn = math.ceil(math.sqrt(n))
for i in range(2, sn+1):
if f(i, n) == s:
print(i)
sys.exit(0)
ans = n + 1
for i in range(1, sn+1):
if (n - s) % i == 0:
b = (n-s)//i + 1
if b >= 2 and f(b, b * i + n%b) == s:
ans = min((ans, b))
if s == n:
print((n+1))
elif ans < n + 1:
print(ans)
else:
print((-1))
| import sys
n = int(eval(input()))
s = int(eval(input()))
def f(b, n):
if n < b:
return n
else:
return f(b, n//b) + n % b
if s == n:
print((n+1))
sys.exit(0)
if n < s:
print((-1))
sys.exit(0)
ans = None
for i in range(2, n):
if i * i > n:
break
if f(i, n) == s:
ans = i
break
for i in range(1, n):
if i * i > n:
break
if (n - s) % i == 0:
b = (n - s) // i + 1
if f(b, n) == s:
if ans is None:
ans = (n - s) // i + 1
else:
ans = min((ans, (n - s) // i + 1))
if ans is None:
print((-1))
else:
print(ans)
| 33 | 39 | 565 | 698 | import math
import sys
n = int(eval(input()))
s = int(eval(input()))
def f(b, n):
if n == 0:
return 0
return f(b, n // b) + n % b
if s > n:
print((-1))
sys.exit(0)
sn = math.ceil(math.sqrt(n))
for i in range(2, sn + 1):
if f(i, n) == s:
print(i)
sys.exit(0)
ans = n + 1
for i in range(1, sn + 1):
if (n - s) % i == 0:
b = (n - s) // i + 1
if b >= 2 and f(b, b * i + n % b) == s:
ans = min((ans, b))
if s == n:
print((n + 1))
elif ans < n + 1:
print(ans)
else:
print((-1))
| import sys
n = int(eval(input()))
s = int(eval(input()))
def f(b, n):
if n < b:
return n
else:
return f(b, n // b) + n % b
if s == n:
print((n + 1))
sys.exit(0)
if n < s:
print((-1))
sys.exit(0)
ans = None
for i in range(2, n):
if i * i > n:
break
if f(i, n) == s:
ans = i
break
for i in range(1, n):
if i * i > n:
break
if (n - s) % i == 0:
b = (n - s) // i + 1
if f(b, n) == s:
if ans is None:
ans = (n - s) // i + 1
else:
ans = min((ans, (n - s) // i + 1))
if ans is None:
print((-1))
else:
print(ans)
| false | 15.384615 | [
"-import math",
"- if n == 0:",
"- return 0",
"- return f(b, n // b) + n % b",
"+ if n < b:",
"+ return n",
"+ else:",
"+ return f(b, n // b) + n % b",
"-if s > n:",
"+if s == n:",
"+ print((n + 1))",
"+ sys.exit(0)",
"+if n < s:",
"-sn = math.ceil(math.sqrt(n))",
"-for i in range(2, sn + 1):",
"+ans = None",
"+for i in range(2, n):",
"+ if i * i > n:",
"+ break",
"- print(i)",
"- sys.exit(0)",
"-ans = n + 1",
"-for i in range(1, sn + 1):",
"+ ans = i",
"+ break",
"+for i in range(1, n):",
"+ if i * i > n:",
"+ break",
"- if b >= 2 and f(b, b * i + n % b) == s:",
"- ans = min((ans, b))",
"-if s == n:",
"- print((n + 1))",
"-elif ans < n + 1:",
"+ if f(b, n) == s:",
"+ if ans is None:",
"+ ans = (n - s) // i + 1",
"+ else:",
"+ ans = min((ans, (n - s) // i + 1))",
"+if ans is None:",
"+ print((-1))",
"+else:",
"-else:",
"- print((-1))"
] | false | 0.06664 | 0.093506 | 0.712679 | [
"s020916796",
"s789079615"
] |
u761989513 | p03805 | python | s600280120 | s706317582 | 68 | 30 | 3,064 | 3,064 | Accepted | Accepted | 55.88 | import itertools
def sonzai(path, start, goal):
for i in path:
if start in i:
if start > goal:
if i[0] == goal:
return True
else:
if i[1] == goal:
return True
return False
n, m = list(map(int, input().split()))
path = []
for i in range(m):
a, b = list(map(int, input().split()))
path.append([a, b])
ans = 0
for i in itertools.permutations(list(range(2, n + 1))):
if not sonzai(path, 1, i[0]):
continue
for j in range(n - 1):
if j == n - 2:
ans += 1
break
if not sonzai(path, i[j], i[j + 1]):
break
print(ans) | import itertools
n, m = list(map(int, input().split()))
graph = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
graph[a - 1][b - 1] = 1
graph[b - 1][a - 1] = 1
ans = 0
for i in itertools.permutations(list(range(2, n + 1))):
if not graph[0][i[0] - 1]:
continue
for j in range(n - 1):
if j == n - 2:
ans += 1
break
if not graph[i[j] - 1][i[j + 1] - 1]:
break
print(ans) | 29 | 19 | 708 | 500 | import itertools
def sonzai(path, start, goal):
for i in path:
if start in i:
if start > goal:
if i[0] == goal:
return True
else:
if i[1] == goal:
return True
return False
n, m = list(map(int, input().split()))
path = []
for i in range(m):
a, b = list(map(int, input().split()))
path.append([a, b])
ans = 0
for i in itertools.permutations(list(range(2, n + 1))):
if not sonzai(path, 1, i[0]):
continue
for j in range(n - 1):
if j == n - 2:
ans += 1
break
if not sonzai(path, i[j], i[j + 1]):
break
print(ans)
| import itertools
n, m = list(map(int, input().split()))
graph = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
graph[a - 1][b - 1] = 1
graph[b - 1][a - 1] = 1
ans = 0
for i in itertools.permutations(list(range(2, n + 1))):
if not graph[0][i[0] - 1]:
continue
for j in range(n - 1):
if j == n - 2:
ans += 1
break
if not graph[i[j] - 1][i[j + 1] - 1]:
break
print(ans)
| false | 34.482759 | [
"-",
"-def sonzai(path, start, goal):",
"- for i in path:",
"- if start in i:",
"- if start > goal:",
"- if i[0] == goal:",
"- return True",
"- else:",
"- if i[1] == goal:",
"- return True",
"- return False",
"-",
"-",
"-path = []",
"+graph = [[0 for i in range(n)] for j in range(n)]",
"- path.append([a, b])",
"+ graph[a - 1][b - 1] = 1",
"+ graph[b - 1][a - 1] = 1",
"- if not sonzai(path, 1, i[0]):",
"+ if not graph[0][i[0] - 1]:",
"- if not sonzai(path, i[j], i[j + 1]):",
"+ if not graph[i[j] - 1][i[j + 1] - 1]:"
] | false | 0.100439 | 0.041904 | 2.396905 | [
"s600280120",
"s706317582"
] |
u878389297 | p02647 | python | s813203334 | s856277091 | 1,161 | 294 | 138,732 | 157,872 | Accepted | Accepted | 74.68 | from numba import njit
@njit(cache=True)
def aaa(n,k,a):
for f in range(k):
a1=[0]*(n+1)
for x in range(n):
y=max(0,x-a[x])
a1[y]=a1[y]+1
z=min(n-1,x+a[x])
a1[z+1]=a1[z+1]-1
a[0]=a1[0]
for x in range(1,n):
a[x]=a[x-1]+a1[x]
if a==[n]*n:
break
return a
x=eval(input())
x0=x.split()
n=int(x0[0])
k=int(x0[1])
a0=eval(input())
a0=a0.split()
a=[int(s) for s in a0]
b=aaa(n,k,a)
for i in range(n):
print((b[i])) | def aaa(n,k,a):
for f in range(k):
a1=[0]*(n+1)
for x in range(n):
y=max(0,x-a[x])
a1[y]=a1[y]+1
z=min(n-1,x+a[x])
a1[z+1]=a1[z+1]-1
a[0]=a1[0]
for x in range(1,n):
a[x]=a[x-1]+a1[x]
if a==[n]*n:
break
return a
x=eval(input())
x0=x.split()
n=int(x0[0])
k=int(x0[1])
a0=eval(input())
a0=a0.split()
a=[int(s) for s in a0]
b=aaa(n,k,a)
for i in range(n):
print((b[i]))
| 29 | 26 | 555 | 511 | from numba import njit
@njit(cache=True)
def aaa(n, k, a):
for f in range(k):
a1 = [0] * (n + 1)
for x in range(n):
y = max(0, x - a[x])
a1[y] = a1[y] + 1
z = min(n - 1, x + a[x])
a1[z + 1] = a1[z + 1] - 1
a[0] = a1[0]
for x in range(1, n):
a[x] = a[x - 1] + a1[x]
if a == [n] * n:
break
return a
x = eval(input())
x0 = x.split()
n = int(x0[0])
k = int(x0[1])
a0 = eval(input())
a0 = a0.split()
a = [int(s) for s in a0]
b = aaa(n, k, a)
for i in range(n):
print((b[i]))
| def aaa(n, k, a):
for f in range(k):
a1 = [0] * (n + 1)
for x in range(n):
y = max(0, x - a[x])
a1[y] = a1[y] + 1
z = min(n - 1, x + a[x])
a1[z + 1] = a1[z + 1] - 1
a[0] = a1[0]
for x in range(1, n):
a[x] = a[x - 1] + a1[x]
if a == [n] * n:
break
return a
x = eval(input())
x0 = x.split()
n = int(x0[0])
k = int(x0[1])
a0 = eval(input())
a0 = a0.split()
a = [int(s) for s in a0]
b = aaa(n, k, a)
for i in range(n):
print((b[i]))
| false | 10.344828 | [
"-from numba import njit",
"-",
"-",
"-@njit(cache=True)"
] | false | 0.116511 | 0.10863 | 1.072549 | [
"s813203334",
"s856277091"
] |
u190405389 | p03206 | python | s877978253 | s948689974 | 182 | 163 | 38,256 | 38,256 | Accepted | Accepted | 10.44 | d = int(eval(input()))
print(('Christmas' + (25-d)*' Eve')) | print(('Christmas'+(25-int(eval(input())))*' Eve')) | 2 | 1 | 52 | 43 | d = int(eval(input()))
print(("Christmas" + (25 - d) * " Eve"))
| print(("Christmas" + (25 - int(eval(input()))) * " Eve"))
| false | 50 | [
"-d = int(eval(input()))",
"-print((\"Christmas\" + (25 - d) * \" Eve\"))",
"+print((\"Christmas\" + (25 - int(eval(input()))) * \" Eve\"))"
] | false | 0.062443 | 0.063205 | 0.987951 | [
"s877978253",
"s948689974"
] |
u133936772 | p02796 | python | s799665636 | s361155713 | 492 | 455 | 20,876 | 22,104 | Accepted | Accepted | 7.52 | n = int(eval(input()))
ll = []
for i in range(n):
x, l = list(map(int, input().split()))
ll.append([x-l, x+l])
ll = sorted(ll)
ans = n
r = ll.pop()[0]
while ll:
while ll and ll[-1][1] > r:
ans -= 1
ll.pop()
if ll:
r = ll.pop()[0]
print(ans) | n = int(eval(input()))
ll = []
for i in range(n):
x, l = list(map(int, input().split()))
ll.append([x-l, x+l])
ll = sorted(ll, key=lambda x: x[1])
ans = 0
tmp = -10**9
for s, t in ll:
if s >= tmp:
ans += 1
tmp = t
print(ans) | 18 | 16 | 268 | 244 | n = int(eval(input()))
ll = []
for i in range(n):
x, l = list(map(int, input().split()))
ll.append([x - l, x + l])
ll = sorted(ll)
ans = n
r = ll.pop()[0]
while ll:
while ll and ll[-1][1] > r:
ans -= 1
ll.pop()
if ll:
r = ll.pop()[0]
print(ans)
| n = int(eval(input()))
ll = []
for i in range(n):
x, l = list(map(int, input().split()))
ll.append([x - l, x + l])
ll = sorted(ll, key=lambda x: x[1])
ans = 0
tmp = -(10**9)
for s, t in ll:
if s >= tmp:
ans += 1
tmp = t
print(ans)
| false | 11.111111 | [
"-ll = sorted(ll)",
"-ans = n",
"-r = ll.pop()[0]",
"-while ll:",
"- while ll and ll[-1][1] > r:",
"- ans -= 1",
"- ll.pop()",
"- if ll:",
"- r = ll.pop()[0]",
"+ll = sorted(ll, key=lambda x: x[1])",
"+ans = 0",
"+tmp = -(10**9)",
"+for s, t in ll:",
"+ if s >= tmp:",
"+ ans += 1",
"+ tmp = t"
] | false | 0.048667 | 0.036464 | 1.334658 | [
"s799665636",
"s361155713"
] |
u968166680 | p02971 | python | s469013233 | s995073165 | 332 | 141 | 42,980 | 33,440 | Accepted | Accepted | 57.53 | import sys
from operator import itemgetter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *A = map(int, read().split())
B = [(i, a) for i, a in enumerate(A)]
B.sort(key=itemgetter(1))
ans = [0] * N
for i, a in B[:-1]:
ans[i] = B[-1][1]
ans[B[-1][0]] = B[-2][1]
print(*ans, sep='\n')
return
if __name__ == '__main__':
main()
| import sys
from operator import itemgetter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *A = list(map(int, read().split()))
a_max = max(A)
max_count = A.count(a_max)
for a in A:
if a != a_max:
print(a_max)
elif max_count > 1:
print(a_max)
else:
B = A[:]
B.remove(a_max)
print((max(B)))
return
if __name__ == '__main__':
main()
| 29 | 31 | 539 | 580 | import sys
from operator import itemgetter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *A = map(int, read().split())
B = [(i, a) for i, a in enumerate(A)]
B.sort(key=itemgetter(1))
ans = [0] * N
for i, a in B[:-1]:
ans[i] = B[-1][1]
ans[B[-1][0]] = B[-2][1]
print(*ans, sep="\n")
return
if __name__ == "__main__":
main()
| import sys
from operator import itemgetter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *A = list(map(int, read().split()))
a_max = max(A)
max_count = A.count(a_max)
for a in A:
if a != a_max:
print(a_max)
elif max_count > 1:
print(a_max)
else:
B = A[:]
B.remove(a_max)
print((max(B)))
return
if __name__ == "__main__":
main()
| false | 6.451613 | [
"- N, *A = map(int, read().split())",
"- B = [(i, a) for i, a in enumerate(A)]",
"- B.sort(key=itemgetter(1))",
"- ans = [0] * N",
"- for i, a in B[:-1]:",
"- ans[i] = B[-1][1]",
"- ans[B[-1][0]] = B[-2][1]",
"- print(*ans, sep=\"\\n\")",
"+ N, *A = list(map(int, read().split()))",
"+ a_max = max(A)",
"+ max_count = A.count(a_max)",
"+ for a in A:",
"+ if a != a_max:",
"+ print(a_max)",
"+ elif max_count > 1:",
"+ print(a_max)",
"+ else:",
"+ B = A[:]",
"+ B.remove(a_max)",
"+ print((max(B)))"
] | false | 0.034353 | 0.041865 | 0.820578 | [
"s469013233",
"s995073165"
] |
u491550356 | p02608 | python | s441215421 | s091981959 | 441 | 223 | 9,320 | 9,144 | Accepted | Accepted | 49.43 | N = int(eval(input()))
ans = [0] * (N+1)
for a in range(1, 105):
if a*a > N :
continue
for b in range(1, 105):
if a*a + b*b > N:
continue
for c in range(1, 105):
if a*a + b*b + c*c + a*b + b*c + c*a > N:
continue
ans[a*a + b*b + c*c + a*b + b*c + c*a] += 1
for i in range(1, N+1):
print((ans[i])) | N = int(eval(input()))
ans = [0] * (N+1)
for a in range(1, 105):
if a*a > N :
break
for b in range(1, 105):
if a*a + b*b > N:
break
for c in range(1, 105):
if a*a + b*b + c*c + a*b + b*c + c*a > N:
break
ans[a*a + b*b + c*c + a*b + b*c + c*a] += 1
for i in range(1, N+1):
print((ans[i]))
| 16 | 16 | 355 | 347 | N = int(eval(input()))
ans = [0] * (N + 1)
for a in range(1, 105):
if a * a > N:
continue
for b in range(1, 105):
if a * a + b * b > N:
continue
for c in range(1, 105):
if a * a + b * b + c * c + a * b + b * c + c * a > N:
continue
ans[a * a + b * b + c * c + a * b + b * c + c * a] += 1
for i in range(1, N + 1):
print((ans[i]))
| N = int(eval(input()))
ans = [0] * (N + 1)
for a in range(1, 105):
if a * a > N:
break
for b in range(1, 105):
if a * a + b * b > N:
break
for c in range(1, 105):
if a * a + b * b + c * c + a * b + b * c + c * a > N:
break
ans[a * a + b * b + c * c + a * b + b * c + c * a] += 1
for i in range(1, N + 1):
print((ans[i]))
| false | 0 | [
"- continue",
"+ break",
"- continue",
"+ break",
"- continue",
"+ break"
] | false | 0.051483 | 0.047278 | 1.088944 | [
"s441215421",
"s091981959"
] |
u401487574 | p03835 | python | s760576709 | s142373879 | 1,382 | 1,273 | 3,060 | 2,940 | Accepted | Accepted | 7.89 | k,s = list(map(int,input().split()))
Xm = k
Ym = k
Zm = k #使わない
count = 0
for i in range(Xm+1):
for j in range(Ym+1):
if 0<= s - (i+j) <= k:
count += 1
print(count) | k,s = list(map(int,input().split()))
x,y,z = k,k,k
cnt = 0
for i in range(k+1):
for j in range(k+1):
if 0<= s - (i+j) <= k:
cnt +=1
print(cnt)
| 10 | 8 | 181 | 168 | k, s = list(map(int, input().split()))
Xm = k
Ym = k
Zm = k # 使わない
count = 0
for i in range(Xm + 1):
for j in range(Ym + 1):
if 0 <= s - (i + j) <= k:
count += 1
print(count)
| k, s = list(map(int, input().split()))
x, y, z = k, k, k
cnt = 0
for i in range(k + 1):
for j in range(k + 1):
if 0 <= s - (i + j) <= k:
cnt += 1
print(cnt)
| false | 20 | [
"-Xm = k",
"-Ym = k",
"-Zm = k # 使わない",
"-count = 0",
"-for i in range(Xm + 1):",
"- for j in range(Ym + 1):",
"+x, y, z = k, k, k",
"+cnt = 0",
"+for i in range(k + 1):",
"+ for j in range(k + 1):",
"- count += 1",
"-print(count)",
"+ cnt += 1",
"+print(cnt)"
] | false | 0.035789 | 0.096551 | 0.370669 | [
"s760576709",
"s142373879"
] |
u759412327 | p03644 | python | s099492914 | s721652636 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | a = int(eval(input()))
if a<=1:
print((1))
elif a<=3:
print((2))
elif a<=7:
print((4))
elif a<=15:
print((8))
elif a<=31:
print((16))
elif a<=63:
print((32))
else:
print((64))
| N = int(eval(input()))
a = 1
while a*2<=N:
a*=2
print(a)
| 15 | 7 | 184 | 63 | a = int(eval(input()))
if a <= 1:
print((1))
elif a <= 3:
print((2))
elif a <= 7:
print((4))
elif a <= 15:
print((8))
elif a <= 31:
print((16))
elif a <= 63:
print((32))
else:
print((64))
| N = int(eval(input()))
a = 1
while a * 2 <= N:
a *= 2
print(a)
| false | 53.333333 | [
"-a = int(eval(input()))",
"-if a <= 1:",
"- print((1))",
"-elif a <= 3:",
"- print((2))",
"-elif a <= 7:",
"- print((4))",
"-elif a <= 15:",
"- print((8))",
"-elif a <= 31:",
"- print((16))",
"-elif a <= 63:",
"- print((32))",
"-else:",
"- print((64))",
"+N = int(eval(input()))",
"+a = 1",
"+while a * 2 <= N:",
"+ a *= 2",
"+print(a)"
] | false | 0.051555 | 0.051265 | 1.005656 | [
"s099492914",
"s721652636"
] |
u644907318 | p03048 | python | s048128850 | s186611656 | 86 | 61 | 67,356 | 66,256 | Accepted | Accepted | 29.07 | R,G,B,N = list(map(int,input().split()))
cnt = 0
for r in range(N//R+1):
for g in range(N//G+1):
n = N-r*R-g*G
if n>=0 and n%B==0:
cnt += 1
print(cnt) | R,G,B,N = list(map(int,input().split()))
cnt = 0
for r in range(N//R+1):
for g in range((N-r*R)//G+1):
if (N-r*R-g*G)%B==0:
cnt += 1
print(cnt) | 8 | 7 | 183 | 167 | R, G, B, N = list(map(int, input().split()))
cnt = 0
for r in range(N // R + 1):
for g in range(N // G + 1):
n = N - r * R - g * G
if n >= 0 and n % B == 0:
cnt += 1
print(cnt)
| R, G, B, N = list(map(int, input().split()))
cnt = 0
for r in range(N // R + 1):
for g in range((N - r * R) // G + 1):
if (N - r * R - g * G) % B == 0:
cnt += 1
print(cnt)
| false | 12.5 | [
"- for g in range(N // G + 1):",
"- n = N - r * R - g * G",
"- if n >= 0 and n % B == 0:",
"+ for g in range((N - r * R) // G + 1):",
"+ if (N - r * R - g * G) % B == 0:"
] | false | 0.121555 | 0.055677 | 2.183197 | [
"s048128850",
"s186611656"
] |
u934442292 | p03164 | python | s744040297 | s938942653 | 1,141 | 162 | 198,232 | 106,636 | Accepted | Accepted | 85.8 | import sys
import numba as nb
import numpy as np
input = sys.stdin.readline
@nb.njit("i8(i8,i8,i8[:],i8[:])")
def solve(N, W, w, v):
dp = np.full(shape=(N + 1, np.sum(v) + 1), fill_value=(N * W), dtype=np.int64)
dp[:, 0] = 0
for i in range(N):
np.minimum(w[i], dp[i][:v[i]], dp[i + 1][:v[i]])
np.minimum(w[i] + dp[i][: - v[i]], dp[i][v[i]:], dp[i + 1][v[i]:])
return np.where(dp[-1] <= W)[0][-1]
def main():
N, W = list(map(int, input().split()))
w = np.empty(shape=N, dtype=np.int64)
v = np.empty(shape=N, dtype=np.int64)
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
ans = solve(N, W, w, v)
print(ans)
if __name__ == "__main__":
main()
| import sys
# import numba as nb
import numpy as np
input = sys.stdin.readline
# @nb.njit("i8(i8,i8,i8[:],i8[:])")
def solve(N, W, w, v):
dp = np.full(shape=(N + 1, np.sum(v) + 1), fill_value=(N * W), dtype=np.int64)
dp[:, 0] = 0
for i in range(N):
np.minimum(w[i], dp[i][:v[i]], dp[i + 1][:v[i]])
np.minimum(w[i] + dp[i][: - v[i]], dp[i][v[i]:], dp[i + 1][v[i]:])
return np.where(dp[-1] <= W)[0][-1]
def main():
N, W = list(map(int, input().split()))
w = np.empty(shape=N, dtype=np.int64)
v = np.empty(shape=N, dtype=np.int64)
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
ans = solve(N, W, w, v)
print(ans)
if __name__ == "__main__":
main()
| 32 | 32 | 753 | 757 | import sys
import numba as nb
import numpy as np
input = sys.stdin.readline
@nb.njit("i8(i8,i8,i8[:],i8[:])")
def solve(N, W, w, v):
dp = np.full(shape=(N + 1, np.sum(v) + 1), fill_value=(N * W), dtype=np.int64)
dp[:, 0] = 0
for i in range(N):
np.minimum(w[i], dp[i][: v[i]], dp[i + 1][: v[i]])
np.minimum(w[i] + dp[i][: -v[i]], dp[i][v[i] :], dp[i + 1][v[i] :])
return np.where(dp[-1] <= W)[0][-1]
def main():
N, W = list(map(int, input().split()))
w = np.empty(shape=N, dtype=np.int64)
v = np.empty(shape=N, dtype=np.int64)
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
ans = solve(N, W, w, v)
print(ans)
if __name__ == "__main__":
main()
| import sys
# import numba as nb
import numpy as np
input = sys.stdin.readline
# @nb.njit("i8(i8,i8,i8[:],i8[:])")
def solve(N, W, w, v):
dp = np.full(shape=(N + 1, np.sum(v) + 1), fill_value=(N * W), dtype=np.int64)
dp[:, 0] = 0
for i in range(N):
np.minimum(w[i], dp[i][: v[i]], dp[i + 1][: v[i]])
np.minimum(w[i] + dp[i][: -v[i]], dp[i][v[i] :], dp[i + 1][v[i] :])
return np.where(dp[-1] <= W)[0][-1]
def main():
N, W = list(map(int, input().split()))
w = np.empty(shape=N, dtype=np.int64)
v = np.empty(shape=N, dtype=np.int64)
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
ans = solve(N, W, w, v)
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"-import numba as nb",
"+",
"+# import numba as nb",
"-",
"-",
"[email protected](\"i8(i8,i8,i8[:],i8[:])\")",
"+# @nb.njit(\"i8(i8,i8,i8[:],i8[:])\")"
] | false | 0.04665 | 0.201703 | 0.23128 | [
"s744040297",
"s938942653"
] |
u929996201 | p02601 | python | s540340910 | s090835806 | 35 | 26 | 9,288 | 9,188 | Accepted | Accepted | 25.71 | import copy
def magic(arr,i,k):
if(k==0):
if(arr[0] < arr[1] and arr[1] < arr[2]):
return True
else:
return False
k-=1
arr[i]*=2
return magic(arr.copy(),0,k) or magic(arr.copy(),1,k) or magic(arr.copy(),2,k)
if __name__ == "__main__":
arr = list(map(int,input().split()))
k = int(eval(input()))
if(magic(arr.copy(),0,k) or magic(arr.copy(),1,k) or magic(arr.copy(),2,k)):
print("Yes")
exit()
else:
print("No") | a,b,c = list(map(int,input().split()))
k = int(eval(input()))
for i in range(k):
if(a >= b):
b*=2
continue
if(b >= c):
c*=2
continue
if(a<b and b<c):
print("Yes")
exit()
else:
print("No") | 19 | 16 | 472 | 222 | import copy
def magic(arr, i, k):
if k == 0:
if arr[0] < arr[1] and arr[1] < arr[2]:
return True
else:
return False
k -= 1
arr[i] *= 2
return magic(arr.copy(), 0, k) or magic(arr.copy(), 1, k) or magic(arr.copy(), 2, k)
if __name__ == "__main__":
arr = list(map(int, input().split()))
k = int(eval(input()))
if magic(arr.copy(), 0, k) or magic(arr.copy(), 1, k) or magic(arr.copy(), 2, k):
print("Yes")
exit()
else:
print("No")
| a, b, c = list(map(int, input().split()))
k = int(eval(input()))
for i in range(k):
if a >= b:
b *= 2
continue
if b >= c:
c *= 2
continue
if a < b and b < c:
print("Yes")
exit()
else:
print("No")
| false | 15.789474 | [
"-import copy",
"-",
"-",
"-def magic(arr, i, k):",
"- if k == 0:",
"- if arr[0] < arr[1] and arr[1] < arr[2]:",
"- return True",
"- else:",
"- return False",
"- k -= 1",
"- arr[i] *= 2",
"- return magic(arr.copy(), 0, k) or magic(arr.copy(), 1, k) or magic(arr.copy(), 2, k)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- arr = list(map(int, input().split()))",
"- k = int(eval(input()))",
"- if magic(arr.copy(), 0, k) or magic(arr.copy(), 1, k) or magic(arr.copy(), 2, k):",
"- print(\"Yes\")",
"- exit()",
"- else:",
"- print(\"No\")",
"+a, b, c = list(map(int, input().split()))",
"+k = int(eval(input()))",
"+for i in range(k):",
"+ if a >= b:",
"+ b *= 2",
"+ continue",
"+ if b >= c:",
"+ c *= 2",
"+ continue",
"+if a < b and b < c:",
"+ print(\"Yes\")",
"+ exit()",
"+else:",
"+ print(\"No\")"
] | false | 0.038895 | 0.037499 | 1.037218 | [
"s540340910",
"s090835806"
] |
u466161487 | p02708 | python | s259374489 | s367365523 | 92 | 73 | 9,160 | 9,164 | Accepted | Accepted | 20.65 | a,b=(int(x) for x in input().split())
z=0
for i in range(b,a+2):
z=(z+(a-i+1)*i+1)%int(1e9+7)
print(z) | a,b=(int(x) for x in input().split())
z=0
for i in range(b,a+2):z=(z+(a-i+1)*i+1)%(10**9+7)
print(z) | 5 | 4 | 108 | 103 | a, b = (int(x) for x in input().split())
z = 0
for i in range(b, a + 2):
z = (z + (a - i + 1) * i + 1) % int(1e9 + 7)
print(z)
| a, b = (int(x) for x in input().split())
z = 0
for i in range(b, a + 2):
z = (z + (a - i + 1) * i + 1) % (10**9 + 7)
print(z)
| false | 20 | [
"- z = (z + (a - i + 1) * i + 1) % int(1e9 + 7)",
"+ z = (z + (a - i + 1) * i + 1) % (10**9 + 7)"
] | false | 0.058117 | 0.041586 | 1.397533 | [
"s259374489",
"s367365523"
] |
u002459665 | p03625 | python | s872018535 | s791313028 | 101 | 88 | 14,636 | 14,636 | Accepted | Accepted | 12.87 | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
# print(A)
lines = []
cnt = 1
before = 'XXX'
for ai in A + ['YYY']:
if ai == before:
cnt += 1
else:
if cnt >= 4:
lines.append(before)
lines.append(before)
elif cnt >=2:
lines.append(before)
if len(lines) >= 2:
break
cnt = 1
before = ai
if len(lines) >= 2:
print((lines[0] * lines[1]))
else:
print((0)) | def main():
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
lines = []
prev = ''
for ai in A:
if ai == prev:
lines.append(ai)
prev = ''
else:
prev = ai
if len(lines) >= 2:
print((lines[0] * lines[1]))
else:
print((0))
if __name__ == "__main__":
main() | 32 | 22 | 561 | 408 | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
# print(A)
lines = []
cnt = 1
before = "XXX"
for ai in A + ["YYY"]:
if ai == before:
cnt += 1
else:
if cnt >= 4:
lines.append(before)
lines.append(before)
elif cnt >= 2:
lines.append(before)
if len(lines) >= 2:
break
cnt = 1
before = ai
if len(lines) >= 2:
print((lines[0] * lines[1]))
else:
print((0))
| def main():
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
lines = []
prev = ""
for ai in A:
if ai == prev:
lines.append(ai)
prev = ""
else:
prev = ai
if len(lines) >= 2:
print((lines[0] * lines[1]))
else:
print((0))
if __name__ == "__main__":
main()
| false | 31.25 | [
"-from collections import Counter",
"+def main():",
"+ N = int(eval(input()))",
"+ A = list(map(int, input().split()))",
"+ A.sort(reverse=True)",
"+ lines = []",
"+ prev = \"\"",
"+ for ai in A:",
"+ if ai == prev:",
"+ lines.append(ai)",
"+ prev = \"\"",
"+ else:",
"+ prev = ai",
"+ if len(lines) >= 2:",
"+ print((lines[0] * lines[1]))",
"+ else:",
"+ print((0))",
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-A.sort(reverse=True)",
"-# print(A)",
"-lines = []",
"-cnt = 1",
"-before = \"XXX\"",
"-for ai in A + [\"YYY\"]:",
"- if ai == before:",
"- cnt += 1",
"- else:",
"- if cnt >= 4:",
"- lines.append(before)",
"- lines.append(before)",
"- elif cnt >= 2:",
"- lines.append(before)",
"- if len(lines) >= 2:",
"- break",
"- cnt = 1",
"- before = ai",
"-if len(lines) >= 2:",
"- print((lines[0] * lines[1]))",
"-else:",
"- print((0))",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.040374 | 0.044982 | 0.897565 | [
"s872018535",
"s791313028"
] |
u638282348 | p02675 | python | s209747082 | s071957524 | 24 | 20 | 9,164 | 8,944 | Accepted | Accepted | 16.67 | N = int(eval(input())) % 10
print(("hon" if N in [2, 4, 5, 7, 9] else "pon" if N in [0, 1, 6, 8] else "bon")) | N = input()[-1]
print(("hon" if N in "24579" else "pon" if N in "0168" else "bon")) | 2 | 2 | 102 | 82 | N = int(eval(input())) % 10
print(("hon" if N in [2, 4, 5, 7, 9] else "pon" if N in [0, 1, 6, 8] else "bon"))
| N = input()[-1]
print(("hon" if N in "24579" else "pon" if N in "0168" else "bon"))
| false | 0 | [
"-N = int(eval(input())) % 10",
"-print((\"hon\" if N in [2, 4, 5, 7, 9] else \"pon\" if N in [0, 1, 6, 8] else \"bon\"))",
"+N = input()[-1]",
"+print((\"hon\" if N in \"24579\" else \"pon\" if N in \"0168\" else \"bon\"))"
] | false | 0.044774 | 0.041583 | 1.07676 | [
"s209747082",
"s071957524"
] |
u057964173 | p02971 | python | s037768599 | s825925257 | 462 | 425 | 61,024 | 61,280 | Accepted | Accepted | 8.01 | import sys
def input(): return sys.stdin.readline().strip()
def resolve():
n=int(eval(input()))
l=[int(eval(input())) for i in range(n)]
biggest = max(l)
lsort=sorted(l)
niban=lsort[-2]
for j in range(n):
if l[j]!=biggest:
print(biggest)
else:
print(niban)
resolve() | import sys
def input(): return sys.stdin.readline().strip()
def resolve():
n=int(eval(input()))
l=[int(eval(input())) for i in range(n)]
l1=sorted(l,reverse=True)
for j in range(n):
if l[j]!=l1[0]:
print((l1[0]))
else:
print((l1[1]))
resolve() | 15 | 12 | 333 | 294 | import sys
def input():
return sys.stdin.readline().strip()
def resolve():
n = int(eval(input()))
l = [int(eval(input())) for i in range(n)]
biggest = max(l)
lsort = sorted(l)
niban = lsort[-2]
for j in range(n):
if l[j] != biggest:
print(biggest)
else:
print(niban)
resolve()
| import sys
def input():
return sys.stdin.readline().strip()
def resolve():
n = int(eval(input()))
l = [int(eval(input())) for i in range(n)]
l1 = sorted(l, reverse=True)
for j in range(n):
if l[j] != l1[0]:
print((l1[0]))
else:
print((l1[1]))
resolve()
| false | 20 | [
"- biggest = max(l)",
"- lsort = sorted(l)",
"- niban = lsort[-2]",
"+ l1 = sorted(l, reverse=True)",
"- if l[j] != biggest:",
"- print(biggest)",
"+ if l[j] != l1[0]:",
"+ print((l1[0]))",
"- print(niban)",
"+ print((l1[1]))"
] | false | 0.033223 | 0.037726 | 0.880635 | [
"s037768599",
"s825925257"
] |
u859987056 | p03545 | python | s390180574 | s936043480 | 29 | 26 | 8,840 | 9,124 | Accepted | Accepted | 10.34 | s = eval(input())
for bit in range(1 << 3):
ans = s[0]
value = int(s[0])
for i in range(3):
if bit & (1 << i):
ans += "+" + s[i+1]
value += int(s[i+1])
else:
ans += "-" + s[i+1]
value -= int(s[i+1])
if value == 7:
print((ans + "=7"))
exit() | s = eval(input())
def dfs(i,f,sum):
if i == 3:
if sum == 7:
print((f + "=7"))
exit()
else:
dfs(i+1,f + "+" + s[i+1],sum + int(s[i+1]))
dfs(i+1,f + "-" + s[i+1],sum - int(s[i+1]))
dfs(0,s[0],int(s[0])) | 16 | 13 | 349 | 270 | s = eval(input())
for bit in range(1 << 3):
ans = s[0]
value = int(s[0])
for i in range(3):
if bit & (1 << i):
ans += "+" + s[i + 1]
value += int(s[i + 1])
else:
ans += "-" + s[i + 1]
value -= int(s[i + 1])
if value == 7:
print((ans + "=7"))
exit()
| s = eval(input())
def dfs(i, f, sum):
if i == 3:
if sum == 7:
print((f + "=7"))
exit()
else:
dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))
dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))
dfs(0, s[0], int(s[0]))
| false | 18.75 | [
"-for bit in range(1 << 3):",
"- ans = s[0]",
"- value = int(s[0])",
"- for i in range(3):",
"- if bit & (1 << i):",
"- ans += \"+\" + s[i + 1]",
"- value += int(s[i + 1])",
"- else:",
"- ans += \"-\" + s[i + 1]",
"- value -= int(s[i + 1])",
"- if value == 7:",
"- print((ans + \"=7\"))",
"- exit()",
"+",
"+",
"+def dfs(i, f, sum):",
"+ if i == 3:",
"+ if sum == 7:",
"+ print((f + \"=7\"))",
"+ exit()",
"+ else:",
"+ dfs(i + 1, f + \"+\" + s[i + 1], sum + int(s[i + 1]))",
"+ dfs(i + 1, f + \"-\" + s[i + 1], sum - int(s[i + 1]))",
"+",
"+",
"+dfs(0, s[0], int(s[0]))"
] | false | 0.044845 | 0.043501 | 1.030885 | [
"s390180574",
"s936043480"
] |
u488401358 | p02710 | python | s730147385 | s762628346 | 1,961 | 1,794 | 293,300 | 427,228 | Accepted | Accepted | 8.52 | import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)
N=int(eval(input()))
c=list(map(int,input().split()))
for i in range(N):
c[i]-=1
edge=[[] for i in range(N)]
for i in range(N-1):
a,b=list(map(int,input().split()))
edge[a-1].append(b-1)
edge[b-1].append(a-1)
subtree=[1]*N
def size(v,pv):
for nv in edge[v]:
if nv!=pv:
size(nv,v)
subtree[v]+=subtree[nv]
size(0,-1)
data=[[] for i in range(N)]
Parent=[[0] for i in range(N)]
parent=[0]*N
def dfs(v,pv,nop):
pp=parent[nop]
parent[nop]=v
Parent[nop].append(v)
data[c[v]].append((parent[c[v]],v))
for nv in edge[v]:
if nv!=pv:
dfs(nv,v,c[v])
parent[nop]=pp
dfs(0,-1,0)
for i in range(N):
dic={v:subtree[v] for v in Parent[i]}
for p,ch in data[i]:
dic[p]-=subtree[ch]
res=N*(N+1)//2
for p in dic:
res-=dic[p]*(dic[p]+1)//2
print(res) | import sys
from collections import deque
input = sys.stdin.buffer.readline
sys.setrecursionlimit(2*10**5)
N = int(eval(input()))
c = list(map(int,input().split()))
edge = [[] for i in range(N+1)]
for _ in range(N-1):
a,b = list(map(int,input().split()))
edge[a].append(b)
edge[b].append(a)
#合流点の検出
deq = deque([1])
parent = [-1 for i in range(N+1)]
parent[1] = 0
topo = []
while deq:
v = deq.popleft()
topo.append(v)
for nv in edge[v]:
if parent[nv]==-1:
parent[nv] = v
deq.append(nv)
topo = topo[::-1]
#辺の張り直し
vertex = []
size = [1 for i in range(N+1)]
size[0] = N
def euler_tour(v,pv):
vertex.append(v)
for nv in edge[v]:
if nv!=pv:
euler_tour(nv,v)
size[v] += size[nv]
vertex.append(v)
euler_tour(1,0)
color_tree_edge = [{c[i]:[]} for i in range(N)]
color_tree_edge = [{c:[] for c in range(1,N+1)}] + color_tree_edge
for v in range(2,N+1):
color_tree_edge[v][c[parent[v]-1]] = []
parent = [0 for i in range(N+1)]
visit = [None for i in range(N+1)]
for v in vertex:
if visit[v] is None:
visit[v] = {}
for nc in color_tree_edge[v]:
color_tree_edge[parent[nc]][nc].append(v)
visit[v][nc] = parent[nc]
parent[nc] = v
else:
for nc in visit[v]:
parent[nc] = visit[v][nc]
def bfs(color):
deq = deque([0])
res = []
while deq:
v = deq.popleft()
res.append(v)
for nv in color_tree_edge[v][color]:
deq.append(nv)
return res[::-1]
ans = [0]*(N+1)
for color in range(1,N+1):
vertex = bfs(color)
res = N*(N+1)//2
for v in vertex:
if v==0 or c[v-1]!=color:
tmp = size[v]
for nv in color_tree_edge[v][color]:
tmp -= size[nv]
res -= tmp*(tmp+1)//2
ans[color] = res
print(("\n".join(map(str,ans[1:]))))
| 48 | 89 | 968 | 1,990 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(eval(input()))
c = list(map(int, input().split()))
for i in range(N):
c[i] -= 1
edge = [[] for i in range(N)]
for i in range(N - 1):
a, b = list(map(int, input().split()))
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
subtree = [1] * N
def size(v, pv):
for nv in edge[v]:
if nv != pv:
size(nv, v)
subtree[v] += subtree[nv]
size(0, -1)
data = [[] for i in range(N)]
Parent = [[0] for i in range(N)]
parent = [0] * N
def dfs(v, pv, nop):
pp = parent[nop]
parent[nop] = v
Parent[nop].append(v)
data[c[v]].append((parent[c[v]], v))
for nv in edge[v]:
if nv != pv:
dfs(nv, v, c[v])
parent[nop] = pp
dfs(0, -1, 0)
for i in range(N):
dic = {v: subtree[v] for v in Parent[i]}
for p, ch in data[i]:
dic[p] -= subtree[ch]
res = N * (N + 1) // 2
for p in dic:
res -= dic[p] * (dic[p] + 1) // 2
print(res)
| import sys
from collections import deque
input = sys.stdin.buffer.readline
sys.setrecursionlimit(2 * 10**5)
N = int(eval(input()))
c = list(map(int, input().split()))
edge = [[] for i in range(N + 1)]
for _ in range(N - 1):
a, b = list(map(int, input().split()))
edge[a].append(b)
edge[b].append(a)
# 合流点の検出
deq = deque([1])
parent = [-1 for i in range(N + 1)]
parent[1] = 0
topo = []
while deq:
v = deq.popleft()
topo.append(v)
for nv in edge[v]:
if parent[nv] == -1:
parent[nv] = v
deq.append(nv)
topo = topo[::-1]
# 辺の張り直し
vertex = []
size = [1 for i in range(N + 1)]
size[0] = N
def euler_tour(v, pv):
vertex.append(v)
for nv in edge[v]:
if nv != pv:
euler_tour(nv, v)
size[v] += size[nv]
vertex.append(v)
euler_tour(1, 0)
color_tree_edge = [{c[i]: []} for i in range(N)]
color_tree_edge = [{c: [] for c in range(1, N + 1)}] + color_tree_edge
for v in range(2, N + 1):
color_tree_edge[v][c[parent[v] - 1]] = []
parent = [0 for i in range(N + 1)]
visit = [None for i in range(N + 1)]
for v in vertex:
if visit[v] is None:
visit[v] = {}
for nc in color_tree_edge[v]:
color_tree_edge[parent[nc]][nc].append(v)
visit[v][nc] = parent[nc]
parent[nc] = v
else:
for nc in visit[v]:
parent[nc] = visit[v][nc]
def bfs(color):
deq = deque([0])
res = []
while deq:
v = deq.popleft()
res.append(v)
for nv in color_tree_edge[v][color]:
deq.append(nv)
return res[::-1]
ans = [0] * (N + 1)
for color in range(1, N + 1):
vertex = bfs(color)
res = N * (N + 1) // 2
for v in vertex:
if v == 0 or c[v - 1] != color:
tmp = size[v]
for nv in color_tree_edge[v][color]:
tmp -= size[nv]
res -= tmp * (tmp + 1) // 2
ans[color] = res
print(("\n".join(map(str, ans[1:]))))
| false | 46.067416 | [
"+from collections import deque",
"-input = sys.stdin.readline",
"-sys.setrecursionlimit(10**7)",
"+input = sys.stdin.buffer.readline",
"+sys.setrecursionlimit(2 * 10**5)",
"-for i in range(N):",
"- c[i] -= 1",
"-edge = [[] for i in range(N)]",
"-for i in range(N - 1):",
"+edge = [[] for i in range(N + 1)]",
"+for _ in range(N - 1):",
"- edge[a - 1].append(b - 1)",
"- edge[b - 1].append(a - 1)",
"-subtree = [1] * N",
"+ edge[a].append(b)",
"+ edge[b].append(a)",
"+# 合流点の検出",
"+deq = deque([1])",
"+parent = [-1 for i in range(N + 1)]",
"+parent[1] = 0",
"+topo = []",
"+while deq:",
"+ v = deq.popleft()",
"+ topo.append(v)",
"+ for nv in edge[v]:",
"+ if parent[nv] == -1:",
"+ parent[nv] = v",
"+ deq.append(nv)",
"+topo = topo[::-1]",
"+# 辺の張り直し",
"+vertex = []",
"+size = [1 for i in range(N + 1)]",
"+size[0] = N",
"-def size(v, pv):",
"+def euler_tour(v, pv):",
"+ vertex.append(v)",
"- size(nv, v)",
"- subtree[v] += subtree[nv]",
"+ euler_tour(nv, v)",
"+ size[v] += size[nv]",
"+ vertex.append(v)",
"-size(0, -1)",
"-data = [[] for i in range(N)]",
"-Parent = [[0] for i in range(N)]",
"-parent = [0] * N",
"+euler_tour(1, 0)",
"+color_tree_edge = [{c[i]: []} for i in range(N)]",
"+color_tree_edge = [{c: [] for c in range(1, N + 1)}] + color_tree_edge",
"+for v in range(2, N + 1):",
"+ color_tree_edge[v][c[parent[v] - 1]] = []",
"+parent = [0 for i in range(N + 1)]",
"+visit = [None for i in range(N + 1)]",
"+for v in vertex:",
"+ if visit[v] is None:",
"+ visit[v] = {}",
"+ for nc in color_tree_edge[v]:",
"+ color_tree_edge[parent[nc]][nc].append(v)",
"+ visit[v][nc] = parent[nc]",
"+ parent[nc] = v",
"+ else:",
"+ for nc in visit[v]:",
"+ parent[nc] = visit[v][nc]",
"-def dfs(v, pv, nop):",
"- pp = parent[nop]",
"- parent[nop] = v",
"- Parent[nop].append(v)",
"- data[c[v]].append((parent[c[v]], v))",
"- for nv in edge[v]:",
"- if nv != pv:",
"- dfs(nv, v, c[v])",
"- parent[nop] = pp",
"+def bfs(color):",
"+ deq = deque([0])",
"+ res = []",
"+ while deq:",
"+ v = deq.popleft()",
"+ res.append(v)",
"+ for nv in color_tree_edge[v][color]:",
"+ deq.append(nv)",
"+ return res[::-1]",
"-dfs(0, -1, 0)",
"-for i in range(N):",
"- dic = {v: subtree[v] for v in Parent[i]}",
"- for p, ch in data[i]:",
"- dic[p] -= subtree[ch]",
"+ans = [0] * (N + 1)",
"+for color in range(1, N + 1):",
"+ vertex = bfs(color)",
"- for p in dic:",
"- res -= dic[p] * (dic[p] + 1) // 2",
"- print(res)",
"+ for v in vertex:",
"+ if v == 0 or c[v - 1] != color:",
"+ tmp = size[v]",
"+ for nv in color_tree_edge[v][color]:",
"+ tmp -= size[nv]",
"+ res -= tmp * (tmp + 1) // 2",
"+ ans[color] = res",
"+print((\"\\n\".join(map(str, ans[1:]))))"
] | false | 0.09014 | 0.071523 | 1.260295 | [
"s730147385",
"s762628346"
] |
u463655976 | p03053 | python | s147691550 | s067151352 | 961 | 820 | 153,308 | 153,308 | Accepted | Accepted | 14.67 | from collections import deque
H,W = list(map(int, input().split()))
A = 0
dp = [None] * H
mat = deque()
for h in range(H):
s = list(eval(input()))
for w, x in zip(list(range(W)), s):
if x == "#":
mat.append((h, w, 0))
dp[h] = s
while len(mat):
h, w, cnt = mat.popleft()
for t, h, w, cnt in [(h > 0, h - 1, w, cnt),(h < H-1, h + 1, w, cnt),(w > 0, h , w - 1, cnt),(w < W-1, h , w + 1, cnt)]:
if t and dp[h][w] == ".":
mat.append((h, w, cnt+1))
dp[h][w] = "#"
print(cnt)
| from collections import deque
H,W = list(map(int, input().split()))
A = 0
dp = [None] * H
mat = deque(maxlen=W*H)
for h in range(H):
s = list(eval(input()))
for w, x in zip(list(range(W)), s):
if x == "#":
mat.append((h, w, 0))
dp[h] = s
while len(mat):
h, w, cnt = mat.popleft()
for t, h, w, cnt in ((h > 0, h - 1, w, cnt),(h < H-1, h + 1, w, cnt),(w > 0, h , w - 1, cnt),(w < W-1, h , w + 1, cnt)):
if t and dp[h][w] == ".":
mat.append((h, w, cnt+1))
dp[h][w] = "#"
print(cnt)
| 21 | 21 | 546 | 556 | from collections import deque
H, W = list(map(int, input().split()))
A = 0
dp = [None] * H
mat = deque()
for h in range(H):
s = list(eval(input()))
for w, x in zip(list(range(W)), s):
if x == "#":
mat.append((h, w, 0))
dp[h] = s
while len(mat):
h, w, cnt = mat.popleft()
for t, h, w, cnt in [
(h > 0, h - 1, w, cnt),
(h < H - 1, h + 1, w, cnt),
(w > 0, h, w - 1, cnt),
(w < W - 1, h, w + 1, cnt),
]:
if t and dp[h][w] == ".":
mat.append((h, w, cnt + 1))
dp[h][w] = "#"
print(cnt)
| from collections import deque
H, W = list(map(int, input().split()))
A = 0
dp = [None] * H
mat = deque(maxlen=W * H)
for h in range(H):
s = list(eval(input()))
for w, x in zip(list(range(W)), s):
if x == "#":
mat.append((h, w, 0))
dp[h] = s
while len(mat):
h, w, cnt = mat.popleft()
for t, h, w, cnt in (
(h > 0, h - 1, w, cnt),
(h < H - 1, h + 1, w, cnt),
(w > 0, h, w - 1, cnt),
(w < W - 1, h, w + 1, cnt),
):
if t and dp[h][w] == ".":
mat.append((h, w, cnt + 1))
dp[h][w] = "#"
print(cnt)
| false | 0 | [
"-mat = deque()",
"+mat = deque(maxlen=W * H)",
"- for t, h, w, cnt in [",
"+ for t, h, w, cnt in (",
"- ]:",
"+ ):"
] | false | 0.113328 | 0.041418 | 2.736189 | [
"s147691550",
"s067151352"
] |
u562935282 | p03161 | python | s654326233 | s319608783 | 530 | 427 | 56,544 | 58,308 | Accepted | Accepted | 19.43 | inf = float('inf')
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, k + 1) if i - j >= 0)
print((dp[n - 1]))
| inf = float('inf')
n, k = list(map(int, input().split()))
h = list(map(int, input().split())) + [inf] * k
dp = [inf] * (n + k)
dp[0] = 0
# 配る
for i in range(n - 1):
for j in range(1, k + 1):
dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print((dp[n - 1]))
| 12 | 13 | 256 | 286 | inf = float("inf")
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, k + 1) if i - j >= 0)
print((dp[n - 1]))
| inf = float("inf")
n, k = list(map(int, input().split()))
h = list(map(int, input().split())) + [inf] * k
dp = [inf] * (n + k)
dp[0] = 0
# 配る
for i in range(n - 1):
for j in range(1, k + 1):
dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print((dp[n - 1]))
| false | 7.692308 | [
"-h = list(map(int, input().split()))",
"-dp = [inf] * n",
"+h = list(map(int, input().split())) + [inf] * k",
"+dp = [inf] * (n + k)",
"-for i in range(1, n):",
"- dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, k + 1) if i - j >= 0)",
"+# 配る",
"+for i in range(n - 1):",
"+ for j in range(1, k + 1):",
"+ dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))"
] | false | 0.038464 | 0.038228 | 1.006176 | [
"s654326233",
"s319608783"
] |
u197300773 | p02691 | python | s738087948 | s497620804 | 189 | 172 | 127,068 | 127,200 | Accepted | Accepted | 8.99 | from collections import defaultdict
n=int(eval(input()))
a=list(map(int,input().split()))
d=defaultdict(int)
for i in range(n):
d[i+1-a[i]]+=1
print((sum(d[i+1+a[i]] for i in range(n)))) | from collections import defaultdict
n=int(eval(input()))
a=list(map(int,input().split()))
d=defaultdict(int)
for i in range(n):
d[i-a[i]]+=1
ans=0
for i in range(n):
ans+=d[i+a[i]]
print(ans) | 7 | 10 | 188 | 202 | from collections import defaultdict
n = int(eval(input()))
a = list(map(int, input().split()))
d = defaultdict(int)
for i in range(n):
d[i + 1 - a[i]] += 1
print((sum(d[i + 1 + a[i]] for i in range(n))))
| from collections import defaultdict
n = int(eval(input()))
a = list(map(int, input().split()))
d = defaultdict(int)
for i in range(n):
d[i - a[i]] += 1
ans = 0
for i in range(n):
ans += d[i + a[i]]
print(ans)
| false | 30 | [
"- d[i + 1 - a[i]] += 1",
"-print((sum(d[i + 1 + a[i]] for i in range(n))))",
"+ d[i - a[i]] += 1",
"+ans = 0",
"+for i in range(n):",
"+ ans += d[i + a[i]]",
"+print(ans)"
] | false | 0.03873 | 0.067095 | 0.577246 | [
"s738087948",
"s497620804"
] |
u633068244 | p00263 | python | s372542698 | s891618875 | 310 | 40 | 4,580 | 4,524 | Accepted | Accepted | 87.1 | for i in range(eval(input())):
b=format(int(input(),16),"b").zfill(32)
a1=0
a2=0.0
for i in range(1,25):
a1+=int(b[i])*2**(24-i)
for i in range(25,32):
a2+=int(b[i])*2**(24-i)
print("-"*int(b[0])+str(a1)+str(a2)[1:]) | for i in range(eval(input())):
b=int(input(),16)
s=1<<31
p=""
if b&s!=0:
b^=s
p="-"
a=int(b*1.0/(1<<7))
print(p+str(a)+str(abs(b*1.0/(1<<7)-a))[1:]) | 9 | 9 | 232 | 167 | for i in range(eval(input())):
b = format(int(input(), 16), "b").zfill(32)
a1 = 0
a2 = 0.0
for i in range(1, 25):
a1 += int(b[i]) * 2 ** (24 - i)
for i in range(25, 32):
a2 += int(b[i]) * 2 ** (24 - i)
print("-" * int(b[0]) + str(a1) + str(a2)[1:])
| for i in range(eval(input())):
b = int(input(), 16)
s = 1 << 31
p = ""
if b & s != 0:
b ^= s
p = "-"
a = int(b * 1.0 / (1 << 7))
print(p + str(a) + str(abs(b * 1.0 / (1 << 7) - a))[1:])
| false | 0 | [
"- b = format(int(input(), 16), \"b\").zfill(32)",
"- a1 = 0",
"- a2 = 0.0",
"- for i in range(1, 25):",
"- a1 += int(b[i]) * 2 ** (24 - i)",
"- for i in range(25, 32):",
"- a2 += int(b[i]) * 2 ** (24 - i)",
"- print(\"-\" * int(b[0]) + str(a1) + str(a2)[1:])",
"+ b = int(input(), 16)",
"+ s = 1 << 31",
"+ p = \"\"",
"+ if b & s != 0:",
"+ b ^= s",
"+ p = \"-\"",
"+ a = int(b * 1.0 / (1 << 7))",
"+ print(p + str(a) + str(abs(b * 1.0 / (1 << 7) - a))[1:])"
] | false | 0.094854 | 0.006925 | 13.697001 | [
"s372542698",
"s891618875"
] |
u057964173 | p03627 | python | s369871779 | s336653539 | 336 | 247 | 68,352 | 64,896 | Accepted | Accepted | 26.49 | import sys
def input(): return sys.stdin.readline().strip()
def resolve():
n=int(eval(input()))
l=list(map(int,input().split()))
from collections import Counter
c=Counter(l)# ()にカウンターの対象のリストの変数名
cl=list(c.items())
cl.sort(key=lambda x:x[0],reverse=True)
ans=[]
for key,value in cl:
if value>=4:
if len(ans)==0:
ans.append(key)
ans.append(key)
break
elif len(ans)==1:
ans.append(key)
break
elif value>=2:
ans.append(key)
if len(ans)==2:
break
if ans:
print((ans[0]*ans[1]))
else:
print((0))
resolve() | import sys
def input(): return sys.stdin.readline().strip()
def resolve():
n=int(eval(input()))
l=list(map(int,input().split()))
from collections import Counter
c=Counter(l)# ()にカウンターの対象のリストの変数名
ans=[]
for key,value in list(c.items()):
if value>=4:
ans.append(key)
ans.append(key)
elif value>=2:
ans.append(key)
ans.sort(reverse=True)
if ans:
print((ans[0]*ans[1]))
else:
print((0))
resolve() | 29 | 21 | 734 | 501 | import sys
def input():
return sys.stdin.readline().strip()
def resolve():
n = int(eval(input()))
l = list(map(int, input().split()))
from collections import Counter
c = Counter(l) # ()にカウンターの対象のリストの変数名
cl = list(c.items())
cl.sort(key=lambda x: x[0], reverse=True)
ans = []
for key, value in cl:
if value >= 4:
if len(ans) == 0:
ans.append(key)
ans.append(key)
break
elif len(ans) == 1:
ans.append(key)
break
elif value >= 2:
ans.append(key)
if len(ans) == 2:
break
if ans:
print((ans[0] * ans[1]))
else:
print((0))
resolve()
| import sys
def input():
return sys.stdin.readline().strip()
def resolve():
n = int(eval(input()))
l = list(map(int, input().split()))
from collections import Counter
c = Counter(l) # ()にカウンターの対象のリストの変数名
ans = []
for key, value in list(c.items()):
if value >= 4:
ans.append(key)
ans.append(key)
elif value >= 2:
ans.append(key)
ans.sort(reverse=True)
if ans:
print((ans[0] * ans[1]))
else:
print((0))
resolve()
| false | 27.586207 | [
"- cl = list(c.items())",
"- cl.sort(key=lambda x: x[0], reverse=True)",
"- for key, value in cl:",
"+ for key, value in list(c.items()):",
"- if len(ans) == 0:",
"- ans.append(key)",
"- ans.append(key)",
"- break",
"- elif len(ans) == 1:",
"- ans.append(key)",
"- break",
"+ ans.append(key)",
"+ ans.append(key)",
"- if len(ans) == 2:",
"- break",
"+ ans.sort(reverse=True)"
] | false | 0.041945 | 0.038396 | 1.092441 | [
"s369871779",
"s336653539"
] |
u129019798 | p03166 | python | s301297448 | s026017146 | 972 | 492 | 139,596 | 109,360 | Accepted | Accepted | 49.38 | def main():
import sys
sys.setrecursionlimit(10**7)
N,M=list(map(int,sys.stdin.readline().split()))
dic=[[] for _ in range(N)]
for i in range(M):
x,y=list(map(int,sys.stdin.readline().split()))
dic[x-1].append(y-1)
dp=[0]*(N)
def dfs(frm):
if dp[frm]:
return dp[frm]
mx=0
if not dic[frm]:
return 0
for val in dic[frm]:
mx=max(mx,dfs(val)+1)
dp[frm]=mx
return mx
mx=0
for key in range(N):
mx=max(mx,dfs(key))
return mx
print((main()))
| def main():
import sys
sys.setrecursionlimit(10**7)
N,M=list(map(int,sys.stdin.readline().split()))
dic=[[] for _ in range(N)]
for i in range(M):
x,y=list(map(int,sys.stdin.readline().split()))
dic[x-1].append(y-1)
dp=[0]*(N)
def dfs(frm):
if dp[frm]:
return dp[frm]
mx=0
if not dic[frm]:
return 0
dp[frm]=max(dfs(val)+1 for val in dic[frm])
return dp[frm]
mx=0
return max(dfs(x) for x in range(N))
print((main()))
| 33 | 29 | 621 | 566 | def main():
import sys
sys.setrecursionlimit(10**7)
N, M = list(map(int, sys.stdin.readline().split()))
dic = [[] for _ in range(N)]
for i in range(M):
x, y = list(map(int, sys.stdin.readline().split()))
dic[x - 1].append(y - 1)
dp = [0] * (N)
def dfs(frm):
if dp[frm]:
return dp[frm]
mx = 0
if not dic[frm]:
return 0
for val in dic[frm]:
mx = max(mx, dfs(val) + 1)
dp[frm] = mx
return mx
mx = 0
for key in range(N):
mx = max(mx, dfs(key))
return mx
print((main()))
| def main():
import sys
sys.setrecursionlimit(10**7)
N, M = list(map(int, sys.stdin.readline().split()))
dic = [[] for _ in range(N)]
for i in range(M):
x, y = list(map(int, sys.stdin.readline().split()))
dic[x - 1].append(y - 1)
dp = [0] * (N)
def dfs(frm):
if dp[frm]:
return dp[frm]
mx = 0
if not dic[frm]:
return 0
dp[frm] = max(dfs(val) + 1 for val in dic[frm])
return dp[frm]
mx = 0
return max(dfs(x) for x in range(N))
print((main()))
| false | 12.121212 | [
"- for val in dic[frm]:",
"- mx = max(mx, dfs(val) + 1)",
"- dp[frm] = mx",
"- return mx",
"+ dp[frm] = max(dfs(val) + 1 for val in dic[frm])",
"+ return dp[frm]",
"- for key in range(N):",
"- mx = max(mx, dfs(key))",
"- return mx",
"+ return max(dfs(x) for x in range(N))"
] | false | 0.067061 | 0.091375 | 0.733911 | [
"s301297448",
"s026017146"
] |
u017415492 | p02971 | python | s178057087 | s935656606 | 676 | 352 | 14,568 | 19,028 | Accepted | Accepted | 47.93 | import copy
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
t=copy.deepcopy(a)
t.sort()
for i in a:
if i==t[-1]:
print((t[-2]))
else:
print((t[-1])) | n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
sa=sorted(a)
for i in a:
if sa[-1]==i:
print((sa[-2]))
else:
print((sa[-1])) | 11 | 9 | 173 | 143 | import copy
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
t = copy.deepcopy(a)
t.sort()
for i in a:
if i == t[-1]:
print((t[-2]))
else:
print((t[-1]))
| n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
sa = sorted(a)
for i in a:
if sa[-1] == i:
print((sa[-2]))
else:
print((sa[-1]))
| false | 18.181818 | [
"-import copy",
"-",
"-t = copy.deepcopy(a)",
"-t.sort()",
"+sa = sorted(a)",
"- if i == t[-1]:",
"- print((t[-2]))",
"+ if sa[-1] == i:",
"+ print((sa[-2]))",
"- print((t[-1]))",
"+ print((sa[-1]))"
] | false | 0.048029 | 0.046716 | 1.028109 | [
"s178057087",
"s935656606"
] |
u150641538 | p03304 | python | s691639636 | s125308090 | 302 | 17 | 21,088 | 3,060 | Accepted | Accepted | 94.37 | import numpy as np
n,m,d = list(map(int,input().split()))
"""
#kuso code
start = time.time()
a = [random.randrange(n) for i in range(m)]
a = np.array(a)
b = np.abs(a[1:]-a[:-1])
cnt = np.sum(b == d)
ave = cnt
i = 0
while(time.time() - start < 10):
a = [random.randrange(n) for i in range(m)]
a = np.array(a)
b = np.abs(a[1:]-a[:-1])
cnt = np.sum(b == d)
ave = ((i+1)*ave + cnt)/(i+2)
i += 1
print(ave)
"""
oks_times_n = 2*np.max(n-2*d,0) + 2*d
ave = oks_times_n/n/n*(m-1)
if (d == 0):
ave /= 2
print(ave)
| n,m,d = list(map(int,input().split()))
"""
#kuso code
start = time.time()
a = [random.randrange(n) for i in range(m)]
a = np.array(a)
b = np.abs(a[1:]-a[:-1])
cnt = np.sum(b == d)
ave = cnt
i = 0
while(time.time() - start < 10):
a = [random.randrange(n) for i in range(m)]
a = np.array(a)
b = np.abs(a[1:]-a[:-1])
cnt = np.sum(b == d)
ave = ((i+1)*ave + cnt)/(i+2)
i += 1
print(ave)
"""
oks_times_n = 2*(n-d)
ave = oks_times_n/n/n*(m-1)
if (d == 0):
ave /= 2
print(ave) | 29 | 27 | 559 | 520 | import numpy as np
n, m, d = list(map(int, input().split()))
"""
#kuso code
start = time.time()
a = [random.randrange(n) for i in range(m)]
a = np.array(a)
b = np.abs(a[1:]-a[:-1])
cnt = np.sum(b == d)
ave = cnt
i = 0
while(time.time() - start < 10):
a = [random.randrange(n) for i in range(m)]
a = np.array(a)
b = np.abs(a[1:]-a[:-1])
cnt = np.sum(b == d)
ave = ((i+1)*ave + cnt)/(i+2)
i += 1
print(ave)
"""
oks_times_n = 2 * np.max(n - 2 * d, 0) + 2 * d
ave = oks_times_n / n / n * (m - 1)
if d == 0:
ave /= 2
print(ave)
| n, m, d = list(map(int, input().split()))
"""
#kuso code
start = time.time()
a = [random.randrange(n) for i in range(m)]
a = np.array(a)
b = np.abs(a[1:]-a[:-1])
cnt = np.sum(b == d)
ave = cnt
i = 0
while(time.time() - start < 10):
a = [random.randrange(n) for i in range(m)]
a = np.array(a)
b = np.abs(a[1:]-a[:-1])
cnt = np.sum(b == d)
ave = ((i+1)*ave + cnt)/(i+2)
i += 1
print(ave)
"""
oks_times_n = 2 * (n - d)
ave = oks_times_n / n / n * (m - 1)
if d == 0:
ave /= 2
print(ave)
| false | 6.896552 | [
"-import numpy as np",
"-",
"-oks_times_n = 2 * np.max(n - 2 * d, 0) + 2 * d",
"+oks_times_n = 2 * (n - d)"
] | false | 0.168838 | 0.035793 | 4.717012 | [
"s691639636",
"s125308090"
] |
u644907318 | p03324 | python | s029968392 | s093184947 | 163 | 30 | 38,256 | 9,176 | Accepted | Accepted | 81.6 | D,N = list(map(int,input().split()))
if D==0:
if N<100:
print(N)
else:
print((101))
else:
if N<100:
print((100**D*N))
else:
print((100**D*101)) | D,N = list(map(int,input().split()))
if D==0 and N<=99:
print((1+N-1))
elif D==0 and N==100:
print((101))
elif D==1 and N<=99:
print((100*N))
elif D==1 and N==100:
print((10100))
elif D==2 and N<=99:
print((10000*N))
elif D==2 and N==100:
print((10000*101)) | 11 | 13 | 189 | 275 | D, N = list(map(int, input().split()))
if D == 0:
if N < 100:
print(N)
else:
print((101))
else:
if N < 100:
print((100**D * N))
else:
print((100**D * 101))
| D, N = list(map(int, input().split()))
if D == 0 and N <= 99:
print((1 + N - 1))
elif D == 0 and N == 100:
print((101))
elif D == 1 and N <= 99:
print((100 * N))
elif D == 1 and N == 100:
print((10100))
elif D == 2 and N <= 99:
print((10000 * N))
elif D == 2 and N == 100:
print((10000 * 101))
| false | 15.384615 | [
"-if D == 0:",
"- if N < 100:",
"- print(N)",
"- else:",
"- print((101))",
"-else:",
"- if N < 100:",
"- print((100**D * N))",
"- else:",
"- print((100**D * 101))",
"+if D == 0 and N <= 99:",
"+ print((1 + N - 1))",
"+elif D == 0 and N == 100:",
"+ print((101))",
"+elif D == 1 and N <= 99:",
"+ print((100 * N))",
"+elif D == 1 and N == 100:",
"+ print((10100))",
"+elif D == 2 and N <= 99:",
"+ print((10000 * N))",
"+elif D == 2 and N == 100:",
"+ print((10000 * 101))"
] | false | 0.03944 | 0.040006 | 0.985842 | [
"s029968392",
"s093184947"
] |
u057109575 | p02781 | python | s581390005 | s284238748 | 187 | 72 | 40,560 | 74,036 | Accepted | Accepted | 61.5 | N, K = list(map(int, open(0).read().split()))
X = str(N + 1)
dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(len(X) + 1)]
dp[0][0][0] = 1
for i in range(len(X)):
D = int(X[i])
for j in range(2):
for k in range(K + 1):
for d in range((9 if j == 1 else D) + 1):
if k + int(d != 0) <= K:
dp[i + 1][j | (d < D)][k + int(d != 0)] += dp[i][j][k]
print((dp[-1][-1][-1]))
| N = eval(input())
K = int(eval(input()))
dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(len(N) + 1)]
dp[0][0][0] = 1
for i in range(len(N)):
n = int(N[i])
for j in range(2):
for k in range(K + 1):
for d in range((9 if j == 1 else n) + 1):
if k + int(d != 0) <= K:
dp[i + 1][j | (d < n)][k + int(d != 0)] += dp[i][j][k]
cnt = len(N) - N.count("0")
print((dp[-1][-1][-1] + int(cnt == K)))
| 15 | 16 | 444 | 463 | N, K = list(map(int, open(0).read().split()))
X = str(N + 1)
dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(len(X) + 1)]
dp[0][0][0] = 1
for i in range(len(X)):
D = int(X[i])
for j in range(2):
for k in range(K + 1):
for d in range((9 if j == 1 else D) + 1):
if k + int(d != 0) <= K:
dp[i + 1][j | (d < D)][k + int(d != 0)] += dp[i][j][k]
print((dp[-1][-1][-1]))
| N = eval(input())
K = int(eval(input()))
dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(len(N) + 1)]
dp[0][0][0] = 1
for i in range(len(N)):
n = int(N[i])
for j in range(2):
for k in range(K + 1):
for d in range((9 if j == 1 else n) + 1):
if k + int(d != 0) <= K:
dp[i + 1][j | (d < n)][k + int(d != 0)] += dp[i][j][k]
cnt = len(N) - N.count("0")
print((dp[-1][-1][-1] + int(cnt == K)))
| false | 6.25 | [
"-N, K = list(map(int, open(0).read().split()))",
"-X = str(N + 1)",
"-dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(len(X) + 1)]",
"+N = eval(input())",
"+K = int(eval(input()))",
"+dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(len(N) + 1)]",
"-for i in range(len(X)):",
"- D = int(X[i])",
"+for i in range(len(N)):",
"+ n = int(N[i])",
"- for d in range((9 if j == 1 else D) + 1):",
"+ for d in range((9 if j == 1 else n) + 1):",
"- dp[i + 1][j | (d < D)][k + int(d != 0)] += dp[i][j][k]",
"-print((dp[-1][-1][-1]))",
"+ dp[i + 1][j | (d < n)][k + int(d != 0)] += dp[i][j][k]",
"+cnt = len(N) - N.count(\"0\")",
"+print((dp[-1][-1][-1] + int(cnt == K)))"
] | false | 0.043218 | 0.039842 | 1.084731 | [
"s581390005",
"s284238748"
] |
u285443936 | p03361 | python | s910813940 | s855041964 | 25 | 19 | 3,064 | 3,064 | Accepted | Accepted | 24 | H, W = list(map(int, input().split()))
sw = [list(str(eval(input()))) for i in range(H)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
for i in range(H):
for j in range(W):
if sw[i][j] == "#":
counter = 0
for k in range(4):
if i+dx[k] < 0 or i+dx[k] >= H or j+dy[k] < 0 or j+dy[k] >= W:
counter += 1
elif sw[i+dx[k]][j+dy[k]] == ".":
counter += 1
if counter == 4:
print("No")
exit()
print("Yes") | H, W = list(map(int, input().split()))
C = [list(eval(input())) for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]
for y in range(H):
for x in range(W):
check = 0
if C[y][x] == "#":
for i in range(4):
nx = x + X[i]
ny = y + Y[i]
if 0 <= nx < W and 0 <= ny < H and C[ny][nx] == "#":
check = 1
break
if check == 0:
print("No")
exit()
print("Yes")
| 18 | 19 | 463 | 437 | H, W = list(map(int, input().split()))
sw = [list(str(eval(input()))) for i in range(H)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for i in range(H):
for j in range(W):
if sw[i][j] == "#":
counter = 0
for k in range(4):
if i + dx[k] < 0 or i + dx[k] >= H or j + dy[k] < 0 or j + dy[k] >= W:
counter += 1
elif sw[i + dx[k]][j + dy[k]] == ".":
counter += 1
if counter == 4:
print("No")
exit()
print("Yes")
| H, W = list(map(int, input().split()))
C = [list(eval(input())) for i in range(H)]
X = [1, 0, -1, 0]
Y = [0, -1, 0, 1]
for y in range(H):
for x in range(W):
check = 0
if C[y][x] == "#":
for i in range(4):
nx = x + X[i]
ny = y + Y[i]
if 0 <= nx < W and 0 <= ny < H and C[ny][nx] == "#":
check = 1
break
if check == 0:
print("No")
exit()
print("Yes")
| false | 5.263158 | [
"-sw = [list(str(eval(input()))) for i in range(H)]",
"-dx = [1, 0, -1, 0]",
"-dy = [0, 1, 0, -1]",
"-for i in range(H):",
"- for j in range(W):",
"- if sw[i][j] == \"#\":",
"- counter = 0",
"- for k in range(4):",
"- if i + dx[k] < 0 or i + dx[k] >= H or j + dy[k] < 0 or j + dy[k] >= W:",
"- counter += 1",
"- elif sw[i + dx[k]][j + dy[k]] == \".\":",
"- counter += 1",
"- if counter == 4:",
"+C = [list(eval(input())) for i in range(H)]",
"+X = [1, 0, -1, 0]",
"+Y = [0, -1, 0, 1]",
"+for y in range(H):",
"+ for x in range(W):",
"+ check = 0",
"+ if C[y][x] == \"#\":",
"+ for i in range(4):",
"+ nx = x + X[i]",
"+ ny = y + Y[i]",
"+ if 0 <= nx < W and 0 <= ny < H and C[ny][nx] == \"#\":",
"+ check = 1",
"+ break",
"+ if check == 0:"
] | false | 0.036277 | 0.035494 | 1.022069 | [
"s910813940",
"s855041964"
] |
u997648604 | p03253 | python | s097379093 | s603231336 | 91 | 83 | 74,288 | 74,528 | Accepted | Accepted | 8.79 | import sys
sys.setrecursionlimit(10**9)
def mi(): return list(map(int,input().split()))
def ii(): return int(eval(input()))
def isp(): return input().split()
def deb(text): print(("-------\n{}\n-------".format(text)))
INF=10**20
class Counting():
def __init__(self,maxim,mod):
maxim += 1
self.mod = mod
self.fact = [0]*maxim
self.fact[0] = 1
for i in range(1,maxim):
self.fact[i] = self.fact[i-1] * i % mod
self.invfact = [0]*maxim
self.invfact[maxim-1] = pow(self.fact[maxim-1],mod-2,mod)
for i in reversed(list(range(maxim-1))):
self.invfact[i] = self.invfact[i+1] * (i+1) % mod
def nCk(self,n,r):
if n < 0 or n < r: return 0
return self.fact[n] * self.invfact[r] * self.invfact[n-r] % self.mod
def nPk(self,n,r):
if n < 0 or n < r: return 0
return self.fact[n] * self.invfact[n-r] % self.mod
def main():
N,M=mi()
MOD=10**9+7
if N == 1:
print((1))
exit()
def prime_array(n):
a = []
b = set()
while n % 2 == 0:
a.append(2)
b.add(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
b.add(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
b.add(n)
return a,b
P,P_set = prime_array(M)
P_count = {p:0 for p in P_set}
for p in P:
P_count[p] += 1
ans = 1
counting = Counting(3*10**5+10,MOD)
for p,e in list(P_count.items()):
ans *= counting.nCk(e+N-1,e)
ans %= MOD
print((ans % MOD))
if __name__ == "__main__":
main() | import sys
sys.setrecursionlimit(10**9)
def mi(): return list(map(int,input().split()))
def ii(): return int(eval(input()))
def isp(): return input().split()
def deb(text): print(("-------\n{}\n-------".format(text)))
INF=10**20
class Counting():
def __init__(self,maxim,mod):
maxim += 1
self.mod = mod
self.fact = [0]*maxim
self.fact[0] = 1
for i in range(1,maxim):
self.fact[i] = self.fact[i-1] * i % mod
self.invfact = [0]*maxim
self.invfact[maxim-1] = pow(self.fact[maxim-1],mod-2,mod)
for i in reversed(list(range(maxim-1))):
self.invfact[i] = self.invfact[i+1] * (i+1) % mod
def nCk(self,n,r):
if n < 0 or n < r: return 0
return self.fact[n] * self.invfact[r] * self.invfact[n-r] % self.mod
def nPk(self,n,r):
if n < 0 or n < r: return 0
return self.fact[n] * self.invfact[n-r] % self.mod
def main():
N,M=mi()
MOD=10**9+7
if N == 1:
print((1))
exit()
def prime_factorize(n):
P = []
P_set = set()
while n % 2 == 0:
P.append(2)
P_set.add(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
P.append(f)
P_set.add(f)
n //= f
else:
f += 2
if n != 1:
P.append(n)
P_set.add(n)
P_count = {p:0 for p in P_set}
for p in P: P_count[p] += 1
return P_count
ans = 1
counting = Counting(3*10**5+10,MOD)
for p,e in list(prime_factorize(M).items()):
ans *= counting.nCk(e+N-1,e)
ans %= MOD
print((ans % MOD))
if __name__ == "__main__":
main() | 81 | 82 | 1,832 | 1,842 | import sys
sys.setrecursionlimit(10**9)
def mi():
return list(map(int, input().split()))
def ii():
return int(eval(input()))
def isp():
return input().split()
def deb(text):
print(("-------\n{}\n-------".format(text)))
INF = 10**20
class Counting:
def __init__(self, maxim, mod):
maxim += 1
self.mod = mod
self.fact = [0] * maxim
self.fact[0] = 1
for i in range(1, maxim):
self.fact[i] = self.fact[i - 1] * i % mod
self.invfact = [0] * maxim
self.invfact[maxim - 1] = pow(self.fact[maxim - 1], mod - 2, mod)
for i in reversed(list(range(maxim - 1))):
self.invfact[i] = self.invfact[i + 1] * (i + 1) % mod
def nCk(self, n, r):
if n < 0 or n < r:
return 0
return self.fact[n] * self.invfact[r] * self.invfact[n - r] % self.mod
def nPk(self, n, r):
if n < 0 or n < r:
return 0
return self.fact[n] * self.invfact[n - r] % self.mod
def main():
N, M = mi()
MOD = 10**9 + 7
if N == 1:
print((1))
exit()
def prime_array(n):
a = []
b = set()
while n % 2 == 0:
a.append(2)
b.add(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
b.add(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
b.add(n)
return a, b
P, P_set = prime_array(M)
P_count = {p: 0 for p in P_set}
for p in P:
P_count[p] += 1
ans = 1
counting = Counting(3 * 10**5 + 10, MOD)
for p, e in list(P_count.items()):
ans *= counting.nCk(e + N - 1, e)
ans %= MOD
print((ans % MOD))
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10**9)
def mi():
return list(map(int, input().split()))
def ii():
return int(eval(input()))
def isp():
return input().split()
def deb(text):
print(("-------\n{}\n-------".format(text)))
INF = 10**20
class Counting:
def __init__(self, maxim, mod):
maxim += 1
self.mod = mod
self.fact = [0] * maxim
self.fact[0] = 1
for i in range(1, maxim):
self.fact[i] = self.fact[i - 1] * i % mod
self.invfact = [0] * maxim
self.invfact[maxim - 1] = pow(self.fact[maxim - 1], mod - 2, mod)
for i in reversed(list(range(maxim - 1))):
self.invfact[i] = self.invfact[i + 1] * (i + 1) % mod
def nCk(self, n, r):
if n < 0 or n < r:
return 0
return self.fact[n] * self.invfact[r] * self.invfact[n - r] % self.mod
def nPk(self, n, r):
if n < 0 or n < r:
return 0
return self.fact[n] * self.invfact[n - r] % self.mod
def main():
N, M = mi()
MOD = 10**9 + 7
if N == 1:
print((1))
exit()
def prime_factorize(n):
P = []
P_set = set()
while n % 2 == 0:
P.append(2)
P_set.add(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
P.append(f)
P_set.add(f)
n //= f
else:
f += 2
if n != 1:
P.append(n)
P_set.add(n)
P_count = {p: 0 for p in P_set}
for p in P:
P_count[p] += 1
return P_count
ans = 1
counting = Counting(3 * 10**5 + 10, MOD)
for p, e in list(prime_factorize(M).items()):
ans *= counting.nCk(e + N - 1, e)
ans %= MOD
print((ans % MOD))
if __name__ == "__main__":
main()
| false | 1.219512 | [
"- def prime_array(n):",
"- a = []",
"- b = set()",
"+ def prime_factorize(n):",
"+ P = []",
"+ P_set = set()",
"- a.append(2)",
"- b.add(2)",
"+ P.append(2)",
"+ P_set.add(2)",
"- a.append(f)",
"- b.add(f)",
"+ P.append(f)",
"+ P_set.add(f)",
"- a.append(n)",
"- b.add(n)",
"- return a, b",
"+ P.append(n)",
"+ P_set.add(n)",
"+ P_count = {p: 0 for p in P_set}",
"+ for p in P:",
"+ P_count[p] += 1",
"+ return P_count",
"- P, P_set = prime_array(M)",
"- P_count = {p: 0 for p in P_set}",
"- for p in P:",
"- P_count[p] += 1",
"- for p, e in list(P_count.items()):",
"+ for p, e in list(prime_factorize(M).items()):"
] | false | 0.685291 | 0.789284 | 0.868243 | [
"s097379093",
"s603231336"
] |
u057415180 | p03107 | python | s163504156 | s561767530 | 39 | 35 | 3,188 | 3,188 | Accepted | Accepted | 10.26 | s = eval(input())
a,b = 0,0
for i in range(len(s)):
if s[i] == '0':
a += 1
else:
b += 1
if a == 0 or b == 0:
print((0))
else:
print((min(a,b)*2)) | s = eval(input())
a,b = 0,0
for i in range(len(s)):
if s[i] == '0':
a += 1
else:
b += 1
print((min(a,b)*2)) | 12 | 9 | 179 | 132 | s = eval(input())
a, b = 0, 0
for i in range(len(s)):
if s[i] == "0":
a += 1
else:
b += 1
if a == 0 or b == 0:
print((0))
else:
print((min(a, b) * 2))
| s = eval(input())
a, b = 0, 0
for i in range(len(s)):
if s[i] == "0":
a += 1
else:
b += 1
print((min(a, b) * 2))
| false | 25 | [
"-if a == 0 or b == 0:",
"- print((0))",
"-else:",
"- print((min(a, b) * 2))",
"+print((min(a, b) * 2))"
] | false | 0.045256 | 0.044595 | 1.014814 | [
"s163504156",
"s561767530"
] |
u623819879 | p03912 | python | s382116036 | s477359171 | 567 | 499 | 81,388 | 76,780 | Accepted | Accepted | 11.99 | from collections import Counter
n,m=list(map(int,input().split()))
x=[int(i) for i in input().split()]
v=[[] for i in range(m)]
for i in x:v[i%m].append(i)
a=0
for i in range(1,m//2+1*(m%2==1)):
x,y=v[i],v[m-i]
d=len(x)-len(y)
if d<0:
d=-d
x,y=y,x
c=sorted(list(Counter(x).items()),key=lambda x:x[1])
p=0
for t in c:
p+=(t[1]//2)
a+=len(y)+min(p,(d//2))
a+=len(v[0])//2+(len(v[m//2])//2 if m%2==0 else 0)
print(a) | from collections import Counter
n,m=list(map(int,input().split()))
x=[int(i) for i in input().split()]
v=[[] for i in range(m)]
for i in x:v[i%m].append(i)
a=0
for i in range(1,m//2+m%2):
x,y=v[i],v[m-i]
d=len(x)-len(y)
if d<0:
d=-d
x,y=y,x
c=sorted([p[1] for p in list(Counter(x).items())])
p=0
for t in c:
p+=(t//2)
a+=len(y)+min(p,(d//2))
a+=len(v[0])//2+(len(v[m//2])//2 if m%2==0 else 0)
print(a) | 19 | 19 | 445 | 433 | from collections import Counter
n, m = list(map(int, input().split()))
x = [int(i) for i in input().split()]
v = [[] for i in range(m)]
for i in x:
v[i % m].append(i)
a = 0
for i in range(1, m // 2 + 1 * (m % 2 == 1)):
x, y = v[i], v[m - i]
d = len(x) - len(y)
if d < 0:
d = -d
x, y = y, x
c = sorted(list(Counter(x).items()), key=lambda x: x[1])
p = 0
for t in c:
p += t[1] // 2
a += len(y) + min(p, (d // 2))
a += len(v[0]) // 2 + (len(v[m // 2]) // 2 if m % 2 == 0 else 0)
print(a)
| from collections import Counter
n, m = list(map(int, input().split()))
x = [int(i) for i in input().split()]
v = [[] for i in range(m)]
for i in x:
v[i % m].append(i)
a = 0
for i in range(1, m // 2 + m % 2):
x, y = v[i], v[m - i]
d = len(x) - len(y)
if d < 0:
d = -d
x, y = y, x
c = sorted([p[1] for p in list(Counter(x).items())])
p = 0
for t in c:
p += t // 2
a += len(y) + min(p, (d // 2))
a += len(v[0]) // 2 + (len(v[m // 2]) // 2 if m % 2 == 0 else 0)
print(a)
| false | 0 | [
"-for i in range(1, m // 2 + 1 * (m % 2 == 1)):",
"+for i in range(1, m // 2 + m % 2):",
"- c = sorted(list(Counter(x).items()), key=lambda x: x[1])",
"+ c = sorted([p[1] for p in list(Counter(x).items())])",
"- p += t[1] // 2",
"+ p += t // 2"
] | false | 0.051353 | 0.129736 | 0.395825 | [
"s382116036",
"s477359171"
] |
u489959379 | p02792 | python | s867406598 | s112589516 | 376 | 211 | 3,064 | 9,196 | Accepted | Accepted | 43.88 | import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(eval(input()))
cnt = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
head = int(str(i)[0])
tale = int(str(i)[-1])
cnt[head][tale] += 1
res = 0
for i in range(1, n + 1):
head = int(str(i)[0])
tale = int(str(i)[-1])
res += cnt[tale][head]
print(res)
if __name__ == '__main__':
resolve()
| import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(eval(input()))
cnt = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
i = str(i)
head = int(i[0])
foot = int(i[-1])
cnt[head][foot] += 1
res = 0
for i in range(1, n + 1):
i = str(i)
head = int(i[0])
foot = int(i[-1])
res += cnt[foot][head]
print(res)
if __name__ == '__main__':
resolve()
| 28 | 29 | 537 | 547 | import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n = int(eval(input()))
cnt = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
head = int(str(i)[0])
tale = int(str(i)[-1])
cnt[head][tale] += 1
res = 0
for i in range(1, n + 1):
head = int(str(i)[0])
tale = int(str(i)[-1])
res += cnt[tale][head]
print(res)
if __name__ == "__main__":
resolve()
| import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n = int(eval(input()))
cnt = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
i = str(i)
head = int(i[0])
foot = int(i[-1])
cnt[head][foot] += 1
res = 0
for i in range(1, n + 1):
i = str(i)
head = int(i[0])
foot = int(i[-1])
res += cnt[foot][head]
print(res)
if __name__ == "__main__":
resolve()
| false | 3.448276 | [
"- head = int(str(i)[0])",
"- tale = int(str(i)[-1])",
"- cnt[head][tale] += 1",
"+ i = str(i)",
"+ head = int(i[0])",
"+ foot = int(i[-1])",
"+ cnt[head][foot] += 1",
"- head = int(str(i)[0])",
"- tale = int(str(i)[-1])",
"- res += cnt[tale][head]",
"+ i = str(i)",
"+ head = int(i[0])",
"+ foot = int(i[-1])",
"+ res += cnt[foot][head]"
] | false | 0.060488 | 0.057995 | 1.043003 | [
"s867406598",
"s112589516"
] |
u325956328 | p02780 | python | s686875697 | s148672177 | 256 | 225 | 25,572 | 33,996 | Accepted | Accepted | 12.11 | from collections import deque
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))
mx = 0
s = 0
q = deque()
for i in range(N):
p[i] += 1
for i in range(N):
s += p[i]
q.append(p[i])
if len(q) > K:
s -= q.popleft()
if len(q) == K:
mx = max(mx, s)
print((mx / 2))
| import numpy as np
N, K = list(map(int, input().split()))
p = np.array(list(map(int, input().split())))
e = (p + 1) / 2
# print(e)
cum_e = np.zeros(N + 1)
cum_e[1:] = np.cumsum(e)
# print(cum_e)
s = cum_e[K:] - cum_e[:-K]
print((max(s)))
| 22 | 17 | 338 | 253 | from collections import deque
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))
mx = 0
s = 0
q = deque()
for i in range(N):
p[i] += 1
for i in range(N):
s += p[i]
q.append(p[i])
if len(q) > K:
s -= q.popleft()
if len(q) == K:
mx = max(mx, s)
print((mx / 2))
| import numpy as np
N, K = list(map(int, input().split()))
p = np.array(list(map(int, input().split())))
e = (p + 1) / 2
# print(e)
cum_e = np.zeros(N + 1)
cum_e[1:] = np.cumsum(e)
# print(cum_e)
s = cum_e[K:] - cum_e[:-K]
print((max(s)))
| false | 22.727273 | [
"-from collections import deque",
"+import numpy as np",
"-p = list(map(int, input().split()))",
"-mx = 0",
"-s = 0",
"-q = deque()",
"-for i in range(N):",
"- p[i] += 1",
"-for i in range(N):",
"- s += p[i]",
"- q.append(p[i])",
"- if len(q) > K:",
"- s -= q.popleft()",
"- if len(q) == K:",
"- mx = max(mx, s)",
"-print((mx / 2))",
"+p = np.array(list(map(int, input().split())))",
"+e = (p + 1) / 2",
"+# print(e)",
"+cum_e = np.zeros(N + 1)",
"+cum_e[1:] = np.cumsum(e)",
"+# print(cum_e)",
"+s = cum_e[K:] - cum_e[:-K]",
"+print((max(s)))"
] | false | 0.034608 | 0.285507 | 0.121215 | [
"s686875697",
"s148672177"
] |
u695079172 | p03797 | python | s239810135 | s133327222 | 177 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90.4 |
n,m=list(map(int,input().split()))
first=min(n,m//2)
n -=first
m-=first*2
second = m//4
print((second+first)) |
def main():
n,m = list(map(int,input().split()))
s = n
c = m
scc = 0
#sを全部使い切る
take = min(s,c//2) #Sの個数とcを2で割った個数。小さい方を選んでSを使い切る
scc += take
s -= take
c -= take * 2
#残ったCでsccを作る(s=cが2個 cc=cが2個 合計4個必要)
take = c // 4
scc += take
print(scc)
if __name__ == '__main__':
main()
| 7 | 22 | 108 | 349 | n, m = list(map(int, input().split()))
first = min(n, m // 2)
n -= first
m -= first * 2
second = m // 4
print((second + first))
| def main():
n, m = list(map(int, input().split()))
s = n
c = m
scc = 0
# sを全部使い切る
take = min(s, c // 2) # Sの個数とcを2で割った個数。小さい方を選んでSを使い切る
scc += take
s -= take
c -= take * 2
# 残ったCでsccを作る(s=cが2個 cc=cが2個 合計4個必要)
take = c // 4
scc += take
print(scc)
if __name__ == "__main__":
main()
| false | 68.181818 | [
"-n, m = list(map(int, input().split()))",
"-first = min(n, m // 2)",
"-n -= first",
"-m -= first * 2",
"-second = m // 4",
"-print((second + first))",
"+def main():",
"+ n, m = list(map(int, input().split()))",
"+ s = n",
"+ c = m",
"+ scc = 0",
"+ # sを全部使い切る",
"+ take = min(s, c // 2) # Sの個数とcを2で割った個数。小さい方を選んでSを使い切る",
"+ scc += take",
"+ s -= take",
"+ c -= take * 2",
"+ # 残ったCでsccを作る(s=cが2個 cc=cが2個 合計4個必要)",
"+ take = c // 4",
"+ scc += take",
"+ print(scc)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.080395 | 0.040308 | 1.994509 | [
"s239810135",
"s133327222"
] |
u903005414 | p03031 | python | s487264810 | s604067530 | 42 | 29 | 3,064 | 3,064 | Accepted | Accepted | 30.95 | N, M = list(map(int, input().split()))
S = []
for _ in range(M):
arr = list(map(int, input().split()))
bit = 0
for i in arr[1:]:
# print(i)
bit = bit | (1 << (i - 1))
# print('bit', bit, bin(bit))
S.append(bit)
# S.append(arr[1:])
P = list(map(int, input().split()))
# print('S')
# print(S)
# print('P', P)
ans = 0
for bit in range(1 << N):
cnt = 0
for i in range(M):
# print('S[i], bit', bin(S[i]), bin(bit))
p = S[i] & bit
# print('p', bin(p))
on = 0
for j in range(N):
# print('judge', 1 << j, p & (1 << j))
if p & (1 << j):
on += 1
# if p & (1 << j):
# on += 1
# print('P[i], i, on', P[i], i, on)
# print('on', on)
if (on % 2) == P[i]:
cnt += 1
if cnt == M:
ans += 1
print(ans)
| N, M = list(map(int, input().split()))
S = []
for _ in range(M):
arr = list(map(int, input().split()))
bit = 0
for i in arr[1:]:
bit = bit | (1 << (i - 1))
S.append(bit)
P = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
for i in range(M):
p = S[i] & bit
on = 0
for j in range(N):
if p & (1 << j):
on += 1
if (on % 2) != P[i]:
break
else:
ans += 1
print(ans)
| 36 | 23 | 915 | 507 | N, M = list(map(int, input().split()))
S = []
for _ in range(M):
arr = list(map(int, input().split()))
bit = 0
for i in arr[1:]:
# print(i)
bit = bit | (1 << (i - 1))
# print('bit', bit, bin(bit))
S.append(bit)
# S.append(arr[1:])
P = list(map(int, input().split()))
# print('S')
# print(S)
# print('P', P)
ans = 0
for bit in range(1 << N):
cnt = 0
for i in range(M):
# print('S[i], bit', bin(S[i]), bin(bit))
p = S[i] & bit
# print('p', bin(p))
on = 0
for j in range(N):
# print('judge', 1 << j, p & (1 << j))
if p & (1 << j):
on += 1
# if p & (1 << j):
# on += 1
# print('P[i], i, on', P[i], i, on)
# print('on', on)
if (on % 2) == P[i]:
cnt += 1
if cnt == M:
ans += 1
print(ans)
| N, M = list(map(int, input().split()))
S = []
for _ in range(M):
arr = list(map(int, input().split()))
bit = 0
for i in arr[1:]:
bit = bit | (1 << (i - 1))
S.append(bit)
P = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
for i in range(M):
p = S[i] & bit
on = 0
for j in range(N):
if p & (1 << j):
on += 1
if (on % 2) != P[i]:
break
else:
ans += 1
print(ans)
| false | 36.111111 | [
"- # print(i)",
"- # print('bit', bit, bin(bit))",
"- # S.append(arr[1:])",
"-# print('S')",
"-# print(S)",
"-# print('P', P)",
"- cnt = 0",
"- # print('S[i], bit', bin(S[i]), bin(bit))",
"- # print('p', bin(p))",
"- # print('judge', 1 << j, p & (1 << j))",
"- # if p & (1 << j):",
"- # on += 1",
"- # print('P[i], i, on', P[i], i, on)",
"- # print('on', on)",
"- if (on % 2) == P[i]:",
"- cnt += 1",
"- if cnt == M:",
"+ if (on % 2) != P[i]:",
"+ break",
"+ else:"
] | false | 0.047691 | 0.047307 | 1.00813 | [
"s487264810",
"s604067530"
] |
u644907318 | p02848 | python | s356049719 | s607276360 | 218 | 77 | 41,580 | 73,088 | Accepted | Accepted | 64.68 | N = int(eval(input()))
S = input().strip()
x = ""
for i in range(len(S)):
a = ord(S[i])+N
if a<=90:
x += chr(a)
else:
x += chr(a-26)
print(x) | N = int(eval(input()))
S = input().strip()
N = N%26
x = ""
for i in range(len(S)):
k = ord(S[i])
j = (k-65+N)%26+65
x += chr(j)
print(x) | 10 | 9 | 172 | 150 | N = int(eval(input()))
S = input().strip()
x = ""
for i in range(len(S)):
a = ord(S[i]) + N
if a <= 90:
x += chr(a)
else:
x += chr(a - 26)
print(x)
| N = int(eval(input()))
S = input().strip()
N = N % 26
x = ""
for i in range(len(S)):
k = ord(S[i])
j = (k - 65 + N) % 26 + 65
x += chr(j)
print(x)
| false | 10 | [
"+N = N % 26",
"- a = ord(S[i]) + N",
"- if a <= 90:",
"- x += chr(a)",
"- else:",
"- x += chr(a - 26)",
"+ k = ord(S[i])",
"+ j = (k - 65 + N) % 26 + 65",
"+ x += chr(j)"
] | false | 0.085211 | 0.036262 | 2.349848 | [
"s356049719",
"s607276360"
] |
u392319141 | p02868 | python | s868067627 | s032092764 | 1,744 | 901 | 122,964 | 45,484 | Accepted | Accepted | 48.34 | class SegmentTree:
"""
0-indexed
query : [L, R)
"""
def __init__(self, size, initValue, cmpFunc):
self.size = 1 << (size.bit_length()) # 完全二分木にする
self.data = [initValue] * (2 * self.size - 1)
self.initValue = initValue
self.cmpFunc = cmpFunc
def build(self, rawData):
self.data[self.size - 1: self.size - 1 + len(rawData)] = rawData
for i in rawData(self.size - 1)[:: -1]:
self.data[i] = self.cmpFunc(self.data[2 * i + 1], self.data[2 * i + 2])
def update(self, index, value):
index += self.size - 1
self.data[index] = value
while index >= 0:
index = (index - 1) // 2
self.data[index] = self.cmpFunc(self.data[2 * index + 1], self.data[2 * index + 2])
def query(self, left, right):
L = left + self.size
R = right + self.size
ret = self.initValue
while L < R:
if R & 1:
R -= 1
ret = self.cmpFunc(ret, self.data[R - 1])
if L & 1:
ret = self.cmpFunc(ret, self.data[L - 1])
L += 1
L >>= 1
R >>= 1
return ret
N, M = list(map(int, input().split()))
LRC = [tuple(map(int, input().split())) for _ in range(M)]
LRC.sort()
tree = SegmentTree(N, float('inf'), min)
tree.update(0, 0)
for l, r, c in LRC:
l -= 1
newDist = tree.query(l, r) + c
if newDist < tree.query(r - 1, r):
tree.update(r - 1, newDist)
ans = tree.query(N - 1, N)
print((-1 if ans == float('inf') else ans)) | from heapq import heappush, heappop
N, M = list(map(int, input().split()))
edges = [[] for _ in range(N)]
for i in range(1, N):
edges[i].append((i - 1, 0))
for _ in range(M):
l, r, c = list(map(int, input().split()))
l -= 1
r -= 1
edges[l].append((r, c))
que = [(0, 0)]
minDist = [float('inf')] * N
while que:
d, now = heappop(que)
if d >= minDist[now]:
continue
minDist[now] = d
for to, cost in edges[now]:
dist = d + cost
if minDist[to] > dist:
heappush(que, (dist, to))
ans = minDist[N - 1]
print((-1 if ans == float('inf') else ans)) | 52 | 28 | 1,625 | 627 | class SegmentTree:
"""
0-indexed
query : [L, R)
"""
def __init__(self, size, initValue, cmpFunc):
self.size = 1 << (size.bit_length()) # 完全二分木にする
self.data = [initValue] * (2 * self.size - 1)
self.initValue = initValue
self.cmpFunc = cmpFunc
def build(self, rawData):
self.data[self.size - 1 : self.size - 1 + len(rawData)] = rawData
for i in rawData(self.size - 1)[::-1]:
self.data[i] = self.cmpFunc(self.data[2 * i + 1], self.data[2 * i + 2])
def update(self, index, value):
index += self.size - 1
self.data[index] = value
while index >= 0:
index = (index - 1) // 2
self.data[index] = self.cmpFunc(
self.data[2 * index + 1], self.data[2 * index + 2]
)
def query(self, left, right):
L = left + self.size
R = right + self.size
ret = self.initValue
while L < R:
if R & 1:
R -= 1
ret = self.cmpFunc(ret, self.data[R - 1])
if L & 1:
ret = self.cmpFunc(ret, self.data[L - 1])
L += 1
L >>= 1
R >>= 1
return ret
N, M = list(map(int, input().split()))
LRC = [tuple(map(int, input().split())) for _ in range(M)]
LRC.sort()
tree = SegmentTree(N, float("inf"), min)
tree.update(0, 0)
for l, r, c in LRC:
l -= 1
newDist = tree.query(l, r) + c
if newDist < tree.query(r - 1, r):
tree.update(r - 1, newDist)
ans = tree.query(N - 1, N)
print((-1 if ans == float("inf") else ans))
| from heapq import heappush, heappop
N, M = list(map(int, input().split()))
edges = [[] for _ in range(N)]
for i in range(1, N):
edges[i].append((i - 1, 0))
for _ in range(M):
l, r, c = list(map(int, input().split()))
l -= 1
r -= 1
edges[l].append((r, c))
que = [(0, 0)]
minDist = [float("inf")] * N
while que:
d, now = heappop(que)
if d >= minDist[now]:
continue
minDist[now] = d
for to, cost in edges[now]:
dist = d + cost
if minDist[to] > dist:
heappush(que, (dist, to))
ans = minDist[N - 1]
print((-1 if ans == float("inf") else ans))
| false | 46.153846 | [
"-class SegmentTree:",
"- \"\"\"",
"- 0-indexed",
"- query : [L, R)",
"- \"\"\"",
"-",
"- def __init__(self, size, initValue, cmpFunc):",
"- self.size = 1 << (size.bit_length()) # 完全二分木にする",
"- self.data = [initValue] * (2 * self.size - 1)",
"- self.initValue = initValue",
"- self.cmpFunc = cmpFunc",
"-",
"- def build(self, rawData):",
"- self.data[self.size - 1 : self.size - 1 + len(rawData)] = rawData",
"- for i in rawData(self.size - 1)[::-1]:",
"- self.data[i] = self.cmpFunc(self.data[2 * i + 1], self.data[2 * i + 2])",
"-",
"- def update(self, index, value):",
"- index += self.size - 1",
"- self.data[index] = value",
"- while index >= 0:",
"- index = (index - 1) // 2",
"- self.data[index] = self.cmpFunc(",
"- self.data[2 * index + 1], self.data[2 * index + 2]",
"- )",
"-",
"- def query(self, left, right):",
"- L = left + self.size",
"- R = right + self.size",
"- ret = self.initValue",
"- while L < R:",
"- if R & 1:",
"- R -= 1",
"- ret = self.cmpFunc(ret, self.data[R - 1])",
"- if L & 1:",
"- ret = self.cmpFunc(ret, self.data[L - 1])",
"- L += 1",
"- L >>= 1",
"- R >>= 1",
"- return ret",
"-",
"+from heapq import heappush, heappop",
"-LRC = [tuple(map(int, input().split())) for _ in range(M)]",
"-LRC.sort()",
"-tree = SegmentTree(N, float(\"inf\"), min)",
"-tree.update(0, 0)",
"-for l, r, c in LRC:",
"+edges = [[] for _ in range(N)]",
"+for i in range(1, N):",
"+ edges[i].append((i - 1, 0))",
"+for _ in range(M):",
"+ l, r, c = list(map(int, input().split()))",
"- newDist = tree.query(l, r) + c",
"- if newDist < tree.query(r - 1, r):",
"- tree.update(r - 1, newDist)",
"-ans = tree.query(N - 1, N)",
"+ r -= 1",
"+ edges[l].append((r, c))",
"+que = [(0, 0)]",
"+minDist = [float(\"inf\")] * N",
"+while que:",
"+ d, now = heappop(que)",
"+ if d >= minDist[now]:",
"+ continue",
"+ minDist[now] = d",
"+ for to, cost in edges[now]:",
"+ dist = d + cost",
"+ if minDist[to] > dist:",
"+ heappush(que, (dist, to))",
"+ans = minDist[N - 1]"
] | false | 0.100164 | 0.047513 | 2.108123 | [
"s868067627",
"s032092764"
] |
u243572357 | p03485 | python | s319250955 | s445272507 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | a, b = list(map(int, input().split()))
print((-(-(a+b)//2))) | a, b = list(map(int, input().split()))
print((-((-a-b)//2))) | 2 | 2 | 53 | 53 | a, b = list(map(int, input().split()))
print((-(-(a + b) // 2)))
| a, b = list(map(int, input().split()))
print((-((-a - b) // 2)))
| false | 0 | [
"-print((-(-(a + b) // 2)))",
"+print((-((-a - b) // 2)))"
] | false | 0.043778 | 0.043309 | 1.010815 | [
"s319250955",
"s445272507"
] |
u201234972 | p02768 | python | s889365936 | s275076822 | 239 | 156 | 10,868 | 3,064 | Accepted | Accepted | 34.73 | Q = 10**9+7
def getInv(N):
inv = [0] * (N + 1)
inv[1] = 1
for i in range(2, N + 1):
inv[i] = (-(Q // i) * inv[Q % i]) % Q
return inv
def main():
n, a, b = list(map( int, input().split()))
Inv = getInv(2*10**5)
def cmb(n,r):
ret = 1
for i in range(r):
ret *= n-i
ret %= Q
ret *= Inv[i+1]
ret %= Q
return ret
print(( (pow(2,n,Q) - cmb(n,a) - cmb(n,b)-1)%Q))
if __name__ == '__main__':
main() | Q = 10**9+7
def cmb(n,r):
if n-r < r: r = n-r
if r == 0: return 1
denominator = 1 #分母
numerator = 1 #分子
for i in range(r):
numerator *= n-i
numerator %= Q
denominator *= i+1
denominator %= Q
return numerator*pow(denominator, Q-2, Q)%Q
def main():
n, a, b = list(map( int, input().split()))
print(( (pow(2,n,Q) - cmb(n,a) - cmb(n,b)-1)%Q))
if __name__ == '__main__':
main()
| 24 | 19 | 523 | 499 | Q = 10**9 + 7
def getInv(N):
inv = [0] * (N + 1)
inv[1] = 1
for i in range(2, N + 1):
inv[i] = (-(Q // i) * inv[Q % i]) % Q
return inv
def main():
n, a, b = list(map(int, input().split()))
Inv = getInv(2 * 10**5)
def cmb(n, r):
ret = 1
for i in range(r):
ret *= n - i
ret %= Q
ret *= Inv[i + 1]
ret %= Q
return ret
print(((pow(2, n, Q) - cmb(n, a) - cmb(n, b) - 1) % Q))
if __name__ == "__main__":
main()
| Q = 10**9 + 7
def cmb(n, r):
if n - r < r:
r = n - r
if r == 0:
return 1
denominator = 1 # 分母
numerator = 1 # 分子
for i in range(r):
numerator *= n - i
numerator %= Q
denominator *= i + 1
denominator %= Q
return numerator * pow(denominator, Q - 2, Q) % Q
def main():
n, a, b = list(map(int, input().split()))
print(((pow(2, n, Q) - cmb(n, a) - cmb(n, b) - 1) % Q))
if __name__ == "__main__":
main()
| false | 20.833333 | [
"-def getInv(N):",
"- inv = [0] * (N + 1)",
"- inv[1] = 1",
"- for i in range(2, N + 1):",
"- inv[i] = (-(Q // i) * inv[Q % i]) % Q",
"- return inv",
"+def cmb(n, r):",
"+ if n - r < r:",
"+ r = n - r",
"+ if r == 0:",
"+ return 1",
"+ denominator = 1 # 分母",
"+ numerator = 1 # 分子",
"+ for i in range(r):",
"+ numerator *= n - i",
"+ numerator %= Q",
"+ denominator *= i + 1",
"+ denominator %= Q",
"+ return numerator * pow(denominator, Q - 2, Q) % Q",
"- Inv = getInv(2 * 10**5)",
"-",
"- def cmb(n, r):",
"- ret = 1",
"- for i in range(r):",
"- ret *= n - i",
"- ret %= Q",
"- ret *= Inv[i + 1]",
"- ret %= Q",
"- return ret",
"-"
] | false | 0.26546 | 0.113588 | 2.337039 | [
"s889365936",
"s275076822"
] |
u930705402 | p02838 | python | s505239004 | s118664316 | 1,821 | 1,296 | 122,936 | 122,808 | Accepted | Accepted | 28.83 | MOD=10**9+7
N=int(eval(input()))
A=list(map(int,input().split()))
ans=0
for j in range(60):
k=2**j
count=0
for i in range(N):
if(A[i]&k):
ans=(ans+(2**j)*(i-count))%MOD
count+=1
else:
ans=(ans+(2**j)*count)%MOD
print(ans) | MOD=10**9+7
N=int(eval(input()))
A=list(map(int,input().split()))
ans=0
for j in range(60):
k=2**j
count=0
for i in range(N):
if(A[i]&k):
ans=(ans+k*(i-count))%MOD
count+=1
else:
ans=(ans+k*count)%MOD
print(ans) | 14 | 14 | 292 | 282 | MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
for j in range(60):
k = 2**j
count = 0
for i in range(N):
if A[i] & k:
ans = (ans + (2**j) * (i - count)) % MOD
count += 1
else:
ans = (ans + (2**j) * count) % MOD
print(ans)
| MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
for j in range(60):
k = 2**j
count = 0
for i in range(N):
if A[i] & k:
ans = (ans + k * (i - count)) % MOD
count += 1
else:
ans = (ans + k * count) % MOD
print(ans)
| false | 0 | [
"- ans = (ans + (2**j) * (i - count)) % MOD",
"+ ans = (ans + k * (i - count)) % MOD",
"- ans = (ans + (2**j) * count) % MOD",
"+ ans = (ans + k * count) % MOD"
] | false | 0.036169 | 0.035636 | 1.014957 | [
"s505239004",
"s118664316"
] |
u013756322 | p03088 | python | s485154083 | s464334734 | 63 | 56 | 4,468 | 4,468 | Accepted | Accepted | 11.11 | import pprint
n = int(eval(input()))
dp = [{} for i in range(n + 1)]
s = "AGCT"
M = 10 ** 9 + 7
for j in range(n + 1):
for c1 in s:
for c2 in s:
for c3 in s:
dp[j][c1 + c2 + c3] = 0
dp[0]["TTT"] = 1
for l in range(n):
for c1 in s:
for c2 in s:
for c3 in s:
for p in s:
if c2 == "A" and c3 == "G" and p == "C":
continue
if c1 == "A" and c3 == "G" and p == "C":
continue
if c1 == "A" and c2 == "G" and p == "C":
continue
if c2 == "G" and c3 == "A" and p == "C":
continue
if c2 == "A" and c3 == "C" and p == "G":
continue
dp[l + 1][c2 + c3 + p] += dp[l][c1 + c2 + c3]
dp[l + 1][c2 + c3 + p] = dp[l + 1][c2 + c3 + p] % M
ans = 0
for c1 in s:
for c2 in s:
for c3 in s:
ans += dp[n][c1 + c2 + c3]
ans = ans % M
print(ans)
| import pprint
n = int(eval(input()))
dp = [{} for i in range(n + 1)]
s = "AGCT"
M = 10 ** 9 + 7
for j in range(n + 1):
for c1 in s:
for c2 in s:
for c3 in s:
dp[j][c1 + c2 + c3] = 0
dp[0]["TTT"] = 1
for l in range(n):
for c1 in s:
for c2 in s:
for c3 in s:
for p in s:
if c2 == "A" and c3 == "G" and p == "C":
continue
if c1 == "A" and c3 == "G" and p == "C":
continue
if c1 == "A" and c2 == "G" and p == "C":
continue
if c2 == "G" and c3 == "A" and p == "C":
continue
if c2 == "A" and c3 == "C" and p == "G":
continue
dp[l + 1][c2 + c3 + p] = (dp[l + 1][c2 + c3 + p] + dp[l][c1 + c2 + c3]) % M
ans = 0
for c1 in s:
for c2 in s:
for c3 in s:
ans += dp[n][c1 + c2 + c3]
ans = ans % M
print(ans)
| 39 | 39 | 940 | 919 | import pprint
n = int(eval(input()))
dp = [{} for i in range(n + 1)]
s = "AGCT"
M = 10**9 + 7
for j in range(n + 1):
for c1 in s:
for c2 in s:
for c3 in s:
dp[j][c1 + c2 + c3] = 0
dp[0]["TTT"] = 1
for l in range(n):
for c1 in s:
for c2 in s:
for c3 in s:
for p in s:
if c2 == "A" and c3 == "G" and p == "C":
continue
if c1 == "A" and c3 == "G" and p == "C":
continue
if c1 == "A" and c2 == "G" and p == "C":
continue
if c2 == "G" and c3 == "A" and p == "C":
continue
if c2 == "A" and c3 == "C" and p == "G":
continue
dp[l + 1][c2 + c3 + p] += dp[l][c1 + c2 + c3]
dp[l + 1][c2 + c3 + p] = dp[l + 1][c2 + c3 + p] % M
ans = 0
for c1 in s:
for c2 in s:
for c3 in s:
ans += dp[n][c1 + c2 + c3]
ans = ans % M
print(ans)
| import pprint
n = int(eval(input()))
dp = [{} for i in range(n + 1)]
s = "AGCT"
M = 10**9 + 7
for j in range(n + 1):
for c1 in s:
for c2 in s:
for c3 in s:
dp[j][c1 + c2 + c3] = 0
dp[0]["TTT"] = 1
for l in range(n):
for c1 in s:
for c2 in s:
for c3 in s:
for p in s:
if c2 == "A" and c3 == "G" and p == "C":
continue
if c1 == "A" and c3 == "G" and p == "C":
continue
if c1 == "A" and c2 == "G" and p == "C":
continue
if c2 == "G" and c3 == "A" and p == "C":
continue
if c2 == "A" and c3 == "C" and p == "G":
continue
dp[l + 1][c2 + c3 + p] = (
dp[l + 1][c2 + c3 + p] + dp[l][c1 + c2 + c3]
) % M
ans = 0
for c1 in s:
for c2 in s:
for c3 in s:
ans += dp[n][c1 + c2 + c3]
ans = ans % M
print(ans)
| false | 0 | [
"- dp[l + 1][c2 + c3 + p] += dp[l][c1 + c2 + c3]",
"- dp[l + 1][c2 + c3 + p] = dp[l + 1][c2 + c3 + p] % M",
"+ dp[l + 1][c2 + c3 + p] = (",
"+ dp[l + 1][c2 + c3 + p] + dp[l][c1 + c2 + c3]",
"+ ) % M"
] | false | 0.18277 | 0.00841 | 21.731283 | [
"s485154083",
"s464334734"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.