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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u186838327 | p03700 | python | s043348468 | s243209753 | 1,286 | 561 | 7,072 | 50,904 | Accepted | Accepted | 56.38 | n, a, b = list(map(int, input().split()))
h = [int(eval(input())) for _ in range(n)]
import math
def ok(x):
t = 0
for i in range(n):
r = h[i] - b*x
if r < 0:
continue
else:
t += math.ceil(r/(a-b))
if t <= x:
return True
else:
return False
l = 0
r = 10**14+1
while l+1 < r:
c = (l+r)//2
if ok(c):
r = c
else:
l = c
print(r) | n, a, b = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(n)]
def ok(x):
tot = 0
for i in range(n):
if b*x >= H[i]:
continue
else:
r = H[i] - b*x
if r%(a-b) == 0:
tot += r//(a-b)
else:
tot += r//(a-b)+1
if tot <= x:
return True
else:
return False
l = 0
r = 10**10
while l+1 < r:
c = (l+r)//2
if ok(c):
r = c
else:
l = c
print(r) | 26 | 28 | 445 | 524 | n, a, b = list(map(int, input().split()))
h = [int(eval(input())) for _ in range(n)]
import math
def ok(x):
t = 0
for i in range(n):
r = h[i] - b * x
if r < 0:
continue
else:
t += math.ceil(r / (a - b))
if t <= x:
return True
else:
return False
l = 0
r = 10**14 + 1
while l + 1 < r:
c = (l + r) // 2
if ok(c):
r = c
else:
l = c
print(r)
| n, a, b = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(n)]
def ok(x):
tot = 0
for i in range(n):
if b * x >= H[i]:
continue
else:
r = H[i] - b * x
if r % (a - b) == 0:
tot += r // (a - b)
else:
tot += r // (a - b) + 1
if tot <= x:
return True
else:
return False
l = 0
r = 10**10
while l + 1 < r:
c = (l + r) // 2
if ok(c):
r = c
else:
l = c
print(r)
| false | 7.142857 | [
"-h = [int(eval(input())) for _ in range(n)]",
"-import math",
"+H = [int(eval(input())) for _ in range(n)]",
"- t = 0",
"+ tot = 0",
"- r = h[i] - b * x",
"- if r < 0:",
"+ if b * x >= H[i]:",
"- t += math.ceil(r / (a - b))",
"- if t <= x:",
"+ ... | false | 0.037974 | 0.076557 | 0.49602 | [
"s043348468",
"s243209753"
] |
u124605948 | p03419 | python | s556719303 | s471215393 | 30 | 26 | 9,108 | 9,068 | Accepted | Accepted | 13.33 | n, m = list(map(int, input().split()))
if n >= 2 and m >= 2:
print(((n-2)*(m-2)))
elif (n == 1 and m >= 3) or (n >= 3 and m == 1):
print((max(n, m)-2))
elif (n == 1 and m == 2) or (n == 2 and m == 1):
print((0))
elif (n == 1 and m == 1):
print((1)) | n, m = list(map(int, input().split()))
if n*m == 1:
print((1))
elif n == 1 or m == 1:
print((max(n, m)-2))
else:
print(((n-2)*(m-2))) | 10 | 8 | 260 | 141 | n, m = list(map(int, input().split()))
if n >= 2 and m >= 2:
print(((n - 2) * (m - 2)))
elif (n == 1 and m >= 3) or (n >= 3 and m == 1):
print((max(n, m) - 2))
elif (n == 1 and m == 2) or (n == 2 and m == 1):
print((0))
elif n == 1 and m == 1:
print((1))
| n, m = list(map(int, input().split()))
if n * m == 1:
print((1))
elif n == 1 or m == 1:
print((max(n, m) - 2))
else:
print(((n - 2) * (m - 2)))
| false | 20 | [
"-if n >= 2 and m >= 2:",
"+if n * m == 1:",
"+ print((1))",
"+elif n == 1 or m == 1:",
"+ print((max(n, m) - 2))",
"+else:",
"-elif (n == 1 and m >= 3) or (n >= 3 and m == 1):",
"- print((max(n, m) - 2))",
"-elif (n == 1 and m == 2) or (n == 2 and m == 1):",
"- print((0))",
"-elif n... | false | 0.03609 | 0.033782 | 1.068326 | [
"s556719303",
"s471215393"
] |
u285436211 | p02659 | python | s847074492 | s450057259 | 32 | 27 | 9,976 | 9,164 | Accepted | Accepted | 15.62 | from decimal import Decimal
a,b=input().split()
print((int(Decimal(a)*Decimal(b)))) | a,b = list(map(str, input().split()))
a=int(a)
b=int(b.replace(".",""))
print((a*b//100)) | 3 | 4 | 83 | 84 | from decimal import Decimal
a, b = input().split()
print((int(Decimal(a) * Decimal(b))))
| a, b = list(map(str, input().split()))
a = int(a)
b = int(b.replace(".", ""))
print((a * b // 100))
| false | 25 | [
"-from decimal import Decimal",
"-",
"-a, b = input().split()",
"-print((int(Decimal(a) * Decimal(b))))",
"+a, b = list(map(str, input().split()))",
"+a = int(a)",
"+b = int(b.replace(\".\", \"\"))",
"+print((a * b // 100))"
] | false | 0.166616 | 0.108038 | 1.542198 | [
"s847074492",
"s450057259"
] |
u008357982 | p02756 | python | s097601048 | s800109453 | 440 | 348 | 12,256 | 8,676 | Accepted | Accepted | 20.91 | from collections import deque
d = deque(list(input()))
flag = 1
for _ in range(int(input())):
a = input()
if a[0] == '1':
flag *= -1
elif a[2] == '1' and flag == 1:
d.appendleft(a[4])
elif a[2] == '1' and flag == -1:
d.append(a[4])
elif a[2] == '2' and flag == 1:
d.append(a[4])
else:
d.appendleft(a[4])
if flag == -1:
d.reverse()
print(*d, sep='')
| from collections import deque
d = deque(list(eval(input())))
flag = 1
for _ in range(int(eval(input()))):
a = eval(input())
if a[0] == '1':
flag *= -1
elif a[2] == '1' and flag == 1:
d.appendleft(a[4])
elif a[2] == '1' and flag == -1:
d.append(a[4])
elif a[2] == '2' and flag == 1:
d.append(a[4])
else:
d.appendleft(a[4])
if flag == -1:
d.reverse()
print((''.join(d)))
| 19 | 19 | 436 | 436 | from collections import deque
d = deque(list(input()))
flag = 1
for _ in range(int(input())):
a = input()
if a[0] == "1":
flag *= -1
elif a[2] == "1" and flag == 1:
d.appendleft(a[4])
elif a[2] == "1" and flag == -1:
d.append(a[4])
elif a[2] == "2" and flag == 1:
d.append(a[4])
else:
d.appendleft(a[4])
if flag == -1:
d.reverse()
print(*d, sep="")
| from collections import deque
d = deque(list(eval(input())))
flag = 1
for _ in range(int(eval(input()))):
a = eval(input())
if a[0] == "1":
flag *= -1
elif a[2] == "1" and flag == 1:
d.appendleft(a[4])
elif a[2] == "1" and flag == -1:
d.append(a[4])
elif a[2] == "2" and flag == 1:
d.append(a[4])
else:
d.appendleft(a[4])
if flag == -1:
d.reverse()
print(("".join(d)))
| false | 0 | [
"-d = deque(list(input()))",
"+d = deque(list(eval(input())))",
"-for _ in range(int(input())):",
"- a = input()",
"+for _ in range(int(eval(input()))):",
"+ a = eval(input())",
"-print(*d, sep=\"\")",
"+print((\"\".join(d)))"
] | false | 0.042663 | 0.084462 | 0.505115 | [
"s097601048",
"s800109453"
] |
u312025627 | p02744 | python | s369238558 | s681146415 | 368 | 335 | 56,408 | 69,256 | Accepted | Accepted | 8.97 | def main():
from string import ascii_lowercase
dic = {i: s for i, s in enumerate(ascii_lowercase)}
N = int(eval(input()))
ans = []
def dfs(s, mx):
if len(s) == N:
print(s)
return
else:
for i in range(mx+2):
v = s + dic[i]
mx = max(mx, i)
dfs(v, mx)
dfs("a", 0)
if __name__ == '__main__':
main()
| def main():
from string import ascii_lowercase
dic = {i: s for i, s in enumerate(ascii_lowercase)}
N = int(input())
ans = []
def dfs(s, mx):
if len(s) == N:
ans.append(s)
return
else:
for i in range(mx+2):
v = s + dic[i]
mx = max(mx, i)
dfs(v, mx)
dfs("a", 0)
print(*ans, sep="\n")
if __name__ == '__main__':
main()
| 20 | 21 | 439 | 471 | def main():
from string import ascii_lowercase
dic = {i: s for i, s in enumerate(ascii_lowercase)}
N = int(eval(input()))
ans = []
def dfs(s, mx):
if len(s) == N:
print(s)
return
else:
for i in range(mx + 2):
v = s + dic[i]
mx = max(mx, i)
dfs(v, mx)
dfs("a", 0)
if __name__ == "__main__":
main()
| def main():
from string import ascii_lowercase
dic = {i: s for i, s in enumerate(ascii_lowercase)}
N = int(input())
ans = []
def dfs(s, mx):
if len(s) == N:
ans.append(s)
return
else:
for i in range(mx + 2):
v = s + dic[i]
mx = max(mx, i)
dfs(v, mx)
dfs("a", 0)
print(*ans, sep="\n")
if __name__ == "__main__":
main()
| false | 4.761905 | [
"- N = int(eval(input()))",
"+ N = int(input())",
"- print(s)",
"+ ans.append(s)",
"+ print(*ans, sep=\"\\n\")"
] | false | 0.14558 | 0.043056 | 3.381162 | [
"s369238558",
"s681146415"
] |
u796942881 | p03221 | python | s242570224 | s067480124 | 633 | 327 | 38,624 | 32,976 | Accepted | Accepted | 48.34 | import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
Pm = [0] * M
Ym = [0] * M
ym = [0] * M
Am = [[0 for i in range(2)] for j in range(M)]
Cn = [0] * N
D = {}
for i in range(M):
P, Y = list(map(int, input().split()))
Pm[i], Ym[i] = P, Y
ym[i] = Y
D[Y] = i
ym.sort()
for i in range(M):
k = D[ym[i]]
# 0-indexed
Cn[Pm[k] - 1] += 1
Am[k] = [Pm[k], Cn[Pm[k] - 1]]
for i in range(M):
print(('{:06d}{:06d}'.format(Am[i][0], Am[i][1])))
| def main():
N, M, *PY = list(map(int, open(0).read().split()))
lst = []
ans = [""] * M
for k, py in enumerate(zip(*[iter(PY)] * 2)):
lst.append((py[0], py[1], k))
lst.sort()
pre, num = lst[0][0], 1
for cur, y, i in lst:
if pre != cur:
num = 1
ans[i] = "{:06}{:06}".format(cur, num)
num += 1
pre = cur
print(("\n".join(ans)))
return
main()
| 35 | 19 | 523 | 439 | import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
Pm = [0] * M
Ym = [0] * M
ym = [0] * M
Am = [[0 for i in range(2)] for j in range(M)]
Cn = [0] * N
D = {}
for i in range(M):
P, Y = list(map(int, input().split()))
Pm[i], Ym[i] = P, Y
ym[i] = Y
D[Y] = i
ym.sort()
for i in range(M):
k = D[ym[i]]
# 0-indexed
Cn[Pm[k] - 1] += 1
Am[k] = [Pm[k], Cn[Pm[k] - 1]]
for i in range(M):
print(("{:06d}{:06d}".format(Am[i][0], Am[i][1])))
| def main():
N, M, *PY = list(map(int, open(0).read().split()))
lst = []
ans = [""] * M
for k, py in enumerate(zip(*[iter(PY)] * 2)):
lst.append((py[0], py[1], k))
lst.sort()
pre, num = lst[0][0], 1
for cur, y, i in lst:
if pre != cur:
num = 1
ans[i] = "{:06}{:06}".format(cur, num)
num += 1
pre = cur
print(("\n".join(ans)))
return
main()
| false | 45.714286 | [
"-import sys",
"+def main():",
"+ N, M, *PY = list(map(int, open(0).read().split()))",
"+ lst = []",
"+ ans = [\"\"] * M",
"+ for k, py in enumerate(zip(*[iter(PY)] * 2)):",
"+ lst.append((py[0], py[1], k))",
"+ lst.sort()",
"+ pre, num = lst[0][0], 1",
"+ for cur, y, i... | false | 0.038958 | 0.00649 | 6.002792 | [
"s242570224",
"s067480124"
] |
u115682115 | p03645 | python | s406279411 | s924003682 | 826 | 596 | 72,024 | 18,892 | Accepted | Accepted | 27.85 | N,M = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(M)]
b = set()
for i in a:
if i[0]==1 or i[1]==N:
b.add((i[0],i[1]))
for i in range(2,N):
if (1,i) in b and (i,N) in b:
print('POSSIBLE')
exit()
print('IMPOSSIBLE')
| N, M = list(map(int,input().split()))
t_mid = set()
f_mid = set()
for _ in range(M):
f, t = list(map(int,input().split()))
if f == 1:
t_mid.add(t)
elif t == N:
f_mid.add(f)
if t_mid & f_mid:
print('POSSIBLE')
else:
print('IMPOSSIBLE')
| 11 | 14 | 282 | 273 | N, M = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(M)]
b = set()
for i in a:
if i[0] == 1 or i[1] == N:
b.add((i[0], i[1]))
for i in range(2, N):
if (1, i) in b and (i, N) in b:
print("POSSIBLE")
exit()
print("IMPOSSIBLE")
| N, M = list(map(int, input().split()))
t_mid = set()
f_mid = set()
for _ in range(M):
f, t = list(map(int, input().split()))
if f == 1:
t_mid.add(t)
elif t == N:
f_mid.add(f)
if t_mid & f_mid:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
| false | 21.428571 | [
"-a = [list(map(int, input().split())) for i in range(M)]",
"-b = set()",
"-for i in a:",
"- if i[0] == 1 or i[1] == N:",
"- b.add((i[0], i[1]))",
"-for i in range(2, N):",
"- if (1, i) in b and (i, N) in b:",
"- print(\"POSSIBLE\")",
"- exit()",
"-print(\"IMPOSSIBLE\")"... | false | 0.125093 | 0.087549 | 1.428834 | [
"s406279411",
"s924003682"
] |
u833543158 | p03013 | python | s109750063 | s780738904 | 667 | 468 | 460,020 | 460,020 | Accepted | Accepted | 29.84 | import sys
N, M = list(map(int, input().split()))
a = [int(line) for line in sys.stdin]
ans = [-1] * (N + 1) # not evaluated yet
for broken in a:
ans[broken] = 0 # unreachable
ans[0] = 1 # reachable
if ans[1]:
ans[1] = 1
for i in range(2, N + 1):
if ans[i]:
ans[i] = ans[i - 1] + ans[i - 2]
print((ans[N] % 1000000007))
| import sys
N, M = list(map(int, input().split()))
ans = [-1] * (N + 1) # not evaluated yet
for line in sys.stdin:
ans[int(line)] = 0 # unreachable
ans[0] = 1 # reachable
if ans[1]:
ans[1] = 1
for i in range(2, N + 1):
if ans[i]:
ans[i] = ans[i - 1] + ans[i - 2]
print((ans[N] % 1000000007))
| 20 | 18 | 361 | 329 | import sys
N, M = list(map(int, input().split()))
a = [int(line) for line in sys.stdin]
ans = [-1] * (N + 1) # not evaluated yet
for broken in a:
ans[broken] = 0 # unreachable
ans[0] = 1 # reachable
if ans[1]:
ans[1] = 1
for i in range(2, N + 1):
if ans[i]:
ans[i] = ans[i - 1] + ans[i - 2]
print((ans[N] % 1000000007))
| import sys
N, M = list(map(int, input().split()))
ans = [-1] * (N + 1) # not evaluated yet
for line in sys.stdin:
ans[int(line)] = 0 # unreachable
ans[0] = 1 # reachable
if ans[1]:
ans[1] = 1
for i in range(2, N + 1):
if ans[i]:
ans[i] = ans[i - 1] + ans[i - 2]
print((ans[N] % 1000000007))
| false | 10 | [
"-a = [int(line) for line in sys.stdin]",
"-for broken in a:",
"- ans[broken] = 0 # unreachable",
"+for line in sys.stdin:",
"+ ans[int(line)] = 0 # unreachable"
] | false | 0.038869 | 0.045571 | 0.852933 | [
"s109750063",
"s780738904"
] |
u057109575 | p02948 | python | s728242162 | s528652642 | 618 | 526 | 105,088 | 94,788 | Accepted | Accepted | 14.89 | from heapq import heappush, heappop
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
pq = []
for a, b in X:
heappush(pq, (a, b))
cand = []
ans = 0
for t in range(1, M + 1):
while pq:
a, b = heappop(pq)
if a <= t:
heappush(cand, -b)
else:
heappush(pq, (a, b))
break
if cand:
v = heappop(cand)
ans += -v
print(ans)
|
from heapq import heappop, heappush
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(reverse=True)
ans = 0
pq = []
for n in range(M + 1):
while X and X[-1][0] <= n:
a, b = X.pop()
heappush(pq, -b)
if pq:
ans -= heappop(pq)
print(ans)
| 25 | 18 | 474 | 335 | from heapq import heappush, heappop
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
pq = []
for a, b in X:
heappush(pq, (a, b))
cand = []
ans = 0
for t in range(1, M + 1):
while pq:
a, b = heappop(pq)
if a <= t:
heappush(cand, -b)
else:
heappush(pq, (a, b))
break
if cand:
v = heappop(cand)
ans += -v
print(ans)
| from heapq import heappop, heappush
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(reverse=True)
ans = 0
pq = []
for n in range(M + 1):
while X and X[-1][0] <= n:
a, b = X.pop()
heappush(pq, -b)
if pq:
ans -= heappop(pq)
print(ans)
| false | 28 | [
"-from heapq import heappush, heappop",
"+from heapq import heappop, heappush",
"+X.sort(reverse=True)",
"+ans = 0",
"-for a, b in X:",
"- heappush(pq, (a, b))",
"-cand = []",
"-ans = 0",
"-for t in range(1, M + 1):",
"- while pq:",
"- a, b = heappop(pq)",
"- if a <= t:",
... | false | 0.037413 | 0.06735 | 0.555492 | [
"s728242162",
"s528652642"
] |
u073852194 | p02948 | python | s158228995 | s854080327 | 707 | 603 | 46,212 | 20,932 | Accepted | Accepted | 14.71 | import heapq
n,m = list(map(int,input().split()))
Jobs = [list(map(int,input().split()))for i in range(n)]
Days = [[] for i in range(m)]
for i in range(n):
if Jobs[i][0] <= m:
Days[Jobs[i][0]-1] += [[-Jobs[i][1],Jobs[i][0]]]
Heap = []
heapq.heapify(Heap)
ans = 0
for i in range(m):
for job in Days[i]:
heapq.heappush(Heap,job)
if Heap:
ans -= heapq.heappop(Heap)[0]
print(ans) | from heapq import heappop,heappush
N,M = list(map(int,input().split()))
job = [tuple(map(int,input().split())) for _ in range(N)]
job.sort(key=lambda x:x[1],reverse=True)
job.sort(key=lambda x:x[0])
heap = []
ans = 0
j = -1
for i in range(M)[::-1]:
while j < N-1 and job[j+1][0]+i <= M:
j += 1
heappush(heap,-job[j][1])
if heap:
ans += -heappop(heap)
print(ans) | 20 | 20 | 437 | 411 | import heapq
n, m = list(map(int, input().split()))
Jobs = [list(map(int, input().split())) for i in range(n)]
Days = [[] for i in range(m)]
for i in range(n):
if Jobs[i][0] <= m:
Days[Jobs[i][0] - 1] += [[-Jobs[i][1], Jobs[i][0]]]
Heap = []
heapq.heapify(Heap)
ans = 0
for i in range(m):
for job in Days[i]:
heapq.heappush(Heap, job)
if Heap:
ans -= heapq.heappop(Heap)[0]
print(ans)
| from heapq import heappop, heappush
N, M = list(map(int, input().split()))
job = [tuple(map(int, input().split())) for _ in range(N)]
job.sort(key=lambda x: x[1], reverse=True)
job.sort(key=lambda x: x[0])
heap = []
ans = 0
j = -1
for i in range(M)[::-1]:
while j < N - 1 and job[j + 1][0] + i <= M:
j += 1
heappush(heap, -job[j][1])
if heap:
ans += -heappop(heap)
print(ans)
| false | 0 | [
"-import heapq",
"+from heapq import heappop, heappush",
"-n, m = list(map(int, input().split()))",
"-Jobs = [list(map(int, input().split())) for i in range(n)]",
"-Days = [[] for i in range(m)]",
"-for i in range(n):",
"- if Jobs[i][0] <= m:",
"- Days[Jobs[i][0] - 1] += [[-Jobs[i][1], Jobs[... | false | 0.048998 | 0.049236 | 0.995163 | [
"s158228995",
"s854080327"
] |
u627803856 | p02813 | python | s208301167 | s473084173 | 179 | 39 | 45,040 | 3,064 | Accepted | Accepted | 78.21 | from itertools import permutations
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
s = list(range(1, n+1))
s = list(permutations(s))
a, b = 0, 0
for i, v in enumerate(s, start=1):
if v == p:
a = i
elif v == q:
b = i
else:
pass
print(0) if p == q else print(abs(a - b))
| n = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
from itertools import permutations
l = list(range(1, n + 1))
perm = permutations(l, n)
idx_P, idx_Q = 0, 0
for i,v in enumerate(perm):
if v == tuple(P):
idx_P = i
if v == tuple(Q):
idx_Q = i
print((abs(idx_P - idx_Q))) | 20 | 17 | 344 | 349 | from itertools import permutations
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
s = list(range(1, n + 1))
s = list(permutations(s))
a, b = 0, 0
for i, v in enumerate(s, start=1):
if v == p:
a = i
elif v == q:
b = i
else:
pass
print(0) if p == q else print(abs(a - b))
| n = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
from itertools import permutations
l = list(range(1, n + 1))
perm = permutations(l, n)
idx_P, idx_Q = 0, 0
for i, v in enumerate(perm):
if v == tuple(P):
idx_P = i
if v == tuple(Q):
idx_Q = i
print((abs(idx_P - idx_Q)))
| false | 15 | [
"+n = int(eval(input()))",
"+P = list(map(int, input().split()))",
"+Q = list(map(int, input().split()))",
"-n = int(input())",
"-p = tuple(map(int, input().split()))",
"-q = tuple(map(int, input().split()))",
"-s = list(range(1, n + 1))",
"-s = list(permutations(s))",
"-a, b = 0, 0",
"-for i, v i... | false | 0.041585 | 0.043689 | 0.951853 | [
"s208301167",
"s473084173"
] |
u821624310 | p02409 | python | s650805964 | s631766267 | 30 | 20 | 7,680 | 7,732 | Accepted | Accepted | 33.33 | b_ifo = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
b, f, r, v = map(int, input().split())
b_ifo[b-1][f-1][r-1] += v
for i in range(4):
for j in range(3):
for k in range(10):
print(" " + str(b_ifo[i][j][k]), end = "")
print()
if i != 3:
print("#" * 20)
| house = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
b, f, r, v = map(int, input().split())
house[b-1][f-1][r-1] += v
for i in range(4):
for j in range(3):
for k in range(10):
print(" " + str(house[i][j][k]), end="")
print()
if j == 3 - 1 and i != 4 - 1:
print("#" * 20)
| 12 | 12 | 370 | 387 | b_ifo = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
b, f, r, v = map(int, input().split())
b_ifo[b - 1][f - 1][r - 1] += v
for i in range(4):
for j in range(3):
for k in range(10):
print(" " + str(b_ifo[i][j][k]), end="")
print()
if i != 3:
print("#" * 20)
| house = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
b, f, r, v = map(int, input().split())
house[b - 1][f - 1][r - 1] += v
for i in range(4):
for j in range(3):
for k in range(10):
print(" " + str(house[i][j][k]), end="")
print()
if j == 3 - 1 and i != 4 - 1:
print("#" * 20)
| false | 0 | [
"-b_ifo = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]",
"+house = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]",
"- b_ifo[b - 1][f - 1][r - 1] += v",
"+ house[b - 1][f - 1][r - 1] += v",
"- print(\" \" + str(b_ifo[i][j][k]), end=\"\")",
"+ p... | false | 0.07502 | 0.067468 | 1.111935 | [
"s650805964",
"s631766267"
] |
u627600101 | p02609 | python | s627589331 | s509743715 | 548 | 418 | 20,624 | 20,564 | Accepted | Accepted | 23.72 | N = int(eval(input()))
X = eval(input())
ans = [1 for _ in range(N)]
if N == 1:
if X[0] == '1':
print((0))
exit()
else:
print((1))
exit()
l = 0
for k in range(N):
if X[k] == '1':
l+=1
if l == 0:
for _ in range(N):
print((1))
exit()
if l == 1:
if X[-1] == '1':
for _ in range(N-1):
ans[_] = 2
else:
ans[-1] = 2
for k in range(N):
if X[k] =='1':
ans[k] = 0
for _ in range(N):
print((ans[_]))
exit()
intN = int(X, 2)
N1 = intN %(l-1)
N0 = intN %(l+1)
start = []
s1 = 1
s0 = 1
for k in range(N-1, -1, -1):
if X[k] == '1':
ia = (N1 - s1)%(l-1)
else:
ia = (N0 + s0)%(l+1)
start.append(ia)
s1 = s1*2%(l-1)
s0 = s0*2%(l+1)
start = start[::-1]
poplist = [0 for _ in range(l+1)]
t = 1
while t < l + 2:
for k in range(t, l+1, 2*t):
for j in range(t):
if k+j>l:
break
poplist[k+j] += 1
t *= 2
for k in range(len(start)):
for count in range(10*5):
if start[k] == 0:
ans[k] += count
break
else:
start[k] = start[k] % poplist[start[k]]
for k in range(N):
print((ans[k])) | N = int(eval(input()))
X = eval(input())
ans = [1 for _ in range(N)]
if N == 1:
if X[0] == '1':
print((0))
exit()
else:
print((1))
exit()
l = X.count('1')
if l == 0:
for _ in range(N):
print((1))
exit()
if l == 1:
if X[-1] == '1':
for _ in range(N-1):
ans[_] = 2
else:
ans[-1] = 2
for k in range(N):
if X[k] =='1':
ans[k] = 0
for _ in range(N):
print((ans[_]))
exit()
intN = int(X, 2)
N1 = intN %(l-1)
N0 = intN %(l+1)
start = []
s1 = 1
s0 = 1
for k in range(N-1, -1, -1):
if X[k] == '1':
ia = (N1 - s1)%(l-1)
else:
ia = (N0 + s0)%(l+1)
start.append(ia)
s1 = s1*2%(l-1)
s0 = s0*2%(l+1)
start = start[::-1]
"""
poplist = [0 for _ in range(l+1)]
t = 1
while t < l + 2:
for k in range(t, l+1, 2*t):
for j in range(t):
if k+j>l:
break
poplist[k+j] += 1
t *= 2
"""
ml = len(bin(l+1))-2
poplist = [[] for _ in range(ml)]
poplist[0] = [0,1]
for k in range(1, ml):
for m in range(k):
poplist[k] += poplist[m]
for m in range(len(poplist[k])):
poplist[k][m] += 1
newpoplist = []
for _ in range(len(poplist)):
newpoplist += poplist[_]
poplist = newpoplist
for k in range(len(start)):
for count in range(10*5):
if start[k] == 0:
ans[k] += count
break
else:
start[k] = start[k] % poplist[start[k]]
for k in range(N):
print((ans[k])) | 77 | 87 | 1,182 | 1,464 | N = int(eval(input()))
X = eval(input())
ans = [1 for _ in range(N)]
if N == 1:
if X[0] == "1":
print((0))
exit()
else:
print((1))
exit()
l = 0
for k in range(N):
if X[k] == "1":
l += 1
if l == 0:
for _ in range(N):
print((1))
exit()
if l == 1:
if X[-1] == "1":
for _ in range(N - 1):
ans[_] = 2
else:
ans[-1] = 2
for k in range(N):
if X[k] == "1":
ans[k] = 0
for _ in range(N):
print((ans[_]))
exit()
intN = int(X, 2)
N1 = intN % (l - 1)
N0 = intN % (l + 1)
start = []
s1 = 1
s0 = 1
for k in range(N - 1, -1, -1):
if X[k] == "1":
ia = (N1 - s1) % (l - 1)
else:
ia = (N0 + s0) % (l + 1)
start.append(ia)
s1 = s1 * 2 % (l - 1)
s0 = s0 * 2 % (l + 1)
start = start[::-1]
poplist = [0 for _ in range(l + 1)]
t = 1
while t < l + 2:
for k in range(t, l + 1, 2 * t):
for j in range(t):
if k + j > l:
break
poplist[k + j] += 1
t *= 2
for k in range(len(start)):
for count in range(10 * 5):
if start[k] == 0:
ans[k] += count
break
else:
start[k] = start[k] % poplist[start[k]]
for k in range(N):
print((ans[k]))
| N = int(eval(input()))
X = eval(input())
ans = [1 for _ in range(N)]
if N == 1:
if X[0] == "1":
print((0))
exit()
else:
print((1))
exit()
l = X.count("1")
if l == 0:
for _ in range(N):
print((1))
exit()
if l == 1:
if X[-1] == "1":
for _ in range(N - 1):
ans[_] = 2
else:
ans[-1] = 2
for k in range(N):
if X[k] == "1":
ans[k] = 0
for _ in range(N):
print((ans[_]))
exit()
intN = int(X, 2)
N1 = intN % (l - 1)
N0 = intN % (l + 1)
start = []
s1 = 1
s0 = 1
for k in range(N - 1, -1, -1):
if X[k] == "1":
ia = (N1 - s1) % (l - 1)
else:
ia = (N0 + s0) % (l + 1)
start.append(ia)
s1 = s1 * 2 % (l - 1)
s0 = s0 * 2 % (l + 1)
start = start[::-1]
"""
poplist = [0 for _ in range(l+1)]
t = 1
while t < l + 2:
for k in range(t, l+1, 2*t):
for j in range(t):
if k+j>l:
break
poplist[k+j] += 1
t *= 2
"""
ml = len(bin(l + 1)) - 2
poplist = [[] for _ in range(ml)]
poplist[0] = [0, 1]
for k in range(1, ml):
for m in range(k):
poplist[k] += poplist[m]
for m in range(len(poplist[k])):
poplist[k][m] += 1
newpoplist = []
for _ in range(len(poplist)):
newpoplist += poplist[_]
poplist = newpoplist
for k in range(len(start)):
for count in range(10 * 5):
if start[k] == 0:
ans[k] += count
break
else:
start[k] = start[k] % poplist[start[k]]
for k in range(N):
print((ans[k]))
| false | 11.494253 | [
"-l = 0",
"-for k in range(N):",
"- if X[k] == \"1\":",
"- l += 1",
"+l = X.count(\"1\")",
"-poplist = [0 for _ in range(l + 1)]",
"+\"\"\"",
"+poplist = [0 for _ in range(l+1)]",
"- for k in range(t, l + 1, 2 * t):",
"- for j in range(t):",
"- if k + j > l:",
"-... | false | 0.075114 | 0.04012 | 1.872237 | [
"s627589331",
"s509743715"
] |
u254871849 | p03673 | python | s601816984 | s024714981 | 299 | 195 | 22,708 | 25,948 | Accepted | Accepted | 34.78 | import sys
input = sys.stdin.readline
import collections
n = int(input().rstrip())
a = [a for a in input().split()]
b = collections.deque([], maxlen=n)
for i in range(n):
b.append(a[i]) if i % 2 == 0 else b.appendleft(a[i])
if (n - 1) % 2 == 0: b = list(reversed(b))
for elem in b: print(elem, end=' ')
| import sys
from collections import deque
n, *a = map(int, sys.stdin.read().split())
def main():
b = deque()
for i in range(n):
if i & 1:
b.appendleft(a[i])
else:
b.append(a[i])
res = list(b)
if n & 1:
res = res[::-1]
return res
if __name__ == '__main__':
ans = main()
print(*ans, sep=' ')
| 13 | 21 | 321 | 388 | import sys
input = sys.stdin.readline
import collections
n = int(input().rstrip())
a = [a for a in input().split()]
b = collections.deque([], maxlen=n)
for i in range(n):
b.append(a[i]) if i % 2 == 0 else b.appendleft(a[i])
if (n - 1) % 2 == 0:
b = list(reversed(b))
for elem in b:
print(elem, end=" ")
| import sys
from collections import deque
n, *a = map(int, sys.stdin.read().split())
def main():
b = deque()
for i in range(n):
if i & 1:
b.appendleft(a[i])
else:
b.append(a[i])
res = list(b)
if n & 1:
res = res[::-1]
return res
if __name__ == "__main__":
ans = main()
print(*ans, sep=" ")
| false | 38.095238 | [
"+from collections import deque",
"-input = sys.stdin.readline",
"-import collections",
"+n, *a = map(int, sys.stdin.read().split())",
"-n = int(input().rstrip())",
"-a = [a for a in input().split()]",
"-b = collections.deque([], maxlen=n)",
"-for i in range(n):",
"- b.append(a[i]) if i % 2 == 0 ... | false | 0.108155 | 0.049463 | 2.186599 | [
"s601816984",
"s024714981"
] |
u021019433 | p02642 | python | s363241226 | s536242029 | 256 | 208 | 163,300 | 98,156 | Accepted | Accepted | 18.75 | N = 1000001
a = [0]* N
eval(input())
for x in input().split():
a[int(x)] += 1
for i in range(1, N):
if a[i]:
a[i + i::i] = (0 for _ in a[i + i::i])
print((a.count(1)))
| N = 1000001
a = [0]* N
_, s = open(0)
for x in s.split():
a[int(x)] += 1
for i in range(1, N):
for j in range(i + i, N, i):
if a[i]:
a[j] = 0
print((a.count(1)))
| 9 | 10 | 176 | 183 | N = 1000001
a = [0] * N
eval(input())
for x in input().split():
a[int(x)] += 1
for i in range(1, N):
if a[i]:
a[i + i :: i] = (0 for _ in a[i + i :: i])
print((a.count(1)))
| N = 1000001
a = [0] * N
_, s = open(0)
for x in s.split():
a[int(x)] += 1
for i in range(1, N):
for j in range(i + i, N, i):
if a[i]:
a[j] = 0
print((a.count(1)))
| false | 10 | [
"-eval(input())",
"-for x in input().split():",
"+_, s = open(0)",
"+for x in s.split():",
"- if a[i]:",
"- a[i + i :: i] = (0 for _ in a[i + i :: i])",
"+ for j in range(i + i, N, i):",
"+ if a[i]:",
"+ a[j] = 0"
] | false | 0.302496 | 3.220693 | 0.093923 | [
"s363241226",
"s536242029"
] |
u061916079 | p03723 | python | s344552358 | s718188919 | 161 | 26 | 12,400 | 2,940 | Accepted | Accepted | 83.85 | # -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
import collections
mo = 1000000007
r = range
x, y, z = list(map(int, input().split()))
ret = 0
while not(x % 2 == 1 or y % 2 == 1 or z % 2 == 1):
ret += 1
x, y, z = y//2+z//2, z//2+x//2, x//2+y//2
if ret > 10000:
ret = -1
break;
print(ret) | x, y, z = list(map(int, input().split()))
ret = 0
while not(x % 2 == 1 or y % 2 == 1 or z % 2 == 1):
ret += 1
x, y, z = y//2+z//2, z//2+x//2, x//2+y//2
if ret > 10000:
ret = -1
break;
print(ret) | 21 | 11 | 384 | 228 | # -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
import collections
mo = 1000000007
r = range
x, y, z = list(map(int, input().split()))
ret = 0
while not (x % 2 == 1 or y % 2 == 1 or z % 2 == 1):
ret += 1
x, y, z = y // 2 + z // 2, z // 2 + x // 2, x // 2 + y // 2
if ret > 10000:
ret = -1
break
print(ret)
| x, y, z = list(map(int, input().split()))
ret = 0
while not (x % 2 == 1 or y % 2 == 1 or z % 2 == 1):
ret += 1
x, y, z = y // 2 + z // 2, z // 2 + x // 2, x // 2 + y // 2
if ret > 10000:
ret = -1
break
print(ret)
| false | 47.619048 | [
"-# -*- coding: utf-8 -*-",
"-import math",
"-import sys",
"-import itertools",
"-import numpy as np",
"-import functools",
"-import collections",
"-",
"-mo = 1000000007",
"-r = range"
] | false | 0.043623 | 0.035518 | 1.228191 | [
"s344552358",
"s718188919"
] |
u353919145 | p03352 | python | s785227643 | s575825266 | 23 | 18 | 2,940 | 3,064 | Accepted | Accepted | 21.74 | X=int(eval(input()))
s=[]
for i in range(1,100,+1):
for j in range(2,100,+1):
if i**j<=X:
s.append(i**j)
print((max(s)))
| n=int(eval(input()))
a=[1]
for i in range(2,33):
for j in range(2,11):
x=i**j
if x<=1000:
a.append(x)
a=list(set(a))
a.sort()
def binarySearch(value, xList):
low=0
high=len(xList)
while low!=high:
mid=(low+high)//2
if xList[mid]<=value:
low=mid+1
else:
high=mid
return xList[low-1]
print((binarySearch(n,a))) | 8 | 24 | 138 | 402 | X = int(eval(input()))
s = []
for i in range(1, 100, +1):
for j in range(2, 100, +1):
if i**j <= X:
s.append(i**j)
print((max(s)))
| n = int(eval(input()))
a = [1]
for i in range(2, 33):
for j in range(2, 11):
x = i**j
if x <= 1000:
a.append(x)
a = list(set(a))
a.sort()
def binarySearch(value, xList):
low = 0
high = len(xList)
while low != high:
mid = (low + high) // 2
if xList[mid] <= value:
low = mid + 1
else:
high = mid
return xList[low - 1]
print((binarySearch(n, a)))
| false | 66.666667 | [
"-X = int(eval(input()))",
"-s = []",
"-for i in range(1, 100, +1):",
"- for j in range(2, 100, +1):",
"- if i**j <= X:",
"- s.append(i**j)",
"-print((max(s)))",
"+n = int(eval(input()))",
"+a = [1]",
"+for i in range(2, 33):",
"+ for j in range(2, 11):",
"+ x = ... | false | 0.04315 | 0.035849 | 1.20367 | [
"s785227643",
"s575825266"
] |
u633068244 | p00085 | python | s204663514 | s679952750 | 430 | 20 | 4,260 | 4,256 | Accepted | Accepted | 95.35 | while True:
n, m = list(map(int, input().split()))
if n == 0 and m == 0:
break
p = [ 1 for i in range(n) ]
pn = n; count = 0; flag = 1
while flag == 1:
for i in range(n):
if p[i] == 1:
count += 1
if count == m:
p[i] = 0
count = 0
pn -= 1
if pn == 1:
flag = 0
break
print(p.index(1)+1) | while True:
n, m = list(map(int, input().split()))
if n == 0 and m == 0:
break
p = [ i+1 for i in range(n) ]
np = n; a = 0
while np > 1:
a = (a+m-1)%len(p)
p.pop(a)
np -= 1
print(p[0]) | 19 | 11 | 618 | 275 | while True:
n, m = list(map(int, input().split()))
if n == 0 and m == 0:
break
p = [1 for i in range(n)]
pn = n
count = 0
flag = 1
while flag == 1:
for i in range(n):
if p[i] == 1:
count += 1
if count == m:
p[i] = 0
count = 0
pn -= 1
if pn == 1:
flag = 0
break
print(p.index(1) + 1)
| while True:
n, m = list(map(int, input().split()))
if n == 0 and m == 0:
break
p = [i + 1 for i in range(n)]
np = n
a = 0
while np > 1:
a = (a + m - 1) % len(p)
p.pop(a)
np -= 1
print(p[0])
| false | 42.105263 | [
"- p = [1 for i in range(n)]",
"- pn = n",
"- count = 0",
"- flag = 1",
"- while flag == 1:",
"- for i in range(n):",
"- if p[i] == 1:",
"- count += 1",
"- if count == m:",
"- p[i] = 0",
"- count... | false | 0.041228 | 0.034919 | 1.180685 | [
"s204663514",
"s679952750"
] |
u562935282 | p02693 | python | s046981149 | s763577953 | 24 | 22 | 9,160 | 9,160 | Accepted | Accepted | 8.33 | def main():
K = int(eval(input()))
A, B = list(map(int, input().split()))
for x in range(A, B + 1):
if x % K == 0:
print('OK')
return
print('NG')
if __name__ == '__main__':
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
# while abs(ok - ng) > 1:
# mid = (ok + ng) // 2
# if func(mid):
# ok = mid
# else:
# ng = mid
# return ok
| def main():
from math import floor
K = int(eval(input()))
A, B = list(map(int, input().split()))
multiple = floor(B / K) * K # BไปฅไธใฎๆๅคงใฎKใฎๅๆฐ
cond = (A <= multiple) # Aไปฅไธใชใ็ฏๅฒๅ
ใซใใ
print(('OK' if cond else 'NG'))
if __name__ == '__main__':
main()
| 30 | 15 | 586 | 280 | def main():
K = int(eval(input()))
A, B = list(map(int, input().split()))
for x in range(A, B + 1):
if x % K == 0:
print("OK")
return
print("NG")
if __name__ == "__main__":
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
# while abs(ok - ng) > 1:
# mid = (ok + ng) // 2
# if func(mid):
# ok = mid
# else:
# ng = mid
# return ok
| def main():
from math import floor
K = int(eval(input()))
A, B = list(map(int, input().split()))
multiple = floor(B / K) * K # BไปฅไธใฎๆๅคงใฎKใฎๅๆฐ
cond = A <= multiple # Aไปฅไธใชใ็ฏๅฒๅ
ใซใใ
print(("OK" if cond else "NG"))
if __name__ == "__main__":
main()
| false | 50 | [
"+ from math import floor",
"+",
"- for x in range(A, B + 1):",
"- if x % K == 0:",
"- print(\"OK\")",
"- return",
"- print(\"NG\")",
"+ multiple = floor(B / K) * K # BไปฅไธใฎๆๅคงใฎKใฎๅๆฐ",
"+ cond = A <= multiple # Aไปฅไธใชใ็ฏๅฒๅ
ใซใใ",
"+ print((\"OK\" if cond els... | false | 0.045437 | 0.153867 | 0.295303 | [
"s046981149",
"s763577953"
] |
u721316601 | p02989 | python | s917746676 | s802045825 | 146 | 77 | 14,780 | 14,428 | Accepted | Accepted | 47.26 | from collections import Counter
N = int(eval(input()))
d = Counter(list(map(int, input().split())))
ans = 0
l, r = 0, N
for K in range(10**5+1):
if l == r:
ans += 1
l += d[K]
r -= d[K]
print(ans) | N = int(eval(input()))
d = sorted(list(map(int, input().split())), reverse=True)
print((d[N//2-1] - d[N//2])) | 14 | 4 | 225 | 105 | from collections import Counter
N = int(eval(input()))
d = Counter(list(map(int, input().split())))
ans = 0
l, r = 0, N
for K in range(10**5 + 1):
if l == r:
ans += 1
l += d[K]
r -= d[K]
print(ans)
| N = int(eval(input()))
d = sorted(list(map(int, input().split())), reverse=True)
print((d[N // 2 - 1] - d[N // 2]))
| false | 71.428571 | [
"-from collections import Counter",
"-",
"-d = Counter(list(map(int, input().split())))",
"-ans = 0",
"-l, r = 0, N",
"-for K in range(10**5 + 1):",
"- if l == r:",
"- ans += 1",
"- l += d[K]",
"- r -= d[K]",
"-print(ans)",
"+d = sorted(list(map(int, input().split())), reverse=... | false | 0.2312 | 0.068535 | 3.373468 | [
"s917746676",
"s802045825"
] |
u706984643 | p02996 | python | s966449186 | s403538444 | 742 | 621 | 104,388 | 96,552 | Accepted | Accepted | 16.31 | import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:list(map(int,input().split()))
ll=lambda:list(map(int,input().split()))
ii=lambda:int(eval(input()))
ip=lambda:list(eval(input()))
ips=lambda:input().split()
"""========main code==============="""
#t=1
t=ii()
lol=[]
ans=0
for _ in range(t):
a,b=ml()
lol.append([b,a])
lol.sort()
f=0
for i in range(t):
if(lol[i][1]+ans<=lol[i][0]):
ans+=lol[i][1]
else:
f=1
break
if f:
print("No")
else:
print("Yes") | import sys
input=sys.stdin.readline
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:list(map(int,input().split()))
ll=lambda:list(map(int,input().split()))
ii=lambda:int(eval(input()))
ip=lambda:list(eval(input()))
ips=lambda:input().split()
"""========main code==============="""
#t=1
t=ii()
lol=[]
ans=0
for _ in range(t):
a,b=ml()
lol.append([b,a])
lol.sort()
f=0
for i in range(t):
if(lol[i][1]+ans<=lol[i][0]):
ans+=lol[i][1]
else:
f=1
break
if f:
print("No")
else:
print("Yes") | 30 | 32 | 564 | 602 | import math
from collections import defaultdict, deque
from itertools import permutations
ml = lambda: list(map(int, input().split()))
ll = lambda: list(map(int, input().split()))
ii = lambda: int(eval(input()))
ip = lambda: list(eval(input()))
ips = lambda: input().split()
"""========main code==============="""
# t=1
t = ii()
lol = []
ans = 0
for _ in range(t):
a, b = ml()
lol.append([b, a])
lol.sort()
f = 0
for i in range(t):
if lol[i][1] + ans <= lol[i][0]:
ans += lol[i][1]
else:
f = 1
break
if f:
print("No")
else:
print("Yes")
| import sys
input = sys.stdin.readline
import math
from collections import defaultdict, deque
from itertools import permutations
ml = lambda: list(map(int, input().split()))
ll = lambda: list(map(int, input().split()))
ii = lambda: int(eval(input()))
ip = lambda: list(eval(input()))
ips = lambda: input().split()
"""========main code==============="""
# t=1
t = ii()
lol = []
ans = 0
for _ in range(t):
a, b = ml()
lol.append([b, a])
lol.sort()
f = 0
for i in range(t):
if lol[i][1] + ans <= lol[i][0]:
ans += lol[i][1]
else:
f = 1
break
if f:
print("No")
else:
print("Yes")
| false | 6.25 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.035819 | 0.054285 | 0.659835 | [
"s966449186",
"s403538444"
] |
u153259685 | p02711 | python | s356959313 | s793183772 | 22 | 20 | 9,004 | 9,084 | Accepted | Accepted | 9.09 | string=eval(input())
if "7" in string:
print('Yes')
else:
print('No') | string=eval(input())
t=False
for i in range (len(string)):
if string[i]=="7":
t=True
if t==True:
print("Yes")
else:
print("No")
| 5 | 9 | 71 | 140 | string = eval(input())
if "7" in string:
print("Yes")
else:
print("No")
| string = eval(input())
t = False
for i in range(len(string)):
if string[i] == "7":
t = True
if t == True:
print("Yes")
else:
print("No")
| false | 44.444444 | [
"-if \"7\" in string:",
"+t = False",
"+for i in range(len(string)):",
"+ if string[i] == \"7\":",
"+ t = True",
"+if t == True:"
] | false | 0.097606 | 0.084064 | 1.161099 | [
"s356959313",
"s793183772"
] |
u844789719 | p03458 | python | s412680938 | s846311027 | 764 | 597 | 83,260 | 199,776 | Accepted | Accepted | 21.86 | import itertools
import numpy as np
N, K, *XYC = open(0).read().split()
N = int(N)
K = int(K)
board = np.zeros((4 * K + 1, 4 * K + 1), dtype=np.uint16)
for x, y, c in zip(XYC[::3], XYC[1::3], XYC[2::3]):
x = int(x)
y = int(y)
if c == 'W':
x += K
x = x % (2 * K)
y = y % (2 * K)
board[x, y] += 1
board[(x + K) % (2 * K), (y + K) % (2 * K)] += 1
board[1 + 2 * K:, 1 + 2 * K:] = board[:2 * K, :2 * K]
board[1:1 + 2 * K, 1 + 2 * K:] = board[1 + 2 * K:, 1 + 2 * K:]
board[1 + 2 * K:, 1:1 + 2 * K] = board[1 + 2 * K:, 1 + 2 * K:]
board[1:1 + 2 * K, 1:1 + 2 * K] = board[1 + 2 * K:, 1 + 2 * K:]
board[0, :] = 0
board[:, 0] = 0
for j in range(1, 3 * K):
board[:, j] += board[:, j - 1]
for j in range(1, 3 * K):
board[j, :] += board[j - 1, :]
ans = np.max(board[K:3 * K, K:3 * K] + board[:2 * K, :2 * K] -
board[:2 * K, K:3 * K] - board[K:3 * K, :2 * K])
print(ans)
| import numpy as np
N, K, *XYC = open(0).read().split()
N = int(N)
K = int(K)
board = np.zeros((4 * K + 1, 4 * K + 1), dtype=np.int64)
for x, y, c in zip(XYC[::3], XYC[1::3], XYC[2::3]):
x = int(x)
y = int(y)
if c == 'W':
x += K
x = x % (2 * K)
y = y % (2 * K)
board[x, y] += 1
board[(x + K) % (2 * K), (y + K) % (2 * K)] += 1
board[1 + 2 * K:, 1 + 2 * K:] = board[:2 * K, :2 * K]
board[1:1 + 2 * K, 1 + 2 * K:] = board[1 + 2 * K:, 1 + 2 * K:]
board[1 + 2 * K:, 1:1 + 2 * K] = board[1 + 2 * K:, 1 + 2 * K:]
board[1:1 + 2 * K, 1:1 + 2 * K] = board[1 + 2 * K:, 1 + 2 * K:]
board[0, :] = 0
board[:, 0] = 0
for j in range(1, 3 * K):
board[:, j] += board[:, j - 1]
for j in range(1, 3 * K):
board[j, :] += board[j - 1, :]
ans = np.max(board[K:3 * K, K:3 * K] + board[:2 * K, :2 * K] -
board[:2 * K, K:3 * K] - board[K:3 * K, :2 * K])
print(ans)
| 28 | 27 | 941 | 922 | import itertools
import numpy as np
N, K, *XYC = open(0).read().split()
N = int(N)
K = int(K)
board = np.zeros((4 * K + 1, 4 * K + 1), dtype=np.uint16)
for x, y, c in zip(XYC[::3], XYC[1::3], XYC[2::3]):
x = int(x)
y = int(y)
if c == "W":
x += K
x = x % (2 * K)
y = y % (2 * K)
board[x, y] += 1
board[(x + K) % (2 * K), (y + K) % (2 * K)] += 1
board[1 + 2 * K :, 1 + 2 * K :] = board[: 2 * K, : 2 * K]
board[1 : 1 + 2 * K, 1 + 2 * K :] = board[1 + 2 * K :, 1 + 2 * K :]
board[1 + 2 * K :, 1 : 1 + 2 * K] = board[1 + 2 * K :, 1 + 2 * K :]
board[1 : 1 + 2 * K, 1 : 1 + 2 * K] = board[1 + 2 * K :, 1 + 2 * K :]
board[0, :] = 0
board[:, 0] = 0
for j in range(1, 3 * K):
board[:, j] += board[:, j - 1]
for j in range(1, 3 * K):
board[j, :] += board[j - 1, :]
ans = np.max(
board[K : 3 * K, K : 3 * K]
+ board[: 2 * K, : 2 * K]
- board[: 2 * K, K : 3 * K]
- board[K : 3 * K, : 2 * K]
)
print(ans)
| import numpy as np
N, K, *XYC = open(0).read().split()
N = int(N)
K = int(K)
board = np.zeros((4 * K + 1, 4 * K + 1), dtype=np.int64)
for x, y, c in zip(XYC[::3], XYC[1::3], XYC[2::3]):
x = int(x)
y = int(y)
if c == "W":
x += K
x = x % (2 * K)
y = y % (2 * K)
board[x, y] += 1
board[(x + K) % (2 * K), (y + K) % (2 * K)] += 1
board[1 + 2 * K :, 1 + 2 * K :] = board[: 2 * K, : 2 * K]
board[1 : 1 + 2 * K, 1 + 2 * K :] = board[1 + 2 * K :, 1 + 2 * K :]
board[1 + 2 * K :, 1 : 1 + 2 * K] = board[1 + 2 * K :, 1 + 2 * K :]
board[1 : 1 + 2 * K, 1 : 1 + 2 * K] = board[1 + 2 * K :, 1 + 2 * K :]
board[0, :] = 0
board[:, 0] = 0
for j in range(1, 3 * K):
board[:, j] += board[:, j - 1]
for j in range(1, 3 * K):
board[j, :] += board[j - 1, :]
ans = np.max(
board[K : 3 * K, K : 3 * K]
+ board[: 2 * K, : 2 * K]
- board[: 2 * K, K : 3 * K]
- board[K : 3 * K, : 2 * K]
)
print(ans)
| false | 3.571429 | [
"-import itertools",
"-board = np.zeros((4 * K + 1, 4 * K + 1), dtype=np.uint16)",
"+board = np.zeros((4 * K + 1, 4 * K + 1), dtype=np.int64)"
] | false | 0.460822 | 0.482082 | 0.955901 | [
"s412680938",
"s846311027"
] |
u396368249 | p03573 | python | s828647353 | s467655901 | 354 | 169 | 22,276 | 13,492 | Accepted | Accepted | 52.26 | # -*- coding: utf-8 -*-
import sys, copy, math, itertools
from copy import *
from collections import deque
import numpy as np
from heapq import *
from bisect import *
import scipy as sp
A, B, C = list( map(int, input().split() ) )
if A==B: print(C)
if B==C: print(A)
if C==A: print(B) | # -*- coding: utf-8 -*-
import sys, copy, math, itertools
from copy import *
from collections import deque
import numpy as np
from heapq import *
from bisect import *
import scipy as sp
#from scipy.optimize import linprog
from scipy import ceil, ifft
from scipy.fftpack import fft
A, B, C = list( map(int, input().split() ) )
if A==B: print(C)
if B==C: print(A)
if C==A: print(B) | 14 | 17 | 299 | 397 | # -*- coding: utf-8 -*-
import sys, copy, math, itertools
from copy import *
from collections import deque
import numpy as np
from heapq import *
from bisect import *
import scipy as sp
A, B, C = list(map(int, input().split()))
if A == B:
print(C)
if B == C:
print(A)
if C == A:
print(B)
| # -*- coding: utf-8 -*-
import sys, copy, math, itertools
from copy import *
from collections import deque
import numpy as np
from heapq import *
from bisect import *
import scipy as sp
# from scipy.optimize import linprog
from scipy import ceil, ifft
from scipy.fftpack import fft
A, B, C = list(map(int, input().split()))
if A == B:
print(C)
if B == C:
print(A)
if C == A:
print(B)
| false | 17.647059 | [
"+# from scipy.optimize import linprog",
"+from scipy import ceil, ifft",
"+from scipy.fftpack import fft",
"+"
] | false | 0.042152 | 0.041986 | 1.003939 | [
"s828647353",
"s467655901"
] |
u532966492 | p02757 | python | s809911363 | s463688619 | 916 | 631 | 6,564 | 12,740 | Accepted | Accepted | 31.11 | def main():
n, p = list(map(int, input().split()))
s = list(map(int, list(eval(input()))))
now = 1
now2 = 0
dp = [0]*p
cnt = 0
if p != 5:
for i in s:
now2 = (now2*10+i) % p
dp[((i-now2) % p)*pow(now, p-2, p) % p] += 1
cnt += dp[((-now2) % p)*pow(now, p-2, p) % p]
now = (now*10) % p
else:
for j, i in enumerate(s):
if i in [0, 5]:
cnt += j+1
print(cnt)
main()
| n,p=list(map(int,input().split()));s,n,N,c,d=list(map(int,list(eval(input())))),1,0,0,[0]*p
if p!=5:
for i in s:N,a=(N*10+i)%p,pow(n,p-2,p);d[(i-N)*a%p]+=1;c+=d[-N*a%p];n=n*10%p
else:c=sum([j+1 for j,i in enumerate(s)if i%5==0])
print(c) | 22 | 5 | 500 | 224 | def main():
n, p = list(map(int, input().split()))
s = list(map(int, list(eval(input()))))
now = 1
now2 = 0
dp = [0] * p
cnt = 0
if p != 5:
for i in s:
now2 = (now2 * 10 + i) % p
dp[((i - now2) % p) * pow(now, p - 2, p) % p] += 1
cnt += dp[((-now2) % p) * pow(now, p - 2, p) % p]
now = (now * 10) % p
else:
for j, i in enumerate(s):
if i in [0, 5]:
cnt += j + 1
print(cnt)
main()
| n, p = list(map(int, input().split()))
s, n, N, c, d = list(map(int, list(eval(input())))), 1, 0, 0, [0] * p
if p != 5:
for i in s:
N, a = (N * 10 + i) % p, pow(n, p - 2, p)
d[(i - N) * a % p] += 1
c += d[-N * a % p]
n = n * 10 % p
else:
c = sum([j + 1 for j, i in enumerate(s) if i % 5 == 0])
print(c)
| false | 77.272727 | [
"-def main():",
"- n, p = list(map(int, input().split()))",
"- s = list(map(int, list(eval(input()))))",
"- now = 1",
"- now2 = 0",
"- dp = [0] * p",
"- cnt = 0",
"- if p != 5:",
"- for i in s:",
"- now2 = (now2 * 10 + i) % p",
"- dp[((i - now2) ... | false | 0.036077 | 0.034399 | 1.04879 | [
"s809911363",
"s463688619"
] |
u179304833 | p02659 | python | s301867252 | s433367605 | 27 | 24 | 10,076 | 9,116 | Accepted | Accepted | 11.11 | import math
import decimal
x,y = list(map(decimal.Decimal,input().split()))
print((math.floor(x*y))) | x,y = list(map(str,input().split()))
yy=y.replace(".","")
xy=str(int(x)*int(yy))
print((xy[:len(xy)-2] if len(xy)>2 else 0))
| 4 | 4 | 101 | 126 | import math
import decimal
x, y = list(map(decimal.Decimal, input().split()))
print((math.floor(x * y)))
| x, y = list(map(str, input().split()))
yy = y.replace(".", "")
xy = str(int(x) * int(yy))
print((xy[: len(xy) - 2] if len(xy) > 2 else 0))
| false | 0 | [
"-import math",
"-import decimal",
"-",
"-x, y = list(map(decimal.Decimal, input().split()))",
"-print((math.floor(x * y)))",
"+x, y = list(map(str, input().split()))",
"+yy = y.replace(\".\", \"\")",
"+xy = str(int(x) * int(yy))",
"+print((xy[: len(xy) - 2] if len(xy) > 2 else 0))"
] | false | 0.17639 | 0.05476 | 3.221125 | [
"s301867252",
"s433367605"
] |
u761320129 | p03427 | python | s425487357 | s282644720 | 30 | 26 | 9,144 | 9,128 | Accepted | Accepted | 13.33 | N = eval(input())
ans = sum(int(c) for c in N)
for i in range(1,len(N)):
t = sum(int(c) for c in N[:i]) - 1 + 9 * (len(N) - i)
ans = max(ans, t)
print(ans) | S = eval(input())
N = int(S)
ans = sum(map(int,S))
for i in range(1,len(S)):
n = str(int(S[:i]) - 1)
t = sum(map(int,n)) + 9*(len(S)-i)
ans = max(ans,t)
print(ans) | 7 | 9 | 164 | 178 | N = eval(input())
ans = sum(int(c) for c in N)
for i in range(1, len(N)):
t = sum(int(c) for c in N[:i]) - 1 + 9 * (len(N) - i)
ans = max(ans, t)
print(ans)
| S = eval(input())
N = int(S)
ans = sum(map(int, S))
for i in range(1, len(S)):
n = str(int(S[:i]) - 1)
t = sum(map(int, n)) + 9 * (len(S) - i)
ans = max(ans, t)
print(ans)
| false | 22.222222 | [
"-N = eval(input())",
"-ans = sum(int(c) for c in N)",
"-for i in range(1, len(N)):",
"- t = sum(int(c) for c in N[:i]) - 1 + 9 * (len(N) - i)",
"+S = eval(input())",
"+N = int(S)",
"+ans = sum(map(int, S))",
"+for i in range(1, len(S)):",
"+ n = str(int(S[:i]) - 1)",
"+ t = sum(map(int, ... | false | 0.037275 | 0.037289 | 0.999629 | [
"s425487357",
"s282644720"
] |
u940568210 | p03379 | python | s206922318 | s047932205 | 1,140 | 318 | 35,724 | 29,972 | Accepted | Accepted | 72.11 |
import numpy as np
n = int(eval(input()))
x_str = input().split()
xs = np.array([int(c) for c in x_str])
xs_len = len(xs)
center = (xs_len - 1)//2
c_xs = np.sort(xs)
for x in xs:
if x <= c_xs[center]:
print((c_xs[center+1]))
else:
print((c_xs[center]))
|
n = int(eval(input()))
x_str = input().split()
xs = [int(c) for c in x_str]
xs_len = len(xs)
center = (xs_len - 1)//2
c_xs = xs[:]
c_xs.sort()
for x in xs:
if x <= c_xs[center]:
print((c_xs[center+1]))
else:
print((c_xs[center]))
| 17 | 16 | 288 | 263 | import numpy as np
n = int(eval(input()))
x_str = input().split()
xs = np.array([int(c) for c in x_str])
xs_len = len(xs)
center = (xs_len - 1) // 2
c_xs = np.sort(xs)
for x in xs:
if x <= c_xs[center]:
print((c_xs[center + 1]))
else:
print((c_xs[center]))
| n = int(eval(input()))
x_str = input().split()
xs = [int(c) for c in x_str]
xs_len = len(xs)
center = (xs_len - 1) // 2
c_xs = xs[:]
c_xs.sort()
for x in xs:
if x <= c_xs[center]:
print((c_xs[center + 1]))
else:
print((c_xs[center]))
| false | 5.882353 | [
"-import numpy as np",
"-",
"-xs = np.array([int(c) for c in x_str])",
"+xs = [int(c) for c in x_str]",
"-c_xs = np.sort(xs)",
"+c_xs = xs[:]",
"+c_xs.sort()"
] | false | 0.287624 | 0.039268 | 7.324556 | [
"s206922318",
"s047932205"
] |
u545368057 | p03576 | python | s111477974 | s660486000 | 690 | 143 | 9,292 | 74,520 | Accepted | Accepted | 79.28 | """
ๅบงๆจๅง็ธฎ
2D็ดฏ็ฉๅ
ๅ
จๆข็ดข
ๅๅฉ
"""
n, k = list(map(int,input().split()))
xs = set()
ys = set()
ps = []
# ๅบงๅง
for _ in range(n):
x,y = list(map(int,input().split()))
ps.append((x,y))
xs.add(x)
ys.add(y)
xdic = {x:i for i,x in enumerate(sorted(list(xs)))}
ydic = {y:i for i,y in enumerate(sorted(list(ys)))}
rxdic = {i:x for i,x in enumerate(sorted(list(xs)))}
rydic = {i:y for i,y in enumerate(sorted(list(ys)))}
# 2D็ดฏ็ฉๅ
h = len(xdic)
w = len(ydic)
A = [[0 for i in range(w+1)] for j in range(h+1)]
Acum = [[0 for i in range(w+1)] for j in range(h+1)]
for x,y in ps:
h = xdic[x]
w = ydic[y]
A[h][w] += 1
for i in range(len(xdic)):
for j in range(len(ydic)):
Acum[i+1][j+1] = Acum[i][j+1] + Acum[i+1][j] - Acum[i][j] + A[i][j]
# ๆข็ดข
ans = 1 << 100
h = len(xdic)
w = len(ydic)
for i1 in range(h+1):
for i2 in range(i1+1,h+1):
for j1 in range(w+1):
for j2 in range(j1+1,w+1):
num = Acum[i2][j2]-Acum[i1][j2]-Acum[i2][j1]+Acum[i1][j1]
# print((i1,i2),(j1,j2),num)
if num == k:
x1 = rxdic[i1]
x2 = rxdic[i2-1]
y1 = rydic[j1]
y2 = rydic[j2-1]
S = (x2-x1)*(y2-y1)
ans = min(ans, S)
print(ans) | n,k = list(map(int, input().split()))
xs = []
ys = []
ps = []
for i in range(n):
x,y = list(map(int, input().split()))
xs.append(x)
ys.append(y)
ps.append((x,y))
# ๅบงๅง
xs = sorted(list(set(xs)))
ys = sorted(list(set(ys)))
xdic = {x:i for i, x in enumerate(xs)}
ydic = {y:i for i, y in enumerate(ys)}
xrdic = {i:x for i, x in enumerate(xs)}
yrdic = {i:y for i, y in enumerate(ys)}
nx = len(xs)
ny = len(ys)
fs = [[0] * (1+ny) for i in range(nx+1)]
for x,y in ps:
ix = xdic[x]
iy = ydic[y]
fs[ix][iy] += 1
acc = [[0] * (1+ny) for i in range(nx+1)]
for i in range(nx):
for j in range(ny):
acc[i+1][j+1] = acc[i+1][j] + acc[i][j+1] - acc[i][j] + fs[i][j]
def calc(sx,sy,tx,ty):
ix1 = xrdic[sx]
ix2 = xrdic[tx]
iy1 = yrdic[sy]
iy2 = yrdic[ty]
return (ix2-ix1) * (iy2-iy1)
# print(xs,xdic,".",ys,ydic)
ans = 10**20
for sx in range(nx+1):
for sy in range(ny+1):
for tx in range(sx+1, nx+1):
for ty in range(sy+1, ny+1):
cnt = acc[tx][ty] - acc[sx][ty] - acc[tx][sy] + acc[sx][sy]
if cnt >= k:
S = calc(sx,sy,tx-1,ty-1)
ans = min(ans, S)
print(ans) | 54 | 49 | 1,356 | 1,236 | """
ๅบงๆจๅง็ธฎ
2D็ดฏ็ฉๅ
ๅ
จๆข็ดข
ๅๅฉ
"""
n, k = list(map(int, input().split()))
xs = set()
ys = set()
ps = []
# ๅบงๅง
for _ in range(n):
x, y = list(map(int, input().split()))
ps.append((x, y))
xs.add(x)
ys.add(y)
xdic = {x: i for i, x in enumerate(sorted(list(xs)))}
ydic = {y: i for i, y in enumerate(sorted(list(ys)))}
rxdic = {i: x for i, x in enumerate(sorted(list(xs)))}
rydic = {i: y for i, y in enumerate(sorted(list(ys)))}
# 2D็ดฏ็ฉๅ
h = len(xdic)
w = len(ydic)
A = [[0 for i in range(w + 1)] for j in range(h + 1)]
Acum = [[0 for i in range(w + 1)] for j in range(h + 1)]
for x, y in ps:
h = xdic[x]
w = ydic[y]
A[h][w] += 1
for i in range(len(xdic)):
for j in range(len(ydic)):
Acum[i + 1][j + 1] = Acum[i][j + 1] + Acum[i + 1][j] - Acum[i][j] + A[i][j]
# ๆข็ดข
ans = 1 << 100
h = len(xdic)
w = len(ydic)
for i1 in range(h + 1):
for i2 in range(i1 + 1, h + 1):
for j1 in range(w + 1):
for j2 in range(j1 + 1, w + 1):
num = Acum[i2][j2] - Acum[i1][j2] - Acum[i2][j1] + Acum[i1][j1]
# print((i1,i2),(j1,j2),num)
if num == k:
x1 = rxdic[i1]
x2 = rxdic[i2 - 1]
y1 = rydic[j1]
y2 = rydic[j2 - 1]
S = (x2 - x1) * (y2 - y1)
ans = min(ans, S)
print(ans)
| n, k = list(map(int, input().split()))
xs = []
ys = []
ps = []
for i in range(n):
x, y = list(map(int, input().split()))
xs.append(x)
ys.append(y)
ps.append((x, y))
# ๅบงๅง
xs = sorted(list(set(xs)))
ys = sorted(list(set(ys)))
xdic = {x: i for i, x in enumerate(xs)}
ydic = {y: i for i, y in enumerate(ys)}
xrdic = {i: x for i, x in enumerate(xs)}
yrdic = {i: y for i, y in enumerate(ys)}
nx = len(xs)
ny = len(ys)
fs = [[0] * (1 + ny) for i in range(nx + 1)]
for x, y in ps:
ix = xdic[x]
iy = ydic[y]
fs[ix][iy] += 1
acc = [[0] * (1 + ny) for i in range(nx + 1)]
for i in range(nx):
for j in range(ny):
acc[i + 1][j + 1] = acc[i + 1][j] + acc[i][j + 1] - acc[i][j] + fs[i][j]
def calc(sx, sy, tx, ty):
ix1 = xrdic[sx]
ix2 = xrdic[tx]
iy1 = yrdic[sy]
iy2 = yrdic[ty]
return (ix2 - ix1) * (iy2 - iy1)
# print(xs,xdic,".",ys,ydic)
ans = 10**20
for sx in range(nx + 1):
for sy in range(ny + 1):
for tx in range(sx + 1, nx + 1):
for ty in range(sy + 1, ny + 1):
cnt = acc[tx][ty] - acc[sx][ty] - acc[tx][sy] + acc[sx][sy]
if cnt >= k:
S = calc(sx, sy, tx - 1, ty - 1)
ans = min(ans, S)
print(ans)
| false | 9.259259 | [
"-\"\"\"",
"-ๅบงๆจๅง็ธฎ",
"-2D็ดฏ็ฉๅ",
"-ๅ
จๆข็ดข",
"-ๅๅฉ",
"-\"\"\"",
"-xs = set()",
"-ys = set()",
"+xs = []",
"+ys = []",
"+for i in range(n):",
"+ x, y = list(map(int, input().split()))",
"+ xs.append(x)",
"+ ys.append(y)",
"+ ps.append((x, y))",
"-for _ in range(n):",
"- x, y = ... | false | 0.046911 | 0.038593 | 1.215527 | [
"s111477974",
"s660486000"
] |
u762540523 | p03722 | python | s645502066 | s221188057 | 850 | 762 | 3,700 | 3,828 | Accepted | Accepted | 10.35 | def resolve():
n, m = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(m)]
a = [[x, y, -z] for x, y, z in a]
print((BF(a, n, 1)[-1]))
def BF(p, n, s):
inf = float("inf")
d = [inf for i in range(n)]
d[s-1] = 0
for i in range(n+1):
for e in p:
if e[0] != inf and d[e[1]-1] > d[e[0]-1]+e[2]:
d[e[1]-1] = d[e[0]-1] + e[2]
if i == n-1:
t = d[-1]
if i == n and t != d[-1]:
return [0, 'inf']
return list([-x for x in d])
if __name__ == "__main__":
resolve() | def BellmanFord():
def BF(s, n, edge, inf=float("inf")):
d = [inf for i in range(n)]
d[s] = 0
for i in range(n):
for before, after, dist in edge:
if before != inf:
d[after] = min(d[after], d[before] + dist)
if i == n - 2:
t = d[:]
elif i == n - 1:
for i, j in enumerate(d):
if j != t[i]:
d[i] = -inf
return list([-x for x in d])
n, m = list(map(int, input().split()))
inf = 10 ** 20
edge = [list(map(int, input().split())) for i in range(m)]
edge = [[x - 1, y - 1, -z] for x, y, z in edge]
l = BF(0, n, edge)
print((l[-1] if l[-1] < inf else "inf"))
BellmanFord() | 24 | 22 | 625 | 789 | def resolve():
n, m = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(m)]
a = [[x, y, -z] for x, y, z in a]
print((BF(a, n, 1)[-1]))
def BF(p, n, s):
inf = float("inf")
d = [inf for i in range(n)]
d[s - 1] = 0
for i in range(n + 1):
for e in p:
if e[0] != inf and d[e[1] - 1] > d[e[0] - 1] + e[2]:
d[e[1] - 1] = d[e[0] - 1] + e[2]
if i == n - 1:
t = d[-1]
if i == n and t != d[-1]:
return [0, "inf"]
return list([-x for x in d])
if __name__ == "__main__":
resolve()
| def BellmanFord():
def BF(s, n, edge, inf=float("inf")):
d = [inf for i in range(n)]
d[s] = 0
for i in range(n):
for before, after, dist in edge:
if before != inf:
d[after] = min(d[after], d[before] + dist)
if i == n - 2:
t = d[:]
elif i == n - 1:
for i, j in enumerate(d):
if j != t[i]:
d[i] = -inf
return list([-x for x in d])
n, m = list(map(int, input().split()))
inf = 10**20
edge = [list(map(int, input().split())) for i in range(m)]
edge = [[x - 1, y - 1, -z] for x, y, z in edge]
l = BF(0, n, edge)
print((l[-1] if l[-1] < inf else "inf"))
BellmanFord()
| false | 8.333333 | [
"-def resolve():",
"+def BellmanFord():",
"+ def BF(s, n, edge, inf=float(\"inf\")):",
"+ d = [inf for i in range(n)]",
"+ d[s] = 0",
"+ for i in range(n):",
"+ for before, after, dist in edge:",
"+ if before != inf:",
"+ d[after] ... | false | 0.048917 | 0.048165 | 1.015622 | [
"s645502066",
"s221188057"
] |
u867826040 | p03425 | python | s370501264 | s239275998 | 52 | 48 | 9,052 | 9,024 | Accepted | Accepted | 7.69 | from itertools import combinations as cmbs
from sys import stdin
c = {"M":0,"A":0,"R":0,"C":0,"H":0}
for si in [s[0] for s in stdin]:
if si in c:
c[si] += 1
print((sum(i*j*k for i,j,k in cmbs(list(c.values()),r=3))))
| from itertools import combinations as cmbs
from sys import stdin
def main():
c = {"M":0,"A":0,"R":0,"C":0,"H":0}
for si in [s[0] for s in stdin]:
if si in c:
c[si] += 1
print((sum(i*j*k for i,j,k in cmbs(list(c.values()),r=3))))
main()
| 7 | 13 | 230 | 279 | from itertools import combinations as cmbs
from sys import stdin
c = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for si in [s[0] for s in stdin]:
if si in c:
c[si] += 1
print((sum(i * j * k for i, j, k in cmbs(list(c.values()), r=3))))
| from itertools import combinations as cmbs
from sys import stdin
def main():
c = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for si in [s[0] for s in stdin]:
if si in c:
c[si] += 1
print((sum(i * j * k for i, j, k in cmbs(list(c.values()), r=3))))
main()
| false | 46.153846 | [
"-c = {\"M\": 0, \"A\": 0, \"R\": 0, \"C\": 0, \"H\": 0}",
"-for si in [s[0] for s in stdin]:",
"- if si in c:",
"- c[si] += 1",
"-print((sum(i * j * k for i, j, k in cmbs(list(c.values()), r=3))))",
"+",
"+def main():",
"+ c = {\"M\": 0, \"A\": 0, \"R\": 0, \"C\": 0, \"H\": 0}",
"+ ... | false | 0.048576 | 0.045555 | 1.066301 | [
"s370501264",
"s239275998"
] |
u344065503 | p02947 | python | s351821228 | s705398291 | 635 | 266 | 75,096 | 99,860 | Accepted | Accepted | 58.11 | import collections
n=int(eval(input()))
ans=0
s=["".join(sorted(eval(input()))) for _ in range(n)]
c=collections.Counter(s)
for i in set(s):
a=c[i]
ans+=a*(a-1)//2
print(ans)
| n=int(eval(input()))
dictionary={}
count=0
for i in range(n):
s="".join(sorted(eval(input())))
if s in dictionary:
dictionary[s]+=1
count+=dictionary[s]
else:
dictionary[s]=0
print(count)
| 9 | 11 | 175 | 222 | import collections
n = int(eval(input()))
ans = 0
s = ["".join(sorted(eval(input()))) for _ in range(n)]
c = collections.Counter(s)
for i in set(s):
a = c[i]
ans += a * (a - 1) // 2
print(ans)
| n = int(eval(input()))
dictionary = {}
count = 0
for i in range(n):
s = "".join(sorted(eval(input())))
if s in dictionary:
dictionary[s] += 1
count += dictionary[s]
else:
dictionary[s] = 0
print(count)
| false | 18.181818 | [
"-import collections",
"-",
"-ans = 0",
"-s = [\"\".join(sorted(eval(input()))) for _ in range(n)]",
"-c = collections.Counter(s)",
"-for i in set(s):",
"- a = c[i]",
"- ans += a * (a - 1) // 2",
"-print(ans)",
"+dictionary = {}",
"+count = 0",
"+for i in range(n):",
"+ s = \"\".joi... | false | 0.03215 | 0.031446 | 1.022402 | [
"s351821228",
"s705398291"
] |
u969850098 | p02803 | python | s107250772 | s408925098 | 410 | 361 | 3,316 | 3,316 | Accepted | Accepted | 11.95 | from collections import deque
def main():
H, W = list(map(int, input().split()))
maze = [list(eval(input())) for _ in range(H)]
ans = 0
for h in range(H):
for w in range(W):
if maze[h][w] == '#':
continue
goal_dists = [[-1] * W for _ in range(H)]
goal_dists[h][w] = 0
d = deque([[h, w]])
while d:
ht, wt = d.popleft()
for dh, dw in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
if not (0 <= ht+dh < H and 0 <= wt+dw < W):
continue
if maze[ht+dh][wt+dw] == '#':
continue
if goal_dists[ht+dh][wt+dw] == -1:
goal_dists[ht+dh][wt+dw] = goal_dists[ht][wt] + 1
d.append([ht+dh, wt+dw])
ans = max(ans, max([max(l) for l in goal_dists]))
print(ans)
if __name__ == "__main__":
main() | from collections import deque
def main():
H, W = list(map(int, input().split()))
maze = [list(eval(input())) for _ in range(H)]
directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]
ans = 0
for h in range(H):
for w in range(W):
if maze[h][w] == '#':
continue
goal_dists = [[-1] * W for _ in range(H)]
goal_dists[h][w] = 0
d = deque([[h, w]])
while d:
ht, wt = d.popleft()
for dh, dw in directions:
if not (0 <= ht+dh < H and 0 <= wt+dw < W):
continue
if maze[ht+dh][wt+dw] == '#':
continue
if goal_dists[ht+dh][wt+dw] == -1:
goal_dists[ht+dh][wt+dw] = goal_dists[ht][wt] + 1
d.append([ht+dh, wt+dw])
ans = max(ans, max([max(l) for l in goal_dists]))
print(ans)
if __name__ == "__main__":
main() | 33 | 34 | 1,011 | 1,040 | from collections import deque
def main():
H, W = list(map(int, input().split()))
maze = [list(eval(input())) for _ in range(H)]
ans = 0
for h in range(H):
for w in range(W):
if maze[h][w] == "#":
continue
goal_dists = [[-1] * W for _ in range(H)]
goal_dists[h][w] = 0
d = deque([[h, w]])
while d:
ht, wt = d.popleft()
for dh, dw in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
if not (0 <= ht + dh < H and 0 <= wt + dw < W):
continue
if maze[ht + dh][wt + dw] == "#":
continue
if goal_dists[ht + dh][wt + dw] == -1:
goal_dists[ht + dh][wt + dw] = goal_dists[ht][wt] + 1
d.append([ht + dh, wt + dw])
ans = max(ans, max([max(l) for l in goal_dists]))
print(ans)
if __name__ == "__main__":
main()
| from collections import deque
def main():
H, W = list(map(int, input().split()))
maze = [list(eval(input())) for _ in range(H)]
directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]
ans = 0
for h in range(H):
for w in range(W):
if maze[h][w] == "#":
continue
goal_dists = [[-1] * W for _ in range(H)]
goal_dists[h][w] = 0
d = deque([[h, w]])
while d:
ht, wt = d.popleft()
for dh, dw in directions:
if not (0 <= ht + dh < H and 0 <= wt + dw < W):
continue
if maze[ht + dh][wt + dw] == "#":
continue
if goal_dists[ht + dh][wt + dw] == -1:
goal_dists[ht + dh][wt + dw] = goal_dists[ht][wt] + 1
d.append([ht + dh, wt + dw])
ans = max(ans, max([max(l) for l in goal_dists]))
print(ans)
if __name__ == "__main__":
main()
| false | 2.941176 | [
"+ directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]",
"- for dh, dw in [[0, 1], [0, -1], [1, 0], [-1, 0]]:",
"+ for dh, dw in directions:"
] | false | 0.039142 | 0.043148 | 0.907173 | [
"s107250772",
"s408925098"
] |
u836737505 | p02714 | python | s949560844 | s421433153 | 402 | 305 | 73,880 | 73,700 | Accepted | Accepted | 24.13 | n = int(eval(input()))
s = eval(input())
r = s.count("R")
g = s.count("G")
b = s.count("B")
c = 0
for i in range(n):
for j in range(1,int((n-i-1)/2)+1):
if len(set([s[i],s[i+j],s[i+j+j]])) == 3:
c += 1
print(((r*g*b) - c)) | n = int(eval(input()))
s = list(eval(input()))
r = s.count("R")
g = s.count("G")
b = s.count("B")
c = 0
for i in range(n):
j = 1
while i+j+j+1 <= n:
if len(set([s[i],s[i+j],s[i+j+j]]))==3:
c += 1
j += 1
print((r*g*b - c)) | 11 | 13 | 242 | 256 | n = int(eval(input()))
s = eval(input())
r = s.count("R")
g = s.count("G")
b = s.count("B")
c = 0
for i in range(n):
for j in range(1, int((n - i - 1) / 2) + 1):
if len(set([s[i], s[i + j], s[i + j + j]])) == 3:
c += 1
print(((r * g * b) - c))
| n = int(eval(input()))
s = list(eval(input()))
r = s.count("R")
g = s.count("G")
b = s.count("B")
c = 0
for i in range(n):
j = 1
while i + j + j + 1 <= n:
if len(set([s[i], s[i + j], s[i + j + j]])) == 3:
c += 1
j += 1
print((r * g * b - c))
| false | 15.384615 | [
"-s = eval(input())",
"+s = list(eval(input()))",
"- for j in range(1, int((n - i - 1) / 2) + 1):",
"+ j = 1",
"+ while i + j + j + 1 <= n:",
"-print(((r * g * b) - c))",
"+ j += 1",
"+print((r * g * b - c))"
] | false | 0.077914 | 0.116015 | 0.671589 | [
"s949560844",
"s421433153"
] |
u077291787 | p02832 | python | s234416373 | s714202610 | 162 | 84 | 25,116 | 25,116 | Accepted | Accepted | 48.15 | # ABC148D - Brick Break
def main():
N, *A = list(map(int, open(0).read().split()))
remaining = 0
cur = 0 # current index
for target in range(1, N + 1):
be_kept = False
for i in range(cur, N):
if A[i] == target:
remaining += 1
cur = i + 1
be_kept = True
break
if not be_kept:
break
print((N - remaining if remaining else -1))
if __name__ == "__main__":
main()
| # ABC148D - Brick Break
def main():
N, *A = list(map(int, open(0).read().split()))
remaining = 0
target = 1
for i in A:
if i == target:
remaining += 1
target += 1
print((N - remaining if remaining else -1))
if __name__ == "__main__":
main()
| 20 | 14 | 509 | 304 | # ABC148D - Brick Break
def main():
N, *A = list(map(int, open(0).read().split()))
remaining = 0
cur = 0 # current index
for target in range(1, N + 1):
be_kept = False
for i in range(cur, N):
if A[i] == target:
remaining += 1
cur = i + 1
be_kept = True
break
if not be_kept:
break
print((N - remaining if remaining else -1))
if __name__ == "__main__":
main()
| # ABC148D - Brick Break
def main():
N, *A = list(map(int, open(0).read().split()))
remaining = 0
target = 1
for i in A:
if i == target:
remaining += 1
target += 1
print((N - remaining if remaining else -1))
if __name__ == "__main__":
main()
| false | 30 | [
"- cur = 0 # current index",
"- for target in range(1, N + 1):",
"- be_kept = False",
"- for i in range(cur, N):",
"- if A[i] == target:",
"- remaining += 1",
"- cur = i + 1",
"- be_kept = True",
"- break",
... | false | 0.038996 | 0.036689 | 1.062861 | [
"s234416373",
"s714202610"
] |
u620084012 | p03835 | python | s586889129 | s675364044 | 1,892 | 244 | 2,940 | 40,940 | Accepted | Accepted | 87.1 | K, S = list(map(int,input().split()))
ans = 0
for k in range(K+1):
for j in range(S-k+1):
if j <= K and 0 <= S-k-j <= K:
ans += 1
print(ans) | K, S = list(map(int,input().split()))
ans = 0
for X in range(K+1):
for Y in range(K+1):
if 0 <= S-(X+Y) <= K:
ans += 1
print(ans)
| 8 | 7 | 166 | 154 | K, S = list(map(int, input().split()))
ans = 0
for k in range(K + 1):
for j in range(S - k + 1):
if j <= K and 0 <= S - k - j <= K:
ans += 1
print(ans)
| K, S = list(map(int, input().split()))
ans = 0
for X in range(K + 1):
for Y in range(K + 1):
if 0 <= S - (X + Y) <= K:
ans += 1
print(ans)
| false | 12.5 | [
"-for k in range(K + 1):",
"- for j in range(S - k + 1):",
"- if j <= K and 0 <= S - k - j <= K:",
"+for X in range(K + 1):",
"+ for Y in range(K + 1):",
"+ if 0 <= S - (X + Y) <= K:"
] | false | 0.036978 | 0.044103 | 0.838447 | [
"s586889129",
"s675364044"
] |
u665238221 | p02269 | python | s534665363 | s736281271 | 4,580 | 1,130 | 30,992 | 31,412 | Accepted | Accepted | 75.33 | n = int(eval(input()))
d = set()
for _ in range(n):
c, s = input().split()
if c == 'insert':
d.add(s)
else:
print(('yes' if s in d else 'no'))
| import sys
n = int(eval(input()))
d = set()
for i in sys.stdin:
c, s = i.split()
if c == 'insert':
d.add(s)
else:
print(('yes' if s in d else 'no'))
| 8 | 9 | 170 | 177 | n = int(eval(input()))
d = set()
for _ in range(n):
c, s = input().split()
if c == "insert":
d.add(s)
else:
print(("yes" if s in d else "no"))
| import sys
n = int(eval(input()))
d = set()
for i in sys.stdin:
c, s = i.split()
if c == "insert":
d.add(s)
else:
print(("yes" if s in d else "no"))
| false | 11.111111 | [
"+import sys",
"+",
"-for _ in range(n):",
"- c, s = input().split()",
"+for i in sys.stdin:",
"+ c, s = i.split()"
] | false | 0.040128 | 0.036158 | 1.109804 | [
"s534665363",
"s736281271"
] |
u971091945 | p02630 | python | s970177370 | s039808596 | 574 | 410 | 24,000 | 40,324 | Accepted | Accepted | 28.57 | import collections
n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
d = collections.Counter(a)
ans = sum(a)
for i in range(q):
b, c = list(map(int, input().split()))
num = (c-b)*d[b]
ans += num
print(ans)
d[c] += d[b]
d[b] = 0 | import collections
n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
bc = []
for i in range(q):
bci = list(map(int, input().split()))
bc.append(bci)
d = collections.Counter(a)
ans = sum(a)
for i in range(q):
b, c = bc[i]
num = (c-b)*d[b]
ans += num
print(ans)
d[c] += d[b]
d[b] = 0 | 16 | 22 | 283 | 359 | import collections
n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
d = collections.Counter(a)
ans = sum(a)
for i in range(q):
b, c = list(map(int, input().split()))
num = (c - b) * d[b]
ans += num
print(ans)
d[c] += d[b]
d[b] = 0
| import collections
n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
bc = []
for i in range(q):
bci = list(map(int, input().split()))
bc.append(bci)
d = collections.Counter(a)
ans = sum(a)
for i in range(q):
b, c = bc[i]
num = (c - b) * d[b]
ans += num
print(ans)
d[c] += d[b]
d[b] = 0
| false | 27.272727 | [
"+bc = []",
"+for i in range(q):",
"+ bci = list(map(int, input().split()))",
"+ bc.append(bci)",
"- b, c = list(map(int, input().split()))",
"+ b, c = bc[i]"
] | false | 0.035674 | 0.045042 | 0.79201 | [
"s970177370",
"s039808596"
] |
u226108478 | p02582 | python | s846513319 | s787141780 | 29 | 24 | 8,948 | 8,924 | Accepted | Accepted | 17.24 | # -*- coding: utf-8 -*-
def main():
s = eval(input())
# See:
# https://atcoder.jp/contests/abc175/editorial/51
# 1. ๅๆๅญใRใจไธ่ดใใฆใใใ
# 2. ไฝๆๅญไธ่ดใใฆใใใใใๆกไปถๅๅฒ
first = s[0] == 'R'
second = s[1] == 'R'
third = s[2] == 'R'
if first and second and third:
print((3))
elif (first and second) or (second and third):
print((2))
elif (first or second or third):
print((1))
else:
print((0))
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
def main():
s = eval(input())
# See:
# https://atcoder.jp/contests/abc175/submissions/15907467
# Pythonใฎใทใณใฟใใฏในใๆดป็จ
if 'RRR' in s:
print((3))
elif 'RR' in s:
print((2))
elif 'R' in s:
print((1))
else:
print((0))
if __name__ == '__main__':
main()
| 26 | 21 | 509 | 347 | # -*- coding: utf-8 -*-
def main():
s = eval(input())
# See:
# https://atcoder.jp/contests/abc175/editorial/51
# 1. ๅๆๅญใRใจไธ่ดใใฆใใใ
# 2. ไฝๆๅญไธ่ดใใฆใใใใใๆกไปถๅๅฒ
first = s[0] == "R"
second = s[1] == "R"
third = s[2] == "R"
if first and second and third:
print((3))
elif (first and second) or (second and third):
print((2))
elif first or second or third:
print((1))
else:
print((0))
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
def main():
s = eval(input())
# See:
# https://atcoder.jp/contests/abc175/submissions/15907467
# Pythonใฎใทใณใฟใใฏในใๆดป็จ
if "RRR" in s:
print((3))
elif "RR" in s:
print((2))
elif "R" in s:
print((1))
else:
print((0))
if __name__ == "__main__":
main()
| false | 19.230769 | [
"- # https://atcoder.jp/contests/abc175/editorial/51",
"- # 1. ๅๆๅญใRใจไธ่ดใใฆใใใ",
"- # 2. ไฝๆๅญไธ่ดใใฆใใใใใๆกไปถๅๅฒ",
"- first = s[0] == \"R\"",
"- second = s[1] == \"R\"",
"- third = s[2] == \"R\"",
"- if first and second and third:",
"+ # https://atcoder.jp/contests/abc175/submissions/15... | false | 0.134898 | 0.037538 | 3.593661 | [
"s846513319",
"s787141780"
] |
u280552586 | p02912 | python | s785319027 | s864958606 | 165 | 141 | 14,204 | 20,404 | Accepted | Accepted | 14.55 | import heapq
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
A = list([x*(-1) for x in A])
heapq.heapify(A)
for _ in range(m):
max_price = -heapq.heappop(A) // 2
heapq.heappush(A, -max_price)
total = -sum(A)
print(total)
| import heapq
n, m = list(map(int, input().split()))
A = list([-int(x) for x in input().split()])
heapq.heapify(A)
for _ in range(m):
max_price = -heapq.heappop(A) // 2
heapq.heappush(A, -max_price)
total = -sum(A)
print(total)
| 15 | 10 | 304 | 244 | import heapq
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
A = list([x * (-1) for x in A])
heapq.heapify(A)
for _ in range(m):
max_price = -heapq.heappop(A) // 2
heapq.heappush(A, -max_price)
total = -sum(A)
print(total)
| import heapq
n, m = list(map(int, input().split()))
A = list([-int(x) for x in input().split()])
heapq.heapify(A)
for _ in range(m):
max_price = -heapq.heappop(A) // 2
heapq.heappush(A, -max_price)
total = -sum(A)
print(total)
| false | 33.333333 | [
"-import sys",
"-input = sys.stdin.readline",
"-A = list(map(int, input().split()))",
"-A = list([x * (-1) for x in A])",
"+A = list([-int(x) for x in input().split()])"
] | false | 0.041152 | 0.041019 | 1.003257 | [
"s785319027",
"s864958606"
] |
u702582248 | p02918 | python | s258130366 | s496989523 | 176 | 41 | 39,408 | 3,564 | Accepted | Accepted | 76.7 | from collections import Counter
mod = 1000000007
def inverse(a):
return pow(a, mod - 2, mod)
def usearch(x, a):
lft = 0
rgt = len(a) + 1
while rgt - lft > 1:
mid = (rgt + lft) // 2
if a[mid] <= x:
lft = mid
else:
rgt = mid
return lft
def main():
n, k = list(map(int, input().split()))
s = eval(input())
cnt = 0
for i in range(n-1):
if s[i] != s[i+1]:
cnt += 1
ans = n - 1 - cnt
while cnt >= 2 and k > 0:
ans += 2
cnt -= 2
k -= 1
if k > 0 and cnt > 0:
ans += 1
print(ans)
main()
| from collections import Counter
mod = 1000000007
def inverse(a):
return pow(a, mod - 2, mod)
def usearch(x, a):
lft = 0
rgt = len(a) + 1
while rgt - lft > 1:
mid = (rgt + lft) // 2
if a[mid] <= x:
lft = mid
else:
rgt = mid
return lft
def main():
n, k = list(map(int, input().split()))
s = eval(input())
cnt = 0
for i in range(n-1):
if s[i] != s[i+1]:
cnt += 1
ans = n - 1 - cnt
ans += k * 2
ans = min(ans, n-1)
print(ans)
main()
| 39 | 33 | 665 | 576 | from collections import Counter
mod = 1000000007
def inverse(a):
return pow(a, mod - 2, mod)
def usearch(x, a):
lft = 0
rgt = len(a) + 1
while rgt - lft > 1:
mid = (rgt + lft) // 2
if a[mid] <= x:
lft = mid
else:
rgt = mid
return lft
def main():
n, k = list(map(int, input().split()))
s = eval(input())
cnt = 0
for i in range(n - 1):
if s[i] != s[i + 1]:
cnt += 1
ans = n - 1 - cnt
while cnt >= 2 and k > 0:
ans += 2
cnt -= 2
k -= 1
if k > 0 and cnt > 0:
ans += 1
print(ans)
main()
| from collections import Counter
mod = 1000000007
def inverse(a):
return pow(a, mod - 2, mod)
def usearch(x, a):
lft = 0
rgt = len(a) + 1
while rgt - lft > 1:
mid = (rgt + lft) // 2
if a[mid] <= x:
lft = mid
else:
rgt = mid
return lft
def main():
n, k = list(map(int, input().split()))
s = eval(input())
cnt = 0
for i in range(n - 1):
if s[i] != s[i + 1]:
cnt += 1
ans = n - 1 - cnt
ans += k * 2
ans = min(ans, n - 1)
print(ans)
main()
| false | 15.384615 | [
"- while cnt >= 2 and k > 0:",
"- ans += 2",
"- cnt -= 2",
"- k -= 1",
"- if k > 0 and cnt > 0:",
"- ans += 1",
"+ ans += k * 2",
"+ ans = min(ans, n - 1)"
] | false | 0.007275 | 0.038035 | 0.191262 | [
"s258130366",
"s496989523"
] |
u130900604 | p02659 | python | s928000566 | s803917682 | 91 | 61 | 77,644 | 61,736 | Accepted | Accepted | 32.97 | def LI():return list(map(int,input().split()))
def yes():return print("Yes")
def no():return print("No")
from collections import deque, defaultdict, Counter
from heapq import heappop, heappush
import math
from decimal import Decimal
# pi=math.pi
# print(pi)
# yes()
# no()
# n=int(input())
# s=input()
a,b=map(Decimal,input().split())
a=100*a
b=100*b
# print(type(a),type(b))
print(a*b//10000)
| a,b=input().split()
b=b.replace(".","")
a=int(a)
b=int(b)
ans=a*b//100
print(ans) | 19 | 6 | 412 | 86 | def LI():
return list(map(int, input().split()))
def yes():
return print("Yes")
def no():
return print("No")
from collections import deque, defaultdict, Counter
from heapq import heappop, heappush
import math
from decimal import Decimal
# pi=math.pi
# print(pi)
# yes()
# no()
# n=int(input())
# s=input()
a, b = map(Decimal, input().split())
a = 100 * a
b = 100 * b
# print(type(a),type(b))
print(a * b // 10000)
| a, b = input().split()
b = b.replace(".", "")
a = int(a)
b = int(b)
ans = a * b // 100
print(ans)
| false | 68.421053 | [
"-def LI():",
"- return list(map(int, input().split()))",
"-",
"-",
"-def yes():",
"- return print(\"Yes\")",
"-",
"-",
"-def no():",
"- return print(\"No\")",
"-",
"-",
"-from collections import deque, defaultdict, Counter",
"-from heapq import heappop, heappush",
"-import math... | false | 0.04529 | 0.038669 | 1.171223 | [
"s928000566",
"s803917682"
] |
u901582103 | p03212 | python | s417868993 | s776025056 | 62 | 44 | 4,072 | 3,060 | Accepted | Accepted | 29.03 | import sys
sys.setrecursionlimit(100000)
n=int(eval(input()))
m=len(str(n))
L=[]
def dfs(i,num):
if i==m+1:
return
if 0<i<m+1:
if len(set(num))==3 and int(num)<=n:
L.append(int(num))
dfs(i+1,num+'3')
dfs(i+1,num+'5')
dfs(i+1,num+'7')
dfs(0,'')
print((len(L))) | n=int(eval(input()))
m=len(str(n))
r=0
def dfs(i,s):
global r
if len(set(s))==3 and int(s)<=n:
r+=1
if i==m:
return
dfs(i+1,'3'+s)
dfs(i+1,'5'+s)
dfs(i+1,'7'+s)
dfs(0,'')
print(r) | 16 | 16 | 314 | 230 | import sys
sys.setrecursionlimit(100000)
n = int(eval(input()))
m = len(str(n))
L = []
def dfs(i, num):
if i == m + 1:
return
if 0 < i < m + 1:
if len(set(num)) == 3 and int(num) <= n:
L.append(int(num))
dfs(i + 1, num + "3")
dfs(i + 1, num + "5")
dfs(i + 1, num + "7")
dfs(0, "")
print((len(L)))
| n = int(eval(input()))
m = len(str(n))
r = 0
def dfs(i, s):
global r
if len(set(s)) == 3 and int(s) <= n:
r += 1
if i == m:
return
dfs(i + 1, "3" + s)
dfs(i + 1, "5" + s)
dfs(i + 1, "7" + s)
dfs(0, "")
print(r)
| false | 0 | [
"-import sys",
"-",
"-sys.setrecursionlimit(100000)",
"-L = []",
"+r = 0",
"-def dfs(i, num):",
"- if i == m + 1:",
"+def dfs(i, s):",
"+ global r",
"+ if len(set(s)) == 3 and int(s) <= n:",
"+ r += 1",
"+ if i == m:",
"- if 0 < i < m + 1:",
"- if len(set(num))... | false | 0.06365 | 0.112628 | 0.565129 | [
"s417868993",
"s776025056"
] |
u021019433 | p03014 | python | s414801709 | s391287788 | 1,083 | 996 | 99,032 | 142,680 | Accepted | Accepted | 8.03 | from itertools import chain
h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
a = [[-1] * w for _ in range(h)]
for i in range(h):
p = 0
while p < w:
j = p
while j < w and s[i][j] == '.':
j += 1
for k in range(p, j):
a[i][k] += j - p
p = j + 1
for j in range(w):
p = 0
while p < h:
i = p
while i < h and s[i][j] == '.':
i += 1
for k in range(p, i):
a[k][j] += i - p
p = i + 1
print((max(chain.from_iterable(a))))
| h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
a = [[None] * w for _ in range(h)]
for i in range(h):
p = 0
while p < w:
j = p
while j < w and s[i][j] == '.':
j += 1
for k in range(p, j):
a[i][k] = j - p
p = j + 1
r = 0
for j in range(w):
p = 0
while p < h:
i = p
while i < h and s[i][j] == '.':
i += 1
for k in range(p, i):
r = max(r, a[k][j] + i - p - 1)
p = i + 1
print(r)
| 26 | 24 | 581 | 545 | from itertools import chain
h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
a = [[-1] * w for _ in range(h)]
for i in range(h):
p = 0
while p < w:
j = p
while j < w and s[i][j] == ".":
j += 1
for k in range(p, j):
a[i][k] += j - p
p = j + 1
for j in range(w):
p = 0
while p < h:
i = p
while i < h and s[i][j] == ".":
i += 1
for k in range(p, i):
a[k][j] += i - p
p = i + 1
print((max(chain.from_iterable(a))))
| h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
a = [[None] * w for _ in range(h)]
for i in range(h):
p = 0
while p < w:
j = p
while j < w and s[i][j] == ".":
j += 1
for k in range(p, j):
a[i][k] = j - p
p = j + 1
r = 0
for j in range(w):
p = 0
while p < h:
i = p
while i < h and s[i][j] == ".":
i += 1
for k in range(p, i):
r = max(r, a[k][j] + i - p - 1)
p = i + 1
print(r)
| false | 7.692308 | [
"-from itertools import chain",
"-",
"-a = [[-1] * w for _ in range(h)]",
"+a = [[None] * w for _ in range(h)]",
"- a[i][k] += j - p",
"+ a[i][k] = j - p",
"+r = 0",
"- a[k][j] += i - p",
"+ r = max(r, a[k][j] + i - p - 1)",
"-print((max(chain.from_itera... | false | 0.077918 | 0.078722 | 0.989792 | [
"s414801709",
"s391287788"
] |
u729938879 | p03108 | python | s343070947 | s593681687 | 965 | 830 | 38,520 | 21,692 | Accepted | Accepted | 13.99 | N, M =list(map(int, input().split()))
a, b = [], []
for i in range(M):
a_i, b_i = list(map(int, input().split()))
a.append(a_i -1)
b.append(b_i -1)
class UnionFind:
def __init__(self, n):
self.p = {}
self.r = {}
self.s = {}
for i in range(n):
self.p[i] = i # ่ฆช,ใฐใซใผใ็ชๅท
self.r[i] = 1
self.s[i] = 1 # ใตใคใบใ้ฃ็ตๆฐ
def find(self, n):
path = []
while n != self.p[n]:
path.append(n)
n = self.p[n]
for m in path:
self.p[m] = n
return n
def union(self, a, b):
ap = self.find(a)
bp = self.find(b)
if self.r[ap] > self.r[bp]:
self.p[bp] = ap
size = self.s[bp] + self.s[ap]
self.s[ap] = size
elif self.r[bp] > self.r[ap]:
self.p[ap] = bp
size = self.s[bp] + self.s[ap]
self.s[bp] = size
elif ap != bp:
self.p[ap] = bp
self.r[bp] += 1
size = self.s[bp] + self.s[ap]
self.s[bp] = size
def size(self, n):
np = self.find(n)
return self.s[np]
s = UnionFind(N)
ans = (N*(N-1)) // 2
anss = [ans]
for i in range(M):
j = M - i - 1
if s.find(a[j]) != s.find(b[j]):
ans -= s.size(a[j]) * s.size(b[j])
s.union(a[j], b[j])
if i != M-1:
anss.append(ans)
sort_ans = sorted(anss)
for i in range(len(sort_ans)):
print((sort_ans[i])) | class UnionFind:
def __init__(self, n):
self.p = [i for i in range(n)]
self.s = [1 for i in range(n)]
def find(self, x):
if x == self.p[x]:
return x
else:
self.p[x] = self.find(self.p[x])
return self.p[x]
def union(self, a, b):
ap = self.find(a)
bp = self.find(b)
if ap != bp:
mini = min(ap ,bp)
maxi = max(ap, bp)
self.p[maxi] = mini
size = self.s[bp] + self.s[ap]
self.s[bp] = size
self.s[ap] = size
return True
else:
return False
def size(self, n):
np = self.find(n)
return self.s[np]
N, M =list(map(int, input().split()))
a, b = [], []
for i in range(M):
a_i, b_i = list(map(int, input().split()))
a.append(a_i -1)
b.append(b_i - 1)
s = UnionFind(N)
ans = (N*(N-1)) // 2
anss = [ans]
for i in range(M):
j = M - i - 1
if s.find(a[j]) != s.find(b[j]):
ans -= s.size(a[j]) * s.size(b[j])
s.union(a[j], b[j])
if i != M-1:
anss.append(ans)
sort_ans = sorted(anss)
for i in range(len(sort_ans)):
print((sort_ans[i])) | 63 | 53 | 1,578 | 1,285 | N, M = list(map(int, input().split()))
a, b = [], []
for i in range(M):
a_i, b_i = list(map(int, input().split()))
a.append(a_i - 1)
b.append(b_i - 1)
class UnionFind:
def __init__(self, n):
self.p = {}
self.r = {}
self.s = {}
for i in range(n):
self.p[i] = i # ่ฆช,ใฐใซใผใ็ชๅท
self.r[i] = 1
self.s[i] = 1 # ใตใคใบใ้ฃ็ตๆฐ
def find(self, n):
path = []
while n != self.p[n]:
path.append(n)
n = self.p[n]
for m in path:
self.p[m] = n
return n
def union(self, a, b):
ap = self.find(a)
bp = self.find(b)
if self.r[ap] > self.r[bp]:
self.p[bp] = ap
size = self.s[bp] + self.s[ap]
self.s[ap] = size
elif self.r[bp] > self.r[ap]:
self.p[ap] = bp
size = self.s[bp] + self.s[ap]
self.s[bp] = size
elif ap != bp:
self.p[ap] = bp
self.r[bp] += 1
size = self.s[bp] + self.s[ap]
self.s[bp] = size
def size(self, n):
np = self.find(n)
return self.s[np]
s = UnionFind(N)
ans = (N * (N - 1)) // 2
anss = [ans]
for i in range(M):
j = M - i - 1
if s.find(a[j]) != s.find(b[j]):
ans -= s.size(a[j]) * s.size(b[j])
s.union(a[j], b[j])
if i != M - 1:
anss.append(ans)
sort_ans = sorted(anss)
for i in range(len(sort_ans)):
print((sort_ans[i]))
| class UnionFind:
def __init__(self, n):
self.p = [i for i in range(n)]
self.s = [1 for i in range(n)]
def find(self, x):
if x == self.p[x]:
return x
else:
self.p[x] = self.find(self.p[x])
return self.p[x]
def union(self, a, b):
ap = self.find(a)
bp = self.find(b)
if ap != bp:
mini = min(ap, bp)
maxi = max(ap, bp)
self.p[maxi] = mini
size = self.s[bp] + self.s[ap]
self.s[bp] = size
self.s[ap] = size
return True
else:
return False
def size(self, n):
np = self.find(n)
return self.s[np]
N, M = list(map(int, input().split()))
a, b = [], []
for i in range(M):
a_i, b_i = list(map(int, input().split()))
a.append(a_i - 1)
b.append(b_i - 1)
s = UnionFind(N)
ans = (N * (N - 1)) // 2
anss = [ans]
for i in range(M):
j = M - i - 1
if s.find(a[j]) != s.find(b[j]):
ans -= s.size(a[j]) * s.size(b[j])
s.union(a[j], b[j])
if i != M - 1:
anss.append(ans)
sort_ans = sorted(anss)
for i in range(len(sort_ans)):
print((sort_ans[i]))
| false | 15.873016 | [
"+class UnionFind:",
"+ def __init__(self, n):",
"+ self.p = [i for i in range(n)]",
"+ self.s = [1 for i in range(n)]",
"+",
"+ def find(self, x):",
"+ if x == self.p[x]:",
"+ return x",
"+ else:",
"+ self.p[x] = self.find(self.p[x])",
"+ ... | false | 0.047818 | 0.04731 | 1.010722 | [
"s343070947",
"s593681687"
] |
u775681539 | p02813 | python | s639748773 | s361196980 | 35 | 27 | 3,060 | 3,064 | Accepted | Accepted | 22.86 | #python3
from itertools import permutations
n=int(eval(input()))
p=[int(i) for i in input().split()]
q=[int(i) for i in input().split()]
def f(lis):
cnt=0
for i in permutations(list(range(1,n+1))):
cnt+=1
if i == tuple(lis):
return cnt
print((abs(f(p)-f(q))))
| def main():
n = int(eval(input()))
p = tuple(int(i) for i in input().split())
q = tuple(int(i) for i in input().split())
from itertools import permutations
a = [i for i in range(1, n+1)]
o1 = -1
o2 = -1
cnt = 0
for i in permutations(a):
cnt += 1
if i == p:
o1 = cnt
if i == q:
o2 = cnt
ans = abs(o1-o2)
print(ans)
main() | 14 | 18 | 279 | 416 | # python3
from itertools import permutations
n = int(eval(input()))
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
def f(lis):
cnt = 0
for i in permutations(list(range(1, n + 1))):
cnt += 1
if i == tuple(lis):
return cnt
print((abs(f(p) - f(q))))
| def main():
n = int(eval(input()))
p = tuple(int(i) for i in input().split())
q = tuple(int(i) for i in input().split())
from itertools import permutations
a = [i for i in range(1, n + 1)]
o1 = -1
o2 = -1
cnt = 0
for i in permutations(a):
cnt += 1
if i == p:
o1 = cnt
if i == q:
o2 = cnt
ans = abs(o1 - o2)
print(ans)
main()
| false | 22.222222 | [
"-# python3",
"-from itertools import permutations",
"+def main():",
"+ n = int(eval(input()))",
"+ p = tuple(int(i) for i in input().split())",
"+ q = tuple(int(i) for i in input().split())",
"+ from itertools import permutations",
"-n = int(eval(input()))",
"-p = [int(i) for i in input... | false | 0.128284 | 0.049409 | 2.596357 | [
"s639748773",
"s361196980"
] |
u001024152 | p03112 | python | s949757477 | s077235790 | 1,823 | 942 | 14,204 | 12,816 | Accepted | Accepted | 48.33 | # D
from bisect import bisect_right
A,B,Q = list(map(int, input().split()))
INF = float('inf')
s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
for q in range(Q):
x = int(eval(input()))
b,d = bisect_right(s, x), bisect_right(t, x)
ans = INF
for s_visit in [s[b-1], s[b]]:
for t_visit in [t[d-1], t[d]]:
dist1 = abs(s_visit - x) + abs(t_visit - s_visit)
dist2 = abs(t_visit - x) + abs(s_visit - t_visit)
ans = min(ans, dist1, dist2)
print(ans) | # D
from bisect import bisect_right
import sys
input = sys.stdin.readline
A,B,Q = list(map(int, input().split()))
INF = float('inf')
s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
for q in range(Q):
x = int(eval(input()))
b,d = bisect_right(s, x), bisect_right(t, x)
ans = INF
for s_visit in [s[b-1], s[b]]:
for t_visit in [t[d-1], t[d]]:
dist1 = abs(s_visit - x) + abs(t_visit - s_visit)
dist2 = abs(t_visit - x) + abs(s_visit - t_visit)
ans = min(ans, dist1, dist2)
print(ans) | 16 | 18 | 568 | 608 | # D
from bisect import bisect_right
A, B, Q = list(map(int, input().split()))
INF = float("inf")
s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
for q in range(Q):
x = int(eval(input()))
b, d = bisect_right(s, x), bisect_right(t, x)
ans = INF
for s_visit in [s[b - 1], s[b]]:
for t_visit in [t[d - 1], t[d]]:
dist1 = abs(s_visit - x) + abs(t_visit - s_visit)
dist2 = abs(t_visit - x) + abs(s_visit - t_visit)
ans = min(ans, dist1, dist2)
print(ans)
| # D
from bisect import bisect_right
import sys
input = sys.stdin.readline
A, B, Q = list(map(int, input().split()))
INF = float("inf")
s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
for q in range(Q):
x = int(eval(input()))
b, d = bisect_right(s, x), bisect_right(t, x)
ans = INF
for s_visit in [s[b - 1], s[b]]:
for t_visit in [t[d - 1], t[d]]:
dist1 = abs(s_visit - x) + abs(t_visit - s_visit)
dist2 = abs(t_visit - x) + abs(s_visit - t_visit)
ans = min(ans, dist1, dist2)
print(ans)
| false | 11.111111 | [
"+import sys",
"+input = sys.stdin.readline"
] | false | 0.03829 | 0.033594 | 1.139797 | [
"s949757477",
"s077235790"
] |
u754022296 | p03725 | python | s330616025 | s609518098 | 1,907 | 1,754 | 83,076 | 83,140 | Accepted | Accepted | 8.02 | import sys
input = sys.stdin.readline
from collections import deque
h, w, k = list(map(int, input().split()))
A = [input().rstrip() for _ in range(h)]
for i, a in enumerate(A):
if "S" in a:
sy = i
sx = a.index("S")
break
que = deque()
D = ((-1, 0), (0, -1), (1, 0), (0, 1))
def bfs(y, x):
seen = [0]*h
seen[y] |= 1 << x
F = deque()
F.append((y, x, 0))
while F:
ny, nx, cnt = F.popleft()
que.append((ny, nx, k))
if cnt == k:
continue
for dy, dx in D:
yy, xx = ny+dy, nx+dx
if 0 <= yy < h and 0 <= xx < w:
if A[yy][xx] == "#":
continue
if seen[yy] >> xx & 1:
continue
seen[yy] |= 1 << xx
F.append((yy, xx, cnt+1))
bfs(sy, sx)
seen = [0]*h
while que:
y, x, cnt = que.popleft()
if y == 0 or y == h-1 or x == 0 or x == w-1:
ans = -(-cnt // k)
break
for dy, dx in D:
ny, nx = y+dy, x+dx
if 0 <= ny < h and 0 <= nx < w:
if seen[ny] >> nx & 1:
continue
seen[ny] |= 1 << nx
que.append((ny, nx, cnt+1))
print(ans) | import sys
input = sys.stdin.readline
from collections import deque
def main():
h, w, k = list(map(int, input().split()))
A = [input().rstrip() for _ in range(h)]
for i, a in enumerate(A):
if "S" in a:
sy = i
sx = a.index("S")
break
que = deque()
D = ((-1, 0), (0, -1), (1, 0), (0, 1))
def bfs(y, x):
seen = [0]*h
seen[y] |= 1 << x
F = deque()
F.append((y, x, 0))
while F:
ny, nx, cnt = F.popleft()
que.append((ny, nx, k))
if cnt == k:
continue
for dy, dx in D:
yy, xx = ny+dy, nx+dx
if 0 <= yy < h and 0 <= xx < w:
if A[yy][xx] == "#":
continue
if seen[yy] >> xx & 1:
continue
seen[yy] |= 1 << xx
F.append((yy, xx, cnt+1))
bfs(sy, sx)
seen = [0]*h
while que:
y, x, cnt = que.popleft()
if y == 0 or y == h-1 or x == 0 or x == w-1:
ans = -(-cnt // k)
break
for dy, dx in D:
ny, nx = y+dy, x+dx
if 0 <= ny < h and 0 <= nx < w:
if seen[ny] >> nx & 1:
continue
seen[ny] |= 1 << nx
que.append((ny, nx, cnt+1))
print(ans)
if __name__ == "__main__":
main() | 52 | 56 | 1,120 | 1,251 | import sys
input = sys.stdin.readline
from collections import deque
h, w, k = list(map(int, input().split()))
A = [input().rstrip() for _ in range(h)]
for i, a in enumerate(A):
if "S" in a:
sy = i
sx = a.index("S")
break
que = deque()
D = ((-1, 0), (0, -1), (1, 0), (0, 1))
def bfs(y, x):
seen = [0] * h
seen[y] |= 1 << x
F = deque()
F.append((y, x, 0))
while F:
ny, nx, cnt = F.popleft()
que.append((ny, nx, k))
if cnt == k:
continue
for dy, dx in D:
yy, xx = ny + dy, nx + dx
if 0 <= yy < h and 0 <= xx < w:
if A[yy][xx] == "#":
continue
if seen[yy] >> xx & 1:
continue
seen[yy] |= 1 << xx
F.append((yy, xx, cnt + 1))
bfs(sy, sx)
seen = [0] * h
while que:
y, x, cnt = que.popleft()
if y == 0 or y == h - 1 or x == 0 or x == w - 1:
ans = -(-cnt // k)
break
for dy, dx in D:
ny, nx = y + dy, x + dx
if 0 <= ny < h and 0 <= nx < w:
if seen[ny] >> nx & 1:
continue
seen[ny] |= 1 << nx
que.append((ny, nx, cnt + 1))
print(ans)
| import sys
input = sys.stdin.readline
from collections import deque
def main():
h, w, k = list(map(int, input().split()))
A = [input().rstrip() for _ in range(h)]
for i, a in enumerate(A):
if "S" in a:
sy = i
sx = a.index("S")
break
que = deque()
D = ((-1, 0), (0, -1), (1, 0), (0, 1))
def bfs(y, x):
seen = [0] * h
seen[y] |= 1 << x
F = deque()
F.append((y, x, 0))
while F:
ny, nx, cnt = F.popleft()
que.append((ny, nx, k))
if cnt == k:
continue
for dy, dx in D:
yy, xx = ny + dy, nx + dx
if 0 <= yy < h and 0 <= xx < w:
if A[yy][xx] == "#":
continue
if seen[yy] >> xx & 1:
continue
seen[yy] |= 1 << xx
F.append((yy, xx, cnt + 1))
bfs(sy, sx)
seen = [0] * h
while que:
y, x, cnt = que.popleft()
if y == 0 or y == h - 1 or x == 0 or x == w - 1:
ans = -(-cnt // k)
break
for dy, dx in D:
ny, nx = y + dy, x + dx
if 0 <= ny < h and 0 <= nx < w:
if seen[ny] >> nx & 1:
continue
seen[ny] |= 1 << nx
que.append((ny, nx, cnt + 1))
print(ans)
if __name__ == "__main__":
main()
| false | 7.142857 | [
"-h, w, k = list(map(int, input().split()))",
"-A = [input().rstrip() for _ in range(h)]",
"-for i, a in enumerate(A):",
"- if \"S\" in a:",
"- sy = i",
"- sx = a.index(\"S\")",
"- break",
"-que = deque()",
"-D = ((-1, 0), (0, -1), (1, 0), (0, 1))",
"+",
"+def main():",
... | false | 0.107155 | 0.039037 | 2.744994 | [
"s330616025",
"s609518098"
] |
u353919145 | p02923 | python | s806519124 | s470825342 | 102 | 87 | 11,136 | 14,252 | Accepted | Accepted | 14.71 | n = int(eval(input()))
x = input().split()
y = [0]
c = 0
for i in range(n-1):
if int(x[i]) >= int(x[i+1]):
c = c + 1
else:
y.append(c)
c = 0
y.append(c)
print((max(y))) | n = int(eval(input()))
alturas = list(map(int, input().split()))
if n == 1:
print((0))
else:
atual = 0
max_value = 0
contador = 0
while atual + 1 < n:
if alturas[atual] >= alturas[atual+1]:
contador += 1
else:
max_value = max(contador, max_value)
contador = 0
atual += 1
max_value = max(contador, max_value)
print(max_value)
| 12 | 18 | 187 | 357 | n = int(eval(input()))
x = input().split()
y = [0]
c = 0
for i in range(n - 1):
if int(x[i]) >= int(x[i + 1]):
c = c + 1
else:
y.append(c)
c = 0
y.append(c)
print((max(y)))
| n = int(eval(input()))
alturas = list(map(int, input().split()))
if n == 1:
print((0))
else:
atual = 0
max_value = 0
contador = 0
while atual + 1 < n:
if alturas[atual] >= alturas[atual + 1]:
contador += 1
else:
max_value = max(contador, max_value)
contador = 0
atual += 1
max_value = max(contador, max_value)
print(max_value)
| false | 33.333333 | [
"-x = input().split()",
"-y = [0]",
"-c = 0",
"-for i in range(n - 1):",
"- if int(x[i]) >= int(x[i + 1]):",
"- c = c + 1",
"- else:",
"- y.append(c)",
"- c = 0",
"-y.append(c)",
"-print((max(y)))",
"+alturas = list(map(int, input().split()))",
"+if n == 1:",
"+ ... | false | 0.046855 | 0.039884 | 1.174765 | [
"s806519124",
"s470825342"
] |
u537905693 | p02953 | python | s704123096 | s461881274 | 70 | 50 | 14,484 | 14,832 | Accepted | Accepted | 28.57 | #!/usr/bin/env python
# coding: utf-8
def ri():
return int(eval(input()))
def rl():
return list(input().split())
def rli():
return list(map(int, input().split()))
def main():
n = ri()
lh = rli()
for i in range(len(lh)-1):
if lh[i+1] > lh[i]:
lh[i+1] -= 1
if lh[i+1] < lh[i]:
print("No")
return
print("Yes")
if __name__ == '__main__':
main()
| #!/usr/bin/env python
# coding: utf-8
def ri():
return int(eval(input()))
def rl():
return list(input().split())
def rli():
return list(map(int, input().split()))
def main():
n = ri()
lh = rli()
c = 0
for h in lh:
# print(c, h)
if h < c:
print("No")
return
elif h == c:
c = h
else:
c = h-1
print("Yes")
if __name__ == '__main__':
main()
| 26 | 30 | 450 | 482 | #!/usr/bin/env python
# coding: utf-8
def ri():
return int(eval(input()))
def rl():
return list(input().split())
def rli():
return list(map(int, input().split()))
def main():
n = ri()
lh = rli()
for i in range(len(lh) - 1):
if lh[i + 1] > lh[i]:
lh[i + 1] -= 1
if lh[i + 1] < lh[i]:
print("No")
return
print("Yes")
if __name__ == "__main__":
main()
| #!/usr/bin/env python
# coding: utf-8
def ri():
return int(eval(input()))
def rl():
return list(input().split())
def rli():
return list(map(int, input().split()))
def main():
n = ri()
lh = rli()
c = 0
for h in lh:
# print(c, h)
if h < c:
print("No")
return
elif h == c:
c = h
else:
c = h - 1
print("Yes")
if __name__ == "__main__":
main()
| false | 13.333333 | [
"- for i in range(len(lh) - 1):",
"- if lh[i + 1] > lh[i]:",
"- lh[i + 1] -= 1",
"- if lh[i + 1] < lh[i]:",
"+ c = 0",
"+ for h in lh:",
"+ # print(c, h)",
"+ if h < c:",
"+ elif h == c:",
"+ c = h",
"+ else:",
"+ ... | false | 0.04643 | 0.04689 | 0.990195 | [
"s704123096",
"s461881274"
] |
u936985471 | p02936 | python | s771189842 | s931249489 | 1,998 | 1,825 | 81,204 | 64,300 | Accepted | Accepted | 8.66 | N,Q=list(map(int,input().split()))
tree={}
for i in range(N-1):
a,b=list(map(int,input().split()))
if (a-1) in tree:
tree[a-1].append(b-1)
else:
tree[a-1]=[b-1]
if (b-1) in tree:
tree[b-1].append(a-1)
else:
tree[b-1]=[a-1]
point=[0]*N
for i in range(Q):
p,x=list(map(int,input().split()))
point[p-1]+=x
ans=[0]*N
stack=[]
stack.append([0,0,-1])
while len(stack)>0:
nodes=stack.pop()
node=nodes[0]
sump=nodes[1]
parent=nodes[2]
sump=sump+point[node]
ans[node]=sump
if node in tree:
childs=tree[node]
for child in childs:
if child!=parent:
stack.append([child,sump,node])
print((*ans)) | N,Q=list(map(int,input().split()))
E=[[] for i in range(N)]
for i in range(N-1):
a,b=list(map(int,input().split()))
a,b=a-1,b-1
E[a].append(b)
E[b].append(a)
P=[0]*N
for i in range(Q):
p,x=list(map(int,input().split()))
P[p-1]+=x
ans=[0]*N
stack=[]
# ็น,่ฆช,ใใคใณใ
stack.append([0,-1,0])
while stack:
node=stack.pop()
v=node[0]
parent=node[1]
point=node[2]
point+=P[v]
ans[v]=point
children=E[v]
for child in children:
if child==parent:
continue
stack.append([child,v,point])
print((*ans)) | 36 | 31 | 676 | 547 | N, Q = list(map(int, input().split()))
tree = {}
for i in range(N - 1):
a, b = list(map(int, input().split()))
if (a - 1) in tree:
tree[a - 1].append(b - 1)
else:
tree[a - 1] = [b - 1]
if (b - 1) in tree:
tree[b - 1].append(a - 1)
else:
tree[b - 1] = [a - 1]
point = [0] * N
for i in range(Q):
p, x = list(map(int, input().split()))
point[p - 1] += x
ans = [0] * N
stack = []
stack.append([0, 0, -1])
while len(stack) > 0:
nodes = stack.pop()
node = nodes[0]
sump = nodes[1]
parent = nodes[2]
sump = sump + point[node]
ans[node] = sump
if node in tree:
childs = tree[node]
for child in childs:
if child != parent:
stack.append([child, sump, node])
print((*ans))
| N, Q = list(map(int, input().split()))
E = [[] for i in range(N)]
for i in range(N - 1):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
E[a].append(b)
E[b].append(a)
P = [0] * N
for i in range(Q):
p, x = list(map(int, input().split()))
P[p - 1] += x
ans = [0] * N
stack = []
# ็น,่ฆช,ใใคใณใ
stack.append([0, -1, 0])
while stack:
node = stack.pop()
v = node[0]
parent = node[1]
point = node[2]
point += P[v]
ans[v] = point
children = E[v]
for child in children:
if child == parent:
continue
stack.append([child, v, point])
print((*ans))
| false | 13.888889 | [
"-tree = {}",
"+E = [[] for i in range(N)]",
"- if (a - 1) in tree:",
"- tree[a - 1].append(b - 1)",
"- else:",
"- tree[a - 1] = [b - 1]",
"- if (b - 1) in tree:",
"- tree[b - 1].append(a - 1)",
"- else:",
"- tree[b - 1] = [a - 1]",
"-point = [0] * N",
"... | false | 0.033736 | 0.035463 | 0.951302 | [
"s771189842",
"s931249489"
] |
u072053884 | p02343 | python | s461360106 | s922021357 | 11,810 | 420 | 8,780 | 8,624 | Accepted | Accepted | 96.44 | import sys
f_i = sys.stdin
n, q = list(map(int, f_i.readline().split()))
class DisjointSets:
def __init__(self, size):
self.size = size
self.representatives = list(range(size))
def _find(self, x):
return self.representatives[x]
def union(self, x, y):
x1 = self._find(x)
y1 = self._find(y)
if x1 == y1:
return None
# unite Sx and Sy
for i in range(self.size):
if self.representatives[i] == y1:
self.representatives[i] = x1
def isSameSet(self, x, y):
if self._find(x) == self._find(y):
print((1))
else:
print((0))
S = DisjointSets(n)
for l in f_i:
com, x, y = list(map(int, l.split()))
if com == 0:
S.union(x, y)
else:
S.isSameSet(x, y) | import sys
f_i = sys.stdin
n, q = list(map(int, f_i.readline().split()))
class DisjointSets:
def __init__(self, size):
# negative values are roots(representatives of each tree)
# positive values represent the parent element
self.table = [-1 for _ in range(size)]
def _find(self, x):
if self.table[x] < 0:
return x
else:
# compression of the path
self.table[x] = self._find(self.table[x])
return self.table[x]
def uniteSets(self, x, y):
s1 = self._find(x)
s2 = self._find(y)
if s1 != s2:
if self.table[s1] < self.table[s2]: # the smaller has more elements
self.table[s1] += self.table[s2]
self.table[s2] = s1
else:
self.table[s2] += self.table[s1]
self.table[s1] = s2
def isSameSet(self, x, y):
if self._find(x) == self._find(y):
print((1))
else:
print((0))
S = DisjointSets(n)
for l in f_i:
com, x, y = list(map(int, l.split()))
if com == 0:
S.uniteSets(x, y)
else:
S.isSameSet(x, y) | 38 | 45 | 853 | 1,203 | import sys
f_i = sys.stdin
n, q = list(map(int, f_i.readline().split()))
class DisjointSets:
def __init__(self, size):
self.size = size
self.representatives = list(range(size))
def _find(self, x):
return self.representatives[x]
def union(self, x, y):
x1 = self._find(x)
y1 = self._find(y)
if x1 == y1:
return None
# unite Sx and Sy
for i in range(self.size):
if self.representatives[i] == y1:
self.representatives[i] = x1
def isSameSet(self, x, y):
if self._find(x) == self._find(y):
print((1))
else:
print((0))
S = DisjointSets(n)
for l in f_i:
com, x, y = list(map(int, l.split()))
if com == 0:
S.union(x, y)
else:
S.isSameSet(x, y)
| import sys
f_i = sys.stdin
n, q = list(map(int, f_i.readline().split()))
class DisjointSets:
def __init__(self, size):
# negative values are roots(representatives of each tree)
# positive values represent the parent element
self.table = [-1 for _ in range(size)]
def _find(self, x):
if self.table[x] < 0:
return x
else:
# compression of the path
self.table[x] = self._find(self.table[x])
return self.table[x]
def uniteSets(self, x, y):
s1 = self._find(x)
s2 = self._find(y)
if s1 != s2:
if self.table[s1] < self.table[s2]: # the smaller has more elements
self.table[s1] += self.table[s2]
self.table[s2] = s1
else:
self.table[s2] += self.table[s1]
self.table[s1] = s2
def isSameSet(self, x, y):
if self._find(x) == self._find(y):
print((1))
else:
print((0))
S = DisjointSets(n)
for l in f_i:
com, x, y = list(map(int, l.split()))
if com == 0:
S.uniteSets(x, y)
else:
S.isSameSet(x, y)
| false | 15.555556 | [
"- self.size = size",
"- self.representatives = list(range(size))",
"+ # negative values are roots(representatives of each tree)",
"+ # positive values represent the parent element",
"+ self.table = [-1 for _ in range(size)]",
"- return self.representatives[x]",
... | false | 0.055481 | 0.03603 | 1.539833 | [
"s461360106",
"s922021357"
] |
u550943777 | p03044 | python | s699084417 | s896765469 | 944 | 814 | 55,432 | 80,288 | Accepted | Accepted | 13.77 | import heapq as hp
N = int(eval(input()))
ans = [-1]*N
arr = []
for i in range(N-1):
u,v,w = list(map(int,input().split()))
u -= 1
v -= 1
arr.append([u,v,w])
e_list = [[] for i in range(N)]
for u,v,w in arr:
e_list[u].append([v,w])
e_list[v].append([u,w])
stack = [0]
ans[0] = 0
while(stack):
cur_pos = stack.pop()
for des,cost in e_list[cur_pos]:
if ans[des] >= 0:
continue
ans[des] = (ans[cur_pos] + cost)%2
stack.append(des)
for i in ans:
print(i) | N = int(input())
e_list = [[] for i in range(N)]
for i in range(N-1):
u,v,w = map(int,input().split())
w %= 2
e_list[u-1].append([v-1,w])
e_list[v-1].append([u-1,w])
stack = [0]
ans = [-1]*N
ans[0] = 0
while stack:
x = stack.pop()
for v,w in e_list[x]:
if ans[v] != -1:
continue
else:
ans[v] = ans[x]^w
stack.append(v)
print(*ans,sep='\n')
| 25 | 20 | 536 | 435 | import heapq as hp
N = int(eval(input()))
ans = [-1] * N
arr = []
for i in range(N - 1):
u, v, w = list(map(int, input().split()))
u -= 1
v -= 1
arr.append([u, v, w])
e_list = [[] for i in range(N)]
for u, v, w in arr:
e_list[u].append([v, w])
e_list[v].append([u, w])
stack = [0]
ans[0] = 0
while stack:
cur_pos = stack.pop()
for des, cost in e_list[cur_pos]:
if ans[des] >= 0:
continue
ans[des] = (ans[cur_pos] + cost) % 2
stack.append(des)
for i in ans:
print(i)
| N = int(input())
e_list = [[] for i in range(N)]
for i in range(N - 1):
u, v, w = map(int, input().split())
w %= 2
e_list[u - 1].append([v - 1, w])
e_list[v - 1].append([u - 1, w])
stack = [0]
ans = [-1] * N
ans[0] = 0
while stack:
x = stack.pop()
for v, w in e_list[x]:
if ans[v] != -1:
continue
else:
ans[v] = ans[x] ^ w
stack.append(v)
print(*ans, sep="\n")
| false | 20 | [
"-import heapq as hp",
"-",
"-N = int(eval(input()))",
"+N = int(input())",
"+e_list = [[] for i in range(N)]",
"+for i in range(N - 1):",
"+ u, v, w = map(int, input().split())",
"+ w %= 2",
"+ e_list[u - 1].append([v - 1, w])",
"+ e_list[v - 1].append([u - 1, w])",
"+stack = [0]",
... | false | 0.040634 | 0.095404 | 0.425915 | [
"s699084417",
"s896765469"
] |
u827141374 | p03073 | python | s484586530 | s597057741 | 50 | 36 | 3,188 | 3,188 | Accepted | Accepted | 28 | S = eval(input())
p01 = 0
p10 = 0
p00 = 0
p11 = 0
for i in range(0, (len(S)//2 * 2), 2):
if S[i:i+2] == '01':
p01 += 1
elif S[i:i+2] == '10':
p10 += 1
elif S[i:i+2] == '00':
p00 += 1
else:
p11 += 1
#print(p01,p10,p00,p11)
c = 0
if (p01 == 0) and (p10 == 0):
c = len(S) // 2
elif p01 >= p10:
c = p10 * 2 + p00 + p11
if len(S) & 1:
if S[-1] == S[-2]:
c += 1
else:
c = p01 * 2 + p00 + p11
if len(S) & 1:
if S[-1] == S[-2]:
c += 1
print(c) | S = eval(input())
c = 0
zo = 0 # zero-one
oz = 0 # one-zero
for i in range(0, len(S)//2 * 2, 2):
if S[i] == '0':
oz += 1
else:
zo += 1
if S[i+1] == '0':
zo += 1
else:
oz += 1
if len(S) & 1:
if S[-1] == '0':
oz += 1
else:
zo += 1
print((min(oz, zo))) | 29 | 19 | 565 | 331 | S = eval(input())
p01 = 0
p10 = 0
p00 = 0
p11 = 0
for i in range(0, (len(S) // 2 * 2), 2):
if S[i : i + 2] == "01":
p01 += 1
elif S[i : i + 2] == "10":
p10 += 1
elif S[i : i + 2] == "00":
p00 += 1
else:
p11 += 1
# print(p01,p10,p00,p11)
c = 0
if (p01 == 0) and (p10 == 0):
c = len(S) // 2
elif p01 >= p10:
c = p10 * 2 + p00 + p11
if len(S) & 1:
if S[-1] == S[-2]:
c += 1
else:
c = p01 * 2 + p00 + p11
if len(S) & 1:
if S[-1] == S[-2]:
c += 1
print(c)
| S = eval(input())
c = 0
zo = 0 # zero-one
oz = 0 # one-zero
for i in range(0, len(S) // 2 * 2, 2):
if S[i] == "0":
oz += 1
else:
zo += 1
if S[i + 1] == "0":
zo += 1
else:
oz += 1
if len(S) & 1:
if S[-1] == "0":
oz += 1
else:
zo += 1
print((min(oz, zo)))
| false | 34.482759 | [
"-p01 = 0",
"-p10 = 0",
"-p00 = 0",
"-p11 = 0",
"-for i in range(0, (len(S) // 2 * 2), 2):",
"- if S[i : i + 2] == \"01\":",
"- p01 += 1",
"- elif S[i : i + 2] == \"10\":",
"- p10 += 1",
"- elif S[i : i + 2] == \"00\":",
"- p00 += 1",
"+c = 0",
"+zo = 0 # zero-... | false | 0.035908 | 0.067817 | 0.529489 | [
"s484586530",
"s597057741"
] |
u086503932 | p02726 | python | s613946583 | s345055070 | 1,312 | 305 | 3,444 | 101,420 | Accepted | Accepted | 76.75 | N, X, Y = list(map(int, input().split()))
ans = [0] * N
for i in range(N):
for j in range(i+1, N):
tmp = min(j-i, abs(X-1-i) + 1 + abs(Y-1-j))
ans[tmp] += 1
for k in range(1,N):
print((ans[k])) | from collections import deque
N, X, Y = map(int, input().split())
adj = [[] for _ in range(N)]
for i in range(N-1):
adj[i].append(i+1)
adj[i+1].append(i)
adj[X-1].append(Y-1)
adj[Y-1].append(X-1)
dist = [[-1]*N for _ in range(N)]
for i in range(N):
queue = deque([i])
dist[i][i] = 0
while queue:
now = queue.popleft()
for u in adj[now]:
if dist[i][u] < 0:
queue.append(u)
dist[i][u] = dist[i][now] + 1
ans = [0] * (N-1)
for i in range(N):
for j in range(i+1,N):
ans[dist[i][j]-1] += 1
[print(a) for a in ans]
| 10 | 30 | 208 | 636 | N, X, Y = list(map(int, input().split()))
ans = [0] * N
for i in range(N):
for j in range(i + 1, N):
tmp = min(j - i, abs(X - 1 - i) + 1 + abs(Y - 1 - j))
ans[tmp] += 1
for k in range(1, N):
print((ans[k]))
| from collections import deque
N, X, Y = map(int, input().split())
adj = [[] for _ in range(N)]
for i in range(N - 1):
adj[i].append(i + 1)
adj[i + 1].append(i)
adj[X - 1].append(Y - 1)
adj[Y - 1].append(X - 1)
dist = [[-1] * N for _ in range(N)]
for i in range(N):
queue = deque([i])
dist[i][i] = 0
while queue:
now = queue.popleft()
for u in adj[now]:
if dist[i][u] < 0:
queue.append(u)
dist[i][u] = dist[i][now] + 1
ans = [0] * (N - 1)
for i in range(N):
for j in range(i + 1, N):
ans[dist[i][j] - 1] += 1
[print(a) for a in ans]
| false | 66.666667 | [
"-N, X, Y = list(map(int, input().split()))",
"-ans = [0] * N",
"+from collections import deque",
"+",
"+N, X, Y = map(int, input().split())",
"+adj = [[] for _ in range(N)]",
"+for i in range(N - 1):",
"+ adj[i].append(i + 1)",
"+ adj[i + 1].append(i)",
"+adj[X - 1].append(Y - 1)",
"+adj[... | false | 0.046465 | 0.044764 | 1.038004 | [
"s613946583",
"s345055070"
] |
u564589929 | p02732 | python | s962206754 | s229318789 | 1,312 | 409 | 32,156 | 26,140 | Accepted | Accepted | 68.83 | from collections import Counter
import math
def solver():
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = Counter(A)
# print(cnt)
def comb(n, r):
if n - r < 0: return 0
if n - r < r: r = n - r
if r == 0: return 1
if r == 1: return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
cnt_comb = {}
sm = 0
for key, val in list(cnt.items()):
tmp = comb(val, 2)
cnt_comb[key] = tmp
sm = sm + tmp
# print(cnt_comb)
# print(list(A))
for a in A:
comb_val = cnt_comb.get(a)
cmb = comb(cnt.get(a) - 1, 2)
print((sm - comb_val + cmb))
if __name__ == '__main__':
solver()
| 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')
def solve():
n = II()
A = LI()
memo = {}
for a in A:
memo[a] = memo.get(a, 0) + 1
def choose2(a):
if a == 0: return 0
return a * (a-1) // 2
# print(memo)
ans = 0
for k, v in list(memo.items()):
ans = ans + choose2(v)
# print(ans)
for a in A:
print((ans - choose2(memo[a]) + choose2(memo[a] - 1)))
if __name__ == '__main__':
solve()
| 50 | 39 | 1,224 | 864 | from collections import Counter
import math
def solver():
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = Counter(A)
# print(cnt)
def comb(n, r):
if n - r < 0:
return 0
if n - r < r:
r = n - r
if r == 0:
return 1
if r == 1:
return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
cnt_comb = {}
sm = 0
for key, val in list(cnt.items()):
tmp = comb(val, 2)
cnt_comb[key] = tmp
sm = sm + tmp
# print(cnt_comb)
# print(list(A))
for a in A:
comb_val = cnt_comb.get(a)
cmb = comb(cnt.get(a) - 1, 2)
print((sm - comb_val + cmb))
if __name__ == "__main__":
solver()
| 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")
def solve():
n = II()
A = LI()
memo = {}
for a in A:
memo[a] = memo.get(a, 0) + 1
def choose2(a):
if a == 0:
return 0
return a * (a - 1) // 2
# print(memo)
ans = 0
for k, v in list(memo.items()):
ans = ans + choose2(v)
# print(ans)
for a in A:
print((ans - choose2(memo[a]) + choose2(memo[a] - 1)))
if __name__ == "__main__":
solve()
| false | 22 | [
"-from collections import Counter",
"-import math",
"+import sys",
"+",
"+sys.setrecursionlimit(10**6)",
"+# input = sys.stdin.readline ####",
"+int1 = lambda x: int(x) - 1",
"-def solver():",
"- N = int(eval(input()))",
"- A = list(map(int, input().split()))",
"- cnt = Counter(A)",
... | false | 0.093892 | 0.093983 | 0.999036 | [
"s962206754",
"s229318789"
] |
u226155577 | p03090 | python | s059024480 | s448252830 | 180 | 20 | 39,152 | 3,444 | Accepted | Accepted | 88.89 | import sys
N = int(eval(input()))
ans = []
if N % 2:
print((N*(N-1)//2 - N//2))
for i in range(1, N+1):
for j in range(i+1, N+1):
if i + j != N:
ans.append("%d %d\n" % (i, j))
else:
print((N*(N-1)//2 - N//2))
for i in range(1, N+1):
for j in range(i+1, N+1):
if i + j != N+1:
ans.append("%d %d\n" % (i, j))
sys.stdout.writelines(ans) | import sys
N = int(sys.stdin.readline())
ans = ["%d\n" % (N*(N-1)//2 - N//2)]
K = N+((N&1)^1)
for i in range(1, N+1):
for j in range(i+1, N+1):
if i + j != K:
ans.append("%d %d\n" % (i, j))
sys.stdout.writelines(ans) | 17 | 10 | 428 | 250 | import sys
N = int(eval(input()))
ans = []
if N % 2:
print((N * (N - 1) // 2 - N // 2))
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
if i + j != N:
ans.append("%d %d\n" % (i, j))
else:
print((N * (N - 1) // 2 - N // 2))
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
if i + j != N + 1:
ans.append("%d %d\n" % (i, j))
sys.stdout.writelines(ans)
| import sys
N = int(sys.stdin.readline())
ans = ["%d\n" % (N * (N - 1) // 2 - N // 2)]
K = N + ((N & 1) ^ 1)
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
if i + j != K:
ans.append("%d %d\n" % (i, j))
sys.stdout.writelines(ans)
| false | 41.176471 | [
"-N = int(eval(input()))",
"-ans = []",
"-if N % 2:",
"- print((N * (N - 1) // 2 - N // 2))",
"- for i in range(1, N + 1):",
"- for j in range(i + 1, N + 1):",
"- if i + j != N:",
"- ans.append(\"%d %d\\n\" % (i, j))",
"-else:",
"- print((N * (N - 1) // 2 ... | false | 0.040656 | 0.036129 | 1.125279 | [
"s059024480",
"s448252830"
] |
u864197622 | p02782 | python | s805187142 | s985337713 | 633 | 223 | 82,324 | 71,664 | Accepted | Accepted | 64.77 | nn = 2002002
P = 10**9+7
fa = [1]
for i in range(1, nn): fa.append(fa[-1] * i % P)
f = lambda a, b: fa[a+b+2] * pow(fa[a+1] * fa[b+1], P-2, P) % P - 1
r1, c1, r2, c2 = list(map(int, input().split()))
print(((f(r2, c2) - f(r2, c1-1) - f(r1-1, c2) + f(r1-1, c1-1)) % P)) | nn = 2002002
P = 10**9+7
fa = [1] + [0] * nn
for i in range(nn): fa[i+1] = fa[i] * (i+1) % P
f = lambda a, b: fa[a+b+2] * pow(fa[a+1] * fa[b+1], P-2, P) % P - 1
r1, c1, r2, c2 = list(map(int, input().split()))
print(((f(r2, c2) - f(r2, c1-1) - f(r1-1, c2) + f(r1-1, c1-1)) % P)) | 7 | 7 | 266 | 276 | nn = 2002002
P = 10**9 + 7
fa = [1]
for i in range(1, nn):
fa.append(fa[-1] * i % P)
f = lambda a, b: fa[a + b + 2] * pow(fa[a + 1] * fa[b + 1], P - 2, P) % P - 1
r1, c1, r2, c2 = list(map(int, input().split()))
print(((f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1)) % P))
| nn = 2002002
P = 10**9 + 7
fa = [1] + [0] * nn
for i in range(nn):
fa[i + 1] = fa[i] * (i + 1) % P
f = lambda a, b: fa[a + b + 2] * pow(fa[a + 1] * fa[b + 1], P - 2, P) % P - 1
r1, c1, r2, c2 = list(map(int, input().split()))
print(((f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1)) % P))
| false | 0 | [
"-fa = [1]",
"-for i in range(1, nn):",
"- fa.append(fa[-1] * i % P)",
"+fa = [1] + [0] * nn",
"+for i in range(nn):",
"+ fa[i + 1] = fa[i] * (i + 1) % P"
] | false | 0.97967 | 2.475082 | 0.395813 | [
"s805187142",
"s985337713"
] |
u186838327 | p03487 | python | s147175654 | s489735149 | 269 | 98 | 67,240 | 89,916 | Accepted | Accepted | 63.57 | n = int(eval(input()))
l = list(map(int, input().split()))
d = {}
for a in l:
if a in d:
d[a] += 1
else:
d[a] = 1
ans = 0
for k, v in list(d.items()):
if k > v:
ans += v
elif k < v:
ans += v-k
else:
pass
print(ans)
| n = int(eval(input()))
A = list(map(int, input().split()))
from collections import Counter
C = Counter(A)
ans = 0
for k, v in list(C.items()):
if v < k:
ans += v
elif v > k:
ans += (v-k)
print(ans)
| 19 | 12 | 253 | 222 | n = int(eval(input()))
l = list(map(int, input().split()))
d = {}
for a in l:
if a in d:
d[a] += 1
else:
d[a] = 1
ans = 0
for k, v in list(d.items()):
if k > v:
ans += v
elif k < v:
ans += v - k
else:
pass
print(ans)
| n = int(eval(input()))
A = list(map(int, input().split()))
from collections import Counter
C = Counter(A)
ans = 0
for k, v in list(C.items()):
if v < k:
ans += v
elif v > k:
ans += v - k
print(ans)
| false | 36.842105 | [
"-l = list(map(int, input().split()))",
"-d = {}",
"-for a in l:",
"- if a in d:",
"- d[a] += 1",
"- else:",
"- d[a] = 1",
"+A = list(map(int, input().split()))",
"+from collections import Counter",
"+",
"+C = Counter(A)",
"-for k, v in list(d.items()):",
"- if k > v:"... | false | 0.054135 | 0.049806 | 1.086905 | [
"s147175654",
"s489735149"
] |
u197615397 | p02271 | python | s307837662 | s515271406 | 820 | 500 | 49,116 | 5,792 | Accepted | Accepted | 39.02 | import bisect
n = int(eval(input()))
A = tuple(map(int,input().split()))
q = int(eval(input()))
Q = tuple(map(int, input().split()))
dp = [0]*(2**n)
for i in range(n):
for j in range(1<<i):
dp[j+(1<<i)] = dp[j] + A[i]
dp.sort()
for n in Q:
i = bisect.bisect(dp, n)
print(("yes" if i>0 and n==dp[i-1] else "no")) | def solve():
from itertools import product
input()
A = tuple(map(lambda x: (0, int(x)), input().split()))
result = [0]*(2000*20+1)
for a in product(*A):
result[sum(a)] = 1
input()
print(*("yes" if result[q] else "no" for q in map(int, input().split())), sep="\n")
if __name__ == "__main__":
solve()
| 15 | 14 | 333 | 355 | import bisect
n = int(eval(input()))
A = tuple(map(int, input().split()))
q = int(eval(input()))
Q = tuple(map(int, input().split()))
dp = [0] * (2**n)
for i in range(n):
for j in range(1 << i):
dp[j + (1 << i)] = dp[j] + A[i]
dp.sort()
for n in Q:
i = bisect.bisect(dp, n)
print(("yes" if i > 0 and n == dp[i - 1] else "no"))
| def solve():
from itertools import product
input()
A = tuple(map(lambda x: (0, int(x)), input().split()))
result = [0] * (2000 * 20 + 1)
for a in product(*A):
result[sum(a)] = 1
input()
print(*("yes" if result[q] else "no" for q in map(int, input().split())), sep="\n")
if __name__ == "__main__":
solve()
| false | 6.666667 | [
"-import bisect",
"+def solve():",
"+ from itertools import product",
"-n = int(eval(input()))",
"-A = tuple(map(int, input().split()))",
"-q = int(eval(input()))",
"-Q = tuple(map(int, input().split()))",
"-dp = [0] * (2**n)",
"-for i in range(n):",
"- for j in range(1 << i):",
"- ... | false | 0.034721 | 0.03509 | 0.989488 | [
"s307837662",
"s515271406"
] |
u644907318 | p03023 | python | s211701677 | s242251552 | 172 | 62 | 38,256 | 61,656 | Accepted | Accepted | 63.95 | print(((int(eval(input()))-2)*180)) | N = int(eval(input()))
print((180*(N-2))) | 1 | 2 | 27 | 34 | print(((int(eval(input())) - 2) * 180))
| N = int(eval(input()))
print((180 * (N - 2)))
| false | 50 | [
"-print(((int(eval(input())) - 2) * 180))",
"+N = int(eval(input()))",
"+print((180 * (N - 2)))"
] | false | 0.037032 | 0.036809 | 1.006047 | [
"s211701677",
"s242251552"
] |
u092650292 | p02606 | python | s411442823 | s813675886 | 42 | 29 | 10,020 | 9,112 | Accepted | Accepted | 30.95 | from math import gcd
from math import factorial as f
from math import ceil, floor, sqrt
import math
import bisect
import re
import heapq
from copy import deepcopy
import itertools
from itertools import permutations
from sys import exit
ii = lambda: int(eval(input()))
mi = lambda: list(map(int, input().split()))
li = lambda: list(map(int, input().split()))
yes = "Yes"
no = "No"
def main():
l, r, d = mi()
cnt = 0
tmp = d
while tmp <= r:
if tmp <= r and tmp >= l:
cnt += 1
tmp += d
print(cnt)
main()
| l, r, d = list(map(int, input().split()))
cnt = 0
tmp = d
while tmp <= r:
if tmp <= r and tmp >= l:
cnt += 1
tmp += d
print(cnt) | 37 | 9 | 584 | 147 | from math import gcd
from math import factorial as f
from math import ceil, floor, sqrt
import math
import bisect
import re
import heapq
from copy import deepcopy
import itertools
from itertools import permutations
from sys import exit
ii = lambda: int(eval(input()))
mi = lambda: list(map(int, input().split()))
li = lambda: list(map(int, input().split()))
yes = "Yes"
no = "No"
def main():
l, r, d = mi()
cnt = 0
tmp = d
while tmp <= r:
if tmp <= r and tmp >= l:
cnt += 1
tmp += d
print(cnt)
main()
| l, r, d = list(map(int, input().split()))
cnt = 0
tmp = d
while tmp <= r:
if tmp <= r and tmp >= l:
cnt += 1
tmp += d
print(cnt)
| false | 75.675676 | [
"-from math import gcd",
"-from math import factorial as f",
"-from math import ceil, floor, sqrt",
"-import math",
"-import bisect",
"-import re",
"-import heapq",
"-from copy import deepcopy",
"-import itertools",
"-from itertools import permutations",
"-from sys import exit",
"-",
"-ii = ... | false | 0.036349 | 0.047598 | 0.763661 | [
"s411442823",
"s813675886"
] |
u594956556 | p03037 | python | s636667801 | s992833842 | 347 | 308 | 3,060 | 10,996 | Accepted | Accepted | 11.24 | n,m=list(map(int,input().split()))
l0,r0=1,n
for i in range(m):
l,r=list(map(int,input().split()))
if l>r0 or r<l0:
print((0))
exit()
else:
l0=max(l0,l)
r0=min(r0,r)
print((r0-l0+1)) | n,m=list(map(int,input().split()))
l=[0 for _ in range(m)]
r=[0 for _ in range(m)]
for i in range(m):
l[i],r[i] = list(map(int,input().split()))
lmax=max(l)
rmin=min(r)
if rmin>=lmax:
print((rmin-lmax+1))
else:
print((0)) | 11 | 13 | 198 | 225 | n, m = list(map(int, input().split()))
l0, r0 = 1, n
for i in range(m):
l, r = list(map(int, input().split()))
if l > r0 or r < l0:
print((0))
exit()
else:
l0 = max(l0, l)
r0 = min(r0, r)
print((r0 - l0 + 1))
| n, m = list(map(int, input().split()))
l = [0 for _ in range(m)]
r = [0 for _ in range(m)]
for i in range(m):
l[i], r[i] = list(map(int, input().split()))
lmax = max(l)
rmin = min(r)
if rmin >= lmax:
print((rmin - lmax + 1))
else:
print((0))
| false | 15.384615 | [
"-l0, r0 = 1, n",
"+l = [0 for _ in range(m)]",
"+r = [0 for _ in range(m)]",
"- l, r = list(map(int, input().split()))",
"- if l > r0 or r < l0:",
"- print((0))",
"- exit()",
"- else:",
"- l0 = max(l0, l)",
"- r0 = min(r0, r)",
"-print((r0 - l0 + 1))",
"+ ... | false | 0.04105 | 0.070635 | 0.58115 | [
"s636667801",
"s992833842"
] |
u854175276 | p03013 | python | s337577807 | s589851085 | 603 | 478 | 64,800 | 45,040 | Accepted | Accepted | 20.73 | def xgcd(a, b):
if b == 0:
g = a
x = 1
y = 0
return g, x, y
else:
g, s, t = xgcd(b, a%b)
x = t
y = s - a//b*x
return g, x, y
def invmod(a, p):
_, x, _ = xgcd(a, p)
if x < 0:
x = x + p
return x
def count_route(n):
if n < 0:
return 0
res = 0
for i in range(n//2+1):
res += f[n - i] * inv[i] * inv[n - 2* i]
return res%const
n, m = list(map(int, input().split()))
const = 1000000007
#nใพใงใฎ้ไนใใใใทใฅใใผใใซใซๆ ผ็ดใใ
f = [1 for i in range(n + 1)]
inv = [1 for i in range(n + 1)]
for i in range(1, n+1):
f[i] = (f[i - 1] * i)%const
inv[i] = invmod(f[i], const)
prev = 0
ans = 1
for i in range(m):
m = int(eval(input()))
ans = (ans * count_route(m - 1 - prev))%const
prev = m + 1
if ans == 0:
break
ans = (ans * count_route(n - prev))%const
print(ans) | n , m = list(map(int, input().split()))
const = 1000000007
r = [1 for i in range(n+1)]
for i in range(m):
r[int(eval(input()))] = 0
for i in range(2, n+1):
if r[i] > 0:
r[i] = (r[i-1] + r[i-2])%const
print((r[n])) | 44 | 9 | 896 | 215 | def xgcd(a, b):
if b == 0:
g = a
x = 1
y = 0
return g, x, y
else:
g, s, t = xgcd(b, a % b)
x = t
y = s - a // b * x
return g, x, y
def invmod(a, p):
_, x, _ = xgcd(a, p)
if x < 0:
x = x + p
return x
def count_route(n):
if n < 0:
return 0
res = 0
for i in range(n // 2 + 1):
res += f[n - i] * inv[i] * inv[n - 2 * i]
return res % const
n, m = list(map(int, input().split()))
const = 1000000007
# nใพใงใฎ้ไนใใใใทใฅใใผใใซใซๆ ผ็ดใใ
f = [1 for i in range(n + 1)]
inv = [1 for i in range(n + 1)]
for i in range(1, n + 1):
f[i] = (f[i - 1] * i) % const
inv[i] = invmod(f[i], const)
prev = 0
ans = 1
for i in range(m):
m = int(eval(input()))
ans = (ans * count_route(m - 1 - prev)) % const
prev = m + 1
if ans == 0:
break
ans = (ans * count_route(n - prev)) % const
print(ans)
| n, m = list(map(int, input().split()))
const = 1000000007
r = [1 for i in range(n + 1)]
for i in range(m):
r[int(eval(input()))] = 0
for i in range(2, n + 1):
if r[i] > 0:
r[i] = (r[i - 1] + r[i - 2]) % const
print((r[n]))
| false | 79.545455 | [
"-def xgcd(a, b):",
"- if b == 0:",
"- g = a",
"- x = 1",
"- y = 0",
"- return g, x, y",
"- else:",
"- g, s, t = xgcd(b, a % b)",
"- x = t",
"- y = s - a // b * x",
"- return g, x, y",
"-",
"-",
"-def invmod(a, p):",
"- _, ... | false | 0.04552 | 0.048371 | 0.941047 | [
"s337577807",
"s589851085"
] |
u102461423 | p02931 | python | s270058485 | s480087739 | 459 | 397 | 35,576 | 35,448 | Accepted | Accepted | 13.51 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
import operator
N,H,W = list(map(int,readline().split()))
m = list(map(int,read().split()))
RCA = sorted(zip(m,m,m),key=operator.itemgetter(2),reverse=True)
root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [True] * (H+W)
def find_root(x):
y = root[x]
if x == y:
return x
path = [x]
while y != root[y]:
path.append(y)
y = root[y]
for p in path:
root[p] = y
return y
def merge(x,y):
x,y = find_root(x),find_root(y)
sx,sy = size[x],size[y]
if sx < sy:
sx,sy = sy,sx
x,y = y,x
root[y] = x
size[x] += sy
no_cycle[x] = no_cycle[x] and no_cycle[y]
answer = 0
for R,C,A in RCA:
x,y = R-1,H+C-1
rx,ry = find_root(x),find_root(y)
if rx == ry:
if not no_cycle[rx]:
continue
no_cycle[rx] = False
else:
if (not no_cycle[rx]) and (not no_cycle[ry]):
continue
merge(rx,ry)
answer += A
print(answer)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import operator
N,H,W = list(map(int,readline().split()))
m = list(map(int,read().split()))
RCA = sorted(zip(m,m,m),key=operator.itemgetter(2),reverse=True)
root = list(range(H+W))
size = [1] * (H+W)
no_cycle = [True] * (H+W)
def find_root(x):
y = root[x]
if x == y:
return y
z = find_root(y)
root[x] = z
return z
def merge(x,y):
x,y = find_root(x),find_root(y)
sx,sy = size[x],size[y]
if sx < sy:
sx,sy = sy,sx
x,y = y,x
root[y] = x
size[x] += sy
no_cycle[x] = no_cycle[x] and no_cycle[y]
answer = 0
for R,C,A in RCA:
x,y = R-1,H+C-1
rx,ry = find_root(x),find_root(y)
if rx == ry:
if not no_cycle[rx]:
continue
no_cycle[rx] = False
else:
if (not no_cycle[rx]) and (not no_cycle[ry]):
continue
merge(rx,ry)
answer += A
print(answer)
| 53 | 48 | 1,153 | 1,035 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
import operator
N, H, W = list(map(int, readline().split()))
m = list(map(int, read().split()))
RCA = sorted(zip(m, m, m), key=operator.itemgetter(2), reverse=True)
root = list(range(H + W))
size = [0] * (H + W)
no_cycle = [True] * (H + W)
def find_root(x):
y = root[x]
if x == y:
return x
path = [x]
while y != root[y]:
path.append(y)
y = root[y]
for p in path:
root[p] = y
return y
def merge(x, y):
x, y = find_root(x), find_root(y)
sx, sy = size[x], size[y]
if sx < sy:
sx, sy = sy, sx
x, y = y, x
root[y] = x
size[x] += sy
no_cycle[x] = no_cycle[x] and no_cycle[y]
answer = 0
for R, C, A in RCA:
x, y = R - 1, H + C - 1
rx, ry = find_root(x), find_root(y)
if rx == ry:
if not no_cycle[rx]:
continue
no_cycle[rx] = False
else:
if (not no_cycle[rx]) and (not no_cycle[ry]):
continue
merge(rx, ry)
answer += A
print(answer)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import operator
N, H, W = list(map(int, readline().split()))
m = list(map(int, read().split()))
RCA = sorted(zip(m, m, m), key=operator.itemgetter(2), reverse=True)
root = list(range(H + W))
size = [1] * (H + W)
no_cycle = [True] * (H + W)
def find_root(x):
y = root[x]
if x == y:
return y
z = find_root(y)
root[x] = z
return z
def merge(x, y):
x, y = find_root(x), find_root(y)
sx, sy = size[x], size[y]
if sx < sy:
sx, sy = sy, sx
x, y = y, x
root[y] = x
size[x] += sy
no_cycle[x] = no_cycle[x] and no_cycle[y]
answer = 0
for R, C, A in RCA:
x, y = R - 1, H + C - 1
rx, ry = find_root(x), find_root(y)
if rx == ry:
if not no_cycle[rx]:
continue
no_cycle[rx] = False
else:
if (not no_cycle[rx]) and (not no_cycle[ry]):
continue
merge(rx, ry)
answer += A
print(answer)
| false | 9.433962 | [
"-sys.setrecursionlimit(10**7)",
"-size = [0] * (H + W)",
"+size = [1] * (H + W)",
"- return x",
"- path = [x]",
"- while y != root[y]:",
"- path.append(y)",
"- y = root[y]",
"- for p in path:",
"- root[p] = y",
"- return y",
"+ return y",
"+ ... | false | 0.038218 | 0.074417 | 0.513564 | [
"s270058485",
"s480087739"
] |
u497596438 | p03290 | python | s505713687 | s368256324 | 234 | 215 | 44,016 | 41,456 | Accepted | Accepted | 8.12 | from copy import copy
D,G=list(map(int,input().split()))
p=[]
c=[]
for i in range(D):
a,b=list(map(int,input().split()))
p.append(a)
c.append(b)
lst1=[]
lst2=[]
lst3=[]
def func1(l1,l2,l3,p,c,G):
S=0
n=0
ind=0
for i in range(len(l1)):
S+=c[i]*l1[i]
n+=p[i]*l1[i]
S+=p[i]*100*(i+1)*l1[i]
for i in range(len(l2)):
if S>=G:
break
kazu=len(l2)-i
a=l2[kazu-1]
for j in range(1,a+1):
if j==a:
break
S+=100*kazu
n+=1
if S>=G:
break
if S>=G:
l3.append(n)
l3.append(S)
return 0
def func(l1,l2,l3,num,p,c,G):
if num==0:
func1(l1,l2,l3,p,c,G)
return 0
y1=copy(l2)
y2=copy(l2)
y2[len(l1)]=0
x1=copy(l1)
x1.append(0)
x2=copy(l1)
x2.append(1)
num-=1
return func(x1,y1,l3,num,p,c,G),func(x2,y2,l3,num,p,c,G)
func(lst1,p,lst3,D,p,c,G)
print((min(lst3))) | from math import ceil
D,G=list(map(int,input().split()))
P=[]
C=[]
R=[]
for i in range(D):
p,c=list(map(int,input().split()))
P.append(p)
C.append(c)
R.append((i+1)*100*p+c)
bit=2**D
ans=10**19
for i in range(bit):
i=bin(i)[2:].zfill(D)
su=0
num=0
k=-1
for j in range(D):
k=int(i[j])
su+=k*R[j]
num+=k*P[j]
if k==0:
t=j
if G<=su:
ans=min(ans,num)
continue
if k==-1:
continue
if ceil((G-su)/((t+1)*100))<P[t]:
ans=min(ans,num+ceil((G-su)/((t+1)*100)))
print(ans)
| 50 | 31 | 1,032 | 605 | from copy import copy
D, G = list(map(int, input().split()))
p = []
c = []
for i in range(D):
a, b = list(map(int, input().split()))
p.append(a)
c.append(b)
lst1 = []
lst2 = []
lst3 = []
def func1(l1, l2, l3, p, c, G):
S = 0
n = 0
ind = 0
for i in range(len(l1)):
S += c[i] * l1[i]
n += p[i] * l1[i]
S += p[i] * 100 * (i + 1) * l1[i]
for i in range(len(l2)):
if S >= G:
break
kazu = len(l2) - i
a = l2[kazu - 1]
for j in range(1, a + 1):
if j == a:
break
S += 100 * kazu
n += 1
if S >= G:
break
if S >= G:
l3.append(n)
l3.append(S)
return 0
def func(l1, l2, l3, num, p, c, G):
if num == 0:
func1(l1, l2, l3, p, c, G)
return 0
y1 = copy(l2)
y2 = copy(l2)
y2[len(l1)] = 0
x1 = copy(l1)
x1.append(0)
x2 = copy(l1)
x2.append(1)
num -= 1
return func(x1, y1, l3, num, p, c, G), func(x2, y2, l3, num, p, c, G)
func(lst1, p, lst3, D, p, c, G)
print((min(lst3)))
| from math import ceil
D, G = list(map(int, input().split()))
P = []
C = []
R = []
for i in range(D):
p, c = list(map(int, input().split()))
P.append(p)
C.append(c)
R.append((i + 1) * 100 * p + c)
bit = 2**D
ans = 10**19
for i in range(bit):
i = bin(i)[2:].zfill(D)
su = 0
num = 0
k = -1
for j in range(D):
k = int(i[j])
su += k * R[j]
num += k * P[j]
if k == 0:
t = j
if G <= su:
ans = min(ans, num)
continue
if k == -1:
continue
if ceil((G - su) / ((t + 1) * 100)) < P[t]:
ans = min(ans, num + ceil((G - su) / ((t + 1) * 100)))
print(ans)
| false | 38 | [
"-from copy import copy",
"+from math import ceil",
"-p = []",
"-c = []",
"+P = []",
"+C = []",
"+R = []",
"- a, b = list(map(int, input().split()))",
"- p.append(a)",
"- c.append(b)",
"-lst1 = []",
"-lst2 = []",
"-lst3 = []",
"-",
"-",
"-def func1(l1, l2, l3, p, c, G):",
"-... | false | 0.039615 | 0.036949 | 1.072138 | [
"s505713687",
"s368256324"
] |
u463775490 | p03610 | python | s463151680 | s477702703 | 29 | 18 | 3,572 | 3,192 | Accepted | Accepted | 37.93 | s = eval(input())
ans = [s[i] for i in range(len(s)) if i%2 == 0]
print((''.join(ans))) | print((input()[::2])) | 3 | 1 | 81 | 19 | s = eval(input())
ans = [s[i] for i in range(len(s)) if i % 2 == 0]
print(("".join(ans)))
| print((input()[::2]))
| false | 66.666667 | [
"-s = eval(input())",
"-ans = [s[i] for i in range(len(s)) if i % 2 == 0]",
"-print((\"\".join(ans)))",
"+print((input()[::2]))"
] | false | 0.138985 | 0.042304 | 3.285374 | [
"s463151680",
"s477702703"
] |
u798803522 | p02271 | python | s223328676 | s756170629 | 70 | 20 | 7,792 | 7,788 | Accepted | Accepted | 71.43 | a_len = int(eval(input()))
a_ar = sorted([int(n) for n in input().split(" ")])
b_len = int(eval(input()))
b_ar = [int(n) for n in input().split(" ")]
dp = [0 for n in range(2001)]
for a in a_ar:
new_dp = dp[:]
new_dp[a] = 1
for i,d in enumerate(dp):
if d and i + a <= 2000:
new_dp[i + a] = 1
elif i + a > 2000:
break
dp = new_dp
for b in b_ar:
if dp[b]:
print("yes")
else:
print("no") | a_len = int(eval(input()))
a_ar = sorted([int(n) for n in input().split(" ")])
b_len = int(eval(input()))
b_ar = [int(n) for n in input().split(" ")]
max_b = max(b_ar)
dp = [0 for n in range(max_b + 1)]
for a in a_ar:
new_dp = dp[:]
new_dp[a] = 1
for i,d in enumerate(dp):
if d and i + a <= max_b:
new_dp[i + a] = 1
dp = new_dp
for b in b_ar:
if dp[b]:
print("yes")
else:
print("no") | 19 | 18 | 470 | 448 | a_len = int(eval(input()))
a_ar = sorted([int(n) for n in input().split(" ")])
b_len = int(eval(input()))
b_ar = [int(n) for n in input().split(" ")]
dp = [0 for n in range(2001)]
for a in a_ar:
new_dp = dp[:]
new_dp[a] = 1
for i, d in enumerate(dp):
if d and i + a <= 2000:
new_dp[i + a] = 1
elif i + a > 2000:
break
dp = new_dp
for b in b_ar:
if dp[b]:
print("yes")
else:
print("no")
| a_len = int(eval(input()))
a_ar = sorted([int(n) for n in input().split(" ")])
b_len = int(eval(input()))
b_ar = [int(n) for n in input().split(" ")]
max_b = max(b_ar)
dp = [0 for n in range(max_b + 1)]
for a in a_ar:
new_dp = dp[:]
new_dp[a] = 1
for i, d in enumerate(dp):
if d and i + a <= max_b:
new_dp[i + a] = 1
dp = new_dp
for b in b_ar:
if dp[b]:
print("yes")
else:
print("no")
| false | 5.263158 | [
"-dp = [0 for n in range(2001)]",
"+max_b = max(b_ar)",
"+dp = [0 for n in range(max_b + 1)]",
"- if d and i + a <= 2000:",
"+ if d and i + a <= max_b:",
"- elif i + a > 2000:",
"- break"
] | false | 0.037775 | 0.052689 | 0.716938 | [
"s223328676",
"s756170629"
] |
u832039789 | p02861 | python | s644835799 | s925005942 | 402 | 17 | 3,188 | 3,064 | Accepted | Accepted | 95.77 | from itertools import permutations as perm
n = int(eval(input()))
l = []
for i in range(n):
x,y = list(map(int,input().split()))
l.append([x, y])
sm = 0
cnt = 0
permm = list(range(n))
for p in perm(permm):
for i, j in zip(p, p[1:]):
x1, y1 = l[i]
x2, y2 = l[j]
sm += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
cnt += 1
print((sm / cnt)) | n = int(eval(input()))
l = []
for i in range(n):
x,y = list(map(int,input().split()))
l.append([x, y])
sm = 0
for i in range(n):
for j in range(n):
sm += ((l[i][0] - l[j][0]) ** 2 + (l[i][1] - l[j][1]) ** 2) ** 0.5
print((sm / n)) | 20 | 11 | 383 | 247 | from itertools import permutations as perm
n = int(eval(input()))
l = []
for i in range(n):
x, y = list(map(int, input().split()))
l.append([x, y])
sm = 0
cnt = 0
permm = list(range(n))
for p in perm(permm):
for i, j in zip(p, p[1:]):
x1, y1 = l[i]
x2, y2 = l[j]
sm += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
cnt += 1
print((sm / cnt))
| n = int(eval(input()))
l = []
for i in range(n):
x, y = list(map(int, input().split()))
l.append([x, y])
sm = 0
for i in range(n):
for j in range(n):
sm += ((l[i][0] - l[j][0]) ** 2 + (l[i][1] - l[j][1]) ** 2) ** 0.5
print((sm / n))
| false | 45 | [
"-from itertools import permutations as perm",
"-",
"-cnt = 0",
"-permm = list(range(n))",
"-for p in perm(permm):",
"- for i, j in zip(p, p[1:]):",
"- x1, y1 = l[i]",
"- x2, y2 = l[j]",
"- sm += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5",
"- cnt += 1",
"-print((sm / cn... | false | 0.092762 | 0.044976 | 2.062506 | [
"s644835799",
"s925005942"
] |
u925626880 | p03448 | python | s898553298 | s895208388 | 32 | 28 | 3,060 | 3,060 | Accepted | Accepted | 12.5 | def main():
a = int(eval(input())) # 500
b = int(eval(input())) # 100
c = int(eval(input())) # 50
x = int(eval(input()))
ans = 0
for i in range(a+1):
I = i*500
for j in range(b+1):
J = j*100
for k in range(c+1):
K = k*50
if I+J+K == x:
ans +=1
print(ans)
if __name__ == '__main__':
main()
| def main():
a = int(eval(input())) # 500
b = int(eval(input())) # 100
c = int(eval(input())) # 50
x = int(eval(input()))
ans = 0
for i in range(a+1):
I = i*500
if I > x:
break
for j in range(b+1):
J = j*100
if I+J > x:
break
for k in range(c+1):
K = k*50
if I+J+K == x:
ans +=1
print(ans)
if __name__ == '__main__':
main()
| 21 | 25 | 414 | 500 | def main():
a = int(eval(input())) # 500
b = int(eval(input())) # 100
c = int(eval(input())) # 50
x = int(eval(input()))
ans = 0
for i in range(a + 1):
I = i * 500
for j in range(b + 1):
J = j * 100
for k in range(c + 1):
K = k * 50
if I + J + K == x:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| def main():
a = int(eval(input())) # 500
b = int(eval(input())) # 100
c = int(eval(input())) # 50
x = int(eval(input()))
ans = 0
for i in range(a + 1):
I = i * 500
if I > x:
break
for j in range(b + 1):
J = j * 100
if I + J > x:
break
for k in range(c + 1):
K = k * 50
if I + J + K == x:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 16 | [
"+ if I > x:",
"+ break",
"+ if I + J > x:",
"+ break"
] | false | 0.007733 | 0.038529 | 0.200706 | [
"s898553298",
"s895208388"
] |
u150984829 | p02234 | python | s214014608 | s122369231 | 180 | 130 | 5,728 | 5,728 | Accepted | Accepted | 27.78 | import sys
n=int(eval(input()))+1
e=list([x.split() for x in sys.stdin])
p=[int(e[0][0])]+list(int(x[1])for x in e)
m=[[0]*n for _ in[0]*n]
for l in range(2,n):
for i in range(1,n-l+1):
j=i+l-1;m[i][j]=1e6
for k in range(i,j):m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
print((m[1][n-1]))
| def s():
n=int(eval(input()))+1
e=[input().split()for _ in[0]*~-n]
p=[int(e[0][0])]+list(int(x[1])for x in e)
m=[[0]*n for _ in[0]*n]
for l in range(2,n):
for i in range(1,n-l+1):
j=i+l-1;m[i][j]=1e6
for k in range(i,j):m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
print((m[1][n-1]))
if'__main__'==__name__:s()
| 10 | 11 | 310 | 339 | import sys
n = int(eval(input())) + 1
e = list([x.split() for x in sys.stdin])
p = [int(e[0][0])] + list(int(x[1]) for x in e)
m = [[0] * n for _ in [0] * n]
for l in range(2, n):
for i in range(1, n - l + 1):
j = i + l - 1
m[i][j] = 1e6
for k in range(i, j):
m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j])
print((m[1][n - 1]))
| def s():
n = int(eval(input())) + 1
e = [input().split() for _ in [0] * ~-n]
p = [int(e[0][0])] + list(int(x[1]) for x in e)
m = [[0] * n for _ in [0] * n]
for l in range(2, n):
for i in range(1, n - l + 1):
j = i + l - 1
m[i][j] = 1e6
for k in range(i, j):
m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j])
print((m[1][n - 1]))
if "__main__" == __name__:
s()
| false | 9.090909 | [
"-import sys",
"+def s():",
"+ n = int(eval(input())) + 1",
"+ e = [input().split() for _ in [0] * ~-n]",
"+ p = [int(e[0][0])] + list(int(x[1]) for x in e)",
"+ m = [[0] * n for _ in [0] * n]",
"+ for l in range(2, n):",
"+ for i in range(1, n - l + 1):",
"+ j = i +... | false | 0.046863 | 0.039865 | 1.175531 | [
"s214014608",
"s122369231"
] |
u084320347 | p02754 | python | s934868969 | s113012239 | 173 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90.17 | N,A,B = list(map(int,input().split()))
ans = N//(A+B)*A
ans += min(N%(A+B),A)
print(ans)
| n,a,b = list(map(int,input().split()))
print(((n//(a+b)*a)+min(n%(a+b),a))) | 7 | 3 | 98 | 76 | N, A, B = list(map(int, input().split()))
ans = N // (A + B) * A
ans += min(N % (A + B), A)
print(ans)
| n, a, b = list(map(int, input().split()))
print(((n // (a + b) * a) + min(n % (a + b), a)))
| false | 57.142857 | [
"-N, A, B = list(map(int, input().split()))",
"-ans = N // (A + B) * A",
"-ans += min(N % (A + B), A)",
"-print(ans)",
"+n, a, b = list(map(int, input().split()))",
"+print(((n // (a + b) * a) + min(n % (a + b), a)))"
] | false | 0.057814 | 0.03551 | 1.628129 | [
"s934868969",
"s113012239"
] |
u628335443 | p02924 | python | s121876135 | s603095570 | 34 | 17 | 5,076 | 2,940 | Accepted | Accepted | 50 | from decimal import Decimal
n = int(eval(input()))
ans = (Decimal((n - 1) * n) / 2)
print(ans)
| n = int(eval(input()))
ans = ((n - 1) * n) // 2
print(ans)
| 7 | 4 | 98 | 57 | from decimal import Decimal
n = int(eval(input()))
ans = Decimal((n - 1) * n) / 2
print(ans)
| n = int(eval(input()))
ans = ((n - 1) * n) // 2
print(ans)
| false | 42.857143 | [
"-from decimal import Decimal",
"-",
"-ans = Decimal((n - 1) * n) / 2",
"+ans = ((n - 1) * n) // 2"
] | false | 0.050091 | 0.063869 | 0.784272 | [
"s121876135",
"s603095570"
] |
u090225501 | p03343 | python | s862738518 | s374807455 | 1,397 | 797 | 3,452 | 12,404 | Accepted | Accepted | 42.95 | import heapq
def main():
_, k, q = list(map(int, input().split()))
a = tuple(map(int, input().split()))
gs = [a]
m = float('inf')
for y in sorted(set(a)):
gs = groups(gs, y, k)
x = find_x(gs, y, k, q)
if x is None:
break
m = min(m, x - y)
print(m)
def find_x(gs, y, k, q):
xs = []
for g in gs:
xs.extend(heapq.nsmallest(len(g) - k + 1, g))
xss = heapq.nsmallest(q, xs)
if len(xss) < q:
return None
return xss[-1]
def groups(gs, m, k):
new_gs = []
for g in gs:
new_gs.extend(groups_1(g, m, k))
return new_gs
def groups_1(a, m, k):
g = []
pos = 0
while pos < len(a):
i = pos
while i < len(a) and a[i] < m:
i += 1
j = i
while j < len(a) and a[j] >= m:
j += 1
if j - i >= k:
g.append(a[i:j])
pos = j
return g
main() | import heapq
def main():
_, k, q = list(map(int, input().split()))
a = list(map(int, input().split()))
idx = make_index(a)
groups = [(0, len(a))]
m = float('inf')
for y in sorted(set(a)):
xs = []
for start, stop in groups:
xs.extend(nsmallest(stop - start - k + 1, a, start, stop))
if len(xs) < q:
break
xxs = heapq.nsmallest(q, xs)
x = xxs[-1]
m = min(m, x - y)
groups = split_groups(idx[y], groups, k)
print(m)
MEMO = dict()
def nsmallest(n, a, start, stop):
global MEMO
key = (n, id(a), start, stop)
if key in MEMO:
return MEMO[key]
val = heapq.nsmallest(n, a[start:stop])
MEMO[key] = val
return val
def split_groups(pivots, groups, k):
gs = []
i = 0
for start, stop in groups:
while i < len(pivots) and pivots[i] < start:
i += 1
while i < len(pivots) and pivots[i] <= stop:
if pivots[i] - start >= k:
gs.append((start, pivots[i]))
start = pivots[i] + 1
i += 1
if stop - start >= k:
gs.append((start, stop))
return gs
def make_index(a):
idx = dict()
for i, x in enumerate(a):
if x in idx:
idx[x].append(i)
else:
idx[x] = [i]
return idx
main()
| 56 | 67 | 1,039 | 1,431 | import heapq
def main():
_, k, q = list(map(int, input().split()))
a = tuple(map(int, input().split()))
gs = [a]
m = float("inf")
for y in sorted(set(a)):
gs = groups(gs, y, k)
x = find_x(gs, y, k, q)
if x is None:
break
m = min(m, x - y)
print(m)
def find_x(gs, y, k, q):
xs = []
for g in gs:
xs.extend(heapq.nsmallest(len(g) - k + 1, g))
xss = heapq.nsmallest(q, xs)
if len(xss) < q:
return None
return xss[-1]
def groups(gs, m, k):
new_gs = []
for g in gs:
new_gs.extend(groups_1(g, m, k))
return new_gs
def groups_1(a, m, k):
g = []
pos = 0
while pos < len(a):
i = pos
while i < len(a) and a[i] < m:
i += 1
j = i
while j < len(a) and a[j] >= m:
j += 1
if j - i >= k:
g.append(a[i:j])
pos = j
return g
main()
| import heapq
def main():
_, k, q = list(map(int, input().split()))
a = list(map(int, input().split()))
idx = make_index(a)
groups = [(0, len(a))]
m = float("inf")
for y in sorted(set(a)):
xs = []
for start, stop in groups:
xs.extend(nsmallest(stop - start - k + 1, a, start, stop))
if len(xs) < q:
break
xxs = heapq.nsmallest(q, xs)
x = xxs[-1]
m = min(m, x - y)
groups = split_groups(idx[y], groups, k)
print(m)
MEMO = dict()
def nsmallest(n, a, start, stop):
global MEMO
key = (n, id(a), start, stop)
if key in MEMO:
return MEMO[key]
val = heapq.nsmallest(n, a[start:stop])
MEMO[key] = val
return val
def split_groups(pivots, groups, k):
gs = []
i = 0
for start, stop in groups:
while i < len(pivots) and pivots[i] < start:
i += 1
while i < len(pivots) and pivots[i] <= stop:
if pivots[i] - start >= k:
gs.append((start, pivots[i]))
start = pivots[i] + 1
i += 1
if stop - start >= k:
gs.append((start, stop))
return gs
def make_index(a):
idx = dict()
for i, x in enumerate(a):
if x in idx:
idx[x].append(i)
else:
idx[x] = [i]
return idx
main()
| false | 16.41791 | [
"- a = tuple(map(int, input().split()))",
"- gs = [a]",
"+ a = list(map(int, input().split()))",
"+ idx = make_index(a)",
"+ groups = [(0, len(a))]",
"- gs = groups(gs, y, k)",
"- x = find_x(gs, y, k, q)",
"- if x is None:",
"+ xs = []",
"+ for sta... | false | 0.079809 | 0.046785 | 1.70589 | [
"s862738518",
"s374807455"
] |
u416758623 | p03243 | python | s790797337 | s830360044 | 22 | 17 | 2,940 | 2,940 | Accepted | Accepted | 22.73 | n = eval(input())
for i in range(1,10):
N = str(i) + str(i) + str(i)
if n <= N:
print(N)
break | # coding: utf-8
# Your code here!
N = eval(input())
if N[0]==N[1]==N[2]:
print(N)
else:
if int(N) <int(N[0]*3):
print((int(N[0]*3)))
else:
print((str((int(N[0])+1))*3))
| 6 | 12 | 117 | 208 | n = eval(input())
for i in range(1, 10):
N = str(i) + str(i) + str(i)
if n <= N:
print(N)
break
| # coding: utf-8
# Your code here!
N = eval(input())
if N[0] == N[1] == N[2]:
print(N)
else:
if int(N) < int(N[0] * 3):
print((int(N[0] * 3)))
else:
print((str((int(N[0]) + 1)) * 3))
| false | 50 | [
"-n = eval(input())",
"-for i in range(1, 10):",
"- N = str(i) + str(i) + str(i)",
"- if n <= N:",
"- print(N)",
"- break",
"+# coding: utf-8",
"+# Your code here!",
"+N = eval(input())",
"+if N[0] == N[1] == N[2]:",
"+ print(N)",
"+else:",
"+ if int(N) < int(N[0] *... | false | 0.068553 | 0.03242 | 2.114502 | [
"s790797337",
"s830360044"
] |
u072717685 | p03775 | python | s361427352 | s593463713 | 70 | 39 | 64,708 | 9,260 | Accepted | Accepted | 44.29 | from math import floor
def main():
n = int(eval(input()))
nsq = floor(n ** 0.5)
r = 11
for nsqe in range(nsq, 0, -1):
if n % nsqe == 0:
rt = max(len(str(nsqe)), len(str(n // nsqe)))
r = min(r, rt)
print(r)
if __name__ == '__main__':
main() | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import sqrt, ceil, log10
def main():
n = int(eval(input()))
sqrtn = ceil(sqrt(n))
r = n
for i1 in range(1, sqrtn + 1):
if n % i1 == 0:
t1 = log10(i1)
t2 = log10(n//i1)
t = max(t1, t2) + 1
r = min(r, t)
print((int(r)))
if __name__ == '__main__':
main()
| 14 | 18 | 304 | 417 | from math import floor
def main():
n = int(eval(input()))
nsq = floor(n**0.5)
r = 11
for nsqe in range(nsq, 0, -1):
if n % nsqe == 0:
rt = max(len(str(nsqe)), len(str(n // nsqe)))
r = min(r, rt)
print(r)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import sqrt, ceil, log10
def main():
n = int(eval(input()))
sqrtn = ceil(sqrt(n))
r = n
for i1 in range(1, sqrtn + 1):
if n % i1 == 0:
t1 = log10(i1)
t2 = log10(n // i1)
t = max(t1, t2) + 1
r = min(r, t)
print((int(r)))
if __name__ == "__main__":
main()
| false | 22.222222 | [
"-from math import floor",
"+import sys",
"+",
"+read = sys.stdin.read",
"+readlines = sys.stdin.readlines",
"+from math import sqrt, ceil, log10",
"- nsq = floor(n**0.5)",
"- r = 11",
"- for nsqe in range(nsq, 0, -1):",
"- if n % nsqe == 0:",
"- rt = max(len(str(nsqe)... | false | 0.060252 | 0.055146 | 1.092591 | [
"s361427352",
"s593463713"
] |
u445624660 | p02743 | python | s336486067 | s094268790 | 121 | 26 | 5,588 | 9,160 | Accepted | Accepted | 78.51 | from decimal import *
a, b, c = list(map(int, input().split()))
if Decimal(a)**Decimal("0.5") + Decimal(b)**Decimal("0.5") < Decimal(
c)**Decimal("0.5"):
print("Yes")
else:
print("No")
| a, b, c = list(map(int, input().split()))
# a + 2โab + b < c , 2โab < c - a - b, 4ab < (c - a - b)^2
if c - a - b < 0:
print("No")
else:
print(("Yes" if 4 * a * b < (c - a - b)**2 else "No"))
| 7 | 6 | 201 | 197 | from decimal import *
a, b, c = list(map(int, input().split()))
if Decimal(a) ** Decimal("0.5") + Decimal(b) ** Decimal("0.5") < Decimal(c) ** Decimal(
"0.5"
):
print("Yes")
else:
print("No")
| a, b, c = list(map(int, input().split()))
# a + 2โab + b < c , 2โab < c - a - b, 4ab < (c - a - b)^2
if c - a - b < 0:
print("No")
else:
print(("Yes" if 4 * a * b < (c - a - b) ** 2 else "No"))
| false | 14.285714 | [
"-from decimal import *",
"-",
"-if Decimal(a) ** Decimal(\"0.5\") + Decimal(b) ** Decimal(\"0.5\") < Decimal(c) ** Decimal(",
"- \"0.5\"",
"-):",
"- print(\"Yes\")",
"+# a + 2โab + b < c , 2โab < c - a - b, 4ab < (c - a - b)^2",
"+if c - a - b < 0:",
"+ print(\"No\")",
"- print(\"No\"... | false | 0.04774 | 0.07586 | 0.629322 | [
"s336486067",
"s094268790"
] |
u745087332 | p03152 | python | s978512182 | s163917042 | 855 | 543 | 3,188 | 3,188 | Accepted | Accepted | 36.49 | # coding:utf-8
import sys
import bisect
# from collections import Counter, defaultdict
INF = float('inf')
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return eval(input())
N, M = LI()
A = LI()
B = LI()
A.sort()
B.sort()
SA = set(A)
SB = set(B)
if N != len(SA) or M != len(SB):
print((0))
exit()
ans = 1
num = 0
aa = N
bb = M
for i in range(1, N * M + 1)[::-1]:
if i in SA and i in SB:
pass
elif i in SB:
while aa != 0 and 0 < i <= A[aa - 1]:
aa -= 1
ans *= N - aa
ans %= MOD
elif i in SA:
while bb != 0 and 0 < i <= B[bb - 1]:
bb -= 1
ans *= M - bb
ans %= MOD
else:
while aa != 0 and 0 < i <= A[aa - 1]:
aa -= 1
while bb != 0 and 0 < i <= B[bb - 1]:
bb -= 1
ans *= (M - bb) * (N - aa) - num
ans %= MOD
num += 1
# print(i, ans, num)
print(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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
def main():
h, w = LI()
A = LI()
A.sort()
B = LI()
B.sort()
# A, Bๅ
ใงใฏๅใๅคใฏๅญๅจใงใใชใ
if len(A) != len(set(A)) or len(B) != len(set(B)):
return 0
a_i, b_i = h - 1, w - 1
if h * w > A[a_i] or h * w > B[b_i]:
return 0
res = 1
for n in range(1, h * w + 1)[::-1]:
while a_i > 0 and A[a_i - 1] >= n:
a_i -= 1
while b_i > 0 and B[b_i - 1] >= n:
b_i -= 1
if n == A[a_i] and n == B[b_i]:
res *= 1
elif n == A[a_i]:
res *= w - b_i
elif n == B[b_i]:
res *= h - a_i
else:
res *= (h - a_i) * (w - b_i) - (h * w - n)
res %= MOD
return res
print((main()))
| 60 | 50 | 1,109 | 1,097 | # coding:utf-8
import sys
import bisect
# from collections import Counter, defaultdict
INF = float("inf")
MOD = 10**9 + 7
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def I():
return int(sys.stdin.readline())
def S():
return eval(input())
N, M = LI()
A = LI()
B = LI()
A.sort()
B.sort()
SA = set(A)
SB = set(B)
if N != len(SA) or M != len(SB):
print((0))
exit()
ans = 1
num = 0
aa = N
bb = M
for i in range(1, N * M + 1)[::-1]:
if i in SA and i in SB:
pass
elif i in SB:
while aa != 0 and 0 < i <= A[aa - 1]:
aa -= 1
ans *= N - aa
ans %= MOD
elif i in SA:
while bb != 0 and 0 < i <= B[bb - 1]:
bb -= 1
ans *= M - bb
ans %= MOD
else:
while aa != 0 and 0 < i <= A[aa - 1]:
aa -= 1
while bb != 0 and 0 < i <= B[bb - 1]:
bb -= 1
ans *= (M - bb) * (N - aa) - num
ans %= MOD
num += 1
# print(i, ans, num)
print(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 LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return eval(input())
def main():
h, w = LI()
A = LI()
A.sort()
B = LI()
B.sort()
# A, Bๅ
ใงใฏๅใๅคใฏๅญๅจใงใใชใ
if len(A) != len(set(A)) or len(B) != len(set(B)):
return 0
a_i, b_i = h - 1, w - 1
if h * w > A[a_i] or h * w > B[b_i]:
return 0
res = 1
for n in range(1, h * w + 1)[::-1]:
while a_i > 0 and A[a_i - 1] >= n:
a_i -= 1
while b_i > 0 and B[b_i - 1] >= n:
b_i -= 1
if n == A[a_i] and n == B[b_i]:
res *= 1
elif n == A[a_i]:
res *= w - b_i
elif n == B[b_i]:
res *= h - a_i
else:
res *= (h - a_i) * (w - b_i) - (h * w - n)
res %= MOD
return res
print((main()))
| false | 16.666667 | [
"-import bisect",
"-# from collections import Counter, defaultdict",
"+def LI_():",
"+ return [int(x) - 1 for x in sys.stdin.readline().split()]",
"+",
"+",
"-def I():",
"+def II():",
"-def S():",
"+def SI():",
"-N, M = LI()",
"-A = LI()",
"-B = LI()",
"-A.sort()",
"-B.sort()",
"-SA... | false | 0.035582 | 0.061153 | 0.58186 | [
"s978512182",
"s163917042"
] |
u810356688 | p03166 | python | s678464748 | s190576483 | 632 | 344 | 80,924 | 36,448 | Accepted | Accepted | 45.57 | import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
memo=dict()
def rec(v):
if v in memo:return memo[v]
res=0
for nv in graph[v]:
res=max(res,rec(nv)+1)
memo[v]=res
return res
def main():
n,m=list(map(int,input().split()))
XY=[tuple(map(int,input().split())) for i in range(m)]
global graph
graph=[[]for _ in range(n)]
for x,y in XY:
graph[x-1].append(y-1)
ans=0
for v in range(n):
ans=max(ans,rec(v))
print(ans)
if __name__=='__main__':
main() | import sys
def input(): return sys.stdin.readline().rstrip()
from collections import deque
def main():
n,m=list(map(int,input().split()))
XY=[tuple(map(int,input().split())) for i in range(m)]
graph=[[]for _ in range(n)]
deg=[0]*n #้ ็นiใฎๅ
ฅๆฌกๆฐ
for x,y in XY:
graph[x-1].append(y-1)
deg[y-1]+=1
que=deque()
for v in range(n):
if deg[v]==0:
que.append(v)
dp=[0]*n
while que:
v=que.popleft()
for nv in graph[v]:
deg[nv]-=1
if deg[nv]==0:
que.append(nv)
dp[nv]=max(dp[nv],dp[v]+1)
ans=0
for v in range(n):
ans=max(ans,dp[v])
print(ans)
if __name__=='__main__':
main() | 25 | 30 | 581 | 751 | import sys
def input():
return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
memo = dict()
def rec(v):
if v in memo:
return memo[v]
res = 0
for nv in graph[v]:
res = max(res, rec(nv) + 1)
memo[v] = res
return res
def main():
n, m = list(map(int, input().split()))
XY = [tuple(map(int, input().split())) for i in range(m)]
global graph
graph = [[] for _ in range(n)]
for x, y in XY:
graph[x - 1].append(y - 1)
ans = 0
for v in range(n):
ans = max(ans, rec(v))
print(ans)
if __name__ == "__main__":
main()
| import sys
def input():
return sys.stdin.readline().rstrip()
from collections import deque
def main():
n, m = list(map(int, input().split()))
XY = [tuple(map(int, input().split())) for i in range(m)]
graph = [[] for _ in range(n)]
deg = [0] * n # ้ ็นiใฎๅ
ฅๆฌกๆฐ
for x, y in XY:
graph[x - 1].append(y - 1)
deg[y - 1] += 1
que = deque()
for v in range(n):
if deg[v] == 0:
que.append(v)
dp = [0] * n
while que:
v = que.popleft()
for nv in graph[v]:
deg[nv] -= 1
if deg[nv] == 0:
que.append(nv)
dp[nv] = max(dp[nv], dp[v] + 1)
ans = 0
for v in range(n):
ans = max(ans, dp[v])
print(ans)
if __name__ == "__main__":
main()
| false | 16.666667 | [
"-sys.setrecursionlimit(10**6)",
"-memo = dict()",
"-",
"-",
"-def rec(v):",
"- if v in memo:",
"- return memo[v]",
"- res = 0",
"- for nv in graph[v]:",
"- res = max(res, rec(nv) + 1)",
"- memo[v] = res",
"- return res",
"+from collections import deque",
"- ... | false | 0.037772 | 0.04712 | 0.80163 | [
"s678464748",
"s190576483"
] |
u922003189 | p02690 | python | s040489912 | s330593995 | 140 | 49 | 9,052 | 9,072 | Accepted | Accepted | 65 | x=int(eval(input()))
i=1
flag=0
for i in range(10000):
for j in range(-1000,1001):
if(i**5+j**5==x):
flag=1
print((i,-j))
exit(0)
| x=int(eval(input()))
i=1
flag=0
for i in range(200):
for j in range(-200,200):
if(i**5+j**5==x):
flag=1
print((i,-j))
exit(0)
| 10 | 10 | 183 | 179 | x = int(eval(input()))
i = 1
flag = 0
for i in range(10000):
for j in range(-1000, 1001):
if i**5 + j**5 == x:
flag = 1
print((i, -j))
exit(0)
| x = int(eval(input()))
i = 1
flag = 0
for i in range(200):
for j in range(-200, 200):
if i**5 + j**5 == x:
flag = 1
print((i, -j))
exit(0)
| false | 0 | [
"-for i in range(10000):",
"- for j in range(-1000, 1001):",
"+for i in range(200):",
"+ for j in range(-200, 200):"
] | false | 0.039633 | 0.038235 | 1.036564 | [
"s040489912",
"s330593995"
] |
u419686324 | p03557 | python | s091790077 | s699201957 | 896 | 319 | 121,644 | 23,328 | Accepted | Accepted | 64.4 | import bisect, functools, sys
sys.setrecursionlimit(10**6)
N = int(eval(input()))
A = sorted(int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())
@functools.lru_cache(maxsize=None)
def a(n):
return bisect.bisect_left(A, n)
b_cache = [0] * (N + 1)
b_cached = [False] * (N + 1)
def b_i(i):
global b_cache, b_cached
if i >= 1:
if not b_cached[i - 1]: b_i(i - 1)
t = b_cache[i - 1] + a(B[i - 1])
b_cache[i] = t
b_cached[i] = True
return t
return 0
@functools.lru_cache(maxsize=None)
def b(n):
return b_i(min(N, bisect.bisect_left(B, n)))
def c():
return sum(b(x) for x in C)
print((c())) | N = int(eval(input()))
A = sorted(int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())
import bisect
print((sum(bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b)) for b in B))) | 31 | 7 | 742 | 251 | import bisect, functools, sys
sys.setrecursionlimit(10**6)
N = int(eval(input()))
A = sorted(int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())
@functools.lru_cache(maxsize=None)
def a(n):
return bisect.bisect_left(A, n)
b_cache = [0] * (N + 1)
b_cached = [False] * (N + 1)
def b_i(i):
global b_cache, b_cached
if i >= 1:
if not b_cached[i - 1]:
b_i(i - 1)
t = b_cache[i - 1] + a(B[i - 1])
b_cache[i] = t
b_cached[i] = True
return t
return 0
@functools.lru_cache(maxsize=None)
def b(n):
return b_i(min(N, bisect.bisect_left(B, n)))
def c():
return sum(b(x) for x in C)
print((c()))
| N = int(eval(input()))
A = sorted(int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())
import bisect
print((sum(bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b)) for b in B)))
| false | 77.419355 | [
"-import bisect, functools, sys",
"-",
"-sys.setrecursionlimit(10**6)",
"+import bisect",
"-",
"-@functools.lru_cache(maxsize=None)",
"-def a(n):",
"- return bisect.bisect_left(A, n)",
"-",
"-",
"-b_cache = [0] * (N + 1)",
"-b_cached = [False] * (N + 1)",
"-",
"-",
"-def b_i(i):",
"... | false | 0.04282 | 0.039205 | 1.092211 | [
"s091790077",
"s699201957"
] |
u548303713 | p02959 | python | s944013861 | s150429288 | 162 | 138 | 18,476 | 18,476 | Accepted | Accepted | 14.81 | n = int(eval(input()))
aa = list(map(int, input().split()))
num = sum(aa)
bb = list(map(int, input().split()))
for i in range(n):
c = min(aa[i], bb[i])
aa[i] -= c
aa[i + 1] -= min(aa[i + 1], bb[i] - c)
print((num - sum(aa))) | n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
b.append(0) #n+1็ช็ฎใไฝใฃใจใ
num=0
c=0
for i in range(n):
if a[i]<=c:
num+=a[i]
c=b[i]
else:
a[i]-=c
num+=c
if b[i]>=a[i]:
num+=a[i]
c=b[i]-a[i]
else:
num+=b[i]
c=0
if b[n]+c>=a[n]:
num+=a[n]
else:
num+=b[n]+c
print(num) | 9 | 25 | 236 | 441 | n = int(eval(input()))
aa = list(map(int, input().split()))
num = sum(aa)
bb = list(map(int, input().split()))
for i in range(n):
c = min(aa[i], bb[i])
aa[i] -= c
aa[i + 1] -= min(aa[i + 1], bb[i] - c)
print((num - sum(aa)))
| n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.append(0) # n+1็ช็ฎใไฝใฃใจใ
num = 0
c = 0
for i in range(n):
if a[i] <= c:
num += a[i]
c = b[i]
else:
a[i] -= c
num += c
if b[i] >= a[i]:
num += a[i]
c = b[i] - a[i]
else:
num += b[i]
c = 0
if b[n] + c >= a[n]:
num += a[n]
else:
num += b[n] + c
print(num)
| false | 64 | [
"-aa = list(map(int, input().split()))",
"-num = sum(aa)",
"-bb = list(map(int, input().split()))",
"+a = list(map(int, input().split()))",
"+b = list(map(int, input().split()))",
"+b.append(0) # n+1็ช็ฎใไฝใฃใจใ",
"+num = 0",
"+c = 0",
"- c = min(aa[i], bb[i])",
"- aa[i] -= c",
"- aa[i + 1]... | false | 0.037671 | 0.098318 | 0.383154 | [
"s944013861",
"s150429288"
] |
u276115223 | p03416 | python | s828236128 | s226882667 | 63 | 50 | 2,940 | 2,940 | Accepted | Accepted | 20.63 | # ABC 090: B โ Palindromic Numbers
a, b = [int(s) for s in input().split()]
number_of_parindromics = 0
for i in range(a, b + 1):
if str(i) == str(i)[::-1]:
number_of_parindromics += 1
print(number_of_parindromics) | # ABC 090: B โ Palindromic Numbers
a, b = list(map(int, input().split()))
nums = 0
for i in range(a, b + 1):
i_str = str(i)
nums = nums + 1 if i_str == i_str[::-1] else nums
print(nums) | 9 | 7 | 236 | 193 | # ABC 090: B โ Palindromic Numbers
a, b = [int(s) for s in input().split()]
number_of_parindromics = 0
for i in range(a, b + 1):
if str(i) == str(i)[::-1]:
number_of_parindromics += 1
print(number_of_parindromics)
| # ABC 090: B โ Palindromic Numbers
a, b = list(map(int, input().split()))
nums = 0
for i in range(a, b + 1):
i_str = str(i)
nums = nums + 1 if i_str == i_str[::-1] else nums
print(nums)
| false | 22.222222 | [
"-# ABC 090: B โ Palindromic Numbers",
"-a, b = [int(s) for s in input().split()]",
"-number_of_parindromics = 0",
"+# ABC 090: B โ Palindromic Numbers",
"+a, b = list(map(int, input().split()))",
"+nums = 0",
"- if str(i) == str(i)[::-1]:",
"- number_of_parindromics += 1",
"-print(number... | false | 0.146558 | 0.130817 | 1.12033 | [
"s828236128",
"s226882667"
] |
u707808519 | p03721 | python | s267034368 | s121431322 | 359 | 216 | 29,816 | 11,836 | Accepted | Accepted | 39.83 | import bisect
N, K = list(map(int, input().split()))
A = []; B = [0]
for i in range(N):
a, b = list(map(int, input().split()))
A.append([a, b])
A.sort()
for i in range(N):
B.append(A[i][1] + B[i])
ans = bisect.bisect_left(B, K) - 1
print((A[ans][0])) | N, K = list(map(int, input().split()))
cnt = [0 for _ in range(10**5 + 10)]
for i in range(N):
a, b = list(map(int, input().split()))
cnt[a] += b
res = 0
for i in range(len(cnt)):
res += cnt[i]
if res >= K:
break
print(i) | 14 | 13 | 264 | 247 | import bisect
N, K = list(map(int, input().split()))
A = []
B = [0]
for i in range(N):
a, b = list(map(int, input().split()))
A.append([a, b])
A.sort()
for i in range(N):
B.append(A[i][1] + B[i])
ans = bisect.bisect_left(B, K) - 1
print((A[ans][0]))
| N, K = list(map(int, input().split()))
cnt = [0 for _ in range(10**5 + 10)]
for i in range(N):
a, b = list(map(int, input().split()))
cnt[a] += b
res = 0
for i in range(len(cnt)):
res += cnt[i]
if res >= K:
break
print(i)
| false | 7.142857 | [
"-import bisect",
"-",
"-A = []",
"-B = [0]",
"+cnt = [0 for _ in range(10**5 + 10)]",
"- A.append([a, b])",
"-A.sort()",
"-for i in range(N):",
"- B.append(A[i][1] + B[i])",
"-ans = bisect.bisect_left(B, K) - 1",
"-print((A[ans][0]))",
"+ cnt[a] += b",
"+res = 0",
"+for i in rang... | false | 0.13594 | 0.203371 | 0.668433 | [
"s267034368",
"s121431322"
] |
u729133443 | p03128 | python | s052458892 | s206857872 | 249 | 174 | 51,420 | 14,388 | Accepted | Accepted | 30.12 | n,m,*a=list(map(int,open(0).read().split()))
d=[]
for i,j in((7,3),(9,6),(8,7),(6,6),(5,5),(4,4),(3,5),(1,2),(2,5)):
if i in a:
d.append((i,j))
dp=[0]*-~n
for i in range(1,n+1):
for j,k in d:
if i-k<0 or i-k!=0 and not dp[i-k]:continue
dp[i]=max(dp[i],dp[i-k]*10+j)
print((dp[n])) | n,m,*a=list(map(int,open(0).read().split()))
d=[0]*-~n
for i in range(1,n+1):
for j,k in zip((1,2,3,4,5,6,7,8,9),(2,5,5,4,5,6,3,7,6)):
if j in a and i-k>=0and(i-k<1or d[i-k]):d[i]=max(d[i],d[i-k]*10+j)
print((d[n])) | 11 | 6 | 314 | 215 | n, m, *a = list(map(int, open(0).read().split()))
d = []
for i, j in ((7, 3), (9, 6), (8, 7), (6, 6), (5, 5), (4, 4), (3, 5), (1, 2), (2, 5)):
if i in a:
d.append((i, j))
dp = [0] * -~n
for i in range(1, n + 1):
for j, k in d:
if i - k < 0 or i - k != 0 and not dp[i - k]:
continue
dp[i] = max(dp[i], dp[i - k] * 10 + j)
print((dp[n]))
| n, m, *a = list(map(int, open(0).read().split()))
d = [0] * -~n
for i in range(1, n + 1):
for j, k in zip((1, 2, 3, 4, 5, 6, 7, 8, 9), (2, 5, 5, 4, 5, 6, 3, 7, 6)):
if j in a and i - k >= 0 and (i - k < 1 or d[i - k]):
d[i] = max(d[i], d[i - k] * 10 + j)
print((d[n]))
| false | 45.454545 | [
"-d = []",
"-for i, j in ((7, 3), (9, 6), (8, 7), (6, 6), (5, 5), (4, 4), (3, 5), (1, 2), (2, 5)):",
"- if i in a:",
"- d.append((i, j))",
"-dp = [0] * -~n",
"+d = [0] * -~n",
"- for j, k in d:",
"- if i - k < 0 or i - k != 0 and not dp[i - k]:",
"- continue",
"- ... | false | 0.04209 | 0.089464 | 0.470464 | [
"s052458892",
"s206857872"
] |
u545368057 | p03734 | python | s309643037 | s276546885 | 293 | 266 | 69,212 | 69,556 | Accepted | Accepted | 9.22 | N,W = list(map(int, input().split()))
ws = []
vs = []
for i in range(N):
w,v = list(map(int, input().split()))
ws.append(w)
vs.append(v)
ws_m = [w-ws[0] for w in ws]
"""
i็ช็ฎใพใง่ฆใฆใnๅ้ธใใงใใฆใ้ใใwใฎใจใใฎvใฎๆๅคงๅค
ใใ ใใwใฏNๅ้ธใใ ใจใใซW-N*[w[0]]ใจใชใฃใฆใใใฎใงใใใใmaxใจใใ
dp[i][n][w]
"""
dp = [[[-1]*(3*N+10) for i in range(N+1)] for j in range(N+1)]
dp[0][0][0] = 0
for i,(w,v) in enumerate(zip(ws_m,vs)):
for n in range(i+1):
for j in range(3*N):
dp[i+1][n][j] = max(dp[i+1][n][j], dp[i][n][j])
if dp[i][n][j] == -1: continue
if j + (n+1)*ws[0] + w <= W:
dp[i+1][n+1][j+w] = max(dp[i][n][j+w], dp[i][n][j] + v)
ans= 0
for i,As in enumerate(dp[N]):
w = min(W - i*ws[0], sum(ws_m))
if w >= 0:
ans = max(ans,max(As[:w+1]))
print(ans)
| N,W = list(map(int, input().split()))
ws = []
vs = []
for i in range(N):
w,v = list(map(int, input().split()))
ws.append(w)
vs.append(v)
ws_m = [w-ws[0] for w in ws]
"""
i็ช็ฎใพใง่ฆใฆใnๅ้ธใใงใใฆใ้ใใwใฎใจใใฎvใฎๆๅคงๅค
ใใ ใใwใฏNๅ้ธใใ ใจใใซW-N*[w[0]]ใจใชใฃใฆใใใฎใงใใใใmaxใจใใ
dp[i][n][w]
"""
dp = [[-1]*(3*N+1) for i in range(N+1)]
dp[0][0] = 0
for i,(w,v) in enumerate(zip(ws_m,vs)):
dp[i+1][:] = dp[i][:]
for j in range(len(dp[i])):
if dp[i][j] == -1:continue
dp[i+1][j+w] = max(dp[i][j]+v, dp[i][j+w])
# print(dp)
# print(dp[N][W-N*ws_m[0]])
dp = [[[-1]*(3*N+1) for i in range(N+1)] for j in range(N+1)]
dp[0][0][0] = 0
for i,(w,v) in enumerate(zip(ws_m,vs)):
# print(i,w,v)
for n in range(N):
# dp[i+1][n][:] = dp[i][n][:]
for j in range(N):
if dp[i][n][j] == -1:continue
if dp[i][n][j]+v >= dp[i][n][j+w]:
# print("aa",i,n,j,v)
dp[i+1][n+1][j+w] = dp[i][n][j] + v
else:
dp[i+1][n][j+w] = dp[i][n][j+w]
dp[i+1][n][j] = max(dp[i+1][n][j], dp[i][n][j])
# print(dp[i])
# for i in range(N+1):
# print("iๅ้ธใใ ใใค",dp[N][i])
anss = dp[N]
a = 0
for i,ans in enumerate(anss):
w = W - i*ws[0]
if w >= 0:
a = max(a,max(ans[:w+1]))
print(a)
| 30 | 50 | 820 | 1,334 | N, W = list(map(int, input().split()))
ws = []
vs = []
for i in range(N):
w, v = list(map(int, input().split()))
ws.append(w)
vs.append(v)
ws_m = [w - ws[0] for w in ws]
"""
i็ช็ฎใพใง่ฆใฆใnๅ้ธใใงใใฆใ้ใใwใฎใจใใฎvใฎๆๅคงๅค
ใใ ใใwใฏNๅ้ธใใ ใจใใซW-N*[w[0]]ใจใชใฃใฆใใใฎใงใใใใmaxใจใใ
dp[i][n][w]
"""
dp = [[[-1] * (3 * N + 10) for i in range(N + 1)] for j in range(N + 1)]
dp[0][0][0] = 0
for i, (w, v) in enumerate(zip(ws_m, vs)):
for n in range(i + 1):
for j in range(3 * N):
dp[i + 1][n][j] = max(dp[i + 1][n][j], dp[i][n][j])
if dp[i][n][j] == -1:
continue
if j + (n + 1) * ws[0] + w <= W:
dp[i + 1][n + 1][j + w] = max(dp[i][n][j + w], dp[i][n][j] + v)
ans = 0
for i, As in enumerate(dp[N]):
w = min(W - i * ws[0], sum(ws_m))
if w >= 0:
ans = max(ans, max(As[: w + 1]))
print(ans)
| N, W = list(map(int, input().split()))
ws = []
vs = []
for i in range(N):
w, v = list(map(int, input().split()))
ws.append(w)
vs.append(v)
ws_m = [w - ws[0] for w in ws]
"""
i็ช็ฎใพใง่ฆใฆใnๅ้ธใใงใใฆใ้ใใwใฎใจใใฎvใฎๆๅคงๅค
ใใ ใใwใฏNๅ้ธใใ ใจใใซW-N*[w[0]]ใจใชใฃใฆใใใฎใงใใใใmaxใจใใ
dp[i][n][w]
"""
dp = [[-1] * (3 * N + 1) for i in range(N + 1)]
dp[0][0] = 0
for i, (w, v) in enumerate(zip(ws_m, vs)):
dp[i + 1][:] = dp[i][:]
for j in range(len(dp[i])):
if dp[i][j] == -1:
continue
dp[i + 1][j + w] = max(dp[i][j] + v, dp[i][j + w])
# print(dp)
# print(dp[N][W-N*ws_m[0]])
dp = [[[-1] * (3 * N + 1) for i in range(N + 1)] for j in range(N + 1)]
dp[0][0][0] = 0
for i, (w, v) in enumerate(zip(ws_m, vs)):
# print(i,w,v)
for n in range(N):
# dp[i+1][n][:] = dp[i][n][:]
for j in range(N):
if dp[i][n][j] == -1:
continue
if dp[i][n][j] + v >= dp[i][n][j + w]:
# print("aa",i,n,j,v)
dp[i + 1][n + 1][j + w] = dp[i][n][j] + v
else:
dp[i + 1][n][j + w] = dp[i][n][j + w]
dp[i + 1][n][j] = max(dp[i + 1][n][j], dp[i][n][j])
# print(dp[i])
# for i in range(N+1):
# print("iๅ้ธใใ ใใค",dp[N][i])
anss = dp[N]
a = 0
for i, ans in enumerate(anss):
w = W - i * ws[0]
if w >= 0:
a = max(a, max(ans[: w + 1]))
print(a)
| false | 40 | [
"-dp = [[[-1] * (3 * N + 10) for i in range(N + 1)] for j in range(N + 1)]",
"+dp = [[-1] * (3 * N + 1) for i in range(N + 1)]",
"+dp[0][0] = 0",
"+for i, (w, v) in enumerate(zip(ws_m, vs)):",
"+ dp[i + 1][:] = dp[i][:]",
"+ for j in range(len(dp[i])):",
"+ if dp[i][j] == -1:",
"+ ... | false | 0.118788 | 0.119282 | 0.995862 | [
"s309643037",
"s276546885"
] |
u588341295 | p03127 | python | s505974400 | s905585598 | 137 | 82 | 16,888 | 16,828 | Accepted | Accepted | 40.15 | # -*- coding: utf-8 -*-
import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
A.sort()
mn = A[0]
i = 1
while i < N and mn > 1:
div = A[i] % mn
if div != 0 and mn > div:
mn = div
i = 0
else:
i += 1
print(mn)
| # -*- coding: utf-8 -*-
"""
ๅ่๏ผhttps://img.atcoder.jp/abc118/editorial.pdf
"""
import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
print((gcd_list(A)))
| 46 | 40 | 1,520 | 1,424 | # -*- coding: utf-8 -*-
import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5:
from math import gcd
else:
from fractions import gcd
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def round(x):
return int((x * 2 + 1) // 2)
def fermat(x, y, MOD):
return x * pow(y, MOD - 2, MOD) % MOD
def lcm(x, y):
return (x * y) // gcd(x, y)
def lcm_list(nums):
return reduce(lcm, nums, 1)
def gcd_list(nums):
return reduce(gcd, nums, nums[0])
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
N = INT()
A = LIST()
A.sort()
mn = A[0]
i = 1
while i < N and mn > 1:
div = A[i] % mn
if div != 0 and mn > div:
mn = div
i = 0
else:
i += 1
print(mn)
| # -*- coding: utf-8 -*-
"""
ๅ่๏ผhttps://img.atcoder.jp/abc118/editorial.pdf
"""
import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5:
from math import gcd
else:
from fractions import gcd
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def round(x):
return int((x * 2 + 1) // 2)
def fermat(x, y, MOD):
return x * pow(y, MOD - 2, MOD) % MOD
def lcm(x, y):
return (x * y) // gcd(x, y)
def lcm_list(nums):
return reduce(lcm, nums, 1)
def gcd_list(nums):
return reduce(gcd, nums, nums[0])
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
N = INT()
A = LIST()
print((gcd_list(A)))
| false | 13.043478 | [
"+\"\"\"",
"+ๅ่๏ผhttps://img.atcoder.jp/abc118/editorial.pdf",
"+\"\"\"",
"-A.sort()",
"-mn = A[0]",
"-i = 1",
"-while i < N and mn > 1:",
"- div = A[i] % mn",
"- if div != 0 and mn > div:",
"- mn = div",
"- i = 0",
"- else:",
"- i += 1",
"-print(mn)",
"+prin... | false | 0.038736 | 0.039504 | 0.980557 | [
"s505974400",
"s905585598"
] |
u759412327 | p03352 | python | s435242717 | s272142774 | 19 | 17 | 3,316 | 2,940 | Accepted | Accepted | 10.53 | X = int(eval(input()))
se = set(n**e for n in range(32) for e in range(2,11) if n**e <= X)
answer = max(se)
print(answer)
| X = int(eval(input()))
S = set(n**e for n in range(32) for e in range(2,11) if n**e<=X)
print((max(S)))
| 5 | 3 | 121 | 98 | X = int(eval(input()))
se = set(n**e for n in range(32) for e in range(2, 11) if n ** e <= X)
answer = max(se)
print(answer)
| X = int(eval(input()))
S = set(n**e for n in range(32) for e in range(2, 11) if n ** e <= X)
print((max(S)))
| false | 40 | [
"-se = set(n**e for n in range(32) for e in range(2, 11) if n ** e <= X)",
"-answer = max(se)",
"-print(answer)",
"+S = set(n**e for n in range(32) for e in range(2, 11) if n ** e <= X)",
"+print((max(S)))"
] | false | 0.049823 | 0.049073 | 1.015281 | [
"s435242717",
"s272142774"
] |
u902462889 | p04045 | python | s900578878 | s533181072 | 593 | 210 | 3,064 | 3,064 | Accepted | Accepted | 64.59 |
lst_1 = input().split()
N = lst_1[0]
K = int(lst_1[1])
lst_N = list(N)
lst_hate = input().split()
flg = True
while 1:
for i in range(len(lst_N)):
for j in range(len(lst_hate)):
if lst_N[i] == lst_hate[j]:
flg = False
break
if flg == True:
break
N = ''.join(lst_N)
N = int(N)
N += 1
lst_N = list(str(N))
flg = True
N = ''.join(lst_N)
print(N) | N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
k = N
"""while k > 0:
lst.append(k % 10)
k //= 10
#lst.reverse()"""
#print(lst)
while 1:
flg = True
lst = []
N = k
while k > 0:
lst.append(k % 10)
k //= 10
lst.reverse()
# print(lst)
for i in range(len(lst)):
if lst[i] in D:
flg = False
break
if flg == False:
k = N
k += 1
else:
break
print(N)
| 34 | 29 | 475 | 509 | lst_1 = input().split()
N = lst_1[0]
K = int(lst_1[1])
lst_N = list(N)
lst_hate = input().split()
flg = True
while 1:
for i in range(len(lst_N)):
for j in range(len(lst_hate)):
if lst_N[i] == lst_hate[j]:
flg = False
break
if flg == True:
break
N = "".join(lst_N)
N = int(N)
N += 1
lst_N = list(str(N))
flg = True
N = "".join(lst_N)
print(N)
| N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
k = N
"""while k > 0:
lst.append(k % 10)
k //= 10
#lst.reverse()"""
# print(lst)
while 1:
flg = True
lst = []
N = k
while k > 0:
lst.append(k % 10)
k //= 10
lst.reverse()
# print(lst)
for i in range(len(lst)):
if lst[i] in D:
flg = False
break
if flg == False:
k = N
k += 1
else:
break
print(N)
| false | 14.705882 | [
"-lst_1 = input().split()",
"-N = lst_1[0]",
"-K = int(lst_1[1])",
"-lst_N = list(N)",
"-lst_hate = input().split()",
"-flg = True",
"+N, K = list(map(int, input().split()))",
"+D = list(map(int, input().split()))",
"+k = N",
"+\"\"\"while k > 0:",
"+ lst.append(k % 10)",
"+ k //= 10",
... | false | 0.044715 | 0.033857 | 1.320707 | [
"s900578878",
"s533181072"
] |
u075012704 | p03151 | python | s356173838 | s670302349 | 391 | 253 | 97,712 | 21,552 | Accepted | Accepted | 35.29 | N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_origin = A[:]
if sum(A) < sum(B):
print((-1))
exit()
diff = [[i, a - b] for i, a, b in zip(list(range(N)), A, B)]
order = sorted([[i, x] for i, x in diff if x > 0], key=lambda d: d[1])
C = []
charge = order.pop()
for i in range(N):
while A[i] - B[i] < 0:
if charge[1] > B[i] - A[i]:
A[charge[0]] -= (B[i] - A[i])
charge[1] -= (B[i] - A[i])
A[i] = B[i]
else:
A[charge[0]] = B[charge[0]]
A[i] += charge[1]
charge = order.pop()
ans = 0
for a, ao in zip(A, A_origin):
if a != ao:
ans += 1
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# ๅใในใใฎไฝ่ฃใๅฐใใ้ ใซ
margins = [[i, a - b] for i, (a, b) in enumerate(zip(A, B)) if (a - b) > 0]
margins.sort(key=lambda m: m[1])
# ่ชฟๆดๆธใฟA
X = A[:]
# ไฝ่ฃใๅคงใใๆนใใไฝฟใฃใฆใใ
for i in range(N):
while (A[i] < B[i]) and margins:
cost = B[i] - A[i]
mi, margin = margins[-1]
if margin > cost:
margins[-1][1] -= cost
A[mi] -= cost
A[i] += cost
else:
margins.pop()
A[mi] -= margin
A[i] += margin
ans = 0
for a, b, x in zip(A, B, X):
if b - a > 0:
print((-1))
break
if a != x:
ans += 1
else:
print(ans)
| 33 | 39 | 730 | 758 | N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_origin = A[:]
if sum(A) < sum(B):
print((-1))
exit()
diff = [[i, a - b] for i, a, b in zip(list(range(N)), A, B)]
order = sorted([[i, x] for i, x in diff if x > 0], key=lambda d: d[1])
C = []
charge = order.pop()
for i in range(N):
while A[i] - B[i] < 0:
if charge[1] > B[i] - A[i]:
A[charge[0]] -= B[i] - A[i]
charge[1] -= B[i] - A[i]
A[i] = B[i]
else:
A[charge[0]] = B[charge[0]]
A[i] += charge[1]
charge = order.pop()
ans = 0
for a, ao in zip(A, A_origin):
if a != ao:
ans += 1
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# ๅใในใใฎไฝ่ฃใๅฐใใ้ ใซ
margins = [[i, a - b] for i, (a, b) in enumerate(zip(A, B)) if (a - b) > 0]
margins.sort(key=lambda m: m[1])
# ่ชฟๆดๆธใฟA
X = A[:]
# ไฝ่ฃใๅคงใใๆนใใไฝฟใฃใฆใใ
for i in range(N):
while (A[i] < B[i]) and margins:
cost = B[i] - A[i]
mi, margin = margins[-1]
if margin > cost:
margins[-1][1] -= cost
A[mi] -= cost
A[i] += cost
else:
margins.pop()
A[mi] -= margin
A[i] += margin
ans = 0
for a, b, x in zip(A, B, X):
if b - a > 0:
print((-1))
break
if a != x:
ans += 1
else:
print(ans)
| false | 15.384615 | [
"-A_origin = A[:]",
"-if sum(A) < sum(B):",
"- print((-1))",
"- exit()",
"-diff = [[i, a - b] for i, a, b in zip(list(range(N)), A, B)]",
"-order = sorted([[i, x] for i, x in diff if x > 0], key=lambda d: d[1])",
"-C = []",
"-charge = order.pop()",
"+# ๅใในใใฎไฝ่ฃใๅฐใใ้ ใซ",
"+margins = [[i, a - b]... | false | 0.036706 | 0.037286 | 0.984457 | [
"s356173838",
"s670302349"
] |
u150984829 | p02258 | python | s830552941 | s848838403 | 180 | 120 | 19,840 | 5,640 | Accepted | Accepted | 33.33 | import sys
b,s=-1e10,1e10
eval(input())
for r in map(int,sys.stdin.readlines()):
b,s=(b,r-s)[b<r-s],(s,r)[s>r]
print(b)
| import sys
b,s=-1e10,1e10
eval(input())
for r in map(int,sys.stdin):
if b<r-s:b=r-s
if s>r:s=r
print(b)
| 6 | 7 | 120 | 106 | import sys
b, s = -1e10, 1e10
eval(input())
for r in map(int, sys.stdin.readlines()):
b, s = (b, r - s)[b < r - s], (s, r)[s > r]
print(b)
| import sys
b, s = -1e10, 1e10
eval(input())
for r in map(int, sys.stdin):
if b < r - s:
b = r - s
if s > r:
s = r
print(b)
| false | 14.285714 | [
"-for r in map(int, sys.stdin.readlines()):",
"- b, s = (b, r - s)[b < r - s], (s, r)[s > r]",
"+for r in map(int, sys.stdin):",
"+ if b < r - s:",
"+ b = r - s",
"+ if s > r:",
"+ s = r"
] | false | 0.037751 | 0.036637 | 1.030397 | [
"s830552941",
"s848838403"
] |
u678167152 | p03361 | python | s217263295 | s997484610 | 196 | 29 | 39,280 | 9,236 | Accepted | Accepted | 85.2 | def check():
H, W = list(map(int, input().split()))
S = [0]*(H+2)
S[0] = '.'*(W+2)
S[H+1] = '.'*(W+2)
dh = [0,1,0,-1]
dw = [1,0,-1,0]
for h in range(1,H+1):
S[h] = '.' + eval(input()) + '.'
for h in range(H):
for w in range(W):
if S[h][w]=='#':
for i in range(4):
if S[h+dh[i]][w+dw[i]]=='#':
break
else:
return 'No'
return 'Yes'
print((check())) | def check():
H, W = list(map(int, input().split()))
S = [0]*(H+2)
S[0] = '.'*(W+2)
S[H+1] = '.'*(W+2)
for h in range(1,H+1):
S[h] = '.' + eval(input()) + '.'
dh = [0,1,0,-1]
dw = [1,0,-1,0]
for h in range(1,H+1):
for w in range(1,W+1):
if S[h][w]=='.':
continue
for i in range(4):
h0 = h+dh[i]
w0 = w+dw[i]
if S[h0][w0]=='#':
break
else:
return 'No'
return 'Yes'
print((check())) | 19 | 25 | 510 | 592 | def check():
H, W = list(map(int, input().split()))
S = [0] * (H + 2)
S[0] = "." * (W + 2)
S[H + 1] = "." * (W + 2)
dh = [0, 1, 0, -1]
dw = [1, 0, -1, 0]
for h in range(1, H + 1):
S[h] = "." + eval(input()) + "."
for h in range(H):
for w in range(W):
if S[h][w] == "#":
for i in range(4):
if S[h + dh[i]][w + dw[i]] == "#":
break
else:
return "No"
return "Yes"
print((check()))
| def check():
H, W = list(map(int, input().split()))
S = [0] * (H + 2)
S[0] = "." * (W + 2)
S[H + 1] = "." * (W + 2)
for h in range(1, H + 1):
S[h] = "." + eval(input()) + "."
dh = [0, 1, 0, -1]
dw = [1, 0, -1, 0]
for h in range(1, H + 1):
for w in range(1, W + 1):
if S[h][w] == ".":
continue
for i in range(4):
h0 = h + dh[i]
w0 = w + dw[i]
if S[h0][w0] == "#":
break
else:
return "No"
return "Yes"
print((check()))
| false | 24 | [
"+ for h in range(1, H + 1):",
"+ S[h] = \".\" + eval(input()) + \".\"",
"- S[h] = \".\" + eval(input()) + \".\"",
"- for h in range(H):",
"- for w in range(W):",
"- if S[h][w] == \"#\":",
"- for i in range(4):",
"- if S[h + dh[i]... | false | 0.055386 | 0.036963 | 1.498417 | [
"s217263295",
"s997484610"
] |
u774729733 | p02954 | python | s831665331 | s226329713 | 403 | 345 | 83,544 | 77,964 | Accepted | Accepted | 14.39 | from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
import logging
import heapq
logging.basicConfig(level=logging.DEBUG)
input = sys.stdin.readline
setrecursionlimit(1000000)
def main():
S=eval(input())
mode="L"
start=0
base=0
end=0
group=[]
for i in range(len(S)):
s=S[i]
if mode=="L" and s==mode:
mode="R"
base=i-1
elif mode=="R" and s==mode:
mode="L"
end=i-1
group.append((start,base,end))
start=i
elif s=="\n":
end=i-1
group.append((start,base,end))
# print(group)
A=[0 for _ in range(len(S)-1)]
for g in group:
s=g[0]
b=g[1]
e=g[2]
l=e-s+1
if l//2==0:
A[b]=A[b+1]=l/2
else:
A[b]=(b-s)//2+(e-b)//2+1
A[b+1]=l-A[b]
print((*A))
main() | from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
import logging
import heapq
logging.basicConfig(level=logging.DEBUG)
input = sys.stdin.readline
setrecursionlimit(1000000)
def main():
S=eval(input())
A=[0 for _ in range(len(S)-1)]
mode="L"
s=0
b=0
e=0
l=0
for i in range(len(S)):
c=S[i]
if mode=="L" and c==mode:
mode="R"
b=i-1
elif mode=="R" and c==mode:
mode="L"
e=i-1
calc(A,s,b,e)
s=i
elif c=="\n":
e=i-1
calc(A,s,b,e)
print((*A))
def calc(A, s, b, e):
l=e-s+1
if l//2==0:
A[b]=A[b+1]=l/2
else:
A[b]=(b-s)//2+(e-b)//2+1
A[b+1]=l-A[b]
main() | 53 | 51 | 1,086 | 949 | from copy import deepcopy
from sys import exit, setrecursionlimit
import math
from collections import defaultdict, Counter, deque
from fractions import Fraction as frac
import bisect
import sys
import logging
import heapq
logging.basicConfig(level=logging.DEBUG)
input = sys.stdin.readline
setrecursionlimit(1000000)
def main():
S = eval(input())
mode = "L"
start = 0
base = 0
end = 0
group = []
for i in range(len(S)):
s = S[i]
if mode == "L" and s == mode:
mode = "R"
base = i - 1
elif mode == "R" and s == mode:
mode = "L"
end = i - 1
group.append((start, base, end))
start = i
elif s == "\n":
end = i - 1
group.append((start, base, end))
# print(group)
A = [0 for _ in range(len(S) - 1)]
for g in group:
s = g[0]
b = g[1]
e = g[2]
l = e - s + 1
if l // 2 == 0:
A[b] = A[b + 1] = l / 2
else:
A[b] = (b - s) // 2 + (e - b) // 2 + 1
A[b + 1] = l - A[b]
print((*A))
main()
| from copy import deepcopy
from sys import exit, setrecursionlimit
import math
from collections import defaultdict, Counter, deque
from fractions import Fraction as frac
import bisect
import sys
import logging
import heapq
logging.basicConfig(level=logging.DEBUG)
input = sys.stdin.readline
setrecursionlimit(1000000)
def main():
S = eval(input())
A = [0 for _ in range(len(S) - 1)]
mode = "L"
s = 0
b = 0
e = 0
l = 0
for i in range(len(S)):
c = S[i]
if mode == "L" and c == mode:
mode = "R"
b = i - 1
elif mode == "R" and c == mode:
mode = "L"
e = i - 1
calc(A, s, b, e)
s = i
elif c == "\n":
e = i - 1
calc(A, s, b, e)
print((*A))
def calc(A, s, b, e):
l = e - s + 1
if l // 2 == 0:
A[b] = A[b + 1] = l / 2
else:
A[b] = (b - s) // 2 + (e - b) // 2 + 1
A[b + 1] = l - A[b]
main()
| false | 3.773585 | [
"+ A = [0 for _ in range(len(S) - 1)]",
"- start = 0",
"- base = 0",
"- end = 0",
"- group = []",
"+ s = 0",
"+ b = 0",
"+ e = 0",
"+ l = 0",
"- s = S[i]",
"- if mode == \"L\" and s == mode:",
"+ c = S[i]",
"+ if mode == \"L\" and c == m... | false | 0.150456 | 0.061134 | 2.461084 | [
"s831665331",
"s226329713"
] |
u935558307 | p03682 | python | s701707969 | s752711479 | 1,875 | 1,617 | 124,836 | 134,820 | Accepted | Accepted | 13.76 | class UnionFind():
def __init__(self,n):
self.n=n
self.parents = [i for i in range(n+1)]
self.size = [1]*(n+1)
def find(self,x):
if self.parents[x]==x:
return x
else:
self.parents[x]=self.find(self.parents[x])
return self.parents[x]
def unite(self,x,y):
xRoot = self.find(x)
yRoot = self.find(y)
if xRoot == yRoot:
return
if self.size[xRoot]>self.size[yRoot]:
self.parents[yRoot] = xRoot
else:
self.parents[xRoot] = yRoot
if self.size[xRoot] == self.size[yRoot]:
self.size[yRoot]+=1
N = int(eval(input()))
edges = []
nodes = []
for i in range(N):
x,y = list(map(int,input().split()))
nodes.append((i,x,y))
nodes.sort(key=lambda x: x[1])
for i in range(1,N):
w = nodes[i][1]-nodes[i-1][1]
edges.append((w,nodes[i][0],nodes[i-1][0]))
nodes.sort(key=lambda x: x[2])
for i in range(1,N):
w = nodes[i][2] - nodes[i-1][2]
edges.append((w,nodes[i][0],nodes[i-1][0]))
edges.sort()
tree = UnionFind(N)
cost = 0
for w,a,b in edges:
if tree.find(a) != tree.find(b):
tree.unite(a,b)
cost += w
print(cost) | class UnionFind():
def __init__(self,n):
self.n=n
self.parents = [i for i in range(n+1)]
self.size = [1]*(n+1)
def find(self,x):
if self.parents[x]==x:
return x
else:
self.parents[x]=self.find(self.parents[x])
return self.parents[x]
def unite(self,x,y):
xRoot = self.find(x)
yRoot = self.find(y)
if xRoot == yRoot:
return
if self.size[xRoot]>self.size[yRoot]:
self.parents[yRoot] = xRoot
self.size[xRoot] += self.size[yRoot]
self.size[yRoot] = 0
else:
self.parents[xRoot] = yRoot
self.size[yRoot] += self.size[xRoot]
self.size[xRoot] = 0
N = int(eval(input()))
XY = [[i]+list(map(int,input().split())) for i in range(N)]
edges = []
XY.sort(key=lambda x: x[1])
for j in range(1,N):
edges.append((XY[j-1][0],XY[j][0],XY[j][1]-XY[j-1][1]))
XY.sort(key=lambda x: x[2])
for j in range(1,N):
edges.append((XY[j-1][0],XY[j][0],XY[j][2]-XY[j-1][2]))
cost = 0
edges.sort(key=lambda x: x[2])
tree = UnionFind(N)
for i,j,c in edges:
if tree.find(i)!=tree.find(j):
tree.unite(i,j)
cost += c
print(cost) | 45 | 44 | 1,261 | 1,270 | class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [i for i in range(n + 1)]
self.size = [1] * (n + 1)
def find(self, x):
if self.parents[x] == x:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def unite(self, x, y):
xRoot = self.find(x)
yRoot = self.find(y)
if xRoot == yRoot:
return
if self.size[xRoot] > self.size[yRoot]:
self.parents[yRoot] = xRoot
else:
self.parents[xRoot] = yRoot
if self.size[xRoot] == self.size[yRoot]:
self.size[yRoot] += 1
N = int(eval(input()))
edges = []
nodes = []
for i in range(N):
x, y = list(map(int, input().split()))
nodes.append((i, x, y))
nodes.sort(key=lambda x: x[1])
for i in range(1, N):
w = nodes[i][1] - nodes[i - 1][1]
edges.append((w, nodes[i][0], nodes[i - 1][0]))
nodes.sort(key=lambda x: x[2])
for i in range(1, N):
w = nodes[i][2] - nodes[i - 1][2]
edges.append((w, nodes[i][0], nodes[i - 1][0]))
edges.sort()
tree = UnionFind(N)
cost = 0
for w, a, b in edges:
if tree.find(a) != tree.find(b):
tree.unite(a, b)
cost += w
print(cost)
| class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [i for i in range(n + 1)]
self.size = [1] * (n + 1)
def find(self, x):
if self.parents[x] == x:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def unite(self, x, y):
xRoot = self.find(x)
yRoot = self.find(y)
if xRoot == yRoot:
return
if self.size[xRoot] > self.size[yRoot]:
self.parents[yRoot] = xRoot
self.size[xRoot] += self.size[yRoot]
self.size[yRoot] = 0
else:
self.parents[xRoot] = yRoot
self.size[yRoot] += self.size[xRoot]
self.size[xRoot] = 0
N = int(eval(input()))
XY = [[i] + list(map(int, input().split())) for i in range(N)]
edges = []
XY.sort(key=lambda x: x[1])
for j in range(1, N):
edges.append((XY[j - 1][0], XY[j][0], XY[j][1] - XY[j - 1][1]))
XY.sort(key=lambda x: x[2])
for j in range(1, N):
edges.append((XY[j - 1][0], XY[j][0], XY[j][2] - XY[j - 1][2]))
cost = 0
edges.sort(key=lambda x: x[2])
tree = UnionFind(N)
for i, j, c in edges:
if tree.find(i) != tree.find(j):
tree.unite(i, j)
cost += c
print(cost)
| false | 2.222222 | [
"+ self.size[xRoot] += self.size[yRoot]",
"+ self.size[yRoot] = 0",
"- if self.size[xRoot] == self.size[yRoot]:",
"- self.size[yRoot] += 1",
"+ self.size[yRoot] += self.size[xRoot]",
"+ self.size[xRoot] = 0",
"+XY = [[i] + list(map(in... | false | 0.195127 | 0.105219 | 1.854484 | [
"s701707969",
"s752711479"
] |
u729133443 | p03075 | python | s183338623 | s900213012 | 165 | 17 | 38,256 | 2,940 | Accepted | Accepted | 89.7 | a,*_,e,k=eval('int(input()),'*6);print(('Y:a(y !'[e-a>k::2])) | a,*_,e,k=list(map(int,open(0)));print(('Y:a(y !'[e-a>k::2])) | 1 | 1 | 59 | 52 | a, *_, e, k = eval("int(input())," * 6)
print(("Y:a(y !"[e - a > k :: 2]))
| a, *_, e, k = list(map(int, open(0)))
print(("Y:a(y !"[e - a > k :: 2]))
| false | 0 | [
"-a, *_, e, k = eval(\"int(input()),\" * 6)",
"+a, *_, e, k = list(map(int, open(0)))"
] | false | 0.041785 | 0.034743 | 1.20268 | [
"s183338623",
"s900213012"
] |
u588341295 | p04013 | python | s739803038 | s702912610 | 315 | 187 | 92,252 | 5,236 | Accepted | Accepted | 40.63 | # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N, K = MAP()
A = LIST()
MAX = N * K
# dp[i][j][k] := iๆ็ฎใพใงใใjๆๅใฃใฆใๅ่จใkใซใใ้ใๆฐ
dp = list3d(N+1, N+1, MAX+1, 0)
dp[0][0][0] = 1
for i in range(N):
a = A[i]
for j in range(i+1):
for k in range(MAX+1):
dp[i+1][j][k] += dp[i][j][k]
if j+1 <= N and k+a <= MAX:
dp[i+1][j+1][k+a] += dp[i][j][k]
ans = 0
for j in range(1, N+1):
# 1ๆไปฅไธๅใฃใๆใฎใๅนณๅใKใซใชใๆ โ jๆๅใฃใฆๅ่จใj*Kใฎๆ ใๅ่จใใ
ans += dp[N][j][j*K]
print(ans)
| # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N, K = MAP()
# ไบใ-Kใใ็ถๆ
ใง็จๆใใฆใใ
A = [a-K for a in LIST()]
MAX = N * K * 2
# dp[i][k] := iๆ็ฎใพใงใฎใซใผใใงใๅ่จใkใซใใ้ใๆฐ
dp = list2d(N+1, MAX+1, 0)
# ่ฒ ใฎๆฐใ่ๆ
ฎใใฆใN*Kไฝ็ฝฎใ0ใจใใ
dp[0][N*K] = 1
for i in range(N):
a = A[i]
for k in range(MAX+1):
dp[i+1][k] += dp[i][k]
if 0 <= k+a <= MAX:
dp[i+1][k+a] += dp[i][k]
# Nๅ็ตใใฃใฆๅ่จใ0ใซใชใฃใฆใใ้ใๆฐ - 1ๆใๅใใชใใฑใผใน
print((dp[N][N*K]-1))
| 39 | 37 | 1,174 | 1,097 | # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
N, K = MAP()
A = LIST()
MAX = N * K
# dp[i][j][k] := iๆ็ฎใพใงใใjๆๅใฃใฆใๅ่จใkใซใใ้ใๆฐ
dp = list3d(N + 1, N + 1, MAX + 1, 0)
dp[0][0][0] = 1
for i in range(N):
a = A[i]
for j in range(i + 1):
for k in range(MAX + 1):
dp[i + 1][j][k] += dp[i][j][k]
if j + 1 <= N and k + a <= MAX:
dp[i + 1][j + 1][k + a] += dp[i][j][k]
ans = 0
for j in range(1, N + 1):
# 1ๆไปฅไธๅใฃใๆใฎใๅนณๅใKใซใชใๆ โ jๆๅใฃใฆๅ่จใj*Kใฎๆ ใๅ่จใใ
ans += dp[N][j][j * K]
print(ans)
| # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
N, K = MAP()
# ไบใ-Kใใ็ถๆ
ใง็จๆใใฆใใ
A = [a - K for a in LIST()]
MAX = N * K * 2
# dp[i][k] := iๆ็ฎใพใงใฎใซใผใใงใๅ่จใkใซใใ้ใๆฐ
dp = list2d(N + 1, MAX + 1, 0)
# ่ฒ ใฎๆฐใ่ๆ
ฎใใฆใN*Kไฝ็ฝฎใ0ใจใใ
dp[0][N * K] = 1
for i in range(N):
a = A[i]
for k in range(MAX + 1):
dp[i + 1][k] += dp[i][k]
if 0 <= k + a <= MAX:
dp[i + 1][k + a] += dp[i][k]
# Nๅ็ตใใฃใฆๅ่จใ0ใซใชใฃใฆใใ้ใๆฐ - 1ๆใๅใใชใใฑใผใน
print((dp[N][N * K] - 1))
| false | 5.128205 | [
"-A = LIST()",
"-MAX = N * K",
"-# dp[i][j][k] := iๆ็ฎใพใงใใjๆๅใฃใฆใๅ่จใkใซใใ้ใๆฐ",
"-dp = list3d(N + 1, N + 1, MAX + 1, 0)",
"-dp[0][0][0] = 1",
"+# ไบใ-Kใใ็ถๆ
ใง็จๆใใฆใใ",
"+A = [a - K for a in LIST()]",
"+MAX = N * K * 2",
"+# dp[i][k] := iๆ็ฎใพใงใฎใซใผใใงใๅ่จใkใซใใ้ใๆฐ",
"+dp = list2d(N + 1, MAX + 1, 0)",
"+# ่ฒ ใฎๆฐใ่... | false | 0.041233 | 0.03974 | 1.03757 | [
"s739803038",
"s702912610"
] |
u819048695 | p02889 | python | s443483729 | s985692002 | 1,857 | 1,042 | 125,404 | 72,284 | Accepted | Accepted | 43.89 | def warshal(data):
for k in range(n):
for i in range(n):
for j in range(n):
data[i][j]=min(data[i][j],data[i][k]+data[k][j])
return data
n,m,l=list(map(int,input().split()))
inf=float("inf")
data=[[inf]*n for i in range(n)]
for i in range(m):
a,b,c=list(map(int,input().split()))
data[a-1][b-1]=c
data[b-1][a-1]=c
for i in range(n):
data[i][i]=0
data=warshal(data)
for i in range(n):
for j in range(n):
if data[i][j]<=l:
data[i][j]=1
else:
data[i][j]=inf
for i in range(n):
data[i][i]=0
data=warshal(data)
q=int(eval(input()))
st=[]
for i in range(q):
s,t=list(map(int,input().split()))
st.append([s-1,t-1])
for s,t in st:
if data[s][t]==inf:
print((-1))
else:
print((data[s][t]-1)) | import sys
input=sys.stdin.readline
def Warshall_Floyd(N,DIST):
for k in range(N):
for i in range(N):
for j in range(N):
DIST[i][j]=min(DIST[i][j],DIST[i][k]+DIST[k][j])
return DIST
N,M,L=list(map(int,input().split()))
ABC=[list(map(int,input().split())) for i in range(M)]
Q=int(eval(input()))
st=[list(map(int,input().split())) for i in range(Q)]
inf=L+1
dist=[[inf]*N for i in range(N)]
for i in range(N):
dist[i][i]=0
for A,B,C in ABC:
dist[A-1][B-1]=min(dist[A-1][B-1],C)
dist[B-1][A-1]=min(dist[B-1][A-1],C)
dist=Warshall_Floyd(N,dist)
dist_2=[[N+1]*N for i in range(N)]
for i in range(N):
for j in range(N):
if dist[i][j]<=L:
dist_2[i][j]=1
for i in range(N):
dist_2[i][i]=0
dist_2=Warshall_Floyd(N,dist_2)
for s,t in st:
if dist_2[s-1][t-1]==N+1:
print((-1))
else:
print((dist_2[s-1][t-1]-1)) | 35 | 44 | 828 | 958 | def warshal(data):
for k in range(n):
for i in range(n):
for j in range(n):
data[i][j] = min(data[i][j], data[i][k] + data[k][j])
return data
n, m, l = list(map(int, input().split()))
inf = float("inf")
data = [[inf] * n for i in range(n)]
for i in range(m):
a, b, c = list(map(int, input().split()))
data[a - 1][b - 1] = c
data[b - 1][a - 1] = c
for i in range(n):
data[i][i] = 0
data = warshal(data)
for i in range(n):
for j in range(n):
if data[i][j] <= l:
data[i][j] = 1
else:
data[i][j] = inf
for i in range(n):
data[i][i] = 0
data = warshal(data)
q = int(eval(input()))
st = []
for i in range(q):
s, t = list(map(int, input().split()))
st.append([s - 1, t - 1])
for s, t in st:
if data[s][t] == inf:
print((-1))
else:
print((data[s][t] - 1))
| import sys
input = sys.stdin.readline
def Warshall_Floyd(N, DIST):
for k in range(N):
for i in range(N):
for j in range(N):
DIST[i][j] = min(DIST[i][j], DIST[i][k] + DIST[k][j])
return DIST
N, M, L = list(map(int, input().split()))
ABC = [list(map(int, input().split())) for i in range(M)]
Q = int(eval(input()))
st = [list(map(int, input().split())) for i in range(Q)]
inf = L + 1
dist = [[inf] * N for i in range(N)]
for i in range(N):
dist[i][i] = 0
for A, B, C in ABC:
dist[A - 1][B - 1] = min(dist[A - 1][B - 1], C)
dist[B - 1][A - 1] = min(dist[B - 1][A - 1], C)
dist = Warshall_Floyd(N, dist)
dist_2 = [[N + 1] * N for i in range(N)]
for i in range(N):
for j in range(N):
if dist[i][j] <= L:
dist_2[i][j] = 1
for i in range(N):
dist_2[i][i] = 0
dist_2 = Warshall_Floyd(N, dist_2)
for s, t in st:
if dist_2[s - 1][t - 1] == N + 1:
print((-1))
else:
print((dist_2[s - 1][t - 1] - 1))
| false | 20.454545 | [
"-def warshal(data):",
"- for k in range(n):",
"- for i in range(n):",
"- for j in range(n):",
"- data[i][j] = min(data[i][j], data[i][k] + data[k][j])",
"- return data",
"+import sys",
"+",
"+input = sys.stdin.readline",
"-n, m, l = list(map(int, input().spl... | false | 0.091547 | 0.047949 | 1.909261 | [
"s443483729",
"s985692002"
] |
u690536347 | p03074 | python | s011840012 | s277755959 | 102 | 91 | 9,996 | 10,000 | Accepted | Accepted | 10.78 | from itertools import accumulate as ac
N, K = list(map(int, input().split()))
*S, = list(map(int, eval(input())))
l = []
c0, c1 = 0, 0
prev = 0
for i, j in enumerate(S):
if i==0:
if j==0:
c0 += 1
else:
c1 += 1
else:
if prev!=j:
if prev==1:
l.append(c1)
c1 = 0
else:
l.append(c0)
c0 = 0
if j==0:
c0 += 1
else:
c1 += 1
prev = j
if c0:
l.append(c0)
if c1:
l.append(c1)
if S[0]==0:
l = [0]+l
if S[-1]==0:
l.append(0)
size = len(l)
accum = list(ac([0]+l))
start = min(2*K+1,size)
ans = 0
for i in range(start, size+1, 2):
ans = max(ans, accum[i]-accum[i-start])
print(ans) | from itertools import accumulate as ac
N, K = list(map(int, input().split()))
*S, = list(map(int, eval(input())))
l = []
c = 0
if N==1:
l.append(S[0])
else:
for i in range(N-1):
c += 1
if S[i]!=S[i+1]:
l.append(c)
c = 0
if c:
l.append(c+1)
if S[0]==0:
l = [0]+l
if S[-1]==0:
l.append(0)
size = len(l)
*a, = ac([0]+l)
group_size = min(2*K+1,size)
ans = 0
for i in range(group_size, size+1, 2):
ans = max(ans, a[i]-a[i-group_size])
print(ans) | 47 | 32 | 811 | 531 | from itertools import accumulate as ac
N, K = list(map(int, input().split()))
(*S,) = list(map(int, eval(input())))
l = []
c0, c1 = 0, 0
prev = 0
for i, j in enumerate(S):
if i == 0:
if j == 0:
c0 += 1
else:
c1 += 1
else:
if prev != j:
if prev == 1:
l.append(c1)
c1 = 0
else:
l.append(c0)
c0 = 0
if j == 0:
c0 += 1
else:
c1 += 1
prev = j
if c0:
l.append(c0)
if c1:
l.append(c1)
if S[0] == 0:
l = [0] + l
if S[-1] == 0:
l.append(0)
size = len(l)
accum = list(ac([0] + l))
start = min(2 * K + 1, size)
ans = 0
for i in range(start, size + 1, 2):
ans = max(ans, accum[i] - accum[i - start])
print(ans)
| from itertools import accumulate as ac
N, K = list(map(int, input().split()))
(*S,) = list(map(int, eval(input())))
l = []
c = 0
if N == 1:
l.append(S[0])
else:
for i in range(N - 1):
c += 1
if S[i] != S[i + 1]:
l.append(c)
c = 0
if c:
l.append(c + 1)
if S[0] == 0:
l = [0] + l
if S[-1] == 0:
l.append(0)
size = len(l)
(*a,) = ac([0] + l)
group_size = min(2 * K + 1, size)
ans = 0
for i in range(group_size, size + 1, 2):
ans = max(ans, a[i] - a[i - group_size])
print(ans)
| false | 31.914894 | [
"-c0, c1 = 0, 0",
"-prev = 0",
"-for i, j in enumerate(S):",
"- if i == 0:",
"- if j == 0:",
"- c0 += 1",
"- else:",
"- c1 += 1",
"- else:",
"- if prev != j:",
"- if prev == 1:",
"- l.append(c1)",
"- c1... | false | 0.036803 | 0.041949 | 0.877321 | [
"s011840012",
"s277755959"
] |
u227550284 | p02712 | python | s187128670 | s568835366 | 210 | 147 | 56,324 | 9,156 | Accepted | Accepted | 30 | import sys
input = sys.stdin.readline
def fizzbuzz(n):
if n % 5 == 0 and n % 3 == 0:
return 0
elif n % 3 == 0:
return 0
elif n % 5 == 0:
return 0
else:
return n
def main():
n = int(eval(input()))
li = list(range(1, n+1))
change_li = list(map(fizzbuzz, li))
print((sum(change_li)))
if __name__ == '__main__':
main()
| n = int(eval(input()))
ans = 0
for i in range(1, n+1):
if i % 3 != 0 and i % 5 != 0:
ans += i
print(ans)
| 26 | 7 | 408 | 118 | import sys
input = sys.stdin.readline
def fizzbuzz(n):
if n % 5 == 0 and n % 3 == 0:
return 0
elif n % 3 == 0:
return 0
elif n % 5 == 0:
return 0
else:
return n
def main():
n = int(eval(input()))
li = list(range(1, n + 1))
change_li = list(map(fizzbuzz, li))
print((sum(change_li)))
if __name__ == "__main__":
main()
| n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
if i % 3 != 0 and i % 5 != 0:
ans += i
print(ans)
| false | 73.076923 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-",
"-",
"-def fizzbuzz(n):",
"- if n % 5 == 0 and n % 3 == 0:",
"- return 0",
"- elif n % 3 == 0:",
"- return 0",
"- elif n % 5 == 0:",
"- return 0",
"- else:",
"- return n",
"-",
"-",
"-def ... | false | 0.151 | 0.134864 | 1.119647 | [
"s187128670",
"s568835366"
] |
u177411511 | p03309 | python | s152238975 | s514553356 | 356 | 247 | 27,264 | 27,260 | Accepted | Accepted | 30.62 | import sys
from collections import deque
from collections import Counter
import statistics
import math
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
n = ni()
a_li = na()
for i in range(n):
a_li[i] = a_li[i] - (i + 1)
m1 = statistics.median_low(a_li)
m2 = statistics.median_high(a_li)
ans1 = 0
ans2 = 0
for i in range(n):
ans1 += abs(a_li[i] - m1)
ans2 += abs(a_li[i] - m2)
print((min(ans1, ans2)))
| import sys
from collections import deque
from collections import Counter
import statistics
import math
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
n = ni()
a_li = na()
for i in range(n):
a_li[i] = a_li[i] - (i + 1)
m1 = statistics.median_low(a_li)
#m2 = statistics.median_high(a_li)
ans1 = 0
#ans2 = 0
for i in range(n):
ans1 += abs(a_li[i] - m1)
#ans2 += abs(a_li[i] - m2)
print(ans1)
| 23 | 23 | 512 | 504 | import sys
from collections import deque
from collections import Counter
import statistics
import math
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
n = ni()
a_li = na()
for i in range(n):
a_li[i] = a_li[i] - (i + 1)
m1 = statistics.median_low(a_li)
m2 = statistics.median_high(a_li)
ans1 = 0
ans2 = 0
for i in range(n):
ans1 += abs(a_li[i] - m1)
ans2 += abs(a_li[i] - m2)
print((min(ans1, ans2)))
| import sys
from collections import deque
from collections import Counter
import statistics
import math
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
n = ni()
a_li = na()
for i in range(n):
a_li[i] = a_li[i] - (i + 1)
m1 = statistics.median_low(a_li)
# m2 = statistics.median_high(a_li)
ans1 = 0
# ans2 = 0
for i in range(n):
ans1 += abs(a_li[i] - m1)
# ans2 += abs(a_li[i] - m2)
print(ans1)
| false | 0 | [
"-m2 = statistics.median_high(a_li)",
"+# m2 = statistics.median_high(a_li)",
"-ans2 = 0",
"+# ans2 = 0",
"- ans2 += abs(a_li[i] - m2)",
"-print((min(ans1, ans2)))",
"+ # ans2 += abs(a_li[i] - m2)",
"+print(ans1)"
] | false | 0.048217 | 0.04889 | 0.986244 | [
"s152238975",
"s514553356"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.