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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u510829608 | p02241 | python | s866720650 | s178618514 | 50 | 30 | 9,620 | 7,952 | Accepted | Accepted | 40 | import array
import collections
import heapq
INF = 1e9
N = int(eval(input()))
AdjacentVertex = collections.namedtuple('AdjacentVertex', 'vertex cost')
adjacency_list = collections.defaultdict(set)
NO_VERTEX = -1
def compute_mst_prim(max_v, adj_list):
pred = collections.defaultdict(lambda: NO_VERTEX)
key = collections.defaultdict(lambda: INF)
key[0] = 0
pq = [(key[v], v) for v in range(max_v)]
heapq.heapify(pq)
in_pq = array.array("B", (True for _ in range(max_v)))
while pq:
_, u = heapq.heappop(pq)
in_pq[u] = False
for v, v_cost in adj_list[u]:
if in_pq[v]:
weight = v_cost
if weight < key[v]:
pred[v] = u
key[v] = weight
heapq.heappush(pq, (weight, v))
in_pq[v] = True
return (pred, key)
for i in range(N):
u = list(map(int, input().split()))
for j in range(N):
if u[j] == -1:
adjacency_list[i].add(AdjacentVertex(j, INF))
adjacency_list[j].add(AdjacentVertex(i, INF))
else:
adjacency_list[i].add(AdjacentVertex(j, u[j]))
adjacency_list[j].add(AdjacentVertex(i, u[j]))
(_, key) = compute_mst_prim(N, adjacency_list)
print((sum(key.values()))) | INF = 1e9
n = int(eval(input()))
adj_matrix = [list(map(int, input().split())) for i in range(n)]
def prim(x):
isVisited = [False] * x
d = [INF] * x
d[0] = 0
p = [-1] * x
while True:
min_cost = INF
for i in range(x):
if isVisited[i] != True and d[i] < min_cost:
min_cost = d[i]
u = i
if min_cost == INF:
break
isVisited[u] = True
for v in range(x):
if isVisited[v] != True and adj_matrix[u][v] != -1:
if adj_matrix[u][v] < d[v]:
d[v] = adj_matrix[u][v]
p[v] = u
return sum(d)
print((prim(n))) | 46 | 33 | 1,347 | 751 | import array
import collections
import heapq
INF = 1e9
N = int(eval(input()))
AdjacentVertex = collections.namedtuple("AdjacentVertex", "vertex cost")
adjacency_list = collections.defaultdict(set)
NO_VERTEX = -1
def compute_mst_prim(max_v, adj_list):
pred = collections.defaultdict(lambda: NO_VERTEX)
key = collections.defaultdict(lambda: INF)
key[0] = 0
pq = [(key[v], v) for v in range(max_v)]
heapq.heapify(pq)
in_pq = array.array("B", (True for _ in range(max_v)))
while pq:
_, u = heapq.heappop(pq)
in_pq[u] = False
for v, v_cost in adj_list[u]:
if in_pq[v]:
weight = v_cost
if weight < key[v]:
pred[v] = u
key[v] = weight
heapq.heappush(pq, (weight, v))
in_pq[v] = True
return (pred, key)
for i in range(N):
u = list(map(int, input().split()))
for j in range(N):
if u[j] == -1:
adjacency_list[i].add(AdjacentVertex(j, INF))
adjacency_list[j].add(AdjacentVertex(i, INF))
else:
adjacency_list[i].add(AdjacentVertex(j, u[j]))
adjacency_list[j].add(AdjacentVertex(i, u[j]))
(_, key) = compute_mst_prim(N, adjacency_list)
print((sum(key.values())))
| INF = 1e9
n = int(eval(input()))
adj_matrix = [list(map(int, input().split())) for i in range(n)]
def prim(x):
isVisited = [False] * x
d = [INF] * x
d[0] = 0
p = [-1] * x
while True:
min_cost = INF
for i in range(x):
if isVisited[i] != True and d[i] < min_cost:
min_cost = d[i]
u = i
if min_cost == INF:
break
isVisited[u] = True
for v in range(x):
if isVisited[v] != True and adj_matrix[u][v] != -1:
if adj_matrix[u][v] < d[v]:
d[v] = adj_matrix[u][v]
p[v] = u
return sum(d)
print((prim(n)))
| false | 28.26087 | [
"-import array",
"-import collections",
"-import heapq",
"-",
"-N = int(eval(input()))",
"-AdjacentVertex = collections.namedtuple(\"AdjacentVertex\", \"vertex cost\")",
"-adjacency_list = collections.defaultdict(set)",
"-NO_VERTEX = -1",
"+n = int(eval(input()))",
"+adj_matrix = [list(map(int, input().split())) for i in range(n)]",
"-def compute_mst_prim(max_v, adj_list):",
"- pred = collections.defaultdict(lambda: NO_VERTEX)",
"- key = collections.defaultdict(lambda: INF)",
"- key[0] = 0",
"- pq = [(key[v], v) for v in range(max_v)]",
"- heapq.heapify(pq)",
"- in_pq = array.array(\"B\", (True for _ in range(max_v)))",
"- while pq:",
"- _, u = heapq.heappop(pq)",
"- in_pq[u] = False",
"- for v, v_cost in adj_list[u]:",
"- if in_pq[v]:",
"- weight = v_cost",
"- if weight < key[v]:",
"- pred[v] = u",
"- key[v] = weight",
"- heapq.heappush(pq, (weight, v))",
"- in_pq[v] = True",
"- return (pred, key)",
"+def prim(x):",
"+ isVisited = [False] * x",
"+ d = [INF] * x",
"+ d[0] = 0",
"+ p = [-1] * x",
"+ while True:",
"+ min_cost = INF",
"+ for i in range(x):",
"+ if isVisited[i] != True and d[i] < min_cost:",
"+ min_cost = d[i]",
"+ u = i",
"+ if min_cost == INF:",
"+ break",
"+ isVisited[u] = True",
"+ for v in range(x):",
"+ if isVisited[v] != True and adj_matrix[u][v] != -1:",
"+ if adj_matrix[u][v] < d[v]:",
"+ d[v] = adj_matrix[u][v]",
"+ p[v] = u",
"+ return sum(d)",
"-for i in range(N):",
"- u = list(map(int, input().split()))",
"- for j in range(N):",
"- if u[j] == -1:",
"- adjacency_list[i].add(AdjacentVertex(j, INF))",
"- adjacency_list[j].add(AdjacentVertex(i, INF))",
"- else:",
"- adjacency_list[i].add(AdjacentVertex(j, u[j]))",
"- adjacency_list[j].add(AdjacentVertex(i, u[j]))",
"-(_, key) = compute_mst_prim(N, adjacency_list)",
"-print((sum(key.values())))",
"+print((prim(n)))"
] | false | 0.202729 | 0.04396 | 4.611685 | [
"s866720650",
"s178618514"
] |
u888092736 | p02598 | python | s007245376 | s252770948 | 1,149 | 790 | 31,496 | 31,528 | Accepted | Accepted | 31.24 | def count_cuts(a, unit):
return (a + unit - 1) // unit - 1
def is_good(mid, key):
return sum(count_cuts(a, mid) for a in A) <= key
def binary_search(key):
bad, good = 0, 1_000_000_000
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(K)))
| def is_good(mid, key):
res = 0
for a in A:
res += (a + mid - 1) // mid
return res - N <= key
def binary_search(bad, good, key):
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(0, 1_000_000_000, K)))
| 21 | 19 | 453 | 419 | def count_cuts(a, unit):
return (a + unit - 1) // unit - 1
def is_good(mid, key):
return sum(count_cuts(a, mid) for a in A) <= key
def binary_search(key):
bad, good = 0, 1_000_000_000
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(K)))
| def is_good(mid, key):
res = 0
for a in A:
res += (a + mid - 1) // mid
return res - N <= key
def binary_search(bad, good, key):
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
N, K, *A = list(map(int, open(0).read().split()))
print((binary_search(0, 1_000_000_000, K)))
| false | 9.52381 | [
"-def count_cuts(a, unit):",
"- return (a + unit - 1) // unit - 1",
"+def is_good(mid, key):",
"+ res = 0",
"+ for a in A:",
"+ res += (a + mid - 1) // mid",
"+ return res - N <= key",
"-def is_good(mid, key):",
"- return sum(count_cuts(a, mid) for a in A) <= key",
"-",
"-",
"-def binary_search(key):",
"- bad, good = 0, 1_000_000_000",
"+def binary_search(bad, good, key):",
"-print((binary_search(K)))",
"+print((binary_search(0, 1_000_000_000, K)))"
] | false | 0.038191 | 0.036564 | 1.044481 | [
"s007245376",
"s252770948"
] |
u585482323 | p03030 | python | s385965736 | s858087810 | 203 | 185 | 39,152 | 39,152 | Accepted | Accepted | 8.87 | #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LS()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
a,p = LI()
print(((a*3+p)//2))
return
#B
def B():
n = I()
s = [None for i in range(n)]
for i in range(n):
l = input().split()
s[i] = l+[i]
s.sort(key = lambda x:(x[0],-int(x[1])))
for i,a,b in s:
print((b+1))
return
#C
def C():
n = I()
return
#D
def D():
n = I()
return
#E
def E():
n = I()
return
#F
def F():
n = I()
return
#Solve
if __name__ == "__main__":
B()
| #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
g = []
for i in range(n):
s,p = input().split()
p = int(p)
g.append((s,-p,i+1))
g.sort()
for a,b,i in g:
print(i)
return
#Solve
if __name__ == "__main__":
solve()
| 76 | 42 | 1,353 | 954 | #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return list(map(list, sys.stdin.readline().split()))
def S():
return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = LS()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
# A
def A():
a, p = LI()
print(((a * 3 + p) // 2))
return
# B
def B():
n = I()
s = [None for i in range(n)]
for i in range(n):
l = input().split()
s[i] = l + [i]
s.sort(key=lambda x: (x[0], -int(x[1])))
for i, a, b in s:
print((b + 1))
return
# C
def C():
n = I()
return
# D
def D():
n = I()
return
# E
def E():
n = I()
return
# F
def F():
n = I()
return
# Solve
if __name__ == "__main__":
B()
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
g = []
for i in range(n):
s, p = input().split()
p = int(p)
g.append((s, -p, i + 1))
g.sort()
for a, b, i in g:
print(i)
return
# Solve
if __name__ == "__main__":
solve()
| false | 44.736842 | [
"-from collections import defaultdict",
"-from collections import deque",
"+from collections import defaultdict, deque",
"- return list(map(int, sys.stdin.readline().split()))",
"+ return [int(x) for x in sys.stdin.readline().split()]",
"- return list(map(list, sys.stdin.readline().split()))",
"+ return [list(x) for x in sys.stdin.readline().split()]",
"- return list(sys.stdin.readline())[:-1]",
"+ res = list(sys.stdin.readline())",
"+ if res[-1] == \"\\n\":",
"+ return res[:-1]",
"+ return res",
"- l = [None for i in range(n)]",
"- for i in range(n):",
"- l[i] = I()",
"- return l",
"+ return [I() for i in range(n)]",
"- l = [None for i in range(n)]",
"- for i in range(n):",
"- l[i] = LI()",
"- return l",
"+ return [LI() for i in range(n)]",
"- l = [None for i in range(n)]",
"- for i in range(n):",
"- l[i] = S()",
"- return l",
"+ return [S() for i in range(n)]",
"- l = [None for i in range(n)]",
"- for i in range(n):",
"- l[i] = LS()",
"- return l",
"+ return [LS() for i in range(n)]",
"-# A",
"-def A():",
"- a, p = LI()",
"- print(((a * 3 + p) // 2))",
"- return",
"-# B",
"-def B():",
"+def solve():",
"- s = [None for i in range(n)]",
"+ g = []",
"- l = input().split()",
"- s[i] = l + [i]",
"- s.sort(key=lambda x: (x[0], -int(x[1])))",
"- for i, a, b in s:",
"- print((b + 1))",
"- return",
"-",
"-",
"-# C",
"-def C():",
"- n = I()",
"- return",
"-",
"-",
"-# D",
"-def D():",
"- n = I()",
"- return",
"-",
"-",
"-# E",
"-def E():",
"- n = I()",
"- return",
"-",
"-",
"-# F",
"-def F():",
"- n = I()",
"+ s, p = input().split()",
"+ p = int(p)",
"+ g.append((s, -p, i + 1))",
"+ g.sort()",
"+ for a, b, i in g:",
"+ print(i)",
"- B()",
"+ solve()"
] | false | 0.073262 | 0.037835 | 1.936367 | [
"s385965736",
"s858087810"
] |
u133936772 | p03435 | python | s513545800 | s218381500 | 30 | 27 | 9,060 | 9,168 | Accepted | Accepted | 10 | g=[[*map(int,input().split())]for _ in range(3)]
for h in [0,1]:
for w in [0,1]:
if g[h][w]+g[h+1][w+1]!=g[h+1][w]+g[h][w+1]:
exit(print('No'))
print('Yes')
| m=lambda:list(map(int,input().split()))
a,b,c=m()
d,e,f=m()
g,h,i=m()
print((['No','Yes'][d-a==e-b==f-c and g-a==h-b==i-c])) | 6 | 5 | 174 | 120 | g = [[*map(int, input().split())] for _ in range(3)]
for h in [0, 1]:
for w in [0, 1]:
if g[h][w] + g[h + 1][w + 1] != g[h + 1][w] + g[h][w + 1]:
exit(print("No"))
print("Yes")
| m = lambda: list(map(int, input().split()))
a, b, c = m()
d, e, f = m()
g, h, i = m()
print((["No", "Yes"][d - a == e - b == f - c and g - a == h - b == i - c]))
| false | 16.666667 | [
"-g = [[*map(int, input().split())] for _ in range(3)]",
"-for h in [0, 1]:",
"- for w in [0, 1]:",
"- if g[h][w] + g[h + 1][w + 1] != g[h + 1][w] + g[h][w + 1]:",
"- exit(print(\"No\"))",
"-print(\"Yes\")",
"+m = lambda: list(map(int, input().split()))",
"+a, b, c = m()",
"+d, e, f = m()",
"+g, h, i = m()",
"+print(([\"No\", \"Yes\"][d - a == e - b == f - c and g - a == h - b == i - c]))"
] | false | 0.043067 | 0.044591 | 0.965812 | [
"s513545800",
"s218381500"
] |
u893063840 | p02892 | python | s412606353 | s260777410 | 1,082 | 369 | 4,464 | 23,560 | Accepted | Accepted | 65.9 | from queue import Queue
def main():
n = int(eval(input()))
S = [list(map(int, eval(input()))) for _ in range(n)]
def bfs(s):
WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE] * n
d = [-1] * n
q = Queue()
q.put(s)
color[s] = GRAY
d[s] = 0
while not q.empty():
u = q.get()
color[u] = BLACK
for v, edge in enumerate(S[u]):
if edge and color[v] == BLACK and d[v] + 1 != d[u]:
return -1
if edge and color[v] == WHITE:
q.put(v)
color[v] = GRAY
d[v] = d[u] + 1
return max(d) + 1
cnt = -1
for i in range(n):
cnt = max(cnt, bfs(i))
print(cnt)
if __name__ == "__main__":
main()
| import numpy as np
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
def main():
n = int(eval(input()))
s = [list(map(int, eval(input()))) for _ in range(n)]
s = np.array(s)
g = csgraph_from_dense(s)
dist_mat = floyd_warshall(g).astype(np.int32)
dist_max = dist_mat.max()
a = np.where(dist_mat[0] % 2 == 0)
b = np.where(dist_mat[0] % 2 == 1)
bl = (s[a][:,a] == 0).all() and (s[b][:,b] == 0).all()
ans = dist_max + 1 if bl else -1
print(ans)
if __name__ == "__main__":
main()
| 41 | 27 | 873 | 566 | from queue import Queue
def main():
n = int(eval(input()))
S = [list(map(int, eval(input()))) for _ in range(n)]
def bfs(s):
WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE] * n
d = [-1] * n
q = Queue()
q.put(s)
color[s] = GRAY
d[s] = 0
while not q.empty():
u = q.get()
color[u] = BLACK
for v, edge in enumerate(S[u]):
if edge and color[v] == BLACK and d[v] + 1 != d[u]:
return -1
if edge and color[v] == WHITE:
q.put(v)
color[v] = GRAY
d[v] = d[u] + 1
return max(d) + 1
cnt = -1
for i in range(n):
cnt = max(cnt, bfs(i))
print(cnt)
if __name__ == "__main__":
main()
| import numpy as np
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
def main():
n = int(eval(input()))
s = [list(map(int, eval(input()))) for _ in range(n)]
s = np.array(s)
g = csgraph_from_dense(s)
dist_mat = floyd_warshall(g).astype(np.int32)
dist_max = dist_mat.max()
a = np.where(dist_mat[0] % 2 == 0)
b = np.where(dist_mat[0] % 2 == 1)
bl = (s[a][:, a] == 0).all() and (s[b][:, b] == 0).all()
ans = dist_max + 1 if bl else -1
print(ans)
if __name__ == "__main__":
main()
| false | 34.146341 | [
"-from queue import Queue",
"+import numpy as np",
"+from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall",
"- S = [list(map(int, eval(input()))) for _ in range(n)]",
"-",
"- def bfs(s):",
"- WHITE = 0",
"- GRAY = 1",
"- BLACK = 2",
"- color = [WHITE] * n",
"- d = [-1] * n",
"- q = Queue()",
"- q.put(s)",
"- color[s] = GRAY",
"- d[s] = 0",
"- while not q.empty():",
"- u = q.get()",
"- color[u] = BLACK",
"- for v, edge in enumerate(S[u]):",
"- if edge and color[v] == BLACK and d[v] + 1 != d[u]:",
"- return -1",
"- if edge and color[v] == WHITE:",
"- q.put(v)",
"- color[v] = GRAY",
"- d[v] = d[u] + 1",
"- return max(d) + 1",
"-",
"- cnt = -1",
"- for i in range(n):",
"- cnt = max(cnt, bfs(i))",
"- print(cnt)",
"+ s = [list(map(int, eval(input()))) for _ in range(n)]",
"+ s = np.array(s)",
"+ g = csgraph_from_dense(s)",
"+ dist_mat = floyd_warshall(g).astype(np.int32)",
"+ dist_max = dist_mat.max()",
"+ a = np.where(dist_mat[0] % 2 == 0)",
"+ b = np.where(dist_mat[0] % 2 == 1)",
"+ bl = (s[a][:, a] == 0).all() and (s[b][:, b] == 0).all()",
"+ ans = dist_max + 1 if bl else -1",
"+ print(ans)"
] | false | 0.045511 | 0.640739 | 0.071028 | [
"s412606353",
"s260777410"
] |
u814986259 | p03660 | python | s708828133 | s958333868 | 784 | 655 | 54,936 | 43,316 | Accepted | Accepted | 16.45 | N=int(eval(input()))
import collections
import heapq
ab=[tuple(map(int,input().split())) for i in range(N-1)]
G=[set() for i in range(N)]
for a,b in ab:
a-=1
b-=1
G[a].add(b)
G[b].add(a)
q=collections.deque()
dis=[[-1]*N for i in range(2)]
dis[0][0]=0
q.append(0)
while(q):
x=q.popleft()
for y in G[x]:
if dis[0][y]==-1:
q.append(y)
dis[0][y]=dis[0][x]+1
dis[1][N-1]=0
q.append(N-1)
while(q):
x=q.popleft()
for y in G[x]:
if dis[1][y]==-1:
q.append(y)
dis[1][y]=dis[1][x]+1
hqF=[(0,0)]
hqS=[(0,N-1)]
colord=[False]*N
while(1):
if len(hqF)==0:
print("Snuke")
exit(0)
_,x = heapq.heappop(hqF)
while(colord[x]):
if hqF:
_,x = heapq.heappop(hqF)
else:
print("Snuke")
exit(0)
colord[x]=True
for y in G[x]:
if colord[y]==False:
heapq.heappush(hqF,(dis[1][y],y))
if len(hqS)==0:
print("Fennec")
exit(0)
_,x = heapq.heappop(hqS)
while(colord[x]):
if hqF:
_,x = heapq.heappop(hqS)
else:
print("Fennec")
exit(0)
colord[x]=True
for y in G[x]:
if colord[y]==False:
heapq.heappush(hqS,(dis[0][y],y))
| import collections
N = int(eval(input()))
G = [set() for i in range(N)]
for i in range(N-1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].add(b)
G[b].add(a)
F = [-1]*N
F[0] = 0
q = collections.deque()
q.append(0)
while(q):
x = q.popleft()
for y in G[x]:
if F[y] < 0:
F[y] = F[x] + 1
q.append(y)
S = [-1]*N
S[N-1] = 0
q.append(N-1)
while(q):
x = q.popleft()
for y in G[x]:
if S[y] < 0:
S[y] = S[x] + 1
q.append(y)
# print(F)
# print(S)
ans = 0
q = collections.deque()
r = [True]*N
for i in range(N):
if F[i] + S[i] == F[-1]:
if F[i] <= S[i]:
q.append(i)
r[i] = False
else:
r[i] = False
ans = len(q)
while(q):
x = q.popleft()
for y in G[x]:
if r[y]:
ans += 1
q.append(y)
r[y] = False
if ans > N - ans:
print("Fennec")
else:
print("Snuke")
| 64 | 59 | 1,204 | 1,019 | N = int(eval(input()))
import collections
import heapq
ab = [tuple(map(int, input().split())) for i in range(N - 1)]
G = [set() for i in range(N)]
for a, b in ab:
a -= 1
b -= 1
G[a].add(b)
G[b].add(a)
q = collections.deque()
dis = [[-1] * N for i in range(2)]
dis[0][0] = 0
q.append(0)
while q:
x = q.popleft()
for y in G[x]:
if dis[0][y] == -1:
q.append(y)
dis[0][y] = dis[0][x] + 1
dis[1][N - 1] = 0
q.append(N - 1)
while q:
x = q.popleft()
for y in G[x]:
if dis[1][y] == -1:
q.append(y)
dis[1][y] = dis[1][x] + 1
hqF = [(0, 0)]
hqS = [(0, N - 1)]
colord = [False] * N
while 1:
if len(hqF) == 0:
print("Snuke")
exit(0)
_, x = heapq.heappop(hqF)
while colord[x]:
if hqF:
_, x = heapq.heappop(hqF)
else:
print("Snuke")
exit(0)
colord[x] = True
for y in G[x]:
if colord[y] == False:
heapq.heappush(hqF, (dis[1][y], y))
if len(hqS) == 0:
print("Fennec")
exit(0)
_, x = heapq.heappop(hqS)
while colord[x]:
if hqF:
_, x = heapq.heappop(hqS)
else:
print("Fennec")
exit(0)
colord[x] = True
for y in G[x]:
if colord[y] == False:
heapq.heappush(hqS, (dis[0][y], y))
| import collections
N = int(eval(input()))
G = [set() for i in range(N)]
for i in range(N - 1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].add(b)
G[b].add(a)
F = [-1] * N
F[0] = 0
q = collections.deque()
q.append(0)
while q:
x = q.popleft()
for y in G[x]:
if F[y] < 0:
F[y] = F[x] + 1
q.append(y)
S = [-1] * N
S[N - 1] = 0
q.append(N - 1)
while q:
x = q.popleft()
for y in G[x]:
if S[y] < 0:
S[y] = S[x] + 1
q.append(y)
# print(F)
# print(S)
ans = 0
q = collections.deque()
r = [True] * N
for i in range(N):
if F[i] + S[i] == F[-1]:
if F[i] <= S[i]:
q.append(i)
r[i] = False
else:
r[i] = False
ans = len(q)
while q:
x = q.popleft()
for y in G[x]:
if r[y]:
ans += 1
q.append(y)
r[y] = False
if ans > N - ans:
print("Fennec")
else:
print("Snuke")
| false | 7.8125 | [
"+import collections",
"+",
"-import collections",
"-import heapq",
"-",
"-ab = [tuple(map(int, input().split())) for i in range(N - 1)]",
"-for a, b in ab:",
"+for i in range(N - 1):",
"+ a, b = list(map(int, input().split()))",
"+F = [-1] * N",
"+F[0] = 0",
"-dis = [[-1] * N for i in range(2)]",
"-dis[0][0] = 0",
"- if dis[0][y] == -1:",
"+ if F[y] < 0:",
"+ F[y] = F[x] + 1",
"- dis[0][y] = dis[0][x] + 1",
"-dis[1][N - 1] = 0",
"+S = [-1] * N",
"+S[N - 1] = 0",
"- if dis[1][y] == -1:",
"+ if S[y] < 0:",
"+ S[y] = S[x] + 1",
"- dis[1][y] = dis[1][x] + 1",
"-hqF = [(0, 0)]",
"-hqS = [(0, N - 1)]",
"-colord = [False] * N",
"-while 1:",
"- if len(hqF) == 0:",
"- print(\"Snuke\")",
"- exit(0)",
"- _, x = heapq.heappop(hqF)",
"- while colord[x]:",
"- if hqF:",
"- _, x = heapq.heappop(hqF)",
"+# print(F)",
"+# print(S)",
"+ans = 0",
"+q = collections.deque()",
"+r = [True] * N",
"+for i in range(N):",
"+ if F[i] + S[i] == F[-1]:",
"+ if F[i] <= S[i]:",
"+ q.append(i)",
"+ r[i] = False",
"- print(\"Snuke\")",
"- exit(0)",
"- colord[x] = True",
"+ r[i] = False",
"+ans = len(q)",
"+while q:",
"+ x = q.popleft()",
"- if colord[y] == False:",
"- heapq.heappush(hqF, (dis[1][y], y))",
"- if len(hqS) == 0:",
"- print(\"Fennec\")",
"- exit(0)",
"- _, x = heapq.heappop(hqS)",
"- while colord[x]:",
"- if hqF:",
"- _, x = heapq.heappop(hqS)",
"- else:",
"- print(\"Fennec\")",
"- exit(0)",
"- colord[x] = True",
"- for y in G[x]:",
"- if colord[y] == False:",
"- heapq.heappush(hqS, (dis[0][y], y))",
"+ if r[y]:",
"+ ans += 1",
"+ q.append(y)",
"+ r[y] = False",
"+if ans > N - ans:",
"+ print(\"Fennec\")",
"+else:",
"+ print(\"Snuke\")"
] | false | 0.067028 | 0.045517 | 1.472582 | [
"s708828133",
"s958333868"
] |
u823290900 | p02713 | python | s526139634 | s864830246 | 1,902 | 1,442 | 9,112 | 9,052 | Accepted | Accepted | 24.19 | from math import gcd
K = int(eval(input()))
ans = 0
for i in range(1, K+1):
for j in range(1, K+1):
for k in range(1, K+1):
ans += gcd(gcd(i, j), k)
print(ans) | import sys
from math import gcd
def solve(K: int):
ans = 0
for i in range(1, K+1):
for j in range(1, K+1):
for k in range(1, K+1):
ans += gcd(gcd(i, j), k)
print(ans)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
K = int(next(tokens)) # type: int
solve(K)
if __name__ == '__main__':
main()
| 12 | 28 | 192 | 515 | from math import gcd
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
for k in range(1, K + 1):
ans += gcd(gcd(i, j), k)
print(ans)
| import sys
from math import gcd
def solve(K: int):
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
for k in range(1, K + 1):
ans += gcd(gcd(i, j), k)
print(ans)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
K = int(next(tokens)) # type: int
solve(K)
if __name__ == "__main__":
main()
| false | 57.142857 | [
"+import sys",
"-K = int(eval(input()))",
"-ans = 0",
"-for i in range(1, K + 1):",
"- for j in range(1, K + 1):",
"- for k in range(1, K + 1):",
"- ans += gcd(gcd(i, j), k)",
"-print(ans)",
"+",
"+def solve(K: int):",
"+ ans = 0",
"+ for i in range(1, K + 1):",
"+ for j in range(1, K + 1):",
"+ for k in range(1, K + 1):",
"+ ans += gcd(gcd(i, j), k)",
"+ print(ans)",
"+ return",
"+",
"+",
"+def main():",
"+ def iterate_tokens():",
"+ for line in sys.stdin:",
"+ for word in line.split():",
"+ yield word",
"+",
"+ tokens = iterate_tokens()",
"+ K = int(next(tokens)) # type: int",
"+ solve(K)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.204518 | 0.155831 | 1.312436 | [
"s526139634",
"s864830246"
] |
u020390084 | p02913 | python | s262669049 | s581154448 | 677 | 104 | 48,476 | 9,636 | Accepted | Accepted | 84.64 | #!/usr/bin/env python3
import sys
def z_algo(S):
N = len(S)
LCPs = [0]*N
i = 1 ## iから何文字一致してるか調べる
j = 0
LCPs[0] = N
while i < N:
while i+j < N and S[j] == S[i+j]:
j += 1
if j == 0:
i += 1
continue
LCPs[i] = j
k = 1
while k+i < N and k+LCPs[k] < j:
LCPs[i+k] = LCPs[k]
k += 1
i += k
j -= k
return LCPs
def solve(N: int, S: str):
answer = 0
for i in range(N):
LCP = z_algo(S[i:])
for j in range(len(LCP)):
# jの長さまでなら重ならない
a = min(j,LCP[j])
answer = max(answer,a)
print(answer)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
solve(N, S)
if __name__ == '__main__':
main()
| N = int(eval(input()))
S = eval(input())
mod = 10**9+7
base = 1234
power = [1]*(N+1)
for i in range(1, N+1):
power[i] = power[i-1]*base%mod
def check(m):
dic = {}
for i in range(N-m+1):
s = S[i:i+m]
if s in list(dic.keys()):
if dic[s]+m<=i:
return True
else:
dic[s] = i
return False
ok = 0
ng = N+1
while ng-ok>1:
mid = (ok+ng)//2
if check(mid):
ok = mid
else:
ng = mid
print(ok) | 48 | 27 | 1,037 | 496 | #!/usr/bin/env python3
import sys
def z_algo(S):
N = len(S)
LCPs = [0] * N
i = 1 ## iから何文字一致してるか調べる
j = 0
LCPs[0] = N
while i < N:
while i + j < N and S[j] == S[i + j]:
j += 1
if j == 0:
i += 1
continue
LCPs[i] = j
k = 1
while k + i < N and k + LCPs[k] < j:
LCPs[i + k] = LCPs[k]
k += 1
i += k
j -= k
return LCPs
def solve(N: int, S: str):
answer = 0
for i in range(N):
LCP = z_algo(S[i:])
for j in range(len(LCP)):
# jの長さまでなら重ならない
a = min(j, LCP[j])
answer = max(answer, a)
print(answer)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
solve(N, S)
if __name__ == "__main__":
main()
| N = int(eval(input()))
S = eval(input())
mod = 10**9 + 7
base = 1234
power = [1] * (N + 1)
for i in range(1, N + 1):
power[i] = power[i - 1] * base % mod
def check(m):
dic = {}
for i in range(N - m + 1):
s = S[i : i + m]
if s in list(dic.keys()):
if dic[s] + m <= i:
return True
else:
dic[s] = i
return False
ok = 0
ng = N + 1
while ng - ok > 1:
mid = (ok + ng) // 2
if check(mid):
ok = mid
else:
ng = mid
print(ok)
| false | 43.75 | [
"-#!/usr/bin/env python3",
"-import sys",
"+N = int(eval(input()))",
"+S = eval(input())",
"+mod = 10**9 + 7",
"+base = 1234",
"+power = [1] * (N + 1)",
"+for i in range(1, N + 1):",
"+ power[i] = power[i - 1] * base % mod",
"-def z_algo(S):",
"- N = len(S)",
"- LCPs = [0] * N",
"- i = 1 ## iから何文字一致してるか調べる",
"- j = 0",
"- LCPs[0] = N",
"- while i < N:",
"- while i + j < N and S[j] == S[i + j]:",
"- j += 1",
"- if j == 0:",
"- i += 1",
"- continue",
"- LCPs[i] = j",
"- k = 1",
"- while k + i < N and k + LCPs[k] < j:",
"- LCPs[i + k] = LCPs[k]",
"- k += 1",
"- i += k",
"- j -= k",
"- return LCPs",
"+def check(m):",
"+ dic = {}",
"+ for i in range(N - m + 1):",
"+ s = S[i : i + m]",
"+ if s in list(dic.keys()):",
"+ if dic[s] + m <= i:",
"+ return True",
"+ else:",
"+ dic[s] = i",
"+ return False",
"-def solve(N: int, S: str):",
"- answer = 0",
"- for i in range(N):",
"- LCP = z_algo(S[i:])",
"- for j in range(len(LCP)):",
"- # jの長さまでなら重ならない",
"- a = min(j, LCP[j])",
"- answer = max(answer, a)",
"- print(answer)",
"- return",
"-",
"-",
"-def main():",
"- def iterate_tokens():",
"- for line in sys.stdin:",
"- for word in line.split():",
"- yield word",
"-",
"- tokens = iterate_tokens()",
"- N = int(next(tokens)) # type: int",
"- S = next(tokens) # type: str",
"- solve(N, S)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+ok = 0",
"+ng = N + 1",
"+while ng - ok > 1:",
"+ mid = (ok + ng) // 2",
"+ if check(mid):",
"+ ok = mid",
"+ else:",
"+ ng = mid",
"+print(ok)"
] | false | 0.037222 | 0.07488 | 0.497094 | [
"s262669049",
"s581154448"
] |
u600402037 | p02972 | python | s806161323 | s265766849 | 205 | 178 | 14,140 | 14,136 | Accepted | Accepted | 13.17 | def main(A,N):
A = [0] + A
for a in range(N-1,0,-1):
#print(inds[ind::ind+1])
if sum(A[a::a]) %2== 0:
A[a] = 0
else:
A[a] = 1
res = [x for x in range(0,N+1) if A[x]]
print((len(res)))
print((*res))
N = int(eval(input()))
A = [int(x) for x in input().split()]
main(A,N) | def main(A,N):
A = [0] + A
for a in range(N//2,0,-1):
#print(inds[ind::ind+1])
if sum(A[a::a]) %2== 0:
A[a] = 0
else:
A[a] = 1
res = [x for x in range(0,N+1) if A[x]]
print((len(res)))
print((*res))
N = int(eval(input()))
A = [int(x) for x in input().split()]
main(A,N)
| 17 | 17 | 357 | 359 | def main(A, N):
A = [0] + A
for a in range(N - 1, 0, -1):
# print(inds[ind::ind+1])
if sum(A[a::a]) % 2 == 0:
A[a] = 0
else:
A[a] = 1
res = [x for x in range(0, N + 1) if A[x]]
print((len(res)))
print((*res))
N = int(eval(input()))
A = [int(x) for x in input().split()]
main(A, N)
| def main(A, N):
A = [0] + A
for a in range(N // 2, 0, -1):
# print(inds[ind::ind+1])
if sum(A[a::a]) % 2 == 0:
A[a] = 0
else:
A[a] = 1
res = [x for x in range(0, N + 1) if A[x]]
print((len(res)))
print((*res))
N = int(eval(input()))
A = [int(x) for x in input().split()]
main(A, N)
| false | 0 | [
"- for a in range(N - 1, 0, -1):",
"+ for a in range(N // 2, 0, -1):"
] | false | 0.047424 | 0.112182 | 0.422738 | [
"s806161323",
"s265766849"
] |
u941407962 | p02763 | python | s205605071 | s598990040 | 920 | 739 | 164,952 | 172,228 | Accepted | Accepted | 19.67 | import sys
input = sys.stdin.readline
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
if i == 0:
return 0
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
aas = "abcdefghijklmnopqrstuvwxyz"
N = int(input().strip())
S = [" "]+list(input().strip())
Q = int(input().strip())
cbt = dict()
for c in aas:
cbt[c] = Bit(N)
for i, a in enumerate(S):
if i == 0:
continue
if a == c:
cbt[c].add(i, 1)
for _ in range(Q):
t, i, c = input().split()
t = int(t)
if t == 1:
i = int(i)
if S[i] != c:
cbt[S[i]].add(i, -1)
cbt[c].add(i, 1)
S[i] = c
else:
l, r = int(i), int(c)
s = 0
for a in aas:
bt = cbt[a]
s += (bt.sum(r)-bt.sum(l-1)>0)
print(s)
| import sys
input = sys.stdin.readline
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
x = "abcdefghijklmnopqrstuvwxyz"
N, = list(map(int, input().split()))
d = dict()
for c in x:
d[c] = Bit(N+1)
S = list(input().strip())
for i, c in enumerate(S):
d[c].add(i+1, 1)
Q = int(eval(input()))
for _ in range(Q):
t, a, b = input().split()
if t == '1':
i, c = int(a), b
b = S[i-1]
S[i-1] = c
d[b].add(i, -1)
d[c].add(i, 1)
else:
l, r = int(a), int(b)
rr = 0
for c in x:
if d[c].sum(r) - d[c].sum(l-1) > 0:
rr += 1
print(rr)
| 49 | 44 | 1,107 | 1,062 | import sys
input = sys.stdin.readline
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
if i == 0:
return 0
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
aas = "abcdefghijklmnopqrstuvwxyz"
N = int(input().strip())
S = [" "] + list(input().strip())
Q = int(input().strip())
cbt = dict()
for c in aas:
cbt[c] = Bit(N)
for i, a in enumerate(S):
if i == 0:
continue
if a == c:
cbt[c].add(i, 1)
for _ in range(Q):
t, i, c = input().split()
t = int(t)
if t == 1:
i = int(i)
if S[i] != c:
cbt[S[i]].add(i, -1)
cbt[c].add(i, 1)
S[i] = c
else:
l, r = int(i), int(c)
s = 0
for a in aas:
bt = cbt[a]
s += bt.sum(r) - bt.sum(l - 1) > 0
print(s)
| import sys
input = sys.stdin.readline
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
x = "abcdefghijklmnopqrstuvwxyz"
(N,) = list(map(int, input().split()))
d = dict()
for c in x:
d[c] = Bit(N + 1)
S = list(input().strip())
for i, c in enumerate(S):
d[c].add(i + 1, 1)
Q = int(eval(input()))
for _ in range(Q):
t, a, b = input().split()
if t == "1":
i, c = int(a), b
b = S[i - 1]
S[i - 1] = c
d[b].add(i, -1)
d[c].add(i, 1)
else:
l, r = int(a), int(b)
rr = 0
for c in x:
if d[c].sum(r) - d[c].sum(l - 1) > 0:
rr += 1
print(rr)
| false | 10.204082 | [
"- if i == 0:",
"- return 0",
"-aas = \"abcdefghijklmnopqrstuvwxyz\"",
"-N = int(input().strip())",
"-S = [\" \"] + list(input().strip())",
"-Q = int(input().strip())",
"-cbt = dict()",
"-for c in aas:",
"- cbt[c] = Bit(N)",
"- for i, a in enumerate(S):",
"- if i == 0:",
"- continue",
"- if a == c:",
"- cbt[c].add(i, 1)",
"+x = \"abcdefghijklmnopqrstuvwxyz\"",
"+(N,) = list(map(int, input().split()))",
"+d = dict()",
"+for c in x:",
"+ d[c] = Bit(N + 1)",
"+S = list(input().strip())",
"+for i, c in enumerate(S):",
"+ d[c].add(i + 1, 1)",
"+Q = int(eval(input()))",
"- t, i, c = input().split()",
"- t = int(t)",
"- if t == 1:",
"- i = int(i)",
"- if S[i] != c:",
"- cbt[S[i]].add(i, -1)",
"- cbt[c].add(i, 1)",
"- S[i] = c",
"+ t, a, b = input().split()",
"+ if t == \"1\":",
"+ i, c = int(a), b",
"+ b = S[i - 1]",
"+ S[i - 1] = c",
"+ d[b].add(i, -1)",
"+ d[c].add(i, 1)",
"- l, r = int(i), int(c)",
"- s = 0",
"- for a in aas:",
"- bt = cbt[a]",
"- s += bt.sum(r) - bt.sum(l - 1) > 0",
"- print(s)",
"+ l, r = int(a), int(b)",
"+ rr = 0",
"+ for c in x:",
"+ if d[c].sum(r) - d[c].sum(l - 1) > 0:",
"+ rr += 1",
"+ print(rr)"
] | false | 0.116716 | 0.037492 | 3.113138 | [
"s205605071",
"s598990040"
] |
u098012509 | p02585 | python | s747428058 | s195937136 | 1,021 | 779 | 74,196 | 74,004 | Accepted | Accepted | 23.7 | import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
def main():
N, K = [int(x) for x in input().split()]
P = [int(x) - 1 for x in input().split()]
C = [int(x) for x in input().split()]
ans = max(C)
for i in range(N):
next = P[i]
cnt = 0
tmp = 0
while True:
tmp += C[next]
ans = max(ans, tmp)
cnt += 1
if cnt == K or next == i:
break
next = P[next]
if cnt == K or tmp <= 0:
continue
q = K // cnt
r = K % cnt
next = P[i]
if q != 0:
tmp *= (q - 1)
q -= 1
r += cnt
ans = max(ans, tmp)
else:
tmp = 0
while r > 0:
tmp += C[next]
ans = max(ans, tmp)
next = P[next]
r -= 1
print(ans)
if __name__ == '__main__':
main()
| import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
def main():
N, K = [int(x) for x in input().split()]
P = [int(x) - 1 for x in input().split()]
C = [int(x) for x in input().split()]
ans = max(C)
for i in range(N):
next = P[i]
cnt = 0
cycle_value = 0
while True:
cycle_value += C[next]
cnt += 1
if next == i:
break
next = P[next]
j = 0
tmp = 0
next = P[i]
while True:
tmp += C[next]
j += 1
ans = max(ans, tmp + ((K - j) // cnt) * max(0, cycle_value))
if j == K or next == i:
break
next = P[next]
print(ans)
if __name__ == '__main__':
main()
| 49 | 40 | 997 | 840 | import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
def main():
N, K = [int(x) for x in input().split()]
P = [int(x) - 1 for x in input().split()]
C = [int(x) for x in input().split()]
ans = max(C)
for i in range(N):
next = P[i]
cnt = 0
tmp = 0
while True:
tmp += C[next]
ans = max(ans, tmp)
cnt += 1
if cnt == K or next == i:
break
next = P[next]
if cnt == K or tmp <= 0:
continue
q = K // cnt
r = K % cnt
next = P[i]
if q != 0:
tmp *= q - 1
q -= 1
r += cnt
ans = max(ans, tmp)
else:
tmp = 0
while r > 0:
tmp += C[next]
ans = max(ans, tmp)
next = P[next]
r -= 1
print(ans)
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
def main():
N, K = [int(x) for x in input().split()]
P = [int(x) - 1 for x in input().split()]
C = [int(x) for x in input().split()]
ans = max(C)
for i in range(N):
next = P[i]
cnt = 0
cycle_value = 0
while True:
cycle_value += C[next]
cnt += 1
if next == i:
break
next = P[next]
j = 0
tmp = 0
next = P[i]
while True:
tmp += C[next]
j += 1
ans = max(ans, tmp + ((K - j) // cnt) * max(0, cycle_value))
if j == K or next == i:
break
next = P[next]
print(ans)
if __name__ == "__main__":
main()
| false | 18.367347 | [
"+ cycle_value = 0",
"+ while True:",
"+ cycle_value += C[next]",
"+ cnt += 1",
"+ if next == i:",
"+ break",
"+ next = P[next]",
"+ j = 0",
"+ next = P[i]",
"- ans = max(ans, tmp)",
"- cnt += 1",
"- if cnt == K or next == i:",
"+ j += 1",
"+ ans = max(ans, tmp + ((K - j) // cnt) * max(0, cycle_value))",
"+ if j == K or next == i:",
"- if cnt == K or tmp <= 0:",
"- continue",
"- q = K // cnt",
"- r = K % cnt",
"- next = P[i]",
"- if q != 0:",
"- tmp *= q - 1",
"- q -= 1",
"- r += cnt",
"- ans = max(ans, tmp)",
"- else:",
"- tmp = 0",
"- while r > 0:",
"- tmp += C[next]",
"- ans = max(ans, tmp)",
"- next = P[next]",
"- r -= 1"
] | false | 0.039451 | 0.036986 | 1.066644 | [
"s747428058",
"s195937136"
] |
u089032001 | p03241 | python | s957257180 | s886426608 | 23 | 21 | 3,064 | 3,060 | Accepted | Accepted | 8.7 | from itertools import product
N, M = list(map(int, input().split()))
max_ans = M // N
ans = 1
tmp = 2
tmpM = M
max_prime = int(M ** 0.5)
all_list = []
i = -1
k = 0
div = 2
while tmpM != 1:
if tmpM % div == 0:
tmpM = tmpM // div
if k == 0:
i += 1
all_list.append(set())
all_list[i].add(div ** k)
k += 1
all_list[i].add(div ** k)
k += 1
else:
k = 0
if div == 2:
div = 3
elif div > max_prime:
div = tmpM
else:
div += 2
if all_list == []:
print((1))
exit()
# print(all_list)
ans = 1
for div_tuple in product(*all_list):
tmp = 1
for k in div_tuple:
tmp *= k
if tmp > max_ans:
break
else:
ans = max(ans, tmp)
print(ans) | N, M = list(map(int, input().split()))
max_ans = M // N
ans = 1
for n in range(1, int(M ** 0.5) + 1):
if M % n != 0:
continue
if n <= max_ans:
ans = max(ans, n)
if M // n <= max_ans:
ans = max(ans, M // n)
print(ans) | 51 | 16 | 875 | 266 | from itertools import product
N, M = list(map(int, input().split()))
max_ans = M // N
ans = 1
tmp = 2
tmpM = M
max_prime = int(M**0.5)
all_list = []
i = -1
k = 0
div = 2
while tmpM != 1:
if tmpM % div == 0:
tmpM = tmpM // div
if k == 0:
i += 1
all_list.append(set())
all_list[i].add(div**k)
k += 1
all_list[i].add(div**k)
k += 1
else:
k = 0
if div == 2:
div = 3
elif div > max_prime:
div = tmpM
else:
div += 2
if all_list == []:
print((1))
exit()
# print(all_list)
ans = 1
for div_tuple in product(*all_list):
tmp = 1
for k in div_tuple:
tmp *= k
if tmp > max_ans:
break
else:
ans = max(ans, tmp)
print(ans)
| N, M = list(map(int, input().split()))
max_ans = M // N
ans = 1
for n in range(1, int(M**0.5) + 1):
if M % n != 0:
continue
if n <= max_ans:
ans = max(ans, n)
if M // n <= max_ans:
ans = max(ans, M // n)
print(ans)
| false | 68.627451 | [
"-from itertools import product",
"-",
"-tmp = 2",
"-tmpM = M",
"-max_prime = int(M**0.5)",
"-all_list = []",
"-i = -1",
"-k = 0",
"-div = 2",
"-while tmpM != 1:",
"- if tmpM % div == 0:",
"- tmpM = tmpM // div",
"- if k == 0:",
"- i += 1",
"- all_list.append(set())",
"- all_list[i].add(div**k)",
"- k += 1",
"- all_list[i].add(div**k)",
"- k += 1",
"- else:",
"- k = 0",
"- if div == 2:",
"- div = 3",
"- elif div > max_prime:",
"- div = tmpM",
"- else:",
"- div += 2",
"-if all_list == []:",
"- print((1))",
"- exit()",
"-# print(all_list)",
"-ans = 1",
"-for div_tuple in product(*all_list):",
"- tmp = 1",
"- for k in div_tuple:",
"- tmp *= k",
"- if tmp > max_ans:",
"- break",
"- else:",
"- ans = max(ans, tmp)",
"+for n in range(1, int(M**0.5) + 1):",
"+ if M % n != 0:",
"+ continue",
"+ if n <= max_ans:",
"+ ans = max(ans, n)",
"+ if M // n <= max_ans:",
"+ ans = max(ans, M // n)"
] | false | 0.043203 | 0.045253 | 0.954682 | [
"s957257180",
"s886426608"
] |
u543954314 | p02647 | python | s825995352 | s155077452 | 1,173 | 881 | 125,696 | 129,840 | Accepted | Accepted | 24.89 | import sys
from itertools import accumulate
from numba import njit
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
@njit
def solve(n, k, a):
b = [0]*n
for _ in range(k):
for i in range(n):
if i > a[i]:
b[i-a[i]] += 1
else:
b[0] += 1
if i + a[i] + 1 < n:
b[i + a[i] + 1] -= 1
for i in range(n-1):
b[i+1] += b[i]
a[i] = 0
a[-1] = 0
b, a = a, b
if min(a) >= n:
break
return a
n, k = nm()
a = nl()
print(*solve(n, k, a))
| import sys
from numba import njit
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
@njit(cache=True)
def solve(n, k, a):
if k == 0:
return a
b = [0]*n
for _ in range(k):
for i in range(n):
if i > a[i]:
b[i-a[i]] += 1
else:
b[0] += 1
if i + a[i] + 1 < n:
b[i + a[i] + 1] -= 1
for i in range(n-1):
b[i+1] += b[i]
a[i] = 0
a[-1] = 0
b, a = a, b
if min(a) >= n:
break
return a
solve(0, 0, [0, 1, 2])
n, k = nm()
a = nl()
print(*solve(n, k, a))
| 35 | 37 | 830 | 865 | import sys
from itertools import accumulate
from numba import njit
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep="\n")
@njit
def solve(n, k, a):
b = [0] * n
for _ in range(k):
for i in range(n):
if i > a[i]:
b[i - a[i]] += 1
else:
b[0] += 1
if i + a[i] + 1 < n:
b[i + a[i] + 1] -= 1
for i in range(n - 1):
b[i + 1] += b[i]
a[i] = 0
a[-1] = 0
b, a = a, b
if min(a) >= n:
break
return a
n, k = nm()
a = nl()
print(*solve(n, k, a))
| import sys
from numba import njit
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep="\n")
@njit(cache=True)
def solve(n, k, a):
if k == 0:
return a
b = [0] * n
for _ in range(k):
for i in range(n):
if i > a[i]:
b[i - a[i]] += 1
else:
b[0] += 1
if i + a[i] + 1 < n:
b[i + a[i] + 1] -= 1
for i in range(n - 1):
b[i + 1] += b[i]
a[i] = 0
a[-1] = 0
b, a = a, b
if min(a) >= n:
break
return a
solve(0, 0, [0, 1, 2])
n, k = nm()
a = nl()
print(*solve(n, k, a))
| false | 5.405405 | [
"-from itertools import accumulate",
"-@njit",
"+@njit(cache=True)",
"+ if k == 0:",
"+ return a",
"+solve(0, 0, [0, 1, 2])"
] | false | 0.139842 | 0.089991 | 1.553957 | [
"s825995352",
"s155077452"
] |
u820839927 | p03035 | python | s515780514 | s215401891 | 174 | 22 | 38,256 | 3,316 | Accepted | Accepted | 87.36 | import os, sys, re, math
A,B = [int(s) for s in input().split(' ')]
if A < 6:
print((0))
elif 6 <= A and A <= 12:
print((int(B/2)))
else:
print(B)
| import os, sys, re, math
A,B = list(map(int,input().split(' ')))
if A >= 13:
print(B)
elif A >= 6:
print((B // 2))
else:
print((0)) | 10 | 9 | 166 | 139 | import os, sys, re, math
A, B = [int(s) for s in input().split(" ")]
if A < 6:
print((0))
elif 6 <= A and A <= 12:
print((int(B / 2)))
else:
print(B)
| import os, sys, re, math
A, B = list(map(int, input().split(" ")))
if A >= 13:
print(B)
elif A >= 6:
print((B // 2))
else:
print((0))
| false | 10 | [
"-A, B = [int(s) for s in input().split(\" \")]",
"-if A < 6:",
"+A, B = list(map(int, input().split(\" \")))",
"+if A >= 13:",
"+ print(B)",
"+elif A >= 6:",
"+ print((B // 2))",
"+else:",
"-elif 6 <= A and A <= 12:",
"- print((int(B / 2)))",
"-else:",
"- print(B)"
] | false | 0.037894 | 0.045218 | 0.838027 | [
"s515780514",
"s215401891"
] |
u564589929 | p03087 | python | s716641543 | s523548165 | 356 | 276 | 53,068 | 6,380 | Accepted | Accepted | 22.47 | import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
INF = float('inf')
def solve():
n, q = MI()
S = eval(input())
ats = [0]
cnt = 0
for i in range(n-1):
j = i + 2
s = S[i:j]
# print(s)
if s == 'AC':
cnt += 1
ats.append(cnt)
# print(ats)
for _ in range(q):
l, r = MI1()
# print(S[l:r+1])
print((ats[r] - ats[l]))
if __name__ == '__main__':
solve()
| import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
INF = float('inf')
def solve():
n, q = MI()
S = eval(input())
ats = [0] * n
cnt = 0
for i in range(n-1):
j = i + 2
s = S[i:j]
# print(s)
if s == 'AC':
cnt += 1
ats[i+1] = cnt
# print(ats)
for _ in range(q):
l, r = MI1()
# print(S[l:r+1])
print((ats[r] - ats[l]))
if __name__ == '__main__':
solve()
| 36 | 36 | 823 | 826 | import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LI1():
return list(map(int1, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
INF = float("inf")
def solve():
n, q = MI()
S = eval(input())
ats = [0]
cnt = 0
for i in range(n - 1):
j = i + 2
s = S[i:j]
# print(s)
if s == "AC":
cnt += 1
ats.append(cnt)
# print(ats)
for _ in range(q):
l, r = MI1()
# print(S[l:r+1])
print((ats[r] - ats[l]))
if __name__ == "__main__":
solve()
| import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LI1():
return list(map(int1, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
INF = float("inf")
def solve():
n, q = MI()
S = eval(input())
ats = [0] * n
cnt = 0
for i in range(n - 1):
j = i + 2
s = S[i:j]
# print(s)
if s == "AC":
cnt += 1
ats[i + 1] = cnt
# print(ats)
for _ in range(q):
l, r = MI1()
# print(S[l:r+1])
print((ats[r] - ats[l]))
if __name__ == "__main__":
solve()
| false | 0 | [
"- ats = [0]",
"+ ats = [0] * n",
"- ats.append(cnt)",
"+ ats[i + 1] = cnt"
] | false | 0.044529 | 0.092631 | 0.480716 | [
"s716641543",
"s523548165"
] |
u072717685 | p02596 | python | s348978984 | s547630275 | 193 | 140 | 9,048 | 9,124 | Accepted | Accepted | 27.46 | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
k = int(eval(input()))
if k % 2 == 0 or k % 5 == 0:
print((-1))
sys.exit()
p = 7 # '7,77,777…'のmod kをいれる変数
plus = 7 # '70,700,7000…'のmod kをいれる変数
r = 1 # カウント
while (p % k) != 0: # kで割り切れるかチェック
plus = (plus * 10) % k # pに足すもう1桁のmod kを計算。
p += plus # pにもう1桁を足す
p = p % k # pのmod kをとる
r += 1
print(r)
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
k = int(eval(input()))
if k % 2 == 0 or k % 5 == 0:
print((-1))
sys.exit()
if k % 7 == 0:
l = k * 9 // 7
else:
l = k * 9
r = 1 # カウント
p = 10 ** r
while (p % l) != 1:
p = (p * 10) % l
r += 1
print(r)
if __name__ == '__main__':
main()
| 20 | 21 | 548 | 413 | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
k = int(eval(input()))
if k % 2 == 0 or k % 5 == 0:
print((-1))
sys.exit()
p = 7 # '7,77,777…'のmod kをいれる変数
plus = 7 # '70,700,7000…'のmod kをいれる変数
r = 1 # カウント
while (p % k) != 0: # kで割り切れるかチェック
plus = (plus * 10) % k # pに足すもう1桁のmod kを計算。
p += plus # pにもう1桁を足す
p = p % k # pのmod kをとる
r += 1
print(r)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
k = int(eval(input()))
if k % 2 == 0 or k % 5 == 0:
print((-1))
sys.exit()
if k % 7 == 0:
l = k * 9 // 7
else:
l = k * 9
r = 1 # カウント
p = 10**r
while (p % l) != 1:
p = (p * 10) % l
r += 1
print(r)
if __name__ == "__main__":
main()
| false | 4.761905 | [
"- p = 7 # '7,77,777…'のmod kをいれる変数",
"- plus = 7 # '70,700,7000…'のmod kをいれる変数",
"+ if k % 7 == 0:",
"+ l = k * 9 // 7",
"+ else:",
"+ l = k * 9",
"- while (p % k) != 0: # kで割り切れるかチェック",
"- plus = (plus * 10) % k # pに足すもう1桁のmod kを計算。",
"- p += plus # pにもう1桁を足す",
"- p = p % k # pのmod kをとる",
"+ p = 10**r",
"+ while (p % l) != 1:",
"+ p = (p * 10) % l"
] | false | 0.11339 | 0.097437 | 1.163726 | [
"s348978984",
"s547630275"
] |
u347600233 | p02689 | python | s539190357 | s152705799 | 486 | 405 | 46,136 | 29,480 | Accepted | Accepted | 16.67 | n, m = list(map(int, input().split()))
h = [int(i) for i in input().split()]
path = [[] for i in range(n)]
set_path = set()
for i in range(m):
a, b = list(map(int, input().split()))
path[a - 1].append(b - 1)
path[b - 1].append(a - 1)
set_path |= set((a - 1, b - 1))
cnt = n - len(set_path)
path_ = {int(i) for i in range(n)}
for i in set_path:
if max([h[j] for j in path[i]]) < h[i]:
cnt += 1
print(cnt) | n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
to = [[] for i in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
to[a - 1] += [b - 1]
to[b - 1] += [a - 1]
print((sum(to[j] == [] or h[j] > max(h[i] for i in to[j]) for j in range(n)))) | 15 | 8 | 433 | 286 | n, m = list(map(int, input().split()))
h = [int(i) for i in input().split()]
path = [[] for i in range(n)]
set_path = set()
for i in range(m):
a, b = list(map(int, input().split()))
path[a - 1].append(b - 1)
path[b - 1].append(a - 1)
set_path |= set((a - 1, b - 1))
cnt = n - len(set_path)
path_ = {int(i) for i in range(n)}
for i in set_path:
if max([h[j] for j in path[i]]) < h[i]:
cnt += 1
print(cnt)
| n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
to = [[] for i in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
to[a - 1] += [b - 1]
to[b - 1] += [a - 1]
print((sum(to[j] == [] or h[j] > max(h[i] for i in to[j]) for j in range(n))))
| false | 46.666667 | [
"-h = [int(i) for i in input().split()]",
"-path = [[] for i in range(n)]",
"-set_path = set()",
"+h = list(map(int, input().split()))",
"+to = [[] for i in range(n)]",
"- path[a - 1].append(b - 1)",
"- path[b - 1].append(a - 1)",
"- set_path |= set((a - 1, b - 1))",
"-cnt = n - len(set_path)",
"-path_ = {int(i) for i in range(n)}",
"-for i in set_path:",
"- if max([h[j] for j in path[i]]) < h[i]:",
"- cnt += 1",
"-print(cnt)",
"+ to[a - 1] += [b - 1]",
"+ to[b - 1] += [a - 1]",
"+print((sum(to[j] == [] or h[j] > max(h[i] for i in to[j]) for j in range(n))))"
] | false | 0.05026 | 0.045605 | 1.102053 | [
"s539190357",
"s152705799"
] |
u576398884 | p02257 | python | s820151179 | s294118303 | 3,000 | 40 | 7,776 | 7,704 | Accepted | Accepted | 98.67 | import math
ans = 0
N = int(eval(input()))
for i in range(N):
a = int(eval(input()))
if a != 2 and a%2 == 0:
continue
b = True
for j in range(3, int(math.sqrt(a))+1, 2):
if a%j == 0:
b = False
if b:
ans += 1
print(ans) | ans = 0
N = int(eval(input()))
for i in range(N):
a = int(eval(input()))
if a == 2:
ans += 1
elif a%2 == 0:
continue
else:
if pow(2, a-1, a) == 1:
ans += 1
print(ans) | 16 | 13 | 279 | 219 | import math
ans = 0
N = int(eval(input()))
for i in range(N):
a = int(eval(input()))
if a != 2 and a % 2 == 0:
continue
b = True
for j in range(3, int(math.sqrt(a)) + 1, 2):
if a % j == 0:
b = False
if b:
ans += 1
print(ans)
| ans = 0
N = int(eval(input()))
for i in range(N):
a = int(eval(input()))
if a == 2:
ans += 1
elif a % 2 == 0:
continue
else:
if pow(2, a - 1, a) == 1:
ans += 1
print(ans)
| false | 18.75 | [
"-import math",
"-",
"- if a != 2 and a % 2 == 0:",
"+ if a == 2:",
"+ ans += 1",
"+ elif a % 2 == 0:",
"- b = True",
"- for j in range(3, int(math.sqrt(a)) + 1, 2):",
"- if a % j == 0:",
"- b = False",
"- if b:",
"- ans += 1",
"+ else:",
"+ if pow(2, a - 1, a) == 1:",
"+ ans += 1"
] | false | 0.064082 | 0.063001 | 1.017146 | [
"s820151179",
"s294118303"
] |
u226155577 | p03083 | python | s487825930 | s229337428 | 641 | 592 | 70,008 | 65,912 | Accepted | Accepted | 7.64 | import sys
B, W = list(map(int, sys.stdin.readline().split()))
MOD = 10**9 + 7
L = B+W
fact = [1]*(L+1)
rfact = [1]*(L+1)
for i in range(L):
fact[i+1] = r = fact[i] * (i+1) % MOD
rfact[i+1] = pow(r, MOD-2, MOD)
rev2 = pow(2, MOD-2, MOD)
p = q = 0
base = 1
ans = ["%d\n" % rev2]
for i in range(1, B+W):
base = rev2 * base % MOD
if i-B >= 0:
p = (p + (fact[i-1]*rfact[B-1]*rfact[i-B] % MOD)*base % MOD) % MOD
if i-W >= 0:
q = (q + (fact[i-1]*rfact[W-1]*rfact[i-W] % MOD)*base % MOD) % MOD
ans.append("%d\n" % ((1-p+q)*rev2 % MOD))
sys.stdout.writelines(ans) | import sys
B, W = list(map(int, sys.stdin.readline().split()))
MOD = 10**9 + 7
L = B+W
fact = [1]*(L+1)
rfact = [1]*(L+1)
for i in range(L):
fact[i+1] = r = fact[i] * (i+1) % MOD
rfact[i+1] = pow(r, MOD-2, MOD)
rev2 = pow(2, MOD-2, MOD)
p = q = 0
base = 1
ans = ["%d\n" % rev2]
for i in range(1, B+W):
base = rev2 * base % MOD
if i-B >= 0:
p = (p + ((fact[i-1]*rfact[B-1] % MOD)*rfact[i-B] % MOD)*base % MOD) % MOD
if i-W >= 0:
q = (q + ((fact[i-1]*rfact[W-1] % MOD)*rfact[i-W] % MOD)*base % MOD) % MOD
ans.append("%d\n" % ((1-p+q)*rev2 % MOD))
sys.stdout.writelines(ans) | 25 | 25 | 617 | 633 | import sys
B, W = list(map(int, sys.stdin.readline().split()))
MOD = 10**9 + 7
L = B + W
fact = [1] * (L + 1)
rfact = [1] * (L + 1)
for i in range(L):
fact[i + 1] = r = fact[i] * (i + 1) % MOD
rfact[i + 1] = pow(r, MOD - 2, MOD)
rev2 = pow(2, MOD - 2, MOD)
p = q = 0
base = 1
ans = ["%d\n" % rev2]
for i in range(1, B + W):
base = rev2 * base % MOD
if i - B >= 0:
p = (p + (fact[i - 1] * rfact[B - 1] * rfact[i - B] % MOD) * base % MOD) % MOD
if i - W >= 0:
q = (q + (fact[i - 1] * rfact[W - 1] * rfact[i - W] % MOD) * base % MOD) % MOD
ans.append("%d\n" % ((1 - p + q) * rev2 % MOD))
sys.stdout.writelines(ans)
| import sys
B, W = list(map(int, sys.stdin.readline().split()))
MOD = 10**9 + 7
L = B + W
fact = [1] * (L + 1)
rfact = [1] * (L + 1)
for i in range(L):
fact[i + 1] = r = fact[i] * (i + 1) % MOD
rfact[i + 1] = pow(r, MOD - 2, MOD)
rev2 = pow(2, MOD - 2, MOD)
p = q = 0
base = 1
ans = ["%d\n" % rev2]
for i in range(1, B + W):
base = rev2 * base % MOD
if i - B >= 0:
p = (
p + ((fact[i - 1] * rfact[B - 1] % MOD) * rfact[i - B] % MOD) * base % MOD
) % MOD
if i - W >= 0:
q = (
q + ((fact[i - 1] * rfact[W - 1] % MOD) * rfact[i - W] % MOD) * base % MOD
) % MOD
ans.append("%d\n" % ((1 - p + q) * rev2 % MOD))
sys.stdout.writelines(ans)
| false | 0 | [
"- p = (p + (fact[i - 1] * rfact[B - 1] * rfact[i - B] % MOD) * base % MOD) % MOD",
"+ p = (",
"+ p + ((fact[i - 1] * rfact[B - 1] % MOD) * rfact[i - B] % MOD) * base % MOD",
"+ ) % MOD",
"- q = (q + (fact[i - 1] * rfact[W - 1] * rfact[i - W] % MOD) * base % MOD) % MOD",
"+ q = (",
"+ q + ((fact[i - 1] * rfact[W - 1] % MOD) * rfact[i - W] % MOD) * base % MOD",
"+ ) % MOD"
] | false | 0.058631 | 0.099996 | 0.586331 | [
"s487825930",
"s229337428"
] |
u197300773 | p03476 | python | s737327748 | s167896180 | 858 | 242 | 5,144 | 5,460 | Accepted | Accepted | 71.79 | import math
def sieve(n):
if n < 2:
is_prime = [False for _ in range(n+1)]
return is_prime
is_prime = [True for _ in range(n+1)]
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5)+1):
if is_prime[i]:
for j in range(i*2, n+1, i):
is_prime[j] = False
return is_prime
N=10**5
prime=sieve(N)
a=[0 for i in range(N+1)]
for i in range(3,N):
if prime[i] and prime[(i+1)//2]: a[i]=a[i-1]+1
else: a[i]=a[i-1]
Q=int(eval(input()))
for i in range(Q):
l,r=list(map(int,input().split()))
print((a[r]-a[l-1])) | import sys
def sieve(n):
if n < 2:
is_prime = [False for _ in range(n+1)]
return is_prime
is_prime = [True for _ in range(n+1)]
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5)+1):
if is_prime[i]:
for j in range(i*2, n+1, i):
is_prime[j] = False
return is_prime
def main():
input = sys.stdin.readline
Q = int(eval(input()))
is_prime = sieve(10**5)
A = [0 for _ in range(10**5 + 1)]
for i in range(3, 10**5 + 1):
if is_prime[i] and is_prime[(i+1)//2]:
A[i] = A[i-1] + 1
else:
A[i] = A[i-1]
for _ in range(Q):
l, r = list(map(int, input().split()))
print((A[r] - A[l-1]))
if __name__ == '__main__':
main()
| 28 | 37 | 615 | 816 | import math
def sieve(n):
if n < 2:
is_prime = [False for _ in range(n + 1)]
return is_prime
is_prime = [True for _ in range(n + 1)]
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if is_prime[i]:
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return is_prime
N = 10**5
prime = sieve(N)
a = [0 for i in range(N + 1)]
for i in range(3, N):
if prime[i] and prime[(i + 1) // 2]:
a[i] = a[i - 1] + 1
else:
a[i] = a[i - 1]
Q = int(eval(input()))
for i in range(Q):
l, r = list(map(int, input().split()))
print((a[r] - a[l - 1]))
| import sys
def sieve(n):
if n < 2:
is_prime = [False for _ in range(n + 1)]
return is_prime
is_prime = [True for _ in range(n + 1)]
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if is_prime[i]:
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return is_prime
def main():
input = sys.stdin.readline
Q = int(eval(input()))
is_prime = sieve(10**5)
A = [0 for _ in range(10**5 + 1)]
for i in range(3, 10**5 + 1):
if is_prime[i] and is_prime[(i + 1) // 2]:
A[i] = A[i - 1] + 1
else:
A[i] = A[i - 1]
for _ in range(Q):
l, r = list(map(int, input().split()))
print((A[r] - A[l - 1]))
if __name__ == "__main__":
main()
| false | 24.324324 | [
"-import math",
"+import sys",
"-N = 10**5",
"-prime = sieve(N)",
"-a = [0 for i in range(N + 1)]",
"-for i in range(3, N):",
"- if prime[i] and prime[(i + 1) // 2]:",
"- a[i] = a[i - 1] + 1",
"- else:",
"- a[i] = a[i - 1]",
"-Q = int(eval(input()))",
"-for i in range(Q):",
"- l, r = list(map(int, input().split()))",
"- print((a[r] - a[l - 1]))",
"+def main():",
"+ input = sys.stdin.readline",
"+ Q = int(eval(input()))",
"+ is_prime = sieve(10**5)",
"+ A = [0 for _ in range(10**5 + 1)]",
"+ for i in range(3, 10**5 + 1):",
"+ if is_prime[i] and is_prime[(i + 1) // 2]:",
"+ A[i] = A[i - 1] + 1",
"+ else:",
"+ A[i] = A[i - 1]",
"+ for _ in range(Q):",
"+ l, r = list(map(int, input().split()))",
"+ print((A[r] - A[l - 1]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.482191 | 0.068064 | 7.084394 | [
"s737327748",
"s167896180"
] |
u729133443 | p02783 | python | s015672400 | s455901674 | 183 | 17 | 38,384 | 2,940 | Accepted | Accepted | 90.71 | print((-eval(input().replace(' ','//-')))) | a,b=list(map(int,input().split()))
print((0--a//b)) | 1 | 2 | 40 | 44 | print((-eval(input().replace(" ", "//-"))))
| a, b = list(map(int, input().split()))
print((0 - -a // b))
| false | 50 | [
"-print((-eval(input().replace(\" \", \"//-\"))))",
"+a, b = list(map(int, input().split()))",
"+print((0 - -a // b))"
] | false | 0.042593 | 0.03905 | 1.090729 | [
"s015672400",
"s455901674"
] |
u644907318 | p04030 | python | s758390486 | s853178423 | 163 | 69 | 38,256 | 61,608 | Accepted | Accepted | 57.67 | s = input().strip()
x = ""
for i in range(len(s)):
a = s[i]
if a!="B":
x += s[i]
elif len(x)>0:
x = x[:-1]
print(x) | s = input().strip()
x = ""
cur = 0
for i in range(len(s)):
if s[i]=="0":
x += "0"
cur += 1
elif s[i]=="1":
x += "1"
cur += 1
else:
if cur>0:
x = x[:-1]
cur -= 1
print(x) | 9 | 15 | 151 | 259 | s = input().strip()
x = ""
for i in range(len(s)):
a = s[i]
if a != "B":
x += s[i]
elif len(x) > 0:
x = x[:-1]
print(x)
| s = input().strip()
x = ""
cur = 0
for i in range(len(s)):
if s[i] == "0":
x += "0"
cur += 1
elif s[i] == "1":
x += "1"
cur += 1
else:
if cur > 0:
x = x[:-1]
cur -= 1
print(x)
| false | 40 | [
"+cur = 0",
"- a = s[i]",
"- if a != \"B\":",
"- x += s[i]",
"- elif len(x) > 0:",
"- x = x[:-1]",
"+ if s[i] == \"0\":",
"+ x += \"0\"",
"+ cur += 1",
"+ elif s[i] == \"1\":",
"+ x += \"1\"",
"+ cur += 1",
"+ else:",
"+ if cur > 0:",
"+ x = x[:-1]",
"+ cur -= 1"
] | false | 0.148567 | 0.078798 | 1.885399 | [
"s758390486",
"s853178423"
] |
u645250356 | p02936 | python | s555420915 | s934299313 | 1,971 | 959 | 237,760 | 122,000 | Accepted | Accepted | 51.34 | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
n,q = inpl()
g = [[]for i in range(n)]
c = [0 for i in range(n)]
seen = [False] * n
for i in range(n-1):
a,b = inpl()
g[a-1].append(b-1)
g[b-1].append(a-1)
for i in range(q):
a,b = inpl()
c[a-1] += b
def dfs(node):
for v in g[node]:
if seen[v]:
continue
c[v] += c[node]
seen[v] = True
dfs(v)
seen[0] = True
dfs(0)
for i in c:
print(i) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,q = inpl()
g = [[] for _ in range(n)]
for i in range(n-1):
a,b = inpl()
a -= 1; b -= 1
g[a].append(b)
g[b].append(a)
c = [0] * n
for i in range(q):
a,b = inpl()
c[a-1] += b
q = deque()
q.append(0)
fin = [False] * n
fin[0] = True
while q:
v = q.popleft()
for nv in g[v]:
if fin[nv]:continue
c[nv] += c[v]
fin[nv] = True
q.append(nv)
print((*c)) | 33 | 32 | 841 | 752 | from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, pprint, fractions
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
mod2 = 998244353
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
n, q = inpl()
g = [[] for i in range(n)]
c = [0 for i in range(n)]
seen = [False] * n
for i in range(n - 1):
a, b = inpl()
g[a - 1].append(b - 1)
g[b - 1].append(a - 1)
for i in range(q):
a, b = inpl()
c[a - 1] += b
def dfs(node):
for v in g[node]:
if seen[v]:
continue
c[v] += c[node]
seen[v] = True
dfs(v)
seen[0] = True
dfs(0)
for i in c:
print(i)
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n, q = inpl()
g = [[] for _ in range(n)]
for i in range(n - 1):
a, b = inpl()
a -= 1
b -= 1
g[a].append(b)
g[b].append(a)
c = [0] * n
for i in range(q):
a, b = inpl()
c[a - 1] += b
q = deque()
q.append(0)
fin = [False] * n
fin[0] = True
while q:
v = q.popleft()
for nv in g[v]:
if fin[nv]:
continue
c[nv] += c[v]
fin[nv] = True
q.append(nv)
print((*c))
| false | 3.030303 | [
"-import sys, bisect, math, itertools, pprint, fractions",
"+import sys, bisect, math, itertools, fractions, pprint",
"-mod2 = 998244353",
"-def inpln(n):",
"- return list(int(sys.stdin.readline()) for i in range(n))",
"-",
"-",
"-g = [[] for i in range(n)]",
"-c = [0 for i in range(n)]",
"-seen = [False] * n",
"+g = [[] for _ in range(n)]",
"- g[a - 1].append(b - 1)",
"- g[b - 1].append(a - 1)",
"+ a -= 1",
"+ b -= 1",
"+ g[a].append(b)",
"+ g[b].append(a)",
"+c = [0] * n",
"-",
"-",
"-def dfs(node):",
"- for v in g[node]:",
"- if seen[v]:",
"+q = deque()",
"+q.append(0)",
"+fin = [False] * n",
"+fin[0] = True",
"+while q:",
"+ v = q.popleft()",
"+ for nv in g[v]:",
"+ if fin[nv]:",
"- c[v] += c[node]",
"- seen[v] = True",
"- dfs(v)",
"-",
"-",
"-seen[0] = True",
"-dfs(0)",
"-for i in c:",
"- print(i)",
"+ c[nv] += c[v]",
"+ fin[nv] = True",
"+ q.append(nv)",
"+print((*c))"
] | false | 0.03608 | 0.036835 | 0.97952 | [
"s555420915",
"s934299313"
] |
u159117533 | p02819 | python | s992484236 | s305853026 | 369 | 251 | 10,868 | 10,868 | Accepted | Accepted | 31.98 | X = int(eval(input()))
LEN = int(1e6)
p = [True] * LEN
p[0] = False
p[1] = False
for i in range(LEN):
if p[i]:
for j in range(i * 2, LEN, i):
p[j] = False
for i in range(X, LEN):
if p[i]:
print(i)
exit()
| X = int(eval(input()))
LEN = int(1e6)
p = [True] * LEN
p[0] = False
p[1] = False
for i in range(LEN):
if p[i]:
if i >= X:
print(i)
exit()
for j in range(i * 2, LEN, i):
p[j] = False
| 16 | 16 | 238 | 229 | X = int(eval(input()))
LEN = int(1e6)
p = [True] * LEN
p[0] = False
p[1] = False
for i in range(LEN):
if p[i]:
for j in range(i * 2, LEN, i):
p[j] = False
for i in range(X, LEN):
if p[i]:
print(i)
exit()
| X = int(eval(input()))
LEN = int(1e6)
p = [True] * LEN
p[0] = False
p[1] = False
for i in range(LEN):
if p[i]:
if i >= X:
print(i)
exit()
for j in range(i * 2, LEN, i):
p[j] = False
| false | 0 | [
"+ if i >= X:",
"+ print(i)",
"+ exit()",
"-for i in range(X, LEN):",
"- if p[i]:",
"- print(i)",
"- exit()"
] | false | 0.715583 | 0.529426 | 1.351619 | [
"s992484236",
"s305853026"
] |
u045793300 | p03844 | python | s652860729 | s796372858 | 27 | 24 | 8,980 | 8,916 | Accepted | Accepted | 11.11 | a, op, b = input().split()
a,b = int(a), int(b)
print((a+b if op == '+' else a-b)) | s = eval(input())
print((eval(s))) | 3 | 2 | 82 | 27 | a, op, b = input().split()
a, b = int(a), int(b)
print((a + b if op == "+" else a - b))
| s = eval(input())
print((eval(s)))
| false | 33.333333 | [
"-a, op, b = input().split()",
"-a, b = int(a), int(b)",
"-print((a + b if op == \"+\" else a - b))",
"+s = eval(input())",
"+print((eval(s)))"
] | false | 0.079062 | 0.035805 | 2.20811 | [
"s652860729",
"s796372858"
] |
u183840468 | p02813 | python | s221424640 | s859697236 | 36 | 27 | 8,308 | 8,052 | Accepted | Accepted | 25 | import itertools
n = int(eval(input()))
l = sorted(list(itertools.permutations([i for i in range(1,n+1)])))
al = tuple([int(i) for i in input().split()])
bl = tuple([int(i) for i in input().split()])
a,b = 0,0
if al == bl:
print((0))
else:
for idx,i in enumerate(l):
if i == al:
a = idx
elif i == bl:
b = idx
else:
pass
print((abs(a-b))) | import itertools
n = int(eval(input()))
pl = tuple([int(i) for i in input().split()])
ql = tuple([int(i) for i in input().split()])
all_list = list(itertools.permutations(list(range(1,n+1))))
print((abs(all_list.index(pl) - all_list.index(ql))))
| 24 | 9 | 437 | 243 | import itertools
n = int(eval(input()))
l = sorted(list(itertools.permutations([i for i in range(1, n + 1)])))
al = tuple([int(i) for i in input().split()])
bl = tuple([int(i) for i in input().split()])
a, b = 0, 0
if al == bl:
print((0))
else:
for idx, i in enumerate(l):
if i == al:
a = idx
elif i == bl:
b = idx
else:
pass
print((abs(a - b)))
| import itertools
n = int(eval(input()))
pl = tuple([int(i) for i in input().split()])
ql = tuple([int(i) for i in input().split()])
all_list = list(itertools.permutations(list(range(1, n + 1))))
print((abs(all_list.index(pl) - all_list.index(ql))))
| false | 62.5 | [
"-l = sorted(list(itertools.permutations([i for i in range(1, n + 1)])))",
"-al = tuple([int(i) for i in input().split()])",
"-bl = tuple([int(i) for i in input().split()])",
"-a, b = 0, 0",
"-if al == bl:",
"- print((0))",
"-else:",
"- for idx, i in enumerate(l):",
"- if i == al:",
"- a = idx",
"- elif i == bl:",
"- b = idx",
"- else:",
"- pass",
"- print((abs(a - b)))",
"+pl = tuple([int(i) for i in input().split()])",
"+ql = tuple([int(i) for i in input().split()])",
"+all_list = list(itertools.permutations(list(range(1, n + 1))))",
"+print((abs(all_list.index(pl) - all_list.index(ql))))"
] | false | 0.050181 | 0.049827 | 1.007095 | [
"s221424640",
"s859697236"
] |
u648315264 | p03281 | python | s807241553 | s458721161 | 75 | 68 | 62,772 | 63,060 | Accepted | Accepted | 9.33 | import sys
input=sys.stdin.readline
def main():
cnt = 0
n = int(eval(input()))
for i in range(1,n+1):
if i % 2 == 1: # 奇数判定
k = 0
for m in range(1,i+1):
if i % m == 0:
k += 1
if k == 8:
cnt += 1
print(cnt)
if __name__=="__main__":
main()
| import sys
input=sys.stdin.readline
def main():
cnt = 0
n = int(eval(input()))
for i in range(1,n+1,2): # 奇数だけ繰り返す
k = 0
for m in range(1,i+1):
if i % m == 0:
k += 1
if k == 8:
cnt += 1
print(cnt)
if __name__=="__main__":
main()
| 18 | 17 | 367 | 325 | import sys
input = sys.stdin.readline
def main():
cnt = 0
n = int(eval(input()))
for i in range(1, n + 1):
if i % 2 == 1: # 奇数判定
k = 0
for m in range(1, i + 1):
if i % m == 0:
k += 1
if k == 8:
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
cnt = 0
n = int(eval(input()))
for i in range(1, n + 1, 2): # 奇数だけ繰り返す
k = 0
for m in range(1, i + 1):
if i % m == 0:
k += 1
if k == 8:
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| false | 5.555556 | [
"- for i in range(1, n + 1):",
"- if i % 2 == 1: # 奇数判定",
"- k = 0",
"- for m in range(1, i + 1):",
"- if i % m == 0:",
"- k += 1",
"- if k == 8:",
"- cnt += 1",
"+ for i in range(1, n + 1, 2): # 奇数だけ繰り返す",
"+ k = 0",
"+ for m in range(1, i + 1):",
"+ if i % m == 0:",
"+ k += 1",
"+ if k == 8:",
"+ cnt += 1"
] | false | 0.042922 | 0.047366 | 0.906185 | [
"s807241553",
"s458721161"
] |
u775681539 | p02888 | python | s067029999 | s519593500 | 960 | 511 | 3,188 | 213,936 | Accepted | Accepted | 46.77 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import combinations
from bisect import bisect_left
def main():
N = int(readline())
L = [int(i) for i in readline().split()]
L.sort()
sig = 0
for i in range(N):
for j in range(i+1, N):
l = bisect_left(L, L[i]+L[j], j+1)
sig += l-j-1
print(sig)
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import combinations
def main():
N = int(readline())
L = [int(i) for i in readline().split()]
#ソートしておく
L.sort()
#最長以外の二辺を先に決める
#インデックスで二辺を選ぶ。最長の辺はjよりインデックスが大きいものとなることが保証される
#jより後ろでc<a+bとなる最長の辺cの数を求めれば良い。二分探索で条件を満たす最大の辺を見つけるとよい
#インデックス用の値を用意
p = [i for i in range(N)]
#組みを作る
idxPairs = [(i, j) for i,j in combinations(p, 2)]
#jよりインデックスが大きい辺の中から最長の辺を見つける
ans = 0
for i, j in idxPairs:
#j以降を二分探索で調べる
#最長の辺をL[j]と選ぶと必ず三角形を作ることができる
l = j
r = N
while r-l>1:
mid = (r+l)//2
if L[mid] < L[i]+L[j]:
l = mid
else:
r = mid
ans += l-j
print(ans)
if __name__ == '__main__':
main()
| 18 | 39 | 486 | 922 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import combinations
from bisect import bisect_left
def main():
N = int(readline())
L = [int(i) for i in readline().split()]
L.sort()
sig = 0
for i in range(N):
for j in range(i + 1, N):
l = bisect_left(L, L[i] + L[j], j + 1)
sig += l - j - 1
print(sig)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import combinations
def main():
N = int(readline())
L = [int(i) for i in readline().split()]
# ソートしておく
L.sort()
# 最長以外の二辺を先に決める
# インデックスで二辺を選ぶ。最長の辺はjよりインデックスが大きいものとなることが保証される
# jより後ろでc<a+bとなる最長の辺cの数を求めれば良い。二分探索で条件を満たす最大の辺を見つけるとよい
# インデックス用の値を用意
p = [i for i in range(N)]
# 組みを作る
idxPairs = [(i, j) for i, j in combinations(p, 2)]
# jよりインデックスが大きい辺の中から最長の辺を見つける
ans = 0
for i, j in idxPairs:
# j以降を二分探索で調べる
# 最長の辺をL[j]と選ぶと必ず三角形を作ることができる
l = j
r = N
while r - l > 1:
mid = (r + l) // 2
if L[mid] < L[i] + L[j]:
l = mid
else:
r = mid
ans += l - j
print(ans)
if __name__ == "__main__":
main()
| false | 53.846154 | [
"-from bisect import bisect_left",
"+ # ソートしておく",
"- sig = 0",
"- for i in range(N):",
"- for j in range(i + 1, N):",
"- l = bisect_left(L, L[i] + L[j], j + 1)",
"- sig += l - j - 1",
"- print(sig)",
"+ # 最長以外の二辺を先に決める",
"+ # インデックスで二辺を選ぶ。最長の辺はjよりインデックスが大きいものとなることが保証される",
"+ # jより後ろでc<a+bとなる最長の辺cの数を求めれば良い。二分探索で条件を満たす最大の辺を見つけるとよい",
"+ # インデックス用の値を用意",
"+ p = [i for i in range(N)]",
"+ # 組みを作る",
"+ idxPairs = [(i, j) for i, j in combinations(p, 2)]",
"+ # jよりインデックスが大きい辺の中から最長の辺を見つける",
"+ ans = 0",
"+ for i, j in idxPairs:",
"+ # j以降を二分探索で調べる",
"+ # 最長の辺をL[j]と選ぶと必ず三角形を作ることができる",
"+ l = j",
"+ r = N",
"+ while r - l > 1:",
"+ mid = (r + l) // 2",
"+ if L[mid] < L[i] + L[j]:",
"+ l = mid",
"+ else:",
"+ r = mid",
"+ ans += l - j",
"+ print(ans)"
] | false | 0.237003 | 0.078422 | 3.022154 | [
"s067029999",
"s519593500"
] |
u432805419 | p04011 | python | s529432151 | s537647990 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | a = [int(eval(input())) for i in range(4)]
if a[0] <= a[1]:
print((a[0]*a[2]))
else:
print((a[1]*a[2] + (a[0]-a[1])*a[3])) | a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
if a > b:
print((b*c+(a-b)*d))
else:
print((a*c)) | 5 | 9 | 120 | 126 | a = [int(eval(input())) for i in range(4)]
if a[0] <= a[1]:
print((a[0] * a[2]))
else:
print((a[1] * a[2] + (a[0] - a[1]) * a[3]))
| a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
if a > b:
print((b * c + (a - b) * d))
else:
print((a * c))
| false | 44.444444 | [
"-a = [int(eval(input())) for i in range(4)]",
"-if a[0] <= a[1]:",
"- print((a[0] * a[2]))",
"+a = int(eval(input()))",
"+b = int(eval(input()))",
"+c = int(eval(input()))",
"+d = int(eval(input()))",
"+if a > b:",
"+ print((b * c + (a - b) * d))",
"- print((a[1] * a[2] + (a[0] - a[1]) * a[3]))",
"+ print((a * c))"
] | false | 0.038086 | 0.072597 | 0.524626 | [
"s529432151",
"s537647990"
] |
u747602774 | p04029 | python | s173571243 | s236209051 | 164 | 17 | 38,256 | 2,940 | Accepted | Accepted | 89.63 | N=int(eval(input()))
S=(N+1)*N//2
print(S) | n = int(eval(input()))
print((n*(n+1)//2)) | 3 | 2 | 38 | 35 | N = int(eval(input()))
S = (N + 1) * N // 2
print(S)
| n = int(eval(input()))
print((n * (n + 1) // 2))
| false | 33.333333 | [
"-N = int(eval(input()))",
"-S = (N + 1) * N // 2",
"-print(S)",
"+n = int(eval(input()))",
"+print((n * (n + 1) // 2))"
] | false | 0.036708 | 0.080466 | 0.456195 | [
"s173571243",
"s236209051"
] |
u604839890 | p02658 | python | s402321287 | s883236267 | 105 | 86 | 89,772 | 21,608 | Accepted | Accepted | 18.1 | n = int(eval(input()))
a = list(map(int, input().split()))
b = sorted(a)
ans = 1
for val in b:
ans *= val
if ans > 10**18:
print((-1))
exit()
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
ans = 1
a.sort()
if a[0] == 0:
print((0))
exit()
for i in a:
ans *= i
if ans > 10**18:
print((-1))
exit()
print(ans) | 10 | 13 | 165 | 209 | n = int(eval(input()))
a = list(map(int, input().split()))
b = sorted(a)
ans = 1
for val in b:
ans *= val
if ans > 10**18:
print((-1))
exit()
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = 1
a.sort()
if a[0] == 0:
print((0))
exit()
for i in a:
ans *= i
if ans > 10**18:
print((-1))
exit()
print(ans)
| false | 23.076923 | [
"-b = sorted(a)",
"-for val in b:",
"- ans *= val",
"+a.sort()",
"+if a[0] == 0:",
"+ print((0))",
"+ exit()",
"+for i in a:",
"+ ans *= i"
] | false | 0.049128 | 0.050214 | 0.97836 | [
"s402321287",
"s883236267"
] |
u767797498 | p02642 | python | s072335535 | s195682181 | 891 | 546 | 86,548 | 32,056 | Accepted | Accepted | 38.72 | n=int(eval(input()))
a=list(map(int,input().split()))
a.sort()
# 小さい側から処理する。a[i]について、10**6 以下のすべての倍数をset()として持つ。
# ただし、set内に存在しない==初出の約数のみ倍数計算をしてカウントする。
# 例えば、2,6,... となった場合、(6の倍数セットは2の倍数セットの下位集合となるため計算不要)
s=set()
cnt=0
for i,aa in enumerate(a):
if aa not in s:
# 同値が複数ある場合、カウントしない。sortしているため、同値は並ぶ
if i+1 == len(a) or aa != a[i+1]:
cnt+=1
for i in range(1,10**6+1):
ma=aa*i
if ma > 10**6:
break
s.add(ma)
print(cnt)
| # 30分ぐらい?で溶けた!計算量は直感だよりだったが。
# → エラトステネスの篩 に相当する実装らしい。
# リスト内の倍数・約数関係を判定し、カウントする。
# 二重ループで判定するとTLEになるため、小さい値の可能な倍数を計算して保存するようにした。
# メモを set() ではなく 配列 で実装するテスト
n=int(eval(input()))
a=list(map(int,input().split()))
a.sort()
# 小さい側から処理する。a[i]について、10**6 以下のすべての倍数をset()として持つ。
# ただし、set内に存在しない==初出の約数のみ倍数計算をしてカウントする。
# 例えば、2,6,... となった場合、(6の倍数セットは2の倍数セットの下位集合となるため計算不要)
s=[False]*(10**6+1)
cnt=0
for i,aa in enumerate(a):
if s[aa]:
continue
# 同値が複数ある場合、カウントしない。
if i+1 == len(a) or aa != a[i+1]:
cnt+=1
for i in range(1,10**6+1):
ma=aa*i
if ma > 10**6:
break
s[ma]=True
print(cnt)
| 24 | 32 | 493 | 646 | n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
# 小さい側から処理する。a[i]について、10**6 以下のすべての倍数をset()として持つ。
# ただし、set内に存在しない==初出の約数のみ倍数計算をしてカウントする。
# 例えば、2,6,... となった場合、(6の倍数セットは2の倍数セットの下位集合となるため計算不要)
s = set()
cnt = 0
for i, aa in enumerate(a):
if aa not in s:
# 同値が複数ある場合、カウントしない。sortしているため、同値は並ぶ
if i + 1 == len(a) or aa != a[i + 1]:
cnt += 1
for i in range(1, 10**6 + 1):
ma = aa * i
if ma > 10**6:
break
s.add(ma)
print(cnt)
| # 30分ぐらい?で溶けた!計算量は直感だよりだったが。
# → エラトステネスの篩 に相当する実装らしい。
# リスト内の倍数・約数関係を判定し、カウントする。
# 二重ループで判定するとTLEになるため、小さい値の可能な倍数を計算して保存するようにした。
# メモを set() ではなく 配列 で実装するテスト
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
# 小さい側から処理する。a[i]について、10**6 以下のすべての倍数をset()として持つ。
# ただし、set内に存在しない==初出の約数のみ倍数計算をしてカウントする。
# 例えば、2,6,... となった場合、(6の倍数セットは2の倍数セットの下位集合となるため計算不要)
s = [False] * (10**6 + 1)
cnt = 0
for i, aa in enumerate(a):
if s[aa]:
continue
# 同値が複数ある場合、カウントしない。
if i + 1 == len(a) or aa != a[i + 1]:
cnt += 1
for i in range(1, 10**6 + 1):
ma = aa * i
if ma > 10**6:
break
s[ma] = True
print(cnt)
| false | 25 | [
"+# 30分ぐらい?で溶けた!計算量は直感だよりだったが。",
"+# → エラトステネスの篩 に相当する実装らしい。",
"+# リスト内の倍数・約数関係を判定し、カウントする。",
"+# 二重ループで判定するとTLEになるため、小さい値の可能な倍数を計算して保存するようにした。",
"+# メモを set() ではなく 配列 で実装するテスト",
"-s = set()",
"+s = [False] * (10**6 + 1)",
"- if aa not in s:",
"- # 同値が複数ある場合、カウントしない。sortしているため、同値は並ぶ",
"- if i + 1 == len(a) or aa != a[i + 1]:",
"- cnt += 1",
"- for i in range(1, 10**6 + 1):",
"- ma = aa * i",
"- if ma > 10**6:",
"- break",
"- s.add(ma)",
"+ if s[aa]:",
"+ continue",
"+ # 同値が複数ある場合、カウントしない。",
"+ if i + 1 == len(a) or aa != a[i + 1]:",
"+ cnt += 1",
"+ for i in range(1, 10**6 + 1):",
"+ ma = aa * i",
"+ if ma > 10**6:",
"+ break",
"+ s[ma] = True"
] | false | 0.240182 | 0.395694 | 0.606988 | [
"s072335535",
"s195682181"
] |
u777283665 | p03695 | python | s344445872 | s702286988 | 168 | 18 | 38,256 | 3,064 | Accepted | Accepted | 89.29 | from bisect import bisect_right
n = int(eval(input()))
a = list(map(int, input().split()))
r = [400, 800, 1200, 1600, 2000, 2400, 2800, 3200]
c = [0] * 9
for score in a:
i = bisect_right(r, score)
c[i] += 1
ans = 8 - c[:-1].count(0)
print((max(1, ans), ans + c[8])) | n = int(eval(input()))
a = list(map(int, input().split()))
r = [0] * 9
for i in a:
temp = i // 400
if temp <= 8:
r[temp] += 1
else:
r[8] += 1
c = sum([1 for i in r[:-1] if i != 0])
t = r[-1]
if c == 0:
print((1, t))
else:
print((c, c+t)) | 15 | 17 | 278 | 281 | from bisect import bisect_right
n = int(eval(input()))
a = list(map(int, input().split()))
r = [400, 800, 1200, 1600, 2000, 2400, 2800, 3200]
c = [0] * 9
for score in a:
i = bisect_right(r, score)
c[i] += 1
ans = 8 - c[:-1].count(0)
print((max(1, ans), ans + c[8]))
| n = int(eval(input()))
a = list(map(int, input().split()))
r = [0] * 9
for i in a:
temp = i // 400
if temp <= 8:
r[temp] += 1
else:
r[8] += 1
c = sum([1 for i in r[:-1] if i != 0])
t = r[-1]
if c == 0:
print((1, t))
else:
print((c, c + t))
| false | 11.764706 | [
"-from bisect import bisect_right",
"-",
"-r = [400, 800, 1200, 1600, 2000, 2400, 2800, 3200]",
"-c = [0] * 9",
"-for score in a:",
"- i = bisect_right(r, score)",
"- c[i] += 1",
"-ans = 8 - c[:-1].count(0)",
"-print((max(1, ans), ans + c[8]))",
"+r = [0] * 9",
"+for i in a:",
"+ temp = i // 400",
"+ if temp <= 8:",
"+ r[temp] += 1",
"+ else:",
"+ r[8] += 1",
"+c = sum([1 for i in r[:-1] if i != 0])",
"+t = r[-1]",
"+if c == 0:",
"+ print((1, t))",
"+else:",
"+ print((c, c + t))"
] | false | 0.055423 | 0.035634 | 1.555359 | [
"s344445872",
"s702286988"
] |
u021019433 | p02928 | python | s267571073 | s058641375 | 638 | 319 | 3,564 | 3,564 | Accepted | Accepted | 50 | from collections import Counter
R = lambda: list(map(int, input().split()))
n, k = R()
a = list(R())
r = k * sum(a[i] < a[j] for i in range(n) for j in range(i))
r = n*(n-1)//2 - sum(x*(x-1)//2 for x in list(Counter(a).values()))
r = r * k*(k-1)//2 + k * sum(a[i] < a[j] for i in range(n) for j in range(i))
print((r % (10**9 + 7)))
| from collections import Counter
R = lambda: list(map(int, input().split()))
n, k = R()
a = list(R())
r = k * sum(a[i] < a[j] for i in range(n) for j in range(i))
r += k*(k-1)//2 * (n*(n-1)//2 - sum(x*(x-1)//2 for x in list(Counter(a).values())))
print((r % (10**9 + 7)))
| 8 | 7 | 326 | 263 | from collections import Counter
R = lambda: list(map(int, input().split()))
n, k = R()
a = list(R())
r = k * sum(a[i] < a[j] for i in range(n) for j in range(i))
r = n * (n - 1) // 2 - sum(x * (x - 1) // 2 for x in list(Counter(a).values()))
r = r * k * (k - 1) // 2 + k * sum(a[i] < a[j] for i in range(n) for j in range(i))
print((r % (10**9 + 7)))
| from collections import Counter
R = lambda: list(map(int, input().split()))
n, k = R()
a = list(R())
r = k * sum(a[i] < a[j] for i in range(n) for j in range(i))
r += (
k
* (k - 1)
// 2
* (n * (n - 1) // 2 - sum(x * (x - 1) // 2 for x in list(Counter(a).values())))
)
print((r % (10**9 + 7)))
| false | 12.5 | [
"-r = n * (n - 1) // 2 - sum(x * (x - 1) // 2 for x in list(Counter(a).values()))",
"-r = r * k * (k - 1) // 2 + k * sum(a[i] < a[j] for i in range(n) for j in range(i))",
"+r += (",
"+ k",
"+ * (k - 1)",
"+ // 2",
"+ * (n * (n - 1) // 2 - sum(x * (x - 1) // 2 for x in list(Counter(a).values())))",
"+)"
] | false | 0.035101 | 0.035791 | 0.980724 | [
"s267571073",
"s058641375"
] |
u367701763 | p02936 | python | s340603653 | s757543752 | 1,208 | 501 | 282,652 | 164,272 | Accepted | Accepted | 58.53 | # https://atcoder.jp/contests/abc138/tasks/abc138_d
import sys
input = sys.stdin.readline
from copy import deepcopy
class Graph:
def __init__(self, n, dictated=False, decrement=True, edge=[]):
self.n = n
self.dictated = dictated
self.decrement = decrement
self.edge = [set() for _ in range(self.n)]
self.parent = [-1]*self.n
self.info = [-1]*self.n
for x, y in edge:
self.add_edge(x,y)
def add_edge(self, x, y):
if self.decrement:
x -= 1
y -= 1
self.edge[x].add(y)
if self.dictated == False:
self.edge[y].add(x)
def add_adjacent_list(self, i, adjacent_list):
if self.decrement:
self.edge[i] = set([x-1 for x in adjacent_list])
else:
self.edge[i] = set(adjacent_list)
def dfs2(self, info, start, goal=-1, time=0, save=False):
"""
:param info: 各頂点の付加情報
:param start: スタート地点
:param goal: ゴール地点
:param save: True = 前回の探索結果を保持する
:return: ゴール地点までの距離。存在しなければ -1
"""
if self.decrement:
start -= 1
goal -= 1
if not save:
self.parent = [-1] * self.n
edge2 = deepcopy(self.edge)
p, t = start, time
self.parent[p] = -2
while True:
if edge2[p]:
q = edge2[p].pop()
if q == self.parent[p] and not self.dictated:
""" 逆流した時の処理 """
""""""""""""""""""""
continue
if self.parent[q] != -1:
""" サイクルで同一点を訪れた時の処理 """
""""""""""""""""""""
continue
if q == goal:
""" ゴール時の処理"""
# return t + 1
""""""""""""""""""""
continue
""" p から q への引継ぎ"""
info[q] += info[p]
""""""""""""""""""""
self.parent[q] = p
p, t = q, t + 1
else:
""" 探索完了時の処理 """
""""""""""""""""""""
if p == start and t == time:
break
p, t = self.parent[p], t-1
""" 二度目に訪問時の処理 """
""""""""""""""""""""
return info
######################################################################################################
N, Q = list(map(int, input().split())) # N:頂点数, Q: クエリの数
M = N-1
graph = Graph(N, dictated=False)
for _ in range(M):
x, y = list(map(int, input().split()))
graph.add_edge(x,y)
info = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
info[p - 1] += x
print((*graph.dfs2(info, start=1)))
| # https://atcoder.jp/contests/abc138/tasks/abc138_d
import sys
input = sys.stdin.readline
from copy import deepcopy
class Graph:
def __init__(self, n, dictated=False, decrement=True, edge=[]):
self.n = n
self.dictated = dictated
self.decrement = decrement
self.edge = [set() for _ in range(self.n)]
self.parent = [-1]*self.n
self.info = [-1]*self.n
for x, y in edge:
self.add_edge(x,y)
def add_edge(self, x, y):
if self.decrement:
x -= 1
y -= 1
self.edge[x].add(y)
if self.dictated == False:
self.edge[y].add(x)
def add_adjacent_list(self, i, adjacent_list):
if self.decrement:
self.edge[i] = set([x-1 for x in adjacent_list])
else:
self.edge[i] = set(adjacent_list)
def dfs2(self, info, start, goal=-1, time=0, save=False):
"""
:param info: 各頂点の付加情報
:param start: スタート地点
:param goal: ゴール地点
:param save: True = 前回の探索結果を保持する
:return: ゴール地点までの距離。存在しなければ -1
"""
if self.decrement:
start -= 1
goal -= 1
# if not save:
# self.parent = [-1] * self.n
#
# edge2 = deepcopy(self.edge)
edge2 = self.edge
p, t = start, time
self.parent[p] = -2
while True:
if edge2[p]:
q = edge2[p].pop()
if q == self.parent[p] and not self.dictated:
""" 逆流した時の処理 """
""""""""""""""""""""
continue
if self.parent[q] != -1:
""" サイクルで同一点を訪れた時の処理 """
""""""""""""""""""""
continue
if q == goal:
""" ゴール時の処理"""
# return t + 1
""""""""""""""""""""
continue
""" p から q への引継ぎ"""
info[q] += info[p]
""""""""""""""""""""
self.parent[q] = p
p, t = q, t + 1
else:
""" 探索完了時の処理 """
""""""""""""""""""""
if p == start and t == time:
break
p, t = self.parent[p], t-1
""" 二度目に訪問時の処理 """
""""""""""""""""""""
return info
######################################################################################################
N, Q = list(map(int, input().split())) # N:頂点数, Q: クエリの数
M = N-1
graph = Graph(N, dictated=False)
for _ in range(M):
x, y = list(map(int, input().split()))
graph.add_edge(x,y)
info = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
info[p - 1] += x
print((*graph.dfs2(info, start=1)))
| 101 | 103 | 2,890 | 2,943 | # https://atcoder.jp/contests/abc138/tasks/abc138_d
import sys
input = sys.stdin.readline
from copy import deepcopy
class Graph:
def __init__(self, n, dictated=False, decrement=True, edge=[]):
self.n = n
self.dictated = dictated
self.decrement = decrement
self.edge = [set() for _ in range(self.n)]
self.parent = [-1] * self.n
self.info = [-1] * self.n
for x, y in edge:
self.add_edge(x, y)
def add_edge(self, x, y):
if self.decrement:
x -= 1
y -= 1
self.edge[x].add(y)
if self.dictated == False:
self.edge[y].add(x)
def add_adjacent_list(self, i, adjacent_list):
if self.decrement:
self.edge[i] = set([x - 1 for x in adjacent_list])
else:
self.edge[i] = set(adjacent_list)
def dfs2(self, info, start, goal=-1, time=0, save=False):
"""
:param info: 各頂点の付加情報
:param start: スタート地点
:param goal: ゴール地点
:param save: True = 前回の探索結果を保持する
:return: ゴール地点までの距離。存在しなければ -1
"""
if self.decrement:
start -= 1
goal -= 1
if not save:
self.parent = [-1] * self.n
edge2 = deepcopy(self.edge)
p, t = start, time
self.parent[p] = -2
while True:
if edge2[p]:
q = edge2[p].pop()
if q == self.parent[p] and not self.dictated:
"""逆流した時の処理"""
"""""" """""" """""" ""
continue
if self.parent[q] != -1:
"""サイクルで同一点を訪れた時の処理"""
"""""" """""" """""" ""
continue
if q == goal:
"""ゴール時の処理"""
# return t + 1
"""""" """""" """""" ""
continue
""" p から q への引継ぎ"""
info[q] += info[p]
"""""" """""" """""" ""
self.parent[q] = p
p, t = q, t + 1
else:
"""探索完了時の処理"""
"""""" """""" """""" ""
if p == start and t == time:
break
p, t = self.parent[p], t - 1
""" 二度目に訪問時の処理 """
"""""" """""" """""" ""
return info
######################################################################################################
N, Q = list(map(int, input().split())) # N:頂点数, Q: クエリの数
M = N - 1
graph = Graph(N, dictated=False)
for _ in range(M):
x, y = list(map(int, input().split()))
graph.add_edge(x, y)
info = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
info[p - 1] += x
print((*graph.dfs2(info, start=1)))
| # https://atcoder.jp/contests/abc138/tasks/abc138_d
import sys
input = sys.stdin.readline
from copy import deepcopy
class Graph:
def __init__(self, n, dictated=False, decrement=True, edge=[]):
self.n = n
self.dictated = dictated
self.decrement = decrement
self.edge = [set() for _ in range(self.n)]
self.parent = [-1] * self.n
self.info = [-1] * self.n
for x, y in edge:
self.add_edge(x, y)
def add_edge(self, x, y):
if self.decrement:
x -= 1
y -= 1
self.edge[x].add(y)
if self.dictated == False:
self.edge[y].add(x)
def add_adjacent_list(self, i, adjacent_list):
if self.decrement:
self.edge[i] = set([x - 1 for x in adjacent_list])
else:
self.edge[i] = set(adjacent_list)
def dfs2(self, info, start, goal=-1, time=0, save=False):
"""
:param info: 各頂点の付加情報
:param start: スタート地点
:param goal: ゴール地点
:param save: True = 前回の探索結果を保持する
:return: ゴール地点までの距離。存在しなければ -1
"""
if self.decrement:
start -= 1
goal -= 1
# if not save:
# self.parent = [-1] * self.n
#
# edge2 = deepcopy(self.edge)
edge2 = self.edge
p, t = start, time
self.parent[p] = -2
while True:
if edge2[p]:
q = edge2[p].pop()
if q == self.parent[p] and not self.dictated:
"""逆流した時の処理"""
"""""" """""" """""" ""
continue
if self.parent[q] != -1:
"""サイクルで同一点を訪れた時の処理"""
"""""" """""" """""" ""
continue
if q == goal:
"""ゴール時の処理"""
# return t + 1
"""""" """""" """""" ""
continue
""" p から q への引継ぎ"""
info[q] += info[p]
"""""" """""" """""" ""
self.parent[q] = p
p, t = q, t + 1
else:
"""探索完了時の処理"""
"""""" """""" """""" ""
if p == start and t == time:
break
p, t = self.parent[p], t - 1
""" 二度目に訪問時の処理 """
"""""" """""" """""" ""
return info
######################################################################################################
N, Q = list(map(int, input().split())) # N:頂点数, Q: クエリの数
M = N - 1
graph = Graph(N, dictated=False)
for _ in range(M):
x, y = list(map(int, input().split()))
graph.add_edge(x, y)
info = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
info[p - 1] += x
print((*graph.dfs2(info, start=1)))
| false | 1.941748 | [
"- if not save:",
"- self.parent = [-1] * self.n",
"- edge2 = deepcopy(self.edge)",
"+ # if not save:",
"+ # self.parent = [-1] * self.n",
"+ #",
"+ # edge2 = deepcopy(self.edge)",
"+ edge2 = self.edge"
] | false | 0.178405 | 0.041495 | 4.299395 | [
"s340603653",
"s757543752"
] |
u983918956 | p03600 | python | s994536180 | s542600266 | 879 | 534 | 46,816 | 44,764 | Accepted | Accepted | 39.25 | N = int(eval(input()))
A = [list(map(int,input().split())) for _ in range(N)]
flag = [[0] * N for _ in range(N)]
dist = [line[:] for line in A]
for k in range(N):
for i in range(N):
for j in range(N):
if i == j or j == k or k == i:
continue
if dist[i][j] > dist[i][k] + dist[k][j]:
dist[i][j] = dist[i][k] + dist[k][j]
elif dist[i][j] < dist[i][k] + dist[k][j]:
flag[i][j] += 1
if A != dist:
print((-1))
exit()
ans = 0
for i in range(N):
for j in range(N):
if flag[i][j] == N-2:
ans += A[i][j]
ans //= 2
print(ans) | N = int(eval(input()))
A = [list(map(int,input().split())) for _ in range(N)]
flag = [[True] * N for _ in range(N)]
for i in range(N):
for j in range(i+1, N):
for k in range(N):
if k == i or k == j:
continue
if A[i][j] > A[i][k] + A[k][j]:
print((-1))
exit()
elif A[i][j] == A[i][k] + A[k][j]:
flag[i][j] = False
ans = 0
for i in range(N):
for j in range(i+1, N):
if flag[i][j]:
ans += A[i][j]
print(ans) | 28 | 24 | 666 | 560 | N = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(N)]
flag = [[0] * N for _ in range(N)]
dist = [line[:] for line in A]
for k in range(N):
for i in range(N):
for j in range(N):
if i == j or j == k or k == i:
continue
if dist[i][j] > dist[i][k] + dist[k][j]:
dist[i][j] = dist[i][k] + dist[k][j]
elif dist[i][j] < dist[i][k] + dist[k][j]:
flag[i][j] += 1
if A != dist:
print((-1))
exit()
ans = 0
for i in range(N):
for j in range(N):
if flag[i][j] == N - 2:
ans += A[i][j]
ans //= 2
print(ans)
| N = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(N)]
flag = [[True] * N for _ in range(N)]
for i in range(N):
for j in range(i + 1, N):
for k in range(N):
if k == i or k == j:
continue
if A[i][j] > A[i][k] + A[k][j]:
print((-1))
exit()
elif A[i][j] == A[i][k] + A[k][j]:
flag[i][j] = False
ans = 0
for i in range(N):
for j in range(i + 1, N):
if flag[i][j]:
ans += A[i][j]
print(ans)
| false | 14.285714 | [
"-flag = [[0] * N for _ in range(N)]",
"-dist = [line[:] for line in A]",
"-for k in range(N):",
"- for i in range(N):",
"- for j in range(N):",
"- if i == j or j == k or k == i:",
"+flag = [[True] * N for _ in range(N)]",
"+for i in range(N):",
"+ for j in range(i + 1, N):",
"+ for k in range(N):",
"+ if k == i or k == j:",
"- if dist[i][j] > dist[i][k] + dist[k][j]:",
"- dist[i][j] = dist[i][k] + dist[k][j]",
"- elif dist[i][j] < dist[i][k] + dist[k][j]:",
"- flag[i][j] += 1",
"-if A != dist:",
"- print((-1))",
"- exit()",
"+ if A[i][j] > A[i][k] + A[k][j]:",
"+ print((-1))",
"+ exit()",
"+ elif A[i][j] == A[i][k] + A[k][j]:",
"+ flag[i][j] = False",
"- for j in range(N):",
"- if flag[i][j] == N - 2:",
"+ for j in range(i + 1, N):",
"+ if flag[i][j]:",
"-ans //= 2"
] | false | 0.109854 | 0.122282 | 0.898365 | [
"s994536180",
"s542600266"
] |
u536600145 | p03166 | python | s335113130 | s262540731 | 1,164 | 371 | 154,060 | 56,368 | Accepted | Accepted | 68.13 | import sys
N, M = list(map(int, input().split()))
sys.setrecursionlimit(10**9)
vertices = [[] for i in range(N+1)]
dp = [-1] * (N+1)
for _ in range(M):
fro, to = list(map(int, input().split()))
vertices[fro].append(to)
def dfs(i):
if dp[i] != -1:
return dp[i]
temp = 0
for vertex in vertices[i]:
temp = max(temp, dfs(vertex)+1)
dp[i] = temp
return temp
for i in range(1,N+1):
dfs(i)
print((max(dp))) | import sys
import collections
# input処理を高速化する
input = sys.stdin.readline
def main():
# 入力
N, M = list(map(int, input().split()))
# 隣接関係は隣接リストで管理する
lst_edge = [[] for _ in range(N)]
# 各頂点の入力辺の本数
deg = [0] * N
for _ in range(M):
x, y = list(map(int, input().split()))
# 最初のindexをゼロにする
lst_edge[x-1].append(y-1)
deg[y-1] += 1
# 入力辺を持たない頂点をqueueに入れる
que = collections.deque()
for v in range(N):
if deg[v] == 0:
que.append(v)
# 各頂点の最初に入力辺を持たなかった点からの距離
dp = [0] * N
# For sequences, (strings, lists, tuples), use the fact that empty sequences are false.
# https://www.python.org/dev/peps/pep-0008/#programming-recommendations
while que:
v = que.popleft()
lst_nv = lst_edge[v]
for nv in lst_nv:
# エッジ(v, nv)をグラフから削除する
deg[nv] -= 1
if deg[nv] == 0:
# エッジがなくなったことで、入力辺がなくなったらqueueに入れる
que.append(nv)
# 最初に入力辺を持たなかった点からの距離
dp[nv] = max(dp[nv], dp[v] + 1)
print((max(dp)))
main() | 28 | 38 | 489 | 1,131 | import sys
N, M = list(map(int, input().split()))
sys.setrecursionlimit(10**9)
vertices = [[] for i in range(N + 1)]
dp = [-1] * (N + 1)
for _ in range(M):
fro, to = list(map(int, input().split()))
vertices[fro].append(to)
def dfs(i):
if dp[i] != -1:
return dp[i]
temp = 0
for vertex in vertices[i]:
temp = max(temp, dfs(vertex) + 1)
dp[i] = temp
return temp
for i in range(1, N + 1):
dfs(i)
print((max(dp)))
| import sys
import collections
# input処理を高速化する
input = sys.stdin.readline
def main():
# 入力
N, M = list(map(int, input().split()))
# 隣接関係は隣接リストで管理する
lst_edge = [[] for _ in range(N)]
# 各頂点の入力辺の本数
deg = [0] * N
for _ in range(M):
x, y = list(map(int, input().split()))
# 最初のindexをゼロにする
lst_edge[x - 1].append(y - 1)
deg[y - 1] += 1
# 入力辺を持たない頂点をqueueに入れる
que = collections.deque()
for v in range(N):
if deg[v] == 0:
que.append(v)
# 各頂点の最初に入力辺を持たなかった点からの距離
dp = [0] * N
# For sequences, (strings, lists, tuples), use the fact that empty sequences are false.
# https://www.python.org/dev/peps/pep-0008/#programming-recommendations
while que:
v = que.popleft()
lst_nv = lst_edge[v]
for nv in lst_nv:
# エッジ(v, nv)をグラフから削除する
deg[nv] -= 1
if deg[nv] == 0:
# エッジがなくなったことで、入力辺がなくなったらqueueに入れる
que.append(nv)
# 最初に入力辺を持たなかった点からの距離
dp[nv] = max(dp[nv], dp[v] + 1)
print((max(dp)))
main()
| false | 26.315789 | [
"+import collections",
"-N, M = list(map(int, input().split()))",
"-sys.setrecursionlimit(10**9)",
"-vertices = [[] for i in range(N + 1)]",
"-dp = [-1] * (N + 1)",
"-for _ in range(M):",
"- fro, to = list(map(int, input().split()))",
"- vertices[fro].append(to)",
"+# input処理を高速化する",
"+input = sys.stdin.readline",
"-def dfs(i):",
"- if dp[i] != -1:",
"- return dp[i]",
"- temp = 0",
"- for vertex in vertices[i]:",
"- temp = max(temp, dfs(vertex) + 1)",
"- dp[i] = temp",
"- return temp",
"+def main():",
"+ # 入力",
"+ N, M = list(map(int, input().split()))",
"+ # 隣接関係は隣接リストで管理する",
"+ lst_edge = [[] for _ in range(N)]",
"+ # 各頂点の入力辺の本数",
"+ deg = [0] * N",
"+ for _ in range(M):",
"+ x, y = list(map(int, input().split()))",
"+ # 最初のindexをゼロにする",
"+ lst_edge[x - 1].append(y - 1)",
"+ deg[y - 1] += 1",
"+ # 入力辺を持たない頂点をqueueに入れる",
"+ que = collections.deque()",
"+ for v in range(N):",
"+ if deg[v] == 0:",
"+ que.append(v)",
"+ # 各頂点の最初に入力辺を持たなかった点からの距離",
"+ dp = [0] * N",
"+ # For sequences, (strings, lists, tuples), use the fact that empty sequences are false.",
"+ # https://www.python.org/dev/peps/pep-0008/#programming-recommendations",
"+ while que:",
"+ v = que.popleft()",
"+ lst_nv = lst_edge[v]",
"+ for nv in lst_nv:",
"+ # エッジ(v, nv)をグラフから削除する",
"+ deg[nv] -= 1",
"+ if deg[nv] == 0:",
"+ # エッジがなくなったことで、入力辺がなくなったらqueueに入れる",
"+ que.append(nv)",
"+ # 最初に入力辺を持たなかった点からの距離",
"+ dp[nv] = max(dp[nv], dp[v] + 1)",
"+ print((max(dp)))",
"-for i in range(1, N + 1):",
"- dfs(i)",
"-print((max(dp)))",
"+main()"
] | false | 0.06415 | 0.071792 | 0.893559 | [
"s335113130",
"s262540731"
] |
u191874006 | p03290 | python | s856474463 | s401097798 | 1,613 | 191 | 41,964 | 41,200 | Accepted | Accepted | 88.16 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
d,g = LI()
pc = [LI() for _ in range(d)]
ans = inf
for i in permutations(list(range(d))):
score = 0
count = 0
for j in list(i):
p,c = pc[j]
if score + p*(j+1)*100 + c < g:
score += p*(j+1)*100 + c
count += p
continue
elif score + p*(j+1)*100 >= g:
count += (g-score-1)//((j+1)*100)+1
break
elif score + p*(j+1)*100 + c >= g:
count += p
break
ans = min(ans,count)
print(ans)
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
d,g = LI()
pc = [LI() for _ in range(d)]
ans = inf
for i in range(1<<d):
tmp = -1
count = 0
score = 0
flag = True
for j in range(d):
if i >> j & 1:
count += pc[j][0]
score += pc[j][1] + pc[j][0]*(j+1)*100
else:
tmp = max(tmp,j)
if tmp != -1:
if score >= g:
pass
elif g - score - (pc[tmp][0]-1)*(tmp+1)*100 > 0:
flag = False
else:
count += (g-score-1)//((tmp+1)*100) + 1
else:
if score < g:
flag = False
if flag:
ans = min(ans, count)
print(ans) | 39 | 46 | 1,079 | 1,206 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
d, g = LI()
pc = [LI() for _ in range(d)]
ans = inf
for i in permutations(list(range(d))):
score = 0
count = 0
for j in list(i):
p, c = pc[j]
if score + p * (j + 1) * 100 + c < g:
score += p * (j + 1) * 100 + c
count += p
continue
elif score + p * (j + 1) * 100 >= g:
count += (g - score - 1) // ((j + 1) * 100) + 1
break
elif score + p * (j + 1) * 100 + c >= g:
count += p
break
ans = min(ans, count)
print(ans)
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
d, g = LI()
pc = [LI() for _ in range(d)]
ans = inf
for i in range(1 << d):
tmp = -1
count = 0
score = 0
flag = True
for j in range(d):
if i >> j & 1:
count += pc[j][0]
score += pc[j][1] + pc[j][0] * (j + 1) * 100
else:
tmp = max(tmp, j)
if tmp != -1:
if score >= g:
pass
elif g - score - (pc[tmp][0] - 1) * (tmp + 1) * 100 > 0:
flag = False
else:
count += (g - score - 1) // ((tmp + 1) * 100) + 1
else:
if score < g:
flag = False
if flag:
ans = min(ans, count)
print(ans)
| false | 15.217391 | [
"-for i in permutations(list(range(d))):",
"+for i in range(1 << d):",
"+ tmp = -1",
"+ count = 0",
"- count = 0",
"- for j in list(i):",
"- p, c = pc[j]",
"- if score + p * (j + 1) * 100 + c < g:",
"- score += p * (j + 1) * 100 + c",
"- count += p",
"- continue",
"- elif score + p * (j + 1) * 100 >= g:",
"- count += (g - score - 1) // ((j + 1) * 100) + 1",
"- break",
"- elif score + p * (j + 1) * 100 + c >= g:",
"- count += p",
"- break",
"- ans = min(ans, count)",
"+ flag = True",
"+ for j in range(d):",
"+ if i >> j & 1:",
"+ count += pc[j][0]",
"+ score += pc[j][1] + pc[j][0] * (j + 1) * 100",
"+ else:",
"+ tmp = max(tmp, j)",
"+ if tmp != -1:",
"+ if score >= g:",
"+ pass",
"+ elif g - score - (pc[tmp][0] - 1) * (tmp + 1) * 100 > 0:",
"+ flag = False",
"+ else:",
"+ count += (g - score - 1) // ((tmp + 1) * 100) + 1",
"+ else:",
"+ if score < g:",
"+ flag = False",
"+ if flag:",
"+ ans = min(ans, count)"
] | false | 0.038776 | 0.118641 | 0.326834 | [
"s856474463",
"s401097798"
] |
u203211107 | p03037 | python | s863489795 | s352704828 | 323 | 289 | 3,060 | 3,060 | Accepted | Accepted | 10.53 | #C - Prison(ABC127)
N,M=list(map(int, input().split()))
l,r=list(map(int, input().split()))
for i in range(M-1):
L,R=list(map(int,input().split()))
l=max(L,l)
r=min(r,R)
if r-l+1>0:
print((r-l+1))
else:
print((0)) | #C - Prison(ABC127)
N,M=list(map(int, input().split()))
l,r=list(map(int, input().split()))
for i in range(M-1):
L,R=list(map(int,input().split()))
if l<L:
l=L
if r>R:
r=R
if r-l+1>0:
print((r-l+1))
else:
print((0)) | 11 | 13 | 221 | 241 | # C - Prison(ABC127)
N, M = list(map(int, input().split()))
l, r = list(map(int, input().split()))
for i in range(M - 1):
L, R = list(map(int, input().split()))
l = max(L, l)
r = min(r, R)
if r - l + 1 > 0:
print((r - l + 1))
else:
print((0))
| # C - Prison(ABC127)
N, M = list(map(int, input().split()))
l, r = list(map(int, input().split()))
for i in range(M - 1):
L, R = list(map(int, input().split()))
if l < L:
l = L
if r > R:
r = R
if r - l + 1 > 0:
print((r - l + 1))
else:
print((0))
| false | 15.384615 | [
"- l = max(L, l)",
"- r = min(r, R)",
"+ if l < L:",
"+ l = L",
"+ if r > R:",
"+ r = R"
] | false | 0.041517 | 0.047311 | 0.877529 | [
"s863489795",
"s352704828"
] |
u218834617 | p03013 | python | s019552519 | s048931274 | 583 | 127 | 468,380 | 17,264 | Accepted | Accepted | 78.22 | N,M=list(map(int,input().split()))
dp=[0]*(N+1)
dp[0]=1
for _ in range(M):
a=int(eval(input()))
dp[a]=-1
for i in range(1,N+1):
if dp[i]==-1:
continue
if dp[i-1]!=-1:
dp[i]+=dp[i-1]
if i>1 and dp[i-2]!=-1:
dp[i]+=dp[i-2]
if dp[-1]==-1:
print((0))
else:
print((dp[-1]%(10**9+7)))
| import sys
N,M=list(map(int,input().split()))
S=set(map(int,sys.stdin))
a,b=0,1
for i in range(1,N+1):
if i in S:
a,b=b,0
else:
a,b=b,a+b
print((b%(10**9+7)))
| 20 | 12 | 337 | 188 | N, M = list(map(int, input().split()))
dp = [0] * (N + 1)
dp[0] = 1
for _ in range(M):
a = int(eval(input()))
dp[a] = -1
for i in range(1, N + 1):
if dp[i] == -1:
continue
if dp[i - 1] != -1:
dp[i] += dp[i - 1]
if i > 1 and dp[i - 2] != -1:
dp[i] += dp[i - 2]
if dp[-1] == -1:
print((0))
else:
print((dp[-1] % (10**9 + 7)))
| import sys
N, M = list(map(int, input().split()))
S = set(map(int, sys.stdin))
a, b = 0, 1
for i in range(1, N + 1):
if i in S:
a, b = b, 0
else:
a, b = b, a + b
print((b % (10**9 + 7)))
| false | 40 | [
"+import sys",
"+",
"-dp = [0] * (N + 1)",
"-dp[0] = 1",
"-for _ in range(M):",
"- a = int(eval(input()))",
"- dp[a] = -1",
"+S = set(map(int, sys.stdin))",
"+a, b = 0, 1",
"- if dp[i] == -1:",
"- continue",
"- if dp[i - 1] != -1:",
"- dp[i] += dp[i - 1]",
"- if i > 1 and dp[i - 2] != -1:",
"- dp[i] += dp[i - 2]",
"-if dp[-1] == -1:",
"- print((0))",
"-else:",
"- print((dp[-1] % (10**9 + 7)))",
"+ if i in S:",
"+ a, b = b, 0",
"+ else:",
"+ a, b = b, a + b",
"+print((b % (10**9 + 7)))"
] | false | 0.03587 | 0.036917 | 0.97162 | [
"s019552519",
"s048931274"
] |
u513081876 | p04045 | python | s075289270 | s613137257 | 106 | 91 | 2,940 | 68,292 | Accepted | Accepted | 14.15 | N, K = list(map(int, input().split()))
D = [int(i) for i in input().split()]
num = N
flag = True
while flag:
for i in D:
if str(i) in str(num):
num += 1
break
else:
print(num)
flag = False
| N, K = list(map(int, input().split()))
D = [str(i) for i in input().split()]
ans = N
for i in range(N, 100001):
if set(list(str(i))) & set(D):
gg = 1
else:
print(i)
break | 14 | 10 | 254 | 206 | N, K = list(map(int, input().split()))
D = [int(i) for i in input().split()]
num = N
flag = True
while flag:
for i in D:
if str(i) in str(num):
num += 1
break
else:
print(num)
flag = False
| N, K = list(map(int, input().split()))
D = [str(i) for i in input().split()]
ans = N
for i in range(N, 100001):
if set(list(str(i))) & set(D):
gg = 1
else:
print(i)
break
| false | 28.571429 | [
"-D = [int(i) for i in input().split()]",
"-num = N",
"-flag = True",
"-while flag:",
"- for i in D:",
"- if str(i) in str(num):",
"- num += 1",
"- break",
"+D = [str(i) for i in input().split()]",
"+ans = N",
"+for i in range(N, 100001):",
"+ if set(list(str(i))) & set(D):",
"+ gg = 1",
"- print(num)",
"- flag = False",
"+ print(i)",
"+ break"
] | false | 0.042767 | 0.043263 | 0.988524 | [
"s075289270",
"s613137257"
] |
u729133443 | p02841 | python | s721245955 | s731969378 | 70 | 28 | 61,404 | 9,052 | Accepted | Accepted | 60 | print((1//int([*open(0)][1][2:]))) | print((+(' 1\n'in[*open(0)][1]))) | 1 | 1 | 32 | 31 | print((1 // int([*open(0)][1][2:])))
| print((+(" 1\n" in [*open(0)][1])))
| false | 0 | [
"-print((1 // int([*open(0)][1][2:])))",
"+print((+(\" 1\\n\" in [*open(0)][1])))"
] | false | 0.03872 | 0.073671 | 0.52558 | [
"s721245955",
"s731969378"
] |
u932465688 | p03363 | python | s045807987 | s730347646 | 270 | 244 | 26,136 | 26,136 | Accepted | Accepted | 9.63 | N = int(eval(input()))
L = list(map(int,input().split()))
S = [0]
c = 0
for i in range(N):
c = S[i] + L[i]
S.append(c)
S.sort()
S.append(S[N]+1)
k = 0
p = 1
ans = 0
while k <= N:
if S[k] == S[k+1]:
p += 1
k += 1
else:
ans += p*(p-1)//2
p = 1
k += 1
print(ans) | N = int(eval(input()))
A = list(map(int,input().split()))
R = [0] #Rは累積和を格納するリストです
for i in range(N):
R.append(R[i]+A[i]) #累積和を入れます
R.sort()
R.append(10**18) #カウントを止めます(番兵)
cnt = 1
ans = 0
cur = R[0] #curは今見ている累積和を表します
for i in range(1,N+2): #番兵の所で止まるように、N+1まで数えます
if cur == R[i]:
cnt += 1 #curと新たに見たR[i]が等しければインクリメント
else:
ans += cnt*(cnt-1)//2
cur = R[i] #違っていたら、curをR[i]に更新
cnt = 1 #cntを1に戻す
print(ans) | 21 | 18 | 301 | 491 | N = int(eval(input()))
L = list(map(int, input().split()))
S = [0]
c = 0
for i in range(N):
c = S[i] + L[i]
S.append(c)
S.sort()
S.append(S[N] + 1)
k = 0
p = 1
ans = 0
while k <= N:
if S[k] == S[k + 1]:
p += 1
k += 1
else:
ans += p * (p - 1) // 2
p = 1
k += 1
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
R = [0] # Rは累積和を格納するリストです
for i in range(N):
R.append(R[i] + A[i]) # 累積和を入れます
R.sort()
R.append(10**18) # カウントを止めます(番兵)
cnt = 1
ans = 0
cur = R[0] # curは今見ている累積和を表します
for i in range(1, N + 2): # 番兵の所で止まるように、N+1まで数えます
if cur == R[i]:
cnt += 1 # curと新たに見たR[i]が等しければインクリメント
else:
ans += cnt * (cnt - 1) // 2
cur = R[i] # 違っていたら、curをR[i]に更新
cnt = 1 # cntを1に戻す
print(ans)
| false | 14.285714 | [
"-L = list(map(int, input().split()))",
"-S = [0]",
"-c = 0",
"+A = list(map(int, input().split()))",
"+R = [0] # Rは累積和を格納するリストです",
"- c = S[i] + L[i]",
"- S.append(c)",
"-S.sort()",
"-S.append(S[N] + 1)",
"-k = 0",
"-p = 1",
"+ R.append(R[i] + A[i]) # 累積和を入れます",
"+R.sort()",
"+R.append(10**18) # カウントを止めます(番兵)",
"+cnt = 1",
"-while k <= N:",
"- if S[k] == S[k + 1]:",
"- p += 1",
"- k += 1",
"+cur = R[0] # curは今見ている累積和を表します",
"+for i in range(1, N + 2): # 番兵の所で止まるように、N+1まで数えます",
"+ if cur == R[i]:",
"+ cnt += 1 # curと新たに見たR[i]が等しければインクリメント",
"- ans += p * (p - 1) // 2",
"- p = 1",
"- k += 1",
"+ ans += cnt * (cnt - 1) // 2",
"+ cur = R[i] # 違っていたら、curをR[i]に更新",
"+ cnt = 1 # cntを1に戻す"
] | false | 0.068465 | 0.035569 | 1.924874 | [
"s045807987",
"s730347646"
] |
u514401521 | p02720 | python | s886689320 | s728428856 | 202 | 84 | 40,816 | 11,228 | Accepted | Accepted | 58.42 | from collections import deque
K = int(eval(input()))
d = deque()
for i in range(1, 10):
d.append(i)
cnt = 0
while d:
tmp = d.popleft()
cnt += 1
if cnt == K:
print(tmp)
break
r = tmp % 10
if r != 0:
d.append(tmp * 10 + r - 1)
d.append(tmp * 10 + r)
if r != 9:
d.append(tmp * 10 + r + 1) | K = int(eval(input()))
import copy
present = [1,2,3,4,5,6,7,8,9]
while K >= len(present):
K -= len(present)
next = []
for i in range(len(present)):
tmp = present[i]
r = tmp % 10
if r != 0:
next.append(tmp * 10 + r -1)
next.append(tmp * 10 + r)
if r != 9:
next.append(tmp * 10 + r +1)
present = next
print((present[K-1])) | 20 | 18 | 364 | 411 | from collections import deque
K = int(eval(input()))
d = deque()
for i in range(1, 10):
d.append(i)
cnt = 0
while d:
tmp = d.popleft()
cnt += 1
if cnt == K:
print(tmp)
break
r = tmp % 10
if r != 0:
d.append(tmp * 10 + r - 1)
d.append(tmp * 10 + r)
if r != 9:
d.append(tmp * 10 + r + 1)
| K = int(eval(input()))
import copy
present = [1, 2, 3, 4, 5, 6, 7, 8, 9]
while K >= len(present):
K -= len(present)
next = []
for i in range(len(present)):
tmp = present[i]
r = tmp % 10
if r != 0:
next.append(tmp * 10 + r - 1)
next.append(tmp * 10 + r)
if r != 9:
next.append(tmp * 10 + r + 1)
present = next
print((present[K - 1]))
| false | 10 | [
"-from collections import deque",
"+K = int(eval(input()))",
"+import copy",
"-K = int(eval(input()))",
"-d = deque()",
"-for i in range(1, 10):",
"- d.append(i)",
"-cnt = 0",
"-while d:",
"- tmp = d.popleft()",
"- cnt += 1",
"- if cnt == K:",
"- print(tmp)",
"- break",
"- r = tmp % 10",
"- if r != 0:",
"- d.append(tmp * 10 + r - 1)",
"- d.append(tmp * 10 + r)",
"- if r != 9:",
"- d.append(tmp * 10 + r + 1)",
"+present = [1, 2, 3, 4, 5, 6, 7, 8, 9]",
"+while K >= len(present):",
"+ K -= len(present)",
"+ next = []",
"+ for i in range(len(present)):",
"+ tmp = present[i]",
"+ r = tmp % 10",
"+ if r != 0:",
"+ next.append(tmp * 10 + r - 1)",
"+ next.append(tmp * 10 + r)",
"+ if r != 9:",
"+ next.append(tmp * 10 + r + 1)",
"+ present = next",
"+print((present[K - 1]))"
] | false | 0.042899 | 0.039371 | 1.089602 | [
"s886689320",
"s728428856"
] |
u670961163 | p03011 | python | s923405258 | s186295055 | 63 | 27 | 61,692 | 8,964 | Accepted | Accepted | 57.14 | p, q, r = list(map(int, input().split()))
print((p + q+ r - max(p, q, r))) | a, b, c= list(map(int, input().split()))
print(( a+b+c- max(a, b, c)))
| 2 | 2 | 67 | 64 | p, q, r = list(map(int, input().split()))
print((p + q + r - max(p, q, r)))
| a, b, c = list(map(int, input().split()))
print((a + b + c - max(a, b, c)))
| false | 0 | [
"-p, q, r = list(map(int, input().split()))",
"-print((p + q + r - max(p, q, r)))",
"+a, b, c = list(map(int, input().split()))",
"+print((a + b + c - max(a, b, c)))"
] | false | 0.133487 | 0.039853 | 3.349513 | [
"s923405258",
"s186295055"
] |
u401452016 | p03164 | python | s438278322 | s401116659 | 678 | 560 | 286,344 | 205,064 | Accepted | Accepted | 17.4 | #EDP-E
import sys
from collections import defaultdict
n, W = list(map(int, sys.stdin.readline().split()))
dp = [defaultdict(int) for _ in range(n)]
w, v = list(map(int, sys.stdin.readline().split()))
dp[0][v] = w
for i in range(1, n):
w, v = list(map(int, sys.stdin.readline().split()))
for vb, wb in list(dp[i-1].items()):
dp[i][vb] = min(wb, dp[i].get(vb, wb))
tmp = min(wb + w, dp[i].get(vb+ v, wb + w))
if tmp <=W:
dp[i][v+ vb] = tmp
dp[i][v] = min(dp[i].get(v, w), w)
#print(dp[-1].items())
print((max(dp[-1].keys())))
| #DP-E
def main():
import sys, copy
N, W = list(map(int, sys.stdin.readline().split()))
L = tuple([tuple(map(int, sys.stdin.readline().split())) for _ in range(N)])
#print(L)
#価値テーブルを作成
dp =[[10**11+1 for _ in range(10**5+1)] for _ in range(N)]
dp[0][L[0][1]] = L[0][0] #初期設定
#print(dp)
for i in range(1, N):
#1. 前回のコピー
dp[i] = copy.copy(dp[i-1])
w, v = L[i][0], L[i][1]
#print(w, v)
#2. 今回の荷物の更新
dp[i][v] = min(w, dp[i][v])
#3. 前回の荷物 + 今回の荷物の更新
for j in range(10**5+1-v):
if dp[i-1][j] !=0:
dp[i][v+j] = min(dp[i][v+j], w + dp[i-1][j])
ans = 0
for v1,w1 in enumerate(dp[-1]):
if w1 <= W:
if ans < v1:
ans = v1
#print(v1, w1)
print(ans)
if __name__ =='__main__':
main() | 20 | 34 | 568 | 904 | # EDP-E
import sys
from collections import defaultdict
n, W = list(map(int, sys.stdin.readline().split()))
dp = [defaultdict(int) for _ in range(n)]
w, v = list(map(int, sys.stdin.readline().split()))
dp[0][v] = w
for i in range(1, n):
w, v = list(map(int, sys.stdin.readline().split()))
for vb, wb in list(dp[i - 1].items()):
dp[i][vb] = min(wb, dp[i].get(vb, wb))
tmp = min(wb + w, dp[i].get(vb + v, wb + w))
if tmp <= W:
dp[i][v + vb] = tmp
dp[i][v] = min(dp[i].get(v, w), w)
# print(dp[-1].items())
print((max(dp[-1].keys())))
| # DP-E
def main():
import sys, copy
N, W = list(map(int, sys.stdin.readline().split()))
L = tuple([tuple(map(int, sys.stdin.readline().split())) for _ in range(N)])
# print(L)
# 価値テーブルを作成
dp = [[10**11 + 1 for _ in range(10**5 + 1)] for _ in range(N)]
dp[0][L[0][1]] = L[0][0] # 初期設定
# print(dp)
for i in range(1, N):
# 1. 前回のコピー
dp[i] = copy.copy(dp[i - 1])
w, v = L[i][0], L[i][1]
# print(w, v)
# 2. 今回の荷物の更新
dp[i][v] = min(w, dp[i][v])
# 3. 前回の荷物 + 今回の荷物の更新
for j in range(10**5 + 1 - v):
if dp[i - 1][j] != 0:
dp[i][v + j] = min(dp[i][v + j], w + dp[i - 1][j])
ans = 0
for v1, w1 in enumerate(dp[-1]):
if w1 <= W:
if ans < v1:
ans = v1
# print(v1, w1)
print(ans)
if __name__ == "__main__":
main()
| false | 41.176471 | [
"-# EDP-E",
"-import sys",
"-from collections import defaultdict",
"+# DP-E",
"+def main():",
"+ import sys, copy",
"-n, W = list(map(int, sys.stdin.readline().split()))",
"-dp = [defaultdict(int) for _ in range(n)]",
"-w, v = list(map(int, sys.stdin.readline().split()))",
"-dp[0][v] = w",
"-for i in range(1, n):",
"- w, v = list(map(int, sys.stdin.readline().split()))",
"- for vb, wb in list(dp[i - 1].items()):",
"- dp[i][vb] = min(wb, dp[i].get(vb, wb))",
"- tmp = min(wb + w, dp[i].get(vb + v, wb + w))",
"- if tmp <= W:",
"- dp[i][v + vb] = tmp",
"- dp[i][v] = min(dp[i].get(v, w), w)",
"-# print(dp[-1].items())",
"-print((max(dp[-1].keys())))",
"+ N, W = list(map(int, sys.stdin.readline().split()))",
"+ L = tuple([tuple(map(int, sys.stdin.readline().split())) for _ in range(N)])",
"+ # print(L)",
"+ # 価値テーブルを作成",
"+ dp = [[10**11 + 1 for _ in range(10**5 + 1)] for _ in range(N)]",
"+ dp[0][L[0][1]] = L[0][0] # 初期設定",
"+ # print(dp)",
"+ for i in range(1, N):",
"+ # 1. 前回のコピー",
"+ dp[i] = copy.copy(dp[i - 1])",
"+ w, v = L[i][0], L[i][1]",
"+ # print(w, v)",
"+ # 2. 今回の荷物の更新",
"+ dp[i][v] = min(w, dp[i][v])",
"+ # 3. 前回の荷物 + 今回の荷物の更新",
"+ for j in range(10**5 + 1 - v):",
"+ if dp[i - 1][j] != 0:",
"+ dp[i][v + j] = min(dp[i][v + j], w + dp[i - 1][j])",
"+ ans = 0",
"+ for v1, w1 in enumerate(dp[-1]):",
"+ if w1 <= W:",
"+ if ans < v1:",
"+ ans = v1",
"+ # print(v1, w1)",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.071051 | 0.591303 | 0.12016 | [
"s438278322",
"s401116659"
] |
u285891772 | p03487 | python | s539106466 | s543306709 | 126 | 98 | 19,852 | 19,848 | Accepted | Accepted | 22.22 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *
N = INT()
a = LIST()
A = Counter(a)
#print(A)
ans = 0
for x in A:
if x > A[x]:
ans += A[x]
else:
ans += A[x] - x
print(ans)
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *
N = INT()
a = LIST()
A = Counter(a)
#print(A)
ans = 0
for key, value in list(A.items()):
if key > value:
ans += value
else:
ans += value - key
print(ans)
| 36 | 36 | 1,039 | 1,063 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians # , log2
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# import numpy as np
# from decimal import *
N = INT()
a = LIST()
A = Counter(a)
# print(A)
ans = 0
for x in A:
if x > A[x]:
ans += A[x]
else:
ans += A[x] - x
print(ans)
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians # , log2
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# import numpy as np
# from decimal import *
N = INT()
a = LIST()
A = Counter(a)
# print(A)
ans = 0
for key, value in list(A.items()):
if key > value:
ans += value
else:
ans += value - key
print(ans)
| false | 0 | [
"-for x in A:",
"- if x > A[x]:",
"- ans += A[x]",
"+for key, value in list(A.items()):",
"+ if key > value:",
"+ ans += value",
"- ans += A[x] - x",
"+ ans += value - key"
] | false | 0.041801 | 0.041193 | 1.014763 | [
"s539106466",
"s543306709"
] |
u844005364 | p03854 | python | s308201680 | s020371199 | 25 | 19 | 9,588 | 3,188 | Accepted | Accepted | 24 | import re
s = eval(input())
print(("YES" if re.match("^(eraser?|dream(er)?)*$", s) else "NO")) | s = eval(input())
if s.replace("eraser"," ").replace("erase"," ").replace("dreamer"," ").replace("dream"," ").replace(" ", ""):
print("NO")
else:
print("YES") | 3 | 5 | 88 | 164 | import re
s = eval(input())
print(("YES" if re.match("^(eraser?|dream(er)?)*$", s) else "NO"))
| s = eval(input())
if (
s.replace("eraser", " ")
.replace("erase", " ")
.replace("dreamer", " ")
.replace("dream", " ")
.replace(" ", "")
):
print("NO")
else:
print("YES")
| false | 40 | [
"-import re",
"-",
"-print((\"YES\" if re.match(\"^(eraser?|dream(er)?)*$\", s) else \"NO\"))",
"+if (",
"+ s.replace(\"eraser\", \" \")",
"+ .replace(\"erase\", \" \")",
"+ .replace(\"dreamer\", \" \")",
"+ .replace(\"dream\", \" \")",
"+ .replace(\" \", \"\")",
"+):",
"+ print(\"NO\")",
"+else:",
"+ print(\"YES\")"
] | false | 0.041324 | 0.038633 | 1.069672 | [
"s308201680",
"s020371199"
] |
u644907318 | p03252 | python | s521647527 | s694474702 | 541 | 202 | 3,632 | 41,840 | Accepted | Accepted | 62.66 | S = input().strip()
T = input().strip()
F = {}
flag = 0
for i in range(len(S)):
a = S[i]
b = T[i]
if a not in F:
F[a] = b
if F[a] != b:
flag = 1
break
for c in F:
if c!=a and F[c]==b:
flag = 1
break
if flag==1:
print("No")
else:
print("Yes")
| A = {chr(i):0 for i in range(97,123)}
S = input().strip()
T = input().strip()
N = len(S)
G = {}
for i in range(N):
a = S[i]
if a not in G:
G[a]=[]
b = T[i]
if b not in G[a]:
G[a].append(b)
flag = 0
cnt = 0
for a in G:
cnt += 1
if len(G[a])>1:
flag = 1
break
if len(G[a])==0 and cnt==26:
break
b = G[a][0]
if a!=b:
cnt += 1
if A[b]==0:
A[b] += 1
else:
flag = 1
break
if flag==1:
print("No")
else:
print("Yes") | 20 | 33 | 345 | 564 | S = input().strip()
T = input().strip()
F = {}
flag = 0
for i in range(len(S)):
a = S[i]
b = T[i]
if a not in F:
F[a] = b
if F[a] != b:
flag = 1
break
for c in F:
if c != a and F[c] == b:
flag = 1
break
if flag == 1:
print("No")
else:
print("Yes")
| A = {chr(i): 0 for i in range(97, 123)}
S = input().strip()
T = input().strip()
N = len(S)
G = {}
for i in range(N):
a = S[i]
if a not in G:
G[a] = []
b = T[i]
if b not in G[a]:
G[a].append(b)
flag = 0
cnt = 0
for a in G:
cnt += 1
if len(G[a]) > 1:
flag = 1
break
if len(G[a]) == 0 and cnt == 26:
break
b = G[a][0]
if a != b:
cnt += 1
if A[b] == 0:
A[b] += 1
else:
flag = 1
break
if flag == 1:
print("No")
else:
print("Yes")
| false | 39.393939 | [
"+A = {chr(i): 0 for i in range(97, 123)}",
"-F = {}",
"+N = len(S)",
"+G = {}",
"+for i in range(N):",
"+ a = S[i]",
"+ if a not in G:",
"+ G[a] = []",
"+ b = T[i]",
"+ if b not in G[a]:",
"+ G[a].append(b)",
"-for i in range(len(S)):",
"- a = S[i]",
"- b = T[i]",
"- if a not in F:",
"- F[a] = b",
"- if F[a] != b:",
"+cnt = 0",
"+for a in G:",
"+ cnt += 1",
"+ if len(G[a]) > 1:",
"- for c in F:",
"- if c != a and F[c] == b:",
"- flag = 1",
"- break",
"+ if len(G[a]) == 0 and cnt == 26:",
"+ break",
"+ b = G[a][0]",
"+ if a != b:",
"+ cnt += 1",
"+ if A[b] == 0:",
"+ A[b] += 1",
"+ else:",
"+ flag = 1",
"+ break"
] | false | 0.112004 | 0.042156 | 2.656909 | [
"s521647527",
"s694474702"
] |
u523087093 | p02813 | python | s130407657 | s818421307 | 42 | 38 | 9,128 | 9,092 | Accepted | Accepted | 9.52 | import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
count = 1
for p in itertools.permutations(list(range(1, N+1))):
if p == P:
count_P = count
if p == Q:
count_Q = count
count += 1
ans = abs(count_P - count_Q)
print(ans) | import itertools
N = int(eval(input()))
P = list(map(int, input().split()))
tuple_P = tuple(P)
sorted_P = sorted(P)
Q = list(map(int, input().split()))
tuple_Q = tuple(Q)
sorted_Q = sorted(Q)
count_P = 1
for perm_P in itertools.permutations(sorted_P):
if tuple_P == perm_P:
break
count_P += 1
count_Q = 1
for perm_Q in itertools.permutations(sorted_Q):
if tuple_Q == perm_Q:
break
count_Q += 1
answer = abs(count_P - count_Q)
print(answer) | 18 | 24 | 320 | 492 | import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
count = 1
for p in itertools.permutations(list(range(1, N + 1))):
if p == P:
count_P = count
if p == Q:
count_Q = count
count += 1
ans = abs(count_P - count_Q)
print(ans)
| import itertools
N = int(eval(input()))
P = list(map(int, input().split()))
tuple_P = tuple(P)
sorted_P = sorted(P)
Q = list(map(int, input().split()))
tuple_Q = tuple(Q)
sorted_Q = sorted(Q)
count_P = 1
for perm_P in itertools.permutations(sorted_P):
if tuple_P == perm_P:
break
count_P += 1
count_Q = 1
for perm_Q in itertools.permutations(sorted_Q):
if tuple_Q == perm_Q:
break
count_Q += 1
answer = abs(count_P - count_Q)
print(answer)
| false | 25 | [
"-P = tuple(map(int, input().split()))",
"-Q = tuple(map(int, input().split()))",
"-count = 1",
"-for p in itertools.permutations(list(range(1, N + 1))):",
"- if p == P:",
"- count_P = count",
"- if p == Q:",
"- count_Q = count",
"- count += 1",
"-ans = abs(count_P - count_Q)",
"-print(ans)",
"+P = list(map(int, input().split()))",
"+tuple_P = tuple(P)",
"+sorted_P = sorted(P)",
"+Q = list(map(int, input().split()))",
"+tuple_Q = tuple(Q)",
"+sorted_Q = sorted(Q)",
"+count_P = 1",
"+for perm_P in itertools.permutations(sorted_P):",
"+ if tuple_P == perm_P:",
"+ break",
"+ count_P += 1",
"+count_Q = 1",
"+for perm_Q in itertools.permutations(sorted_Q):",
"+ if tuple_Q == perm_Q:",
"+ break",
"+ count_Q += 1",
"+answer = abs(count_P - count_Q)",
"+print(answer)"
] | false | 0.047854 | 0.04667 | 1.025372 | [
"s130407657",
"s818421307"
] |
u498487134 | p02832 | python | s781427464 | s152112070 | 250 | 105 | 77,516 | 100,700 | Accepted | Accepted | 58 | N = int(eval(input()))
A = list(map(int, input().split()))
se = 1
for i in range(N):
if A[i]==se:
se+=1
ans=N-se+1
if se==1:
ans=-1
print(ans) | import sys
input = sys.stdin.readline
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
A=LI()
cnt=0
now=1
for i in range(N):
if A[i]==now:
now+=1
else:
cnt+=1
if cnt==N:
cnt=-1
print(cnt)
main()
| 12 | 26 | 165 | 432 | N = int(eval(input()))
A = list(map(int, input().split()))
se = 1
for i in range(N):
if A[i] == se:
se += 1
ans = N - se + 1
if se == 1:
ans = -1
print(ans)
| import sys
input = sys.stdin.readline
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def main():
mod = 10**9 + 7
N = I()
A = LI()
cnt = 0
now = 1
for i in range(N):
if A[i] == now:
now += 1
else:
cnt += 1
if cnt == N:
cnt = -1
print(cnt)
main()
| false | 53.846154 | [
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-se = 1",
"-for i in range(N):",
"- if A[i] == se:",
"- se += 1",
"-ans = N - se + 1",
"-if se == 1:",
"- ans = -1",
"-print(ans)",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def main():",
"+ mod = 10**9 + 7",
"+ N = I()",
"+ A = LI()",
"+ cnt = 0",
"+ now = 1",
"+ for i in range(N):",
"+ if A[i] == now:",
"+ now += 1",
"+ else:",
"+ cnt += 1",
"+ if cnt == N:",
"+ cnt = -1",
"+ print(cnt)",
"+",
"+",
"+main()"
] | false | 0.034256 | 0.033443 | 1.024334 | [
"s781427464",
"s152112070"
] |
u255317651 | p02314 | python | s758627570 | s200415606 | 480 | 360 | 7,500 | 7,264 | Accepted | Accepted | 25 | # -*- coding: utf-8 -*-
"""
Created on Sat May 26 12:16:54 2018
DPL-1A Rec Call Revised
@author: maezawa
"""
n, m = list(map(int, input().split()))
c = list(map(int, input().split()))
c.sort()
dp = [float('inf') for _ in range(n+1)]
dp[0] = 0
#print(n,m)
#print(c)
#print(*dp, sep='\n')
for j in range(1,n+1):
temp = []
for i in range(m):
if j < c[i]:
continue
else:
temp.append(dp[j-c[i]]+1)
dp[j] = min(temp)
print((dp[n]))
| n, m = list(map(int, input().split()))
c = list(map(int, input().split()))
dp = [0] * (n+1)
for i in range(1, n+1):
dp[i] = min([dp[i - c[j]]+1 for j in range(m) if i-c[j]>=0])
print((dp[n]))
| 26 | 9 | 504 | 209 | # -*- coding: utf-8 -*-
"""
Created on Sat May 26 12:16:54 2018
DPL-1A Rec Call Revised
@author: maezawa
"""
n, m = list(map(int, input().split()))
c = list(map(int, input().split()))
c.sort()
dp = [float("inf") for _ in range(n + 1)]
dp[0] = 0
# print(n,m)
# print(c)
# print(*dp, sep='\n')
for j in range(1, n + 1):
temp = []
for i in range(m):
if j < c[i]:
continue
else:
temp.append(dp[j - c[i]] + 1)
dp[j] = min(temp)
print((dp[n]))
| n, m = list(map(int, input().split()))
c = list(map(int, input().split()))
dp = [0] * (n + 1)
for i in range(1, n + 1):
dp[i] = min([dp[i - c[j]] + 1 for j in range(m) if i - c[j] >= 0])
print((dp[n]))
| false | 65.384615 | [
"-# -*- coding: utf-8 -*-",
"-\"\"\"",
"-Created on Sat May 26 12:16:54 2018",
"-DPL-1A Rec Call Revised",
"-@author: maezawa",
"-\"\"\"",
"-c.sort()",
"-dp = [float(\"inf\") for _ in range(n + 1)]",
"-dp[0] = 0",
"-# print(n,m)",
"-# print(c)",
"-# print(*dp, sep='\\n')",
"-for j in range(1, n + 1):",
"- temp = []",
"- for i in range(m):",
"- if j < c[i]:",
"- continue",
"- else:",
"- temp.append(dp[j - c[i]] + 1)",
"- dp[j] = min(temp)",
"+dp = [0] * (n + 1)",
"+for i in range(1, n + 1):",
"+ dp[i] = min([dp[i - c[j]] + 1 for j in range(m) if i - c[j] >= 0])"
] | false | 0.073441 | 0.04264 | 1.722354 | [
"s758627570",
"s200415606"
] |
u999893056 | p03292 | python | s450205849 | s585221327 | 20 | 17 | 3,060 | 2,940 | Accepted | Accepted | 15 | *a,=list(map(int,input().split()))
print((max(a)-min(a))) | a = list(map(int, input().split()))
print((max(a)-min(a))) | 2 | 3 | 50 | 59 | (*a,) = list(map(int, input().split()))
print((max(a) - min(a)))
| a = list(map(int, input().split()))
print((max(a) - min(a)))
| false | 33.333333 | [
"-(*a,) = list(map(int, input().split()))",
"+a = list(map(int, input().split()))"
] | false | 0.040146 | 0.041277 | 0.972595 | [
"s450205849",
"s585221327"
] |
u454524105 | p02678 | python | s469502809 | s504034478 | 1,768 | 1,476 | 74,488 | 66,572 | Accepted | Accepted | 16.52 | from collections import deque
INF = 10**9 + 7
n, m = list(map(int, input().split()))
g = [[] for _ in range(n+1)]
for _ in range(m):
a, b = list(map(int, input().split()))
g[a].append([a, b])
g[b].append([b, a])
res = [[0, INF] for _ in range(n+1)]
res[1][1] = 0
q = deque(g[1])
while q:
q_ = q.popleft()
if res[q_[1]][1] == INF:
for gi in g[q_[1]]: q.append(gi)
res[q_[1]][0] = q_[0]
res[q_[1]][1] = res[q_[0]][1] + 1
print("Yes")
for i in res[2:]: print((i[0])) | from collections import deque
INF = 10**9 + 7
n, m = list(map(int, input().split()))
g = [[] for _ in range(n+1)]
for _ in range(m):
a, b = list(map(int, input().split()))
g[a].append([a, b])
g[b].append([b, a])
res = [INF for _ in range(n+1)]
res[1] = 0
q = deque(g[1])
while q:
q_ = q.popleft()
if res[q_[1]] == INF:
for gi in g[q_[1]]: q.append(gi)
res[q_[1]] = q_[0]
print("Yes")
for i in res[2:]: print(i) | 19 | 18 | 511 | 451 | from collections import deque
INF = 10**9 + 7
n, m = list(map(int, input().split()))
g = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = list(map(int, input().split()))
g[a].append([a, b])
g[b].append([b, a])
res = [[0, INF] for _ in range(n + 1)]
res[1][1] = 0
q = deque(g[1])
while q:
q_ = q.popleft()
if res[q_[1]][1] == INF:
for gi in g[q_[1]]:
q.append(gi)
res[q_[1]][0] = q_[0]
res[q_[1]][1] = res[q_[0]][1] + 1
print("Yes")
for i in res[2:]:
print((i[0]))
| from collections import deque
INF = 10**9 + 7
n, m = list(map(int, input().split()))
g = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = list(map(int, input().split()))
g[a].append([a, b])
g[b].append([b, a])
res = [INF for _ in range(n + 1)]
res[1] = 0
q = deque(g[1])
while q:
q_ = q.popleft()
if res[q_[1]] == INF:
for gi in g[q_[1]]:
q.append(gi)
res[q_[1]] = q_[0]
print("Yes")
for i in res[2:]:
print(i)
| false | 5.263158 | [
"-res = [[0, INF] for _ in range(n + 1)]",
"-res[1][1] = 0",
"+res = [INF for _ in range(n + 1)]",
"+res[1] = 0",
"- if res[q_[1]][1] == INF:",
"+ if res[q_[1]] == INF:",
"- res[q_[1]][0] = q_[0]",
"- res[q_[1]][1] = res[q_[0]][1] + 1",
"+ res[q_[1]] = q_[0]",
"- print((i[0]))",
"+ print(i)"
] | false | 0.049419 | 0.044874 | 1.101297 | [
"s469502809",
"s504034478"
] |
u623231048 | p03111 | python | s895357787 | s691341526 | 355 | 68 | 3,064 | 3,064 | Accepted | Accepted | 80.85 | n,a,b,c = list(map(int,input().split()))
takelist = [a,b,c]
li = [int(eval(input())) for _ in range(n)]
li2 = [0 for _ in range(n)]
min = 10**100
def movelist(li,n):
for i in range(n):
if li[i] != 3:
li[i] += 1
break
else:
li[i] = 0
for i in range(4**n):
li3 = [0,0,0,0]
sum = 0
for j in range(n):
if li3[li2[j]] != 0 and li2[j] != 3:
sum += 10
li3[li2[j]] += li[j]
if li3[0] != 0 and li3[1] != 0 and li3[2] != 0:
for k in range(3):
sum += abs(li3[k] - takelist[k])
if sum < min:
min = sum
movelist(li2,n)
print(min)
| n,A,B,C = list(map(int,input().split()))
li = [int(eval(input())) for _ in range(n)]
def searchans(count,a,b,c):
if count == n:
if not 0 in [a,b,c]:
return abs(A-a) + abs(B-b) + abs(C-c) - 30
else:
return 10**100
else:
ret0 = searchans(count+1,a,b,c)
ret1 = searchans(count+1,a+li[count],b,c) + 10
ret2 = searchans(count+1,a,b+li[count],c) + 10
ret3 = searchans(count+1,a,b,c+li[count]) + 10
return min([ret0,ret1,ret2,ret3])
print((searchans(0,0,0,0)))
| 30 | 17 | 682 | 546 | n, a, b, c = list(map(int, input().split()))
takelist = [a, b, c]
li = [int(eval(input())) for _ in range(n)]
li2 = [0 for _ in range(n)]
min = 10**100
def movelist(li, n):
for i in range(n):
if li[i] != 3:
li[i] += 1
break
else:
li[i] = 0
for i in range(4**n):
li3 = [0, 0, 0, 0]
sum = 0
for j in range(n):
if li3[li2[j]] != 0 and li2[j] != 3:
sum += 10
li3[li2[j]] += li[j]
if li3[0] != 0 and li3[1] != 0 and li3[2] != 0:
for k in range(3):
sum += abs(li3[k] - takelist[k])
if sum < min:
min = sum
movelist(li2, n)
print(min)
| n, A, B, C = list(map(int, input().split()))
li = [int(eval(input())) for _ in range(n)]
def searchans(count, a, b, c):
if count == n:
if not 0 in [a, b, c]:
return abs(A - a) + abs(B - b) + abs(C - c) - 30
else:
return 10**100
else:
ret0 = searchans(count + 1, a, b, c)
ret1 = searchans(count + 1, a + li[count], b, c) + 10
ret2 = searchans(count + 1, a, b + li[count], c) + 10
ret3 = searchans(count + 1, a, b, c + li[count]) + 10
return min([ret0, ret1, ret2, ret3])
print((searchans(0, 0, 0, 0)))
| false | 43.333333 | [
"-n, a, b, c = list(map(int, input().split()))",
"-takelist = [a, b, c]",
"+n, A, B, C = list(map(int, input().split()))",
"-li2 = [0 for _ in range(n)]",
"-min = 10**100",
"-def movelist(li, n):",
"- for i in range(n):",
"- if li[i] != 3:",
"- li[i] += 1",
"- break",
"+def searchans(count, a, b, c):",
"+ if count == n:",
"+ if not 0 in [a, b, c]:",
"+ return abs(A - a) + abs(B - b) + abs(C - c) - 30",
"- li[i] = 0",
"+ return 10**100",
"+ else:",
"+ ret0 = searchans(count + 1, a, b, c)",
"+ ret1 = searchans(count + 1, a + li[count], b, c) + 10",
"+ ret2 = searchans(count + 1, a, b + li[count], c) + 10",
"+ ret3 = searchans(count + 1, a, b, c + li[count]) + 10",
"+ return min([ret0, ret1, ret2, ret3])",
"-for i in range(4**n):",
"- li3 = [0, 0, 0, 0]",
"- sum = 0",
"- for j in range(n):",
"- if li3[li2[j]] != 0 and li2[j] != 3:",
"- sum += 10",
"- li3[li2[j]] += li[j]",
"- if li3[0] != 0 and li3[1] != 0 and li3[2] != 0:",
"- for k in range(3):",
"- sum += abs(li3[k] - takelist[k])",
"- if sum < min:",
"- min = sum",
"- movelist(li2, n)",
"-print(min)",
"+print((searchans(0, 0, 0, 0)))"
] | false | 0.256567 | 0.064056 | 4.005345 | [
"s895357787",
"s691341526"
] |
u556589653 | p02712 | python | s900381292 | s896415932 | 180 | 152 | 9,164 | 9,064 | Accepted | Accepted | 15.56 | N = int(eval(input()))
ans = 0
for i in range(1,N+1):
if i%3 == 0 or i%5 == 0:
ans += 0
else:
ans += i
print(ans) | N = int(eval(input()))
ans = 0
for i in range(1,N+1):
if i%3 == 0 or i%5 == 0:
continue
else:
ans += i
print(ans) | 8 | 8 | 138 | 126 | N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
if i % 3 == 0 or i % 5 == 0:
ans += 0
else:
ans += i
print(ans)
| N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
if i % 3 == 0 or i % 5 == 0:
continue
else:
ans += i
print(ans)
| false | 0 | [
"- ans += 0",
"+ continue"
] | false | 0.150384 | 0.152433 | 0.986554 | [
"s900381292",
"s896415932"
] |
u540762794 | p02844 | python | s072611556 | s208215268 | 646 | 36 | 9,340 | 9,172 | Accepted | Accepted | 94.43 | # -*- coding: utf-8 -*-
N = int(eval(input()))
S = list(eval(input()))
ans = 0
for i in range(1000):
pw = list("{0:03d}".format(i))
if pw[0] in S:
w1 = S.index(pw[0])
if pw[1] in S[w1+1:]:
w2 = w1+1 + S[w1+1:].index(pw[1])
if pw[2] in S[w2+1:]:
ans += 1
print(ans)
| # -*- coding: utf-8 -*-
N = int(eval(input()))
S = eval(input())
ans = 0
for i in range(1000):
pw = list("{0:03d}".format(i))
if pw[0] in S:
w1 = S.index(pw[0])
if pw[1] in S[w1+1:]:
w2 = w1+1 + S[w1+1:].index(pw[1])
if pw[2] in S[w2+1:]:
ans += 1
print(ans)
| 17 | 17 | 337 | 331 | # -*- coding: utf-8 -*-
N = int(eval(input()))
S = list(eval(input()))
ans = 0
for i in range(1000):
pw = list("{0:03d}".format(i))
if pw[0] in S:
w1 = S.index(pw[0])
if pw[1] in S[w1 + 1 :]:
w2 = w1 + 1 + S[w1 + 1 :].index(pw[1])
if pw[2] in S[w2 + 1 :]:
ans += 1
print(ans)
| # -*- coding: utf-8 -*-
N = int(eval(input()))
S = eval(input())
ans = 0
for i in range(1000):
pw = list("{0:03d}".format(i))
if pw[0] in S:
w1 = S.index(pw[0])
if pw[1] in S[w1 + 1 :]:
w2 = w1 + 1 + S[w1 + 1 :].index(pw[1])
if pw[2] in S[w2 + 1 :]:
ans += 1
print(ans)
| false | 0 | [
"-S = list(eval(input()))",
"+S = eval(input())"
] | false | 0.072933 | 0.03521 | 2.071356 | [
"s072611556",
"s208215268"
] |
u046187684 | p03013 | python | s620307324 | s975270573 | 160 | 49 | 15,592 | 11,884 | Accepted | Accepted | 69.38 | def solve(string):
n, m, *a = list(map(int, string.split()))
ans = [0] * (n + 1)
a = set(a)
ans[0] = 1
ans[1] = 0 if 1 in a else 1
num = 1000000007
for i in range(2, n + 1):
if i in a:
continue
ans[i] = (ans[i - 2] + ans[i - 1]) % num
return str(ans[-1])
if __name__ == '__main__':
n, m = list(map(int, input().split()))
print((solve('{} {}\n'.format(n, m) + '\n'.join([eval(input()) for _ in range(m)]))))
| import sys
mod = 10**9+7
def main():
n,m=list(map(int,input().split(' ')))
if m > 0:
aaa = set(map(int,sys.stdin))
else:
aaa = set()
dp = [0] * (n+1)
dp[0] = 1
dp[1] = 1 if 1 not in aaa else 0
for i in range(2,n+1):
if i in aaa:
continue
dp[i] = (dp[i-1]+dp[i-2])%mod
print((dp[n]))
main()
| 17 | 20 | 473 | 380 | def solve(string):
n, m, *a = list(map(int, string.split()))
ans = [0] * (n + 1)
a = set(a)
ans[0] = 1
ans[1] = 0 if 1 in a else 1
num = 1000000007
for i in range(2, n + 1):
if i in a:
continue
ans[i] = (ans[i - 2] + ans[i - 1]) % num
return str(ans[-1])
if __name__ == "__main__":
n, m = list(map(int, input().split()))
print(
(solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(m)])))
)
| import sys
mod = 10**9 + 7
def main():
n, m = list(map(int, input().split(" ")))
if m > 0:
aaa = set(map(int, sys.stdin))
else:
aaa = set()
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1 if 1 not in aaa else 0
for i in range(2, n + 1):
if i in aaa:
continue
dp[i] = (dp[i - 1] + dp[i - 2]) % mod
print((dp[n]))
main()
| false | 15 | [
"-def solve(string):",
"- n, m, *a = list(map(int, string.split()))",
"- ans = [0] * (n + 1)",
"- a = set(a)",
"- ans[0] = 1",
"- ans[1] = 0 if 1 in a else 1",
"- num = 1000000007",
"- for i in range(2, n + 1):",
"- if i in a:",
"- continue",
"- ans[i] = (ans[i - 2] + ans[i - 1]) % num",
"- return str(ans[-1])",
"+import sys",
"+",
"+mod = 10**9 + 7",
"-if __name__ == \"__main__\":",
"- n, m = list(map(int, input().split()))",
"- print(",
"- (solve(\"{} {}\\n\".format(n, m) + \"\\n\".join([eval(input()) for _ in range(m)])))",
"- )",
"+def main():",
"+ n, m = list(map(int, input().split(\" \")))",
"+ if m > 0:",
"+ aaa = set(map(int, sys.stdin))",
"+ else:",
"+ aaa = set()",
"+ dp = [0] * (n + 1)",
"+ dp[0] = 1",
"+ dp[1] = 1 if 1 not in aaa else 0",
"+ for i in range(2, n + 1):",
"+ if i in aaa:",
"+ continue",
"+ dp[i] = (dp[i - 1] + dp[i - 2]) % mod",
"+ print((dp[n]))",
"+",
"+",
"+main()"
] | false | 0.036333 | 0.047471 | 0.765369 | [
"s620307324",
"s975270573"
] |
u130900604 | p02990 | python | s955219571 | s327980043 | 876 | 34 | 14,336 | 4,852 | Accepted | Accepted | 96.12 | mod=10**9+7
n,k=list(map(int,input().split()))
from scipy.misc import comb
for i in range(1,k+1):
print((comb(n-k+1,i,exact=True)*comb(k-1,i-1,exact=True)%mod)) | # coding: utf-8
# Your code here!
def MI():return list(map(int,input().split()))
def LI():return list(MI())
N,K=list(map(int,open(0).read().split()))
# from juppyさん
mod = 10**9+7
MAX_N = 20020
fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
fact.append(fact[-1]*(i+1)%mod)
fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
fact_inv[i] = fact_inv[i+1]*(i+1)%mod
def mod_comb_k(n,k,mod):
return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod
# ここまで
for i in range(1,K+1):
if N-K+1<i:print((0));continue
ans=mod_comb_k(N-K+1,i,mod)*mod_comb_k(K-1,i-1,mod)
print((ans%mod)) | 7 | 31 | 162 | 655 | mod = 10**9 + 7
n, k = list(map(int, input().split()))
from scipy.misc import comb
for i in range(1, k + 1):
print((comb(n - k + 1, i, exact=True) * comb(k - 1, i - 1, exact=True) % mod))
| # coding: utf-8
# Your code here!
def MI():
return list(map(int, input().split()))
def LI():
return list(MI())
N, K = list(map(int, open(0).read().split()))
# from juppyさん
mod = 10**9 + 7
MAX_N = 20020
fact = [1]
fact_inv = [0] * (MAX_N + 4)
for i in range(MAX_N + 3):
fact.append(fact[-1] * (i + 1) % mod)
fact_inv[-1] = pow(fact[-1], mod - 2, mod)
for i in range(MAX_N + 2, -1, -1):
fact_inv[i] = fact_inv[i + 1] * (i + 1) % mod
def mod_comb_k(n, k, mod):
return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod
# ここまで
for i in range(1, K + 1):
if N - K + 1 < i:
print((0))
continue
ans = mod_comb_k(N - K + 1, i, mod) * mod_comb_k(K - 1, i - 1, mod)
print((ans % mod))
| false | 77.419355 | [
"+# coding: utf-8",
"+# Your code here!",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(MI())",
"+",
"+",
"+N, K = list(map(int, open(0).read().split()))",
"+# from juppyさん",
"-n, k = list(map(int, input().split()))",
"-from scipy.misc import comb",
"+MAX_N = 20020",
"+fact = [1]",
"+fact_inv = [0] * (MAX_N + 4)",
"+for i in range(MAX_N + 3):",
"+ fact.append(fact[-1] * (i + 1) % mod)",
"+fact_inv[-1] = pow(fact[-1], mod - 2, mod)",
"+for i in range(MAX_N + 2, -1, -1):",
"+ fact_inv[i] = fact_inv[i + 1] * (i + 1) % mod",
"-for i in range(1, k + 1):",
"- print((comb(n - k + 1, i, exact=True) * comb(k - 1, i - 1, exact=True) % mod))",
"+",
"+def mod_comb_k(n, k, mod):",
"+ return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod",
"+",
"+",
"+# ここまで",
"+for i in range(1, K + 1):",
"+ if N - K + 1 < i:",
"+ print((0))",
"+ continue",
"+ ans = mod_comb_k(N - K + 1, i, mod) * mod_comb_k(K - 1, i - 1, mod)",
"+ print((ans % mod))"
] | false | 0.480062 | 0.056526 | 8.492795 | [
"s955219571",
"s327980043"
] |
u287132915 | p02973 | python | s858125628 | s210859468 | 223 | 194 | 8,592 | 85,964 | Accepted | Accepted | 13 | # 広義最長部分増加数列の長さを求めるdef
# 配列LIS自体は広義最長部分増加文字列ではない
import bisect
def lis(seq):
LIS = [seq[0]]
for i in range(1, len(seq)):
if seq[i] >= LIS[-1]:
LIS.append(seq[i])
else:
LIS[bisect.bisect_right(LIS, seq[i])] = seq[i]
return(len(LIS))
n = int(eval(input()))
a = [0] * n
for i in range(n):
a[i] = int(eval(input()))
b = a[::-1]
print((lis(b))) | n = int(eval(input()))
a = []
for i in range(n):
ai = int(eval(input()))
a.append(ai)
lst = [a[0]]
for i in range(1, n):
ai = a[i]
left = -1
right = len(lst)
while left+1 < right:
mid = (left + right) // 2
if lst[mid] < ai:
right = mid
else:
left = mid
if right == len(lst):
lst.append(ai)
else:
lst[right] = ai
print((len(lst))) | 19 | 22 | 401 | 433 | # 広義最長部分増加数列の長さを求めるdef
# 配列LIS自体は広義最長部分増加文字列ではない
import bisect
def lis(seq):
LIS = [seq[0]]
for i in range(1, len(seq)):
if seq[i] >= LIS[-1]:
LIS.append(seq[i])
else:
LIS[bisect.bisect_right(LIS, seq[i])] = seq[i]
return len(LIS)
n = int(eval(input()))
a = [0] * n
for i in range(n):
a[i] = int(eval(input()))
b = a[::-1]
print((lis(b)))
| n = int(eval(input()))
a = []
for i in range(n):
ai = int(eval(input()))
a.append(ai)
lst = [a[0]]
for i in range(1, n):
ai = a[i]
left = -1
right = len(lst)
while left + 1 < right:
mid = (left + right) // 2
if lst[mid] < ai:
right = mid
else:
left = mid
if right == len(lst):
lst.append(ai)
else:
lst[right] = ai
print((len(lst)))
| false | 13.636364 | [
"-# 広義最長部分増加数列の長さを求めるdef",
"-# 配列LIS自体は広義最長部分増加文字列ではない",
"-import bisect",
"-",
"-",
"-def lis(seq):",
"- LIS = [seq[0]]",
"- for i in range(1, len(seq)):",
"- if seq[i] >= LIS[-1]:",
"- LIS.append(seq[i])",
"+n = int(eval(input()))",
"+a = []",
"+for i in range(n):",
"+ ai = int(eval(input()))",
"+ a.append(ai)",
"+lst = [a[0]]",
"+for i in range(1, n):",
"+ ai = a[i]",
"+ left = -1",
"+ right = len(lst)",
"+ while left + 1 < right:",
"+ mid = (left + right) // 2",
"+ if lst[mid] < ai:",
"+ right = mid",
"- LIS[bisect.bisect_right(LIS, seq[i])] = seq[i]",
"- return len(LIS)",
"-",
"-",
"-n = int(eval(input()))",
"-a = [0] * n",
"-for i in range(n):",
"- a[i] = int(eval(input()))",
"-b = a[::-1]",
"-print((lis(b)))",
"+ left = mid",
"+ if right == len(lst):",
"+ lst.append(ai)",
"+ else:",
"+ lst[right] = ai",
"+print((len(lst)))"
] | false | 0.041067 | 0.038041 | 1.079537 | [
"s858125628",
"s210859468"
] |
u368249389 | p02742 | python | s111501850 | s441584107 | 193 | 17 | 38,256 | 2,940 | Accepted | Accepted | 91.19 |
H, W = list(map(int, input().split()))
if H==1 or W==1:
print((1))
else:
if H%2==0:
print((H*W//2))
else:
if W%2==0:
print((H*W//2))
else:
print((H*W//2+1))
| # Problem B - Bishop
import math
# input
H, W = list(map(int, input().split()))
# check
if H==1 or W==1:
print((1))
else:
ans = math.ceil(H * W / 2)
print(ans)
| 13 | 13 | 217 | 179 | H, W = list(map(int, input().split()))
if H == 1 or W == 1:
print((1))
else:
if H % 2 == 0:
print((H * W // 2))
else:
if W % 2 == 0:
print((H * W // 2))
else:
print((H * W // 2 + 1))
| # Problem B - Bishop
import math
# input
H, W = list(map(int, input().split()))
# check
if H == 1 or W == 1:
print((1))
else:
ans = math.ceil(H * W / 2)
print(ans)
| false | 0 | [
"+# Problem B - Bishop",
"+import math",
"+",
"+# input",
"+# check",
"- if H % 2 == 0:",
"- print((H * W // 2))",
"- else:",
"- if W % 2 == 0:",
"- print((H * W // 2))",
"- else:",
"- print((H * W // 2 + 1))",
"+ ans = math.ceil(H * W / 2)",
"+ print(ans)"
] | false | 0.045954 | 0.046561 | 0.986956 | [
"s111501850",
"s441584107"
] |
u353919145 | p03264 | python | s653231059 | s058102442 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | k=int(eval(input()))
count=0
for i in range (2,k+1,1):
for j in range (k+1):
if i%2==0 and j%2==1:
count+=1
print(count) | n=eval(input())
O=0
E=0
for i in range (0,int(n)):
if i%2==0 :
E+=1
else:
O+=1
print((O*E)) | 8 | 9 | 146 | 116 | k = int(eval(input()))
count = 0
for i in range(2, k + 1, 1):
for j in range(k + 1):
if i % 2 == 0 and j % 2 == 1:
count += 1
print(count)
| n = eval(input())
O = 0
E = 0
for i in range(0, int(n)):
if i % 2 == 0:
E += 1
else:
O += 1
print((O * E))
| false | 11.111111 | [
"-k = int(eval(input()))",
"-count = 0",
"-for i in range(2, k + 1, 1):",
"- for j in range(k + 1):",
"- if i % 2 == 0 and j % 2 == 1:",
"- count += 1",
"-print(count)",
"+n = eval(input())",
"+O = 0",
"+E = 0",
"+for i in range(0, int(n)):",
"+ if i % 2 == 0:",
"+ E += 1",
"+ else:",
"+ O += 1",
"+print((O * E))"
] | false | 0.045647 | 0.049412 | 0.923811 | [
"s653231059",
"s058102442"
] |
u588341295 | p03166 | python | s866196057 | s866926359 | 1,127 | 646 | 50,968 | 74,516 | Accepted | Accepted | 42.68 | # -*- coding: utf-8 -*-
"""
参考:https://qiita.com/drken/items/03c7db44ccd27820ea0d
・自力AC
・トポロジカルソート
・解説読んで、DPする位置をちょっと変えてみた。
"""
import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
def topological_sort(N, dag):
# ここからトポロジカルソート準備
incnts = [0] * N
outnodes = [[] for i in range(N)]
for i in range(len(dag)):
# 流入するノード数
incnts[dag[i][1]] += 1
# 流出先ノードのリスト
outnodes[dag[i][0]].append(dag[i][1])
# 流入ノード数が0であるノードのセットS
S = set()
for i in range(N):
if incnts[i] == 0:
S.add(i)
# ここからトポロジカルソート
L = []
# 暫定セットが空になるまでループ
while S:
# 暫定セットから結果リストへ1つ入れる
L.append(S.pop())
# 確定させたノードから流出するノードでループ
for node in outnodes[L[-1]]:
# 流入ノード数を1減らす
incnts[node] -= 1
# 流入ノードが0なら暫定セットへ
if incnts[node] == 0:
S.add(node)
# そのノードの順序確定時に答えの更新もやればループは減ると思う
src = L[-1]
for dest in nodes[src]:
dp[dest] = max(dp[dest], dp[src]+1)
return L
N, M = MAP()
nodes = [[] for i in range(N)]
edges = [None] * M
for i in range(M):
x, y = MAP()
nodes[x-1].append(y-1)
edges[i] = ((x-1, y-1))
dp = [0] * N
# この後の最大値更新で矛盾が生じないようにソートしておく
l = topological_sort(N, edges)
print((max(dp)))
| # -*- coding: utf-8 -*-
"""
参考:https://qiita.com/drken/items/03c7db44ccd27820ea0d
・メモ化再帰でもやってみる。
"""
import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N, M = MAP()
nodes = [[] for i in range(N)]
edges = [None] * M
for i in range(M):
x, y = MAP()
nodes[x-1].append(y-1)
edges[i] = ((x-1, y-1))
memo = [-1] * N
# メモ化再帰
def dfs(cur):
if memo[cur] != -1:
return memo[cur]
mx = 0
for dest in nodes[cur]:
mx = max(mx, dfs(dest)+1)
memo[cur] = mx
return mx
ans = 0
for i in range(N):
# メモはグローバルに持っているので、
# 全ノードについてdfsしても無駄に潜ることはない。
ans = max(ans, dfs(i))
print(ans)
| 85 | 60 | 2,421 | 1,730 | # -*- coding: utf-8 -*-
"""
参考:https://qiita.com/drken/items/03c7db44ccd27820ea0d
・自力AC
・トポロジカルソート
・解説読んで、DPする位置をちょっと変えてみた。
"""
import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5:
from math import gcd
else:
from fractions import gcd
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
def input():
return sys.stdin.readline().strip()
def ceil(a, b=1):
return int(-(-a // b))
def round(x):
return int((x * 2 + 1) // 2)
def fermat(x, y, MOD):
return x * pow(y, MOD - 2, MOD) % MOD
def lcm(x, y):
return (x * y) // gcd(x, y)
def lcm_list(nums):
return reduce(lcm, nums, 1)
def gcd_list(nums):
return reduce(gcd, nums, nums[0])
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
def topological_sort(N, dag):
# ここからトポロジカルソート準備
incnts = [0] * N
outnodes = [[] for i in range(N)]
for i in range(len(dag)):
# 流入するノード数
incnts[dag[i][1]] += 1
# 流出先ノードのリスト
outnodes[dag[i][0]].append(dag[i][1])
# 流入ノード数が0であるノードのセットS
S = set()
for i in range(N):
if incnts[i] == 0:
S.add(i)
# ここからトポロジカルソート
L = []
# 暫定セットが空になるまでループ
while S:
# 暫定セットから結果リストへ1つ入れる
L.append(S.pop())
# 確定させたノードから流出するノードでループ
for node in outnodes[L[-1]]:
# 流入ノード数を1減らす
incnts[node] -= 1
# 流入ノードが0なら暫定セットへ
if incnts[node] == 0:
S.add(node)
# そのノードの順序確定時に答えの更新もやればループは減ると思う
src = L[-1]
for dest in nodes[src]:
dp[dest] = max(dp[dest], dp[src] + 1)
return L
N, M = MAP()
nodes = [[] for i in range(N)]
edges = [None] * M
for i in range(M):
x, y = MAP()
nodes[x - 1].append(y - 1)
edges[i] = (x - 1, y - 1)
dp = [0] * N
# この後の最大値更新で矛盾が生じないようにソートしておく
l = topological_sort(N, edges)
print((max(dp)))
| # -*- coding: utf-8 -*-
"""
参考:https://qiita.com/drken/items/03c7db44ccd27820ea0d
・メモ化再帰でもやってみる。
"""
import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5:
from math import gcd
else:
from fractions import gcd
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
def input():
return sys.stdin.readline().strip()
def ceil(a, b=1):
return int(-(-a // b))
def round(x):
return int((x * 2 + 1) // 2)
def fermat(x, y, MOD):
return x * pow(y, MOD - 2, MOD) % MOD
def lcm(x, y):
return (x * y) // gcd(x, y)
def lcm_list(nums):
return reduce(lcm, nums, 1)
def gcd_list(nums):
return reduce(gcd, nums, nums[0])
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
N, M = MAP()
nodes = [[] for i in range(N)]
edges = [None] * M
for i in range(M):
x, y = MAP()
nodes[x - 1].append(y - 1)
edges[i] = (x - 1, y - 1)
memo = [-1] * N
# メモ化再帰
def dfs(cur):
if memo[cur] != -1:
return memo[cur]
mx = 0
for dest in nodes[cur]:
mx = max(mx, dfs(dest) + 1)
memo[cur] = mx
return mx
ans = 0
for i in range(N):
# メモはグローバルに持っているので、
# 全ノードについてdfsしても無駄に潜ることはない。
ans = max(ans, dfs(i))
print(ans)
| false | 29.411765 | [
"-・自力AC",
"-・トポロジカルソート",
"-・解説読んで、DPする位置をちょっと変えてみた。",
"+・メモ化再帰でもやってみる。",
"-",
"-",
"-def topological_sort(N, dag):",
"- # ここからトポロジカルソート準備",
"- incnts = [0] * N",
"- outnodes = [[] for i in range(N)]",
"- for i in range(len(dag)):",
"- # 流入するノード数",
"- incnts[dag[i][1]] += 1",
"- # 流出先ノードのリスト",
"- outnodes[dag[i][0]].append(dag[i][1])",
"- # 流入ノード数が0であるノードのセットS",
"- S = set()",
"- for i in range(N):",
"- if incnts[i] == 0:",
"- S.add(i)",
"- # ここからトポロジカルソート",
"- L = []",
"- # 暫定セットが空になるまでループ",
"- while S:",
"- # 暫定セットから結果リストへ1つ入れる",
"- L.append(S.pop())",
"- # 確定させたノードから流出するノードでループ",
"- for node in outnodes[L[-1]]:",
"- # 流入ノード数を1減らす",
"- incnts[node] -= 1",
"- # 流入ノードが0なら暫定セットへ",
"- if incnts[node] == 0:",
"- S.add(node)",
"- # そのノードの順序確定時に答えの更新もやればループは減ると思う",
"- src = L[-1]",
"- for dest in nodes[src]:",
"- dp[dest] = max(dp[dest], dp[src] + 1)",
"- return L",
"-",
"-",
"-dp = [0] * N",
"-# この後の最大値更新で矛盾が生じないようにソートしておく",
"-l = topological_sort(N, edges)",
"-print((max(dp)))",
"+memo = [-1] * N",
"+# メモ化再帰",
"+def dfs(cur):",
"+ if memo[cur] != -1:",
"+ return memo[cur]",
"+ mx = 0",
"+ for dest in nodes[cur]:",
"+ mx = max(mx, dfs(dest) + 1)",
"+ memo[cur] = mx",
"+ return mx",
"+",
"+",
"+ans = 0",
"+for i in range(N):",
"+ # メモはグローバルに持っているので、",
"+ # 全ノードについてdfsしても無駄に潜ることはない。",
"+ ans = max(ans, dfs(i))",
"+print(ans)"
] | false | 0.064701 | 0.03654 | 1.770693 | [
"s866196057",
"s866926359"
] |
u677121387 | p02639 | python | s713674642 | s465831235 | 59 | 23 | 61,636 | 9,164 | Accepted | Accepted | 61.02 | x = [int(i) for i in input().split()]
for i in range(5):
if x[i] == 0:
print((i+1))
break | x = [int(i) for i in input().split()]
print((x.index(0)+1)) | 5 | 2 | 111 | 58 | x = [int(i) for i in input().split()]
for i in range(5):
if x[i] == 0:
print((i + 1))
break
| x = [int(i) for i in input().split()]
print((x.index(0) + 1))
| false | 60 | [
"-for i in range(5):",
"- if x[i] == 0:",
"- print((i + 1))",
"- break",
"+print((x.index(0) + 1))"
] | false | 0.080709 | 0.07195 | 1.121741 | [
"s713674642",
"s465831235"
] |
u897329068 | p03611 | python | s190400024 | s499904685 | 324 | 96 | 37,624 | 13,964 | Accepted | Accepted | 70.37 | N = int(eval(input()))
A = list(map(int,input().split()))
afters = []
for ai in range(N):
for sign in [-1,0,1]:
afters.append(A[ai]+sign)
uniq = set(afters)
countDic = {}
sas = sorted(afters)
for a in sas:
if a in list(countDic.keys()):
countDic[a] += 1
else:
countDic[a] = 1
print((max(countDic.values()))) | N = int(eval(input()))
src = list(map(int, input().split()))
MAX = 10**5
counts = [0 for i in range(MAX+2)]
for a in src:
a += 1
counts[a-1] += 1
counts[a] += 1
counts[a+1] += 1
print((max(counts[1:-2]))) | 19 | 13 | 327 | 218 | N = int(eval(input()))
A = list(map(int, input().split()))
afters = []
for ai in range(N):
for sign in [-1, 0, 1]:
afters.append(A[ai] + sign)
uniq = set(afters)
countDic = {}
sas = sorted(afters)
for a in sas:
if a in list(countDic.keys()):
countDic[a] += 1
else:
countDic[a] = 1
print((max(countDic.values())))
| N = int(eval(input()))
src = list(map(int, input().split()))
MAX = 10**5
counts = [0 for i in range(MAX + 2)]
for a in src:
a += 1
counts[a - 1] += 1
counts[a] += 1
counts[a + 1] += 1
print((max(counts[1:-2])))
| false | 31.578947 | [
"-A = list(map(int, input().split()))",
"-afters = []",
"-for ai in range(N):",
"- for sign in [-1, 0, 1]:",
"- afters.append(A[ai] + sign)",
"-uniq = set(afters)",
"-countDic = {}",
"-sas = sorted(afters)",
"-for a in sas:",
"- if a in list(countDic.keys()):",
"- countDic[a] += 1",
"- else:",
"- countDic[a] = 1",
"-print((max(countDic.values())))",
"+src = list(map(int, input().split()))",
"+MAX = 10**5",
"+counts = [0 for i in range(MAX + 2)]",
"+for a in src:",
"+ a += 1",
"+ counts[a - 1] += 1",
"+ counts[a] += 1",
"+ counts[a + 1] += 1",
"+print((max(counts[1:-2])))"
] | false | 0.04036 | 0.052983 | 0.761748 | [
"s190400024",
"s499904685"
] |
u426108351 | p03163 | python | s608968451 | s369611823 | 635 | 553 | 173,448 | 121,708 | Accepted | Accepted | 12.91 | N, W = list(map(int, input().split()))
dp = [[0 for i in range(W + 1)] for j in range(N+1)]
for j in range(N):
w, v = list(map(int, input().split()))
for k in range(W + 1):
if k >= w:
dp[j+1][k] = max(dp[j][k-w] + v, dp[j][k])
else:
dp[j+1][k] = dp[j][k]
print((dp[N][W]))
| N, W = list(map(int, input().split()))
dp = [[0]*(W+1) for i in range(N+1)]
for i in range(N):
w, v = list(map(int, input().split()))
for j in range(W+1):
if w + j <= W:
dp[i+1][j+w] = max(dp[i][j+w], dp[i][j]+v)
dp[i+1][j] = max(dp[i][j], dp[i+1][j])
else:
dp[i+1][j] = max(dp[i][j], dp[i+1][j])
print((max(dp[N])))
| 12 | 12 | 320 | 375 | N, W = list(map(int, input().split()))
dp = [[0 for i in range(W + 1)] for j in range(N + 1)]
for j in range(N):
w, v = list(map(int, input().split()))
for k in range(W + 1):
if k >= w:
dp[j + 1][k] = max(dp[j][k - w] + v, dp[j][k])
else:
dp[j + 1][k] = dp[j][k]
print((dp[N][W]))
| N, W = list(map(int, input().split()))
dp = [[0] * (W + 1) for i in range(N + 1)]
for i in range(N):
w, v = list(map(int, input().split()))
for j in range(W + 1):
if w + j <= W:
dp[i + 1][j + w] = max(dp[i][j + w], dp[i][j] + v)
dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])
else:
dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])
print((max(dp[N])))
| false | 0 | [
"-dp = [[0 for i in range(W + 1)] for j in range(N + 1)]",
"-for j in range(N):",
"+dp = [[0] * (W + 1) for i in range(N + 1)]",
"+for i in range(N):",
"- for k in range(W + 1):",
"- if k >= w:",
"- dp[j + 1][k] = max(dp[j][k - w] + v, dp[j][k])",
"+ for j in range(W + 1):",
"+ if w + j <= W:",
"+ dp[i + 1][j + w] = max(dp[i][j + w], dp[i][j] + v)",
"+ dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])",
"- dp[j + 1][k] = dp[j][k]",
"-print((dp[N][W]))",
"+ dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])",
"+print((max(dp[N])))"
] | false | 0.037764 | 0.049687 | 0.760041 | [
"s608968451",
"s369611823"
] |
u373499377 | p04044 | python | s762151112 | s969150092 | 20 | 18 | 3,064 | 3,060 | Accepted | Accepted | 10 | def main():
n, l = list(map(int, input().split()))
words = []
for i in range(n):
words.append(eval(input()))
words.sort()
print((''.join(words)))
if __name__ == "__main__":
main()
| def main():
n, l = list(map(int, input().split()))
words = [eval(input()) for i in range(n)]
# words = []
# for i in range(n):
# words.append(input())
words.sort()
print((''.join(words)))
if __name__ == "__main__":
main()
| 13 | 14 | 214 | 261 | def main():
n, l = list(map(int, input().split()))
words = []
for i in range(n):
words.append(eval(input()))
words.sort()
print(("".join(words)))
if __name__ == "__main__":
main()
| def main():
n, l = list(map(int, input().split()))
words = [eval(input()) for i in range(n)]
# words = []
# for i in range(n):
# words.append(input())
words.sort()
print(("".join(words)))
if __name__ == "__main__":
main()
| false | 7.142857 | [
"- words = []",
"- for i in range(n):",
"- words.append(eval(input()))",
"+ words = [eval(input()) for i in range(n)]",
"+ # words = []",
"+ # for i in range(n):",
"+ # words.append(input())"
] | false | 0.036488 | 0.036154 | 1.00925 | [
"s762151112",
"s969150092"
] |
u268793453 | p03846 | python | s795377665 | s990639740 | 105 | 85 | 14,820 | 14,820 | Accepted | Accepted | 19.05 | from collections import defaultdict
n = int(eval(input()))
A = [int(i) for i in input().split()]
p = 10 ** 9 + 7
m = n % 2 == 0
cnt = defaultdict(int)
for a in A:
if (a % 2 == 0) == m:
print((0))
exit()
cnt[a] += 1
if cnt[a] > 2 or cnt[0] > 1:
print((0))
exit()
print((pow(2, (n//2), p))) | from collections import defaultdict
n = int(eval(input()))
A = [int(i) for i in input().split()]
p = 10 ** 9 + 7
m = n % 2 == 0
cnt = defaultdict(int)
for a in A:
if (a % 2 == 0) == m:
print((0))
exit()
cnt[a] += 1
if cnt[0] > 1:
print((0))
exit(0)
del cnt[0]
for c in list(cnt.values()):
if c != 2:
print((0))
exit(0)
print((pow(2, (n//2), p))) | 19 | 27 | 342 | 410 | from collections import defaultdict
n = int(eval(input()))
A = [int(i) for i in input().split()]
p = 10**9 + 7
m = n % 2 == 0
cnt = defaultdict(int)
for a in A:
if (a % 2 == 0) == m:
print((0))
exit()
cnt[a] += 1
if cnt[a] > 2 or cnt[0] > 1:
print((0))
exit()
print((pow(2, (n // 2), p)))
| from collections import defaultdict
n = int(eval(input()))
A = [int(i) for i in input().split()]
p = 10**9 + 7
m = n % 2 == 0
cnt = defaultdict(int)
for a in A:
if (a % 2 == 0) == m:
print((0))
exit()
cnt[a] += 1
if cnt[0] > 1:
print((0))
exit(0)
del cnt[0]
for c in list(cnt.values()):
if c != 2:
print((0))
exit(0)
print((pow(2, (n // 2), p)))
| false | 29.62963 | [
"- if cnt[a] > 2 or cnt[0] > 1:",
"+if cnt[0] > 1:",
"+ print((0))",
"+ exit(0)",
"+del cnt[0]",
"+for c in list(cnt.values()):",
"+ if c != 2:",
"- exit()",
"+ exit(0)"
] | false | 0.047859 | 0.048639 | 0.983968 | [
"s795377665",
"s990639740"
] |
u118772524 | p02676 | python | s504758819 | s944015194 | 26 | 23 | 8,928 | 9,164 | Accepted | Accepted | 11.54 |
k= int(eval(input()))
s= eval(input())
a=len(s)
if k >= a:
print(s)
else :
print((s[:k]+"..."))
| k= int(eval(input()))
s= str(eval(input()))
a=len(s)
if k >= a:
print(s)
else :
print((s[:k]+"...")) | 12 | 10 | 103 | 102 | k = int(eval(input()))
s = eval(input())
a = len(s)
if k >= a:
print(s)
else:
print((s[:k] + "..."))
| k = int(eval(input()))
s = str(eval(input()))
a = len(s)
if k >= a:
print(s)
else:
print((s[:k] + "..."))
| false | 16.666667 | [
"-s = eval(input())",
"+s = str(eval(input()))"
] | false | 0.03565 | 0.044418 | 0.802604 | [
"s504758819",
"s944015194"
] |
u440566786 | p02913 | python | s648540674 | s617333947 | 955 | 217 | 53,636 | 43,376 | Accepted | Accepted | 77.28 | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
class SuffixArray(object):
"""
construct:
suffix array: O(N(logN)^2)
lcp array: O(N)
sparse table: O(NlogN)
query:
lcp: O(1)
"""
def __init__(self,s):
"""
s: str
"""
self.__s=s
self.__n=len(s)
self.__suffix_array()
self.__lcp_array()
self.__sparse_table()
# suffix array
def __suffix_array(self):
s=self.__s; n=self.__n
# initialize
sa=list(range(n))
rank=[ord(s[i]) for i in range(n)]
tmp=[0]*n
k=1
cmp_key=lambda i:(rank[i],rank[i+k] if i+k<n else -1)
# iterate
while(k<=n):
sa.sort(key=cmp_key)
tmp[sa[0]]=0
for i in range(1,n):
tmp[sa[i]]=tmp[sa[i-1]]+(cmp_key(sa[i-1])<cmp_key(sa[i]))
rank=tmp[:]
k<<=1
self.__sa=sa
self.__rank=rank
# LCP array
def __lcp_array(self):
s=self.__s; n=self.__n
sa=self.__sa; rank=self.__rank
lcp=[0]*n
h=0
for i in range(n):
j=sa[rank[i]-1]
if h>0: h-=1
while j+h<n and i+h<n and s[j+h]==s[i+h]: h+=1
lcp[rank[i]]=h
self.__lcp=lcp
# sparse table
def __sparse_table(self):
n=self.__n
logn=max(0,(n-1).bit_length())
table=[[0]*n for _ in range(logn)]
table[0]=self.__lcp[:]
# construct
from itertools import product
for i,k in product(list(range(1,logn)),list(range(n))):
if k+(1<<(i-1))>=n:
table[i][k]=table[i-1][k]
else:
table[i][k]=min(table[i-1][k],table[i-1][k+(1<<(i-1))])
self.__table=table
def lcp(self,a,b):
"""
a,b: int 0<=a,b<n
return LCP length between s[a:] and s[b:]
"""
if a==b: return self.__n-a
l,r=self.__rank[a],self.__rank[b]
l,r=min(l,r)+1,max(l,r)+1
i=max(0,(r-l-1).bit_length()-1)
table=self.__table
return min(table[i][l],table[i][r-(1<<i)])
def resolve():
n=int(eval(input()))
s=eval(input())
sa=SuffixArray(s)
ans=0
for i in range(n):
for j in range(i+1,n):
ans=max(ans,min(sa.lcp(i,j),j-i))
print(ans)
resolve() | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def bisect(l,r,f,discrete=True,left=True):
"""
l,r: l<r int if discrete else float
f: function defined on [l,...,r] to {False,True}
if discrete: f defined on Z; else: R
if left: f satisfies that there uniquely exists d such that iff i<=d then f(i)
else: iff i>=d then f(i) is True
return d such as those above
"""
assert r>l
if discrete: assert isinstance(l,int) and isinstance(r,int)
eps=1 if discrete else 10**-12
if (not left)^f(r): return r if left else r+1
elif left^f(l): return l-1 if left else l
while(r-l>eps):
h=(l+r)//2 if discrete else (l+r)/2
if (not left)^f(h): l=h
else: r=h
return h if not discrete else l if left else r
class RollingHash(object):
"""
construct: O(N)
query:
hash: O(1)
lcp: O(logN)
"""
__base1=1007; __mod1=10**9
__base2=1009; __mod2=10**7
def __init__(self,S):
"""
S: str
"""
n=len(S)
self.__n=n
b1=self.__base1; m1=self.__mod1
b2=self.__base2; m2=self.__mod2
H1,H2=[0]*(n+1),[0]*(n+1)
P1,P2=[1]*(n+1),[1]*(n+1)
for i,s in enumerate(S):
H1[i+1]=(H1[i]*b1+ord(s))%m1
H2[i+1]=(H2[i]*b2+ord(s))%m2
P1[i+1]=P1[i]*b1%m1
P2[i+1]=P2[i]*b2%m2
self.__H1=H1; self.__H2=H2
self.__P1=P1; self.__P2=P2
@property
def len(self):
return self.__n
def hash(self,l,r=None):
"""
l,r: int (0<=l<=r<=n)
return (hash1,hash2) of S[l:r]
"""
m1=self.__mod1; m2=self.__mod2
if r is None: r=self.__n
assert 0<=l<=r<=self.__n
return ((self.__H1[r]-self.__P1[r-l]*self.__H1[l]%m1)%m1,
(self.__H2[r]-self.__P2[r-l]*self.__H2[l]%m2)%m2)
@classmethod
def lcp(cls,rh1,rh2,l1,l2,r1=None,r2=None):
"""
rh1,rh2: RollingHash object
l1,l2,r1,r2: int 0<=l1<=r1<=r1.len,0<=l2<=r2<=rh2.len
return lcp length between rh1[l1:r1] and rh2[l2:r2]
"""
if r1 is None: r1=rh1.__n
if r2 is None: r2=rh2.__n
assert 0<=l1<=r1<=rh1.__n and 0<=l2<=r2<=rh2.__n
L=0
R=min(r1-l1,r2-l2)
if rh1.hash(l1,l1+R)==rh2.hash(l2,l2+R): return R
while(R-L>1):
H=(L+R)//2
if rh1.hash(l1,l1+H)==rh2.hash(l2,l2+H): L=H
else: R=H
return L
def resolve():
n=int(eval(input()))
S=eval(input())
# d=0ではtrue,d=nではfalseなので、そこでbisectする
rh=RollingHash(S)
def judge(d):
# initialize
J={rh.hash(i,i+d):-1 for i in range(n-d+1)}
for i in range(n-d+1):
h=rh.hash(i,i+d)
if J[h]!=-1:
if i-J[h]>=d: return True
else: J[h]=i
return False
print((bisect(0,n,judge)))
resolve() | 93 | 103 | 2,510 | 3,065 | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
class SuffixArray(object):
"""
construct:
suffix array: O(N(logN)^2)
lcp array: O(N)
sparse table: O(NlogN)
query:
lcp: O(1)
"""
def __init__(self, s):
"""
s: str
"""
self.__s = s
self.__n = len(s)
self.__suffix_array()
self.__lcp_array()
self.__sparse_table()
# suffix array
def __suffix_array(self):
s = self.__s
n = self.__n
# initialize
sa = list(range(n))
rank = [ord(s[i]) for i in range(n)]
tmp = [0] * n
k = 1
cmp_key = lambda i: (rank[i], rank[i + k] if i + k < n else -1)
# iterate
while k <= n:
sa.sort(key=cmp_key)
tmp[sa[0]] = 0
for i in range(1, n):
tmp[sa[i]] = tmp[sa[i - 1]] + (cmp_key(sa[i - 1]) < cmp_key(sa[i]))
rank = tmp[:]
k <<= 1
self.__sa = sa
self.__rank = rank
# LCP array
def __lcp_array(self):
s = self.__s
n = self.__n
sa = self.__sa
rank = self.__rank
lcp = [0] * n
h = 0
for i in range(n):
j = sa[rank[i] - 1]
if h > 0:
h -= 1
while j + h < n and i + h < n and s[j + h] == s[i + h]:
h += 1
lcp[rank[i]] = h
self.__lcp = lcp
# sparse table
def __sparse_table(self):
n = self.__n
logn = max(0, (n - 1).bit_length())
table = [[0] * n for _ in range(logn)]
table[0] = self.__lcp[:]
# construct
from itertools import product
for i, k in product(list(range(1, logn)), list(range(n))):
if k + (1 << (i - 1)) >= n:
table[i][k] = table[i - 1][k]
else:
table[i][k] = min(table[i - 1][k], table[i - 1][k + (1 << (i - 1))])
self.__table = table
def lcp(self, a, b):
"""
a,b: int 0<=a,b<n
return LCP length between s[a:] and s[b:]
"""
if a == b:
return self.__n - a
l, r = self.__rank[a], self.__rank[b]
l, r = min(l, r) + 1, max(l, r) + 1
i = max(0, (r - l - 1).bit_length() - 1)
table = self.__table
return min(table[i][l], table[i][r - (1 << i)])
def resolve():
n = int(eval(input()))
s = eval(input())
sa = SuffixArray(s)
ans = 0
for i in range(n):
for j in range(i + 1, n):
ans = max(ans, min(sa.lcp(i, j), j - i))
print(ans)
resolve()
| import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def bisect(l, r, f, discrete=True, left=True):
"""
l,r: l<r int if discrete else float
f: function defined on [l,...,r] to {False,True}
if discrete: f defined on Z; else: R
if left: f satisfies that there uniquely exists d such that iff i<=d then f(i)
else: iff i>=d then f(i) is True
return d such as those above
"""
assert r > l
if discrete:
assert isinstance(l, int) and isinstance(r, int)
eps = 1 if discrete else 10**-12
if (not left) ^ f(r):
return r if left else r + 1
elif left ^ f(l):
return l - 1 if left else l
while r - l > eps:
h = (l + r) // 2 if discrete else (l + r) / 2
if (not left) ^ f(h):
l = h
else:
r = h
return h if not discrete else l if left else r
class RollingHash(object):
"""
construct: O(N)
query:
hash: O(1)
lcp: O(logN)
"""
__base1 = 1007
__mod1 = 10**9
__base2 = 1009
__mod2 = 10**7
def __init__(self, S):
"""
S: str
"""
n = len(S)
self.__n = n
b1 = self.__base1
m1 = self.__mod1
b2 = self.__base2
m2 = self.__mod2
H1, H2 = [0] * (n + 1), [0] * (n + 1)
P1, P2 = [1] * (n + 1), [1] * (n + 1)
for i, s in enumerate(S):
H1[i + 1] = (H1[i] * b1 + ord(s)) % m1
H2[i + 1] = (H2[i] * b2 + ord(s)) % m2
P1[i + 1] = P1[i] * b1 % m1
P2[i + 1] = P2[i] * b2 % m2
self.__H1 = H1
self.__H2 = H2
self.__P1 = P1
self.__P2 = P2
@property
def len(self):
return self.__n
def hash(self, l, r=None):
"""
l,r: int (0<=l<=r<=n)
return (hash1,hash2) of S[l:r]
"""
m1 = self.__mod1
m2 = self.__mod2
if r is None:
r = self.__n
assert 0 <= l <= r <= self.__n
return (
(self.__H1[r] - self.__P1[r - l] * self.__H1[l] % m1) % m1,
(self.__H2[r] - self.__P2[r - l] * self.__H2[l] % m2) % m2,
)
@classmethod
def lcp(cls, rh1, rh2, l1, l2, r1=None, r2=None):
"""
rh1,rh2: RollingHash object
l1,l2,r1,r2: int 0<=l1<=r1<=r1.len,0<=l2<=r2<=rh2.len
return lcp length between rh1[l1:r1] and rh2[l2:r2]
"""
if r1 is None:
r1 = rh1.__n
if r2 is None:
r2 = rh2.__n
assert 0 <= l1 <= r1 <= rh1.__n and 0 <= l2 <= r2 <= rh2.__n
L = 0
R = min(r1 - l1, r2 - l2)
if rh1.hash(l1, l1 + R) == rh2.hash(l2, l2 + R):
return R
while R - L > 1:
H = (L + R) // 2
if rh1.hash(l1, l1 + H) == rh2.hash(l2, l2 + H):
L = H
else:
R = H
return L
def resolve():
n = int(eval(input()))
S = eval(input())
# d=0ではtrue,d=nではfalseなので、そこでbisectする
rh = RollingHash(S)
def judge(d):
# initialize
J = {rh.hash(i, i + d): -1 for i in range(n - d + 1)}
for i in range(n - d + 1):
h = rh.hash(i, i + d)
if J[h] != -1:
if i - J[h] >= d:
return True
else:
J[h] = i
return False
print((bisect(0, n, judge)))
resolve()
| false | 9.708738 | [
"-class SuffixArray(object):",
"+def bisect(l, r, f, discrete=True, left=True):",
"- construct:",
"- suffix array: O(N(logN)^2)",
"- lcp array: O(N)",
"- sparse table: O(NlogN)",
"+ l,r: l<r int if discrete else float",
"+ f: function defined on [l,...,r] to {False,True}",
"+ if discrete: f defined on Z; else: R",
"+ if left: f satisfies that there uniquely exists d such that iff i<=d then f(i)",
"+ else: iff i>=d then f(i) is True",
"+ return d such as those above",
"+ \"\"\"",
"+ assert r > l",
"+ if discrete:",
"+ assert isinstance(l, int) and isinstance(r, int)",
"+ eps = 1 if discrete else 10**-12",
"+ if (not left) ^ f(r):",
"+ return r if left else r + 1",
"+ elif left ^ f(l):",
"+ return l - 1 if left else l",
"+ while r - l > eps:",
"+ h = (l + r) // 2 if discrete else (l + r) / 2",
"+ if (not left) ^ f(h):",
"+ l = h",
"+ else:",
"+ r = h",
"+ return h if not discrete else l if left else r",
"+",
"+",
"+class RollingHash(object):",
"+ \"\"\"",
"+ construct: O(N)",
"- lcp: O(1)",
"+ hash: O(1)",
"+ lcp: O(logN)",
"- def __init__(self, s):",
"+ __base1 = 1007",
"+ __mod1 = 10**9",
"+ __base2 = 1009",
"+ __mod2 = 10**7",
"+",
"+ def __init__(self, S):",
"- s: str",
"+ S: str",
"- self.__s = s",
"- self.__n = len(s)",
"- self.__suffix_array()",
"- self.__lcp_array()",
"- self.__sparse_table()",
"+ n = len(S)",
"+ self.__n = n",
"+ b1 = self.__base1",
"+ m1 = self.__mod1",
"+ b2 = self.__base2",
"+ m2 = self.__mod2",
"+ H1, H2 = [0] * (n + 1), [0] * (n + 1)",
"+ P1, P2 = [1] * (n + 1), [1] * (n + 1)",
"+ for i, s in enumerate(S):",
"+ H1[i + 1] = (H1[i] * b1 + ord(s)) % m1",
"+ H2[i + 1] = (H2[i] * b2 + ord(s)) % m2",
"+ P1[i + 1] = P1[i] * b1 % m1",
"+ P2[i + 1] = P2[i] * b2 % m2",
"+ self.__H1 = H1",
"+ self.__H2 = H2",
"+ self.__P1 = P1",
"+ self.__P2 = P2",
"- # suffix array",
"- def __suffix_array(self):",
"- s = self.__s",
"- n = self.__n",
"- # initialize",
"- sa = list(range(n))",
"- rank = [ord(s[i]) for i in range(n)]",
"- tmp = [0] * n",
"- k = 1",
"- cmp_key = lambda i: (rank[i], rank[i + k] if i + k < n else -1)",
"- # iterate",
"- while k <= n:",
"- sa.sort(key=cmp_key)",
"- tmp[sa[0]] = 0",
"- for i in range(1, n):",
"- tmp[sa[i]] = tmp[sa[i - 1]] + (cmp_key(sa[i - 1]) < cmp_key(sa[i]))",
"- rank = tmp[:]",
"- k <<= 1",
"- self.__sa = sa",
"- self.__rank = rank",
"+ @property",
"+ def len(self):",
"+ return self.__n",
"- # LCP array",
"- def __lcp_array(self):",
"- s = self.__s",
"- n = self.__n",
"- sa = self.__sa",
"- rank = self.__rank",
"- lcp = [0] * n",
"- h = 0",
"- for i in range(n):",
"- j = sa[rank[i] - 1]",
"- if h > 0:",
"- h -= 1",
"- while j + h < n and i + h < n and s[j + h] == s[i + h]:",
"- h += 1",
"- lcp[rank[i]] = h",
"- self.__lcp = lcp",
"+ def hash(self, l, r=None):",
"+ \"\"\"",
"+ l,r: int (0<=l<=r<=n)",
"+ return (hash1,hash2) of S[l:r]",
"+ \"\"\"",
"+ m1 = self.__mod1",
"+ m2 = self.__mod2",
"+ if r is None:",
"+ r = self.__n",
"+ assert 0 <= l <= r <= self.__n",
"+ return (",
"+ (self.__H1[r] - self.__P1[r - l] * self.__H1[l] % m1) % m1,",
"+ (self.__H2[r] - self.__P2[r - l] * self.__H2[l] % m2) % m2,",
"+ )",
"- # sparse table",
"- def __sparse_table(self):",
"- n = self.__n",
"- logn = max(0, (n - 1).bit_length())",
"- table = [[0] * n for _ in range(logn)]",
"- table[0] = self.__lcp[:]",
"- # construct",
"- from itertools import product",
"-",
"- for i, k in product(list(range(1, logn)), list(range(n))):",
"- if k + (1 << (i - 1)) >= n:",
"- table[i][k] = table[i - 1][k]",
"+ @classmethod",
"+ def lcp(cls, rh1, rh2, l1, l2, r1=None, r2=None):",
"+ \"\"\"",
"+ rh1,rh2: RollingHash object",
"+ l1,l2,r1,r2: int 0<=l1<=r1<=r1.len,0<=l2<=r2<=rh2.len",
"+ return lcp length between rh1[l1:r1] and rh2[l2:r2]",
"+ \"\"\"",
"+ if r1 is None:",
"+ r1 = rh1.__n",
"+ if r2 is None:",
"+ r2 = rh2.__n",
"+ assert 0 <= l1 <= r1 <= rh1.__n and 0 <= l2 <= r2 <= rh2.__n",
"+ L = 0",
"+ R = min(r1 - l1, r2 - l2)",
"+ if rh1.hash(l1, l1 + R) == rh2.hash(l2, l2 + R):",
"+ return R",
"+ while R - L > 1:",
"+ H = (L + R) // 2",
"+ if rh1.hash(l1, l1 + H) == rh2.hash(l2, l2 + H):",
"+ L = H",
"- table[i][k] = min(table[i - 1][k], table[i - 1][k + (1 << (i - 1))])",
"- self.__table = table",
"-",
"- def lcp(self, a, b):",
"- \"\"\"",
"- a,b: int 0<=a,b<n",
"- return LCP length between s[a:] and s[b:]",
"- \"\"\"",
"- if a == b:",
"- return self.__n - a",
"- l, r = self.__rank[a], self.__rank[b]",
"- l, r = min(l, r) + 1, max(l, r) + 1",
"- i = max(0, (r - l - 1).bit_length() - 1)",
"- table = self.__table",
"- return min(table[i][l], table[i][r - (1 << i)])",
"+ R = H",
"+ return L",
"- s = eval(input())",
"- sa = SuffixArray(s)",
"- ans = 0",
"- for i in range(n):",
"- for j in range(i + 1, n):",
"- ans = max(ans, min(sa.lcp(i, j), j - i))",
"- print(ans)",
"+ S = eval(input())",
"+ # d=0ではtrue,d=nではfalseなので、そこでbisectする",
"+ rh = RollingHash(S)",
"+",
"+ def judge(d):",
"+ # initialize",
"+ J = {rh.hash(i, i + d): -1 for i in range(n - d + 1)}",
"+ for i in range(n - d + 1):",
"+ h = rh.hash(i, i + d)",
"+ if J[h] != -1:",
"+ if i - J[h] >= d:",
"+ return True",
"+ else:",
"+ J[h] = i",
"+ return False",
"+",
"+ print((bisect(0, n, judge)))"
] | false | 0.047361 | 0.039476 | 1.199752 | [
"s648540674",
"s617333947"
] |
u347600233 | p02762 | python | s480795128 | s760949693 | 1,117 | 656 | 13,420 | 18,324 | Accepted | Accepted | 41.27 | # UnionFind: https://note.nkmk.me/python-union-find/
n, m, k = list(map(int, input().split()))
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
def find(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.root[x] > self.root[y]:
x, y = y, x
self.root[x] += self.root[y]
self.root[y] = x
def is_same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.root[self.find(x)]
candidate = [-1] * (n + 1)
f_ship = UnionFind(n)
for _ in range(m):
a, b = list(map(int, input().split()))
candidate[a] -= 1
candidate[b] -= 1
f_ship.unite(a, b)
for _ in range(k):
c, d = list(map(int, input().split()))
if f_ship.is_same(c, d):
candidate[c] -= 1
candidate[d] -= 1
for i in range(1, n + 1):
candidate[i] += f_ship.size(i)
print((*candidate[1:])) | # UnionFind: https://note.nkmk.me/python-union-find/
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
def find(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.root[x] > self.root[y]:
x, y = y, x
self.root[x] += self.root[y]
self.root[y] = x
def is_same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.root[self.find(x)]
n, m, k = list(map(int, input().split()))
friends = UnionFind(n)
f_or_b = [1] * (n + 1)
for i in range(m):
a, b = list(map(int, input().split()))
friends.unite(a, b)
f_or_b[a] += 1
f_or_b[b] += 1
for i in range(k):
c, d = list(map(int, input().split()))
if friends.is_same(c, d):
f_or_b[c] += 1
f_or_b[d] += 1
print((*[friends.size(i) - f_or_b[i] for i in range(1, n + 1)])) | 45 | 43 | 1,210 | 1,175 | # UnionFind: https://note.nkmk.me/python-union-find/
n, m, k = list(map(int, input().split()))
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
def find(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.root[x] > self.root[y]:
x, y = y, x
self.root[x] += self.root[y]
self.root[y] = x
def is_same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.root[self.find(x)]
candidate = [-1] * (n + 1)
f_ship = UnionFind(n)
for _ in range(m):
a, b = list(map(int, input().split()))
candidate[a] -= 1
candidate[b] -= 1
f_ship.unite(a, b)
for _ in range(k):
c, d = list(map(int, input().split()))
if f_ship.is_same(c, d):
candidate[c] -= 1
candidate[d] -= 1
for i in range(1, n + 1):
candidate[i] += f_ship.size(i)
print((*candidate[1:]))
| # UnionFind: https://note.nkmk.me/python-union-find/
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
def find(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.root[x] > self.root[y]:
x, y = y, x
self.root[x] += self.root[y]
self.root[y] = x
def is_same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.root[self.find(x)]
n, m, k = list(map(int, input().split()))
friends = UnionFind(n)
f_or_b = [1] * (n + 1)
for i in range(m):
a, b = list(map(int, input().split()))
friends.unite(a, b)
f_or_b[a] += 1
f_or_b[b] += 1
for i in range(k):
c, d = list(map(int, input().split()))
if friends.is_same(c, d):
f_or_b[c] += 1
f_or_b[d] += 1
print((*[friends.size(i) - f_or_b[i] for i in range(1, n + 1)]))
| false | 4.444444 | [
"-n, m, k = list(map(int, input().split()))",
"-",
"-",
"-candidate = [-1] * (n + 1)",
"-f_ship = UnionFind(n)",
"-for _ in range(m):",
"+n, m, k = list(map(int, input().split()))",
"+friends = UnionFind(n)",
"+f_or_b = [1] * (n + 1)",
"+for i in range(m):",
"- candidate[a] -= 1",
"- candidate[b] -= 1",
"- f_ship.unite(a, b)",
"-for _ in range(k):",
"+ friends.unite(a, b)",
"+ f_or_b[a] += 1",
"+ f_or_b[b] += 1",
"+for i in range(k):",
"- if f_ship.is_same(c, d):",
"- candidate[c] -= 1",
"- candidate[d] -= 1",
"-for i in range(1, n + 1):",
"- candidate[i] += f_ship.size(i)",
"-print((*candidate[1:]))",
"+ if friends.is_same(c, d):",
"+ f_or_b[c] += 1",
"+ f_or_b[d] += 1",
"+print((*[friends.size(i) - f_or_b[i] for i in range(1, n + 1)]))"
] | false | 0.042843 | 0.103307 | 0.414714 | [
"s480795128",
"s760949693"
] |
u189023301 | p02972 | python | s352987963 | s087492539 | 238 | 212 | 13,108 | 13,088 | Accepted | Accepted | 10.92 | n = int(input())
lis = list(map(int, input().split()))
val = [0] * n
for i in range(n, 0, -1):
if n // i == 1:
val[i - 1] = lis[i - 1]
else:
a = sum(val[i - 1::i])
if a % 2 == lis[i - 1]:
val[i - 1] = 0
else:
val[i - 1] = 1
print(sum(val))
print(*[i + 1 for i in range(n) if val[i] == 1], sep=" ")
| import sys
input = sys.stdin.readline
def main():
n = int(input())
lis = list(map(int, input().split()))
val = [0] * n
for i in range(n, 0, -1):
if n // i == 1:
val[i - 1] = lis[i - 1]
else:
a = sum(val[i - 1::i])
if a % 2 != lis[i - 1]:
val[i - 1] ^= 1
print(sum(val))
print(*[i + 1 for i in range(n) if val[i] == 1], sep=" ")
if __name__ == '__main__':
main()
| 16 | 21 | 379 | 485 | n = int(input())
lis = list(map(int, input().split()))
val = [0] * n
for i in range(n, 0, -1):
if n // i == 1:
val[i - 1] = lis[i - 1]
else:
a = sum(val[i - 1 :: i])
if a % 2 == lis[i - 1]:
val[i - 1] = 0
else:
val[i - 1] = 1
print(sum(val))
print(*[i + 1 for i in range(n) if val[i] == 1], sep=" ")
| import sys
input = sys.stdin.readline
def main():
n = int(input())
lis = list(map(int, input().split()))
val = [0] * n
for i in range(n, 0, -1):
if n // i == 1:
val[i - 1] = lis[i - 1]
else:
a = sum(val[i - 1 :: i])
if a % 2 != lis[i - 1]:
val[i - 1] ^= 1
print(sum(val))
print(*[i + 1 for i in range(n) if val[i] == 1], sep=" ")
if __name__ == "__main__":
main()
| false | 23.809524 | [
"-n = int(input())",
"-lis = list(map(int, input().split()))",
"-val = [0] * n",
"-for i in range(n, 0, -1):",
"- if n // i == 1:",
"- val[i - 1] = lis[i - 1]",
"- else:",
"- a = sum(val[i - 1 :: i])",
"- if a % 2 == lis[i - 1]:",
"- val[i - 1] = 0",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+",
"+def main():",
"+ n = int(input())",
"+ lis = list(map(int, input().split()))",
"+ val = [0] * n",
"+ for i in range(n, 0, -1):",
"+ if n // i == 1:",
"+ val[i - 1] = lis[i - 1]",
"- val[i - 1] = 1",
"-print(sum(val))",
"-print(*[i + 1 for i in range(n) if val[i] == 1], sep=\" \")",
"+ a = sum(val[i - 1 :: i])",
"+ if a % 2 != lis[i - 1]:",
"+ val[i - 1] ^= 1",
"+ print(sum(val))",
"+ print(*[i + 1 for i in range(n) if val[i] == 1], sep=\" \")",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.04156 | 0.080027 | 0.519324 | [
"s352987963",
"s087492539"
] |
u780025254 | p02392 | python | s780595058 | s281751180 | 30 | 20 | 7,712 | 5,588 | Accepted | Accepted | 33.33 | nums = input().split()
a = int(nums[0])
b = int(nums[1])
c = int(nums[2])
if a < b < c:
print('Yes')
else:
print('No') | a, b, c = list(map(int, input().split()))
if a < b < c:
print("Yes")
else:
print("No")
| 9 | 6 | 135 | 95 | nums = input().split()
a = int(nums[0])
b = int(nums[1])
c = int(nums[2])
if a < b < c:
print("Yes")
else:
print("No")
| a, b, c = list(map(int, input().split()))
if a < b < c:
print("Yes")
else:
print("No")
| false | 33.333333 | [
"-nums = input().split()",
"-a = int(nums[0])",
"-b = int(nums[1])",
"-c = int(nums[2])",
"+a, b, c = list(map(int, input().split()))"
] | false | 0.062281 | 0.035111 | 1.773826 | [
"s780595058",
"s281751180"
] |
u775681539 | p02996 | python | s733256196 | s719085549 | 704 | 412 | 31,992 | 31,828 | Accepted | Accepted | 41.48 | #python3
from operator import itemgetter
from itertools import accumulate
def main():
n = int(eval(input()))
d = []
for _ in range(n):
x, y = list(map(int, input().split()))
d.append((x, y))
d.sort(key=itemgetter(1))
acc = 0
f = True
for i in range(n):
acc = acc+d[i][0]
if acc > d[i][1]:
f = False
if f:
print('Yes')
else:
print('No')
main()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from operator import itemgetter
def main():
N = int(readline())
tasks = []
for _ in range(N):
a, b = list(map(int, readline().split()))
tasks.append((a, b))
tasks.sort(key=itemgetter(1))
time = 0
for a, b in tasks:
time += a
if time > b:
print('No')
return
print('Yes')
if __name__ == '__main__':
main()
| 21 | 22 | 449 | 527 | # python3
from operator import itemgetter
from itertools import accumulate
def main():
n = int(eval(input()))
d = []
for _ in range(n):
x, y = list(map(int, input().split()))
d.append((x, y))
d.sort(key=itemgetter(1))
acc = 0
f = True
for i in range(n):
acc = acc + d[i][0]
if acc > d[i][1]:
f = False
if f:
print("Yes")
else:
print("No")
main()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from operator import itemgetter
def main():
N = int(readline())
tasks = []
for _ in range(N):
a, b = list(map(int, readline().split()))
tasks.append((a, b))
tasks.sort(key=itemgetter(1))
time = 0
for a, b in tasks:
time += a
if time > b:
print("No")
return
print("Yes")
if __name__ == "__main__":
main()
| false | 4.545455 | [
"-# python3",
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"-from itertools import accumulate",
"- n = int(eval(input()))",
"- d = []",
"- for _ in range(n):",
"- x, y = list(map(int, input().split()))",
"- d.append((x, y))",
"- d.sort(key=itemgetter(1))",
"- acc = 0",
"- f = True",
"- for i in range(n):",
"- acc = acc + d[i][0]",
"- if acc > d[i][1]:",
"- f = False",
"- if f:",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"+ N = int(readline())",
"+ tasks = []",
"+ for _ in range(N):",
"+ a, b = list(map(int, readline().split()))",
"+ tasks.append((a, b))",
"+ tasks.sort(key=itemgetter(1))",
"+ time = 0",
"+ for a, b in tasks:",
"+ time += a",
"+ if time > b:",
"+ print(\"No\")",
"+ return",
"+ print(\"Yes\")",
"-main()",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.068257 | 0.038176 | 1.787967 | [
"s733256196",
"s719085549"
] |
u237513745 | p02947 | python | s652803763 | s535735299 | 531 | 438 | 21,988 | 23,644 | Accepted | Accepted | 17.51 | n = int(eval(input()))
dict = {}
ans = 0
for i in range(n):
s = str(sorted(eval(input())))
if s in list(dict.keys()):
ans += dict[s]
dict[s] += 1
else:
dict[s] = 1
print(ans)
| n = int(eval(input()))
dict = {}
ans = 0
for i in range(n):
s = tuple(sorted(eval(input())))
if s in list(dict.keys()):
ans += dict[s]
dict[s] += 1
else:
dict[s] = 1
print(ans) | 12 | 12 | 205 | 206 | n = int(eval(input()))
dict = {}
ans = 0
for i in range(n):
s = str(sorted(eval(input())))
if s in list(dict.keys()):
ans += dict[s]
dict[s] += 1
else:
dict[s] = 1
print(ans)
| n = int(eval(input()))
dict = {}
ans = 0
for i in range(n):
s = tuple(sorted(eval(input())))
if s in list(dict.keys()):
ans += dict[s]
dict[s] += 1
else:
dict[s] = 1
print(ans)
| false | 0 | [
"- s = str(sorted(eval(input())))",
"+ s = tuple(sorted(eval(input())))"
] | false | 0.048737 | 0.048215 | 1.010818 | [
"s652803763",
"s535735299"
] |
u156815136 | p03673 | python | s933601231 | s292691481 | 211 | 165 | 26,020 | 32,356 | Accepted | Accepted | 21.8 | #
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
r_ = n / m
if (r_ - (n // m)) > 0:
return (n//m) + 1
else:
return (n//m)"""
""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
fac[0] = 1 % mod
for i in range(1,N):
fac[i] = fac[i-1] * i % mod"""
"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
pw[0] = 1 % mod
for i in range(1,N):
pw[i] = pw[i-1] * c % mod"""
"""
def YEILD():
yield 'one'
yield 'two'
yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
if b == 0:#結局はc,0の最大公約数はcなのに
return a
return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
d = a
if b!=0:
d = extgcd(b,a%b,y,x)
y -= (a//b) * x
print(x,y)
else:
x = 1
y = 0
return d"""
def readInts():
return list(map(int,input().split()))
mod = 10**9 + 7
def main():
n = int(eval(input()))
*A, = list(map(int,input().split())) # こうすることで、当データとidxが取得できる!!!つよ!!
from collections import deque
B = deque([]) # リストとして活用できる
for i,a in enumerate(A):
if i % 2 == 0:
B.append(a)
else:
B.appendleft(a)
if n % 2 == 1:
B.reverse() # 逆順に
print((*B))
if __name__ == '__main__':
main() | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
n = I()
A = readInts()
dq = deque()
for i in range(n):
if i%2:
dq.appendleft(A[i])
else:
dq.append(A[i])
if n%2:
dq = list(dq)[::-1]
print((*dq))
| 78 | 37 | 1,427 | 822 | #
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
# import math
# mod = 10**9+7
# import itertools
# import fractions
# import numpy as np
# mod = 10**4 + 7
"""def kiri(n,m):
r_ = n / m
if (r_ - (n // m)) > 0:
return (n//m) + 1
else:
return (n//m)"""
""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
fac[0] = 1 % mod
for i in range(1,N):
fac[i] = fac[i-1] * i % mod"""
"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
pw[0] = 1 % mod
for i in range(1,N):
pw[i] = pw[i-1] * c % mod"""
"""
def YEILD():
yield 'one'
yield 'two'
yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
if b == 0:#結局はc,0の最大公約数はcなのに
return a
return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
d = a
if b!=0:
d = extgcd(b,a%b,y,x)
y -= (a//b) * x
print(x,y)
else:
x = 1
y = 0
return d"""
def readInts():
return list(map(int, input().split()))
mod = 10**9 + 7
def main():
n = int(eval(input()))
(*A,) = list(map(int, input().split())) # こうすることで、当データとidxが取得できる!!!つよ!!
from collections import deque
B = deque([]) # リストとして活用できる
for i, a in enumerate(A):
if i % 2 == 0:
B.append(a)
else:
B.appendleft(a)
if n % 2 == 1:
B.reverse() # 逆順に
print((*B))
if __name__ == "__main__":
main()
| # from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
n = I()
A = readInts()
dq = deque()
for i in range(n):
if i % 2:
dq.appendleft(A[i])
else:
dq.append(A[i])
if n % 2:
dq = list(dq)[::-1]
print((*dq))
| false | 52.564103 | [
"+# from statistics import median",
"+# import collections",
"+# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]",
"+from fractions import gcd",
"+from itertools import combinations, permutations, accumulate # (string,3) 3回",
"+",
"+# from collections import deque",
"+from collections import deque, defaultdict, Counter",
"+",
"+# import bisect",
"-# Written by NoKnowledgeGG @YlePhan",
"-# ('ω')",
"+# d = m - k[i] - k[j]",
"+# if kk[bisect.bisect_right(kk,d) - 1] == d:",
"-# import math",
"-# mod = 10**9+7",
"-# import itertools",
"-# import fractions",
"-# import numpy as np",
"-# mod = 10**4 + 7",
"-\"\"\"def kiri(n,m):",
"- r_ = n / m",
"- if (r_ - (n // m)) > 0:",
"- return (n//m) + 1",
"- else:",
"- return (n//m)\"\"\"",
"-\"\"\" n! mod m 階乗",
"-mod = 1e9 + 7",
"-N = 10000000",
"-fac = [0] * N",
"-def ini():",
"- fac[0] = 1 % mod",
"- for i in range(1,N):",
"- fac[i] = fac[i-1] * i % mod\"\"\"",
"-\"\"\"mod = 1e9+7",
"-N = 10000000",
"-pw = [0] * N",
"-def ini(c):",
"- pw[0] = 1 % mod",
"- for i in range(1,N):",
"- pw[i] = pw[i-1] * c % mod\"\"\"",
"-\"\"\"",
"-def YEILD():",
"- yield 'one'",
"- yield 'two'",
"- yield 'three'",
"-generator = YEILD()",
"-print(next(generator))",
"-print(next(generator))",
"-print(next(generator))",
"-\"\"\"",
"-\"\"\"def gcd_(a,b):",
"- if b == 0:#結局はc,0の最大公約数はcなのに",
"- return a",
"- return gcd_(a,a % b) # a = p * b + q\"\"\"",
"-\"\"\"def extgcd(a,b,x,y):",
"- d = a",
"- if b!=0:",
"- d = extgcd(b,a%b,y,x)",
"- y -= (a//b) * x",
"- print(x,y)",
"- else:",
"- x = 1",
"- y = 0",
"- return d\"\"\"",
"+#",
"+#",
"+# pythonで無理なときは、pypyでやると正解するかも!!",
"+#",
"+#",
"+import sys",
"-",
"+sys.setrecursionlimit(10000000)",
"+mod = 10**9 + 7",
"+# mod = 9982443453",
"-mod = 10**9 + 7",
"+def I():",
"+ return int(eval(input()))",
"-def main():",
"- n = int(eval(input()))",
"- (*A,) = list(map(int, input().split())) # こうすることで、当データとidxが取得できる!!!つよ!!",
"- from collections import deque",
"-",
"- B = deque([]) # リストとして活用できる",
"- for i, a in enumerate(A):",
"- if i % 2 == 0:",
"- B.append(a)",
"- else:",
"- B.appendleft(a)",
"- if n % 2 == 1:",
"- B.reverse() # 逆順に",
"- print((*B))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+n = I()",
"+A = readInts()",
"+dq = deque()",
"+for i in range(n):",
"+ if i % 2:",
"+ dq.appendleft(A[i])",
"+ else:",
"+ dq.append(A[i])",
"+if n % 2:",
"+ dq = list(dq)[::-1]",
"+print((*dq))"
] | false | 0.082144 | 0.041246 | 1.991572 | [
"s933601231",
"s292691481"
] |
u571969099 | p02862 | python | s438165395 | s821525620 | 231 | 191 | 3,188 | 38,640 | Accepted | Accepted | 17.32 | x, y = [int(i) for i in input().split()]
if (x + y) % 3 != 0:
print((0))
exit()
z = (x + y) // 3
x -= z
y -= z
p = 10**9+7
def kai(x, p):
a = 1
for i in range(1, x + 1):
a *= i
a %= p
return a
def comb(a, b, p):
if a < 0 or b < 0:
return 0
elif a < b:
return 0
c = 1
c *= kai(a, p)
c *= pow(kai(b, p), p - 2, p)
c *= pow(kai(a - b, p), p - 2, p)
return c % p
print((comb(x+y, x, p)))
| x, y = [int(i) for i in input().split()]
def kai(x, p):
a = 1
for i in range(1, x + 1):
a *= i
a %= p
return a
def comb(a, b, p):
if a < 0 or b < 0:
return 0
elif a < b:
return 0
c = 1
c *= kai(a, p)
c *= pow(kai(b, p), p - 2, p)
c *= pow(kai(a - b, p), p - 2, p)
return c % p
if (x + y) % 3 != 0:
print((0))
exit()
z = (x + y) // 3
p = 10 ** 9 + 7
print((comb(x + y - 2 * z, x - z, p)))
| 32 | 27 | 498 | 494 | x, y = [int(i) for i in input().split()]
if (x + y) % 3 != 0:
print((0))
exit()
z = (x + y) // 3
x -= z
y -= z
p = 10**9 + 7
def kai(x, p):
a = 1
for i in range(1, x + 1):
a *= i
a %= p
return a
def comb(a, b, p):
if a < 0 or b < 0:
return 0
elif a < b:
return 0
c = 1
c *= kai(a, p)
c *= pow(kai(b, p), p - 2, p)
c *= pow(kai(a - b, p), p - 2, p)
return c % p
print((comb(x + y, x, p)))
| x, y = [int(i) for i in input().split()]
def kai(x, p):
a = 1
for i in range(1, x + 1):
a *= i
a %= p
return a
def comb(a, b, p):
if a < 0 or b < 0:
return 0
elif a < b:
return 0
c = 1
c *= kai(a, p)
c *= pow(kai(b, p), p - 2, p)
c *= pow(kai(a - b, p), p - 2, p)
return c % p
if (x + y) % 3 != 0:
print((0))
exit()
z = (x + y) // 3
p = 10**9 + 7
print((comb(x + y - 2 * z, x - z, p)))
| false | 15.625 | [
"-if (x + y) % 3 != 0:",
"- print((0))",
"- exit()",
"-z = (x + y) // 3",
"-x -= z",
"-y -= z",
"-p = 10**9 + 7",
"-print((comb(x + y, x, p)))",
"+if (x + y) % 3 != 0:",
"+ print((0))",
"+ exit()",
"+z = (x + y) // 3",
"+p = 10**9 + 7",
"+print((comb(x + y - 2 * z, x - z, p)))"
] | false | 0.345959 | 0.097329 | 3.554537 | [
"s438165395",
"s821525620"
] |
u196746947 | p02647 | python | s378828408 | s198772790 | 317 | 262 | 153,116 | 127,788 | Accepted | Accepted | 17.35 | import sys
input=sys.stdin.readline
def main():
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
zeros=[0]*n
if min(a)==n:
print((*a))
exit()
for i in range(k):
x=zeros.copy()
for j in range(n):
if a[j]==0:
l=j
r=min(j+1,n)
#print(l,r)
x[l]+=1
if r!=n:
#print(r)
x[r]+=-1
#print(x)
else:
l=max(0,j-a[j])
r=min(j+a[j]+1,n)
#print(l,r)
x[l]+=1
if r!=n:
#print(r)
x[r]+=-1
#print(x)
ruiseki=[0]*n
ruiseki[0]=x[0]
a[0]=ruiseki[0]
for i in range(1,n):
ruiseki[i]=ruiseki[i-1]+x[i]
a[i]=ruiseki[i]
if min(a)==n:
print((*a))
exit()
#print(*ruiseki)
print((*a))
if __name__=="__main__":
main()
| import sys
input=sys.stdin.readline
def main():
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
zeros=[0]*n
if min(a)==n:
print((*a))
exit()
for i in range(k):
x=zeros.copy()
for j in range(n):
l=max(0,j-a[j])
r=min(j+a[j]+1,n)
#print(l,r)
x[l]+=1
if r!=n:
#print(r)
x[r]+=-1
#print(x)
ruiseki=[0]*n
ruiseki[0]=x[0]
a[0]=ruiseki[0]
for i in range(1,n):
ruiseki[i]=ruiseki[i-1]+x[i]
a[i]=ruiseki[i]
if min(a)==n:
print((*a))
exit()
#print(*ruiseki)
print((*a))
if __name__=="__main__":
main() | 46 | 38 | 1,090 | 810 | import sys
input = sys.stdin.readline
def main():
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
zeros = [0] * n
if min(a) == n:
print((*a))
exit()
for i in range(k):
x = zeros.copy()
for j in range(n):
if a[j] == 0:
l = j
r = min(j + 1, n)
# print(l,r)
x[l] += 1
if r != n:
# print(r)
x[r] += -1
# print(x)
else:
l = max(0, j - a[j])
r = min(j + a[j] + 1, n)
# print(l,r)
x[l] += 1
if r != n:
# print(r)
x[r] += -1
# print(x)
ruiseki = [0] * n
ruiseki[0] = x[0]
a[0] = ruiseki[0]
for i in range(1, n):
ruiseki[i] = ruiseki[i - 1] + x[i]
a[i] = ruiseki[i]
if min(a) == n:
print((*a))
exit()
# print(*ruiseki)
print((*a))
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
zeros = [0] * n
if min(a) == n:
print((*a))
exit()
for i in range(k):
x = zeros.copy()
for j in range(n):
l = max(0, j - a[j])
r = min(j + a[j] + 1, n)
# print(l,r)
x[l] += 1
if r != n:
# print(r)
x[r] += -1
# print(x)
ruiseki = [0] * n
ruiseki[0] = x[0]
a[0] = ruiseki[0]
for i in range(1, n):
ruiseki[i] = ruiseki[i - 1] + x[i]
a[i] = ruiseki[i]
if min(a) == n:
print((*a))
exit()
# print(*ruiseki)
print((*a))
if __name__ == "__main__":
main()
| false | 17.391304 | [
"- if a[j] == 0:",
"- l = j",
"- r = min(j + 1, n)",
"- # print(l,r)",
"- x[l] += 1",
"- if r != n:",
"- # print(r)",
"- x[r] += -1",
"- # print(x)",
"- else:",
"- l = max(0, j - a[j])",
"- r = min(j + a[j] + 1, n)",
"- # print(l,r)",
"- x[l] += 1",
"- if r != n:",
"- # print(r)",
"- x[r] += -1",
"- # print(x)",
"+ l = max(0, j - a[j])",
"+ r = min(j + a[j] + 1, n)",
"+ # print(l,r)",
"+ x[l] += 1",
"+ if r != n:",
"+ # print(r)",
"+ x[r] += -1",
"+ # print(x)"
] | false | 0.039474 | 0.046126 | 0.855797 | [
"s378828408",
"s198772790"
] |
u230621983 | p02726 | python | s267383883 | s582519778 | 1,986 | 1,736 | 3,444 | 3,444 | Accepted | Accepted | 12.59 | n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans_l = [0]*n
for i in range(n):
for j in range(i, n):
k = min(abs(j-i), abs(x-i)+1+abs(y-j), abs(x-j)+1+abs(y-i))
ans_l[k] += 1
for ans in ans_l[1:]:
print(ans) | n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans_l = [0]*n
def min_dist(a,b):
return min(b-a, abs(x-a)+1+abs(y-b), abs(x-b)+1+abs(y-a))
for i in range(n):
for j in range(i, n):
k = min_dist(i,j)
ans_l[k] += 1
for ans in ans_l[1:]:
print(ans) | 10 | 13 | 244 | 287 | n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans_l = [0] * n
for i in range(n):
for j in range(i, n):
k = min(abs(j - i), abs(x - i) + 1 + abs(y - j), abs(x - j) + 1 + abs(y - i))
ans_l[k] += 1
for ans in ans_l[1:]:
print(ans)
| n, x, y = list(map(int, input().split()))
x -= 1
y -= 1
ans_l = [0] * n
def min_dist(a, b):
return min(b - a, abs(x - a) + 1 + abs(y - b), abs(x - b) + 1 + abs(y - a))
for i in range(n):
for j in range(i, n):
k = min_dist(i, j)
ans_l[k] += 1
for ans in ans_l[1:]:
print(ans)
| false | 23.076923 | [
"+",
"+",
"+def min_dist(a, b):",
"+ return min(b - a, abs(x - a) + 1 + abs(y - b), abs(x - b) + 1 + abs(y - a))",
"+",
"+",
"- k = min(abs(j - i), abs(x - i) + 1 + abs(y - j), abs(x - j) + 1 + abs(y - i))",
"+ k = min_dist(i, j)"
] | false | 0.039773 | 0.039627 | 1.00368 | [
"s267383883",
"s582519778"
] |
u145950990 | p02995 | python | s857654535 | s277373307 | 38 | 35 | 5,344 | 5,076 | Accepted | Accepted | 7.89 | import fractions
a,b,c,d = list(map(int,input().split()))
e = c*d//fractions.gcd(c,d)
cnt = b-a+1
c_cnt = b//c-(a-1)//c
d_cnt = b//d-(a-1)//d
e_cnt = b//e-(a-1)//e
print((cnt-c_cnt-d_cnt+e_cnt)) | import fractions
def div_cnt(x):
return b//x-(a-1)//x
a,b,c,d = list(map(int,input().split()))
e = c*d//fractions.gcd(c,d)
cnt = b-a+1
c_cnt = div_cnt(c)
d_cnt = div_cnt(d)
e_cnt = div_cnt(e)
print((cnt-c_cnt-d_cnt+e_cnt)) | 8 | 11 | 193 | 229 | import fractions
a, b, c, d = list(map(int, input().split()))
e = c * d // fractions.gcd(c, d)
cnt = b - a + 1
c_cnt = b // c - (a - 1) // c
d_cnt = b // d - (a - 1) // d
e_cnt = b // e - (a - 1) // e
print((cnt - c_cnt - d_cnt + e_cnt))
| import fractions
def div_cnt(x):
return b // x - (a - 1) // x
a, b, c, d = list(map(int, input().split()))
e = c * d // fractions.gcd(c, d)
cnt = b - a + 1
c_cnt = div_cnt(c)
d_cnt = div_cnt(d)
e_cnt = div_cnt(e)
print((cnt - c_cnt - d_cnt + e_cnt))
| false | 27.272727 | [
"+",
"+",
"+def div_cnt(x):",
"+ return b // x - (a - 1) // x",
"+",
"-c_cnt = b // c - (a - 1) // c",
"-d_cnt = b // d - (a - 1) // d",
"-e_cnt = b // e - (a - 1) // e",
"+c_cnt = div_cnt(c)",
"+d_cnt = div_cnt(d)",
"+e_cnt = div_cnt(e)"
] | false | 0.058375 | 0.058056 | 1.005492 | [
"s857654535",
"s277373307"
] |
u541055501 | p03431 | python | s759867080 | s058122089 | 1,191 | 1,083 | 28,728 | 28,876 | Accepted | Accepted | 9.07 | n,k=list(map(int,input().split()))
p=998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]%p]
a=0
for i in r(n-1,k):a+=f[k-1]*pow(f[i]*f[k-1-i],-1,p)
print((a%p)) | n,k=list(map(int,input().split()))
p=998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]%p]
print((sum(f[k-1]*pow(f[i]*f[k-1-i],-1,p)for i in r(n-1,k))%p)) | 8 | 6 | 158 | 151 | n, k = list(map(int, input().split()))
p = 998244353
r = range
f = [1]
for i in r(k):
f += [-~i * f[i] % p]
a = 0
for i in r(n - 1, k):
a += f[k - 1] * pow(f[i] * f[k - 1 - i], -1, p)
print((a % p))
| n, k = list(map(int, input().split()))
p = 998244353
r = range
f = [1]
for i in r(k):
f += [-~i * f[i] % p]
print((sum(f[k - 1] * pow(f[i] * f[k - 1 - i], -1, p) for i in r(n - 1, k)) % p))
| false | 25 | [
"-a = 0",
"-for i in r(n - 1, k):",
"- a += f[k - 1] * pow(f[i] * f[k - 1 - i], -1, p)",
"-print((a % p))",
"+print((sum(f[k - 1] * pow(f[i] * f[k - 1 - i], -1, p) for i in r(n - 1, k)) % p))"
] | false | 0.426228 | 0.135645 | 3.142241 | [
"s759867080",
"s058122089"
] |
u790012205 | p03805 | python | s746574429 | s279237252 | 212 | 25 | 42,716 | 3,064 | Accepted | Accepted | 88.21 | N, M = list(map(int, input().split()))
R = [[] for i in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
R[a - 1].append(b - 1)
R[b - 1].append(a - 1)
Parents = [[] for i in range(N)]
C = 0
def func(x, c):
global C
c += 1
last = True
for r in R[x]:
if r in Parents[x]:
continue
for i in range(len(Parents[x])):
Parents[r].append(Parents[x][i])
Parents[r].append(x)
last = False
func(r, c)
for i in range(len(Parents[x])):
Parents[r].remove(Parents[x][i])
Parents[r].remove(x)
if last:
if c == N:
C += 1
func(0, 0)
print(C) | import sys
sys.setrecursionlimit(10 ** 9)
N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]
for _ in range(M):
a, b = list(map(int, input().split()))
G[a - 1].append(b - 1)
G[b - 1].append(a - 1)
D = [0] * N
D[0] = 1
C = 0
def dfs(n):
global C
if not 0 in D:
C += 1
return
for i in G[n]:
if D[i] == 1:
continue
D[i] = 1
dfs(i)
D[i] = 0
dfs(0)
print(C) | 30 | 26 | 704 | 466 | N, M = list(map(int, input().split()))
R = [[] for i in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
R[a - 1].append(b - 1)
R[b - 1].append(a - 1)
Parents = [[] for i in range(N)]
C = 0
def func(x, c):
global C
c += 1
last = True
for r in R[x]:
if r in Parents[x]:
continue
for i in range(len(Parents[x])):
Parents[r].append(Parents[x][i])
Parents[r].append(x)
last = False
func(r, c)
for i in range(len(Parents[x])):
Parents[r].remove(Parents[x][i])
Parents[r].remove(x)
if last:
if c == N:
C += 1
func(0, 0)
print(C)
| import sys
sys.setrecursionlimit(10**9)
N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]
for _ in range(M):
a, b = list(map(int, input().split()))
G[a - 1].append(b - 1)
G[b - 1].append(a - 1)
D = [0] * N
D[0] = 1
C = 0
def dfs(n):
global C
if not 0 in D:
C += 1
return
for i in G[n]:
if D[i] == 1:
continue
D[i] = 1
dfs(i)
D[i] = 0
dfs(0)
print(C)
| false | 13.333333 | [
"+import sys",
"+",
"+sys.setrecursionlimit(10**9)",
"-R = [[] for i in range(N)]",
"-for i in range(M):",
"+G = [[] for _ in range(N)]",
"+for _ in range(M):",
"- R[a - 1].append(b - 1)",
"- R[b - 1].append(a - 1)",
"-Parents = [[] for i in range(N)]",
"+ G[a - 1].append(b - 1)",
"+ G[b - 1].append(a - 1)",
"+D = [0] * N",
"+D[0] = 1",
"-def func(x, c):",
"+def dfs(n):",
"- c += 1",
"- last = True",
"- for r in R[x]:",
"- if r in Parents[x]:",
"+ if not 0 in D:",
"+ C += 1",
"+ return",
"+ for i in G[n]:",
"+ if D[i] == 1:",
"- for i in range(len(Parents[x])):",
"- Parents[r].append(Parents[x][i])",
"- Parents[r].append(x)",
"- last = False",
"- func(r, c)",
"- for i in range(len(Parents[x])):",
"- Parents[r].remove(Parents[x][i])",
"- Parents[r].remove(x)",
"- if last:",
"- if c == N:",
"- C += 1",
"+ D[i] = 1",
"+ dfs(i)",
"+ D[i] = 0",
"-func(0, 0)",
"+dfs(0)"
] | false | 0.203761 | 0.074662 | 2.72911 | [
"s746574429",
"s279237252"
] |
u631277801 | p03472 | python | s477655142 | s619564256 | 350 | 217 | 17,400 | 11,600 | Accepted | Accepted | 38 | from itertools import accumulate
from bisect import bisect_left
from math import ceil
N,H = list(map(int, input().split()))
A = []
B = []
for _ in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
# 最も強いaを探す
a_max = max(A)
# それ以上のbを探す
b_strong = []
for b in B:
if b >= a_max:
b_strong.append(b)
# bをソートしてcum作る
b_strong.sort(reverse=True)
b_cum = list(accumulate(b_strong))
b_cum = [0] + b_cum
# もしHPがb_cum[-1]なら投げてるうちに倒せる
if H <= b_cum[-1]:
ans = bisect_left(b_cum, H)
else:
ans = len(b_cum) - 1
ans += ceil((H - b_cum[-1]) / a_max)
print(ans) | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
n,h = li()
alis = []
blis = []
for _ in range(n):
a,b = li()
alis.append(a)
blis.append(b)
amax = max(alis)
blis.sort()
buse = []
while blis:
cur = blis.pop()
if cur > amax:
buse.append(cur)
cnt = 0
res = h
for b in buse:
res -= b
cnt += 1
if res <= 0:
break
if res > 0:
cnt += -(-res//amax)
print(cnt) | 35 | 42 | 655 | 845 | from itertools import accumulate
from bisect import bisect_left
from math import ceil
N, H = list(map(int, input().split()))
A = []
B = []
for _ in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
# 最も強いaを探す
a_max = max(A)
# それ以上のbを探す
b_strong = []
for b in B:
if b >= a_max:
b_strong.append(b)
# bをソートしてcum作る
b_strong.sort(reverse=True)
b_cum = list(accumulate(b_strong))
b_cum = [0] + b_cum
# もしHPがb_cum[-1]なら投げてるうちに倒せる
if H <= b_cum[-1]:
ans = bisect_left(b_cum, H)
else:
ans = len(b_cum) - 1
ans += ceil((H - b_cum[-1]) / a_max)
print(ans)
| import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li():
return list(map(int, stdin.readline().split()))
def li_():
return [int(x) - 1 for x in stdin.readline().split()]
def lf():
return list(map(float, stdin.readline().split()))
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
n, h = li()
alis = []
blis = []
for _ in range(n):
a, b = li()
alis.append(a)
blis.append(b)
amax = max(alis)
blis.sort()
buse = []
while blis:
cur = blis.pop()
if cur > amax:
buse.append(cur)
cnt = 0
res = h
for b in buse:
res -= b
cnt += 1
if res <= 0:
break
if res > 0:
cnt += -(-res // amax)
print(cnt)
| false | 16.666667 | [
"-from itertools import accumulate",
"-from bisect import bisect_left",
"-from math import ceil",
"+import sys",
"-N, H = list(map(int, input().split()))",
"-A = []",
"-B = []",
"-for _ in range(N):",
"- a, b = list(map(int, input().split()))",
"- A.append(a)",
"- B.append(b)",
"-# 最も強いaを探す",
"-a_max = max(A)",
"-# それ以上のbを探す",
"-b_strong = []",
"-for b in B:",
"- if b >= a_max:",
"- b_strong.append(b)",
"-# bをソートしてcum作る",
"-b_strong.sort(reverse=True)",
"-b_cum = list(accumulate(b_strong))",
"-b_cum = [0] + b_cum",
"-# もしHPがb_cum[-1]なら投げてるうちに倒せる",
"-if H <= b_cum[-1]:",
"- ans = bisect_left(b_cum, H)",
"-else:",
"- ans = len(b_cum) - 1",
"- ans += ceil((H - b_cum[-1]) / a_max)",
"-print(ans)",
"+stdin = sys.stdin",
"+sys.setrecursionlimit(10**5)",
"+",
"+",
"+def li():",
"+ return list(map(int, stdin.readline().split()))",
"+",
"+",
"+def li_():",
"+ return [int(x) - 1 for x in stdin.readline().split()]",
"+",
"+",
"+def lf():",
"+ return list(map(float, stdin.readline().split()))",
"+",
"+",
"+def ls():",
"+ return stdin.readline().split()",
"+",
"+",
"+def ns():",
"+ return stdin.readline().rstrip()",
"+",
"+",
"+def lc():",
"+ return list(ns())",
"+",
"+",
"+def ni():",
"+ return int(stdin.readline())",
"+",
"+",
"+def nf():",
"+ return float(stdin.readline())",
"+",
"+",
"+n, h = li()",
"+alis = []",
"+blis = []",
"+for _ in range(n):",
"+ a, b = li()",
"+ alis.append(a)",
"+ blis.append(b)",
"+amax = max(alis)",
"+blis.sort()",
"+buse = []",
"+while blis:",
"+ cur = blis.pop()",
"+ if cur > amax:",
"+ buse.append(cur)",
"+cnt = 0",
"+res = h",
"+for b in buse:",
"+ res -= b",
"+ cnt += 1",
"+ if res <= 0:",
"+ break",
"+if res > 0:",
"+ cnt += -(-res // amax)",
"+print(cnt)"
] | false | 0.039656 | 0.046833 | 0.846755 | [
"s477655142",
"s619564256"
] |
u578953945 | p03386 | python | s757323011 | s157453529 | 180 | 162 | 38,384 | 38,256 | Accepted | Accepted | 10 | a,b,k=list(map(int,input().split()))
s=list(range(a,b+1))
for i in sorted(set(s[:k]) | set(s[-k:])):
print(i) | a,b,k=list(map(int,input().split()))
l=list(range(a,b+1))
la= set(l[:k]) | set(l[-k:])
for i in (sorted(la)):
print(i) | 4 | 5 | 104 | 112 | a, b, k = list(map(int, input().split()))
s = list(range(a, b + 1))
for i in sorted(set(s[:k]) | set(s[-k:])):
print(i)
| a, b, k = list(map(int, input().split()))
l = list(range(a, b + 1))
la = set(l[:k]) | set(l[-k:])
for i in sorted(la):
print(i)
| false | 20 | [
"-s = list(range(a, b + 1))",
"-for i in sorted(set(s[:k]) | set(s[-k:])):",
"+l = list(range(a, b + 1))",
"+la = set(l[:k]) | set(l[-k:])",
"+for i in sorted(la):"
] | false | 0.040727 | 0.044082 | 0.923901 | [
"s757323011",
"s157453529"
] |
u186838327 | p02887 | python | s361403871 | s604999777 | 50 | 41 | 3,316 | 3,316 | Accepted | Accepted | 18 | n = int(eval(input()))
s = str(eval(input()))
ans = 0
for i in range(n):
if i == 0:
ans += 1
else:
if s[i-1] == s[i]:
continue
else:
ans += 1
print(ans) | n = int(eval(input()))
s = str(eval(input()))
ans = 1
for i in range(1, n):
if s[i] != s[i-1]:
ans += 1
print(ans) | 13 | 8 | 181 | 122 | n = int(eval(input()))
s = str(eval(input()))
ans = 0
for i in range(n):
if i == 0:
ans += 1
else:
if s[i - 1] == s[i]:
continue
else:
ans += 1
print(ans)
| n = int(eval(input()))
s = str(eval(input()))
ans = 1
for i in range(1, n):
if s[i] != s[i - 1]:
ans += 1
print(ans)
| false | 38.461538 | [
"-ans = 0",
"-for i in range(n):",
"- if i == 0:",
"+ans = 1",
"+for i in range(1, n):",
"+ if s[i] != s[i - 1]:",
"- else:",
"- if s[i - 1] == s[i]:",
"- continue",
"- else:",
"- ans += 1"
] | false | 0.068215 | 0.064061 | 1.064847 | [
"s361403871",
"s604999777"
] |
u677523557 | p02851 | python | s827499356 | s325747354 | 573 | 470 | 59,496 | 166,780 | Accepted | Accepted | 17.98 | from bisect import bisect_right
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(N):
A[i] = (A[i]-1)%K
B = [0]
for a in A:
B.append((B[-1]+a)%K)
dic = {}
for i, b in enumerate(B):
if not b in list(dic.keys()):
dic[b] = [i]
else:
dic[b].append(i)
ans = 0
for L in list(dic.values()):
for i in range(len(L)):
#print(L, i)
j = bisect_right(L, L[i]+K-1)
#print(j)
ans += j-i-1
print(ans) | import sys
input = sys.stdin.readline
from collections import deque
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0]
for a in A:
b = (B[-1] + (a-1)) % K
B.append(b)
ans = 0
dic = {}
for i, b in enumerate(B):
if b in dic:
dic[b].append(i)
else:
dic[b] = deque()
dic[b].append(i)
while len(dic[b]) > 0 and dic[b][0] <= i - K:
dic[b].popleft()
ans += len(dic[b])-1
print(ans) | 27 | 27 | 505 | 496 | from bisect import bisect_right
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(N):
A[i] = (A[i] - 1) % K
B = [0]
for a in A:
B.append((B[-1] + a) % K)
dic = {}
for i, b in enumerate(B):
if not b in list(dic.keys()):
dic[b] = [i]
else:
dic[b].append(i)
ans = 0
for L in list(dic.values()):
for i in range(len(L)):
# print(L, i)
j = bisect_right(L, L[i] + K - 1)
# print(j)
ans += j - i - 1
print(ans)
| import sys
input = sys.stdin.readline
from collections import deque
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0]
for a in A:
b = (B[-1] + (a - 1)) % K
B.append(b)
ans = 0
dic = {}
for i, b in enumerate(B):
if b in dic:
dic[b].append(i)
else:
dic[b] = deque()
dic[b].append(i)
while len(dic[b]) > 0 and dic[b][0] <= i - K:
dic[b].popleft()
ans += len(dic[b]) - 1
print(ans)
| false | 0 | [
"-from bisect import bisect_right",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+from collections import deque",
"-for i in range(N):",
"- A[i] = (A[i] - 1) % K",
"- B.append((B[-1] + a) % K)",
"+ b = (B[-1] + (a - 1)) % K",
"+ B.append(b)",
"+ans = 0",
"- if not b in list(dic.keys()):",
"- dic[b] = [i]",
"+ if b in dic:",
"+ dic[b].append(i)",
"+ dic[b] = deque()",
"-ans = 0",
"-for L in list(dic.values()):",
"- for i in range(len(L)):",
"- # print(L, i)",
"- j = bisect_right(L, L[i] + K - 1)",
"- # print(j)",
"- ans += j - i - 1",
"+ while len(dic[b]) > 0 and dic[b][0] <= i - K:",
"+ dic[b].popleft()",
"+ ans += len(dic[b]) - 1"
] | false | 0.034646 | 0.035821 | 0.967211 | [
"s827499356",
"s325747354"
] |
u888092736 | p02796 | python | s139574180 | s405427146 | 310 | 223 | 32,100 | 25,876 | Accepted | Accepted | 28.06 | (N,), *XL = [list(map(int, s.split())) for s in open(0)]
XL.sort(key=lambda x: x[0] + x[1])
curr = -float("inf")
ans = 0
for x, l in XL:
if x - l >= curr:
curr = x + l
ans += 1
print(ans)
| N, *XL = list(map(int, open(0).read().split()))
XL = sorted((x + l, x - l) for x, l in zip(*[iter(XL)] * 2))
curr = -float("inf")
ans = 0
for right, left in XL:
if left >= curr:
curr = right
ans += 1
print(ans)
| 9 | 10 | 216 | 235 | (N,), *XL = [list(map(int, s.split())) for s in open(0)]
XL.sort(key=lambda x: x[0] + x[1])
curr = -float("inf")
ans = 0
for x, l in XL:
if x - l >= curr:
curr = x + l
ans += 1
print(ans)
| N, *XL = list(map(int, open(0).read().split()))
XL = sorted((x + l, x - l) for x, l in zip(*[iter(XL)] * 2))
curr = -float("inf")
ans = 0
for right, left in XL:
if left >= curr:
curr = right
ans += 1
print(ans)
| false | 10 | [
"-(N,), *XL = [list(map(int, s.split())) for s in open(0)]",
"-XL.sort(key=lambda x: x[0] + x[1])",
"+N, *XL = list(map(int, open(0).read().split()))",
"+XL = sorted((x + l, x - l) for x, l in zip(*[iter(XL)] * 2))",
"-for x, l in XL:",
"- if x - l >= curr:",
"- curr = x + l",
"+for right, left in XL:",
"+ if left >= curr:",
"+ curr = right"
] | false | 0.047815 | 0.048211 | 0.991791 | [
"s139574180",
"s405427146"
] |
u780342333 | p02382 | python | s013543645 | s308640097 | 30 | 20 | 7,820 | 5,668 | Accepted | Accepted | 33.33 | import math
n = int(eval(input()))
vector_x = [float(x) for x in input().split(" ")]
vector_y = [float(y) for y in input().split(" ")]
p1 = sum([abs(x - y) for x, y in zip(vector_x, vector_y)])
p2 = sum([abs(x - y) ** 2 for x, y in zip(vector_x, vector_y)]) ** (1/2)
p3 = sum([abs(x - y) ** 3 for x, y in zip(vector_x, vector_y)]) ** (1/3)
t = max([abs(x - y) for x, y in zip(vector_x, vector_y)])
print(("{:.6f}".format(p1)))
print(("{:.6f}".format(p2)))
print(("{:.6f}".format(p3)))
print(("{:.6f}".format(t))) | def get_minkowski_distance(a, b, p):
"""
get Minkowski's distance
a : int list
b : int list
p : int
"""
s = 0
res = 0.0
if p == 0:
l = []
for x, y in zip(a, b):
l.append(abs(x - y))
res = max(l)
else:
for x, y in zip(a, b):
s += abs(x - y) ** p
res = round((s ** (1/p)), 6)
return res
if __name__ == "__main__":
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print((get_minkowski_distance(a, b, 1)))
print((get_minkowski_distance(a, b, 2)))
print((get_minkowski_distance(a, b, 3)))
print((get_minkowski_distance(a, b, 0)))
| 15 | 34 | 515 | 734 | import math
n = int(eval(input()))
vector_x = [float(x) for x in input().split(" ")]
vector_y = [float(y) for y in input().split(" ")]
p1 = sum([abs(x - y) for x, y in zip(vector_x, vector_y)])
p2 = sum([abs(x - y) ** 2 for x, y in zip(vector_x, vector_y)]) ** (1 / 2)
p3 = sum([abs(x - y) ** 3 for x, y in zip(vector_x, vector_y)]) ** (1 / 3)
t = max([abs(x - y) for x, y in zip(vector_x, vector_y)])
print(("{:.6f}".format(p1)))
print(("{:.6f}".format(p2)))
print(("{:.6f}".format(p3)))
print(("{:.6f}".format(t)))
| def get_minkowski_distance(a, b, p):
"""
get Minkowski's distance
a : int list
b : int list
p : int
"""
s = 0
res = 0.0
if p == 0:
l = []
for x, y in zip(a, b):
l.append(abs(x - y))
res = max(l)
else:
for x, y in zip(a, b):
s += abs(x - y) ** p
res = round((s ** (1 / p)), 6)
return res
if __name__ == "__main__":
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print((get_minkowski_distance(a, b, 1)))
print((get_minkowski_distance(a, b, 2)))
print((get_minkowski_distance(a, b, 3)))
print((get_minkowski_distance(a, b, 0)))
| false | 55.882353 | [
"-import math",
"+def get_minkowski_distance(a, b, p):",
"+ \"\"\"",
"+ get Minkowski's distance",
"+ a : int list",
"+ b : int list",
"+ p : int",
"+ \"\"\"",
"+ s = 0",
"+ res = 0.0",
"+ if p == 0:",
"+ l = []",
"+ for x, y in zip(a, b):",
"+ l.append(abs(x - y))",
"+ res = max(l)",
"+ else:",
"+ for x, y in zip(a, b):",
"+ s += abs(x - y) ** p",
"+ res = round((s ** (1 / p)), 6)",
"+ return res",
"-n = int(eval(input()))",
"-vector_x = [float(x) for x in input().split(\" \")]",
"-vector_y = [float(y) for y in input().split(\" \")]",
"-p1 = sum([abs(x - y) for x, y in zip(vector_x, vector_y)])",
"-p2 = sum([abs(x - y) ** 2 for x, y in zip(vector_x, vector_y)]) ** (1 / 2)",
"-p3 = sum([abs(x - y) ** 3 for x, y in zip(vector_x, vector_y)]) ** (1 / 3)",
"-t = max([abs(x - y) for x, y in zip(vector_x, vector_y)])",
"-print((\"{:.6f}\".format(p1)))",
"-print((\"{:.6f}\".format(p2)))",
"-print((\"{:.6f}\".format(p3)))",
"-print((\"{:.6f}\".format(t)))",
"+",
"+if __name__ == \"__main__\":",
"+ n = int(eval(input()))",
"+ a = list(map(int, input().split()))",
"+ b = list(map(int, input().split()))",
"+ print((get_minkowski_distance(a, b, 1)))",
"+ print((get_minkowski_distance(a, b, 2)))",
"+ print((get_minkowski_distance(a, b, 3)))",
"+ print((get_minkowski_distance(a, b, 0)))"
] | false | 0.035019 | 0.007369 | 4.752347 | [
"s013543645",
"s308640097"
] |
u627803856 | p02773 | python | s736997484 | s500906671 | 1,062 | 771 | 120,784 | 45,788 | Accepted | Accepted | 27.4 | from collections import Counter
n=int(eval(input()))
s=[eval(input()) for i in range(n)]
c = Counter(s)
c2 = c.most_common()
m = c2[0][1]#最大値
ans = [i[0] for i in c2 if i[1] == m]#回数が最大となるもの
ans.sort()
print((*ans)) | n = int(eval(input()))
d = {}
for _ in range(n):
s = eval(input())
d[s] = d.get(s, 0) + 1
sorted_d = sorted(list(d.items()), key=lambda x:x[1], reverse=True)
ma = sorted_d[0][1]
res = []
for i in range(len(sorted_d)):
if sorted_d[i][1] == ma:
res.append(sorted_d[i][0])
res.sort()
for i in range(len(res)):
print((res[i])) | 11 | 19 | 213 | 349 | from collections import Counter
n = int(eval(input()))
s = [eval(input()) for i in range(n)]
c = Counter(s)
c2 = c.most_common()
m = c2[0][1] # 最大値
ans = [i[0] for i in c2 if i[1] == m] # 回数が最大となるもの
ans.sort()
print((*ans))
| n = int(eval(input()))
d = {}
for _ in range(n):
s = eval(input())
d[s] = d.get(s, 0) + 1
sorted_d = sorted(list(d.items()), key=lambda x: x[1], reverse=True)
ma = sorted_d[0][1]
res = []
for i in range(len(sorted_d)):
if sorted_d[i][1] == ma:
res.append(sorted_d[i][0])
res.sort()
for i in range(len(res)):
print((res[i]))
| false | 42.105263 | [
"-from collections import Counter",
"-",
"-s = [eval(input()) for i in range(n)]",
"-c = Counter(s)",
"-c2 = c.most_common()",
"-m = c2[0][1] # 最大値",
"-ans = [i[0] for i in c2 if i[1] == m] # 回数が最大となるもの",
"-ans.sort()",
"-print((*ans))",
"+d = {}",
"+for _ in range(n):",
"+ s = eval(input())",
"+ d[s] = d.get(s, 0) + 1",
"+sorted_d = sorted(list(d.items()), key=lambda x: x[1], reverse=True)",
"+ma = sorted_d[0][1]",
"+res = []",
"+for i in range(len(sorted_d)):",
"+ if sorted_d[i][1] == ma:",
"+ res.append(sorted_d[i][0])",
"+res.sort()",
"+for i in range(len(res)):",
"+ print((res[i]))"
] | false | 0.038458 | 0.081443 | 0.472205 | [
"s736997484",
"s500906671"
] |
u143509139 | p02847 | python | s231698578 | s474989028 | 180 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90.56 | s = eval(input())
print((['', 'SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN'].index(s))) | print((7-['SUN','MON','TUE','WED','THU','FRI','SAT'].index(eval(input())))) | 2 | 1 | 82 | 67 | s = eval(input())
print((["", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"].index(s)))
| print((7 - ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"].index(eval(input()))))
| false | 50 | [
"-s = eval(input())",
"-print(([\"\", \"SAT\", \"FRI\", \"THU\", \"WED\", \"TUE\", \"MON\", \"SUN\"].index(s)))",
"+print((7 - [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\"].index(eval(input()))))"
] | false | 0.048938 | 0.085804 | 0.570345 | [
"s231698578",
"s474989028"
] |
u498487134 | p02948 | python | s944807942 | s983330024 | 1,045 | 217 | 71,456 | 86,104 | Accepted | Accepted | 79.23 | #最終日から見る,残り日数条件を満たす中で最大収入のものを選ぶ
import heapq
N,M=list(map(int,input().split()))
AB=[[0,0] for _ in range(N)]
for i in range(N):
AB[i][0],AB[i][1] = list(map(int,input().split()))
AB.sort()
ans=0
q=[]
heapq.heapify(q)
ne=0
#dは残り日数
for d in range(1,M+1):
for i in range(ne,N):
if AB[i][0]<=d:
heapq.heappush(q,AB[i][1]*-1)
ne=i+1
else:
break
if len(q)!=0:
a=heapq.heappop(q)
ans-=a
print(ans) | import sys
input = sys.stdin.readline
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
import heapq
mod=10**9+7
N,M=MI()
L=[[]for _ in range(M)]
for i in range(N):
#何日までに受ける必要があるかを気にしながら持つ
a,b=MI()
if a<=M:
L[M-a].append(-b)
ans=0
hq=[]
heapq.heapify(hq)
for i in range(M-1,-1,-1):
for bb in L[i]:
heapq.heappush(hq,bb)
if len(hq)!=0:
temp=heapq.heappop(hq)
ans+=-1*temp
print(ans)
main()
| 29 | 35 | 496 | 692 | # 最終日から見る,残り日数条件を満たす中で最大収入のものを選ぶ
import heapq
N, M = list(map(int, input().split()))
AB = [[0, 0] for _ in range(N)]
for i in range(N):
AB[i][0], AB[i][1] = list(map(int, input().split()))
AB.sort()
ans = 0
q = []
heapq.heapify(q)
ne = 0
# dは残り日数
for d in range(1, M + 1):
for i in range(ne, N):
if AB[i][0] <= d:
heapq.heappush(q, AB[i][1] * -1)
ne = i + 1
else:
break
if len(q) != 0:
a = heapq.heappop(q)
ans -= a
print(ans)
| import sys
input = sys.stdin.readline
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def main():
import heapq
mod = 10**9 + 7
N, M = MI()
L = [[] for _ in range(M)]
for i in range(N):
# 何日までに受ける必要があるかを気にしながら持つ
a, b = MI()
if a <= M:
L[M - a].append(-b)
ans = 0
hq = []
heapq.heapify(hq)
for i in range(M - 1, -1, -1):
for bb in L[i]:
heapq.heappush(hq, bb)
if len(hq) != 0:
temp = heapq.heappop(hq)
ans += -1 * temp
print(ans)
main()
| false | 17.142857 | [
"-# 最終日から見る,残り日数条件を満たす中で最大収入のものを選ぶ",
"-import heapq",
"+import sys",
"-N, M = list(map(int, input().split()))",
"-AB = [[0, 0] for _ in range(N)]",
"-for i in range(N):",
"- AB[i][0], AB[i][1] = list(map(int, input().split()))",
"-AB.sort()",
"-ans = 0",
"-q = []",
"-heapq.heapify(q)",
"-ne = 0",
"-# dは残り日数",
"-for d in range(1, M + 1):",
"- for i in range(ne, N):",
"- if AB[i][0] <= d:",
"- heapq.heappush(q, AB[i][1] * -1)",
"- ne = i + 1",
"- else:",
"- break",
"- if len(q) != 0:",
"- a = heapq.heappop(q)",
"- ans -= a",
"-print(ans)",
"+input = sys.stdin.readline",
"+",
"+",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def main():",
"+ import heapq",
"+",
"+ mod = 10**9 + 7",
"+ N, M = MI()",
"+ L = [[] for _ in range(M)]",
"+ for i in range(N):",
"+ # 何日までに受ける必要があるかを気にしながら持つ",
"+ a, b = MI()",
"+ if a <= M:",
"+ L[M - a].append(-b)",
"+ ans = 0",
"+ hq = []",
"+ heapq.heapify(hq)",
"+ for i in range(M - 1, -1, -1):",
"+ for bb in L[i]:",
"+ heapq.heappush(hq, bb)",
"+ if len(hq) != 0:",
"+ temp = heapq.heappop(hq)",
"+ ans += -1 * temp",
"+ print(ans)",
"+",
"+",
"+main()"
] | false | 0.034991 | 0.037064 | 0.944056 | [
"s944807942",
"s983330024"
] |
u396495667 | p03852 | python | s169612949 | s547550854 | 169 | 17 | 38,256 | 2,940 | Accepted | Accepted | 89.94 | c = eval(input())
list = ['a','i','u','e','o']
if c in list:
print('vowel')
else:
print('consonant') | s = eval(input())
a = {'a','i','u','e','o'}
if s in a:
print('vowel')
else:
print('consonant') | 8 | 7 | 107 | 99 | c = eval(input())
list = ["a", "i", "u", "e", "o"]
if c in list:
print("vowel")
else:
print("consonant")
| s = eval(input())
a = {"a", "i", "u", "e", "o"}
if s in a:
print("vowel")
else:
print("consonant")
| false | 12.5 | [
"-c = eval(input())",
"-list = [\"a\", \"i\", \"u\", \"e\", \"o\"]",
"-if c in list:",
"+s = eval(input())",
"+a = {\"a\", \"i\", \"u\", \"e\", \"o\"}",
"+if s in a:"
] | false | 0.042895 | 0.040387 | 1.062084 | [
"s169612949",
"s547550854"
] |
u972591645 | p02579 | python | s614562886 | s281623185 | 1,903 | 1,607 | 23,668 | 23,476 | Accepted | Accepted | 15.55 | from collections import deque
def main():
h, w = list(map(int, input().split()))
start_h, start_w = [int(x)+1 for x in input().split()]
goal_h, goal_w = [int(x)+1 for x in input().split()]
s = ["#"*(w+4)]
s.append("#"*(w+4))
for _ in range(h):
s.append("##" + eval(input()) + "##")
s.append("#"*(w+4))
s.append("#"*(w+4))
ans = [[-1]*(w+4) for _ in range(h+4)]
for i in range(h+4):
for j in range(w+4):
if s[i][j] == "#":
ans[i][j] = -2
ans[start_h][start_w] = 0
move1 = [(-1, 0), (1, 0), (0, -1), (0, 1)]
move2 = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2),(-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),(0, -2), (0, -1), (0, 0), (0, 1), (0, 2),(1, -2), (1, -1), (1, 0), (1, 1), (1, 2),(2, -2), (2, -1), (2, 0), (2, 1), (2, 2)]
yet = deque([(start_h, start_w)])
done = deque()
while yet:
x1, y1 = yet.popleft()
done.append((x1, y1))
for (p, q) in move1:
v1, v2 = x1+p, y1+q
if ans[v1][v2] == -1: #"."でまだ辿り着いていないマス
yet.append((v1, v2))
ans[v1][v2] = ans[x1][y1]
if len(yet) == 0:
while done:
x2, y2 = done.popleft()
for (p, q) in move2:
i, j = x2+p, y2+q
if ans[i][j] == -1:
ans[i][j] = ans[x2][y2]+1
yet.append((i, j))
print((ans[goal_h][goal_w]))
if __name__ == "__main__":
main()
| from collections import deque
def main():
h, w = list(map(int, input().split()))
c = list([int(x)+1 for x in input().split()])
d = list([int(x)+1 for x in input().split()])
s = ['#'*(w+4)]*2 + ['#'*2 + eval(input()) + '#'*2 for _ in range(h)] + ['#'*(w+4)]*2
ans = [[-1]*(w+4) for _ in range(h+4)]
for i in range(h+4):
for j in range(w+4):
if s[i][j] == '#':
ans[i][j] = -2
ans[c[0]][c[1]] = 0
move1 = [(0, 1), (0, -1), (1, 0), (-1, 0)]
move2 = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if abs(i)+abs(j) > 1]
yet = deque([(c[0], c[1])])
done = deque()
while yet:
y, x = yet.popleft()
done.append((y, x))
for dy, dx in move1:
ydy, xdx = y+dy, x+dx
if ans[ydy][xdx] == -1:
yet.append((ydy, xdx))
ans[ydy][xdx] = ans[y][x]
if len(yet) == 0:
while done:
y, x = done.popleft()
for dy, dx in move2:
ydy, xdx = y+dy, x+dx
if ans[ydy][xdx] == -1:
ans[ydy][xdx] = ans[y][x] + 1
yet.append((ydy, xdx))
print((ans[d[0]][d[1]]))
if __name__ == '__main__':
main()
| 49 | 43 | 1,574 | 1,319 | from collections import deque
def main():
h, w = list(map(int, input().split()))
start_h, start_w = [int(x) + 1 for x in input().split()]
goal_h, goal_w = [int(x) + 1 for x in input().split()]
s = ["#" * (w + 4)]
s.append("#" * (w + 4))
for _ in range(h):
s.append("##" + eval(input()) + "##")
s.append("#" * (w + 4))
s.append("#" * (w + 4))
ans = [[-1] * (w + 4) for _ in range(h + 4)]
for i in range(h + 4):
for j in range(w + 4):
if s[i][j] == "#":
ans[i][j] = -2
ans[start_h][start_w] = 0
move1 = [(-1, 0), (1, 0), (0, -1), (0, 1)]
move2 = [
(-2, -2),
(-2, -1),
(-2, 0),
(-2, 1),
(-2, 2),
(-1, -2),
(-1, -1),
(-1, 0),
(-1, 1),
(-1, 2),
(0, -2),
(0, -1),
(0, 0),
(0, 1),
(0, 2),
(1, -2),
(1, -1),
(1, 0),
(1, 1),
(1, 2),
(2, -2),
(2, -1),
(2, 0),
(2, 1),
(2, 2),
]
yet = deque([(start_h, start_w)])
done = deque()
while yet:
x1, y1 = yet.popleft()
done.append((x1, y1))
for (p, q) in move1:
v1, v2 = x1 + p, y1 + q
if ans[v1][v2] == -1: # "."でまだ辿り着いていないマス
yet.append((v1, v2))
ans[v1][v2] = ans[x1][y1]
if len(yet) == 0:
while done:
x2, y2 = done.popleft()
for (p, q) in move2:
i, j = x2 + p, y2 + q
if ans[i][j] == -1:
ans[i][j] = ans[x2][y2] + 1
yet.append((i, j))
print((ans[goal_h][goal_w]))
if __name__ == "__main__":
main()
| from collections import deque
def main():
h, w = list(map(int, input().split()))
c = list([int(x) + 1 for x in input().split()])
d = list([int(x) + 1 for x in input().split()])
s = (
["#" * (w + 4)] * 2
+ ["#" * 2 + eval(input()) + "#" * 2 for _ in range(h)]
+ ["#" * (w + 4)] * 2
)
ans = [[-1] * (w + 4) for _ in range(h + 4)]
for i in range(h + 4):
for j in range(w + 4):
if s[i][j] == "#":
ans[i][j] = -2
ans[c[0]][c[1]] = 0
move1 = [(0, 1), (0, -1), (1, 0), (-1, 0)]
move2 = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if abs(i) + abs(j) > 1]
yet = deque([(c[0], c[1])])
done = deque()
while yet:
y, x = yet.popleft()
done.append((y, x))
for dy, dx in move1:
ydy, xdx = y + dy, x + dx
if ans[ydy][xdx] == -1:
yet.append((ydy, xdx))
ans[ydy][xdx] = ans[y][x]
if len(yet) == 0:
while done:
y, x = done.popleft()
for dy, dx in move2:
ydy, xdx = y + dy, x + dx
if ans[ydy][xdx] == -1:
ans[ydy][xdx] = ans[y][x] + 1
yet.append((ydy, xdx))
print((ans[d[0]][d[1]]))
if __name__ == "__main__":
main()
| false | 12.244898 | [
"- start_h, start_w = [int(x) + 1 for x in input().split()]",
"- goal_h, goal_w = [int(x) + 1 for x in input().split()]",
"- s = [\"#\" * (w + 4)]",
"- s.append(\"#\" * (w + 4))",
"- for _ in range(h):",
"- s.append(\"##\" + eval(input()) + \"##\")",
"- s.append(\"#\" * (w + 4))",
"- s.append(\"#\" * (w + 4))",
"+ c = list([int(x) + 1 for x in input().split()])",
"+ d = list([int(x) + 1 for x in input().split()])",
"+ s = (",
"+ [\"#\" * (w + 4)] * 2",
"+ + [\"#\" * 2 + eval(input()) + \"#\" * 2 for _ in range(h)]",
"+ + [\"#\" * (w + 4)] * 2",
"+ )",
"- ans[start_h][start_w] = 0",
"- move1 = [(-1, 0), (1, 0), (0, -1), (0, 1)]",
"- move2 = [",
"- (-2, -2),",
"- (-2, -1),",
"- (-2, 0),",
"- (-2, 1),",
"- (-2, 2),",
"- (-1, -2),",
"- (-1, -1),",
"- (-1, 0),",
"- (-1, 1),",
"- (-1, 2),",
"- (0, -2),",
"- (0, -1),",
"- (0, 0),",
"- (0, 1),",
"- (0, 2),",
"- (1, -2),",
"- (1, -1),",
"- (1, 0),",
"- (1, 1),",
"- (1, 2),",
"- (2, -2),",
"- (2, -1),",
"- (2, 0),",
"- (2, 1),",
"- (2, 2),",
"- ]",
"- yet = deque([(start_h, start_w)])",
"+ ans[c[0]][c[1]] = 0",
"+ move1 = [(0, 1), (0, -1), (1, 0), (-1, 0)]",
"+ move2 = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if abs(i) + abs(j) > 1]",
"+ yet = deque([(c[0], c[1])])",
"- x1, y1 = yet.popleft()",
"- done.append((x1, y1))",
"- for (p, q) in move1:",
"- v1, v2 = x1 + p, y1 + q",
"- if ans[v1][v2] == -1: # \".\"でまだ辿り着いていないマス",
"- yet.append((v1, v2))",
"- ans[v1][v2] = ans[x1][y1]",
"+ y, x = yet.popleft()",
"+ done.append((y, x))",
"+ for dy, dx in move1:",
"+ ydy, xdx = y + dy, x + dx",
"+ if ans[ydy][xdx] == -1:",
"+ yet.append((ydy, xdx))",
"+ ans[ydy][xdx] = ans[y][x]",
"- x2, y2 = done.popleft()",
"- for (p, q) in move2:",
"- i, j = x2 + p, y2 + q",
"- if ans[i][j] == -1:",
"- ans[i][j] = ans[x2][y2] + 1",
"- yet.append((i, j))",
"- print((ans[goal_h][goal_w]))",
"+ y, x = done.popleft()",
"+ for dy, dx in move2:",
"+ ydy, xdx = y + dy, x + dx",
"+ if ans[ydy][xdx] == -1:",
"+ ans[ydy][xdx] = ans[y][x] + 1",
"+ yet.append((ydy, xdx))",
"+ print((ans[d[0]][d[1]]))"
] | false | 0.033997 | 0.034951 | 0.972728 | [
"s614562886",
"s281623185"
] |
u892797057 | p02571 | python | s897299424 | s133660902 | 190 | 68 | 9,104 | 9,088 | Accepted | Accepted | 64.21 | S = eval(input())
T = eval(input())
min_count = len(T)
for s_i in range(len(S)):
i = s_i
matched = 0
for j in range(len(T)):
if len(S) <= i: # Out of S
matched = 0 # Cannot append characters to S
break
if S[i] == T[j]:
matched += 1
i += 1
count = len(T) - matched
if count < min_count:
min_count = count
print(min_count) | S = eval(input())
T = eval(input())
min_count = len(T)
for s in range(len(S) - len(T) + 1): # T cannot exceed the length of S
matched = 0
for i in range(len(T)):
# print(f'S[{s + i}] == T[{i}]')
if S[s + i] == T[i]:
matched += 1
count = len(T) - matched
if count < min_count:
min_count = count
print(min_count) | 18 | 14 | 416 | 365 | S = eval(input())
T = eval(input())
min_count = len(T)
for s_i in range(len(S)):
i = s_i
matched = 0
for j in range(len(T)):
if len(S) <= i: # Out of S
matched = 0 # Cannot append characters to S
break
if S[i] == T[j]:
matched += 1
i += 1
count = len(T) - matched
if count < min_count:
min_count = count
print(min_count)
| S = eval(input())
T = eval(input())
min_count = len(T)
for s in range(len(S) - len(T) + 1): # T cannot exceed the length of S
matched = 0
for i in range(len(T)):
# print(f'S[{s + i}] == T[{i}]')
if S[s + i] == T[i]:
matched += 1
count = len(T) - matched
if count < min_count:
min_count = count
print(min_count)
| false | 22.222222 | [
"-for s_i in range(len(S)):",
"- i = s_i",
"+for s in range(len(S) - len(T) + 1): # T cannot exceed the length of S",
"- for j in range(len(T)):",
"- if len(S) <= i: # Out of S",
"- matched = 0 # Cannot append characters to S",
"- break",
"- if S[i] == T[j]:",
"+ for i in range(len(T)):",
"+ # print(f'S[{s + i}] == T[{i}]')",
"+ if S[s + i] == T[i]:",
"- i += 1"
] | false | 0.034672 | 0.072927 | 0.475432 | [
"s897299424",
"s133660902"
] |
u947883560 | p02644 | python | s267475989 | s782687711 | 341 | 306 | 163,756 | 156,184 | Accepted | Accepted | 10.26 | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]
INF = float("inf")
MOD = 10**9 + 7
EPS = 1e-6
KETA = 10**7
def main():
H, W, K = MAP()
x1, y1, x2, y2 = LIST()
c = [[-1] + [0 if c == "." else -1 for c in eval(input())] + [-1]
for i in range(H)]
c = [[-1] * (W + 2)] + c + [[-1] * (W + 2)]
c[x1][y1] = 0
# 0123: 上下左右
stack = [((x1 * KETA + y1) << 2) + 0, ((x1 * KETA + y1) << 2) + 1,
((x1 * KETA + y1) << 2) + 2, ((x1 * KETA + y1) << 2) + 3]
DX = (1, 0, -1, 0)
DY = (0, 1, 0, -1)
head = 0
while head < len(stack):
b = stack[head]
head += 1
d = b % 4
x, y = divmod(b >> 2, KETA)
flag = True
a = c[x][y] + 1
for k in range(1, K + 1):
xx, yy = x + k * DX[d], y + k * DY[d]
if c[xx][yy] == 0:
stack.append(((xx * KETA + yy) << 2) + (d - 1) % 4)
stack.append(((xx * KETA + yy) << 2) + (d + 1) % 4)
c[xx][yy] = a
elif c[xx][yy] != a:
flag = False
break
if flag:
stack.append(((xx * KETA + yy) << 2) + d)
if c[x2][y2] > 0:
print((c[x2][y2]))
return
print((-1))
return
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from collections import deque
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]
INF = float("inf")
MOD = 10**9 + 7
EPS = 1e-6
KETA = 10**7
def main():
H, W, K = MAP()
x1, y1, x2, y2 = LIST()
c = [[-1] + [0 if c == "." else -1 for c in eval(input())] + [-1]
for i in range(H)]
c = [[-1] * (W + 2)] + c + [[-1] * (W + 2)]
c[x1][y1] = 0
# 0123: 上下左右
stack = deque([((x1 * KETA + y1) << 2) + 0, ((x1 * KETA + y1) << 2) + 1,
((x1 * KETA + y1) << 2) + 2, ((x1 * KETA + y1) << 2) + 3])
DX = (1, 0, -1, 0)
DY = (0, 1, 0, -1)
head = 0
while stack:
b = stack.popleft()
head += 1
d = b % 4
x, y = divmod(b >> 2, KETA)
flag = True
a = c[x][y] + 1
for k in range(1, K + 1):
xx, yy = x + k * DX[d], y + k * DY[d]
if c[xx][yy] == 0:
stack.append(((xx * KETA + yy) << 2) + (d - 1) % 4)
stack.append(((xx * KETA + yy) << 2) + (d + 1) % 4)
c[xx][yy] = a
elif c[xx][yy] != a:
flag = False
break
if flag:
stack.append(((xx * KETA + yy) << 2) + d)
if c[x2][y2] > 0:
print((c[x2][y2]))
return
print((-1))
return
if __name__ == '__main__':
main()
| 58 | 59 | 1,586 | 1,622 | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return [LIST() for _ in range(n)]
INF = float("inf")
MOD = 10**9 + 7
EPS = 1e-6
KETA = 10**7
def main():
H, W, K = MAP()
x1, y1, x2, y2 = LIST()
c = [[-1] + [0 if c == "." else -1 for c in eval(input())] + [-1] for i in range(H)]
c = [[-1] * (W + 2)] + c + [[-1] * (W + 2)]
c[x1][y1] = 0
# 0123: 上下左右
stack = [
((x1 * KETA + y1) << 2) + 0,
((x1 * KETA + y1) << 2) + 1,
((x1 * KETA + y1) << 2) + 2,
((x1 * KETA + y1) << 2) + 3,
]
DX = (1, 0, -1, 0)
DY = (0, 1, 0, -1)
head = 0
while head < len(stack):
b = stack[head]
head += 1
d = b % 4
x, y = divmod(b >> 2, KETA)
flag = True
a = c[x][y] + 1
for k in range(1, K + 1):
xx, yy = x + k * DX[d], y + k * DY[d]
if c[xx][yy] == 0:
stack.append(((xx * KETA + yy) << 2) + (d - 1) % 4)
stack.append(((xx * KETA + yy) << 2) + (d + 1) % 4)
c[xx][yy] = a
elif c[xx][yy] != a:
flag = False
break
if flag:
stack.append(((xx * KETA + yy) << 2) + d)
if c[x2][y2] > 0:
print((c[x2][y2]))
return
print((-1))
return
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from collections import deque
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return [LIST() for _ in range(n)]
INF = float("inf")
MOD = 10**9 + 7
EPS = 1e-6
KETA = 10**7
def main():
H, W, K = MAP()
x1, y1, x2, y2 = LIST()
c = [[-1] + [0 if c == "." else -1 for c in eval(input())] + [-1] for i in range(H)]
c = [[-1] * (W + 2)] + c + [[-1] * (W + 2)]
c[x1][y1] = 0
# 0123: 上下左右
stack = deque(
[
((x1 * KETA + y1) << 2) + 0,
((x1 * KETA + y1) << 2) + 1,
((x1 * KETA + y1) << 2) + 2,
((x1 * KETA + y1) << 2) + 3,
]
)
DX = (1, 0, -1, 0)
DY = (0, 1, 0, -1)
head = 0
while stack:
b = stack.popleft()
head += 1
d = b % 4
x, y = divmod(b >> 2, KETA)
flag = True
a = c[x][y] + 1
for k in range(1, K + 1):
xx, yy = x + k * DX[d], y + k * DY[d]
if c[xx][yy] == 0:
stack.append(((xx * KETA + yy) << 2) + (d - 1) % 4)
stack.append(((xx * KETA + yy) << 2) + (d + 1) % 4)
c[xx][yy] = a
elif c[xx][yy] != a:
flag = False
break
if flag:
stack.append(((xx * KETA + yy) << 2) + d)
if c[x2][y2] > 0:
print((c[x2][y2]))
return
print((-1))
return
if __name__ == "__main__":
main()
| false | 1.694915 | [
"+from collections import deque",
"- stack = [",
"- ((x1 * KETA + y1) << 2) + 0,",
"- ((x1 * KETA + y1) << 2) + 1,",
"- ((x1 * KETA + y1) << 2) + 2,",
"- ((x1 * KETA + y1) << 2) + 3,",
"- ]",
"+ stack = deque(",
"+ [",
"+ ((x1 * KETA + y1) << 2) + 0,",
"+ ((x1 * KETA + y1) << 2) + 1,",
"+ ((x1 * KETA + y1) << 2) + 2,",
"+ ((x1 * KETA + y1) << 2) + 3,",
"+ ]",
"+ )",
"- while head < len(stack):",
"- b = stack[head]",
"+ while stack:",
"+ b = stack.popleft()"
] | false | 0.048289 | 0.048695 | 0.991676 | [
"s267475989",
"s782687711"
] |
u985929170 | p03478 | python | s424730056 | s375478967 | 44 | 37 | 9,216 | 8,996 | Accepted | Accepted | 15.91 | N,A,B = list(map(int,input().split()))
l = list(range(1,N+1))
su = 0
for i in l:
num_li = (list(str(i)))
num_li = list(map(int,num_li))
k = sum(num_li)
if A <= k <= B:su+=i
print(su) | n,a,b = list(map(int,input().split()))
ans = 0
for i in range(1,n+1):
l = sum(map(int,list(str(i))))
if a<=l<=b:
ans += i
print(ans) | 9 | 7 | 200 | 148 | N, A, B = list(map(int, input().split()))
l = list(range(1, N + 1))
su = 0
for i in l:
num_li = list(str(i))
num_li = list(map(int, num_li))
k = sum(num_li)
if A <= k <= B:
su += i
print(su)
| n, a, b = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
l = sum(map(int, list(str(i))))
if a <= l <= b:
ans += i
print(ans)
| false | 22.222222 | [
"-N, A, B = list(map(int, input().split()))",
"-l = list(range(1, N + 1))",
"-su = 0",
"-for i in l:",
"- num_li = list(str(i))",
"- num_li = list(map(int, num_li))",
"- k = sum(num_li)",
"- if A <= k <= B:",
"- su += i",
"-print(su)",
"+n, a, b = list(map(int, input().split()))",
"+ans = 0",
"+for i in range(1, n + 1):",
"+ l = sum(map(int, list(str(i))))",
"+ if a <= l <= b:",
"+ ans += i",
"+print(ans)"
] | false | 0.043703 | 0.109884 | 0.397719 | [
"s424730056",
"s375478967"
] |
u319589470 | p03854 | python | s251383896 | s837871476 | 73 | 19 | 3,316 | 3,188 | Accepted | Accepted | 73.97 | s_1 = eval(input())
s = s_1[::-1]
while len(s) >= 0:
if s[0:5] == "maerd":
s = s[5:len(s)]
continue
elif s[0:7] == "remaerd":
s = s[7:len(s)]
continue
elif s[0:5] == "esare":
s = s[5:len(s)]
continue
elif s[0:6] == "resare":
s = s[6:len(s)]
continue
elif s == "":
print("YES")
break
else:
print("NO")
break | s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if len(s)>0:
print("NO")
else:
print("YES") | 21 | 5 | 380 | 144 | s_1 = eval(input())
s = s_1[::-1]
while len(s) >= 0:
if s[0:5] == "maerd":
s = s[5 : len(s)]
continue
elif s[0:7] == "remaerd":
s = s[7 : len(s)]
continue
elif s[0:5] == "esare":
s = s[5 : len(s)]
continue
elif s[0:6] == "resare":
s = s[6 : len(s)]
continue
elif s == "":
print("YES")
break
else:
print("NO")
break
| s = (
input()
.replace("eraser", "")
.replace("erase", "")
.replace("dreamer", "")
.replace("dream", "")
)
if len(s) > 0:
print("NO")
else:
print("YES")
| false | 76.190476 | [
"-s_1 = eval(input())",
"-s = s_1[::-1]",
"-while len(s) >= 0:",
"- if s[0:5] == \"maerd\":",
"- s = s[5 : len(s)]",
"- continue",
"- elif s[0:7] == \"remaerd\":",
"- s = s[7 : len(s)]",
"- continue",
"- elif s[0:5] == \"esare\":",
"- s = s[5 : len(s)]",
"- continue",
"- elif s[0:6] == \"resare\":",
"- s = s[6 : len(s)]",
"- continue",
"- elif s == \"\":",
"- print(\"YES\")",
"- break",
"- else:",
"- print(\"NO\")",
"- break",
"+s = (",
"+ input()",
"+ .replace(\"eraser\", \"\")",
"+ .replace(\"erase\", \"\")",
"+ .replace(\"dreamer\", \"\")",
"+ .replace(\"dream\", \"\")",
"+)",
"+if len(s) > 0:",
"+ print(\"NO\")",
"+else:",
"+ print(\"YES\")"
] | false | 0.034657 | 0.036419 | 0.951609 | [
"s251383896",
"s837871476"
] |
u569960318 | p02270 | python | s588474655 | s591049217 | 650 | 530 | 17,840 | 17,876 | Accepted | Accepted | 18.46 | def checkCapacity(W,k,P):
ws = 0
cnt = 1
for wi in W:
if wi > P: return False
ws += wi
if ws > P:
cnt += 1
ws = wi
if cnt > k: return False
return True
if __name__=='__main__':
n,k = list(map(int, input().split()))
W = list(map(int,[eval(input()) for _ in range(n)]))
Pmax = sum(W)
Pmin = 0
while Pmin < Pmax:
P = (Pmax + Pmin) // 2
if checkCapacity(W,k,P):
Pmax = P
else:
Pmin = P + 1
print(Pmax) | def checkCapacity(W,k,P):
ws = 0
cnt = 1
for wi in W:
ws += wi
if ws > P:
cnt += 1
ws = wi
if cnt > k: return False
return True
if __name__=='__main__':
n,k = list(map(int, input().split()))
W = list(map(int,[eval(input()) for _ in range(n)]))
Pmax = sum(W)
Pmin = max(W)
while Pmin < Pmax:
P = (Pmax + Pmin) // 2
if checkCapacity(W,k,P):
Pmax = P
else:
Pmin = P + 1
print(Pmax) | 24 | 23 | 559 | 531 | def checkCapacity(W, k, P):
ws = 0
cnt = 1
for wi in W:
if wi > P:
return False
ws += wi
if ws > P:
cnt += 1
ws = wi
if cnt > k:
return False
return True
if __name__ == "__main__":
n, k = list(map(int, input().split()))
W = list(map(int, [eval(input()) for _ in range(n)]))
Pmax = sum(W)
Pmin = 0
while Pmin < Pmax:
P = (Pmax + Pmin) // 2
if checkCapacity(W, k, P):
Pmax = P
else:
Pmin = P + 1
print(Pmax)
| def checkCapacity(W, k, P):
ws = 0
cnt = 1
for wi in W:
ws += wi
if ws > P:
cnt += 1
ws = wi
if cnt > k:
return False
return True
if __name__ == "__main__":
n, k = list(map(int, input().split()))
W = list(map(int, [eval(input()) for _ in range(n)]))
Pmax = sum(W)
Pmin = max(W)
while Pmin < Pmax:
P = (Pmax + Pmin) // 2
if checkCapacity(W, k, P):
Pmax = P
else:
Pmin = P + 1
print(Pmax)
| false | 4.166667 | [
"- if wi > P:",
"- return False",
"- Pmin = 0",
"+ Pmin = max(W)"
] | false | 0.046366 | 0.045515 | 1.0187 | [
"s588474655",
"s591049217"
] |
u445404615 | p02577 | python | s465991218 | s281255579 | 728 | 68 | 10,620 | 9,256 | Accepted | Accepted | 90.66 | n=int(eval(input()))
l=list(str(n))
wrk=0
for i in l:
wrk+=int(i)
if wrk % 9 == 0:
print('Yes')
else:
print('No') | n=eval(input())
wrk=0
for i in n:
wrk+=int(i)
if wrk % 9 == 0:
print('Yes')
else:
print('No') | 11 | 10 | 131 | 110 | n = int(eval(input()))
l = list(str(n))
wrk = 0
for i in l:
wrk += int(i)
if wrk % 9 == 0:
print("Yes")
else:
print("No")
| n = eval(input())
wrk = 0
for i in n:
wrk += int(i)
if wrk % 9 == 0:
print("Yes")
else:
print("No")
| false | 9.090909 | [
"-n = int(eval(input()))",
"-l = list(str(n))",
"+n = eval(input())",
"-for i in l:",
"+for i in n:"
] | false | 0.067462 | 0.08651 | 0.779816 | [
"s465991218",
"s281255579"
] |
u893063840 | p02837 | python | s685874201 | s685304269 | 732 | 603 | 3,064 | 3,064 | Accepted | Accepted | 17.62 | from itertools import product
n = int(eval(input()))
a = []
xy = []
for _ in range(n):
a_tmp = int(eval(input()))
a.append(a_tmp)
xy_tmp = []
for _ in range(a_tmp):
xy_tmp.append(list(map(int, input().split())))
xy.append(xy_tmp)
ans = 0
for pat in product([1, 0], repeat=n):
sat = True
for i, bl in enumerate(pat):
if bl:
for x, y in xy[i]:
x -= 1
if pat[x] != y:
sat = False
if sat:
cnt = sum(pat)
ans = max(ans, cnt)
print(ans)
| from itertools import product
n = int(eval(input()))
a = []
xy = []
for _ in range(n):
ea = int(eval(input()))
new = []
for _ in range(ea):
x, y = list(map(int, input().split()))
x -= 1
new.append([x, y])
xy.append(new)
ans = 0
for pat in product([1, 0], repeat=n):
bl = True
for i, e in enumerate(pat):
if e:
for x, y in xy[i]:
if pat[x] != y:
bl = False
if bl:
ans = max(ans, sum(pat))
print(ans)
| 30 | 29 | 582 | 531 | from itertools import product
n = int(eval(input()))
a = []
xy = []
for _ in range(n):
a_tmp = int(eval(input()))
a.append(a_tmp)
xy_tmp = []
for _ in range(a_tmp):
xy_tmp.append(list(map(int, input().split())))
xy.append(xy_tmp)
ans = 0
for pat in product([1, 0], repeat=n):
sat = True
for i, bl in enumerate(pat):
if bl:
for x, y in xy[i]:
x -= 1
if pat[x] != y:
sat = False
if sat:
cnt = sum(pat)
ans = max(ans, cnt)
print(ans)
| from itertools import product
n = int(eval(input()))
a = []
xy = []
for _ in range(n):
ea = int(eval(input()))
new = []
for _ in range(ea):
x, y = list(map(int, input().split()))
x -= 1
new.append([x, y])
xy.append(new)
ans = 0
for pat in product([1, 0], repeat=n):
bl = True
for i, e in enumerate(pat):
if e:
for x, y in xy[i]:
if pat[x] != y:
bl = False
if bl:
ans = max(ans, sum(pat))
print(ans)
| false | 3.333333 | [
"- a_tmp = int(eval(input()))",
"- a.append(a_tmp)",
"- xy_tmp = []",
"- for _ in range(a_tmp):",
"- xy_tmp.append(list(map(int, input().split())))",
"- xy.append(xy_tmp)",
"+ ea = int(eval(input()))",
"+ new = []",
"+ for _ in range(ea):",
"+ x, y = list(map(int, input().split()))",
"+ x -= 1",
"+ new.append([x, y])",
"+ xy.append(new)",
"- sat = True",
"- for i, bl in enumerate(pat):",
"- if bl:",
"+ bl = True",
"+ for i, e in enumerate(pat):",
"+ if e:",
"- x -= 1",
"- sat = False",
"- if sat:",
"- cnt = sum(pat)",
"- ans = max(ans, cnt)",
"+ bl = False",
"+ if bl:",
"+ ans = max(ans, sum(pat))"
] | false | 0.040482 | 0.04825 | 0.839009 | [
"s685874201",
"s685304269"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.