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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u970308980 | p03479 | python | s790696147 | s735255979 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | X, Y = list(map(int, input().split()))
ans = 0
tmp = X
while tmp <= Y:
tmp *= 2
ans += 1
print(ans)
| X, Y = list(map(int, input().split()))
cnt = 0
while X <= Y:
cnt += 1
X *= 2
print(cnt)
| 9 | 8 | 112 | 99 | X, Y = list(map(int, input().split()))
ans = 0
tmp = X
while tmp <= Y:
tmp *= 2
ans += 1
print(ans)
| X, Y = list(map(int, input().split()))
cnt = 0
while X <= Y:
cnt += 1
X *= 2
print(cnt)
| false | 11.111111 | [
"-ans = 0",
"-tmp = X",
"-while tmp <= Y:",
"- tmp *= 2",
"- ans += 1",
"-print(ans)",
"+cnt = 0",
"+while X <= Y:",
"+ cnt += 1",
"+ X *= 2",
"+print(cnt)"
] | false | 0.039268 | 0.040503 | 0.96951 | [
"s790696147",
"s735255979"
] |
u729133443 | p03658 | python | s361764328 | s543193519 | 178 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90.45 | _,k,*l=list(map(int,open(0).read().split()));print((sum(sorted(l)[-k:]))) | t,l=open(0);print((sum(sorted(map(int,l.split()))[-int(t[2:]):]))) | 1 | 1 | 65 | 64 | _, k, *l = list(map(int, open(0).read().split()))
print((sum(sorted(l)[-k:])))
| t, l = open(0)
print((sum(sorted(map(int, l.split()))[-int(t[2:]) :])))
| false | 0 | [
"-_, k, *l = list(map(int, open(0).read().split()))",
"-print((sum(sorted(l)[-k:])))",
"+t, l = open(0)",
"+print((sum(sorted(map(int, l.split()))[-int(t[2:]) :])))"
] | false | 0.078459 | 0.046123 | 1.701075 | [
"s361764328",
"s543193519"
] |
u489762173 | p02947 | python | s114685659 | s546347925 | 362 | 234 | 18,456 | 18,336 | Accepted | Accepted | 35.36 | import sys
from operator import mul
from functools import reduce
def combinations_count(n, r):
r = min(r, n - r)
numer = reduce(mul, list(range(n, n - r, -1)), 1)
denom = reduce(mul, list(range(1, r + 1)), 1)
return numer // denom
def main():
N = int(eval(input()))
Ss = {}
for x in range(N):
tmp = ''.join(sorted(eval(input())))
if tmp in Ss:
Ss[tmp] += 1
else:
Ss[tmp] = 1
ans = 0
for i in list(Ss.values()):
if i != 1:
ans += combinations_count(i, 2)
print(ans)
main() | import sys
from operator import mul
from functools import reduce
def combinations_count(n, r):
r = min(r, n - r)
numer = reduce(mul, list(range(n, n - r, -1)), 1)
denom = reduce(mul, list(range(1, r + 1)), 1)
return numer // denom
def main():
N = int(eval(input()))
Ss = {}
for x in range(N):
tmp = ''.join(sorted(sys.stdin.readline().rstrip()))
if tmp in Ss:
Ss[tmp] += 1
else:
Ss[tmp] = 1
ans = 0
for i in list(Ss.values()):
if i != 1:
ans += combinations_count(i, 2)
print(ans)
main() | 32 | 32 | 589 | 611 | import sys
from operator import mul
from functools import reduce
def combinations_count(n, r):
r = min(r, n - r)
numer = reduce(mul, list(range(n, n - r, -1)), 1)
denom = reduce(mul, list(range(1, r + 1)), 1)
return numer // denom
def main():
N = int(eval(input()))
Ss = {}
for x in range(N):
tmp = "".join(sorted(eval(input())))
if tmp in Ss:
Ss[tmp] += 1
else:
Ss[tmp] = 1
ans = 0
for i in list(Ss.values()):
if i != 1:
ans += combinations_count(i, 2)
print(ans)
main()
| import sys
from operator import mul
from functools import reduce
def combinations_count(n, r):
r = min(r, n - r)
numer = reduce(mul, list(range(n, n - r, -1)), 1)
denom = reduce(mul, list(range(1, r + 1)), 1)
return numer // denom
def main():
N = int(eval(input()))
Ss = {}
for x in range(N):
tmp = "".join(sorted(sys.stdin.readline().rstrip()))
if tmp in Ss:
Ss[tmp] += 1
else:
Ss[tmp] = 1
ans = 0
for i in list(Ss.values()):
if i != 1:
ans += combinations_count(i, 2)
print(ans)
main()
| false | 0 | [
"- tmp = \"\".join(sorted(eval(input())))",
"+ tmp = \"\".join(sorted(sys.stdin.readline().rstrip()))"
] | false | 0.038158 | 0.03769 | 1.012411 | [
"s114685659",
"s546347925"
] |
u110859855 | p02689 | python | s436007959 | s403552830 | 317 | 274 | 20,916 | 20,088 | Accepted | Accepted | 13.56 | import copy
n,m = list(map(int,input().split()))
tall = [int(e) for e in input().split()]
bridge = copy.copy(tall)
for i in range(m):
c = [int(f)-1 for f in input().split()]
a,b = c[0],c[1]
if bridge[a] < tall[b]:
bridge[a] = tall[b]
elif bridge[a] == tall[b]:
bridge[a] = 10**10
if bridge[b] < tall[a]:
bridge[b] = tall[a]
elif bridge[b] == tall[a]:
bridge[b] = 10**10
cnt = 0
for j in range(n):
if tall[j] == bridge[j]:
cnt += 1
print(cnt) | n,m = list(map(int,input().split()))
tall = [int(e) for e in input().split()]
is_best = [True]*n
for i in range(m):
c = [int(f)-1 for f in input().split()]
a,b = c[0],c[1]
if tall[a] < tall[b]:
is_best[a] = False
elif tall[b] < tall[a]:
is_best[b] = False
else:
is_best[a],is_best[b] = False,False
print((is_best.count(True))) | 24 | 18 | 530 | 384 | import copy
n, m = list(map(int, input().split()))
tall = [int(e) for e in input().split()]
bridge = copy.copy(tall)
for i in range(m):
c = [int(f) - 1 for f in input().split()]
a, b = c[0], c[1]
if bridge[a] < tall[b]:
bridge[a] = tall[b]
elif bridge[a] == tall[b]:
bridge[a] = 10**10
if bridge[b] < tall[a]:
bridge[b] = tall[a]
elif bridge[b] == tall[a]:
bridge[b] = 10**10
cnt = 0
for j in range(n):
if tall[j] == bridge[j]:
cnt += 1
print(cnt)
| n, m = list(map(int, input().split()))
tall = [int(e) for e in input().split()]
is_best = [True] * n
for i in range(m):
c = [int(f) - 1 for f in input().split()]
a, b = c[0], c[1]
if tall[a] < tall[b]:
is_best[a] = False
elif tall[b] < tall[a]:
is_best[b] = False
else:
is_best[a], is_best[b] = False, False
print((is_best.count(True)))
| false | 25 | [
"-import copy",
"-",
"-bridge = copy.copy(tall)",
"+is_best = [True] * n",
"- if bridge[a] < tall[b]:",
"- bridge[a] = tall[b]",
"- elif bridge[a] == tall[b]:",
"- bridge[a] = 10**10",
"- if bridge[b] < tall[a]:",
"- bridge[b] = tall[a]",
"- elif bridge[b] == tall[a]:",
"- bridge[b] = 10**10",
"-cnt = 0",
"-for j in range(n):",
"- if tall[j] == bridge[j]:",
"- cnt += 1",
"-print(cnt)",
"+ if tall[a] < tall[b]:",
"+ is_best[a] = False",
"+ elif tall[b] < tall[a]:",
"+ is_best[b] = False",
"+ else:",
"+ is_best[a], is_best[b] = False, False",
"+print((is_best.count(True)))"
] | false | 0.047421 | 0.03926 | 1.20788 | [
"s436007959",
"s403552830"
] |
u645250356 | p03315 | python | s585914273 | s581530990 | 312 | 35 | 67,308 | 10,312 | Accepted | Accepted | 88.78 | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
s = list(eval(input()))
print((s.count('+') - s.count('-')))
| from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
s = eval(input())
res = 0
for x in s:
if x == '+':
res += 1
else:
res -= 1
print(res) | 11 | 18 | 370 | 457 | from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
s = list(eval(input()))
print((s.count("+") - s.count("-")))
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
s = eval(input())
res = 0
for x in s:
if x == "+":
res += 1
else:
res -= 1
print(res)
| false | 38.888889 | [
"-from heapq import heappop, heappush, heapify",
"-import sys, bisect, math, itertools, fractions",
"+from heapq import heappop, heappush",
"+from bisect import bisect_left, bisect_right",
"+import sys, math, itertools, fractions",
"-s = list(eval(input()))",
"-print((s.count(\"+\") - s.count(\"-\")))",
"+s = eval(input())",
"+res = 0",
"+for x in s:",
"+ if x == \"+\":",
"+ res += 1",
"+ else:",
"+ res -= 1",
"+print(res)"
] | false | 0.07616 | 0.035522 | 2.144003 | [
"s585914273",
"s581530990"
] |
u186838327 | p03283 | python | s869763188 | s039553031 | 622 | 457 | 79,924 | 22,692 | Accepted | Accepted | 26.53 | n, m, q = list(map(int, input().split()))
A = [[0]*n for i in range(n)]
for i in range(m):
l, r = list(map(int, input().split()))
l, r = l-1, r-1
A[l][r] += 1
#print(A)
s = [[0]*(n+1) for _ in range(n+1)]
for i in range(n):
for j in range(n):
s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j] + A[i][j]
#print(s)
for i in range(q):
p, q = list(map(int, input().split()))
p, q = p-1, q-1
ans = s[q+1][q+1] - s[p][q+1] - s[q+1][p] + s[p][p]
print(ans)
| import sys
import io, os
#input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n, m, Q = list(map(int, input().split()))
C = [[0]*n for _ in range(n)]
for i in range(m):
l, r = list(map(int, input().split()))
l, r = l-1, r-1
C[l][r] += 1
s = [[0]*(n+1) for _ in range(n+1)]
for i in range(n):
for j in range(n):
s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j] + C[i][j]
for i in range(Q):
p, q = list(map(int, input().split()))
p, q = p-1, q-1
ans = s[q+1][q+1]-s[q+1][p]-s[p][q+1]+s[p][p]
print(ans)
| 23 | 22 | 490 | 586 | n, m, q = list(map(int, input().split()))
A = [[0] * n for i in range(n)]
for i in range(m):
l, r = list(map(int, input().split()))
l, r = l - 1, r - 1
A[l][r] += 1
# print(A)
s = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(n):
for j in range(n):
s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + A[i][j]
# print(s)
for i in range(q):
p, q = list(map(int, input().split()))
p, q = p - 1, q - 1
ans = s[q + 1][q + 1] - s[p][q + 1] - s[q + 1][p] + s[p][p]
print(ans)
| import sys
import io, os
# input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, m, Q = list(map(int, input().split()))
C = [[0] * n for _ in range(n)]
for i in range(m):
l, r = list(map(int, input().split()))
l, r = l - 1, r - 1
C[l][r] += 1
s = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(n):
for j in range(n):
s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + C[i][j]
for i in range(Q):
p, q = list(map(int, input().split()))
p, q = p - 1, q - 1
ans = s[q + 1][q + 1] - s[q + 1][p] - s[p][q + 1] + s[p][p]
print(ans)
| false | 4.347826 | [
"-n, m, q = list(map(int, input().split()))",
"-A = [[0] * n for i in range(n)]",
"+import sys",
"+import io, os",
"+",
"+# input = sys.stdin.buffer.readline",
"+input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline",
"+n, m, Q = list(map(int, input().split()))",
"+C = [[0] * n for _ in range(n)]",
"- A[l][r] += 1",
"-# print(A)",
"+ C[l][r] += 1",
"- s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + A[i][j]",
"-# print(s)",
"-for i in range(q):",
"+ s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + C[i][j]",
"+for i in range(Q):",
"- ans = s[q + 1][q + 1] - s[p][q + 1] - s[q + 1][p] + s[p][p]",
"+ ans = s[q + 1][q + 1] - s[q + 1][p] - s[p][q + 1] + s[p][p]"
] | false | 0.038225 | 0.207728 | 0.184017 | [
"s869763188",
"s039553031"
] |
u984592063 | p02679 | python | s424693486 | s388389766 | 1,750 | 885 | 68,480 | 68,572 | Accepted | Accepted | 49.43 | from collections import defaultdict
def gcd(a, b):
return gcd(b, a%b) if b else a
mod = 10 ** 9 + 7
N = int(eval(input()))
X = defaultdict(lambda: [0, 0])
# X = dict()
x = 0
y = 0
z = 0
for i in range(N):
a, b = list(map(int, input().split()))
g = abs(gcd(a, b))
if a * b > 0:
X[(abs(a) // g, abs(b) // g)][0] += 1
elif a * b < 0:
X[(abs(b) // g, abs(a) // g)][1] += 1
else:
if a:
x += 1
elif b:
y += 1
else:
z += 1
# suppose we have a super head point which can put togother with every point.
ans = 1
pow2 = [1]
for i in range(N):
pow2 += [pow2[-1] * 2 % mod]
for i in list(X.values()):
ans *= pow2[i[0]] + pow2[i[1]]- 1
ans %= mod
ans *= pow2[x] + pow2[y] - 1
print(((ans+z-1)%mod))
| mod = 10 ** 9 + 7
from math import gcd
N = int(eval(input()))
from collections import defaultdict
X = defaultdict(lambda: [0, 0])
x = 0
y = 0
z = 0
for i in range(N):
a, b = list(map(int, input().split()))
g = abs(gcd(a, b))
if a * b > 0:
X[(abs(a) // g, abs(b) // g)][0] += 1
elif a * b < 0:
X[(abs(b) // g, abs(a) // g)][1] += 1
else:
if a:
x += 1
elif b:
y += 1
else:
z += 1
ans = 1
pow2 = [1]
for i in range(N):
pow2 += [pow2[-1] * 2 % mod]
for i in list(X.values()):
ans *= pow2[i[0]] + pow2[i[1]]- 1
ans %= mod
ans *= pow2[x] + pow2[y] - 1
ans += z - 1
ans %= mod
print(ans)
| 36 | 33 | 814 | 649 | from collections import defaultdict
def gcd(a, b):
return gcd(b, a % b) if b else a
mod = 10**9 + 7
N = int(eval(input()))
X = defaultdict(lambda: [0, 0])
# X = dict()
x = 0
y = 0
z = 0
for i in range(N):
a, b = list(map(int, input().split()))
g = abs(gcd(a, b))
if a * b > 0:
X[(abs(a) // g, abs(b) // g)][0] += 1
elif a * b < 0:
X[(abs(b) // g, abs(a) // g)][1] += 1
else:
if a:
x += 1
elif b:
y += 1
else:
z += 1
# suppose we have a super head point which can put togother with every point.
ans = 1
pow2 = [1]
for i in range(N):
pow2 += [pow2[-1] * 2 % mod]
for i in list(X.values()):
ans *= pow2[i[0]] + pow2[i[1]] - 1
ans %= mod
ans *= pow2[x] + pow2[y] - 1
print(((ans + z - 1) % mod))
| mod = 10**9 + 7
from math import gcd
N = int(eval(input()))
from collections import defaultdict
X = defaultdict(lambda: [0, 0])
x = 0
y = 0
z = 0
for i in range(N):
a, b = list(map(int, input().split()))
g = abs(gcd(a, b))
if a * b > 0:
X[(abs(a) // g, abs(b) // g)][0] += 1
elif a * b < 0:
X[(abs(b) // g, abs(a) // g)][1] += 1
else:
if a:
x += 1
elif b:
y += 1
else:
z += 1
ans = 1
pow2 = [1]
for i in range(N):
pow2 += [pow2[-1] * 2 % mod]
for i in list(X.values()):
ans *= pow2[i[0]] + pow2[i[1]] - 1
ans %= mod
ans *= pow2[x] + pow2[y] - 1
ans += z - 1
ans %= mod
print(ans)
| false | 8.333333 | [
"+mod = 10**9 + 7",
"+from math import gcd",
"+",
"+N = int(eval(input()))",
"-",
"-def gcd(a, b):",
"- return gcd(b, a % b) if b else a",
"-",
"-",
"-mod = 10**9 + 7",
"-N = int(eval(input()))",
"-# X = dict()",
"-# suppose we have a super head point which can put togother with every point.",
"-print(((ans + z - 1) % mod))",
"+ans += z - 1",
"+ans %= mod",
"+print(ans)"
] | false | 0.091605 | 0.049201 | 1.861837 | [
"s424693486",
"s388389766"
] |
u536034761 | p02684 | python | s852110828 | s221163552 | 195 | 141 | 47,460 | 32,304 | Accepted | Accepted | 27.69 | N, K = list(map(int, input().split(" ")))
routs = {}
location = [0 for i in range(N + 1)]
tereporter = list(map(int, input().split()))
for i in range(N):
routs[i] = tereporter[i] - 1
present_location = 0
n = 0
for i in range(K):
n += 1
present_location = routs[present_location]
if location[present_location] == 0:
location[present_location] = n
else:
loop = n - location[present_location]
if (K - location[present_location]) % loop == 0:
break
else:
for i in range((K - location[present_location]) % loop):
present_location = routs[present_location]
break
print((present_location + 1)) | N, K = list(map(int, input().split()))
teleporters = list(map(int, input().split()))
n = 0
present = 0
praces = [-1 for i in range(N)]
praces[0] = 0
for i in range(K):
present = teleporters[present] - 1
n += 1
if praces[present] == -1:
praces[present] = n
else:
before = praces[present]
loop = n - before
remainder = (K - before) % loop
present = praces.index(before + remainder)
break
print((present + 1)) | 22 | 18 | 651 | 447 | N, K = list(map(int, input().split(" ")))
routs = {}
location = [0 for i in range(N + 1)]
tereporter = list(map(int, input().split()))
for i in range(N):
routs[i] = tereporter[i] - 1
present_location = 0
n = 0
for i in range(K):
n += 1
present_location = routs[present_location]
if location[present_location] == 0:
location[present_location] = n
else:
loop = n - location[present_location]
if (K - location[present_location]) % loop == 0:
break
else:
for i in range((K - location[present_location]) % loop):
present_location = routs[present_location]
break
print((present_location + 1))
| N, K = list(map(int, input().split()))
teleporters = list(map(int, input().split()))
n = 0
present = 0
praces = [-1 for i in range(N)]
praces[0] = 0
for i in range(K):
present = teleporters[present] - 1
n += 1
if praces[present] == -1:
praces[present] = n
else:
before = praces[present]
loop = n - before
remainder = (K - before) % loop
present = praces.index(before + remainder)
break
print((present + 1))
| false | 18.181818 | [
"-N, K = list(map(int, input().split(\" \")))",
"-routs = {}",
"-location = [0 for i in range(N + 1)]",
"-tereporter = list(map(int, input().split()))",
"-for i in range(N):",
"- routs[i] = tereporter[i] - 1",
"-present_location = 0",
"+N, K = list(map(int, input().split()))",
"+teleporters = list(map(int, input().split()))",
"+present = 0",
"+praces = [-1 for i in range(N)]",
"+praces[0] = 0",
"+ present = teleporters[present] - 1",
"- present_location = routs[present_location]",
"- if location[present_location] == 0:",
"- location[present_location] = n",
"+ if praces[present] == -1:",
"+ praces[present] = n",
"- loop = n - location[present_location]",
"- if (K - location[present_location]) % loop == 0:",
"- break",
"- else:",
"- for i in range((K - location[present_location]) % loop):",
"- present_location = routs[present_location]",
"- break",
"-print((present_location + 1))",
"+ before = praces[present]",
"+ loop = n - before",
"+ remainder = (K - before) % loop",
"+ present = praces.index(before + remainder)",
"+ break",
"+print((present + 1))"
] | false | 0.102024 | 0.045997 | 2.21805 | [
"s852110828",
"s221163552"
] |
u534308356 | p02707 | python | s293115657 | s405488614 | 178 | 148 | 34,208 | 33,924 | Accepted | Accepted | 16.85 | import collections
n = int(eval(input()))
data = list(map(int, input().split()))
c = collections.Counter(data)
for i in range(1, n+1):
print((c[i]))
| import collections
n = int(eval(input()))
data = list(map(int, input().split()))
count = [0] * n
for d in data:
count[d-1] += 1
for c in count:
print(c)
| 9 | 12 | 154 | 166 | import collections
n = int(eval(input()))
data = list(map(int, input().split()))
c = collections.Counter(data)
for i in range(1, n + 1):
print((c[i]))
| import collections
n = int(eval(input()))
data = list(map(int, input().split()))
count = [0] * n
for d in data:
count[d - 1] += 1
for c in count:
print(c)
| false | 25 | [
"-c = collections.Counter(data)",
"-for i in range(1, n + 1):",
"- print((c[i]))",
"+count = [0] * n",
"+for d in data:",
"+ count[d - 1] += 1",
"+for c in count:",
"+ print(c)"
] | false | 0.082853 | 0.034679 | 2.389131 | [
"s293115657",
"s405488614"
] |
u623814058 | p03494 | python | s391948206 | s170593752 | 26 | 23 | 9,216 | 9,120 | Accepted | Accepted | 11.54 | N = int(eval(input()))
A = list(map(int, input().split()))
count = 0
while all(a % 2 == 0 for a in A):
A = list([x / 2 for x in A])
count = count + 1
print(count) | N=int(eval(input()))
A=list(map(int, input().split()))
count=0
while all(a%2==0 for a in A):
A=[i/2 for i in A]
count+=1
print(count) | 9 | 7 | 179 | 141 | N = int(eval(input()))
A = list(map(int, input().split()))
count = 0
while all(a % 2 == 0 for a in A):
A = list([x / 2 for x in A])
count = count + 1
print(count)
| N = int(eval(input()))
A = list(map(int, input().split()))
count = 0
while all(a % 2 == 0 for a in A):
A = [i / 2 for i in A]
count += 1
print(count)
| false | 22.222222 | [
"- A = list([x / 2 for x in A])",
"- count = count + 1",
"+ A = [i / 2 for i in A]",
"+ count += 1"
] | false | 0.101705 | 0.048637 | 2.091112 | [
"s391948206",
"s170593752"
] |
u490553751 | p02784 | python | s119541906 | s748772258 | 60 | 47 | 13,588 | 14,268 | Accepted | Accepted | 21.67 | import sys
input = sys.stdin.readline
H,N = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
sum = 0
for i in range(N) :
sum += A[i]
if sum >= H :
print("Yes")
else :
print("No") | #template
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
H,N = inputlist()
A = inputlist()
s = sum(A)
if H <= s:
print("Yes")
else:
print("No") | 11 | 10 | 223 | 203 | import sys
input = sys.stdin.readline
H, N = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
sum = 0
for i in range(N):
sum += A[i]
if sum >= H:
print("Yes")
else:
print("No")
| # template
from collections import Counter
def inputlist():
return [int(j) for j in input().split()]
H, N = inputlist()
A = inputlist()
s = sum(A)
if H <= s:
print("Yes")
else:
print("No")
| false | 9.090909 | [
"-import sys",
"+# template",
"+from collections import Counter",
"-input = sys.stdin.readline",
"-H, N = [int(i) for i in input().split()]",
"-A = [int(i) for i in input().split()]",
"-sum = 0",
"-for i in range(N):",
"- sum += A[i]",
"-if sum >= H:",
"+",
"+def inputlist():",
"+ return [int(j) for j in input().split()]",
"+",
"+",
"+H, N = inputlist()",
"+A = inputlist()",
"+s = sum(A)",
"+if H <= s:"
] | false | 0.040445 | 0.0481 | 0.840857 | [
"s119541906",
"s748772258"
] |
u634079249 | p03835 | python | s610063890 | s045371902 | 1,280 | 748 | 2,940 | 39,832 | Accepted | Accepted | 41.56 | import sys
import os
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
K, S = list(map(int, sys.stdin.readline().split()))
ret = 0
for x in range(K + 1):
for y in range(K + 1):
if S - x - y <= K and S - x - y >= 0:
ret += 1
print(ret)
if __name__ == '__main__':
main()
| import sys
import os
import math
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
MOD = 10 ** 9 + 7
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
K, S = il()
P = [1 for x in range(K + 1) for y in range(K + 1) if 0 <= S - x - y <= K]
print((sum(P)))
if __name__ == '__main__':
main()
| 20 | 27 | 376 | 799 | import sys
import os
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
K, S = list(map(int, sys.stdin.readline().split()))
ret = 0
for x in range(K + 1):
for y in range(K + 1):
if S - x - y <= K and S - x - y >= 0:
ret += 1
print(ret)
if __name__ == "__main__":
main()
| import sys
import os
import math
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
MOD = 10**9 + 7
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
K, S = il()
P = [1 for x in range(K + 1) for y in range(K + 1) if 0 <= S - x - y <= K]
print((sum(P)))
if __name__ == "__main__":
main()
| false | 25.925926 | [
"+import math",
"+",
"+ii = lambda: int(sys.stdin.buffer.readline().rstrip())",
"+il = lambda: list(map(int, sys.stdin.buffer.readline().split()))",
"+fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))",
"+iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]",
"+iss = lambda: sys.stdin.buffer.readline().decode().rstrip()",
"+sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))",
"+isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]",
"+MOD = 10**9 + 7",
"- K, S = list(map(int, sys.stdin.readline().split()))",
"- ret = 0",
"- for x in range(K + 1):",
"- for y in range(K + 1):",
"- if S - x - y <= K and S - x - y >= 0:",
"- ret += 1",
"- print(ret)",
"+ K, S = il()",
"+ P = [1 for x in range(K + 1) for y in range(K + 1) if 0 <= S - x - y <= K]",
"+ print((sum(P)))"
] | false | 0.043382 | 0.083778 | 0.517828 | [
"s610063890",
"s045371902"
] |
u659159398 | p02712 | python | s258445408 | s768326191 | 151 | 68 | 9,168 | 64,712 | Accepted | Accepted | 54.97 | n = int(eval(input()))
totsum = 0
for num in range(1, n+1):
if num%3!=0 and num%5!=0:
totsum+=num
print(totsum) | n = int(eval(input()))
ans = 0
for i in range(1, n+1):
if i%3 == 0 or i%5==0:
pass
else:
ans += i
print(ans) | 7 | 8 | 122 | 133 | n = int(eval(input()))
totsum = 0
for num in range(1, n + 1):
if num % 3 != 0 and num % 5 != 0:
totsum += num
print(totsum)
| n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
if i % 3 == 0 or i % 5 == 0:
pass
else:
ans += i
print(ans)
| false | 12.5 | [
"-totsum = 0",
"-for num in range(1, n + 1):",
"- if num % 3 != 0 and num % 5 != 0:",
"- totsum += num",
"-print(totsum)",
"+ans = 0",
"+for i in range(1, n + 1):",
"+ if i % 3 == 0 or i % 5 == 0:",
"+ pass",
"+ else:",
"+ ans += i",
"+print(ans)"
] | false | 0.11844 | 0.255504 | 0.463553 | [
"s258445408",
"s768326191"
] |
u193264896 | p02814 | python | s978914008 | s185515563 | 772 | 245 | 27,232 | 39,688 | Accepted | Accepted | 68.26 | from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
return (a * b) // gcd(a, b)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def main():
n, m = list(map(int, readline().split()))
a = np.array(input().split(), np.int64)
a //= 2
b=np.copy(a)
while True:
c = b%2
if c.sum() == 0:
b //= 2
elif c.sum() == n:
break
else:
print((0))
sys.exit()
d = lcm_list(a)
if d>10**9:
ans = 0
else:
ans = (m//d) - (m//(d+d))
print(ans)
if __name__ == '__main__':
main() | import sys
from math import gcd
from functools import reduce
import numpy as np
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def lcm_base(a, b):
return (a * b) // gcd(a, b)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def main():
n, m = list(map(int, readline().split()))
a = np.array(input().split(), np.int64)
a //= 2
b = np.copy(a)
while True:
c = b % 2
if c.sum() == 0:
b //= 2
elif c.sum() == n:
break
else:
print((0))
sys.exit()
d = lcm_list(a)
if d > 10 ** 9:
ans = 0
else:
ans = (m // d) - (m // (d + d))
print(ans)
if __name__ == '__main__':
main()
| 50 | 44 | 1,281 | 846 | from scipy.sparse.csgraph import (
shortest_path,
floyd_warshall,
dijkstra,
bellman_ford,
johnson,
minimum_spanning_tree,
)
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from collections import deque, Counter, defaultdict
from itertools import product, permutations, combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi, factorial
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7
def lcm_base(a, b):
return (a * b) // gcd(a, b)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def main():
n, m = list(map(int, readline().split()))
a = np.array(input().split(), np.int64)
a //= 2
b = np.copy(a)
while True:
c = b % 2
if c.sum() == 0:
b //= 2
elif c.sum() == n:
break
else:
print((0))
sys.exit()
d = lcm_list(a)
if d > 10**9:
ans = 0
else:
ans = (m // d) - (m // (d + d))
print(ans)
if __name__ == "__main__":
main()
| import sys
from math import gcd
from functools import reduce
import numpy as np
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7
def lcm_base(a, b):
return (a * b) // gcd(a, b)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def main():
n, m = list(map(int, readline().split()))
a = np.array(input().split(), np.int64)
a //= 2
b = np.copy(a)
while True:
c = b % 2
if c.sum() == 0:
b //= 2
elif c.sum() == n:
break
else:
print((0))
sys.exit()
d = lcm_list(a)
if d > 10**9:
ans = 0
else:
ans = (m // d) - (m // (d + d))
print(ans)
if __name__ == "__main__":
main()
| false | 12 | [
"-from scipy.sparse.csgraph import (",
"- shortest_path,",
"- floyd_warshall,",
"- dijkstra,",
"- bellman_ford,",
"- johnson,",
"- minimum_spanning_tree,",
"-)",
"-from scipy.sparse import csr_matrix, coo_matrix, lil_matrix",
"+import sys",
"+from math import gcd",
"+from functools import reduce",
"-from collections import deque, Counter, defaultdict",
"-from itertools import product, permutations, combinations",
"-from operator import itemgetter",
"-from heapq import heappop, heappush",
"-from bisect import bisect_left, bisect_right, bisect",
"-from fractions import gcd",
"-from math import ceil, floor, sqrt, cos, sin, pi, factorial",
"-from functools import reduce",
"-import sys",
"-read = sys.stdin.buffer.read",
"+read = sys.stdin.read",
"-readlines = sys.stdin.buffer.readlines"
] | false | 0.226891 | 0.274772 | 0.825745 | [
"s978914008",
"s185515563"
] |
u589381719 | p03161 | python | s424240069 | s242331973 | 444 | 340 | 52,448 | 52,448 | Accepted | Accepted | 23.42 | # 貰うDP
N,K=list(map(int,input().split()))
h=list(map(int,input().split()))
INF=10**9
dp=[INF]*(N)
dp[0]=0
for n in range(1,N):
dp[n]=min([dp[k] + abs(h[n] - h[k]) for k in range(max(0,n-K), n)])
print((dp[N-1])) | # 配るDP
N,K=list(map(int,input().split()))
H=list(map(int,input().split()))
INF=10**9
add_list=[INF]*K
H.extend(add_list)
dp=[INF]*(N+100) #Kの分追加
dp[0]=0
for n in range(N):
for k in range(n+1,n+K+1):
dp[k]=min(dp[k], dp[n]+abs(H[n]-H[k]))
print((dp[N-1])) | 10 | 14 | 217 | 273 | # 貰うDP
N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * (N)
dp[0] = 0
for n in range(1, N):
dp[n] = min([dp[k] + abs(h[n] - h[k]) for k in range(max(0, n - K), n)])
print((dp[N - 1]))
| # 配るDP
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
INF = 10**9
add_list = [INF] * K
H.extend(add_list)
dp = [INF] * (N + 100) # Kの分追加
dp[0] = 0
for n in range(N):
for k in range(n + 1, n + K + 1):
dp[k] = min(dp[k], dp[n] + abs(H[n] - H[k]))
print((dp[N - 1]))
| false | 28.571429 | [
"-# 貰うDP",
"+# 配るDP",
"-h = list(map(int, input().split()))",
"+H = list(map(int, input().split()))",
"-dp = [INF] * (N)",
"+add_list = [INF] * K",
"+H.extend(add_list)",
"+dp = [INF] * (N + 100) # Kの分追加",
"-for n in range(1, N):",
"- dp[n] = min([dp[k] + abs(h[n] - h[k]) for k in range(max(0, n - K), n)])",
"+for n in range(N):",
"+ for k in range(n + 1, n + K + 1):",
"+ dp[k] = min(dp[k], dp[n] + abs(H[n] - H[k]))"
] | false | 0.065984 | 0.117927 | 0.559532 | [
"s424240069",
"s242331973"
] |
u075012704 | p02586 | python | s895762014 | s690228172 | 1,208 | 1,001 | 433,756 | 357,588 | Accepted | Accepted | 17.14 | def main():
import sys
my_input = sys.stdin.readline
H, W, K = list(map(int, my_input().split()))
V = [[0] * W for _ in range(H)]
for i in range(K):
h, w, v = list(map(int, my_input().split()))
h, w = h - 1, w - 1
V[h][w] = v
# dp1 ~ 4[h][w][x] := h行w列にいて、h行からn個アイテムを拾っている時の価値の総和の最大値
dp0 = [[0] * (W + 1) for _ in range(H + 1)]
dp1 = [[0] * (W + 1) for _ in range(H + 1)]
dp2 = [[0] * (W + 1) for _ in range(H + 1)]
dp3 = [[0] * (W + 1) for _ in range(H + 1)]
for h in range(1, H + 1):
for w in range(1, W + 1):
dp1[h][w] = max(
dp1[h][w],
dp3[h - 1][w] + V[h - 1][w - 1],
dp1[h][w - 1],
dp0[h][w - 1] + V[h - 1][w - 1]
)
dp2[h][w] = max(
dp2[h][w],
dp3[h - 1][w] + V[h - 1][w - 1],
dp2[h][w - 1],
dp1[h][w - 1] + V[h - 1][w - 1]
)
dp3[h][w] = max(
dp3[h][w],
dp3[h - 1][w] + V[h - 1][w - 1],
dp3[h][w - 1],
dp2[h][w - 1] + V[h - 1][w - 1]
)
print((dp3[-1][-1]))
if __name__ == "__main__":
main()
| def main():
import sys
my_input = sys.stdin.readline
H, W, K = list(map(int, my_input().split()))
V = [[0] * W for _ in range(H)]
for i in range(K):
h, w, v = list(map(int, my_input().split()))
h, w = h - 1, w - 1
V[h][w] = v
# dp1 ~ 4[h][w][x] := h行w列にいて、h行からn個アイテムを拾っている時の価値の総和の最大値
dp1 = [[0] * (W + 1) for _ in range(H + 1)]
dp2 = [[0] * (W + 1) for _ in range(H + 1)]
dp3 = [[0] * (W + 1) for _ in range(H + 1)]
for h in range(1, H + 1):
for w in range(1, W + 1):
dp1[h][w] = max(
dp1[h][w],
dp3[h - 1][w] + V[h - 1][w - 1],
dp1[h][w - 1]
)
dp2[h][w] = max(
dp2[h][w],
dp3[h - 1][w] + V[h - 1][w - 1],
dp2[h][w - 1],
dp1[h][w - 1] + V[h - 1][w - 1]
)
dp3[h][w] = max(
dp3[h][w],
dp3[h - 1][w] + V[h - 1][w - 1],
dp3[h][w - 1],
dp2[h][w - 1] + V[h - 1][w - 1]
)
print((dp3[-1][-1]))
if __name__ == "__main__":
main()
| 44 | 42 | 1,281 | 1,182 | def main():
import sys
my_input = sys.stdin.readline
H, W, K = list(map(int, my_input().split()))
V = [[0] * W for _ in range(H)]
for i in range(K):
h, w, v = list(map(int, my_input().split()))
h, w = h - 1, w - 1
V[h][w] = v
# dp1 ~ 4[h][w][x] := h行w列にいて、h行からn個アイテムを拾っている時の価値の総和の最大値
dp0 = [[0] * (W + 1) for _ in range(H + 1)]
dp1 = [[0] * (W + 1) for _ in range(H + 1)]
dp2 = [[0] * (W + 1) for _ in range(H + 1)]
dp3 = [[0] * (W + 1) for _ in range(H + 1)]
for h in range(1, H + 1):
for w in range(1, W + 1):
dp1[h][w] = max(
dp1[h][w],
dp3[h - 1][w] + V[h - 1][w - 1],
dp1[h][w - 1],
dp0[h][w - 1] + V[h - 1][w - 1],
)
dp2[h][w] = max(
dp2[h][w],
dp3[h - 1][w] + V[h - 1][w - 1],
dp2[h][w - 1],
dp1[h][w - 1] + V[h - 1][w - 1],
)
dp3[h][w] = max(
dp3[h][w],
dp3[h - 1][w] + V[h - 1][w - 1],
dp3[h][w - 1],
dp2[h][w - 1] + V[h - 1][w - 1],
)
print((dp3[-1][-1]))
if __name__ == "__main__":
main()
| def main():
import sys
my_input = sys.stdin.readline
H, W, K = list(map(int, my_input().split()))
V = [[0] * W for _ in range(H)]
for i in range(K):
h, w, v = list(map(int, my_input().split()))
h, w = h - 1, w - 1
V[h][w] = v
# dp1 ~ 4[h][w][x] := h行w列にいて、h行からn個アイテムを拾っている時の価値の総和の最大値
dp1 = [[0] * (W + 1) for _ in range(H + 1)]
dp2 = [[0] * (W + 1) for _ in range(H + 1)]
dp3 = [[0] * (W + 1) for _ in range(H + 1)]
for h in range(1, H + 1):
for w in range(1, W + 1):
dp1[h][w] = max(dp1[h][w], dp3[h - 1][w] + V[h - 1][w - 1], dp1[h][w - 1])
dp2[h][w] = max(
dp2[h][w],
dp3[h - 1][w] + V[h - 1][w - 1],
dp2[h][w - 1],
dp1[h][w - 1] + V[h - 1][w - 1],
)
dp3[h][w] = max(
dp3[h][w],
dp3[h - 1][w] + V[h - 1][w - 1],
dp3[h][w - 1],
dp2[h][w - 1] + V[h - 1][w - 1],
)
print((dp3[-1][-1]))
if __name__ == "__main__":
main()
| false | 4.545455 | [
"- dp0 = [[0] * (W + 1) for _ in range(H + 1)]",
"- dp1[h][w] = max(",
"- dp1[h][w],",
"- dp3[h - 1][w] + V[h - 1][w - 1],",
"- dp1[h][w - 1],",
"- dp0[h][w - 1] + V[h - 1][w - 1],",
"- )",
"+ dp1[h][w] = max(dp1[h][w], dp3[h - 1][w] + V[h - 1][w - 1], dp1[h][w - 1])"
] | false | 0.036447 | 0.038165 | 0.954996 | [
"s895762014",
"s690228172"
] |
u188827677 | p02983 | python | s055764395 | s932129934 | 773 | 45 | 2,940 | 3,060 | Accepted | Accepted | 94.18 | l,r = list(map(int, input().split()))
if r - l >= 2018:
print((0))
else:
ans = 2019
for i in range(l, r):
for j in range(i + 1, r + 1):
ans = min(ans, i * j % 2019)
print(ans) | l,r = list(map(int, input().split()))
ans = 2019
for i in range(l, r):
for j in range(i+1, r+1):
t = i*j%2019
if ans > t:
ans = t
if ans == 0:
print(ans)
exit()
print(ans) | 9 | 12 | 193 | 209 | l, r = list(map(int, input().split()))
if r - l >= 2018:
print((0))
else:
ans = 2019
for i in range(l, r):
for j in range(i + 1, r + 1):
ans = min(ans, i * j % 2019)
print(ans)
| l, r = list(map(int, input().split()))
ans = 2019
for i in range(l, r):
for j in range(i + 1, r + 1):
t = i * j % 2019
if ans > t:
ans = t
if ans == 0:
print(ans)
exit()
print(ans)
| false | 25 | [
"-if r - l >= 2018:",
"- print((0))",
"-else:",
"- ans = 2019",
"- for i in range(l, r):",
"- for j in range(i + 1, r + 1):",
"- ans = min(ans, i * j % 2019)",
"- print(ans)",
"+ans = 2019",
"+for i in range(l, r):",
"+ for j in range(i + 1, r + 1):",
"+ t = i * j % 2019",
"+ if ans > t:",
"+ ans = t",
"+ if ans == 0:",
"+ print(ans)",
"+ exit()",
"+print(ans)"
] | false | 0.067371 | 0.038282 | 1.759884 | [
"s055764395",
"s932129934"
] |
u120810144 | p03425 | python | s474877969 | s903131242 | 163 | 150 | 10,520 | 10,520 | Accepted | Accepted | 7.98 | n = int(eval(input()))
s = [eval(input()) for i in range(n)]
order = "MARCH"
nums = [[name[0] for name in s].count(order[i]) for i in range(len(order))]
ans = 0
for i in range(0, 5):
for j in range(i+1, 5):
for k in range(j+1, 5):
ans += nums[i] * nums[j] * nums[k]
print(ans)
| n = int(eval(input()))
s = [eval(input()) for i in range(n)]
order = "MARCH"
initial_array = [name[0] for name in s]
nums = [initial_array.count(order[i]) for i in range(len(order))]
ans = 0
for i in range(0, 5):
for j in range(i+1, 5):
for k in range(j+1, 5):
ans += nums[i] * nums[j] * nums[k]
print(ans)
| 16 | 17 | 322 | 353 | n = int(eval(input()))
s = [eval(input()) for i in range(n)]
order = "MARCH"
nums = [[name[0] for name in s].count(order[i]) for i in range(len(order))]
ans = 0
for i in range(0, 5):
for j in range(i + 1, 5):
for k in range(j + 1, 5):
ans += nums[i] * nums[j] * nums[k]
print(ans)
| n = int(eval(input()))
s = [eval(input()) for i in range(n)]
order = "MARCH"
initial_array = [name[0] for name in s]
nums = [initial_array.count(order[i]) for i in range(len(order))]
ans = 0
for i in range(0, 5):
for j in range(i + 1, 5):
for k in range(j + 1, 5):
ans += nums[i] * nums[j] * nums[k]
print(ans)
| false | 5.882353 | [
"-nums = [[name[0] for name in s].count(order[i]) for i in range(len(order))]",
"+initial_array = [name[0] for name in s]",
"+nums = [initial_array.count(order[i]) for i in range(len(order))]"
] | false | 0.048744 | 0.040589 | 1.200924 | [
"s474877969",
"s903131242"
] |
u539281377 | p02784 | python | s747695385 | s051772472 | 78 | 41 | 13,964 | 13,916 | Accepted | Accepted | 47.44 | H,N=list(map(int,input().split()))
A=sorted((list(map(int,input().split()))))
A=A[::-1]
print(("Yes" if sum(A[0:N])>=H else "No")) | H,N,*A=list(map(int,open(0).read().split()))
print(("Yes" if sum(A)>=H else "No")) | 4 | 2 | 125 | 75 | H, N = list(map(int, input().split()))
A = sorted((list(map(int, input().split()))))
A = A[::-1]
print(("Yes" if sum(A[0:N]) >= H else "No"))
| H, N, *A = list(map(int, open(0).read().split()))
print(("Yes" if sum(A) >= H else "No"))
| false | 50 | [
"-H, N = list(map(int, input().split()))",
"-A = sorted((list(map(int, input().split()))))",
"-A = A[::-1]",
"-print((\"Yes\" if sum(A[0:N]) >= H else \"No\"))",
"+H, N, *A = list(map(int, open(0).read().split()))",
"+print((\"Yes\" if sum(A) >= H else \"No\"))"
] | false | 0.042061 | 0.042999 | 0.978165 | [
"s747695385",
"s051772472"
] |
u332906195 | p02583 | python | s612782048 | s056844504 | 144 | 87 | 9,188 | 9,168 | Accepted | Accepted | 39.58 | N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(N):
for j in range(i + 1, N):
for k in range(j + 1, N):
if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j] \
and L[i] != L[j] and L[j] != L[k] and L[k] != L[i]:
ans += 1
print(ans)
| N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
for j in range(i + 1, N):
for k in range(j + 1, N):
if L[i] + L[j] > L[k] and L[i] != L[j] and L[j] != L[k]:
ans += 1
print(ans)
| 11 | 9 | 345 | 265 | N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(N):
for j in range(i + 1, N):
for k in range(j + 1, N):
if (
L[i] + L[j] > L[k]
and L[j] + L[k] > L[i]
and L[k] + L[i] > L[j]
and L[i] != L[j]
and L[j] != L[k]
and L[k] != L[i]
):
ans += 1
print(ans)
| N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
for j in range(i + 1, N):
for k in range(j + 1, N):
if L[i] + L[j] > L[k] and L[i] != L[j] and L[j] != L[k]:
ans += 1
print(ans)
| false | 18.181818 | [
"-N = int(input())",
"-L = list(map(int, input().split()))",
"+N = int(eval(input()))",
"+L = sorted(list(map(int, input().split())))",
"- if (",
"- L[i] + L[j] > L[k]",
"- and L[j] + L[k] > L[i]",
"- and L[k] + L[i] > L[j]",
"- and L[i] != L[j]",
"- and L[j] != L[k]",
"- and L[k] != L[i]",
"- ):",
"+ if L[i] + L[j] > L[k] and L[i] != L[j] and L[j] != L[k]:"
] | false | 0.106208 | 0.085092 | 1.248156 | [
"s612782048",
"s056844504"
] |
u652057333 | p02695 | python | s690245351 | s503905852 | 249 | 182 | 9,232 | 70,644 | Accepted | Accepted | 26.91 | from itertools import combinations
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(20000000)
n, m, q = list(map(int, input().split()))
abcd = []
for i in range(q):
a, b, c, d = list(map(int, input().split()))
abcd.append([a-1, b-1, c, d])
# def check(Q):
# A = [1] + [-1 for _ in range(n-1)]
# score = 0
# for a, b, c, d in Q:
# if A[a] == -1 and A[b] == -1:
# tmp_b = min(A[b:])
# if tmp_b == -1 or tmp_b >= max(A[:a]) + c:
# A[a] = max(A[:a])
# A[b] = A[a] + c
# score += d
# elif A[a] == -1 and A[b] != -1:
# if max(A[:a]) <= A[b] - c <= max(A[:a]):
# A[a] = A[b] - c
# score += d
# elif A[a] != -1 and A[b] == -1:
# if min(A[:b]) <= A[a] + c <= max(A[b:]):
# A[b] = A[a] + c
# score += d
# else:
# if A[b] - A[a] == c:
# score += d
# print(A)
# return score
def dfs(A, depth, max_a):
if depth == n:
score = 0
for a, b, c, d in abcd:
if A[b] - A[a] == c:
score += d
return score
ans = 0
for i in range(max_a, m+1):
ans = max(ans, dfs(A + [i], depth+1, i))
return ans
ans = dfs([1], 1, 1)
print(ans)
| from itertools import combinations
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(20000000)
n, m, q = list(map(int, input().split()))
abcd = []
for i in range(q):
a, b, c, d = list(map(int, input().split()))
abcd.append([a-1, b-1, c, d])
def dfs(A, depth, max_a):
if depth == n:
score = 0
for a, b, c, d in abcd:
if A[b] - A[a] == c:
score += d
return score
ans = 0
for i in range(max_a, m+1):
ans = max(ans, dfs(A + [i], depth+1, i))
return ans
ans = dfs([1], 1, 1)
print(ans)
| 50 | 26 | 1,403 | 611 | from itertools import combinations
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(20000000)
n, m, q = list(map(int, input().split()))
abcd = []
for i in range(q):
a, b, c, d = list(map(int, input().split()))
abcd.append([a - 1, b - 1, c, d])
# def check(Q):
# A = [1] + [-1 for _ in range(n-1)]
# score = 0
# for a, b, c, d in Q:
# if A[a] == -1 and A[b] == -1:
# tmp_b = min(A[b:])
# if tmp_b == -1 or tmp_b >= max(A[:a]) + c:
# A[a] = max(A[:a])
# A[b] = A[a] + c
# score += d
# elif A[a] == -1 and A[b] != -1:
# if max(A[:a]) <= A[b] - c <= max(A[:a]):
# A[a] = A[b] - c
# score += d
# elif A[a] != -1 and A[b] == -1:
# if min(A[:b]) <= A[a] + c <= max(A[b:]):
# A[b] = A[a] + c
# score += d
# else:
# if A[b] - A[a] == c:
# score += d
# print(A)
# return score
def dfs(A, depth, max_a):
if depth == n:
score = 0
for a, b, c, d in abcd:
if A[b] - A[a] == c:
score += d
return score
ans = 0
for i in range(max_a, m + 1):
ans = max(ans, dfs(A + [i], depth + 1, i))
return ans
ans = dfs([1], 1, 1)
print(ans)
| from itertools import combinations
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(20000000)
n, m, q = list(map(int, input().split()))
abcd = []
for i in range(q):
a, b, c, d = list(map(int, input().split()))
abcd.append([a - 1, b - 1, c, d])
def dfs(A, depth, max_a):
if depth == n:
score = 0
for a, b, c, d in abcd:
if A[b] - A[a] == c:
score += d
return score
ans = 0
for i in range(max_a, m + 1):
ans = max(ans, dfs(A + [i], depth + 1, i))
return ans
ans = dfs([1], 1, 1)
print(ans)
| false | 48 | [
"-# def check(Q):",
"-# A = [1] + [-1 for _ in range(n-1)]",
"-# score = 0",
"-# for a, b, c, d in Q:",
"-# if A[a] == -1 and A[b] == -1:",
"-# tmp_b = min(A[b:])",
"-# if tmp_b == -1 or tmp_b >= max(A[:a]) + c:",
"-# A[a] = max(A[:a])",
"-# A[b] = A[a] + c",
"-# score += d",
"-# elif A[a] == -1 and A[b] != -1:",
"-# if max(A[:a]) <= A[b] - c <= max(A[:a]):",
"-# A[a] = A[b] - c",
"-# score += d",
"-# elif A[a] != -1 and A[b] == -1:",
"-# if min(A[:b]) <= A[a] + c <= max(A[b:]):",
"-# A[b] = A[a] + c",
"-# score += d",
"-# else:",
"-# if A[b] - A[a] == c:",
"-# score += d",
"-# print(A)",
"-# return score",
"+",
"+"
] | false | 0.103857 | 0.043432 | 2.39125 | [
"s690245351",
"s503905852"
] |
u086503932 | p02936 | python | s024888778 | s237565209 | 1,841 | 1,669 | 230,960 | 56,156 | Accepted | Accepted | 9.34 | import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6)
def DFS(v, parent):
global v_count
for u in adj[v]:
if u != parent:
v_count[u] += v_count[v]
DFS(u,v)
N, Q = list(map(int, input().split()))
adj = [[] for _ in range(N)]
v_count = [0] * N
for i in range(N-1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
adj[a].append(b)
adj[b].append(a)# aがbの親とは限らないため
for j in range(Q):
p, x = list(map(int, input().split()))
v_count[p-1] += x
# 0起点に親ノードの数字を子ノードに足していく
DFS(0, -1)# 現在のノード, 親ノード
print((*v_count))
| from collections import deque
N, Q = list(map(int, input().split()))
adj = [[] for _ in range(N)]
count = [0] * N
for _ in range(N-1):
a,b = list(map(int, input().split()))
adj[a-1].append(b-1)
adj[b-1].append(a-1)
for _ in range(Q):
p,x = list(map(int, input().split()))
count[p-1] += x
queue = deque([0])
visit = [True] * N
visit[0] = False
while queue:
now = queue.popleft()
for u in adj[now]:
if visit[u]:
count[u] += count[now]
queue.append(u)
visit[u] = False
print((*count)) | 30 | 27 | 588 | 530 | import sys
input = sys.stdin.readline # for input speed
sys.setrecursionlimit(10**6)
def DFS(v, parent):
global v_count
for u in adj[v]:
if u != parent:
v_count[u] += v_count[v]
DFS(u, v)
N, Q = list(map(int, input().split()))
adj = [[] for _ in range(N)]
v_count = [0] * N
for i in range(N - 1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
adj[a].append(b)
adj[b].append(a) # aがbの親とは限らないため
for j in range(Q):
p, x = list(map(int, input().split()))
v_count[p - 1] += x
# 0起点に親ノードの数字を子ノードに足していく
DFS(0, -1) # 現在のノード, 親ノード
print((*v_count))
| from collections import deque
N, Q = list(map(int, input().split()))
adj = [[] for _ in range(N)]
count = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
adj[a - 1].append(b - 1)
adj[b - 1].append(a - 1)
for _ in range(Q):
p, x = list(map(int, input().split()))
count[p - 1] += x
queue = deque([0])
visit = [True] * N
visit[0] = False
while queue:
now = queue.popleft()
for u in adj[now]:
if visit[u]:
count[u] += count[now]
queue.append(u)
visit[u] = False
print((*count))
| false | 10 | [
"-import sys",
"-",
"-input = sys.stdin.readline # for input speed",
"-sys.setrecursionlimit(10**6)",
"-",
"-",
"-def DFS(v, parent):",
"- global v_count",
"- for u in adj[v]:",
"- if u != parent:",
"- v_count[u] += v_count[v]",
"- DFS(u, v)",
"-",
"+from collections import deque",
"-v_count = [0] * N",
"-for i in range(N - 1):",
"+count = [0] * N",
"+for _ in range(N - 1):",
"- a -= 1",
"- b -= 1",
"- adj[a].append(b)",
"- adj[b].append(a) # aがbの親とは限らないため",
"-for j in range(Q):",
"+ adj[a - 1].append(b - 1)",
"+ adj[b - 1].append(a - 1)",
"+for _ in range(Q):",
"- v_count[p - 1] += x",
"-# 0起点に親ノードの数字を子ノードに足していく",
"-DFS(0, -1) # 現在のノード, 親ノード",
"-print((*v_count))",
"+ count[p - 1] += x",
"+queue = deque([0])",
"+visit = [True] * N",
"+visit[0] = False",
"+while queue:",
"+ now = queue.popleft()",
"+ for u in adj[now]:",
"+ if visit[u]:",
"+ count[u] += count[now]",
"+ queue.append(u)",
"+ visit[u] = False",
"+print((*count))"
] | false | 0.039789 | 0.038666 | 1.029052 | [
"s024888778",
"s237565209"
] |
u690037900 | p03574 | python | s493411911 | s050148833 | 218 | 30 | 14,472 | 3,064 | Accepted | Accepted | 86.24 | import numpy as np
h,w=list(map(int,input().split()))
L=[[i for i in eval(input())] for i in range(h)]
L_first=np.zeros((2,w),dtype=str)
L_first2=np.zeros((1,1),dtype=str)
L=np.array(L,dtype=str)
L=np.insert(L_first,1,L,axis=0)
L=np.insert(L,0,L_first2,axis=1)
L=np.insert(L,w+1,L_first2,axis=1)
ans=np.zeros((h,w),dtype=str)
for i in range(1,h+1):
for j in range(1,w+1):
num = 0
if L[i][j]==".":
L2=L[i-1:i+2,j-1:j+2]
ans[i-1][j-1]=np.sum(L2=="#")
else:ans[i-1][j-1]="#"
for i in range(h):
print(("".join(ans[i]))) | H, W = list(map(int, input().split()))
src = [list(eval(input())) for i in range(H)]
ans=src
dxy = [(-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1)]
for y in range(H):
for x in range(W):
if src[y][x] == '#': continue
c = 0
for dx, dy in dxy:
if x + dx < 0 or x + dx > W - 1 or y + dy < 0 or y + dy > H - 1: continue
if src[y + dy][x + dx] == '#': c += 1
ans[y][x] = c
for row in ans:
print((''.join(list(map(str, row))))) | 19 | 16 | 575 | 509 | import numpy as np
h, w = list(map(int, input().split()))
L = [[i for i in eval(input())] for i in range(h)]
L_first = np.zeros((2, w), dtype=str)
L_first2 = np.zeros((1, 1), dtype=str)
L = np.array(L, dtype=str)
L = np.insert(L_first, 1, L, axis=0)
L = np.insert(L, 0, L_first2, axis=1)
L = np.insert(L, w + 1, L_first2, axis=1)
ans = np.zeros((h, w), dtype=str)
for i in range(1, h + 1):
for j in range(1, w + 1):
num = 0
if L[i][j] == ".":
L2 = L[i - 1 : i + 2, j - 1 : j + 2]
ans[i - 1][j - 1] = np.sum(L2 == "#")
else:
ans[i - 1][j - 1] = "#"
for i in range(h):
print(("".join(ans[i])))
| H, W = list(map(int, input().split()))
src = [list(eval(input())) for i in range(H)]
ans = src
dxy = [(-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1)]
for y in range(H):
for x in range(W):
if src[y][x] == "#":
continue
c = 0
for dx, dy in dxy:
if x + dx < 0 or x + dx > W - 1 or y + dy < 0 or y + dy > H - 1:
continue
if src[y + dy][x + dx] == "#":
c += 1
ans[y][x] = c
for row in ans:
print(("".join(list(map(str, row)))))
| false | 15.789474 | [
"-import numpy as np",
"-",
"-h, w = list(map(int, input().split()))",
"-L = [[i for i in eval(input())] for i in range(h)]",
"-L_first = np.zeros((2, w), dtype=str)",
"-L_first2 = np.zeros((1, 1), dtype=str)",
"-L = np.array(L, dtype=str)",
"-L = np.insert(L_first, 1, L, axis=0)",
"-L = np.insert(L, 0, L_first2, axis=1)",
"-L = np.insert(L, w + 1, L_first2, axis=1)",
"-ans = np.zeros((h, w), dtype=str)",
"-for i in range(1, h + 1):",
"- for j in range(1, w + 1):",
"- num = 0",
"- if L[i][j] == \".\":",
"- L2 = L[i - 1 : i + 2, j - 1 : j + 2]",
"- ans[i - 1][j - 1] = np.sum(L2 == \"#\")",
"- else:",
"- ans[i - 1][j - 1] = \"#\"",
"-for i in range(h):",
"- print((\"\".join(ans[i])))",
"+H, W = list(map(int, input().split()))",
"+src = [list(eval(input())) for i in range(H)]",
"+ans = src",
"+dxy = [(-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1)]",
"+for y in range(H):",
"+ for x in range(W):",
"+ if src[y][x] == \"#\":",
"+ continue",
"+ c = 0",
"+ for dx, dy in dxy:",
"+ if x + dx < 0 or x + dx > W - 1 or y + dy < 0 or y + dy > H - 1:",
"+ continue",
"+ if src[y + dy][x + dx] == \"#\":",
"+ c += 1",
"+ ans[y][x] = c",
"+for row in ans:",
"+ print((\"\".join(list(map(str, row)))))"
] | false | 0.319639 | 0.043596 | 7.331796 | [
"s493411911",
"s050148833"
] |
u969850098 | p03103 | python | s372741312 | s507594379 | 1,767 | 337 | 24,444 | 27,756 | Accepted | Accepted | 80.93 | import sys
n_shops, n_drinks = list(map(int, input().split()))
shop_info = sorted([tuple(map(int, line.split())) for line in sys.stdin.readlines()])
cost = 0
purchased_n_drinks = 0
for _ in range(len(shop_info)):
info = shop_info.pop(0)
if (purchased_n_drinks + info[1]) >= n_drinks:
cost += ( n_drinks - purchased_n_drinks) * info[0]
break
purchased_n_drinks += info[1]
cost += info[0] * info[1]
print(cost) | import sys
readline = sys.stdin.readline
def main():
N, M = list(map(int, readline().rstrip().split()))
AB = [list(map(int, readline().rstrip().split())) for _ in range(N)]
AB.sort()
pro = 0
cost = 0
for a, b in AB:
if pro + b >= M:
cost += (M - pro) * a
break
pro += b
cost += a * b
print(cost)
if __name__ == '__main__':
main() | 13 | 21 | 446 | 431 | import sys
n_shops, n_drinks = list(map(int, input().split()))
shop_info = sorted([tuple(map(int, line.split())) for line in sys.stdin.readlines()])
cost = 0
purchased_n_drinks = 0
for _ in range(len(shop_info)):
info = shop_info.pop(0)
if (purchased_n_drinks + info[1]) >= n_drinks:
cost += (n_drinks - purchased_n_drinks) * info[0]
break
purchased_n_drinks += info[1]
cost += info[0] * info[1]
print(cost)
| import sys
readline = sys.stdin.readline
def main():
N, M = list(map(int, readline().rstrip().split()))
AB = [list(map(int, readline().rstrip().split())) for _ in range(N)]
AB.sort()
pro = 0
cost = 0
for a, b in AB:
if pro + b >= M:
cost += (M - pro) * a
break
pro += b
cost += a * b
print(cost)
if __name__ == "__main__":
main()
| false | 38.095238 | [
"-n_shops, n_drinks = list(map(int, input().split()))",
"-shop_info = sorted([tuple(map(int, line.split())) for line in sys.stdin.readlines()])",
"-cost = 0",
"-purchased_n_drinks = 0",
"-for _ in range(len(shop_info)):",
"- info = shop_info.pop(0)",
"- if (purchased_n_drinks + info[1]) >= n_drinks:",
"- cost += (n_drinks - purchased_n_drinks) * info[0]",
"- break",
"- purchased_n_drinks += info[1]",
"- cost += info[0] * info[1]",
"-print(cost)",
"+readline = sys.stdin.readline",
"+",
"+",
"+def main():",
"+ N, M = list(map(int, readline().rstrip().split()))",
"+ AB = [list(map(int, readline().rstrip().split())) for _ in range(N)]",
"+ AB.sort()",
"+ pro = 0",
"+ cost = 0",
"+ for a, b in AB:",
"+ if pro + b >= M:",
"+ cost += (M - pro) * a",
"+ break",
"+ pro += b",
"+ cost += a * b",
"+ print(cost)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.035301 | 0.035684 | 0.989266 | [
"s372741312",
"s507594379"
] |
u353919145 | p03160 | python | s469975455 | s899819365 | 145 | 133 | 13,928 | 21,032 | Accepted | Accepted | 8.28 | n = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("inf") for i in range(n)]
dp[0] = 0
dp[1] = dp[0] + (h[1] - h[0])
for i in range(1, n):
dp[i] = min(dp[i - 2] + (abs(h[i] - h[i - 2])), dp[i - 1] + (abs(h[i] - h[i - 1])))
print((dp[n - 1])) | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
sys.setrecursionlimit(1000000)
# do magic here
n = int(eval(input()))
heights = [int(x) for x in input().split()]
dp = [0 for x in range(n+1)]
dp[1] = abs(heights[1]-heights[0])
for x in range(2, n):
a = abs(heights[x]-heights[x-1]) + dp[x-1]
b = abs(heights[x]-heights[x-2]) + dp[x-2]
dp[x] = min(a, b)
print((dp[n-1]))
| 8 | 18 | 264 | 422 | n = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("inf") for i in range(n)]
dp[0] = 0
dp[1] = dp[0] + (h[1] - h[0])
for i in range(1, n):
dp[i] = min(dp[i - 2] + (abs(h[i] - h[i - 2])), dp[i - 1] + (abs(h[i] - h[i - 1])))
print((dp[n - 1]))
| import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
sys.setrecursionlimit(1000000)
# do magic here
n = int(eval(input()))
heights = [int(x) for x in input().split()]
dp = [0 for x in range(n + 1)]
dp[1] = abs(heights[1] - heights[0])
for x in range(2, n):
a = abs(heights[x] - heights[x - 1]) + dp[x - 1]
b = abs(heights[x] - heights[x - 2]) + dp[x - 2]
dp[x] = min(a, b)
print((dp[n - 1]))
| false | 55.555556 | [
"+import sys",
"+",
"+reader = (s.rstrip() for s in sys.stdin)",
"+input = reader.__next__",
"+sys.setrecursionlimit(1000000)",
"+# do magic here",
"-h = list(map(int, input().split()))",
"-dp = [float(\"inf\") for i in range(n)]",
"-dp[0] = 0",
"-dp[1] = dp[0] + (h[1] - h[0])",
"-for i in range(1, n):",
"- dp[i] = min(dp[i - 2] + (abs(h[i] - h[i - 2])), dp[i - 1] + (abs(h[i] - h[i - 1])))",
"+heights = [int(x) for x in input().split()]",
"+dp = [0 for x in range(n + 1)]",
"+dp[1] = abs(heights[1] - heights[0])",
"+for x in range(2, n):",
"+ a = abs(heights[x] - heights[x - 1]) + dp[x - 1]",
"+ b = abs(heights[x] - heights[x - 2]) + dp[x - 2]",
"+ dp[x] = min(a, b)"
] | false | 0.06976 | 0.046718 | 1.493227 | [
"s469975455",
"s899819365"
] |
u991567869 | p03814 | python | s853997748 | s534491723 | 36 | 18 | 3,516 | 3,512 | Accepted | Accepted | 50 | s = eval(input())
for i in range(len(s)):
if s[i] == "A":
start = i
break
for i in range(len(s))[::-1]:
if s[i] == "Z":
end = i
break
ans = end - start + 1
print(ans) | s = eval(input())
ans = len(s[s.find("A"): s.rfind("Z")]) + 1
print(ans) | 14 | 3 | 216 | 68 | s = eval(input())
for i in range(len(s)):
if s[i] == "A":
start = i
break
for i in range(len(s))[::-1]:
if s[i] == "Z":
end = i
break
ans = end - start + 1
print(ans)
| s = eval(input())
ans = len(s[s.find("A") : s.rfind("Z")]) + 1
print(ans)
| false | 78.571429 | [
"-for i in range(len(s)):",
"- if s[i] == \"A\":",
"- start = i",
"- break",
"-for i in range(len(s))[::-1]:",
"- if s[i] == \"Z\":",
"- end = i",
"- break",
"-ans = end - start + 1",
"+ans = len(s[s.find(\"A\") : s.rfind(\"Z\")]) + 1"
] | false | 0.082249 | 0.088227 | 0.932238 | [
"s853997748",
"s534491723"
] |
u811733736 | p00030 | python | s064211294 | s457601956 | 50 | 40 | 7,884 | 7,888 | Accepted | Accepted | 20 | from collections import deque
class Bt(object):
def __init__(self):
self.used = [False] * 10 # 0-9????????°???????????¨?????????????????????????????°
self.answers = [] # ?????¶???????????????????????????
self.Q = deque() # ????????§???????????¢??????????????°???????¨???¶??¨
def solve(self, num, remain):
# ????´¢??????????°??????§?????????????????????????????§????????????????????§????????°??????????????????????????????
try:
min_choice = max(self.Q) + 1
except ValueError:
min_choice = 0
if min_choice <= remain < 10 and self.used[remain] == False and num == 1:
#self.Q.append(remain)
#print('{0}'.format(self.Q))
#ans = [*self.Q]
#ans.sort()
#if not ans in self.answers:
# self.answers.append(ans)
#self.Q.pop()
self.answers.append(1)
return
elif num < 0:
return
for i in range(min_choice, 10):
if self.used[i] == False and (remain - i) >= 0:
self.used[i] = True
self.Q.append(i)
self.solve(num - 1, remain - i)
self.used[i] = False
self.Q.pop()
if __name__ == '__main__':
while True:
# ??????????????\???
n, s = [int(x) for x in input().split(' ')]
if n == 0 and s == 0:
break
if 0 <= s <= 45:
# ????????????
a = Bt()
a.solve(n, s)
# ???????????¨???
print((len(a.answers)))
else:
print((0)) | from collections import deque
class Bt(object):
def __init__(self):
self.used = [False] * 10 # 0-9????????°???????????¨?????????????????????????????°
self.answers = [] # ?????¶???????????????????????????
self.Q = deque() # ????????§???????????¢??????????????°???????¨???¶??¨
def solve(self, num, remain):
# ????´¢??????????°??????§?????????????????????????????§????????????????????§????????°??????????????????????????????
try:
min_choice = max(self.Q) + 1
except ValueError:
min_choice = 0
if min_choice <= remain < 10 and self.used[remain] == False and num == 1:
self.Q.append(remain)
# print('{0}'.format(self.Q))
#ans = [*self.Q]
ans = []
for i in self.Q:
ans.append(i)
ans.sort()
if not ans in self.answers:
self.answers.append(ans)
self.Q.pop()
# self.answers.append(1)
return
elif num < 0:
return
for i in range(min_choice, 10):
if self.used[i] == False and (remain - i) >= 0:
self.used[i] = True
self.Q.append(i)
self.solve(num - 1, remain - i)
self.used[i] = False
self.Q.pop()
if __name__ == '__main__':
while True:
# ??????????????\???
n, s = [int(x) for x in input().split(' ')]
if n == 0 and s == 0:
break
if 0 <= s <= 45:
# ????????????
a = Bt()
a.solve(n, s)
# ???????????¨???
print((len(a.answers)))
else:
print((0)) | 54 | 57 | 1,702 | 1,783 | from collections import deque
class Bt(object):
def __init__(self):
self.used = [
False
] * 10 # 0-9????????°???????????¨?????????????????????????????°
self.answers = [] # ?????¶???????????????????????????
self.Q = deque() # ????????§???????????¢??????????????°???????¨???¶??¨
def solve(self, num, remain):
# ????´¢??????????°??????§?????????????????????????????§????????????????????§????????°??????????????????????????????
try:
min_choice = max(self.Q) + 1
except ValueError:
min_choice = 0
if min_choice <= remain < 10 and self.used[remain] == False and num == 1:
# self.Q.append(remain)
# print('{0}'.format(self.Q))
# ans = [*self.Q]
# ans.sort()
# if not ans in self.answers:
# self.answers.append(ans)
# self.Q.pop()
self.answers.append(1)
return
elif num < 0:
return
for i in range(min_choice, 10):
if self.used[i] == False and (remain - i) >= 0:
self.used[i] = True
self.Q.append(i)
self.solve(num - 1, remain - i)
self.used[i] = False
self.Q.pop()
if __name__ == "__main__":
while True:
# ??????????????\???
n, s = [int(x) for x in input().split(" ")]
if n == 0 and s == 0:
break
if 0 <= s <= 45:
# ????????????
a = Bt()
a.solve(n, s)
# ???????????¨???
print((len(a.answers)))
else:
print((0))
| from collections import deque
class Bt(object):
def __init__(self):
self.used = [
False
] * 10 # 0-9????????°???????????¨?????????????????????????????°
self.answers = [] # ?????¶???????????????????????????
self.Q = deque() # ????????§???????????¢??????????????°???????¨???¶??¨
def solve(self, num, remain):
# ????´¢??????????°??????§?????????????????????????????§????????????????????§????????°??????????????????????????????
try:
min_choice = max(self.Q) + 1
except ValueError:
min_choice = 0
if min_choice <= remain < 10 and self.used[remain] == False and num == 1:
self.Q.append(remain)
# print('{0}'.format(self.Q))
# ans = [*self.Q]
ans = []
for i in self.Q:
ans.append(i)
ans.sort()
if not ans in self.answers:
self.answers.append(ans)
self.Q.pop()
# self.answers.append(1)
return
elif num < 0:
return
for i in range(min_choice, 10):
if self.used[i] == False and (remain - i) >= 0:
self.used[i] = True
self.Q.append(i)
self.solve(num - 1, remain - i)
self.used[i] = False
self.Q.pop()
if __name__ == "__main__":
while True:
# ??????????????\???
n, s = [int(x) for x in input().split(" ")]
if n == 0 and s == 0:
break
if 0 <= s <= 45:
# ????????????
a = Bt()
a.solve(n, s)
# ???????????¨???
print((len(a.answers)))
else:
print((0))
| false | 5.263158 | [
"- # self.Q.append(remain)",
"+ self.Q.append(remain)",
"- # ans.sort()",
"- # if not ans in self.answers:",
"- # self.answers.append(ans)",
"- # self.Q.pop()",
"- self.answers.append(1)",
"+ ans = []",
"+ for i in self.Q:",
"+ ans.append(i)",
"+ ans.sort()",
"+ if not ans in self.answers:",
"+ self.answers.append(ans)",
"+ self.Q.pop()",
"+ # self.answers.append(1)"
] | false | 0.046201 | 0.067297 | 0.686517 | [
"s064211294",
"s457601956"
] |
u919633157 | p03854 | python | s269412183 | s657833154 | 76 | 27 | 3,188 | 11,636 | Accepted | Accepted | 64.47 | s=input()[::-1]
ans='YES'
while len(s)>0:
if s[:5] in ['dream'[::-1],'erase'[::-1]]:
s=s[5:]
elif s[:6] in ['eraser'[::-1]]:
s=s[6:]
elif s[:7] in ['dreamer'[::-1]]:
s=s[7:]
else:
ans='NO'
break
print(ans) | import re
s=eval(input())
pat=r'^(dream(er)?|erase(r)?)*$'
a=re.match(pat,s)
print(('YES' if a else 'NO')) | 13 | 5 | 273 | 102 | s = input()[::-1]
ans = "YES"
while len(s) > 0:
if s[:5] in ["dream"[::-1], "erase"[::-1]]:
s = s[5:]
elif s[:6] in ["eraser"[::-1]]:
s = s[6:]
elif s[:7] in ["dreamer"[::-1]]:
s = s[7:]
else:
ans = "NO"
break
print(ans)
| import re
s = eval(input())
pat = r"^(dream(er)?|erase(r)?)*$"
a = re.match(pat, s)
print(("YES" if a else "NO"))
| false | 61.538462 | [
"-s = input()[::-1]",
"-ans = \"YES\"",
"-while len(s) > 0:",
"- if s[:5] in [\"dream\"[::-1], \"erase\"[::-1]]:",
"- s = s[5:]",
"- elif s[:6] in [\"eraser\"[::-1]]:",
"- s = s[6:]",
"- elif s[:7] in [\"dreamer\"[::-1]]:",
"- s = s[7:]",
"- else:",
"- ans = \"NO\"",
"- break",
"-print(ans)",
"+import re",
"+",
"+s = eval(input())",
"+pat = r\"^(dream(er)?|erase(r)?)*$\"",
"+a = re.match(pat, s)",
"+print((\"YES\" if a else \"NO\"))"
] | false | 0.043745 | 0.048829 | 0.895881 | [
"s269412183",
"s657833154"
] |
u200887663 | p02773 | python | s325833164 | s413336316 | 770 | 711 | 32,096 | 32,096 | Accepted | Accepted | 7.66 | n=int(eval(input()))
dic={}
for i in range(n):
s=eval(input())
count=dic.get(s,0)
count+=1
dic[s]=count
mx=1
for v in list(dic.values()):
mx=max(v,mx)
ans=[]
for k,v in list(dic.items()):
if v==mx:
ans.append(k)
ans.sort()
#print("---")
for st in ans:
print(st)
| n=int(eval(input()))
#n,m=map(int,input().split())
#hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
dic={}
for i in range(n):
s=eval(input())
dic[s]=dic.get(s,0)+1
mx=max(dic.values())
ansl=[]
for k, v in list(dic.items()):
if v==mx:
ansl.append(k)
ansl.sort()
for st in ansl:
print(st) | 21 | 21 | 297 | 357 | n = int(eval(input()))
dic = {}
for i in range(n):
s = eval(input())
count = dic.get(s, 0)
count += 1
dic[s] = count
mx = 1
for v in list(dic.values()):
mx = max(v, mx)
ans = []
for k, v in list(dic.items()):
if v == mx:
ans.append(k)
ans.sort()
# print("---")
for st in ans:
print(st)
| n = int(eval(input()))
# n,m=map(int,input().split())
# hl=list(map(int,input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
dic = {}
for i in range(n):
s = eval(input())
dic[s] = dic.get(s, 0) + 1
mx = max(dic.values())
ansl = []
for k, v in list(dic.items()):
if v == mx:
ansl.append(k)
ansl.sort()
for st in ansl:
print(st)
| false | 0 | [
"+# n,m=map(int,input().split())",
"+# hl=list(map(int,input().split()))",
"+# l=[list(map(int,input().split())) for i in range(n)]",
"- count = dic.get(s, 0)",
"- count += 1",
"- dic[s] = count",
"-mx = 1",
"-for v in list(dic.values()):",
"- mx = max(v, mx)",
"-ans = []",
"+ dic[s] = dic.get(s, 0) + 1",
"+mx = max(dic.values())",
"+ansl = []",
"- ans.append(k)",
"-ans.sort()",
"-for st in ans:",
"+ ansl.append(k)",
"+ansl.sort()",
"+for st in ansl:"
] | false | 0.160504 | 0.105583 | 1.520176 | [
"s325833164",
"s413336316"
] |
u619819312 | p03845 | python | s239396441 | s862276674 | 21 | 18 | 3,060 | 3,060 | Accepted | Accepted | 14.29 | s=int(eval(input()))
a=list(map(int,input().split()))
b=int(eval(input()))
s=[]
for i in range(b):
c,d=list(map(int,input().split()))
s.append(sum(a[:c-1])+sum(a[c:])+d)
print((s[i])) | s=int(eval(input()))
a=list(map(int,input().split()))
b=int(eval(input()))
for i in range(b):
c,d=list(map(int,input().split()))
print((sum(a[:c-1])+sum(a[c:])+d)) | 8 | 6 | 185 | 159 | s = int(eval(input()))
a = list(map(int, input().split()))
b = int(eval(input()))
s = []
for i in range(b):
c, d = list(map(int, input().split()))
s.append(sum(a[: c - 1]) + sum(a[c:]) + d)
print((s[i]))
| s = int(eval(input()))
a = list(map(int, input().split()))
b = int(eval(input()))
for i in range(b):
c, d = list(map(int, input().split()))
print((sum(a[: c - 1]) + sum(a[c:]) + d))
| false | 25 | [
"-s = []",
"- s.append(sum(a[: c - 1]) + sum(a[c:]) + d)",
"- print((s[i]))",
"+ print((sum(a[: c - 1]) + sum(a[c:]) + d))"
] | false | 0.073303 | 0.106966 | 0.685292 | [
"s239396441",
"s862276674"
] |
u673361376 | p03575 | python | s633134428 | s384488625 | 182 | 21 | 39,536 | 3,316 | Accepted | Accepted | 88.46 | def findunit(edges, N):
roots = [i for i in range(N)]
for edge in edges:
if roots[edge[0]] == roots[edge[1]]:continue
prv_root = roots[edge[1]]
for idx, root in enumerate(roots):
if root == prv_root:
roots[idx] = roots[edge[0]]
return roots
N,M=list(map(int,input().split()))
edges = [ [int(a) -1 for a in input().split()] for _ in range(M)]
ans = 0
for i in range(M):
if len(set(findunit(edges[:i] + edges[i+1:], N))) != 1:ans += 1
print(ans) | from collections import deque
def is_all_nodes_connected():
q = deque()
used = set()
q.append(1)
used.add(1)
while len(q) > 0:
prv_node = q.pop()
for node in g[prv_node]:
if node in used:
continue
else:
q.append(node)
used.add(node)
if len(used) == N:
return True
else:
return False
N, M = list(map(int, input().split()))
g = {i: [] for i in range(1, N+1)}
AB = []
for _ in range(M):
a, b = list(map(int, input().split()))
g[a].append(b)
g[b].append(a)
AB.append([a, b])
ans = 0
for a, b in AB:
g[a].remove(b)
g[b].remove(a)
if is_all_nodes_connected() is False:
ans += 1
g[a].append(b)
g[b].append(a)
print(ans)
| 16 | 41 | 487 | 823 | def findunit(edges, N):
roots = [i for i in range(N)]
for edge in edges:
if roots[edge[0]] == roots[edge[1]]:
continue
prv_root = roots[edge[1]]
for idx, root in enumerate(roots):
if root == prv_root:
roots[idx] = roots[edge[0]]
return roots
N, M = list(map(int, input().split()))
edges = [[int(a) - 1 for a in input().split()] for _ in range(M)]
ans = 0
for i in range(M):
if len(set(findunit(edges[:i] + edges[i + 1 :], N))) != 1:
ans += 1
print(ans)
| from collections import deque
def is_all_nodes_connected():
q = deque()
used = set()
q.append(1)
used.add(1)
while len(q) > 0:
prv_node = q.pop()
for node in g[prv_node]:
if node in used:
continue
else:
q.append(node)
used.add(node)
if len(used) == N:
return True
else:
return False
N, M = list(map(int, input().split()))
g = {i: [] for i in range(1, N + 1)}
AB = []
for _ in range(M):
a, b = list(map(int, input().split()))
g[a].append(b)
g[b].append(a)
AB.append([a, b])
ans = 0
for a, b in AB:
g[a].remove(b)
g[b].remove(a)
if is_all_nodes_connected() is False:
ans += 1
g[a].append(b)
g[b].append(a)
print(ans)
| false | 60.97561 | [
"-def findunit(edges, N):",
"- roots = [i for i in range(N)]",
"- for edge in edges:",
"- if roots[edge[0]] == roots[edge[1]]:",
"- continue",
"- prv_root = roots[edge[1]]",
"- for idx, root in enumerate(roots):",
"- if root == prv_root:",
"- roots[idx] = roots[edge[0]]",
"- return roots",
"+from collections import deque",
"+",
"+",
"+def is_all_nodes_connected():",
"+ q = deque()",
"+ used = set()",
"+ q.append(1)",
"+ used.add(1)",
"+ while len(q) > 0:",
"+ prv_node = q.pop()",
"+ for node in g[prv_node]:",
"+ if node in used:",
"+ continue",
"+ else:",
"+ q.append(node)",
"+ used.add(node)",
"+ if len(used) == N:",
"+ return True",
"+ else:",
"+ return False",
"-edges = [[int(a) - 1 for a in input().split()] for _ in range(M)]",
"+g = {i: [] for i in range(1, N + 1)}",
"+AB = []",
"+for _ in range(M):",
"+ a, b = list(map(int, input().split()))",
"+ g[a].append(b)",
"+ g[b].append(a)",
"+ AB.append([a, b])",
"-for i in range(M):",
"- if len(set(findunit(edges[:i] + edges[i + 1 :], N))) != 1:",
"+for a, b in AB:",
"+ g[a].remove(b)",
"+ g[b].remove(a)",
"+ if is_all_nodes_connected() is False:",
"+ g[a].append(b)",
"+ g[b].append(a)"
] | false | 0.046401 | 0.147012 | 0.315627 | [
"s633134428",
"s384488625"
] |
u815878613 | p03452 | python | s499581008 | s726872069 | 1,025 | 907 | 62,136 | 63,036 | Accepted | Accepted | 11.51 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
class WeightedUnionFind:
def __init__(self, N):
self.par = [i for i in range(N)]
self.rank = [0] * N
self.weight = [0] * N # 親までの距離
def find(self, x):
if self.par[x] == x:
return x
else:
r = self.find(self.par[x])
self.weight[x] += self.weight[self.par[x]]
self.par[x] = r
return r
def union(self, x, y, w):
rx = self.find(x)
ry = self.find(y)
if self.rank[rx] < self.rank[ry]:
self.par[rx] = ry
self.weight[rx] = w - self.weight[x] + self.weight[y]
else:
self.par[ry] = rx
self.weight[ry] = -w - self.weight[y] + self.weight[x]
if self.rank[rx] == self.rank[ry]:
self.rank[rx] += 1
def diff_w(self, x, y):
return self.weight[x] - self.weight[y]
def main():
N, M = list(map(int, readline().split()))
m = list(map(int, read().split()))
LRD = list(zip(m, m, m))
D = WeightedUnionFind(N)
for l, r, d in LRD:
l -= 1
r -= 1
D.union(l, r, d)
for l, r, d in LRD:
l -= 1
r -= 1
D.find(l)
D.find(r)
if d != D.diff_w(l, r):
print('No')
sys.exit()
print('Yes')
main()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
class WeightedUnionFind:
def __init__(self, N):
self.par = [i for i in range(N)]
self.rank = [0] * N
self.weight = [0] * N # 親までの距離
def find(self, x):
if self.par[x] == x:
return x
else:
r = self.find(self.par[x])
self.weight[x] += self.weight[self.par[x]]
self.par[x] = r
return r
def union(self, x, y, w):
rx = self.find(x)
ry = self.find(y)
if self.rank[rx] < self.rank[ry]:
self.par[rx] = ry
self.weight[rx] = w - self.weight[x] + self.weight[y]
else:
self.par[ry] = rx
self.weight[ry] = -w - self.weight[y] + self.weight[x]
if self.rank[rx] == self.rank[ry]:
self.rank[rx] += 1
def diff_w(self, x, y):
return self.weight[x] - self.weight[y]
def main():
N, M = list(map(int, readline().split()))
m = list(map(int, read().split()))
LRD = list(zip(m, m, m))
D = WeightedUnionFind(N)
a = []
for l, r, d in LRD:
l -= 1
r -= 1
D.union(l, r, d)
a.append(l)
a.append(r)
for i in set(a):
D.find(i)
for l, r, d in LRD:
l -= 1
r -= 1
if d != D.diff_w(l, r):
print('No')
sys.exit()
print('Yes')
main()
| 62 | 66 | 1,446 | 1,505 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
class WeightedUnionFind:
def __init__(self, N):
self.par = [i for i in range(N)]
self.rank = [0] * N
self.weight = [0] * N # 親までの距離
def find(self, x):
if self.par[x] == x:
return x
else:
r = self.find(self.par[x])
self.weight[x] += self.weight[self.par[x]]
self.par[x] = r
return r
def union(self, x, y, w):
rx = self.find(x)
ry = self.find(y)
if self.rank[rx] < self.rank[ry]:
self.par[rx] = ry
self.weight[rx] = w - self.weight[x] + self.weight[y]
else:
self.par[ry] = rx
self.weight[ry] = -w - self.weight[y] + self.weight[x]
if self.rank[rx] == self.rank[ry]:
self.rank[rx] += 1
def diff_w(self, x, y):
return self.weight[x] - self.weight[y]
def main():
N, M = list(map(int, readline().split()))
m = list(map(int, read().split()))
LRD = list(zip(m, m, m))
D = WeightedUnionFind(N)
for l, r, d in LRD:
l -= 1
r -= 1
D.union(l, r, d)
for l, r, d in LRD:
l -= 1
r -= 1
D.find(l)
D.find(r)
if d != D.diff_w(l, r):
print("No")
sys.exit()
print("Yes")
main()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
class WeightedUnionFind:
def __init__(self, N):
self.par = [i for i in range(N)]
self.rank = [0] * N
self.weight = [0] * N # 親までの距離
def find(self, x):
if self.par[x] == x:
return x
else:
r = self.find(self.par[x])
self.weight[x] += self.weight[self.par[x]]
self.par[x] = r
return r
def union(self, x, y, w):
rx = self.find(x)
ry = self.find(y)
if self.rank[rx] < self.rank[ry]:
self.par[rx] = ry
self.weight[rx] = w - self.weight[x] + self.weight[y]
else:
self.par[ry] = rx
self.weight[ry] = -w - self.weight[y] + self.weight[x]
if self.rank[rx] == self.rank[ry]:
self.rank[rx] += 1
def diff_w(self, x, y):
return self.weight[x] - self.weight[y]
def main():
N, M = list(map(int, readline().split()))
m = list(map(int, read().split()))
LRD = list(zip(m, m, m))
D = WeightedUnionFind(N)
a = []
for l, r, d in LRD:
l -= 1
r -= 1
D.union(l, r, d)
a.append(l)
a.append(r)
for i in set(a):
D.find(i)
for l, r, d in LRD:
l -= 1
r -= 1
if d != D.diff_w(l, r):
print("No")
sys.exit()
print("Yes")
main()
| false | 6.060606 | [
"+ a = []",
"+ a.append(l)",
"+ a.append(r)",
"+ for i in set(a):",
"+ D.find(i)",
"- D.find(l)",
"- D.find(r)"
] | false | 0.046326 | 0.046346 | 0.999574 | [
"s499581008",
"s726872069"
] |
u256464928 | p02845 | python | s958277263 | s703690109 | 108 | 78 | 20,952 | 14,020 | Accepted | Accepted | 27.78 | def main():
from collections import defaultdict
N = int(eval(input()))
A = list(map(int,input().split()))
MOD = 1000000007
c = defaultdict(int)
c[0] = 3
ans = 1
for i in range(N):
if not c[A[i]]:
print((0))
exit()
ans *= c[A[i]]
ans %= MOD
c[A[i]] -= 1
c[A[i]+1] += 1
print(ans)
main()
| def main():
N = int(eval(input()))
A = list(map(int,input().split()))
MOD = 1000000007
c = [0] * (N+1)
c[0] = 3
ans = 1
for i in range(N):
if not c[A[i]]:
print((0))
exit()
ans *= c[A[i]]
ans %= MOD
c[A[i]] -= 1
c[A[i]+1] += 1
print(ans)
main()
| 19 | 18 | 359 | 315 | def main():
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 1000000007
c = defaultdict(int)
c[0] = 3
ans = 1
for i in range(N):
if not c[A[i]]:
print((0))
exit()
ans *= c[A[i]]
ans %= MOD
c[A[i]] -= 1
c[A[i] + 1] += 1
print(ans)
main()
| def main():
N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 1000000007
c = [0] * (N + 1)
c[0] = 3
ans = 1
for i in range(N):
if not c[A[i]]:
print((0))
exit()
ans *= c[A[i]]
ans %= MOD
c[A[i]] -= 1
c[A[i] + 1] += 1
print(ans)
main()
| false | 5.263158 | [
"- from collections import defaultdict",
"-",
"- c = defaultdict(int)",
"+ c = [0] * (N + 1)"
] | false | 0.035809 | 0.035622 | 1.005254 | [
"s958277263",
"s703690109"
] |
u906501980 | p03161 | python | s432251256 | s980139152 | 1,500 | 364 | 13,908 | 52,448 | Accepted | Accepted | 75.73 | def main():
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [None]*n
dp[0], dp[1] = 0, abs(h[0]-h[1])
for i, hi in enumerate(h[2:], 2):
di = 10**9
m = max(0, i-k)
for dj, hj in zip(dp[m:i], h[m:i]):
hh = hj-hi
if hh>0:
d = dj + hh
else:
d = dj - hh
if di > d:
di = d
dp[i] = di
print((dp[-1]))
if __name__ == "__main__":
main() | n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [10**9+1]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
for j in range(1, min(i+1, k+1)):
dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]))
print((dp[n-1]))
| 21 | 10 | 528 | 260 | def main():
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [None] * n
dp[0], dp[1] = 0, abs(h[0] - h[1])
for i, hi in enumerate(h[2:], 2):
di = 10**9
m = max(0, i - k)
for dj, hj in zip(dp[m:i], h[m:i]):
hh = hj - hi
if hh > 0:
d = dj + hh
else:
d = dj - hh
if di > d:
di = d
dp[i] = di
print((dp[-1]))
if __name__ == "__main__":
main()
| n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [10**9 + 1] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
for j in range(1, min(i + 1, k + 1)):
dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print((dp[n - 1]))
| false | 52.380952 | [
"-def main():",
"- n, k = list(map(int, input().split()))",
"- h = list(map(int, input().split()))",
"- dp = [None] * n",
"- dp[0], dp[1] = 0, abs(h[0] - h[1])",
"- for i, hi in enumerate(h[2:], 2):",
"- di = 10**9",
"- m = max(0, i - k)",
"- for dj, hj in zip(dp[m:i], h[m:i]):",
"- hh = hj - hi",
"- if hh > 0:",
"- d = dj + hh",
"- else:",
"- d = dj - hh",
"- if di > d:",
"- di = d",
"- dp[i] = di",
"- print((dp[-1]))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+n, k = list(map(int, input().split()))",
"+h = list(map(int, input().split()))",
"+dp = [10**9 + 1] * n",
"+dp[0] = 0",
"+dp[1] = abs(h[1] - h[0])",
"+for i in range(2, n):",
"+ for j in range(1, min(i + 1, k + 1)):",
"+ dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))",
"+print((dp[n - 1]))"
] | false | 0.099387 | 0.042164 | 2.357184 | [
"s432251256",
"s980139152"
] |
u843175622 | p02596 | python | s430867984 | s831382655 | 545 | 68 | 16,696 | 63,280 | Accepted | Accepted | 87.52 | k = int(eval(input()))
now = 7
cnt = 1
used = [False] * k
ten = 10
while not used[now % k]:
if now % k == 0:
print(cnt)
exit()
used[now % k] = True
now = (now + ten * 7) % k
ten = ten * 10 % k
cnt += 1
print((-1))
| k = int(eval(input()))
n = 7
for i in range(k):
if n % k == 0:
print((i + 1))
exit()
n = (n * 10 + 7) % k
print((-1))
| 15 | 8 | 257 | 139 | k = int(eval(input()))
now = 7
cnt = 1
used = [False] * k
ten = 10
while not used[now % k]:
if now % k == 0:
print(cnt)
exit()
used[now % k] = True
now = (now + ten * 7) % k
ten = ten * 10 % k
cnt += 1
print((-1))
| k = int(eval(input()))
n = 7
for i in range(k):
if n % k == 0:
print((i + 1))
exit()
n = (n * 10 + 7) % k
print((-1))
| false | 46.666667 | [
"-now = 7",
"-cnt = 1",
"-used = [False] * k",
"-ten = 10",
"-while not used[now % k]:",
"- if now % k == 0:",
"- print(cnt)",
"+n = 7",
"+for i in range(k):",
"+ if n % k == 0:",
"+ print((i + 1))",
"- used[now % k] = True",
"- now = (now + ten * 7) % k",
"- ten = ten * 10 % k",
"- cnt += 1",
"+ n = (n * 10 + 7) % k"
] | false | 0.143259 | 0.09642 | 1.485785 | [
"s430867984",
"s831382655"
] |
u250583425 | p02720 | python | s163950852 | s088414564 | 99 | 68 | 10,792 | 10,816 | Accepted | Accepted | 31.31 | import sys
import heapq
def input(): return sys.stdin.readline().rstrip()
def main():
K = int(eval(input()))
q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(q)
while len(q) < K:
K -= len(q)
new_q = []
for i in q:
d1 = int(str(i)[-1])
if d1 > 0:
new_q.append(i * 10 + d1 - 1)
new_q.append(i * 10 + d1)
if d1 < 9:
new_q.append(i * 10 + d1 + 1)
q = new_q
heapq.heapify(q)
print((q[K-1]))
if __name__ == '__main__':
main()
| import sys
import heapq
def input(): return sys.stdin.readline().rstrip()
def main():
K = int(eval(input()))
q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(q)
while len(q) < K:
K -= len(q)
new_q = []
for i in q:
d1 = i % 10
if d1 > 0:
new_q.append(i * 10 + d1 - 1)
new_q.append(i * 10 + d1)
if d1 < 9:
new_q.append(i * 10 + d1 + 1)
q = new_q
heapq.heapify(q)
print((q[K-1]))
if __name__ == '__main__':
main()
| 24 | 24 | 578 | 569 | import sys
import heapq
def input():
return sys.stdin.readline().rstrip()
def main():
K = int(eval(input()))
q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(q)
while len(q) < K:
K -= len(q)
new_q = []
for i in q:
d1 = int(str(i)[-1])
if d1 > 0:
new_q.append(i * 10 + d1 - 1)
new_q.append(i * 10 + d1)
if d1 < 9:
new_q.append(i * 10 + d1 + 1)
q = new_q
heapq.heapify(q)
print((q[K - 1]))
if __name__ == "__main__":
main()
| import sys
import heapq
def input():
return sys.stdin.readline().rstrip()
def main():
K = int(eval(input()))
q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(q)
while len(q) < K:
K -= len(q)
new_q = []
for i in q:
d1 = i % 10
if d1 > 0:
new_q.append(i * 10 + d1 - 1)
new_q.append(i * 10 + d1)
if d1 < 9:
new_q.append(i * 10 + d1 + 1)
q = new_q
heapq.heapify(q)
print((q[K - 1]))
if __name__ == "__main__":
main()
| false | 0 | [
"- d1 = int(str(i)[-1])",
"+ d1 = i % 10"
] | false | 0.043908 | 0.078341 | 0.560474 | [
"s163950852",
"s088414564"
] |
u057109575 | p02714 | python | s766599560 | s801710736 | 1,402 | 146 | 69,080 | 68,052 | Accepted | Accepted | 89.59 | from bisect import bisect_right
N = int(eval(input()))
S = eval(input())
d = [[0] * N for _ in range(3)]
for i in range(3):
for j in range(N):
d[i][j] = int(S[j] == "RGB"[i])
cumsum = [[0] * (N + 1) for _ in range(3)]
for i in range(3):
for j in range(N):
cumsum[i][j + 1] = cumsum[i][j] + d[i][j]
cnt = [len(v) for v in d]
ans = 0
for i in range(1, N - 1):
for j in range(i + 1, N):
if S[i - 1] == S[j - 1]:
continue
# Find `k` string and index
s = (set("RGB") - set([S[i - 1], S[j - 1]])).pop()
idx = "RGB".find(s)
ans += cumsum[idx][-1] - cumsum[idx][j]
k = 2 * j - i
if k <= N and d[idx][k - 1]:
ans -= 1
print(ans)
| N = int(eval(input()))
S = eval(input())
d = {"R": 0, "G": 0, "B": 0}
for i in range(N):
d[S[i]] += 1
ans = d["R"] * d["G"] * d["B"]
cnt = 0
for i in range(1, N - 1):
for j in range(i + 1, N):
k = 2 * j - i
if k > N or S[i - 1] == S[j - 1]:
continue
if S[i - 1] != S[k - 1] and S[j - 1] != S[k - 1]:
cnt += 1
print((ans - cnt))
| 33 | 21 | 788 | 424 | from bisect import bisect_right
N = int(eval(input()))
S = eval(input())
d = [[0] * N for _ in range(3)]
for i in range(3):
for j in range(N):
d[i][j] = int(S[j] == "RGB"[i])
cumsum = [[0] * (N + 1) for _ in range(3)]
for i in range(3):
for j in range(N):
cumsum[i][j + 1] = cumsum[i][j] + d[i][j]
cnt = [len(v) for v in d]
ans = 0
for i in range(1, N - 1):
for j in range(i + 1, N):
if S[i - 1] == S[j - 1]:
continue
# Find `k` string and index
s = (set("RGB") - set([S[i - 1], S[j - 1]])).pop()
idx = "RGB".find(s)
ans += cumsum[idx][-1] - cumsum[idx][j]
k = 2 * j - i
if k <= N and d[idx][k - 1]:
ans -= 1
print(ans)
| N = int(eval(input()))
S = eval(input())
d = {"R": 0, "G": 0, "B": 0}
for i in range(N):
d[S[i]] += 1
ans = d["R"] * d["G"] * d["B"]
cnt = 0
for i in range(1, N - 1):
for j in range(i + 1, N):
k = 2 * j - i
if k > N or S[i - 1] == S[j - 1]:
continue
if S[i - 1] != S[k - 1] and S[j - 1] != S[k - 1]:
cnt += 1
print((ans - cnt))
| false | 36.363636 | [
"-from bisect import bisect_right",
"-",
"-d = [[0] * N for _ in range(3)]",
"-for i in range(3):",
"- for j in range(N):",
"- d[i][j] = int(S[j] == \"RGB\"[i])",
"-cumsum = [[0] * (N + 1) for _ in range(3)]",
"-for i in range(3):",
"- for j in range(N):",
"- cumsum[i][j + 1] = cumsum[i][j] + d[i][j]",
"-cnt = [len(v) for v in d]",
"-ans = 0",
"+d = {\"R\": 0, \"G\": 0, \"B\": 0}",
"+for i in range(N):",
"+ d[S[i]] += 1",
"+ans = d[\"R\"] * d[\"G\"] * d[\"B\"]",
"+cnt = 0",
"- if S[i - 1] == S[j - 1]:",
"+ k = 2 * j - i",
"+ if k > N or S[i - 1] == S[j - 1]:",
"- # Find `k` string and index",
"- s = (set(\"RGB\") - set([S[i - 1], S[j - 1]])).pop()",
"- idx = \"RGB\".find(s)",
"- ans += cumsum[idx][-1] - cumsum[idx][j]",
"- k = 2 * j - i",
"- if k <= N and d[idx][k - 1]:",
"- ans -= 1",
"-print(ans)",
"+ if S[i - 1] != S[k - 1] and S[j - 1] != S[k - 1]:",
"+ cnt += 1",
"+print((ans - cnt))"
] | false | 0.105318 | 0.039979 | 2.63432 | [
"s766599560",
"s801710736"
] |
u367701763 | p02550 | python | s600991992 | s395809412 | 84 | 75 | 75,052 | 77,860 | Accepted | Accepted | 10.71 | def cycle_getter(N, start):
"""
:param N: 移動回数
:param start: 初期条件
:return front: cycleまでの要素のリスト
cycle: cycle内の要素のリスト
end: cycle後の余った部分の要素のリスト
cnt: cycle回数
"""
p = start
front, cycle, end = [], [], []
cnt = 0
visit = {p:0}
L, R = N, -1
for i in range(1,N):
p = lift(p)
if p in visit:
"""
(L, R) = (サイクルに入るまでに移動した回数, サイクルの終端に着くまでに移動した回数)
[6,2,3,4,0,1,2] ⇒ (L, R) = (1, 6)
"""
L, R = visit[p], i
period = R-L
break
visit[p] = i
p = start
for _ in range(L):
front.append(p)
p = lift(p)
if L != N:
for _ in range(L,R):
cycle.append(p)
p = lift(p)
for _ in range(N-(N-L)%period,N):
end.append(p)
p = lift(p)
cnt = (N-L)//period
return front, cycle, end, cnt
def lift(x): return pow(x,2,M)
################################################################################
import sys
input = sys.stdin.readline
N, X, M = list(map(int, input().split()))
front, cycle, end, cnt = cycle_getter(N,X)
print((sum(front)+sum(cycle)*cnt+sum(end))) | def cycle_getter(N, start):
"""
:param N: 移動回数
:param start: 初期条件
:return front: cycleまでの要素のリスト
cycle: cycle内の要素のリスト
end: cycle後の余った部分の要素のリスト
cnt: cycle回数
"""
p = start
front, cycle, end = [], [], []
cnt = 0
visit = {p:0}
L, R = N, -1
P = [p]
for i in range(1,N):
p = lift(p)
if p in visit:
"""
(L, R) = (サイクルに入るまでに移動した回数, サイクルの終端に着くまでに移動した回数)
[6,2,3,4,0,1,2] ⇒ (L, R) = (1, 6)
"""
L, R = visit[p], i
period = R-L
break
visit[p] = i
P.append(p)
front = P[:L]
if L != N:
cycle, end = P[L:R], P[L:L+(N-L)%period]
cnt = (N-L)//period
return front, cycle, end, cnt
################################################################################
import sys
input = sys.stdin.readline
def lift(x): return pow(x,2,M)
N, X, M = list(map(int, input().split()))
front, cycle, end, cnt = cycle_getter(N,X)
# print(front, cycle, end, cnt)
print((sum(front)+sum(cycle)*cnt+sum(end))) | 48 | 45 | 1,264 | 1,140 | def cycle_getter(N, start):
"""
:param N: 移動回数
:param start: 初期条件
:return front: cycleまでの要素のリスト
cycle: cycle内の要素のリスト
end: cycle後の余った部分の要素のリスト
cnt: cycle回数
"""
p = start
front, cycle, end = [], [], []
cnt = 0
visit = {p: 0}
L, R = N, -1
for i in range(1, N):
p = lift(p)
if p in visit:
"""
(L, R) = (サイクルに入るまでに移動した回数, サイクルの終端に着くまでに移動した回数)
[6,2,3,4,0,1,2] ⇒ (L, R) = (1, 6)
"""
L, R = visit[p], i
period = R - L
break
visit[p] = i
p = start
for _ in range(L):
front.append(p)
p = lift(p)
if L != N:
for _ in range(L, R):
cycle.append(p)
p = lift(p)
for _ in range(N - (N - L) % period, N):
end.append(p)
p = lift(p)
cnt = (N - L) // period
return front, cycle, end, cnt
def lift(x):
return pow(x, 2, M)
################################################################################
import sys
input = sys.stdin.readline
N, X, M = list(map(int, input().split()))
front, cycle, end, cnt = cycle_getter(N, X)
print((sum(front) + sum(cycle) * cnt + sum(end)))
| def cycle_getter(N, start):
"""
:param N: 移動回数
:param start: 初期条件
:return front: cycleまでの要素のリスト
cycle: cycle内の要素のリスト
end: cycle後の余った部分の要素のリスト
cnt: cycle回数
"""
p = start
front, cycle, end = [], [], []
cnt = 0
visit = {p: 0}
L, R = N, -1
P = [p]
for i in range(1, N):
p = lift(p)
if p in visit:
"""
(L, R) = (サイクルに入るまでに移動した回数, サイクルの終端に着くまでに移動した回数)
[6,2,3,4,0,1,2] ⇒ (L, R) = (1, 6)
"""
L, R = visit[p], i
period = R - L
break
visit[p] = i
P.append(p)
front = P[:L]
if L != N:
cycle, end = P[L:R], P[L : L + (N - L) % period]
cnt = (N - L) // period
return front, cycle, end, cnt
################################################################################
import sys
input = sys.stdin.readline
def lift(x):
return pow(x, 2, M)
N, X, M = list(map(int, input().split()))
front, cycle, end, cnt = cycle_getter(N, X)
# print(front, cycle, end, cnt)
print((sum(front) + sum(cycle) * cnt + sum(end)))
| false | 6.25 | [
"+ P = [p]",
"- p = start",
"- for _ in range(L):",
"- front.append(p)",
"- p = lift(p)",
"+ P.append(p)",
"+ front = P[:L]",
"- for _ in range(L, R):",
"- cycle.append(p)",
"- p = lift(p)",
"- for _ in range(N - (N - L) % period, N):",
"- end.append(p)",
"- p = lift(p)",
"+ cycle, end = P[L:R], P[L : L + (N - L) % period]",
"+",
"+",
"+################################################################################",
"+import sys",
"+",
"+input = sys.stdin.readline",
"-################################################################################",
"-import sys",
"-",
"-input = sys.stdin.readline",
"+# print(front, cycle, end, cnt)"
] | false | 0.040291 | 0.038389 | 1.049553 | [
"s600991992",
"s395809412"
] |
u038021590 | p03162 | python | s856780664 | s888208034 | 693 | 269 | 76,120 | 91,100 | Accepted | Accepted | 61.18 | N = int(eval(input()))
A_B_C = []
for i in range(N):
A_B_C.append(tuple(map(int, input().split())))
DP = [[0]*3 for i in range(N)]
DP[0][0] = A_B_C[0][0]
DP[0][1] = A_B_C[0][1]
DP[0][2] = A_B_C[0][2]
for i in range(1, N):
for j in range(3):
j_a = (j + 1) % 3
j_b = (j + 2) % 3
DP[i][j] = max(DP[i-1][j_a], DP[i-1][j_b]) + A_B_C[i][j]
print((max(DP[N-1][0], DP[N-1][1], DP[N-1][2]))) | N = int(eval(input()))
F = [tuple(map(int, input().split())) for _ in range(N)]
DP = [0] * 3
for f in F:
D = [0] * 3
S = {0, 1, 2}
for i in range(3):
S.remove(i)
for s in S:
D[i] = max(D[i], f[i] + DP[s])
S.add(i)
DP = D
print((max(DP))) | 17 | 16 | 425 | 299 | N = int(eval(input()))
A_B_C = []
for i in range(N):
A_B_C.append(tuple(map(int, input().split())))
DP = [[0] * 3 for i in range(N)]
DP[0][0] = A_B_C[0][0]
DP[0][1] = A_B_C[0][1]
DP[0][2] = A_B_C[0][2]
for i in range(1, N):
for j in range(3):
j_a = (j + 1) % 3
j_b = (j + 2) % 3
DP[i][j] = max(DP[i - 1][j_a], DP[i - 1][j_b]) + A_B_C[i][j]
print((max(DP[N - 1][0], DP[N - 1][1], DP[N - 1][2])))
| N = int(eval(input()))
F = [tuple(map(int, input().split())) for _ in range(N)]
DP = [0] * 3
for f in F:
D = [0] * 3
S = {0, 1, 2}
for i in range(3):
S.remove(i)
for s in S:
D[i] = max(D[i], f[i] + DP[s])
S.add(i)
DP = D
print((max(DP)))
| false | 5.882353 | [
"-A_B_C = []",
"-for i in range(N):",
"- A_B_C.append(tuple(map(int, input().split())))",
"-DP = [[0] * 3 for i in range(N)]",
"-DP[0][0] = A_B_C[0][0]",
"-DP[0][1] = A_B_C[0][1]",
"-DP[0][2] = A_B_C[0][2]",
"-for i in range(1, N):",
"- for j in range(3):",
"- j_a = (j + 1) % 3",
"- j_b = (j + 2) % 3",
"- DP[i][j] = max(DP[i - 1][j_a], DP[i - 1][j_b]) + A_B_C[i][j]",
"-print((max(DP[N - 1][0], DP[N - 1][1], DP[N - 1][2])))",
"+F = [tuple(map(int, input().split())) for _ in range(N)]",
"+DP = [0] * 3",
"+for f in F:",
"+ D = [0] * 3",
"+ S = {0, 1, 2}",
"+ for i in range(3):",
"+ S.remove(i)",
"+ for s in S:",
"+ D[i] = max(D[i], f[i] + DP[s])",
"+ S.add(i)",
"+ DP = D",
"+print((max(DP)))"
] | false | 0.0352 | 0.036177 | 0.973007 | [
"s856780664",
"s888208034"
] |
u723711163 | p02924 | python | s812683795 | s278582382 | 1,461 | 29 | 38,384 | 8,932 | Accepted | Accepted | 98.02 | N = int(eval(input()))
S = sum(range(1,N))
print(S) | n = int(eval(input()))
n -= 1
print((n*(n+1)//2)) | 5 | 4 | 51 | 45 | N = int(eval(input()))
S = sum(range(1, N))
print(S)
| n = int(eval(input()))
n -= 1
print((n * (n + 1) // 2))
| false | 20 | [
"-N = int(eval(input()))",
"-S = sum(range(1, N))",
"-print(S)",
"+n = int(eval(input()))",
"+n -= 1",
"+print((n * (n + 1) // 2))"
] | false | 0.041475 | 0.035847 | 1.157012 | [
"s812683795",
"s278582382"
] |
u561231954 | p03168 | python | s881297082 | s831515383 | 796 | 336 | 274,696 | 82,808 | Accepted | Accepted | 57.79 | def main():
n=int(eval(input()))
p=[float(i) for i in input().split()]
dp=[[0]*(n+1) for i in range(n+1)]
dp[0][0]=1
for i in range(n):
dp[i+1][0]=dp[i][0]*(1-p[i])
for j in range(i+1):
dp[i+1][j+1]=dp[i][j]*p[i]+dp[i][j+1]*(1-p[i])
print((sum(dp[n][(n+1)//2:])))
if __name__=='__main__':
main() | def main():
import numpy as np
n=int(eval(input()))
p=np.array([float(i) for i in input().split()])
dp=np.zeros([n+1,n+1],dtype=np.float64)
dp[0][0]=1
for i in range(n):
tmp=np.roll(dp[i],1)
tmp[0]=0
dp[i+1]+=dp[i]*(1-p[i])+tmp*p[i]
print((sum(dp[n][(n+1)//2:])))
if __name__=='__main__':
main()
| 14 | 18 | 338 | 357 | def main():
n = int(eval(input()))
p = [float(i) for i in input().split()]
dp = [[0] * (n + 1) for i in range(n + 1)]
dp[0][0] = 1
for i in range(n):
dp[i + 1][0] = dp[i][0] * (1 - p[i])
for j in range(i + 1):
dp[i + 1][j + 1] = dp[i][j] * p[i] + dp[i][j + 1] * (1 - p[i])
print((sum(dp[n][(n + 1) // 2 :])))
if __name__ == "__main__":
main()
| def main():
import numpy as np
n = int(eval(input()))
p = np.array([float(i) for i in input().split()])
dp = np.zeros([n + 1, n + 1], dtype=np.float64)
dp[0][0] = 1
for i in range(n):
tmp = np.roll(dp[i], 1)
tmp[0] = 0
dp[i + 1] += dp[i] * (1 - p[i]) + tmp * p[i]
print((sum(dp[n][(n + 1) // 2 :])))
if __name__ == "__main__":
main()
| false | 22.222222 | [
"+ import numpy as np",
"+",
"- p = [float(i) for i in input().split()]",
"- dp = [[0] * (n + 1) for i in range(n + 1)]",
"+ p = np.array([float(i) for i in input().split()])",
"+ dp = np.zeros([n + 1, n + 1], dtype=np.float64)",
"- dp[i + 1][0] = dp[i][0] * (1 - p[i])",
"- for j in range(i + 1):",
"- dp[i + 1][j + 1] = dp[i][j] * p[i] + dp[i][j + 1] * (1 - p[i])",
"+ tmp = np.roll(dp[i], 1)",
"+ tmp[0] = 0",
"+ dp[i + 1] += dp[i] * (1 - p[i]) + tmp * p[i]"
] | false | 0.039083 | 0.266088 | 0.14688 | [
"s881297082",
"s831515383"
] |
u865741247 | p03006 | python | s788444186 | s172188389 | 1,203 | 309 | 3,064 | 45,460 | Accepted | Accepted | 74.31 | n = int(eval(input()))
points = [list(map(int, input().split(" "))) for _ in range(n)]
X = 0
Y = 1
ans = 10 ** 14
for i in range(n):
for j in range(n):
if i == j:
continue
x1, y1 = points[i]
x2, y2 = points[j]
p = x1 - x2
q = y1 - y2
cost = n
for point1 in points: # そのpointからcost0で遷移できる先があるかどうか
fromx, fromy = point1
for point2 in points:
tox, toy = point2
if fromx - tox == p and fromy - toy == q:
cost -= 1
break
if ans > cost:
ans = cost
if n == 1:
print((1))
else:
print(ans)
| n = int(eval(input()))
points = [list(map(int, input().split(" "))) for _ in range(n)]
X = 0
Y = 1
ans = 10 ** 14
if n == 1:
ans = 1
else:
for i in range(n):
for j in range(n):
if i == j:
continue
x1, y1 = points[i]
x2, y2 = points[j]
p = x1 - x2
q = y1 - y2
cost = n
for point1 in points: # そのpointからcost0で遷移できる先があるかどうか
fromx, fromy = point1
for point2 in points:
tox, toy = point2
if fromx - tox == p and fromy - toy == q:
cost -= 1
break
if ans > cost:
ans = cost
print(ans)
| 28 | 31 | 698 | 771 | n = int(eval(input()))
points = [list(map(int, input().split(" "))) for _ in range(n)]
X = 0
Y = 1
ans = 10**14
for i in range(n):
for j in range(n):
if i == j:
continue
x1, y1 = points[i]
x2, y2 = points[j]
p = x1 - x2
q = y1 - y2
cost = n
for point1 in points: # そのpointからcost0で遷移できる先があるかどうか
fromx, fromy = point1
for point2 in points:
tox, toy = point2
if fromx - tox == p and fromy - toy == q:
cost -= 1
break
if ans > cost:
ans = cost
if n == 1:
print((1))
else:
print(ans)
| n = int(eval(input()))
points = [list(map(int, input().split(" "))) for _ in range(n)]
X = 0
Y = 1
ans = 10**14
if n == 1:
ans = 1
else:
for i in range(n):
for j in range(n):
if i == j:
continue
x1, y1 = points[i]
x2, y2 = points[j]
p = x1 - x2
q = y1 - y2
cost = n
for point1 in points: # そのpointからcost0で遷移できる先があるかどうか
fromx, fromy = point1
for point2 in points:
tox, toy = point2
if fromx - tox == p and fromy - toy == q:
cost -= 1
break
if ans > cost:
ans = cost
print(ans)
| false | 9.677419 | [
"-for i in range(n):",
"- for j in range(n):",
"- if i == j:",
"- continue",
"- x1, y1 = points[i]",
"- x2, y2 = points[j]",
"- p = x1 - x2",
"- q = y1 - y2",
"- cost = n",
"- for point1 in points: # そのpointからcost0で遷移できる先があるかどうか",
"- fromx, fromy = point1",
"- for point2 in points:",
"- tox, toy = point2",
"- if fromx - tox == p and fromy - toy == q:",
"- cost -= 1",
"- break",
"- if ans > cost:",
"- ans = cost",
"- print((1))",
"+ ans = 1",
"- print(ans)",
"+ for i in range(n):",
"+ for j in range(n):",
"+ if i == j:",
"+ continue",
"+ x1, y1 = points[i]",
"+ x2, y2 = points[j]",
"+ p = x1 - x2",
"+ q = y1 - y2",
"+ cost = n",
"+ for point1 in points: # そのpointからcost0で遷移できる先があるかどうか",
"+ fromx, fromy = point1",
"+ for point2 in points:",
"+ tox, toy = point2",
"+ if fromx - tox == p and fromy - toy == q:",
"+ cost -= 1",
"+ break",
"+ if ans > cost:",
"+ ans = cost",
"+print(ans)"
] | false | 0.046989 | 0.038107 | 1.233069 | [
"s788444186",
"s172188389"
] |
u340781749 | p02775 | python | s197791203 | s801371770 | 1,517 | 1,188 | 5,492 | 5,492 | Accepted | Accepted | 21.69 | n = eval(input())
precise = 0
ok_over = 1
ok_prec = 0
for d in n:
d = int(d)
new_over = min(precise + d + 1, ok_over + d + 2, ok_over + 9 - d, ok_prec + d + 1)
new_prec = min(ok_over + d + 1, ok_prec + d)
precise += d
ok_over = new_over
ok_prec = new_prec
ok_over += 1
print((min(precise, ok_over, ok_prec)))
| n = eval(input())
precise = 0
over = 1
for d in n:
d = int(d)
new_over = min(precise + d + 1, over + d + 2, over + 9 - d)
precise = min(over + d + 1, precise + d)
over = new_over
over += 1
print((min(precise, over)))
| 13 | 10 | 337 | 234 | n = eval(input())
precise = 0
ok_over = 1
ok_prec = 0
for d in n:
d = int(d)
new_over = min(precise + d + 1, ok_over + d + 2, ok_over + 9 - d, ok_prec + d + 1)
new_prec = min(ok_over + d + 1, ok_prec + d)
precise += d
ok_over = new_over
ok_prec = new_prec
ok_over += 1
print((min(precise, ok_over, ok_prec)))
| n = eval(input())
precise = 0
over = 1
for d in n:
d = int(d)
new_over = min(precise + d + 1, over + d + 2, over + 9 - d)
precise = min(over + d + 1, precise + d)
over = new_over
over += 1
print((min(precise, over)))
| false | 23.076923 | [
"-ok_over = 1",
"-ok_prec = 0",
"+over = 1",
"- new_over = min(precise + d + 1, ok_over + d + 2, ok_over + 9 - d, ok_prec + d + 1)",
"- new_prec = min(ok_over + d + 1, ok_prec + d)",
"- precise += d",
"- ok_over = new_over",
"- ok_prec = new_prec",
"-ok_over += 1",
"-print((min(precise, ok_over, ok_prec)))",
"+ new_over = min(precise + d + 1, over + d + 2, over + 9 - d)",
"+ precise = min(over + d + 1, precise + d)",
"+ over = new_over",
"+over += 1",
"+print((min(precise, over)))"
] | false | 0.083525 | 0.038621 | 2.162692 | [
"s197791203",
"s801371770"
] |
u729133443 | p02614 | python | s775305689 | s599650326 | 97 | 73 | 9,020 | 9,092 | Accepted | Accepted | 24.74 | h,*c=open(0)
h,w,k=list(map(int,h.split()))
print((sum(k==sum(y>>w+z//w&y%2**w>>z%w&1and'.'>c[z//w][z%w]for z in range(h*w))for y in range(1<<h+w)))) | h,*c=open(0)
h,w,k=list(map(int,h.split()))
print((sum(k==sum(y>>w+z//w&y>>z%w&1and'.'>c[z//w][z%w]for z in range(h*w))for y in range(1<<h+w)))) | 3 | 3 | 143 | 138 | h, *c = open(0)
h, w, k = list(map(int, h.split()))
print(
(
sum(
k
== sum(
y >> w + z // w & y % 2**w >> z % w & 1 and "." > c[z // w][z % w]
for z in range(h * w)
)
for y in range(1 << h + w)
)
)
)
| h, *c = open(0)
h, w, k = list(map(int, h.split()))
print(
(
sum(
k
== sum(
y >> w + z // w & y >> z % w & 1 and "." > c[z // w][z % w]
for z in range(h * w)
)
for y in range(1 << h + w)
)
)
)
| false | 0 | [
"- y >> w + z // w & y % 2**w >> z % w & 1 and \".\" > c[z // w][z % w]",
"+ y >> w + z // w & y >> z % w & 1 and \".\" > c[z // w][z % w]"
] | false | 0.169626 | 0.08808 | 1.92582 | [
"s775305689",
"s599650326"
] |
u136090046 | p03294 | python | s507034294 | s376446562 | 57 | 18 | 5,688 | 3,316 | Accepted | Accepted | 68.42 | from fractions import gcd
n = int(eval(input()))
array = sorted([int(x) for x in input().split()])
res = 0
for i in array:
res += i-1
print(res) | n = int(eval(input()))
array = [int(x) for x in input().split()]
res = 0
for i in array:
res += i-1
print(res) | 9 | 7 | 152 | 115 | from fractions import gcd
n = int(eval(input()))
array = sorted([int(x) for x in input().split()])
res = 0
for i in array:
res += i - 1
print(res)
| n = int(eval(input()))
array = [int(x) for x in input().split()]
res = 0
for i in array:
res += i - 1
print(res)
| false | 22.222222 | [
"-from fractions import gcd",
"-",
"-array = sorted([int(x) for x in input().split()])",
"+array = [int(x) for x in input().split()]"
] | false | 0.034556 | 0.037519 | 0.921026 | [
"s507034294",
"s376446562"
] |
u604774382 | p02258 | python | s096306185 | s697206716 | 800 | 280 | 6,724 | 4,208 | Accepted | Accepted | 65 | n = int( eval(input( )) )
mi = int( eval(input( )) )
profit = 0 - 1000000000
for i in range( n-1 ):
num = int( eval(input( )) )
diff = num - mi
if profit < diff:
profit = diff
if num < mi:
mi = num
print( profit )
| n = int( input( ) )
mi = int( input( ) )
profit = 0 - 1000000000
n -= 1
i = 0
while i < n:
num = int( input( ) )
diff = num - mi
if profit < diff:
profit = diff
if num < mi:
mi = num
i += 1
print( profit ) | 17 | 18 | 228 | 248 | n = int(eval(input()))
mi = int(eval(input()))
profit = 0 - 1000000000
for i in range(n - 1):
num = int(eval(input()))
diff = num - mi
if profit < diff:
profit = diff
if num < mi:
mi = num
print(profit)
| n = int(input())
mi = int(input())
profit = 0 - 1000000000
n -= 1
i = 0
while i < n:
num = int(input())
diff = num - mi
if profit < diff:
profit = diff
if num < mi:
mi = num
i += 1
print(profit)
| false | 5.555556 | [
"-n = int(eval(input()))",
"-mi = int(eval(input()))",
"+n = int(input())",
"+mi = int(input())",
"-for i in range(n - 1):",
"- num = int(eval(input()))",
"+n -= 1",
"+i = 0",
"+while i < n:",
"+ num = int(input())",
"+ i += 1"
] | false | 0.09892 | 0.043823 | 2.257267 | [
"s096306185",
"s697206716"
] |
u863964720 | p02702 | python | s246490021 | s378519219 | 313 | 289 | 27,412 | 27,176 | Accepted | Accepted | 7.67 | from operator import mul
from functools import reduce
import numpy as np
#def ConZ(i):
#z_num = i+int(i*(i-1)/2)
#return z_num
#def ConN(i):
#n_num = int(i*(i-1)/2)
#return n_num
def cmb(n):
over = reduce(mul, list(range(n, n - 2, -1)))
under = reduce(mul, list(range(1,2 + 1)))
return over // under
S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = np.array([0]*2019)
mod[0] += 1
for i in range(len(S)):
A_num += int(S[i:i+1])*keta
if A_num >= 2019:
A_num = A_num%2019
mod[A_num] +=1
#keta*=10
keta = keta * 10 % 2019
#print(mod)
#x += ConZ(mod[0])
#del mod[0]
#for j in range(len(mod)):
#x+=cmb(mod[j])
#print(x)
print((int(np.sum(mod* (mod - 1) /2))))
| from operator import mul
from functools import reduce
import numpy as np
def ConZ(i):
z_num = i+int(i*(i-1)/2)
return z_num
#def ConN(i):
#n_num = int(i*(i-1)/2)
#return n_num
def cmb(n):
over = reduce(mul, list(range(n, n - 2, -1)))
under = reduce(mul, list(range(1,2 + 1)))
return over // under
S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = np.array([0]*2019)
for i in range(len(S)):
A_num += int(S[i:i+1])*keta
if A_num >= 2019:
A_num = A_num%2019
mod[A_num] +=1
#keta*=10
keta = keta * 10 % 2019
#print(mod)
x += ConZ(mod[0])
#del mod[0]
for j in range(1,len(mod)):
x+=cmb(mod[j])
print(x)
#print(int(np.sum(mod* (mod - 1) /2)))
| 37 | 35 | 740 | 721 | from operator import mul
from functools import reduce
import numpy as np
# def ConZ(i):
# z_num = i+int(i*(i-1)/2)
# return z_num
# def ConN(i):
# n_num = int(i*(i-1)/2)
# return n_num
def cmb(n):
over = reduce(mul, list(range(n, n - 2, -1)))
under = reduce(mul, list(range(1, 2 + 1)))
return over // under
S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = np.array([0] * 2019)
mod[0] += 1
for i in range(len(S)):
A_num += int(S[i : i + 1]) * keta
if A_num >= 2019:
A_num = A_num % 2019
mod[A_num] += 1
# keta*=10
keta = keta * 10 % 2019
# print(mod)
# x += ConZ(mod[0])
# del mod[0]
# for j in range(len(mod)):
# x+=cmb(mod[j])
# print(x)
print((int(np.sum(mod * (mod - 1) / 2))))
| from operator import mul
from functools import reduce
import numpy as np
def ConZ(i):
z_num = i + int(i * (i - 1) / 2)
return z_num
# def ConN(i):
# n_num = int(i*(i-1)/2)
# return n_num
def cmb(n):
over = reduce(mul, list(range(n, n - 2, -1)))
under = reduce(mul, list(range(1, 2 + 1)))
return over // under
S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = np.array([0] * 2019)
for i in range(len(S)):
A_num += int(S[i : i + 1]) * keta
if A_num >= 2019:
A_num = A_num % 2019
mod[A_num] += 1
# keta*=10
keta = keta * 10 % 2019
# print(mod)
x += ConZ(mod[0])
# del mod[0]
for j in range(1, len(mod)):
x += cmb(mod[j])
print(x)
# print(int(np.sum(mod* (mod - 1) /2)))
| false | 5.405405 | [
"-# def ConZ(i):",
"-# z_num = i+int(i*(i-1)/2)",
"-# return z_num",
"+",
"+def ConZ(i):",
"+ z_num = i + int(i * (i - 1) / 2)",
"+ return z_num",
"+",
"+",
"-mod[0] += 1",
"-# x += ConZ(mod[0])",
"+x += ConZ(mod[0])",
"-# for j in range(len(mod)):",
"-# x+=cmb(mod[j])",
"-# print(x)",
"-print((int(np.sum(mod * (mod - 1) / 2))))",
"+for j in range(1, len(mod)):",
"+ x += cmb(mod[j])",
"+print(x)",
"+# print(int(np.sum(mod* (mod - 1) /2)))"
] | false | 0.218522 | 0.333566 | 0.655107 | [
"s246490021",
"s378519219"
] |
u994988729 | p02559 | python | s240438541 | s677552461 | 2,958 | 699 | 59,420 | 61,416 | Accepted | Accepted | 76.37 | import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
class BinaryIndexTree: # 1-indexed
def __init__(self, N):
"""
INPUT
N [int] -> 全部0で初期化
N [list] -> そのまま初期化
"""
if isinstance(N, int):
self.N = N
self.depth = N.bit_length()
self.tree = [0] * (N + 1)
self.elem = [0] * (N + 1)
elif isinstance(N, list):
self.N = len(N)
self.depth = self.N.bit_length()
self.tree = [0] + N
self.elem = [0] + N
self._init()
else:
raise "INVALID INPUT: input must be int or list"
def _init(self):
size = self.N
for i in range(1, self.N):
if i + (i & -i) > size:
continue
self.tree[i + (i & -i)] += self.tree[i]
def show(self):
print((*self.elem))
def add(self, i, x):
self.elem[i] += x
while i <= self.N:
self.tree[i] += x
i += i & -i
def sum(self, i):
res = 0
while i > 0:
res += self.tree[i]
i -= i & -i
return res
def lower_bound(self, val):
if val <= 0:
return 0
i = 0
k = 1 << self.depth
while k:
if i + k <= self.N and self.tree[i + k] < val:
val -= self.tree[i + k]
i += k
k >>= 1
return i + 1
N, Q = list(map(int, input().split()))
A = list(map(int, input().split()))
bit = BinaryIndexTree(A)
for _ in range(Q):
t, a, b = list(map(int, input().split()))
if t == 0:
bit.add(a + 1, b)
else:
print((bit.sum(b) - bit.sum(a))) | code = r"""
# distutils: language=c++
# distutils: include_dirs = [/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]
from libcpp cimport *
cdef extern from "/opt/atcoder-stl/atcoder/fenwicktree.hpp" namespace "atcoder":
cdef cppclass fenwick_tree[T]:
fenwick_tree()
fenwick_tree(int n)
void add(int a, T x)
T sum(int l, int r)
import sys
input = sys.stdin.buffer.readline
N, Q = map(int, input().split())
cdef fenwick_tree[long] bit
bit = fenwick_tree[long](N)
A = list(map(int, input().split()))
for i, a in enumerate(A):
bit.add(i, a)
for _ in range(Q):
t, u, v = map(int, input().split())
if t == 0:
bit.add(u, v)
else:
print(bit.sum(u, v))
"""
import os
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
open('solve.pyx', 'w').write(code)
os.system('cythonize -i -3 -b solve.pyx')
import solve | 72 | 37 | 1,795 | 952 | import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
class BinaryIndexTree: # 1-indexed
def __init__(self, N):
"""
INPUT
N [int] -> 全部0で初期化
N [list] -> そのまま初期化
"""
if isinstance(N, int):
self.N = N
self.depth = N.bit_length()
self.tree = [0] * (N + 1)
self.elem = [0] * (N + 1)
elif isinstance(N, list):
self.N = len(N)
self.depth = self.N.bit_length()
self.tree = [0] + N
self.elem = [0] + N
self._init()
else:
raise "INVALID INPUT: input must be int or list"
def _init(self):
size = self.N
for i in range(1, self.N):
if i + (i & -i) > size:
continue
self.tree[i + (i & -i)] += self.tree[i]
def show(self):
print((*self.elem))
def add(self, i, x):
self.elem[i] += x
while i <= self.N:
self.tree[i] += x
i += i & -i
def sum(self, i):
res = 0
while i > 0:
res += self.tree[i]
i -= i & -i
return res
def lower_bound(self, val):
if val <= 0:
return 0
i = 0
k = 1 << self.depth
while k:
if i + k <= self.N and self.tree[i + k] < val:
val -= self.tree[i + k]
i += k
k >>= 1
return i + 1
N, Q = list(map(int, input().split()))
A = list(map(int, input().split()))
bit = BinaryIndexTree(A)
for _ in range(Q):
t, a, b = list(map(int, input().split()))
if t == 0:
bit.add(a + 1, b)
else:
print((bit.sum(b) - bit.sum(a)))
| code = r"""
# distutils: language=c++
# distutils: include_dirs = [/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]
from libcpp cimport *
cdef extern from "/opt/atcoder-stl/atcoder/fenwicktree.hpp" namespace "atcoder":
cdef cppclass fenwick_tree[T]:
fenwick_tree()
fenwick_tree(int n)
void add(int a, T x)
T sum(int l, int r)
import sys
input = sys.stdin.buffer.readline
N, Q = map(int, input().split())
cdef fenwick_tree[long] bit
bit = fenwick_tree[long](N)
A = list(map(int, input().split()))
for i, a in enumerate(A):
bit.add(i, a)
for _ in range(Q):
t, u, v = map(int, input().split())
if t == 0:
bit.add(u, v)
else:
print(bit.sum(u, v))
"""
import os
import sys
if sys.argv[-1] == "ONLINE_JUDGE":
open("solve.pyx", "w").write(code)
os.system("cythonize -i -3 -b solve.pyx")
import solve
| false | 48.611111 | [
"+code = r\"\"\"",
"+# distutils: language=c++",
"+# distutils: include_dirs = [/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]",
"+from libcpp cimport *",
"+cdef extern from \"/opt/atcoder-stl/atcoder/fenwicktree.hpp\" namespace \"atcoder\":",
"+ cdef cppclass fenwick_tree[T]:",
"+ fenwick_tree()",
"+ fenwick_tree(int n)",
"+ void add(int a, T x)",
"+ T sum(int l, int r)",
"+import sys",
"+input = sys.stdin.buffer.readline",
"+N, Q = map(int, input().split())",
"+cdef fenwick_tree[long] bit",
"+bit = fenwick_tree[long](N)",
"+A = list(map(int, input().split()))",
"+for i, a in enumerate(A):",
"+ bit.add(i, a)",
"+for _ in range(Q):",
"+ t, u, v = map(int, input().split())",
"+ if t == 0:",
"+ bit.add(u, v)",
"+ else:",
"+ print(bit.sum(u, v))",
"+\"\"\"",
"+import os",
"-input = sys.stdin.buffer.readline",
"-sys.setrecursionlimit(10**7)",
"-",
"-",
"-class BinaryIndexTree: # 1-indexed",
"- def __init__(self, N):",
"- \"\"\"",
"- INPUT",
"- N [int] -> 全部0で初期化",
"- N [list] -> そのまま初期化",
"- \"\"\"",
"- if isinstance(N, int):",
"- self.N = N",
"- self.depth = N.bit_length()",
"- self.tree = [0] * (N + 1)",
"- self.elem = [0] * (N + 1)",
"- elif isinstance(N, list):",
"- self.N = len(N)",
"- self.depth = self.N.bit_length()",
"- self.tree = [0] + N",
"- self.elem = [0] + N",
"- self._init()",
"- else:",
"- raise \"INVALID INPUT: input must be int or list\"",
"-",
"- def _init(self):",
"- size = self.N",
"- for i in range(1, self.N):",
"- if i + (i & -i) > size:",
"- continue",
"- self.tree[i + (i & -i)] += self.tree[i]",
"-",
"- def show(self):",
"- print((*self.elem))",
"-",
"- def add(self, i, x):",
"- self.elem[i] += x",
"- while i <= self.N:",
"- self.tree[i] += x",
"- i += i & -i",
"-",
"- def sum(self, i):",
"- res = 0",
"- while i > 0:",
"- res += self.tree[i]",
"- i -= i & -i",
"- return res",
"-",
"- def lower_bound(self, val):",
"- if val <= 0:",
"- return 0",
"- i = 0",
"- k = 1 << self.depth",
"- while k:",
"- if i + k <= self.N and self.tree[i + k] < val:",
"- val -= self.tree[i + k]",
"- i += k",
"- k >>= 1",
"- return i + 1",
"-",
"-",
"-N, Q = list(map(int, input().split()))",
"-A = list(map(int, input().split()))",
"-bit = BinaryIndexTree(A)",
"-for _ in range(Q):",
"- t, a, b = list(map(int, input().split()))",
"- if t == 0:",
"- bit.add(a + 1, b)",
"- else:",
"- print((bit.sum(b) - bit.sum(a)))",
"+if sys.argv[-1] == \"ONLINE_JUDGE\":",
"+ open(\"solve.pyx\", \"w\").write(code)",
"+ os.system(\"cythonize -i -3 -b solve.pyx\")",
"+import solve"
] | false | 0.035557 | 0.041115 | 0.864826 | [
"s240438541",
"s677552461"
] |
u498487134 | p02756 | python | s510816615 | s155110908 | 891 | 335 | 97,948 | 144,972 | Accepted | Accepted | 62.4 |
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
from collections import deque
def main():
mod=10**9+7
S=deque(eval(input()))
Q=I()
dir=0#0で手前につける
for _ in range(Q):
q=list(input().split())
if q[0]=="1":
dir+=1
dir%=2
else:
dir2=dir
if q[1]=="2":
dir2+=1
dir2%=2
if dir2==0:
S.appendleft(q[2])
else:
S.append(q[2])
ans=list(S)
if dir==1:
ans=ans[::-1]
print((''.join(map(str, ans))))
main()
|
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
from collections import deque
def main():
mod=10**9+7
S=eval(input())
from collections import deque
dq=deque()
for c in S:
dq.appendleft(c)
rev=0
Q=I()
for _ in range(Q):
q=input().split()
if q[0]=="1":
rev=(rev+1)%2
else:
f=int(q[1])
c=q[2]
if (rev+f)%2==1:
dq.append(c)
else:
dq.appendleft(c)
ans=[]
if rev:
while dq:
ans.append(dq.popleft())
else:
while dq:
ans.append(dq.pop())
print((''.join(map(str, ans))))
main()
| 38 | 47 | 738 | 878 | def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
from collections import deque
def main():
mod = 10**9 + 7
S = deque(eval(input()))
Q = I()
dir = 0 # 0で手前につける
for _ in range(Q):
q = list(input().split())
if q[0] == "1":
dir += 1
dir %= 2
else:
dir2 = dir
if q[1] == "2":
dir2 += 1
dir2 %= 2
if dir2 == 0:
S.appendleft(q[2])
else:
S.append(q[2])
ans = list(S)
if dir == 1:
ans = ans[::-1]
print(("".join(map(str, ans))))
main()
| def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
from collections import deque
def main():
mod = 10**9 + 7
S = eval(input())
from collections import deque
dq = deque()
for c in S:
dq.appendleft(c)
rev = 0
Q = I()
for _ in range(Q):
q = input().split()
if q[0] == "1":
rev = (rev + 1) % 2
else:
f = int(q[1])
c = q[2]
if (rev + f) % 2 == 1:
dq.append(c)
else:
dq.appendleft(c)
ans = []
if rev:
while dq:
ans.append(dq.popleft())
else:
while dq:
ans.append(dq.pop())
print(("".join(map(str, ans))))
main()
| false | 19.148936 | [
"- S = deque(eval(input()))",
"+ S = eval(input())",
"+ from collections import deque",
"+",
"+ dq = deque()",
"+ for c in S:",
"+ dq.appendleft(c)",
"+ rev = 0",
"- dir = 0 # 0で手前につける",
"- q = list(input().split())",
"+ q = input().split()",
"- dir += 1",
"- dir %= 2",
"+ rev = (rev + 1) % 2",
"- dir2 = dir",
"- if q[1] == \"2\":",
"- dir2 += 1",
"- dir2 %= 2",
"- if dir2 == 0:",
"- S.appendleft(q[2])",
"+ f = int(q[1])",
"+ c = q[2]",
"+ if (rev + f) % 2 == 1:",
"+ dq.append(c)",
"- S.append(q[2])",
"- ans = list(S)",
"- if dir == 1:",
"- ans = ans[::-1]",
"+ dq.appendleft(c)",
"+ ans = []",
"+ if rev:",
"+ while dq:",
"+ ans.append(dq.popleft())",
"+ else:",
"+ while dq:",
"+ ans.append(dq.pop())"
] | false | 0.03404 | 0.03577 | 0.951634 | [
"s510816615",
"s155110908"
] |
u347600233 | p02934 | python | s779743451 | s088746186 | 31 | 26 | 9,076 | 8,912 | Accepted | Accepted | 16.13 | n = int(eval(input()))
a = [int(i) for i in input().split()]
print((1 / sum(1 / ai for ai in a))) | n = int(eval(input()))
a = list(map(int, input().split()))
print((1 / sum(1 / ai for ai in a))) | 3 | 3 | 91 | 89 | n = int(eval(input()))
a = [int(i) for i in input().split()]
print((1 / sum(1 / ai for ai in a)))
| n = int(eval(input()))
a = list(map(int, input().split()))
print((1 / sum(1 / ai for ai in a)))
| false | 0 | [
"-a = [int(i) for i in input().split()]",
"+a = list(map(int, input().split()))"
] | false | 0.067602 | 0.065978 | 1.024613 | [
"s779743451",
"s088746186"
] |
u148551245 | p03415 | python | s278802118 | s321787166 | 175 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90.29 | l = [0] * 3
for i in range(3):
l[i] = list(input())
for i in range(3):
for j in range(3):
if i == j:
print(l[i][j], end='')
print("")
| for i in range(3):
print(input()[i], end='')
print()
| 9 | 3 | 170 | 59 | l = [0] * 3
for i in range(3):
l[i] = list(input())
for i in range(3):
for j in range(3):
if i == j:
print(l[i][j], end="")
print("")
| for i in range(3):
print(input()[i], end="")
print()
| false | 66.666667 | [
"-l = [0] * 3",
"- l[i] = list(input())",
"-for i in range(3):",
"- for j in range(3):",
"- if i == j:",
"- print(l[i][j], end=\"\")",
"-print(\"\")",
"+ print(input()[i], end=\"\")",
"+print()"
] | false | 0.042463 | 0.074577 | 0.569381 | [
"s278802118",
"s321787166"
] |
u312025627 | p03262 | python | s294572331 | s229226653 | 320 | 258 | 81,812 | 64,360 | Accepted | Accepted | 19.38 | def main():
N, X = (int(i) for i in input().split())
x = [abs(int(i) - X) for i in input().split()]
from fractions import gcd
for i in range(1,N):
x[i] = gcd(x[i-1], x[i])
print((x[-1]))
if __name__ == '__main__':
main() |
def gcd(x, y):
if y == 0:
return x
while y != 0:
x, y = y, x % y
return x
def main():
N, X = (int(i) for i in input().split())
A = [int(i) for i in input().split()] + [X]
A.sort()
diff = [A[i+1] - A[i] for i in range(N)]
ans = diff[0]
for d in diff:
ans = gcd(ans, d)
print(ans)
if __name__ == '__main__':
main()
| 11 | 22 | 262 | 407 | def main():
N, X = (int(i) for i in input().split())
x = [abs(int(i) - X) for i in input().split()]
from fractions import gcd
for i in range(1, N):
x[i] = gcd(x[i - 1], x[i])
print((x[-1]))
if __name__ == "__main__":
main()
| def gcd(x, y):
if y == 0:
return x
while y != 0:
x, y = y, x % y
return x
def main():
N, X = (int(i) for i in input().split())
A = [int(i) for i in input().split()] + [X]
A.sort()
diff = [A[i + 1] - A[i] for i in range(N)]
ans = diff[0]
for d in diff:
ans = gcd(ans, d)
print(ans)
if __name__ == "__main__":
main()
| false | 50 | [
"+def gcd(x, y):",
"+ if y == 0:",
"+ return x",
"+ while y != 0:",
"+ x, y = y, x % y",
"+ return x",
"+",
"+",
"- x = [abs(int(i) - X) for i in input().split()]",
"- from fractions import gcd",
"-",
"- for i in range(1, N):",
"- x[i] = gcd(x[i - 1], x[i])",
"- print((x[-1]))",
"+ A = [int(i) for i in input().split()] + [X]",
"+ A.sort()",
"+ diff = [A[i + 1] - A[i] for i in range(N)]",
"+ ans = diff[0]",
"+ for d in diff:",
"+ ans = gcd(ans, d)",
"+ print(ans)"
] | false | 0.139798 | 0.043923 | 3.182764 | [
"s294572331",
"s229226653"
] |
u498487134 | p02733 | python | s770351359 | s777722094 | 1,644 | 452 | 49,756 | 74,376 | Accepted | Accepted | 72.51 | def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
H,W,K=MI()
S=[[]for _ in range(H)]
for i in range(H):
S[i]=list(eval(input()))
ans=10**10
import itertools
import bisect
for ite in itertools.product([0,1], repeat=H):
#高さ方向で全探索,0,1の切り替わりでグループを分ける
g=[]#各グループの末尾列の番号
cnt=[]#数えるよう,合計
cnt2=[]#数えるよう,その列だけ
now=-1
for i in range(len(ite)):
if ite[i]!=now:
g.append(i-1)
cnt.append(0)
cnt2.append(0)
now=ite[i]
g.append(H-1)
cnt.append(0)
cnt2.append(0)
temp=len(g)-2
last=[0]#最後に追ったところを保存
fl=0#Kを超えたら
fl2=0#無理なとき
for j in range(W):
for k in range(len(cnt2)):
cnt2[k]=0
if fl2==1:
break
for i in range(H):
if S[i][j]=="1":
num=bisect.bisect_left(g,i)
cnt[num]+=1
cnt2[num]+=1
if cnt[num]>K:
fl=1
if fl==1:
for k in range(len(cnt)):
cnt[k]=cnt2[k]
cnt2[k]=0
fl=0
temp+=1
last.append(j)
if last[-1]==last[-2]:
temp=10**10
fl2=1
break
#print(ite,temp,g,last)
ans=min(ans,temp)
print(ans)
main()
| def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
H,W,K=MI()
S=[]
for _ in range(H):
s=eval(input())
S.append(s)
# Hに関してbit全探索
import itertools
inf=10**10
ans=inf
import bisect
for ite in itertools.product([0,1], repeat=H-1):
temp=sum(ite)
g=[-1]#グループに分ける,区切り(末尾)の数字をいれる
for i in range(len(ite)):
if ite[i]==1:
g.append(i)
M=len(g)
cnt=[0]*M#グループ毎
flag=1#無理かどうか
for j in range(W):
if flag==0:
break
cnt2=[0]*M#各列用
#数える
for i in range(H):
if S[i][j]=="1":
num=bisect.bisect_left(g,i)-1
cnt[num]+=1
cnt2[num]+=1
#無理
for i in range(M):
if cnt2[i]>K:
temp=inf
flag=0
break
#わるか確認
flag2=0
for i in range(M):
if cnt[i]>K:
flag2=1
break
#わる
if flag2:
for i in range(M):
cnt[i]=cnt2[i]
temp+=1
# print(ite,temp,g)
ans=min(ans,temp)
print(ans)
main()
| 74 | 71 | 1,859 | 1,651 | def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def main():
mod = 10**9 + 7
H, W, K = MI()
S = [[] for _ in range(H)]
for i in range(H):
S[i] = list(eval(input()))
ans = 10**10
import itertools
import bisect
for ite in itertools.product([0, 1], repeat=H):
# 高さ方向で全探索,0,1の切り替わりでグループを分ける
g = [] # 各グループの末尾列の番号
cnt = [] # 数えるよう,合計
cnt2 = [] # 数えるよう,その列だけ
now = -1
for i in range(len(ite)):
if ite[i] != now:
g.append(i - 1)
cnt.append(0)
cnt2.append(0)
now = ite[i]
g.append(H - 1)
cnt.append(0)
cnt2.append(0)
temp = len(g) - 2
last = [0] # 最後に追ったところを保存
fl = 0 # Kを超えたら
fl2 = 0 # 無理なとき
for j in range(W):
for k in range(len(cnt2)):
cnt2[k] = 0
if fl2 == 1:
break
for i in range(H):
if S[i][j] == "1":
num = bisect.bisect_left(g, i)
cnt[num] += 1
cnt2[num] += 1
if cnt[num] > K:
fl = 1
if fl == 1:
for k in range(len(cnt)):
cnt[k] = cnt2[k]
cnt2[k] = 0
fl = 0
temp += 1
last.append(j)
if last[-1] == last[-2]:
temp = 10**10
fl2 = 1
break
# print(ite,temp,g,last)
ans = min(ans, temp)
print(ans)
main()
| def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def main():
mod = 10**9 + 7
H, W, K = MI()
S = []
for _ in range(H):
s = eval(input())
S.append(s)
# Hに関してbit全探索
import itertools
inf = 10**10
ans = inf
import bisect
for ite in itertools.product([0, 1], repeat=H - 1):
temp = sum(ite)
g = [-1] # グループに分ける,区切り(末尾)の数字をいれる
for i in range(len(ite)):
if ite[i] == 1:
g.append(i)
M = len(g)
cnt = [0] * M # グループ毎
flag = 1 # 無理かどうか
for j in range(W):
if flag == 0:
break
cnt2 = [0] * M # 各列用
# 数える
for i in range(H):
if S[i][j] == "1":
num = bisect.bisect_left(g, i) - 1
cnt[num] += 1
cnt2[num] += 1
# 無理
for i in range(M):
if cnt2[i] > K:
temp = inf
flag = 0
break
# わるか確認
flag2 = 0
for i in range(M):
if cnt[i] > K:
flag2 = 1
break
# わる
if flag2:
for i in range(M):
cnt[i] = cnt2[i]
temp += 1
# print(ite,temp,g)
ans = min(ans, temp)
print(ans)
main()
| false | 4.054054 | [
"- S = [[] for _ in range(H)]",
"- for i in range(H):",
"- S[i] = list(eval(input()))",
"- ans = 10**10",
"+ S = []",
"+ for _ in range(H):",
"+ s = eval(input())",
"+ S.append(s)",
"+ # Hに関してbit全探索",
"+",
"+ inf = 10**10",
"+ ans = inf",
"- for ite in itertools.product([0, 1], repeat=H):",
"- # 高さ方向で全探索,0,1の切り替わりでグループを分ける",
"- g = [] # 各グループの末尾列の番号",
"- cnt = [] # 数えるよう,合計",
"- cnt2 = [] # 数えるよう,その列だけ",
"- now = -1",
"+ for ite in itertools.product([0, 1], repeat=H - 1):",
"+ temp = sum(ite)",
"+ g = [-1] # グループに分ける,区切り(末尾)の数字をいれる",
"- if ite[i] != now:",
"- g.append(i - 1)",
"- cnt.append(0)",
"- cnt2.append(0)",
"- now = ite[i]",
"- g.append(H - 1)",
"- cnt.append(0)",
"- cnt2.append(0)",
"- temp = len(g) - 2",
"- last = [0] # 最後に追ったところを保存",
"- fl = 0 # Kを超えたら",
"- fl2 = 0 # 無理なとき",
"+ if ite[i] == 1:",
"+ g.append(i)",
"+ M = len(g)",
"+ cnt = [0] * M # グループ毎",
"+ flag = 1 # 無理かどうか",
"- for k in range(len(cnt2)):",
"- cnt2[k] = 0",
"- if fl2 == 1:",
"+ if flag == 0:",
"+ cnt2 = [0] * M # 各列用",
"+ # 数える",
"- num = bisect.bisect_left(g, i)",
"+ num = bisect.bisect_left(g, i) - 1",
"- if cnt[num] > K:",
"- fl = 1",
"- if fl == 1:",
"- for k in range(len(cnt)):",
"- cnt[k] = cnt2[k]",
"- cnt2[k] = 0",
"- fl = 0",
"+ # 無理",
"+ for i in range(M):",
"+ if cnt2[i] > K:",
"+ temp = inf",
"+ flag = 0",
"+ break",
"+ # わるか確認",
"+ flag2 = 0",
"+ for i in range(M):",
"+ if cnt[i] > K:",
"+ flag2 = 1",
"+ break",
"+ # わる",
"+ if flag2:",
"+ for i in range(M):",
"+ cnt[i] = cnt2[i]",
"- last.append(j)",
"- if last[-1] == last[-2]:",
"- temp = 10**10",
"- fl2 = 1",
"- break",
"- # print(ite,temp,g,last)",
"+ # print(ite,temp,g)"
] | false | 0.046637 | 0.04652 | 1.002502 | [
"s770351359",
"s777722094"
] |
u130900604 | p02659 | python | s260375038 | s166516957 | 88 | 29 | 71,388 | 9,036 | Accepted | Accepted | 67.05 | from decimal import Decimal
a,b=list(map(Decimal,input().split()))
b=100*b
print((a*b//100)) | a,b=input().split()
a=int(a)
b=b.replace(".","")
b=int(b)
print((a*b//100)) | 4 | 5 | 87 | 77 | from decimal import Decimal
a, b = list(map(Decimal, input().split()))
b = 100 * b
print((a * b // 100))
| a, b = input().split()
a = int(a)
b = b.replace(".", "")
b = int(b)
print((a * b // 100))
| false | 20 | [
"-from decimal import Decimal",
"-",
"-a, b = list(map(Decimal, input().split()))",
"-b = 100 * b",
"+a, b = input().split()",
"+a = int(a)",
"+b = b.replace(\".\", \"\")",
"+b = int(b)"
] | false | 0.084897 | 0.038706 | 2.193381 | [
"s260375038",
"s166516957"
] |
u811733736 | p02361 | python | s363255787 | s937112714 | 4,730 | 2,980 | 196,712 | 195,896 | Accepted | Accepted | 37 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
"""
from enum import Enum
from heapq import heappush, heappop, heapify
class Sssp(object):
""" single source shortest path """
class Status(Enum):
""" ?????????????¨??????¶??? """
white = 1 # ????¨????
gray = 2 # ?¨???????
black = 3 #?¨???????
def __init__(self, V, data):
num_of_nodes = V
self.color = [Sssp.Status.white] * num_of_nodes # ????????????????¨??????¶???
self.d = [float('inf')] * num_of_nodes # ?§???????????????????
self.p = [-1] * num_of_nodes # ????????????????????????????¨?????????????????????????
self.adj = [[] for _ in range(num_of_nodes)]
self.make_adj(data)
def make_adj(self, data):
# ??£??\??????????????????
for f, t, c in data:
self.adj[f].insert(0, (t, c))
# self.adj[t].insert(0, (f, c))
def dijkstra(self, start):
self.d[start] = 0
pq = []
heappush(pq, (0, start))
while pq:
cost, u = heappop(pq)
self.color[u] = Sssp.Status.black
if self.d[u] < cost:
continue
for v, cost in self.adj[u]:
if self.color[v] == Sssp.Status.black:
continue
if self.d[v] > self.d[u] + cost:
self.d[v] = self.d[u] + cost
heappush(pq, (self.d[v], v))
self.color[v] = Sssp.Status.gray
if __name__ == '__main__':
# ??????????????\???
V, E, r = [int(x) for x in input().split(' ')]
data = []
for i in range(E):
data.append(list(map(int, input().split(' '))))
# ???????????¢?´¢
s = Sssp(V, data)
s.dijkstra(r)
# ???????????¨???
for i in range(V):
if s.d[i] == float('inf'):
print('INF')
else:
print(('{}'.format(s.d[i]))) | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
4.73[s]??§????????????AC
"""
from enum import Enum
from heapq import heappush, heappop
class Sssp(object):
""" single source shortest path """
class Status(Enum):
""" ?????????????¨??????¶??? """
white = 1 # ????¨????
gray = 2 # ?¨???????
black = 3 #?¨???????
def __init__(self, V, data):
num_of_nodes = V
self.color = [Sssp.Status.white] * num_of_nodes # ????????????????¨??????¶???
self.d = [float('inf')] * num_of_nodes # ?§???????????????????
self.p = [-1] * num_of_nodes # ????????????????????????????¨?????????????????????????
self.adj = [[] for _ in range(num_of_nodes)]
self.make_adj(data)
def make_adj(self, data):
# ??£??\??????????????????
for f, t, c in data:
self.adj[f].insert(0, (t, c))
# self.adj[t].insert(0, (f, c))
def dijkstra(self, start):
self.d[start] = 0
pq = []
heappush(pq, (0, start))
while pq:
cost, u = heappop(pq)
self.color[u] = Sssp.Status.black
if self.d[u] < cost:
continue
for v, cost in self.adj[u]:
if self.color[v] == Sssp.Status.black:
continue
if self.d[v] > self.d[u] + cost:
self.d[v] = self.d[u] + cost
heappush(pq, (self.d[v], v))
self.color[v] = Sssp.Status.gray
def solve(V, r, data):
WHITE = 0
GRAY = 1
BLACK = 2
num_of_nodes = V
color = [WHITE] * num_of_nodes # ????????????????¨??????¶???
d = [float('inf')] * num_of_nodes # ?§???????????????????
adj = [[] for _ in range(num_of_nodes)]
for f, t, c in data:
adj[f].insert(0, (t, c))
# dijkstra
d[r] = 0
pq = []
heappush(pq, (0, r))
while pq:
cost, u = heappop(pq)
color[u] = BLACK
if d[u] < cost:
continue
for v, cost in adj[u]:
if color[v] == BLACK:
continue
if d[v] > d[u] + cost:
d[v] = d[u] + cost
heappush(pq, (d[v], v))
color[v] = GRAY
# ???????????¨???
for i in range(V):
if d[i] == float('inf'):
print('INF')
else:
print(('{}'.format(d[i])))
if __name__ == '__main__':
# ??????????????\???
V, E, r = [int(x) for x in input().split(' ')]
data = []
for i in range(E):
data.append(list(map(int, input().split(' '))))
# ???????????¢?´¢
solve(V, r, data) | 68 | 101 | 2,041 | 2,802 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
"""
from enum import Enum
from heapq import heappush, heappop, heapify
class Sssp(object):
"""single source shortest path"""
class Status(Enum):
"""?????????????¨??????¶???"""
white = 1 # ????¨????
gray = 2 # ?¨???????
black = 3 # ?¨???????
def __init__(self, V, data):
num_of_nodes = V
self.color = [Sssp.Status.white] * num_of_nodes # ????????????????¨??????¶???
self.d = [float("inf")] * num_of_nodes # ?§???????????????????
self.p = [
-1
] * num_of_nodes # ????????????????????????????¨?????????????????????????
self.adj = [[] for _ in range(num_of_nodes)]
self.make_adj(data)
def make_adj(self, data):
# ??£??\??????????????????
for f, t, c in data:
self.adj[f].insert(0, (t, c))
# self.adj[t].insert(0, (f, c))
def dijkstra(self, start):
self.d[start] = 0
pq = []
heappush(pq, (0, start))
while pq:
cost, u = heappop(pq)
self.color[u] = Sssp.Status.black
if self.d[u] < cost:
continue
for v, cost in self.adj[u]:
if self.color[v] == Sssp.Status.black:
continue
if self.d[v] > self.d[u] + cost:
self.d[v] = self.d[u] + cost
heappush(pq, (self.d[v], v))
self.color[v] = Sssp.Status.gray
if __name__ == "__main__":
# ??????????????\???
V, E, r = [int(x) for x in input().split(" ")]
data = []
for i in range(E):
data.append(list(map(int, input().split(" "))))
# ???????????¢?´¢
s = Sssp(V, data)
s.dijkstra(r)
# ???????????¨???
for i in range(V):
if s.d[i] == float("inf"):
print("INF")
else:
print(("{}".format(s.d[i])))
| # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
4.73[s]??§????????????AC
"""
from enum import Enum
from heapq import heappush, heappop
class Sssp(object):
"""single source shortest path"""
class Status(Enum):
"""?????????????¨??????¶???"""
white = 1 # ????¨????
gray = 2 # ?¨???????
black = 3 # ?¨???????
def __init__(self, V, data):
num_of_nodes = V
self.color = [Sssp.Status.white] * num_of_nodes # ????????????????¨??????¶???
self.d = [float("inf")] * num_of_nodes # ?§???????????????????
self.p = [
-1
] * num_of_nodes # ????????????????????????????¨?????????????????????????
self.adj = [[] for _ in range(num_of_nodes)]
self.make_adj(data)
def make_adj(self, data):
# ??£??\??????????????????
for f, t, c in data:
self.adj[f].insert(0, (t, c))
# self.adj[t].insert(0, (f, c))
def dijkstra(self, start):
self.d[start] = 0
pq = []
heappush(pq, (0, start))
while pq:
cost, u = heappop(pq)
self.color[u] = Sssp.Status.black
if self.d[u] < cost:
continue
for v, cost in self.adj[u]:
if self.color[v] == Sssp.Status.black:
continue
if self.d[v] > self.d[u] + cost:
self.d[v] = self.d[u] + cost
heappush(pq, (self.d[v], v))
self.color[v] = Sssp.Status.gray
def solve(V, r, data):
WHITE = 0
GRAY = 1
BLACK = 2
num_of_nodes = V
color = [WHITE] * num_of_nodes # ????????????????¨??????¶???
d = [float("inf")] * num_of_nodes # ?§???????????????????
adj = [[] for _ in range(num_of_nodes)]
for f, t, c in data:
adj[f].insert(0, (t, c))
# dijkstra
d[r] = 0
pq = []
heappush(pq, (0, r))
while pq:
cost, u = heappop(pq)
color[u] = BLACK
if d[u] < cost:
continue
for v, cost in adj[u]:
if color[v] == BLACK:
continue
if d[v] > d[u] + cost:
d[v] = d[u] + cost
heappush(pq, (d[v], v))
color[v] = GRAY
# ???????????¨???
for i in range(V):
if d[i] == float("inf"):
print("INF")
else:
print(("{}".format(d[i])))
if __name__ == "__main__":
# ??????????????\???
V, E, r = [int(x) for x in input().split(" ")]
data = []
for i in range(E):
data.append(list(map(int, input().split(" "))))
# ???????????¢?´¢
solve(V, r, data)
| false | 32.673267 | [
"+4.73[s]??§????????????AC",
"-from heapq import heappush, heappop, heapify",
"+from heapq import heappush, heappop",
"+def solve(V, r, data):",
"+ WHITE = 0",
"+ GRAY = 1",
"+ BLACK = 2",
"+ num_of_nodes = V",
"+ color = [WHITE] * num_of_nodes # ????????????????¨??????¶???",
"+ d = [float(\"inf\")] * num_of_nodes # ?§???????????????????",
"+ adj = [[] for _ in range(num_of_nodes)]",
"+ for f, t, c in data:",
"+ adj[f].insert(0, (t, c))",
"+ # dijkstra",
"+ d[r] = 0",
"+ pq = []",
"+ heappush(pq, (0, r))",
"+ while pq:",
"+ cost, u = heappop(pq)",
"+ color[u] = BLACK",
"+ if d[u] < cost:",
"+ continue",
"+ for v, cost in adj[u]:",
"+ if color[v] == BLACK:",
"+ continue",
"+ if d[v] > d[u] + cost:",
"+ d[v] = d[u] + cost",
"+ heappush(pq, (d[v], v))",
"+ color[v] = GRAY",
"+ # ???????????¨???",
"+ for i in range(V):",
"+ if d[i] == float(\"inf\"):",
"+ print(\"INF\")",
"+ else:",
"+ print((\"{}\".format(d[i])))",
"+",
"+",
"- s = Sssp(V, data)",
"- s.dijkstra(r)",
"- # ???????????¨???",
"- for i in range(V):",
"- if s.d[i] == float(\"inf\"):",
"- print(\"INF\")",
"- else:",
"- print((\"{}\".format(s.d[i])))",
"+ solve(V, r, data)"
] | false | 0.098611 | 0.070183 | 1.405056 | [
"s363255787",
"s937112714"
] |
u556589653 | p03659 | python | s844052044 | s015074912 | 255 | 207 | 24,812 | 24,824 | Accepted | Accepted | 18.82 | N = int(eval(input()))
A = list(map(int,input().split()))
ruiseki = [0]*(N+1)
total = 0
now = 10**20
sa = 0
now_2 = 0
for i in range(N):
total += A[i]
ruiseki[i+1] = total
for i in range(1,len(ruiseki)-1):
snuke = ruiseki[i]-ruiseki[0]
arai = ruiseki[N]-ruiseki[i]
now_2 = abs(snuke-arai)
now = min(now,now_2)
print(now)
| N = int(eval(input()))
A = list(map(int,input().split()))
ruisekiwa = [0]*(N+1)
now = 0
minimum = 10**10
for i in range(N):
now += A[i]
ruisekiwa[i+1] = now
for i in range(N-1):
snuke = ruisekiwa[i+1]
arai = ruisekiwa[N]-snuke
K = abs(snuke-arai)
if K < minimum:
minimum = K
print(minimum) | 16 | 15 | 342 | 313 | N = int(eval(input()))
A = list(map(int, input().split()))
ruiseki = [0] * (N + 1)
total = 0
now = 10**20
sa = 0
now_2 = 0
for i in range(N):
total += A[i]
ruiseki[i + 1] = total
for i in range(1, len(ruiseki) - 1):
snuke = ruiseki[i] - ruiseki[0]
arai = ruiseki[N] - ruiseki[i]
now_2 = abs(snuke - arai)
now = min(now, now_2)
print(now)
| N = int(eval(input()))
A = list(map(int, input().split()))
ruisekiwa = [0] * (N + 1)
now = 0
minimum = 10**10
for i in range(N):
now += A[i]
ruisekiwa[i + 1] = now
for i in range(N - 1):
snuke = ruisekiwa[i + 1]
arai = ruisekiwa[N] - snuke
K = abs(snuke - arai)
if K < minimum:
minimum = K
print(minimum)
| false | 6.25 | [
"-ruiseki = [0] * (N + 1)",
"-total = 0",
"-now = 10**20",
"-sa = 0",
"-now_2 = 0",
"+ruisekiwa = [0] * (N + 1)",
"+now = 0",
"+minimum = 10**10",
"- total += A[i]",
"- ruiseki[i + 1] = total",
"-for i in range(1, len(ruiseki) - 1):",
"- snuke = ruiseki[i] - ruiseki[0]",
"- arai = ruiseki[N] - ruiseki[i]",
"- now_2 = abs(snuke - arai)",
"- now = min(now, now_2)",
"-print(now)",
"+ now += A[i]",
"+ ruisekiwa[i + 1] = now",
"+for i in range(N - 1):",
"+ snuke = ruisekiwa[i + 1]",
"+ arai = ruisekiwa[N] - snuke",
"+ K = abs(snuke - arai)",
"+ if K < minimum:",
"+ minimum = K",
"+print(minimum)"
] | false | 0.041399 | 0.040386 | 1.025089 | [
"s844052044",
"s015074912"
] |
u562935282 | p02624 | python | s153699958 | s615227236 | 1,296 | 30 | 9,148 | 9,180 | Accepted | Accepted | 97.69 | # 解説
def main():
N = int(eval(input()))
ans = 0
for div in range(1, N + 1):
m = N // div # div, div*2, ..., div*m
ans += (m * (m + 1) // 2) * div
print(ans)
if __name__ == '__main__':
main()
| def main():
from math import isqrt
# Return the integer part of the square root of the input.
N = int(eval(input()))
def f(x):
return x * (x + 1) // 2
ans = 0
for k in range(1, isqrt(N) + 1):
# https://maspypy.com/atcoder-%e5%8f%82%e5%8a%a0%e6%84%9f%e6%83%b3-2020-06-27abc-172
# a*b<=N
# k=min(a,b)
# k*k, k*(k+1),...,k*m
# k*jはkの倍数かつjの倍数なので,2回計上される
# k*kはkの倍数として1回だけ計上されるので,2回分計上して過剰分を減らす
m = N // k
ans += 2 * k * (f(m) - f(k - 1)) - k * k
print(ans)
if __name__ == '__main__':
main()
| 14 | 24 | 239 | 613 | # 解説
def main():
N = int(eval(input()))
ans = 0
for div in range(1, N + 1):
m = N // div # div, div*2, ..., div*m
ans += (m * (m + 1) // 2) * div
print(ans)
if __name__ == "__main__":
main()
| def main():
from math import isqrt
# Return the integer part of the square root of the input.
N = int(eval(input()))
def f(x):
return x * (x + 1) // 2
ans = 0
for k in range(1, isqrt(N) + 1):
# https://maspypy.com/atcoder-%e5%8f%82%e5%8a%a0%e6%84%9f%e6%83%b3-2020-06-27abc-172
# a*b<=N
# k=min(a,b)
# k*k, k*(k+1),...,k*m
# k*jはkの倍数かつjの倍数なので,2回計上される
# k*kはkの倍数として1回だけ計上されるので,2回分計上して過剰分を減らす
m = N // k
ans += 2 * k * (f(m) - f(k - 1)) - k * k
print(ans)
if __name__ == "__main__":
main()
| false | 41.666667 | [
"-# 解説",
"+ from math import isqrt",
"+",
"+ # Return the integer part of the square root of the input.",
"+",
"+ def f(x):",
"+ return x * (x + 1) // 2",
"+",
"- for div in range(1, N + 1):",
"- m = N // div # div, div*2, ..., div*m",
"- ans += (m * (m + 1) // 2) * div",
"+ for k in range(1, isqrt(N) + 1):",
"+ # https://maspypy.com/atcoder-%e5%8f%82%e5%8a%a0%e6%84%9f%e6%83%b3-2020-06-27abc-172",
"+ # a*b<=N",
"+ # k=min(a,b)",
"+ # k*k, k*(k+1),...,k*m",
"+ # k*jはkの倍数かつjの倍数なので,2回計上される",
"+ # k*kはkの倍数として1回だけ計上されるので,2回分計上して過剰分を減らす",
"+ m = N // k",
"+ ans += 2 * k * (f(m) - f(k - 1)) - k * k"
] | false | 0.90927 | 0.032336 | 28.118996 | [
"s153699958",
"s615227236"
] |
u057109575 | p03262 | python | s439627827 | s255849804 | 136 | 92 | 16,080 | 16,280 | Accepted | Accepted | 32.35 | from fractions import gcd
N, *X = list(map(int, open(0).read().split()))
X.sort()
y = [X[i + 1] - X[i] for i in range(N)]
ans = y[0]
for v in y[1:]:
ans = gcd(ans, v)
print(ans)
| from fractions import gcd
from functools import reduce
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
y = [abs(x[i] - X) for i in range(N)]
print((reduce(gcd, y))) | 9 | 6 | 183 | 188 | from fractions import gcd
N, *X = list(map(int, open(0).read().split()))
X.sort()
y = [X[i + 1] - X[i] for i in range(N)]
ans = y[0]
for v in y[1:]:
ans = gcd(ans, v)
print(ans)
| from fractions import gcd
from functools import reduce
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
y = [abs(x[i] - X) for i in range(N)]
print((reduce(gcd, y)))
| false | 33.333333 | [
"+from functools import reduce",
"-N, *X = list(map(int, open(0).read().split()))",
"-X.sort()",
"-y = [X[i + 1] - X[i] for i in range(N)]",
"-ans = y[0]",
"-for v in y[1:]:",
"- ans = gcd(ans, v)",
"-print(ans)",
"+N, X = list(map(int, input().split()))",
"+x = list(map(int, input().split()))",
"+y = [abs(x[i] - X) for i in range(N)]",
"+print((reduce(gcd, y)))"
] | false | 0.110276 | 0.142588 | 0.77339 | [
"s439627827",
"s255849804"
] |
u581187895 | p03018 | python | s627576323 | s609089669 | 66 | 49 | 3,500 | 9,292 | Accepted | Accepted | 25.76 | S = input().replace("BC", "D")
acc = 0
ans = 0
for s in S:
if s == "B" or s == "C":
acc = 0
continue
if s == "A":
acc += 1
if s == "D":
ans += acc
print(ans) |
def resolve():
S = eval(input())
rep_S = S.replace("BC", "D")
cnt = 0
ans = 0
for i in range(len(rep_S)):
if rep_S[i] == "A":
cnt += 1
elif rep_S[i] == "D":
ans += cnt
else:
cnt = 0
print(ans)
if __name__ == "__main__":
resolve() | 12 | 20 | 194 | 335 | S = input().replace("BC", "D")
acc = 0
ans = 0
for s in S:
if s == "B" or s == "C":
acc = 0
continue
if s == "A":
acc += 1
if s == "D":
ans += acc
print(ans)
| def resolve():
S = eval(input())
rep_S = S.replace("BC", "D")
cnt = 0
ans = 0
for i in range(len(rep_S)):
if rep_S[i] == "A":
cnt += 1
elif rep_S[i] == "D":
ans += cnt
else:
cnt = 0
print(ans)
if __name__ == "__main__":
resolve()
| false | 40 | [
"-S = input().replace(\"BC\", \"D\")",
"-acc = 0",
"-ans = 0",
"-for s in S:",
"- if s == \"B\" or s == \"C\":",
"- acc = 0",
"- continue",
"- if s == \"A\":",
"- acc += 1",
"- if s == \"D\":",
"- ans += acc",
"-print(ans)",
"+def resolve():",
"+ S = eval(input())",
"+ rep_S = S.replace(\"BC\", \"D\")",
"+ cnt = 0",
"+ ans = 0",
"+ for i in range(len(rep_S)):",
"+ if rep_S[i] == \"A\":",
"+ cnt += 1",
"+ elif rep_S[i] == \"D\":",
"+ ans += cnt",
"+ else:",
"+ cnt = 0",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ resolve()"
] | false | 0.075574 | 0.086546 | 0.873224 | [
"s627576323",
"s609089669"
] |
u761320129 | p03948 | python | s528368189 | s142345675 | 96 | 88 | 14,680 | 14,252 | Accepted | Accepted | 8.33 | N,T = list(map(int,input().split()))
A = list(map(int,input().split()))
cummax = [A[-1]]
for a in reversed(A[:-1]):
cummax.append(max(cummax[-1], a))
cummax.reverse()
maxgain = n = 0
for buy,sell in zip(A,cummax):
gain = sell - buy
if gain > maxgain:
maxgain = gain
n = 1
elif gain == maxgain:
n += 1
print(n)
| N,T = list(map(int,input().split()))
A = list(map(int,input().split()))
cnt = max_profit = 0
INF = float('inf')
min_cost = INF
for a in A:
profit = a - min_cost
if profit == max_profit:
cnt += 1
elif profit > max_profit:
cnt = 1
max_profit = profit
min_cost = min(min_cost, a)
print(cnt) | 17 | 16 | 362 | 338 | N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
cummax = [A[-1]]
for a in reversed(A[:-1]):
cummax.append(max(cummax[-1], a))
cummax.reverse()
maxgain = n = 0
for buy, sell in zip(A, cummax):
gain = sell - buy
if gain > maxgain:
maxgain = gain
n = 1
elif gain == maxgain:
n += 1
print(n)
| N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = max_profit = 0
INF = float("inf")
min_cost = INF
for a in A:
profit = a - min_cost
if profit == max_profit:
cnt += 1
elif profit > max_profit:
cnt = 1
max_profit = profit
min_cost = min(min_cost, a)
print(cnt)
| false | 5.882353 | [
"-cummax = [A[-1]]",
"-for a in reversed(A[:-1]):",
"- cummax.append(max(cummax[-1], a))",
"-cummax.reverse()",
"-maxgain = n = 0",
"-for buy, sell in zip(A, cummax):",
"- gain = sell - buy",
"- if gain > maxgain:",
"- maxgain = gain",
"- n = 1",
"- elif gain == maxgain:",
"- n += 1",
"-print(n)",
"+cnt = max_profit = 0",
"+INF = float(\"inf\")",
"+min_cost = INF",
"+for a in A:",
"+ profit = a - min_cost",
"+ if profit == max_profit:",
"+ cnt += 1",
"+ elif profit > max_profit:",
"+ cnt = 1",
"+ max_profit = profit",
"+ min_cost = min(min_cost, a)",
"+print(cnt)"
] | false | 0.035576 | 0.035865 | 0.991935 | [
"s528368189",
"s142345675"
] |
u476604182 | p02960 | python | s752250077 | s307104375 | 905 | 484 | 137,120 | 43,884 | Accepted | Accepted | 46.52 | S = eval(input())
con = 10**9 + 7
T = [s if s != "?" else "0" for s in S]
T = int(''.join(T))
SS = T % 13
def get_mod(S):
c = {}
iii = 1
for i in range(len(S)):
if S[len(S) - i - 1] != "?":
iii *= 10
iii %= 13
continue
c[i] = {(j * iii) % 13: 1 for j in range(0, 10)}
iii *= 10
iii %= 13
return c
c = get_mod(S)
def get_tdp(pdp):
tdp = {i: 0 for i in range(13)}
for r in list(v.keys()):
for _r, _v in list(pdp.items()):
i = (_r + r) % 13
tdp[i] += _v
for i in range(13):
tdp[i] %= con
return tdp
pdp = {i: 0 for i in range(13)}
pdp[SS] += 1
for k, v in list(c.items()):
pdp = get_tdp(pdp)
ans = pdp[5]
print(ans) | N = input()[::-1]
iv = 1
MOD = 10**9+7
pdp = [0 for i in range(13)]
pdp[0]=1
dp = [0 for i in range(13)]
for i in range(len(N)):
x = N[i]
if x=='?':
for j in range(13):
for h in range(10):
dp[(h*iv+j)%13] += pdp[j]
for j in range(13):
pdp[j] = (dp[j]%MOD)
dp[j] = 0
else:
x = int(x)
for j in range(13):
dp[(j+x*iv)%13]+=pdp[j]
for j in range(13):
pdp[j] = (dp[j]%MOD)
dp[j]=0
iv *= 10
iv %= 13
print((pdp[5])) | 38 | 25 | 774 | 505 | S = eval(input())
con = 10**9 + 7
T = [s if s != "?" else "0" for s in S]
T = int("".join(T))
SS = T % 13
def get_mod(S):
c = {}
iii = 1
for i in range(len(S)):
if S[len(S) - i - 1] != "?":
iii *= 10
iii %= 13
continue
c[i] = {(j * iii) % 13: 1 for j in range(0, 10)}
iii *= 10
iii %= 13
return c
c = get_mod(S)
def get_tdp(pdp):
tdp = {i: 0 for i in range(13)}
for r in list(v.keys()):
for _r, _v in list(pdp.items()):
i = (_r + r) % 13
tdp[i] += _v
for i in range(13):
tdp[i] %= con
return tdp
pdp = {i: 0 for i in range(13)}
pdp[SS] += 1
for k, v in list(c.items()):
pdp = get_tdp(pdp)
ans = pdp[5]
print(ans)
| N = input()[::-1]
iv = 1
MOD = 10**9 + 7
pdp = [0 for i in range(13)]
pdp[0] = 1
dp = [0 for i in range(13)]
for i in range(len(N)):
x = N[i]
if x == "?":
for j in range(13):
for h in range(10):
dp[(h * iv + j) % 13] += pdp[j]
for j in range(13):
pdp[j] = dp[j] % MOD
dp[j] = 0
else:
x = int(x)
for j in range(13):
dp[(j + x * iv) % 13] += pdp[j]
for j in range(13):
pdp[j] = dp[j] % MOD
dp[j] = 0
iv *= 10
iv %= 13
print((pdp[5]))
| false | 34.210526 | [
"-S = eval(input())",
"-con = 10**9 + 7",
"-T = [s if s != \"?\" else \"0\" for s in S]",
"-T = int(\"\".join(T))",
"-SS = T % 13",
"-",
"-",
"-def get_mod(S):",
"- c = {}",
"- iii = 1",
"- for i in range(len(S)):",
"- if S[len(S) - i - 1] != \"?\":",
"- iii *= 10",
"- iii %= 13",
"- continue",
"- c[i] = {(j * iii) % 13: 1 for j in range(0, 10)}",
"- iii *= 10",
"- iii %= 13",
"- return c",
"-",
"-",
"-c = get_mod(S)",
"-",
"-",
"-def get_tdp(pdp):",
"- tdp = {i: 0 for i in range(13)}",
"- for r in list(v.keys()):",
"- for _r, _v in list(pdp.items()):",
"- i = (_r + r) % 13",
"- tdp[i] += _v",
"- for i in range(13):",
"- tdp[i] %= con",
"- return tdp",
"-",
"-",
"-pdp = {i: 0 for i in range(13)}",
"-pdp[SS] += 1",
"-for k, v in list(c.items()):",
"- pdp = get_tdp(pdp)",
"-ans = pdp[5]",
"-print(ans)",
"+N = input()[::-1]",
"+iv = 1",
"+MOD = 10**9 + 7",
"+pdp = [0 for i in range(13)]",
"+pdp[0] = 1",
"+dp = [0 for i in range(13)]",
"+for i in range(len(N)):",
"+ x = N[i]",
"+ if x == \"?\":",
"+ for j in range(13):",
"+ for h in range(10):",
"+ dp[(h * iv + j) % 13] += pdp[j]",
"+ for j in range(13):",
"+ pdp[j] = dp[j] % MOD",
"+ dp[j] = 0",
"+ else:",
"+ x = int(x)",
"+ for j in range(13):",
"+ dp[(j + x * iv) % 13] += pdp[j]",
"+ for j in range(13):",
"+ pdp[j] = dp[j] % MOD",
"+ dp[j] = 0",
"+ iv *= 10",
"+ iv %= 13",
"+print((pdp[5]))"
] | false | 0.035847 | 0.076786 | 0.466851 | [
"s752250077",
"s307104375"
] |
u222668979 | p03583 | python | s036076907 | s703199739 | 1,983 | 1,418 | 9,124 | 8,924 | Accepted | Accepted | 28.49 | n = int(eval(input()))
for h in range(1, 3501):
for w in range(1, 3501):
bns = n * h * w
bnb = 4 * h * w - n * (h + w)
if bnb >= 1 and bns % bnb == 0:
print((h, w, bns // bnb))
exit()
| n = int(eval(input()))
for h in range(1, 3501):
for w in range(h, 3501):
bns = n * h * w
bnb = 4 * h * w - n * (h + w)
if bnb >= 1 and bns % bnb == 0:
print((h, w, bns // bnb))
exit()
| 9 | 9 | 237 | 237 | n = int(eval(input()))
for h in range(1, 3501):
for w in range(1, 3501):
bns = n * h * w
bnb = 4 * h * w - n * (h + w)
if bnb >= 1 and bns % bnb == 0:
print((h, w, bns // bnb))
exit()
| n = int(eval(input()))
for h in range(1, 3501):
for w in range(h, 3501):
bns = n * h * w
bnb = 4 * h * w - n * (h + w)
if bnb >= 1 and bns % bnb == 0:
print((h, w, bns // bnb))
exit()
| false | 0 | [
"- for w in range(1, 3501):",
"+ for w in range(h, 3501):"
] | false | 1.172413 | 1.160112 | 1.010603 | [
"s036076907",
"s703199739"
] |
u716530146 | p02763 | python | s151945089 | s237391599 | 671 | 488 | 70,660 | 73,784 | Accepted | Accepted | 27.27 | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
class SegmentTree:
__slots__ = ['ide','n','seg','segfunc']
def __init__(self,size,func,element):
self.segfunc = func
self.ide = element
# self.size = sizeを超える最小の2冪の数
self.n = 2 ** (n-1).bit_length()
# 全てのnodeの数は(2*n-1)個
# 上にn-1個,最下段にn個
self.seg = [self.ide] * (2*self.n-1)
def apply(self,array):
arraysize = len(array)
# 配列埋め込み
for i in range(arraysize):
self.seg[self.n-1+i] = array[i]
# 上にあげる
for i in range(self.n-2,-1,-1):
self.seg[i] = self.segfunc(self.seg[2*i+1],self.seg[2*i+2])
def update(self,k,x):
k += self.n -1
self.seg[k] = x
while k:
k = (k-1)//2
self.seg[k] = self.segfunc(self.seg[2*k+1],self.seg[2*k+2])
def notrec(self,l,r):
# 半開区間[l,r)
l += self.n-1; r += self.n-1
vl = vr = self.ide
while l < r:
if l & 1 == 0:
vl = self.segfunc(vl,self.seg[l])
l += 1
if r & 1 == 0:
vr = self.segfunc(vr,self.seg[r-1])
l = (l-1)//2; r = (r-1)//2
return self.segfunc(vl,vr)
def makebin(s):
k = ord(s)-ord("a")
# print(1<<k,k)
return 1 << k
def segfunc(a,b):
return a | b
def out(n):
count = 0
while n:
if n & 1 == 1:
print((chr(ord("a")+count)))
n//=2
count += 1
n = int(eval(input()))
st = SegmentTree(n,segfunc,0)
S = eval(input())
for i,si in enumerate(S):
st.update(i,makebin(si))
Q = int(eval(input()))
# print(st.seg)
# exit()
for _ in range(Q):
typo,a,b = input().split()
if typo == "1":
st.update(int(a)-1,makebin(b))
else:
print((bin(st.notrec(int(a)-1,int(b)))[1:].count("1")))
| #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
class SegmentTree:
__slots__ = ['ide','n','seg','segfunc']
def __init__(self,size,func,element):
self.segfunc = func
self.ide = element
# self.size = sizeを超える最小の2冪の数
self.n = 2 ** (n-1).bit_length()
# 全てのnodeの数は(2*n-1)個
# 上にn-1個,最下段にn個
self.seg = [self.ide] * (2*self.n-1)
def apply(self,array):
arraysize = len(array)
# 配列埋め込み
for i in range(arraysize):
self.seg[self.n-1+i] = array[i]
# 上にあげる
for i in range(self.n-2,-1,-1):
self.seg[i] = self.segfunc(self.seg[2*i+1],self.seg[2*i+2])
def update(self,k,x):
k += self.n -1
self.seg[k] = x
while k:
k = (k-1)//2
self.seg[k] = self.segfunc(self.seg[2*k+1],self.seg[2*k+2])
def query(self,l,r):
# 半開区間[l,r)
l += self.n-1; r += self.n-1
vl = vr = self.ide
while l < r:
if l & 1 == 0:
vl = self.segfunc(vl,self.seg[l])
l += 1
if r & 1 == 0:
vr = self.segfunc(vr,self.seg[r-1])
l = (l-1)//2; r = (r-1)//2
return self.segfunc(vl,vr)
def segor(a,b):
return a|b
n = int(eval(input()))
st = SegmentTree(n,segor,0)
S = eval(input())
data = [0] * n
for i,si in enumerate(S):
k = ord(si)-ord("a")
data[i] = 1 << k
st.apply(data)
Q = int(eval(input()))
for _ in range(Q):
typo,a,b = input().split()
if typo == "1":
st.update(int(a)-1,1 << (ord(b)-ord("a")))
if typo == "2":
print((bin((st.query(int(a)-1,int(b))))[2:].count("1")))
| 77 | 66 | 1,872 | 1,714 | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
class SegmentTree:
__slots__ = ["ide", "n", "seg", "segfunc"]
def __init__(self, size, func, element):
self.segfunc = func
self.ide = element
# self.size = sizeを超える最小の2冪の数
self.n = 2 ** (n - 1).bit_length()
# 全てのnodeの数は(2*n-1)個
# 上にn-1個,最下段にn個
self.seg = [self.ide] * (2 * self.n - 1)
def apply(self, array):
arraysize = len(array)
# 配列埋め込み
for i in range(arraysize):
self.seg[self.n - 1 + i] = array[i]
# 上にあげる
for i in range(self.n - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.n - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[2 * k + 1], self.seg[2 * k + 2])
def notrec(self, l, r):
# 半開区間[l,r)
l += self.n - 1
r += self.n - 1
vl = vr = self.ide
while l < r:
if l & 1 == 0:
vl = self.segfunc(vl, self.seg[l])
l += 1
if r & 1 == 0:
vr = self.segfunc(vr, self.seg[r - 1])
l = (l - 1) // 2
r = (r - 1) // 2
return self.segfunc(vl, vr)
def makebin(s):
k = ord(s) - ord("a")
# print(1<<k,k)
return 1 << k
def segfunc(a, b):
return a | b
def out(n):
count = 0
while n:
if n & 1 == 1:
print((chr(ord("a") + count)))
n //= 2
count += 1
n = int(eval(input()))
st = SegmentTree(n, segfunc, 0)
S = eval(input())
for i, si in enumerate(S):
st.update(i, makebin(si))
Q = int(eval(input()))
# print(st.seg)
# exit()
for _ in range(Q):
typo, a, b = input().split()
if typo == "1":
st.update(int(a) - 1, makebin(b))
else:
print((bin(st.notrec(int(a) - 1, int(b)))[1:].count("1")))
| #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
class SegmentTree:
__slots__ = ["ide", "n", "seg", "segfunc"]
def __init__(self, size, func, element):
self.segfunc = func
self.ide = element
# self.size = sizeを超える最小の2冪の数
self.n = 2 ** (n - 1).bit_length()
# 全てのnodeの数は(2*n-1)個
# 上にn-1個,最下段にn個
self.seg = [self.ide] * (2 * self.n - 1)
def apply(self, array):
arraysize = len(array)
# 配列埋め込み
for i in range(arraysize):
self.seg[self.n - 1 + i] = array[i]
# 上にあげる
for i in range(self.n - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.n - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[2 * k + 1], self.seg[2 * k + 2])
def query(self, l, r):
# 半開区間[l,r)
l += self.n - 1
r += self.n - 1
vl = vr = self.ide
while l < r:
if l & 1 == 0:
vl = self.segfunc(vl, self.seg[l])
l += 1
if r & 1 == 0:
vr = self.segfunc(vr, self.seg[r - 1])
l = (l - 1) // 2
r = (r - 1) // 2
return self.segfunc(vl, vr)
def segor(a, b):
return a | b
n = int(eval(input()))
st = SegmentTree(n, segor, 0)
S = eval(input())
data = [0] * n
for i, si in enumerate(S):
k = ord(si) - ord("a")
data[i] = 1 << k
st.apply(data)
Q = int(eval(input()))
for _ in range(Q):
typo, a, b = input().split()
if typo == "1":
st.update(int(a) - 1, 1 << (ord(b) - ord("a")))
if typo == "2":
print((bin((st.query(int(a) - 1, int(b))))[2:].count("1")))
| false | 14.285714 | [
"- def notrec(self, l, r):",
"+ def query(self, l, r):",
"-def makebin(s):",
"- k = ord(s) - ord(\"a\")",
"- # print(1<<k,k)",
"- return 1 << k",
"-",
"-",
"-def segfunc(a, b):",
"+def segor(a, b):",
"-def out(n):",
"- count = 0",
"- while n:",
"- if n & 1 == 1:",
"- print((chr(ord(\"a\") + count)))",
"- n //= 2",
"- count += 1",
"-",
"-",
"-st = SegmentTree(n, segfunc, 0)",
"+st = SegmentTree(n, segor, 0)",
"+data = [0] * n",
"- st.update(i, makebin(si))",
"+ k = ord(si) - ord(\"a\")",
"+ data[i] = 1 << k",
"+st.apply(data)",
"-# print(st.seg)",
"-# exit()",
"- st.update(int(a) - 1, makebin(b))",
"- else:",
"- print((bin(st.notrec(int(a) - 1, int(b)))[1:].count(\"1\")))",
"+ st.update(int(a) - 1, 1 << (ord(b) - ord(\"a\")))",
"+ if typo == \"2\":",
"+ print((bin((st.query(int(a) - 1, int(b))))[2:].count(\"1\")))"
] | false | 0.037063 | 0.036861 | 1.00547 | [
"s151945089",
"s237391599"
] |
u992465933 | p02898 | python | s222842819 | s057329121 | 51 | 44 | 11,892 | 11,912 | Accepted | Accepted | 13.73 | def main():
n, k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
count = 0
for i in range(n):
if h[i] >= k:
count += 1
print(count)
if __name__ == '__main__':
main()
| def main():
n,k = list(map(int,input().split()))
H = list(map(int,input().split()))
count = 0
for h in H:
if h >= k:
count += 1
print(count)
if __name__ == '__main__':
main()
| 14 | 13 | 253 | 228 | def main():
n, k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
count = 0
for i in range(n):
if h[i] >= k:
count += 1
print(count)
if __name__ == "__main__":
main()
| def main():
n, k = list(map(int, input().split()))
H = list(map(int, input().split()))
count = 0
for h in H:
if h >= k:
count += 1
print(count)
if __name__ == "__main__":
main()
| false | 7.142857 | [
"- n, k = [int(x) for x in input().split()]",
"- h = [int(x) for x in input().split()]",
"+ n, k = list(map(int, input().split()))",
"+ H = list(map(int, input().split()))",
"- for i in range(n):",
"- if h[i] >= k:",
"+ for h in H:",
"+ if h >= k:"
] | false | 0.007487 | 0.041644 | 0.179781 | [
"s222842819",
"s057329121"
] |
u130900604 | p02713 | python | s123675688 | s661569685 | 651 | 546 | 73,388 | 68,120 | Accepted | Accepted | 16.13 | from math import*;from itertools import*;r=list(range(1,int(eval(input()))+1));print((sum(gcd(a,gcd(b,c))for a,b,c in product(r,r,r)))) | from math import*;r=list(range(1,int(eval(input()))+1));print((sum(gcd(a,gcd(b,c))for a in r for b in r for c in r))) | 1 | 1 | 121 | 103 | from math import *
from itertools import *
r = list(range(1, int(eval(input())) + 1))
print((sum(gcd(a, gcd(b, c)) for a, b, c in product(r, r, r))))
| from math import *
r = list(range(1, int(eval(input())) + 1))
print((sum(gcd(a, gcd(b, c)) for a in r for b in r for c in r)))
| false | 0 | [
"-from itertools import *",
"-print((sum(gcd(a, gcd(b, c)) for a, b, c in product(r, r, r))))",
"+print((sum(gcd(a, gcd(b, c)) for a in r for b in r for c in r)))"
] | false | 0.049413 | 0.188498 | 0.262139 | [
"s123675688",
"s661569685"
] |
u278057806 | p02813 | python | s666032524 | s484558660 | 44 | 32 | 3,064 | 3,060 | Accepted | Accepted | 27.27 | import itertools
N = int(eval(input()))
P = list(map(int, (input().split())))
Q = list(map(int, (input().split())))
a = 0
b = 0
cnt = 0
tmp = sorted(P)
for x in itertools.permutations(tmp):
cnt += 1
if P == list(x):
a = cnt
if Q == list(x):
b = cnt
print((abs(a - b)))
| from itertools import permutations
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
a = 0
b = 0
ans = 0
for i in permutations(list(range(1, N + 1))):
a += 1
b += 1
if i == P:
ans = abs(ans - a)
if i == Q:
ans = abs(ans - b)
print(ans)
| 22 | 21 | 317 | 329 | import itertools
N = int(eval(input()))
P = list(map(int, (input().split())))
Q = list(map(int, (input().split())))
a = 0
b = 0
cnt = 0
tmp = sorted(P)
for x in itertools.permutations(tmp):
cnt += 1
if P == list(x):
a = cnt
if Q == list(x):
b = cnt
print((abs(a - b)))
| from itertools import permutations
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
a = 0
b = 0
ans = 0
for i in permutations(list(range(1, N + 1))):
a += 1
b += 1
if i == P:
ans = abs(ans - a)
if i == Q:
ans = abs(ans - b)
print(ans)
| false | 4.545455 | [
"-import itertools",
"+from itertools import permutations",
"-P = list(map(int, (input().split())))",
"-Q = list(map(int, (input().split())))",
"+P = tuple(map(int, input().split()))",
"+Q = tuple(map(int, input().split()))",
"-cnt = 0",
"-tmp = sorted(P)",
"-for x in itertools.permutations(tmp):",
"- cnt += 1",
"- if P == list(x):",
"- a = cnt",
"- if Q == list(x):",
"- b = cnt",
"-print((abs(a - b)))",
"+ans = 0",
"+for i in permutations(list(range(1, N + 1))):",
"+ a += 1",
"+ b += 1",
"+ if i == P:",
"+ ans = abs(ans - a)",
"+ if i == Q:",
"+ ans = abs(ans - b)",
"+print(ans)"
] | false | 0.199515 | 0.043147 | 4.624042 | [
"s666032524",
"s484558660"
] |
u995102075 | p02971 | python | s387867329 | s395962408 | 675 | 546 | 15,672 | 14,856 | Accepted | Accepted | 19.11 | N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
ans = []
front_max_list, back_max_list = [0], [0]
for i in range(N):
front_max_list.append(max(front_max_list[i], A[i]))
back_max_list.append(max(back_max_list[i], A[N - i - 1]))
for i in range(N):
print((max(front_max_list[i], back_max_list[N - i - 1])))
| N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A_ = sorted(A.copy(), reverse=True)
max_num = [A_[0], A_[1]]
for i in range(N):
if A[i] != max_num[0]:
print((max_num[0]))
else:
print((max_num[1]))
| 12 | 11 | 334 | 235 | N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
ans = []
front_max_list, back_max_list = [0], [0]
for i in range(N):
front_max_list.append(max(front_max_list[i], A[i]))
back_max_list.append(max(back_max_list[i], A[N - i - 1]))
for i in range(N):
print((max(front_max_list[i], back_max_list[N - i - 1])))
| N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A_ = sorted(A.copy(), reverse=True)
max_num = [A_[0], A_[1]]
for i in range(N):
if A[i] != max_num[0]:
print((max_num[0]))
else:
print((max_num[1]))
| false | 8.333333 | [
"-ans = []",
"-front_max_list, back_max_list = [0], [0]",
"+A_ = sorted(A.copy(), reverse=True)",
"+max_num = [A_[0], A_[1]]",
"- front_max_list.append(max(front_max_list[i], A[i]))",
"- back_max_list.append(max(back_max_list[i], A[N - i - 1]))",
"-for i in range(N):",
"- print((max(front_max_list[i], back_max_list[N - i - 1])))",
"+ if A[i] != max_num[0]:",
"+ print((max_num[0]))",
"+ else:",
"+ print((max_num[1]))"
] | false | 0.078937 | 0.036767 | 2.146942 | [
"s387867329",
"s395962408"
] |
u327532412 | p02831 | python | s055684467 | s303261293 | 35 | 30 | 5,052 | 9,108 | Accepted | Accepted | 14.29 | import fractions
A, B = list(map(int, input().split()))
def lcm(a, b):
return (a * b) / fractions.gcd(a, b)
print((int(lcm(A, B)))) | import math
def lcm(A, B):
return int((A * B) / math.gcd(A, B))
A, B = list(map(int, input().split()))
print((lcm(A,B))) | 5 | 5 | 131 | 120 | import fractions
A, B = list(map(int, input().split()))
def lcm(a, b):
return (a * b) / fractions.gcd(a, b)
print((int(lcm(A, B))))
| import math
def lcm(A, B):
return int((A * B) / math.gcd(A, B))
A, B = list(map(int, input().split()))
print((lcm(A, B)))
| false | 0 | [
"-import fractions",
"+import math",
"+",
"+",
"+def lcm(A, B):",
"+ return int((A * B) / math.gcd(A, B))",
"+",
"-",
"-",
"-def lcm(a, b):",
"- return (a * b) / fractions.gcd(a, b)",
"-",
"-",
"-print((int(lcm(A, B))))",
"+print((lcm(A, B)))"
] | false | 0.117125 | 0.038814 | 3.017626 | [
"s055684467",
"s303261293"
] |
u780962115 | p02851 | python | s177380103 | s742350671 | 846 | 382 | 69,000 | 68,184 | Accepted | Accepted | 54.85 | def shaku(K,lists):
ans=0
SUMS=0
index=0
for l in range(len(lists)):
while index < l or index< len(lists) and SUMS +lists[index] < K:
SUMS += lists[index]
index+= 1
ans += index-l
SUMS -= lists[l]
return ans
n,k=list(map(int,input().split()))
lists=list(map(int,input().split()))
uselist=[0 for i in range(n+1)]
for i in range(n):
uselist[i+1]=(uselist[i]+lists[i])
anslist=[0 for i in range(n+1)]
for j in range(1,n+1):
anslist[j]=(uselist[j]-j)%k
dic={}
for i in range(n+1):
if anslist[i] in list(dic.keys()):
dic[anslist[i]].append(i+1)
else:
dic[anslist[i]]=[1+i]
#answerに答えを格納することにする
answer=0
for lis in list(dic.values()):
sublis=[lis[0]]
for a in range(1,len(lis)):
sublis.append(lis[a]-lis[a-1])
P=shaku(k,sublis)
for some in lis:
if some<k:
answer-=1
answer+=P
print(answer) | # Rem of sum is Num
# Reviewing problem
from collections import defaultdict
def cnt_func(X):
res = 0
right = 0
L = len(X)
for i in range(L):
while right+1 < L and X[right+1] < K+X[i]:
right += 1
res += right-i
return res
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.insert(0, 0)
for i in range(1, N+1):
A[i] += A[i-1]
B = [0 for i in range(N+1)]
for i in range(N+1):
B[i] = (A[i]-i) % K
ans = 0
Mod = defaultdict(list)
for i in range(N+1):
Mod[B[i]].append(i)
for X in list(Mod.values()):
ans += cnt_func(X)
print(ans) | 42 | 34 | 957 | 642 | def shaku(K, lists):
ans = 0
SUMS = 0
index = 0
for l in range(len(lists)):
while index < l or index < len(lists) and SUMS + lists[index] < K:
SUMS += lists[index]
index += 1
ans += index - l
SUMS -= lists[l]
return ans
n, k = list(map(int, input().split()))
lists = list(map(int, input().split()))
uselist = [0 for i in range(n + 1)]
for i in range(n):
uselist[i + 1] = uselist[i] + lists[i]
anslist = [0 for i in range(n + 1)]
for j in range(1, n + 1):
anslist[j] = (uselist[j] - j) % k
dic = {}
for i in range(n + 1):
if anslist[i] in list(dic.keys()):
dic[anslist[i]].append(i + 1)
else:
dic[anslist[i]] = [1 + i]
# answerに答えを格納することにする
answer = 0
for lis in list(dic.values()):
sublis = [lis[0]]
for a in range(1, len(lis)):
sublis.append(lis[a] - lis[a - 1])
P = shaku(k, sublis)
for some in lis:
if some < k:
answer -= 1
answer += P
print(answer)
| # Rem of sum is Num
# Reviewing problem
from collections import defaultdict
def cnt_func(X):
res = 0
right = 0
L = len(X)
for i in range(L):
while right + 1 < L and X[right + 1] < K + X[i]:
right += 1
res += right - i
return res
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.insert(0, 0)
for i in range(1, N + 1):
A[i] += A[i - 1]
B = [0 for i in range(N + 1)]
for i in range(N + 1):
B[i] = (A[i] - i) % K
ans = 0
Mod = defaultdict(list)
for i in range(N + 1):
Mod[B[i]].append(i)
for X in list(Mod.values()):
ans += cnt_func(X)
print(ans)
| false | 19.047619 | [
"-def shaku(K, lists):",
"- ans = 0",
"- SUMS = 0",
"- index = 0",
"- for l in range(len(lists)):",
"- while index < l or index < len(lists) and SUMS + lists[index] < K:",
"- SUMS += lists[index]",
"- index += 1",
"- ans += index - l",
"- SUMS -= lists[l]",
"- return ans",
"+# Rem of sum is Num",
"+# Reviewing problem",
"+from collections import defaultdict",
"-n, k = list(map(int, input().split()))",
"-lists = list(map(int, input().split()))",
"-uselist = [0 for i in range(n + 1)]",
"-for i in range(n):",
"- uselist[i + 1] = uselist[i] + lists[i]",
"-anslist = [0 for i in range(n + 1)]",
"-for j in range(1, n + 1):",
"- anslist[j] = (uselist[j] - j) % k",
"-dic = {}",
"-for i in range(n + 1):",
"- if anslist[i] in list(dic.keys()):",
"- dic[anslist[i]].append(i + 1)",
"- else:",
"- dic[anslist[i]] = [1 + i]",
"-# answerに答えを格納することにする",
"-answer = 0",
"-for lis in list(dic.values()):",
"- sublis = [lis[0]]",
"- for a in range(1, len(lis)):",
"- sublis.append(lis[a] - lis[a - 1])",
"- P = shaku(k, sublis)",
"- for some in lis:",
"- if some < k:",
"- answer -= 1",
"- answer += P",
"-print(answer)",
"+def cnt_func(X):",
"+ res = 0",
"+ right = 0",
"+ L = len(X)",
"+ for i in range(L):",
"+ while right + 1 < L and X[right + 1] < K + X[i]:",
"+ right += 1",
"+ res += right - i",
"+ return res",
"+",
"+",
"+N, K = list(map(int, input().split()))",
"+A = list(map(int, input().split()))",
"+A.insert(0, 0)",
"+for i in range(1, N + 1):",
"+ A[i] += A[i - 1]",
"+B = [0 for i in range(N + 1)]",
"+for i in range(N + 1):",
"+ B[i] = (A[i] - i) % K",
"+ans = 0",
"+Mod = defaultdict(list)",
"+for i in range(N + 1):",
"+ Mod[B[i]].append(i)",
"+for X in list(Mod.values()):",
"+ ans += cnt_func(X)",
"+print(ans)"
] | false | 0.037769 | 0.072931 | 0.517871 | [
"s177380103",
"s742350671"
] |
u145950990 | p02984 | python | s570723139 | s790251458 | 140 | 108 | 14,032 | 20,728 | Accepted | Accepted | 22.86 | n = int(eval(input()))
a = list(map(int,input().split()))
ans = [0]
for i in range(n-1):
ans.append(a[i]-ans[i])
ans[0] = a[-1]-(ans[0]+ans[-1])
for i in range(1,n):
ans[i] = (a[i-1]-ans[i-1]//2)*2
print((*ans))
| n = int(eval(input()))
a = list(map(int,input().split()))
x = 0
for i in range(n):
x = a[i] - x
ans = []
ans.append(x)
for i in range(n-1):
ans.append((a[i]-ans[-1]//2)*2)
print((*ans)) | 9 | 10 | 220 | 195 | n = int(eval(input()))
a = list(map(int, input().split()))
ans = [0]
for i in range(n - 1):
ans.append(a[i] - ans[i])
ans[0] = a[-1] - (ans[0] + ans[-1])
for i in range(1, n):
ans[i] = (a[i - 1] - ans[i - 1] // 2) * 2
print((*ans))
| n = int(eval(input()))
a = list(map(int, input().split()))
x = 0
for i in range(n):
x = a[i] - x
ans = []
ans.append(x)
for i in range(n - 1):
ans.append((a[i] - ans[-1] // 2) * 2)
print((*ans))
| false | 10 | [
"-ans = [0]",
"+x = 0",
"+for i in range(n):",
"+ x = a[i] - x",
"+ans = []",
"+ans.append(x)",
"- ans.append(a[i] - ans[i])",
"-ans[0] = a[-1] - (ans[0] + ans[-1])",
"-for i in range(1, n):",
"- ans[i] = (a[i - 1] - ans[i - 1] // 2) * 2",
"+ ans.append((a[i] - ans[-1] // 2) * 2)"
] | false | 0.048524 | 0.047146 | 1.029223 | [
"s570723139",
"s790251458"
] |
u391475811 | p03377 | python | s794799285 | s769712177 | 19 | 17 | 3,316 | 2,940 | Accepted | Accepted | 10.53 | A,B,X=list(map(int,input().split()))
if A <= X <= (A+B):
print("YES")
else:
print("NO") | A,B,X=list(map(int,input().split()))
if A>X or A+B <X:
print("NO")
else:
print("YES") | 5 | 6 | 89 | 89 | A, B, X = list(map(int, input().split()))
if A <= X <= (A + B):
print("YES")
else:
print("NO")
| A, B, X = list(map(int, input().split()))
if A > X or A + B < X:
print("NO")
else:
print("YES")
| false | 16.666667 | [
"-if A <= X <= (A + B):",
"+if A > X or A + B < X:",
"+ print(\"NO\")",
"+else:",
"-else:",
"- print(\"NO\")"
] | false | 0.052277 | 0.049436 | 1.057479 | [
"s794799285",
"s769712177"
] |
u134019875 | p02773 | python | s233759297 | s338355901 | 901 | 484 | 29,616 | 35,424 | Accepted | Accepted | 46.28 | n = int(eval(input()))
L = sorted(eval(input()) for _ in range(n))
s = sorted(set(L))
c = [0] * len(s)
prev = L[0]
cnt = 1
l = 0
for i in range(1, len(L)):
if L[i] == prev:
cnt += 1
else:
c[l] = cnt
l += 1
cnt = 1
prev = L[i]
c[-1] = cnt
m = max(c)
for j in range(len(c)):
if c[j] == m:
print((s[j]))
| n = int(eval(input()))
d = {}
for _ in range(n):
s = str(eval(input()))
d[s] = 1 if s not in d else d[s] + 1
M = max(d.values())
L = []
for k, v in list(d.items()):
if v == M:
L.append(k)
L.sort()
for x in L:
print(x)
| 20 | 14 | 366 | 238 | n = int(eval(input()))
L = sorted(eval(input()) for _ in range(n))
s = sorted(set(L))
c = [0] * len(s)
prev = L[0]
cnt = 1
l = 0
for i in range(1, len(L)):
if L[i] == prev:
cnt += 1
else:
c[l] = cnt
l += 1
cnt = 1
prev = L[i]
c[-1] = cnt
m = max(c)
for j in range(len(c)):
if c[j] == m:
print((s[j]))
| n = int(eval(input()))
d = {}
for _ in range(n):
s = str(eval(input()))
d[s] = 1 if s not in d else d[s] + 1
M = max(d.values())
L = []
for k, v in list(d.items()):
if v == M:
L.append(k)
L.sort()
for x in L:
print(x)
| false | 30 | [
"-L = sorted(eval(input()) for _ in range(n))",
"-s = sorted(set(L))",
"-c = [0] * len(s)",
"-prev = L[0]",
"-cnt = 1",
"-l = 0",
"-for i in range(1, len(L)):",
"- if L[i] == prev:",
"- cnt += 1",
"- else:",
"- c[l] = cnt",
"- l += 1",
"- cnt = 1",
"- prev = L[i]",
"-c[-1] = cnt",
"-m = max(c)",
"-for j in range(len(c)):",
"- if c[j] == m:",
"- print((s[j]))",
"+d = {}",
"+for _ in range(n):",
"+ s = str(eval(input()))",
"+ d[s] = 1 if s not in d else d[s] + 1",
"+M = max(d.values())",
"+L = []",
"+for k, v in list(d.items()):",
"+ if v == M:",
"+ L.append(k)",
"+L.sort()",
"+for x in L:",
"+ print(x)"
] | false | 0.035631 | 0.034478 | 1.033426 | [
"s233759297",
"s338355901"
] |
u670180528 | p03241 | python | s439931977 | s243469367 | 470 | 23 | 40,044 | 3,060 | Accepted | Accepted | 95.11 | n,m=list(map(int,input().split()))
for i in range(m//n+1)[::-1]:
if m%i<1:
print(i)
exit() | n,m=list(map(int,input().split()))
ans=1
for i in range(1,int(m**.5)+1):
if m%i==0:
if i*n<=m and ans<i:
ans=i
if n<=i and ans<m//i:
ans=m//i
print(ans) | 5 | 9 | 93 | 176 | n, m = list(map(int, input().split()))
for i in range(m // n + 1)[::-1]:
if m % i < 1:
print(i)
exit()
| n, m = list(map(int, input().split()))
ans = 1
for i in range(1, int(m**0.5) + 1):
if m % i == 0:
if i * n <= m and ans < i:
ans = i
if n <= i and ans < m // i:
ans = m // i
print(ans)
| false | 44.444444 | [
"-for i in range(m // n + 1)[::-1]:",
"- if m % i < 1:",
"- print(i)",
"- exit()",
"+ans = 1",
"+for i in range(1, int(m**0.5) + 1):",
"+ if m % i == 0:",
"+ if i * n <= m and ans < i:",
"+ ans = i",
"+ if n <= i and ans < m // i:",
"+ ans = m // i",
"+print(ans)"
] | false | 0.075609 | 0.037319 | 2.026019 | [
"s439931977",
"s243469367"
] |
u922449550 | p03732 | python | s741153276 | s581924646 | 1,708 | 218 | 53,648 | 42,988 | Accepted | Accepted | 87.24 | N, W = list(map(int, input().split()))
wv = [list(map(int, input().split())) for i in range(N)]
w1 = wv[0][0]
w_to_idx = {0:0}
idx_to_w = {0:0}
idx_W = 0
def calc():
global w_to_idx, idx_to_w, idx_W
idx = 1
w_max = 0
for i in range(1, N+1):
w = w1*i
for j in range(3*i + 1):
ww = w + j
if ww in w_to_idx:
continue
w_to_idx[ww] = idx
idx_to_w[idx] = ww
if w_max < ww <= W:
w_max = ww
idx_W = idx
idx += 1
calc()
n = len(w_to_idx)
dp = [[0]*n for i in range(N+1)]
for i, (w, v) in enumerate(wv, 1):
for j in range(n):
dp[i][j] = dp[i-1][j]
ww = idx_to_w[j]
if ww >= w and ww-w in w_to_idx:
jj = w_to_idx[ww - w]
dp[i][j] = max(dp[i][j], dp[i-1][jj] + v)
print((max(dp[-1][:idx_W+1]))) | from itertools import accumulate
N, W = list(map(int, input().split()))
wv = {}
w1 = 0
for i in range(N):
w, v = list(map(int, input().split()))
if i == 0:
w1 = w
if w in wv:
wv[w].append(v)
else:
wv[w] = [v]
for w in wv:
wv[w].sort(reverse=True)
wv[w] = [0] + list(accumulate(wv[w]))
w2 = w1+1; w3 = w1+2; w4 = w1+3
for w in [w1, w1+1, w1+2, w1+3]:
if w not in wv:
wv[w] = [0]
ans = 0
for n1 in range(len(wv[w1])):
for n2 in range(len(wv[w2])):
for n3 in range(len(wv[w3])):
for n4 in range(len(wv[w4])):
w = w1*n1 + w2*n2 + w3*n3 + w4*n4
if w <= W:
ans = max(ans, wv[w1][n1]+wv[w2][n2]+wv[w3][n3]+wv[w4][n4])
print(ans) | 36 | 33 | 814 | 714 | N, W = list(map(int, input().split()))
wv = [list(map(int, input().split())) for i in range(N)]
w1 = wv[0][0]
w_to_idx = {0: 0}
idx_to_w = {0: 0}
idx_W = 0
def calc():
global w_to_idx, idx_to_w, idx_W
idx = 1
w_max = 0
for i in range(1, N + 1):
w = w1 * i
for j in range(3 * i + 1):
ww = w + j
if ww in w_to_idx:
continue
w_to_idx[ww] = idx
idx_to_w[idx] = ww
if w_max < ww <= W:
w_max = ww
idx_W = idx
idx += 1
calc()
n = len(w_to_idx)
dp = [[0] * n for i in range(N + 1)]
for i, (w, v) in enumerate(wv, 1):
for j in range(n):
dp[i][j] = dp[i - 1][j]
ww = idx_to_w[j]
if ww >= w and ww - w in w_to_idx:
jj = w_to_idx[ww - w]
dp[i][j] = max(dp[i][j], dp[i - 1][jj] + v)
print((max(dp[-1][: idx_W + 1])))
| from itertools import accumulate
N, W = list(map(int, input().split()))
wv = {}
w1 = 0
for i in range(N):
w, v = list(map(int, input().split()))
if i == 0:
w1 = w
if w in wv:
wv[w].append(v)
else:
wv[w] = [v]
for w in wv:
wv[w].sort(reverse=True)
wv[w] = [0] + list(accumulate(wv[w]))
w2 = w1 + 1
w3 = w1 + 2
w4 = w1 + 3
for w in [w1, w1 + 1, w1 + 2, w1 + 3]:
if w not in wv:
wv[w] = [0]
ans = 0
for n1 in range(len(wv[w1])):
for n2 in range(len(wv[w2])):
for n3 in range(len(wv[w3])):
for n4 in range(len(wv[w4])):
w = w1 * n1 + w2 * n2 + w3 * n3 + w4 * n4
if w <= W:
ans = max(ans, wv[w1][n1] + wv[w2][n2] + wv[w3][n3] + wv[w4][n4])
print(ans)
| false | 8.333333 | [
"+from itertools import accumulate",
"+",
"-wv = [list(map(int, input().split())) for i in range(N)]",
"-w1 = wv[0][0]",
"-w_to_idx = {0: 0}",
"-idx_to_w = {0: 0}",
"-idx_W = 0",
"-",
"-",
"-def calc():",
"- global w_to_idx, idx_to_w, idx_W",
"- idx = 1",
"- w_max = 0",
"- for i in range(1, N + 1):",
"- w = w1 * i",
"- for j in range(3 * i + 1):",
"- ww = w + j",
"- if ww in w_to_idx:",
"- continue",
"- w_to_idx[ww] = idx",
"- idx_to_w[idx] = ww",
"- if w_max < ww <= W:",
"- w_max = ww",
"- idx_W = idx",
"- idx += 1",
"-",
"-",
"-calc()",
"-n = len(w_to_idx)",
"-dp = [[0] * n for i in range(N + 1)]",
"-for i, (w, v) in enumerate(wv, 1):",
"- for j in range(n):",
"- dp[i][j] = dp[i - 1][j]",
"- ww = idx_to_w[j]",
"- if ww >= w and ww - w in w_to_idx:",
"- jj = w_to_idx[ww - w]",
"- dp[i][j] = max(dp[i][j], dp[i - 1][jj] + v)",
"-print((max(dp[-1][: idx_W + 1])))",
"+wv = {}",
"+w1 = 0",
"+for i in range(N):",
"+ w, v = list(map(int, input().split()))",
"+ if i == 0:",
"+ w1 = w",
"+ if w in wv:",
"+ wv[w].append(v)",
"+ else:",
"+ wv[w] = [v]",
"+for w in wv:",
"+ wv[w].sort(reverse=True)",
"+ wv[w] = [0] + list(accumulate(wv[w]))",
"+w2 = w1 + 1",
"+w3 = w1 + 2",
"+w4 = w1 + 3",
"+for w in [w1, w1 + 1, w1 + 2, w1 + 3]:",
"+ if w not in wv:",
"+ wv[w] = [0]",
"+ans = 0",
"+for n1 in range(len(wv[w1])):",
"+ for n2 in range(len(wv[w2])):",
"+ for n3 in range(len(wv[w3])):",
"+ for n4 in range(len(wv[w4])):",
"+ w = w1 * n1 + w2 * n2 + w3 * n3 + w4 * n4",
"+ if w <= W:",
"+ ans = max(ans, wv[w1][n1] + wv[w2][n2] + wv[w3][n3] + wv[w4][n4])",
"+print(ans)"
] | false | 0.040947 | 0.044963 | 0.910683 | [
"s741153276",
"s581924646"
] |
u600402037 | p03309 | python | s570244658 | s226662047 | 254 | 214 | 34,216 | 34,188 | Accepted | Accepted | 15.75 | # coding: utf-8
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
A = np.array(lr())
A -= np.arange(1, N+1)
A.sort()
def check(i):
ret = np.abs(A - A[i]).sum()
return ret
answer = min(check(0), check(-1))
left = 0; right = N-1
l_mid = (left*2 + right) // 3
r_mid = (left + right*2) // 3
while abs(right-left) > 2:
l_mid = (left*2 + right) // 3
r_mid = (left + right*2) // 3
if check(l_mid) < check(r_mid):
right = r_mid
else:
left = l_mid
cand = min(check(l_mid), check(r_mid))
answer = min(answer, cand)
print(answer)
| # coding: utf-8
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
A = np.array(lr(), dtype=np.int32)
A -= np.arange(1, N+1)
answer = np.abs(A - int(np.median(A))).sum()
print(answer)
| 32 | 13 | 692 | 294 | # coding: utf-8
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
A = np.array(lr())
A -= np.arange(1, N + 1)
A.sort()
def check(i):
ret = np.abs(A - A[i]).sum()
return ret
answer = min(check(0), check(-1))
left = 0
right = N - 1
l_mid = (left * 2 + right) // 3
r_mid = (left + right * 2) // 3
while abs(right - left) > 2:
l_mid = (left * 2 + right) // 3
r_mid = (left + right * 2) // 3
if check(l_mid) < check(r_mid):
right = r_mid
else:
left = l_mid
cand = min(check(l_mid), check(r_mid))
answer = min(answer, cand)
print(answer)
| # coding: utf-8
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
A = np.array(lr(), dtype=np.int32)
A -= np.arange(1, N + 1)
answer = np.abs(A - int(np.median(A))).sum()
print(answer)
| false | 59.375 | [
"-A = np.array(lr())",
"+A = np.array(lr(), dtype=np.int32)",
"-A.sort()",
"-",
"-",
"-def check(i):",
"- ret = np.abs(A - A[i]).sum()",
"- return ret",
"-",
"-",
"-answer = min(check(0), check(-1))",
"-left = 0",
"-right = N - 1",
"-l_mid = (left * 2 + right) // 3",
"-r_mid = (left + right * 2) // 3",
"-while abs(right - left) > 2:",
"- l_mid = (left * 2 + right) // 3",
"- r_mid = (left + right * 2) // 3",
"- if check(l_mid) < check(r_mid):",
"- right = r_mid",
"- else:",
"- left = l_mid",
"-cand = min(check(l_mid), check(r_mid))",
"-answer = min(answer, cand)",
"+answer = np.abs(A - int(np.median(A))).sum()"
] | false | 0.213555 | 0.267711 | 0.797706 | [
"s570244658",
"s226662047"
] |
u037430802 | p03837 | python | s047619297 | s275038193 | 684 | 125 | 3,452 | 3,572 | Accepted | Accepted | 81.73 | n,m = list(map(int, input().split()))
INF = 1000*n+1
#edges = [[] for _ in range(m)]
edge = [[INF for _ in range(n)] for _ in range(n)]
d = [[INF for _ in range(n)] for _ in range(n)]
abc = [list(map(int, input().split())) for _ in range(m)]
for a,b,c in abc:
edge[a-1][b-1] = c
edge[b-1][a-1] = c
def dijkstra(i):
#d = [INF for _ in range(n)]
d[i][i] = 0
used = [False] * n
while True:
v = -1
for j in range(n):
if used[j] == False and (v == -1 or d[i][j] < d[i][v]):
v = j
if v == -1:
break
used[v] = True
for k in range(n):
d[i][k] = min(d[i][k], d[i][v] + edge[v][k])
d[k][i] = d[i][k]
for i in range(n):
dijkstra(i)
#print(edge)
#print(d)
ans = 0
for a, b, c in abc:
if d[a-1][b-1] < c:
ans += 1
print(ans)
| import heapq
N, M = list(map(int, input().split()))
es = [[] for _ in range(N)]
INF = float("inf")
for i in range(M):
a, b, c = list(map(int, input().split()))
a, b = a-1, b-1
es[a].append((b,c))
es[b].append((a,c))
def djkstra(start, n, es):
# start:スタート地点のノード
# n:ノード数
# es:edges, ある辺のコスト
# 最初は全部未探索
costs = [INF] * n
costs[start] = 0
checked = [False] * n #調べ終わったノードはTrue
hq = [(0, start)] # スタートからスタートまでのコスト(=0)とスタートの番号
heapq.heapify(hq)
while hq: # キューに残りがある限り
cost, v = heapq.heappop(hq) # 取り出す
if checked[v]:
continue # 既に調べていたら飛ばす
checked[v] = True
costs[v] = cost
for to, c in es[v]: # ノードvから伸びている辺すべてについて
if costs[to] <= cost + c:
continue # 現時点で発覚しているtoまでのコストのほうが、v経由でto行くまでのコストより小さいなら更新せず飛ばす
heapq.heappush(hq, (cost+c, to)) # toに行くまでの最短距離がcost+cに更新される
return costs
min_cost = [[] for _ in range(N)]
for i in range(N):
min_cost[i] = djkstra(i,N,es)
ans = 0
for i in range(len(es)):
for to, c in es[i]:
if min_cost[i][to] < c:
#print("--------")
#print(i,to,c)
ans += 1
print((ans//2))
#print(min_cost) | 42 | 51 | 910 | 1,270 | n, m = list(map(int, input().split()))
INF = 1000 * n + 1
# edges = [[] for _ in range(m)]
edge = [[INF for _ in range(n)] for _ in range(n)]
d = [[INF for _ in range(n)] for _ in range(n)]
abc = [list(map(int, input().split())) for _ in range(m)]
for a, b, c in abc:
edge[a - 1][b - 1] = c
edge[b - 1][a - 1] = c
def dijkstra(i):
# d = [INF for _ in range(n)]
d[i][i] = 0
used = [False] * n
while True:
v = -1
for j in range(n):
if used[j] == False and (v == -1 or d[i][j] < d[i][v]):
v = j
if v == -1:
break
used[v] = True
for k in range(n):
d[i][k] = min(d[i][k], d[i][v] + edge[v][k])
d[k][i] = d[i][k]
for i in range(n):
dijkstra(i)
# print(edge)
# print(d)
ans = 0
for a, b, c in abc:
if d[a - 1][b - 1] < c:
ans += 1
print(ans)
| import heapq
N, M = list(map(int, input().split()))
es = [[] for _ in range(N)]
INF = float("inf")
for i in range(M):
a, b, c = list(map(int, input().split()))
a, b = a - 1, b - 1
es[a].append((b, c))
es[b].append((a, c))
def djkstra(start, n, es):
# start:スタート地点のノード
# n:ノード数
# es:edges, ある辺のコスト
# 最初は全部未探索
costs = [INF] * n
costs[start] = 0
checked = [False] * n # 調べ終わったノードはTrue
hq = [(0, start)] # スタートからスタートまでのコスト(=0)とスタートの番号
heapq.heapify(hq)
while hq: # キューに残りがある限り
cost, v = heapq.heappop(hq) # 取り出す
if checked[v]:
continue # 既に調べていたら飛ばす
checked[v] = True
costs[v] = cost
for to, c in es[v]: # ノードvから伸びている辺すべてについて
if costs[to] <= cost + c:
continue # 現時点で発覚しているtoまでのコストのほうが、v経由でto行くまでのコストより小さいなら更新せず飛ばす
heapq.heappush(hq, (cost + c, to)) # toに行くまでの最短距離がcost+cに更新される
return costs
min_cost = [[] for _ in range(N)]
for i in range(N):
min_cost[i] = djkstra(i, N, es)
ans = 0
for i in range(len(es)):
for to, c in es[i]:
if min_cost[i][to] < c:
# print("--------")
# print(i,to,c)
ans += 1
print((ans // 2))
# print(min_cost)
| false | 17.647059 | [
"-n, m = list(map(int, input().split()))",
"-INF = 1000 * n + 1",
"-# edges = [[] for _ in range(m)]",
"-edge = [[INF for _ in range(n)] for _ in range(n)]",
"-d = [[INF for _ in range(n)] for _ in range(n)]",
"-abc = [list(map(int, input().split())) for _ in range(m)]",
"-for a, b, c in abc:",
"- edge[a - 1][b - 1] = c",
"- edge[b - 1][a - 1] = c",
"+import heapq",
"+",
"+N, M = list(map(int, input().split()))",
"+es = [[] for _ in range(N)]",
"+INF = float(\"inf\")",
"+for i in range(M):",
"+ a, b, c = list(map(int, input().split()))",
"+ a, b = a - 1, b - 1",
"+ es[a].append((b, c))",
"+ es[b].append((a, c))",
"-def dijkstra(i):",
"- # d = [INF for _ in range(n)]",
"- d[i][i] = 0",
"- used = [False] * n",
"- while True:",
"- v = -1",
"- for j in range(n):",
"- if used[j] == False and (v == -1 or d[i][j] < d[i][v]):",
"- v = j",
"- if v == -1:",
"- break",
"- used[v] = True",
"- for k in range(n):",
"- d[i][k] = min(d[i][k], d[i][v] + edge[v][k])",
"- d[k][i] = d[i][k]",
"+def djkstra(start, n, es):",
"+ # start:スタート地点のノード",
"+ # n:ノード数",
"+ # es:edges, ある辺のコスト",
"+ # 最初は全部未探索",
"+ costs = [INF] * n",
"+ costs[start] = 0",
"+ checked = [False] * n # 調べ終わったノードはTrue",
"+ hq = [(0, start)] # スタートからスタートまでのコスト(=0)とスタートの番号",
"+ heapq.heapify(hq)",
"+ while hq: # キューに残りがある限り",
"+ cost, v = heapq.heappop(hq) # 取り出す",
"+ if checked[v]:",
"+ continue # 既に調べていたら飛ばす",
"+ checked[v] = True",
"+ costs[v] = cost",
"+ for to, c in es[v]: # ノードvから伸びている辺すべてについて",
"+ if costs[to] <= cost + c:",
"+ continue # 現時点で発覚しているtoまでのコストのほうが、v経由でto行くまでのコストより小さいなら更新せず飛ばす",
"+ heapq.heappush(hq, (cost + c, to)) # toに行くまでの最短距離がcost+cに更新される",
"+ return costs",
"-for i in range(n):",
"- dijkstra(i)",
"-# print(edge)",
"-# print(d)",
"+min_cost = [[] for _ in range(N)]",
"+for i in range(N):",
"+ min_cost[i] = djkstra(i, N, es)",
"-for a, b, c in abc:",
"- if d[a - 1][b - 1] < c:",
"- ans += 1",
"-print(ans)",
"+for i in range(len(es)):",
"+ for to, c in es[i]:",
"+ if min_cost[i][to] < c:",
"+ # print(i,to,c)",
"+ ans += 1",
"+print((ans // 2))",
"+# print(min_cost)"
] | false | 0.135593 | 0.048472 | 2.797334 | [
"s047619297",
"s275038193"
] |
u271469978 | p02999 | python | s626733929 | s770603790 | 169 | 17 | 39,988 | 2,940 | Accepted | Accepted | 89.94 | x, a = list(map(int, input().split()))
print((0 if x < a else 10)) | x,a=input().split();print(((x>=a)*10)) | 2 | 1 | 59 | 36 | x, a = list(map(int, input().split()))
print((0 if x < a else 10))
| x, a = input().split()
print(((x >= a) * 10))
| false | 50 | [
"-x, a = list(map(int, input().split()))",
"-print((0 if x < a else 10))",
"+x, a = input().split()",
"+print(((x >= a) * 10))"
] | false | 0.142522 | 0.05932 | 2.402603 | [
"s626733929",
"s770603790"
] |
u703442202 | p02781 | python | s827364419 | s107460295 | 216 | 23 | 3,436 | 3,064 | Accepted | Accepted | 89.35 | n = eval(input())
k = int(eval(input()))
dp = [[[0 for i in range(len(n)+1)] for i in range(2)] for i in range(len(n)+1)]
dp[0][0][0] = 1
for a in range(len(n)):
for b in range(2):
for c in range(len(n)):
for i in range(10):
if b ==1:
if i != 0:
dp[a+1][1][c+1] += dp[a][1][c]
else:
dp[a+1][1][c] += dp[a][1][c]
else:
if int(n[a]) > i and i ==0:
dp[a+1][1][c] += dp[a][0][c]
if int(n[a]) > i and i != 0:
dp[a+1][1][c+1] += dp[a][0][c]
if int(n[a]) == i and i ==0:
dp[a+1][0][c] += dp[a][0][c]
if int(n[a]) == i and i !=0:
dp[a+1][0][c+1] += dp[a][0][c]
if len(n) == 1:
if k == 1:
print((int(n)))
if k >= 2:
print((0))
else:
print((dp[-1][0][k] + dp[-1][1][k]))
| n = eval(input())
k = int(eval(input()))
dp = [[[0 for i in range(k+1)] for i in range(2)] for i in range(len(n)+1)]
dp[0][0][0] = 1
for a in range(len(n)):
for b in range(2):
for c in range(k+1):
for i in range(10):
if b ==1:
if c ==k:
if i == 0:
dp[a+1][1][c] += dp[a][1][c]
else:
if i == 0:
dp[a+1][1][c] += dp[a][1][c]
else:
dp[a+1][1][c+1] += dp[a][1][c]
else:
if int(n[a]) > i:
if c == k:
if i == 0:
dp[a+1][1][c] += dp[a][0][c]
else:
if i == 0:
dp[a+1][1][c] += dp[a][0][c]
else:
dp[a+1][1][c+1] += dp[a][0][c]
if int(n[a]) == i:
if c == k:
if i == 0:
dp[a+1][0][c] += dp[a][0][c]
else:
if i == 0:
dp[a+1][0][c] += dp[a][0][c]
else:
dp[a+1][0][c+1] += dp[a][0][c]
print((dp[-1][0][-1] + dp[-1][1][-1]))
| 29 | 40 | 849 | 1,145 | n = eval(input())
k = int(eval(input()))
dp = [[[0 for i in range(len(n) + 1)] for i in range(2)] for i in range(len(n) + 1)]
dp[0][0][0] = 1
for a in range(len(n)):
for b in range(2):
for c in range(len(n)):
for i in range(10):
if b == 1:
if i != 0:
dp[a + 1][1][c + 1] += dp[a][1][c]
else:
dp[a + 1][1][c] += dp[a][1][c]
else:
if int(n[a]) > i and i == 0:
dp[a + 1][1][c] += dp[a][0][c]
if int(n[a]) > i and i != 0:
dp[a + 1][1][c + 1] += dp[a][0][c]
if int(n[a]) == i and i == 0:
dp[a + 1][0][c] += dp[a][0][c]
if int(n[a]) == i and i != 0:
dp[a + 1][0][c + 1] += dp[a][0][c]
if len(n) == 1:
if k == 1:
print((int(n)))
if k >= 2:
print((0))
else:
print((dp[-1][0][k] + dp[-1][1][k]))
| n = eval(input())
k = int(eval(input()))
dp = [[[0 for i in range(k + 1)] for i in range(2)] for i in range(len(n) + 1)]
dp[0][0][0] = 1
for a in range(len(n)):
for b in range(2):
for c in range(k + 1):
for i in range(10):
if b == 1:
if c == k:
if i == 0:
dp[a + 1][1][c] += dp[a][1][c]
else:
if i == 0:
dp[a + 1][1][c] += dp[a][1][c]
else:
dp[a + 1][1][c + 1] += dp[a][1][c]
else:
if int(n[a]) > i:
if c == k:
if i == 0:
dp[a + 1][1][c] += dp[a][0][c]
else:
if i == 0:
dp[a + 1][1][c] += dp[a][0][c]
else:
dp[a + 1][1][c + 1] += dp[a][0][c]
if int(n[a]) == i:
if c == k:
if i == 0:
dp[a + 1][0][c] += dp[a][0][c]
else:
if i == 0:
dp[a + 1][0][c] += dp[a][0][c]
else:
dp[a + 1][0][c + 1] += dp[a][0][c]
print((dp[-1][0][-1] + dp[-1][1][-1]))
| false | 27.5 | [
"-dp = [[[0 for i in range(len(n) + 1)] for i in range(2)] for i in range(len(n) + 1)]",
"+dp = [[[0 for i in range(k + 1)] for i in range(2)] for i in range(len(n) + 1)]",
"- for c in range(len(n)):",
"+ for c in range(k + 1):",
"- if i != 0:",
"- dp[a + 1][1][c + 1] += dp[a][1][c]",
"+ if c == k:",
"+ if i == 0:",
"+ dp[a + 1][1][c] += dp[a][1][c]",
"- dp[a + 1][1][c] += dp[a][1][c]",
"+ if i == 0:",
"+ dp[a + 1][1][c] += dp[a][1][c]",
"+ else:",
"+ dp[a + 1][1][c + 1] += dp[a][1][c]",
"- if int(n[a]) > i and i == 0:",
"- dp[a + 1][1][c] += dp[a][0][c]",
"- if int(n[a]) > i and i != 0:",
"- dp[a + 1][1][c + 1] += dp[a][0][c]",
"- if int(n[a]) == i and i == 0:",
"- dp[a + 1][0][c] += dp[a][0][c]",
"- if int(n[a]) == i and i != 0:",
"- dp[a + 1][0][c + 1] += dp[a][0][c]",
"-if len(n) == 1:",
"- if k == 1:",
"- print((int(n)))",
"- if k >= 2:",
"- print((0))",
"-else:",
"- print((dp[-1][0][k] + dp[-1][1][k]))",
"+ if int(n[a]) > i:",
"+ if c == k:",
"+ if i == 0:",
"+ dp[a + 1][1][c] += dp[a][0][c]",
"+ else:",
"+ if i == 0:",
"+ dp[a + 1][1][c] += dp[a][0][c]",
"+ else:",
"+ dp[a + 1][1][c + 1] += dp[a][0][c]",
"+ if int(n[a]) == i:",
"+ if c == k:",
"+ if i == 0:",
"+ dp[a + 1][0][c] += dp[a][0][c]",
"+ else:",
"+ if i == 0:",
"+ dp[a + 1][0][c] += dp[a][0][c]",
"+ else:",
"+ dp[a + 1][0][c + 1] += dp[a][0][c]",
"+print((dp[-1][0][-1] + dp[-1][1][-1]))"
] | false | 0.115675 | 0.037677 | 3.070199 | [
"s827364419",
"s107460295"
] |
u983918956 | p03200 | python | s501480431 | s393925262 | 69 | 46 | 4,840 | 3,500 | Accepted | Accepted | 33.33 | S = list(eval(input()))
count_B = 0
ans = 0
for i in range(len(S)):
if S[i] == "B":
count_B += 1
elif S[i] == "W":
ans += count_B
print(ans) | S = eval(input())
ans = 0
cnt = 0
for s in S:
if s == "B":
cnt += 1
else:
ans += cnt
print(ans) | 9 | 9 | 166 | 121 | S = list(eval(input()))
count_B = 0
ans = 0
for i in range(len(S)):
if S[i] == "B":
count_B += 1
elif S[i] == "W":
ans += count_B
print(ans)
| S = eval(input())
ans = 0
cnt = 0
for s in S:
if s == "B":
cnt += 1
else:
ans += cnt
print(ans)
| false | 0 | [
"-S = list(eval(input()))",
"-count_B = 0",
"+S = eval(input())",
"-for i in range(len(S)):",
"- if S[i] == \"B\":",
"- count_B += 1",
"- elif S[i] == \"W\":",
"- ans += count_B",
"+cnt = 0",
"+for s in S:",
"+ if s == \"B\":",
"+ cnt += 1",
"+ else:",
"+ ans += cnt"
] | false | 0.036234 | 0.038506 | 0.941009 | [
"s501480431",
"s393925262"
] |
u644907318 | p03959 | python | s828420029 | s614080281 | 168 | 117 | 18,924 | 98,752 | Accepted | Accepted | 30.36 | p = 10**9+7
N = int(eval(input()))
T = list(map(int,input().split()))
A = list(map(int,input().split()))
H = [0 for _ in range(N)]
cnt = 1
H[0] = T[0]
for i in range(1,N):
if T[i]>T[i-1]:
H[i] = T[i]
if H[-1]>0 and H[-1]!=A[-1]:
cnt = 0
else:
H[-1] = A[-1]
for i in range(-2,-N-1,-1):
if H[i]==0 and A[i]>A[i+1]:
if A[i]<=T[i]:
H[i] = A[i]
else:
cnt = 0
break
elif H[i]>0 and A[i]>A[i+1]:
if H[i]==A[i]:continue
else:
cnt = 0
break
if cnt==1:
for i in range(1,N-1):
if H[i]==0:
cnt = (cnt*min(T[i],A[i]))%p
print(cnt) | p = 10**9+7
N = int(eval(input()))
T = list(map(int,input().split()))
A = list(map(int,input().split()))
H = [0 for _ in range(N)]
flag = 0
if T[N-1]!=A[0]:
flag = 1
hmax = A[0]
if flag==0:
indmaxT=0
H[0] = T[0]
for i in range(1,N):
if T[i]>T[i-1]:
H[i] = T[i]
if H[i]==hmax:
indmaxT = i
break
indmaxA = N-1
H[N-1] = A[N-1]
for i in range(N-2,-1,-1):
if A[i]>A[i+1]:
H[i]=A[i]
if H[i]==hmax:
indmaxA = i
break
if indmaxA<indmaxT:
flag = 1
if flag==1:
print((0))
else:
cnt = 1
cur = 0
for i in range(1,indmaxT):
if H[i]==0:
cnt = (cnt*H[cur])%p
elif H[i]>0:
cur = i
cur = N-1
for i in range(N-2,indmaxA,-1):
if H[i]==0:
cnt = (cnt*H[cur])%p
elif H[i]>0:
cur = i
for i in range(indmaxT+1,indmaxA):
cnt = (cnt*hmax)%p
print(cnt) | 31 | 47 | 750 | 1,051 | p = 10**9 + 7
N = int(eval(input()))
T = list(map(int, input().split()))
A = list(map(int, input().split()))
H = [0 for _ in range(N)]
cnt = 1
H[0] = T[0]
for i in range(1, N):
if T[i] > T[i - 1]:
H[i] = T[i]
if H[-1] > 0 and H[-1] != A[-1]:
cnt = 0
else:
H[-1] = A[-1]
for i in range(-2, -N - 1, -1):
if H[i] == 0 and A[i] > A[i + 1]:
if A[i] <= T[i]:
H[i] = A[i]
else:
cnt = 0
break
elif H[i] > 0 and A[i] > A[i + 1]:
if H[i] == A[i]:
continue
else:
cnt = 0
break
if cnt == 1:
for i in range(1, N - 1):
if H[i] == 0:
cnt = (cnt * min(T[i], A[i])) % p
print(cnt)
| p = 10**9 + 7
N = int(eval(input()))
T = list(map(int, input().split()))
A = list(map(int, input().split()))
H = [0 for _ in range(N)]
flag = 0
if T[N - 1] != A[0]:
flag = 1
hmax = A[0]
if flag == 0:
indmaxT = 0
H[0] = T[0]
for i in range(1, N):
if T[i] > T[i - 1]:
H[i] = T[i]
if H[i] == hmax:
indmaxT = i
break
indmaxA = N - 1
H[N - 1] = A[N - 1]
for i in range(N - 2, -1, -1):
if A[i] > A[i + 1]:
H[i] = A[i]
if H[i] == hmax:
indmaxA = i
break
if indmaxA < indmaxT:
flag = 1
if flag == 1:
print((0))
else:
cnt = 1
cur = 0
for i in range(1, indmaxT):
if H[i] == 0:
cnt = (cnt * H[cur]) % p
elif H[i] > 0:
cur = i
cur = N - 1
for i in range(N - 2, indmaxA, -1):
if H[i] == 0:
cnt = (cnt * H[cur]) % p
elif H[i] > 0:
cur = i
for i in range(indmaxT + 1, indmaxA):
cnt = (cnt * hmax) % p
print(cnt)
| false | 34.042553 | [
"-cnt = 1",
"-H[0] = T[0]",
"-for i in range(1, N):",
"- if T[i] > T[i - 1]:",
"- H[i] = T[i]",
"-if H[-1] > 0 and H[-1] != A[-1]:",
"- cnt = 0",
"+flag = 0",
"+if T[N - 1] != A[0]:",
"+ flag = 1",
"+hmax = A[0]",
"+if flag == 0:",
"+ indmaxT = 0",
"+ H[0] = T[0]",
"+ for i in range(1, N):",
"+ if T[i] > T[i - 1]:",
"+ H[i] = T[i]",
"+ if H[i] == hmax:",
"+ indmaxT = i",
"+ break",
"+ indmaxA = N - 1",
"+ H[N - 1] = A[N - 1]",
"+ for i in range(N - 2, -1, -1):",
"+ if A[i] > A[i + 1]:",
"+ H[i] = A[i]",
"+ if H[i] == hmax:",
"+ indmaxA = i",
"+ break",
"+ if indmaxA < indmaxT:",
"+ flag = 1",
"+if flag == 1:",
"+ print((0))",
"- H[-1] = A[-1]",
"- for i in range(-2, -N - 1, -1):",
"- if H[i] == 0 and A[i] > A[i + 1]:",
"- if A[i] <= T[i]:",
"- H[i] = A[i]",
"- else:",
"- cnt = 0",
"- break",
"- elif H[i] > 0 and A[i] > A[i + 1]:",
"- if H[i] == A[i]:",
"- continue",
"- else:",
"- cnt = 0",
"- break",
"- if cnt == 1:",
"- for i in range(1, N - 1):",
"- if H[i] == 0:",
"- cnt = (cnt * min(T[i], A[i])) % p",
"-print(cnt)",
"+ cnt = 1",
"+ cur = 0",
"+ for i in range(1, indmaxT):",
"+ if H[i] == 0:",
"+ cnt = (cnt * H[cur]) % p",
"+ elif H[i] > 0:",
"+ cur = i",
"+ cur = N - 1",
"+ for i in range(N - 2, indmaxA, -1):",
"+ if H[i] == 0:",
"+ cnt = (cnt * H[cur]) % p",
"+ elif H[i] > 0:",
"+ cur = i",
"+ for i in range(indmaxT + 1, indmaxA):",
"+ cnt = (cnt * hmax) % p",
"+ print(cnt)"
] | false | 0.037695 | 0.066947 | 0.563059 | [
"s828420029",
"s614080281"
] |
u254871849 | p03806 | python | s760846028 | s028031271 | 1,562 | 168 | 71,132 | 13,924 | Accepted | Accepted | 89.24 | import sys
INF = float('inf')
n, ma, mb = list(map(int, sys.stdin.readline().split()))
a, b, c = [], [], []
for _ in range(n):
ai, bi, ci = list(map(int, sys.stdin.readline().split()))
a.append(ai); b.append(bi); c.append(ci)
def main():
sa = sum(a)
sb = sum(b)
res = [[[INF] * (sb + 1) for _ in range(sa + 1)] for _ in range(n + 1)]
res[0][0][0] = 0
for i in range(n):
for j in range(sa + 1):
for k in range(sb + 1):
if j >= a[i] and k >= b[i]:
res[i+1][j][k] = min(res[i][j-a[i]][k-b[i]] + c[i], res[i][j][k])
else:
res[i+1][j][k] = res[i][j][k]
ans = INF
for i in range(1, min(sa//ma, sb//mb)+1):
ans = min(ans, res[n][ma * i][mb * i])
if ans == INF:
return -1
else:
return ans
if __name__ == '__main__':
ans = main()
print(ans) | import sys
import numpy as np
I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, ma, mb = I[:3]
abc = I[3:].reshape(n, 3)
def main():
sa, sb = np.sum(abc, axis=0)[:2]
res = np.full((sa+1, sb+1), np.inf)
res[0, 0] = 0
for a, b, c in abc:
res[a:, b:] = np.minimum(res[a:, b:], res[:-a, :-b] + c)
ans = np.inf
for i in range(1, min(sa//ma, sb//mb) + 1):
ans = np.minimum(ans, res[ma * i, mb * i])
if ans == np.inf:
return -1
return int(ans)
if __name__ == '__main__':
ans = main()
print(ans) | 34 | 26 | 929 | 602 | import sys
INF = float("inf")
n, ma, mb = list(map(int, sys.stdin.readline().split()))
a, b, c = [], [], []
for _ in range(n):
ai, bi, ci = list(map(int, sys.stdin.readline().split()))
a.append(ai)
b.append(bi)
c.append(ci)
def main():
sa = sum(a)
sb = sum(b)
res = [[[INF] * (sb + 1) for _ in range(sa + 1)] for _ in range(n + 1)]
res[0][0][0] = 0
for i in range(n):
for j in range(sa + 1):
for k in range(sb + 1):
if j >= a[i] and k >= b[i]:
res[i + 1][j][k] = min(
res[i][j - a[i]][k - b[i]] + c[i], res[i][j][k]
)
else:
res[i + 1][j][k] = res[i][j][k]
ans = INF
for i in range(1, min(sa // ma, sb // mb) + 1):
ans = min(ans, res[n][ma * i][mb * i])
if ans == INF:
return -1
else:
return ans
if __name__ == "__main__":
ans = main()
print(ans)
| import sys
import numpy as np
I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, ma, mb = I[:3]
abc = I[3:].reshape(n, 3)
def main():
sa, sb = np.sum(abc, axis=0)[:2]
res = np.full((sa + 1, sb + 1), np.inf)
res[0, 0] = 0
for a, b, c in abc:
res[a:, b:] = np.minimum(res[a:, b:], res[:-a, :-b] + c)
ans = np.inf
for i in range(1, min(sa // ma, sb // mb) + 1):
ans = np.minimum(ans, res[ma * i, mb * i])
if ans == np.inf:
return -1
return int(ans)
if __name__ == "__main__":
ans = main()
print(ans)
| false | 23.529412 | [
"+import numpy as np",
"-INF = float(\"inf\")",
"-n, ma, mb = list(map(int, sys.stdin.readline().split()))",
"-a, b, c = [], [], []",
"-for _ in range(n):",
"- ai, bi, ci = list(map(int, sys.stdin.readline().split()))",
"- a.append(ai)",
"- b.append(bi)",
"- c.append(ci)",
"+I = np.array(sys.stdin.read().split(), dtype=np.int64)",
"+n, ma, mb = I[:3]",
"+abc = I[3:].reshape(n, 3)",
"- sa = sum(a)",
"- sb = sum(b)",
"- res = [[[INF] * (sb + 1) for _ in range(sa + 1)] for _ in range(n + 1)]",
"- res[0][0][0] = 0",
"- for i in range(n):",
"- for j in range(sa + 1):",
"- for k in range(sb + 1):",
"- if j >= a[i] and k >= b[i]:",
"- res[i + 1][j][k] = min(",
"- res[i][j - a[i]][k - b[i]] + c[i], res[i][j][k]",
"- )",
"- else:",
"- res[i + 1][j][k] = res[i][j][k]",
"- ans = INF",
"+ sa, sb = np.sum(abc, axis=0)[:2]",
"+ res = np.full((sa + 1, sb + 1), np.inf)",
"+ res[0, 0] = 0",
"+ for a, b, c in abc:",
"+ res[a:, b:] = np.minimum(res[a:, b:], res[:-a, :-b] + c)",
"+ ans = np.inf",
"- ans = min(ans, res[n][ma * i][mb * i])",
"- if ans == INF:",
"+ ans = np.minimum(ans, res[ma * i, mb * i])",
"+ if ans == np.inf:",
"- else:",
"- return ans",
"+ return int(ans)"
] | false | 0.092054 | 0.333684 | 0.275872 | [
"s760846028",
"s028031271"
] |
u088552457 | p03262 | python | s936744908 | s207731028 | 121 | 95 | 15,020 | 16,244 | Accepted | Accepted | 21.49 | N, X = list(map(int, input().split()))
a = list(map(int, input().split()))
m = []
for aa in a:
m.append(abs(X-aa))
ans = 0
import fractions
for i, g in enumerate(m):
ans = fractions.gcd(ans, g)
print(ans) | def main():
n,m = input_list()
x = input_list()
if len(x) == 1:
print((abs(x[0] - m)))
exit(0)
diffs = []
for i in range(len(x)):
d = abs(m - x[i])
diffs.append(d)
print((gcd_list(diffs)))
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
# 2で割り切れる回数
def divide_two(arg):
c = 0
while True:
if c >= 2:
break
if arg % 2 != 0:
break
arg //= 2
c += 1
return c
import math
import fractions
import collections
from functools import reduce
main() | 13 | 47 | 219 | 871 | N, X = list(map(int, input().split()))
a = list(map(int, input().split()))
m = []
for aa in a:
m.append(abs(X - aa))
ans = 0
import fractions
for i, g in enumerate(m):
ans = fractions.gcd(ans, g)
print(ans)
| def main():
n, m = input_list()
x = input_list()
if len(x) == 1:
print((abs(x[0] - m)))
exit(0)
diffs = []
for i in range(len(x)):
d = abs(m - x[i])
diffs.append(d)
print((gcd_list(diffs)))
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
# 2で割り切れる回数
def divide_two(arg):
c = 0
while True:
if c >= 2:
break
if arg % 2 != 0:
break
arg //= 2
c += 1
return c
import math
import fractions
import collections
from functools import reduce
main()
| false | 72.340426 | [
"-N, X = list(map(int, input().split()))",
"-a = list(map(int, input().split()))",
"-m = []",
"-for aa in a:",
"- m.append(abs(X - aa))",
"-ans = 0",
"+def main():",
"+ n, m = input_list()",
"+ x = input_list()",
"+ if len(x) == 1:",
"+ print((abs(x[0] - m)))",
"+ exit(0)",
"+ diffs = []",
"+ for i in range(len(x)):",
"+ d = abs(m - x[i])",
"+ diffs.append(d)",
"+ print((gcd_list(diffs)))",
"+",
"+",
"+def input_list():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def input_list_str():",
"+ return list(map(str, input().split()))",
"+",
"+",
"+def lcm_base(x, y):",
"+ return (x * y) // fractions.gcd(x, y)",
"+",
"+",
"+def lcm_list(numbers):",
"+ return reduce(lcm_base, numbers, 1)",
"+",
"+",
"+def gcd(*numbers):",
"+ return reduce(fractions.gcd, numbers)",
"+",
"+",
"+def gcd_list(numbers):",
"+ return reduce(fractions.gcd, numbers)",
"+",
"+",
"+# 2で割り切れる回数",
"+def divide_two(arg):",
"+ c = 0",
"+ while True:",
"+ if c >= 2:",
"+ break",
"+ if arg % 2 != 0:",
"+ break",
"+ arg //= 2",
"+ c += 1",
"+ return c",
"+",
"+",
"+import math",
"+import collections",
"+from functools import reduce",
"-for i, g in enumerate(m):",
"- ans = fractions.gcd(ans, g)",
"-print(ans)",
"+main()"
] | false | 0.048593 | 0.103276 | 0.470517 | [
"s936744908",
"s207731028"
] |
u619379081 | p03291 | python | s267398243 | s794135520 | 181 | 71 | 40,304 | 3,188 | Accepted | Accepted | 60.77 | s = eval(input())
count = 0
a, c, q = 0, 0, 0
n = len(s)
for i in range(n):
if s[i] == 'C':
c += 1
elif s[i] == '?':
q += 1
else:
continue
c = 3 * c + q
p = pow(3, q-3)
for i in range(n):
if s[i] == 'A':
a += 3
elif s[i] == 'C':
c -= 3
elif s[i] == 'B':
count += 3*a*c
else:
c -= 1
count += a*c
a += 1
print((int(count*p) % 1000000007)) | s = eval(input())
count = 0
a = 0
q = s.count('?')
c = 3 * s.count('C') + q
p = pow(3, q-3)
for i in range(len(s)):
if s[i] == 'A':
a += 3
elif s[i] == 'C':
c -= 3
elif s[i] == 'B':
count += 3*a*c
else:
c -= 1
count += a*c
a += 1
print((int(count*p) % 1000000007)) | 25 | 18 | 452 | 337 | s = eval(input())
count = 0
a, c, q = 0, 0, 0
n = len(s)
for i in range(n):
if s[i] == "C":
c += 1
elif s[i] == "?":
q += 1
else:
continue
c = 3 * c + q
p = pow(3, q - 3)
for i in range(n):
if s[i] == "A":
a += 3
elif s[i] == "C":
c -= 3
elif s[i] == "B":
count += 3 * a * c
else:
c -= 1
count += a * c
a += 1
print((int(count * p) % 1000000007))
| s = eval(input())
count = 0
a = 0
q = s.count("?")
c = 3 * s.count("C") + q
p = pow(3, q - 3)
for i in range(len(s)):
if s[i] == "A":
a += 3
elif s[i] == "C":
c -= 3
elif s[i] == "B":
count += 3 * a * c
else:
c -= 1
count += a * c
a += 1
print((int(count * p) % 1000000007))
| false | 28 | [
"-a, c, q = 0, 0, 0",
"-n = len(s)",
"-for i in range(n):",
"- if s[i] == \"C\":",
"- c += 1",
"- elif s[i] == \"?\":",
"- q += 1",
"- else:",
"- continue",
"-c = 3 * c + q",
"+a = 0",
"+q = s.count(\"?\")",
"+c = 3 * s.count(\"C\") + q",
"-for i in range(n):",
"+for i in range(len(s)):"
] | false | 0.035884 | 0.035211 | 1.019105 | [
"s267398243",
"s794135520"
] |
u844646164 | p02888 | python | s469868359 | s353673353 | 1,962 | 1,745 | 51,292 | 51,804 | Accepted | Accepted | 11.06 | import bisect
from bisect import bisect_left
n = int(eval(input()))
l = list(map(int, input().split()))
l = sorted(l)
ans = 0
for i in range(n):
for j in range(n-1, i, -1):
s = l[i]+l[j]
ans += bisect_left(l[j+1:n], s)
print(ans)
| import bisect
N = int(eval(input()))
L = list(map(int, input().split()))
L = sorted(L)
ans = 0
for i in range(N):
for j in range(i+1, N):
idx = bisect.bisect_left(L[j+1:], L[i]+L[j])
ans += idx
print(ans)
| 13 | 12 | 248 | 226 | import bisect
from bisect import bisect_left
n = int(eval(input()))
l = list(map(int, input().split()))
l = sorted(l)
ans = 0
for i in range(n):
for j in range(n - 1, i, -1):
s = l[i] + l[j]
ans += bisect_left(l[j + 1 : n], s)
print(ans)
| import bisect
N = int(eval(input()))
L = list(map(int, input().split()))
L = sorted(L)
ans = 0
for i in range(N):
for j in range(i + 1, N):
idx = bisect.bisect_left(L[j + 1 :], L[i] + L[j])
ans += idx
print(ans)
| false | 7.692308 | [
"-from bisect import bisect_left",
"-n = int(eval(input()))",
"-l = list(map(int, input().split()))",
"-l = sorted(l)",
"+N = int(eval(input()))",
"+L = list(map(int, input().split()))",
"+L = sorted(L)",
"-for i in range(n):",
"- for j in range(n - 1, i, -1):",
"- s = l[i] + l[j]",
"- ans += bisect_left(l[j + 1 : n], s)",
"+for i in range(N):",
"+ for j in range(i + 1, N):",
"+ idx = bisect.bisect_left(L[j + 1 :], L[i] + L[j])",
"+ ans += idx"
] | false | 0.035919 | 0.036458 | 0.985216 | [
"s469868359",
"s353673353"
] |
u936985471 | p03994 | python | s469648374 | s599977258 | 74 | 67 | 4,156 | 4,152 | Accepted | Accepted | 9.46 | s=list(eval(input()))
K=int(eval(input()))
def calcCostToGetA(char):
if char=='a':
return 0
return (ord("z")+1)-ord(char)
for i in range(len(s)):
cost=calcCostToGetA(s[i])
if cost<=K:
s[i]='a'
K-=cost
if K==0:
break
if K>0:
s[-1]=chr(ord(s[-1])+K%26)
print(("".join(s))) | # 頭から順にaに変えていく
import sys
readline = sys.stdin.readline
S = list(readline().rstrip())
K = int(readline())
z = ord("z")
for i in range(len(S) - 1):
# aにするためのコストを求める
if S[i] == "a":
continue
cost = z + 1 - ord(S[i])
if cost <= K:
S[i] = "a"
K -= cost
K %= 26
nex = ord(S[-1]) + K
if nex > ord("z"):
nex -= 26
S[-1] = chr(nex)
print(("".join(S)))
| 20 | 25 | 313 | 393 | s = list(eval(input()))
K = int(eval(input()))
def calcCostToGetA(char):
if char == "a":
return 0
return (ord("z") + 1) - ord(char)
for i in range(len(s)):
cost = calcCostToGetA(s[i])
if cost <= K:
s[i] = "a"
K -= cost
if K == 0:
break
if K > 0:
s[-1] = chr(ord(s[-1]) + K % 26)
print(("".join(s)))
| # 頭から順にaに変えていく
import sys
readline = sys.stdin.readline
S = list(readline().rstrip())
K = int(readline())
z = ord("z")
for i in range(len(S) - 1):
# aにするためのコストを求める
if S[i] == "a":
continue
cost = z + 1 - ord(S[i])
if cost <= K:
S[i] = "a"
K -= cost
K %= 26
nex = ord(S[-1]) + K
if nex > ord("z"):
nex -= 26
S[-1] = chr(nex)
print(("".join(S)))
| false | 20 | [
"-s = list(eval(input()))",
"-K = int(eval(input()))",
"+# 頭から順にaに変えていく",
"+import sys",
"-",
"-def calcCostToGetA(char):",
"- if char == \"a\":",
"- return 0",
"- return (ord(\"z\") + 1) - ord(char)",
"-",
"-",
"-for i in range(len(s)):",
"- cost = calcCostToGetA(s[i])",
"+readline = sys.stdin.readline",
"+S = list(readline().rstrip())",
"+K = int(readline())",
"+z = ord(\"z\")",
"+for i in range(len(S) - 1):",
"+ # aにするためのコストを求める",
"+ if S[i] == \"a\":",
"+ continue",
"+ cost = z + 1 - ord(S[i])",
"- s[i] = \"a\"",
"+ S[i] = \"a\"",
"- if K == 0:",
"- break",
"-if K > 0:",
"- s[-1] = chr(ord(s[-1]) + K % 26)",
"-print((\"\".join(s)))",
"+K %= 26",
"+nex = ord(S[-1]) + K",
"+if nex > ord(\"z\"):",
"+ nex -= 26",
"+S[-1] = chr(nex)",
"+print((\"\".join(S)))"
] | false | 0.047711 | 0.047858 | 0.996913 | [
"s469648374",
"s599977258"
] |
u588341295 | p03722 | python | s338834609 | s591888690 | 848 | 594 | 3,404 | 3,404 | Accepted | Accepted | 29.95 | # -*- coding: utf-8 -*-
"""
・ベルマンフォード
"""
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
N, M = list(map(int, input().split()))
edges = [None] * M
for i in range(M):
a, b, c = list(map(int, input().split()))
# 0-indexed
# コストの正負を逆転させれば最短経路問題として処理できる
edges[i] = (a-1, b-1, -c)
def bellman_ford(N: int, edges: list, start: int) -> list:
# 頂点[ある始点からの最短距離]
# (経路自体を知りたい時はここに前の頂点も持たせる)
verts = [float('inf')] * N
verts[start] = 0
# 各辺によるコストの置き換えを頂点数N-1回繰り返す
for i in range(N-1):
for src, dest, cost in edges:
verts[dest] = min(verts[src] + cost, verts[dest])
# 無限に減らせる場所がないか確認
for i in range(N):
for src, dest, cost in edges:
if verts[src] + cost < verts[dest]:
verts[dest] = verts[src] + cost
if dest == N-1:
# 頂点Nがそれに該当していたら空リストを返却
return []
# 問題なければ頂点リストを返却
return verts
verts = bellman_ford(N, edges, 0)
if not verts:
print('inf')
else:
# 正負を戻して出力
print((-verts[N-1]))
| # -*- coding: utf-8 -*-
"""
・ベルマンフォード
"""
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
N, M = list(map(int, input().split()))
edges = [None] * M
for i in range(M):
a, b, c = list(map(int, input().split()))
# 0-indexed
# コストの正負を逆転させれば最短経路問題として処理できる
edges[i] = (a-1, b-1, -c)
def bellman_ford(N: int, edges: list, start: int) -> list:
# 頂点[ある始点からの最短距離]
# (経路自体を知りたい時はここに前の頂点も持たせる)
verts = [float('inf')] * N
verts[start] = 0
# 各辺によるコストの置き換えを頂点数N-1回繰り返す
for i in range(N-1):
for src, dest, cost in edges:
verts[dest] = min(verts[src] + cost, verts[dest])
# 無限に減らせる場所がないか確認
for src, dest, cost in edges:
if verts[src] + cost < verts[dest]:
verts[dest] = verts[src] + cost
if dest == N-1:
# 頂点Nがそれに該当していたら空リストを返却
return []
# 問題なければ頂点リストを返却
return verts
verts = bellman_ford(N, edges, 0)
if not verts:
print('inf')
else:
# 正負を戻して出力
print((-verts[N-1]))
| 45 | 44 | 1,128 | 1,080 | # -*- coding: utf-8 -*-
"""
・ベルマンフォード
"""
import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10**9)
N, M = list(map(int, input().split()))
edges = [None] * M
for i in range(M):
a, b, c = list(map(int, input().split()))
# 0-indexed
# コストの正負を逆転させれば最短経路問題として処理できる
edges[i] = (a - 1, b - 1, -c)
def bellman_ford(N: int, edges: list, start: int) -> list:
# 頂点[ある始点からの最短距離]
# (経路自体を知りたい時はここに前の頂点も持たせる)
verts = [float("inf")] * N
verts[start] = 0
# 各辺によるコストの置き換えを頂点数N-1回繰り返す
for i in range(N - 1):
for src, dest, cost in edges:
verts[dest] = min(verts[src] + cost, verts[dest])
# 無限に減らせる場所がないか確認
for i in range(N):
for src, dest, cost in edges:
if verts[src] + cost < verts[dest]:
verts[dest] = verts[src] + cost
if dest == N - 1:
# 頂点Nがそれに該当していたら空リストを返却
return []
# 問題なければ頂点リストを返却
return verts
verts = bellman_ford(N, edges, 0)
if not verts:
print("inf")
else:
# 正負を戻して出力
print((-verts[N - 1]))
| # -*- coding: utf-8 -*-
"""
・ベルマンフォード
"""
import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10**9)
N, M = list(map(int, input().split()))
edges = [None] * M
for i in range(M):
a, b, c = list(map(int, input().split()))
# 0-indexed
# コストの正負を逆転させれば最短経路問題として処理できる
edges[i] = (a - 1, b - 1, -c)
def bellman_ford(N: int, edges: list, start: int) -> list:
# 頂点[ある始点からの最短距離]
# (経路自体を知りたい時はここに前の頂点も持たせる)
verts = [float("inf")] * N
verts[start] = 0
# 各辺によるコストの置き換えを頂点数N-1回繰り返す
for i in range(N - 1):
for src, dest, cost in edges:
verts[dest] = min(verts[src] + cost, verts[dest])
# 無限に減らせる場所がないか確認
for src, dest, cost in edges:
if verts[src] + cost < verts[dest]:
verts[dest] = verts[src] + cost
if dest == N - 1:
# 頂点Nがそれに該当していたら空リストを返却
return []
# 問題なければ頂点リストを返却
return verts
verts = bellman_ford(N, edges, 0)
if not verts:
print("inf")
else:
# 正負を戻して出力
print((-verts[N - 1]))
| false | 2.222222 | [
"- for i in range(N):",
"- for src, dest, cost in edges:",
"- if verts[src] + cost < verts[dest]:",
"- verts[dest] = verts[src] + cost",
"- if dest == N - 1:",
"- # 頂点Nがそれに該当していたら空リストを返却",
"- return []",
"+ for src, dest, cost in edges:",
"+ if verts[src] + cost < verts[dest]:",
"+ verts[dest] = verts[src] + cost",
"+ if dest == N - 1:",
"+ # 頂点Nがそれに該当していたら空リストを返却",
"+ return []"
] | false | 0.040252 | 0.036662 | 1.097916 | [
"s338834609",
"s591888690"
] |
u301624971 | p03371 | python | s436426449 | s835458335 | 102 | 53 | 3,064 | 3,064 | Accepted | Accepted | 48.04 | A, B, C, X, Y = list(map(int, input().split()))
MAX = max(X, Y)
MIN = 2*C*max(X, Y)
i = MAX
x=X
y=Y
while i > 0:
tmpC = (MAX-i)*2*C
total = (A*x)+(B*y)+tmpC
if(MIN > total):
MIN = total
i-=1
if(x!=0):
x-=1
if(y!=0):
y-=1
print(MIN)
|
def myAnswer(A:int,B:int,C:int,X:int,Y:int) -> int:
ans = 0
both = C * 2
AB=A+B
while X!=0 or Y!=0:
if(X>=1 and Y >=1):
ans += min(AB,both)
X-=1
Y-=1
elif(X>=1 and Y == 0):
ans += min(both,A)
X -= 1
else:
ans += min(both,B)
Y -= 1
return ans
def modelAnswer():
tmp=1
def main():
A,B,C,X,Y=list(map(int,input().split()))
print((myAnswer(A,B,C,X,Y)))
if __name__ == '__main__':
main() | 20 | 26 | 296 | 510 | A, B, C, X, Y = list(map(int, input().split()))
MAX = max(X, Y)
MIN = 2 * C * max(X, Y)
i = MAX
x = X
y = Y
while i > 0:
tmpC = (MAX - i) * 2 * C
total = (A * x) + (B * y) + tmpC
if MIN > total:
MIN = total
i -= 1
if x != 0:
x -= 1
if y != 0:
y -= 1
print(MIN)
| def myAnswer(A: int, B: int, C: int, X: int, Y: int) -> int:
ans = 0
both = C * 2
AB = A + B
while X != 0 or Y != 0:
if X >= 1 and Y >= 1:
ans += min(AB, both)
X -= 1
Y -= 1
elif X >= 1 and Y == 0:
ans += min(both, A)
X -= 1
else:
ans += min(both, B)
Y -= 1
return ans
def modelAnswer():
tmp = 1
def main():
A, B, C, X, Y = list(map(int, input().split()))
print((myAnswer(A, B, C, X, Y)))
if __name__ == "__main__":
main()
| false | 23.076923 | [
"-A, B, C, X, Y = list(map(int, input().split()))",
"-MAX = max(X, Y)",
"-MIN = 2 * C * max(X, Y)",
"-i = MAX",
"-x = X",
"-y = Y",
"-while i > 0:",
"- tmpC = (MAX - i) * 2 * C",
"- total = (A * x) + (B * y) + tmpC",
"- if MIN > total:",
"- MIN = total",
"- i -= 1",
"- if x != 0:",
"- x -= 1",
"- if y != 0:",
"- y -= 1",
"-print(MIN)",
"+def myAnswer(A: int, B: int, C: int, X: int, Y: int) -> int:",
"+ ans = 0",
"+ both = C * 2",
"+ AB = A + B",
"+ while X != 0 or Y != 0:",
"+ if X >= 1 and Y >= 1:",
"+ ans += min(AB, both)",
"+ X -= 1",
"+ Y -= 1",
"+ elif X >= 1 and Y == 0:",
"+ ans += min(both, A)",
"+ X -= 1",
"+ else:",
"+ ans += min(both, B)",
"+ Y -= 1",
"+ return ans",
"+",
"+",
"+def modelAnswer():",
"+ tmp = 1",
"+",
"+",
"+def main():",
"+ A, B, C, X, Y = list(map(int, input().split()))",
"+ print((myAnswer(A, B, C, X, Y)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.146209 | 0.201182 | 0.726753 | [
"s436426449",
"s835458335"
] |
u786020649 | p03558 | python | s717611943 | s562775553 | 120 | 87 | 14,760 | 14,668 | Accepted | Accepted | 27.5 | from collections import deque
k=int(eval(input()))
v=list(range(k))
stack=deque([1])
inf=float('inf')
visited=[0]*k
dist=[inf]*k
dist[1]=0
while stack:
v=stack.pop()
if not visited[v]:
nv0=10*v%k
nv1=(v+1)%k
if dist[nv0]>dist[v]:
dist[nv0]=dist[v]
stack.append(nv0)
if dist[nv1]>1+dist[v]:
stack.appendleft(nv1)
dist[nv1]=dist[v]+1
visited[v]=1
print((dist[0]+1)) | import sys
from collections import deque
readline=sys.stdin.readline
def main():
k=int(readline())
v=list(range(k))
inf=float('inf')
dist=[inf]*k
visited=[0]*k
stack=deque([1])
dist[1]=0
while stack:
v=stack.pop()
if not visited[v]:
nv0=10*v%k
nv1=(v+1)%k
if dist[nv0]>dist[v]:
dist[nv0]=dist[v]
stack.append(nv0)
if dist[nv1]>dist[v]+1:
dist[nv1]=dist[v]+1
stack.appendleft(nv1)
visited[v]=1
print((dist[0]+1))
if __name__=='__main__':
main()
| 22 | 28 | 425 | 651 | from collections import deque
k = int(eval(input()))
v = list(range(k))
stack = deque([1])
inf = float("inf")
visited = [0] * k
dist = [inf] * k
dist[1] = 0
while stack:
v = stack.pop()
if not visited[v]:
nv0 = 10 * v % k
nv1 = (v + 1) % k
if dist[nv0] > dist[v]:
dist[nv0] = dist[v]
stack.append(nv0)
if dist[nv1] > 1 + dist[v]:
stack.appendleft(nv1)
dist[nv1] = dist[v] + 1
visited[v] = 1
print((dist[0] + 1))
| import sys
from collections import deque
readline = sys.stdin.readline
def main():
k = int(readline())
v = list(range(k))
inf = float("inf")
dist = [inf] * k
visited = [0] * k
stack = deque([1])
dist[1] = 0
while stack:
v = stack.pop()
if not visited[v]:
nv0 = 10 * v % k
nv1 = (v + 1) % k
if dist[nv0] > dist[v]:
dist[nv0] = dist[v]
stack.append(nv0)
if dist[nv1] > dist[v] + 1:
dist[nv1] = dist[v] + 1
stack.appendleft(nv1)
visited[v] = 1
print((dist[0] + 1))
if __name__ == "__main__":
main()
| false | 21.428571 | [
"+import sys",
"-k = int(eval(input()))",
"-v = list(range(k))",
"-stack = deque([1])",
"-inf = float(\"inf\")",
"-visited = [0] * k",
"-dist = [inf] * k",
"-dist[1] = 0",
"-while stack:",
"- v = stack.pop()",
"- if not visited[v]:",
"- nv0 = 10 * v % k",
"- nv1 = (v + 1) % k",
"- if dist[nv0] > dist[v]:",
"- dist[nv0] = dist[v]",
"- stack.append(nv0)",
"- if dist[nv1] > 1 + dist[v]:",
"- stack.appendleft(nv1)",
"- dist[nv1] = dist[v] + 1",
"- visited[v] = 1",
"-print((dist[0] + 1))",
"+readline = sys.stdin.readline",
"+",
"+",
"+def main():",
"+ k = int(readline())",
"+ v = list(range(k))",
"+ inf = float(\"inf\")",
"+ dist = [inf] * k",
"+ visited = [0] * k",
"+ stack = deque([1])",
"+ dist[1] = 0",
"+ while stack:",
"+ v = stack.pop()",
"+ if not visited[v]:",
"+ nv0 = 10 * v % k",
"+ nv1 = (v + 1) % k",
"+ if dist[nv0] > dist[v]:",
"+ dist[nv0] = dist[v]",
"+ stack.append(nv0)",
"+ if dist[nv1] > dist[v] + 1:",
"+ dist[nv1] = dist[v] + 1",
"+ stack.appendleft(nv1)",
"+ visited[v] = 1",
"+ print((dist[0] + 1))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.093755 | 0.137443 | 0.682138 | [
"s717611943",
"s562775553"
] |
u200887663 | p02689 | python | s578347407 | s022887009 | 315 | 263 | 24,444 | 19,980 | Accepted | Accepted | 16.51 | #n=int(input())
n,m=list(map(int,input().split()))
hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
dic={}
for i in range(n):
dic[i+1]=True
for i in range(m):
a,b=list(map(int,input().split()))
if hl[a-1]<=hl[b-1]:
dic[a]=False
if hl[b-1]<=hl[a-1]:
dic[b]=False
ans=0
for k,v in list(dic.items()):
if v :
ans+=1
print(ans)
| #k=int(input())
n,m=list(map(int,input().split()))
hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
dic={}
for i in range(m):
a,b=list(map(int,input().split()))
if hl[a-1] <= hl[b-1]:
dic[a]=False
if hl[b-1] <= hl[a-1]:
dic[b]=False
print((n-len(dic)))
| 24 | 13 | 417 | 319 | # n=int(input())
n, m = list(map(int, input().split()))
hl = list(map(int, input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
dic = {}
for i in range(n):
dic[i + 1] = True
for i in range(m):
a, b = list(map(int, input().split()))
if hl[a - 1] <= hl[b - 1]:
dic[a] = False
if hl[b - 1] <= hl[a - 1]:
dic[b] = False
ans = 0
for k, v in list(dic.items()):
if v:
ans += 1
print(ans)
| # k=int(input())
n, m = list(map(int, input().split()))
hl = list(map(int, input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
dic = {}
for i in range(m):
a, b = list(map(int, input().split()))
if hl[a - 1] <= hl[b - 1]:
dic[a] = False
if hl[b - 1] <= hl[a - 1]:
dic[b] = False
print((n - len(dic)))
| false | 45.833333 | [
"-# n=int(input())",
"+# k=int(input())",
"-for i in range(n):",
"- dic[i + 1] = True",
"-ans = 0",
"-for k, v in list(dic.items()):",
"- if v:",
"- ans += 1",
"-print(ans)",
"+print((n - len(dic)))"
] | false | 0.040225 | 0.039127 | 1.028048 | [
"s578347407",
"s022887009"
] |
u656917242 | p02990 | python | s230576032 | s568799067 | 595 | 545 | 3,944 | 3,944 | Accepted | Accepted | 8.4 | from operator import mul
from functools import reduce
def cmb(n, r):
if n < r:
return 0
r = min(n - r, r)
if r == 0:
return 1
numer = reduce(mul, list(range(n, n - r, -1)))
denom = reduce(mul, list(range(1, r + 1)))
return numer // denom % INF
N, K = list(map(int, input().split()))
INF = 10 ** 9 + 7
for i in range(1, K + 1):
print((cmb(K - 1, i - 1) * cmb(N - K + 1, i) % INF)) | from operator import mul
from functools import reduce
N, K=list(map(int, input().split()))
def cmb(n, r):
if(n<r):
return 0
r=min(r,n-r)
if(r==0):
return 1
upper=reduce(mul, list(range(n, n-r, -1)))
under=reduce(mul, list(range(1,r+1)))
return upper // under % INF
INF=10**9+7
for i in range(1,K+1):
ret = cmb(N-K+1,i)*cmb(K-1,i-1)
print((ret%INF))
| 20 | 22 | 394 | 391 | from operator import mul
from functools import reduce
def cmb(n, r):
if n < r:
return 0
r = min(n - r, r)
if r == 0:
return 1
numer = reduce(mul, list(range(n, n - r, -1)))
denom = reduce(mul, list(range(1, r + 1)))
return numer // denom % INF
N, K = list(map(int, input().split()))
INF = 10**9 + 7
for i in range(1, K + 1):
print((cmb(K - 1, i - 1) * cmb(N - K + 1, i) % INF))
| from operator import mul
from functools import reduce
N, K = list(map(int, input().split()))
def cmb(n, r):
if n < r:
return 0
r = min(r, n - r)
if r == 0:
return 1
upper = reduce(mul, list(range(n, n - r, -1)))
under = reduce(mul, list(range(1, r + 1)))
return upper // under % INF
INF = 10**9 + 7
for i in range(1, K + 1):
ret = cmb(N - K + 1, i) * cmb(K - 1, i - 1)
print((ret % INF))
| false | 9.090909 | [
"+",
"+N, K = list(map(int, input().split()))",
"- r = min(n - r, r)",
"+ r = min(r, n - r)",
"- numer = reduce(mul, list(range(n, n - r, -1)))",
"- denom = reduce(mul, list(range(1, r + 1)))",
"- return numer // denom % INF",
"+ upper = reduce(mul, list(range(n, n - r, -1)))",
"+ under = reduce(mul, list(range(1, r + 1)))",
"+ return upper // under % INF",
"-N, K = list(map(int, input().split()))",
"- print((cmb(K - 1, i - 1) * cmb(N - K + 1, i) % INF))",
"+ ret = cmb(N - K + 1, i) * cmb(K - 1, i - 1)",
"+ print((ret % INF))"
] | false | 0.095446 | 0.045297 | 2.107142 | [
"s230576032",
"s568799067"
] |
u411353821 | p02791 | python | s738693770 | s908827310 | 108 | 76 | 24,956 | 24,744 | Accepted | Accepted | 29.63 | N, *D = [list(map(int, s.split())) for s in open(0)]
N, D = N[0], D[0]
cnt = 1
min_v = D[0]
for i in range(1, len(D)):
if min_v >= D[i]:
cnt += 1
min_v = D[i]
print(cnt) | def main():
_ = int(eval(input()))
A = list(map(int, input().split()))
min_value = 1e10
cnt = 0
for a in A:
if a <= min_value:
min_value = a
cnt += 1
print(cnt)
if __name__ == "__main__":
main() | 10 | 14 | 199 | 264 | N, *D = [list(map(int, s.split())) for s in open(0)]
N, D = N[0], D[0]
cnt = 1
min_v = D[0]
for i in range(1, len(D)):
if min_v >= D[i]:
cnt += 1
min_v = D[i]
print(cnt)
| def main():
_ = int(eval(input()))
A = list(map(int, input().split()))
min_value = 1e10
cnt = 0
for a in A:
if a <= min_value:
min_value = a
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| false | 28.571429 | [
"-N, *D = [list(map(int, s.split())) for s in open(0)]",
"-N, D = N[0], D[0]",
"-cnt = 1",
"-min_v = D[0]",
"-for i in range(1, len(D)):",
"- if min_v >= D[i]:",
"- cnt += 1",
"- min_v = D[i]",
"-print(cnt)",
"+def main():",
"+ _ = int(eval(input()))",
"+ A = list(map(int, input().split()))",
"+ min_value = 1e10",
"+ cnt = 0",
"+ for a in A:",
"+ if a <= min_value:",
"+ min_value = a",
"+ cnt += 1",
"+ print(cnt)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.077866 | 0.037427 | 2.080479 | [
"s738693770",
"s908827310"
] |
u624475441 | p03457 | python | s609352118 | s949402402 | 233 | 178 | 28,148 | 3,060 | Accepted | Accepted | 23.61 | import sys
eval(input())
e = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]
for (t0, a0, b0), (t1, a1, b1) in zip(e, e[1:]):
d = (t1 - t0) - abs(a1 - a0) - abs(b1 - b0)
if d < 0 or d % 2 == 1:
print('No')
exit()
print('Yes') | import sys
eval(input())
pt, px, py = 0, 0, 0
for e in sys.stdin:
ct, cx, cy = list(map(int, e.split()))
d = (ct - pt) - abs(cx - px) - abs(cy - py)
if d < 0 or d % 2 == 1:
print('No')
break
pt, px, py = ct, cx, cy
else:
print('Yes') | 9 | 12 | 264 | 268 | import sys
eval(input())
e = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]
for (t0, a0, b0), (t1, a1, b1) in zip(e, e[1:]):
d = (t1 - t0) - abs(a1 - a0) - abs(b1 - b0)
if d < 0 or d % 2 == 1:
print("No")
exit()
print("Yes")
| import sys
eval(input())
pt, px, py = 0, 0, 0
for e in sys.stdin:
ct, cx, cy = list(map(int, e.split()))
d = (ct - pt) - abs(cx - px) - abs(cy - py)
if d < 0 or d % 2 == 1:
print("No")
break
pt, px, py = ct, cx, cy
else:
print("Yes")
| false | 25 | [
"-e = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]",
"-for (t0, a0, b0), (t1, a1, b1) in zip(e, e[1:]):",
"- d = (t1 - t0) - abs(a1 - a0) - abs(b1 - b0)",
"+pt, px, py = 0, 0, 0",
"+for e in sys.stdin:",
"+ ct, cx, cy = list(map(int, e.split()))",
"+ d = (ct - pt) - abs(cx - px) - abs(cy - py)",
"- exit()",
"-print(\"Yes\")",
"+ break",
"+ pt, px, py = ct, cx, cy",
"+else:",
"+ print(\"Yes\")"
] | false | 0.041781 | 0.063968 | 0.653157 | [
"s609352118",
"s949402402"
] |
u057109575 | p02616 | python | s433792952 | s865835059 | 363 | 159 | 114,468 | 114,412 | Accepted | Accepted | 56.2 |
N, K = list(map(int, input().split()))
X = list(map(int, input().split()))
MOD = 10 ** 9 + 7
pos = sorted(v for v in X if v >= 0)
neg = sorted(-v for v in X if v < 0)
ok = False # True: ans>=0, False: ans<0
if pos:
if N == K:
# Select all -> number of negatives must be even
ok = len(neg) % 2 == 0
else:
ok = True
else:
# All negative and even number is selected
ok = K % 2 == 0
ans = 1
if ok:
# ans >= 0
if K % 2 == 1:
ans = ans * pos.pop() % MOD
# 答えは正になる→二つの数の積は必ず正になる.
cand = []
while len(pos) >= 2:
x = pos.pop() * pos.pop()
cand.append(x)
while len(neg) >= 2:
x = neg.pop() * neg.pop()
cand.append(x)
cand.sort(reverse=True)
for i in range(K // 2):
ans = ans * cand[i] % MOD
else:
# ans <= 0
cand = sorted(X, key=lambda x: abs(x))
for i in range(K):
ans = ans * cand[i] % MOD
print(ans)
|
N, K = list(map(int, input().split()))
X = list(map(int, input().split()))
MOD = 10 ** 9 + 7
if K % 2 == 1 and all(v < 0 for v in X):
# Minimize abs
X.sort(key=lambda x: -x)
ans = 1
for i in range(K):
ans = ans * X[i] % MOD
print(ans)
elif K == N:
ans = 1
for i in range(K):
ans = ans * X[i] % MOD
print(ans)
else:
pos = sorted(v for v in X if v >= 0)
neg = sorted(-v for v in X if v < 0)
ans = 1
if K % 2 == 1:
ans *= pos.pop()
cand = []
while len(pos) >= 2:
tmp = pos.pop() * pos.pop()
cand.append(tmp)
while len(neg) >= 2:
tmp = neg.pop() * neg.pop()
cand.append(tmp)
cand.sort(reverse=True)
for i in range(K // 2):
ans = ans * cand[i] % MOD
print(ans)
| 45 | 40 | 980 | 833 | N, K = list(map(int, input().split()))
X = list(map(int, input().split()))
MOD = 10**9 + 7
pos = sorted(v for v in X if v >= 0)
neg = sorted(-v for v in X if v < 0)
ok = False # True: ans>=0, False: ans<0
if pos:
if N == K:
# Select all -> number of negatives must be even
ok = len(neg) % 2 == 0
else:
ok = True
else:
# All negative and even number is selected
ok = K % 2 == 0
ans = 1
if ok:
# ans >= 0
if K % 2 == 1:
ans = ans * pos.pop() % MOD
# 答えは正になる→二つの数の積は必ず正になる.
cand = []
while len(pos) >= 2:
x = pos.pop() * pos.pop()
cand.append(x)
while len(neg) >= 2:
x = neg.pop() * neg.pop()
cand.append(x)
cand.sort(reverse=True)
for i in range(K // 2):
ans = ans * cand[i] % MOD
else:
# ans <= 0
cand = sorted(X, key=lambda x: abs(x))
for i in range(K):
ans = ans * cand[i] % MOD
print(ans)
| N, K = list(map(int, input().split()))
X = list(map(int, input().split()))
MOD = 10**9 + 7
if K % 2 == 1 and all(v < 0 for v in X):
# Minimize abs
X.sort(key=lambda x: -x)
ans = 1
for i in range(K):
ans = ans * X[i] % MOD
print(ans)
elif K == N:
ans = 1
for i in range(K):
ans = ans * X[i] % MOD
print(ans)
else:
pos = sorted(v for v in X if v >= 0)
neg = sorted(-v for v in X if v < 0)
ans = 1
if K % 2 == 1:
ans *= pos.pop()
cand = []
while len(pos) >= 2:
tmp = pos.pop() * pos.pop()
cand.append(tmp)
while len(neg) >= 2:
tmp = neg.pop() * neg.pop()
cand.append(tmp)
cand.sort(reverse=True)
for i in range(K // 2):
ans = ans * cand[i] % MOD
print(ans)
| false | 11.111111 | [
"-pos = sorted(v for v in X if v >= 0)",
"-neg = sorted(-v for v in X if v < 0)",
"-ok = False # True: ans>=0, False: ans<0",
"-if pos:",
"- if N == K:",
"- # Select all -> number of negatives must be even",
"- ok = len(neg) % 2 == 0",
"- else:",
"- ok = True",
"+if K % 2 == 1 and all(v < 0 for v in X):",
"+ # Minimize abs",
"+ X.sort(key=lambda x: -x)",
"+ ans = 1",
"+ for i in range(K):",
"+ ans = ans * X[i] % MOD",
"+ print(ans)",
"+elif K == N:",
"+ ans = 1",
"+ for i in range(K):",
"+ ans = ans * X[i] % MOD",
"+ print(ans)",
"- # All negative and even number is selected",
"- ok = K % 2 == 0",
"-ans = 1",
"-if ok:",
"- # ans >= 0",
"+ pos = sorted(v for v in X if v >= 0)",
"+ neg = sorted(-v for v in X if v < 0)",
"+ ans = 1",
"- ans = ans * pos.pop() % MOD",
"- # 答えは正になる→二つの数の積は必ず正になる.",
"+ ans *= pos.pop()",
"- x = pos.pop() * pos.pop()",
"- cand.append(x)",
"+ tmp = pos.pop() * pos.pop()",
"+ cand.append(tmp)",
"- x = neg.pop() * neg.pop()",
"- cand.append(x)",
"+ tmp = neg.pop() * neg.pop()",
"+ cand.append(tmp)",
"-else:",
"- # ans <= 0",
"- cand = sorted(X, key=lambda x: abs(x))",
"- for i in range(K):",
"- ans = ans * cand[i] % MOD",
"-print(ans)",
"+ print(ans)"
] | false | 0.041715 | 0.102819 | 0.405713 | [
"s433792952",
"s865835059"
] |
u489186465 | p03041 | python | s060472939 | s885147173 | 187 | 171 | 38,384 | 38,420 | Accepted | Accepted | 8.56 | n, k = list(map(int, input().split()))
s = eval(input())
print((s[:k-1] + s[k-1].lower() + s[k:])) | n, k = list(map(int, input().split()))
s = list(eval(input()))
s[k-1] = s[k-1].lower()
print(("".join(s))) | 4 | 5 | 88 | 97 | n, k = list(map(int, input().split()))
s = eval(input())
print((s[: k - 1] + s[k - 1].lower() + s[k:]))
| n, k = list(map(int, input().split()))
s = list(eval(input()))
s[k - 1] = s[k - 1].lower()
print(("".join(s)))
| false | 20 | [
"-s = eval(input())",
"-print((s[: k - 1] + s[k - 1].lower() + s[k:]))",
"+s = list(eval(input()))",
"+s[k - 1] = s[k - 1].lower()",
"+print((\"\".join(s)))"
] | false | 0.052152 | 0.034417 | 1.515285 | [
"s060472939",
"s885147173"
] |
u671060652 | p03107 | python | s066823422 | s009310799 | 326 | 81 | 73,836 | 71,844 | Accepted | Accepted | 75.15 | import itertools
import math
import fractions
import functools
import copy
s = list(eval(input()))
one = s.count("1")
zero = s.count("0")
print((min(one,zero)*2)) | def main():
# n = int(input())
# n, m = map(int, input().split())
# a = list(map(int, input().split()))
s = list(eval(input()))
# h = [int(input()) for _ in rane(n)]
count0 = 0
count1 = 0
for i in s:
if i == "0":
count0 += 1
else:
count1 += 1
print((min(count0, count1)*2))
if __name__ == '__main__':
main()
| 10 | 19 | 164 | 401 | import itertools
import math
import fractions
import functools
import copy
s = list(eval(input()))
one = s.count("1")
zero = s.count("0")
print((min(one, zero) * 2))
| def main():
# n = int(input())
# n, m = map(int, input().split())
# a = list(map(int, input().split()))
s = list(eval(input()))
# h = [int(input()) for _ in rane(n)]
count0 = 0
count1 = 0
for i in s:
if i == "0":
count0 += 1
else:
count1 += 1
print((min(count0, count1) * 2))
if __name__ == "__main__":
main()
| false | 47.368421 | [
"-import itertools",
"-import math",
"-import fractions",
"-import functools",
"-import copy",
"+def main():",
"+ # n = int(input())",
"+ # n, m = map(int, input().split())",
"+ # a = list(map(int, input().split()))",
"+ s = list(eval(input()))",
"+ # h = [int(input()) for _ in rane(n)]",
"+ count0 = 0",
"+ count1 = 0",
"+ for i in s:",
"+ if i == \"0\":",
"+ count0 += 1",
"+ else:",
"+ count1 += 1",
"+ print((min(count0, count1) * 2))",
"-s = list(eval(input()))",
"-one = s.count(\"1\")",
"-zero = s.count(\"0\")",
"-print((min(one, zero) * 2))",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.03554 | 0.074065 | 0.479853 | [
"s066823422",
"s009310799"
] |
u094191970 | p03044 | python | s014364745 | s159285591 | 1,141 | 750 | 50,072 | 45,352 | Accepted | Accepted | 34.27 | from collections import deque
n=int(eval(input()))
tree=[[] for i in range(n)]
for i in range(n-1):
u,v,w=list(map(int,input().split()))
u-=1
v-=1
tree[u].append([v,w])
tree[v].append([u,w])
dist=[-1]*n
dist[0]=0
ans=[-1]*n
ans[0]=0
dq=deque()
dq.append(0)
while dq:
x=dq.popleft()
for vv,ww in tree[x]:
if dist[vv]==-1:
dq.append(vv)
dist[vv]=dist[x]+ww
if dist[vv]%2==0:
ans[vv]=0
else:
ans[vv]=1
for i in ans:
print(i) | from collections import deque
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
n=int(eval(input()))
tree=[[] for i in range(n)]
for i in range(n-1):
u,v,w=nii()
u-=1
v-=1
tree[u].append([v,w])
tree[v].append([u,w])
ans=[-1 for i in range(n)]
ans[0]=0
que=deque()
que.append(0)
while que:
x=que.popleft()
for i in tree[x]:
nx=i[0]
nw=i[1]
if ans[nx]==-1:
que.append(nx)
if nw%2==0:
ans[nx]=ans[x]
else:
ans[nx]=(ans[x]+1)%2
for i in ans:
print(i) | 34 | 34 | 509 | 558 | from collections import deque
n = int(eval(input()))
tree = [[] for i in range(n)]
for i in range(n - 1):
u, v, w = list(map(int, input().split()))
u -= 1
v -= 1
tree[u].append([v, w])
tree[v].append([u, w])
dist = [-1] * n
dist[0] = 0
ans = [-1] * n
ans[0] = 0
dq = deque()
dq.append(0)
while dq:
x = dq.popleft()
for vv, ww in tree[x]:
if dist[vv] == -1:
dq.append(vv)
dist[vv] = dist[x] + ww
if dist[vv] % 2 == 0:
ans[vv] = 0
else:
ans[vv] = 1
for i in ans:
print(i)
| from collections import deque
from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
n = int(eval(input()))
tree = [[] for i in range(n)]
for i in range(n - 1):
u, v, w = nii()
u -= 1
v -= 1
tree[u].append([v, w])
tree[v].append([u, w])
ans = [-1 for i in range(n)]
ans[0] = 0
que = deque()
que.append(0)
while que:
x = que.popleft()
for i in tree[x]:
nx = i[0]
nw = i[1]
if ans[nx] == -1:
que.append(nx)
if nw % 2 == 0:
ans[nx] = ans[x]
else:
ans[nx] = (ans[x] + 1) % 2
for i in ans:
print(i)
| false | 0 | [
"+from sys import stdin",
"+nii = lambda: list(map(int, stdin.readline().split()))",
"- u, v, w = list(map(int, input().split()))",
"+ u, v, w = nii()",
"-dist = [-1] * n",
"-dist[0] = 0",
"-ans = [-1] * n",
"+ans = [-1 for i in range(n)]",
"-dq = deque()",
"-dq.append(0)",
"-while dq:",
"- x = dq.popleft()",
"- for vv, ww in tree[x]:",
"- if dist[vv] == -1:",
"- dq.append(vv)",
"- dist[vv] = dist[x] + ww",
"- if dist[vv] % 2 == 0:",
"- ans[vv] = 0",
"+que = deque()",
"+que.append(0)",
"+while que:",
"+ x = que.popleft()",
"+ for i in tree[x]:",
"+ nx = i[0]",
"+ nw = i[1]",
"+ if ans[nx] == -1:",
"+ que.append(nx)",
"+ if nw % 2 == 0:",
"+ ans[nx] = ans[x]",
"- ans[vv] = 1",
"+ ans[nx] = (ans[x] + 1) % 2"
] | false | 0.044258 | 0.044042 | 1.004916 | [
"s014364745",
"s159285591"
] |
u895445743 | p04001 | python | s154841915 | s027958018 | 194 | 77 | 40,048 | 67,720 | Accepted | Accepted | 60.31 | from itertools import product
a=list(eval(input()))
sum=0
text=""
for i in product(["","+"],repeat=len(a)-1):
text=""
for j in range(len(a)-1):
text+=a[j]+i[j]
text+=a[len(a)-1]
sum+=eval(text)
print(sum)
| from itertools import product
s = str(eval(input()))
a = list(product(['+', ''], repeat=len(s)-1))
ans = 0
tmp = ""
for i in a:
tmp = ""
for j in range(len(s)-1):
tmp += (s[j]+i[j])
tmp += s[len(s)-1]
ans += eval(tmp)
print(ans)
| 13 | 15 | 244 | 264 | from itertools import product
a = list(eval(input()))
sum = 0
text = ""
for i in product(["", "+"], repeat=len(a) - 1):
text = ""
for j in range(len(a) - 1):
text += a[j] + i[j]
text += a[len(a) - 1]
sum += eval(text)
print(sum)
| from itertools import product
s = str(eval(input()))
a = list(product(["+", ""], repeat=len(s) - 1))
ans = 0
tmp = ""
for i in a:
tmp = ""
for j in range(len(s) - 1):
tmp += s[j] + i[j]
tmp += s[len(s) - 1]
ans += eval(tmp)
print(ans)
| false | 13.333333 | [
"-a = list(eval(input()))",
"-sum = 0",
"-text = \"\"",
"-for i in product([\"\", \"+\"], repeat=len(a) - 1):",
"- text = \"\"",
"- for j in range(len(a) - 1):",
"- text += a[j] + i[j]",
"- text += a[len(a) - 1]",
"- sum += eval(text)",
"-print(sum)",
"+s = str(eval(input()))",
"+a = list(product([\"+\", \"\"], repeat=len(s) - 1))",
"+ans = 0",
"+tmp = \"\"",
"+for i in a:",
"+ tmp = \"\"",
"+ for j in range(len(s) - 1):",
"+ tmp += s[j] + i[j]",
"+ tmp += s[len(s) - 1]",
"+ ans += eval(tmp)",
"+print(ans)"
] | false | 0.147699 | 0.035332 | 4.180345 | [
"s154841915",
"s027958018"
] |
u508164527 | p02819 | python | s011326351 | s384830069 | 31 | 17 | 2,940 | 3,060 | Accepted | Accepted | 45.16 | X = int(eval(input()))
for i in range(X, 100005):
for j in range(2,i):
if i%j == 0:
break
else:
print(i)
quit() | import math
X = int(eval(input()))
def isPrime(n):
if n == 1:
return False
max = math.ceil(math.sqrt(n))
for i in range(2,max):
if n % i == 0:
return False
return True
while(True):
if isPrime(X):
print(X)
quit()
else:
X = X+1 | 8 | 17 | 134 | 274 | X = int(eval(input()))
for i in range(X, 100005):
for j in range(2, i):
if i % j == 0:
break
else:
print(i)
quit()
| import math
X = int(eval(input()))
def isPrime(n):
if n == 1:
return False
max = math.ceil(math.sqrt(n))
for i in range(2, max):
if n % i == 0:
return False
return True
while True:
if isPrime(X):
print(X)
quit()
else:
X = X + 1
| false | 52.941176 | [
"+import math",
"+",
"-for i in range(X, 100005):",
"- for j in range(2, i):",
"- if i % j == 0:",
"- break",
"+",
"+",
"+def isPrime(n):",
"+ if n == 1:",
"+ return False",
"+ max = math.ceil(math.sqrt(n))",
"+ for i in range(2, max):",
"+ if n % i == 0:",
"+ return False",
"+ return True",
"+",
"+",
"+while True:",
"+ if isPrime(X):",
"+ print(X)",
"+ quit()",
"- print(i)",
"- quit()",
"+ X = X + 1"
] | false | 0.090021 | 0.125328 | 0.718287 | [
"s011326351",
"s384830069"
] |
u757117214 | p03060 | python | s281465161 | s846770491 | 22 | 17 | 3,572 | 3,060 | Accepted | Accepted | 22.73 | from functools import reduce
from operator import add
n=int(eval(input()))
v=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
l=[v[i]-c[i] for i in range(n) if v[i]>c[i]]
print((reduce(add,l) if l else 0)) | n=int(eval(input()))
v=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
sum=0
for i in range(n):
if v[i]>c[i]:
sum+=v[i]-c[i]
print(sum) | 7 | 8 | 224 | 164 | from functools import reduce
from operator import add
n = int(eval(input()))
v = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
l = [v[i] - c[i] for i in range(n) if v[i] > c[i]]
print((reduce(add, l) if l else 0))
| n = int(eval(input()))
v = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
sum = 0
for i in range(n):
if v[i] > c[i]:
sum += v[i] - c[i]
print(sum)
| false | 12.5 | [
"-from functools import reduce",
"-from operator import add",
"-",
"-l = [v[i] - c[i] for i in range(n) if v[i] > c[i]]",
"-print((reduce(add, l) if l else 0))",
"+sum = 0",
"+for i in range(n):",
"+ if v[i] > c[i]:",
"+ sum += v[i] - c[i]",
"+print(sum)"
] | false | 0.034001 | 0.033807 | 1.005728 | [
"s281465161",
"s846770491"
] |
u654470292 | p02973 | python | s814387506 | s160386934 | 439 | 141 | 47,704 | 14,300 | Accepted | Accepted | 67.88 | import sys
from collections import deque
import time
import bisect
def input():
return sys.stdin.readline()[:-1]
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
# print(a)
ans=deque([a[0]])
for i in range(1,n):
loc=bisect.bisect_left(ans,a[i])
if loc==0:
ans.appendleft(a[i])
else:
ans[loc-1]=a[i]
# print(ans)
print((len(ans))) | import bisect, copy, heapq, math
from math import inf
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
def celi(a,b):
return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
now=n
lst=[-1]*n
for i in range(n):
tmp=bisect.bisect_left(lst,a[i])
if tmp==now:
lst[tmp-1]=a[i]
now-=1
else:
lst[tmp-1]=a[i]
# print(lst)
print((n-now)) | 18 | 32 | 377 | 732 | import sys
from collections import deque
import time
import bisect
def input():
return sys.stdin.readline()[:-1]
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
# print(a)
ans = deque([a[0]])
for i in range(1, n):
loc = bisect.bisect_left(ans, a[i])
if loc == 0:
ans.appendleft(a[i])
else:
ans[loc - 1] = a[i]
# print(ans)
print((len(ans)))
| import bisect, copy, heapq, math
from math import inf
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0] + list(accumulate(lst))
def celi(a, b):
return -(-a // b)
sys.setrecursionlimit(5000000)
mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
now = n
lst = [-1] * n
for i in range(n):
tmp = bisect.bisect_left(lst, a[i])
if tmp == now:
lst[tmp - 1] = a[i]
now -= 1
else:
lst[tmp - 1] = a[i]
# print(lst)
print((n - now))
| false | 43.75 | [
"+import bisect, copy, heapq, math",
"+from math import inf",
"-from collections import deque",
"-import time",
"-import bisect",
"+from collections import *",
"+from functools import lru_cache",
"+from itertools import accumulate, combinations, permutations, product",
"+def ruiseki(lst):",
"+ return [0] + list(accumulate(lst))",
"+",
"+",
"+def celi(a, b):",
"+ return -(-a // b)",
"+",
"+",
"+sys.setrecursionlimit(5000000)",
"+mod = pow(10, 9) + 7",
"+al = [chr(ord(\"a\") + i) for i in range(26)]",
"+direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]",
"-# print(a)",
"-ans = deque([a[0]])",
"-for i in range(1, n):",
"- loc = bisect.bisect_left(ans, a[i])",
"- if loc == 0:",
"- ans.appendleft(a[i])",
"+now = n",
"+lst = [-1] * n",
"+for i in range(n):",
"+ tmp = bisect.bisect_left(lst, a[i])",
"+ if tmp == now:",
"+ lst[tmp - 1] = a[i]",
"+ now -= 1",
"- ans[loc - 1] = a[i]",
"-# print(ans)",
"-print((len(ans)))",
"+ lst[tmp - 1] = a[i]",
"+# print(lst)",
"+print((n - now))"
] | false | 0.057161 | 0.043266 | 1.321165 | [
"s814387506",
"s160386934"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.