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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u074220993 | p03480 | python | s490198399 | s743546485 | 61 | 52 | 10,260 | 9,212 | Accepted | Accepted | 14.75 | S = list(eval(input()))
lenS = len(S)
S = S + ['.']
K = lenS
i = 0
ps = S[0]
for s in S:
if s != ps:
K = min(K, max(i, lenS-i))
ps = s
i += 1
print(K) | def main():
S = eval(input())
l = len(S)
ans = l
#データ加工
for i, s in enumerate(S[1:]):
if s != S[i]:
ans = min(ans, max(i+1, l-1-i))
print(ans)
main() | 12 | 11 | 179 | 202 | S = list(eval(input()))
lenS = len(S)
S = S + ["."]
K = lenS
i = 0
ps = S[0]
for s in S:
if s != ps:
K = min(K, max(i, lenS - i))
ps = s
i += 1
print(K)
| def main():
S = eval(input())
l = len(S)
ans = l
# データ加工
for i, s in enumerate(S[1:]):
if s != S[i]:
ans = min(ans, max(i + 1, l - 1 - i))
print(ans)
main()
| false | 8.333333 | [
"-S = list(eval(input()))",
"-lenS = len(S)",
"-S = S + [\".\"]",
"-K = lenS",
"-i = 0",
"-ps = S[0]",
"-for s in S:",
"- if s != ps:",
"- K = min(K, max(i, lenS - i))",
"- ps = s",
"- i += 1",
"-print(K)",
"+def main():",
"+ S = eval(input())",
"+ l = len(S)",
... | false | 0.044575 | 0.045029 | 0.989899 | [
"s490198399",
"s743546485"
] |
u061231294 | p02948 | python | s419211100 | s704283212 | 844 | 483 | 72,480 | 72,156 | Accepted | Accepted | 42.77 | import heapq
N, M = list(map(int, input().split()))
jobs = [[] for _ in range(M+1)]
for _ in range(N):
day, value = list(map(int, input().split()))
if day <= M:
jobs[day].append(value)
ans = 0
hq = []
for day in range(1, M+1):
for value in jobs[day]:
heapq.heappush(hq, - value)
if len(hq) > 0:
ans -= heapq.heappop(hq)
print(ans)
| import heapq
import sys
from collections import defaultdict
input = sys.stdin.readline
N, M = list(map(int, input().split()))
jobs = defaultdict(list)
for _ in range(N):
day, value = list(map(int, input().split()))
if day <= M:
jobs[day].append(value)
ans = 0
hq = []
for day in range(1, M+1):
for value in jobs[day]:
heapq.heappush(hq, - value)
if len(hq) > 0:
ans -= heapq.heappop(hq)
print(ans)
| 18 | 21 | 379 | 449 | import heapq
N, M = list(map(int, input().split()))
jobs = [[] for _ in range(M + 1)]
for _ in range(N):
day, value = list(map(int, input().split()))
if day <= M:
jobs[day].append(value)
ans = 0
hq = []
for day in range(1, M + 1):
for value in jobs[day]:
heapq.heappush(hq, -value)
if len(hq) > 0:
ans -= heapq.heappop(hq)
print(ans)
| import heapq
import sys
from collections import defaultdict
input = sys.stdin.readline
N, M = list(map(int, input().split()))
jobs = defaultdict(list)
for _ in range(N):
day, value = list(map(int, input().split()))
if day <= M:
jobs[day].append(value)
ans = 0
hq = []
for day in range(1, M + 1):
for value in jobs[day]:
heapq.heappush(hq, -value)
if len(hq) > 0:
ans -= heapq.heappop(hq)
print(ans)
| false | 14.285714 | [
"+import sys",
"+from collections import defaultdict",
"+input = sys.stdin.readline",
"-jobs = [[] for _ in range(M + 1)]",
"+jobs = defaultdict(list)"
] | false | 0.037484 | 0.044696 | 0.838654 | [
"s419211100",
"s704283212"
] |
u932868243 | p02837 | python | s210016997 | s559221525 | 105 | 91 | 3,064 | 3,064 | Accepted | Accepted | 13.33 | import itertools
n=int(eval(input()))
la=[]
for _ in range(n):
d=int(eval(input()))
for dd in range(d):
x,y=list(map(int,input().split()))
la.append([_,x-1,y])
ans=0
for i in itertools.product([0,1],repeat=n):
s=sum(list(i))
for l in la:
if i[l[0]]==1 and i[l[1]]!=l[2]:
break
else:
ans=max(ans,s)
print(ans) | import itertools
n=int(eval(input()))
l=[]
for i in range(n):
d=int(eval(input()))
for dd in range(d):
x,y=list(map(int,input().split()))
l.append([i,x-1,y])
ans=0
for p in itertools.product([0,1],repeat=n):
for ll in l:
if p[ll[0]]==1 and p[ll[1]]!=ll[2]:
break
else:
ans=max(ans,sum(p))
print(ans) | 17 | 17 | 338 | 328 | import itertools
n = int(eval(input()))
la = []
for _ in range(n):
d = int(eval(input()))
for dd in range(d):
x, y = list(map(int, input().split()))
la.append([_, x - 1, y])
ans = 0
for i in itertools.product([0, 1], repeat=n):
s = sum(list(i))
for l in la:
if i[l[0]] == 1 and i[l[1]] != l[2]:
break
else:
ans = max(ans, s)
print(ans)
| import itertools
n = int(eval(input()))
l = []
for i in range(n):
d = int(eval(input()))
for dd in range(d):
x, y = list(map(int, input().split()))
l.append([i, x - 1, y])
ans = 0
for p in itertools.product([0, 1], repeat=n):
for ll in l:
if p[ll[0]] == 1 and p[ll[1]] != ll[2]:
break
else:
ans = max(ans, sum(p))
print(ans)
| false | 0 | [
"-la = []",
"-for _ in range(n):",
"+l = []",
"+for i in range(n):",
"- la.append([_, x - 1, y])",
"+ l.append([i, x - 1, y])",
"-for i in itertools.product([0, 1], repeat=n):",
"- s = sum(list(i))",
"- for l in la:",
"- if i[l[0]] == 1 and i[l[1]] != l[2]:",
"+for p i... | false | 0.048242 | 0.048306 | 0.998681 | [
"s210016997",
"s559221525"
] |
u729133443 | p02843 | python | s557332699 | s015707561 | 175 | 17 | 38,384 | 2,940 | Accepted | Accepted | 90.29 | n=int(eval(input()));print((+(n//100*5>=n%100))) | n=int(eval(input()));print((+(n%100*21<=n))) | 1 | 1 | 40 | 36 | n = int(eval(input()))
print((+(n // 100 * 5 >= n % 100)))
| n = int(eval(input()))
print((+(n % 100 * 21 <= n)))
| false | 0 | [
"-print((+(n // 100 * 5 >= n % 100)))",
"+print((+(n % 100 * 21 <= n)))"
] | false | 0.043751 | 0.045357 | 0.964599 | [
"s557332699",
"s015707561"
] |
u709304134 | p02732 | python | s814343480 | s451394522 | 501 | 415 | 38,844 | 38,840 | Accepted | Accepted | 17.17 | import collections
import math
def C(n):
return n * (n-1) // 2
N = int(eval(input()))
A = list(map(int,input().split()))
c = collections.Counter(A)
d = {}
sm = 0
for k,v in c.most_common():
d[k] = v
sm += C(v)
for a in A:
print((sm - C(d[a]) + C(d[a]-1)))
| import collections
def C(n):
return n * (n-1) // 2
N = int(eval(input()))
A = list(map(int,input().split()))
c = collections.Counter(A)
d = {}
sm = 0
for k,v in c.most_common():
d[k] = v
sm += C(v)
for a in A:
print((sm - d[a] + 1)) | 14 | 13 | 278 | 253 | import collections
import math
def C(n):
return n * (n - 1) // 2
N = int(eval(input()))
A = list(map(int, input().split()))
c = collections.Counter(A)
d = {}
sm = 0
for k, v in c.most_common():
d[k] = v
sm += C(v)
for a in A:
print((sm - C(d[a]) + C(d[a] - 1)))
| import collections
def C(n):
return n * (n - 1) // 2
N = int(eval(input()))
A = list(map(int, input().split()))
c = collections.Counter(A)
d = {}
sm = 0
for k, v in c.most_common():
d[k] = v
sm += C(v)
for a in A:
print((sm - d[a] + 1))
| false | 7.142857 | [
"-import math",
"- print((sm - C(d[a]) + C(d[a] - 1)))",
"+ print((sm - d[a] + 1))"
] | false | 0.041946 | 0.041258 | 1.016675 | [
"s814343480",
"s451394522"
] |
u385244248 | p02813 | python | s989971088 | s970983359 | 196 | 51 | 45,680 | 10,080 | Accepted | Accepted | 73.98 | import itertools
N = int(eval(input()))
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
T = list(itertools.permutations(list(range(1, N+1)), N))
for i in range(len(T)):
if T[i] == P:
s = i
if T[i] == Q:
d = i
print((abs(s-d))) | import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect
MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()
N = int(eval(input()))
L = list(itertools.permutations(list(range(1, N + 1)), N))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
for num, i in enumerate(L):
if i == P:
a = num
if i == Q:
b = num
print((abs(a - b)))
| 12 | 22 | 272 | 476 | import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
T = list(itertools.permutations(list(range(1, N + 1)), N))
for i in range(len(T)):
if T[i] == P:
s = i
if T[i] == Q:
d = i
print((abs(s - d)))
| import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect
MOD = 10**9 + 7
INF = 10**18 + 7
input = lambda: sys.stdin.readline().strip()
N = int(eval(input()))
L = list(itertools.permutations(list(range(1, N + 1)), N))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
for num, i in enumerate(L):
if i == P:
a = num
if i == Q:
b = num
print((abs(a - b)))
| false | 45.454545 | [
"+import sys",
"+import math",
"+import fractions",
"+from collections import deque",
"+import copy",
"+import bisect",
"+MOD = 10**9 + 7",
"+INF = 10**18 + 7",
"+input = lambda: sys.stdin.readline().strip()",
"+L = list(itertools.permutations(list(range(1, N + 1)), N))",
"-T = list(itertools.pe... | false | 0.040329 | 0.079569 | 0.506844 | [
"s989971088",
"s970983359"
] |
u223663729 | p02685 | python | s833155465 | s333202973 | 1,428 | 985 | 68,300 | 69,592 | Accepted | Accepted | 31.02 | mod = 998244353
n, m, k = list(map(int, input().split()))
def modpow(a, n, mod):
y = 1
while n:
if n & 1:
y = y * a % mod
a = a * a % mod
n >>= 1
return y
MAX = 500000
fac = [0]*MAX
facinv = [0]*MAX
inv = [0]*MAX
def modinv(a, mod):
b = mod
x, u = 1, 0
while b:
q = a//b
a, b = b, a-q*b
x, u = u, x-q*u
x %= mod
return x
def mod_nCr_init(n, mod):
fac[0] = fac[1] = 1
facinv[0] = facinv[1] = 1
inv[1] = 1
for i in range(2, n):
fac[i] = fac[i-1] * i % mod
inv[i] = -inv[mod % i] * (mod // i) % mod
facinv[i] = facinv[i-1] * inv[i] % mod
def mod_nCr(n, r, mod):
if n < r or n < 0 or r < 0:
return 0
return fac[n] * (facinv[r] * facinv[n-r] % mod) % mod
mod_nCr_init(MAX, mod)
ans = 0
for i in range(0, k+1):
ans += m * modpow(m-1, n-1-i, mod) * mod_nCr(n-1, i, mod)
ans %= mod
print(ans)
| N, M, K = list(map(int, input().split()))
mod = 998244353
MAX = 510000
fac = [0]*MAX
facinv = [0]*MAX
inv = [0]*MAX
def modinv(a, mod):
b = mod
x, u = 1, 0
while b:
q = a//b
a, b = b, a-q*b
x, u = u, x-q*u
x %= mod
return x
def mod_nCr_init(n, mod):
fac[0] = fac[1] = 1
facinv[0] = facinv[1] = 1
inv[1] = 1
for i in range(2, n):
fac[i] = fac[i-1] * i % mod
inv[i] = -inv[mod % i] * (mod // i) % mod
facinv[i] = facinv[i-1] * inv[i] % mod
def mod_nCr(n, r, mod):
if n < r or n < 0 or r < 0:
return 0
return fac[n] * (facinv[r] * facinv[n-r] % mod) % mod
mod_nCr_init(MAX, mod)
ans = 0
for i in range(K+1):
ans += mod_nCr(N-1, i, mod) * M * pow(M-1, N-i-1, mod)
ans %= mod
print(ans)
| 54 | 42 | 1,001 | 834 | mod = 998244353
n, m, k = list(map(int, input().split()))
def modpow(a, n, mod):
y = 1
while n:
if n & 1:
y = y * a % mod
a = a * a % mod
n >>= 1
return y
MAX = 500000
fac = [0] * MAX
facinv = [0] * MAX
inv = [0] * MAX
def modinv(a, mod):
b = mod
x, u = 1, 0
while b:
q = a // b
a, b = b, a - q * b
x, u = u, x - q * u
x %= mod
return x
def mod_nCr_init(n, mod):
fac[0] = fac[1] = 1
facinv[0] = facinv[1] = 1
inv[1] = 1
for i in range(2, n):
fac[i] = fac[i - 1] * i % mod
inv[i] = -inv[mod % i] * (mod // i) % mod
facinv[i] = facinv[i - 1] * inv[i] % mod
def mod_nCr(n, r, mod):
if n < r or n < 0 or r < 0:
return 0
return fac[n] * (facinv[r] * facinv[n - r] % mod) % mod
mod_nCr_init(MAX, mod)
ans = 0
for i in range(0, k + 1):
ans += m * modpow(m - 1, n - 1 - i, mod) * mod_nCr(n - 1, i, mod)
ans %= mod
print(ans)
| N, M, K = list(map(int, input().split()))
mod = 998244353
MAX = 510000
fac = [0] * MAX
facinv = [0] * MAX
inv = [0] * MAX
def modinv(a, mod):
b = mod
x, u = 1, 0
while b:
q = a // b
a, b = b, a - q * b
x, u = u, x - q * u
x %= mod
return x
def mod_nCr_init(n, mod):
fac[0] = fac[1] = 1
facinv[0] = facinv[1] = 1
inv[1] = 1
for i in range(2, n):
fac[i] = fac[i - 1] * i % mod
inv[i] = -inv[mod % i] * (mod // i) % mod
facinv[i] = facinv[i - 1] * inv[i] % mod
def mod_nCr(n, r, mod):
if n < r or n < 0 or r < 0:
return 0
return fac[n] * (facinv[r] * facinv[n - r] % mod) % mod
mod_nCr_init(MAX, mod)
ans = 0
for i in range(K + 1):
ans += mod_nCr(N - 1, i, mod) * M * pow(M - 1, N - i - 1, mod)
ans %= mod
print(ans)
| false | 22.222222 | [
"+N, M, K = list(map(int, input().split()))",
"-n, m, k = list(map(int, input().split()))",
"-",
"-",
"-def modpow(a, n, mod):",
"- y = 1",
"- while n:",
"- if n & 1:",
"- y = y * a % mod",
"- a = a * a % mod",
"- n >>= 1",
"- return y",
"-",
"-",
... | false | 2.308756 | 3.634248 | 0.635277 | [
"s833155465",
"s333202973"
] |
u989345508 | p03212 | python | s816590262 | s633071877 | 1,144 | 58 | 4,272 | 7,284 | Accepted | Accepted | 94.93 | #0,7,5,3で選んでくる
x=[0,7,5,3]
a=[]
k=0
def new_num(c):
global x
d=0
for i in range(9):
d+=(10**i)*x[c[i]]
return d
for i0 in range(4):
for i1 in range(4):
for i2 in range(4):
for i3 in range(4):
for i4 in range(4):
for i5 in range(4):
for i6 in range(4):
for i7 in range(4):
for i8 in range(4):
l1=new_num([i0,i1,i2,i3,i4,i5,i6,i7,i8])
l2=str(l1)
if ("3" in l2) and ("5" in l2) and ("7" in l2) and ("0" not in l2):
a.append(l1)
a.sort()
co=0
n=int(eval(input()))
for i in a:
if i<=n:
#print(i)
co+=1
else:
break
print(co)
| from itertools import product
n=int(eval(input()))
ans=[]
for i in range(3,10):
l=list(product(["3","5","7"],repeat=i))
for j in l:
if len(set(j))==3:
ans.append(int("".join(list(j))))
ans.sort()
m=len(ans)
l,r=0,m-1
while l+1<r:
k=(l+r)//2
if ans[k]<n:
l=k
elif ans[k]>n:
r=k
else:
l,r=k,k
break
if ans[l]==n:
print((l+1))
elif ans[r]==n:
print((r+1))
elif ans[l]>n:
print(l)
elif ans[r]<n:
print((r+1))
elif ans[l]<n:
print((l+1))
#print(l,r)
#print(ans)
| 35 | 33 | 897 | 572 | # 0,7,5,3で選んでくる
x = [0, 7, 5, 3]
a = []
k = 0
def new_num(c):
global x
d = 0
for i in range(9):
d += (10**i) * x[c[i]]
return d
for i0 in range(4):
for i1 in range(4):
for i2 in range(4):
for i3 in range(4):
for i4 in range(4):
for i5 in range(4):
for i6 in range(4):
for i7 in range(4):
for i8 in range(4):
l1 = new_num([i0, i1, i2, i3, i4, i5, i6, i7, i8])
l2 = str(l1)
if (
("3" in l2)
and ("5" in l2)
and ("7" in l2)
and ("0" not in l2)
):
a.append(l1)
a.sort()
co = 0
n = int(eval(input()))
for i in a:
if i <= n:
# print(i)
co += 1
else:
break
print(co)
| from itertools import product
n = int(eval(input()))
ans = []
for i in range(3, 10):
l = list(product(["3", "5", "7"], repeat=i))
for j in l:
if len(set(j)) == 3:
ans.append(int("".join(list(j))))
ans.sort()
m = len(ans)
l, r = 0, m - 1
while l + 1 < r:
k = (l + r) // 2
if ans[k] < n:
l = k
elif ans[k] > n:
r = k
else:
l, r = k, k
break
if ans[l] == n:
print((l + 1))
elif ans[r] == n:
print((r + 1))
elif ans[l] > n:
print(l)
elif ans[r] < n:
print((r + 1))
elif ans[l] < n:
print((l + 1))
# print(l,r)
# print(ans)
| false | 5.714286 | [
"-# 0,7,5,3で選んでくる",
"-x = [0, 7, 5, 3]",
"-a = []",
"-k = 0",
"+from itertools import product",
"-",
"-def new_num(c):",
"- global x",
"- d = 0",
"- for i in range(9):",
"- d += (10**i) * x[c[i]]",
"- return d",
"-",
"-",
"-for i0 in range(4):",
"- for i1 in range... | false | 2.164595 | 0.064508 | 33.555418 | [
"s816590262",
"s633071877"
] |
u413165887 | p02781 | python | s407025508 | s953357108 | 31 | 27 | 9,060 | 9,156 | Accepted | Accepted | 12.9 | n = list(map(int, list(eval(input()))))
k = int(eval(input()))
dp0 = [[0]*3]*len(n)
dp1 = [[0]*3]*len(n)
dp0[0][0] = 1
dp1[0][0] = max(0, n[0]-1)
for i in range(1, len(n)):
if n[i]==0:
dp0[i] = dp0[i-1]
else:
dp0[i] = [0]+dp0[i-1][:2]
dp1[i] = [
dp1[i-1][0]+dp0[i-1][0]*(n[i]!=0)+9,
dp1[i-1][1]+dp0[i-1][1]*(n[i]!=0)+dp0[i-1][0]*max(0, n[i]-1)+dp1[i-1][0]*9,
dp1[i-1][2]+dp0[i-1][2]*(n[i]!=0)+dp0[i-1][1]*max(0, n[i]-1)+dp1[i-1][1]*9,
]
print((dp0[-1][k-1]+dp1[-1][k-1])) | n = list(map(int, list(eval(input()))))
k = int(eval(input()))
dp0 = [0]*3
dp1 = [[0]*3]*len(n)
dp0[0] = 1
dp1[0][0] = max(0, n[0]-1)
for i in range(1, len(n)):
dp1[i] = [
dp1[i-1][0]+dp0[0]*(n[i]!=0)+9,
dp1[i-1][1]+dp0[1]*(n[i]!=0)+dp0[0]*max(0, n[i]-1)+dp1[i-1][0]*9,
dp1[i-1][2]+dp0[2]*(n[i]!=0)+dp0[1]*max(0, n[i]-1)+dp1[i-1][1]*9,
]
if n[i] != 0:
dp0 = [0]+dp0[:2]
print((dp0[k-1]+dp1[-1][k-1])) | 20 | 16 | 535 | 446 | n = list(map(int, list(eval(input()))))
k = int(eval(input()))
dp0 = [[0] * 3] * len(n)
dp1 = [[0] * 3] * len(n)
dp0[0][0] = 1
dp1[0][0] = max(0, n[0] - 1)
for i in range(1, len(n)):
if n[i] == 0:
dp0[i] = dp0[i - 1]
else:
dp0[i] = [0] + dp0[i - 1][:2]
dp1[i] = [
dp1[i - 1][0] + dp0[i - 1][0] * (n[i] != 0) + 9,
dp1[i - 1][1]
+ dp0[i - 1][1] * (n[i] != 0)
+ dp0[i - 1][0] * max(0, n[i] - 1)
+ dp1[i - 1][0] * 9,
dp1[i - 1][2]
+ dp0[i - 1][2] * (n[i] != 0)
+ dp0[i - 1][1] * max(0, n[i] - 1)
+ dp1[i - 1][1] * 9,
]
print((dp0[-1][k - 1] + dp1[-1][k - 1]))
| n = list(map(int, list(eval(input()))))
k = int(eval(input()))
dp0 = [0] * 3
dp1 = [[0] * 3] * len(n)
dp0[0] = 1
dp1[0][0] = max(0, n[0] - 1)
for i in range(1, len(n)):
dp1[i] = [
dp1[i - 1][0] + dp0[0] * (n[i] != 0) + 9,
dp1[i - 1][1]
+ dp0[1] * (n[i] != 0)
+ dp0[0] * max(0, n[i] - 1)
+ dp1[i - 1][0] * 9,
dp1[i - 1][2]
+ dp0[2] * (n[i] != 0)
+ dp0[1] * max(0, n[i] - 1)
+ dp1[i - 1][1] * 9,
]
if n[i] != 0:
dp0 = [0] + dp0[:2]
print((dp0[k - 1] + dp1[-1][k - 1]))
| false | 20 | [
"-dp0 = [[0] * 3] * len(n)",
"+dp0 = [0] * 3",
"-dp0[0][0] = 1",
"+dp0[0] = 1",
"- if n[i] == 0:",
"- dp0[i] = dp0[i - 1]",
"- else:",
"- dp0[i] = [0] + dp0[i - 1][:2]",
"- dp1[i - 1][0] + dp0[i - 1][0] * (n[i] != 0) + 9,",
"+ dp1[i - 1][0] + dp0[0] * (n[i] != 0) ... | false | 0.040356 | 0.155191 | 0.260041 | [
"s407025508",
"s953357108"
] |
u366996583 | p02639 | python | s282474791 | s902746702 | 30 | 23 | 8,920 | 9,008 | Accepted | Accepted | 23.33 | l=list(map(int,input().split()))
for i in range(5):
if l[i]==0:
print((i+1))
break | l=list(map(int,input().split()))
for i in range(5):
if l[i]!=i+1:
print((i+1)) | 5 | 4 | 94 | 85 | l = list(map(int, input().split()))
for i in range(5):
if l[i] == 0:
print((i + 1))
break
| l = list(map(int, input().split()))
for i in range(5):
if l[i] != i + 1:
print((i + 1))
| false | 20 | [
"- if l[i] == 0:",
"+ if l[i] != i + 1:",
"- break"
] | false | 0.039457 | 0.03875 | 1.018248 | [
"s282474791",
"s902746702"
] |
u562935282 | p02718 | python | s477654279 | s455898927 | 172 | 17 | 38,384 | 2,940 | Accepted | Accepted | 90.12 | def main():
n, m = list(map(int, input().split()))
*a, = list(map(int, input().split()))
LIM = sum(a) / (4 * m)
cnt = 0
for x in a:
if x >= LIM:
cnt += 1
print(('Yes' if cnt >= m else 'No'))
if __name__ == '__main__':
main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
| N, M = list(map(int, input().split()))
*a, = list(map(int, input().split()))
tot = sum(a)
cnt = 0
for x in a:
cnt += int(x * 4 * M >= tot)
print(('Yes' if cnt >= M else 'No'))
# 候補>=得票数の総和/4m
# 候補*4m>=得票数の総和
| 25 | 13 | 422 | 214 | def main():
n, m = list(map(int, input().split()))
(*a,) = list(map(int, input().split()))
LIM = sum(a) / (4 * m)
cnt = 0
for x in a:
if x >= LIM:
cnt += 1
print(("Yes" if cnt >= m else "No"))
if __name__ == "__main__":
main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
| N, M = list(map(int, input().split()))
(*a,) = list(map(int, input().split()))
tot = sum(a)
cnt = 0
for x in a:
cnt += int(x * 4 * M >= tot)
print(("Yes" if cnt >= M else "No"))
# 候補>=得票数の総和/4m
# 候補*4m>=得票数の総和
| false | 48 | [
"-def main():",
"- n, m = list(map(int, input().split()))",
"- (*a,) = list(map(int, input().split()))",
"- LIM = sum(a) / (4 * m)",
"- cnt = 0",
"- for x in a:",
"- if x >= LIM:",
"- cnt += 1",
"- print((\"Yes\" if cnt >= m else \"No\"))",
"-",
"-",
"-if __... | false | 0.097772 | 0.036287 | 2.694396 | [
"s477654279",
"s455898927"
] |
u869790980 | p03401 | python | s402313714 | s645597464 | 532 | 179 | 112,620 | 92,160 | Accepted | Accepted | 66.35 | n = int(input())
ais =[0] + list(map(int,input().split())) + [0]
skip = -float('inf')
cumul = 0
res = []
for i in range(1,len(ais)-1):
val = abs(ais[i] - ais[i-1])
skip = -abs(ais[i] - ais[i-1]) - abs(ais[i+1] - ais[i]) + abs(ais[i+1] - ais[i-1])
res.append(skip)
cumul += val
cumul += abs(ais[-1] - ais[-2])
for i in range(len(res)):
print(res[i] + cumul) | n,ais,cumul,res =int(input()),[0] + list(map(int,input().split())) + [0],0,[]
for i in range(1,len(ais)):
if i < len(ais) -1: res.append(-abs(ais[i] - ais[i-1]) - abs(ais[i+1] - ais[i]) + abs(ais[i+1] - ais[i-1]))
cumul += abs(ais[i] - ais[i-1])
for v in res: print(v + cumul) | 13 | 5 | 375 | 283 | n = int(input())
ais = [0] + list(map(int, input().split())) + [0]
skip = -float("inf")
cumul = 0
res = []
for i in range(1, len(ais) - 1):
val = abs(ais[i] - ais[i - 1])
skip = (
-abs(ais[i] - ais[i - 1])
- abs(ais[i + 1] - ais[i])
+ abs(ais[i + 1] - ais[i - 1])
)
res.append(skip)
cumul += val
cumul += abs(ais[-1] - ais[-2])
for i in range(len(res)):
print(res[i] + cumul)
| n, ais, cumul, res = int(input()), [0] + list(map(int, input().split())) + [0], 0, []
for i in range(1, len(ais)):
if i < len(ais) - 1:
res.append(
-abs(ais[i] - ais[i - 1])
- abs(ais[i + 1] - ais[i])
+ abs(ais[i + 1] - ais[i - 1])
)
cumul += abs(ais[i] - ais[i - 1])
for v in res:
print(v + cumul)
| false | 61.538462 | [
"-n = int(input())",
"-ais = [0] + list(map(int, input().split())) + [0]",
"-skip = -float(\"inf\")",
"-cumul = 0",
"-res = []",
"-for i in range(1, len(ais) - 1):",
"- val = abs(ais[i] - ais[i - 1])",
"- skip = (",
"- -abs(ais[i] - ais[i - 1])",
"- - abs(ais[i + 1] - ais[i])",... | false | 0.078853 | 0.082897 | 0.951213 | [
"s402313714",
"s645597464"
] |
u595893956 | p03109 | python | s146449054 | s321712164 | 21 | 18 | 3,316 | 2,940 | Accepted | Accepted | 14.29 | #n = int(input())
a,b,c=list(map(int,input().split("/"))) #横並び
#x=[int(input()) for i in range(3)] #縦に並んだのを配列に
#y=list(map(int,input().split())) #横に並んだのを配列に
if b<4 :print("Heisei")
elif b==4 and c<=30 :print("Heisei")
else :print("TBD")
#print('YNEOS'[1::2])
| a,b,c=list(map(int,input().split("/")))
if b<4 :print("Heisei")
elif b==4 and c<=30 :print("Heisei")
else :print("TBD")
| 8 | 4 | 260 | 117 | # n = int(input())
a, b, c = list(map(int, input().split("/"))) # 横並び
# x=[int(input()) for i in range(3)] #縦に並んだのを配列に
# y=list(map(int,input().split())) #横に並んだのを配列に
if b < 4:
print("Heisei")
elif b == 4 and c <= 30:
print("Heisei")
else:
print("TBD")
# print('YNEOS'[1::2])
| a, b, c = list(map(int, input().split("/")))
if b < 4:
print("Heisei")
elif b == 4 and c <= 30:
print("Heisei")
else:
print("TBD")
| false | 50 | [
"-# n = int(input())",
"-a, b, c = list(map(int, input().split(\"/\"))) # 横並び",
"-# x=[int(input()) for i in range(3)] #縦に並んだのを配列に",
"-# y=list(map(int,input().split())) #横に並んだのを配列に",
"+a, b, c = list(map(int, input().split(\"/\")))",
"-# print('YNEOS'[1::2])"
] | false | 0.042663 | 0.045275 | 0.942314 | [
"s146449054",
"s321712164"
] |
u102960641 | p02868 | python | s718422648 | s428671367 | 988 | 877 | 57,480 | 57,476 | Accepted | Accepted | 11.23 | import heapq
N,M = list(map(int,input().split()))
LRC = [tuple(map(int,input().split())) for i in range(M)]
es = [[] for i in range(N)]
for l,r,c in LRC:
l,r = l-1,r-1
es[l].append((r,c))
for i in range(N-1):
es[i+1].append((i,0))
INF = 10 ** 18
dist = [INF]*N
dist[0] = 0
hq = [(0,0)]
heapq.heapify(hq)
while(hq):
d,v = heapq.heappop(hq)
if v==N-1:
print(d)
exit()
for to,c in es[v]:
if d+c >= dist[to]: continue
dist[to] = d+c
heapq.heappush(hq, (d+c, to))
print((-1))
| import sys
input = sys.stdin.readline
import heapq
N,M = list(map(int,input().split()))
LRC = [tuple(map(int,input().split())) for i in range(M)]
es = [[] for i in range(N)]
for l,r,c in LRC:
l,r = l-1,r-1
es[l].append((r,c))
for i in range(N-1):
es[i+1].append((i,0))
INF = float("inf")
dist = [INF]*N
dist[0] = 0
hq = [(0,0)]
heapq.heapify(hq)
while(hq):
d,v = heapq.heappop(hq)
if v==N-1:
print(d)
exit()
for to,c in es[v]:
if d+c >= dist[to]: continue
dist[to] = d+c
heapq.heappush(hq, (d+c, to))
print((-1)) | 27 | 30 | 556 | 601 | import heapq
N, M = list(map(int, input().split()))
LRC = [tuple(map(int, input().split())) for i in range(M)]
es = [[] for i in range(N)]
for l, r, c in LRC:
l, r = l - 1, r - 1
es[l].append((r, c))
for i in range(N - 1):
es[i + 1].append((i, 0))
INF = 10**18
dist = [INF] * N
dist[0] = 0
hq = [(0, 0)]
heapq.heapify(hq)
while hq:
d, v = heapq.heappop(hq)
if v == N - 1:
print(d)
exit()
for to, c in es[v]:
if d + c >= dist[to]:
continue
dist[to] = d + c
heapq.heappush(hq, (d + c, to))
print((-1))
| import sys
input = sys.stdin.readline
import heapq
N, M = list(map(int, input().split()))
LRC = [tuple(map(int, input().split())) for i in range(M)]
es = [[] for i in range(N)]
for l, r, c in LRC:
l, r = l - 1, r - 1
es[l].append((r, c))
for i in range(N - 1):
es[i + 1].append((i, 0))
INF = float("inf")
dist = [INF] * N
dist[0] = 0
hq = [(0, 0)]
heapq.heapify(hq)
while hq:
d, v = heapq.heappop(hq)
if v == N - 1:
print(d)
exit()
for to, c in es[v]:
if d + c >= dist[to]:
continue
dist[to] = d + c
heapq.heappush(hq, (d + c, to))
print((-1))
| false | 10 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"-INF = 10**18",
"+INF = float(\"inf\")"
] | false | 0.042394 | 0.042437 | 0.998985 | [
"s718422648",
"s428671367"
] |
u016302627 | p03160 | python | s517465683 | s138417295 | 167 | 123 | 13,976 | 20,464 | Accepted | Accepted | 26.35 | n = int(eval(input()))
H = list(map(int, input().split()))
DP = [10 ** 9] * n
DP[0] = 0
for i in range(1, n):
DP[i] = min(DP[i], DP[i-1] + abs(H[i] - H[i-1]))
if i > 1:
DP[i] = min(DP[i], DP[i-2] + abs(H[i] - H[i-2]))
print((DP[-1])) | n = int(eval(input()))
H = list(map(int, input().split()))
memo = [0 for _ in range(n)]
memo[1] = abs(H[1] - H[0])
for i in range(2, n):
memo[i] = min(memo[i-1] + abs(H[i] - H[i-1]), memo[i-2] + abs(H[i] - H[i-2]))
print((memo[-1])) | 11 | 8 | 253 | 234 | n = int(eval(input()))
H = list(map(int, input().split()))
DP = [10**9] * n
DP[0] = 0
for i in range(1, n):
DP[i] = min(DP[i], DP[i - 1] + abs(H[i] - H[i - 1]))
if i > 1:
DP[i] = min(DP[i], DP[i - 2] + abs(H[i] - H[i - 2]))
print((DP[-1]))
| n = int(eval(input()))
H = list(map(int, input().split()))
memo = [0 for _ in range(n)]
memo[1] = abs(H[1] - H[0])
for i in range(2, n):
memo[i] = min(
memo[i - 1] + abs(H[i] - H[i - 1]), memo[i - 2] + abs(H[i] - H[i - 2])
)
print((memo[-1]))
| false | 27.272727 | [
"-DP = [10**9] * n",
"-DP[0] = 0",
"-for i in range(1, n):",
"- DP[i] = min(DP[i], DP[i - 1] + abs(H[i] - H[i - 1]))",
"- if i > 1:",
"- DP[i] = min(DP[i], DP[i - 2] + abs(H[i] - H[i - 2]))",
"-print((DP[-1]))",
"+memo = [0 for _ in range(n)]",
"+memo[1] = abs(H[1] - H[0])",
"+for i i... | false | 0.0369 | 0.037583 | 0.981841 | [
"s517465683",
"s138417295"
] |
u923279197 | p02861 | python | s582560059 | s367897992 | 216 | 187 | 40,684 | 40,812 | Accepted | Accepted | 13.43 | import itertools,math
def dist(x,y):
return ((x[0]-y[0])**2 + (x[1]-y[1])**2)**(1/2)
n = int(eval(input()))
data = [list(map(int,input().split()))for i in range(n)]
ans = 0
for v in itertools.permutations(data):
for i in range(1,n):
ans += dist(v[i],v[i-1])
print((ans/math.factorial(n))) | from math import sqrt
from itertools import permutations
def dist(a,b):
return sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)
n = int(eval(input()))
data = [list(map(int,input().split())) for _ in range(n)]
ans = 0
for q in permutations(data):
for i in range(1,n):
ans += dist(q[i-1],q[i])
for i in range(n):
ans /= (i+1)
print(ans) | 11 | 14 | 307 | 349 | import itertools, math
def dist(x, y):
return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** (1 / 2)
n = int(eval(input()))
data = [list(map(int, input().split())) for i in range(n)]
ans = 0
for v in itertools.permutations(data):
for i in range(1, n):
ans += dist(v[i], v[i - 1])
print((ans / math.factorial(n)))
| from math import sqrt
from itertools import permutations
def dist(a, b):
return sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
n = int(eval(input()))
data = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for q in permutations(data):
for i in range(1, n):
ans += dist(q[i - 1], q[i])
for i in range(n):
ans /= i + 1
print(ans)
| false | 21.428571 | [
"-import itertools, math",
"+from math import sqrt",
"+from itertools import permutations",
"-def dist(x, y):",
"- return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** (1 / 2)",
"+def dist(a, b):",
"+ return sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)",
"-data = [list(map(int, input().split()))... | false | 0.040616 | 0.042675 | 0.951732 | [
"s582560059",
"s367897992"
] |
u700805562 | p02726 | python | s516134282 | s436059533 | 1,980 | 1,399 | 3,444 | 3,444 | Accepted | Accepted | 29.34 | n, x, y = list(map(int, input().split()))
ans = [0]*(n-1)
for i in range(1, n):
for j in range(i+1, n+1):
res = min(abs(j-i), abs(x-i)+1+abs(j-y), abs(x-j)+1+abs(y-i))
ans[res-1] += 1
for i in ans: print(i) | n, x, y = list(map(int, input().split()))
ans = [0]*(n-1)
for i in range(1, n):
for j in range(i+1, n+1):
ans[min(j-i-1, abs(i-x)+abs(j-y))] += 1
for i in ans:
print(i) | 7 | 7 | 226 | 184 | n, x, y = list(map(int, input().split()))
ans = [0] * (n - 1)
for i in range(1, n):
for j in range(i + 1, n + 1):
res = min(abs(j - i), abs(x - i) + 1 + abs(j - y), abs(x - j) + 1 + abs(y - i))
ans[res - 1] += 1
for i in ans:
print(i)
| n, x, y = list(map(int, input().split()))
ans = [0] * (n - 1)
for i in range(1, n):
for j in range(i + 1, n + 1):
ans[min(j - i - 1, abs(i - x) + abs(j - y))] += 1
for i in ans:
print(i)
| false | 0 | [
"- res = min(abs(j - i), abs(x - i) + 1 + abs(j - y), abs(x - j) + 1 + abs(y - i))",
"- ans[res - 1] += 1",
"+ ans[min(j - i - 1, abs(i - x) + abs(j - y))] += 1"
] | false | 0.038273 | 0.036157 | 1.058522 | [
"s516134282",
"s436059533"
] |
u802963389 | p03037 | python | s883358450 | s053123140 | 405 | 306 | 32,312 | 11,024 | Accepted | Accepted | 24.44 | n, m = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(m)]
ans =[0] * (n + 1)
for l, r in LR:
ans[l - 1] += 1
ans[r] -= 1
accu =[0] * (n + 1)
for i in range(n):
accu[i + 1] += ans[i] + accu[i]
ans = accu.count(m)
print(ans) | n, m = list(map(int, input().split()))
L = []
R = []
for _ in range(m):
l, r = list(map(int, input().split()))
L.append(l)
R.append(r)
ans = max(0, min(R) - max(L) + 1)
print(ans)
| 15 | 12 | 282 | 190 | n, m = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(m)]
ans = [0] * (n + 1)
for l, r in LR:
ans[l - 1] += 1
ans[r] -= 1
accu = [0] * (n + 1)
for i in range(n):
accu[i + 1] += ans[i] + accu[i]
ans = accu.count(m)
print(ans)
| n, m = list(map(int, input().split()))
L = []
R = []
for _ in range(m):
l, r = list(map(int, input().split()))
L.append(l)
R.append(r)
ans = max(0, min(R) - max(L) + 1)
print(ans)
| false | 20 | [
"-LR = [list(map(int, input().split())) for _ in range(m)]",
"-ans = [0] * (n + 1)",
"-for l, r in LR:",
"- ans[l - 1] += 1",
"- ans[r] -= 1",
"-accu = [0] * (n + 1)",
"-for i in range(n):",
"- accu[i + 1] += ans[i] + accu[i]",
"-ans = accu.count(m)",
"+L = []",
"+R = []",
"+for _ in ... | false | 0.076771 | 0.041251 | 1.861063 | [
"s883358450",
"s053123140"
] |
u440566786 | p02890 | python | s211633753 | s027640071 | 514 | 472 | 105,372 | 105,512 | Accepted | Accepted | 8.17 | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def bin_sort(A,n_min=None,n_max=None):
if(n_min is None): n_min=min(A)
if(n_max is None): n_max=max(A)
bin=[0]*(n_max-n_min+1)
for a in A: bin[a-n_min]+=1
B=[]
for i in range(n_min,n_max+1):
for _ in range(bin[i-n_min]): B.append(i)
return B
def resolve():
n=int(eval(input()))
A=[0]*n
for a in map(int,input().split()): A[a-1]+=1
A=bin_sort(A,0,n)
S=[0]*(n+1)
for i in range(n): S[i+1]=S[i]+A[i]
# output
p=n; i=n
for k in range(1,n+1):
while(1):
while(1):
if(i<=0 or A[i-1]<p): break
i-=1
if(S[i]+p*(n-i)>=k*p): break
p-=1
print(p)
resolve() | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def bin_sort(A,n_min=None,n_max=None):
if(n_min is None): n_min=min(A)
if(n_max is None): n_max=max(A)
bin=[0]*(n_max-n_min+1)
for a in A: bin[a-n_min]+=1
B=[]
for i in range(n_min,n_max+1): B.extend([i]*bin[i-n_min])
return B
def resolve():
n=int(eval(input()))
A=[0]*n
for a in map(int,input().split()): A[a-1]+=1
A=bin_sort(A,0,n)
S=[0]*(n+1)
for i in range(n): S[i+1]=S[i]+A[i]
# output
p=n; i=n
for k in range(1,n+1):
while(1):
while(1):
if(i<=0 or A[i-1]<p): break
i-=1
if(S[i]+p*(n-i)>=k*p): break
p-=1
print(p)
resolve() | 33 | 32 | 844 | 820 | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def bin_sort(A, n_min=None, n_max=None):
if n_min is None:
n_min = min(A)
if n_max is None:
n_max = max(A)
bin = [0] * (n_max - n_min + 1)
for a in A:
bin[a - n_min] += 1
B = []
for i in range(n_min, n_max + 1):
for _ in range(bin[i - n_min]):
B.append(i)
return B
def resolve():
n = int(eval(input()))
A = [0] * n
for a in map(int, input().split()):
A[a - 1] += 1
A = bin_sort(A, 0, n)
S = [0] * (n + 1)
for i in range(n):
S[i + 1] = S[i] + A[i]
# output
p = n
i = n
for k in range(1, n + 1):
while 1:
while 1:
if i <= 0 or A[i - 1] < p:
break
i -= 1
if S[i] + p * (n - i) >= k * p:
break
p -= 1
print(p)
resolve()
| import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def bin_sort(A, n_min=None, n_max=None):
if n_min is None:
n_min = min(A)
if n_max is None:
n_max = max(A)
bin = [0] * (n_max - n_min + 1)
for a in A:
bin[a - n_min] += 1
B = []
for i in range(n_min, n_max + 1):
B.extend([i] * bin[i - n_min])
return B
def resolve():
n = int(eval(input()))
A = [0] * n
for a in map(int, input().split()):
A[a - 1] += 1
A = bin_sort(A, 0, n)
S = [0] * (n + 1)
for i in range(n):
S[i + 1] = S[i] + A[i]
# output
p = n
i = n
for k in range(1, n + 1):
while 1:
while 1:
if i <= 0 or A[i - 1] < p:
break
i -= 1
if S[i] + p * (n - i) >= k * p:
break
p -= 1
print(p)
resolve()
| false | 3.030303 | [
"- for _ in range(bin[i - n_min]):",
"- B.append(i)",
"+ B.extend([i] * bin[i - n_min])"
] | false | 0.007448 | 0.039083 | 0.190569 | [
"s211633753",
"s027640071"
] |
u597455618 | p02899 | python | s083626007 | s647132980 | 98 | 71 | 18,376 | 17,736 | Accepted | Accepted | 27.55 | n = int(eval(input()))
h = tuple(map(int, input().split()))
ans = [0]*n
for i in range(n):
ans[h[i]-1] = i+1
print((" ".join(map(str, ans)))) | def main():
n = int(eval(input()))
h = tuple(map(int, input().split()))
ans = [0]*n
for i in range(n):
ans[h[i]-1] = i+1
print((" ".join(map(str, ans))))
if __name__ == "__main__":
main() | 6 | 10 | 140 | 207 | n = int(eval(input()))
h = tuple(map(int, input().split()))
ans = [0] * n
for i in range(n):
ans[h[i] - 1] = i + 1
print((" ".join(map(str, ans))))
| def main():
n = int(eval(input()))
h = tuple(map(int, input().split()))
ans = [0] * n
for i in range(n):
ans[h[i] - 1] = i + 1
print((" ".join(map(str, ans))))
if __name__ == "__main__":
main()
| false | 40 | [
"-n = int(eval(input()))",
"-h = tuple(map(int, input().split()))",
"-ans = [0] * n",
"-for i in range(n):",
"- ans[h[i] - 1] = i + 1",
"-print((\" \".join(map(str, ans))))",
"+def main():",
"+ n = int(eval(input()))",
"+ h = tuple(map(int, input().split()))",
"+ ans = [0] * n",
"+ ... | false | 0.043026 | 0.087515 | 0.491637 | [
"s083626007",
"s647132980"
] |
u396961814 | p03042 | python | s636131318 | s439438288 | 19 | 17 | 3,188 | 3,064 | Accepted | Accepted | 10.53 | N=list(eval(input()))
A=int(''.join(N[0:2]))
B=int(''.join(N[2:4]))
FLG_A = (A>12) or A==0
FLG_B = (B>12) or B==0
if FLG_A & FLG_B:
ans='NA'
elif FLG_A & ~FLG_B:
ans='YYMM'
elif ~FLG_A & FLG_B:
ans='MMYY'
elif ~FLG_A & ~FLG_B:
ans='AMBIGUOUS'
print(ans) | N=list(eval(input()))
A=int(''.join(N[0:2]))
B=int(''.join(N[2:4]))
FLG_A = (A>12) | (A==0)
FLG_B = (B>12) | (B==0)
if FLG_A & FLG_B:
ans='NA'
elif FLG_A & ~FLG_B:
ans='YYMM'
elif ~FLG_A & FLG_B:
ans='MMYY'
elif ~FLG_A & ~FLG_B:
ans='AMBIGUOUS'
print(ans) | 18 | 18 | 284 | 286 | N = list(eval(input()))
A = int("".join(N[0:2]))
B = int("".join(N[2:4]))
FLG_A = (A > 12) or A == 0
FLG_B = (B > 12) or B == 0
if FLG_A & FLG_B:
ans = "NA"
elif FLG_A & ~FLG_B:
ans = "YYMM"
elif ~FLG_A & FLG_B:
ans = "MMYY"
elif ~FLG_A & ~FLG_B:
ans = "AMBIGUOUS"
print(ans)
| N = list(eval(input()))
A = int("".join(N[0:2]))
B = int("".join(N[2:4]))
FLG_A = (A > 12) | (A == 0)
FLG_B = (B > 12) | (B == 0)
if FLG_A & FLG_B:
ans = "NA"
elif FLG_A & ~FLG_B:
ans = "YYMM"
elif ~FLG_A & FLG_B:
ans = "MMYY"
elif ~FLG_A & ~FLG_B:
ans = "AMBIGUOUS"
print(ans)
| false | 0 | [
"-FLG_A = (A > 12) or A == 0",
"-FLG_B = (B > 12) or B == 0",
"+FLG_A = (A > 12) | (A == 0)",
"+FLG_B = (B > 12) | (B == 0)"
] | false | 0.051028 | 0.051588 | 0.989134 | [
"s636131318",
"s439438288"
] |
u949338836 | p02260 | python | s402519290 | s341670837 | 40 | 30 | 6,724 | 7,708 | Accepted | Accepted | 25 | #coding:utf-8
n = int(eval(input()))
numbers = list(map(int, input().split()))
def selectionSort(ary):
count = 0
for i in range(len(ary)):
minj = i
for j in range(i, len(ary)):
if ary[minj] > ary[j]:
minj = j
if minj != i:
ary[minj], ary[i] = ary[i], ary[minj]
count += 1
return (ary, count)
result = selectionSort(numbers)
print((*result[0]))
print((result[1])) | #coding:utf-8
#1_2_B
def selection_sort(ary, n):
count = 0
for i in range(n):
minj = i
for j in range(i, n):
if ary[minj] > ary[j]:
minj = j
if ary[minj] != ary[i]:
ary[minj], ary[i] = ary[i], ary[minj]
count += 1
print((*ary))
print(count)
n = int(eval(input()))
selection_sort(list(map(int, input().split())), n) | 19 | 17 | 460 | 415 | # coding:utf-8
n = int(eval(input()))
numbers = list(map(int, input().split()))
def selectionSort(ary):
count = 0
for i in range(len(ary)):
minj = i
for j in range(i, len(ary)):
if ary[minj] > ary[j]:
minj = j
if minj != i:
ary[minj], ary[i] = ary[i], ary[minj]
count += 1
return (ary, count)
result = selectionSort(numbers)
print((*result[0]))
print((result[1]))
| # coding:utf-8
# 1_2_B
def selection_sort(ary, n):
count = 0
for i in range(n):
minj = i
for j in range(i, n):
if ary[minj] > ary[j]:
minj = j
if ary[minj] != ary[i]:
ary[minj], ary[i] = ary[i], ary[minj]
count += 1
print((*ary))
print(count)
n = int(eval(input()))
selection_sort(list(map(int, input().split())), n)
| false | 10.526316 | [
"-n = int(eval(input()))",
"-numbers = list(map(int, input().split()))",
"+# 1_2_B",
"+def selection_sort(ary, n):",
"+ count = 0",
"+ for i in range(n):",
"+ minj = i",
"+ for j in range(i, n):",
"+ if ary[minj] > ary[j]:",
"+ minj = j",
"+ i... | false | 0.046968 | 0.07489 | 0.627159 | [
"s402519290",
"s341670837"
] |
u863397945 | p02983 | python | s055084304 | s433206157 | 835 | 681 | 9,080 | 9,152 | Accepted | Accepted | 18.44 | L,R = list(map(int,input().split()))
ans = 2018
for i in range(L,min(R,L+2100)):
for j in range(i+1,min(R+1,i+2100)):
if (i*j) % 2019 <= ans:
ans = (i*j) % 2019
print(ans) | #! python3
# solve_133C.py
L,R = list(map(int,input().split()))
ans = 3000
for i in range(L,min(R,L+2019)):
for j in range(i+1,min(R+1,L+2019)):
ans = min(ans,i*j%2019)
print(ans) | 10 | 12 | 201 | 209 | L, R = list(map(int, input().split()))
ans = 2018
for i in range(L, min(R, L + 2100)):
for j in range(i + 1, min(R + 1, i + 2100)):
if (i * j) % 2019 <= ans:
ans = (i * j) % 2019
print(ans)
| #! python3
# solve_133C.py
L, R = list(map(int, input().split()))
ans = 3000
for i in range(L, min(R, L + 2019)):
for j in range(i + 1, min(R + 1, L + 2019)):
ans = min(ans, i * j % 2019)
print(ans)
| false | 16.666667 | [
"+#! python3",
"+# solve_133C.py",
"-ans = 2018",
"-for i in range(L, min(R, L + 2100)):",
"- for j in range(i + 1, min(R + 1, i + 2100)):",
"- if (i * j) % 2019 <= ans:",
"- ans = (i * j) % 2019",
"+ans = 3000",
"+for i in range(L, min(R, L + 2019)):",
"+ for j in range(i... | false | 0.118738 | 0.083408 | 1.423572 | [
"s055084304",
"s433206157"
] |
u716530146 | p03037 | python | s516330311 | s712264621 | 311 | 260 | 56,284 | 54,108 | Accepted | Accepted | 16.4 | #!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
n, m = list(map(int, input().split()))
data = [list(map(int, input().split())) for i in range(m)]
l, r = 0, 10**6
for i, j in data:
l = max(l, i)
r = min(r, j)
print((max(0, r-l+1)))
| #!/usr/bin/env python3
import sys
input = lambda: sys.stdin.buffer.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
n, m = list(map(int, input().split()))
data = [list(map(int, input().split())) for i in range(m)]
l, r = 0, 10**6
for i, j in data:
l = max(l, i)
r = min(r, j)
print((max(0, r-l+1)))
| 20 | 20 | 341 | 348 | #!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float("inf")
mod = 10**9 + 7
n, m = list(map(int, input().split()))
data = [list(map(int, input().split())) for i in range(m)]
l, r = 0, 10**6
for i, j in data:
l = max(l, i)
r = min(r, j)
print((max(0, r - l + 1)))
| #!/usr/bin/env python3
import sys
input = lambda: sys.stdin.buffer.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float("inf")
mod = 10**9 + 7
n, m = list(map(int, input().split()))
data = [list(map(int, input().split())) for i in range(m)]
l, r = 0, 10**6
for i, j in data:
l = max(l, i)
r = min(r, j)
print((max(0, r - l + 1)))
| false | 0 | [
"-input = lambda: sys.stdin.readline()[:-1]",
"+input = lambda: sys.stdin.buffer.readline()[:-1]"
] | false | 0.038479 | 0.037493 | 1.02628 | [
"s516330311",
"s712264621"
] |
u350248178 | p03329 | python | s707202007 | s295819416 | 612 | 383 | 3,864 | 3,060 | Accepted | Accepted | 37.42 | n=int(eval(input()))
dp=[100001 for i in range(n+1)]
dp[0]=0
for i in range(1,n+1):
p=1
while p<=i:
dp[i]=min(dp[i],dp[i-p]+1)
p*=6
q=1
while q<=i:
dp[i]=min(dp[i],dp[i-q]+1)
q*=9
print((dp[n])) | n=int(eval(input()))
ans=10**100
for t in range(n+1):
p=t
q=n-p
c=0
while p>0:
c+=p%6
p=p//6
while q>0:
c+=q%9
q=q//9
ans=min(ans,c)
print(ans)
| 16 | 20 | 252 | 219 | n = int(eval(input()))
dp = [100001 for i in range(n + 1)]
dp[0] = 0
for i in range(1, n + 1):
p = 1
while p <= i:
dp[i] = min(dp[i], dp[i - p] + 1)
p *= 6
q = 1
while q <= i:
dp[i] = min(dp[i], dp[i - q] + 1)
q *= 9
print((dp[n]))
| n = int(eval(input()))
ans = 10**100
for t in range(n + 1):
p = t
q = n - p
c = 0
while p > 0:
c += p % 6
p = p // 6
while q > 0:
c += q % 9
q = q // 9
ans = min(ans, c)
print(ans)
| false | 20 | [
"-dp = [100001 for i in range(n + 1)]",
"-dp[0] = 0",
"-for i in range(1, n + 1):",
"- p = 1",
"- while p <= i:",
"- dp[i] = min(dp[i], dp[i - p] + 1)",
"- p *= 6",
"- q = 1",
"- while q <= i:",
"- dp[i] = min(dp[i], dp[i - q] + 1)",
"- q *= 9",
"-print(... | false | 0.238316 | 0.153106 | 1.556549 | [
"s707202007",
"s295819416"
] |
u373047809 | p03241 | python | s557205996 | s645136974 | 1,958 | 411 | 2,940 | 38,512 | Accepted | Accepted | 79.01 | n,m=list(map(int,input().split()));print((next(v for v in range(m//n,-1,-1)if m%v==0))) | n,m=list(map(int,input().split()));print((next(v for v in range(m//n+1)[::-1]if m%v<1))) | 1 | 1 | 79 | 80 | n, m = list(map(int, input().split()))
print((next(v for v in range(m // n, -1, -1) if m % v == 0)))
| n, m = list(map(int, input().split()))
print((next(v for v in range(m // n + 1)[::-1] if m % v < 1)))
| false | 0 | [
"-print((next(v for v in range(m // n, -1, -1) if m % v == 0)))",
"+print((next(v for v in range(m // n + 1)[::-1] if m % v < 1)))"
] | false | 0.064106 | 0.048548 | 1.320484 | [
"s557205996",
"s645136974"
] |
u753803401 | p02972 | python | s618552410 | s977765608 | 535 | 312 | 14,096 | 65,884 | Accepted | Accepted | 41.68 | n = int(eval(input()))
a = list(map(int, input().split()))
ls = [0] * n
ans = []
for i in range(n-1, -1, -1):
t = 0
for j in range(i, n, (i + 1)):
t += ls[j]
if a[i] != t % 2:
ans.append(i + 1)
ls[i] = 1
print((len(ans)))
if len(ans) != 0:
print((*ans))
| def slove():
import sys
input = sys.stdin.readline
n = int(input().rstrip('\n'))
a = list(map(int, input().rstrip('\n').split()))
b = [0] * n
ans = []
for i in range(n-1, -1, -1):
cnt = 0
for j in range(i, n, i + 1):
cnt += b[j]
if cnt % 2 != a[i]:
b[i] += 1
ans.append(i + 1)
print((len(ans)))
if len(ans) != 0:
print((*ans))
if __name__ == '__main__':
slove()
| 14 | 21 | 297 | 488 | n = int(eval(input()))
a = list(map(int, input().split()))
ls = [0] * n
ans = []
for i in range(n - 1, -1, -1):
t = 0
for j in range(i, n, (i + 1)):
t += ls[j]
if a[i] != t % 2:
ans.append(i + 1)
ls[i] = 1
print((len(ans)))
if len(ans) != 0:
print((*ans))
| def slove():
import sys
input = sys.stdin.readline
n = int(input().rstrip("\n"))
a = list(map(int, input().rstrip("\n").split()))
b = [0] * n
ans = []
for i in range(n - 1, -1, -1):
cnt = 0
for j in range(i, n, i + 1):
cnt += b[j]
if cnt % 2 != a[i]:
b[i] += 1
ans.append(i + 1)
print((len(ans)))
if len(ans) != 0:
print((*ans))
if __name__ == "__main__":
slove()
| false | 33.333333 | [
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-ls = [0] * n",
"-ans = []",
"-for i in range(n - 1, -1, -1):",
"- t = 0",
"- for j in range(i, n, (i + 1)):",
"- t += ls[j]",
"- if a[i] != t % 2:",
"- ans.append(i + 1)",
"- ls[i] = 1",
"-print(... | false | 0.044858 | 0.044862 | 0.999897 | [
"s618552410",
"s977765608"
] |
u392319141 | p03946 | python | s591498330 | s361854109 | 237 | 118 | 22,164 | 15,020 | Accepted | Accepted | 50.21 | N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
mi = 10**18
miCnt = 1
S = []
for i, a in enumerate(A):
S.append((a - mi, i, miCnt))
if a == mi:
miCnt += 1
mi = min(mi, a)
S.sort(reverse=True)
S = [c for v, i, c in S if v == S[0][0]]
ans = min(len(S), sum(S))
print(ans)
| N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
mx = [0] * (N + 1)
for i, a in enumerate(A[::-1], start=1):
mx[-i] = max(mx[-i + 1], a)
mxD = 0
ans = 0
for i, a in enumerate(A):
d = mx[i + 1] - a
if mxD < d:
mxD = d
ans = 0
if mxD == d:
ans += 1
print(ans)
| 16 | 18 | 328 | 338 | N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
mi = 10**18
miCnt = 1
S = []
for i, a in enumerate(A):
S.append((a - mi, i, miCnt))
if a == mi:
miCnt += 1
mi = min(mi, a)
S.sort(reverse=True)
S = [c for v, i, c in S if v == S[0][0]]
ans = min(len(S), sum(S))
print(ans)
| N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
mx = [0] * (N + 1)
for i, a in enumerate(A[::-1], start=1):
mx[-i] = max(mx[-i + 1], a)
mxD = 0
ans = 0
for i, a in enumerate(A):
d = mx[i + 1] - a
if mxD < d:
mxD = d
ans = 0
if mxD == d:
ans += 1
print(ans)
| false | 11.111111 | [
"-mi = 10**18",
"-miCnt = 1",
"-S = []",
"+mx = [0] * (N + 1)",
"+for i, a in enumerate(A[::-1], start=1):",
"+ mx[-i] = max(mx[-i + 1], a)",
"+mxD = 0",
"+ans = 0",
"- S.append((a - mi, i, miCnt))",
"- if a == mi:",
"- miCnt += 1",
"- mi = min(mi, a)",
"-S.sort(reverse=Tr... | false | 0.038966 | 0.039657 | 0.98258 | [
"s591498330",
"s361854109"
] |
u863442865 | p03780 | python | s677638257 | s208422681 | 825 | 20 | 38,688 | 3,572 | Accepted | Accepted | 97.58 | def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations
#from itertools import accumulate, product
from bisect import bisect_left,bisect_right
from math import floor, ceil
#from operator import itemgetter
import numpy as np
#mod = 1000000007
N,K = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
def check(num):
dp = np.zeros((N+1, K), dtype=np.bool)
dp[0,0] = 1
for i in range(N):
# まとめて遷移
dp[i+1] |= dp[i]
#i番目のカードはスルー
if i != num and a[i] < K:
dp[i+1,a[i]:] |= dp[i,:K-a[i]]
return any(dp[N, -a[num]:])
left = -1
right = N
while right - left > 1:
mid = (left+right)//2
if check(mid):
right = mid
else:
left = mid
print(right)
# 間に合わないよ~><
# def dp(num):
# dp = [[0]*(K) for _ in range(n)]
# dp[0][0] = 1
# b = a[:num]+a[num+1:] #N-1個
# for i in range(n-1):
# for j in range(K):
# if b[i]<=j:
# dp[i+1][j] = dp[i][j-b[i]] or dp[i][j]
# else:
# dp[i+1][j]=dp[i][j]
# return any(dp[n-1][K-a[num]:])
if __name__ == '__main__':
main() | def d_no_need(N, K, A):
card = sorted(A, reverse=True)
s = 0
ans = 0
for a in card:
if s + a < K:
s += a
ans += 1
else:
ans = 0
return ans
N,K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print((d_no_need(N, K, A)))
| 54 | 15 | 1,529 | 330 | def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import Counter, deque
# from collections import defaultdict
from itertools import combinations, permutations
# from itertools import accumulate, product
from bisect import bisect_left, bisect_right
from math import floor, ceil
# from operator import itemgetter
import numpy as np
# mod = 1000000007
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
def check(num):
dp = np.zeros((N + 1, K), dtype=np.bool)
dp[0, 0] = 1
for i in range(N):
# まとめて遷移
dp[i + 1] |= dp[i]
# i番目のカードはスルー
if i != num and a[i] < K:
dp[i + 1, a[i] :] |= dp[i, : K - a[i]]
return any(dp[N, -a[num] :])
left = -1
right = N
while right - left > 1:
mid = (left + right) // 2
if check(mid):
right = mid
else:
left = mid
print(right)
# 間に合わないよ~><
# def dp(num):
# dp = [[0]*(K) for _ in range(n)]
# dp[0][0] = 1
# b = a[:num]+a[num+1:] #N-1個
# for i in range(n-1):
# for j in range(K):
# if b[i]<=j:
# dp[i+1][j] = dp[i][j-b[i]] or dp[i][j]
# else:
# dp[i+1][j]=dp[i][j]
# return any(dp[n-1][K-a[num]:])
if __name__ == "__main__":
main()
| def d_no_need(N, K, A):
card = sorted(A, reverse=True)
s = 0
ans = 0
for a in card:
if s + a < K:
s += a
ans += 1
else:
ans = 0
return ans
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print((d_no_need(N, K, A)))
| false | 72.222222 | [
"-def main():",
"- import sys",
"-",
"- input = sys.stdin.readline",
"- sys.setrecursionlimit(10000000)",
"- from collections import Counter, deque",
"-",
"- # from collections import defaultdict",
"- from itertools import combinations, permutations",
"-",
"- # from itertool... | false | 0.395863 | 0.035438 | 11.170514 | [
"s677638257",
"s208422681"
] |
u583507988 | p02802 | python | s404217193 | s248071428 | 436 | 217 | 4,724 | 9,348 | Accepted | Accepted | 50.23 | n, m = list(map(int, input().split()))
ac = 0
wa = 0
res1 = [0]*n
res2 = [0]*n
for i in range(m):
p, s = list(map(str, input().split()))
if s == 'AC' and res1[int(p)-1] == 0:
ac += 1
res1[int(p)-1] = 1
wa += res2[int(p)-1]
elif s == 'WA' and res1[int(p)-1] == 0:
res2[int(p)-1] += 1
print((ac, wa)) | n,m=list(map(int,input().split()))
ac=[0]*(n+1)
wa=0
for i in range(m):
p,c=input().split()
if c=='WA' and ac[int(p)]!=1:
ac[int(p)]-=1
elif c=='AC' and ac[int(p)]!=1:
wa+=abs(ac[int(p)])
ac[int(p)]=1
print((ac.count(1),wa)) | 15 | 11 | 327 | 244 | n, m = list(map(int, input().split()))
ac = 0
wa = 0
res1 = [0] * n
res2 = [0] * n
for i in range(m):
p, s = list(map(str, input().split()))
if s == "AC" and res1[int(p) - 1] == 0:
ac += 1
res1[int(p) - 1] = 1
wa += res2[int(p) - 1]
elif s == "WA" and res1[int(p) - 1] == 0:
res2[int(p) - 1] += 1
print((ac, wa))
| n, m = list(map(int, input().split()))
ac = [0] * (n + 1)
wa = 0
for i in range(m):
p, c = input().split()
if c == "WA" and ac[int(p)] != 1:
ac[int(p)] -= 1
elif c == "AC" and ac[int(p)] != 1:
wa += abs(ac[int(p)])
ac[int(p)] = 1
print((ac.count(1), wa))
| false | 26.666667 | [
"-ac = 0",
"+ac = [0] * (n + 1)",
"-res1 = [0] * n",
"-res2 = [0] * n",
"- p, s = list(map(str, input().split()))",
"- if s == \"AC\" and res1[int(p) - 1] == 0:",
"- ac += 1",
"- res1[int(p) - 1] = 1",
"- wa += res2[int(p) - 1]",
"- elif s == \"WA\" and res1[int(p) - ... | false | 0.0918 | 0.044061 | 2.083466 | [
"s404217193",
"s248071428"
] |
u567281053 | p02279 | python | s991558425 | s488639515 | 840 | 720 | 67,660 | 67,740 | Accepted | Accepted | 14.29 | import sys
class Node:
def __init__(self):
self.id = 0
self.parent = -1
self.depth = 0
self.type = "root"
self.children = []
def addDepth(id, tree):
tree[id].depth += 1
for child in tree[id].children:
addDepth(child, tree)
if __name__ == "__main__":
lines = sys.stdin.readlines()
N = int(lines[0])
del lines[0]
tree = []
for i in range(N):
tree.append(Node())
for line in lines:
line = list(map(int, line.split()))
tree[line[0]].id = line[0]
tree[line[0]].children = line[2:]
for node in tree:
for child in node.children:
tree[child].parent = node.id
addDepth(child, tree)
if tree[child].children:
tree[child].type = "internal node"
else:
tree[child].type = "leaf"
for node in tree:
print("node {0.id}: parent = {0.parent}, depth = {0.depth}, {0.type}, {0.children}".format(node)) | import sys
class Node:
def __init__(self):
self.id = -1
self.parent = -1
self.type = "leaf"
def printInfo(self):
print("node {0.id}: parent = {0.parent}, depth = {0.depth}, {0.type}, {0.children}".format(self))
def setTree(id, tree, depth):
tree[id].depth = depth
if not tree[id].children:
return
for child in tree[id].children:
tree[child].parent = id
setTree(child, tree, depth + 1)
tree[id].type = "internal node"
if __name__ == "__main__":
lines = sys.stdin.readlines()
N = int(lines[0])
del lines[0]
tree = []
for i in range(N):
tree.append(Node())
root = N * (N - 1) / 2
for line in lines:
info = list(map(int, line.split()))
tree[info[0]].children = info[2:]
tree[info[0]].id = info[0]
for i in tree[info[0]].children:
root -= i
setTree(root, tree, 0)
tree[root].type = "root"
for node in tree:
node.printInfo() | 40 | 43 | 1,039 | 1,042 | import sys
class Node:
def __init__(self):
self.id = 0
self.parent = -1
self.depth = 0
self.type = "root"
self.children = []
def addDepth(id, tree):
tree[id].depth += 1
for child in tree[id].children:
addDepth(child, tree)
if __name__ == "__main__":
lines = sys.stdin.readlines()
N = int(lines[0])
del lines[0]
tree = []
for i in range(N):
tree.append(Node())
for line in lines:
line = list(map(int, line.split()))
tree[line[0]].id = line[0]
tree[line[0]].children = line[2:]
for node in tree:
for child in node.children:
tree[child].parent = node.id
addDepth(child, tree)
if tree[child].children:
tree[child].type = "internal node"
else:
tree[child].type = "leaf"
for node in tree:
print(
"node {0.id}: parent = {0.parent}, depth = {0.depth}, {0.type}, {0.children}".format(
node
)
)
| import sys
class Node:
def __init__(self):
self.id = -1
self.parent = -1
self.type = "leaf"
def printInfo(self):
print(
"node {0.id}: parent = {0.parent}, depth = {0.depth}, {0.type}, {0.children}".format(
self
)
)
def setTree(id, tree, depth):
tree[id].depth = depth
if not tree[id].children:
return
for child in tree[id].children:
tree[child].parent = id
setTree(child, tree, depth + 1)
tree[id].type = "internal node"
if __name__ == "__main__":
lines = sys.stdin.readlines()
N = int(lines[0])
del lines[0]
tree = []
for i in range(N):
tree.append(Node())
root = N * (N - 1) / 2
for line in lines:
info = list(map(int, line.split()))
tree[info[0]].children = info[2:]
tree[info[0]].id = info[0]
for i in tree[info[0]].children:
root -= i
setTree(root, tree, 0)
tree[root].type = "root"
for node in tree:
node.printInfo()
| false | 6.976744 | [
"- self.id = 0",
"+ self.id = -1",
"- self.depth = 0",
"- self.type = \"root\"",
"- self.children = []",
"+ self.type = \"leaf\"",
"+",
"+ def printInfo(self):",
"+ print(",
"+ \"node {0.id}: parent = {0.parent}, depth = {0.depth}, {0.... | false | 0.043653 | 0.044064 | 0.990667 | [
"s991558425",
"s488639515"
] |
u388927326 | p03045 | python | s181335147 | s473966114 | 456 | 300 | 16,016 | 15,952 | Accepted | Accepted | 34.21 | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
def main():
n, m = list(map(int, input().split()))
parents = [i for i in range(n)]
for i in range(m):
x, y, z = list(map(int, input().split()))
unite(x - 1, y - 1, parents)
uniq = {find(i, parents) for i in range(n)}
print((len(uniq)))
def unite(x, y, parents):
px = find(x, parents)
py = find(y, parents)
parents[py] = px
def find(x, parents):
if parents[x] == x:
return x
fx = find(parents[x], parents)
parents[x] = fx
return fx
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
def main():
n, m = list(map(int, input().split()))
parents = [i for i in range(n)]
for i in range(m):
x, y, z = list(map(int, sys.stdin.readline().split()))
unite(x - 1, y - 1, parents)
uniq = {find(i, parents) for i in range(n)}
print((len(uniq)))
def unite(x, y, parents):
px = find(x, parents)
py = find(y, parents)
parents[py] = px
def find(x, parents):
if parents[x] == x:
return x
fx = find(parents[x], parents)
parents[x] = fx
return fx
if __name__ == "__main__":
main()
| 28 | 28 | 624 | 637 | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
def main():
n, m = list(map(int, input().split()))
parents = [i for i in range(n)]
for i in range(m):
x, y, z = list(map(int, input().split()))
unite(x - 1, y - 1, parents)
uniq = {find(i, parents) for i in range(n)}
print((len(uniq)))
def unite(x, y, parents):
px = find(x, parents)
py = find(y, parents)
parents[py] = px
def find(x, parents):
if parents[x] == x:
return x
fx = find(parents[x], parents)
parents[x] = fx
return fx
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
def main():
n, m = list(map(int, input().split()))
parents = [i for i in range(n)]
for i in range(m):
x, y, z = list(map(int, sys.stdin.readline().split()))
unite(x - 1, y - 1, parents)
uniq = {find(i, parents) for i in range(n)}
print((len(uniq)))
def unite(x, y, parents):
px = find(x, parents)
py = find(y, parents)
parents[py] = px
def find(x, parents):
if parents[x] == x:
return x
fx = find(parents[x], parents)
parents[x] = fx
return fx
if __name__ == "__main__":
main()
| false | 0 | [
"- x, y, z = list(map(int, input().split()))",
"+ x, y, z = list(map(int, sys.stdin.readline().split()))"
] | false | 0.094333 | 0.050289 | 1.875814 | [
"s181335147",
"s473966114"
] |
u761989513 | p03999 | python | s336449294 | s428919226 | 20 | 18 | 3,060 | 3,060 | Accepted | Accepted | 10 | s = eval(input())
n = len(s)
ans = 0
for bit in range(1 << (n - 1)):
f = s[0]
for i in range(n - 1):
if bit & (1 << i):
f += "+"
f += s[i + 1]
ans += sum(map(int, f.split("+")))
print(ans) | def dfs(i, f):
if i == n - 1:
return sum(list(map(int, f.split("+"))))
return dfs(i + 1, f + s[i + 1]) +\
dfs(i + 1, f + "+" + s[i + 1])
s = input()
n = len(s)
print(dfs(0, s[0]))
| 11 | 10 | 232 | 217 | s = eval(input())
n = len(s)
ans = 0
for bit in range(1 << (n - 1)):
f = s[0]
for i in range(n - 1):
if bit & (1 << i):
f += "+"
f += s[i + 1]
ans += sum(map(int, f.split("+")))
print(ans)
| def dfs(i, f):
if i == n - 1:
return sum(list(map(int, f.split("+"))))
return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1])
s = input()
n = len(s)
print(dfs(0, s[0]))
| false | 9.090909 | [
"-s = eval(input())",
"+def dfs(i, f):",
"+ if i == n - 1:",
"+ return sum(list(map(int, f.split(\"+\"))))",
"+ return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + \"+\" + s[i + 1])",
"+",
"+",
"+s = input()",
"-ans = 0",
"-for bit in range(1 << (n - 1)):",
"- f = s[0]",
"- for... | false | 0.045598 | 0.045 | 1.013288 | [
"s336449294",
"s428919226"
] |
u561083515 | p03044 | python | s811604845 | s982659106 | 848 | 672 | 50,236 | 43,028 | Accepted | Accepted | 20.75 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from collections import deque
N = int(eval(input()))
edge = [[] for _ in range(N)]
for i in range(N-1):
u,v,w = list(map(int,input().split()))
edge[u-1].append([v-1,w])
edge[v-1].append([u-1,w])
# 親を探索(頂点0を根)
parent = [0] * N
for v,_ in edge[0]:
parent[v] = 0
open_list = deque([0])
while open_list:
now = open_list.popleft()
for v,w in edge[now]:
if v == parent[now]:
continue
open_list.append(v)
parent[v] = now
# 根からの距離を探索
path = [0] * N
open_list = deque([0])
while open_list:
now = open_list.popleft()
for v,w in edge[now]:
if v == parent[now]:
continue
open_list.append(v)
path[v] = path[now] + w
for i in path:
if i % 2 == 0:
print((0))
else:
print((1)) | from collections import deque
N = int(eval(input()))
edge = [[] for _ in range(N)]
for _ in range(N-1):
u,v,w = list(map(int, input().split()))
edge[u-1].append((v-1, w))
edge[v-1].append((u-1, w))
dist = [-1] * N
dist[0] = 0
que = deque([0])
while que:
u = que.popleft()
d = dist[u]
for v,w in edge[u]:
if dist[v] > 0:
continue
dist[v] = d + w
que.append(v)
for d in dist:
if d % 2 == 0:
print((0))
else:
print((1)) | 42 | 27 | 887 | 514 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import deque
N = int(eval(input()))
edge = [[] for _ in range(N)]
for i in range(N - 1):
u, v, w = list(map(int, input().split()))
edge[u - 1].append([v - 1, w])
edge[v - 1].append([u - 1, w])
# 親を探索(頂点0を根)
parent = [0] * N
for v, _ in edge[0]:
parent[v] = 0
open_list = deque([0])
while open_list:
now = open_list.popleft()
for v, w in edge[now]:
if v == parent[now]:
continue
open_list.append(v)
parent[v] = now
# 根からの距離を探索
path = [0] * N
open_list = deque([0])
while open_list:
now = open_list.popleft()
for v, w in edge[now]:
if v == parent[now]:
continue
open_list.append(v)
path[v] = path[now] + w
for i in path:
if i % 2 == 0:
print((0))
else:
print((1))
| from collections import deque
N = int(eval(input()))
edge = [[] for _ in range(N)]
for _ in range(N - 1):
u, v, w = list(map(int, input().split()))
edge[u - 1].append((v - 1, w))
edge[v - 1].append((u - 1, w))
dist = [-1] * N
dist[0] = 0
que = deque([0])
while que:
u = que.popleft()
d = dist[u]
for v, w in edge[u]:
if dist[v] > 0:
continue
dist[v] = d + w
que.append(v)
for d in dist:
if d % 2 == 0:
print((0))
else:
print((1))
| false | 35.714286 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-sys.setrecursionlimit(10**7)",
"-for i in range(N - 1):",
"+for _ in range(N - 1):",
"- edge[u - 1].append([v - 1, w])",
"- edge[v - 1].append([u - 1, w])",
"-# 親を探索(頂点0を根)",
"-parent = [0] * N",
"-for v, _ in edge[0]:",
"- parent[v... | false | 0.063543 | 0.058608 | 1.084197 | [
"s811604845",
"s982659106"
] |
u581187895 | p03495 | python | s546551280 | s169801154 | 201 | 173 | 42,520 | 39,348 | Accepted | Accepted | 13.93 | from collections import Counter
n, k = list(map(int, input().split()))
arr = Counter(input().split())
chenge = len(arr) - k
count = 0
for k, v in arr.most_common()[::-1]:
if chenge > 0:
count += v
chenge -= 1
print(count)
| from collections import Counter
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A = Counter(A).most_common() # 降順 type=list
# 数が少ないものを変更する
cnt = A[K:]
print((sum([v for k, v in cnt])))
| 14 | 9 | 252 | 214 | from collections import Counter
n, k = list(map(int, input().split()))
arr = Counter(input().split())
chenge = len(arr) - k
count = 0
for k, v in arr.most_common()[::-1]:
if chenge > 0:
count += v
chenge -= 1
print(count)
| from collections import Counter
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A = Counter(A).most_common() # 降順 type=list
# 数が少ないものを変更する
cnt = A[K:]
print((sum([v for k, v in cnt])))
| false | 35.714286 | [
"-n, k = list(map(int, input().split()))",
"-arr = Counter(input().split())",
"-chenge = len(arr) - k",
"-count = 0",
"-for k, v in arr.most_common()[::-1]:",
"- if chenge > 0:",
"- count += v",
"- chenge -= 1",
"-print(count)",
"+N, K = list(map(int, input().split()))",
"+A = l... | false | 0.145036 | 0.085847 | 1.689463 | [
"s546551280",
"s169801154"
] |
u029000441 | p03252 | python | s712091335 | s130731699 | 118 | 46 | 3,900 | 5,548 | Accepted | Accepted | 61.02 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()
s=input().rstrip()
t=input().rstrip()
u=Counter(s)
v=Counter(t)
for i in range(len(s)):
if u[s[i]]!=v[t[i]]:
print("No")
#print(i)
sys.exit()
print("Yes") | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()
alphasm=[chr(i) for i in range(97, 97+26)]
s=input().rstrip()
t=input().rstrip()
u=Counter(list(s))
v=Counter(list(t))
a,b=[],[]
for i in alphasm:
a.append(u[i])
b.append(v[i])
a.sort()
b.sort()
if a==b:
print("Yes")
else:
print("No") | 31 | 37 | 936 | 1,011 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def LI2():
return [int(eval(input())) for i in range(n)]
def MXI():
return [[LI()] for i in range(n)]
def printns(x):
print(("\n".join(x)))
def printni(x):
print(("\n".join(list(map(str, x)))))
inf = 10**17
mod = 10**9 + 7
# s=input().rstrip()
s = input().rstrip()
t = input().rstrip()
u = Counter(s)
v = Counter(t)
for i in range(len(s)):
if u[s[i]] != v[t[i]]:
print("No")
# print(i)
sys.exit()
print("Yes")
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def LI2():
return [int(eval(input())) for i in range(n)]
def MXI():
return [[LI()] for i in range(n)]
def printns(x):
print(("\n".join(x)))
def printni(x):
print(("\n".join(list(map(str, x)))))
inf = 10**17
mod = 10**9 + 7
# s=input().rstrip()
alphasm = [chr(i) for i in range(97, 97 + 26)]
s = input().rstrip()
t = input().rstrip()
u = Counter(list(s))
v = Counter(list(t))
a, b = [], []
for i in alphasm:
a.append(u[i])
b.append(v[i])
a.sort()
b.sort()
if a == b:
print("Yes")
else:
print("No")
| false | 16.216216 | [
"+alphasm = [chr(i) for i in range(97, 97 + 26)]",
"-u = Counter(s)",
"-v = Counter(t)",
"-for i in range(len(s)):",
"- if u[s[i]] != v[t[i]]:",
"- print(\"No\")",
"- # print(i)",
"- sys.exit()",
"-print(\"Yes\")",
"+u = Counter(list(s))",
"+v = Counter(list(t))",
"+a, ... | false | 0.035216 | 0.042932 | 0.820283 | [
"s712091335",
"s130731699"
] |
u226108478 | p02952 | python | s305952159 | s175904544 | 85 | 77 | 2,940 | 2,940 | Accepted | Accepted | 9.41 | # -*- coding: utf-8 -*-
def main():
n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
if len(list(str(i))) % 2 == 1:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
def count_digit(n: int) -> int:
digit = 0
while n:
digit += 1
n //= 10
return digit
def main():
n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
if count_digit(i) % 2 == 1:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| 16 | 26 | 233 | 356 | # -*- coding: utf-8 -*-
def main():
n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
if len(list(str(i))) % 2 == 1:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
def count_digit(n: int) -> int:
digit = 0
while n:
digit += 1
n //= 10
return digit
def main():
n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
if count_digit(i) % 2 == 1:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 38.461538 | [
"+def count_digit(n: int) -> int:",
"+ digit = 0",
"+ while n:",
"+ digit += 1",
"+ n //= 10",
"+ return digit",
"+",
"+",
"- if len(list(str(i))) % 2 == 1:",
"+ if count_digit(i) % 2 == 1:"
] | false | 0.106248 | 0.091946 | 1.155545 | [
"s305952159",
"s175904544"
] |
u852690916 | p02792 | python | s974253088 | s062925482 | 1,025 | 273 | 43,228 | 46,188 | Accepted | Accepted | 73.37 | N=int(eval(input()))
def cnt(i,j):
ret=0
si=str(i)
for n in range(1,N+1):
if n%10!=j:
continue
if str(n)[0]!=si:
continue
ret+=1
return ret
ans=0
for i in range(10):
for j in range(10):
ans+=cnt(i,j)*cnt(j,i)
print(ans)
| S=eval(input())
N=int(S)
keta=len(S)
ans=[[0]*10 for _ in range(10)]
fa=0
for A in range(1,N+1):
ns=str(A)
tailA=int(ns[-1])
if tailA==0: continue
headA=int(ns[0])
if ans[headA][tailA]==0:
dp=[[[0]*2 for __ in range(2)] for _ in range(keta+1)]
dp[0][0][1]=1
for i in range(keta):
x=int(S[i])
for j in range(2):
for k in range(2):
for n in range(10):
ni=i+1
nj=1 if j==1 or n>0 else 0
nk=1 if k==1 and n==x else 0
if k==1 and n>x: continue
if j==0 and nj==1 and n!=tailA: continue
if ni==keta and n!=headA: continue
dp[ni][nj][nk]+=dp[i][j][k]
for k in range(2):
ans[headA][tailA]+=dp[keta][1][k]
fa+=ans[headA][tailA]
print(fa) | 18 | 29 | 309 | 945 | N = int(eval(input()))
def cnt(i, j):
ret = 0
si = str(i)
for n in range(1, N + 1):
if n % 10 != j:
continue
if str(n)[0] != si:
continue
ret += 1
return ret
ans = 0
for i in range(10):
for j in range(10):
ans += cnt(i, j) * cnt(j, i)
print(ans)
| S = eval(input())
N = int(S)
keta = len(S)
ans = [[0] * 10 for _ in range(10)]
fa = 0
for A in range(1, N + 1):
ns = str(A)
tailA = int(ns[-1])
if tailA == 0:
continue
headA = int(ns[0])
if ans[headA][tailA] == 0:
dp = [[[0] * 2 for __ in range(2)] for _ in range(keta + 1)]
dp[0][0][1] = 1
for i in range(keta):
x = int(S[i])
for j in range(2):
for k in range(2):
for n in range(10):
ni = i + 1
nj = 1 if j == 1 or n > 0 else 0
nk = 1 if k == 1 and n == x else 0
if k == 1 and n > x:
continue
if j == 0 and nj == 1 and n != tailA:
continue
if ni == keta and n != headA:
continue
dp[ni][nj][nk] += dp[i][j][k]
for k in range(2):
ans[headA][tailA] += dp[keta][1][k]
fa += ans[headA][tailA]
print(fa)
| false | 37.931034 | [
"-N = int(eval(input()))",
"-",
"-",
"-def cnt(i, j):",
"- ret = 0",
"- si = str(i)",
"- for n in range(1, N + 1):",
"- if n % 10 != j:",
"- continue",
"- if str(n)[0] != si:",
"- continue",
"- ret += 1",
"- return ret",
"-",
"-",
... | false | 0.362901 | 0.042831 | 8.472943 | [
"s974253088",
"s062925482"
] |
u723711163 | p03682 | python | s876674773 | s808179629 | 1,802 | 1,374 | 141,948 | 128,580 | Accepted | Accepted | 23.75 | class UF():
def __init__(self, N):
self.par = [-1]*N
def find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x,y):
p1,p2 = self.find(x),self.find(y)
if p1 == p2: return
if p1 > p2:
p1,p2 = p2,p1
self.par[p1] += self.par[p2]
self.par[p2] = p1
def same(self, x,y):
return self.find(x) == self.find(y)
N = int(eval(input()))
coordinates = []
for i in range(N):
x,y = list(map(int, input().split()))
coordinates.append((i,x,y))
edges = []
sort_x = sorted(coordinates, key=lambda x: x[1])
for i in range(N-1):
u,v = sort_x[i][0], sort_x[i+1][0]
edges.append([u,v,abs(sort_x[i][1] - sort_x[i+1][1])])
sort_y = sorted(coordinates, key=lambda x: x[2])
for i in range(N-1):
u,v = sort_y[i][0], sort_y[i+1][0]
edges.append([u,v,abs(sort_y[i][2] - sort_y[i+1][2] )])
edges.sort(key=lambda x: x[2])
uf = UF(N)
res = 0
for u,v,c in edges:
if not uf.same(u,v):
uf.union(u,v)
res += c
print(res)
| class UF():
def __init__(self, N):
self.par = [-1]*N
def find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x,y):
p1,p2 = self.find(x),self.find(y)
if p1 == p2: return
if p1 > p2:
p1,p2 = p2,p1
self.par[p1] += self.par[p2]
self.par[p2] = p1
def same(self, x,y):
return self.find(x) == self.find(y)
n = int(eval(input()))
coords = []
for i in range(n):
x,y = list(map(int,input().split()))
coords.append((i,x,y))
edges = []
sorted_x = sorted(coords, key=lambda x: x[1])
for i in range(n-1):
c = abs(sorted_x[i][1] - sorted_x[i+1][1])
u,v = sorted_x[i][0], sorted_x[i+1][0]
edges.append((c,u,v))
sorted_y = sorted(coords, key=lambda x: x[2])
for i in range(n-1):
c = abs(sorted_y[i][2] - sorted_y[i+1][2])
u,v = sorted_y[i][0], sorted_y[i+1][0]
edges.append((c,u,v))
edges.sort()
uf = UF(n)
res = 0
for c,u,v in edges:
if not uf.same(u,v):
uf.union(u,v)
res += c
print(res) | 49 | 52 | 1,094 | 1,089 | class UF:
def __init__(self, N):
self.par = [-1] * N
def find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
p1, p2 = self.find(x), self.find(y)
if p1 == p2:
return
if p1 > p2:
p1, p2 = p2, p1
self.par[p1] += self.par[p2]
self.par[p2] = p1
def same(self, x, y):
return self.find(x) == self.find(y)
N = int(eval(input()))
coordinates = []
for i in range(N):
x, y = list(map(int, input().split()))
coordinates.append((i, x, y))
edges = []
sort_x = sorted(coordinates, key=lambda x: x[1])
for i in range(N - 1):
u, v = sort_x[i][0], sort_x[i + 1][0]
edges.append([u, v, abs(sort_x[i][1] - sort_x[i + 1][1])])
sort_y = sorted(coordinates, key=lambda x: x[2])
for i in range(N - 1):
u, v = sort_y[i][0], sort_y[i + 1][0]
edges.append([u, v, abs(sort_y[i][2] - sort_y[i + 1][2])])
edges.sort(key=lambda x: x[2])
uf = UF(N)
res = 0
for u, v, c in edges:
if not uf.same(u, v):
uf.union(u, v)
res += c
print(res)
| class UF:
def __init__(self, N):
self.par = [-1] * N
def find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
p1, p2 = self.find(x), self.find(y)
if p1 == p2:
return
if p1 > p2:
p1, p2 = p2, p1
self.par[p1] += self.par[p2]
self.par[p2] = p1
def same(self, x, y):
return self.find(x) == self.find(y)
n = int(eval(input()))
coords = []
for i in range(n):
x, y = list(map(int, input().split()))
coords.append((i, x, y))
edges = []
sorted_x = sorted(coords, key=lambda x: x[1])
for i in range(n - 1):
c = abs(sorted_x[i][1] - sorted_x[i + 1][1])
u, v = sorted_x[i][0], sorted_x[i + 1][0]
edges.append((c, u, v))
sorted_y = sorted(coords, key=lambda x: x[2])
for i in range(n - 1):
c = abs(sorted_y[i][2] - sorted_y[i + 1][2])
u, v = sorted_y[i][0], sorted_y[i + 1][0]
edges.append((c, u, v))
edges.sort()
uf = UF(n)
res = 0
for c, u, v in edges:
if not uf.same(u, v):
uf.union(u, v)
res += c
print(res)
| false | 5.769231 | [
"-N = int(eval(input()))",
"-coordinates = []",
"-for i in range(N):",
"+n = int(eval(input()))",
"+coords = []",
"+for i in range(n):",
"- coordinates.append((i, x, y))",
"+ coords.append((i, x, y))",
"-sort_x = sorted(coordinates, key=lambda x: x[1])",
"-for i in range(N - 1):",
"- u,... | false | 0.041109 | 0.041092 | 1.000406 | [
"s876674773",
"s808179629"
] |
u952708174 | p03644 | python | s744023458 | s710513204 | 162 | 17 | 38,384 | 2,940 | Accepted | Accepted | 89.51 | x=int(eval(input("")))
k=0
while True:
if pow(2,k)>x:
break
k+=1
print((pow(2,k-1))) | N = int(eval(input()))
k = 0
while pow(2, k) <= N:
k += 1
print((2**(k - 1))) | 7 | 5 | 90 | 77 | x = int(eval(input("")))
k = 0
while True:
if pow(2, k) > x:
break
k += 1
print((pow(2, k - 1)))
| N = int(eval(input()))
k = 0
while pow(2, k) <= N:
k += 1
print((2 ** (k - 1)))
| false | 28.571429 | [
"-x = int(eval(input(\"\")))",
"+N = int(eval(input()))",
"-while True:",
"- if pow(2, k) > x:",
"- break",
"+while pow(2, k) <= N:",
"-print((pow(2, k - 1)))",
"+print((2 ** (k - 1)))"
] | false | 0.041463 | 0.042248 | 0.981431 | [
"s744023458",
"s710513204"
] |
u645250356 | p03069 | python | s781274275 | s478162212 | 240 | 86 | 7,136 | 3,500 | Accepted | Accepted | 64.17 | import fractions,math,sys
from collections import Counter
n = int(eval(input()))
s = list(eval(input()))
cnt = Counter(s)
white_l = 0
black_l = 0
min = cnt['.']
for i in range(n):
if s[i] == '#':
black_l += 1
cnt['#'] -= 1
else:
white_l += 1
cnt['.'] -= 1
if black_l + cnt['.'] < min:
min = black_l + cnt['.']
print(min)
| n = int(eval(input()))
s = eval(input())
white = s.count('.')
black = 0
min = white
for i in range(n):
if s[i] == '#':
black += 1
else:
white -= 1
if black + white < min:
min = black + white
print(min)
| 19 | 14 | 380 | 241 | import fractions, math, sys
from collections import Counter
n = int(eval(input()))
s = list(eval(input()))
cnt = Counter(s)
white_l = 0
black_l = 0
min = cnt["."]
for i in range(n):
if s[i] == "#":
black_l += 1
cnt["#"] -= 1
else:
white_l += 1
cnt["."] -= 1
if black_l + cnt["."] < min:
min = black_l + cnt["."]
print(min)
| n = int(eval(input()))
s = eval(input())
white = s.count(".")
black = 0
min = white
for i in range(n):
if s[i] == "#":
black += 1
else:
white -= 1
if black + white < min:
min = black + white
print(min)
| false | 26.315789 | [
"-import fractions, math, sys",
"-from collections import Counter",
"-",
"-s = list(eval(input()))",
"-cnt = Counter(s)",
"-white_l = 0",
"-black_l = 0",
"-min = cnt[\".\"]",
"+s = eval(input())",
"+white = s.count(\".\")",
"+black = 0",
"+min = white",
"- black_l += 1",
"- c... | false | 0.043616 | 0.153862 | 0.283475 | [
"s781274275",
"s478162212"
] |
u928385607 | p03308 | python | s374901617 | s100642363 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
for i in range(n):
for j in range(i+1, n):
if a[i] - a[j] > ans:
ans = a[i] - a[j]
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
print((a[0] - a[n-1]))
| 12 | 6 | 196 | 102 | n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
for i in range(n):
for j in range(i + 1, n):
if a[i] - a[j] > ans:
ans = a[i] - a[j]
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
print((a[0] - a[n - 1]))
| false | 50 | [
"-ans = 0",
"-for i in range(n):",
"- for j in range(i + 1, n):",
"- if a[i] - a[j] > ans:",
"- ans = a[i] - a[j]",
"-print(ans)",
"+print((a[0] - a[n - 1]))"
] | false | 0.047696 | 0.07602 | 0.627419 | [
"s374901617",
"s100642363"
] |
u514383727 | p03699 | python | s450541438 | s363896789 | 368 | 323 | 11,508 | 11,252 | Accepted | Accepted | 12.23 | n = int(eval(input()))
s = [int(eval(input())) for _ in range(n)]
dp = [[-1 for _ in range(n*100+1)] for _ in range(n+1)]
dp [0][0] = 0
for i in range(n):
for j in range(n*100+1):
if dp[i][j] != -1:
dp[i+1][j] = dp[i][j]
dp[i+1][j+s[i]] = dp[i][j] + s[i]
res = 0
for i in range(n*100+1)[::-1]:
if dp[n][i] > res and i % 10 != 0:
res = dp[n][i]
break
print(res)
| n = int(eval(input()))
s = [int(eval(input())) for _ in range(n)]
dp = [[-1 for _ in range(sum(s)+1)] for _ in range(n+1)]
dp [0][0] = 0
for i in range(n):
for j in range(sum(s)+1):
if dp[i][j] != -1:
dp[i+1][j] = dp[i][j]
dp[i+1][j+s[i]] = dp[i][j] + s[i]
res = 0
for i in range(sum(s)+1)[::-1]:
if dp[n][i] > res and i % 10 != 0:
res = dp[n][i]
break
print(res)
| 15 | 15 | 419 | 422 | n = int(eval(input()))
s = [int(eval(input())) for _ in range(n)]
dp = [[-1 for _ in range(n * 100 + 1)] for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(n * 100 + 1):
if dp[i][j] != -1:
dp[i + 1][j] = dp[i][j]
dp[i + 1][j + s[i]] = dp[i][j] + s[i]
res = 0
for i in range(n * 100 + 1)[::-1]:
if dp[n][i] > res and i % 10 != 0:
res = dp[n][i]
break
print(res)
| n = int(eval(input()))
s = [int(eval(input())) for _ in range(n)]
dp = [[-1 for _ in range(sum(s) + 1)] for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(sum(s) + 1):
if dp[i][j] != -1:
dp[i + 1][j] = dp[i][j]
dp[i + 1][j + s[i]] = dp[i][j] + s[i]
res = 0
for i in range(sum(s) + 1)[::-1]:
if dp[n][i] > res and i % 10 != 0:
res = dp[n][i]
break
print(res)
| false | 0 | [
"-dp = [[-1 for _ in range(n * 100 + 1)] for _ in range(n + 1)]",
"+dp = [[-1 for _ in range(sum(s) + 1)] for _ in range(n + 1)]",
"- for j in range(n * 100 + 1):",
"+ for j in range(sum(s) + 1):",
"-for i in range(n * 100 + 1)[::-1]:",
"+for i in range(sum(s) + 1)[::-1]:"
] | false | 0.044837 | 0.045074 | 0.994746 | [
"s450541438",
"s363896789"
] |
u477977638 | p02732 | python | s857709534 | s263247169 | 397 | 251 | 77,772 | 20,396 | Accepted | Accepted | 36.78 | import sys
input = sys.stdin.readline
#input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
def RD(): return sys.stdin.read()
def II(): return int(eval(input()))
def MI(): return list(map(int,input().split()))
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#import numpy as np
from collections import deque
def main():
n=II()
A=LI()
B=[0]*(n+1)
for i in A:
B[i]+=1
ans=0
for i in B:
ans+=i*(i-1)//2
#print(ans)
for i in A:
print((ans-B[i]+1))
if __name__ == "__main__":
main() | import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
def RD(): return sys.stdin.read()
def II(): return int(eval(input()))
def MI(): return list(map(int,input().split()))
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#import numpy as np
def main():
n=II()
A=LI()
B=[0]*(n+1)
for i in A:
B[i]+=1
ans=0
for i in B:
ans+=i*(i-1)//2
#print(ans)
for i in A:
print((ans-B[i]+1))
if __name__ == "__main__":
main() | 40 | 38 | 618 | 584 | import sys
input = sys.stdin.readline
# input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
def RD():
return sys.stdin.read()
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def TI():
return tuple(map(int, input().split()))
# rstrip().decode('utf-8')
# import numpy as np
from collections import deque
def main():
n = II()
A = LI()
B = [0] * (n + 1)
for i in A:
B[i] += 1
ans = 0
for i in B:
ans += i * (i - 1) // 2
# print(ans)
for i in A:
print((ans - B[i] + 1))
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
def RD():
return sys.stdin.read()
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def TI():
return tuple(map(int, input().split()))
# rstrip().decode('utf-8')
# import numpy as np
def main():
n = II()
A = LI()
B = [0] * (n + 1)
for i in A:
B[i] += 1
ans = 0
for i in B:
ans += i * (i - 1) // 2
# print(ans)
for i in A:
print((ans - B[i] + 1))
if __name__ == "__main__":
main()
| false | 5 | [
"-# input = sys.stdin.buffer.readline",
"+input = sys.stdin.buffer.readline",
"-from collections import deque",
"-",
"-"
] | false | 0.036565 | 0.044391 | 0.823701 | [
"s857709534",
"s263247169"
] |
u279493135 | p02720 | python | s884832526 | s163292998 | 122 | 100 | 14,164 | 20,956 | Accepted | Accepted | 18.03 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
K = INT()
q = list(range(1, 10))
q = deque(q)
for _ in range(K):
x = q.popleft()
r = x%10
if r > 0:
q.append(10*x+(r-1))
q.append(10*x+r)
if r < 9:
q.append(10*x+(r+1))
print(x)
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
K = INT()
q = deque(list(range(1, 10)))
for i in range(K):
n = q.popleft()
r = n%10
if r != 0:
q.append(10*n+(r-1))
q.append(10*n+r)
if r != 9:
q.append(10*n+(r+1))
print(n) | 34 | 34 | 985 | 972 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
K = INT()
q = list(range(1, 10))
q = deque(q)
for _ in range(K):
x = q.popleft()
r = x % 10
if r > 0:
q.append(10 * x + (r - 1))
q.append(10 * x + r)
if r < 9:
q.append(10 * x + (r + 1))
print(x)
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
K = INT()
q = deque(list(range(1, 10)))
for i in range(K):
n = q.popleft()
r = n % 10
if r != 0:
q.append(10 * n + (r - 1))
q.append(10 * n + r)
if r != 9:
q.append(10 * n + (r + 1))
print(n)
| false | 0 | [
"-from itertools import accumulate, permutations, combinations, product, groupby",
"+from itertools import accumulate, permutations, combinations, product",
"-q = list(range(1, 10))",
"-q = deque(q)",
"-for _ in range(K):",
"- x = q.popleft()",
"- r = x % 10",
"- if r > 0:",
"- q.app... | false | 0.117442 | 0.042102 | 2.789485 | [
"s884832526",
"s163292998"
] |
u814781830 | p02862 | python | s751101550 | s580151667 | 366 | 128 | 85,488 | 3,064 | Accepted | Accepted | 65.03 | X, Y = list(map(int, input().split()))
MOD = 10 ** 9 + 7
def createFacArr(n, mod):
fac = [0] * n
finv = [0] * n
inv = [0] * n
fac[0], fac[1] = 1, 1
finv[0], finv[1] = 1, 1
inv[1] = 1
for i in range(2, n):
fac[i] = fac[i-1] * i % mod
inv[i] = mod - inv[mod%i] * (mod // i) % mod
finv[i] = finv[i-1] * inv[i] % mod
return fac, finv, inv
def comb(n ,k, mod, fac, finv, inv):
'''
二項係数の計算
'''
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n-k] % mod) % mod
def main():
if (X + Y) % 3 != 0:
return 0
# 移動回数を求める
m = (2 * X - Y) // 3
n = X - 2 * m
fac, finv, inv = createFacArr(10**6*2, MOD)
return comb(m+n, n, MOD, fac, finv, inv)
print((main()))
| X, Y = list(map(int,input().split()))
MOD = 10 ** 9 + 7
def calc_comb(n, k, mod):
'''
n が大きい場合に使う
'''
a = 1
b = 1
for i in range(1,k+1):
a *= i
a %= mod
b *= n
n -= 1
b %= mod
return b * pow(a, mod-2, mod) % mod
if (X+Y) % 3 != 0:
print((0))
else:
total_move = (X+Y) // 3
# 右に2つ動くことを選択しなければいけない回数
right_move = min(X,Y) - total_move
if right_move >= 0:
print((calc_comb(total_move, right_move, MOD)))
else:
print((0))
| 36 | 29 | 833 | 550 | X, Y = list(map(int, input().split()))
MOD = 10**9 + 7
def createFacArr(n, mod):
fac = [0] * n
finv = [0] * n
inv = [0] * n
fac[0], fac[1] = 1, 1
finv[0], finv[1] = 1, 1
inv[1] = 1
for i in range(2, n):
fac[i] = fac[i - 1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i - 1] * inv[i] % mod
return fac, finv, inv
def comb(n, k, mod, fac, finv, inv):
"""
二項係数の計算
"""
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % mod) % mod
def main():
if (X + Y) % 3 != 0:
return 0
# 移動回数を求める
m = (2 * X - Y) // 3
n = X - 2 * m
fac, finv, inv = createFacArr(10**6 * 2, MOD)
return comb(m + n, n, MOD, fac, finv, inv)
print((main()))
| X, Y = list(map(int, input().split()))
MOD = 10**9 + 7
def calc_comb(n, k, mod):
"""
n が大きい場合に使う
"""
a = 1
b = 1
for i in range(1, k + 1):
a *= i
a %= mod
b *= n
n -= 1
b %= mod
return b * pow(a, mod - 2, mod) % mod
if (X + Y) % 3 != 0:
print((0))
else:
total_move = (X + Y) // 3
# 右に2つ動くことを選択しなければいけない回数
right_move = min(X, Y) - total_move
if right_move >= 0:
print((calc_comb(total_move, right_move, MOD)))
else:
print((0))
| false | 19.444444 | [
"-def createFacArr(n, mod):",
"- fac = [0] * n",
"- finv = [0] * n",
"- inv = [0] * n",
"- fac[0], fac[1] = 1, 1",
"- finv[0], finv[1] = 1, 1",
"- inv[1] = 1",
"- for i in range(2, n):",
"- fac[i] = fac[i - 1] * i % mod",
"- inv[i] = mod - inv[mod % i] * (mod // ... | false | 2.052059 | 0.053514 | 38.346485 | [
"s751101550",
"s580151667"
] |
u546285759 | p00055 | python | s166156021 | s200756815 | 40 | 20 | 7,336 | 7,448 | Accepted | Accepted | 50 | import sys
for line in sys.stdin:
ans = [float(line.strip())]
for i in range(1, 10):
if (i+1) % 2 == 0: ans += [ans[i-1]*2]
else: ans += [ans[i-1]/3]
print((sum(ans))) | while True:
try:
a = float(eval(input()))
except:
break
total = a
for i in range(2, 11):
tmp = a / 3 if i % 2 else a * 2
total += tmp
a = tmp
print(total) | 8 | 11 | 201 | 218 | import sys
for line in sys.stdin:
ans = [float(line.strip())]
for i in range(1, 10):
if (i + 1) % 2 == 0:
ans += [ans[i - 1] * 2]
else:
ans += [ans[i - 1] / 3]
print((sum(ans)))
| while True:
try:
a = float(eval(input()))
except:
break
total = a
for i in range(2, 11):
tmp = a / 3 if i % 2 else a * 2
total += tmp
a = tmp
print(total)
| false | 27.272727 | [
"-import sys",
"-",
"-for line in sys.stdin:",
"- ans = [float(line.strip())]",
"- for i in range(1, 10):",
"- if (i + 1) % 2 == 0:",
"- ans += [ans[i - 1] * 2]",
"- else:",
"- ans += [ans[i - 1] / 3]",
"- print((sum(ans)))",
"+while True:",
"+ t... | false | 0.03471 | 0.040068 | 0.866259 | [
"s166156021",
"s200756815"
] |
u674588203 | p02755 | python | s938767512 | s010237113 | 29 | 21 | 2,940 | 2,940 | Accepted | Accepted | 27.59 | A,B=list(map(int,input().split()))
for i in range(20000):
if ((i*8)+0.000005)//100==A and ((i*10)+0.000005)//100==B:
print(i)
exit()
else:
pass
print((-1)) | A,B=list(map(int,input().split()))
for i in range(20000):
if (i*8)//100==A and (i*10)//100==B:
print(i)
exit()
else:
pass
print((-1)) | 8 | 8 | 186 | 164 | A, B = list(map(int, input().split()))
for i in range(20000):
if ((i * 8) + 0.000005) // 100 == A and ((i * 10) + 0.000005) // 100 == B:
print(i)
exit()
else:
pass
print((-1))
| A, B = list(map(int, input().split()))
for i in range(20000):
if (i * 8) // 100 == A and (i * 10) // 100 == B:
print(i)
exit()
else:
pass
print((-1))
| false | 0 | [
"- if ((i * 8) + 0.000005) // 100 == A and ((i * 10) + 0.000005) // 100 == B:",
"+ if (i * 8) // 100 == A and (i * 10) // 100 == B:"
] | false | 0.051388 | 0.115422 | 0.445216 | [
"s938767512",
"s010237113"
] |
u150984829 | p00009 | python | s009541415 | s933645032 | 410 | 170 | 9,880 | 15,008 | Accepted | Accepted | 58.54 | import sys
m=166666;s=[1]*m;t=[1]*m
for i in range(m):
for j in range(2):
if (s[i],t[i])[j]:
k=6*i+[5,7][j];n=[i+k,k-i-2]
s[n[j]::k]=[0]*len(s[n[j]::k])
t[n[1-j]::k]=[0]*len(t[n[1-j]::k])
for e in map(int,sys.stdin):
print(([e-1,sum(s[:(e+1)//6])+sum(t[:(e-1)//6])+2][e>3]))
| import sys
a=[1]*500000
for i in range(3,999,2):
if a[i//2]:a[(i*i)//2::i]=[0]*len(a[(i*i)//2::i])
for e in map(int,sys.stdin):print(([e-1,sum(a[:(e+1)//2])][e>3]))
| 10 | 5 | 295 | 168 | import sys
m = 166666
s = [1] * m
t = [1] * m
for i in range(m):
for j in range(2):
if (s[i], t[i])[j]:
k = 6 * i + [5, 7][j]
n = [i + k, k - i - 2]
s[n[j] :: k] = [0] * len(s[n[j] :: k])
t[n[1 - j] :: k] = [0] * len(t[n[1 - j] :: k])
for e in map(int, sys.stdin):
print(([e - 1, sum(s[: (e + 1) // 6]) + sum(t[: (e - 1) // 6]) + 2][e > 3]))
| import sys
a = [1] * 500000
for i in range(3, 999, 2):
if a[i // 2]:
a[(i * i) // 2 :: i] = [0] * len(a[(i * i) // 2 :: i])
for e in map(int, sys.stdin):
print(([e - 1, sum(a[: (e + 1) // 2])][e > 3]))
| false | 50 | [
"-m = 166666",
"-s = [1] * m",
"-t = [1] * m",
"-for i in range(m):",
"- for j in range(2):",
"- if (s[i], t[i])[j]:",
"- k = 6 * i + [5, 7][j]",
"- n = [i + k, k - i - 2]",
"- s[n[j] :: k] = [0] * len(s[n[j] :: k])",
"- t[n[1 - j] :: k] = [0] ... | false | 1.582232 | 0.072191 | 21.917405 | [
"s009541415",
"s933645032"
] |
u835283937 | p03937 | python | s124419629 | s588210219 | 30 | 27 | 9,176 | 9,116 | Accepted | Accepted | 10 | def main():
H, W = list(map(int, input().split()))
board = list()
for i in range(H):
board.append(list(eval(input())))
stat = [[False for i in range(W)] for j in range(H)]
go = True
i = j = 0
stat[i][j] = True
while go:
if (i < H) and (j + 1 < W) and board[i][j + 1] == "#":
j = j + 1
stat[i][j] = True
elif (i + 1 < H) and (j < W) and board[i + 1][j] == "#":
i = i + 1
stat[i][j] = True
else:
break
ans = True
for i in range(H):
for j in range(W):
if board[i][j] == "#" and stat[i][j] == False:
ans = False
if ans:
print("Possible")
else:
print("Impossible")
if __name__ == "__main__":
main() | def main2():
H, W = list(map(int, input().split()))
count = 0
for i in range(H):
count += input().count("#")
if count == (H + W - 1):
print("Possible")
else:
print("Impossible")
if __name__ == "__main__":
main2() | 36 | 14 | 827 | 270 | def main():
H, W = list(map(int, input().split()))
board = list()
for i in range(H):
board.append(list(eval(input())))
stat = [[False for i in range(W)] for j in range(H)]
go = True
i = j = 0
stat[i][j] = True
while go:
if (i < H) and (j + 1 < W) and board[i][j + 1] == "#":
j = j + 1
stat[i][j] = True
elif (i + 1 < H) and (j < W) and board[i + 1][j] == "#":
i = i + 1
stat[i][j] = True
else:
break
ans = True
for i in range(H):
for j in range(W):
if board[i][j] == "#" and stat[i][j] == False:
ans = False
if ans:
print("Possible")
else:
print("Impossible")
if __name__ == "__main__":
main()
| def main2():
H, W = list(map(int, input().split()))
count = 0
for i in range(H):
count += input().count("#")
if count == (H + W - 1):
print("Possible")
else:
print("Impossible")
if __name__ == "__main__":
main2()
| false | 61.111111 | [
"-def main():",
"+def main2():",
"- board = list()",
"+ count = 0",
"- board.append(list(eval(input())))",
"- stat = [[False for i in range(W)] for j in range(H)]",
"- go = True",
"- i = j = 0",
"- stat[i][j] = True",
"- while go:",
"- if (i < H) and (j + 1 < W... | false | 0.045455 | 0.046775 | 0.971782 | [
"s124419629",
"s588210219"
] |
u163907160 | p02983 | python | s454652623 | s075918759 | 1,051 | 318 | 20,644 | 20,892 | Accepted | Accepted | 69.74 | import collections
import numpy as np
import sys
sys.setrecursionlimit(10000000)
import copy
#N=int(input())
L,R=list(map(int,input().split()))
l=[]
for i in range(2021):
l.append(L%2019)
if L==R:
break
L+=1
ans=2019999
for i in range(len(l)):
for j in range(i+1,len(l)):
ans=min(l[i]*l[j]%2019,ans)
print(ans) | import collections
import numpy as np
import sys
sys.setrecursionlimit(10000000)
import copy
#N=int(input())
L,R=list(map(int,input().split()))
if R-L>=2019:
print((0))
exit()
else:
ans=2019999
for i in range(L,R+1):
for j in range(i+1,R+1):
ans=min(i*j%2019,ans)
if ans==0:
print(ans)
exit()
print(ans) | 18 | 19 | 353 | 397 | import collections
import numpy as np
import sys
sys.setrecursionlimit(10000000)
import copy
# N=int(input())
L, R = list(map(int, input().split()))
l = []
for i in range(2021):
l.append(L % 2019)
if L == R:
break
L += 1
ans = 2019999
for i in range(len(l)):
for j in range(i + 1, len(l)):
ans = min(l[i] * l[j] % 2019, ans)
print(ans)
| import collections
import numpy as np
import sys
sys.setrecursionlimit(10000000)
import copy
# N=int(input())
L, R = list(map(int, input().split()))
if R - L >= 2019:
print((0))
exit()
else:
ans = 2019999
for i in range(L, R + 1):
for j in range(i + 1, R + 1):
ans = min(i * j % 2019, ans)
if ans == 0:
print(ans)
exit()
print(ans)
| false | 5.263158 | [
"-l = []",
"-for i in range(2021):",
"- l.append(L % 2019)",
"- if L == R:",
"- break",
"- L += 1",
"-ans = 2019999",
"-for i in range(len(l)):",
"- for j in range(i + 1, len(l)):",
"- ans = min(l[i] * l[j] % 2019, ans)",
"-print(ans)",
"+if R - L >= 2019:",
"+ p... | false | 0.006956 | 0.087797 | 0.079228 | [
"s454652623",
"s075918759"
] |
u190079347 | p03599 | python | s659185913 | s732847450 | 98 | 58 | 3,828 | 3,188 | Accepted | Accepted | 40.82 | A,B,C,D,E,F = list(map(int,input().split()))
W=set()
for a in range(0,F+1,100*A):
for b in range(0,F+1-a,100*B):
W.add(a+b)
S=set()
for c in range(0,F+1,C):
for d in range(0,F+1,D):
S.add(c+d)
rate = -1
for w in W:
for s in S:
if 0 < w+s <= F and s <= w*E//100:
if s/(w+s) > rate:
rate = s/(w+s)
ans = w+s, s
print((ans[0],ans[1])) | A,B,C,D,E,F = list(map(int,input().split()))
W=set()
for a in range(0,F+1,100*A):
for b in range(0,F+1-a,100*B):
W.add(a+b)
S=set()
for c in range(0,F+1,C):
for d in range(0,F+1-c,D):
S.add(c+d)
rate = -1
for w in W:
for s in S:
if 0 < w+s <= F and s <= w*E//100:
if s/(w+s) > rate:
rate = s/(w+s)
ans = w+s, s
print((ans[0],ans[1])) | 17 | 17 | 419 | 421 | A, B, C, D, E, F = list(map(int, input().split()))
W = set()
for a in range(0, F + 1, 100 * A):
for b in range(0, F + 1 - a, 100 * B):
W.add(a + b)
S = set()
for c in range(0, F + 1, C):
for d in range(0, F + 1, D):
S.add(c + d)
rate = -1
for w in W:
for s in S:
if 0 < w + s <= F and s <= w * E // 100:
if s / (w + s) > rate:
rate = s / (w + s)
ans = w + s, s
print((ans[0], ans[1]))
| A, B, C, D, E, F = list(map(int, input().split()))
W = set()
for a in range(0, F + 1, 100 * A):
for b in range(0, F + 1 - a, 100 * B):
W.add(a + b)
S = set()
for c in range(0, F + 1, C):
for d in range(0, F + 1 - c, D):
S.add(c + d)
rate = -1
for w in W:
for s in S:
if 0 < w + s <= F and s <= w * E // 100:
if s / (w + s) > rate:
rate = s / (w + s)
ans = w + s, s
print((ans[0], ans[1]))
| false | 0 | [
"- for d in range(0, F + 1, D):",
"+ for d in range(0, F + 1 - c, D):"
] | false | 0.148955 | 0.077333 | 1.926139 | [
"s659185913",
"s732847450"
] |
u912237403 | p00060 | python | s968192093 | s469245408 | 20 | 10 | 4,208 | 4,204 | Accepted | Accepted | 50 | import sys
for s in sys.stdin:
C=[0]+[1]*10
a,b,c=list(map(int,s.split()))
C[a]=0
C[b]=0
C[c]=0
if sum(C[:21-a-b])>=4:print("YES")
else: print("NO") | import sys
for s in sys.stdin:
a,b,c=list(map(int,s.split()))
x=20-a-b
f=3
if x<a: f-=1
if x<b: f-=1
if x<c: f-=1
if x-f>=4:print("YES")
else: print("NO") | 9 | 10 | 176 | 187 | import sys
for s in sys.stdin:
C = [0] + [1] * 10
a, b, c = list(map(int, s.split()))
C[a] = 0
C[b] = 0
C[c] = 0
if sum(C[: 21 - a - b]) >= 4:
print("YES")
else:
print("NO")
| import sys
for s in sys.stdin:
a, b, c = list(map(int, s.split()))
x = 20 - a - b
f = 3
if x < a:
f -= 1
if x < b:
f -= 1
if x < c:
f -= 1
if x - f >= 4:
print("YES")
else:
print("NO")
| false | 10 | [
"- C = [0] + [1] * 10",
"- C[a] = 0",
"- C[b] = 0",
"- C[c] = 0",
"- if sum(C[: 21 - a - b]) >= 4:",
"+ x = 20 - a - b",
"+ f = 3",
"+ if x < a:",
"+ f -= 1",
"+ if x < b:",
"+ f -= 1",
"+ if x < c:",
"+ f -= 1",
"+ if x - f >= 4:"
] | false | 0.038251 | 0.076993 | 0.49682 | [
"s968192093",
"s469245408"
] |
u029000441 | p03244 | python | s299696830 | s877473548 | 155 | 113 | 19,104 | 99,616 | Accepted | Accepted | 27.1 | # coding: utf-8
# hello worldと表示する
#dpでできないかな?
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7
n=I()
lis=LI()
ev,od=[],[]
for i in range(n):
if i%2==0:
ev.append(lis[i])
else:
od.append(lis[i])
c=Counter(ev)
d=Counter(od)
#print(c.most_common()[0][1])
#-c.most_common()[0]-d.most_common()[0]
if c.most_common()[0][0]==d.most_common()[0][0]:
if c.most_common()[0][1]==n//2:
ans=n//2
elif c.most_common()[1][1]>=d.most_common()[1][1]:
ans=len(od)-d.most_common()[0][1]+len(ev)-c.most_common()[1][1]
elif c.most_common()[1][1]<d.most_common()[1][1]:
ans=len(od)-c.most_common()[0][1]+len(ev)-d.most_common()[1][1]
else:
ans=len(ev)+len(od)-c.most_common()[0][1]-d.most_common()[0][1]
print(ans) | # coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7
n=I()//2
lis=LI()
lis1=[]
lis2=[]
for i in range(n):
lis1.append(lis[2*i])
lis2.append(lis[2*i+1])
x=Counter(lis1).most_common(2)
y=Counter(lis2).most_common(2)
#print(x)
#print(y)
if len(x)==1:
x.append((0,0))
if len(y)==1:
y.append((-1,0))
#print(x)
#print(y)
if x[0][0]!=y[0][0]:
print((2*n-x[0][1]-y[0][1]))
else:
cands=[]
#print(2*n-x[0][1]-y[1][]))
if x[1][0]!=y[0][0]:
cands.append(2*n-x[1][1]-y[0][1])
if x[0][0]!=y[1][0]:
cands.append(2*n-x[0][1]-y[1][1])
if x[1][0]!=y[1][0]:
cands.append(2*n-x[1][1]-y[1][1])
print((min(cands)))
| 46 | 58 | 1,493 | 1,501 | # coding: utf-8
# hello worldと表示する
# dpでできないかな?
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil, pi
from operator import itemgetter
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def LI2():
return [int(eval(input())) for i in range(n)]
def MXI():
return [[LI()] for i in range(n)]
def SI():
return input().rstrip()
def printns(x):
print(("\n".join(x)))
def printni(x):
print(("\n".join(list(map(str, x)))))
inf = 10**17
mod = 10**9 + 7
n = I()
lis = LI()
ev, od = [], []
for i in range(n):
if i % 2 == 0:
ev.append(lis[i])
else:
od.append(lis[i])
c = Counter(ev)
d = Counter(od)
# print(c.most_common()[0][1])
# -c.most_common()[0]-d.most_common()[0]
if c.most_common()[0][0] == d.most_common()[0][0]:
if c.most_common()[0][1] == n // 2:
ans = n // 2
elif c.most_common()[1][1] >= d.most_common()[1][1]:
ans = len(od) - d.most_common()[0][1] + len(ev) - c.most_common()[1][1]
elif c.most_common()[1][1] < d.most_common()[1][1]:
ans = len(od) - c.most_common()[0][1] + len(ev) - d.most_common()[1][1]
else:
ans = len(ev) + len(od) - c.most_common()[0][1] - d.most_common()[0][1]
print(ans)
| # coding: utf-8
# hello worldと表示する
# float型を許すな
# numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil, pi, factorial
from operator import itemgetter
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def LI2():
return [int(eval(input())) for i in range(n)]
def MXI():
return [[LI()] for i in range(n)]
def SI():
return input().rstrip()
def printns(x):
print(("\n".join(x)))
def printni(x):
print(("\n".join(list(map(str, x)))))
inf = 10**17
mod = 10**9 + 7
n = I() // 2
lis = LI()
lis1 = []
lis2 = []
for i in range(n):
lis1.append(lis[2 * i])
lis2.append(lis[2 * i + 1])
x = Counter(lis1).most_common(2)
y = Counter(lis2).most_common(2)
# print(x)
# print(y)
if len(x) == 1:
x.append((0, 0))
if len(y) == 1:
y.append((-1, 0))
# print(x)
# print(y)
if x[0][0] != y[0][0]:
print((2 * n - x[0][1] - y[0][1]))
else:
cands = []
# print(2*n-x[0][1]-y[1][]))
if x[1][0] != y[0][0]:
cands.append(2 * n - x[1][1] - y[0][1])
if x[0][0] != y[1][0]:
cands.append(2 * n - x[0][1] - y[1][1])
if x[1][0] != y[1][0]:
cands.append(2 * n - x[1][1] - y[1][1])
print((min(cands)))
| false | 20.689655 | [
"-# dpでできないかな?",
"+# float型を許すな",
"+# numpyはpythonで",
"-from math import floor, ceil, pi",
"+from math import floor, ceil, pi, factorial",
"-n = I()",
"+n = I() // 2",
"-ev, od = [], []",
"+lis1 = []",
"+lis2 = []",
"- if i % 2 == 0:",
"- ev.append(lis[i])",
"- else:",
"- ... | false | 0.291263 | 0.177491 | 1.641007 | [
"s299696830",
"s877473548"
] |
u190405389 | p02585 | python | s642950204 | s776126936 | 630 | 439 | 92,780 | 10,160 | Accepted | Accepted | 30.32 | import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print(('\n'.join(map(str,x))))
def printline(x):print((' '.join(map(str,x))))
def check(cir,num):
ans = -10**20
l = len(cir)
for start in range(l):
a = 0
for i in range(num):
if start+i == l:
start = -i
a += cir[start + i]
ans = max(ans,a)
return ans
n,k = readints()
p = [x-1 for x in readints()]
c = readints()
circles = []
used = [0]*n
for i in range(n):
if not used[i]:
circles.append([c[i]])
used[i] = 1
j = p[i]
while not used[j]:
circles[-1].append(c[j])
used[j] = 1
j = p[j]
score = -10**20
for cir in circles:
m = len(cir)
a = sum(cir)
if k>m:
if a>0:
score = max(score, (k//m)*a + check(cir,k%m), (k//m-1)*a + check(cir,m))
else:
score = max(score,check(cir,m))
else:
score = max(score,check(cir,k))
print(score)
| import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print(('\n'.join(map(str,x))))
def printline(x):print((' '.join(map(str,x))))
def check(cir,num):
m = len(cir)
a = sum(cir)
if num == 0:
ss = 0
elif num == 1:
ss = max(cir)
else:
ac = list(accumulate([0]+cir))
l = 0
r = 1
ss = ac[r]-ac[l]
i = 0
while 1:
if r == m:
l = ac[l+1:r].index(min(ac[l+1:r])) + l+1
ss = max(ss,ac[r]-ac[l])
break
elif i%2==0:
r = ac[r+1:l+num+1].index(max(ac[r+1:l+num+1])) + r+1
else:
l = ac[l+1:r].index(min(ac[l+1:r])) + l+1
i+=1
ss = max(ss,ac[r]-ac[l])
num = m-num
l = 0
r = num
i = 0
ss = max(ss,a-ac[r]+ac[l])
while 1:
if r == m:
l = ac[l+1:r-num+1].index(max(ac[l+1:r-num+1])) + l+1
ss = max(ss,a-ac[r]+ac[l])
break
elif i%2==0:
r = ac[r+1:l+m].index(min(ac[r+1:l+m])) + r+1
else:
l = ac[l+1:r-num+1].index(max(ac[l+1:r-num+1])) + l+1
i+=1
ss = max(ss,a-ac[r]+ac[l])
return ss
from itertools import accumulate
n,k = readints()
p = [x-1 for x in readints()]
c = readints()
circles = []
used = [0]*n
for i in range(n):
if not used[i]:
circles.append([c[i]])
used[i] = 1
j = p[i]
while not used[j]:
circles[-1].append(c[j])
used[j] = 1
j = p[j]
score = -10**20
for cir in circles:
m = len(cir)
a = sum(cir)
if k>m:
if a>0:
score = max(score, (k//m)*a + check(cir,k%m), (k//m-1)*a + check(cir,m))
else:
score = max(score,check(cir,m))
else:
score = max(score,check(cir,k))
print(score)
| 62 | 96 | 1,309 | 2,270 | import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():
return readline().rstrip().decode()
def readstrs():
return list(readline().decode().split())
def readint():
return int(readline())
def readints():
return list(map(int, readline().split()))
def printrows(x):
print(("\n".join(map(str, x))))
def printline(x):
print((" ".join(map(str, x))))
def check(cir, num):
ans = -(10**20)
l = len(cir)
for start in range(l):
a = 0
for i in range(num):
if start + i == l:
start = -i
a += cir[start + i]
ans = max(ans, a)
return ans
n, k = readints()
p = [x - 1 for x in readints()]
c = readints()
circles = []
used = [0] * n
for i in range(n):
if not used[i]:
circles.append([c[i]])
used[i] = 1
j = p[i]
while not used[j]:
circles[-1].append(c[j])
used[j] = 1
j = p[j]
score = -(10**20)
for cir in circles:
m = len(cir)
a = sum(cir)
if k > m:
if a > 0:
score = max(
score,
(k // m) * a + check(cir, k % m),
(k // m - 1) * a + check(cir, m),
)
else:
score = max(score, check(cir, m))
else:
score = max(score, check(cir, k))
print(score)
| import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():
return readline().rstrip().decode()
def readstrs():
return list(readline().decode().split())
def readint():
return int(readline())
def readints():
return list(map(int, readline().split()))
def printrows(x):
print(("\n".join(map(str, x))))
def printline(x):
print((" ".join(map(str, x))))
def check(cir, num):
m = len(cir)
a = sum(cir)
if num == 0:
ss = 0
elif num == 1:
ss = max(cir)
else:
ac = list(accumulate([0] + cir))
l = 0
r = 1
ss = ac[r] - ac[l]
i = 0
while 1:
if r == m:
l = ac[l + 1 : r].index(min(ac[l + 1 : r])) + l + 1
ss = max(ss, ac[r] - ac[l])
break
elif i % 2 == 0:
r = ac[r + 1 : l + num + 1].index(max(ac[r + 1 : l + num + 1])) + r + 1
else:
l = ac[l + 1 : r].index(min(ac[l + 1 : r])) + l + 1
i += 1
ss = max(ss, ac[r] - ac[l])
num = m - num
l = 0
r = num
i = 0
ss = max(ss, a - ac[r] + ac[l])
while 1:
if r == m:
l = ac[l + 1 : r - num + 1].index(max(ac[l + 1 : r - num + 1])) + l + 1
ss = max(ss, a - ac[r] + ac[l])
break
elif i % 2 == 0:
r = ac[r + 1 : l + m].index(min(ac[r + 1 : l + m])) + r + 1
else:
l = ac[l + 1 : r - num + 1].index(max(ac[l + 1 : r - num + 1])) + l + 1
i += 1
ss = max(ss, a - ac[r] + ac[l])
return ss
from itertools import accumulate
n, k = readints()
p = [x - 1 for x in readints()]
c = readints()
circles = []
used = [0] * n
for i in range(n):
if not used[i]:
circles.append([c[i]])
used[i] = 1
j = p[i]
while not used[j]:
circles[-1].append(c[j])
used[j] = 1
j = p[j]
score = -(10**20)
for cir in circles:
m = len(cir)
a = sum(cir)
if k > m:
if a > 0:
score = max(
score,
(k // m) * a + check(cir, k % m),
(k // m - 1) * a + check(cir, m),
)
else:
score = max(score, check(cir, m))
else:
score = max(score, check(cir, k))
print(score)
| false | 35.416667 | [
"- ans = -(10**20)",
"- l = len(cir)",
"- for start in range(l):",
"- a = 0",
"- for i in range(num):",
"- if start + i == l:",
"- start = -i",
"- a += cir[start + i]",
"- ans = max(ans, a)",
"- return ans",
"+ m = len(... | false | 0.039332 | 0.041886 | 0.939036 | [
"s642950204",
"s776126936"
] |
u729133443 | p03061 | python | s556157187 | s151387062 | 644 | 389 | 96,952 | 16,144 | Accepted | Accepted | 39.6 | class SegTree():
def __init__(self,data,unit,f):
self.size=n=len(data)
self.data=[unit for _ in range(n)]+data
for i in range(n-1,0,-1):self.data[i]=f(self.data[i+i],self.data[i-~i])
self.unit=unit
self.f=f
def update(self,i,x):
c,f=self.data,self.f
i+=self.size
c[i]=x
while i>1:
i>>=1
c[i]=f(c[i+i],c[i-~i])
def add(self,i,x):
c,f=self.data,self.f
i+=self.size
c[i]=f(c[i],x)
while i>1:
i>>=1
c[i]=f(c[i+i],c[i-~i])
def query(self,l,r):
c,f=self.data,self.f
x,y=self.unit,self.unit
l+=self.size
r+=self.size
while l<r:
if l&1:
x=f(x,c[l])
l+=1
if r&1:
r-=1
y=f(c[r],y)
l>>=1
r>>=1
return f(x,y)
def main():
from fractions import gcd
n,*a=list(map(int,open(0).read().split()))
f=SegTree(a,0,gcd).query
m=max(f(1,n),f(0,n-1))
for i in range(n-2):
m=max(m,gcd(f(0,i+1),f(i+2,n)))
print(m)
main() | class SWAG():
__slots__='unit','f','fold_r','fold_l','data_r','data_l'
def __init__(self,unit,f,data):
self.unit=unit
self.f=f
self.construct(data)
def construct(self,data):
self.fold_r=[self.unit]
self.fold_l=[self.unit]
self.data_r=[]
self.data_l=[]
sep=0--len(data)//2
for t in data[sep:]:
self.append(t)
for t in data[sep-1::-1]:
self.appendleft(t)
def append(self,x):
self.fold_r.append(self.f(self.fold_r[-1],x))
self.data_r.append(x)
def appendleft(self,x):
self.fold_l.append(self.f(self.fold_l[-1],x))
self.data_l.append(x)
def pop(self):
if not self.data_r:
self.construct(self.data_l[::-1])
if not self.data_r:
return self.popleft()
self.fold_r.pop()
return self.data_r.pop()
def popleft(self):
if not self.data_l:
self.construct(self.data_r)
if not self.data_l:
return False
self.fold_l.pop()
return self.data_l.pop()
def fold_all(self):
return self.f(self.fold_r[-1],self.fold_l[-1])
def main():
from fractions import gcd
n,*a=list(map(int,open(0).read().split()))
l,r=SWAG(0,gcd,[]),SWAG(0,gcd,a[1:])
m=r.fold_all()
for i in range(n-1):
l.append(a[i])
r.popleft()
m=max(m,gcd(l.fold_all(),r.fold_all()))
print(m)
main() | 45 | 49 | 1,192 | 1,511 | class SegTree:
def __init__(self, data, unit, f):
self.size = n = len(data)
self.data = [unit for _ in range(n)] + data
for i in range(n - 1, 0, -1):
self.data[i] = f(self.data[i + i], self.data[i - ~i])
self.unit = unit
self.f = f
def update(self, i, x):
c, f = self.data, self.f
i += self.size
c[i] = x
while i > 1:
i >>= 1
c[i] = f(c[i + i], c[i - ~i])
def add(self, i, x):
c, f = self.data, self.f
i += self.size
c[i] = f(c[i], x)
while i > 1:
i >>= 1
c[i] = f(c[i + i], c[i - ~i])
def query(self, l, r):
c, f = self.data, self.f
x, y = self.unit, self.unit
l += self.size
r += self.size
while l < r:
if l & 1:
x = f(x, c[l])
l += 1
if r & 1:
r -= 1
y = f(c[r], y)
l >>= 1
r >>= 1
return f(x, y)
def main():
from fractions import gcd
n, *a = list(map(int, open(0).read().split()))
f = SegTree(a, 0, gcd).query
m = max(f(1, n), f(0, n - 1))
for i in range(n - 2):
m = max(m, gcd(f(0, i + 1), f(i + 2, n)))
print(m)
main()
| class SWAG:
__slots__ = "unit", "f", "fold_r", "fold_l", "data_r", "data_l"
def __init__(self, unit, f, data):
self.unit = unit
self.f = f
self.construct(data)
def construct(self, data):
self.fold_r = [self.unit]
self.fold_l = [self.unit]
self.data_r = []
self.data_l = []
sep = 0 - -len(data) // 2
for t in data[sep:]:
self.append(t)
for t in data[sep - 1 :: -1]:
self.appendleft(t)
def append(self, x):
self.fold_r.append(self.f(self.fold_r[-1], x))
self.data_r.append(x)
def appendleft(self, x):
self.fold_l.append(self.f(self.fold_l[-1], x))
self.data_l.append(x)
def pop(self):
if not self.data_r:
self.construct(self.data_l[::-1])
if not self.data_r:
return self.popleft()
self.fold_r.pop()
return self.data_r.pop()
def popleft(self):
if not self.data_l:
self.construct(self.data_r)
if not self.data_l:
return False
self.fold_l.pop()
return self.data_l.pop()
def fold_all(self):
return self.f(self.fold_r[-1], self.fold_l[-1])
def main():
from fractions import gcd
n, *a = list(map(int, open(0).read().split()))
l, r = SWAG(0, gcd, []), SWAG(0, gcd, a[1:])
m = r.fold_all()
for i in range(n - 1):
l.append(a[i])
r.popleft()
m = max(m, gcd(l.fold_all(), r.fold_all()))
print(m)
main()
| false | 8.163265 | [
"-class SegTree:",
"- def __init__(self, data, unit, f):",
"- self.size = n = len(data)",
"- self.data = [unit for _ in range(n)] + data",
"- for i in range(n - 1, 0, -1):",
"- self.data[i] = f(self.data[i + i], self.data[i - ~i])",
"+class SWAG:",
"+ __slots__ = ... | false | 0.055068 | 0.05518 | 0.997977 | [
"s556157187",
"s151387062"
] |
u785578220 | p03160 | python | s476404607 | s116860264 | 220 | 170 | 13,976 | 13,928 | Accepted | Accepted | 22.73 | a = int(eval(input()))
b = 2+1#int(input())
x = list(map(int, input().split()))
dp = [0]+[10**10]*(a-1)
dp[1] = abs(x[1]-x[0])
for i,h in enumerate(x):
for j in range(i+1,min(i+b,a)):
dp[j] = min(dp[j],dp[i]+abs(h-x[j]))
#print(dp)
print((dp[a-1])) | n = int(eval(input()))
H = list(map(int,input().split()))
inf = float('INF')
dp = [inf]*n
dp[0] = 0
for i in range(1,n):
if i != 1:dp[i]=min(dp[i],dp[i-2]+abs(H[i]-H[i-2]))
dp[i]=min(dp[i],dp[i-1]+abs(H[i]-H[i-1]))
print((dp[-1])) | 10 | 11 | 261 | 242 | a = int(eval(input()))
b = 2 + 1 # int(input())
x = list(map(int, input().split()))
dp = [0] + [10**10] * (a - 1)
dp[1] = abs(x[1] - x[0])
for i, h in enumerate(x):
for j in range(i + 1, min(i + b, a)):
dp[j] = min(dp[j], dp[i] + abs(h - x[j]))
# print(dp)
print((dp[a - 1]))
| n = int(eval(input()))
H = list(map(int, input().split()))
inf = float("INF")
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
if i != 1:
dp[i] = min(dp[i], dp[i - 2] + abs(H[i] - H[i - 2]))
dp[i] = min(dp[i], dp[i - 1] + abs(H[i] - H[i - 1]))
print((dp[-1]))
| false | 9.090909 | [
"-a = int(eval(input()))",
"-b = 2 + 1 # int(input())",
"-x = list(map(int, input().split()))",
"-dp = [0] + [10**10] * (a - 1)",
"-dp[1] = abs(x[1] - x[0])",
"-for i, h in enumerate(x):",
"- for j in range(i + 1, min(i + b, a)):",
"- dp[j] = min(dp[j], dp[i] + abs(h - x[j]))",
"-# print(... | false | 0.008301 | 0.067837 | 0.122365 | [
"s476404607",
"s116860264"
] |
u450983668 | p03037 | python | s153225158 | s744839447 | 325 | 67 | 3,060 | 25,076 | Accepted | Accepted | 79.38 | n, m = list(map(int, input().split()))
lmin = 0
lmax = 1e5+10
for _ in range(m):
l, r = list(map(int, input().split()))
lmin = max(lmin, l)
lmax = min(lmax, r)
print((max(0, lmax-lmin+1))) | n, m, *ls = list(map(int, open(0).read().split()))
l = max(ls[0::2])
r = min(ls[1::2])
print((max(0, r-l+1))) | 8 | 4 | 187 | 104 | n, m = list(map(int, input().split()))
lmin = 0
lmax = 1e5 + 10
for _ in range(m):
l, r = list(map(int, input().split()))
lmin = max(lmin, l)
lmax = min(lmax, r)
print((max(0, lmax - lmin + 1)))
| n, m, *ls = list(map(int, open(0).read().split()))
l = max(ls[0::2])
r = min(ls[1::2])
print((max(0, r - l + 1)))
| false | 50 | [
"-n, m = list(map(int, input().split()))",
"-lmin = 0",
"-lmax = 1e5 + 10",
"-for _ in range(m):",
"- l, r = list(map(int, input().split()))",
"- lmin = max(lmin, l)",
"- lmax = min(lmax, r)",
"-print((max(0, lmax - lmin + 1)))",
"+n, m, *ls = list(map(int, open(0).read().split()))",
"+l ... | false | 0.043585 | 0.037784 | 1.153526 | [
"s153225158",
"s744839447"
] |
u729133443 | p02723 | python | s234069413 | s253523998 | 164 | 25 | 38,256 | 9,104 | Accepted | Accepted | 84.76 | s=eval(input())
print(('YNeos'[s[2::2]!=s[3::2]::2])) | s=eval(input())
print(('YNeos'[s[2::3]!=s[3:5]::2])) | 2 | 2 | 46 | 45 | s = eval(input())
print(("YNeos"[s[2::2] != s[3::2] :: 2]))
| s = eval(input())
print(("YNeos"[s[2::3] != s[3:5] :: 2]))
| false | 0 | [
"-print((\"YNeos\"[s[2::2] != s[3::2] :: 2]))",
"+print((\"YNeos\"[s[2::3] != s[3:5] :: 2]))"
] | false | 0.069189 | 0.044793 | 1.544629 | [
"s234069413",
"s253523998"
] |
u547167033 | p02780 | python | s182256425 | s570160949 | 155 | 134 | 24,548 | 25,060 | Accepted | Accepted | 13.55 | n,k=list(map(int,input().split()))
p=list(map(int,input().split()))
cnt=sum(p[:k])
ans=cnt
for i in range(k,n):
cnt-=p[i-k]
cnt+=p[i]
ans=max(ans,cnt)
print((ans/2+k/2)) | n,k=list(map(int,input().split()))
p=list(map(int,input().split()))
x=sum(p[:k])
max_x=x
idx=0
for i in range(k,n):
x=x+p[i]-p[i-k]
if max_x<x:
idx=i-k+1
max_x=x
ans=0
for i in range(idx,idx+k):
ans+=(p[i]*(p[i]+1)//2)/p[i]
print(ans) | 9 | 14 | 175 | 255 | n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
cnt = sum(p[:k])
ans = cnt
for i in range(k, n):
cnt -= p[i - k]
cnt += p[i]
ans = max(ans, cnt)
print((ans / 2 + k / 2))
| n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
x = sum(p[:k])
max_x = x
idx = 0
for i in range(k, n):
x = x + p[i] - p[i - k]
if max_x < x:
idx = i - k + 1
max_x = x
ans = 0
for i in range(idx, idx + k):
ans += (p[i] * (p[i] + 1) // 2) / p[i]
print(ans)
| false | 35.714286 | [
"-cnt = sum(p[:k])",
"-ans = cnt",
"+x = sum(p[:k])",
"+max_x = x",
"+idx = 0",
"- cnt -= p[i - k]",
"- cnt += p[i]",
"- ans = max(ans, cnt)",
"-print((ans / 2 + k / 2))",
"+ x = x + p[i] - p[i - k]",
"+ if max_x < x:",
"+ idx = i - k + 1",
"+ max_x = x",
"+ans... | false | 0.038767 | 0.039699 | 0.976533 | [
"s182256425",
"s570160949"
] |
u638456847 | p02879 | python | s455569805 | s009108306 | 19 | 17 | 3,064 | 3,064 | Accepted | Accepted | 10.53 | def main():
a,b = list(map(str, input().split()))
if len(a) == 1 and len(b) == 1:
print((int(a) * int(b)))
else:
print("-1")
if __name__ == "__main__":
main()
| def main():
a,b = list(map(int, input().split()))
print((a * b if a < 10 and b < 10 else "-1"))
if __name__ == "__main__":
main()
| 11 | 7 | 196 | 142 | def main():
a, b = list(map(str, input().split()))
if len(a) == 1 and len(b) == 1:
print((int(a) * int(b)))
else:
print("-1")
if __name__ == "__main__":
main()
| def main():
a, b = list(map(int, input().split()))
print((a * b if a < 10 and b < 10 else "-1"))
if __name__ == "__main__":
main()
| false | 36.363636 | [
"- a, b = list(map(str, input().split()))",
"- if len(a) == 1 and len(b) == 1:",
"- print((int(a) * int(b)))",
"- else:",
"- print(\"-1\")",
"+ a, b = list(map(int, input().split()))",
"+ print((a * b if a < 10 and b < 10 else \"-1\"))"
] | false | 0.082245 | 0.073344 | 1.121349 | [
"s455569805",
"s009108306"
] |
u221264296 | p02612 | python | s599398618 | s599229411 | 34 | 28 | 9,152 | 9,076 | Accepted | Accepted | 17.65 | n = int(eval(input()))
i=1
ans=0
for i in range(100):
if i*1000>=n:
ans = i*1000-n
break
print(ans)
| n=int(eval(input()))
if n%1000==0:
print((0))
else:print((1000-n%1000)) | 8 | 4 | 106 | 66 | n = int(eval(input()))
i = 1
ans = 0
for i in range(100):
if i * 1000 >= n:
ans = i * 1000 - n
break
print(ans)
| n = int(eval(input()))
if n % 1000 == 0:
print((0))
else:
print((1000 - n % 1000))
| false | 50 | [
"-i = 1",
"-ans = 0",
"-for i in range(100):",
"- if i * 1000 >= n:",
"- ans = i * 1000 - n",
"- break",
"-print(ans)",
"+if n % 1000 == 0:",
"+ print((0))",
"+else:",
"+ print((1000 - n % 1000))"
] | false | 0.041574 | 0.034713 | 1.19764 | [
"s599398618",
"s599229411"
] |
u593567568 | p02763 | python | s058871669 | s832295761 | 1,572 | 696 | 172,640 | 48,980 | Accepted | Accepted | 55.73 | import sys
sys.setrecursionlimit(10 ** 7)
class SegmentTree:
"""
引数:
N: 処理する区間の長さ
operator: モノイド演算 (max, min, __add__,ラムダ式,関数定義など)
UNIT: 単位元
a: 長さNの配列 a で初期化(a を与えない場合、単位元で初期化)
注意: 内部的には 1-indexed
"""
def __init__(self, N, operator, unit, a=None):
self.op = operator
self.UNIT = unit
self.N0 = 2**(N-1).bit_length()
self.tree = [self.UNIT]*(2*self.N0)
if a != None:
self.tree[self.N0:self.N0+N] = a[:]
for k in range(self.N0-1, 0, -1):
self.tree[k] = self.op(self.tree[2*k], self.tree[2*k+1])
# a_k の値を x に更新
def update(self, k, x):
k += self.N0
self.tree[k] = x
k //= 2
while k:
self.tree[k] = self.op(self.tree[2*k], self.tree[2*k+1])
k //= 2
# 区間[l,r)をopでまとめる
def query(self, l, r):
L = l + self.N0
R = r + self.N0
s = self.UNIT
while L < R:
if R & 1:
R -= 1
s = self.op(self.tree[R], s)
if L & 1:
s = self.op(s, self.tree[L])
L += 1
L >>= 1
R >>= 1
return s
def get(self, k): # k番目の値を取得。query[k,k]と同じ
return self.tree[k + self.N0]
def all(self):
return self.tree[1]
N = int(eval(input()))
S = eval(input())
S = list(S)
def ope(x, y):
r = []
if type(x) is str and type(y) is str:
r = [x, y]
elif type(x) is str:
r = [x] + y
elif type(y) is str:
r = x + [y]
else:
r = x + y
return list(set(r))
seg = SegmentTree(N, ope, '-', S)
Q = int(eval(input()))
ans = []
for _ in range(Q):
q, a, b = input().split()
if q == '1':
seg.update(int(a) - 1, b)
else:
r = seg.query(int(a) - 1, int(b))
ans.append(str(len(r)-1))
print(("\n".join(ans)))
| import sys
from operator import or_
sys.setrecursionlimit(10 ** 7)
# AC
# Python3 (3.4.3) TLE
# PyPy3 (2.4.0) 1572 ms
class SegmentTree:
"""
引数:
N: 処理する区間の長さ
operator: モノイド演算 (max, min, __add__,ラムダ式,関数定義など)
UNIT: 単位元
a: 長さNの配列 a で初期化(a を与えない場合、単位元で初期化)
注意: 内部的には 1-indexed
"""
def __init__(self, N, operator, unit, a=None):
self.op = operator
self.UNIT = unit
self.N0 = 2**(N-1).bit_length()
self.tree = [self.UNIT]*(2*self.N0)
if a != None:
self.tree[self.N0:self.N0+N] = a[:]
for k in range(self.N0-1, 0, -1):
self.tree[k] = self.op(self.tree[2*k], self.tree[2*k+1])
# a_k の値を x に更新
def update(self, k, x):
k += self.N0
self.tree[k] = x
k //= 2
while k:
self.tree[k] = self.op(self.tree[2*k], self.tree[2*k+1])
k //= 2
# 区間[l,r)をopでまとめる
def query(self, l, r):
L = l + self.N0
R = r + self.N0
s = self.UNIT
while L < R:
if R & 1:
R -= 1
s = self.op(self.tree[R], s)
if L & 1:
s = self.op(s, self.tree[L])
L += 1
L >>= 1
R >>= 1
return s
def get(self, k): # k番目の値を取得。query[k,k]と同じ
return self.tree[k + self.N0]
def all(self):
return self.tree[1]
N = int(eval(input()))
S = eval(input())
S = [1 << (ord(x) - 97) for x in S]
seg = SegmentTree(N, or_, 0, S)
Q = int(eval(input()))
ans = []
for _ in range(Q):
q, a, b = input().split()
if q == '1':
b = 1 << (ord(b) - 97)
seg.update(int(a) - 1, b)
else:
r = seg.query(int(a) - 1, int(b))
cnt = 0
for i in range(26):
if r & (1 << i):
cnt += 1
ans.append(str(cnt))
print(("\n".join(ans)))
| 92 | 89 | 2,000 | 1,989 | import sys
sys.setrecursionlimit(10**7)
class SegmentTree:
"""
引数:
N: 処理する区間の長さ
operator: モノイド演算 (max, min, __add__,ラムダ式,関数定義など)
UNIT: 単位元
a: 長さNの配列 a で初期化(a を与えない場合、単位元で初期化)
注意: 内部的には 1-indexed
"""
def __init__(self, N, operator, unit, a=None):
self.op = operator
self.UNIT = unit
self.N0 = 2 ** (N - 1).bit_length()
self.tree = [self.UNIT] * (2 * self.N0)
if a != None:
self.tree[self.N0 : self.N0 + N] = a[:]
for k in range(self.N0 - 1, 0, -1):
self.tree[k] = self.op(self.tree[2 * k], self.tree[2 * k + 1])
# a_k の値を x に更新
def update(self, k, x):
k += self.N0
self.tree[k] = x
k //= 2
while k:
self.tree[k] = self.op(self.tree[2 * k], self.tree[2 * k + 1])
k //= 2
# 区間[l,r)をopでまとめる
def query(self, l, r):
L = l + self.N0
R = r + self.N0
s = self.UNIT
while L < R:
if R & 1:
R -= 1
s = self.op(self.tree[R], s)
if L & 1:
s = self.op(s, self.tree[L])
L += 1
L >>= 1
R >>= 1
return s
def get(self, k): # k番目の値を取得。query[k,k]と同じ
return self.tree[k + self.N0]
def all(self):
return self.tree[1]
N = int(eval(input()))
S = eval(input())
S = list(S)
def ope(x, y):
r = []
if type(x) is str and type(y) is str:
r = [x, y]
elif type(x) is str:
r = [x] + y
elif type(y) is str:
r = x + [y]
else:
r = x + y
return list(set(r))
seg = SegmentTree(N, ope, "-", S)
Q = int(eval(input()))
ans = []
for _ in range(Q):
q, a, b = input().split()
if q == "1":
seg.update(int(a) - 1, b)
else:
r = seg.query(int(a) - 1, int(b))
ans.append(str(len(r) - 1))
print(("\n".join(ans)))
| import sys
from operator import or_
sys.setrecursionlimit(10**7)
# AC
# Python3 (3.4.3) TLE
# PyPy3 (2.4.0) 1572 ms
class SegmentTree:
"""
引数:
N: 処理する区間の長さ
operator: モノイド演算 (max, min, __add__,ラムダ式,関数定義など)
UNIT: 単位元
a: 長さNの配列 a で初期化(a を与えない場合、単位元で初期化)
注意: 内部的には 1-indexed
"""
def __init__(self, N, operator, unit, a=None):
self.op = operator
self.UNIT = unit
self.N0 = 2 ** (N - 1).bit_length()
self.tree = [self.UNIT] * (2 * self.N0)
if a != None:
self.tree[self.N0 : self.N0 + N] = a[:]
for k in range(self.N0 - 1, 0, -1):
self.tree[k] = self.op(self.tree[2 * k], self.tree[2 * k + 1])
# a_k の値を x に更新
def update(self, k, x):
k += self.N0
self.tree[k] = x
k //= 2
while k:
self.tree[k] = self.op(self.tree[2 * k], self.tree[2 * k + 1])
k //= 2
# 区間[l,r)をopでまとめる
def query(self, l, r):
L = l + self.N0
R = r + self.N0
s = self.UNIT
while L < R:
if R & 1:
R -= 1
s = self.op(self.tree[R], s)
if L & 1:
s = self.op(s, self.tree[L])
L += 1
L >>= 1
R >>= 1
return s
def get(self, k): # k番目の値を取得。query[k,k]と同じ
return self.tree[k + self.N0]
def all(self):
return self.tree[1]
N = int(eval(input()))
S = eval(input())
S = [1 << (ord(x) - 97) for x in S]
seg = SegmentTree(N, or_, 0, S)
Q = int(eval(input()))
ans = []
for _ in range(Q):
q, a, b = input().split()
if q == "1":
b = 1 << (ord(b) - 97)
seg.update(int(a) - 1, b)
else:
r = seg.query(int(a) - 1, int(b))
cnt = 0
for i in range(26):
if r & (1 << i):
cnt += 1
ans.append(str(cnt))
print(("\n".join(ans)))
| false | 3.26087 | [
"+from operator import or_",
"-",
"-",
"+# AC",
"+# Python3 (3.4.3) TLE",
"+# PyPy3 (2.4.0) 1572 ms",
"-S = list(S)",
"-",
"-",
"-def ope(x, y):",
"- r = []",
"- if type(x) is str and type(y) is str:",
"- r = [x, y]",
"- elif type(x) is str:",
"- r = [x] + y",
"-... | false | 0.0645 | 0.057786 | 1.116193 | [
"s058871669",
"s832295761"
] |
u994988729 | p02954 | python | s037894906 | s144982425 | 1,918 | 131 | 279,772 | 19,816 | Accepted | Accepted | 93.17 | import numpy as np
S = eval(input())
N = len(S)
move = 10 ** 100
U = N + 1
D = move.bit_length()
dbl = np.zeros((D, U), dtype=int)
for i, s in enumerate(S, start=1):
if s == "R":
dbl[0, i] = i + 1
else:
dbl[0, i] = i - 1
for h in range(D - 1):
dbl[h + 1] = dbl[h, dbl[h]]
child = np.arange(1, N + 1)
for i in reversed(list(range(D))):
if move & (1 << i):
child = dbl[i, child]
ans = np.bincount(child, minlength=N + 1)
print((*ans[1:])) | def RunLengthEncoding(S):
res = []
N = len(S)
i = 0
while i < N:
cnt = 1
while i < N - 1 and S[i] == S[i + 1]:
cnt += 1
i += 1
res.append((S[i], cnt))
i += 1
return res
S = eval(input())
N = len(S)
rle = RunLengthEncoding(S)
goal = []
for i, (l, r) in enumerate(zip(S[:-1], S[1:])):
if l == "R" and r == "L":
goal.append(i)
ans = [0] * N
p = 0
for i in range(0, len(rle), 2):
_, nl = rle[i]
_, nr = rle[i+1]
g = goal[i//2]
ans[g] += (nl + 1) // 2
ans[g+1] += nl // 2
ans[g+1] += (nr + 1) // 2
ans[g] += nr // 2
print((*ans)) | 26 | 36 | 493 | 673 | import numpy as np
S = eval(input())
N = len(S)
move = 10**100
U = N + 1
D = move.bit_length()
dbl = np.zeros((D, U), dtype=int)
for i, s in enumerate(S, start=1):
if s == "R":
dbl[0, i] = i + 1
else:
dbl[0, i] = i - 1
for h in range(D - 1):
dbl[h + 1] = dbl[h, dbl[h]]
child = np.arange(1, N + 1)
for i in reversed(list(range(D))):
if move & (1 << i):
child = dbl[i, child]
ans = np.bincount(child, minlength=N + 1)
print((*ans[1:]))
| def RunLengthEncoding(S):
res = []
N = len(S)
i = 0
while i < N:
cnt = 1
while i < N - 1 and S[i] == S[i + 1]:
cnt += 1
i += 1
res.append((S[i], cnt))
i += 1
return res
S = eval(input())
N = len(S)
rle = RunLengthEncoding(S)
goal = []
for i, (l, r) in enumerate(zip(S[:-1], S[1:])):
if l == "R" and r == "L":
goal.append(i)
ans = [0] * N
p = 0
for i in range(0, len(rle), 2):
_, nl = rle[i]
_, nr = rle[i + 1]
g = goal[i // 2]
ans[g] += (nl + 1) // 2
ans[g + 1] += nl // 2
ans[g + 1] += (nr + 1) // 2
ans[g] += nr // 2
print((*ans))
| false | 27.777778 | [
"-import numpy as np",
"+def RunLengthEncoding(S):",
"+ res = []",
"+ N = len(S)",
"+ i = 0",
"+ while i < N:",
"+ cnt = 1",
"+ while i < N - 1 and S[i] == S[i + 1]:",
"+ cnt += 1",
"+ i += 1",
"+ res.append((S[i], cnt))",
"+ i += 1... | false | 0.267342 | 0.036538 | 7.316888 | [
"s037894906",
"s144982425"
] |
u750651325 | p03612 | python | s839124423 | s380332100 | 102 | 69 | 20,648 | 21,272 | Accepted | Accepted | 32.35 | N = int(eval(input()))
p = list(map(int, input().split()))
count = 0
i = 0
while N > i:
if p[i]-1 == i:
count += 1
i += 1
i+=1
print(count)
| import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return eval(input())
def i(): return int(eval(input()))
def S(): return input().split()
def I(): return list(map(int,input().split()))
def X(): return list(eval(input()))
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
N = i()
p = l()
count = 0
i = 0
while i < N:
if p[i] == i+1:
count += 1
i += 1
i += 1
print(count)
| 11 | 30 | 169 | 623 | N = int(eval(input()))
p = list(map(int, input().split()))
count = 0
i = 0
while N > i:
if p[i] - 1 == i:
count += 1
i += 1
i += 1
print(count)
| import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque, Counter
from decimal import Decimal
def s():
return eval(input())
def i():
return int(eval(input()))
def S():
return input().split()
def I():
return list(map(int, input().split()))
def X():
return list(eval(input()))
def L():
return list(input().split())
def l():
return list(map(int, input().split()))
def lcm(a, b):
return a * b // math.gcd(a, b)
sys.setrecursionlimit(10**9)
mod = 10**9 + 7
N = i()
p = l()
count = 0
i = 0
while i < N:
if p[i] == i + 1:
count += 1
i += 1
i += 1
print(count)
| false | 63.333333 | [
"-N = int(eval(input()))",
"-p = list(map(int, input().split()))",
"+import sys",
"+import math",
"+import itertools",
"+import bisect",
"+from copy import copy",
"+from collections import deque, Counter",
"+from decimal import Decimal",
"+",
"+",
"+def s():",
"+ return eval(input())",
... | false | 0.041483 | 0.09604 | 0.43194 | [
"s839124423",
"s380332100"
] |
u863442865 | p02689 | python | s714625853 | s664472722 | 231 | 209 | 31,276 | 30,532 | Accepted | Accepted | 9.52 | #MLE注意!0や1のケースに注意
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
import math
#from math import gcd
#inf = 10**17
#mod = 10**9 + 7
n,m = list(map(int, input().split()))
h = list(map(int, input().split()))
adj = [[] for _ in range(n)] #頂点数, 場合によって変える
for _ in range(m):
a,b = list(map(int, input().split()))
adj[a-1].append(b-1)
adj[b-1].append(a-1)
#-1まだ 0負け確 1良い
check = [-1]*n
for i in range(n):
if check[i] == 0:
continue
if len(adj[i]) == 0:
check[i] = 1
else:
for j in adj[i]:
if h[i] < h[j]:
check[i] = 0
break
elif h[i] == h[j]:
check[i] = 0
check[j] = 0
break
else:
check[j] = 0
if check[i] == -1:
check[i] = 1
res = 0
for i in check:
if i == 1:
res += 1
print(res)
if __name__ == '__main__':
main()
| #MLE注意!0や1のケースに注意
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
import math
#from math import gcd
#inf = 10**17
#mod = 10**9 + 7
n,m = list(map(int, input().split()))
h = list(map(int, input().split()))
adj = [[] for _ in range(n)] #頂点数, 場合によって変える
for _ in range(m):
a,b = list(map(int, input().split()))
adj[a-1].append(b-1)
adj[b-1].append(a-1)
res = 0
for i in range(n):
c = h[i]
for j in adj[i]:
if h[i] <= h[j]:
break
else:
res += 1
print(res)
if __name__ == '__main__':
main() | 53 | 38 | 1,420 | 958 | # MLE注意!0や1のケースに注意
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
# from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
import math
# from math import gcd
# inf = 10**17
# mod = 10**9 + 7
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
adj = [[] for _ in range(n)] # 頂点数, 場合によって変える
for _ in range(m):
a, b = list(map(int, input().split()))
adj[a - 1].append(b - 1)
adj[b - 1].append(a - 1)
# -1まだ 0負け確 1良い
check = [-1] * n
for i in range(n):
if check[i] == 0:
continue
if len(adj[i]) == 0:
check[i] = 1
else:
for j in adj[i]:
if h[i] < h[j]:
check[i] = 0
break
elif h[i] == h[j]:
check[i] = 0
check[j] = 0
break
else:
check[j] = 0
if check[i] == -1:
check[i] = 1
res = 0
for i in check:
if i == 1:
res += 1
print(res)
if __name__ == "__main__":
main()
| # MLE注意!0や1のケースに注意
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
# from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
import math
# from math import gcd
# inf = 10**17
# mod = 10**9 + 7
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
adj = [[] for _ in range(n)] # 頂点数, 場合によって変える
for _ in range(m):
a, b = list(map(int, input().split()))
adj[a - 1].append(b - 1)
adj[b - 1].append(a - 1)
res = 0
for i in range(n):
c = h[i]
for j in adj[i]:
if h[i] <= h[j]:
break
else:
res += 1
print(res)
if __name__ == "__main__":
main()
| false | 28.301887 | [
"- # -1まだ 0負け確 1良い",
"- check = [-1] * n",
"+ res = 0",
"- if check[i] == 0:",
"- continue",
"- if len(adj[i]) == 0:",
"- check[i] = 1",
"+ c = h[i]",
"+ for j in adj[i]:",
"+ if h[i] <= h[j]:",
"+ break",
"- ... | false | 0.097048 | 0.148132 | 0.65515 | [
"s714625853",
"s664472722"
] |
u645250356 | p02658 | python | s900783987 | s091498490 | 97 | 69 | 23,644 | 23,276 | Accepted | Accepted | 28.87 | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
a.sort()
x = 1
for i in range(n):
x *= a[i]
# print(i,x)
if x > 10**18:
print((-1))
quit()
print(x) | 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()))
n = inp()
a = inpl()
if 0 in set(a):
print((0))
quit()
res = 1
for x in a:
res *= x
if res > 10**18:
print((-1))
quit()
print(res) | 21 | 22 | 518 | 516 | from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
a.sort()
x = 1
for i in range(n):
x *= a[i]
# print(i,x)
if x > 10**18:
print((-1))
quit()
print(x)
| 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()))
n = inp()
a = inpl()
if 0 in set(a):
print((0))
quit()
res = 1
for x in a:
res *= x
if res > 10**18:
print((-1))
quit()
print(res)
| false | 4.545455 | [
"-from heapq import heappop, heappush, heapify",
"+from heapq import heappop, heappush",
"-import sys, math, itertools, fractions, pprint",
"+import sys, math, itertools, fractions",
"-a.sort()",
"-x = 1",
"-for i in range(n):",
"- x *= a[i]",
"- # print(i,x)",
"- if x > 10**18:",
"+if ... | false | 0.03589 | 0.076916 | 0.466611 | [
"s900783987",
"s091498490"
] |
u223133214 | p03037 | python | s519650409 | s778229413 | 612 | 294 | 60,376 | 56,284 | Accepted | Accepted | 51.96 | N, M = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(M)]
A, B = 1, N
for lr in LR:
L, R = lr
if R < A or B < L:
print((0))
exit()
if A <= L <= R <= B:
A, B = L, R
elif L <= A <= R <= B:
B = R
elif A <= L <= B <= R:
A = L
print((B - A + 1))
| import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(M)]
A, B = 1, N
for lr in LR:
L, R = lr
if R < A or B < L:
print((0))
exit()
if A <= L <= R <= B:
A, B = L, R
elif L <= A <= R <= B:
B = R
elif A <= L <= B <= R:
A = L
print((B - A + 1))
| 17 | 19 | 347 | 387 | N, M = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(M)]
A, B = 1, N
for lr in LR:
L, R = lr
if R < A or B < L:
print((0))
exit()
if A <= L <= R <= B:
A, B = L, R
elif L <= A <= R <= B:
B = R
elif A <= L <= B <= R:
A = L
print((B - A + 1))
| import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(M)]
A, B = 1, N
for lr in LR:
L, R = lr
if R < A or B < L:
print((0))
exit()
if A <= L <= R <= B:
A, B = L, R
elif L <= A <= R <= B:
B = R
elif A <= L <= B <= R:
A = L
print((B - A + 1))
| false | 10.526316 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.124437 | 0.083227 | 1.495154 | [
"s519650409",
"s778229413"
] |
u368780724 | p03212 | python | s443514534 | s984380808 | 102 | 71 | 6,936 | 6,920 | Accepted | Accepted | 30.39 | import bisect
N = int(eval(input()))
S = set([7,5,3])
for i in range(8):
for j in S.copy():
for k in [7,5,3]:
S.add(int(str(j)+str(k)))
S = list(sorted(S))
T = []
for i in S:
if str(i).count('3') and str(i).count('5') and str(i).count('7'):
T.append(i)
print((bisect.bisect_right(T,N))) | import bisect
N = int(eval(input()))
S = set([7,5,3])
for i in range(8):
for j in S.copy():
for k in [7,5,3]:
S.add(10*j+k)
T = []
for i in S:
if str(i).count('3') and str(i).count('5') and str(i).count('7'):
T.append(i)
T.sort()
print((bisect.bisect_right(T,N))) | 13 | 13 | 326 | 303 | import bisect
N = int(eval(input()))
S = set([7, 5, 3])
for i in range(8):
for j in S.copy():
for k in [7, 5, 3]:
S.add(int(str(j) + str(k)))
S = list(sorted(S))
T = []
for i in S:
if str(i).count("3") and str(i).count("5") and str(i).count("7"):
T.append(i)
print((bisect.bisect_right(T, N)))
| import bisect
N = int(eval(input()))
S = set([7, 5, 3])
for i in range(8):
for j in S.copy():
for k in [7, 5, 3]:
S.add(10 * j + k)
T = []
for i in S:
if str(i).count("3") and str(i).count("5") and str(i).count("7"):
T.append(i)
T.sort()
print((bisect.bisect_right(T, N)))
| false | 0 | [
"- S.add(int(str(j) + str(k)))",
"-S = list(sorted(S))",
"+ S.add(10 * j + k)",
"+T.sort()"
] | false | 0.165523 | 0.167735 | 0.986815 | [
"s443514534",
"s984380808"
] |
u442948527 | p03543 | python | s581953890 | s187564717 | 30 | 27 | 9,104 | 8,932 | Accepted | Accepted | 10 | N=eval(input())
M=int(N[:3])
N=int(N[1:4])
print((["No","Yes"][M%111==0 or N%111==0])) | a,b,c,d=eval(input())
print((['No','Yes'][a==b==c or b==c==d])) | 4 | 2 | 81 | 56 | N = eval(input())
M = int(N[:3])
N = int(N[1:4])
print((["No", "Yes"][M % 111 == 0 or N % 111 == 0]))
| a, b, c, d = eval(input())
print((["No", "Yes"][a == b == c or b == c == d]))
| false | 50 | [
"-N = eval(input())",
"-M = int(N[:3])",
"-N = int(N[1:4])",
"-print(([\"No\", \"Yes\"][M % 111 == 0 or N % 111 == 0]))",
"+a, b, c, d = eval(input())",
"+print(([\"No\", \"Yes\"][a == b == c or b == c == d]))"
] | false | 0.064692 | 0.134097 | 0.48243 | [
"s581953890",
"s187564717"
] |
u642874916 | p02629 | python | s779795496 | s700788862 | 192 | 87 | 74,504 | 74,628 | Accepted | Accepted | 54.69 | from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time
def I(): return int(eval(input()))
def S(): return eval(input())
def MI(): return list(map(int, input().split()))
def MS(): return list(map(str, input().split()))
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in eval(input())]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
for i in range(len(mat)):
print((*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]]))
yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True
ret = []
def Base_10_to_n(X, n):
if (int(X/n)):
return Base_10_to_n(int(X/n), n) + ',' +str(X%n)
return str(X%n)
def main():
N = I()
l = 0
c = 1
cur = N
last = cur
while True:
cur -= 26 ** c
c += 1
if cur < 0:
break
last = cur
if last == 0:
l = c - 2
# print('last=0', l, last)
d = Base_10_to_n(last, 25).split(',')
# print(d)
print((l * 'z'))
else:
l = c - 1
ans = []
last -= 1
if last == 0:
print((l * 'a'))
return
while last > 0:
# print('last', last)
r = last % 26
last //= 26
# print('last', last)
# print('r', l_alp[r])
ans.append(l_alp[r])
while len(ans) < l:
ans.append('a')
ans = ans[::-1]
temp = ''
for a in ans:
temp += a
print(temp)
# print(d)
# for i in range(1, 27):
# N = i
# while N > 0:
# r = N % 26
# N = N // 26
# print('N', N, 'r', r, l_alp[r])
# for N in range(1, 27):
# d = Base_10_to_n(N, 26).split(',')
# ans = ''
# print(N, d)
# for i in d:
# ans += l_alp[int(i)]
# print(ans)
if __name__ == '__main__':
main()
| from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time
def I(): return int(eval(input()))
def S(): return eval(input())
def MI(): return list(map(int, input().split()))
def MS(): return list(map(str, input().split()))
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in eval(input())]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
for i in range(len(mat)):
print((*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]]))
yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True
ret = []
def Base_10_to_n(X, n):
if (int(X/n)):
return Base_10_to_n(int(X/n), n) + ',' +str(X%n)
return str(X%n)
def main():
N = I()
N -= 1
for i in range(1, 15):
if N >= 26 ** i:
N -= 26 ** i
continue
ans = ''
for j in range(i):
r = N % 26
N //= 26
ans += l_alp[r]
print((ans[::-1]))
break
if __name__ == '__main__':
main()
| 118 | 69 | 2,856 | 1,868 | from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import (
permutations,
combinations,
accumulate,
product,
combinations_with_replacement,
)
import sys
import bisect
import string
import math
import time
def I():
return int(eval(input()))
def S():
return eval(input())
def MI():
return list(map(int, input().split()))
def MS():
return list(map(str, input().split()))
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def StoI():
return [ord(i) - 97 for i in eval(input())]
def ItoS(nn):
return chr(nn + 97)
def input():
return sys.stdin.readline().rstrip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
for i in range(len(mat)):
print((*["IINF" if v == IINF else "{:0=4}".format(v) for v in mat[i]]))
yn = {False: "No", True: "Yes"}
YN = {False: "NO", True: "YES"}
MOD = 10**9 + 7
inf = float("inf")
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
show_flg = False
# show_flg = True
ret = []
def Base_10_to_n(X, n):
if int(X / n):
return Base_10_to_n(int(X / n), n) + "," + str(X % n)
return str(X % n)
def main():
N = I()
l = 0
c = 1
cur = N
last = cur
while True:
cur -= 26**c
c += 1
if cur < 0:
break
last = cur
if last == 0:
l = c - 2
# print('last=0', l, last)
d = Base_10_to_n(last, 25).split(",")
# print(d)
print((l * "z"))
else:
l = c - 1
ans = []
last -= 1
if last == 0:
print((l * "a"))
return
while last > 0:
# print('last', last)
r = last % 26
last //= 26
# print('last', last)
# print('r', l_alp[r])
ans.append(l_alp[r])
while len(ans) < l:
ans.append("a")
ans = ans[::-1]
temp = ""
for a in ans:
temp += a
print(temp)
# print(d)
# for i in range(1, 27):
# N = i
# while N > 0:
# r = N % 26
# N = N // 26
# print('N', N, 'r', r, l_alp[r])
# for N in range(1, 27):
# d = Base_10_to_n(N, 26).split(',')
# ans = ''
# print(N, d)
# for i in d:
# ans += l_alp[int(i)]
# print(ans)
if __name__ == "__main__":
main()
| from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import (
permutations,
combinations,
accumulate,
product,
combinations_with_replacement,
)
import sys
import bisect
import string
import math
import time
def I():
return int(eval(input()))
def S():
return eval(input())
def MI():
return list(map(int, input().split()))
def MS():
return list(map(str, input().split()))
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def StoI():
return [ord(i) - 97 for i in eval(input())]
def ItoS(nn):
return chr(nn + 97)
def input():
return sys.stdin.readline().rstrip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
for i in range(len(mat)):
print((*["IINF" if v == IINF else "{:0=4}".format(v) for v in mat[i]]))
yn = {False: "No", True: "Yes"}
YN = {False: "NO", True: "YES"}
MOD = 10**9 + 7
inf = float("inf")
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
show_flg = False
# show_flg = True
ret = []
def Base_10_to_n(X, n):
if int(X / n):
return Base_10_to_n(int(X / n), n) + "," + str(X % n)
return str(X % n)
def main():
N = I()
N -= 1
for i in range(1, 15):
if N >= 26**i:
N -= 26**i
continue
ans = ""
for j in range(i):
r = N % 26
N //= 26
ans += l_alp[r]
print((ans[::-1]))
break
if __name__ == "__main__":
main()
| false | 41.525424 | [
"- l = 0",
"- c = 1",
"- cur = N",
"- last = cur",
"- while True:",
"- cur -= 26**c",
"- c += 1",
"- if cur < 0:",
"- break",
"- last = cur",
"- if last == 0:",
"- l = c - 2",
"- # print('last=0', l, last)",
"- d... | false | 0.047846 | 0.068684 | 0.696609 | [
"s779795496",
"s700788862"
] |
u750990077 | p02688 | python | s753292259 | s849051871 | 68 | 30 | 67,724 | 9,184 | Accepted | Accepted | 55.88 | def main():
n, k = list(map(int, input().split()))
snack = set()
for _ in range(k):
eval(input())
a = set(list(map(int, input().split())))
snack |= a
print((n-len(snack)))
if __name__ == "__main__":
main() | def main():
n, k = list(map(int, input().split()))
sunukes = set()
for _ in range(k):
eval(input())
sunukes |= set(list(map(int, input().split())))
print((n-len(sunukes)))
if __name__ == "__main__":
main() | 12 | 10 | 256 | 237 | def main():
n, k = list(map(int, input().split()))
snack = set()
for _ in range(k):
eval(input())
a = set(list(map(int, input().split())))
snack |= a
print((n - len(snack)))
if __name__ == "__main__":
main()
| def main():
n, k = list(map(int, input().split()))
sunukes = set()
for _ in range(k):
eval(input())
sunukes |= set(list(map(int, input().split())))
print((n - len(sunukes)))
if __name__ == "__main__":
main()
| false | 16.666667 | [
"- snack = set()",
"+ sunukes = set()",
"- a = set(list(map(int, input().split())))",
"- snack |= a",
"- print((n - len(snack)))",
"+ sunukes |= set(list(map(int, input().split())))",
"+ print((n - len(sunukes)))"
] | false | 0.098561 | 0.040276 | 2.447161 | [
"s753292259",
"s849051871"
] |
u075012704 | p03808 | python | s857903567 | s079915990 | 94 | 68 | 14,252 | 14,260 | Accepted | Accepted | 27.66 | N = int(eval(input()))
A = list(map(int, input().split()))
K = sum(A) / sum(range(1, N+1))
D = [A[i+1] - A[i] - K for i in range(-1, N-1)]
for d in D:
if not (d <= 0 and d % N == 0):
print("NO")
break
else:
print("YES") | N = int(eval(input()))
A = list(map(int, input().split()))
# 毎回1+2+...+N個の石が取り除かれる
Sum = sum(A)
if Sum % (N * (N + 1) // 2) != 0:
print('NO')
exit()
# 操作回数
K = Sum // (N * (N + 1) // 2)
Diff = [A[i] - A[(i - 1)] for i in range(N)]
# 変化量-1が(N-1)箇所、+(N-1)が一か所を、すべて-1した後に、一か所+1と置き換える
Diff = [d - K for d in Diff]
for d in Diff:
if d < 0:
if d % N != 0:
print('NO')
exit()
else:
K -= abs(d // N)
if K == 0:
print('YES')
else:
print('NO')
| 11 | 30 | 248 | 536 | N = int(eval(input()))
A = list(map(int, input().split()))
K = sum(A) / sum(range(1, N + 1))
D = [A[i + 1] - A[i] - K for i in range(-1, N - 1)]
for d in D:
if not (d <= 0 and d % N == 0):
print("NO")
break
else:
print("YES")
| N = int(eval(input()))
A = list(map(int, input().split()))
# 毎回1+2+...+N個の石が取り除かれる
Sum = sum(A)
if Sum % (N * (N + 1) // 2) != 0:
print("NO")
exit()
# 操作回数
K = Sum // (N * (N + 1) // 2)
Diff = [A[i] - A[(i - 1)] for i in range(N)]
# 変化量-1が(N-1)箇所、+(N-1)が一か所を、すべて-1した後に、一か所+1と置き換える
Diff = [d - K for d in Diff]
for d in Diff:
if d < 0:
if d % N != 0:
print("NO")
exit()
else:
K -= abs(d // N)
if K == 0:
print("YES")
else:
print("NO")
| false | 63.333333 | [
"-K = sum(A) / sum(range(1, N + 1))",
"-D = [A[i + 1] - A[i] - K for i in range(-1, N - 1)]",
"-for d in D:",
"- if not (d <= 0 and d % N == 0):",
"- print(\"NO\")",
"- break",
"+# 毎回1+2+...+N個の石が取り除かれる",
"+Sum = sum(A)",
"+if Sum % (N * (N + 1) // 2) != 0:",
"+ print(\"NO\")",... | false | 0.038202 | 0.04626 | 0.825811 | [
"s857903567",
"s079915990"
] |
u934868410 | p03775 | python | s210236977 | s041583898 | 68 | 42 | 3,316 | 3,060 | Accepted | Accepted | 38.24 | from collections import defaultdict
n = int(eval(input()))
fact = defaultdict(int)
fact[1] = 1
f = 2
k = n
while f * f <= min(k * k, n):
if k % f == 0:
fact[f] += 1
k //= f
else:
f += 1
if k > 1:
fact[k] += 1
def digits(n):
ret = 0
while n > 0:
ret += 1
n //= 10
return ret
def dfs(index, mul, fact):
if index >= len(fact):
return max(digits(mul), digits(n // mul))
k, v = fact[index]
ret = 10
for i in range(v + 1):
ret = min(ret, dfs(index + 1, mul * pow(k, i), fact))
return ret
print((dfs(0, 1, list(fact.items())))) | n = int(eval(input()))
ans = 10
i = 1
def dig(n):
ret = 0
while n > 0:
ret += 1
n //= 10
return ret
while i*i <= n:
if n % i == 0:
ans = min(ans, max(dig(i), dig(n//i)))
i += 1
print(ans) | 36 | 19 | 654 | 248 | from collections import defaultdict
n = int(eval(input()))
fact = defaultdict(int)
fact[1] = 1
f = 2
k = n
while f * f <= min(k * k, n):
if k % f == 0:
fact[f] += 1
k //= f
else:
f += 1
if k > 1:
fact[k] += 1
def digits(n):
ret = 0
while n > 0:
ret += 1
n //= 10
return ret
def dfs(index, mul, fact):
if index >= len(fact):
return max(digits(mul), digits(n // mul))
k, v = fact[index]
ret = 10
for i in range(v + 1):
ret = min(ret, dfs(index + 1, mul * pow(k, i), fact))
return ret
print((dfs(0, 1, list(fact.items()))))
| n = int(eval(input()))
ans = 10
i = 1
def dig(n):
ret = 0
while n > 0:
ret += 1
n //= 10
return ret
while i * i <= n:
if n % i == 0:
ans = min(ans, max(dig(i), dig(n // i)))
i += 1
print(ans)
| false | 47.222222 | [
"-from collections import defaultdict",
"-",
"-fact = defaultdict(int)",
"-fact[1] = 1",
"-f = 2",
"-k = n",
"-while f * f <= min(k * k, n):",
"- if k % f == 0:",
"- fact[f] += 1",
"- k //= f",
"- else:",
"- f += 1",
"-if k > 1:",
"- fact[k] += 1",
"+ans = 1... | false | 0.048879 | 0.045823 | 1.066698 | [
"s210236977",
"s041583898"
] |
u268554510 | p03194 | python | s737235201 | s297967971 | 73 | 47 | 3,060 | 3,064 | Accepted | Accepted | 35.62 | n,p = list(map(int,input().split()))
if n == 1:
print(p)
exit()
if n >=40:
print((1))
exit()
i =2
ans =1
while i**n <= p:
if p%(i**n)==0:
ans *= i
p =p//(i**n)
else:
i += 1
print(ans) | n,p = list(map(int,input().split()))
if n == 1:
print(p)
exit()
if n >=40 or p==1:
print((1))
exit()
i =2
ans =1
while i**n <= p:
if p%(i**n)==0:
ans *= i
p =p//(i**n)
elif i==2:
i+=1
else:
i+=2
print(ans) | 17 | 19 | 241 | 273 | n, p = list(map(int, input().split()))
if n == 1:
print(p)
exit()
if n >= 40:
print((1))
exit()
i = 2
ans = 1
while i**n <= p:
if p % (i**n) == 0:
ans *= i
p = p // (i**n)
else:
i += 1
print(ans)
| n, p = list(map(int, input().split()))
if n == 1:
print(p)
exit()
if n >= 40 or p == 1:
print((1))
exit()
i = 2
ans = 1
while i**n <= p:
if p % (i**n) == 0:
ans *= i
p = p // (i**n)
elif i == 2:
i += 1
else:
i += 2
print(ans)
| false | 10.526316 | [
"-if n >= 40:",
"+if n >= 40 or p == 1:",
"+ elif i == 2:",
"+ i += 1",
"- i += 1",
"+ i += 2"
] | false | 0.040948 | 0.040466 | 1.011902 | [
"s737235201",
"s297967971"
] |
u532966492 | p03796 | python | s704333941 | s515119634 | 38 | 29 | 2,940 | 2,940 | Accepted | Accepted | 23.68 | N=int(eval(input()))
power=1
for i in range(N):
power = (power*(i+1))%(10**9+7)
print(power) | def n_func(n,mod=10**9+7):
ans=1
for i in range(1,n+1):
ans=(ans*i)%mod
return ans
print((n_func(int(eval(input()))))) | 5 | 6 | 94 | 135 | N = int(eval(input()))
power = 1
for i in range(N):
power = (power * (i + 1)) % (10**9 + 7)
print(power)
| def n_func(n, mod=10**9 + 7):
ans = 1
for i in range(1, n + 1):
ans = (ans * i) % mod
return ans
print((n_func(int(eval(input())))))
| false | 16.666667 | [
"-N = int(eval(input()))",
"-power = 1",
"-for i in range(N):",
"- power = (power * (i + 1)) % (10**9 + 7)",
"-print(power)",
"+def n_func(n, mod=10**9 + 7):",
"+ ans = 1",
"+ for i in range(1, n + 1):",
"+ ans = (ans * i) % mod",
"+ return ans",
"+",
"+",
"+print((n_func(... | false | 0.042974 | 0.079078 | 0.543439 | [
"s704333941",
"s515119634"
] |
u375477204 | p02983 | python | s965788612 | s666854775 | 758 | 60 | 3,060 | 3,060 | Accepted | Accepted | 92.08 | L, R = list(map(int, input().split()))
mod = 2019
s = 2018
for i in range(L, min(R, L+2018)):
for j in range(i+1, min(R+1, L+2019)):
t = (i%mod)*(j%mod)%mod
if s > t:
s = t
print (s) | L, R = list(map(int, input().split()))
mod = 2019
s = 2018
for i in range(L,R):
for j in range(i+1, R+1):
t = (i%mod)*(j%mod)%mod
if s > t:
s = t
if t == 0:
break
else:
continue
break
print (s) | 9 | 14 | 216 | 268 | L, R = list(map(int, input().split()))
mod = 2019
s = 2018
for i in range(L, min(R, L + 2018)):
for j in range(i + 1, min(R + 1, L + 2019)):
t = (i % mod) * (j % mod) % mod
if s > t:
s = t
print(s)
| L, R = list(map(int, input().split()))
mod = 2019
s = 2018
for i in range(L, R):
for j in range(i + 1, R + 1):
t = (i % mod) * (j % mod) % mod
if s > t:
s = t
if t == 0:
break
else:
continue
break
print(s)
| false | 35.714286 | [
"-for i in range(L, min(R, L + 2018)):",
"- for j in range(i + 1, min(R + 1, L + 2019)):",
"+for i in range(L, R):",
"+ for j in range(i + 1, R + 1):",
"+ if t == 0:",
"+ break",
"+ else:",
"+ continue",
"+ break"
] | false | 0.232794 | 0.036529 | 6.372861 | [
"s965788612",
"s666854775"
] |
u735008991 | p03031 | python | s972725975 | s009386579 | 43 | 32 | 3,064 | 3,064 | Accepted | Accepted | 25.58 | N, M = list(map(int, input().split()))
S = []
for _ in range(M):
S.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
for m in range(M):
if p[m] != ([bin(bit)[2:].zfill(N)[s-1] for s in S[m]].count('1') % 2):
break
else:
ans += 1
print(ans)
| N, M = list(map(int, input().split()))
S = []
for _ in range(M):
S.append(list(map(int, input().split()))[1:])
P = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
for m in range(M):
if sum([bit & (1 << (s-1)) > 0 for s in S[m]]) % 2 != P[m]:
break
else:
ans += 1
print(ans)
| 13 | 13 | 350 | 338 | N, M = list(map(int, input().split()))
S = []
for _ in range(M):
S.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
for m in range(M):
if p[m] != ([bin(bit)[2:].zfill(N)[s - 1] for s in S[m]].count("1") % 2):
break
else:
ans += 1
print(ans)
| N, M = list(map(int, input().split()))
S = []
for _ in range(M):
S.append(list(map(int, input().split()))[1:])
P = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
for m in range(M):
if sum([bit & (1 << (s - 1)) > 0 for s in S[m]]) % 2 != P[m]:
break
else:
ans += 1
print(ans)
| false | 0 | [
"-p = list(map(int, input().split()))",
"+P = list(map(int, input().split()))",
"- if p[m] != ([bin(bit)[2:].zfill(N)[s - 1] for s in S[m]].count(\"1\") % 2):",
"+ if sum([bit & (1 << (s - 1)) > 0 for s in S[m]]) % 2 != P[m]:"
] | false | 0.036735 | 0.05026 | 0.730903 | [
"s972725975",
"s009386579"
] |
u072717685 | p02695 | python | s151659069 | s041134112 | 676 | 234 | 21,812 | 46,552 | Accepted | Accepted | 65.38 | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import combinations_with_replacement
def main():
n, m, q = list(map(int, input().split()))
qs = []
for _ in range(q):
abcd = tuple(map(int, input().split()))
qs.append(abcd)
A = tuple(combinations_with_replacement(list(range(1, m+1)), n))
r = 0
for Ae in A:
t0 = 0
for qe in qs:
if Ae[qe[1]-1] - Ae[qe[0]-1] == qe[2]:
t0 += qe[3]
r = max(r, t0)
print(r)
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import combinations_with_replacement
import numpy as np
def main():
n, m, q = list(map(int, input().split()))
A = np.array(list(combinations_with_replacement(list(range(1, m + 1)), n)))
numA = len(A)
score = np.zeros(numA, np.int32)
ma = list(map(int, read().split()))
for a, b, c, d in zip(ma, ma, ma, ma):
a -= 1
b -= 1
eachA_is_equalOrNot = A[:, b] - A[:, a] == c
score += d * eachA_is_equalOrNot
# print(score)
print((score.max()))
if __name__ == '__main__':
main() | 22 | 21 | 578 | 622 | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import combinations_with_replacement
def main():
n, m, q = list(map(int, input().split()))
qs = []
for _ in range(q):
abcd = tuple(map(int, input().split()))
qs.append(abcd)
A = tuple(combinations_with_replacement(list(range(1, m + 1)), n))
r = 0
for Ae in A:
t0 = 0
for qe in qs:
if Ae[qe[1] - 1] - Ae[qe[0] - 1] == qe[2]:
t0 += qe[3]
r = max(r, t0)
print(r)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import combinations_with_replacement
import numpy as np
def main():
n, m, q = list(map(int, input().split()))
A = np.array(list(combinations_with_replacement(list(range(1, m + 1)), n)))
numA = len(A)
score = np.zeros(numA, np.int32)
ma = list(map(int, read().split()))
for a, b, c, d in zip(ma, ma, ma, ma):
a -= 1
b -= 1
eachA_is_equalOrNot = A[:, b] - A[:, a] == c
score += d * eachA_is_equalOrNot
# print(score)
print((score.max()))
if __name__ == "__main__":
main()
| false | 4.545455 | [
"+import numpy as np",
"- qs = []",
"- for _ in range(q):",
"- abcd = tuple(map(int, input().split()))",
"- qs.append(abcd)",
"- A = tuple(combinations_with_replacement(list(range(1, m + 1)), n))",
"- r = 0",
"- for Ae in A:",
"- t0 = 0",
"- for qe in qs:... | false | 0.054085 | 0.228442 | 0.236754 | [
"s151659069",
"s041134112"
] |
u865108308 | p02694 | python | s130779014 | s799125575 | 24 | 22 | 9,032 | 9,080 | Accepted | Accepted | 8.33 | x = int(eval(input()))
money = 100
year = 0
while money < x:
money += int(money / 100)
year += 1
print(year)
| x = int(eval(input()))
money = 100
year = 0
while money < x:
money += money // 100
year += 1
print(year)
| 9 | 9 | 119 | 115 | x = int(eval(input()))
money = 100
year = 0
while money < x:
money += int(money / 100)
year += 1
print(year)
| x = int(eval(input()))
money = 100
year = 0
while money < x:
money += money // 100
year += 1
print(year)
| false | 0 | [
"- money += int(money / 100)",
"+ money += money // 100"
] | false | 0.048965 | 0.056577 | 0.865456 | [
"s130779014",
"s799125575"
] |
u644907318 | p03363 | python | s785521448 | s429346361 | 326 | 154 | 112,900 | 136,908 | Accepted | Accepted | 52.76 | N = int(eval(input()))
A = list(map(int,input().split()))
B = [0 for _ in range(N+1)]
for i in range(N):
B[i+1] = B[i]+A[i]
C = {}
for i in range(N+1):
b = B[i]
if b not in C:
C[b] = 0
C[b] += 1
cnt = 0
for b in C:
cnt += (C[b]*(C[b]-1))//2
print(cnt) | N = int(eval(input()))
A = list(map(int,input().split()))
B = [0 for _ in range(N+1)]
for i in range(1,N+1):
B[i] = B[i-1]+A[i-1]
C = {}
for i in range(N+1):
b = B[i]
if b not in C:
C[b]=0
C[b] += 1
cnt = 0
for b in C:
n = C[b]
if n>=2:
cnt += (n*(n-1))//2
print(cnt) | 15 | 17 | 287 | 317 | N = int(eval(input()))
A = list(map(int, input().split()))
B = [0 for _ in range(N + 1)]
for i in range(N):
B[i + 1] = B[i] + A[i]
C = {}
for i in range(N + 1):
b = B[i]
if b not in C:
C[b] = 0
C[b] += 1
cnt = 0
for b in C:
cnt += (C[b] * (C[b] - 1)) // 2
print(cnt)
| N = int(eval(input()))
A = list(map(int, input().split()))
B = [0 for _ in range(N + 1)]
for i in range(1, N + 1):
B[i] = B[i - 1] + A[i - 1]
C = {}
for i in range(N + 1):
b = B[i]
if b not in C:
C[b] = 0
C[b] += 1
cnt = 0
for b in C:
n = C[b]
if n >= 2:
cnt += (n * (n - 1)) // 2
print(cnt)
| false | 11.764706 | [
"-for i in range(N):",
"- B[i + 1] = B[i] + A[i]",
"+for i in range(1, N + 1):",
"+ B[i] = B[i - 1] + A[i - 1]",
"- cnt += (C[b] * (C[b] - 1)) // 2",
"+ n = C[b]",
"+ if n >= 2:",
"+ cnt += (n * (n - 1)) // 2"
] | false | 0.040822 | 0.131406 | 0.310653 | [
"s785521448",
"s429346361"
] |
u777283665 | p02916 | python | s021194591 | s093760378 | 173 | 17 | 38,256 | 3,064 | Accepted | Accepted | 90.17 | n = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
for a in A:
ans += B[a-1]
for i in range(n-1):
if A[i] + 1 == A[i+1]:
ans += C[A[i]-1]
print(ans) | n = int(eval(input()))
a = [i-1 for i in map(int, input().split())]
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
prev_ind = 50
for i in a:
ans += b[i]
if prev_ind + 1 == i:
ans += c[prev_ind]
prev_ind = i
print(ans) | 15 | 14 | 264 | 279 | n = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
for a in A:
ans += B[a - 1]
for i in range(n - 1):
if A[i] + 1 == A[i + 1]:
ans += C[A[i] - 1]
print(ans)
| n = int(eval(input()))
a = [i - 1 for i in map(int, input().split())]
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
prev_ind = 50
for i in a:
ans += b[i]
if prev_ind + 1 == i:
ans += c[prev_ind]
prev_ind = i
print(ans)
| false | 6.666667 | [
"-A = list(map(int, input().split()))",
"-B = list(map(int, input().split()))",
"-C = list(map(int, input().split()))",
"+a = [i - 1 for i in map(int, input().split())]",
"+b = list(map(int, input().split()))",
"+c = list(map(int, input().split()))",
"-for a in A:",
"- ans += B[a - 1]",
"-for i i... | false | 0.082891 | 0.036328 | 2.281748 | [
"s021194591",
"s093760378"
] |
u037430802 | p02888 | python | s052877898 | s526279835 | 1,336 | 1,156 | 3,188 | 3,188 | Accepted | Accepted | 13.47 | from bisect import bisect_left
from bisect import bisect_right
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
"""
短いほうから2本固定して条件に合うものをさがす(長いほうから2本固定でもOK)
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""
ans = 0
for i in range(N-2):
a = L[i]
for j in range(i+1, N-1):
b = L[j]
# そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや!
k = bisect_left(L, a+b)
ans += k - j - 1
"""
ans = 0
for i in range(N):
for j in range(i+1, N):
l = L[j] - L[i]
r = L[j] + L[i]
# a < b < c(場合によっては等号を含む)で考えたときの、b - a < cを満たすもの
il = bisect_right(L, l, lo=j)
# a < b < c(場合によっては等号を含む)で考えたときの、c < a + bを満たすもの
ir = bisect_left(L, r, lo=j)
# b - a < cを満たすものがない場合、飛ばす
if il == N-1:
break
ans += ir - il - 1
"""
print(ans)
| from bisect import bisect_left
from bisect import bisect_right
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
"""
短いほうから2本固定して条件に合うものをさがす(長いほうから2本固定でもOK)
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""
ans = 0
for i in range(N-2):
a = L[i]
for j in range(i+1, N-1):
#b = L[j]
# そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや!
k = bisect_left(L, a+L[j])
ans += k - j - 1
"""
ans = 0
for i in range(N):
for j in range(i+1, N):
l = L[j] - L[i]
r = L[j] + L[i]
# a < b < c(場合によっては等号を含む)で考えたときの、b - a < cを満たすもの
il = bisect_right(L, l, lo=j)
# a < b < c(場合によっては等号を含む)で考えたときの、c < a + bを満たすもの
ir = bisect_left(L, r, lo=j)
# b - a < cを満たすものがない場合、飛ばす
if il == N-1:
break
ans += ir - il - 1
"""
print(ans)
| 43 | 43 | 909 | 913 | from bisect import bisect_left
from bisect import bisect_right
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
"""
短いほうから2本固定して条件に合うものをさがす(長いほうから2本固定でもOK)
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""
ans = 0
for i in range(N - 2):
a = L[i]
for j in range(i + 1, N - 1):
b = L[j]
# そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや!
k = bisect_left(L, a + b)
ans += k - j - 1
"""
ans = 0
for i in range(N):
for j in range(i+1, N):
l = L[j] - L[i]
r = L[j] + L[i]
# a < b < c(場合によっては等号を含む)で考えたときの、b - a < cを満たすもの
il = bisect_right(L, l, lo=j)
# a < b < c(場合によっては等号を含む)で考えたときの、c < a + bを満たすもの
ir = bisect_left(L, r, lo=j)
# b - a < cを満たすものがない場合、飛ばす
if il == N-1:
break
ans += ir - il - 1
"""
print(ans)
| from bisect import bisect_left
from bisect import bisect_right
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
"""
短いほうから2本固定して条件に合うものをさがす(長いほうから2本固定でもOK)
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""
ans = 0
for i in range(N - 2):
a = L[i]
for j in range(i + 1, N - 1):
# b = L[j]
# そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや!
k = bisect_left(L, a + L[j])
ans += k - j - 1
"""
ans = 0
for i in range(N):
for j in range(i+1, N):
l = L[j] - L[i]
r = L[j] + L[i]
# a < b < c(場合によっては等号を含む)で考えたときの、b - a < cを満たすもの
il = bisect_right(L, l, lo=j)
# a < b < c(場合によっては等号を含む)で考えたときの、c < a + bを満たすもの
ir = bisect_left(L, r, lo=j)
# b - a < cを満たすものがない場合、飛ばす
if il == N-1:
break
ans += ir - il - 1
"""
print(ans)
| false | 0 | [
"- b = L[j]",
"+ # b = L[j]",
"- k = bisect_left(L, a + b)",
"+ k = bisect_left(L, a + L[j])"
] | false | 0.046377 | 0.112441 | 0.412452 | [
"s052877898",
"s526279835"
] |
u991567869 | p02696 | python | s265531147 | s464418205 | 24 | 21 | 9,108 | 9,052 | Accepted | Accepted | 12.5 | a, b, n = list(map(int, input().split()))
x = (n//b)*b - 1
if x == -1:
x = n
ans = a*x//b - a*(x//b)
print(ans) | a, b, n = list(map(int, input().split()))
if n <= b - 1:
x = n
else:
x = n - (n%b + 1)
ans = a*x//b - a*(x//b)
print(ans) | 8 | 9 | 118 | 133 | a, b, n = list(map(int, input().split()))
x = (n // b) * b - 1
if x == -1:
x = n
ans = a * x // b - a * (x // b)
print(ans)
| a, b, n = list(map(int, input().split()))
if n <= b - 1:
x = n
else:
x = n - (n % b + 1)
ans = a * x // b - a * (x // b)
print(ans)
| false | 11.111111 | [
"-x = (n // b) * b - 1",
"-if x == -1:",
"+if n <= b - 1:",
"+else:",
"+ x = n - (n % b + 1)"
] | false | 0.077046 | 0.038753 | 1.988142 | [
"s265531147",
"s464418205"
] |
u222668979 | p02577 | python | s837682460 | s432959533 | 204 | 104 | 9,212 | 82,704 | Accepted | Accepted | 49.02 | n=int(eval(input()))
print(('No' if n % 3 else 'Yes'))
| n = list(map(int, list(eval(input()))))
ans = 0
for i in n:
ans = (ans + i) % 9
print(('Yes' if ans % 9 == 0 else 'No'))
| 2 | 6 | 48 | 117 | n = int(eval(input()))
print(("No" if n % 3 else "Yes"))
| n = list(map(int, list(eval(input()))))
ans = 0
for i in n:
ans = (ans + i) % 9
print(("Yes" if ans % 9 == 0 else "No"))
| false | 66.666667 | [
"-n = int(eval(input()))",
"-print((\"No\" if n % 3 else \"Yes\"))",
"+n = list(map(int, list(eval(input()))))",
"+ans = 0",
"+for i in n:",
"+ ans = (ans + i) % 9",
"+print((\"Yes\" if ans % 9 == 0 else \"No\"))"
] | false | 0.046534 | 0.068191 | 0.682407 | [
"s837682460",
"s432959533"
] |
u879870653 | p03786 | python | s802702979 | s896521255 | 442 | 143 | 23,220 | 14,320 | Accepted | Accepted | 67.65 | import numpy as np
N = int(eval(input()))
A = list(map(int,input().split()))
A = sorted(A)
C = np.cumsum(A)
ans = 0
cnt = 0
for i in range(N-1) :
if C[i]*2 >= A[i+1] :
cnt += 1
else :
cnt = 0
ans = cnt + 1
print(ans)
| N = int(eval(input()))
A = list(map(int,input().split()))
A = sorted(A)
ans = 1
cum = [0]*N
for i, a in enumerate(A) :
if i == 0 :
cum[i] = a
else :
cum[i] = cum[i-1] + a
for i in range(N-2,-1,-1) :
if cum[i]*2 >= A[i+1] :
ans += 1
else :
break
print(ans)
| 21 | 21 | 265 | 327 | import numpy as np
N = int(eval(input()))
A = list(map(int, input().split()))
A = sorted(A)
C = np.cumsum(A)
ans = 0
cnt = 0
for i in range(N - 1):
if C[i] * 2 >= A[i + 1]:
cnt += 1
else:
cnt = 0
ans = cnt + 1
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
A = sorted(A)
ans = 1
cum = [0] * N
for i, a in enumerate(A):
if i == 0:
cum[i] = a
else:
cum[i] = cum[i - 1] + a
for i in range(N - 2, -1, -1):
if cum[i] * 2 >= A[i + 1]:
ans += 1
else:
break
print(ans)
| false | 0 | [
"-import numpy as np",
"-",
"-C = np.cumsum(A)",
"-ans = 0",
"-cnt = 0",
"-for i in range(N - 1):",
"- if C[i] * 2 >= A[i + 1]:",
"- cnt += 1",
"+ans = 1",
"+cum = [0] * N",
"+for i, a in enumerate(A):",
"+ if i == 0:",
"+ cum[i] = a",
"- cnt = 0",
"-ans = cnt ... | false | 0.690353 | 0.081976 | 8.421363 | [
"s802702979",
"s896521255"
] |
u780698286 | p02688 | python | s219059378 | s021802054 | 30 | 27 | 9,356 | 9,056 | Accepted | Accepted | 10 | from collections import Counter
n, k = list(map(int, input().split()))
b = []
for j in range(k):
d = int(eval(input()))
a = list(map(int, input().split()))
for f in a:
b.append(f)
print((n - len(Counter(b)))) | n, k = list(map(int, input().split()))
l = [0] * n
for i in range(k):
d = int(eval(input()))
x = list(map(int, input().split()))
for j in range(d):
l[x[j]-1] += 1
print((l.count(0))) | 11 | 8 | 220 | 195 | from collections import Counter
n, k = list(map(int, input().split()))
b = []
for j in range(k):
d = int(eval(input()))
a = list(map(int, input().split()))
for f in a:
b.append(f)
print((n - len(Counter(b))))
| n, k = list(map(int, input().split()))
l = [0] * n
for i in range(k):
d = int(eval(input()))
x = list(map(int, input().split()))
for j in range(d):
l[x[j] - 1] += 1
print((l.count(0)))
| false | 27.272727 | [
"-from collections import Counter",
"-",
"-b = []",
"-for j in range(k):",
"+l = [0] * n",
"+for i in range(k):",
"- a = list(map(int, input().split()))",
"- for f in a:",
"- b.append(f)",
"-print((n - len(Counter(b))))",
"+ x = list(map(int, input().split()))",
"+ for j in ... | false | 0.044608 | 0.042863 | 1.040729 | [
"s219059378",
"s021802054"
] |
u729133443 | p02623 | python | s138321137 | s377968651 | 340 | 183 | 77,152 | 124,740 | Accepted | Accepted | 46.18 | from numpy import*
n,m,k,*a=int_(open(0).read().split())
c=cumsum
b=c([0]+a[:n])
print((max(list(range(len(b:=b[b<=k])))+searchsorted(c(a[n:]),k-b+1)))) | n,m,k,*a=list(map(int,open(0).read().split()))
s=sum(a[:n])
x=i=j=n
a+=k,
while~i:
while s+a[j]<=k:s+=a[j];j+=1
if s<=k:x=max(x,i+j)
i-=1;s-=a[i]
print((x-n)) | 5 | 9 | 148 | 161 | from numpy import *
n, m, k, *a = int_(open(0).read().split())
c = cumsum
b = c([0] + a[:n])
print((max(list(range(len(b := b[b <= k]))) + searchsorted(c(a[n:]), k - b + 1))))
| n, m, k, *a = list(map(int, open(0).read().split()))
s = sum(a[:n])
x = i = j = n
a += (k,)
while ~i:
while s + a[j] <= k:
s += a[j]
j += 1
if s <= k:
x = max(x, i + j)
i -= 1
s -= a[i]
print((x - n))
| false | 44.444444 | [
"-from numpy import *",
"-",
"-n, m, k, *a = int_(open(0).read().split())",
"-c = cumsum",
"-b = c([0] + a[:n])",
"-print((max(list(range(len(b := b[b <= k]))) + searchsorted(c(a[n:]), k - b + 1))))",
"+n, m, k, *a = list(map(int, open(0).read().split()))",
"+s = sum(a[:n])",
"+x = i = j = n",
"+a... | false | 0.274544 | 0.056985 | 4.817801 | [
"s138321137",
"s377968651"
] |
u620084012 | p03131 | python | s890238120 | s969252249 | 169 | 17 | 38,256 | 2,940 | Accepted | Accepted | 89.94 | import sys
def main():
def input():
return sys.stdin.readline()[:-1]
K, A, B = list(map(int,input().split()))
if A+2 >= B:
print((K+1))
else:
t = (K-A+1)//2
if (K-A+1)%2 == 0:
print((max(K+1, A+(B-A)*t)))
else:
print((max(K+1, 1+A+(B-A)*t)))
if __name__ == '__main__':
main()
| K, A, B = list(map(int,input().split()))
if K >= A+1 and B >= A+2:
t = K-(A-1)
print((B+(B-A)*(t//2-1)+t%2))
else:
print((K+1))
| 16 | 6 | 364 | 135 | import sys
def main():
def input():
return sys.stdin.readline()[:-1]
K, A, B = list(map(int, input().split()))
if A + 2 >= B:
print((K + 1))
else:
t = (K - A + 1) // 2
if (K - A + 1) % 2 == 0:
print((max(K + 1, A + (B - A) * t)))
else:
print((max(K + 1, 1 + A + (B - A) * t)))
if __name__ == "__main__":
main()
| K, A, B = list(map(int, input().split()))
if K >= A + 1 and B >= A + 2:
t = K - (A - 1)
print((B + (B - A) * (t // 2 - 1) + t % 2))
else:
print((K + 1))
| false | 62.5 | [
"-import sys",
"-",
"-",
"-def main():",
"- def input():",
"- return sys.stdin.readline()[:-1]",
"-",
"- K, A, B = list(map(int, input().split()))",
"- if A + 2 >= B:",
"- print((K + 1))",
"- else:",
"- t = (K - A + 1) // 2",
"- if (K - A + 1) % 2 == 0... | false | 0.04301 | 0.038883 | 1.106127 | [
"s890238120",
"s969252249"
] |
u219197917 | p02733 | python | s405093292 | s417212003 | 1,487 | 569 | 3,316 | 3,316 | Accepted | Accepted | 61.74 | def main():
h, w, k = list(map(int, input().split()))
s = [[int(i) for i in list(eval(input()))] for _ in range(h)]
cnt = [bin(i).count("1") for i in range(2**(h - 1))]
c = 0
for ci in [sum(i) for i in zip(*s)]:
if ci > k:
cnt[0] = 100000
break
c += ci
if c > k:
cnt[0] += 1
c = ci
for i in range(1, 2**(h - 1)):
div = [j + 1 for j in range(h) if i & 2**j]
ss = []
l = 0
for d in div:
ss.append(s[l:d])
l = d
ss.append(s[l:])
c = [0] * len(ss)
t = [[sum(i) for i in zip(*si)] for si in ss]
for j in range(w):
if max(ti[j] for ti in t) > k:
cnt[i] = 100000
break
for tt, ti in enumerate(t):
c[tt] += ti[j]
if max(c) > k:
cnt[i] += 1
c = [ti[j] for ti in t]
print((min(cnt)))
if __name__ == '__main__':
main() | def main():
h, w, k = list(map(int, input().split()))
s = [[int(i) for i in list(eval(input()))] for _ in range(h)]
cnt = [bin(i).count("1") for i in range(2**(h - 1))]
c = 0
for ci in [sum(i) for i in zip(*s)]:
if ci > k:
cnt[0] = 100000
break
c += ci
if c > k:
cnt[0] += 1
c = ci
minc = cnt[0]
for i in range(1, 2**(h - 1)):
div = [j + 1 for j in range(h) if i & 2**j]
ss = []
l = 0
for d in div:
ss.append(s[l:d])
l = d
ss.append(s[l:])
c = [0] * len(ss)
t = [[sum(i) for i in zip(*si)] for si in ss]
for j in range(w):
if cnt[i] >= minc:
break
if max(ti[j] for ti in t) > k:
cnt[i] = 100000
break
for tt, ti in enumerate(t):
c[tt] += ti[j]
if max(c) > k:
cnt[i] += 1
c = [ti[j] for ti in t]
print((min(cnt)))
if __name__ == '__main__':
main() | 36 | 39 | 1,037 | 1,111 | def main():
h, w, k = list(map(int, input().split()))
s = [[int(i) for i in list(eval(input()))] for _ in range(h)]
cnt = [bin(i).count("1") for i in range(2 ** (h - 1))]
c = 0
for ci in [sum(i) for i in zip(*s)]:
if ci > k:
cnt[0] = 100000
break
c += ci
if c > k:
cnt[0] += 1
c = ci
for i in range(1, 2 ** (h - 1)):
div = [j + 1 for j in range(h) if i & 2**j]
ss = []
l = 0
for d in div:
ss.append(s[l:d])
l = d
ss.append(s[l:])
c = [0] * len(ss)
t = [[sum(i) for i in zip(*si)] for si in ss]
for j in range(w):
if max(ti[j] for ti in t) > k:
cnt[i] = 100000
break
for tt, ti in enumerate(t):
c[tt] += ti[j]
if max(c) > k:
cnt[i] += 1
c = [ti[j] for ti in t]
print((min(cnt)))
if __name__ == "__main__":
main()
| def main():
h, w, k = list(map(int, input().split()))
s = [[int(i) for i in list(eval(input()))] for _ in range(h)]
cnt = [bin(i).count("1") for i in range(2 ** (h - 1))]
c = 0
for ci in [sum(i) for i in zip(*s)]:
if ci > k:
cnt[0] = 100000
break
c += ci
if c > k:
cnt[0] += 1
c = ci
minc = cnt[0]
for i in range(1, 2 ** (h - 1)):
div = [j + 1 for j in range(h) if i & 2**j]
ss = []
l = 0
for d in div:
ss.append(s[l:d])
l = d
ss.append(s[l:])
c = [0] * len(ss)
t = [[sum(i) for i in zip(*si)] for si in ss]
for j in range(w):
if cnt[i] >= minc:
break
if max(ti[j] for ti in t) > k:
cnt[i] = 100000
break
for tt, ti in enumerate(t):
c[tt] += ti[j]
if max(c) > k:
cnt[i] += 1
c = [ti[j] for ti in t]
print((min(cnt)))
if __name__ == "__main__":
main()
| false | 7.692308 | [
"+ minc = cnt[0]",
"+ if cnt[i] >= minc:",
"+ break"
] | false | 0.007123 | 0.034989 | 0.203581 | [
"s405093292",
"s417212003"
] |
u423966555 | p02573 | python | s178789599 | s575091330 | 1,022 | 737 | 72,632 | 72,708 | Accepted | Accepted | 27.89 | N, M = list(map(int, input().split()))
friends = [set() for _ in range(N)]
for _ in range(M):
a, b = [int(x)-1 for x in input().split()]
friends[a].add(b)
friends[b].add(a)
# print(friends)
visited = [0]*N #グループを作って合ったら
ans = 0
for i in range(N):
if visited[i]:
continue
tmp = list(friends[i])
ans_tmp = 1
visited[i] = 1
while tmp:
t = tmp.pop()
if not visited[t]:
visited[t] = 1
ans_tmp += 1
for j in friends[t]:
tmp.append(j)
ans = max(ans, ans_tmp)
print(ans)
| def main():
N, M = list(map(int, input().split()))
friends = [set() for _ in range(N)]
for _ in range(M):
a, b = [int(x)-1 for x in input().split()]
friends[a].add(b)
friends[b].add(a)
# print(friends)
visited = [0]*N #グループを作って合ったら
ans = 0
for i in range(N):
if visited[i]:
continue
tmp = list(friends[i])
ans_tmp = 1
visited[i] = 1
while tmp:
t = tmp.pop()
if not visited[t]:
visited[t] = 1
ans_tmp += 1
for j in friends[t]:
tmp.append(j)
ans = max(ans, ans_tmp)
print(ans)
if __name__ == '__main__':
main() | 27 | 31 | 603 | 753 | N, M = list(map(int, input().split()))
friends = [set() for _ in range(N)]
for _ in range(M):
a, b = [int(x) - 1 for x in input().split()]
friends[a].add(b)
friends[b].add(a)
# print(friends)
visited = [0] * N # グループを作って合ったら
ans = 0
for i in range(N):
if visited[i]:
continue
tmp = list(friends[i])
ans_tmp = 1
visited[i] = 1
while tmp:
t = tmp.pop()
if not visited[t]:
visited[t] = 1
ans_tmp += 1
for j in friends[t]:
tmp.append(j)
ans = max(ans, ans_tmp)
print(ans)
| def main():
N, M = list(map(int, input().split()))
friends = [set() for _ in range(N)]
for _ in range(M):
a, b = [int(x) - 1 for x in input().split()]
friends[a].add(b)
friends[b].add(a)
# print(friends)
visited = [0] * N # グループを作って合ったら
ans = 0
for i in range(N):
if visited[i]:
continue
tmp = list(friends[i])
ans_tmp = 1
visited[i] = 1
while tmp:
t = tmp.pop()
if not visited[t]:
visited[t] = 1
ans_tmp += 1
for j in friends[t]:
tmp.append(j)
ans = max(ans, ans_tmp)
print(ans)
if __name__ == "__main__":
main()
| false | 12.903226 | [
"-N, M = list(map(int, input().split()))",
"-friends = [set() for _ in range(N)]",
"-for _ in range(M):",
"- a, b = [int(x) - 1 for x in input().split()]",
"- friends[a].add(b)",
"- friends[b].add(a)",
"-# print(friends)",
"-visited = [0] * N # グループを作って合ったら",
"-ans = 0",
"-for i in range... | false | 0.035707 | 0.036644 | 0.974429 | [
"s178789599",
"s575091330"
] |
u499381410 | p03703 | python | s019976191 | s009678091 | 427 | 305 | 82,888 | 152,788 | Accepted | Accepted | 28.57 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 1 << 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
class BIT:
def __init__(self, size):
self.bit = [0] * size
self.size = size
self.total = 0
def add(self, i, w):
x = i + 1
while x <= self.size:
self.bit[x - 1] += w
x += x & -x
return
def sum(self, i):
res = 0
x = i + 1
while x:
res += self.bit[x - 1]
x -= x & -x
return res
n, k = LI()
A = IR(n)
A = [a - k for a in A]
A = [0] + list(accumulate(A))
D = {}
for i, v in enumerate(sorted(set(A))):
D[v] = i
for i in range(n + 1):
A[i] = D[A[i]]
bit = BIT(max(A) + 1)
c = 0
for a in A:
c += bit.sum(a)
bit.add(a, 1)
print(c)
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
class BIT:
def __init__(self, size):
self.bit = [0] * size
self.size = size
self.total = 0
def add(self, i, w):
x = i + 1
self.total += w
while x <= self.size:
self.bit[x - 1] += w
x += x & -x
return
def sum(self, i):
res = 0
x = i + 1
while x:
res += self.bit[x - 1]
x -= x & -x
return res
n, k = LI()
A = IR(n)
A = [0] + list(accumulate([a - k for a in A]))
D = {v:i for i,v in enumerate(sorted(A))}
bit = BIT(len(A))
c = 0
for a in A:
c += bit.sum(D[a])
bit.add(D[a], 1)
print(c)
| 70 | 68 | 1,782 | 1,761 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 1 << 100
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
class BIT:
def __init__(self, size):
self.bit = [0] * size
self.size = size
self.total = 0
def add(self, i, w):
x = i + 1
while x <= self.size:
self.bit[x - 1] += w
x += x & -x
return
def sum(self, i):
res = 0
x = i + 1
while x:
res += self.bit[x - 1]
x -= x & -x
return res
n, k = LI()
A = IR(n)
A = [a - k for a in A]
A = [0] + list(accumulate(A))
D = {}
for i, v in enumerate(sorted(set(A))):
D[v] = i
for i in range(n + 1):
A[i] = D[A[i]]
bit = BIT(max(A) + 1)
c = 0
for a in A:
c += bit.sum(a)
bit.add(a, 1)
print(c)
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10**13
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 10**9 + 7
class BIT:
def __init__(self, size):
self.bit = [0] * size
self.size = size
self.total = 0
def add(self, i, w):
x = i + 1
self.total += w
while x <= self.size:
self.bit[x - 1] += w
x += x & -x
return
def sum(self, i):
res = 0
x = i + 1
while x:
res += self.bit[x - 1]
x -= x & -x
return res
n, k = LI()
A = IR(n)
A = [0] + list(accumulate([a - k for a in A]))
D = {v: i for i, v in enumerate(sorted(A))}
bit = BIT(len(A))
c = 0
for a in A:
c += bit.sum(D[a])
bit.add(D[a], 1)
print(c)
| false | 2.857143 | [
"-from bisect import bisect_right, bisect_left",
"+import math",
"+import bisect",
"-from math import factorial, ceil, floor, gamma, log",
"+from math import factorial, ceil, floor, cos, radians, pi, sin",
"+from operator import mul",
"-INF = 1 << 100",
"+INF = 10**13",
"-mod = 1000000007",
"+mod ... | false | 0.050582 | 0.05003 | 1.011028 | [
"s019976191",
"s009678091"
] |
u350093546 | p02580 | python | s412569293 | s276697029 | 657 | 601 | 176,756 | 176,764 | Accepted | Accepted | 8.52 | h,w,m=list(map(int,input().split()))
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()
for i in range(m):
a,b=list(map(int,input().split()))
hlist[a]+=1
wlist[b]+=1
cnt.add((a,b))
hcnt,wcnt=max(hlist),max(wlist)
hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]
for i in hhh:
for j in www:
if not (i,j) in cnt:
print((hcnt+wcnt))
exit()
print((hcnt+wcnt-1))
| h,w,m=list(map(int,input().split()))
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()
for i in range(m):
a,b=list(map(int,input().split()))
hlist[a]+=1
wlist[b]+=1
cnt.add((a,b))
hcnt,wcnt=max(hlist),max(wlist)
hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]
for i in hhh:
for j in www:
if (i,j) not in cnt:
print((hcnt+wcnt))
exit()
print((hcnt+wcnt-1)) | 28 | 28 | 441 | 440 | h, w, m = list(map(int, input().split()))
hlist = [0] * (h + 1)
wlist = [0] * (w + 1)
cnt = set()
for i in range(m):
a, b = list(map(int, input().split()))
hlist[a] += 1
wlist[b] += 1
cnt.add((a, b))
hcnt, wcnt = max(hlist), max(wlist)
hhh = [i for i, v in enumerate(hlist) if v == hcnt]
www = [i for i, v in enumerate(wlist) if v == wcnt]
for i in hhh:
for j in www:
if not (i, j) in cnt:
print((hcnt + wcnt))
exit()
print((hcnt + wcnt - 1))
| h, w, m = list(map(int, input().split()))
hlist = [0] * (h + 1)
wlist = [0] * (w + 1)
cnt = set()
for i in range(m):
a, b = list(map(int, input().split()))
hlist[a] += 1
wlist[b] += 1
cnt.add((a, b))
hcnt, wcnt = max(hlist), max(wlist)
hhh = [i for i, v in enumerate(hlist) if v == hcnt]
www = [i for i, v in enumerate(wlist) if v == wcnt]
for i in hhh:
for j in www:
if (i, j) not in cnt:
print((hcnt + wcnt))
exit()
print((hcnt + wcnt - 1))
| false | 0 | [
"- if not (i, j) in cnt:",
"+ if (i, j) not in cnt:"
] | false | 0.083687 | 0.037141 | 2.253203 | [
"s412569293",
"s276697029"
] |
u707124227 | p03253 | python | s883897626 | s896509789 | 123 | 113 | 20,896 | 110,724 | Accepted | Accepted | 8.13 | n,m=list(map(int,input().split()))
mod=pow(10,9)+7
if m==1:
print((1))
exit()
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
# コンビネーション、さらに高速。あらかじめO(N)の計算をすることでのちの計算が早くなる
def cmb(n,r,mod):
if (r<0 or r>n):
return 0
r=min(r,n-r)
return g1[n]*g2[r]*g2[n-r]%mod
g1=[1,1]
g2=[1,1]
inverse=[0,1]
for i in range(2,n+30+1):
g1.append((g1[-1]*i)%mod)
inverse.append((-inverse[mod%i]*(mod//i))%mod)
g2.append((g2[-1]*inverse[-1])%mod)
l=factorization(m)
ans=1
for li in l:
b=li[1]
ans*=cmb(b+n-1,n-1,mod)
ans%=mod
print(ans) | n,m=list(map(int,input().split()))
mod=10**9+7
# コンビネーション、さらに高速。あらかじめO(N)の計算をすることでのちの計算が早くなる
def cmb(n,r,mod):
if (r<0 or r>n):
return 0
r=min(r,n-r)
return g1[n]*g2[r]*g2[n-r]%mod
g1=[1,1] # g1[i]=i! % mod :階乗
g2=[1,1] # g2[i]=(i!)^(-1) % mod :階乗の逆元
inverse=[0,1]
for i in range(2,min(2*10**5,n+m)+1):
g1.append((g1[-1]*i)%mod)
inverse.append((-inverse[mod%i]*(mod//i))%mod)
g2.append((g2[-1]*inverse[-1])%mod)
#heap
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
#factorization(24)
## [[2, 3], [3, 1]]
## 24 = 2^3 * 3^1
if m==1:
print((1))
exit()
ary=factorization(m)
ans=1
for x,y in ary:
ans*=cmb(n-1+y,y,mod)
ans%=mod
print(ans) | 42 | 48 | 822 | 948 | n, m = list(map(int, input().split()))
mod = pow(10, 9) + 7
if m == 1:
print((1))
exit()
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
# コンビネーション、さらに高速。あらかじめO(N)の計算をすることでのちの計算が早くなる
def cmb(n, r, mod):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 30 + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
l = factorization(m)
ans = 1
for li in l:
b = li[1]
ans *= cmb(b + n - 1, n - 1, mod)
ans %= mod
print(ans)
| n, m = list(map(int, input().split()))
mod = 10**9 + 7
# コンビネーション、さらに高速。あらかじめO(N)の計算をすることでのちの計算が早くなる
def cmb(n, r, mod):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
g1 = [1, 1] # g1[i]=i! % mod :階乗
g2 = [1, 1] # g2[i]=(i!)^(-1) % mod :階乗の逆元
inverse = [0, 1]
for i in range(2, min(2 * 10**5, n + m) + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
# heap
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
# factorization(24)
## [[2, 3], [3, 1]]
## 24 = 2^3 * 3^1
if m == 1:
print((1))
exit()
ary = factorization(m)
ans = 1
for x, y in ary:
ans *= cmb(n - 1 + y, y, mod)
ans %= mod
print(ans)
| false | 12.5 | [
"-mod = pow(10, 9) + 7",
"-if m == 1:",
"- print((1))",
"- exit()",
"+mod = 10**9 + 7",
"+# コンビネーション、さらに高速。あらかじめO(N)の計算をすることでのちの計算が早くなる",
"+def cmb(n, r, mod):",
"+ if r < 0 or r > n:",
"+ return 0",
"+ r = min(r, n - r)",
"+ return g1[n] * g2[r] * g2[n - r] % mod",
"+g1 ... | false | 0.094188 | 0.148015 | 0.636342 | [
"s883897626",
"s896509789"
] |
u561231954 | p02813 | python | s931184458 | s065784422 | 35 | 24 | 8,052 | 3,188 | Accepted | Accepted | 31.43 | import itertools
n=int(eval(input()))
p=tuple([int(i) for i in input().split()])
q=tuple([int(i) for i in input().split()])
x=list(itertools.permutations(list(range(1,n+1))))
nc=len(x)
for i in range(nc):
if x[i]==p:
pn=i
for j in range(nc):
if x[j]==q:
qn=j
print((abs(pn-qn))) | def main():
from itertools import permutations
import sys
input=sys.stdin.readline
n=int(eval(input()))
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
cnt=1
for i in permutations(list(range(1,n+1))):
if i==p:
pi=cnt
if i==q:
qi=cnt
cnt+=1
print((abs(pi-qi)))
if __name__=='__main__':
main() | 17 | 19 | 300 | 413 | import itertools
n = int(eval(input()))
p = tuple([int(i) for i in input().split()])
q = tuple([int(i) for i in input().split()])
x = list(itertools.permutations(list(range(1, n + 1))))
nc = len(x)
for i in range(nc):
if x[i] == p:
pn = i
for j in range(nc):
if x[j] == q:
qn = j
print((abs(pn - qn)))
| def main():
from itertools import permutations
import sys
input = sys.stdin.readline
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
cnt = 1
for i in permutations(list(range(1, n + 1))):
if i == p:
pi = cnt
if i == q:
qi = cnt
cnt += 1
print((abs(pi - qi)))
if __name__ == "__main__":
main()
| false | 10.526316 | [
"-import itertools",
"+def main():",
"+ from itertools import permutations",
"+ import sys",
"-n = int(eval(input()))",
"-p = tuple([int(i) for i in input().split()])",
"-q = tuple([int(i) for i in input().split()])",
"-x = list(itertools.permutations(list(range(1, n + 1))))",
"-nc = len(x)",
... | false | 0.04132 | 0.065335 | 0.632438 | [
"s931184458",
"s065784422"
] |
u762420987 | p03612 | python | s750512666 | s232106210 | 203 | 72 | 52,908 | 14,008 | Accepted | Accepted | 64.53 | N = int(eval(input()))
plist = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
if plist[i] == i + 1:
plist[i], plist[i + 1] = plist[i + 1], plist[i]
ans += 1
if plist[-1] == N:
ans += 1
print(ans)
| N = int(eval(input()))
p = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
if p[i] == i + 1:
p[i], p[i + 1] = p[i + 1], p[i]
ans += 1
if p[-1] == N:
ans += 1
print(ans)
| 10 | 10 | 239 | 211 | N = int(eval(input()))
plist = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
if plist[i] == i + 1:
plist[i], plist[i + 1] = plist[i + 1], plist[i]
ans += 1
if plist[-1] == N:
ans += 1
print(ans)
| N = int(eval(input()))
p = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
if p[i] == i + 1:
p[i], p[i + 1] = p[i + 1], p[i]
ans += 1
if p[-1] == N:
ans += 1
print(ans)
| false | 0 | [
"-plist = list(map(int, input().split()))",
"+p = list(map(int, input().split()))",
"- if plist[i] == i + 1:",
"- plist[i], plist[i + 1] = plist[i + 1], plist[i]",
"+ if p[i] == i + 1:",
"+ p[i], p[i + 1] = p[i + 1], p[i]",
"-if plist[-1] == N:",
"+if p[-1] == N:"
] | false | 0.036231 | 0.03352 | 1.080898 | [
"s750512666",
"s232106210"
] |
u419963262 | p02657 | python | s877348278 | s559777771 | 24 | 22 | 9,012 | 9,108 | Accepted | Accepted | 8.33 | a,b=list(map(float,input().split()))
print((int(a*b//1))) | a,b=list(map(float,input().split()))
print((int(a*b*100000//100000))) | 2 | 2 | 50 | 62 | a, b = list(map(float, input().split()))
print((int(a * b // 1)))
| a, b = list(map(float, input().split()))
print((int(a * b * 100000 // 100000)))
| false | 0 | [
"-print((int(a * b // 1)))",
"+print((int(a * b * 100000 // 100000)))"
] | false | 0.046514 | 0.140396 | 0.331304 | [
"s877348278",
"s559777771"
] |
u246756871 | p02315 | python | s197047717 | s567298807 | 1,060 | 660 | 28,100 | 7,984 | Accepted | Accepted | 37.74 | n, maxw = list(map(int, input().split()))
v_lis, w_lis = [], [] # in order, list for values, and for weights
# set data
for _ in range(n):
v, c = list(map(int, input().split()))
v_lis.append(v)
w_lis.append(c)
# ?????´???????????????????????´????????§?¨±????????¨??????
# (Outer is for index of products, inner is maximum allowable amount)
dp = [[0 for _ in range(maxw+1)] for _ in range(n+1)]
for i in range(1, n+1):
for j in range(1, maxw+1):
if j>=w_lis[i-1]:
dp[i][j] = max(dp[i-1][j], dp[i-1][j-w_lis[i-1]]+v_lis[i-1])
else:
dp[i][j] = dp[i-1][j]
print((dp[-1][-1])) | n, maxw = list(map(int, input().split()))
dp = [0 for _ in range(maxw+1)]
for i in range(n):
v, c = list(map(int, input().split()))
for j in range(maxw, -1, -1):
if j>=c:
dp[j] = max(dp[j], dp[j-c]+v)
else:
break
print((dp[-1])) | 21 | 11 | 651 | 285 | n, maxw = list(map(int, input().split()))
v_lis, w_lis = [], [] # in order, list for values, and for weights
# set data
for _ in range(n):
v, c = list(map(int, input().split()))
v_lis.append(v)
w_lis.append(c)
# ?????´???????????????????????´????????§?¨±????????¨??????
# (Outer is for index of products, inner is maximum allowable amount)
dp = [[0 for _ in range(maxw + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, maxw + 1):
if j >= w_lis[i - 1]:
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w_lis[i - 1]] + v_lis[i - 1])
else:
dp[i][j] = dp[i - 1][j]
print((dp[-1][-1]))
| n, maxw = list(map(int, input().split()))
dp = [0 for _ in range(maxw + 1)]
for i in range(n):
v, c = list(map(int, input().split()))
for j in range(maxw, -1, -1):
if j >= c:
dp[j] = max(dp[j], dp[j - c] + v)
else:
break
print((dp[-1]))
| false | 47.619048 | [
"-v_lis, w_lis = [], [] # in order, list for values, and for weights",
"-# set data",
"-for _ in range(n):",
"+dp = [0 for _ in range(maxw + 1)]",
"+for i in range(n):",
"- v_lis.append(v)",
"- w_lis.append(c)",
"-# ?????´???????????????????????´????????§?¨±????????¨??????",
"-# (Outer is for... | false | 0.07215 | 0.042507 | 1.697365 | [
"s197047717",
"s567298807"
] |
u608088992 | p02762 | python | s924597947 | s428710932 | 879 | 741 | 25,892 | 26,032 | Accepted | Accepted | 15.7 | import sys
class UFT(): #Union-find tree class
def __init__(self, N):
self.tree = [int(i) for i in range(N)]
self.rank = [0 for i in range(N)]
def find(self, a):
if self.tree[a] == a: return a
else:
self.tree[a] = self.find(self.tree[a])
return self.tree[a]
def unite(self, a, b):
a = self.find(a)
b = self.find(b)
if a == b: return
if self.rank[a] < self.rank[b]: self.tree[a] = b
else:
self.tree[b] = a
if self.rank[a] == self.rank[b]: self.rank[a] += 1
def solve():
input = sys.stdin.readline
N, M, K = list(map(int, input().split()))
parent = UFT(N)
NG = [0] * N
Connected = [0] * N
treeSize = dict()
for _ in range(M):
x, y = list(map(int, input().split()))
parent.unite(x-1, y-1)
Connected[x-1] += 1
Connected[y-1] += 1
for _ in range(K):
x, y = list(map(int, input().split()))
if parent.find(x-1) != parent.find(y-1): continue
parent.unite(x-1, y-1)
NG[x-1] += 1
NG[y-1] += 1
for i in range(N):
key = parent.find(i)
if key in treeSize: treeSize[key] += 1
else: treeSize[key] = 1
Ans = [0] * N
for i in range(N):
Ans[i] = treeSize[parent.find(i)] - Connected[i] - NG[i] - 1
print((" ".join(map(str, Ans))))
return 0
if __name__ =="__main__":
solve() | import sys
class UFT(): #Union-find tree class
def __init__(self, N):
self.tree = [int(i) for i in range(N)]
self.rank = [0 for i in range(N)]
def find(self, a):
if self.tree[a] == a: return a
else:
self.tree[a] = self.find(self.tree[a])
return self.tree[a]
def unite(self, a, b):
a = self.find(a)
b = self.find(b)
if a == b: return
if self.rank[a] < self.rank[b]: self.tree[a] = b
else:
self.tree[b] = a
if self.rank[a] == self.rank[b]: self.rank[a] += 1
def solve():
input = sys.stdin.readline
N, M, K = list(map(int, input().split()))
parent = UFT(N)
connect = dict()
NG = [0] * N
friend = [0] * N
for _ in range(M):
x, y = list(map(int, input().split()))
parent.unite(x-1, y-1)
friend[x-1] += 1
friend[y-1] += 1
for i in range(N):
key = parent.find(i)
if key in connect: connect[key] += 1
else: connect[key] = 1
for _ in range(K):
c, d = list(map(int, input().split()))
if parent.find(c-1) == parent.find(d-1):
NG[c-1] += 1
NG[d-1] += 1
Ans = [0] * N
for i in range(N):
Ans[i] = connect[parent.find(i)] - friend[i] - NG[i] - 1
print((" ".join(map(str, Ans))))
return 0
if __name__ =="__main__":
solve() | 53 | 54 | 1,487 | 1,441 | import sys
class UFT: # Union-find tree class
def __init__(self, N):
self.tree = [int(i) for i in range(N)]
self.rank = [0 for i in range(N)]
def find(self, a):
if self.tree[a] == a:
return a
else:
self.tree[a] = self.find(self.tree[a])
return self.tree[a]
def unite(self, a, b):
a = self.find(a)
b = self.find(b)
if a == b:
return
if self.rank[a] < self.rank[b]:
self.tree[a] = b
else:
self.tree[b] = a
if self.rank[a] == self.rank[b]:
self.rank[a] += 1
def solve():
input = sys.stdin.readline
N, M, K = list(map(int, input().split()))
parent = UFT(N)
NG = [0] * N
Connected = [0] * N
treeSize = dict()
for _ in range(M):
x, y = list(map(int, input().split()))
parent.unite(x - 1, y - 1)
Connected[x - 1] += 1
Connected[y - 1] += 1
for _ in range(K):
x, y = list(map(int, input().split()))
if parent.find(x - 1) != parent.find(y - 1):
continue
parent.unite(x - 1, y - 1)
NG[x - 1] += 1
NG[y - 1] += 1
for i in range(N):
key = parent.find(i)
if key in treeSize:
treeSize[key] += 1
else:
treeSize[key] = 1
Ans = [0] * N
for i in range(N):
Ans[i] = treeSize[parent.find(i)] - Connected[i] - NG[i] - 1
print((" ".join(map(str, Ans))))
return 0
if __name__ == "__main__":
solve()
| import sys
class UFT: # Union-find tree class
def __init__(self, N):
self.tree = [int(i) for i in range(N)]
self.rank = [0 for i in range(N)]
def find(self, a):
if self.tree[a] == a:
return a
else:
self.tree[a] = self.find(self.tree[a])
return self.tree[a]
def unite(self, a, b):
a = self.find(a)
b = self.find(b)
if a == b:
return
if self.rank[a] < self.rank[b]:
self.tree[a] = b
else:
self.tree[b] = a
if self.rank[a] == self.rank[b]:
self.rank[a] += 1
def solve():
input = sys.stdin.readline
N, M, K = list(map(int, input().split()))
parent = UFT(N)
connect = dict()
NG = [0] * N
friend = [0] * N
for _ in range(M):
x, y = list(map(int, input().split()))
parent.unite(x - 1, y - 1)
friend[x - 1] += 1
friend[y - 1] += 1
for i in range(N):
key = parent.find(i)
if key in connect:
connect[key] += 1
else:
connect[key] = 1
for _ in range(K):
c, d = list(map(int, input().split()))
if parent.find(c - 1) == parent.find(d - 1):
NG[c - 1] += 1
NG[d - 1] += 1
Ans = [0] * N
for i in range(N):
Ans[i] = connect[parent.find(i)] - friend[i] - NG[i] - 1
print((" ".join(map(str, Ans))))
return 0
if __name__ == "__main__":
solve()
| false | 1.851852 | [
"+ connect = dict()",
"- Connected = [0] * N",
"- treeSize = dict()",
"+ friend = [0] * N",
"- Connected[x - 1] += 1",
"- Connected[y - 1] += 1",
"- for _ in range(K):",
"- x, y = list(map(int, input().split()))",
"- if parent.find(x - 1) != parent.find(y -... | false | 0.06633 | 0.078671 | 0.84313 | [
"s924597947",
"s428710932"
] |
u633068244 | p00053 | python | s825688717 | s745757530 | 720 | 50 | 6,692 | 8,808 | Accepted | Accepted | 93.06 | import math
r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
if p[i]:
for j in range(2*i+1,r,i+1):
p[j] = 0
while True:
n = int(input())
if not n:
break
i, num, sum = 0, 0, 0
while num < n:
if p[i] == 1:
num += 1
sum += i+1
i += 1
print(sum) | import math
r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
if p[i]:
for j in range(2*i+1,r,i+1):
p[j] = 0
prime = [0 for i in range(11000)]
j = 0
for i in range(len(p)):
if p[i]:
prime[j] = i+1
j += 1
while True:
n = int(input())
if not n:
break
print(sum(prime[:n])) | 22 | 23 | 389 | 400 | import math
r = 105000
sqrt = int(math.sqrt(r))
p = [1] * r
p[0] = 0
for i in range(1, sqrt):
if p[i]:
for j in range(2 * i + 1, r, i + 1):
p[j] = 0
while True:
n = int(input())
if not n:
break
i, num, sum = 0, 0, 0
while num < n:
if p[i] == 1:
num += 1
sum += i + 1
i += 1
print(sum)
| import math
r = 105000
sqrt = int(math.sqrt(r))
p = [1] * r
p[0] = 0
for i in range(1, sqrt):
if p[i]:
for j in range(2 * i + 1, r, i + 1):
p[j] = 0
prime = [0 for i in range(11000)]
j = 0
for i in range(len(p)):
if p[i]:
prime[j] = i + 1
j += 1
while True:
n = int(input())
if not n:
break
print(sum(prime[:n]))
| false | 4.347826 | [
"+prime = [0 for i in range(11000)]",
"+j = 0",
"+for i in range(len(p)):",
"+ if p[i]:",
"+ prime[j] = i + 1",
"+ j += 1",
"- i, num, sum = 0, 0, 0",
"- while num < n:",
"- if p[i] == 1:",
"- num += 1",
"- sum += i + 1",
"- i += 1",
... | false | 0.174231 | 0.079017 | 2.204993 | [
"s825688717",
"s745757530"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.