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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u912237403 | p00076 | python | s523626125 | s096294964 | 20 | 10 | 4,440 | 4,440 | Accepted | Accepted | 50 | A=[[]]*1001
x=1.0
y=0.0
for i in range(1,1001):
A[i]=[x,y]
tmp=i**.5
x,y=x-y/tmp,y+x/tmp
while 1:
n = eval(input())
if n==-1:break
print(A[n][0])
print(A[n][1]) | N=1001
A=[[]]*N
x=1.0
y=0.0
for i in range(1,N):
A[i]=[x,y]
tmp=i**.5
x,y=x-y/tmp,y+x/tmp
while 1:
n = eval(input())
if n==-1:break
a,b=A[n]
print(a,b) | 13 | 14 | 194 | 187 | A = [[]] * 1001
x = 1.0
y = 0.0
for i in range(1, 1001):
A[i] = [x, y]
tmp = i**0.5
x, y = x - y / tmp, y + x / tmp
while 1:
n = eval(input())
if n == -1:
break
print(A[n][0])
print(A[n][1])
| N = 1001
A = [[]] * N
x = 1.0
y = 0.0
for i in range(1, N):
A[i] = [x, y]
tmp = i**0.5
x, y = x - y / tmp, y + x / tmp
while 1:
n = eval(input())
if n == -1:
break
a, b = A[n]
print(a, b)
| false | 7.142857 | [
"-A = [[]] * 1001",
"+N = 1001",
"+A = [[]] * N",
"-for i in range(1, 1001):",
"+for i in range(1, N):",
"- print(A[n][0])",
"- print(A[n][1])",
"+ a, b = A[n]",
"+ print(a, b)"
]
| false | 0.036927 | 0.043583 | 0.847284 | [
"s523626125",
"s096294964"
]
|
u777283665 | p03578 | python | s980813511 | s843994608 | 291 | 224 | 67,412 | 46,432 | Accepted | Accepted | 23.02 | n = int(eval(input()))
x = dict()
for i in input().split():
x[i] = x.get(i, 0) + 1
m = int(eval(input()))
y = dict()
for i in input().split():
y[i] = y.get(i, 0) + 1
for i, j in list(y.items()):
if x.get(i, 0) < j:
print("NO")
exit()
print("YES") | n = int(eval(input()))
x = dict()
for i in input().split():
x[i] = x.get(i, 0) + 1
m = int(eval(input()))
for i in input().split():
if i not in x or x[i] == 0:
print("NO")
exit()
else:
x[i] -= 1
print("YES") | 17 | 15 | 276 | 248 | n = int(eval(input()))
x = dict()
for i in input().split():
x[i] = x.get(i, 0) + 1
m = int(eval(input()))
y = dict()
for i in input().split():
y[i] = y.get(i, 0) + 1
for i, j in list(y.items()):
if x.get(i, 0) < j:
print("NO")
exit()
print("YES")
| n = int(eval(input()))
x = dict()
for i in input().split():
x[i] = x.get(i, 0) + 1
m = int(eval(input()))
for i in input().split():
if i not in x or x[i] == 0:
print("NO")
exit()
else:
x[i] -= 1
print("YES")
| false | 11.764706 | [
"-y = dict()",
"- y[i] = y.get(i, 0) + 1",
"-for i, j in list(y.items()):",
"- if x.get(i, 0) < j:",
"+ if i not in x or x[i] == 0:",
"+ else:",
"+ x[i] -= 1"
]
| false | 0.043429 | 0.007744 | 5.607808 | [
"s980813511",
"s843994608"
]
|
u211160392 | p03142 | python | s304797889 | s877063471 | 782 | 542 | 82,096 | 23,840 | Accepted | Accepted | 30.69 | from collections import deque
N, M = list(map(int,input().split()))
count = [0]*N
side = [[]for i in range(N)]
rside = [[]for i in range(N)]
for i in range(N+M-1):
a,b = list(map(int,input().split()))
side[a-1].append(b-1)
rside[b-1].append(a-1)
count[b-1] += 1
root = count.index(0)
queue = deque([root])
top = [0]*N
for i in range(N):
q = queue.popleft()
top[q] = i
for k in side[q]:
count[k] -= 1
if count[k] == 0:
queue.append(k)
for i in range(N):
if rside[i] == []:
print((0))
continue
ret = root
for j in rside[i]:
if top[ret] < top[j]:
ret = j
print((ret+1))
| from collections import deque
N,M = list(map(int,input().split()))
side = [[]for _ in range(N)]
counts = [0]*N
ans = [0]*N
for i in range(N+M-1):
a,b = list(map(int,input().split()))
side[a-1].append(b-1)
counts[b-1]+=1
queue = deque([counts.index(0)])
while queue:
q = queue.popleft()
for i in side[q]:
counts[i] -= 1
if counts[i] == 0:
ans[i] = q+1
queue.append(i)
for i in ans:
print(i) | 32 | 22 | 693 | 465 | from collections import deque
N, M = list(map(int, input().split()))
count = [0] * N
side = [[] for i in range(N)]
rside = [[] for i in range(N)]
for i in range(N + M - 1):
a, b = list(map(int, input().split()))
side[a - 1].append(b - 1)
rside[b - 1].append(a - 1)
count[b - 1] += 1
root = count.index(0)
queue = deque([root])
top = [0] * N
for i in range(N):
q = queue.popleft()
top[q] = i
for k in side[q]:
count[k] -= 1
if count[k] == 0:
queue.append(k)
for i in range(N):
if rside[i] == []:
print((0))
continue
ret = root
for j in rside[i]:
if top[ret] < top[j]:
ret = j
print((ret + 1))
| from collections import deque
N, M = list(map(int, input().split()))
side = [[] for _ in range(N)]
counts = [0] * N
ans = [0] * N
for i in range(N + M - 1):
a, b = list(map(int, input().split()))
side[a - 1].append(b - 1)
counts[b - 1] += 1
queue = deque([counts.index(0)])
while queue:
q = queue.popleft()
for i in side[q]:
counts[i] -= 1
if counts[i] == 0:
ans[i] = q + 1
queue.append(i)
for i in ans:
print(i)
| false | 31.25 | [
"-count = [0] * N",
"-side = [[] for i in range(N)]",
"-rside = [[] for i in range(N)]",
"+side = [[] for _ in range(N)]",
"+counts = [0] * N",
"+ans = [0] * N",
"- rside[b - 1].append(a - 1)",
"- count[b - 1] += 1",
"-root = count.index(0)",
"-queue = deque([root])",
"-top = [0] * N",
"-for i in range(N):",
"+ counts[b - 1] += 1",
"+queue = deque([counts.index(0)])",
"+while queue:",
"- top[q] = i",
"- for k in side[q]:",
"- count[k] -= 1",
"- if count[k] == 0:",
"- queue.append(k)",
"-for i in range(N):",
"- if rside[i] == []:",
"- print((0))",
"- continue",
"- ret = root",
"- for j in rside[i]:",
"- if top[ret] < top[j]:",
"- ret = j",
"- print((ret + 1))",
"+ for i in side[q]:",
"+ counts[i] -= 1",
"+ if counts[i] == 0:",
"+ ans[i] = q + 1",
"+ queue.append(i)",
"+for i in ans:",
"+ print(i)"
]
| false | 0.129709 | 0.035856 | 3.617546 | [
"s304797889",
"s877063471"
]
|
u077291787 | p03331 | python | s917753748 | s300424462 | 141 | 17 | 3,060 | 2,940 | Accepted | Accepted | 87.94 | # AGC025A - Digits Sum
def main():
n = int(eval(input()))
ans = float("inf")
for i in range(1, n // 2 + 1):
j = n - i
ds = sum(map(int, str(i))) + sum(map(int, str(j))) # digits sum
ans = min(ans, ds)
print(ans)
if __name__ == "__main__":
main() | # AGC025A - Digits Sum
# Better ver.
def main():
n = int(eval(input()))
ans = sum(map(int, str(n))) # ds: digit sum
print((ans if ans != 1 else 10))
if __name__ == "__main__":
main() | 13 | 10 | 298 | 202 | # AGC025A - Digits Sum
def main():
n = int(eval(input()))
ans = float("inf")
for i in range(1, n // 2 + 1):
j = n - i
ds = sum(map(int, str(i))) + sum(map(int, str(j))) # digits sum
ans = min(ans, ds)
print(ans)
if __name__ == "__main__":
main()
| # AGC025A - Digits Sum
# Better ver.
def main():
n = int(eval(input()))
ans = sum(map(int, str(n))) # ds: digit sum
print((ans if ans != 1 else 10))
if __name__ == "__main__":
main()
| false | 23.076923 | [
"+# Better ver.",
"- ans = float(\"inf\")",
"- for i in range(1, n // 2 + 1):",
"- j = n - i",
"- ds = sum(map(int, str(i))) + sum(map(int, str(j))) # digits sum",
"- ans = min(ans, ds)",
"- print(ans)",
"+ ans = sum(map(int, str(n))) # ds: digit sum",
"+ print((ans if ans != 1 else 10))"
]
| false | 0.187603 | 0.100737 | 1.862301 | [
"s917753748",
"s300424462"
]
|
u006880673 | p02579 | python | s076779132 | s938866924 | 1,413 | 734 | 124,884 | 159,840 | Accepted | Accepted | 48.05 | import heapq
INF = 1e7
def main():
H,W=list(map(int, input().split()))
sx, sy = list(map(int, input().split()))
dh, dw = list(map(int, input().split()))
sx -= 1
sy -= 1
S = [eval(input()) for _ in range(H)]
def dijkstra(sx, sy):
D = [[INF]*(W) for _ in range(H)] #始点からの距離(重み)
D[sx][sy] = 0
PQ = [(0, (sx, sy))]
heapq.heapify(PQ)
while PQ: # PQに候補がある限り
_, (ux, uy) = heapq.heappop(PQ) # 最小コストなノードu
for dx in range(-2, 3):
for dy in range(-2, 3):
xx, yy = ux+dx, uy+dy
if 0 <= xx < H and 0 <= yy < W and S[xx][yy]==".":
is_not_neighbor = int(abs(dx) + abs(dy) != 1)
# neighborでなければコストが1増える
if abs(dx) + abs(dy) == 1:
if D[ux][uy] < D[xx][yy]:
D[xx][yy] = D[ux][uy]
heapq.heappush(PQ, (D[xx][yy], (xx, yy)))
else:
if D[ux][uy] + 1 < D[xx][yy]:
D[xx][yy] = D[ux][uy] + 1
heapq.heappush(PQ, (D[xx][yy], (xx, yy)))
return D
D = dijkstra(sx, sy)
if D[dh-1][dw-1] >= INF:
print((-1))
else:
print((D[dh-1][dw-1]))
main() | from itertools import product
from collections import deque
INF = 1e7
def main():
H, W = list(map(int, input().split()))
ch, cw = [int(x)+1 for x in input().split()]
dh, dw = [int(x)+1 for x in input().split()]
S = [["#"]*(W+4) for _ in range(H+4)]
whites = [] # 道であるindex
for i in range(2, H+2):
tmp = eval(input())
for j in range(2, W+2):
S[i][j] = tmp[j-2]
if S[i][j] == ".":
whites.append((i,j))
dxdy = [(1,0), (-1,0), (0,1), (0,-1)]
magic = list(product(list(range(-2, 3)), repeat=2))
magic.remove((0, 0))
for to_remove in dxdy:
magic.remove(to_remove)
# graph = {idx: deque() for idx in whites}
# for idx in whites:
# x = idx[0]
# y = idx[1]
# for dx, dy in dxdy:
# if S[x+dx][y+dy] == ".":
# graph[idx].append((x+dx, y+dy))
# graph2 = {idx: deque() for idx in whites}
# for idx in whites:
# x = idx[0]
# y = idx[1]
# for mx, my in magic:
# if S[x+mx][y+my] == ".":
# graph2[idx].append((x+mx, y+my))
def bfs(u,v):
dist = [[INF] * (W+4) for _ in range(H+4)] #indexed from 1
# seen = [[0] * (W+4) for _ in range(H+4)] #indexed from 1
queue = deque()
# seen[u][v] = 1
dist[u][v] = 0
queue.append((u,v))
while queue:
p, q = queue.popleft()
# if not graph[(p,q)]:
# queue.popleft()
# continue
# g,h = graph[(p,q)].popleft()
# if seen[g][h]:
# continue
# seen[g][h] = 1
# dist[g][h] = min(dist[g][h], dist[p][q])
for dx, dy in dxdy:
g = p+dx
h = q+dy
if S[g][h]=="." and dist[g][h] > dist[p][q]:
dist[g][h] = dist[p][q]
queue.appendleft((g,h))
for dx, dy in magic:
g = p+dx
h = q+dy
if S[g][h]=="." and dist[g][h] > dist[p][q]+1:
dist[g][h] = dist[p][q]+1
queue.append((g,h))
# dist[g][h] = min(dist[g][h], dist[p][q]+1)
# queue.append((g,h))
return dist
D = bfs(ch, cw)
ans = D[dh][dw]
if ans == INF:
print((-1))
else:
print(ans)
if __name__ == "__main__":
main() | 37 | 79 | 1,383 | 2,518 | import heapq
INF = 1e7
def main():
H, W = list(map(int, input().split()))
sx, sy = list(map(int, input().split()))
dh, dw = list(map(int, input().split()))
sx -= 1
sy -= 1
S = [eval(input()) for _ in range(H)]
def dijkstra(sx, sy):
D = [[INF] * (W) for _ in range(H)] # 始点からの距離(重み)
D[sx][sy] = 0
PQ = [(0, (sx, sy))]
heapq.heapify(PQ)
while PQ: # PQに候補がある限り
_, (ux, uy) = heapq.heappop(PQ) # 最小コストなノードu
for dx in range(-2, 3):
for dy in range(-2, 3):
xx, yy = ux + dx, uy + dy
if 0 <= xx < H and 0 <= yy < W and S[xx][yy] == ".":
is_not_neighbor = int(abs(dx) + abs(dy) != 1)
# neighborでなければコストが1増える
if abs(dx) + abs(dy) == 1:
if D[ux][uy] < D[xx][yy]:
D[xx][yy] = D[ux][uy]
heapq.heappush(PQ, (D[xx][yy], (xx, yy)))
else:
if D[ux][uy] + 1 < D[xx][yy]:
D[xx][yy] = D[ux][uy] + 1
heapq.heappush(PQ, (D[xx][yy], (xx, yy)))
return D
D = dijkstra(sx, sy)
if D[dh - 1][dw - 1] >= INF:
print((-1))
else:
print((D[dh - 1][dw - 1]))
main()
| from itertools import product
from collections import deque
INF = 1e7
def main():
H, W = list(map(int, input().split()))
ch, cw = [int(x) + 1 for x in input().split()]
dh, dw = [int(x) + 1 for x in input().split()]
S = [["#"] * (W + 4) for _ in range(H + 4)]
whites = [] # 道であるindex
for i in range(2, H + 2):
tmp = eval(input())
for j in range(2, W + 2):
S[i][j] = tmp[j - 2]
if S[i][j] == ".":
whites.append((i, j))
dxdy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
magic = list(product(list(range(-2, 3)), repeat=2))
magic.remove((0, 0))
for to_remove in dxdy:
magic.remove(to_remove)
# graph = {idx: deque() for idx in whites}
# for idx in whites:
# x = idx[0]
# y = idx[1]
# for dx, dy in dxdy:
# if S[x+dx][y+dy] == ".":
# graph[idx].append((x+dx, y+dy))
# graph2 = {idx: deque() for idx in whites}
# for idx in whites:
# x = idx[0]
# y = idx[1]
# for mx, my in magic:
# if S[x+mx][y+my] == ".":
# graph2[idx].append((x+mx, y+my))
def bfs(u, v):
dist = [[INF] * (W + 4) for _ in range(H + 4)] # indexed from 1
# seen = [[0] * (W+4) for _ in range(H+4)] #indexed from 1
queue = deque()
# seen[u][v] = 1
dist[u][v] = 0
queue.append((u, v))
while queue:
p, q = queue.popleft()
# if not graph[(p,q)]:
# queue.popleft()
# continue
# g,h = graph[(p,q)].popleft()
# if seen[g][h]:
# continue
# seen[g][h] = 1
# dist[g][h] = min(dist[g][h], dist[p][q])
for dx, dy in dxdy:
g = p + dx
h = q + dy
if S[g][h] == "." and dist[g][h] > dist[p][q]:
dist[g][h] = dist[p][q]
queue.appendleft((g, h))
for dx, dy in magic:
g = p + dx
h = q + dy
if S[g][h] == "." and dist[g][h] > dist[p][q] + 1:
dist[g][h] = dist[p][q] + 1
queue.append((g, h))
# dist[g][h] = min(dist[g][h], dist[p][q]+1)
# queue.append((g,h))
return dist
D = bfs(ch, cw)
ans = D[dh][dw]
if ans == INF:
print((-1))
else:
print(ans)
if __name__ == "__main__":
main()
| false | 53.164557 | [
"-import heapq",
"+from itertools import product",
"+from collections import deque",
"- sx, sy = list(map(int, input().split()))",
"- dh, dw = list(map(int, input().split()))",
"- sx -= 1",
"- sy -= 1",
"- S = [eval(input()) for _ in range(H)]",
"+ ch, cw = [int(x) + 1 for x in input().split()]",
"+ dh, dw = [int(x) + 1 for x in input().split()]",
"+ S = [[\"#\"] * (W + 4) for _ in range(H + 4)]",
"+ whites = [] # 道であるindex",
"+ for i in range(2, H + 2):",
"+ tmp = eval(input())",
"+ for j in range(2, W + 2):",
"+ S[i][j] = tmp[j - 2]",
"+ if S[i][j] == \".\":",
"+ whites.append((i, j))",
"+ dxdy = [(1, 0), (-1, 0), (0, 1), (0, -1)]",
"+ magic = list(product(list(range(-2, 3)), repeat=2))",
"+ magic.remove((0, 0))",
"+ for to_remove in dxdy:",
"+ magic.remove(to_remove)",
"+ # graph = {idx: deque() for idx in whites}",
"+ # for idx in whites:",
"+ # x = idx[0]",
"+ # y = idx[1]",
"+ # for dx, dy in dxdy:",
"+ # if S[x+dx][y+dy] == \".\":",
"+ # graph[idx].append((x+dx, y+dy))",
"+ # graph2 = {idx: deque() for idx in whites}",
"+ # for idx in whites:",
"+ # x = idx[0]",
"+ # y = idx[1]",
"+ # for mx, my in magic:",
"+ # if S[x+mx][y+my] == \".\":",
"+ # graph2[idx].append((x+mx, y+my))",
"+ def bfs(u, v):",
"+ dist = [[INF] * (W + 4) for _ in range(H + 4)] # indexed from 1",
"+ # seen = [[0] * (W+4) for _ in range(H+4)] #indexed from 1",
"+ queue = deque()",
"+ # seen[u][v] = 1",
"+ dist[u][v] = 0",
"+ queue.append((u, v))",
"+ while queue:",
"+ p, q = queue.popleft()",
"+ # if not graph[(p,q)]:",
"+ # queue.popleft()",
"+ # continue",
"+ # g,h = graph[(p,q)].popleft()",
"+ # if seen[g][h]:",
"+ # continue",
"+ # seen[g][h] = 1",
"+ # dist[g][h] = min(dist[g][h], dist[p][q])",
"+ for dx, dy in dxdy:",
"+ g = p + dx",
"+ h = q + dy",
"+ if S[g][h] == \".\" and dist[g][h] > dist[p][q]:",
"+ dist[g][h] = dist[p][q]",
"+ queue.appendleft((g, h))",
"+ for dx, dy in magic:",
"+ g = p + dx",
"+ h = q + dy",
"+ if S[g][h] == \".\" and dist[g][h] > dist[p][q] + 1:",
"+ dist[g][h] = dist[p][q] + 1",
"+ queue.append((g, h))",
"+ # dist[g][h] = min(dist[g][h], dist[p][q]+1)",
"+ # queue.append((g,h))",
"+ return dist",
"- def dijkstra(sx, sy):",
"- D = [[INF] * (W) for _ in range(H)] # 始点からの距離(重み)",
"- D[sx][sy] = 0",
"- PQ = [(0, (sx, sy))]",
"- heapq.heapify(PQ)",
"- while PQ: # PQに候補がある限り",
"- _, (ux, uy) = heapq.heappop(PQ) # 最小コストなノードu",
"- for dx in range(-2, 3):",
"- for dy in range(-2, 3):",
"- xx, yy = ux + dx, uy + dy",
"- if 0 <= xx < H and 0 <= yy < W and S[xx][yy] == \".\":",
"- is_not_neighbor = int(abs(dx) + abs(dy) != 1)",
"- # neighborでなければコストが1増える",
"- if abs(dx) + abs(dy) == 1:",
"- if D[ux][uy] < D[xx][yy]:",
"- D[xx][yy] = D[ux][uy]",
"- heapq.heappush(PQ, (D[xx][yy], (xx, yy)))",
"- else:",
"- if D[ux][uy] + 1 < D[xx][yy]:",
"- D[xx][yy] = D[ux][uy] + 1",
"- heapq.heappush(PQ, (D[xx][yy], (xx, yy)))",
"- return D",
"-",
"- D = dijkstra(sx, sy)",
"- if D[dh - 1][dw - 1] >= INF:",
"+ D = bfs(ch, cw)",
"+ ans = D[dh][dw]",
"+ if ans == INF:",
"- print((D[dh - 1][dw - 1]))",
"+ print(ans)",
"-main()",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.223185 | 0.060668 | 3.678776 | [
"s076779132",
"s938866924"
]
|
u561083515 | p02947 | python | s969015861 | s825123918 | 1,588 | 587 | 41,012 | 22,372 | Accepted | Accepted | 63.04 | from collections import Counter,defaultdict
import sys
input = sys.stdin.readline
N = int(eval(input()))
s = [None] + [list(eval(input())) for _ in range(N)]
count = defaultdict(int)
answer = 0
for i in range(1,N+1):
c = Counter(s[i])
c = sorted(list(c.items()), key=lambda x:x[0])
# O(len(c))
str_c = ""
for key,item in c:
str_c += key*item
answer += count[str_c]
count[str_c] += 1
print(answer) | from collections import defaultdict
N = int(eval(input()))
cnt = defaultdict(int)
ans = 0
for _ in range(N):
s = list(eval(input()))
s.sort()
s = str(s)
ans += cnt[s]
cnt[s] += 1
print(ans) | 21 | 15 | 438 | 215 | from collections import Counter, defaultdict
import sys
input = sys.stdin.readline
N = int(eval(input()))
s = [None] + [list(eval(input())) for _ in range(N)]
count = defaultdict(int)
answer = 0
for i in range(1, N + 1):
c = Counter(s[i])
c = sorted(list(c.items()), key=lambda x: x[0])
# O(len(c))
str_c = ""
for key, item in c:
str_c += key * item
answer += count[str_c]
count[str_c] += 1
print(answer)
| from collections import defaultdict
N = int(eval(input()))
cnt = defaultdict(int)
ans = 0
for _ in range(N):
s = list(eval(input()))
s.sort()
s = str(s)
ans += cnt[s]
cnt[s] += 1
print(ans)
| false | 28.571429 | [
"-from collections import Counter, defaultdict",
"-import sys",
"+from collections import defaultdict",
"-input = sys.stdin.readline",
"-s = [None] + [list(eval(input())) for _ in range(N)]",
"-count = defaultdict(int)",
"-answer = 0",
"-for i in range(1, N + 1):",
"- c = Counter(s[i])",
"- c = sorted(list(c.items()), key=lambda x: x[0])",
"- # O(len(c))",
"- str_c = \"\"",
"- for key, item in c:",
"- str_c += key * item",
"- answer += count[str_c]",
"- count[str_c] += 1",
"-print(answer)",
"+cnt = defaultdict(int)",
"+ans = 0",
"+for _ in range(N):",
"+ s = list(eval(input()))",
"+ s.sort()",
"+ s = str(s)",
"+ ans += cnt[s]",
"+ cnt[s] += 1",
"+print(ans)"
]
| false | 0.035901 | 0.033789 | 1.062492 | [
"s969015861",
"s825123918"
]
|
u462329577 | p03427 | python | s507263522 | s819475787 | 166 | 18 | 38,256 | 2,940 | Accepted | Accepted | 89.16 | #!/usr/bin/env python3
s = eval(input())
digit = len(s)
if s[1:] == "9"*(digit-1):
print((int(s[0])+9*(digit-1)))
else:
print((int(s[0])+9*(digit-1)-1)) | s = eval(input())
if len(s) == 1: print((int(s[0])))
elif s[1:] == "9"*(len(s)-1):
print((int(s[0])+9*len(s)-9))
else:
print((int(s[0])+9*len(s)-10))
| 7 | 6 | 156 | 184 | #!/usr/bin/env python3
s = eval(input())
digit = len(s)
if s[1:] == "9" * (digit - 1):
print((int(s[0]) + 9 * (digit - 1)))
else:
print((int(s[0]) + 9 * (digit - 1) - 1))
| s = eval(input())
if len(s) == 1:
print((int(s[0])))
elif s[1:] == "9" * (len(s) - 1):
print((int(s[0]) + 9 * len(s) - 9))
else:
print((int(s[0]) + 9 * len(s) - 10))
| false | 14.285714 | [
"-#!/usr/bin/env python3",
"-digit = len(s)",
"-if s[1:] == \"9\" * (digit - 1):",
"- print((int(s[0]) + 9 * (digit - 1)))",
"+if len(s) == 1:",
"+ print((int(s[0])))",
"+elif s[1:] == \"9\" * (len(s) - 1):",
"+ print((int(s[0]) + 9 * len(s) - 9))",
"- print((int(s[0]) + 9 * (digit - 1) - 1))",
"+ print((int(s[0]) + 9 * len(s) - 10))"
]
| false | 0.121369 | 0.042435 | 2.860109 | [
"s507263522",
"s819475787"
]
|
u815763296 | p02713 | python | s491146072 | s265019893 | 1,284 | 511 | 9,052 | 68,880 | Accepted | Accepted | 60.2 | import math
K = int(eval(input()))
total = 0
for x in range(1, K+1):
for y in range(1, K+1):
a=math.gcd(x, y)
for z in range(1, K+1):
total = total+math.gcd(z, a)
print(total)
| import math
K = int(eval(input()))
total = 0
for x in range(1, K+1):
for y in range(1, K+1):
for z in range(1, K+1):
total = total+math.gcd(x, math.gcd(y, z))
print(total)
| 9 | 8 | 210 | 197 | import math
K = int(eval(input()))
total = 0
for x in range(1, K + 1):
for y in range(1, K + 1):
a = math.gcd(x, y)
for z in range(1, K + 1):
total = total + math.gcd(z, a)
print(total)
| import math
K = int(eval(input()))
total = 0
for x in range(1, K + 1):
for y in range(1, K + 1):
for z in range(1, K + 1):
total = total + math.gcd(x, math.gcd(y, z))
print(total)
| false | 11.111111 | [
"- a = math.gcd(x, y)",
"- total = total + math.gcd(z, a)",
"+ total = total + math.gcd(x, math.gcd(y, z))"
]
| false | 0.165575 | 0.149852 | 1.104926 | [
"s491146072",
"s265019893"
]
|
u699089116 | p02945 | python | s117911733 | s097600926 | 169 | 132 | 38,384 | 61,600 | Accepted | Accepted | 21.89 | a, b = list(map(int, input().split()))
print((max(a+b, a-b, a*b))) | a, b = list(map(int, input().split()))
print((max([a+b, a-b, a*b]))) | 3 | 3 | 61 | 63 | a, b = list(map(int, input().split()))
print((max(a + b, a - b, a * b)))
| a, b = list(map(int, input().split()))
print((max([a + b, a - b, a * b])))
| false | 0 | [
"-print((max(a + b, a - b, a * b)))",
"+print((max([a + b, a - b, a * b])))"
]
| false | 0.036984 | 0.170292 | 0.217179 | [
"s117911733",
"s097600926"
]
|
u144913062 | p02955 | python | s700446557 | s689547908 | 410 | 260 | 53,980 | 41,820 | Accepted | Accepted | 36.59 | from heapq import heapify, heappush, heappop
def divisor(n):
divisors = []
i = 1
while i * i <= n:
if n % i == 0:
divisors.append(i)
if i != n / i:
divisors.append(n // i)
i += 1
divisors.sort()
return divisors
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
divisors = divisor(sum(A))
for d in divisors[::-1]:
heap = []
s = 0
for a in A:
x = a // d * d - a
heap.append(x)
s += -x
heapify(heap)
n = 0
for _ in range(s // d):
x = heappop(heap)
if x + d > K:
break
else:
if x + d > 0:
n += x + d
heappush(heap, x + d)
else:
if sum(abs(x) for x in heap) <= 2 * K:
print(d)
exit()
| def divisor(n):
divisors = []
i = 1
while i * i <= n:
if n % i == 0:
divisors.append(i)
if i * i < n:
divisors.append(n // i)
i += 1
divisors.sort()
return divisors
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
divisors = divisor(sum(A))
for d in divisors[::-1]:
rem = [a % d for a in A]
rem.sort(reverse=True)
i = sum(rem) // d
if sum(rem[i:]) <= K:
print(d)
exit()
| 39 | 23 | 875 | 522 | from heapq import heapify, heappush, heappop
def divisor(n):
divisors = []
i = 1
while i * i <= n:
if n % i == 0:
divisors.append(i)
if i != n / i:
divisors.append(n // i)
i += 1
divisors.sort()
return divisors
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
divisors = divisor(sum(A))
for d in divisors[::-1]:
heap = []
s = 0
for a in A:
x = a // d * d - a
heap.append(x)
s += -x
heapify(heap)
n = 0
for _ in range(s // d):
x = heappop(heap)
if x + d > K:
break
else:
if x + d > 0:
n += x + d
heappush(heap, x + d)
else:
if sum(abs(x) for x in heap) <= 2 * K:
print(d)
exit()
| def divisor(n):
divisors = []
i = 1
while i * i <= n:
if n % i == 0:
divisors.append(i)
if i * i < n:
divisors.append(n // i)
i += 1
divisors.sort()
return divisors
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
divisors = divisor(sum(A))
for d in divisors[::-1]:
rem = [a % d for a in A]
rem.sort(reverse=True)
i = sum(rem) // d
if sum(rem[i:]) <= K:
print(d)
exit()
| false | 41.025641 | [
"-from heapq import heapify, heappush, heappop",
"-",
"-",
"- if i != n / i:",
"+ if i * i < n:",
"- heap = []",
"- s = 0",
"- for a in A:",
"- x = a // d * d - a",
"- heap.append(x)",
"- s += -x",
"- heapify(heap)",
"- n = 0",
"- for _ in range(s // d):",
"- x = heappop(heap)",
"- if x + d > K:",
"- break",
"- else:",
"- if x + d > 0:",
"- n += x + d",
"- heappush(heap, x + d)",
"- else:",
"- if sum(abs(x) for x in heap) <= 2 * K:",
"- print(d)",
"- exit()",
"+ rem = [a % d for a in A]",
"+ rem.sort(reverse=True)",
"+ i = sum(rem) // d",
"+ if sum(rem[i:]) <= K:",
"+ print(d)",
"+ exit()"
]
| false | 0.042064 | 0.038327 | 1.097492 | [
"s700446557",
"s689547908"
]
|
u262869085 | p03147 | python | s919617603 | s274267733 | 47 | 37 | 3,060 | 3,060 | Accepted | Accepted | 21.28 | N =int(eval(input()))
l =[int(i)for i in input().split()]
min = []
max = []
ans =0
while l !=[0]*N:
ans += 1
s =False
for i,j in enumerate(l):
if s:
if j == 0:
break
if j !=0:
s =True
l[i]-=1
print(ans)
| def f(l):
sta = True
for i,j in enumerate(l):
if sta:
if j!=0:
sta=False
l[i]-=1
else:
if j==0:
break
else:
l[i]-=1
return l
N =int(eval(input()))
h =[int(i) for i in input().split()]
m = 0
while h != [0]*N:
h =f(h)
m += 1
print(m) | 17 | 23 | 294 | 386 | N = int(eval(input()))
l = [int(i) for i in input().split()]
min = []
max = []
ans = 0
while l != [0] * N:
ans += 1
s = False
for i, j in enumerate(l):
if s:
if j == 0:
break
if j != 0:
s = True
l[i] -= 1
print(ans)
| def f(l):
sta = True
for i, j in enumerate(l):
if sta:
if j != 0:
sta = False
l[i] -= 1
else:
if j == 0:
break
else:
l[i] -= 1
return l
N = int(eval(input()))
h = [int(i) for i in input().split()]
m = 0
while h != [0] * N:
h = f(h)
m += 1
print(m)
| false | 26.086957 | [
"-N = int(eval(input()))",
"-l = [int(i) for i in input().split()]",
"-min = []",
"-max = []",
"-ans = 0",
"-while l != [0] * N:",
"- ans += 1",
"- s = False",
"+def f(l):",
"+ sta = True",
"- if s:",
"+ if sta:",
"+ if j != 0:",
"+ sta = False",
"+ l[i] -= 1",
"+ else:",
"- if j != 0:",
"- s = True",
"- l[i] -= 1",
"-print(ans)",
"+ else:",
"+ l[i] -= 1",
"+ return l",
"+",
"+",
"+N = int(eval(input()))",
"+h = [int(i) for i in input().split()]",
"+m = 0",
"+while h != [0] * N:",
"+ h = f(h)",
"+ m += 1",
"+print(m)"
]
| false | 0.045351 | 0.126677 | 0.358004 | [
"s919617603",
"s274267733"
]
|
u077291787 | p03593 | python | s635792707 | s696319772 | 22 | 18 | 3,316 | 3,064 | Accepted | Accepted | 18.18 | # code-festival-2017-qualaC - Palindromic Matrix
from collections import defaultdict
def main():
H, W, *A = open(0).read().split()
H, W, C = int(H), int(W), defaultdict(int)
for i in "".join(A):
C[i] += 1
single = H & W & 1
double = (H >> 1 if W & 1 else 0) + (W >> 1 if H & 1 else 0)
C_mod4 = [i % 4 for i in list(C.values())]
flg = C_mod4.count(1) + C_mod4.count(3) <= single and C_mod4.count(2) <= double
print(("Yes" if flg else "No"))
if __name__ == "__main__":
main() | # code-festival-2017-qualaC - Palindromic Matrix
def main():
H, W, *A = open(0).read().split()
H, W, C = int(H), int(W), {}
for i in "".join(A):
if i not in C:
C[i] = 0
C[i] += 1
single = H & W & 1
double = (H >> 1 if W & 1 else 0) + (W >> 1 if H & 1 else 0)
C_mod4 = [i % 4 for i in list(C.values())]
flg = C_mod4.count(1) + C_mod4.count(3) <= single and C_mod4.count(2) <= double
print(("Yes" if flg else "No"))
if __name__ == "__main__":
main() | 18 | 17 | 530 | 521 | # code-festival-2017-qualaC - Palindromic Matrix
from collections import defaultdict
def main():
H, W, *A = open(0).read().split()
H, W, C = int(H), int(W), defaultdict(int)
for i in "".join(A):
C[i] += 1
single = H & W & 1
double = (H >> 1 if W & 1 else 0) + (W >> 1 if H & 1 else 0)
C_mod4 = [i % 4 for i in list(C.values())]
flg = C_mod4.count(1) + C_mod4.count(3) <= single and C_mod4.count(2) <= double
print(("Yes" if flg else "No"))
if __name__ == "__main__":
main()
| # code-festival-2017-qualaC - Palindromic Matrix
def main():
H, W, *A = open(0).read().split()
H, W, C = int(H), int(W), {}
for i in "".join(A):
if i not in C:
C[i] = 0
C[i] += 1
single = H & W & 1
double = (H >> 1 if W & 1 else 0) + (W >> 1 if H & 1 else 0)
C_mod4 = [i % 4 for i in list(C.values())]
flg = C_mod4.count(1) + C_mod4.count(3) <= single and C_mod4.count(2) <= double
print(("Yes" if flg else "No"))
if __name__ == "__main__":
main()
| false | 5.555556 | [
"-from collections import defaultdict",
"-",
"-",
"- H, W, C = int(H), int(W), defaultdict(int)",
"+ H, W, C = int(H), int(W), {}",
"+ if i not in C:",
"+ C[i] = 0"
]
| false | 0.035749 | 0.035703 | 1.001291 | [
"s635792707",
"s696319772"
]
|
u968846084 | p02679 | python | s063816635 | s586860272 | 1,085 | 763 | 169,444 | 180,044 | Accepted | Accepted | 29.68 | import collections
n=int(eval(input()))
A=[]
AA=[]
B=[]
C=[]
X=[]
mod=10**9+7
p=137053438808121949
for i in range(n):
a,b=list(map(int,input().split()))
if a<0:
a=a*-1
b=b*-1
if a*b>0:
A.append(b*pow(a,p-2,p)%p)
elif a*b<0:
AA.append(a*pow((-b),p-2,p)%p)
else:
if a==0 and b==0:
X.append(i)
elif a==0:
B.append(i)
else:
C.append(i)
D=collections.Counter(A)
DD=collections.Counter(AA)
E=set(list(D)+list(DD))
a=1
for i in E:
a=(a*(2**D[i]+2**DD[i]-1))%mod
a=(a*(2**len(B)+2**len(C)-1)-1)%mod
print(((a+len(X))%mod)) | from math import gcd
from collections import defaultdict
n=int(eval(input()))
A=defaultdict(int)
AA=defaultdict(int)
B=[]
C=[]
X=[]
mod=10**9+7
for i in range(n):
a,b=list(map(int,input().split()))
if a<0:
a=a*-1
b=b*-1
if a*b>0:
l=a*b//gcd(a,b)
A[str(l//b)+":"+str(l//a)]+=1
elif a*b<0:
l=a*(-b)//gcd(a,-b)
AA[str(l//a)+":"+str(l//(-b))]+=1
else:
if a==0 and b==0:
X.append(i)
elif a==0:
B.append(i)
else:
C.append(i)
E=set(list(A.keys())+list(AA.keys()))
a=1
for i in E:
a=(a*(2**A[i]+2**AA[i]-1))%mod
a=(a*(2**len(B)+2**len(C)-1)-1)%mod
print(((a+len(X))%mod)) | 33 | 33 | 590 | 647 | import collections
n = int(eval(input()))
A = []
AA = []
B = []
C = []
X = []
mod = 10**9 + 7
p = 137053438808121949
for i in range(n):
a, b = list(map(int, input().split()))
if a < 0:
a = a * -1
b = b * -1
if a * b > 0:
A.append(b * pow(a, p - 2, p) % p)
elif a * b < 0:
AA.append(a * pow((-b), p - 2, p) % p)
else:
if a == 0 and b == 0:
X.append(i)
elif a == 0:
B.append(i)
else:
C.append(i)
D = collections.Counter(A)
DD = collections.Counter(AA)
E = set(list(D) + list(DD))
a = 1
for i in E:
a = (a * (2 ** D[i] + 2 ** DD[i] - 1)) % mod
a = (a * (2 ** len(B) + 2 ** len(C) - 1) - 1) % mod
print(((a + len(X)) % mod))
| from math import gcd
from collections import defaultdict
n = int(eval(input()))
A = defaultdict(int)
AA = defaultdict(int)
B = []
C = []
X = []
mod = 10**9 + 7
for i in range(n):
a, b = list(map(int, input().split()))
if a < 0:
a = a * -1
b = b * -1
if a * b > 0:
l = a * b // gcd(a, b)
A[str(l // b) + ":" + str(l // a)] += 1
elif a * b < 0:
l = a * (-b) // gcd(a, -b)
AA[str(l // a) + ":" + str(l // (-b))] += 1
else:
if a == 0 and b == 0:
X.append(i)
elif a == 0:
B.append(i)
else:
C.append(i)
E = set(list(A.keys()) + list(AA.keys()))
a = 1
for i in E:
a = (a * (2 ** A[i] + 2 ** AA[i] - 1)) % mod
a = (a * (2 ** len(B) + 2 ** len(C) - 1) - 1) % mod
print(((a + len(X)) % mod))
| false | 0 | [
"-import collections",
"+from math import gcd",
"+from collections import defaultdict",
"-A = []",
"-AA = []",
"+A = defaultdict(int)",
"+AA = defaultdict(int)",
"-p = 137053438808121949",
"- A.append(b * pow(a, p - 2, p) % p)",
"+ l = a * b // gcd(a, b)",
"+ A[str(l // b) + \":\" + str(l // a)] += 1",
"- AA.append(a * pow((-b), p - 2, p) % p)",
"+ l = a * (-b) // gcd(a, -b)",
"+ AA[str(l // a) + \":\" + str(l // (-b))] += 1",
"-D = collections.Counter(A)",
"-DD = collections.Counter(AA)",
"-E = set(list(D) + list(DD))",
"+E = set(list(A.keys()) + list(AA.keys()))",
"- a = (a * (2 ** D[i] + 2 ** DD[i] - 1)) % mod",
"+ a = (a * (2 ** A[i] + 2 ** AA[i] - 1)) % mod"
]
| false | 0.044877 | 0.045022 | 0.99678 | [
"s063816635",
"s586860272"
]
|
u102461423 | p02604 | python | s797913798 | s955543275 | 1,901 | 1,308 | 36,416 | 111,880 | Accepted | Accepted | 31.19 | import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main(XYP):
X, Y, P = XYP[::3], XYP[1::3], XYP[2::3]
N = len(X)
dp_X = np.empty((1 << N, N), np.int64) # 建設、人 -> Xコスト
dp_X[0] = np.abs(X) * P
for n in range(N):
B = 1 << n
dp_X[B:2 * B] = np.minimum(dp_X[:B], np.abs(X - X[n]) * P)
dp_Y = np.empty((1 << N, N), np.int64) # 建設、人 -> Xコスト
dp_Y[0] = np.abs(Y) * P
for n in range(N):
B = 1 << n
dp_Y[B:2 * B] = np.minimum(dp_Y[:B], np.abs(Y - Y[n]) * P)
popcount = np.zeros(1 << N, np.int64)
for n in range(N):
popcount[1 << n:1 << n + 1] = popcount[:1 << n] + 1
INF = 10**18
ans = np.full(N + 1, INF, np.int64)
for s in range(1 << N):
size = popcount[s]
t = s
while True:
u = s ^ t
cost = (np.minimum(dp_X[t], dp_Y[u])).sum()
ans[size] = min(ans[size], cost)
if t == 0:
break
t = (t - 1) & s
return ans
if sys.argv[-1] == 'ONLINE_JUDGE':
import numba
from numba.pycc import CC
i8 = numba.int64
cc = CC('my_module')
def cc_export(f, signature):
cc.export(f.__name__, signature)(f)
return numba.njit(f)
main = cc_export(main, (i8[:], ))
cc.compile()
from my_module import main
N = int(readline())
XYP = np.array(read().split(), np.int64)
ans = main(XYP)
print(('\n'.join(map(str, ans.tolist())))) | import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit((i8[:], i8[:]), cache=True)
def f(X, P):
INF = 10**18
ind = np.argsort(X)
X, P = X[ind], P[ind]
N = len(X)
if N == 0:
return np.array([0], np.int64)
# [0, i) から X[j] までのコストの和
dp1 = np.zeros((N + 1, N), np.int64)
for i in range(N):
for j in range(N):
dp1[i + 1, j] = np.abs(X[i] - X[j]) * P[i]
for i in range(N):
dp1[i + 1] += dp1[i]
# [l, r]をひとまとめにするときのコストの最小値
dp2 = np.empty((N, N), np.int64)
for l in range(N):
for r in range(l, N):
dp2[l, r] = (dp1[r + 1] - dp1[l]).min()
# [0,i] を j 件でとる場合のコストの最小値
dp3 = np.full((N, N + 1), INF, np.int64)
for i in range(N):
dp3[i, 0] = np.sum(X[:i + 1] * P[:i + 1])
dp3[i, 1] = dp2[0, i]
for j in range(i):
# [0,j] + (j,i]
dp3[i, 1:] = np.minimum(dp3[i, 1:], dp3[j, :-1] + dp2[j + 1, i])
return dp3[-1]
@njit((i8[:], i8[:]), cache=True)
def merge(A, B):
LA, LB = len(A), len(B)
INF = 10**18
C = np.full(LA + LB - 1, INF, np.int64)
for i in range(LA):
C[i:i + LB] = np.minimum(C[i:i + LB], A[i] + B)
return C
@njit((i8[:], ), cache=True)
def main(XYP):
X, Y, P = XYP[::3], XYP[1::3], XYP[2::3]
N = len(X)
INF = 10**18
ans = np.full(N + 1, INF, np.int64)
full = (1 << N) - 1
for x in range(1 << N):
i_x = np.bool_([x & (1 << i) for i in range(N)])
i_y = ~i_x
dp = f(X[i_x & (X >= 0)], P[i_x & (X >= 0)])
dp = merge(dp, f(-X[i_x & (X < 0)], P[i_x & (X < 0)]))
dp = merge(dp, f(Y[i_y & (Y >= 0)], P[i_y & (Y >= 0)]))
dp = merge(dp, f(-Y[i_y & (Y < 0)], P[i_y & (Y < 0)]))
ans = np.minimum(ans, dp)
return ans
N = int(readline())
XYP = np.array(read().split(), np.int64)
ans = main(XYP)
print(('\n'.join(map(str, ans.tolist())))) | 60 | 73 | 1,587 | 2,114 | import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main(XYP):
X, Y, P = XYP[::3], XYP[1::3], XYP[2::3]
N = len(X)
dp_X = np.empty((1 << N, N), np.int64) # 建設、人 -> Xコスト
dp_X[0] = np.abs(X) * P
for n in range(N):
B = 1 << n
dp_X[B : 2 * B] = np.minimum(dp_X[:B], np.abs(X - X[n]) * P)
dp_Y = np.empty((1 << N, N), np.int64) # 建設、人 -> Xコスト
dp_Y[0] = np.abs(Y) * P
for n in range(N):
B = 1 << n
dp_Y[B : 2 * B] = np.minimum(dp_Y[:B], np.abs(Y - Y[n]) * P)
popcount = np.zeros(1 << N, np.int64)
for n in range(N):
popcount[1 << n : 1 << n + 1] = popcount[: 1 << n] + 1
INF = 10**18
ans = np.full(N + 1, INF, np.int64)
for s in range(1 << N):
size = popcount[s]
t = s
while True:
u = s ^ t
cost = (np.minimum(dp_X[t], dp_Y[u])).sum()
ans[size] = min(ans[size], cost)
if t == 0:
break
t = (t - 1) & s
return ans
if sys.argv[-1] == "ONLINE_JUDGE":
import numba
from numba.pycc import CC
i8 = numba.int64
cc = CC("my_module")
def cc_export(f, signature):
cc.export(f.__name__, signature)(f)
return numba.njit(f)
main = cc_export(main, (i8[:],))
cc.compile()
from my_module import main
N = int(readline())
XYP = np.array(read().split(), np.int64)
ans = main(XYP)
print(("\n".join(map(str, ans.tolist()))))
| import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit((i8[:], i8[:]), cache=True)
def f(X, P):
INF = 10**18
ind = np.argsort(X)
X, P = X[ind], P[ind]
N = len(X)
if N == 0:
return np.array([0], np.int64)
# [0, i) から X[j] までのコストの和
dp1 = np.zeros((N + 1, N), np.int64)
for i in range(N):
for j in range(N):
dp1[i + 1, j] = np.abs(X[i] - X[j]) * P[i]
for i in range(N):
dp1[i + 1] += dp1[i]
# [l, r]をひとまとめにするときのコストの最小値
dp2 = np.empty((N, N), np.int64)
for l in range(N):
for r in range(l, N):
dp2[l, r] = (dp1[r + 1] - dp1[l]).min()
# [0,i] を j 件でとる場合のコストの最小値
dp3 = np.full((N, N + 1), INF, np.int64)
for i in range(N):
dp3[i, 0] = np.sum(X[: i + 1] * P[: i + 1])
dp3[i, 1] = dp2[0, i]
for j in range(i):
# [0,j] + (j,i]
dp3[i, 1:] = np.minimum(dp3[i, 1:], dp3[j, :-1] + dp2[j + 1, i])
return dp3[-1]
@njit((i8[:], i8[:]), cache=True)
def merge(A, B):
LA, LB = len(A), len(B)
INF = 10**18
C = np.full(LA + LB - 1, INF, np.int64)
for i in range(LA):
C[i : i + LB] = np.minimum(C[i : i + LB], A[i] + B)
return C
@njit((i8[:],), cache=True)
def main(XYP):
X, Y, P = XYP[::3], XYP[1::3], XYP[2::3]
N = len(X)
INF = 10**18
ans = np.full(N + 1, INF, np.int64)
full = (1 << N) - 1
for x in range(1 << N):
i_x = np.bool_([x & (1 << i) for i in range(N)])
i_y = ~i_x
dp = f(X[i_x & (X >= 0)], P[i_x & (X >= 0)])
dp = merge(dp, f(-X[i_x & (X < 0)], P[i_x & (X < 0)]))
dp = merge(dp, f(Y[i_y & (Y >= 0)], P[i_y & (Y >= 0)]))
dp = merge(dp, f(-Y[i_y & (Y < 0)], P[i_y & (Y < 0)]))
ans = np.minimum(ans, dp)
return ans
N = int(readline())
XYP = np.array(read().split(), np.int64)
ans = main(XYP)
print(("\n".join(map(str, ans.tolist()))))
| false | 17.808219 | [
"+import numba",
"+from numba import njit",
"+i8 = numba.int64",
"+@njit((i8[:], i8[:]), cache=True)",
"+def f(X, P):",
"+ INF = 10**18",
"+ ind = np.argsort(X)",
"+ X, P = X[ind], P[ind]",
"+ N = len(X)",
"+ if N == 0:",
"+ return np.array([0], np.int64)",
"+ # [0, i) から X[j] までのコストの和",
"+ dp1 = np.zeros((N + 1, N), np.int64)",
"+ for i in range(N):",
"+ for j in range(N):",
"+ dp1[i + 1, j] = np.abs(X[i] - X[j]) * P[i]",
"+ for i in range(N):",
"+ dp1[i + 1] += dp1[i]",
"+ # [l, r]をひとまとめにするときのコストの最小値",
"+ dp2 = np.empty((N, N), np.int64)",
"+ for l in range(N):",
"+ for r in range(l, N):",
"+ dp2[l, r] = (dp1[r + 1] - dp1[l]).min()",
"+ # [0,i] を j 件でとる場合のコストの最小値",
"+ dp3 = np.full((N, N + 1), INF, np.int64)",
"+ for i in range(N):",
"+ dp3[i, 0] = np.sum(X[: i + 1] * P[: i + 1])",
"+ dp3[i, 1] = dp2[0, i]",
"+ for j in range(i):",
"+ # [0,j] + (j,i]",
"+ dp3[i, 1:] = np.minimum(dp3[i, 1:], dp3[j, :-1] + dp2[j + 1, i])",
"+ return dp3[-1]",
"+",
"+",
"+@njit((i8[:], i8[:]), cache=True)",
"+def merge(A, B):",
"+ LA, LB = len(A), len(B)",
"+ INF = 10**18",
"+ C = np.full(LA + LB - 1, INF, np.int64)",
"+ for i in range(LA):",
"+ C[i : i + LB] = np.minimum(C[i : i + LB], A[i] + B)",
"+ return C",
"+",
"+",
"+@njit((i8[:],), cache=True)",
"- dp_X = np.empty((1 << N, N), np.int64) # 建設、人 -> Xコスト",
"- dp_X[0] = np.abs(X) * P",
"- for n in range(N):",
"- B = 1 << n",
"- dp_X[B : 2 * B] = np.minimum(dp_X[:B], np.abs(X - X[n]) * P)",
"- dp_Y = np.empty((1 << N, N), np.int64) # 建設、人 -> Xコスト",
"- dp_Y[0] = np.abs(Y) * P",
"- for n in range(N):",
"- B = 1 << n",
"- dp_Y[B : 2 * B] = np.minimum(dp_Y[:B], np.abs(Y - Y[n]) * P)",
"- popcount = np.zeros(1 << N, np.int64)",
"- for n in range(N):",
"- popcount[1 << n : 1 << n + 1] = popcount[: 1 << n] + 1",
"- for s in range(1 << N):",
"- size = popcount[s]",
"- t = s",
"- while True:",
"- u = s ^ t",
"- cost = (np.minimum(dp_X[t], dp_Y[u])).sum()",
"- ans[size] = min(ans[size], cost)",
"- if t == 0:",
"- break",
"- t = (t - 1) & s",
"+ full = (1 << N) - 1",
"+ for x in range(1 << N):",
"+ i_x = np.bool_([x & (1 << i) for i in range(N)])",
"+ i_y = ~i_x",
"+ dp = f(X[i_x & (X >= 0)], P[i_x & (X >= 0)])",
"+ dp = merge(dp, f(-X[i_x & (X < 0)], P[i_x & (X < 0)]))",
"+ dp = merge(dp, f(Y[i_y & (Y >= 0)], P[i_y & (Y >= 0)]))",
"+ dp = merge(dp, f(-Y[i_y & (Y < 0)], P[i_y & (Y < 0)]))",
"+ ans = np.minimum(ans, dp)",
"-",
"-if sys.argv[-1] == \"ONLINE_JUDGE\":",
"- import numba",
"- from numba.pycc import CC",
"-",
"- i8 = numba.int64",
"- cc = CC(\"my_module\")",
"-",
"- def cc_export(f, signature):",
"- cc.export(f.__name__, signature)(f)",
"- return numba.njit(f)",
"-",
"- main = cc_export(main, (i8[:],))",
"- cc.compile()",
"-from my_module import main"
]
| false | 0.498015 | 0.242792 | 2.0512 | [
"s797913798",
"s955543275"
]
|
u678167152 | p03244 | python | s818984659 | s944128181 | 95 | 83 | 16,100 | 25,256 | Accepted | Accepted | 12.63 | n = int(eval(input()))
v = list(map(int, input().split()))
from collections import Counter
def minus(lis):
if len(set(lis))==1:
return lis[0], 0, 10**9
c = Counter(lis)
f_key = max(c, key=c.get)
second,first = sorted(c.values())[-2:]
return f_key,len(lis)-first,len(lis)-second
def solve(n,v):
if len(set(v))==1:
return n//2
Odd = [v[i] for i in range(n) if i%2==1]
Even = [v[i] for i in range(n) if i%2==0]
odd_key, odd_f,odd_s = minus(Odd)
# print(odd_key, odd_f,odd_s)
even_key, even_f,even_s = minus(Even)
if odd_key == even_key:
return min(odd_f+even_s,even_f+odd_s)
# print(odd,even)
return odd_f + even_f
print((solve(n,v))) | from collections import Counter
def solve():
ans = 0
N = int(eval(input()))
V = list(map(int, input().split()))
V1 = [V[i] for i in range(0,N,2)]
V2 = [V[i] for i in range(1,N,2)]
v1 = Counter(V1)
v2 = Counter(V2)
v1 = sorted(list(v1.items()),key=lambda x:-x[1])
v2 = sorted(list(v2.items()),key=lambda x:-x[1])
if v1[0][0]!=v2[0][0]:
ans = N-(v1[0][1]+v2[0][1])
else:
if len(v1)==1:
if len(v2)==1:
return N//2
return N-(v1[0][1]+v2[1][1])
if len(v2)==1:
return N-(v1[1][1]+v2[0][1])
ans = N-max(v1[1][1]+v2[0][1],v1[0][1]+v2[1][1])
return ans
print((solve())) | 26 | 23 | 731 | 628 | n = int(eval(input()))
v = list(map(int, input().split()))
from collections import Counter
def minus(lis):
if len(set(lis)) == 1:
return lis[0], 0, 10**9
c = Counter(lis)
f_key = max(c, key=c.get)
second, first = sorted(c.values())[-2:]
return f_key, len(lis) - first, len(lis) - second
def solve(n, v):
if len(set(v)) == 1:
return n // 2
Odd = [v[i] for i in range(n) if i % 2 == 1]
Even = [v[i] for i in range(n) if i % 2 == 0]
odd_key, odd_f, odd_s = minus(Odd)
# print(odd_key, odd_f,odd_s)
even_key, even_f, even_s = minus(Even)
if odd_key == even_key:
return min(odd_f + even_s, even_f + odd_s)
# print(odd,even)
return odd_f + even_f
print((solve(n, v)))
| from collections import Counter
def solve():
ans = 0
N = int(eval(input()))
V = list(map(int, input().split()))
V1 = [V[i] for i in range(0, N, 2)]
V2 = [V[i] for i in range(1, N, 2)]
v1 = Counter(V1)
v2 = Counter(V2)
v1 = sorted(list(v1.items()), key=lambda x: -x[1])
v2 = sorted(list(v2.items()), key=lambda x: -x[1])
if v1[0][0] != v2[0][0]:
ans = N - (v1[0][1] + v2[0][1])
else:
if len(v1) == 1:
if len(v2) == 1:
return N // 2
return N - (v1[0][1] + v2[1][1])
if len(v2) == 1:
return N - (v1[1][1] + v2[0][1])
ans = N - max(v1[1][1] + v2[0][1], v1[0][1] + v2[1][1])
return ans
print((solve()))
| false | 11.538462 | [
"-n = int(eval(input()))",
"-v = list(map(int, input().split()))",
"-def minus(lis):",
"- if len(set(lis)) == 1:",
"- return lis[0], 0, 10**9",
"- c = Counter(lis)",
"- f_key = max(c, key=c.get)",
"- second, first = sorted(c.values())[-2:]",
"- return f_key, len(lis) - first, len(lis) - second",
"+def solve():",
"+ ans = 0",
"+ N = int(eval(input()))",
"+ V = list(map(int, input().split()))",
"+ V1 = [V[i] for i in range(0, N, 2)]",
"+ V2 = [V[i] for i in range(1, N, 2)]",
"+ v1 = Counter(V1)",
"+ v2 = Counter(V2)",
"+ v1 = sorted(list(v1.items()), key=lambda x: -x[1])",
"+ v2 = sorted(list(v2.items()), key=lambda x: -x[1])",
"+ if v1[0][0] != v2[0][0]:",
"+ ans = N - (v1[0][1] + v2[0][1])",
"+ else:",
"+ if len(v1) == 1:",
"+ if len(v2) == 1:",
"+ return N // 2",
"+ return N - (v1[0][1] + v2[1][1])",
"+ if len(v2) == 1:",
"+ return N - (v1[1][1] + v2[0][1])",
"+ ans = N - max(v1[1][1] + v2[0][1], v1[0][1] + v2[1][1])",
"+ return ans",
"-def solve(n, v):",
"- if len(set(v)) == 1:",
"- return n // 2",
"- Odd = [v[i] for i in range(n) if i % 2 == 1]",
"- Even = [v[i] for i in range(n) if i % 2 == 0]",
"- odd_key, odd_f, odd_s = minus(Odd)",
"- # print(odd_key, odd_f,odd_s)",
"- even_key, even_f, even_s = minus(Even)",
"- if odd_key == even_key:",
"- return min(odd_f + even_s, even_f + odd_s)",
"- # print(odd,even)",
"- return odd_f + even_f",
"-",
"-",
"-print((solve(n, v)))",
"+print((solve()))"
]
| false | 0.048864 | 0.142556 | 0.342772 | [
"s818984659",
"s944128181"
]
|
u893063840 | p03722 | python | s522420651 | s938098895 | 1,410 | 1,235 | 3,572 | 3,572 | Accepted | Accepted | 12.41 | n, m = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
def bellman_ford(s, g):
dist = [float("inf")] * n
dist[s] = 0
negative = [False] * n
for i in range(2 * n):
for a, b, c in abc:
a -= 1
b -= 1
c = -c
if dist[b] > dist[a] + c:
dist[b] = dist[a] + c
if i >= n:
negative[b] = True
if negative[g]:
ret = "inf"
else:
ret = -dist[g]
return ret
ans = bellman_ford(0, n - 1)
print(ans)
| n, m = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
def bellman_ford(s, g):
# loop 0 - (n-1) : bellman ford
# loop n - (2n-1): check g can be updated
dist = [float("inf")] * n
dist[s] = 0
for i in range(2 * n):
for a, b, c in abc:
a -= 1
b -= 1
c = -c
if dist[b] > dist[a] + c:
dist[b] = dist[a] + c
if i >= n:
dist[b] = -float("inf")
if dist[g] == -float("inf"):
ret = "inf"
else:
ret = -dist[g]
return ret
ans = bellman_ford(0, n - 1)
print(ans)
| 30 | 31 | 493 | 564 | n, m = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
def bellman_ford(s, g):
dist = [float("inf")] * n
dist[s] = 0
negative = [False] * n
for i in range(2 * n):
for a, b, c in abc:
a -= 1
b -= 1
c = -c
if dist[b] > dist[a] + c:
dist[b] = dist[a] + c
if i >= n:
negative[b] = True
if negative[g]:
ret = "inf"
else:
ret = -dist[g]
return ret
ans = bellman_ford(0, n - 1)
print(ans)
| n, m = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(m)]
def bellman_ford(s, g):
# loop 0 - (n-1) : bellman ford
# loop n - (2n-1): check g can be updated
dist = [float("inf")] * n
dist[s] = 0
for i in range(2 * n):
for a, b, c in abc:
a -= 1
b -= 1
c = -c
if dist[b] > dist[a] + c:
dist[b] = dist[a] + c
if i >= n:
dist[b] = -float("inf")
if dist[g] == -float("inf"):
ret = "inf"
else:
ret = -dist[g]
return ret
ans = bellman_ford(0, n - 1)
print(ans)
| false | 3.225806 | [
"+ # loop 0 - (n-1) : bellman ford",
"+ # loop n - (2n-1): check g can be updated",
"- negative = [False] * n",
"- negative[b] = True",
"- if negative[g]:",
"+ dist[b] = -float(\"inf\")",
"+ if dist[g] == -float(\"inf\"):"
]
| false | 0.142724 | 0.046366 | 3.078184 | [
"s522420651",
"s938098895"
]
|
u682672120 | p03044 | python | s595146867 | s642724710 | 544 | 368 | 97,632 | 95,776 | Accepted | Accepted | 32.35 | import queue
n = int(eval(input()))
node = [[] for _ in range(n)]
color = [-1] * n
color[0] = 0
for _ in range(n-1):
u, v, w = list(map(int, input().split()))
node[u-1].append((v-1, w))
node[v-1].append((u-1, w))
q = queue.Queue()
q.put(0)
while not q.empty():
i = q.get()
c = color[i]
for j, w in node[i]:
if color[j] < 0:
color[j] = c if w % 2 == 0 else (c + 1) % 2
q.put(j)
for c in color:
print(c)
| from collections import deque
n = int(eval(input()))
tree = [[] for _ in range(n)]
for _ in range(n-1):
u, v, w = list(map(int, input().split()))
u -= 1
v -= 1
tree[u].append((v, w % 2))
tree[v].append((u, w % 2))
q = deque()
q.append(0)
color = [-1] * n
color[0] = 0
while q:
v = q.popleft()
for child, w in tree[v]:
if color[child] < 0:
color[child] = (color[v] + w) % 2
q.append(child)
for i in color:
print(i)
| 26 | 25 | 484 | 497 | import queue
n = int(eval(input()))
node = [[] for _ in range(n)]
color = [-1] * n
color[0] = 0
for _ in range(n - 1):
u, v, w = list(map(int, input().split()))
node[u - 1].append((v - 1, w))
node[v - 1].append((u - 1, w))
q = queue.Queue()
q.put(0)
while not q.empty():
i = q.get()
c = color[i]
for j, w in node[i]:
if color[j] < 0:
color[j] = c if w % 2 == 0 else (c + 1) % 2
q.put(j)
for c in color:
print(c)
| from collections import deque
n = int(eval(input()))
tree = [[] for _ in range(n)]
for _ in range(n - 1):
u, v, w = list(map(int, input().split()))
u -= 1
v -= 1
tree[u].append((v, w % 2))
tree[v].append((u, w % 2))
q = deque()
q.append(0)
color = [-1] * n
color[0] = 0
while q:
v = q.popleft()
for child, w in tree[v]:
if color[child] < 0:
color[child] = (color[v] + w) % 2
q.append(child)
for i in color:
print(i)
| false | 3.846154 | [
"-import queue",
"+from collections import deque",
"-node = [[] for _ in range(n)]",
"+tree = [[] for _ in range(n)]",
"+for _ in range(n - 1):",
"+ u, v, w = list(map(int, input().split()))",
"+ u -= 1",
"+ v -= 1",
"+ tree[u].append((v, w % 2))",
"+ tree[v].append((u, w % 2))",
"+q = deque()",
"+q.append(0)",
"-for _ in range(n - 1):",
"- u, v, w = list(map(int, input().split()))",
"- node[u - 1].append((v - 1, w))",
"- node[v - 1].append((u - 1, w))",
"-q = queue.Queue()",
"-q.put(0)",
"-while not q.empty():",
"- i = q.get()",
"- c = color[i]",
"- for j, w in node[i]:",
"- if color[j] < 0:",
"- color[j] = c if w % 2 == 0 else (c + 1) % 2",
"- q.put(j)",
"-for c in color:",
"- print(c)",
"+while q:",
"+ v = q.popleft()",
"+ for child, w in tree[v]:",
"+ if color[child] < 0:",
"+ color[child] = (color[v] + w) % 2",
"+ q.append(child)",
"+for i in color:",
"+ print(i)"
]
| false | 0.07 | 0.03512 | 1.993182 | [
"s595146867",
"s642724710"
]
|
u784022244 | p02845 | python | s921174431 | s591372648 | 130 | 87 | 20,708 | 85,324 | Accepted | Accepted | 33.08 | N=int(eval(input()))
A=list(map(int, input().split()))
mod=10**9+7
if A[0]!=0:
print((0))
exit()
L=[1,0,0]
ans=3
for i in range(1,N):
a=A[i]
count=0
add=True
for j,l in enumerate(L):
if a==l:
count+=1
if add:
L[j]+=1
add=False
ans*=count
ans%=mod
print(ans)
#print(L)
| N=int(eval(input()))
A=list(map(int, input().split()))
p=10**9+7
if A[0]!=0:
print((0))
exit()
dp=[0]*N
dp[0]=3
counts=[0]*N #前が何人か(自分が*人目)
counts[0]=1
for i in range(1,N):
a=A[i]
if a==0:
dp[i]=(dp[i-1]*(3 - counts[a]))%p
else:
dp[i]=(dp[i-1]*(counts[a-1] - counts[a]))%p
counts[a]+=1
print((dp[-1]))
| 23 | 24 | 379 | 373 | N = int(eval(input()))
A = list(map(int, input().split()))
mod = 10**9 + 7
if A[0] != 0:
print((0))
exit()
L = [1, 0, 0]
ans = 3
for i in range(1, N):
a = A[i]
count = 0
add = True
for j, l in enumerate(L):
if a == l:
count += 1
if add:
L[j] += 1
add = False
ans *= count
ans %= mod
print(ans)
# print(L)
| N = int(eval(input()))
A = list(map(int, input().split()))
p = 10**9 + 7
if A[0] != 0:
print((0))
exit()
dp = [0] * N
dp[0] = 3
counts = [0] * N # 前が何人か(自分が*人目)
counts[0] = 1
for i in range(1, N):
a = A[i]
if a == 0:
dp[i] = (dp[i - 1] * (3 - counts[a])) % p
else:
dp[i] = (dp[i - 1] * (counts[a - 1] - counts[a])) % p
counts[a] += 1
print((dp[-1]))
| false | 4.166667 | [
"-mod = 10**9 + 7",
"+p = 10**9 + 7",
"-L = [1, 0, 0]",
"-ans = 3",
"+dp = [0] * N",
"+dp[0] = 3",
"+counts = [0] * N # 前が何人か(自分が*人目)",
"+counts[0] = 1",
"- count = 0",
"- add = True",
"- for j, l in enumerate(L):",
"- if a == l:",
"- count += 1",
"- if add:",
"- L[j] += 1",
"- add = False",
"- ans *= count",
"- ans %= mod",
"-print(ans)",
"-# print(L)",
"+ if a == 0:",
"+ dp[i] = (dp[i - 1] * (3 - counts[a])) % p",
"+ else:",
"+ dp[i] = (dp[i - 1] * (counts[a - 1] - counts[a])) % p",
"+ counts[a] += 1",
"+print((dp[-1]))"
]
| false | 0.106731 | 0.042559 | 2.507847 | [
"s921174431",
"s591372648"
]
|
u810356688 | p03196 | python | s028430971 | s109404439 | 230 | 179 | 13,188 | 38,512 | Accepted | Accepted | 22.17 | import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def prime_fact(m):
pf={}
for i in range(2,int(m**0.5)+1):
while m%i==0:
pf[i]=pf.get(i,0)+1
m//=i
if m>1:pf[m]=1
return pf
def main():
n,p=list(map(int,input().split()))
p_dict=prime_fact(p)
ans=1
for pp in list(p_dict.items()):
ans*=pp[0]**(pp[1]//n)
print(ans)
if __name__=='__main__':
main() | import sys
def input(): return sys.stdin.readline().rstrip()
def prime_fact(m):
pf={}
for i in range(2,int(m**0.5)+1):
while m%i==0:
pf[i]=pf.get(i,0)+1
m//=i
if m>1:pf[m]=1
return pf
def main():
n,p=list(map(int,input().split()))
p_dict=prime_fact(p)
ans=1
for pp in list(p_dict.items()):
ans*=pp[0]**(pp[1]//n)
print(ans)
if __name__=='__main__':
main() | 22 | 21 | 465 | 445 | import sys
def input():
return sys.stdin.readline().rstrip()
import numpy as np
def prime_fact(m):
pf = {}
for i in range(2, int(m**0.5) + 1):
while m % i == 0:
pf[i] = pf.get(i, 0) + 1
m //= i
if m > 1:
pf[m] = 1
return pf
def main():
n, p = list(map(int, input().split()))
p_dict = prime_fact(p)
ans = 1
for pp in list(p_dict.items()):
ans *= pp[0] ** (pp[1] // n)
print(ans)
if __name__ == "__main__":
main()
| import sys
def input():
return sys.stdin.readline().rstrip()
def prime_fact(m):
pf = {}
for i in range(2, int(m**0.5) + 1):
while m % i == 0:
pf[i] = pf.get(i, 0) + 1
m //= i
if m > 1:
pf[m] = 1
return pf
def main():
n, p = list(map(int, input().split()))
p_dict = prime_fact(p)
ans = 1
for pp in list(p_dict.items()):
ans *= pp[0] ** (pp[1] // n)
print(ans)
if __name__ == "__main__":
main()
| false | 4.545455 | [
"-",
"-",
"-import numpy as np"
]
| false | 0.032737 | 0.033333 | 0.98211 | [
"s028430971",
"s109404439"
]
|
u977389981 | p03000 | python | s924289848 | s192334612 | 189 | 17 | 38,384 | 2,940 | Accepted | Accepted | 91.01 | import bisect
N, X = list(map(int, input().split()))
L = [int(i) for i in input().split()]
D = [0] * (N + 1)
for i in range(N):
D[i + 1] = D[i] + L[i]
print((bisect.bisect_right(D, X))) | n, x = list(map(int, input().split()))
L = list(map(int, input().split()))
ans = 1
d = 0
for l in L:
d = d + l
if d <= x:
ans += 1
else:
break
print(ans) | 11 | 13 | 199 | 197 | import bisect
N, X = list(map(int, input().split()))
L = [int(i) for i in input().split()]
D = [0] * (N + 1)
for i in range(N):
D[i + 1] = D[i] + L[i]
print((bisect.bisect_right(D, X)))
| n, x = list(map(int, input().split()))
L = list(map(int, input().split()))
ans = 1
d = 0
for l in L:
d = d + l
if d <= x:
ans += 1
else:
break
print(ans)
| false | 15.384615 | [
"-import bisect",
"-",
"-N, X = list(map(int, input().split()))",
"-L = [int(i) for i in input().split()]",
"-D = [0] * (N + 1)",
"-for i in range(N):",
"- D[i + 1] = D[i] + L[i]",
"-print((bisect.bisect_right(D, X)))",
"+n, x = list(map(int, input().split()))",
"+L = list(map(int, input().split()))",
"+ans = 1",
"+d = 0",
"+for l in L:",
"+ d = d + l",
"+ if d <= x:",
"+ ans += 1",
"+ else:",
"+ break",
"+print(ans)"
]
| false | 0.03506 | 0.035103 | 0.998782 | [
"s924289848",
"s192334612"
]
|
u691501673 | p03164 | python | s667875187 | s355126286 | 795 | 582 | 326,784 | 235,540 | Accepted | Accepted | 26.79 | import sys
# input処理を高速化する
input = sys.stdin.readline
# 入力
N, W = list(map(int, input().split()))
array = [list(map(int, input().split())) for _ in range(N)] # [重さ、価値]
# sum_vの取りうる上限値
# MAX_V = (10**3 + 1) * N
MAX_V = 0
for line in array:
MAX_V += line[1]
MAX_V += 1
# 最小値を求めるので無限大の値
f_inf = float('inf')
def chmin(a, b):
if a <= b:
return a
else:
return b
def knapsack(n, w):
# dpの初期化 dp[i][sum_v]は重さの総和の最小値
dp = [[f_inf] * MAX_V for j in range(N + 1)]
# 初期条件
dp[0][0] = 0
# forは全て関数の中で回す。
# 入力
for i in range(N):
# w, v = map(int, input().split())
for sum_v in range(MAX_V):
# i番目の品物を選ぶ場合
if sum_v - array[i][1] >= 0:
dp[i + 1][sum_v] = chmin(dp[i + 1][sum_v],
dp[i][sum_v - array[i][1]] + array[i][0])
# i番目の品物を選ばない場合
dp[i + 1][sum_v] = chmin(dp[i + 1][sum_v], dp[i][sum_v])
# dp[N][sum_v]の値が、W以下であるsum_vの値の最大値
ans = 0
for sum_v in range(MAX_V):
if dp[N][sum_v] <= W:
ans = sum_v
print(ans)
knapsack(N, W)
| # N個、重さW
N, W = list(map(int, input().split()))
# 重さ, 価値
array = [list(map(int, input().split())) for _ in range(N)]
# 価値の最大値
sum = 1
for i in range(N):
sum += array[i][1]
weights = [[float('inf')] * (sum + 1) for _ in range(N + 1)]
# 初期値
weights[0][0] = 0
# 価値ごとの重さの最小値を出す
for n in range(N):
# 価値が0..1000までのそれぞれについて、価値を超えているうちの重さの最小値を算出する
for v in range(sum + 1):
# n回目の品物を持ち帰らない場合の重量
weights[n + 1][v] = weights[n][v]
weight = weights[n][v - array[n][1]] + array[n][0]
if weight < weights[n + 1][v]:
weights[n + 1][v] = weight
ans = 0
for i in range(sum):
if weights[N][i] <= W:
ans = i
print(f"{ans}")
| 48 | 29 | 1,170 | 699 | import sys
# input処理を高速化する
input = sys.stdin.readline
# 入力
N, W = list(map(int, input().split()))
array = [list(map(int, input().split())) for _ in range(N)] # [重さ、価値]
# sum_vの取りうる上限値
# MAX_V = (10**3 + 1) * N
MAX_V = 0
for line in array:
MAX_V += line[1]
MAX_V += 1
# 最小値を求めるので無限大の値
f_inf = float("inf")
def chmin(a, b):
if a <= b:
return a
else:
return b
def knapsack(n, w):
# dpの初期化 dp[i][sum_v]は重さの総和の最小値
dp = [[f_inf] * MAX_V for j in range(N + 1)]
# 初期条件
dp[0][0] = 0
# forは全て関数の中で回す。
# 入力
for i in range(N):
# w, v = map(int, input().split())
for sum_v in range(MAX_V):
# i番目の品物を選ぶ場合
if sum_v - array[i][1] >= 0:
dp[i + 1][sum_v] = chmin(
dp[i + 1][sum_v], dp[i][sum_v - array[i][1]] + array[i][0]
)
# i番目の品物を選ばない場合
dp[i + 1][sum_v] = chmin(dp[i + 1][sum_v], dp[i][sum_v])
# dp[N][sum_v]の値が、W以下であるsum_vの値の最大値
ans = 0
for sum_v in range(MAX_V):
if dp[N][sum_v] <= W:
ans = sum_v
print(ans)
knapsack(N, W)
| # N個、重さW
N, W = list(map(int, input().split()))
# 重さ, 価値
array = [list(map(int, input().split())) for _ in range(N)]
# 価値の最大値
sum = 1
for i in range(N):
sum += array[i][1]
weights = [[float("inf")] * (sum + 1) for _ in range(N + 1)]
# 初期値
weights[0][0] = 0
# 価値ごとの重さの最小値を出す
for n in range(N):
# 価値が0..1000までのそれぞれについて、価値を超えているうちの重さの最小値を算出する
for v in range(sum + 1):
# n回目の品物を持ち帰らない場合の重量
weights[n + 1][v] = weights[n][v]
weight = weights[n][v - array[n][1]] + array[n][0]
if weight < weights[n + 1][v]:
weights[n + 1][v] = weight
ans = 0
for i in range(sum):
if weights[N][i] <= W:
ans = i
print(f"{ans}")
| false | 39.583333 | [
"-import sys",
"-",
"-# input処理を高速化する",
"-input = sys.stdin.readline",
"-# 入力",
"+# N個、重さW",
"-array = [list(map(int, input().split())) for _ in range(N)] # [重さ、価値]",
"-# sum_vの取りうる上限値",
"-# MAX_V = (10**3 + 1) * N",
"-MAX_V = 0",
"-for line in array:",
"- MAX_V += line[1]",
"-MAX_V += 1",
"-# 最小値を求めるので無限大の値",
"-f_inf = float(\"inf\")",
"-",
"-",
"-def chmin(a, b):",
"- if a <= b:",
"- return a",
"- else:",
"- return b",
"-",
"-",
"-def knapsack(n, w):",
"- # dpの初期化 dp[i][sum_v]は重さの総和の最小値",
"- dp = [[f_inf] * MAX_V for j in range(N + 1)]",
"- # 初期条件",
"- dp[0][0] = 0",
"- # forは全て関数の中で回す。",
"- # 入力",
"- for i in range(N):",
"- # w, v = map(int, input().split())",
"- for sum_v in range(MAX_V):",
"- # i番目の品物を選ぶ場合",
"- if sum_v - array[i][1] >= 0:",
"- dp[i + 1][sum_v] = chmin(",
"- dp[i + 1][sum_v], dp[i][sum_v - array[i][1]] + array[i][0]",
"- )",
"- # i番目の品物を選ばない場合",
"- dp[i + 1][sum_v] = chmin(dp[i + 1][sum_v], dp[i][sum_v])",
"- # dp[N][sum_v]の値が、W以下であるsum_vの値の最大値",
"- ans = 0",
"- for sum_v in range(MAX_V):",
"- if dp[N][sum_v] <= W:",
"- ans = sum_v",
"- print(ans)",
"-",
"-",
"-knapsack(N, W)",
"+# 重さ, 価値",
"+array = [list(map(int, input().split())) for _ in range(N)]",
"+# 価値の最大値",
"+sum = 1",
"+for i in range(N):",
"+ sum += array[i][1]",
"+weights = [[float(\"inf\")] * (sum + 1) for _ in range(N + 1)]",
"+# 初期値",
"+weights[0][0] = 0",
"+# 価値ごとの重さの最小値を出す",
"+for n in range(N):",
"+ # 価値が0..1000までのそれぞれについて、価値を超えているうちの重さの最小値を算出する",
"+ for v in range(sum + 1):",
"+ # n回目の品物を持ち帰らない場合の重量",
"+ weights[n + 1][v] = weights[n][v]",
"+ weight = weights[n][v - array[n][1]] + array[n][0]",
"+ if weight < weights[n + 1][v]:",
"+ weights[n + 1][v] = weight",
"+ans = 0",
"+for i in range(sum):",
"+ if weights[N][i] <= W:",
"+ ans = i",
"+print(f\"{ans}\")"
]
| false | 0.033947 | 0.036691 | 0.925212 | [
"s667875187",
"s355126286"
]
|
u970308980 | p03329 | python | s317414863 | s591365442 | 1,435 | 1,314 | 3,828 | 3,864 | Accepted | Accepted | 8.43 | N = int(eval(input()))
INF = float('inf')
dp = [INF] * (N+1)
dp[0] = 0
for n in range(N + 1):
power = 0
while pow(6, power) <= n:
dp[n] = min(dp[n], dp[n - pow(6, power)] + 1)
power += 1
power = 0
while pow(9, power) <= n:
dp[n] = min(dp[n], dp[n - pow(9, power)] + 1)
power += 1
print((dp[N]))
| N = int(eval(input()))
INF = float('inf')
dp = [INF for _ in range(N+1)]
dp[0] = 0
for n in range(N + 1):
power = 0
while pow(6, power) <= n:
dp[n] = min(dp[n], dp[n - pow(6, power)] + 1)
power += 1
power = 0
while pow(9, power) <= n:
dp[n] = min(dp[n], dp[n - pow(9, power)] + 1)
power += 1
print((dp[N]))
| 17 | 17 | 354 | 366 | N = int(eval(input()))
INF = float("inf")
dp = [INF] * (N + 1)
dp[0] = 0
for n in range(N + 1):
power = 0
while pow(6, power) <= n:
dp[n] = min(dp[n], dp[n - pow(6, power)] + 1)
power += 1
power = 0
while pow(9, power) <= n:
dp[n] = min(dp[n], dp[n - pow(9, power)] + 1)
power += 1
print((dp[N]))
| N = int(eval(input()))
INF = float("inf")
dp = [INF for _ in range(N + 1)]
dp[0] = 0
for n in range(N + 1):
power = 0
while pow(6, power) <= n:
dp[n] = min(dp[n], dp[n - pow(6, power)] + 1)
power += 1
power = 0
while pow(9, power) <= n:
dp[n] = min(dp[n], dp[n - pow(9, power)] + 1)
power += 1
print((dp[N]))
| false | 0 | [
"-dp = [INF] * (N + 1)",
"+dp = [INF for _ in range(N + 1)]"
]
| false | 0.836414 | 0.849288 | 0.984842 | [
"s317414863",
"s591365442"
]
|
u281303342 | p03721 | python | s394478507 | s698319728 | 410 | 220 | 16,940 | 30,124 | Accepted | Accepted | 46.34 | N,K = list(map(int,input().split()))
AB = []
for i in range(N):
a,b = list(map(int,input().split()))
AB.append((a,b))
AB.sort()
cnt = 0
for ab in AB:
a,b = ab
cnt += b
if cnt >= K:
print(a)
break
| # atcoder : python3 (3.4.3)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod = 10**9+7
# main
N,K = list(map(int,input().split()))
AB = [list(map(int,input().split())) for _ in range(N)]
Cnt = [0]*(10**5+1)
for a,b in AB:
Cnt[a] += b
i = 1
for ci in range(len(Cnt)):
if i <= K < i+Cnt[ci]:
print(ci)
sys.exit()
else:
i += Cnt[ci] | 15 | 21 | 236 | 404 | N, K = list(map(int, input().split()))
AB = []
for i in range(N):
a, b = list(map(int, input().split()))
AB.append((a, b))
AB.sort()
cnt = 0
for ab in AB:
a, b = ab
cnt += b
if cnt >= K:
print(a)
break
| # atcoder : python3 (3.4.3)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod = 10**9 + 7
# main
N, K = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
Cnt = [0] * (10**5 + 1)
for a, b in AB:
Cnt[a] += b
i = 1
for ci in range(len(Cnt)):
if i <= K < i + Cnt[ci]:
print(ci)
sys.exit()
else:
i += Cnt[ci]
| false | 28.571429 | [
"+# atcoder : python3 (3.4.3)",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+sys.setrecursionlimit(10**6)",
"+mod = 10**9 + 7",
"+# main",
"-AB = []",
"-for i in range(N):",
"- a, b = list(map(int, input().split()))",
"- AB.append((a, b))",
"-AB.sort()",
"-cnt = 0",
"-for ab in AB:",
"- a, b = ab",
"- cnt += b",
"- if cnt >= K:",
"- print(a)",
"- break",
"+AB = [list(map(int, input().split())) for _ in range(N)]",
"+Cnt = [0] * (10**5 + 1)",
"+for a, b in AB:",
"+ Cnt[a] += b",
"+i = 1",
"+for ci in range(len(Cnt)):",
"+ if i <= K < i + Cnt[ci]:",
"+ print(ci)",
"+ sys.exit()",
"+ else:",
"+ i += Cnt[ci]"
]
| false | 0.035569 | 0.033185 | 1.071849 | [
"s394478507",
"s698319728"
]
|
u134302690 | p03220 | python | s314451788 | s260522012 | 184 | 18 | 38,384 | 3,060 | Accepted | Accepted | 90.22 | n = int(eval(input()))
t,a = list(map(int,input().split()))
h = list(map(int,input().split()))
for i,ave in enumerate(h):
h[i] = abs(a-(t-h[i]*0.006))
ans = h.index(min(h))+1
print(ans)
| N = int(eval(input()))
T,A = list(map(int,input().split()))
H = list(map(int,input().split()))
count = 10**9
ans = 0
for i in range(N):
aveT = abs(A- (T - 0.006 * H[i]))
if count >= aveT:
count = aveT
ans = i+1
print(ans) | 7 | 11 | 184 | 243 | n = int(eval(input()))
t, a = list(map(int, input().split()))
h = list(map(int, input().split()))
for i, ave in enumerate(h):
h[i] = abs(a - (t - h[i] * 0.006))
ans = h.index(min(h)) + 1
print(ans)
| N = int(eval(input()))
T, A = list(map(int, input().split()))
H = list(map(int, input().split()))
count = 10**9
ans = 0
for i in range(N):
aveT = abs(A - (T - 0.006 * H[i]))
if count >= aveT:
count = aveT
ans = i + 1
print(ans)
| false | 36.363636 | [
"-n = int(eval(input()))",
"-t, a = list(map(int, input().split()))",
"-h = list(map(int, input().split()))",
"-for i, ave in enumerate(h):",
"- h[i] = abs(a - (t - h[i] * 0.006))",
"-ans = h.index(min(h)) + 1",
"+N = int(eval(input()))",
"+T, A = list(map(int, input().split()))",
"+H = list(map(int, input().split()))",
"+count = 10**9",
"+ans = 0",
"+for i in range(N):",
"+ aveT = abs(A - (T - 0.006 * H[i]))",
"+ if count >= aveT:",
"+ count = aveT",
"+ ans = i + 1"
]
| false | 0.117676 | 0.043598 | 2.699139 | [
"s314451788",
"s260522012"
]
|
u514401521 | p02708 | python | s276379772 | s594901212 | 116 | 95 | 9,184 | 9,192 | Accepted | Accepted | 18.1 | N, K = list(map(int, input().split()))
M = 10**9 + 7
ans = 0
for i in range(K, N+2):
_min = (i-1)*i//2
_max = (N + N-i+1) * i //2
ans += (_max - _min + 1)
print((ans % M)) | N, K = list(map(int, input().split()))
ans = 0
mod = 10**9+7
for i in range(K, N+2):
min = i*(i-1)/2
max = (2*N-i+1)*i/2
ans += max - min + 1
print((int(ans%mod))) | 8 | 9 | 186 | 176 | N, K = list(map(int, input().split()))
M = 10**9 + 7
ans = 0
for i in range(K, N + 2):
_min = (i - 1) * i // 2
_max = (N + N - i + 1) * i // 2
ans += _max - _min + 1
print((ans % M))
| N, K = list(map(int, input().split()))
ans = 0
mod = 10**9 + 7
for i in range(K, N + 2):
min = i * (i - 1) / 2
max = (2 * N - i + 1) * i / 2
ans += max - min + 1
print((int(ans % mod)))
| false | 11.111111 | [
"-M = 10**9 + 7",
"+mod = 10**9 + 7",
"- _min = (i - 1) * i // 2",
"- _max = (N + N - i + 1) * i // 2",
"- ans += _max - _min + 1",
"-print((ans % M))",
"+ min = i * (i - 1) / 2",
"+ max = (2 * N - i + 1) * i / 2",
"+ ans += max - min + 1",
"+print((int(ans % mod)))"
]
| false | 0.049543 | 0.064984 | 0.762383 | [
"s276379772",
"s594901212"
]
|
u323680411 | p03478 | python | s147770781 | s874234405 | 34 | 24 | 3,060 | 3,064 | Accepted | Accepted | 29.41 | def judge(n):
result = 0
j = n
for i in range(1, len(str(n)) + 1):
result += j % 10
j = int(j / 10)
return result
def main():
N, A, B = list(map(int, input().split()))
ans = 0
for i in range(1, N + 1):
if A <= judge(i) <= B:
ans += i
print(ans)
main() | from sys import stdin
def main() -> None:
n, a, b = [int(next_str()) for _ in range(3)]
ans = 0
for i in range(1, n + 1):
sum_of_digits_i = sum_of_digits(i)
if a <= sum_of_digits_i <= b:
ans += i
print(ans)
def sum_of_digits(a: int) -> int:
result = 0
while a != 0:
result += a % 10
a //= 10
return result
def next_str() -> str:
result = ""
while True:
tmp = stdin.read(1)
if tmp.strip() != "":
result += tmp
elif tmp != '\r':
break
return result
if __name__ == '__main__':
main() | 20 | 36 | 337 | 661 | def judge(n):
result = 0
j = n
for i in range(1, len(str(n)) + 1):
result += j % 10
j = int(j / 10)
return result
def main():
N, A, B = list(map(int, input().split()))
ans = 0
for i in range(1, N + 1):
if A <= judge(i) <= B:
ans += i
print(ans)
main()
| from sys import stdin
def main() -> None:
n, a, b = [int(next_str()) for _ in range(3)]
ans = 0
for i in range(1, n + 1):
sum_of_digits_i = sum_of_digits(i)
if a <= sum_of_digits_i <= b:
ans += i
print(ans)
def sum_of_digits(a: int) -> int:
result = 0
while a != 0:
result += a % 10
a //= 10
return result
def next_str() -> str:
result = ""
while True:
tmp = stdin.read(1)
if tmp.strip() != "":
result += tmp
elif tmp != "\r":
break
return result
if __name__ == "__main__":
main()
| false | 44.444444 | [
"-def judge(n):",
"- result = 0",
"- j = n",
"- for i in range(1, len(str(n)) + 1):",
"- result += j % 10",
"- j = int(j / 10)",
"- return result",
"+from sys import stdin",
"-def main():",
"- N, A, B = list(map(int, input().split()))",
"+def main() -> None:",
"+ n, a, b = [int(next_str()) for _ in range(3)]",
"- for i in range(1, N + 1):",
"- if A <= judge(i) <= B:",
"+ for i in range(1, n + 1):",
"+ sum_of_digits_i = sum_of_digits(i)",
"+ if a <= sum_of_digits_i <= b:",
"-main()",
"+def sum_of_digits(a: int) -> int:",
"+ result = 0",
"+ while a != 0:",
"+ result += a % 10",
"+ a //= 10",
"+ return result",
"+",
"+",
"+def next_str() -> str:",
"+ result = \"\"",
"+ while True:",
"+ tmp = stdin.read(1)",
"+ if tmp.strip() != \"\":",
"+ result += tmp",
"+ elif tmp != \"\\r\":",
"+ break",
"+ return result",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.094559 | 0.037195 | 2.542261 | [
"s147770781",
"s874234405"
]
|
u545368057 | p03111 | python | s751357639 | s758244351 | 1,968 | 68 | 14,512 | 3,064 | Accepted | Accepted | 96.54 | import numpy as np
N, A, B, C = list(map(int,input().split()))
goals = [A,B,C]
ls = []
for i in range(N):
ls.append(int(eval(input())))
# goals = [1000,800,100]
# ls = [300,333,400,444,500,555,600,666]
# goals = [100, 90, 80]
# ls = [98, 40,30,21,80]
def count(x,ls):
try:
x.index(0)
x.index(1)
x.index(2)
except:
return False
A = np.zeros(len(goals))
for i,l in enumerate(ls):
add_ind = x[i]
if add_ind==3:
pass
else:
A[add_ind] += l
combine_MP = 0
for i in range(3):
combine_MP += 10*(x.count(i)-1)
return A, combine_MP
score_min = 100000
for N in range(4**8):
x = []
for j in range(len(ls)):
x.append(N % 4)
N = N // 4
try:
A, combine_MP = count(x,ls)
score = np.abs(A-np.array(goals)).sum() + combine_MP
if score_min >= score:
score_min = score
except:
pass
print((int(score_min))) | """
l1,l2,...,lN
N は max8本
A,B,Cの3本の竹にしたい
延長 : 1MP +1
短縮 : 1MP -1
合成 : 10MP li + lj
A, B, Cを達成するための最小MP
"""
N,A,B,C = list(map(int, input().split()))
ls = [int(eval(input())) for i in range(N)]
import sys
sys.setrecursionlimit(100000)
"""
Gを作りながら探索するパターン
"""
minMP = 10**9 + 7
def dfs(i,MP,a,b,c):
global minMP
# 探索打ち切り条件->計算してしまう
if i+1 >= N:
if a>0 and b>0 and c>0:
cnt = MP + abs(A-a)+abs(B-b)+abs(C-c) - 30
minMP = min(cnt,minMP)
return 0
l = ls[i+1]
# 再帰的に探索
dfs(i+1,MP,a,b,c) # なんもしない
dfs(i+1,MP+10,a+l,b,c) # aに
dfs(i+1,MP+10,a,b+l,c) # bに
dfs(i+1,MP+10,a,b,c+l) # cに
dfs(-1,0,0,0,0)
print(minMP) | 47 | 39 | 1,035 | 717 | import numpy as np
N, A, B, C = list(map(int, input().split()))
goals = [A, B, C]
ls = []
for i in range(N):
ls.append(int(eval(input())))
# goals = [1000,800,100]
# ls = [300,333,400,444,500,555,600,666]
# goals = [100, 90, 80]
# ls = [98, 40,30,21,80]
def count(x, ls):
try:
x.index(0)
x.index(1)
x.index(2)
except:
return False
A = np.zeros(len(goals))
for i, l in enumerate(ls):
add_ind = x[i]
if add_ind == 3:
pass
else:
A[add_ind] += l
combine_MP = 0
for i in range(3):
combine_MP += 10 * (x.count(i) - 1)
return A, combine_MP
score_min = 100000
for N in range(4**8):
x = []
for j in range(len(ls)):
x.append(N % 4)
N = N // 4
try:
A, combine_MP = count(x, ls)
score = np.abs(A - np.array(goals)).sum() + combine_MP
if score_min >= score:
score_min = score
except:
pass
print((int(score_min)))
| """
l1,l2,...,lN
N は max8本
A,B,Cの3本の竹にしたい
延長 : 1MP +1
短縮 : 1MP -1
合成 : 10MP li + lj
A, B, Cを達成するための最小MP
"""
N, A, B, C = list(map(int, input().split()))
ls = [int(eval(input())) for i in range(N)]
import sys
sys.setrecursionlimit(100000)
"""
Gを作りながら探索するパターン
"""
minMP = 10**9 + 7
def dfs(i, MP, a, b, c):
global minMP
# 探索打ち切り条件->計算してしまう
if i + 1 >= N:
if a > 0 and b > 0 and c > 0:
cnt = MP + abs(A - a) + abs(B - b) + abs(C - c) - 30
minMP = min(cnt, minMP)
return 0
l = ls[i + 1]
# 再帰的に探索
dfs(i + 1, MP, a, b, c) # なんもしない
dfs(i + 1, MP + 10, a + l, b, c) # aに
dfs(i + 1, MP + 10, a, b + l, c) # bに
dfs(i + 1, MP + 10, a, b, c + l) # cに
dfs(-1, 0, 0, 0, 0)
print(minMP)
| false | 17.021277 | [
"-import numpy as np",
"+\"\"\"",
"+l1,l2,...,lN",
"+N は max8本",
"+A,B,Cの3本の竹にしたい",
"+延長 : 1MP +1",
"+短縮 : 1MP -1",
"+合成 : 10MP li + lj",
"+A, B, Cを達成するための最小MP",
"+\"\"\"",
"+N, A, B, C = list(map(int, input().split()))",
"+ls = [int(eval(input())) for i in range(N)]",
"+import sys",
"-N, A, B, C = list(map(int, input().split()))",
"-goals = [A, B, C]",
"-ls = []",
"-for i in range(N):",
"- ls.append(int(eval(input())))",
"-# goals = [1000,800,100]",
"-# ls = [300,333,400,444,500,555,600,666]",
"-# goals = [100, 90, 80]",
"-# ls = [98, 40,30,21,80]",
"-def count(x, ls):",
"- try:",
"- x.index(0)",
"- x.index(1)",
"- x.index(2)",
"- except:",
"- return False",
"- A = np.zeros(len(goals))",
"- for i, l in enumerate(ls):",
"- add_ind = x[i]",
"- if add_ind == 3:",
"- pass",
"- else:",
"- A[add_ind] += l",
"- combine_MP = 0",
"- for i in range(3):",
"- combine_MP += 10 * (x.count(i) - 1)",
"- return A, combine_MP",
"+sys.setrecursionlimit(100000)",
"+\"\"\"",
"+Gを作りながら探索するパターン",
"+\"\"\"",
"+minMP = 10**9 + 7",
"-score_min = 100000",
"-for N in range(4**8):",
"- x = []",
"- for j in range(len(ls)):",
"- x.append(N % 4)",
"- N = N // 4",
"- try:",
"- A, combine_MP = count(x, ls)",
"- score = np.abs(A - np.array(goals)).sum() + combine_MP",
"- if score_min >= score:",
"- score_min = score",
"- except:",
"- pass",
"-print((int(score_min)))",
"+def dfs(i, MP, a, b, c):",
"+ global minMP",
"+ # 探索打ち切り条件->計算してしまう",
"+ if i + 1 >= N:",
"+ if a > 0 and b > 0 and c > 0:",
"+ cnt = MP + abs(A - a) + abs(B - b) + abs(C - c) - 30",
"+ minMP = min(cnt, minMP)",
"+ return 0",
"+ l = ls[i + 1]",
"+ # 再帰的に探索",
"+ dfs(i + 1, MP, a, b, c) # なんもしない",
"+ dfs(i + 1, MP + 10, a + l, b, c) # aに",
"+ dfs(i + 1, MP + 10, a, b + l, c) # bに",
"+ dfs(i + 1, MP + 10, a, b, c + l) # cに",
"+",
"+",
"+dfs(-1, 0, 0, 0, 0)",
"+print(minMP)"
]
| false | 2.386943 | 0.060449 | 39.48716 | [
"s751357639",
"s758244351"
]
|
u998733244 | p03160 | python | s947350926 | s853485927 | 255 | 136 | 52,600 | 20,708 | Accepted | Accepted | 46.67 | #!/usr/bin/env python3
N = int(eval(input()))
H = list(map(int, input().split()))
dp = [float('inf') for i in range(N+1)]
dp[1] = 0
dp[2] = abs(H[1]-H[0])
for i in range(3, N+1):
dp[i] = min(dp[i-1]+abs(H[i-1]-H[i-2]), dp[i-2]+abs(H[i-1]-H[i-3]))
print((dp[N]))
| #!/usr/bin/env python3
N = int(eval(input()))
H = list(map(int, input().split()))
dp = [float('inf') for _ in range(N+1)]
dp[1] = 0
dp[2] = abs(H[0]-H[1])
for i in range(3, N+1):
dp[i] = min(dp[i-2] + abs(H[i-3]-H[i-1]), dp[i-1] + abs(H[i-2]-H[i-1]))
print((dp[N]))
| 15 | 13 | 278 | 278 | #!/usr/bin/env python3
N = int(eval(input()))
H = list(map(int, input().split()))
dp = [float("inf") for i in range(N + 1)]
dp[1] = 0
dp[2] = abs(H[1] - H[0])
for i in range(3, N + 1):
dp[i] = min(
dp[i - 1] + abs(H[i - 1] - H[i - 2]), dp[i - 2] + abs(H[i - 1] - H[i - 3])
)
print((dp[N]))
| #!/usr/bin/env python3
N = int(eval(input()))
H = list(map(int, input().split()))
dp = [float("inf") for _ in range(N + 1)]
dp[1] = 0
dp[2] = abs(H[0] - H[1])
for i in range(3, N + 1):
dp[i] = min(
dp[i - 2] + abs(H[i - 3] - H[i - 1]), dp[i - 1] + abs(H[i - 2] - H[i - 1])
)
print((dp[N]))
| false | 13.333333 | [
"-dp = [float(\"inf\") for i in range(N + 1)]",
"+dp = [float(\"inf\") for _ in range(N + 1)]",
"-dp[2] = abs(H[1] - H[0])",
"+dp[2] = abs(H[0] - H[1])",
"- dp[i - 1] + abs(H[i - 1] - H[i - 2]), dp[i - 2] + abs(H[i - 1] - H[i - 3])",
"+ dp[i - 2] + abs(H[i - 3] - H[i - 1]), dp[i - 1] + abs(H[i - 2] - H[i - 1])"
]
| false | 0.038181 | 0.042268 | 0.903302 | [
"s947350926",
"s853485927"
]
|
u321605735 | p02675 | python | s844282779 | s774002498 | 31 | 25 | 9,132 | 9,080 | Accepted | Accepted | 19.35 | N=int(eval(input()))
ans=int(N%10)
if ans==3:
print("bon")
elif ans==0:
print("pon")
elif ans==1:
print("pon")
elif ans==6:
print("pon")
elif ans==8:
print("pon")
else:
print("hon") | N=int(eval(input()))
if int(N%10)==3:
print("bon")
elif int(N%10)<=1:
print("pon")
elif int(N%10)==6 or int(N%10)==8:
print("pon")
else:
print("hon") | 14 | 9 | 200 | 167 | N = int(eval(input()))
ans = int(N % 10)
if ans == 3:
print("bon")
elif ans == 0:
print("pon")
elif ans == 1:
print("pon")
elif ans == 6:
print("pon")
elif ans == 8:
print("pon")
else:
print("hon")
| N = int(eval(input()))
if int(N % 10) == 3:
print("bon")
elif int(N % 10) <= 1:
print("pon")
elif int(N % 10) == 6 or int(N % 10) == 8:
print("pon")
else:
print("hon")
| false | 35.714286 | [
"-ans = int(N % 10)",
"-if ans == 3:",
"+if int(N % 10) == 3:",
"-elif ans == 0:",
"+elif int(N % 10) <= 1:",
"-elif ans == 1:",
"- print(\"pon\")",
"-elif ans == 6:",
"- print(\"pon\")",
"-elif ans == 8:",
"+elif int(N % 10) == 6 or int(N % 10) == 8:"
]
| false | 0.039124 | 0.068138 | 0.574195 | [
"s844282779",
"s774002498"
]
|
u864013199 | p02973 | python | s945758059 | s288368926 | 236 | 124 | 11,036 | 11,032 | Accepted | Accepted | 47.46 | #ttps://atcoder.jp/contests/abc134/submissions/6459172
from bisect import bisect
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
dp = [1]
for a in A:
a *= -1
i = bisect(dp,a) #既存に-aを挿入した時のindex
if i < len(dp): #挿入位置が長さより小さい時(要はabsが一番小さくない時
dp[i] = a #-aにする
else:
dp.append(a) #右端に-aを普通に追加
print((len(dp))) | #ttps://atcoder.jp/contests/abc134/submissions/6459172
from bisect import bisect
import sys
input = sys.stdin.readline
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
dp = [1]
for a in A:
a *= -1
i = bisect(dp,a) #既存に-aを挿入した時のindex
if i < len(dp): #挿入位置が長さより小さい時(要はabsが一番小さくない時
dp[i] = a #-aにする
else:
dp.append(a) #右端に-aを普通に追加
print((len(dp))) | 16 | 18 | 371 | 411 | # ttps://atcoder.jp/contests/abc134/submissions/6459172
from bisect import bisect
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
dp = [1]
for a in A:
a *= -1
i = bisect(dp, a) # 既存に-aを挿入した時のindex
if i < len(dp): # 挿入位置が長さより小さい時(要はabsが一番小さくない時
dp[i] = a # -aにする
else:
dp.append(a) # 右端に-aを普通に追加
print((len(dp)))
| # ttps://atcoder.jp/contests/abc134/submissions/6459172
from bisect import bisect
import sys
input = sys.stdin.readline
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
dp = [1]
for a in A:
a *= -1
i = bisect(dp, a) # 既存に-aを挿入した時のindex
if i < len(dp): # 挿入位置が長さより小さい時(要はabsが一番小さくない時
dp[i] = a # -aにする
else:
dp.append(a) # 右端に-aを普通に追加
print((len(dp)))
| false | 11.111111 | [
"+import sys",
"+input = sys.stdin.readline"
]
| false | 0.043151 | 0.042975 | 1.004091 | [
"s945758059",
"s288368926"
]
|
u848647227 | p03856 | python | s696319474 | s213770916 | 48 | 42 | 3,956 | 3,956 | Accepted | Accepted | 12.5 | ar = list(eval(input()))
while True:
a = len(ar)
if a == 0:
print("YES")
break
if "".join(ar[a-5:a]) == "dream" or "".join(ar[a-5:a]) == "erase":
del ar[a-5:a]
elif "".join(ar[a-6:a]) == "eraser":
del ar[a-6:a]
elif "".join(ar[a-7:a]) == "dreamer":
del ar[a-7:a]
else:
print("NO")
break | ar = list(eval(input()))
l = len(ar)
if l < 5:
print('NO')
else:
while True:
if l == 0:
print("YES")
exit()
if "".join(ar[l-5:l]) == 'dream' or "".join(ar[l-5:l]) == 'erase':
l -= 5
elif "".join(ar[l-6:l]) == 'eraser':
l -= 6
elif "".join(ar[l-7:l]) == 'dreamer':
l -= 7
else:
print("NO")
exit()
| 15 | 18 | 374 | 439 | ar = list(eval(input()))
while True:
a = len(ar)
if a == 0:
print("YES")
break
if "".join(ar[a - 5 : a]) == "dream" or "".join(ar[a - 5 : a]) == "erase":
del ar[a - 5 : a]
elif "".join(ar[a - 6 : a]) == "eraser":
del ar[a - 6 : a]
elif "".join(ar[a - 7 : a]) == "dreamer":
del ar[a - 7 : a]
else:
print("NO")
break
| ar = list(eval(input()))
l = len(ar)
if l < 5:
print("NO")
else:
while True:
if l == 0:
print("YES")
exit()
if "".join(ar[l - 5 : l]) == "dream" or "".join(ar[l - 5 : l]) == "erase":
l -= 5
elif "".join(ar[l - 6 : l]) == "eraser":
l -= 6
elif "".join(ar[l - 7 : l]) == "dreamer":
l -= 7
else:
print("NO")
exit()
| false | 16.666667 | [
"-while True:",
"- a = len(ar)",
"- if a == 0:",
"- print(\"YES\")",
"- break",
"- if \"\".join(ar[a - 5 : a]) == \"dream\" or \"\".join(ar[a - 5 : a]) == \"erase\":",
"- del ar[a - 5 : a]",
"- elif \"\".join(ar[a - 6 : a]) == \"eraser\":",
"- del ar[a - 6 : a]",
"- elif \"\".join(ar[a - 7 : a]) == \"dreamer\":",
"- del ar[a - 7 : a]",
"- else:",
"- print(\"NO\")",
"- break",
"+l = len(ar)",
"+if l < 5:",
"+ print(\"NO\")",
"+else:",
"+ while True:",
"+ if l == 0:",
"+ print(\"YES\")",
"+ exit()",
"+ if \"\".join(ar[l - 5 : l]) == \"dream\" or \"\".join(ar[l - 5 : l]) == \"erase\":",
"+ l -= 5",
"+ elif \"\".join(ar[l - 6 : l]) == \"eraser\":",
"+ l -= 6",
"+ elif \"\".join(ar[l - 7 : l]) == \"dreamer\":",
"+ l -= 7",
"+ else:",
"+ print(\"NO\")",
"+ exit()"
]
| false | 0.046525 | 0.047457 | 0.980361 | [
"s696319474",
"s213770916"
]
|
u281303342 | p03128 | python | s091509915 | s149048267 | 95 | 85 | 3,420 | 3,348 | Accepted | Accepted | 10.53 | N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort(reverse=True)
# 各数字に必要なマッチの本数
num = [0,2,5,5,4,5,6,3,7,6]
# dp : i本のマッチで実現できる最大の桁数
dp = [-1*float("inf")]*(N+1)
# dp初期化 (0本では0桁, 各数字を1つ作る場合は1桁)
dp[0] = 0
for a in A:
if num[a] <= N:
dp[num[a]] = 1
for i in range(1,N+1):
for a in A:
if i - num[a] >= 0:
dp[i] = max(dp[i], dp[i-num[a]] + 1)
ans = ""
for i in range(dp[N]):
for a in A:
if N-num[a] >= 0 and dp[N-num[a]] == dp[N]-1:
ans += str(a)
N -= num[a]
break
print(ans) | # Python3 (3.4.3)
import sys
input = sys.stdin.readline
# -------------------------------------------------------------
# function
# -------------------------------------------------------------
# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
# 各数字に必要なマッチの本数
num = [0,2,5,5,4,5,6,3,7,6]
# dp : i本のマッチで作ることが可能な最大の桁数
dp = [-float("inf")]*(N+1)
# dp初期化
# - 0本 -> 0桁
# - 各数字を1つ作る場合は1桁
dp[0] = 0
for a in A:
if num[a] <= N:
dp[num[a]] = 1
# dp更新
for i in range(1,N+1):
for a in A:
if i - num[a] >= 0:
dp[i] = max(dp[i], dp[i-num[a]] + 1)
# 復元
A.sort(reverse=True)
ans = ""
for i in range(dp[N]):
for a in A:
if N-num[a] >= 0 and dp[N-num[a]] == dp[N]-1:
ans += str(a)
N -= num[a]
break
print(ans) | 29 | 45 | 612 | 985 | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
# 各数字に必要なマッチの本数
num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
# dp : i本のマッチで実現できる最大の桁数
dp = [-1 * float("inf")] * (N + 1)
# dp初期化 (0本では0桁, 各数字を1つ作る場合は1桁)
dp[0] = 0
for a in A:
if num[a] <= N:
dp[num[a]] = 1
for i in range(1, N + 1):
for a in A:
if i - num[a] >= 0:
dp[i] = max(dp[i], dp[i - num[a]] + 1)
ans = ""
for i in range(dp[N]):
for a in A:
if N - num[a] >= 0 and dp[N - num[a]] == dp[N] - 1:
ans += str(a)
N -= num[a]
break
print(ans)
| # Python3 (3.4.3)
import sys
input = sys.stdin.readline
# -------------------------------------------------------------
# function
# -------------------------------------------------------------
# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
# 各数字に必要なマッチの本数
num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
# dp : i本のマッチで作ることが可能な最大の桁数
dp = [-float("inf")] * (N + 1)
# dp初期化
# - 0本 -> 0桁
# - 各数字を1つ作る場合は1桁
dp[0] = 0
for a in A:
if num[a] <= N:
dp[num[a]] = 1
# dp更新
for i in range(1, N + 1):
for a in A:
if i - num[a] >= 0:
dp[i] = max(dp[i], dp[i - num[a]] + 1)
# 復元
A.sort(reverse=True)
ans = ""
for i in range(dp[N]):
for a in A:
if N - num[a] >= 0 and dp[N - num[a]] == dp[N] - 1:
ans += str(a)
N -= num[a]
break
print(ans)
| false | 35.555556 | [
"+# Python3 (3.4.3)",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+# function",
"+# main",
"-A.sort(reverse=True)",
"-# dp : i本のマッチで実現できる最大の桁数",
"-dp = [-1 * float(\"inf\")] * (N + 1)",
"-# dp初期化 (0本では0桁, 各数字を1つ作る場合は1桁)",
"+# dp : i本のマッチで作ることが可能な最大の桁数",
"+dp = [-float(\"inf\")] * (N + 1)",
"+# dp初期化",
"+# - 0本 -> 0桁",
"+# - 各数字を1つ作る場合は1桁",
"+# dp更新",
"+# 復元",
"+A.sort(reverse=True)"
]
| false | 0.050502 | 0.06757 | 0.747396 | [
"s091509915",
"s149048267"
]
|
u021548497 | p03488 | python | s934241711 | s811813059 | 440 | 70 | 75,780 | 71,480 | Accepted | Accepted | 84.09 | def main():
s = eval(input())
n = len(s)
x, y = list(map(int, input().split()))
dpx = [[False, False] for _ in range(n+2)]
dpy = [[False, False] for _ in range(n+2)]
dpx[0][0] = True
dpy[0][0] = True
x_turn = False
y_turn = False
judge = True
turn = False
xcount = 0
count = 0
for i in range(n):
if judge and s[i] == "F":
xcount += 1
continue
if judge:
judge = False
turn = False if turn else True
continue
if s[i] == "F":
count += 1
if i != n-1:
continue
if turn:
y_turn = False if y_turn else True
if y_turn:
p, q = 0, 1
else:
p, q = 1, 0
for i in range(n+1):
dpy[i][q] = False
for i in range(n+1):
if dpy[i][p]:
dpy[abs(i-count)][q] = True
dpy[i+count][q] = True
else:
x_turn = False if x_turn else True
if x_turn:
p, q = 0, 1
else:
p, q = 1, 0
for i in range(n+1):
dpx[i][q] = False
for i in range(n+1):
if dpx[i][p]:
dpx[abs(i-count)][q] = True
dpx[i+count][q] = True
turn = False if turn else True
count = 0
p = 1 if x_turn else 0
q = 1 if y_turn else 0
x -= xcount
if abs(x) > n:
print("No")
elif dpx[abs(x)][p] and dpy[abs(y)][q]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | import sys
def main():
s = eval(input())
n = len(s)
x, y = list(map(int, input().split()))
move = [0]
for i in range(n):
if s[i] == "F":
move[-1] += 1
else:
move.append(0)
move_x = move[2::2]
move_y = move[1::2]
move_a = move[0]
for start, lis in zip([x-move_a, y], [move_x, move_y]):
move_range = sum(lis)
if abs(start) > move_range:
print("No")
sys.exit()
dp = 2**move_range
for value in lis:
dp = (dp >> value)|(dp << value)
if not (dp>>(move_range+start))&1:
print("No")
sys.exit()
print("Yes")
if __name__ == "__main__":
main() | 68 | 36 | 1,471 | 671 | def main():
s = eval(input())
n = len(s)
x, y = list(map(int, input().split()))
dpx = [[False, False] for _ in range(n + 2)]
dpy = [[False, False] for _ in range(n + 2)]
dpx[0][0] = True
dpy[0][0] = True
x_turn = False
y_turn = False
judge = True
turn = False
xcount = 0
count = 0
for i in range(n):
if judge and s[i] == "F":
xcount += 1
continue
if judge:
judge = False
turn = False if turn else True
continue
if s[i] == "F":
count += 1
if i != n - 1:
continue
if turn:
y_turn = False if y_turn else True
if y_turn:
p, q = 0, 1
else:
p, q = 1, 0
for i in range(n + 1):
dpy[i][q] = False
for i in range(n + 1):
if dpy[i][p]:
dpy[abs(i - count)][q] = True
dpy[i + count][q] = True
else:
x_turn = False if x_turn else True
if x_turn:
p, q = 0, 1
else:
p, q = 1, 0
for i in range(n + 1):
dpx[i][q] = False
for i in range(n + 1):
if dpx[i][p]:
dpx[abs(i - count)][q] = True
dpx[i + count][q] = True
turn = False if turn else True
count = 0
p = 1 if x_turn else 0
q = 1 if y_turn else 0
x -= xcount
if abs(x) > n:
print("No")
elif dpx[abs(x)][p] and dpy[abs(y)][q]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| import sys
def main():
s = eval(input())
n = len(s)
x, y = list(map(int, input().split()))
move = [0]
for i in range(n):
if s[i] == "F":
move[-1] += 1
else:
move.append(0)
move_x = move[2::2]
move_y = move[1::2]
move_a = move[0]
for start, lis in zip([x - move_a, y], [move_x, move_y]):
move_range = sum(lis)
if abs(start) > move_range:
print("No")
sys.exit()
dp = 2**move_range
for value in lis:
dp = (dp >> value) | (dp << value)
if not (dp >> (move_range + start)) & 1:
print("No")
sys.exit()
print("Yes")
if __name__ == "__main__":
main()
| false | 47.058824 | [
"+import sys",
"+",
"+",
"- dpx = [[False, False] for _ in range(n + 2)]",
"- dpy = [[False, False] for _ in range(n + 2)]",
"- dpx[0][0] = True",
"- dpy[0][0] = True",
"- x_turn = False",
"- y_turn = False",
"- judge = True",
"- turn = False",
"- xcount = 0",
"- count = 0",
"+ move = [0]",
"- if judge and s[i] == \"F\":",
"- xcount += 1",
"- continue",
"- if judge:",
"- judge = False",
"- turn = False if turn else True",
"- continue",
"- count += 1",
"- if i != n - 1:",
"- continue",
"- if turn:",
"- y_turn = False if y_turn else True",
"- if y_turn:",
"- p, q = 0, 1",
"- else:",
"- p, q = 1, 0",
"- for i in range(n + 1):",
"- dpy[i][q] = False",
"- for i in range(n + 1):",
"- if dpy[i][p]:",
"- dpy[abs(i - count)][q] = True",
"- dpy[i + count][q] = True",
"+ move[-1] += 1",
"- x_turn = False if x_turn else True",
"- if x_turn:",
"- p, q = 0, 1",
"- else:",
"- p, q = 1, 0",
"- for i in range(n + 1):",
"- dpx[i][q] = False",
"- for i in range(n + 1):",
"- if dpx[i][p]:",
"- dpx[abs(i - count)][q] = True",
"- dpx[i + count][q] = True",
"- turn = False if turn else True",
"- count = 0",
"- p = 1 if x_turn else 0",
"- q = 1 if y_turn else 0",
"- x -= xcount",
"- if abs(x) > n:",
"- print(\"No\")",
"- elif dpx[abs(x)][p] and dpy[abs(y)][q]:",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"+ move.append(0)",
"+ move_x = move[2::2]",
"+ move_y = move[1::2]",
"+ move_a = move[0]",
"+ for start, lis in zip([x - move_a, y], [move_x, move_y]):",
"+ move_range = sum(lis)",
"+ if abs(start) > move_range:",
"+ print(\"No\")",
"+ sys.exit()",
"+ dp = 2**move_range",
"+ for value in lis:",
"+ dp = (dp >> value) | (dp << value)",
"+ if not (dp >> (move_range + start)) & 1:",
"+ print(\"No\")",
"+ sys.exit()",
"+ print(\"Yes\")"
]
| false | 0.040944 | 0.039593 | 1.034125 | [
"s934241711",
"s811813059"
]
|
u888092736 | p02647 | python | s059593454 | s101469915 | 1,390 | 1,090 | 132,532 | 137,048 | Accepted | Accepted | 21.58 | import numpy as np
from numba import njit
@njit
def solve(N, K, A):
for _ in range(K):
B = np.zeros(N + 1, dtype=np.int64)
for i in range(N):
a = A[i]
B[max(0, i - a)] += 1
B[min(N, i + a + 1)] -= 1
A = np.cumsum(B)[:-1]
if np.all(A == N):
return A
return A
N, K = list(map(int, input().split()))
A = np.array(input().split(), dtype=int)
print((' '.join(map(str, solve(N, K, A))))) | import numpy as np
from numba import njit
@njit('i8[:](i8,i8,i8[:])')
def solve(N, K, A):
for _ in range(K):
B = np.zeros(N + 1, dtype=np.int64)
for i in range(N):
a = A[i]
B[max(0, i - a)] += 1
B[min(N, i + a + 1)] -= 1
A = np.cumsum(B)[:-1]
if np.all(A == N):
return A
return A
N, K = list(map(int, input().split()))
A = np.array(input().split(), dtype=int)
print((' '.join(map(str, solve(N, K, A))))) | 21 | 21 | 485 | 507 | import numpy as np
from numba import njit
@njit
def solve(N, K, A):
for _ in range(K):
B = np.zeros(N + 1, dtype=np.int64)
for i in range(N):
a = A[i]
B[max(0, i - a)] += 1
B[min(N, i + a + 1)] -= 1
A = np.cumsum(B)[:-1]
if np.all(A == N):
return A
return A
N, K = list(map(int, input().split()))
A = np.array(input().split(), dtype=int)
print((" ".join(map(str, solve(N, K, A)))))
| import numpy as np
from numba import njit
@njit("i8[:](i8,i8,i8[:])")
def solve(N, K, A):
for _ in range(K):
B = np.zeros(N + 1, dtype=np.int64)
for i in range(N):
a = A[i]
B[max(0, i - a)] += 1
B[min(N, i + a + 1)] -= 1
A = np.cumsum(B)[:-1]
if np.all(A == N):
return A
return A
N, K = list(map(int, input().split()))
A = np.array(input().split(), dtype=int)
print((" ".join(map(str, solve(N, K, A)))))
| false | 0 | [
"-@njit",
"+@njit(\"i8[:](i8,i8,i8[:])\")"
]
| false | 0.27046 | 0.556954 | 0.485605 | [
"s059593454",
"s101469915"
]
|
u941047297 | p03963 | python | s588602142 | s398917211 | 165 | 20 | 38,256 | 3,060 | Accepted | Accepted | 87.88 | N, K = list(map(int, input().split()))
ans = K * ((K - 1) ** (N - 1))
print(ans) | n, k = list(map(int, input().split()))
print((k * ((k - 1) ** (n - 1)))) | 3 | 2 | 82 | 71 | N, K = list(map(int, input().split()))
ans = K * ((K - 1) ** (N - 1))
print(ans)
| n, k = list(map(int, input().split()))
print((k * ((k - 1) ** (n - 1))))
| false | 33.333333 | [
"-N, K = list(map(int, input().split()))",
"-ans = K * ((K - 1) ** (N - 1))",
"-print(ans)",
"+n, k = list(map(int, input().split()))",
"+print((k * ((k - 1) ** (n - 1))))"
]
| false | 0.036614 | 0.045181 | 0.810393 | [
"s588602142",
"s398917211"
]
|
u609061751 | p02835 | python | s775000831 | s748128092 | 148 | 17 | 12,492 | 2,940 | Accepted | Accepted | 88.51 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
A = [int(x) for x in readline().rstrip().split()]
if sum(A) >= 22:
print("bust")
else:
print("win") | A = [int(x) for x in input().split()]
total = sum(A)
if total <= 21:
print("win")
else:
print("bust") | 11 | 6 | 253 | 114 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
A = [int(x) for x in readline().rstrip().split()]
if sum(A) >= 22:
print("bust")
else:
print("win")
| A = [int(x) for x in input().split()]
total = sum(A)
if total <= 21:
print("win")
else:
print("bust")
| false | 45.454545 | [
"-import sys",
"-",
"-read = sys.stdin.buffer.read",
"-readline = sys.stdin.buffer.readline",
"-readlines = sys.stdin.buffer.readlines",
"-import numpy as np",
"-",
"-A = [int(x) for x in readline().rstrip().split()]",
"-if sum(A) >= 22:",
"+A = [int(x) for x in input().split()]",
"+total = sum(A)",
"+if total <= 21:",
"+ print(\"win\")",
"+else:",
"-else:",
"- print(\"win\")"
]
| false | 0.060746 | 0.036971 | 1.643068 | [
"s775000831",
"s748128092"
]
|
u877415670 | p02832 | python | s400898053 | s323901217 | 155 | 110 | 26,148 | 26,268 | Accepted | Accepted | 29.03 | import sys
n=int(eval(input()))
a = list(map(int, input().split()))
ans = 0
_find = 1
before = 0
if not 1 in set(a):
print((-1))
sys.exit()
for i in range(n):
if a[i]==_find:
ans += i-before
_find += 1
before = i+1
print((ans+n-before)) | n=int(eval(input()))
a=list(map(int,input().split()))
ans = 0
block = 1
no_block = False
for i in range(n):
if a[i]!=block:
ans+=1
else:
no_block = True
block+=1
if no_block is False:
print((-1))
else:
print(ans) | 20 | 18 | 286 | 267 | import sys
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
_find = 1
before = 0
if not 1 in set(a):
print((-1))
sys.exit()
for i in range(n):
if a[i] == _find:
ans += i - before
_find += 1
before = i + 1
print((ans + n - before))
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
block = 1
no_block = False
for i in range(n):
if a[i] != block:
ans += 1
else:
no_block = True
block += 1
if no_block is False:
print((-1))
else:
print(ans)
| false | 10 | [
"-import sys",
"-",
"-_find = 1",
"-before = 0",
"-if not 1 in set(a):",
"+block = 1",
"+no_block = False",
"+for i in range(n):",
"+ if a[i] != block:",
"+ ans += 1",
"+ else:",
"+ no_block = True",
"+ block += 1",
"+if no_block is False:",
"- sys.exit()",
"-for i in range(n):",
"- if a[i] == _find:",
"- ans += i - before",
"- _find += 1",
"- before = i + 1",
"-print((ans + n - before))",
"+else:",
"+ print(ans)"
]
| false | 0.041416 | 0.036425 | 1.137034 | [
"s400898053",
"s323901217"
]
|
u959981943 | p03285 | python | s782978456 | s913611266 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | from sys import stdin
N = int(stdin.readline().rstrip())
if N in [1, 2, 3, 5, 6, 9, 10, 13, 17]:
print('No')
else:
print('Yes')
| N = int(eval(input()))
if N in [1, 2, 3, 5, 6, 9, 10, 13, 17]:
print('No')
else:
print('Yes')
| 8 | 6 | 145 | 102 | from sys import stdin
N = int(stdin.readline().rstrip())
if N in [1, 2, 3, 5, 6, 9, 10, 13, 17]:
print("No")
else:
print("Yes")
| N = int(eval(input()))
if N in [1, 2, 3, 5, 6, 9, 10, 13, 17]:
print("No")
else:
print("Yes")
| false | 25 | [
"-from sys import stdin",
"-",
"-N = int(stdin.readline().rstrip())",
"+N = int(eval(input()))"
]
| false | 0.047713 | 0.051688 | 0.923099 | [
"s782978456",
"s913611266"
]
|
u729133443 | p03773 | python | s607639209 | s942561485 | 161 | 28 | 38,256 | 8,900 | Accepted | Accepted | 82.61 | a,b=list(map(int,input().split()));print(((a+b)%24)) | print((eval(input().replace(*' +'))%24)) | 1 | 1 | 44 | 38 | a, b = list(map(int, input().split()))
print(((a + b) % 24))
| print((eval(input().replace(*" +")) % 24))
| false | 0 | [
"-a, b = list(map(int, input().split()))",
"-print(((a + b) % 24))",
"+print((eval(input().replace(*\" +\")) % 24))"
]
| false | 0.033718 | 0.032695 | 1.031291 | [
"s607639209",
"s942561485"
]
|
u519123891 | p02707 | python | s599189804 | s935864815 | 221 | 167 | 54,432 | 33,608 | Accepted | Accepted | 24.43 | # input
n = int(eval(input()))
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[:n-1]]
# calc
w_ls = {i+1: 0 for i in range(n)}
for a in a_ls:
w_ls[a] += 1
# result
for i in range(n):
print((w_ls[i+1])) | # input
n = int(eval(input()))
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[:n-1]]
# calc
w_ls = [0 for i in range(n)]
for a in a_ls:
w_ls[a-1] += 1
# result
for w in w_ls:
print(w) | 13 | 13 | 220 | 205 | # input
n = int(eval(input()))
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[: n - 1]]
# calc
w_ls = {i + 1: 0 for i in range(n)}
for a in a_ls:
w_ls[a] += 1
# result
for i in range(n):
print((w_ls[i + 1]))
| # input
n = int(eval(input()))
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[: n - 1]]
# calc
w_ls = [0 for i in range(n)]
for a in a_ls:
w_ls[a - 1] += 1
# result
for w in w_ls:
print(w)
| false | 0 | [
"-w_ls = {i + 1: 0 for i in range(n)}",
"+w_ls = [0 for i in range(n)]",
"- w_ls[a] += 1",
"+ w_ls[a - 1] += 1",
"-for i in range(n):",
"- print((w_ls[i + 1]))",
"+for w in w_ls:",
"+ print(w)"
]
| false | 0.047213 | 0.047828 | 0.987139 | [
"s599189804",
"s935864815"
]
|
u293198424 | p03324 | python | s173718495 | s154977842 | 183 | 163 | 38,384 | 38,256 | Accepted | Accepted | 10.93 | d,n = list(map(int,input().split()))
if n==100 and d==0:
ans = 100**d*n+1
elif n==100 and d==1:
ans = 100**d*n + 100
elif n==100 and d==2:
ans = 100**d*n + 10000
else:
ans = 100**d*n
print(ans)
| d,n = list(map(int,input().split()))
if n==100:
ans = 100**d*(n+1)
else:
ans = 100**d*n
print(ans) | 11 | 6 | 218 | 105 | d, n = list(map(int, input().split()))
if n == 100 and d == 0:
ans = 100**d * n + 1
elif n == 100 and d == 1:
ans = 100**d * n + 100
elif n == 100 and d == 2:
ans = 100**d * n + 10000
else:
ans = 100**d * n
print(ans)
| d, n = list(map(int, input().split()))
if n == 100:
ans = 100**d * (n + 1)
else:
ans = 100**d * n
print(ans)
| false | 45.454545 | [
"-if n == 100 and d == 0:",
"- ans = 100**d * n + 1",
"-elif n == 100 and d == 1:",
"- ans = 100**d * n + 100",
"-elif n == 100 and d == 2:",
"- ans = 100**d * n + 10000",
"+if n == 100:",
"+ ans = 100**d * (n + 1)"
]
| false | 0.10246 | 0.094193 | 1.087771 | [
"s173718495",
"s154977842"
]
|
u462831976 | p00040 | python | s353019359 | s596222047 | 210 | 60 | 7,796 | 7,820 | Accepted | Accepted | 71.43 | # -*- coding: utf-8 -*-
import sys
import os
import math
N = int(eval(input()))
alphabet = 'abcdefghijklmnopqrstuvwxyz'
def encode(s, alpha, beta):
t = []
for c in s:
if c == ' ':
t.append(c)
else:
gamma = ord(c) - 97
v = (alpha * gamma + beta) % 26
w = alphabet[v]
t.append(w)
return ''.join(t)
for i in range(N):
s = input().strip()
for a in range(26):
for b in range(26):
encoded = encode(s, a, b)
if 'that' in encoded or 'this' in encoded:
print(encoded) | # -*- coding: utf-8 -*-
import sys
import os
import math
N = int(eval(input()))
alphabet = 'abcdefghijklmnopqrstuvwxyz'
def encode(s, alpha, beta):
t = []
for c in s:
if c == ' ':
t.append(c)
else:
gamma = ord(c) - 97
v = (alpha * gamma + beta) % 26
w = alphabet[v]
t.append(w)
return ''.join(t)
for i in range(N):
s = input().strip()
for a in range(0, 26):
for b in range(0, 26):
encoded_this = encode('this', a, b)
encoded_that = encode('that', a, b)
if encoded_this in s or encoded_that in s:
encoded_alphabet = encode(alphabet, a, b)
table = str.maketrans(encoded_alphabet, alphabet)
dst = s.translate(table)
print(dst) | 31 | 34 | 633 | 864 | # -*- coding: utf-8 -*-
import sys
import os
import math
N = int(eval(input()))
alphabet = "abcdefghijklmnopqrstuvwxyz"
def encode(s, alpha, beta):
t = []
for c in s:
if c == " ":
t.append(c)
else:
gamma = ord(c) - 97
v = (alpha * gamma + beta) % 26
w = alphabet[v]
t.append(w)
return "".join(t)
for i in range(N):
s = input().strip()
for a in range(26):
for b in range(26):
encoded = encode(s, a, b)
if "that" in encoded or "this" in encoded:
print(encoded)
| # -*- coding: utf-8 -*-
import sys
import os
import math
N = int(eval(input()))
alphabet = "abcdefghijklmnopqrstuvwxyz"
def encode(s, alpha, beta):
t = []
for c in s:
if c == " ":
t.append(c)
else:
gamma = ord(c) - 97
v = (alpha * gamma + beta) % 26
w = alphabet[v]
t.append(w)
return "".join(t)
for i in range(N):
s = input().strip()
for a in range(0, 26):
for b in range(0, 26):
encoded_this = encode("this", a, b)
encoded_that = encode("that", a, b)
if encoded_this in s or encoded_that in s:
encoded_alphabet = encode(alphabet, a, b)
table = str.maketrans(encoded_alphabet, alphabet)
dst = s.translate(table)
print(dst)
| false | 8.823529 | [
"- for a in range(26):",
"- for b in range(26):",
"- encoded = encode(s, a, b)",
"- if \"that\" in encoded or \"this\" in encoded:",
"- print(encoded)",
"+ for a in range(0, 26):",
"+ for b in range(0, 26):",
"+ encoded_this = encode(\"this\", a, b)",
"+ encoded_that = encode(\"that\", a, b)",
"+ if encoded_this in s or encoded_that in s:",
"+ encoded_alphabet = encode(alphabet, a, b)",
"+ table = str.maketrans(encoded_alphabet, alphabet)",
"+ dst = s.translate(table)",
"+ print(dst)"
]
| false | 0.045789 | 0.037579 | 1.218479 | [
"s353019359",
"s596222047"
]
|
u970197315 | p03425 | python | s870806585 | s769654772 | 196 | 165 | 10,032 | 3,064 | Accepted | Accepted | 15.82 | # ABC089 C - March
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
x = [0,0,0,0,0,0,1,1,1,2]
y = [1,1,1,2,2,3,2,2,3,3]
z = [2,3,4,3,4,4,3,4,4,4]
m = 0
a = 0
r = 0
c = 0
h = 0
for s in S:
if s[0:1] == 'M':
m += 1
if s[0:1] == 'A':
a += 1
if s[0:1] == 'R':
r += 1
if s[0:1] == 'C':
c += 1
if s[0:1] == 'H':
h += 1
ans = 0
D = []
D.append(m)
D.append(a)
D.append(r)
D.append(c)
D.append(h)
for d in range(10):
ans += D[x[d]]*D[y[d]]*D[z[d]]
print(ans)
| n=int(eval(input()))
m=0
a=0
r=0
c=0
h=0
for i in range(n):
s=eval(input())
if s[0]=='M':
m+=1
elif s[0]=='A':
a+=1
elif s[0]=='R':
r+=1
elif s[0]=='C':
c+=1
elif s[0]=='H':
h+=1
ans=0
ans+=m*a*r
ans+=m*a*c
ans+=m*a*h
ans+=m*r*c
ans+=m*r*h
ans+=m*c*h
ans+=a*r*c
ans+=a*r*h
ans+=a*c*h
ans+=r*c*h
print(ans) | 38 | 34 | 557 | 394 | # ABC089 C - March
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
x = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
y = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
z = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]
m = 0
a = 0
r = 0
c = 0
h = 0
for s in S:
if s[0:1] == "M":
m += 1
if s[0:1] == "A":
a += 1
if s[0:1] == "R":
r += 1
if s[0:1] == "C":
c += 1
if s[0:1] == "H":
h += 1
ans = 0
D = []
D.append(m)
D.append(a)
D.append(r)
D.append(c)
D.append(h)
for d in range(10):
ans += D[x[d]] * D[y[d]] * D[z[d]]
print(ans)
| n = int(eval(input()))
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
s = eval(input())
if s[0] == "M":
m += 1
elif s[0] == "A":
a += 1
elif s[0] == "R":
r += 1
elif s[0] == "C":
c += 1
elif s[0] == "H":
h += 1
ans = 0
ans += m * a * r
ans += m * a * c
ans += m * a * h
ans += m * r * c
ans += m * r * h
ans += m * c * h
ans += a * r * c
ans += a * r * h
ans += a * c * h
ans += r * c * h
print(ans)
| false | 10.526316 | [
"-# ABC089 C - March",
"-N = int(eval(input()))",
"-S = [eval(input()) for i in range(N)]",
"-x = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]",
"-y = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]",
"-z = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]",
"+n = int(eval(input()))",
"-for s in S:",
"- if s[0:1] == \"M\":",
"+for i in range(n):",
"+ s = eval(input())",
"+ if s[0] == \"M\":",
"- if s[0:1] == \"A\":",
"+ elif s[0] == \"A\":",
"- if s[0:1] == \"R\":",
"+ elif s[0] == \"R\":",
"- if s[0:1] == \"C\":",
"+ elif s[0] == \"C\":",
"- if s[0:1] == \"H\":",
"+ elif s[0] == \"H\":",
"-D = []",
"-D.append(m)",
"-D.append(a)",
"-D.append(r)",
"-D.append(c)",
"-D.append(h)",
"-for d in range(10):",
"- ans += D[x[d]] * D[y[d]] * D[z[d]]",
"+ans += m * a * r",
"+ans += m * a * c",
"+ans += m * a * h",
"+ans += m * r * c",
"+ans += m * r * h",
"+ans += m * c * h",
"+ans += a * r * c",
"+ans += a * r * h",
"+ans += a * c * h",
"+ans += r * c * h"
]
| false | 0.045555 | 0.048627 | 0.936819 | [
"s870806585",
"s769654772"
]
|
u243312682 | p02659 | python | s214758205 | s127271551 | 29 | 23 | 10,008 | 9,164 | Accepted | Accepted | 20.69 | from decimal import *
def main():
a, b = list(map(str, input().split()))
res = int(a) * Decimal(b)
print((int(res)))
if __name__ == '__main__':
main() | def main():
a, b = list(map(str, input().split()))
res = int(a) * round((float(b)) * 100) // 100
print(res)
if __name__ == '__main__':
main() | 8 | 8 | 166 | 163 | from decimal import *
def main():
a, b = list(map(str, input().split()))
res = int(a) * Decimal(b)
print((int(res)))
if __name__ == "__main__":
main()
| def main():
a, b = list(map(str, input().split()))
res = int(a) * round((float(b)) * 100) // 100
print(res)
if __name__ == "__main__":
main()
| false | 0 | [
"-from decimal import *",
"-",
"-",
"- res = int(a) * Decimal(b)",
"- print((int(res)))",
"+ res = int(a) * round((float(b)) * 100) // 100",
"+ print(res)"
]
| false | 0.039441 | 0.038599 | 1.021807 | [
"s214758205",
"s127271551"
]
|
u645250356 | p03564 | python | s595107266 | s219643145 | 176 | 39 | 38,384 | 5,120 | Accepted | Accepted | 77.84 | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
k = inp()
res = 1
for i in range(n):
res = min(res+k, res*2)
print(res) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
k = inp()
now = 1
for i in range(n):
now = min(now+k, now*2)
print(now) | 15 | 16 | 448 | 452 | from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
k = inp()
res = 1
for i in range(n):
res = min(res + k, res * 2)
print(res)
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n = inp()
k = inp()
now = 1
for i in range(n):
now = min(now + k, now * 2)
print(now)
| false | 6.25 | [
"-import sys, bisect, math, itertools",
"+from bisect import bisect_left, bisect_right",
"+import sys, math, itertools, fractions, pprint",
"+INF = float(\"inf\")",
"-def inpln(n):",
"- return list(int(sys.stdin.readline()) for i in range(n))",
"-",
"-",
"-res = 1",
"+now = 1",
"- res = min(res + k, res * 2)",
"-print(res)",
"+ now = min(now + k, now * 2)",
"+print(now)"
]
| false | 0.054991 | 0.077128 | 0.712982 | [
"s595107266",
"s219643145"
]
|
u320325426 | p03555 | python | s078452076 | s877674552 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | print(("YES" if eval(input()) == input()[::-1] else "NO")) | print((["NO", "YES"][eval(input()) == input()[::-1]])) | 1 | 1 | 50 | 46 | print(("YES" if eval(input()) == input()[::-1] else "NO"))
| print((["NO", "YES"][eval(input()) == input()[::-1]]))
| false | 0 | [
"-print((\"YES\" if eval(input()) == input()[::-1] else \"NO\"))",
"+print(([\"NO\", \"YES\"][eval(input()) == input()[::-1]]))"
]
| false | 0.045499 | 0.047741 | 0.953051 | [
"s078452076",
"s877674552"
]
|
u424209323 | p02273 | python | s702766270 | s391341518 | 30 | 20 | 6,656 | 6,652 | Accepted | Accepted | 33.33 | import math
def koch(n, x1, y1, x2, y2):
if n == 0:
return
theta60 = math.radians(60)
sx = ( 2 * x1 + x2 ) /3
sy = ( 2 * y1 + y2 ) /3
tx = ( 2 * x2 + x1 ) /3
ty = ( 2 * y2 + y1 ) /3
ux = ( tx - sx ) * math.cos( theta60 ) - ( ty - sy ) * math.sin( theta60 ) + sx
uy = ( tx - sx ) * math.sin( theta60 ) + ( ty - sy ) * math.cos( theta60 ) + sy
koch(n-1, x1, y1, sx, sy)
print(sx, sy)
koch(n-1, sx, sy, ux, uy)
print(ux, uy)
koch(n-1, ux, uy, tx, ty)
print(tx, ty)
koch(n-1, tx, ty, x2, y2)
n = eval(input())
p1x = float(0.)
p1y = float(0.)
p2x = float(100.)
p2y = float(0.)
print(p1x, p1y)
koch(n, p1x, p1y, p2x, p2y)
print(p2x, p2y) | import math
def kock(n, x1, y1, x2, y2):
if n == 0:
return
angle = math.radians(60)
sx = (2*x1 + x2)/3
sy = (2*y1 + y2)/3
tx = (2*x2 + x1)/3
ty = (2*y2 + y1)/3
ux = (tx - sx)*math.cos(angle) - (ty - sy)*math.sin(angle) + sx
uy = (tx - sx)*math.sin(angle) + (ty - sy)*math.cos(angle) + sy
kock(n-1, x1, y1, sx, sy)
print(sx, sy)
kock(n-1, sx, sy, ux, uy)
print(ux, uy)
kock(n-1, ux, uy, tx, ty)
print(tx, ty)
kock(n-1, tx, ty, x2, y2)
n = eval(input())
p1x = float(0.)
p1y = float(0.)
p2x = float(100.)
p2y = float(0.)
print(p1x, p1y)
kock(n, p1x, p1y, p2x, p2y)
print(p2x, p2y) | 33 | 33 | 760 | 673 | import math
def koch(n, x1, y1, x2, y2):
if n == 0:
return
theta60 = math.radians(60)
sx = (2 * x1 + x2) / 3
sy = (2 * y1 + y2) / 3
tx = (2 * x2 + x1) / 3
ty = (2 * y2 + y1) / 3
ux = (tx - sx) * math.cos(theta60) - (ty - sy) * math.sin(theta60) + sx
uy = (tx - sx) * math.sin(theta60) + (ty - sy) * math.cos(theta60) + sy
koch(n - 1, x1, y1, sx, sy)
print(sx, sy)
koch(n - 1, sx, sy, ux, uy)
print(ux, uy)
koch(n - 1, ux, uy, tx, ty)
print(tx, ty)
koch(n - 1, tx, ty, x2, y2)
n = eval(input())
p1x = float(0.0)
p1y = float(0.0)
p2x = float(100.0)
p2y = float(0.0)
print(p1x, p1y)
koch(n, p1x, p1y, p2x, p2y)
print(p2x, p2y)
| import math
def kock(n, x1, y1, x2, y2):
if n == 0:
return
angle = math.radians(60)
sx = (2 * x1 + x2) / 3
sy = (2 * y1 + y2) / 3
tx = (2 * x2 + x1) / 3
ty = (2 * y2 + y1) / 3
ux = (tx - sx) * math.cos(angle) - (ty - sy) * math.sin(angle) + sx
uy = (tx - sx) * math.sin(angle) + (ty - sy) * math.cos(angle) + sy
kock(n - 1, x1, y1, sx, sy)
print(sx, sy)
kock(n - 1, sx, sy, ux, uy)
print(ux, uy)
kock(n - 1, ux, uy, tx, ty)
print(tx, ty)
kock(n - 1, tx, ty, x2, y2)
n = eval(input())
p1x = float(0.0)
p1y = float(0.0)
p2x = float(100.0)
p2y = float(0.0)
print(p1x, p1y)
kock(n, p1x, p1y, p2x, p2y)
print(p2x, p2y)
| false | 0 | [
"-def koch(n, x1, y1, x2, y2):",
"+def kock(n, x1, y1, x2, y2):",
"- theta60 = math.radians(60)",
"+ angle = math.radians(60)",
"- ux = (tx - sx) * math.cos(theta60) - (ty - sy) * math.sin(theta60) + sx",
"- uy = (tx - sx) * math.sin(theta60) + (ty - sy) * math.cos(theta60) + sy",
"- koch(n - 1, x1, y1, sx, sy)",
"+ ux = (tx - sx) * math.cos(angle) - (ty - sy) * math.sin(angle) + sx",
"+ uy = (tx - sx) * math.sin(angle) + (ty - sy) * math.cos(angle) + sy",
"+ kock(n - 1, x1, y1, sx, sy)",
"- koch(n - 1, sx, sy, ux, uy)",
"+ kock(n - 1, sx, sy, ux, uy)",
"- koch(n - 1, ux, uy, tx, ty)",
"+ kock(n - 1, ux, uy, tx, ty)",
"- koch(n - 1, tx, ty, x2, y2)",
"+ kock(n - 1, tx, ty, x2, y2)",
"-koch(n, p1x, p1y, p2x, p2y)",
"+kock(n, p1x, p1y, p2x, p2y)"
]
| false | 0.047184 | 0.038339 | 1.230699 | [
"s702766270",
"s391341518"
]
|
u673361376 | p03546 | python | s707654030 | s807867656 | 193 | 33 | 40,300 | 3,976 | Accepted | Accepted | 82.9 | H,W = list(map(int,input().split()))
C = [list(map(int,input().split())) for _ in range(10)]
cntA = {}
for _ in range(H):
for a in map(int,input().split()):
if a not in cntA:
cntA[a] = 1
else:
cntA[a] += 1
for k in range(10):
for i in range(10):
for j in range(10):
C[i][j] = min(C[i][j], C[i][k]+C[k][j])
ans = 0
for key, num in list(cntA.items()):
if key not in [-1,1]:
ans += C[key][1]*num
print(ans) | import copy
from collections import Counter
def make_table():
dp = copy.deepcopy(C)
for k in range(N):
for i in range(N):
for j in range(N):
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
return dp
N = 10
H, W = list(map(int, input().split()))
C = [list(map(int, input().split())) for _ in range(N)]
A = []
for _ in range(H):
A.extend(list(map(int, input().split())))
cntA = Counter(A)
dp = make_table()
print((sum([dp[key][1] * cntA[key] if key != -1 else 0 for key in cntA]))) | 20 | 26 | 458 | 554 | H, W = list(map(int, input().split()))
C = [list(map(int, input().split())) for _ in range(10)]
cntA = {}
for _ in range(H):
for a in map(int, input().split()):
if a not in cntA:
cntA[a] = 1
else:
cntA[a] += 1
for k in range(10):
for i in range(10):
for j in range(10):
C[i][j] = min(C[i][j], C[i][k] + C[k][j])
ans = 0
for key, num in list(cntA.items()):
if key not in [-1, 1]:
ans += C[key][1] * num
print(ans)
| import copy
from collections import Counter
def make_table():
dp = copy.deepcopy(C)
for k in range(N):
for i in range(N):
for j in range(N):
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
return dp
N = 10
H, W = list(map(int, input().split()))
C = [list(map(int, input().split())) for _ in range(N)]
A = []
for _ in range(H):
A.extend(list(map(int, input().split())))
cntA = Counter(A)
dp = make_table()
print((sum([dp[key][1] * cntA[key] if key != -1 else 0 for key in cntA])))
| false | 23.076923 | [
"+import copy",
"+from collections import Counter",
"+",
"+",
"+def make_table():",
"+ dp = copy.deepcopy(C)",
"+ for k in range(N):",
"+ for i in range(N):",
"+ for j in range(N):",
"+ dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])",
"+ return dp",
"+",
"+",
"+N = 10",
"-C = [list(map(int, input().split())) for _ in range(10)]",
"-cntA = {}",
"+C = [list(map(int, input().split())) for _ in range(N)]",
"+A = []",
"- for a in map(int, input().split()):",
"- if a not in cntA:",
"- cntA[a] = 1",
"- else:",
"- cntA[a] += 1",
"-for k in range(10):",
"- for i in range(10):",
"- for j in range(10):",
"- C[i][j] = min(C[i][j], C[i][k] + C[k][j])",
"-ans = 0",
"-for key, num in list(cntA.items()):",
"- if key not in [-1, 1]:",
"- ans += C[key][1] * num",
"-print(ans)",
"+ A.extend(list(map(int, input().split())))",
"+cntA = Counter(A)",
"+dp = make_table()",
"+print((sum([dp[key][1] * cntA[key] if key != -1 else 0 for key in cntA])))"
]
| false | 0.069843 | 0.058987 | 1.184044 | [
"s707654030",
"s807867656"
]
|
u564589929 | p02936 | python | s916913238 | s192427765 | 1,712 | 948 | 67,208 | 67,284 | Accepted | Accepted | 44.63 | 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)]
def printlist(lst, k='\n'): print((k.join(list(map(str, lst)))))
INF = float('inf')
from collections import deque
def solve():
n, q = MI()
e = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = MI1()
e[a].append(b)
e[b].append(a)
point = [0] * n
for _ in range(q):
p, x = MI()
p -= 1
point[p] += x
d = deque([(0, point[0])])
used = [0] * n
used[0] = 1
l = 1
while l > 0:
v, p = d.popleft()
l -= 1
for nv in e[v]:
if used[nv]: continue
used[nv] = 1
point[nv] += p
d.append((nv, point[nv]))
l += 1
printlist(point, " ")
if __name__ == '__main__':
solve()
| import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def printlist(lst, k='\n'): print((k.join(list(map(str, lst)))))
INF = float('inf')
from collections import deque
def solve():
n, q = MI()
e = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = MI1()
e[a].append(b)
e[b].append(a)
point = [0] * n
for _ in range(q):
p, x = MI()
p -= 1
point[p] += x
d = deque([(0, point[0])])
used = [0] * n
used[0] = 1
l = 1
while l > 0:
v, p = d.popleft()
l -= 1
for nv in e[v]:
if used[nv]: continue
used[nv] = 1
point[nv] += p
d.append((nv, point[nv]))
l += 1
printlist(point, " ")
if __name__ == '__main__':
solve()
| 49 | 49 | 1,178 | 1,176 | 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)]
def printlist(lst, k="\n"):
print((k.join(list(map(str, lst)))))
INF = float("inf")
from collections import deque
def solve():
n, q = MI()
e = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = MI1()
e[a].append(b)
e[b].append(a)
point = [0] * n
for _ in range(q):
p, x = MI()
p -= 1
point[p] += x
d = deque([(0, point[0])])
used = [0] * n
used[0] = 1
l = 1
while l > 0:
v, p = d.popleft()
l -= 1
for nv in e[v]:
if used[nv]:
continue
used[nv] = 1
point[nv] += p
d.append((nv, point[nv]))
l += 1
printlist(point, " ")
if __name__ == "__main__":
solve()
| import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LI1():
return list(map(int1, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def printlist(lst, k="\n"):
print((k.join(list(map(str, lst)))))
INF = float("inf")
from collections import deque
def solve():
n, q = MI()
e = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = MI1()
e[a].append(b)
e[b].append(a)
point = [0] * n
for _ in range(q):
p, x = MI()
p -= 1
point[p] += x
d = deque([(0, point[0])])
used = [0] * n
used[0] = 1
l = 1
while l > 0:
v, p = d.popleft()
l -= 1
for nv in e[v]:
if used[nv]:
continue
used[nv] = 1
point[nv] += p
d.append((nv, point[nv]))
l += 1
printlist(point, " ")
if __name__ == "__main__":
solve()
| false | 0 | [
"-# input = sys.stdin.readline ####",
"+input = sys.stdin.readline ####"
]
| false | 0.036851 | 0.04201 | 0.877201 | [
"s916913238",
"s192427765"
]
|
u094191970 | p02579 | python | s823891467 | s100307624 | 791 | 718 | 135,012 | 133,424 | Accepted | Accepted | 9.23 | from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque
h,w=nii()
ch,cw=nii()
dh,dw=nii()
s=[list(eval(input())) for i in range(h)]
ch-=1
cw-=1
dh-=1
dw-=1
dist=[[-1]*w for i in range(h)]
dist[ch][cw]=0
que=deque()
que.append((ch,cw))
def BFS():
while que:
y,x=que.popleft()
if y==dh and x==dw:
print((dist[y][x]))
exit()
for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
ny=y+dy
nx=x+dx
if 0<=ny<h and 0<=nx<w and s[ny][nx]!='#':
que.appendleft((ny,nx))
s[ny][nx]='#'
dist[ny][nx]=dist[y][x]
for i in range(-2,3):
for j in range(-2,3):
ny=y+i
nx=x+j
if 0<=ny<h and 0<=nx<w and s[ny][nx]!='#' and dist[ny][nx]==-1:
que.append((ny,nx))
dist[ny][nx]=dist[y][x]+1
BFS()
print((-1)) | from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque
h,w=nii()
ch,cw=nii()
dh,dw=nii()
s=[list(eval(input())) for i in range(h)]
ch-=1
cw-=1
dh-=1
dw-=1
ans=[[-1]*w for i in range(h)]
ans[ch][cw]=0
que=deque()
que.append((ch,cw))
while que:
y,x=que.popleft()
if y==dh and x==dw:
print((ans[y][x]))
exit()
for dy,dx in [[-1,0],[1,0],[0,-1],[0,1]]:
ny=y+dy
nx=x+dx
if 0<=ny<h and 0<=nx<w and s[ny][nx]!='#':
que.appendleft((ny,nx))
s[ny][nx]='#'
ans[ny][nx]=ans[y][x]
for i in range(-2,3):
for j in range(-2,3):
ny=y+i
nx=x+j
if 0<=ny<h and 0<=nx<w and s[ny][nx]!='#' and ans[ny][nx]==-1:
que.append((ny,nx))
ans[ny][nx]=ans[y][x]+1
print((-1)) | 48 | 45 | 932 | 865 | from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
from collections import deque
h, w = nii()
ch, cw = nii()
dh, dw = nii()
s = [list(eval(input())) for i in range(h)]
ch -= 1
cw -= 1
dh -= 1
dw -= 1
dist = [[-1] * w for i in range(h)]
dist[ch][cw] = 0
que = deque()
que.append((ch, cw))
def BFS():
while que:
y, x = que.popleft()
if y == dh and x == dw:
print((dist[y][x]))
exit()
for dy, dx in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
ny = y + dy
nx = x + dx
if 0 <= ny < h and 0 <= nx < w and s[ny][nx] != "#":
que.appendleft((ny, nx))
s[ny][nx] = "#"
dist[ny][nx] = dist[y][x]
for i in range(-2, 3):
for j in range(-2, 3):
ny = y + i
nx = x + j
if (
0 <= ny < h
and 0 <= nx < w
and s[ny][nx] != "#"
and dist[ny][nx] == -1
):
que.append((ny, nx))
dist[ny][nx] = dist[y][x] + 1
BFS()
print((-1))
| from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
from collections import deque
h, w = nii()
ch, cw = nii()
dh, dw = nii()
s = [list(eval(input())) for i in range(h)]
ch -= 1
cw -= 1
dh -= 1
dw -= 1
ans = [[-1] * w for i in range(h)]
ans[ch][cw] = 0
que = deque()
que.append((ch, cw))
while que:
y, x = que.popleft()
if y == dh and x == dw:
print((ans[y][x]))
exit()
for dy, dx in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
ny = y + dy
nx = x + dx
if 0 <= ny < h and 0 <= nx < w and s[ny][nx] != "#":
que.appendleft((ny, nx))
s[ny][nx] = "#"
ans[ny][nx] = ans[y][x]
for i in range(-2, 3):
for j in range(-2, 3):
ny = y + i
nx = x + j
if 0 <= ny < h and 0 <= nx < w and s[ny][nx] != "#" and ans[ny][nx] == -1:
que.append((ny, nx))
ans[ny][nx] = ans[y][x] + 1
print((-1))
| false | 6.25 | [
"-dist = [[-1] * w for i in range(h)]",
"-dist[ch][cw] = 0",
"+ans = [[-1] * w for i in range(h)]",
"+ans[ch][cw] = 0",
"-",
"-",
"-def BFS():",
"- while que:",
"- y, x = que.popleft()",
"- if y == dh and x == dw:",
"- print((dist[y][x]))",
"- exit()",
"- for dy, dx in [[1, 0], [-1, 0], [0, 1], [0, -1]]:",
"- ny = y + dy",
"- nx = x + dx",
"- if 0 <= ny < h and 0 <= nx < w and s[ny][nx] != \"#\":",
"- que.appendleft((ny, nx))",
"- s[ny][nx] = \"#\"",
"- dist[ny][nx] = dist[y][x]",
"- for i in range(-2, 3):",
"- for j in range(-2, 3):",
"- ny = y + i",
"- nx = x + j",
"- if (",
"- 0 <= ny < h",
"- and 0 <= nx < w",
"- and s[ny][nx] != \"#\"",
"- and dist[ny][nx] == -1",
"- ):",
"- que.append((ny, nx))",
"- dist[ny][nx] = dist[y][x] + 1",
"-",
"-",
"-BFS()",
"+while que:",
"+ y, x = que.popleft()",
"+ if y == dh and x == dw:",
"+ print((ans[y][x]))",
"+ exit()",
"+ for dy, dx in [[-1, 0], [1, 0], [0, -1], [0, 1]]:",
"+ ny = y + dy",
"+ nx = x + dx",
"+ if 0 <= ny < h and 0 <= nx < w and s[ny][nx] != \"#\":",
"+ que.appendleft((ny, nx))",
"+ s[ny][nx] = \"#\"",
"+ ans[ny][nx] = ans[y][x]",
"+ for i in range(-2, 3):",
"+ for j in range(-2, 3):",
"+ ny = y + i",
"+ nx = x + j",
"+ if 0 <= ny < h and 0 <= nx < w and s[ny][nx] != \"#\" and ans[ny][nx] == -1:",
"+ que.append((ny, nx))",
"+ ans[ny][nx] = ans[y][x] + 1"
]
| false | 0.046976 | 0.045595 | 1.03027 | [
"s823891467",
"s100307624"
]
|
u211160392 | p03048 | python | s704842094 | s474748933 | 1,471 | 297 | 3,060 | 40,812 | Accepted | Accepted | 79.81 | import math
R,G,B,N = list(map(int,input().split()))
ans = 0
r,g,b = 0,0,0
for i in range(math.floor(N/R)+1):
for j in range(math.floor((N-i*R)/G)+1):
if (N-R*i-G*j)%B == 0:
ans += 1
print(ans) | R, G, B, N = list(map(int,input().split()))
ans = 0
for r in range(N+1):
for g in range(N+1):
b = N - r*R - g*G
if 0 <= b and b%B == 0:
ans += 1
print(ans) | 9 | 8 | 219 | 188 | import math
R, G, B, N = list(map(int, input().split()))
ans = 0
r, g, b = 0, 0, 0
for i in range(math.floor(N / R) + 1):
for j in range(math.floor((N - i * R) / G) + 1):
if (N - R * i - G * j) % B == 0:
ans += 1
print(ans)
| R, G, B, N = list(map(int, input().split()))
ans = 0
for r in range(N + 1):
for g in range(N + 1):
b = N - r * R - g * G
if 0 <= b and b % B == 0:
ans += 1
print(ans)
| false | 11.111111 | [
"-import math",
"-",
"-r, g, b = 0, 0, 0",
"-for i in range(math.floor(N / R) + 1):",
"- for j in range(math.floor((N - i * R) / G) + 1):",
"- if (N - R * i - G * j) % B == 0:",
"+for r in range(N + 1):",
"+ for g in range(N + 1):",
"+ b = N - r * R - g * G",
"+ if 0 <= b and b % B == 0:"
]
| false | 0.075772 | 1.554283 | 0.04875 | [
"s704842094",
"s474748933"
]
|
u903005414 | p02947 | python | s769120997 | s520602695 | 375 | 346 | 19,824 | 19,764 | Accepted | Accepted | 7.73 | from collections import Counter
N = int(eval(input()))
S = []
for _ in range(N):
s = list(eval(input()))
s.sort()
s = ''.join(s)
S.append(s)
counter = Counter(S)
ans = 0
for v in list(counter.values()):
ans += v * (v - 1) // 2
print(ans)
| from collections import Counter
N = int(eval(input()))
S = [''.join(sorted(eval(input()))) for _ in range(N)]
counter = Counter(S)
ans = 0
for v in list(counter.values()):
ans += v * (v - 1) // 2
print(ans)
| 16 | 10 | 258 | 204 | from collections import Counter
N = int(eval(input()))
S = []
for _ in range(N):
s = list(eval(input()))
s.sort()
s = "".join(s)
S.append(s)
counter = Counter(S)
ans = 0
for v in list(counter.values()):
ans += v * (v - 1) // 2
print(ans)
| from collections import Counter
N = int(eval(input()))
S = ["".join(sorted(eval(input()))) for _ in range(N)]
counter = Counter(S)
ans = 0
for v in list(counter.values()):
ans += v * (v - 1) // 2
print(ans)
| false | 37.5 | [
"-S = []",
"-for _ in range(N):",
"- s = list(eval(input()))",
"- s.sort()",
"- s = \"\".join(s)",
"- S.append(s)",
"+S = [\"\".join(sorted(eval(input()))) for _ in range(N)]"
]
| false | 0.037686 | 0.036841 | 1.022941 | [
"s769120997",
"s520602695"
]
|
u401452016 | p02861 | python | s080420745 | s840229710 | 383 | 348 | 7,972 | 8,052 | Accepted | Accepted | 9.14 | import sys
import itertools
import math
n = int(sys.stdin.readline())
pos = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
a = list(itertools.permutations(pos, n))
#print(pos)
ans = 0
for ele in a:
#print(ele)
for i in range(n-1):
ans += math.sqrt((ele[i][0] - ele[i+1][0])**2 + (ele[i][1] - ele[i+1][1])**2)
print((ans/len(a))) | #ABC145C
def main():
import sys, math
import itertools as ite
N = int(sys.stdin.readline())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
#print(L)
A = list(ite.permutations([i for i in range(N)]))
#print(A)
ans = 0
for a in A:
for i in range(N-1):
ans += math.sqrt((L[a[i]][0]- L[a[i+1]][0])**2 + (L[a[i]][1]- L[a[i+1]][1])**2)
print((ans/len(A)))
if __name__=='__main__':
main() | 14 | 23 | 374 | 510 | import sys
import itertools
import math
n = int(sys.stdin.readline())
pos = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
a = list(itertools.permutations(pos, n))
# print(pos)
ans = 0
for ele in a:
# print(ele)
for i in range(n - 1):
ans += math.sqrt(
(ele[i][0] - ele[i + 1][0]) ** 2 + (ele[i][1] - ele[i + 1][1]) ** 2
)
print((ans / len(a)))
| # ABC145C
def main():
import sys, math
import itertools as ite
N = int(sys.stdin.readline())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
# print(L)
A = list(ite.permutations([i for i in range(N)]))
# print(A)
ans = 0
for a in A:
for i in range(N - 1):
ans += math.sqrt(
(L[a[i]][0] - L[a[i + 1]][0]) ** 2 + (L[a[i]][1] - L[a[i + 1]][1]) ** 2
)
print((ans / len(A)))
if __name__ == "__main__":
main()
| false | 39.130435 | [
"-import sys",
"-import itertools",
"-import math",
"+# ABC145C",
"+def main():",
"+ import sys, math",
"+ import itertools as ite",
"-n = int(sys.stdin.readline())",
"-pos = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]",
"-a = list(itertools.permutations(pos, n))",
"-# print(pos)",
"-ans = 0",
"-for ele in a:",
"- # print(ele)",
"- for i in range(n - 1):",
"- ans += math.sqrt(",
"- (ele[i][0] - ele[i + 1][0]) ** 2 + (ele[i][1] - ele[i + 1][1]) ** 2",
"- )",
"-print((ans / len(a)))",
"+ N = int(sys.stdin.readline())",
"+ L = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]",
"+ # print(L)",
"+ A = list(ite.permutations([i for i in range(N)]))",
"+ # print(A)",
"+ ans = 0",
"+ for a in A:",
"+ for i in range(N - 1):",
"+ ans += math.sqrt(",
"+ (L[a[i]][0] - L[a[i + 1]][0]) ** 2 + (L[a[i]][1] - L[a[i + 1]][1]) ** 2",
"+ )",
"+ print((ans / len(A)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.047383 | 0.047933 | 0.98852 | [
"s080420745",
"s840229710"
]
|
u504836877 | p03775 | python | s473491823 | s069388857 | 82 | 70 | 3,060 | 3,060 | Accepted | Accepted | 14.63 | N = int(eval(input()))
def F(a, b):
return max(len(str(a)), len(str(b)))
ans = 100
i = 1
while i <= N**0.5:
if N%i == 0:
ans = min(ans, F(i, N//i))
i += 1
print(ans) | N = int(eval(input()))
def f(a, b):
return max(len(str(a)), len(str(b)))
ans = N
i = 1
while i <= N**0.5:
if N%i == 0:
ans = min(ans, f(i, N//i))
i += 1
print(ans) | 13 | 13 | 198 | 192 | N = int(eval(input()))
def F(a, b):
return max(len(str(a)), len(str(b)))
ans = 100
i = 1
while i <= N**0.5:
if N % i == 0:
ans = min(ans, F(i, N // i))
i += 1
print(ans)
| N = int(eval(input()))
def f(a, b):
return max(len(str(a)), len(str(b)))
ans = N
i = 1
while i <= N**0.5:
if N % i == 0:
ans = min(ans, f(i, N // i))
i += 1
print(ans)
| false | 0 | [
"-def F(a, b):",
"+def f(a, b):",
"-ans = 100",
"+ans = N",
"- ans = min(ans, F(i, N // i))",
"+ ans = min(ans, f(i, N // i))"
]
| false | 0.326413 | 0.007378 | 44.241901 | [
"s473491823",
"s069388857"
]
|
u502314533 | p03231 | python | s143061295 | s572143746 | 46 | 36 | 5,432 | 5,432 | Accepted | Accepted | 21.74 | from fractions import *
def lcm(a,b):
return int(abs(a * b) / gcd(a,b) if a and b else 0)
def getDivisors(a,b):
divisors = []
for i in range(2,min(a,b)+1):
if a % i == 0 and b % i == 0:
divisors.append(i)
return divisors
N,M = list(map(int,input().split()))
a = eval(input())
b = eval(input())
if a[0] != b[0]:
print((-1))
elif gcd(N,M) == 1:
print((lcm(N,M)))
elif N != M:
divisors = getDivisors(N,M)
for i in divisors:
k = N//i
l = M//i
while k < N and l < M:
if a[k] != b[l]:
print((-1))
quit()
k += N//i
l += M//i
print((lcm(N,M)))
else:
if a == b: print(N)
else: print((-1))
| from fractions import gcd
def lcm(a,b):
return int(abs(a * b) / gcd(a,b) if a and b else 0)
N,M = list(map(int,input().split()))
S = eval(input())
T = eval(input())
g = gcd(N,M)
n = N // g
m = M // g
for k in range(g):
if S[k * n] != T[k * m]:
print((-1))
quit()
print((lcm(N,M))) | 38 | 18 | 753 | 304 | from fractions import *
def lcm(a, b):
return int(abs(a * b) / gcd(a, b) if a and b else 0)
def getDivisors(a, b):
divisors = []
for i in range(2, min(a, b) + 1):
if a % i == 0 and b % i == 0:
divisors.append(i)
return divisors
N, M = list(map(int, input().split()))
a = eval(input())
b = eval(input())
if a[0] != b[0]:
print((-1))
elif gcd(N, M) == 1:
print((lcm(N, M)))
elif N != M:
divisors = getDivisors(N, M)
for i in divisors:
k = N // i
l = M // i
while k < N and l < M:
if a[k] != b[l]:
print((-1))
quit()
k += N // i
l += M // i
print((lcm(N, M)))
else:
if a == b:
print(N)
else:
print((-1))
| from fractions import gcd
def lcm(a, b):
return int(abs(a * b) / gcd(a, b) if a and b else 0)
N, M = list(map(int, input().split()))
S = eval(input())
T = eval(input())
g = gcd(N, M)
n = N // g
m = M // g
for k in range(g):
if S[k * n] != T[k * m]:
print((-1))
quit()
print((lcm(N, M)))
| false | 52.631579 | [
"-from fractions import *",
"+from fractions import gcd",
"-def getDivisors(a, b):",
"- divisors = []",
"- for i in range(2, min(a, b) + 1):",
"- if a % i == 0 and b % i == 0:",
"- divisors.append(i)",
"- return divisors",
"-",
"-",
"-a = eval(input())",
"-b = eval(input())",
"-if a[0] != b[0]:",
"- print((-1))",
"-elif gcd(N, M) == 1:",
"- print((lcm(N, M)))",
"-elif N != M:",
"- divisors = getDivisors(N, M)",
"- for i in divisors:",
"- k = N // i",
"- l = M // i",
"- while k < N and l < M:",
"- if a[k] != b[l]:",
"- print((-1))",
"- quit()",
"- k += N // i",
"- l += M // i",
"- print((lcm(N, M)))",
"-else:",
"- if a == b:",
"- print(N)",
"- else:",
"+S = eval(input())",
"+T = eval(input())",
"+g = gcd(N, M)",
"+n = N // g",
"+m = M // g",
"+for k in range(g):",
"+ if S[k * n] != T[k * m]:",
"+ quit()",
"+print((lcm(N, M)))"
]
| false | 0.051437 | 0.059624 | 0.862688 | [
"s143061295",
"s572143746"
]
|
u777923818 | p03475 | python | s202745695 | s458540721 | 92 | 77 | 3,188 | 3,188 | Accepted | Accepted | 16.3 | # -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
stations = []
for _ in range(N-1):
stations.append(inpl())
P = []
for i in range(N-1):
C, S, F = stations[i]
P = [C + max(S, F*(p//F + int(p%F!=0))) for p in P]
P.append(S+C)
for p in P:
print(p)
print((0)) | # -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
stations = [inpl() for _ in range(N-1)]
for i in range(N):
now = 0
for C, S, F in stations[i:]:
if now <= S:
now = S
now = S + -(-(now - S)//F)*F + C
print(now)
| 18 | 14 | 339 | 317 | # -*- coding: utf-8 -*-
def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
stations = []
for _ in range(N - 1):
stations.append(inpl())
P = []
for i in range(N - 1):
C, S, F = stations[i]
P = [C + max(S, F * (p // F + int(p % F != 0))) for p in P]
P.append(S + C)
for p in P:
print(p)
print((0))
| # -*- coding: utf-8 -*-
def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
stations = [inpl() for _ in range(N - 1)]
for i in range(N):
now = 0
for C, S, F in stations[i:]:
if now <= S:
now = S
now = S + -(-(now - S) // F) * F + C
print(now)
| false | 22.222222 | [
"-stations = []",
"-for _ in range(N - 1):",
"- stations.append(inpl())",
"-P = []",
"-for i in range(N - 1):",
"- C, S, F = stations[i]",
"- P = [C + max(S, F * (p // F + int(p % F != 0))) for p in P]",
"- P.append(S + C)",
"-for p in P:",
"- print(p)",
"-print((0))",
"+stations = [inpl() for _ in range(N - 1)]",
"+for i in range(N):",
"+ now = 0",
"+ for C, S, F in stations[i:]:",
"+ if now <= S:",
"+ now = S",
"+ now = S + -(-(now - S) // F) * F + C",
"+ print(now)"
]
| false | 0.041174 | 0.040927 | 1.006036 | [
"s202745695",
"s458540721"
]
|
u111365362 | p03074 | python | s240180598 | s556057568 | 392 | 76 | 24,500 | 10,492 | Accepted | Accepted | 80.61 | N,K = list(map(int,input().split()))
S = eval(input())
if S[0] == '0':
divide = []
else:
divide = [0]
tmp = 1
for i in range(1,N):
if S[i] == S[i-1]:
tmp += 1
else:
divide += [tmp]
tmp = 1
divide += [tmp]
le = len(divide)
zero = [0]*2*le + divide + [0]*2*le
su = [0]
for i in range(0,5*le):
su += [su[-1]+zero[i]]
del su[0]
lle = len(su)
mxm = 0
for k in range(K,lle):
if 2*k+1 >= lle:
break
cd = su[2*k+1] - su[2*k-2*K]
if cd > mxm:
mxm = cd
xmx = max(divide)
print((max(mxm,xmx))) | #20:03
n,k = list(map(int,input().split()))
s = eval(input())
if s[0] == '1':
can01 = [0]
can10 = []
else:
can01 = [0]
can10 = [0]
for i in range(1,n):
if s[i-1] == '0' and s[i] == '1':
can01.append(i)
elif s[i-1] == '1' and s[i] == '0':
can10.append(i)
if s[n-1] == '1':
can10.append(n)
else:
can10.append(n)
can01.append(n)
#print(can01,can10)
can01 = [0] * k + can01
can10 = can10 + [n] * k
#print(can01,can10)
ans = []
for i in range(len(can10)):
ans.append(can10[i] - can01[i])
print((max(ans))) | 30 | 27 | 533 | 540 | N, K = list(map(int, input().split()))
S = eval(input())
if S[0] == "0":
divide = []
else:
divide = [0]
tmp = 1
for i in range(1, N):
if S[i] == S[i - 1]:
tmp += 1
else:
divide += [tmp]
tmp = 1
divide += [tmp]
le = len(divide)
zero = [0] * 2 * le + divide + [0] * 2 * le
su = [0]
for i in range(0, 5 * le):
su += [su[-1] + zero[i]]
del su[0]
lle = len(su)
mxm = 0
for k in range(K, lle):
if 2 * k + 1 >= lle:
break
cd = su[2 * k + 1] - su[2 * k - 2 * K]
if cd > mxm:
mxm = cd
xmx = max(divide)
print((max(mxm, xmx)))
| # 20:03
n, k = list(map(int, input().split()))
s = eval(input())
if s[0] == "1":
can01 = [0]
can10 = []
else:
can01 = [0]
can10 = [0]
for i in range(1, n):
if s[i - 1] == "0" and s[i] == "1":
can01.append(i)
elif s[i - 1] == "1" and s[i] == "0":
can10.append(i)
if s[n - 1] == "1":
can10.append(n)
else:
can10.append(n)
can01.append(n)
# print(can01,can10)
can01 = [0] * k + can01
can10 = can10 + [n] * k
# print(can01,can10)
ans = []
for i in range(len(can10)):
ans.append(can10[i] - can01[i])
print((max(ans)))
| false | 10 | [
"-N, K = list(map(int, input().split()))",
"-S = eval(input())",
"-if S[0] == \"0\":",
"- divide = []",
"+# 20:03",
"+n, k = list(map(int, input().split()))",
"+s = eval(input())",
"+if s[0] == \"1\":",
"+ can01 = [0]",
"+ can10 = []",
"- divide = [0]",
"-tmp = 1",
"-for i in range(1, N):",
"- if S[i] == S[i - 1]:",
"- tmp += 1",
"- else:",
"- divide += [tmp]",
"- tmp = 1",
"-divide += [tmp]",
"-le = len(divide)",
"-zero = [0] * 2 * le + divide + [0] * 2 * le",
"-su = [0]",
"-for i in range(0, 5 * le):",
"- su += [su[-1] + zero[i]]",
"-del su[0]",
"-lle = len(su)",
"-mxm = 0",
"-for k in range(K, lle):",
"- if 2 * k + 1 >= lle:",
"- break",
"- cd = su[2 * k + 1] - su[2 * k - 2 * K]",
"- if cd > mxm:",
"- mxm = cd",
"-xmx = max(divide)",
"-print((max(mxm, xmx)))",
"+ can01 = [0]",
"+ can10 = [0]",
"+for i in range(1, n):",
"+ if s[i - 1] == \"0\" and s[i] == \"1\":",
"+ can01.append(i)",
"+ elif s[i - 1] == \"1\" and s[i] == \"0\":",
"+ can10.append(i)",
"+if s[n - 1] == \"1\":",
"+ can10.append(n)",
"+else:",
"+ can10.append(n)",
"+ can01.append(n)",
"+# print(can01,can10)",
"+can01 = [0] * k + can01",
"+can10 = can10 + [n] * k",
"+# print(can01,can10)",
"+ans = []",
"+for i in range(len(can10)):",
"+ ans.append(can10[i] - can01[i])",
"+print((max(ans)))"
]
| false | 0.097616 | 0.038409 | 2.541506 | [
"s240180598",
"s556057568"
]
|
u269969976 | p03329 | python | s868915125 | s453213328 | 935 | 326 | 3,864 | 6,124 | Accepted | Accepted | 65.13 | # coding:utf-8
n = int(input().rstrip())
dic = [None for i in range(n + 1)]
def get_ans(amount:int):
if dic[amount] is not None:
return dic[amount]
if amount <= 0:
return 0
ans = amount
for i in reversed(list(range(6))):
num = pow(9, i)
if num > amount:
continue
ret = get_ans(amount - num) + 1
ans = min(ans, ret)
for i in reversed(list(range(7))):
num = pow(6, i)
if num > amount:
continue
ret = get_ans(amount - num) + 1
ans = min(ans, ret)
dic[amount] = ans
return ans
print((get_ans(n))) | # coding: utf-8
def get_pow(target: int, base: int):
ans = 0
current = base
for i in range(1, target + 1):
if current > target:
break
ans = i
current *= base
return ans
dic = {}
def get_ans(remain: int):
if remain in dic:
return dic[remain]
if remain < 6:
return max(0, remain)
ans = remain
pos9 = get_pow(remain, 9)
for i in reversed(list(range(1, pos9 + 1))):
ret = get_ans(remain - pow(9, i)) + 1
ans = min(ans, ret)
pow6 = get_pow(remain, 6)
for i in reversed(list(range(1, pow6 + 1))):
ret = get_ans(remain - pow(6, i)) + 1
ans = min(ans, ret)
dic[remain] = ans
return ans
n = int(input().rstrip())
print((get_ans(n)))
| 32 | 39 | 649 | 794 | # coding:utf-8
n = int(input().rstrip())
dic = [None for i in range(n + 1)]
def get_ans(amount: int):
if dic[amount] is not None:
return dic[amount]
if amount <= 0:
return 0
ans = amount
for i in reversed(list(range(6))):
num = pow(9, i)
if num > amount:
continue
ret = get_ans(amount - num) + 1
ans = min(ans, ret)
for i in reversed(list(range(7))):
num = pow(6, i)
if num > amount:
continue
ret = get_ans(amount - num) + 1
ans = min(ans, ret)
dic[amount] = ans
return ans
print((get_ans(n)))
| # coding: utf-8
def get_pow(target: int, base: int):
ans = 0
current = base
for i in range(1, target + 1):
if current > target:
break
ans = i
current *= base
return ans
dic = {}
def get_ans(remain: int):
if remain in dic:
return dic[remain]
if remain < 6:
return max(0, remain)
ans = remain
pos9 = get_pow(remain, 9)
for i in reversed(list(range(1, pos9 + 1))):
ret = get_ans(remain - pow(9, i)) + 1
ans = min(ans, ret)
pow6 = get_pow(remain, 6)
for i in reversed(list(range(1, pow6 + 1))):
ret = get_ans(remain - pow(6, i)) + 1
ans = min(ans, ret)
dic[remain] = ans
return ans
n = int(input().rstrip())
print((get_ans(n)))
| false | 17.948718 | [
"-# coding:utf-8",
"-n = int(input().rstrip())",
"-dic = [None for i in range(n + 1)]",
"-",
"-",
"-def get_ans(amount: int):",
"- if dic[amount] is not None:",
"- return dic[amount]",
"- if amount <= 0:",
"- return 0",
"- ans = amount",
"- for i in reversed(list(range(6))):",
"- num = pow(9, i)",
"- if num > amount:",
"- continue",
"- ret = get_ans(amount - num) + 1",
"- ans = min(ans, ret)",
"- for i in reversed(list(range(7))):",
"- num = pow(6, i)",
"- if num > amount:",
"- continue",
"- ret = get_ans(amount - num) + 1",
"- ans = min(ans, ret)",
"- dic[amount] = ans",
"+# coding: utf-8",
"+def get_pow(target: int, base: int):",
"+ ans = 0",
"+ current = base",
"+ for i in range(1, target + 1):",
"+ if current > target:",
"+ break",
"+ ans = i",
"+ current *= base",
"+dic = {}",
"+",
"+",
"+def get_ans(remain: int):",
"+ if remain in dic:",
"+ return dic[remain]",
"+ if remain < 6:",
"+ return max(0, remain)",
"+ ans = remain",
"+ pos9 = get_pow(remain, 9)",
"+ for i in reversed(list(range(1, pos9 + 1))):",
"+ ret = get_ans(remain - pow(9, i)) + 1",
"+ ans = min(ans, ret)",
"+ pow6 = get_pow(remain, 6)",
"+ for i in reversed(list(range(1, pow6 + 1))):",
"+ ret = get_ans(remain - pow(6, i)) + 1",
"+ ans = min(ans, ret)",
"+ dic[remain] = ans",
"+ return ans",
"+",
"+",
"+n = int(input().rstrip())"
]
| false | 0.149582 | 0.068722 | 2.176633 | [
"s868915125",
"s453213328"
]
|
u698919163 | p02959 | python | s270773010 | s622314067 | 245 | 110 | 19,004 | 97,280 | Accepted | Accepted | 55.1 | N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
start = [0]*(N+1)
attack = 0
enemy = 0
for i in range(N+1):
start[i] = A[i]
for i in range(N):
attack = min(A[i],B[i])
A[i] = A[i] - attack
B[i] = B[i] - attack
attack = min(A[i+1],B[i])
A[i+1] = A[i+1] - attack
B[i] = B[i] - attack
for i in range(N+1):
enemy = enemy + (start[i]-A[i])
print(enemy) | N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(N):
tmp = 0
if A[i] >= B[i]:
A[i] -= B[i]
ans += B[i]
else:
ans += A[i]
tmp = B[i] - A[i]
A[i] = 0
if A[i+1] >= tmp:
A[i+1] -= tmp
ans += tmp
else:
ans += A[i+1]
A[i+1] = 0
print(ans) | 22 | 23 | 450 | 451 | N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
start = [0] * (N + 1)
attack = 0
enemy = 0
for i in range(N + 1):
start[i] = A[i]
for i in range(N):
attack = min(A[i], B[i])
A[i] = A[i] - attack
B[i] = B[i] - attack
attack = min(A[i + 1], B[i])
A[i + 1] = A[i + 1] - attack
B[i] = B[i] - attack
for i in range(N + 1):
enemy = enemy + (start[i] - A[i])
print(enemy)
| N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
tmp = 0
if A[i] >= B[i]:
A[i] -= B[i]
ans += B[i]
else:
ans += A[i]
tmp = B[i] - A[i]
A[i] = 0
if A[i + 1] >= tmp:
A[i + 1] -= tmp
ans += tmp
else:
ans += A[i + 1]
A[i + 1] = 0
print(ans)
| false | 4.347826 | [
"-start = [0] * (N + 1)",
"-attack = 0",
"-enemy = 0",
"-for i in range(N + 1):",
"- start[i] = A[i]",
"+ans = 0",
"- attack = min(A[i], B[i])",
"- A[i] = A[i] - attack",
"- B[i] = B[i] - attack",
"- attack = min(A[i + 1], B[i])",
"- A[i + 1] = A[i + 1] - attack",
"- B[i] = B[i] - attack",
"-for i in range(N + 1):",
"- enemy = enemy + (start[i] - A[i])",
"-print(enemy)",
"+ tmp = 0",
"+ if A[i] >= B[i]:",
"+ A[i] -= B[i]",
"+ ans += B[i]",
"+ else:",
"+ ans += A[i]",
"+ tmp = B[i] - A[i]",
"+ A[i] = 0",
"+ if A[i + 1] >= tmp:",
"+ A[i + 1] -= tmp",
"+ ans += tmp",
"+ else:",
"+ ans += A[i + 1]",
"+ A[i + 1] = 0",
"+print(ans)"
]
| false | 0.048443 | 0.047153 | 1.027364 | [
"s270773010",
"s622314067"
]
|
u327466606 | p03334 | python | s693386159 | s723521343 | 928 | 591 | 19,284 | 21,424 | Accepted | Accepted | 36.31 | from math import sqrt
from itertools import product
import numpy as np
def helper(N,D):
if D%2 == 1:
grid = np.zeros((N,N),dtype=bool)
grid[::2,:] = True
grid[:,1::2] = ~grid[:,1::2]
elif D%4 == 2:
grid = np.zeros((N,N),dtype=bool)
grid[::2,:] = True
else:
M = (N-1)//2+1
D //= 4
g = helper(M, D)
grid = np.zeros((2*M,2*M),dtype=bool)
grid[::2,::2] = g
grid[1::2,::2] = g
grid[::2,1::2] = g
grid[1::2,1::2] = g
grid = grid[:N,:N]
return grid
N,D1,D2 = list(map(int,input().split()))
M = N*2
g1 = helper(N*2,D1)
g2 = helper(N*2,D2)
ans = g1&g2
for x,y in np.transpose(np.nonzero(ans))[:N*N]:
print((x,y))
| from math import sqrt
from itertools import product
import numpy as np
def judge(D):
n = 1
while D%4==0:
n *= 2
D //= 4
def h1(x,y):
return ~(x//n+y//n)%2
def h2(x,y):
return ~(x//n)%2
return h1 if D%2==1 else h2
N,D1,D2 = list(map(int,input().split()))
j1,j2 = judge(D1),judge(D2)
cnt = 0
for x,y in product(list(range(N*2)),repeat=2):
if j1(x,y) and j2(x,y):
print((x,y))
cnt += 1
if cnt >= N*N:
break
| 35 | 27 | 702 | 467 | from math import sqrt
from itertools import product
import numpy as np
def helper(N, D):
if D % 2 == 1:
grid = np.zeros((N, N), dtype=bool)
grid[::2, :] = True
grid[:, 1::2] = ~grid[:, 1::2]
elif D % 4 == 2:
grid = np.zeros((N, N), dtype=bool)
grid[::2, :] = True
else:
M = (N - 1) // 2 + 1
D //= 4
g = helper(M, D)
grid = np.zeros((2 * M, 2 * M), dtype=bool)
grid[::2, ::2] = g
grid[1::2, ::2] = g
grid[::2, 1::2] = g
grid[1::2, 1::2] = g
grid = grid[:N, :N]
return grid
N, D1, D2 = list(map(int, input().split()))
M = N * 2
g1 = helper(N * 2, D1)
g2 = helper(N * 2, D2)
ans = g1 & g2
for x, y in np.transpose(np.nonzero(ans))[: N * N]:
print((x, y))
| from math import sqrt
from itertools import product
import numpy as np
def judge(D):
n = 1
while D % 4 == 0:
n *= 2
D //= 4
def h1(x, y):
return ~(x // n + y // n) % 2
def h2(x, y):
return ~(x // n) % 2
return h1 if D % 2 == 1 else h2
N, D1, D2 = list(map(int, input().split()))
j1, j2 = judge(D1), judge(D2)
cnt = 0
for x, y in product(list(range(N * 2)), repeat=2):
if j1(x, y) and j2(x, y):
print((x, y))
cnt += 1
if cnt >= N * N:
break
| false | 22.857143 | [
"-def helper(N, D):",
"- if D % 2 == 1:",
"- grid = np.zeros((N, N), dtype=bool)",
"- grid[::2, :] = True",
"- grid[:, 1::2] = ~grid[:, 1::2]",
"- elif D % 4 == 2:",
"- grid = np.zeros((N, N), dtype=bool)",
"- grid[::2, :] = True",
"- else:",
"- M = (N - 1) // 2 + 1",
"+def judge(D):",
"+ n = 1",
"+ while D % 4 == 0:",
"+ n *= 2",
"- g = helper(M, D)",
"- grid = np.zeros((2 * M, 2 * M), dtype=bool)",
"- grid[::2, ::2] = g",
"- grid[1::2, ::2] = g",
"- grid[::2, 1::2] = g",
"- grid[1::2, 1::2] = g",
"- grid = grid[:N, :N]",
"- return grid",
"+",
"+ def h1(x, y):",
"+ return ~(x // n + y // n) % 2",
"+",
"+ def h2(x, y):",
"+ return ~(x // n) % 2",
"+",
"+ return h1 if D % 2 == 1 else h2",
"-M = N * 2",
"-g1 = helper(N * 2, D1)",
"-g2 = helper(N * 2, D2)",
"-ans = g1 & g2",
"-for x, y in np.transpose(np.nonzero(ans))[: N * N]:",
"- print((x, y))",
"+j1, j2 = judge(D1), judge(D2)",
"+cnt = 0",
"+for x, y in product(list(range(N * 2)), repeat=2):",
"+ if j1(x, y) and j2(x, y):",
"+ print((x, y))",
"+ cnt += 1",
"+ if cnt >= N * N:",
"+ break"
]
| false | 0.302797 | 0.03839 | 7.8873 | [
"s693386159",
"s723521343"
]
|
u569960318 | p02417 | python | s758849235 | s228781169 | 30 | 20 | 7,532 | 7,400 | Accepted | Accepted | 33.33 | import sys
cnts = {}
for line in sys.stdin:
alpha_line = [x.lower() for x in list([c for c in list(line) if c.isalpha()])]
for c in alpha_line:
cnts[c] = cnts.get(c,0) + 1
for c in range(ord('a'),ord('z')+1): print((chr(c),':',cnts.get(chr(c),0))) | import sys
cnts = {}
for line in sys.stdin:
for c in list(line.lower()): cnts[c] = cnts.get(c,0) + 1
for c in range(ord('a'),ord('z')+1): print((chr(c),':',cnts.get(chr(c),0))) | 8 | 6 | 274 | 185 | import sys
cnts = {}
for line in sys.stdin:
alpha_line = [x.lower() for x in list([c for c in list(line) if c.isalpha()])]
for c in alpha_line:
cnts[c] = cnts.get(c, 0) + 1
for c in range(ord("a"), ord("z") + 1):
print((chr(c), ":", cnts.get(chr(c), 0)))
| import sys
cnts = {}
for line in sys.stdin:
for c in list(line.lower()):
cnts[c] = cnts.get(c, 0) + 1
for c in range(ord("a"), ord("z") + 1):
print((chr(c), ":", cnts.get(chr(c), 0)))
| false | 25 | [
"- alpha_line = [x.lower() for x in list([c for c in list(line) if c.isalpha()])]",
"- for c in alpha_line:",
"+ for c in list(line.lower()):"
]
| false | 0.049729 | 0.050602 | 0.982747 | [
"s758849235",
"s228781169"
]
|
u218843509 | p02633 | python | s426589294 | s817661596 | 73 | 26 | 61,680 | 9,096 | Accepted | Accepted | 64.38 | from math import gcd
print((360 //gcd(360, int(eval(input())))))
| import math
print((360//math.gcd(360,int(eval(input()))))) | 2 | 2 | 58 | 51 | from math import gcd
print((360 // gcd(360, int(eval(input())))))
| import math
print((360 // math.gcd(360, int(eval(input())))))
| false | 0 | [
"-from math import gcd",
"+import math",
"-print((360 // gcd(360, int(eval(input())))))",
"+print((360 // math.gcd(360, int(eval(input())))))"
]
| false | 0.077732 | 0.096462 | 0.805836 | [
"s426589294",
"s817661596"
]
|
u606045429 | p03937 | python | s626275338 | s293292172 | 27 | 17 | 3,064 | 2,940 | Accepted | Accepted | 37.04 | H, W = [int(i) for i in input().split()]
A = [list(eval(input())) for _ in range(H)]
def dfs(h, w, count):
if (h, w) == (H - 1, W - 1):
return count
ans = 0
for nh, nw in [(h + 1, w), (h, w + 1)]:
if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == "#":
ans += dfs(nh, nw, count + 1)
return ans
if dfs(0, 0, 1) == sum(a.count("#") for a in A):
print("Possible")
else:
print("Impossible")
| H, W = [int(i) for i in input().split()]
A = [list(eval(input())) for _ in range(H)]
if H + W - 1 == sum(a.count("#") for a in A):
print("Possible")
else:
print("Impossible")
| 17 | 7 | 449 | 184 | H, W = [int(i) for i in input().split()]
A = [list(eval(input())) for _ in range(H)]
def dfs(h, w, count):
if (h, w) == (H - 1, W - 1):
return count
ans = 0
for nh, nw in [(h + 1, w), (h, w + 1)]:
if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == "#":
ans += dfs(nh, nw, count + 1)
return ans
if dfs(0, 0, 1) == sum(a.count("#") for a in A):
print("Possible")
else:
print("Impossible")
| H, W = [int(i) for i in input().split()]
A = [list(eval(input())) for _ in range(H)]
if H + W - 1 == sum(a.count("#") for a in A):
print("Possible")
else:
print("Impossible")
| false | 58.823529 | [
"-",
"-",
"-def dfs(h, w, count):",
"- if (h, w) == (H - 1, W - 1):",
"- return count",
"- ans = 0",
"- for nh, nw in [(h + 1, w), (h, w + 1)]:",
"- if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == \"#\":",
"- ans += dfs(nh, nw, count + 1)",
"- return ans",
"-",
"-",
"-if dfs(0, 0, 1) == sum(a.count(\"#\") for a in A):",
"+if H + W - 1 == sum(a.count(\"#\") for a in A):"
]
| false | 0.046591 | 0.044141 | 1.055504 | [
"s626275338",
"s293292172"
]
|
u546285759 | p00007 | python | s364550872 | s138523455 | 30 | 20 | 7,536 | 7,708 | Accepted | Accepted | 33.33 | from math import ceil
debt = 100000
n = int(eval(input()))
for _ in range(n):
tmp = ceil(debt*1.05)
debt = ceil((tmp/1000))*1000
print(debt) | import math
debt = 100000
n = int(eval(input()))
for i in range(n):
interest = 0.05 * debt
debt += (math.ceil(interest / 1000) * 1000)
print(debt) | 7 | 7 | 148 | 154 | from math import ceil
debt = 100000
n = int(eval(input()))
for _ in range(n):
tmp = ceil(debt * 1.05)
debt = ceil((tmp / 1000)) * 1000
print(debt)
| import math
debt = 100000
n = int(eval(input()))
for i in range(n):
interest = 0.05 * debt
debt += math.ceil(interest / 1000) * 1000
print(debt)
| false | 0 | [
"-from math import ceil",
"+import math",
"-for _ in range(n):",
"- tmp = ceil(debt * 1.05)",
"- debt = ceil((tmp / 1000)) * 1000",
"+for i in range(n):",
"+ interest = 0.05 * debt",
"+ debt += math.ceil(interest / 1000) * 1000"
]
| false | 0.054467 | 0.059939 | 0.908702 | [
"s364550872",
"s138523455"
]
|
u673361376 | p03418 | python | s685043281 | s397817212 | 186 | 102 | 39,152 | 3,060 | Accepted | Accepted | 45.16 | N,K = list(map(int,input().split()))
if K == 0:
print((N**2))
exit()
ans = 0
for b in range(1,N+1):
if b <= K: continue
else: ans += N//b*(b-K) + max(0,(N-(N//b)*b)-K+1)
print(ans) | N, K = list(map(int, input().split()))
if K == 0:
print((N ** 2))
exit()
ans = 0
for b in range(K + 1, N + 1):
val1 = N // b * (b - K)
if N % b == 0:
val2 = 0
else:
val2 = max(0, N - (N // b) * b - K + 1)
ans += val1 + val2
print(ans)
| 12 | 15 | 194 | 283 | N, K = list(map(int, input().split()))
if K == 0:
print((N**2))
exit()
ans = 0
for b in range(1, N + 1):
if b <= K:
continue
else:
ans += N // b * (b - K) + max(0, (N - (N // b) * b) - K + 1)
print(ans)
| N, K = list(map(int, input().split()))
if K == 0:
print((N**2))
exit()
ans = 0
for b in range(K + 1, N + 1):
val1 = N // b * (b - K)
if N % b == 0:
val2 = 0
else:
val2 = max(0, N - (N // b) * b - K + 1)
ans += val1 + val2
print(ans)
| false | 20 | [
"-for b in range(1, N + 1):",
"- if b <= K:",
"- continue",
"+for b in range(K + 1, N + 1):",
"+ val1 = N // b * (b - K)",
"+ if N % b == 0:",
"+ val2 = 0",
"- ans += N // b * (b - K) + max(0, (N - (N // b) * b) - K + 1)",
"+ val2 = max(0, N - (N // b) * b - K + 1)",
"+ ans += val1 + val2"
]
| false | 0.040172 | 0.054727 | 0.734037 | [
"s685043281",
"s397817212"
]
|
u692453235 | p02813 | python | s680508476 | s388563852 | 50 | 37 | 8,052 | 8,052 | Accepted | Accepted | 26 | import itertools
N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
L = [i for i in range(1, N+1)]
a = 0
b = 0
#順列作成
L_list = list(itertools.permutations(L))
for i in range(len(L_list)):
if list(L_list[i]) == P:
a = i+1
if list(L_list[i]) == Q:
b = i+1
print((abs(a-b))) | #パクリ
import itertools
N = int(eval(input()))
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
lis=list(itertools.permutations(P))
lis.sort()
#indexで要素の何番目か取得
print((abs(lis.index(P)-lis.index(Q))))
| 20 | 12 | 340 | 227 | import itertools
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
L = [i for i in range(1, N + 1)]
a = 0
b = 0
# 順列作成
L_list = list(itertools.permutations(L))
for i in range(len(L_list)):
if list(L_list[i]) == P:
a = i + 1
if list(L_list[i]) == Q:
b = i + 1
print((abs(a - b)))
| # パクリ
import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
lis = list(itertools.permutations(P))
lis.sort()
# indexで要素の何番目か取得
print((abs(lis.index(P) - lis.index(Q))))
| false | 40 | [
"+# パクリ",
"-P = list(map(int, input().split()))",
"-Q = list(map(int, input().split()))",
"-L = [i for i in range(1, N + 1)]",
"-a = 0",
"-b = 0",
"-# 順列作成",
"-L_list = list(itertools.permutations(L))",
"-for i in range(len(L_list)):",
"- if list(L_list[i]) == P:",
"- a = i + 1",
"- if list(L_list[i]) == Q:",
"- b = i + 1",
"-print((abs(a - b)))",
"+P = tuple(map(int, input().split()))",
"+Q = tuple(map(int, input().split()))",
"+lis = list(itertools.permutations(P))",
"+lis.sort()",
"+# indexで要素の何番目か取得",
"+print((abs(lis.index(P) - lis.index(Q))))"
]
| false | 0.100188 | 0.041019 | 2.442486 | [
"s680508476",
"s388563852"
]
|
u046187684 | p02982 | python | s592823508 | s569584163 | 196 | 171 | 38,384 | 38,384 | Accepted | Accepted | 12.76 | import math
from itertools import combinations
N,D = list(map(int,input().split()))
X = [list(map(float, input().split())) for i in range(N)]
counter = 0
for x0,x1 in combinations(X, 2):
if math.sqrt(sum([(a-b)**2 for a, b in zip(x0,x1)])).is_integer():
counter+=1
print(counter)
| import math
from itertools import combinations
N,D = list(map(int,input().split()))
X = [list(map(float, input().split())) for i in range(N)]
counter = [(sum([(a-b)**2 for a, b in zip(x0,x1)])**0.5).is_integer() for x0,x1 in combinations(X, 2)]
print((sum(counter)))
| 9 | 6 | 294 | 264 | import math
from itertools import combinations
N, D = list(map(int, input().split()))
X = [list(map(float, input().split())) for i in range(N)]
counter = 0
for x0, x1 in combinations(X, 2):
if math.sqrt(sum([(a - b) ** 2 for a, b in zip(x0, x1)])).is_integer():
counter += 1
print(counter)
| import math
from itertools import combinations
N, D = list(map(int, input().split()))
X = [list(map(float, input().split())) for i in range(N)]
counter = [
(sum([(a - b) ** 2 for a, b in zip(x0, x1)]) ** 0.5).is_integer()
for x0, x1 in combinations(X, 2)
]
print((sum(counter)))
| false | 33.333333 | [
"-counter = 0",
"-for x0, x1 in combinations(X, 2):",
"- if math.sqrt(sum([(a - b) ** 2 for a, b in zip(x0, x1)])).is_integer():",
"- counter += 1",
"-print(counter)",
"+counter = [",
"+ (sum([(a - b) ** 2 for a, b in zip(x0, x1)]) ** 0.5).is_integer()",
"+ for x0, x1 in combinations(X, 2)",
"+]",
"+print((sum(counter)))"
]
| false | 0.037708 | 0.037516 | 1.005108 | [
"s592823508",
"s569584163"
]
|
u816488327 | p02863 | python | s448802687 | s021416498 | 1,970 | 310 | 357,500 | 83,176 | Accepted | Accepted | 84.26 | def solve():
from sys import stdin
f_i = stdin
N, T = list(map(int, f_i.readline().split()))
AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
AB.sort()
dp = [[0] * T for i in range(N + 1)]
for i, AB_i in enumerate(AB, start=1):
A_i, B_i = AB_i
dp_i = dp[i]
dp_pre = dp[i-1]
dp_i[:A_i] = dp_pre[:A_i]
for j, t in enumerate(zip(dp_pre[A_i:], dp_pre), start=A_i):
x, y = t
if x < y + B_i:
dp_i[j] = y + B_i
else:
dp_i[j] = x
ans = max(dp[k][-1] + AB[k][1] for k in range(N))
print(ans)
solve() | def solve():
import numpy as np
from sys import stdin
f_i = stdin
N, T = list(map(int, f_i.readline().split()))
AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
AB.sort()
max_Ai = AB[-1][0]
dp = [[0] * T for i in range(N + 1)]
dp = np.zeros(max_Ai + T, dtype=int)
for A_i, B_i in AB:
dp[A_i:A_i+T] = np.maximum(dp[A_i:A_i+T], dp[:T] + B_i)
print((max(dp)))
solve() | 26 | 20 | 690 | 469 | def solve():
from sys import stdin
f_i = stdin
N, T = list(map(int, f_i.readline().split()))
AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
AB.sort()
dp = [[0] * T for i in range(N + 1)]
for i, AB_i in enumerate(AB, start=1):
A_i, B_i = AB_i
dp_i = dp[i]
dp_pre = dp[i - 1]
dp_i[:A_i] = dp_pre[:A_i]
for j, t in enumerate(zip(dp_pre[A_i:], dp_pre), start=A_i):
x, y = t
if x < y + B_i:
dp_i[j] = y + B_i
else:
dp_i[j] = x
ans = max(dp[k][-1] + AB[k][1] for k in range(N))
print(ans)
solve()
| def solve():
import numpy as np
from sys import stdin
f_i = stdin
N, T = list(map(int, f_i.readline().split()))
AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
AB.sort()
max_Ai = AB[-1][0]
dp = [[0] * T for i in range(N + 1)]
dp = np.zeros(max_Ai + T, dtype=int)
for A_i, B_i in AB:
dp[A_i : A_i + T] = np.maximum(dp[A_i : A_i + T], dp[:T] + B_i)
print((max(dp)))
solve()
| false | 23.076923 | [
"+ import numpy as np",
"+ max_Ai = AB[-1][0]",
"- for i, AB_i in enumerate(AB, start=1):",
"- A_i, B_i = AB_i",
"- dp_i = dp[i]",
"- dp_pre = dp[i - 1]",
"- dp_i[:A_i] = dp_pre[:A_i]",
"- for j, t in enumerate(zip(dp_pre[A_i:], dp_pre), start=A_i):",
"- x, y = t",
"- if x < y + B_i:",
"- dp_i[j] = y + B_i",
"- else:",
"- dp_i[j] = x",
"- ans = max(dp[k][-1] + AB[k][1] for k in range(N))",
"- print(ans)",
"+ dp = np.zeros(max_Ai + T, dtype=int)",
"+ for A_i, B_i in AB:",
"+ dp[A_i : A_i + T] = np.maximum(dp[A_i : A_i + T], dp[:T] + B_i)",
"+ print((max(dp)))"
]
| false | 0.076634 | 0.232885 | 0.329063 | [
"s448802687",
"s021416498"
]
|
u531436689 | p03815 | python | s405877318 | s565850402 | 63 | 41 | 6,224 | 5,460 | Accepted | Accepted | 34.92 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return eval(input())
def solve(x):
rot = x // (6 + 5)
res = x % (6 + 5)
ans = 2 * rot
# rot:evenなら、つぎに当たるのは6
if res > 0 and rot % 2 == 0:
if res <= 6:
ans += 1
else:
ans += 2
elif res > 0 and rot % 2 == 1:
if res <= 5:
ans += 1
else:
ans += 2
else:
pass
return ans
def main():
x = I()
ans = solve(x)
print(ans)
# print()
# for i in range(1, 30):
# print(i, solve(i))
main()
| import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return eval(input())
def solve(x):
rot = x // (6 + 5)
res = x % (6 + 5)
ans = 2 * rot
# rot:evenなら、つぎに当たるのは6
if 0 < res <= 6:
ans += 1
if 6 < res:
ans += 2
return ans
def main():
x = I()
ans = solve(x)
print(ans)
main()
| 47 | 36 | 1,137 | 880 | import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def I():
return int(sys.stdin.readline())
def F():
return float(sys.stdin.readline())
def S():
return eval(input())
def solve(x):
rot = x // (6 + 5)
res = x % (6 + 5)
ans = 2 * rot
# rot:evenなら、つぎに当たるのは6
if res > 0 and rot % 2 == 0:
if res <= 6:
ans += 1
else:
ans += 2
elif res > 0 and rot % 2 == 1:
if res <= 5:
ans += 1
else:
ans += 2
else:
pass
return ans
def main():
x = I()
ans = solve(x)
print(ans)
# print()
# for i in range(1, 30):
# print(i, solve(i))
main()
| import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def I():
return int(sys.stdin.readline())
def F():
return float(sys.stdin.readline())
def S():
return eval(input())
def solve(x):
rot = x // (6 + 5)
res = x % (6 + 5)
ans = 2 * rot
# rot:evenなら、つぎに当たるのは6
if 0 < res <= 6:
ans += 1
if 6 < res:
ans += 2
return ans
def main():
x = I()
ans = solve(x)
print(ans)
main()
| false | 23.404255 | [
"- if res > 0 and rot % 2 == 0:",
"- if res <= 6:",
"- ans += 1",
"- else:",
"- ans += 2",
"- elif res > 0 and rot % 2 == 1:",
"- if res <= 5:",
"- ans += 1",
"- else:",
"- ans += 2",
"- else:",
"- pass",
"+ if 0 < res <= 6:",
"+ ans += 1",
"+ if 6 < res:",
"+ ans += 2",
"- # print()",
"- # for i in range(1, 30):",
"- # print(i, solve(i))"
]
| false | 0.036688 | 0.068376 | 0.536567 | [
"s405877318",
"s565850402"
]
|
u847467233 | p00616 | python | s640250379 | s874795469 | 170 | 130 | 10,276 | 10,136 | Accepted | Accepted | 23.53 | # AOJ 1030 Cubes Without Holes
# Python3 2018.7.6 bal4u
import sys
from sys import stdin
input = stdin.readline
# n <= 500, 2^9 = 512
while True:
n, h = list(map(int, input().split()))
if n == 0: break
ans = []
for i in range(h):
c, a, b = input().split()
a, b = int(a)-1, int(b)-1
if c == "xy":
ans += [a+(b<<9)+(z<<18) for z in range(n)]
elif c == "xz":
ans += [a+(y<<9)+(b<<18) for y in range(n)]
else:
ans += [x+(a<<9)+(b<<18) for x in range(n)]
print((n**3-len(set(ans))))
| # AOJ 1030 Cubes Without Holes
# Python3 2018.7.6 bal4u
import sys
from sys import stdin
input = stdin.readline
# n <= 500, 2^9 = 512
while True:
n, h = list(map(int, input().split()))
if n == 0: break
ans = []
for i in range(h):
s = eval(input())
c = s[:2]
a, b = s[3:].split()
a, b = int(a)-1, int(b)-1
if c == "xy":
k = a+(b<<9)
ans += [k+(z<<18) for z in range(n)]
elif c == "xz":
k = a+(b<<18)
ans += [k+(y<<9) for y in range(n)]
else:
k = (a<<9)+(b<<18)
ans += [k+x for x in range(n)]
print((n**3-len(set(ans))))
| 22 | 27 | 518 | 571 | # AOJ 1030 Cubes Without Holes
# Python3 2018.7.6 bal4u
import sys
from sys import stdin
input = stdin.readline
# n <= 500, 2^9 = 512
while True:
n, h = list(map(int, input().split()))
if n == 0:
break
ans = []
for i in range(h):
c, a, b = input().split()
a, b = int(a) - 1, int(b) - 1
if c == "xy":
ans += [a + (b << 9) + (z << 18) for z in range(n)]
elif c == "xz":
ans += [a + (y << 9) + (b << 18) for y in range(n)]
else:
ans += [x + (a << 9) + (b << 18) for x in range(n)]
print((n**3 - len(set(ans))))
| # AOJ 1030 Cubes Without Holes
# Python3 2018.7.6 bal4u
import sys
from sys import stdin
input = stdin.readline
# n <= 500, 2^9 = 512
while True:
n, h = list(map(int, input().split()))
if n == 0:
break
ans = []
for i in range(h):
s = eval(input())
c = s[:2]
a, b = s[3:].split()
a, b = int(a) - 1, int(b) - 1
if c == "xy":
k = a + (b << 9)
ans += [k + (z << 18) for z in range(n)]
elif c == "xz":
k = a + (b << 18)
ans += [k + (y << 9) for y in range(n)]
else:
k = (a << 9) + (b << 18)
ans += [k + x for x in range(n)]
print((n**3 - len(set(ans))))
| false | 18.518519 | [
"- c, a, b = input().split()",
"+ s = eval(input())",
"+ c = s[:2]",
"+ a, b = s[3:].split()",
"- ans += [a + (b << 9) + (z << 18) for z in range(n)]",
"+ k = a + (b << 9)",
"+ ans += [k + (z << 18) for z in range(n)]",
"- ans += [a + (y << 9) + (b << 18) for y in range(n)]",
"+ k = a + (b << 18)",
"+ ans += [k + (y << 9) for y in range(n)]",
"- ans += [x + (a << 9) + (b << 18) for x in range(n)]",
"+ k = (a << 9) + (b << 18)",
"+ ans += [k + x for x in range(n)]"
]
| false | 0.045048 | 0.04186 | 1.076175 | [
"s640250379",
"s874795469"
]
|
u353919145 | p02789 | python | s051660675 | s735349100 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | r = input ().split ()
print(("Yes" if r[0] == r[1] else "No")) | l = list(input().split())
N = int(l[0])
M = int(l[1])
if (N == M) :
print ("Yes")
else :
print ("No") | 2 | 7 | 62 | 115 | r = input().split()
print(("Yes" if r[0] == r[1] else "No"))
| l = list(input().split())
N = int(l[0])
M = int(l[1])
if N == M:
print("Yes")
else:
print("No")
| false | 71.428571 | [
"-r = input().split()",
"-print((\"Yes\" if r[0] == r[1] else \"No\"))",
"+l = list(input().split())",
"+N = int(l[0])",
"+M = int(l[1])",
"+if N == M:",
"+ print(\"Yes\")",
"+else:",
"+ print(\"No\")"
]
| false | 0.041843 | 0.044262 | 0.945344 | [
"s051660675",
"s735349100"
]
|
u605879293 | p02389 | python | s602110536 | s296171528 | 30 | 20 | 7,580 | 7,644 | Accepted | Accepted | 33.33 | x = eval(input())
a, b = tuple(x.split())
a = int(a)
b = int(b)
print((a * b, 2 * a + 2 * b)) | x, y = input().split()
x, y = int(x), int(y)
print((x * y, 2 * (x + y))) | 5 | 3 | 89 | 72 | x = eval(input())
a, b = tuple(x.split())
a = int(a)
b = int(b)
print((a * b, 2 * a + 2 * b))
| x, y = input().split()
x, y = int(x), int(y)
print((x * y, 2 * (x + y)))
| false | 40 | [
"-x = eval(input())",
"-a, b = tuple(x.split())",
"-a = int(a)",
"-b = int(b)",
"-print((a * b, 2 * a + 2 * b))",
"+x, y = input().split()",
"+x, y = int(x), int(y)",
"+print((x * y, 2 * (x + y)))"
]
| false | 0.03628 | 0.045174 | 0.803105 | [
"s602110536",
"s296171528"
]
|
u830054172 | p03722 | python | s512657373 | s058120719 | 1,704 | 1,041 | 3,440 | 3,444 | Accepted | Accepted | 38.91 | #負の経路の検出
def find_negative_loop(n, es, d):
#始点はどこでもよい
check = [0 for _ in range(n)]
for _ in range(n):
for p, q, r in es:
#e: 辺iについて
if d[p] != float("inf") and d[q] > d[p] + r:
d[q] = d[p] + r
check[q] = True
if check[p]:
check[q] = True
# if i == n-1:
# return True
return check
def shortest_path(s, n, es):
#s -> i の最短経路
#s: 始点、n: 頂点数、w:辺の数、es[i]: [辺の始点、辺の終点、辺のコスト]
d = [float("inf")] * n
#d[i]: s->iの最短距離
d[s] = 0
for _ in range(n):
update = False
for p, q, r in es:
#e: 辺iについて
if d[p] != float("inf") and d[q] > d[p] + r:
d[q] = d[p] + r
update = True
# print(update)
if not update:
break
return d
n,w = list(map(int,input().split())) #n:頂点数 w:辺の数
es = [] #es[i]: [辺の始点,辺の終点,辺のコスト]
for _ in range(w):
x,y,z = list(map(int,input().split()))
es.append([x-1, y-1, -z])
# es.append([y,x,z])
# print(shortest_path(0, n, es))
# print(es)
# if find_negative_loop(n,es):
d = shortest_path(0, n, es)
# print(d)
c = find_negative_loop(n, es, d)
# print(c)
if c[-1]:
print("inf")
else:
# d = shortest_path(0, n, es)
print((-d[-1])) | n, m = list(map(int, input().split()))
edge = []
for _ in range(m):
a, b, c = list(map(int, input().split()))
edge.append([a-1, b-1, -c])
d = [float("inf") for _ in range(n)]
d[0] = 0
check = [0 for _ in range(n)]
for i in range(n):
for now, next, weight in edge:
if d[next] > d[now] + weight:
d[next] = d[now] + weight
if i == n-1:
check[next] = 1
if i == n-1:
if check[now]:
check[next] = 1
if check[-1]:
print("inf")
else:
print((-d[-1])) | 61 | 26 | 1,378 | 561 | # 負の経路の検出
def find_negative_loop(n, es, d):
# 始点はどこでもよい
check = [0 for _ in range(n)]
for _ in range(n):
for p, q, r in es:
# e: 辺iについて
if d[p] != float("inf") and d[q] > d[p] + r:
d[q] = d[p] + r
check[q] = True
if check[p]:
check[q] = True
# if i == n-1:
# return True
return check
def shortest_path(s, n, es):
# s -> i の最短経路
# s: 始点、n: 頂点数、w:辺の数、es[i]: [辺の始点、辺の終点、辺のコスト]
d = [float("inf")] * n
# d[i]: s->iの最短距離
d[s] = 0
for _ in range(n):
update = False
for p, q, r in es:
# e: 辺iについて
if d[p] != float("inf") and d[q] > d[p] + r:
d[q] = d[p] + r
update = True
# print(update)
if not update:
break
return d
n, w = list(map(int, input().split())) # n:頂点数 w:辺の数
es = [] # es[i]: [辺の始点,辺の終点,辺のコスト]
for _ in range(w):
x, y, z = list(map(int, input().split()))
es.append([x - 1, y - 1, -z])
# es.append([y,x,z])
# print(shortest_path(0, n, es))
# print(es)
# if find_negative_loop(n,es):
d = shortest_path(0, n, es)
# print(d)
c = find_negative_loop(n, es, d)
# print(c)
if c[-1]:
print("inf")
else:
# d = shortest_path(0, n, es)
print((-d[-1]))
| n, m = list(map(int, input().split()))
edge = []
for _ in range(m):
a, b, c = list(map(int, input().split()))
edge.append([a - 1, b - 1, -c])
d = [float("inf") for _ in range(n)]
d[0] = 0
check = [0 for _ in range(n)]
for i in range(n):
for now, next, weight in edge:
if d[next] > d[now] + weight:
d[next] = d[now] + weight
if i == n - 1:
check[next] = 1
if i == n - 1:
if check[now]:
check[next] = 1
if check[-1]:
print("inf")
else:
print((-d[-1]))
| false | 57.377049 | [
"-# 負の経路の検出",
"-def find_negative_loop(n, es, d):",
"- # 始点はどこでもよい",
"- check = [0 for _ in range(n)]",
"- for _ in range(n):",
"- for p, q, r in es:",
"- # e: 辺iについて",
"- if d[p] != float(\"inf\") and d[q] > d[p] + r:",
"- d[q] = d[p] + r",
"- check[q] = True",
"- if check[p]:",
"- check[q] = True",
"- # if i == n-1:",
"- # return True",
"- return check",
"-",
"-",
"-def shortest_path(s, n, es):",
"- # s -> i の最短経路",
"- # s: 始点、n: 頂点数、w:辺の数、es[i]: [辺の始点、辺の終点、辺のコスト]",
"- d = [float(\"inf\")] * n",
"- # d[i]: s->iの最短距離",
"- d[s] = 0",
"- for _ in range(n):",
"- update = False",
"- for p, q, r in es:",
"- # e: 辺iについて",
"- if d[p] != float(\"inf\") and d[q] > d[p] + r:",
"- d[q] = d[p] + r",
"- update = True",
"- # print(update)",
"- if not update:",
"- break",
"- return d",
"-",
"-",
"-n, w = list(map(int, input().split())) # n:頂点数 w:辺の数",
"-es = [] # es[i]: [辺の始点,辺の終点,辺のコスト]",
"-for _ in range(w):",
"- x, y, z = list(map(int, input().split()))",
"- es.append([x - 1, y - 1, -z])",
"- # es.append([y,x,z])",
"-# print(shortest_path(0, n, es))",
"-# print(es)",
"-# if find_negative_loop(n,es):",
"-d = shortest_path(0, n, es)",
"-# print(d)",
"-c = find_negative_loop(n, es, d)",
"-# print(c)",
"-if c[-1]:",
"+n, m = list(map(int, input().split()))",
"+edge = []",
"+for _ in range(m):",
"+ a, b, c = list(map(int, input().split()))",
"+ edge.append([a - 1, b - 1, -c])",
"+d = [float(\"inf\") for _ in range(n)]",
"+d[0] = 0",
"+check = [0 for _ in range(n)]",
"+for i in range(n):",
"+ for now, next, weight in edge:",
"+ if d[next] > d[now] + weight:",
"+ d[next] = d[now] + weight",
"+ if i == n - 1:",
"+ check[next] = 1",
"+ if i == n - 1:",
"+ if check[now]:",
"+ check[next] = 1",
"+if check[-1]:",
"- # d = shortest_path(0, n, es)"
]
| false | 0.072832 | 0.041596 | 1.750935 | [
"s512657373",
"s058120719"
]
|
u841568901 | p03262 | python | s906425514 | s244427932 | 81 | 66 | 20,440 | 20,416 | Accepted | Accepted | 18.52 | import math
N, A = list(map(int, input().split()))
X = list(map(int, input().split()))
L = ([abs(x-A) for x in X])
S = L[0]
for i in range(1, N):
S = math.gcd(S,L[i])
print(S) | import math
from functools import reduce
N, A = list(map(int, input().split()))
X = list(map(int, input().split()))
L = ([abs(x-A) for x in X])
print((reduce(math.gcd, L))) | 8 | 6 | 178 | 169 | import math
N, A = list(map(int, input().split()))
X = list(map(int, input().split()))
L = [abs(x - A) for x in X]
S = L[0]
for i in range(1, N):
S = math.gcd(S, L[i])
print(S)
| import math
from functools import reduce
N, A = list(map(int, input().split()))
X = list(map(int, input().split()))
L = [abs(x - A) for x in X]
print((reduce(math.gcd, L)))
| false | 25 | [
"+from functools import reduce",
"-S = L[0]",
"-for i in range(1, N):",
"- S = math.gcd(S, L[i])",
"-print(S)",
"+print((reduce(math.gcd, L)))"
]
| false | 0.047589 | 0.047698 | 0.997704 | [
"s906425514",
"s244427932"
]
|
u163783894 | p02925 | python | s832371499 | s352835949 | 1,698 | 1,359 | 35,436 | 38,056 | Accepted | Accepted | 19.96 | import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
def solve():
N = int(eval(input()))
A = [[] for _ in range(N)]
for i in range(N):
A[i] = list([int(x) - 1 for x in input().split()])
# print(A)
days = 0
ta = [i for i in range(N)]
while True:
ta2 = []
aset = set()
for i in ta:
if len(A[i]) == 0 or i in aset:
continue
if i == A[A[i][0]][0]:
ta2.append(i)
ta2.append(A[i][0])
aset |= set([i])
aset |= set([A[i][0]])
if len(ta2) > 0:
for t in ta2:
A[t].pop(0)
days += 1
ta = ta2
else:
break
empty = True
for i in range(N):
if len(A[i]) != 0:
empty = False
break
if empty:
print(days)
else:
print((-1))
if __name__ == '__main__':
solve()
| import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
def solve():
N = int(eval(input()))
A = [deque for _ in range(N)]
for i in range(N):
A[i] = deque(list([int(x) - 1 for x in input().split()]))
days = 0
ta = [i for i in range(N)]
while True:
ta2 = []
aset = set()
for i in ta:
if len(A[i]) == 0 or i in aset:
continue
if i == A[A[i][0]][0]:
ta2.append(i)
ta2.append(A[i][0])
aset |= set([i])
aset |= set([A[i][0]])
if len(ta2) > 0:
for t in ta2:
A[t].popleft()
days += 1
ta = ta2
else:
break
empty = True
for i in range(N):
if len(A[i]) != 0:
empty = False
break
if empty:
print(days)
else:
print((-1))
if __name__ == '__main__':
solve()
| 48 | 46 | 1,036 | 1,031 | import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
def solve():
N = int(eval(input()))
A = [[] for _ in range(N)]
for i in range(N):
A[i] = list([int(x) - 1 for x in input().split()])
# print(A)
days = 0
ta = [i for i in range(N)]
while True:
ta2 = []
aset = set()
for i in ta:
if len(A[i]) == 0 or i in aset:
continue
if i == A[A[i][0]][0]:
ta2.append(i)
ta2.append(A[i][0])
aset |= set([i])
aset |= set([A[i][0]])
if len(ta2) > 0:
for t in ta2:
A[t].pop(0)
days += 1
ta = ta2
else:
break
empty = True
for i in range(N):
if len(A[i]) != 0:
empty = False
break
if empty:
print(days)
else:
print((-1))
if __name__ == "__main__":
solve()
| import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
def solve():
N = int(eval(input()))
A = [deque for _ in range(N)]
for i in range(N):
A[i] = deque(list([int(x) - 1 for x in input().split()]))
days = 0
ta = [i for i in range(N)]
while True:
ta2 = []
aset = set()
for i in ta:
if len(A[i]) == 0 or i in aset:
continue
if i == A[A[i][0]][0]:
ta2.append(i)
ta2.append(A[i][0])
aset |= set([i])
aset |= set([A[i][0]])
if len(ta2) > 0:
for t in ta2:
A[t].popleft()
days += 1
ta = ta2
else:
break
empty = True
for i in range(N):
if len(A[i]) != 0:
empty = False
break
if empty:
print(days)
else:
print((-1))
if __name__ == "__main__":
solve()
| false | 4.166667 | [
"- A = [[] for _ in range(N)]",
"+ A = [deque for _ in range(N)]",
"- A[i] = list([int(x) - 1 for x in input().split()])",
"- # print(A)",
"+ A[i] = deque(list([int(x) - 1 for x in input().split()]))",
"- A[t].pop(0)",
"+ A[t].popleft()"
]
| false | 0.048482 | 0.048412 | 1.001446 | [
"s832371499",
"s352835949"
]
|
u698919163 | p02688 | python | s680455089 | s903932752 | 24 | 22 | 9,204 | 9,184 | Accepted | Accepted | 8.33 | N,K = list(map(int,input().split()))
list_A = [0]*N
ans = 0
d = []
A = []
for i in range(K):
d.append(int(eval(input())))
A.append(list(map(int,input().split())))
list_A = [0]*N
for i in range(len(A)):
for j in A[i]:
list_A[j-1] += 1
for i in range(N):
if list_A[i] == 0:
ans += 1
print(ans) | N,K = list(map(int,input().split()))
tmp_A = [0]*N
ans = 0
for i in range(K):
d = int(eval(input()))
A = list(map(int,input().split()))
for j in range(d):
tmp_A[A[j]-1] += 1
for i in range(N):
if tmp_A[i] == 0:
ans += 1
print(ans) | 22 | 15 | 354 | 283 | N, K = list(map(int, input().split()))
list_A = [0] * N
ans = 0
d = []
A = []
for i in range(K):
d.append(int(eval(input())))
A.append(list(map(int, input().split())))
list_A = [0] * N
for i in range(len(A)):
for j in A[i]:
list_A[j - 1] += 1
for i in range(N):
if list_A[i] == 0:
ans += 1
print(ans)
| N, K = list(map(int, input().split()))
tmp_A = [0] * N
ans = 0
for i in range(K):
d = int(eval(input()))
A = list(map(int, input().split()))
for j in range(d):
tmp_A[A[j] - 1] += 1
for i in range(N):
if tmp_A[i] == 0:
ans += 1
print(ans)
| false | 31.818182 | [
"-list_A = [0] * N",
"+tmp_A = [0] * N",
"-d = []",
"-A = []",
"- d.append(int(eval(input())))",
"- A.append(list(map(int, input().split())))",
"-list_A = [0] * N",
"-for i in range(len(A)):",
"- for j in A[i]:",
"- list_A[j - 1] += 1",
"+ d = int(eval(input()))",
"+ A = list(map(int, input().split()))",
"+ for j in range(d):",
"+ tmp_A[A[j] - 1] += 1",
"- if list_A[i] == 0:",
"+ if tmp_A[i] == 0:"
]
| false | 0.03828 | 0.046228 | 0.828064 | [
"s680455089",
"s903932752"
]
|
u210827208 | p03786 | python | s784058828 | s898011850 | 131 | 111 | 14,320 | 14,320 | Accepted | Accepted | 15.27 | n=int(eval(input()))
A=list(map(int,input().split()))
A.sort()
S=[]
s=0
for i in range(n):
s+=A[i]
S.append(s)
ans=1
for i in reversed(list(range(n-1))):
if S[i]*2>=A[i+1]:
ans+=1
else:
break
print(ans) | n=int(eval(input()))
A=list(map(int,input().split()))
A.sort()
ans=1
s=0
for i in range(n):
if 2*s>=A[i]:
ans+=1
else:
ans=1
s+=A[i]
print(ans) | 15 | 12 | 236 | 176 | n = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
S = []
s = 0
for i in range(n):
s += A[i]
S.append(s)
ans = 1
for i in reversed(list(range(n - 1))):
if S[i] * 2 >= A[i + 1]:
ans += 1
else:
break
print(ans)
| n = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
ans = 1
s = 0
for i in range(n):
if 2 * s >= A[i]:
ans += 1
else:
ans = 1
s += A[i]
print(ans)
| false | 20 | [
"-S = []",
"+ans = 1",
"- s += A[i]",
"- S.append(s)",
"-ans = 1",
"-for i in reversed(list(range(n - 1))):",
"- if S[i] * 2 >= A[i + 1]:",
"+ if 2 * s >= A[i]:",
"- break",
"+ ans = 1",
"+ s += A[i]"
]
| false | 0.063897 | 0.048108 | 1.328199 | [
"s784058828",
"s898011850"
]
|
u737758066 | p02859 | python | s269109583 | s700859656 | 195 | 178 | 38,516 | 38,256 | Accepted | Accepted | 8.72 | r = int(eval(input()))
print((r*r))
| r = int(eval(input()))
print((r**2))
| 2 | 2 | 29 | 30 | r = int(eval(input()))
print((r * r))
| r = int(eval(input()))
print((r**2))
| false | 0 | [
"-print((r * r))",
"+print((r**2))"
]
| false | 0.037344 | 0.097921 | 0.381368 | [
"s269109583",
"s700859656"
]
|
u764956288 | p02695 | python | s251439610 | s505659344 | 711 | 606 | 9,204 | 9,200 | Accepted | Accepted | 14.77 | # import numpy as np
# import queue
# import heapq
from itertools import combinations_with_replacement
def main():
N, M, Q = list(map(int, input().split()))
queries = [list(map(int, input().split())) for _ in range(Q)]
As = combinations_with_replacement(list(range(1, M+1)), N)
max_total = 0
for A in As:
total = 0
for i, q in enumerate(queries):
if A[q[1]-1] - A[q[0]-1] == q[2]:
total += q[3]
max_total = max(max_total, total)
print(max_total)
if __name__ == "__main__":
main()
| from itertools import combinations_with_replacement
def main():
n_ints, max_int, n_queries = list(map(int, input().split()))
queries = [list(map(int, input().split())) for _ in range(n_queries)]
possible_sequences = combinations_with_replacement(list(range(1, max_int+1)), n_ints)
max_score = 0
for sequence in possible_sequences:
score = 0
for i, q in enumerate(queries):
a, b, c, d = q
if sequence[b-1] - sequence[a-1] == c:
score += d
max_score = max(max_score, score)
print(max_score)
if __name__ == "__main__":
main()
| 28 | 26 | 585 | 638 | # import numpy as np
# import queue
# import heapq
from itertools import combinations_with_replacement
def main():
N, M, Q = list(map(int, input().split()))
queries = [list(map(int, input().split())) for _ in range(Q)]
As = combinations_with_replacement(list(range(1, M + 1)), N)
max_total = 0
for A in As:
total = 0
for i, q in enumerate(queries):
if A[q[1] - 1] - A[q[0] - 1] == q[2]:
total += q[3]
max_total = max(max_total, total)
print(max_total)
if __name__ == "__main__":
main()
| from itertools import combinations_with_replacement
def main():
n_ints, max_int, n_queries = list(map(int, input().split()))
queries = [list(map(int, input().split())) for _ in range(n_queries)]
possible_sequences = combinations_with_replacement(
list(range(1, max_int + 1)), n_ints
)
max_score = 0
for sequence in possible_sequences:
score = 0
for i, q in enumerate(queries):
a, b, c, d = q
if sequence[b - 1] - sequence[a - 1] == c:
score += d
max_score = max(max_score, score)
print(max_score)
if __name__ == "__main__":
main()
| false | 7.142857 | [
"-# import numpy as np",
"-# import queue",
"-# import heapq",
"- N, M, Q = list(map(int, input().split()))",
"- queries = [list(map(int, input().split())) for _ in range(Q)]",
"- As = combinations_with_replacement(list(range(1, M + 1)), N)",
"- max_total = 0",
"- for A in As:",
"- total = 0",
"+ n_ints, max_int, n_queries = list(map(int, input().split()))",
"+ queries = [list(map(int, input().split())) for _ in range(n_queries)]",
"+ possible_sequences = combinations_with_replacement(",
"+ list(range(1, max_int + 1)), n_ints",
"+ )",
"+ max_score = 0",
"+ for sequence in possible_sequences:",
"+ score = 0",
"- if A[q[1] - 1] - A[q[0] - 1] == q[2]:",
"- total += q[3]",
"- max_total = max(max_total, total)",
"- print(max_total)",
"+ a, b, c, d = q",
"+ if sequence[b - 1] - sequence[a - 1] == c:",
"+ score += d",
"+ max_score = max(max_score, score)",
"+ print(max_score)"
]
| false | 0.050582 | 0.049974 | 1.012182 | [
"s251439610",
"s505659344"
]
|
u991567869 | p03495 | python | s745737705 | s549217825 | 200 | 110 | 39,348 | 35,996 | Accepted | Accepted | 45 | from collections import Counter
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
d = Counter(a)
d = d.most_common()
ans = 0
for i in range(len(d) - k):
ans += d[-i - 1][1]
print(ans) | from collections import Counter
n, k = list(map(int, input().split()))
a = input().split()
d = sorted(Counter(a).values())
ans = 0
for i in range(len(d) - k):
ans += d[i]
print(ans) | 12 | 11 | 220 | 192 | from collections import Counter
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
d = Counter(a)
d = d.most_common()
ans = 0
for i in range(len(d) - k):
ans += d[-i - 1][1]
print(ans)
| from collections import Counter
n, k = list(map(int, input().split()))
a = input().split()
d = sorted(Counter(a).values())
ans = 0
for i in range(len(d) - k):
ans += d[i]
print(ans)
| false | 8.333333 | [
"-a = list(map(int, input().split()))",
"-d = Counter(a)",
"-d = d.most_common()",
"+a = input().split()",
"+d = sorted(Counter(a).values())",
"- ans += d[-i - 1][1]",
"+ ans += d[i]"
]
| false | 0.073949 | 0.077636 | 0.952512 | [
"s745737705",
"s549217825"
]
|
u411203878 | p03474 | python | s905823058 | s958930223 | 166 | 72 | 38,384 | 61,780 | Accepted | Accepted | 56.63 | a,b = list(map(int,input().split()))
s=eval(input())
for i in range(a+b+1):
if i < a and '-' != s[i]:
continue
elif a < i and i < a+b+1 and '-' != s[i]:
continue
elif i == a and '-' == s[i]:
continue
else:
print('No')
exit()
print('Yes') | A,B = list(map(int,input().split()))
S = list(eval(input()))
check = [str(i) for i in range(10)]
okFlag = True
for key,val in enumerate(S):
if key == A:
if S[key] != '-':
okFlag = False
else:
continue
elif S[key] not in check:
okFlag = False
if okFlag:
print('Yes')
else:
print('No') | 14 | 18 | 296 | 354 | a, b = list(map(int, input().split()))
s = eval(input())
for i in range(a + b + 1):
if i < a and "-" != s[i]:
continue
elif a < i and i < a + b + 1 and "-" != s[i]:
continue
elif i == a and "-" == s[i]:
continue
else:
print("No")
exit()
print("Yes")
| A, B = list(map(int, input().split()))
S = list(eval(input()))
check = [str(i) for i in range(10)]
okFlag = True
for key, val in enumerate(S):
if key == A:
if S[key] != "-":
okFlag = False
else:
continue
elif S[key] not in check:
okFlag = False
if okFlag:
print("Yes")
else:
print("No")
| false | 22.222222 | [
"-a, b = list(map(int, input().split()))",
"-s = eval(input())",
"-for i in range(a + b + 1):",
"- if i < a and \"-\" != s[i]:",
"- continue",
"- elif a < i and i < a + b + 1 and \"-\" != s[i]:",
"- continue",
"- elif i == a and \"-\" == s[i]:",
"- continue",
"- else:",
"- print(\"No\")",
"- exit()",
"-print(\"Yes\")",
"+A, B = list(map(int, input().split()))",
"+S = list(eval(input()))",
"+check = [str(i) for i in range(10)]",
"+okFlag = True",
"+for key, val in enumerate(S):",
"+ if key == A:",
"+ if S[key] != \"-\":",
"+ okFlag = False",
"+ else:",
"+ continue",
"+ elif S[key] not in check:",
"+ okFlag = False",
"+if okFlag:",
"+ print(\"Yes\")",
"+else:",
"+ print(\"No\")"
]
| false | 0.127195 | 0.036353 | 3.498894 | [
"s905823058",
"s958930223"
]
|
u556589653 | p03048 | python | s859534512 | s828448918 | 1,965 | 379 | 2,940 | 40,684 | Accepted | Accepted | 80.71 | R,G,B,N = list(map(int,input().split()))
ans = 0
for i in range(0,N//R+1):
for j in range(0,(N-i*R)//G+1):
k = N - i*R -j*G
if k%B == 0 and k>= 0:
ans += 1
print(ans) | R,G,B,N = list(map(int,input().split()))
ans = 0
for i in range(0,N//R+1):
for j in range(0,N//G+1):
k = N - i*R -j*G
if k%B == 0 and k>= 0:
ans += 1
print(ans)
| 8 | 8 | 183 | 178 | R, G, B, N = list(map(int, input().split()))
ans = 0
for i in range(0, N // R + 1):
for j in range(0, (N - i * R) // G + 1):
k = N - i * R - j * G
if k % B == 0 and k >= 0:
ans += 1
print(ans)
| R, G, B, N = list(map(int, input().split()))
ans = 0
for i in range(0, N // R + 1):
for j in range(0, N // G + 1):
k = N - i * R - j * G
if k % B == 0 and k >= 0:
ans += 1
print(ans)
| false | 0 | [
"- for j in range(0, (N - i * R) // G + 1):",
"+ for j in range(0, N // G + 1):"
]
| false | 0.06327 | 0.136399 | 0.463857 | [
"s859534512",
"s828448918"
]
|
u780962115 | p02727 | python | s190336573 | s231937092 | 492 | 410 | 22,504 | 106,708 | Accepted | Accepted | 16.67 | import sys
input=sys.stdin.readline
x,y,a,b,c=list(map(int,input().split()))
a_list=list(map(int,input().split()))
a_list=sorted(a_list)
b_list=list(map(int,input().split()))
b_list=sorted(b_list)
a_list=a_list[-x:]
b_list=b_list[-y:]
c_list=list(map(int,input().split()))
for i in range(c):
c_list[i]=-c_list[i]
import heapq
heapq.heapify(a_list)
heapq.heapify(b_list)
heapq.heapify(c_list)
flag=True
while flag and c_list:
x=heapq.heappop(c_list)
x=x*(-1)
#c_listの中でのもっとも大きい値
min_a=heapq.heappop(a_list)
min_b=heapq.heappop(b_list)
if min(min_a,min_b)>=x:
flag=False
heapq.heappush(a_list,min_a)
heapq.heappush(b_list,min_b)
else:
if min_a>=min_b:
heapq.heappush(a_list,min_a)
heapq.heappush(b_list,x)
elif min_a<min_b:
heapq.heappush(b_list,min_b)
heapq.heappush(a_list,x)
sum_a=sum(list(a_list))
sum_b=sum(list(b_list))
print((sum_a+sum_b))
| x,y,a,b,c=list(map(int,input().split()))
a_list=list(map(int,input().split()))
a_list=sorted(a_list)
b_list=list(map(int,input().split()))
b_list=sorted(b_list)
a_list=a_list[-x:]
b_list=b_list[-y:]
c_list=list(map(int,input().split()))
for i in range(c):
c_list[i]=-c_list[i]
import heapq
heapq.heapify(a_list)
heapq.heapify(b_list)
heapq.heapify(c_list)
flag=True
while flag and c_list:
x=heapq.heappop(c_list)
x=x*(-1)
#c_listの中でのもっとも大きい値
min_a=heapq.heappop(a_list)
min_b=heapq.heappop(b_list)
if min(min_a,min_b)>=x:
flag=False
heapq.heappush(a_list,min_a)
heapq.heappush(b_list,min_b)
else:
if min_a>=min_b:
heapq.heappush(a_list,min_a)
heapq.heappush(b_list,x)
elif min_a<min_b:
heapq.heappush(b_list,min_b)
heapq.heappush(a_list,x)
sum_a=sum(list(a_list))
sum_b=sum(list(b_list))
print((sum_a+sum_b))
| 45 | 45 | 1,037 | 1,000 | import sys
input = sys.stdin.readline
x, y, a, b, c = list(map(int, input().split()))
a_list = list(map(int, input().split()))
a_list = sorted(a_list)
b_list = list(map(int, input().split()))
b_list = sorted(b_list)
a_list = a_list[-x:]
b_list = b_list[-y:]
c_list = list(map(int, input().split()))
for i in range(c):
c_list[i] = -c_list[i]
import heapq
heapq.heapify(a_list)
heapq.heapify(b_list)
heapq.heapify(c_list)
flag = True
while flag and c_list:
x = heapq.heappop(c_list)
x = x * (-1)
# c_listの中でのもっとも大きい値
min_a = heapq.heappop(a_list)
min_b = heapq.heappop(b_list)
if min(min_a, min_b) >= x:
flag = False
heapq.heappush(a_list, min_a)
heapq.heappush(b_list, min_b)
else:
if min_a >= min_b:
heapq.heappush(a_list, min_a)
heapq.heappush(b_list, x)
elif min_a < min_b:
heapq.heappush(b_list, min_b)
heapq.heappush(a_list, x)
sum_a = sum(list(a_list))
sum_b = sum(list(b_list))
print((sum_a + sum_b))
| x, y, a, b, c = list(map(int, input().split()))
a_list = list(map(int, input().split()))
a_list = sorted(a_list)
b_list = list(map(int, input().split()))
b_list = sorted(b_list)
a_list = a_list[-x:]
b_list = b_list[-y:]
c_list = list(map(int, input().split()))
for i in range(c):
c_list[i] = -c_list[i]
import heapq
heapq.heapify(a_list)
heapq.heapify(b_list)
heapq.heapify(c_list)
flag = True
while flag and c_list:
x = heapq.heappop(c_list)
x = x * (-1)
# c_listの中でのもっとも大きい値
min_a = heapq.heappop(a_list)
min_b = heapq.heappop(b_list)
if min(min_a, min_b) >= x:
flag = False
heapq.heappush(a_list, min_a)
heapq.heappush(b_list, min_b)
else:
if min_a >= min_b:
heapq.heappush(a_list, min_a)
heapq.heappush(b_list, x)
elif min_a < min_b:
heapq.heappush(b_list, min_b)
heapq.heappush(a_list, x)
sum_a = sum(list(a_list))
sum_b = sum(list(b_list))
print((sum_a + sum_b))
| false | 0 | [
"-import sys",
"-",
"-input = sys.stdin.readline"
]
| false | 0.036912 | 0.078952 | 0.467522 | [
"s190336573",
"s231937092"
]
|
u493520238 | p02596 | python | s991669975 | s247685292 | 76 | 64 | 71,116 | 63,196 | Accepted | Accepted | 15.79 | k = int(eval(input()))
rem = 7%k
alreadys = [False]*k
alreadys[rem] = True
ans = 1
while True:
if rem == 0:
print(ans)
exit()
ans += 1
rem = (rem*10+7)%k
if alreadys[rem]:
print((-1))
exit()
alreadys[rem] = True | k = int(eval(input()))
rem = 7%k
for i in range(10**6+1):
if rem == 0:
print((i+1))
break
rem = (rem*10+7)%k
else:
print((-1)) | 16 | 9 | 271 | 152 | k = int(eval(input()))
rem = 7 % k
alreadys = [False] * k
alreadys[rem] = True
ans = 1
while True:
if rem == 0:
print(ans)
exit()
ans += 1
rem = (rem * 10 + 7) % k
if alreadys[rem]:
print((-1))
exit()
alreadys[rem] = True
| k = int(eval(input()))
rem = 7 % k
for i in range(10**6 + 1):
if rem == 0:
print((i + 1))
break
rem = (rem * 10 + 7) % k
else:
print((-1))
| false | 43.75 | [
"-alreadys = [False] * k",
"-alreadys[rem] = True",
"-ans = 1",
"-while True:",
"+for i in range(10**6 + 1):",
"- print(ans)",
"- exit()",
"- ans += 1",
"+ print((i + 1))",
"+ break",
"- if alreadys[rem]:",
"- print((-1))",
"- exit()",
"- alreadys[rem] = True",
"+else:",
"+ print((-1))"
]
| false | 0.426638 | 0.14795 | 2.883667 | [
"s991669975",
"s247685292"
]
|
u248670337 | p02630 | python | s242248500 | s485601984 | 595 | 384 | 23,336 | 67,672 | Accepted | Accepted | 35.46 | from collections import*
eval(input());s=sum(A:=list(map(int,input().split())));A=Counter(A)
for i in range(int(eval(input()))):b,c=list(map(int,input().split()));s+=(c-b)*A[b];A[c]+=A[b];A[b]=0;print(s) | from collections import*
_,A,_,*Q=[list(map(int,l.split()))for l in open(0)];A=[a for a in A];s=sum(A);C=Counter(A)
for b,c in Q:s+=(c-b)*C[b];C[c]+=C[b];C[b]=0;print(s) | 3 | 3 | 187 | 165 | from collections import *
eval(input())
s = sum(A := list(map(int, input().split())))
A = Counter(A)
for i in range(int(eval(input()))):
b, c = list(map(int, input().split()))
s += (c - b) * A[b]
A[c] += A[b]
A[b] = 0
print(s)
| from collections import *
_, A, _, *Q = [list(map(int, l.split())) for l in open(0)]
A = [a for a in A]
s = sum(A)
C = Counter(A)
for b, c in Q:
s += (c - b) * C[b]
C[c] += C[b]
C[b] = 0
print(s)
| false | 0 | [
"-eval(input())",
"-s = sum(A := list(map(int, input().split())))",
"-A = Counter(A)",
"-for i in range(int(eval(input()))):",
"- b, c = list(map(int, input().split()))",
"- s += (c - b) * A[b]",
"- A[c] += A[b]",
"- A[b] = 0",
"+_, A, _, *Q = [list(map(int, l.split())) for l in open(0)]",
"+A = [a for a in A]",
"+s = sum(A)",
"+C = Counter(A)",
"+for b, c in Q:",
"+ s += (c - b) * C[b]",
"+ C[c] += C[b]",
"+ C[b] = 0"
]
| false | 0.03622 | 0.072522 | 0.499433 | [
"s242248500",
"s485601984"
]
|
u425177436 | p03480 | python | s233508052 | s252735303 | 60 | 44 | 3,316 | 5,204 | Accepted | Accepted | 26.67 | S=eval(input())
N=K=len(S)
for i in range(1,N):
if S[i-1]!=S[i]:
K=min(K,max(i,N-i))
print(K) | S=eval(input())
N=len(S)
print((min([max(i,N-i) for i in range(1,N) if S[i-1]!=S[i]],default=N))) | 6 | 3 | 104 | 91 | S = eval(input())
N = K = len(S)
for i in range(1, N):
if S[i - 1] != S[i]:
K = min(K, max(i, N - i))
print(K)
| S = eval(input())
N = len(S)
print((min([max(i, N - i) for i in range(1, N) if S[i - 1] != S[i]], default=N)))
| false | 50 | [
"-N = K = len(S)",
"-for i in range(1, N):",
"- if S[i - 1] != S[i]:",
"- K = min(K, max(i, N - i))",
"-print(K)",
"+N = len(S)",
"+print((min([max(i, N - i) for i in range(1, N) if S[i - 1] != S[i]], default=N)))"
]
| false | 0.036455 | 0.034238 | 1.06474 | [
"s233508052",
"s252735303"
]
|
u303650160 | p02642 | python | s769660085 | s730069672 | 767 | 242 | 201,000 | 219,096 | Accepted | Accepted | 68.45 | import sys
def Not_Divisible(n,p):
maxp = max(p)
dp = [[True,0] for _ in range(maxp+1)]
for a in p:
dp[a][1]+=1
t =2
while a*t <= maxp:
if dp[a*t][0] == True :
dp[a*t][0] = False
t+=1
k=0
for d in p:
if dp[d][1] == 1 and dp[d][0] == True:
k+=1
return k
def main():
input = sys.stdin.readline
inp1 = input().rstrip().split()
n = int(inp1[0])
inp2 = input().rstrip().split()
p = tuple(map(int,inp2))
print((Not_Divisible(n,p)))
if __name__ == '__main__':
main() | import sys
def Not_Divisible(n,p):
maxp = max(p)
dp = [True for _ in range(maxp+1)]
count =[0 for _ in range(maxp+1)]
for a in p:
count[a]+=1
t =2
while a*t <= maxp:
if dp[a*t] == True :
dp[a*t] = False
t+=1
k=0
for d in p:
if count[d] == 1 and dp[d] == True:
k+=1
return k
def main():
input = sys.stdin.readline
inp1 = input().rstrip().split()
n = int(inp1[0])
inp2 = input().rstrip().split()
p = tuple(map(int,inp2))
print((Not_Divisible(n,p)))
if __name__ == '__main__':
main() | 32 | 33 | 635 | 661 | import sys
def Not_Divisible(n, p):
maxp = max(p)
dp = [[True, 0] for _ in range(maxp + 1)]
for a in p:
dp[a][1] += 1
t = 2
while a * t <= maxp:
if dp[a * t][0] == True:
dp[a * t][0] = False
t += 1
k = 0
for d in p:
if dp[d][1] == 1 and dp[d][0] == True:
k += 1
return k
def main():
input = sys.stdin.readline
inp1 = input().rstrip().split()
n = int(inp1[0])
inp2 = input().rstrip().split()
p = tuple(map(int, inp2))
print((Not_Divisible(n, p)))
if __name__ == "__main__":
main()
| import sys
def Not_Divisible(n, p):
maxp = max(p)
dp = [True for _ in range(maxp + 1)]
count = [0 for _ in range(maxp + 1)]
for a in p:
count[a] += 1
t = 2
while a * t <= maxp:
if dp[a * t] == True:
dp[a * t] = False
t += 1
k = 0
for d in p:
if count[d] == 1 and dp[d] == True:
k += 1
return k
def main():
input = sys.stdin.readline
inp1 = input().rstrip().split()
n = int(inp1[0])
inp2 = input().rstrip().split()
p = tuple(map(int, inp2))
print((Not_Divisible(n, p)))
if __name__ == "__main__":
main()
| false | 3.030303 | [
"- dp = [[True, 0] for _ in range(maxp + 1)]",
"+ dp = [True for _ in range(maxp + 1)]",
"+ count = [0 for _ in range(maxp + 1)]",
"- dp[a][1] += 1",
"+ count[a] += 1",
"- if dp[a * t][0] == True:",
"- dp[a * t][0] = False",
"+ if dp[a * t] == True:",
"+ dp[a * t] = False",
"- if dp[d][1] == 1 and dp[d][0] == True:",
"+ if count[d] == 1 and dp[d] == True:"
]
| false | 0.110771 | 0.038682 | 2.863656 | [
"s769660085",
"s730069672"
]
|
u802963389 | p03612 | python | s000849918 | s147543392 | 129 | 77 | 19,364 | 14,256 | Accepted | Accepted | 40.31 | from itertools import groupby
n = eval(input())
li = list(map(int, input().split()))
lii = [val == (itr + 1) for itr, val in enumerate(li)]
gbli = [[key, len(list(group))] for key, group in groupby(lii)]
ans = 0
for key, val in gbli:
if key:
ans += (val - 1) // 2 + 1
print(ans)
| from itertools import groupby
n = int(eval(input()))
P = list(map(int, input().split()))
T = [val == (itr + 1) for itr, val in enumerate(P)]
ans = 0
for k, v in groupby(T):
if k == True:
ans += (sum(v) - 1) // 2 + 1
print(ans) | 13 | 11 | 299 | 242 | from itertools import groupby
n = eval(input())
li = list(map(int, input().split()))
lii = [val == (itr + 1) for itr, val in enumerate(li)]
gbli = [[key, len(list(group))] for key, group in groupby(lii)]
ans = 0
for key, val in gbli:
if key:
ans += (val - 1) // 2 + 1
print(ans)
| from itertools import groupby
n = int(eval(input()))
P = list(map(int, input().split()))
T = [val == (itr + 1) for itr, val in enumerate(P)]
ans = 0
for k, v in groupby(T):
if k == True:
ans += (sum(v) - 1) // 2 + 1
print(ans)
| false | 15.384615 | [
"-n = eval(input())",
"-li = list(map(int, input().split()))",
"-lii = [val == (itr + 1) for itr, val in enumerate(li)]",
"-gbli = [[key, len(list(group))] for key, group in groupby(lii)]",
"+n = int(eval(input()))",
"+P = list(map(int, input().split()))",
"+T = [val == (itr + 1) for itr, val in enumerate(P)]",
"-for key, val in gbli:",
"- if key:",
"- ans += (val - 1) // 2 + 1",
"+for k, v in groupby(T):",
"+ if k == True:",
"+ ans += (sum(v) - 1) // 2 + 1"
]
| false | 0.045366 | 0.036808 | 1.23252 | [
"s000849918",
"s147543392"
]
|
u546285759 | p00027 | python | s918940612 | s352816851 | 30 | 20 | 7,980 | 7,980 | Accepted | Accepted | 33.33 | from datetime import date
while True:
m, d = list(map(int, input().split()))
if m == 0:
break
result = date(2004, m, d).isoweekday()
print(("Monday"*(result==1)+"Tuesday"*(result==2)+"Wednesday"*(result==3)+"Thursday"*(result==4)+"Friday"*(result==5)+"Saturday"*(result==6)+"Sunday"*(result==7))) | from datetime import date
while True:
m, d = list(map(int, input().split()))
if m == 0:
break
result = date(2004, m, d).isoweekday()
print(("Mon"*(result==1)+"Tues"*(result==2)+"Wednes"*(result==3)+"Thurs"*(result==4)+"Fri"*(result==5)+"Satur"*(result==6)+"Sun"*(result==7)+"day")) | 7 | 7 | 318 | 303 | from datetime import date
while True:
m, d = list(map(int, input().split()))
if m == 0:
break
result = date(2004, m, d).isoweekday()
print(
(
"Monday" * (result == 1)
+ "Tuesday" * (result == 2)
+ "Wednesday" * (result == 3)
+ "Thursday" * (result == 4)
+ "Friday" * (result == 5)
+ "Saturday" * (result == 6)
+ "Sunday" * (result == 7)
)
)
| from datetime import date
while True:
m, d = list(map(int, input().split()))
if m == 0:
break
result = date(2004, m, d).isoweekday()
print(
(
"Mon" * (result == 1)
+ "Tues" * (result == 2)
+ "Wednes" * (result == 3)
+ "Thurs" * (result == 4)
+ "Fri" * (result == 5)
+ "Satur" * (result == 6)
+ "Sun" * (result == 7)
+ "day"
)
)
| false | 0 | [
"- \"Monday\" * (result == 1)",
"- + \"Tuesday\" * (result == 2)",
"- + \"Wednesday\" * (result == 3)",
"- + \"Thursday\" * (result == 4)",
"- + \"Friday\" * (result == 5)",
"- + \"Saturday\" * (result == 6)",
"- + \"Sunday\" * (result == 7)",
"+ \"Mon\" * (result == 1)",
"+ + \"Tues\" * (result == 2)",
"+ + \"Wednes\" * (result == 3)",
"+ + \"Thurs\" * (result == 4)",
"+ + \"Fri\" * (result == 5)",
"+ + \"Satur\" * (result == 6)",
"+ + \"Sun\" * (result == 7)",
"+ + \"day\""
]
| false | 0.085144 | 0.05495 | 1.549495 | [
"s918940612",
"s352816851"
]
|
u141610915 | p02913 | python | s563195415 | s750868308 | 807 | 724 | 247,304 | 231,048 | Accepted | Accepted | 10.29 | N = int(eval(input()))
S = list(eval(input()))
#LCSRe i番目とj番目でそれぞれ終わるような共通文字列の長さ
#i < j であるi文字目とj文字目が等しいならLCSRe[i + 1][j + 1] = LCSRe[i][j] + 1
#res_lengthよりLCSReの更新した値が大なら、その時のindexをiへ、res_lengthも更新
def longestRepeatedSubstring(s):
n = len(s)
LCSRe = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
res = ""
res_length = 0
index = 0
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
if s[i - 1] == s[j - 1] and LCSRe[i - 1][j - 1] < j - i:
LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1
if LCSRe[i][j] > res_length:
res_length = LCSRe[i][j]
index = max(i, index)
else:
LCSRe[i][j] = 0
#print(LCSRe)
if res_length > 0:
for i in range(index - res_length + 1, index + 1):
res = res + s[i - 1]
return res_length
print((longestRepeatedSubstring(S))) | N = int(eval(input()))
S = list(eval(input())) + ["!"]
dp = [[0] * N for _ in range(N)]
for j in range(1, N):
if S[0] == S[j]:
dp[0][j] = 1
res = 0
for i in range(N):
for j in range(i, N):
res = max(dp[i][j], res)
if i == N - 1 or j == N - 1:
continue
if S[i + 1] == S[j + 1] and j - i > dp[i][j]:
dp[i + 1][j + 1] = dp[i][j] + 1
else:
dp[i + 1][j + 1] = 0
print(res) | 27 | 17 | 859 | 413 | N = int(eval(input()))
S = list(eval(input()))
# LCSRe i番目とj番目でそれぞれ終わるような共通文字列の長さ
# i < j であるi文字目とj文字目が等しいならLCSRe[i + 1][j + 1] = LCSRe[i][j] + 1
# res_lengthよりLCSReの更新した値が大なら、その時のindexをiへ、res_lengthも更新
def longestRepeatedSubstring(s):
n = len(s)
LCSRe = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
res = ""
res_length = 0
index = 0
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
if s[i - 1] == s[j - 1] and LCSRe[i - 1][j - 1] < j - i:
LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1
if LCSRe[i][j] > res_length:
res_length = LCSRe[i][j]
index = max(i, index)
else:
LCSRe[i][j] = 0
# print(LCSRe)
if res_length > 0:
for i in range(index - res_length + 1, index + 1):
res = res + s[i - 1]
return res_length
print((longestRepeatedSubstring(S)))
| N = int(eval(input()))
S = list(eval(input())) + ["!"]
dp = [[0] * N for _ in range(N)]
for j in range(1, N):
if S[0] == S[j]:
dp[0][j] = 1
res = 0
for i in range(N):
for j in range(i, N):
res = max(dp[i][j], res)
if i == N - 1 or j == N - 1:
continue
if S[i + 1] == S[j + 1] and j - i > dp[i][j]:
dp[i + 1][j + 1] = dp[i][j] + 1
else:
dp[i + 1][j + 1] = 0
print(res)
| false | 37.037037 | [
"-S = list(eval(input()))",
"-# LCSRe i番目とj番目でそれぞれ終わるような共通文字列の長さ",
"-# i < j であるi文字目とj文字目が等しいならLCSRe[i + 1][j + 1] = LCSRe[i][j] + 1",
"-# res_lengthよりLCSReの更新した値が大なら、その時のindexをiへ、res_lengthも更新",
"-def longestRepeatedSubstring(s):",
"- n = len(s)",
"- LCSRe = [[0 for _ in range(n + 1)] for _ in range(n + 1)]",
"- res = \"\"",
"- res_length = 0",
"- index = 0",
"- for i in range(1, n + 1):",
"- for j in range(i + 1, n + 1):",
"- if s[i - 1] == s[j - 1] and LCSRe[i - 1][j - 1] < j - i:",
"- LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1",
"- if LCSRe[i][j] > res_length:",
"- res_length = LCSRe[i][j]",
"- index = max(i, index)",
"- else:",
"- LCSRe[i][j] = 0",
"- # print(LCSRe)",
"- if res_length > 0:",
"- for i in range(index - res_length + 1, index + 1):",
"- res = res + s[i - 1]",
"- return res_length",
"-",
"-",
"-print((longestRepeatedSubstring(S)))",
"+S = list(eval(input())) + [\"!\"]",
"+dp = [[0] * N for _ in range(N)]",
"+for j in range(1, N):",
"+ if S[0] == S[j]:",
"+ dp[0][j] = 1",
"+res = 0",
"+for i in range(N):",
"+ for j in range(i, N):",
"+ res = max(dp[i][j], res)",
"+ if i == N - 1 or j == N - 1:",
"+ continue",
"+ if S[i + 1] == S[j + 1] and j - i > dp[i][j]:",
"+ dp[i + 1][j + 1] = dp[i][j] + 1",
"+ else:",
"+ dp[i + 1][j + 1] = 0",
"+print(res)"
]
| false | 0.037604 | 0.040323 | 0.932579 | [
"s563195415",
"s750868308"
]
|
u367130284 | p03608 | python | s448617630 | s057719451 | 670 | 608 | 21,284 | 17,388 | Accepted | Accepted | 9.25 | from itertools import*
from scipy.sparse.csgraph import floyd_warshall
n,m,r=list(map(int,input().split()))
*R,=list(map(int,input().split()))
table=[[0]*n for i in range(n)]
for i in range(m):
a,b,c=list(map(int,input().split()))
table[a-1][b-1]=c
table[b-1][a-1]=c
d,p=floyd_warshall(csgraph=table, directed=False, return_predecessors=True)
cost=[sum(d[i[j]-1][i[j+1]-1]for j in range(r-1))for i in permutations(R)]
print((int(min(cost)))) | #from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
from scipy.sparse.csgraph import floyd_warshall
#input=sys.stdin.readline #危険!基本オフにしろ!
sys.setrecursionlimit(10**6)
def main():
n,m,r=list(map(int,input().split()))
grid=[[0]*n for i in range(n)]
*R,=list(map(int,input().split()))
for i in range(m):
a,b,c=list(map(int,input().split()))
grid[a-1][b-1]=c
grid[b-1][a-1]=c
# print(grid)
d,p=floyd_warshall(csgraph=grid, directed=False, return_predecessors=True)
# print(p)
# print(d)
print((int(min(sum(d[i[j]-1][i[j+1]-1]for j in range(len(i)-1))for i in permutations(R)))))
if __name__ == '__main__':
main()
| 13 | 34 | 446 | 1,081 | from itertools import *
from scipy.sparse.csgraph import floyd_warshall
n, m, r = list(map(int, input().split()))
(*R,) = list(map(int, input().split()))
table = [[0] * n for i in range(n)]
for i in range(m):
a, b, c = list(map(int, input().split()))
table[a - 1][b - 1] = c
table[b - 1][a - 1] = c
d, p = floyd_warshall(csgraph=table, directed=False, return_predecessors=True)
cost = [sum(d[i[j] - 1][i[j + 1] - 1] for j in range(r - 1)) for i in permutations(R)]
print((int(min(cost))))
| # from numpy import*
# from scipy import*
from collections import * # defaultdict Counter deque appendleft
from fractions import gcd
from functools import * # reduce
from itertools import * # permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import * # bisect_left bisect_right
from heapq import * # heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
from scipy.sparse.csgraph import floyd_warshall
# input=sys.stdin.readline #危険!基本オフにしろ!
sys.setrecursionlimit(10**6)
def main():
n, m, r = list(map(int, input().split()))
grid = [[0] * n for i in range(n)]
(*R,) = list(map(int, input().split()))
for i in range(m):
a, b, c = list(map(int, input().split()))
grid[a - 1][b - 1] = c
grid[b - 1][a - 1] = c
# print(grid)
d, p = floyd_warshall(csgraph=grid, directed=False, return_predecessors=True)
# print(p)
# print(d)
print(
(
int(
min(
sum(d[i[j] - 1][i[j + 1] - 1] for j in range(len(i) - 1))
for i in permutations(R)
)
)
)
)
if __name__ == "__main__":
main()
| false | 61.764706 | [
"-from itertools import *",
"+# from numpy import*",
"+# from scipy import*",
"+from collections import * # defaultdict Counter deque appendleft",
"+from fractions import gcd",
"+from functools import * # reduce",
"+from itertools import * # permutations(\"AB\",repeat=2) combinations(\"AB\",2) product(\"AB\",2) groupby",
"+from operator import mul",
"+from bisect import * # bisect_left bisect_right",
"+from heapq import * # heapify heappop heappushpop",
"+from math import factorial",
"+from copy import deepcopy",
"+import sys",
"-n, m, r = list(map(int, input().split()))",
"-(*R,) = list(map(int, input().split()))",
"-table = [[0] * n for i in range(n)]",
"-for i in range(m):",
"- a, b, c = list(map(int, input().split()))",
"- table[a - 1][b - 1] = c",
"- table[b - 1][a - 1] = c",
"-d, p = floyd_warshall(csgraph=table, directed=False, return_predecessors=True)",
"-cost = [sum(d[i[j] - 1][i[j + 1] - 1] for j in range(r - 1)) for i in permutations(R)]",
"-print((int(min(cost))))",
"+# input=sys.stdin.readline #危険!基本オフにしろ!",
"+sys.setrecursionlimit(10**6)",
"+",
"+",
"+def main():",
"+ n, m, r = list(map(int, input().split()))",
"+ grid = [[0] * n for i in range(n)]",
"+ (*R,) = list(map(int, input().split()))",
"+ for i in range(m):",
"+ a, b, c = list(map(int, input().split()))",
"+ grid[a - 1][b - 1] = c",
"+ grid[b - 1][a - 1] = c",
"+ # print(grid)",
"+ d, p = floyd_warshall(csgraph=grid, directed=False, return_predecessors=True)",
"+ # print(p)",
"+ # print(d)",
"+ print(",
"+ (",
"+ int(",
"+ min(",
"+ sum(d[i[j] - 1][i[j + 1] - 1] for j in range(len(i) - 1))",
"+ for i in permutations(R)",
"+ )",
"+ )",
"+ )",
"+ )",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.452229 | 0.494109 | 0.915242 | [
"s448617630",
"s057719451"
]
|
u777923818 | p03286 | python | s769865141 | s148451258 | 447 | 18 | 8,344 | 3,064 | Accepted | Accepted | 95.97 | # -*- coding: utf-8 -*-
from bisect import bisect_left
def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
A = []
B = []
for i in range(2**16):
A.append(int(("0{}"*16).format(*list(bin(i)[2:].zfill(16))), 2))
for i in range(2**16):
B.append(-int(("{}0"*16).format(*list(bin(i)[2:].zfill(16))), 2))
for j, b in enumerate(B):
i = bisect_left(A, N-b)
if i == len(A):
continue
a = A[i]
if a+b == N:
ans = [""]*32
ans[::2] = list(bin(j)[2:].zfill(16))
ans[1::2] = list(bin(i)[2:].zfill(16))
print((int("".join(ans))))
break | from bisect import bisect_left
def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
U = [0]*32
L = [0]*32
U[0] = 1
for i in range(1, 32):
if i%2:
U[i] = U[i-1]*1
L[i] = L[i-1] + 2**i
else:
U[i] = U[i-1] + 2**i
L[i] = L[i-1] * 1
searched = [0]*32
while N:
if N < 0:
d = bisect_left(L, -N)
assert searched[d] != 1
searched[d] = 1
N += 2**d
else:
d = bisect_left(U, N)
assert searched[d] != 1
searched[d] = 1
N -= 2**d
print(("0"*(sum(searched) == 0) + "".join(map(str, searched)).rstrip("0")[::-1])) | 23 | 28 | 628 | 651 | # -*- coding: utf-8 -*-
from bisect import bisect_left
def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
A = []
B = []
for i in range(2**16):
A.append(int(("0{}" * 16).format(*list(bin(i)[2:].zfill(16))), 2))
for i in range(2**16):
B.append(-int(("{}0" * 16).format(*list(bin(i)[2:].zfill(16))), 2))
for j, b in enumerate(B):
i = bisect_left(A, N - b)
if i == len(A):
continue
a = A[i]
if a + b == N:
ans = [""] * 32
ans[::2] = list(bin(j)[2:].zfill(16))
ans[1::2] = list(bin(i)[2:].zfill(16))
print((int("".join(ans))))
break
| from bisect import bisect_left
def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
U = [0] * 32
L = [0] * 32
U[0] = 1
for i in range(1, 32):
if i % 2:
U[i] = U[i - 1] * 1
L[i] = L[i - 1] + 2**i
else:
U[i] = U[i - 1] + 2**i
L[i] = L[i - 1] * 1
searched = [0] * 32
while N:
if N < 0:
d = bisect_left(L, -N)
assert searched[d] != 1
searched[d] = 1
N += 2**d
else:
d = bisect_left(U, N)
assert searched[d] != 1
searched[d] = 1
N -= 2**d
print(("0" * (sum(searched) == 0) + "".join(map(str, searched)).rstrip("0")[::-1]))
| false | 17.857143 | [
"-# -*- coding: utf-8 -*-",
"-A = []",
"-B = []",
"-for i in range(2**16):",
"- A.append(int((\"0{}\" * 16).format(*list(bin(i)[2:].zfill(16))), 2))",
"-for i in range(2**16):",
"- B.append(-int((\"{}0\" * 16).format(*list(bin(i)[2:].zfill(16))), 2))",
"-for j, b in enumerate(B):",
"- i = bisect_left(A, N - b)",
"- if i == len(A):",
"- continue",
"- a = A[i]",
"- if a + b == N:",
"- ans = [\"\"] * 32",
"- ans[::2] = list(bin(j)[2:].zfill(16))",
"- ans[1::2] = list(bin(i)[2:].zfill(16))",
"- print((int(\"\".join(ans))))",
"- break",
"+U = [0] * 32",
"+L = [0] * 32",
"+U[0] = 1",
"+for i in range(1, 32):",
"+ if i % 2:",
"+ U[i] = U[i - 1] * 1",
"+ L[i] = L[i - 1] + 2**i",
"+ else:",
"+ U[i] = U[i - 1] + 2**i",
"+ L[i] = L[i - 1] * 1",
"+searched = [0] * 32",
"+while N:",
"+ if N < 0:",
"+ d = bisect_left(L, -N)",
"+ assert searched[d] != 1",
"+ searched[d] = 1",
"+ N += 2**d",
"+ else:",
"+ d = bisect_left(U, N)",
"+ assert searched[d] != 1",
"+ searched[d] = 1",
"+ N -= 2**d",
"+print((\"0\" * (sum(searched) == 0) + \"\".join(map(str, searched)).rstrip(\"0\")[::-1]))"
]
| false | 0.580522 | 0.037546 | 15.461688 | [
"s769865141",
"s148451258"
]
|
u679759899 | p03078 | python | s197848552 | s109079857 | 977 | 370 | 155,448 | 58,204 | Accepted | Accepted | 62.13 | x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
xy = []
for aa in a:
for bb in b:
xy.append(aa + bb)
xy.sort(reverse=True)
t =[]
for d in xy[:k]:
for cc in c:
t.append(d+cc)
t.sort(reverse=True)
for tt in t[:k]:
print(tt) | from heapq import *
x, y, z, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)
a.append(-float('inf'))
b.append(-float('inf'))
c.append(-float('inf'))
done = {}
h = []
heappush(h, (-(a[0] + b[0] + c[0]), 0, 0, 0))
done[0,0,0] = 1
ind = 0
while ind < k:
t = heappop(h)
print((-t[0]))
ind += 1
if (t[1]+1, t[2], t[3]) not in done:
done[t[1]+1, t[2], t[3]] = 1
heappush(h, (-(a[t[1]+1] + b[t[2]] + c[t[3]]), t[1] + 1, t[2], t[3]))
if (t[1], t[2]+1, t[3]) not in done:
done[t[1], t[2]+1, t[3]] = 1
heappush(h, (-(a[t[1]] + b[t[2]+1] + c[t[3]]), t[1], t[2]+1, t[3]))
if (t[1], t[2], t[3]+1) not in done:
done[t[1], t[2], t[3]+1] = 1
heappush(h, (-(a[t[1]] + b[t[2]] + c[t[3]+1]), t[1], t[2], t[3]+1))
| 17 | 29 | 365 | 951 | x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
xy = []
for aa in a:
for bb in b:
xy.append(aa + bb)
xy.sort(reverse=True)
t = []
for d in xy[:k]:
for cc in c:
t.append(d + cc)
t.sort(reverse=True)
for tt in t[:k]:
print(tt)
| from heapq import *
x, y, z, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)
a.append(-float("inf"))
b.append(-float("inf"))
c.append(-float("inf"))
done = {}
h = []
heappush(h, (-(a[0] + b[0] + c[0]), 0, 0, 0))
done[0, 0, 0] = 1
ind = 0
while ind < k:
t = heappop(h)
print((-t[0]))
ind += 1
if (t[1] + 1, t[2], t[3]) not in done:
done[t[1] + 1, t[2], t[3]] = 1
heappush(h, (-(a[t[1] + 1] + b[t[2]] + c[t[3]]), t[1] + 1, t[2], t[3]))
if (t[1], t[2] + 1, t[3]) not in done:
done[t[1], t[2] + 1, t[3]] = 1
heappush(h, (-(a[t[1]] + b[t[2] + 1] + c[t[3]]), t[1], t[2] + 1, t[3]))
if (t[1], t[2], t[3] + 1) not in done:
done[t[1], t[2], t[3] + 1] = 1
heappush(h, (-(a[t[1]] + b[t[2]] + c[t[3] + 1]), t[1], t[2], t[3] + 1))
| false | 41.37931 | [
"+from heapq import *",
"+",
"-a = list(map(int, input().split()))",
"-b = list(map(int, input().split()))",
"-c = list(map(int, input().split()))",
"-xy = []",
"-for aa in a:",
"- for bb in b:",
"- xy.append(aa + bb)",
"-xy.sort(reverse=True)",
"-t = []",
"-for d in xy[:k]:",
"- for cc in c:",
"- t.append(d + cc)",
"-t.sort(reverse=True)",
"-for tt in t[:k]:",
"- print(tt)",
"+a = sorted(list(map(int, input().split())), reverse=True)",
"+b = sorted(list(map(int, input().split())), reverse=True)",
"+c = sorted(list(map(int, input().split())), reverse=True)",
"+a.append(-float(\"inf\"))",
"+b.append(-float(\"inf\"))",
"+c.append(-float(\"inf\"))",
"+done = {}",
"+h = []",
"+heappush(h, (-(a[0] + b[0] + c[0]), 0, 0, 0))",
"+done[0, 0, 0] = 1",
"+ind = 0",
"+while ind < k:",
"+ t = heappop(h)",
"+ print((-t[0]))",
"+ ind += 1",
"+ if (t[1] + 1, t[2], t[3]) not in done:",
"+ done[t[1] + 1, t[2], t[3]] = 1",
"+ heappush(h, (-(a[t[1] + 1] + b[t[2]] + c[t[3]]), t[1] + 1, t[2], t[3]))",
"+ if (t[1], t[2] + 1, t[3]) not in done:",
"+ done[t[1], t[2] + 1, t[3]] = 1",
"+ heappush(h, (-(a[t[1]] + b[t[2] + 1] + c[t[3]]), t[1], t[2] + 1, t[3]))",
"+ if (t[1], t[2], t[3] + 1) not in done:",
"+ done[t[1], t[2], t[3] + 1] = 1",
"+ heappush(h, (-(a[t[1]] + b[t[2]] + c[t[3] + 1]), t[1], t[2], t[3] + 1))"
]
| false | 0.145933 | 0.041831 | 3.488655 | [
"s197848552",
"s109079857"
]
|
u279493135 | p02933 | python | s781797400 | s333743568 | 57 | 43 | 6,096 | 5,588 | Accepted | Accepted | 24.56 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
a = INT()
s = eval(input())
if a >= 3200:
print(s)
else:
print("red")
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
a = INT()
s = eval(input())
print(("red" if a < 3200 else s))
| 24 | 22 | 690 | 690 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
a = INT()
s = eval(input())
if a >= 3200:
print(s)
else:
print("red")
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
a = INT()
s = eval(input())
print(("red" if a < 3200 else s))
| false | 8.333333 | [
"-from itertools import permutations, combinations, product, accumulate",
"+from itertools import permutations, combinations, product",
"+from bisect import bisect",
"-if a >= 3200:",
"- print(s)",
"-else:",
"- print(\"red\")",
"+print((\"red\" if a < 3200 else s))"
]
| false | 0.047202 | 0.046909 | 1.006248 | [
"s781797400",
"s333743568"
]
|
u633548583 | p03250 | python | s749925163 | s914147758 | 26 | 17 | 2,940 | 2,940 | Accepted | Accepted | 34.62 | a,b,c=sorted(map(int,input().split()))
print((10*c+b+a)) | a,b,c=sorted(list(map(int,input().split())))
print((c*10+b+a)) | 2 | 2 | 55 | 61 | a, b, c = sorted(map(int, input().split()))
print((10 * c + b + a))
| a, b, c = sorted(list(map(int, input().split())))
print((c * 10 + b + a))
| false | 0 | [
"-a, b, c = sorted(map(int, input().split()))",
"-print((10 * c + b + a))",
"+a, b, c = sorted(list(map(int, input().split())))",
"+print((c * 10 + b + a))"
]
| false | 0.046072 | 0.038189 | 1.206417 | [
"s749925163",
"s914147758"
]
|
u066692421 | p03221 | python | s468181352 | s790821611 | 916 | 818 | 43,404 | 36,020 | Accepted | Accepted | 10.7 | list1 = input().split()
n = int(list1[0])
m = int(list1[1])
pre = [[] for i in range(n)]
for j in range(m):
data = input().split()
p = int(data[0])
y = int(data[1])
pre[p - 1].append((j, y))
inums = []
for k in range(n):
if len(pre[k]) == 0:
pass
else:
sorted_y = sorted(pre[k], key = lambda x:x[1])
for l in range(len(sorted_y)):
s1 = str(k + 1).zfill(6)
s2 = str(l + 1).zfill(6)
inums.append((sorted_y[l][0], s1 + s2))
ans = sorted(inums, key = lambda x:x[0])
for h in range(m):
print((ans[h][1])) | list1 = input().split()
n = int(list1[0])
m = int(list1[1])
pre = [[] for i in range(n)]
for j in range(m):
data = input().split()
p = int(data[0])
y = int(data[1])
pre[p - 1].append((j, y))
inums = [0 for z in range(m)]
for k in range(n):
if len(pre[k]) == 0:
pass
else:
sorted_y = sorted(pre[k], key = lambda x:x[1])
for l in range(len(sorted_y)):
s1 = str(k + 1).zfill(6)
s2 = str(l + 1).zfill(6)
inums[sorted_y[l][0]] = s1 + s2
for h in range(m):
print((inums[h])) | 25 | 24 | 612 | 580 | list1 = input().split()
n = int(list1[0])
m = int(list1[1])
pre = [[] for i in range(n)]
for j in range(m):
data = input().split()
p = int(data[0])
y = int(data[1])
pre[p - 1].append((j, y))
inums = []
for k in range(n):
if len(pre[k]) == 0:
pass
else:
sorted_y = sorted(pre[k], key=lambda x: x[1])
for l in range(len(sorted_y)):
s1 = str(k + 1).zfill(6)
s2 = str(l + 1).zfill(6)
inums.append((sorted_y[l][0], s1 + s2))
ans = sorted(inums, key=lambda x: x[0])
for h in range(m):
print((ans[h][1]))
| list1 = input().split()
n = int(list1[0])
m = int(list1[1])
pre = [[] for i in range(n)]
for j in range(m):
data = input().split()
p = int(data[0])
y = int(data[1])
pre[p - 1].append((j, y))
inums = [0 for z in range(m)]
for k in range(n):
if len(pre[k]) == 0:
pass
else:
sorted_y = sorted(pre[k], key=lambda x: x[1])
for l in range(len(sorted_y)):
s1 = str(k + 1).zfill(6)
s2 = str(l + 1).zfill(6)
inums[sorted_y[l][0]] = s1 + s2
for h in range(m):
print((inums[h]))
| false | 4 | [
"-inums = []",
"+inums = [0 for z in range(m)]",
"- inums.append((sorted_y[l][0], s1 + s2))",
"-ans = sorted(inums, key=lambda x: x[0])",
"+ inums[sorted_y[l][0]] = s1 + s2",
"- print((ans[h][1]))",
"+ print((inums[h]))"
]
| false | 0.047293 | 0.037816 | 1.250589 | [
"s468181352",
"s790821611"
]
|
u893478938 | p03173 | python | s258297710 | s370338698 | 596 | 244 | 48,016 | 47,344 | Accepted | Accepted | 59.06 | def resolve():
N = int(eval(input()))
a = list(map(int,input().split()))
DP = [[2 ** 63 -1 for _ in range(N+1)] for _ in range(N)]
SUM = [[0 for _ in range(N+1)] for _ in range(N+1)]
SUM[0][0] = 0
for i in range(N):
for j in range(i,N):
SUM[i][j+1] = SUM[i][j] + a[j]
if i < j:
SUM[i+1][j] = SUM[i][j] - a[i]
for i in range(N):
j = i+1
DP[i][j] = 0
for w in range(2,N+1):
for i in range(N+1-w):
j = i + w
for k in range(i,j):
DP[i][j] = min(DP[i][k]+DP[k][j]+SUM[i][j],DP[i][j])
print((DP[0][N]))
resolve() | def resolve():
N = int(eval(input()))
a = list(map(int,input().split()))
DP = [[2 ** 63 -1 for _ in range(N+1)] for _ in range(N)]
SUM = [[0 for _ in range(N+1)] for _ in range(N+1)]
RANGE = [[0 for _ in range(N+1)] for _ in range(N+1)]
SUM[0][0] = 0
for i in range(N):
for j in range(i,N):
SUM[i][j+1] = SUM[i][j] + a[j]
if i < j:
SUM[i+1][j] = SUM[i][j] - a[i]
for i in range(N):
j = i+1
DP[i][j] = 0
RANGE[i][j] = i
for w in range(2,N+1):
for i in range(N+1-w):
j = i + w
for k in range(RANGE[i][j-1],RANGE[i+1][j]+1):
s = DP[i][k]+DP[k][j]+SUM[i][j]
if DP[i][j] > s:
DP[i][j] = s
RANGE[i][j] = k
print((DP[0][N]))
resolve() | 24 | 29 | 673 | 867 | def resolve():
N = int(eval(input()))
a = list(map(int, input().split()))
DP = [[2**63 - 1 for _ in range(N + 1)] for _ in range(N)]
SUM = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
SUM[0][0] = 0
for i in range(N):
for j in range(i, N):
SUM[i][j + 1] = SUM[i][j] + a[j]
if i < j:
SUM[i + 1][j] = SUM[i][j] - a[i]
for i in range(N):
j = i + 1
DP[i][j] = 0
for w in range(2, N + 1):
for i in range(N + 1 - w):
j = i + w
for k in range(i, j):
DP[i][j] = min(DP[i][k] + DP[k][j] + SUM[i][j], DP[i][j])
print((DP[0][N]))
resolve()
| def resolve():
N = int(eval(input()))
a = list(map(int, input().split()))
DP = [[2**63 - 1 for _ in range(N + 1)] for _ in range(N)]
SUM = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
RANGE = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
SUM[0][0] = 0
for i in range(N):
for j in range(i, N):
SUM[i][j + 1] = SUM[i][j] + a[j]
if i < j:
SUM[i + 1][j] = SUM[i][j] - a[i]
for i in range(N):
j = i + 1
DP[i][j] = 0
RANGE[i][j] = i
for w in range(2, N + 1):
for i in range(N + 1 - w):
j = i + w
for k in range(RANGE[i][j - 1], RANGE[i + 1][j] + 1):
s = DP[i][k] + DP[k][j] + SUM[i][j]
if DP[i][j] > s:
DP[i][j] = s
RANGE[i][j] = k
print((DP[0][N]))
resolve()
| false | 17.241379 | [
"+ RANGE = [[0 for _ in range(N + 1)] for _ in range(N + 1)]",
"+ RANGE[i][j] = i",
"- for k in range(i, j):",
"- DP[i][j] = min(DP[i][k] + DP[k][j] + SUM[i][j], DP[i][j])",
"+ for k in range(RANGE[i][j - 1], RANGE[i + 1][j] + 1):",
"+ s = DP[i][k] + DP[k][j] + SUM[i][j]",
"+ if DP[i][j] > s:",
"+ DP[i][j] = s",
"+ RANGE[i][j] = k"
]
| false | 0.040562 | 0.041046 | 0.98821 | [
"s258297710",
"s370338698"
]
|
u608088992 | p03457 | python | s145297307 | s090077746 | 401 | 308 | 21,108 | 3,064 | Accepted | Accepted | 23.19 | N = int(eval(input()))
I = [[int(i) for i in input().split()] for j in range(N)]
current, time = (0, 0), 0
for i in range(N):
dist = abs(current[0] - I[i][1]) + abs(current[1] - I[i][2])
if dist > I[i][0] - time or (I[i][0]- time - dist) % 2 == 1:
print("No")
break
current, time = (I[i][1], I[i][2]), I[i][0]
else:
print("Yes") | import sys
def solve():
N = int(eval(input()))
cx, cy = 0, 0
nt = 0
for _ in range(N):
t, x, y = list(map(int, input().split()))
rem = t - nt - abs(x - cx) - abs(y - cy)
if rem < 0 or rem % 2 > 0:
print("No")
break
cx, cy = x, y
nt = t
else: print("Yes")
return 0
if __name__ == "__main__":
solve() | 12 | 20 | 366 | 408 | N = int(eval(input()))
I = [[int(i) for i in input().split()] for j in range(N)]
current, time = (0, 0), 0
for i in range(N):
dist = abs(current[0] - I[i][1]) + abs(current[1] - I[i][2])
if dist > I[i][0] - time or (I[i][0] - time - dist) % 2 == 1:
print("No")
break
current, time = (I[i][1], I[i][2]), I[i][0]
else:
print("Yes")
| import sys
def solve():
N = int(eval(input()))
cx, cy = 0, 0
nt = 0
for _ in range(N):
t, x, y = list(map(int, input().split()))
rem = t - nt - abs(x - cx) - abs(y - cy)
if rem < 0 or rem % 2 > 0:
print("No")
break
cx, cy = x, y
nt = t
else:
print("Yes")
return 0
if __name__ == "__main__":
solve()
| false | 40 | [
"-N = int(eval(input()))",
"-I = [[int(i) for i in input().split()] for j in range(N)]",
"-current, time = (0, 0), 0",
"-for i in range(N):",
"- dist = abs(current[0] - I[i][1]) + abs(current[1] - I[i][2])",
"- if dist > I[i][0] - time or (I[i][0] - time - dist) % 2 == 1:",
"- print(\"No\")",
"- break",
"- current, time = (I[i][1], I[i][2]), I[i][0]",
"-else:",
"- print(\"Yes\")",
"+import sys",
"+",
"+",
"+def solve():",
"+ N = int(eval(input()))",
"+ cx, cy = 0, 0",
"+ nt = 0",
"+ for _ in range(N):",
"+ t, x, y = list(map(int, input().split()))",
"+ rem = t - nt - abs(x - cx) - abs(y - cy)",
"+ if rem < 0 or rem % 2 > 0:",
"+ print(\"No\")",
"+ break",
"+ cx, cy = x, y",
"+ nt = t",
"+ else:",
"+ print(\"Yes\")",
"+ return 0",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
]
| false | 0.041955 | 0.041349 | 1.014663 | [
"s145297307",
"s090077746"
]
|
u127499732 | p02911 | python | s667749296 | s385040514 | 123 | 105 | 13,164 | 14,412 | Accepted | Accepted | 14.63 | def main():
import sys
import collections
n,k,q=list(map(int,input().split()))
a=[int(e) for e in sys.stdin]
point=[k-q]*n
for person,getPoint in list(collections.Counter(a).items()):
point[person-1]+=getPoint
for res in point:
print(("Yes" if res>0 else "No"))
if __name__=="__main__":
main() | def main():
import collections
n, k, q, *a = list(map(int, open(0).read().split()))
point=[k-q]*n
for person,getPoint in list(collections.Counter(a).items()):
point[person-1]+=getPoint
for res in point:
print(("Yes" if res>0 else "No"))
if __name__=="__main__":
main() | 16 | 13 | 332 | 297 | def main():
import sys
import collections
n, k, q = list(map(int, input().split()))
a = [int(e) for e in sys.stdin]
point = [k - q] * n
for person, getPoint in list(collections.Counter(a).items()):
point[person - 1] += getPoint
for res in point:
print(("Yes" if res > 0 else "No"))
if __name__ == "__main__":
main()
| def main():
import collections
n, k, q, *a = list(map(int, open(0).read().split()))
point = [k - q] * n
for person, getPoint in list(collections.Counter(a).items()):
point[person - 1] += getPoint
for res in point:
print(("Yes" if res > 0 else "No"))
if __name__ == "__main__":
main()
| false | 18.75 | [
"- import sys",
"- n, k, q = list(map(int, input().split()))",
"- a = [int(e) for e in sys.stdin]",
"+ n, k, q, *a = list(map(int, open(0).read().split()))"
]
| false | 0.079589 | 0.042606 | 1.86804 | [
"s667749296",
"s385040514"
]
|
u255673886 | p02787 | python | s106901311 | s275556396 | 541 | 370 | 43,756 | 233,308 | Accepted | Accepted | 31.61 | from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
def myinput():
return list(map(int,input().split()))
def mylistinput(n):
return [ list(myinput()) for _ in range(n) ]
def mycol(data,col):
return [ row[col] for row in data ]
def mysort(data,col,reverse_flag):
data.sort(key=lambda x:x[col],reverse=reverse_flag)
return data
def mymax(data):
M = -1*float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M,m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m,M)
return m
def myoutput(ls,space=True):
if space:
if len(ls)==0:
print(" ")
elif type(ls[0])==str:
print((" ".join(ls)))
elif type(ls[0])==int:
print((" ".join(map(str,ls))))
else:
print("Output Error")
else:
if len(ls)==0:
print("")
elif type(ls[0])==str:
print(("".join(ls)))
elif type(ls[0])==int:
print(("".join(map(str,ls))))
else:
print("Output Error")
H,N = myinput()
AB = mylistinput(N)
# dp[i]: 敵の体力をiだけ減らすとしたときの,消耗魔力累計値の最小値
dp = [float("inf")]*(H+1)
dp[0] = 0
for i in range(1,H+1):
for j in range(N):
a = AB[j][0]
b = AB[j][1]
if i<a:
dp[i] = min( dp[i], dp[0]+b )
else:
dp[i] = min( dp[i], dp[i-a]+b )
# print(dp)
ans = dp[H]
print(ans) | from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
def mycol(data,col):
return [ row[col] for row in data ]
def mysort(data,col,reverse=False):
data.sort(key=lambda x:x[col],reverse=revese)
return data
def mymax(data):
M = -1*float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M,m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m,M)
return m
def mycount(ls,x):
# lsはソート済みであること
l = bisect_left(ls,x)
r = bisect_right(ls,x)
return (r-l)
def mydictvaluesort(dictionary):
return sorted( list(dictionary.items()), key=lambda x:x[1] )
def mydictkeysort(dictionary):
return sorted( list(dictionary.items()), key=lambda x:x[0] )
def myoutput(ls,space=True):
if space:
if len(ls)==0:
print(" ")
elif type(ls[0])==str:
print((" ".join(ls)))
elif type(ls[0])==int:
print((" ".join(map(str,ls))))
else:
print("Output Error")
else:
if len(ls)==0:
print("")
elif type(ls[0])==str:
print(("".join(ls)))
elif type(ls[0])==int:
print(("".join(map(str,ls))))
else:
print("Output Error")
def I():
return int(eval(input()))
def MI():
return list(map(int,input().split()))
def RI():
return list(map(int,input().split()))
def CI(n):
return [ int(eval(input())) for _ in range(n) ]
def LI(n):
return [ list(map(int,input().split())) for _ in range(n) ]
def S():
return eval(input())
def MS():
return input().split()
def RS():
return list(eval(input()))
def CS(n):
return [ eval(input()) for _ in range(n) ]
def LS(n):
return [ list(eval(input())) for _ in range(n) ]
# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())
h,n = MI()
ab = LI(n)
# dp[i][j]:i番目までの魔法の中から削る体力がj以上になるように選んだ時の消耗魔力の最小値
dp = [ [INF]*(h+1) for _ in range(n+1) ]
dp[0][0] = 0
for i in range(n):
a = ab[i][0]
b = ab[i][1]
for j in range(h+1):
if j<a:
dp[i+1][j] = min( dp[i][j], b )
else:
dp[i+1][j] = min( dp[i][j], dp[i+1][j-a]+b )
# print(dp)
print((dp[n][h])) | 76 | 121 | 1,868 | 2,877 | from collections import deque
from heapq import heapify, heappop, heappush, heappushpop
from copy import copy, deepcopy
from itertools import permutations, combinations
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
def myinput():
return list(map(int, input().split()))
def mylistinput(n):
return [list(myinput()) for _ in range(n)]
def mycol(data, col):
return [row[col] for row in data]
def mysort(data, col, reverse_flag):
data.sort(key=lambda x: x[col], reverse=reverse_flag)
return data
def mymax(data):
M = -1 * float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M, m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m, M)
return m
def myoutput(ls, space=True):
if space:
if len(ls) == 0:
print(" ")
elif type(ls[0]) == str:
print((" ".join(ls)))
elif type(ls[0]) == int:
print((" ".join(map(str, ls))))
else:
print("Output Error")
else:
if len(ls) == 0:
print("")
elif type(ls[0]) == str:
print(("".join(ls)))
elif type(ls[0]) == int:
print(("".join(map(str, ls))))
else:
print("Output Error")
H, N = myinput()
AB = mylistinput(N)
# dp[i]: 敵の体力をiだけ減らすとしたときの,消耗魔力累計値の最小値
dp = [float("inf")] * (H + 1)
dp[0] = 0
for i in range(1, H + 1):
for j in range(N):
a = AB[j][0]
b = AB[j][1]
if i < a:
dp[i] = min(dp[i], dp[0] + b)
else:
dp[i] = min(dp[i], dp[i - a] + b)
# print(dp)
ans = dp[H]
print(ans)
| from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop
from copy import copy, deepcopy
from itertools import product, permutations, combinations, combinations_with_replacement
from bisect import bisect_left, bisect_right
from math import sqrt, gcd, ceil, floor, factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean, median, mode
import sys
sys.setrecursionlimit(10**6)
INF = float("inf")
def mycol(data, col):
return [row[col] for row in data]
def mysort(data, col, reverse=False):
data.sort(key=lambda x: x[col], reverse=revese)
return data
def mymax(data):
M = -1 * float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M, m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m, M)
return m
def mycount(ls, x):
# lsはソート済みであること
l = bisect_left(ls, x)
r = bisect_right(ls, x)
return r - l
def mydictvaluesort(dictionary):
return sorted(list(dictionary.items()), key=lambda x: x[1])
def mydictkeysort(dictionary):
return sorted(list(dictionary.items()), key=lambda x: x[0])
def myoutput(ls, space=True):
if space:
if len(ls) == 0:
print(" ")
elif type(ls[0]) == str:
print((" ".join(ls)))
elif type(ls[0]) == int:
print((" ".join(map(str, ls))))
else:
print("Output Error")
else:
if len(ls) == 0:
print("")
elif type(ls[0]) == str:
print(("".join(ls)))
elif type(ls[0]) == int:
print(("".join(map(str, ls))))
else:
print("Output Error")
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def RI():
return list(map(int, input().split()))
def CI(n):
return [int(eval(input())) for _ in range(n)]
def LI(n):
return [list(map(int, input().split())) for _ in range(n)]
def S():
return eval(input())
def MS():
return input().split()
def RS():
return list(eval(input()))
def CS(n):
return [eval(input()) for _ in range(n)]
def LS(n):
return [list(eval(input())) for _ in range(n)]
# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())
h, n = MI()
ab = LI(n)
# dp[i][j]:i番目までの魔法の中から削る体力がj以上になるように選んだ時の消耗魔力の最小値
dp = [[INF] * (h + 1) for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
a = ab[i][0]
b = ab[i][1]
for j in range(h + 1):
if j < a:
dp[i + 1][j] = min(dp[i][j], b)
else:
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a] + b)
# print(dp)
print((dp[n][h]))
| false | 37.190083 | [
"-from collections import deque",
"+from collections import deque, defaultdict, Counter",
"-from itertools import permutations, combinations",
"-from collections import defaultdict, Counter",
"+from itertools import product, permutations, combinations, combinations_with_replacement",
"+from math import sqrt, gcd, ceil, floor, factorial",
"-# from math import gcd,ceil,floor,factorial",
"+from statistics import mean, median, mode",
"+import sys",
"-",
"-def myinput():",
"- return list(map(int, input().split()))",
"-",
"-",
"-def mylistinput(n):",
"- return [list(myinput()) for _ in range(n)]",
"+sys.setrecursionlimit(10**6)",
"+INF = float(\"inf\")",
"-def mysort(data, col, reverse_flag):",
"- data.sort(key=lambda x: x[col], reverse=reverse_flag)",
"+def mysort(data, col, reverse=False):",
"+ data.sort(key=lambda x: x[col], reverse=revese)",
"+",
"+",
"+def mycount(ls, x):",
"+ # lsはソート済みであること",
"+ l = bisect_left(ls, x)",
"+ r = bisect_right(ls, x)",
"+ return r - l",
"+",
"+",
"+def mydictvaluesort(dictionary):",
"+ return sorted(list(dictionary.items()), key=lambda x: x[1])",
"+",
"+",
"+def mydictkeysort(dictionary):",
"+ return sorted(list(dictionary.items()), key=lambda x: x[0])",
"-H, N = myinput()",
"-AB = mylistinput(N)",
"-# dp[i]: 敵の体力をiだけ減らすとしたときの,消耗魔力累計値の最小値",
"-dp = [float(\"inf\")] * (H + 1)",
"-dp[0] = 0",
"-for i in range(1, H + 1):",
"- for j in range(N):",
"- a = AB[j][0]",
"- b = AB[j][1]",
"- if i < a:",
"- dp[i] = min(dp[i], dp[0] + b)",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def RI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def CI(n):",
"+ return [int(eval(input())) for _ in range(n)]",
"+",
"+",
"+def LI(n):",
"+ return [list(map(int, input().split())) for _ in range(n)]",
"+",
"+",
"+def S():",
"+ return eval(input())",
"+",
"+",
"+def MS():",
"+ return input().split()",
"+",
"+",
"+def RS():",
"+ return list(eval(input()))",
"+",
"+",
"+def CS(n):",
"+ return [eval(input()) for _ in range(n)]",
"+",
"+",
"+def LS(n):",
"+ return [list(eval(input())) for _ in range(n)]",
"+",
"+",
"+# ddict = defaultdict(lambda: 0)",
"+# ddict = defaultdict(lambda: 1)",
"+# ddict = defaultdict(lambda: int())",
"+# ddict = defaultdict(lambda: list())",
"+# ddict = defaultdict(lambda: float())",
"+h, n = MI()",
"+ab = LI(n)",
"+# dp[i][j]:i番目までの魔法の中から削る体力がj以上になるように選んだ時の消耗魔力の最小値",
"+dp = [[INF] * (h + 1) for _ in range(n + 1)]",
"+dp[0][0] = 0",
"+for i in range(n):",
"+ a = ab[i][0]",
"+ b = ab[i][1]",
"+ for j in range(h + 1):",
"+ if j < a:",
"+ dp[i + 1][j] = min(dp[i][j], b)",
"- dp[i] = min(dp[i], dp[i - a] + b)",
"+ dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a] + b)",
"-ans = dp[H]",
"-print(ans)",
"+print((dp[n][h]))"
]
| false | 0.0868 | 0.124106 | 0.699402 | [
"s106901311",
"s275556396"
]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.