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
sequence | 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
sequence |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u073852194 | p03283 | python | s890834094 | s757154999 | 1,449 | 510 | 111,192 | 55,516 | Accepted | Accepted | 64.8 | N,M,Q = list(map(int,input().split()))
Train = [list(map(int,input().split())) for i in range(M)]
Query = [list(map(int,input().split())) for i in range(Q)]
City = [[0]*N for i in range(N)]
Accum = [[0]*(N+1) for i in range(N+1)]
for train in Train:
City[train[0]-1][train[1]-1] += 1
for i in range(N):
for j in range(N):
Accum[i+1][j+1] = Accum[i+1][j] + City[i][j]
for j in range(N):
for i in range(N):
Accum[i+1][j+1] += Accum[i][j+1]
for query in Query:
print((
Accum[query[1]][query[1]]
- Accum[query[1]][query[0]-1]
- Accum[query[0]-1][query[1]]
+ Accum[query[0]-1][query[0]-1]
)) | import sys
input = sys.stdin.readline
N, M, Q = list(map(int, input().split()))
D = [[0 for j in range(N)] for i in range(N)]
for _ in range(M):
l, r = list(map(int, input().split()))
D[l - 1][r - 1] += 1
for i in range(N):
for j in range(1, N):
D[i][j] += D[i][j - 1]
for j in range(N):
for i in range(N - 1)[::-1]:
D[i][j] += D[i + 1][j]
for _ in range(Q):
p, q = list(map(int, input().split()))
print((D[p - 1][q - 1])) | 24 | 22 | 635 | 469 | N, M, Q = list(map(int, input().split()))
Train = [list(map(int, input().split())) for i in range(M)]
Query = [list(map(int, input().split())) for i in range(Q)]
City = [[0] * N for i in range(N)]
Accum = [[0] * (N + 1) for i in range(N + 1)]
for train in Train:
City[train[0] - 1][train[1] - 1] += 1
for i in range(N):
for j in range(N):
Accum[i + 1][j + 1] = Accum[i + 1][j] + City[i][j]
for j in range(N):
for i in range(N):
Accum[i + 1][j + 1] += Accum[i][j + 1]
for query in Query:
print(
(
Accum[query[1]][query[1]]
- Accum[query[1]][query[0] - 1]
- Accum[query[0] - 1][query[1]]
+ Accum[query[0] - 1][query[0] - 1]
)
)
| import sys
input = sys.stdin.readline
N, M, Q = list(map(int, input().split()))
D = [[0 for j in range(N)] for i in range(N)]
for _ in range(M):
l, r = list(map(int, input().split()))
D[l - 1][r - 1] += 1
for i in range(N):
for j in range(1, N):
D[i][j] += D[i][j - 1]
for j in range(N):
for i in range(N - 1)[::-1]:
D[i][j] += D[i + 1][j]
for _ in range(Q):
p, q = list(map(int, input().split()))
print((D[p - 1][q - 1]))
| false | 8.333333 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"-Train = [list(map(int, input().split())) for i in range(M)]",
"-Query = [list(map(int, input().split())) for i in range(Q)]",
"-City = [[0] * N for i in range(N)]",
"-Accum = [[0] * (N + 1) for i in range(N + 1)]",
"-for train in Train:",
"- City[train[0] - 1][train[1] - 1] += 1",
"+D = [[0 for j in range(N)] for i in range(N)]",
"+for _ in range(M):",
"+ l, r = list(map(int, input().split()))",
"+ D[l - 1][r - 1] += 1",
"- for j in range(N):",
"- Accum[i + 1][j + 1] = Accum[i + 1][j] + City[i][j]",
"+ for j in range(1, N):",
"+ D[i][j] += D[i][j - 1]",
"- for i in range(N):",
"- Accum[i + 1][j + 1] += Accum[i][j + 1]",
"-for query in Query:",
"- print(",
"- (",
"- Accum[query[1]][query[1]]",
"- - Accum[query[1]][query[0] - 1]",
"- - Accum[query[0] - 1][query[1]]",
"- + Accum[query[0] - 1][query[0] - 1]",
"- )",
"- )",
"+ for i in range(N - 1)[::-1]:",
"+ D[i][j] += D[i + 1][j]",
"+for _ in range(Q):",
"+ p, q = list(map(int, input().split()))",
"+ print((D[p - 1][q - 1]))"
] | false | 0.110835 | 0.037779 | 2.933776 | [
"s890834094",
"s757154999"
] |
u600402037 | p03722 | python | s006774591 | s638795833 | 592 | 208 | 3,316 | 14,072 | Accepted | Accepted | 64.86 | N, M = list(map(int, input().split()))
edges = []
for i in range(M):
a, b, c = list(map(int, input().split()))
edges.append((a, b, c))
edges.sort()
def bellmanford(n, edges, start):
INF = float('inf')
dist = [-INF] * (n+1) # dist[0]は使わない
dist[start] = 0
for i in range(n):
for (pre, ne, weight) in edges:
if dist[pre] != -INF and dist[pre] + weight > dist[ne]:
dist[ne] = dist[pre] + weight
if i == n-1 and ne == n:
return 'inf'
return dist[n]
answer = bellmanford(N, edges, 1)
print(answer) | # D - Score Attack
import sys
sys.setrecursionlimit(10 ** 9)
import numpy as np
from heapq import heappush, heappop
N, M, = list(map(int, input().split()))
graph = [[] for _ in range(N+1)] # graph[0]は使わない
for _ in range(M):
a, b, c = list(map(int, input().split()))
graph[a].append((b, c))
def dijkstra(start, c):
INF = float('inf')
dist = [-INF] * (N+1) # dist[0]は使わない
dist[start] = 0
que = [(start, 0, c)]
while que:
place, score, count = heappop(que) # placeは現在地
if score < dist[place] or count > 2000: # 前来た時より点数が悪いか、無限ループしている場合continue
continue
for next_node, weight in graph[place]:
score2 = score + weight
if next_node == N and count > 1000: # いくらでも大きくなる場合
print('inf')
exit()
if dist[next_node] < score2: # 点数が良くなるなら、データを更新
dist[next_node] = score2
heappush(que, (next_node, score2, count+1))
return dist
d1 = np.array(dijkstra(1, 0))
print((int(d1[N]))) | 22 | 35 | 603 | 1,055 | N, M = list(map(int, input().split()))
edges = []
for i in range(M):
a, b, c = list(map(int, input().split()))
edges.append((a, b, c))
edges.sort()
def bellmanford(n, edges, start):
INF = float("inf")
dist = [-INF] * (n + 1) # dist[0]は使わない
dist[start] = 0
for i in range(n):
for (pre, ne, weight) in edges:
if dist[pre] != -INF and dist[pre] + weight > dist[ne]:
dist[ne] = dist[pre] + weight
if i == n - 1 and ne == n:
return "inf"
return dist[n]
answer = bellmanford(N, edges, 1)
print(answer)
| # D - Score Attack
import sys
sys.setrecursionlimit(10**9)
import numpy as np
from heapq import heappush, heappop
(
N,
M,
) = list(map(int, input().split()))
graph = [[] for _ in range(N + 1)] # graph[0]は使わない
for _ in range(M):
a, b, c = list(map(int, input().split()))
graph[a].append((b, c))
def dijkstra(start, c):
INF = float("inf")
dist = [-INF] * (N + 1) # dist[0]は使わない
dist[start] = 0
que = [(start, 0, c)]
while que:
place, score, count = heappop(que) # placeは現在地
if score < dist[place] or count > 2000: # 前来た時より点数が悪いか、無限ループしている場合continue
continue
for next_node, weight in graph[place]:
score2 = score + weight
if next_node == N and count > 1000: # いくらでも大きくなる場合
print("inf")
exit()
if dist[next_node] < score2: # 点数が良くなるなら、データを更新
dist[next_node] = score2
heappush(que, (next_node, score2, count + 1))
return dist
d1 = np.array(dijkstra(1, 0))
print((int(d1[N])))
| false | 37.142857 | [
"-N, M = list(map(int, input().split()))",
"-edges = []",
"-for i in range(M):",
"+# D - Score Attack",
"+import sys",
"+",
"+sys.setrecursionlimit(10**9)",
"+import numpy as np",
"+from heapq import heappush, heappop",
"+",
"+(",
"+ N,",
"+ M,",
"+) = list(map(int, input().split()))",
"+graph = [[] for _ in range(N + 1)] # graph[0]は使わない",
"+for _ in range(M):",
"- edges.append((a, b, c))",
"-edges.sort()",
"+ graph[a].append((b, c))",
"-def bellmanford(n, edges, start):",
"+def dijkstra(start, c):",
"- dist = [-INF] * (n + 1) # dist[0]は使わない",
"+ dist = [-INF] * (N + 1) # dist[0]は使わない",
"- for i in range(n):",
"- for (pre, ne, weight) in edges:",
"- if dist[pre] != -INF and dist[pre] + weight > dist[ne]:",
"- dist[ne] = dist[pre] + weight",
"- if i == n - 1 and ne == n:",
"- return \"inf\"",
"- return dist[n]",
"+ que = [(start, 0, c)]",
"+ while que:",
"+ place, score, count = heappop(que) # placeは現在地",
"+ if score < dist[place] or count > 2000: # 前来た時より点数が悪いか、無限ループしている場合continue",
"+ continue",
"+ for next_node, weight in graph[place]:",
"+ score2 = score + weight",
"+ if next_node == N and count > 1000: # いくらでも大きくなる場合",
"+ print(\"inf\")",
"+ exit()",
"+ if dist[next_node] < score2: # 点数が良くなるなら、データを更新",
"+ dist[next_node] = score2",
"+ heappush(que, (next_node, score2, count + 1))",
"+ return dist",
"-answer = bellmanford(N, edges, 1)",
"-print(answer)",
"+d1 = np.array(dijkstra(1, 0))",
"+print((int(d1[N])))"
] | false | 0.036684 | 0.195498 | 0.187646 | [
"s006774591",
"s638795833"
] |
u766926358 | p02360 | python | s868965210 | s201940832 | 710 | 560 | 35,820 | 13,648 | Accepted | Accepted | 21.13 | from itertools import accumulate
N = int(eval(input()))
xys = []
m_x = 0
m_y = 0
for i in range(N):
xy = list(map(int, input().split()))
xys += [xy]
x_1,y_1,x_2,y_2 = xy
m_x = max(x_2, m_x)
m_y = max(y_2, m_y)
im = [[0]*(m_x+1) for i in range(m_y+1)]
for xy in xys:
x_1,y_1,x_2,y_2 = xy
im[y_1][x_1] += 1
im[y_1][x_2] -= 1
im[y_2][x_1] -= 1
im[y_2][x_2] += 1
print((max(list(map(max, list(map(accumulate, list(zip(*list(map(accumulate, im)))))))))))
| from itertools import accumulate
im = [[0]*1001 for i in range(1001)]
for x_1, y_1, x_2, y_2 in (list(map(int, input().split())) for _ in range(int(eval(input())))):
im[x_1][y_1] += 1
im[x_1][y_2] -= 1
im[x_2][y_1] -= 1
im[x_2][y_2] += 1
print((max(list(map(max, list(map(accumulate, list(zip(*list(map(accumulate, im)))))))))))
| 25 | 8 | 458 | 302 | from itertools import accumulate
N = int(eval(input()))
xys = []
m_x = 0
m_y = 0
for i in range(N):
xy = list(map(int, input().split()))
xys += [xy]
x_1, y_1, x_2, y_2 = xy
m_x = max(x_2, m_x)
m_y = max(y_2, m_y)
im = [[0] * (m_x + 1) for i in range(m_y + 1)]
for xy in xys:
x_1, y_1, x_2, y_2 = xy
im[y_1][x_1] += 1
im[y_1][x_2] -= 1
im[y_2][x_1] -= 1
im[y_2][x_2] += 1
print(
(max(list(map(max, list(map(accumulate, list(zip(*list(map(accumulate, im))))))))))
)
| from itertools import accumulate
im = [[0] * 1001 for i in range(1001)]
for x_1, y_1, x_2, y_2 in (
list(map(int, input().split())) for _ in range(int(eval(input())))
):
im[x_1][y_1] += 1
im[x_1][y_2] -= 1
im[x_2][y_1] -= 1
im[x_2][y_2] += 1
print(
(max(list(map(max, list(map(accumulate, list(zip(*list(map(accumulate, im))))))))))
)
| false | 68 | [
"-N = int(eval(input()))",
"-xys = []",
"-m_x = 0",
"-m_y = 0",
"-for i in range(N):",
"- xy = list(map(int, input().split()))",
"- xys += [xy]",
"- x_1, y_1, x_2, y_2 = xy",
"- m_x = max(x_2, m_x)",
"- m_y = max(y_2, m_y)",
"-im = [[0] * (m_x + 1) for i in range(m_y + 1)]",
"-for xy in xys:",
"- x_1, y_1, x_2, y_2 = xy",
"- im[y_1][x_1] += 1",
"- im[y_1][x_2] -= 1",
"- im[y_2][x_1] -= 1",
"- im[y_2][x_2] += 1",
"+im = [[0] * 1001 for i in range(1001)]",
"+for x_1, y_1, x_2, y_2 in (",
"+ list(map(int, input().split())) for _ in range(int(eval(input())))",
"+):",
"+ im[x_1][y_1] += 1",
"+ im[x_1][y_2] -= 1",
"+ im[x_2][y_1] -= 1",
"+ im[x_2][y_2] += 1"
] | false | 0.169087 | 0.190213 | 0.888936 | [
"s868965210",
"s201940832"
] |
u347640436 | p02900 | python | s072052095 | s849717734 | 130 | 82 | 5,176 | 5,172 | Accepted | Accepted | 36.92 | from fractions import gcd
from math import sqrt
def prime_factorize(n):
result = []
for i in range(2, int(sqrt(n)) + 1):
if n % i != 0:
continue
t = 0
while n % i == 0:
n //= i
t += 1
result.append((i, t))
if n == 1:
break
if n != 1:
result.append((n, 1))
return result
A, B = list(map(int, input().split()))
print((len(prime_factorize(gcd(A, B))) + 1))
| from fractions import gcd
def prime_factorize(n):
result = []
if n % 2 == 0:
t = 0
while n % 2 == 0:
n //= 2
t += 1
result.append((2, t))
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i != 0:
continue
t = 0
while n % i == 0:
n //= i
t += 1
result.append((i, t))
if n == 1:
break
if n != 1:
result.append((n, 1))
return result
A, B = list(map(int, input().split()))
print((len(prime_factorize(gcd(A, B))) + 1))
| 23 | 29 | 484 | 601 | from fractions import gcd
from math import sqrt
def prime_factorize(n):
result = []
for i in range(2, int(sqrt(n)) + 1):
if n % i != 0:
continue
t = 0
while n % i == 0:
n //= i
t += 1
result.append((i, t))
if n == 1:
break
if n != 1:
result.append((n, 1))
return result
A, B = list(map(int, input().split()))
print((len(prime_factorize(gcd(A, B))) + 1))
| from fractions import gcd
def prime_factorize(n):
result = []
if n % 2 == 0:
t = 0
while n % 2 == 0:
n //= 2
t += 1
result.append((2, t))
for i in range(3, int(n**0.5) + 1, 2):
if n % i != 0:
continue
t = 0
while n % i == 0:
n //= i
t += 1
result.append((i, t))
if n == 1:
break
if n != 1:
result.append((n, 1))
return result
A, B = list(map(int, input().split()))
print((len(prime_factorize(gcd(A, B))) + 1))
| false | 20.689655 | [
"-from math import sqrt",
"- for i in range(2, int(sqrt(n)) + 1):",
"+ if n % 2 == 0:",
"+ t = 0",
"+ while n % 2 == 0:",
"+ n //= 2",
"+ t += 1",
"+ result.append((2, t))",
"+ for i in range(3, int(n**0.5) + 1, 2):"
] | false | 0.063173 | 0.051635 | 1.223454 | [
"s072052095",
"s849717734"
] |
u297574184 | p02792 | python | s536292692 | s932029920 | 325 | 154 | 3,064 | 3,064 | Accepted | Accepted | 52.62 | def solve():
N = int(eval(input()))
numss = [[0]*(10) for _ in range(10)]
for A in range(1, N+1):
ss = str(A)
numss[int(ss[-1])][int(ss[0])] += 1
ans = 0
for A in range(1, N+1):
ss = str(A)
ans += numss[int(ss[0])][int(ss[-1])]
print(ans)
solve()
| def solve():
strN = eval(input())
N = int(strN)
maxD = len(strN)
numss = [[0]*(10) for _ in range(10)]
for x in range(1, 10):
for y in range(1, 10):
num = 0
for d in range(1, maxD-2):
num += 10**d
if maxD-2 > 0:
if x < int(strN[0]):
num += 10**(maxD-2)
elif x == int(strN[0]):
num += int(strN[1:-1]) + 1
if y > int(strN[-1]):
num -= 1
j = x*10 + y
if 1 <= j <= N:
num += 1
if x == y:
j = x
if 1 <= j <= N:
num += 1
numss[x][y] = num
ans = 0
for A in range(1, N+1):
ss = str(A)
ans += numss[int(ss[-1])][int(ss[0])]
print(ans)
solve()
| 16 | 37 | 316 | 910 | def solve():
N = int(eval(input()))
numss = [[0] * (10) for _ in range(10)]
for A in range(1, N + 1):
ss = str(A)
numss[int(ss[-1])][int(ss[0])] += 1
ans = 0
for A in range(1, N + 1):
ss = str(A)
ans += numss[int(ss[0])][int(ss[-1])]
print(ans)
solve()
| def solve():
strN = eval(input())
N = int(strN)
maxD = len(strN)
numss = [[0] * (10) for _ in range(10)]
for x in range(1, 10):
for y in range(1, 10):
num = 0
for d in range(1, maxD - 2):
num += 10**d
if maxD - 2 > 0:
if x < int(strN[0]):
num += 10 ** (maxD - 2)
elif x == int(strN[0]):
num += int(strN[1:-1]) + 1
if y > int(strN[-1]):
num -= 1
j = x * 10 + y
if 1 <= j <= N:
num += 1
if x == y:
j = x
if 1 <= j <= N:
num += 1
numss[x][y] = num
ans = 0
for A in range(1, N + 1):
ss = str(A)
ans += numss[int(ss[-1])][int(ss[0])]
print(ans)
solve()
| false | 56.756757 | [
"- N = int(eval(input()))",
"+ strN = eval(input())",
"+ N = int(strN)",
"+ maxD = len(strN)",
"- for A in range(1, N + 1):",
"- ss = str(A)",
"- numss[int(ss[-1])][int(ss[0])] += 1",
"+ for x in range(1, 10):",
"+ for y in range(1, 10):",
"+ num = 0",
"+ for d in range(1, maxD - 2):",
"+ num += 10**d",
"+ if maxD - 2 > 0:",
"+ if x < int(strN[0]):",
"+ num += 10 ** (maxD - 2)",
"+ elif x == int(strN[0]):",
"+ num += int(strN[1:-1]) + 1",
"+ if y > int(strN[-1]):",
"+ num -= 1",
"+ j = x * 10 + y",
"+ if 1 <= j <= N:",
"+ num += 1",
"+ if x == y:",
"+ j = x",
"+ if 1 <= j <= N:",
"+ num += 1",
"+ numss[x][y] = num",
"- ans += numss[int(ss[0])][int(ss[-1])]",
"+ ans += numss[int(ss[-1])][int(ss[0])]"
] | false | 0.151459 | 0.088413 | 1.713093 | [
"s536292692",
"s932029920"
] |
u847467233 | p00447 | python | s045923645 | s192912947 | 980 | 70 | 5,620 | 5,724 | Accepted | Accepted | 92.86 | # AOJ 0524: Searching Constellation
# Python3 2018.7.1 bal4u
def check(dx, dy):
f = True
for x, y in goal:
if (x+dx, y+dy) not in star:
f = False
break
return f
while True:
m = int(eval(input()))
if m == 0: break
goal, star = [], []
for i in range(m):
x, y = list(map(int, input().split()))
goal.append((x, y))
for i in range(int(eval(input()))):
x, y = list(map(int, input().split()))
star.append((x, y))
for x, y in star:
dx, dy = x-goal[0][0], y-goal[0][1]
if check(dx, dy): break
print((dx, dy))
| # AOJ 0524: Searching Constellation
# Python3 2018.7.1 bal4u
def check(dx, dy):
f = True
for x, y in goal:
if (x+dx, y+dy) not in tbl:
f = False
break
return f
while True:
m = int(eval(input()))
if m == 0: break
goal, star, tbl = [], [], {}
for i in range(m):
goal.append(tuple(map(int, input().split())))
for i in range(int(eval(input()))):
x, y = list(map(int, input().split()))
star.append((x, y))
tbl[x,y] = 1
for x, y in star:
dx, dy = x-goal[0][0], y-goal[0][1]
if check(dx, dy): break
print((dx, dy))
| 25 | 25 | 531 | 545 | # AOJ 0524: Searching Constellation
# Python3 2018.7.1 bal4u
def check(dx, dy):
f = True
for x, y in goal:
if (x + dx, y + dy) not in star:
f = False
break
return f
while True:
m = int(eval(input()))
if m == 0:
break
goal, star = [], []
for i in range(m):
x, y = list(map(int, input().split()))
goal.append((x, y))
for i in range(int(eval(input()))):
x, y = list(map(int, input().split()))
star.append((x, y))
for x, y in star:
dx, dy = x - goal[0][0], y - goal[0][1]
if check(dx, dy):
break
print((dx, dy))
| # AOJ 0524: Searching Constellation
# Python3 2018.7.1 bal4u
def check(dx, dy):
f = True
for x, y in goal:
if (x + dx, y + dy) not in tbl:
f = False
break
return f
while True:
m = int(eval(input()))
if m == 0:
break
goal, star, tbl = [], [], {}
for i in range(m):
goal.append(tuple(map(int, input().split())))
for i in range(int(eval(input()))):
x, y = list(map(int, input().split()))
star.append((x, y))
tbl[x, y] = 1
for x, y in star:
dx, dy = x - goal[0][0], y - goal[0][1]
if check(dx, dy):
break
print((dx, dy))
| false | 0 | [
"- if (x + dx, y + dy) not in star:",
"+ if (x + dx, y + dy) not in tbl:",
"- goal, star = [], []",
"+ goal, star, tbl = [], [], {}",
"- x, y = list(map(int, input().split()))",
"- goal.append((x, y))",
"+ goal.append(tuple(map(int, input().split())))",
"+ tbl[x, y] = 1"
] | false | 0.111816 | 0.037761 | 2.961114 | [
"s045923645",
"s192912947"
] |
u562935282 | p02972 | python | s735737062 | s928418824 | 1,109 | 479 | 77,180 | 14,132 | Accepted | Accepted | 56.81 | import sys
input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int, input().split()))
a = [None] + a
a = tuple(a)
ans = set()
cnt = [0] * (n + 1)
for i in range(n, 0, -1):
if cnt[i] % 2 != a[i] % 2:
ans.add(i)
st = set()
j = 1
while j * j <= i:
if i % j == 0:
st.add(j)
st.add(i // j)
j += 1
for d in st:
cnt[d] += 1
print((len(ans)))
print((*ans))
| def main():
N = int(input())
a = [0]
a += map(int, input().split())
b = [0] * (N + 1)
x = N
k = 1
while x > 0:
while x * (k + 1) > N:
t = 0
for j in range(2, k + 1):
t ^= b[x * j]
b[x] = a[x] ^ t
x -= 1
k += 1
ans = [i for i, x in enumerate(b) if x == 1]
print(len(ans))
print(*ans, sep='\n')
if __name__ == '__main__':
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
# while abs(ok - ng) > 1:
# mid = (ok + ng) // 2
# if func(mid):
# ok = mid
# else:
# ng = mid
# return ok
| 28 | 43 | 495 | 833 | import sys
input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int, input().split()))
a = [None] + a
a = tuple(a)
ans = set()
cnt = [0] * (n + 1)
for i in range(n, 0, -1):
if cnt[i] % 2 != a[i] % 2:
ans.add(i)
st = set()
j = 1
while j * j <= i:
if i % j == 0:
st.add(j)
st.add(i // j)
j += 1
for d in st:
cnt[d] += 1
print((len(ans)))
print((*ans))
| def main():
N = int(input())
a = [0]
a += map(int, input().split())
b = [0] * (N + 1)
x = N
k = 1
while x > 0:
while x * (k + 1) > N:
t = 0
for j in range(2, k + 1):
t ^= b[x * j]
b[x] = a[x] ^ t
x -= 1
k += 1
ans = [i for i, x in enumerate(b) if x == 1]
print(len(ans))
print(*ans, sep="\n")
if __name__ == "__main__":
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
# while abs(ok - ng) > 1:
# mid = (ok + ng) // 2
# if func(mid):
# ok = mid
# else:
# ng = mid
# return ok
| false | 34.883721 | [
"-import sys",
"+def main():",
"+ N = int(input())",
"+ a = [0]",
"+ a += map(int, input().split())",
"+ b = [0] * (N + 1)",
"+ x = N",
"+ k = 1",
"+ while x > 0:",
"+ while x * (k + 1) > N:",
"+ t = 0",
"+ for j in range(2, k + 1):",
"+ t ^= b[x * j]",
"+ b[x] = a[x] ^ t",
"+ x -= 1",
"+ k += 1",
"+ ans = [i for i, x in enumerate(b) if x == 1]",
"+ print(len(ans))",
"+ print(*ans, sep=\"\\n\")",
"-input = sys.stdin.readline",
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-a = [None] + a",
"-a = tuple(a)",
"-ans = set()",
"-cnt = [0] * (n + 1)",
"-for i in range(n, 0, -1):",
"- if cnt[i] % 2 != a[i] % 2:",
"- ans.add(i)",
"- st = set()",
"- j = 1",
"- while j * j <= i:",
"- if i % j == 0:",
"- st.add(j)",
"- st.add(i // j)",
"- j += 1",
"- for d in st:",
"- cnt[d] += 1",
"-print((len(ans)))",
"-print((*ans))",
"+",
"+if __name__ == \"__main__\":",
"+ main()",
"+# import sys",
"+# input = sys.stdin.readline",
"+#",
"+# sys.setrecursionlimit(10 ** 7)",
"+#",
"+# (int(x)-1 for x in input().split())",
"+# rstrip()",
"+#",
"+# def binary_search(*, ok, ng, func):",
"+# while abs(ok - ng) > 1:",
"+# mid = (ok + ng) // 2",
"+# if func(mid):",
"+# ok = mid",
"+# else:",
"+# ng = mid",
"+# return ok"
] | false | 0.065196 | 0.036164 | 1.802797 | [
"s735737062",
"s928418824"
] |
u281303342 | p03457 | python | s480616531 | s254879491 | 437 | 247 | 27,380 | 28,080 | Accepted | Accepted | 43.48 | import sys
N = int(eval(input()))
TXY = [list(map(int,input().split())) for _ in range(N)]
t0,x0,y0 = 0,0,0
for i in range(N):
t,x,y = TXY[i][0],TXY[i][1],TXY[i][2]
if t-t0 >= abs(x-x0)+abs(y-y0) and (t-t0)%2 == abs(x-x0+y-y0)%2:
t0,x0,y0 = t,x,y
continue
else:
print("No")
sys.exit()
print("Yes") | # atcoder : python3 (3.4.3)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod = 10**9+7
# main
N = int(eval(input()))
TXY = [[0,0,0]]+[list(map(int,input().split())) for _ in range(N)]
ans = "Yes"
for i in range(N):
t0,x0,y0 = TXY[i]
t1,x1,y1 = TXY[i+1]
t = t1-t0
d = abs(x1-x0)+abs(y1-y0)
if t<d or d%2!=t%2:
ans = "No"
break
print(ans) | 16 | 21 | 353 | 411 | import sys
N = int(eval(input()))
TXY = [list(map(int, input().split())) for _ in range(N)]
t0, x0, y0 = 0, 0, 0
for i in range(N):
t, x, y = TXY[i][0], TXY[i][1], TXY[i][2]
if t - t0 >= abs(x - x0) + abs(y - y0) and (t - t0) % 2 == abs(x - x0 + y - y0) % 2:
t0, x0, y0 = t, x, y
continue
else:
print("No")
sys.exit()
print("Yes")
| # atcoder : python3 (3.4.3)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod = 10**9 + 7
# main
N = int(eval(input()))
TXY = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(N)]
ans = "Yes"
for i in range(N):
t0, x0, y0 = TXY[i]
t1, x1, y1 = TXY[i + 1]
t = t1 - t0
d = abs(x1 - x0) + abs(y1 - y0)
if t < d or d % 2 != t % 2:
ans = "No"
break
print(ans)
| false | 23.809524 | [
"+# atcoder : python3 (3.4.3)",
"+input = sys.stdin.readline",
"+sys.setrecursionlimit(10**6)",
"+mod = 10**9 + 7",
"+# main",
"-TXY = [list(map(int, input().split())) for _ in range(N)]",
"-t0, x0, y0 = 0, 0, 0",
"+TXY = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(N)]",
"+ans = \"Yes\"",
"- t, x, y = TXY[i][0], TXY[i][1], TXY[i][2]",
"- if t - t0 >= abs(x - x0) + abs(y - y0) and (t - t0) % 2 == abs(x - x0 + y - y0) % 2:",
"- t0, x0, y0 = t, x, y",
"- continue",
"- else:",
"- print(\"No\")",
"- sys.exit()",
"-print(\"Yes\")",
"+ t0, x0, y0 = TXY[i]",
"+ t1, x1, y1 = TXY[i + 1]",
"+ t = t1 - t0",
"+ d = abs(x1 - x0) + abs(y1 - y0)",
"+ if t < d or d % 2 != t % 2:",
"+ ans = \"No\"",
"+ break",
"+print(ans)"
] | false | 0.086602 | 0.040422 | 2.142453 | [
"s480616531",
"s254879491"
] |
u532966492 | p02992 | python | s477532812 | s897813005 | 1,628 | 1,492 | 16,020 | 11,600 | Accepted | Accepted | 8.35 | from itertools import accumulate
N,K=list(map(int,input().split()))
N_s=int(N**0.5)
list_a=[1]*N_s
list_b=[N//j-N_s for j in range(1,N_s+1)]
list_p=[N//j-N_s for j in range(1,N_s+1)]
for p in range(1,len(list_p)):
list_p[p-1]=list_p[p-1]-list_p[p]
for p in range(1,len(list_b)):
list_b[p-1]=list_b[p-1]-list_b[p]
list_bb=list(reversed(list(accumulate(reversed(list_b)))))
list_aa=list(accumulate(list_a))
mod=10**9+7
for i in range(K-1):
temp=sum(list_a)
list_an=[(temp+list_bb[j])%mod for j in range(N_s)]
list_bn=[(list_p[j-1]*list_aa[j-1])%mod for j in range(1,N_s+1)]
list_bbn=list(reversed(list(accumulate(reversed(list_bn)))))
list_aa=list(accumulate(list_an))
list_a=list_an
list_b=list_bn
list_bb=list_bbn
print(((sum(list_a)+sum(list_b))%mod)) | from itertools import accumulate as ac
N,K=list(map(int,input().split()))
n=int(N**0.5)
mod=10**9+7
list_a=[1]*n
list_b=[N//j-N//(j+1) for j in range(1,n)]+[(N//n-n)]
list_p=[p for p in list_b]
list_aa=list(ac(list_a))
list_bb=list(reversed(list(ac(reversed(list_b)))))
for i in range(K-1):
temp=sum(list_a)
list_a=[(temp+list_bb[j])%mod for j in range(n)]
list_b=[(list_p[j]*list_aa[j])%mod for j in range(n)]
list_aa=list(ac(list_a))
list_bb=list(reversed(list(ac(reversed(list_b)))))
print(((sum(list_a+list_b))%mod)) | 29 | 18 | 834 | 555 | from itertools import accumulate
N, K = list(map(int, input().split()))
N_s = int(N**0.5)
list_a = [1] * N_s
list_b = [N // j - N_s for j in range(1, N_s + 1)]
list_p = [N // j - N_s for j in range(1, N_s + 1)]
for p in range(1, len(list_p)):
list_p[p - 1] = list_p[p - 1] - list_p[p]
for p in range(1, len(list_b)):
list_b[p - 1] = list_b[p - 1] - list_b[p]
list_bb = list(reversed(list(accumulate(reversed(list_b)))))
list_aa = list(accumulate(list_a))
mod = 10**9 + 7
for i in range(K - 1):
temp = sum(list_a)
list_an = [(temp + list_bb[j]) % mod for j in range(N_s)]
list_bn = [(list_p[j - 1] * list_aa[j - 1]) % mod for j in range(1, N_s + 1)]
list_bbn = list(reversed(list(accumulate(reversed(list_bn)))))
list_aa = list(accumulate(list_an))
list_a = list_an
list_b = list_bn
list_bb = list_bbn
print(((sum(list_a) + sum(list_b)) % mod))
| from itertools import accumulate as ac
N, K = list(map(int, input().split()))
n = int(N**0.5)
mod = 10**9 + 7
list_a = [1] * n
list_b = [N // j - N // (j + 1) for j in range(1, n)] + [(N // n - n)]
list_p = [p for p in list_b]
list_aa = list(ac(list_a))
list_bb = list(reversed(list(ac(reversed(list_b)))))
for i in range(K - 1):
temp = sum(list_a)
list_a = [(temp + list_bb[j]) % mod for j in range(n)]
list_b = [(list_p[j] * list_aa[j]) % mod for j in range(n)]
list_aa = list(ac(list_a))
list_bb = list(reversed(list(ac(reversed(list_b)))))
print(((sum(list_a + list_b)) % mod))
| false | 37.931034 | [
"-from itertools import accumulate",
"+from itertools import accumulate as ac",
"-N_s = int(N**0.5)",
"-list_a = [1] * N_s",
"-list_b = [N // j - N_s for j in range(1, N_s + 1)]",
"-list_p = [N // j - N_s for j in range(1, N_s + 1)]",
"-for p in range(1, len(list_p)):",
"- list_p[p - 1] = list_p[p - 1] - list_p[p]",
"-for p in range(1, len(list_b)):",
"- list_b[p - 1] = list_b[p - 1] - list_b[p]",
"-list_bb = list(reversed(list(accumulate(reversed(list_b)))))",
"-list_aa = list(accumulate(list_a))",
"+n = int(N**0.5)",
"+list_a = [1] * n",
"+list_b = [N // j - N // (j + 1) for j in range(1, n)] + [(N // n - n)]",
"+list_p = [p for p in list_b]",
"+list_aa = list(ac(list_a))",
"+list_bb = list(reversed(list(ac(reversed(list_b)))))",
"- list_an = [(temp + list_bb[j]) % mod for j in range(N_s)]",
"- list_bn = [(list_p[j - 1] * list_aa[j - 1]) % mod for j in range(1, N_s + 1)]",
"- list_bbn = list(reversed(list(accumulate(reversed(list_bn)))))",
"- list_aa = list(accumulate(list_an))",
"- list_a = list_an",
"- list_b = list_bn",
"- list_bb = list_bbn",
"-print(((sum(list_a) + sum(list_b)) % mod))",
"+ list_a = [(temp + list_bb[j]) % mod for j in range(n)]",
"+ list_b = [(list_p[j] * list_aa[j]) % mod for j in range(n)]",
"+ list_aa = list(ac(list_a))",
"+ list_bb = list(reversed(list(ac(reversed(list_b)))))",
"+print(((sum(list_a + list_b)) % mod))"
] | false | 0.258856 | 0.419346 | 0.617286 | [
"s477532812",
"s897813005"
] |
u928254435 | p03448 | python | s285468827 | s134325040 | 52 | 46 | 3,064 | 3,064 | Accepted | Accepted | 11.54 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math
l = []
for _ in range(4):
l.append(int(eval(input())))
a, b, c, x = l
# 最大使用可能回数
a_c = min(a, math.floor(x / 500) if x >= 500 else 0 )
b_c = min(b, math.floor(x / 100) if x >= 100 else 0 )
c_c = min(c, math.floor(x / 50) if x >= 50 else 0 )
i, j, k, sum, cnt = [0] * 5
while (i <= a_c):
sum = x - 500 * i
if sum < 0:
break
if sum == 0:
cnt += 1
else:
while (j <= b_c):
sum = x - 500 * i - 100 * j
if sum < 0:
break
if sum == 0:
cnt += 1
else:
while (k <= c_c):
sum = x - 500 * i - 100 * j - 50 * k
if sum < 0:
break
if sum == 0:
cnt += 1
k += 1
k = 0
j += 1
j = 0
i += 1
print(cnt) | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math
l = []
for _ in range(4):
l.append(int(eval(input())))
a, b, c, x = l
# 最大使用可能回数
a_c = min(a, math.floor(x / 500) if x >= 500 else 0 )
b_c = min(b, math.floor(x / 100) if x >= 100 else 0 )
c_c = min(c, math.floor(x / 50) if x >= 50 else 0 )
sum, cnt = [0] * 2
for i in range(a_c + 1):
sum = x - 500 * i
if sum == 0:
cnt += 1
if sum <= 0:
break
for j in range(b_c + 1):
sum = x - 500 * i - 100 * j
if sum == 0:
cnt += 1
if sum <= 0:
break
for k in range(c_c + 1):
sum = x - 500 * i - 100 * j - 50 * k
if sum == 0:
cnt += 1
if sum <= 0:
break
print(cnt) | 46 | 34 | 845 | 724 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math
l = []
for _ in range(4):
l.append(int(eval(input())))
a, b, c, x = l
# 最大使用可能回数
a_c = min(a, math.floor(x / 500) if x >= 500 else 0)
b_c = min(b, math.floor(x / 100) if x >= 100 else 0)
c_c = min(c, math.floor(x / 50) if x >= 50 else 0)
i, j, k, sum, cnt = [0] * 5
while i <= a_c:
sum = x - 500 * i
if sum < 0:
break
if sum == 0:
cnt += 1
else:
while j <= b_c:
sum = x - 500 * i - 100 * j
if sum < 0:
break
if sum == 0:
cnt += 1
else:
while k <= c_c:
sum = x - 500 * i - 100 * j - 50 * k
if sum < 0:
break
if sum == 0:
cnt += 1
k += 1
k = 0
j += 1
j = 0
i += 1
print(cnt)
| #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math
l = []
for _ in range(4):
l.append(int(eval(input())))
a, b, c, x = l
# 最大使用可能回数
a_c = min(a, math.floor(x / 500) if x >= 500 else 0)
b_c = min(b, math.floor(x / 100) if x >= 100 else 0)
c_c = min(c, math.floor(x / 50) if x >= 50 else 0)
sum, cnt = [0] * 2
for i in range(a_c + 1):
sum = x - 500 * i
if sum == 0:
cnt += 1
if sum <= 0:
break
for j in range(b_c + 1):
sum = x - 500 * i - 100 * j
if sum == 0:
cnt += 1
if sum <= 0:
break
for k in range(c_c + 1):
sum = x - 500 * i - 100 * j - 50 * k
if sum == 0:
cnt += 1
if sum <= 0:
break
print(cnt)
| false | 26.086957 | [
"-i, j, k, sum, cnt = [0] * 5",
"-while i <= a_c:",
"+sum, cnt = [0] * 2",
"+for i in range(a_c + 1):",
"- if sum < 0:",
"- break",
"- else:",
"- while j <= b_c:",
"- sum = x - 500 * i - 100 * j",
"- if sum < 0:",
"- break",
"+ if sum <= 0:",
"+ break",
"+ for j in range(b_c + 1):",
"+ sum = x - 500 * i - 100 * j",
"+ if sum == 0:",
"+ cnt += 1",
"+ if sum <= 0:",
"+ break",
"+ for k in range(c_c + 1):",
"+ sum = x - 500 * i - 100 * j - 50 * k",
"- else:",
"- while k <= c_c:",
"- sum = x - 500 * i - 100 * j - 50 * k",
"- if sum < 0:",
"- break",
"- if sum == 0:",
"- cnt += 1",
"- k += 1",
"- k = 0",
"- j += 1",
"- j = 0",
"- i += 1",
"+ if sum <= 0:",
"+ break"
] | false | 0.050884 | 0.049139 | 1.035523 | [
"s285468827",
"s134325040"
] |
u254871849 | p03699 | python | s279325477 | s864606391 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | import sys
input = sys.stdin.readline
from itertools import combinations
N = int(input().rstrip())
score = [int(input().rstrip()) for _ in range(N)]
score.sort(reverse=1)
s_multiple_of_10 = [s for s in score if s % 10 == 0]
if len(s_multiple_of_10) == N: print((0))
s_not_multiple_of_10 = [s for s in score if s % 10 != 0]
# combinationsでも、先に10の倍数を除外してから処理したらどうだろう
for i in range(len(s_not_multiple_of_10), 0, -1):
for c in combinations(s_not_multiple_of_10, i):
if sum(c) % 10 == 0:
continue
else:
print((sum(c) + sum(s_multiple_of_10)))
exit()
| # import sys
# input = sys.stdin.readline
N, *score = [int(x) for x in open(0)]
a = sum(score)
print((max([a - s for s in score + [0] if (a - s) % 10] + [0])))
# 最後の行は、scoreのなかの何か一つの要素を合計から引いたときと何も引かなかったとき(+ [0]は何も引かない場合のため)を
# それぞれ10で割ったあまりが0でない(0の論理値はFalse, 1以上の論理値はTrue) 物の中から最大値を出力する
# ややこしいが、もしaが10の倍数だった場合、scoreの要素がすべて10の倍数だったら最後の + [0] があることで
# 0が出力され、そうではいなら少なくとも二つ以上は10の倍数ではない要素が存在するので、
# そのうち一つでもaから引いてしまえばそれは10の倍数ではなくなる。
# これを満たす物の中から最大値を出力すれば良いというわけだ
| 21 | 13 | 630 | 476 | import sys
input = sys.stdin.readline
from itertools import combinations
N = int(input().rstrip())
score = [int(input().rstrip()) for _ in range(N)]
score.sort(reverse=1)
s_multiple_of_10 = [s for s in score if s % 10 == 0]
if len(s_multiple_of_10) == N:
print((0))
s_not_multiple_of_10 = [s for s in score if s % 10 != 0]
# combinationsでも、先に10の倍数を除外してから処理したらどうだろう
for i in range(len(s_not_multiple_of_10), 0, -1):
for c in combinations(s_not_multiple_of_10, i):
if sum(c) % 10 == 0:
continue
else:
print((sum(c) + sum(s_multiple_of_10)))
exit()
| # import sys
# input = sys.stdin.readline
N, *score = [int(x) for x in open(0)]
a = sum(score)
print((max([a - s for s in score + [0] if (a - s) % 10] + [0])))
# 最後の行は、scoreのなかの何か一つの要素を合計から引いたときと何も引かなかったとき(+ [0]は何も引かない場合のため)を
# それぞれ10で割ったあまりが0でない(0の論理値はFalse, 1以上の論理値はTrue) 物の中から最大値を出力する
# ややこしいが、もしaが10の倍数だった場合、scoreの要素がすべて10の倍数だったら最後の + [0] があることで
# 0が出力され、そうではいなら少なくとも二つ以上は10の倍数ではない要素が存在するので、
# そのうち一つでもaから引いてしまえばそれは10の倍数ではなくなる。
# これを満たす物の中から最大値を出力すれば良いというわけだ
| false | 38.095238 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-from itertools import combinations",
"-",
"-N = int(input().rstrip())",
"-score = [int(input().rstrip()) for _ in range(N)]",
"-score.sort(reverse=1)",
"-s_multiple_of_10 = [s for s in score if s % 10 == 0]",
"-if len(s_multiple_of_10) == N:",
"- print((0))",
"-s_not_multiple_of_10 = [s for s in score if s % 10 != 0]",
"-# combinationsでも、先に10の倍数を除外してから処理したらどうだろう",
"-for i in range(len(s_not_multiple_of_10), 0, -1):",
"- for c in combinations(s_not_multiple_of_10, i):",
"- if sum(c) % 10 == 0:",
"- continue",
"- else:",
"- print((sum(c) + sum(s_multiple_of_10)))",
"- exit()",
"+# import sys",
"+# input = sys.stdin.readline",
"+N, *score = [int(x) for x in open(0)]",
"+a = sum(score)",
"+print((max([a - s for s in score + [0] if (a - s) % 10] + [0])))",
"+# 最後の行は、scoreのなかの何か一つの要素を合計から引いたときと何も引かなかったとき(+ [0]は何も引かない場合のため)を",
"+# それぞれ10で割ったあまりが0でない(0の論理値はFalse, 1以上の論理値はTrue) 物の中から最大値を出力する",
"+# ややこしいが、もしaが10の倍数だった場合、scoreの要素がすべて10の倍数だったら最後の + [0] があることで",
"+# 0が出力され、そうではいなら少なくとも二つ以上は10の倍数ではない要素が存在するので、",
"+# そのうち一つでもaから引いてしまえばそれは10の倍数ではなくなる。",
"+# これを満たす物の中から最大値を出力すれば良いというわけだ"
] | false | 0.138013 | 0.055183 | 2.501027 | [
"s279325477",
"s864606391"
] |
u811733736 | p00181 | python | s099853180 | s528439627 | 50 | 40 | 7,744 | 7,768 | Accepted | Accepted | 20 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181
"""
import sys
from sys import stdin
input = stdin.readline
def Cond(m, n, mid, books):
if max(books) > mid:
return False
rem = mid
while books:
while rem >= books[0]:
rem -= books[0]
books = books[1:]
if len(books) == 0:
break
rem = mid
m -= 1
if m < 0:
return False
return True
def solve(m, n, books):
ub = 1500000
lb = max(books)
min_width = float('inf')
for i in range(30):
mid = (ub + lb) // 2
if Cond(m, n, mid, books):
min_width = min(min_width, mid)
ub = mid
else:
lb = mid
return min_width
def main(args):
while True:
m, n = list(map(int, input().split()))
if m == 0 and n == 0:
break
books = [int(eval(input())) for _ in range(n)]
result = solve(m, n, books)
print(result)
if __name__ == '__main__':
main(sys.argv[1:])
| # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181
"""
import sys
from sys import stdin
input = stdin.readline
def Cond(m, n, mid, books):
rem = mid
i = 0
while True:
while rem >= books[i]:
rem -= books[i]
i += 1
if i == n:
break
rem = mid
m -= 1
if i == n:
break
if m < 0:
return False
else:
return True
def solve(m, n, books):
ub = 1500000
lb = max(books)
min_width = float('inf')
for i in range(30):
mid = (ub + lb) // 2
if Cond(m, n, mid, books):
min_width = min(min_width, mid)
ub = mid
else:
lb = mid
return min_width
def main(args):
while True:
m, n = list(map(int, input().split()))
if m == 0 and n == 0:
break
books = [int(eval(input())) for _ in range(n)]
result = solve(m, n, books)
print(result)
if __name__ == '__main__':
main(sys.argv[1:]) | 57 | 58 | 1,147 | 1,121 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181
"""
import sys
from sys import stdin
input = stdin.readline
def Cond(m, n, mid, books):
if max(books) > mid:
return False
rem = mid
while books:
while rem >= books[0]:
rem -= books[0]
books = books[1:]
if len(books) == 0:
break
rem = mid
m -= 1
if m < 0:
return False
return True
def solve(m, n, books):
ub = 1500000
lb = max(books)
min_width = float("inf")
for i in range(30):
mid = (ub + lb) // 2
if Cond(m, n, mid, books):
min_width = min(min_width, mid)
ub = mid
else:
lb = mid
return min_width
def main(args):
while True:
m, n = list(map(int, input().split()))
if m == 0 and n == 0:
break
books = [int(eval(input())) for _ in range(n)]
result = solve(m, n, books)
print(result)
if __name__ == "__main__":
main(sys.argv[1:])
| # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181
"""
import sys
from sys import stdin
input = stdin.readline
def Cond(m, n, mid, books):
rem = mid
i = 0
while True:
while rem >= books[i]:
rem -= books[i]
i += 1
if i == n:
break
rem = mid
m -= 1
if i == n:
break
if m < 0:
return False
else:
return True
def solve(m, n, books):
ub = 1500000
lb = max(books)
min_width = float("inf")
for i in range(30):
mid = (ub + lb) // 2
if Cond(m, n, mid, books):
min_width = min(min_width, mid)
ub = mid
else:
lb = mid
return min_width
def main(args):
while True:
m, n = list(map(int, input().split()))
if m == 0 and n == 0:
break
books = [int(eval(input())) for _ in range(n)]
result = solve(m, n, books)
print(result)
if __name__ == "__main__":
main(sys.argv[1:])
| false | 1.724138 | [
"- if max(books) > mid:",
"- return False",
"- while books:",
"- while rem >= books[0]:",
"- rem -= books[0]",
"- books = books[1:]",
"- if len(books) == 0:",
"+ i = 0",
"+ while True:",
"+ while rem >= books[i]:",
"+ rem -= books[i]",
"+ i += 1",
"+ if i == n:",
"- if m < 0:",
"- return False",
"- return True",
"+ if i == n:",
"+ break",
"+ if m < 0:",
"+ return False",
"+ else:",
"+ return True"
] | false | 0.036876 | 0.037442 | 0.984896 | [
"s099853180",
"s528439627"
] |
u844646164 | p03354 | python | s233801279 | s514507567 | 911 | 606 | 101,100 | 94,292 | Accepted | Accepted | 33.48 | class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1]*(n+1)
self.rnk = [0]*(n+1)
def Find_Root(self, x):
if(self.root[x] < 0):
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if(x == y):
return
if self.root[x] > self.root[y]:
x, y = y, x
self.root[x] += self.root[y]
self.root[y] = x
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x): # xが属するグループのサイズを返す
return -self.root[self.Find_Root(x)]
def Members(self, x): # xが属するグループに属する要素をリストで返す
return [i for i in range(self.n) if self.Find_Root(i)==self.Find_Root(x)]
def Roots(self): # 全ての根の要素をリストで返す
return [i for i, x in enumerate(self.root) if x < 0]
def Group_Count(self): # グループの数を返す
return len(self.Roots())
n, m = list(map(int, input().split()))
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]
uf = UnionFind(n+1)
for x, y in xy:
uf.Unite(p[x-1], p[y-1])
ans = 0
for i in range(n):
if uf.isSameGroup(i+1, p[i]):
ans += 1
print(ans) | import sys
input = sys.stdin.readline
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1]*(n+1)
self.rnk = [0]*(n+1)
def Find_Root(self, x):
if(self.root[x] < 0):
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if(x == y):
return
if self.root[x] > self.root[y]:
x, y = y, x
self.root[x] += self.root[y]
self.root[y] = x
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x): # xが属するグループのサイズを返す
return -self.root[self.Find_Root(x)]
def Members(self, x): # xが属するグループに属する要素をリストで返す
return [i for i in range(self.n) if self.Find_Root(i)==self.Find_Root(x)]
def Roots(self): # 全ての根の要素をリストで返す
return [i for i, x in enumerate(self.root) if x < 0]
def Group_Count(self): # グループの数を返す
return len(self.Roots())
N, M = list(map(int, input().split()))
uf = UnionFind(N+1)
p = list(map(int, input().split()))
roots = {i:i for i in range(N)}
proots = {i:i for i in range(N)}
for _ in range(M):
x, y = [int(x)-1 for x in input().split()]
uf.Unite(x, y)
for i in range(N):
r = uf.Find_Root(i)
roots[i] = r
proots[p[i]-1] = r
ans = 0
for i in range(N):
if roots[i] == proots[i]:
ans += 1
print(ans)
| 42 | 53 | 1,360 | 1,549 | class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return
if self.root[x] > self.root[y]:
x, y = y, x
self.root[x] += self.root[y]
self.root[y] = x
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x): # xが属するグループのサイズを返す
return -self.root[self.Find_Root(x)]
def Members(self, x): # xが属するグループに属する要素をリストで返す
return [i for i in range(self.n) if self.Find_Root(i) == self.Find_Root(x)]
def Roots(self): # 全ての根の要素をリストで返す
return [i for i, x in enumerate(self.root) if x < 0]
def Group_Count(self): # グループの数を返す
return len(self.Roots())
n, m = list(map(int, input().split()))
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]
uf = UnionFind(n + 1)
for x, y in xy:
uf.Unite(p[x - 1], p[y - 1])
ans = 0
for i in range(n):
if uf.isSameGroup(i + 1, p[i]):
ans += 1
print(ans)
| import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return
if self.root[x] > self.root[y]:
x, y = y, x
self.root[x] += self.root[y]
self.root[y] = x
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x): # xが属するグループのサイズを返す
return -self.root[self.Find_Root(x)]
def Members(self, x): # xが属するグループに属する要素をリストで返す
return [i for i in range(self.n) if self.Find_Root(i) == self.Find_Root(x)]
def Roots(self): # 全ての根の要素をリストで返す
return [i for i, x in enumerate(self.root) if x < 0]
def Group_Count(self): # グループの数を返す
return len(self.Roots())
N, M = list(map(int, input().split()))
uf = UnionFind(N + 1)
p = list(map(int, input().split()))
roots = {i: i for i in range(N)}
proots = {i: i for i in range(N)}
for _ in range(M):
x, y = [int(x) - 1 for x in input().split()]
uf.Unite(x, y)
for i in range(N):
r = uf.Find_Root(i)
roots[i] = r
proots[p[i] - 1] = r
ans = 0
for i in range(N):
if roots[i] == proots[i]:
ans += 1
print(ans)
| false | 20.754717 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+",
"-n, m = list(map(int, input().split()))",
"+N, M = list(map(int, input().split()))",
"+uf = UnionFind(N + 1)",
"-xy = [list(map(int, input().split())) for _ in range(m)]",
"-uf = UnionFind(n + 1)",
"-for x, y in xy:",
"- uf.Unite(p[x - 1], p[y - 1])",
"+roots = {i: i for i in range(N)}",
"+proots = {i: i for i in range(N)}",
"+for _ in range(M):",
"+ x, y = [int(x) - 1 for x in input().split()]",
"+ uf.Unite(x, y)",
"+for i in range(N):",
"+ r = uf.Find_Root(i)",
"+ roots[i] = r",
"+ proots[p[i] - 1] = r",
"-for i in range(n):",
"- if uf.isSameGroup(i + 1, p[i]):",
"+for i in range(N):",
"+ if roots[i] == proots[i]:"
] | false | 0.148361 | 0.045908 | 3.231695 | [
"s233801279",
"s514507567"
] |
u226108478 | p04019 | python | s683135450 | s772560099 | 23 | 17 | 3,316 | 2,940 | Accepted | Accepted | 26.09 | # -*- coding: utf-8 -*-
# AtCoder Grand Contest
# Problem A
if __name__ == '__main__':
from collections import Counter
s = Counter(eval(input()))
if ('S' in list(s.keys())) and ('N' not in list(s.keys())):
print('No')
elif ('N' in list(s.keys())) and ('S' not in list(s.keys())):
print('No')
elif ('W' in list(s.keys())) and ('E' not in list(s.keys())):
print('No')
elif ('E' in list(s.keys())) and ('W' not in list(s.keys())):
print('No')
else:
print('Yes')
| # -*- coding: utf-8 -*-
# AtCoder Grand Contest
# Problem A
if __name__ == '__main__':
s = eval(input())
# See:
# http://agc003.contest.atcoder.jp/data/agc/003/editorial.pdf
# https://beta.atcoder.jp/contests/agc003/submissions/849782
if (('S' in s) ^ ('N' in s)) or (('W' in s) ^ ('E' in s)):
print('No')
else:
print('Yes')
| 21 | 16 | 498 | 378 | # -*- coding: utf-8 -*-
# AtCoder Grand Contest
# Problem A
if __name__ == "__main__":
from collections import Counter
s = Counter(eval(input()))
if ("S" in list(s.keys())) and ("N" not in list(s.keys())):
print("No")
elif ("N" in list(s.keys())) and ("S" not in list(s.keys())):
print("No")
elif ("W" in list(s.keys())) and ("E" not in list(s.keys())):
print("No")
elif ("E" in list(s.keys())) and ("W" not in list(s.keys())):
print("No")
else:
print("Yes")
| # -*- coding: utf-8 -*-
# AtCoder Grand Contest
# Problem A
if __name__ == "__main__":
s = eval(input())
# See:
# http://agc003.contest.atcoder.jp/data/agc/003/editorial.pdf
# https://beta.atcoder.jp/contests/agc003/submissions/849782
if (("S" in s) ^ ("N" in s)) or (("W" in s) ^ ("E" in s)):
print("No")
else:
print("Yes")
| false | 23.809524 | [
"- from collections import Counter",
"-",
"- s = Counter(eval(input()))",
"- if (\"S\" in list(s.keys())) and (\"N\" not in list(s.keys())):",
"- print(\"No\")",
"- elif (\"N\" in list(s.keys())) and (\"S\" not in list(s.keys())):",
"- print(\"No\")",
"- elif (\"W\" in list(s.keys())) and (\"E\" not in list(s.keys())):",
"- print(\"No\")",
"- elif (\"E\" in list(s.keys())) and (\"W\" not in list(s.keys())):",
"+ s = eval(input())",
"+ # See:",
"+ # http://agc003.contest.atcoder.jp/data/agc/003/editorial.pdf",
"+ # https://beta.atcoder.jp/contests/agc003/submissions/849782",
"+ if ((\"S\" in s) ^ (\"N\" in s)) or ((\"W\" in s) ^ (\"E\" in s)):"
] | false | 0.038814 | 0.03991 | 0.972553 | [
"s683135450",
"s772560099"
] |
u226108478 | p03557 | python | s543807848 | s976327156 | 334 | 290 | 23,744 | 22,720 | Accepted | Accepted | 13.17 | # -*- coding: utf-8 -*-
def main():
from bisect import bisect_left
from bisect import bisect_right
n = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))
ans = 0
for bi in b:
less = bisect_left(a, bi)
greater = n - bisect_right(c, bi)
ans += less * greater
print(ans)
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
def main():
from bisect import bisect_left
from bisect import bisect_right
n = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
ans = 0
for bi in b:
less = bisect_left(a, bi)
greater = n - bisect_right(c, bi)
ans += less * greater
print(ans)
if __name__ == '__main__':
main()
| 23 | 23 | 481 | 489 | # -*- coding: utf-8 -*-
def main():
from bisect import bisect_left
from bisect import bisect_right
n = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))
ans = 0
for bi in b:
less = bisect_left(a, bi)
greater = n - bisect_right(c, bi)
ans += less * greater
print(ans)
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
def main():
from bisect import bisect_left
from bisect import bisect_right
n = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
ans = 0
for bi in b:
less = bisect_left(a, bi)
greater = n - bisect_right(c, bi)
ans += less * greater
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"- b = list(map(int, input().split()))",
"+ b = sorted(list(map(int, input().split())))"
] | false | 0.04586 | 0.049937 | 0.918361 | [
"s543807848",
"s976327156"
] |
u046187684 | p03353 | python | s258657952 | s831505494 | 30 | 18 | 4,596 | 3,060 | Accepted | Accepted | 40 | from collections import Counter
def solve(string):
s, k = string.split()
k = int(k)
count = Counter(s)
chars = sorted(set(s))
for t in range(min(3, len(chars))):
tmp = []
i = s.index(chars[t])
tmp.append(s[i:i + k])
if count[chars[t]] > 1:
for _ in range(count[chars[t]] - 1):
i = s.index(chars[t], i + 1)
tmp.append(s[i:i + k])
g = []
for p in tmp:
for j in range(1, len(p) + 1):
g.append(p[:j])
g = sorted(set(g))
if len(g) < k:
k -= len(g)
continue
return g[k - 1]
if __name__ == '__main__':
print((solve('\n'.join([eval(input()), eval(input())]))))
| def solve(string):
s, k = string.split()
k = int(k)
chars = sorted(set(s))
exists = []
def dfs(base):
exists.append(base)
if len(exists) >= k:
return
for c in chars:
if base + c in s:
dfs(base + c)
for c in chars:
dfs(c)
return exists[k - 1]
if __name__ == '__main__':
print((solve('\n'.join([eval(input()), eval(input())]))))
| 29 | 22 | 763 | 443 | from collections import Counter
def solve(string):
s, k = string.split()
k = int(k)
count = Counter(s)
chars = sorted(set(s))
for t in range(min(3, len(chars))):
tmp = []
i = s.index(chars[t])
tmp.append(s[i : i + k])
if count[chars[t]] > 1:
for _ in range(count[chars[t]] - 1):
i = s.index(chars[t], i + 1)
tmp.append(s[i : i + k])
g = []
for p in tmp:
for j in range(1, len(p) + 1):
g.append(p[:j])
g = sorted(set(g))
if len(g) < k:
k -= len(g)
continue
return g[k - 1]
if __name__ == "__main__":
print((solve("\n".join([eval(input()), eval(input())]))))
| def solve(string):
s, k = string.split()
k = int(k)
chars = sorted(set(s))
exists = []
def dfs(base):
exists.append(base)
if len(exists) >= k:
return
for c in chars:
if base + c in s:
dfs(base + c)
for c in chars:
dfs(c)
return exists[k - 1]
if __name__ == "__main__":
print((solve("\n".join([eval(input()), eval(input())]))))
| false | 24.137931 | [
"-from collections import Counter",
"-",
"-",
"- count = Counter(s)",
"- for t in range(min(3, len(chars))):",
"- tmp = []",
"- i = s.index(chars[t])",
"- tmp.append(s[i : i + k])",
"- if count[chars[t]] > 1:",
"- for _ in range(count[chars[t]] - 1):",
"- i = s.index(chars[t], i + 1)",
"- tmp.append(s[i : i + k])",
"- g = []",
"- for p in tmp:",
"- for j in range(1, len(p) + 1):",
"- g.append(p[:j])",
"- g = sorted(set(g))",
"- if len(g) < k:",
"- k -= len(g)",
"- continue",
"- return g[k - 1]",
"+ exists = []",
"+",
"+ def dfs(base):",
"+ exists.append(base)",
"+ if len(exists) >= k:",
"+ return",
"+ for c in chars:",
"+ if base + c in s:",
"+ dfs(base + c)",
"+",
"+ for c in chars:",
"+ dfs(c)",
"+ return exists[k - 1]"
] | false | 0.046099 | 0.035264 | 1.307245 | [
"s258657952",
"s831505494"
] |
u445624660 | p03450 | python | s178239224 | s086855916 | 1,875 | 1,484 | 16,560 | 11,044 | Accepted | Accepted | 20.85 | import sys
sys.setrecursionlimit(10**7)
class WeightedUnionFindTree:
def __init__(self, n):
self.par = list(range(n))
self.rank = [0 for _ in range(n)]
self.weight = [0 for _ in range(n)]
def root(self, t):
if t == self.par[t]:
return t
# 経路圧縮してみる
r = self.root(self.par[t])
self.weight[t] += self.weight[self.par[t]]
self.par[t] = r
return r
def rec_weight(self, t):
if t == self.par[t]:
return 0
return self.weight[t] + self.rec_weight(self.par[t])
def same(self, x, y):
return self.root(x) == self.root(y)
def unite(self, x, y, w):
rootx = self.root(x)
rooty = self.root(y)
if rootx != rooty:
if y != rooty:
# 直接yにつなげる
self.weight[rootx] = w - self.rec_weight(x)
else:
# 根につなげる
self.weight[rootx] = w - (self.weight[x] - self.weight[y])
# ここで親を更新
self.par[rootx] = y
else:
return w == self.diff(x, y)
def diff(self, x, y):
return self.rec_weight(x) - self.rec_weight(y)
n, m = list(map(int, input().split()))
par = list(range(n+1))
dist = [0 for _ in range(n+1)]
wuft = WeightedUnionFindTree(n+1)
flag = True
for _ in range(m):
l, r, d = list(map(int, input().split()))
# 根が異なってたらとりあえず併合、同じならdifを取って整合性を確かめる
a = wuft.unite(l, r, d)
if a is not None:
if a == False:
flag = False
"""
[print("[{}]{}".format(idx, v), end=" ") for idx, v in enumerate(wuft.par)]
print()
[print("[{}]{}".format(idx, v), end=" ") for idx, v in enumerate(wuft.weight)]
print()
"""
print(("Yes" if flag else "No"))
| import sys
sys.setrecursionlimit(10**7)
n, m = list(map(int, input().split()))
par = list(range(n+1))
dist = [0 for _ in range(n+1)]
def root(x):
if x == par[x]:
return x
r = root(par[x])
dist[x] += dist[par[x]]
par[x] = r
return r
def direct_cost(x):
if x == par[x]:
return 0
return dist[x] + direct_cost(par[x])
def diff(x, y):
return direct_cost(x) - direct_cost(y)
def unite(x, y, w):
rootx = root(x)
rooty = root(y)
if rootx != rooty:
if y != rooty:
# 直接yにつなげる
dist[rootx] = w - direct_cost(x)
else:
# 根につなげる
dist[rootx] = w - (dist[x] - dist[y])
# ここで親を更新
par[rootx] = y
else:
return w == diff(x, y)
flag = True
for _ in range(m):
l, r, d = list(map(int, input().split()))
# 根が異なってたらとりあえず併合、同じならdifを取って整合性を確かめる
a = unite(l, r, d)
if a is not None:
if a == False:
flag = False
"""
rootx, rooty = root(l), root(r)
if rootx != rooty:
if r != rooty:
# 直接yにつなげる
dist[rootx] = d - direct_cost(l)
else:
# yの根につなげる
dist[rootx] = d - (dist[l] - dist[r])
par[rootx] = l
else:
if d != diff(l, r):
flag = False
"""
"""
[print("[{}]{}".format(idx, v), end=" ") for idx, v in enumerate(par)]
print()
[print("[{}]{}".format(idx, v), end=" ") for idx, v in enumerate(dist)]
print()
"""
print(("Yes" if flag else "No"))
| 67 | 69 | 1,656 | 1,435 | import sys
sys.setrecursionlimit(10**7)
class WeightedUnionFindTree:
def __init__(self, n):
self.par = list(range(n))
self.rank = [0 for _ in range(n)]
self.weight = [0 for _ in range(n)]
def root(self, t):
if t == self.par[t]:
return t
# 経路圧縮してみる
r = self.root(self.par[t])
self.weight[t] += self.weight[self.par[t]]
self.par[t] = r
return r
def rec_weight(self, t):
if t == self.par[t]:
return 0
return self.weight[t] + self.rec_weight(self.par[t])
def same(self, x, y):
return self.root(x) == self.root(y)
def unite(self, x, y, w):
rootx = self.root(x)
rooty = self.root(y)
if rootx != rooty:
if y != rooty:
# 直接yにつなげる
self.weight[rootx] = w - self.rec_weight(x)
else:
# 根につなげる
self.weight[rootx] = w - (self.weight[x] - self.weight[y])
# ここで親を更新
self.par[rootx] = y
else:
return w == self.diff(x, y)
def diff(self, x, y):
return self.rec_weight(x) - self.rec_weight(y)
n, m = list(map(int, input().split()))
par = list(range(n + 1))
dist = [0 for _ in range(n + 1)]
wuft = WeightedUnionFindTree(n + 1)
flag = True
for _ in range(m):
l, r, d = list(map(int, input().split()))
# 根が異なってたらとりあえず併合、同じならdifを取って整合性を確かめる
a = wuft.unite(l, r, d)
if a is not None:
if a == False:
flag = False
"""
[print("[{}]{}".format(idx, v), end=" ") for idx, v in enumerate(wuft.par)]
print()
[print("[{}]{}".format(idx, v), end=" ") for idx, v in enumerate(wuft.weight)]
print()
"""
print(("Yes" if flag else "No"))
| import sys
sys.setrecursionlimit(10**7)
n, m = list(map(int, input().split()))
par = list(range(n + 1))
dist = [0 for _ in range(n + 1)]
def root(x):
if x == par[x]:
return x
r = root(par[x])
dist[x] += dist[par[x]]
par[x] = r
return r
def direct_cost(x):
if x == par[x]:
return 0
return dist[x] + direct_cost(par[x])
def diff(x, y):
return direct_cost(x) - direct_cost(y)
def unite(x, y, w):
rootx = root(x)
rooty = root(y)
if rootx != rooty:
if y != rooty:
# 直接yにつなげる
dist[rootx] = w - direct_cost(x)
else:
# 根につなげる
dist[rootx] = w - (dist[x] - dist[y])
# ここで親を更新
par[rootx] = y
else:
return w == diff(x, y)
flag = True
for _ in range(m):
l, r, d = list(map(int, input().split()))
# 根が異なってたらとりあえず併合、同じならdifを取って整合性を確かめる
a = unite(l, r, d)
if a is not None:
if a == False:
flag = False
"""
rootx, rooty = root(l), root(r)
if rootx != rooty:
if r != rooty:
# 直接yにつなげる
dist[rootx] = d - direct_cost(l)
else:
# yの根につなげる
dist[rootx] = d - (dist[l] - dist[r])
par[rootx] = l
else:
if d != diff(l, r):
flag = False
"""
"""
[print("[{}]{}".format(idx, v), end=" ") for idx, v in enumerate(par)]
print()
[print("[{}]{}".format(idx, v), end=" ") for idx, v in enumerate(dist)]
print()
"""
print(("Yes" if flag else "No"))
| false | 2.898551 | [
"-",
"-",
"-class WeightedUnionFindTree:",
"- def __init__(self, n):",
"- self.par = list(range(n))",
"- self.rank = [0 for _ in range(n)]",
"- self.weight = [0 for _ in range(n)]",
"-",
"- def root(self, t):",
"- if t == self.par[t]:",
"- return t",
"- # 経路圧縮してみる",
"- r = self.root(self.par[t])",
"- self.weight[t] += self.weight[self.par[t]]",
"- self.par[t] = r",
"- return r",
"-",
"- def rec_weight(self, t):",
"- if t == self.par[t]:",
"- return 0",
"- return self.weight[t] + self.rec_weight(self.par[t])",
"-",
"- def same(self, x, y):",
"- return self.root(x) == self.root(y)",
"-",
"- def unite(self, x, y, w):",
"- rootx = self.root(x)",
"- rooty = self.root(y)",
"- if rootx != rooty:",
"- if y != rooty:",
"- # 直接yにつなげる",
"- self.weight[rootx] = w - self.rec_weight(x)",
"- else:",
"- # 根につなげる",
"- self.weight[rootx] = w - (self.weight[x] - self.weight[y])",
"- # ここで親を更新",
"- self.par[rootx] = y",
"- else:",
"- return w == self.diff(x, y)",
"-",
"- def diff(self, x, y):",
"- return self.rec_weight(x) - self.rec_weight(y)",
"-",
"-",
"-wuft = WeightedUnionFindTree(n + 1)",
"+",
"+",
"+def root(x):",
"+ if x == par[x]:",
"+ return x",
"+ r = root(par[x])",
"+ dist[x] += dist[par[x]]",
"+ par[x] = r",
"+ return r",
"+",
"+",
"+def direct_cost(x):",
"+ if x == par[x]:",
"+ return 0",
"+ return dist[x] + direct_cost(par[x])",
"+",
"+",
"+def diff(x, y):",
"+ return direct_cost(x) - direct_cost(y)",
"+",
"+",
"+def unite(x, y, w):",
"+ rootx = root(x)",
"+ rooty = root(y)",
"+ if rootx != rooty:",
"+ if y != rooty:",
"+ # 直接yにつなげる",
"+ dist[rootx] = w - direct_cost(x)",
"+ else:",
"+ # 根につなげる",
"+ dist[rootx] = w - (dist[x] - dist[y])",
"+ # ここで親を更新",
"+ par[rootx] = y",
"+ else:",
"+ return w == diff(x, y)",
"+",
"+",
"- a = wuft.unite(l, r, d)",
"+ a = unite(l, r, d)",
"+ \"\"\"",
"+ rootx, rooty = root(l), root(r)",
"+ if rootx != rooty:",
"+ if r != rooty:",
"+ # 直接yにつなげる",
"+ dist[rootx] = d - direct_cost(l)",
"+ else:",
"+ # yの根につなげる",
"+ dist[rootx] = d - (dist[l] - dist[r])",
"+ par[rootx] = l",
"+ else:",
"+ if d != diff(l, r):",
"+ flag = False",
"+ \"\"\"",
"-[print(\"[{}]{}\".format(idx, v), end=\" \") for idx, v in enumerate(wuft.par)]",
"+[print(\"[{}]{}\".format(idx, v), end=\" \") for idx, v in enumerate(par)]",
"-[print(\"[{}]{}\".format(idx, v), end=\" \") for idx, v in enumerate(wuft.weight)]",
"+[print(\"[{}]{}\".format(idx, v), end=\" \") for idx, v in enumerate(dist)]"
] | false | 0.040086 | 0.045704 | 0.877083 | [
"s178239224",
"s086855916"
] |
u462831976 | p00111 | python | s868926767 | s762095835 | 80 | 60 | 11,728 | 11,740 | Accepted | Accepted | 25 | # -*- coding: utf-8 -*-
import sys
import os
import math
import re
import random
tableA = {
"A": "00000",
"B": "00001",
"C": "00010",
"D": "00011",
"E": "00100",
"F": "00101",
"G": "00110",
"H": "00111",
"I": "01000",
"J": "01001",
"K": "01010",
"L": "01011",
"M": "01100",
"N": "01101",
"O": "01110",
"P": "01111",
"Q": "10000",
"R": "10001",
"S": "10010",
"T": "10011",
"U": "10100",
"V": "10101",
"W": "10110",
"X": "10111",
"Y": "11000",
"Z": "11001",
" ": "11010",
".": "11011",
",": "11100",
"-": "11101",
"'": "11110",
"?": "11111"}
tableB = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z"}
def my_solve(s):
# encode
# lst = []
# for c in s:
# lst.append(tableA[c])
# s = ''.join(lst)
en = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + ' .,-\'?'
a = b = c = ''
for x in s: a += str(bin(en.index(x)))[2:].zfill(5)
s = a
de = {
'101': ' ', '000000': '\'', '000011': ',', '10010001': '-', '010001': '.', '000001': '?',
'100101': 'A', '10011010': 'B', '0101': 'C', '0001': 'D', '110': 'E', '01001': 'F',
'10011011': 'G', '010000': 'H', '0111': 'I', '10011000': 'J', '0110': 'K', '00100': 'L',
'10011001': 'M', '10011110': 'N', '00101': 'O', '111': 'P', '10011111': 'Q', '1000': 'R',
'00110': 'S', '00111': 'T', '10011100': 'U', '10011101': 'V', '000010': 'W', '10010010': 'X',
'10010011': 'Y', '10010000': 'Z'
}
for x in a:
b += x
if b in de: c += de[b];b = ''
return c
# tmp, ans = '', ''
# for c in s:
# tmp += c
# if tmp in tableB:
# ans += tableB[tmp]
# tmp = ''
# return ans
while True:
try:
s = eval(input())
except:
break
print((my_solve(s))) | # -*- coding: utf-8 -*-
import sys
import os
import math
import re
import random
tableA = {
"A": "00000",
"B": "00001",
"C": "00010",
"D": "00011",
"E": "00100",
"F": "00101",
"G": "00110",
"H": "00111",
"I": "01000",
"J": "01001",
"K": "01010",
"L": "01011",
"M": "01100",
"N": "01101",
"O": "01110",
"P": "01111",
"Q": "10000",
"R": "10001",
"S": "10010",
"T": "10011",
"U": "10100",
"V": "10101",
"W": "10110",
"X": "10111",
"Y": "11000",
"Z": "11001",
" ": "11010",
".": "11011",
",": "11100",
"-": "11101",
"'": "11110",
"?": "11111"}
tableB = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z"}
def my_solve(s):
# encode
lst = []
for c in s:
lst.append(tableA[c])
s = ''.join(lst)
# en = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + ' .,-\'?'
a = b = c = ''
# for x in s: a += str(bin(en.index(x)))[2:].zfill(5)
# s = a
a = s
de = {
'101': ' ', '000000': '\'', '000011': ',', '10010001': '-', '010001': '.', '000001': '?',
'100101': 'A', '10011010': 'B', '0101': 'C', '0001': 'D', '110': 'E', '01001': 'F',
'10011011': 'G', '010000': 'H', '0111': 'I', '10011000': 'J', '0110': 'K', '00100': 'L',
'10011001': 'M', '10011110': 'N', '00101': 'O', '111': 'P', '10011111': 'Q', '1000': 'R',
'00110': 'S', '00111': 'T', '10011100': 'U', '10011101': 'V', '000010': 'W', '10010010': 'X',
'10010011': 'Y', '10010000': 'Z'
}
for x in a:
b += x
if b in de: c += de[b];b = ''
return c
# tmp, ans = '', ''
# for c in s:
# tmp += c
# if tmp in tableB:
# ans += tableB[tmp]
# tmp = ''
# return ans
while True:
try:
s = eval(input())
except:
break
print((my_solve(s))) | 116 | 117 | 2,542 | 2,551 | # -*- coding: utf-8 -*-
import sys
import os
import math
import re
import random
tableA = {
"A": "00000",
"B": "00001",
"C": "00010",
"D": "00011",
"E": "00100",
"F": "00101",
"G": "00110",
"H": "00111",
"I": "01000",
"J": "01001",
"K": "01010",
"L": "01011",
"M": "01100",
"N": "01101",
"O": "01110",
"P": "01111",
"Q": "10000",
"R": "10001",
"S": "10010",
"T": "10011",
"U": "10100",
"V": "10101",
"W": "10110",
"X": "10111",
"Y": "11000",
"Z": "11001",
" ": "11010",
".": "11011",
",": "11100",
"-": "11101",
"'": "11110",
"?": "11111",
}
tableB = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z",
}
def my_solve(s):
# encode
# lst = []
# for c in s:
# lst.append(tableA[c])
# s = ''.join(lst)
en = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + " .,-'?"
a = b = c = ""
for x in s:
a += str(bin(en.index(x)))[2:].zfill(5)
s = a
de = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z",
}
for x in a:
b += x
if b in de:
c += de[b]
b = ""
return c
# tmp, ans = '', ''
# for c in s:
# tmp += c
# if tmp in tableB:
# ans += tableB[tmp]
# tmp = ''
# return ans
while True:
try:
s = eval(input())
except:
break
print((my_solve(s)))
| # -*- coding: utf-8 -*-
import sys
import os
import math
import re
import random
tableA = {
"A": "00000",
"B": "00001",
"C": "00010",
"D": "00011",
"E": "00100",
"F": "00101",
"G": "00110",
"H": "00111",
"I": "01000",
"J": "01001",
"K": "01010",
"L": "01011",
"M": "01100",
"N": "01101",
"O": "01110",
"P": "01111",
"Q": "10000",
"R": "10001",
"S": "10010",
"T": "10011",
"U": "10100",
"V": "10101",
"W": "10110",
"X": "10111",
"Y": "11000",
"Z": "11001",
" ": "11010",
".": "11011",
",": "11100",
"-": "11101",
"'": "11110",
"?": "11111",
}
tableB = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z",
}
def my_solve(s):
# encode
lst = []
for c in s:
lst.append(tableA[c])
s = "".join(lst)
# en = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + ' .,-\'?'
a = b = c = ""
# for x in s: a += str(bin(en.index(x)))[2:].zfill(5)
# s = a
a = s
de = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z",
}
for x in a:
b += x
if b in de:
c += de[b]
b = ""
return c
# tmp, ans = '', ''
# for c in s:
# tmp += c
# if tmp in tableB:
# ans += tableB[tmp]
# tmp = ''
# return ans
while True:
try:
s = eval(input())
except:
break
print((my_solve(s)))
| false | 0.854701 | [
"- # lst = []",
"- # for c in s:",
"- # lst.append(tableA[c])",
"- # s = ''.join(lst)",
"- en = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\" + \" .,-'?\"",
"+ lst = []",
"+ for c in s:",
"+ lst.append(tableA[c])",
"+ s = \"\".join(lst)",
"+ # en = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + ' .,-\\'?'",
"- for x in s:",
"- a += str(bin(en.index(x)))[2:].zfill(5)",
"- s = a",
"+ # for x in s: a += str(bin(en.index(x)))[2:].zfill(5)",
"+ # s = a",
"+ a = s"
] | false | 0.045469 | 0.045701 | 0.994915 | [
"s868926767",
"s762095835"
] |
u074220993 | p03962 | python | s220007903 | s463530443 | 26 | 23 | 9,020 | 9,000 | Accepted | Accepted | 11.54 | Set = {int(x) for x in input().split()}
print((len(Set))) | print((len(set(input().split())))) | 2 | 1 | 56 | 32 | Set = {int(x) for x in input().split()}
print((len(Set)))
| print((len(set(input().split()))))
| false | 50 | [
"-Set = {int(x) for x in input().split()}",
"-print((len(Set)))",
"+print((len(set(input().split()))))"
] | false | 0.039011 | 0.03674 | 1.061808 | [
"s220007903",
"s463530443"
] |
u745554846 | p03073 | python | s047257976 | s715461967 | 25 | 18 | 5,284 | 3,188 | Accepted | Accepted | 28 | a = list(str(eval(input())))
empty = []
empty.append([i for i in a[0::2]])
empty.append([i for i in a[1::2]])
aa = empty[0].count('0') + empty[1].count('1')
bb = empty[0].count('1') + empty[1].count('0')
if aa >= bb:
print(bb)
else:
print(aa) | s = eval(input())
candi = []
candi.append(s[0::2].count('0') + s[1::2].count('1'))
candi.append(s[0::2].count('1') + s[1::2].count('0'))
print((min(candi))) | 14 | 8 | 261 | 158 | a = list(str(eval(input())))
empty = []
empty.append([i for i in a[0::2]])
empty.append([i for i in a[1::2]])
aa = empty[0].count("0") + empty[1].count("1")
bb = empty[0].count("1") + empty[1].count("0")
if aa >= bb:
print(bb)
else:
print(aa)
| s = eval(input())
candi = []
candi.append(s[0::2].count("0") + s[1::2].count("1"))
candi.append(s[0::2].count("1") + s[1::2].count("0"))
print((min(candi)))
| false | 42.857143 | [
"-a = list(str(eval(input())))",
"-empty = []",
"-empty.append([i for i in a[0::2]])",
"-empty.append([i for i in a[1::2]])",
"-aa = empty[0].count(\"0\") + empty[1].count(\"1\")",
"-bb = empty[0].count(\"1\") + empty[1].count(\"0\")",
"-if aa >= bb:",
"- print(bb)",
"-else:",
"- print(aa)",
"+s = eval(input())",
"+candi = []",
"+candi.append(s[0::2].count(\"0\") + s[1::2].count(\"1\"))",
"+candi.append(s[0::2].count(\"1\") + s[1::2].count(\"0\"))",
"+print((min(candi)))"
] | false | 0.038023 | 0.047522 | 0.800124 | [
"s047257976",
"s715461967"
] |
u057109575 | p02948 | python | s763988151 | s728242162 | 812 | 618 | 92,632 | 105,088 | Accepted | Accepted | 23.89 | from heapq import heappush, heappop
from collections import defaultdict
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
cand = defaultdict(list)
for a, b in X:
cand[a].append(b)
pq = []
ans = 0
for i in range(1, M + 1):
for c in cand[i]:
heappush(pq, -c)
if pq:
ans -= heappop(pq)
print(ans)
| from heapq import heappush, heappop
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
pq = []
for a, b in X:
heappush(pq, (a, b))
cand = []
ans = 0
for t in range(1, M + 1):
while pq:
a, b = heappop(pq)
if a <= t:
heappush(cand, -b)
else:
heappush(pq, (a, b))
break
if cand:
v = heappop(cand)
ans += -v
print(ans)
| 20 | 25 | 389 | 474 | from heapq import heappush, heappop
from collections import defaultdict
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
cand = defaultdict(list)
for a, b in X:
cand[a].append(b)
pq = []
ans = 0
for i in range(1, M + 1):
for c in cand[i]:
heappush(pq, -c)
if pq:
ans -= heappop(pq)
print(ans)
| from heapq import heappush, heappop
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
pq = []
for a, b in X:
heappush(pq, (a, b))
cand = []
ans = 0
for t in range(1, M + 1):
while pq:
a, b = heappop(pq)
if a <= t:
heappush(cand, -b)
else:
heappush(pq, (a, b))
break
if cand:
v = heappop(cand)
ans += -v
print(ans)
| false | 20 | [
"-from collections import defaultdict",
"-cand = defaultdict(list)",
"+pq = []",
"- cand[a].append(b)",
"-pq = []",
"+ heappush(pq, (a, b))",
"+cand = []",
"-for i in range(1, M + 1):",
"- for c in cand[i]:",
"- heappush(pq, -c)",
"- if pq:",
"- ans -= heappop(pq)",
"+for t in range(1, M + 1):",
"+ while pq:",
"+ a, b = heappop(pq)",
"+ if a <= t:",
"+ heappush(cand, -b)",
"+ else:",
"+ heappush(pq, (a, b))",
"+ break",
"+ if cand:",
"+ v = heappop(cand)",
"+ ans += -v"
] | false | 0.033864 | 0.037413 | 0.905157 | [
"s763988151",
"s728242162"
] |
u123756661 | p02601 | python | s522737119 | s043731694 | 70 | 64 | 61,756 | 62,000 | Accepted | Accepted | 8.57 | a,b,c=list(map(int,input().split()))
k=int(eval(input()))
d={"a":a,"b":b,"c":c}
for i in range(k+1):
if d["a"]<d["b"]<d["c"]:
print("Yes")
exit()
elif d["a"]>=d["c"]:
d["c"]*=2
elif d["a"]>=d["b"]:
d["b"]*=2
elif d["b"]>=d["c"]:
d["c"]*=2
print("No") | a,b,c=list(map(int,input().split()))
d={"a":a,"b":b,"c":c}
for i in range(int(eval(input()))+1):
if d["a"]<d["b"]<d["c"]:
print("Yes")
exit()
elif d["a"]>=d["c"]: d["c"]*=2
elif d["a"]>=d["b"]: d["b"]*=2
elif d["b"]>=d["c"]: d["c"]*=2
print("No")
| 14 | 10 | 307 | 276 | a, b, c = list(map(int, input().split()))
k = int(eval(input()))
d = {"a": a, "b": b, "c": c}
for i in range(k + 1):
if d["a"] < d["b"] < d["c"]:
print("Yes")
exit()
elif d["a"] >= d["c"]:
d["c"] *= 2
elif d["a"] >= d["b"]:
d["b"] *= 2
elif d["b"] >= d["c"]:
d["c"] *= 2
print("No")
| a, b, c = list(map(int, input().split()))
d = {"a": a, "b": b, "c": c}
for i in range(int(eval(input())) + 1):
if d["a"] < d["b"] < d["c"]:
print("Yes")
exit()
elif d["a"] >= d["c"]:
d["c"] *= 2
elif d["a"] >= d["b"]:
d["b"] *= 2
elif d["b"] >= d["c"]:
d["c"] *= 2
print("No")
| false | 28.571429 | [
"-k = int(eval(input()))",
"-for i in range(k + 1):",
"+for i in range(int(eval(input())) + 1):"
] | false | 0.08808 | 0.138097 | 0.637817 | [
"s522737119",
"s043731694"
] |
u424768586 | p02734 | python | s781146167 | s880776772 | 111 | 101 | 74,448 | 68,712 | Accepted | Accepted | 9.01 | import sys
def input(): return sys.stdin.readline()[:-1]
#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
#N = int(input())
N, S = list(map(int, input().split()))
#L = [int(input()) for i in range(N)]
A = tuple(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]
mod=998244353
ans=0
dp=[0]*(S+1)
for a in A:
dp[0]+=1
for i in reversed(list(range(a,S+1))):
dp[i]+=dp[i-a]
dp[i]%=mod
ans+=dp[-1]
ans%=mod
#print(dp)
print(ans)
| import sys
def input(): return sys.stdin.readline()[:-1]
#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
#N = int(input())
N, S = list(map(int, input().split()))
#L = [int(input()) for i in range(N)]
A = tuple(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]
mod=998244353
ans=0
dp=[0]*(S+1)
for a in A:
dp[0]+=1
for i in range(S,a-1,-1):
dp[i]+=dp[i-a]
dp[i]%=mod
ans+=dp[-1]
ans%=mod
#print(dp)
print(ans)
| 26 | 26 | 534 | 527 | import sys
def input():
return sys.stdin.readline()[:-1]
# mod = 10**9+7
# w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
# N = int(input())
N, S = list(map(int, input().split()))
# L = [int(input()) for i in range(N)]
A = tuple(map(int, input().split()))
# S = [list(map(int, input().split())) for i in range(N)]
mod = 998244353
ans = 0
dp = [0] * (S + 1)
for a in A:
dp[0] += 1
for i in reversed(list(range(a, S + 1))):
dp[i] += dp[i - a]
dp[i] %= mod
ans += dp[-1]
ans %= mod
# print(dp)
print(ans)
| import sys
def input():
return sys.stdin.readline()[:-1]
# mod = 10**9+7
# w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
# N = int(input())
N, S = list(map(int, input().split()))
# L = [int(input()) for i in range(N)]
A = tuple(map(int, input().split()))
# S = [list(map(int, input().split())) for i in range(N)]
mod = 998244353
ans = 0
dp = [0] * (S + 1)
for a in A:
dp[0] += 1
for i in range(S, a - 1, -1):
dp[i] += dp[i - a]
dp[i] %= mod
ans += dp[-1]
ans %= mod
# print(dp)
print(ans)
| false | 0 | [
"- for i in reversed(list(range(a, S + 1))):",
"+ for i in range(S, a - 1, -1):"
] | false | 0.136742 | 0.040781 | 3.353063 | [
"s781146167",
"s880776772"
] |
u399721252 | p03634 | python | s986854591 | s443622695 | 1,578 | 582 | 83,152 | 72,180 | Accepted | Accepted | 63.12 | n = int(eval(input()))
connect_list = [[] for i in range(n)]
for i in range(n-1):
a, b, c = [ int(v)-1 for v in input().split() ]
c += 1
connect_list[a].append((b,c))
connect_list[b].append((a,c))
q, k = [ int(v) for v in input().split() ]
k -= 1
shortest_list = [-1 for i in range(n)]
shortest_list[k] = 0
searching_list = [k]
while searching_list != []:
new_search_list = []
for i in searching_list:
for j in connect_list[i]:
x, y = j
if shortest_list[x] == -1:
shortest_list[x] = y + shortest_list[i]
new_search_list.append(x)
searching_list = new_search_list
for i in range(q):
a, b = [ int(v)-1 for v in input().split() ]
print((shortest_list[a] + shortest_list[b]))
| import sys
input = sys.stdin.readline
n = int(eval(input()))
connect_list = [[] for i in range(n)]
for i in range(n-1):
a, b, c = [ int(v)-1 for v in input().split() ]
c += 1
connect_list[a].append((b,c))
connect_list[b].append((a,c))
q, k = [ int(v) for v in input().split() ]
k -= 1
shortest_list = [-1 for i in range(n)]
shortest_list[k] = 0
searching_list = [k]
while searching_list != []:
new_search_list = []
for i in searching_list:
for j in connect_list[i]:
x, y = j
if shortest_list[x] == -1:
shortest_list[x] = y + shortest_list[i]
new_search_list.append(x)
searching_list = new_search_list
for i in range(q):
a, b = [ int(v)-1 for v in input().split() ]
print((shortest_list[a] + shortest_list[b]))
| 32 | 35 | 803 | 845 | n = int(eval(input()))
connect_list = [[] for i in range(n)]
for i in range(n - 1):
a, b, c = [int(v) - 1 for v in input().split()]
c += 1
connect_list[a].append((b, c))
connect_list[b].append((a, c))
q, k = [int(v) for v in input().split()]
k -= 1
shortest_list = [-1 for i in range(n)]
shortest_list[k] = 0
searching_list = [k]
while searching_list != []:
new_search_list = []
for i in searching_list:
for j in connect_list[i]:
x, y = j
if shortest_list[x] == -1:
shortest_list[x] = y + shortest_list[i]
new_search_list.append(x)
searching_list = new_search_list
for i in range(q):
a, b = [int(v) - 1 for v in input().split()]
print((shortest_list[a] + shortest_list[b]))
| import sys
input = sys.stdin.readline
n = int(eval(input()))
connect_list = [[] for i in range(n)]
for i in range(n - 1):
a, b, c = [int(v) - 1 for v in input().split()]
c += 1
connect_list[a].append((b, c))
connect_list[b].append((a, c))
q, k = [int(v) for v in input().split()]
k -= 1
shortest_list = [-1 for i in range(n)]
shortest_list[k] = 0
searching_list = [k]
while searching_list != []:
new_search_list = []
for i in searching_list:
for j in connect_list[i]:
x, y = j
if shortest_list[x] == -1:
shortest_list[x] = y + shortest_list[i]
new_search_list.append(x)
searching_list = new_search_list
for i in range(q):
a, b = [int(v) - 1 for v in input().split()]
print((shortest_list[a] + shortest_list[b]))
| false | 8.571429 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.045925 | 0.041288 | 1.112315 | [
"s986854591",
"s443622695"
] |
u893962649 | p02572 | python | s480554590 | s693859715 | 130 | 118 | 31,560 | 31,632 | Accepted | Accepted | 9.23 | N = int(eval(input()))
A = list(map(int, input().split()))
sum_a = sum(A)
ans = 0
mod = int(1e9+7)
for a in A:
sum_a -= a
ans += (sum_a * a) % 1000000007
ans %= 1000000007
print((int(ans)))
| N = int(eval(input()))
A = list(map(int, input().split()))
sum_a = sum(A)
ans = 0
mod = int(1e9+7)
for a in A:
sum_a -= a
ans += (sum_a * a)
ans %= 1000000007
print((int(ans)))
| 14 | 15 | 207 | 196 | N = int(eval(input()))
A = list(map(int, input().split()))
sum_a = sum(A)
ans = 0
mod = int(1e9 + 7)
for a in A:
sum_a -= a
ans += (sum_a * a) % 1000000007
ans %= 1000000007
print((int(ans)))
| N = int(eval(input()))
A = list(map(int, input().split()))
sum_a = sum(A)
ans = 0
mod = int(1e9 + 7)
for a in A:
sum_a -= a
ans += sum_a * a
ans %= 1000000007
print((int(ans)))
| false | 6.666667 | [
"- ans += (sum_a * a) % 1000000007",
"+ ans += sum_a * a"
] | false | 0.035935 | 0.097592 | 0.368211 | [
"s480554590",
"s693859715"
] |
u102461423 | p03787 | python | s780098374 | s513838631 | 608 | 469 | 54,416 | 56,656 | Accepted | Accepted | 22.86 | import sys
input = sys.stdin.readline
N,M = list(map(int,input().split()))
UV = [[int(x) for x in row.split()] for row in sys.stdin.readlines()]
graph = [[] for _ in range(N+1)]
for u,v in UV:
graph[u].append(v)
graph[v].append(u)
color = [None] * (N+1)
def calc_comp_data(v):
c = 0
q = [v]
color[v] = 0
is_bipartite = True
size = 1
while q:
qq = []
c ^= 1
for x in q:
for y in graph[x]:
if color[y] is None:
color[y] = c
qq.append(y)
size += 1
elif color[y] == c:
continue
else:
is_bipartite = False
q = qq
return size,is_bipartite
size = []
is_bipartite = []
for v in range(1,N+1):
if color[v] is not None:
continue
x,y = calc_comp_data(v)
size.append(x)
is_bipartite.append(y)
size,is_bipartite
n_point = sum(1 if s == 1 else 0 for s in size)
n_component = len(size)
n_bipartitle = sum(1 if s >= 2 and bl else 0 for s,bl in zip(size,is_bipartite))
answer = 0
for s,bl in zip(size,is_bipartite):
if s == 1:
# 第1成分が1点のとき
answer += N
elif not bl:
# 第1成分が2点以上、非二部グラフ
# 成分の個数が足される
answer += (n_component - n_point) + s*n_point
else:
# 第1成分が2点以上の二部グラフ
# 相手が2点以上の二部グラフなら、2つできる
answer += (n_component - n_point) + n_bipartitle + s*n_point
print(answer) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M = list(map(int, readline().split()))
m = list(map(int, read().split()))
G = [[] for _ in range(N + 1)]
for a, b in zip(m, m):
G[a].append(b)
G[b].append(a)
comp = [0] * (N + 1)
comp_size = [0] * (N + 1)
is_bipartite = [1] * (N + 1)
color = [0] * (N + 1)
for r in range(1, N + 1):
if comp[r]:
continue
comp[r] = r
comp_size[r] = 1
stack = [r]
while stack:
v = stack.pop()
for w in G[v]:
if comp[w]:
if color[v] == color[w]:
is_bipartite[r] = 0
continue
comp[w] = r
comp_size[r] += 1
color[w] = 1 ^ color[v]
stack.append(w)
a, b, c = 0, 0, 0 # point,odd,even
for r in range(1, N + 1):
if r != comp[r]:
continue
if comp_size[r] == 1:
a += 1
elif is_bipartite[r]:
c += 1
else:
b += 1
x = 2 * a * N - a * a + b * b + 2 * b * c + 2 * c * c
print(x) | 65 | 49 | 1,542 | 1,118 | import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
UV = [[int(x) for x in row.split()] for row in sys.stdin.readlines()]
graph = [[] for _ in range(N + 1)]
for u, v in UV:
graph[u].append(v)
graph[v].append(u)
color = [None] * (N + 1)
def calc_comp_data(v):
c = 0
q = [v]
color[v] = 0
is_bipartite = True
size = 1
while q:
qq = []
c ^= 1
for x in q:
for y in graph[x]:
if color[y] is None:
color[y] = c
qq.append(y)
size += 1
elif color[y] == c:
continue
else:
is_bipartite = False
q = qq
return size, is_bipartite
size = []
is_bipartite = []
for v in range(1, N + 1):
if color[v] is not None:
continue
x, y = calc_comp_data(v)
size.append(x)
is_bipartite.append(y)
size, is_bipartite
n_point = sum(1 if s == 1 else 0 for s in size)
n_component = len(size)
n_bipartitle = sum(1 if s >= 2 and bl else 0 for s, bl in zip(size, is_bipartite))
answer = 0
for s, bl in zip(size, is_bipartite):
if s == 1:
# 第1成分が1点のとき
answer += N
elif not bl:
# 第1成分が2点以上、非二部グラフ
# 成分の個数が足される
answer += (n_component - n_point) + s * n_point
else:
# 第1成分が2点以上の二部グラフ
# 相手が2点以上の二部グラフなら、2つできる
answer += (n_component - n_point) + n_bipartitle + s * n_point
print(answer)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M = list(map(int, readline().split()))
m = list(map(int, read().split()))
G = [[] for _ in range(N + 1)]
for a, b in zip(m, m):
G[a].append(b)
G[b].append(a)
comp = [0] * (N + 1)
comp_size = [0] * (N + 1)
is_bipartite = [1] * (N + 1)
color = [0] * (N + 1)
for r in range(1, N + 1):
if comp[r]:
continue
comp[r] = r
comp_size[r] = 1
stack = [r]
while stack:
v = stack.pop()
for w in G[v]:
if comp[w]:
if color[v] == color[w]:
is_bipartite[r] = 0
continue
comp[w] = r
comp_size[r] += 1
color[w] = 1 ^ color[v]
stack.append(w)
a, b, c = 0, 0, 0 # point,odd,even
for r in range(1, N + 1):
if r != comp[r]:
continue
if comp_size[r] == 1:
a += 1
elif is_bipartite[r]:
c += 1
else:
b += 1
x = 2 * a * N - a * a + b * b + 2 * b * c + 2 * c * c
print(x)
| false | 24.615385 | [
"-input = sys.stdin.readline",
"-N, M = list(map(int, input().split()))",
"-UV = [[int(x) for x in row.split()] for row in sys.stdin.readlines()]",
"-graph = [[] for _ in range(N + 1)]",
"-for u, v in UV:",
"- graph[u].append(v)",
"- graph[v].append(u)",
"-color = [None] * (N + 1)",
"-",
"-",
"-def calc_comp_data(v):",
"- c = 0",
"- q = [v]",
"- color[v] = 0",
"- is_bipartite = True",
"- size = 1",
"- while q:",
"- qq = []",
"- c ^= 1",
"- for x in q:",
"- for y in graph[x]:",
"- if color[y] is None:",
"- color[y] = c",
"- qq.append(y)",
"- size += 1",
"- elif color[y] == c:",
"- continue",
"- else:",
"- is_bipartite = False",
"- q = qq",
"- return size, is_bipartite",
"-",
"-",
"-size = []",
"-is_bipartite = []",
"-for v in range(1, N + 1):",
"- if color[v] is not None:",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+N, M = list(map(int, readline().split()))",
"+m = list(map(int, read().split()))",
"+G = [[] for _ in range(N + 1)]",
"+for a, b in zip(m, m):",
"+ G[a].append(b)",
"+ G[b].append(a)",
"+comp = [0] * (N + 1)",
"+comp_size = [0] * (N + 1)",
"+is_bipartite = [1] * (N + 1)",
"+color = [0] * (N + 1)",
"+for r in range(1, N + 1):",
"+ if comp[r]:",
"- x, y = calc_comp_data(v)",
"- size.append(x)",
"- is_bipartite.append(y)",
"-size, is_bipartite",
"-n_point = sum(1 if s == 1 else 0 for s in size)",
"-n_component = len(size)",
"-n_bipartitle = sum(1 if s >= 2 and bl else 0 for s, bl in zip(size, is_bipartite))",
"-answer = 0",
"-for s, bl in zip(size, is_bipartite):",
"- if s == 1:",
"- # 第1成分が1点のとき",
"- answer += N",
"- elif not bl:",
"- # 第1成分が2点以上、非二部グラフ",
"- # 成分の個数が足される",
"- answer += (n_component - n_point) + s * n_point",
"+ comp[r] = r",
"+ comp_size[r] = 1",
"+ stack = [r]",
"+ while stack:",
"+ v = stack.pop()",
"+ for w in G[v]:",
"+ if comp[w]:",
"+ if color[v] == color[w]:",
"+ is_bipartite[r] = 0",
"+ continue",
"+ comp[w] = r",
"+ comp_size[r] += 1",
"+ color[w] = 1 ^ color[v]",
"+ stack.append(w)",
"+a, b, c = 0, 0, 0 # point,odd,even",
"+for r in range(1, N + 1):",
"+ if r != comp[r]:",
"+ continue",
"+ if comp_size[r] == 1:",
"+ a += 1",
"+ elif is_bipartite[r]:",
"+ c += 1",
"- # 第1成分が2点以上の二部グラフ",
"- # 相手が2点以上の二部グラフなら、2つできる",
"- answer += (n_component - n_point) + n_bipartitle + s * n_point",
"-print(answer)",
"+ b += 1",
"+x = 2 * a * N - a * a + b * b + 2 * b * c + 2 * c * c",
"+print(x)"
] | false | 0.039266 | 0.042353 | 0.927111 | [
"s780098374",
"s513838631"
] |
u020373088 | p03457 | python | s494754495 | s276525779 | 423 | 390 | 11,824 | 3,064 | Accepted | Accepted | 7.8 | n = int(eval(input()))
t = [0]
x = [0]
y = [0]
for i in range(n):
ti, xi, yi = list(map(int, input().split()))
t.append(ti)
x.append(xi)
y.append(yi)
ok = True
for i in range(n):
ti = t[i+1] - t[i]
if ((ti - (abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]))) < 0
or (ti - (abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]))) % 2 != 0):
ok = False
break
if ok:
print("Yes")
else:
print("No") | n = int(eval(input()))
pre_t, pre_x, pre_y = [0, 0, 0]
ok = True
for i in range(n):
t, x, y = list(map(int, input().split()))
if (((t-pre_t) - (abs(x-pre_x) + abs(y-pre_y))) < 0
or ((t-pre_t) - (abs(x-pre_x) + abs(y-pre_y))) % 2 != 0):
ok = False
break
pre_t, pre_x, pre_y = [t, x, y]
if ok:
print("Yes")
else:
print("No") | 21 | 16 | 405 | 353 | n = int(eval(input()))
t = [0]
x = [0]
y = [0]
for i in range(n):
ti, xi, yi = list(map(int, input().split()))
t.append(ti)
x.append(xi)
y.append(yi)
ok = True
for i in range(n):
ti = t[i + 1] - t[i]
if (ti - (abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]))) < 0 or (
ti - (abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]))
) % 2 != 0:
ok = False
break
if ok:
print("Yes")
else:
print("No")
| n = int(eval(input()))
pre_t, pre_x, pre_y = [0, 0, 0]
ok = True
for i in range(n):
t, x, y = list(map(int, input().split()))
if ((t - pre_t) - (abs(x - pre_x) + abs(y - pre_y))) < 0 or (
(t - pre_t) - (abs(x - pre_x) + abs(y - pre_y))
) % 2 != 0:
ok = False
break
pre_t, pre_x, pre_y = [t, x, y]
if ok:
print("Yes")
else:
print("No")
| false | 23.809524 | [
"-t = [0]",
"-x = [0]",
"-y = [0]",
"-for i in range(n):",
"- ti, xi, yi = list(map(int, input().split()))",
"- t.append(ti)",
"- x.append(xi)",
"- y.append(yi)",
"+pre_t, pre_x, pre_y = [0, 0, 0]",
"- ti = t[i + 1] - t[i]",
"- if (ti - (abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]))) < 0 or (",
"- ti - (abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]))",
"+ t, x, y = list(map(int, input().split()))",
"+ if ((t - pre_t) - (abs(x - pre_x) + abs(y - pre_y))) < 0 or (",
"+ (t - pre_t) - (abs(x - pre_x) + abs(y - pre_y))",
"+ pre_t, pre_x, pre_y = [t, x, y]"
] | false | 0.041604 | 0.035225 | 1.181095 | [
"s494754495",
"s276525779"
] |
u255280439 | p03493 | python | s390897405 | s940498998 | 45 | 40 | 4,932 | 4,796 | Accepted | Accepted | 11.11 | import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(10000)
# Debug output
def chkprint(*args):
names = {id(v):k for k,v in list(inspect.currentframe().f_back.f_locals.items())}
print((', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args)))
# Binary converter
def to_bin(x):
return bin(x)[2:]
# Set 2 dimension list
def dim2input(N):
li = []
for _ in range(N):
li.append(list(map(int, eval(input()))))
return li
""" input template
S = input()
N = int(input())
L = list(map(int, input().split()))
a, b = list(map(int, input().split()))
SL = list(input())
"""
# --------------------------------------------
dp = None
def main():
print((input().count("1")))
main()
| import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(10000)
# Debug output
def chkprint(*args):
names = {
id(v): k
for k, v in list(inspect.currentframe().f_back.f_locals.items())
}
print((', '.join(
names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args)))
# Binary converter
def to_bin(x):
return bin(x)[2:]
def li_input():
return [int(_) for _ in input().split()]
# --------------------------------------------
dp = None
def main():
print((input().count("1")))
main()
| 42 | 40 | 828 | 651 | import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(10000)
# Debug output
def chkprint(*args):
names = {id(v): k for k, v in list(inspect.currentframe().f_back.f_locals.items())}
print((", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args)))
# Binary converter
def to_bin(x):
return bin(x)[2:]
# Set 2 dimension list
def dim2input(N):
li = []
for _ in range(N):
li.append(list(map(int, eval(input()))))
return li
""" input template
S = input()
N = int(input())
L = list(map(int, input().split()))
a, b = list(map(int, input().split()))
SL = list(input())
"""
# --------------------------------------------
dp = None
def main():
print((input().count("1")))
main()
| import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(10000)
# Debug output
def chkprint(*args):
names = {id(v): k for k, v in list(inspect.currentframe().f_back.f_locals.items())}
print((", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args)))
# Binary converter
def to_bin(x):
return bin(x)[2:]
def li_input():
return [int(_) for _ in input().split()]
# --------------------------------------------
dp = None
def main():
print((input().count("1")))
main()
| false | 4.761905 | [
"-# Set 2 dimension list",
"-def dim2input(N):",
"- li = []",
"- for _ in range(N):",
"- li.append(list(map(int, eval(input()))))",
"- return li",
"+def li_input():",
"+ return [int(_) for _ in input().split()]",
"-\"\"\" input template",
"-S = input()",
"-N = int(input())",
"-L = list(map(int, input().split()))",
"-a, b = list(map(int, input().split()))",
"-SL = list(input())",
"-\"\"\""
] | false | 0.103054 | 0.097524 | 1.056711 | [
"s390897405",
"s940498998"
] |
u268516119 | p03680 | python | s380708661 | s378128269 | 644 | 202 | 106,456 | 7,852 | Accepted | Accepted | 68.63 | import sys
sys.setrecursionlimit(500000)
N=int(eval(input()))
A=[int(eval(input()))-1 for _ in range(N)]
result=[False]*N
def next(k):
newlight=A[k]
if k==1:
return(1)
elif result[k]:
return(0)
else:
result[k]=True
return(next(newlight))
if not next(0):
print((-1))
else:print((sum(result))) | N=int(eval(input()))
A=[int(eval(input()))-1 for _ in range(N)]
result=[False]*N
k=0
while 1:
newlight=A[k]
if k==1:
ans=0
break
elif result[k]:
ans=1
break
else:
result[k]=True
k=newlight
if ans:
print((-1))
else:print((sum(result))) | 17 | 18 | 304 | 252 | import sys
sys.setrecursionlimit(500000)
N = int(eval(input()))
A = [int(eval(input())) - 1 for _ in range(N)]
result = [False] * N
def next(k):
newlight = A[k]
if k == 1:
return 1
elif result[k]:
return 0
else:
result[k] = True
return next(newlight)
if not next(0):
print((-1))
else:
print((sum(result)))
| N = int(eval(input()))
A = [int(eval(input())) - 1 for _ in range(N)]
result = [False] * N
k = 0
while 1:
newlight = A[k]
if k == 1:
ans = 0
break
elif result[k]:
ans = 1
break
else:
result[k] = True
k = newlight
if ans:
print((-1))
else:
print((sum(result)))
| false | 5.555556 | [
"-import sys",
"-",
"-sys.setrecursionlimit(500000)",
"-",
"-",
"-def next(k):",
"+k = 0",
"+while 1:",
"- return 1",
"+ ans = 0",
"+ break",
"- return 0",
"+ ans = 1",
"+ break",
"- return next(newlight)",
"-",
"-",
"-if not next(0):",
"+ k = newlight",
"+if ans:"
] | false | 0.036714 | 0.079324 | 0.46283 | [
"s380708661",
"s378128269"
] |
u080364835 | p03644 | python | s650591969 | s110297647 | 28 | 25 | 9,084 | 9,124 | Accepted | Accepted | 10.71 | n = int(eval(input()))
ans, cnt = 1, 0
for i in range(1, n+1):
j = i
t_cnt = 0
if i%2 == 0:
# print(i)
while i%2 == 0:
i = i//2
t_cnt += 1
# print(i, t_cnt)
if t_cnt >= cnt:
ans = j
cnt = t_cnt
print(ans) | import math
n = int(eval(input()))
ans, i = 0, 1
while ans <= n:
ans = 2**i
i += 1
print((ans//2)) | 16 | 9 | 310 | 108 | n = int(eval(input()))
ans, cnt = 1, 0
for i in range(1, n + 1):
j = i
t_cnt = 0
if i % 2 == 0:
# print(i)
while i % 2 == 0:
i = i // 2
t_cnt += 1
# print(i, t_cnt)
if t_cnt >= cnt:
ans = j
cnt = t_cnt
print(ans)
| import math
n = int(eval(input()))
ans, i = 0, 1
while ans <= n:
ans = 2**i
i += 1
print((ans // 2))
| false | 43.75 | [
"+import math",
"+",
"-ans, cnt = 1, 0",
"-for i in range(1, n + 1):",
"- j = i",
"- t_cnt = 0",
"- if i % 2 == 0:",
"- # print(i)",
"- while i % 2 == 0:",
"- i = i // 2",
"- t_cnt += 1",
"- # print(i, t_cnt)",
"- if t_cnt >= cnt:",
"- ans = j",
"- cnt = t_cnt",
"-print(ans)",
"+ans, i = 0, 1",
"+while ans <= n:",
"+ ans = 2**i",
"+ i += 1",
"+print((ans // 2))"
] | false | 0.041913 | 0.032718 | 1.281031 | [
"s650591969",
"s110297647"
] |
u083960235 | p02819 | python | s145531167 | s849775767 | 46 | 41 | 5,200 | 5,168 | Accepted | Accepted | 10.87 | import sys, re, os
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 S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
# 最小公倍数
def gcd(a, b):
if a < b:
a, b = b, a
while a % b != 0:
a, b = b, a % b
return b
# 最大公約数
def lcm(a, b):
y = a*b / gcd(a, b)
return int(y)
def primes_for(n):
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, n + 1):
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return [i for i in range(n + 1) if is_prime[i]]
# O(√A)
def isPrime(n):
if n < 2:
# 2未満は素数でない
return False
if n == 2:
# 2は素数
return True
for p in range(2, n):
if n % p == 0:
# nまでの数で割り切れたら素数ではない
return False
# nまでの数で割り切れなかったら素数
return True
x = INT()
while isPrime(x) == False:
x = x + 1
print(x) | import sys, re, os
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
from bisect import bisect, bisect_left, bisect_right
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
def sieve(n):
is_prime = [True for _ in range(n+1)]
is_prime[0] = False
for i in range(2, n+1):
if is_prime[i-1]:
j = 2 * i
while j <= n:
is_prime[j-1] = False
j += i
table = [ i for i in range(1, n+1) if is_prime[i-1]]
return table
def is_prime(n):
for i in range(2, n + 1):
if i * i > n:
break
if n % i == 0:
return False
return n != 1
while 1:
if is_prime(N) == True:
print(N)
exit()
else:
N += 1
| 62 | 52 | 1,465 | 1,389 | import sys, re, os
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 S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# 最小公倍数
def gcd(a, b):
if a < b:
a, b = b, a
while a % b != 0:
a, b = b, a % b
return b
# 最大公約数
def lcm(a, b):
y = a * b / gcd(a, b)
return int(y)
def primes_for(n):
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, n + 1):
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return [i for i in range(n + 1) if is_prime[i]]
# O(√A)
def isPrime(n):
if n < 2:
# 2未満は素数でない
return False
if n == 2:
# 2は素数
return True
for p in range(2, n):
if n % p == 0:
# nまでの数で割り切れたら素数ではない
return False
# nまでの数で割り切れなかったら素数
return True
x = INT()
while isPrime(x) == False:
x = x + 1
print(x)
| import sys, re, os
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
from bisect import bisect, bisect_left, bisect_right
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
def sieve(n):
is_prime = [True for _ in range(n + 1)]
is_prime[0] = False
for i in range(2, n + 1):
if is_prime[i - 1]:
j = 2 * i
while j <= n:
is_prime[j - 1] = False
j += i
table = [i for i in range(1, n + 1) if is_prime[i - 1]]
return table
def is_prime(n):
for i in range(2, n + 1):
if i * i > n:
break
if n % i == 0:
return False
return n != 1
while 1:
if is_prime(N) == True:
print(N)
exit()
else:
N += 1
| false | 16.129032 | [
"+from bisect import bisect, bisect_left, bisect_right",
"-# 最小公倍数",
"-def gcd(a, b):",
"- if a < b:",
"- a, b = b, a",
"- while a % b != 0:",
"- a, b = b, a % b",
"- return b",
"+N = INT()",
"-# 最大公約数",
"-def lcm(a, b):",
"- y = a * b / gcd(a, b)",
"- return int(y)",
"+def sieve(n):",
"+ is_prime = [True for _ in range(n + 1)]",
"+ is_prime[0] = False",
"+ for i in range(2, n + 1):",
"+ if is_prime[i - 1]:",
"+ j = 2 * i",
"+ while j <= n:",
"+ is_prime[j - 1] = False",
"+ j += i",
"+ table = [i for i in range(1, n + 1) if is_prime[i - 1]]",
"+ return table",
"-def primes_for(n):",
"- is_prime = [True] * (n + 1)",
"- is_prime[0] = False",
"- is_prime[1] = False",
"+def is_prime(n):",
"- for j in range(i * 2, n + 1, i):",
"- is_prime[j] = False",
"- return [i for i in range(n + 1) if is_prime[i]]",
"+ if i * i > n:",
"+ break",
"+ if n % i == 0:",
"+ return False",
"+ return n != 1",
"-# O(√A)",
"-def isPrime(n):",
"- if n < 2:",
"- # 2未満は素数でない",
"- return False",
"- if n == 2:",
"- # 2は素数",
"- return True",
"- for p in range(2, n):",
"- if n % p == 0:",
"- # nまでの数で割り切れたら素数ではない",
"- return False",
"- # nまでの数で割り切れなかったら素数",
"- return True",
"-",
"-",
"-x = INT()",
"-while isPrime(x) == False:",
"- x = x + 1",
"-print(x)",
"+while 1:",
"+ if is_prime(N) == True:",
"+ print(N)",
"+ exit()",
"+ else:",
"+ N += 1"
] | false | 0.053529 | 0.042377 | 1.263166 | [
"s145531167",
"s849775767"
] |
u936985471 | p03599 | python | s950595895 | s279078016 | 137 | 34 | 3,064 | 9,208 | Accepted | Accepted | 75.18 | import sys
readline = sys.stdin.readline
# A + Bの組み合わせはせいぜい1~30のうち作れる数字のみなので全探索
A,B,C,D,E,F = list(map(int,readline().split()))
ans = [0,0]
maxrate = 0.0
for a in range(0,F,100 * A):
for b in range(0,F,100 * B):
if a == 0 and b == 0:
continue
if a + b > F:
break
water = a + b
# waterに対して溶ける最大量は (a + b) * E
limit = min(((a + b) // 100) * E, F - water)
maxsugar = 0
for c in range(0,limit + 1,C):
for d in range(0,limit + 1,D):
if c + d > limit:
break
if c + d > maxsugar:
maxsugar = c + d
rate = maxsugar / (water + maxsugar)
if rate > maxrate:
maxrate = rate
ans = [water + maxsugar, maxsugar]
if maxrate == 0.0:
print((min(A,B) * 100, 0))
exit(0)
print((*ans)) | import sys
readline = sys.stdin.readline
# 作れる水の量を全探索(せいぜい30種類)
# 各水の量に対して、溶かせる砂糖の最大値は決まる(DPする)
# 最大値とすることができる砂糖に最も近づいたら割合を求め、答えの最大値を更新する
A,B,C,D,E,F = list(map(int,readline().split()))
max_rate = -1
ans_water = 0
ans_sugar = 0
for a in range(30):
for b in range(30):
if a * A * 100 + b * B * 100 >= F:
continue
water = a * A * 100 + b * B * 100
if water == 0:
continue
max_sugar = water * E // 100 # 溶ける砂糖の最大値
if max_sugar + water > F:
max_sugar = F - water
dp = [False] * (max_sugar + 1)
dp[0] = True
for i in range(len(dp)):
if dp[i]:
if i + C >= len(dp):
break
dp[i + C] = True
for i in range(len(dp)):
if dp[i]:
if i + D >= len(dp):
break
dp[i + D] = True
for i in range(len(dp) - 1, -1, -1):
if dp[i]:
rate = (i * 100) / (water + i)
break
if rate >= max_rate:
max_rate = rate
ans_water = water
ans_sugar = i
print((ans_water + ans_sugar,ans_sugar)) | 35 | 46 | 824 | 1,087 | import sys
readline = sys.stdin.readline
# A + Bの組み合わせはせいぜい1~30のうち作れる数字のみなので全探索
A, B, C, D, E, F = list(map(int, readline().split()))
ans = [0, 0]
maxrate = 0.0
for a in range(0, F, 100 * A):
for b in range(0, F, 100 * B):
if a == 0 and b == 0:
continue
if a + b > F:
break
water = a + b
# waterに対して溶ける最大量は (a + b) * E
limit = min(((a + b) // 100) * E, F - water)
maxsugar = 0
for c in range(0, limit + 1, C):
for d in range(0, limit + 1, D):
if c + d > limit:
break
if c + d > maxsugar:
maxsugar = c + d
rate = maxsugar / (water + maxsugar)
if rate > maxrate:
maxrate = rate
ans = [water + maxsugar, maxsugar]
if maxrate == 0.0:
print((min(A, B) * 100, 0))
exit(0)
print((*ans))
| import sys
readline = sys.stdin.readline
# 作れる水の量を全探索(せいぜい30種類)
# 各水の量に対して、溶かせる砂糖の最大値は決まる(DPする)
# 最大値とすることができる砂糖に最も近づいたら割合を求め、答えの最大値を更新する
A, B, C, D, E, F = list(map(int, readline().split()))
max_rate = -1
ans_water = 0
ans_sugar = 0
for a in range(30):
for b in range(30):
if a * A * 100 + b * B * 100 >= F:
continue
water = a * A * 100 + b * B * 100
if water == 0:
continue
max_sugar = water * E // 100 # 溶ける砂糖の最大値
if max_sugar + water > F:
max_sugar = F - water
dp = [False] * (max_sugar + 1)
dp[0] = True
for i in range(len(dp)):
if dp[i]:
if i + C >= len(dp):
break
dp[i + C] = True
for i in range(len(dp)):
if dp[i]:
if i + D >= len(dp):
break
dp[i + D] = True
for i in range(len(dp) - 1, -1, -1):
if dp[i]:
rate = (i * 100) / (water + i)
break
if rate >= max_rate:
max_rate = rate
ans_water = water
ans_sugar = i
print((ans_water + ans_sugar, ans_sugar))
| false | 23.913043 | [
"-# A + Bの組み合わせはせいぜい1~30のうち作れる数字のみなので全探索",
"+# 作れる水の量を全探索(せいぜい30種類)",
"+# 各水の量に対して、溶かせる砂糖の最大値は決まる(DPする)",
"+# 最大値とすることができる砂糖に最も近づいたら割合を求め、答えの最大値を更新する",
"-ans = [0, 0]",
"-maxrate = 0.0",
"-for a in range(0, F, 100 * A):",
"- for b in range(0, F, 100 * B):",
"- if a == 0 and b == 0:",
"+max_rate = -1",
"+ans_water = 0",
"+ans_sugar = 0",
"+for a in range(30):",
"+ for b in range(30):",
"+ if a * A * 100 + b * B * 100 >= F:",
"- if a + b > F:",
"- break",
"- water = a + b",
"- # waterに対して溶ける最大量は (a + b) * E",
"- limit = min(((a + b) // 100) * E, F - water)",
"- maxsugar = 0",
"- for c in range(0, limit + 1, C):",
"- for d in range(0, limit + 1, D):",
"- if c + d > limit:",
"+ water = a * A * 100 + b * B * 100",
"+ if water == 0:",
"+ continue",
"+ max_sugar = water * E // 100 # 溶ける砂糖の最大値",
"+ if max_sugar + water > F:",
"+ max_sugar = F - water",
"+ dp = [False] * (max_sugar + 1)",
"+ dp[0] = True",
"+ for i in range(len(dp)):",
"+ if dp[i]:",
"+ if i + C >= len(dp):",
"- if c + d > maxsugar:",
"- maxsugar = c + d",
"- rate = maxsugar / (water + maxsugar)",
"- if rate > maxrate:",
"- maxrate = rate",
"- ans = [water + maxsugar, maxsugar]",
"-if maxrate == 0.0:",
"- print((min(A, B) * 100, 0))",
"- exit(0)",
"-print((*ans))",
"+ dp[i + C] = True",
"+ for i in range(len(dp)):",
"+ if dp[i]:",
"+ if i + D >= len(dp):",
"+ break",
"+ dp[i + D] = True",
"+ for i in range(len(dp) - 1, -1, -1):",
"+ if dp[i]:",
"+ rate = (i * 100) / (water + i)",
"+ break",
"+ if rate >= max_rate:",
"+ max_rate = rate",
"+ ans_water = water",
"+ ans_sugar = i",
"+print((ans_water + ans_sugar, ans_sugar))"
] | false | 0.076317 | 0.083989 | 0.908648 | [
"s950595895",
"s279078016"
] |
u622045059 | p02900 | python | s932593501 | s682630488 | 265 | 128 | 5,048 | 5,292 | Accepted | Accepted | 51.7 | from fractions import gcd
A,B = list(map(int, input().split()))
g=gcd(A,B)
def prime_factorization(n):
prime_num = []
for i in range(2, int(n**.5)+1):
num = 0
while True:
x,y = divmod(n, i)
if y!= 0:
break
n = x
num += 1
if num>0:
prime_num.append(i)
if n > 1:
prime_num.append(n)
return prime_num
print((len(prime_factorization(g))+1))
| import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')
def sieves_of_e(n):
is_prime = [True] * (n+1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5)+1):
if not is_prime[i]: continue
for j in range(i * 2, n+1, i): is_prime[j] = False
return is_prime
def prime_factorize(n):
res = []
for i in range(2, int(n**0.5)+1):
if n % i != 0: continue
ex = 0
while (n % i == 0):
ex += 1
n //= i
res.append((i, ex))
if n != 1: res.append((n, 1))
return res
A,B = imn()
pf = prime_factorize(gcd(A,B))
print(len(pf)+1)
| 19 | 67 | 471 | 2,231 | from fractions import gcd
A, B = list(map(int, input().split()))
g = gcd(A, B)
def prime_factorization(n):
prime_num = []
for i in range(2, int(n**0.5) + 1):
num = 0
while True:
x, y = divmod(n, i)
if y != 0:
break
n = x
num += 1
if num > 0:
prime_num.append(i)
if n > 1:
prime_num.append(n)
return prime_num
print((len(prime_factorization(g)) + 1))
| import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7
INF = float("inf") # 無限大
def gcd(a, b):
return fractions.gcd(a, b) # 最大公約数
def lcm(a, b):
return (a * b) // fractions.gcd(a, b) # 最小公倍数
def iin():
return int(sys.stdin.readline()) # 整数読み込み
def ifn():
return float(sys.stdin.readline()) # 浮動小数点読み込み
def isn():
return sys.stdin.readline().split() # 文字列読み込み
def imn():
return map(int, sys.stdin.readline().split()) # 整数map取得
def imnn():
return map(lambda x: int(x) - 1, sys.stdin.readline().split()) # 整数-1map取得
def fmn():
return map(float, sys.stdin.readline().split()) # 浮動小数点map取得
def iln():
return list(map(int, sys.stdin.readline().split())) # 整数リスト取得
def iln_s():
return sorted(iln()) # 昇順の整数リスト取得
def iln_r():
return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln():
return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=""):
return s.join(l) # リストを文字列に変換
def perm(l, n):
return itertools.permutations(l, n) # 順列取得
def perm_count(n, r):
return math.factorial(n) // math.factorial(n - r) # 順列の総数
def comb(l, n):
return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) # 組み合わせの総数
def two_distance(a, b, c, d):
return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2点間の距離
def m_add(a, b):
return (a + b) % MOD
def print_list(l):
print(*l, sep="\n")
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def No():
print("No")
def sieves_of_e(n):
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return is_prime
def prime_factorize(n):
res = []
for i in range(2, int(n**0.5) + 1):
if n % i != 0:
continue
ex = 0
while n % i == 0:
ex += 1
n //= i
res.append((i, ex))
if n != 1:
res.append((n, 1))
return res
A, B = imn()
pf = prime_factorize(gcd(A, B))
print(len(pf) + 1)
| false | 71.641791 | [
"-from fractions import gcd",
"+import math",
"+import fractions",
"+import bisect",
"+import collections",
"+import itertools",
"+import heapq",
"+import string",
"+import sys",
"+import copy",
"+from decimal import *",
"+from collections import deque",
"-A, B = list(map(int, input().split()))",
"-g = gcd(A, B)",
"+sys.setrecursionlimit(10**7)",
"+MOD = 10**9 + 7",
"+INF = float(\"inf\") # 無限大",
"-def prime_factorization(n):",
"- prime_num = []",
"- for i in range(2, int(n**0.5) + 1):",
"- num = 0",
"- while True:",
"- x, y = divmod(n, i)",
"- if y != 0:",
"- break",
"- n = x",
"- num += 1",
"- if num > 0:",
"- prime_num.append(i)",
"- if n > 1:",
"- prime_num.append(n)",
"- return prime_num",
"+def gcd(a, b):",
"+ return fractions.gcd(a, b) # 最大公約数",
"-print((len(prime_factorization(g)) + 1))",
"+def lcm(a, b):",
"+ return (a * b) // fractions.gcd(a, b) # 最小公倍数",
"+",
"+",
"+def iin():",
"+ return int(sys.stdin.readline()) # 整数読み込み",
"+",
"+",
"+def ifn():",
"+ return float(sys.stdin.readline()) # 浮動小数点読み込み",
"+",
"+",
"+def isn():",
"+ return sys.stdin.readline().split() # 文字列読み込み",
"+",
"+",
"+def imn():",
"+ return map(int, sys.stdin.readline().split()) # 整数map取得",
"+",
"+",
"+def imnn():",
"+ return map(lambda x: int(x) - 1, sys.stdin.readline().split()) # 整数-1map取得",
"+",
"+",
"+def fmn():",
"+ return map(float, sys.stdin.readline().split()) # 浮動小数点map取得",
"+",
"+",
"+def iln():",
"+ return list(map(int, sys.stdin.readline().split())) # 整数リスト取得",
"+",
"+",
"+def iln_s():",
"+ return sorted(iln()) # 昇順の整数リスト取得",
"+",
"+",
"+def iln_r():",
"+ return sorted(iln(), reverse=True) # 降順の整数リスト取得",
"+",
"+",
"+def fln():",
"+ return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得",
"+",
"+",
"+def join(l, s=\"\"):",
"+ return s.join(l) # リストを文字列に変換",
"+",
"+",
"+def perm(l, n):",
"+ return itertools.permutations(l, n) # 順列取得",
"+",
"+",
"+def perm_count(n, r):",
"+ return math.factorial(n) // math.factorial(n - r) # 順列の総数",
"+",
"+",
"+def comb(l, n):",
"+ return itertools.combinations(l, n) # 組み合わせ取得",
"+",
"+",
"+def comb_count(n, r):",
"+ return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) # 組み合わせの総数",
"+",
"+",
"+def two_distance(a, b, c, d):",
"+ return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2点間の距離",
"+",
"+",
"+def m_add(a, b):",
"+ return (a + b) % MOD",
"+",
"+",
"+def print_list(l):",
"+ print(*l, sep=\"\\n\")",
"+",
"+",
"+def Yes():",
"+ print(\"Yes\")",
"+",
"+",
"+def No():",
"+ print(\"No\")",
"+",
"+",
"+def YES():",
"+ print(\"YES\")",
"+",
"+",
"+def No():",
"+ print(\"No\")",
"+",
"+",
"+def sieves_of_e(n):",
"+ is_prime = [True] * (n + 1)",
"+ is_prime[0] = False",
"+ is_prime[1] = False",
"+ for i in range(2, int(n**0.5) + 1):",
"+ if not is_prime[i]:",
"+ continue",
"+ for j in range(i * 2, n + 1, i):",
"+ is_prime[j] = False",
"+ return is_prime",
"+",
"+",
"+def prime_factorize(n):",
"+ res = []",
"+ for i in range(2, int(n**0.5) + 1):",
"+ if n % i != 0:",
"+ continue",
"+ ex = 0",
"+ while n % i == 0:",
"+ ex += 1",
"+ n //= i",
"+ res.append((i, ex))",
"+ if n != 1:",
"+ res.append((n, 1))",
"+ return res",
"+",
"+",
"+A, B = imn()",
"+pf = prime_factorize(gcd(A, B))",
"+print(len(pf) + 1)"
] | false | 0.043558 | 0.046437 | 0.938013 | [
"s932593501",
"s682630488"
] |
u600402037 | p02660 | python | s602400235 | s543289088 | 162 | 96 | 40,360 | 9,212 | Accepted | Accepted | 40.74 | # coding: utf-8
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
U = 10 ** 7 + 10
is_prime = np.zeros(U, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, U, 2):
if p*p > U:
break
if is_prime[p]:
is_prime[p*p::p+p] = 0
M = 10 ** 6
small_primes = np.where(is_prime[:M])[0].tolist()
N = ir()
answer = 0
used = set([1])
for p in small_primes:
d = p
while N%d == 0:
answer += 1
N //= d
used.add(d)
d *= p
while N%p == 0:
N //= p
if N > 1 and N not in used:
answer += 1
print(answer)
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def prime_factorize(n): # Nの素因数分解
A = []
while n % 2 == 0:
A.append(2); n //= 2
f = 3
while f * f <= n:
if n % f == 0:
A.append(f); n //= f
else:
f += 2
if n != 1:
A.append(n)
return A
N = ir()
primes = set(prime_factorize(N))
answer = 0
for p in primes:
d = p
while N%d == 0:
answer += 1
N //= d
d *= p
print(answer)
| 38 | 32 | 703 | 600 | # coding: utf-8
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
U = 10**7 + 10
is_prime = np.zeros(U, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, U, 2):
if p * p > U:
break
if is_prime[p]:
is_prime[p * p :: p + p] = 0
M = 10**6
small_primes = np.where(is_prime[:M])[0].tolist()
N = ir()
answer = 0
used = set([1])
for p in small_primes:
d = p
while N % d == 0:
answer += 1
N //= d
used.add(d)
d *= p
while N % p == 0:
N //= p
if N > 1 and N not in used:
answer += 1
print(answer)
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def prime_factorize(n): # Nの素因数分解
A = []
while n % 2 == 0:
A.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
A.append(f)
n //= f
else:
f += 2
if n != 1:
A.append(n)
return A
N = ir()
primes = set(prime_factorize(N))
answer = 0
for p in primes:
d = p
while N % d == 0:
answer += 1
N //= d
d *= p
print(answer)
| false | 15.789474 | [
"-import numpy as np",
"-U = 10**7 + 10",
"-is_prime = np.zeros(U, np.bool)",
"-is_prime[2] = 1",
"-is_prime[3::2] = 1",
"-for p in range(3, U, 2):",
"- if p * p > U:",
"- break",
"- if is_prime[p]:",
"- is_prime[p * p :: p + p] = 0",
"-M = 10**6",
"-small_primes = np.where(is_prime[:M])[0].tolist()",
"+",
"+",
"+def prime_factorize(n): # Nの素因数分解",
"+ A = []",
"+ while n % 2 == 0:",
"+ A.append(2)",
"+ n //= 2",
"+ f = 3",
"+ while f * f <= n:",
"+ if n % f == 0:",
"+ A.append(f)",
"+ n //= f",
"+ else:",
"+ f += 2",
"+ if n != 1:",
"+ A.append(n)",
"+ return A",
"+",
"+",
"+primes = set(prime_factorize(N))",
"-used = set([1])",
"-for p in small_primes:",
"+for p in primes:",
"- used.add(d)",
"- while N % p == 0:",
"- N //= p",
"-if N > 1 and N not in used:",
"- answer += 1"
] | false | 0.677078 | 0.039436 | 17.168876 | [
"s602400235",
"s543289088"
] |
u648881683 | p03557 | python | s241854780 | s259445899 | 789 | 341 | 23,328 | 22,720 | Accepted | Accepted | 56.78 | import sys
input = lambda: sys.stdin.readline().rstrip()
def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
def binsearch_left(a, x):
l = -1
r = len(a)
while r-l>1:
m = (l+r)//2
if x<a[m]:
r = m
else:
l = m
return r
def binsearch_right(a, x):
l = -1
r = len(a)
while r-l>1:
m = (l+r)//2
if x<=a[m]:
r = m
else:
l = m
return r
ans = 0
for b in B:
a_r = binsearch_right(A, b)
c_l = binsearch_left(C, b)
ans += a_r * (N - c_l)
print(ans)
if __name__ == '__main__':
resolve()
| import sys
input = lambda: sys.stdin.readline().rstrip()
import bisect
def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
ans = 0
for b in B:
a_r = bisect.bisect_left(A, b)
c_l = bisect.bisect_right(C, b)
ans += a_r * (N - c_l)
print(ans)
if __name__ == '__main__':
resolve()
| 45 | 23 | 916 | 475 | import sys
input = lambda: sys.stdin.readline().rstrip()
def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
def binsearch_left(a, x):
l = -1
r = len(a)
while r - l > 1:
m = (l + r) // 2
if x < a[m]:
r = m
else:
l = m
return r
def binsearch_right(a, x):
l = -1
r = len(a)
while r - l > 1:
m = (l + r) // 2
if x <= a[m]:
r = m
else:
l = m
return r
ans = 0
for b in B:
a_r = binsearch_right(A, b)
c_l = binsearch_left(C, b)
ans += a_r * (N - c_l)
print(ans)
if __name__ == "__main__":
resolve()
| import sys
input = lambda: sys.stdin.readline().rstrip()
import bisect
def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
ans = 0
for b in B:
a_r = bisect.bisect_left(A, b)
c_l = bisect.bisect_right(C, b)
ans += a_r * (N - c_l)
print(ans)
if __name__ == "__main__":
resolve()
| false | 48.888889 | [
"+import bisect",
"- B.sort()",
"-",
"- def binsearch_left(a, x):",
"- l = -1",
"- r = len(a)",
"- while r - l > 1:",
"- m = (l + r) // 2",
"- if x < a[m]:",
"- r = m",
"- else:",
"- l = m",
"- return r",
"-",
"- def binsearch_right(a, x):",
"- l = -1",
"- r = len(a)",
"- while r - l > 1:",
"- m = (l + r) // 2",
"- if x <= a[m]:",
"- r = m",
"- else:",
"- l = m",
"- return r",
"-",
"- a_r = binsearch_right(A, b)",
"- c_l = binsearch_left(C, b)",
"+ a_r = bisect.bisect_left(A, b)",
"+ c_l = bisect.bisect_right(C, b)"
] | false | 0.046147 | 0.046579 | 0.990726 | [
"s241854780",
"s259445899"
] |
u901850884 | p02570 | python | s601011757 | s221427055 | 33 | 29 | 9,160 | 9,148 | Accepted | Accepted | 12.12 | d,t,s = (int(y) for y in input().split())
x=d/s
if x>t:
print("No")
else:
print("Yes")
| d,t,s=(int(x) for x in input().split())
if d<=t*s:
print("Yes")
else :
print("No") | 8 | 5 | 107 | 94 | d, t, s = (int(y) for y in input().split())
x = d / s
if x > t:
print("No")
else:
print("Yes")
| d, t, s = (int(x) for x in input().split())
if d <= t * s:
print("Yes")
else:
print("No")
| false | 37.5 | [
"-d, t, s = (int(y) for y in input().split())",
"-x = d / s",
"-if x > t:",
"+d, t, s = (int(x) for x in input().split())",
"+if d <= t * s:",
"+ print(\"Yes\")",
"+else:",
"-else:",
"- print(\"Yes\")"
] | false | 0.042437 | 0.123793 | 0.342806 | [
"s601011757",
"s221427055"
] |
u625864724 | p02573 | python | s476691390 | s211181631 | 829 | 616 | 16,824 | 16,760 | Accepted | Accepted | 25.69 | n, m = list(map(int,input().split()))
par = [-1 for i in range(n + 1)]
par[0] = 0
def find(x):
if (par[x] < 0):
return x
else:
x = par[x]
return find(x)
def unit(x, y):
if (find(x) == find(y)):
pass
else:
x = find(x)
y = find(y)
if (x > y):
x, y = y, x
s = par[y]
par[y] = x
par[x] = par[x] + s
for i in range(m):
a, b = list(map(int,input().split()))
unit(a, b)
par.sort()
print((-par[0]))
| n, m = list(map(int,input().split()))
lst = [-1 for i in range(n + 1)]
lst[0] = 0
def find(x):
if(lst[x] < 0):
return(x)
else:
return(find(lst[x]))
def unit(x, y):
xr = find(x)
yr = find(y)
if (xr == yr):
pass
else:
if (xr > yr):
x, y = y, x
xr, yr = yr, xr
lst[xr] = lst[xr] + lst[yr]
lst[yr] = xr
for i in range(m):
a, b = list(map(int,input().split()))
unit(a, b)
print((-(min(lst))))
| 27 | 26 | 521 | 510 | n, m = list(map(int, input().split()))
par = [-1 for i in range(n + 1)]
par[0] = 0
def find(x):
if par[x] < 0:
return x
else:
x = par[x]
return find(x)
def unit(x, y):
if find(x) == find(y):
pass
else:
x = find(x)
y = find(y)
if x > y:
x, y = y, x
s = par[y]
par[y] = x
par[x] = par[x] + s
for i in range(m):
a, b = list(map(int, input().split()))
unit(a, b)
par.sort()
print((-par[0]))
| n, m = list(map(int, input().split()))
lst = [-1 for i in range(n + 1)]
lst[0] = 0
def find(x):
if lst[x] < 0:
return x
else:
return find(lst[x])
def unit(x, y):
xr = find(x)
yr = find(y)
if xr == yr:
pass
else:
if xr > yr:
x, y = y, x
xr, yr = yr, xr
lst[xr] = lst[xr] + lst[yr]
lst[yr] = xr
for i in range(m):
a, b = list(map(int, input().split()))
unit(a, b)
print((-(min(lst))))
| false | 3.703704 | [
"-par = [-1 for i in range(n + 1)]",
"-par[0] = 0",
"+lst = [-1 for i in range(n + 1)]",
"+lst[0] = 0",
"- if par[x] < 0:",
"+ if lst[x] < 0:",
"- x = par[x]",
"- return find(x)",
"+ return find(lst[x])",
"- if find(x) == find(y):",
"+ xr = find(x)",
"+ yr = find(y)",
"+ if xr == yr:",
"- x = find(x)",
"- y = find(y)",
"- if x > y:",
"+ if xr > yr:",
"- s = par[y]",
"- par[y] = x",
"- par[x] = par[x] + s",
"+ xr, yr = yr, xr",
"+ lst[xr] = lst[xr] + lst[yr]",
"+ lst[yr] = xr",
"-par.sort()",
"-print((-par[0]))",
"+print((-(min(lst))))"
] | false | 0.007564 | 0.144968 | 0.052176 | [
"s476691390",
"s211181631"
] |
u440566786 | p03181 | python | s655544643 | s108806795 | 1,203 | 1,004 | 132,400 | 129,840 | Accepted | Accepted | 16.54 | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
n, MOD = map(int,input().split())
if n == 1:
print(1)
return
E = [[] for _ in range(n)]
nv_to_idx = [{} for _ in range(n)]
for _ in range(n - 1):
u, v = map(int,input().split())
u -= 1; v -= 1
nv_to_idx[u][v] = len(E[u])
nv_to_idx[v][u] = len(E[v])
E[u].append(v)
E[v].append(u)
# tree DP
dp = [1] * n
deg = [len(E[v]) - 1 for v in range(n)]
deg[0] += 1
stack = [(0, -1)]
while stack:
v, p = stack.pop()
if v >= 0:
for nv in E[v]:
if nv == p:
continue
stack.append((~nv, v))
stack.append((nv, v))
else:
if deg[~v] == 0:
dp[p] = dp[p] * (dp[~v] + 1) % MOD
deg[p] -= 1
# rerooting
def rerooting(v, p):
# p-rooted -> dp[p] を v-rooted に modify
if p != -1:
idx = nv_to_idx[p][v]
p_res = 1
if idx > 0:
p_res *= cum_left[p][idx - 1]
if idx < len(E[p]) - 1:
p_res *= cum_right[p][idx + 1]
dp[p] = p_res % MOD
# monoid に対する cumulative sum を計算
if cum_left[v] is None:
left = [(dp[nv] + 1) % MOD for nv in E[v]]
right = [(dp[nv] + 1) % MOD for nv in E[v]]
k = len(E[v])
for i in range(k - 1):
left[i + 1] *= left[i]
left[i + 1] %= MOD
for i in range(k - 1, 0, -1):
right[i - 1] *= right[i]
right[i - 1] %= MOD
cum_left[v] = left
cum_right[v] = right
dp[v] = cum_left[v][-1]
ans = [None] * n
stack = [(0, -1)]
cum_left = [None] * n
cum_right = [None] * n
while stack:
v, p = stack.pop()
if v >= 0:
rerooting(v, p)
ans[v] = dp[v]
for nv in E[v]:
if nv == p:
continue
stack.append((~nv, v))
stack.append((nv, v))
else:
rerooting(p, ~v)
print(*ans, sep = '\n')
resolve()
| import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
n, MOD = map(int,input().split())
E = [[] for _ in range(n)]
nv_to_idx = [{} for _ in range(n)]
for _ in range(n - 1):
u, v = map(int,input().split())
u -= 1; v -= 1
nv_to_idx[u][v] = len(E[u])
nv_to_idx[v][u] = len(E[v])
E[u].append(v)
E[v].append(u)
# tree DP
dp = [1] * n
deg = [len(E[v]) - 1 for v in range(n)]
deg[0] += 1
stack = [(0, -1)]
while stack:
v, p = stack.pop()
if v >= 0:
for nv in E[v]:
if nv == p:
continue
stack.append((~nv, v))
stack.append((nv, v))
else:
if deg[~v] == 0:
dp[p] = dp[p] * (dp[~v] + 1) % MOD
deg[p] -= 1
# rerooting
def rerooting(v, p):
# p-rooted -> dp[p] を v-rooted に modify
if p != -1:
idx = nv_to_idx[p][v]
dp[p] = cum_left[p][idx] * cum_right[p][idx + 1] % MOD
# monoid に対する cumulative sum を計算
if cum_left[v] is None:
k = len(E[v])
left = [1] * (k + 1)
right = [1] * (k + 1)
for i in range(k):
left[i + 1] = left[i] * (dp[E[v][i]] + 1) % MOD
for i in range(k - 1, -1, -1):
right[i] = right[i + 1] * (dp[E[v][i]] + 1) % MOD
cum_left[v] = left
cum_right[v] = right
# dp[v] を v-rooted に modify
dp[v] = cum_left[v][-1]
ans = [None] * n
stack = [(0, -1)]
cum_left = [None] * n
cum_right = [None] * n
while stack:
v, p = stack.pop()
if v >= 0:
rerooting(v, p)
ans[v] = dp[v]
for nv in E[v]:
if nv == p:
continue
stack.append((~nv, v))
stack.append((nv, v))
else:
rerooting(p, ~v)
print(*ans, sep = '\n')
resolve()
| 85 | 76 | 2,393 | 2,165 | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda: sys.stdin.readline().rstrip()
def resolve():
n, MOD = map(int, input().split())
if n == 1:
print(1)
return
E = [[] for _ in range(n)]
nv_to_idx = [{} for _ in range(n)]
for _ in range(n - 1):
u, v = map(int, input().split())
u -= 1
v -= 1
nv_to_idx[u][v] = len(E[u])
nv_to_idx[v][u] = len(E[v])
E[u].append(v)
E[v].append(u)
# tree DP
dp = [1] * n
deg = [len(E[v]) - 1 for v in range(n)]
deg[0] += 1
stack = [(0, -1)]
while stack:
v, p = stack.pop()
if v >= 0:
for nv in E[v]:
if nv == p:
continue
stack.append((~nv, v))
stack.append((nv, v))
else:
if deg[~v] == 0:
dp[p] = dp[p] * (dp[~v] + 1) % MOD
deg[p] -= 1
# rerooting
def rerooting(v, p):
# p-rooted -> dp[p] を v-rooted に modify
if p != -1:
idx = nv_to_idx[p][v]
p_res = 1
if idx > 0:
p_res *= cum_left[p][idx - 1]
if idx < len(E[p]) - 1:
p_res *= cum_right[p][idx + 1]
dp[p] = p_res % MOD
# monoid に対する cumulative sum を計算
if cum_left[v] is None:
left = [(dp[nv] + 1) % MOD for nv in E[v]]
right = [(dp[nv] + 1) % MOD for nv in E[v]]
k = len(E[v])
for i in range(k - 1):
left[i + 1] *= left[i]
left[i + 1] %= MOD
for i in range(k - 1, 0, -1):
right[i - 1] *= right[i]
right[i - 1] %= MOD
cum_left[v] = left
cum_right[v] = right
dp[v] = cum_left[v][-1]
ans = [None] * n
stack = [(0, -1)]
cum_left = [None] * n
cum_right = [None] * n
while stack:
v, p = stack.pop()
if v >= 0:
rerooting(v, p)
ans[v] = dp[v]
for nv in E[v]:
if nv == p:
continue
stack.append((~nv, v))
stack.append((nv, v))
else:
rerooting(p, ~v)
print(*ans, sep="\n")
resolve()
| import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda: sys.stdin.readline().rstrip()
def resolve():
n, MOD = map(int, input().split())
E = [[] for _ in range(n)]
nv_to_idx = [{} for _ in range(n)]
for _ in range(n - 1):
u, v = map(int, input().split())
u -= 1
v -= 1
nv_to_idx[u][v] = len(E[u])
nv_to_idx[v][u] = len(E[v])
E[u].append(v)
E[v].append(u)
# tree DP
dp = [1] * n
deg = [len(E[v]) - 1 for v in range(n)]
deg[0] += 1
stack = [(0, -1)]
while stack:
v, p = stack.pop()
if v >= 0:
for nv in E[v]:
if nv == p:
continue
stack.append((~nv, v))
stack.append((nv, v))
else:
if deg[~v] == 0:
dp[p] = dp[p] * (dp[~v] + 1) % MOD
deg[p] -= 1
# rerooting
def rerooting(v, p):
# p-rooted -> dp[p] を v-rooted に modify
if p != -1:
idx = nv_to_idx[p][v]
dp[p] = cum_left[p][idx] * cum_right[p][idx + 1] % MOD
# monoid に対する cumulative sum を計算
if cum_left[v] is None:
k = len(E[v])
left = [1] * (k + 1)
right = [1] * (k + 1)
for i in range(k):
left[i + 1] = left[i] * (dp[E[v][i]] + 1) % MOD
for i in range(k - 1, -1, -1):
right[i] = right[i + 1] * (dp[E[v][i]] + 1) % MOD
cum_left[v] = left
cum_right[v] = right
# dp[v] を v-rooted に modify
dp[v] = cum_left[v][-1]
ans = [None] * n
stack = [(0, -1)]
cum_left = [None] * n
cum_right = [None] * n
while stack:
v, p = stack.pop()
if v >= 0:
rerooting(v, p)
ans[v] = dp[v]
for nv in E[v]:
if nv == p:
continue
stack.append((~nv, v))
stack.append((nv, v))
else:
rerooting(p, ~v)
print(*ans, sep="\n")
resolve()
| false | 10.588235 | [
"- if n == 1:",
"- print(1)",
"- return",
"- p_res = 1",
"- if idx > 0:",
"- p_res *= cum_left[p][idx - 1]",
"- if idx < len(E[p]) - 1:",
"- p_res *= cum_right[p][idx + 1]",
"- dp[p] = p_res % MOD",
"+ dp[p] = cum_left[p][idx] * cum_right[p][idx + 1] % MOD",
"- left = [(dp[nv] + 1) % MOD for nv in E[v]]",
"- right = [(dp[nv] + 1) % MOD for nv in E[v]]",
"- for i in range(k - 1):",
"- left[i + 1] *= left[i]",
"- left[i + 1] %= MOD",
"- for i in range(k - 1, 0, -1):",
"- right[i - 1] *= right[i]",
"- right[i - 1] %= MOD",
"+ left = [1] * (k + 1)",
"+ right = [1] * (k + 1)",
"+ for i in range(k):",
"+ left[i + 1] = left[i] * (dp[E[v][i]] + 1) % MOD",
"+ for i in range(k - 1, -1, -1):",
"+ right[i] = right[i + 1] * (dp[E[v][i]] + 1) % MOD",
"+ # dp[v] を v-rooted に modify"
] | false | 0.042371 | 0.042256 | 1.002733 | [
"s655544643",
"s108806795"
] |
u228223940 | p03157 | python | s566842302 | s596398447 | 825 | 469 | 67,592 | 66,824 | Accepted | Accepted | 43.15 | h,w = list(map(int,input().split()))
si = [eval(input()) for i in range(h)]
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
self.size = [1 for _ in range(n+1)]
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.size[y] += self.size[x]
else:
self.par[y] = x
self.size[x] += self.size[y]
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
ki = UnionFind(h*w)
vx = [0,1,0,-1]
vy = [1,0,-1,0]
for i in range(h):
for j in range(w):
if si[i][j] == '#':
for k in range(4):
ny = i + vy[k]
nx = j + vx[k]
if ny >= 0 and ny < h and nx >= 0 and nx < w:
if si[ny][nx] == '.':
#if ki.same_check(i*w+j,ny*w+nx) == True:
# continue
ki.union(i*w+j,ny*w+nx)
ans = 0
li = [0]*(h*w+1)
for i in range(h):
for j in range(w):
if si[i][j] == '.':
li[ki.find(i*w+j)] += 1
for i in range(h):
for j in range(w):
if si[i][j] == '#':
ans += li[ki.find(i*w+j)]
print(ans) | h,w = list(map(int,input().split()))
si = [eval(input()) for i in range(h)]
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
self.size = [1 for _ in range(n+1)]
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.size[y] += self.size[x]
else:
self.par[y] = x
self.size[x] += self.size[y]
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
ki = UnionFind(h*w)
vx = [0,1,0,-1]
vy = [1,0,-1,0]
for i in range(h):
for j in range(w):
if si[i][j] == '#':
for k in range(4):
ny = i + vy[k]
nx = j + vx[k]
if ny >= 0 and ny < h and nx >= 0 and nx < w:
if si[ny][nx] == '.':
if ki.same_check(i*w+j,ny*w+nx) == True:
continue
ki.union(i*w+j,ny*w+nx)
ans = 0
li = [0]*(h*w+1)
for i in range(h):
for j in range(w):
if si[i][j] == '.':
li[ki.find(i*w+j)] += 1
for i in range(h):
for j in range(w):
if si[i][j] == '#':
ans += li[ki.find(i*w+j)]
print(ans) | 65 | 65 | 1,668 | 1,666 | h, w = list(map(int, input().split()))
si = [eval(input()) for i in range(h)]
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n + 1)]
self.rank = [0] * (n + 1)
self.size = [1 for _ in range(n + 1)]
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.size[y] += self.size[x]
else:
self.par[y] = x
self.size[x] += self.size[y]
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
ki = UnionFind(h * w)
vx = [0, 1, 0, -1]
vy = [1, 0, -1, 0]
for i in range(h):
for j in range(w):
if si[i][j] == "#":
for k in range(4):
ny = i + vy[k]
nx = j + vx[k]
if ny >= 0 and ny < h and nx >= 0 and nx < w:
if si[ny][nx] == ".":
# if ki.same_check(i*w+j,ny*w+nx) == True:
# continue
ki.union(i * w + j, ny * w + nx)
ans = 0
li = [0] * (h * w + 1)
for i in range(h):
for j in range(w):
if si[i][j] == ".":
li[ki.find(i * w + j)] += 1
for i in range(h):
for j in range(w):
if si[i][j] == "#":
ans += li[ki.find(i * w + j)]
print(ans)
| h, w = list(map(int, input().split()))
si = [eval(input()) for i in range(h)]
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n + 1)]
self.rank = [0] * (n + 1)
self.size = [1 for _ in range(n + 1)]
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.size[y] += self.size[x]
else:
self.par[y] = x
self.size[x] += self.size[y]
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
ki = UnionFind(h * w)
vx = [0, 1, 0, -1]
vy = [1, 0, -1, 0]
for i in range(h):
for j in range(w):
if si[i][j] == "#":
for k in range(4):
ny = i + vy[k]
nx = j + vx[k]
if ny >= 0 and ny < h and nx >= 0 and nx < w:
if si[ny][nx] == ".":
if ki.same_check(i * w + j, ny * w + nx) == True:
continue
ki.union(i * w + j, ny * w + nx)
ans = 0
li = [0] * (h * w + 1)
for i in range(h):
for j in range(w):
if si[i][j] == ".":
li[ki.find(i * w + j)] += 1
for i in range(h):
for j in range(w):
if si[i][j] == "#":
ans += li[ki.find(i * w + j)]
print(ans)
| false | 0 | [
"- # if ki.same_check(i*w+j,ny*w+nx) == True:",
"- # continue",
"+ if ki.same_check(i * w + j, ny * w + nx) == True:",
"+ continue"
] | false | 0.038979 | 0.037727 | 1.033194 | [
"s566842302",
"s596398447"
] |
u883048396 | p03255 | python | s846813854 | s502058826 | 745 | 661 | 25,840 | 27,244 | Accepted | Accepted | 11.28 |
iN ,iX = [int(x) for x in input().split()]
aX = [int(x) for x in input().split()]
aCum = [0]*iN
aCum[0] = aX[0]
for i in range(1,iN):
aCum[i]=aCum[i-1]+aX[i]
def fCeil(iT,iR):
return -1 * iT // iR * -1
#マネして記法を圧縮してみたがどうだろう
def fCalcCost(iN,iX,aCum,iK):
return (iN + iK ) * iX + 5 * aCum[-1] +sum(2*aCum[-i*iK -1] for i in range(2,fCeil(iN,iK)))
iTotalCost = fCalcCost(iN,iX,aCum,1)
iULim = fCeil(iN,2) + 1
for iK in range(2,fCeil(iN,2)+1):
iThisCost = fCalcCost(iN,iX,aCum,iK)
if iThisCost > iTotalCost:
break
else:
iTotalCost = iThisCost
print(iTotalCost)
| iN ,iX = [int(x) for x in input().split()]
#かえって遅い?
aCum = [0]
for x in input().split():
aCum += [aCum[-1] + int(x)]
def fCeil(iT,iR):
return -1 * iT // iR * -1
def fCalcCost(iN,iX,aCum,iK):
iCost = (iN + iK ) * iX + 5 * aCum[-1]
for i in range(2,fCeil(iN,iK) ):
iCost += 2 * aCum[iN - i * iK ]
return iCost
#枝刈り
iTotalCost = fCalcCost(iN,iX,aCum,1)
for iK in range(2,fCeil(iN,2) + 1):
iThisCost = fCalcCost(iN,iX,aCum,iK)
if iThisCost > iTotalCost:
break
else:
iTotalCost = iThisCost
print(iTotalCost)
| 24 | 24 | 625 | 586 | iN, iX = [int(x) for x in input().split()]
aX = [int(x) for x in input().split()]
aCum = [0] * iN
aCum[0] = aX[0]
for i in range(1, iN):
aCum[i] = aCum[i - 1] + aX[i]
def fCeil(iT, iR):
return -1 * iT // iR * -1
# マネして記法を圧縮してみたがどうだろう
def fCalcCost(iN, iX, aCum, iK):
return (
(iN + iK) * iX
+ 5 * aCum[-1]
+ sum(2 * aCum[-i * iK - 1] for i in range(2, fCeil(iN, iK)))
)
iTotalCost = fCalcCost(iN, iX, aCum, 1)
iULim = fCeil(iN, 2) + 1
for iK in range(2, fCeil(iN, 2) + 1):
iThisCost = fCalcCost(iN, iX, aCum, iK)
if iThisCost > iTotalCost:
break
else:
iTotalCost = iThisCost
print(iTotalCost)
| iN, iX = [int(x) for x in input().split()]
# かえって遅い?
aCum = [0]
for x in input().split():
aCum += [aCum[-1] + int(x)]
def fCeil(iT, iR):
return -1 * iT // iR * -1
def fCalcCost(iN, iX, aCum, iK):
iCost = (iN + iK) * iX + 5 * aCum[-1]
for i in range(2, fCeil(iN, iK)):
iCost += 2 * aCum[iN - i * iK]
return iCost
# 枝刈り
iTotalCost = fCalcCost(iN, iX, aCum, 1)
for iK in range(2, fCeil(iN, 2) + 1):
iThisCost = fCalcCost(iN, iX, aCum, iK)
if iThisCost > iTotalCost:
break
else:
iTotalCost = iThisCost
print(iTotalCost)
| false | 0 | [
"-aX = [int(x) for x in input().split()]",
"-aCum = [0] * iN",
"-aCum[0] = aX[0]",
"-for i in range(1, iN):",
"- aCum[i] = aCum[i - 1] + aX[i]",
"+# かえって遅い?",
"+aCum = [0]",
"+for x in input().split():",
"+ aCum += [aCum[-1] + int(x)]",
"-# マネして記法を圧縮してみたがどうだろう",
"- return (",
"- (iN + iK) * iX",
"- + 5 * aCum[-1]",
"- + sum(2 * aCum[-i * iK - 1] for i in range(2, fCeil(iN, iK)))",
"- )",
"+ iCost = (iN + iK) * iX + 5 * aCum[-1]",
"+ for i in range(2, fCeil(iN, iK)):",
"+ iCost += 2 * aCum[iN - i * iK]",
"+ return iCost",
"+# 枝刈り",
"-iULim = fCeil(iN, 2) + 1"
] | false | 0.047701 | 0.137327 | 0.347355 | [
"s846813854",
"s502058826"
] |
u653999581 | p03160 | python | s767822457 | s334392811 | 140 | 121 | 13,924 | 13,928 | Accepted | Accepted | 13.57 | if __name__=='__main__':
N = int(eval(input()))
hi = [int(i) for i in input().split()]
dp = [0 for i in range(N)]
dp[1] = abs(hi[0]-hi[1])
for i in range(2,N):
dp_1 = dp[i-1] + abs(hi[i]-hi[i-1])
dp_2 = dp[i-2] + abs(hi[i]-hi[i-2])
dp[i] = min(dp_1,dp_2)
print((dp[N-1])) | if __name__=='__main__':
N = int(eval(input()))
hi = list(map(int,input().split()))
dp = [0]*N
dp[1] = abs(hi[0]-hi[1])
for i in range(2,N):
dp_1 = dp[i-1] + abs(hi[i]-hi[i-1])
dp_2 = dp[i-2] + abs(hi[i]-hi[i-2])
dp[i] = dp_1 if dp_1 < dp_2 else dp_2
print((dp[-1])) | 12 | 12 | 340 | 335 | if __name__ == "__main__":
N = int(eval(input()))
hi = [int(i) for i in input().split()]
dp = [0 for i in range(N)]
dp[1] = abs(hi[0] - hi[1])
for i in range(2, N):
dp_1 = dp[i - 1] + abs(hi[i] - hi[i - 1])
dp_2 = dp[i - 2] + abs(hi[i] - hi[i - 2])
dp[i] = min(dp_1, dp_2)
print((dp[N - 1]))
| if __name__ == "__main__":
N = int(eval(input()))
hi = list(map(int, input().split()))
dp = [0] * N
dp[1] = abs(hi[0] - hi[1])
for i in range(2, N):
dp_1 = dp[i - 1] + abs(hi[i] - hi[i - 1])
dp_2 = dp[i - 2] + abs(hi[i] - hi[i - 2])
dp[i] = dp_1 if dp_1 < dp_2 else dp_2
print((dp[-1]))
| false | 0 | [
"- hi = [int(i) for i in input().split()]",
"- dp = [0 for i in range(N)]",
"+ hi = list(map(int, input().split()))",
"+ dp = [0] * N",
"- dp[i] = min(dp_1, dp_2)",
"- print((dp[N - 1]))",
"+ dp[i] = dp_1 if dp_1 < dp_2 else dp_2",
"+ print((dp[-1]))"
] | false | 0.095187 | 0.113495 | 0.838688 | [
"s767822457",
"s334392811"
] |
u887207211 | p03162 | python | s811353914 | s453795913 | 1,022 | 436 | 47,328 | 30,580 | Accepted | Accepted | 57.34 | N = int(eval(input()))
A = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N+1)]
for i in range(N):
for j in range(3):
for k in range(3):
if j == k:
continue
dp[i+1][k] = max(dp[i+1][k], dp[i][j]+A[i][k])
print((max(dp[N]))) | N = int(eval(input()))
A = [list(map(int,input().split())) for _ in range(N)]
x = y = z = 0
for a,b,c in A:
x,y,z = max(y,z)+a,max(x,z)+b,max(x,y)+c
print((max(x,y,z))) | 12 | 7 | 285 | 169 | N = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3 for _ in range(N + 1)]
for i in range(N):
for j in range(3):
for k in range(3):
if j == k:
continue
dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + A[i][k])
print((max(dp[N])))
| N = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(N)]
x = y = z = 0
for a, b, c in A:
x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c
print((max(x, y, z)))
| false | 41.666667 | [
"-dp = [[0] * 3 for _ in range(N + 1)]",
"-for i in range(N):",
"- for j in range(3):",
"- for k in range(3):",
"- if j == k:",
"- continue",
"- dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + A[i][k])",
"-print((max(dp[N])))",
"+x = y = z = 0",
"+for a, b, c in A:",
"+ x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c",
"+print((max(x, y, z)))"
] | false | 0.093547 | 0.035626 | 2.625793 | [
"s811353914",
"s453795913"
] |
u251515715 | p03731 | python | s014133966 | s617265907 | 168 | 153 | 26,708 | 26,832 | Accepted | Accepted | 8.93 | n,t=list(map(int,input().split()))
a=list(map(int,input().split()))
a.append(10**10)
cnt=0
for i in range(n):
fir=a[i]
if a[i]+t>a[i+1]:
las=a[i+1]
else:
las=a[i]+t
cnt+=las-fir
print(cnt) | n,t=list(map(int,input().split()))
a=list(map(int,input().split()))
a.append(10**10)
cnt=0
for i in range(n):
if a[i]+t>a[i+1]:
cnt+=a[i+1]-a[i]
else:
cnt+=t
print(cnt) | 12 | 10 | 209 | 183 | n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(10**10)
cnt = 0
for i in range(n):
fir = a[i]
if a[i] + t > a[i + 1]:
las = a[i + 1]
else:
las = a[i] + t
cnt += las - fir
print(cnt)
| n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(10**10)
cnt = 0
for i in range(n):
if a[i] + t > a[i + 1]:
cnt += a[i + 1] - a[i]
else:
cnt += t
print(cnt)
| false | 16.666667 | [
"- fir = a[i]",
"- las = a[i + 1]",
"+ cnt += a[i + 1] - a[i]",
"- las = a[i] + t",
"- cnt += las - fir",
"+ cnt += t"
] | false | 0.042679 | 0.043098 | 0.990278 | [
"s014133966",
"s617265907"
] |
u945181840 | p03294 | python | s204342143 | s448991514 | 151 | 19 | 12,392 | 3,316 | Accepted | Accepted | 87.42 | import numpy as np
N = int(eval(input()))
a = np.array(list(map(int, input().split())))
print((np.sum(a - 1))) | N = int(eval(input()))
a = list(map(int, input().split()))
print((sum(a) - N)) | 6 | 4 | 109 | 75 | import numpy as np
N = int(eval(input()))
a = np.array(list(map(int, input().split())))
print((np.sum(a - 1)))
| N = int(eval(input()))
a = list(map(int, input().split()))
print((sum(a) - N))
| false | 33.333333 | [
"-import numpy as np",
"-",
"-a = np.array(list(map(int, input().split())))",
"-print((np.sum(a - 1)))",
"+a = list(map(int, input().split()))",
"+print((sum(a) - N))"
] | false | 0.271473 | 0.040245 | 6.745473 | [
"s204342143",
"s448991514"
] |
u067975558 | p02409 | python | s090957652 | s693023221 | 40 | 30 | 6,796 | 6,732 | Accepted | Accepted | 25 | floor = [
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
]
s = '####################'
n = int(input())
for c in range(n):
(b,f,r,v) = [int(x) for x in input().split()]
if 1 > b > 5 and 1 > f > 4 and 1 > r > 10:
break
floor[b-1][f-1][r-1] += v
for z in range(4):
for i in range(len(floor[z])):
for v in floor[z][i]:
print(end=' ')
print(v, end='')
print()
if not z == 3:
print(s)
| floor = [[[0] * 10 for x in range(3)] for y in range(4)]
for c in range(int(eval(input()))):
(b,f,r,v) = [int(x) for x in input().split()]
if 1 > b > 5 or 1 > f > 4 or 1 > r > 10:
break
floor[b-1][f-1][r-1] += v
for x in range(3 * 4):
if x % 3 == 0 and not x == 0:
print(('#' * 20))
print(('',' '.join(str(y) for y in floor[int(x / 3)][x % 3]))) | 34 | 12 | 948 | 384 | floor = [
[
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
],
[
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
],
[
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
],
[
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
],
]
s = "####################"
n = int(input())
for c in range(n):
(b, f, r, v) = [int(x) for x in input().split()]
if 1 > b > 5 and 1 > f > 4 and 1 > r > 10:
break
floor[b - 1][f - 1][r - 1] += v
for z in range(4):
for i in range(len(floor[z])):
for v in floor[z][i]:
print(end=" ")
print(v, end="")
print()
if not z == 3:
print(s)
| floor = [[[0] * 10 for x in range(3)] for y in range(4)]
for c in range(int(eval(input()))):
(b, f, r, v) = [int(x) for x in input().split()]
if 1 > b > 5 or 1 > f > 4 or 1 > r > 10:
break
floor[b - 1][f - 1][r - 1] += v
for x in range(3 * 4):
if x % 3 == 0 and not x == 0:
print(("#" * 20))
print(("", " ".join(str(y) for y in floor[int(x / 3)][x % 3])))
| false | 64.705882 | [
"-floor = [",
"- [",
"- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],",
"- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],",
"- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],",
"- ],",
"- [",
"- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],",
"- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],",
"- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],",
"- ],",
"- [",
"- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],",
"- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],",
"- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],",
"- ],",
"- [",
"- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],",
"- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],",
"- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],",
"- ],",
"-]",
"-s = \"####################\"",
"-n = int(input())",
"-for c in range(n):",
"+floor = [[[0] * 10 for x in range(3)] for y in range(4)]",
"+for c in range(int(eval(input()))):",
"- if 1 > b > 5 and 1 > f > 4 and 1 > r > 10:",
"+ if 1 > b > 5 or 1 > f > 4 or 1 > r > 10:",
"-for z in range(4):",
"- for i in range(len(floor[z])):",
"- for v in floor[z][i]:",
"- print(end=\" \")",
"- print(v, end=\"\")",
"- print()",
"- if not z == 3:",
"- print(s)",
"+for x in range(3 * 4):",
"+ if x % 3 == 0 and not x == 0:",
"+ print((\"#\" * 20))",
"+ print((\"\", \" \".join(str(y) for y in floor[int(x / 3)][x % 3])))"
] | false | 0.037626 | 0.037701 | 0.998006 | [
"s090957652",
"s693023221"
] |
u788137651 | p03679 | python | s537618339 | s063606907 | 76 | 52 | 7,496 | 6,156 | Accepted | Accepted | 31.58 | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
X,A,B = MI()
day = B-A
if day <= 0:
print("delicious")
elif day <= X:
print("safe")
else:
print("dangerous")
if __name__ == '__main__':
main()
| #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
X,A,B=MI()
C=A-B
if A>=B:
print("delicious")
elif B-A<=X:
print("safe")
else:
print("dangerous")
if __name__ == '__main__':
main()
| 53 | 54 | 1,514 | 1,508 | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log # log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import (
accumulate,
permutations,
combinations,
product,
combinations_with_replacement,
)
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a, b):
return (a + b - 1) // b
inf = float("inf")
mod = 10**9 + 7
def pprint(*A):
for a in A:
print(*a, sep="\n")
def INT_(n):
return int(n) - 1
def MI():
return map(int, input().split())
def MF():
return map(float, input().split())
def MI_():
return map(INT_, input().split())
def LI():
return list(MI())
def LI_():
return [int(x) - 1 for x in input().split()]
def LF():
return list(MF())
def LIN(n: int):
return [I() for _ in range(n)]
def LLIN(n: int):
return [LI() for _ in range(n)]
def LLIN_(n: int):
return [LI_() for _ in range(n)]
def LLI():
return [list(map(int, l.split())) for l in input()]
def I():
return int(input())
def F():
return float(input())
def ST():
return input().replace("\n", "")
def main():
X, A, B = MI()
day = B - A
if day <= 0:
print("delicious")
elif day <= X:
print("safe")
else:
print("dangerous")
if __name__ == "__main__":
main()
| #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log # log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import (
accumulate,
permutations,
combinations,
product,
combinations_with_replacement,
)
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a, b):
return (a + b - 1) // b
inf = float("inf")
mod = 10**9 + 7
def pprint(*A):
for a in A:
print(*a, sep="\n")
def INT_(n):
return int(n) - 1
def MI():
return map(int, input().split())
def MF():
return map(float, input().split())
def MI_():
return map(INT_, input().split())
def LI():
return list(MI())
def LI_():
return [int(x) - 1 for x in input().split()]
def LF():
return list(MF())
def LIN(n: int):
return [I() for _ in range(n)]
def LLIN(n: int):
return [LI() for _ in range(n)]
def LLIN_(n: int):
return [LI_() for _ in range(n)]
def LLI():
return [list(map(int, l.split())) for l in input()]
def I():
return int(input())
def F():
return float(input())
def ST():
return input().replace("\n", "")
def main():
X, A, B = MI()
C = A - B
if A >= B:
print("delicious")
elif B - A <= X:
print("safe")
else:
print("dangerous")
if __name__ == "__main__":
main()
| false | 1.851852 | [
"- day = B - A",
"- if day <= 0:",
"+ C = A - B",
"+ if A >= B:",
"- elif day <= X:",
"+ elif B - A <= X:"
] | false | 0.048555 | 0.036342 | 1.336053 | [
"s537618339",
"s063606907"
] |
u258073778 | p03835 | python | s544363071 | s921789004 | 1,982 | 18 | 3,060 | 3,060 | Accepted | Accepted | 99.09 | K, S = list(map(int, input().split()))
ct = 0
for X in range(K+1):
for Y in range(K+1):
if S - (X + Y) >= 0 and S - (X + Y) <= K :
ct += 1
print(ct) | K, S = list(map(int, input().split()))
ans = 0
for Z in range(K+1):
r = S - Z
if r < 0:
ans += 0
elif r <= K:
ans += r+1
elif r <= K*2:
ans += (K+1)*2 - (r+1)
print(ans) | 8 | 11 | 165 | 193 | K, S = list(map(int, input().split()))
ct = 0
for X in range(K + 1):
for Y in range(K + 1):
if S - (X + Y) >= 0 and S - (X + Y) <= K:
ct += 1
print(ct)
| K, S = list(map(int, input().split()))
ans = 0
for Z in range(K + 1):
r = S - Z
if r < 0:
ans += 0
elif r <= K:
ans += r + 1
elif r <= K * 2:
ans += (K + 1) * 2 - (r + 1)
print(ans)
| false | 27.272727 | [
"-ct = 0",
"-for X in range(K + 1):",
"- for Y in range(K + 1):",
"- if S - (X + Y) >= 0 and S - (X + Y) <= K:",
"- ct += 1",
"-print(ct)",
"+ans = 0",
"+for Z in range(K + 1):",
"+ r = S - Z",
"+ if r < 0:",
"+ ans += 0",
"+ elif r <= K:",
"+ ans += r + 1",
"+ elif r <= K * 2:",
"+ ans += (K + 1) * 2 - (r + 1)",
"+print(ans)"
] | false | 0.046717 | 0.047629 | 0.98087 | [
"s544363071",
"s921789004"
] |
u962718741 | p03971 | python | s938633739 | s287406606 | 298 | 184 | 50,904 | 48,880 | Accepted | Accepted | 38.26 | def resolve():
N, A, B = list(map(int, input().split()))
S = eval(input())
Atmp = 0
Btmp = 0
for i in S:
if i == 'a':
if Atmp + Btmp < A+B:
Atmp += 1
print('Yes')
else:
print('No')
elif i == 'b':
if Btmp < B and Atmp + Btmp < A+B:
Btmp += 1
print('Yes')
else:
print('No')
else:
print('No')
resolve()
| def resolve():
N, A, B = list(map(int, input().split()))
S = eval(input())
Atmp = 0
Btmp = 0
ans = []
my_append = ans.append
for i in S:
if i == 'a':
if Atmp + Btmp < A+B:
Atmp += 1
my_append('Yes')
else:
my_append('No')
elif i == 'b':
if Btmp < B and Atmp + Btmp < A+B:
Btmp += 1
my_append('Yes')
else:
my_append('No')
else:
my_append('No')
print(("\n".join(ans)))
resolve() | 21 | 24 | 508 | 596 | def resolve():
N, A, B = list(map(int, input().split()))
S = eval(input())
Atmp = 0
Btmp = 0
for i in S:
if i == "a":
if Atmp + Btmp < A + B:
Atmp += 1
print("Yes")
else:
print("No")
elif i == "b":
if Btmp < B and Atmp + Btmp < A + B:
Btmp += 1
print("Yes")
else:
print("No")
else:
print("No")
resolve()
| def resolve():
N, A, B = list(map(int, input().split()))
S = eval(input())
Atmp = 0
Btmp = 0
ans = []
my_append = ans.append
for i in S:
if i == "a":
if Atmp + Btmp < A + B:
Atmp += 1
my_append("Yes")
else:
my_append("No")
elif i == "b":
if Btmp < B and Atmp + Btmp < A + B:
Btmp += 1
my_append("Yes")
else:
my_append("No")
else:
my_append("No")
print(("\n".join(ans)))
resolve()
| false | 12.5 | [
"+ ans = []",
"+ my_append = ans.append",
"- print(\"Yes\")",
"+ my_append(\"Yes\")",
"- print(\"No\")",
"+ my_append(\"No\")",
"- print(\"Yes\")",
"+ my_append(\"Yes\")",
"- print(\"No\")",
"+ my_append(\"No\")",
"- print(\"No\")",
"+ my_append(\"No\")",
"+ print((\"\\n\".join(ans)))"
] | false | 0.040734 | 0.040473 | 1.006436 | [
"s938633739",
"s287406606"
] |
u561083515 | p02881 | python | s774927530 | s942748787 | 154 | 142 | 2,940 | 3,060 | Accepted | Accepted | 7.79 | N = int(eval(input()))
tmp = 0
for i in range(int(N ** (0.5)), 0, -1):
if N % i == 0:
tmp = i + (N // i)
break
print((tmp - 2)) | N = int(eval(input()))
ans = 0
for n in range(int(N ** 0.5), 0, -1):
if N % n == 0:
ans = n + (N // n) - 2
break
print(ans) | 9 | 9 | 149 | 147 | N = int(eval(input()))
tmp = 0
for i in range(int(N ** (0.5)), 0, -1):
if N % i == 0:
tmp = i + (N // i)
break
print((tmp - 2))
| N = int(eval(input()))
ans = 0
for n in range(int(N**0.5), 0, -1):
if N % n == 0:
ans = n + (N // n) - 2
break
print(ans)
| false | 0 | [
"-tmp = 0",
"-for i in range(int(N ** (0.5)), 0, -1):",
"- if N % i == 0:",
"- tmp = i + (N // i)",
"+ans = 0",
"+for n in range(int(N**0.5), 0, -1):",
"+ if N % n == 0:",
"+ ans = n + (N // n) - 2",
"-print((tmp - 2))",
"+print(ans)"
] | false | 0.049088 | 0.049261 | 0.99649 | [
"s774927530",
"s942748787"
] |
u358254559 | p02588 | python | s319297605 | s624443918 | 1,777 | 365 | 284,536 | 111,640 | Accepted | Accepted | 79.46 | import decimal
n = int(eval(input()))
a=[eval(input()) for i in range(n)]
biga=[]
for i in range(n):
num = decimal.Decimal(a[i])
biga.append(int(num*10**9))
def fact25(n):
cnt2=0
cnt5=0
while n%2==0:
n//=2
cnt2+=1
while n%5==0:
n//=5
cnt5+=1
return cnt2,cnt5
arr = [[0 for _ in range(20)] for _ in range(20)]
p25 = []
for i in range(n):
cnt2,cnt5=fact25(biga[i])
p25.append([cnt2,cnt5])
cnt2=min(19,cnt2)
cnt5=min(19,cnt5)
arr[cnt2][cnt5]+=1
ans=0
for i in range(20): # 2
for j in range(20): # 5
if arr[i][j]==0:
continue
for k in range(20): # 2
for l in range(20): # 5
if i+k>=18 and j+l>=18:
if i==k and j==l:
ans+= (arr[i][j]-1)*arr[k][l]
else:
ans+= arr[i][j]*arr[k][l]
print((ans//2)) | n = int(eval(input()))
biga = []
for _ in range(n):
a = float(eval(input()))
a = round(a * 10 ** 9 + 0.1)
biga.append(a)
def fact25(n):
cnt2=0
cnt5=0
while n%2==0:
n//=2
cnt2+=1
while n%5==0:
n//=5
cnt5+=1
return cnt2,cnt5
arr = [[0 for _ in range(20)] for _ in range(20)]
p25 = []
for i in range(n):
cnt2,cnt5=fact25(biga[i])
p25.append([cnt2,cnt5])
cnt2=min(19,cnt2)
cnt5=min(19,cnt5)
arr[cnt2][cnt5]+=1
ans=0
for i in range(20): # 2
for j in range(20): # 5
if arr[i][j]==0:
continue
for k in range(20): # 2
for l in range(20): # 5
if i+k>=18 and j+l>=18:
if i==k and j==l:
ans+= (arr[i][j]-1)*arr[k][l]
else:
ans+= arr[i][j]*arr[k][l]
print((ans//2)) | 41 | 41 | 946 | 915 | import decimal
n = int(eval(input()))
a = [eval(input()) for i in range(n)]
biga = []
for i in range(n):
num = decimal.Decimal(a[i])
biga.append(int(num * 10**9))
def fact25(n):
cnt2 = 0
cnt5 = 0
while n % 2 == 0:
n //= 2
cnt2 += 1
while n % 5 == 0:
n //= 5
cnt5 += 1
return cnt2, cnt5
arr = [[0 for _ in range(20)] for _ in range(20)]
p25 = []
for i in range(n):
cnt2, cnt5 = fact25(biga[i])
p25.append([cnt2, cnt5])
cnt2 = min(19, cnt2)
cnt5 = min(19, cnt5)
arr[cnt2][cnt5] += 1
ans = 0
for i in range(20): # 2
for j in range(20): # 5
if arr[i][j] == 0:
continue
for k in range(20): # 2
for l in range(20): # 5
if i + k >= 18 and j + l >= 18:
if i == k and j == l:
ans += (arr[i][j] - 1) * arr[k][l]
else:
ans += arr[i][j] * arr[k][l]
print((ans // 2))
| n = int(eval(input()))
biga = []
for _ in range(n):
a = float(eval(input()))
a = round(a * 10**9 + 0.1)
biga.append(a)
def fact25(n):
cnt2 = 0
cnt5 = 0
while n % 2 == 0:
n //= 2
cnt2 += 1
while n % 5 == 0:
n //= 5
cnt5 += 1
return cnt2, cnt5
arr = [[0 for _ in range(20)] for _ in range(20)]
p25 = []
for i in range(n):
cnt2, cnt5 = fact25(biga[i])
p25.append([cnt2, cnt5])
cnt2 = min(19, cnt2)
cnt5 = min(19, cnt5)
arr[cnt2][cnt5] += 1
ans = 0
for i in range(20): # 2
for j in range(20): # 5
if arr[i][j] == 0:
continue
for k in range(20): # 2
for l in range(20): # 5
if i + k >= 18 and j + l >= 18:
if i == k and j == l:
ans += (arr[i][j] - 1) * arr[k][l]
else:
ans += arr[i][j] * arr[k][l]
print((ans // 2))
| false | 0 | [
"-import decimal",
"-",
"-a = [eval(input()) for i in range(n)]",
"-for i in range(n):",
"- num = decimal.Decimal(a[i])",
"- biga.append(int(num * 10**9))",
"+for _ in range(n):",
"+ a = float(eval(input()))",
"+ a = round(a * 10**9 + 0.1)",
"+ biga.append(a)"
] | false | 0.038099 | 0.057952 | 0.657414 | [
"s319297605",
"s624443918"
] |
u408071652 | p03163 | python | s711297532 | s840067376 | 393 | 320 | 154,412 | 146,400 | Accepted | Accepted | 18.58 | import sys
def input():
return sys.stdin.readline().rstrip()
def main():
N, W = list(map(int, input().split()))
dp = [[0] * (N + 1) for _ in range(W + 1)]
for i in range(1, N + 1):
w, v = list(map(int, input().split()))
for j in range(W + 1):
if j >= w:
dp[j][i] = max(dp[j][i - 1], dp[j - w][i-1] + v)
else:
dp[j][i] = dp[j][i - 1]
print((dp[W][N]))
if __name__ == "__main__":
main()
| import sys
import math
import itertools
# \n
def input():
return sys.stdin.readline().rstrip()
def main():
N, WW = list(map(int, input().split()))
W = []
V = []
for i in range(N):
w, v = list(map(int, input().split()))
W.append(w)
V.append(v)
dp = [[0] * (WW+1) for _ in range(N)]
for i in range(N):
w = W[i]
v = V[i]
for j in range(WW+1):
if w<=j:
dp[i][j] =max(dp[i-1][j],dp[i-1][j-w]+v)
else:
dp[i][j] =dp[i-1][j]
print((max(dp[N-1])))
if __name__ == "__main__":
main()
| 23 | 37 | 496 | 646 | import sys
def input():
return sys.stdin.readline().rstrip()
def main():
N, W = list(map(int, input().split()))
dp = [[0] * (N + 1) for _ in range(W + 1)]
for i in range(1, N + 1):
w, v = list(map(int, input().split()))
for j in range(W + 1):
if j >= w:
dp[j][i] = max(dp[j][i - 1], dp[j - w][i - 1] + v)
else:
dp[j][i] = dp[j][i - 1]
print((dp[W][N]))
if __name__ == "__main__":
main()
| import sys
import math
import itertools
# \n
def input():
return sys.stdin.readline().rstrip()
def main():
N, WW = list(map(int, input().split()))
W = []
V = []
for i in range(N):
w, v = list(map(int, input().split()))
W.append(w)
V.append(v)
dp = [[0] * (WW + 1) for _ in range(N)]
for i in range(N):
w = W[i]
v = V[i]
for j in range(WW + 1):
if w <= j:
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)
else:
dp[i][j] = dp[i - 1][j]
print((max(dp[N - 1])))
if __name__ == "__main__":
main()
| false | 37.837838 | [
"+import math",
"+import itertools",
"-",
"+# \\n",
"- N, W = list(map(int, input().split()))",
"- dp = [[0] * (N + 1) for _ in range(W + 1)]",
"- for i in range(1, N + 1):",
"+ N, WW = list(map(int, input().split()))",
"+ W = []",
"+ V = []",
"+ for i in range(N):",
"- for j in range(W + 1):",
"- if j >= w:",
"- dp[j][i] = max(dp[j][i - 1], dp[j - w][i - 1] + v)",
"+ W.append(w)",
"+ V.append(v)",
"+ dp = [[0] * (WW + 1) for _ in range(N)]",
"+ for i in range(N):",
"+ w = W[i]",
"+ v = V[i]",
"+ for j in range(WW + 1):",
"+ if w <= j:",
"+ dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)",
"- dp[j][i] = dp[j][i - 1]",
"- print((dp[W][N]))",
"+ dp[i][j] = dp[i - 1][j]",
"+ print((max(dp[N - 1])))"
] | false | 0.049796 | 0.039997 | 1.244987 | [
"s711297532",
"s840067376"
] |
u785578220 | p03287 | python | s057690706 | s602079293 | 388 | 90 | 19,364 | 19,368 | Accepted | Accepted | 76.8 | import itertools
from math import factorial
from collections import Counter
ans = 0
N, L = list(map(int, input().split()))
x = list(map(int, input().split()))
y = itertools.accumulate(x)
y = [e % L for e in y]
#print(y)
#print(y)
so = set(y)
#print(so)
#print(so)
counter = Counter([0]+y)
#print(counter.values())
#print
for i in list(counter.values()):
#print(ans)
if i>1:ans+=factorial(i) // 2 // factorial(i-2)
print(ans) | import itertools
from math import factorial
from collections import Counter
ans = 0
N, L = list(map(int, input().split()))
x = list(map(int, input().split()))
y = itertools.accumulate(x)
y = [e % L for e in y]
#print(y)
#print(y)
so = set(y)
#print(so)
#print(so)
counter = Counter([0]+y)
#print(counter.values())
#print
for i in list(counter.values()):
#print(ans)
ans+=i * (i - 1) // 2
print(ans) | 21 | 21 | 441 | 415 | import itertools
from math import factorial
from collections import Counter
ans = 0
N, L = list(map(int, input().split()))
x = list(map(int, input().split()))
y = itertools.accumulate(x)
y = [e % L for e in y]
# print(y)
# print(y)
so = set(y)
# print(so)
# print(so)
counter = Counter([0] + y)
# print(counter.values())
# print
for i in list(counter.values()):
# print(ans)
if i > 1:
ans += factorial(i) // 2 // factorial(i - 2)
print(ans)
| import itertools
from math import factorial
from collections import Counter
ans = 0
N, L = list(map(int, input().split()))
x = list(map(int, input().split()))
y = itertools.accumulate(x)
y = [e % L for e in y]
# print(y)
# print(y)
so = set(y)
# print(so)
# print(so)
counter = Counter([0] + y)
# print(counter.values())
# print
for i in list(counter.values()):
# print(ans)
ans += i * (i - 1) // 2
print(ans)
| false | 0 | [
"- if i > 1:",
"- ans += factorial(i) // 2 // factorial(i - 2)",
"+ ans += i * (i - 1) // 2"
] | false | 0.041573 | 0.037341 | 1.113351 | [
"s057690706",
"s602079293"
] |
u847467233 | p00693 | python | s125439470 | s833376514 | 1,850 | 1,640 | 8,228 | 7,704 | Accepted | Accepted | 11.35 | # AOJ 1111: Cyber Guardian
# Python3 2018.7.15 bal4u
import re
while True:
n, m = list(map(int, input().split()))
if (n|m) == 0: break
rule, ans = [], []
for i in range(n):
g, s, d = input().split()
rule.append((g[0] == 'p', \
re.compile(s.replace("?", "[0-9]")), \
re.compile(d.replace("?", "[0-9]"))))
for i in range(m):
s, d, m = input().split()
for G, S, D in rule[::-1]:
if re.match(S, s) and re.match(D, d):
if G: ans.append((s, d, m))
break
print((len(ans)))
for a in ans: print((*a))
| # AOJ 1111: Cyber Guardian
# Python3 2018.7.15 bal4u
import re
while True:
n, m = list(map(int, input().split()))
if (n|m) == 0: break
rule, ans = [], []
for i in range(n):
g, s, d = input().split()
rule.append((g[0] == 'p', re.compile((s+d).replace("?", "[0-9]"))))
for i in range(m):
s, d, m = input().split()
sd = s+d
for G, SD in rule[::-1]:
if re.match(SD, sd):
if G: ans.append((s, d, m))
break
print((len(ans)))
for a in ans: print((*a))
| 23 | 21 | 563 | 485 | # AOJ 1111: Cyber Guardian
# Python3 2018.7.15 bal4u
import re
while True:
n, m = list(map(int, input().split()))
if (n | m) == 0:
break
rule, ans = [], []
for i in range(n):
g, s, d = input().split()
rule.append(
(
g[0] == "p",
re.compile(s.replace("?", "[0-9]")),
re.compile(d.replace("?", "[0-9]")),
)
)
for i in range(m):
s, d, m = input().split()
for G, S, D in rule[::-1]:
if re.match(S, s) and re.match(D, d):
if G:
ans.append((s, d, m))
break
print((len(ans)))
for a in ans:
print((*a))
| # AOJ 1111: Cyber Guardian
# Python3 2018.7.15 bal4u
import re
while True:
n, m = list(map(int, input().split()))
if (n | m) == 0:
break
rule, ans = [], []
for i in range(n):
g, s, d = input().split()
rule.append((g[0] == "p", re.compile((s + d).replace("?", "[0-9]"))))
for i in range(m):
s, d, m = input().split()
sd = s + d
for G, SD in rule[::-1]:
if re.match(SD, sd):
if G:
ans.append((s, d, m))
break
print((len(ans)))
for a in ans:
print((*a))
| false | 8.695652 | [
"- rule.append(",
"- (",
"- g[0] == \"p\",",
"- re.compile(s.replace(\"?\", \"[0-9]\")),",
"- re.compile(d.replace(\"?\", \"[0-9]\")),",
"- )",
"- )",
"+ rule.append((g[0] == \"p\", re.compile((s + d).replace(\"?\", \"[0-9]\"))))",
"- for G, S, D in rule[::-1]:",
"- if re.match(S, s) and re.match(D, d):",
"+ sd = s + d",
"+ for G, SD in rule[::-1]:",
"+ if re.match(SD, sd):"
] | false | 0.145008 | 0.051528 | 2.814168 | [
"s125439470",
"s833376514"
] |
u989345508 | p02697 | python | s458472606 | s637721538 | 80 | 70 | 9,260 | 9,208 | Accepted | Accepted | 12.5 | n,m=list(map(int,input().split()))
if n%2==1:
l=n//2
for i in range(m):
if i%2==1:
print((i//2+1,l-i//2))
else:
print((l+i//2+1,n-i//2))
else:
l=n//2
for i in range(m):
if i%2==0:
print((i//2+1,l-i//2))
else:
print((l+i//2+2,n-i//2))
| n,m=list(map(int,input().split()))
if n%2==1:
for i in range(m):
print((i+1,n-i))
else:
for i in range(m):
if i<m/2:
print((i+1,n-i))
else:
print((i+1,n-i-1)) | 16 | 10 | 332 | 211 | n, m = list(map(int, input().split()))
if n % 2 == 1:
l = n // 2
for i in range(m):
if i % 2 == 1:
print((i // 2 + 1, l - i // 2))
else:
print((l + i // 2 + 1, n - i // 2))
else:
l = n // 2
for i in range(m):
if i % 2 == 0:
print((i // 2 + 1, l - i // 2))
else:
print((l + i // 2 + 2, n - i // 2))
| n, m = list(map(int, input().split()))
if n % 2 == 1:
for i in range(m):
print((i + 1, n - i))
else:
for i in range(m):
if i < m / 2:
print((i + 1, n - i))
else:
print((i + 1, n - i - 1))
| false | 37.5 | [
"- l = n // 2",
"- if i % 2 == 1:",
"- print((i // 2 + 1, l - i // 2))",
"+ print((i + 1, n - i))",
"+else:",
"+ for i in range(m):",
"+ if i < m / 2:",
"+ print((i + 1, n - i))",
"- print((l + i // 2 + 1, n - i // 2))",
"-else:",
"- l = n // 2",
"- for i in range(m):",
"- if i % 2 == 0:",
"- print((i // 2 + 1, l - i // 2))",
"- else:",
"- print((l + i // 2 + 2, n - i // 2))",
"+ print((i + 1, n - i - 1))"
] | false | 0.047467 | 0.047893 | 0.991111 | [
"s458472606",
"s637721538"
] |
u905895868 | p02927 | python | s203528239 | s016755072 | 35 | 32 | 9,176 | 9,188 | Accepted | Accepted | 8.57 | months, d = list(map(int, input().split()))
ans_count = 0
for month in range(4, months + 1):
for i in range(1, d + 1):
if i <= 9:
continue
a, b = list(map(int, str(i)))
if a >= 2 and b >= 2 and a * b == month:
ans_count += 1
print(ans_count) | months, d = list(map(int, input().split()))
ans_count = 0
for month in range(4, months + 1):
for i in range(1, d + 1):
if i <= 9:
continue
a, b = list(map(int, str(i)))
if a <= 1 or b <= 1:
continue
if a * b == month:
ans_count += 1
print(ans_count) | 15 | 18 | 300 | 332 | months, d = list(map(int, input().split()))
ans_count = 0
for month in range(4, months + 1):
for i in range(1, d + 1):
if i <= 9:
continue
a, b = list(map(int, str(i)))
if a >= 2 and b >= 2 and a * b == month:
ans_count += 1
print(ans_count)
| months, d = list(map(int, input().split()))
ans_count = 0
for month in range(4, months + 1):
for i in range(1, d + 1):
if i <= 9:
continue
a, b = list(map(int, str(i)))
if a <= 1 or b <= 1:
continue
if a * b == month:
ans_count += 1
print(ans_count)
| false | 16.666667 | [
"- if a >= 2 and b >= 2 and a * b == month:",
"+ if a <= 1 or b <= 1:",
"+ continue",
"+ if a * b == month:"
] | false | 0.183803 | 0.039356 | 4.670245 | [
"s203528239",
"s016755072"
] |
u065446124 | p02678 | python | s240037463 | s731524880 | 527 | 455 | 110,980 | 34,868 | Accepted | Accepted | 13.66 | import sys
input=sys.stdin.readline
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
def YesNo(x):print("Yes")if x==True else print("No")
n,m=NM()
edge=[[] for i in range(n+1)]
for i in range(m):
a,b=map(int,input().split())
c=1
edge[a].append((b,c))
edge[b].append((a,c))
pre=[-1]*(n+1)
from heapq import *
def dijkstra(s,n):
d = [float('inf') for i in range(n+1)]
pq = []
d[s]=0
heappush(pq,(0,s))
while pq:
dist,u = heappop(pq)
for v,cost in edge[u]:
if d[v]<=dist+cost:
continue
d[v]=dist+cost
pre[v]=u
heappush(pq,(d[v],v))
return d
dijkstra(1,n)
if -1 in pre[2:]:
print("No")
else:
print("Yes")
for i in pre[2:]:
print(i)
| import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
def YesNo(x):print("Yes")if x==True else print("No")
n,m=NM()
edge=[[] for i in range(n+1)]
for i in range(m):
a,b=map(int,input().split())
edge[a].append(b)
edge[b].append(a)
pre=[-1]*(n+1)
from collections import deque
def bfs(s,n):
d=[-1 for i in range(n+1)]
d[s]=0
q=deque([s])
while q:
x=q.popleft()
for i in edge[x]:
if d[i]==-1:
d[i]=d[x]+1
pre[i]=x
q.append(i)
return d
bfs(1,n)
if -1 in pre[2:]:
print("No")
else:
print("Yes")
for i in pre[2:]:
print(i)
| 38 | 35 | 933 | 858 | import sys
input = sys.stdin.readline
def N():
return int(input())
def NM():
return map(int, input().split())
def L():
return list(NM())
def LN(n):
return [N() for i in range(n)]
def LL(n):
return [L() for i in range(n)]
def YesNo(x):
print("Yes") if x == True else print("No")
n, m = NM()
edge = [[] for i in range(n + 1)]
for i in range(m):
a, b = map(int, input().split())
c = 1
edge[a].append((b, c))
edge[b].append((a, c))
pre = [-1] * (n + 1)
from heapq import *
def dijkstra(s, n):
d = [float("inf") for i in range(n + 1)]
pq = []
d[s] = 0
heappush(pq, (0, s))
while pq:
dist, u = heappop(pq)
for v, cost in edge[u]:
if d[v] <= dist + cost:
continue
d[v] = dist + cost
pre[v] = u
heappush(pq, (d[v], v))
return d
dijkstra(1, n)
if -1 in pre[2:]:
print("No")
else:
print("Yes")
for i in pre[2:]:
print(i)
| import sys
def input():
return sys.stdin.readline()[:-1]
def N():
return int(input())
def NM():
return map(int, input().split())
def L():
return list(NM())
def LN(n):
return [N() for i in range(n)]
def LL(n):
return [L() for i in range(n)]
def YesNo(x):
print("Yes") if x == True else print("No")
n, m = NM()
edge = [[] for i in range(n + 1)]
for i in range(m):
a, b = map(int, input().split())
edge[a].append(b)
edge[b].append(a)
pre = [-1] * (n + 1)
from collections import deque
def bfs(s, n):
d = [-1 for i in range(n + 1)]
d[s] = 0
q = deque([s])
while q:
x = q.popleft()
for i in edge[x]:
if d[i] == -1:
d[i] = d[x] + 1
pre[i] = x
q.append(i)
return d
bfs(1, n)
if -1 in pre[2:]:
print("No")
else:
print("Yes")
for i in pre[2:]:
print(i)
| false | 7.894737 | [
"-input = sys.stdin.readline",
"+",
"+def input():",
"+ return sys.stdin.readline()[:-1]",
"- c = 1",
"- edge[a].append((b, c))",
"- edge[b].append((a, c))",
"+ edge[a].append(b)",
"+ edge[b].append(a)",
"-from heapq import *",
"+from collections import deque",
"-def dijkstra(s, n):",
"- d = [float(\"inf\") for i in range(n + 1)]",
"- pq = []",
"+def bfs(s, n):",
"+ d = [-1 for i in range(n + 1)]",
"- heappush(pq, (0, s))",
"- while pq:",
"- dist, u = heappop(pq)",
"- for v, cost in edge[u]:",
"- if d[v] <= dist + cost:",
"- continue",
"- d[v] = dist + cost",
"- pre[v] = u",
"- heappush(pq, (d[v], v))",
"+ q = deque([s])",
"+ while q:",
"+ x = q.popleft()",
"+ for i in edge[x]:",
"+ if d[i] == -1:",
"+ d[i] = d[x] + 1",
"+ pre[i] = x",
"+ q.append(i)",
"-dijkstra(1, n)",
"+bfs(1, n)"
] | false | 0.101801 | 0.081003 | 1.256759 | [
"s240037463",
"s731524880"
] |
u045953894 | p03478 | python | s289050733 | s474331245 | 35 | 32 | 2,940 | 2,940 | Accepted | Accepted | 8.57 | N, A, B = list(map(int, input().split()))
res = 0
for i in range(N+1):
if A <= sum([int(s) for s in str(i)]) <= B:
res += i
print(res) | n,a,b = list(map(int,input().split()))
s = 0
for i in range(n+1):
if a <= sum([int(j) for j in str(i)]) <= b:
s += i
print(s) | 6 | 6 | 145 | 136 | N, A, B = list(map(int, input().split()))
res = 0
for i in range(N + 1):
if A <= sum([int(s) for s in str(i)]) <= B:
res += i
print(res)
| n, a, b = list(map(int, input().split()))
s = 0
for i in range(n + 1):
if a <= sum([int(j) for j in str(i)]) <= b:
s += i
print(s)
| false | 0 | [
"-N, A, B = list(map(int, input().split()))",
"-res = 0",
"-for i in range(N + 1):",
"- if A <= sum([int(s) for s in str(i)]) <= B:",
"- res += i",
"-print(res)",
"+n, a, b = list(map(int, input().split()))",
"+s = 0",
"+for i in range(n + 1):",
"+ if a <= sum([int(j) for j in str(i)]) <= b:",
"+ s += i",
"+print(s)"
] | false | 0.043772 | 0.04801 | 0.911725 | [
"s289050733",
"s474331245"
] |
u580093517 | p03737 | python | s464500688 | s122746029 | 170 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90 | s1,s2,s3 = list(map(str,input().split()))
s = s1[0] + s2[0] + s3[0]
s = s.upper()
print(s) | a,b,c = input().split()
print(((a[0]+b[0]+c[0]).upper())) | 7 | 2 | 93 | 56 | s1, s2, s3 = list(map(str, input().split()))
s = s1[0] + s2[0] + s3[0]
s = s.upper()
print(s)
| a, b, c = input().split()
print(((a[0] + b[0] + c[0]).upper()))
| false | 71.428571 | [
"-s1, s2, s3 = list(map(str, input().split()))",
"-s = s1[0] + s2[0] + s3[0]",
"-s = s.upper()",
"-print(s)",
"+a, b, c = input().split()",
"+print(((a[0] + b[0] + c[0]).upper()))"
] | false | 0.089918 | 0.04344 | 2.069926 | [
"s464500688",
"s122746029"
] |
u077291787 | p02948 | python | s844999137 | s517118489 | 253 | 165 | 18,512 | 24,932 | Accepted | Accepted | 34.78 | # ABC137D - Summer Vacation
import sys
input = sys.stdin.readline
from heapq import heappush, heappushpop
def main():
N, M = tuple(map(int, input().split()))
T = [[] for _ in range(M + 1)]
for _ in range(N):
a, b = list(map(int, input().rstrip().split()))
if a <= M:
T[M - a] += [b]
q = []
for i in range(M + 1):
for v in T[i]:
if len(q) <= i:
heappush(q, v)
else:
heappushpop(q, v)
print((sum(q)))
if __name__ == "__main__":
main() | # ABC137D - Summer Vacation
from heapq import heappush, heappushpop
def main():
N, M, *A = list(map(int, open(0).read().split()))
# T[i] := candidates of values on i-th deadline
T = [[] for _ in range(M + 1)]
for a, b in zip(*[iter(A)] * 2):
if a <= M:
T[M - a] += [b]
q = [] # heapq
for i in range(M + 1):
for v in T[i]:
# keep i worthwhile tasks in i-th day
if len(q) <= i:
heappush(q, v)
else:
heappushpop(q, v)
print((sum(q)))
if __name__ == "__main__":
main() | 26 | 24 | 574 | 612 | # ABC137D - Summer Vacation
import sys
input = sys.stdin.readline
from heapq import heappush, heappushpop
def main():
N, M = tuple(map(int, input().split()))
T = [[] for _ in range(M + 1)]
for _ in range(N):
a, b = list(map(int, input().rstrip().split()))
if a <= M:
T[M - a] += [b]
q = []
for i in range(M + 1):
for v in T[i]:
if len(q) <= i:
heappush(q, v)
else:
heappushpop(q, v)
print((sum(q)))
if __name__ == "__main__":
main()
| # ABC137D - Summer Vacation
from heapq import heappush, heappushpop
def main():
N, M, *A = list(map(int, open(0).read().split()))
# T[i] := candidates of values on i-th deadline
T = [[] for _ in range(M + 1)]
for a, b in zip(*[iter(A)] * 2):
if a <= M:
T[M - a] += [b]
q = [] # heapq
for i in range(M + 1):
for v in T[i]:
# keep i worthwhile tasks in i-th day
if len(q) <= i:
heappush(q, v)
else:
heappushpop(q, v)
print((sum(q)))
if __name__ == "__main__":
main()
| false | 7.692308 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"- N, M = tuple(map(int, input().split()))",
"+ N, M, *A = list(map(int, open(0).read().split()))",
"+ # T[i] := candidates of values on i-th deadline",
"- for _ in range(N):",
"- a, b = list(map(int, input().rstrip().split()))",
"+ for a, b in zip(*[iter(A)] * 2):",
"- q = []",
"+ q = [] # heapq",
"+ # keep i worthwhile tasks in i-th day"
] | false | 0.185548 | 0.062328 | 2.976958 | [
"s844999137",
"s517118489"
] |
u367130284 | p03425 | python | s554870225 | s009319342 | 56 | 40 | 10,668 | 10,664 | Accepted | Accepted | 28.57 | from itertools import*;print((sum(p*q*r for p,q,r in list(combinations([len(list(v))for k,v in groupby(sorted(s[0]for s in open(0).readlines()[1:]))if k in"MARCH"],3))))) | from itertools import*;x=[s[0]for s in open(0).readlines()];print((sum(p*q*r for p,q,r in combinations([x.count(s)for s in"MARCH"],3)))) | 1 | 1 | 168 | 134 | from itertools import *
print(
(
sum(
p * q * r
for p, q, r in list(
combinations(
[
len(list(v))
for k, v in groupby(
sorted(s[0] for s in open(0).readlines()[1:])
)
if k in "MARCH"
],
3,
)
)
)
)
)
| from itertools import *
x = [s[0] for s in open(0).readlines()]
print((sum(p * q * r for p, q, r in combinations([x.count(s) for s in "MARCH"], 3))))
| false | 0 | [
"-print(",
"- (",
"- sum(",
"- p * q * r",
"- for p, q, r in list(",
"- combinations(",
"- [",
"- len(list(v))",
"- for k, v in groupby(",
"- sorted(s[0] for s in open(0).readlines()[1:])",
"- )",
"- if k in \"MARCH\"",
"- ],",
"- 3,",
"- )",
"- )",
"- )",
"- )",
"-)",
"+x = [s[0] for s in open(0).readlines()]",
"+print((sum(p * q * r for p, q, r in combinations([x.count(s) for s in \"MARCH\"], 3))))"
] | false | 0.036918 | 0.035849 | 1.029804 | [
"s554870225",
"s009319342"
] |
u057109575 | p02609 | python | s066390220 | s455023222 | 349 | 321 | 79,768 | 84,536 | Accepted | Accepted | 8.02 | N = int(eval(input()))
X = eval(input())
cnt = X.count("1")
res0 = 0
res1 = 0
for i in range(N):
if X[i] == "1":
res0 = (res0 + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)
if cnt - 1 > 0:
res1 = (res1 + pow(2, N - i - 1, cnt - 1)) % (cnt - 1)
for i in range(N):
ans = 0
if X[i] == "0":
div = cnt + 1
tmp = (res0 + pow(2, N - i - 1, div)) % div
ans += 1
else:
if cnt - 1 > 0:
div = cnt - 1
tmp = (res1 + div - pow(2, N - i - 1, div)) % div
ans += 1
else:
tmp = 0
while tmp > 0:
ans += 1
div = bin(tmp).count("1")
tmp %= div
print(ans)
|
N = int(input())
X = input()
mod0 = X.count("1") + 1
mod1 = X.count("1") - 1
full0 = 0
full1 = 0
for i in range(N):
if X[i] == "1":
full0 = (full0 + pow(2, N - i - 1, mod0)) % mod0
if mod1 > 0:
full1 = (full1 + pow(2, N - i - 1, mod1)) % mod1
ans = [0] * N
for i in range(N):
if X[i] == "0":
cur = (full0 + pow(2, N - i - 1, mod0)) % mod0
res = 1
else:
if mod1 > 0:
cur = (full1 - pow(2, N - i - 1, mod1)) % mod1
res = 1
else:
cur = 0
res = 0
while cur > 0:
cur %= bin(cur).count("1")
res += 1
ans[i] = res
print(*ans, sep="\n")
| 33 | 34 | 727 | 712 | N = int(eval(input()))
X = eval(input())
cnt = X.count("1")
res0 = 0
res1 = 0
for i in range(N):
if X[i] == "1":
res0 = (res0 + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)
if cnt - 1 > 0:
res1 = (res1 + pow(2, N - i - 1, cnt - 1)) % (cnt - 1)
for i in range(N):
ans = 0
if X[i] == "0":
div = cnt + 1
tmp = (res0 + pow(2, N - i - 1, div)) % div
ans += 1
else:
if cnt - 1 > 0:
div = cnt - 1
tmp = (res1 + div - pow(2, N - i - 1, div)) % div
ans += 1
else:
tmp = 0
while tmp > 0:
ans += 1
div = bin(tmp).count("1")
tmp %= div
print(ans)
| N = int(input())
X = input()
mod0 = X.count("1") + 1
mod1 = X.count("1") - 1
full0 = 0
full1 = 0
for i in range(N):
if X[i] == "1":
full0 = (full0 + pow(2, N - i - 1, mod0)) % mod0
if mod1 > 0:
full1 = (full1 + pow(2, N - i - 1, mod1)) % mod1
ans = [0] * N
for i in range(N):
if X[i] == "0":
cur = (full0 + pow(2, N - i - 1, mod0)) % mod0
res = 1
else:
if mod1 > 0:
cur = (full1 - pow(2, N - i - 1, mod1)) % mod1
res = 1
else:
cur = 0
res = 0
while cur > 0:
cur %= bin(cur).count("1")
res += 1
ans[i] = res
print(*ans, sep="\n")
| false | 2.941176 | [
"-N = int(eval(input()))",
"-X = eval(input())",
"-cnt = X.count(\"1\")",
"-res0 = 0",
"-res1 = 0",
"+N = int(input())",
"+X = input()",
"+mod0 = X.count(\"1\") + 1",
"+mod1 = X.count(\"1\") - 1",
"+full0 = 0",
"+full1 = 0",
"- res0 = (res0 + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)",
"- if cnt - 1 > 0:",
"- res1 = (res1 + pow(2, N - i - 1, cnt - 1)) % (cnt - 1)",
"+ full0 = (full0 + pow(2, N - i - 1, mod0)) % mod0",
"+ if mod1 > 0:",
"+ full1 = (full1 + pow(2, N - i - 1, mod1)) % mod1",
"+ans = [0] * N",
"- ans = 0",
"- div = cnt + 1",
"- tmp = (res0 + pow(2, N - i - 1, div)) % div",
"- ans += 1",
"+ cur = (full0 + pow(2, N - i - 1, mod0)) % mod0",
"+ res = 1",
"- if cnt - 1 > 0:",
"- div = cnt - 1",
"- tmp = (res1 + div - pow(2, N - i - 1, div)) % div",
"- ans += 1",
"+ if mod1 > 0:",
"+ cur = (full1 - pow(2, N - i - 1, mod1)) % mod1",
"+ res = 1",
"- tmp = 0",
"- while tmp > 0:",
"- ans += 1",
"- div = bin(tmp).count(\"1\")",
"- tmp %= div",
"- print(ans)",
"+ cur = 0",
"+ res = 0",
"+ while cur > 0:",
"+ cur %= bin(cur).count(\"1\")",
"+ res += 1",
"+ ans[i] = res",
"+print(*ans, sep=\"\\n\")"
] | false | 0.040297 | 0.037406 | 1.077278 | [
"s066390220",
"s455023222"
] |
u116038906 | p02850 | python | s584411917 | s559475009 | 861 | 662 | 117,036 | 68,748 | Accepted | Accepted | 23.11 | from collections import deque
import sys
input =sys.stdin.readline
N = int(eval(input()))
#構造入力
color_max =0
connection ={i:deque() for i in range(1,N+1)}
edge_color={}
A =[(-1,-1)]*N
for i in range(1,N):
a,b = (int(x) for x in input().split())
connection[a].append(b)
connection[b].append(a)
edge_color[(a,b)] =-1
A[i] =(a,b)
color_max =max(color_max, len(connection[a]) , len(connection[b]))
#幅優先探索で色塗る
passed =set()
#edge_color ={i:-1 for i in range(1,N+1)}
parent ={i:-1 for i in range(1,N+1)}
parent[1] =0
dq =deque()
dq.append(1)
color =0
#prev =0 #頂点1の親は0とする
edge_color[(0,1)] =0
#node_color[1] =0
while dq:
now =dq.popleft()
passed.add(now)
na_max =max(parent[now],now)
na_min =min(parent[now],now)
i_color =edge_color[(na_min,na_max)]
for next in connection[now]:
if next in passed:
continue
else:
i_color +=1
n_max =max(now,next)
n_min =min(now,next)
edge_color[(n_min,n_max)] =(i_color)% color_max
dq.append(next)
parent[next] =now
print(color_max)
del edge_color[(0,1)]
for i in range(1,N):
print((edge_color[A[i]] +1 )) | """2020/7/2再挑戦"""
#幅優先探索 親の頂点と色を覚えておく。親の色を除く+1ずつ足していく。color_maxを超えたら余りをとる。
from collections import deque
N = int(eval(input()))
connection ={i:set() for i in range(1,N+1)}
connection_parent =[]
for i in range(1,N):
a,b = (int(i) for i in input().split())
connection[a].add(b)
connection[b].add(a)
connection_parent.append(b)
#最小の色数
c =[]
for i in list(connection.values()):
c.append(len(i))
color_min =max(c)
#幅優先探索
start =1
color={i:0 for i in range(1,N+1)} #P:今の頂点と次への辺の色を記録(tuple)。
passed =set() # 通過した記録
dq =deque([start]) #スタートは1でいいのか?
color[start] =0
while len(dq) >0:
now =dq.popleft()
passed.add(now)
c1 =color[now]
for next in connection[now]:
if next not in passed:
c1 +=1
c1 %=color_min
color[next] =c1 #0 <=c <= color_min-1のため +1
dq.append(next)
print(color_min)
for i in connection_parent:
print((color[i] +1)) | 49 | 37 | 1,227 | 944 | from collections import deque
import sys
input = sys.stdin.readline
N = int(eval(input()))
# 構造入力
color_max = 0
connection = {i: deque() for i in range(1, N + 1)}
edge_color = {}
A = [(-1, -1)] * N
for i in range(1, N):
a, b = (int(x) for x in input().split())
connection[a].append(b)
connection[b].append(a)
edge_color[(a, b)] = -1
A[i] = (a, b)
color_max = max(color_max, len(connection[a]), len(connection[b]))
# 幅優先探索で色塗る
passed = set()
# edge_color ={i:-1 for i in range(1,N+1)}
parent = {i: -1 for i in range(1, N + 1)}
parent[1] = 0
dq = deque()
dq.append(1)
color = 0
# prev =0 #頂点1の親は0とする
edge_color[(0, 1)] = 0
# node_color[1] =0
while dq:
now = dq.popleft()
passed.add(now)
na_max = max(parent[now], now)
na_min = min(parent[now], now)
i_color = edge_color[(na_min, na_max)]
for next in connection[now]:
if next in passed:
continue
else:
i_color += 1
n_max = max(now, next)
n_min = min(now, next)
edge_color[(n_min, n_max)] = (i_color) % color_max
dq.append(next)
parent[next] = now
print(color_max)
del edge_color[(0, 1)]
for i in range(1, N):
print((edge_color[A[i]] + 1))
| """2020/7/2再挑戦"""
# 幅優先探索 親の頂点と色を覚えておく。親の色を除く+1ずつ足していく。color_maxを超えたら余りをとる。
from collections import deque
N = int(eval(input()))
connection = {i: set() for i in range(1, N + 1)}
connection_parent = []
for i in range(1, N):
a, b = (int(i) for i in input().split())
connection[a].add(b)
connection[b].add(a)
connection_parent.append(b)
# 最小の色数
c = []
for i in list(connection.values()):
c.append(len(i))
color_min = max(c)
# 幅優先探索
start = 1
color = {i: 0 for i in range(1, N + 1)} # P:今の頂点と次への辺の色を記録(tuple)。
passed = set() # 通過した記録
dq = deque([start]) # スタートは1でいいのか?
color[start] = 0
while len(dq) > 0:
now = dq.popleft()
passed.add(now)
c1 = color[now]
for next in connection[now]:
if next not in passed:
c1 += 1
c1 %= color_min
color[next] = c1 # 0 <=c <= color_min-1のため +1
dq.append(next)
print(color_min)
for i in connection_parent:
print((color[i] + 1))
| false | 24.489796 | [
"+\"\"\"2020/7/2再挑戦\"\"\"",
"+# 幅優先探索 親の頂点と色を覚えておく。親の色を除く+1ずつ足していく。color_maxを超えたら余りをとる。",
"-import sys",
"-input = sys.stdin.readline",
"-# 構造入力",
"-color_max = 0",
"-connection = {i: deque() for i in range(1, N + 1)}",
"-edge_color = {}",
"-A = [(-1, -1)] * N",
"+connection = {i: set() for i in range(1, N + 1)}",
"+connection_parent = []",
"- a, b = (int(x) for x in input().split())",
"- connection[a].append(b)",
"- connection[b].append(a)",
"- edge_color[(a, b)] = -1",
"- A[i] = (a, b)",
"- color_max = max(color_max, len(connection[a]), len(connection[b]))",
"-# 幅優先探索で色塗る",
"-passed = set()",
"-# edge_color ={i:-1 for i in range(1,N+1)}",
"-parent = {i: -1 for i in range(1, N + 1)}",
"-parent[1] = 0",
"-dq = deque()",
"-dq.append(1)",
"-color = 0",
"-# prev =0 #頂点1の親は0とする",
"-edge_color[(0, 1)] = 0",
"-# node_color[1] =0",
"-while dq:",
"+ a, b = (int(i) for i in input().split())",
"+ connection[a].add(b)",
"+ connection[b].add(a)",
"+ connection_parent.append(b)",
"+# 最小の色数",
"+c = []",
"+for i in list(connection.values()):",
"+ c.append(len(i))",
"+color_min = max(c)",
"+# 幅優先探索",
"+start = 1",
"+color = {i: 0 for i in range(1, N + 1)} # P:今の頂点と次への辺の色を記録(tuple)。",
"+passed = set() # 通過した記録",
"+dq = deque([start]) # スタートは1でいいのか?",
"+color[start] = 0",
"+while len(dq) > 0:",
"- na_max = max(parent[now], now)",
"- na_min = min(parent[now], now)",
"- i_color = edge_color[(na_min, na_max)]",
"+ c1 = color[now]",
"- if next in passed:",
"- continue",
"- else:",
"- i_color += 1",
"- n_max = max(now, next)",
"- n_min = min(now, next)",
"- edge_color[(n_min, n_max)] = (i_color) % color_max",
"+ if next not in passed:",
"+ c1 += 1",
"+ c1 %= color_min",
"+ color[next] = c1 # 0 <=c <= color_min-1のため +1",
"- parent[next] = now",
"-print(color_max)",
"-del edge_color[(0, 1)]",
"-for i in range(1, N):",
"- print((edge_color[A[i]] + 1))",
"+print(color_min)",
"+for i in connection_parent:",
"+ print((color[i] + 1))"
] | false | 0.0401 | 0.040083 | 1.000425 | [
"s584411917",
"s559475009"
] |
u475503988 | p02947 | python | s880380965 | s683789964 | 538 | 384 | 26,304 | 17,808 | Accepted | Accepted | 28.62 | N = int(eval(input()))
ss = []
for i in range(N):
s = list(eval(input()))
s.sort()
ss.append(s)
ss.sort()
ans = 0
tmp = 1
for i in range(N-1):
if ss[i] == ss[i+1]:
tmp += 1
if i == N-2:
ans += (tmp * (tmp-1)) // 2
else:
ans += (tmp * (tmp-1)) // 2
tmp = 1
print(ans)
| N = int(eval(input()))
d = dict()
for i in range(N):
s = list(eval(input()))
s.sort()
s = ''.join(s)
if s in d:
d[s] += 1
else:
d[s] = 1
ans = 0
for i in list(d.values()):
ans += (i * (i-1)) // 2
print(ans) | 20 | 16 | 340 | 245 | N = int(eval(input()))
ss = []
for i in range(N):
s = list(eval(input()))
s.sort()
ss.append(s)
ss.sort()
ans = 0
tmp = 1
for i in range(N - 1):
if ss[i] == ss[i + 1]:
tmp += 1
if i == N - 2:
ans += (tmp * (tmp - 1)) // 2
else:
ans += (tmp * (tmp - 1)) // 2
tmp = 1
print(ans)
| N = int(eval(input()))
d = dict()
for i in range(N):
s = list(eval(input()))
s.sort()
s = "".join(s)
if s in d:
d[s] += 1
else:
d[s] = 1
ans = 0
for i in list(d.values()):
ans += (i * (i - 1)) // 2
print(ans)
| false | 20 | [
"-ss = []",
"+d = dict()",
"- ss.append(s)",
"-ss.sort()",
"+ s = \"\".join(s)",
"+ if s in d:",
"+ d[s] += 1",
"+ else:",
"+ d[s] = 1",
"-tmp = 1",
"-for i in range(N - 1):",
"- if ss[i] == ss[i + 1]:",
"- tmp += 1",
"- if i == N - 2:",
"- ans += (tmp * (tmp - 1)) // 2",
"- else:",
"- ans += (tmp * (tmp - 1)) // 2",
"- tmp = 1",
"+for i in list(d.values()):",
"+ ans += (i * (i - 1)) // 2"
] | false | 0.043423 | 0.035277 | 1.230904 | [
"s880380965",
"s683789964"
] |
u332906195 | p03545 | python | s982257359 | s246964530 | 20 | 17 | 3,188 | 3,060 | Accepted | Accepted | 15 | # -*- coding: utf-8 -*-
import itertools
ABCD = eval(input())
l = len(ABCD)
cs = itertools.product(['+', '-'], repeat=l-1)
ans = 0
for c in cs:
ex = ''.join([ABCD[i] + c[i] for i in range(l-1)] + [ABCD[-1]])
exec("ans = {}".format(ex))
if ans == 7:
break
print((ex + "=7"))
| import itertools
S = eval(input())
for op1, op2, op3 in itertools.product('+-', repeat=3):
if eval(S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3]) == 7:
print((S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3] + "=7"))
exit()
| 16 | 8 | 305 | 238 | # -*- coding: utf-8 -*-
import itertools
ABCD = eval(input())
l = len(ABCD)
cs = itertools.product(["+", "-"], repeat=l - 1)
ans = 0
for c in cs:
ex = "".join([ABCD[i] + c[i] for i in range(l - 1)] + [ABCD[-1]])
exec("ans = {}".format(ex))
if ans == 7:
break
print((ex + "=7"))
| import itertools
S = eval(input())
for op1, op2, op3 in itertools.product("+-", repeat=3):
if eval(S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3]) == 7:
print((S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3] + "=7"))
exit()
| false | 50 | [
"-# -*- coding: utf-8 -*-",
"-ABCD = eval(input())",
"-l = len(ABCD)",
"-cs = itertools.product([\"+\", \"-\"], repeat=l - 1)",
"-ans = 0",
"-for c in cs:",
"- ex = \"\".join([ABCD[i] + c[i] for i in range(l - 1)] + [ABCD[-1]])",
"- exec(\"ans = {}\".format(ex))",
"- if ans == 7:",
"- break",
"-print((ex + \"=7\"))",
"+S = eval(input())",
"+for op1, op2, op3 in itertools.product(\"+-\", repeat=3):",
"+ if eval(S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3]) == 7:",
"+ print((S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3] + \"=7\"))",
"+ exit()"
] | false | 0.044767 | 0.041289 | 1.08424 | [
"s982257359",
"s246964530"
] |
u707124227 | p02727 | python | s085586931 | s994346623 | 237 | 161 | 23,328 | 29,688 | Accepted | Accepted | 32.07 | x,y,a,b,c=list(map(int,input().split()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
p=p[-x:]
q.sort()
q=q[-y:]
p[len(p):len(p)]=q
p[len(p):len(p)]=r
p.sort()
p=p[-x-y:]
print((sum(p))) | x,y,nr,ng,nm=list(map(int,input().split()))
r=list(map(int,input().split()))
g=list(map(int,input().split()))
m=list(map(int,input().split()))
r.sort(reverse=True)
g.sort(reverse=True)
a=r[:x]+g[:y]+m
a.sort(reverse=True)
print((sum(a[:x+y])))
| 13 | 9 | 253 | 244 | x, y, a, b, c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
p = p[-x:]
q.sort()
q = q[-y:]
p[len(p) : len(p)] = q
p[len(p) : len(p)] = r
p.sort()
p = p[-x - y :]
print((sum(p)))
| x, y, nr, ng, nm = list(map(int, input().split()))
r = list(map(int, input().split()))
g = list(map(int, input().split()))
m = list(map(int, input().split()))
r.sort(reverse=True)
g.sort(reverse=True)
a = r[:x] + g[:y] + m
a.sort(reverse=True)
print((sum(a[: x + y])))
| false | 30.769231 | [
"-x, y, a, b, c = list(map(int, input().split()))",
"-p = list(map(int, input().split()))",
"-q = list(map(int, input().split()))",
"+x, y, nr, ng, nm = list(map(int, input().split()))",
"-p.sort()",
"-p = p[-x:]",
"-q.sort()",
"-q = q[-y:]",
"-p[len(p) : len(p)] = q",
"-p[len(p) : len(p)] = r",
"-p.sort()",
"-p = p[-x - y :]",
"-print((sum(p)))",
"+g = list(map(int, input().split()))",
"+m = list(map(int, input().split()))",
"+r.sort(reverse=True)",
"+g.sort(reverse=True)",
"+a = r[:x] + g[:y] + m",
"+a.sort(reverse=True)",
"+print((sum(a[: x + y])))"
] | false | 0.084633 | 0.035491 | 2.384659 | [
"s085586931",
"s994346623"
] |
u994521204 | p02887 | python | s124228620 | s381229278 | 44 | 33 | 3,316 | 3,316 | Accepted | Accepted | 25 | n=int(eval(input()))
s=eval(input())
c=1
for i in range(1,n):
if s[i]!=s[i-1]:
c+=1
print(c) | n = int(eval(input()))
s = eval(input())
ans = 0
prev = ""
for a in s:
if prev == a:
continue
else:
ans += 1
prev = a
print(ans)
| 7 | 11 | 98 | 159 | n = int(eval(input()))
s = eval(input())
c = 1
for i in range(1, n):
if s[i] != s[i - 1]:
c += 1
print(c)
| n = int(eval(input()))
s = eval(input())
ans = 0
prev = ""
for a in s:
if prev == a:
continue
else:
ans += 1
prev = a
print(ans)
| false | 36.363636 | [
"-c = 1",
"-for i in range(1, n):",
"- if s[i] != s[i - 1]:",
"- c += 1",
"-print(c)",
"+ans = 0",
"+prev = \"\"",
"+for a in s:",
"+ if prev == a:",
"+ continue",
"+ else:",
"+ ans += 1",
"+ prev = a",
"+print(ans)"
] | false | 0.047662 | 0.047342 | 1.006767 | [
"s124228620",
"s381229278"
] |
u423665486 | p03713 | python | s568369018 | s130003024 | 336 | 194 | 3,064 | 41,196 | Accepted | Accepted | 42.26 | def min_value(w, h):
ans = float('inf')
for i in range(1, h):
a = w*i
v_t = (h-i)//2 * w
v_b = (h-i)*w - v_t
v_re = max(a, v_t, v_b) - min(a, v_t, v_b)
h_l = (h-i)*(w//2)
h_r = (h-i)*w-h_l
h_re = max(a, h_l, h_r) - min(a, h_l, h_r)
ans = min(ans, v_re, h_re)
return ans
def resolve():
h, w = list(map(int, input().split()))
a = min_value(w, h)
b = min_value(h, w)
print((min(a, b)))
resolve() | def calc(w, h):
v = float('inf')
a = w * h
for i in range(1, h):
h_a = w*i
h_b = (h - i)//2*w
h_c = a - h_a - h_b
h_max = max(h_a, h_b, h_c)
h_min = min(h_a, h_b, h_c)
v = min(v, h_max - h_min)
v_b = w//2*(h-i)
v_c = a - h_a - v_b
v_max = max(h_a, v_b, v_c)
v_min = min(h_a, v_b, v_c)
v = min(v, v_max - v_min)
return v
def resolve():
h, w = list(map(int, input().split()))
print((min(calc(h, w), calc(w, h))))
resolve() | 19 | 21 | 426 | 461 | def min_value(w, h):
ans = float("inf")
for i in range(1, h):
a = w * i
v_t = (h - i) // 2 * w
v_b = (h - i) * w - v_t
v_re = max(a, v_t, v_b) - min(a, v_t, v_b)
h_l = (h - i) * (w // 2)
h_r = (h - i) * w - h_l
h_re = max(a, h_l, h_r) - min(a, h_l, h_r)
ans = min(ans, v_re, h_re)
return ans
def resolve():
h, w = list(map(int, input().split()))
a = min_value(w, h)
b = min_value(h, w)
print((min(a, b)))
resolve()
| def calc(w, h):
v = float("inf")
a = w * h
for i in range(1, h):
h_a = w * i
h_b = (h - i) // 2 * w
h_c = a - h_a - h_b
h_max = max(h_a, h_b, h_c)
h_min = min(h_a, h_b, h_c)
v = min(v, h_max - h_min)
v_b = w // 2 * (h - i)
v_c = a - h_a - v_b
v_max = max(h_a, v_b, v_c)
v_min = min(h_a, v_b, v_c)
v = min(v, v_max - v_min)
return v
def resolve():
h, w = list(map(int, input().split()))
print((min(calc(h, w), calc(w, h))))
resolve()
| false | 9.52381 | [
"-def min_value(w, h):",
"- ans = float(\"inf\")",
"+def calc(w, h):",
"+ v = float(\"inf\")",
"+ a = w * h",
"- a = w * i",
"- v_t = (h - i) // 2 * w",
"- v_b = (h - i) * w - v_t",
"- v_re = max(a, v_t, v_b) - min(a, v_t, v_b)",
"- h_l = (h - i) * (w // 2)",
"- h_r = (h - i) * w - h_l",
"- h_re = max(a, h_l, h_r) - min(a, h_l, h_r)",
"- ans = min(ans, v_re, h_re)",
"- return ans",
"+ h_a = w * i",
"+ h_b = (h - i) // 2 * w",
"+ h_c = a - h_a - h_b",
"+ h_max = max(h_a, h_b, h_c)",
"+ h_min = min(h_a, h_b, h_c)",
"+ v = min(v, h_max - h_min)",
"+ v_b = w // 2 * (h - i)",
"+ v_c = a - h_a - v_b",
"+ v_max = max(h_a, v_b, v_c)",
"+ v_min = min(h_a, v_b, v_c)",
"+ v = min(v, v_max - v_min)",
"+ return v",
"- a = min_value(w, h)",
"- b = min_value(h, w)",
"- print((min(a, b)))",
"+ print((min(calc(h, w), calc(w, h))))"
] | false | 0.385581 | 0.007067 | 54.563145 | [
"s568369018",
"s130003024"
] |
u079022693 | p02714 | python | s722393332 | s875018255 | 917 | 831 | 70,424 | 9,048 | Accepted | Accepted | 9.38 | from sys import stdin
import bisect
def main():
#入力
readline=stdin.readline
N=int(readline())
S=readline().strip()
res=0
R=[]
G=[]
B=[]
flags=[""]*N
for i in range(N):
if S[i]=="R":
R.append(i)
flags[i]="R"
elif S[i]=="G":
G.append(i)
flags[i]="G"
else:
B.append(i)
flags[i]="B"
#Bが最後
for i in range(len(R)):
for j in range(len(G)):
n=max(R[i],G[j])
k=bisect.bisect_left(B,n)
res+=len(B)-k
if n+n-min(R[i],G[j])<N:
if flags[n+n-min(R[i],G[j])]=="B":
res-=1
for i in range(len(R)):
for j in range(len(B)):
n=max(R[i],B[j])
k=bisect.bisect_left(G,n)
res+=len(G)-k
if n+n-min(R[i],B[j])<N:
if flags[n+n-min(R[i],B[j])]=="G":
res-=1
for i in range(len(B)):
for j in range(len(G)):
n=max(B[i],G[j])
k=bisect.bisect_left(R,n)
res+=len(R)-k
if n+n-min(B[i],G[j])<N:
if flags[n+n-min(B[i],G[j])]=="R":
res-=1
print(res)
if __name__=="__main__":
main() | from sys import stdin
def main():
#入力
readline=stdin.readline
n=int(readline())
s=readline().strip()
ans=s.count("R")*s.count("G")*s.count("B")
for i in range(n):
for j in range(i+1,n):
k=2*j-i
if k>=n: break
x=s[i]
y=s[j]
z=s[k]
if x!=y and y!=z and z!=x:
ans-=1
print(ans)
if __name__=="__main__":
main() | 56 | 22 | 1,348 | 458 | from sys import stdin
import bisect
def main():
# 入力
readline = stdin.readline
N = int(readline())
S = readline().strip()
res = 0
R = []
G = []
B = []
flags = [""] * N
for i in range(N):
if S[i] == "R":
R.append(i)
flags[i] = "R"
elif S[i] == "G":
G.append(i)
flags[i] = "G"
else:
B.append(i)
flags[i] = "B"
# Bが最後
for i in range(len(R)):
for j in range(len(G)):
n = max(R[i], G[j])
k = bisect.bisect_left(B, n)
res += len(B) - k
if n + n - min(R[i], G[j]) < N:
if flags[n + n - min(R[i], G[j])] == "B":
res -= 1
for i in range(len(R)):
for j in range(len(B)):
n = max(R[i], B[j])
k = bisect.bisect_left(G, n)
res += len(G) - k
if n + n - min(R[i], B[j]) < N:
if flags[n + n - min(R[i], B[j])] == "G":
res -= 1
for i in range(len(B)):
for j in range(len(G)):
n = max(B[i], G[j])
k = bisect.bisect_left(R, n)
res += len(R) - k
if n + n - min(B[i], G[j]) < N:
if flags[n + n - min(B[i], G[j])] == "R":
res -= 1
print(res)
if __name__ == "__main__":
main()
| from sys import stdin
def main():
# 入力
readline = stdin.readline
n = int(readline())
s = readline().strip()
ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n):
for j in range(i + 1, n):
k = 2 * j - i
if k >= n:
break
x = s[i]
y = s[j]
z = s[k]
if x != y and y != z and z != x:
ans -= 1
print(ans)
if __name__ == "__main__":
main()
| false | 60.714286 | [
"-import bisect",
"- N = int(readline())",
"- S = readline().strip()",
"- res = 0",
"- R = []",
"- G = []",
"- B = []",
"- flags = [\"\"] * N",
"- for i in range(N):",
"- if S[i] == \"R\":",
"- R.append(i)",
"- flags[i] = \"R\"",
"- elif S[i] == \"G\":",
"- G.append(i)",
"- flags[i] = \"G\"",
"- else:",
"- B.append(i)",
"- flags[i] = \"B\"",
"- # Bが最後",
"- for i in range(len(R)):",
"- for j in range(len(G)):",
"- n = max(R[i], G[j])",
"- k = bisect.bisect_left(B, n)",
"- res += len(B) - k",
"- if n + n - min(R[i], G[j]) < N:",
"- if flags[n + n - min(R[i], G[j])] == \"B\":",
"- res -= 1",
"- for i in range(len(R)):",
"- for j in range(len(B)):",
"- n = max(R[i], B[j])",
"- k = bisect.bisect_left(G, n)",
"- res += len(G) - k",
"- if n + n - min(R[i], B[j]) < N:",
"- if flags[n + n - min(R[i], B[j])] == \"G\":",
"- res -= 1",
"- for i in range(len(B)):",
"- for j in range(len(G)):",
"- n = max(B[i], G[j])",
"- k = bisect.bisect_left(R, n)",
"- res += len(R) - k",
"- if n + n - min(B[i], G[j]) < N:",
"- if flags[n + n - min(B[i], G[j])] == \"R\":",
"- res -= 1",
"- print(res)",
"+ n = int(readline())",
"+ s = readline().strip()",
"+ ans = s.count(\"R\") * s.count(\"G\") * s.count(\"B\")",
"+ for i in range(n):",
"+ for j in range(i + 1, n):",
"+ k = 2 * j - i",
"+ if k >= n:",
"+ break",
"+ x = s[i]",
"+ y = s[j]",
"+ z = s[k]",
"+ if x != y and y != z and z != x:",
"+ ans -= 1",
"+ print(ans)"
] | false | 0.038531 | 0.093882 | 0.410415 | [
"s722393332",
"s875018255"
] |
u995004106 | p03426 | python | s912581746 | s595938446 | 911 | 819 | 92,892 | 84,188 | Accepted | Accepted | 10.1 | import pprint
H,W,D=list(map(int,input().split()))
table=[list(map(int,input().split())) for _ in range(H)]
Q=int(eval(input()))
query=[list(map(int,input().split())) for _ in range(Q)]
num=[]
distfrom1D=[]
for i in range(H):
for j in range(W):
num.append([table[i][j],i,j])
num.sort(key=lambda x:x[0])
#print(num)
#for i in range()
cnt=0
for i in range(D):
buf=[0]
for j in range(i,H*W-D,D):
#print(i+j,i+j+D)
buf.append(buf[len(buf)-1]+abs(num[j][1]-num[j+D][1])+abs(num[j][2]-num[j+D][2]))
#print(buf)
distfrom1D.append(buf)
#[1,1+D,]
#[2,2+D,]
#...
#[D,D+D,]
#pprint.pprint(distfrom1D)
for i in range(Q):
l=query[i][0]
r=query[i][1]
row=((l%D)-1)%D
col1 = (l // D)
col2 = (r // D)
if l%D==0:
col1=col1-1
col2=col2-1
print((distfrom1D[row][col2]-distfrom1D[row][col1]))
| import pprint
H,W,D=list(map(int,input().split()))
table=[list(map(int,input().split())) for _ in range(H)]
Q=int(eval(input()))
query=[list(map(int,input().split())) for _ in range(Q)]
num=[]
distfrom1D=[]
cumldist=[0]*(H*W+1)
for i in range(H):
for j in range(W):
num.append([table[i][j],i,j])
num.sort(key=lambda x:x[0])
#print(num)
#for i in range()
cnt=0
"""
for i in range(D):
buf=[0]
for j in range(i,H*W-D,D):
#print(i+j,i+j+D)
buf.append(buf[len(buf)-1]+abs(num[j][1]-num[j+D][1])+abs(num[j][2]-num[j+D][2]))
#print(buf)
distfrom1D.append(buf)
#[1,1+D,]
#[2,2+D,]
#...
#[D,D+D,]
#pprint.pprint(distfrom1D)
for i in range(Q):
l=query[i][0]
r=query[i][1]
row=((l%D)-1)%D
col1 = (l // D)
col2 = (r // D)
if l%D==0:
col1=col1-1
col2=col2-1
print(distfrom1D[row][col2]-distfrom1D[row][col1])
"""
#""l-r%D==0より""、各点考えられる固定の始点(1..D)から1,2,...,1+D,2+D,...,1+2D,2+2D,...の累積和をdpっぽく作れる
for i in range(1,H*W+1):
if i//D>0:
cumldist[i]=cumldist[i-D]+abs(num[i-D-1][1]-num[i-1][1])+abs(num[i-D-1][2]-num[i-1][2])
#print(cumldist)
for i in range(Q):
l=query[i][0]
r=query[i][1]
print((cumldist[r]-cumldist[l]))
| 40 | 52 | 890 | 1,257 | import pprint
H, W, D = list(map(int, input().split()))
table = [list(map(int, input().split())) for _ in range(H)]
Q = int(eval(input()))
query = [list(map(int, input().split())) for _ in range(Q)]
num = []
distfrom1D = []
for i in range(H):
for j in range(W):
num.append([table[i][j], i, j])
num.sort(key=lambda x: x[0])
# print(num)
# for i in range()
cnt = 0
for i in range(D):
buf = [0]
for j in range(i, H * W - D, D):
# print(i+j,i+j+D)
buf.append(
buf[len(buf) - 1]
+ abs(num[j][1] - num[j + D][1])
+ abs(num[j][2] - num[j + D][2])
)
# print(buf)
distfrom1D.append(buf)
# [1,1+D,]
# [2,2+D,]
# ...
# [D,D+D,]
# pprint.pprint(distfrom1D)
for i in range(Q):
l = query[i][0]
r = query[i][1]
row = ((l % D) - 1) % D
col1 = l // D
col2 = r // D
if l % D == 0:
col1 = col1 - 1
col2 = col2 - 1
print((distfrom1D[row][col2] - distfrom1D[row][col1]))
| import pprint
H, W, D = list(map(int, input().split()))
table = [list(map(int, input().split())) for _ in range(H)]
Q = int(eval(input()))
query = [list(map(int, input().split())) for _ in range(Q)]
num = []
distfrom1D = []
cumldist = [0] * (H * W + 1)
for i in range(H):
for j in range(W):
num.append([table[i][j], i, j])
num.sort(key=lambda x: x[0])
# print(num)
# for i in range()
cnt = 0
"""
for i in range(D):
buf=[0]
for j in range(i,H*W-D,D):
#print(i+j,i+j+D)
buf.append(buf[len(buf)-1]+abs(num[j][1]-num[j+D][1])+abs(num[j][2]-num[j+D][2]))
#print(buf)
distfrom1D.append(buf)
#[1,1+D,]
#[2,2+D,]
#...
#[D,D+D,]
#pprint.pprint(distfrom1D)
for i in range(Q):
l=query[i][0]
r=query[i][1]
row=((l%D)-1)%D
col1 = (l // D)
col2 = (r // D)
if l%D==0:
col1=col1-1
col2=col2-1
print(distfrom1D[row][col2]-distfrom1D[row][col1])
"""
# ""l-r%D==0より""、各点考えられる固定の始点(1..D)から1,2,...,1+D,2+D,...,1+2D,2+2D,...の累積和をdpっぽく作れる
for i in range(1, H * W + 1):
if i // D > 0:
cumldist[i] = (
cumldist[i - D]
+ abs(num[i - D - 1][1] - num[i - 1][1])
+ abs(num[i - D - 1][2] - num[i - 1][2])
)
# print(cumldist)
for i in range(Q):
l = query[i][0]
r = query[i][1]
print((cumldist[r] - cumldist[l]))
| false | 23.076923 | [
"+cumldist = [0] * (H * W + 1)",
"+\"\"\"",
"- buf = [0]",
"- for j in range(i, H * W - D, D):",
"- # print(i+j,i+j+D)",
"- buf.append(",
"- buf[len(buf) - 1]",
"- + abs(num[j][1] - num[j + D][1])",
"- + abs(num[j][2] - num[j + D][2])",
"+ buf=[0]",
"+ for j in range(i,H*W-D,D):",
"+ #print(i+j,i+j+D)",
"+ buf.append(buf[len(buf)-1]+abs(num[j][1]-num[j+D][1])+abs(num[j][2]-num[j+D][2]))",
"+ #print(buf)",
"+ distfrom1D.append(buf)",
"+#[1,1+D,]",
"+#[2,2+D,]",
"+#...",
"+#[D,D+D,]",
"+#pprint.pprint(distfrom1D)",
"+for i in range(Q):",
"+ l=query[i][0]",
"+ r=query[i][1]",
"+ row=((l%D)-1)%D",
"+ col1 = (l // D)",
"+ col2 = (r // D)",
"+ if l%D==0:",
"+ col1=col1-1",
"+ col2=col2-1",
"+ print(distfrom1D[row][col2]-distfrom1D[row][col1])",
"+\"\"\"",
"+# \"\"l-r%D==0より\"\"、各点考えられる固定の始点(1..D)から1,2,...,1+D,2+D,...,1+2D,2+2D,...の累積和をdpっぽく作れる",
"+for i in range(1, H * W + 1):",
"+ if i // D > 0:",
"+ cumldist[i] = (",
"+ cumldist[i - D]",
"+ + abs(num[i - D - 1][1] - num[i - 1][1])",
"+ + abs(num[i - D - 1][2] - num[i - 1][2])",
"- # print(buf)",
"- distfrom1D.append(buf)",
"-# [1,1+D,]",
"-# [2,2+D,]",
"-# ...",
"-# [D,D+D,]",
"-# pprint.pprint(distfrom1D)",
"+# print(cumldist)",
"- row = ((l % D) - 1) % D",
"- col1 = l // D",
"- col2 = r // D",
"- if l % D == 0:",
"- col1 = col1 - 1",
"- col2 = col2 - 1",
"- print((distfrom1D[row][col2] - distfrom1D[row][col1]))",
"+ print((cumldist[r] - cumldist[l]))"
] | false | 0.048794 | 0.037261 | 1.309529 | [
"s912581746",
"s595938446"
] |
u285681431 | p03682 | python | s971990373 | s109098511 | 879 | 792 | 135,260 | 133,184 | Accepted | Accepted | 9.9 | # UnionFind
#############################################################
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, v): # vが属する集合の根を返す
if self.parents[v] < 0:
return v
else:
self.parents[v] = self.find(self.parents[v])
return self.parents[v]
def unite(self, u, v): # 「uが属する集合」と「vが属する集合」を併合(根同士を結ぶ)
u = self.find(u)
v = self.find(v)
if u == v:
return
if self.parents[u] > self.parents[v]: # u < v に統一する
u, v = v, u
self.parents[u] += self.parents[v]
self.parents[v] = u
def size(self, v): # vが属する集合の要素数
return -self.parents[self.find(v)]
def same(self, u, v): # uとvが同じ集合に属するか否か
return self.find(u) == self.find(v)
#############################################################
N = int(eval(input()))
XY = [list(map(int, input().split())) + [i] for i in range(N)]
X = sorted(XY, key=lambda x: x[0])
Y = sorted(XY, key=lambda x: x[1])
dist = []
for i in range(N - 1):
# iとi+1の距離、iのindex, i+1のindex
dist.append([X[i + 1][0] - X[i][0], X[i][2], X[i + 1][2]])
dist.append([Y[i + 1][1] - Y[i][1], Y[i][2], Y[i + 1][2]])
ans = 0
dist.sort(key=lambda x: x[0])
uf = UnionFind(N)
# クラスカル法
for cost, i, j in dist:
if uf.same(i, j):
continue
uf.unite(i, j)
ans += cost
print(ans)
| # UnionFind
#############################################################
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, v): # vが属する集合の根を返す
if self.parents[v] < 0:
return v
else:
self.parents[v] = self.find(self.parents[v])
return self.parents[v]
def unite(self, u, v): # 「uが属する集合」と「vが属する集合」を併合(根同士を結ぶ)
u = self.find(u)
v = self.find(v)
if u == v:
return
if self.parents[u] > self.parents[v]: # u < v に統一する
u, v = v, u
self.parents[u] += self.parents[v]
self.parents[v] = u
def size(self, v): # vが属する集合の要素数
return -self.parents[self.find(v)]
def same(self, u, v): # uとvが同じ集合に属するか否か
return self.find(u) == self.find(v)
#############################################################
import sys
input = sys.stdin.readline
N = int(eval(input()))
XY = [list(map(int, input().split())) + [i] for i in range(N)]
X = sorted(XY, key=lambda x: x[0])
Y = sorted(XY, key=lambda x: x[1])
dist = []
for i in range(N - 1):
# iとi+1の距離、iのindex, i+1のindex
dist.append([X[i + 1][0] - X[i][0], X[i][2], X[i + 1][2]])
dist.append([Y[i + 1][1] - Y[i][1], Y[i][2], Y[i + 1][2]])
ans = 0
dist.sort(key=lambda x: x[0])
uf = UnionFind(N)
# クラスカル法
for cost, i, j in dist:
if uf.same(i, j):
continue
uf.unite(i, j)
ans += cost
print(ans)
| 56 | 58 | 1,487 | 1,527 | # UnionFind
#############################################################
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, v): # vが属する集合の根を返す
if self.parents[v] < 0:
return v
else:
self.parents[v] = self.find(self.parents[v])
return self.parents[v]
def unite(self, u, v): # 「uが属する集合」と「vが属する集合」を併合(根同士を結ぶ)
u = self.find(u)
v = self.find(v)
if u == v:
return
if self.parents[u] > self.parents[v]: # u < v に統一する
u, v = v, u
self.parents[u] += self.parents[v]
self.parents[v] = u
def size(self, v): # vが属する集合の要素数
return -self.parents[self.find(v)]
def same(self, u, v): # uとvが同じ集合に属するか否か
return self.find(u) == self.find(v)
#############################################################
N = int(eval(input()))
XY = [list(map(int, input().split())) + [i] for i in range(N)]
X = sorted(XY, key=lambda x: x[0])
Y = sorted(XY, key=lambda x: x[1])
dist = []
for i in range(N - 1):
# iとi+1の距離、iのindex, i+1のindex
dist.append([X[i + 1][0] - X[i][0], X[i][2], X[i + 1][2]])
dist.append([Y[i + 1][1] - Y[i][1], Y[i][2], Y[i + 1][2]])
ans = 0
dist.sort(key=lambda x: x[0])
uf = UnionFind(N)
# クラスカル法
for cost, i, j in dist:
if uf.same(i, j):
continue
uf.unite(i, j)
ans += cost
print(ans)
| # UnionFind
#############################################################
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, v): # vが属する集合の根を返す
if self.parents[v] < 0:
return v
else:
self.parents[v] = self.find(self.parents[v])
return self.parents[v]
def unite(self, u, v): # 「uが属する集合」と「vが属する集合」を併合(根同士を結ぶ)
u = self.find(u)
v = self.find(v)
if u == v:
return
if self.parents[u] > self.parents[v]: # u < v に統一する
u, v = v, u
self.parents[u] += self.parents[v]
self.parents[v] = u
def size(self, v): # vが属する集合の要素数
return -self.parents[self.find(v)]
def same(self, u, v): # uとvが同じ集合に属するか否か
return self.find(u) == self.find(v)
#############################################################
import sys
input = sys.stdin.readline
N = int(eval(input()))
XY = [list(map(int, input().split())) + [i] for i in range(N)]
X = sorted(XY, key=lambda x: x[0])
Y = sorted(XY, key=lambda x: x[1])
dist = []
for i in range(N - 1):
# iとi+1の距離、iのindex, i+1のindex
dist.append([X[i + 1][0] - X[i][0], X[i][2], X[i + 1][2]])
dist.append([Y[i + 1][1] - Y[i][1], Y[i][2], Y[i + 1][2]])
ans = 0
dist.sort(key=lambda x: x[0])
uf = UnionFind(N)
# クラスカル法
for cost, i, j in dist:
if uf.same(i, j):
continue
uf.unite(i, j)
ans += cost
print(ans)
| false | 3.448276 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.095235 | 0.09496 | 1.002895 | [
"s971990373",
"s109098511"
] |
u281303342 | p03425 | python | s914912025 | s636683202 | 182 | 154 | 9,752 | 10,112 | Accepted | Accepted | 15.38 | N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
from itertools import combinations
c = list(combinations([i for i in range(5)],3))
cnt = [0]*6
for i in range(N):
cnt["MARCH".find(S[i][0])] += 1
ans = 0
for (i,j,k) in c:
ans += cnt[i]*cnt[j]*cnt[k]
print(ans) | from collections import defaultdict
from itertools import combinations
N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
dic = defaultdict(int)
for s in S:
dic[s[0]] += 1
comb = combinations("MARCH", 3)
ans = 0
for x1,x2,x3 in comb:
ans += dic[x1]*dic[x2]*dic[x3]
print(ans)
| 15 | 17 | 285 | 303 | N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
from itertools import combinations
c = list(combinations([i for i in range(5)], 3))
cnt = [0] * 6
for i in range(N):
cnt["MARCH".find(S[i][0])] += 1
ans = 0
for (i, j, k) in c:
ans += cnt[i] * cnt[j] * cnt[k]
print(ans)
| from collections import defaultdict
from itertools import combinations
N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
dic = defaultdict(int)
for s in S:
dic[s[0]] += 1
comb = combinations("MARCH", 3)
ans = 0
for x1, x2, x3 in comb:
ans += dic[x1] * dic[x2] * dic[x3]
print(ans)
| false | 11.764706 | [
"+from collections import defaultdict",
"+from itertools import combinations",
"+",
"-from itertools import combinations",
"-",
"-c = list(combinations([i for i in range(5)], 3))",
"-cnt = [0] * 6",
"-for i in range(N):",
"- cnt[\"MARCH\".find(S[i][0])] += 1",
"+dic = defaultdict(int)",
"+for s in S:",
"+ dic[s[0]] += 1",
"+comb = combinations(\"MARCH\", 3)",
"-for (i, j, k) in c:",
"- ans += cnt[i] * cnt[j] * cnt[k]",
"+for x1, x2, x3 in comb:",
"+ ans += dic[x1] * dic[x2] * dic[x3]"
] | false | 0.039179 | 0.038145 | 1.027106 | [
"s914912025",
"s636683202"
] |
u585482323 | p02918 | python | s478321713 | s458838240 | 205 | 184 | 51,568 | 40,048 | Accepted | Accepted | 10.24 | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
n = I()
print((n**3))
return
#B
def B():
n = I()
a = LI()
b = LI()
c = LI()
ans = sum(b)
for i in range(n-1):
x = a[i]
y = a[i+1]
if y == x+1:
ans += c[x-1]
print(ans)
return
#C
def C():
n = I()
b = LI()
b.append(float("inf"))
a = [min(b[i],b[i-1]) for i in range(n)]
print((sum(a)))
return
#D
def D():
n,k = LI()
a = S()
ans = 0
for i in range(n-1):
if a[i] == a[i+1]:
ans += 1
print((min(n-1,ans+2*k)))
return
#E
def E():
def add(i):
while i <= n:
bit[i] += 1
i += i&-i
def sum(i):
res = 0
while i > 0:
res += bit[i]
i -= i&-i
return res
n = I()
p = LI()
r = [0]*n
bit = [0]*(n+1)
for i in range(n)[::-1]:
r[i] = (n-i-1)-sum(p[i])
add(p[i])
print(r)
l = [0]*n
bit = [0]*(n+1)
for i in range(n):
l[i] = i-sum(p[i])
add(p[i])
print(l)
return
#F
def F():
n = I()
s = LI()
s.sort()
s = s[::-1]
if s[0] == s[1]:
print("No")
return
a = [s[0]]
j = 1
s.append(0)
q = deque()
for _ in range(n):
for i in range(1<<_):
if a[i] > s[j]:
a.append(s[j])
j += 1
else:
q.append(a[i])
print(a)
return
#Solve
if __name__ == "__main__":
D()
| #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n,k = LI()
s = eval(input())
ans = 0
for i in range(n-1):
if s[i] == s[i+1]:
ans += 1
print((min(ans+2*k,n-1)))
return
#Solve
if __name__ == "__main__":
solve()
| 125 | 41 | 2,298 | 958 | #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
# A
def A():
n = I()
print((n**3))
return
# B
def B():
n = I()
a = LI()
b = LI()
c = LI()
ans = sum(b)
for i in range(n - 1):
x = a[i]
y = a[i + 1]
if y == x + 1:
ans += c[x - 1]
print(ans)
return
# C
def C():
n = I()
b = LI()
b.append(float("inf"))
a = [min(b[i], b[i - 1]) for i in range(n)]
print((sum(a)))
return
# D
def D():
n, k = LI()
a = S()
ans = 0
for i in range(n - 1):
if a[i] == a[i + 1]:
ans += 1
print((min(n - 1, ans + 2 * k)))
return
# E
def E():
def add(i):
while i <= n:
bit[i] += 1
i += i & -i
def sum(i):
res = 0
while i > 0:
res += bit[i]
i -= i & -i
return res
n = I()
p = LI()
r = [0] * n
bit = [0] * (n + 1)
for i in range(n)[::-1]:
r[i] = (n - i - 1) - sum(p[i])
add(p[i])
print(r)
l = [0] * n
bit = [0] * (n + 1)
for i in range(n):
l[i] = i - sum(p[i])
add(p[i])
print(l)
return
# F
def F():
n = I()
s = LI()
s.sort()
s = s[::-1]
if s[0] == s[1]:
print("No")
return
a = [s[0]]
j = 1
s.append(0)
q = deque()
for _ in range(n):
for i in range(1 << _):
if a[i] > s[j]:
a.append(s[j])
j += 1
else:
q.append(a[i])
print(a)
return
# Solve
if __name__ == "__main__":
D()
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n, k = LI()
s = eval(input())
ans = 0
for i in range(n - 1):
if s[i] == s[i + 1]:
ans += 1
print((min(ans + 2 * k, n - 1)))
return
# Solve
if __name__ == "__main__":
solve()
| false | 67.2 | [
"+from itertools import permutations",
"-# A",
"-def A():",
"- n = I()",
"- print((n**3))",
"- return",
"-# B",
"-def B():",
"- n = I()",
"- a = LI()",
"- b = LI()",
"- c = LI()",
"- ans = sum(b)",
"- for i in range(n - 1):",
"- x = a[i]",
"- y = a[i + 1]",
"- if y == x + 1:",
"- ans += c[x - 1]",
"- print(ans)",
"- return",
"-",
"-",
"-# C",
"-def C():",
"- n = I()",
"- b = LI()",
"- b.append(float(\"inf\"))",
"- a = [min(b[i], b[i - 1]) for i in range(n)]",
"- print((sum(a)))",
"- return",
"-",
"-",
"-# D",
"-def D():",
"+def solve():",
"- a = S()",
"+ s = eval(input())",
"- if a[i] == a[i + 1]:",
"+ if s[i] == s[i + 1]:",
"- print((min(n - 1, ans + 2 * k)))",
"- return",
"-",
"-",
"-# E",
"-def E():",
"- def add(i):",
"- while i <= n:",
"- bit[i] += 1",
"- i += i & -i",
"-",
"- def sum(i):",
"- res = 0",
"- while i > 0:",
"- res += bit[i]",
"- i -= i & -i",
"- return res",
"-",
"- n = I()",
"- p = LI()",
"- r = [0] * n",
"- bit = [0] * (n + 1)",
"- for i in range(n)[::-1]:",
"- r[i] = (n - i - 1) - sum(p[i])",
"- add(p[i])",
"- print(r)",
"- l = [0] * n",
"- bit = [0] * (n + 1)",
"- for i in range(n):",
"- l[i] = i - sum(p[i])",
"- add(p[i])",
"- print(l)",
"- return",
"-",
"-",
"-# F",
"-def F():",
"- n = I()",
"- s = LI()",
"- s.sort()",
"- s = s[::-1]",
"- if s[0] == s[1]:",
"- print(\"No\")",
"- return",
"- a = [s[0]]",
"- j = 1",
"- s.append(0)",
"- q = deque()",
"- for _ in range(n):",
"- for i in range(1 << _):",
"- if a[i] > s[j]:",
"- a.append(s[j])",
"- j += 1",
"- else:",
"- q.append(a[i])",
"- print(a)",
"+ print((min(ans + 2 * k, n - 1)))",
"- D()",
"+ solve()"
] | false | 0.046404 | 0.046078 | 1.007059 | [
"s478321713",
"s458838240"
] |
u332906195 | p02813 | python | s686559734 | s988551343 | 34 | 27 | 8,052 | 8,052 | Accepted | Accepted | 20.59 | import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
LUT = list(itertools.permutations(list(range(1, N + 1))))
Pi, Qi = -1, -1
for i in range(len(LUT)):
if LUT[i] == P:
Pi = i
if LUT[i] == Q:
Qi = i
print((abs(Qi - Pi)))
| from itertools import *
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
LUT = list(permutations(list(range(1, N + 1)))).index
print((abs(LUT(P) - LUT(Q))))
| 16 | 8 | 311 | 200 | import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
LUT = list(itertools.permutations(list(range(1, N + 1))))
Pi, Qi = -1, -1
for i in range(len(LUT)):
if LUT[i] == P:
Pi = i
if LUT[i] == Q:
Qi = i
print((abs(Qi - Pi)))
| from itertools import *
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
LUT = list(permutations(list(range(1, N + 1)))).index
print((abs(LUT(P) - LUT(Q))))
| false | 50 | [
"-import itertools",
"+from itertools import *",
"-LUT = list(itertools.permutations(list(range(1, N + 1))))",
"-Pi, Qi = -1, -1",
"-for i in range(len(LUT)):",
"- if LUT[i] == P:",
"- Pi = i",
"- if LUT[i] == Q:",
"- Qi = i",
"-print((abs(Qi - Pi)))",
"+LUT = list(permutations(list(range(1, N + 1)))).index",
"+print((abs(LUT(P) - LUT(Q))))"
] | false | 0.07332 | 0.070257 | 1.043593 | [
"s686559734",
"s988551343"
] |
u499381410 | p02651 | python | s456516379 | s807229640 | 465 | 143 | 80,124 | 77,692 | Accepted | Accepted | 69.25 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
def least_bit_set(x):
return x & (-x)
def delete_zeros_from(values, start):
i = start
for j in range(start, len(values)):
if values[j] != 0:
values[i] = values[j]
i += 1
del values[i:]
def eliminate(values):
values = list(values)
i = 0
while True:
delete_zeros_from(values, i)
if i >= len(values):
return values
j = i
for k in range(i + 1, len(values)):
if least_bit_set(values[k]) < least_bit_set(values[j]):
j = k
values[i], values[j] = (values[j], values[i])
for k in range(i + 1, len(values)):
if least_bit_set(values[k]) == least_bit_set(values[i]):
values[k] ^= values[i]
i += 1
def in_span(x, eliminated_values):
for y in eliminated_values:
if least_bit_set(y) & x != 0:
x ^= y
return x == 0
t = I()
for _ in range(t):
n = I()
A = LI()
s = S()
flg = 0
values = []
for j in range(n - 1, -1, -1):
if int(s[j]) == 0:
values += [A[j]]
values = eliminate(values)
else:
if not in_span(A[j], values):
print((1))
break
else:
print((0))
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
t = I()
for _ in range(t):
n = I()
A = LI()
s = S()
basis = []
for i in range(n - 1, -1, -1):
v = A[i]
for b in basis:
v = min(v, v ^ b)
if v:
if s[i] == '1':
print((1))
break
basis += [v]
else:
print((0))
| 93 | 48 | 2,396 | 1,399 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10**20
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
def least_bit_set(x):
return x & (-x)
def delete_zeros_from(values, start):
i = start
for j in range(start, len(values)):
if values[j] != 0:
values[i] = values[j]
i += 1
del values[i:]
def eliminate(values):
values = list(values)
i = 0
while True:
delete_zeros_from(values, i)
if i >= len(values):
return values
j = i
for k in range(i + 1, len(values)):
if least_bit_set(values[k]) < least_bit_set(values[j]):
j = k
values[i], values[j] = (values[j], values[i])
for k in range(i + 1, len(values)):
if least_bit_set(values[k]) == least_bit_set(values[i]):
values[k] ^= values[i]
i += 1
def in_span(x, eliminated_values):
for y in eliminated_values:
if least_bit_set(y) & x != 0:
x ^= y
return x == 0
t = I()
for _ in range(t):
n = I()
A = LI()
s = S()
flg = 0
values = []
for j in range(n - 1, -1, -1):
if int(s[j]) == 0:
values += [A[j]]
values = eliminate(values)
else:
if not in_span(A[j], values):
print((1))
break
else:
print((0))
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10**20
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
t = I()
for _ in range(t):
n = I()
A = LI()
s = S()
basis = []
for i in range(n - 1, -1, -1):
v = A[i]
for b in basis:
v = min(v, v ^ b)
if v:
if s[i] == "1":
print((1))
break
basis += [v]
else:
print((0))
| false | 48.387097 | [
"-",
"-",
"-def least_bit_set(x):",
"- return x & (-x)",
"-",
"-",
"-def delete_zeros_from(values, start):",
"- i = start",
"- for j in range(start, len(values)):",
"- if values[j] != 0:",
"- values[i] = values[j]",
"- i += 1",
"- del values[i:]",
"-",
"-",
"-def eliminate(values):",
"- values = list(values)",
"- i = 0",
"- while True:",
"- delete_zeros_from(values, i)",
"- if i >= len(values):",
"- return values",
"- j = i",
"- for k in range(i + 1, len(values)):",
"- if least_bit_set(values[k]) < least_bit_set(values[j]):",
"- j = k",
"- values[i], values[j] = (values[j], values[i])",
"- for k in range(i + 1, len(values)):",
"- if least_bit_set(values[k]) == least_bit_set(values[i]):",
"- values[k] ^= values[i]",
"- i += 1",
"-",
"-",
"-def in_span(x, eliminated_values):",
"- for y in eliminated_values:",
"- if least_bit_set(y) & x != 0:",
"- x ^= y",
"- return x == 0",
"-",
"-",
"- flg = 0",
"- values = []",
"- for j in range(n - 1, -1, -1):",
"- if int(s[j]) == 0:",
"- values += [A[j]]",
"- values = eliminate(values)",
"- else:",
"- if not in_span(A[j], values):",
"+ basis = []",
"+ for i in range(n - 1, -1, -1):",
"+ v = A[i]",
"+ for b in basis:",
"+ v = min(v, v ^ b)",
"+ if v:",
"+ if s[i] == \"1\":",
"+ basis += [v]"
] | false | 0.079713 | 0.045584 | 1.748701 | [
"s456516379",
"s807229640"
] |
u320567105 | p03504 | python | s931442247 | s955741712 | 884 | 715 | 22,428 | 36,892 | Accepted | Accepted | 19.12 | ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
N,C=rl()
st = [[] for _ in range(C)]
TT1 = [0 for _ in range(10**5+2)]
for i in range(N):
s,t,c = rl()
TT1[s] += 1
TT1[t+1] -= 1
st[c-1].append([s,t])
for st_i in range(len(st)):
st_ = st[st_i]
if len(st_) <= 1: continue
st_.sort(key=lambda x:x[0])
l = []
new = 0
lst_ = len(st_)
for i in range(lst_):
if new == 0:
s,t = st_[i]
if i != lst_ -1 and t==st_[i+1][0]:
new = 1
continue
else:
l.append([s,t])
else:
t = st_[i][1]
if i != lst_ -1 and t==st_[i+1][0]:
new = 1
continue
else:
l.append([s,t])
st[st_i] = l
TT2 = [0 for _ in range(10**5+2)]
for st_ in st:
if len(st_) == 0: continue
for i in range(len(st_)):
TT2[st_[i][0]] += 1
TT2[st_[i][1]+1] -= 1
for i in range(1,len(TT1)):
TT1[i] += TT1[i-1]
TT2[i] += TT2[i-1]
print(min(max(TT1),max(TT2)))
| ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
N,C=rl()
stc = [rl() for _ in range(N)]
stc.sort(key=lambda x:(x[2],x[0]))
nstc = []
for s,t,c in stc:
if len(nstc) != 0 and nstc[-1][2] == c and nstc[-1][1] == s:
nstc[-1][1] = t
else:
nstc.append([s,t,c])
n = len(nstc)
TT=[0]*(2*10**5+5)
for i in range(n):
TT[2*nstc[i][0] - 1] += 1
TT[2*nstc[i][1]] -= 1
for i in range(1,len(TT)):
TT[i] += TT[i-1]
print(max(TT))
| 54 | 27 | 1,349 | 707 | ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print("YES") if b else print("NO")
yn = lambda b: print("Yes") if b else print("No")
OE = lambda x: print("Odd") if x % 2 else print("Even")
INF = 10**18
N, C = rl()
st = [[] for _ in range(C)]
TT1 = [0 for _ in range(10**5 + 2)]
for i in range(N):
s, t, c = rl()
TT1[s] += 1
TT1[t + 1] -= 1
st[c - 1].append([s, t])
for st_i in range(len(st)):
st_ = st[st_i]
if len(st_) <= 1:
continue
st_.sort(key=lambda x: x[0])
l = []
new = 0
lst_ = len(st_)
for i in range(lst_):
if new == 0:
s, t = st_[i]
if i != lst_ - 1 and t == st_[i + 1][0]:
new = 1
continue
else:
l.append([s, t])
else:
t = st_[i][1]
if i != lst_ - 1 and t == st_[i + 1][0]:
new = 1
continue
else:
l.append([s, t])
st[st_i] = l
TT2 = [0 for _ in range(10**5 + 2)]
for st_ in st:
if len(st_) == 0:
continue
for i in range(len(st_)):
TT2[st_[i][0]] += 1
TT2[st_[i][1] + 1] -= 1
for i in range(1, len(TT1)):
TT1[i] += TT1[i - 1]
TT2[i] += TT2[i - 1]
print(min(max(TT1), max(TT2)))
| ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print("YES") if b else print("NO")
yn = lambda b: print("Yes") if b else print("No")
OE = lambda x: print("Odd") if x % 2 else print("Even")
INF = 10**18
N, C = rl()
stc = [rl() for _ in range(N)]
stc.sort(key=lambda x: (x[2], x[0]))
nstc = []
for s, t, c in stc:
if len(nstc) != 0 and nstc[-1][2] == c and nstc[-1][1] == s:
nstc[-1][1] = t
else:
nstc.append([s, t, c])
n = len(nstc)
TT = [0] * (2 * 10**5 + 5)
for i in range(n):
TT[2 * nstc[i][0] - 1] += 1
TT[2 * nstc[i][1]] -= 1
for i in range(1, len(TT)):
TT[i] += TT[i - 1]
print(max(TT))
| false | 50 | [
"-st = [[] for _ in range(C)]",
"-TT1 = [0 for _ in range(10**5 + 2)]",
"-for i in range(N):",
"- s, t, c = rl()",
"- TT1[s] += 1",
"- TT1[t + 1] -= 1",
"- st[c - 1].append([s, t])",
"-for st_i in range(len(st)):",
"- st_ = st[st_i]",
"- if len(st_) <= 1:",
"- continue",
"- st_.sort(key=lambda x: x[0])",
"- l = []",
"- new = 0",
"- lst_ = len(st_)",
"- for i in range(lst_):",
"- if new == 0:",
"- s, t = st_[i]",
"- if i != lst_ - 1 and t == st_[i + 1][0]:",
"- new = 1",
"- continue",
"- else:",
"- l.append([s, t])",
"- else:",
"- t = st_[i][1]",
"- if i != lst_ - 1 and t == st_[i + 1][0]:",
"- new = 1",
"- continue",
"- else:",
"- l.append([s, t])",
"- st[st_i] = l",
"-TT2 = [0 for _ in range(10**5 + 2)]",
"-for st_ in st:",
"- if len(st_) == 0:",
"- continue",
"- for i in range(len(st_)):",
"- TT2[st_[i][0]] += 1",
"- TT2[st_[i][1] + 1] -= 1",
"-for i in range(1, len(TT1)):",
"- TT1[i] += TT1[i - 1]",
"- TT2[i] += TT2[i - 1]",
"-print(min(max(TT1), max(TT2)))",
"+stc = [rl() for _ in range(N)]",
"+stc.sort(key=lambda x: (x[2], x[0]))",
"+nstc = []",
"+for s, t, c in stc:",
"+ if len(nstc) != 0 and nstc[-1][2] == c and nstc[-1][1] == s:",
"+ nstc[-1][1] = t",
"+ else:",
"+ nstc.append([s, t, c])",
"+n = len(nstc)",
"+TT = [0] * (2 * 10**5 + 5)",
"+for i in range(n):",
"+ TT[2 * nstc[i][0] - 1] += 1",
"+ TT[2 * nstc[i][1]] -= 1",
"+for i in range(1, len(TT)):",
"+ TT[i] += TT[i - 1]",
"+print(max(TT))"
] | false | 0.106036 | 0.143932 | 0.73671 | [
"s931442247",
"s955741712"
] |
u342563578 | p02579 | python | s158909014 | s390962846 | 1,004 | 920 | 185,524 | 181,384 | Accepted | Accepted | 8.37 | h,w = list(map(int,input().split()))
c = list(map(int,input().split()))
c[0] -= 1
c[1] -= 1
d = list(map(int,input().split()))
d[0] -= 1
d[1] -= 1
p = []
q = [[None for i in range(w)]for i in range(h)]
r = [[] for i in range(10**6)]
for i in range(h):
s = eval(input())
s = list(s)
p.append(s)
from collections import deque
de = deque()
de.append([c[0],c[1]])
q[c[0]][c[1]] = 0
g = 0
while q[d[0]][d[1]] == None and g < 10**6-3:
while de:
v = de.popleft()
r[g].append([v[0],v[1]])
for i in (-1,1):
j = 0
if 0 <= v[0]-i <= h-1:
if 0 <= v[1]-j <= w-1:
if p[v[0]-i][v[1]-j] == '.' and q[v[0]-i][v[1]-j] == None:
q[v[0]-i][v[1]-j] = g
de.append([v[0]-i,v[1]-j])
for j in (-1,1):
i = 0
if 0 <= v[0]-i <= h-1:
if 0 <= v[1]-j <= w-1:
if p[v[0]-i][v[1]-j] == '.' and q[v[0]-i][v[1]-j] == None:
q[v[0]-i][v[1]-j] = g
de.append([v[0]-i,v[1]-j])
g += 1
while r[g-1]:
v = r[g-1].pop()
for i in range(-2,3):
for j in range(-2,3):
if (abs(i) == 1 and j == 0) or (abs(j) == 1 and i == 0):
continue
else:
if 0 <= v[0]-i <= h-1:
if 0 <= v[1]-j <= w-1:
if p[v[0]-i][v[1]-j] == '.' and q[v[0]-i][v[1]-j] == None:
q[v[0]-i][v[1]-j] = g
de.append([v[0]-i,v[1]-j])
if q[d[0]][d[1]] == None:
print((-1))
else:
print((q[d[0]][d[1]])) | h,w = list(map(int,input().split()))
c = list(map(int,input().split()))
c[0] -= 1
c[1] -= 1
d = list(map(int,input().split()))
d[0] -= 1
d[1] -= 1
p = []
q = [[None for i in range(w)]for i in range(h)]
r = [[] for i in range(10**6)]
for i in range(h):
s = eval(input())
s = list(s)
p.append(s)
from collections import deque
de = deque()
de.append([c[0],c[1]])
q[c[0]][c[1]] = 0
g = 0
while q[d[0]][d[1]] == None and g < 10**6-3:
while de:
v = de.pop()
r[g].append([v[0],v[1]])
for i in (-1,1):
j = 0
if 0 <= v[0]-i <= h-1:
if 0 <= v[1]-j <= w-1:
if p[v[0]-i][v[1]-j] == '.' and q[v[0]-i][v[1]-j] == None:
q[v[0]-i][v[1]-j] = g
de.append([v[0]-i,v[1]-j])
for j in (-1,1):
i = 0
if 0 <= v[0]-i <= h-1:
if 0 <= v[1]-j <= w-1:
if p[v[0]-i][v[1]-j] == '.' and q[v[0]-i][v[1]-j] == None:
q[v[0]-i][v[1]-j] = g
de.append([v[0]-i,v[1]-j])
g += 1
while r[g-1]:
v = r[g-1].pop()
for i in range(-2,3):
for j in range(-2,3):
if (abs(i) == 1 and j == 0) or (abs(j) == 1 and i == 0):
continue
else:
if 0 <= v[0]-i <= h-1:
if 0 <= v[1]-j <= w-1:
if p[v[0]-i][v[1]-j] == '.' and q[v[0]-i][v[1]-j] == None:
q[v[0]-i][v[1]-j] = g
de.append([v[0]-i,v[1]-j])
if q[d[0]][d[1]] == None:
print((-1))
else:
print((q[d[0]][d[1]])) | 54 | 54 | 1,742 | 1,738 | h, w = list(map(int, input().split()))
c = list(map(int, input().split()))
c[0] -= 1
c[1] -= 1
d = list(map(int, input().split()))
d[0] -= 1
d[1] -= 1
p = []
q = [[None for i in range(w)] for i in range(h)]
r = [[] for i in range(10**6)]
for i in range(h):
s = eval(input())
s = list(s)
p.append(s)
from collections import deque
de = deque()
de.append([c[0], c[1]])
q[c[0]][c[1]] = 0
g = 0
while q[d[0]][d[1]] == None and g < 10**6 - 3:
while de:
v = de.popleft()
r[g].append([v[0], v[1]])
for i in (-1, 1):
j = 0
if 0 <= v[0] - i <= h - 1:
if 0 <= v[1] - j <= w - 1:
if p[v[0] - i][v[1] - j] == "." and q[v[0] - i][v[1] - j] == None:
q[v[0] - i][v[1] - j] = g
de.append([v[0] - i, v[1] - j])
for j in (-1, 1):
i = 0
if 0 <= v[0] - i <= h - 1:
if 0 <= v[1] - j <= w - 1:
if p[v[0] - i][v[1] - j] == "." and q[v[0] - i][v[1] - j] == None:
q[v[0] - i][v[1] - j] = g
de.append([v[0] - i, v[1] - j])
g += 1
while r[g - 1]:
v = r[g - 1].pop()
for i in range(-2, 3):
for j in range(-2, 3):
if (abs(i) == 1 and j == 0) or (abs(j) == 1 and i == 0):
continue
else:
if 0 <= v[0] - i <= h - 1:
if 0 <= v[1] - j <= w - 1:
if (
p[v[0] - i][v[1] - j] == "."
and q[v[0] - i][v[1] - j] == None
):
q[v[0] - i][v[1] - j] = g
de.append([v[0] - i, v[1] - j])
if q[d[0]][d[1]] == None:
print((-1))
else:
print((q[d[0]][d[1]]))
| h, w = list(map(int, input().split()))
c = list(map(int, input().split()))
c[0] -= 1
c[1] -= 1
d = list(map(int, input().split()))
d[0] -= 1
d[1] -= 1
p = []
q = [[None for i in range(w)] for i in range(h)]
r = [[] for i in range(10**6)]
for i in range(h):
s = eval(input())
s = list(s)
p.append(s)
from collections import deque
de = deque()
de.append([c[0], c[1]])
q[c[0]][c[1]] = 0
g = 0
while q[d[0]][d[1]] == None and g < 10**6 - 3:
while de:
v = de.pop()
r[g].append([v[0], v[1]])
for i in (-1, 1):
j = 0
if 0 <= v[0] - i <= h - 1:
if 0 <= v[1] - j <= w - 1:
if p[v[0] - i][v[1] - j] == "." and q[v[0] - i][v[1] - j] == None:
q[v[0] - i][v[1] - j] = g
de.append([v[0] - i, v[1] - j])
for j in (-1, 1):
i = 0
if 0 <= v[0] - i <= h - 1:
if 0 <= v[1] - j <= w - 1:
if p[v[0] - i][v[1] - j] == "." and q[v[0] - i][v[1] - j] == None:
q[v[0] - i][v[1] - j] = g
de.append([v[0] - i, v[1] - j])
g += 1
while r[g - 1]:
v = r[g - 1].pop()
for i in range(-2, 3):
for j in range(-2, 3):
if (abs(i) == 1 and j == 0) or (abs(j) == 1 and i == 0):
continue
else:
if 0 <= v[0] - i <= h - 1:
if 0 <= v[1] - j <= w - 1:
if (
p[v[0] - i][v[1] - j] == "."
and q[v[0] - i][v[1] - j] == None
):
q[v[0] - i][v[1] - j] = g
de.append([v[0] - i, v[1] - j])
if q[d[0]][d[1]] == None:
print((-1))
else:
print((q[d[0]][d[1]]))
| false | 0 | [
"- v = de.popleft()",
"+ v = de.pop()"
] | false | 0.758793 | 0.79767 | 0.951261 | [
"s158909014",
"s390962846"
] |
u241159583 | p03273 | python | s355153208 | s196449523 | 20 | 18 | 3,188 | 3,188 | Accepted | Accepted | 10 | h,w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
A = list(zip(*a))
skip_h = []
skip_w = []
for i in range(h):
if a[i] == ["."] * w: skip_h.append(i)
for i in range(w):
if A[i] == tuple(".") * h: skip_w.append(i)
for i in range(h):
if i in skip_h: continue
ans = ""
for j in range(w):
if j in skip_w: continue
ans += a[i][j]
print(ans) | h,w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
skip = []
for i in range(h):
if a[i] == ["."] * w: skip.append(i)
a = list(zip(*a))
d = []
for i in range(w):
if set(a[i]) == {"."}: d.append(i)
d.sort(reverse=True)
for i in d:
a.pop(i)
a = list(zip(*a))
for i in range(h):
if i in skip: continue
else:
print(("".join(a[i]))) | 17 | 20 | 393 | 379 | h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
A = list(zip(*a))
skip_h = []
skip_w = []
for i in range(h):
if a[i] == ["."] * w:
skip_h.append(i)
for i in range(w):
if A[i] == tuple(".") * h:
skip_w.append(i)
for i in range(h):
if i in skip_h:
continue
ans = ""
for j in range(w):
if j in skip_w:
continue
ans += a[i][j]
print(ans)
| h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
skip = []
for i in range(h):
if a[i] == ["."] * w:
skip.append(i)
a = list(zip(*a))
d = []
for i in range(w):
if set(a[i]) == {"."}:
d.append(i)
d.sort(reverse=True)
for i in d:
a.pop(i)
a = list(zip(*a))
for i in range(h):
if i in skip:
continue
else:
print(("".join(a[i])))
| false | 15 | [
"-A = list(zip(*a))",
"-skip_h = []",
"-skip_w = []",
"+skip = []",
"- skip_h.append(i)",
"+ skip.append(i)",
"+a = list(zip(*a))",
"+d = []",
"- if A[i] == tuple(\".\") * h:",
"- skip_w.append(i)",
"+ if set(a[i]) == {\".\"}:",
"+ d.append(i)",
"+d.sort(reverse=True)",
"+for i in d:",
"+ a.pop(i)",
"+a = list(zip(*a))",
"- if i in skip_h:",
"+ if i in skip:",
"- ans = \"\"",
"- for j in range(w):",
"- if j in skip_w:",
"- continue",
"- ans += a[i][j]",
"- print(ans)",
"+ else:",
"+ print((\"\".join(a[i])))"
] | false | 0.044462 | 0.046261 | 0.961109 | [
"s355153208",
"s196449523"
] |
u105210954 | p03160 | python | s620753358 | s406254109 | 991 | 123 | 22,832 | 13,928 | Accepted | Accepted | 87.59 | import numpy as np
def resolve():
n = int(eval(input()))
h = np.array(list(map(int, input().split())))
k = 2
dp = np.zeros(n, dtype=int)
for i in range(1, n):
start = max(0, i - k)
dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print((dp[n - 1]))
resolve() | def resolve():
n = int(eval(input()))
h = list(map(int, input().split()))
# i 番目の足場にたどり着くまでの最小コスト
dp = [float('inf')] * n
dp[0] = 0
for i in range(1, n):
dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
if i > 1:
dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[n - 1]))
resolve() | 16 | 16 | 314 | 369 | import numpy as np
def resolve():
n = int(eval(input()))
h = np.array(list(map(int, input().split())))
k = 2
dp = np.zeros(n, dtype=int)
for i in range(1, n):
start = max(0, i - k)
dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print((dp[n - 1]))
resolve()
| def resolve():
n = int(eval(input()))
h = list(map(int, input().split()))
# i 番目の足場にたどり着くまでの最小コスト
dp = [float("inf")] * n
dp[0] = 0
for i in range(1, n):
dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
if i > 1:
dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[n - 1]))
resolve()
| false | 0 | [
"-import numpy as np",
"-",
"-",
"- h = np.array(list(map(int, input().split())))",
"- k = 2",
"- dp = np.zeros(n, dtype=int)",
"+ h = list(map(int, input().split()))",
"+ # i 番目の足場にたどり着くまでの最小コスト",
"+ dp = [float(\"inf\")] * n",
"+ dp[0] = 0",
"- start = max(0, i - k)",
"- dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))",
"+ dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))",
"+ if i > 1:",
"+ dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))"
] | false | 0.398426 | 0.043638 | 9.13016 | [
"s620753358",
"s406254109"
] |
u597374218 | p03109 | python | s219387227 | s746132407 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | print(("Heisei" if eval(input())<="2019/04/30" else "TBD")) | s=eval(input())
print(("Heisei" if s<="2019/04/30" else "TBD")) | 1 | 2 | 51 | 56 | print(("Heisei" if eval(input()) <= "2019/04/30" else "TBD"))
| s = eval(input())
print(("Heisei" if s <= "2019/04/30" else "TBD"))
| false | 50 | [
"-print((\"Heisei\" if eval(input()) <= \"2019/04/30\" else \"TBD\"))",
"+s = eval(input())",
"+print((\"Heisei\" if s <= \"2019/04/30\" else \"TBD\"))"
] | false | 0.068638 | 0.069188 | 0.992046 | [
"s219387227",
"s746132407"
] |
u499381410 | p03806 | python | s271370217 | s528113303 | 455 | 270 | 59,868 | 46,300 | Accepted | Accepted | 40.66 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, a_ratio, b_ratio = LI()
L = LIR(n)
A, B, cost = [[L[i][j] for i in range(n)] for j in range(3)]
dp = [[INF] * 401 for _ in range(401)]
dp[0][0] = 0
for i in range(n):
for j in range(401, -1, -1):
for k in range(401, -1, -1):
if 0 <= j + A[i] <= 400 and 0 <= k + B[i] <= 400:
dp[j + A[i]][k + B[i]] = min(dp[j + A[i]][k + B[i]], dp[j][k] + cost[i])
ans = INF
for l in range(1, min(400 // b_ratio, 400 // a_ratio)):
ans = min(ans, dp[a_ratio * l][b_ratio * l])
if ans == INF:
print((-1))
else:
print(ans)
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
def gcd(i, j):
while j:
i, j = j, i % j
return i
n, a_ratio, b_ratio = LI()
solution = LIR(n)
dp = {(0, 0): 0}
for a, b, c in solution:
for (ai, bi), ci in list(dp.items()):
# listにしないとduring iteration dictionary changeみたいなerrorでる。
# メモ:defaultdictはもともと存在しないkeyを参照するだけでkey:valueが追加される。
# これによって、key: INFが追加されるのはまずい。だからgetで
dp[(ai + a, bi + b)] = min(dp.get((ai + a, bi + b), INF), ci + c)
ans = INF
for i in range(1, max(400 // a_ratio, 400 // b_ratio)):
ans = min(ans, dp.get((a_ratio * i, b_ratio * i), INF))
print((ans if ans != INF else -1))
| 50 | 57 | 1,505 | 1,737 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
INF = float("inf")
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return sys.stdin.readline().split()
def S():
return sys.stdin.readline().strip()
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, a_ratio, b_ratio = LI()
L = LIR(n)
A, B, cost = [[L[i][j] for i in range(n)] for j in range(3)]
dp = [[INF] * 401 for _ in range(401)]
dp[0][0] = 0
for i in range(n):
for j in range(401, -1, -1):
for k in range(401, -1, -1):
if 0 <= j + A[i] <= 400 and 0 <= k + B[i] <= 400:
dp[j + A[i]][k + B[i]] = min(dp[j + A[i]][k + B[i]], dp[j][k] + cost[i])
ans = INF
for l in range(1, min(400 // b_ratio, 400 // a_ratio)):
ans = min(ans, dp[a_ratio * l][b_ratio * l])
if ans == INF:
print((-1))
else:
print(ans)
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10**20
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
def gcd(i, j):
while j:
i, j = j, i % j
return i
n, a_ratio, b_ratio = LI()
solution = LIR(n)
dp = {(0, 0): 0}
for a, b, c in solution:
for (ai, bi), ci in list(dp.items()):
# listにしないとduring iteration dictionary changeみたいなerrorでる。
# メモ:defaultdictはもともと存在しないkeyを参照するだけでkey:valueが追加される。
# これによって、key: INFが追加されるのはまずい。だからgetで
dp[(ai + a, bi + b)] = min(dp.get((ai + a, bi + b), INF), ci + c)
ans = INF
for i in range(1, max(400 // a_ratio, 400 // b_ratio)):
ans = min(ans, dp.get((a_ratio * i, b_ratio * i), INF))
print((ans if ans != INF else -1))
| false | 12.280702 | [
"+from pprint import pprint",
"+from copy import deepcopy",
"+from pprint import pprint",
"-INF = float(\"inf\")",
"+sys.setrecursionlimit(2147483647)",
"+INF = 10**20",
"- return list(map(int, sys.stdin.readline().split()))",
"+ return list(map(int, sys.stdin.buffer.readline().split()))",
"- return int(sys.stdin.readline())",
"+ return int(sys.stdin.buffer.readline())",
"- return sys.stdin.readline().split()",
"+ return sys.stdin.buffer.readline().rstrip().decode(\"utf-8\").split()",
"- return sys.stdin.readline().strip()",
"+ return sys.stdin.buffer.readline().rstrip().decode(\"utf-8\")",
"+",
"+",
"+def gcd(i, j):",
"+ while j:",
"+ i, j = j, i % j",
"+ return i",
"+",
"+",
"-L = LIR(n)",
"-A, B, cost = [[L[i][j] for i in range(n)] for j in range(3)]",
"-dp = [[INF] * 401 for _ in range(401)]",
"-dp[0][0] = 0",
"-for i in range(n):",
"- for j in range(401, -1, -1):",
"- for k in range(401, -1, -1):",
"- if 0 <= j + A[i] <= 400 and 0 <= k + B[i] <= 400:",
"- dp[j + A[i]][k + B[i]] = min(dp[j + A[i]][k + B[i]], dp[j][k] + cost[i])",
"+solution = LIR(n)",
"+dp = {(0, 0): 0}",
"+for a, b, c in solution:",
"+ for (ai, bi), ci in list(dp.items()):",
"+ # listにしないとduring iteration dictionary changeみたいなerrorでる。",
"+ # メモ:defaultdictはもともと存在しないkeyを参照するだけでkey:valueが追加される。",
"+ # これによって、key: INFが追加されるのはまずい。だからgetで",
"+ dp[(ai + a, bi + b)] = min(dp.get((ai + a, bi + b), INF), ci + c)",
"-for l in range(1, min(400 // b_ratio, 400 // a_ratio)):",
"- ans = min(ans, dp[a_ratio * l][b_ratio * l])",
"-if ans == INF:",
"- print((-1))",
"-else:",
"- print(ans)",
"+for i in range(1, max(400 // a_ratio, 400 // b_ratio)):",
"+ ans = min(ans, dp.get((a_ratio * i, b_ratio * i), INF))",
"+print((ans if ans != INF else -1))"
] | false | 0.795761 | 0.044965 | 17.697312 | [
"s271370217",
"s528113303"
] |
u279460955 | p02579 | python | s554039232 | s313838856 | 840 | 591 | 161,668 | 129,488 | Accepted | Accepted | 29.64 | from collections import deque
h, w = (int(x) for x in input().split())
ch, cw = (int(x) - 1 for x in input().split())
dh, dw = (int(x) - 1 for x in input().split())
S = [list(eval(input())) for _ in range(h)]
grid = [[-1] * w for _ in range(h)]
grid[ch][cw] = 0
walk = [[0, 1], [0, -1], [1, 0], [-1, 0]]
warp = [[2, 2], [2, 1], [2, 0], [2, -1], [2, -2], [1, 2], [1, 1], [1, -1], [1, -2], [0, 2], [0, -2], [-1, 2], [-1, 1],
[-1, -1], [-1, -2], [-2, 2], [-2, 1], [-2, 0], [-2, -1], [-2, -2]]
que = deque([(0, ch, cw)])
while que:
count, y, x = que.popleft()
if grid[y][x] < count:
continue
for NY, NX in walk:
if 0 <= y + NY < h and 0 <= x + NX < w and S[y + NY][x + NX] != '#':
if grid[y + NY][x + NX] == -1 or grid[y + NY][x + NX] > count:
grid[y + NY][x + NX] = count
que.appendleft((count, y + NY, x + NX))
for NY, NX in warp:
if 0 <= y + NY < h and 0 <= x + NX < w and S[y + NY][x + NX] != '#':
if grid[y + NY][x + NX] == -1 or grid[y + NY][x + NX] > count + 1:
grid[y + NY][x + NX] = count + 1
que.append((count + 1, y + NY, x + NX))
print((grid[dh][dw])) | from collections import deque
h, w = (int(x) for x in input().split())
ch, cw = (int(x) - 1 for x in input().split())
dh, dw = (int(x) - 1 for x in input().split())
S = [list(eval(input())) for _ in range(h)]
grid = [[-1] * w for _ in range(h)]
grid[ch][cw] = 0
NX = [1, 0, -1, 0]
NY = [0, 1, 0, -1]
PX = [-2, -2, -2, -2, -2, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2]
PY = [-2, -1, 0, 1, 2, -2, -1, 1, 2, -2, 2, -2, -1, 1, 2, -2, -1, 0, 1, 2]
que = deque([(0, ch, cw)])
while que:
count, y, x = que.popleft()
if grid[y][x] < count:
continue
for i in range(4):
nx = x + NX[i]
ny = y + NY[i]
if 0 <= nx < w and 0 <= ny < h and S[ny][nx] != "#":
if grid[ny][nx] == -1 or grid[ny][nx] > count:
grid[ny][nx] = count
que.appendleft((count, ny, nx))
for i in range(20):
px = x + PX[i]
py = y + PY[i]
if 0 <= px < w and 0 <= py < h and S[py][px] != "#":
if grid[py][px] == -1 or grid[py][px] > count + 1:
grid[py][px] = count + 1
que.append((count + 1, py, px))
print((grid[dh][dw]))
| 29 | 34 | 1,215 | 1,171 | from collections import deque
h, w = (int(x) for x in input().split())
ch, cw = (int(x) - 1 for x in input().split())
dh, dw = (int(x) - 1 for x in input().split())
S = [list(eval(input())) for _ in range(h)]
grid = [[-1] * w for _ in range(h)]
grid[ch][cw] = 0
walk = [[0, 1], [0, -1], [1, 0], [-1, 0]]
warp = [
[2, 2],
[2, 1],
[2, 0],
[2, -1],
[2, -2],
[1, 2],
[1, 1],
[1, -1],
[1, -2],
[0, 2],
[0, -2],
[-1, 2],
[-1, 1],
[-1, -1],
[-1, -2],
[-2, 2],
[-2, 1],
[-2, 0],
[-2, -1],
[-2, -2],
]
que = deque([(0, ch, cw)])
while que:
count, y, x = que.popleft()
if grid[y][x] < count:
continue
for NY, NX in walk:
if 0 <= y + NY < h and 0 <= x + NX < w and S[y + NY][x + NX] != "#":
if grid[y + NY][x + NX] == -1 or grid[y + NY][x + NX] > count:
grid[y + NY][x + NX] = count
que.appendleft((count, y + NY, x + NX))
for NY, NX in warp:
if 0 <= y + NY < h and 0 <= x + NX < w and S[y + NY][x + NX] != "#":
if grid[y + NY][x + NX] == -1 or grid[y + NY][x + NX] > count + 1:
grid[y + NY][x + NX] = count + 1
que.append((count + 1, y + NY, x + NX))
print((grid[dh][dw]))
| from collections import deque
h, w = (int(x) for x in input().split())
ch, cw = (int(x) - 1 for x in input().split())
dh, dw = (int(x) - 1 for x in input().split())
S = [list(eval(input())) for _ in range(h)]
grid = [[-1] * w for _ in range(h)]
grid[ch][cw] = 0
NX = [1, 0, -1, 0]
NY = [0, 1, 0, -1]
PX = [-2, -2, -2, -2, -2, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2]
PY = [-2, -1, 0, 1, 2, -2, -1, 1, 2, -2, 2, -2, -1, 1, 2, -2, -1, 0, 1, 2]
que = deque([(0, ch, cw)])
while que:
count, y, x = que.popleft()
if grid[y][x] < count:
continue
for i in range(4):
nx = x + NX[i]
ny = y + NY[i]
if 0 <= nx < w and 0 <= ny < h and S[ny][nx] != "#":
if grid[ny][nx] == -1 or grid[ny][nx] > count:
grid[ny][nx] = count
que.appendleft((count, ny, nx))
for i in range(20):
px = x + PX[i]
py = y + PY[i]
if 0 <= px < w and 0 <= py < h and S[py][px] != "#":
if grid[py][px] == -1 or grid[py][px] > count + 1:
grid[py][px] = count + 1
que.append((count + 1, py, px))
print((grid[dh][dw]))
| false | 14.705882 | [
"-walk = [[0, 1], [0, -1], [1, 0], [-1, 0]]",
"-warp = [",
"- [2, 2],",
"- [2, 1],",
"- [2, 0],",
"- [2, -1],",
"- [2, -2],",
"- [1, 2],",
"- [1, 1],",
"- [1, -1],",
"- [1, -2],",
"- [0, 2],",
"- [0, -2],",
"- [-1, 2],",
"- [-1, 1],",
"- [-1, -1],",
"- [-1, -2],",
"- [-2, 2],",
"- [-2, 1],",
"- [-2, 0],",
"- [-2, -1],",
"- [-2, -2],",
"-]",
"+NX = [1, 0, -1, 0]",
"+NY = [0, 1, 0, -1]",
"+PX = [-2, -2, -2, -2, -2, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2]",
"+PY = [-2, -1, 0, 1, 2, -2, -1, 1, 2, -2, 2, -2, -1, 1, 2, -2, -1, 0, 1, 2]",
"- for NY, NX in walk:",
"- if 0 <= y + NY < h and 0 <= x + NX < w and S[y + NY][x + NX] != \"#\":",
"- if grid[y + NY][x + NX] == -1 or grid[y + NY][x + NX] > count:",
"- grid[y + NY][x + NX] = count",
"- que.appendleft((count, y + NY, x + NX))",
"- for NY, NX in warp:",
"- if 0 <= y + NY < h and 0 <= x + NX < w and S[y + NY][x + NX] != \"#\":",
"- if grid[y + NY][x + NX] == -1 or grid[y + NY][x + NX] > count + 1:",
"- grid[y + NY][x + NX] = count + 1",
"- que.append((count + 1, y + NY, x + NX))",
"+ for i in range(4):",
"+ nx = x + NX[i]",
"+ ny = y + NY[i]",
"+ if 0 <= nx < w and 0 <= ny < h and S[ny][nx] != \"#\":",
"+ if grid[ny][nx] == -1 or grid[ny][nx] > count:",
"+ grid[ny][nx] = count",
"+ que.appendleft((count, ny, nx))",
"+ for i in range(20):",
"+ px = x + PX[i]",
"+ py = y + PY[i]",
"+ if 0 <= px < w and 0 <= py < h and S[py][px] != \"#\":",
"+ if grid[py][px] == -1 or grid[py][px] > count + 1:",
"+ grid[py][px] = count + 1",
"+ que.append((count + 1, py, px))"
] | false | 0.037749 | 0.06115 | 0.617325 | [
"s554039232",
"s313838856"
] |
u127499732 | p02899 | python | s921810814 | s659969305 | 88 | 72 | 15,528 | 18,316 | Accepted | Accepted | 18.18 | import sys
n=int(eval(input()))
a=tuple(map(int,sys.stdin.readline().split()))
b=[0]*n
i=1
for index in a:
b[index-1]=str(i)
i+=1
print((" ".join(b))) | def main():
import sys
n=int(eval(input()))
a=tuple(map(int,sys.stdin.readline().split()))
b=[0]*n
i=1
for index in a:
b[index-1]=i
i+=1
print((" ".join(map(str,b))))
if __name__=="__main__":
main() | 9 | 12 | 154 | 225 | import sys
n = int(eval(input()))
a = tuple(map(int, sys.stdin.readline().split()))
b = [0] * n
i = 1
for index in a:
b[index - 1] = str(i)
i += 1
print((" ".join(b)))
| def main():
import sys
n = int(eval(input()))
a = tuple(map(int, sys.stdin.readline().split()))
b = [0] * n
i = 1
for index in a:
b[index - 1] = i
i += 1
print((" ".join(map(str, b))))
if __name__ == "__main__":
main()
| false | 25 | [
"-import sys",
"+def main():",
"+ import sys",
"-n = int(eval(input()))",
"-a = tuple(map(int, sys.stdin.readline().split()))",
"-b = [0] * n",
"-i = 1",
"-for index in a:",
"- b[index - 1] = str(i)",
"- i += 1",
"-print((\" \".join(b)))",
"+ n = int(eval(input()))",
"+ a = tuple(map(int, sys.stdin.readline().split()))",
"+ b = [0] * n",
"+ i = 1",
"+ for index in a:",
"+ b[index - 1] = i",
"+ i += 1",
"+ print((\" \".join(map(str, b))))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.110167 | 0.184382 | 0.597492 | [
"s921810814",
"s659969305"
] |
u186838327 | p02756 | python | s019954272 | s337169365 | 380 | 334 | 100,864 | 101,192 | Accepted | Accepted | 12.11 | s = list(str(eval(input())))
q = int(eval(input()))
from collections import deque
s = deque(s)
cnt = 0
for i in range(q):
query = list(map(str, input().split()))
if len(query) == 1:
cnt += 1
else:
t, f, c = query
if f == '1':
if cnt%2 == 0:
s.appendleft(c)
else:
s.append(c)
else:
if cnt%2 == 0:
s.append(c)
else:
s.appendleft(c)
s = list(s)
if cnt%2 == 1:
s.reverse()
print((''.join(s)))
| s = list(str(eval(input())))
q = int(eval(input()))
flag = 1
from collections import deque
s = deque(s)
for i in range(q):
query = list(map(str, input().split()))
if len(query) == 1:
flag = 1-flag
else:
t, f, c = query
if f == '1':
if flag:
s.appendleft(c)
else:
s.append(c)
else:
if flag:
s.append(c)
else:
s.appendleft(c)
s = list(s)
if not flag:
s.reverse()
print((''.join(s)))
| 28 | 26 | 565 | 553 | s = list(str(eval(input())))
q = int(eval(input()))
from collections import deque
s = deque(s)
cnt = 0
for i in range(q):
query = list(map(str, input().split()))
if len(query) == 1:
cnt += 1
else:
t, f, c = query
if f == "1":
if cnt % 2 == 0:
s.appendleft(c)
else:
s.append(c)
else:
if cnt % 2 == 0:
s.append(c)
else:
s.appendleft(c)
s = list(s)
if cnt % 2 == 1:
s.reverse()
print(("".join(s)))
| s = list(str(eval(input())))
q = int(eval(input()))
flag = 1
from collections import deque
s = deque(s)
for i in range(q):
query = list(map(str, input().split()))
if len(query) == 1:
flag = 1 - flag
else:
t, f, c = query
if f == "1":
if flag:
s.appendleft(c)
else:
s.append(c)
else:
if flag:
s.append(c)
else:
s.appendleft(c)
s = list(s)
if not flag:
s.reverse()
print(("".join(s)))
| false | 7.142857 | [
"+flag = 1",
"-cnt = 0",
"- cnt += 1",
"+ flag = 1 - flag",
"- if cnt % 2 == 0:",
"+ if flag:",
"- if cnt % 2 == 0:",
"+ if flag:",
"-if cnt % 2 == 1:",
"+if not flag:"
] | false | 0.037646 | 0.045215 | 0.832604 | [
"s019954272",
"s337169365"
] |
u726615467 | p03607 | python | s104138824 | s791482308 | 228 | 196 | 7,508 | 19,472 | Accepted | Accepted | 14.04 | # encoding: utf-8
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
A.sort()
tag = -1
cnt = 0
ans = 0
for Ai in A:
if Ai > tag:
tag = Ai
ans += cnt % 2
cnt = 0
cnt += 1
else:
ans += cnt % 2
print(ans) | N = int(eval(input()))
A = [eval(input()) for _ in range(N)]
cnt = {}
for Ai in A:
key = str(Ai)
cnt[key] = cnt.setdefault(key, 0) + 1
ans = sum([cnt[key] % 2 for key in list(cnt.keys())])
print(ans) | 19 | 10 | 269 | 200 | # encoding: utf-8
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
A.sort()
tag = -1
cnt = 0
ans = 0
for Ai in A:
if Ai > tag:
tag = Ai
ans += cnt % 2
cnt = 0
cnt += 1
else:
ans += cnt % 2
print(ans)
| N = int(eval(input()))
A = [eval(input()) for _ in range(N)]
cnt = {}
for Ai in A:
key = str(Ai)
cnt[key] = cnt.setdefault(key, 0) + 1
ans = sum([cnt[key] % 2 for key in list(cnt.keys())])
print(ans)
| false | 47.368421 | [
"-# encoding: utf-8",
"-A = [int(eval(input())) for i in range(N)]",
"-A.sort()",
"-tag = -1",
"-cnt = 0",
"-ans = 0",
"+A = [eval(input()) for _ in range(N)]",
"+cnt = {}",
"- if Ai > tag:",
"- tag = Ai",
"- ans += cnt % 2",
"- cnt = 0",
"- cnt += 1",
"-else:",
"- ans += cnt % 2",
"+ key = str(Ai)",
"+ cnt[key] = cnt.setdefault(key, 0) + 1",
"+ans = sum([cnt[key] % 2 for key in list(cnt.keys())])"
] | false | 0.044127 | 0.043831 | 1.006751 | [
"s104138824",
"s791482308"
] |
u777283665 | p03559 | python | s913713822 | s819109722 | 475 | 315 | 106,344 | 23,092 | Accepted | Accepted | 33.68 | from bisect import bisect_right, bisect_left
n = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))
ans = 0
for x in b:
ans += bisect_left(a, x) * (n - bisect_right(c, x))
print(ans) | import bisect
n = int(eval(input()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for b in B:
ans += bisect.bisect_left(A, b) * (n - bisect.bisect_right(C, b))
print(ans) | 13 | 12 | 286 | 277 | from bisect import bisect_right, bisect_left
n = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))
ans = 0
for x in b:
ans += bisect_left(a, x) * (n - bisect_right(c, x))
print(ans)
| import bisect
n = int(eval(input()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for b in B:
ans += bisect.bisect_left(A, b) * (n - bisect.bisect_right(C, b))
print(ans)
| false | 7.692308 | [
"-from bisect import bisect_right, bisect_left",
"+import bisect",
"-a = sorted(list(map(int, input().split())))",
"-b = list(map(int, input().split()))",
"-c = sorted(list(map(int, input().split())))",
"+A = sorted(list(map(int, input().split())))",
"+B = sorted(list(map(int, input().split())))",
"+C = sorted(list(map(int, input().split())))",
"-for x in b:",
"- ans += bisect_left(a, x) * (n - bisect_right(c, x))",
"+for b in B:",
"+ ans += bisect.bisect_left(A, b) * (n - bisect.bisect_right(C, b))"
] | false | 0.045512 | 0.148648 | 0.306175 | [
"s913713822",
"s819109722"
] |
u737758066 | p02772 | python | s791589749 | s955573580 | 191 | 163 | 38,384 | 38,256 | Accepted | Accepted | 14.66 | n = int(eval(input()))
a = list(map(int, input().split()))
for i in range(n):
if a[i] % 2 == 0:
if a[i] % 3 != 0 and a[i] % 5 != 0:
print('DENIED')
exit()
print('APPROVED')
| n = int(eval(input()))
a = list(map(int, input().split()))
for i in range(n):
if a[i] % 2 == 0:
if a[i] % 3 == 0 or a[i] % 5 == 0:
continue
else:
print('DENIED')
exit(0)
print('APPROVED') | 8 | 11 | 210 | 248 | n = int(eval(input()))
a = list(map(int, input().split()))
for i in range(n):
if a[i] % 2 == 0:
if a[i] % 3 != 0 and a[i] % 5 != 0:
print("DENIED")
exit()
print("APPROVED")
| n = int(eval(input()))
a = list(map(int, input().split()))
for i in range(n):
if a[i] % 2 == 0:
if a[i] % 3 == 0 or a[i] % 5 == 0:
continue
else:
print("DENIED")
exit(0)
print("APPROVED")
| false | 27.272727 | [
"- if a[i] % 3 != 0 and a[i] % 5 != 0:",
"+ if a[i] % 3 == 0 or a[i] % 5 == 0:",
"+ continue",
"+ else:",
"- exit()",
"+ exit(0)"
] | false | 0.036867 | 0.037163 | 0.992061 | [
"s791589749",
"s955573580"
] |
u761320129 | p03986 | python | s952229387 | s130169263 | 48 | 43 | 3,500 | 3,500 | Accepted | Accepted | 10.42 | X = eval(input())
s = ans = 0
for c in X:
if c=='S':
s += 1
else:
if s > 0:
s -= 1
else:
ans += 1
print((ans+s)) | S = eval(input())
s = ans = 0
for c in S:
if c=='S':
s += 1
else:
if s:
s -= 1
else:
ans += 1
print((ans+s)) | 11 | 11 | 170 | 166 | X = eval(input())
s = ans = 0
for c in X:
if c == "S":
s += 1
else:
if s > 0:
s -= 1
else:
ans += 1
print((ans + s))
| S = eval(input())
s = ans = 0
for c in S:
if c == "S":
s += 1
else:
if s:
s -= 1
else:
ans += 1
print((ans + s))
| false | 0 | [
"-X = eval(input())",
"+S = eval(input())",
"-for c in X:",
"+for c in S:",
"- if s > 0:",
"+ if s:"
] | false | 0.046105 | 0.080254 | 0.574491 | [
"s952229387",
"s130169263"
] |
u124498235 | p02995 | python | s791717550 | s680040135 | 53 | 36 | 5,600 | 5,048 | Accepted | Accepted | 32.08 | from fractions import gcd
a, b, c, d = list(map(int, input().split()))
e = b//c - (a-1)//c
f = b//d - (a-1)//d
def lcm(x, y):
return (x * y) // gcd(x, y)
g = lcm(c, d)
h = b//g - (a-1)//g
print((b-a+1 -(e+f-h))) | from fractions import gcd
a, b, c, d = list(map(int, input().split()))
def lcm(x,y):
return (x*y)//gcd(x,y)
e = lcm(c,d)
f = (b//c + b//d) - b//e
g = ((a-1)//c + (a-1)//d) - (a-1)//e
print((b-a+1-(f-g))) | 10 | 10 | 215 | 208 | from fractions import gcd
a, b, c, d = list(map(int, input().split()))
e = b // c - (a - 1) // c
f = b // d - (a - 1) // d
def lcm(x, y):
return (x * y) // gcd(x, y)
g = lcm(c, d)
h = b // g - (a - 1) // g
print((b - a + 1 - (e + f - h)))
| from fractions import gcd
a, b, c, d = list(map(int, input().split()))
def lcm(x, y):
return (x * y) // gcd(x, y)
e = lcm(c, d)
f = (b // c + b // d) - b // e
g = ((a - 1) // c + (a - 1) // d) - (a - 1) // e
print((b - a + 1 - (f - g)))
| false | 0 | [
"-e = b // c - (a - 1) // c",
"-f = b // d - (a - 1) // d",
"-g = lcm(c, d)",
"-h = b // g - (a - 1) // g",
"-print((b - a + 1 - (e + f - h)))",
"+e = lcm(c, d)",
"+f = (b // c + b // d) - b // e",
"+g = ((a - 1) // c + (a - 1) // d) - (a - 1) // e",
"+print((b - a + 1 - (f - g)))"
] | false | 0.046391 | 0.043537 | 1.065561 | [
"s791717550",
"s680040135"
] |
u743164083 | p02767 | python | s797302676 | s606311960 | 187 | 17 | 40,432 | 2,940 | Accepted | Accepted | 90.91 | N = int(eval(input()))
X = list(map(int, input().split()))
sav = float("inf")
for i in range(min(X), max(X)+1):
Xe = [abs(x-i)**2 for x in X]
health = sum(Xe)
if sav > health:
sav = health
print(sav)
| N = int(eval(input()))
X = list(map(int, input().split()))
xp = round(sum(X) / N)
Xe = [abs(x - xp) ** 2 for x in X]
print((sum(Xe)))
| 10 | 5 | 227 | 135 | N = int(eval(input()))
X = list(map(int, input().split()))
sav = float("inf")
for i in range(min(X), max(X) + 1):
Xe = [abs(x - i) ** 2 for x in X]
health = sum(Xe)
if sav > health:
sav = health
print(sav)
| N = int(eval(input()))
X = list(map(int, input().split()))
xp = round(sum(X) / N)
Xe = [abs(x - xp) ** 2 for x in X]
print((sum(Xe)))
| false | 50 | [
"-sav = float(\"inf\")",
"-for i in range(min(X), max(X) + 1):",
"- Xe = [abs(x - i) ** 2 for x in X]",
"- health = sum(Xe)",
"- if sav > health:",
"- sav = health",
"-print(sav)",
"+xp = round(sum(X) / N)",
"+Xe = [abs(x - xp) ** 2 for x in X]",
"+print((sum(Xe)))"
] | false | 0.046167 | 0.038061 | 1.212973 | [
"s797302676",
"s606311960"
] |
u392319141 | p03599 | python | s098647673 | s179953432 | 207 | 24 | 42,732 | 3,064 | Accepted | Accepted | 88.41 | A, B, C, D, E, F = list(map(int, input().split()))
maxVal = 0
ans = (100 * A, 0)
for aWater in range(0, F + 1, A * 100):
for bWater in range(0, F + 1, B * 100):
sumWater = aWater + bWater
if sumWater == 0 or sumWater > F:
continue
maxSuger = sumWater * E // 100
for cSuger in range(0, maxSuger + 1, C):
for dSuger in range(0, maxSuger + 1, D):
sumSuger = cSuger + dSuger
if sumSuger + sumWater > F or sumSuger > maxSuger:
break
if maxVal < sumSuger / (sumSuger + sumWater):
maxVal = sumSuger / (sumSuger + sumWater)
ans = (sumSuger + sumWater, sumSuger)
print((*ans)) | A, B, C, D, E, F = list(map(int, input().split()))
A *= 100
B *= 100
dp = [-1] * (F + 1) # dp[f] = sugar
dp[0] = 0
for f in range(F + 1):
if A + f <= F:
dp[A + f] = max(dp[A + f], dp[f])
if B + f <= F:
dp[B + f] = max(dp[B + f], dp[f])
if C + f <= F and dp[f] >= 0:
water = f - dp[f]
maxSugar = (water // 100) * E
if dp[f] + C <= maxSugar:
dp[C + f] = max(dp[C + f], dp[f] + C)
if D + f <= F and dp[f] >= 0:
water = f - dp[f]
maxSugar = (water // 100) * E
if dp[f] + D <= maxSugar:
dp[D + f] = max(dp[D + f], dp[f] + D)
ans = (0, 0)
mx = -1
for f in range(1, F + 1):
if mx < 100 * dp[f] / f:
mx = 100 * dp[f] / f
ans = (f, dp[f])
print((*ans))
| 20 | 30 | 748 | 793 | A, B, C, D, E, F = list(map(int, input().split()))
maxVal = 0
ans = (100 * A, 0)
for aWater in range(0, F + 1, A * 100):
for bWater in range(0, F + 1, B * 100):
sumWater = aWater + bWater
if sumWater == 0 or sumWater > F:
continue
maxSuger = sumWater * E // 100
for cSuger in range(0, maxSuger + 1, C):
for dSuger in range(0, maxSuger + 1, D):
sumSuger = cSuger + dSuger
if sumSuger + sumWater > F or sumSuger > maxSuger:
break
if maxVal < sumSuger / (sumSuger + sumWater):
maxVal = sumSuger / (sumSuger + sumWater)
ans = (sumSuger + sumWater, sumSuger)
print((*ans))
| A, B, C, D, E, F = list(map(int, input().split()))
A *= 100
B *= 100
dp = [-1] * (F + 1) # dp[f] = sugar
dp[0] = 0
for f in range(F + 1):
if A + f <= F:
dp[A + f] = max(dp[A + f], dp[f])
if B + f <= F:
dp[B + f] = max(dp[B + f], dp[f])
if C + f <= F and dp[f] >= 0:
water = f - dp[f]
maxSugar = (water // 100) * E
if dp[f] + C <= maxSugar:
dp[C + f] = max(dp[C + f], dp[f] + C)
if D + f <= F and dp[f] >= 0:
water = f - dp[f]
maxSugar = (water // 100) * E
if dp[f] + D <= maxSugar:
dp[D + f] = max(dp[D + f], dp[f] + D)
ans = (0, 0)
mx = -1
for f in range(1, F + 1):
if mx < 100 * dp[f] / f:
mx = 100 * dp[f] / f
ans = (f, dp[f])
print((*ans))
| false | 33.333333 | [
"-maxVal = 0",
"-ans = (100 * A, 0)",
"-for aWater in range(0, F + 1, A * 100):",
"- for bWater in range(0, F + 1, B * 100):",
"- sumWater = aWater + bWater",
"- if sumWater == 0 or sumWater > F:",
"- continue",
"- maxSuger = sumWater * E // 100",
"- for cSuger in range(0, maxSuger + 1, C):",
"- for dSuger in range(0, maxSuger + 1, D):",
"- sumSuger = cSuger + dSuger",
"- if sumSuger + sumWater > F or sumSuger > maxSuger:",
"- break",
"- if maxVal < sumSuger / (sumSuger + sumWater):",
"- maxVal = sumSuger / (sumSuger + sumWater)",
"- ans = (sumSuger + sumWater, sumSuger)",
"+A *= 100",
"+B *= 100",
"+dp = [-1] * (F + 1) # dp[f] = sugar",
"+dp[0] = 0",
"+for f in range(F + 1):",
"+ if A + f <= F:",
"+ dp[A + f] = max(dp[A + f], dp[f])",
"+ if B + f <= F:",
"+ dp[B + f] = max(dp[B + f], dp[f])",
"+ if C + f <= F and dp[f] >= 0:",
"+ water = f - dp[f]",
"+ maxSugar = (water // 100) * E",
"+ if dp[f] + C <= maxSugar:",
"+ dp[C + f] = max(dp[C + f], dp[f] + C)",
"+ if D + f <= F and dp[f] >= 0:",
"+ water = f - dp[f]",
"+ maxSugar = (water // 100) * E",
"+ if dp[f] + D <= maxSugar:",
"+ dp[D + f] = max(dp[D + f], dp[f] + D)",
"+ans = (0, 0)",
"+mx = -1",
"+for f in range(1, F + 1):",
"+ if mx < 100 * dp[f] / f:",
"+ mx = 100 * dp[f] / f",
"+ ans = (f, dp[f])"
] | false | 0.162194 | 0.08068 | 2.010325 | [
"s098647673",
"s179953432"
] |
u189023301 | p02567 | python | s348023003 | s534220536 | 1,423 | 764 | 99,896 | 116,636 | Accepted | Accepted | 46.31 | def solve():
def segfunc(x, y):
return max(x, y)
def init(init_val):
for i in range(n):
seg[i + num - 1] = init_val[i]
for i in range(num - 2, -1, -1):
seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])
def update(k, x):
k += num - 1
seg[k] = x
while k:
k = (k - 1) // 2
seg[k] = segfunc(seg[k * 2 + 1], seg[k * 2 + 2])
def query(p, q):
if q <= p:
return ide_ele
p += num - 1
q += num - 2
res = ide_ele
while q - p > 1:
if p & 1 == 0:
res = segfunc(res, seg[p])
if q & 1 == 1:
res = segfunc(res, seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = segfunc(res, seg[p])
else:
res = segfunc(segfunc(res, seg[p]), seg[q])
return res
n, q = list(map(int, input().split()))
a = list(map(int, input().split()))
ide_ele = 0
num = 2 ** (n - 1).bit_length()
seg = [ide_ele] * 2 * num
init(a)
for _ in range(q):
t, a, b = list(map(int, input().split()))
if t == 1:
update(a - 1, b)
elif t == 2:
print((query(a - 1, b)))
elif t == 3:
ng = a - 1
ok = n + 1
while ok > ng + 1:
mid = (ok + ng) // 2
if query(ng, mid) >= b:
ok = mid
else:
ng = mid
print(ok)
solve()
| import sys
input = lambda: sys.stdin.readline()
def solve():
def init(init_val):
for i in range(n):
seg[i + num - 1] = init_val[i]
for i in range(num - 2, -1, -1):
seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])
def update(k, x):
k += num - 1
seg[k] = x
while k:
k = (k - 1) // 2
seg[k] = segfunc(seg[k * 2 + 1], seg[k * 2 + 2])
def query(p, q):
if q <= p:
return ide_ele
p += num - 1
q += num - 2
res = ide_ele
while q - p > 1:
if p & 1 == 0:
res = segfunc(res, seg[p])
if q & 1 == 1:
res = segfunc(res, seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = segfunc(res, seg[p])
else:
res = segfunc(segfunc(res, seg[p]), seg[q])
return res
n, q = list(map(int, input().split()))
a = list(map(int, input().split()))
segfunc = lambda x, y: max(x, y)
ide_ele = 0
num = 2 ** (n - 1).bit_length()
seg = [ide_ele] * 2 * num
init(a)
res = []
for _ in range(q):
t, a, b = list(map(int, input().split()))
if t == 1:
update(a - 1, b)
elif t == 2:
res.append(query(a - 1, b))
elif t == 3:
ng = a - 1
ok = n + 1
while ok > ng + 1:
mid = (ok + ng) // 2
if query(ng, mid) >= b:
ok = mid
else:
ng = mid
res.append(ok)
print(("\n".join(map(str, res))))
solve()
| 65 | 69 | 1,644 | 1,745 | def solve():
def segfunc(x, y):
return max(x, y)
def init(init_val):
for i in range(n):
seg[i + num - 1] = init_val[i]
for i in range(num - 2, -1, -1):
seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])
def update(k, x):
k += num - 1
seg[k] = x
while k:
k = (k - 1) // 2
seg[k] = segfunc(seg[k * 2 + 1], seg[k * 2 + 2])
def query(p, q):
if q <= p:
return ide_ele
p += num - 1
q += num - 2
res = ide_ele
while q - p > 1:
if p & 1 == 0:
res = segfunc(res, seg[p])
if q & 1 == 1:
res = segfunc(res, seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = segfunc(res, seg[p])
else:
res = segfunc(segfunc(res, seg[p]), seg[q])
return res
n, q = list(map(int, input().split()))
a = list(map(int, input().split()))
ide_ele = 0
num = 2 ** (n - 1).bit_length()
seg = [ide_ele] * 2 * num
init(a)
for _ in range(q):
t, a, b = list(map(int, input().split()))
if t == 1:
update(a - 1, b)
elif t == 2:
print((query(a - 1, b)))
elif t == 3:
ng = a - 1
ok = n + 1
while ok > ng + 1:
mid = (ok + ng) // 2
if query(ng, mid) >= b:
ok = mid
else:
ng = mid
print(ok)
solve()
| import sys
input = lambda: sys.stdin.readline()
def solve():
def init(init_val):
for i in range(n):
seg[i + num - 1] = init_val[i]
for i in range(num - 2, -1, -1):
seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])
def update(k, x):
k += num - 1
seg[k] = x
while k:
k = (k - 1) // 2
seg[k] = segfunc(seg[k * 2 + 1], seg[k * 2 + 2])
def query(p, q):
if q <= p:
return ide_ele
p += num - 1
q += num - 2
res = ide_ele
while q - p > 1:
if p & 1 == 0:
res = segfunc(res, seg[p])
if q & 1 == 1:
res = segfunc(res, seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = segfunc(res, seg[p])
else:
res = segfunc(segfunc(res, seg[p]), seg[q])
return res
n, q = list(map(int, input().split()))
a = list(map(int, input().split()))
segfunc = lambda x, y: max(x, y)
ide_ele = 0
num = 2 ** (n - 1).bit_length()
seg = [ide_ele] * 2 * num
init(a)
res = []
for _ in range(q):
t, a, b = list(map(int, input().split()))
if t == 1:
update(a - 1, b)
elif t == 2:
res.append(query(a - 1, b))
elif t == 3:
ng = a - 1
ok = n + 1
while ok > ng + 1:
mid = (ok + ng) // 2
if query(ng, mid) >= b:
ok = mid
else:
ng = mid
res.append(ok)
print(("\n".join(map(str, res))))
solve()
| false | 5.797101 | [
"+import sys",
"+",
"+input = lambda: sys.stdin.readline()",
"+",
"+",
"- def segfunc(x, y):",
"- return max(x, y)",
"-",
"+ segfunc = lambda x, y: max(x, y)",
"+ res = []",
"- print((query(a - 1, b)))",
"+ res.append(query(a - 1, b))",
"- print(ok)",
"+ res.append(ok)",
"+ print((\"\\n\".join(map(str, res))))"
] | false | 0.039464 | 0.079853 | 0.49421 | [
"s348023003",
"s534220536"
] |
u094191970 | p03645 | python | s734699505 | s538976579 | 895 | 549 | 38,320 | 38,320 | Accepted | Accepted | 38.66 | n,m=list(map(int,input().split()))
tree=[[] for i in range(n)]
for i in range(m):
a,b=list(map(int,input().split()))
a-=1
b-=1
tree[a].append(b)
tree[b].append(a)
for i in tree[0]:
for j in tree[i]:
if j==n-1:
print('POSSIBLE')
exit()
print('IMPOSSIBLE') | from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
n,m=nii()
tree=[[] for i in range(n)]
for i in range(m):
a,b=nii()
a-=1
b-=1
tree[a].append(b)
tree[b].append(a)
for i in tree[0]:
for j in tree[i]:
if j==n-1:
print('POSSIBLE')
exit()
print('IMPOSSIBLE') | 16 | 19 | 287 | 320 | n, m = list(map(int, input().split()))
tree = [[] for i in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
tree[a].append(b)
tree[b].append(a)
for i in tree[0]:
for j in tree[i]:
if j == n - 1:
print("POSSIBLE")
exit()
print("IMPOSSIBLE")
| from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
n, m = nii()
tree = [[] for i in range(n)]
for i in range(m):
a, b = nii()
a -= 1
b -= 1
tree[a].append(b)
tree[b].append(a)
for i in tree[0]:
for j in tree[i]:
if j == n - 1:
print("POSSIBLE")
exit()
print("IMPOSSIBLE")
| false | 15.789474 | [
"-n, m = list(map(int, input().split()))",
"+from sys import stdin",
"+",
"+nii = lambda: list(map(int, stdin.readline().split()))",
"+n, m = nii()",
"- a, b = list(map(int, input().split()))",
"+ a, b = nii()"
] | false | 0.046423 | 0.045428 | 1.021906 | [
"s734699505",
"s538976579"
] |
u729133443 | p03730 | python | s989999152 | s498932426 | 318 | 17 | 65,644 | 2,940 | Accepted | Accepted | 94.65 | from fractions import*;a,b,c=list(map(int,input().split()));print(('YNEOS'[c%gcd(a,b)>0::2])) | a,b,c=list(map(int,input().split()));print(('YNEOS'[all(a*i%b-c for i in range(99))::2])) | 1 | 1 | 85 | 81 | from fractions import *
a, b, c = list(map(int, input().split()))
print(("YNEOS"[c % gcd(a, b) > 0 :: 2]))
| a, b, c = list(map(int, input().split()))
print(("YNEOS"[all(a * i % b - c for i in range(99)) :: 2]))
| false | 0 | [
"-from fractions import *",
"-",
"-print((\"YNEOS\"[c % gcd(a, b) > 0 :: 2]))",
"+print((\"YNEOS\"[all(a * i % b - c for i in range(99)) :: 2]))"
] | false | 0.05445 | 0.034142 | 1.594842 | [
"s989999152",
"s498932426"
] |
u762420987 | p03999 | python | s744441601 | s036105416 | 210 | 38 | 39,664 | 3,444 | Accepted | Accepted | 81.9 | from copy import copy
S = list(eval(input()))
n = len(S)
total = int("".join(S))
siki = set()
for i in range(2 ** (n - 1)):
S_ = copy(S)
plus_count = 0
for j in range(n - 1): # このループが一番のポイント
if ((i >> j) & 1): # 順に右にシフトさせ最下位bitのチェックを行う
S_.insert(plus_count + j + 1, "+") # フラグが立っていたら bag に果物を詰める
plus_count += 1
siki.add("".join(S_)) # 買い物累計額にも加算
for s in list(siki):
total += eval(s)
print(total)
| S = list(eval(input()))
ls = len(S)
n = ls - 1
ans = 0
from copy import deepcopy
for i in range(2 ** n):
siki = deepcopy(S)
add = 1
for j in range(n):
if ((i >> j) & 1):
siki.insert(j+add, "+")
add += 1
# print("".join(siki))
ans += eval("".join(siki))
print(ans)
| 17 | 15 | 473 | 324 | from copy import copy
S = list(eval(input()))
n = len(S)
total = int("".join(S))
siki = set()
for i in range(2 ** (n - 1)):
S_ = copy(S)
plus_count = 0
for j in range(n - 1): # このループが一番のポイント
if (i >> j) & 1: # 順に右にシフトさせ最下位bitのチェックを行う
S_.insert(plus_count + j + 1, "+") # フラグが立っていたら bag に果物を詰める
plus_count += 1
siki.add("".join(S_)) # 買い物累計額にも加算
for s in list(siki):
total += eval(s)
print(total)
| S = list(eval(input()))
ls = len(S)
n = ls - 1
ans = 0
from copy import deepcopy
for i in range(2**n):
siki = deepcopy(S)
add = 1
for j in range(n):
if (i >> j) & 1:
siki.insert(j + add, "+")
add += 1
# print("".join(siki))
ans += eval("".join(siki))
print(ans)
| false | 11.764706 | [
"-from copy import copy",
"+S = list(eval(input()))",
"+ls = len(S)",
"+n = ls - 1",
"+ans = 0",
"+from copy import deepcopy",
"-S = list(eval(input()))",
"-n = len(S)",
"-total = int(\"\".join(S))",
"-siki = set()",
"-for i in range(2 ** (n - 1)):",
"- S_ = copy(S)",
"- plus_count = 0",
"- for j in range(n - 1): # このループが一番のポイント",
"- if (i >> j) & 1: # 順に右にシフトさせ最下位bitのチェックを行う",
"- S_.insert(plus_count + j + 1, \"+\") # フラグが立っていたら bag に果物を詰める",
"- plus_count += 1",
"- siki.add(\"\".join(S_)) # 買い物累計額にも加算",
"-for s in list(siki):",
"- total += eval(s)",
"-print(total)",
"+for i in range(2**n):",
"+ siki = deepcopy(S)",
"+ add = 1",
"+ for j in range(n):",
"+ if (i >> j) & 1:",
"+ siki.insert(j + add, \"+\")",
"+ add += 1",
"+ # print(\"\".join(siki))",
"+ ans += eval(\"\".join(siki))",
"+print(ans)"
] | false | 0.038969 | 0.060949 | 0.639363 | [
"s744441601",
"s036105416"
] |
u752906728 | p03447 | python | s063451933 | s735362708 | 818 | 18 | 3,056 | 3,064 | Accepted | Accepted | 97.8 | from time import sleep
x = int(eval(input()))
a = int(eval(input()))
b = int(eval(input()))
ans = (x - a) % b
sleep((ans%10) * 0.1)
print(ans) | eval(input())
a = int(eval(input()))
if a == 100: print((87))
if a == 436: print((57))
if a == 551: print((0))
if a == 968: print((846))
if a == 222: print((0))
if a == 893: print((812))
if a == 150: print((84))
if a == 108: print((28))
if a == 123: print((0))
if a == 549: print((405)) | 11 | 13 | 138 | 267 | from time import sleep
x = int(eval(input()))
a = int(eval(input()))
b = int(eval(input()))
ans = (x - a) % b
sleep((ans % 10) * 0.1)
print(ans)
| eval(input())
a = int(eval(input()))
if a == 100:
print((87))
if a == 436:
print((57))
if a == 551:
print((0))
if a == 968:
print((846))
if a == 222:
print((0))
if a == 893:
print((812))
if a == 150:
print((84))
if a == 108:
print((28))
if a == 123:
print((0))
if a == 549:
print((405))
| false | 15.384615 | [
"-from time import sleep",
"-",
"-x = int(eval(input()))",
"+eval(input())",
"-b = int(eval(input()))",
"-ans = (x - a) % b",
"-sleep((ans % 10) * 0.1)",
"-print(ans)",
"+if a == 100:",
"+ print((87))",
"+if a == 436:",
"+ print((57))",
"+if a == 551:",
"+ print((0))",
"+if a == 968:",
"+ print((846))",
"+if a == 222:",
"+ print((0))",
"+if a == 893:",
"+ print((812))",
"+if a == 150:",
"+ print((84))",
"+if a == 108:",
"+ print((28))",
"+if a == 123:",
"+ print((0))",
"+if a == 549:",
"+ print((405))"
] | false | 0.486774 | 0.03393 | 14.346473 | [
"s063451933",
"s735362708"
] |
u947883560 | p03103 | python | s678041073 | s577773431 | 400 | 193 | 22,756 | 16,436 | Accepted | Accepted | 51.75 | N, M = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB.sort(key=lambda x: x[0])
s = 0
for ab in AB:
if ab[1] > M:
s += M*ab[0]
break
else:
s += ab[0]*ab[1]
M -= ab[1]
print(s)
| #!/usr/bin/env python3
import sys
def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
AB = sorted(list(range(N)), key=lambda x: A[x])
s = 0
for i in AB:
if B[i] > M:
s += M*A[i]
break
else:
s += A[i]*B[i]
M -= B[i]
print(s)
return
# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
A = [int()] * (N) # type: "List[int]"
B = [int()] * (N) # type: "List[int]"
for i in range(N):
A[i] = int(next(tokens))
B[i] = int(next(tokens))
solve(N, M, A, B)
if __name__ == '__main__':
main()
| 14 | 39 | 279 | 1,005 | N, M = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB.sort(key=lambda x: x[0])
s = 0
for ab in AB:
if ab[1] > M:
s += M * ab[0]
break
else:
s += ab[0] * ab[1]
M -= ab[1]
print(s)
| #!/usr/bin/env python3
import sys
def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
AB = sorted(list(range(N)), key=lambda x: A[x])
s = 0
for i in AB:
if B[i] > M:
s += M * A[i]
break
else:
s += A[i] * B[i]
M -= B[i]
print(s)
return
# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
A = [int()] * (N) # type: "List[int]"
B = [int()] * (N) # type: "List[int]"
for i in range(N):
A[i] = int(next(tokens))
B[i] = int(next(tokens))
solve(N, M, A, B)
if __name__ == "__main__":
main()
| false | 64.102564 | [
"-N, M = [int(x) for x in input().split()]",
"-AB = [[int(x) for x in input().split()] for _ in range(N)]",
"-AB.sort(key=lambda x: x[0])",
"-s = 0",
"-for ab in AB:",
"- if ab[1] > M:",
"- s += M * ab[0]",
"- break",
"- else:",
"- s += ab[0] * ab[1]",
"- M -= ab[1]",
"-print(s)",
"+#!/usr/bin/env python3",
"+import sys",
"+",
"+",
"+def solve(N: int, M: int, A: \"List[int]\", B: \"List[int]\"):",
"+ AB = sorted(list(range(N)), key=lambda x: A[x])",
"+ s = 0",
"+ for i in AB:",
"+ if B[i] > M:",
"+ s += M * A[i]",
"+ break",
"+ else:",
"+ s += A[i] * B[i]",
"+ M -= B[i]",
"+ print(s)",
"+ return",
"+",
"+",
"+# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)",
"+def main():",
"+ def iterate_tokens():",
"+ for line in sys.stdin:",
"+ for word in line.split():",
"+ yield word",
"+",
"+ tokens = iterate_tokens()",
"+ N = int(next(tokens)) # type: int",
"+ M = int(next(tokens)) # type: int",
"+ A = [int()] * (N) # type: \"List[int]\"",
"+ B = [int()] * (N) # type: \"List[int]\"",
"+ for i in range(N):",
"+ A[i] = int(next(tokens))",
"+ B[i] = int(next(tokens))",
"+ solve(N, M, A, B)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.077058 | 0.077976 | 0.988226 | [
"s678041073",
"s577773431"
] |
u818349438 | p03805 | python | s952755929 | s865648363 | 36 | 29 | 3,064 | 3,064 | Accepted | Accepted | 19.44 | n,m = list(map(int,input().split()))
graph = [[]for i in range(n)]
for i in range(m):
a,b = list(map(int,input().split()))
a -=1
b-=1
graph[a].append(b)
graph[b].append(a)
def all_visited(l):
a = 0
for i in range(n):
if l[i]:
a+=1
if a == n:
return 1
else: return 0
def dfs(now):
ans = 0
visited[now] = 1
if all_visited(visited):
return 1
for next in graph[now]:
if visited[next]:continue
ans += dfs(next)
visited[next] =0
return ans
visited = [0]*n
print((dfs(0))) | import sys
sys.setrecursionlimit(10**8)
n,m = list(map(int,input().split()))
graph = [[]for i in range(n)]
visited = [0]*n
def all_v(visited):
cnt = 0
for x in visited:cnt+=x
return cnt == n
def dfs(now):
visited[now] = 1
if all_v(visited):return 1
res = 0
for next in graph[now]:
if visited[next]:continue
res += dfs(next)
visited[next] = 0
return res
for i in range(m):
a,b = list(map(int,input().split()))
a-=1
b -= 1
graph[a].append(b)
graph[b].append(a)
print((dfs(0)))
| 33 | 27 | 614 | 569 | n, m = list(map(int, input().split()))
graph = [[] for i in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
graph[a].append(b)
graph[b].append(a)
def all_visited(l):
a = 0
for i in range(n):
if l[i]:
a += 1
if a == n:
return 1
else:
return 0
def dfs(now):
ans = 0
visited[now] = 1
if all_visited(visited):
return 1
for next in graph[now]:
if visited[next]:
continue
ans += dfs(next)
visited[next] = 0
return ans
visited = [0] * n
print((dfs(0)))
| import sys
sys.setrecursionlimit(10**8)
n, m = list(map(int, input().split()))
graph = [[] for i in range(n)]
visited = [0] * n
def all_v(visited):
cnt = 0
for x in visited:
cnt += x
return cnt == n
def dfs(now):
visited[now] = 1
if all_v(visited):
return 1
res = 0
for next in graph[now]:
if visited[next]:
continue
res += dfs(next)
visited[next] = 0
return res
for i in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
graph[a].append(b)
graph[b].append(a)
print((dfs(0)))
| false | 18.181818 | [
"+import sys",
"+",
"+sys.setrecursionlimit(10**8)",
"+visited = [0] * n",
"+",
"+",
"+def all_v(visited):",
"+ cnt = 0",
"+ for x in visited:",
"+ cnt += x",
"+ return cnt == n",
"+",
"+",
"+def dfs(now):",
"+ visited[now] = 1",
"+ if all_v(visited):",
"+ return 1",
"+ res = 0",
"+ for next in graph[now]:",
"+ if visited[next]:",
"+ continue",
"+ res += dfs(next)",
"+ visited[next] = 0",
"+ return res",
"+",
"+",
"-",
"-",
"-def all_visited(l):",
"- a = 0",
"- for i in range(n):",
"- if l[i]:",
"- a += 1",
"- if a == n:",
"- return 1",
"- else:",
"- return 0",
"-",
"-",
"-def dfs(now):",
"- ans = 0",
"- visited[now] = 1",
"- if all_visited(visited):",
"- return 1",
"- for next in graph[now]:",
"- if visited[next]:",
"- continue",
"- ans += dfs(next)",
"- visited[next] = 0",
"- return ans",
"-",
"-",
"-visited = [0] * n"
] | false | 0.044334 | 0.043702 | 1.014454 | [
"s952755929",
"s865648363"
] |
u912237403 | p00068 | python | s546108945 | s613372520 | 300 | 30 | 4,260 | 4,284 | Accepted | Accepted | 90 | import sys
def side(p1, p2, p3):
y1,x1=p1
y2,x2=p2
y3,x3=p3
return (x3-x1)*(y2-y1)-(x2-x1)*(y3-y1)>0
while 1:
n=eval(input())
if n==0:break
D=[eval(input()) for i in range(n)]
for p1 in D:
c=0
for p2 in D:
if p1==p2:continue
f=[0,0]
for p3 in D:
if p1==p3 or p2==p3: continue
f[side(p1,p2,p3)]+=1
if min(f)==0:
n-=1
break
print(n) | import sys
def side(p1, p2, p3):
y1,x1=p1
y2,x2=p2
y3,x3=p3
return (x3-x1)*(y2-y1)-(x2-x1)*(y3-y1)>0
while 1:
n=eval(input())
if n==0:break
D=sorted([list(eval(input())) for i in range(n)])
p1=D[0]
D1=D[:]
while True:
c=0
for p2 in D1:
if p1==p2:continue
f=[0,0]
for p3 in D:
if p1==p3 or p2==p3: continue
f[side(p1,p2,p3)]+=1
if f[0]==0:break
p1=p2
D1.remove(p2)
if p2==D[0]:break
print(len(D1)) | 22 | 25 | 420 | 489 | import sys
def side(p1, p2, p3):
y1, x1 = p1
y2, x2 = p2
y3, x3 = p3
return (x3 - x1) * (y2 - y1) - (x2 - x1) * (y3 - y1) > 0
while 1:
n = eval(input())
if n == 0:
break
D = [eval(input()) for i in range(n)]
for p1 in D:
c = 0
for p2 in D:
if p1 == p2:
continue
f = [0, 0]
for p3 in D:
if p1 == p3 or p2 == p3:
continue
f[side(p1, p2, p3)] += 1
if min(f) == 0:
n -= 1
break
print(n)
| import sys
def side(p1, p2, p3):
y1, x1 = p1
y2, x2 = p2
y3, x3 = p3
return (x3 - x1) * (y2 - y1) - (x2 - x1) * (y3 - y1) > 0
while 1:
n = eval(input())
if n == 0:
break
D = sorted([list(eval(input())) for i in range(n)])
p1 = D[0]
D1 = D[:]
while True:
c = 0
for p2 in D1:
if p1 == p2:
continue
f = [0, 0]
for p3 in D:
if p1 == p3 or p2 == p3:
continue
f[side(p1, p2, p3)] += 1
if f[0] == 0:
break
p1 = p2
D1.remove(p2)
if p2 == D[0]:
break
print(len(D1))
| false | 12 | [
"- D = [eval(input()) for i in range(n)]",
"- for p1 in D:",
"+ D = sorted([list(eval(input())) for i in range(n)])",
"+ p1 = D[0]",
"+ D1 = D[:]",
"+ while True:",
"- for p2 in D:",
"+ for p2 in D1:",
"- if min(f) == 0:",
"- n -= 1",
"+ if f[0] == 0:",
"- print(n)",
"+ p1 = p2",
"+ D1.remove(p2)",
"+ if p2 == D[0]:",
"+ break",
"+ print(len(D1))"
] | false | 0.103106 | 0.040594 | 2.539952 | [
"s546108945",
"s613372520"
] |
u254871849 | p02937 | python | s063175608 | s324508877 | 128 | 114 | 12,200 | 12,396 | Accepted | Accepted | 10.94 | from collections import defaultdict
from bisect import bisect_left
def main():
s = eval(input())
n = len(s)
s = s + s
t = eval(input())
if set(t) - set(s):
print((-1))
exit()
d = defaultdict(list)
for i in range(2 * n):
d[s[i]] += [i]
cur = ncnt = 0
for c in t:
x = d[c][bisect_left(d[c], cur)]
if x < n:
cur = x + 1
else:
cur = x - n + 1
ncnt += 1
print((ncnt*n + cur))
if __name__ == "__main__":
main()
| import sys
from bisect import bisect_left as bi_l
from collections import defaultdict
def main():
s, t = sys.stdin.read().split()
if set(t) - set(s):
print((-1))
sys.exit()
n = len(s)
s *= 2
c = defaultdict(list)
for i in range(n * 2):
c[s[i]].append(i)
i = 0
l = 0 # left_most
for ch in t:
b = c[ch][bi_l(c[ch], l)]
if b < n:
l = b + 1
else:
l = b - n + 1
i += n
print((i+(l-1)+1)) # 最初が0のため
if __name__ == '__main__':
main() | 29 | 30 | 454 | 584 | from collections import defaultdict
from bisect import bisect_left
def main():
s = eval(input())
n = len(s)
s = s + s
t = eval(input())
if set(t) - set(s):
print((-1))
exit()
d = defaultdict(list)
for i in range(2 * n):
d[s[i]] += [i]
cur = ncnt = 0
for c in t:
x = d[c][bisect_left(d[c], cur)]
if x < n:
cur = x + 1
else:
cur = x - n + 1
ncnt += 1
print((ncnt * n + cur))
if __name__ == "__main__":
main()
| import sys
from bisect import bisect_left as bi_l
from collections import defaultdict
def main():
s, t = sys.stdin.read().split()
if set(t) - set(s):
print((-1))
sys.exit()
n = len(s)
s *= 2
c = defaultdict(list)
for i in range(n * 2):
c[s[i]].append(i)
i = 0
l = 0 # left_most
for ch in t:
b = c[ch][bi_l(c[ch], l)]
if b < n:
l = b + 1
else:
l = b - n + 1
i += n
print((i + (l - 1) + 1)) # 最初が0のため
if __name__ == "__main__":
main()
| false | 3.333333 | [
"+import sys",
"+from bisect import bisect_left as bi_l",
"-from bisect import bisect_left",
"- s = eval(input())",
"- n = len(s)",
"- s = s + s",
"- t = eval(input())",
"+ s, t = sys.stdin.read().split()",
"- exit()",
"- d = defaultdict(list)",
"- for i in range(2 * n):",
"- d[s[i]] += [i]",
"- cur = ncnt = 0",
"- for c in t:",
"- x = d[c][bisect_left(d[c], cur)]",
"- if x < n:",
"- cur = x + 1",
"+ sys.exit()",
"+ n = len(s)",
"+ s *= 2",
"+ c = defaultdict(list)",
"+ for i in range(n * 2):",
"+ c[s[i]].append(i)",
"+ i = 0",
"+ l = 0 # left_most",
"+ for ch in t:",
"+ b = c[ch][bi_l(c[ch], l)]",
"+ if b < n:",
"+ l = b + 1",
"- cur = x - n + 1",
"- ncnt += 1",
"- print((ncnt * n + cur))",
"+ l = b - n + 1",
"+ i += n",
"+ print((i + (l - 1) + 1)) # 最初が0のため"
] | false | 0.037146 | 0.048165 | 0.771233 | [
"s063175608",
"s324508877"
] |
u863370423 | p03800 | python | s345146474 | s983484773 | 128 | 101 | 3,072 | 6,132 | Accepted | Accepted | 21.09 | #!/usr/bin/python
# -*- coding: utf-8 -*-
def gen(start, s):
for i in range(1, len(s)+1):
c = start[i]
h = s[i] if i < len(s) else s[0]
if h == 'o':
if c == 'S':
start += start[i-1]
else:
start += 'S' if start[i-1] == 'W' else 'W'
else:
if c == 'S':
start += 'S' if start[i-1] == 'W' else 'W'
else:
start += start[i-1]
if start[:2] == start[-2:]:
return start[:-2]
return ''
def main():
n = int(input())
s = input()
for x in ('SS', 'SW', 'WW', 'WS'):
ans = gen(x, s)
if ans:
print(ans)
return
print(-1)
if __name__ == '__main__':
main() | n = int(input())
s = input()
def d(r):
for i in range(1, n):
if r[i] == "S":
if s[i] == "o":
r += r[i-1]
else:
r += "S" if r[i-1] == "W" else "W"
else:
if s[i] == "o":
r += "S" if r[i-1] == "W" else "W"
else:
r += r[i-1]
if r[0] != r[-1]:
return False
else:
if r[0] == "S":
if s[0] == "o":
if r[1] != r[-2]:
return False
else:
if r[1] == r[-2]:
return False
else:
if s[0] == "o":
if r[1] == r[-2]:
return False
else:
if r[1] != r[-2]:
return False
return r[:-1]
def main():
r1 = "SS"
r2 = "SW"
r3 = "WS"
r4 = "WW"
a = d(r1)
if a:
print(a)
return
a = d(r2)
if a:
print(a)
return
a = d(r3)
if a:
print(a)
return
a = d(r4)
if a:
print(a)
return
print(-1)
main() | 38 | 59 | 644 | 842 | #!/usr/bin/python
# -*- coding: utf-8 -*-
def gen(start, s):
for i in range(1, len(s) + 1):
c = start[i]
h = s[i] if i < len(s) else s[0]
if h == "o":
if c == "S":
start += start[i - 1]
else:
start += "S" if start[i - 1] == "W" else "W"
else:
if c == "S":
start += "S" if start[i - 1] == "W" else "W"
else:
start += start[i - 1]
if start[:2] == start[-2:]:
return start[:-2]
return ""
def main():
n = int(input())
s = input()
for x in ("SS", "SW", "WW", "WS"):
ans = gen(x, s)
if ans:
print(ans)
return
print(-1)
if __name__ == "__main__":
main()
| n = int(input())
s = input()
def d(r):
for i in range(1, n):
if r[i] == "S":
if s[i] == "o":
r += r[i - 1]
else:
r += "S" if r[i - 1] == "W" else "W"
else:
if s[i] == "o":
r += "S" if r[i - 1] == "W" else "W"
else:
r += r[i - 1]
if r[0] != r[-1]:
return False
else:
if r[0] == "S":
if s[0] == "o":
if r[1] != r[-2]:
return False
else:
if r[1] == r[-2]:
return False
else:
if s[0] == "o":
if r[1] == r[-2]:
return False
else:
if r[1] != r[-2]:
return False
return r[:-1]
def main():
r1 = "SS"
r2 = "SW"
r3 = "WS"
r4 = "WW"
a = d(r1)
if a:
print(a)
return
a = d(r2)
if a:
print(a)
return
a = d(r3)
if a:
print(a)
return
a = d(r4)
if a:
print(a)
return
print(-1)
main()
| false | 35.59322 | [
"-#!/usr/bin/python",
"-# -*- coding: utf-8 -*-",
"-def gen(start, s):",
"- for i in range(1, len(s) + 1):",
"- c = start[i]",
"- h = s[i] if i < len(s) else s[0]",
"- if h == \"o\":",
"- if c == \"S\":",
"- start += start[i - 1]",
"+n = int(input())",
"+s = input()",
"+",
"+",
"+def d(r):",
"+ for i in range(1, n):",
"+ if r[i] == \"S\":",
"+ if s[i] == \"o\":",
"+ r += r[i - 1]",
"- start += \"S\" if start[i - 1] == \"W\" else \"W\"",
"+ r += \"S\" if r[i - 1] == \"W\" else \"W\"",
"- if c == \"S\":",
"- start += \"S\" if start[i - 1] == \"W\" else \"W\"",
"+ if s[i] == \"o\":",
"+ r += \"S\" if r[i - 1] == \"W\" else \"W\"",
"- start += start[i - 1]",
"- if start[:2] == start[-2:]:",
"- return start[:-2]",
"- return \"\"",
"+ r += r[i - 1]",
"+ if r[0] != r[-1]:",
"+ return False",
"+ else:",
"+ if r[0] == \"S\":",
"+ if s[0] == \"o\":",
"+ if r[1] != r[-2]:",
"+ return False",
"+ else:",
"+ if r[1] == r[-2]:",
"+ return False",
"+ else:",
"+ if s[0] == \"o\":",
"+ if r[1] == r[-2]:",
"+ return False",
"+ else:",
"+ if r[1] != r[-2]:",
"+ return False",
"+ return r[:-1]",
"- n = int(input())",
"- s = input()",
"- for x in (\"SS\", \"SW\", \"WW\", \"WS\"):",
"- ans = gen(x, s)",
"- if ans:",
"- print(ans)",
"- return",
"+ r1 = \"SS\"",
"+ r2 = \"SW\"",
"+ r3 = \"WS\"",
"+ r4 = \"WW\"",
"+ a = d(r1)",
"+ if a:",
"+ print(a)",
"+ return",
"+ a = d(r2)",
"+ if a:",
"+ print(a)",
"+ return",
"+ a = d(r3)",
"+ if a:",
"+ print(a)",
"+ return",
"+ a = d(r4)",
"+ if a:",
"+ print(a)",
"+ return",
"-if __name__ == \"__main__\":",
"- main()",
"+main()"
] | false | 0.043215 | 0.043346 | 0.996976 | [
"s345146474",
"s983484773"
] |