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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u485435834 | p03478 | python | s549076952 | s569874756 | 33 | 28 | 2,940 | 2,940 | Accepted | Accepted | 15.15 | N, A, B = list(map(int, input().split()))
num = 0
for i in range(1, N + 1):
if A <= sum(int(n) for n in str(i)) <= B:
num += i
print(num)
| N, A, B = list(map(int, input().split()))
print((sum(i for i in range(1, N+1) if A <= sum(map(int, str(i))) <= B)))
| 6 | 2 | 155 | 109 | N, A, B = list(map(int, input().split()))
num = 0
for i in range(1, N + 1):
if A <= sum(int(n) for n in str(i)) <= B:
num += i
print(num)
| N, A, B = list(map(int, input().split()))
print((sum(i for i in range(1, N + 1) if A <= sum(map(int, str(i))) <= B)))
| false | 66.666667 | [
"-num = 0",
"-for i in range(1, N + 1):",
"- if A <= sum(int(n) for n in str(i)) <= B:",
"- num += i",
"-print(num)",
"+print((sum(i for i in range(1, N + 1) if A <= sum(map(int, str(i))) <= B)))"
] | false | 0.05557 | 0.056126 | 0.990092 | [
"s549076952",
"s569874756"
] |
u619144316 | p02695 | python | s116016315 | s161490771 | 1,139 | 926 | 39,552 | 9,216 | Accepted | Accepted | 18.7 | import numpy as np
import itertools
N ,M ,Q = list(map(int,input().split(' ')))
ABCD = []
for _ in range(Q):
ABCD.append(list(map(int,input().split())))
ALL = list(itertools.combinations_with_replacement(list(range(1,M+1)), N))
MAX = 0
for row in ALL:
SUM = 0
for a,b,c,d in ABCD:
if (row[b-1] - row[a-1]) == c:
SUM += d
MAX = max(MAX,SUM)
print(MAX) | import itertools
N,M,Q = list(map(int,input().split()))
ABCD = []
for _ in range(Q):
a,b,c,d = list(map(int,input().split()))
ABCD.append(tuple([a-1,b-1,c,d]))
A = list(range(1,M+1))
MAX = 0
for L in itertools.combinations_with_replacement(A,N):
SUM = 0
for a,b,c,d in ABCD:
if L[b] - L[a] == c:
SUM += d
MAX = max(SUM,MAX)
print(MAX) | 18 | 19 | 394 | 384 | import numpy as np
import itertools
N, M, Q = list(map(int, input().split(" ")))
ABCD = []
for _ in range(Q):
ABCD.append(list(map(int, input().split())))
ALL = list(itertools.combinations_with_replacement(list(range(1, M + 1)), N))
MAX = 0
for row in ALL:
SUM = 0
for a, b, c, d in ABCD:
if (row[b - 1] - row[a - 1]) == c:
SUM += d
MAX = max(MAX, SUM)
print(MAX)
| import itertools
N, M, Q = list(map(int, input().split()))
ABCD = []
for _ in range(Q):
a, b, c, d = list(map(int, input().split()))
ABCD.append(tuple([a - 1, b - 1, c, d]))
A = list(range(1, M + 1))
MAX = 0
for L in itertools.combinations_with_replacement(A, N):
SUM = 0
for a, b, c, d in ABCD:
if L[b] - L[a] == c:
SUM += d
MAX = max(SUM, MAX)
print(MAX)
| false | 5.263158 | [
"-import numpy as np",
"-N, M, Q = list(map(int, input().split(\" \")))",
"+N, M, Q = list(map(int, input().split()))",
"- ABCD.append(list(map(int, input().split())))",
"-ALL = list(itertools.combinations_with_replacement(list(range(1, M + 1)), N))",
"+ a, b, c, d = list(map(int, input().split()))"... | false | 0.117055 | 0.107319 | 1.09072 | [
"s116016315",
"s161490771"
] |
u926678805 | p03290 | python | s397858580 | s587314716 | 266 | 47 | 3,064 | 3,064 | Accepted | Accepted | 82.33 | d,g=list(map(int,input().split()))
data=[]
cp=[]
for i in range(1,d+1):
p,c=list(map(int,input().split()))
data.append(p)
cp.append(c)
a=99999999
for i in range(1024):
ct=0
ans=0
tmp=data[:]
for j in range(d):
if i&(1<<j):
ct+=100*(j+1)*data[j]+cp[j]
ans+=data[j]
tmp[j]=0
p=len(tmp)-1
while ct<g :
if tmp[p]>1:
ct+=100*(p+1)
tmp[p]-=1
ans+=1
else:
p-=1
if p<0:
ans=99999999
break
a=min(a,ans)
print(a)
| d,g=list(map(int,input().split()))
data=[]
for i in range(d):
p,c=list(map(int,input().split()))
data.append((p,c))
n=0
mn=99999999
while n<2**d:
point=0
count=0
for i in range(d):
if n&(1<<i):
point+=data[i][0]*100*(i+1)+data[i][1]
count+=data[i][0]
if point<g:
for i in range(d):
i=d-1-i
if not n&(1<<i):
for j in range(data[i][0]-1):
point+=(i+1)*100
count+=1
if point>=g:
mn=min(mn,count)
break
else:
break
break
else:
mn=min(mn,count)
n+=1
print(mn)
| 32 | 32 | 620 | 755 | d, g = list(map(int, input().split()))
data = []
cp = []
for i in range(1, d + 1):
p, c = list(map(int, input().split()))
data.append(p)
cp.append(c)
a = 99999999
for i in range(1024):
ct = 0
ans = 0
tmp = data[:]
for j in range(d):
if i & (1 << j):
ct += 100 * (j + 1) * data[j] + cp[j]
ans += data[j]
tmp[j] = 0
p = len(tmp) - 1
while ct < g:
if tmp[p] > 1:
ct += 100 * (p + 1)
tmp[p] -= 1
ans += 1
else:
p -= 1
if p < 0:
ans = 99999999
break
a = min(a, ans)
print(a)
| d, g = list(map(int, input().split()))
data = []
for i in range(d):
p, c = list(map(int, input().split()))
data.append((p, c))
n = 0
mn = 99999999
while n < 2**d:
point = 0
count = 0
for i in range(d):
if n & (1 << i):
point += data[i][0] * 100 * (i + 1) + data[i][1]
count += data[i][0]
if point < g:
for i in range(d):
i = d - 1 - i
if not n & (1 << i):
for j in range(data[i][0] - 1):
point += (i + 1) * 100
count += 1
if point >= g:
mn = min(mn, count)
break
else:
break
break
else:
mn = min(mn, count)
n += 1
print(mn)
| false | 0 | [
"-cp = []",
"-for i in range(1, d + 1):",
"+for i in range(d):",
"- data.append(p)",
"- cp.append(c)",
"-a = 99999999",
"-for i in range(1024):",
"- ct = 0",
"- ans = 0",
"- tmp = data[:]",
"- for j in range(d):",
"- if i & (1 << j):",
"- ct += 100 * (j + ... | false | 0.039788 | 0.057133 | 0.696417 | [
"s397858580",
"s587314716"
] |
u948524308 | p03836 | python | s884957197 | s281533857 | 19 | 17 | 3,188 | 3,064 | Accepted | Accepted | 10.53 | sx,sy,tx,ty=list(map(int,input().split()))
r1=["R"]
for i in range(tx-sx-1):
r1.append("R")
for i in range(ty-sy):
r1.append("U")
for i in range(tx - sx):
r1.append("L")
for i in range(ty - sy):
r1.append("D")
r1.append("D")
for i in range(tx-sx+1):
r1.append("R")
for i in range(ty-sy+1):
r1.append("U")
r1.append("LU")
for i in range(tx-sx+1):
r1.append("L")
for i in range(ty-sy+1):
r1.append("D")
r1.append("R")
print(("".join(r1)))
| sx,sy,tx,ty=list(map(int,input().split()))
r1=["R"]*(tx-sx)
r1.append("U"*(ty-sy))
r1.append("L"*(tx - sx))
r1.append("D"*(ty - sy))
r1.append("D")
r1.append("R"*(tx-sx+1))
r1.append("U"*(ty-sy+1))
r1.append("LU")
r1.append("L"*(tx-sx+1))
r1.append("D"*(ty-sy+1))
r1.append("R")
print(("".join(r1)))
| 35 | 25 | 508 | 328 | sx, sy, tx, ty = list(map(int, input().split()))
r1 = ["R"]
for i in range(tx - sx - 1):
r1.append("R")
for i in range(ty - sy):
r1.append("U")
for i in range(tx - sx):
r1.append("L")
for i in range(ty - sy):
r1.append("D")
r1.append("D")
for i in range(tx - sx + 1):
r1.append("R")
for i in range(ty - sy + 1):
r1.append("U")
r1.append("LU")
for i in range(tx - sx + 1):
r1.append("L")
for i in range(ty - sy + 1):
r1.append("D")
r1.append("R")
print(("".join(r1)))
| sx, sy, tx, ty = list(map(int, input().split()))
r1 = ["R"] * (tx - sx)
r1.append("U" * (ty - sy))
r1.append("L" * (tx - sx))
r1.append("D" * (ty - sy))
r1.append("D")
r1.append("R" * (tx - sx + 1))
r1.append("U" * (ty - sy + 1))
r1.append("LU")
r1.append("L" * (tx - sx + 1))
r1.append("D" * (ty - sy + 1))
r1.append("R")
print(("".join(r1)))
| false | 28.571429 | [
"-r1 = [\"R\"]",
"-for i in range(tx - sx - 1):",
"- r1.append(\"R\")",
"-for i in range(ty - sy):",
"- r1.append(\"U\")",
"-for i in range(tx - sx):",
"- r1.append(\"L\")",
"-for i in range(ty - sy):",
"- r1.append(\"D\")",
"+r1 = [\"R\"] * (tx - sx)",
"+r1.append(\"U\" * (ty - sy))... | false | 0.038064 | 0.038385 | 0.991634 | [
"s884957197",
"s281533857"
] |
u408071652 | p02863 | python | s666754631 | s456687954 | 126 | 115 | 74,236 | 73,568 | Accepted | Accepted | 8.73 | import sys
# \n
def input():
return sys.stdin.readline().rstrip()
def main():
N, T = list(map(int, input().split()))
dp = [0] * (T + 1)
AB = []
for k in range(N):
a, b = list(map(int, input().split()))
AB.append((a, b))
AB.sort()
maxdp = 0
for i in range(N):
a, b = AB[i] # a:time b:value
dp[T] =max( maxdp + b,dp[T])
for j in range(T - 1, a - 1, -1):
dp[j] = max(dp[j], dp[j - a] + b)
maxdp= max(dp[j],maxdp)
print((dp[T]))
if __name__ == "__main__":
main()
| import sys
# \n
def input():
return sys.stdin.readline().rstrip()
def main():
N, T = list(map(int, input().split()))
dp = [0] * (T + 1)
AB = []
for k in range(N):
a, b = list(map(int, input().split()))
AB.append((a, b))
AB.sort()
maxdp = 0
temp =0
for i in range(N):
a, b = AB[i] # a:time b:value
temp +=a
dp[T] = max(maxdp + b, dp[T])
for j in range(min(T - 1,temp+1), a - 1, -1):
dp[j] = max(dp[j], dp[j - a] + b)
maxdp = max(dp[j], maxdp)
print((dp[T]))
if __name__ == "__main__":
main()
| 33 | 31 | 594 | 632 | import sys
# \n
def input():
return sys.stdin.readline().rstrip()
def main():
N, T = list(map(int, input().split()))
dp = [0] * (T + 1)
AB = []
for k in range(N):
a, b = list(map(int, input().split()))
AB.append((a, b))
AB.sort()
maxdp = 0
for i in range(N):
a, b = AB[i] # a:time b:value
dp[T] = max(maxdp + b, dp[T])
for j in range(T - 1, a - 1, -1):
dp[j] = max(dp[j], dp[j - a] + b)
maxdp = max(dp[j], maxdp)
print((dp[T]))
if __name__ == "__main__":
main()
| import sys
# \n
def input():
return sys.stdin.readline().rstrip()
def main():
N, T = list(map(int, input().split()))
dp = [0] * (T + 1)
AB = []
for k in range(N):
a, b = list(map(int, input().split()))
AB.append((a, b))
AB.sort()
maxdp = 0
temp = 0
for i in range(N):
a, b = AB[i] # a:time b:value
temp += a
dp[T] = max(maxdp + b, dp[T])
for j in range(min(T - 1, temp + 1), a - 1, -1):
dp[j] = max(dp[j], dp[j - a] + b)
maxdp = max(dp[j], maxdp)
print((dp[T]))
if __name__ == "__main__":
main()
| false | 6.060606 | [
"+ temp = 0",
"+ temp += a",
"- for j in range(T - 1, a - 1, -1):",
"+ for j in range(min(T - 1, temp + 1), a - 1, -1):"
] | false | 0.036286 | 0.036133 | 1.004246 | [
"s666754631",
"s456687954"
] |
u330661451 | p02954 | python | s449804399 | s359190394 | 215 | 123 | 4,984 | 10,484 | Accepted | Accepted | 42.79 | s = input() + "R"
v = [0 for i in range(len(s)-1)]
even = 0
odd = 0
lrpos = 0
lr = "R"
for i in range(len(s)):
if lr != s[i]:
if lr == "R":
if even == odd:
v[i-1] += even
v[i] += odd
else:
v[i] += even
v[i-1] += odd
else:
if even == odd:
v[lrpos] += even
v[lrpos-1] += odd
else:
v[lrpos-1] += even
v[lrpos] += odd
odd = 0
even = 0
lr = s[i]
lrpos = i
if even < odd:
even += 1
else:
odd += 1
for i in v:
print(str(i) + " ",end="")
| s = eval(input())
ans = [0] * len(s)
cnt = 1
prev = -1
for i in range(1,len(s)+1):
if i == len(s) or s[i] != s[i-1]:
if s[i-1] == "L":
ans[prev-1] += cnt // 2
ans[prev] += (cnt+1) // 2
else:
ans[i] += cnt // 2
ans[i-1] += (cnt+1) // 2
prev = i
cnt = 1
else:
cnt += 1
print((" ".join(map(str,ans))))
| 37 | 18 | 739 | 405 | s = input() + "R"
v = [0 for i in range(len(s) - 1)]
even = 0
odd = 0
lrpos = 0
lr = "R"
for i in range(len(s)):
if lr != s[i]:
if lr == "R":
if even == odd:
v[i - 1] += even
v[i] += odd
else:
v[i] += even
v[i - 1] += odd
else:
if even == odd:
v[lrpos] += even
v[lrpos - 1] += odd
else:
v[lrpos - 1] += even
v[lrpos] += odd
odd = 0
even = 0
lr = s[i]
lrpos = i
if even < odd:
even += 1
else:
odd += 1
for i in v:
print(str(i) + " ", end="")
| s = eval(input())
ans = [0] * len(s)
cnt = 1
prev = -1
for i in range(1, len(s) + 1):
if i == len(s) or s[i] != s[i - 1]:
if s[i - 1] == "L":
ans[prev - 1] += cnt // 2
ans[prev] += (cnt + 1) // 2
else:
ans[i] += cnt // 2
ans[i - 1] += (cnt + 1) // 2
prev = i
cnt = 1
else:
cnt += 1
print((" ".join(map(str, ans))))
| false | 51.351351 | [
"-s = input() + \"R\"",
"-v = [0 for i in range(len(s) - 1)]",
"-even = 0",
"-odd = 0",
"-lrpos = 0",
"-lr = \"R\"",
"-for i in range(len(s)):",
"- if lr != s[i]:",
"- if lr == \"R\":",
"- if even == odd:",
"- v[i - 1] += even",
"- v[i] += odd... | false | 0.035905 | 0.057529 | 0.624122 | [
"s449804399",
"s359190394"
] |
u797673668 | p02266 | python | s265637083 | s286566733 | 80 | 70 | 8,152 | 8,416 | Accepted | Accepted | 12.5 | def marge_ponds(lx, area_of_pond):
global ponds
if ponds:
lp = ponds.pop()
if lp[0] > lx:
return marge_ponds(lx, area_of_pond + lp[1])
else:
ponds.append(lp)
return area_of_pond
terrains = input().strip()
x, last_x, ponds = 0, [], []
for terrain in terrains:
if terrain == '\\':
last_x.append(x)
elif terrain == '/':
if last_x:
lx = last_x.pop()
area_of_pond = marge_ponds(lx, x - lx)
ponds.append((lx, area_of_pond))
x += 1
print((sum(pond[1] for pond in ponds)))
ponds.insert(0, (0, len(ponds)))
print((' '.join(map(str, [pond[1] for pond in ponds])))) | from collections import deque
def marge_ponds(lx, area_of_pond):
global ponds
if ponds and ponds[-1][0] > lx:
return marge_ponds(lx, area_of_pond + ponds.pop()[1])
return area_of_pond
terrains = input().strip()
x, last_x, ponds = 0, deque(), deque()
for terrain in terrains:
if terrain == '\\':
last_x.append(x)
elif terrain == '/':
if last_x:
lx = last_x.pop()
ponds.append((lx, marge_ponds(lx, x - lx)))
x += 1
print((sum(pond[1] for pond in ponds)))
ponds.appendleft((0, len(ponds)))
print((' '.join(map(str, [pond[1] for pond in ponds])))) | 27 | 25 | 704 | 641 | def marge_ponds(lx, area_of_pond):
global ponds
if ponds:
lp = ponds.pop()
if lp[0] > lx:
return marge_ponds(lx, area_of_pond + lp[1])
else:
ponds.append(lp)
return area_of_pond
terrains = input().strip()
x, last_x, ponds = 0, [], []
for terrain in terrains:
if terrain == "\\":
last_x.append(x)
elif terrain == "/":
if last_x:
lx = last_x.pop()
area_of_pond = marge_ponds(lx, x - lx)
ponds.append((lx, area_of_pond))
x += 1
print((sum(pond[1] for pond in ponds)))
ponds.insert(0, (0, len(ponds)))
print((" ".join(map(str, [pond[1] for pond in ponds]))))
| from collections import deque
def marge_ponds(lx, area_of_pond):
global ponds
if ponds and ponds[-1][0] > lx:
return marge_ponds(lx, area_of_pond + ponds.pop()[1])
return area_of_pond
terrains = input().strip()
x, last_x, ponds = 0, deque(), deque()
for terrain in terrains:
if terrain == "\\":
last_x.append(x)
elif terrain == "/":
if last_x:
lx = last_x.pop()
ponds.append((lx, marge_ponds(lx, x - lx)))
x += 1
print((sum(pond[1] for pond in ponds)))
ponds.appendleft((0, len(ponds)))
print((" ".join(map(str, [pond[1] for pond in ponds]))))
| false | 7.407407 | [
"+from collections import deque",
"+",
"+",
"- if ponds:",
"- lp = ponds.pop()",
"- if lp[0] > lx:",
"- return marge_ponds(lx, area_of_pond + lp[1])",
"- else:",
"- ponds.append(lp)",
"+ if ponds and ponds[-1][0] > lx:",
"+ return marge_pon... | false | 0.037472 | 0.037078 | 1.010625 | [
"s265637083",
"s286566733"
] |
u175034939 | p03681 | python | s094965174 | s328118697 | 702 | 41 | 5,112 | 3,064 | Accepted | Accepted | 94.16 | import math
n,m = list(map(int,input().split()))
a = 1000000007
if not (0 <= abs(n-m) <= 1):
print((0))
exit()
if n == m:
num = 2
else:
num = 1
print((num*math.factorial(n)*math.factorial(m) % a)) | n,m = list(map(int,input().split()))
a = 10**9+7
if m > n:
n,m = m,n
if not (0 <= n-m <= 1):
print((0))
exit()
if n == m:
num = 2
n = 1
else:
num = 1
t = 1
for i in range(1,m+1):
t *= i
t %= a
print((num*t*t*n%a)) | 12 | 18 | 214 | 254 | import math
n, m = list(map(int, input().split()))
a = 1000000007
if not (0 <= abs(n - m) <= 1):
print((0))
exit()
if n == m:
num = 2
else:
num = 1
print((num * math.factorial(n) * math.factorial(m) % a))
| n, m = list(map(int, input().split()))
a = 10**9 + 7
if m > n:
n, m = m, n
if not (0 <= n - m <= 1):
print((0))
exit()
if n == m:
num = 2
n = 1
else:
num = 1
t = 1
for i in range(1, m + 1):
t *= i
t %= a
print((num * t * t * n % a))
| false | 33.333333 | [
"-import math",
"-",
"-a = 1000000007",
"-if not (0 <= abs(n - m) <= 1):",
"+a = 10**9 + 7",
"+if m > n:",
"+ n, m = m, n",
"+if not (0 <= n - m <= 1):",
"+ n = 1",
"-print((num * math.factorial(n) * math.factorial(m) % a))",
"+t = 1",
"+for i in range(1, m + 1):",
"+ t *= i",
"+ ... | false | 0.165802 | 0.040907 | 4.053167 | [
"s094965174",
"s328118697"
] |
u077291787 | p03354 | python | s021626256 | s049900920 | 582 | 529 | 90,944 | 90,168 | Accepted | Accepted | 9.11 | # ARC097D - Equals (ABC097D)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
def dfs(v: int, color: int) -> None:
seen[v] = 1 # make vertex v searched
group[v] = color
for u in G[v]: # search vertices available from v recursively
if not seen[u]: # skip if already searched
dfs(u, color)
def main():
# check i and Pi are connected components or not
global G, seen, group
N, M = tuple(map(int, input().split()))
P = tuple(map(int, input().split()))
E = tuple(tuple(map(int, input().split())) for _ in range(M))
G = [[] for _ in range(N + 1)] # construct a graph (1-idx)
for v, u in E:
G[v] += [u]
G[u] += [v]
seen, group = [0] * (N + 1), [0] * (N + 1)
color = 1
for i in range(1, N + 1): # connected components have the same color
if not seen[i]:
dfs(i, color)
color += 1
ans = sum(group[i] == group[p] for i, p in enumerate(P, 1))
print(ans)
if __name__ == "__main__":
main() | # ARC097D - Equals
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
def dfs(v: int, color: int) -> None:
group[v] = color # make vertex v searched
for u in G[v]: # search vertices available from v recursively
if not group[u]: # skip if already searched
dfs(u, color)
def main():
# check i and Pi are connected components or not
global G, group
N, M = tuple(map(int, input().split()))
P = tuple(map(int, input().split()))
E = tuple(tuple(map(int, input().split())) for _ in range(M))
G = [[] for _ in range(N + 1)] # construct a graph (1-idx)
for v, u in E:
G[v] += [u]
G[u] += [v]
group = [0] * (N + 1)
color = 1
for v in range(1, N + 1): # connected components are in the same group
if not group[v]:
dfs(v, color)
color += 1
ans = sum(group[i] == group[p] for i, p in enumerate(P, 1))
print(ans)
if __name__ == "__main__":
main() | 37 | 36 | 1,075 | 1,025 | # ARC097D - Equals (ABC097D)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
def dfs(v: int, color: int) -> None:
seen[v] = 1 # make vertex v searched
group[v] = color
for u in G[v]: # search vertices available from v recursively
if not seen[u]: # skip if already searched
dfs(u, color)
def main():
# check i and Pi are connected components or not
global G, seen, group
N, M = tuple(map(int, input().split()))
P = tuple(map(int, input().split()))
E = tuple(tuple(map(int, input().split())) for _ in range(M))
G = [[] for _ in range(N + 1)] # construct a graph (1-idx)
for v, u in E:
G[v] += [u]
G[u] += [v]
seen, group = [0] * (N + 1), [0] * (N + 1)
color = 1
for i in range(1, N + 1): # connected components have the same color
if not seen[i]:
dfs(i, color)
color += 1
ans = sum(group[i] == group[p] for i, p in enumerate(P, 1))
print(ans)
if __name__ == "__main__":
main()
| # ARC097D - Equals
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
def dfs(v: int, color: int) -> None:
group[v] = color # make vertex v searched
for u in G[v]: # search vertices available from v recursively
if not group[u]: # skip if already searched
dfs(u, color)
def main():
# check i and Pi are connected components or not
global G, group
N, M = tuple(map(int, input().split()))
P = tuple(map(int, input().split()))
E = tuple(tuple(map(int, input().split())) for _ in range(M))
G = [[] for _ in range(N + 1)] # construct a graph (1-idx)
for v, u in E:
G[v] += [u]
G[u] += [v]
group = [0] * (N + 1)
color = 1
for v in range(1, N + 1): # connected components are in the same group
if not group[v]:
dfs(v, color)
color += 1
ans = sum(group[i] == group[p] for i, p in enumerate(P, 1))
print(ans)
if __name__ == "__main__":
main()
| false | 2.702703 | [
"-# ARC097D - Equals (ABC097D)",
"+# ARC097D - Equals",
"- seen[v] = 1 # make vertex v searched",
"- group[v] = color",
"+ group[v] = color # make vertex v searched",
"- if not seen[u]: # skip if already searched",
"+ if not group[u]: # skip if already searched",
"- globa... | false | 0.074596 | 0.041191 | 1.810983 | [
"s021626256",
"s049900920"
] |
u919633157 | p03478 | python | s952362722 | s423943985 | 35 | 29 | 3,060 | 2,940 | Accepted | Accepted | 17.14 | n,a,b=list(map(int,input().split()))
cnt=0
for i in range(1,n+1):
if a<=sum(list(map(int,str(i))))<=b:
cnt+=i
print(cnt) | n,a,b=list(map(int,input().split()))
cnt=0
for i in range(1,n+1):
if a<=sum(map(int,str(i)))<=b:
cnt+=i
print(cnt) | 6 | 6 | 131 | 125 | n, a, b = list(map(int, input().split()))
cnt = 0
for i in range(1, n + 1):
if a <= sum(list(map(int, str(i)))) <= b:
cnt += i
print(cnt)
| n, a, b = list(map(int, input().split()))
cnt = 0
for i in range(1, n + 1):
if a <= sum(map(int, str(i))) <= b:
cnt += i
print(cnt)
| false | 0 | [
"- if a <= sum(list(map(int, str(i)))) <= b:",
"+ if a <= sum(map(int, str(i))) <= b:"
] | false | 0.03458 | 0.033854 | 1.021438 | [
"s952362722",
"s423943985"
] |
u883048396 | p03401 | python | s167602198 | s723922605 | 185 | 171 | 16,192 | 16,192 | Accepted | Accepted | 7.57 | iN = int(eval(input()))
aA = [0] + [int(_) for _ in input().split()] + [0]
iAll = sum([abs(aA[i+1]-aA[i]) for i in range(iN+1)])
print(("\n".join([str( iAll - abs(aA[i-1]-aA[i]) - abs(aA[i]-aA[i+1]) + abs(aA[i-1]-aA[i+1])) for i in range(1,iN+1)])))
| #mapってそんなに速ないんけ?
iN = int(eval(input()))
aA = [0] + [int(_) for _ in input().split()] + [0]
iAll = sum([abs(aA[i+1]-aA[i]) for i in range(iN+1)])
print(("\n".join(map(str,[iAll - abs(aA[i-1]-aA[i]) - abs(aA[i]-aA[i+1]) + abs(aA[i-1]-aA[i+1]) for i in range(1,iN+1)]))))
| 4 | 5 | 253 | 274 | iN = int(eval(input()))
aA = [0] + [int(_) for _ in input().split()] + [0]
iAll = sum([abs(aA[i + 1] - aA[i]) for i in range(iN + 1)])
print(
(
"\n".join(
[
str(
iAll
- abs(aA[i - 1] - aA[i])
- abs(aA[i] - aA[i + 1])
+ abs(aA[i - 1] - aA[i + 1])
)
for i in range(1, iN + 1)
]
)
)
)
| # mapってそんなに速ないんけ?
iN = int(eval(input()))
aA = [0] + [int(_) for _ in input().split()] + [0]
iAll = sum([abs(aA[i + 1] - aA[i]) for i in range(iN + 1)])
print(
(
"\n".join(
map(
str,
[
iAll
- abs(aA[i - 1] - aA[i])
- abs(aA[i] - aA[i + 1])
+ abs(aA[i - 1] - aA[i + 1])
for i in range(1, iN + 1)
],
)
)
)
)
| false | 20 | [
"+# mapってそんなに速ないんけ?",
"- [",
"- str(",
"+ map(",
"+ str,",
"+ [",
"- )",
"- for i in range(1, iN + 1)",
"- ]",
"+ for i in range(1, iN + 1)",
"+ ],",
"+... | false | 0.104958 | 0.101177 | 1.037372 | [
"s167602198",
"s723922605"
] |
u476604182 | p02955 | python | s668017813 | s719733946 | 297 | 256 | 45,276 | 42,860 | Accepted | Accepted | 13.8 | N, K = list(map(int, input().split()))
A = [int(c) for c in input().split()]
S = sum(A)
pls = []
for i in range(1,S):
if i*i>S:
break
if S%i==0:
pls += [i]
pls += [S//i]
pls.sort(reverse=True)
for p in pls:
B = []
for i in range(N):
B += [A[i]%p]
B.sort()
for j in range(N):
if B[j]!=0:
break
m = j
lim = N-1
cnt = 0
while m<lim:
if B[m]<p-B[-1]:
B[-1] += B[m]
cnt += B[m]
B[m] = 0
m += 1
elif B[m]>p-B[-1]:
cnt += p-B[-1]
B[m] -= p-B[-1]
B.pop()
lim -= 1
else:
B.pop()
cnt += B[m]
B[m] = 0
m += 1
lim -= 1
if B[-1]==0 and cnt<=K:
print(p)
break | N,K,*A = list(map(int, open(0).read().split()))
pls = []
S = sum(A)
for i in range(1,int(S**0.5)+1):
if S%i==0:
pls.append(i)
pls.append(S//i)
pls.sort()
ans = 0
for p in pls:
B = [a%p for a in A]
B.sort()
i = 0
j = N-1
cnt = K
while i<N:
if B[i]!=0:
break
i += 1
else:
ans = p
continue
while True:
a = B[i]
b = B[j]
if a<p-b:
if cnt<a:
break
B[j] += a
cnt -= a
i += 1
elif a>p-b:
if cnt<p-b:
break
B[i] -= p-b
cnt -= p-b
j -= 1
else:
if cnt<a:
break
cnt -= a
i += 1
j -= 1
if i>=j:
ans = p
break
print(ans) | 42 | 47 | 786 | 727 | N, K = list(map(int, input().split()))
A = [int(c) for c in input().split()]
S = sum(A)
pls = []
for i in range(1, S):
if i * i > S:
break
if S % i == 0:
pls += [i]
pls += [S // i]
pls.sort(reverse=True)
for p in pls:
B = []
for i in range(N):
B += [A[i] % p]
B.sort()
for j in range(N):
if B[j] != 0:
break
m = j
lim = N - 1
cnt = 0
while m < lim:
if B[m] < p - B[-1]:
B[-1] += B[m]
cnt += B[m]
B[m] = 0
m += 1
elif B[m] > p - B[-1]:
cnt += p - B[-1]
B[m] -= p - B[-1]
B.pop()
lim -= 1
else:
B.pop()
cnt += B[m]
B[m] = 0
m += 1
lim -= 1
if B[-1] == 0 and cnt <= K:
print(p)
break
| N, K, *A = list(map(int, open(0).read().split()))
pls = []
S = sum(A)
for i in range(1, int(S**0.5) + 1):
if S % i == 0:
pls.append(i)
pls.append(S // i)
pls.sort()
ans = 0
for p in pls:
B = [a % p for a in A]
B.sort()
i = 0
j = N - 1
cnt = K
while i < N:
if B[i] != 0:
break
i += 1
else:
ans = p
continue
while True:
a = B[i]
b = B[j]
if a < p - b:
if cnt < a:
break
B[j] += a
cnt -= a
i += 1
elif a > p - b:
if cnt < p - b:
break
B[i] -= p - b
cnt -= p - b
j -= 1
else:
if cnt < a:
break
cnt -= a
i += 1
j -= 1
if i >= j:
ans = p
break
print(ans)
| false | 10.638298 | [
"-N, K = list(map(int, input().split()))",
"-A = [int(c) for c in input().split()]",
"+N, K, *A = list(map(int, open(0).read().split()))",
"+pls = []",
"-pls = []",
"-for i in range(1, S):",
"- if i * i > S:",
"- break",
"+for i in range(1, int(S**0.5) + 1):",
"- pls += [i]",
"-... | false | 0.037056 | 0.117175 | 0.316242 | [
"s668017813",
"s719733946"
] |
u745087332 | p03208 | python | s551704674 | s626495195 | 193 | 133 | 18,164 | 7,384 | Accepted | Accepted | 31.09 | # coding:utf-8
import sys
from collections import Counter
input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7
def inpl(): return list(map(int, input().split()))
N, K = inpl()
H = []
for i in range(N):
H.append(int(eval(input())))
C = Counter(H)
H2 = sorted(H)
S = [0]
for i in range(N - 1):
S.append(S[-1] + H2[i + 1] - H2[i])
# print(H2)
ans = INF
for i in range(N - K + 1):
# print(i + K - 1, S[i + K - 1] - S[i])
ans = min(ans, S[i + K - 1] - S[i])
print(ans)
| # coding:utf-8
import sys
input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7
def inpl(): return list(map(int, input().split()))
N, K = inpl()
H = [int(eval(input())) for _ in range(N)]
H.sort()
ans = INF
for i in range(N - K + 1):
ans = min(ans, H[i + K - 1] - H[i])
print(ans)
| 34 | 22 | 530 | 319 | # coding:utf-8
import sys
from collections import Counter
input = sys.stdin.readline
INF = float("inf")
MOD = 10**9 + 7
def inpl():
return list(map(int, input().split()))
N, K = inpl()
H = []
for i in range(N):
H.append(int(eval(input())))
C = Counter(H)
H2 = sorted(H)
S = [0]
for i in range(N - 1):
S.append(S[-1] + H2[i + 1] - H2[i])
# print(H2)
ans = INF
for i in range(N - K + 1):
# print(i + K - 1, S[i + K - 1] - S[i])
ans = min(ans, S[i + K - 1] - S[i])
print(ans)
| # coding:utf-8
import sys
input = sys.stdin.readline
INF = float("inf")
MOD = 10**9 + 7
def inpl():
return list(map(int, input().split()))
N, K = inpl()
H = [int(eval(input())) for _ in range(N)]
H.sort()
ans = INF
for i in range(N - K + 1):
ans = min(ans, H[i + K - 1] - H[i])
print(ans)
| false | 35.294118 | [
"-from collections import Counter",
"-H = []",
"-for i in range(N):",
"- H.append(int(eval(input())))",
"-C = Counter(H)",
"-H2 = sorted(H)",
"-S = [0]",
"-for i in range(N - 1):",
"- S.append(S[-1] + H2[i + 1] - H2[i])",
"-# print(H2)",
"+H = [int(eval(input())) for _ in range(N)]",
"+H... | false | 0.171266 | 0.045294 | 3.78119 | [
"s551704674",
"s626495195"
] |
u761989513 | p03448 | python | s238255380 | s587134064 | 50 | 18 | 2,940 | 3,060 | Accepted | Accepted | 64 | a, b, c, x = list(map(int, [eval(input()) for i in range(4)]))
ans = 0
for A in range(a + 1):
for B in range(b + 1):
for C in range(c + 1):
if 500 * A + 100 * B + 50 * C == x:
ans += 1
print(ans) | a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
ans = 0
for A in range(a + 1):
for B in range(b + 1):
C = (x - 500 * A - 100 * B) // 50
if 0 <= C <= c:
ans += 1
print(ans) | 8 | 11 | 210 | 233 | a, b, c, x = list(map(int, [eval(input()) for i in range(4)]))
ans = 0
for A in range(a + 1):
for B in range(b + 1):
for C in range(c + 1):
if 500 * A + 100 * B + 50 * C == x:
ans += 1
print(ans)
| a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
ans = 0
for A in range(a + 1):
for B in range(b + 1):
C = (x - 500 * A - 100 * B) // 50
if 0 <= C <= c:
ans += 1
print(ans)
| false | 27.272727 | [
"-a, b, c, x = list(map(int, [eval(input()) for i in range(4)]))",
"+a = int(eval(input()))",
"+b = int(eval(input()))",
"+c = int(eval(input()))",
"+x = int(eval(input()))",
"- for C in range(c + 1):",
"- if 500 * A + 100 * B + 50 * C == x:",
"- ans += 1",
"+ ... | false | 0.107562 | 0.054549 | 1.971859 | [
"s238255380",
"s587134064"
] |
u223133214 | p02803 | python | s413681966 | s472358171 | 314 | 284 | 49,116 | 47,580 | Accepted | Accepted | 9.55 | h, w = list(map(int, input().split()))
def cl(sx, sy, m):
Z = -1
dist = [[Z for i in range(w)] for j in range(h)]
for i in range(h):
for j in range(w):
if m[i][j] == '#':
dist[i][j] = -1
def bfs():
q = []
q.insert(0, (sx, sy))
dist[sy][sx] = 0
while len(q):
x, y = q.pop()
for i in range(0, 4):
nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
if (0 <= nx < w and 0 <= ny < h and m[ny][nx] != '#' and dist[ny][nx] == Z):
q.insert(0, (nx, ny))
dist[ny][nx] = dist[y][x] + 1
return dist
return bfs()
S = [list(eval(input())) for _ in range(h)]
ans = 0
for y in range(h):
for x in range(w):
e = S[y][x]
if e != '#':
num = cl(x, y, S)
for k in range(h):
ans = max(ans, max(num[k]))
print(ans)
| from collections import deque
h, w = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(h)]
INF = 10010001001
way = [[0, 1], [0, -1], [1, 0], [-1, 0]]
ans = 0
for sy in range(h):
for sx in range(w):
dist = [[INF] * w for _ in range(h)]
dist[sy][sx] = 0
if S[sy][sx] == '#':
continue
q = deque()
q.append((sy, sx))
while len(q):
y, x = q.popleft()
for dy, dx in way:
ny, nx = y + dy, x + dx
if not (0 <= ny <= h - 1 and 0 <= nx <= w - 1):
continue
if S[ny][nx] == '#' or dist[ny][nx] != INF:
continue
dist[ny][nx] = dist[y][x] + 1
q.append((ny, nx))
for yy in range(h):
for xx in range(w):
if dist[yy][xx] == INF:
continue
else:
ans = max(ans, dist[yy][xx])
print(ans) | 34 | 32 | 968 | 1,008 | h, w = list(map(int, input().split()))
def cl(sx, sy, m):
Z = -1
dist = [[Z for i in range(w)] for j in range(h)]
for i in range(h):
for j in range(w):
if m[i][j] == "#":
dist[i][j] = -1
def bfs():
q = []
q.insert(0, (sx, sy))
dist[sy][sx] = 0
while len(q):
x, y = q.pop()
for i in range(0, 4):
nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
if (
0 <= nx < w
and 0 <= ny < h
and m[ny][nx] != "#"
and dist[ny][nx] == Z
):
q.insert(0, (nx, ny))
dist[ny][nx] = dist[y][x] + 1
return dist
return bfs()
S = [list(eval(input())) for _ in range(h)]
ans = 0
for y in range(h):
for x in range(w):
e = S[y][x]
if e != "#":
num = cl(x, y, S)
for k in range(h):
ans = max(ans, max(num[k]))
print(ans)
| from collections import deque
h, w = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(h)]
INF = 10010001001
way = [[0, 1], [0, -1], [1, 0], [-1, 0]]
ans = 0
for sy in range(h):
for sx in range(w):
dist = [[INF] * w for _ in range(h)]
dist[sy][sx] = 0
if S[sy][sx] == "#":
continue
q = deque()
q.append((sy, sx))
while len(q):
y, x = q.popleft()
for dy, dx in way:
ny, nx = y + dy, x + dx
if not (0 <= ny <= h - 1 and 0 <= nx <= w - 1):
continue
if S[ny][nx] == "#" or dist[ny][nx] != INF:
continue
dist[ny][nx] = dist[y][x] + 1
q.append((ny, nx))
for yy in range(h):
for xx in range(w):
if dist[yy][xx] == INF:
continue
else:
ans = max(ans, dist[yy][xx])
print(ans)
| false | 5.882353 | [
"+from collections import deque",
"+",
"-",
"-",
"-def cl(sx, sy, m):",
"- Z = -1",
"- dist = [[Z for i in range(w)] for j in range(h)]",
"- for i in range(h):",
"- for j in range(w):",
"- if m[i][j] == \"#\":",
"- dist[i][j] = -1",
"-",
"- def bf... | false | 0.123389 | 0.049161 | 2.509918 | [
"s413681966",
"s472358171"
] |
u827202523 | p03355 | python | s179581224 | s919742508 | 82 | 46 | 68,952 | 10,904 | Accepted | Accepted | 43.9 | import sys
from collections import defaultdict, deque, Counter
import math
# import copy
from bisect import bisect_left, bisect_right
# import heapq
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
def nck(n, k, kaijyo):
return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD
def npk(n, k, kaijyo):
if k == 0 or k == n:
return n % MOD
return (kaijyo[n] * divide(kaijyo[n-k])) % MOD
def kaijyo(n):
ret = [1]
for i in range(1, n + 1):
ret.append((ret[-1] * i)% MOD)
return ret
def solve():
S = getS()
k = getN()
li = []
for i in range(len(S)):
for j in range(1, k + 1):
if i + j > len(S):
continue
li.append(S[i:i+j])
li = list(set(li))
li.sort()
print((li[k-1]))
# print(li)
def main():
n = getN()
for _ in range(n):
solve()
if __name__ == "__main__":
# main()
solve() | import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
def solve():
s = getS()
k = getN()
ss = set()
for i in range(len(s)):
for j in range(1, k+1):
if i + j <= len(s):
ss.add(s[i:i+j])
ss = list(ss)
ss.sort()
# ss.sort(key=lambda x:len(x))
# print(ss)
print((ss[k-1]))
def main():
n = getN()
for _ in range(n):
solve()
return
if __name__ == "__main__":
# main()
solve()
| 67 | 51 | 1,255 | 1,002 | import sys
from collections import defaultdict, deque, Counter
import math
# import copy
from bisect import bisect_left, bisect_right
# import heapq
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = 10**20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)
def nck(n, k, kaijyo):
return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD
def npk(n, k, kaijyo):
if k == 0 or k == n:
return n % MOD
return (kaijyo[n] * divide(kaijyo[n - k])) % MOD
def kaijyo(n):
ret = [1]
for i in range(1, n + 1):
ret.append((ret[-1] * i) % MOD)
return ret
def solve():
S = getS()
k = getN()
li = []
for i in range(len(S)):
for j in range(1, k + 1):
if i + j > len(S):
continue
li.append(S[i : i + j])
li = list(set(li))
li.sort()
print((li[k - 1]))
# print(li)
def main():
n = getN()
for _ in range(n):
solve()
if __name__ == "__main__":
# main()
solve()
| import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)
def solve():
s = getS()
k = getN()
ss = set()
for i in range(len(s)):
for j in range(1, k + 1):
if i + j <= len(s):
ss.add(s[i : i + j])
ss = list(ss)
ss.sort()
# ss.sort(key=lambda x:len(x))
# print(ss)
print((ss[k - 1]))
def main():
n = getN()
for _ in range(n):
solve()
return
if __name__ == "__main__":
# main()
solve()
| false | 23.880597 | [
"+import math",
"+import copy",
"+from heapq import heappush, heappop, heapify",
"+from functools import cmp_to_key",
"+from bisect import bisect_left, bisect_right",
"-import math",
"-# import copy",
"-from bisect import bisect_left, bisect_right",
"-",
"-# import heapq",
"-INF = 10**20",
"+I... | false | 0.127782 | 0.1688 | 0.757001 | [
"s179581224",
"s919742508"
] |
u127499732 | p03078 | python | s104255003 | s518327783 | 791 | 35 | 4,852 | 5,360 | Accepted | Accepted | 95.58 | def main():
import heapq
x, y, z, k, *abc = map(int, open(0).read().split())
a = abc[:x]
b = abc[x:x + y]
c = abc[x + y:]
d = []
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
h = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
heapq.heapify(h)
ans = []
for _ in range(k):
p, i, j, k = heapq.heappop(h)
ans.append(-p)
for p, q, r in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]:
if i + p < x and j + q < y and k + r < z:
if (i + p, j + q, k + r) not in d:
d.append((i + p, j + q, k + r))
v = - (a[i + p] + b[j + q] + c[k + r])
heapq.heappush(h, (v, i + p, j + q, k + r))
print(*ans, sep='\n')
if __name__ == '__main__':
main()
| def main():
import heapq
x, y, z, k, *abc = map(int, open(0).read().split())
a = abc[:x]
b = abc[x:x + y]
c = abc[x + y:]
s = set()
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
h = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
heapq.heapify(h)
ans = []
for _ in range(k):
p, i, j, k = heapq.heappop(h)
ans.append(-p)
for p, q, r in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]:
if i + p < x and j + q < y and k + r < z:
if (i + p, j + q, k + r) not in s:
s.add((i + p, j + q, k + r))
v = - (a[i + p] + b[j + q] + c[k + r])
heapq.heappush(h, (v, i + p, j + q, k + r))
print(*ans, sep='\n')
if __name__ == '__main__':
main()
| 31 | 31 | 827 | 827 | def main():
import heapq
x, y, z, k, *abc = map(int, open(0).read().split())
a = abc[:x]
b = abc[x : x + y]
c = abc[x + y :]
d = []
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
h = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
heapq.heapify(h)
ans = []
for _ in range(k):
p, i, j, k = heapq.heappop(h)
ans.append(-p)
for p, q, r in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]:
if i + p < x and j + q < y and k + r < z:
if (i + p, j + q, k + r) not in d:
d.append((i + p, j + q, k + r))
v = -(a[i + p] + b[j + q] + c[k + r])
heapq.heappush(h, (v, i + p, j + q, k + r))
print(*ans, sep="\n")
if __name__ == "__main__":
main()
| def main():
import heapq
x, y, z, k, *abc = map(int, open(0).read().split())
a = abc[:x]
b = abc[x : x + y]
c = abc[x + y :]
s = set()
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
h = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
heapq.heapify(h)
ans = []
for _ in range(k):
p, i, j, k = heapq.heappop(h)
ans.append(-p)
for p, q, r in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]:
if i + p < x and j + q < y and k + r < z:
if (i + p, j + q, k + r) not in s:
s.add((i + p, j + q, k + r))
v = -(a[i + p] + b[j + q] + c[k + r])
heapq.heappush(h, (v, i + p, j + q, k + r))
print(*ans, sep="\n")
if __name__ == "__main__":
main()
| false | 0 | [
"- d = []",
"+ s = set()",
"- if (i + p, j + q, k + r) not in d:",
"- d.append((i + p, j + q, k + r))",
"+ if (i + p, j + q, k + r) not in s:",
"+ s.add((i + p, j + q, k + r))"
] | false | 0.045528 | 0.035432 | 1.284939 | [
"s104255003",
"s518327783"
] |
u062147869 | p03233 | python | s029494490 | s504610832 | 1,271 | 890 | 64,752 | 58,460 | Accepted | Accepted | 29.98 | import sys
N=int(eval(input()))
A=0
B=0
table=[]
for i in range(N):
a,b=list(map(int,input().split()))
table.append((a,i))
table.append((b,i))
A+=a
B+=b
ans=min(A,B)
table.sort()
num=0
for i in range(N):
num+=table[i][0]
L=[0]*N
#print(table)
for i in range(N):
c,j=table[i]
if L[j]!=0:
ans=min(num,ans)
print(ans)
#print(L)
sys.exit()
L[j]+=1
c,n=table[N-1]
if n!=table[N][1]:
num=num-table[N-1][0]+table[N][0]
ans = min(num, ans)
print(ans)
sys.exit()
num1=num-table[N-1][0]+table[N+1][0]
num2=num-table[N-2][0]+table[N][0]
print((min(ans,num1,num2)))
| import sys
input = sys.stdin.readline
N=int(eval(input()))
A=0
B=0
table=[]
for i in range(N):
a,b=list(map(int,input().split()))
table.append((a,i))
table.append((b,i))
A+=a
B+=b
ans=min(A,B)
table.sort()
num=0
for i in range(N):
num+=table[i][0]
L=[0]*N
#print(table)
for i in range(N):
c,j=table[i]
if L[j]!=0:
ans=min(num,ans)
print(ans)
#print(L)
sys.exit()
L[j]+=1
c,n=table[N-1]
if n!=table[N][1]:
num=num-table[N-1][0]+table[N][0]
ans = min(num, ans)
print(ans)
sys.exit()
num1=num-table[N-1][0]+table[N+1][0]
num2=num-table[N-2][0]+table[N][0]
print((min(ans,num1,num2)))
| 37 | 38 | 662 | 690 | import sys
N = int(eval(input()))
A = 0
B = 0
table = []
for i in range(N):
a, b = list(map(int, input().split()))
table.append((a, i))
table.append((b, i))
A += a
B += b
ans = min(A, B)
table.sort()
num = 0
for i in range(N):
num += table[i][0]
L = [0] * N
# print(table)
for i in range(N):
c, j = table[i]
if L[j] != 0:
ans = min(num, ans)
print(ans)
# print(L)
sys.exit()
L[j] += 1
c, n = table[N - 1]
if n != table[N][1]:
num = num - table[N - 1][0] + table[N][0]
ans = min(num, ans)
print(ans)
sys.exit()
num1 = num - table[N - 1][0] + table[N + 1][0]
num2 = num - table[N - 2][0] + table[N][0]
print((min(ans, num1, num2)))
| import sys
input = sys.stdin.readline
N = int(eval(input()))
A = 0
B = 0
table = []
for i in range(N):
a, b = list(map(int, input().split()))
table.append((a, i))
table.append((b, i))
A += a
B += b
ans = min(A, B)
table.sort()
num = 0
for i in range(N):
num += table[i][0]
L = [0] * N
# print(table)
for i in range(N):
c, j = table[i]
if L[j] != 0:
ans = min(num, ans)
print(ans)
# print(L)
sys.exit()
L[j] += 1
c, n = table[N - 1]
if n != table[N][1]:
num = num - table[N - 1][0] + table[N][0]
ans = min(num, ans)
print(ans)
sys.exit()
num1 = num - table[N - 1][0] + table[N + 1][0]
num2 = num - table[N - 2][0] + table[N][0]
print((min(ans, num1, num2)))
| false | 2.631579 | [
"+input = sys.stdin.readline"
] | false | 0.086621 | 0.118316 | 0.732117 | [
"s029494490",
"s504610832"
] |
u747602774 | p03945 | python | s408870824 | s625340058 | 49 | 40 | 3,956 | 3,188 | Accepted | Accepted | 18.37 | li=list(eval(input()))
ans=0
for n in range(len(li)-1):
if li[n]!=li[n+1]:
ans+=1
print(ans) | s = eval(input())
n = len(s)
t = s[0]
ans = 0
for i in range(n):
if s[i] != t:
ans += 1
t = s[i]
print(ans) | 6 | 9 | 97 | 129 | li = list(eval(input()))
ans = 0
for n in range(len(li) - 1):
if li[n] != li[n + 1]:
ans += 1
print(ans)
| s = eval(input())
n = len(s)
t = s[0]
ans = 0
for i in range(n):
if s[i] != t:
ans += 1
t = s[i]
print(ans)
| false | 33.333333 | [
"-li = list(eval(input()))",
"+s = eval(input())",
"+n = len(s)",
"+t = s[0]",
"-for n in range(len(li) - 1):",
"- if li[n] != li[n + 1]:",
"+for i in range(n):",
"+ if s[i] != t:",
"+ t = s[i]"
] | false | 0.04254 | 0.041804 | 1.017607 | [
"s408870824",
"s625340058"
] |
u969190727 | p03033 | python | s311044356 | s315594273 | 1,893 | 1,691 | 125,324 | 127,856 | Accepted | Accepted | 10.67 | import sys
input = sys.stdin.readline
n,q=list(map(int,input().split()))
import heapq
S=[]
D=dict()
for i in range(n):
s,t,x=list(map(int,input().split()))
S.append((1,x,max(0,s-x)))
S.append((-1,x,max(0,t-x)))
D[x]=False
S.sort(key=lambda x:x[2])
X=[]
cur=0
for i in range(q):
d=int(eval(input()))
while cur<2*n:
a,b,c=S[cur]
if c>d:
break
else:
cur+=1
if a==1:
heapq.heappush(X,b)
D[b]=True
else:
D[b]=False
while X:
ans=heapq.heappop(X)
if D[ans]:
print(ans)
heapq.heappush(X,ans)
break
if not X:
print((-1))
| import sys
input = sys.stdin.buffer.readline
n,q=list(map(int,input().split()))
import heapq
S=[]
D=dict()
for i in range(n):
s,t,x=list(map(int,input().split()))
S.append((1,x,max(0,s-x)))
S.append((-1,x,max(0,t-x)))
D[x]=False
S.sort(key=lambda x:x[2])
X=[]
cur=0
for i in range(q):
d=int(eval(input()))
while cur<2*n:
a,b,c=S[cur]
if c>d:
break
else:
cur+=1
if a==1:
heapq.heappush(X,b)
D[b]=True
else:
D[b]=False
while X:
ans=heapq.heappop(X)
if D[ans]:
print(ans)
heapq.heappush(X,ans)
break
if not X:
print((-1))
| 35 | 35 | 632 | 639 | import sys
input = sys.stdin.readline
n, q = list(map(int, input().split()))
import heapq
S = []
D = dict()
for i in range(n):
s, t, x = list(map(int, input().split()))
S.append((1, x, max(0, s - x)))
S.append((-1, x, max(0, t - x)))
D[x] = False
S.sort(key=lambda x: x[2])
X = []
cur = 0
for i in range(q):
d = int(eval(input()))
while cur < 2 * n:
a, b, c = S[cur]
if c > d:
break
else:
cur += 1
if a == 1:
heapq.heappush(X, b)
D[b] = True
else:
D[b] = False
while X:
ans = heapq.heappop(X)
if D[ans]:
print(ans)
heapq.heappush(X, ans)
break
if not X:
print((-1))
| import sys
input = sys.stdin.buffer.readline
n, q = list(map(int, input().split()))
import heapq
S = []
D = dict()
for i in range(n):
s, t, x = list(map(int, input().split()))
S.append((1, x, max(0, s - x)))
S.append((-1, x, max(0, t - x)))
D[x] = False
S.sort(key=lambda x: x[2])
X = []
cur = 0
for i in range(q):
d = int(eval(input()))
while cur < 2 * n:
a, b, c = S[cur]
if c > d:
break
else:
cur += 1
if a == 1:
heapq.heappush(X, b)
D[b] = True
else:
D[b] = False
while X:
ans = heapq.heappop(X)
if D[ans]:
print(ans)
heapq.heappush(X, ans)
break
if not X:
print((-1))
| false | 0 | [
"-input = sys.stdin.readline",
"+input = sys.stdin.buffer.readline"
] | false | 0.043543 | 0.038908 | 1.119138 | [
"s311044356",
"s315594273"
] |
u931462344 | p03043 | python | s873833806 | s455741103 | 59 | 51 | 3,060 | 3,060 | Accepted | Accepted | 13.56 | n, k = list(map(int, input().split()))
ans = 0
for i in range(1,n+1):
tmp = i
cnt = 0
while tmp < k:
tmp *= 2
cnt += 1
ans += (1/n) * pow((1/2), cnt)
print(ans) | N, K = list(map(int, input().split()))
ans = 0
for i in range(1, N+1):
tmp = i
cnt = 0
while tmp < K:
tmp *= 2
cnt += 1
ans += (1/N)*(1/2)**cnt
print(ans) | 10 | 11 | 195 | 191 | n, k = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
tmp = i
cnt = 0
while tmp < k:
tmp *= 2
cnt += 1
ans += (1 / n) * pow((1 / 2), cnt)
print(ans)
| N, K = list(map(int, input().split()))
ans = 0
for i in range(1, N + 1):
tmp = i
cnt = 0
while tmp < K:
tmp *= 2
cnt += 1
ans += (1 / N) * (1 / 2) ** cnt
print(ans)
| false | 9.090909 | [
"-n, k = list(map(int, input().split()))",
"+N, K = list(map(int, input().split()))",
"-for i in range(1, n + 1):",
"+for i in range(1, N + 1):",
"- while tmp < k:",
"+ while tmp < K:",
"- ans += (1 / n) * pow((1 / 2), cnt)",
"+ ans += (1 / N) * (1 / 2) ** cnt"
] | false | 0.081109 | 0.070387 | 1.152331 | [
"s873833806",
"s455741103"
] |
u075012704 | p03223 | python | s959655200 | s030623736 | 635 | 237 | 61,272 | 13,696 | Accepted | Accepted | 62.68 | from collections import deque
N = int(eval(input()))
A = deque(sorted([int(eval(input())) for i in range(N)]))
X = deque([A.popleft()])
ans = 0
for i in range(N - 1):
# Aのどちらから取り出してXのどちらに入れるか
left_left = abs(X[0] - A[0])
left_right = abs(X[-1] - A[0])
right_left = abs(X[0] - A[-1])
right_right = abs(X[-1] - A[-1])
if left_left >= max(left_right, right_left, right_right):
ans += left_left
X.appendleft(A.popleft())
elif left_right >= max(left_left, right_left, right_right):
ans += left_right
X.append(A.popleft())
elif right_left >= max(left_left, left_right, right_right):
ans += right_left
X.appendleft(A.pop())
else:
ans += right_right
X.append(A.pop())
print(ans)
| N = int(eval(input()))
A = sorted([int(eval(input())) for i in range(N)])
if N % 2 == 0:
X = [-2] * ((N - 2) // 2) + [-1, 1] + [2] * ((N - 2) // 2)
ans = sum([a * x for a, x in zip(A, X)])
print(ans)
else:
X1 = [-2] * ((N - 2) // 2 + 1) + [1, 1] + [2] * ((N - 2) // 2)
X2 = [-2] * ((N - 2) // 2) + [-1, -1] + [2] * ((N - 2) // 2 + 1)
ans1 = sum([a * x for a, x in zip(A, X1)])
ans2 = sum([a * x for a, x in zip(A, X2)])
print((max(ans1, ans2)))
| 30 | 13 | 794 | 476 | from collections import deque
N = int(eval(input()))
A = deque(sorted([int(eval(input())) for i in range(N)]))
X = deque([A.popleft()])
ans = 0
for i in range(N - 1):
# Aのどちらから取り出してXのどちらに入れるか
left_left = abs(X[0] - A[0])
left_right = abs(X[-1] - A[0])
right_left = abs(X[0] - A[-1])
right_right = abs(X[-1] - A[-1])
if left_left >= max(left_right, right_left, right_right):
ans += left_left
X.appendleft(A.popleft())
elif left_right >= max(left_left, right_left, right_right):
ans += left_right
X.append(A.popleft())
elif right_left >= max(left_left, left_right, right_right):
ans += right_left
X.appendleft(A.pop())
else:
ans += right_right
X.append(A.pop())
print(ans)
| N = int(eval(input()))
A = sorted([int(eval(input())) for i in range(N)])
if N % 2 == 0:
X = [-2] * ((N - 2) // 2) + [-1, 1] + [2] * ((N - 2) // 2)
ans = sum([a * x for a, x in zip(A, X)])
print(ans)
else:
X1 = [-2] * ((N - 2) // 2 + 1) + [1, 1] + [2] * ((N - 2) // 2)
X2 = [-2] * ((N - 2) // 2) + [-1, -1] + [2] * ((N - 2) // 2 + 1)
ans1 = sum([a * x for a, x in zip(A, X1)])
ans2 = sum([a * x for a, x in zip(A, X2)])
print((max(ans1, ans2)))
| false | 56.666667 | [
"-from collections import deque",
"-",
"-A = deque(sorted([int(eval(input())) for i in range(N)]))",
"-X = deque([A.popleft()])",
"-ans = 0",
"-for i in range(N - 1):",
"- # Aのどちらから取り出してXのどちらに入れるか",
"- left_left = abs(X[0] - A[0])",
"- left_right = abs(X[-1] - A[0])",
"- right_left = a... | false | 0.044688 | 0.14573 | 0.30665 | [
"s959655200",
"s030623736"
] |
u970197315 | p02820 | python | s020800873 | s846095935 | 118 | 105 | 13,428 | 3,444 | Accepted | Accepted | 11.02 | # ABC149 D
si = lambda: eval(input())
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
n,k=nm()
r,s,p=nm()
t=si()
l=[[] for i in range(k)]
ans=0
for i in range(n):
j=(i+1)%k
l[j].append(t[i:i+1])
same_flg=False
for ll in l:
cur_str=''
for lll in ll:
if cur_str=='':
if lll=='p':
ans+=s
elif lll=='r':
ans+=p
elif lll=='s':
ans+=r
cur_str=lll
same_flg=True
continue
if lll==cur_str:
# 足さない
cur_str=lll
if same_flg==True:
same_flg=False
elif same_flg==False:
if lll=='p':
ans+=s
elif lll=='r':
ans+=p
elif lll=='s':
ans+=r
same_flg=True
pass
else:
if lll=='p':
ans+=s
elif lll=='r':
ans+=p
elif lll=='s':
ans+=r
cur_str=lll
same_flg=True
print(ans) | n,k=list(map(int,input().split()))
r,s,p=list(map(int,input().split()))
t=eval(input())
ans=0
S=""
for i in range(n):
if i-k>=0:
if t[i]==t[i-k]:
if t[i]=="r":
if S[i-k]=="p":
S+="r"
elif S[i-k]=="r":
S+="p"
ans+=p
elif t[i]=="s":
if S[i-k]=="r":
S+="s"
elif S[i-k]=="s":
S+="r"
ans+=r
elif t[i]=="p":
if S[i-k]=="s":
S+="p"
elif S[i-k]=="p":
S+="s"
ans+=s
continue
if t[i]=="r":
ans+=p
S+="p"
elif t[i]=="s":
ans+=r
S+="r"
elif t[i]=="p":
ans+=s
S+="s"
print(ans) | 54 | 38 | 1,227 | 682 | # ABC149 D
si = lambda: eval(input())
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
n, k = nm()
r, s, p = nm()
t = si()
l = [[] for i in range(k)]
ans = 0
for i in range(n):
j = (i + 1) % k
l[j].append(t[i : i + 1])
same_flg = False
for ll in l:
cur_str = ""
for lll in ll:
if cur_str == "":
if lll == "p":
ans += s
elif lll == "r":
ans += p
elif lll == "s":
ans += r
cur_str = lll
same_flg = True
continue
if lll == cur_str:
# 足さない
cur_str = lll
if same_flg == True:
same_flg = False
elif same_flg == False:
if lll == "p":
ans += s
elif lll == "r":
ans += p
elif lll == "s":
ans += r
same_flg = True
pass
else:
if lll == "p":
ans += s
elif lll == "r":
ans += p
elif lll == "s":
ans += r
cur_str = lll
same_flg = True
print(ans)
| n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
ans = 0
S = ""
for i in range(n):
if i - k >= 0:
if t[i] == t[i - k]:
if t[i] == "r":
if S[i - k] == "p":
S += "r"
elif S[i - k] == "r":
S += "p"
ans += p
elif t[i] == "s":
if S[i - k] == "r":
S += "s"
elif S[i - k] == "s":
S += "r"
ans += r
elif t[i] == "p":
if S[i - k] == "s":
S += "p"
elif S[i - k] == "p":
S += "s"
ans += s
continue
if t[i] == "r":
ans += p
S += "p"
elif t[i] == "s":
ans += r
S += "r"
elif t[i] == "p":
ans += s
S += "s"
print(ans)
| false | 29.62963 | [
"-# ABC149 D",
"-si = lambda: eval(input())",
"-ni = lambda: int(eval(input()))",
"-nm = lambda: list(map(int, input().split()))",
"-nl = lambda: list(map(int, input().split()))",
"-n, k = nm()",
"-r, s, p = nm()",
"-t = si()",
"-l = [[] for i in range(k)]",
"+n, k = list(map(int, input().split())... | false | 0.036748 | 0.036748 | 1.000008 | [
"s020800873",
"s846095935"
] |
u991567869 | p03909 | python | s734212253 | s733200319 | 29 | 24 | 9,152 | 9,180 | Accepted | Accepted | 17.24 | h, w = list(map(int, input().split()))
s = []
for i in range(h):
S = list(input().split())
s.append(S)
for i in range(h):
for j in range(w):
if s[i][j] == "snuke":
l = chr(ord("A") + j)
print((l + str(i + 1)))
exit() | h, w = list(map(int, input().split()))
for i in range(h):
s = input().split()
for j in range(w):
if s[j] == "snuke":
l = chr(ord("A") + j)
print((l + str(i + 1)))
exit() | 13 | 9 | 278 | 222 | h, w = list(map(int, input().split()))
s = []
for i in range(h):
S = list(input().split())
s.append(S)
for i in range(h):
for j in range(w):
if s[i][j] == "snuke":
l = chr(ord("A") + j)
print((l + str(i + 1)))
exit()
| h, w = list(map(int, input().split()))
for i in range(h):
s = input().split()
for j in range(w):
if s[j] == "snuke":
l = chr(ord("A") + j)
print((l + str(i + 1)))
exit()
| false | 30.769231 | [
"-s = []",
"- S = list(input().split())",
"- s.append(S)",
"-for i in range(h):",
"+ s = input().split()",
"- if s[i][j] == \"snuke\":",
"+ if s[j] == \"snuke\":"
] | false | 0.142125 | 0.03961 | 3.588113 | [
"s734212253",
"s733200319"
] |
u981931040 | p04044 | python | s947926239 | s789107177 | 20 | 17 | 3,060 | 3,060 | Accepted | Accepted | 15 | N ,L = list(map(int , input().split()))
s=sorted([eval(input()) for i in range(N)])
print(("".join(s)))
| N, L = list(map(int,input().split()))
S = list(eval(input()) for _ in range(N))
S.sort()
print(("".join(S))) | 4 | 4 | 94 | 97 | N, L = list(map(int, input().split()))
s = sorted([eval(input()) for i in range(N)])
print(("".join(s)))
| N, L = list(map(int, input().split()))
S = list(eval(input()) for _ in range(N))
S.sort()
print(("".join(S)))
| false | 0 | [
"-s = sorted([eval(input()) for i in range(N)])",
"-print((\"\".join(s)))",
"+S = list(eval(input()) for _ in range(N))",
"+S.sort()",
"+print((\"\".join(S)))"
] | false | 0.066738 | 0.07047 | 0.947045 | [
"s947926239",
"s789107177"
] |
u699089116 | p02780 | python | s819067999 | s008562102 | 241 | 126 | 75,784 | 31,892 | Accepted | Accepted | 47.72 | n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
p = list([x * (x+1) /2 /x for x in p])
for i in range(1, n):
p[i] = p[i-1] + p[i]
m = p[k-1]
for i in range(k, n):
a = p[i] - p[i-k]
if m < a:
m = a
print(m) | from itertools import accumulate
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
A = list(accumulate(P))
largest = A[K-1]
point = 0
for i in range(K, N):
if largest < A[i] - A[i-K]:
largest = A[i] - A[i-K]
point = i
ans = 0
for j in range(point - K + 1, point+1):
p = P[j]
ans += (((p + 1) * p) / 2) / p
print(ans) | 15 | 19 | 269 | 385 | n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
p = list([x * (x + 1) / 2 / x for x in p])
for i in range(1, n):
p[i] = p[i - 1] + p[i]
m = p[k - 1]
for i in range(k, n):
a = p[i] - p[i - k]
if m < a:
m = a
print(m)
| from itertools import accumulate
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
A = list(accumulate(P))
largest = A[K - 1]
point = 0
for i in range(K, N):
if largest < A[i] - A[i - K]:
largest = A[i] - A[i - K]
point = i
ans = 0
for j in range(point - K + 1, point + 1):
p = P[j]
ans += (((p + 1) * p) / 2) / p
print(ans)
| false | 21.052632 | [
"-n, k = list(map(int, input().split()))",
"-p = list(map(int, input().split()))",
"-p = list([x * (x + 1) / 2 / x for x in p])",
"-for i in range(1, n):",
"- p[i] = p[i - 1] + p[i]",
"-m = p[k - 1]",
"-for i in range(k, n):",
"- a = p[i] - p[i - k]",
"- if m < a:",
"- m = a",
"-... | false | 0.047052 | 0.047049 | 1.000061 | [
"s819067999",
"s008562102"
] |
u279493135 | p03687 | python | s011844494 | s027106303 | 55 | 38 | 5,712 | 5,200 | Accepted | Accepted | 30.91 | 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
s = eval(input())
N = len(s)
se = set(s)
ans = INF
for x in se: # xとの距離を調べる
tmp = 0
ans = min(ans, max([len(l) for l in s.split(x)]))
print(ans)
| 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
s = eval(input())
ans = INF
for x in set(s): # xとの距離を調べる
ans = min(ans, max([len(l) for l in s.split(x)]))
print(ans)
| 29 | 26 | 925 | 894 | 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
s = eval(input())
N = len(s)
se = set(s)
ans = INF
for x in se: # xとの距離を調べる
tmp = 0
ans = min(ans, max([len(l) for l in s.split(x)]))
print(ans)
| 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
s = eval(input())
ans = INF
for x in set(s): # xとの距離を調べる
ans = min(ans, max([len(l) for l in s.split(x)]))
print(ans)
| false | 10.344828 | [
"-N = len(s)",
"-se = set(s)",
"-for x in se: # xとの距離を調べる",
"- tmp = 0",
"+for x in set(s): # xとの距離を調べる"
] | false | 0.132768 | 0.041873 | 3.170733 | [
"s011844494",
"s027106303"
] |
u231189826 | p02721 | python | s294220246 | s027932446 | 780 | 390 | 32,388 | 22,396 | Accepted | Accepted | 50 | import copy
N,K,C = list(map(int, input().split()))
S = list(eval(input()))
count = 0
mae = [0]*K
ushiro = [0]*K
hi = 0
youso = 0
S_copy = copy.deepcopy(S)
while True:
if S_copy[hi] == 'o':
mae[youso] = hi+1
youso += 1
if youso == K:
break
for i in range(C):
if hi+1+i <= N-1:
S_copy[hi+1+i] = 'x'
hi += 1
hi = 0
youso = 0
S_copy = copy.deepcopy(S)
S_copy.reverse()
while True:
if S_copy[hi] == 'o':
ushiro[youso] = hi-1
youso += 1
if youso == K:
break
for i in range(C):
if hi+1+i <= N-1:
S_copy[hi+1+i] = 'x'
hi += 1
ushiro = list([N-x-1 for x in ushiro])
ushiro.reverse()
ans = []
for j in range(len(mae)):
if mae[j] == ushiro[j]:
ans.append(mae[j])
if ans:
for j in range(len(ans)):
print((ans[j]))
| import copy
N,K,C = list(map(int, input().split()))
S = list(eval(input()))
mae = [0]*K
ushiro = [0]*K
hi = 0
youso = 0
while True:
if S[hi] == 'o':
mae[youso] = hi+1
youso += 1
if youso == K:
break
hi += C
hi += 1
hi = N-1
youso = 0
while True:
if S[hi] == 'o':
ushiro[youso] = hi+1
youso += 1
if youso == K:
break
hi -= C
hi -= 1
ushiro.reverse()
for j in range(len(mae)):
if mae[j] == ushiro[j]:
print((mae[j]))
| 57 | 42 | 955 | 577 | import copy
N, K, C = list(map(int, input().split()))
S = list(eval(input()))
count = 0
mae = [0] * K
ushiro = [0] * K
hi = 0
youso = 0
S_copy = copy.deepcopy(S)
while True:
if S_copy[hi] == "o":
mae[youso] = hi + 1
youso += 1
if youso == K:
break
for i in range(C):
if hi + 1 + i <= N - 1:
S_copy[hi + 1 + i] = "x"
hi += 1
hi = 0
youso = 0
S_copy = copy.deepcopy(S)
S_copy.reverse()
while True:
if S_copy[hi] == "o":
ushiro[youso] = hi - 1
youso += 1
if youso == K:
break
for i in range(C):
if hi + 1 + i <= N - 1:
S_copy[hi + 1 + i] = "x"
hi += 1
ushiro = list([N - x - 1 for x in ushiro])
ushiro.reverse()
ans = []
for j in range(len(mae)):
if mae[j] == ushiro[j]:
ans.append(mae[j])
if ans:
for j in range(len(ans)):
print((ans[j]))
| import copy
N, K, C = list(map(int, input().split()))
S = list(eval(input()))
mae = [0] * K
ushiro = [0] * K
hi = 0
youso = 0
while True:
if S[hi] == "o":
mae[youso] = hi + 1
youso += 1
if youso == K:
break
hi += C
hi += 1
hi = N - 1
youso = 0
while True:
if S[hi] == "o":
ushiro[youso] = hi + 1
youso += 1
if youso == K:
break
hi -= C
hi -= 1
ushiro.reverse()
for j in range(len(mae)):
if mae[j] == ushiro[j]:
print((mae[j]))
| false | 26.315789 | [
"-count = 0",
"-S_copy = copy.deepcopy(S)",
"- if S_copy[hi] == \"o\":",
"+ if S[hi] == \"o\":",
"- for i in range(C):",
"- if hi + 1 + i <= N - 1:",
"- S_copy[hi + 1 + i] = \"x\"",
"+ hi += C",
"-hi = 0",
"+hi = N - 1",
"-S_copy = copy.deepcopy(S)",... | false | 0.044515 | 0.042614 | 1.044592 | [
"s294220246",
"s027932446"
] |
u633068244 | p00112 | python | s417437011 | s032928741 | 960 | 40 | 4,972 | 4,976 | Accepted | Accepted | 95.83 | while 1:
n = eval(input())
if n == 0: break
que = sorted([int(input()) for i in range(n)])
print(sum([sum(que[:i]) for i in range(1,n)])) | while 1:
n = eval(input())
if n == 0: break
q = sorted([int(input()) for i in range(n)])
t = [0]*n
for i in range(1,n):
t[i] = t[i-1] + q[i-1]
print(sum(t)) | 5 | 8 | 142 | 168 | while 1:
n = eval(input())
if n == 0:
break
que = sorted([int(input()) for i in range(n)])
print(sum([sum(que[:i]) for i in range(1, n)]))
| while 1:
n = eval(input())
if n == 0:
break
q = sorted([int(input()) for i in range(n)])
t = [0] * n
for i in range(1, n):
t[i] = t[i - 1] + q[i - 1]
print(sum(t))
| false | 37.5 | [
"- que = sorted([int(input()) for i in range(n)])",
"- print(sum([sum(que[:i]) for i in range(1, n)]))",
"+ q = sorted([int(input()) for i in range(n)])",
"+ t = [0] * n",
"+ for i in range(1, n):",
"+ t[i] = t[i - 1] + q[i - 1]",
"+ print(sum(t))"
] | false | 0.10335 | 0.038511 | 2.68365 | [
"s417437011",
"s032928741"
] |
u169350228 | p02665 | python | s858159143 | s031819425 | 411 | 111 | 99,996 | 87,064 | Accepted | Accepted | 72.99 | import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
def main():
n = int(ipt())
a = [int(i) for i in ipt().split()]
if n == 0 and a[0] == 0:
print((-1))
exit()
elif n == 0 and a[0] == 1:
print((1))
exit()
elif n == 0 and a[0] > 1:
print((-1))
exit()
suma = sum(a)
ans = a[0]
can = 1
for i,ai in enumerate(a):
if ai > can:
print((-1))
exit()
suma -= ai
ans += can
if (can-ai)*2 >= suma:
can = suma
else:
can = (can-ai)*2
print(ans)
return
if __name__ == '__main__':
main()
| import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
def main():
n = int(ipt())
a = [int(i) for i in ipt().split()]
suma = sum(a)
ans = 0
can = 1
for i,ai in enumerate(a):
if ai > can:
print((-1))
exit()
suma -= ai
ans += can
if (can-ai)*2 >= suma:
can = suma
else:
can = (can-ai)*2
print(ans)
return
if __name__ == '__main__':
main()
| 46 | 37 | 913 | 713 | import math
# import numpy as np
import queue
from collections import deque, defaultdict
import heapq
from sys import stdin, setrecursionlimit
# from scipy.sparse.csgraph import dijkstra
# from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
def main():
n = int(ipt())
a = [int(i) for i in ipt().split()]
if n == 0 and a[0] == 0:
print((-1))
exit()
elif n == 0 and a[0] == 1:
print((1))
exit()
elif n == 0 and a[0] > 1:
print((-1))
exit()
suma = sum(a)
ans = a[0]
can = 1
for i, ai in enumerate(a):
if ai > can:
print((-1))
exit()
suma -= ai
ans += can
if (can - ai) * 2 >= suma:
can = suma
else:
can = (can - ai) * 2
print(ans)
return
if __name__ == "__main__":
main()
| import math
# import numpy as np
import queue
from collections import deque, defaultdict
import heapq
from sys import stdin, setrecursionlimit
# from scipy.sparse.csgraph import dijkstra
# from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
def main():
n = int(ipt())
a = [int(i) for i in ipt().split()]
suma = sum(a)
ans = 0
can = 1
for i, ai in enumerate(a):
if ai > can:
print((-1))
exit()
suma -= ai
ans += can
if (can - ai) * 2 >= suma:
can = suma
else:
can = (can - ai) * 2
print(ans)
return
if __name__ == "__main__":
main()
| false | 19.565217 | [
"- if n == 0 and a[0] == 0:",
"- print((-1))",
"- exit()",
"- elif n == 0 and a[0] == 1:",
"- print((1))",
"- exit()",
"- elif n == 0 and a[0] > 1:",
"- print((-1))",
"- exit()",
"- ans = a[0]",
"+ ans = 0"
] | false | 0.037186 | 0.043112 | 0.862548 | [
"s858159143",
"s031819425"
] |
u192154323 | p02695 | python | s179548525 | s988822385 | 1,184 | 578 | 22,928 | 9,228 | Accepted | Accepted | 51.18 | import itertools
n,m,q = list(map(int,input().split()))
num_ls = [[0,0,0,0] for _ in range(q)]
for i in range(q):
num_ls[i] = list(map(int,input().split()))
a_base = [i for i in range(1,m+1)]
a_ls = []
for A in itertools.combinations_with_replacement(a_base, n):
istarget = True
for i in range(n-1):
if A[i] > A[i+1]:
istarget = False
if istarget:
a_ls.append(list(A))
ans = 0
for A in a_ls:
value_of_A = 0
for a,b,c,d in num_ls:
if A[b-1] - A[a-1] == c:
value_of_A += d
ans = max(ans, value_of_A)
print(ans) | N,M,Q = list(map(int,input().split()))
req_ls = []
l_ind_ls = [0] * Q
r_ind_ls = [0] * Q
diff_ls = [0] * Q
point_ls = [0] * Q
for i in range(Q):
l_ind_ls[i], r_ind_ls[i], diff_ls[i], point_ls[i] = list(map(int, input().split()))
l_ind_ls[i] -= 1
r_ind_ls[i] -= 1
def score(ls):
tmp = 0
for l_ind, r_ind, diff, point in zip(l_ind_ls,r_ind_ls,diff_ls,point_ls):
if ls[r_ind] - ls[l_ind] == diff:
tmp += point
return tmp
def dfs(ls):
if len(ls) == N:
return score(ls)
res = 0
last = ls[-1] if len(ls) > 0 else 1
for nex in range(last, M+1):
ls.append(nex)
res = max(res, dfs(ls))
ls.pop()
return res
print((dfs([])))
| 23 | 31 | 601 | 730 | import itertools
n, m, q = list(map(int, input().split()))
num_ls = [[0, 0, 0, 0] for _ in range(q)]
for i in range(q):
num_ls[i] = list(map(int, input().split()))
a_base = [i for i in range(1, m + 1)]
a_ls = []
for A in itertools.combinations_with_replacement(a_base, n):
istarget = True
for i in range(n - 1):
if A[i] > A[i + 1]:
istarget = False
if istarget:
a_ls.append(list(A))
ans = 0
for A in a_ls:
value_of_A = 0
for a, b, c, d in num_ls:
if A[b - 1] - A[a - 1] == c:
value_of_A += d
ans = max(ans, value_of_A)
print(ans)
| N, M, Q = list(map(int, input().split()))
req_ls = []
l_ind_ls = [0] * Q
r_ind_ls = [0] * Q
diff_ls = [0] * Q
point_ls = [0] * Q
for i in range(Q):
l_ind_ls[i], r_ind_ls[i], diff_ls[i], point_ls[i] = list(map(int, input().split()))
l_ind_ls[i] -= 1
r_ind_ls[i] -= 1
def score(ls):
tmp = 0
for l_ind, r_ind, diff, point in zip(l_ind_ls, r_ind_ls, diff_ls, point_ls):
if ls[r_ind] - ls[l_ind] == diff:
tmp += point
return tmp
def dfs(ls):
if len(ls) == N:
return score(ls)
res = 0
last = ls[-1] if len(ls) > 0 else 1
for nex in range(last, M + 1):
ls.append(nex)
res = max(res, dfs(ls))
ls.pop()
return res
print((dfs([])))
| false | 25.806452 | [
"-import itertools",
"+N, M, Q = list(map(int, input().split()))",
"+req_ls = []",
"+l_ind_ls = [0] * Q",
"+r_ind_ls = [0] * Q",
"+diff_ls = [0] * Q",
"+point_ls = [0] * Q",
"+for i in range(Q):",
"+ l_ind_ls[i], r_ind_ls[i], diff_ls[i], point_ls[i] = list(map(int, input().split()))",
"+ l_i... | false | 0.247594 | 0.119973 | 2.06374 | [
"s179548525",
"s988822385"
] |
u375616706 | p03722 | python | s105976148 | s807868248 | 1,958 | 621 | 3,572 | 3,308 | Accepted | Accepted | 68.28 | import sys
def input(): return sys.stdin.readline().strip()
N, M = (list)(list(map(int, input().split())))
edge = []
for _ in range(M):
edge.append((list)(list(map(int, input().split()))))
inf = 10**15
d = [inf]*(N+1)
d[1] = 0
ans = inf
for i in range(N):
update = False
for a, b, c in edge:
c = -c
new_d = d[a]+c
if d[a] != inf and d[b] > new_d:
d[b] = new_d
update = True
if not update:
break
neg = [False]*(N+1)
for i in range(N):
for a, b, c in edge:
c = -c
new_d = d[a]+c
if d[a] != inf and d[b] > new_d:
d[b] = new_d
neg[b] = True
if neg[a]:
neg[b] = True
if neg[-1]:
print('inf')
else:
print((-d[-1]))
| # -*- coding: utf-8 -*-
"""
・ベルマンフォード
"""
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
N, M = list(map(int, input().split()))
edges = [None] * M
for i in range(M):
a, b, c = list(map(int, input().split()))
# 0-indexed
# コストの正負を逆転させれば最短経路問題として処理できる
edges[i] = (a-1, b-1, -c)
def bellman_ford(N, edges, start):
# 頂点[ある始点からの最短距離]
# (経路自体を知りたい時はここに前の頂点も持たせる)
verts = [float('inf')] * N
verts[start] = 0
# 各辺によるコストの置き換えを頂点数N-1回繰り返す
for i in range(N-1):
for src, dest, cost in edges:
verts[dest] = min(verts[src] + cost, verts[dest])
# 無限に減らせる場所がないか確認
for src, dest, cost in edges:
if verts[src] + cost < verts[dest]:
verts[dest] = verts[src] + cost
if dest == N-1:
# 頂点Nがそれに該当していたら空リストを返却
return []
# 問題なければ頂点リストを返却
return verts
verts = bellman_ford(N, edges, 0)
if not verts:
print('inf')
else:
# 正負を戻して出力
print((-verts[N-1]))
| 45 | 44 | 802 | 1,056 | import sys
def input():
return sys.stdin.readline().strip()
N, M = (list)(list(map(int, input().split())))
edge = []
for _ in range(M):
edge.append((list)(list(map(int, input().split()))))
inf = 10**15
d = [inf] * (N + 1)
d[1] = 0
ans = inf
for i in range(N):
update = False
for a, b, c in edge:
c = -c
new_d = d[a] + c
if d[a] != inf and d[b] > new_d:
d[b] = new_d
update = True
if not update:
break
neg = [False] * (N + 1)
for i in range(N):
for a, b, c in edge:
c = -c
new_d = d[a] + c
if d[a] != inf and d[b] > new_d:
d[b] = new_d
neg[b] = True
if neg[a]:
neg[b] = True
if neg[-1]:
print("inf")
else:
print((-d[-1]))
| # -*- coding: utf-8 -*-
"""
・ベルマンフォード
"""
import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10**9)
N, M = list(map(int, input().split()))
edges = [None] * M
for i in range(M):
a, b, c = list(map(int, input().split()))
# 0-indexed
# コストの正負を逆転させれば最短経路問題として処理できる
edges[i] = (a - 1, b - 1, -c)
def bellman_ford(N, edges, start):
# 頂点[ある始点からの最短距離]
# (経路自体を知りたい時はここに前の頂点も持たせる)
verts = [float("inf")] * N
verts[start] = 0
# 各辺によるコストの置き換えを頂点数N-1回繰り返す
for i in range(N - 1):
for src, dest, cost in edges:
verts[dest] = min(verts[src] + cost, verts[dest])
# 無限に減らせる場所がないか確認
for src, dest, cost in edges:
if verts[src] + cost < verts[dest]:
verts[dest] = verts[src] + cost
if dest == N - 1:
# 頂点Nがそれに該当していたら空リストを返却
return []
# 問題なければ頂点リストを返却
return verts
verts = bellman_ford(N, edges, 0)
if not verts:
print("inf")
else:
# 正負を戻して出力
print((-verts[N - 1]))
| false | 2.222222 | [
"+# -*- coding: utf-8 -*-",
"+\"\"\"",
"+・ベルマンフォード",
"+\"\"\"",
"-N, M = (list)(list(map(int, input().split())))",
"-edge = []",
"-for _ in range(M):",
"- edge.append((list)(list(map(int, input().split()))))",
"-inf = 10**15",
"-d = [inf] * (N + 1)",
"-d[1] = 0",
"-ans = inf",
"-for i in ... | false | 0.065431 | 0.044631 | 1.466062 | [
"s105976148",
"s807868248"
] |
u127499732 | p03163 | python | s751142390 | s189246643 | 382 | 285 | 118,512 | 40,048 | Accepted | Accepted | 25.39 | def main():
from collections import deque
n,w=list(map(int,input().split()))
item=deque([list(map(int,input().split())) for _ in range(n)])
DP=[[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
itemNow=item.popleft()
weight=itemNow[0]
value=itemNow[1]
for j in range(w+1):
if j<weight:
DP[i][j]=DP[i-1][j]
else:
DP[i][j]=max(DP[i-1][j],DP[i-1][j-weight]+value)
print((DP[n][w]))
if __name__=="__main__":
main() | def main():
import sys
num,capacity=list(map(int,input().split()))
items=tuple([list(map(int,sys.stdin.readline().split())) for _ in range(num)])
DP=[-1]*(capacity+1)
DP[0]=0
for item in items:
weight=item[0]
value=item[1]
left=capacity-weight
for i in range(left,-1,-1):
if DP[i]<0:
continue
DP[i+weight]=max(DP[i]+value,DP[i+weight])
print((max(DP)))
if __name__=="__main__":
main() | 19 | 18 | 498 | 452 | def main():
from collections import deque
n, w = list(map(int, input().split()))
item = deque([list(map(int, input().split())) for _ in range(n)])
DP = [[0] * (w + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
itemNow = item.popleft()
weight = itemNow[0]
value = itemNow[1]
for j in range(w + 1):
if j < weight:
DP[i][j] = DP[i - 1][j]
else:
DP[i][j] = max(DP[i - 1][j], DP[i - 1][j - weight] + value)
print((DP[n][w]))
if __name__ == "__main__":
main()
| def main():
import sys
num, capacity = list(map(int, input().split()))
items = tuple([list(map(int, sys.stdin.readline().split())) for _ in range(num)])
DP = [-1] * (capacity + 1)
DP[0] = 0
for item in items:
weight = item[0]
value = item[1]
left = capacity - weight
for i in range(left, -1, -1):
if DP[i] < 0:
continue
DP[i + weight] = max(DP[i] + value, DP[i + weight])
print((max(DP)))
if __name__ == "__main__":
main()
| false | 5.263158 | [
"- from collections import deque",
"+ import sys",
"- n, w = list(map(int, input().split()))",
"- item = deque([list(map(int, input().split())) for _ in range(n)])",
"- DP = [[0] * (w + 1) for _ in range(n + 1)]",
"- for i in range(1, n + 1):",
"- itemNow = item.popleft()",
"-... | false | 0.040429 | 0.142317 | 0.284079 | [
"s751142390",
"s189246643"
] |
u638456847 | p02689 | python | s327310458 | s624720829 | 217 | 154 | 44,920 | 30,268 | Accepted | Accepted | 29.03 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N,M = list(map(int, readline().split()))
H = [int(i) for i in readline().split()]
ab = list(map(int, read().split()))
E = [[] for _ in range(N+1)]
for i, (a, b) in enumerate(zip(*[iter(ab)]*2)):
E[a].append(b)
E[b].append(a)
ans = 0
for i in range(1,N+1):
flag = True
for v in E[i]:
if H[i-1] > H[v-1]:
continue
else:
flag = False
break
if flag:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N,M = list(map(int, readline().split()))
H = [int(i) for i in readline().split()]
ab = list(map(int, read().split()))
E = [0] * N
for i, (a, b) in enumerate(zip(*[iter(ab)]*2)):
if H[b-1] > E[a-1]:
E[a-1] = H[b-1]
if H[a-1] > E[b-1]:
E[b-1] = H[a-1]
ans = 0
for i,h in enumerate(H):
if h > E[i]:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 32 | 27 | 696 | 577 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N, M = list(map(int, readline().split()))
H = [int(i) for i in readline().split()]
ab = list(map(int, read().split()))
E = [[] for _ in range(N + 1)]
for i, (a, b) in enumerate(zip(*[iter(ab)] * 2)):
E[a].append(b)
E[b].append(a)
ans = 0
for i in range(1, N + 1):
flag = True
for v in E[i]:
if H[i - 1] > H[v - 1]:
continue
else:
flag = False
break
if flag:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N, M = list(map(int, readline().split()))
H = [int(i) for i in readline().split()]
ab = list(map(int, read().split()))
E = [0] * N
for i, (a, b) in enumerate(zip(*[iter(ab)] * 2)):
if H[b - 1] > E[a - 1]:
E[a - 1] = H[b - 1]
if H[a - 1] > E[b - 1]:
E[b - 1] = H[a - 1]
ans = 0
for i, h in enumerate(H):
if h > E[i]:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 15.625 | [
"- E = [[] for _ in range(N + 1)]",
"+ E = [0] * N",
"- E[a].append(b)",
"- E[b].append(a)",
"+ if H[b - 1] > E[a - 1]:",
"+ E[a - 1] = H[b - 1]",
"+ if H[a - 1] > E[b - 1]:",
"+ E[b - 1] = H[a - 1]",
"- for i in range(1, N + 1):",
"- ... | false | 0.055496 | 0.041719 | 1.330244 | [
"s327310458",
"s624720829"
] |
u760569096 | p02585 | python | s016039883 | s132281743 | 489 | 427 | 80,996 | 78,812 | Accepted | Accepted | 12.68 | n,k = list(map(int, input().split()))
p = list(map(int, input().split()))
c = list(map(int, input().split()))
r = -10**9
for i in range(n):
ans=c[i]
e =[ans]
f = i
a = 1
while a<k:
i = p[i]-1
if i == f:
break
a+=1
ans+=c[i]
e.append(ans)
if e[-1]>0 and a<k:
w = k%len(e)
if w!=0:
y = k//len(e)*e[-1]+max(e[:w])
else:
y =( k//len(e)-1)*e[-1]+max(e)
g=y
else:
g=max(e)
r = max(r,g)
print(r) | n,k = list(map(int, input().split()))
p = list(map(int, input().split()))
c = list(map(int, input().split()))
g = []
for i in range(n):
ans=c[i]
e =[ans]
f = i
a = 1
while a<k:
i = p[i]-1
if i == f:
break
a+=1
ans+=c[i]
e.append(ans)
if e[-1]>0 and a<k:
w = k%len(e)
if w!=0:
y = k//len(e)*e[-1]+max(e[:w])
else:
y =( k//len(e)-1)*e[-1]+max(e)
g.append(y)
else:
g.append(max(e))
print((max(g)))
| 27 | 26 | 483 | 485 | n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
c = list(map(int, input().split()))
r = -(10**9)
for i in range(n):
ans = c[i]
e = [ans]
f = i
a = 1
while a < k:
i = p[i] - 1
if i == f:
break
a += 1
ans += c[i]
e.append(ans)
if e[-1] > 0 and a < k:
w = k % len(e)
if w != 0:
y = k // len(e) * e[-1] + max(e[:w])
else:
y = (k // len(e) - 1) * e[-1] + max(e)
g = y
else:
g = max(e)
r = max(r, g)
print(r)
| n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
c = list(map(int, input().split()))
g = []
for i in range(n):
ans = c[i]
e = [ans]
f = i
a = 1
while a < k:
i = p[i] - 1
if i == f:
break
a += 1
ans += c[i]
e.append(ans)
if e[-1] > 0 and a < k:
w = k % len(e)
if w != 0:
y = k // len(e) * e[-1] + max(e[:w])
else:
y = (k // len(e) - 1) * e[-1] + max(e)
g.append(y)
else:
g.append(max(e))
print((max(g)))
| false | 3.703704 | [
"-r = -(10**9)",
"+g = []",
"- g = y",
"+ g.append(y)",
"- g = max(e)",
"- r = max(r, g)",
"-print(r)",
"+ g.append(max(e))",
"+print((max(g)))"
] | false | 0.042239 | 0.042115 | 1.002955 | [
"s016039883",
"s132281743"
] |
u299791633 | p02683 | python | s798523519 | s395248324 | 105 | 96 | 9,264 | 9,344 | Accepted | Accepted | 8.57 | import itertools
n, m, x = list(map(int, input().split()))
books=[]
results=[]
for i in range(n):
books.append(list(map(int, input().split())))
# 全ての本を買ってもXwo満たせないアルゴリズムがあるか検査
for i in range(m):
skill=0
for j in books:
skill+=j[i+1]
if skill<x:
print((-1))
exit()
# 本の組み合わせをためす
index=[]
for i in range(n):
index.append(i)
patarns=[]
for i in range(1,n+1):
patarns.append(itertools.combinations(index,i))
#print(list(a))
# 全パターン検査
for patarn in patarns:
#flg=True
# ある本の組み合わせの時検査
for bk_indexies in patarn:
# すべてのアルゴリズム
flg=True
for arg in range(m):
point=0
money=0
for bk_index in bk_indexies:
# アルゴリズムargの合計得点
point+=books[bk_index][arg+1]
money+=books[bk_index][0]
#print(arg,money,point)
if point<x:
flg=False
if flg:
#print(money,list(patarn))
results.append(money)
#print(results)
print((min(results)))
| import itertools
n, m, x = list(map(int, input().split()))
result=[]
books=[]
tmp=[]
for i in range(n):
books.append(list(map(int, input().split())))
tmp.append(i)
# 参考書の選択パターン作成
patterns=[]
for i in range(n):
patterns.append(itertools.combinations(tmp,i+1))
# 全ての参考書を購入しても条件を満たせないときは-1
for arg in range(m):
point=0
for book in books:
point+=book[arg+1]
if point<x:
print((-1))
exit()
# すべての参考書のパターン
for pattern in patterns:
# ある参考書のパターン
for bks in pattern:
flg=True
# 各アルゴリズムの時の理解度合計
for i in range(m):
# あるアルゴリズムのときの点数とトータルコスト
cost=0
point=0
for bk in bks:
cost+=books[bk][0]
point+=books[bk][i+1]
if point < x:
# あるアルゴリズムで条件を満たさない
flg=False
if flg==True:
result.append(cost)
print((min(result))) | 46 | 41 | 1,095 | 961 | import itertools
n, m, x = list(map(int, input().split()))
books = []
results = []
for i in range(n):
books.append(list(map(int, input().split())))
# 全ての本を買ってもXwo満たせないアルゴリズムがあるか検査
for i in range(m):
skill = 0
for j in books:
skill += j[i + 1]
if skill < x:
print((-1))
exit()
# 本の組み合わせをためす
index = []
for i in range(n):
index.append(i)
patarns = []
for i in range(1, n + 1):
patarns.append(itertools.combinations(index, i))
# print(list(a))
# 全パターン検査
for patarn in patarns:
# flg=True
# ある本の組み合わせの時検査
for bk_indexies in patarn:
# すべてのアルゴリズム
flg = True
for arg in range(m):
point = 0
money = 0
for bk_index in bk_indexies:
# アルゴリズムargの合計得点
point += books[bk_index][arg + 1]
money += books[bk_index][0]
# print(arg,money,point)
if point < x:
flg = False
if flg:
# print(money,list(patarn))
results.append(money)
# print(results)
print((min(results)))
| import itertools
n, m, x = list(map(int, input().split()))
result = []
books = []
tmp = []
for i in range(n):
books.append(list(map(int, input().split())))
tmp.append(i)
# 参考書の選択パターン作成
patterns = []
for i in range(n):
patterns.append(itertools.combinations(tmp, i + 1))
# 全ての参考書を購入しても条件を満たせないときは-1
for arg in range(m):
point = 0
for book in books:
point += book[arg + 1]
if point < x:
print((-1))
exit()
# すべての参考書のパターン
for pattern in patterns:
# ある参考書のパターン
for bks in pattern:
flg = True
# 各アルゴリズムの時の理解度合計
for i in range(m):
# あるアルゴリズムのときの点数とトータルコスト
cost = 0
point = 0
for bk in bks:
cost += books[bk][0]
point += books[bk][i + 1]
if point < x:
# あるアルゴリズムで条件を満たさない
flg = False
if flg == True:
result.append(cost)
print((min(result)))
| false | 10.869565 | [
"+result = []",
"-results = []",
"+tmp = []",
"-# 全ての本を買ってもXwo満たせないアルゴリズムがあるか検査",
"-for i in range(m):",
"- skill = 0",
"- for j in books:",
"- skill += j[i + 1]",
"- if skill < x:",
"+ tmp.append(i)",
"+# 参考書の選択パターン作成",
"+patterns = []",
"+for i in range(n):",
"+ pat... | false | 0.037183 | 0.036725 | 1.01248 | [
"s798523519",
"s395248324"
] |
u761320129 | p03822 | python | s203932637 | s576534583 | 637 | 241 | 123,792 | 121,392 | Accepted | Accepted | 62.17 | import sys
sys.setrecursionlimit(10**8)
N = int(eval(input()))
A = [int(eval(input()))-1 for i in range(N-1)]
wins = [[] for _ in range(N)]
for i,a in enumerate(A):
wins[a].append(i+1)
depth = [-1] * N
def dep(v):
if len(wins[v])==0: return 0
if depth[v] >= 0:
return depth[v]
ds = []
for w in wins[v]:
ds.append(dep(w))
ds.sort(reverse=True)
ret = 0
for i,d in enumerate(ds):
ret = max(ret, i+d+1)
depth[v] = ret
return ret
print((dep(0))) | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
N = int(eval(input()))
A = [int(eval(input()))-1 for i in range(N-1)]
wins = [[] for _ in range(N)]
for i,a in enumerate(A):
wins[a].append(i+1)
def depth(v):
if len(wins[v])==0: return 0
res = []
for u in wins[v]:
res.append(depth(u))
res.sort()
ret = 0
for r in res:
ret = max(r+1,ret+1)
return ret
print((depth(0))) | 24 | 22 | 515 | 443 | import sys
sys.setrecursionlimit(10**8)
N = int(eval(input()))
A = [int(eval(input())) - 1 for i in range(N - 1)]
wins = [[] for _ in range(N)]
for i, a in enumerate(A):
wins[a].append(i + 1)
depth = [-1] * N
def dep(v):
if len(wins[v]) == 0:
return 0
if depth[v] >= 0:
return depth[v]
ds = []
for w in wins[v]:
ds.append(dep(w))
ds.sort(reverse=True)
ret = 0
for i, d in enumerate(ds):
ret = max(ret, i + d + 1)
depth[v] = ret
return ret
print((dep(0)))
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
N = int(eval(input()))
A = [int(eval(input())) - 1 for i in range(N - 1)]
wins = [[] for _ in range(N)]
for i, a in enumerate(A):
wins[a].append(i + 1)
def depth(v):
if len(wins[v]) == 0:
return 0
res = []
for u in wins[v]:
res.append(depth(u))
res.sort()
ret = 0
for r in res:
ret = max(r + 1, ret + 1)
return ret
print((depth(0)))
| false | 8.333333 | [
"+input = sys.stdin.readline",
"-depth = [-1] * N",
"-def dep(v):",
"+def depth(v):",
"- if depth[v] >= 0:",
"- return depth[v]",
"- ds = []",
"- for w in wins[v]:",
"- ds.append(dep(w))",
"- ds.sort(reverse=True)",
"+ res = []",
"+ for u in wins[v]:",
"+ ... | false | 0.037482 | 0.143353 | 0.261467 | [
"s203932637",
"s576534583"
] |
u958053648 | p02779 | python | s242170063 | s713629469 | 138 | 105 | 33,996 | 33,996 | Accepted | Accepted | 23.91 | from collections import Counter
N=int(eval(input()))
A=list(map(int, input().split()))
B=Counter(A)
if N==len(B):
print('YES')
else:
print('NO') | from collections import Counter
N=int(eval(input()))
A=list(map(int, input().split()))
B=Counter(A)
if len(A)==len(B):
print('YES')
else:
print('NO') | 8 | 8 | 147 | 152 | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
B = Counter(A)
if N == len(B):
print("YES")
else:
print("NO")
| from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
B = Counter(A)
if len(A) == len(B):
print("YES")
else:
print("NO")
| false | 0 | [
"-if N == len(B):",
"+if len(A) == len(B):"
] | false | 0.042496 | 0.04127 | 1.029726 | [
"s242170063",
"s713629469"
] |
u573754721 | p02768 | python | s779423326 | s866452583 | 174 | 150 | 38,512 | 3,064 | Accepted | Accepted | 13.79 | def nCr(n, r):
mod=10**9+7
r = min(r, n-r)
numer = denom = 1
for i in range(1, r+1):
numer = numer * (n+1-i) % mod
denom = denom * i % mod
return numer * pow(denom, mod-2, mod) % mod
n,a,b=list(map(int,input().split()))
s=pow(2,n,10**9+7)
ans=s-1-nCr(n,a)-nCr(n,b)
while ans<0:
ans+=10**9+7
print(ans) | mod=10**9+7
def nCr(n, r):
r = min(r, n-r)
numer = denom = 1
for i in range(1, r+1):
numer = numer * (n+1-i) % mod
denom = denom * i % mod
return numer * pow(denom, mod-2, mod) % mod
n,a,b=list(map(int,input().split()))
f=pow(2, n, mod)-1-nCr(n,a)-nCr(n,b)
while f<0:
f+=mod
print(f) | 15 | 14 | 352 | 327 | def nCr(n, r):
mod = 10**9 + 7
r = min(r, n - r)
numer = denom = 1
for i in range(1, r + 1):
numer = numer * (n + 1 - i) % mod
denom = denom * i % mod
return numer * pow(denom, mod - 2, mod) % mod
n, a, b = list(map(int, input().split()))
s = pow(2, n, 10**9 + 7)
ans = s - 1 - nCr(n, a) - nCr(n, b)
while ans < 0:
ans += 10**9 + 7
print(ans)
| mod = 10**9 + 7
def nCr(n, r):
r = min(r, n - r)
numer = denom = 1
for i in range(1, r + 1):
numer = numer * (n + 1 - i) % mod
denom = denom * i % mod
return numer * pow(denom, mod - 2, mod) % mod
n, a, b = list(map(int, input().split()))
f = pow(2, n, mod) - 1 - nCr(n, a) - nCr(n, b)
while f < 0:
f += mod
print(f)
| false | 6.666667 | [
"+mod = 10**9 + 7",
"+",
"+",
"- mod = 10**9 + 7",
"-s = pow(2, n, 10**9 + 7)",
"-ans = s - 1 - nCr(n, a) - nCr(n, b)",
"-while ans < 0:",
"- ans += 10**9 + 7",
"-print(ans)",
"+f = pow(2, n, mod) - 1 - nCr(n, a) - nCr(n, b)",
"+while f < 0:",
"+ f += mod",
"+print(f)"
] | false | 0.133413 | 0.334152 | 0.399259 | [
"s779423326",
"s866452583"
] |
u508732591 | p02315 | python | s727860527 | s072653558 | 790 | 680 | 25,496 | 25,488 | Accepted | Accepted | 13.92 | N,W = list(map(int, input().split()))
dp = [[0]*(W+1) for y in range(N+1)]
for i in range(1,N+1):
v, w = list(map(int, input().split()))
for j in range(W+1):
if j < w:
dp[i][j] = dp[i-1][j]
else:
dp[i][j] = max(dp[i-1][j],dp[i-1][j-w]+v)
print((dp[N][W])) | N,W = list(map(int, input().split()))
dp = [[0]*(W+1) for y in range(N+1)]
for i in range(1,N+1):
v, w = list(map(int, input().split()))
dp[i][0:w] = dp[i-1][0:w]
for j in range(w, W+1):
dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
print((dp[N][W])) | 12 | 10 | 302 | 264 | N, W = list(map(int, input().split()))
dp = [[0] * (W + 1) for y in range(N + 1)]
for i in range(1, N + 1):
v, w = list(map(int, input().split()))
for j in range(W + 1):
if j < w:
dp[i][j] = dp[i - 1][j]
else:
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)
print((dp[N][W]))
| N, W = list(map(int, input().split()))
dp = [[0] * (W + 1) for y in range(N + 1)]
for i in range(1, N + 1):
v, w = list(map(int, input().split()))
dp[i][0:w] = dp[i - 1][0:w]
for j in range(w, W + 1):
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)
print((dp[N][W]))
| false | 16.666667 | [
"- for j in range(W + 1):",
"- if j < w:",
"- dp[i][j] = dp[i - 1][j]",
"- else:",
"- dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)",
"+ dp[i][0:w] = dp[i - 1][0:w]",
"+ for j in range(w, W + 1):",
"+ dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w... | false | 0.116007 | 0.04111 | 2.821855 | [
"s727860527",
"s072653558"
] |
u869790980 | p02787 | python | s646037224 | s150023573 | 682 | 381 | 33,948 | 33,512 | Accepted | Accepted | 44.13 | hh,n = list(map(int,input().split(' ')))
spells = [list(map(int, input().split(' '))) for _ in range(n)]
h = {}
h[0] = 0
#h[health] = cost in points
for health in range(1, hh+1):
for u,v in spells:
h[health] = min(h[health] if health in h else +float('inf'), h[max(0,health - u)] + v)
print(h[hh]) | hh,n = list(map(int,input().split(' ')))
spells = [list(map(int, input().split(' '))) for _ in range(n)]
h = [+float('inf')] * (hh+1)
h[0] = 0
for health in range(1, hh+1):
for u,v in spells: h[health] = min(h[health], h[max(0,health - u)] + v)
print(h[hh]) | 11 | 8 | 307 | 261 | hh, n = list(map(int, input().split(" ")))
spells = [list(map(int, input().split(" "))) for _ in range(n)]
h = {}
h[0] = 0
# h[health] = cost in points
for health in range(1, hh + 1):
for u, v in spells:
h[health] = min(
h[health] if health in h else +float("inf"), h[max(0, health - u)] + v
)
print(h[hh])
| hh, n = list(map(int, input().split(" ")))
spells = [list(map(int, input().split(" "))) for _ in range(n)]
h = [+float("inf")] * (hh + 1)
h[0] = 0
for health in range(1, hh + 1):
for u, v in spells:
h[health] = min(h[health], h[max(0, health - u)] + v)
print(h[hh])
| false | 27.272727 | [
"-h = {}",
"+h = [+float(\"inf\")] * (hh + 1)",
"-# h[health] = cost in points",
"- h[health] = min(",
"- h[health] if health in h else +float(\"inf\"), h[max(0, health - u)] + v",
"- )",
"+ h[health] = min(h[health], h[max(0, health - u)] + v)"
] | false | 0.106451 | 0.094463 | 1.126908 | [
"s646037224",
"s150023573"
] |
u528470578 | p03167 | python | s517421191 | s422565998 | 181 | 161 | 122,720 | 122,672 | Accepted | Accepted | 11.05 | MOD = int(1e9) + 7
H, W = list(map(int, input().split()))
maze = [list(eval(input())) for _ in range(H)]
dp = [[0 for i in range(W)] for j in range(H)]
dp[0][0] = 1
for i in range(H):
for j in range(W):
if i + 1 < H and maze[i+1][j] == ".":
dp[i+1][j] += dp[i][j]
dp[i+1][j] %= MOD
if j + 1 < W and maze[i][j+1] == ".":
dp[i][j+1] += dp[i][j]
dp[i][j+1] %= MOD
print((dp[H-1][W-1])) | H, W = list(map(int, input().split()))
g = [list(eval(input())) for _ in range(H)]
mod = int(1e9) + 7
dp = [[0 for i in range(W)] for j in range(H)]
dp[0][0] = 1
for i in range(H):
for j in range(W):
if g[i][j] == "#":
continue
if i + 1 < H:
dp[i+1][j] += dp[i][j] % mod
if j + 1 < W:
dp[i][j+1] += dp[i][j] % mod
print((dp[H-1][W-1] % mod)) | 15 | 14 | 451 | 404 | MOD = int(1e9) + 7
H, W = list(map(int, input().split()))
maze = [list(eval(input())) for _ in range(H)]
dp = [[0 for i in range(W)] for j in range(H)]
dp[0][0] = 1
for i in range(H):
for j in range(W):
if i + 1 < H and maze[i + 1][j] == ".":
dp[i + 1][j] += dp[i][j]
dp[i + 1][j] %= MOD
if j + 1 < W and maze[i][j + 1] == ".":
dp[i][j + 1] += dp[i][j]
dp[i][j + 1] %= MOD
print((dp[H - 1][W - 1]))
| H, W = list(map(int, input().split()))
g = [list(eval(input())) for _ in range(H)]
mod = int(1e9) + 7
dp = [[0 for i in range(W)] for j in range(H)]
dp[0][0] = 1
for i in range(H):
for j in range(W):
if g[i][j] == "#":
continue
if i + 1 < H:
dp[i + 1][j] += dp[i][j] % mod
if j + 1 < W:
dp[i][j + 1] += dp[i][j] % mod
print((dp[H - 1][W - 1] % mod))
| false | 6.666667 | [
"-MOD = int(1e9) + 7",
"-maze = [list(eval(input())) for _ in range(H)]",
"+g = [list(eval(input())) for _ in range(H)]",
"+mod = int(1e9) + 7",
"- if i + 1 < H and maze[i + 1][j] == \".\":",
"- dp[i + 1][j] += dp[i][j]",
"- dp[i + 1][j] %= MOD",
"- if j + 1 < W and... | false | 0.048246 | 0.046566 | 1.036089 | [
"s517421191",
"s422565998"
] |
u263830634 | p02996 | python | s516852542 | s750777914 | 1,528 | 474 | 78,296 | 31,836 | Accepted | Accepted | 68.98 | N = int(eval(input()))
lst = []
for _ in range(N):
A, B = list(map(int, input().split()))
lst += [[B, A]]
lst.sort()
t = 0
for i in range(N):
t += lst[i][1] #仕事に使う時間をプラス
if t > lst[i][0]: #制限時間と比較
print ('No')
exit()
print ('Yes')
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
N = int(eval(input()))
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x: x[1]) #締め切りが早い順位ソート
tmp = 0
for a, b in AB:
if tmp + a <= b:
tmp += a
else:
print ('No')
exit()
print ('Yes') | 16 | 18 | 269 | 347 | N = int(eval(input()))
lst = []
for _ in range(N):
A, B = list(map(int, input().split()))
lst += [[B, A]]
lst.sort()
t = 0
for i in range(N):
t += lst[i][1] # 仕事に使う時間をプラス
if t > lst[i][0]: # 制限時間と比較
print("No")
exit()
print("Yes")
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9 + 7
N = int(eval(input()))
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1]) # 締め切りが早い順位ソート
tmp = 0
for a, b in AB:
if tmp + a <= b:
tmp += a
else:
print("No")
exit()
print("Yes")
| false | 11.111111 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"+sys.setrecursionlimit(10**9)",
"+MOD = 10**9 + 7",
"-lst = []",
"-for _ in range(N):",
"- A, B = list(map(int, input().split()))",
"- lst += [[B, A]]",
"-lst.sort()",
"-t = 0",
"-for i in range(N):",
"- t += lst[i][1] # 仕事に使う時間をプ... | false | 0.083439 | 0.035926 | 2.322544 | [
"s516852542",
"s750777914"
] |
u586960661 | p03171 | python | s101489539 | s148815335 | 1,816 | 329 | 164,488 | 112,988 | Accepted | Accepted | 81.88 | def fun(i,j):
# print(i,j)
if i>j or i>=n or j<0:
return 0
elif i==j:
dp[i][j]=arr[i]
return dp[i][j]
else:
if dp[i][j]==0:
dp[i][j]=max(arr[i]+min(fun(i+1,j-1),fun(i+2,j)),arr[j]+min(fun(i+1,j-1),fun(i,j-2)))
return dp[i][j]
n=int(eval(input()))
dp=[0]*n
for i in range(n):
dp[i]=[0]*n
arr=list(map(int,input().split()))
print((2*fun(0,n-1)-sum(arr))) | def fun(i,j):
# print(i,j)
if i>j or i>=n or j<0:
return 0
elif i==j:
dp[i][j]=arr[i]
return dp[i][j]
else:
if dp[i][j]==0:
dp[i][j]=max(arr[i]+min(fun(i+1,j-1),fun(i+2,j)),arr[j]+min(fun(i+1,j-1),fun(i,j-2)))
return dp[i][j]
n=int(eval(input()))
dp=[0]*n
for i in range(n):
dp[i]=[0]*n
arr=list(map(int,input().split()))
for i in range(n-1,-1,-1):
for j in range(i,n,1):
if i==j:
dp[i][j]=arr[i]
else:
dp[i][j]=max(arr[i]-dp[i+1][j],arr[j]-dp[i][j-1])
# print(dp[i])
print((dp[0][n-1]))
# print(2*fun(0,n-1)-sum(arr)) | 17 | 26 | 378 | 567 | def fun(i, j):
# print(i,j)
if i > j or i >= n or j < 0:
return 0
elif i == j:
dp[i][j] = arr[i]
return dp[i][j]
else:
if dp[i][j] == 0:
dp[i][j] = max(
arr[i] + min(fun(i + 1, j - 1), fun(i + 2, j)),
arr[j] + min(fun(i + 1, j - 1), fun(i, j - 2)),
)
return dp[i][j]
n = int(eval(input()))
dp = [0] * n
for i in range(n):
dp[i] = [0] * n
arr = list(map(int, input().split()))
print((2 * fun(0, n - 1) - sum(arr)))
| def fun(i, j):
# print(i,j)
if i > j or i >= n or j < 0:
return 0
elif i == j:
dp[i][j] = arr[i]
return dp[i][j]
else:
if dp[i][j] == 0:
dp[i][j] = max(
arr[i] + min(fun(i + 1, j - 1), fun(i + 2, j)),
arr[j] + min(fun(i + 1, j - 1), fun(i, j - 2)),
)
return dp[i][j]
n = int(eval(input()))
dp = [0] * n
for i in range(n):
dp[i] = [0] * n
arr = list(map(int, input().split()))
for i in range(n - 1, -1, -1):
for j in range(i, n, 1):
if i == j:
dp[i][j] = arr[i]
else:
dp[i][j] = max(arr[i] - dp[i + 1][j], arr[j] - dp[i][j - 1])
# print(dp[i])
print((dp[0][n - 1]))
# print(2*fun(0,n-1)-sum(arr))
| false | 34.615385 | [
"-print((2 * fun(0, n - 1) - sum(arr)))",
"+for i in range(n - 1, -1, -1):",
"+ for j in range(i, n, 1):",
"+ if i == j:",
"+ dp[i][j] = arr[i]",
"+ else:",
"+ dp[i][j] = max(arr[i] - dp[i + 1][j], arr[j] - dp[i][j - 1])",
"+ # print(dp[i])",
"+print((dp... | false | 0.037803 | 0.087473 | 0.432164 | [
"s101489539",
"s148815335"
] |
u242525751 | p03089 | python | s647013117 | s388784222 | 193 | 171 | 38,640 | 38,768 | Accepted | Accepted | 11.4 | n = int(eval(input()))
b = list(map(int, input().split()))
for i in range(n):
if b[i] > i+1:
print((-1))
break
else:
ans = []
while len(b) > 1:
# print(ans,b)
c = len(ans)
f = b[0]
for i in range(1, len(b))[::-1]:
if b[i] == i + 1:
# print("check", b[i:])
ans.append(b.pop(i))
break
else:
for i in range(1, len(b)):
# print(f, i, b, n - c, ans)
if f >= b[i]:
ans.append(b.pop(i-1))
break
elif n - c == b[i]:
ans.append(b.pop(i))
break
elif i == len(b) - 1:
ans.append(b.pop(-1))
break
else:
f = b[i]
ans.append(1)
for i in range(n)[::-1]:
print((ans[i])) | n = int(eval(input()))
b = list(map(int, input().split()))
for i in range(n):
if b[i] > i+1:
print((-1))
break
else:
ans = []
while len(b) > 0:
f = b[0]
for i in range(len(b))[::-1]:
if b[i] == i + 1:
ans.append(b.pop(i))
break
for i in range(n)[::-1]:
print((ans[i])) | 34 | 17 | 760 | 325 | n = int(eval(input()))
b = list(map(int, input().split()))
for i in range(n):
if b[i] > i + 1:
print((-1))
break
else:
ans = []
while len(b) > 1:
# print(ans,b)
c = len(ans)
f = b[0]
for i in range(1, len(b))[::-1]:
if b[i] == i + 1:
# print("check", b[i:])
ans.append(b.pop(i))
break
else:
for i in range(1, len(b)):
# print(f, i, b, n - c, ans)
if f >= b[i]:
ans.append(b.pop(i - 1))
break
elif n - c == b[i]:
ans.append(b.pop(i))
break
elif i == len(b) - 1:
ans.append(b.pop(-1))
break
else:
f = b[i]
ans.append(1)
for i in range(n)[::-1]:
print((ans[i]))
| n = int(eval(input()))
b = list(map(int, input().split()))
for i in range(n):
if b[i] > i + 1:
print((-1))
break
else:
ans = []
while len(b) > 0:
f = b[0]
for i in range(len(b))[::-1]:
if b[i] == i + 1:
ans.append(b.pop(i))
break
for i in range(n)[::-1]:
print((ans[i]))
| false | 50 | [
"- while len(b) > 1:",
"- # print(ans,b)",
"- c = len(ans)",
"+ while len(b) > 0:",
"- for i in range(1, len(b))[::-1]:",
"+ for i in range(len(b))[::-1]:",
"- # print(\"check\", b[i:])",
"- else:",
"- for i in range(1, len... | false | 0.080801 | 0.041325 | 1.955261 | [
"s647013117",
"s388784222"
] |
u620084012 | p03943 | python | s650172711 | s235201742 | 162 | 17 | 38,256 | 2,940 | Accepted | Accepted | 89.51 | a, b, c = list(map(int,input().split()))
if a+b==c or b+c==a or c+a==b:
print("Yes")
else:
print("No")
| a, b, c = list(map(int,input().split()))
if a==b+c or b==a+c or c==b+a:
print("Yes")
else:
print("No")
| 5 | 5 | 109 | 109 | a, b, c = list(map(int, input().split()))
if a + b == c or b + c == a or c + a == b:
print("Yes")
else:
print("No")
| a, b, c = list(map(int, input().split()))
if a == b + c or b == a + c or c == b + a:
print("Yes")
else:
print("No")
| false | 0 | [
"-if a + b == c or b + c == a or c + a == b:",
"+if a == b + c or b == a + c or c == b + a:"
] | false | 0.123408 | 0.043221 | 2.855294 | [
"s650172711",
"s235201742"
] |
u225388820 | p02910 | python | s685901405 | s681683449 | 19 | 17 | 3,060 | 3,060 | Accepted | Accepted | 10.53 | s=eval(input())
n=len(s)
ans=0
for i in range(0,n,2):
if s[i]=='L':
ans+=1
for i in range(1,n,2):
if s[i]=='R':
ans+=1
if ans==0:
print('Yes')
else:
print('No') | s=eval(input())
n=len(s)
ans=True
for i in range(0,n,2):
if s[i]=='L':
ans=False
for i in range(1,n,2):
if s[i]=='R':
ans=False
if ans:
print('Yes')
else:
print('No')
| 13 | 13 | 198 | 205 | s = eval(input())
n = len(s)
ans = 0
for i in range(0, n, 2):
if s[i] == "L":
ans += 1
for i in range(1, n, 2):
if s[i] == "R":
ans += 1
if ans == 0:
print("Yes")
else:
print("No")
| s = eval(input())
n = len(s)
ans = True
for i in range(0, n, 2):
if s[i] == "L":
ans = False
for i in range(1, n, 2):
if s[i] == "R":
ans = False
if ans:
print("Yes")
else:
print("No")
| false | 0 | [
"-ans = 0",
"+ans = True",
"- ans += 1",
"+ ans = False",
"- ans += 1",
"-if ans == 0:",
"+ ans = False",
"+if ans:"
] | false | 0.048963 | 0.048204 | 1.015733 | [
"s685901405",
"s681683449"
] |
u745087332 | p04034 | python | s968570661 | s981903457 | 418 | 200 | 4,656 | 4,596 | Accepted | Accepted | 52.15 | # coding:utf-8
INF = float('inf')
def inpl(): return list(map(int, input().split()))
N, M = inpl()
# move = [inpl() for _ in range(M)]
ans = [0 for _ in range(N)]
ans[0] = 1
box = [1 for _ in range(N)]
# print(ans, box)
for i in range(M):
# x, y = move[i]
x, y = inpl()
box[x - 1] -= 1
box[y - 1] += 1
if ans[x - 1]:
ans[y - 1] = 1
if box[x - 1] == 0:
ans[x - 1] = 0
# print(ans, box)
print((sum(ans))) | # coding:utf-8
import sys
INF = float('inf')
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
def main():
n, m = LI()
B = [1] * n
R = [0] * n
R[0] = 1
for _ in range(m):
x, y = LI_()
B[x] -= 1
B[y] += 1
# 赤いボールが移動したかも?
if R[x]:
R[y] = 1
# 箱が空なので赤いボールは絶対入ってない!
if not B[x]:
R[x] = 0
return sum(R)
print((main()))
| 28 | 40 | 487 | 748 | # coding:utf-8
INF = float("inf")
def inpl():
return list(map(int, input().split()))
N, M = inpl()
# move = [inpl() for _ in range(M)]
ans = [0 for _ in range(N)]
ans[0] = 1
box = [1 for _ in range(N)]
# print(ans, box)
for i in range(M):
# x, y = move[i]
x, y = inpl()
box[x - 1] -= 1
box[y - 1] += 1
if ans[x - 1]:
ans[y - 1] = 1
if box[x - 1] == 0:
ans[x - 1] = 0
# print(ans, box)
print((sum(ans)))
| # coding:utf-8
import sys
INF = float("inf")
MOD = 10**9 + 7
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return eval(input())
def main():
n, m = LI()
B = [1] * n
R = [0] * n
R[0] = 1
for _ in range(m):
x, y = LI_()
B[x] -= 1
B[y] += 1
# 赤いボールが移動したかも?
if R[x]:
R[y] = 1
# 箱が空なので赤いボールは絶対入ってない!
if not B[x]:
R[x] = 0
return sum(R)
print((main()))
| false | 30 | [
"+import sys",
"+",
"+MOD = 10**9 + 7",
"-def inpl():",
"- return list(map(int, input().split()))",
"+def LI():",
"+ return [int(x) for x in sys.stdin.readline().split()]",
"-N, M = inpl()",
"-# move = [inpl() for _ in range(M)]",
"-ans = [0 for _ in range(N)]",
"-ans[0] = 1",
"-box = [1... | false | 0.043091 | 0.062677 | 0.687506 | [
"s968570661",
"s981903457"
] |
u857759499 | p03574 | python | s882129027 | s385801341 | 151 | 21 | 12,508 | 3,188 | Accepted | Accepted | 86.09 | from sys import stdin
import numpy as np
input = stdin.readline
h,w = list(map(int,input().split()))
s = (np.array([list(input().strip()) for _ in range(h)])=="#")
ans = np.zeros((h+2,w+2),dtype=np.uint8)
for i,j in [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]:
ans[1+i:h+1+i,1+j:w+1+j] += s
ans = ans[1:h+1,1:w+1].astype("str")
ans[s] = "#"
for i in ans:
print(("".join(i))) | def main():
from sys import stdin
input = stdin.readline
h,w = list(map(int,input().split()))
s = []
sa = s.append
sa(list("."*(w+2)))
for _ in range(h):
sa(["."]+list(input().strip())+["."])
sa(list("."*(w+2)))
for i in range(1,h+1):
for j in range(1,w+1):
if s[i][j] == ".":
n = 0
n += s[i-1][j-1:j+2].count("#")
n += s[i][j-1:j+2].count("#")
n += s[i+1][j-1:j+2].count("#")
s[i][j] = str(n)
for i in range(1,h+1):
print(("".join(s[i][1:w+1])))
main() | 12 | 21 | 393 | 543 | from sys import stdin
import numpy as np
input = stdin.readline
h, w = list(map(int, input().split()))
s = np.array([list(input().strip()) for _ in range(h)]) == "#"
ans = np.zeros((h + 2, w + 2), dtype=np.uint8)
for i, j in [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]:
ans[1 + i : h + 1 + i, 1 + j : w + 1 + j] += s
ans = ans[1 : h + 1, 1 : w + 1].astype("str")
ans[s] = "#"
for i in ans:
print(("".join(i)))
| def main():
from sys import stdin
input = stdin.readline
h, w = list(map(int, input().split()))
s = []
sa = s.append
sa(list("." * (w + 2)))
for _ in range(h):
sa(["."] + list(input().strip()) + ["."])
sa(list("." * (w + 2)))
for i in range(1, h + 1):
for j in range(1, w + 1):
if s[i][j] == ".":
n = 0
n += s[i - 1][j - 1 : j + 2].count("#")
n += s[i][j - 1 : j + 2].count("#")
n += s[i + 1][j - 1 : j + 2].count("#")
s[i][j] = str(n)
for i in range(1, h + 1):
print(("".join(s[i][1 : w + 1])))
main()
| false | 42.857143 | [
"-from sys import stdin",
"-import numpy as np",
"+def main():",
"+ from sys import stdin",
"-input = stdin.readline",
"-h, w = list(map(int, input().split()))",
"-s = np.array([list(input().strip()) for _ in range(h)]) == \"#\"",
"-ans = np.zeros((h + 2, w + 2), dtype=np.uint8)",
"-for i, j in [... | false | 0.310398 | 0.085945 | 3.611579 | [
"s882129027",
"s385801341"
] |
u816631826 | p03239 | python | s723429597 | s156285939 | 21 | 18 | 3,064 | 3,060 | Accepted | Accepted | 14.29 | x=list(map(int,input().split()))
ww=[]
min=x[1]
flag=0
min2=100000
for i in range(x[0]):
ww.append([])
ww[i] = list(map(int, input().split()))
if ww[i][1]<=min:
if ww[i][0]<min2:
min2=ww[i][0]
else:
flag+=1
if flag== x[0]:
print("TLE")
else:
print(min2)
| N , T = list(map(int, input().split()))
l =[]
for index in range(N):
n , t =list(map(int ,input().split()))
l .append([n,t])
ans = []
for elt in l :
if elt[1]<=T :
ans.append(elt[0])
if ans == []:
print("TLE")
else:
print((min(ans)))
| 22 | 13 | 331 | 261 | x = list(map(int, input().split()))
ww = []
min = x[1]
flag = 0
min2 = 100000
for i in range(x[0]):
ww.append([])
ww[i] = list(map(int, input().split()))
if ww[i][1] <= min:
if ww[i][0] < min2:
min2 = ww[i][0]
else:
flag += 1
if flag == x[0]:
print("TLE")
else:
print(min2)
| N, T = list(map(int, input().split()))
l = []
for index in range(N):
n, t = list(map(int, input().split()))
l.append([n, t])
ans = []
for elt in l:
if elt[1] <= T:
ans.append(elt[0])
if ans == []:
print("TLE")
else:
print((min(ans)))
| false | 40.909091 | [
"-x = list(map(int, input().split()))",
"-ww = []",
"-min = x[1]",
"-flag = 0",
"-min2 = 100000",
"-for i in range(x[0]):",
"- ww.append([])",
"- ww[i] = list(map(int, input().split()))",
"- if ww[i][1] <= min:",
"- if ww[i][0] < min2:",
"- min2 = ww[i][0]",
"- el... | false | 0.035712 | 0.035665 | 1.00131 | [
"s723429597",
"s156285939"
] |
u102461423 | p03822 | python | s895306286 | s815454261 | 678 | 400 | 231,984 | 28,244 | Accepted | Accepted | 41 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N-1)]
graph = [[] for _ in range(N+1)]
for i,x in enumerate(A,2):
graph[x].append(i)
def dfs(x):
arr = [dfs(y) for y in graph[x]]
if not arr:
return 0
arr.sort()
return max(i+x for i,x in enumerate(arr[::-1],1))
answer = dfs(1)
print(answer) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,*P = list(map(int,read().split()))
graph = [[] for _ in range(N+1)]
for i,x in enumerate(P,2):
graph[i].append(x)
graph[x].append(i)
root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
dp = [0] * (N+1)
for v in order[::-1]:
p = parent[v]
A = [dp[c] for c in graph[v] if c != p]
if not A:
continue
A.sort(reverse = True)
A = [x + i for i,x in enumerate(A,1)]
dp[v] = max(A)
answer = dp[1]
print(answer) | 20 | 37 | 411 | 768 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N - 1)]
graph = [[] for _ in range(N + 1)]
for i, x in enumerate(A, 2):
graph[x].append(i)
def dfs(x):
arr = [dfs(y) for y in graph[x]]
if not arr:
return 0
arr.sort()
return max(i + x for i, x in enumerate(arr[::-1], 1))
answer = dfs(1)
print(answer)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, *P = list(map(int, read().split()))
graph = [[] for _ in range(N + 1)]
for i, x in enumerate(P, 2):
graph[i].append(x)
graph[x].append(i)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
dp = [0] * (N + 1)
for v in order[::-1]:
p = parent[v]
A = [dp[c] for c in graph[v] if c != p]
if not A:
continue
A.sort(reverse=True)
A = [x + i for i, x in enumerate(A, 1)]
dp[v] = max(A)
answer = dp[1]
print(answer)
| false | 45.945946 | [
"-input = sys.stdin.readline",
"-sys.setrecursionlimit(10**7)",
"-N = int(eval(input()))",
"-A = [int(eval(input())) for _ in range(N - 1)]",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+N, *P = list(map(int, read().split()))",
... | false | 0.037623 | 0.071408 | 0.526864 | [
"s895306286",
"s815454261"
] |
u796942881 | p03137 | python | s372490875 | s077499743 | 111 | 83 | 13,840 | 14,968 | Accepted | Accepted | 25.23 | N, M = list(map(int, input().split()))
X = [int(i) for i in input().split()]
X.sort()
D = [X[i+1] - X[i] for i in range(M - 1)]
D.sort()
print((0 if M <= N else sum(D[:M-N])))
| N, M = list(map(int, input().split()))
X = list(set([int(i) for i in input().split()]))
X.sort()
D = [X[i+1] - X[i] for i in range(M - 1)]
D.sort()
print((0 if M <= N else sum(D[:M-N])))
| 10 | 10 | 181 | 192 | N, M = list(map(int, input().split()))
X = [int(i) for i in input().split()]
X.sort()
D = [X[i + 1] - X[i] for i in range(M - 1)]
D.sort()
print((0 if M <= N else sum(D[: M - N])))
| N, M = list(map(int, input().split()))
X = list(set([int(i) for i in input().split()]))
X.sort()
D = [X[i + 1] - X[i] for i in range(M - 1)]
D.sort()
print((0 if M <= N else sum(D[: M - N])))
| false | 0 | [
"-X = [int(i) for i in input().split()]",
"+X = list(set([int(i) for i in input().split()]))"
] | false | 0.034932 | 0.085235 | 0.409833 | [
"s372490875",
"s077499743"
] |
u119148115 | p02609 | python | s809911169 | s134507908 | 182 | 162 | 134,748 | 126,140 | Accepted | Accepted | 10.99 | import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
X = LI2()
X.reverse()
if N == 1 and len(X) == 1 and X[0] == 0:
print(1)
exit()
def popcount(n):
res = 0
m = n.bit_length()
for i in range(m):
res += (n >> i) & 1
return res
F = [0]*(2*10**5)
for i in range(1,2*10**5):
F[i] = 1 + F[i % popcount(i)]
a = sum(X)
b = a-1
c = a+1
if a == 1:
A, C = [1], [1] # 2冪をa,b,cで割った余り
xa, xc = 0, 0 # Xをa,b,cで割った余り
for i in range(N):
if X[i] == 1:
xa += A[-1]
xc += C[-1]
xa %= a
xc %= c
A.append((2 * A[-1]) % a)
C.append((2 * C[-1]) % c)
ANS = []
for i in range(N):
if X[i] == 1:
ANS.append(0)
else:
ANS.append(1 + F[(xc + C[i]) % c])
ANS.reverse()
print(*ANS, sep='\n')
exit()
A,B,C = [1],[1],[1] # 2冪をa,b,cで割った余り
xa,xb,xc = 0,0,0 # Xをa,b,cで割った余り
for i in range(N):
if X[i] == 1:
xa += A[-1]
xb += B[-1]
xc += C[-1]
xa %= a
xb %= b
xc %= c
A.append((2*A[-1])%a)
B.append((2*B[-1])%b)
C.append((2*C[-1])%c)
ANS = []
for i in range(N):
if X[i] == 1:
ANS.append(1 + F[(xb-B[i]) % b])
else:
ANS.append(1 + F[(xc+C[i]) % c])
ANS.reverse()
print(*ANS,sep='\n')
| import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
N = I()
X = LI2()
X.reverse()
if N == 1 and len(X) == 1 and X[0] == 0:
print(1)
exit()
def popcount(n):
res = 0
m = n.bit_length()
for i in range(m):
res += (n >> i) & 1
return res
# 1回の操作で 2*10**5 未満になることに注意
F = [0]*(2*10**5) # F[i] = f(i)
for i in range(1,2*10**5):
F[i] = 1 + F[i % popcount(i)]
a = sum(X)
b = a-1
c = a+1
if a == 1:
C = [1] # 2冪をcで割った余り
xc = 0 # Xをcで割った余り
for i in range(N):
if X[i] == 1:
xc += C[-1]
xc %= c
C.append((2 * C[-1]) % c)
ANS = []
for i in range(N):
if X[i] == 1:
ANS.append(0)
else:
ANS.append(1 + F[(xc + C[i]) % c])
ANS.reverse()
print(*ANS, sep='\n')
exit()
B,C = [1],[1] # 2冪をb,cで割った余り
xb,xc = 0,0 # Xをb,cで割った余り
for i in range(N):
if X[i] == 1:
xb += B[-1]
xc += C[-1]
xb %= b
xc %= c
B.append((2*B[-1])%b)
C.append((2*C[-1])%c)
ANS = []
for i in range(N):
if X[i] == 1:
ANS.append(1 + F[(xb-B[i]) % b])
else:
ANS.append(1 + F[(xc+C[i]) % c])
ANS.reverse()
print(*ANS,sep='\n')
| 82 | 71 | 1,844 | 1,353 | import sys
sys.setrecursionlimit(10**7)
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return map(int, sys.stdin.readline().rstrip().split())
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
def LI2():
return list(map(int, sys.stdin.readline().rstrip())) # 空白なし
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split()) # 空白あり
def LS2():
return list(sys.stdin.readline().rstrip()) # 空白なし
N = I()
X = LI2()
X.reverse()
if N == 1 and len(X) == 1 and X[0] == 0:
print(1)
exit()
def popcount(n):
res = 0
m = n.bit_length()
for i in range(m):
res += (n >> i) & 1
return res
F = [0] * (2 * 10**5)
for i in range(1, 2 * 10**5):
F[i] = 1 + F[i % popcount(i)]
a = sum(X)
b = a - 1
c = a + 1
if a == 1:
A, C = [1], [1] # 2冪をa,b,cで割った余り
xa, xc = 0, 0 # Xをa,b,cで割った余り
for i in range(N):
if X[i] == 1:
xa += A[-1]
xc += C[-1]
xa %= a
xc %= c
A.append((2 * A[-1]) % a)
C.append((2 * C[-1]) % c)
ANS = []
for i in range(N):
if X[i] == 1:
ANS.append(0)
else:
ANS.append(1 + F[(xc + C[i]) % c])
ANS.reverse()
print(*ANS, sep="\n")
exit()
A, B, C = [1], [1], [1] # 2冪をa,b,cで割った余り
xa, xb, xc = 0, 0, 0 # Xをa,b,cで割った余り
for i in range(N):
if X[i] == 1:
xa += A[-1]
xb += B[-1]
xc += C[-1]
xa %= a
xb %= b
xc %= c
A.append((2 * A[-1]) % a)
B.append((2 * B[-1]) % b)
C.append((2 * C[-1]) % c)
ANS = []
for i in range(N):
if X[i] == 1:
ANS.append(1 + F[(xb - B[i]) % b])
else:
ANS.append(1 + F[(xc + C[i]) % c])
ANS.reverse()
print(*ANS, sep="\n")
| import sys
def I():
return int(sys.stdin.readline().rstrip())
def LI2():
return list(map(int, sys.stdin.readline().rstrip())) # 空白なし
N = I()
X = LI2()
X.reverse()
if N == 1 and len(X) == 1 and X[0] == 0:
print(1)
exit()
def popcount(n):
res = 0
m = n.bit_length()
for i in range(m):
res += (n >> i) & 1
return res
# 1回の操作で 2*10**5 未満になることに注意
F = [0] * (2 * 10**5) # F[i] = f(i)
for i in range(1, 2 * 10**5):
F[i] = 1 + F[i % popcount(i)]
a = sum(X)
b = a - 1
c = a + 1
if a == 1:
C = [1] # 2冪をcで割った余り
xc = 0 # Xをcで割った余り
for i in range(N):
if X[i] == 1:
xc += C[-1]
xc %= c
C.append((2 * C[-1]) % c)
ANS = []
for i in range(N):
if X[i] == 1:
ANS.append(0)
else:
ANS.append(1 + F[(xc + C[i]) % c])
ANS.reverse()
print(*ANS, sep="\n")
exit()
B, C = [1], [1] # 2冪をb,cで割った余り
xb, xc = 0, 0 # Xをb,cで割った余り
for i in range(N):
if X[i] == 1:
xb += B[-1]
xc += C[-1]
xb %= b
xc %= c
B.append((2 * B[-1]) % b)
C.append((2 * C[-1]) % c)
ANS = []
for i in range(N):
if X[i] == 1:
ANS.append(1 + F[(xb - B[i]) % b])
else:
ANS.append(1 + F[(xc + C[i]) % c])
ANS.reverse()
print(*ANS, sep="\n")
| false | 13.414634 | [
"-",
"-sys.setrecursionlimit(10**7)",
"-def MI():",
"- return map(int, sys.stdin.readline().rstrip().split())",
"-",
"-",
"-def LI():",
"- return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり",
"-",
"-",
"-",
"-",
"-def S():",
"- return sys.stdin.readline().rstrip(... | false | 4.170107 | 1.463838 | 2.84875 | [
"s809911169",
"s134507908"
] |
u446711904 | p02802 | python | s866716767 | s376880191 | 291 | 207 | 37,260 | 18,084 | Accepted | Accepted | 28.87 | n,m=list(map(int,input().split()))
if m==0:
print((0,0))
import sys
sys.exit()
p=[list(input().split()) for _ in range(m)]
correct=set([p[i][0] for i in range(m) if p[i][1]=='AC'])
sum_wa=0
data=[0]*n
for i in range(m):
if p[i][0] in correct and data[int(p[i][0])-1]==0:
if p[i][1]=='WA':
sum_wa+=1
else:
data[int(p[i][0])-1]=1
print((sum(data),sum_wa)) | n,m=list(map(int,input().split()))
data=[0]*n
s=set()
for i in range(m):
p,a=input().split()
p=int(p)-1
if p in s:
continue
else:
if a=='WA':
data[p]-=1
else:
data[p]*=-1
s.add(p)
print((len(s),sum([data[i] for i in range(n) if data[i]>0]))) | 21 | 18 | 424 | 329 | n, m = list(map(int, input().split()))
if m == 0:
print((0, 0))
import sys
sys.exit()
p = [list(input().split()) for _ in range(m)]
correct = set([p[i][0] for i in range(m) if p[i][1] == "AC"])
sum_wa = 0
data = [0] * n
for i in range(m):
if p[i][0] in correct and data[int(p[i][0]) - 1] == 0:
if p[i][1] == "WA":
sum_wa += 1
else:
data[int(p[i][0]) - 1] = 1
print((sum(data), sum_wa))
| n, m = list(map(int, input().split()))
data = [0] * n
s = set()
for i in range(m):
p, a = input().split()
p = int(p) - 1
if p in s:
continue
else:
if a == "WA":
data[p] -= 1
else:
data[p] *= -1
s.add(p)
print((len(s), sum([data[i] for i in range(n) if data[i] > 0])))
| false | 14.285714 | [
"-if m == 0:",
"- print((0, 0))",
"- import sys",
"-",
"- sys.exit()",
"-p = [list(input().split()) for _ in range(m)]",
"-correct = set([p[i][0] for i in range(m) if p[i][1] == \"AC\"])",
"-sum_wa = 0",
"+s = set()",
"- if p[i][0] in correct and data[int(p[i][0]) - 1] == 0:",
"- ... | false | 0.036931 | 0.035637 | 1.036329 | [
"s866716767",
"s376880191"
] |
u072717685 | p03557 | python | s678711990 | s522360391 | 303 | 230 | 29,124 | 44,168 | Accepted | Accepted | 24.09 | from bisect import bisect
from itertools import accumulate
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ainb = [bisect(b, ea) for ea in a]
bc = [n - bisect(c, eb) for eb in b]
bcaccum = tuple(accumulate(bc))
tr = 0
for eainb in ainb:
if eainb != 0:
tr += bcaccum[eainb - 1]
r = bcaccum[-1] * n - tr
print(r)
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
from bisect import bisect, bisect_left
from itertools import accumulate
def main():
data = list(map(int, read().split()))
n = data[0]
a = data[1:n + 1]
b = data[n + 1: n * 2 + 1]
c = data[n * 2 + 1:]
a.sort()
b.sort()
c.sort()
b2 = [bisect_left(a, be) for be in b]
b2a = list(accumulate(b2))
b2a = [0] + b2a
ans = sum([b2a[bisect_left(b, ce)] for ce in c])
print(ans)
if __name__ == '__main__':
main() | 23 | 22 | 565 | 545 | from bisect import bisect
from itertools import accumulate
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ainb = [bisect(b, ea) for ea in a]
bc = [n - bisect(c, eb) for eb in b]
bcaccum = tuple(accumulate(bc))
tr = 0
for eainb in ainb:
if eainb != 0:
tr += bcaccum[eainb - 1]
r = bcaccum[-1] * n - tr
print(r)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
# readlines = sys.stdin.readlines
from bisect import bisect, bisect_left
from itertools import accumulate
def main():
data = list(map(int, read().split()))
n = data[0]
a = data[1 : n + 1]
b = data[n + 1 : n * 2 + 1]
c = data[n * 2 + 1 :]
a.sort()
b.sort()
c.sort()
b2 = [bisect_left(a, be) for be in b]
b2a = list(accumulate(b2))
b2a = [0] + b2a
ans = sum([b2a[bisect_left(b, ce)] for ce in c])
print(ans)
if __name__ == "__main__":
main()
| false | 4.347826 | [
"-from bisect import bisect",
"+import sys",
"+",
"+read = sys.stdin.read",
"+# readlines = sys.stdin.readlines",
"+from bisect import bisect, bisect_left",
"- n = int(eval(input()))",
"- a = list(map(int, input().split()))",
"- b = list(map(int, input().split()))",
"- c = list(map(int... | false | 0.049943 | 0.041611 | 1.20023 | [
"s678711990",
"s522360391"
] |
u600402037 | p02936 | python | s877529134 | s151378563 | 1,893 | 869 | 238,868 | 89,420 | Accepted | Accepted | 54.09 | import sys
sys.setrecursionlimit(10 ** 7)
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, Q = lr()
edges = [[] for _ in range(N+1)]
for _ in range(N-1):
a, b = lr()
edges[a].append(b)
edges[b].append(a)
counter = [0] * (N+1)
for _ in range(Q):
p, x = lr()
counter[p] += x
parents = [0] * (N+1)
def bfs(x):
p = parents[x]
c = counter[x]
for y in edges[x]:
if y == p:
continue
counter[y] += c
parents[y] = x
bfs(y)
bfs(1)
print((*counter[1:]))
# 09 | import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# クエリでは根だけにカウンターの値を足して、最後に上から足していく(imos法みたいに)
N, Q = lr()
graph = [[] for _ in range(N+1)]
for _ in range(N-1):
a, b = lr()
graph[a].append(b)
graph[b].append(a)
counter = [0] * (N+1) # 1-indexed
for _ in range(Q):
p, x = lr()
counter[p] += x
root = 1
stack = [(root, None)]
while stack:
cur, parent = stack.pop()
c = counter[cur]
for child in graph[cur]:
if child == parent:
continue
counter[child] += c
if len(graph[child]) > 1:
stack.append((child, cur))
print((*counter[1:]))
| 34 | 32 | 622 | 713 | import sys
sys.setrecursionlimit(10**7)
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, Q = lr()
edges = [[] for _ in range(N + 1)]
for _ in range(N - 1):
a, b = lr()
edges[a].append(b)
edges[b].append(a)
counter = [0] * (N + 1)
for _ in range(Q):
p, x = lr()
counter[p] += x
parents = [0] * (N + 1)
def bfs(x):
p = parents[x]
c = counter[x]
for y in edges[x]:
if y == p:
continue
counter[y] += c
parents[y] = x
bfs(y)
bfs(1)
print((*counter[1:]))
# 09
| import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# クエリでは根だけにカウンターの値を足して、最後に上から足していく(imos法みたいに)
N, Q = lr()
graph = [[] for _ in range(N + 1)]
for _ in range(N - 1):
a, b = lr()
graph[a].append(b)
graph[b].append(a)
counter = [0] * (N + 1) # 1-indexed
for _ in range(Q):
p, x = lr()
counter[p] += x
root = 1
stack = [(root, None)]
while stack:
cur, parent = stack.pop()
c = counter[cur]
for child in graph[cur]:
if child == parent:
continue
counter[child] += c
if len(graph[child]) > 1:
stack.append((child, cur))
print((*counter[1:]))
| false | 5.882353 | [
"-sys.setrecursionlimit(10**7)",
"+# クエリでは根だけにカウンターの値を足して、最後に上から足していく(imos法みたいに)",
"-edges = [[] for _ in range(N + 1)]",
"+graph = [[] for _ in range(N + 1)]",
"- edges[a].append(b)",
"- edges[b].append(a)",
"-counter = [0] * (N + 1)",
"+ graph[a].append(b)",
"+ graph[b].append(a)",
"... | false | 0.038373 | 0.037364 | 1.027013 | [
"s877529134",
"s151378563"
] |
u191874006 | p02614 | python | s312283597 | s545035825 | 104 | 78 | 69,580 | 68,432 | Accepted | Accepted | 25 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
h, w, K = LI()
c = [list(eval(input())) for _ in range(h)]
count = 0
for i in range(h):
for j in range(w):
if c[i][j] == '#':
count += 1
ans = 0
for i in range(1 << h):
f = defaultdict(lambda : 0)
cnt = count
for k in range(h):
if i >> k & 1:
for l in range(w):
if c[k][l] == "#" and f[(k, l)] == 0:
f[(k, l)] = 1
cnt -= 1
for j in range(1 << w):
cnt2 = cnt
f2 = defaultdict(lambda : 0)
for k, l in list(f.items()):
if l == 1:
f2[k] = 1
for k in range(w):
if j >> k & 1:
for l in range(h):
if c[l][k] == "#" and f2[(l, k)] == 0:
f2[(l, k)] = 1
cnt2 -= 1
if cnt2 == K:
ans += 1
print(ans) | #!/usr/bin/env python3
h, w, k = list(map(int, input().split()))
c = [eval(input()) for _ in range(h)]
ans = 0
for i in range(1<<h):
for j in range(1<<w):
cnt = 0
for y in range(h):
for x in range(w):
if (i >> y & 1) or (j >> x & 1):
continue
if c[y][x] == '#':
cnt += 1
if cnt == k:
ans += 1
print(ans) | 51 | 18 | 1,458 | 439 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
h, w, K = LI()
c = [list(eval(input())) for _ in range(h)]
count = 0
for i in range(h):
for j in range(w):
if c[i][j] == "#":
count += 1
ans = 0
for i in range(1 << h):
f = defaultdict(lambda: 0)
cnt = count
for k in range(h):
if i >> k & 1:
for l in range(w):
if c[k][l] == "#" and f[(k, l)] == 0:
f[(k, l)] = 1
cnt -= 1
for j in range(1 << w):
cnt2 = cnt
f2 = defaultdict(lambda: 0)
for k, l in list(f.items()):
if l == 1:
f2[k] = 1
for k in range(w):
if j >> k & 1:
for l in range(h):
if c[l][k] == "#" and f2[(l, k)] == 0:
f2[(l, k)] = 1
cnt2 -= 1
if cnt2 == K:
ans += 1
print(ans)
| #!/usr/bin/env python3
h, w, k = list(map(int, input().split()))
c = [eval(input()) for _ in range(h)]
ans = 0
for i in range(1 << h):
for j in range(1 << w):
cnt = 0
for y in range(h):
for x in range(w):
if (i >> y & 1) or (j >> x & 1):
continue
if c[y][x] == "#":
cnt += 1
if cnt == k:
ans += 1
print(ans)
| false | 64.705882 | [
"-import sys",
"-import math",
"-from bisect import bisect_right as br",
"-from bisect import bisect_left as bl",
"-",
"-sys.setrecursionlimit(2147483647)",
"-from heapq import heappush, heappop, heappushpop",
"-from collections import defaultdict",
"-from itertools import accumulate",
"-from coll... | false | 0.064395 | 0.084438 | 0.762638 | [
"s312283597",
"s545035825"
] |
u753803401 | p02899 | python | s904851948 | s611180242 | 536 | 392 | 70,956 | 67,960 | Accepted | Accepted | 26.87 | def slove():
import sys
input = sys.stdin.readline
n = int(input().rstrip('\n'))
a = [[v, i + 1] for i, v in enumerate(list(map(int, input().rstrip('\n').split())))]
a.sort()
print((*[a[i][1] for i in range(n)]))
if __name__ == '__main__':
slove()
| import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
a = list(map(int, readline().split()))
ans = []
for i, v in enumerate(a):
ans.append([i, v])
ans.sort(key=lambda x: x[1])
ls = []
for i in range(n):
ls.append(ans[i][0] + 1)
print((*ls))
if __name__ == '__main__':
solve()
| 11 | 20 | 286 | 402 | def slove():
import sys
input = sys.stdin.readline
n = int(input().rstrip("\n"))
a = [[v, i + 1] for i, v in enumerate(list(map(int, input().rstrip("\n").split())))]
a.sort()
print((*[a[i][1] for i in range(n)]))
if __name__ == "__main__":
slove()
| import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10**9 + 7
n = int(readline())
a = list(map(int, readline().split()))
ans = []
for i, v in enumerate(a):
ans.append([i, v])
ans.sort(key=lambda x: x[1])
ls = []
for i in range(n):
ls.append(ans[i][0] + 1)
print((*ls))
if __name__ == "__main__":
solve()
| false | 45 | [
"-def slove():",
"- import sys",
"+import sys",
"- input = sys.stdin.readline",
"- n = int(input().rstrip(\"\\n\"))",
"- a = [[v, i + 1] for i, v in enumerate(list(map(int, input().rstrip(\"\\n\").split())))]",
"- a.sort()",
"- print((*[a[i][1] for i in range(n)]))",
"+",
"+def s... | false | 0.065775 | 0.037153 | 1.770389 | [
"s904851948",
"s611180242"
] |
u036104576 | p03033 | python | s206434237 | s139071572 | 1,981 | 1,641 | 203,304 | 105,452 | Accepted | Accepted | 17.16 | import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, Q = list(map(int, input().split()))
events = []
for i in range(N):
s, t, x = list(map(int, input().split()))
events.append((s - x, 0, x))
events.append((t - x, 1, x))
for i in range(Q):
d = int(eval(input()))
events.append((d, 2, i))
events = sorted(events)
q = [INF]
cnt = defaultdict(int)
ans = [INF] * Q
for a, b, c in events:
if b == 0:
heapq.heappush(q, c)
cnt[c] += 1
if b == 1:
cnt[c] -= 1
if b == 2:
while len(q) > 1 and cnt[q[0]] == 0:
heapq.heappop(q)
if q[0] == INF:
ans[c] = -1
else:
ans[c] = q[0]
for i in range(Q):
print((ans[i])) | import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, Q = list(map(int, input().split()))
events = []
for i in range(N):
s, t, x = list(map(int, input().split()))
events.append((s - x, 0, x))
events.append((t - x, 1, x))
for i in range(Q):
d = int(eval(input()))
events.append((d, 2, i))
events = sorted(events)
q = [INF]
cnt = defaultdict(int)
cnt[INF] = 1
ans = [INF] * Q
for a, b, c in events:
if b == 0:
heapq.heappush(q, c)
cnt[c] += 1
if b == 1:
cnt[c] -= 1
if b == 2:
while cnt[q[0]] == 0:
heapq.heappop(q)
if q[0] == INF:
ans[c] = -1
else:
ans[c] = q[0]
for i in range(Q):
print((ans[i])) | 66 | 67 | 1,424 | 1,423 | import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, Q = list(map(int, input().split()))
events = []
for i in range(N):
s, t, x = list(map(int, input().split()))
events.append((s - x, 0, x))
events.append((t - x, 1, x))
for i in range(Q):
d = int(eval(input()))
events.append((d, 2, i))
events = sorted(events)
q = [INF]
cnt = defaultdict(int)
ans = [INF] * Q
for a, b, c in events:
if b == 0:
heapq.heappush(q, c)
cnt[c] += 1
if b == 1:
cnt[c] -= 1
if b == 2:
while len(q) > 1 and cnt[q[0]] == 0:
heapq.heappop(q)
if q[0] == INF:
ans[c] = -1
else:
ans[c] = q[0]
for i in range(Q):
print((ans[i]))
| import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, Q = list(map(int, input().split()))
events = []
for i in range(N):
s, t, x = list(map(int, input().split()))
events.append((s - x, 0, x))
events.append((t - x, 1, x))
for i in range(Q):
d = int(eval(input()))
events.append((d, 2, i))
events = sorted(events)
q = [INF]
cnt = defaultdict(int)
cnt[INF] = 1
ans = [INF] * Q
for a, b, c in events:
if b == 0:
heapq.heappush(q, c)
cnt[c] += 1
if b == 1:
cnt[c] -= 1
if b == 2:
while cnt[q[0]] == 0:
heapq.heappop(q)
if q[0] == INF:
ans[c] = -1
else:
ans[c] = q[0]
for i in range(Q):
print((ans[i]))
| false | 1.492537 | [
"+cnt[INF] = 1",
"- while len(q) > 1 and cnt[q[0]] == 0:",
"+ while cnt[q[0]] == 0:"
] | false | 0.143667 | 0.008281 | 17.348467 | [
"s206434237",
"s139071572"
] |
u034777138 | p02898 | python | s215141449 | s139359092 | 54 | 48 | 11,912 | 11,908 | Accepted | Accepted | 11.11 |
inputA = list(map(int,input().split()))
inputB = list(map(int,input().split()))
humancount = inputA[0]
talllimit = inputA[1]
anser = 0
for count in range(0,humancount):
if inputB[count] >= talllimit:
anser += 1
print(anser) | ip= list(map(int, input().split()))
N = ip[0]
K = ip[1]
h = list(map(int, input().split()))
ans = 0
for tall in h:
if tall >= K:
ans +=1
print(ans) | 14 | 12 | 255 | 173 | inputA = list(map(int, input().split()))
inputB = list(map(int, input().split()))
humancount = inputA[0]
talllimit = inputA[1]
anser = 0
for count in range(0, humancount):
if inputB[count] >= talllimit:
anser += 1
print(anser)
| ip = list(map(int, input().split()))
N = ip[0]
K = ip[1]
h = list(map(int, input().split()))
ans = 0
for tall in h:
if tall >= K:
ans += 1
print(ans)
| false | 14.285714 | [
"-inputA = list(map(int, input().split()))",
"-inputB = list(map(int, input().split()))",
"-humancount = inputA[0]",
"-talllimit = inputA[1]",
"-anser = 0",
"-for count in range(0, humancount):",
"- if inputB[count] >= talllimit:",
"- anser += 1",
"-print(anser)",
"+ip = list(map(int, in... | false | 0.082243 | 0.091643 | 0.897434 | [
"s215141449",
"s139359092"
] |
u720721463 | p03524 | python | s861647423 | s509982767 | 83 | 70 | 67,536 | 67,664 | Accepted | Accepted | 15.66 | s = eval(input())
na = nb = nc = 0
for c in s:
if c == 'a':
na += 1
if c == 'b':
nb += 1
if c == 'c':
nc += 1
if max(abs(na-nb), max( abs(na - nc), abs(nb - nc))) > 1:
print("NO")
else:
print("YES")
| s = eval(input())
na = nb = nc = 0
for c in s:
if c == 'a':
na += 1
if c == 'b':
nb += 1
if c == 'c':
nc += 1
if abs(na - nb) < 2 and abs(na - nc) < 2 and abs(nb - nc) < 2:
print("YES")
else:
print("NO")
| 15 | 15 | 231 | 236 | s = eval(input())
na = nb = nc = 0
for c in s:
if c == "a":
na += 1
if c == "b":
nb += 1
if c == "c":
nc += 1
if max(abs(na - nb), max(abs(na - nc), abs(nb - nc))) > 1:
print("NO")
else:
print("YES")
| s = eval(input())
na = nb = nc = 0
for c in s:
if c == "a":
na += 1
if c == "b":
nb += 1
if c == "c":
nc += 1
if abs(na - nb) < 2 and abs(na - nc) < 2 and abs(nb - nc) < 2:
print("YES")
else:
print("NO")
| false | 0 | [
"-if max(abs(na - nb), max(abs(na - nc), abs(nb - nc))) > 1:",
"+if abs(na - nb) < 2 and abs(na - nc) < 2 and abs(nb - nc) < 2:",
"+ print(\"YES\")",
"+else:",
"-else:",
"- print(\"YES\")"
] | false | 0.040031 | 0.038604 | 1.036981 | [
"s861647423",
"s509982767"
] |
u844646164 | p03450 | python | s815573152 | s726477978 | 1,671 | 606 | 133,264 | 88,572 | Accepted | Accepted | 63.73 |
import sys
sys.setrecursionlimit(10**5)
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1]*(n+1)
self.rnk = [0]*(n+1)
self.weight = [0]*(n+1)
def Find_Root(self, x):
if(self.root[x] < 0):
return x
else:
r = self.Find_Root(self.root[x])
self.weight[x] += self.weight[self.root[x]]
self.root[x] = r
return r
def GetWeight(self, x):
self.Find_Root(x)
return self.weight[x]
def Unite(self, x, y, w):
w += self.GetWeight(x)
w -= self.GetWeight(y)
x = self.Find_Root(x)
y = self.Find_Root(y)
if(x == y):
return False
if self.rnk[x] < self.rnk[y]:
x, y = y, x
w = -w
if self.rnk[x] == self.rnk[y]:
self.rnk[x] += 1
self.root[y] = x
self.weight[y] = w
return True
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x):
return -self.root[self.Find_Root(x)]
def Diff(self, x, y):
return self.GetWeight(y) - self.GetWeight(x)
n, m = list(map(int, input().split()))
if m == 0:
print('Yes')
exit()
lrd = [list(map(int, input().split())) for _ in range(m)]
uf = UnionFind(n)
for l, r, d in lrd:
if uf.isSameGroup(l, r)==False:
uf.Unite(l, r, d)
else:
if uf.Diff(l, r) != d:
print('No')
exit()
print('Yes')
| import sys
sys.setrecursionlimit(10**5)
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1]*(n+1)
self.rnk = [0]*(n+1)
self.weight = [0]*(n+1)
def Find_Root(self, x):
if(self.root[x] < 0):
return x
else:
r = self.Find_Root(self.root[x])
self.weight[x] += self.weight[self.root[x]]
self.root[x] = r
return r
def GetWeight(self, x):
self.Find_Root(x)
return self.weight[x]
def Unite(self, x, y, w):
w += self.GetWeight(x)
w -= self.GetWeight(y)
x = self.Find_Root(x)
y = self.Find_Root(y)
if(x == y):
return False
if self.rnk[x] < self.rnk[y]:
x, y = y, x
w = -w
if self.rnk[x] == self.rnk[y]:
self.rnk[x] += 1
self.root[y] = x
self.weight[y] = w
return True
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x):
return -self.root[self.Find_Root(x)]
def Diff(self, x, y):
return self.GetWeight(y) - self.GetWeight(x)
N, M = list(map(int, input().split()))
uf = UnionFind(N+1)
for _ in range(M):
l, r, d = list(map(int, input().split()))
if not uf.isSameGroup(l, r):
uf.Unite(l, r, d)
else:
if uf.Diff(l, r) != d:
print('No')
exit()
print('Yes')
| 59 | 53 | 1,568 | 1,500 | import sys
sys.setrecursionlimit(10**5)
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
self.weight = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
r = self.Find_Root(self.root[x])
self.weight[x] += self.weight[self.root[x]]
self.root[x] = r
return r
def GetWeight(self, x):
self.Find_Root(x)
return self.weight[x]
def Unite(self, x, y, w):
w += self.GetWeight(x)
w -= self.GetWeight(y)
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return False
if self.rnk[x] < self.rnk[y]:
x, y = y, x
w = -w
if self.rnk[x] == self.rnk[y]:
self.rnk[x] += 1
self.root[y] = x
self.weight[y] = w
return True
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x):
return -self.root[self.Find_Root(x)]
def Diff(self, x, y):
return self.GetWeight(y) - self.GetWeight(x)
n, m = list(map(int, input().split()))
if m == 0:
print("Yes")
exit()
lrd = [list(map(int, input().split())) for _ in range(m)]
uf = UnionFind(n)
for l, r, d in lrd:
if uf.isSameGroup(l, r) == False:
uf.Unite(l, r, d)
else:
if uf.Diff(l, r) != d:
print("No")
exit()
print("Yes")
| import sys
sys.setrecursionlimit(10**5)
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
self.weight = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
r = self.Find_Root(self.root[x])
self.weight[x] += self.weight[self.root[x]]
self.root[x] = r
return r
def GetWeight(self, x):
self.Find_Root(x)
return self.weight[x]
def Unite(self, x, y, w):
w += self.GetWeight(x)
w -= self.GetWeight(y)
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return False
if self.rnk[x] < self.rnk[y]:
x, y = y, x
w = -w
if self.rnk[x] == self.rnk[y]:
self.rnk[x] += 1
self.root[y] = x
self.weight[y] = w
return True
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x):
return -self.root[self.Find_Root(x)]
def Diff(self, x, y):
return self.GetWeight(y) - self.GetWeight(x)
N, M = list(map(int, input().split()))
uf = UnionFind(N + 1)
for _ in range(M):
l, r, d = list(map(int, input().split()))
if not uf.isSameGroup(l, r):
uf.Unite(l, r, d)
else:
if uf.Diff(l, r) != d:
print("No")
exit()
print("Yes")
| false | 10.169492 | [
"-n, m = list(map(int, input().split()))",
"-if m == 0:",
"- print(\"Yes\")",
"- exit()",
"-lrd = [list(map(int, input().split())) for _ in range(m)]",
"-uf = UnionFind(n)",
"-for l, r, d in lrd:",
"- if uf.isSameGroup(l, r) == False:",
"+N, M = list(map(int, input().split()))",
"+uf = Un... | false | 0.043462 | 0.0436 | 0.996831 | [
"s815573152",
"s726477978"
] |
u584083761 | p02726 | python | s488827200 | s181898902 | 1,969 | 1,339 | 3,444 | 3,444 | Accepted | Accepted | 32 | n,x,y = list(map(int, input().split()))
ans = [0]*(n)
for i in range(n-1):
for j in range(i+1, n):
r1 = min(j-i, (abs(x-i-1) + 1 + abs(y-j-1) ), (abs(y-i-1) + 1 + abs(x-j-1) ) )
ans[r1] += 1
for i in ans[1:]:
print(i) | n,x,y = list(map(int, input().split()))
ans = [0]*(n)
for i in range(n-1):
for j in range(i+1, n):
#r1 = min(j-i, (abs(x-i-1) + 1 + abs(y-j-1) ), (abs(y-i-1) + 1 + abs(x-j-1) ) )
r1 = min(j - i, (abs(x - i - 1) + 1 + abs(y - j - 1)))
ans[r1] += 1
for i in ans[1:]:
print(i) | 10 | 11 | 254 | 319 | n, x, y = list(map(int, input().split()))
ans = [0] * (n)
for i in range(n - 1):
for j in range(i + 1, n):
r1 = min(
j - i,
(abs(x - i - 1) + 1 + abs(y - j - 1)),
(abs(y - i - 1) + 1 + abs(x - j - 1)),
)
ans[r1] += 1
for i in ans[1:]:
print(i)
| n, x, y = list(map(int, input().split()))
ans = [0] * (n)
for i in range(n - 1):
for j in range(i + 1, n):
# r1 = min(j-i, (abs(x-i-1) + 1 + abs(y-j-1) ), (abs(y-i-1) + 1 + abs(x-j-1) ) )
r1 = min(j - i, (abs(x - i - 1) + 1 + abs(y - j - 1)))
ans[r1] += 1
for i in ans[1:]:
print(i)
| false | 9.090909 | [
"- r1 = min(",
"- j - i,",
"- (abs(x - i - 1) + 1 + abs(y - j - 1)),",
"- (abs(y - i - 1) + 1 + abs(x - j - 1)),",
"- )",
"+ # r1 = min(j-i, (abs(x-i-1) + 1 + abs(y-j-1) ), (abs(y-i-1) + 1 + abs(x-j-1) ) )",
"+ r1 = min(j - i, (abs(x - i - 1... | false | 0.037999 | 0.045892 | 0.828006 | [
"s488827200",
"s181898902"
] |
u150984829 | p02283 | python | s108276761 | s527537306 | 3,900 | 3,540 | 63,248 | 63,328 | Accepted | Accepted | 9.23 | import sys
class Node:
__slots__ = ['key', 'left', 'right']
def __init__(self, key):
self.key = key
self.left = self.right = None
class BST:
__slots__ = ['root']
def __init__(self):
self.root = None
def insert(self, key):
x, y = self.root, None
while x != None: x, y = x.left if key < x.key else x.right, x
if y == None: self.root = Node(key)
elif key < y.key: y.left = Node(key)
else: y.right = Node(key)
def print_tree(self):
def inorder(node):
return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''
print((inorder(self.root)))
print((preorder(self.root)))
tree = BST()
eval(input())
for e in sys.stdin:
if e[0] == 'i': tree.insert(int(e[7:]))
else: tree.print_tree()
| import sys
class Node:
__slots__ = ['key', 'left', 'right']
def __init__(self, key):
self.key = key
self.left = self.right = None
root = None
def insert(key):
global root
x, y = root, None
while x is not None: x, y = x.left if key < x.key else x.right, x
if y is None: root = Node(key)
elif key < y.key: y.left = Node(key)
else: y.right = Node(key)
def inorder(node):
return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''
eval(input())
for e in sys.stdin:
if e[0] == 'i': insert(int(e[7:]))
else: print((inorder(root))); print((preorder(root)))
| 31 | 27 | 974 | 760 | import sys
class Node:
__slots__ = ["key", "left", "right"]
def __init__(self, key):
self.key = key
self.left = self.right = None
class BST:
__slots__ = ["root"]
def __init__(self):
self.root = None
def insert(self, key):
x, y = self.root, None
while x != None:
x, y = x.left if key < x.key else x.right, x
if y == None:
self.root = Node(key)
elif key < y.key:
y.left = Node(key)
else:
y.right = Node(key)
def print_tree(self):
def inorder(node):
return (
inorder(node.left) + f" {node.key}" + inorder(node.right)
if node
else ""
)
def preorder(node):
return (
f" {node.key}" + preorder(node.left) + preorder(node.right)
if node
else ""
)
print((inorder(self.root)))
print((preorder(self.root)))
tree = BST()
eval(input())
for e in sys.stdin:
if e[0] == "i":
tree.insert(int(e[7:]))
else:
tree.print_tree()
| import sys
class Node:
__slots__ = ["key", "left", "right"]
def __init__(self, key):
self.key = key
self.left = self.right = None
root = None
def insert(key):
global root
x, y = root, None
while x is not None:
x, y = x.left if key < x.key else x.right, x
if y is None:
root = Node(key)
elif key < y.key:
y.left = Node(key)
else:
y.right = Node(key)
def inorder(node):
return inorder(node.left) + f" {node.key}" + inorder(node.right) if node else ""
def preorder(node):
return f" {node.key}" + preorder(node.left) + preorder(node.right) if node else ""
eval(input())
for e in sys.stdin:
if e[0] == "i":
insert(int(e[7:]))
else:
print((inorder(root)))
print((preorder(root)))
| false | 12.903226 | [
"-class BST:",
"- __slots__ = [\"root\"]",
"-",
"- def __init__(self):",
"- self.root = None",
"-",
"- def insert(self, key):",
"- x, y = self.root, None",
"- while x != None:",
"- x, y = x.left if key < x.key else x.right, x",
"- if y == None:",
... | false | 0.084735 | 0.044645 | 1.897967 | [
"s108276761",
"s527537306"
] |
u736729525 | p02554 | python | s872605673 | s098205537 | 1,595 | 33 | 239,088 | 9,304 | Accepted | Accepted | 97.93 | import sys
def test(N):
answer = 0
for i in range(1, 10**N):
s = ("%0" + str(N) +"d") % i
if "0" in s and "9" in s:
#print(s)
answer += 1
return answer
def solve(N):
MOD = 10**9+7
dp = [[0, 0, 0, 0] for i in range(N+1)]
dp[0] = [1, 0, 0, 0]
A = 0
B = 1
C = 2
D = 3
for i in range(1, N+1):
# 0
dp[i][A] = (dp[i-1][A]*8) % MOD
dp[i][B] = (dp[i-1][A] + dp[i-1][B]*9) % MOD
dp[i][C] = (dp[i-1][A] + dp[i-1][C]*9) % MOD
dp[i][D] = (dp[i-1][B] + dp[i-1][C] + dp[i-1][D]*10) % MOD
#print(i, dp[i], sum(dp[i]))
return dp[N][D]
N = int(eval(input()))
print((solve(N)))
| import sys
def test(N):
MOD = 10**9+7
U = (pow(10, N, MOD) - 1)%MOD
notA = (pow(9, N, MOD) - 1)% MOD
notB = (pow(9, N, MOD) - 1)% MOD
A = (U - notA) % MOD
B = (U - notB) % MOD
AnorB = (pow(8, N, MOD) - 1)%MOD
AorB = (U - AnorB) % MOD
AandB = (A+B-AorB) %MOD
#print(f"{U=}, {AorB=}, {A=}, {B=}, {AnorB=}")
return AandB
def solve(N):
MOD = 10**9+7
dp = [[0, 0, 0, 0] for i in range(N+1)]
dp[0] = [1, 0, 0, 0]
A = 0
B = 1
C = 2
D = 3
for i in range(1, N+1):
dp[i][A] = (dp[i-1][A]*8) % MOD
dp[i][B] = (dp[i-1][A] + dp[i-1][B]*9) % MOD
dp[i][C] = (dp[i-1][A] + dp[i-1][C]*9) % MOD
dp[i][D] = (dp[i-1][B] + dp[i-1][C] + dp[i-1][D]*10) % MOD
#print(i, dp[i], sum(dp[i]))
return dp[N][D]
N = int(eval(input()))
print((test(N)))
#print(solve(N))
| 30 | 35 | 730 | 897 | import sys
def test(N):
answer = 0
for i in range(1, 10**N):
s = ("%0" + str(N) + "d") % i
if "0" in s and "9" in s:
# print(s)
answer += 1
return answer
def solve(N):
MOD = 10**9 + 7
dp = [[0, 0, 0, 0] for i in range(N + 1)]
dp[0] = [1, 0, 0, 0]
A = 0
B = 1
C = 2
D = 3
for i in range(1, N + 1):
# 0
dp[i][A] = (dp[i - 1][A] * 8) % MOD
dp[i][B] = (dp[i - 1][A] + dp[i - 1][B] * 9) % MOD
dp[i][C] = (dp[i - 1][A] + dp[i - 1][C] * 9) % MOD
dp[i][D] = (dp[i - 1][B] + dp[i - 1][C] + dp[i - 1][D] * 10) % MOD
# print(i, dp[i], sum(dp[i]))
return dp[N][D]
N = int(eval(input()))
print((solve(N)))
| import sys
def test(N):
MOD = 10**9 + 7
U = (pow(10, N, MOD) - 1) % MOD
notA = (pow(9, N, MOD) - 1) % MOD
notB = (pow(9, N, MOD) - 1) % MOD
A = (U - notA) % MOD
B = (U - notB) % MOD
AnorB = (pow(8, N, MOD) - 1) % MOD
AorB = (U - AnorB) % MOD
AandB = (A + B - AorB) % MOD
# print(f"{U=}, {AorB=}, {A=}, {B=}, {AnorB=}")
return AandB
def solve(N):
MOD = 10**9 + 7
dp = [[0, 0, 0, 0] for i in range(N + 1)]
dp[0] = [1, 0, 0, 0]
A = 0
B = 1
C = 2
D = 3
for i in range(1, N + 1):
dp[i][A] = (dp[i - 1][A] * 8) % MOD
dp[i][B] = (dp[i - 1][A] + dp[i - 1][B] * 9) % MOD
dp[i][C] = (dp[i - 1][A] + dp[i - 1][C] * 9) % MOD
dp[i][D] = (dp[i - 1][B] + dp[i - 1][C] + dp[i - 1][D] * 10) % MOD
# print(i, dp[i], sum(dp[i]))
return dp[N][D]
N = int(eval(input()))
print((test(N)))
# print(solve(N))
| false | 14.285714 | [
"- answer = 0",
"- for i in range(1, 10**N):",
"- s = (\"%0\" + str(N) + \"d\") % i",
"- if \"0\" in s and \"9\" in s:",
"- # print(s)",
"- answer += 1",
"- return answer",
"+ MOD = 10**9 + 7",
"+ U = (pow(10, N, MOD) - 1) % MOD",
"+ notA = (po... | false | 0.493833 | 0.037152 | 13.29214 | [
"s872605673",
"s098205537"
] |
u794910686 | p03127 | python | s199680594 | s759819982 | 330 | 72 | 23,112 | 14,224 | Accepted | Accepted | 78.18 | import numpy as np
N=int(eval(input()))
# A=list(map(int,input().split()))
A=[int(i) for i in input().split()]
A=np.array(sorted(A))
while np.any(A[:-1]>0):
try:
m=sorted(list(A[A>0]))[0]
A=list(A[1:]%m)
A.append(m)
A=np.array(A)
except:
continue
print(m)
| def gcd(a,b):
while b!=0:
a,b=b,a%b
return a
N=int(eval(input()))
# A=list(map(int,input().split()))
A=[int(i) for i in input().split()]
m=0
for a in A:
m=gcd(a,m)
print(m) | 16 | 13 | 315 | 200 | import numpy as np
N = int(eval(input()))
# A=list(map(int,input().split()))
A = [int(i) for i in input().split()]
A = np.array(sorted(A))
while np.any(A[:-1] > 0):
try:
m = sorted(list(A[A > 0]))[0]
A = list(A[1:] % m)
A.append(m)
A = np.array(A)
except:
continue
print(m)
| def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
N = int(eval(input()))
# A=list(map(int,input().split()))
A = [int(i) for i in input().split()]
m = 0
for a in A:
m = gcd(a, m)
print(m)
| false | 18.75 | [
"-import numpy as np",
"+def gcd(a, b):",
"+ while b != 0:",
"+ a, b = b, a % b",
"+ return a",
"+",
"-A = np.array(sorted(A))",
"-while np.any(A[:-1] > 0):",
"- try:",
"- m = sorted(list(A[A > 0]))[0]",
"- A = list(A[1:] % m)",
"- A.append(m)",
"- ... | false | 0.221363 | 0.044978 | 4.921577 | [
"s199680594",
"s759819982"
] |
u380524497 | p03546 | python | s157932128 | s063874666 | 32 | 29 | 3,064 | 3,188 | Accepted | Accepted | 9.38 | h, w = list(map(int, input().split()))
edges = [[] for i in range(10)]
for _from in range(10):
line = list(map(int, input().split()))
for to in range(10):
if _from == to:
continue
cost = line[to]
edges[_from].append([to, cost])
cost_to_1 = [10**5] * 10
cost_to_1[1] = 0
for num in range(10):
if num == 1:
continue
min_cost_to = [10**5] * 10
min_cost_to[num] = 0
todo = []
for to, cost in edges[num]:
if to == num:
continue
min_cost_to[to] = cost
todo.append(to)
while todo:
now = todo.pop()
cost = min_cost_to[now]
for to, add_cost in edges[now]:
if to == now:
continue
if cost + add_cost < min_cost_to[to]:
min_cost_to[to] = cost + add_cost
todo.append(to)
else:
continue
cost_to_1[num] = min_cost_to[1]
ans = 0
for i in range(h):
line = list(map(int, input().split()))
for num in line:
if num == -1 or num == 1:
continue
ans += cost_to_1[num]
print(ans)
| import heapq
h, w = list(map(int, input().split()))
costs = []
for i in range(10):
line = list(map(int, input().split()))
costs.append(line)
mini_cost_to_1_from = [10**4] * 10
mini_cost_to_1_from[1] = 0
for num in range(10):
if num == 1:
continue
seen = [False] * 10
todo = []
for to in range(10):
if num == to:
continue
cost = costs[num][to]
heapq.heappush(todo, [cost, to])
while todo:
cost, node = heapq.heappop(todo)
if node == 1:
mini_cost_to_1_from[num] = cost
break
if seen[node]:
continue
seen[node] = cost
for to in range(10):
if node == to:
continue
if seen[to]:
continue
add = costs[node][to]
heapq.heappush(todo, [cost+add, to])
num_count = [0] * 11
for i in range(h):
wall = list(map(int, input().split()))
for num in wall:
num_count[num] += 1
ans = 0
for num in range(10):
ans += num_count[num] * mini_cost_to_1_from[num]
print(ans)
| 50 | 53 | 1,183 | 1,152 | h, w = list(map(int, input().split()))
edges = [[] for i in range(10)]
for _from in range(10):
line = list(map(int, input().split()))
for to in range(10):
if _from == to:
continue
cost = line[to]
edges[_from].append([to, cost])
cost_to_1 = [10**5] * 10
cost_to_1[1] = 0
for num in range(10):
if num == 1:
continue
min_cost_to = [10**5] * 10
min_cost_to[num] = 0
todo = []
for to, cost in edges[num]:
if to == num:
continue
min_cost_to[to] = cost
todo.append(to)
while todo:
now = todo.pop()
cost = min_cost_to[now]
for to, add_cost in edges[now]:
if to == now:
continue
if cost + add_cost < min_cost_to[to]:
min_cost_to[to] = cost + add_cost
todo.append(to)
else:
continue
cost_to_1[num] = min_cost_to[1]
ans = 0
for i in range(h):
line = list(map(int, input().split()))
for num in line:
if num == -1 or num == 1:
continue
ans += cost_to_1[num]
print(ans)
| import heapq
h, w = list(map(int, input().split()))
costs = []
for i in range(10):
line = list(map(int, input().split()))
costs.append(line)
mini_cost_to_1_from = [10**4] * 10
mini_cost_to_1_from[1] = 0
for num in range(10):
if num == 1:
continue
seen = [False] * 10
todo = []
for to in range(10):
if num == to:
continue
cost = costs[num][to]
heapq.heappush(todo, [cost, to])
while todo:
cost, node = heapq.heappop(todo)
if node == 1:
mini_cost_to_1_from[num] = cost
break
if seen[node]:
continue
seen[node] = cost
for to in range(10):
if node == to:
continue
if seen[to]:
continue
add = costs[node][to]
heapq.heappush(todo, [cost + add, to])
num_count = [0] * 11
for i in range(h):
wall = list(map(int, input().split()))
for num in wall:
num_count[num] += 1
ans = 0
for num in range(10):
ans += num_count[num] * mini_cost_to_1_from[num]
print(ans)
| false | 5.660377 | [
"+import heapq",
"+",
"-edges = [[] for i in range(10)]",
"-for _from in range(10):",
"+costs = []",
"+for i in range(10):",
"- for to in range(10):",
"- if _from == to:",
"- continue",
"- cost = line[to]",
"- edges[_from].append([to, cost])",
"-cost_to_1 = [... | false | 0.039905 | 0.050318 | 0.793049 | [
"s157932128",
"s063874666"
] |
u309977459 | p03681 | python | s551031113 | s197474362 | 710 | 46 | 5,180 | 7,060 | Accepted | Accepted | 93.52 | from math import factorial as F
N, M = list(map(int, input().split()))
N, M = min(N, M), max(N, M)
mod = 10**9+7
if M-N > 1:
print((0))
elif M-N == 1:
print((F(M)*F(N) % mod))
else:
print((F(M)**2*2 % mod))
| N, M = list(map(int, input().split()))
N, M = min(N, M), max(N, M)
mod = 10**9+7
g = [1, 1]
for i in range(2, M+1):
g.append((g[-1] * i) % mod)
if M-N > 1:
print((0))
elif M-N == 1:
print((g[M]*g[N] % mod))
else:
print((g[M]**2*2 % mod))
| 11 | 14 | 218 | 257 | from math import factorial as F
N, M = list(map(int, input().split()))
N, M = min(N, M), max(N, M)
mod = 10**9 + 7
if M - N > 1:
print((0))
elif M - N == 1:
print((F(M) * F(N) % mod))
else:
print((F(M) ** 2 * 2 % mod))
| N, M = list(map(int, input().split()))
N, M = min(N, M), max(N, M)
mod = 10**9 + 7
g = [1, 1]
for i in range(2, M + 1):
g.append((g[-1] * i) % mod)
if M - N > 1:
print((0))
elif M - N == 1:
print((g[M] * g[N] % mod))
else:
print((g[M] ** 2 * 2 % mod))
| false | 21.428571 | [
"-from math import factorial as F",
"-",
"+g = [1, 1]",
"+for i in range(2, M + 1):",
"+ g.append((g[-1] * i) % mod)",
"- print((F(M) * F(N) % mod))",
"+ print((g[M] * g[N] % mod))",
"- print((F(M) ** 2 * 2 % mod))",
"+ print((g[M] ** 2 * 2 % mod))"
] | false | 0.043171 | 0.040479 | 1.066507 | [
"s551031113",
"s197474362"
] |
u011062360 | p03805 | python | s304056056 | s409137496 | 28 | 21 | 3,188 | 3,064 | Accepted | Accepted | 25 | from itertools import permutations
n, m = list(map(int, input().split()))
list_AB = [ list(map(int,input().split(" "))) for i in range(m)]
list_MAP = [[0]*n for _ in range(n)]
list_N = [i for i in range(2, n+1)]
for a, b in list_AB:
list_MAP[a-1][b-1] = 1
list_MAP[b-1][a-1] = 1
ans = 0
for l in permutations(list_N, n-1):
cnt = 0
p = 1
q = 0
for num in l:
q = num
cnt += list_MAP[p-1][q-1]
p = num
if cnt == n-1:
ans += 1
print(ans) | n, m = list(map(int, input().split()))
list_MAP = [[0]*n for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
list_MAP[a-1][b-1] = 1
list_MAP[b-1][a-1] = 1
dp = [[0]*n for _ in range(1<<n)]
dp[1][0] = 1
for num in range(1<<n):
for v in range(n):
if num & (1<<v) == 0:
continue
sub = num ^ (1<<v)
for u in range(n):
if sub & (1<<u) and list_MAP[v][u]:
dp[num][v] += dp[sub][u]
ans = sum(dp[(1 << n) - 1][u] for u in range(1, n))
print(ans) | 25 | 20 | 516 | 551 | from itertools import permutations
n, m = list(map(int, input().split()))
list_AB = [list(map(int, input().split(" "))) for i in range(m)]
list_MAP = [[0] * n for _ in range(n)]
list_N = [i for i in range(2, n + 1)]
for a, b in list_AB:
list_MAP[a - 1][b - 1] = 1
list_MAP[b - 1][a - 1] = 1
ans = 0
for l in permutations(list_N, n - 1):
cnt = 0
p = 1
q = 0
for num in l:
q = num
cnt += list_MAP[p - 1][q - 1]
p = num
if cnt == n - 1:
ans += 1
print(ans)
| n, m = list(map(int, input().split()))
list_MAP = [[0] * n for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
list_MAP[a - 1][b - 1] = 1
list_MAP[b - 1][a - 1] = 1
dp = [[0] * n for _ in range(1 << n)]
dp[1][0] = 1
for num in range(1 << n):
for v in range(n):
if num & (1 << v) == 0:
continue
sub = num ^ (1 << v)
for u in range(n):
if sub & (1 << u) and list_MAP[v][u]:
dp[num][v] += dp[sub][u]
ans = sum(dp[(1 << n) - 1][u] for u in range(1, n))
print(ans)
| false | 20 | [
"-from itertools import permutations",
"-",
"-list_AB = [list(map(int, input().split(\" \"))) for i in range(m)]",
"-list_N = [i for i in range(2, n + 1)]",
"-for a, b in list_AB:",
"+for _ in range(m):",
"+ a, b = list(map(int, input().split()))",
"-ans = 0",
"-for l in permutations(list_N, n - ... | false | 0.044716 | 0.037186 | 1.202479 | [
"s304056056",
"s409137496"
] |
u463655976 | p03559 | python | s208319882 | s160478110 | 575 | 328 | 43,892 | 22,720 | Accepted | Accepted | 42.96 | N = int(eval(input()))
L = []
L.extend(((int(x), 3) for x in input().split()))
L.extend(((int(x), 2) for x in input().split()))
L.extend(((int(x), 1) for x in input().split()))
L = sorted(L, reverse=True)
cnt_C = 0
cnt_B = 0
cnt_A = 0
for x, i in L:
if i == 1:
cnt_C += 1
elif i == 2:
cnt_B += cnt_C
elif i == 3:
cnt_A += cnt_B
print(cnt_A)
| N = int(eval(input()))
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
cur_l = 0
cur_r = 0
p = 0
for cur_mid in B:
while cur_l < len(A):
if A[cur_l] >= cur_mid:
break
cur_l += 1
while cur_r < len(C):
if cur_mid < C[cur_r]:
break
cur_r += 1
p += cur_l * (len(C) - cur_r)
print(p)
| 21 | 21 | 398 | 430 | N = int(eval(input()))
L = []
L.extend(((int(x), 3) for x in input().split()))
L.extend(((int(x), 2) for x in input().split()))
L.extend(((int(x), 1) for x in input().split()))
L = sorted(L, reverse=True)
cnt_C = 0
cnt_B = 0
cnt_A = 0
for x, i in L:
if i == 1:
cnt_C += 1
elif i == 2:
cnt_B += cnt_C
elif i == 3:
cnt_A += cnt_B
print(cnt_A)
| N = int(eval(input()))
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
cur_l = 0
cur_r = 0
p = 0
for cur_mid in B:
while cur_l < len(A):
if A[cur_l] >= cur_mid:
break
cur_l += 1
while cur_r < len(C):
if cur_mid < C[cur_r]:
break
cur_r += 1
p += cur_l * (len(C) - cur_r)
print(p)
| false | 0 | [
"-L = []",
"-L.extend(((int(x), 3) for x in input().split()))",
"-L.extend(((int(x), 2) for x in input().split()))",
"-L.extend(((int(x), 1) for x in input().split()))",
"-L = sorted(L, reverse=True)",
"-cnt_C = 0",
"-cnt_B = 0",
"-cnt_A = 0",
"-for x, i in L:",
"- if i == 1:",
"- cnt_... | false | 0.035886 | 0.040258 | 0.891406 | [
"s208319882",
"s160478110"
] |
u891847179 | p02726 | python | s892031915 | s046778614 | 1,618 | 1,133 | 3,444 | 3,444 | Accepted | Accepted | 29.98 | N, X, Y = list(map(int, input().split()))
res = [0] * N
for j in range(1, N + 1):
for i in range(1, j):
if i == X and Y == j:
key = 1
else:
key = int(min(j - i, abs(X - i) + abs(Y - j) + 1))
res[key] += 1
for i in range(1, N):
print((res[i])) | N, X, Y = list(map(int, input().split()))
res = [0] * N
for j in range(1, N + 1):
for i in range(1, j):
res[min(j - i, abs(X - i) + abs(Y - j) + 1)] += 1
for i in range(1, N):
print((res[i]))
| 12 | 8 | 308 | 214 | N, X, Y = list(map(int, input().split()))
res = [0] * N
for j in range(1, N + 1):
for i in range(1, j):
if i == X and Y == j:
key = 1
else:
key = int(min(j - i, abs(X - i) + abs(Y - j) + 1))
res[key] += 1
for i in range(1, N):
print((res[i]))
| N, X, Y = list(map(int, input().split()))
res = [0] * N
for j in range(1, N + 1):
for i in range(1, j):
res[min(j - i, abs(X - i) + abs(Y - j) + 1)] += 1
for i in range(1, N):
print((res[i]))
| false | 33.333333 | [
"- if i == X and Y == j:",
"- key = 1",
"- else:",
"- key = int(min(j - i, abs(X - i) + abs(Y - j) + 1))",
"- res[key] += 1",
"+ res[min(j - i, abs(X - i) + abs(Y - j) + 1)] += 1"
] | false | 0.035707 | 0.037946 | 0.941003 | [
"s892031915",
"s046778614"
] |
u371763408 | p03637 | python | s379116677 | s087373955 | 96 | 73 | 14,480 | 11,480 | Accepted | Accepted | 23.96 | n=int(eval(input()))
A=list(map(int,input().split()))
four=list([x for x in A if x%4==0])
even=list([x for x in A if x%2==0])
odd=list([x for x in A if x%2==1])
# print(len(even))
# print(len(odd))
# print(len(four))
#全ての成分が偶数
if len(even)==len(A):
print('Yes')
exit()
#4の倍数が奇数の半分以上ある(切り下げ)かつ2の倍数が偶数個かつ元が偶数個
if len(four)>=len(odd)/2 and (len(even)-len(four))%2==0:
if (len(even)-len(four))%2>0:
print('Yes')
print('aa')
exit()
# #4の倍数が奇数の半分以上ある(切り上げ)かつ4の倍数が奇数個あるかつ2の倍数が奇数個あるかつ元が奇数個
if len(four)>=len(odd)/2 and len(four)%2!=0 and len(A)%2!=0:
print('Yes')
exit()
if len(four)>=len(odd)/2 and len(four)%2==0 and len(A)%2==0:
print('Yes')
exit()
else:
print('No') | #強い人のコード
N=int(eval(input()))
ans='Yes'
odd=0
four=0
for x in map(int,input().split()):
if x%2==1:
odd+=1
elif x%4==0:
four+=1
#4の倍数+1が奇数の数より少ないとダメ
if four+1<odd:
ans='No'
#4の倍数+1が奇数と同じかつその合計が全体より少ないとダメ(ひとつ奇数が余ることになる)
elif four+1==odd and odd+four<N:
ans='No'
print(ans)
| 28 | 17 | 714 | 313 | n = int(eval(input()))
A = list(map(int, input().split()))
four = list([x for x in A if x % 4 == 0])
even = list([x for x in A if x % 2 == 0])
odd = list([x for x in A if x % 2 == 1])
# print(len(even))
# print(len(odd))
# print(len(four))
# 全ての成分が偶数
if len(even) == len(A):
print("Yes")
exit()
# 4の倍数が奇数の半分以上ある(切り下げ)かつ2の倍数が偶数個かつ元が偶数個
if len(four) >= len(odd) / 2 and (len(even) - len(four)) % 2 == 0:
if (len(even) - len(four)) % 2 > 0:
print("Yes")
print("aa")
exit()
# #4の倍数が奇数の半分以上ある(切り上げ)かつ4の倍数が奇数個あるかつ2の倍数が奇数個あるかつ元が奇数個
if len(four) >= len(odd) / 2 and len(four) % 2 != 0 and len(A) % 2 != 0:
print("Yes")
exit()
if len(four) >= len(odd) / 2 and len(four) % 2 == 0 and len(A) % 2 == 0:
print("Yes")
exit()
else:
print("No")
| # 強い人のコード
N = int(eval(input()))
ans = "Yes"
odd = 0
four = 0
for x in map(int, input().split()):
if x % 2 == 1:
odd += 1
elif x % 4 == 0:
four += 1
# 4の倍数+1が奇数の数より少ないとダメ
if four + 1 < odd:
ans = "No"
# 4の倍数+1が奇数と同じかつその合計が全体より少ないとダメ(ひとつ奇数が余ることになる)
elif four + 1 == odd and odd + four < N:
ans = "No"
print(ans)
| false | 39.285714 | [
"-n = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-four = list([x for x in A if x % 4 == 0])",
"-even = list([x for x in A if x % 2 == 0])",
"-odd = list([x for x in A if x % 2 == 1])",
"-# print(len(even))",
"-# print(len(odd))",
"-# print(len(four))",
"-# 全ての成分が偶数",
"-if len(ev... | false | 0.042519 | 0.04707 | 0.903309 | [
"s379116677",
"s087373955"
] |
u077291787 | p03317 | python | s904821327 | s115720406 | 40 | 17 | 13,812 | 3,060 | Accepted | Accepted | 57.5 | # ABC099C - Minimization
from math import ceil
N, K = list(map(int, input().rstrip().split()))
_ = list(map(int, input().rstrip().split()))
print((1 + ceil((N - K) / (K - 1)))) | # ARC099C - Minimization
from math import ceil
N, K = list(map(int, input().rstrip().split()))
print((1 + ceil((N - K) / (K - 1)))) | 6 | 5 | 180 | 134 | # ABC099C - Minimization
from math import ceil
N, K = list(map(int, input().rstrip().split()))
_ = list(map(int, input().rstrip().split()))
print((1 + ceil((N - K) / (K - 1))))
| # ARC099C - Minimization
from math import ceil
N, K = list(map(int, input().rstrip().split()))
print((1 + ceil((N - K) / (K - 1))))
| false | 16.666667 | [
"-# ABC099C - Minimization",
"+# ARC099C - Minimization",
"-_ = list(map(int, input().rstrip().split()))"
] | false | 0.036634 | 0.037942 | 0.965546 | [
"s904821327",
"s115720406"
] |
u063091489 | p00033 | python | s420909763 | s878795451 | 20 | 10 | 4,232 | 4,220 | Accepted | Accepted | 50 |
N = int(input())
for c in range(N):
B = [0]
C = [0]
def dfs(depth):
if depth == 10:
return True
res = False
if B[-1] < A[depth]:
B.append(A[depth])
res |= dfs(depth+1)
del B[-1]
if C[-1] < A[depth]:
C.append(A[depth])
res |= dfs(depth+1)
del C[-1]
return res
A = list(map(int, input().split(" ")))
print("YES" if dfs(0) else "NO")
| N = int(input())
def dfs(depth, l, r):
if depth == 10:
return True
res = False
if l < A[depth]:
res |= dfs(depth+1, A[depth], r)
if r < A[depth]:
res |= dfs(depth+1, l, A[depth])
return res
for c in range(N):
A = list(map(int, input().split(" ")))
print("YES" if dfs(0, 0, 0) else "NO")
| 27 | 16 | 545 | 361 | N = int(input())
for c in range(N):
B = [0]
C = [0]
def dfs(depth):
if depth == 10:
return True
res = False
if B[-1] < A[depth]:
B.append(A[depth])
res |= dfs(depth + 1)
del B[-1]
if C[-1] < A[depth]:
C.append(A[depth])
res |= dfs(depth + 1)
del C[-1]
return res
A = list(map(int, input().split(" ")))
print("YES" if dfs(0) else "NO")
| N = int(input())
def dfs(depth, l, r):
if depth == 10:
return True
res = False
if l < A[depth]:
res |= dfs(depth + 1, A[depth], r)
if r < A[depth]:
res |= dfs(depth + 1, l, A[depth])
return res
for c in range(N):
A = list(map(int, input().split(" ")))
print("YES" if dfs(0, 0, 0) else "NO")
| false | 40.740741 | [
"+",
"+",
"+def dfs(depth, l, r):",
"+ if depth == 10:",
"+ return True",
"+ res = False",
"+ if l < A[depth]:",
"+ res |= dfs(depth + 1, A[depth], r)",
"+ if r < A[depth]:",
"+ res |= dfs(depth + 1, l, A[depth])",
"+ return res",
"+",
"+",
"- B = [0]... | false | 0.090277 | 0.153656 | 0.587524 | [
"s420909763",
"s878795451"
] |
u010110540 | p03805 | python | s770426551 | s625321131 | 30 | 18 | 3,064 | 3,064 | Accepted | Accepted | 40 | import itertools
N, M = list(map(int, input().split()))
adj_matrix = [[0]* N for _ in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
adj_matrix[a-1][b-1] = 1
adj_matrix[b-1][a-1] = 1
cnt = 0
for each in itertools.permutations(list(range(N))):
if each[0] != 0:
break
factor = 1
for i in range(N-1):
factor *= adj_matrix[each[i]][each[i+1]]
cnt += factor
print(cnt) | #bid DP
N, M = list(map(int, input().split()))
g = [[] for i in range(N)] #隣接リスト
for i in range(M):
a, b = list(map(int, input().split()))
g[a-1].append(b-1)
g[b-1].append(a-1)
memo = {}
All_used = (1 << N) -1
def dfs(v, used):
if used == All_used:
return 1
key = (v, used)
if key in memo:
return memo[key]
ans = 0
for u in g[v]:
if (used >> u) & 1 == 1:
continue
used ^= (1 << u)
ans += dfs(u, used)
used ^= (1 << u)
memo[key] = ans
return ans
print((dfs(0, 1))) | 21 | 34 | 435 | 615 | import itertools
N, M = list(map(int, input().split()))
adj_matrix = [[0] * N for _ in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
adj_matrix[a - 1][b - 1] = 1
adj_matrix[b - 1][a - 1] = 1
cnt = 0
for each in itertools.permutations(list(range(N))):
if each[0] != 0:
break
factor = 1
for i in range(N - 1):
factor *= adj_matrix[each[i]][each[i + 1]]
cnt += factor
print(cnt)
| # bid DP
N, M = list(map(int, input().split()))
g = [[] for i in range(N)] # 隣接リスト
for i in range(M):
a, b = list(map(int, input().split()))
g[a - 1].append(b - 1)
g[b - 1].append(a - 1)
memo = {}
All_used = (1 << N) - 1
def dfs(v, used):
if used == All_used:
return 1
key = (v, used)
if key in memo:
return memo[key]
ans = 0
for u in g[v]:
if (used >> u) & 1 == 1:
continue
used ^= 1 << u
ans += dfs(u, used)
used ^= 1 << u
memo[key] = ans
return ans
print((dfs(0, 1)))
| false | 38.235294 | [
"-import itertools",
"-",
"+# bid DP",
"-adj_matrix = [[0] * N for _ in range(N)]",
"+g = [[] for i in range(N)] # 隣接リスト",
"- adj_matrix[a - 1][b - 1] = 1",
"- adj_matrix[b - 1][a - 1] = 1",
"-cnt = 0",
"-for each in itertools.permutations(list(range(N))):",
"- if each[0] != 0:",
"- ... | false | 0.046998 | 0.037033 | 1.269091 | [
"s770426551",
"s625321131"
] |
u600402037 | p02728 | python | s619059058 | s105008913 | 1,615 | 1,387 | 125,104 | 125,232 | Accepted | Accepted | 14.12 | # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 全方位木DP、葉側と根側
N = ir()
graph = [[] for _ in range(N+1)] # 1-indexed
for _ in range(N-1):
a, b = lr()
graph[a].append(b)
graph[b].append(a)
MOD = 10 ** 9 + 7
fact = [1] * (N + 10)
for n in range(1, N + 10):
fact[n] = n * fact[n - 1] % MOD
fact_inv = [1] * (N + 10)
fact_inv[-1] = pow(fact[-1], MOD - 2, MOD)
for n in range(N + 9, 0, -1):
fact_inv[n - 1] = fact_inv[n] * n % MOD
root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
cur = stack.pop()
order.append(cur)
for next in graph[cur]:
if next == parent[cur]:
continue
parent[next] = cur
stack.append(next)
size_down = [0] * (N+1) # 1-indexed
dp_down = [1] * (N+1) # 葉側の組み合わせ
for v in order[::-1]:
dp_down[v] *= fact[size_down[v]]
dp_down[v] %= MOD
p = parent[v]
s = size_down[v] + 1
size_down[p] += s
dp_down[p] *= fact_inv[s] * dp_down[v]
dp_down[p] %= MOD
size_up = [N-x-1 for x in size_down] # 自分含めない
dp_up = [1] * (N+1) # 根側の組み合わせ
for v in order[1:]:
p = parent[v]
x = dp_down[p]
x *= dp_up[p]
x *= fact_inv[size_down[p]]
x *= fact[size_down[v] + 1]
x *= pow(dp_down[v], MOD-2, MOD)
x %= MOD
x *= fact[size_up[v]-1]
x *= fact_inv[size_up[p]]
dp_up[v] = x % MOD
size_up[1] = 0; dp_up[1] = 1
for xd, xu, sd, su in zip(dp_down[1:], dp_up[1:], size_down[1:], size_up[1:]):
answer = xd * xu * fact[sd+su] * fact_inv[sd] * fact_inv[su] % MOD
print((answer % MOD))
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 全方位木DP、葉側と根側
N = ir()
graph = [[] for _ in range(N+1)] # 1-indexed
for _ in range(N-1):
a, b = lr()
graph[a].append(b)
graph[b].append(a)
MOD = 10 ** 9 + 7
fact = [1] * (N + 10)
for n in range(1, N + 10):
fact[n] = n * fact[n - 1] % MOD
fact_inv = [1] * (N + 10)
fact_inv[-1] = pow(fact[-1], MOD - 2, MOD)
for n in range(N + 9, 0, -1):
fact_inv[n - 1] = fact_inv[n] * n % MOD
root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
cur = stack.pop()
order.append(cur)
for next in graph[cur]:
if next == parent[cur]:
continue
parent[next] = cur
stack.append(next)
size_down = [0] * (N+1) # 1-indexed
dp_down = [1] * (N+1) # 葉側の組み合わせ
for v in order[::-1]:
dp_down[v] *= fact[size_down[v]]
dp_down[v] %= MOD
p = parent[v]
s = size_down[v] + 1
size_down[p] += s
dp_down[p] *= fact_inv[s] * dp_down[v]
dp_down[p] %= MOD
size_up = [N-x-1 for x in size_down] # 自分含めない
dp_up = [1] * (N+1) # 根側の組み合わせ
for v in order[1:]:
p = parent[v]
x = dp_down[p]
x *= dp_up[p]
x *= fact_inv[size_down[p]]
x *= fact[size_down[v] + 1]
x *= pow(dp_down[v], MOD-2, MOD)
x %= MOD
x *= fact[size_up[v]-1]
x *= fact_inv[size_up[p]]
dp_up[v] = x % MOD
for xd, xu, sd, su in zip(dp_down[1:], dp_up[1:], size_down[1:], size_up[1:]):
answer = xd * xu * fact[sd+su] * fact_inv[sd] * fact_inv[su] % MOD
print((answer % MOD))
| 67 | 66 | 1,690 | 1,660 | # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 全方位木DP、葉側と根側
N = ir()
graph = [[] for _ in range(N + 1)] # 1-indexed
for _ in range(N - 1):
a, b = lr()
graph[a].append(b)
graph[b].append(a)
MOD = 10**9 + 7
fact = [1] * (N + 10)
for n in range(1, N + 10):
fact[n] = n * fact[n - 1] % MOD
fact_inv = [1] * (N + 10)
fact_inv[-1] = pow(fact[-1], MOD - 2, MOD)
for n in range(N + 9, 0, -1):
fact_inv[n - 1] = fact_inv[n] * n % MOD
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
cur = stack.pop()
order.append(cur)
for next in graph[cur]:
if next == parent[cur]:
continue
parent[next] = cur
stack.append(next)
size_down = [0] * (N + 1) # 1-indexed
dp_down = [1] * (N + 1) # 葉側の組み合わせ
for v in order[::-1]:
dp_down[v] *= fact[size_down[v]]
dp_down[v] %= MOD
p = parent[v]
s = size_down[v] + 1
size_down[p] += s
dp_down[p] *= fact_inv[s] * dp_down[v]
dp_down[p] %= MOD
size_up = [N - x - 1 for x in size_down] # 自分含めない
dp_up = [1] * (N + 1) # 根側の組み合わせ
for v in order[1:]:
p = parent[v]
x = dp_down[p]
x *= dp_up[p]
x *= fact_inv[size_down[p]]
x *= fact[size_down[v] + 1]
x *= pow(dp_down[v], MOD - 2, MOD)
x %= MOD
x *= fact[size_up[v] - 1]
x *= fact_inv[size_up[p]]
dp_up[v] = x % MOD
size_up[1] = 0
dp_up[1] = 1
for xd, xu, sd, su in zip(dp_down[1:], dp_up[1:], size_down[1:], size_up[1:]):
answer = xd * xu * fact[sd + su] * fact_inv[sd] * fact_inv[su] % MOD
print((answer % MOD))
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 全方位木DP、葉側と根側
N = ir()
graph = [[] for _ in range(N + 1)] # 1-indexed
for _ in range(N - 1):
a, b = lr()
graph[a].append(b)
graph[b].append(a)
MOD = 10**9 + 7
fact = [1] * (N + 10)
for n in range(1, N + 10):
fact[n] = n * fact[n - 1] % MOD
fact_inv = [1] * (N + 10)
fact_inv[-1] = pow(fact[-1], MOD - 2, MOD)
for n in range(N + 9, 0, -1):
fact_inv[n - 1] = fact_inv[n] * n % MOD
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
cur = stack.pop()
order.append(cur)
for next in graph[cur]:
if next == parent[cur]:
continue
parent[next] = cur
stack.append(next)
size_down = [0] * (N + 1) # 1-indexed
dp_down = [1] * (N + 1) # 葉側の組み合わせ
for v in order[::-1]:
dp_down[v] *= fact[size_down[v]]
dp_down[v] %= MOD
p = parent[v]
s = size_down[v] + 1
size_down[p] += s
dp_down[p] *= fact_inv[s] * dp_down[v]
dp_down[p] %= MOD
size_up = [N - x - 1 for x in size_down] # 自分含めない
dp_up = [1] * (N + 1) # 根側の組み合わせ
for v in order[1:]:
p = parent[v]
x = dp_down[p]
x *= dp_up[p]
x *= fact_inv[size_down[p]]
x *= fact[size_down[v] + 1]
x *= pow(dp_down[v], MOD - 2, MOD)
x %= MOD
x *= fact[size_up[v] - 1]
x *= fact_inv[size_up[p]]
dp_up[v] = x % MOD
for xd, xu, sd, su in zip(dp_down[1:], dp_up[1:], size_down[1:], size_up[1:]):
answer = xd * xu * fact[sd + su] * fact_inv[sd] * fact_inv[su] % MOD
print((answer % MOD))
| false | 1.492537 | [
"-size_up[1] = 0",
"-dp_up[1] = 1"
] | false | 0.037391 | 0.037591 | 0.994691 | [
"s619059058",
"s105008913"
] |
u811733736 | p00181 | python | s444167361 | s023462450 | 80 | 60 | 7,744 | 7,700 | Accepted | Accepted | 25 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181
"""
import sys
from sys import stdin
input = stdin.readline
def Cond(m, n, mid, books):
if max(books) > mid:
return False
rem = mid
while books:
while rem >= books[0]:
rem -= books[0]
books = books[1:]
if len(books) == 0:
break
rem = mid
m -= 1
if m >= 0:
return True
else:
return False
def solve(m, n, books):
ub = 1500000
lb = 0
min_width = float('inf')
for i in range(100):
mid = (ub + lb) // 2
if Cond(m, n, mid, books):
min_width = min(min_width, mid)
ub = mid
else:
lb = mid
return min_width
def main(args):
while True:
m, n = list(map(int, input().split()))
if m == 0 and n == 0:
break
books = [int(eval(input())) for _ in range(n)]
result = solve(m, n, books)
print(result)
if __name__ == '__main__':
main(sys.argv[1:]) | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181
"""
import sys
from sys import stdin
input = stdin.readline
def Cond(m, n, mid, books):
if max(books) > mid:
return False
rem = mid
while books:
while rem >= books[0]:
rem -= books[0]
books = books[1:]
if len(books) == 0:
break
rem = mid
m -= 1
if m >= 0:
return True
else:
return False
def solve(m, n, books):
ub = 1500000
lb = 0
min_width = float('inf')
for i in range(50):
mid = (ub + lb) // 2
if Cond(m, n, mid, books):
min_width = min(min_width, mid)
ub = mid
else:
lb = mid
return min_width
def main(args):
while True:
m, n = list(map(int, input().split()))
if m == 0 and n == 0:
break
books = [int(eval(input())) for _ in range(n)]
result = solve(m, n, books)
print(result)
if __name__ == '__main__':
main(sys.argv[1:]) | 59 | 59 | 1,137 | 1,136 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181
"""
import sys
from sys import stdin
input = stdin.readline
def Cond(m, n, mid, books):
if max(books) > mid:
return False
rem = mid
while books:
while rem >= books[0]:
rem -= books[0]
books = books[1:]
if len(books) == 0:
break
rem = mid
m -= 1
if m >= 0:
return True
else:
return False
def solve(m, n, books):
ub = 1500000
lb = 0
min_width = float("inf")
for i in range(100):
mid = (ub + lb) // 2
if Cond(m, n, mid, books):
min_width = min(min_width, mid)
ub = mid
else:
lb = mid
return min_width
def main(args):
while True:
m, n = list(map(int, input().split()))
if m == 0 and n == 0:
break
books = [int(eval(input())) for _ in range(n)]
result = solve(m, n, books)
print(result)
if __name__ == "__main__":
main(sys.argv[1:])
| # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181
"""
import sys
from sys import stdin
input = stdin.readline
def Cond(m, n, mid, books):
if max(books) > mid:
return False
rem = mid
while books:
while rem >= books[0]:
rem -= books[0]
books = books[1:]
if len(books) == 0:
break
rem = mid
m -= 1
if m >= 0:
return True
else:
return False
def solve(m, n, books):
ub = 1500000
lb = 0
min_width = float("inf")
for i in range(50):
mid = (ub + lb) // 2
if Cond(m, n, mid, books):
min_width = min(min_width, mid)
ub = mid
else:
lb = mid
return min_width
def main(args):
while True:
m, n = list(map(int, input().split()))
if m == 0 and n == 0:
break
books = [int(eval(input())) for _ in range(n)]
result = solve(m, n, books)
print(result)
if __name__ == "__main__":
main(sys.argv[1:])
| false | 0 | [
"- for i in range(100):",
"+ for i in range(50):"
] | false | 0.046067 | 0.043554 | 1.057697 | [
"s444167361",
"s023462450"
] |
u969850098 | p02720 | python | s635408131 | s652578827 | 234 | 205 | 17,012 | 17,004 | Accepted | Accepted | 12.39 | from collections import deque
K = int(eval(input()))
que = deque(['1', '2', '3', '4', '5', '6', '7', '8', '9'])
while K:
if K == 1:
ans = que.popleft()
break
K -= 1
v = que.popleft()
if v[-1] == '0':
que.append(v + '0')
que.append(v + '1')
elif v[-1] == '9':
que.append(v + '8')
que.append(v + '9')
else:
que.append(v + str(int(v[-1]) - 1))
que.append(v + str(int(v[-1])))
que.append(v + str(int(v[-1]) + 1))
print(ans) | from collections import deque
def main():
K = int(eval(input()))
que = deque(['1', '2', '3', '4', '5', '6', '7', '8', '9'])
while K:
if K == 1:
ans = que.popleft()
break
K -= 1
v = que.popleft()
if v[-1] == '0':
que.append(v + '0')
que.append(v + '1')
elif v[-1] == '9':
que.append(v + '8')
que.append(v + '9')
else:
que.append(v + str(int(v[-1]) - 1))
que.append(v + str(int(v[-1])))
que.append(v + str(int(v[-1]) + 1))
print(ans)
if __name__ == '__main__':
main() | 23 | 28 | 534 | 667 | from collections import deque
K = int(eval(input()))
que = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
while K:
if K == 1:
ans = que.popleft()
break
K -= 1
v = que.popleft()
if v[-1] == "0":
que.append(v + "0")
que.append(v + "1")
elif v[-1] == "9":
que.append(v + "8")
que.append(v + "9")
else:
que.append(v + str(int(v[-1]) - 1))
que.append(v + str(int(v[-1])))
que.append(v + str(int(v[-1]) + 1))
print(ans)
| from collections import deque
def main():
K = int(eval(input()))
que = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
while K:
if K == 1:
ans = que.popleft()
break
K -= 1
v = que.popleft()
if v[-1] == "0":
que.append(v + "0")
que.append(v + "1")
elif v[-1] == "9":
que.append(v + "8")
que.append(v + "9")
else:
que.append(v + str(int(v[-1]) - 1))
que.append(v + str(int(v[-1])))
que.append(v + str(int(v[-1]) + 1))
print(ans)
if __name__ == "__main__":
main()
| false | 17.857143 | [
"-K = int(eval(input()))",
"-que = deque([\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"])",
"-while K:",
"- if K == 1:",
"- ans = que.popleft()",
"- break",
"- K -= 1",
"- v = que.popleft()",
"- if v[-1] == \"0\":",
"- que.append(v + \"0\")",
"- ... | false | 0.056107 | 0.067579 | 0.830241 | [
"s635408131",
"s652578827"
] |
u598296382 | p02713 | python | s208234853 | s672143910 | 304 | 190 | 75,448 | 72,456 | Accepted | Accepted | 37.5 | import math
k = int(eval(input()))
ab = []
ans = 0
for a in range(1,k+1):
for b in range(1,k+1):
if a % b == 0:
ab.append(b)
elif b % a == 0:
ab.append(a)
else:
ab.append(math.gcd(a, b))
for i in ab:
for c in range(1,k+1):
if i % c == 0:
ans += c
elif c % i == 0:
ans += i
else:
ans += math.gcd(i, c)
print(ans) | import math
k = int(eval(input()))
ab = []
ans = 0
for a in range(1,k+1):
for b in range(1,k+1):
ab.append(math.gcd(a, b))
for i in ab:
for c in range(1,k+1):
ans += math.gcd(i, c)
print(ans) | 24 | 14 | 459 | 225 | import math
k = int(eval(input()))
ab = []
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
if a % b == 0:
ab.append(b)
elif b % a == 0:
ab.append(a)
else:
ab.append(math.gcd(a, b))
for i in ab:
for c in range(1, k + 1):
if i % c == 0:
ans += c
elif c % i == 0:
ans += i
else:
ans += math.gcd(i, c)
print(ans)
| import math
k = int(eval(input()))
ab = []
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
ab.append(math.gcd(a, b))
for i in ab:
for c in range(1, k + 1):
ans += math.gcd(i, c)
print(ans)
| false | 41.666667 | [
"- if a % b == 0:",
"- ab.append(b)",
"- elif b % a == 0:",
"- ab.append(a)",
"- else:",
"- ab.append(math.gcd(a, b))",
"+ ab.append(math.gcd(a, b))",
"- if i % c == 0:",
"- ans += c",
"- elif c % i == 0:",
"- ... | false | 0.158146 | 0.123617 | 1.279319 | [
"s208234853",
"s672143910"
] |
u564589929 | p02762 | python | s901545329 | s924417521 | 1,333 | 1,082 | 37,808 | 19,612 | Accepted | Accepted | 18.83 | import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
INF = float('inf')
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def solve():
n, m, k = MI()
uf = UnionFind(n)
friends = [0] * n
for i in range(m):
a, b = MI1()
uf.union(a, b)
friends[a] += 1
friends[b] += 1
# print(uf.__str__())
# print(friends)
# blocks = [[0] * n for _ in range(n)]
blocks = {}
for i in range(k):
c, d = MI1()
# blocks[c][d] += 1
# blocks[d][c] += 1
blocks.setdefault(c, [])
blocks[c].append(d)
blocks.setdefault(d, [])
blocks[d].append(c)
# print(blocks)
ans = [0] * n
for i in range(n):
# print(i, uf.size(i))
block = 0
# print(' bb', blocks.get(i))
for bb in blocks.get(i, []):
# print(bb)
if uf.same(i, bb):
# print(idx, bb, uf.find(idx), uf.same(idx, i))
block += 1
ans[i] = uf.size(i) - 1 - block - friends[i]
# print(ans)
print((' '.join(list(map(str, ans)))))
if __name__ == '__main__':
solve()
| import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
INF = float('inf')
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def solve():
n, m, k = MI()
uf = UnionFind(n)
friends = [0] * n
for i in range(m):
a, b = MI1()
uf.union(a, b)
friends[a] += 1
friends[b] += 1
# print(uf.__str__())
# print(friends)
blocks = [0] * n
for i in range(k):
c, d = MI1()
if uf.same(c, d):
blocks[c] += 1
blocks[d] += 1
# print(blocks)
ans = [0] * n
for i in range(n):
ans[i] = uf.size(i) - 1 - blocks[i] - friends[i]
# print(ans)
print((' '.join(list(map(str, ans)))))
if __name__ == '__main__':
solve()
| 109 | 95 | 2,682 | 2,263 | import sys
sys.setrecursionlimit(10**6)
# input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LI1():
return list(map(int1, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
INF = float("inf")
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
def solve():
n, m, k = MI()
uf = UnionFind(n)
friends = [0] * n
for i in range(m):
a, b = MI1()
uf.union(a, b)
friends[a] += 1
friends[b] += 1
# print(uf.__str__())
# print(friends)
# blocks = [[0] * n for _ in range(n)]
blocks = {}
for i in range(k):
c, d = MI1()
# blocks[c][d] += 1
# blocks[d][c] += 1
blocks.setdefault(c, [])
blocks[c].append(d)
blocks.setdefault(d, [])
blocks[d].append(c)
# print(blocks)
ans = [0] * n
for i in range(n):
# print(i, uf.size(i))
block = 0
# print(' bb', blocks.get(i))
for bb in blocks.get(i, []):
# print(bb)
if uf.same(i, bb):
# print(idx, bb, uf.find(idx), uf.same(idx, i))
block += 1
ans[i] = uf.size(i) - 1 - block - friends[i]
# print(ans)
print((" ".join(list(map(str, ans)))))
if __name__ == "__main__":
solve()
| import sys
sys.setrecursionlimit(10**6)
# input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LI1():
return list(map(int1, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
INF = float("inf")
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
def solve():
n, m, k = MI()
uf = UnionFind(n)
friends = [0] * n
for i in range(m):
a, b = MI1()
uf.union(a, b)
friends[a] += 1
friends[b] += 1
# print(uf.__str__())
# print(friends)
blocks = [0] * n
for i in range(k):
c, d = MI1()
if uf.same(c, d):
blocks[c] += 1
blocks[d] += 1
# print(blocks)
ans = [0] * n
for i in range(n):
ans[i] = uf.size(i) - 1 - blocks[i] - friends[i]
# print(ans)
print((" ".join(list(map(str, ans)))))
if __name__ == "__main__":
solve()
| false | 12.844037 | [
"- # blocks = [[0] * n for _ in range(n)]",
"- blocks = {}",
"+ blocks = [0] * n",
"- # blocks[c][d] += 1",
"- # blocks[d][c] += 1",
"- blocks.setdefault(c, [])",
"- blocks[c].append(d)",
"- blocks.setdefault(d, [])",
"- blocks[d].append(c)",
"+ ... | false | 0.066516 | 0.073939 | 0.899612 | [
"s901545329",
"s924417521"
] |
u509405951 | p02713 | python | s671177211 | s669867314 | 316 | 217 | 68,760 | 89,552 | Accepted | Accepted | 31.33 | def euclid(a, b):
while b:
a, b = b, a%b
return a
K = int(eval(input()))
count=0
for i in range(1, K+1):
for j in range(i, K+1):
for k in range(j, K+1):
if i == j and j == k:
kake = 1
elif i == j or j == k or i == k:
kake = 3
else:
kake = 6
count += euclid(euclid(i, j), k) * kake
print(count) | import numpy as np
K = int(eval(input()))
x = np.arange(1, K + 1)
nums = np.gcd.outer(np.gcd.outer(x, x), x)
print((np.sum(nums))) | 20 | 7 | 381 | 130 | def euclid(a, b):
while b:
a, b = b, a % b
return a
K = int(eval(input()))
count = 0
for i in range(1, K + 1):
for j in range(i, K + 1):
for k in range(j, K + 1):
if i == j and j == k:
kake = 1
elif i == j or j == k or i == k:
kake = 3
else:
kake = 6
count += euclid(euclid(i, j), k) * kake
print(count)
| import numpy as np
K = int(eval(input()))
x = np.arange(1, K + 1)
nums = np.gcd.outer(np.gcd.outer(x, x), x)
print((np.sum(nums)))
| false | 65 | [
"-def euclid(a, b):",
"- while b:",
"- a, b = b, a % b",
"- return a",
"-",
"+import numpy as np",
"-count = 0",
"-for i in range(1, K + 1):",
"- for j in range(i, K + 1):",
"- for k in range(j, K + 1):",
"- if i == j and j == k:",
"- kake = 1",... | false | 0.162446 | 0.3985 | 0.407643 | [
"s671177211",
"s669867314"
] |
u321035578 | p02813 | python | s670677544 | s401910312 | 185 | 27 | 38,384 | 8,052 | Accepted | Accepted | 85.41 | def main():
n=int(eval(input()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
fact = [1]
for i in range(1,9):
fact.append(i*fact[i-1])
tmp = []
for i in range(n):
tmp.append(i+1)
i=0
ansp = caldict(fact,i,p,tmp)
tmp = []
for i in range(n):
tmp.append(i+1)
i=0
ansq = caldict(fact,i,q,tmp)
print((abs(ansp-ansq)))
def caldict(f,i,p,tmp):
if i < len(p)-1:
nowi = tmp.index(p[i])
now = tmp.pop(nowi)
i+=1
return nowi * f[len(tmp)] + caldict(f,i,p,tmp)
else:
return 1
if __name__=='__main__':
main()
| import itertools
def main():
n=int(eval(input()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
perm = list(itertools.permutations(list(range(1,n+1))) )
ansp = perm.index(tuple(p))
# qq = list(itertools.permutations(q) )
ansq = perm.index(tuple(q))
print((abs(ansp-ansq)))
if __name__=='__main__':
main()
| 31 | 15 | 674 | 364 | def main():
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
fact = [1]
for i in range(1, 9):
fact.append(i * fact[i - 1])
tmp = []
for i in range(n):
tmp.append(i + 1)
i = 0
ansp = caldict(fact, i, p, tmp)
tmp = []
for i in range(n):
tmp.append(i + 1)
i = 0
ansq = caldict(fact, i, q, tmp)
print((abs(ansp - ansq)))
def caldict(f, i, p, tmp):
if i < len(p) - 1:
nowi = tmp.index(p[i])
now = tmp.pop(nowi)
i += 1
return nowi * f[len(tmp)] + caldict(f, i, p, tmp)
else:
return 1
if __name__ == "__main__":
main()
| import itertools
def main():
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
perm = list(itertools.permutations(list(range(1, n + 1))))
ansp = perm.index(tuple(p))
# qq = list(itertools.permutations(q) )
ansq = perm.index(tuple(q))
print((abs(ansp - ansq)))
if __name__ == "__main__":
main()
| false | 51.612903 | [
"+import itertools",
"+",
"+",
"- fact = [1]",
"- for i in range(1, 9):",
"- fact.append(i * fact[i - 1])",
"- tmp = []",
"- for i in range(n):",
"- tmp.append(i + 1)",
"- i = 0",
"- ansp = caldict(fact, i, p, tmp)",
"- tmp = []",
"- for i in range(n):",... | false | 0.081117 | 0.04655 | 1.742575 | [
"s670677544",
"s401910312"
] |
u541055501 | p02611 | python | s866362139 | s095896323 | 77 | 32 | 73,264 | 9,204 | Accepted | Accepted | 58.44 | for _ in range(int(eval(input()))):
n=int(eval(input()))
print((sum([n**j*[[0,765144583,346175634,347662323,5655049,184117322,927321758,444014759,542573865,237315285,417297686,471090892,183023413,660103155,727008098,869418286],[539588932,729548371,700407153,404391958,962779130,184117322,927321758,444014759,542573865,237315285,417297686,471090892,183023413,660103155,727008098,869418286]][n&1][j]for j in range(16)])%(10**9+7))) | t,*n=list(map(int,open(0)))
for k in n:print((sum(k**j*[0,765144583,346175634,347662323,5655049,184117322,927321758,444014759,542573865,237315285,417297686,471090892,183023413,660103155,727008098,869418286,539588932,729548371,700407153,404391958,962779130,184117322,927321758,444014759,542573865,237315285,417297686,471090892,183023413,660103155,727008098,869418286][(k&1)*16+j]for j in range(16))%(10**9+7))) | 3 | 2 | 419 | 402 | for _ in range(int(eval(input()))):
n = int(eval(input()))
print(
(
sum(
[
n**j
* [
[
0,
765144583,
346175634,
347662323,
5655049,
184117322,
927321758,
444014759,
542573865,
237315285,
417297686,
471090892,
183023413,
660103155,
727008098,
869418286,
],
[
539588932,
729548371,
700407153,
404391958,
962779130,
184117322,
927321758,
444014759,
542573865,
237315285,
417297686,
471090892,
183023413,
660103155,
727008098,
869418286,
],
][n & 1][j]
for j in range(16)
]
)
% (10**9 + 7)
)
)
| t, *n = list(map(int, open(0)))
for k in n:
print(
(
sum(
k**j
* [
0,
765144583,
346175634,
347662323,
5655049,
184117322,
927321758,
444014759,
542573865,
237315285,
417297686,
471090892,
183023413,
660103155,
727008098,
869418286,
539588932,
729548371,
700407153,
404391958,
962779130,
184117322,
927321758,
444014759,
542573865,
237315285,
417297686,
471090892,
183023413,
660103155,
727008098,
869418286,
][(k & 1) * 16 + j]
for j in range(16)
)
% (10**9 + 7)
)
)
| false | 33.333333 | [
"-for _ in range(int(eval(input()))):",
"- n = int(eval(input()))",
"+t, *n = list(map(int, open(0)))",
"+for k in n:",
"- [",
"- n**j",
"- * [",
"- [",
"- 0,",
"- 7... | false | 0.037462 | 0.075438 | 0.496585 | [
"s866362139",
"s095896323"
] |
u520276780 | p02793 | python | s254919047 | s290817275 | 1,892 | 1,542 | 5,612 | 6,500 | Accepted | Accepted | 18.5 | n = int(eval(input()))
a = list(map(int, input().split( )))
#最小公倍数でよいか?
#全てのjについてAiBiはAjで割り切れる
#計算時間は?
from fractions import gcd
mod =10**9+7
#これが邪魔だったらしい
"""
def lcd(x,y):
g = gcd(x,y)
return x*y//g
"""
ag = 1
for i in range(n):
ag = ag*a[i]//gcd(ag,a[i])
ans = 0
for i in range(n):
ans += ag//a[i]
ans %=mod
print(ans)
| #最初のを試したところ、python のほうが早かった
#メモリが問題になるせいか?
#こちらでは?
from fractions import gcd
import random
n = int(eval(input()))
a = list(map(int, input().split( )))
random.shuffle(a)
#最小公倍数でよいか?
#全てのjについてAiBiはAjで割り切れる
#計算時間は?
mod =10**9+7
ag1 = 1
for i in range(n//2):
ag1 = ag1*a[i]//gcd(ag1,a[i])
ag2 = 1
for i in range(n//2,n):
ag2 = ag2*a[i]//gcd(ag2,a[i])
ag3 = ag1*ag2//gcd(ag1,ag2)
ans = 0
for i in range(n//2):
ans += ag1//a[i]
ans*=ag3//ag1
ans %=mod
ans2 = 0
for i in range(n//2,n):
ans2 += ag2//a[i]
ans2*= ag3//ag2
ans2%=mod
ans += ans2
ans %=mod
print(ans)
| 26 | 39 | 361 | 612 | n = int(eval(input()))
a = list(map(int, input().split()))
# 最小公倍数でよいか?
# 全てのjについてAiBiはAjで割り切れる
# 計算時間は?
from fractions import gcd
mod = 10**9 + 7
# これが邪魔だったらしい
"""
def lcd(x,y):
g = gcd(x,y)
return x*y//g
"""
ag = 1
for i in range(n):
ag = ag * a[i] // gcd(ag, a[i])
ans = 0
for i in range(n):
ans += ag // a[i]
ans %= mod
print(ans)
| # 最初のを試したところ、python のほうが早かった
# メモリが問題になるせいか?
# こちらでは?
from fractions import gcd
import random
n = int(eval(input()))
a = list(map(int, input().split()))
random.shuffle(a)
# 最小公倍数でよいか?
# 全てのjについてAiBiはAjで割り切れる
# 計算時間は?
mod = 10**9 + 7
ag1 = 1
for i in range(n // 2):
ag1 = ag1 * a[i] // gcd(ag1, a[i])
ag2 = 1
for i in range(n // 2, n):
ag2 = ag2 * a[i] // gcd(ag2, a[i])
ag3 = ag1 * ag2 // gcd(ag1, ag2)
ans = 0
for i in range(n // 2):
ans += ag1 // a[i]
ans *= ag3 // ag1
ans %= mod
ans2 = 0
for i in range(n // 2, n):
ans2 += ag2 // a[i]
ans2 *= ag3 // ag2
ans2 %= mod
ans += ans2
ans %= mod
print(ans)
| false | 33.333333 | [
"+# 最初のを試したところ、python のほうが早かった",
"+# メモリが問題になるせいか?",
"+# こちらでは?",
"+from fractions import gcd",
"+import random",
"+",
"+random.shuffle(a)",
"-from fractions import gcd",
"-",
"-# これが邪魔だったらしい",
"-\"\"\"",
"-def lcd(x,y):",
"- g = gcd(x,y)",
"- return x*y//g",
"-\"\"\"",
"-ag = 1"... | false | 0.133481 | 0.183138 | 0.728854 | [
"s254919047",
"s290817275"
] |
u612975321 | p02991 | python | s998426967 | s981964661 | 737 | 304 | 42,456 | 42,328 | Accepted | Accepted | 58.75 | import copy
import sys
input = sys.stdin.readline
n, m = list(map(int,input().split()))
graph = [[] for i in range(n+1)]
for i in range(m):
u, v = list(map(int,input().split()))
graph[u].append(v)
s, g = list(map(int,input().split()))
INF = 10**7
ans = [[INF, INF, INF] for i in range(n+1)]
q = [s]
d = 0
while q:
nq = []
d += 1
p = d % 3
for cf in q:
for ct in graph[cf]:
if ans[ct][p] == INF:
ans[ct][p] = d
nq.append(ct)
q = copy.deepcopy(nq)
if ans[g][0] == INF:
print((-1))
else:
print((ans[g][0]//3)) | # 頂点を3回ずつに持つ (x歩目の着地)
# 最短路
import sys
input = sys.stdin.readline
N,M = list(map(int,input().split()))
if M == 0:
print((-1))
exit()
edge = [[] for _ in range(N+1)]
for _ in range(M):
u,v = list(map(int,input().split()))
edge[u].append(v)
S,T = list(map(int,input().split()))
INF = 10 ** 9
dist = [[INF,INF,INF] for _ in range(N+1)]
d = 0
q = [S]
while q:
d += 1
r = d % 3
qq = []
for u in q:
for v in edge[u]:
if dist[v][r] == INF:
dist[v][r] = d
qq.append(v)
q = qq
d = dist[T][0]
answer = -1 if d == INF else d // 3
print(answer)
| 29 | 34 | 602 | 594 | import copy
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
graph = [[] for i in range(n + 1)]
for i in range(m):
u, v = list(map(int, input().split()))
graph[u].append(v)
s, g = list(map(int, input().split()))
INF = 10**7
ans = [[INF, INF, INF] for i in range(n + 1)]
q = [s]
d = 0
while q:
nq = []
d += 1
p = d % 3
for cf in q:
for ct in graph[cf]:
if ans[ct][p] == INF:
ans[ct][p] = d
nq.append(ct)
q = copy.deepcopy(nq)
if ans[g][0] == INF:
print((-1))
else:
print((ans[g][0] // 3))
| # 頂点を3回ずつに持つ (x歩目の着地)
# 最短路
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
if M == 0:
print((-1))
exit()
edge = [[] for _ in range(N + 1)]
for _ in range(M):
u, v = list(map(int, input().split()))
edge[u].append(v)
S, T = list(map(int, input().split()))
INF = 10**9
dist = [[INF, INF, INF] for _ in range(N + 1)]
d = 0
q = [S]
while q:
d += 1
r = d % 3
qq = []
for u in q:
for v in edge[u]:
if dist[v][r] == INF:
dist[v][r] = d
qq.append(v)
q = qq
d = dist[T][0]
answer = -1 if d == INF else d // 3
print(answer)
| false | 14.705882 | [
"-import copy",
"+# 頂点を3回ずつに持つ (x歩目の着地)",
"+# 最短路",
"-n, m = list(map(int, input().split()))",
"-graph = [[] for i in range(n + 1)]",
"-for i in range(m):",
"+N, M = list(map(int, input().split()))",
"+if M == 0:",
"+ print((-1))",
"+ exit()",
"+edge = [[] for _ in range(N + 1)]",
"+for ... | false | 0.192989 | 0.046503 | 4.150039 | [
"s998426967",
"s981964661"
] |
u597374218 | p02641 | python | s824913988 | s488452484 | 25 | 21 | 9,188 | 9,180 | Accepted | Accepted | 16 | X,N=list(map(int,input().split()))
p=list(map(int,input().split()))
diff=100
for x in range(102):
if x not in p and abs(X-x)<diff:
diff=abs(X-x)
ans=x
print(ans) | X,N=list(map(int,input().split()))
p=list(map(int,input().split()))
diff=99
for x in range(102):
if x not in p and abs(X-x)<diff:
diff=abs(X-x)
ans=x
print(ans) | 8 | 8 | 182 | 181 | X, N = list(map(int, input().split()))
p = list(map(int, input().split()))
diff = 100
for x in range(102):
if x not in p and abs(X - x) < diff:
diff = abs(X - x)
ans = x
print(ans)
| X, N = list(map(int, input().split()))
p = list(map(int, input().split()))
diff = 99
for x in range(102):
if x not in p and abs(X - x) < diff:
diff = abs(X - x)
ans = x
print(ans)
| false | 0 | [
"-diff = 100",
"+diff = 99"
] | false | 0.032496 | 0.035723 | 0.909671 | [
"s824913988",
"s488452484"
] |
u813098295 | p04045 | python | s346796503 | s466035436 | 134 | 42 | 5,380 | 3,060 | Accepted | Accepted | 68.66 | def main():
N, K = list(map(int, input().split()))
D = input().split()
for i in range(N, N*10):
if len(set(list(str(i))) & set(D)) == 0:
print(i)
break
main() | n, k = list(map(int, input().split()))
d = [ int(x) for x in input().split() ]
def is_ok(x):
while x != 0:
if x % 10 in d:
return False
x //= 10
return True
money = n
while True:
if is_ok(n):
print(n)
break
n += 1
| 10 | 16 | 214 | 285 | def main():
N, K = list(map(int, input().split()))
D = input().split()
for i in range(N, N * 10):
if len(set(list(str(i))) & set(D)) == 0:
print(i)
break
main()
| n, k = list(map(int, input().split()))
d = [int(x) for x in input().split()]
def is_ok(x):
while x != 0:
if x % 10 in d:
return False
x //= 10
return True
money = n
while True:
if is_ok(n):
print(n)
break
n += 1
| false | 37.5 | [
"-def main():",
"- N, K = list(map(int, input().split()))",
"- D = input().split()",
"- for i in range(N, N * 10):",
"- if len(set(list(str(i))) & set(D)) == 0:",
"- print(i)",
"- break",
"+n, k = list(map(int, input().split()))",
"+d = [int(x) for x in input().... | false | 0.076295 | 0.041081 | 1.85718 | [
"s346796503",
"s466035436"
] |
u690536347 | p02695 | python | s874267351 | s961873780 | 1,066 | 594 | 9,136 | 9,132 | Accepted | Accepted | 44.28 | from itertools import combinations_with_replacement
N, M, Q = list(map(int, input().split()))
l = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for A in combinations_with_replacement(list(range(1, M+1)), N):
v = 0
for a, b, c, d in l:
if A[b-1]-A[a-1]==c:
v += d
ans = max(ans, v)
print(ans)
| from itertools import combinations_with_replacement
N, M, Q = list(map(int, input().split()))
l = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for A in combinations_with_replacement(list(range(1, M+1)), N):
ans = max(ans, sum(d for a, b, c, d in l if A[b-1]-A[a-1]==c))
print(ans)
| 11 | 7 | 337 | 295 | from itertools import combinations_with_replacement
N, M, Q = list(map(int, input().split()))
l = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for A in combinations_with_replacement(list(range(1, M + 1)), N):
v = 0
for a, b, c, d in l:
if A[b - 1] - A[a - 1] == c:
v += d
ans = max(ans, v)
print(ans)
| from itertools import combinations_with_replacement
N, M, Q = list(map(int, input().split()))
l = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for A in combinations_with_replacement(list(range(1, M + 1)), N):
ans = max(ans, sum(d for a, b, c, d in l if A[b - 1] - A[a - 1] == c))
print(ans)
| false | 36.363636 | [
"- v = 0",
"- for a, b, c, d in l:",
"- if A[b - 1] - A[a - 1] == c:",
"- v += d",
"- ans = max(ans, v)",
"+ ans = max(ans, sum(d for a, b, c, d in l if A[b - 1] - A[a - 1] == c))"
] | false | 0.236641 | 0.157454 | 1.502925 | [
"s874267351",
"s961873780"
] |
u790710233 | p03804 | python | s434232109 | s391781484 | 24 | 20 | 3,060 | 3,064 | Accepted | Accepted | 16.67 | n, m = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(n)]
b = [list(eval(input())) for _ in range(m)]
for i in range(n):
for j in range(n):
if j+m <= n and i+m <= n:
if [a[i+k][j:j+m] for k in range(m)] == b:
print('Yes')
exit()
else:
print('No')
| n, m = list(map(int, input().split()))
a = [eval(input()) for _ in range(n)]
b = [eval(input()) for _ in range(m)]
for i in range(n):
for j in range(n):
if a[i][j] == b[0][0]:
if j+m <= n and i+m <= n:
if [a[i+k][j:j+m] for k in range(m)] == b:
print('Yes')
exit()
else:
print('No')
| 12 | 13 | 326 | 362 | n, m = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(n)]
b = [list(eval(input())) for _ in range(m)]
for i in range(n):
for j in range(n):
if j + m <= n and i + m <= n:
if [a[i + k][j : j + m] for k in range(m)] == b:
print("Yes")
exit()
else:
print("No")
| n, m = list(map(int, input().split()))
a = [eval(input()) for _ in range(n)]
b = [eval(input()) for _ in range(m)]
for i in range(n):
for j in range(n):
if a[i][j] == b[0][0]:
if j + m <= n and i + m <= n:
if [a[i + k][j : j + m] for k in range(m)] == b:
print("Yes")
exit()
else:
print("No")
| false | 7.692308 | [
"-a = [list(eval(input())) for _ in range(n)]",
"-b = [list(eval(input())) for _ in range(m)]",
"+a = [eval(input()) for _ in range(n)]",
"+b = [eval(input()) for _ in range(m)]",
"- if j + m <= n and i + m <= n:",
"- if [a[i + k][j : j + m] for k in range(m)] == b:",
"- ... | false | 0.047862 | 0.046499 | 1.029325 | [
"s434232109",
"s391781484"
] |
u888092736 | p02572 | python | s930384176 | s651117335 | 175 | 160 | 31,764 | 31,268 | Accepted | Accepted | 8.57 | from itertools import accumulate
N, *A = list(map(int, open(0).read().split()))
MOD = 1_000_000_007
acc = list(accumulate(A, initial=0))
ans = 0
for i in range(1, N):
ans += A[i - 1] * (acc[N] - acc[i])
ans %= MOD
print(ans)
| from itertools import accumulate
N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 1_000_000_007
acc = list(accumulate(A, initial=0))
ans = 0
for i in range(N):
ans += A[i] * (acc[N] - acc[i + 1])
ans %= MOD
print(ans)
| 12 | 13 | 241 | 251 | from itertools import accumulate
N, *A = list(map(int, open(0).read().split()))
MOD = 1_000_000_007
acc = list(accumulate(A, initial=0))
ans = 0
for i in range(1, N):
ans += A[i - 1] * (acc[N] - acc[i])
ans %= MOD
print(ans)
| from itertools import accumulate
N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 1_000_000_007
acc = list(accumulate(A, initial=0))
ans = 0
for i in range(N):
ans += A[i] * (acc[N] - acc[i + 1])
ans %= MOD
print(ans)
| false | 7.692308 | [
"-N, *A = list(map(int, open(0).read().split()))",
"+N = int(eval(input()))",
"+A = list(map(int, input().split()))",
"-for i in range(1, N):",
"- ans += A[i - 1] * (acc[N] - acc[i])",
"+for i in range(N):",
"+ ans += A[i] * (acc[N] - acc[i + 1])"
] | false | 0.048024 | 0.038222 | 1.25645 | [
"s930384176",
"s651117335"
] |
u347640436 | p02973 | python | s754346449 | s291214538 | 257 | 229 | 8,828 | 11,756 | Accepted | Accepted | 10.89 | from collections import deque
from bisect import bisect_left
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
t = deque([A[0]])
for a in A[1:]:
if a <= t[0]:
t.appendleft(a)
else:
t[bisect_left(t, a) - 1] = a
print((len(t)))
| from bisect import bisect_right
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
t = [-A[0]]
for a in A[1:]:
if a <= -t[-1]:
t.append(-a)
else:
t[bisect_right(t, -a)] = -a
print((len(t)))
| 13 | 12 | 266 | 228 | from collections import deque
from bisect import bisect_left
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
t = deque([A[0]])
for a in A[1:]:
if a <= t[0]:
t.appendleft(a)
else:
t[bisect_left(t, a) - 1] = a
print((len(t)))
| from bisect import bisect_right
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
t = [-A[0]]
for a in A[1:]:
if a <= -t[-1]:
t.append(-a)
else:
t[bisect_right(t, -a)] = -a
print((len(t)))
| false | 7.692308 | [
"-from collections import deque",
"-from bisect import bisect_left",
"+from bisect import bisect_right",
"-t = deque([A[0]])",
"+t = [-A[0]]",
"- if a <= t[0]:",
"- t.appendleft(a)",
"+ if a <= -t[-1]:",
"+ t.append(-a)",
"- t[bisect_left(t, a) - 1] = a",
"+ t[b... | false | 0.035727 | 0.037322 | 0.957272 | [
"s754346449",
"s291214538"
] |
u124498235 | p03417 | python | s534435093 | s048271128 | 23 | 17 | 3,060 | 3,060 | Accepted | Accepted | 26.09 | n, m = list(map(int, input().split()))
if n == 1 and m == 1:
print((1))
elif n == 1:
print((m-2))
elif m == 1:
print((n-2))
else:
print(((m-2)*(n-2))) | n, m = list(map(int, input().split()))
if n == 1 and m == 1:
print((1))
exit()
if n == 1 or m == 1:
print((max(max(n,m)-2,0)))
elif n == 2 or m == 2:
print((0))
else:
print(((n-2)*(m-2)))
| 9 | 11 | 152 | 194 | n, m = list(map(int, input().split()))
if n == 1 and m == 1:
print((1))
elif n == 1:
print((m - 2))
elif m == 1:
print((n - 2))
else:
print(((m - 2) * (n - 2)))
| n, m = list(map(int, input().split()))
if n == 1 and m == 1:
print((1))
exit()
if n == 1 or m == 1:
print((max(max(n, m) - 2, 0)))
elif n == 2 or m == 2:
print((0))
else:
print(((n - 2) * (m - 2)))
| false | 18.181818 | [
"-elif n == 1:",
"- print((m - 2))",
"-elif m == 1:",
"- print((n - 2))",
"+ exit()",
"+if n == 1 or m == 1:",
"+ print((max(max(n, m) - 2, 0)))",
"+elif n == 2 or m == 2:",
"+ print((0))",
"- print(((m - 2) * (n - 2)))",
"+ print(((n - 2) * (m - 2)))"
] | false | 0.082667 | 0.039737 | 2.080347 | [
"s534435093",
"s048271128"
] |
u439396449 | p04013 | python | s034740150 | s577037004 | 279 | 221 | 5,972 | 21,156 | Accepted | Accepted | 20.79 | from itertools import product
N, A = list(map(int, input().split()))
x = [int(x) for x in input().split()]
X = max(max(x), A)
dp = [[0 for _ in range(2 * N * X + 1)] for _ in range(N + 1)]
dp[0][N * X] = 1
for j, t in product(list(range(1, N + 1)), list(range(2 * N * X + 1))):
y = x[j - 1] - A
if t - y < 0 or t - y > 2 * N * X:
dp[j][t] = dp[j - 1][t]
elif 0 <= t - y <= 2 * N * X:
dp[j][t] = dp[j - 1][t] + dp[j - 1][t - y]
print((dp[N][N * X] - 1)) | from collections import defaultdict
N, A = list(map(int, input().split()))
x = [int(x) for x in input().split()]
for i in range(N):
x[i] -= A
X = max(max(x), A)
dp = [defaultdict(int) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(N):
for j in range(-N * X, N * X + 1):
if - N * X <= j - x[i] <= N * X:
dp[i + 1][j] = dp[i][j] + dp[i][j - x[i]]
else:
dp[i + 1][j] = dp[i][j]
print((dp[N][0] - 1))
| 16 | 18 | 478 | 461 | from itertools import product
N, A = list(map(int, input().split()))
x = [int(x) for x in input().split()]
X = max(max(x), A)
dp = [[0 for _ in range(2 * N * X + 1)] for _ in range(N + 1)]
dp[0][N * X] = 1
for j, t in product(list(range(1, N + 1)), list(range(2 * N * X + 1))):
y = x[j - 1] - A
if t - y < 0 or t - y > 2 * N * X:
dp[j][t] = dp[j - 1][t]
elif 0 <= t - y <= 2 * N * X:
dp[j][t] = dp[j - 1][t] + dp[j - 1][t - y]
print((dp[N][N * X] - 1))
| from collections import defaultdict
N, A = list(map(int, input().split()))
x = [int(x) for x in input().split()]
for i in range(N):
x[i] -= A
X = max(max(x), A)
dp = [defaultdict(int) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(N):
for j in range(-N * X, N * X + 1):
if -N * X <= j - x[i] <= N * X:
dp[i + 1][j] = dp[i][j] + dp[i][j - x[i]]
else:
dp[i + 1][j] = dp[i][j]
print((dp[N][0] - 1))
| false | 11.111111 | [
"-from itertools import product",
"+from collections import defaultdict",
"+for i in range(N):",
"+ x[i] -= A",
"-dp = [[0 for _ in range(2 * N * X + 1)] for _ in range(N + 1)]",
"-dp[0][N * X] = 1",
"-for j, t in product(list(range(1, N + 1)), list(range(2 * N * X + 1))):",
"- y = x[j - 1] - A"... | false | 0.043278 | 0.039874 | 1.085371 | [
"s034740150",
"s577037004"
] |
u281303342 | p03634 | python | s402945772 | s064556406 | 1,400 | 1,080 | 131,632 | 146,028 | Accepted | Accepted | 22.86 | import sys
sys.setrecursionlimit(1000000)
N = int(eval(input()))
X = [[] for _ in range(N)]
for i in range(N-1):
a,b,c = list(map(int,input().split()))
X[a-1].append((b-1,c))
X[b-1].append((a-1,c))
cost = [-1]*N
def calc(i,c):
# 指定の頂点までのコストを代入
cost[i] = c
# 頂点から移動できる頂点があれば
for ni,nc in X[i]:
# 初期状態のままなら計算
if cost[ni] == -1:
calc(ni,c+nc)
Q,K = list(map(int,input().split()))
# 事前計算
calc(K-1,0)
for i in range(Q):
x,y = list(map(int,input().split()))
print((cost[x-1]+cost[y-1]))
| import sys
sys.setrecursionlimit(1000000)
def dfs(n,p,d):
visited[n] = True
dist[n] = d
for (i,c) in A[n]:
if i != p and not visited[i]:
dfs(i,n,d+c)
N = int(eval(input()))
A = [[] for _ in range(N)]
for _ in range(N-1):
a,b,c = list(map(int,input().split()))
A[a-1].append((b-1,c))
A[b-1].append((a-1,c))
Q,K = list(map(int,input().split()))
B = []
for _ in range(Q):
x,y = list(map(int,input().split()))
B.append((x,y))
dist = [-1]*N
visited = [False]*N
dfs(K-1,N,0)
for (x,y) in B:
print((dist[x-1]+dist[y-1]))
| 29 | 29 | 553 | 577 | import sys
sys.setrecursionlimit(1000000)
N = int(eval(input()))
X = [[] for _ in range(N)]
for i in range(N - 1):
a, b, c = list(map(int, input().split()))
X[a - 1].append((b - 1, c))
X[b - 1].append((a - 1, c))
cost = [-1] * N
def calc(i, c):
# 指定の頂点までのコストを代入
cost[i] = c
# 頂点から移動できる頂点があれば
for ni, nc in X[i]:
# 初期状態のままなら計算
if cost[ni] == -1:
calc(ni, c + nc)
Q, K = list(map(int, input().split()))
# 事前計算
calc(K - 1, 0)
for i in range(Q):
x, y = list(map(int, input().split()))
print((cost[x - 1] + cost[y - 1]))
| import sys
sys.setrecursionlimit(1000000)
def dfs(n, p, d):
visited[n] = True
dist[n] = d
for (i, c) in A[n]:
if i != p and not visited[i]:
dfs(i, n, d + c)
N = int(eval(input()))
A = [[] for _ in range(N)]
for _ in range(N - 1):
a, b, c = list(map(int, input().split()))
A[a - 1].append((b - 1, c))
A[b - 1].append((a - 1, c))
Q, K = list(map(int, input().split()))
B = []
for _ in range(Q):
x, y = list(map(int, input().split()))
B.append((x, y))
dist = [-1] * N
visited = [False] * N
dfs(K - 1, N, 0)
for (x, y) in B:
print((dist[x - 1] + dist[y - 1]))
| false | 0 | [
"-N = int(eval(input()))",
"-X = [[] for _ in range(N)]",
"-for i in range(N - 1):",
"- a, b, c = list(map(int, input().split()))",
"- X[a - 1].append((b - 1, c))",
"- X[b - 1].append((a - 1, c))",
"-cost = [-1] * N",
"-def calc(i, c):",
"- # 指定の頂点までのコストを代入",
"- cost[i] = c",
"- ... | false | 0.036758 | 0.03836 | 0.958238 | [
"s402945772",
"s064556406"
] |
u186838327 | p03634 | python | s596760087 | s713510094 | 745 | 660 | 80,304 | 76,464 | Accepted | Accepted | 11.41 | import sys
input = sys.stdin.readline
n =int(eval(input()))
edge = [[] for _ in range(n)]
for i in range(n-1):
a, b, c = list(map(int, input().split()))
a, b = a-1, b-1
edge[a].append((c, b))
edge[b].append((c, a))
q, k = list(map(int, input().split()))
k -= 1
import heapq
INF = 10**18
def dijkstra_heap(s, edge):
d = [INF] * n
used = [True] * n #True: not used
d[s] = 0
used[s] = False
edgelist = []
for e in edge[s]:
heapq.heappush(edgelist,e)
while len(edgelist):
minedge = heapq.heappop(edgelist)
if not used[minedge[1]]:
continue
v = minedge[1]
d[v] = minedge[0]
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,(e[0]+d[v],e[1]))
return d
d = dijkstra_heap(k, edge)
#print(d)
for i in range(q):
x, y = list(map(int, input().split()))
x, y = x-1, y-1
print((d[x]+d[y]))
| import sys
input = sys.stdin.buffer.readline
n = int(eval(input()))
edge = [[] for _ in range(n)]
for i in range(n-1):
a,b,c = list(map(int, input().split()))
a, b = a-1, b-1
edge[a].append((c, b))
edge[b].append((c, a))
q, k = list(map(int, input().split()))
k -= 1
import heapq
INF = 10**18
def dijkstra_heap(s, edge, n):
d = [INF] * n
used = [True] * n #True: not used
d[s] = 0
used[s] = False
edgelist = []
for e in edge[s]:
heapq.heappush(edgelist,e)
while len(edgelist):
minedge = heapq.heappop(edgelist)
if not used[minedge[1]]:
continue
v = minedge[1]
d[v] = minedge[0]
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,(e[0]+d[v],e[1]))
return d
d = dijkstra_heap(k, edge, n)
for i in range(q):
x, y = list(map(int, input().split()))
x, y = x-1, y-1
print((d[x]+d[y]))
| 43 | 41 | 976 | 975 | import sys
input = sys.stdin.readline
n = int(eval(input()))
edge = [[] for _ in range(n)]
for i in range(n - 1):
a, b, c = list(map(int, input().split()))
a, b = a - 1, b - 1
edge[a].append((c, b))
edge[b].append((c, a))
q, k = list(map(int, input().split()))
k -= 1
import heapq
INF = 10**18
def dijkstra_heap(s, edge):
d = [INF] * n
used = [True] * n # True: not used
d[s] = 0
used[s] = False
edgelist = []
for e in edge[s]:
heapq.heappush(edgelist, e)
while len(edgelist):
minedge = heapq.heappop(edgelist)
if not used[minedge[1]]:
continue
v = minedge[1]
d[v] = minedge[0]
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist, (e[0] + d[v], e[1]))
return d
d = dijkstra_heap(k, edge)
# print(d)
for i in range(q):
x, y = list(map(int, input().split()))
x, y = x - 1, y - 1
print((d[x] + d[y]))
| import sys
input = sys.stdin.buffer.readline
n = int(eval(input()))
edge = [[] for _ in range(n)]
for i in range(n - 1):
a, b, c = list(map(int, input().split()))
a, b = a - 1, b - 1
edge[a].append((c, b))
edge[b].append((c, a))
q, k = list(map(int, input().split()))
k -= 1
import heapq
INF = 10**18
def dijkstra_heap(s, edge, n):
d = [INF] * n
used = [True] * n # True: not used
d[s] = 0
used[s] = False
edgelist = []
for e in edge[s]:
heapq.heappush(edgelist, e)
while len(edgelist):
minedge = heapq.heappop(edgelist)
if not used[minedge[1]]:
continue
v = minedge[1]
d[v] = minedge[0]
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist, (e[0] + d[v], e[1]))
return d
d = dijkstra_heap(k, edge, n)
for i in range(q):
x, y = list(map(int, input().split()))
x, y = x - 1, y - 1
print((d[x] + d[y]))
| false | 4.651163 | [
"-input = sys.stdin.readline",
"+input = sys.stdin.buffer.readline",
"-def dijkstra_heap(s, edge):",
"+def dijkstra_heap(s, edge, n):",
"-d = dijkstra_heap(k, edge)",
"-# print(d)",
"+d = dijkstra_heap(k, edge, n)"
] | false | 0.043306 | 0.120521 | 0.359325 | [
"s596760087",
"s713510094"
] |
u779805689 | p02620 | python | s828653806 | s818419823 | 574 | 515 | 84,832 | 76,536 | Accepted | Accepted | 10.28 | def f(a,d,T):
try:
return T[d:].index(a)+d
except ValueError:
return len(T)
from random import randint
A=26
D=int(eval(input()))
C=[0]+list(map(int,input().split())) #減る満足度のベース
S=[0]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度
for i in range(1,D+1):
S[i]=[0]+list(map(int,input().split()))
T=[0]
for i in range(D):
T.append(int(eval(input())))
L=[[0]*(A+1) for _ in range(D+1)]
for x in range(1,D+1):
t=T[x]
for j in range(1,A+1):
if t!=j:
L[x][j]=L[x-1][j]+1
else:
L[x][j]=0
X=0
for d in range(1,D+1):
X+=S[d][T[d]]
for j in range(1,A+1):
X-=C[j]*L[d][j]
M=int(eval(input()))
for _ in range(M):
d,q=list(map(int,input().split()))
p=T[d]
a=f(p,d+1,T)
b=f(q,d+1,T)
Y=0
h=L[d-1][p]
for i in range(d,a):
h+=1
Y+=h-L[i][p]
L[i][p]=h
m=0
Z=0
for j in range(d,b):
Z-=m-L[j][q]
L[j][q]=m
m+=1
X+=(S[d][q]-S[d][p])+Z*C[q]-Y*C[p]
print(X)
T[d]=q
| def f(a,d,T):
try:
return T[d+1:].index(a)+(d+1)
except ValueError:
return len(T)
def g(a,d,T):
try:
return T[:d].index(a)
except ValueError:
return 0
A=26
D=int(eval(input()))
C=[0]+list(map(int,input().split())) #減る満足度のベース
S=[0]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度
for i in range(1,D+1):
S[i]=[0]+list(map(int,input().split()))
T=[0]
for i in range(D):
T.append(int(eval(input())))
X=0
L=[0]*(A+1)
R=[[0]*(A+1) for _ in range(D+1)]
for d in range(1,D+1):
X+=S[d][T[d]]
for j in range(1,A+1):
if j!=T[d]:
L[j]+=1
R[d][j]=R[d-1][j]+1
X-=C[j]*L[j]
else:
L[j]=0
M=int(eval(input()))
for _ in range(M):
d,q=list(map(int,input().split()))
p=T[d]
Y=0
h=R[d-1][p]
for i in range(d,f(p,d,T)):
h+=1
Y+=h-R[i][p]
R[i][p]=h
Z=0
m=0
for j in range(d,f(q,d,T)):
Z+=R[j][q]-m
R[j][q]=m
m+=1
T[d]=q
X+=(S[d][q]-S[d][p])+Z*C[q]-Y*C[p]
print(X)
| 63 | 61 | 1,110 | 1,117 | def f(a, d, T):
try:
return T[d:].index(a) + d
except ValueError:
return len(T)
from random import randint
A = 26
D = int(eval(input()))
C = [0] + list(map(int, input().split())) # 減る満足度のベース
S = [0] * (D + 1) # S[d][i] :(d+1)日目にコンテストiを開催した時の満足度
for i in range(1, D + 1):
S[i] = [0] + list(map(int, input().split()))
T = [0]
for i in range(D):
T.append(int(eval(input())))
L = [[0] * (A + 1) for _ in range(D + 1)]
for x in range(1, D + 1):
t = T[x]
for j in range(1, A + 1):
if t != j:
L[x][j] = L[x - 1][j] + 1
else:
L[x][j] = 0
X = 0
for d in range(1, D + 1):
X += S[d][T[d]]
for j in range(1, A + 1):
X -= C[j] * L[d][j]
M = int(eval(input()))
for _ in range(M):
d, q = list(map(int, input().split()))
p = T[d]
a = f(p, d + 1, T)
b = f(q, d + 1, T)
Y = 0
h = L[d - 1][p]
for i in range(d, a):
h += 1
Y += h - L[i][p]
L[i][p] = h
m = 0
Z = 0
for j in range(d, b):
Z -= m - L[j][q]
L[j][q] = m
m += 1
X += (S[d][q] - S[d][p]) + Z * C[q] - Y * C[p]
print(X)
T[d] = q
| def f(a, d, T):
try:
return T[d + 1 :].index(a) + (d + 1)
except ValueError:
return len(T)
def g(a, d, T):
try:
return T[:d].index(a)
except ValueError:
return 0
A = 26
D = int(eval(input()))
C = [0] + list(map(int, input().split())) # 減る満足度のベース
S = [0] * (D + 1) # S[d][i] :(d+1)日目にコンテストiを開催した時の満足度
for i in range(1, D + 1):
S[i] = [0] + list(map(int, input().split()))
T = [0]
for i in range(D):
T.append(int(eval(input())))
X = 0
L = [0] * (A + 1)
R = [[0] * (A + 1) for _ in range(D + 1)]
for d in range(1, D + 1):
X += S[d][T[d]]
for j in range(1, A + 1):
if j != T[d]:
L[j] += 1
R[d][j] = R[d - 1][j] + 1
X -= C[j] * L[j]
else:
L[j] = 0
M = int(eval(input()))
for _ in range(M):
d, q = list(map(int, input().split()))
p = T[d]
Y = 0
h = R[d - 1][p]
for i in range(d, f(p, d, T)):
h += 1
Y += h - R[i][p]
R[i][p] = h
Z = 0
m = 0
for j in range(d, f(q, d, T)):
Z += R[j][q] - m
R[j][q] = m
m += 1
T[d] = q
X += (S[d][q] - S[d][p]) + Z * C[q] - Y * C[p]
print(X)
| false | 3.174603 | [
"- return T[d:].index(a) + d",
"+ return T[d + 1 :].index(a) + (d + 1)",
"-from random import randint",
"+def g(a, d, T):",
"+ try:",
"+ return T[:d].index(a)",
"+ except ValueError:",
"+ return 0",
"+",
"-L = [[0] * (A + 1) for _ in range(D + 1)]",
"-for x in r... | false | 0.12143 | 0.050809 | 2.389909 | [
"s828653806",
"s818419823"
] |
u572122511 | p02694 | python | s060607851 | s255744351 | 23 | 20 | 9,168 | 9,164 | Accepted | Accepted | 13.04 | X = int(eval(input()))
save = 100
count = 0
while save < X:
save += int(save * 0.01)
count += 1
print(count) | X = int(eval(input()))
m = 100
count = 0
while m < X:
m *= 1.01
m = int(m)
count += 1
print(count) | 8 | 9 | 122 | 113 | X = int(eval(input()))
save = 100
count = 0
while save < X:
save += int(save * 0.01)
count += 1
print(count)
| X = int(eval(input()))
m = 100
count = 0
while m < X:
m *= 1.01
m = int(m)
count += 1
print(count)
| false | 11.111111 | [
"-save = 100",
"+m = 100",
"-while save < X:",
"- save += int(save * 0.01)",
"+while m < X:",
"+ m *= 1.01",
"+ m = int(m)"
] | false | 0.038445 | 0.037802 | 1.01702 | [
"s060607851",
"s255744351"
] |
u477977638 | p02865 | python | s851081623 | s727823644 | 164 | 65 | 38,384 | 61,928 | Accepted | Accepted | 60.37 | import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')
import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)
#map(int,input().split())
def main():
n=int(eval(input()))
print(((n-1)//2))
if __name__ == '__main__':
main() | import sys
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(eval(input()))
def MI(): return list(map(int,input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
def main():
n=II()
print(((n-1)//2))
if __name__ == "__main__":
main()
| 39 | 30 | 896 | 539 | import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
# rstrip().decode('utf-8')
import math
# import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
# from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# sys.setrecursionlimit(10**7)
# map(int,input().split())
def main():
n = int(eval(input()))
print(((n - 1) // 2))
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
# from functools import lru_cache
def RD():
return sys.stdin.read()
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MF():
return list(map(float, input().split()))
def LI():
return list(map(int, input().split()))
def LF():
return list(map(float, input().split()))
def TI():
return tuple(map(int, input().split()))
# rstrip().decode()
def main():
n = II()
print(((n - 1) // 2))
if __name__ == "__main__":
main()
| false | 23.076923 | [
"-read = sys.stdin.buffer.read",
"-inputs = sys.stdin.buffer.readlines",
"-# rstrip().decode('utf-8')",
"-import math",
"+# sys.setrecursionlimit(10**9)",
"+# from functools import lru_cache",
"+def RD():",
"+ return sys.stdin.read()",
"-# import numpy as np",
"-# import operator",
"-# import... | false | 0.045353 | 0.117431 | 0.386214 | [
"s851081623",
"s727823644"
] |
u860002137 | p02735 | python | s928611467 | s384087652 | 205 | 39 | 42,352 | 3,188 | Accepted | Accepted | 80.98 | from collections import deque
h, w = list(map(int, input().split()))
s = [list(map(str, input().rstrip())) for _ in range(h)]
dp = [[10001] * w for _ in range(h)]
if s[0][0] == "#":
dp[0][0] = 1
else:
dp[0][0] = 0
moves = [[1, 0], [0, 1]]
for y in range(h):
for x in range(w):
for m in moves:
ny, nx = y + m[0], x + m[1]
if ny >= h or nx >= w:
continue
add = 0
# .から#に突入する時だけカウントが増える
if s[y][x] == "." and s[ny][nx] == "#":
add = 1
dp[ny][nx] = min(dp[ny][nx], dp[y][x] + add)
print((dp[-1][-1])) | h, w = list(map(int, input().split()))
s = [list(map(str, input().rstrip())) for _ in range(h)]
dp = [[10001] * w for _ in range(h)]
if s[0][0] == "#":
dp[0][0] = 1
else:
dp[0][0] = 0
moves = [[1, 0], [0, 1]]
for y in range(h):
for x in range(w):
for m in moves:
ny, nx = y + m[0], x + m[1]
if ny >= h or nx >= w:
continue
add = 0
# .から#に突入する時だけカウントが増える
if s[y][x] == "." and s[ny][nx] == "#":
add = 1
dp[ny][nx] = min(dp[ny][nx], dp[y][x] + add)
print((dp[-1][-1])) | 27 | 25 | 644 | 611 | from collections import deque
h, w = list(map(int, input().split()))
s = [list(map(str, input().rstrip())) for _ in range(h)]
dp = [[10001] * w for _ in range(h)]
if s[0][0] == "#":
dp[0][0] = 1
else:
dp[0][0] = 0
moves = [[1, 0], [0, 1]]
for y in range(h):
for x in range(w):
for m in moves:
ny, nx = y + m[0], x + m[1]
if ny >= h or nx >= w:
continue
add = 0
# .から#に突入する時だけカウントが増える
if s[y][x] == "." and s[ny][nx] == "#":
add = 1
dp[ny][nx] = min(dp[ny][nx], dp[y][x] + add)
print((dp[-1][-1]))
| h, w = list(map(int, input().split()))
s = [list(map(str, input().rstrip())) for _ in range(h)]
dp = [[10001] * w for _ in range(h)]
if s[0][0] == "#":
dp[0][0] = 1
else:
dp[0][0] = 0
moves = [[1, 0], [0, 1]]
for y in range(h):
for x in range(w):
for m in moves:
ny, nx = y + m[0], x + m[1]
if ny >= h or nx >= w:
continue
add = 0
# .から#に突入する時だけカウントが増える
if s[y][x] == "." and s[ny][nx] == "#":
add = 1
dp[ny][nx] = min(dp[ny][nx], dp[y][x] + add)
print((dp[-1][-1]))
| false | 7.407407 | [
"-from collections import deque",
"-"
] | false | 0.052374 | 0.035927 | 1.457785 | [
"s928611467",
"s384087652"
] |
u090068671 | p02642 | python | s493559920 | s499728455 | 861 | 604 | 100,864 | 99,944 | Accepted | Accepted | 29.85 | from collections import defaultdict
def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
a_max = max(A)+1
B = defaultdict(int)
for i in range(N):
a = A[i]
if B[a]>1:
B[a] = 2
else:
for j in range(a, a_max, a):
B[j] += 1
Y = 0
for a in A:
if B[a]==1:
Y+=1
print(Y)
resolve() | def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
a_max = max(A)+1
B = {}
for i in range(N):
a = A[i]
if a not in list(B.keys()):
for j in range(a, a_max, a):
B[j] = False
B[a] = True
else:
B[a] = False
Y = list(B.values()).count(True)
print(Y)
resolve() | 20 | 16 | 337 | 307 | from collections import defaultdict
def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
a_max = max(A) + 1
B = defaultdict(int)
for i in range(N):
a = A[i]
if B[a] > 1:
B[a] = 2
else:
for j in range(a, a_max, a):
B[j] += 1
Y = 0
for a in A:
if B[a] == 1:
Y += 1
print(Y)
resolve()
| def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
a_max = max(A) + 1
B = {}
for i in range(N):
a = A[i]
if a not in list(B.keys()):
for j in range(a, a_max, a):
B[j] = False
B[a] = True
else:
B[a] = False
Y = list(B.values()).count(True)
print(Y)
resolve()
| false | 20 | [
"-from collections import defaultdict",
"-",
"-",
"- B = defaultdict(int)",
"+ B = {}",
"- if B[a] > 1:",
"- B[a] = 2",
"+ if a not in list(B.keys()):",
"+ for j in range(a, a_max, a):",
"+ B[j] = False",
"+ B[a] = True",
"- ... | false | 0.043793 | 0.038161 | 1.147583 | [
"s493559920",
"s499728455"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.