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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u707808519 | p02640 | python | s880747911 | s617618030 | 25 | 20 | 9,168 | 9,160 | Accepted | Accepted | 20 | x, y = list(map(int, input().split()))
ans = 'No'
for a in range(x+1):
if 2*a + 4*(x-a) == y:
ans = 'Yes'
break
print(ans) | x, y = list(map(int, input().split()))
ans = 'No'
for a in range(x+1):
if 4*x-y == 2*a:
ans = 'Yes'
break
print(ans)
| 7 | 7 | 142 | 137 | x, y = list(map(int, input().split()))
ans = "No"
for a in range(x + 1):
if 2 * a + 4 * (x - a) == y:
ans = "Yes"
break
print(ans)
| x, y = list(map(int, input().split()))
ans = "No"
for a in range(x + 1):
if 4 * x - y == 2 * a:
ans = "Yes"
break
print(ans)
| false | 0 | [
"- if 2 * a + 4 * (x - a) == y:",
"+ if 4 * x - y == 2 * a:"
]
| false | 0.044402 | 0.044201 | 1.00455 | [
"s880747911",
"s617618030"
]
|
u327466606 | p03161 | python | s387530364 | s739119677 | 1,897 | 550 | 23,044 | 59,232 | Accepted | Accepted | 71.01 | import numpy as np
N,K = list(map(int,input().split()))
H = np.array(list(map(int,input().split())))
dp = np.zeros(N, dtype=int)
for i in range(1,N):
s = max(i-K,0)
dp[i] = np.min(dp[s:i]+np.abs(H[s:i]-H[i]))
print((dp[-1]))
| N,K = list(map(int,input().split()))
H = list(map(int,input().split()))
dp = [0]
for i in range(1,N):
h = H[i]
dp.append(min(dp[-j-1]+abs(h-H[i-j-1]) for j in range(min(i,K))))
print((dp[-1])) | 11 | 10 | 234 | 200 | import numpy as np
N, K = list(map(int, input().split()))
H = np.array(list(map(int, input().split())))
dp = np.zeros(N, dtype=int)
for i in range(1, N):
s = max(i - K, 0)
dp[i] = np.min(dp[s:i] + np.abs(H[s:i] - H[i]))
print((dp[-1]))
| N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
dp = [0]
for i in range(1, N):
h = H[i]
dp.append(min(dp[-j - 1] + abs(h - H[i - j - 1]) for j in range(min(i, K))))
print((dp[-1]))
| false | 9.090909 | [
"-import numpy as np",
"-",
"-H = np.array(list(map(int, input().split())))",
"-dp = np.zeros(N, dtype=int)",
"+H = list(map(int, input().split()))",
"+dp = [0]",
"- s = max(i - K, 0)",
"- dp[i] = np.min(dp[s:i] + np.abs(H[s:i] - H[i]))",
"+ h = H[i]",
"+ dp.append(min(dp[-j - 1] + abs(h - H[i - j - 1]) for j in range(min(i, K))))"
]
| false | 0.242077 | 0.04394 | 5.509307 | [
"s387530364",
"s739119677"
]
|
u170201762 | p03660 | python | s097214340 | s607024422 | 1,329 | 1,040 | 125,784 | 105,324 | Accepted | Accepted | 21.75 | from collections import defaultdict
from heapq import heappop, heappush
from math import ceil
class Graph(object):
def __init__(self):
self.graph = defaultdict(list)
def __len__(self):
return len(self.graph)
def add_edge(self, From, To, cost=1):
self.graph[From].append((To,cost))
def get_nodes(self):
return list(self.graph.keys())
class Dijkstra(object):
def __init__(self, graph, start):
self.g = graph.graph
self.dist = defaultdict(lambda:float('inf'))
self.dist[start] = 0
self.prev = defaultdict(lambda: None)
self.Q = []
heappush(self.Q,(self.dist[start], start))
while self.Q:
dist_u, u = heappop(self.Q)
if self.dist[u] < dist_u:
continue
for v, cost in self.g[u]:
alt = dist_u + cost
if self.dist[v] > alt:
self.dist[v] = alt
self.prev[v] = u
heappush(self.Q,(alt, v))
def shortest_distance(self, goal):
return self.dist[goal]
def shortest_path(self, goal):
path = []
node = goal
while node is not None:
path.append(node)
node = self.prev[node]
return path[::-1]
N = int(eval(input()))
g = Graph()
for _ in range(N-1):
a,b = list(map(int,input().split()))
g.add_edge(a,b)
g.add_edge(b,a)
dij = Dijkstra(g,1)
path = dij.shortest_path(N)
c1 = path[ceil(len(path)/2)-1]
c2 = path[ceil(len(path)/2)]
g.graph[c1] = [(to,cost) for to,cost in g.graph[c1] if to != c2]
g.graph[c2] = [(to,cost) for to,cost in g.graph[c2] if to != c1]
dij = Dijkstra(g,1)
f = 0
for i in range(1,N):
if dij.shortest_distance(i) != float('inf'):
f += 1
if f > N-f:
print('Fennec')
else:
print('Snuke') | from heapq import heappush, heappop
def dijkstra(graph:list, node:int, start:int) -> list:
# graph[node] = [(cost, to)]
inf = float('inf')
dist = [inf]*node
dist[start] = 0
heap = [(0,start)]
while heap:
cost,thisNode = heappop(heap)
for NextCost,NextNode in graph[thisNode]:
dist_cand = dist[thisNode]+NextCost
if dist_cand < dist[NextNode]:
dist[NextNode] = dist_cand
heappush(heap,(dist[NextNode],NextNode))
return dist
N = int(eval(input()))
g = [[] for _ in range(N)]
for _ in range(N-1):
a,b = list(map(int,input().split()))
g[a-1].append((1,b-1))
g[b-1].append((1,a-1))
df = dijkstra(g,N,0)
ds = dijkstra(g,N,N-1)
f = 0
for i in range(N):
if df[i] <= ds[i]:
f += 1
if f > N-f:
print('Fennec')
else:
print('Snuke') | 76 | 36 | 1,913 | 880 | from collections import defaultdict
from heapq import heappop, heappush
from math import ceil
class Graph(object):
def __init__(self):
self.graph = defaultdict(list)
def __len__(self):
return len(self.graph)
def add_edge(self, From, To, cost=1):
self.graph[From].append((To, cost))
def get_nodes(self):
return list(self.graph.keys())
class Dijkstra(object):
def __init__(self, graph, start):
self.g = graph.graph
self.dist = defaultdict(lambda: float("inf"))
self.dist[start] = 0
self.prev = defaultdict(lambda: None)
self.Q = []
heappush(self.Q, (self.dist[start], start))
while self.Q:
dist_u, u = heappop(self.Q)
if self.dist[u] < dist_u:
continue
for v, cost in self.g[u]:
alt = dist_u + cost
if self.dist[v] > alt:
self.dist[v] = alt
self.prev[v] = u
heappush(self.Q, (alt, v))
def shortest_distance(self, goal):
return self.dist[goal]
def shortest_path(self, goal):
path = []
node = goal
while node is not None:
path.append(node)
node = self.prev[node]
return path[::-1]
N = int(eval(input()))
g = Graph()
for _ in range(N - 1):
a, b = list(map(int, input().split()))
g.add_edge(a, b)
g.add_edge(b, a)
dij = Dijkstra(g, 1)
path = dij.shortest_path(N)
c1 = path[ceil(len(path) / 2) - 1]
c2 = path[ceil(len(path) / 2)]
g.graph[c1] = [(to, cost) for to, cost in g.graph[c1] if to != c2]
g.graph[c2] = [(to, cost) for to, cost in g.graph[c2] if to != c1]
dij = Dijkstra(g, 1)
f = 0
for i in range(1, N):
if dij.shortest_distance(i) != float("inf"):
f += 1
if f > N - f:
print("Fennec")
else:
print("Snuke")
| from heapq import heappush, heappop
def dijkstra(graph: list, node: int, start: int) -> list:
# graph[node] = [(cost, to)]
inf = float("inf")
dist = [inf] * node
dist[start] = 0
heap = [(0, start)]
while heap:
cost, thisNode = heappop(heap)
for NextCost, NextNode in graph[thisNode]:
dist_cand = dist[thisNode] + NextCost
if dist_cand < dist[NextNode]:
dist[NextNode] = dist_cand
heappush(heap, (dist[NextNode], NextNode))
return dist
N = int(eval(input()))
g = [[] for _ in range(N)]
for _ in range(N - 1):
a, b = list(map(int, input().split()))
g[a - 1].append((1, b - 1))
g[b - 1].append((1, a - 1))
df = dijkstra(g, N, 0)
ds = dijkstra(g, N, N - 1)
f = 0
for i in range(N):
if df[i] <= ds[i]:
f += 1
if f > N - f:
print("Fennec")
else:
print("Snuke")
| false | 52.631579 | [
"-from collections import defaultdict",
"-from heapq import heappop, heappush",
"-from math import ceil",
"+from heapq import heappush, heappop",
"-class Graph(object):",
"- def __init__(self):",
"- self.graph = defaultdict(list)",
"-",
"- def __len__(self):",
"- return len(self.graph)",
"-",
"- def add_edge(self, From, To, cost=1):",
"- self.graph[From].append((To, cost))",
"-",
"- def get_nodes(self):",
"- return list(self.graph.keys())",
"-",
"-",
"-class Dijkstra(object):",
"- def __init__(self, graph, start):",
"- self.g = graph.graph",
"- self.dist = defaultdict(lambda: float(\"inf\"))",
"- self.dist[start] = 0",
"- self.prev = defaultdict(lambda: None)",
"- self.Q = []",
"- heappush(self.Q, (self.dist[start], start))",
"- while self.Q:",
"- dist_u, u = heappop(self.Q)",
"- if self.dist[u] < dist_u:",
"- continue",
"- for v, cost in self.g[u]:",
"- alt = dist_u + cost",
"- if self.dist[v] > alt:",
"- self.dist[v] = alt",
"- self.prev[v] = u",
"- heappush(self.Q, (alt, v))",
"-",
"- def shortest_distance(self, goal):",
"- return self.dist[goal]",
"-",
"- def shortest_path(self, goal):",
"- path = []",
"- node = goal",
"- while node is not None:",
"- path.append(node)",
"- node = self.prev[node]",
"- return path[::-1]",
"+def dijkstra(graph: list, node: int, start: int) -> list:",
"+ # graph[node] = [(cost, to)]",
"+ inf = float(\"inf\")",
"+ dist = [inf] * node",
"+ dist[start] = 0",
"+ heap = [(0, start)]",
"+ while heap:",
"+ cost, thisNode = heappop(heap)",
"+ for NextCost, NextNode in graph[thisNode]:",
"+ dist_cand = dist[thisNode] + NextCost",
"+ if dist_cand < dist[NextNode]:",
"+ dist[NextNode] = dist_cand",
"+ heappush(heap, (dist[NextNode], NextNode))",
"+ return dist",
"-g = Graph()",
"+g = [[] for _ in range(N)]",
"- g.add_edge(a, b)",
"- g.add_edge(b, a)",
"-dij = Dijkstra(g, 1)",
"-path = dij.shortest_path(N)",
"-c1 = path[ceil(len(path) / 2) - 1]",
"-c2 = path[ceil(len(path) / 2)]",
"-g.graph[c1] = [(to, cost) for to, cost in g.graph[c1] if to != c2]",
"-g.graph[c2] = [(to, cost) for to, cost in g.graph[c2] if to != c1]",
"-dij = Dijkstra(g, 1)",
"+ g[a - 1].append((1, b - 1))",
"+ g[b - 1].append((1, a - 1))",
"+df = dijkstra(g, N, 0)",
"+ds = dijkstra(g, N, N - 1)",
"-for i in range(1, N):",
"- if dij.shortest_distance(i) != float(\"inf\"):",
"+for i in range(N):",
"+ if df[i] <= ds[i]:"
]
| false | 0.007303 | 0.040993 | 0.178151 | [
"s097214340",
"s607024422"
]
|
u508732591 | p02412 | python | s701277099 | s373266057 | 30 | 20 | 7,740 | 7,648 | Accepted | Accepted | 33.33 | while True:
n,x = list(map(int,input().split()))
if n==x==0: break
print((sum( [ len(list(range(max(i+1,x-i-n),min(n,(x-i+1)//2)))) for i in range(1,min(n-1,x//3)) ]))) | while True:
n,x = list(map(int,input().split()))
if n==0 and x==0:
break
print((sum( [ max(min(n,(x-i+1)//2) - max(i+1,x-i-n),0) for i in range(1,min(n-1,x//3)) ]))) | 6 | 7 | 173 | 185 | while True:
n, x = list(map(int, input().split()))
if n == x == 0:
break
print(
(
sum(
[
len(list(range(max(i + 1, x - i - n), min(n, (x - i + 1) // 2))))
for i in range(1, min(n - 1, x // 3))
]
)
)
)
| while True:
n, x = list(map(int, input().split()))
if n == 0 and x == 0:
break
print(
(
sum(
[
max(min(n, (x - i + 1) // 2) - max(i + 1, x - i - n), 0)
for i in range(1, min(n - 1, x // 3))
]
)
)
)
| false | 14.285714 | [
"- if n == x == 0:",
"+ if n == 0 and x == 0:",
"- len(list(range(max(i + 1, x - i - n), min(n, (x - i + 1) // 2))))",
"+ max(min(n, (x - i + 1) // 2) - max(i + 1, x - i - n), 0)"
]
| false | 0.131709 | 0.051474 | 2.558741 | [
"s701277099",
"s373266057"
]
|
u794173881 | p03525 | python | s388953038 | s833359559 | 238 | 193 | 44,784 | 41,456 | Accepted | Accepted | 18.91 | n = int(eval(input()))
s = list(map(int, input().split()))
cnt_memo = {}
for num in s:
if num in cnt_memo:
cnt_memo[num] += 1
else:
cnt_memo[num] = 1
kakutei = [0]
mikakutei = []
for i in cnt_memo:
if i == 0:
print((0))
exit()
elif i == 12:
if cnt_memo[i] == 1:
kakutei.append(12)
else:
print((0))
exit()
else:
if cnt_memo[i] == 1:
mikakutei.append(i)
elif cnt_memo[i] == 2:
kakutei.append(i)
kakutei.append(24 - i)
else:
print((0))
exit()
tmp_ans1 = 25
for num1 in kakutei:
for num2 in kakutei:
if num1 != num2:
tmp_ans1 = min(tmp_ans1, min(abs(num1 - num2), 24 -abs(num1 - num2)))
len_mikakutei = len(mikakutei)
mikakutei_pattern = 2**len_mikakutei
ans = 0
for i in range(mikakutei_pattern):
tmp = []
num = i
cnt = 0
for _ in range(len_mikakutei):
if num % 2 == 1:
tmp.append(mikakutei[cnt])
else:
tmp.append(24 - mikakutei[cnt])
num //= 2
cnt += 1
tmp_ans = 25
for num1 in tmp:
for num2 in kakutei:
tmp_ans = min(tmp_ans, min(abs(num1 - num2), 24 -abs(num1 - num2)))
for num1 in tmp:
for num2 in tmp:
if num1 != num2:
tmp_ans = min(tmp_ans, min(abs(num1 - num2), 24 -abs(num1 - num2)))
tmp_ans = min(tmp_ans, tmp_ans1)
ans = max(ans, tmp_ans)
print(ans)
| n = int(eval(input()))
d = list(map(int, input().split()))
memo = {0: 1}
for i in range(n):
if d[i] not in memo:
memo[d[i]] = 1
else:
memo[d[i]] += 1
used = [] * n
li = []
for i in memo:
if memo[i] >= 3:
print((0))
exit()
elif memo[i] == 2:
used.append(i)
used.append(24 - i)
else:
li.append(i)
ans = 0
for bit_state in range(1 << len(li)):
tmp = used[0:]
for i in range(len(li)):
if bit_state & (1 << i):
tmp.append(li[i])
else:
tmp.append(24 - li[i])
tmp = sorted(tmp)
diff = 10 ** 18
for i in range(1, len(tmp)):
diff = min(diff, tmp[i] - tmp[i - 1])
diff = min(diff, 24 - (tmp[-1] - tmp[0]))
ans = max(ans, diff)
print(ans) | 64 | 37 | 1,577 | 810 | n = int(eval(input()))
s = list(map(int, input().split()))
cnt_memo = {}
for num in s:
if num in cnt_memo:
cnt_memo[num] += 1
else:
cnt_memo[num] = 1
kakutei = [0]
mikakutei = []
for i in cnt_memo:
if i == 0:
print((0))
exit()
elif i == 12:
if cnt_memo[i] == 1:
kakutei.append(12)
else:
print((0))
exit()
else:
if cnt_memo[i] == 1:
mikakutei.append(i)
elif cnt_memo[i] == 2:
kakutei.append(i)
kakutei.append(24 - i)
else:
print((0))
exit()
tmp_ans1 = 25
for num1 in kakutei:
for num2 in kakutei:
if num1 != num2:
tmp_ans1 = min(tmp_ans1, min(abs(num1 - num2), 24 - abs(num1 - num2)))
len_mikakutei = len(mikakutei)
mikakutei_pattern = 2**len_mikakutei
ans = 0
for i in range(mikakutei_pattern):
tmp = []
num = i
cnt = 0
for _ in range(len_mikakutei):
if num % 2 == 1:
tmp.append(mikakutei[cnt])
else:
tmp.append(24 - mikakutei[cnt])
num //= 2
cnt += 1
tmp_ans = 25
for num1 in tmp:
for num2 in kakutei:
tmp_ans = min(tmp_ans, min(abs(num1 - num2), 24 - abs(num1 - num2)))
for num1 in tmp:
for num2 in tmp:
if num1 != num2:
tmp_ans = min(tmp_ans, min(abs(num1 - num2), 24 - abs(num1 - num2)))
tmp_ans = min(tmp_ans, tmp_ans1)
ans = max(ans, tmp_ans)
print(ans)
| n = int(eval(input()))
d = list(map(int, input().split()))
memo = {0: 1}
for i in range(n):
if d[i] not in memo:
memo[d[i]] = 1
else:
memo[d[i]] += 1
used = [] * n
li = []
for i in memo:
if memo[i] >= 3:
print((0))
exit()
elif memo[i] == 2:
used.append(i)
used.append(24 - i)
else:
li.append(i)
ans = 0
for bit_state in range(1 << len(li)):
tmp = used[0:]
for i in range(len(li)):
if bit_state & (1 << i):
tmp.append(li[i])
else:
tmp.append(24 - li[i])
tmp = sorted(tmp)
diff = 10**18
for i in range(1, len(tmp)):
diff = min(diff, tmp[i] - tmp[i - 1])
diff = min(diff, 24 - (tmp[-1] - tmp[0]))
ans = max(ans, diff)
print(ans)
| false | 42.1875 | [
"-s = list(map(int, input().split()))",
"-cnt_memo = {}",
"-for num in s:",
"- if num in cnt_memo:",
"- cnt_memo[num] += 1",
"+d = list(map(int, input().split()))",
"+memo = {0: 1}",
"+for i in range(n):",
"+ if d[i] not in memo:",
"+ memo[d[i]] = 1",
"- cnt_memo[num] = 1",
"-kakutei = [0]",
"-mikakutei = []",
"-for i in cnt_memo:",
"- if i == 0:",
"+ memo[d[i]] += 1",
"+used = [] * n",
"+li = []",
"+for i in memo:",
"+ if memo[i] >= 3:",
"- elif i == 12:",
"- if cnt_memo[i] == 1:",
"- kakutei.append(12)",
"+ elif memo[i] == 2:",
"+ used.append(i)",
"+ used.append(24 - i)",
"+ else:",
"+ li.append(i)",
"+ans = 0",
"+for bit_state in range(1 << len(li)):",
"+ tmp = used[0:]",
"+ for i in range(len(li)):",
"+ if bit_state & (1 << i):",
"+ tmp.append(li[i])",
"- print((0))",
"- exit()",
"- else:",
"- if cnt_memo[i] == 1:",
"- mikakutei.append(i)",
"- elif cnt_memo[i] == 2:",
"- kakutei.append(i)",
"- kakutei.append(24 - i)",
"- else:",
"- print((0))",
"- exit()",
"-tmp_ans1 = 25",
"-for num1 in kakutei:",
"- for num2 in kakutei:",
"- if num1 != num2:",
"- tmp_ans1 = min(tmp_ans1, min(abs(num1 - num2), 24 - abs(num1 - num2)))",
"-len_mikakutei = len(mikakutei)",
"-mikakutei_pattern = 2**len_mikakutei",
"-ans = 0",
"-for i in range(mikakutei_pattern):",
"- tmp = []",
"- num = i",
"- cnt = 0",
"- for _ in range(len_mikakutei):",
"- if num % 2 == 1:",
"- tmp.append(mikakutei[cnt])",
"- else:",
"- tmp.append(24 - mikakutei[cnt])",
"- num //= 2",
"- cnt += 1",
"- tmp_ans = 25",
"- for num1 in tmp:",
"- for num2 in kakutei:",
"- tmp_ans = min(tmp_ans, min(abs(num1 - num2), 24 - abs(num1 - num2)))",
"- for num1 in tmp:",
"- for num2 in tmp:",
"- if num1 != num2:",
"- tmp_ans = min(tmp_ans, min(abs(num1 - num2), 24 - abs(num1 - num2)))",
"- tmp_ans = min(tmp_ans, tmp_ans1)",
"- ans = max(ans, tmp_ans)",
"+ tmp.append(24 - li[i])",
"+ tmp = sorted(tmp)",
"+ diff = 10**18",
"+ for i in range(1, len(tmp)):",
"+ diff = min(diff, tmp[i] - tmp[i - 1])",
"+ diff = min(diff, 24 - (tmp[-1] - tmp[0]))",
"+ ans = max(ans, diff)"
]
| false | 0.083966 | 0.078744 | 1.066327 | [
"s388953038",
"s833359559"
]
|
u863370423 | p02687 | python | s438225897 | s736516130 | 55 | 25 | 64,244 | 8,932 | Accepted | Accepted | 54.55 | s = input()
if s == "ARC":
print("ABC")
else:
print("ARC") | s = list(eval(input()))
s[1] = (s[1] == 'B') and 'R' or 'B'
a = ''.join(s)
print(a)
| 5 | 6 | 66 | 85 | s = input()
if s == "ARC":
print("ABC")
else:
print("ARC")
| s = list(eval(input()))
s[1] = (s[1] == "B") and "R" or "B"
a = "".join(s)
print(a)
| false | 16.666667 | [
"-s = input()",
"-if s == \"ARC\":",
"- print(\"ABC\")",
"-else:",
"- print(\"ARC\")",
"+s = list(eval(input()))",
"+s[1] = (s[1] == \"B\") and \"R\" or \"B\"",
"+a = \"\".join(s)",
"+print(a)"
]
| false | 0.041934 | 0.168481 | 0.248896 | [
"s438225897",
"s736516130"
]
|
u370086573 | p02261 | python | s205052741 | s775073974 | 170 | 120 | 7,824 | 7,848 | Accepted | Accepted | 29.41 | def bubble_sort(r, n):
flag = True # ??£??\????´?????????¨????????°
while flag:
flag = False
for i in range(n - 1, 0, -1):
if r[i - 1][1] > r[i][1]:
r[i - 1], r[i] = r[i], r[i - 1]
flag = True
return r
def select_sort(r, n):
for i in range(0, n):
minj = i
for j in range(i, n):
if r[j][1] < r[minj][1]:
minj = j
if i != minj:
r[i], r[minj] = r[minj], r[i]
return r
def stable_sort(r, sort_r):
for i in range(len(r)):
for j in range(i + 1, len(r)):
for a in range(len(sort_r)):
for b in range(a + 1, len(sort_r)):
if r[i][1] == r[j][1] and r[i] == sort_r[b] and r[j] == sort_r[a]:
return "Not stable"
return "Stable"
N = int(eval(input()))
R = list(input().split())
C = R[:]
BS_R = bubble_sort(R, N)
SS_R = select_sort(C, N)
print((*BS_R))
print((stable_sort(R, BS_R)))
print((*SS_R))
print((stable_sort(R, SS_R))) | def selectionSort(n, A):
cnt = 0
for i in range(n):
minj = i
for j in range(i, n):
if A[minj][1] > A[j][1]:
minj = j
if i != minj:
A[i], A[minj] = A[minj], A[i]
cnt += 1
return A
def bubbleSort(n, A):
flag = True
cnt = 0
while flag:
flag = False
for j in range(n - 1, 0, -1):
if A[j - 1][1] > A[j][1]:
A[j - 1], A[j] = A[j], A[j - 1]
cnt += 1
flag = True
return A
def stableSort(input, output):
n = len(input)
for i in range(n):
for j in range(i + 1, n):
for a in range(n):
for b in range(a + 1, n):
if input[i][1] == input[j][1] and input[i] == output[b] and input[j] == output[a]:
return print("Not stable")
return print("Stable")
if __name__ == '__main__':
n = int(input())
R = list(map(str, input().split()))
C = R[:]
D = R[:] #????????¨?????????
SR = selectionSort(n, R)
BR = bubbleSort(n, C)
print(*BR)
stableSort(D,BR)
print(*SR)
stableSort(D,SR)
| 42 | 48 | 1,081 | 1,219 | def bubble_sort(r, n):
flag = True # ??£??\????´?????????¨????????°
while flag:
flag = False
for i in range(n - 1, 0, -1):
if r[i - 1][1] > r[i][1]:
r[i - 1], r[i] = r[i], r[i - 1]
flag = True
return r
def select_sort(r, n):
for i in range(0, n):
minj = i
for j in range(i, n):
if r[j][1] < r[minj][1]:
minj = j
if i != minj:
r[i], r[minj] = r[minj], r[i]
return r
def stable_sort(r, sort_r):
for i in range(len(r)):
for j in range(i + 1, len(r)):
for a in range(len(sort_r)):
for b in range(a + 1, len(sort_r)):
if r[i][1] == r[j][1] and r[i] == sort_r[b] and r[j] == sort_r[a]:
return "Not stable"
return "Stable"
N = int(eval(input()))
R = list(input().split())
C = R[:]
BS_R = bubble_sort(R, N)
SS_R = select_sort(C, N)
print((*BS_R))
print((stable_sort(R, BS_R)))
print((*SS_R))
print((stable_sort(R, SS_R)))
| def selectionSort(n, A):
cnt = 0
for i in range(n):
minj = i
for j in range(i, n):
if A[minj][1] > A[j][1]:
minj = j
if i != minj:
A[i], A[minj] = A[minj], A[i]
cnt += 1
return A
def bubbleSort(n, A):
flag = True
cnt = 0
while flag:
flag = False
for j in range(n - 1, 0, -1):
if A[j - 1][1] > A[j][1]:
A[j - 1], A[j] = A[j], A[j - 1]
cnt += 1
flag = True
return A
def stableSort(input, output):
n = len(input)
for i in range(n):
for j in range(i + 1, n):
for a in range(n):
for b in range(a + 1, n):
if (
input[i][1] == input[j][1]
and input[i] == output[b]
and input[j] == output[a]
):
return print("Not stable")
return print("Stable")
if __name__ == "__main__":
n = int(input())
R = list(map(str, input().split()))
C = R[:]
D = R[:] # ????????¨?????????
SR = selectionSort(n, R)
BR = bubbleSort(n, C)
print(*BR)
stableSort(D, BR)
print(*SR)
stableSort(D, SR)
| false | 12.5 | [
"-def bubble_sort(r, n):",
"- flag = True # ??£??\\????´?????????¨????????°",
"+def selectionSort(n, A):",
"+ cnt = 0",
"+ for i in range(n):",
"+ minj = i",
"+ for j in range(i, n):",
"+ if A[minj][1] > A[j][1]:",
"+ minj = j",
"+ if i != minj:",
"+ A[i], A[minj] = A[minj], A[i]",
"+ cnt += 1",
"+ return A",
"+",
"+",
"+def bubbleSort(n, A):",
"+ flag = True",
"+ cnt = 0",
"- for i in range(n - 1, 0, -1):",
"- if r[i - 1][1] > r[i][1]:",
"- r[i - 1], r[i] = r[i], r[i - 1]",
"+ for j in range(n - 1, 0, -1):",
"+ if A[j - 1][1] > A[j][1]:",
"+ A[j - 1], A[j] = A[j], A[j - 1]",
"+ cnt += 1",
"- return r",
"+ return A",
"-def select_sort(r, n):",
"- for i in range(0, n):",
"- minj = i",
"- for j in range(i, n):",
"- if r[j][1] < r[minj][1]:",
"- minj = j",
"- if i != minj:",
"- r[i], r[minj] = r[minj], r[i]",
"- return r",
"+def stableSort(input, output):",
"+ n = len(input)",
"+ for i in range(n):",
"+ for j in range(i + 1, n):",
"+ for a in range(n):",
"+ for b in range(a + 1, n):",
"+ if (",
"+ input[i][1] == input[j][1]",
"+ and input[i] == output[b]",
"+ and input[j] == output[a]",
"+ ):",
"+ return print(\"Not stable\")",
"+ return print(\"Stable\")",
"-def stable_sort(r, sort_r):",
"- for i in range(len(r)):",
"- for j in range(i + 1, len(r)):",
"- for a in range(len(sort_r)):",
"- for b in range(a + 1, len(sort_r)):",
"- if r[i][1] == r[j][1] and r[i] == sort_r[b] and r[j] == sort_r[a]:",
"- return \"Not stable\"",
"- return \"Stable\"",
"-",
"-",
"-N = int(eval(input()))",
"-R = list(input().split())",
"-C = R[:]",
"-BS_R = bubble_sort(R, N)",
"-SS_R = select_sort(C, N)",
"-print((*BS_R))",
"-print((stable_sort(R, BS_R)))",
"-print((*SS_R))",
"-print((stable_sort(R, SS_R)))",
"+if __name__ == \"__main__\":",
"+ n = int(input())",
"+ R = list(map(str, input().split()))",
"+ C = R[:]",
"+ D = R[:] # ????????¨?????????",
"+ SR = selectionSort(n, R)",
"+ BR = bubbleSort(n, C)",
"+ print(*BR)",
"+ stableSort(D, BR)",
"+ print(*SR)",
"+ stableSort(D, SR)"
]
| false | 0.077823 | 0.042996 | 1.809996 | [
"s205052741",
"s775073974"
]
|
u320567105 | p03109 | python | s613585146 | s760080627 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | s = eval(input())
m = s[5:7]
if m=='01'or m=='02' or m=='03' or m=='04':
print('Heisei')
else:
print('TBD') | ri = lambda: int(eval(input()))
rl = lambda: list(map(int,input().split()))
s=eval(input())
if s[5:7]<='04':
print('Heisei')
else:
print('TBD') | 8 | 8 | 118 | 147 | s = eval(input())
m = s[5:7]
if m == "01" or m == "02" or m == "03" or m == "04":
print("Heisei")
else:
print("TBD")
| ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
s = eval(input())
if s[5:7] <= "04":
print("Heisei")
else:
print("TBD")
| false | 0 | [
"+ri = lambda: int(eval(input()))",
"+rl = lambda: list(map(int, input().split()))",
"-m = s[5:7]",
"-if m == \"01\" or m == \"02\" or m == \"03\" or m == \"04\":",
"+if s[5:7] <= \"04\":"
]
| false | 0.075985 | 0.075852 | 1.00175 | [
"s613585146",
"s760080627"
]
|
u312025627 | p03295 | python | s605506962 | s368170022 | 718 | 386 | 62,040 | 59,484 | Accepted | Accepted | 46.24 | def main():
N, M = (int(i) for i in input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(M)]
ab.sort(key=lambda p: p[1])
pre_b = 1
ans = 0
for a, b in ab:
if pre_b <= a:
ans += 1
pre_b = b
print(ans)
if __name__ == '__main__':
main()
| def main():
import sys
input = sys.stdin.buffer.readline
N, M = (int(i) for i in input().split())
AB = [[int(i) for i in input().split()] for j in range(M)]
AB.sort(key=lambda p: p[1])
mx_b = AB[0][1]
ans = 1
for a, b in AB[1:]:
if a < mx_b:
continue
else:
mx_b = b
ans += 1
print(ans)
if __name__ == '__main__':
main()
| 16 | 19 | 340 | 432 | def main():
N, M = (int(i) for i in input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(M)]
ab.sort(key=lambda p: p[1])
pre_b = 1
ans = 0
for a, b in ab:
if pre_b <= a:
ans += 1
pre_b = b
print(ans)
if __name__ == "__main__":
main()
| def main():
import sys
input = sys.stdin.buffer.readline
N, M = (int(i) for i in input().split())
AB = [[int(i) for i in input().split()] for j in range(M)]
AB.sort(key=lambda p: p[1])
mx_b = AB[0][1]
ans = 1
for a, b in AB[1:]:
if a < mx_b:
continue
else:
mx_b = b
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 15.789474 | [
"+ import sys",
"+",
"+ input = sys.stdin.buffer.readline",
"- ab = [tuple(int(i) for i in input().split()) for _ in range(M)]",
"- ab.sort(key=lambda p: p[1])",
"- pre_b = 1",
"- ans = 0",
"- for a, b in ab:",
"- if pre_b <= a:",
"+ AB = [[int(i) for i in input().split()] for j in range(M)]",
"+ AB.sort(key=lambda p: p[1])",
"+ mx_b = AB[0][1]",
"+ ans = 1",
"+ for a, b in AB[1:]:",
"+ if a < mx_b:",
"+ continue",
"+ else:",
"+ mx_b = b",
"- pre_b = b"
]
| false | 0.082849 | 0.083973 | 0.986616 | [
"s605506962",
"s368170022"
]
|
u864197622 | p03074 | python | s388038937 | s373521044 | 81 | 51 | 7,160 | 9,356 | Accepted | Accepted | 37.04 | N, K = list(map(int, input().split()))
s = eval(input())
X = [0]
if s[0] == "0":
X.append(0)
for i in range(N):
if i == N-1 or s[i] != s[i+1]:
X.append(i+1)
if s[-1] == "0":
X.append(X[-1])
if len(X) <= K*2+1:
print(N)
else:
ma = 0
for i in range(0, len(X) - K*2 - 1, 2):
ma = max(X[i+K*2+1]-X[i], ma)
print(ma) | N, K = list(map(int, input().split()))
s = eval(input())
L = 2 * K + 1
X = [0]*(2-int(s[0])) + [i+1 for i in range(N-1) if s[i]!=s[i+1]] + [N] * L
print((max([X[i+L]-X[i] for i in range(0, len(X)-L, 2)]))) | 19 | 5 | 363 | 195 | N, K = list(map(int, input().split()))
s = eval(input())
X = [0]
if s[0] == "0":
X.append(0)
for i in range(N):
if i == N - 1 or s[i] != s[i + 1]:
X.append(i + 1)
if s[-1] == "0":
X.append(X[-1])
if len(X) <= K * 2 + 1:
print(N)
else:
ma = 0
for i in range(0, len(X) - K * 2 - 1, 2):
ma = max(X[i + K * 2 + 1] - X[i], ma)
print(ma)
| N, K = list(map(int, input().split()))
s = eval(input())
L = 2 * K + 1
X = [0] * (2 - int(s[0])) + [i + 1 for i in range(N - 1) if s[i] != s[i + 1]] + [N] * L
print((max([X[i + L] - X[i] for i in range(0, len(X) - L, 2)])))
| false | 73.684211 | [
"-X = [0]",
"-if s[0] == \"0\":",
"- X.append(0)",
"-for i in range(N):",
"- if i == N - 1 or s[i] != s[i + 1]:",
"- X.append(i + 1)",
"-if s[-1] == \"0\":",
"- X.append(X[-1])",
"-if len(X) <= K * 2 + 1:",
"- print(N)",
"-else:",
"- ma = 0",
"- for i in range(0, len(X) - K * 2 - 1, 2):",
"- ma = max(X[i + K * 2 + 1] - X[i], ma)",
"- print(ma)",
"+L = 2 * K + 1",
"+X = [0] * (2 - int(s[0])) + [i + 1 for i in range(N - 1) if s[i] != s[i + 1]] + [N] * L",
"+print((max([X[i + L] - X[i] for i in range(0, len(X) - L, 2)])))"
]
| false | 0.064585 | 0.041302 | 1.563697 | [
"s388038937",
"s373521044"
]
|
u634079249 | p03325 | python | s008422869 | s430905822 | 68 | 54 | 11,008 | 11,004 | Accepted | Accepted | 20.59 | import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
# import fractions
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
ret = 0
for n in range(N):
while A[n] % 2 == 0:
A[n] //= 2
ret += 1
print(ret)
if __name__ == '__main__':
main()
| import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
ret = 0
for a in A:
while a % 2 == 0:
a //= 2
ret += 1
print(ret)
if __name__ == '__main__':
main()
| 41 | 40 | 1,194 | 1,110 | import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
# import fractions
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)
MOD = 10**9 + 7
MAX = float("inf")
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
ret = 0
for n in range(N):
while A[n] % 2 == 0:
A[n] //= 2
ret += 1
print(ret)
if __name__ == "__main__":
main()
| import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10**9 + 7
MAX = float("inf")
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
ret = 0
for a in A:
while a % 2 == 0:
a //= 2
ret += 1
print(ret)
if __name__ == "__main__":
main()
| false | 2.439024 | [
"-# import fractions",
"-# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)",
"- for n in range(N):",
"- while A[n] % 2 == 0:",
"- A[n] //= 2",
"+ for a in A:",
"+ while a % 2 == 0:",
"+ a //= 2"
]
| false | 0.045688 | 0.044829 | 1.019144 | [
"s008422869",
"s430905822"
]
|
u426534722 | p02363 | python | s172305138 | s921124709 | 990 | 530 | 8,176 | 8,120 | Accepted | Accepted | 46.46 | from sys import stdin
from math import isinf
n, e = list(map(int, stdin.readline().split()))
d = [[float('inf')] * n for _ in range(n)]
for i in range(n):
d[i][i] = 0
for i in range(e):
u, v, c = list(map(int, stdin.readline().split()))
d[u][v] = c
for k in range(n):
for i in range(n):
if d[i][k] == float('inf'): continue
for j in range(n):
if d[k][j] == float('inf'): continue
if d[i][j] > d[i][k] + d[k][j]:
d[i][j] = d[i][k] + d[k][j]
for i in range(n):
if d[i][i] < 0:
print("NEGATIVE CYCLE")
exit(0)
for di in d:
print((' '.join(('INF' if isinf(dij) else str(dij) for dij in di)))) | from sys import stdin
from math import isinf
n, e = list(map(int, stdin.readline().split()))
d = [[float('inf')] * n for _ in range(n)]
for i in range(n):
d[i][i] = 0
for i in range(e):
u, v, c = list(map(int, stdin.readline().split()))
d[u][v] = c
for k in range(n):
for i in range(n):
for j in range(n):
if d[i][j] > d[i][k] + d[k][j]:
d[i][j] = d[i][k] + d[k][j]
for i in range(n):
if d[i][i] < 0:
print("NEGATIVE CYCLE")
exit(0)
for di in d:
print((' '.join(('INF' if isinf(dij) else str(dij) for dij in di)))) | 22 | 20 | 691 | 595 | from sys import stdin
from math import isinf
n, e = list(map(int, stdin.readline().split()))
d = [[float("inf")] * n for _ in range(n)]
for i in range(n):
d[i][i] = 0
for i in range(e):
u, v, c = list(map(int, stdin.readline().split()))
d[u][v] = c
for k in range(n):
for i in range(n):
if d[i][k] == float("inf"):
continue
for j in range(n):
if d[k][j] == float("inf"):
continue
if d[i][j] > d[i][k] + d[k][j]:
d[i][j] = d[i][k] + d[k][j]
for i in range(n):
if d[i][i] < 0:
print("NEGATIVE CYCLE")
exit(0)
for di in d:
print((" ".join(("INF" if isinf(dij) else str(dij) for dij in di))))
| from sys import stdin
from math import isinf
n, e = list(map(int, stdin.readline().split()))
d = [[float("inf")] * n for _ in range(n)]
for i in range(n):
d[i][i] = 0
for i in range(e):
u, v, c = list(map(int, stdin.readline().split()))
d[u][v] = c
for k in range(n):
for i in range(n):
for j in range(n):
if d[i][j] > d[i][k] + d[k][j]:
d[i][j] = d[i][k] + d[k][j]
for i in range(n):
if d[i][i] < 0:
print("NEGATIVE CYCLE")
exit(0)
for di in d:
print((" ".join(("INF" if isinf(dij) else str(dij) for dij in di))))
| false | 9.090909 | [
"- if d[i][k] == float(\"inf\"):",
"- continue",
"- if d[k][j] == float(\"inf\"):",
"- continue"
]
| false | 0.103445 | 0.09376 | 1.103293 | [
"s172305138",
"s921124709"
]
|
u644907318 | p02813 | python | s375109336 | s931773018 | 202 | 80 | 40,300 | 73,360 | Accepted | Accepted | 60.4 | from itertools import permutations
N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
A = sorted(P)
cnt = 0
for x in permutations(A,N):
x = list(x)
if x==P:
a = cnt
if x==Q:
b = cnt
cnt += 1
print((abs(a-b))) | from itertools import permutations
N = int(eval(input()))
P = tuple(list(map(int,input().split())))
Q = tuple(list(map(int,input().split())))
cnt = 0
for x in permutations(list(range(1,N+1)),N):
if P==x:
indP = cnt
if Q==x:
indQ = cnt
cnt += 1
print((abs(indP-indQ))) | 14 | 12 | 287 | 292 | from itertools import permutations
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
A = sorted(P)
cnt = 0
for x in permutations(A, N):
x = list(x)
if x == P:
a = cnt
if x == Q:
b = cnt
cnt += 1
print((abs(a - b)))
| from itertools import permutations
N = int(eval(input()))
P = tuple(list(map(int, input().split())))
Q = tuple(list(map(int, input().split())))
cnt = 0
for x in permutations(list(range(1, N + 1)), N):
if P == x:
indP = cnt
if Q == x:
indQ = cnt
cnt += 1
print((abs(indP - indQ)))
| false | 14.285714 | [
"-P = list(map(int, input().split()))",
"-Q = list(map(int, input().split()))",
"-A = sorted(P)",
"+P = tuple(list(map(int, input().split())))",
"+Q = tuple(list(map(int, input().split())))",
"-for x in permutations(A, N):",
"- x = list(x)",
"- if x == P:",
"- a = cnt",
"- if x == Q:",
"- b = cnt",
"+for x in permutations(list(range(1, N + 1)), N):",
"+ if P == x:",
"+ indP = cnt",
"+ if Q == x:",
"+ indQ = cnt",
"-print((abs(a - b)))",
"+print((abs(indP - indQ)))"
]
| false | 0.040777 | 0.036881 | 1.105657 | [
"s375109336",
"s931773018"
]
|
u018679195 | p03680 | python | s631748766 | s044381952 | 531 | 197 | 55,896 | 7,084 | Accepted | Accepted | 62.9 | n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
visited = set()
count = 0
next = 1
while True:
count += 1
visited.add(next)
next = a[next-1]
if next == 2:
print(count)
exit(0)
if next in visited:
print((-1))
exit(0) | n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
b = a[0]
cnt = 1
while b != 2 and cnt <= n:
b = a[b-1]
cnt += 1
if b == 2:
print(cnt)
else:
print((-1))
| 18 | 13 | 277 | 186 | n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
visited = set()
count = 0
next = 1
while True:
count += 1
visited.add(next)
next = a[next - 1]
if next == 2:
print(count)
exit(0)
if next in visited:
print((-1))
exit(0)
| n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
b = a[0]
cnt = 1
while b != 2 and cnt <= n:
b = a[b - 1]
cnt += 1
if b == 2:
print(cnt)
else:
print((-1))
| false | 27.777778 | [
"-a = []",
"-for i in range(n):",
"- a.append(int(eval(input())))",
"-visited = set()",
"-count = 0",
"-next = 1",
"-while True:",
"- count += 1",
"- visited.add(next)",
"- next = a[next - 1]",
"- if next == 2:",
"- print(count)",
"- exit(0)",
"- if next in visited:",
"- print((-1))",
"- exit(0)",
"+a = [int(eval(input())) for i in range(n)]",
"+b = a[0]",
"+cnt = 1",
"+while b != 2 and cnt <= n:",
"+ b = a[b - 1]",
"+ cnt += 1",
"+if b == 2:",
"+ print(cnt)",
"+else:",
"+ print((-1))"
]
| false | 0.036598 | 0.036089 | 1.014101 | [
"s631748766",
"s044381952"
]
|
u788703383 | p02702 | python | s407256227 | s748776167 | 344 | 296 | 9,364 | 9,240 | Accepted | Accepted | 13.95 | s = eval(input())
MOD = 2019
r = [0]*MOD
r[0] = 1
z = 0
t = 0
for i in reversed(s):
z = int(i) * pow(10,t,MOD) + z
z %= MOD
r[z] += 1
t += 1
print((sum(i*(i-1)//2 for i in r)))
| def main():
s = eval(input())
MOD = 2019
r = [0]*MOD
r[0] = 1
z = 0
t = 0
for i in reversed(s):
z = int(i) * pow(10,t,MOD) + z
z %= MOD
r[z] += 1
t += 1
print((sum(i*(i-1)//2 for i in r)))
if __name__ == '__main__':
main()
| 12 | 17 | 196 | 301 | s = eval(input())
MOD = 2019
r = [0] * MOD
r[0] = 1
z = 0
t = 0
for i in reversed(s):
z = int(i) * pow(10, t, MOD) + z
z %= MOD
r[z] += 1
t += 1
print((sum(i * (i - 1) // 2 for i in r)))
| def main():
s = eval(input())
MOD = 2019
r = [0] * MOD
r[0] = 1
z = 0
t = 0
for i in reversed(s):
z = int(i) * pow(10, t, MOD) + z
z %= MOD
r[z] += 1
t += 1
print((sum(i * (i - 1) // 2 for i in r)))
if __name__ == "__main__":
main()
| false | 29.411765 | [
"-s = eval(input())",
"-MOD = 2019",
"-r = [0] * MOD",
"-r[0] = 1",
"-z = 0",
"-t = 0",
"-for i in reversed(s):",
"- z = int(i) * pow(10, t, MOD) + z",
"- z %= MOD",
"- r[z] += 1",
"- t += 1",
"-print((sum(i * (i - 1) // 2 for i in r)))",
"+def main():",
"+ s = eval(input())",
"+ MOD = 2019",
"+ r = [0] * MOD",
"+ r[0] = 1",
"+ z = 0",
"+ t = 0",
"+ for i in reversed(s):",
"+ z = int(i) * pow(10, t, MOD) + z",
"+ z %= MOD",
"+ r[z] += 1",
"+ t += 1",
"+ print((sum(i * (i - 1) // 2 for i in r)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.037109 | 0.043092 | 0.861155 | [
"s407256227",
"s748776167"
]
|
u671861352 | p03006 | python | s481721658 | s161224697 | 168 | 18 | 3,444 | 3,188 | Accepted | Accepted | 89.29 | N = int(eval(input()))
if N == 1:
print((1))
exit()
xy = [tuple(int(e) for e in input().split()) for _ in range(N)]
d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j]
items = list(set(d_list))
s = 1
for item in items:
c = d_list.count(item)
if c > s:
s = c
print((N - s)) | N = int(eval(input()))
if N == 1:
print((1))
else:
xy = [tuple(int(e) for e in input().split()) for _ in range(N)]
xy.sort()
d = {}
for i in range(N):
for j in range(i + 1, N):
p = xy[i][0] - xy[j][0]
q = xy[i][1] - xy[j][1]
if (p, q) in d:
d[(p, q)] += 1
else:
d[(p, q)] = 1
print((N - max(d.values()))) | 13 | 16 | 318 | 421 | N = int(eval(input()))
if N == 1:
print((1))
exit()
xy = [tuple(int(e) for e in input().split()) for _ in range(N)]
d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j]
items = list(set(d_list))
s = 1
for item in items:
c = d_list.count(item)
if c > s:
s = c
print((N - s))
| N = int(eval(input()))
if N == 1:
print((1))
else:
xy = [tuple(int(e) for e in input().split()) for _ in range(N)]
xy.sort()
d = {}
for i in range(N):
for j in range(i + 1, N):
p = xy[i][0] - xy[j][0]
q = xy[i][1] - xy[j][1]
if (p, q) in d:
d[(p, q)] += 1
else:
d[(p, q)] = 1
print((N - max(d.values())))
| false | 18.75 | [
"- exit()",
"-xy = [tuple(int(e) for e in input().split()) for _ in range(N)]",
"-d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j]",
"-items = list(set(d_list))",
"-s = 1",
"-for item in items:",
"- c = d_list.count(item)",
"- if c > s:",
"- s = c",
"-print((N - s))",
"+else:",
"+ xy = [tuple(int(e) for e in input().split()) for _ in range(N)]",
"+ xy.sort()",
"+ d = {}",
"+ for i in range(N):",
"+ for j in range(i + 1, N):",
"+ p = xy[i][0] - xy[j][0]",
"+ q = xy[i][1] - xy[j][1]",
"+ if (p, q) in d:",
"+ d[(p, q)] += 1",
"+ else:",
"+ d[(p, q)] = 1",
"+ print((N - max(d.values())))"
]
| false | 0.047186 | 0.04432 | 1.064656 | [
"s481721658",
"s161224697"
]
|
u352394527 | p00481 | python | s183268209 | s101905654 | 19,860 | 3,420 | 29,300 | 29,296 | Accepted | Accepted | 82.78 | import queue
from collections import deque
h,w,n = list(map(int,input().split()))
factrys = [None] * (n + 1)
ss = ["X" * (w + 2)]
for i in range(h):
s = "X" + eval(input()) + "X"
if "S" in s:
factrys[0] = (i + 1, s.index("S"))
for j in range(1,n + 1):
if str(j) in s:
factrys[j] = (i + 1, s.index(str(j)))
ss.append(s)
ss.append("X" * (w + 2))
def bfs(i):
mp = [[None] * (w + 2) for j in range(h + 2)]
x,y = factrys[i]
mp[x][y] = 0
que = queue.Queue()
que.put((x, y))
while True:
(x,y) = que.get()
# print(i,x,y)
# print(mp[x][y])
if (x,y) == factrys[i + 1]:
return mp[x][y]
count = mp[x][y]
if ss[x + 1][y] != "X" and mp[x + 1][y] is None:
mp[x + 1][y] = count + 1
que.put((x + 1, y))
if ss[x - 1][y] != "X" and mp[x - 1][y] is None:
mp[x - 1][y] = count + 1
que.put((x - 1, y))
if ss[x][y + 1] != "X" and mp[x][y + 1] is None:
mp[x][y + 1] = count + 1
que.put((x, y + 1))
if ss[x][y - 1] != "X" and mp[x][y - 1] is None:
mp[x][y - 1] = count + 1
que.put((x, y - 1))
ans = 0
for i in range(n):
ret = bfs(i)
if ret is None:
ans += 0
else:
ans += (ret)
print(ans)
| import queue
from collections import deque
h,w,n = list(map(int,input().split()))
factrys = [None] * (n + 1)
ss = ["X" * (w + 2)]
for i in range(h):
s = "X" + eval(input()) + "X"
if "S" in s:
factrys[0] = (i + 1, s.index("S"))
for j in range(1,n + 1):
if str(j) in s:
factrys[j] = (i + 1, s.index(str(j)))
ss.append(s)
ss.append("X" * (w + 2))
def bfs(i):
mp = [[None] * (w + 2) for j in range(h + 2)]
x,y = factrys[i]
mp[x][y] = 0
que = deque()
que.append((x, y))
while True:
(x,y) = que.popleft()
# print(i,x,y)
# print(mp[x][y])
if (x,y) == factrys[i + 1]:
return mp[x][y]
count = mp[x][y]
if ss[x + 1][y] != "X" and mp[x + 1][y] is None:
mp[x + 1][y] = count + 1
que.append((x + 1, y))
if ss[x - 1][y] != "X" and mp[x - 1][y] is None:
mp[x - 1][y] = count + 1
que.append((x - 1, y))
if ss[x][y + 1] != "X" and mp[x][y + 1] is None:
mp[x][y + 1] = count + 1
que.append((x, y + 1))
if ss[x][y - 1] != "X" and mp[x][y - 1] is None:
mp[x][y - 1] = count + 1
que.append((x, y - 1))
ans = 0
for i in range(n):
ret = bfs(i)
if ret is None:
ans += 0
else:
ans += (ret)
print(ans)
| 49 | 49 | 1,237 | 1,250 | import queue
from collections import deque
h, w, n = list(map(int, input().split()))
factrys = [None] * (n + 1)
ss = ["X" * (w + 2)]
for i in range(h):
s = "X" + eval(input()) + "X"
if "S" in s:
factrys[0] = (i + 1, s.index("S"))
for j in range(1, n + 1):
if str(j) in s:
factrys[j] = (i + 1, s.index(str(j)))
ss.append(s)
ss.append("X" * (w + 2))
def bfs(i):
mp = [[None] * (w + 2) for j in range(h + 2)]
x, y = factrys[i]
mp[x][y] = 0
que = queue.Queue()
que.put((x, y))
while True:
(x, y) = que.get()
# print(i,x,y)
# print(mp[x][y])
if (x, y) == factrys[i + 1]:
return mp[x][y]
count = mp[x][y]
if ss[x + 1][y] != "X" and mp[x + 1][y] is None:
mp[x + 1][y] = count + 1
que.put((x + 1, y))
if ss[x - 1][y] != "X" and mp[x - 1][y] is None:
mp[x - 1][y] = count + 1
que.put((x - 1, y))
if ss[x][y + 1] != "X" and mp[x][y + 1] is None:
mp[x][y + 1] = count + 1
que.put((x, y + 1))
if ss[x][y - 1] != "X" and mp[x][y - 1] is None:
mp[x][y - 1] = count + 1
que.put((x, y - 1))
ans = 0
for i in range(n):
ret = bfs(i)
if ret is None:
ans += 0
else:
ans += ret
print(ans)
| import queue
from collections import deque
h, w, n = list(map(int, input().split()))
factrys = [None] * (n + 1)
ss = ["X" * (w + 2)]
for i in range(h):
s = "X" + eval(input()) + "X"
if "S" in s:
factrys[0] = (i + 1, s.index("S"))
for j in range(1, n + 1):
if str(j) in s:
factrys[j] = (i + 1, s.index(str(j)))
ss.append(s)
ss.append("X" * (w + 2))
def bfs(i):
mp = [[None] * (w + 2) for j in range(h + 2)]
x, y = factrys[i]
mp[x][y] = 0
que = deque()
que.append((x, y))
while True:
(x, y) = que.popleft()
# print(i,x,y)
# print(mp[x][y])
if (x, y) == factrys[i + 1]:
return mp[x][y]
count = mp[x][y]
if ss[x + 1][y] != "X" and mp[x + 1][y] is None:
mp[x + 1][y] = count + 1
que.append((x + 1, y))
if ss[x - 1][y] != "X" and mp[x - 1][y] is None:
mp[x - 1][y] = count + 1
que.append((x - 1, y))
if ss[x][y + 1] != "X" and mp[x][y + 1] is None:
mp[x][y + 1] = count + 1
que.append((x, y + 1))
if ss[x][y - 1] != "X" and mp[x][y - 1] is None:
mp[x][y - 1] = count + 1
que.append((x, y - 1))
ans = 0
for i in range(n):
ret = bfs(i)
if ret is None:
ans += 0
else:
ans += ret
print(ans)
| false | 0 | [
"- que = queue.Queue()",
"- que.put((x, y))",
"+ que = deque()",
"+ que.append((x, y))",
"- (x, y) = que.get()",
"+ (x, y) = que.popleft()",
"- que.put((x + 1, y))",
"+ que.append((x + 1, y))",
"- que.put((x - 1, y))",
"+ que.append((x - 1, y))",
"- que.put((x, y + 1))",
"+ que.append((x, y + 1))",
"- que.put((x, y - 1))",
"+ que.append((x, y - 1))"
]
| false | 0.16615 | 0.039554 | 4.200593 | [
"s183268209",
"s101905654"
]
|
u197868423 | p02660 | python | s535850048 | s369587320 | 383 | 139 | 9,480 | 9,448 | Accepted | Accepted | 63.71 | from collections import Counter
N = int(eval(input()))
a = []
x = 2
while x ** 2 <= N:
if N % x == 0:
a.append(x)
N /= x
x = 2
else:
x += 1
else:
if x <= N:
a.append(int(N))
a = Counter(a)
ans = 0
for i in a:
k = 1
while True:
if a[i] >= k:
ans += 1
a[i] -= k
k += 1
else:
break
print(ans) | n = int(eval(input()))
arr = []
for i in range(2, int(-(-n**0.5//1))+1):
if n%i==0:
cnt=0
while n%i==0:
cnt+=1
n //= i
arr.append([i, cnt])
if n!=1:
arr.append([n, 1])
# if arr==[]:
# arr.append([n, 1])
ans = 0
for i in range(len(arr)):
k = 1
while True:
if arr[i][1] >= k:
ans += 1
arr[i][1] -= k
k += 1
else:
break
print(ans) | 28 | 29 | 436 | 486 | from collections import Counter
N = int(eval(input()))
a = []
x = 2
while x**2 <= N:
if N % x == 0:
a.append(x)
N /= x
x = 2
else:
x += 1
else:
if x <= N:
a.append(int(N))
a = Counter(a)
ans = 0
for i in a:
k = 1
while True:
if a[i] >= k:
ans += 1
a[i] -= k
k += 1
else:
break
print(ans)
| n = int(eval(input()))
arr = []
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if n % i == 0:
cnt = 0
while n % i == 0:
cnt += 1
n //= i
arr.append([i, cnt])
if n != 1:
arr.append([n, 1])
# if arr==[]:
# arr.append([n, 1])
ans = 0
for i in range(len(arr)):
k = 1
while True:
if arr[i][1] >= k:
ans += 1
arr[i][1] -= k
k += 1
else:
break
print(ans)
| false | 3.448276 | [
"-from collections import Counter",
"-",
"-N = int(eval(input()))",
"-a = []",
"-x = 2",
"-while x**2 <= N:",
"- if N % x == 0:",
"- a.append(x)",
"- N /= x",
"- x = 2",
"- else:",
"- x += 1",
"-else:",
"- if x <= N:",
"- a.append(int(N))",
"-a = Counter(a)",
"+n = int(eval(input()))",
"+arr = []",
"+for i in range(2, int(-(-(n**0.5) // 1)) + 1):",
"+ if n % i == 0:",
"+ cnt = 0",
"+ while n % i == 0:",
"+ cnt += 1",
"+ n //= i",
"+ arr.append([i, cnt])",
"+if n != 1:",
"+ arr.append([n, 1])",
"+# if arr==[]:",
"+# arr.append([n, 1])",
"-for i in a:",
"+for i in range(len(arr)):",
"- if a[i] >= k:",
"+ if arr[i][1] >= k:",
"- a[i] -= k",
"+ arr[i][1] -= k"
]
| false | 0.041999 | 0.051373 | 0.817544 | [
"s535850048",
"s369587320"
]
|
u311379832 | p03281 | python | s360167642 | s124206035 | 19 | 17 | 3,060 | 3,060 | Accepted | Accepted | 10.53 | N = int(eval(input()))
ansCnt = 0
for i in range(1, N + 1, 2):
tmpCnt = 0
for j in range(1, N + 1):
if i < j:
break
if i % j == 0:
tmpCnt += 1
if tmpCnt == 8:
ansCnt += 1
print(ansCnt) | N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
cnt = 0
if i % 2 != 0:
for j in range(1, int(pow(i, 0.5)) + 1):
if i % j == 0:
cnt += 1
if j != i // j:
cnt += 1
if cnt == 8:
ans += 1
print(ans) | 13 | 14 | 251 | 310 | N = int(eval(input()))
ansCnt = 0
for i in range(1, N + 1, 2):
tmpCnt = 0
for j in range(1, N + 1):
if i < j:
break
if i % j == 0:
tmpCnt += 1
if tmpCnt == 8:
ansCnt += 1
print(ansCnt)
| N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
cnt = 0
if i % 2 != 0:
for j in range(1, int(pow(i, 0.5)) + 1):
if i % j == 0:
cnt += 1
if j != i // j:
cnt += 1
if cnt == 8:
ans += 1
print(ans)
| false | 7.142857 | [
"-ansCnt = 0",
"-for i in range(1, N + 1, 2):",
"- tmpCnt = 0",
"- for j in range(1, N + 1):",
"- if i < j:",
"- break",
"- if i % j == 0:",
"- tmpCnt += 1",
"- if tmpCnt == 8:",
"- ansCnt += 1",
"-print(ansCnt)",
"+ans = 0",
"+for i in range(1, N + 1):",
"+ cnt = 0",
"+ if i % 2 != 0:",
"+ for j in range(1, int(pow(i, 0.5)) + 1):",
"+ if i % j == 0:",
"+ cnt += 1",
"+ if j != i // j:",
"+ cnt += 1",
"+ if cnt == 8:",
"+ ans += 1",
"+print(ans)"
]
| false | 0.078122 | 0.074712 | 1.045636 | [
"s360167642",
"s124206035"
]
|
u146685294 | p02899 | python | s356224058 | s870944412 | 264 | 242 | 23,480 | 20,040 | Accepted | Accepted | 8.33 | import heapq
n = int(eval(input()))
list = []
idx = 1
for count_str in input().split():
count = int(count_str)
heapq.heappush(list, (count, idx))
idx += 1
print((" ".join([ str(heapq.heappop(list)[1]) for _ in range(n) ])))
| import heapq
n = int(eval(input()))
priority_list = []
student = 0
for priority in list(map(int, input().split())):
student += 1
priority_list.append((priority, str(student)))
heapq.heapify(priority_list)
print((' '.join([ heapq.heappop(priority_list)[1] for _ in range(n) ]))) | 13 | 13 | 248 | 293 | import heapq
n = int(eval(input()))
list = []
idx = 1
for count_str in input().split():
count = int(count_str)
heapq.heappush(list, (count, idx))
idx += 1
print((" ".join([str(heapq.heappop(list)[1]) for _ in range(n)])))
| import heapq
n = int(eval(input()))
priority_list = []
student = 0
for priority in list(map(int, input().split())):
student += 1
priority_list.append((priority, str(student)))
heapq.heapify(priority_list)
print((" ".join([heapq.heappop(priority_list)[1] for _ in range(n)])))
| false | 0 | [
"-list = []",
"-idx = 1",
"-for count_str in input().split():",
"- count = int(count_str)",
"- heapq.heappush(list, (count, idx))",
"- idx += 1",
"-print((\" \".join([str(heapq.heappop(list)[1]) for _ in range(n)])))",
"+priority_list = []",
"+student = 0",
"+for priority in list(map(int, input().split())):",
"+ student += 1",
"+ priority_list.append((priority, str(student)))",
"+heapq.heapify(priority_list)",
"+print((\" \".join([heapq.heappop(priority_list)[1] for _ in range(n)])))"
]
| false | 0.049131 | 0.048403 | 1.015031 | [
"s356224058",
"s870944412"
]
|
u133936772 | p02614 | python | s998010247 | s382371814 | 70 | 60 | 9,100 | 9,188 | Accepted | Accepted | 14.29 | h,w,x=list(map(int,input().split()))
c=[eval(input()) for _ in range(h)]
a=0
for i in range(2**h):
for j in range(2**w):
t=0
for k in range(h):
for l in range(w):
if i>>k&1 and j>>l&1 and c[k][l]=='#': t+=1
if t==x: a+=1
print(a) | h,w,x=list(map(int,input().split()))
c=[eval(input()) for _ in [0]*h]
print((sum(x==sum(i>>k&1 and j>>l&1 and c[k][l]=='#' for k in range(h) for l in range(w)) for i in range(2**h) for j in range(2**w))
)) | 11 | 4 | 255 | 194 | h, w, x = list(map(int, input().split()))
c = [eval(input()) for _ in range(h)]
a = 0
for i in range(2**h):
for j in range(2**w):
t = 0
for k in range(h):
for l in range(w):
if i >> k & 1 and j >> l & 1 and c[k][l] == "#":
t += 1
if t == x:
a += 1
print(a)
| h, w, x = list(map(int, input().split()))
c = [eval(input()) for _ in [0] * h]
print(
(
sum(
x
== sum(
i >> k & 1 and j >> l & 1 and c[k][l] == "#"
for k in range(h)
for l in range(w)
)
for i in range(2**h)
for j in range(2**w)
)
)
)
| false | 63.636364 | [
"-c = [eval(input()) for _ in range(h)]",
"-a = 0",
"-for i in range(2**h):",
"- for j in range(2**w):",
"- t = 0",
"- for k in range(h):",
"- for l in range(w):",
"- if i >> k & 1 and j >> l & 1 and c[k][l] == \"#\":",
"- t += 1",
"- if t == x:",
"- a += 1",
"-print(a)",
"+c = [eval(input()) for _ in [0] * h]",
"+print(",
"+ (",
"+ sum(",
"+ x",
"+ == sum(",
"+ i >> k & 1 and j >> l & 1 and c[k][l] == \"#\"",
"+ for k in range(h)",
"+ for l in range(w)",
"+ )",
"+ for i in range(2**h)",
"+ for j in range(2**w)",
"+ )",
"+ )",
"+)"
]
| false | 0.125615 | 0.047787 | 2.628634 | [
"s998010247",
"s382371814"
]
|
u416758623 | p03036 | python | s345935393 | s344701361 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | r,d,x = list(map(int, input().split()))
for i in range(10):
x = r * x - d
print(x) | r, d , x = list(map(int, input().split()))
for i in range(10):
x = (r * x) - d
print(x) | 5 | 4 | 89 | 92 | r, d, x = list(map(int, input().split()))
for i in range(10):
x = r * x - d
print(x)
| r, d, x = list(map(int, input().split()))
for i in range(10):
x = (r * x) - d
print(x)
| false | 20 | [
"- x = r * x - d",
"+ x = (r * x) - d"
]
| false | 0.041333 | 0.043345 | 0.953589 | [
"s345935393",
"s344701361"
]
|
u046187684 | p03112 | python | s414708188 | s613677789 | 814 | 737 | 39,508 | 39,524 | Accepted | Accepted | 9.46 | from bisect import bisect_left
def solve(string):
a, b, q, *stx = list(map(int, string.split()))
s = [-10**10] + stx[:a] + [2 * 10**10]
t = [-10**10] + stx[a:a + b] + [2 * 10**10]
# x = dict([])
ans = []
i_s = 0
i_t = 0
for _x in stx[-q:]:
"""
while s[i_s] < _x:
i_s += 1
while t[i_t] < _x:
i_t += 1
"""
i_s, i_t = bisect_left(s, _x), bisect_left(t, _x)
ls, rs = _x - s[i_s - 1], s[i_s] - _x
lt, rt = _x - t[i_t - 1], t[i_t] - _x
r_max = max(rs, rt)
l_max = max(ls, lt)
"""
x[_x] = min([
r_max - _x, _x - l_min, rt - ls + min(rt - _x, _x - ls),
rs - lt + min(rs - _x, _x - lt)
])
"""
ans.append(str(min([r_max, l_max, rt + ls + min(rt, ls), rs + lt + min(rs, lt)])))
# return "\n".join([str(x[_x]) for _x in stx[-q:]])
return "\n".join(ans)
if __name__ == '__main__':
n, m, l = list(map(int, input().split()))
print((solve('{} {} {}\n'.format(n, m, l) + '\n'.join([eval(input()) for _ in range(n + m + l)]))))
| from bisect import bisect_left
def solve(string):
a, b, q, *stx = list(map(int, string.split()))
s = [-10**10] + stx[:a] + [2 * 10**10]
t = [-10**10] + stx[a:a + b] + [2 * 10**10]
# x = dict([])
ans = []
i_s = 0
i_t = 0
for _x in stx[-q:]:
"""
while s[i_s] < _x:
i_s += 1
while t[i_t] < _x:
i_t += 1
"""
i_s, i_t = bisect_left(s, _x), bisect_left(t, _x)
ls, rs = _x - s[i_s - 1], s[i_s] - _x
lt, rt = _x - t[i_t - 1], t[i_t] - _x
r_max = max(rs, rt)
l_max = max(ls, lt)
"""
x[_x] = min([
r_max - _x, _x - l_min, rt - ls + min(rt - _x, _x - ls),
rs - lt + min(rs - _x, _x - lt)
])
"""
ans.append(
str(
min(r_max, l_max, rt + ls + (rt if rt < ls else ls),
rs + lt + (rs if rs < lt else lt))))
# return "\n".join([str(x[_x]) for _x in stx[-q:]])
return "\n".join(ans)
if __name__ == '__main__':
n, m, l = list(map(int, input().split()))
print((solve('{} {} {}\n'.format(n, m, l) + '\n'.join([eval(input()) for _ in range(n + m + l)]))))
| 37 | 40 | 1,138 | 1,213 | from bisect import bisect_left
def solve(string):
a, b, q, *stx = list(map(int, string.split()))
s = [-(10**10)] + stx[:a] + [2 * 10**10]
t = [-(10**10)] + stx[a : a + b] + [2 * 10**10]
# x = dict([])
ans = []
i_s = 0
i_t = 0
for _x in stx[-q:]:
"""
while s[i_s] < _x:
i_s += 1
while t[i_t] < _x:
i_t += 1
"""
i_s, i_t = bisect_left(s, _x), bisect_left(t, _x)
ls, rs = _x - s[i_s - 1], s[i_s] - _x
lt, rt = _x - t[i_t - 1], t[i_t] - _x
r_max = max(rs, rt)
l_max = max(ls, lt)
"""
x[_x] = min([
r_max - _x, _x - l_min, rt - ls + min(rt - _x, _x - ls),
rs - lt + min(rs - _x, _x - lt)
])
"""
ans.append(
str(min([r_max, l_max, rt + ls + min(rt, ls), rs + lt + min(rs, lt)]))
)
# return "\n".join([str(x[_x]) for _x in stx[-q:]])
return "\n".join(ans)
if __name__ == "__main__":
n, m, l = list(map(int, input().split()))
print(
(
solve(
"{} {} {}\n".format(n, m, l)
+ "\n".join([eval(input()) for _ in range(n + m + l)])
)
)
)
| from bisect import bisect_left
def solve(string):
a, b, q, *stx = list(map(int, string.split()))
s = [-(10**10)] + stx[:a] + [2 * 10**10]
t = [-(10**10)] + stx[a : a + b] + [2 * 10**10]
# x = dict([])
ans = []
i_s = 0
i_t = 0
for _x in stx[-q:]:
"""
while s[i_s] < _x:
i_s += 1
while t[i_t] < _x:
i_t += 1
"""
i_s, i_t = bisect_left(s, _x), bisect_left(t, _x)
ls, rs = _x - s[i_s - 1], s[i_s] - _x
lt, rt = _x - t[i_t - 1], t[i_t] - _x
r_max = max(rs, rt)
l_max = max(ls, lt)
"""
x[_x] = min([
r_max - _x, _x - l_min, rt - ls + min(rt - _x, _x - ls),
rs - lt + min(rs - _x, _x - lt)
])
"""
ans.append(
str(
min(
r_max,
l_max,
rt + ls + (rt if rt < ls else ls),
rs + lt + (rs if rs < lt else lt),
)
)
)
# return "\n".join([str(x[_x]) for _x in stx[-q:]])
return "\n".join(ans)
if __name__ == "__main__":
n, m, l = list(map(int, input().split()))
print(
(
solve(
"{} {} {}\n".format(n, m, l)
+ "\n".join([eval(input()) for _ in range(n + m + l)])
)
)
)
| false | 7.5 | [
"- str(min([r_max, l_max, rt + ls + min(rt, ls), rs + lt + min(rs, lt)]))",
"+ str(",
"+ min(",
"+ r_max,",
"+ l_max,",
"+ rt + ls + (rt if rt < ls else ls),",
"+ rs + lt + (rs if rs < lt else lt),",
"+ )",
"+ )"
]
| false | 0.048959 | 0.092911 | 0.526938 | [
"s414708188",
"s613677789"
]
|
u279493135 | p03475 | python | s488213997 | s453534752 | 2,352 | 109 | 3,188 | 3,188 | Accepted | Accepted | 95.37 | N = int(eval(input()))
CSF = [list(map(int, input().strip().split())) for _ in range(N-1)]
for i in range(N): # 出発駅
time = 0
for j in range(i, N-1):
if time < CSF[j][1]: # 開通まで待つ
time = CSF[j][1]
else:
for k in range(CSF[j][2]):
if (time + k) % CSF[j][2] == 0:
time = time + k
break
time += CSF[j][0]
print(time)
| N = int(eval(input()))
CSF = [list(map(int, input().strip().split())) for _ in range(N-1)]
for i in range(N): # 出発駅
time = 0
for j in range(i, N-1):
if time < CSF[j][1]: # 開通まで待つ
time = CSF[j][1]
elif time % CSF[j][2] == 0:
pass
else:
time += CSF[j][2]-time%CSF[j][2]
time += CSF[j][0]
print(time)
| 16 | 15 | 384 | 350 | N = int(eval(input()))
CSF = [list(map(int, input().strip().split())) for _ in range(N - 1)]
for i in range(N): # 出発駅
time = 0
for j in range(i, N - 1):
if time < CSF[j][1]: # 開通まで待つ
time = CSF[j][1]
else:
for k in range(CSF[j][2]):
if (time + k) % CSF[j][2] == 0:
time = time + k
break
time += CSF[j][0]
print(time)
| N = int(eval(input()))
CSF = [list(map(int, input().strip().split())) for _ in range(N - 1)]
for i in range(N): # 出発駅
time = 0
for j in range(i, N - 1):
if time < CSF[j][1]: # 開通まで待つ
time = CSF[j][1]
elif time % CSF[j][2] == 0:
pass
else:
time += CSF[j][2] - time % CSF[j][2]
time += CSF[j][0]
print(time)
| false | 6.25 | [
"+ elif time % CSF[j][2] == 0:",
"+ pass",
"- for k in range(CSF[j][2]):",
"- if (time + k) % CSF[j][2] == 0:",
"- time = time + k",
"- break",
"+ time += CSF[j][2] - time % CSF[j][2]"
]
| false | 0.075575 | 0.036358 | 2.078646 | [
"s488213997",
"s453534752"
]
|
u046187684 | p03283 | python | s622821716 | s558756946 | 2,119 | 709 | 138,104 | 60,160 | Accepted | Accepted | 66.54 | def solve(string):
n, m, q, *lrpq = list(map(int, string.split()))
lr, pq = lrpq[:2 * m], lrpq[2 * m:]
t = [[0] * (n + 1) for _ in range(n + 1)]
for l, r in zip(lr[::2], lr[1::2]):
t[l][r] += 1
for i in range(n + 1):
for j in range(n + 1):
if j > 0:
t[i][j] += t[i][j - 1]
ans = [
str(sum([t[i][q] - t[i][p - 1]
for i in range(p, q + 1)]))
for p, q in zip(pq[::2], pq[1::2])
]
return "\n".join(ans)
if __name__ == '__main__':
n, m, q = list(map(int, input().split()))
print((solve('{} {} {}\n'.format(n, m, q) + '\n'.join([eval(input()) for _ in range(m + q)]))))
| def solve(string):
n, m, q, *lrpq = list(map(int, string.split()))
lr, pq = lrpq[:2 * m], lrpq[2 * m:]
t = [[0] * (n + 1) for _ in range(n + 1)]
for l, r in zip(lr[::2], lr[1::2]):
t[l][r] += 1
for i in range(n + 1):
for j in range(n + 1):
if j > 0:
t[i][j] += t[i][j - 1]
for i in range(n + 1):
for j in range(n + 1):
if i > 0:
t[i][j] += t[i - 1][j]
ans = [
str(t[q][q] - t[p - 1][q] - t[q][p - 1] + t[p - 1][p - 1])
for p, q in zip(pq[::2], pq[1::2])
]
return "\n".join(ans)
if __name__ == '__main__':
n, m, q = list(map(int, input().split()))
print((solve('{} {} {}\n'.format(n, m, q) + '\n'.join([eval(input()) for _ in range(m + q)]))))
| 22 | 25 | 685 | 790 | def solve(string):
n, m, q, *lrpq = list(map(int, string.split()))
lr, pq = lrpq[: 2 * m], lrpq[2 * m :]
t = [[0] * (n + 1) for _ in range(n + 1)]
for l, r in zip(lr[::2], lr[1::2]):
t[l][r] += 1
for i in range(n + 1):
for j in range(n + 1):
if j > 0:
t[i][j] += t[i][j - 1]
ans = [
str(sum([t[i][q] - t[i][p - 1] for i in range(p, q + 1)]))
for p, q in zip(pq[::2], pq[1::2])
]
return "\n".join(ans)
if __name__ == "__main__":
n, m, q = list(map(int, input().split()))
print(
(
solve(
"{} {} {}\n".format(n, m, q)
+ "\n".join([eval(input()) for _ in range(m + q)])
)
)
)
| def solve(string):
n, m, q, *lrpq = list(map(int, string.split()))
lr, pq = lrpq[: 2 * m], lrpq[2 * m :]
t = [[0] * (n + 1) for _ in range(n + 1)]
for l, r in zip(lr[::2], lr[1::2]):
t[l][r] += 1
for i in range(n + 1):
for j in range(n + 1):
if j > 0:
t[i][j] += t[i][j - 1]
for i in range(n + 1):
for j in range(n + 1):
if i > 0:
t[i][j] += t[i - 1][j]
ans = [
str(t[q][q] - t[p - 1][q] - t[q][p - 1] + t[p - 1][p - 1])
for p, q in zip(pq[::2], pq[1::2])
]
return "\n".join(ans)
if __name__ == "__main__":
n, m, q = list(map(int, input().split()))
print(
(
solve(
"{} {} {}\n".format(n, m, q)
+ "\n".join([eval(input()) for _ in range(m + q)])
)
)
)
| false | 12 | [
"+ for i in range(n + 1):",
"+ for j in range(n + 1):",
"+ if i > 0:",
"+ t[i][j] += t[i - 1][j]",
"- str(sum([t[i][q] - t[i][p - 1] for i in range(p, q + 1)]))",
"+ str(t[q][q] - t[p - 1][q] - t[q][p - 1] + t[p - 1][p - 1])"
]
| false | 0.090699 | 0.110727 | 0.819128 | [
"s622821716",
"s558756946"
]
|
u845573105 | p02579 | python | s257173046 | s827869749 | 731 | 556 | 92,316 | 98,172 | Accepted | Accepted | 23.94 | H, W = list(map(int, input().split()))
ch, cw = list(map(int, input().split()))
gh, gw = list(map(int, input().split()))
f = [[s=="." for s in eval(input())] for h in range(H)]
ans = [[-1 for w in range(W)]for h in range(H)]
nextQ = [(ch-1)*1000 + cw-1]
ans[ch-1][cw-1] = 0
while len(nextQ)>0:
Q = list(nextQ)
nextQ = set()
visited = set()
while len(Q):
nh = Q.pop(0)
nw = nh%1000
nh = nh//1000
for dh in range(0-min(nh,2), 3):
if nh+dh>=H:
break
for dw in range(0-min(nw,2), 3):
if nw + dw>=W:
break
if dh==0 and dw==0:
continue
if dh*dw==0 and (abs(dh)==1 or abs(dw)==1):
if ans[nh+dh][nw+dw]==-1:
if f[nh+dh][nw+dw]:
Q.append((nh+dh)*1000 + nw+dw)
visited.add((nh+dh)*1000 + nw+dw)
ans[nh+dh][nw+dw]=ans[nh][nw]
else:
ans[nh+dh][nw+dw]=-2
elif ans[nh+dh][nw+dw]>ans[nh][nw]:
Q.append((nh+dh)*1000 + nw+dw)
nextQ -= {(nh+dh)*1000 + nw+dw}
ans[nh+dh][nw+dw]=ans[nh][nw]
else:
if ans[nh+dh][nw+dw]==-1:
if f[nh+dh][nw+dw]:
nextQ.add((nh+dh)*1000 + nw+dw)
ans[nh+dh][nw+dw]=ans[nh][nw]+1
else:
ans[nh+dh][nw+dw]=-2
print((ans[gh-1][gw-1]))
| H, W = list(map(int, input().split()))
ch, cw = list(map(int, input().split()))
gh, gw = list(map(int, input().split()))
f = [[s=="." for s in eval(input())] for h in range(H)]
ans = [[-1 for w in range(W)]for h in range(H)]
nextQ = [(ch-1)*1000 + cw-1]
ans[ch-1][cw-1] = 0
while len(nextQ)>0:
Q = list(nextQ)
nextQ = set()
i = 0
while i<len(Q):
nh = Q[i]
i += 1
nw = nh%1000
nh = nh//1000
for dh in range(0-min(nh,2), 3):
if nh+dh>=H:
break
for dw in range(0-min(nw,2), 3):
if nw + dw>=W:
break
if dh==0 and dw==0:
continue
if dh*dw==0 and (abs(dh)==1 or abs(dw)==1):
if ans[nh+dh][nw+dw]==-1:
if f[nh+dh][nw+dw]:
Q.append((nh+dh)*1000 + nw+dw)
ans[nh+dh][nw+dw]=ans[nh][nw]
else:
ans[nh+dh][nw+dw]=-2
elif ans[nh+dh][nw+dw]>ans[nh][nw]:
Q.append((nh+dh)*1000 + nw+dw)
nextQ -= {(nh+dh)*1000 + nw+dw}
ans[nh+dh][nw+dw]=ans[nh][nw]
else:
if ans[nh+dh][nw+dw]==-1:
if f[nh+dh][nw+dw]:
nextQ.add((nh+dh)*1000 + nw+dw)
ans[nh+dh][nw+dw]=ans[nh][nw]+1
else:
ans[nh+dh][nw+dw]=-2
print((ans[gh-1][gw-1]))
| 46 | 47 | 1,377 | 1,330 | H, W = list(map(int, input().split()))
ch, cw = list(map(int, input().split()))
gh, gw = list(map(int, input().split()))
f = [[s == "." for s in eval(input())] for h in range(H)]
ans = [[-1 for w in range(W)] for h in range(H)]
nextQ = [(ch - 1) * 1000 + cw - 1]
ans[ch - 1][cw - 1] = 0
while len(nextQ) > 0:
Q = list(nextQ)
nextQ = set()
visited = set()
while len(Q):
nh = Q.pop(0)
nw = nh % 1000
nh = nh // 1000
for dh in range(0 - min(nh, 2), 3):
if nh + dh >= H:
break
for dw in range(0 - min(nw, 2), 3):
if nw + dw >= W:
break
if dh == 0 and dw == 0:
continue
if dh * dw == 0 and (abs(dh) == 1 or abs(dw) == 1):
if ans[nh + dh][nw + dw] == -1:
if f[nh + dh][nw + dw]:
Q.append((nh + dh) * 1000 + nw + dw)
visited.add((nh + dh) * 1000 + nw + dw)
ans[nh + dh][nw + dw] = ans[nh][nw]
else:
ans[nh + dh][nw + dw] = -2
elif ans[nh + dh][nw + dw] > ans[nh][nw]:
Q.append((nh + dh) * 1000 + nw + dw)
nextQ -= {(nh + dh) * 1000 + nw + dw}
ans[nh + dh][nw + dw] = ans[nh][nw]
else:
if ans[nh + dh][nw + dw] == -1:
if f[nh + dh][nw + dw]:
nextQ.add((nh + dh) * 1000 + nw + dw)
ans[nh + dh][nw + dw] = ans[nh][nw] + 1
else:
ans[nh + dh][nw + dw] = -2
print((ans[gh - 1][gw - 1]))
| H, W = list(map(int, input().split()))
ch, cw = list(map(int, input().split()))
gh, gw = list(map(int, input().split()))
f = [[s == "." for s in eval(input())] for h in range(H)]
ans = [[-1 for w in range(W)] for h in range(H)]
nextQ = [(ch - 1) * 1000 + cw - 1]
ans[ch - 1][cw - 1] = 0
while len(nextQ) > 0:
Q = list(nextQ)
nextQ = set()
i = 0
while i < len(Q):
nh = Q[i]
i += 1
nw = nh % 1000
nh = nh // 1000
for dh in range(0 - min(nh, 2), 3):
if nh + dh >= H:
break
for dw in range(0 - min(nw, 2), 3):
if nw + dw >= W:
break
if dh == 0 and dw == 0:
continue
if dh * dw == 0 and (abs(dh) == 1 or abs(dw) == 1):
if ans[nh + dh][nw + dw] == -1:
if f[nh + dh][nw + dw]:
Q.append((nh + dh) * 1000 + nw + dw)
ans[nh + dh][nw + dw] = ans[nh][nw]
else:
ans[nh + dh][nw + dw] = -2
elif ans[nh + dh][nw + dw] > ans[nh][nw]:
Q.append((nh + dh) * 1000 + nw + dw)
nextQ -= {(nh + dh) * 1000 + nw + dw}
ans[nh + dh][nw + dw] = ans[nh][nw]
else:
if ans[nh + dh][nw + dw] == -1:
if f[nh + dh][nw + dw]:
nextQ.add((nh + dh) * 1000 + nw + dw)
ans[nh + dh][nw + dw] = ans[nh][nw] + 1
else:
ans[nh + dh][nw + dw] = -2
print((ans[gh - 1][gw - 1]))
| false | 2.12766 | [
"- visited = set()",
"- while len(Q):",
"- nh = Q.pop(0)",
"+ i = 0",
"+ while i < len(Q):",
"+ nh = Q[i]",
"+ i += 1",
"- visited.add((nh + dh) * 1000 + nw + dw)"
]
| false | 0.079405 | 0.033143 | 2.395844 | [
"s257173046",
"s827869749"
]
|
u745087332 | p03111 | python | s198578008 | s609061664 | 274 | 72 | 47,852 | 3,064 | Accepted | Accepted | 73.72 | # coding:utf-8
import sys
import itertools
INF = float('inf')
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
n, a, b, c = LI()
A = [a, b, c]
K = [II() for _ in range(n)]
ans = INF
for x in itertools.product([0, 1, 2, 3], repeat=n):
s = set(x)
if 0 not in s or 1 not in s or 2 not in s:
continue
T = [0] * 3
cnt = 0
for i, n in enumerate(x):
if n == 3:
continue
if T[n]:
cnt += 1
T[n] += K[i]
# print(T, cnt)
tmp = cnt * 10
for i in range(3):
tmp += abs(T[i] - A[i])
ans = min(ans, tmp)
print(ans)
| # coding:utf-8
import sys
INF = float('inf')
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
n, a, b, c = LI()
A = [a, b, c]
K = [II() for _ in range(n)]
def DFS(cur, x, y, z):
if cur == n:
return abs(x - a) + abs(y - b) + abs(z - c) - 30 if min(x, y, z) > 0 else INF
ret0 = DFS(cur + 1, x, y, z)
ret1 = DFS(cur + 1, x + K[cur], y, z) + 10
ret2 = DFS(cur + 1, x, y + K[cur], z) + 10
ret3 = DFS(cur + 1, x, y, z + K[cur]) + 10
return min(ret0, ret1, ret2, ret3)
print((DFS(0, 0, 0, 0)))
| 41 | 30 | 864 | 771 | # coding:utf-8
import sys
import itertools
INF = float("inf")
MOD = 10**9 + 7
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return eval(input())
n, a, b, c = LI()
A = [a, b, c]
K = [II() for _ in range(n)]
ans = INF
for x in itertools.product([0, 1, 2, 3], repeat=n):
s = set(x)
if 0 not in s or 1 not in s or 2 not in s:
continue
T = [0] * 3
cnt = 0
for i, n in enumerate(x):
if n == 3:
continue
if T[n]:
cnt += 1
T[n] += K[i]
# print(T, cnt)
tmp = cnt * 10
for i in range(3):
tmp += abs(T[i] - A[i])
ans = min(ans, tmp)
print(ans)
| # coding:utf-8
import sys
INF = float("inf")
MOD = 10**9 + 7
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return eval(input())
n, a, b, c = LI()
A = [a, b, c]
K = [II() for _ in range(n)]
def DFS(cur, x, y, z):
if cur == n:
return abs(x - a) + abs(y - b) + abs(z - c) - 30 if min(x, y, z) > 0 else INF
ret0 = DFS(cur + 1, x, y, z)
ret1 = DFS(cur + 1, x + K[cur], y, z) + 10
ret2 = DFS(cur + 1, x, y + K[cur], z) + 10
ret3 = DFS(cur + 1, x, y, z + K[cur]) + 10
return min(ret0, ret1, ret2, ret3)
print((DFS(0, 0, 0, 0)))
| false | 26.829268 | [
"-import itertools",
"-ans = INF",
"-for x in itertools.product([0, 1, 2, 3], repeat=n):",
"- s = set(x)",
"- if 0 not in s or 1 not in s or 2 not in s:",
"- continue",
"- T = [0] * 3",
"- cnt = 0",
"- for i, n in enumerate(x):",
"- if n == 3:",
"- continue",
"- if T[n]:",
"- cnt += 1",
"- T[n] += K[i]",
"- # print(T, cnt)",
"- tmp = cnt * 10",
"- for i in range(3):",
"- tmp += abs(T[i] - A[i])",
"- ans = min(ans, tmp)",
"-print(ans)",
"+",
"+",
"+def DFS(cur, x, y, z):",
"+ if cur == n:",
"+ return abs(x - a) + abs(y - b) + abs(z - c) - 30 if min(x, y, z) > 0 else INF",
"+ ret0 = DFS(cur + 1, x, y, z)",
"+ ret1 = DFS(cur + 1, x + K[cur], y, z) + 10",
"+ ret2 = DFS(cur + 1, x, y + K[cur], z) + 10",
"+ ret3 = DFS(cur + 1, x, y, z + K[cur]) + 10",
"+ return min(ret0, ret1, ret2, ret3)",
"+",
"+",
"+print((DFS(0, 0, 0, 0)))"
]
| false | 0.284699 | 0.095615 | 2.977562 | [
"s198578008",
"s609061664"
]
|
u888092736 | p03999 | python | s123308394 | s008494365 | 34 | 28 | 8,928 | 9,096 | Accepted | Accepted | 17.65 | from itertools import product
S = eval(input())
N = len(S)
ans = 0
for opes in product(("", "+"), repeat=N - 1):
eqn = []
for s, o in zip(S[:-1], opes):
eqn += s + o
ans += eval("".join(eqn) + S[-1])
print(ans)
| from itertools import product
S = eval(input())
N = len(S)
ans = 0
for opes in product(("", "+"), repeat=N - 1):
eqn = []
for s, o in zip(S[:-1], opes):
eqn += s + o
eqn = "".join(eqn) + S[-1]
ans += sum(map(int, eqn.split("+")))
print(ans)
| 12 | 13 | 238 | 273 | from itertools import product
S = eval(input())
N = len(S)
ans = 0
for opes in product(("", "+"), repeat=N - 1):
eqn = []
for s, o in zip(S[:-1], opes):
eqn += s + o
ans += eval("".join(eqn) + S[-1])
print(ans)
| from itertools import product
S = eval(input())
N = len(S)
ans = 0
for opes in product(("", "+"), repeat=N - 1):
eqn = []
for s, o in zip(S[:-1], opes):
eqn += s + o
eqn = "".join(eqn) + S[-1]
ans += sum(map(int, eqn.split("+")))
print(ans)
| false | 7.692308 | [
"- ans += eval(\"\".join(eqn) + S[-1])",
"+ eqn = \"\".join(eqn) + S[-1]",
"+ ans += sum(map(int, eqn.split(\"+\")))"
]
| false | 0.036402 | 0.036889 | 0.986786 | [
"s123308394",
"s008494365"
]
|
u347600233 | p02628 | python | s870463229 | s646951749 | 34 | 31 | 9,252 | 9,264 | Accepted | Accepted | 8.82 | n, k = list(map(int, input().split()))
p = [int(i) for i in input().split()]
print((sum(sorted(p)[:k]))) | n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
print((sum(sorted(p)[:k]))) | 3 | 3 | 98 | 96 | n, k = list(map(int, input().split()))
p = [int(i) for i in input().split()]
print((sum(sorted(p)[:k])))
| n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
print((sum(sorted(p)[:k])))
| false | 0 | [
"-p = [int(i) for i in input().split()]",
"+p = list(map(int, input().split()))"
]
| false | 0.036688 | 0.036596 | 1.002515 | [
"s870463229",
"s646951749"
]
|
u477977638 | p02972 | python | s969551554 | s204226522 | 228 | 131 | 13,092 | 92,976 | Accepted | Accepted | 42.54 | import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())
def main():
n=int(eval(input()))
A=list(map(int,input().split()))
ans=[0]*(n+1)
for i in range(n,0,-1):
ans[i]=(sum(ans[::i])%2) ^ A[i-1]
print((sum(ans)))
print((*[i for i,x in enumerate(ans) if x==1]))
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return input().rstrip().decode()
def II(): return int(eval(input()))
def FI(): return int(eval(input()))
def MI(): return list(map(int,input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
def main():
n=II()
A=[0]+LI()
B=[0]*(n+1)
for i in range(n,0,-1):
a=A[i]
if n//i>=2:
for j in range(2,n//i+1):
#print(i,j)
a^=B[i*j]
B[i]=a
ans=[]
for i,v in enumerate(B):
if v:
ans.append(i)
print((len(ans)))
print((*ans))
if __name__ == "__main__":
main()
| 46 | 51 | 1,121 | 818 | import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
# rstrip().decode('utf-8')
# INF=float("inf")
# MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
# import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
# from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())
def main():
n = int(eval(input()))
A = list(map(int, input().split()))
ans = [0] * (n + 1)
for i in range(n, 0, -1):
ans[i] = (sum(ans[::i]) % 2) ^ A[i - 1]
print((sum(ans)))
print((*[i for i, x in enumerate(ans) if x == 1]))
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
# from functools import lru_cache
def RD():
return input().rstrip().decode()
def II():
return int(eval(input()))
def FI():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MF():
return list(map(float, input().split()))
def LI():
return list(map(int, input().split()))
def LF():
return list(map(float, input().split()))
def TI():
return tuple(map(int, input().split()))
# rstrip().decode()
def main():
n = II()
A = [0] + LI()
B = [0] * (n + 1)
for i in range(n, 0, -1):
a = A[i]
if n // i >= 2:
for j in range(2, n // i + 1):
# print(i,j)
a ^= B[i * j]
B[i] = a
ans = []
for i, v in enumerate(B):
if v:
ans.append(i)
print((len(ans)))
print((*ans))
if __name__ == "__main__":
main()
| false | 9.803922 | [
"-read = sys.stdin.buffer.read",
"-inputs = sys.stdin.buffer.readlines",
"-# rstrip().decode('utf-8')",
"-# INF=float(\"inf\")",
"-# MOD=10**9+7",
"-# sys.setrecursionlimit(2147483647)",
"-# import math",
"-# import numpy as np",
"-# import operator",
"-# import bisect",
"-# from heapq import heapify,heappop,heappush",
"-# from math import gcd",
"-# from fractions import gcd",
"-# from collections import deque",
"-# from collections import defaultdict",
"-# from collections import Counter",
"-# from itertools import accumulate",
"-# from itertools import groupby",
"-# from itertools import permutations",
"-# from itertools import combinations",
"-# from scipy.sparse import csr_matrix",
"-# from scipy.sparse.csgraph import floyd_warshall",
"-# from scipy.sparse.csgraph import csgraph_from_dense",
"-# from scipy.sparse.csgraph import dijkstra",
"-# map(int,input().split())",
"+# sys.setrecursionlimit(10**9)",
"+# from functools import lru_cache",
"+def RD():",
"+ return input().rstrip().decode()",
"+",
"+",
"+def II():",
"+ return int(eval(input()))",
"+",
"+",
"+def FI():",
"+ return int(eval(input()))",
"+",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def MF():",
"+ return list(map(float, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LF():",
"+ return list(map(float, input().split()))",
"+",
"+",
"+def TI():",
"+ return tuple(map(int, input().split()))",
"+",
"+",
"+# rstrip().decode()",
"- n = int(eval(input()))",
"- A = list(map(int, input().split()))",
"- ans = [0] * (n + 1)",
"+ n = II()",
"+ A = [0] + LI()",
"+ B = [0] * (n + 1)",
"- ans[i] = (sum(ans[::i]) % 2) ^ A[i - 1]",
"- print((sum(ans)))",
"- print((*[i for i, x in enumerate(ans) if x == 1]))",
"+ a = A[i]",
"+ if n // i >= 2:",
"+ for j in range(2, n // i + 1):",
"+ # print(i,j)",
"+ a ^= B[i * j]",
"+ B[i] = a",
"+ ans = []",
"+ for i, v in enumerate(B):",
"+ if v:",
"+ ans.append(i)",
"+ print((len(ans)))",
"+ print((*ans))"
]
| false | 0.046018 | 0.007208 | 6.38394 | [
"s969551554",
"s204226522"
]
|
u816631826 | p02676 | python | s795238634 | s583938890 | 30 | 24 | 9,000 | 9,160 | Accepted | Accepted | 20 | num=int(eval(input())) #ask integer for limitation
s=eval(input()) #ask string
if len(s) > num: #check if the length s exceeded num
print((s[:num] + "...")) #print s with the limit "num"
else: #if the string not exceeded num
print(s) | #K is an input for the range of S
#input to get lowercase the letters from users
K = int(eval(input()))
S = eval(input())
if len (S) > K:
print((S[:K] + "..."))
else:
print(S) | 6 | 8 | 238 | 176 | num = int(eval(input())) # ask integer for limitation
s = eval(input()) # ask string
if len(s) > num: # check if the length s exceeded num
print((s[:num] + "...")) # print s with the limit "num"
else: # if the string not exceeded num
print(s)
| # K is an input for the range of S
# input to get lowercase the letters from users
K = int(eval(input()))
S = eval(input())
if len(S) > K:
print((S[:K] + "..."))
else:
print(S)
| false | 25 | [
"-num = int(eval(input())) # ask integer for limitation",
"-s = eval(input()) # ask string",
"-if len(s) > num: # check if the length s exceeded num",
"- print((s[:num] + \"...\")) # print s with the limit \"num\"",
"-else: # if the string not exceeded num",
"- print(s)",
"+# K is an input for the range of S",
"+# input to get lowercase the letters from users",
"+K = int(eval(input()))",
"+S = eval(input())",
"+if len(S) > K:",
"+ print((S[:K] + \"...\"))",
"+else:",
"+ print(S)"
]
| false | 0.047211 | 0.112923 | 0.418084 | [
"s795238634",
"s583938890"
]
|
u298297089 | p03252 | python | s774786045 | s224787741 | 106 | 87 | 7,984 | 8,112 | Accepted | Accepted | 17.92 | s = eval(input())
t = eval(input())
ans = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
res = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
cnt = 0
for a,b in zip(s,t):
ans[b].append(a)
res[a].append(b)
# elif ans[a] != a and ans[ans[a]] != ans[b]:
# print(a, b, '0', a, b, ans[a], ans[b], cnt)
# print('No')
# break
cnt += 1
aa = [0 for v in list(ans.values()) if len(set(v)) > 1]
bb = [0 for v in list(res.values()) if len(set(v)) > 1]
if len(aa) == 0 and len(bb) == 0:
print('Yes')
else:
print('No')
# print(ans)
| s = eval(input())
t = eval(input())
ans = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
res = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
for a,b in zip(s,t):
ans[b].append(a)
res[a].append(b)
aa = [0 for v in list(ans.values()) if len(set(v)) > 1]
bb = [0 for v in list(res.values()) if len(set(v)) > 1]
if len(aa) == 0 and len(bb) == 0:
print('Yes')
else:
print('No')
| 23 | 16 | 564 | 380 | s = eval(input())
t = eval(input())
ans = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
res = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
cnt = 0
for a, b in zip(s, t):
ans[b].append(a)
res[a].append(b)
# elif ans[a] != a and ans[ans[a]] != ans[b]:
# print(a, b, '0', a, b, ans[a], ans[b], cnt)
# print('No')
# break
cnt += 1
aa = [0 for v in list(ans.values()) if len(set(v)) > 1]
bb = [0 for v in list(res.values()) if len(set(v)) > 1]
if len(aa) == 0 and len(bb) == 0:
print("Yes")
else:
print("No")
# print(ans)
| s = eval(input())
t = eval(input())
ans = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
res = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
for a, b in zip(s, t):
ans[b].append(a)
res[a].append(b)
aa = [0 for v in list(ans.values()) if len(set(v)) > 1]
bb = [0 for v in list(res.values()) if len(set(v)) > 1]
if len(aa) == 0 and len(bb) == 0:
print("Yes")
else:
print("No")
| false | 30.434783 | [
"-cnt = 0",
"- # elif ans[a] != a and ans[ans[a]] != ans[b]:",
"- # print(a, b, '0', a, b, ans[a], ans[b], cnt)",
"- # print('No')",
"- # break",
"- cnt += 1",
"-# print(ans)"
]
| false | 0.047488 | 0.046625 | 1.0185 | [
"s774786045",
"s224787741"
]
|
u325227960 | p02757 | python | s908040306 | s502263766 | 246 | 226 | 53,472 | 53,472 | Accepted | Accepted | 8.13 | n, p = list(map(int,input().split()))
s = eval(input())
mod = p
l = 100
M = [1] # i!のmod
m = 1
for i in range(1, l):
m = (m * i) % mod
M.append(m)
def pow(x, y, mod): # x**y の mod を返す関数
ans = 1
while y > 0:
if y % 2 == 1:
ans = (ans * x) % mod
x = (x**2) % mod
y //= 2
return ans
def inv(x, mod): # x の mod での逆元を返す関数
return pow(x, mod-2, mod)
T = [1]
for i in range(n-1):
T.append((T[-1]*10) % p)
P = [0] * p
P[0] = 1
ans = 0
v = 0
S = [int(s[i]) for i in range(n-1,-1,-1)]
if p==2 or p==5:
for i in range(n):
ans += (int(s[i]) % p == 0) * (i+1)
else:
for i in range(n):
v = (v + T[i]*S[i]) % p
ans += P[v]
P[v] += 1
# print(P)
print(ans)
| n, p = list(map(int,input().split()))
s = eval(input())
mod = p
l = 100
M = [1] # i!のmod
m = 1
for i in range(1, l):
m = (m * i) % mod
M.append(m)
def pow(x, y, mod): # x**y の mod を返す関数
ans = 1
while y > 0:
if y % 2 == 1:
ans = (ans * x) % mod
x = (x**2) % mod
y //= 2
return ans
def inv(x, mod): # x の mod での逆元を返す関数
return pow(x, mod-2, mod)
T = [1]
for i in range(n-1):
T.append((T[-1]*10) % p)
P = [0] * p
P[0] = 1
ans = 0
v = 0
S = [int(s[i]) for i in range(n-1,-1,-1)]
import math
if p==2 or p==5:
for i in range(n):
ans += (int(s[i]) % p == 0) * (i+1)
elif math.log10(p) in [1,2,3,4]:
print("Wrong Answer")
else:
for i in range(n):
v = (v + T[i]*S[i]) % p
ans += P[v]
P[v] += 1
# print(P)
print(ans)
| 46 | 50 | 796 | 872 | n, p = list(map(int, input().split()))
s = eval(input())
mod = p
l = 100
M = [1] # i!のmod
m = 1
for i in range(1, l):
m = (m * i) % mod
M.append(m)
def pow(x, y, mod): # x**y の mod を返す関数
ans = 1
while y > 0:
if y % 2 == 1:
ans = (ans * x) % mod
x = (x**2) % mod
y //= 2
return ans
def inv(x, mod): # x の mod での逆元を返す関数
return pow(x, mod - 2, mod)
T = [1]
for i in range(n - 1):
T.append((T[-1] * 10) % p)
P = [0] * p
P[0] = 1
ans = 0
v = 0
S = [int(s[i]) for i in range(n - 1, -1, -1)]
if p == 2 or p == 5:
for i in range(n):
ans += (int(s[i]) % p == 0) * (i + 1)
else:
for i in range(n):
v = (v + T[i] * S[i]) % p
ans += P[v]
P[v] += 1
# print(P)
print(ans)
| n, p = list(map(int, input().split()))
s = eval(input())
mod = p
l = 100
M = [1] # i!のmod
m = 1
for i in range(1, l):
m = (m * i) % mod
M.append(m)
def pow(x, y, mod): # x**y の mod を返す関数
ans = 1
while y > 0:
if y % 2 == 1:
ans = (ans * x) % mod
x = (x**2) % mod
y //= 2
return ans
def inv(x, mod): # x の mod での逆元を返す関数
return pow(x, mod - 2, mod)
T = [1]
for i in range(n - 1):
T.append((T[-1] * 10) % p)
P = [0] * p
P[0] = 1
ans = 0
v = 0
S = [int(s[i]) for i in range(n - 1, -1, -1)]
import math
if p == 2 or p == 5:
for i in range(n):
ans += (int(s[i]) % p == 0) * (i + 1)
elif math.log10(p) in [1, 2, 3, 4]:
print("Wrong Answer")
else:
for i in range(n):
v = (v + T[i] * S[i]) % p
ans += P[v]
P[v] += 1
# print(P)
print(ans)
| false | 8 | [
"+import math",
"+",
"+elif math.log10(p) in [1, 2, 3, 4]:",
"+ print(\"Wrong Answer\")"
]
| false | 0.056335 | 0.037657 | 1.496009 | [
"s908040306",
"s502263766"
]
|
u556589653 | p02718 | python | s546511971 | s326168052 | 33 | 26 | 9,924 | 9,140 | Accepted | Accepted | 21.21 | from decimal import Decimal
n,m = list(map(int,input().split()))
A = list(map(int,input().split()))
border = float(sum(A)/(4*m))
border2 = str(border)
border3 = Decimal(border2)
ans = 0
judge = 0
for i in range(n):
if A[i] >= border3:
ans+=1
if ans >= m:
print("Yes")
else:
print("No")
| n,m = map(int,input().split())
A = list(map(int,input().split()))
judge = sum(A) / (4 * m)
ans = []
for i in range(n):
if A[i] < judge :
continue
else:
ans.append(A[i])
print("Yes") if len(ans) >= m else print("No")
| 15 | 10 | 304 | 236 | from decimal import Decimal
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
border = float(sum(A) / (4 * m))
border2 = str(border)
border3 = Decimal(border2)
ans = 0
judge = 0
for i in range(n):
if A[i] >= border3:
ans += 1
if ans >= m:
print("Yes")
else:
print("No")
| n, m = map(int, input().split())
A = list(map(int, input().split()))
judge = sum(A) / (4 * m)
ans = []
for i in range(n):
if A[i] < judge:
continue
else:
ans.append(A[i])
print("Yes") if len(ans) >= m else print("No")
| false | 33.333333 | [
"-from decimal import Decimal",
"-",
"-n, m = list(map(int, input().split()))",
"+n, m = map(int, input().split())",
"-border = float(sum(A) / (4 * m))",
"-border2 = str(border)",
"-border3 = Decimal(border2)",
"-ans = 0",
"-judge = 0",
"+judge = sum(A) / (4 * m)",
"+ans = []",
"- if A[i] >= border3:",
"- ans += 1",
"-if ans >= m:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+ if A[i] < judge:",
"+ continue",
"+ else:",
"+ ans.append(A[i])",
"+print(\"Yes\") if len(ans) >= m else print(\"No\")"
]
| false | 0.04799 | 0.044589 | 1.076268 | [
"s546511971",
"s326168052"
]
|
u729133443 | p02555 | python | s179934512 | s951234507 | 90 | 52 | 75,024 | 22,268 | Accepted | Accepted | 42.22 | a,b,c=1,0,0
exec('a,b,c=b,c,a+c;'*(int(eval(input()))-2))
print((c%(10**9+7))) | a,b,c=1,0,0
exec('a,b,c=b,c,a+c;'*int(eval(input())))
print((a%(10**9+7))) | 3 | 3 | 72 | 68 | a, b, c = 1, 0, 0
exec("a,b,c=b,c,a+c;" * (int(eval(input())) - 2))
print((c % (10**9 + 7)))
| a, b, c = 1, 0, 0
exec("a,b,c=b,c,a+c;" * int(eval(input())))
print((a % (10**9 + 7)))
| false | 0 | [
"-exec(\"a,b,c=b,c,a+c;\" * (int(eval(input())) - 2))",
"-print((c % (10**9 + 7)))",
"+exec(\"a,b,c=b,c,a+c;\" * int(eval(input())))",
"+print((a % (10**9 + 7)))"
]
| false | 0.04255 | 0.081498 | 0.5221 | [
"s179934512",
"s951234507"
]
|
u077291787 | p03495 | python | s611086669 | s471139711 | 229 | 98 | 33,696 | 41,500 | Accepted | Accepted | 57.21 | # ABC081C - Not so Diverse (ARC086C)
n, k = list(map(int, input().rstrip().split()))
lst = sorted(list(map(int, input().rstrip().split())))
dic = {}
for i in lst:
if i not in dic:
dic[i] = 1
else:
dic[i] += 1
cnt = sorted([i for i in list(dic.values())], reverse=True)
ans = 0
for i in range(len(cnt)):
if k > 0:
k -= 1
continue
ans += cnt[i]
print(ans) | # ARC086C - Not so Diverse (ABC081C)
from collections import Counter
def main():
n, k = list(map(int, input().rstrip().split()))
A = sorted(list(Counter(list(map(int, input().split()))).values()), reverse=True)
print((sum(A[k:])))
if __name__ == "__main__":
main() | 18 | 12 | 413 | 281 | # ABC081C - Not so Diverse (ARC086C)
n, k = list(map(int, input().rstrip().split()))
lst = sorted(list(map(int, input().rstrip().split())))
dic = {}
for i in lst:
if i not in dic:
dic[i] = 1
else:
dic[i] += 1
cnt = sorted([i for i in list(dic.values())], reverse=True)
ans = 0
for i in range(len(cnt)):
if k > 0:
k -= 1
continue
ans += cnt[i]
print(ans)
| # ARC086C - Not so Diverse (ABC081C)
from collections import Counter
def main():
n, k = list(map(int, input().rstrip().split()))
A = sorted(list(Counter(list(map(int, input().split()))).values()), reverse=True)
print((sum(A[k:])))
if __name__ == "__main__":
main()
| false | 33.333333 | [
"-# ABC081C - Not so Diverse (ARC086C)",
"-n, k = list(map(int, input().rstrip().split()))",
"-lst = sorted(list(map(int, input().rstrip().split())))",
"-dic = {}",
"-for i in lst:",
"- if i not in dic:",
"- dic[i] = 1",
"- else:",
"- dic[i] += 1",
"-cnt = sorted([i for i in list(dic.values())], reverse=True)",
"-ans = 0",
"-for i in range(len(cnt)):",
"- if k > 0:",
"- k -= 1",
"- continue",
"- ans += cnt[i]",
"-print(ans)",
"+# ARC086C - Not so Diverse (ABC081C)",
"+from collections import Counter",
"+",
"+",
"+def main():",
"+ n, k = list(map(int, input().rstrip().split()))",
"+ A = sorted(list(Counter(list(map(int, input().split()))).values()), reverse=True)",
"+ print((sum(A[k:])))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.036473 | 0.041247 | 0.884258 | [
"s611086669",
"s471139711"
]
|
u599925824 | p03075 | python | s246356017 | s264346912 | 150 | 17 | 12,500 | 3,064 | Accepted | Accepted | 88.67 | import numpy as np
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
e = int(eval(input()))
k = int(eval(input()))
if k>=b-a and k>=c-a and k>=d-a and k>=e-a and k>=c-b and k>=d-b and k>=e-b and k>=d-c and k>=e-c and k>=e-d:
print("Yay!")
else:
print(":(") | a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
e = int(eval(input()))
k = int(eval(input()))
if k>=b-a and k>=c-a and k>=d-a and k>=e-a and k>=c-b and k>=d-b and k>=e-b and k>=d-c and k>=e-c and k>=e-d:
print("Yay!")
else:
print(":(") | 11 | 10 | 276 | 256 | import numpy as np
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
e = int(eval(input()))
k = int(eval(input()))
if (
k >= b - a
and k >= c - a
and k >= d - a
and k >= e - a
and k >= c - b
and k >= d - b
and k >= e - b
and k >= d - c
and k >= e - c
and k >= e - d
):
print("Yay!")
else:
print(":(")
| a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
e = int(eval(input()))
k = int(eval(input()))
if (
k >= b - a
and k >= c - a
and k >= d - a
and k >= e - a
and k >= c - b
and k >= d - b
and k >= e - b
and k >= d - c
and k >= e - c
and k >= e - d
):
print("Yay!")
else:
print(":(")
| false | 9.090909 | [
"-import numpy as np",
"-"
]
| false | 0.107757 | 0.036248 | 2.972808 | [
"s246356017",
"s264346912"
]
|
u312025627 | p02555 | python | s000684126 | s734399202 | 85 | 78 | 63,348 | 64,324 | Accepted | Accepted | 8.24 | MOD = 10**9 + 7
def main():
S = int(eval(input()))
if S < 3:
print((0))
return
dp = [0] * (S + 1)
dp[3] = 1
for i in range(4, S + 1):
dp[i] = dp[i - 1] + dp[i - 3]
dp[i] %= MOD
print((dp[S]))
# print(*dp)
if __name__ == '__main__':
main()
| MOD = 10**9 + 7
m = 5000
fac = [0] * m
finv = [0] * m
inv = [0] * m
def COMBinitialize(m):
fac[0] = 1
finv[0] = 1
if m > 1:
fac[1] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, m):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def COMB(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
COMBinitialize(m)
def main():
S = int(eval(input()))
if S < 3:
print((0))
return
ans = 0
for i in range(1, S // 3 + 1):
r = S - i * 3
ans += COMB(r + i - 1, i - 1)
ans %= MOD
print(ans)
if __name__ == '__main__':
main()
| 19 | 48 | 315 | 852 | MOD = 10**9 + 7
def main():
S = int(eval(input()))
if S < 3:
print((0))
return
dp = [0] * (S + 1)
dp[3] = 1
for i in range(4, S + 1):
dp[i] = dp[i - 1] + dp[i - 3]
dp[i] %= MOD
print((dp[S]))
# print(*dp)
if __name__ == "__main__":
main()
| MOD = 10**9 + 7
m = 5000
fac = [0] * m
finv = [0] * m
inv = [0] * m
def COMBinitialize(m):
fac[0] = 1
finv[0] = 1
if m > 1:
fac[1] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, m):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def COMB(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
COMBinitialize(m)
def main():
S = int(eval(input()))
if S < 3:
print((0))
return
ans = 0
for i in range(1, S // 3 + 1):
r = S - i * 3
ans += COMB(r + i - 1, i - 1)
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| false | 60.416667 | [
"+m = 5000",
"+fac = [0] * m",
"+finv = [0] * m",
"+inv = [0] * m",
"+",
"+",
"+def COMBinitialize(m):",
"+ fac[0] = 1",
"+ finv[0] = 1",
"+ if m > 1:",
"+ fac[1] = 1",
"+ finv[1] = 1",
"+ inv[1] = 1",
"+ for i in range(2, m):",
"+ fac[i] = fac[i - 1] * i % MOD",
"+ inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD",
"+ finv[i] = finv[i - 1] * inv[i] % MOD",
"+",
"+",
"+def COMB(n, k):",
"+ if n < k:",
"+ return 0",
"+ if n < 0 or k < 0:",
"+ return 0",
"+ return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD",
"+",
"+",
"+COMBinitialize(m)",
"- dp = [0] * (S + 1)",
"- dp[3] = 1",
"- for i in range(4, S + 1):",
"- dp[i] = dp[i - 1] + dp[i - 3]",
"- dp[i] %= MOD",
"- print((dp[S]))",
"- # print(*dp)",
"+ ans = 0",
"+ for i in range(1, S // 3 + 1):",
"+ r = S - i * 3",
"+ ans += COMB(r + i - 1, i - 1)",
"+ ans %= MOD",
"+ print(ans)"
]
| false | 0.051353 | 0.056218 | 0.913464 | [
"s000684126",
"s734399202"
]
|
u460386402 | p02582 | python | s965847107 | s929970084 | 31 | 27 | 9,040 | 9,084 | Accepted | Accepted | 12.9 | s=eval(input())
count=0
if s.count('R')==1:
print((1))
elif s.count('R')==3:
print((3))
elif s.count('R')==2:
if s[1]=="R":
print((2))
else:
print((1))
else:
print((0)) | s=eval(input())
ans=0
for i in range(1,4):
r="R"*i
if r in s:
ans=i
print(ans) | 13 | 8 | 182 | 88 | s = eval(input())
count = 0
if s.count("R") == 1:
print((1))
elif s.count("R") == 3:
print((3))
elif s.count("R") == 2:
if s[1] == "R":
print((2))
else:
print((1))
else:
print((0))
| s = eval(input())
ans = 0
for i in range(1, 4):
r = "R" * i
if r in s:
ans = i
print(ans)
| false | 38.461538 | [
"-count = 0",
"-if s.count(\"R\") == 1:",
"- print((1))",
"-elif s.count(\"R\") == 3:",
"- print((3))",
"-elif s.count(\"R\") == 2:",
"- if s[1] == \"R\":",
"- print((2))",
"- else:",
"- print((1))",
"-else:",
"- print((0))",
"+ans = 0",
"+for i in range(1, 4):",
"+ r = \"R\" * i",
"+ if r in s:",
"+ ans = i",
"+print(ans)"
]
| false | 0.03854 | 0.039386 | 0.978504 | [
"s965847107",
"s929970084"
]
|
u094191970 | p03818 | python | s817018364 | s214536064 | 65 | 45 | 18,656 | 14,396 | Accepted | Accepted | 30.77 | from collections import Counter
n=int(eval(input()))
a=list(map(int,input().split()))
c=Counter(a)
cnt=0
ans=0
for v in list(c.values()):
ans+=1
if v%2==0:
cnt+=1
if cnt%2==1:
ans-=1
print(ans) | n=int(eval(input()))
a=set(list(map(int,input().split())))
al=len(a)
print((al if al%2==1 else al-1)) | 19 | 4 | 215 | 96 | from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)
cnt = 0
ans = 0
for v in list(c.values()):
ans += 1
if v % 2 == 0:
cnt += 1
if cnt % 2 == 1:
ans -= 1
print(ans)
| n = int(eval(input()))
a = set(list(map(int, input().split())))
al = len(a)
print((al if al % 2 == 1 else al - 1))
| false | 78.947368 | [
"-from collections import Counter",
"-",
"-a = list(map(int, input().split()))",
"-c = Counter(a)",
"-cnt = 0",
"-ans = 0",
"-for v in list(c.values()):",
"- ans += 1",
"- if v % 2 == 0:",
"- cnt += 1",
"-if cnt % 2 == 1:",
"- ans -= 1",
"-print(ans)",
"+a = set(list(map(int, input().split())))",
"+al = len(a)",
"+print((al if al % 2 == 1 else al - 1))"
]
| false | 0.037106 | 0.037626 | 0.986166 | [
"s817018364",
"s214536064"
]
|
u727148417 | p02702 | python | s912552042 | s832620052 | 361 | 198 | 12,232 | 81,464 | Accepted | Accepted | 45.15 | import sys
from collections import deque
def input():
return sys.stdin.readline()[:-1]
S = deque(list(map(int, list(eval(input())))))
num = 0
dict = {}
dict[0] = 1
ans = 0
for i in range(len(S)):
num += S.pop() * pow(10,i,2019)
cand = num % 2019
if cand in list(dict.keys()):
dict[cand] += 1
else:
dict[cand] = 1
for key in list(dict.keys()):
ans += dict[key] * (dict[key] - 1) // 2
print(ans)
| #import sys
from collections import deque
#def input():
# return sys.stdin.readline()[:-1]
S = deque(list(map(int, list(eval(input())))))
num = 0
dict = {}
dict[0] = 1
ans = 0
for i in range(len(S)):
num += S.pop() * pow(10,i,2019)
cand = num % 2019
if cand in list(dict.keys()):
dict[cand] += 1
else:
dict[cand] = 1
for key in list(dict.keys()):
ans += dict[key] * (dict[key] - 1) // 2
print(ans)
| 22 | 22 | 434 | 437 | import sys
from collections import deque
def input():
return sys.stdin.readline()[:-1]
S = deque(list(map(int, list(eval(input())))))
num = 0
dict = {}
dict[0] = 1
ans = 0
for i in range(len(S)):
num += S.pop() * pow(10, i, 2019)
cand = num % 2019
if cand in list(dict.keys()):
dict[cand] += 1
else:
dict[cand] = 1
for key in list(dict.keys()):
ans += dict[key] * (dict[key] - 1) // 2
print(ans)
| # import sys
from collections import deque
# def input():
# return sys.stdin.readline()[:-1]
S = deque(list(map(int, list(eval(input())))))
num = 0
dict = {}
dict[0] = 1
ans = 0
for i in range(len(S)):
num += S.pop() * pow(10, i, 2019)
cand = num % 2019
if cand in list(dict.keys()):
dict[cand] += 1
else:
dict[cand] = 1
for key in list(dict.keys()):
ans += dict[key] * (dict[key] - 1) // 2
print(ans)
| false | 0 | [
"-import sys",
"+# import sys",
"-",
"-def input():",
"- return sys.stdin.readline()[:-1]",
"-",
"-",
"+# def input():",
"+# return sys.stdin.readline()[:-1]"
]
| false | 0.033305 | 0.03568 | 0.933448 | [
"s912552042",
"s832620052"
]
|
u945181840 | p02780 | python | s543691603 | s471314734 | 153 | 119 | 25,420 | 25,420 | Accepted | Accepted | 22.22 | import sys
from itertools import accumulate
read = sys.stdin.read
N, K, *p = list(map(int, read().split()))
p = [(1 + i) * i // 2 / i for i in p]
p = [0] + p
P = list(accumulate(p))
answer = 0
for i in range(K, N + 1):
s = P[i] - P[i - K]
if s > answer:
answer = s
print(answer)
| import sys
from itertools import accumulate
read = sys.stdin.read
N, K, *p = list(map(int, read().split()))
p = [(1 + i) / 2 for i in p]
p = [0] + p
P = list(accumulate(p))
answer = max(P[i] - P[i - K] for i in range(K, N + 1))
print(answer)
| 18 | 13 | 311 | 252 | import sys
from itertools import accumulate
read = sys.stdin.read
N, K, *p = list(map(int, read().split()))
p = [(1 + i) * i // 2 / i for i in p]
p = [0] + p
P = list(accumulate(p))
answer = 0
for i in range(K, N + 1):
s = P[i] - P[i - K]
if s > answer:
answer = s
print(answer)
| import sys
from itertools import accumulate
read = sys.stdin.read
N, K, *p = list(map(int, read().split()))
p = [(1 + i) / 2 for i in p]
p = [0] + p
P = list(accumulate(p))
answer = max(P[i] - P[i - K] for i in range(K, N + 1))
print(answer)
| false | 27.777778 | [
"-p = [(1 + i) * i // 2 / i for i in p]",
"+p = [(1 + i) / 2 for i in p]",
"-answer = 0",
"-for i in range(K, N + 1):",
"- s = P[i] - P[i - K]",
"- if s > answer:",
"- answer = s",
"+answer = max(P[i] - P[i - K] for i in range(K, N + 1))"
]
| false | 0.042645 | 0.048235 | 0.884106 | [
"s543691603",
"s471314734"
]
|
u974918235 | p02613 | python | s121281216 | s902487209 | 151 | 139 | 9,064 | 16,280 | Accepted | Accepted | 7.95 | N = int(eval(input()))
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(N):
a = eval(input())
if a == "AC":
ac += 1
if a == "WA":
wa += 1
if a == "TLE":
tle += 1
if a =="RE":
re += 1
print(f"AC x {ac}")
print(f"WA x {wa}")
print(f"TLE x {tle}")
print(f"RE x {re}") | N = int(eval(input()))
lst = [eval(input()) for _ in range(N)]
for i in ["AC", "WA", "TLE", "RE"]:
print(f"{i} x {lst.count(i)}") | 19 | 4 | 291 | 122 | N = int(eval(input()))
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(N):
a = eval(input())
if a == "AC":
ac += 1
if a == "WA":
wa += 1
if a == "TLE":
tle += 1
if a == "RE":
re += 1
print(f"AC x {ac}")
print(f"WA x {wa}")
print(f"TLE x {tle}")
print(f"RE x {re}")
| N = int(eval(input()))
lst = [eval(input()) for _ in range(N)]
for i in ["AC", "WA", "TLE", "RE"]:
print(f"{i} x {lst.count(i)}")
| false | 78.947368 | [
"-ac = 0",
"-wa = 0",
"-tle = 0",
"-re = 0",
"-for _ in range(N):",
"- a = eval(input())",
"- if a == \"AC\":",
"- ac += 1",
"- if a == \"WA\":",
"- wa += 1",
"- if a == \"TLE\":",
"- tle += 1",
"- if a == \"RE\":",
"- re += 1",
"-print(f\"AC x {ac}\")",
"-print(f\"WA x {wa}\")",
"-print(f\"TLE x {tle}\")",
"-print(f\"RE x {re}\")",
"+lst = [eval(input()) for _ in range(N)]",
"+for i in [\"AC\", \"WA\", \"TLE\", \"RE\"]:",
"+ print(f\"{i} x {lst.count(i)}\")"
]
| false | 0.082942 | 0.078895 | 1.051299 | [
"s121281216",
"s902487209"
]
|
u258492760 | p03085 | python | s170761363 | s412217156 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | b = eval(input())
if b == 'A':
print('T')
if b == 'T':
print('A')
if b == 'C':
print('G')
if b == 'G':
print('C') | b = eval(input())
B = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
print((B[b])) | 10 | 3 | 133 | 70 | b = eval(input())
if b == "A":
print("T")
if b == "T":
print("A")
if b == "C":
print("G")
if b == "G":
print("C")
| b = eval(input())
B = {"A": "T", "T": "A", "C": "G", "G": "C"}
print((B[b]))
| false | 70 | [
"-if b == \"A\":",
"- print(\"T\")",
"-if b == \"T\":",
"- print(\"A\")",
"-if b == \"C\":",
"- print(\"G\")",
"-if b == \"G\":",
"- print(\"C\")",
"+B = {\"A\": \"T\", \"T\": \"A\", \"C\": \"G\", \"G\": \"C\"}",
"+print((B[b]))"
]
| false | 0.064928 | 0.04857 | 1.336796 | [
"s170761363",
"s412217156"
]
|
u353895424 | p03379 | python | s751610098 | s742625516 | 415 | 325 | 93,780 | 25,228 | Accepted | Accepted | 21.69 | n = int(eval(input()))
x = list(map(int, input().split()))
sx = sorted(x)
m = (n+1)//2
med1 = sx[m - 1]
med2 = sx[m]
for _x in x:
if _x <= med1:
print(med2)
else:
print(med1) | n = int(eval(input()))
x = list(map(int, input().split()))
x_ = sorted(x)
c = x_[n//2 - 1]
c_ = x_[n//2]
for i in range(n):
if x[i] <= c:
print(c_)
else:
print(c) | 13 | 11 | 206 | 191 | n = int(eval(input()))
x = list(map(int, input().split()))
sx = sorted(x)
m = (n + 1) // 2
med1 = sx[m - 1]
med2 = sx[m]
for _x in x:
if _x <= med1:
print(med2)
else:
print(med1)
| n = int(eval(input()))
x = list(map(int, input().split()))
x_ = sorted(x)
c = x_[n // 2 - 1]
c_ = x_[n // 2]
for i in range(n):
if x[i] <= c:
print(c_)
else:
print(c)
| false | 15.384615 | [
"-sx = sorted(x)",
"-m = (n + 1) // 2",
"-med1 = sx[m - 1]",
"-med2 = sx[m]",
"-for _x in x:",
"- if _x <= med1:",
"- print(med2)",
"+x_ = sorted(x)",
"+c = x_[n // 2 - 1]",
"+c_ = x_[n // 2]",
"+for i in range(n):",
"+ if x[i] <= c:",
"+ print(c_)",
"- print(med1)",
"+ print(c)"
]
| false | 0.006336 | 0.039109 | 0.162007 | [
"s751610098",
"s742625516"
]
|
u185896732 | p03449 | python | s573251122 | s335776222 | 21 | 18 | 3,316 | 3,060 | Accepted | Accepted | 14.29 | import sys
from collections import deque
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
n=int(input().rstrip())
a=[list(map(int,input().split())) for _ in range(2)]
ans=0
print((max([sum(a[0][:i+1])+sum(a[1][i:]) for i in range(n)]))) | import sys
input=sys.stdin.readline
n=int(input().rstrip())
a=[list(map(int,input().split())) for _ in range(2)]
ans=0
for i in range(n):
now=sum(a[0][:i+1])+sum(a[1][i:])
ans=max(ans,now)
print(ans) | 9 | 11 | 248 | 219 | import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
n = int(input().rstrip())
a = [list(map(int, input().split())) for _ in range(2)]
ans = 0
print((max([sum(a[0][: i + 1]) + sum(a[1][i:]) for i in range(n)])))
| import sys
input = sys.stdin.readline
n = int(input().rstrip())
a = [list(map(int, input().split())) for _ in range(2)]
ans = 0
for i in range(n):
now = sum(a[0][: i + 1]) + sum(a[1][i:])
ans = max(ans, now)
print(ans)
| false | 18.181818 | [
"-from collections import deque",
"-sys.setrecursionlimit(10**6)",
"-print((max([sum(a[0][: i + 1]) + sum(a[1][i:]) for i in range(n)])))",
"+for i in range(n):",
"+ now = sum(a[0][: i + 1]) + sum(a[1][i:])",
"+ ans = max(ans, now)",
"+print(ans)"
]
| false | 0.038626 | 0.040113 | 0.962923 | [
"s573251122",
"s335776222"
]
|
u427344224 | p03162 | python | s637204499 | s233518949 | 1,151 | 594 | 45,680 | 40,236 | Accepted | Accepted | 48.39 | N = int(eval(input()))
a_list = [[0 for _ in range(3)] for _ in range(N)]
for i in range(N):
a, b, c = list(map(int, input().split()))
a_list[i][0] = a
a_list[i][1] = b
a_list[i][2] = c
dp = [[0 for _ in range(3)] for _ in range(N + 1)]
for i in range(1, N + 1):
for j in range(3):
for k in range(3):
if i == 1:
dp[i][j] = a_list[i - 1][k]
if j == k:
continue
else:
dp[i][j] = max(dp[i][j], dp[i - 1][k] + a_list[i - 1][j])
print((max(dp[N])))
| N = int(eval(input()))
abc = []
for i in range(N):
abc.append(tuple(map(int, input().split())))
dp = [[0] * 3 for _ in range(N + 1)]
for i in range(N):
a, b, c = abc[i]
dp[i + 1][0] += max(dp[i][1] + a, dp[i][2] + a)
dp[i + 1][1] += max(dp[i][0] + b, dp[i][2] + b)
dp[i + 1][2] += max(dp[i][0] + c, dp[i][1] + c)
print((max(dp[N])))
| 21 | 15 | 565 | 363 | N = int(eval(input()))
a_list = [[0 for _ in range(3)] for _ in range(N)]
for i in range(N):
a, b, c = list(map(int, input().split()))
a_list[i][0] = a
a_list[i][1] = b
a_list[i][2] = c
dp = [[0 for _ in range(3)] for _ in range(N + 1)]
for i in range(1, N + 1):
for j in range(3):
for k in range(3):
if i == 1:
dp[i][j] = a_list[i - 1][k]
if j == k:
continue
else:
dp[i][j] = max(dp[i][j], dp[i - 1][k] + a_list[i - 1][j])
print((max(dp[N])))
| N = int(eval(input()))
abc = []
for i in range(N):
abc.append(tuple(map(int, input().split())))
dp = [[0] * 3 for _ in range(N + 1)]
for i in range(N):
a, b, c = abc[i]
dp[i + 1][0] += max(dp[i][1] + a, dp[i][2] + a)
dp[i + 1][1] += max(dp[i][0] + b, dp[i][2] + b)
dp[i + 1][2] += max(dp[i][0] + c, dp[i][1] + c)
print((max(dp[N])))
| false | 28.571429 | [
"-a_list = [[0 for _ in range(3)] for _ in range(N)]",
"+abc = []",
"- a, b, c = list(map(int, input().split()))",
"- a_list[i][0] = a",
"- a_list[i][1] = b",
"- a_list[i][2] = c",
"-dp = [[0 for _ in range(3)] for _ in range(N + 1)]",
"-for i in range(1, N + 1):",
"- for j in range(3):",
"- for k in range(3):",
"- if i == 1:",
"- dp[i][j] = a_list[i - 1][k]",
"- if j == k:",
"- continue",
"- else:",
"- dp[i][j] = max(dp[i][j], dp[i - 1][k] + a_list[i - 1][j])",
"+ abc.append(tuple(map(int, input().split())))",
"+dp = [[0] * 3 for _ in range(N + 1)]",
"+for i in range(N):",
"+ a, b, c = abc[i]",
"+ dp[i + 1][0] += max(dp[i][1] + a, dp[i][2] + a)",
"+ dp[i + 1][1] += max(dp[i][0] + b, dp[i][2] + b)",
"+ dp[i + 1][2] += max(dp[i][0] + c, dp[i][1] + c)"
]
| false | 0.05356 | 0.036989 | 1.447989 | [
"s637204499",
"s233518949"
]
|
u334712262 | p02763 | python | s546248683 | s783039048 | 1,372 | 658 | 55,720 | 55,656 | Accepted | Accepted | 52.04 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub, or_
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
class SegmentTree():
# to par: (n-1) // 2
# to chr: 2n+1, 2n+2
def __init__(self, array, operator, identity_element):
""" operator and identity_element has to be a monoid.
"""
self.__N = 2**int(math.ceil(math.log(len(array), 2)))
self.__table = [identity_element] * (self.__N * 2 - 1)
self.__op = operator
self.__ie = identity_element
for i, v in enumerate(array):
self.__table[i+self.__N - 1] = v
for i in range(self.__N - 2, 0, -1):
pi = i
li = 2*pi + 1
ri = 2*pi + 2
v = self.__op(self.__table[li], self.__table[ri])
self.__table[pi] = v
def update(self, idx, x):
i = self.__N - 1 + idx # target leaf
t = self.__table
o = self.__op
t[i] = x
while i != 0:
i = (i - 1) // 2
t[i] = o(t[2*i + 1], t[2*i + 2])
def query(self, a, b):
stack = [(0, 0, self.__N)]
t = self.__table
o = self.__op
ans = self.__ie
while stack:
k, l, r = stack.pop()
cnd = t[k]
if a <= l and r <= b:
ans = o(ans, cnd)
else:
if (l + r) // 2 > a and b > l:
stack.append((2 * k + 1, l, (l + r) // 2))
if r > a and b > (l + r) // 2:
stack.append((2 * k + 2, (l + r) // 2, r))
return ans
def print(self):
print(self.__table)
@mt
def slv(N, S, Q):
st = SegmentTree([1 << (ord(c) - ord('a')) for c in S], or_, 0)
for q in Q:
if q[0] == '1':
i = int(q[1]) - 1
c = q[2]
st.update(i, 1 << (ord(c) - ord('a')))
if q[0] == '2':
i = int(q[1]) - 1
j = int(q[2]) - 1
ans = 0
v = st.query(i, j+1)
for k in range(26):
if (1 << k) & v:
ans += 1
print(ans)
# return ans
def main():
N = read_int()
S = read_str()
Q = [read_str_n() for _ in range(read_int())]
(slv(N, S, Q))
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub, or_
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
class SegmentTree:
def __init__(self, array, operator, identity_element):
_len = len(array)
self.__op = operator
self.__size = 1 << (_len - 1).bit_length()
self.__tree = [identity_element] * self.__size + \
array + [identity_element] * (self.__size - _len)
self.__ie = identity_element
for i in range(self.__size - 1, 0, -1):
self.__tree[i] = operator(
self.__tree[i * 2], self.__tree[i * 2 + 1])
def update(self, i, v):
i += self.__size
self.__tree[i] = v
while i:
i //= 2
self.__tree[i] = self.__op(
self.__tree[i * 2], self.__tree[i * 2 + 1])
def query(self, l, r):
l += self.__size
r += self.__size
ret = self.__ie
while l < r:
if l & 1:
ret = self.__op(ret, self.__tree[l])
l += 1
if r & 1:
r -= 1
ret = self.__op(ret, self.__tree[r])
l //= 2
r //= 2
return ret
@mt
def slv(N, S, Q):
st = SegmentTree([1 << (ord(c) - ord('a')) for c in S], or_, 0)
for q in Q:
if q[0] == '1':
i = int(q[1]) - 1
c = q[2]
st.update(i, 1 << (ord(c) - ord('a')))
if q[0] == '2':
i = int(q[1]) - 1
j = int(q[2]) - 1
ans = 0
v = st.query(i, j+1)
for k in range(26):
if (1 << k) & v:
ans += 1
print(ans)
# return ans
def main():
N = read_int()
S = read_str()
Q = [read_str_n() for _ in range(read_int())]
(slv(N, S, Q))
if __name__ == '__main__':
main()
| 143 | 125 | 3,367 | 2,916 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub, or_
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
class SegmentTree:
# to par: (n-1) // 2
# to chr: 2n+1, 2n+2
def __init__(self, array, operator, identity_element):
"""operator and identity_element has to be a monoid."""
self.__N = 2 ** int(math.ceil(math.log(len(array), 2)))
self.__table = [identity_element] * (self.__N * 2 - 1)
self.__op = operator
self.__ie = identity_element
for i, v in enumerate(array):
self.__table[i + self.__N - 1] = v
for i in range(self.__N - 2, 0, -1):
pi = i
li = 2 * pi + 1
ri = 2 * pi + 2
v = self.__op(self.__table[li], self.__table[ri])
self.__table[pi] = v
def update(self, idx, x):
i = self.__N - 1 + idx # target leaf
t = self.__table
o = self.__op
t[i] = x
while i != 0:
i = (i - 1) // 2
t[i] = o(t[2 * i + 1], t[2 * i + 2])
def query(self, a, b):
stack = [(0, 0, self.__N)]
t = self.__table
o = self.__op
ans = self.__ie
while stack:
k, l, r = stack.pop()
cnd = t[k]
if a <= l and r <= b:
ans = o(ans, cnd)
else:
if (l + r) // 2 > a and b > l:
stack.append((2 * k + 1, l, (l + r) // 2))
if r > a and b > (l + r) // 2:
stack.append((2 * k + 2, (l + r) // 2, r))
return ans
def print(self):
print(self.__table)
@mt
def slv(N, S, Q):
st = SegmentTree([1 << (ord(c) - ord("a")) for c in S], or_, 0)
for q in Q:
if q[0] == "1":
i = int(q[1]) - 1
c = q[2]
st.update(i, 1 << (ord(c) - ord("a")))
if q[0] == "2":
i = int(q[1]) - 1
j = int(q[2]) - 1
ans = 0
v = st.query(i, j + 1)
for k in range(26):
if (1 << k) & v:
ans += 1
print(ans)
# return ans
def main():
N = read_int()
S = read_str()
Q = [read_str_n() for _ in range(read_int())]
(slv(N, S, Q))
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub, or_
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
class SegmentTree:
def __init__(self, array, operator, identity_element):
_len = len(array)
self.__op = operator
self.__size = 1 << (_len - 1).bit_length()
self.__tree = (
[identity_element] * self.__size
+ array
+ [identity_element] * (self.__size - _len)
)
self.__ie = identity_element
for i in range(self.__size - 1, 0, -1):
self.__tree[i] = operator(self.__tree[i * 2], self.__tree[i * 2 + 1])
def update(self, i, v):
i += self.__size
self.__tree[i] = v
while i:
i //= 2
self.__tree[i] = self.__op(self.__tree[i * 2], self.__tree[i * 2 + 1])
def query(self, l, r):
l += self.__size
r += self.__size
ret = self.__ie
while l < r:
if l & 1:
ret = self.__op(ret, self.__tree[l])
l += 1
if r & 1:
r -= 1
ret = self.__op(ret, self.__tree[r])
l //= 2
r //= 2
return ret
@mt
def slv(N, S, Q):
st = SegmentTree([1 << (ord(c) - ord("a")) for c in S], or_, 0)
for q in Q:
if q[0] == "1":
i = int(q[1]) - 1
c = q[2]
st.update(i, 1 << (ord(c) - ord("a")))
if q[0] == "2":
i = int(q[1]) - 1
j = int(q[2]) - 1
ans = 0
v = st.query(i, j + 1)
for k in range(26):
if (1 << k) & v:
ans += 1
print(ans)
# return ans
def main():
N = read_int()
S = read_str()
Q = [read_str_n() for _ in range(read_int())]
(slv(N, S, Q))
if __name__ == "__main__":
main()
| false | 12.587413 | [
"- # to par: (n-1) // 2",
"- # to chr: 2n+1, 2n+2",
"- \"\"\"operator and identity_element has to be a monoid.\"\"\"",
"- self.__N = 2 ** int(math.ceil(math.log(len(array), 2)))",
"- self.__table = [identity_element] * (self.__N * 2 - 1)",
"+ _len = len(array)",
"+ self.__size = 1 << (_len - 1).bit_length()",
"+ self.__tree = (",
"+ [identity_element] * self.__size",
"+ + array",
"+ + [identity_element] * (self.__size - _len)",
"+ )",
"- for i, v in enumerate(array):",
"- self.__table[i + self.__N - 1] = v",
"- for i in range(self.__N - 2, 0, -1):",
"- pi = i",
"- li = 2 * pi + 1",
"- ri = 2 * pi + 2",
"- v = self.__op(self.__table[li], self.__table[ri])",
"- self.__table[pi] = v",
"+ for i in range(self.__size - 1, 0, -1):",
"+ self.__tree[i] = operator(self.__tree[i * 2], self.__tree[i * 2 + 1])",
"- def update(self, idx, x):",
"- i = self.__N - 1 + idx # target leaf",
"- t = self.__table",
"- o = self.__op",
"- t[i] = x",
"- while i != 0:",
"- i = (i - 1) // 2",
"- t[i] = o(t[2 * i + 1], t[2 * i + 2])",
"+ def update(self, i, v):",
"+ i += self.__size",
"+ self.__tree[i] = v",
"+ while i:",
"+ i //= 2",
"+ self.__tree[i] = self.__op(self.__tree[i * 2], self.__tree[i * 2 + 1])",
"- def query(self, a, b):",
"- stack = [(0, 0, self.__N)]",
"- t = self.__table",
"- o = self.__op",
"- ans = self.__ie",
"- while stack:",
"- k, l, r = stack.pop()",
"- cnd = t[k]",
"- if a <= l and r <= b:",
"- ans = o(ans, cnd)",
"- else:",
"- if (l + r) // 2 > a and b > l:",
"- stack.append((2 * k + 1, l, (l + r) // 2))",
"- if r > a and b > (l + r) // 2:",
"- stack.append((2 * k + 2, (l + r) // 2, r))",
"- return ans",
"-",
"- def print(self):",
"- print(self.__table)",
"+ def query(self, l, r):",
"+ l += self.__size",
"+ r += self.__size",
"+ ret = self.__ie",
"+ while l < r:",
"+ if l & 1:",
"+ ret = self.__op(ret, self.__tree[l])",
"+ l += 1",
"+ if r & 1:",
"+ r -= 1",
"+ ret = self.__op(ret, self.__tree[r])",
"+ l //= 2",
"+ r //= 2",
"+ return ret"
]
| false | 0.04678 | 0.064321 | 0.727287 | [
"s546248683",
"s783039048"
]
|
u226108478 | p03449 | python | s942211143 | s786733245 | 157 | 17 | 12,472 | 3,060 | Accepted | Accepted | 89.17 | # -*- coding: utf-8 -*-
# AtCoder Beginner Contest
# Problem C
import numpy as np
if __name__ == '__main__':
# Input
N = int(eval(input()))
route = np.zeros([2, N], dtype=int)
# HACK: More smarter.
for i in range(2):
line = [int(i) for i in input().split(" ")]
for j in range(N):
route[i][j] = line[j]
candy_count_max = 0
# See: https://img.atcoder.jp/arc090/editorial.pdf
# p.7
# HACK: Not beautiful.
for i in range(N):
candy_count = 0
for j in range(i + 1):
candy_count += route[0][j]
candy_count += route[1][i]
for j in range(i + 1, N):
candy_count += route[1][j]
if candy_count > candy_count_max:
candy_count_max = candy_count
print(candy_count_max) | # -*- coding: utf-8 -*-
def main():
n = int(eval(input()))
a = [list(map(int, input().split())) for i in range(2)]
count = 0
for i in range(n):
first = sum(a[0][:i + 1])
second = sum(a[1][i:])
count = max(count, first + second)
print(count)
if __name__ == '__main__':
main()
| 38 | 18 | 847 | 340 | # -*- coding: utf-8 -*-
# AtCoder Beginner Contest
# Problem C
import numpy as np
if __name__ == "__main__":
# Input
N = int(eval(input()))
route = np.zeros([2, N], dtype=int)
# HACK: More smarter.
for i in range(2):
line = [int(i) for i in input().split(" ")]
for j in range(N):
route[i][j] = line[j]
candy_count_max = 0
# See: https://img.atcoder.jp/arc090/editorial.pdf
# p.7
# HACK: Not beautiful.
for i in range(N):
candy_count = 0
for j in range(i + 1):
candy_count += route[0][j]
candy_count += route[1][i]
for j in range(i + 1, N):
candy_count += route[1][j]
if candy_count > candy_count_max:
candy_count_max = candy_count
print(candy_count_max)
| # -*- coding: utf-8 -*-
def main():
n = int(eval(input()))
a = [list(map(int, input().split())) for i in range(2)]
count = 0
for i in range(n):
first = sum(a[0][: i + 1])
second = sum(a[1][i:])
count = max(count, first + second)
print(count)
if __name__ == "__main__":
main()
| false | 52.631579 | [
"-# AtCoder Beginner Contest",
"-# Problem C",
"-import numpy as np",
"+def main():",
"+ n = int(eval(input()))",
"+ a = [list(map(int, input().split())) for i in range(2)]",
"+ count = 0",
"+ for i in range(n):",
"+ first = sum(a[0][: i + 1])",
"+ second = sum(a[1][i:])",
"+ count = max(count, first + second)",
"+ print(count)",
"+",
"- # Input",
"- N = int(eval(input()))",
"- route = np.zeros([2, N], dtype=int)",
"- # HACK: More smarter.",
"- for i in range(2):",
"- line = [int(i) for i in input().split(\" \")]",
"- for j in range(N):",
"- route[i][j] = line[j]",
"- candy_count_max = 0",
"- # See: https://img.atcoder.jp/arc090/editorial.pdf",
"- # p.7",
"- # HACK: Not beautiful.",
"- for i in range(N):",
"- candy_count = 0",
"- for j in range(i + 1):",
"- candy_count += route[0][j]",
"- candy_count += route[1][i]",
"- for j in range(i + 1, N):",
"- candy_count += route[1][j]",
"- if candy_count > candy_count_max:",
"- candy_count_max = candy_count",
"- print(candy_count_max)",
"+ main()"
]
| false | 0.377288 | 0.041639 | 9.060832 | [
"s942211143",
"s786733245"
]
|
u294630296 | p02713 | python | s581374113 | s855033700 | 1,854 | 1,428 | 71,636 | 71,432 | Accepted | Accepted | 22.98 | import math
K = int(eval(input()))
res = [math.gcd(a, math.gcd(b,c)) for a in range(1, K+1) for b in range(1, K+1) for c in range(1, K+1)]
print((sum(res)))
| from math import gcd
K = int(eval(input()))
res = [gcd(a, gcd(b,c)) for a in range(1, K+1) for b in range(1, K+1) for c in range(1, K+1)]
print((sum(res)))
| 10 | 10 | 166 | 165 | import math
K = int(eval(input()))
res = [
math.gcd(a, math.gcd(b, c))
for a in range(1, K + 1)
for b in range(1, K + 1)
for c in range(1, K + 1)
]
print((sum(res)))
| from math import gcd
K = int(eval(input()))
res = [
gcd(a, gcd(b, c))
for a in range(1, K + 1)
for b in range(1, K + 1)
for c in range(1, K + 1)
]
print((sum(res)))
| false | 0 | [
"-import math",
"+from math import gcd",
"- math.gcd(a, math.gcd(b, c))",
"+ gcd(a, gcd(b, c))"
]
| false | 0.050078 | 0.243791 | 0.205414 | [
"s581374113",
"s855033700"
]
|
u075303794 | p02927 | python | s477046686 | s818666680 | 24 | 20 | 3,060 | 2,940 | Accepted | Accepted | 16.67 | M,D = list(map(int,input().split()))
ans = 0
for i in range(1, M+1):
for j in range(1, D+1):
if j < 22:
continue
else:
j = str(j)
d1 = int(j[0])
d2 = int(j[1])
if d1>=2 and d2>=2 and i == d1*d2:
ans += 1
print(ans) | M,D = list(map(int,input().split()))
ans = 0
for i in range(1, M+1):
for j in range(1, D+1):
if j//10 >=2 and j%10 >=2 and i == (j//10)*(j%10):
ans += 1
print(ans) | 13 | 7 | 268 | 177 | M, D = list(map(int, input().split()))
ans = 0
for i in range(1, M + 1):
for j in range(1, D + 1):
if j < 22:
continue
else:
j = str(j)
d1 = int(j[0])
d2 = int(j[1])
if d1 >= 2 and d2 >= 2 and i == d1 * d2:
ans += 1
print(ans)
| M, D = list(map(int, input().split()))
ans = 0
for i in range(1, M + 1):
for j in range(1, D + 1):
if j // 10 >= 2 and j % 10 >= 2 and i == (j // 10) * (j % 10):
ans += 1
print(ans)
| false | 46.153846 | [
"- if j < 22:",
"- continue",
"- else:",
"- j = str(j)",
"- d1 = int(j[0])",
"- d2 = int(j[1])",
"- if d1 >= 2 and d2 >= 2 and i == d1 * d2:",
"- ans += 1",
"+ if j // 10 >= 2 and j % 10 >= 2 and i == (j // 10) * (j % 10):",
"+ ans += 1"
]
| false | 0.049523 | 0.049033 | 1.009987 | [
"s477046686",
"s818666680"
]
|
u671060652 | p02860 | python | s911008401 | s615188004 | 170 | 55 | 38,384 | 61,720 | Accepted | Accepted | 67.65 | n = int(eval(input()))
s = eval(input())
def judge(s):
if len(s) % 2 == 1:
print("No")
return
for i in range(0, len(s)//2):
if(s[i] != s[len(s)//2 + i]):
print("No")
return
print("Yes")
return
judge(s) | n = int(eval(input()))
s = eval(input())
l = s[:len(s)//2]
if s == l+l:
print("Yes")
else: print("No") | 17 | 7 | 273 | 101 | n = int(eval(input()))
s = eval(input())
def judge(s):
if len(s) % 2 == 1:
print("No")
return
for i in range(0, len(s) // 2):
if s[i] != s[len(s) // 2 + i]:
print("No")
return
print("Yes")
return
judge(s)
| n = int(eval(input()))
s = eval(input())
l = s[: len(s) // 2]
if s == l + l:
print("Yes")
else:
print("No")
| false | 58.823529 | [
"-",
"-",
"-def judge(s):",
"- if len(s) % 2 == 1:",
"- print(\"No\")",
"- return",
"- for i in range(0, len(s) // 2):",
"- if s[i] != s[len(s) // 2 + i]:",
"- print(\"No\")",
"- return",
"+l = s[: len(s) // 2]",
"+if s == l + l:",
"- return",
"-",
"-",
"-judge(s)",
"+else:",
"+ print(\"No\")"
]
| false | 0.03444 | 0.033747 | 1.020552 | [
"s911008401",
"s615188004"
]
|
u846150137 | p03255 | python | s795441410 | s769579738 | 1,066 | 858 | 27,656 | 27,244 | Accepted | Accepted | 19.51 | I=lambda:list(map(int,input().split()))
n,p = I()
s=[0]
for i in I():
s += [s[-1] + i]
for t in range(1, n + 1):
m = 5 * s[n] + t * p
c = n - t * 2
while c > 0:
m += 2 * s[c]
c -= t
a = m if t == 1 else min(a,m)
print((a + n * p)) | I=lambda:list(map(int,input().split()))
n,p = I()
s=[0]
for i in I():
s += [s[-1]+i]
for t in range(1,n + 1):
m = 5 * s[n] + t * p
for i in range(n - t * 2,0,-t):
m += 2 * s[i]
a = m if t == 1 else min(a,m)
print((a + n * p)) | 14 | 12 | 254 | 241 | I = lambda: list(map(int, input().split()))
n, p = I()
s = [0]
for i in I():
s += [s[-1] + i]
for t in range(1, n + 1):
m = 5 * s[n] + t * p
c = n - t * 2
while c > 0:
m += 2 * s[c]
c -= t
a = m if t == 1 else min(a, m)
print((a + n * p))
| I = lambda: list(map(int, input().split()))
n, p = I()
s = [0]
for i in I():
s += [s[-1] + i]
for t in range(1, n + 1):
m = 5 * s[n] + t * p
for i in range(n - t * 2, 0, -t):
m += 2 * s[i]
a = m if t == 1 else min(a, m)
print((a + n * p))
| false | 14.285714 | [
"- c = n - t * 2",
"- while c > 0:",
"- m += 2 * s[c]",
"- c -= t",
"+ for i in range(n - t * 2, 0, -t):",
"+ m += 2 * s[i]"
]
| false | 0.063965 | 0.037361 | 1.7121 | [
"s795441410",
"s769579738"
]
|
u435300817 | p02412 | python | s404613409 | s748118580 | 1,930 | 330 | 19,480 | 7,768 | Accepted | Accepted | 82.9 | num_list = []
while True:
values = [int(x) for x in input().split()]
if 0 == values[0] and 0 == values[1]:
break
num_list.append(values)
for n, t in num_list:
ret = ' '.join(str(x + y + z) for x in range(1, n + 1) for y in range(x + 1, n + 1) for z in range(y + 1, n + 1))
cnt = 0
for x in ret.split():
if str(t) == x:
cnt += 1
print(cnt) | num_list = []
while True:
values = [int(x) for x in input().split()]
if 0 == values[0] and 0 == values[1]:
break
num_list.append(values)
for n, t in num_list:
ret = ' '.join(str(x + y + z) for x in range(1, n + 1) for y in range(x + 1, n + 1) for z in range(y + 1, n + 1) if t == x + y + z)
print((ret.count(str(t)))) | 14 | 10 | 408 | 353 | num_list = []
while True:
values = [int(x) for x in input().split()]
if 0 == values[0] and 0 == values[1]:
break
num_list.append(values)
for n, t in num_list:
ret = " ".join(
str(x + y + z)
for x in range(1, n + 1)
for y in range(x + 1, n + 1)
for z in range(y + 1, n + 1)
)
cnt = 0
for x in ret.split():
if str(t) == x:
cnt += 1
print(cnt)
| num_list = []
while True:
values = [int(x) for x in input().split()]
if 0 == values[0] and 0 == values[1]:
break
num_list.append(values)
for n, t in num_list:
ret = " ".join(
str(x + y + z)
for x in range(1, n + 1)
for y in range(x + 1, n + 1)
for z in range(y + 1, n + 1)
if t == x + y + z
)
print((ret.count(str(t))))
| false | 28.571429 | [
"+ if t == x + y + z",
"- cnt = 0",
"- for x in ret.split():",
"- if str(t) == x:",
"- cnt += 1",
"- print(cnt)",
"+ print((ret.count(str(t))))"
]
| false | 0.037156 | 0.035906 | 1.034808 | [
"s404613409",
"s748118580"
]
|
u227020436 | p03287 | python | s702919501 | s788623414 | 144 | 86 | 21,952 | 14,228 | Accepted | Accepted | 40.28 | N, M = [int(t) for t in input().split()]
a = [int(t) for t in input().split()]
assert len(a) == N
def prefixsum(a):
s = [0] * len(a)
s[0] = a[0] % M
for i in range(1, len(a)):
s[i] = (s[i-1] + a[i]) % M
return s
s = prefixsum(a)
t = [(s[i], i) for i in range(N)]
t.sort()
count = 0
prev = -1
c = 0
for v, i in t:
if v == 0: count += 1
if prev == v:
c += 1
else:
count += c * (c - 1) // 2
c = 1
prev = v
count += c * (c - 1) // 2
print(count) | # -*- coding: utf-8 -*-
N, M = [int(t) for t in input().split()]
A = [int(t) for t in input().split()]
assert len(A) == N
def prefixsum(A):
'''S[i] == sum(A[:i]) % M かつ len(S) == len(A) + 1 であるSを返す.'''
S = [0]
for a in A:
S.append((S[-1] + a) % M)
return S
def eqlen(S):
'''Sは整列済みリスト. 等しい要素の個数からなるリストを返す.'''
T = []
p = None
for s in S:
if p == s:
T[-1] += 1
else:
T.append(1)
p = s
return T
S = prefixsum(A)
S.sort()
T = eqlen(S)
print((sum(t * (t - 1) // 2 for t in T))) | 29 | 29 | 544 | 600 | N, M = [int(t) for t in input().split()]
a = [int(t) for t in input().split()]
assert len(a) == N
def prefixsum(a):
s = [0] * len(a)
s[0] = a[0] % M
for i in range(1, len(a)):
s[i] = (s[i - 1] + a[i]) % M
return s
s = prefixsum(a)
t = [(s[i], i) for i in range(N)]
t.sort()
count = 0
prev = -1
c = 0
for v, i in t:
if v == 0:
count += 1
if prev == v:
c += 1
else:
count += c * (c - 1) // 2
c = 1
prev = v
count += c * (c - 1) // 2
print(count)
| # -*- coding: utf-8 -*-
N, M = [int(t) for t in input().split()]
A = [int(t) for t in input().split()]
assert len(A) == N
def prefixsum(A):
"""S[i] == sum(A[:i]) % M かつ len(S) == len(A) + 1 であるSを返す."""
S = [0]
for a in A:
S.append((S[-1] + a) % M)
return S
def eqlen(S):
"""Sは整列済みリスト. 等しい要素の個数からなるリストを返す."""
T = []
p = None
for s in S:
if p == s:
T[-1] += 1
else:
T.append(1)
p = s
return T
S = prefixsum(A)
S.sort()
T = eqlen(S)
print((sum(t * (t - 1) // 2 for t in T)))
| false | 0 | [
"+# -*- coding: utf-8 -*-",
"-a = [int(t) for t in input().split()]",
"-assert len(a) == N",
"+A = [int(t) for t in input().split()]",
"+assert len(A) == N",
"-def prefixsum(a):",
"- s = [0] * len(a)",
"- s[0] = a[0] % M",
"- for i in range(1, len(a)):",
"- s[i] = (s[i - 1] + a[i]) % M",
"- return s",
"+def prefixsum(A):",
"+ \"\"\"S[i] == sum(A[:i]) % M かつ len(S) == len(A) + 1 であるSを返す.\"\"\"",
"+ S = [0]",
"+ for a in A:",
"+ S.append((S[-1] + a) % M)",
"+ return S",
"-s = prefixsum(a)",
"-t = [(s[i], i) for i in range(N)]",
"-t.sort()",
"-count = 0",
"-prev = -1",
"-c = 0",
"-for v, i in t:",
"- if v == 0:",
"- count += 1",
"- if prev == v:",
"- c += 1",
"- else:",
"- count += c * (c - 1) // 2",
"- c = 1",
"- prev = v",
"-count += c * (c - 1) // 2",
"-print(count)",
"+def eqlen(S):",
"+ \"\"\"Sは整列済みリスト. 等しい要素の個数からなるリストを返す.\"\"\"",
"+ T = []",
"+ p = None",
"+ for s in S:",
"+ if p == s:",
"+ T[-1] += 1",
"+ else:",
"+ T.append(1)",
"+ p = s",
"+ return T",
"+",
"+",
"+S = prefixsum(A)",
"+S.sort()",
"+T = eqlen(S)",
"+print((sum(t * (t - 1) // 2 for t in T)))"
]
| false | 0.034625 | 0.036128 | 0.9584 | [
"s702919501",
"s788623414"
]
|
u279605379 | p02297 | python | s593854766 | s825537588 | 30 | 20 | 7,716 | 7,728 | Accepted | Accepted | 33.33 | x=list(range(int(eval(input()))))
P=[]
for _ in x:P+=[[int(i) for i in input().split()]]
_=0
P+=[P[0]]
for j in x:_+=P[j][0]*P[j+1][1]-P[j+1][0]*P[j][1]
print((_*0.5)) | x=list(range(int(eval(input()))))
P=[]
for _ in x:P+=[[int(i) for i in input().split()]]
_=0
P+=[P[0]]
for j in x:_+=P[j+1][1]*P[j][0]-P[j][1]*P[j+1][0]
print((_*0.5)) | 7 | 7 | 159 | 159 | x = list(range(int(eval(input()))))
P = []
for _ in x:
P += [[int(i) for i in input().split()]]
_ = 0
P += [P[0]]
for j in x:
_ += P[j][0] * P[j + 1][1] - P[j + 1][0] * P[j][1]
print((_ * 0.5))
| x = list(range(int(eval(input()))))
P = []
for _ in x:
P += [[int(i) for i in input().split()]]
_ = 0
P += [P[0]]
for j in x:
_ += P[j + 1][1] * P[j][0] - P[j][1] * P[j + 1][0]
print((_ * 0.5))
| false | 0 | [
"- _ += P[j][0] * P[j + 1][1] - P[j + 1][0] * P[j][1]",
"+ _ += P[j + 1][1] * P[j][0] - P[j][1] * P[j + 1][0]"
]
| false | 0.107943 | 0.074187 | 1.455021 | [
"s593854766",
"s825537588"
]
|
u021019433 | p02837 | python | s005871850 | s896055358 | 368 | 61 | 58,204 | 3,064 | Accepted | Accepted | 83.42 | from itertools import combinations, count
n = int(eval(input()))
r = list(range(n))
a = [(set(), set()) for _ in r]
for i in r:
for _ in range(int(eval(input()))):
x, y = list(map(int, input().split()))
a[i][y].add(x - 1)
r = next(i for i in count(n, - 1) for x in map(set, combinations(r, i))
if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x))
print(r)
| from itertools import combinations, count
n = int(eval(input()))
r = list(range(n))
a = [(set(), set()) for _ in r]
for i in r:
for _ in range(int(eval(input()))):
x, y = list(map(int, input().split()))
a[i][y].add(x - 1)
r = next(i for i in count(n, - 1) for x in combinations(r, i)
if all(a[j][0].isdisjoint(x) and a[j][1].issubset(x) for j in x))
print(r)
| 12 | 12 | 369 | 367 | from itertools import combinations, count
n = int(eval(input()))
r = list(range(n))
a = [(set(), set()) for _ in r]
for i in r:
for _ in range(int(eval(input()))):
x, y = list(map(int, input().split()))
a[i][y].add(x - 1)
r = next(
i
for i in count(n, -1)
for x in map(set, combinations(r, i))
if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x)
)
print(r)
| from itertools import combinations, count
n = int(eval(input()))
r = list(range(n))
a = [(set(), set()) for _ in r]
for i in r:
for _ in range(int(eval(input()))):
x, y = list(map(int, input().split()))
a[i][y].add(x - 1)
r = next(
i
for i in count(n, -1)
for x in combinations(r, i)
if all(a[j][0].isdisjoint(x) and a[j][1].issubset(x) for j in x)
)
print(r)
| false | 0 | [
"- for x in map(set, combinations(r, i))",
"- if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x)",
"+ for x in combinations(r, i)",
"+ if all(a[j][0].isdisjoint(x) and a[j][1].issubset(x) for j in x)"
]
| false | 0.035536 | 0.035606 | 0.998021 | [
"s005871850",
"s896055358"
]
|
u347640436 | p02948 | python | s795358805 | s013144451 | 427 | 213 | 26,072 | 26,020 | Accepted | Accepted | 50.12 | from heapq import heappush, heappop
n, m = list(map(int, input().split()))
jobs = {}
for _ in range(n):
a, b = list(map(int, input().split()))
if a > m:
continue
if a in jobs:
jobs[a].append(b)
else:
jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
if a in jobs:
for b in jobs[a]:
heappush(candidates, -b)
else:
if len(candidates) == 0:
continue
result += -heappop(candidates)
print(result)
| from sys import stdin
def main():
from builtins import int, map, range
readline = stdin.readline
from heapq import heappush, heappop
n, m = list(map(int, readline().split()))
jobs = {}
for _ in range(n):
a, b = list(map(int, readline().split()))
if a > m:
continue
if a in jobs:
jobs[a].append(b)
else:
jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
if a in jobs:
for b in jobs[a]:
heappush(candidates, -b)
else:
if len(candidates) == 0:
continue
result += -heappop(candidates)
print(result)
main()
| 22 | 27 | 464 | 627 | from heapq import heappush, heappop
n, m = list(map(int, input().split()))
jobs = {}
for _ in range(n):
a, b = list(map(int, input().split()))
if a > m:
continue
if a in jobs:
jobs[a].append(b)
else:
jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
if a in jobs:
for b in jobs[a]:
heappush(candidates, -b)
else:
if len(candidates) == 0:
continue
result += -heappop(candidates)
print(result)
| from sys import stdin
def main():
from builtins import int, map, range
readline = stdin.readline
from heapq import heappush, heappop
n, m = list(map(int, readline().split()))
jobs = {}
for _ in range(n):
a, b = list(map(int, readline().split()))
if a > m:
continue
if a in jobs:
jobs[a].append(b)
else:
jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
if a in jobs:
for b in jobs[a]:
heappush(candidates, -b)
else:
if len(candidates) == 0:
continue
result += -heappop(candidates)
print(result)
main()
| false | 18.518519 | [
"-from heapq import heappush, heappop",
"+from sys import stdin",
"-n, m = list(map(int, input().split()))",
"-jobs = {}",
"-for _ in range(n):",
"- a, b = list(map(int, input().split()))",
"- if a > m:",
"- continue",
"- if a in jobs:",
"- jobs[a].append(b)",
"- else:",
"- jobs[a] = [b]",
"-result = 0",
"-candidates = []",
"-for a in range(1, m + 1):",
"- if a in jobs:",
"- for b in jobs[a]:",
"- heappush(candidates, -b)",
"- else:",
"- if len(candidates) == 0:",
"+",
"+def main():",
"+ from builtins import int, map, range",
"+",
"+ readline = stdin.readline",
"+ from heapq import heappush, heappop",
"+",
"+ n, m = list(map(int, readline().split()))",
"+ jobs = {}",
"+ for _ in range(n):",
"+ a, b = list(map(int, readline().split()))",
"+ if a > m:",
"- result += -heappop(candidates)",
"-print(result)",
"+ if a in jobs:",
"+ jobs[a].append(b)",
"+ else:",
"+ jobs[a] = [b]",
"+ result = 0",
"+ candidates = []",
"+ for a in range(1, m + 1):",
"+ if a in jobs:",
"+ for b in jobs[a]:",
"+ heappush(candidates, -b)",
"+ else:",
"+ if len(candidates) == 0:",
"+ continue",
"+ result += -heappop(candidates)",
"+ print(result)",
"+",
"+",
"+main()"
]
| false | 0.085254 | 0.045741 | 1.863842 | [
"s795358805",
"s013144451"
]
|
u603958124 | p03061 | python | s654525017 | s386589828 | 1,691 | 114 | 22,144 | 22,252 | Accepted | Accepted | 93.26 | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(eval(input()))
def MAP() : return list(map(int,input().split()))
def MAP1() : return [int(x)-1 for x in input().split()]
def LIST() : return list(MAP())
def LIST1() : return list(MAP1())
#####segfunc#####
def segfunc(x, y):
return gcd(x, y)
#################
#####ide_ele#####
ide_ele = 0
#################
class SegTree:
"""
init(init_val, ide_ele): 配列init_valで初期化 O(N)
update(k, x): k番目の値をxに更新 O(logN)
query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
"""
def __init__(self, init_val, segfunc, ide_ele):
"""
init_val: 配列の初期値
segfunc: 区間にしたい操作
ide_ele: 単位元
n: 要素数
num: n以上の最小の2のべき乗
tree: セグメント木(1-index)
"""
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.tree = [ide_ele] * 2 * self.num
# 配列の値を葉にセット
for i in range(n):
self.tree[self.num + i] = init_val[i]
# 構築していく
for i in range(self.num - 1, 0, -1):
self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, k, x):
"""
k番目の値をxに更新
k: index(0-index)
x: update value
"""
k += self.num
self.tree[k] = x
while k > 1:
self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
k >>= 1
def query(self, l, r):
"""
[l, r)のsegfuncしたものを得る
l: index(0-index)
r: index(0-index)
"""
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.tree[l])
l += 1
if r & 1:
res = self.segfunc(res, self.tree[r - 1])
l >>= 1
r >>= 1
return res
def solve():
N = INT()
a = LIST()
seg = SegTree(a, segfunc, ide_ele)
ans = 1
for i in range(N):
seg.update(i, 0)
ans = max(ans, seg.query(0, N))
seg.update(i, a[i])
print(ans)
if __name__ == '__main__':
solve() | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(eval(input()))
def MAP() : return list(map(int,input().split()))
def MAP1() : return [int(x)-1 for x in input().split()]
def LIST() : return list(MAP())
def LIST1() : return list(MAP1())
def solve():
N = INT()
a = LIST()
l = [0]*N
r = [0]*N
l[0] = a[0]
r[N-1] = a[N-1]
for i in range(1, N):
l[i] = gcd(l[i-1], a[i])
for i in range(N-2, -1, -1):
r[i] = gcd(r[i+1], a[i])
ans = max(r[1], l[N-2])
for i in range(1, N-1):
ans = max(ans, gcd(l[i-1], r[i+1]))
print(ans)
if __name__ == '__main__':
solve() | 102 | 40 | 2,862 | 1,245 | from math import (
ceil,
floor,
factorial,
gcd,
sqrt,
log2,
cos,
sin,
tan,
acos,
asin,
atan,
degrees,
radians,
pi,
inf,
)
from itertools import (
accumulate,
groupby,
permutations,
combinations,
product,
combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def MAP1():
return [int(x) - 1 for x in input().split()]
def LIST():
return list(MAP())
def LIST1():
return list(MAP1())
#####segfunc#####
def segfunc(x, y):
return gcd(x, y)
#################
#####ide_ele#####
ide_ele = 0
#################
class SegTree:
"""
init(init_val, ide_ele): 配列init_valで初期化 O(N)
update(k, x): k番目の値をxに更新 O(logN)
query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
"""
def __init__(self, init_val, segfunc, ide_ele):
"""
init_val: 配列の初期値
segfunc: 区間にしたい操作
ide_ele: 単位元
n: 要素数
num: n以上の最小の2のべき乗
tree: セグメント木(1-index)
"""
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.tree = [ide_ele] * 2 * self.num
# 配列の値を葉にセット
for i in range(n):
self.tree[self.num + i] = init_val[i]
# 構築していく
for i in range(self.num - 1, 0, -1):
self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, k, x):
"""
k番目の値をxに更新
k: index(0-index)
x: update value
"""
k += self.num
self.tree[k] = x
while k > 1:
self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
k >>= 1
def query(self, l, r):
"""
[l, r)のsegfuncしたものを得る
l: index(0-index)
r: index(0-index)
"""
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.tree[l])
l += 1
if r & 1:
res = self.segfunc(res, self.tree[r - 1])
l >>= 1
r >>= 1
return res
def solve():
N = INT()
a = LIST()
seg = SegTree(a, segfunc, ide_ele)
ans = 1
for i in range(N):
seg.update(i, 0)
ans = max(ans, seg.query(0, N))
seg.update(i, a[i])
print(ans)
if __name__ == "__main__":
solve()
| from math import (
ceil,
floor,
factorial,
gcd,
sqrt,
log2,
cos,
sin,
tan,
acos,
asin,
atan,
degrees,
radians,
pi,
inf,
)
from itertools import (
accumulate,
groupby,
permutations,
combinations,
product,
combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def MAP1():
return [int(x) - 1 for x in input().split()]
def LIST():
return list(MAP())
def LIST1():
return list(MAP1())
def solve():
N = INT()
a = LIST()
l = [0] * N
r = [0] * N
l[0] = a[0]
r[N - 1] = a[N - 1]
for i in range(1, N):
l[i] = gcd(l[i - 1], a[i])
for i in range(N - 2, -1, -1):
r[i] = gcd(r[i + 1], a[i])
ans = max(r[1], l[N - 2])
for i in range(1, N - 1):
ans = max(ans, gcd(l[i - 1], r[i + 1]))
print(ans)
if __name__ == "__main__":
solve()
| false | 60.784314 | [
"-#####segfunc#####",
"-def segfunc(x, y):",
"- return gcd(x, y)",
"-",
"-",
"-#################",
"-#####ide_ele#####",
"-ide_ele = 0",
"-#################",
"-class SegTree:",
"- \"\"\"",
"- init(init_val, ide_ele): 配列init_valで初期化 O(N)",
"- update(k, x): k番目の値をxに更新 O(logN)",
"- query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)",
"- \"\"\"",
"-",
"- def __init__(self, init_val, segfunc, ide_ele):",
"- \"\"\"",
"- init_val: 配列の初期値",
"- segfunc: 区間にしたい操作",
"- ide_ele: 単位元",
"- n: 要素数",
"- num: n以上の最小の2のべき乗",
"- tree: セグメント木(1-index)",
"- \"\"\"",
"- n = len(init_val)",
"- self.segfunc = segfunc",
"- self.ide_ele = ide_ele",
"- self.num = 1 << (n - 1).bit_length()",
"- self.tree = [ide_ele] * 2 * self.num",
"- # 配列の値を葉にセット",
"- for i in range(n):",
"- self.tree[self.num + i] = init_val[i]",
"- # 構築していく",
"- for i in range(self.num - 1, 0, -1):",
"- self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])",
"-",
"- def update(self, k, x):",
"- \"\"\"",
"- k番目の値をxに更新",
"- k: index(0-index)",
"- x: update value",
"- \"\"\"",
"- k += self.num",
"- self.tree[k] = x",
"- while k > 1:",
"- self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])",
"- k >>= 1",
"-",
"- def query(self, l, r):",
"- \"\"\"",
"- [l, r)のsegfuncしたものを得る",
"- l: index(0-index)",
"- r: index(0-index)",
"- \"\"\"",
"- res = self.ide_ele",
"- l += self.num",
"- r += self.num",
"- while l < r:",
"- if l & 1:",
"- res = self.segfunc(res, self.tree[l])",
"- l += 1",
"- if r & 1:",
"- res = self.segfunc(res, self.tree[r - 1])",
"- l >>= 1",
"- r >>= 1",
"- return res",
"-",
"-",
"- seg = SegTree(a, segfunc, ide_ele)",
"- ans = 1",
"- for i in range(N):",
"- seg.update(i, 0)",
"- ans = max(ans, seg.query(0, N))",
"- seg.update(i, a[i])",
"+ l = [0] * N",
"+ r = [0] * N",
"+ l[0] = a[0]",
"+ r[N - 1] = a[N - 1]",
"+ for i in range(1, N):",
"+ l[i] = gcd(l[i - 1], a[i])",
"+ for i in range(N - 2, -1, -1):",
"+ r[i] = gcd(r[i + 1], a[i])",
"+ ans = max(r[1], l[N - 2])",
"+ for i in range(1, N - 1):",
"+ ans = max(ans, gcd(l[i - 1], r[i + 1]))"
]
| false | 0.063152 | 0.037024 | 1.705721 | [
"s654525017",
"s386589828"
]
|
u611090896 | p04001 | python | s527298496 | s941339888 | 38 | 34 | 9,144 | 9,064 | Accepted | Accepted | 10.53 | S = eval(input())
res_list = []
for i in range(2**(len(S)-1)):
temp_s = ''
for j in range(len(S)):
temp_s += S[j]
if ((i >> j) & 1):
temp_s += '+'
# print(temp_s)
res_list.append(temp_s)
temp_S_list = [eval(item) for item in res_list]
print((sum(temp_S_list))) | s = eval(input())
n = len(s)-1
total=0
for i in range(2**n):
pl=['']*n
ans=''
for j in range(n):
if ((i>>j)&1):
pl[n-1-j] = '+'
for k in range(n):
ans += s[k]+pl[k]
ans+=s[-1]
total += eval(ans)
print(total) | 16 | 15 | 315 | 243 | S = eval(input())
res_list = []
for i in range(2 ** (len(S) - 1)):
temp_s = ""
for j in range(len(S)):
temp_s += S[j]
if (i >> j) & 1:
temp_s += "+"
# print(temp_s)
res_list.append(temp_s)
temp_S_list = [eval(item) for item in res_list]
print((sum(temp_S_list)))
| s = eval(input())
n = len(s) - 1
total = 0
for i in range(2**n):
pl = [""] * n
ans = ""
for j in range(n):
if (i >> j) & 1:
pl[n - 1 - j] = "+"
for k in range(n):
ans += s[k] + pl[k]
ans += s[-1]
total += eval(ans)
print(total)
| false | 6.25 | [
"-S = eval(input())",
"-res_list = []",
"-for i in range(2 ** (len(S) - 1)):",
"- temp_s = \"\"",
"- for j in range(len(S)):",
"- temp_s += S[j]",
"+s = eval(input())",
"+n = len(s) - 1",
"+total = 0",
"+for i in range(2**n):",
"+ pl = [\"\"] * n",
"+ ans = \"\"",
"+ for j in range(n):",
"- temp_s += \"+\"",
"- # print(temp_s)",
"- res_list.append(temp_s)",
"-temp_S_list = [eval(item) for item in res_list]",
"-print((sum(temp_S_list)))",
"+ pl[n - 1 - j] = \"+\"",
"+ for k in range(n):",
"+ ans += s[k] + pl[k]",
"+ ans += s[-1]",
"+ total += eval(ans)",
"+print(total)"
]
| false | 0.039894 | 0.040716 | 0.97982 | [
"s527298496",
"s941339888"
]
|
u209619667 | p03243 | python | s686421110 | s181943005 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | A = int(eval(input()))
if A <=111:
print((111))
elif A<= 222:
print((222))
elif A <= 333:
print((333))
elif A <= 444:
print((444))
elif A <= 555:
print((555))
elif A <=666:
print((666))
elif A <= 777:
print((777))
elif A <= 888:
print((888))
elif A <=999:
print((999)) | A = int(eval(input()))
B = int(A / 111)
C = A % 111 == 0
if not C:
B = (B+1) * 111
print(B)
else:
B = B*111
print(B) | 19 | 9 | 280 | 126 | A = int(eval(input()))
if A <= 111:
print((111))
elif A <= 222:
print((222))
elif A <= 333:
print((333))
elif A <= 444:
print((444))
elif A <= 555:
print((555))
elif A <= 666:
print((666))
elif A <= 777:
print((777))
elif A <= 888:
print((888))
elif A <= 999:
print((999))
| A = int(eval(input()))
B = int(A / 111)
C = A % 111 == 0
if not C:
B = (B + 1) * 111
print(B)
else:
B = B * 111
print(B)
| false | 52.631579 | [
"-if A <= 111:",
"- print((111))",
"-elif A <= 222:",
"- print((222))",
"-elif A <= 333:",
"- print((333))",
"-elif A <= 444:",
"- print((444))",
"-elif A <= 555:",
"- print((555))",
"-elif A <= 666:",
"- print((666))",
"-elif A <= 777:",
"- print((777))",
"-elif A <= 888:",
"- print((888))",
"-elif A <= 999:",
"- print((999))",
"+B = int(A / 111)",
"+C = A % 111 == 0",
"+if not C:",
"+ B = (B + 1) * 111",
"+ print(B)",
"+else:",
"+ B = B * 111",
"+ print(B)"
]
| false | 0.049283 | 0.047665 | 1.033957 | [
"s686421110",
"s181943005"
]
|
u416011173 | p02550 | python | s756657052 | s999216555 | 60 | 55 | 13,116 | 13,216 | Accepted | Accepted | 8.33 | # -*- coding: utf-8 -*-
# 標準入力を取得
N, X, M = list(map(int, input().split()))
# 求解処理
def f(x: int, m: int) -> int:
return x**2 % m
A = [X]
s = {X}
i = 0
while True:
A_next = f(A[-1], M)
if A_next in s:
i = A.index(A_next)
break
else:
A.append(A_next)
s.add(A_next)
loop_length = len(A) - i
loop_cnt = (N - i) // loop_length
loop_res = (N - i) % loop_length
ans = sum(A[:i]) + loop_cnt * sum(A[i:]) + sum(A[i: i + loop_res])
# 結果出力
print(ans)
| # -*- coding: utf-8 -*-
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
# 標準入力を取得
N, X, M = list(map(int, input().split()))
return N, X, M
def f(x: int, m: int) -> int:
"""
xをmで割った余りを返す.
Args:\n
x (int): 整数
m (int): 整数
Returns:\n
int: xをmで割った余り
"""
return x % m
def main(N: int, X: int, M: int) -> None:
"""
メイン処理.
Args:\n
N (int): 整数(1 <= N <= 10^{10})
X (int): 整数(0 <= X <= M <= 10^5)
M (int): 整数(0 <= X <= M <= 10^5)
"""
# 求解処理
A = [X]
s = {X}
i = 0
while True:
A_next = f(A[-1]**2, M)
if A_next in s:
i = A.index(A_next)
break
else:
A.append(A_next)
s.add(A_next)
loop_length = len(A) - i
loop_cnt = (N - i) // loop_length
loop_res = (N - i) % loop_length
ans = sum(A[:i]) + loop_cnt * sum(A[i:]) + sum(A[i: i + loop_res])
# 結果出力
print(ans)
if __name__ == "__main__":
# 標準入力を取得
N, X, M = get_input()
# メイン処理
main(N, X, M)
| 30 | 66 | 524 | 1,182 | # -*- coding: utf-8 -*-
# 標準入力を取得
N, X, M = list(map(int, input().split()))
# 求解処理
def f(x: int, m: int) -> int:
return x**2 % m
A = [X]
s = {X}
i = 0
while True:
A_next = f(A[-1], M)
if A_next in s:
i = A.index(A_next)
break
else:
A.append(A_next)
s.add(A_next)
loop_length = len(A) - i
loop_cnt = (N - i) // loop_length
loop_res = (N - i) % loop_length
ans = sum(A[:i]) + loop_cnt * sum(A[i:]) + sum(A[i : i + loop_res])
# 結果出力
print(ans)
| # -*- coding: utf-8 -*-
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
# 標準入力を取得
N, X, M = list(map(int, input().split()))
return N, X, M
def f(x: int, m: int) -> int:
"""
xをmで割った余りを返す.
Args:\n
x (int): 整数
m (int): 整数
Returns:\n
int: xをmで割った余り
"""
return x % m
def main(N: int, X: int, M: int) -> None:
"""
メイン処理.
Args:\n
N (int): 整数(1 <= N <= 10^{10})
X (int): 整数(0 <= X <= M <= 10^5)
M (int): 整数(0 <= X <= M <= 10^5)
"""
# 求解処理
A = [X]
s = {X}
i = 0
while True:
A_next = f(A[-1] ** 2, M)
if A_next in s:
i = A.index(A_next)
break
else:
A.append(A_next)
s.add(A_next)
loop_length = len(A) - i
loop_cnt = (N - i) // loop_length
loop_res = (N - i) % loop_length
ans = sum(A[:i]) + loop_cnt * sum(A[i:]) + sum(A[i : i + loop_res])
# 結果出力
print(ans)
if __name__ == "__main__":
# 標準入力を取得
N, X, M = get_input()
# メイン処理
main(N, X, M)
| false | 54.545455 | [
"-# 標準入力を取得",
"-N, X, M = list(map(int, input().split()))",
"-# 求解処理",
"-def f(x: int, m: int) -> int:",
"- return x**2 % m",
"+def get_input() -> tuple:",
"+ \"\"\"",
"+ 標準入力を取得する.",
"+ Returns:\\n",
"+ tuple: 標準入力",
"+ \"\"\"",
"+ # 標準入力を取得",
"+ N, X, M = list(map(int, input().split()))",
"+ return N, X, M",
"-A = [X]",
"-s = {X}",
"-i = 0",
"-while True:",
"- A_next = f(A[-1], M)",
"- if A_next in s:",
"- i = A.index(A_next)",
"- break",
"- else:",
"- A.append(A_next)",
"- s.add(A_next)",
"-loop_length = len(A) - i",
"-loop_cnt = (N - i) // loop_length",
"-loop_res = (N - i) % loop_length",
"-ans = sum(A[:i]) + loop_cnt * sum(A[i:]) + sum(A[i : i + loop_res])",
"-# 結果出力",
"-print(ans)",
"+def f(x: int, m: int) -> int:",
"+ \"\"\"",
"+ xをmで割った余りを返す.",
"+ Args:\\n",
"+ x (int): 整数",
"+ m (int): 整数",
"+ Returns:\\n",
"+ int: xをmで割った余り",
"+ \"\"\"",
"+ return x % m",
"+",
"+",
"+def main(N: int, X: int, M: int) -> None:",
"+ \"\"\"",
"+ メイン処理.",
"+ Args:\\n",
"+ N (int): 整数(1 <= N <= 10^{10})",
"+ X (int): 整数(0 <= X <= M <= 10^5)",
"+ M (int): 整数(0 <= X <= M <= 10^5)",
"+ \"\"\"",
"+ # 求解処理",
"+ A = [X]",
"+ s = {X}",
"+ i = 0",
"+ while True:",
"+ A_next = f(A[-1] ** 2, M)",
"+ if A_next in s:",
"+ i = A.index(A_next)",
"+ break",
"+ else:",
"+ A.append(A_next)",
"+ s.add(A_next)",
"+ loop_length = len(A) - i",
"+ loop_cnt = (N - i) // loop_length",
"+ loop_res = (N - i) % loop_length",
"+ ans = sum(A[:i]) + loop_cnt * sum(A[i:]) + sum(A[i : i + loop_res])",
"+ # 結果出力",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ # 標準入力を取得",
"+ N, X, M = get_input()",
"+ # メイン処理",
"+ main(N, X, M)"
]
| false | 0.007808 | 0.036262 | 0.215314 | [
"s756657052",
"s999216555"
]
|
u389910364 | p03323 | python | s460880855 | s285521819 | 23 | 17 | 3,572 | 3,060 | Accepted | Accepted | 26.09 | import functools
import os
INF = float('inf')
def inp():
return int(input())
def inpf():
return float(input())
def inps():
return input()
def inl():
return list(map(int, input().split()))
def inlf():
return list(map(float, input().split()))
def inls():
return input().split()
def debug(fn):
if not os.getenv('LOCAL'):
return fn
@functools.wraps(fn)
def wrapper(*args, **kwargs):
print('DEBUG: {}({}) -> '.format(
fn.__name__,
', '.join(
list(map(str, args)) +
['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
)
), end='')
ret = fn(*args, **kwargs)
print(ret)
return ret
return wrapper
a, b = inl()
print('Yay!' if a*2 <= 16 and b*2 <= 16 else ':(')
| import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
A, B = list(map(int, sys.stdin.buffer.readline().split()))
ok = A <= 8 and B <= 8
if ok:
print('Yay!')
else:
print(':(')
| 53 | 20 | 883 | 336 | import functools
import os
INF = float("inf")
def inp():
return int(input())
def inpf():
return float(input())
def inps():
return input()
def inl():
return list(map(int, input().split()))
def inlf():
return list(map(float, input().split()))
def inls():
return input().split()
def debug(fn):
if not os.getenv("LOCAL"):
return fn
@functools.wraps(fn)
def wrapper(*args, **kwargs):
print(
"DEBUG: {}({}) -> ".format(
fn.__name__,
", ".join(
list(map(str, args))
+ ["{}={}".format(k, str(v)) for k, v in kwargs.items()]
),
),
end="",
)
ret = fn(*args, **kwargs)
print(ret)
return ret
return wrapper
a, b = inl()
print("Yay!" if a * 2 <= 16 and b * 2 <= 16 else ":(")
| import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
A, B = list(map(int, sys.stdin.buffer.readline().split()))
ok = A <= 8 and B <= 8
if ok:
print("Yay!")
else:
print(":(")
| false | 62.264151 | [
"-import functools",
"+import sys",
"+if os.getenv(\"LOCAL\"):",
"+ sys.stdin = open(\"_in.txt\", \"r\")",
"+sys.setrecursionlimit(10**9)",
"-",
"-",
"-def inp():",
"- return int(input())",
"-",
"-",
"-def inpf():",
"- return float(input())",
"-",
"-",
"-def inps():",
"- return input()",
"-",
"-",
"-def inl():",
"- return list(map(int, input().split()))",
"-",
"-",
"-def inlf():",
"- return list(map(float, input().split()))",
"-",
"-",
"-def inls():",
"- return input().split()",
"-",
"-",
"-def debug(fn):",
"- if not os.getenv(\"LOCAL\"):",
"- return fn",
"-",
"- @functools.wraps(fn)",
"- def wrapper(*args, **kwargs):",
"- print(",
"- \"DEBUG: {}({}) -> \".format(",
"- fn.__name__,",
"- \", \".join(",
"- list(map(str, args))",
"- + [\"{}={}\".format(k, str(v)) for k, v in kwargs.items()]",
"- ),",
"- ),",
"- end=\"\",",
"- )",
"- ret = fn(*args, **kwargs)",
"- print(ret)",
"- return ret",
"-",
"- return wrapper",
"-",
"-",
"-a, b = inl()",
"-print(\"Yay!\" if a * 2 <= 16 and b * 2 <= 16 else \":(\")",
"+IINF = 10**18",
"+MOD = 10**9 + 7",
"+# MOD = 998244353",
"+A, B = list(map(int, sys.stdin.buffer.readline().split()))",
"+ok = A <= 8 and B <= 8",
"+if ok:",
"+ print(\"Yay!\")",
"+else:",
"+ print(\":(\")"
]
| false | 0.039833 | 0.044131 | 0.902612 | [
"s460880855",
"s285521819"
]
|
u125545880 | p02936 | python | s266221853 | s872286135 | 1,990 | 1,182 | 236,924 | 62,576 | Accepted | Accepted | 40.6 | # 深さ優先探索の問題
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
N, Q = list(map(int, input().split()))
# 隣接リスト
t = [[] for _ in range(N)]
for _ in range(N-1):
a, b = [int(i) for i in readline().split()]
t[a-1].append(b-1)
t[b-1].append(a-1)
# スコア
s = [0] * N
for _ in range(Q):
p, x = [int(i) for i in readline().split()]
#s[p-1] = s[p-1] + x
s[p-1] += x
ans = [0] * N
# 深さ優先探索
def dfs(v, p, value):
#value = value + s[v]
value += s[v]
ans[v] = value
for c in t[v]:
if c == p:
continue
dfs(c, v, value)
dfs(0, -1, 0)
print((*ans))
| # 深さ優先探索の問題
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
N, Q = list(map(int, input().split()))
# 隣接リスト
t = [[] for _ in range(N)]
for _ in range(N-1):
a, b = [int(i) for i in readline().split()]
t[a-1].append(b-1)
t[b-1].append(a-1)
# スコア
score = [0] * N
for _ in range(Q):
p, x = [int(i) for i in readline().split()]
#s[p-1] = s[p-1] + x
score[p-1] += x
ans = [0] * N
# 深さ優先探索 (スタック)
rootchecker = [0] * N
rootchecker[0] = 1
stack = [0]
while stack:
#print(stack)
s = stack.pop()
ans[s] += score[s]
for c in t[s]:
if rootchecker[c] == 0:
ans[c] += ans[s]
rootchecker[c] = 1
stack.append(c)
print((*ans))
| 37 | 39 | 653 | 752 | # 深さ優先探索の問題
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
N, Q = list(map(int, input().split()))
# 隣接リスト
t = [[] for _ in range(N)]
for _ in range(N - 1):
a, b = [int(i) for i in readline().split()]
t[a - 1].append(b - 1)
t[b - 1].append(a - 1)
# スコア
s = [0] * N
for _ in range(Q):
p, x = [int(i) for i in readline().split()]
# s[p-1] = s[p-1] + x
s[p - 1] += x
ans = [0] * N
# 深さ優先探索
def dfs(v, p, value):
# value = value + s[v]
value += s[v]
ans[v] = value
for c in t[v]:
if c == p:
continue
dfs(c, v, value)
dfs(0, -1, 0)
print((*ans))
| # 深さ優先探索の問題
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
N, Q = list(map(int, input().split()))
# 隣接リスト
t = [[] for _ in range(N)]
for _ in range(N - 1):
a, b = [int(i) for i in readline().split()]
t[a - 1].append(b - 1)
t[b - 1].append(a - 1)
# スコア
score = [0] * N
for _ in range(Q):
p, x = [int(i) for i in readline().split()]
# s[p-1] = s[p-1] + x
score[p - 1] += x
ans = [0] * N
# 深さ優先探索 (スタック)
rootchecker = [0] * N
rootchecker[0] = 1
stack = [0]
while stack:
# print(stack)
s = stack.pop()
ans[s] += score[s]
for c in t[s]:
if rootchecker[c] == 0:
ans[c] += ans[s]
rootchecker[c] = 1
stack.append(c)
print((*ans))
| false | 5.128205 | [
"-s = [0] * N",
"+score = [0] * N",
"- s[p - 1] += x",
"+ score[p - 1] += x",
"-# 深さ優先探索",
"-def dfs(v, p, value):",
"- # value = value + s[v]",
"- value += s[v]",
"- ans[v] = value",
"- for c in t[v]:",
"- if c == p:",
"- continue",
"- dfs(c, v, value)",
"-",
"-",
"-dfs(0, -1, 0)",
"+# 深さ優先探索 (スタック)",
"+rootchecker = [0] * N",
"+rootchecker[0] = 1",
"+stack = [0]",
"+while stack:",
"+ # print(stack)",
"+ s = stack.pop()",
"+ ans[s] += score[s]",
"+ for c in t[s]:",
"+ if rootchecker[c] == 0:",
"+ ans[c] += ans[s]",
"+ rootchecker[c] = 1",
"+ stack.append(c)"
]
| false | 0.037349 | 0.036282 | 1.029389 | [
"s266221853",
"s872286135"
]
|
u440566786 | p03329 | python | s322854180 | s880658447 | 636 | 233 | 69,464 | 41,068 | Accepted | Accepted | 63.36 | def nsin(X,n):
if(int(X/n)):
return nsin(int(X/n),n)+str(X%n)
return str(X)
N = int(eval(input()))
score = N
for i in range(N+1):
score = min(score,sum(map(int,nsin(i,6)+nsin(N-i,9))))
print(score) | N = int(eval(input()))
score = N
for i in range(N+1):
count = 0
t = i
while(t):
count += t%6
t//=6
t = N-i
while(t):
count += t%9
t//=9
score = min(count,score)
print(score) | 10 | 16 | 221 | 240 | def nsin(X, n):
if int(X / n):
return nsin(int(X / n), n) + str(X % n)
return str(X)
N = int(eval(input()))
score = N
for i in range(N + 1):
score = min(score, sum(map(int, nsin(i, 6) + nsin(N - i, 9))))
print(score)
| N = int(eval(input()))
score = N
for i in range(N + 1):
count = 0
t = i
while t:
count += t % 6
t //= 6
t = N - i
while t:
count += t % 9
t //= 9
score = min(count, score)
print(score)
| false | 37.5 | [
"-def nsin(X, n):",
"- if int(X / n):",
"- return nsin(int(X / n), n) + str(X % n)",
"- return str(X)",
"-",
"-",
"- score = min(score, sum(map(int, nsin(i, 6) + nsin(N - i, 9))))",
"+ count = 0",
"+ t = i",
"+ while t:",
"+ count += t % 6",
"+ t //= 6",
"+ t = N - i",
"+ while t:",
"+ count += t % 9",
"+ t //= 9",
"+ score = min(count, score)"
]
| false | 0.146654 | 0.061597 | 2.380865 | [
"s322854180",
"s880658447"
]
|
u022215787 | p03971 | python | s900242367 | s550592751 | 99 | 71 | 4,016 | 9,680 | Accepted | Accepted | 28.28 | n, a, b = list(map(int, input().split()))
s_l = eval(input())
ca = 0
cb = 0
for s in s_l:
if s == 'a' and ca + cb < a+b:
ca += 1
print('Yes')
elif s == 'b' and ca + cb < a+b and cb < b:
cb += 1
print('Yes')
else:
print('No') | n, a, b = list(map(int, input().split()))
s = eval(input())
jap_c = 0
ab_c = 0
for i in list(s):
if i == 'a':
if jap_c + ab_c < a+b:
jap_c += 1
print('Yes')
continue
if i == 'b':
if jap_c + ab_c < a+b:
if ab_c < b:
ab_c += 1
print('Yes')
continue
print('No') | 13 | 17 | 251 | 386 | n, a, b = list(map(int, input().split()))
s_l = eval(input())
ca = 0
cb = 0
for s in s_l:
if s == "a" and ca + cb < a + b:
ca += 1
print("Yes")
elif s == "b" and ca + cb < a + b and cb < b:
cb += 1
print("Yes")
else:
print("No")
| n, a, b = list(map(int, input().split()))
s = eval(input())
jap_c = 0
ab_c = 0
for i in list(s):
if i == "a":
if jap_c + ab_c < a + b:
jap_c += 1
print("Yes")
continue
if i == "b":
if jap_c + ab_c < a + b:
if ab_c < b:
ab_c += 1
print("Yes")
continue
print("No")
| false | 23.529412 | [
"-s_l = eval(input())",
"-ca = 0",
"-cb = 0",
"-for s in s_l:",
"- if s == \"a\" and ca + cb < a + b:",
"- ca += 1",
"- print(\"Yes\")",
"- elif s == \"b\" and ca + cb < a + b and cb < b:",
"- cb += 1",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"+s = eval(input())",
"+jap_c = 0",
"+ab_c = 0",
"+for i in list(s):",
"+ if i == \"a\":",
"+ if jap_c + ab_c < a + b:",
"+ jap_c += 1",
"+ print(\"Yes\")",
"+ continue",
"+ if i == \"b\":",
"+ if jap_c + ab_c < a + b:",
"+ if ab_c < b:",
"+ ab_c += 1",
"+ print(\"Yes\")",
"+ continue",
"+ print(\"No\")"
]
| false | 0.036826 | 0.035562 | 1.03555 | [
"s900242367",
"s550592751"
]
|
u717993780 | p03556 | python | s886269002 | s805739668 | 55 | 27 | 2,940 | 2,940 | Accepted | Accepted | 50.91 | import math
n = int(eval(input()))
for i in reversed(list(range(n+1))):
if math.sqrt(i) - math.floor(math.sqrt(i)) == 0:
print(i)
exit() | n = int(eval(input()))
for i in range(n+2):
if i**2 > n:
print(((i-1)**2))
exit() | 6 | 5 | 139 | 87 | import math
n = int(eval(input()))
for i in reversed(list(range(n + 1))):
if math.sqrt(i) - math.floor(math.sqrt(i)) == 0:
print(i)
exit()
| n = int(eval(input()))
for i in range(n + 2):
if i**2 > n:
print(((i - 1) ** 2))
exit()
| false | 16.666667 | [
"-import math",
"-",
"-for i in reversed(list(range(n + 1))):",
"- if math.sqrt(i) - math.floor(math.sqrt(i)) == 0:",
"- print(i)",
"+for i in range(n + 2):",
"+ if i**2 > n:",
"+ print(((i - 1) ** 2))"
]
| false | 0.05578 | 0.083668 | 0.666684 | [
"s886269002",
"s805739668"
]
|
u926412290 | p03167 | python | s936545985 | s013260996 | 167 | 97 | 86,624 | 71,988 | Accepted | Accepted | 41.92 | from collections import deque
MOD = 10**9 + 7
H, W = list(map(int, input().split()))
G = [eval(input()) for _ in range(H)]
def main():
dp = [[0] * W for _ in range(H)]
for i in range(H):
if G[i][0] == '#':
break
dp[i][0] = 1
for i in range(W):
if G[0][i] == '#':
break
dp[0][i] = 1
que = deque([(0, 0)])
while que:
h, w = que.popleft()
for dh, dw in ((1, 0), (0, 1)):
nh = h + dh
nw = w + dw
if nh < 0 or nw < 0 or nh >= H or nw >= W:
continue
if G[nh][nw] == '#':
continue
if nh > 0 and nw > 0:
if dp[nh][nw]:
continue
dp[nh][nw] = (dp[nh - 1][nw] + dp[nh][nw - 1]) % MOD
que.append((nh, nw))
print((dp[H - 1][W - 1]))
if __name__ == "__main__":
main()
| MOD = 10**9 + 7
H, W = list(map(int, input().split()))
G = [eval(input()) for _ in range(H)]
dp = [[0] * W for _ in range(H)]
for i in range(H):
if G[i][0] == '#':
break
dp[i][0] = 1
for i in range(W):
if G[0][i] == '#':
break
dp[0][i] = 1
for i in range(1, H):
for j in range(1, W):
if G[i][j] == '#':
dp[i][j] = 0
else:
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD
print((dp[H - 1][W - 1])) | 40 | 23 | 943 | 482 | from collections import deque
MOD = 10**9 + 7
H, W = list(map(int, input().split()))
G = [eval(input()) for _ in range(H)]
def main():
dp = [[0] * W for _ in range(H)]
for i in range(H):
if G[i][0] == "#":
break
dp[i][0] = 1
for i in range(W):
if G[0][i] == "#":
break
dp[0][i] = 1
que = deque([(0, 0)])
while que:
h, w = que.popleft()
for dh, dw in ((1, 0), (0, 1)):
nh = h + dh
nw = w + dw
if nh < 0 or nw < 0 or nh >= H or nw >= W:
continue
if G[nh][nw] == "#":
continue
if nh > 0 and nw > 0:
if dp[nh][nw]:
continue
dp[nh][nw] = (dp[nh - 1][nw] + dp[nh][nw - 1]) % MOD
que.append((nh, nw))
print((dp[H - 1][W - 1]))
if __name__ == "__main__":
main()
| MOD = 10**9 + 7
H, W = list(map(int, input().split()))
G = [eval(input()) for _ in range(H)]
dp = [[0] * W for _ in range(H)]
for i in range(H):
if G[i][0] == "#":
break
dp[i][0] = 1
for i in range(W):
if G[0][i] == "#":
break
dp[0][i] = 1
for i in range(1, H):
for j in range(1, W):
if G[i][j] == "#":
dp[i][j] = 0
else:
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD
print((dp[H - 1][W - 1]))
| false | 42.5 | [
"-from collections import deque",
"-",
"-",
"-",
"-def main():",
"- dp = [[0] * W for _ in range(H)]",
"- for i in range(H):",
"- if G[i][0] == \"#\":",
"- break",
"- dp[i][0] = 1",
"- for i in range(W):",
"- if G[0][i] == \"#\":",
"- break",
"- dp[0][i] = 1",
"- que = deque([(0, 0)])",
"- while que:",
"- h, w = que.popleft()",
"- for dh, dw in ((1, 0), (0, 1)):",
"- nh = h + dh",
"- nw = w + dw",
"- if nh < 0 or nw < 0 or nh >= H or nw >= W:",
"- continue",
"- if G[nh][nw] == \"#\":",
"- continue",
"- if nh > 0 and nw > 0:",
"- if dp[nh][nw]:",
"- continue",
"- dp[nh][nw] = (dp[nh - 1][nw] + dp[nh][nw - 1]) % MOD",
"- que.append((nh, nw))",
"- print((dp[H - 1][W - 1]))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+dp = [[0] * W for _ in range(H)]",
"+for i in range(H):",
"+ if G[i][0] == \"#\":",
"+ break",
"+ dp[i][0] = 1",
"+for i in range(W):",
"+ if G[0][i] == \"#\":",
"+ break",
"+ dp[0][i] = 1",
"+for i in range(1, H):",
"+ for j in range(1, W):",
"+ if G[i][j] == \"#\":",
"+ dp[i][j] = 0",
"+ else:",
"+ dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD",
"+print((dp[H - 1][W - 1]))"
]
| false | 0.042104 | 0.08075 | 0.521405 | [
"s936545985",
"s013260996"
]
|
u351892848 | p03037 | python | s306442806 | s369535745 | 322 | 199 | 3,060 | 16,620 | Accepted | Accepted | 38.2 | N, M = list(map(int, input().split()))
left = 1
right = N
for i in range(M):
L, R = list(map(int, input().split()))
left = max(left, L)
right = min(right, R)
print((max(right - left + 1, 0))) | N, M = list(map(int, input().split()))
L = [None] * M
R = [None] * M
for i in range(M):
l, r = list(map(int, input().split()))
L[i] = l
R[i] = r
L_max = max(L)
R_min = min(R)
if L_max > R_min:
print((0))
else:
print((R_min - L_max + 1))
| 11 | 17 | 202 | 261 | N, M = list(map(int, input().split()))
left = 1
right = N
for i in range(M):
L, R = list(map(int, input().split()))
left = max(left, L)
right = min(right, R)
print((max(right - left + 1, 0)))
| N, M = list(map(int, input().split()))
L = [None] * M
R = [None] * M
for i in range(M):
l, r = list(map(int, input().split()))
L[i] = l
R[i] = r
L_max = max(L)
R_min = min(R)
if L_max > R_min:
print((0))
else:
print((R_min - L_max + 1))
| false | 35.294118 | [
"-left = 1",
"-right = N",
"+L = [None] * M",
"+R = [None] * M",
"- L, R = list(map(int, input().split()))",
"- left = max(left, L)",
"- right = min(right, R)",
"-print((max(right - left + 1, 0)))",
"+ l, r = list(map(int, input().split()))",
"+ L[i] = l",
"+ R[i] = r",
"+L_max = max(L)",
"+R_min = min(R)",
"+if L_max > R_min:",
"+ print((0))",
"+else:",
"+ print((R_min - L_max + 1))"
]
| false | 0.118536 | 0.074997 | 1.580545 | [
"s306442806",
"s369535745"
]
|
u276115223 | p03970 | python | s062142051 | s086850537 | 20 | 17 | 3,060 | 2,940 | Accepted | Accepted | 15 | # CODE FESTIVAL 2016 予選 B: A – Signboard
s = eval(input())
s_correct = 'CODEFESTIVAL2016'
iterations = 0
for i in range(len(s)):
if s[i] != s_correct[i]:
iterations += 1
print(iterations) | # CODE FESTIVAL 2016 予選 B: A – Signboard
expects = 'CODEFESTIVAL2016'
s = eval(input())
count = 0
for a, b in zip(expects, s):
if a != b:
count += 1
print(count) | 11 | 11 | 206 | 180 | # CODE FESTIVAL 2016 予選 B: A – Signboard
s = eval(input())
s_correct = "CODEFESTIVAL2016"
iterations = 0
for i in range(len(s)):
if s[i] != s_correct[i]:
iterations += 1
print(iterations)
| # CODE FESTIVAL 2016 予選 B: A – Signboard
expects = "CODEFESTIVAL2016"
s = eval(input())
count = 0
for a, b in zip(expects, s):
if a != b:
count += 1
print(count)
| false | 0 | [
"+expects = \"CODEFESTIVAL2016\"",
"-s_correct = \"CODEFESTIVAL2016\"",
"-iterations = 0",
"-for i in range(len(s)):",
"- if s[i] != s_correct[i]:",
"- iterations += 1",
"-print(iterations)",
"+count = 0",
"+for a, b in zip(expects, s):",
"+ if a != b:",
"+ count += 1",
"+print(count)"
]
| false | 0.047814 | 0.047576 | 1.005002 | [
"s062142051",
"s086850537"
]
|
u875291233 | p03608 | python | s540647052 | s933046782 | 551 | 428 | 66,904 | 56,408 | Accepted | Accepted | 22.32 | # coding: utf-8
# Your code here!
from heapq import heappush, heappop
def dijkstra(g,start): #g: 隣接リスト
inf = float("inf")
dist = [inf]*(len(g))
q = [(start,0)] #(点、そこまでの距離)
dist[start] = 0
while q:
v,c = heappop(q)
if dist[v] < c: continue
for to, cost in g[v]:
if dist[v] + cost < dist[to]:
dist[to] = dist[v] + cost
heappush(q, (to, dist[to]))
return dist
n,m,R = [int(i) for i in input().split()]
r = [int(i)-1 for i in input().split()]
inf = 10**9
g = [[] for _ in range(n)]
for _ in range(m):
a,b,c = [int(i) for i in input().split()]
g[a-1].append((b-1, c))
g[b-1].append((a-1, c))
dvec = [None]*R
for i, ri in enumerate(r):
dvec[i] = dijkstra(g, ri)
m = {ri:i for i, ri in enumerate(r)}
ans = inf
import itertools
for x in itertools.permutations(r):
c = 0
for i, xi in enumerate(x):
if i > 0:
c += dvec[m[xi]][x[i-1]]
if c < ans:
ans = c
print(ans)
| # coding: utf-8
# Your code here!
"""
Dijkstra法: 単一始点最短路(距離が正)
g: g[i] = [(子、距離),...]の隣接リスト
start: 始点
"""
from heapq import heappush, heappop
def dijkstra(g,start): #g: 隣接リスト
dist = [1e18]*(len(g)) #初期化
q = [(0,start)] #(そこまでの距離、点)
dist[start] = 0
pending = len(g)-1
while q and pending:
c,v = heappop(q)
if dist[v] < c: continue
pending -= 1
for to, cost in g[v]:
if dist[v] + cost < dist[to]:
dist[to] = dist[v] + cost
heappush(q, (dist[to], to))
return dist
n,m,R = [int(i) for i in input().split()]
r = [int(i)-1 for i in input().split()]
inf = 10**9
g = [[] for _ in range(n)]
for _ in range(m):
a,b,c = [int(i) for i in input().split()]
g[a-1].append((b-1, c))
g[b-1].append((a-1, c))
dvec = [None]*R
for i, ri in enumerate(r):
dvec[i] = dijkstra(g, ri)
m = {ri:i for i, ri in enumerate(r)}
ans = inf
import itertools
for x in itertools.permutations(r):
c = 0
for i, xi in enumerate(x):
if i > 0:
c += dvec[m[xi]][x[i-1]]
if c < ans:
ans = c
print(ans)
| 59 | 66 | 1,099 | 1,218 | # coding: utf-8
# Your code here!
from heapq import heappush, heappop
def dijkstra(g, start): # g: 隣接リスト
inf = float("inf")
dist = [inf] * (len(g))
q = [(start, 0)] # (点、そこまでの距離)
dist[start] = 0
while q:
v, c = heappop(q)
if dist[v] < c:
continue
for to, cost in g[v]:
if dist[v] + cost < dist[to]:
dist[to] = dist[v] + cost
heappush(q, (to, dist[to]))
return dist
n, m, R = [int(i) for i in input().split()]
r = [int(i) - 1 for i in input().split()]
inf = 10**9
g = [[] for _ in range(n)]
for _ in range(m):
a, b, c = [int(i) for i in input().split()]
g[a - 1].append((b - 1, c))
g[b - 1].append((a - 1, c))
dvec = [None] * R
for i, ri in enumerate(r):
dvec[i] = dijkstra(g, ri)
m = {ri: i for i, ri in enumerate(r)}
ans = inf
import itertools
for x in itertools.permutations(r):
c = 0
for i, xi in enumerate(x):
if i > 0:
c += dvec[m[xi]][x[i - 1]]
if c < ans:
ans = c
print(ans)
| # coding: utf-8
# Your code here!
"""
Dijkstra法: 単一始点最短路(距離が正)
g: g[i] = [(子、距離),...]の隣接リスト
start: 始点
"""
from heapq import heappush, heappop
def dijkstra(g, start): # g: 隣接リスト
dist = [1e18] * (len(g)) # 初期化
q = [(0, start)] # (そこまでの距離、点)
dist[start] = 0
pending = len(g) - 1
while q and pending:
c, v = heappop(q)
if dist[v] < c:
continue
pending -= 1
for to, cost in g[v]:
if dist[v] + cost < dist[to]:
dist[to] = dist[v] + cost
heappush(q, (dist[to], to))
return dist
n, m, R = [int(i) for i in input().split()]
r = [int(i) - 1 for i in input().split()]
inf = 10**9
g = [[] for _ in range(n)]
for _ in range(m):
a, b, c = [int(i) for i in input().split()]
g[a - 1].append((b - 1, c))
g[b - 1].append((a - 1, c))
dvec = [None] * R
for i, ri in enumerate(r):
dvec[i] = dijkstra(g, ri)
m = {ri: i for i, ri in enumerate(r)}
ans = inf
import itertools
for x in itertools.permutations(r):
c = 0
for i, xi in enumerate(x):
if i > 0:
c += dvec[m[xi]][x[i - 1]]
if c < ans:
ans = c
print(ans)
| false | 10.606061 | [
"+\"\"\"",
"+Dijkstra法: 単一始点最短路(距離が正)",
"+g: g[i] = [(子、距離),...]の隣接リスト",
"+start: 始点",
"+\"\"\"",
"- inf = float(\"inf\")",
"- dist = [inf] * (len(g))",
"- q = [(start, 0)] # (点、そこまでの距離)",
"+ dist = [1e18] * (len(g)) # 初期化",
"+ q = [(0, start)] # (そこまでの距離、点)",
"- while q:",
"- v, c = heappop(q)",
"+ pending = len(g) - 1",
"+ while q and pending:",
"+ c, v = heappop(q)",
"+ pending -= 1",
"- heappush(q, (to, dist[to]))",
"+ heappush(q, (dist[to], to))"
]
| false | 0.007754 | 0.032872 | 0.235888 | [
"s540647052",
"s933046782"
]
|
u042802884 | p02863 | python | s673089105 | s186685662 | 1,267 | 589 | 197,252 | 123,864 | Accepted | Accepted | 53.51 | N,T=list(map(int,input().split()))
x=[None] # x[0]
for i in range(1,N+1): # x[i]のiに対応させる
x.append(tuple(map(int,input().split()))) # x[1]~x[N]
# print(x) #DB★
dp1=[[0 for j in range(T)] for i in range(N+2)] # 0~N+1 dp1[i]はx[1]からx[i]まで使用(dp1[0]は使用するx[i]なしの初期値,dp1[N+1]は余り→0で初期化していることが後で役に立つ)
for i in range(1,N+1): # dp1[0]は初期値なのでいじらない。dp1[N+1]は余りなので計算しない。dp1[N]まで計算するので,iはNまで
for j in range(T): # 0分後からT-1分後まで計算する
if x[i][0]>j:
dp1[i][j]=dp1[i-1][j]
else:
dp1[i][j]=max(dp1[i-1][j],dp1[i-1][j-x[i][0]]+x[i][1])
# print(dp1) #DB★
dp2=[[0 for j in range(T)] for i in range(N+2)] # 0~N+1 dp2[i]はx[i]からx[N]まで(x[N]からx[i]まで)使用(dp2[N+1]は使用するx[i]なしの初期値,dp2[0]は余り)
for i in range(N,0,-1): # dp2[N+1]は初期値なのでいじらない。dp2[0]は余りなので計算しない。dp2[1]まで計算するので,iは1まで
for j in range(T):
if x[i][0]>j:
dp2[i][j]=dp2[i+1][j]
else:
dp2[i][j]=max(dp2[i+1][j],dp2[i+1][j-x[i][0]]+x[i][1])
# print(dp2) #DB★
cans=[0 for i in range(N+1)] # i番目の料理を最後に食べる場合の満足度の最大値
for i in range(1,N+1):
cans[i]=max([dp1[i-1][j]+dp2[i+1][T-1-j] for j in range(T)])+x[i][1]
# print(cans) #DB★
ans=max(cans)
print(ans) | N,T=list(map(int,input().split()))
x=[(0,0)] # x[0]
for i in range(1,N+1): # x[i]のiに対応させる
x.append(tuple(map(int,input().split()))) # x[1]~x[N]
x.sort()
# print(x) #DB★
dp1=[[0 for j in range(T)] for i in range(N+2)] # 0~N+1 dp1[i]はx[1]からx[i]まで使用(dp1[0]は使用するx[i]なしの初期値,dp1[N+1]は余り→0で初期化していることが後で役に立つ)
for i in range(1,N+1): # dp1[0]は初期値なのでいじらない。dp1[N+1]は余りなので計算しない。dp1[N]まで計算するので,iはNまで
for j in range(T): # 0分後からT-1分後まで計算する
if x[i][0]>j:
dp1[i][j]=dp1[i-1][j]
else:
dp1[i][j]=max(dp1[i-1][j],dp1[i-1][j-x[i][0]]+x[i][1])
cans=[dp1[i-1][T-1]+x[i][1] for i in range(1,N+1)]
# print(cans) #DB★
ans=max(cans)
print(ans) | 35 | 23 | 1,199 | 686 | N, T = list(map(int, input().split()))
x = [None] # x[0]
for i in range(1, N + 1): # x[i]のiに対応させる
x.append(tuple(map(int, input().split()))) # x[1]~x[N]
# print(x) #DB★
dp1 = [
[0 for j in range(T)] for i in range(N + 2)
] # 0~N+1 dp1[i]はx[1]からx[i]まで使用(dp1[0]は使用するx[i]なしの初期値,dp1[N+1]は余り→0で初期化していることが後で役に立つ)
for i in range(1, N + 1): # dp1[0]は初期値なのでいじらない。dp1[N+1]は余りなので計算しない。dp1[N]まで計算するので,iはNまで
for j in range(T): # 0分後からT-1分後まで計算する
if x[i][0] > j:
dp1[i][j] = dp1[i - 1][j]
else:
dp1[i][j] = max(dp1[i - 1][j], dp1[i - 1][j - x[i][0]] + x[i][1])
# print(dp1) #DB★
dp2 = [
[0 for j in range(T)] for i in range(N + 2)
] # 0~N+1 dp2[i]はx[i]からx[N]まで(x[N]からx[i]まで)使用(dp2[N+1]は使用するx[i]なしの初期値,dp2[0]は余り)
for i in range(N, 0, -1): # dp2[N+1]は初期値なのでいじらない。dp2[0]は余りなので計算しない。dp2[1]まで計算するので,iは1まで
for j in range(T):
if x[i][0] > j:
dp2[i][j] = dp2[i + 1][j]
else:
dp2[i][j] = max(dp2[i + 1][j], dp2[i + 1][j - x[i][0]] + x[i][1])
# print(dp2) #DB★
cans = [0 for i in range(N + 1)] # i番目の料理を最後に食べる場合の満足度の最大値
for i in range(1, N + 1):
cans[i] = max([dp1[i - 1][j] + dp2[i + 1][T - 1 - j] for j in range(T)]) + x[i][1]
# print(cans) #DB★
ans = max(cans)
print(ans)
| N, T = list(map(int, input().split()))
x = [(0, 0)] # x[0]
for i in range(1, N + 1): # x[i]のiに対応させる
x.append(tuple(map(int, input().split()))) # x[1]~x[N]
x.sort()
# print(x) #DB★
dp1 = [
[0 for j in range(T)] for i in range(N + 2)
] # 0~N+1 dp1[i]はx[1]からx[i]まで使用(dp1[0]は使用するx[i]なしの初期値,dp1[N+1]は余り→0で初期化していることが後で役に立つ)
for i in range(1, N + 1): # dp1[0]は初期値なのでいじらない。dp1[N+1]は余りなので計算しない。dp1[N]まで計算するので,iはNまで
for j in range(T): # 0分後からT-1分後まで計算する
if x[i][0] > j:
dp1[i][j] = dp1[i - 1][j]
else:
dp1[i][j] = max(dp1[i - 1][j], dp1[i - 1][j - x[i][0]] + x[i][1])
cans = [dp1[i - 1][T - 1] + x[i][1] for i in range(1, N + 1)]
# print(cans) #DB★
ans = max(cans)
print(ans)
| false | 34.285714 | [
"-x = [None] # x[0]",
"+x = [(0, 0)] # x[0]",
"+x.sort()",
"-# print(dp1) #DB★",
"-dp2 = [",
"- [0 for j in range(T)] for i in range(N + 2)",
"-] # 0~N+1 dp2[i]はx[i]からx[N]まで(x[N]からx[i]まで)使用(dp2[N+1]は使用するx[i]なしの初期値,dp2[0]は余り)",
"-for i in range(N, 0, -1): # dp2[N+1]は初期値なのでいじらない。dp2[0]は余りなので計算しない。dp2[1]まで計算するので,iは1まで",
"- for j in range(T):",
"- if x[i][0] > j:",
"- dp2[i][j] = dp2[i + 1][j]",
"- else:",
"- dp2[i][j] = max(dp2[i + 1][j], dp2[i + 1][j - x[i][0]] + x[i][1])",
"-# print(dp2) #DB★",
"-cans = [0 for i in range(N + 1)] # i番目の料理を最後に食べる場合の満足度の最大値",
"-for i in range(1, N + 1):",
"- cans[i] = max([dp1[i - 1][j] + dp2[i + 1][T - 1 - j] for j in range(T)]) + x[i][1]",
"+cans = [dp1[i - 1][T - 1] + x[i][1] for i in range(1, N + 1)]"
]
| false | 0.036634 | 0.082306 | 0.445094 | [
"s673089105",
"s186685662"
]
|
u191829404 | p03329 | python | s908277606 | s821803339 | 249 | 221 | 47,472 | 47,344 | Accepted | Accepted | 11.24 | # https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde s=input() s='abcde'
# abcde s=list(input()) s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ) a=int(input()) a=5
# 1 2 | x,y = s_inpl() | x=1,y=2
# 1 2 3 4 5 ... n li = input().split() li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n li = inpl() li=[1,2,3,4,5,...,n]
# FFFTFTTFF li = input().split('T') li=['FFF', 'F', '', 'FF']
# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]
import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき,A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
def i_inpl(): return int(eval(input()))
def s_inpl(): return list(map(int,input().split()))
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")
N = i_inpl()
dp = [INF for _ in range(N+1)]
dp[0] = 0
for i in range(1, N+1):
# 6
power = 1
while power <= N:
dp[i] = min(dp[i], dp[i-power] + 1)
power *= 6
# 9
power = 1
while power <= N:
dp[i] = min(dp[i], dp[i-power] + 1)
power *= 9
print((dp[N])) | # https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde s=input() s='abcde'
# abcde s=list(input()) s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ) a=int(input()) a=5
# 1 2 | x,y = s_inpl() | x=1,y=2
# 1 2 3 4 5 ... n li = input().split() li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n li = inpl() li=[1,2,3,4,5,...,n]
# FFFTFTTFF li = input().split('T') li=['FFF', 'F', '', 'FF']
# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]
import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき,A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
def i_inpl(): return int(eval(input()))
def s_inpl(): return list(map(int,input().split()))
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")
N = i_inpl()
dp = [INF for _ in range(N+1)]
dp[0] = 0
for i in range(1, N+1):
# 6
power = 1
while power <= i:
dp[i] = min(dp[i], dp[i-power] + 1)
power *= 6
# 9
power = 1
while power <= i:
dp[i] = min(dp[i], dp[i-power] + 1)
power *= 9
print((dp[N])) | 53 | 53 | 1,436 | 1,436 | # https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde s=input() s='abcde'
# abcde s=list(input()) s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ) a=int(input()) a=5
# 1 2 | x,y = s_inpl() | x=1,y=2
# 1 2 3 4 5 ... n li = input().split() li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n li = inpl() li=[1,2,3,4,5,...,n]
# FFFTFTTFF li = input().split('T') li=['FFF', 'F', '', 'FF']
# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]
import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき,A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
def i_inpl():
return int(eval(input()))
def s_inpl():
return list(map(int, input().split()))
def l_inpl():
return list(map(int, input().split()))
INF = float("inf")
N = i_inpl()
dp = [INF for _ in range(N + 1)]
dp[0] = 0
for i in range(1, N + 1):
# 6
power = 1
while power <= N:
dp[i] = min(dp[i], dp[i - power] + 1)
power *= 6
# 9
power = 1
while power <= N:
dp[i] = min(dp[i], dp[i - power] + 1)
power *= 9
print((dp[N]))
| # https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde s=input() s='abcde'
# abcde s=list(input()) s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ) a=int(input()) a=5
# 1 2 | x,y = s_inpl() | x=1,y=2
# 1 2 3 4 5 ... n li = input().split() li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n li = inpl() li=[1,2,3,4,5,...,n]
# FFFTFTTFF li = input().split('T') li=['FFF', 'F', '', 'FF']
# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]
import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき,A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
def i_inpl():
return int(eval(input()))
def s_inpl():
return list(map(int, input().split()))
def l_inpl():
return list(map(int, input().split()))
INF = float("inf")
N = i_inpl()
dp = [INF for _ in range(N + 1)]
dp[0] = 0
for i in range(1, N + 1):
# 6
power = 1
while power <= i:
dp[i] = min(dp[i], dp[i - power] + 1)
power *= 6
# 9
power = 1
while power <= i:
dp[i] = min(dp[i], dp[i - power] + 1)
power *= 9
print((dp[N]))
| false | 0 | [
"- while power <= N:",
"+ while power <= i:",
"- while power <= N:",
"+ while power <= i:"
]
| false | 0.181483 | 0.00621 | 29.223529 | [
"s908277606",
"s821803339"
]
|
u411203878 | p03038 | python | s769689022 | s077884883 | 782 | 400 | 91,288 | 100,776 | Accepted | Accepted | 48.85 | n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = []
for _ in range(m):
b, c = (int(x) for x in input().split())
bc.append([b,c])
bc = sorted(bc, key=lambda x: -x[1])
memo = []
limit = 0
for i in range(m):
a += [bc[i][1]]*bc[i][0]
limit += bc[i][0]
if limit >= n:
break
a.sort(reverse=True)
print((sum(a[:n]))) | import heapq
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = []
for _ in range(m):
b, c = (int(x) for x in input().split())
bc.append([b, c])
bc = sorted(bc, key=lambda x: -x[1])
heapq.heapify(a)
for i in range(m):
count = 0
if bc[i][1] < a[0]:
break
while a[0] < bc[i][1] and count < bc[i][0]:
heapq.heappop(a)
heapq.heappush(a,bc[i][1])
count += 1
print((sum(a))) | 24 | 22 | 388 | 463 | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = []
for _ in range(m):
b, c = (int(x) for x in input().split())
bc.append([b, c])
bc = sorted(bc, key=lambda x: -x[1])
memo = []
limit = 0
for i in range(m):
a += [bc[i][1]] * bc[i][0]
limit += bc[i][0]
if limit >= n:
break
a.sort(reverse=True)
print((sum(a[:n])))
| import heapq
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = []
for _ in range(m):
b, c = (int(x) for x in input().split())
bc.append([b, c])
bc = sorted(bc, key=lambda x: -x[1])
heapq.heapify(a)
for i in range(m):
count = 0
if bc[i][1] < a[0]:
break
while a[0] < bc[i][1] and count < bc[i][0]:
heapq.heappop(a)
heapq.heappush(a, bc[i][1])
count += 1
print((sum(a)))
| false | 8.333333 | [
"+import heapq",
"+",
"-memo = []",
"-limit = 0",
"+heapq.heapify(a)",
"- a += [bc[i][1]] * bc[i][0]",
"- limit += bc[i][0]",
"- if limit >= n:",
"+ count = 0",
"+ if bc[i][1] < a[0]:",
"-a.sort(reverse=True)",
"-print((sum(a[:n])))",
"+ while a[0] < bc[i][1] and count < bc[i][0]:",
"+ heapq.heappop(a)",
"+ heapq.heappush(a, bc[i][1])",
"+ count += 1",
"+print((sum(a)))"
]
| false | 0.073519 | 0.074688 | 0.984349 | [
"s769689022",
"s077884883"
]
|
u996731299 | p02761 | python | s862454843 | s004135139 | 21 | 17 | 3,064 | 3,064 | Accepted | Accepted | 19.05 | N,M=list(map(int,input().split()))
if M!=0:
a=[list(map(int,input().split())) for i in range(M)]
ans=0
for i in range(M):
if ans==-1:
break
for j in range(M):
if a[i][0]==a[j][0] and a[i][1]!=a[j][1]:
ans=-1
break
#print(ans)####
answer=[0]*N
answer[0]=1
for i in range(M):
answer[a[i][0]-1]=a[i][1]
if answer[0]==0 and N>=2:
ans=-1
#print(answer)######
if ans==-1:
print(ans)
elif answer[0]==0 and N==1:
print("0")
else:
ans=0
for i in range(N):
ans+=answer[i]*(10**(N-i-1))
print(ans)
else:
if N!=1:
print((10**(N-1)))
else:
print("0") | N,M=list(map(int,input().split()))
num=[list(map(int,input().split())) for i in range(M)]
ans=[-1]*N
check=True
for i in range(M):
if ans[num[i][0]-1]==-1:
ans[num[i][0]-1]=num[i][1]
elif ans[num[i][0]-1]!=num[i][1]:
check=False
break
if ans[0]==-1 and N>1:
ans[0]=1
elif ans[0]==-1 and N==1:
ans[0]=0
elif ans[0]==0 and N>1:
check=False
for i in range(N):
if ans[i]==-1:
ans[i]=0
if check==False:
print("-1")
else:
answer=0
for i in range(N):
answer+=ans[i]*(10**(N-i-1))
print(answer)
| 34 | 27 | 777 | 588 | N, M = list(map(int, input().split()))
if M != 0:
a = [list(map(int, input().split())) for i in range(M)]
ans = 0
for i in range(M):
if ans == -1:
break
for j in range(M):
if a[i][0] == a[j][0] and a[i][1] != a[j][1]:
ans = -1
break
# print(ans)####
answer = [0] * N
answer[0] = 1
for i in range(M):
answer[a[i][0] - 1] = a[i][1]
if answer[0] == 0 and N >= 2:
ans = -1
# print(answer)######
if ans == -1:
print(ans)
elif answer[0] == 0 and N == 1:
print("0")
else:
ans = 0
for i in range(N):
ans += answer[i] * (10 ** (N - i - 1))
print(ans)
else:
if N != 1:
print((10 ** (N - 1)))
else:
print("0")
| N, M = list(map(int, input().split()))
num = [list(map(int, input().split())) for i in range(M)]
ans = [-1] * N
check = True
for i in range(M):
if ans[num[i][0] - 1] == -1:
ans[num[i][0] - 1] = num[i][1]
elif ans[num[i][0] - 1] != num[i][1]:
check = False
break
if ans[0] == -1 and N > 1:
ans[0] = 1
elif ans[0] == -1 and N == 1:
ans[0] = 0
elif ans[0] == 0 and N > 1:
check = False
for i in range(N):
if ans[i] == -1:
ans[i] = 0
if check == False:
print("-1")
else:
answer = 0
for i in range(N):
answer += ans[i] * (10 ** (N - i - 1))
print(answer)
| false | 20.588235 | [
"-if M != 0:",
"- a = [list(map(int, input().split())) for i in range(M)]",
"- ans = 0",
"- for i in range(M):",
"- if ans == -1:",
"- break",
"- for j in range(M):",
"- if a[i][0] == a[j][0] and a[i][1] != a[j][1]:",
"- ans = -1",
"- break",
"- # print(ans)####",
"- answer = [0] * N",
"- answer[0] = 1",
"- for i in range(M):",
"- answer[a[i][0] - 1] = a[i][1]",
"- if answer[0] == 0 and N >= 2:",
"- ans = -1",
"- # print(answer)######",
"- if ans == -1:",
"- print(ans)",
"- elif answer[0] == 0 and N == 1:",
"- print(\"0\")",
"- else:",
"- ans = 0",
"- for i in range(N):",
"- ans += answer[i] * (10 ** (N - i - 1))",
"- print(ans)",
"+num = [list(map(int, input().split())) for i in range(M)]",
"+ans = [-1] * N",
"+check = True",
"+for i in range(M):",
"+ if ans[num[i][0] - 1] == -1:",
"+ ans[num[i][0] - 1] = num[i][1]",
"+ elif ans[num[i][0] - 1] != num[i][1]:",
"+ check = False",
"+ break",
"+if ans[0] == -1 and N > 1:",
"+ ans[0] = 1",
"+elif ans[0] == -1 and N == 1:",
"+ ans[0] = 0",
"+elif ans[0] == 0 and N > 1:",
"+ check = False",
"+for i in range(N):",
"+ if ans[i] == -1:",
"+ ans[i] = 0",
"+if check == False:",
"+ print(\"-1\")",
"- if N != 1:",
"- print((10 ** (N - 1)))",
"- else:",
"- print(\"0\")",
"+ answer = 0",
"+ for i in range(N):",
"+ answer += ans[i] * (10 ** (N - i - 1))",
"+ print(answer)"
]
| false | 0.082085 | 0.037417 | 2.19378 | [
"s862454843",
"s004135139"
]
|
u193264896 | p03557 | python | s599451316 | s076583619 | 562 | 335 | 118,496 | 21,580 | Accepted | Accepted | 40.39 | from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi
#import numpy as np
import sys
input = sys.stdin.readline
#文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)
def main():
n = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for y in B:
i = bisect_left(A, y)
j = bisect_right(C,y)
if i>0 and j != len(C):
ans += i*(n-j)
print(ans)
if __name__ == '__main__':
main() | import sys
from bisect import bisect_right, bisect_left
from functools import reduce
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def main():
N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))
C = list(map(int, readline().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for i in range(N):
top = bisect_left(A, B[i])
bottom = bisect_right(C, B[i])
if top>0 and bottom != N:
ans += top*(N-bottom)
print(ans)
if __name__ == '__main__':
main() | 34 | 30 | 1,002 | 741 | from collections import deque
from collections import Counter
from itertools import product, permutations, combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
# from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
# from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
# import numpy as np
import sys
input = sys.stdin.readline
# 文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)
def main():
n = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for y in B:
i = bisect_left(A, y)
j = bisect_right(C, y)
if i > 0 and j != len(C):
ans += i * (n - j)
print(ans)
if __name__ == "__main__":
main()
| import sys
from bisect import bisect_right, bisect_left
from functools import reduce
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def main():
N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))
C = list(map(int, readline().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for i in range(N):
top = bisect_left(A, B[i])
bottom = bisect_right(C, B[i])
if top > 0 and bottom != N:
ans += top * (N - bottom)
print(ans)
if __name__ == "__main__":
main()
| false | 11.764706 | [
"-from collections import deque",
"-from collections import Counter",
"-from itertools import product, permutations, combinations",
"-from operator import itemgetter",
"-from heapq import heappop, heappush",
"-from bisect import bisect_left, bisect_right, bisect",
"+import sys",
"+from bisect import bisect_right, bisect_left",
"+from functools import reduce",
"-# from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree",
"-# from scipy.sparse import csr_matrix, coo_matrix, lil_matrix",
"-from fractions import gcd",
"-from math import ceil, floor, sqrt, cos, sin, pi",
"+readline = sys.stdin.buffer.readline",
"+sys.setrecursionlimit(10**8)",
"+INF = float(\"inf\")",
"+MOD = 10**9 + 7",
"-# import numpy as np",
"-import sys",
"-input = sys.stdin.readline",
"-# 文字列のときはうまく行かないのでコメントアウトすること",
"-sys.setrecursionlimit(2147483647)",
"+def lcm_base(x, y):",
"+ return (x * y) // gcd(x, y)",
"+",
"+",
"+def lcm_list(numbers):",
"+ return reduce(lcm_base, numbers, 1)",
"- n = int(eval(input()))",
"- A = list(map(int, input().split()))",
"- B = list(map(int, input().split()))",
"- C = list(map(int, input().split()))",
"+ N = int(readline())",
"+ A = list(map(int, readline().split()))",
"+ B = list(map(int, readline().split()))",
"+ C = list(map(int, readline().split()))",
"- for y in B:",
"- i = bisect_left(A, y)",
"- j = bisect_right(C, y)",
"- if i > 0 and j != len(C):",
"- ans += i * (n - j)",
"+ for i in range(N):",
"+ top = bisect_left(A, B[i])",
"+ bottom = bisect_right(C, B[i])",
"+ if top > 0 and bottom != N:",
"+ ans += top * (N - bottom)"
]
| false | 0.039864 | 0.058602 | 0.680245 | [
"s599451316",
"s076583619"
]
|
u196579381 | p03044 | python | s597475850 | s310693673 | 1,295 | 972 | 105,244 | 101,020 | Accepted | Accepted | 24.94 | import queue
N = int(eval(input()))
alist = [[] for _ in range(N+1)]
d = {}
q = queue.Queue()
for _ in range(N-1):
u, v, w = list(map(int, input().split()))
alist[u].append(v)
alist[v].append(u)
d[(u, v)] = w % 2
q.put(1)
d[(1, 1)] = 0
seen = [False]*(N+1)
seen[1] = True
while not q.empty():
s = q.get()
for n in alist[s]:
if not seen[n]:
q.put(n)
seen[n] = True
d[(1, n)] = (d[1, s]+d[tuple(sorted([s, n]))]) % 2
for i in range(1, N+1):
print((d[(1, i)]))
| import queue
import sys
input = sys.stdin.readline
N = int(eval(input()))
alist = [[] for _ in range(N+1)]
d = {}
q = queue.Queue()
for _ in range(N-1):
u, v, w = list(map(int, input().split()))
alist[u].append(v)
alist[v].append(u)
d[(u, v)] = w
q.put(1)
d[(1, 1)] = 0
seen = [False]*(N+1)
seen[1] = True
while not q.empty():
s = q.get()
for n in alist[s]:
if not seen[n]:
q.put(n)
seen[n] = True
d[(1, n)] = d[1, s]+d[tuple(sorted([s, n]))]
for i in range(1, N+1):
print((d[(1, i)] % 2))
| 27 | 30 | 546 | 582 | import queue
N = int(eval(input()))
alist = [[] for _ in range(N + 1)]
d = {}
q = queue.Queue()
for _ in range(N - 1):
u, v, w = list(map(int, input().split()))
alist[u].append(v)
alist[v].append(u)
d[(u, v)] = w % 2
q.put(1)
d[(1, 1)] = 0
seen = [False] * (N + 1)
seen[1] = True
while not q.empty():
s = q.get()
for n in alist[s]:
if not seen[n]:
q.put(n)
seen[n] = True
d[(1, n)] = (d[1, s] + d[tuple(sorted([s, n]))]) % 2
for i in range(1, N + 1):
print((d[(1, i)]))
| import queue
import sys
input = sys.stdin.readline
N = int(eval(input()))
alist = [[] for _ in range(N + 1)]
d = {}
q = queue.Queue()
for _ in range(N - 1):
u, v, w = list(map(int, input().split()))
alist[u].append(v)
alist[v].append(u)
d[(u, v)] = w
q.put(1)
d[(1, 1)] = 0
seen = [False] * (N + 1)
seen[1] = True
while not q.empty():
s = q.get()
for n in alist[s]:
if not seen[n]:
q.put(n)
seen[n] = True
d[(1, n)] = d[1, s] + d[tuple(sorted([s, n]))]
for i in range(1, N + 1):
print((d[(1, i)] % 2))
| false | 10 | [
"+import sys",
"+input = sys.stdin.readline",
"- d[(u, v)] = w % 2",
"+ d[(u, v)] = w",
"- d[(1, n)] = (d[1, s] + d[tuple(sorted([s, n]))]) % 2",
"+ d[(1, n)] = d[1, s] + d[tuple(sorted([s, n]))]",
"- print((d[(1, i)]))",
"+ print((d[(1, i)] % 2))"
]
| false | 0.073153 | 0.049995 | 1.463208 | [
"s597475850",
"s310693673"
]
|
u608088992 | p03821 | python | s615706375 | s434637723 | 395 | 187 | 21,156 | 21,108 | Accepted | Accepted | 52.66 | N = int(eval(input()))
AB = [[int(i) for i in input().split()] for j in range(N)]
ans = 0
for i in reversed(list(range(N))):
Atemp = AB[i][0] + ans
ans += (0 if Atemp%AB[i][1] == 0 else AB[i][1]-Atemp%AB[i][1])
print(ans) | import sys
def solve():
input = sys.stdin.readline
N = int(eval(input()))
array = [[int(a) for a in input().split()] for _ in range(N)]
count = 0
for i in reversed(list(range(N))):
a, b = array[i]
if (a + count) % b == 0: continue
else: count += b - ((a + count) % b)
print(count)
return 0
if __name__ == "__main__":
solve() | 8 | 17 | 225 | 388 | N = int(eval(input()))
AB = [[int(i) for i in input().split()] for j in range(N)]
ans = 0
for i in reversed(list(range(N))):
Atemp = AB[i][0] + ans
ans += 0 if Atemp % AB[i][1] == 0 else AB[i][1] - Atemp % AB[i][1]
print(ans)
| import sys
def solve():
input = sys.stdin.readline
N = int(eval(input()))
array = [[int(a) for a in input().split()] for _ in range(N)]
count = 0
for i in reversed(list(range(N))):
a, b = array[i]
if (a + count) % b == 0:
continue
else:
count += b - ((a + count) % b)
print(count)
return 0
if __name__ == "__main__":
solve()
| false | 52.941176 | [
"-N = int(eval(input()))",
"-AB = [[int(i) for i in input().split()] for j in range(N)]",
"-ans = 0",
"-for i in reversed(list(range(N))):",
"- Atemp = AB[i][0] + ans",
"- ans += 0 if Atemp % AB[i][1] == 0 else AB[i][1] - Atemp % AB[i][1]",
"-print(ans)",
"+import sys",
"+",
"+",
"+def solve():",
"+ input = sys.stdin.readline",
"+ N = int(eval(input()))",
"+ array = [[int(a) for a in input().split()] for _ in range(N)]",
"+ count = 0",
"+ for i in reversed(list(range(N))):",
"+ a, b = array[i]",
"+ if (a + count) % b == 0:",
"+ continue",
"+ else:",
"+ count += b - ((a + count) % b)",
"+ print(count)",
"+ return 0",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
]
| false | 0.077993 | 0.044687 | 1.745306 | [
"s615706375",
"s434637723"
]
|
u214561383 | p02899 | python | s704380298 | s401354803 | 169 | 86 | 13,880 | 18,372 | Accepted | Accepted | 49.11 | n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
i = 1
for j in a:
ans[j-1] = i
i += 1
for i in ans:
print(i, end=" ")
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = [0] * n
i = 1
for j in a:
ans[j-1] = i
i += 1
print((' '.join(map(str, ans)))) | 9 | 8 | 156 | 150 | n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
i = 1
for j in a:
ans[j - 1] = i
i += 1
for i in ans:
print(i, end=" ")
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = [0] * n
i = 1
for j in a:
ans[j - 1] = i
i += 1
print((" ".join(map(str, ans))))
| false | 11.111111 | [
"-n = int(input())",
"+n = int(eval(input()))",
"-for i in ans:",
"- print(i, end=\" \")",
"+print((\" \".join(map(str, ans))))"
]
| false | 0.035068 | 0.033614 | 1.043239 | [
"s704380298",
"s401354803"
]
|
u600402037 | p02955 | python | s049562396 | s526474210 | 1,094 | 243 | 12,440 | 14,452 | Accepted | Accepted | 77.79 | import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def make_divisors(n): # nの約数を列挙
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort(reverse=True)
return divisors
# 全ての合計の約数が答えの候補、上から可能かどうか見ていく
N, K = lr()
A = np.array(lr())
total = A.sum()
D = make_divisors(total) # 降順
for d in D:
B = A % d
B.sort()
inc = d - B
B_cum = B.cumsum()
inc_cum = inc.cumsum()
for i in range(N):
x = B_cum[i]
y = inc_cum[N-1] - inc_cum[i]
if x > K or y > K:
continue
if (x+y) // 2 <= K:
print(d); exit()
| import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def make_divisors(n): # nの約数を列挙
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort(reverse=True)
return divisors
# 全ての合計の約数が答えの候補、上から可能かどうか見ていく
N, K = lr()
A = np.array(lr())
total = A.sum()
D = make_divisors(total) # 降順
for d in D:
B = A % d
B.sort()
inc = d - B
B_cum = B.cumsum()
inc_cum = inc.cumsum()
for i in range(N):
x = B_cum[i]
y = inc_cum[N-1] - inc_cum[i]
if x > K: # xは単調増加
break
if y > K:
continue
if (x+y) // 2 <= K:
print(d); exit()
| 35 | 37 | 838 | 876 | import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def make_divisors(n): # nの約数を列挙
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort(reverse=True)
return divisors
# 全ての合計の約数が答えの候補、上から可能かどうか見ていく
N, K = lr()
A = np.array(lr())
total = A.sum()
D = make_divisors(total) # 降順
for d in D:
B = A % d
B.sort()
inc = d - B
B_cum = B.cumsum()
inc_cum = inc.cumsum()
for i in range(N):
x = B_cum[i]
y = inc_cum[N - 1] - inc_cum[i]
if x > K or y > K:
continue
if (x + y) // 2 <= K:
print(d)
exit()
| import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def make_divisors(n): # nの約数を列挙
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort(reverse=True)
return divisors
# 全ての合計の約数が答えの候補、上から可能かどうか見ていく
N, K = lr()
A = np.array(lr())
total = A.sum()
D = make_divisors(total) # 降順
for d in D:
B = A % d
B.sort()
inc = d - B
B_cum = B.cumsum()
inc_cum = inc.cumsum()
for i in range(N):
x = B_cum[i]
y = inc_cum[N - 1] - inc_cum[i]
if x > K: # xは単調増加
break
if y > K:
continue
if (x + y) // 2 <= K:
print(d)
exit()
| false | 5.405405 | [
"- if x > K or y > K:",
"+ if x > K: # xは単調増加",
"+ break",
"+ if y > K:"
]
| false | 0.183142 | 0.182921 | 1.001207 | [
"s049562396",
"s526474210"
]
|
u855710796 | p02632 | python | s277619488 | s251934233 | 2,000 | 1,382 | 214,456 | 217,252 | Accepted | Accepted | 30.9 | K = int(eval(input()))
S = eval(input())
mod = 10**9 + 7
class Combination:
def __init__(self, n):
self.facts = [1 for i in range(n+1)]
self.invs = [1 for i in range(n+1)]
for i in range(1, n+1):
self.facts[i] = self.facts[i-1] * i % mod
self.invs[i] = pow(self.facts[i], mod-2, mod)
def ncr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.facts[n] * self.invs[r] * self.invs[n-r] % mod
def nhr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.ncr(n+r-1, n-1)
N = K+len(S)
comb = Combination(K+len(S))
ans = 0
for i in range(K+1):
ans = (ans + comb.ncr(N-i-1, len(S)-1) * pow(25, N-i-len(S), mod) * pow(26, i, mod)) % mod
print(ans) | K = int(eval(input()))
S = eval(input())
mod = 10**9 + 7
class Combination:
def __init__(self, n):
self.facts = [1 for i in range(n+1)]
self.invs = [1 for i in range(n+1)]
for i in range(1, n+1):
self.facts[i] = self.facts[i-1] * i % mod
self.invs[i] = pow(self.facts[i], mod-2, mod)
def ncr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.facts[n] * self.invs[r] * self.invs[n-r] % mod
def nhr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.ncr(n+r-1, n-1)
N = K+len(S)
pow25 = [1] * (N+1)
pow26 = [1] * (N+1)
for i in range(1, N+1):
pow25[i] = (pow25[i-1] * 25) % mod
pow26[i] = (pow26[i-1] * 26) % mod
comb = Combination(K+len(S))
ans = 0
for i in range(K+1):
ans = (ans + comb.ncr(N-i-1, len(S)-1) * pow25[N-i-len(S)] * pow26[i]) % mod
print(ans) | 38 | 44 | 916 | 1,051 | K = int(eval(input()))
S = eval(input())
mod = 10**9 + 7
class Combination:
def __init__(self, n):
self.facts = [1 for i in range(n + 1)]
self.invs = [1 for i in range(n + 1)]
for i in range(1, n + 1):
self.facts[i] = self.facts[i - 1] * i % mod
self.invs[i] = pow(self.facts[i], mod - 2, mod)
def ncr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.facts[n] * self.invs[r] * self.invs[n - r] % mod
def nhr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.ncr(n + r - 1, n - 1)
N = K + len(S)
comb = Combination(K + len(S))
ans = 0
for i in range(K + 1):
ans = (
ans
+ comb.ncr(N - i - 1, len(S) - 1)
* pow(25, N - i - len(S), mod)
* pow(26, i, mod)
) % mod
print(ans)
| K = int(eval(input()))
S = eval(input())
mod = 10**9 + 7
class Combination:
def __init__(self, n):
self.facts = [1 for i in range(n + 1)]
self.invs = [1 for i in range(n + 1)]
for i in range(1, n + 1):
self.facts[i] = self.facts[i - 1] * i % mod
self.invs[i] = pow(self.facts[i], mod - 2, mod)
def ncr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.facts[n] * self.invs[r] * self.invs[n - r] % mod
def nhr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.ncr(n + r - 1, n - 1)
N = K + len(S)
pow25 = [1] * (N + 1)
pow26 = [1] * (N + 1)
for i in range(1, N + 1):
pow25[i] = (pow25[i - 1] * 25) % mod
pow26[i] = (pow26[i - 1] * 26) % mod
comb = Combination(K + len(S))
ans = 0
for i in range(K + 1):
ans = (
ans + comb.ncr(N - i - 1, len(S) - 1) * pow25[N - i - len(S)] * pow26[i]
) % mod
print(ans)
| false | 13.636364 | [
"+pow25 = [1] * (N + 1)",
"+pow26 = [1] * (N + 1)",
"+for i in range(1, N + 1):",
"+ pow25[i] = (pow25[i - 1] * 25) % mod",
"+ pow26[i] = (pow26[i - 1] * 26) % mod",
"- ans",
"- + comb.ncr(N - i - 1, len(S) - 1)",
"- * pow(25, N - i - len(S), mod)",
"- * pow(26, i, mod)",
"+ ans + comb.ncr(N - i - 1, len(S) - 1) * pow25[N - i - len(S)] * pow26[i]"
]
| false | 0.038458 | 0.047301 | 0.813059 | [
"s277619488",
"s251934233"
]
|
u996672406 | p02918 | python | s017141146 | s701839122 | 61 | 42 | 7,840 | 3,316 | Accepted | Accepted | 31.15 | def mapping(string):
return 1 if string == "L" else -1
n, k = list(map(int, input().split()))
s = list(map(mapping, eval(input())))
flips = []
for i in range(n - 1):
if s[i] != s[i + 1]:
flips.append(i + 1)
print((min(n - 1, n - 1 - len(flips) + 2 * k)))
| n, k = list(map(int, input().split()))
s = eval(input())
flips = 0
for i in range(n - 1):
if s[i] != s[i + 1]:
flips += 1
print((min(n - 1, n - 1 - flips + 2 * k)))
| 13 | 9 | 273 | 173 | def mapping(string):
return 1 if string == "L" else -1
n, k = list(map(int, input().split()))
s = list(map(mapping, eval(input())))
flips = []
for i in range(n - 1):
if s[i] != s[i + 1]:
flips.append(i + 1)
print((min(n - 1, n - 1 - len(flips) + 2 * k)))
| n, k = list(map(int, input().split()))
s = eval(input())
flips = 0
for i in range(n - 1):
if s[i] != s[i + 1]:
flips += 1
print((min(n - 1, n - 1 - flips + 2 * k)))
| false | 30.769231 | [
"-def mapping(string):",
"- return 1 if string == \"L\" else -1",
"-",
"-",
"-s = list(map(mapping, eval(input())))",
"-flips = []",
"+s = eval(input())",
"+flips = 0",
"- flips.append(i + 1)",
"-print((min(n - 1, n - 1 - len(flips) + 2 * k)))",
"+ flips += 1",
"+print((min(n - 1, n - 1 - flips + 2 * k)))"
]
| false | 0.103388 | 0.070769 | 1.460917 | [
"s017141146",
"s701839122"
]
|
u218834617 | p03338 | python | s406572412 | s429933314 | 32 | 29 | 9,216 | 9,112 | Accepted | Accepted | 9.38 | from collections import Counter
N=int(eval(input()))
S=eval(input())
ans=0
X=Counter()
Y=Counter(S)
for c in S:
Y[c]-=1
if Y[c]==0:
del X[c]
else:
X[c]+=1
ans=max(ans,len(X))
print(ans)
| N=int(eval(input()))
S=eval(input())
ans=0
for i in range(1,N-1):
a=[0]*26
for j in range(i):
a[ord(S[j])-97]|=1
for j in range(i,N):
a[ord(S[j])-97]|=2
ans=max(ans,a.count(3))
print(ans)
| 18 | 13 | 234 | 222 | from collections import Counter
N = int(eval(input()))
S = eval(input())
ans = 0
X = Counter()
Y = Counter(S)
for c in S:
Y[c] -= 1
if Y[c] == 0:
del X[c]
else:
X[c] += 1
ans = max(ans, len(X))
print(ans)
| N = int(eval(input()))
S = eval(input())
ans = 0
for i in range(1, N - 1):
a = [0] * 26
for j in range(i):
a[ord(S[j]) - 97] |= 1
for j in range(i, N):
a[ord(S[j]) - 97] |= 2
ans = max(ans, a.count(3))
print(ans)
| false | 27.777778 | [
"-from collections import Counter",
"-",
"-X = Counter()",
"-Y = Counter(S)",
"-for c in S:",
"- Y[c] -= 1",
"- if Y[c] == 0:",
"- del X[c]",
"- else:",
"- X[c] += 1",
"- ans = max(ans, len(X))",
"+for i in range(1, N - 1):",
"+ a = [0] * 26",
"+ for j in range(i):",
"+ a[ord(S[j]) - 97] |= 1",
"+ for j in range(i, N):",
"+ a[ord(S[j]) - 97] |= 2",
"+ ans = max(ans, a.count(3))"
]
| false | 0.03984 | 0.0344 | 1.158148 | [
"s406572412",
"s429933314"
]
|
u883048396 | p03309 | python | s337545170 | s816699629 | 324 | 198 | 25,708 | 25,708 | Accepted | Accepted | 38.89 | def 解():
iN = int(eval(input()))
aA = list(map(int,input().split()))
aA = sorted(map(lambda x,y:x-y,aA,list(range(1,iN+1))))
iL = len(aA)
if iL % 2 :
iMed = aA[(iL-1)//2]
else:
iMed = aA[iL//2]
iMean = sum(aA) // 2
iBlim= min(iMed,iMean)
iUlim= min(iMed,iMean+1)
print((min(sum(abs(a-i) for a in aA) for i in [iMed,iMean,iMean+1])))
解()
| def 解():
iN = int(eval(input()))
#aA = map(int,input().split())
aA = sorted(map(lambda x,y:x-y,list(map(int,input().split())),list(range(1,iN+1))))
iL = len(aA)
if iL % 2 :
iMed = aA[(iL-1)//2]
else:
iMed = aA[iL//2]
print((sum(abs(a-iMed) for a in aA)))
解()
| 16 | 12 | 390 | 295 | def 解():
iN = int(eval(input()))
aA = list(map(int, input().split()))
aA = sorted(map(lambda x, y: x - y, aA, list(range(1, iN + 1))))
iL = len(aA)
if iL % 2:
iMed = aA[(iL - 1) // 2]
else:
iMed = aA[iL // 2]
iMean = sum(aA) // 2
iBlim = min(iMed, iMean)
iUlim = min(iMed, iMean + 1)
print((min(sum(abs(a - i) for a in aA) for i in [iMed, iMean, iMean + 1])))
解()
| def 解():
iN = int(eval(input()))
# aA = map(int,input().split())
aA = sorted(
map(lambda x, y: x - y, list(map(int, input().split())), list(range(1, iN + 1)))
)
iL = len(aA)
if iL % 2:
iMed = aA[(iL - 1) // 2]
else:
iMed = aA[iL // 2]
print((sum(abs(a - iMed) for a in aA)))
解()
| false | 25 | [
"- aA = list(map(int, input().split()))",
"- aA = sorted(map(lambda x, y: x - y, aA, list(range(1, iN + 1))))",
"+ # aA = map(int,input().split())",
"+ aA = sorted(",
"+ map(lambda x, y: x - y, list(map(int, input().split())), list(range(1, iN + 1)))",
"+ )",
"- iMean = sum(aA) // 2",
"- iBlim = min(iMed, iMean)",
"- iUlim = min(iMed, iMean + 1)",
"- print((min(sum(abs(a - i) for a in aA) for i in [iMed, iMean, iMean + 1])))",
"+ print((sum(abs(a - iMed) for a in aA)))"
]
| false | 0.042452 | 0.105984 | 0.400554 | [
"s337545170",
"s816699629"
]
|
u252828980 | p02959 | python | s474554897 | s916484348 | 194 | 166 | 18,624 | 19,156 | Accepted | Accepted | 14.43 | n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
num = 0
for i in range(n):
if a[i] >= b[i]:
# print(a[i],b[i])
a[i] -= b[i]
num += b[i]
b[i] = 0
elif a[i] < b[i]:
num += a[i]
#a[i] = 0
b[i] -= a[i]
num += min(b[i],a[i+1])
a[i+1] = max(a[i+1]-b[i],0)
print(num) | n = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
tot = sum(A)
for i in range(n):
en = A[i] + A[i+1]
A[i] = max(A[i] -B[i],0)
if A[i] == 0:
A[i+1] = max(en - B[i],0)
#print(A[i],A[i+1])
print((tot-sum(A))) | 20 | 11 | 416 | 278 | n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
num = 0
for i in range(n):
if a[i] >= b[i]:
# print(a[i],b[i])
a[i] -= b[i]
num += b[i]
b[i] = 0
elif a[i] < b[i]:
num += a[i]
# a[i] = 0
b[i] -= a[i]
num += min(b[i], a[i + 1])
a[i + 1] = max(a[i + 1] - b[i], 0)
print(num)
| n = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
tot = sum(A)
for i in range(n):
en = A[i] + A[i + 1]
A[i] = max(A[i] - B[i], 0)
if A[i] == 0:
A[i + 1] = max(en - B[i], 0)
# print(A[i],A[i+1])
print((tot - sum(A)))
| false | 45 | [
"-a = list(map(int, input().split()))",
"-b = list(map(int, input().split()))",
"-num = 0",
"+A = list(map(int, input().split()))",
"+B = list(map(int, input().split()))",
"+tot = sum(A)",
"- if a[i] >= b[i]:",
"- # print(a[i],b[i])",
"- a[i] -= b[i]",
"- num += b[i]",
"- b[i] = 0",
"- elif a[i] < b[i]:",
"- num += a[i]",
"- # a[i] = 0",
"- b[i] -= a[i]",
"- num += min(b[i], a[i + 1])",
"- a[i + 1] = max(a[i + 1] - b[i], 0)",
"-print(num)",
"+ en = A[i] + A[i + 1]",
"+ A[i] = max(A[i] - B[i], 0)",
"+ if A[i] == 0:",
"+ A[i + 1] = max(en - B[i], 0)",
"+ # print(A[i],A[i+1])",
"+print((tot - sum(A)))"
]
| false | 0.041346 | 0.035119 | 1.177307 | [
"s474554897",
"s916484348"
]
|
u596276291 | p03796 | python | s914466193 | s048556750 | 162 | 36 | 3,700 | 3,316 | Accepted | Accepted | 77.78 | from collections import defaultdict
def main():
N = int(eval(input()))
ans = 1
for i in range(1, N + 1):
ans *= i
ans %= 10 ** 9 + 7
print((ans % (10 ** 9 + 7)))
if __name__ == '__main__':
main()
| from collections import defaultdict
MOD = 10 ** 9 + 7
def main():
N = int(eval(input()))
ans = 1
for i in range(1, N + 1):
ans *= i
ans %= MOD
print((ans % MOD))
if __name__ == '__main__':
main()
| 14 | 15 | 241 | 242 | from collections import defaultdict
def main():
N = int(eval(input()))
ans = 1
for i in range(1, N + 1):
ans *= i
ans %= 10**9 + 7
print((ans % (10**9 + 7)))
if __name__ == "__main__":
main()
| from collections import defaultdict
MOD = 10**9 + 7
def main():
N = int(eval(input()))
ans = 1
for i in range(1, N + 1):
ans *= i
ans %= MOD
print((ans % MOD))
if __name__ == "__main__":
main()
| false | 6.666667 | [
"+",
"+MOD = 10**9 + 7",
"- ans %= 10**9 + 7",
"- print((ans % (10**9 + 7)))",
"+ ans %= MOD",
"+ print((ans % MOD))"
]
| false | 0.047155 | 0.093762 | 0.502926 | [
"s914466193",
"s048556750"
]
|
u545368057 | p03339 | python | s506322678 | s547280235 | 288 | 227 | 20,140 | 29,724 | Accepted | Accepted | 21.18 | """
WEEWW
<>><<
01100
10100
01000
10000
10010
下記の和
1. リーダーより左にいるWの数
2. リーダーより右にいるEの数
"""
N = int(eval(input()))
S = eval(input())
# 1.
cntW = 0
W_num = [0]*N
for i,s in enumerate(S):
if s == "W":
cntW += 1
W_num[i] = cntW
# 2.
cntE = 0
E_num = [0]*N
for i,s in enumerate(S[::-1]):
if s == "E":
cntE +=1
E_num[i] = cntE
E_num = E_num[::-1]
ans = 10**10
for e,w in zip(E_num, W_num):
cnt = e + w - 1
ans = min(cnt, ans)
print(ans) | N = int(eval(input()))
S = eval(input())
cnt_w = [0] * (N+1) # 左からWの数
cnt_e = [0] * (N+1) # 右からEの数
for i in range(N):
if S[i] == "W":
cnt_w[i+1] = cnt_w[i] + 1
else:
cnt_w[i+1] = cnt_w[i]
for i in range(N-1,-1,-1):
if S[i] == "E":
cnt_e[i] = cnt_e[i+1] + 1
else:
cnt_e[i] = cnt_e[i+1]
# print("W",cnt_w)
# print("E",cnt_e)
ans = [w+e for w,e in zip(cnt_w,cnt_e)]
print((min(ans))) | 38 | 20 | 507 | 437 | """
WEEWW
<>><<
01100
10100
01000
10000
10010
下記の和
1. リーダーより左にいるWの数
2. リーダーより右にいるEの数
"""
N = int(eval(input()))
S = eval(input())
# 1.
cntW = 0
W_num = [0] * N
for i, s in enumerate(S):
if s == "W":
cntW += 1
W_num[i] = cntW
# 2.
cntE = 0
E_num = [0] * N
for i, s in enumerate(S[::-1]):
if s == "E":
cntE += 1
E_num[i] = cntE
E_num = E_num[::-1]
ans = 10**10
for e, w in zip(E_num, W_num):
cnt = e + w - 1
ans = min(cnt, ans)
print(ans)
| N = int(eval(input()))
S = eval(input())
cnt_w = [0] * (N + 1) # 左からWの数
cnt_e = [0] * (N + 1) # 右からEの数
for i in range(N):
if S[i] == "W":
cnt_w[i + 1] = cnt_w[i] + 1
else:
cnt_w[i + 1] = cnt_w[i]
for i in range(N - 1, -1, -1):
if S[i] == "E":
cnt_e[i] = cnt_e[i + 1] + 1
else:
cnt_e[i] = cnt_e[i + 1]
# print("W",cnt_w)
# print("E",cnt_e)
ans = [w + e for w, e in zip(cnt_w, cnt_e)]
print((min(ans)))
| false | 47.368421 | [
"-\"\"\"",
"-WEEWW",
"-<>><<",
"-01100",
"-10100",
"-01000",
"-10000",
"-10010",
"-下記の和",
"-1. リーダーより左にいるWの数",
"-2. リーダーより右にいるEの数",
"-\"\"\"",
"-# 1.",
"-cntW = 0",
"-W_num = [0] * N",
"-for i, s in enumerate(S):",
"- if s == \"W\":",
"- cntW += 1",
"- W_num[i] = cntW",
"-# 2.",
"-cntE = 0",
"-E_num = [0] * N",
"-for i, s in enumerate(S[::-1]):",
"- if s == \"E\":",
"- cntE += 1",
"- E_num[i] = cntE",
"-E_num = E_num[::-1]",
"-ans = 10**10",
"-for e, w in zip(E_num, W_num):",
"- cnt = e + w - 1",
"- ans = min(cnt, ans)",
"-print(ans)",
"+cnt_w = [0] * (N + 1) # 左からWの数",
"+cnt_e = [0] * (N + 1) # 右からEの数",
"+for i in range(N):",
"+ if S[i] == \"W\":",
"+ cnt_w[i + 1] = cnt_w[i] + 1",
"+ else:",
"+ cnt_w[i + 1] = cnt_w[i]",
"+for i in range(N - 1, -1, -1):",
"+ if S[i] == \"E\":",
"+ cnt_e[i] = cnt_e[i + 1] + 1",
"+ else:",
"+ cnt_e[i] = cnt_e[i + 1]",
"+# print(\"W\",cnt_w)",
"+# print(\"E\",cnt_e)",
"+ans = [w + e for w, e in zip(cnt_w, cnt_e)]",
"+print((min(ans)))"
]
| false | 0.048499 | 0.045159 | 1.073949 | [
"s506322678",
"s547280235"
]
|
u949338836 | p02401 | python | s165782594 | s052636908 | 40 | 30 | 6,724 | 6,724 | Accepted | Accepted | 25 | #coding:utf-8
#1_4_C 2015.3.29
while True:
data = input().split()
if data[1] == '?':
break
elif data[1] == '+':
print((int(data[0]) + int(data[2])))
elif data[1] == '-':
print((int(data[0]) - int(data[2])))
elif data[1] == '*':
print((int(data[0]) * int(data[2])))
elif data[1] == '/':
print((int(data[0]) // int(data[2]))) | #coding:utf-8
#1_4_C 2015.3.29
while True:
data = eval(input())
if '?' in data:
break
print((eval(data.replace('/','//')))) | 14 | 7 | 392 | 141 | # coding:utf-8
# 1_4_C 2015.3.29
while True:
data = input().split()
if data[1] == "?":
break
elif data[1] == "+":
print((int(data[0]) + int(data[2])))
elif data[1] == "-":
print((int(data[0]) - int(data[2])))
elif data[1] == "*":
print((int(data[0]) * int(data[2])))
elif data[1] == "/":
print((int(data[0]) // int(data[2])))
| # coding:utf-8
# 1_4_C 2015.3.29
while True:
data = eval(input())
if "?" in data:
break
print((eval(data.replace("/", "//"))))
| false | 50 | [
"- data = input().split()",
"- if data[1] == \"?\":",
"+ data = eval(input())",
"+ if \"?\" in data:",
"- elif data[1] == \"+\":",
"- print((int(data[0]) + int(data[2])))",
"- elif data[1] == \"-\":",
"- print((int(data[0]) - int(data[2])))",
"- elif data[1] == \"*\":",
"- print((int(data[0]) * int(data[2])))",
"- elif data[1] == \"/\":",
"- print((int(data[0]) // int(data[2])))",
"+ print((eval(data.replace(\"/\", \"//\"))))"
]
| false | 0.038464 | 0.047075 | 0.817074 | [
"s165782594",
"s052636908"
]
|
u888092736 | p03147 | python | s934631323 | s061438127 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | N = int(eval(input()))
h = list(map(int, input().split()))
board = [[0] * (N + 1) for _ in range(max(h))]
for i in range(N):
for j in range(h[i]):
board[j][i + 1] = 1
print((sum(row[i] == 0 and row[i + 1] == 1 for row in board for i in range(N))))
| eval(input())
ans, tmp = 0, 0
for h in map(int, input().split()):
ans += max(0, h - tmp)
tmp = h
print(ans)
| 7 | 6 | 258 | 115 | N = int(eval(input()))
h = list(map(int, input().split()))
board = [[0] * (N + 1) for _ in range(max(h))]
for i in range(N):
for j in range(h[i]):
board[j][i + 1] = 1
print((sum(row[i] == 0 and row[i + 1] == 1 for row in board for i in range(N))))
| eval(input())
ans, tmp = 0, 0
for h in map(int, input().split()):
ans += max(0, h - tmp)
tmp = h
print(ans)
| false | 14.285714 | [
"-N = int(eval(input()))",
"-h = list(map(int, input().split()))",
"-board = [[0] * (N + 1) for _ in range(max(h))]",
"-for i in range(N):",
"- for j in range(h[i]):",
"- board[j][i + 1] = 1",
"-print((sum(row[i] == 0 and row[i + 1] == 1 for row in board for i in range(N))))",
"+eval(input())",
"+ans, tmp = 0, 0",
"+for h in map(int, input().split()):",
"+ ans += max(0, h - tmp)",
"+ tmp = h",
"+print(ans)"
]
| false | 0.037469 | 0.035228 | 1.063618 | [
"s934631323",
"s061438127"
]
|
u991567869 | p03475 | python | s957510134 | s285203359 | 115 | 94 | 9,152 | 9,148 | Accepted | Accepted | 18.26 | n = int(eval(input()))
l = [[0]*3 for i in range(n)]
for i in range(n - 1):
c, s, f = list(map(int, input().split()))
l[i][0] = c
l[i][1] = s
l[i][2] = f
for i in range(n - 1):
t = 0
for j in range(i, n - 1):
t = max(l[j][1], t)
mod = abs(t - l[j][1])%l[j][2]
if mod != 0:
t += l[j][2] - mod
t += l[j][0]
print(t)
print((0)) | n = int(eval(input()))
l = [list(map(int, input().split())) for i in range(n - 1)]
for i in range(n):
t = 0
for c, s, f in l[i:]:
t = max(s, t)
mod = abs(t - s)%f
if mod != 0:
t += f - mod
t += c
print(t) | 20 | 12 | 404 | 266 | n = int(eval(input()))
l = [[0] * 3 for i in range(n)]
for i in range(n - 1):
c, s, f = list(map(int, input().split()))
l[i][0] = c
l[i][1] = s
l[i][2] = f
for i in range(n - 1):
t = 0
for j in range(i, n - 1):
t = max(l[j][1], t)
mod = abs(t - l[j][1]) % l[j][2]
if mod != 0:
t += l[j][2] - mod
t += l[j][0]
print(t)
print((0))
| n = int(eval(input()))
l = [list(map(int, input().split())) for i in range(n - 1)]
for i in range(n):
t = 0
for c, s, f in l[i:]:
t = max(s, t)
mod = abs(t - s) % f
if mod != 0:
t += f - mod
t += c
print(t)
| false | 40 | [
"-l = [[0] * 3 for i in range(n)]",
"-for i in range(n - 1):",
"- c, s, f = list(map(int, input().split()))",
"- l[i][0] = c",
"- l[i][1] = s",
"- l[i][2] = f",
"-for i in range(n - 1):",
"+l = [list(map(int, input().split())) for i in range(n - 1)]",
"+for i in range(n):",
"- for j in range(i, n - 1):",
"- t = max(l[j][1], t)",
"- mod = abs(t - l[j][1]) % l[j][2]",
"+ for c, s, f in l[i:]:",
"+ t = max(s, t)",
"+ mod = abs(t - s) % f",
"- t += l[j][2] - mod",
"- t += l[j][0]",
"+ t += f - mod",
"+ t += c",
"-print((0))"
]
| false | 0.03754 | 0.039601 | 0.947954 | [
"s957510134",
"s285203359"
]
|
u480138356 | p04006 | python | s910056497 | s987197421 | 1,784 | 1,431 | 3,700 | 14,260 | Accepted | Accepted | 19.79 | import sys
import copy
input = sys.stdin.readline
def main():
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
min_ = copy.deepcopy(a)
ans = int(1e15)
# 魔法を唱える回数 k
for k in range(N):
tmp = k * x
for i in range(N):
min_[i] = min(min_[i], a[(i-k)%N])
tmp += min_[i]
# print(min_)
ans = min(ans, tmp)
print(ans)
if __name__ == "__main__":
main() | import sys
import numpy as np
input = sys.stdin.readline
def main():
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
min_ = np.array(a)
ans = sum(min_)
# 魔法を唱える回数 k
for k in range(1, N):
min_ = np.minimum(min_, np.roll(min_, 1))
ans = min(ans, k * x + sum(min_))
print(ans)
if __name__ == "__main__":
main() | 25 | 21 | 480 | 402 | import sys
import copy
input = sys.stdin.readline
def main():
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
min_ = copy.deepcopy(a)
ans = int(1e15)
# 魔法を唱える回数 k
for k in range(N):
tmp = k * x
for i in range(N):
min_[i] = min(min_[i], a[(i - k) % N])
tmp += min_[i]
# print(min_)
ans = min(ans, tmp)
print(ans)
if __name__ == "__main__":
main()
| import sys
import numpy as np
input = sys.stdin.readline
def main():
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
min_ = np.array(a)
ans = sum(min_)
# 魔法を唱える回数 k
for k in range(1, N):
min_ = np.minimum(min_, np.roll(min_, 1))
ans = min(ans, k * x + sum(min_))
print(ans)
if __name__ == "__main__":
main()
| false | 16 | [
"-import copy",
"+import numpy as np",
"- min_ = copy.deepcopy(a)",
"- ans = int(1e15)",
"+ min_ = np.array(a)",
"+ ans = sum(min_)",
"- for k in range(N):",
"- tmp = k * x",
"- for i in range(N):",
"- min_[i] = min(min_[i], a[(i - k) % N])",
"- tmp += min_[i]",
"- # print(min_)",
"- ans = min(ans, tmp)",
"+ for k in range(1, N):",
"+ min_ = np.minimum(min_, np.roll(min_, 1))",
"+ ans = min(ans, k * x + sum(min_))"
]
| false | 0.050114 | 0.280021 | 0.178966 | [
"s910056497",
"s987197421"
]
|
u810356688 | p03006 | python | s881791216 | s509492382 | 23 | 21 | 3,572 | 3,564 | Accepted | Accepted | 8.7 | import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import combinations
from collections import Counter
def main():
n=int(eval(input()))
if n==1:
print((1))
sys.exit()
XY=[tuple(map(int,input().split())) for i in range(n)]
XY.sort()
lis=list(combinations(XY,2))
PQ=[]
for l in lis:
PQ.append((l[1][0]-l[0][0],l[1][1]-l[0][1]))
x=Counter(PQ).most_common(1)[0][1]
print((n-x))
if __name__=='__main__':
main() | import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import combinations
from collections import Counter
def main():
n=int(eval(input()))
if n==1:
print((1))
sys.exit()
XY=[tuple(map(int,input().split())) for i in range(n)]
XY.sort()
PQ=[]
for i in range(n-1):
x1=XY[i]
for j in range(i+1,n):
x2=XY[j]
PQ.append((x2[0]-x1[0],x2[1]-x1[1]))
print((n-Counter(PQ).most_common(1)[0][1]))
if __name__=='__main__':
main() | 20 | 21 | 504 | 536 | import sys
def input():
return sys.stdin.readline().rstrip()
from itertools import combinations
from collections import Counter
def main():
n = int(eval(input()))
if n == 1:
print((1))
sys.exit()
XY = [tuple(map(int, input().split())) for i in range(n)]
XY.sort()
lis = list(combinations(XY, 2))
PQ = []
for l in lis:
PQ.append((l[1][0] - l[0][0], l[1][1] - l[0][1]))
x = Counter(PQ).most_common(1)[0][1]
print((n - x))
if __name__ == "__main__":
main()
| import sys
def input():
return sys.stdin.readline().rstrip()
from itertools import combinations
from collections import Counter
def main():
n = int(eval(input()))
if n == 1:
print((1))
sys.exit()
XY = [tuple(map(int, input().split())) for i in range(n)]
XY.sort()
PQ = []
for i in range(n - 1):
x1 = XY[i]
for j in range(i + 1, n):
x2 = XY[j]
PQ.append((x2[0] - x1[0], x2[1] - x1[1]))
print((n - Counter(PQ).most_common(1)[0][1]))
if __name__ == "__main__":
main()
| false | 4.761905 | [
"- lis = list(combinations(XY, 2))",
"- for l in lis:",
"- PQ.append((l[1][0] - l[0][0], l[1][1] - l[0][1]))",
"- x = Counter(PQ).most_common(1)[0][1]",
"- print((n - x))",
"+ for i in range(n - 1):",
"+ x1 = XY[i]",
"+ for j in range(i + 1, n):",
"+ x2 = XY[j]",
"+ PQ.append((x2[0] - x1[0], x2[1] - x1[1]))",
"+ print((n - Counter(PQ).most_common(1)[0][1]))"
]
| false | 0.041525 | 0.102077 | 0.406797 | [
"s881791216",
"s509492382"
]
|
u368796742 | p03722 | python | s910824091 | s072861690 | 398 | 346 | 48,744 | 48,104 | Accepted | Accepted | 13.07 | from collections import deque
n,m = list(map(int,input().split()))
e1 = [[] for i in range(n)]
e2 = [[] for i in range(n)]
l = []
for i in range(m):
a,b,c = list(map(int,input().split()))
a -= 1
b -= 1
e1[a].append(b)
e2[b].append(a)
l.append([a,b,c])
def search(x,e):
dis = [0]*n
dis[x] = 1
q = deque([])
q.append(x)
while q:
now = q.popleft()
for nex in e[now]:
if dis[nex] == 0:
dis[nex] = 1
q.append(nex)
return dis
dis1 = search(0,e1)
dis2 = search(n-1,e2)
dis = [0]*n
for i in range(n):
if dis1[i] == 1 and dis2[i] == 1:
dis[i] = 1
li = []
for i in range(m):
a,b,c = l[i]
if dis[a] == 1 and dis[b] == 1:
li.append(l[i])
ans = [-float("INF")]*n
ans[0] = 0
for i in range(2*n):
check = False
for i,j,k in li:
if ans[i]+k > ans[j]:
ans[j] = ans[i]+k
check = True
if not check:
print((ans[-1]))
exit()
print("inf") | from collections import deque
n,m = list(map(int,input().split()))
e1 = [[] for i in range(n)]
e2 = [[] for i in range(n)]
l = []
for i in range(m):
a,b,c = list(map(int,input().split()))
a -= 1
b -= 1
e1[a].append(b)
e2[b].append(a)
l.append([a,b,c])
def search(x,e):
dis = [0]*n
dis[x] = 1
q = deque([])
q.append(x)
while q:
now = q.popleft()
for nex in e[now]:
if dis[nex] == 0:
dis[nex] = 1
q.append(nex)
return dis
dis1 = search(0,e1)
dis2 = search(n-1,e2)
dis = [0]*n
for i in range(n):
if dis1[i] == 1 and dis2[i] == 1:
dis[i] = 1
li = []
for i in range(m):
a,b,c = l[i]
if dis[a] == 1 and dis[b] == 1:
li.append(l[i])
ans = [-float("INF")]*n
ans[0] = 0
for i in range(n):
check = False
for i,j,k in li:
if ans[i]+k > ans[j]:
ans[j] = ans[i]+k
check = True
if not check:
print((ans[-1]))
exit()
print("inf") | 55 | 55 | 1,064 | 1,062 | from collections import deque
n, m = list(map(int, input().split()))
e1 = [[] for i in range(n)]
e2 = [[] for i in range(n)]
l = []
for i in range(m):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
e1[a].append(b)
e2[b].append(a)
l.append([a, b, c])
def search(x, e):
dis = [0] * n
dis[x] = 1
q = deque([])
q.append(x)
while q:
now = q.popleft()
for nex in e[now]:
if dis[nex] == 0:
dis[nex] = 1
q.append(nex)
return dis
dis1 = search(0, e1)
dis2 = search(n - 1, e2)
dis = [0] * n
for i in range(n):
if dis1[i] == 1 and dis2[i] == 1:
dis[i] = 1
li = []
for i in range(m):
a, b, c = l[i]
if dis[a] == 1 and dis[b] == 1:
li.append(l[i])
ans = [-float("INF")] * n
ans[0] = 0
for i in range(2 * n):
check = False
for i, j, k in li:
if ans[i] + k > ans[j]:
ans[j] = ans[i] + k
check = True
if not check:
print((ans[-1]))
exit()
print("inf")
| from collections import deque
n, m = list(map(int, input().split()))
e1 = [[] for i in range(n)]
e2 = [[] for i in range(n)]
l = []
for i in range(m):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
e1[a].append(b)
e2[b].append(a)
l.append([a, b, c])
def search(x, e):
dis = [0] * n
dis[x] = 1
q = deque([])
q.append(x)
while q:
now = q.popleft()
for nex in e[now]:
if dis[nex] == 0:
dis[nex] = 1
q.append(nex)
return dis
dis1 = search(0, e1)
dis2 = search(n - 1, e2)
dis = [0] * n
for i in range(n):
if dis1[i] == 1 and dis2[i] == 1:
dis[i] = 1
li = []
for i in range(m):
a, b, c = l[i]
if dis[a] == 1 and dis[b] == 1:
li.append(l[i])
ans = [-float("INF")] * n
ans[0] = 0
for i in range(n):
check = False
for i, j, k in li:
if ans[i] + k > ans[j]:
ans[j] = ans[i] + k
check = True
if not check:
print((ans[-1]))
exit()
print("inf")
| false | 0 | [
"-for i in range(2 * n):",
"+for i in range(n):"
]
| false | 0.036513 | 0.034916 | 1.045735 | [
"s910824091",
"s072861690"
]
|
u279605379 | p02294 | python | s551984546 | s538343110 | 60 | 40 | 7,860 | 7,864 | Accepted | Accepted | 33.33 | class Line:
def __init__(self,p1,p2):
if p1[1] < p2[1]:self.s=p2;self.e=p1
elif p1[1] > p2[1]:self.s=p1;self.e=p2
else:
if p1[0] < p2[0]:self.s=p1;self.e=p2
else:self.s=p2;self.e=p1
def dot(a,b):return a[0]*b[0] + a[1]*b[1]
def cross(a,b):return a[0]*b[1] - a[1]*b[0]
def dif(a,b):return [x-y for x,y in zip(a,b)]
def InterSection(l,m):
a = dif(l.e,l.s);b = dif(m.e,l.s);c = dif(m.s,l.s)
d = dif(m.e,m.s);e = dif(l.e,m.s);f = dif(l.s,m.s)
g = lambda a, b : cross(a,b)==0 and dot(a,b)>0 and dot(b,b)<dot(a,a)
if g(a,b) or g(a,c) or g(d,e) or g(d,f):return True
elif l.s == m.e or l.s == m.s or l.e == m.e or l.e == m.s:return True
elif cross(a,b) * cross(a,c) >= 0 or cross(d,e) * cross(d,f) >= 0:return False
else:return True
q = int(eval(input()))
for i in range(q):
x0,y0,x1,y1,x2,y2,x3,y3 = [int(i) for i in input().split()]
a = [x0,y0] ; b = [x1,y1] ; c = [x2,y2] ; d = [x3,y3]
l1 = Line(a,b) ; l2 = Line(c,d)
if InterSection(l1,l2):print((1))
else:print((0)) | class Line:
def __init__(self,p1,p2):
if p1[1] < p2[1]:self.s=p2;self.e=p1
elif p1[1] > p2[1]:self.s=p1;self.e=p2
else:
if p1[0] < p2[0]:self.s=p1;self.e=p2
else:self.s=p2;self.e=p1
def dot(a,b):return a[0]*b[0] + a[1]*b[1]
def cross(a,b):return a[0]*b[1] - a[1]*b[0]
def dif(a,b):return [x-y for x,y in zip(a,b)]
def InterSection(l,m):
a = dif(l.e,l.s);b = dif(m.e,l.s);c = dif(m.s,l.s)
d = dif(m.e,m.s);e = dif(l.e,m.s);f = dif(l.s,m.s)
g = lambda a, b : cross(a,b)==0 and dot(a,b)>0 and dot(b,b)<dot(a,a)
if g(a,b) or g(a,c) or g(d,e) or g(d,f):return True
elif l.s == m.e or l.s == m.s or l.e == m.e or l.e == m.s:return True
elif cross(a,b) * cross(a,c) >= 0 or cross(d,e) * cross(d,f) >= 0:return False
else:return True
q = int(eval(input()))
for i in range(q):
x0,y0,x1,y1,x2,y2,x3,y3 = [int(i) for i in input().split()]
a = [x0,y0] ; b = [x1,y1] ; c = [x2,y2] ; d = [x3,y3]
l1 = Line(b,a) ; l2 = Line(d,c)
if InterSection(l1,l2):print((1))
else:print((0)) | 26 | 26 | 1,079 | 1,079 | class Line:
def __init__(self, p1, p2):
if p1[1] < p2[1]:
self.s = p2
self.e = p1
elif p1[1] > p2[1]:
self.s = p1
self.e = p2
else:
if p1[0] < p2[0]:
self.s = p1
self.e = p2
else:
self.s = p2
self.e = p1
def dot(a, b):
return a[0] * b[0] + a[1] * b[1]
def cross(a, b):
return a[0] * b[1] - a[1] * b[0]
def dif(a, b):
return [x - y for x, y in zip(a, b)]
def InterSection(l, m):
a = dif(l.e, l.s)
b = dif(m.e, l.s)
c = dif(m.s, l.s)
d = dif(m.e, m.s)
e = dif(l.e, m.s)
f = dif(l.s, m.s)
g = lambda a, b: cross(a, b) == 0 and dot(a, b) > 0 and dot(b, b) < dot(a, a)
if g(a, b) or g(a, c) or g(d, e) or g(d, f):
return True
elif l.s == m.e or l.s == m.s or l.e == m.e or l.e == m.s:
return True
elif cross(a, b) * cross(a, c) >= 0 or cross(d, e) * cross(d, f) >= 0:
return False
else:
return True
q = int(eval(input()))
for i in range(q):
x0, y0, x1, y1, x2, y2, x3, y3 = [int(i) for i in input().split()]
a = [x0, y0]
b = [x1, y1]
c = [x2, y2]
d = [x3, y3]
l1 = Line(a, b)
l2 = Line(c, d)
if InterSection(l1, l2):
print((1))
else:
print((0))
| class Line:
def __init__(self, p1, p2):
if p1[1] < p2[1]:
self.s = p2
self.e = p1
elif p1[1] > p2[1]:
self.s = p1
self.e = p2
else:
if p1[0] < p2[0]:
self.s = p1
self.e = p2
else:
self.s = p2
self.e = p1
def dot(a, b):
return a[0] * b[0] + a[1] * b[1]
def cross(a, b):
return a[0] * b[1] - a[1] * b[0]
def dif(a, b):
return [x - y for x, y in zip(a, b)]
def InterSection(l, m):
a = dif(l.e, l.s)
b = dif(m.e, l.s)
c = dif(m.s, l.s)
d = dif(m.e, m.s)
e = dif(l.e, m.s)
f = dif(l.s, m.s)
g = lambda a, b: cross(a, b) == 0 and dot(a, b) > 0 and dot(b, b) < dot(a, a)
if g(a, b) or g(a, c) or g(d, e) or g(d, f):
return True
elif l.s == m.e or l.s == m.s or l.e == m.e or l.e == m.s:
return True
elif cross(a, b) * cross(a, c) >= 0 or cross(d, e) * cross(d, f) >= 0:
return False
else:
return True
q = int(eval(input()))
for i in range(q):
x0, y0, x1, y1, x2, y2, x3, y3 = [int(i) for i in input().split()]
a = [x0, y0]
b = [x1, y1]
c = [x2, y2]
d = [x3, y3]
l1 = Line(b, a)
l2 = Line(d, c)
if InterSection(l1, l2):
print((1))
else:
print((0))
| false | 0 | [
"- l1 = Line(a, b)",
"- l2 = Line(c, d)",
"+ l1 = Line(b, a)",
"+ l2 = Line(d, c)"
]
| false | 0.041359 | 0.103936 | 0.39793 | [
"s551984546",
"s538343110"
]
|
u052499405 | p03061 | python | s441811440 | s293203028 | 1,670 | 1,271 | 16,124 | 30,088 | Accepted | Accepted | 23.89 | #!/usr/bin/env python3
import sys
from fractions import gcd
input = sys.stdin.readline
class RgcdQ:
def __init__(self, a):
self.n = len(a)
self.size = 2**(self.n - 1).bit_length()
self.data = [0] * (2*self.size-1)
self.initialize(a)
# Initialize data
def initialize(self, a):
for i in range(self.n):
self.data[self.size + i - 1] = a[i]
for i in range(self.size-2, -1, -1):
self.data[i] = gcd(self.data[i*2 + 1], self.data[i*2 + 2])
# Update ak as x
def update(self, k, x):
k += self.size - 1
self.data[k] = x
while k > 0:
k = (k - 1) // 2
self.data[k] = gcd(self.data[2*k+1], self.data[2*k+2])
# gcd value in [l, r)
def query(self, l, r):
L = l + self.size; R = r + self.size
s = 0
while L < R:
if R & 1:
R -= 1
s = gcd(s, self.data[R-1])
if L & 1:
s = gcd(s, self.data[L-1])
L += 1
L >>= 1; R >>= 1
return s
if __name__ == "__main__":
n = int(eval(input()))
a = [int(item) for item in input().split()]
ST = RgcdQ(a)
ans = 0
for i in range(0, n):
ans = max(ans, gcd(ST.query(0, i), ST.query(i+1, n)))
print(ans) | #!/usr/bin/env python3
import sys
from fractions import gcd
input = sys.stdin.readline
class DisjointSparseTable:
def __init__(self, a):
# Identity element
self.e = 0
self.level = (len(a) - 1).bit_length()
self.size = 2**self.level
self.table = [[self.e] * self.size for _ in range(self.level)]
# Set bottom first
for i, item in enumerate(a):
self.table[-1][i] = item
self.build()
def build(self):
for i in range(1, self.level):
step = 2**i
lv = self.level - 1 - i
for mid in range(step, self.size, step*2):
# Forward
val = self.e
for j in range(step):
val = gcd(self.table[-1][mid + j], val)
self.table[lv][mid + j] = val
# Backward
val = self.e
for j in range(step):
val = gcd(self.table[-1][mid - 1 - j], val)
self.table[lv][mid - 1 - j] = val
# Returns f[l:r)
def query(self, l, r):
if l == r:
return self.e
elif l == r - 1:
return self.table[-1][l]
lv = self.level - (l ^ r-1).bit_length()
return gcd(self.table[lv][l], self.table[lv][r-1])
if __name__ == "__main__":
n = int(eval(input()))
a = [int(item) for item in input().split()]
DST = DisjointSparseTable(a)
ans = 0
for i in range(0, n):
ans = max(ans, gcd(DST.query(0, i), DST.query(i+1, n)))
print(ans) | 50 | 51 | 1,373 | 1,616 | #!/usr/bin/env python3
import sys
from fractions import gcd
input = sys.stdin.readline
class RgcdQ:
def __init__(self, a):
self.n = len(a)
self.size = 2 ** (self.n - 1).bit_length()
self.data = [0] * (2 * self.size - 1)
self.initialize(a)
# Initialize data
def initialize(self, a):
for i in range(self.n):
self.data[self.size + i - 1] = a[i]
for i in range(self.size - 2, -1, -1):
self.data[i] = gcd(self.data[i * 2 + 1], self.data[i * 2 + 2])
# Update ak as x
def update(self, k, x):
k += self.size - 1
self.data[k] = x
while k > 0:
k = (k - 1) // 2
self.data[k] = gcd(self.data[2 * k + 1], self.data[2 * k + 2])
# gcd value in [l, r)
def query(self, l, r):
L = l + self.size
R = r + self.size
s = 0
while L < R:
if R & 1:
R -= 1
s = gcd(s, self.data[R - 1])
if L & 1:
s = gcd(s, self.data[L - 1])
L += 1
L >>= 1
R >>= 1
return s
if __name__ == "__main__":
n = int(eval(input()))
a = [int(item) for item in input().split()]
ST = RgcdQ(a)
ans = 0
for i in range(0, n):
ans = max(ans, gcd(ST.query(0, i), ST.query(i + 1, n)))
print(ans)
| #!/usr/bin/env python3
import sys
from fractions import gcd
input = sys.stdin.readline
class DisjointSparseTable:
def __init__(self, a):
# Identity element
self.e = 0
self.level = (len(a) - 1).bit_length()
self.size = 2**self.level
self.table = [[self.e] * self.size for _ in range(self.level)]
# Set bottom first
for i, item in enumerate(a):
self.table[-1][i] = item
self.build()
def build(self):
for i in range(1, self.level):
step = 2**i
lv = self.level - 1 - i
for mid in range(step, self.size, step * 2):
# Forward
val = self.e
for j in range(step):
val = gcd(self.table[-1][mid + j], val)
self.table[lv][mid + j] = val
# Backward
val = self.e
for j in range(step):
val = gcd(self.table[-1][mid - 1 - j], val)
self.table[lv][mid - 1 - j] = val
# Returns f[l:r)
def query(self, l, r):
if l == r:
return self.e
elif l == r - 1:
return self.table[-1][l]
lv = self.level - (l ^ r - 1).bit_length()
return gcd(self.table[lv][l], self.table[lv][r - 1])
if __name__ == "__main__":
n = int(eval(input()))
a = [int(item) for item in input().split()]
DST = DisjointSparseTable(a)
ans = 0
for i in range(0, n):
ans = max(ans, gcd(DST.query(0, i), DST.query(i + 1, n)))
print(ans)
| false | 1.960784 | [
"-class RgcdQ:",
"+class DisjointSparseTable:",
"- self.n = len(a)",
"- self.size = 2 ** (self.n - 1).bit_length()",
"- self.data = [0] * (2 * self.size - 1)",
"- self.initialize(a)",
"+ # Identity element",
"+ self.e = 0",
"+ self.level = (len(a) - 1).bit_length()",
"+ self.size = 2**self.level",
"+ self.table = [[self.e] * self.size for _ in range(self.level)]",
"+ # Set bottom first",
"+ for i, item in enumerate(a):",
"+ self.table[-1][i] = item",
"+ self.build()",
"- # Initialize data",
"- def initialize(self, a):",
"- for i in range(self.n):",
"- self.data[self.size + i - 1] = a[i]",
"- for i in range(self.size - 2, -1, -1):",
"- self.data[i] = gcd(self.data[i * 2 + 1], self.data[i * 2 + 2])",
"+ def build(self):",
"+ for i in range(1, self.level):",
"+ step = 2**i",
"+ lv = self.level - 1 - i",
"+ for mid in range(step, self.size, step * 2):",
"+ # Forward",
"+ val = self.e",
"+ for j in range(step):",
"+ val = gcd(self.table[-1][mid + j], val)",
"+ self.table[lv][mid + j] = val",
"+ # Backward",
"+ val = self.e",
"+ for j in range(step):",
"+ val = gcd(self.table[-1][mid - 1 - j], val)",
"+ self.table[lv][mid - 1 - j] = val",
"- # Update ak as x",
"- def update(self, k, x):",
"- k += self.size - 1",
"- self.data[k] = x",
"- while k > 0:",
"- k = (k - 1) // 2",
"- self.data[k] = gcd(self.data[2 * k + 1], self.data[2 * k + 2])",
"-",
"- # gcd value in [l, r)",
"+ # Returns f[l:r)",
"- L = l + self.size",
"- R = r + self.size",
"- s = 0",
"- while L < R:",
"- if R & 1:",
"- R -= 1",
"- s = gcd(s, self.data[R - 1])",
"- if L & 1:",
"- s = gcd(s, self.data[L - 1])",
"- L += 1",
"- L >>= 1",
"- R >>= 1",
"- return s",
"+ if l == r:",
"+ return self.e",
"+ elif l == r - 1:",
"+ return self.table[-1][l]",
"+ lv = self.level - (l ^ r - 1).bit_length()",
"+ return gcd(self.table[lv][l], self.table[lv][r - 1])",
"- ST = RgcdQ(a)",
"+ DST = DisjointSparseTable(a)",
"- ans = max(ans, gcd(ST.query(0, i), ST.query(i + 1, n)))",
"+ ans = max(ans, gcd(DST.query(0, i), DST.query(i + 1, n)))"
]
| false | 0.052613 | 0.052337 | 1.005264 | [
"s441811440",
"s293203028"
]
|
u118642796 | p03574 | python | s949421545 | s024745650 | 179 | 34 | 39,792 | 3,444 | Accepted | Accepted | 81.01 | H,W = list(map(int,input().split()))
S = ["."*(W+2)]
[S.append("."+eval(input())+".") for _ in range(H)]
S.append("."*(W+2))
ans = []
for h in range(1,H+1):
ans_tmp = ""
for w in range(1,W+1):
if S[h][w] == ".":
tmp = 0
for i in [-1,0,1]:
for j in [-1,0,1]:
if S[h+i][w+j] == "#":
tmp += 1
ans_tmp += str(tmp)
else:
ans_tmp += "#"
ans.append(ans_tmp)
for s in ans:
print(s)
| H, W = map(int, input().split())
S = [input() for _ in range(H)]
Ans = [[S[h][w] for w in range(W)] for h in range(H)]
for h in range(H):
for w in range(W):
if Ans[h][w] == '.':
x = 0
for i in [-1, 0, 1]:
for j in [-1, 0, 1]:
if 0 <= h + i and h + i < H and 0 <= w + j and w + j < W and S[h + i][w + j] == '#':
x += 1
Ans[h][w] = x
for h in range(H):
for w in range(W):
print(Ans[h][w], end="")
print("")
| 21 | 19 | 523 | 549 | H, W = list(map(int, input().split()))
S = ["." * (W + 2)]
[S.append("." + eval(input()) + ".") for _ in range(H)]
S.append("." * (W + 2))
ans = []
for h in range(1, H + 1):
ans_tmp = ""
for w in range(1, W + 1):
if S[h][w] == ".":
tmp = 0
for i in [-1, 0, 1]:
for j in [-1, 0, 1]:
if S[h + i][w + j] == "#":
tmp += 1
ans_tmp += str(tmp)
else:
ans_tmp += "#"
ans.append(ans_tmp)
for s in ans:
print(s)
| H, W = map(int, input().split())
S = [input() for _ in range(H)]
Ans = [[S[h][w] for w in range(W)] for h in range(H)]
for h in range(H):
for w in range(W):
if Ans[h][w] == ".":
x = 0
for i in [-1, 0, 1]:
for j in [-1, 0, 1]:
if (
0 <= h + i
and h + i < H
and 0 <= w + j
and w + j < W
and S[h + i][w + j] == "#"
):
x += 1
Ans[h][w] = x
for h in range(H):
for w in range(W):
print(Ans[h][w], end="")
print("")
| false | 9.52381 | [
"-H, W = list(map(int, input().split()))",
"-S = [\".\" * (W + 2)]",
"-[S.append(\".\" + eval(input()) + \".\") for _ in range(H)]",
"-S.append(\".\" * (W + 2))",
"-ans = []",
"-for h in range(1, H + 1):",
"- ans_tmp = \"\"",
"- for w in range(1, W + 1):",
"- if S[h][w] == \".\":",
"- tmp = 0",
"+H, W = map(int, input().split())",
"+S = [input() for _ in range(H)]",
"+Ans = [[S[h][w] for w in range(W)] for h in range(H)]",
"+for h in range(H):",
"+ for w in range(W):",
"+ if Ans[h][w] == \".\":",
"+ x = 0",
"- if S[h + i][w + j] == \"#\":",
"- tmp += 1",
"- ans_tmp += str(tmp)",
"- else:",
"- ans_tmp += \"#\"",
"- ans.append(ans_tmp)",
"-for s in ans:",
"- print(s)",
"+ if (",
"+ 0 <= h + i",
"+ and h + i < H",
"+ and 0 <= w + j",
"+ and w + j < W",
"+ and S[h + i][w + j] == \"#\"",
"+ ):",
"+ x += 1",
"+ Ans[h][w] = x",
"+for h in range(H):",
"+ for w in range(W):",
"+ print(Ans[h][w], end=\"\")",
"+ print(\"\")"
]
| false | 0.144202 | 0.037947 | 3.800107 | [
"s949421545",
"s024745650"
]
|
u924691798 | p02925 | python | s525374809 | s718590533 | 1,645 | 495 | 37,108 | 55,260 | Accepted | Accepted | 69.91 | import sys
input = sys.stdin.readline
N = int(eval(input()))
A = [list([int(n)-1 for n in input().split()]) for i in range(N)]
cur = [0 for i in range(N)]
que = [i for i in range(N)]
ans = 0
while len(que) > 0:
done = {}
que2 = []
for n in que:
if done.get(n):
continue
pair = A[n][cur[n]]
if done.get(pair):
continue
if n == A[pair][cur[pair]]:
cur[n] += 1
cur[pair] += 1
done[n] = True
done[pair] = True
if cur[n] < N-1:
que2.append(n)
if cur[pair] < N-1:
que2.append(pair)
if len(done) > 0:
ans += 1
que = que2
ok = True
for i in range(N):
if cur[i] < N-1:
ok = False
if ok:
print(ans)
else:
print((-1))
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(eval(input()))
A = [list([int(n)-1 for n in input().split()]) for i in range(N)]
cur = [0 for i in range(N)]
que = [i for i in range(N)]
ans = 0
while len(que) > 0:
done = {}
que2 = []
for n in que:
if done.get(n):
continue
pair = A[n][cur[n]]
if done.get(pair):
continue
if n == A[pair][cur[pair]]:
cur[n] += 1
cur[pair] += 1
done[n] = True
done[pair] = True
if cur[n] < N-1:
que2.append(n)
if cur[pair] < N-1:
que2.append(pair)
if len(done) > 0:
ans += 1
que = que2
ok = True
for i in range(N):
if cur[i] < N-1:
ok = False
if ok:
print(ans)
else:
print((-1))
| 37 | 38 | 849 | 879 | import sys
input = sys.stdin.readline
N = int(eval(input()))
A = [list([int(n) - 1 for n in input().split()]) for i in range(N)]
cur = [0 for i in range(N)]
que = [i for i in range(N)]
ans = 0
while len(que) > 0:
done = {}
que2 = []
for n in que:
if done.get(n):
continue
pair = A[n][cur[n]]
if done.get(pair):
continue
if n == A[pair][cur[pair]]:
cur[n] += 1
cur[pair] += 1
done[n] = True
done[pair] = True
if cur[n] < N - 1:
que2.append(n)
if cur[pair] < N - 1:
que2.append(pair)
if len(done) > 0:
ans += 1
que = que2
ok = True
for i in range(N):
if cur[i] < N - 1:
ok = False
if ok:
print(ans)
else:
print((-1))
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(eval(input()))
A = [list([int(n) - 1 for n in input().split()]) for i in range(N)]
cur = [0 for i in range(N)]
que = [i for i in range(N)]
ans = 0
while len(que) > 0:
done = {}
que2 = []
for n in que:
if done.get(n):
continue
pair = A[n][cur[n]]
if done.get(pair):
continue
if n == A[pair][cur[pair]]:
cur[n] += 1
cur[pair] += 1
done[n] = True
done[pair] = True
if cur[n] < N - 1:
que2.append(n)
if cur[pair] < N - 1:
que2.append(pair)
if len(done) > 0:
ans += 1
que = que2
ok = True
for i in range(N):
if cur[i] < N - 1:
ok = False
if ok:
print(ans)
else:
print((-1))
| false | 2.631579 | [
"+sys.setrecursionlimit(10**7)"
]
| false | 0.041159 | 0.075873 | 0.542473 | [
"s525374809",
"s718590533"
]
|
u905203728 | p02856 | python | s770791105 | s075072755 | 1,011 | 337 | 78,680 | 106,880 | Accepted | Accepted | 66.67 | m=int(eval(input()))
DC=[list(map(int,input().split())) for _ in range(m)]
D,S=0,0
for d,c in DC:
D +=c
S +=d*c
print((D-1+(S-1)//9)) | n=int(eval(input()))
DC=[list(map(int,input().split())) for _ in range(n)]
D,S=0,0
for d,c in DC:
D +=c
S +=d*c
print((D-1+(S-1)//9)) | 8 | 8 | 141 | 141 | m = int(eval(input()))
DC = [list(map(int, input().split())) for _ in range(m)]
D, S = 0, 0
for d, c in DC:
D += c
S += d * c
print((D - 1 + (S - 1) // 9))
| n = int(eval(input()))
DC = [list(map(int, input().split())) for _ in range(n)]
D, S = 0, 0
for d, c in DC:
D += c
S += d * c
print((D - 1 + (S - 1) // 9))
| false | 0 | [
"-m = int(eval(input()))",
"-DC = [list(map(int, input().split())) for _ in range(m)]",
"+n = int(eval(input()))",
"+DC = [list(map(int, input().split())) for _ in range(n)]"
]
| false | 0.056409 | 0.055231 | 1.02134 | [
"s770791105",
"s075072755"
]
|
u588341295 | p03354 | python | s703125487 | s731071811 | 662 | 599 | 13,812 | 14,008 | Accepted | Accepted | 9.52 | # -*- coding: utf-8 -*-
"""
参考:http://at274.hatenablog.com/entry/2018/02/02/173000
・Union-Find木
"""
class UnionFind:
def __init__(self, n):
# 親要素のノード番号を格納。par[x] == xの時そのノードは根
# 1-indexedのままでOK、その場合は[0]は未使用
self.par = [i for i in range(n+1)]
# 木の高さを格納する(初期状態では0)
self.rank = [0] * (n+1)
# 検索
def find(self, x):
# 根ならその番号を返す
if self.par[x] == x:
return x
else:
# 走査していく過程で親を書き換える
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
# 根を探す
x = self.find(x)
y = self.find(y)
# 木の高さを比較し、低いほうから高いほうに辺を張る
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
# 木の高さが同じなら片方を1増やす
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
N, M = list(map(int, input().split()))
pN = list(map(int, input().split()))
uf = UnionFind(N)
for i in range(M):
x, y = list(map(int, input().split()))
uf.union(x, y)
cnt = 0
for i in range(N):
if uf.same_check(pN[i], i+1):
cnt += 1
print(cnt)
| # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
class UnionFind:
""" Union-Find木 """
def __init__(self, n):
self.n = n
# 親要素のノード番号を格納。par[x] == xの時そのノードは根
# 1-indexedのままでOK、その場合は[0]は未使用
self.par = [i for i in range(n+1)]
# 木の高さを格納する(初期状態では0)
self.rank = [0] * (n+1)
# あるノードを根とする集合に属するノード数
self.size = [1] * (n+1)
# あるノードを根とする集合が木かどうか
self.tree = [True] * (n+1)
def find(self, x):
""" 根の検索(グループ番号と言えなくもない) """
# 根ならその番号を返す
if self.par[x] == x:
return x
else:
# 走査していく過程で親を書き換える
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
""" 併合 """
# 根を探す
x = self.find(x)
y = self.find(y)
# 木かどうかの判定用
if x == y:
self.tree[x] = False
return
if not self.tree[x] or not self.tree[y]:
self.tree[x] = self.tree[y] = False
# 木の高さを比較し、低いほうから高いほうに辺を張る
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.size[y] += self.size[x]
else:
self.par[y] = x
self.size[x] += self.size[y]
# 木の高さが同じなら片方を1増やす
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def same(self, x, y):
""" 同じ集合に属するか判定 """
return self.find(x) == self.find(y)
def get_size(self, x):
""" あるノードの属する集合のノード数 """
return self.size[self.find(x)]
def is_tree(self, x):
""" 木かどうかの判定 """
return self.tree[self.find(x)]
def len(self):
""" 集合の数 """
res = set()
for i in range(self.n+1):
res.add(self.find(i))
# グループ0の分を引いて返却
return len(res) - 1
N, M = MAP()
P = [p-1 for p in LIST()]
uf = UnionFind(N)
for i in range(M):
a, b = MAP()
a -= 1
b -= 1
uf.union(P[a], P[b])
cnt = 0
for i in range(N):
p = P[i]
if uf.same(p, i):
cnt += 1
print(cnt)
| 56 | 105 | 1,324 | 2,791 | # -*- coding: utf-8 -*-
"""
参考:http://at274.hatenablog.com/entry/2018/02/02/173000
・Union-Find木
"""
class UnionFind:
def __init__(self, n):
# 親要素のノード番号を格納。par[x] == xの時そのノードは根
# 1-indexedのままでOK、その場合は[0]は未使用
self.par = [i for i in range(n + 1)]
# 木の高さを格納する(初期状態では0)
self.rank = [0] * (n + 1)
# 検索
def find(self, x):
# 根ならその番号を返す
if self.par[x] == x:
return x
else:
# 走査していく過程で親を書き換える
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
# 根を探す
x = self.find(x)
y = self.find(y)
# 木の高さを比較し、低いほうから高いほうに辺を張る
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
# 木の高さが同じなら片方を1増やす
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
N, M = list(map(int, input().split()))
pN = list(map(int, input().split()))
uf = UnionFind(N)
for i in range(M):
x, y = list(map(int, input().split()))
uf.union(x, y)
cnt = 0
for i in range(N):
if uf.same_check(pN[i], i + 1):
cnt += 1
print(cnt)
| # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
class UnionFind:
"""Union-Find木"""
def __init__(self, n):
self.n = n
# 親要素のノード番号を格納。par[x] == xの時そのノードは根
# 1-indexedのままでOK、その場合は[0]は未使用
self.par = [i for i in range(n + 1)]
# 木の高さを格納する(初期状態では0)
self.rank = [0] * (n + 1)
# あるノードを根とする集合に属するノード数
self.size = [1] * (n + 1)
# あるノードを根とする集合が木かどうか
self.tree = [True] * (n + 1)
def find(self, x):
"""根の検索(グループ番号と言えなくもない)"""
# 根ならその番号を返す
if self.par[x] == x:
return x
else:
# 走査していく過程で親を書き換える
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
"""併合"""
# 根を探す
x = self.find(x)
y = self.find(y)
# 木かどうかの判定用
if x == y:
self.tree[x] = False
return
if not self.tree[x] or not self.tree[y]:
self.tree[x] = self.tree[y] = False
# 木の高さを比較し、低いほうから高いほうに辺を張る
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.size[y] += self.size[x]
else:
self.par[y] = x
self.size[x] += self.size[y]
# 木の高さが同じなら片方を1増やす
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def same(self, x, y):
"""同じ集合に属するか判定"""
return self.find(x) == self.find(y)
def get_size(self, x):
"""あるノードの属する集合のノード数"""
return self.size[self.find(x)]
def is_tree(self, x):
"""木かどうかの判定"""
return self.tree[self.find(x)]
def len(self):
"""集合の数"""
res = set()
for i in range(self.n + 1):
res.add(self.find(i))
# グループ0の分を引いて返却
return len(res) - 1
N, M = MAP()
P = [p - 1 for p in LIST()]
uf = UnionFind(N)
for i in range(M):
a, b = MAP()
a -= 1
b -= 1
uf.union(P[a], P[b])
cnt = 0
for i in range(N):
p = P[i]
if uf.same(p, i):
cnt += 1
print(cnt)
| false | 46.666667 | [
"-\"\"\"",
"-参考:http://at274.hatenablog.com/entry/2018/02/02/173000",
"-・Union-Find木",
"-\"\"\"",
"+import sys",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+",
"+def list2d(a, b, c):",
"+ return [[c] * b for i in range(a)]",
"+",
"+",
"+def list3d(a, b, c, d):",
"+ return [[[d] * c for j in range(b)] for i in range(a)]",
"+",
"+",
"+def list4d(a, b, c, d, e):",
"+ return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]",
"+",
"+",
"+def ceil(x, y=1):",
"+ return int(-(-x // y))",
"+",
"+",
"+def INT():",
"+ return int(eval(input()))",
"+",
"+",
"+def MAP():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LIST(N=None):",
"+ return list(MAP()) if N is None else [INT() for i in range(N)]",
"+",
"+",
"+def Yes():",
"+ print(\"Yes\")",
"+",
"+",
"+def No():",
"+ print(\"No\")",
"+",
"+",
"+def YES():",
"+ print(\"YES\")",
"+",
"+",
"+def NO():",
"+ print(\"NO\")",
"+",
"+",
"+sys.setrecursionlimit(10**9)",
"+INF = float(\"inf\")",
"+MOD = 10**9 + 7",
"+ \"\"\"Union-Find木\"\"\"",
"+",
"+ self.n = n",
"+ # あるノードを根とする集合に属するノード数",
"+ self.size = [1] * (n + 1)",
"+ # あるノードを根とする集合が木かどうか",
"+ self.tree = [True] * (n + 1)",
"- # 検索",
"+ \"\"\"根の検索(グループ番号と言えなくもない)\"\"\"",
"- # 併合",
"+ \"\"\"併合\"\"\"",
"+ # 木かどうかの判定用",
"+ if x == y:",
"+ self.tree[x] = False",
"+ return",
"+ if not self.tree[x] or not self.tree[y]:",
"+ self.tree[x] = self.tree[y] = False",
"+ self.size[y] += self.size[x]",
"+ self.size[x] += self.size[y]",
"- # 同じ集合に属するか判定",
"- def same_check(self, x, y):",
"+ def same(self, x, y):",
"+ \"\"\"同じ集合に属するか判定\"\"\"",
"+ def get_size(self, x):",
"+ \"\"\"あるノードの属する集合のノード数\"\"\"",
"+ return self.size[self.find(x)]",
"-N, M = list(map(int, input().split()))",
"-pN = list(map(int, input().split()))",
"+ def is_tree(self, x):",
"+ \"\"\"木かどうかの判定\"\"\"",
"+ return self.tree[self.find(x)]",
"+",
"+ def len(self):",
"+ \"\"\"集合の数\"\"\"",
"+ res = set()",
"+ for i in range(self.n + 1):",
"+ res.add(self.find(i))",
"+ # グループ0の分を引いて返却",
"+ return len(res) - 1",
"+",
"+",
"+N, M = MAP()",
"+P = [p - 1 for p in LIST()]",
"- x, y = list(map(int, input().split()))",
"- uf.union(x, y)",
"+ a, b = MAP()",
"+ a -= 1",
"+ b -= 1",
"+ uf.union(P[a], P[b])",
"- if uf.same_check(pN[i], i + 1):",
"+ p = P[i]",
"+ if uf.same(p, i):"
]
| false | 0.042186 | 0.038707 | 1.089884 | [
"s703125487",
"s731071811"
]
|
u373047809 | p03341 | python | s358329584 | s058523230 | 181 | 151 | 31,576 | 3,676 | Accepted | Accepted | 16.57 | from itertools import*;eval(input());s=eval(input());print((min(w+e for w,e in zip(*[([0]+list(accumulate(list(map(int,s[::a].translate(str.maketrans("EW","01"[::a]))))))[:-1])[::a]for a in[-1,1]])))) | eval(input());s=eval(input());m=c=s.count("E")
for t in s:c-=t<"W";m=min(m,c);c+=t>"E"
print(m)
| 1 | 3 | 180 | 86 | from itertools import *
eval(input())
s = eval(input())
print(
(
min(
w + e
for w, e in zip(
*[
(
[0]
+ list(
accumulate(
list(
map(
int,
s[::a].translate(
str.maketrans("EW", "01"[::a])
),
)
)
)
)[:-1]
)[::a]
for a in [-1, 1]
]
)
)
)
)
| eval(input())
s = eval(input())
m = c = s.count("E")
for t in s:
c -= t < "W"
m = min(m, c)
c += t > "E"
print(m)
| false | 66.666667 | [
"-from itertools import *",
"-",
"-print(",
"- (",
"- min(",
"- w + e",
"- for w, e in zip(",
"- *[",
"- (",
"- [0]",
"- + list(",
"- accumulate(",
"- list(",
"- map(",
"- int,",
"- s[::a].translate(",
"- str.maketrans(\"EW\", \"01\"[::a])",
"- ),",
"- )",
"- )",
"- )",
"- )[:-1]",
"- )[::a]",
"- for a in [-1, 1]",
"- ]",
"- )",
"- )",
"- )",
"-)",
"+m = c = s.count(\"E\")",
"+for t in s:",
"+ c -= t < \"W\"",
"+ m = min(m, c)",
"+ c += t > \"E\"",
"+print(m)"
]
| false | 0.048151 | 0.047475 | 1.014247 | [
"s358329584",
"s058523230"
]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.