user_id stringlengths 10 10 | problem_id stringlengths 6 6 | language stringclasses 1 value | submission_id_v0 stringlengths 10 10 | submission_id_v1 stringlengths 10 10 | cpu_time_v0 int64 10 38.3k | cpu_time_v1 int64 0 24.7k | memory_v0 int64 2.57k 1.02M | memory_v1 int64 2.57k 869k | status_v0 stringclasses 1 value | status_v1 stringclasses 1 value | improvement_frac float64 7.51 100 | input stringlengths 20 4.55k | target stringlengths 17 3.34k | code_v0_loc int64 1 148 | code_v1_loc int64 1 184 | code_v0_num_chars int64 13 4.55k | code_v1_num_chars int64 14 3.34k | code_v0_no_empty_lines stringlengths 21 6.88k | code_v1_no_empty_lines stringlengths 20 4.93k | code_same bool 1 class | relative_loc_diff_percent float64 0 79.8 | diff list | diff_only_import_comment bool 1 class | measured_runtime_v0 float64 0.01 4.45 | measured_runtime_v1 float64 0.01 4.31 | runtime_lift float64 0 359 | key list |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u600402037 | p03722 | python | s638795833 | s132353762 | 208 | 162 | 14,072 | 12,748 | Accepted | Accepted | 22.12 | # 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]))) | # 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, co):
INF = float('inf')
dist = [INF] * (N+1) # dist[0]は使わない
dist[start] = 0
que = [(0, start, co)] # queではscoreを先頭に
while que:
score, place, 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 and count < 2000: # 点数が良くなるなら、データを更新
dist[next_node] = score2
heappush(que, (score2, next_node, count+1))
return dist
d1 = np.array(dijkstra(1, 0))
print((-int(d1[N]))) | 35 | 35 | 1,055 | 1,114 | # 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])))
| # 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, co):
INF = float("inf")
dist = [INF] * (N + 1) # dist[0]は使わない
dist[start] = 0
que = [(0, start, co)] # queではscoreを先頭に
while que:
score, place, 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 and count < 2000: # 点数が良くなるなら、データを更新
dist[next_node] = score2
heappush(que, (score2, next_node, count + 1))
return dist
d1 = np.array(dijkstra(1, 0))
print((-int(d1[N])))
| false | 0 | [
"- graph[a].append((b, c))",
"+ graph[a].append((b, -c)) # ヒープ構造を使うため重みはマイナスの値",
"-def dijkstra(start, c):",
"+def dijkstra(start, co):",
"- dist = [-INF] * (N + 1) # dist[0]は使わない",
"+ dist = [INF] * (N + 1) # dist[0]は使わない",
"- que = [(start, 0, c)]",
"+ que = [(0, start, co)] # queではscoreを先頭に",
"- place, score, count = heappop(que) # placeは現在地",
"- if score < dist[place] or count > 2000: # 前来た時より点数が悪いか、無限ループしている場合continue",
"+ score, place, count = heappop(que) # placeは現在地",
"+ if score > dist[place] or count > 2000: # 前来た時より点数が悪いか、無限ループしている場合continue",
"- if dist[next_node] < score2: # 点数が良くなるなら、データを更新",
"+ if dist[next_node] > score2 and count < 2000: # 点数が良くなるなら、データを更新",
"- heappush(que, (next_node, score2, count + 1))",
"+ heappush(que, (score2, next_node, count + 1))",
"-print((int(d1[N])))",
"+print((-int(d1[N])))"
] | false | 0.195498 | 0.227203 | 0.860457 | [
"s638795833",
"s132353762"
] |
u968166680 | p02820 | python | s820909801 | s682320478 | 117 | 85 | 85,460 | 79,388 | Accepted | Accepted | 27.35 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, K = list(map(int, readline().split()))
R, S, P = list(map(int, readline().split()))
T = readline().strip()
T = [int(c) for c in T.translate(str.maketrans('rsp', '012'))]
H = [R, S, P]
dp = [[0] * 3 for _ in range(N + 1)]
for i in range(N):
com = T[i]
for h in range(3):
if i > K - 1:
dp[i + 1][h] = max(dp[i + 1 - K][(h + 1) % 3], dp[i + 1 - K][(h + 2) % 3])
if (h + 1) % 3 == com:
dp[i + 1][h] += H[h]
print((sum(max(p) for p in dp[-K:])))
return
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, K = list(map(int, readline().split()))
R, S, P = list(map(int, readline().split()))
T = readline().strip()
T = [int(c) for c in T.translate(str.maketrans('rsp', '012'))]
point = [R, S, P]
hand = [0] * N
ans = 0
for i, com in enumerate(T):
win = (com - 1) % 3
if i >= K and win == hand[i - K]:
hand[i] = -1
else:
hand[i] = win
ans += point[win]
print(ans)
return
if __name__ == '__main__':
main()
| 35 | 35 | 796 | 703 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, K = list(map(int, readline().split()))
R, S, P = list(map(int, readline().split()))
T = readline().strip()
T = [int(c) for c in T.translate(str.maketrans("rsp", "012"))]
H = [R, S, P]
dp = [[0] * 3 for _ in range(N + 1)]
for i in range(N):
com = T[i]
for h in range(3):
if i > K - 1:
dp[i + 1][h] = max(
dp[i + 1 - K][(h + 1) % 3], dp[i + 1 - K][(h + 2) % 3]
)
if (h + 1) % 3 == com:
dp[i + 1][h] += H[h]
print((sum(max(p) for p in dp[-K:])))
return
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, K = list(map(int, readline().split()))
R, S, P = list(map(int, readline().split()))
T = readline().strip()
T = [int(c) for c in T.translate(str.maketrans("rsp", "012"))]
point = [R, S, P]
hand = [0] * N
ans = 0
for i, com in enumerate(T):
win = (com - 1) % 3
if i >= K and win == hand[i - K]:
hand[i] = -1
else:
hand[i] = win
ans += point[win]
print(ans)
return
if __name__ == "__main__":
main()
| false | 0 | [
"- H = [R, S, P]",
"- dp = [[0] * 3 for _ in range(N + 1)]",
"- for i in range(N):",
"- com = T[i]",
"- for h in range(3):",
"- if i > K - 1:",
"- dp[i + 1][h] = max(",
"- dp[i + 1 - K][(h + 1) % 3], dp[i + 1 - K][(h + 2) % 3]",
"- )",
"- if (h + 1) % 3 == com:",
"- dp[i + 1][h] += H[h]",
"- print((sum(max(p) for p in dp[-K:])))",
"+ point = [R, S, P]",
"+ hand = [0] * N",
"+ ans = 0",
"+ for i, com in enumerate(T):",
"+ win = (com - 1) % 3",
"+ if i >= K and win == hand[i - K]:",
"+ hand[i] = -1",
"+ else:",
"+ hand[i] = win",
"+ ans += point[win]",
"+ print(ans)"
] | false | 0.034861 | 0.042067 | 0.828705 | [
"s820909801",
"s682320478"
] |
u174766008 | p02783 | python | s340989857 | s148577594 | 20 | 18 | 2,940 | 2,940 | Accepted | Accepted | 10 | h,a = list(map(int, input().split()))
i = 0
while i < 10**4:
i += 1
h = h - a
if h <= 0:
print(i)
break | h, a = list(map(int,input().split()))
print((h//a + (h%a!=0))) | 8 | 2 | 133 | 56 | h, a = list(map(int, input().split()))
i = 0
while i < 10**4:
i += 1
h = h - a
if h <= 0:
print(i)
break
| h, a = list(map(int, input().split()))
print((h // a + (h % a != 0)))
| false | 75 | [
"-i = 0",
"-while i < 10**4:",
"- i += 1",
"- h = h - a",
"- if h <= 0:",
"- print(i)",
"- break",
"+print((h // a + (h % a != 0)))"
] | false | 0.04375 | 0.041187 | 1.06223 | [
"s340989857",
"s148577594"
] |
u584083761 | p03163 | python | s483536431 | s644975984 | 1,934 | 727 | 319,940 | 173,704 | Accepted | Accepted | 62.41 | n,w=list(map(int, input().split()))
wv=[list(map(int, input().split())) for _ in range(n)]
dp = [[-float("inf") for _ in range(w+1)] for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
for j in range(w+1):
if j >= wv[i][0]:
dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1])
else:
dp[i+1][j] = dp[i][j]
print((max(dp[-1])))
| n,w=list(map(int, input().split()))
wv=[list(map(int, input().split())) for _ in range(n)]
dp = [[0 for _ in range(w+1)] for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
for j in range(w+1):
if j >= wv[i][0]:
dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1])
else:
dp[i+1][j] = dp[i][j]
print((dp[-1][-1])) | 15 | 14 | 395 | 391 | n, w = list(map(int, input().split()))
wv = [list(map(int, input().split())) for _ in range(n)]
dp = [[-float("inf") for _ in range(w + 1)] for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(w + 1):
if j >= wv[i][0]:
dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1])
else:
dp[i + 1][j] = dp[i][j]
print((max(dp[-1])))
| n, w = list(map(int, input().split()))
wv = [list(map(int, input().split())) for _ in range(n)]
dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(w + 1):
if j >= wv[i][0]:
dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1])
else:
dp[i + 1][j] = dp[i][j]
print((dp[-1][-1]))
| false | 6.666667 | [
"-dp = [[-float(\"inf\") for _ in range(w + 1)] for _ in range(n + 1)]",
"+dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)]",
"-print((max(dp[-1])))",
"+print((dp[-1][-1]))"
] | false | 0.037718 | 0.037538 | 1.00479 | [
"s483536431",
"s644975984"
] |
u072717685 | p03448 | python | s578953670 | s880265177 | 43 | 24 | 3,700 | 3,700 | Accepted | Accepted | 44.19 | import sys
input = sys.stdin.readline
from math import factorial
from itertools import combinations
from collections import Counter
from copy import deepcopy
from operator import mul
from functools import reduce
def main():
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
r = 0
for ia in range(a + 1):
for ib in range(min(b + 1, (x - ia * 500)//100 + 1)):
for ic in range(min(c + 1, (x - ia * 500 - ib * 100)//50 + 1)):
r += ia * 500 + ib * 100 + ic * 50 == x
print(r)
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
from math import factorial
from itertools import combinations
from collections import Counter
from copy import deepcopy
from operator import mul
from functools import reduce
def main():
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
r = 0
for ia in range(a + 1):
for ib in range(min(b + 1, (x - ia * 500)//100 + 1)):
r += (x - ia * 500 - ib * 100) // 50 <= c
print(r)
if __name__ == '__main__':
main()
| 26 | 24 | 622 | 541 | import sys
input = sys.stdin.readline
from math import factorial
from itertools import combinations
from collections import Counter
from copy import deepcopy
from operator import mul
from functools import reduce
def main():
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
r = 0
for ia in range(a + 1):
for ib in range(min(b + 1, (x - ia * 500) // 100 + 1)):
for ic in range(min(c + 1, (x - ia * 500 - ib * 100) // 50 + 1)):
r += ia * 500 + ib * 100 + ic * 50 == x
print(r)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
from math import factorial
from itertools import combinations
from collections import Counter
from copy import deepcopy
from operator import mul
from functools import reduce
def main():
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
x = int(eval(input()))
r = 0
for ia in range(a + 1):
for ib in range(min(b + 1, (x - ia * 500) // 100 + 1)):
r += (x - ia * 500 - ib * 100) // 50 <= c
print(r)
if __name__ == "__main__":
main()
| false | 7.692308 | [
"- for ic in range(min(c + 1, (x - ia * 500 - ib * 100) // 50 + 1)):",
"- r += ia * 500 + ib * 100 + ic * 50 == x",
"+ r += (x - ia * 500 - ib * 100) // 50 <= c"
] | false | 0.038265 | 0.063413 | 0.603424 | [
"s578953670",
"s880265177"
] |
u094191970 | p03037 | python | s398490819 | s748459943 | 369 | 339 | 27,332 | 27,336 | Accepted | Accepted | 8.13 | n,m=list(map(int,input().split()))
ll=[list(map(int,input().split())) for i in range(m)]
a=0
b=n
for l,r in ll:
a=max(a,l)
b=min(b,r)
print((max(b-a+1,0))) | n,m=list(map(int,input().split()))
ll=[list(map(int,input().split())) for i in range(m)]
a=0
b=n
for l,r in ll:
if a<l:
a=l
if r<b:
b=r
print((max(b-a+1,0))) | 9 | 11 | 158 | 166 | n, m = list(map(int, input().split()))
ll = [list(map(int, input().split())) for i in range(m)]
a = 0
b = n
for l, r in ll:
a = max(a, l)
b = min(b, r)
print((max(b - a + 1, 0)))
| n, m = list(map(int, input().split()))
ll = [list(map(int, input().split())) for i in range(m)]
a = 0
b = n
for l, r in ll:
if a < l:
a = l
if r < b:
b = r
print((max(b - a + 1, 0)))
| false | 18.181818 | [
"- a = max(a, l)",
"- b = min(b, r)",
"+ if a < l:",
"+ a = l",
"+ if r < b:",
"+ b = r"
] | false | 0.047904 | 0.036608 | 1.308547 | [
"s398490819",
"s748459943"
] |
u225388820 | p02588 | python | s230230903 | s599946314 | 617 | 463 | 94,348 | 102,492 | Accepted | Accepted | 24.96 | class BIT:
def __init__(self, n):
#A1 ... AnのBIT(1-indexed)
self.BIT = [0] * (n + 1)
self.n = n
#A1 ~ Aiまでの和 O(logN)
def query(self, idx):
res_sum = 0
while idx > 0:
res_sum += self.BIT[idx]
idx -= idx & (-idx)
return res_sum
#Ai += x O(logN)
def add(self, idx, x):
while idx <= self.n:
self.BIT[idx] += x
idx += idx&(-idx)
return
def get_int(f):
if "." not in f:
return int(f),0
return int(f.replace(".","")),len(f)-f.index(".")-1
n = int(eval(input()))
p = []
for i in range(n):
a, b = get_int(eval(input()))
c, d = 0, 0
while a % 2 == 0:
c += 1
a //= 2
while a % 5 == 0:
d += 1
a //= 5
c -= b
d -= b
p.append((c, d))
p.sort()
now = n - 1
t = BIT(50)
ans = 0
for i in range(n):
for j in range(now, i, -1):
if p[i][0] + p[j][0] >= 0:
t.add(-p[j][1] + 25, 1)
now -= 1
else:
break
if now < i:
t.add(-p[i][1] + 25, -1)
ans += max(0, t.query(25 + p[i][1]))
print(ans) | class BIT:
def __init__(self, n):
#A1 ... AnのBIT(1-indexed)
self.BIT = [0] * (n + 1)
self.n = n
#A1 ~ Aiまでの和 O(logN)
def query(self, idx):
res_sum = 0
while idx > 0:
res_sum += self.BIT[idx]
idx -= idx & (-idx)
return res_sum
#Ai += x O(logN)
def add(self, idx, x):
while idx <= self.n:
self.BIT[idx] += x
idx += idx&(-idx)
return
def get_int(f):
if "." not in f:
return int(f),0
return int(f.replace(".","")),len(f)-f.index(".")-1
n = int(eval(input()))
p = []
for i in range(n):
a, b = get_int(eval(input()))
c, d = 0, 0
while a % 2 == 0:
c += 1
a //= 2
while a % 5 == 0:
d += 1
a //= 5
c -= b
d -= b
p.append((c, d))
p.sort(key=lambda x:x[0])
now = n - 1
t = BIT(50)
ans = 0
for i in range(n):
for j in range(now, i, -1):
if p[i][0] + p[j][0] >= 0:
t.add(-p[j][1] + 25, 1)
now -= 1
else:
break
if now < i:
t.add(-p[i][1] + 25, -1)
ans += max(0, t.query(25 + p[i][1]))
print(ans) | 54 | 54 | 1,188 | 1,205 | class BIT:
def __init__(self, n):
# A1 ... AnのBIT(1-indexed)
self.BIT = [0] * (n + 1)
self.n = n
# A1 ~ Aiまでの和 O(logN)
def query(self, idx):
res_sum = 0
while idx > 0:
res_sum += self.BIT[idx]
idx -= idx & (-idx)
return res_sum
# Ai += x O(logN)
def add(self, idx, x):
while idx <= self.n:
self.BIT[idx] += x
idx += idx & (-idx)
return
def get_int(f):
if "." not in f:
return int(f), 0
return int(f.replace(".", "")), len(f) - f.index(".") - 1
n = int(eval(input()))
p = []
for i in range(n):
a, b = get_int(eval(input()))
c, d = 0, 0
while a % 2 == 0:
c += 1
a //= 2
while a % 5 == 0:
d += 1
a //= 5
c -= b
d -= b
p.append((c, d))
p.sort()
now = n - 1
t = BIT(50)
ans = 0
for i in range(n):
for j in range(now, i, -1):
if p[i][0] + p[j][0] >= 0:
t.add(-p[j][1] + 25, 1)
now -= 1
else:
break
if now < i:
t.add(-p[i][1] + 25, -1)
ans += max(0, t.query(25 + p[i][1]))
print(ans)
| class BIT:
def __init__(self, n):
# A1 ... AnのBIT(1-indexed)
self.BIT = [0] * (n + 1)
self.n = n
# A1 ~ Aiまでの和 O(logN)
def query(self, idx):
res_sum = 0
while idx > 0:
res_sum += self.BIT[idx]
idx -= idx & (-idx)
return res_sum
# Ai += x O(logN)
def add(self, idx, x):
while idx <= self.n:
self.BIT[idx] += x
idx += idx & (-idx)
return
def get_int(f):
if "." not in f:
return int(f), 0
return int(f.replace(".", "")), len(f) - f.index(".") - 1
n = int(eval(input()))
p = []
for i in range(n):
a, b = get_int(eval(input()))
c, d = 0, 0
while a % 2 == 0:
c += 1
a //= 2
while a % 5 == 0:
d += 1
a //= 5
c -= b
d -= b
p.append((c, d))
p.sort(key=lambda x: x[0])
now = n - 1
t = BIT(50)
ans = 0
for i in range(n):
for j in range(now, i, -1):
if p[i][0] + p[j][0] >= 0:
t.add(-p[j][1] + 25, 1)
now -= 1
else:
break
if now < i:
t.add(-p[i][1] + 25, -1)
ans += max(0, t.query(25 + p[i][1]))
print(ans)
| false | 0 | [
"-p.sort()",
"+p.sort(key=lambda x: x[0])"
] | false | 0.041517 | 0.042482 | 0.977288 | [
"s230230903",
"s599946314"
] |
u644907318 | p03127 | python | s386344615 | s982185447 | 231 | 98 | 62,704 | 85,440 | Accepted | Accepted | 57.58 | def gcd(x,y):
while y>0:
x,y = y,x%y
return x
N = int(eval(input()))
A = list(map(int,input().split()))
a = A[0]
for i in range(1,N):
a = gcd(a,A[i])
print(a) | def gcd(x,y):
while y>0:
x,y = y,x%y
return x
N = int(eval(input()))
A = list(map(int,input().split()))
x = A[0]
for i in range(1,N):
x = gcd(x,A[i])
print(x) | 10 | 10 | 181 | 181 | def gcd(x, y):
while y > 0:
x, y = y, x % y
return x
N = int(eval(input()))
A = list(map(int, input().split()))
a = A[0]
for i in range(1, N):
a = gcd(a, A[i])
print(a)
| def gcd(x, y):
while y > 0:
x, y = y, x % y
return x
N = int(eval(input()))
A = list(map(int, input().split()))
x = A[0]
for i in range(1, N):
x = gcd(x, A[i])
print(x)
| false | 0 | [
"-a = A[0]",
"+x = A[0]",
"- a = gcd(a, A[i])",
"-print(a)",
"+ x = gcd(x, A[i])",
"+print(x)"
] | false | 0.046551 | 0.038171 | 1.21954 | [
"s386344615",
"s982185447"
] |
u002459665 | p02773 | python | s627104171 | s834580552 | 1,395 | 1,060 | 55,576 | 55,608 | Accepted | Accepted | 24.01 | N = int(eval(input()))
S = []
for i in range(N):
s = eval(input())
S.append(s)
from collections import Counter
c = Counter()
for si in S:
c[si] += 1
a = []
for k, v in list(c.items()):
a.append([v, k])
from operator import itemgetter
a.sort(key=itemgetter(1))
a.sort(key=itemgetter(0), reverse=True)
for ai in a:
if ai[0] == a[0][0]:
print((ai[1])) | N = int(eval(input()))
S = []
for i in range(N):
s = eval(input())
S.append(s)
from collections import Counter
c = Counter()
for si in S:
c[si] += 1
ca = []
for name, cnt in list(c.items()):
ca.append([name, cnt])
ca.sort(key=lambda x:x[0])
ca.sort(key=lambda x:x[1], reverse=True)
max_c = ca[0][1]
for name, cnt in ca:
if cnt == max_c:
print(name)
| 25 | 23 | 387 | 386 | N = int(eval(input()))
S = []
for i in range(N):
s = eval(input())
S.append(s)
from collections import Counter
c = Counter()
for si in S:
c[si] += 1
a = []
for k, v in list(c.items()):
a.append([v, k])
from operator import itemgetter
a.sort(key=itemgetter(1))
a.sort(key=itemgetter(0), reverse=True)
for ai in a:
if ai[0] == a[0][0]:
print((ai[1]))
| N = int(eval(input()))
S = []
for i in range(N):
s = eval(input())
S.append(s)
from collections import Counter
c = Counter()
for si in S:
c[si] += 1
ca = []
for name, cnt in list(c.items()):
ca.append([name, cnt])
ca.sort(key=lambda x: x[0])
ca.sort(key=lambda x: x[1], reverse=True)
max_c = ca[0][1]
for name, cnt in ca:
if cnt == max_c:
print(name)
| false | 8 | [
"-a = []",
"-for k, v in list(c.items()):",
"- a.append([v, k])",
"-from operator import itemgetter",
"-",
"-a.sort(key=itemgetter(1))",
"-a.sort(key=itemgetter(0), reverse=True)",
"-for ai in a:",
"- if ai[0] == a[0][0]:",
"- print((ai[1]))",
"+ca = []",
"+for name, cnt in list(c.items()):",
"+ ca.append([name, cnt])",
"+ca.sort(key=lambda x: x[0])",
"+ca.sort(key=lambda x: x[1], reverse=True)",
"+max_c = ca[0][1]",
"+for name, cnt in ca:",
"+ if cnt == max_c:",
"+ print(name)"
] | false | 0.040616 | 0.039982 | 1.015869 | [
"s627104171",
"s834580552"
] |
u873904588 | p02882 | python | s536056619 | s168910261 | 44 | 30 | 5,696 | 9,380 | Accepted | Accepted | 31.82 | import sys
from io import StringIO
import unittest
import math
def resolve():
a, b, x = list(map(int, input().split()))
tan_theta = 2*(b/a-x/math.pow(a, 3))
tan_theta2 = a * pow(b, 2) / (2 * x)
if math.pow(a, 3) / 2 * tan_theta < x:
theta = math.atan(tan_theta)
else:
theta = math.atan(tan_theta2)
print((math.degrees(theta)))
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """2 2 4"""
output = """45.0000000000"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """12 21 10"""
output = """89.7834636934"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """3 1 8"""
output = """4.2363947991"""
self.assertIO(input, output)
if __name__ == "__main__":
# unittest.main()
resolve()
| # https://atcoder.jp/contests/abc144/tasks/abc144_d
import math
a, b, x = list(map(int, input().split()))
if a * a * b * (1/2) <= x:
tmp = 2 * (a*a*b-x) / (a*a*a)
print((math.degrees(math.atan(tmp))))
else:
tmp = a*b*b / (2*x)
print((math.degrees(math.atan(tmp))))
| 49 | 10 | 1,215 | 287 | import sys
from io import StringIO
import unittest
import math
def resolve():
a, b, x = list(map(int, input().split()))
tan_theta = 2 * (b / a - x / math.pow(a, 3))
tan_theta2 = a * pow(b, 2) / (2 * x)
if math.pow(a, 3) / 2 * tan_theta < x:
theta = math.atan(tan_theta)
else:
theta = math.atan(tan_theta2)
print((math.degrees(theta)))
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """2 2 4"""
output = """45.0000000000"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """12 21 10"""
output = """89.7834636934"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """3 1 8"""
output = """4.2363947991"""
self.assertIO(input, output)
if __name__ == "__main__":
# unittest.main()
resolve()
| # https://atcoder.jp/contests/abc144/tasks/abc144_d
import math
a, b, x = list(map(int, input().split()))
if a * a * b * (1 / 2) <= x:
tmp = 2 * (a * a * b - x) / (a * a * a)
print((math.degrees(math.atan(tmp))))
else:
tmp = a * b * b / (2 * x)
print((math.degrees(math.atan(tmp))))
| false | 79.591837 | [
"-import sys",
"-from io import StringIO",
"-import unittest",
"+# https://atcoder.jp/contests/abc144/tasks/abc144_d",
"-",
"-def resolve():",
"- a, b, x = list(map(int, input().split()))",
"- tan_theta = 2 * (b / a - x / math.pow(a, 3))",
"- tan_theta2 = a * pow(b, 2) / (2 * x)",
"- if math.pow(a, 3) / 2 * tan_theta < x:",
"- theta = math.atan(tan_theta)",
"- else:",
"- theta = math.atan(tan_theta2)",
"- print((math.degrees(theta)))",
"-",
"-",
"-class TestClass(unittest.TestCase):",
"- def assertIO(self, input, output):",
"- stdout, stdin = sys.stdout, sys.stdin",
"- sys.stdout, sys.stdin = StringIO(), StringIO(input)",
"- resolve()",
"- sys.stdout.seek(0)",
"- out = sys.stdout.read()[:-1]",
"- sys.stdout, sys.stdin = stdout, stdin",
"- self.assertEqual(out, output)",
"-",
"- def test_入力例_1(self):",
"- input = \"\"\"2 2 4\"\"\"",
"- output = \"\"\"45.0000000000\"\"\"",
"- self.assertIO(input, output)",
"-",
"- def test_入力例_2(self):",
"- input = \"\"\"12 21 10\"\"\"",
"- output = \"\"\"89.7834636934\"\"\"",
"- self.assertIO(input, output)",
"-",
"- def test_入力例_3(self):",
"- input = \"\"\"3 1 8\"\"\"",
"- output = \"\"\"4.2363947991\"\"\"",
"- self.assertIO(input, output)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- # unittest.main()",
"- resolve()",
"+a, b, x = list(map(int, input().split()))",
"+if a * a * b * (1 / 2) <= x:",
"+ tmp = 2 * (a * a * b - x) / (a * a * a)",
"+ print((math.degrees(math.atan(tmp))))",
"+else:",
"+ tmp = a * b * b / (2 * x)",
"+ print((math.degrees(math.atan(tmp))))"
] | false | 0.119232 | 0.037252 | 3.200674 | [
"s536056619",
"s168910261"
] |
u554096168 | p02936 | python | s574368599 | s298616921 | 1,763 | 1,210 | 238,808 | 72,132 | Accepted | Accepted | 31.37 | import sys
sys.setrecursionlimit(5 * 10**5)
input=sys.stdin.readline
N, Q = list(map(int, input().split()))
M = [[] for _ in range(N)]
for _ in range(N-1):
a, b = list(map(int, input().split()))
M[a-1].append(b-1)
M[b-1].append(a-1)
ans = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
ans[p-1] += x
def setAnswer(parent, number):
ans[number] += ans[parent]
for i in M[number]:
if i != parent:
setAnswer(number, i)
for i in M[0]:
setAnswer(0, i)
print((' '.join(map(str, ans))))
| import sys
from collections import deque
sys.setrecursionlimit(5 * 10**5)
input=sys.stdin.readline
N, Q = list(map(int, input().split()))
M = [[] for _ in range(N)]
for _ in range(N-1):
a, b = list(map(int, input().split()))
M[a-1].append(b-1)
M[b-1].append(a-1)
ans = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
ans[p-1] += x
Q = deque([0])
while Q:
current = Q.popleft()
for i in M[current]:
ans[i] += ans[current]
M[i].remove(current)
Q.append(i)
print((' '.join(map(str, ans))))
| 28 | 30 | 589 | 592 | import sys
sys.setrecursionlimit(5 * 10**5)
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
M = [[] for _ in range(N)]
for _ in range(N - 1):
a, b = list(map(int, input().split()))
M[a - 1].append(b - 1)
M[b - 1].append(a - 1)
ans = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
ans[p - 1] += x
def setAnswer(parent, number):
ans[number] += ans[parent]
for i in M[number]:
if i != parent:
setAnswer(number, i)
for i in M[0]:
setAnswer(0, i)
print((" ".join(map(str, ans))))
| import sys
from collections import deque
sys.setrecursionlimit(5 * 10**5)
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
M = [[] for _ in range(N)]
for _ in range(N - 1):
a, b = list(map(int, input().split()))
M[a - 1].append(b - 1)
M[b - 1].append(a - 1)
ans = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
ans[p - 1] += x
Q = deque([0])
while Q:
current = Q.popleft()
for i in M[current]:
ans[i] += ans[current]
M[i].remove(current)
Q.append(i)
print((" ".join(map(str, ans))))
| false | 6.666667 | [
"+from collections import deque",
"-",
"-",
"-def setAnswer(parent, number):",
"- ans[number] += ans[parent]",
"- for i in M[number]:",
"- if i != parent:",
"- setAnswer(number, i)",
"-",
"-",
"-for i in M[0]:",
"- setAnswer(0, i)",
"+Q = deque([0])",
"+while Q:",
"+ current = Q.popleft()",
"+ for i in M[current]:",
"+ ans[i] += ans[current]",
"+ M[i].remove(current)",
"+ Q.append(i)"
] | false | 0.047961 | 0.006864 | 6.987029 | [
"s574368599",
"s298616921"
] |
u279493135 | p02735 | python | s277707865 | s841111382 | 343 | 60 | 63,980 | 5,444 | Accepted | Accepted | 82.51 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
def main():
H, W = MAP()
dx = [1, 0]
dy = [0, 1]
s = [eval(input()) for _ in range(H)]
start = (0, 0)
q = deque()
q.append(start)
cost = [[INF]*W for _ in range(H)]
if s[0][0] == "#":
cost[0][0] = 1
else:
cost[0][0] = 0
while q:
i, j = q.popleft()
for k in range(2):
y = i + dy[k]
x = j + dx[k]
if y < 0 or y > H-1 or x < 0 or x > W-1:
continue
if s[i][j] == "." and s[y][x] == "#": # コストが増える
if cost[y][x] > cost[i][j] + 1:
cost[y][x] = cost[i][j] + 1
q.append((y, x))
elif s[i][j] == "#" and s[y][x] == "#":
if cost[y][x] > cost[i][j]:
cost[y][x] = cost[i][j]
q.append((y, x))
elif s[i][j] == "." and s[y][x] == ".":
if cost[y][x] > cost[i][j]:
cost[y][x] = cost[i][j]
q.append((y, x))
else: # # -> .
if cost[y][x] > cost[i][j]:
cost[y][x] = cost[i][j]
q.append((y, x))
# print(cost)
print((cost[H-1][W-1]))
if __name__ == '__main__':
main()
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
def main():
H, W = MAP()
dx = [1, 0]
dy = [0, 1]
s = [eval(input()) for _ in range(H)]
start = (0, 0)
q = deque()
q.append(start)
cost = [[INF]*W for _ in range(H)]
if s[0][0] == "#":
cost[0][0] = 1
else:
cost[0][0] = 0
while q:
i, j = q.popleft()
for k in range(2):
y = i + dy[k]
x = j + dx[k]
if y < 0 or y > H-1 or x < 0 or x > W-1:
continue
if s[i][j] == "." and s[y][x] == "#": # コストが増える
if cost[y][x] > cost[i][j] + 1:
cost[y][x] = cost[i][j] + 1
q.append((y, x))
else:
if cost[y][x] > cost[i][j]:
cost[y][x] = cost[i][j]
q.append((y, x))
print((cost[H-1][W-1]))
if __name__ == '__main__':
main()
| 66 | 55 | 2,077 | 1,681 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
def main():
H, W = MAP()
dx = [1, 0]
dy = [0, 1]
s = [eval(input()) for _ in range(H)]
start = (0, 0)
q = deque()
q.append(start)
cost = [[INF] * W for _ in range(H)]
if s[0][0] == "#":
cost[0][0] = 1
else:
cost[0][0] = 0
while q:
i, j = q.popleft()
for k in range(2):
y = i + dy[k]
x = j + dx[k]
if y < 0 or y > H - 1 or x < 0 or x > W - 1:
continue
if s[i][j] == "." and s[y][x] == "#": # コストが増える
if cost[y][x] > cost[i][j] + 1:
cost[y][x] = cost[i][j] + 1
q.append((y, x))
elif s[i][j] == "#" and s[y][x] == "#":
if cost[y][x] > cost[i][j]:
cost[y][x] = cost[i][j]
q.append((y, x))
elif s[i][j] == "." and s[y][x] == ".":
if cost[y][x] > cost[i][j]:
cost[y][x] = cost[i][j]
q.append((y, x))
else: # # -> .
if cost[y][x] > cost[i][j]:
cost[y][x] = cost[i][j]
q.append((y, x))
# print(cost)
print((cost[H - 1][W - 1]))
if __name__ == "__main__":
main()
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
def main():
H, W = MAP()
dx = [1, 0]
dy = [0, 1]
s = [eval(input()) for _ in range(H)]
start = (0, 0)
q = deque()
q.append(start)
cost = [[INF] * W for _ in range(H)]
if s[0][0] == "#":
cost[0][0] = 1
else:
cost[0][0] = 0
while q:
i, j = q.popleft()
for k in range(2):
y = i + dy[k]
x = j + dx[k]
if y < 0 or y > H - 1 or x < 0 or x > W - 1:
continue
if s[i][j] == "." and s[y][x] == "#": # コストが増える
if cost[y][x] > cost[i][j] + 1:
cost[y][x] = cost[i][j] + 1
q.append((y, x))
else:
if cost[y][x] > cost[i][j]:
cost[y][x] = cost[i][j]
q.append((y, x))
print((cost[H - 1][W - 1]))
if __name__ == "__main__":
main()
| false | 16.666667 | [
"- elif s[i][j] == \"#\" and s[y][x] == \"#\":",
"+ else:",
"- elif s[i][j] == \".\" and s[y][x] == \".\":",
"- if cost[y][x] > cost[i][j]:",
"- cost[y][x] = cost[i][j]",
"- q.append((y, x))",
"- else: # # -> .",
"- if cost[y][x] > cost[i][j]:",
"- cost[y][x] = cost[i][j]",
"- q.append((y, x))",
"- # print(cost)"
] | false | 0.09286 | 0.058834 | 1.578349 | [
"s277707865",
"s841111382"
] |
u798803522 | p02368 | python | s995290020 | s461461949 | 2,230 | 1,050 | 22,132 | 21,992 | Accepted | Accepted | 52.91 | from collections import defaultdict
import sys
sys.setrecursionlimit(100000)
def counter():
cnt = 0
while True:
yield cnt
cnt += 1
def dfs(here, visited, track, count, connect):
visited |= {here}
for c in connect[here]:
if c not in visited:
dfs(c, visited, track, count, connect)
track[here] = next(count)
def kosaraju(here, visited, track, count, connect):
visited |= {here}
for c in connect[here]:
if c not in visited:
kosaraju(c, visited, track, count, connect)
track[here] = count
vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
reversed_connect = defaultdict(list)
for _ in range(edges):
v1, v2 = (int(n) for n in input().split(" "))
connect[v1].append(v2)
reversed_connect[v2].append(v1)
visited = set()
track_gen = counter()
track = [-1 for n in range(vertices)]
for v in range(vertices):
if v not in visited:
dfs(v, visited, track, track_gen, connect)
visited = set()
track_gen = counter()
strongly_con = [-1 for n in range(vertices)]
for v in range(vertices - 1 ,- 1, -1):
here = track.index(v)
if here not in visited:
num = next(track_gen)
kosaraju(here, visited, strongly_con, num, reversed_connect)
q_num = int(eval(input()))
for _ in range(q_num):
v1, v2 = (int(n) for n in input().split(" "))
if strongly_con[v1] == strongly_con[v2]:
print((1))
else:
print((0)) | from collections import defaultdict
import sys
sys.setrecursionlimit(100000)
def counter():
cnt = 0
while True:
yield cnt
cnt += 1
def dfs(here, visited, track, count, connect):
visited |= {here}
for c in connect[here]:
if c not in visited:
dfs(c, visited, track, count, connect)
track.append(here)
def kosaraju(here, visited, track, count, connect):
visited |= {here}
for c in connect[here]:
if c not in visited:
kosaraju(c, visited, track, count, connect)
track[here] = count
vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
reversed_connect = defaultdict(list)
for _ in range(edges):
v1, v2 = (int(n) for n in input().split(" "))
connect[v1].append(v2)
reversed_connect[v2].append(v1)
visited = set()
track_gen = counter()
track = []
for v in range(vertices):
if v not in visited:
dfs(v, visited, track, track_gen, connect)
visited = set()
track_gen = counter()
strongly_con = [-1 for n in range(vertices)]
for here in track[::-1]:
if here not in visited:
num = next(track_gen)
kosaraju(here, visited, strongly_con, num, reversed_connect)
q_num = int(eval(input()))
for _ in range(q_num):
v1, v2 = (int(n) for n in input().split(" "))
if strongly_con[v1] == strongly_con[v2]:
print((1))
else:
print((0)) | 55 | 54 | 1,525 | 1,450 | from collections import defaultdict
import sys
sys.setrecursionlimit(100000)
def counter():
cnt = 0
while True:
yield cnt
cnt += 1
def dfs(here, visited, track, count, connect):
visited |= {here}
for c in connect[here]:
if c not in visited:
dfs(c, visited, track, count, connect)
track[here] = next(count)
def kosaraju(here, visited, track, count, connect):
visited |= {here}
for c in connect[here]:
if c not in visited:
kosaraju(c, visited, track, count, connect)
track[here] = count
vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
reversed_connect = defaultdict(list)
for _ in range(edges):
v1, v2 = (int(n) for n in input().split(" "))
connect[v1].append(v2)
reversed_connect[v2].append(v1)
visited = set()
track_gen = counter()
track = [-1 for n in range(vertices)]
for v in range(vertices):
if v not in visited:
dfs(v, visited, track, track_gen, connect)
visited = set()
track_gen = counter()
strongly_con = [-1 for n in range(vertices)]
for v in range(vertices - 1, -1, -1):
here = track.index(v)
if here not in visited:
num = next(track_gen)
kosaraju(here, visited, strongly_con, num, reversed_connect)
q_num = int(eval(input()))
for _ in range(q_num):
v1, v2 = (int(n) for n in input().split(" "))
if strongly_con[v1] == strongly_con[v2]:
print((1))
else:
print((0))
| from collections import defaultdict
import sys
sys.setrecursionlimit(100000)
def counter():
cnt = 0
while True:
yield cnt
cnt += 1
def dfs(here, visited, track, count, connect):
visited |= {here}
for c in connect[here]:
if c not in visited:
dfs(c, visited, track, count, connect)
track.append(here)
def kosaraju(here, visited, track, count, connect):
visited |= {here}
for c in connect[here]:
if c not in visited:
kosaraju(c, visited, track, count, connect)
track[here] = count
vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
reversed_connect = defaultdict(list)
for _ in range(edges):
v1, v2 = (int(n) for n in input().split(" "))
connect[v1].append(v2)
reversed_connect[v2].append(v1)
visited = set()
track_gen = counter()
track = []
for v in range(vertices):
if v not in visited:
dfs(v, visited, track, track_gen, connect)
visited = set()
track_gen = counter()
strongly_con = [-1 for n in range(vertices)]
for here in track[::-1]:
if here not in visited:
num = next(track_gen)
kosaraju(here, visited, strongly_con, num, reversed_connect)
q_num = int(eval(input()))
for _ in range(q_num):
v1, v2 = (int(n) for n in input().split(" "))
if strongly_con[v1] == strongly_con[v2]:
print((1))
else:
print((0))
| false | 1.818182 | [
"- track[here] = next(count)",
"+ track.append(here)",
"-track = [-1 for n in range(vertices)]",
"+track = []",
"-for v in range(vertices - 1, -1, -1):",
"- here = track.index(v)",
"+for here in track[::-1]:"
] | false | 0.037157 | 0.036477 | 1.018641 | [
"s995290020",
"s461461949"
] |
u546338822 | p03418 | python | s380019804 | s393310876 | 549 | 220 | 3,060 | 3,060 | Accepted | Accepted | 59.93 | n,k = list(map(int,input().split()))
def main():
ans = 0
if k!= 0:
for b in range(k+1,n+1):
for q in range((n-k)//b+1):
ans += min(b-k,n-b*q-k+1)
print(ans)
return
else:
print((n*n))
return
if __name__ == "__main__":
main() | def main():
n,k = list(map(int,input().split()))
s = 0
if k==0:
s = n*n
else:
for k_ in range(k,n):
for q in range((n-k_)//(k_+1)+1):
if q==0:
s += n-k_
else:
s += (n-k_)//q-k_
print(s)
if __name__ == "__main__":
main() | 16 | 16 | 316 | 365 | n, k = list(map(int, input().split()))
def main():
ans = 0
if k != 0:
for b in range(k + 1, n + 1):
for q in range((n - k) // b + 1):
ans += min(b - k, n - b * q - k + 1)
print(ans)
return
else:
print((n * n))
return
if __name__ == "__main__":
main()
| def main():
n, k = list(map(int, input().split()))
s = 0
if k == 0:
s = n * n
else:
for k_ in range(k, n):
for q in range((n - k_) // (k_ + 1) + 1):
if q == 0:
s += n - k_
else:
s += (n - k_) // q - k_
print(s)
if __name__ == "__main__":
main()
| false | 0 | [
"-n, k = list(map(int, input().split()))",
"-",
"-",
"- ans = 0",
"- if k != 0:",
"- for b in range(k + 1, n + 1):",
"- for q in range((n - k) // b + 1):",
"- ans += min(b - k, n - b * q - k + 1)",
"- print(ans)",
"- return",
"+ n, k = list(map(int, input().split()))",
"+ s = 0",
"+ if k == 0:",
"+ s = n * n",
"- print((n * n))",
"- return",
"+ for k_ in range(k, n):",
"+ for q in range((n - k_) // (k_ + 1) + 1):",
"+ if q == 0:",
"+ s += n - k_",
"+ else:",
"+ s += (n - k_) // q - k_",
"+ print(s)"
] | false | 0.047869 | 0.043128 | 1.109921 | [
"s380019804",
"s393310876"
] |
u129978636 | p03447 | python | s335564304 | s126854526 | 19 | 17 | 2,940 | 3,064 | Accepted | Accepted | 10.53 | X = int( eval(input()))
A = int( eval(input()))
B = int( eval(input()))
X1 = X -A
Dcount = X1 // B
Dprice = B * Dcount
print((X1 - Dprice))
| X = int( eval(input()))
A = int( eval(input()))
B = int( eval(input()))
X1 = X -A
print((X1 % B))
| 11 | 6 | 134 | 84 | X = int(eval(input()))
A = int(eval(input()))
B = int(eval(input()))
X1 = X - A
Dcount = X1 // B
Dprice = B * Dcount
print((X1 - Dprice))
| X = int(eval(input()))
A = int(eval(input()))
B = int(eval(input()))
X1 = X - A
print((X1 % B))
| false | 45.454545 | [
"-Dcount = X1 // B",
"-Dprice = B * Dcount",
"-print((X1 - Dprice))",
"+print((X1 % B))"
] | false | 0.062674 | 0.04804 | 1.304611 | [
"s335564304",
"s126854526"
] |
u502312544 | p03129 | python | s960934779 | s781589273 | 30 | 27 | 9,152 | 9,064 | Accepted | Accepted | 10 | n,k = list(map(int, input().split()))
if n==1 or n==2:
if k==1:
print('YES')
else:
print('NO')
elif n%2==0:
cnt = n/2
if(cnt>=k):
print('YES')
else:
print('NO')
else:
cnt = n//2 + 1
if(cnt>=k):
print('YES')
else:
print('NO') | n,k = list(map(int, input().split()))
x = (n+1)//2
bl = (x>=k)
ans = 'YES' if bl else 'NO'
print(ans) | 18 | 5 | 315 | 99 | n, k = list(map(int, input().split()))
if n == 1 or n == 2:
if k == 1:
print("YES")
else:
print("NO")
elif n % 2 == 0:
cnt = n / 2
if cnt >= k:
print("YES")
else:
print("NO")
else:
cnt = n // 2 + 1
if cnt >= k:
print("YES")
else:
print("NO")
| n, k = list(map(int, input().split()))
x = (n + 1) // 2
bl = x >= k
ans = "YES" if bl else "NO"
print(ans)
| false | 72.222222 | [
"-if n == 1 or n == 2:",
"- if k == 1:",
"- print(\"YES\")",
"- else:",
"- print(\"NO\")",
"-elif n % 2 == 0:",
"- cnt = n / 2",
"- if cnt >= k:",
"- print(\"YES\")",
"- else:",
"- print(\"NO\")",
"-else:",
"- cnt = n // 2 + 1",
"- if cnt >= k:",
"- print(\"YES\")",
"- else:",
"- print(\"NO\")",
"+x = (n + 1) // 2",
"+bl = x >= k",
"+ans = \"YES\" if bl else \"NO\"",
"+print(ans)"
] | false | 0.032381 | 0.033044 | 0.979928 | [
"s960934779",
"s781589273"
] |
u690536347 | p04035 | python | s101896353 | s154609759 | 133 | 100 | 14,528 | 14,076 | Accepted | Accepted | 24.81 | from itertools import accumulate as ac
n,l=list(map(int,input().split()))
*a,=list(map(int,input().split()))
v=[]
for i in range(n-1):
if a[i]+a[i+1]>=l:
v.append(i+1)
break
else:
print("Impossible")
if v:
st=v[0]
v+=list(range(1,st)[::-1])
v+=list(range(st+1,n))
print("Possible")
for i in v[::-1]:
print(i) | n,l=map(int,input().split())
*a,=map(int,input().split())
v=[0]
for i in range(n-1):
if a[i]+a[i+1]>=l:
v[0]=i+1
v+=list(range(1,i+1)[::-1])
v+=list(range(i+2,n))
print("Possible")
print(*v[::-1],sep="\n")
break
else:
print("Impossible")
| 20 | 14 | 344 | 279 | from itertools import accumulate as ac
n, l = list(map(int, input().split()))
(*a,) = list(map(int, input().split()))
v = []
for i in range(n - 1):
if a[i] + a[i + 1] >= l:
v.append(i + 1)
break
else:
print("Impossible")
if v:
st = v[0]
v += list(range(1, st)[::-1])
v += list(range(st + 1, n))
print("Possible")
for i in v[::-1]:
print(i)
| n, l = map(int, input().split())
(*a,) = map(int, input().split())
v = [0]
for i in range(n - 1):
if a[i] + a[i + 1] >= l:
v[0] = i + 1
v += list(range(1, i + 1)[::-1])
v += list(range(i + 2, n))
print("Possible")
print(*v[::-1], sep="\n")
break
else:
print("Impossible")
| false | 30 | [
"-from itertools import accumulate as ac",
"-",
"-n, l = list(map(int, input().split()))",
"-(*a,) = list(map(int, input().split()))",
"-v = []",
"+n, l = map(int, input().split())",
"+(*a,) = map(int, input().split())",
"+v = [0]",
"- v.append(i + 1)",
"+ v[0] = i + 1",
"+ v += list(range(1, i + 1)[::-1])",
"+ v += list(range(i + 2, n))",
"+ print(\"Possible\")",
"+ print(*v[::-1], sep=\"\\n\")",
"-if v:",
"- st = v[0]",
"- v += list(range(1, st)[::-1])",
"- v += list(range(st + 1, n))",
"- print(\"Possible\")",
"- for i in v[::-1]:",
"- print(i)"
] | false | 0.098082 | 0.085848 | 1.142514 | [
"s101896353",
"s154609759"
] |
u079022693 | p03032 | python | s109577212 | s666424804 | 37 | 32 | 3,188 | 3,064 | Accepted | Accepted | 13.51 | def main():
N,K=list(map(int,input().split()))
V=list(map(int,input().split()))
M=min(N,K)
result=0
for l in range(M+1):
for r in range(M+1-l):
L=l
R=r
count=0
minus=[]
m=l+r
while L>0:
a=V[L-1]
if a>=0:
count+=a
else:
count+=a
minus.append(a)
L-=1
while R>0:
a=V[-R]
if a>=0:
count+=a
else:
count+=a
minus.append(a)
R-=1
minus.sort()
i_minus=0
while K-m>0 and i_minus<len(minus):
count-=minus[i_minus]
m+=1
i_minus+=1
result=max(result,count)
print(result)
if __name__=="__main__":
main() | from sys import stdin
import heapq
def main():
#入力
readline=stdin.readline
n,k=list(map(int,readline().split()))
v=list(map(int,readline().split()))
v_rev=list(reversed(v))
m=min(n,k)
ans=0
for l in range(m+1):
for r in range(m+1):
if l+r>m:
break
minus=[]
s=0
for i in range(l):
x=v[i]
if x<0:
minus.append(x)
s+=x
for i in range(r):
x=v_rev[i]
if x<0:
minus.append(x)
s+=x
if l+r<k:
minus.sort()
for i in range(k-l-r):
if i>=len(minus):
break
s-=minus[i]
ans=max(ans,s)
print(ans)
if __name__=="__main__":
main() | 40 | 43 | 988 | 937 | def main():
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
M = min(N, K)
result = 0
for l in range(M + 1):
for r in range(M + 1 - l):
L = l
R = r
count = 0
minus = []
m = l + r
while L > 0:
a = V[L - 1]
if a >= 0:
count += a
else:
count += a
minus.append(a)
L -= 1
while R > 0:
a = V[-R]
if a >= 0:
count += a
else:
count += a
minus.append(a)
R -= 1
minus.sort()
i_minus = 0
while K - m > 0 and i_minus < len(minus):
count -= minus[i_minus]
m += 1
i_minus += 1
result = max(result, count)
print(result)
if __name__ == "__main__":
main()
| from sys import stdin
import heapq
def main():
# 入力
readline = stdin.readline
n, k = list(map(int, readline().split()))
v = list(map(int, readline().split()))
v_rev = list(reversed(v))
m = min(n, k)
ans = 0
for l in range(m + 1):
for r in range(m + 1):
if l + r > m:
break
minus = []
s = 0
for i in range(l):
x = v[i]
if x < 0:
minus.append(x)
s += x
for i in range(r):
x = v_rev[i]
if x < 0:
minus.append(x)
s += x
if l + r < k:
minus.sort()
for i in range(k - l - r):
if i >= len(minus):
break
s -= minus[i]
ans = max(ans, s)
print(ans)
if __name__ == "__main__":
main()
| false | 6.976744 | [
"+from sys import stdin",
"+import heapq",
"+",
"+",
"- N, K = list(map(int, input().split()))",
"- V = list(map(int, input().split()))",
"- M = min(N, K)",
"- result = 0",
"- for l in range(M + 1):",
"- for r in range(M + 1 - l):",
"- L = l",
"- R = r",
"- count = 0",
"+ # 入力",
"+ readline = stdin.readline",
"+ n, k = list(map(int, readline().split()))",
"+ v = list(map(int, readline().split()))",
"+ v_rev = list(reversed(v))",
"+ m = min(n, k)",
"+ ans = 0",
"+ for l in range(m + 1):",
"+ for r in range(m + 1):",
"+ if l + r > m:",
"+ break",
"- m = l + r",
"- while L > 0:",
"- a = V[L - 1]",
"- if a >= 0:",
"- count += a",
"- else:",
"- count += a",
"- minus.append(a)",
"- L -= 1",
"- while R > 0:",
"- a = V[-R]",
"- if a >= 0:",
"- count += a",
"- else:",
"- count += a",
"- minus.append(a)",
"- R -= 1",
"- minus.sort()",
"- i_minus = 0",
"- while K - m > 0 and i_minus < len(minus):",
"- count -= minus[i_minus]",
"- m += 1",
"- i_minus += 1",
"- result = max(result, count)",
"- print(result)",
"+ s = 0",
"+ for i in range(l):",
"+ x = v[i]",
"+ if x < 0:",
"+ minus.append(x)",
"+ s += x",
"+ for i in range(r):",
"+ x = v_rev[i]",
"+ if x < 0:",
"+ minus.append(x)",
"+ s += x",
"+ if l + r < k:",
"+ minus.sort()",
"+ for i in range(k - l - r):",
"+ if i >= len(minus):",
"+ break",
"+ s -= minus[i]",
"+ ans = max(ans, s)",
"+ print(ans)"
] | false | 0.036736 | 0.037173 | 0.988245 | [
"s109577212",
"s666424804"
] |
u401452016 | p03371 | python | s224193275 | s455577799 | 97 | 88 | 3,060 | 3,060 | Accepted | Accepted | 9.28 | #ABC095C 全列挙
def main():
import sys, math
A,B,C,X,Y = list(map(int, sys.stdin.readline().split()))
ans = float('inf')
for i in range(10**5+1):
tmp = i*2*C + max(0, (X-i)*A) + max(0, (Y-i)*B)
ans = min(tmp, ans)
if i > X and i > Y:
break
print(ans)
if __name__=='__main__':
main()
| #ABC095C
def main():
import sys
A,B,C,X,Y = list(map(int, sys.stdin.readline().split()))
# cをi枚とする
ans = -1
for i in range(0, 2*10**5+1, 2):
tmp = max((X-i//2)*A, 0) + i*C + max((Y-i//2)*B, 0)
if ans ==-1 or ans > tmp:
ans = tmp
print(ans)
if __name__=='__main__':
main()
| 14 | 16 | 350 | 351 | # ABC095C 全列挙
def main():
import sys, math
A, B, C, X, Y = list(map(int, sys.stdin.readline().split()))
ans = float("inf")
for i in range(10**5 + 1):
tmp = i * 2 * C + max(0, (X - i) * A) + max(0, (Y - i) * B)
ans = min(tmp, ans)
if i > X and i > Y:
break
print(ans)
if __name__ == "__main__":
main()
| # ABC095C
def main():
import sys
A, B, C, X, Y = list(map(int, sys.stdin.readline().split()))
# cをi枚とする
ans = -1
for i in range(0, 2 * 10**5 + 1, 2):
tmp = max((X - i // 2) * A, 0) + i * C + max((Y - i // 2) * B, 0)
if ans == -1 or ans > tmp:
ans = tmp
print(ans)
if __name__ == "__main__":
main()
| false | 12.5 | [
"-# ABC095C 全列挙",
"+# ABC095C",
"- import sys, math",
"+ import sys",
"- ans = float(\"inf\")",
"- for i in range(10**5 + 1):",
"- tmp = i * 2 * C + max(0, (X - i) * A) + max(0, (Y - i) * B)",
"- ans = min(tmp, ans)",
"- if i > X and i > Y:",
"- break",
"+ # cをi枚とする",
"+ ans = -1",
"+ for i in range(0, 2 * 10**5 + 1, 2):",
"+ tmp = max((X - i // 2) * A, 0) + i * C + max((Y - i // 2) * B, 0)",
"+ if ans == -1 or ans > tmp:",
"+ ans = tmp"
] | false | 0.049841 | 0.117752 | 0.423269 | [
"s224193275",
"s455577799"
] |
u906501980 | p02697 | python | s368891676 | s458644321 | 90 | 74 | 69,588 | 9,280 | Accepted | Accepted | 17.78 | def main():
n, m = list(map(int, input().split()))
if n & 1:
for i in range(m):
print((i+1, n-i))
else:
i = 0
flag = False
for i in range(m):
if n-2*i-1 > n//2:
print((i+1, n-i))
else:
print((i+1, n-i-1))
if __name__ == "__main__":
main() | def main():
n, m = list(map(int, input().split()))
if n%2:
for i in range(m):
print((i+1, n-i))
else:
for i in range(m):
if n-2*i-1 > n//2:
print((i+1, n-i))
else:
print((i+1, n-i-1))
if __name__ == "__main__":
main() | 16 | 14 | 358 | 319 | def main():
n, m = list(map(int, input().split()))
if n & 1:
for i in range(m):
print((i + 1, n - i))
else:
i = 0
flag = False
for i in range(m):
if n - 2 * i - 1 > n // 2:
print((i + 1, n - i))
else:
print((i + 1, n - i - 1))
if __name__ == "__main__":
main()
| def main():
n, m = list(map(int, input().split()))
if n % 2:
for i in range(m):
print((i + 1, n - i))
else:
for i in range(m):
if n - 2 * i - 1 > n // 2:
print((i + 1, n - i))
else:
print((i + 1, n - i - 1))
if __name__ == "__main__":
main()
| false | 12.5 | [
"- if n & 1:",
"+ if n % 2:",
"- i = 0",
"- flag = False"
] | false | 0.041814 | 0.042493 | 0.984017 | [
"s368891676",
"s458644321"
] |
u018679195 | p02693 | python | s554481748 | s918461142 | 45 | 22 | 61,804 | 8,916 | Accepted | Accepted | 51.11 | k = int(eval(input()))
a, b = list(map(int, input().split()))
for i in range(a, b + 1):
if i % k == 0:
print('OK')
exit()
print('NG') | K = int(eval(input()))
s = eval(input())
A = int(s.split(" ")[0])
B = int(s.split(" ")[1])
i = 1
mul = 1
while mul <= B:
mul = i * K
if A <= mul <= B:
print("OK")
break
i = i + 1
else :
print("NG") | 7 | 14 | 147 | 230 | k = int(eval(input()))
a, b = list(map(int, input().split()))
for i in range(a, b + 1):
if i % k == 0:
print("OK")
exit()
print("NG")
| K = int(eval(input()))
s = eval(input())
A = int(s.split(" ")[0])
B = int(s.split(" ")[1])
i = 1
mul = 1
while mul <= B:
mul = i * K
if A <= mul <= B:
print("OK")
break
i = i + 1
else:
print("NG")
| false | 50 | [
"-k = int(eval(input()))",
"-a, b = list(map(int, input().split()))",
"-for i in range(a, b + 1):",
"- if i % k == 0:",
"+K = int(eval(input()))",
"+s = eval(input())",
"+A = int(s.split(\" \")[0])",
"+B = int(s.split(\" \")[1])",
"+i = 1",
"+mul = 1",
"+while mul <= B:",
"+ mul = i * K",
"+ if A <= mul <= B:",
"- exit()",
"-print(\"NG\")",
"+ break",
"+ i = i + 1",
"+else:",
"+ print(\"NG\")"
] | false | 0.046112 | 0.008868 | 5.200079 | [
"s554481748",
"s918461142"
] |
u360116509 | p03164 | python | s316450530 | s793718898 | 851 | 418 | 299,184 | 89,292 | Accepted | Accepted | 50.88 | def main():
N, W = list(map(int, input().split()))
Ws = []
Vs = []
for _ in range(N):
w, v = list(map(int, input().split()))
Ws.append(w)
Vs.append(v)
mv = sum(Vs)
dp = [[float('INF')] * (mv + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for j in range(mv + 1):
if Vs[i] > j:
dp[i + 1][j] = dp[i][j]
else:
dp[i + 1][j] = min(dp[i][j], dp[i][j - Vs[i]] + Ws[i])
for j in range(mv, -1, -1):
if W >= dp[N][j]:
print(j)
break
main()
| def main():
N, W = list(map(int, input().split()))
MV = 10**5
dp = [float('INF')] * (MV + 1)
dp[0] = 0
for _ in range(N):
w, v = list(map(int, input().split()))
for i in range(MV, -1, -1):
if v > i:
tmp = w
else:
tmp = dp[i - v] + w
dp[i] = min(dp[i], tmp)
ans = 0
for v, w in enumerate(dp):
if W >= w:
ans = max(ans, v)
else:
break
print(ans)
main()
| 24 | 23 | 611 | 519 | def main():
N, W = list(map(int, input().split()))
Ws = []
Vs = []
for _ in range(N):
w, v = list(map(int, input().split()))
Ws.append(w)
Vs.append(v)
mv = sum(Vs)
dp = [[float("INF")] * (mv + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for j in range(mv + 1):
if Vs[i] > j:
dp[i + 1][j] = dp[i][j]
else:
dp[i + 1][j] = min(dp[i][j], dp[i][j - Vs[i]] + Ws[i])
for j in range(mv, -1, -1):
if W >= dp[N][j]:
print(j)
break
main()
| def main():
N, W = list(map(int, input().split()))
MV = 10**5
dp = [float("INF")] * (MV + 1)
dp[0] = 0
for _ in range(N):
w, v = list(map(int, input().split()))
for i in range(MV, -1, -1):
if v > i:
tmp = w
else:
tmp = dp[i - v] + w
dp[i] = min(dp[i], tmp)
ans = 0
for v, w in enumerate(dp):
if W >= w:
ans = max(ans, v)
else:
break
print(ans)
main()
| false | 4.166667 | [
"- Ws = []",
"- Vs = []",
"+ MV = 10**5",
"+ dp = [float(\"INF\")] * (MV + 1)",
"+ dp[0] = 0",
"- Ws.append(w)",
"- Vs.append(v)",
"- mv = sum(Vs)",
"- dp = [[float(\"INF\")] * (mv + 1) for _ in range(N + 1)]",
"- dp[0][0] = 0",
"- for i in range(N):",
"- for j in range(mv + 1):",
"- if Vs[i] > j:",
"- dp[i + 1][j] = dp[i][j]",
"+ for i in range(MV, -1, -1):",
"+ if v > i:",
"+ tmp = w",
"- dp[i + 1][j] = min(dp[i][j], dp[i][j - Vs[i]] + Ws[i])",
"- for j in range(mv, -1, -1):",
"- if W >= dp[N][j]:",
"- print(j)",
"+ tmp = dp[i - v] + w",
"+ dp[i] = min(dp[i], tmp)",
"+ ans = 0",
"+ for v, w in enumerate(dp):",
"+ if W >= w:",
"+ ans = max(ans, v)",
"+ else:",
"+ print(ans)"
] | false | 0.039834 | 0.211071 | 0.188724 | [
"s316450530",
"s793718898"
] |
u312025627 | p03371 | python | s835292773 | s886224622 | 181 | 166 | 38,384 | 38,384 | Accepted | Accepted | 8.29 | def main():
A, B, C, X, Y = (int(i) for i in input().split())
ans1 = A * X + B * Y
ans2 = 0
ans3 = 0
if X < Y:
ans2 += 2 * C * X
ans2 += B * (Y-X)
ans3 += 2 * C * Y
else:
ans2 += 2 * C * Y
ans2 += A * (X-Y)
ans3 += 2 * C * X
print((min(ans1,ans2,ans3)))
if __name__ == '__main__':
main() | def main():
a, b, c, x, y = (int(i) for i in input().split())
ans = 0
if x > y:
p = (x - y)*a
elif y > x:
p = (y - x)*b
else:
p = 0
print((min(a*x + b*y, 2*c*max(x, y), 2*c*min(x, y) + p)))
if __name__ == '__main__':
main()
| 18 | 14 | 384 | 289 | def main():
A, B, C, X, Y = (int(i) for i in input().split())
ans1 = A * X + B * Y
ans2 = 0
ans3 = 0
if X < Y:
ans2 += 2 * C * X
ans2 += B * (Y - X)
ans3 += 2 * C * Y
else:
ans2 += 2 * C * Y
ans2 += A * (X - Y)
ans3 += 2 * C * X
print((min(ans1, ans2, ans3)))
if __name__ == "__main__":
main()
| def main():
a, b, c, x, y = (int(i) for i in input().split())
ans = 0
if x > y:
p = (x - y) * a
elif y > x:
p = (y - x) * b
else:
p = 0
print((min(a * x + b * y, 2 * c * max(x, y), 2 * c * min(x, y) + p)))
if __name__ == "__main__":
main()
| false | 22.222222 | [
"- A, B, C, X, Y = (int(i) for i in input().split())",
"- ans1 = A * X + B * Y",
"- ans2 = 0",
"- ans3 = 0",
"- if X < Y:",
"- ans2 += 2 * C * X",
"- ans2 += B * (Y - X)",
"- ans3 += 2 * C * Y",
"+ a, b, c, x, y = (int(i) for i in input().split())",
"+ ans = 0",
"+ if x > y:",
"+ p = (x - y) * a",
"+ elif y > x:",
"+ p = (y - x) * b",
"- ans2 += 2 * C * Y",
"- ans2 += A * (X - Y)",
"- ans3 += 2 * C * X",
"- print((min(ans1, ans2, ans3)))",
"+ p = 0",
"+ print((min(a * x + b * y, 2 * c * max(x, y), 2 * c * min(x, y) + p)))"
] | false | 0.036827 | 0.03393 | 1.085378 | [
"s835292773",
"s886224622"
] |
u661290476 | p00009 | python | s753935851 | s941163823 | 850 | 750 | 54,456 | 31,900 | Accepted | Accepted | 11.76 | prime=[True]*1000000
np=[0]*1000000
for i in range(2,1000000):
if prime[i]:
for j in range(i*2,1000000,i):
prime[j]=False
np[i]=np[i-1]+prime[i]
while True:
try:
n=int(eval(input()))
except:
break
print((np[n])) | prime=[True]*1000000
np=[0]*1000000
for i in range(2,1000):
if prime[i]:
for j in range(i*2,1000000,i):
prime[j]=False
while True:
try:
n=int(eval(input()))
except:
break
print((sum(prime[2:n+1]))) | 14 | 13 | 273 | 254 | prime = [True] * 1000000
np = [0] * 1000000
for i in range(2, 1000000):
if prime[i]:
for j in range(i * 2, 1000000, i):
prime[j] = False
np[i] = np[i - 1] + prime[i]
while True:
try:
n = int(eval(input()))
except:
break
print((np[n]))
| prime = [True] * 1000000
np = [0] * 1000000
for i in range(2, 1000):
if prime[i]:
for j in range(i * 2, 1000000, i):
prime[j] = False
while True:
try:
n = int(eval(input()))
except:
break
print((sum(prime[2 : n + 1])))
| false | 7.142857 | [
"-for i in range(2, 1000000):",
"+for i in range(2, 1000):",
"- np[i] = np[i - 1] + prime[i]",
"- print((np[n]))",
"+ print((sum(prime[2 : n + 1])))"
] | false | 1.561773 | 0.402627 | 3.878958 | [
"s753935851",
"s941163823"
] |
u554781254 | p02713 | python | s733596430 | s700335715 | 1,980 | 1,270 | 9,580 | 9,580 | Accepted | Accepted | 35.86 | import sys
input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop
from math import gcd
INF = float('inf')
NIL = - 1
n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
for j in range(1, n + 1):
for k in range(1, n + 1):
ans += gcd(gcd(i, j), k)
print(ans)
| import sys
input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop
from math import gcd
INF = float('inf')
NIL = - 1
N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
if i == 1:
ans += N ** 2
continue
for j in range(1, N + 1):
if j == 1:
ans += N
continue
tmp = gcd(i, j)
for k in range(1, N + 1):
ans += gcd(tmp, k)
print(ans)
| 21 | 28 | 412 | 548 | import sys
input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop
from math import gcd
INF = float("inf")
NIL = -1
n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
for j in range(1, n + 1):
for k in range(1, n + 1):
ans += gcd(gcd(i, j), k)
print(ans)
| import sys
input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop
from math import gcd
INF = float("inf")
NIL = -1
N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
if i == 1:
ans += N**2
continue
for j in range(1, N + 1):
if j == 1:
ans += N
continue
tmp = gcd(i, j)
for k in range(1, N + 1):
ans += gcd(tmp, k)
print(ans)
| false | 25 | [
"-n = int(eval(input()))",
"+N = int(eval(input()))",
"-for i in range(1, n + 1):",
"- for j in range(1, n + 1):",
"- for k in range(1, n + 1):",
"- ans += gcd(gcd(i, j), k)",
"+for i in range(1, N + 1):",
"+ if i == 1:",
"+ ans += N**2",
"+ continue",
"+ for j in range(1, N + 1):",
"+ if j == 1:",
"+ ans += N",
"+ continue",
"+ tmp = gcd(i, j)",
"+ for k in range(1, N + 1):",
"+ ans += gcd(tmp, k)"
] | false | 0.197591 | 0.047595 | 4.15154 | [
"s733596430",
"s700335715"
] |
u973108807 | p03416 | python | s476079877 | s003799805 | 64 | 51 | 2,940 | 2,940 | Accepted | Accepted | 20.31 | a,b = list(map(int,input().split()))
ans = 0
for i in range(a,b+1):
if str(i) == str(i)[::-1]:
ans += 1
print(ans) | a,b = list(map(int,input().split()))
ans = 0
for i in range(a,b+1):
s = str(i)
if s == s[::-1]:
ans += 1
print(ans) | 6 | 7 | 119 | 123 | a, b = list(map(int, input().split()))
ans = 0
for i in range(a, b + 1):
if str(i) == str(i)[::-1]:
ans += 1
print(ans)
| a, b = list(map(int, input().split()))
ans = 0
for i in range(a, b + 1):
s = str(i)
if s == s[::-1]:
ans += 1
print(ans)
| false | 14.285714 | [
"- if str(i) == str(i)[::-1]:",
"+ s = str(i)",
"+ if s == s[::-1]:"
] | false | 0.055792 | 0.063218 | 0.882535 | [
"s476079877",
"s003799805"
] |
u805852597 | p02658 | python | s866269497 | s606700388 | 80 | 49 | 21,480 | 21,656 | Accepted | Accepted | 38.75 | n = int(eval(input()))
a = list(map(int, input().split()))
ans = 1
for num in sorted(a):
ans *= num
if ans > 10**18:
print("-1")
exit()
print(ans) | def main ():
N = int(eval(input()))
A = list(map(int,input(). split ()))
if 0 in A:
print((0))
return
prod = 1
for a in A:
prod *= a
if prod > 1000000000000000000:
print((-1))
return
print(prod)
main () | 9 | 16 | 166 | 297 | n = int(eval(input()))
a = list(map(int, input().split()))
ans = 1
for num in sorted(a):
ans *= num
if ans > 10**18:
print("-1")
exit()
print(ans)
| def main():
N = int(eval(input()))
A = list(map(int, input().split()))
if 0 in A:
print((0))
return
prod = 1
for a in A:
prod *= a
if prod > 1000000000000000000:
print((-1))
return
print(prod)
main()
| false | 43.75 | [
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-ans = 1",
"-for num in sorted(a):",
"- ans *= num",
"- if ans > 10**18:",
"- print(\"-1\")",
"- exit()",
"-print(ans)",
"+def main():",
"+ N = int(eval(input()))",
"+ A = list(map(int, input().split()))",
"+ if 0 in A:",
"+ print((0))",
"+ return",
"+ prod = 1",
"+ for a in A:",
"+ prod *= a",
"+ if prod > 1000000000000000000:",
"+ print((-1))",
"+ return",
"+ print(prod)",
"+",
"+",
"+main()"
] | false | 0.088942 | 0.089059 | 0.998677 | [
"s866269497",
"s606700388"
] |
u312025627 | p03700 | python | s519284327 | s388600360 | 632 | 429 | 122,840 | 94,948 | Accepted | Accepted | 32.12 | def main():
N, A, B = (int(i) for i in input().split())
H = [int(eval(input())) for i in range(N)]
def is_ok(H, mid):
H = [h - mid*B for h in H]
need = 0
for h in H:
if h > 0:
need += (h + (A - B) - 1)//(A - B)
if need <= mid:
return True
else:
return False
def binary_search_meguru(H):
ng = -1
ok = 10**9 + 1
while abs(ok - ng) > 1:
mid = ng + (ok - ng) // 2 # 爆破回数
if is_ok(H, mid):
ok = mid
else:
ng = mid
return ok
print((binary_search_meguru(H)))
if __name__ == '__main__':
main()
| def main():
import sys
input = sys.stdin.buffer.readline
N, A, B = (int(i) for i in input().split())
H = [int(eval(input())) for i in range(N)]
def is_ok(x):
need = 0
cur = [0]*N
for i, h in enumerate(H):
cur.append(max(0, h - B*x))
for i, less in enumerate(cur):
need += (less+(A-B)-1)//(A-B)
if need <= x:
return True
else:
return False
def binary_search_meguru():
ng = -1
ok = 10**9 + 1
while abs(ok - ng) > 1:
mid = ng + (ok - ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print((binary_search_meguru()))
if __name__ == '__main__':
main()
| 31 | 34 | 730 | 813 | def main():
N, A, B = (int(i) for i in input().split())
H = [int(eval(input())) for i in range(N)]
def is_ok(H, mid):
H = [h - mid * B for h in H]
need = 0
for h in H:
if h > 0:
need += (h + (A - B) - 1) // (A - B)
if need <= mid:
return True
else:
return False
def binary_search_meguru(H):
ng = -1
ok = 10**9 + 1
while abs(ok - ng) > 1:
mid = ng + (ok - ng) // 2 # 爆破回数
if is_ok(H, mid):
ok = mid
else:
ng = mid
return ok
print((binary_search_meguru(H)))
if __name__ == "__main__":
main()
| def main():
import sys
input = sys.stdin.buffer.readline
N, A, B = (int(i) for i in input().split())
H = [int(eval(input())) for i in range(N)]
def is_ok(x):
need = 0
cur = [0] * N
for i, h in enumerate(H):
cur.append(max(0, h - B * x))
for i, less in enumerate(cur):
need += (less + (A - B) - 1) // (A - B)
if need <= x:
return True
else:
return False
def binary_search_meguru():
ng = -1
ok = 10**9 + 1
while abs(ok - ng) > 1:
mid = ng + (ok - ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print((binary_search_meguru()))
if __name__ == "__main__":
main()
| false | 8.823529 | [
"+ import sys",
"+",
"+ input = sys.stdin.buffer.readline",
"- def is_ok(H, mid):",
"- H = [h - mid * B for h in H]",
"+ def is_ok(x):",
"- for h in H:",
"- if h > 0:",
"- need += (h + (A - B) - 1) // (A - B)",
"- if need <= mid:",
"+ cur = [0] * N",
"+ for i, h in enumerate(H):",
"+ cur.append(max(0, h - B * x))",
"+ for i, less in enumerate(cur):",
"+ need += (less + (A - B) - 1) // (A - B)",
"+ if need <= x:",
"- def binary_search_meguru(H):",
"+ def binary_search_meguru():",
"- mid = ng + (ok - ng) // 2 # 爆破回数",
"- if is_ok(H, mid):",
"+ mid = ng + (ok - ng) // 2",
"+ if is_ok(mid):",
"- print((binary_search_meguru(H)))",
"+ print((binary_search_meguru()))"
] | false | 0.03732 | 0.036146 | 1.032484 | [
"s519284327",
"s388600360"
] |
u214617707 | p03546 | python | s649277548 | s571779114 | 55 | 47 | 3,444 | 3,444 | Accepted | Accepted | 14.55 | H, W = list(map(int, input().split()))
c = [[0]*10 for i in range(10)]
for i in range(10):
a = list(map(int, input().split()))
for j in range(10):
c[i][j] = a[j]
A = [[0]*W for i in range(H)]
for i in range(H):
a = list(map(int, input().split()))
for j in range(W):
A[i][j] = a[j]
for k in range(10):
for i in range(10):
for j in range(10):
for k in range(10):
if i != j:
c[i][j] = min(c[i][j], c[i][k]+c[k][j])
ans = 0
for i in range(H):
for j in range(W):
if A[i][j] != -1 and A[i][j] != 1:
ans += c[A[i][j]][1]
print(ans) | H, W = list(map(int, input().split()))
c = [[0]*10 for i in range(10)]
for i in range(10):
a = list(map(int, input().split()))
for j in range(10):
c[i][j] = a[j]
A = [[0]*W for i in range(H)]
for i in range(H):
a = list(map(int, input().split()))
for j in range(W):
A[i][j] = a[j]
for k in range(10):
for i in range(10):
for j in range(10):
if i != j:
c[i][j] = min(c[i][j], c[i][k]+c[k][j])
ans = 0
for i in range(H):
for j in range(W):
if A[i][j] != -1 and A[i][j] != 1:
ans += c[A[i][j]][1]
print(ans) | 27 | 28 | 664 | 647 | H, W = list(map(int, input().split()))
c = [[0] * 10 for i in range(10)]
for i in range(10):
a = list(map(int, input().split()))
for j in range(10):
c[i][j] = a[j]
A = [[0] * W for i in range(H)]
for i in range(H):
a = list(map(int, input().split()))
for j in range(W):
A[i][j] = a[j]
for k in range(10):
for i in range(10):
for j in range(10):
for k in range(10):
if i != j:
c[i][j] = min(c[i][j], c[i][k] + c[k][j])
ans = 0
for i in range(H):
for j in range(W):
if A[i][j] != -1 and A[i][j] != 1:
ans += c[A[i][j]][1]
print(ans)
| H, W = list(map(int, input().split()))
c = [[0] * 10 for i in range(10)]
for i in range(10):
a = list(map(int, input().split()))
for j in range(10):
c[i][j] = a[j]
A = [[0] * W for i in range(H)]
for i in range(H):
a = list(map(int, input().split()))
for j in range(W):
A[i][j] = a[j]
for k in range(10):
for i in range(10):
for j in range(10):
if i != j:
c[i][j] = min(c[i][j], c[i][k] + c[k][j])
ans = 0
for i in range(H):
for j in range(W):
if A[i][j] != -1 and A[i][j] != 1:
ans += c[A[i][j]][1]
print(ans)
| false | 3.571429 | [
"- for k in range(10):",
"- if i != j:",
"- c[i][j] = min(c[i][j], c[i][k] + c[k][j])",
"+ if i != j:",
"+ c[i][j] = min(c[i][j], c[i][k] + c[k][j])"
] | false | 0.113797 | 0.037221 | 3.057359 | [
"s649277548",
"s571779114"
] |
u520158330 | p03601 | python | s754408493 | s639780933 | 170 | 153 | 5,332 | 5,792 | Accepted | Accepted | 10 | A,B,C,D,E,F = list(map(int,input().split()))
water_sugar = []
sugar_best = []
for a in range(0,31):
water = A*a
sugar = E*water
if water==0:
pass
elif (water*100)>F:
break
elif (water*100)+sugar>F:
water_sugar.append([water*100,F-(water*100)])
elif (water*100)+sugar<=F:
water_sugar.append([water*100,sugar])
for b in range(1,31):
water += B
sugar = E*water
if (water*100)>F:
break
elif (water*100)+sugar>F:
water_sugar.append([water*100,F-(water*100)])
elif (water*100)+sugar<=F:
water_sugar.append([water*100,sugar])
#print(water_sugar)
for ws in water_sugar:
sugar = []
c=0
while(True):
s = c*C
if s<=ws[1]:
sugar.append(s)
else:
break
while(True):
s += D
if s<=ws[1]:
sugar.append(s)
else:
break
c+=1
ws[1] = max(sugar)
sugar_best.append((100*ws[1])/(ws[0]+ws[1]))
best = water_sugar[sugar_best.index(max(sugar_best))]
print((best[0]+best[1],best[1])) | A,B,C,D,E,F = list(map(int,input().split()))
water_sugar = []
sugar_best = []
s = 0
max_sugar = 0
for a in range(0,31):
water = A*a
sugar = E*water
if water==0:
pass
elif (water*100)>F:
break
elif (water*100)+sugar>F:
s = F-(water*100)
water_sugar.append([water*100,s])
elif (water*100)+sugar<=F:
s = sugar
water_sugar.append([water*100,s])
if s>max_sugar: max_sugar=s
for b in range(1,31):
water += B
sugar = E*water
if (water*100)>F:
break
elif (water*100)+sugar>F:
s = F-(water*100)
water_sugar.append([water*100,s])
elif (water*100)+sugar<=F:
s = sugar
water_sugar.append([water*100,s])
if s>max_sugar: max_sugar=s
#print(water_sugar)
#print(max_sugar)
sugar = []
c=0
while(True):
s = c*C
if s<=max_sugar:
sugar.append(s)
else:
break
while(True):
s += D
if s<=max_sugar:
sugar.append(s)
else:
break
c+=1
sugar = sorted(sugar,reverse=True)
#print(sugar)
for ws in water_sugar:
for s in sugar:
if s<=ws[1]: break
ws[1] = s
sugar_best.append((100*ws[1])/(ws[0]+ws[1]))
best = water_sugar[sugar_best.index(max(sugar_best))]
print((best[0]+best[1],best[1])) | 50 | 66 | 1,194 | 1,426 | A, B, C, D, E, F = list(map(int, input().split()))
water_sugar = []
sugar_best = []
for a in range(0, 31):
water = A * a
sugar = E * water
if water == 0:
pass
elif (water * 100) > F:
break
elif (water * 100) + sugar > F:
water_sugar.append([water * 100, F - (water * 100)])
elif (water * 100) + sugar <= F:
water_sugar.append([water * 100, sugar])
for b in range(1, 31):
water += B
sugar = E * water
if (water * 100) > F:
break
elif (water * 100) + sugar > F:
water_sugar.append([water * 100, F - (water * 100)])
elif (water * 100) + sugar <= F:
water_sugar.append([water * 100, sugar])
# print(water_sugar)
for ws in water_sugar:
sugar = []
c = 0
while True:
s = c * C
if s <= ws[1]:
sugar.append(s)
else:
break
while True:
s += D
if s <= ws[1]:
sugar.append(s)
else:
break
c += 1
ws[1] = max(sugar)
sugar_best.append((100 * ws[1]) / (ws[0] + ws[1]))
best = water_sugar[sugar_best.index(max(sugar_best))]
print((best[0] + best[1], best[1]))
| A, B, C, D, E, F = list(map(int, input().split()))
water_sugar = []
sugar_best = []
s = 0
max_sugar = 0
for a in range(0, 31):
water = A * a
sugar = E * water
if water == 0:
pass
elif (water * 100) > F:
break
elif (water * 100) + sugar > F:
s = F - (water * 100)
water_sugar.append([water * 100, s])
elif (water * 100) + sugar <= F:
s = sugar
water_sugar.append([water * 100, s])
if s > max_sugar:
max_sugar = s
for b in range(1, 31):
water += B
sugar = E * water
if (water * 100) > F:
break
elif (water * 100) + sugar > F:
s = F - (water * 100)
water_sugar.append([water * 100, s])
elif (water * 100) + sugar <= F:
s = sugar
water_sugar.append([water * 100, s])
if s > max_sugar:
max_sugar = s
# print(water_sugar)
# print(max_sugar)
sugar = []
c = 0
while True:
s = c * C
if s <= max_sugar:
sugar.append(s)
else:
break
while True:
s += D
if s <= max_sugar:
sugar.append(s)
else:
break
c += 1
sugar = sorted(sugar, reverse=True)
# print(sugar)
for ws in water_sugar:
for s in sugar:
if s <= ws[1]:
break
ws[1] = s
sugar_best.append((100 * ws[1]) / (ws[0] + ws[1]))
best = water_sugar[sugar_best.index(max(sugar_best))]
print((best[0] + best[1], best[1]))
| false | 24.242424 | [
"+s = 0",
"+max_sugar = 0",
"- water_sugar.append([water * 100, F - (water * 100)])",
"+ s = F - (water * 100)",
"+ water_sugar.append([water * 100, s])",
"- water_sugar.append([water * 100, sugar])",
"+ s = sugar",
"+ water_sugar.append([water * 100, s])",
"+ if s > max_sugar:",
"+ max_sugar = s",
"- water_sugar.append([water * 100, F - (water * 100)])",
"+ s = F - (water * 100)",
"+ water_sugar.append([water * 100, s])",
"- water_sugar.append([water * 100, sugar])",
"+ s = sugar",
"+ water_sugar.append([water * 100, s])",
"+ if s > max_sugar:",
"+ max_sugar = s",
"-for ws in water_sugar:",
"- sugar = []",
"- c = 0",
"+# print(max_sugar)",
"+sugar = []",
"+c = 0",
"+while True:",
"+ s = c * C",
"+ if s <= max_sugar:",
"+ sugar.append(s)",
"+ else:",
"+ break",
"- s = c * C",
"- if s <= ws[1]:",
"+ s += D",
"+ if s <= max_sugar:",
"- while True:",
"- s += D",
"- if s <= ws[1]:",
"- sugar.append(s)",
"- else:",
"- break",
"- c += 1",
"- ws[1] = max(sugar)",
"+ c += 1",
"+sugar = sorted(sugar, reverse=True)",
"+# print(sugar)",
"+for ws in water_sugar:",
"+ for s in sugar:",
"+ if s <= ws[1]:",
"+ break",
"+ ws[1] = s"
] | false | 0.046311 | 0.048587 | 0.953157 | [
"s754408493",
"s639780933"
] |
u497235501 | p03013 | python | s497432326 | s898579870 | 179 | 62 | 84,248 | 14,180 | Accepted | Accepted | 65.36 | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 1000000007
a=open(0)
N,_,*a = list(map(int, a.read().split()))
dp = [-1 for _ in range(100010)]
dp[0] = 0
for i in a: dp[i] = 0
def rec(i):
if dp[i] > -1:
return dp[i]
if i<3:
dp[i] = rec(i-1) + 1
return dp[i]
dp[i] = (rec(i-1)+rec(i-2))%MOD
return dp[i]
print((rec(N)))
| MOD=10**9+7
N,_,*a = list(map(int, open(0).read().split()))
A=set(a)
dp = [0 for _ in range(N+1)]
dp[:2] = 1, 0 if 1 in A else 1
for i in range(2,N+1):
if i not in A:
dp[i]=(dp[i-1]+dp[i-2])%MOD
print((dp[N]))
| 26 | 13 | 410 | 234 | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 1000000007
a = open(0)
N, _, *a = list(map(int, a.read().split()))
dp = [-1 for _ in range(100010)]
dp[0] = 0
for i in a:
dp[i] = 0
def rec(i):
if dp[i] > -1:
return dp[i]
if i < 3:
dp[i] = rec(i - 1) + 1
return dp[i]
dp[i] = (rec(i - 1) + rec(i - 2)) % MOD
return dp[i]
print((rec(N)))
| MOD = 10**9 + 7
N, _, *a = list(map(int, open(0).read().split()))
A = set(a)
dp = [0 for _ in range(N + 1)]
dp[:2] = 1, 0 if 1 in A else 1
for i in range(2, N + 1):
if i not in A:
dp[i] = (dp[i - 1] + dp[i - 2]) % MOD
print((dp[N]))
| false | 50 | [
"-import sys",
"-",
"-sys.setrecursionlimit(2147483647)",
"-INF = float(\"inf\")",
"-MOD = 1000000007",
"-a = open(0)",
"-N, _, *a = list(map(int, a.read().split()))",
"-dp = [-1 for _ in range(100010)]",
"-dp[0] = 0",
"-for i in a:",
"- dp[i] = 0",
"-",
"-",
"-def rec(i):",
"- if dp[i] > -1:",
"- return dp[i]",
"- if i < 3:",
"- dp[i] = rec(i - 1) + 1",
"- return dp[i]",
"- dp[i] = (rec(i - 1) + rec(i - 2)) % MOD",
"- return dp[i]",
"-",
"-",
"-print((rec(N)))",
"+MOD = 10**9 + 7",
"+N, _, *a = list(map(int, open(0).read().split()))",
"+A = set(a)",
"+dp = [0 for _ in range(N + 1)]",
"+dp[:2] = 1, 0 if 1 in A else 1",
"+for i in range(2, N + 1):",
"+ if i not in A:",
"+ dp[i] = (dp[i - 1] + dp[i - 2]) % MOD",
"+print((dp[N]))"
] | false | 0.056547 | 0.110701 | 0.510811 | [
"s497432326",
"s898579870"
] |
u227082700 | p03957 | python | s408000671 | s866012031 | 20 | 17 | 2,940 | 3,060 | Accepted | Accepted | 15 | s=eval(input())
if "C"in s and "F"in s:
if s.find("C")<s.rfind("F"):print("Yes")
else:print("No")
else:print("No") | s=eval(input())
if "C"not in s:print("No")
elif s.find("C",0)<s.find("F",s.find("C",0)+1):print("Yes")
else:print("No") | 5 | 4 | 116 | 116 | s = eval(input())
if "C" in s and "F" in s:
if s.find("C") < s.rfind("F"):
print("Yes")
else:
print("No")
else:
print("No")
| s = eval(input())
if "C" not in s:
print("No")
elif s.find("C", 0) < s.find("F", s.find("C", 0) + 1):
print("Yes")
else:
print("No")
| false | 20 | [
"-if \"C\" in s and \"F\" in s:",
"- if s.find(\"C\") < s.rfind(\"F\"):",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"+if \"C\" not in s:",
"+ print(\"No\")",
"+elif s.find(\"C\", 0) < s.find(\"F\", s.find(\"C\", 0) + 1):",
"+ print(\"Yes\")"
] | false | 0.052245 | 0.071722 | 0.728428 | [
"s408000671",
"s866012031"
] |
u699089116 | p02612 | python | s637198143 | s421538728 | 69 | 27 | 61,668 | 9,152 | Accepted | Accepted | 60.87 | n = int(eval(input()))
for i in range(1, 11):
if n <= i * 1000:
print((i * 1000 - n))
exit() | n = int(eval(input()))
print((0 if n % 1000 == 0 else 1000 - n % 1000)) | 6 | 3 | 110 | 66 | n = int(eval(input()))
for i in range(1, 11):
if n <= i * 1000:
print((i * 1000 - n))
exit()
| n = int(eval(input()))
print((0 if n % 1000 == 0 else 1000 - n % 1000))
| false | 50 | [
"-for i in range(1, 11):",
"- if n <= i * 1000:",
"- print((i * 1000 - n))",
"- exit()",
"+print((0 if n % 1000 == 0 else 1000 - n % 1000))"
] | false | 0.040038 | 0.039482 | 1.014074 | [
"s637198143",
"s421538728"
] |
u250583425 | p03329 | python | s424338086 | s313856513 | 700 | 200 | 85,852 | 41,968 | Accepted | Accepted | 71.43 | import sys
sys.setrecursionlimit(10 ** 9)
from functools import lru_cache
def input(): return sys.stdin.readline().rstrip()
def main():
N = int(eval(input()))
yen = [6 ** i for i in range(1, 7)]
yen += [9 ** i for i in range(1, 6)]
yen = [i for i in yen if i <= N]
yen.sort(reverse=True)
def MIN(a, b):
if a > b:
return b
else:
return a
@lru_cache(maxsize=None)
def dfs(x, n, m):
n += 1
for y in yen:
if n >= m:
return n
if y > x:
continue
if x - y < 6:
return n + x - y
m = MIN(dfs(x - y, n, m), m)
return m
print((dfs(N, 0, N)))
if __name__ == '__main__':
main()
| import sys
def input(): return sys.stdin.readline().rstrip()
def MIN(a, b):
if a > b:
return b
else:
return a
def main():
N = int(eval(input()))
yen6 = [6 ** i for i in range(1, 7) if 6 ** i <= N]
yen9 = [9 ** i for i in range(1, 6) if 9 ** i <= N]
if N < 6:
print(N)
exit()
dp = [N] * (N + 1)
for i in range(6):
dp[i] = i
for i in range(1, N + 1):
for j in yen6:
if i - j < 0:
break
dp[i] = MIN(dp[i], dp[i - j] + 1)
for j in yen9:
if i - j < 0:
break
dp[i] = MIN(dp[i], dp[i - j] + 1)
print((dp[N]))
if __name__ == '__main__':
main()
| 35 | 34 | 796 | 746 | import sys
sys.setrecursionlimit(10**9)
from functools import lru_cache
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(eval(input()))
yen = [6**i for i in range(1, 7)]
yen += [9**i for i in range(1, 6)]
yen = [i for i in yen if i <= N]
yen.sort(reverse=True)
def MIN(a, b):
if a > b:
return b
else:
return a
@lru_cache(maxsize=None)
def dfs(x, n, m):
n += 1
for y in yen:
if n >= m:
return n
if y > x:
continue
if x - y < 6:
return n + x - y
m = MIN(dfs(x - y, n, m), m)
return m
print((dfs(N, 0, N)))
if __name__ == "__main__":
main()
| import sys
def input():
return sys.stdin.readline().rstrip()
def MIN(a, b):
if a > b:
return b
else:
return a
def main():
N = int(eval(input()))
yen6 = [6**i for i in range(1, 7) if 6**i <= N]
yen9 = [9**i for i in range(1, 6) if 9**i <= N]
if N < 6:
print(N)
exit()
dp = [N] * (N + 1)
for i in range(6):
dp[i] = i
for i in range(1, N + 1):
for j in yen6:
if i - j < 0:
break
dp[i] = MIN(dp[i], dp[i - j] + 1)
for j in yen9:
if i - j < 0:
break
dp[i] = MIN(dp[i], dp[i - j] + 1)
print((dp[N]))
if __name__ == "__main__":
main()
| false | 2.857143 | [
"-",
"-sys.setrecursionlimit(10**9)",
"-from functools import lru_cache",
"+def MIN(a, b):",
"+ if a > b:",
"+ return b",
"+ else:",
"+ return a",
"+",
"+",
"- yen = [6**i for i in range(1, 7)]",
"- yen += [9**i for i in range(1, 6)]",
"- yen = [i for i in yen if i <= N]",
"- yen.sort(reverse=True)",
"-",
"- def MIN(a, b):",
"- if a > b:",
"- return b",
"- else:",
"- return a",
"-",
"- @lru_cache(maxsize=None)",
"- def dfs(x, n, m):",
"- n += 1",
"- for y in yen:",
"- if n >= m:",
"- return n",
"- if y > x:",
"- continue",
"- if x - y < 6:",
"- return n + x - y",
"- m = MIN(dfs(x - y, n, m), m)",
"- return m",
"-",
"- print((dfs(N, 0, N)))",
"+ yen6 = [6**i for i in range(1, 7) if 6**i <= N]",
"+ yen9 = [9**i for i in range(1, 6) if 9**i <= N]",
"+ if N < 6:",
"+ print(N)",
"+ exit()",
"+ dp = [N] * (N + 1)",
"+ for i in range(6):",
"+ dp[i] = i",
"+ for i in range(1, N + 1):",
"+ for j in yen6:",
"+ if i - j < 0:",
"+ break",
"+ dp[i] = MIN(dp[i], dp[i - j] + 1)",
"+ for j in yen9:",
"+ if i - j < 0:",
"+ break",
"+ dp[i] = MIN(dp[i], dp[i - j] + 1)",
"+ print((dp[N]))"
] | false | 0.107154 | 0.097809 | 1.095548 | [
"s424338086",
"s313856513"
] |
u193806284 | p03419 | python | s888605241 | s587764433 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 |
def calc0(N, M):
cell = [[0 for i in range(M)] for j in range(N)]
for i in range(M):
for j in range(N):
for y in range(-1, 2):
for x in range(-1, 2):
xx = i + x
yy = j + y
if 0 <= xx < M and 0 <= yy < N:
cell[yy][xx] ^= 1
r = 0
for i in range(M):
for j in range(N):
if cell[j][i]:
r += 1
return r
def calc(N, M):
if N == 1 and M == 1:
return 1
if N >= 2 and M >= 2:
return (N - 2) * (M - 2)
if N == 1:
return M - 2
return N - 2
N, M = [int(_) for _ in input().split()]
print((calc(N, M)))
| def calc(N, M):
if N == 1 and M == 1:
return 1
if N == 1:
return M - 2
if M == 1:
return N - 2
# N >= 2 and M >= 2:
return (N - 2) * (M - 2)
N, M = [int(_) for _ in input().split()]
print((calc(N, M)))
| 31 | 13 | 742 | 258 | def calc0(N, M):
cell = [[0 for i in range(M)] for j in range(N)]
for i in range(M):
for j in range(N):
for y in range(-1, 2):
for x in range(-1, 2):
xx = i + x
yy = j + y
if 0 <= xx < M and 0 <= yy < N:
cell[yy][xx] ^= 1
r = 0
for i in range(M):
for j in range(N):
if cell[j][i]:
r += 1
return r
def calc(N, M):
if N == 1 and M == 1:
return 1
if N >= 2 and M >= 2:
return (N - 2) * (M - 2)
if N == 1:
return M - 2
return N - 2
N, M = [int(_) for _ in input().split()]
print((calc(N, M)))
| def calc(N, M):
if N == 1 and M == 1:
return 1
if N == 1:
return M - 2
if M == 1:
return N - 2
# N >= 2 and M >= 2:
return (N - 2) * (M - 2)
N, M = [int(_) for _ in input().split()]
print((calc(N, M)))
| false | 58.064516 | [
"-def calc0(N, M):",
"- cell = [[0 for i in range(M)] for j in range(N)]",
"- for i in range(M):",
"- for j in range(N):",
"- for y in range(-1, 2):",
"- for x in range(-1, 2):",
"- xx = i + x",
"- yy = j + y",
"- if 0 <= xx < M and 0 <= yy < N:",
"- cell[yy][xx] ^= 1",
"- r = 0",
"- for i in range(M):",
"- for j in range(N):",
"- if cell[j][i]:",
"- r += 1",
"- return r",
"-",
"-",
"- if N >= 2 and M >= 2:",
"- return (N - 2) * (M - 2)",
"- return N - 2",
"+ if M == 1:",
"+ return N - 2",
"+ # N >= 2 and M >= 2:",
"+ return (N - 2) * (M - 2)"
] | false | 0.040336 | 0.044924 | 0.897859 | [
"s888605241",
"s587764433"
] |
u350248178 | p03253 | python | s891305869 | s942272536 | 1,948 | 44 | 114,140 | 6,900 | Accepted | Accepted | 97.74 | n,m=list(map(int,input().split()))
def c(n,m):
import math
if n-m<0:
return 0
return(math.factorial(n)//math.factorial(n-m)//math.factorial(m))
def factorize(n):
fct=[]
b,e=2,0
while b*b<=n:
while n%b==0:
n=n//b
e=e+1
if e>0:
fct.append((b,e))
b,e=b+1,0
if n>1:
fct.append((n,1))
return fct
l=factorize(m)
mod=10**9+7
ans=1
for i,j in l:
ans*=c(j+n-1,j)
ans=ans%mod
print(ans) | n,m=list(map(int,input().split()))
def factorize(n):
fct=[]
b,e=2,0
while b*b<=n:
while n%b==0:
n=n//b
e=e+1
if e>0:
fct.append((b,e))
b,e=b+1,0
if n>1:
fct.append((n,1))
return fct
l=factorize(m)
mod=10**9+7
ans=1
def inv(x):
return pow(x, mod - 2, mod)
cms = 10**5 + 100
cm = [0] * cms
def comb_init():
cm[0] = 1
for i in range(1, cms):
cm[i] = cm[i-1] * i % mod
def c(a, b):
return (cm[a] * inv(cm[a-b]) % mod) * inv(cm[b]) % mod
mod=10**9+7
comb_init()
for i,j in l:
ans*=c(j+n-1,j)
ans=ans%mod
print(ans) | 30 | 42 | 519 | 676 | n, m = list(map(int, input().split()))
def c(n, m):
import math
if n - m < 0:
return 0
return math.factorial(n) // math.factorial(n - m) // math.factorial(m)
def factorize(n):
fct = []
b, e = 2, 0
while b * b <= n:
while n % b == 0:
n = n // b
e = e + 1
if e > 0:
fct.append((b, e))
b, e = b + 1, 0
if n > 1:
fct.append((n, 1))
return fct
l = factorize(m)
mod = 10**9 + 7
ans = 1
for i, j in l:
ans *= c(j + n - 1, j)
ans = ans % mod
print(ans)
| n, m = list(map(int, input().split()))
def factorize(n):
fct = []
b, e = 2, 0
while b * b <= n:
while n % b == 0:
n = n // b
e = e + 1
if e > 0:
fct.append((b, e))
b, e = b + 1, 0
if n > 1:
fct.append((n, 1))
return fct
l = factorize(m)
mod = 10**9 + 7
ans = 1
def inv(x):
return pow(x, mod - 2, mod)
cms = 10**5 + 100
cm = [0] * cms
def comb_init():
cm[0] = 1
for i in range(1, cms):
cm[i] = cm[i - 1] * i % mod
def c(a, b):
return (cm[a] * inv(cm[a - b]) % mod) * inv(cm[b]) % mod
mod = 10**9 + 7
comb_init()
for i, j in l:
ans *= c(j + n - 1, j)
ans = ans % mod
print(ans)
| false | 28.571429 | [
"-",
"-",
"-def c(n, m):",
"- import math",
"-",
"- if n - m < 0:",
"- return 0",
"- return math.factorial(n) // math.factorial(n - m) // math.factorial(m)",
"+",
"+",
"+def inv(x):",
"+ return pow(x, mod - 2, mod)",
"+",
"+",
"+cms = 10**5 + 100",
"+cm = [0] * cms",
"+",
"+",
"+def comb_init():",
"+ cm[0] = 1",
"+ for i in range(1, cms):",
"+ cm[i] = cm[i - 1] * i % mod",
"+",
"+",
"+def c(a, b):",
"+ return (cm[a] * inv(cm[a - b]) % mod) * inv(cm[b]) % mod",
"+",
"+",
"+mod = 10**9 + 7",
"+comb_init()"
] | false | 0.366798 | 0.082603 | 4.44049 | [
"s891305869",
"s942272536"
] |
u367965715 | p02803 | python | s810169359 | s375901539 | 1,446 | 264 | 21,232 | 20,516 | Accepted | Accepted | 81.74 | import numpy as np
from collections import deque
from itertools import product
H, W = list(map(int, input().split()))
S = np.full((H, W), 'x', dtype='U1')
for i in range(H):
S[i] = list(eval(input()))
def bfs(x, y):
dist = np.full((H, W), -1, dtype='i8')
que = deque()
dist[x, y] = 0
que.append((x, y))
while que:
h, w = que.popleft()
d = dist[h, w]
for dx, dy in ((0, -1), (-1, 0), (1, 0), (0, 1)):
hh, ww = h + dx, w + dy
if hh < 0 or H <= hh or ww < 0 or W <= ww or S[hh, ww] == '#' or dist[hh, ww] != -1:
continue
dist[hh, ww] = d + 1
que.append((hh, ww))
return d
res = 0
for i, k in product(list(range(H)), list(range(W))):
if S[i, k] == '#':
continue
d = bfs(i, k)
if d > res:
res = d
print(res)
| import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from itertools import product
h, w = list(map(int, input().split()))
s = np.full((h, w), 'x', dtype='U1')
for i in range(h):
s[i] = list(eval(input()))
d = np.identity(h * w, dtype='i1')
for i, k in product(list(range(h)), list(range(w))):
if s[i, k] == '#':
continue
for dy, dx in ((-1, 0), (0, -1), (0, 1), (1, 0)):
y, x = i + dy, k + dx
if y < 0 or h <= y or x < 0 or w <= x or s[y, x] == '#':
continue
d[i*w+k, y*w+x] = 1
d[y*w+x, i*w+k] = 1
print((floyd_warshall(d).astype('i8').max()))
| 36 | 21 | 864 | 620 | import numpy as np
from collections import deque
from itertools import product
H, W = list(map(int, input().split()))
S = np.full((H, W), "x", dtype="U1")
for i in range(H):
S[i] = list(eval(input()))
def bfs(x, y):
dist = np.full((H, W), -1, dtype="i8")
que = deque()
dist[x, y] = 0
que.append((x, y))
while que:
h, w = que.popleft()
d = dist[h, w]
for dx, dy in ((0, -1), (-1, 0), (1, 0), (0, 1)):
hh, ww = h + dx, w + dy
if (
hh < 0
or H <= hh
or ww < 0
or W <= ww
or S[hh, ww] == "#"
or dist[hh, ww] != -1
):
continue
dist[hh, ww] = d + 1
que.append((hh, ww))
return d
res = 0
for i, k in product(list(range(H)), list(range(W))):
if S[i, k] == "#":
continue
d = bfs(i, k)
if d > res:
res = d
print(res)
| import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from itertools import product
h, w = list(map(int, input().split()))
s = np.full((h, w), "x", dtype="U1")
for i in range(h):
s[i] = list(eval(input()))
d = np.identity(h * w, dtype="i1")
for i, k in product(list(range(h)), list(range(w))):
if s[i, k] == "#":
continue
for dy, dx in ((-1, 0), (0, -1), (0, 1), (1, 0)):
y, x = i + dy, k + dx
if y < 0 or h <= y or x < 0 or w <= x or s[y, x] == "#":
continue
d[i * w + k, y * w + x] = 1
d[y * w + x, i * w + k] = 1
print((floyd_warshall(d).astype("i8").max()))
| false | 41.666667 | [
"-from collections import deque",
"+from scipy.sparse.csgraph import floyd_warshall",
"-H, W = list(map(int, input().split()))",
"-S = np.full((H, W), \"x\", dtype=\"U1\")",
"-for i in range(H):",
"- S[i] = list(eval(input()))",
"-",
"-",
"-def bfs(x, y):",
"- dist = np.full((H, W), -1, dtype=\"i8\")",
"- que = deque()",
"- dist[x, y] = 0",
"- que.append((x, y))",
"- while que:",
"- h, w = que.popleft()",
"- d = dist[h, w]",
"- for dx, dy in ((0, -1), (-1, 0), (1, 0), (0, 1)):",
"- hh, ww = h + dx, w + dy",
"- if (",
"- hh < 0",
"- or H <= hh",
"- or ww < 0",
"- or W <= ww",
"- or S[hh, ww] == \"#\"",
"- or dist[hh, ww] != -1",
"- ):",
"- continue",
"- dist[hh, ww] = d + 1",
"- que.append((hh, ww))",
"- return d",
"-",
"-",
"-res = 0",
"-for i, k in product(list(range(H)), list(range(W))):",
"- if S[i, k] == \"#\":",
"+h, w = list(map(int, input().split()))",
"+s = np.full((h, w), \"x\", dtype=\"U1\")",
"+for i in range(h):",
"+ s[i] = list(eval(input()))",
"+d = np.identity(h * w, dtype=\"i1\")",
"+for i, k in product(list(range(h)), list(range(w))):",
"+ if s[i, k] == \"#\":",
"- d = bfs(i, k)",
"- if d > res:",
"- res = d",
"-print(res)",
"+ for dy, dx in ((-1, 0), (0, -1), (0, 1), (1, 0)):",
"+ y, x = i + dy, k + dx",
"+ if y < 0 or h <= y or x < 0 or w <= x or s[y, x] == \"#\":",
"+ continue",
"+ d[i * w + k, y * w + x] = 1",
"+ d[y * w + x, i * w + k] = 1",
"+print((floyd_warshall(d).astype(\"i8\").max()))"
] | false | 0.298697 | 0.285853 | 1.044932 | [
"s810169359",
"s375901539"
] |
u285891772 | p02927 | python | s574003733 | s280668251 | 50 | 40 | 5,200 | 5,160 | Accepted | Accepted | 20 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
M, D = MAP()
ans = 0
for m in range(1, M+1):
for d in range(1, D+1):
if len(str(d)) == 2:
d1 = int(str(d)[1])
d10 = int(str(d)[0])
if 2 <= d1 and 2 <= d10 and d1*d10 == m:
ans += 1
print(ans)
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
M, D = MAP()
ans = 0
for i in range(1, M+1):
for j in range(1, D+1):
if 2 <= j//10 and 2 <= j%10 and (j//10)*(j%10) == i:
ans += 1
print(ans)
| 32 | 31 | 1,115 | 1,058 | import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
) # , log2
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# from decimal import *
M, D = MAP()
ans = 0
for m in range(1, M + 1):
for d in range(1, D + 1):
if len(str(d)) == 2:
d1 = int(str(d)[1])
d10 = int(str(d)[0])
if 2 <= d1 and 2 <= d10 and d1 * d10 == m:
ans += 1
print(ans)
| import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
) # , log2
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# from decimal import *
M, D = MAP()
ans = 0
for i in range(1, M + 1):
for j in range(1, D + 1):
if 2 <= j // 10 and 2 <= j % 10 and (j // 10) * (j % 10) == i:
ans += 1
print(ans)
| false | 3.125 | [
"-for m in range(1, M + 1):",
"- for d in range(1, D + 1):",
"- if len(str(d)) == 2:",
"- d1 = int(str(d)[1])",
"- d10 = int(str(d)[0])",
"- if 2 <= d1 and 2 <= d10 and d1 * d10 == m:",
"- ans += 1",
"+for i in range(1, M + 1):",
"+ for j in range(1, D + 1):",
"+ if 2 <= j // 10 and 2 <= j % 10 and (j // 10) * (j % 10) == i:",
"+ ans += 1"
] | false | 0.105037 | 0.082908 | 1.266917 | [
"s574003733",
"s280668251"
] |
u604839890 | p02713 | python | s183617991 | s173505014 | 470 | 186 | 68,904 | 68,652 | Accepted | Accepted | 60.43 | import math
w = 0
k = int(eval(input()))
for i in range(1, k+1):
for j in range(1, k+1):
for l in range(1, k+1):
m = math.gcd(i, j)
w += math.gcd(m, l)
print(w) | import math
w = 0
k = int(eval(input()))
for i in range(1, k+1):
for j in range(1, k+1):
m = math.gcd(i, j)
for l in range(1, k+1):
w += math.gcd(m, l)
print(w) | 10 | 10 | 201 | 197 | import math
w = 0
k = int(eval(input()))
for i in range(1, k + 1):
for j in range(1, k + 1):
for l in range(1, k + 1):
m = math.gcd(i, j)
w += math.gcd(m, l)
print(w)
| import math
w = 0
k = int(eval(input()))
for i in range(1, k + 1):
for j in range(1, k + 1):
m = math.gcd(i, j)
for l in range(1, k + 1):
w += math.gcd(m, l)
print(w)
| false | 0 | [
"+ m = math.gcd(i, j)",
"- m = math.gcd(i, j)"
] | false | 0.039662 | 0.136209 | 0.291186 | [
"s183617991",
"s173505014"
] |
u279605379 | p02297 | python | s293905102 | s191524744 | 30 | 20 | 7,668 | 7,728 | Accepted | Accepted | 33.33 | n = int(eval(input()))
P =[]
s = 0
for _ in range(n):P.append([int(i) for i in input().split()])
P.append(P[0])
for j in range(n):s += - P[j][1]*P[j+1][0] + P[j+1][1] * P[j][0]
print((s*0.5)) | n = int(eval(input()))
P =[]
s = 0
for _ in range(n):P.append([int(i) for i in input().split()])
P.append(P[0])
for j in range(n):s += P[j][1]*P[j+1][0] - P[j+1][1] * P[j][0]
print((s*-0.5)) | 7 | 7 | 189 | 188 | n = int(eval(input()))
P = []
s = 0
for _ in range(n):
P.append([int(i) for i in input().split()])
P.append(P[0])
for j in range(n):
s += -P[j][1] * P[j + 1][0] + P[j + 1][1] * P[j][0]
print((s * 0.5))
| n = int(eval(input()))
P = []
s = 0
for _ in range(n):
P.append([int(i) for i in input().split()])
P.append(P[0])
for j in range(n):
s += P[j][1] * P[j + 1][0] - P[j + 1][1] * P[j][0]
print((s * -0.5))
| false | 0 | [
"- s += -P[j][1] * P[j + 1][0] + P[j + 1][1] * P[j][0]",
"-print((s * 0.5))",
"+ s += P[j][1] * P[j + 1][0] - P[j + 1][1] * P[j][0]",
"+print((s * -0.5))"
] | false | 0.032711 | 0.038413 | 0.85157 | [
"s293905102",
"s191524744"
] |
u038408819 | p03659 | python | s892085002 | s183137696 | 236 | 191 | 28,652 | 24,832 | Accepted | Accepted | 19.07 | N = int(eval(input()))
a = list(map(int, input().split()))
s_right = [0] * (N + 1)
s_left = [0] * (N + 1)
for i in range(N):
s_left[i + 1] = s_left[i] + a[i]
s_right[i + 1] = s_right[i] + a[N - 1 - i]
ans = float('Inf')
for i in range(1, N):
#print(ans)
if ans > abs(s_left[i] - s_right[N - i]):
ans = abs(s_left[i] - s_right[N - i])
print(ans)
| N = int(eval(input()))
a = list(map(int, input().split()))
s = [0] * (N + 1)
for i in range(N):
s[i + 1] = s[i] + a[i]
ans = float('Inf')
for i in range(1, N):
#print(ans)
kouho = abs(s[i] - ((s[-1]) - s[i]))
if ans > kouho:
ans = kouho
#ans = min(ans, kouho)
print(ans)
| 13 | 13 | 375 | 305 | N = int(eval(input()))
a = list(map(int, input().split()))
s_right = [0] * (N + 1)
s_left = [0] * (N + 1)
for i in range(N):
s_left[i + 1] = s_left[i] + a[i]
s_right[i + 1] = s_right[i] + a[N - 1 - i]
ans = float("Inf")
for i in range(1, N):
# print(ans)
if ans > abs(s_left[i] - s_right[N - i]):
ans = abs(s_left[i] - s_right[N - i])
print(ans)
| N = int(eval(input()))
a = list(map(int, input().split()))
s = [0] * (N + 1)
for i in range(N):
s[i + 1] = s[i] + a[i]
ans = float("Inf")
for i in range(1, N):
# print(ans)
kouho = abs(s[i] - ((s[-1]) - s[i]))
if ans > kouho:
ans = kouho
# ans = min(ans, kouho)
print(ans)
| false | 0 | [
"-s_right = [0] * (N + 1)",
"-s_left = [0] * (N + 1)",
"+s = [0] * (N + 1)",
"- s_left[i + 1] = s_left[i] + a[i]",
"- s_right[i + 1] = s_right[i] + a[N - 1 - i]",
"+ s[i + 1] = s[i] + a[i]",
"- if ans > abs(s_left[i] - s_right[N - i]):",
"- ans = abs(s_left[i] - s_right[N - i])",
"+ kouho = abs(s[i] - ((s[-1]) - s[i]))",
"+ if ans > kouho:",
"+ ans = kouho",
"+ # ans = min(ans, kouho)"
] | false | 0.038432 | 0.044861 | 0.856687 | [
"s892085002",
"s183137696"
] |
u794173881 | p03027 | python | s719891765 | s472042129 | 1,999 | 978 | 115,996 | 115,440 | Accepted | Accepted | 51.08 | class Combination:
'''
計算量:階乗・逆元テーブルの作成O(N)
nCkを求めるO(1)
'''
def __init__(self, n, MOD):
self.fact = [1]
for i in range(1, n + 1):
self.fact.append(self.fact[-1] * i % MOD)
self.inv_fact = [pow(self.fact[i] ,MOD - 2 ,MOD) for i in range(n + 1)]
self.MOD = MOD
def factorial(self, k):
'''k!を求める'''
return self.fact[k]
def inverse_factorial(self, k):
'''k!の逆元を求める'''
return self.inv_fact[k]
def combination(self, k, r):
'''kCrを求める'''
return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD
q = int(eval(input()))
MOD = 10**6 + 3
comb = Combination(MOD, MOD)
for i in range(q):
a1, d, n = list(map(int, input().split()))
if d == 0:
print((pow(a1, n, MOD)))
continue
syoko = a1 * (comb.inv_fact[d] * comb.fact[d-1])
syoko %= MOD
if syoko ==0 or syoko + (n-1) >= MOD:
print((0))
else:
ans = pow(d, n, MOD) * comb.fact[syoko+(n-1)] * comb.inv_fact[syoko-1]
print((ans % MOD)) | class Combination:
def __init__(self, n, MOD):
self.fact = [1]
for i in range(1, n + 1):
self.fact.append(self.fact[-1] * i % MOD)
self.inv_fact = [0] * (n + 1)
self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
for i in reversed(list(range(n))):
self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
self.MOD = MOD
def factorial(self, k):
"""k!を求める O(1)"""
return self.fact[k]
q = int(eval(input()))
info = [list(map(int, input().split())) for i in range(q)]
MOD = 1000003
comb = Combination(MOD, MOD)
for x, d, n in info:
if d == 0:
ans = pow(x, n, MOD)
print(ans)
continue
ans = pow(d, n, MOD)
x_d = x * pow(d, MOD - 2, MOD) % MOD
# x_d * (x_d + 1) * (x_d + 2) * ... *(x_d + n - 1)
tmp = comb.factorial(min(x_d + n - 1, MOD)) * pow(comb.factorial(x_d - 1), MOD - 2, MOD)
ans *= tmp
print((ans % MOD))
| 40 | 33 | 1,109 | 981 | class Combination:
"""
計算量:階乗・逆元テーブルの作成O(N)
nCkを求めるO(1)
"""
def __init__(self, n, MOD):
self.fact = [1]
for i in range(1, n + 1):
self.fact.append(self.fact[-1] * i % MOD)
self.inv_fact = [pow(self.fact[i], MOD - 2, MOD) for i in range(n + 1)]
self.MOD = MOD
def factorial(self, k):
"""k!を求める"""
return self.fact[k]
def inverse_factorial(self, k):
"""k!の逆元を求める"""
return self.inv_fact[k]
def combination(self, k, r):
"""kCrを求める"""
return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD
q = int(eval(input()))
MOD = 10**6 + 3
comb = Combination(MOD, MOD)
for i in range(q):
a1, d, n = list(map(int, input().split()))
if d == 0:
print((pow(a1, n, MOD)))
continue
syoko = a1 * (comb.inv_fact[d] * comb.fact[d - 1])
syoko %= MOD
if syoko == 0 or syoko + (n - 1) >= MOD:
print((0))
else:
ans = pow(d, n, MOD) * comb.fact[syoko + (n - 1)] * comb.inv_fact[syoko - 1]
print((ans % MOD))
| class Combination:
def __init__(self, n, MOD):
self.fact = [1]
for i in range(1, n + 1):
self.fact.append(self.fact[-1] * i % MOD)
self.inv_fact = [0] * (n + 1)
self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
for i in reversed(list(range(n))):
self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
self.MOD = MOD
def factorial(self, k):
"""k!を求める O(1)"""
return self.fact[k]
q = int(eval(input()))
info = [list(map(int, input().split())) for i in range(q)]
MOD = 1000003
comb = Combination(MOD, MOD)
for x, d, n in info:
if d == 0:
ans = pow(x, n, MOD)
print(ans)
continue
ans = pow(d, n, MOD)
x_d = x * pow(d, MOD - 2, MOD) % MOD
# x_d * (x_d + 1) * (x_d + 2) * ... *(x_d + n - 1)
tmp = comb.factorial(min(x_d + n - 1, MOD)) * pow(
comb.factorial(x_d - 1), MOD - 2, MOD
)
ans *= tmp
print((ans % MOD))
| false | 17.5 | [
"- \"\"\"",
"- 計算量:階乗・逆元テーブルの作成O(N)",
"- nCkを求めるO(1)",
"- \"\"\"",
"-",
"- self.inv_fact = [pow(self.fact[i], MOD - 2, MOD) for i in range(n + 1)]",
"+ self.inv_fact = [0] * (n + 1)",
"+ self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)",
"+ for i in reversed(list(range(n))):",
"+ self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD",
"- \"\"\"k!を求める\"\"\"",
"+ \"\"\"k!を求める O(1)\"\"\"",
"-",
"- def inverse_factorial(self, k):",
"- \"\"\"k!の逆元を求める\"\"\"",
"- return self.inv_fact[k]",
"-",
"- def combination(self, k, r):",
"- \"\"\"kCrを求める\"\"\"",
"- return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD",
"-MOD = 10**6 + 3",
"+info = [list(map(int, input().split())) for i in range(q)]",
"+MOD = 1000003",
"-for i in range(q):",
"- a1, d, n = list(map(int, input().split()))",
"+for x, d, n in info:",
"- print((pow(a1, n, MOD)))",
"+ ans = pow(x, n, MOD)",
"+ print(ans)",
"- syoko = a1 * (comb.inv_fact[d] * comb.fact[d - 1])",
"- syoko %= MOD",
"- if syoko == 0 or syoko + (n - 1) >= MOD:",
"- print((0))",
"- else:",
"- ans = pow(d, n, MOD) * comb.fact[syoko + (n - 1)] * comb.inv_fact[syoko - 1]",
"- print((ans % MOD))",
"+ ans = pow(d, n, MOD)",
"+ x_d = x * pow(d, MOD - 2, MOD) % MOD",
"+ # x_d * (x_d + 1) * (x_d + 2) * ... *(x_d + n - 1)",
"+ tmp = comb.factorial(min(x_d + n - 1, MOD)) * pow(",
"+ comb.factorial(x_d - 1), MOD - 2, MOD",
"+ )",
"+ ans *= tmp",
"+ print((ans % MOD))"
] | false | 3.806618 | 1.534045 | 2.481426 | [
"s719891765",
"s472042129"
] |
u545368057 | p03061 | python | s366579372 | s386676689 | 856 | 306 | 82,668 | 14,588 | Accepted | Accepted | 64.25 | # from math import gcd
import sys
input = sys.stdin.readline
n = int(eval(input()))
As = list(map(int, input().split()))
def gcd(n, m):
# 最大公約数
a = max(n,m)
b = min(n,m)
while b:
a, b = b, a % b
return a
class segmented_tree:
X_unit = 1 << 30
X_f = lambda self, a, b: gcd(a,b)
def __init__(self, N):
self.N = N
self.X = [self.X_unit] * (2*N)
def build(self, seq):
for i, x in enumerate(seq, self.N):
self.X[i] = x
# 後ろから入れていく
for i in range(self.N-1, 0, -1):
self.X[i] = self.X_f(self.X[i<<1], self.X[i<<1|1])
# 1点更新
def set_val(self, i, x):
i += self.N
self.X[i] = x
while i > 1:
i >>= 1
self.X[i] = self.X_f(self.X[i<<1],self.X[i<<1|1])
# 区間取得
def fold(self, l, r):
l += self.N
r += self.N
vl = self.X[l]
vr = self.X[r-1]
# 外から決めていく
while l < r:
# print(l,r)
if l & 1:
vl = self.X_f(vl, self.X[l])
l += 1
if r & 1:
r -= 1
vr = self.X_f(vr, self.X[r])
l >>= 1
r >>= 1
return self.X_f(vl,vr)
st = segmented_tree(n)
st.build(As)
mx = 0
for i in range(n):
if i == 0:
a = st.fold(i+1,n)
else:
a = st.fold(0,i)
if i+1 < n:
b = st.fold(i+1,n)
else:
b = a
mx = max(mx,gcd(a,b))
print(mx) | """
左右の累積gcdをもたせて置く
i番目を除く(i=1)
R : acc[i-1]
L : racc[n-i-1]
"""
n = int(eval(input()))
As = list(map(int, input().split()))
def gcd(n, m):
a = max(n,m)
b = min(n,m)
while b:
a, b = b, a % b
return a
acc = [As[0]]
racc = [As[-1]] #(右から)i番目の累積gcd
for i in range(1,n):
acc.append(gcd(acc[i-1],As[i]))
racc.append(gcd(racc[i-1],As[-i-1]))
racc = racc[::-1] #i番目以降のgcd
ans = 0
for i in range(n):
if i == 0:
ans = max(ans, racc[i+1])
elif i == n-1:
ans = max(ans, acc[i-1])
else:
ans = max(ans, gcd(acc[i-1],racc[i+1]))
print(ans) | 69 | 36 | 1,576 | 634 | # from math import gcd
import sys
input = sys.stdin.readline
n = int(eval(input()))
As = list(map(int, input().split()))
def gcd(n, m):
# 最大公約数
a = max(n, m)
b = min(n, m)
while b:
a, b = b, a % b
return a
class segmented_tree:
X_unit = 1 << 30
X_f = lambda self, a, b: gcd(a, b)
def __init__(self, N):
self.N = N
self.X = [self.X_unit] * (2 * N)
def build(self, seq):
for i, x in enumerate(seq, self.N):
self.X[i] = x
# 後ろから入れていく
for i in range(self.N - 1, 0, -1):
self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])
# 1点更新
def set_val(self, i, x):
i += self.N
self.X[i] = x
while i > 1:
i >>= 1
self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])
# 区間取得
def fold(self, l, r):
l += self.N
r += self.N
vl = self.X[l]
vr = self.X[r - 1]
# 外から決めていく
while l < r:
# print(l,r)
if l & 1:
vl = self.X_f(vl, self.X[l])
l += 1
if r & 1:
r -= 1
vr = self.X_f(vr, self.X[r])
l >>= 1
r >>= 1
return self.X_f(vl, vr)
st = segmented_tree(n)
st.build(As)
mx = 0
for i in range(n):
if i == 0:
a = st.fold(i + 1, n)
else:
a = st.fold(0, i)
if i + 1 < n:
b = st.fold(i + 1, n)
else:
b = a
mx = max(mx, gcd(a, b))
print(mx)
| """
左右の累積gcdをもたせて置く
i番目を除く(i=1)
R : acc[i-1]
L : racc[n-i-1]
"""
n = int(eval(input()))
As = list(map(int, input().split()))
def gcd(n, m):
a = max(n, m)
b = min(n, m)
while b:
a, b = b, a % b
return a
acc = [As[0]]
racc = [As[-1]] # (右から)i番目の累積gcd
for i in range(1, n):
acc.append(gcd(acc[i - 1], As[i]))
racc.append(gcd(racc[i - 1], As[-i - 1]))
racc = racc[::-1] # i番目以降のgcd
ans = 0
for i in range(n):
if i == 0:
ans = max(ans, racc[i + 1])
elif i == n - 1:
ans = max(ans, acc[i - 1])
else:
ans = max(ans, gcd(acc[i - 1], racc[i + 1]))
print(ans)
| false | 47.826087 | [
"-# from math import gcd",
"-import sys",
"-",
"-input = sys.stdin.readline",
"+\"\"\"",
"+左右の累積gcdをもたせて置く",
"+i番目を除く(i=1)",
"+R : acc[i-1]",
"+L : racc[n-i-1]",
"+\"\"\"",
"- # 最大公約数",
"-class segmented_tree:",
"- X_unit = 1 << 30",
"- X_f = lambda self, a, b: gcd(a, b)",
"-",
"- def __init__(self, N):",
"- self.N = N",
"- self.X = [self.X_unit] * (2 * N)",
"-",
"- def build(self, seq):",
"- for i, x in enumerate(seq, self.N):",
"- self.X[i] = x",
"- # 後ろから入れていく",
"- for i in range(self.N - 1, 0, -1):",
"- self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])",
"-",
"- # 1点更新",
"- def set_val(self, i, x):",
"- i += self.N",
"- self.X[i] = x",
"- while i > 1:",
"- i >>= 1",
"- self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])",
"-",
"- # 区間取得",
"- def fold(self, l, r):",
"- l += self.N",
"- r += self.N",
"- vl = self.X[l]",
"- vr = self.X[r - 1]",
"- # 外から決めていく",
"- while l < r:",
"- # print(l,r)",
"- if l & 1:",
"- vl = self.X_f(vl, self.X[l])",
"- l += 1",
"- if r & 1:",
"- r -= 1",
"- vr = self.X_f(vr, self.X[r])",
"- l >>= 1",
"- r >>= 1",
"- return self.X_f(vl, vr)",
"-",
"-",
"-st = segmented_tree(n)",
"-st.build(As)",
"-mx = 0",
"+acc = [As[0]]",
"+racc = [As[-1]] # (右から)i番目の累積gcd",
"+for i in range(1, n):",
"+ acc.append(gcd(acc[i - 1], As[i]))",
"+ racc.append(gcd(racc[i - 1], As[-i - 1]))",
"+racc = racc[::-1] # i番目以降のgcd",
"+ans = 0",
"- a = st.fold(i + 1, n)",
"+ ans = max(ans, racc[i + 1])",
"+ elif i == n - 1:",
"+ ans = max(ans, acc[i - 1])",
"- a = st.fold(0, i)",
"- if i + 1 < n:",
"- b = st.fold(i + 1, n)",
"- else:",
"- b = a",
"- mx = max(mx, gcd(a, b))",
"-print(mx)",
"+ ans = max(ans, gcd(acc[i - 1], racc[i + 1]))",
"+print(ans)"
] | false | 0.046775 | 0.046107 | 1.01449 | [
"s366579372",
"s386676689"
] |
u451017206 | p03215 | python | s977557137 | s986764095 | 912 | 548 | 73,952 | 55,720 | Accepted | Accepted | 39.91 | def cumsum(l):
c = [0] * len(l)
for i in range(len(l)):
c[i] = c[i-1] + l[i]
return c
N, K = list(map(int, input().split()))
a = [int(i) for i in input().split()]
c = [0] + cumsum(a)
s = {bin(c[j+i] - c[j]).replace('0b','').zfill(40) for i in range(1, N+1) for j in range(N-i+1)}
ans = 0
for i in range(40):
t = {j for j in s if j[i] == '1'}
if len(t) >= K:
ans += 2**(39-i)
s = t
print(ans) | def cumsum(l):
c = [0] * len(l)
for i in range(len(l)):
c[i] = c[i-1] + l[i]
return c
N, K = list(map(int, input().split()))
a = [int(i) for i in input().split()]
c = [0] + cumsum(a)
s = [bin(c[j+i] - c[j]).replace('0b','').zfill(40) for i in range(1, N+1) for j in range(N-i+1)]
ans = 0
for i in range(40):
t = [j for j in s if j[i] == '1']
if len(t) >= K:
ans += 2**(39-i)
s = t
print(ans) | 19 | 18 | 450 | 448 | def cumsum(l):
c = [0] * len(l)
for i in range(len(l)):
c[i] = c[i - 1] + l[i]
return c
N, K = list(map(int, input().split()))
a = [int(i) for i in input().split()]
c = [0] + cumsum(a)
s = {
bin(c[j + i] - c[j]).replace("0b", "").zfill(40)
for i in range(1, N + 1)
for j in range(N - i + 1)
}
ans = 0
for i in range(40):
t = {j for j in s if j[i] == "1"}
if len(t) >= K:
ans += 2 ** (39 - i)
s = t
print(ans)
| def cumsum(l):
c = [0] * len(l)
for i in range(len(l)):
c[i] = c[i - 1] + l[i]
return c
N, K = list(map(int, input().split()))
a = [int(i) for i in input().split()]
c = [0] + cumsum(a)
s = [
bin(c[j + i] - c[j]).replace("0b", "").zfill(40)
for i in range(1, N + 1)
for j in range(N - i + 1)
]
ans = 0
for i in range(40):
t = [j for j in s if j[i] == "1"]
if len(t) >= K:
ans += 2 ** (39 - i)
s = t
print(ans)
| false | 5.263158 | [
"-s = {",
"+s = [",
"-}",
"+]",
"- t = {j for j in s if j[i] == \"1\"}",
"+ t = [j for j in s if j[i] == \"1\"]"
] | false | 0.086488 | 0.037291 | 2.319276 | [
"s977557137",
"s986764095"
] |
u380412651 | p03044 | python | s078724210 | s184433387 | 909 | 564 | 147,248 | 79,428 | Accepted | Accepted | 37.95 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
def dfs(v, p, c):
color[v] = c
for e in graph[v]:
if e[0] == p: continue
if e[1] % 2: dfs(e[0], v, 1-c)
else: dfs(e[0], v, c)
n = int(eval(input()))
color = [-1 for _ in range(n)]
graph = [[] for _ in range(n)]
for i in range(n-1):
u, v, w = [int(x) for x in input().split()]
u, v = u - 1, v - 1
graph[u].append((v, w))
graph[v].append((u, w))
dfs(0, -1, 1)
for i in range(n):
print((color[i])) | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5)
def dfs(v, p, c):
color[v] = c
for e in graph[v]:
if e[0] == p: continue
if e[1] % 2: dfs(e[0], v, 1-c)
else: dfs(e[0], v, c)
n = int(eval(input()))
color = [-1] * n
graph = [[] for _ in range(n)]
for _ in range(n-1):
u, v, w = [int(x) for x in input().split()]
u, v = u-1, v-1
graph[u].append((v, w))
graph[v].append((u, w))
dfs(0, -1, 1)
for c in color: print(c) | 25 | 24 | 535 | 503 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
def dfs(v, p, c):
color[v] = c
for e in graph[v]:
if e[0] == p:
continue
if e[1] % 2:
dfs(e[0], v, 1 - c)
else:
dfs(e[0], v, c)
n = int(eval(input()))
color = [-1 for _ in range(n)]
graph = [[] for _ in range(n)]
for i in range(n - 1):
u, v, w = [int(x) for x in input().split()]
u, v = u - 1, v - 1
graph[u].append((v, w))
graph[v].append((u, w))
dfs(0, -1, 1)
for i in range(n):
print((color[i]))
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)
def dfs(v, p, c):
color[v] = c
for e in graph[v]:
if e[0] == p:
continue
if e[1] % 2:
dfs(e[0], v, 1 - c)
else:
dfs(e[0], v, c)
n = int(eval(input()))
color = [-1] * n
graph = [[] for _ in range(n)]
for _ in range(n - 1):
u, v, w = [int(x) for x in input().split()]
u, v = u - 1, v - 1
graph[u].append((v, w))
graph[v].append((u, w))
dfs(0, -1, 1)
for c in color:
print(c)
| false | 4 | [
"-sys.setrecursionlimit(100000)",
"+sys.setrecursionlimit(10**5)",
"-color = [-1 for _ in range(n)]",
"+color = [-1] * n",
"-for i in range(n - 1):",
"+for _ in range(n - 1):",
"-for i in range(n):",
"- print((color[i]))",
"+for c in color:",
"+ print(c)"
] | false | 0.15554 | 0.073654 | 2.111755 | [
"s078724210",
"s184433387"
] |
u466335531 | p03329 | python | s955162043 | s366481587 | 655 | 527 | 118,876 | 115,932 | Accepted | Accepted | 19.54 | six=[6**i for i in range(1,7)][::-1]
nine=[9**i for i in range(1,6)][::-1]
N=int(eval(input()))
ans=[]
def find(n,a):
if n<6: ans.append(n+a)
for s in six:
if s<=n:
find(n-s,a+1)
break
for s in nine:
if s<=n:
find(n-s,a+1)
break
find(N,0)
print((min(ans))) | six=[6**i for i in range(1,7)][::-1]
nine=[9**i for i in range(1,6)][::-1]
N=int(eval(input()))
ans=[]
def find(n,a):
if n<6:
ans.append(n+a)
return
for s in six:
if s<=n:
find(n-s,a+1)
break
for s in nine:
if s<=n:
find(n-s,a+1)
break
find(N,0)
print((min(ans))) | 17 | 19 | 341 | 366 | six = [6**i for i in range(1, 7)][::-1]
nine = [9**i for i in range(1, 6)][::-1]
N = int(eval(input()))
ans = []
def find(n, a):
if n < 6:
ans.append(n + a)
for s in six:
if s <= n:
find(n - s, a + 1)
break
for s in nine:
if s <= n:
find(n - s, a + 1)
break
find(N, 0)
print((min(ans)))
| six = [6**i for i in range(1, 7)][::-1]
nine = [9**i for i in range(1, 6)][::-1]
N = int(eval(input()))
ans = []
def find(n, a):
if n < 6:
ans.append(n + a)
return
for s in six:
if s <= n:
find(n - s, a + 1)
break
for s in nine:
if s <= n:
find(n - s, a + 1)
break
find(N, 0)
print((min(ans)))
| false | 10.526316 | [
"+ return"
] | false | 0.55617 | 0.086803 | 6.407252 | [
"s955162043",
"s366481587"
] |
u715329136 | p02600 | python | s597496426 | s076836490 | 33 | 27 | 9,192 | 9,160 | Accepted | Accepted | 18.18 | rate = int(eval(input()))
k = '1'
if (400 <= rate < 600):
k = '8'
elif (600 <= rate < 800):
k = '7'
elif (800 <= rate < 1000):
k = '6'
elif (1000 <= rate < 1200):
k = '5'
elif (1200 <= rate < 1400):
k = '4'
elif (1400 <= rate < 1600):
k = '3'
elif (1600 <= rate < 1800):
k = '2'
elif (1800 <= rate < 2000):
k = '1'
print(k)
| def resolve():
rate = int(eval(input()))
if rate < 600:
print('8')
elif rate < 800:
print('7')
elif rate < 1000:
print('6')
elif rate < 1200:
print('5')
elif rate < 1400:
print('4')
elif rate < 1600:
print('3')
elif rate < 1800:
print('2')
else:
print('1')
if __name__ == "__main__":
resolve() | 19 | 21 | 368 | 412 | rate = int(eval(input()))
k = "1"
if 400 <= rate < 600:
k = "8"
elif 600 <= rate < 800:
k = "7"
elif 800 <= rate < 1000:
k = "6"
elif 1000 <= rate < 1200:
k = "5"
elif 1200 <= rate < 1400:
k = "4"
elif 1400 <= rate < 1600:
k = "3"
elif 1600 <= rate < 1800:
k = "2"
elif 1800 <= rate < 2000:
k = "1"
print(k)
| def resolve():
rate = int(eval(input()))
if rate < 600:
print("8")
elif rate < 800:
print("7")
elif rate < 1000:
print("6")
elif rate < 1200:
print("5")
elif rate < 1400:
print("4")
elif rate < 1600:
print("3")
elif rate < 1800:
print("2")
else:
print("1")
if __name__ == "__main__":
resolve()
| false | 9.52381 | [
"-rate = int(eval(input()))",
"-k = \"1\"",
"-if 400 <= rate < 600:",
"- k = \"8\"",
"-elif 600 <= rate < 800:",
"- k = \"7\"",
"-elif 800 <= rate < 1000:",
"- k = \"6\"",
"-elif 1000 <= rate < 1200:",
"- k = \"5\"",
"-elif 1200 <= rate < 1400:",
"- k = \"4\"",
"-elif 1400 <= rate < 1600:",
"- k = \"3\"",
"-elif 1600 <= rate < 1800:",
"- k = \"2\"",
"-elif 1800 <= rate < 2000:",
"- k = \"1\"",
"-print(k)",
"+def resolve():",
"+ rate = int(eval(input()))",
"+ if rate < 600:",
"+ print(\"8\")",
"+ elif rate < 800:",
"+ print(\"7\")",
"+ elif rate < 1000:",
"+ print(\"6\")",
"+ elif rate < 1200:",
"+ print(\"5\")",
"+ elif rate < 1400:",
"+ print(\"4\")",
"+ elif rate < 1600:",
"+ print(\"3\")",
"+ elif rate < 1800:",
"+ print(\"2\")",
"+ else:",
"+ print(\"1\")",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ resolve()"
] | false | 0.038606 | 0.035295 | 1.093793 | [
"s597496426",
"s076836490"
] |
u379692329 | p03329 | python | s770077782 | s295798742 | 1,467 | 544 | 3,828 | 3,828 | Accepted | Accepted | 62.92 | N = int(eval(input()))
dp = [N] * (N+1)
dp[0] = 0
for i in range(1, N+1):
pow6 = []
pow9 = []
for j in range(i):
if 6**j > i:
break
pow6.append(6**j)
for k in range(i):
if 9**k > i:
break
pow9.append(9**k)
L = set(pow6 + pow9)
for l in L:
if i-l < 0:
break
dp[i] = min(dp[i], dp[i-l]+1)
print((dp[N])) | N = int(eval(input()))
INF = 10**9
dp = [INF]*(N+1)
dp[0] = 0
num6 = [6**i for i in range(1, 10)]
num9 = [9**i for i in range(1, 7)]
S = sorted([1] + num6 + num9)
for i in range(1, N+1):
tmp = INF
for j in S:
if j > i:
break
else:
dp[i] = min(tmp, dp[i-j]+1)
tmp = dp[i]
print((dp[N])) | 23 | 18 | 430 | 356 | N = int(eval(input()))
dp = [N] * (N + 1)
dp[0] = 0
for i in range(1, N + 1):
pow6 = []
pow9 = []
for j in range(i):
if 6**j > i:
break
pow6.append(6**j)
for k in range(i):
if 9**k > i:
break
pow9.append(9**k)
L = set(pow6 + pow9)
for l in L:
if i - l < 0:
break
dp[i] = min(dp[i], dp[i - l] + 1)
print((dp[N]))
| N = int(eval(input()))
INF = 10**9
dp = [INF] * (N + 1)
dp[0] = 0
num6 = [6**i for i in range(1, 10)]
num9 = [9**i for i in range(1, 7)]
S = sorted([1] + num6 + num9)
for i in range(1, N + 1):
tmp = INF
for j in S:
if j > i:
break
else:
dp[i] = min(tmp, dp[i - j] + 1)
tmp = dp[i]
print((dp[N]))
| false | 21.73913 | [
"-dp = [N] * (N + 1)",
"+INF = 10**9",
"+dp = [INF] * (N + 1)",
"+num6 = [6**i for i in range(1, 10)]",
"+num9 = [9**i for i in range(1, 7)]",
"+S = sorted([1] + num6 + num9)",
"- pow6 = []",
"- pow9 = []",
"- for j in range(i):",
"- if 6**j > i:",
"+ tmp = INF",
"+ for j in S:",
"+ if j > i:",
"- pow6.append(6**j)",
"- for k in range(i):",
"- if 9**k > i:",
"- break",
"- pow9.append(9**k)",
"- L = set(pow6 + pow9)",
"- for l in L:",
"- if i - l < 0:",
"- break",
"- dp[i] = min(dp[i], dp[i - l] + 1)",
"+ else:",
"+ dp[i] = min(tmp, dp[i - j] + 1)",
"+ tmp = dp[i]"
] | false | 0.643657 | 0.098083 | 6.562368 | [
"s770077782",
"s295798742"
] |
u462329577 | p02624 | python | s177826010 | s885244894 | 34 | 30 | 9,172 | 9,068 | Accepted | Accepted | 11.76 | #!/usr/bin/env python3
# input
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(eval(input()))
ans = n * (n + 1) - 1 # 1とk 自信
i = 2
while i * i <= n:
num = n // i
min_i = i * i
max_i = i * num
ans += (num - i + 1) * (min_i + max_i) # 自分自身
ans -= min_i
i += 1
print(ans)
| #!/usr/bin/env python3
# input
n = int(eval(input()))
ans = n * (n + 1) - 1 # 1とk 自信
i = 2
while i * i <= n:
num = n // i
min_i = i * i
max_i = i * num
ans += (num - i + 1) * (min_i + max_i) # 自分自身
ans -= min_i
i += 1
print(ans)
| 19 | 15 | 385 | 265 | #!/usr/bin/env python3
# input
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(eval(input()))
ans = n * (n + 1) - 1 # 1とk 自信
i = 2
while i * i <= n:
num = n // i
min_i = i * i
max_i = i * num
ans += (num - i + 1) * (min_i + max_i) # 自分自身
ans -= min_i
i += 1
print(ans)
| #!/usr/bin/env python3
# input
n = int(eval(input()))
ans = n * (n + 1) - 1 # 1とk 自信
i = 2
while i * i <= n:
num = n // i
min_i = i * i
max_i = i * num
ans += (num - i + 1) * (min_i + max_i) # 自分自身
ans -= min_i
i += 1
print(ans)
| false | 21.052632 | [
"-import sys",
"-",
"-read = sys.stdin.buffer.read",
"-readline = sys.stdin.buffer.readline",
"-readlines = sys.stdin.buffer.readlines"
] | false | 0.098906 | 0.162795 | 0.607553 | [
"s177826010",
"s885244894"
] |
u539367121 | p02901 | python | s030064403 | s740135615 | 1,609 | 1,026 | 9,260 | 9,392 | Accepted | Accepted | 36.23 | n,m=list(map(int,input().split()))
inf=10**9
cost=[inf for i in range(m)]
for i in range(m):
a,b=list(map(int,input().split()))
c=[int(x)-1 for x in input().split()]
s=0
for j in c:
s|=1<<j
cost[i]=[s,a]
#print(cost)
dp=[inf]*(1<<n)
dp[0]=0
for s in range(1<<n):
for bit,c in cost:
dp[s|bit]=min(dp[s|bit], dp[s]+c)
#print(dp)
print((-1 if dp[-1]==inf else dp[-1]))
| def main():
n,m=list(map(int,input().split()))
inf=10**9
cost=[inf for i in range(m)]
for i in range(m):
a,b=list(map(int,input().split()))
c=[int(x)-1 for x in input().split()]
s=0
for j in c:
s|=1<<j
cost[i]=[s,a]
#print(cost)
dp=[inf]*(1<<n)
dp[0]=0
for s in range(1<<n):
for bit,c in cost:
dp[s|bit]=min(dp[s|bit], dp[s]+c)
#print(dp)
print((-1 if dp[-1]==inf else dp[-1]))
if __name__=='__main__':
main() | 20 | 23 | 393 | 477 | n, m = list(map(int, input().split()))
inf = 10**9
cost = [inf for i in range(m)]
for i in range(m):
a, b = list(map(int, input().split()))
c = [int(x) - 1 for x in input().split()]
s = 0
for j in c:
s |= 1 << j
cost[i] = [s, a]
# print(cost)
dp = [inf] * (1 << n)
dp[0] = 0
for s in range(1 << n):
for bit, c in cost:
dp[s | bit] = min(dp[s | bit], dp[s] + c)
# print(dp)
print((-1 if dp[-1] == inf else dp[-1]))
| def main():
n, m = list(map(int, input().split()))
inf = 10**9
cost = [inf for i in range(m)]
for i in range(m):
a, b = list(map(int, input().split()))
c = [int(x) - 1 for x in input().split()]
s = 0
for j in c:
s |= 1 << j
cost[i] = [s, a]
# print(cost)
dp = [inf] * (1 << n)
dp[0] = 0
for s in range(1 << n):
for bit, c in cost:
dp[s | bit] = min(dp[s | bit], dp[s] + c)
# print(dp)
print((-1 if dp[-1] == inf else dp[-1]))
if __name__ == "__main__":
main()
| false | 13.043478 | [
"-n, m = list(map(int, input().split()))",
"-inf = 10**9",
"-cost = [inf for i in range(m)]",
"-for i in range(m):",
"- a, b = list(map(int, input().split()))",
"- c = [int(x) - 1 for x in input().split()]",
"- s = 0",
"- for j in c:",
"- s |= 1 << j",
"- cost[i] = [s, a]",
"-# print(cost)",
"-dp = [inf] * (1 << n)",
"-dp[0] = 0",
"-for s in range(1 << n):",
"- for bit, c in cost:",
"- dp[s | bit] = min(dp[s | bit], dp[s] + c)",
"-# print(dp)",
"-print((-1 if dp[-1] == inf else dp[-1]))",
"+def main():",
"+ n, m = list(map(int, input().split()))",
"+ inf = 10**9",
"+ cost = [inf for i in range(m)]",
"+ for i in range(m):",
"+ a, b = list(map(int, input().split()))",
"+ c = [int(x) - 1 for x in input().split()]",
"+ s = 0",
"+ for j in c:",
"+ s |= 1 << j",
"+ cost[i] = [s, a]",
"+ # print(cost)",
"+ dp = [inf] * (1 << n)",
"+ dp[0] = 0",
"+ for s in range(1 << n):",
"+ for bit, c in cost:",
"+ dp[s | bit] = min(dp[s | bit], dp[s] + c)",
"+ # print(dp)",
"+ print((-1 if dp[-1] == inf else dp[-1]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.048421 | 0.038042 | 1.272824 | [
"s030064403",
"s740135615"
] |
u745087332 | p03255 | python | s027381814 | s069312828 | 1,994 | 1,061 | 30,572 | 25,708 | Accepted | Accepted | 46.79 | # coding:utf-8
INF = float('inf')
def inpl(): return list(map(int, input().split()))
N, X = inpl()
A = inpl()
B = [0]
for a in A:
B.append(B[-1] + a)
ans = []
for k in range(1, N + 1):
e = 5
cur = N - k
tmp = e * (B[N] - B[cur]) + (N + k) * X
cur -= k
while True:
tmp += e * (B[cur + k] - B[max(cur, 0)])
if cur <= 0:
break
e += 2
cur -= k
ans.append(tmp)
print((min(ans))) | # coding:utf-8
INF = float('inf')
def inpl(): return list(map(int, input().split()))
N, X = inpl()
A = inpl()
B = [0]
for a in A:
B.append(B[-1] + a)
ans = INF
for k in range(1, N + 1):
tmp = 5 * B[N] + (N + k) * X
cur = N - 2 * k
while cur > 0:
tmp += 2 * B[cur]
cur -= k
ans = min(ans, tmp)
print(ans)
| 31 | 24 | 482 | 370 | # coding:utf-8
INF = float("inf")
def inpl():
return list(map(int, input().split()))
N, X = inpl()
A = inpl()
B = [0]
for a in A:
B.append(B[-1] + a)
ans = []
for k in range(1, N + 1):
e = 5
cur = N - k
tmp = e * (B[N] - B[cur]) + (N + k) * X
cur -= k
while True:
tmp += e * (B[cur + k] - B[max(cur, 0)])
if cur <= 0:
break
e += 2
cur -= k
ans.append(tmp)
print((min(ans)))
| # coding:utf-8
INF = float("inf")
def inpl():
return list(map(int, input().split()))
N, X = inpl()
A = inpl()
B = [0]
for a in A:
B.append(B[-1] + a)
ans = INF
for k in range(1, N + 1):
tmp = 5 * B[N] + (N + k) * X
cur = N - 2 * k
while cur > 0:
tmp += 2 * B[cur]
cur -= k
ans = min(ans, tmp)
print(ans)
| false | 22.580645 | [
"-ans = []",
"+ans = INF",
"- e = 5",
"- cur = N - k",
"- tmp = e * (B[N] - B[cur]) + (N + k) * X",
"- cur -= k",
"- while True:",
"- tmp += e * (B[cur + k] - B[max(cur, 0)])",
"- if cur <= 0:",
"- break",
"- e += 2",
"+ tmp = 5 * B[N] + (N + k) * X",
"+ cur = N - 2 * k",
"+ while cur > 0:",
"+ tmp += 2 * B[cur]",
"- ans.append(tmp)",
"-print((min(ans)))",
"+ ans = min(ans, tmp)",
"+print(ans)"
] | false | 0.035285 | 0.035684 | 0.988832 | [
"s027381814",
"s069312828"
] |
u279493135 | p02691 | python | s668639742 | s085274801 | 221 | 165 | 35,812 | 138,200 | Accepted | Accepted | 25.34 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
A = [x-i for i, x in enumerate(A)]
cnt_A = Counter(A)
ans = 0
for i, a in enumerate(A):
ans += cnt_A[-A[i]-2*i]
print(ans)
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
L = [i+x for i, x in enumerate(A)]
R = [i-x for i, x in enumerate(A)]
cnt_R = Counter(R)
ans = 0
for l in L:
ans += cnt_R[l]
print(ans)
| 29 | 30 | 951 | 962 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import (
accumulate,
permutations,
combinations,
product,
groupby,
combinations_with_replacement,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
A = LIST()
A = [x - i for i, x in enumerate(A)]
cnt_A = Counter(A)
ans = 0
for i, a in enumerate(A):
ans += cnt_A[-A[i] - 2 * i]
print(ans)
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import (
accumulate,
permutations,
combinations,
product,
groupby,
combinations_with_replacement,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
A = LIST()
L = [i + x for i, x in enumerate(A)]
R = [i - x for i, x in enumerate(A)]
cnt_R = Counter(R)
ans = 0
for l in L:
ans += cnt_R[l]
print(ans)
| false | 3.333333 | [
"-A = [x - i for i, x in enumerate(A)]",
"-cnt_A = Counter(A)",
"+L = [i + x for i, x in enumerate(A)]",
"+R = [i - x for i, x in enumerate(A)]",
"+cnt_R = Counter(R)",
"-for i, a in enumerate(A):",
"- ans += cnt_A[-A[i] - 2 * i]",
"+for l in L:",
"+ ans += cnt_R[l]"
] | false | 0.03717 | 0.03741 | 0.993572 | [
"s668639742",
"s085274801"
] |
u146803137 | p02959 | python | s824582435 | s774440626 | 275 | 151 | 86,748 | 24,232 | Accepted | Accepted | 45.09 | import math
import re
import copy
import sys
n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
for i in range(n):
c += min(a[i],b[i])
if a[i] < b[i]:
c += min(a[i+1],b[i]-a[i])
a[i+1] -= min(a[i+1],b[i]-a[i])
print(c) | n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n-1,-1,-1):
ans += min(a[i]+a[i+1],b[i])
a[i] = max(a[i]-max(b[i]-a[i+1],0),0)
print(ans)
| 17 | 8 | 303 | 215 | import math
import re
import copy
import sys
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
for i in range(n):
c += min(a[i], b[i])
if a[i] < b[i]:
c += min(a[i + 1], b[i] - a[i])
a[i + 1] -= min(a[i + 1], b[i] - a[i])
print(c)
| n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n - 1, -1, -1):
ans += min(a[i] + a[i + 1], b[i])
a[i] = max(a[i] - max(b[i] - a[i + 1], 0), 0)
print(ans)
| false | 52.941176 | [
"-import math",
"-import re",
"-import copy",
"-import sys",
"-",
"-c = 0",
"-for i in range(n):",
"- c += min(a[i], b[i])",
"- if a[i] < b[i]:",
"- c += min(a[i + 1], b[i] - a[i])",
"- a[i + 1] -= min(a[i + 1], b[i] - a[i])",
"-print(c)",
"+ans = 0",
"+for i in range(n - 1, -1, -1):",
"+ ans += min(a[i] + a[i + 1], b[i])",
"+ a[i] = max(a[i] - max(b[i] - a[i + 1], 0), 0)",
"+print(ans)"
] | false | 0.096626 | 0.045171 | 2.139118 | [
"s824582435",
"s774440626"
] |
u197968862 | p03160 | python | s201163850 | s185454786 | 234 | 99 | 52,208 | 85,732 | Accepted | Accepted | 57.69 | n = int(eval(input()))
h = list(map(int,input().split()))
dp = [0] * n
for i in range(1,n):
if i == 1:
dp[i] = abs(h[i]-h[0])
continue
dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print((dp[-1])) | n = int(eval(input()))
h = list(map(int, input().split()))
dp = [float('inf')] * n
dp[0] = 0
for i in range(n):
if i < n - 2:
dp[i+2] = min(dp[i+2], dp[i]+abs(h[i] - h[i+2]))
dp[i+1] = min(dp[i+1], dp[i]+abs(h[i] - h[i+1]))
elif i == n - 2:
dp[i+1] = min(dp[i+1], dp[i]+abs(h[i] - h[i+1]))
print((dp[-1])) | 11 | 14 | 241 | 345 | n = int(eval(input()))
h = list(map(int, input().split()))
dp = [0] * n
for i in range(1, n):
if i == 1:
dp[i] = abs(h[i] - h[0])
continue
dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[-1]))
| n = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("inf")] * n
dp[0] = 0
for i in range(n):
if i < n - 2:
dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
elif i == n - 2:
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
print((dp[-1]))
| false | 21.428571 | [
"-dp = [0] * n",
"-for i in range(1, n):",
"- if i == 1:",
"- dp[i] = abs(h[i] - h[0])",
"- continue",
"- dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))",
"+dp = [float(\"inf\")] * n",
"+dp[0] = 0",
"+for i in range(n):",
"+ if i < n - 2:",
"+ dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))",
"+ dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))",
"+ elif i == n - 2:",
"+ dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))"
] | false | 0.04188 | 0.03968 | 1.055441 | [
"s201163850",
"s185454786"
] |
u910756197 | p03607 | python | s364089600 | s093368771 | 224 | 187 | 15,460 | 14,700 | Accepted | Accepted | 16.52 | from collections import defaultdict
def solve():
dic = defaultdict(int)
n = int(eval(input()))
ans = 0
for _ in range(n):
a = int(eval(input()))
dic[a] = (dic[a] + 1) % 2
print((sum(dic.values())))
if __name__ == '__main__':
solve() | n = int(eval(input()))
s = set()
for _ in range(n):
s ^= {eval(input())}
print((len(s))) | 13 | 5 | 272 | 82 | from collections import defaultdict
def solve():
dic = defaultdict(int)
n = int(eval(input()))
ans = 0
for _ in range(n):
a = int(eval(input()))
dic[a] = (dic[a] + 1) % 2
print((sum(dic.values())))
if __name__ == "__main__":
solve()
| n = int(eval(input()))
s = set()
for _ in range(n):
s ^= {eval(input())}
print((len(s)))
| false | 61.538462 | [
"-from collections import defaultdict",
"-",
"-",
"-def solve():",
"- dic = defaultdict(int)",
"- n = int(eval(input()))",
"- ans = 0",
"- for _ in range(n):",
"- a = int(eval(input()))",
"- dic[a] = (dic[a] + 1) % 2",
"- print((sum(dic.values())))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- solve()",
"+n = int(eval(input()))",
"+s = set()",
"+for _ in range(n):",
"+ s ^= {eval(input())}",
"+print((len(s)))"
] | false | 0.061952 | 0.113161 | 0.547468 | [
"s364089600",
"s093368771"
] |
u759412327 | p03487 | python | s193514189 | s794308628 | 79 | 72 | 20,600 | 22,368 | Accepted | Accepted | 8.86 | N = int(eval(input()))
A = list(map(int,input().split()))
B = (10**5+1)*[0]
ans = 0
for a in A:
if a<=10**5:
B[a]+=1
else:
ans+=1
for n in range(10**5):
if B[n]<n:
ans+=B[n]
elif n<B[n]:
ans+=B[n]-n
print(ans) | from collections import *
N = int(eval(input()))
C = Counter(list(map(int,input().split())))
ans = 0
for k,v in list(C.items()):
if k<v:
ans+=v-k
elif v<k:
ans+=v
print(ans) | 18 | 12 | 247 | 186 | N = int(eval(input()))
A = list(map(int, input().split()))
B = (10**5 + 1) * [0]
ans = 0
for a in A:
if a <= 10**5:
B[a] += 1
else:
ans += 1
for n in range(10**5):
if B[n] < n:
ans += B[n]
elif n < B[n]:
ans += B[n] - n
print(ans)
| from collections import *
N = int(eval(input()))
C = Counter(list(map(int, input().split())))
ans = 0
for k, v in list(C.items()):
if k < v:
ans += v - k
elif v < k:
ans += v
print(ans)
| false | 33.333333 | [
"+from collections import *",
"+",
"-A = list(map(int, input().split()))",
"-B = (10**5 + 1) * [0]",
"+C = Counter(list(map(int, input().split())))",
"-for a in A:",
"- if a <= 10**5:",
"- B[a] += 1",
"- else:",
"- ans += 1",
"-for n in range(10**5):",
"- if B[n] < n:",
"- ans += B[n]",
"- elif n < B[n]:",
"- ans += B[n] - n",
"+for k, v in list(C.items()):",
"+ if k < v:",
"+ ans += v - k",
"+ elif v < k:",
"+ ans += v"
] | false | 0.073948 | 0.102306 | 0.722811 | [
"s193514189",
"s794308628"
] |
u475503988 | p02927 | python | s273187763 | s897070363 | 19 | 17 | 2,940 | 3,060 | Accepted | Accepted | 10.53 | M, D = list(map(int, input().split()))
ans = 0
for m in range(1, M+1):
for d in range(22, D+1):
d1 = d % 10
if d1 < 2: continue
d10 = d // 10
if d10 < 2: continue
if d1 * d10 == m:
ans += 1
print(ans)
| M, D = list(map(int, input().split()))
ans = 0
for d in range(22, D+1):
d1 = d % 10
if d1 < 2: continue
d10 = d // 10
if d10 < 2: continue
if d1 * d10 <= M:
ans += 1
print(ans) | 13 | 12 | 265 | 211 | M, D = list(map(int, input().split()))
ans = 0
for m in range(1, M + 1):
for d in range(22, D + 1):
d1 = d % 10
if d1 < 2:
continue
d10 = d // 10
if d10 < 2:
continue
if d1 * d10 == m:
ans += 1
print(ans)
| M, D = list(map(int, input().split()))
ans = 0
for d in range(22, D + 1):
d1 = d % 10
if d1 < 2:
continue
d10 = d // 10
if d10 < 2:
continue
if d1 * d10 <= M:
ans += 1
print(ans)
| false | 7.692308 | [
"-for m in range(1, M + 1):",
"- for d in range(22, D + 1):",
"- d1 = d % 10",
"- if d1 < 2:",
"- continue",
"- d10 = d // 10",
"- if d10 < 2:",
"- continue",
"- if d1 * d10 == m:",
"- ans += 1",
"+for d in range(22, D + 1):",
"+ d1 = d % 10",
"+ if d1 < 2:",
"+ continue",
"+ d10 = d // 10",
"+ if d10 < 2:",
"+ continue",
"+ if d1 * d10 <= M:",
"+ ans += 1"
] | false | 0.039741 | 0.039683 | 1.001463 | [
"s273187763",
"s897070363"
] |
u252828980 | p02947 | python | s525463719 | s990428240 | 362 | 227 | 19,756 | 24,068 | Accepted | Accepted | 37.29 | n = int(eval(input()))
from collections import Counter
cnt= 0
L = []
for i in range(n):
s = sorted(eval(input()))
L.append(("".join(s)))
L = Counter(L)
for v in list(L.values()):
cnt +=(v-1)*v//2
print(cnt) | n = int(eval(input()))
L = ["".join(sorted(eval(input()))) for i in range(n)]
from collections import Counter
L = Counter(L)
def num(n):
return n*(n-1)//2
cnt = 0
for v in list(L.values()):
cnt +=num(v)
print(cnt) | 12 | 14 | 212 | 226 | n = int(eval(input()))
from collections import Counter
cnt = 0
L = []
for i in range(n):
s = sorted(eval(input()))
L.append(("".join(s)))
L = Counter(L)
for v in list(L.values()):
cnt += (v - 1) * v // 2
print(cnt)
| n = int(eval(input()))
L = ["".join(sorted(eval(input()))) for i in range(n)]
from collections import Counter
L = Counter(L)
def num(n):
return n * (n - 1) // 2
cnt = 0
for v in list(L.values()):
cnt += num(v)
print(cnt)
| false | 14.285714 | [
"+L = [\"\".join(sorted(eval(input()))) for i in range(n)]",
"+L = Counter(L)",
"+",
"+",
"+def num(n):",
"+ return n * (n - 1) // 2",
"+",
"+",
"-L = []",
"-for i in range(n):",
"- s = sorted(eval(input()))",
"- L.append((\"\".join(s)))",
"-L = Counter(L)",
"- cnt += (v - 1) * v // 2",
"+ cnt += num(v)"
] | false | 0.084907 | 0.067737 | 1.253486 | [
"s525463719",
"s990428240"
] |
u945228737 | p03222 | python | s739770857 | s827072647 | 35 | 32 | 9,136 | 9,228 | Accepted | Accepted | 8.57 | # 解説と下記を参考に作成
# https://atcoder.jp/contests/abc113/submissions/15821617
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(H, W, K):
mod = 10 ** 9 + 7
dp = [[0] * W for _ in range(H + 1)]
dp[0][0] = 1
for h in range(H):
for w in range(W):
if dp[h][w] == 0:
continue
for i in range(3):
new_w = w - 1 + i
if not 0 <= new_w < W:
continue
def cnt_tmp(n, r, l, flg):
re = 0
if n >= W - 2:
if r <= n <= l:
return 1
if flg:
return 1
else:
return 2
if r <= n <= l:
return cnt_tmp(n + 1, r, l, False)
re += cnt_tmp(n + 1, r, l, False)
re += cnt_tmp(n + 1, r, l, True) if not flg else 0
return re
tmp = cnt_tmp(0, min(w, new_w) - 1, max(w, new_w), False)
dp[h + 1][new_w] += dp[h][w] * tmp
dp[h + 1][new_w] %= mod
# for dpi in dp:
# print(dpi)
print((dp[-1][K - 1]))
if __name__ == '__main__':
H, W, K = list(map(int, input().split()))
solve(H, W, K)
# # test
# from random import randint
# from func import random_str
# solve()
| # 解説と下記を参考に作成
# https://atcoder.jp/contests/abc113/submissions/15821617
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(H, W, K):
mod = 10 ** 9 + 7
dp = [[0] * W for _ in range(H + 1)]
dp[0][0] = 1
fibo = [1, 2, 3, 5, 8, 13, 21]
for h in range(H):
for w in range(W):
if dp[h][w] == 0:
continue
for i in range(3):
new_w = w - 1 + i
if not 0 <= new_w < W:
continue
l, r = min(w, new_w), max(w, new_w)
tmp = fibo[max(l - 1, 0)] * fibo[max(W - 1 - (r + 1), 0)]
dp[h + 1][new_w] += dp[h][w] * tmp
dp[h + 1][new_w] %= mod
print((dp[-1][K - 1]))
if __name__ == '__main__':
H, W, K = list(map(int, input().split()))
solve(H, W, K)
# # test
# from random import randint
# from func import random_str
# solve()
| 54 | 38 | 1,597 | 1,054 | # 解説と下記を参考に作成
# https://atcoder.jp/contests/abc113/submissions/15821617
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(H, W, K):
mod = 10**9 + 7
dp = [[0] * W for _ in range(H + 1)]
dp[0][0] = 1
for h in range(H):
for w in range(W):
if dp[h][w] == 0:
continue
for i in range(3):
new_w = w - 1 + i
if not 0 <= new_w < W:
continue
def cnt_tmp(n, r, l, flg):
re = 0
if n >= W - 2:
if r <= n <= l:
return 1
if flg:
return 1
else:
return 2
if r <= n <= l:
return cnt_tmp(n + 1, r, l, False)
re += cnt_tmp(n + 1, r, l, False)
re += cnt_tmp(n + 1, r, l, True) if not flg else 0
return re
tmp = cnt_tmp(0, min(w, new_w) - 1, max(w, new_w), False)
dp[h + 1][new_w] += dp[h][w] * tmp
dp[h + 1][new_w] %= mod
# for dpi in dp:
# print(dpi)
print((dp[-1][K - 1]))
if __name__ == "__main__":
H, W, K = list(map(int, input().split()))
solve(H, W, K)
# # test
# from random import randint
# from func import random_str
# solve()
| # 解説と下記を参考に作成
# https://atcoder.jp/contests/abc113/submissions/15821617
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(H, W, K):
mod = 10**9 + 7
dp = [[0] * W for _ in range(H + 1)]
dp[0][0] = 1
fibo = [1, 2, 3, 5, 8, 13, 21]
for h in range(H):
for w in range(W):
if dp[h][w] == 0:
continue
for i in range(3):
new_w = w - 1 + i
if not 0 <= new_w < W:
continue
l, r = min(w, new_w), max(w, new_w)
tmp = fibo[max(l - 1, 0)] * fibo[max(W - 1 - (r + 1), 0)]
dp[h + 1][new_w] += dp[h][w] * tmp
dp[h + 1][new_w] %= mod
print((dp[-1][K - 1]))
if __name__ == "__main__":
H, W, K = list(map(int, input().split()))
solve(H, W, K)
# # test
# from random import randint
# from func import random_str
# solve()
| false | 29.62963 | [
"+ fibo = [1, 2, 3, 5, 8, 13, 21]",
"-",
"- def cnt_tmp(n, r, l, flg):",
"- re = 0",
"- if n >= W - 2:",
"- if r <= n <= l:",
"- return 1",
"- if flg:",
"- return 1",
"- else:",
"- return 2",
"- if r <= n <= l:",
"- return cnt_tmp(n + 1, r, l, False)",
"- re += cnt_tmp(n + 1, r, l, False)",
"- re += cnt_tmp(n + 1, r, l, True) if not flg else 0",
"- return re",
"-",
"- tmp = cnt_tmp(0, min(w, new_w) - 1, max(w, new_w), False)",
"+ l, r = min(w, new_w), max(w, new_w)",
"+ tmp = fibo[max(l - 1, 0)] * fibo[max(W - 1 - (r + 1), 0)]",
"- # for dpi in dp:",
"- # print(dpi)"
] | false | 0.08174 | 0.140409 | 0.582155 | [
"s739770857",
"s827072647"
] |
u075012704 | p03972 | python | s318233054 | s917098359 | 711 | 501 | 27,736 | 16,512 | Accepted | Accepted | 29.54 | W, H = list(map(int, input().split()))
P = [(int(eval(input())), 0) for i in range(W)]
Q = [(int(eval(input())), 1) for i in range(H)]
E = sorted(P + Q)
used = [W + 1, H + 1]
ans = 0
for e, f in E:
ans += e * used[1 - f]
used[f] -= 1
print(ans)
| from itertools import accumulate
from bisect import bisect_left
W, H = list(map(int, input().split()))
W_cost = sorted([int(eval(input())) for i in range(W)])
H_cost = [int(eval(input())) for i in range(H)]
# 横は全部辺を張り、縦は各区間1本
W_cost_sum = sum(W_cost)
ans = W_cost_sum * (H + 1) + sum(H_cost)
W_acc_cost = [0] + list(accumulate(W_cost))
for h in H_cost:
hx = bisect_left(W_cost, h)
ans -= (W_cost_sum - W_acc_cost[hx]) - ((W - hx) * h)
print(ans)
| 13 | 18 | 250 | 458 | W, H = list(map(int, input().split()))
P = [(int(eval(input())), 0) for i in range(W)]
Q = [(int(eval(input())), 1) for i in range(H)]
E = sorted(P + Q)
used = [W + 1, H + 1]
ans = 0
for e, f in E:
ans += e * used[1 - f]
used[f] -= 1
print(ans)
| from itertools import accumulate
from bisect import bisect_left
W, H = list(map(int, input().split()))
W_cost = sorted([int(eval(input())) for i in range(W)])
H_cost = [int(eval(input())) for i in range(H)]
# 横は全部辺を張り、縦は各区間1本
W_cost_sum = sum(W_cost)
ans = W_cost_sum * (H + 1) + sum(H_cost)
W_acc_cost = [0] + list(accumulate(W_cost))
for h in H_cost:
hx = bisect_left(W_cost, h)
ans -= (W_cost_sum - W_acc_cost[hx]) - ((W - hx) * h)
print(ans)
| false | 27.777778 | [
"+from itertools import accumulate",
"+from bisect import bisect_left",
"+",
"-P = [(int(eval(input())), 0) for i in range(W)]",
"-Q = [(int(eval(input())), 1) for i in range(H)]",
"-E = sorted(P + Q)",
"-used = [W + 1, H + 1]",
"-ans = 0",
"-for e, f in E:",
"- ans += e * used[1 - f]",
"- used[f] -= 1",
"+W_cost = sorted([int(eval(input())) for i in range(W)])",
"+H_cost = [int(eval(input())) for i in range(H)]",
"+# 横は全部辺を張り、縦は各区間1本",
"+W_cost_sum = sum(W_cost)",
"+ans = W_cost_sum * (H + 1) + sum(H_cost)",
"+W_acc_cost = [0] + list(accumulate(W_cost))",
"+for h in H_cost:",
"+ hx = bisect_left(W_cost, h)",
"+ ans -= (W_cost_sum - W_acc_cost[hx]) - ((W - hx) * h)"
] | false | 0.037193 | 0.037655 | 0.987717 | [
"s318233054",
"s917098359"
] |
u488127128 | p03804 | python | s264101008 | s270487377 | 20 | 18 | 3,064 | 3,064 | Accepted | Accepted | 10 | import sys
def solve():
n,m = list(map(int, sys.stdin.readline().split()))
A = [sys.stdin.readline().rstrip() for _ in range(n)]
B = [sys.stdin.readline().rstrip() for _ in range(m)]
for r in range(n-m+1):
for c in range(n-m+1):
X = []
for a in A[r:r+m]:
X.append(a[c:c+m])
if X == B:
print('Yes')
exit()
print('No')
if __name__ == '__main__':
solve() | def solve():
n,m = list(map(int, input().split()))
A = [eval(input()) for _ in range(n)]
B = [eval(input()) for _ in range(m)]
for r in range(n-m+1):
for c in range(n-m+1):
X = []
for i,a in enumerate(A[r:r+m]):
if a[c:c+m] != B[i]:
break
else:
print('Yes')
exit()
print('No')
if __name__ == '__main__':
solve() | 18 | 17 | 480 | 446 | import sys
def solve():
n, m = list(map(int, sys.stdin.readline().split()))
A = [sys.stdin.readline().rstrip() for _ in range(n)]
B = [sys.stdin.readline().rstrip() for _ in range(m)]
for r in range(n - m + 1):
for c in range(n - m + 1):
X = []
for a in A[r : r + m]:
X.append(a[c : c + m])
if X == B:
print("Yes")
exit()
print("No")
if __name__ == "__main__":
solve()
| def solve():
n, m = list(map(int, input().split()))
A = [eval(input()) for _ in range(n)]
B = [eval(input()) for _ in range(m)]
for r in range(n - m + 1):
for c in range(n - m + 1):
X = []
for i, a in enumerate(A[r : r + m]):
if a[c : c + m] != B[i]:
break
else:
print("Yes")
exit()
print("No")
if __name__ == "__main__":
solve()
| false | 5.555556 | [
"-import sys",
"-",
"-",
"- n, m = list(map(int, sys.stdin.readline().split()))",
"- A = [sys.stdin.readline().rstrip() for _ in range(n)]",
"- B = [sys.stdin.readline().rstrip() for _ in range(m)]",
"+ n, m = list(map(int, input().split()))",
"+ A = [eval(input()) for _ in range(n)]",
"+ B = [eval(input()) for _ in range(m)]",
"- for a in A[r : r + m]:",
"- X.append(a[c : c + m])",
"- if X == B:",
"+ for i, a in enumerate(A[r : r + m]):",
"+ if a[c : c + m] != B[i]:",
"+ break",
"+ else:"
] | false | 0.04682 | 0.04561 | 1.02653 | [
"s264101008",
"s270487377"
] |
u545368057 | p03048 | python | s229858133 | s576303678 | 269 | 90 | 40,428 | 67,236 | Accepted | Accepted | 66.54 | R, B, G, N = list(map(int,input().split()))
cnt = 0
ball = 0
a = sorted([R,G,B])
for r in range(N//a[0]+1):
ball = r*a[0]
for b in range((N-ball)//a[1]+1):
if N-ball >= 0 and (N-ball-b*a[1])%a[2] == 0:
cnt += 1
print(cnt) | r,g,b,n = list(map(int, input().split()))
cnt = 0
for i in range(n+1):
for j in range(n+1):
rest = n - i*r - j*g
if rest >=0 and rest%b==0:
cnt += 1
print(cnt) | 13 | 8 | 261 | 192 | R, B, G, N = list(map(int, input().split()))
cnt = 0
ball = 0
a = sorted([R, G, B])
for r in range(N // a[0] + 1):
ball = r * a[0]
for b in range((N - ball) // a[1] + 1):
if N - ball >= 0 and (N - ball - b * a[1]) % a[2] == 0:
cnt += 1
print(cnt)
| r, g, b, n = list(map(int, input().split()))
cnt = 0
for i in range(n + 1):
for j in range(n + 1):
rest = n - i * r - j * g
if rest >= 0 and rest % b == 0:
cnt += 1
print(cnt)
| false | 38.461538 | [
"-R, B, G, N = list(map(int, input().split()))",
"+r, g, b, n = list(map(int, input().split()))",
"-ball = 0",
"-a = sorted([R, G, B])",
"-for r in range(N // a[0] + 1):",
"- ball = r * a[0]",
"- for b in range((N - ball) // a[1] + 1):",
"- if N - ball >= 0 and (N - ball - b * a[1]) % a[2] == 0:",
"+for i in range(n + 1):",
"+ for j in range(n + 1):",
"+ rest = n - i * r - j * g",
"+ if rest >= 0 and rest % b == 0:"
] | false | 0.522439 | 1.645554 | 0.317485 | [
"s229858133",
"s576303678"
] |
u863370423 | p03264 | python | s446080051 | s819514131 | 164 | 29 | 38,384 | 9,092 | Accepted | Accepted | 82.32 | from math import floor, ceil
n = int(eval(input()))
a = n // 2
b = n - a
print((a * b)) | from sys import stdin,stdout
def main():
line=stdin.readline()
parts=line.split()
a=int(parts[0])
par=int(a/2)
impar=int(a/2)+a%2
stdout.write(str(par*impar))
main() | 6 | 10 | 85 | 199 | from math import floor, ceil
n = int(eval(input()))
a = n // 2
b = n - a
print((a * b))
| from sys import stdin, stdout
def main():
line = stdin.readline()
parts = line.split()
a = int(parts[0])
par = int(a / 2)
impar = int(a / 2) + a % 2
stdout.write(str(par * impar))
main()
| false | 40 | [
"-from math import floor, ceil",
"+from sys import stdin, stdout",
"-n = int(eval(input()))",
"-a = n // 2",
"-b = n - a",
"-print((a * b))",
"+",
"+def main():",
"+ line = stdin.readline()",
"+ parts = line.split()",
"+ a = int(parts[0])",
"+ par = int(a / 2)",
"+ impar = int(a / 2) + a % 2",
"+ stdout.write(str(par * impar))",
"+",
"+",
"+main()"
] | false | 0.035789 | 0.041903 | 0.854093 | [
"s446080051",
"s819514131"
] |
u753803401 | p03273 | python | s194926160 | s829530666 | 329 | 172 | 21,688 | 13,580 | Accepted | Accepted | 47.72 | import numpy
h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
a = numpy.asarray(a)
a = a[:, numpy.any(a == "#", axis=0)]
a = a[numpy.any(a == "#", axis=1)]
for i in range(len(a)):
print(("".join(a[i])))
| import numpy
h, w = list(map(int, input().split()))
ls = [list(eval(input())) for _ in range(h)]
ls = numpy.array(ls)
ls = ls[numpy.any(ls == "#", axis=1), :]
ls = ls[:, numpy.any(ls == "#", axis=0)]
for i in list(ls):
print(("".join(i)))
| 8 | 8 | 234 | 236 | import numpy
h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
a = numpy.asarray(a)
a = a[:, numpy.any(a == "#", axis=0)]
a = a[numpy.any(a == "#", axis=1)]
for i in range(len(a)):
print(("".join(a[i])))
| import numpy
h, w = list(map(int, input().split()))
ls = [list(eval(input())) for _ in range(h)]
ls = numpy.array(ls)
ls = ls[numpy.any(ls == "#", axis=1), :]
ls = ls[:, numpy.any(ls == "#", axis=0)]
for i in list(ls):
print(("".join(i)))
| false | 0 | [
"-a = [list(eval(input())) for _ in range(h)]",
"-a = numpy.asarray(a)",
"-a = a[:, numpy.any(a == \"#\", axis=0)]",
"-a = a[numpy.any(a == \"#\", axis=1)]",
"-for i in range(len(a)):",
"- print((\"\".join(a[i])))",
"+ls = [list(eval(input())) for _ in range(h)]",
"+ls = numpy.array(ls)",
"+ls = ls[numpy.any(ls == \"#\", axis=1), :]",
"+ls = ls[:, numpy.any(ls == \"#\", axis=0)]",
"+for i in list(ls):",
"+ print((\"\".join(i)))"
] | false | 0.258432 | 0.29641 | 0.871874 | [
"s194926160",
"s829530666"
] |
u839188633 | p02821 | python | s183883907 | s745983662 | 345 | 211 | 33,524 | 34,144 | Accepted | Accepted | 38.84 | from numpy.fft import rfft, irfft
import numpy as np
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
a = np.zeros(2 ** 18)
for Ai in A:
a[Ai] += 1
fa = rfft(a)
a2 = irfft(fa ** 2)
a2 = np.round(a2).astype(np.int)
cum_a2 = np.cumsum(a2)
index = np.searchsorted(cum_a2, N ** 2 - M)
a2[index] -= cum_a2[index] - (N ** 2 - M)
ans = sum(A) * 2 * N - (a2[: index + 1] * np.arange(index + 1)).sum()
print(ans)
| from numpy.fft import rfft, irfft
import numpy as np
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
a = np.bincount(A, minlength=2 ** 18)
fa = rfft(a)
a2 = irfft(fa ** 2)
a2 = np.round(a2).astype(np.int)
cum_a2 = np.cumsum(a2)
index = np.searchsorted(cum_a2, N ** 2 - M)
a2[index] -= cum_a2[index] - (N ** 2 - M)
ans = sum(A) * 2 * N - (a2[: index + 1] * np.arange(index + 1)).sum()
print(ans)
| 22 | 20 | 456 | 442 | from numpy.fft import rfft, irfft
import numpy as np
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
a = np.zeros(2**18)
for Ai in A:
a[Ai] += 1
fa = rfft(a)
a2 = irfft(fa**2)
a2 = np.round(a2).astype(np.int)
cum_a2 = np.cumsum(a2)
index = np.searchsorted(cum_a2, N**2 - M)
a2[index] -= cum_a2[index] - (N**2 - M)
ans = sum(A) * 2 * N - (a2[: index + 1] * np.arange(index + 1)).sum()
print(ans)
| from numpy.fft import rfft, irfft
import numpy as np
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
a = np.bincount(A, minlength=2**18)
fa = rfft(a)
a2 = irfft(fa**2)
a2 = np.round(a2).astype(np.int)
cum_a2 = np.cumsum(a2)
index = np.searchsorted(cum_a2, N**2 - M)
a2[index] -= cum_a2[index] - (N**2 - M)
ans = sum(A) * 2 * N - (a2[: index + 1] * np.arange(index + 1)).sum()
print(ans)
| false | 9.090909 | [
"-a = np.zeros(2**18)",
"-for Ai in A:",
"- a[Ai] += 1",
"+a = np.bincount(A, minlength=2**18)"
] | false | 0.909025 | 0.428061 | 2.12359 | [
"s183883907",
"s745983662"
] |
u550294762 | p03290 | python | s986410860 | s806109961 | 217 | 109 | 41,840 | 75,576 | Accepted | Accepted | 49.77 | d, g = list(map(int, input().split()))
pc_ls = []
for i in range(d):
p, c = list(map(int, input().split()))
pc_ls.append([p, c])
ptns = []
for i in range(2 ** d):
ptn = []
for j in range(d):
if ((i >> j) & 1):
ptn.append(j)
ptns.append(ptn)
ret = 10 ** 10
for item in ptns:
cnt = 0
pnt = 0
for val in item:
cnt += pc_ls[val][0]
pnt += (100 * (val + 1)) * pc_ls[val][0] + pc_ls[val][1]
left = g - pnt
if left <= 0:
ret = min(ret, cnt)
else:
for i in range(1, d + 1):
if (d - i) in item:
continue
else:
max_val = (100 * (d - i + 1)) * pc_ls[-i][0]
if max_val < left:
cnt += pc_ls[-i][0]
left -= max_val
else:
cnt += (left + 100 * (d - i + 1) -
1) // (100 * (d - i + 1))
break
ret = min(ret, cnt)
print(ret)
| import itertools
from typing import List, Tuple
def main():
d, g = list(map(int, input().split()))
v = []
for _ in range(d):
p, c = list(map(int, input().split()))
v.append((p, c))
print((ag(v, g)))
def ag(v: List[Tuple[int, int]], g: int) -> int:
ret = 10 ** 10
for comb in itertools.product((False, True), repeat=len(v)):
cnt, score = 0, 0
for i, bit in enumerate(comb):
if bit:
score += (i + 1) * 100 * v[i][0] + v[i][1]
cnt += v[i][0]
if score < g:
idx = len(v) - list(reversed(comb)).index(False) - 1
add = ((g - score) + ((idx + 1) * 100) - 1) // ((idx + 1) * 100)
if add < v[idx][0]:
cnt += add
else:
cnt = 10 ** 10 # impossible
ret = min(ret, cnt)
return ret
if __name__ == '__main__':
main()
| 41 | 35 | 1,037 | 933 | d, g = list(map(int, input().split()))
pc_ls = []
for i in range(d):
p, c = list(map(int, input().split()))
pc_ls.append([p, c])
ptns = []
for i in range(2**d):
ptn = []
for j in range(d):
if (i >> j) & 1:
ptn.append(j)
ptns.append(ptn)
ret = 10**10
for item in ptns:
cnt = 0
pnt = 0
for val in item:
cnt += pc_ls[val][0]
pnt += (100 * (val + 1)) * pc_ls[val][0] + pc_ls[val][1]
left = g - pnt
if left <= 0:
ret = min(ret, cnt)
else:
for i in range(1, d + 1):
if (d - i) in item:
continue
else:
max_val = (100 * (d - i + 1)) * pc_ls[-i][0]
if max_val < left:
cnt += pc_ls[-i][0]
left -= max_val
else:
cnt += (left + 100 * (d - i + 1) - 1) // (100 * (d - i + 1))
break
ret = min(ret, cnt)
print(ret)
| import itertools
from typing import List, Tuple
def main():
d, g = list(map(int, input().split()))
v = []
for _ in range(d):
p, c = list(map(int, input().split()))
v.append((p, c))
print((ag(v, g)))
def ag(v: List[Tuple[int, int]], g: int) -> int:
ret = 10**10
for comb in itertools.product((False, True), repeat=len(v)):
cnt, score = 0, 0
for i, bit in enumerate(comb):
if bit:
score += (i + 1) * 100 * v[i][0] + v[i][1]
cnt += v[i][0]
if score < g:
idx = len(v) - list(reversed(comb)).index(False) - 1
add = ((g - score) + ((idx + 1) * 100) - 1) // ((idx + 1) * 100)
if add < v[idx][0]:
cnt += add
else:
cnt = 10**10 # impossible
ret = min(ret, cnt)
return ret
if __name__ == "__main__":
main()
| false | 14.634146 | [
"-d, g = list(map(int, input().split()))",
"-pc_ls = []",
"-for i in range(d):",
"- p, c = list(map(int, input().split()))",
"- pc_ls.append([p, c])",
"-ptns = []",
"-for i in range(2**d):",
"- ptn = []",
"- for j in range(d):",
"- if (i >> j) & 1:",
"- ptn.append(j)",
"- ptns.append(ptn)",
"-ret = 10**10",
"-for item in ptns:",
"- cnt = 0",
"- pnt = 0",
"- for val in item:",
"- cnt += pc_ls[val][0]",
"- pnt += (100 * (val + 1)) * pc_ls[val][0] + pc_ls[val][1]",
"- left = g - pnt",
"- if left <= 0:",
"+import itertools",
"+from typing import List, Tuple",
"+",
"+",
"+def main():",
"+ d, g = list(map(int, input().split()))",
"+ v = []",
"+ for _ in range(d):",
"+ p, c = list(map(int, input().split()))",
"+ v.append((p, c))",
"+ print((ag(v, g)))",
"+",
"+",
"+def ag(v: List[Tuple[int, int]], g: int) -> int:",
"+ ret = 10**10",
"+ for comb in itertools.product((False, True), repeat=len(v)):",
"+ cnt, score = 0, 0",
"+ for i, bit in enumerate(comb):",
"+ if bit:",
"+ score += (i + 1) * 100 * v[i][0] + v[i][1]",
"+ cnt += v[i][0]",
"+ if score < g:",
"+ idx = len(v) - list(reversed(comb)).index(False) - 1",
"+ add = ((g - score) + ((idx + 1) * 100) - 1) // ((idx + 1) * 100)",
"+ if add < v[idx][0]:",
"+ cnt += add",
"+ else:",
"+ cnt = 10**10 # impossible",
"- else:",
"- for i in range(1, d + 1):",
"- if (d - i) in item:",
"- continue",
"- else:",
"- max_val = (100 * (d - i + 1)) * pc_ls[-i][0]",
"- if max_val < left:",
"- cnt += pc_ls[-i][0]",
"- left -= max_val",
"- else:",
"- cnt += (left + 100 * (d - i + 1) - 1) // (100 * (d - i + 1))",
"- break",
"- ret = min(ret, cnt)",
"-print(ret)",
"+ return ret",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.038027 | 0.044433 | 0.855822 | [
"s986410860",
"s806109961"
] |
u095021077 | p03043 | python | s540027008 | s544823788 | 183 | 69 | 45,876 | 3,060 | Accepted | Accepted | 62.3 | temp=input().split()
N=int(temp[0])
K=int(temp[1])
r=[]
for i in range(1, N+1):
temp=i
counter=0
while temp<K:
temp*=2
counter+=1
r.append(counter)
print((sum([pow(0.5, r[i]) for i in range(N)])/N)) | N, K=list(map(int, input().split()))
prob=0
for i in range(1, N+1):
counter=0
while i*pow(2, counter)<K:
counter+=1
prob+=pow(1/2, counter)/N
print(prob) | 15 | 11 | 237 | 176 | temp = input().split()
N = int(temp[0])
K = int(temp[1])
r = []
for i in range(1, N + 1):
temp = i
counter = 0
while temp < K:
temp *= 2
counter += 1
r.append(counter)
print((sum([pow(0.5, r[i]) for i in range(N)]) / N))
| N, K = list(map(int, input().split()))
prob = 0
for i in range(1, N + 1):
counter = 0
while i * pow(2, counter) < K:
counter += 1
prob += pow(1 / 2, counter) / N
print(prob)
| false | 26.666667 | [
"-temp = input().split()",
"-N = int(temp[0])",
"-K = int(temp[1])",
"-r = []",
"+N, K = list(map(int, input().split()))",
"+prob = 0",
"- temp = i",
"- while temp < K:",
"- temp *= 2",
"+ while i * pow(2, counter) < K:",
"- r.append(counter)",
"-print((sum([pow(0.5, r[i]) for i in range(N)]) / N))",
"+ prob += pow(1 / 2, counter) / N",
"+print(prob)"
] | false | 0.070643 | 0.190542 | 0.370748 | [
"s540027008",
"s544823788"
] |
u072053884 | p02304 | python | s049553725 | s870364634 | 1,340 | 1,220 | 35,336 | 35,284 | Accepted | Accepted | 8.96 | # Acceptance of input
import sys
file_input = sys.stdin
n = file_input.readline()
EP = []
l = -1000000001
u = 1000000001
vs_x = set()
for line in file_input:
x1, y1, x2, y2 = (list(map(int, line.split())))
if x1 == x2:
if y1 < y2:
EP.append((y1, l, x1))
EP.append((y2, u, x1))
else:
EP.append((y1, u, x1))
EP.append((y2, l, x1))
vs_x.add(x1)
else:
if x1 < x2:
EP.append((y1, x1, x2))
else:
EP.append((y1, x2, x1))
# Binary Indexed Tree
class BinaryIndexedTree:
def __init__(self, n):
self.data = [0] * (n + 1)
self.num = n
def switch(self, i, d):
while i <= self.num:
self.data[i] += d
i += i & -i
def _sum(self, i):
s = 0
while i:
s += self.data[i]
i -= i & -i
return s
def seg_sum(self, a, b):
return self._sum(b) - self._sum(a - 1)
# Sweep
import bisect
EP.sort()
BIT = BinaryIndexedTree(len(vs_x))
vs_x = [l] + sorted(vs_x)
d_vs_x = {e: i for i, e in enumerate(vs_x)}
cnt = 0
for p in EP:
e = p[1]
if e == l:
BIT.switch(d_vs_x[p[2]], 1)
elif e == u:
BIT.switch(d_vs_x[p[2]], -1)
else:
l_x = bisect.bisect_left(vs_x, e)
r_x = bisect.bisect(vs_x, p[2]) - 1
cnt += BIT.seg_sum(l_x, r_x)
# Output
print(cnt) | # Acceptance of input
import sys
file_input = sys.stdin
n = file_input.readline()
EP = []
l = -1000000001
u = 1000000001
vs_x = set()
h_num = 0
for line in file_input:
x1, y1, x2, y2 = (list(map(int, line.split())))
if x1 == x2:
if y1 < y2:
EP.append((y1, l, x1))
EP.append((y2, u, x1))
else:
EP.append((y1, u, x1))
EP.append((y2, l, x1))
vs_x.add(x1)
else:
if x1 < x2:
EP.append((y1, x1, x2))
else:
EP.append((y1, x2, x1))
h_num += 1
# Binary Indexed Tree
class BinaryIndexedTree:
def __init__(self, n):
self.data = [0] * (n + 1)
self.num = n
def switch(self, i, d):
while i <= self.num:
self.data[i] += d
i += i & -i
def _sum(self, i):
s = 0
while i:
s += self.data[i]
i -= i & -i
return s
def seg_sum(self, a, b):
return self._sum(b) - self._sum(a - 1)
# Sweep
import bisect
EP.sort()
BIT = BinaryIndexedTree(len(vs_x))
vs_x = [l] + sorted(vs_x)
d_vs_x = {e: i for i, e in enumerate(vs_x)}
cnt = 0
for p in EP:
e = p[1]
if e == l:
BIT.switch(d_vs_x[p[2]], 1)
elif e == u:
BIT.switch(d_vs_x[p[2]], -1)
else:
l_x = bisect.bisect_left(vs_x, e)
r_x = bisect.bisect(vs_x, p[2]) - 1
cnt += BIT.seg_sum(l_x, r_x)
h_num -= 1
if h_num == 0:
break
# Output
print(cnt) | 71 | 76 | 1,484 | 1,570 | # Acceptance of input
import sys
file_input = sys.stdin
n = file_input.readline()
EP = []
l = -1000000001
u = 1000000001
vs_x = set()
for line in file_input:
x1, y1, x2, y2 = list(map(int, line.split()))
if x1 == x2:
if y1 < y2:
EP.append((y1, l, x1))
EP.append((y2, u, x1))
else:
EP.append((y1, u, x1))
EP.append((y2, l, x1))
vs_x.add(x1)
else:
if x1 < x2:
EP.append((y1, x1, x2))
else:
EP.append((y1, x2, x1))
# Binary Indexed Tree
class BinaryIndexedTree:
def __init__(self, n):
self.data = [0] * (n + 1)
self.num = n
def switch(self, i, d):
while i <= self.num:
self.data[i] += d
i += i & -i
def _sum(self, i):
s = 0
while i:
s += self.data[i]
i -= i & -i
return s
def seg_sum(self, a, b):
return self._sum(b) - self._sum(a - 1)
# Sweep
import bisect
EP.sort()
BIT = BinaryIndexedTree(len(vs_x))
vs_x = [l] + sorted(vs_x)
d_vs_x = {e: i for i, e in enumerate(vs_x)}
cnt = 0
for p in EP:
e = p[1]
if e == l:
BIT.switch(d_vs_x[p[2]], 1)
elif e == u:
BIT.switch(d_vs_x[p[2]], -1)
else:
l_x = bisect.bisect_left(vs_x, e)
r_x = bisect.bisect(vs_x, p[2]) - 1
cnt += BIT.seg_sum(l_x, r_x)
# Output
print(cnt)
| # Acceptance of input
import sys
file_input = sys.stdin
n = file_input.readline()
EP = []
l = -1000000001
u = 1000000001
vs_x = set()
h_num = 0
for line in file_input:
x1, y1, x2, y2 = list(map(int, line.split()))
if x1 == x2:
if y1 < y2:
EP.append((y1, l, x1))
EP.append((y2, u, x1))
else:
EP.append((y1, u, x1))
EP.append((y2, l, x1))
vs_x.add(x1)
else:
if x1 < x2:
EP.append((y1, x1, x2))
else:
EP.append((y1, x2, x1))
h_num += 1
# Binary Indexed Tree
class BinaryIndexedTree:
def __init__(self, n):
self.data = [0] * (n + 1)
self.num = n
def switch(self, i, d):
while i <= self.num:
self.data[i] += d
i += i & -i
def _sum(self, i):
s = 0
while i:
s += self.data[i]
i -= i & -i
return s
def seg_sum(self, a, b):
return self._sum(b) - self._sum(a - 1)
# Sweep
import bisect
EP.sort()
BIT = BinaryIndexedTree(len(vs_x))
vs_x = [l] + sorted(vs_x)
d_vs_x = {e: i for i, e in enumerate(vs_x)}
cnt = 0
for p in EP:
e = p[1]
if e == l:
BIT.switch(d_vs_x[p[2]], 1)
elif e == u:
BIT.switch(d_vs_x[p[2]], -1)
else:
l_x = bisect.bisect_left(vs_x, e)
r_x = bisect.bisect(vs_x, p[2]) - 1
cnt += BIT.seg_sum(l_x, r_x)
h_num -= 1
if h_num == 0:
break
# Output
print(cnt)
| false | 6.578947 | [
"+h_num = 0",
"+ h_num += 1",
"+ h_num -= 1",
"+ if h_num == 0:",
"+ break"
] | false | 0.043628 | 0.174315 | 0.250282 | [
"s049553725",
"s870364634"
] |
u241159583 | p04005 | python | s351264163 | s334255058 | 29 | 25 | 9,172 | 9,060 | Accepted | Accepted | 13.79 | a = sorted(list(map(int, input().split())))
ok = False
for i in range(3):
if a[i] % 2 ==0:
ok = True
break
if not ok:
ans = a[0]*a[1]
print((0 if ok else ans)) | a = sorted(list(map(int, input().split())))
ans = a[0]*a[1]
for i in range(3):
if a[i]%2==0:
ans = 0
break
print(ans) | 9 | 7 | 189 | 143 | a = sorted(list(map(int, input().split())))
ok = False
for i in range(3):
if a[i] % 2 == 0:
ok = True
break
if not ok:
ans = a[0] * a[1]
print((0 if ok else ans))
| a = sorted(list(map(int, input().split())))
ans = a[0] * a[1]
for i in range(3):
if a[i] % 2 == 0:
ans = 0
break
print(ans)
| false | 22.222222 | [
"-ok = False",
"+ans = a[0] * a[1]",
"- ok = True",
"+ ans = 0",
"-if not ok:",
"- ans = a[0] * a[1]",
"-print((0 if ok else ans))",
"+print(ans)"
] | false | 0.074066 | 0.03808 | 1.945041 | [
"s351264163",
"s334255058"
] |
u600402037 | p03053 | python | s489541885 | s258272986 | 530 | 402 | 121,052 | 37,892 | Accepted | Accepted | 24.15 | import sys
from collections import deque
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to only numbers
rs = lambda: stdin.readline().rstrip() # ignores trailing space
H, W = rl()
A = [list(rs()) for _ in range(H)]
answer = 0
que = deque()
data = [[-1] * W for _ in range(H)]
for i in range(H):
for j in range(W):
if A[i][j] == '#':
data[i][j] = 0
que.append((j, i))
while que:
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
p = que.popleft()
for i in range(4):
nx = p[0] + dx[i]
ny = p[1] + dy[i]
if 0 <= ny <= H-1 and 0 <= nx <= W-1:
if data[ny][nx] == -1:
data[ny][nx] = data[p[1]][p[0]] + 1
que.append((nx, ny))
answer = max([max(z) for z in data])
print(answer)
# 54
| import sys
import numpy as np
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to only numbers
rs = lambda: stdin.readline().rstrip() # ignores trailing space
H, W = rl()
A = [list(rs()) for _ in range(H)]
INF = 10 ** 5
B = np.array([[0 if x == '#' else INF for x in row] for row in A])
for i in range(1, H):
B[i] = np.minimum(B[i], B[i-1] + 1)
for i in range(H-2, -1, -1):
B[i] = np.minimum(B[i], B[i+1] + 1)
for j in range(1, W):
B[:, j] = np.minimum(B[:, j], B[:, j-1] + 1)
for j in range(W-2, -1, -1):
B[:, j] = np.minimum(B[:, j], B[:, j+1] + 1)
print((B.max()))
| 34 | 27 | 910 | 704 | import sys
from collections import deque
stdin = sys.stdin
sys.setrecursionlimit(10**7)
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to only numbers
rs = lambda: stdin.readline().rstrip() # ignores trailing space
H, W = rl()
A = [list(rs()) for _ in range(H)]
answer = 0
que = deque()
data = [[-1] * W for _ in range(H)]
for i in range(H):
for j in range(W):
if A[i][j] == "#":
data[i][j] = 0
que.append((j, i))
while que:
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
p = que.popleft()
for i in range(4):
nx = p[0] + dx[i]
ny = p[1] + dy[i]
if 0 <= ny <= H - 1 and 0 <= nx <= W - 1:
if data[ny][nx] == -1:
data[ny][nx] = data[p[1]][p[0]] + 1
que.append((nx, ny))
answer = max([max(z) for z in data])
print(answer)
# 54
| import sys
import numpy as np
stdin = sys.stdin
sys.setrecursionlimit(10**7)
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to only numbers
rs = lambda: stdin.readline().rstrip() # ignores trailing space
H, W = rl()
A = [list(rs()) for _ in range(H)]
INF = 10**5
B = np.array([[0 if x == "#" else INF for x in row] for row in A])
for i in range(1, H):
B[i] = np.minimum(B[i], B[i - 1] + 1)
for i in range(H - 2, -1, -1):
B[i] = np.minimum(B[i], B[i + 1] + 1)
for j in range(1, W):
B[:, j] = np.minimum(B[:, j], B[:, j - 1] + 1)
for j in range(W - 2, -1, -1):
B[:, j] = np.minimum(B[:, j], B[:, j + 1] + 1)
print((B.max()))
| false | 20.588235 | [
"-from collections import deque",
"+import numpy as np",
"-answer = 0",
"-que = deque()",
"-data = [[-1] * W for _ in range(H)]",
"-for i in range(H):",
"- for j in range(W):",
"- if A[i][j] == \"#\":",
"- data[i][j] = 0",
"- que.append((j, i))",
"-while que:",
"- dx = [1, 0, -1, 0]",
"- dy = [0, 1, 0, -1]",
"- p = que.popleft()",
"- for i in range(4):",
"- nx = p[0] + dx[i]",
"- ny = p[1] + dy[i]",
"- if 0 <= ny <= H - 1 and 0 <= nx <= W - 1:",
"- if data[ny][nx] == -1:",
"- data[ny][nx] = data[p[1]][p[0]] + 1",
"- que.append((nx, ny))",
"-answer = max([max(z) for z in data])",
"-print(answer)",
"-# 54",
"+INF = 10**5",
"+B = np.array([[0 if x == \"#\" else INF for x in row] for row in A])",
"+for i in range(1, H):",
"+ B[i] = np.minimum(B[i], B[i - 1] + 1)",
"+for i in range(H - 2, -1, -1):",
"+ B[i] = np.minimum(B[i], B[i + 1] + 1)",
"+for j in range(1, W):",
"+ B[:, j] = np.minimum(B[:, j], B[:, j - 1] + 1)",
"+for j in range(W - 2, -1, -1):",
"+ B[:, j] = np.minimum(B[:, j], B[:, j + 1] + 1)",
"+print((B.max()))"
] | false | 0.041343 | 0.187514 | 0.22048 | [
"s489541885",
"s258272986"
] |
u333945892 | p03287 | python | s296661856 | s080778430 | 217 | 111 | 20,504 | 15,452 | Accepted | Accepted | 48.85 | #list_int 並べて出力 print (' '.join(map(str,ans_li)))
#list_str 並べて出力 print (' '.join(list))
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())
N,M = inpl()
aa = inpl()
ans = 0
ed = [0]
SUM_L = defaultdict(int)
SUM_R = defaultdict(int)
SUM_L[0] += 1
SUM_R[0] += 1
SUM = sum(aa) % M
tmpL = tmpR = 0
for i in range(N):
tmpL += aa[i]
tmpL %= M
if SUM_L[tmpL] == 0:
ed.append(tmpL)
SUM_L[tmpL] += 1
tmpR += aa[N-i-1]
tmpR %= M
SUM_R[tmpR] += 1
ans = 0
for l in ed:
numL = SUM_L[l]
r = (SUM - l) % M
numR = SUM_R[r]
ans += numL * (numR-1)
print((ans//2))
| from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())
N,M = inpl()
aa = inpl()
ans = 0
modSUM = defaultdict(int)
tmp = 0
modSUM[0] += 1
for a in aa:
tmp += a
tmp %= M
ans += modSUM[tmp]
modSUM[tmp] += 1
print(ans)
| 46 | 26 | 907 | 541 | # list_int 並べて出力 print (' '.join(map(str,ans_li)))
# list_str 並べて出力 print (' '.join(list))
from collections import defaultdict
import sys, heapq, bisect, math, itertools, string, queue, datetime
sys.setrecursionlimit(10**8)
INF = float("inf")
mod = 10**9 + 7
eps = 10**-7
AtoZ = [chr(i) for i in range(65, 65 + 26)]
atoz = [chr(i) for i in range(97, 97 + 26)]
def inpl():
return list(map(int, input().split()))
def inpl_s():
return list(input().split())
N, M = inpl()
aa = inpl()
ans = 0
ed = [0]
SUM_L = defaultdict(int)
SUM_R = defaultdict(int)
SUM_L[0] += 1
SUM_R[0] += 1
SUM = sum(aa) % M
tmpL = tmpR = 0
for i in range(N):
tmpL += aa[i]
tmpL %= M
if SUM_L[tmpL] == 0:
ed.append(tmpL)
SUM_L[tmpL] += 1
tmpR += aa[N - i - 1]
tmpR %= M
SUM_R[tmpR] += 1
ans = 0
for l in ed:
numL = SUM_L[l]
r = (SUM - l) % M
numR = SUM_R[r]
ans += numL * (numR - 1)
print((ans // 2))
| from collections import defaultdict
import sys, heapq, bisect, math, itertools, string, queue, datetime
sys.setrecursionlimit(10**8)
INF = float("inf")
mod = 10**9 + 7
eps = 10**-7
AtoZ = [chr(i) for i in range(65, 65 + 26)]
atoz = [chr(i) for i in range(97, 97 + 26)]
def inpl():
return list(map(int, input().split()))
def inpl_s():
return list(input().split())
N, M = inpl()
aa = inpl()
ans = 0
modSUM = defaultdict(int)
tmp = 0
modSUM[0] += 1
for a in aa:
tmp += a
tmp %= M
ans += modSUM[tmp]
modSUM[tmp] += 1
print(ans)
| false | 43.478261 | [
"-# list_int 並べて出力 print (' '.join(map(str,ans_li)))",
"-# list_str 並べて出力 print (' '.join(list))",
"-ed = [0]",
"-SUM_L = defaultdict(int)",
"-SUM_R = defaultdict(int)",
"-SUM_L[0] += 1",
"-SUM_R[0] += 1",
"-SUM = sum(aa) % M",
"-tmpL = tmpR = 0",
"-for i in range(N):",
"- tmpL += aa[i]",
"- tmpL %= M",
"- if SUM_L[tmpL] == 0:",
"- ed.append(tmpL)",
"- SUM_L[tmpL] += 1",
"- tmpR += aa[N - i - 1]",
"- tmpR %= M",
"- SUM_R[tmpR] += 1",
"-ans = 0",
"-for l in ed:",
"- numL = SUM_L[l]",
"- r = (SUM - l) % M",
"- numR = SUM_R[r]",
"- ans += numL * (numR - 1)",
"-print((ans // 2))",
"+modSUM = defaultdict(int)",
"+tmp = 0",
"+modSUM[0] += 1",
"+for a in aa:",
"+ tmp += a",
"+ tmp %= M",
"+ ans += modSUM[tmp]",
"+ modSUM[tmp] += 1",
"+print(ans)"
] | false | 0.048511 | 0.074973 | 0.647051 | [
"s296661856",
"s080778430"
] |
u301624971 | p02725 | python | s641675998 | s334085889 | 127 | 111 | 26,100 | 26,444 | Accepted | Accepted | 12.6 | K,N=list(map(int,input().split()))
A=list(map(int,input().split()))
MAX=A.pop(N-1)
pre=MAX
counter=[]
for a in reversed(A):
counter.append(pre - a)
pre=a
counter.append(pre + K - MAX)
counter.sort()
print((sum(counter[:N-1])))
| def myAnswer(K:int,N:int,A:list) -> int:
distance=[]
pre = A.pop(0)
MIN = pre
for a in A:
distance.append(a - pre)
pre = a
distance.append(MIN + K - A[-1])
distance.sort()
return sum(distance[:N - 1])
def modelAnswer():
tmp=1
def main():
K,N = list(map(int,input().split()))
A = list(map(int,input().split()))
print((myAnswer(K,N,A[:])))
if __name__ == '__main__':
main() | 15 | 21 | 245 | 434 | K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
MAX = A.pop(N - 1)
pre = MAX
counter = []
for a in reversed(A):
counter.append(pre - a)
pre = a
counter.append(pre + K - MAX)
counter.sort()
print((sum(counter[: N - 1])))
| def myAnswer(K: int, N: int, A: list) -> int:
distance = []
pre = A.pop(0)
MIN = pre
for a in A:
distance.append(a - pre)
pre = a
distance.append(MIN + K - A[-1])
distance.sort()
return sum(distance[: N - 1])
def modelAnswer():
tmp = 1
def main():
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
print((myAnswer(K, N, A[:])))
if __name__ == "__main__":
main()
| false | 28.571429 | [
"-K, N = list(map(int, input().split()))",
"-A = list(map(int, input().split()))",
"-MAX = A.pop(N - 1)",
"-pre = MAX",
"-counter = []",
"-for a in reversed(A):",
"- counter.append(pre - a)",
"- pre = a",
"-counter.append(pre + K - MAX)",
"-counter.sort()",
"-print((sum(counter[: N - 1])))",
"+def myAnswer(K: int, N: int, A: list) -> int:",
"+ distance = []",
"+ pre = A.pop(0)",
"+ MIN = pre",
"+ for a in A:",
"+ distance.append(a - pre)",
"+ pre = a",
"+ distance.append(MIN + K - A[-1])",
"+ distance.sort()",
"+ return sum(distance[: N - 1])",
"+",
"+",
"+def modelAnswer():",
"+ tmp = 1",
"+",
"+",
"+def main():",
"+ K, N = list(map(int, input().split()))",
"+ A = list(map(int, input().split()))",
"+ print((myAnswer(K, N, A[:])))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.091179 | 0.044745 | 2.037743 | [
"s641675998",
"s334085889"
] |
u796942881 | p02923 | python | s423411785 | s344080558 | 68 | 52 | 11,660 | 11,136 | Accepted | Accepted | 23.53 | def main():
H = open(0).read().split()[1:]
ans = 0
tmp = 0
for h1, h2 in zip(H[:-1], H[1:]):
if int(h1) >= int(h2):
tmp += 1
else:
if ans < tmp:
ans = tmp
tmp = 0
if ans < tmp:
ans = tmp
print(ans)
return
main()
| def main():
eval(input())
H = list(map(int, input().split()))
ans = 0
prev = float('inf')
cnt = -1
for cur in H:
if prev >= cur:
cnt += 1
else:
if ans < cnt:
ans = cnt
cnt = 0
prev = cur
if ans < cnt:
ans = cnt
print(ans)
return
main()
| 18 | 21 | 335 | 366 | def main():
H = open(0).read().split()[1:]
ans = 0
tmp = 0
for h1, h2 in zip(H[:-1], H[1:]):
if int(h1) >= int(h2):
tmp += 1
else:
if ans < tmp:
ans = tmp
tmp = 0
if ans < tmp:
ans = tmp
print(ans)
return
main()
| def main():
eval(input())
H = list(map(int, input().split()))
ans = 0
prev = float("inf")
cnt = -1
for cur in H:
if prev >= cur:
cnt += 1
else:
if ans < cnt:
ans = cnt
cnt = 0
prev = cur
if ans < cnt:
ans = cnt
print(ans)
return
main()
| false | 14.285714 | [
"- H = open(0).read().split()[1:]",
"+ eval(input())",
"+ H = list(map(int, input().split()))",
"- tmp = 0",
"- for h1, h2 in zip(H[:-1], H[1:]):",
"- if int(h1) >= int(h2):",
"- tmp += 1",
"+ prev = float(\"inf\")",
"+ cnt = -1",
"+ for cur in H:",
"+ if prev >= cur:",
"+ cnt += 1",
"- if ans < tmp:",
"- ans = tmp",
"- tmp = 0",
"- if ans < tmp:",
"- ans = tmp",
"+ if ans < cnt:",
"+ ans = cnt",
"+ cnt = 0",
"+ prev = cur",
"+ if ans < cnt:",
"+ ans = cnt"
] | false | 0.04283 | 0.037105 | 1.15429 | [
"s423411785",
"s344080558"
] |
u144913062 | p02900 | python | s557307321 | s731394458 | 375 | 276 | 3,060 | 64,108 | Accepted | Accepted | 26.4 | A, B = list(map(int, input().split()))
ans = 1
for i in range(2, 1+int(min(A**.5, B**.5))):
if A % i == 0 and B % i == 0:
ans += 1
while A % i == 0:
A //= i
while B % i == 0:
B //= i
if A != 1 and B != 1 and (A % B == 0 or B % A == 0):
ans += 1
print(ans)
| from fractions import gcd
def prime_factor(n):
factors = set()
i = 2
while i * i <= n:
while n % i == 0:
factors.add(i)
n //= i
i += 1
if n != 1:
factors.add(n)
return factors
A, B = list(map(int, input().split()))
print((len(prime_factor(gcd(A, B))) + 1)) | 12 | 16 | 301 | 333 | A, B = list(map(int, input().split()))
ans = 1
for i in range(2, 1 + int(min(A**0.5, B**0.5))):
if A % i == 0 and B % i == 0:
ans += 1
while A % i == 0:
A //= i
while B % i == 0:
B //= i
if A != 1 and B != 1 and (A % B == 0 or B % A == 0):
ans += 1
print(ans)
| from fractions import gcd
def prime_factor(n):
factors = set()
i = 2
while i * i <= n:
while n % i == 0:
factors.add(i)
n //= i
i += 1
if n != 1:
factors.add(n)
return factors
A, B = list(map(int, input().split()))
print((len(prime_factor(gcd(A, B))) + 1))
| false | 25 | [
"+from fractions import gcd",
"+",
"+",
"+def prime_factor(n):",
"+ factors = set()",
"+ i = 2",
"+ while i * i <= n:",
"+ while n % i == 0:",
"+ factors.add(i)",
"+ n //= i",
"+ i += 1",
"+ if n != 1:",
"+ factors.add(n)",
"+ return factors",
"+",
"+",
"-ans = 1",
"-for i in range(2, 1 + int(min(A**0.5, B**0.5))):",
"- if A % i == 0 and B % i == 0:",
"- ans += 1",
"- while A % i == 0:",
"- A //= i",
"- while B % i == 0:",
"- B //= i",
"-if A != 1 and B != 1 and (A % B == 0 or B % A == 0):",
"- ans += 1",
"-print(ans)",
"+print((len(prime_factor(gcd(A, B))) + 1))"
] | false | 0.071701 | 0.25021 | 0.286564 | [
"s557307321",
"s731394458"
] |
u466056315 | p02681 | python | s338585018 | s719568179 | 25 | 21 | 9,108 | 9,076 | Accepted | Accepted | 16 | S = eval(input())
T = eval(input())
if S.islower() and T.islower() and len(S) >= 1 and len(S) <= 10 and len(T) == len(S) + 1 and T[:-1] == S:
print("Yes")
else:
print("No") | S = eval(input())
T = eval(input())
if S.islower() and T.islower() and T[:-1] == S:
print("Yes")
else:
print("No") | 6 | 6 | 169 | 111 | S = eval(input())
T = eval(input())
if (
S.islower()
and T.islower()
and len(S) >= 1
and len(S) <= 10
and len(T) == len(S) + 1
and T[:-1] == S
):
print("Yes")
else:
print("No")
| S = eval(input())
T = eval(input())
if S.islower() and T.islower() and T[:-1] == S:
print("Yes")
else:
print("No")
| false | 0 | [
"-if (",
"- S.islower()",
"- and T.islower()",
"- and len(S) >= 1",
"- and len(S) <= 10",
"- and len(T) == len(S) + 1",
"- and T[:-1] == S",
"-):",
"+if S.islower() and T.islower() and T[:-1] == S:"
] | false | 0.042804 | 0.042008 | 1.018948 | [
"s338585018",
"s719568179"
] |
u004423772 | p02756 | python | s592438895 | s324533089 | 483 | 347 | 8,820 | 67,360 | Accepted | Accepted | 28.16 | from collections import deque
S = input().rstrip('\r\n')
S_list = deque(S)
is_reverse = False
Q = int(eval(input()))
for _ in range(Q):
query = input().rstrip('\r\n')
t, f, c = '', '', ''
if len(query) == 1:
t = query
else:
t, f, c = query.split(' ')
if t == '1':
is_reverse = not is_reverse
else:
if f == '1':
if is_reverse:
S_list.append(c)
else:
S_list.appendleft(c)
else:
if is_reverse:
S_list.appendleft(c)
else:
S_list.append(c)
if is_reverse:
S_list.reverse()
print((''.join(S_list))) | import sys
input = sys.stdin.readline
from collections import deque
def main():
S = input().rstrip("\r\n")
Q = int(eval(input()))
d = deque(S)
reverse = False
for _ in range(Q):
q = input().rstrip("\r\n")
if q == "1":
reverse = not reverse
else:
_, f, c = q.split()
if (f == "1" and not reverse) or (f == "2" and reverse):
d.appendleft(c)
else:
d.append(c)
l = list(d)
if reverse:l.reverse()
print(("".join(l)))
if __name__ == "__main__":
main() | 30 | 23 | 694 | 599 | from collections import deque
S = input().rstrip("\r\n")
S_list = deque(S)
is_reverse = False
Q = int(eval(input()))
for _ in range(Q):
query = input().rstrip("\r\n")
t, f, c = "", "", ""
if len(query) == 1:
t = query
else:
t, f, c = query.split(" ")
if t == "1":
is_reverse = not is_reverse
else:
if f == "1":
if is_reverse:
S_list.append(c)
else:
S_list.appendleft(c)
else:
if is_reverse:
S_list.appendleft(c)
else:
S_list.append(c)
if is_reverse:
S_list.reverse()
print(("".join(S_list)))
| import sys
input = sys.stdin.readline
from collections import deque
def main():
S = input().rstrip("\r\n")
Q = int(eval(input()))
d = deque(S)
reverse = False
for _ in range(Q):
q = input().rstrip("\r\n")
if q == "1":
reverse = not reverse
else:
_, f, c = q.split()
if (f == "1" and not reverse) or (f == "2" and reverse):
d.appendleft(c)
else:
d.append(c)
l = list(d)
if reverse:
l.reverse()
print(("".join(l)))
if __name__ == "__main__":
main()
| false | 23.333333 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"-S = input().rstrip(\"\\r\\n\")",
"-S_list = deque(S)",
"-is_reverse = False",
"-Q = int(eval(input()))",
"-for _ in range(Q):",
"- query = input().rstrip(\"\\r\\n\")",
"- t, f, c = \"\", \"\", \"\"",
"- if len(query) == 1:",
"- t = query",
"- else:",
"- t, f, c = query.split(\" \")",
"- if t == \"1\":",
"- is_reverse = not is_reverse",
"- else:",
"- if f == \"1\":",
"- if is_reverse:",
"- S_list.append(c)",
"+",
"+def main():",
"+ S = input().rstrip(\"\\r\\n\")",
"+ Q = int(eval(input()))",
"+ d = deque(S)",
"+ reverse = False",
"+ for _ in range(Q):",
"+ q = input().rstrip(\"\\r\\n\")",
"+ if q == \"1\":",
"+ reverse = not reverse",
"+ else:",
"+ _, f, c = q.split()",
"+ if (f == \"1\" and not reverse) or (f == \"2\" and reverse):",
"+ d.appendleft(c)",
"- S_list.appendleft(c)",
"- else:",
"- if is_reverse:",
"- S_list.appendleft(c)",
"- else:",
"- S_list.append(c)",
"-if is_reverse:",
"- S_list.reverse()",
"-print((\"\".join(S_list)))",
"+ d.append(c)",
"+ l = list(d)",
"+ if reverse:",
"+ l.reverse()",
"+ print((\"\".join(l)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.080566 | 0.037682 | 2.138035 | [
"s592438895",
"s324533089"
] |
u426534722 | p02277 | python | s379503431 | s442118547 | 1,380 | 1,270 | 23,472 | 23,472 | Accepted | Accepted | 7.97 | INF = int(1e10)
def merge(A, left, mid, right):
L = A[left: mid] + [[0, INF]]
R = A[mid: right] + [[0, INF]]
i = j = 0
for k in range(left, right):
if L[i][1] <= R[j][1]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def mergeSort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
def partition(A, p, r):
x = A[r][1]
i = p - 1
for j in range(p, r):
if A[j][1] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
def quicksort(A, p, r):
if p < r:
q = partition(A, p, r)
quicksort(A, p, q - 1)
quicksort(A, q + 1, r)
n = int(input())
f = lambda a: (a[0], int(a[1]))
A = [f(input().split()) for _ in range(n)]
B = A[:]
mergeSort(A, 0, n)
quicksort(B, 0, n - 1)
print("Stable" if A == B else "Not stable")
print(*(f"{a} {b}" for a, b in B), sep="\n")
| import sys
readline = sys.stdin.readline
INF = int(1e10)
def merge(A, left, mid, right):
L = A[left: mid] + [[0, INF]]
R = A[mid: right] + [[0, INF]]
i = j = 0
for k in range(left, right):
if L[i][1] <= R[j][1]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def mergeSort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
def partition(A, p, r):
x = A[r][1]
i = p - 1
for j in range(p, r):
if A[j][1] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
def quicksort(A, p, r):
if p < r:
q = partition(A, p, r)
quicksort(A, p, q - 1)
quicksort(A, q + 1, r)
n = int(input())
f = lambda a: (a[0], int(a[1]))
A = [f(readline().split()) for _ in range(n)]
B = A[:]
mergeSort(A, 0, n)
quicksort(B, 0, n - 1)
print("Stable" if A == B else "Not stable")
print(*(f"{a} {b}" for a, b in B), sep="\n")
| 41 | 43 | 1,102 | 1,148 | INF = int(1e10)
def merge(A, left, mid, right):
L = A[left:mid] + [[0, INF]]
R = A[mid:right] + [[0, INF]]
i = j = 0
for k in range(left, right):
if L[i][1] <= R[j][1]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def mergeSort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
def partition(A, p, r):
x = A[r][1]
i = p - 1
for j in range(p, r):
if A[j][1] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
def quicksort(A, p, r):
if p < r:
q = partition(A, p, r)
quicksort(A, p, q - 1)
quicksort(A, q + 1, r)
n = int(input())
f = lambda a: (a[0], int(a[1]))
A = [f(input().split()) for _ in range(n)]
B = A[:]
mergeSort(A, 0, n)
quicksort(B, 0, n - 1)
print("Stable" if A == B else "Not stable")
print(*(f"{a} {b}" for a, b in B), sep="\n")
| import sys
readline = sys.stdin.readline
INF = int(1e10)
def merge(A, left, mid, right):
L = A[left:mid] + [[0, INF]]
R = A[mid:right] + [[0, INF]]
i = j = 0
for k in range(left, right):
if L[i][1] <= R[j][1]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def mergeSort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
def partition(A, p, r):
x = A[r][1]
i = p - 1
for j in range(p, r):
if A[j][1] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
def quicksort(A, p, r):
if p < r:
q = partition(A, p, r)
quicksort(A, p, q - 1)
quicksort(A, q + 1, r)
n = int(input())
f = lambda a: (a[0], int(a[1]))
A = [f(readline().split()) for _ in range(n)]
B = A[:]
mergeSort(A, 0, n)
quicksort(B, 0, n - 1)
print("Stable" if A == B else "Not stable")
print(*(f"{a} {b}" for a, b in B), sep="\n")
| false | 4.651163 | [
"+import sys",
"+",
"+readline = sys.stdin.readline",
"-A = [f(input().split()) for _ in range(n)]",
"+A = [f(readline().split()) for _ in range(n)]"
] | false | 0.040809 | 0.096963 | 0.420871 | [
"s379503431",
"s442118547"
] |
u411203878 | p03760 | python | s602718514 | s617448423 | 166 | 95 | 38,384 | 61,068 | Accepted | Accepted | 42.77 | s1=eval(input())
s2=eval(input())
ans = []
for i in range(len(s1)+len(s2)):
if i%2==0:
ans.append(s1[i//2])
else:
ans.append(s2[i//2])
print((''.join(map(str,ans)))) | a = list(eval(input()))
b = list(eval(input()))
ans = []
for i in range(len(a)):
ans.append(a[i])
if i < len(b):
ans.append(b[i])
print((''.join(ans))) | 13 | 10 | 191 | 164 | s1 = eval(input())
s2 = eval(input())
ans = []
for i in range(len(s1) + len(s2)):
if i % 2 == 0:
ans.append(s1[i // 2])
else:
ans.append(s2[i // 2])
print(("".join(map(str, ans))))
| a = list(eval(input()))
b = list(eval(input()))
ans = []
for i in range(len(a)):
ans.append(a[i])
if i < len(b):
ans.append(b[i])
print(("".join(ans)))
| false | 23.076923 | [
"-s1 = eval(input())",
"-s2 = eval(input())",
"+a = list(eval(input()))",
"+b = list(eval(input()))",
"-for i in range(len(s1) + len(s2)):",
"- if i % 2 == 0:",
"- ans.append(s1[i // 2])",
"- else:",
"- ans.append(s2[i // 2])",
"-print((\"\".join(map(str, ans))))",
"+for i in range(len(a)):",
"+ ans.append(a[i])",
"+ if i < len(b):",
"+ ans.append(b[i])",
"+print((\"\".join(ans)))"
] | false | 0.061697 | 0.066147 | 0.932738 | [
"s602718514",
"s617448423"
] |
u888092736 | p03724 | python | s203146679 | s891469678 | 225 | 114 | 9,912 | 31,708 | Accepted | Accepted | 49.33 | from itertools import accumulate
N, M = map(int, input().split())
acc = [0] * N
for _ in range(M):
a, b = map(int, input().split())
if a > b:
a, b = b, a
acc[a - 1] += 1
acc[b - 1] -= 1
print("NO") if any(a % 2 for a in accumulate(acc)) else print("YES")
| from itertools import accumulate
N, M, *ab = map(int, open(0).read().split())
acc = [0] * (N + 1)
for a, b in zip(*[iter(ab)] * 2):
if a > b:
a, b = b, a
acc[a - 1] += 1
acc[b - 1] -= 1
acc = list(accumulate(acc, initial=0))
print("NO") if any(a % 2 for a in acc) else print("YES")
| 11 | 11 | 290 | 313 | from itertools import accumulate
N, M = map(int, input().split())
acc = [0] * N
for _ in range(M):
a, b = map(int, input().split())
if a > b:
a, b = b, a
acc[a - 1] += 1
acc[b - 1] -= 1
print("NO") if any(a % 2 for a in accumulate(acc)) else print("YES")
| from itertools import accumulate
N, M, *ab = map(int, open(0).read().split())
acc = [0] * (N + 1)
for a, b in zip(*[iter(ab)] * 2):
if a > b:
a, b = b, a
acc[a - 1] += 1
acc[b - 1] -= 1
acc = list(accumulate(acc, initial=0))
print("NO") if any(a % 2 for a in acc) else print("YES")
| false | 0 | [
"-N, M = map(int, input().split())",
"-acc = [0] * N",
"-for _ in range(M):",
"- a, b = map(int, input().split())",
"+N, M, *ab = map(int, open(0).read().split())",
"+acc = [0] * (N + 1)",
"+for a, b in zip(*[iter(ab)] * 2):",
"-print(\"NO\") if any(a % 2 for a in accumulate(acc)) else print(\"YES\")",
"+acc = list(accumulate(acc, initial=0))",
"+print(\"NO\") if any(a % 2 for a in acc) else print(\"YES\")"
] | false | 0.056917 | 0.041672 | 1.365837 | [
"s203146679",
"s891469678"
] |
u545368057 | p03160 | python | s352485404 | s097587812 | 180 | 166 | 13,908 | 14,876 | Accepted | Accepted | 7.78 | N = int(eval(input()))
hs = list(map(int, input().split()))
"""
dp[i] i番目に到達するときの最小値
遷移
送るDP
i-1段目まで下記を実施
dp[i+1] = min(dp[i+1], dp[i]+コスト)
if (一段飛ばしできる余地があれば):
dp[i+2] = min(dp[i+2],dp[i]+コスト)
"""
INF = 10**9+7
dp = [INF]*101000
dp[0] = 0
for i in range(1,N):
if i-2 >= 0:
cost2 = abs(hs[i]-hs[i-2])
dp[i] = min(dp[i],dp[i-2]+cost2)
cost1 = abs(hs[i]-hs[i-1])
dp[i] = min(dp[i],dp[i-1]+cost1)
print((dp[N-1])) |
"""
dp[i] : 足場iに到達するにあたって、たどり着く最小回数
"""
INF = 10**10
dp = [INF]*110000
N = int(eval(input()))
hs = list(map(int, input().split())) + [INF,INF]
dp[0] = 0
for i in range(N):
dp[i+1] = min(dp[i+1], dp[i]+abs(hs[i+1]-hs[i]))
dp[i+2] = min(dp[i+2], dp[i]+abs(hs[i+2]-hs[i]))
print((dp[N-1]))
| 24 | 14 | 461 | 303 | N = int(eval(input()))
hs = list(map(int, input().split()))
"""
dp[i] i番目に到達するときの最小値
遷移
送るDP
i-1段目まで下記を実施
dp[i+1] = min(dp[i+1], dp[i]+コスト)
if (一段飛ばしできる余地があれば):
dp[i+2] = min(dp[i+2],dp[i]+コスト)
"""
INF = 10**9 + 7
dp = [INF] * 101000
dp[0] = 0
for i in range(1, N):
if i - 2 >= 0:
cost2 = abs(hs[i] - hs[i - 2])
dp[i] = min(dp[i], dp[i - 2] + cost2)
cost1 = abs(hs[i] - hs[i - 1])
dp[i] = min(dp[i], dp[i - 1] + cost1)
print((dp[N - 1]))
| """
dp[i] : 足場iに到達するにあたって、たどり着く最小回数
"""
INF = 10**10
dp = [INF] * 110000
N = int(eval(input()))
hs = list(map(int, input().split())) + [INF, INF]
dp[0] = 0
for i in range(N):
dp[i + 1] = min(dp[i + 1], dp[i] + abs(hs[i + 1] - hs[i]))
dp[i + 2] = min(dp[i + 2], dp[i] + abs(hs[i + 2] - hs[i]))
print((dp[N - 1]))
| false | 41.666667 | [
"+\"\"\"",
"+dp[i] : 足場iに到達するにあたって、たどり着く最小回数",
"+\"\"\"",
"+INF = 10**10",
"+dp = [INF] * 110000",
"-hs = list(map(int, input().split()))",
"-\"\"\"",
"-dp[i] i番目に到達するときの最小値",
"-遷移",
"-送るDP",
"-i-1段目まで下記を実施",
"-dp[i+1] = min(dp[i+1], dp[i]+コスト)",
"-if (一段飛ばしできる余地があれば):",
"- dp[i+2] = min(dp[i+2],dp[i]+コスト)",
"-\"\"\"",
"-INF = 10**9 + 7",
"-dp = [INF] * 101000",
"+hs = list(map(int, input().split())) + [INF, INF]",
"-for i in range(1, N):",
"- if i - 2 >= 0:",
"- cost2 = abs(hs[i] - hs[i - 2])",
"- dp[i] = min(dp[i], dp[i - 2] + cost2)",
"- cost1 = abs(hs[i] - hs[i - 1])",
"- dp[i] = min(dp[i], dp[i - 1] + cost1)",
"+for i in range(N):",
"+ dp[i + 1] = min(dp[i + 1], dp[i] + abs(hs[i + 1] - hs[i]))",
"+ dp[i + 2] = min(dp[i + 2], dp[i] + abs(hs[i + 2] - hs[i]))"
] | false | 0.040336 | 0.076388 | 0.528047 | [
"s352485404",
"s097587812"
] |
u433532588 | p02996 | python | s003780991 | s707901641 | 1,018 | 884 | 36,588 | 29,440 | Accepted | Accepted | 13.16 |
N = int(eval(input()))
# (締切, 時間)
DeadlineCost = [] * N
for i in range(N):
c, d = list(map(int, input().split()))
# tupleじゃなくて array だとどれぐらい遅くなる?
DeadlineCost.append([d, c])
DeadlineCost.sort(reverse=True)
#print(DeadlineCost)
t = 0
for i in range(N):
(d, c) = DeadlineCost.pop()
t += c
if t > d:
print('No')
exit()
print('Yes') |
N = int(eval(input()))
# (締切, 時間)
DeadlineCost = [] * N
for i in range(N):
c, d = list(map(int, input().split()))
DeadlineCost.append((d, c))
DeadlineCost.sort()
#print(DeadlineCost)
t = 0
for i in range(N):
# .pop じゃなくて参照に変更するとどれぐらい速くなる?
(d, c) = DeadlineCost[i]
t += c
if t > d:
print('No')
exit()
print('Yes') | 25 | 25 | 388 | 372 | N = int(eval(input()))
# (締切, 時間)
DeadlineCost = [] * N
for i in range(N):
c, d = list(map(int, input().split()))
# tupleじゃなくて array だとどれぐらい遅くなる?
DeadlineCost.append([d, c])
DeadlineCost.sort(reverse=True)
# print(DeadlineCost)
t = 0
for i in range(N):
(d, c) = DeadlineCost.pop()
t += c
if t > d:
print("No")
exit()
print("Yes")
| N = int(eval(input()))
# (締切, 時間)
DeadlineCost = [] * N
for i in range(N):
c, d = list(map(int, input().split()))
DeadlineCost.append((d, c))
DeadlineCost.sort()
# print(DeadlineCost)
t = 0
for i in range(N):
# .pop じゃなくて参照に変更するとどれぐらい速くなる?
(d, c) = DeadlineCost[i]
t += c
if t > d:
print("No")
exit()
print("Yes")
| false | 0 | [
"- # tupleじゃなくて array だとどれぐらい遅くなる?",
"- DeadlineCost.append([d, c])",
"-DeadlineCost.sort(reverse=True)",
"+ DeadlineCost.append((d, c))",
"+DeadlineCost.sort()",
"- (d, c) = DeadlineCost.pop()",
"+ # .pop じゃなくて参照に変更するとどれぐらい速くなる?",
"+ (d, c) = DeadlineCost[i]"
] | false | 0.051203 | 0.036469 | 1.403998 | [
"s003780991",
"s707901641"
] |
u241159583 | p03361 | python | s099114381 | s842911369 | 265 | 29 | 9,248 | 9,148 | Accepted | Accepted | 89.06 | h,w = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(h)]
black = []
for i in range(h):
for j in range(w):
if s[i][j] == "#":
black.append([i,j])
for x,y in black:
flag = False
for a,b in [(0,1), (1,0), (0,-1), (-1,0)]:
if [x+a, y+b] in black: flag = True
if not flag:
print("No")
exit()
print("Yes") | h,w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
for i in range(h):
for j in range(w):
if s[i][j] == "#":
flag = False
for i_new, j_new in [(i+1, j), (i-1, j), (i,j+1), (i,j-1)]:
if i_new<0 or i_new>=h or j_new<0 or j_new>=w: continue
if s[i_new][j_new] == "#":
flag = True
break
if not flag:
print("No")
exit()
print("Yes")
| 15 | 16 | 386 | 508 | h, w = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(h)]
black = []
for i in range(h):
for j in range(w):
if s[i][j] == "#":
black.append([i, j])
for x, y in black:
flag = False
for a, b in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
if [x + a, y + b] in black:
flag = True
if not flag:
print("No")
exit()
print("Yes")
| h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
for i in range(h):
for j in range(w):
if s[i][j] == "#":
flag = False
for i_new, j_new in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]:
if i_new < 0 or i_new >= h or j_new < 0 or j_new >= w:
continue
if s[i_new][j_new] == "#":
flag = True
break
if not flag:
print("No")
exit()
print("Yes")
| false | 6.25 | [
"-s = [list(eval(input())) for _ in range(h)]",
"-black = []",
"+s = [eval(input()) for _ in range(h)]",
"- black.append([i, j])",
"-for x, y in black:",
"- flag = False",
"- for a, b in [(0, 1), (1, 0), (0, -1), (-1, 0)]:",
"- if [x + a, y + b] in black:",
"- flag = True",
"- if not flag:",
"- print(\"No\")",
"- exit()",
"+ flag = False",
"+ for i_new, j_new in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]:",
"+ if i_new < 0 or i_new >= h or j_new < 0 or j_new >= w:",
"+ continue",
"+ if s[i_new][j_new] == \"#\":",
"+ flag = True",
"+ break",
"+ if not flag:",
"+ print(\"No\")",
"+ exit()"
] | false | 0.0867 | 0.133054 | 0.65162 | [
"s099114381",
"s842911369"
] |
u287500079 | p02861 | python | s584239668 | s951965076 | 494 | 322 | 8,052 | 70,760 | Accepted | Accepted | 34.82 | import math
from itertools import permutations
n = int(eval(input()))
xy = [[int(i) for i in input().split()] for _ in range(n)]
arr = list(permutations(list(range(n)), n))
ans = 0
for i in range(len(arr)):
for j in range(1, n):
ans += math.sqrt(pow(xy[arr[i][j]][0] - xy[arr[i][j-1]][0], 2) + pow(xy[arr[i][j]][1] - xy[arr[i][j-1]][1], 2))
ans /= len(arr)
print(ans)
| 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 STR(): return eval(input())
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 = sys.maxsize
mod = 10 ** 9 + 7
n = INT()
xy = [LIST() for _ in range(n)]
a = list(permutations(xy, n))
l = len(a)
ans = 0
for i in range(l):
tmp = 0
for j in range(n - 1):
tmp += sqrt((a[i][j][0] - a[i][j+1][0]) ** 2 + (a[i][j][1] - a[i][j+1][1]) ** 2)
ans += tmp
ans /= l
print(ans) | 11 | 30 | 378 | 1,027 | import math
from itertools import permutations
n = int(eval(input()))
xy = [[int(i) for i in input().split()] for _ in range(n)]
arr = list(permutations(list(range(n)), n))
ans = 0
for i in range(len(arr)):
for j in range(1, n):
ans += math.sqrt(
pow(xy[arr[i][j]][0] - xy[arr[i][j - 1]][0], 2)
+ pow(xy[arr[i][j]][1] - xy[arr[i][j - 1]][1], 2)
)
ans /= len(arr)
print(ans)
| 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 STR():
return eval(input())
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 = sys.maxsize
mod = 10**9 + 7
n = INT()
xy = [LIST() for _ in range(n)]
a = list(permutations(xy, n))
l = len(a)
ans = 0
for i in range(l):
tmp = 0
for j in range(n - 1):
tmp += sqrt(
(a[i][j][0] - a[i][j + 1][0]) ** 2 + (a[i][j][1] - a[i][j + 1][1]) ** 2
)
ans += tmp
ans /= l
print(ans)
| false | 63.333333 | [
"-import math",
"-from itertools import permutations",
"+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",
"-n = int(eval(input()))",
"-xy = [[int(i) for i in input().split()] for _ in range(n)]",
"-arr = list(permutations(list(range(n)), n))",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+",
"+def STR():",
"+ return eval(input())",
"+",
"+",
"+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 = sys.maxsize",
"+mod = 10**9 + 7",
"+n = INT()",
"+xy = [LIST() for _ in range(n)]",
"+a = list(permutations(xy, n))",
"+l = len(a)",
"-for i in range(len(arr)):",
"- for j in range(1, n):",
"- ans += math.sqrt(",
"- pow(xy[arr[i][j]][0] - xy[arr[i][j - 1]][0], 2)",
"- + pow(xy[arr[i][j]][1] - xy[arr[i][j - 1]][1], 2)",
"+for i in range(l):",
"+ tmp = 0",
"+ for j in range(n - 1):",
"+ tmp += sqrt(",
"+ (a[i][j][0] - a[i][j + 1][0]) ** 2 + (a[i][j][1] - a[i][j + 1][1]) ** 2",
"-ans /= len(arr)",
"+ ans += tmp",
"+ans /= l"
] | false | 0.046653 | 0.044591 | 1.046256 | [
"s584239668",
"s951965076"
] |
u319245933 | p02606 | python | s506409622 | s188113749 | 85 | 66 | 61,648 | 61,760 | Accepted | Accepted | 22.35 | L,R,d = list(map(int,input().split()))
print((len([i for i in range(L,R+1) if i % d == 0]))) | L,R,d=list(map(int,input().split()));print((R//d-(L-1)//d)) | 2 | 1 | 85 | 51 | L, R, d = list(map(int, input().split()))
print((len([i for i in range(L, R + 1) if i % d == 0])))
| L, R, d = list(map(int, input().split()))
print((R // d - (L - 1) // d))
| false | 50 | [
"-print((len([i for i in range(L, R + 1) if i % d == 0])))",
"+print((R // d - (L - 1) // d))"
] | false | 0.041577 | 0.040755 | 1.020158 | [
"s506409622",
"s188113749"
] |
u729133443 | p03448 | python | s682150044 | s032241396 | 188 | 50 | 40,304 | 3,060 | Accepted | Accepted | 73.4 | a,b,c,x=[int(eval(input()))+1for _ in[0]*4];print((sum(x-1==(10*s+2*t+r)*50for s in range(a)for t in range(b)for r in range(c)))) | R=range;a,b,c,x=[int(eval(input()))+1for _ in[0]*4];print((sum(x-1==(10*s+2*t+r)*50for s in R(a)for t in R(b)for r in R(c)))) | 1 | 1 | 121 | 117 | a, b, c, x = [int(eval(input())) + 1 for _ in [0] * 4]
print(
(
sum(
x - 1 == (10 * s + 2 * t + r) * 50
for s in range(a)
for t in range(b)
for r in range(c)
)
)
)
| R = range
a, b, c, x = [int(eval(input())) + 1 for _ in [0] * 4]
print(
(sum(x - 1 == (10 * s + 2 * t + r) * 50 for s in R(a) for t in R(b) for r in R(c)))
)
| false | 0 | [
"+R = range",
"- (",
"- sum(",
"- x - 1 == (10 * s + 2 * t + r) * 50",
"- for s in range(a)",
"- for t in range(b)",
"- for r in range(c)",
"- )",
"- )",
"+ (sum(x - 1 == (10 * s + 2 * t + r) * 50 for s in R(a) for t in R(b) for r in R(c)))"
] | false | 0.057686 | 0.055655 | 1.036509 | [
"s682150044",
"s032241396"
] |
u667978773 | p02994 | python | s339607166 | s281355519 | 181 | 167 | 38,384 | 38,256 | Accepted | Accepted | 7.73 | n,l=(list(map(int,input().split())))
if l>0:
print((int((n*l+(n+1)*n/2-n-l))))
elif l+n-1<0:
print((int((n*l+(n+1)*n/2-n-(l+n-1)))))
else:
print((int((n*l+(n+1)*n/2-n)))) | n,l=(list(map(int,input().split())))
if l>0:
print((sum(range(l+1,l+n))))
elif l+n-1<0:
print((sum(range(l,l+n-1))))
else:
print((sum(range(l,l+n)))) | 7 | 7 | 170 | 149 | n, l = list(map(int, input().split()))
if l > 0:
print((int((n * l + (n + 1) * n / 2 - n - l))))
elif l + n - 1 < 0:
print((int((n * l + (n + 1) * n / 2 - n - (l + n - 1)))))
else:
print((int((n * l + (n + 1) * n / 2 - n))))
| n, l = list(map(int, input().split()))
if l > 0:
print((sum(range(l + 1, l + n))))
elif l + n - 1 < 0:
print((sum(range(l, l + n - 1))))
else:
print((sum(range(l, l + n))))
| false | 0 | [
"- print((int((n * l + (n + 1) * n / 2 - n - l))))",
"+ print((sum(range(l + 1, l + n))))",
"- print((int((n * l + (n + 1) * n / 2 - n - (l + n - 1)))))",
"+ print((sum(range(l, l + n - 1))))",
"- print((int((n * l + (n + 1) * n / 2 - n))))",
"+ print((sum(range(l, l + n))))"
] | false | 0.068899 | 0.070158 | 0.982058 | [
"s339607166",
"s281355519"
] |
u285891772 | p03044 | python | s383940733 | s619131256 | 812 | 727 | 108,092 | 99,940 | Accepted | Accepted | 10.47 | import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
uvw = [LIST() for _ in range(N-1)]
graph = defaultdict(list)
for u, v, w in uvw:
graph[u-1].append((v-1, w))
graph[v-1].append((u-1, w))
#print(graph)
colors=[0]*N
colors[0]=1
def DFS(node):
for x, w in graph[node]:
if not colors[x]:
if w%2:
colors[x] = colors[node]*(-1)
else:
colors[x] = colors[node]
DFS(x)
DFS(0)
#print(colors)
for x in colors:
if x == 1:
print((0))
else:
print((1))
| import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
uvw = [LIST() for _ in range(N-1)]
graph = [[] for _ in range(N)]
for u, v, w in uvw:
graph[u-1].append((v-1, w))
graph[v-1].append((u-1, w))
#print(graph)
color = [-1]*N
color[0] = 0
def DFS(node):
for i, w in graph[node]:
if color[i] == -1:
if w%2:
color[i] = color[node]^1
else:
color[i] = color[node]
DFS(i)
DFS(0)
#print(color)
for x in color:
print(x)
| 55 | 50 | 1,330 | 1,292 | import sys, re
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
) # , log2
from collections import deque, defaultdict, Counter
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
uvw = [LIST() for _ in range(N - 1)]
graph = defaultdict(list)
for u, v, w in uvw:
graph[u - 1].append((v - 1, w))
graph[v - 1].append((u - 1, w))
# print(graph)
colors = [0] * N
colors[0] = 1
def DFS(node):
for x, w in graph[node]:
if not colors[x]:
if w % 2:
colors[x] = colors[node] * (-1)
else:
colors[x] = colors[node]
DFS(x)
DFS(0)
# print(colors)
for x in colors:
if x == 1:
print((0))
else:
print((1))
| import sys, re
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
) # , log2
from collections import deque, defaultdict, Counter
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
uvw = [LIST() for _ in range(N - 1)]
graph = [[] for _ in range(N)]
for u, v, w in uvw:
graph[u - 1].append((v - 1, w))
graph[v - 1].append((u - 1, w))
# print(graph)
color = [-1] * N
color[0] = 0
def DFS(node):
for i, w in graph[node]:
if color[i] == -1:
if w % 2:
color[i] = color[node] ^ 1
else:
color[i] = color[node]
DFS(i)
DFS(0)
# print(color)
for x in color:
print(x)
| false | 9.090909 | [
"-graph = defaultdict(list)",
"+graph = [[] for _ in range(N)]",
"-colors = [0] * N",
"-colors[0] = 1",
"+color = [-1] * N",
"+color[0] = 0",
"- for x, w in graph[node]:",
"- if not colors[x]:",
"+ for i, w in graph[node]:",
"+ if color[i] == -1:",
"- colors[x] = colors[node] * (-1)",
"+ color[i] = color[node] ^ 1",
"- colors[x] = colors[node]",
"- DFS(x)",
"+ color[i] = color[node]",
"+ DFS(i)",
"-# print(colors)",
"-for x in colors:",
"- if x == 1:",
"- print((0))",
"- else:",
"- print((1))",
"+# print(color)",
"+for x in color:",
"+ print(x)"
] | false | 0.073782 | 0.070417 | 1.047792 | [
"s383940733",
"s619131256"
] |
u151625340 | p03006 | python | s539511880 | s143903504 | 209 | 177 | 41,584 | 39,664 | Accepted | Accepted | 15.31 | N = int(eval(input()))
X = []
for i in range(N):
xi,yi = list(map(int,input().split()))
X.append([xi,yi])
L = []
d = {}
for i in range(N):
for j in range(N):
if i == j:
continue
x,y = X[i][0]-X[j][0],X[i][1]-X[j][1]
#L.append([x,y])
if not x in d:
d[x] = {}
if not y in d[x]:
d[x][y] = 1
else:
d[x][y] += 1
m = 0
for k in list(d.keys()):
for kk in list(d[k].keys()):
m = max(m,d[k][kk])
print((N-m))
| from collections import Counter
N = int(eval(input()))
if N == 1:
print((1))
else:
X = []
for i in range(N):
xi,yi = list(map(int,input().split()))
X.append((xi,yi))
L = []
for i in range(N):
for j in range(N):
if i == j:
continue
x,y = X[i][0]-X[j][0],X[i][1]-X[j][1]
L.append((x,y))
m = Counter(L).most_common()[0][1]
print((N-m))
| 26 | 18 | 537 | 438 | N = int(eval(input()))
X = []
for i in range(N):
xi, yi = list(map(int, input().split()))
X.append([xi, yi])
L = []
d = {}
for i in range(N):
for j in range(N):
if i == j:
continue
x, y = X[i][0] - X[j][0], X[i][1] - X[j][1]
# L.append([x,y])
if not x in d:
d[x] = {}
if not y in d[x]:
d[x][y] = 1
else:
d[x][y] += 1
m = 0
for k in list(d.keys()):
for kk in list(d[k].keys()):
m = max(m, d[k][kk])
print((N - m))
| from collections import Counter
N = int(eval(input()))
if N == 1:
print((1))
else:
X = []
for i in range(N):
xi, yi = list(map(int, input().split()))
X.append((xi, yi))
L = []
for i in range(N):
for j in range(N):
if i == j:
continue
x, y = X[i][0] - X[j][0], X[i][1] - X[j][1]
L.append((x, y))
m = Counter(L).most_common()[0][1]
print((N - m))
| false | 30.769231 | [
"+from collections import Counter",
"+",
"-X = []",
"-for i in range(N):",
"- xi, yi = list(map(int, input().split()))",
"- X.append([xi, yi])",
"-L = []",
"-d = {}",
"-for i in range(N):",
"- for j in range(N):",
"- if i == j:",
"- continue",
"- x, y = X[i][0] - X[j][0], X[i][1] - X[j][1]",
"- # L.append([x,y])",
"- if not x in d:",
"- d[x] = {}",
"- if not y in d[x]:",
"- d[x][y] = 1",
"- else:",
"- d[x][y] += 1",
"-m = 0",
"-for k in list(d.keys()):",
"- for kk in list(d[k].keys()):",
"- m = max(m, d[k][kk])",
"-print((N - m))",
"+if N == 1:",
"+ print((1))",
"+else:",
"+ X = []",
"+ for i in range(N):",
"+ xi, yi = list(map(int, input().split()))",
"+ X.append((xi, yi))",
"+ L = []",
"+ for i in range(N):",
"+ for j in range(N):",
"+ if i == j:",
"+ continue",
"+ x, y = X[i][0] - X[j][0], X[i][1] - X[j][1]",
"+ L.append((x, y))",
"+ m = Counter(L).most_common()[0][1]",
"+ print((N - m))"
] | false | 0.046002 | 0.04586 | 1.003103 | [
"s539511880",
"s143903504"
] |
u952708174 | p03163 | python | s283314295 | s268655612 | 843 | 332 | 135,168 | 20,996 | Accepted | Accepted | 60.62 | from collections import defaultdict
N, W = [int(i) for i in input().split()]
Things = [[int(i) for i in input().split()] for j in range(N)]
dp = defaultdict(int)
dp[0] = 0
for w, v in Things:
for nw, nv in list(dp.items()):
if nw + w <= W:
dp[nw + w] = max(dp[nw + w], nv + v)
print((max(dp.values()))) | def d_knapsack1(N, W, Goods):
"""
N個の品物のi番目について、重さはw_i, 価値はv_iである。
品物のいくつかを選んでナップサックに入れるが、品物の重さの総和はW以下とする。
品物の価値の総和の最大値を求めよ。
※ 1 <= w_i <= W <= 10^5 と、重さの制約がゆるめ
"""
import numpy as np
# dp[w]: 重さwの品物の入れ方で達成できる価値の最大値
dp = np.zeros(W + 1, dtype=np.int64)
for w, v in Goods:
# 重さi(0<=i<=W-w)のときの価値に対し注目している荷物を入れて、
# 重さi+wのときの価値を更新する
np.maximum(dp[:W + 1 - w] + v, dp[w:], out=dp[w:])
# outで指定した箇所のみ上書き。与えないと新しく配列が作られる
return dp[-1]
N, W = [int(i) for i in input().split()]
Goods = [[int(i) for i in input().split()] for j in range(N)]
print((d_knapsack1(N, W, Goods))) | 11 | 20 | 335 | 659 | from collections import defaultdict
N, W = [int(i) for i in input().split()]
Things = [[int(i) for i in input().split()] for j in range(N)]
dp = defaultdict(int)
dp[0] = 0
for w, v in Things:
for nw, nv in list(dp.items()):
if nw + w <= W:
dp[nw + w] = max(dp[nw + w], nv + v)
print((max(dp.values())))
| def d_knapsack1(N, W, Goods):
"""
N個の品物のi番目について、重さはw_i, 価値はv_iである。
品物のいくつかを選んでナップサックに入れるが、品物の重さの総和はW以下とする。
品物の価値の総和の最大値を求めよ。
※ 1 <= w_i <= W <= 10^5 と、重さの制約がゆるめ
"""
import numpy as np
# dp[w]: 重さwの品物の入れ方で達成できる価値の最大値
dp = np.zeros(W + 1, dtype=np.int64)
for w, v in Goods:
# 重さi(0<=i<=W-w)のときの価値に対し注目している荷物を入れて、
# 重さi+wのときの価値を更新する
np.maximum(dp[: W + 1 - w] + v, dp[w:], out=dp[w:])
# outで指定した箇所のみ上書き。与えないと新しく配列が作られる
return dp[-1]
N, W = [int(i) for i in input().split()]
Goods = [[int(i) for i in input().split()] for j in range(N)]
print((d_knapsack1(N, W, Goods)))
| false | 45 | [
"-from collections import defaultdict",
"+def d_knapsack1(N, W, Goods):",
"+ \"\"\"",
"+ N個の品物のi番目について、重さはw_i, 価値はv_iである。",
"+ 品物のいくつかを選んでナップサックに入れるが、品物の重さの総和はW以下とする。",
"+ 品物の価値の総和の最大値を求めよ。",
"+ ※ 1 <= w_i <= W <= 10^5 と、重さの制約がゆるめ",
"+ \"\"\"",
"+ import numpy as np",
"+",
"+ # dp[w]: 重さwの品物の入れ方で達成できる価値の最大値",
"+ dp = np.zeros(W + 1, dtype=np.int64)",
"+ for w, v in Goods:",
"+ # 重さi(0<=i<=W-w)のときの価値に対し注目している荷物を入れて、",
"+ # 重さi+wのときの価値を更新する",
"+ np.maximum(dp[: W + 1 - w] + v, dp[w:], out=dp[w:])",
"+ # outで指定した箇所のみ上書き。与えないと新しく配列が作られる",
"+ return dp[-1]",
"+",
"-Things = [[int(i) for i in input().split()] for j in range(N)]",
"-dp = defaultdict(int)",
"-dp[0] = 0",
"-for w, v in Things:",
"- for nw, nv in list(dp.items()):",
"- if nw + w <= W:",
"- dp[nw + w] = max(dp[nw + w], nv + v)",
"-print((max(dp.values())))",
"+Goods = [[int(i) for i in input().split()] for j in range(N)]",
"+print((d_knapsack1(N, W, Goods)))"
] | false | 0.042631 | 0.940747 | 0.045317 | [
"s283314295",
"s268655612"
] |
u714225686 | p03031 | python | s133758937 | s471023509 | 309 | 20 | 21,208 | 3,188 | Accepted | Accepted | 93.53 | # n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)] # 二次元配列入力 二次元マップみたいな入力のとき
# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b)) # 0埋めのときの出力
# 000100-0.987654
import numpy as np
import math
import copy
N, M=list(map(int, input().split()))
# 各スイッチがどの電球につながっているかの情報をビットで保持する配列
# 1番目のスイッチが2番目と3番目の電球につながっていた場合以下のようにいなる
# (1 << 1) | (1 << 2) = (110)b ※ zero index
mask_list = [0 for _ in range(N)]
for i in range(M):
switches = list(map(int, input().split()))
# switchesの2番目以降の要素には、スイッチの番号が入っている
for j in range(1, len(switches)):
sw_num = (switches[j] - 1) # スイッチの番号をzero index で管理する
sw_bit = 1 << i # つながっている電球を二進数で表す
mask_list[sw_num] = mask_list[sw_num] | sw_bit
conds = list(map(int, input().split()))
conds_dec = 0
for i in range(len(conds)):
conds_dec |= conds[i] << i
light_num = 0
for s in range(1 << N):
t = 0
for i in range(N):
if s >> i & 1:
t = t ^ mask_list[i]
if t == conds_dec:
light_num += 1
print(light_num)
| # n=int(sys.stdin.readline())
# a,b=map(int, sys.stdin.readline().split())
# c=list(map(int, sys.stdin.readline().split()))
# s=[list(map(int,list(sys.stdin.readline()))) for i in range(h)] # 二次元配列入力 二次元マップみたいな入力のとき
# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b)) # 0埋めのときの出力
# 000100-0.987654
import math
import sys
#sys.stdin = open("input.txt")
N, M=list(map(int, sys.stdin.readline().split()))
# 各スイッチがどの電球につながっているかの情報をビットで保持する配列
# 1番目のスイッチが2番目と3番目の電球につながっていた場合以下のようになる
# (1 << 1) | (1 << 2) = (110)b ※ zero index
bulb_list = [0 for _ in range(N)]
for bulb_idx in range(M):
switches = list(map(int, sys.stdin.readline().split()))
bulb_bit = 1 << bulb_idx # つながっている電球を二進数で表す
# switchesの2番目以降の要素には、スイッチの番号が入っている
for sw in switches[1::]:
sw_idx = (sw - 1) # スイッチの番号をzero indexに変換する
bulb_list[sw_idx] = bulb_list[sw_idx] | bulb_bit
bulb_conds = list(map(int, sys.stdin.readline().split()))
bulb_cond = 0
for i, bc in enumerate(bulb_conds):
bulb_cond |= bc << i
light_num = 0
# N = 3 の時
# 000, 001, 010, 011, 100, 101, 110, 111 の8パターンで、
# スイッチを押す全てのパターンを表現することが出来る
for bit_ptn in range(1 << N):
t = 0 # tはbit_ptnが表すスイッチの組み合わせを全て押したときの電球の状態を表す(最初は全部消えている)
for i in range(N):
if bit_ptn >> i & 1:
t = t ^ bulb_list[i]
if t == bulb_cond:
light_num += 1
print(light_num)
| 49 | 49 | 1,157 | 1,412 | # n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)] # 二次元配列入力 二次元マップみたいな入力のとき
# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b)) # 0埋めのときの出力
# 000100-0.987654
import numpy as np
import math
import copy
N, M = list(map(int, input().split()))
# 各スイッチがどの電球につながっているかの情報をビットで保持する配列
# 1番目のスイッチが2番目と3番目の電球につながっていた場合以下のようにいなる
# (1 << 1) | (1 << 2) = (110)b ※ zero index
mask_list = [0 for _ in range(N)]
for i in range(M):
switches = list(map(int, input().split()))
# switchesの2番目以降の要素には、スイッチの番号が入っている
for j in range(1, len(switches)):
sw_num = switches[j] - 1 # スイッチの番号をzero index で管理する
sw_bit = 1 << i # つながっている電球を二進数で表す
mask_list[sw_num] = mask_list[sw_num] | sw_bit
conds = list(map(int, input().split()))
conds_dec = 0
for i in range(len(conds)):
conds_dec |= conds[i] << i
light_num = 0
for s in range(1 << N):
t = 0
for i in range(N):
if s >> i & 1:
t = t ^ mask_list[i]
if t == conds_dec:
light_num += 1
print(light_num)
| # n=int(sys.stdin.readline())
# a,b=map(int, sys.stdin.readline().split())
# c=list(map(int, sys.stdin.readline().split()))
# s=[list(map(int,list(sys.stdin.readline()))) for i in range(h)] # 二次元配列入力 二次元マップみたいな入力のとき
# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b)) # 0埋めのときの出力
# 000100-0.987654
import math
import sys
# sys.stdin = open("input.txt")
N, M = list(map(int, sys.stdin.readline().split()))
# 各スイッチがどの電球につながっているかの情報をビットで保持する配列
# 1番目のスイッチが2番目と3番目の電球につながっていた場合以下のようになる
# (1 << 1) | (1 << 2) = (110)b ※ zero index
bulb_list = [0 for _ in range(N)]
for bulb_idx in range(M):
switches = list(map(int, sys.stdin.readline().split()))
bulb_bit = 1 << bulb_idx # つながっている電球を二進数で表す
# switchesの2番目以降の要素には、スイッチの番号が入っている
for sw in switches[1::]:
sw_idx = sw - 1 # スイッチの番号をzero indexに変換する
bulb_list[sw_idx] = bulb_list[sw_idx] | bulb_bit
bulb_conds = list(map(int, sys.stdin.readline().split()))
bulb_cond = 0
for i, bc in enumerate(bulb_conds):
bulb_cond |= bc << i
light_num = 0
# N = 3 の時
# 000, 001, 010, 011, 100, 101, 110, 111 の8パターンで、
# スイッチを押す全てのパターンを表現することが出来る
for bit_ptn in range(1 << N):
t = 0 # tはbit_ptnが表すスイッチの組み合わせを全て押したときの電球の状態を表す(最初は全部消えている)
for i in range(N):
if bit_ptn >> i & 1:
t = t ^ bulb_list[i]
if t == bulb_cond:
light_num += 1
print(light_num)
| false | 0 | [
"-# n=int(input())",
"-# a,b=map(int, input().split())",
"-# c=list(map(int, input().split()))",
"-# s=[list(map(int,list(input()))) for i in range(h)] # 二次元配列入力 二次元マップみたいな入力のとき",
"+# n=int(sys.stdin.readline())",
"+# a,b=map(int, sys.stdin.readline().split())",
"+# c=list(map(int, sys.stdin.readline().split()))",
"+# s=[list(map(int,list(sys.stdin.readline()))) for i in range(h)] # 二次元配列入力 二次元マップみたいな入力のとき",
"-import numpy as np",
"-import copy",
"+import sys",
"-N, M = list(map(int, input().split()))",
"+# sys.stdin = open(\"input.txt\")",
"+N, M = list(map(int, sys.stdin.readline().split()))",
"-# 1番目のスイッチが2番目と3番目の電球につながっていた場合以下のようにいなる",
"+# 1番目のスイッチが2番目と3番目の電球につながっていた場合以下のようになる",
"-mask_list = [0 for _ in range(N)]",
"-for i in range(M):",
"- switches = list(map(int, input().split()))",
"+bulb_list = [0 for _ in range(N)]",
"+for bulb_idx in range(M):",
"+ switches = list(map(int, sys.stdin.readline().split()))",
"+ bulb_bit = 1 << bulb_idx # つながっている電球を二進数で表す",
"- for j in range(1, len(switches)):",
"- sw_num = switches[j] - 1 # スイッチの番号をzero index で管理する",
"- sw_bit = 1 << i # つながっている電球を二進数で表す",
"- mask_list[sw_num] = mask_list[sw_num] | sw_bit",
"-conds = list(map(int, input().split()))",
"-conds_dec = 0",
"-for i in range(len(conds)):",
"- conds_dec |= conds[i] << i",
"+ for sw in switches[1::]:",
"+ sw_idx = sw - 1 # スイッチの番号をzero indexに変換する",
"+ bulb_list[sw_idx] = bulb_list[sw_idx] | bulb_bit",
"+bulb_conds = list(map(int, sys.stdin.readline().split()))",
"+bulb_cond = 0",
"+for i, bc in enumerate(bulb_conds):",
"+ bulb_cond |= bc << i",
"-for s in range(1 << N):",
"- t = 0",
"+# N = 3 の時",
"+# 000, 001, 010, 011, 100, 101, 110, 111 の8パターンで、",
"+# スイッチを押す全てのパターンを表現することが出来る",
"+for bit_ptn in range(1 << N):",
"+ t = 0 # tはbit_ptnが表すスイッチの組み合わせを全て押したときの電球の状態を表す(最初は全部消えている)",
"- if s >> i & 1:",
"- t = t ^ mask_list[i]",
"- if t == conds_dec:",
"+ if bit_ptn >> i & 1:",
"+ t = t ^ bulb_list[i]",
"+ if t == bulb_cond:"
] | false | 0.044662 | 0.044268 | 1.008899 | [
"s133758937",
"s471023509"
] |
u113971909 | p02707 | python | s524258956 | s305410861 | 149 | 112 | 32,368 | 33,036 | Accepted | Accepted | 24.83 | n=int(eval(input()))
A=list(map(int,input().split()))
R=[0]*n
for a in A:
R[a-1]+=1
for r in R:
print(r) | #!/usr/bin python3
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
A = list(map(int, input().split()))
ret = [0]*N
for a in A:
ret[a-1]+=1
print(('\n'.join(map(str, ret))))
if __name__ == '__main__':
main() | 7 | 16 | 108 | 297 | n = int(eval(input()))
A = list(map(int, input().split()))
R = [0] * n
for a in A:
R[a - 1] += 1
for r in R:
print(r)
| #!/usr/bin python3
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
A = list(map(int, input().split()))
ret = [0] * N
for a in A:
ret[a - 1] += 1
print(("\n".join(map(str, ret))))
if __name__ == "__main__":
main()
| false | 56.25 | [
"-n = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-R = [0] * n",
"-for a in A:",
"- R[a - 1] += 1",
"-for r in R:",
"- print(r)",
"+#!/usr/bin python3",
"+# -*- coding: utf-8 -*-",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+",
"+def main():",
"+ N = int(eval(input()))",
"+ A = list(map(int, input().split()))",
"+ ret = [0] * N",
"+ for a in A:",
"+ ret[a - 1] += 1",
"+ print((\"\\n\".join(map(str, ret))))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.038868 | 0.043006 | 0.903779 | [
"s524258956",
"s305410861"
] |
u656153606 | p02392 | python | s383687323 | s445898318 | 30 | 20 | 7,452 | 7,640 | Accepted | Accepted | 33.33 | Input = input().split()
if Input[2] > Input[1]:
if Input[1] > Input[0]:
print("Yes")
else:
print("No")
else:
print("No") | a, b, c = [int(i) for i in input().split()]
if a < b:
if b < c:
print('Yes')
else:
print('No')
else:
print('No') | 8 | 9 | 155 | 149 | Input = input().split()
if Input[2] > Input[1]:
if Input[1] > Input[0]:
print("Yes")
else:
print("No")
else:
print("No")
| a, b, c = [int(i) for i in input().split()]
if a < b:
if b < c:
print("Yes")
else:
print("No")
else:
print("No")
| false | 11.111111 | [
"-Input = input().split()",
"-if Input[2] > Input[1]:",
"- if Input[1] > Input[0]:",
"+a, b, c = [int(i) for i in input().split()]",
"+if a < b:",
"+ if b < c:"
] | false | 0.037903 | 0.15792 | 0.240013 | [
"s383687323",
"s445898318"
] |
u213580455 | p02995 | python | s733826398 | s550365785 | 37 | 17 | 5,304 | 3,064 | Accepted | Accepted | 54.05 | from fractions import gcd
# def gcd(x, y):
# while(y != 0):
# temp = y
# y = x%y
# x = temp
# return y
def getMultiCount(start, end, times):
if end < times: return 0
s = start-(start%times)
if s != start: s += times
e = end-(end%times)
if s > e: return 0
return ((e-s)//times)+1
def answer(a, b, c, d):
cCount = getMultiCount(a, b, c)
dCount = getMultiCount(a, b, d)
cdCount = getMultiCount(a, b, c*d//gcd(c,d))
return (b-a+1)-(cCount + dCount - cdCount)
a, b, c, d = list(map(int, input().split()))
print((answer(a, b, c, d))) | def gcd(a, b):
a, b = sorted([a, b], reverse=True)
while(b != 0):
a, b = (b, a%b)
return a
def getMultiCount(start, end, times):
if end < times: return 0
s = start-(start%times)
if s != start: s += times
e = end-(end%times)
if s > e: return 0
return ((e-s)//times)+1
def answer(a, b, c, d):
cCount = getMultiCount(a, b, c)
dCount = getMultiCount(a, b, d)
cdCount = getMultiCount(a, b, c*d//gcd(c,d))
return (b-a+1)-(cCount + dCount - cdCount)
a, b, c, d = list(map(int, input().split()))
print((answer(a, b, c, d))) | 24 | 22 | 621 | 595 | from fractions import gcd
# def gcd(x, y):
# while(y != 0):
# temp = y
# y = x%y
# x = temp
# return y
def getMultiCount(start, end, times):
if end < times:
return 0
s = start - (start % times)
if s != start:
s += times
e = end - (end % times)
if s > e:
return 0
return ((e - s) // times) + 1
def answer(a, b, c, d):
cCount = getMultiCount(a, b, c)
dCount = getMultiCount(a, b, d)
cdCount = getMultiCount(a, b, c * d // gcd(c, d))
return (b - a + 1) - (cCount + dCount - cdCount)
a, b, c, d = list(map(int, input().split()))
print((answer(a, b, c, d)))
| def gcd(a, b):
a, b = sorted([a, b], reverse=True)
while b != 0:
a, b = (b, a % b)
return a
def getMultiCount(start, end, times):
if end < times:
return 0
s = start - (start % times)
if s != start:
s += times
e = end - (end % times)
if s > e:
return 0
return ((e - s) // times) + 1
def answer(a, b, c, d):
cCount = getMultiCount(a, b, c)
dCount = getMultiCount(a, b, d)
cdCount = getMultiCount(a, b, c * d // gcd(c, d))
return (b - a + 1) - (cCount + dCount - cdCount)
a, b, c, d = list(map(int, input().split()))
print((answer(a, b, c, d)))
| false | 8.333333 | [
"-from fractions import gcd",
"+def gcd(a, b):",
"+ a, b = sorted([a, b], reverse=True)",
"+ while b != 0:",
"+ a, b = (b, a % b)",
"+ return a",
"-# def gcd(x, y):",
"-# while(y != 0):",
"-# temp = y",
"-# y = x%y",
"-# x = temp",
"-# return y",
"+"
] | false | 0.152728 | 0.133561 | 1.143509 | [
"s733826398",
"s550365785"
] |
u073852194 | p03287 | python | s494722916 | s119244067 | 248 | 92 | 64,280 | 16,552 | Accepted | Accepted | 62.9 | from collections import Counter
n,m = list(map(int,input().split()))
A = list(map(int,input().split()))
S = [0]
s = 0
for i in range(n):
s += A[i]
S += [s]
R = []
for i in range(n+1):
R += [S[i]%m]
R = Counter(R)
ans = 0
for r in list(R.values()):
ans += r*(r-1)//2
print(ans) | from collections import Counter
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
S = [0]
for i in range(N):
S.append((S[-1]+A[i])%M)
C = Counter(S)
ans = 0
for v in list(C.values()):
ans += v*(v-1)//2
print(ans) | 25 | 18 | 307 | 254 | from collections import Counter
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
S = [0]
s = 0
for i in range(n):
s += A[i]
S += [s]
R = []
for i in range(n + 1):
R += [S[i] % m]
R = Counter(R)
ans = 0
for r in list(R.values()):
ans += r * (r - 1) // 2
print(ans)
| from collections import Counter
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
S = [0]
for i in range(N):
S.append((S[-1] + A[i]) % M)
C = Counter(S)
ans = 0
for v in list(C.values()):
ans += v * (v - 1) // 2
print(ans)
| false | 28 | [
"-n, m = list(map(int, input().split()))",
"+N, M = list(map(int, input().split()))",
"-s = 0",
"-for i in range(n):",
"- s += A[i]",
"- S += [s]",
"-R = []",
"-for i in range(n + 1):",
"- R += [S[i] % m]",
"-R = Counter(R)",
"+for i in range(N):",
"+ S.append((S[-1] + A[i]) % M)",
"+C = Counter(S)",
"-for r in list(R.values()):",
"- ans += r * (r - 1) // 2",
"+for v in list(C.values()):",
"+ ans += v * (v - 1) // 2"
] | false | 0.035469 | 0.080544 | 0.440362 | [
"s494722916",
"s119244067"
] |
u150984829 | p02275 | python | s028091213 | s301297315 | 2,660 | 930 | 224,508 | 224,412 | Accepted | Accepted | 65.04 | n=int(eval(input()))
A=list(map(int,input().split()))
m=10001
B=A[:]
C=[0]*m
for a in A:C[a]+=1
for i in range(1,m):C[i]+=C[i-1]
for j in A[::-1]:B[C[j]-1]=j;C[j]-=1
print((*B))
| eval(input())
A=list(map(int,input().split()))
B=[]
C=[0]*(max(A)+1)
for a in A:C[a]+=1
i=0
for k in C:B+=[str(i)]*k;i+=1
print((' '.join(B)))
| 9 | 8 | 178 | 142 | n = int(eval(input()))
A = list(map(int, input().split()))
m = 10001
B = A[:]
C = [0] * m
for a in A:
C[a] += 1
for i in range(1, m):
C[i] += C[i - 1]
for j in A[::-1]:
B[C[j] - 1] = j
C[j] -= 1
print((*B))
| eval(input())
A = list(map(int, input().split()))
B = []
C = [0] * (max(A) + 1)
for a in A:
C[a] += 1
i = 0
for k in C:
B += [str(i)] * k
i += 1
print((" ".join(B)))
| false | 11.111111 | [
"-n = int(eval(input()))",
"+eval(input())",
"-m = 10001",
"-B = A[:]",
"-C = [0] * m",
"+B = []",
"+C = [0] * (max(A) + 1)",
"-for i in range(1, m):",
"- C[i] += C[i - 1]",
"-for j in A[::-1]:",
"- B[C[j] - 1] = j",
"- C[j] -= 1",
"-print((*B))",
"+i = 0",
"+for k in C:",
"+ B += [str(i)] * k",
"+ i += 1",
"+print((\" \".join(B)))"
] | false | 0.046634 | 0.041095 | 1.134807 | [
"s028091213",
"s301297315"
] |
u678167152 | p03044 | python | s980622789 | s271146489 | 1,054 | 652 | 82,908 | 76,488 | Accepted | Accepted | 38.14 | import sys
sys.setrecursionlimit(10**8)
N = int(input())
edge = [[] for _ in range(N+1)]
for i in range(N-1):
u,v,w = map(int, input().split())
edge[u].append([v,w%2])
edge[v].append([u,w%2])
color = [0]*(N+1)
visited = [False]*(N+1)
def dfs(u):
for v,w in edge[u]:
if visited[v]==False:
#print(v)
visited[v]=True
color[v]=color[u]^w
dfs(v)
return 0
visited[1]=True
dfs(1)
ans = color[1:]
print(*ans,sep='\n')
| import sys
sys.setrecursionlimit(10**8)
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N-1):
u,v,w = map(int, input().split())
w %= 2
v -= 1
u -= 1
edge[u].append((w,v))
edge[v].append((w,u))
color = [-1]*N
#print(edge)
def dfs(s,col):
#print(s,col)
for w,v in edge[s]:
if color[v]==-1:
color[v] = col^w
dfs(v,color[v])
return
color[0] = 0
dfs(0,0)
ans = color
#print(ans)
print(*ans,sep='\n')
| 23 | 30 | 470 | 476 | import sys
sys.setrecursionlimit(10**8)
N = int(input())
edge = [[] for _ in range(N + 1)]
for i in range(N - 1):
u, v, w = map(int, input().split())
edge[u].append([v, w % 2])
edge[v].append([u, w % 2])
color = [0] * (N + 1)
visited = [False] * (N + 1)
def dfs(u):
for v, w in edge[u]:
if visited[v] == False:
# print(v)
visited[v] = True
color[v] = color[u] ^ w
dfs(v)
return 0
visited[1] = True
dfs(1)
ans = color[1:]
print(*ans, sep="\n")
| import sys
sys.setrecursionlimit(10**8)
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N - 1):
u, v, w = map(int, input().split())
w %= 2
v -= 1
u -= 1
edge[u].append((w, v))
edge[v].append((w, u))
color = [-1] * N
# print(edge)
def dfs(s, col):
# print(s,col)
for w, v in edge[s]:
if color[v] == -1:
color[v] = col ^ w
dfs(v, color[v])
return
color[0] = 0
dfs(0, 0)
ans = color
# print(ans)
print(*ans, sep="\n")
| false | 23.333333 | [
"-edge = [[] for _ in range(N + 1)]",
"-for i in range(N - 1):",
"+edge = [[] for _ in range(N)]",
"+for _ in range(N - 1):",
"- edge[u].append([v, w % 2])",
"- edge[v].append([u, w % 2])",
"-color = [0] * (N + 1)",
"-visited = [False] * (N + 1)",
"+ w %= 2",
"+ v -= 1",
"+ u -= 1",
"+ edge[u].append((w, v))",
"+ edge[v].append((w, u))",
"+color = [-1] * N",
"+# print(edge)",
"+def dfs(s, col):",
"+ # print(s,col)",
"+ for w, v in edge[s]:",
"+ if color[v] == -1:",
"+ color[v] = col ^ w",
"+ dfs(v, color[v])",
"+ return",
"-def dfs(u):",
"- for v, w in edge[u]:",
"- if visited[v] == False:",
"- # print(v)",
"- visited[v] = True",
"- color[v] = color[u] ^ w",
"- dfs(v)",
"- return 0",
"-",
"-",
"-visited[1] = True",
"-dfs(1)",
"-ans = color[1:]",
"+color[0] = 0",
"+dfs(0, 0)",
"+ans = color",
"+# print(ans)"
] | false | 0.090241 | 0.039058 | 2.310448 | [
"s980622789",
"s271146489"
] |
u852690916 | p03329 | python | s507292993 | s052613167 | 224 | 192 | 45,552 | 42,476 | Accepted | Accepted | 14.29 | import heapq
N=int(eval(input()))
N_max=100000
d=set()
n=1
while n<=N_max:
d.add(n)
n*=6
n=1
while n<=N_max:
d.add(n)
n*=9
dp=[N_max+1 for _ in range(N_max+1)]
dp[0]=0
for i in range(1,N_max+1):
for n in d:
if i>=n:
dp[i]=min(dp[i],dp[i-n]+1)
print((dp[N])) | N = int(eval(input()))
a = [1]
n6 = 6
while n6 <= 100000:
a.append(n6)
n6 *= 6
n9 = 9
while n9 <= 100000:
a.append(n9)
n9 *= 9
#dp[i]=ちょうどi円払う場合に最小の操作回数
dp = [10**9] * (N+100010)
dp[0] = 0
for i in range(N):
for n in a:
dp[i+n] = min(dp[i+n], dp[i]+1)
print((dp[N])) | 22 | 20 | 313 | 308 | import heapq
N = int(eval(input()))
N_max = 100000
d = set()
n = 1
while n <= N_max:
d.add(n)
n *= 6
n = 1
while n <= N_max:
d.add(n)
n *= 9
dp = [N_max + 1 for _ in range(N_max + 1)]
dp[0] = 0
for i in range(1, N_max + 1):
for n in d:
if i >= n:
dp[i] = min(dp[i], dp[i - n] + 1)
print((dp[N]))
| N = int(eval(input()))
a = [1]
n6 = 6
while n6 <= 100000:
a.append(n6)
n6 *= 6
n9 = 9
while n9 <= 100000:
a.append(n9)
n9 *= 9
# dp[i]=ちょうどi円払う場合に最小の操作回数
dp = [10**9] * (N + 100010)
dp[0] = 0
for i in range(N):
for n in a:
dp[i + n] = min(dp[i + n], dp[i] + 1)
print((dp[N]))
| false | 9.090909 | [
"-import heapq",
"-",
"-N_max = 100000",
"-d = set()",
"-n = 1",
"-while n <= N_max:",
"- d.add(n)",
"- n *= 6",
"-n = 1",
"-while n <= N_max:",
"- d.add(n)",
"- n *= 9",
"-dp = [N_max + 1 for _ in range(N_max + 1)]",
"+a = [1]",
"+n6 = 6",
"+while n6 <= 100000:",
"+ a.append(n6)",
"+ n6 *= 6",
"+n9 = 9",
"+while n9 <= 100000:",
"+ a.append(n9)",
"+ n9 *= 9",
"+# dp[i]=ちょうどi円払う場合に最小の操作回数",
"+dp = [10**9] * (N + 100010)",
"-for i in range(1, N_max + 1):",
"- for n in d:",
"- if i >= n:",
"- dp[i] = min(dp[i], dp[i - n] + 1)",
"+for i in range(N):",
"+ for n in a:",
"+ dp[i + n] = min(dp[i + n], dp[i] + 1)"
] | false | 0.854233 | 0.121577 | 7.026291 | [
"s507292993",
"s052613167"
] |
u857428111 | p02732 | python | s363148044 | s975730169 | 519 | 363 | 100,804 | 26,396 | Accepted | Accepted | 30.06 | # coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)
#const
dxdy=((1,0),(0,1))
# my functions here!
def pin(type=int):
return list(map(type,input().rstrip().split()))
def resolve():
N,=pin()
A=list(pin())
from collections import Counter as ct
a=ct(A)
t=(list(a.items()))
#print(t)
Sum=0
for l in list(a.values()):
Sum+=(l*(l-1))//2
ans=[0]*N
for j in list(a.items()):
x,y=j
ans[x-1]=Sum-((y*(y-1))//2)+(((y-2)*(y-1))//2)
for i in A:
print((ans[i-1]))
"""
#printデバッグ消した?
#前の問題の結果見てないのに次の問題に行くの?
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """5
1 1 2 1 2"""
output = """2
2
3
2
3"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """4
1 2 3 4"""
output = """0
0
0
0"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """5
3 3 3 3 3"""
output = """6
6
6
6
6"""
self.assertIO(input, output)
def test_入力例_4(self):
input = """8
1 2 1 4 2 1 4 1"""
output = """5
7
5
7
7
5
7
5"""
self.assertIO(input, output)
if __name__=="__main__":resolve() | #%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return list(map(type,input().split()))
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
N=int(eval(input()))
A=tupin()
from collections import Counter
c=Counter(A)
total=0
for t in list(c.items()):
ag,b=t
total+=(b*(b-1))//2
#print(total)
for m in A:
a=c[m]
print((total-((a*(a-1))//2)+((a-1)*(a-2))//2))
#%%submit!
resolve() | 95 | 23 | 1,699 | 513 | # coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)
# const
dxdy = ((1, 0), (0, 1))
# my functions here!
def pin(type=int):
return list(map(type, input().rstrip().split()))
def resolve():
(N,) = pin()
A = list(pin())
from collections import Counter as ct
a = ct(A)
t = list(a.items())
# print(t)
Sum = 0
for l in list(a.values()):
Sum += (l * (l - 1)) // 2
ans = [0] * N
for j in list(a.items()):
x, y = j
ans[x - 1] = Sum - ((y * (y - 1)) // 2) + (((y - 2) * (y - 1)) // 2)
for i in A:
print((ans[i - 1]))
"""
#printデバッグ消した?
#前の問題の結果見てないのに次の問題に行くの?
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """5
1 1 2 1 2"""
output = """2
2
3
2
3"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """4
1 2 3 4"""
output = """0
0
0
0"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """5
3 3 3 3 3"""
output = """6
6
6
6
6"""
self.assertIO(input, output)
def test_入力例_4(self):
input = """8
1 2 1 4 2 1 4 1"""
output = """5
7
5
7
7
5
7
5"""
self.assertIO(input, output)
if __name__ == "__main__":
resolve()
| #%% for atcoder uniittest use
import sys
input = lambda: sys.stdin.readline().rstrip()
def pin(type=int):
return list(map(type, input().split()))
def tupin(t=int):
return tuple(pin(t))
#%%code
def resolve():
N = int(eval(input()))
A = tupin()
from collections import Counter
c = Counter(A)
total = 0
for t in list(c.items()):
ag, b = t
total += (b * (b - 1)) // 2
# print(total)
for m in A:
a = c[m]
print((total - ((a * (a - 1)) // 2) + ((a - 1) * (a - 2)) // 2))
#%%submit!
resolve()
| false | 75.789474 | [
"-# coding: utf-8",
"-# Your code here!",
"-# coding: utf-8",
"+#%% for atcoder uniittest use",
"-sys.setrecursionlimit(10000000)",
"-# const",
"-dxdy = ((1, 0), (0, 1))",
"-# my functions here!",
"-def pin(type=int):",
"- return list(map(type, input().rstrip().split()))",
"+input = lambda: sys.stdin.readline().rstrip()",
"-def resolve():",
"- (N,) = pin()",
"- A = list(pin())",
"- from collections import Counter as ct",
"-",
"- a = ct(A)",
"- t = list(a.items())",
"- # print(t)",
"- Sum = 0",
"- for l in list(a.values()):",
"- Sum += (l * (l - 1)) // 2",
"- ans = [0] * N",
"- for j in list(a.items()):",
"- x, y = j",
"- ans[x - 1] = Sum - ((y * (y - 1)) // 2) + (((y - 2) * (y - 1)) // 2)",
"- for i in A:",
"- print((ans[i - 1]))",
"+def pin(type=int):",
"+ return list(map(type, input().split()))",
"-\"\"\"",
"-#printデバッグ消した?",
"-#前の問題の結果見てないのに次の問題に行くの?",
"-\"\"\"",
"-\"\"\"",
"-お前カッコ閉じるの忘れてるだろ",
"-\"\"\"",
"-import sys",
"-from io import StringIO",
"-import unittest",
"+def tupin(t=int):",
"+ return tuple(pin(t))",
"-class TestClass(unittest.TestCase):",
"- def assertIO(self, input, output):",
"- stdout, stdin = sys.stdout, sys.stdin",
"- sys.stdout, sys.stdin = StringIO(), StringIO(input)",
"- resolve()",
"- sys.stdout.seek(0)",
"- out = sys.stdout.read()[:-1]",
"- sys.stdout, sys.stdin = stdout, stdin",
"- self.assertEqual(out, output)",
"+#%%code",
"+def resolve():",
"+ N = int(eval(input()))",
"+ A = tupin()",
"+ from collections import Counter",
"- def test_入力例_1(self):",
"- input = \"\"\"5",
"-1 1 2 1 2\"\"\"",
"- output = \"\"\"2",
"-2",
"-3",
"-2",
"-3\"\"\"",
"- self.assertIO(input, output)",
"-",
"- def test_入力例_2(self):",
"- input = \"\"\"4",
"-1 2 3 4\"\"\"",
"- output = \"\"\"0",
"-0",
"-0",
"-0\"\"\"",
"- self.assertIO(input, output)",
"-",
"- def test_入力例_3(self):",
"- input = \"\"\"5",
"-3 3 3 3 3\"\"\"",
"- output = \"\"\"6",
"-6",
"-6",
"-6",
"-6\"\"\"",
"- self.assertIO(input, output)",
"-",
"- def test_入力例_4(self):",
"- input = \"\"\"8",
"-1 2 1 4 2 1 4 1\"\"\"",
"- output = \"\"\"5",
"-7",
"-5",
"-7",
"-7",
"-5",
"-7",
"-5\"\"\"",
"- self.assertIO(input, output)",
"+ c = Counter(A)",
"+ total = 0",
"+ for t in list(c.items()):",
"+ ag, b = t",
"+ total += (b * (b - 1)) // 2",
"+ # print(total)",
"+ for m in A:",
"+ a = c[m]",
"+ print((total - ((a * (a - 1)) // 2) + ((a - 1) * (a - 2)) // 2))",
"-if __name__ == \"__main__\":",
"- resolve()",
"+#%%submit!",
"+resolve()"
] | false | 0.111702 | 0.04038 | 2.766226 | [
"s363148044",
"s975730169"
] |
u083960235 | p03640 | python | s494836972 | s689484844 | 50 | 46 | 5,964 | 10,968 | Accepted | Accepted | 8 | 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 heapq import heapify, heappop, heappush
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return 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
H, W = MAP()
N = INT()
A = LIST()
C = [[0] * W for i in range(H)]
num = 0
for h in range(H):
if h % 2 == 0:
for w in range(W):
if A[num] > 0:
A[num] -= 1
else:
num += 1
A[num] -= 1
C[h][w] = num + 1
else:
for w in range(W-1, -1, -1):
if A[num] > 0:
# C[h][w] = num + 1
A[num] -= 1
else:
num += 1
A[num] -= 1
C[h][w] = num + 1
for c in C:
print(*c, end="\n")
| 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(input())
def MAP(): return map(int, input().split())
def S_MAP(): return 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
H, W = MAP()
N = INT()
A = LIST()
C = [[0] * W for i in range(H)]
i = 0
for h in range(H):
for w in range(W):
while A[i] == 0:
i += 1
if h % 2 == 0:
# forward
C[h][w] = i + 1
else:
# backward
C[h][W-w-1] = i + 1
A[i] -= 1
# print(*[c for c in C], sep="\n")
for c in C:
print(*c, sep=" ")
| 46 | 40 | 1,369 | 1,191 | 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 heapq import heapify, heappop, heappush
from fractions import gcd
def input():
return sys.stdin.readline().strip()
def INT():
return int(input())
def MAP():
return map(int, input().split())
def S_MAP():
return 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
H, W = MAP()
N = INT()
A = LIST()
C = [[0] * W for i in range(H)]
num = 0
for h in range(H):
if h % 2 == 0:
for w in range(W):
if A[num] > 0:
A[num] -= 1
else:
num += 1
A[num] -= 1
C[h][w] = num + 1
else:
for w in range(W - 1, -1, -1):
if A[num] > 0:
# C[h][w] = num + 1
A[num] -= 1
else:
num += 1
A[num] -= 1
C[h][w] = num + 1
for c in C:
print(*c, end="\n")
| 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(input())
def MAP():
return map(int, input().split())
def S_MAP():
return 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
H, W = MAP()
N = INT()
A = LIST()
C = [[0] * W for i in range(H)]
i = 0
for h in range(H):
for w in range(W):
while A[i] == 0:
i += 1
if h % 2 == 0:
# forward
C[h][w] = i + 1
else:
# backward
C[h][W - w - 1] = i + 1
A[i] -= 1
# print(*[c for c in C], sep="\n")
for c in C:
print(*c, sep=" ")
| false | 13.043478 | [
"-from heapq import heapify, heappop, heappush",
"+from bisect import bisect, bisect_left, bisect_right",
"-num = 0",
"+i = 0",
"- if h % 2 == 0:",
"- for w in range(W):",
"- if A[num] > 0:",
"- A[num] -= 1",
"- else:",
"- num += 1",
"- A[num] -= 1",
"- C[h][w] = num + 1",
"- else:",
"- for w in range(W - 1, -1, -1):",
"- if A[num] > 0:",
"- # C[h][w] = num + 1",
"- A[num] -= 1",
"- else:",
"- num += 1",
"- A[num] -= 1",
"- C[h][w] = num + 1",
"+ for w in range(W):",
"+ while A[i] == 0:",
"+ i += 1",
"+ if h % 2 == 0:",
"+ # forward",
"+ C[h][w] = i + 1",
"+ else:",
"+ # backward",
"+ C[h][W - w - 1] = i + 1",
"+ A[i] -= 1",
"+# print(*[c for c in C], sep=\"\\n\")",
"- print(*c, end=\"\\n\")",
"+ print(*c, sep=\" \")"
] | false | 0.036914 | 0.038098 | 0.968926 | [
"s494836972",
"s689484844"
] |
u017810624 | p03152 | python | s037482606 | s542261284 | 673 | 586 | 3,316 | 3,188 | Accepted | Accepted | 12.93 | n,m=list(map(int,input().split()));a,b=[set(map(int,input().split())) for j in range(2)];c=1;N=M=0
for k in range(m*n,0,-1):
A=k in a;B=k in b
if A and B:M+=1;N+=1
elif A:c*=M;N+=1
elif B:c*=N;M+=1
else:c*=M*N-m*n+k
c%=10**9+7
print(c) | eval(input());a,b=[set(map(int,input().split())) for j in[0]*2];c=1;N=M=0;x=max(a)
for k in range(x,0,-1):
A=k in a;B=k in b
if A and B:M+=1;N+=1
elif A:c*=M;N+=1
elif B:c*=N;M+=1
else:c*=M*N-x+k
c%=10**9+7
print(c) | 9 | 9 | 243 | 223 | n, m = list(map(int, input().split()))
a, b = [set(map(int, input().split())) for j in range(2)]
c = 1
N = M = 0
for k in range(m * n, 0, -1):
A = k in a
B = k in b
if A and B:
M += 1
N += 1
elif A:
c *= M
N += 1
elif B:
c *= N
M += 1
else:
c *= M * N - m * n + k
c %= 10**9 + 7
print(c)
| eval(input())
a, b = [set(map(int, input().split())) for j in [0] * 2]
c = 1
N = M = 0
x = max(a)
for k in range(x, 0, -1):
A = k in a
B = k in b
if A and B:
M += 1
N += 1
elif A:
c *= M
N += 1
elif B:
c *= N
M += 1
else:
c *= M * N - x + k
c %= 10**9 + 7
print(c)
| false | 0 | [
"-n, m = list(map(int, input().split()))",
"-a, b = [set(map(int, input().split())) for j in range(2)]",
"+eval(input())",
"+a, b = [set(map(int, input().split())) for j in [0] * 2]",
"-for k in range(m * n, 0, -1):",
"+x = max(a)",
"+for k in range(x, 0, -1):",
"- c *= M * N - m * n + k",
"+ c *= M * N - x + k"
] | false | 0.047619 | 0.047868 | 0.994814 | [
"s037482606",
"s542261284"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.