user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u970899068
p02803
python
s676607767
s128595561
278
256
44,140
44,268
Accepted
Accepted
7.91
def clear_maze(sx, sy, maze): INF=-10**9 global cnt cnt=0 distance = [[INF for i in range(w+1)] for j in range(h+1)] # distance = [[None]*field_x_length]*field_y_length def bfs(): global cnt queue = [] queue.insert(0, (sx, sy)) distance[sx][sy] = 0 while len(queue): x, y = queue.pop() for i in range(0, 4): nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i] if (0 <= nx and 0 <= ny and maze[nx][ny] != '#' and distance[nx][ny] == INF): queue.insert(0, (nx, ny)) distance[nx][ny] = distance[x][y] + 1 if cnt<distance[nx][ny]: cnt=distance[nx][ny] return cnt return bfs() h,w = list(map(int, input().split())) maze=[list(eval(input())) for i in range(h)] t=[[0]*w for i in range(h)] for i in range(h): maze[i]=['#']+maze[i]+['#'] maze=[['#' for i in range(w+2)]]+maze+[['#' for i in range(w+2)]] ans=0 for i in range(1, h + 1): for j in range(1, w + 1): if maze[i][j] == '#': continue v = (clear_maze(i, j, maze)) if ans <= v: ans = v print(ans)
import collections from collections import deque h,w = list(map(int, input().split())) maze=[list(eval(input())) for i in range(h)] # 枠を囲う for i in range(h): maze[i]=['#']+maze[i]+['#'] maze=[['#' for i in range(w+2)]]+maze+[['#' for i in range(w+2)]] def clear_maze(sx, sy): INF=-10**9 distance = [[INF for i in range(w+2)] for j in range(h+2)] # distance = [[None]*field_x_length]*field_y_length def bfs(): d = deque() d.append((sx, sy)) distance[sx][sy] = 0 ans=0 while len(d): x, y = d.popleft() for i in range(0, 4): nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i] if (0 <= nx and 0 <= ny and maze[nx][ny] != '#' and distance[nx][ny] == INF): d.append((nx, ny)) distance[nx][ny] = distance[x][y] + 1 ans=max(distance[nx][ny],ans) return ans return bfs() m=0 for i in range(1,h+1): for j in range(1,w+1): if maze[i][j] == '.': x=clear_maze(i,j) m=max(x,m) print(m)
51
45
1,274
1,144
def clear_maze(sx, sy, maze): INF = -(10**9) global cnt cnt = 0 distance = [[INF for i in range(w + 1)] for j in range(h + 1)] # distance = [[None]*field_x_length]*field_y_length def bfs(): global cnt queue = [] queue.insert(0, (sx, sy)) distance[sx][sy] = 0 while len(queue): x, y = queue.pop() for i in range(0, 4): nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i] if ( 0 <= nx and 0 <= ny and maze[nx][ny] != "#" and distance[nx][ny] == INF ): queue.insert(0, (nx, ny)) distance[nx][ny] = distance[x][y] + 1 if cnt < distance[nx][ny]: cnt = distance[nx][ny] return cnt return bfs() h, w = list(map(int, input().split())) maze = [list(eval(input())) for i in range(h)] t = [[0] * w for i in range(h)] for i in range(h): maze[i] = ["#"] + maze[i] + ["#"] maze = [["#" for i in range(w + 2)]] + maze + [["#" for i in range(w + 2)]] ans = 0 for i in range(1, h + 1): for j in range(1, w + 1): if maze[i][j] == "#": continue v = clear_maze(i, j, maze) if ans <= v: ans = v print(ans)
import collections from collections import deque h, w = list(map(int, input().split())) maze = [list(eval(input())) for i in range(h)] # 枠を囲う for i in range(h): maze[i] = ["#"] + maze[i] + ["#"] maze = [["#" for i in range(w + 2)]] + maze + [["#" for i in range(w + 2)]] def clear_maze(sx, sy): INF = -(10**9) distance = [[INF for i in range(w + 2)] for j in range(h + 2)] # distance = [[None]*field_x_length]*field_y_length def bfs(): d = deque() d.append((sx, sy)) distance[sx][sy] = 0 ans = 0 while len(d): x, y = d.popleft() for i in range(0, 4): nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i] if ( 0 <= nx and 0 <= ny and maze[nx][ny] != "#" and distance[nx][ny] == INF ): d.append((nx, ny)) distance[nx][ny] = distance[x][y] + 1 ans = max(distance[nx][ny], ans) return ans return bfs() m = 0 for i in range(1, h + 1): for j in range(1, w + 1): if maze[i][j] == ".": x = clear_maze(i, j) m = max(x, m) print(m)
false
11.764706
[ "-def clear_maze(sx, sy, maze):", "+import collections", "+from collections import deque", "+", "+h, w = list(map(int, input().split()))", "+maze = [list(eval(input())) for i in range(h)]", "+# 枠を囲う", "+for i in range(h):", "+ maze[i] = [\"#\"] + maze[i] + [\"#\"]", "+maze = [[\"#\" for i in range(w + 2)]] + maze + [[\"#\" for i in range(w + 2)]]", "+", "+", "+def clear_maze(sx, sy):", "- global cnt", "- cnt = 0", "- distance = [[INF for i in range(w + 1)] for j in range(h + 1)]", "+ distance = [[INF for i in range(w + 2)] for j in range(h + 2)]", "- global cnt", "- queue = []", "- queue.insert(0, (sx, sy))", "+ d = deque()", "+ d.append((sx, sy))", "- while len(queue):", "- x, y = queue.pop()", "+ ans = 0", "+ while len(d):", "+ x, y = d.popleft()", "- queue.insert(0, (nx, ny))", "+ d.append((nx, ny))", "- if cnt < distance[nx][ny]:", "- cnt = distance[nx][ny]", "- return cnt", "+ ans = max(distance[nx][ny], ans)", "+ return ans", "-h, w = list(map(int, input().split()))", "-maze = [list(eval(input())) for i in range(h)]", "-t = [[0] * w for i in range(h)]", "-for i in range(h):", "- maze[i] = [\"#\"] + maze[i] + [\"#\"]", "-maze = [[\"#\" for i in range(w + 2)]] + maze + [[\"#\" for i in range(w + 2)]]", "-ans = 0", "+m = 0", "- if maze[i][j] == \"#\":", "- continue", "- v = clear_maze(i, j, maze)", "- if ans <= v:", "- ans = v", "-print(ans)", "+ if maze[i][j] == \".\":", "+ x = clear_maze(i, j)", "+ m = max(x, m)", "+print(m)" ]
false
0.039761
0.047883
0.830377
[ "s676607767", "s128595561" ]
u735891571
p02678
python
s680034685
s470840275
821
619
64,068
64,064
Accepted
Accepted
24.6
from scipy.sparse.csgraph import breadth_first_tree, breadth_first_order from scipy.sparse import csr_matrix, coo_matrix N, M = list(map(int,input().split())) A = [] B = [] for i in range(M): a, b = list(map(int,input().split())) a -= 1 b -= 1 A.append(a) B.append(b) D = [1] * M csr = coo_matrix((D, (A, B)), (N, N)).tocsr() Tcsr = breadth_first_order(csr, 0, False, True) ans = [] for i in Tcsr[1][1:]+1: if i == -9998: print("No") quit() ans.append(i) print("Yes") for i in ans: print(i)
from scipy.sparse.csgraph import breadth_first_tree, breadth_first_order from scipy.sparse import csr_matrix, coo_matrix import sys input = sys.stdin.readline N, M = list(map(int,input().split())) A = [] B = [] for i in range(M): a, b = list(map(int,input().split())) a -= 1 b -= 1 A.append(a) B.append(b) D = [1] * M csr = coo_matrix((D, (A, B)), (N, N)).tocsr() Tcsr = breadth_first_order(csr, 0, False, True) ans = [] for i in Tcsr[1][1:]+1: if i == -9998: print("No") quit() ans.append(i) print("Yes") for i in ans: print(i)
23
25
548
588
from scipy.sparse.csgraph import breadth_first_tree, breadth_first_order from scipy.sparse import csr_matrix, coo_matrix N, M = list(map(int, input().split())) A = [] B = [] for i in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 A.append(a) B.append(b) D = [1] * M csr = coo_matrix((D, (A, B)), (N, N)).tocsr() Tcsr = breadth_first_order(csr, 0, False, True) ans = [] for i in Tcsr[1][1:] + 1: if i == -9998: print("No") quit() ans.append(i) print("Yes") for i in ans: print(i)
from scipy.sparse.csgraph import breadth_first_tree, breadth_first_order from scipy.sparse import csr_matrix, coo_matrix import sys input = sys.stdin.readline N, M = list(map(int, input().split())) A = [] B = [] for i in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 A.append(a) B.append(b) D = [1] * M csr = coo_matrix((D, (A, B)), (N, N)).tocsr() Tcsr = breadth_first_order(csr, 0, False, True) ans = [] for i in Tcsr[1][1:] + 1: if i == -9998: print("No") quit() ans.append(i) print("Yes") for i in ans: print(i)
false
8
[ "+import sys", "+input = sys.stdin.readline" ]
false
0.304092
0.974879
0.311928
[ "s680034685", "s470840275" ]
u923668099
p02255
python
s665886881
s444530804
30
20
8,084
8,100
Accepted
Accepted
33.33
# coding: utf-8 n = int(eval(input())) data = [int(i) for i in input().split()] for i in range(n): v = data[i] j = i - 1 while j >= 0 and data[j] > v: data[j+1] = data[j] j -= 1 data[j+1] = v print((*data))
def InsertionSort(A, N): print((*A)) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j + 1] = v print((*A)) N = int(eval(input())) A = [int(a) for a in input().split()] InsertionSort(A, N)
12
21
246
323
# coding: utf-8 n = int(eval(input())) data = [int(i) for i in input().split()] for i in range(n): v = data[i] j = i - 1 while j >= 0 and data[j] > v: data[j + 1] = data[j] j -= 1 data[j + 1] = v print((*data))
def InsertionSort(A, N): print((*A)) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j + 1] = v print((*A)) N = int(eval(input())) A = [int(a) for a in input().split()] InsertionSort(A, N)
false
42.857143
[ "-# coding: utf-8", "-n = int(eval(input()))", "-data = [int(i) for i in input().split()]", "-for i in range(n):", "- v = data[i]", "- j = i - 1", "- while j >= 0 and data[j] > v:", "- data[j + 1] = data[j]", "- j -= 1", "- data[j + 1] = v", "- print((*data))", "+def InsertionSort(A, N):", "+ print((*A))", "+ for i in range(1, N):", "+ v = A[i]", "+ j = i - 1", "+ while j >= 0 and A[j] > v:", "+ A[j + 1] = A[j]", "+ j -= 1", "+ A[j + 1] = v", "+ print((*A))", "+", "+", "+N = int(eval(input()))", "+A = [int(a) for a in input().split()]", "+InsertionSort(A, N)" ]
false
0.043569
0.042932
1.01482
[ "s665886881", "s444530804" ]
u476604182
p03108
python
s273804015
s773007234
882
411
25,984
26,128
Accepted
Accepted
53.4
from functools import reduce from operator import mul def cmb(n,r): r = min(r, n-r) if r==0: return 1 if r<0: return 0 over = reduce(mul, list(range(n, n-r, -1))) under = reduce(mul, list(range(1,r+1))) return over//under class UnionFind: def __init__(self, n): self.par = [i for i in range(n)] self.size = [1]*n self.rank = [0]*n def find(self, x): if self.par[x]==x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unit(self, x, y): x = self.find(x) y = self.find(y) if x==y: return elif self.rank[x]<self.rank[y]: self.par[x] = y self.size[y] += self.size[x] return elif self.rank[y]<self.rank[x]: self.par[y] = x self.size[x] += self.size[y] else: self.par[y] = x self.size[x] += self.size[y] self.rank[x] += 1 def same(self, x, y): return self.find(x)==self.find(y) def count(self, x): return self.size[x] N, M = list(map(int, input().split())) bridge = [] u = UnionFind(N) m = cmb(N,2) ans = [m] for i in range(M): A, B = list(map(int, input().split())) bridge += [(A,B)] for i in range(M-1,0,-1): a, b = bridge[i] if u.same(a-1,b-1): ans += [m] continue pa = u.find(a-1) pb = u.find(b-1) m -= u.count(pa)*u.count(pb) ans += [m] u.unit(a-1,b-1) for i in range(M-1,-1,-1): print((ans[i]))
class UnionFind: def __init__(self, n): self.par = [i for i in range(n)] self.size = [1]*n self.rank = [0]*n def find(self, x): if self.par[x]==x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unit(self, x, y): x = self.find(x) y = self.find(y) if x==y: return elif self.rank[x]<self.rank[y]: self.par[x] = y self.size[y] += self.size[x] return elif self.rank[y]<self.rank[x]: self.par[y] = x self.size[x] += self.size[y] else: self.par[y] = x self.size[x] += self.size[y] self.rank[x] += 1 def same(self, x, y): return self.find(x)==self.find(y) def count(self, x): return self.size[x] N, M, *L = list(map(int, open(0).read().split())) u = UnionFind(N+1) m = N*(N-1)//2 ans = [] for a, b in zip(*[iter(L[::-1])]*2): ans += [m] A = u.find(a) B = u.find(b) if A!=B: na = u.count(A) nb = u.count(B) u.unit(a,b) m -= na*nb print(('\n'.join(map(str,ans[::-1]))))
69
49
1,457
1,097
from functools import reduce from operator import mul def cmb(n, r): r = min(r, n - r) if r == 0: return 1 if r < 0: return 0 over = reduce(mul, list(range(n, n - r, -1))) under = reduce(mul, list(range(1, r + 1))) return over // under class UnionFind: def __init__(self, n): self.par = [i for i in range(n)] self.size = [1] * n self.rank = [0] * n def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unit(self, x, y): x = self.find(x) y = self.find(y) if x == y: return elif self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] return elif self.rank[y] < self.rank[x]: self.par[y] = x self.size[x] += self.size[y] else: self.par[y] = x self.size[x] += self.size[y] self.rank[x] += 1 def same(self, x, y): return self.find(x) == self.find(y) def count(self, x): return self.size[x] N, M = list(map(int, input().split())) bridge = [] u = UnionFind(N) m = cmb(N, 2) ans = [m] for i in range(M): A, B = list(map(int, input().split())) bridge += [(A, B)] for i in range(M - 1, 0, -1): a, b = bridge[i] if u.same(a - 1, b - 1): ans += [m] continue pa = u.find(a - 1) pb = u.find(b - 1) m -= u.count(pa) * u.count(pb) ans += [m] u.unit(a - 1, b - 1) for i in range(M - 1, -1, -1): print((ans[i]))
class UnionFind: def __init__(self, n): self.par = [i for i in range(n)] self.size = [1] * n self.rank = [0] * n def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unit(self, x, y): x = self.find(x) y = self.find(y) if x == y: return elif self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] return elif self.rank[y] < self.rank[x]: self.par[y] = x self.size[x] += self.size[y] else: self.par[y] = x self.size[x] += self.size[y] self.rank[x] += 1 def same(self, x, y): return self.find(x) == self.find(y) def count(self, x): return self.size[x] N, M, *L = list(map(int, open(0).read().split())) u = UnionFind(N + 1) m = N * (N - 1) // 2 ans = [] for a, b in zip(*[iter(L[::-1])] * 2): ans += [m] A = u.find(a) B = u.find(b) if A != B: na = u.count(A) nb = u.count(B) u.unit(a, b) m -= na * nb print(("\n".join(map(str, ans[::-1]))))
false
28.985507
[ "-from functools import reduce", "-from operator import mul", "-", "-", "-def cmb(n, r):", "- r = min(r, n - r)", "- if r == 0:", "- return 1", "- if r < 0:", "- return 0", "- over = reduce(mul, list(range(n, n - r, -1)))", "- under = reduce(mul, list(range(1, r + 1)))", "- return over // under", "-", "-", "-N, M = list(map(int, input().split()))", "-bridge = []", "-u = UnionFind(N)", "-m = cmb(N, 2)", "-ans = [m]", "-for i in range(M):", "- A, B = list(map(int, input().split()))", "- bridge += [(A, B)]", "-for i in range(M - 1, 0, -1):", "- a, b = bridge[i]", "- if u.same(a - 1, b - 1):", "- ans += [m]", "- continue", "- pa = u.find(a - 1)", "- pb = u.find(b - 1)", "- m -= u.count(pa) * u.count(pb)", "+N, M, *L = list(map(int, open(0).read().split()))", "+u = UnionFind(N + 1)", "+m = N * (N - 1) // 2", "+ans = []", "+for a, b in zip(*[iter(L[::-1])] * 2):", "- u.unit(a - 1, b - 1)", "-for i in range(M - 1, -1, -1):", "- print((ans[i]))", "+ A = u.find(a)", "+ B = u.find(b)", "+ if A != B:", "+ na = u.count(A)", "+ nb = u.count(B)", "+ u.unit(a, b)", "+ m -= na * nb", "+print((\"\\n\".join(map(str, ans[::-1]))))" ]
false
0.039977
0.039483
1.012517
[ "s273804015", "s773007234" ]
u731368968
p02755
python
s033983375
s475376594
24
18
2,940
2,940
Accepted
Accepted
25
A, B = list(map(int, input().split())) for i in range(20000): if int(i*0.08) == A and int(i * 0.1) == B: print(i) exit() print((-1))
A,B=list(map(int,input().split())) for i in range(2000): if A==i*8//100 and B==i*10//100: print(i) break else: print((-1))
6
7
150
135
A, B = list(map(int, input().split())) for i in range(20000): if int(i * 0.08) == A and int(i * 0.1) == B: print(i) exit() print((-1))
A, B = list(map(int, input().split())) for i in range(2000): if A == i * 8 // 100 and B == i * 10 // 100: print(i) break else: print((-1))
false
14.285714
[ "-for i in range(20000):", "- if int(i * 0.08) == A and int(i * 0.1) == B:", "+for i in range(2000):", "+ if A == i * 8 // 100 and B == i * 10 // 100:", "- exit()", "-print((-1))", "+ break", "+else:", "+ print((-1))" ]
false
0.09027
0.040267
2.241793
[ "s033983375", "s475376594" ]
u107077660
p04043
python
s816091617
s524856998
41
22
3,064
3,064
Accepted
Accepted
46.34
L = sorted(list(map(int, input().split()))) if L == [5,5,7]: print("YES") else: print("NO")
S = [int(i) for i in input().split()] S.sort() if S == [5,5,7]: print("YES") else: print("NO")
5
6
97
102
L = sorted(list(map(int, input().split()))) if L == [5, 5, 7]: print("YES") else: print("NO")
S = [int(i) for i in input().split()] S.sort() if S == [5, 5, 7]: print("YES") else: print("NO")
false
16.666667
[ "-L = sorted(list(map(int, input().split())))", "-if L == [5, 5, 7]:", "+S = [int(i) for i in input().split()]", "+S.sort()", "+if S == [5, 5, 7]:" ]
false
0.036075
0.074153
0.486498
[ "s816091617", "s524856998" ]
u934442292
p03319
python
s592851637
s068618685
40
17
13,876
2,940
Accepted
Accepted
57.5
import sys input = sys.stdin.readline def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) q, r, = divmod(N - 1, K - 1) ans = q + int(r > 0) print(ans) 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())) q, r, = divmod(N - 1, K - 1) ans = q + int(r > 0) print(ans) if __name__ == "__main__": main()
17
17
261
263
import sys input = sys.stdin.readline def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) ( q, r, ) = divmod(N - 1, K - 1) ans = q + int(r > 0) print(ans) 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())) ( q, r, ) = divmod(N - 1, K - 1) ans = q + int(r > 0) print(ans) if __name__ == "__main__": main()
false
0
[ "- A = list(map(int, input().split()))", "+ # A = list(map(int, input().split()))" ]
false
0.042752
0.038757
1.103081
[ "s592851637", "s068618685" ]
u263830634
p03721
python
s925672350
s917006454
909
220
61,144
18,220
Accepted
Accepted
75.8
N, K = list(map(int, input().split())) lst = [] for i in range(N): lst += [list(map(int, input().split()))] lst.sort() for i in range(N): if K <= lst[i][1]: print((lst[i][0])) exit() else: K -= lst[i][1]
import sys input = sys.stdin.readline N, K = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(N)] AB.sort(key = lambda x: x[0]) for a, b in AB: K -= b if K <= 0: print (a) exit()
15
15
250
252
N, K = list(map(int, input().split())) lst = [] for i in range(N): lst += [list(map(int, input().split()))] lst.sort() for i in range(N): if K <= lst[i][1]: print((lst[i][0])) exit() else: K -= lst[i][1]
import sys input = sys.stdin.readline N, K = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(N)] AB.sort(key=lambda x: x[0]) for a, b in AB: K -= b if K <= 0: print(a) exit()
false
0
[ "+import sys", "+", "+input = sys.stdin.readline", "-lst = []", "-for i in range(N):", "- lst += [list(map(int, input().split()))]", "-lst.sort()", "-for i in range(N):", "- if K <= lst[i][1]:", "- print((lst[i][0]))", "+AB = [tuple(map(int, input().split())) for _ in range(N)]", "+AB.sort(key=lambda x: x[0])", "+for a, b in AB:", "+ K -= b", "+ if K <= 0:", "+ print(a)", "- else:", "- K -= lst[i][1]" ]
false
0.035408
0.0425
0.833125
[ "s925672350", "s917006454" ]
u489959379
p02901
python
s958087866
s867364368
1,410
959
3,316
9,372
Accepted
Accepted
31.99
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, m = list(map(int, input().split())) ABC = [] for _ in range(m): a, b = list(map(int, input().split())) C = list(map(int, input().split())) bit = ["0"] * n for c in C: bit[c - 1] = "1" bit = "".join(bit) ABC.append([a, b, int(bit, 2)]) dp = [f_inf for _ in range(1 << n)] dp[0] = 0 for i in range(1 << n): for a, b, c in ABC: idx = i | c dp[idx] = min(dp[idx], dp[i] + a) if dp[-1] != f_inf: print((dp[-1])) else: print((-1)) if __name__ == '__main__': resolve()
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, m = list(map(int, input().split())) keys = [] for _ in range(m): bit = ["0"] * n a, b = list(map(int, input().split())) C = list(map(int, input().split())) for c in C: bit[c - 1] = "1" bit = int("".join(bit), 2) keys.append([bit, a]) dp = [f_inf] * (1 << n) dp[0] = 0 for i in range(1 << n): for k, cost in keys: idx = i | k dp[idx] = min(dp[idx], dp[i] + cost) print((dp[-1] if dp[-1] != f_inf else -1)) if __name__ == '__main__': resolve()
35
32
731
710
import sys sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 def resolve(): n, m = list(map(int, input().split())) ABC = [] for _ in range(m): a, b = list(map(int, input().split())) C = list(map(int, input().split())) bit = ["0"] * n for c in C: bit[c - 1] = "1" bit = "".join(bit) ABC.append([a, b, int(bit, 2)]) dp = [f_inf for _ in range(1 << n)] dp[0] = 0 for i in range(1 << n): for a, b, c in ABC: idx = i | c dp[idx] = min(dp[idx], dp[i] + a) if dp[-1] != f_inf: print((dp[-1])) else: print((-1)) if __name__ == "__main__": resolve()
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): n, m = list(map(int, input().split())) keys = [] for _ in range(m): bit = ["0"] * n a, b = list(map(int, input().split())) C = list(map(int, input().split())) for c in C: bit[c - 1] = "1" bit = int("".join(bit), 2) keys.append([bit, a]) dp = [f_inf] * (1 << n) dp[0] = 0 for i in range(1 << n): for k, cost in keys: idx = i | k dp[idx] = min(dp[idx], dp[i] + cost) print((dp[-1] if dp[-1] != f_inf else -1)) if __name__ == "__main__": resolve()
false
8.571429
[ "+input = sys.stdin.readline", "- ABC = []", "+ keys = []", "+ bit = [\"0\"] * n", "- bit = [\"0\"] * n", "- bit = \"\".join(bit)", "- ABC.append([a, b, int(bit, 2)])", "- dp = [f_inf for _ in range(1 << n)]", "+ bit = int(\"\".join(bit), 2)", "+ keys.append([bit, a])", "+ dp = [f_inf] * (1 << n)", "- for a, b, c in ABC:", "- idx = i | c", "- dp[idx] = min(dp[idx], dp[i] + a)", "- if dp[-1] != f_inf:", "- print((dp[-1]))", "- else:", "- print((-1))", "+ for k, cost in keys:", "+ idx = i | k", "+ dp[idx] = min(dp[idx], dp[i] + cost)", "+ print((dp[-1] if dp[-1] != f_inf else -1))" ]
false
0.036485
0.03599
1.013738
[ "s958087866", "s867364368" ]
u136395536
p03416
python
s496821008
s077755592
56
50
2,940
2,940
Accepted
Accepted
10.71
A,B = (int(i) for i in input().split()) count = 0 for i in range(B-A+1): number = A+i charnum = str(number) if(charnum[0]==charnum[4] and charnum[1]==charnum[3]): count = count + 1 print(count)
A,B = (int(i) for i in input().split()) count = 0 for i in range(A,B+1): s = str(i) if s[0]==s[4] and s[1]==s[3]: count += 1 print(count)
10
9
226
163
A, B = (int(i) for i in input().split()) count = 0 for i in range(B - A + 1): number = A + i charnum = str(number) if charnum[0] == charnum[4] and charnum[1] == charnum[3]: count = count + 1 print(count)
A, B = (int(i) for i in input().split()) count = 0 for i in range(A, B + 1): s = str(i) if s[0] == s[4] and s[1] == s[3]: count += 1 print(count)
false
10
[ "-for i in range(B - A + 1):", "- number = A + i", "- charnum = str(number)", "- if charnum[0] == charnum[4] and charnum[1] == charnum[3]:", "- count = count + 1", "+for i in range(A, B + 1):", "+ s = str(i)", "+ if s[0] == s[4] and s[1] == s[3]:", "+ count += 1" ]
false
0.062012
0.046076
1.345883
[ "s496821008", "s077755592" ]
u678167152
p03745
python
s013412573
s274790788
85
74
14,224
14,252
Accepted
Accepted
12.94
N = int(eval(input())) A = list(map(int, input().split())) def solve(N,A): liss = [] lis = [] lis.append(A[0]) a = A[0] for i in range(1,N): if len(lis)==1 or prev==0: prev = A[i]-a elif (A[i]-a)*prev<0: liss.append(lis) lis = [] lis.append(A[i]) a = A[i] liss.append(lis) ans = len(liss) return ans print((solve(N,A)))
N = int(eval(input())) A = list(map(int, input().split())) def solve(N,A): ans = 1 lis = [] lis.append(A[0]) a = A[0] for i in range(1,N): if len(lis)==1 or prev==0: prev = A[i]-a elif (A[i]-a)*prev<0: ans += 1 lis = [] lis.append(A[i]) a = A[i] return ans print((solve(N,A)))
19
17
429
376
N = int(eval(input())) A = list(map(int, input().split())) def solve(N, A): liss = [] lis = [] lis.append(A[0]) a = A[0] for i in range(1, N): if len(lis) == 1 or prev == 0: prev = A[i] - a elif (A[i] - a) * prev < 0: liss.append(lis) lis = [] lis.append(A[i]) a = A[i] liss.append(lis) ans = len(liss) return ans print((solve(N, A)))
N = int(eval(input())) A = list(map(int, input().split())) def solve(N, A): ans = 1 lis = [] lis.append(A[0]) a = A[0] for i in range(1, N): if len(lis) == 1 or prev == 0: prev = A[i] - a elif (A[i] - a) * prev < 0: ans += 1 lis = [] lis.append(A[i]) a = A[i] return ans print((solve(N, A)))
false
10.526316
[ "- liss = []", "+ ans = 1", "- liss.append(lis)", "+ ans += 1", "- liss.append(lis)", "- ans = len(liss)" ]
false
0.157449
0.04619
3.40876
[ "s013412573", "s274790788" ]
u796942881
p02959
python
s045898968
s104158243
117
87
20,324
18,624
Accepted
Accepted
25.64
from sys import stdin def main(): lines = stdin.readlines() A = tuple(map(int, lines[1].split())) B = tuple(map(int, lines[2].split())) pre = A[0] ans = 0 for a, b in zip(A[1:], B): tmp1 = min(pre, b) b -= tmp1 tmp2 = min(a, b) ans += tmp1 + tmp2 pre = a - tmp2 print(ans) return main()
from sys import stdin def main(): eval(input()) A = tuple(map(int, stdin.readline().split())) B = tuple(map(int, stdin.readline().split())) pre = A[0] ans = 0 for a, b in zip(A[1:], B): tmp1 = pre if pre < b else b b -= tmp1 tmp2 = a if a < b else b ans += tmp1 + tmp2 pre = a - tmp2 print(ans) return main()
20
20
382
398
from sys import stdin def main(): lines = stdin.readlines() A = tuple(map(int, lines[1].split())) B = tuple(map(int, lines[2].split())) pre = A[0] ans = 0 for a, b in zip(A[1:], B): tmp1 = min(pre, b) b -= tmp1 tmp2 = min(a, b) ans += tmp1 + tmp2 pre = a - tmp2 print(ans) return main()
from sys import stdin def main(): eval(input()) A = tuple(map(int, stdin.readline().split())) B = tuple(map(int, stdin.readline().split())) pre = A[0] ans = 0 for a, b in zip(A[1:], B): tmp1 = pre if pre < b else b b -= tmp1 tmp2 = a if a < b else b ans += tmp1 + tmp2 pre = a - tmp2 print(ans) return main()
false
0
[ "- lines = stdin.readlines()", "- A = tuple(map(int, lines[1].split()))", "- B = tuple(map(int, lines[2].split()))", "+ eval(input())", "+ A = tuple(map(int, stdin.readline().split()))", "+ B = tuple(map(int, stdin.readline().split()))", "- tmp1 = min(pre, b)", "+ tmp1 = pre if pre < b else b", "- tmp2 = min(a, b)", "+ tmp2 = a if a < b else b" ]
false
0.036547
0.058045
0.629636
[ "s045898968", "s104158243" ]
u145600939
p02913
python
s788687126
s468392048
498
202
229,768
4,208
Accepted
Accepted
59.44
def main(): n = int(eval(input())) s = eval(input()) dp = [[0]*(n+1) for i in range(n+1)] ans = 0 for i in range(n-1)[::-1]: for j in range(i+1,n)[::-1]: if s[i] == s[j]: dp[i][j] = max(dp[i][j], dp[i+1][j+1] + 1) ans = max(ans, min(dp[i][j],j-i)) print(ans) main()
n = int(eval(input())) s = eval(input()) mod = 10**20 + 7 base = 12345 def ok(l): array = {} rolling_hash = 0 for i in range(n): rolling_hash *= base rolling_hash += ord(s[i]) if i - l >= 0: rolling_hash -= ord(s[i-l]) * pow(base, l, mod) rolling_hash %= mod if i >= l-1: if rolling_hash in list(array.keys()): array[rolling_hash].append(i) else: array[rolling_hash] = [i] for check in list(array.values()): if max(check) - min(check) >= l: return True return False top = n bottom = 0 while top - bottom > 1: mid = (top + bottom)//2 if ok(mid): bottom = mid else: top = mid print(bottom)
12
35
341
778
def main(): n = int(eval(input())) s = eval(input()) dp = [[0] * (n + 1) for i in range(n + 1)] ans = 0 for i in range(n - 1)[::-1]: for j in range(i + 1, n)[::-1]: if s[i] == s[j]: dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + 1) ans = max(ans, min(dp[i][j], j - i)) print(ans) main()
n = int(eval(input())) s = eval(input()) mod = 10**20 + 7 base = 12345 def ok(l): array = {} rolling_hash = 0 for i in range(n): rolling_hash *= base rolling_hash += ord(s[i]) if i - l >= 0: rolling_hash -= ord(s[i - l]) * pow(base, l, mod) rolling_hash %= mod if i >= l - 1: if rolling_hash in list(array.keys()): array[rolling_hash].append(i) else: array[rolling_hash] = [i] for check in list(array.values()): if max(check) - min(check) >= l: return True return False top = n bottom = 0 while top - bottom > 1: mid = (top + bottom) // 2 if ok(mid): bottom = mid else: top = mid print(bottom)
false
65.714286
[ "-def main():", "- n = int(eval(input()))", "- s = eval(input())", "- dp = [[0] * (n + 1) for i in range(n + 1)]", "- ans = 0", "- for i in range(n - 1)[::-1]:", "- for j in range(i + 1, n)[::-1]:", "- if s[i] == s[j]:", "- dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + 1)", "- ans = max(ans, min(dp[i][j], j - i))", "- print(ans)", "+n = int(eval(input()))", "+s = eval(input())", "+mod = 10**20 + 7", "+base = 12345", "-main()", "+def ok(l):", "+ array = {}", "+ rolling_hash = 0", "+ for i in range(n):", "+ rolling_hash *= base", "+ rolling_hash += ord(s[i])", "+ if i - l >= 0:", "+ rolling_hash -= ord(s[i - l]) * pow(base, l, mod)", "+ rolling_hash %= mod", "+ if i >= l - 1:", "+ if rolling_hash in list(array.keys()):", "+ array[rolling_hash].append(i)", "+ else:", "+ array[rolling_hash] = [i]", "+ for check in list(array.values()):", "+ if max(check) - min(check) >= l:", "+ return True", "+ return False", "+", "+", "+top = n", "+bottom = 0", "+while top - bottom > 1:", "+ mid = (top + bottom) // 2", "+ if ok(mid):", "+ bottom = mid", "+ else:", "+ top = mid", "+print(bottom)" ]
false
0.048025
0.043492
1.10422
[ "s788687126", "s468392048" ]
u888092736
p02598
python
s287876772
s007245376
1,941
1,149
31,412
31,496
Accepted
Accepted
40.8
def is_good(mid, key): return sum(count_cuts(a, mid) for a in A) <= key def binary_search(key): bad, good = 0, 2 * 10 ** 14 + 1 while good - bad > 1: mid = (bad + good) // 2 if is_good(mid, key): good = mid else: bad = mid return good def count_cuts(a, unit): return (a + unit - 1) // unit - 1 N, K, *A = list(map(int, open(0).read().split())) print((binary_search(K)))
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)))
21
21
456
453
def is_good(mid, key): return sum(count_cuts(a, mid) for a in A) <= key def binary_search(key): bad, good = 0, 2 * 10**14 + 1 while good - bad > 1: mid = (bad + good) // 2 if is_good(mid, key): good = mid else: bad = mid return good def count_cuts(a, unit): return (a + unit - 1) // unit - 1 N, K, *A = list(map(int, open(0).read().split())) print((binary_search(K)))
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)))
false
0
[ "+def count_cuts(a, unit):", "+ return (a + unit - 1) // unit - 1", "+", "+", "- bad, good = 0, 2 * 10**14 + 1", "+ bad, good = 0, 1_000_000_000", "-def count_cuts(a, unit):", "- return (a + unit - 1) // unit - 1", "-", "-" ]
false
0.038337
0.038191
1.003814
[ "s287876772", "s007245376" ]
u358919705
p00022
python
s849639573
s474073786
1,250
60
7,828
7,712
Accepted
Accepted
95.2
import itertools while True: n = int(eval(input())) if n == 0: break a = [int(eval(input())) for _ in range(n)] a[:0] = [0] for i in range(1, len(a)): a[i] += a[i - 1] print((max([x[1] - x[0] for x in itertools.combinations(a, 2)])))
while True: n = int(eval(input())) if not n: break a = [int(eval(input())) for _ in range(n)] for i in range(1, n): if a[i - 1] > 0: a[i] += a[i - 1] print((max(a)))
10
9
272
207
import itertools while True: n = int(eval(input())) if n == 0: break a = [int(eval(input())) for _ in range(n)] a[:0] = [0] for i in range(1, len(a)): a[i] += a[i - 1] print((max([x[1] - x[0] for x in itertools.combinations(a, 2)])))
while True: n = int(eval(input())) if not n: break a = [int(eval(input())) for _ in range(n)] for i in range(1, n): if a[i - 1] > 0: a[i] += a[i - 1] print((max(a)))
false
10
[ "-import itertools", "-", "- if n == 0:", "+ if not n:", "- a[:0] = [0]", "- for i in range(1, len(a)):", "- a[i] += a[i - 1]", "- print((max([x[1] - x[0] for x in itertools.combinations(a, 2)])))", "+ for i in range(1, n):", "+ if a[i - 1] > 0:", "+ a[i] += a[i - 1]", "+ print((max(a)))" ]
false
0.060372
0.035523
1.699496
[ "s849639573", "s474073786" ]
u297574184
p03035
python
s436524960
s321517546
20
18
2,940
2,940
Accepted
Accepted
10
A, B = list(map(int, input().split())) if A <= 5: print((0)) elif A <= 12: print((B//2)) else: print(B)
A, B = list(map(int, input().split())) if A <= 5: B = 0 elif A <= 12: B //= 2 print(B)
8
8
114
98
A, B = list(map(int, input().split())) if A <= 5: print((0)) elif A <= 12: print((B // 2)) else: print(B)
A, B = list(map(int, input().split())) if A <= 5: B = 0 elif A <= 12: B //= 2 print(B)
false
0
[ "- print((0))", "+ B = 0", "- print((B // 2))", "-else:", "- print(B)", "+ B //= 2", "+print(B)" ]
false
0.040966
0.077186
0.530745
[ "s436524960", "s321517546" ]
u606045429
p02716
python
s615185385
s049743227
1,320
1,022
291,152
291,132
Accepted
Accepted
22.58
from collections import defaultdict INF = float("inf") N, *A = list(map(int, open(0).read().split())) dp_in = defaultdict(lambda: -INF) dp_out = defaultdict(lambda: -INF) dp_out[(0, 0)] = 0 for i, a in enumerate(A, 1): p = i // 2 for j in [p - 1, p, p + 1]: dp_in[(i, j)] = a + dp_out[(i - 1, j - 1)] dp_out[(i, j)] = max(dp_in[(i - 1, j)], dp_out[(i - 1, j)]) print((max(dp_in[(N, N // 2)], dp_out[(N, N // 2)])))
from collections import defaultdict def main(): INF = float("inf") N, *A = list(map(int, open(0).read().split())) dp_in = defaultdict(lambda: -INF) dp_out = defaultdict(lambda: -INF) dp_out[(0, 0)] = 0 for i, a in enumerate(A, 1): p = i // 2 for j in [p - 1, p, p + 1]: dp_in[(i, j)] = a + dp_out[(i - 1, j - 1)] dp_out[(i, j)] = max(dp_in[(i - 1, j)], dp_out[(i - 1, j)]) print((max(dp_in[(N, N // 2)], dp_out[(N, N // 2)]))) main()
18
21
453
520
from collections import defaultdict INF = float("inf") N, *A = list(map(int, open(0).read().split())) dp_in = defaultdict(lambda: -INF) dp_out = defaultdict(lambda: -INF) dp_out[(0, 0)] = 0 for i, a in enumerate(A, 1): p = i // 2 for j in [p - 1, p, p + 1]: dp_in[(i, j)] = a + dp_out[(i - 1, j - 1)] dp_out[(i, j)] = max(dp_in[(i - 1, j)], dp_out[(i - 1, j)]) print((max(dp_in[(N, N // 2)], dp_out[(N, N // 2)])))
from collections import defaultdict def main(): INF = float("inf") N, *A = list(map(int, open(0).read().split())) dp_in = defaultdict(lambda: -INF) dp_out = defaultdict(lambda: -INF) dp_out[(0, 0)] = 0 for i, a in enumerate(A, 1): p = i // 2 for j in [p - 1, p, p + 1]: dp_in[(i, j)] = a + dp_out[(i - 1, j - 1)] dp_out[(i, j)] = max(dp_in[(i - 1, j)], dp_out[(i - 1, j)]) print((max(dp_in[(N, N // 2)], dp_out[(N, N // 2)]))) main()
false
14.285714
[ "-INF = float(\"inf\")", "-N, *A = list(map(int, open(0).read().split()))", "-dp_in = defaultdict(lambda: -INF)", "-dp_out = defaultdict(lambda: -INF)", "-dp_out[(0, 0)] = 0", "-for i, a in enumerate(A, 1):", "- p = i // 2", "- for j in [p - 1, p, p + 1]:", "- dp_in[(i, j)] = a + dp_out[(i - 1, j - 1)]", "- dp_out[(i, j)] = max(dp_in[(i - 1, j)], dp_out[(i - 1, j)])", "-print((max(dp_in[(N, N // 2)], dp_out[(N, N // 2)])))", "+", "+def main():", "+ INF = float(\"inf\")", "+ N, *A = list(map(int, open(0).read().split()))", "+ dp_in = defaultdict(lambda: -INF)", "+ dp_out = defaultdict(lambda: -INF)", "+ dp_out[(0, 0)] = 0", "+ for i, a in enumerate(A, 1):", "+ p = i // 2", "+ for j in [p - 1, p, p + 1]:", "+ dp_in[(i, j)] = a + dp_out[(i - 1, j - 1)]", "+ dp_out[(i, j)] = max(dp_in[(i - 1, j)], dp_out[(i - 1, j)])", "+ print((max(dp_in[(N, N // 2)], dp_out[(N, N // 2)])))", "+", "+", "+main()" ]
false
0.047576
0.047204
1.007867
[ "s615185385", "s049743227" ]
u645250356
p03557
python
s021929667
s683569770
375
325
23,360
23,328
Accepted
Accepted
13.33
import bisect n = int(eval(input())) bb = [0] * (n+1) ans = 0 a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = [int(i) for i in input().split()] a.sort() b.sort() c.sort() for i in range(1,n+1): bb[i] = bisect.bisect_left(a,b[i-1]) + bb[i-1] for i in range(n): ans += bb[bisect.bisect_left(b,c[i])] print(ans)
import bisect n = int(eval(input())) ans = 0 a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a.sort() b.sort() c.sort() for i in range(n): ans += bisect.bisect_left(a,b[i]) * (n-bisect.bisect_right(c,b[i])) print(ans)
17
12
360
283
import bisect n = int(eval(input())) bb = [0] * (n + 1) ans = 0 a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = [int(i) for i in input().split()] a.sort() b.sort() c.sort() for i in range(1, n + 1): bb[i] = bisect.bisect_left(a, b[i - 1]) + bb[i - 1] for i in range(n): ans += bb[bisect.bisect_left(b, c[i])] print(ans)
import bisect n = int(eval(input())) ans = 0 a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() for i in range(n): ans += bisect.bisect_left(a, b[i]) * (n - bisect.bisect_right(c, b[i])) print(ans)
false
29.411765
[ "-bb = [0] * (n + 1)", "-a = [int(i) for i in input().split()]", "-b = [int(i) for i in input().split()]", "-c = [int(i) for i in input().split()]", "+a = list(map(int, input().split()))", "+b = list(map(int, input().split()))", "+c = list(map(int, input().split()))", "-for i in range(1, n + 1):", "- bb[i] = bisect.bisect_left(a, b[i - 1]) + bb[i - 1]", "- ans += bb[bisect.bisect_left(b, c[i])]", "+ ans += bisect.bisect_left(a, b[i]) * (n - bisect.bisect_right(c, b[i]))" ]
false
0.038809
0.039467
0.983317
[ "s021929667", "s683569770" ]
u561083515
p03651
python
s430034835
s393391825
168
93
14,224
16,280
Accepted
Accepted
44.64
N,K = list(map(int, input().split())) A = [int(i) for i in input().split()] A.sort() if A[-1] < K: print("IMPOSSIBLE") exit() from bisect import bisect_left flag = False for i in range(N): if A[i] == K: flag = True idx = bisect_left(A, K - A[i]) if idx < N and i != idx and A[idx] == K - A[i]: flag = True if flag: print('POSSIBLE') else: print('IMPOSSIBLE')
from fractions import gcd N,K = list(map(int, input().split())) A = [int(i) for i in input().split()] M = max(A) G = 0 for a in A: G = gcd(G, a) if K % G == 0 and K <= M: print("POSSIBLE") else: print("IMPOSSIBLE")
23
15
427
238
N, K = list(map(int, input().split())) A = [int(i) for i in input().split()] A.sort() if A[-1] < K: print("IMPOSSIBLE") exit() from bisect import bisect_left flag = False for i in range(N): if A[i] == K: flag = True idx = bisect_left(A, K - A[i]) if idx < N and i != idx and A[idx] == K - A[i]: flag = True if flag: print("POSSIBLE") else: print("IMPOSSIBLE")
from fractions import gcd N, K = list(map(int, input().split())) A = [int(i) for i in input().split()] M = max(A) G = 0 for a in A: G = gcd(G, a) if K % G == 0 and K <= M: print("POSSIBLE") else: print("IMPOSSIBLE")
false
34.782609
[ "+from fractions import gcd", "+", "-A.sort()", "-if A[-1] < K:", "- print(\"IMPOSSIBLE\")", "- exit()", "-from bisect import bisect_left", "-", "-flag = False", "-for i in range(N):", "- if A[i] == K:", "- flag = True", "- idx = bisect_left(A, K - A[i])", "- if idx < N and i != idx and A[idx] == K - A[i]:", "- flag = True", "-if flag:", "+M = max(A)", "+G = 0", "+for a in A:", "+ G = gcd(G, a)", "+if K % G == 0 and K <= M:" ]
false
0.036112
0.046053
0.784144
[ "s430034835", "s393391825" ]
u740284863
p02813
python
s743609440
s980231339
39
34
14,180
13,932
Accepted
Accepted
12.82
import itertools,math n = int(eval(input())) a = sorted(list(itertools.permutations([ i for i in range(1,n+1)]))) p = tuple(map(int,input().split())) q = tuple(map(int,input().split())) print((abs(a.index(p) - a.index(q))))
import itertools n = int(eval(input())) P = tuple(map(int,input().split())) Q = tuple(map(int,input().split())) L = list(itertools.permutations([i for i in range(1,n+1)])) print(( abs((L.index(P)+1)-((L.index(Q)+1))) ))
6
8
220
227
import itertools, math n = int(eval(input())) a = sorted(list(itertools.permutations([i for i in range(1, n + 1)]))) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) print((abs(a.index(p) - a.index(q))))
import itertools n = int(eval(input())) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) L = list(itertools.permutations([i for i in range(1, n + 1)])) print((abs((L.index(P) + 1) - ((L.index(Q) + 1)))))
false
25
[ "-import itertools, math", "+import itertools", "-a = sorted(list(itertools.permutations([i for i in range(1, n + 1)])))", "-p = tuple(map(int, input().split()))", "-q = tuple(map(int, input().split()))", "-print((abs(a.index(p) - a.index(q))))", "+P = tuple(map(int, input().split()))", "+Q = tuple(map(int, input().split()))", "+L = list(itertools.permutations([i for i in range(1, n + 1)]))", "+print((abs((L.index(P) + 1) - ((L.index(Q) + 1)))))" ]
false
0.040686
0.03944
1.031592
[ "s743609440", "s980231339" ]
u627234757
p03037
python
s661584276
s274754900
353
191
10,996
9,208
Accepted
Accepted
45.89
N, M = list(map(int, input().split())) L = [] R = [] for _ in range(M): tmp1,tmp2 = list(map(int,input().split())) L.append(tmp1) R.append(tmp2) max_L = L[0] min_R = R[0] for i in range(1,M): max_L = max(max_L, L[i]) min_R = min(min_R, R[i]) if min_R >= max_L: res = min_R - max_L + 1 else: res = 0 print(res)
n, m = list(map(int, input().split())) max_l = 0 min_r = 10**5 for i in range(m): l, r = list(map(int, input().split())) if l > max_l: max_l = l if r < min_r: min_r = r max_l = min(n+1, max_l) min_r = min(n+1, min_r) res = min_r - max_l + 1 if res<0: res = 0 print(res)
19
15
345
287
N, M = list(map(int, input().split())) L = [] R = [] for _ in range(M): tmp1, tmp2 = list(map(int, input().split())) L.append(tmp1) R.append(tmp2) max_L = L[0] min_R = R[0] for i in range(1, M): max_L = max(max_L, L[i]) min_R = min(min_R, R[i]) if min_R >= max_L: res = min_R - max_L + 1 else: res = 0 print(res)
n, m = list(map(int, input().split())) max_l = 0 min_r = 10**5 for i in range(m): l, r = list(map(int, input().split())) if l > max_l: max_l = l if r < min_r: min_r = r max_l = min(n + 1, max_l) min_r = min(n + 1, min_r) res = min_r - max_l + 1 if res < 0: res = 0 print(res)
false
21.052632
[ "-N, M = list(map(int, input().split()))", "-L = []", "-R = []", "-for _ in range(M):", "- tmp1, tmp2 = list(map(int, input().split()))", "- L.append(tmp1)", "- R.append(tmp2)", "-max_L = L[0]", "-min_R = R[0]", "-for i in range(1, M):", "- max_L = max(max_L, L[i])", "- min_R = min(min_R, R[i])", "-if min_R >= max_L:", "- res = min_R - max_L + 1", "-else:", "+n, m = list(map(int, input().split()))", "+max_l = 0", "+min_r = 10**5", "+for i in range(m):", "+ l, r = list(map(int, input().split()))", "+ if l > max_l:", "+ max_l = l", "+ if r < min_r:", "+ min_r = r", "+max_l = min(n + 1, max_l)", "+min_r = min(n + 1, min_r)", "+res = min_r - max_l + 1", "+if res < 0:" ]
false
0.04147
0.121408
0.341581
[ "s661584276", "s274754900" ]
u296518383
p02862
python
s782629493
s107812686
409
315
127,612
118,928
Accepted
Accepted
22.98
def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = 10**6 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) X,Y=list(map(int,input().split())) if (X+Y)%3!=0: print((0)) exit() n=(X+Y)//3 k=Y-(X+Y)//3 if k<0 or k>n: print((0)) exit() #print("n,k:",n,k) print((cmb(n,k,mod)))
X, Y = list(map(int, input().split())) MOD = 10 ** 9 + 7 if (X + Y) % 3 != 0: print((0)) exit() if abs(X - Y) > (X + Y) // 3: print((0)) exit() n = (X + Y) // 3 + 1 k = ((X - Y) + n + 1) // 2 SIZE = max(n, k) g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] # 逆元テーブル計算用テーブル def comb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod for i in range(2, SIZE): g1.append((g1[-1] * i) % MOD) inverse.append((-inverse[MOD % i] * (MOD // i) ) % MOD) g2.append((g2[-1] * inverse[-1]) % MOD) print((comb(n - 1, k - 1, MOD)))
32
32
598
661
def cmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod mod = 10**9 + 7 # 出力の制限 N = 10**6 g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] # 逆元テーブル計算用テーブル for i in range(2, N + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) X, Y = list(map(int, input().split())) if (X + Y) % 3 != 0: print((0)) exit() n = (X + Y) // 3 k = Y - (X + Y) // 3 if k < 0 or k > n: print((0)) exit() # print("n,k:",n,k) print((cmb(n, k, mod)))
X, Y = list(map(int, input().split())) MOD = 10**9 + 7 if (X + Y) % 3 != 0: print((0)) exit() if abs(X - Y) > (X + Y) // 3: print((0)) exit() n = (X + Y) // 3 + 1 k = ((X - Y) + n + 1) // 2 SIZE = max(n, k) g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] # 逆元テーブル計算用テーブル def comb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod for i in range(2, SIZE): g1.append((g1[-1] * i) % MOD) inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD) g2.append((g2[-1] * inverse[-1]) % MOD) print((comb(n - 1, k - 1, MOD)))
false
0
[ "-def cmb(n, r, mod):", "+X, Y = list(map(int, input().split()))", "+MOD = 10**9 + 7", "+if (X + Y) % 3 != 0:", "+ print((0))", "+ exit()", "+if abs(X - Y) > (X + Y) // 3:", "+ print((0))", "+ exit()", "+n = (X + Y) // 3 + 1", "+k = ((X - Y) + n + 1) // 2", "+SIZE = max(n, k)", "+g1 = [1, 1] # 元テーブル", "+g2 = [1, 1] # 逆元テーブル", "+inverse = [0, 1] # 逆元テーブル計算用テーブル", "+", "+", "+def comb(n, r, mod):", "-mod = 10**9 + 7 # 出力の制限", "-N = 10**6", "-g1 = [1, 1] # 元テーブル", "-g2 = [1, 1] # 逆元テーブル", "-inverse = [0, 1] # 逆元テーブル計算用テーブル", "-for i in range(2, N + 1):", "- g1.append((g1[-1] * i) % mod)", "- inverse.append((-inverse[mod % i] * (mod // i)) % mod)", "- g2.append((g2[-1] * inverse[-1]) % mod)", "-X, Y = list(map(int, input().split()))", "-if (X + Y) % 3 != 0:", "- print((0))", "- exit()", "-n = (X + Y) // 3", "-k = Y - (X + Y) // 3", "-if k < 0 or k > n:", "- print((0))", "- exit()", "-# print(\"n,k:\",n,k)", "-print((cmb(n, k, mod)))", "+for i in range(2, SIZE):", "+ g1.append((g1[-1] * i) % MOD)", "+ inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)", "+ g2.append((g2[-1] * inverse[-1]) % MOD)", "+print((comb(n - 1, k - 1, MOD)))" ]
false
3.260735
0.340239
9.583656
[ "s782629493", "s107812686" ]
u421502518
p03470
python
s689270111
s950580047
47
17
3,060
3,060
Accepted
Accepted
63.83
n = int(eval(input())) d = [] for i in range(n): d.append(int(eval(input()))) d = sorted(d) answer = 1 for i in range(1, n): if d[i-1] != d[i]: answer += 1 print(answer)
n = int(eval(input())) d = [] for i in range(n): d.append(int(eval(input()))) d.sort() answer = 1 for i in range(1, n): if d[i-1] != d[i]: answer += 1 print(answer)
10
10
170
165
n = int(eval(input())) d = [] for i in range(n): d.append(int(eval(input()))) d = sorted(d) answer = 1 for i in range(1, n): if d[i - 1] != d[i]: answer += 1 print(answer)
n = int(eval(input())) d = [] for i in range(n): d.append(int(eval(input()))) d.sort() answer = 1 for i in range(1, n): if d[i - 1] != d[i]: answer += 1 print(answer)
false
0
[ "-d = sorted(d)", "+d.sort()" ]
false
0.049598
0.036697
1.351547
[ "s689270111", "s950580047" ]
u943057856
p02813
python
s099504170
s424441793
52
40
14,152
14,196
Accepted
Accepted
23.08
from itertools import permutations n=int(eval(input())) p=list(map(int,input().split())) q=list(map(int,input().split())) c=sorted(list(permutations(list(range(1,n+1))))) a,b,=0,0 for i,c in enumerate(c): if p==list(c): a=i if q==list(c): b=i print((abs(a-b)))
from itertools import permutations n=int(eval(input())) p=tuple(map(int,input().split())) q=tuple(map(int,input().split())) P=sorted(list(permutations(list(range(1,n+1)),n))) print((abs(P.index(p)-P.index(q))))
12
6
281
201
from itertools import permutations n = int(eval(input())) p = list(map(int, input().split())) q = list(map(int, input().split())) c = sorted(list(permutations(list(range(1, n + 1))))) a, b, = ( 0, 0, ) for i, c in enumerate(c): if p == list(c): a = i if q == list(c): b = i print((abs(a - b)))
from itertools import permutations n = int(eval(input())) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) P = sorted(list(permutations(list(range(1, n + 1)), n))) print((abs(P.index(p) - P.index(q))))
false
50
[ "-p = list(map(int, input().split()))", "-q = list(map(int, input().split()))", "-c = sorted(list(permutations(list(range(1, n + 1)))))", "-a, b, = (", "- 0,", "- 0,", "-)", "-for i, c in enumerate(c):", "- if p == list(c):", "- a = i", "- if q == list(c):", "- b = i", "-print((abs(a - b)))", "+p = tuple(map(int, input().split()))", "+q = tuple(map(int, input().split()))", "+P = sorted(list(permutations(list(range(1, n + 1)), n)))", "+print((abs(P.index(p) - P.index(q))))" ]
false
0.043878
0.04178
1.050206
[ "s099504170", "s424441793" ]
u118211443
p02912
python
s867730665
s223743904
186
163
15,300
14,536
Accepted
Accepted
12.37
import heapq import math n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list([x * (-1) for x in a]) heapq.heapify(b) for i in range(m): h = heapq.heappop(b) heapq.heappush(b, math.ceil(h / 2)) c = list([x * (-1) for x in b]) print((sum(c)))
import heapq import math n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list([x * (-1) for x in a]) heapq.heapify(b) for i in range(m): h = heapq.heappop(b) heapq.heappush(b, math.ceil(h / 2)) print((sum(b)*(-1)))
15
12
301
263
import heapq import math n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list([x * (-1) for x in a]) heapq.heapify(b) for i in range(m): h = heapq.heappop(b) heapq.heappush(b, math.ceil(h / 2)) c = list([x * (-1) for x in b]) print((sum(c)))
import heapq import math n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list([x * (-1) for x in a]) heapq.heapify(b) for i in range(m): h = heapq.heappop(b) heapq.heappush(b, math.ceil(h / 2)) print((sum(b) * (-1)))
false
20
[ "-c = list([x * (-1) for x in b])", "-print((sum(c)))", "+print((sum(b) * (-1)))" ]
false
0.051561
0.052006
0.991438
[ "s867730665", "s223743904" ]
u309289733
p04000
python
s635261947
s967274611
1,955
1,759
152,092
152,100
Accepted
Accepted
10.03
from collections import Counter, defaultdict h, w, n = list(map(int, input().split())) hs, ws = h - 2, w - 2 dd = defaultdict(int) for a, b in (list(map(int, input().split())) for _ in range(n)): for y in range(max(0, a - 3), min(a, hs)): for x in range(max(0, b - 3), min(b, ws)): dd[(y, x)] += 1 print((hs * ws - len(dd))) c = Counter(list(dd.values())) for i in range(1, 10): print((c[i] if i in c else 0))
from collections import Counter, defaultdict h, w, n = list(map(int, input().split())) blacks = defaultdict(int) for a, b in (list(map(int, input().split())) for _ in range(n)): for y in range(max(0, a - 3), min(a, (h - 2))): for x in range(max(0, b - 3), min(b, (w - 2))): blacks[(y, x)] += 1 print(((h - 2) * (w - 2) - len(blacks))) c = Counter(list(blacks.values())) for i in range(1, 10): print((c[i] if i in c else 0))
16
15
435
448
from collections import Counter, defaultdict h, w, n = list(map(int, input().split())) hs, ws = h - 2, w - 2 dd = defaultdict(int) for a, b in (list(map(int, input().split())) for _ in range(n)): for y in range(max(0, a - 3), min(a, hs)): for x in range(max(0, b - 3), min(b, ws)): dd[(y, x)] += 1 print((hs * ws - len(dd))) c = Counter(list(dd.values())) for i in range(1, 10): print((c[i] if i in c else 0))
from collections import Counter, defaultdict h, w, n = list(map(int, input().split())) blacks = defaultdict(int) for a, b in (list(map(int, input().split())) for _ in range(n)): for y in range(max(0, a - 3), min(a, (h - 2))): for x in range(max(0, b - 3), min(b, (w - 2))): blacks[(y, x)] += 1 print(((h - 2) * (w - 2) - len(blacks))) c = Counter(list(blacks.values())) for i in range(1, 10): print((c[i] if i in c else 0))
false
6.25
[ "-hs, ws = h - 2, w - 2", "-dd = defaultdict(int)", "+blacks = defaultdict(int)", "- for y in range(max(0, a - 3), min(a, hs)):", "- for x in range(max(0, b - 3), min(b, ws)):", "- dd[(y, x)] += 1", "-print((hs * ws - len(dd)))", "-c = Counter(list(dd.values()))", "+ for y in range(max(0, a - 3), min(a, (h - 2))):", "+ for x in range(max(0, b - 3), min(b, (w - 2))):", "+ blacks[(y, x)] += 1", "+print(((h - 2) * (w - 2) - len(blacks)))", "+c = Counter(list(blacks.values()))" ]
false
0.04162
0.036806
1.130788
[ "s635261947", "s967274611" ]
u585482323
p03493
python
s647650804
s292402140
195
166
39,408
38,512
Accepted
Accepted
14.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(): n,a,b = LI() print((min(n*a,b))) return #B def B(): s = S() print((s.count("1"))) return #C def C(): return #D def D(): return #E def E(): return #F def F(): return #G def G(): return #H def H(): return #I def I_(): return #J def J(): return #Solve if __name__ == "__main__": B()
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from itertools import permutations import sys import math import bisect 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(): s = eval(input()) print((s.count("1"))) return #Solve if __name__ == "__main__": solve()
78
35
1,237
834
#!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(): n, a, b = LI() print((min(n * a, b))) return # B def B(): s = S() print((s.count("1"))) return # C def C(): return # D def D(): return # E def E(): return # F def F(): return # G def G(): return # H def H(): return # I def I_(): return # J def J(): return # Solve if __name__ == "__main__": B()
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations import sys import math import bisect 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(): s = eval(input()) print((s.count("1"))) return # Solve if __name__ == "__main__": solve()
false
55.128205
[ "-from collections import defaultdict", "-from collections import deque", "+from collections import defaultdict, deque", "+from itertools import permutations", "-import random", "- 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():", "- n, a, b = LI()", "- print((min(n * a, b)))", "- return", "-# B", "-def B():", "- s = S()", "+def solve():", "+ s = eval(input())", "- return", "-", "-", "-# C", "-def C():", "- return", "-", "-", "-# D", "-def D():", "- return", "-", "-", "-# E", "-def E():", "- return", "-", "-", "-# F", "-def F():", "- return", "-", "-", "-# G", "-def G():", "- return", "-", "-", "-# H", "-def H():", "- return", "-", "-", "-# I", "-def I_():", "- return", "-", "-", "-# J", "-def J():", "- B()", "+ solve()" ]
false
0.127574
0.008423
15.14591
[ "s647650804", "s292402140" ]
u426108351
p03161
python
s822386966
s854316844
386
351
56,544
52,448
Accepted
Accepted
9.07
N, K = list(map(int, input().split())) h = list(map(int, input().split())) dp = [1000000001 for i in range(N)] dp[0] = 0 for i in range(N): for j in range(1, K+1): if i+j <= N-1: dp[i+j] = min(dp[i] + abs(h[i+j] - h[i]), dp[i+j]) print((dp[N-1]))
N, K = list(map(int, input().split())) h = list(map(int, input().split())) dp = [10000000000]*(N+100) dp[0] = 0 for i in range(N): for j in range(1, K+1): if i + j <= N-1: dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i])) print((dp[N-1]))
10
10
273
266
N, K = list(map(int, input().split())) h = list(map(int, input().split())) dp = [1000000001 for i in range(N)] dp[0] = 0 for i in range(N): for j in range(1, K + 1): if i + j <= N - 1: dp[i + j] = min(dp[i] + abs(h[i + j] - h[i]), dp[i + j]) print((dp[N - 1]))
N, K = list(map(int, input().split())) h = list(map(int, input().split())) dp = [10000000000] * (N + 100) dp[0] = 0 for i in range(N): for j in range(1, K + 1): if i + j <= N - 1: dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i])) print((dp[N - 1]))
false
0
[ "-dp = [1000000001 for i in range(N)]", "+dp = [10000000000] * (N + 100)", "- dp[i + j] = min(dp[i] + abs(h[i + j] - h[i]), dp[i + j])", "+ dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))" ]
false
0.041554
0.09762
0.425671
[ "s822386966", "s854316844" ]
u543954314
p02722
python
s147413768
s326890080
647
211
43,996
3,316
Accepted
Accepted
67.39
import sys stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: list(map(int, stdin.readline().split())) nl = lambda: list(map(int, stdin.readline().split())) def divisor(n): ass = [] for i in range(1, int(n**0.5)+1): if n%i == 0: ass.append(i) ass.append(n//i) return ass n = ni() p = divisor(n) s = set() for k in p: nk = n // k for t in divisor(nk - 1): s.add(t*k) ans = 0 s.remove(1) s.add(n) for t in s: m = n while m % t == 0: m //= t if m % t == 1: ans += 1 print(ans)
import sys stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: list(map(int, stdin.readline().split())) nl = lambda: list(map(int, stdin.readline().split())) def divisor(n): ass = [] for i in range(1, int(n**0.5)+1): if n%i == 0: ass.append(i) ass.append(n//i) return ass n = ni() p = divisor(n) q = divisor(n-1) s = set() ans = 0 for x in p + q: m = n if x == 1: continue while m % x == 0: m //= x if m % x == 1: s.add(x) print((len(s)))
34
30
656
585
import sys stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: list(map(int, stdin.readline().split())) nl = lambda: list(map(int, stdin.readline().split())) def divisor(n): ass = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: ass.append(i) ass.append(n // i) return ass n = ni() p = divisor(n) s = set() for k in p: nk = n // k for t in divisor(nk - 1): s.add(t * k) ans = 0 s.remove(1) s.add(n) for t in s: m = n while m % t == 0: m //= t if m % t == 1: ans += 1 print(ans)
import sys stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: list(map(int, stdin.readline().split())) nl = lambda: list(map(int, stdin.readline().split())) def divisor(n): ass = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: ass.append(i) ass.append(n // i) return ass n = ni() p = divisor(n) q = divisor(n - 1) s = set() ans = 0 for x in p + q: m = n if x == 1: continue while m % x == 0: m //= x if m % x == 1: s.add(x) print((len(s)))
false
11.764706
[ "+q = divisor(n - 1)", "-for k in p:", "- nk = n // k", "- for t in divisor(nk - 1):", "- s.add(t * k)", "-s.remove(1)", "-s.add(n)", "-for t in s:", "+for x in p + q:", "- while m % t == 0:", "- m //= t", "- if m % t == 1:", "- ans += 1", "-print(ans)", "+ if x == 1:", "+ continue", "+ while m % x == 0:", "+ m //= x", "+ if m % x == 1:", "+ s.add(x)", "+print((len(s)))" ]
false
0.167427
0.058772
2.848736
[ "s147413768", "s326890080" ]
u785578220
p03045
python
s008525897
s118944329
621
472
16,784
12,780
Accepted
Accepted
23.99
class UnionFind: def __init__(self, n): self.par = [i for i in range(n+1)] self.rank = [0] * (n+1) def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same_check(self, x, y): return self.find(x) == self.find(y) n,m=list(map(int,input().split())) uni = UnionFind(n-1) for i in range(m): a,b,c=list(map(int,input().split())) a-=1 b-=1 uni.union(a,b) t = set([]) for i in range(n): p = uni.find(i) t.add(p) print((len(t)))
def main(): #Union Find #locate x def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) return par[x] #merge x y def unite(x,y): x = find(x) y = find(y) if x == y: return False else: #sizeの大きいほうがx if par[x] > par[y]: x,y = y,x par[x] += par[y] par[y] = x return True #x and y in same group def same(x,y): return find(x) == find(y) #number of factor of x group def size(x): return -par[find(x)] n,m = list(map(int,input().split())) #initiarize #根なら-size,子なら親の頂点 par = [-1]*n for i in range(m): X,Y,Z = list(map(int,input().split())) unite(X-1,Y-1) tank = set([]) for i in range(n): tank.add(find(i)) print((len(tank))) if __name__ == '__main__': main()
37
46
886
991
class UnionFind: def __init__(self, n): self.par = [i for i in range(n + 1)] self.rank = [0] * (n + 1) def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same_check(self, x, y): return self.find(x) == self.find(y) n, m = list(map(int, input().split())) uni = UnionFind(n - 1) for i in range(m): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 uni.union(a, b) t = set([]) for i in range(n): p = uni.find(i) t.add(p) print((len(t)))
def main(): # Union Find # locate x def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) return par[x] # merge x y def unite(x, y): x = find(x) y = find(y) if x == y: return False else: # sizeの大きいほうがx if par[x] > par[y]: x, y = y, x par[x] += par[y] par[y] = x return True # x and y in same group def same(x, y): return find(x) == find(y) # number of factor of x group def size(x): return -par[find(x)] n, m = list(map(int, input().split())) # initiarize # 根なら-size,子なら親の頂点 par = [-1] * n for i in range(m): X, Y, Z = list(map(int, input().split())) unite(X - 1, Y - 1) tank = set([]) for i in range(n): tank.add(find(i)) print((len(tank))) if __name__ == "__main__": main()
false
19.565217
[ "-class UnionFind:", "- def __init__(self, n):", "- self.par = [i for i in range(n + 1)]", "- self.rank = [0] * (n + 1)", "-", "- def find(self, x):", "- if self.par[x] == x:", "+def main():", "+ # Union Find", "+ # locate x", "+ def find(x):", "+ if par[x] < 0:", "- self.par[x] = self.find(self.par[x])", "- return self.par[x]", "+ par[x] = find(par[x])", "+ return par[x]", "- def union(self, x, y):", "- x = self.find(x)", "- y = self.find(y)", "- if self.rank[x] < self.rank[y]:", "- self.par[x] = y", "+ # merge x y", "+ def unite(x, y):", "+ x = find(x)", "+ y = find(y)", "+ if x == y:", "+ return False", "- self.par[y] = x", "- if self.rank[x] == self.rank[y]:", "- self.rank[x] += 1", "+ # sizeの大きいほうがx", "+ if par[x] > par[y]:", "+ x, y = y, x", "+ par[x] += par[y]", "+ par[y] = x", "+ return True", "- def same_check(self, x, y):", "- return self.find(x) == self.find(y)", "+ # x and y in same group", "+ def same(x, y):", "+ return find(x) == find(y)", "+", "+ # number of factor of x group", "+ def size(x):", "+ return -par[find(x)]", "+", "+ n, m = list(map(int, input().split()))", "+ # initiarize", "+ # 根なら-size,子なら親の頂点", "+ par = [-1] * n", "+ for i in range(m):", "+ X, Y, Z = list(map(int, input().split()))", "+ unite(X - 1, Y - 1)", "+ tank = set([])", "+ for i in range(n):", "+ tank.add(find(i))", "+ print((len(tank)))", "-n, m = list(map(int, input().split()))", "-uni = UnionFind(n - 1)", "-for i in range(m):", "- a, b, c = list(map(int, input().split()))", "- a -= 1", "- b -= 1", "- uni.union(a, b)", "-t = set([])", "-for i in range(n):", "- p = uni.find(i)", "- t.add(p)", "-print((len(t)))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.047038
0.05348
0.87955
[ "s008525897", "s118944329" ]
u015593272
p02583
python
s025090587
s430462499
842
465
108,204
91,748
Accepted
Accepted
44.77
import numpy as np from numba import * N = int(eval(input())) length = np.array(input().split(), np.int64) length = np.sort(length) @njit def calc(length): cnt = 0 for i in range(N): for j in range(i + 1, N): for k in range(j + 1, N): l1, l2, l3 = length[i], length[j], length[k] if (l1 != l2 and l1 != l3 and l2 != l3): if (l1 + l2 > l3): cnt += 1 return (cnt) ans = calc(length) print(ans)
import numpy as np from numba import * N = int(eval(input())) length = np.array(input().split(), np.int64) length = np.sort(length) def calc(length): cnt = 0 for i in range(N): for j in range(i + 1, N): for k in range(j + 1, N): l1, l2, l3 = length[i], length[j], length[k] if (l1 != l2 and l1 != l3 and l2 != l3): if (l1 + l2 > l3): cnt += 1 return (cnt) ans = calc(length) print(ans)
26
26
535
530
import numpy as np from numba import * N = int(eval(input())) length = np.array(input().split(), np.int64) length = np.sort(length) @njit def calc(length): cnt = 0 for i in range(N): for j in range(i + 1, N): for k in range(j + 1, N): l1, l2, l3 = length[i], length[j], length[k] if l1 != l2 and l1 != l3 and l2 != l3: if l1 + l2 > l3: cnt += 1 return cnt ans = calc(length) print(ans)
import numpy as np from numba import * N = int(eval(input())) length = np.array(input().split(), np.int64) length = np.sort(length) def calc(length): cnt = 0 for i in range(N): for j in range(i + 1, N): for k in range(j + 1, N): l1, l2, l3 = length[i], length[j], length[k] if l1 != l2 and l1 != l3 and l2 != l3: if l1 + l2 > l3: cnt += 1 return cnt ans = calc(length) print(ans)
false
0
[ "-@njit" ]
false
0.228535
0.303041
0.754137
[ "s025090587", "s430462499" ]
u458530128
p02315
python
s586321153
s765436866
990
630
25,944
5,932
Accepted
Accepted
36.36
N, W = list(map(int, input().split())) items = [[0, 0]] for _ in range(N): v, w = list(map(int, input().split())) items.append([v, w]) DP = [[0 for _ in range(W + 1)] for _ in range(N + 1)] for i in range(1, N + 1): for j in range(W + 1): if items[i][1] > j: DP[i][j] = DP[i - 1][j] else: DP[i][j] = max(DP[i - 1][j], DP[i - 1][j - items[i][1]] + items[i][0]) print((DP[N][W]))
N, W = list(map(int, input().split())) items = [[0, 0]] for _ in range(N): v, w = list(map(int, input().split())) items.append([v, w]) ''' DP = [[0 for _ in range(W + 1)] for _ in range(N + 1)] for i in range(1, N + 1): for j in range(W + 1): if items[i][1] > j: DP[i][j] = DP[i - 1][j] else: DP[i][j] = max(DP[i - 1][j], DP[i - 1][j - items[i][1]] + items[i][0]) print(DP[N][W]) ''' DP2 = [0 for _ in range(W + 1)] for i in range(1, N + 1): for j in range(W, items[i][1] - 1, -1): DP2[j] = max(DP2[j], DP2[j - items[i][1]] + items[i][0]) print((DP2[W]))
14
21
442
642
N, W = list(map(int, input().split())) items = [[0, 0]] for _ in range(N): v, w = list(map(int, input().split())) items.append([v, w]) DP = [[0 for _ in range(W + 1)] for _ in range(N + 1)] for i in range(1, N + 1): for j in range(W + 1): if items[i][1] > j: DP[i][j] = DP[i - 1][j] else: DP[i][j] = max(DP[i - 1][j], DP[i - 1][j - items[i][1]] + items[i][0]) print((DP[N][W]))
N, W = list(map(int, input().split())) items = [[0, 0]] for _ in range(N): v, w = list(map(int, input().split())) items.append([v, w]) """ DP = [[0 for _ in range(W + 1)] for _ in range(N + 1)] for i in range(1, N + 1): for j in range(W + 1): if items[i][1] > j: DP[i][j] = DP[i - 1][j] else: DP[i][j] = max(DP[i - 1][j], DP[i - 1][j - items[i][1]] + items[i][0]) print(DP[N][W]) """ DP2 = [0 for _ in range(W + 1)] for i in range(1, N + 1): for j in range(W, items[i][1] - 1, -1): DP2[j] = max(DP2[j], DP2[j - items[i][1]] + items[i][0]) print((DP2[W]))
false
33.333333
[ "+\"\"\"", "-print((DP[N][W]))", "+print(DP[N][W])", "+\"\"\"", "+DP2 = [0 for _ in range(W + 1)]", "+for i in range(1, N + 1):", "+ for j in range(W, items[i][1] - 1, -1):", "+ DP2[j] = max(DP2[j], DP2[j - items[i][1]] + items[i][0])", "+print((DP2[W]))" ]
false
0.045741
0.106579
0.429177
[ "s586321153", "s765436866" ]
u294485299
p02689
python
s679874537
s498362433
486
339
31,952
98,148
Accepted
Accepted
30.25
n, m = list(map(int, input().split())) ans= 0 rs = [] hs = list(map(int, input().split())) ds = {} ok = True for i in range(m): a,b = list(map(int, input().split())) if(a in ds): ds[a].append(b) if(b in ds): ds[b].append(a) if(a not in ds): ds[a] = [b] if(b not in ds): ds[b] = [a] for i in range(1, n+1): if(i not in ds): ans +=1 else: for l in ds[i]: if(hs[i-1] <= hs[l-1]): ok = False if(ok): ans +=1 ok = True print(ans)
n, m = list(map(int, input().split())) ans= 0 hs = list(map(int, input().split())) ds = {} ok = True for i in range(m): a,b = list(map(int, input().split())) if(a in ds): ds[a].append(b) if(b in ds): ds[b].append(a) if(a not in ds): ds[a] = [b] if(b not in ds): ds[b] = [a] for i in range(1, n+1): if(i not in ds): ans +=1 else: for l in ds[i]: if(hs[i-1] <= hs[l-1]): ok = False if(ok): ans +=1 ok = True print(ans)
27
26
570
562
n, m = list(map(int, input().split())) ans = 0 rs = [] hs = list(map(int, input().split())) ds = {} ok = True for i in range(m): a, b = list(map(int, input().split())) if a in ds: ds[a].append(b) if b in ds: ds[b].append(a) if a not in ds: ds[a] = [b] if b not in ds: ds[b] = [a] for i in range(1, n + 1): if i not in ds: ans += 1 else: for l in ds[i]: if hs[i - 1] <= hs[l - 1]: ok = False if ok: ans += 1 ok = True print(ans)
n, m = list(map(int, input().split())) ans = 0 hs = list(map(int, input().split())) ds = {} ok = True for i in range(m): a, b = list(map(int, input().split())) if a in ds: ds[a].append(b) if b in ds: ds[b].append(a) if a not in ds: ds[a] = [b] if b not in ds: ds[b] = [a] for i in range(1, n + 1): if i not in ds: ans += 1 else: for l in ds[i]: if hs[i - 1] <= hs[l - 1]: ok = False if ok: ans += 1 ok = True print(ans)
false
3.703704
[ "-rs = []" ]
false
0.041806
0.075408
0.554396
[ "s679874537", "s498362433" ]
u604774382
p02398
python
s024484955
s677850684
40
30
6,728
6,724
Accepted
Accepted
25
import sys a, b, c = [ int( val ) for val in sys.stdin.readline().split( ' ' ) ] cnt = 0 i = a while i <= b: if ( c % i ) == 0: cnt += 1 i += 1 print(( "{}".format( cnt ) ))
import sys a, b, c = [ int( val ) for val in sys.stdin.readline().split( ' ' ) ] cnt = 0 for divisor in range( a, b+1 ): if ( c % divisor ) == 0: cnt += 1 print(( "{}".format( cnt ) ))
10
8
185
202
import sys a, b, c = [int(val) for val in sys.stdin.readline().split(" ")] cnt = 0 i = a while i <= b: if (c % i) == 0: cnt += 1 i += 1 print(("{}".format(cnt)))
import sys a, b, c = [int(val) for val in sys.stdin.readline().split(" ")] cnt = 0 for divisor in range(a, b + 1): if (c % divisor) == 0: cnt += 1 print(("{}".format(cnt)))
false
20
[ "-i = a", "-while i <= b:", "- if (c % i) == 0:", "+for divisor in range(a, b + 1):", "+ if (c % divisor) == 0:", "- i += 1" ]
false
0.046242
0.037575
1.230642
[ "s024484955", "s677850684" ]
u254871849
p03401
python
s768854517
s838491662
487
203
22,976
14,188
Accepted
Accepted
58.32
import sys import numpy as np n, *a = map(int, sys.stdin.read().split()) a = np.array([0] + a + [0]) def main(): res1 = np.absolute(a[2:] - a[1:-1]) + np.absolute(a[1:-1] - a[:-2]) res2 = np.absolute(a[2:] - a[:-2]) default = np.absolute(a[1:] - a[:-1]).sum() ans = default - (res1 - res2) return ans if __name__ == '__main__': ans = main() print(*ans, sep='\n')
import sys n, *a = list(map(int, sys.stdin.read().split())) a = [0] + a + [0] def main(): s = sum([abs(a[i+1] - a[i]) for i in range(n + 1)]) for i in range(1, n + 1): if a[i-1] <= a[i] <= a[i+1]: res = s elif a[i-1] >= a[i] >= a[i+1]: res = s else: res = s - 2 * min(abs(a[i] - a[i-1]), abs(a[i+1] - a[i])) print(res) if __name__ == '__main__': main()
17
15
415
420
import sys import numpy as np n, *a = map(int, sys.stdin.read().split()) a = np.array([0] + a + [0]) def main(): res1 = np.absolute(a[2:] - a[1:-1]) + np.absolute(a[1:-1] - a[:-2]) res2 = np.absolute(a[2:] - a[:-2]) default = np.absolute(a[1:] - a[:-1]).sum() ans = default - (res1 - res2) return ans if __name__ == "__main__": ans = main() print(*ans, sep="\n")
import sys n, *a = list(map(int, sys.stdin.read().split())) a = [0] + a + [0] def main(): s = sum([abs(a[i + 1] - a[i]) for i in range(n + 1)]) for i in range(1, n + 1): if a[i - 1] <= a[i] <= a[i + 1]: res = s elif a[i - 1] >= a[i] >= a[i + 1]: res = s else: res = s - 2 * min(abs(a[i] - a[i - 1]), abs(a[i + 1] - a[i])) print(res) if __name__ == "__main__": main()
false
11.764706
[ "-import numpy as np", "-n, *a = map(int, sys.stdin.read().split())", "-a = np.array([0] + a + [0])", "+n, *a = list(map(int, sys.stdin.read().split()))", "+a = [0] + a + [0]", "- res1 = np.absolute(a[2:] - a[1:-1]) + np.absolute(a[1:-1] - a[:-2])", "- res2 = np.absolute(a[2:] - a[:-2])", "- default = np.absolute(a[1:] - a[:-1]).sum()", "- ans = default - (res1 - res2)", "- return ans", "+ s = sum([abs(a[i + 1] - a[i]) for i in range(n + 1)])", "+ for i in range(1, n + 1):", "+ if a[i - 1] <= a[i] <= a[i + 1]:", "+ res = s", "+ elif a[i - 1] >= a[i] >= a[i + 1]:", "+ res = s", "+ else:", "+ res = s - 2 * min(abs(a[i] - a[i - 1]), abs(a[i + 1] - a[i]))", "+ print(res)", "- ans = main()", "- print(*ans, sep=\"\\n\")", "+ main()" ]
false
0.734914
0.03828
19.198259
[ "s768854517", "s838491662" ]
u086503932
p02678
python
s942677697
s803536275
535
486
35,764
98,372
Accepted
Accepted
9.16
#!/usr/bin/env python3 from collections import deque def main(): N, M = map(int, input().split()) adj = [[] for _ in range(N)] for i in range(M): a, b = map(int, input().split()) adj[a-1].append(b-1) adj[b-1].append(a-1) queue = deque([0]) visit = [-1] * N visit[0] = 0# 部屋1の親はないので while queue: now = queue.popleft() for u in adj[now]: if visit[u] < 0: queue.append(u) visit[u] = now if -1 in visit: print('No') else: print('Yes') [print(v+1) for v in visit[1:]] if __name__ == "__main__": main()
N, M = list(map(int, input().split())) adj = [[] for _ in range(N)] for _ in range(M): A, B = [int(x)-1 for x in input().split()] adj[A].append(B) adj[B].append(A) from collections import deque queue = deque([0]) visit = [-1] * N visit[0] = 1 while queue: now = queue.popleft() for u in adj[now]: if visit[u] < 0: queue.append(u) visit[u] = visit[now] + 1 print('Yes') for i in range(1,N): for u in adj[i]: if visit[u] == visit[i]-1: print((u+1)) break
29
26
677
566
#!/usr/bin/env python3 from collections import deque def main(): N, M = map(int, input().split()) adj = [[] for _ in range(N)] for i in range(M): a, b = map(int, input().split()) adj[a - 1].append(b - 1) adj[b - 1].append(a - 1) queue = deque([0]) visit = [-1] * N visit[0] = 0 # 部屋1の親はないので while queue: now = queue.popleft() for u in adj[now]: if visit[u] < 0: queue.append(u) visit[u] = now if -1 in visit: print("No") else: print("Yes") [print(v + 1) for v in visit[1:]] if __name__ == "__main__": main()
N, M = list(map(int, input().split())) adj = [[] for _ in range(N)] for _ in range(M): A, B = [int(x) - 1 for x in input().split()] adj[A].append(B) adj[B].append(A) from collections import deque queue = deque([0]) visit = [-1] * N visit[0] = 1 while queue: now = queue.popleft() for u in adj[now]: if visit[u] < 0: queue.append(u) visit[u] = visit[now] + 1 print("Yes") for i in range(1, N): for u in adj[i]: if visit[u] == visit[i] - 1: print((u + 1)) break
false
10.344828
[ "-#!/usr/bin/env python3", "+N, M = list(map(int, input().split()))", "+adj = [[] for _ in range(N)]", "+for _ in range(M):", "+ A, B = [int(x) - 1 for x in input().split()]", "+ adj[A].append(B)", "+ adj[B].append(A)", "-", "-def main():", "- N, M = map(int, input().split())", "- adj = [[] for _ in range(N)]", "- for i in range(M):", "- a, b = map(int, input().split())", "- adj[a - 1].append(b - 1)", "- adj[b - 1].append(a - 1)", "- queue = deque([0])", "- visit = [-1] * N", "- visit[0] = 0 # 部屋1の親はないので", "- while queue:", "- now = queue.popleft()", "- for u in adj[now]:", "- if visit[u] < 0:", "- queue.append(u)", "- visit[u] = now", "- if -1 in visit:", "- print(\"No\")", "- else:", "- print(\"Yes\")", "- [print(v + 1) for v in visit[1:]]", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+queue = deque([0])", "+visit = [-1] * N", "+visit[0] = 1", "+while queue:", "+ now = queue.popleft()", "+ for u in adj[now]:", "+ if visit[u] < 0:", "+ queue.append(u)", "+ visit[u] = visit[now] + 1", "+print(\"Yes\")", "+for i in range(1, N):", "+ for u in adj[i]:", "+ if visit[u] == visit[i] - 1:", "+ print((u + 1))", "+ break" ]
false
0.0071
0.039102
0.181571
[ "s942677697", "s803536275" ]
u620084012
p03330
python
s113322422
s994551560
660
519
5,492
11,592
Accepted
Accepted
21.36
N, C = list(map(int, input().split())) D = [list(map(int, input().split())) for k in range(C)] G = [list(map(int, input().split())) for k in range(N)] M = [[0,0,0] for k in range(C)] for x in range(N): for y in range(N): M[G[x][y]-1][(x+y)%3] += 1 ans = 10**9 for p in range(C): for q in range(C): for r in range(C): if p!=q and q!=r and r!=p: t = 0 for s in range(C): t += D[s][p]*M[s][0]+ D[s][q]*M[s][1] + D[s][r]*M[s][2] ans = min(t,ans) print(ans)
N, C = list(map(int,input().split())) D = [list(map(int,input().split())) for _ in range(C)] G = [list(map(int,input().split())) for _ in range(N)] Z = [0]*C O = [0]*C T = [0]*C for x in range(N): for y in range(N): if (x+y)%3 == 0: Z[G[x][y]-1] += 1 elif (x+y)%3 == 1: O[G[x][y]-1] += 1 else: T[G[x][y]-1] += 1 ans = 10**9 for c1 in range(C): for c2 in range(C): for c3 in range(C): if c1 == c2 or c2 == c3 or c3 == c1: continue temp = 0 for k in range(C): temp += Z[k]*D[k][c1] for k in range(C): temp += O[k]*D[k][c2] for k in range(C): temp += T[k]*D[k][c3] ans = min(ans,temp) print(ans)
20
31
572
831
N, C = list(map(int, input().split())) D = [list(map(int, input().split())) for k in range(C)] G = [list(map(int, input().split())) for k in range(N)] M = [[0, 0, 0] for k in range(C)] for x in range(N): for y in range(N): M[G[x][y] - 1][(x + y) % 3] += 1 ans = 10**9 for p in range(C): for q in range(C): for r in range(C): if p != q and q != r and r != p: t = 0 for s in range(C): t += D[s][p] * M[s][0] + D[s][q] * M[s][1] + D[s][r] * M[s][2] ans = min(t, ans) print(ans)
N, C = list(map(int, input().split())) D = [list(map(int, input().split())) for _ in range(C)] G = [list(map(int, input().split())) for _ in range(N)] Z = [0] * C O = [0] * C T = [0] * C for x in range(N): for y in range(N): if (x + y) % 3 == 0: Z[G[x][y] - 1] += 1 elif (x + y) % 3 == 1: O[G[x][y] - 1] += 1 else: T[G[x][y] - 1] += 1 ans = 10**9 for c1 in range(C): for c2 in range(C): for c3 in range(C): if c1 == c2 or c2 == c3 or c3 == c1: continue temp = 0 for k in range(C): temp += Z[k] * D[k][c1] for k in range(C): temp += O[k] * D[k][c2] for k in range(C): temp += T[k] * D[k][c3] ans = min(ans, temp) print(ans)
false
35.483871
[ "-D = [list(map(int, input().split())) for k in range(C)]", "-G = [list(map(int, input().split())) for k in range(N)]", "-M = [[0, 0, 0] for k in range(C)]", "+D = [list(map(int, input().split())) for _ in range(C)]", "+G = [list(map(int, input().split())) for _ in range(N)]", "+Z = [0] * C", "+O = [0] * C", "+T = [0] * C", "- M[G[x][y] - 1][(x + y) % 3] += 1", "+ if (x + y) % 3 == 0:", "+ Z[G[x][y] - 1] += 1", "+ elif (x + y) % 3 == 1:", "+ O[G[x][y] - 1] += 1", "+ else:", "+ T[G[x][y] - 1] += 1", "-for p in range(C):", "- for q in range(C):", "- for r in range(C):", "- if p != q and q != r and r != p:", "- t = 0", "- for s in range(C):", "- t += D[s][p] * M[s][0] + D[s][q] * M[s][1] + D[s][r] * M[s][2]", "- ans = min(t, ans)", "+for c1 in range(C):", "+ for c2 in range(C):", "+ for c3 in range(C):", "+ if c1 == c2 or c2 == c3 or c3 == c1:", "+ continue", "+ temp = 0", "+ for k in range(C):", "+ temp += Z[k] * D[k][c1]", "+ for k in range(C):", "+ temp += O[k] * D[k][c2]", "+ for k in range(C):", "+ temp += T[k] * D[k][c3]", "+ ans = min(ans, temp)" ]
false
0.046183
0.129093
0.357748
[ "s113322422", "s994551560" ]
u562935282
p03157
python
s071466057
s702703757
1,819
573
9,108
148,212
Accepted
Accepted
68.5
class UnionFind: def __init__(self, n): self.v = [-1 for _ in range(n)] # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed) self.bk = [1 if s[r][c] == '#' else 0 for r in range(H) for c in range(W)] self.wt = [1 if s[r][c] == '.' else 0 for r in range(H) for c in range(W)] def find(self, x): # xを含む木における根の頂点番号を返す if self.v[x] < 0: # (負)は根 return x else: # 根の頂点番号 self.v[x] = self.find(self.v[x]) # uniteでは, 旧根に属する頂点の根が旧根のままなので更新 return self.v[x] def unite(self, x, y): # 違う根に属していたらrankが低くなるように連結 x = self.find(x) y = self.find(y) if x == y: return if -self.v[x] < -self.v[y]: # size比較,  (-1) * (連結頂点数 * (-1)), (正)同士の大小比較 x, y = y, x # 連結頂点数が少ない方をyにすると, findでの更新回数が減る? self.v[x] += self.v[y] # 連結頂点数の和を取る, 連結頂点数 * (-1) self.v[y] = x # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする self.bk[x % (H * W)] += self.bk[y % (H * W)] self.wt[x % (H * W)] += self.wt[y % (H * W)] def root(self, x): return self.v[x] < 0 # (負)は根 def same(self, x, y): return self.find(x) == self.find(y) # 同じ根に属するか def size(self, x): return -self.v[self.find(x)] # 連結頂点数を返す def calc(self, x): return self.bk[x % (H * W)] * self.wt[x % (H * W)] dr = [0, 0, 1, -1] dc = [1, -1, 0, 0] H, W = list(map(int, input().split())) s = [eval(input()) for _ in range(H)] uf = UnionFind(2 * H * W) # 全頂点 * 2 for r in range(H): for c in range(W): if s[r][c] == '#': for i in range(4): nr = r + dr[i] nc = c + dc[i] if 0 <= nr < H and 0 <= nc < W: if s[nr][nc] == '.': uf.unite(r * W + c, H * W + (nr * W + nc)) # #: *1, .: * 2 else: for i in range(4): nr = r + dr[i] nc = c + dc[i] if 0 <= nr < H and 0 <= nc < W: if s[nr][nc] == '#': uf.unite(H * W + (r * W + c), nr * W + nc) # #: *1, .: * 2 ans = 0 for r in range(H): for c in range(W): if uf.root(r * W + c): # print(r, c, '#') sz = uf.size(r * W + c) # print(' ', r * W + c, sz, '#') if sz > 1: ans += uf.calc(r * W + c) if uf.root(H * W + (r * W + c)): # print(r, c, '.') sz = uf.size(H * W + (r * W + c)) # print(' ', r * W + c, sz, '.') if sz > 1: ans += uf.calc(H * W + (r * W + c)) print(ans) # print(uf.v)
# https://atcoder.jp/contests/aising2019/submissions/3986315 import sys sys.setrecursionlimit(2 * 10 ** 5) H, W = list(map(int, input().split())) s = [eval(input()) for _ in range(H)] ans = 0 dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] un_reached = [[True for i in range(W)] for j in range(H)] def dfs(x, y): un_reached[x][y] = False if s[x][y] == '#': cc[1] += 1 else: cc[0] += 1 for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0 <= nx < H and 0 <= ny < W and s[nx][ny] != s[x][y] and un_reached[nx][ny]: dfs(nx, ny) for i in range(H): for j in range(W): if un_reached[i][j]: cc = [0 for _ in range(2)] # [wt, bk] dfs(i, j) ans += cc[1] * cc[0] print(ans)
80
37
2,712
806
class UnionFind: def __init__(self, n): self.v = [-1 for _ in range(n)] # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed) self.bk = [1 if s[r][c] == "#" else 0 for r in range(H) for c in range(W)] self.wt = [1 if s[r][c] == "." else 0 for r in range(H) for c in range(W)] def find(self, x): # xを含む木における根の頂点番号を返す if self.v[x] < 0: # (負)は根 return x else: # 根の頂点番号 self.v[x] = self.find(self.v[x]) # uniteでは, 旧根に属する頂点の根が旧根のままなので更新 return self.v[x] def unite(self, x, y): # 違う根に属していたらrankが低くなるように連結 x = self.find(x) y = self.find(y) if x == y: return if -self.v[x] < -self.v[y]: # size比較,  (-1) * (連結頂点数 * (-1)), (正)同士の大小比較 x, y = y, x # 連結頂点数が少ない方をyにすると, findでの更新回数が減る? self.v[x] += self.v[y] # 連結頂点数の和を取る, 連結頂点数 * (-1) self.v[y] = x # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする self.bk[x % (H * W)] += self.bk[y % (H * W)] self.wt[x % (H * W)] += self.wt[y % (H * W)] def root(self, x): return self.v[x] < 0 # (負)は根 def same(self, x, y): return self.find(x) == self.find(y) # 同じ根に属するか def size(self, x): return -self.v[self.find(x)] # 連結頂点数を返す def calc(self, x): return self.bk[x % (H * W)] * self.wt[x % (H * W)] dr = [0, 0, 1, -1] dc = [1, -1, 0, 0] H, W = list(map(int, input().split())) s = [eval(input()) for _ in range(H)] uf = UnionFind(2 * H * W) # 全頂点 * 2 for r in range(H): for c in range(W): if s[r][c] == "#": for i in range(4): nr = r + dr[i] nc = c + dc[i] if 0 <= nr < H and 0 <= nc < W: if s[nr][nc] == ".": uf.unite(r * W + c, H * W + (nr * W + nc)) # #: *1, .: * 2 else: for i in range(4): nr = r + dr[i] nc = c + dc[i] if 0 <= nr < H and 0 <= nc < W: if s[nr][nc] == "#": uf.unite(H * W + (r * W + c), nr * W + nc) # #: *1, .: * 2 ans = 0 for r in range(H): for c in range(W): if uf.root(r * W + c): # print(r, c, '#') sz = uf.size(r * W + c) # print(' ', r * W + c, sz, '#') if sz > 1: ans += uf.calc(r * W + c) if uf.root(H * W + (r * W + c)): # print(r, c, '.') sz = uf.size(H * W + (r * W + c)) # print(' ', r * W + c, sz, '.') if sz > 1: ans += uf.calc(H * W + (r * W + c)) print(ans) # print(uf.v)
# https://atcoder.jp/contests/aising2019/submissions/3986315 import sys sys.setrecursionlimit(2 * 10**5) H, W = list(map(int, input().split())) s = [eval(input()) for _ in range(H)] ans = 0 dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] un_reached = [[True for i in range(W)] for j in range(H)] def dfs(x, y): un_reached[x][y] = False if s[x][y] == "#": cc[1] += 1 else: cc[0] += 1 for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0 <= nx < H and 0 <= ny < W and s[nx][ny] != s[x][y] and un_reached[nx][ny]: dfs(nx, ny) for i in range(H): for j in range(W): if un_reached[i][j]: cc = [0 for _ in range(2)] # [wt, bk] dfs(i, j) ans += cc[1] * cc[0] print(ans)
false
53.75
[ "-class UnionFind:", "- def __init__(self, n):", "- self.v = [-1 for _ in range(n)] # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed)", "- self.bk = [1 if s[r][c] == \"#\" else 0 for r in range(H) for c in range(W)]", "- self.wt = [1 if s[r][c] == \".\" else 0 for r in range(H) for c in range(W)]", "+# https://atcoder.jp/contests/aising2019/submissions/3986315", "+import sys", "- def find(self, x): # xを含む木における根の頂点番号を返す", "- if self.v[x] < 0: # (負)は根", "- return x", "- else: # 根の頂点番号", "- self.v[x] = self.find(self.v[x]) # uniteでは, 旧根に属する頂点の根が旧根のままなので更新", "- return self.v[x]", "-", "- def unite(self, x, y): # 違う根に属していたらrankが低くなるように連結", "- x = self.find(x)", "- y = self.find(y)", "- if x == y:", "- return", "- if -self.v[x] < -self.v[y]: # size比較,  (-1) * (連結頂点数 * (-1)), (正)同士の大小比較", "- x, y = y, x # 連結頂点数が少ない方をyにすると, findでの更新回数が減る?", "- self.v[x] += self.v[y] # 連結頂点数の和を取る, 連結頂点数 * (-1)", "- self.v[y] = x # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする", "- self.bk[x % (H * W)] += self.bk[y % (H * W)]", "- self.wt[x % (H * W)] += self.wt[y % (H * W)]", "-", "- def root(self, x):", "- return self.v[x] < 0 # (負)は根", "-", "- def same(self, x, y):", "- return self.find(x) == self.find(y) # 同じ根に属するか", "-", "- def size(self, x):", "- return -self.v[self.find(x)] # 連結頂点数を返す", "-", "- def calc(self, x):", "- return self.bk[x % (H * W)] * self.wt[x % (H * W)]", "+sys.setrecursionlimit(2 * 10**5)", "+H, W = list(map(int, input().split()))", "+s = [eval(input()) for _ in range(H)]", "+ans = 0", "+dx = [0, 0, 1, -1]", "+dy = [1, -1, 0, 0]", "+un_reached = [[True for i in range(W)] for j in range(H)]", "-dr = [0, 0, 1, -1]", "-dc = [1, -1, 0, 0]", "-H, W = list(map(int, input().split()))", "-s = [eval(input()) for _ in range(H)]", "-uf = UnionFind(2 * H * W) # 全頂点 * 2", "-for r in range(H):", "- for c in range(W):", "- if s[r][c] == \"#\":", "- for i in range(4):", "- nr = r + dr[i]", "- nc = c + dc[i]", "- if 0 <= nr < H and 0 <= nc < W:", "- if s[nr][nc] == \".\":", "- uf.unite(r * W + c, H * W + (nr * W + nc)) # #: *1, .: * 2", "- else:", "- for i in range(4):", "- nr = r + dr[i]", "- nc = c + dc[i]", "- if 0 <= nr < H and 0 <= nc < W:", "- if s[nr][nc] == \"#\":", "- uf.unite(H * W + (r * W + c), nr * W + nc) # #: *1, .: * 2", "-ans = 0", "-for r in range(H):", "- for c in range(W):", "- if uf.root(r * W + c):", "- # print(r, c, '#')", "- sz = uf.size(r * W + c)", "- # print(' ', r * W + c, sz, '#')", "- if sz > 1:", "- ans += uf.calc(r * W + c)", "- if uf.root(H * W + (r * W + c)):", "- # print(r, c, '.')", "- sz = uf.size(H * W + (r * W + c))", "- # print(' ', r * W + c, sz, '.')", "- if sz > 1:", "- ans += uf.calc(H * W + (r * W + c))", "+def dfs(x, y):", "+ un_reached[x][y] = False", "+ if s[x][y] == \"#\":", "+ cc[1] += 1", "+ else:", "+ cc[0] += 1", "+ for i in range(4):", "+ nx = x + dx[i]", "+ ny = y + dy[i]", "+ if 0 <= nx < H and 0 <= ny < W and s[nx][ny] != s[x][y] and un_reached[nx][ny]:", "+ dfs(nx, ny)", "+", "+", "+for i in range(H):", "+ for j in range(W):", "+ if un_reached[i][j]:", "+ cc = [0 for _ in range(2)] # [wt, bk]", "+ dfs(i, j)", "+ ans += cc[1] * cc[0]", "-# print(uf.v)" ]
false
0.038374
0.08569
0.447822
[ "s071466057", "s702703757" ]
u608297208
p03702
python
s185061480
s286752458
1,589
1,345
19,260
15,232
Accepted
Accepted
15.36
import math N,A,B = list(map(int,input().split())) H = [int(eval(input())) for i in range(N)] Hs = sum(H) c = A - B M = math.ceil(Hs / B) m = 0 while M - m > 1: n = (M + m) // 2 H2 = [H[i] - n * B for i in range(N) if H[i] - n * B > 0] cnts = [math.ceil(H2[i] / c) for i in range(len(H2))] cnt = sum(cnts) if cnt > n: m = n elif cnt == n: M = n break else: M = n print(M)
import math N,A,B = list(map(int,input().split())) H = [int(eval(input())) for i in range(N)] Hs = sum(H) c = A - B M = math.ceil(max(H) / B) m = max(H) // A while M - m > 1: n = (M + m) // 2 H2 = [math.ceil((H[i] - n * B) / c) for i in range(N) if H[i] - n * B > 0] cnt = sum(H2) if cnt > n: m = n elif cnt == n: M = n break else: M = n print(M)
22
21
397
370
import math N, A, B = list(map(int, input().split())) H = [int(eval(input())) for i in range(N)] Hs = sum(H) c = A - B M = math.ceil(Hs / B) m = 0 while M - m > 1: n = (M + m) // 2 H2 = [H[i] - n * B for i in range(N) if H[i] - n * B > 0] cnts = [math.ceil(H2[i] / c) for i in range(len(H2))] cnt = sum(cnts) if cnt > n: m = n elif cnt == n: M = n break else: M = n print(M)
import math N, A, B = list(map(int, input().split())) H = [int(eval(input())) for i in range(N)] Hs = sum(H) c = A - B M = math.ceil(max(H) / B) m = max(H) // A while M - m > 1: n = (M + m) // 2 H2 = [math.ceil((H[i] - n * B) / c) for i in range(N) if H[i] - n * B > 0] cnt = sum(H2) if cnt > n: m = n elif cnt == n: M = n break else: M = n print(M)
false
4.545455
[ "-M = math.ceil(Hs / B)", "-m = 0", "+M = math.ceil(max(H) / B)", "+m = max(H) // A", "- H2 = [H[i] - n * B for i in range(N) if H[i] - n * B > 0]", "- cnts = [math.ceil(H2[i] / c) for i in range(len(H2))]", "- cnt = sum(cnts)", "+ H2 = [math.ceil((H[i] - n * B) / c) for i in range(N) if H[i] - n * B > 0]", "+ cnt = sum(H2)" ]
false
0.033471
0.037096
0.902281
[ "s185061480", "s286752458" ]
u754022296
p03168
python
s582345168
s115742008
857
245
259,720
84,788
Accepted
Accepted
71.41
n = int(eval(input())) P = list(map(float, input().split())) dp = [[0]*(n+1) for _ in range(n+1)] dp[0][0] = 1 for i in range(n): for j in range(n+1): if j==0: dp[i+1][j] = dp[i][j]*(1-P[i]) else: dp[i+1][j] = dp[i][j-1]*P[i] + dp[i][j]*(1-P[i]) print((sum(dp[n][1+n//2:])))
import numpy as np n = int(eval(input())) P = list(map(float, input().split())) dp = np.zeros((n+1, n+1)) dp[0, 0] = 1 for i in range(n): dp[i+1, 0] = dp[i, 0] * (1-P[i]) dp[i+1, 1:] = dp[i, :-1]*P[i] + dp[i, 1:]*(1-P[i]) print((dp[n, 1+n//2:].sum()))
11
10
298
257
n = int(eval(input())) P = list(map(float, input().split())) dp = [[0] * (n + 1) for _ in range(n + 1)] dp[0][0] = 1 for i in range(n): for j in range(n + 1): if j == 0: dp[i + 1][j] = dp[i][j] * (1 - P[i]) else: dp[i + 1][j] = dp[i][j - 1] * P[i] + dp[i][j] * (1 - P[i]) print((sum(dp[n][1 + n // 2 :])))
import numpy as np n = int(eval(input())) P = list(map(float, input().split())) dp = np.zeros((n + 1, n + 1)) dp[0, 0] = 1 for i in range(n): dp[i + 1, 0] = dp[i, 0] * (1 - P[i]) dp[i + 1, 1:] = dp[i, :-1] * P[i] + dp[i, 1:] * (1 - P[i]) print((dp[n, 1 + n // 2 :].sum()))
false
9.090909
[ "+import numpy as np", "+", "-dp = [[0] * (n + 1) for _ in range(n + 1)]", "-dp[0][0] = 1", "+dp = np.zeros((n + 1, n + 1))", "+dp[0, 0] = 1", "- for j in range(n + 1):", "- if j == 0:", "- dp[i + 1][j] = dp[i][j] * (1 - P[i])", "- else:", "- dp[i + 1][j] = dp[i][j - 1] * P[i] + dp[i][j] * (1 - P[i])", "-print((sum(dp[n][1 + n // 2 :])))", "+ dp[i + 1, 0] = dp[i, 0] * (1 - P[i])", "+ dp[i + 1, 1:] = dp[i, :-1] * P[i] + dp[i, 1:] * (1 - P[i])", "+print((dp[n, 1 + n // 2 :].sum()))" ]
false
0.042155
0.57431
0.0734
[ "s582345168", "s115742008" ]
u493130708
p02949
python
s774750828
s229797415
1,211
1,012
75,648
75,856
Accepted
Accepted
16.43
import bisect import collections import copy import functools import heapq import math import sys from collections import deque from collections import defaultdict input = sys.stdin.readline MOD = 10**9+7 N,M,P = list(map(int,(input().split()))) line = [] for i in range(M): a,b,c = list(map(int,(input().split()))) line.append([a-1,b-1,-c+P]) min_distance = [float("inf")]*N # min_distance[i] は始点から街iまでの最短距離 min_distance[0] = 0 # 始点から始点への最短距離は0とする def Bellman_Ford(): for _ in range(N): update = False for s,g,d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = min_distance[s] + d # 最短距離を上書きする update = True if not update: flag = 1 break def Bellman_Ford2(): for _ in range(N): for s,g,d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = -float("inf") if g == N-1: break else: continue break flag = 0 Bellman_Ford() if flag == 1: ans = min_distance[N-1] print((max(-ans,0))) else: Bellman_Ford2() ans = min_distance[N-1] if ans == -float("inf"): print((-1)) else: print((max(-ans,0))) #print(min_distance)
import bisect import collections import copy import functools import heapq import math import sys from collections import deque from collections import defaultdict input = sys.stdin.readline MOD = 10**9+7 N,M,P = list(map(int,(input().split()))) line = [] for i in range(M): a,b,c = list(map(int,(input().split()))) line.append([a-1,b-1,-c+P]) min_distance = [float("inf")]*N # min_distance[i] は始点から街iまでの最短距離 min_distance[0] = 0 # 始点から始点への最短距離は0とする flag = 0 for _ in range(N): update = False for s,g,d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = min_distance[s] + d # 最短距離を上書きする update = True if not update: flag = 1 break if flag == 1: ans = min_distance[N-1] print((max(-ans,0))) else: for _ in range(N): for s,g,d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = -float("inf") if g == N-1: break else: continue break ans = min_distance[N-1] if ans == -float("inf"): print((-1)) else: print((max(-ans,0))) #print(min_distance)
58
52
1,590
1,502
import bisect import collections import copy import functools import heapq import math import sys from collections import deque from collections import defaultdict input = sys.stdin.readline MOD = 10**9 + 7 N, M, P = list(map(int, (input().split()))) line = [] for i in range(M): a, b, c = list(map(int, (input().split()))) line.append([a - 1, b - 1, -c + P]) min_distance = [float("inf")] * N # min_distance[i] は始点から街iまでの最短距離 min_distance[0] = 0 # 始点から始点への最短距離は0とする def Bellman_Ford(): for _ in range(N): update = False for s, g, d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if ( min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g] ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = min_distance[s] + d # 最短距離を上書きする update = True if not update: flag = 1 break def Bellman_Ford2(): for _ in range(N): for s, g, d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if ( min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g] ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = -float("inf") if g == N - 1: break else: continue break flag = 0 Bellman_Ford() if flag == 1: ans = min_distance[N - 1] print((max(-ans, 0))) else: Bellman_Ford2() ans = min_distance[N - 1] if ans == -float("inf"): print((-1)) else: print((max(-ans, 0))) # print(min_distance)
import bisect import collections import copy import functools import heapq import math import sys from collections import deque from collections import defaultdict input = sys.stdin.readline MOD = 10**9 + 7 N, M, P = list(map(int, (input().split()))) line = [] for i in range(M): a, b, c = list(map(int, (input().split()))) line.append([a - 1, b - 1, -c + P]) min_distance = [float("inf")] * N # min_distance[i] は始点から街iまでの最短距離 min_distance[0] = 0 # 始点から始点への最短距離は0とする flag = 0 for _ in range(N): update = False for s, g, d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if ( min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g] ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = min_distance[s] + d # 最短距離を上書きする update = True if not update: flag = 1 break if flag == 1: ans = min_distance[N - 1] print((max(-ans, 0))) else: for _ in range(N): for s, g, d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る if ( min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g] ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、 min_distance[g] = -float("inf") if g == N - 1: break else: continue break ans = min_distance[N - 1] if ans == -float("inf"): print((-1)) else: print((max(-ans, 0))) # print(min_distance)
false
10.344828
[ "-", "-", "-def Bellman_Ford():", "- for _ in range(N):", "- update = False", "- for s, g, d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る", "- if (", "- min_distance[s] != float(\"inf\")", "- and min_distance[s] + d < min_distance[g]", "- ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、", "- min_distance[g] = min_distance[s] + d # 最短距離を上書きする", "- update = True", "- if not update:", "- flag = 1", "- break", "-", "-", "-def Bellman_Ford2():", "+flag = 0", "+for _ in range(N):", "+ update = False", "+ for s, g, d in line: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る", "+ if (", "+ min_distance[s] != float(\"inf\") and min_distance[s] + d < min_distance[g]", "+ ): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、", "+ min_distance[g] = min_distance[s] + d # 最短距離を上書きする", "+ update = True", "+ if not update:", "+ flag = 1", "+ break", "+if flag == 1:", "+ ans = min_distance[N - 1]", "+ print((max(-ans, 0)))", "+else:", "-", "-", "-flag = 0", "-Bellman_Ford()", "-if flag == 1:", "- ans = min_distance[N - 1]", "- print((max(-ans, 0)))", "-else:", "- Bellman_Ford2()" ]
false
0.038135
0.03725
1.023766
[ "s774750828", "s229797415" ]
u406138190
p02683
python
s947510508
s173763740
156
98
9,236
9,244
Accepted
Accepted
37.18
n,m,x=list(map(int,input().split())) arr=[[0 for i in range(m+1)] for j in range(n)] b=[0]*18 ans=-1 flag=1 for i in range(n): arr[i]=list(map(int,input().split())) for i in range(2**n): b=[0]*18 for j in range(n): flag=1 if (1& i>>j): for s in range(m+1): b[s]= b[s]+arr[j][s] for y in range(1,m+1): if(b[y]<x): flag=0 if flag : if ans==-1 or ans>b[0]: ans=b[0] print(ans)
n,m,x=list(map(int,input().split())) a=[[0]*(m+1)]*n for i in range(n): a[i]=list(map(int,input().split())) b=[0]*(m+1) flag=True ans=-1 for i in range(2**n): flag=True b=[0]*(m+1) for j in range(n): if(i>>j & 1): for y in range(m+1): b[y]=b[y]+a[j][y] for y in range(1,m+1): if(b[y]<x): flag=False break if(flag): if ans<0 or b[0]<ans: ans=b[0] print(ans)
22
22
534
483
n, m, x = list(map(int, input().split())) arr = [[0 for i in range(m + 1)] for j in range(n)] b = [0] * 18 ans = -1 flag = 1 for i in range(n): arr[i] = list(map(int, input().split())) for i in range(2**n): b = [0] * 18 for j in range(n): flag = 1 if 1 & i >> j: for s in range(m + 1): b[s] = b[s] + arr[j][s] for y in range(1, m + 1): if b[y] < x: flag = 0 if flag: if ans == -1 or ans > b[0]: ans = b[0] print(ans)
n, m, x = list(map(int, input().split())) a = [[0] * (m + 1)] * n for i in range(n): a[i] = list(map(int, input().split())) b = [0] * (m + 1) flag = True ans = -1 for i in range(2**n): flag = True b = [0] * (m + 1) for j in range(n): if i >> j & 1: for y in range(m + 1): b[y] = b[y] + a[j][y] for y in range(1, m + 1): if b[y] < x: flag = False break if flag: if ans < 0 or b[0] < ans: ans = b[0] print(ans)
false
0
[ "-arr = [[0 for i in range(m + 1)] for j in range(n)]", "-b = [0] * 18", "+a = [[0] * (m + 1)] * n", "+for i in range(n):", "+ a[i] = list(map(int, input().split()))", "+b = [0] * (m + 1)", "+flag = True", "-flag = 1", "-for i in range(n):", "- arr[i] = list(map(int, input().split()))", "- b = [0] * 18", "+ flag = True", "+ b = [0] * (m + 1)", "- flag = 1", "- if 1 & i >> j:", "- for s in range(m + 1):", "- b[s] = b[s] + arr[j][s]", "- for y in range(1, m + 1):", "- if b[y] < x:", "- flag = 0", "- if flag:", "- if ans == -1 or ans > b[0]:", "- ans = b[0]", "+ if i >> j & 1:", "+ for y in range(m + 1):", "+ b[y] = b[y] + a[j][y]", "+ for y in range(1, m + 1):", "+ if b[y] < x:", "+ flag = False", "+ break", "+ if flag:", "+ if ans < 0 or b[0] < ans:", "+ ans = b[0]" ]
false
0.08452
0.044336
1.906345
[ "s947510508", "s173763740" ]
u729133443
p03201
python
s609883013
s044644120
454
415
33,712
55,140
Accepted
Accepted
8.59
from collections import* from bisect import* p=[1] for _ in range(30):p+=p[-1]*2, n,*a=list(map(int,open(0).read().split())) d=Counter(a) c=0 for b in sorted(a)[::-1]: if d[b]<1:continue d[b]-=1 x=p[bisect(p,b)]-b if d[x]: d[x]-=1 c+=1 print(c)
from collections import* C=Counter(a:=sorted(map(int,[*open(r:=0)][1].split()))) for x in a[::-1]: if C[x]>0:y=2**x.bit_length()-x;C[x]-=1;r+=C[y]>0;C[y]-=1 print(r)
15
5
268
170
from collections import * from bisect import * p = [1] for _ in range(30): p += (p[-1] * 2,) n, *a = list(map(int, open(0).read().split())) d = Counter(a) c = 0 for b in sorted(a)[::-1]: if d[b] < 1: continue d[b] -= 1 x = p[bisect(p, b)] - b if d[x]: d[x] -= 1 c += 1 print(c)
from collections import * C = Counter(a := sorted(map(int, [*open(r := 0)][1].split()))) for x in a[::-1]: if C[x] > 0: y = 2 ** x.bit_length() - x C[x] -= 1 r += C[y] > 0 C[y] -= 1 print(r)
false
66.666667
[ "-from bisect import *", "-p = [1]", "-for _ in range(30):", "- p += (p[-1] * 2,)", "-n, *a = list(map(int, open(0).read().split()))", "-d = Counter(a)", "-c = 0", "-for b in sorted(a)[::-1]:", "- if d[b] < 1:", "- continue", "- d[b] -= 1", "- x = p[bisect(p, b)] - b", "- if d[x]:", "- d[x] -= 1", "- c += 1", "-print(c)", "+C = Counter(a := sorted(map(int, [*open(r := 0)][1].split())))", "+for x in a[::-1]:", "+ if C[x] > 0:", "+ y = 2 ** x.bit_length() - x", "+ C[x] -= 1", "+ r += C[y] > 0", "+ C[y] -= 1", "+print(r)" ]
false
0.038597
0.047391
0.814444
[ "s609883013", "s044644120" ]
u935184340
p00008
python
s607291156
s175978156
30
20
7,704
7,796
Accepted
Accepted
33.33
import sys from itertools import product sum = [0] * 51 for k,l in product([i+j for i,j in product(list(range(10)),repeat=2)],repeat=2): sum[k+l] += 1 for i in sys.stdin: print((sum[int(i)]))
import sys import math def nCr(n, k): if 0 <= k <= n: nk,kk = 1,1 for t in range(1, min(k, n - k) + 1): nk = nk*n kk = kk*t n -= 1 return nk // kk else: return 0 p = [0] * 51 v = 0 for i in range(19): t = nCr(i+3, i) v = v + 4 * nCr(i-8,i-10) p[i] = t - v p[36-i] = p[i] for i in sys.stdin: print((p[int(i)]))
9
24
201
429
import sys from itertools import product sum = [0] * 51 for k, l in product([i + j for i, j in product(list(range(10)), repeat=2)], repeat=2): sum[k + l] += 1 for i in sys.stdin: print((sum[int(i)]))
import sys import math def nCr(n, k): if 0 <= k <= n: nk, kk = 1, 1 for t in range(1, min(k, n - k) + 1): nk = nk * n kk = kk * t n -= 1 return nk // kk else: return 0 p = [0] * 51 v = 0 for i in range(19): t = nCr(i + 3, i) v = v + 4 * nCr(i - 8, i - 10) p[i] = t - v p[36 - i] = p[i] for i in sys.stdin: print((p[int(i)]))
false
62.5
[ "-from itertools import product", "+import math", "-sum = [0] * 51", "-for k, l in product([i + j for i, j in product(list(range(10)), repeat=2)], repeat=2):", "- sum[k + l] += 1", "+", "+def nCr(n, k):", "+ if 0 <= k <= n:", "+ nk, kk = 1, 1", "+ for t in range(1, min(k, n - k) + 1):", "+ nk = nk * n", "+ kk = kk * t", "+ n -= 1", "+ return nk // kk", "+ else:", "+ return 0", "+", "+", "+p = [0] * 51", "+v = 0", "+for i in range(19):", "+ t = nCr(i + 3, i)", "+ v = v + 4 * nCr(i - 8, i - 10)", "+ p[i] = t - v", "+ p[36 - i] = p[i]", "- print((sum[int(i)]))", "+ print((p[int(i)]))" ]
false
0.042956
0.042475
1.011325
[ "s607291156", "s175978156" ]
u193927973
p02888
python
s803556165
s690718547
1,272
1,034
74,604
74,844
Accepted
Accepted
18.71
import bisect as bs N=int(eval(input())) y=list(map(int, input().split())) y.sort() ans=0 for i in range(N-2): for j in range(i+1, N-1): tmp=y[i]+y[j] ans+=bs.bisect_left(y[(j+1):],tmp) print(ans)
from bisect import bisect_left N=int(eval(input())) y=list(map(int, input().split())) y.sort() ans=0 for i in range(N-2): for j in range(i+1, N-1): tmp=y[i]+y[j] ans+=bisect_left(y[(j+1):],tmp) print(ans)
12
10
218
217
import bisect as bs N = int(eval(input())) y = list(map(int, input().split())) y.sort() ans = 0 for i in range(N - 2): for j in range(i + 1, N - 1): tmp = y[i] + y[j] ans += bs.bisect_left(y[(j + 1) :], tmp) print(ans)
from bisect import bisect_left N = int(eval(input())) y = list(map(int, input().split())) y.sort() ans = 0 for i in range(N - 2): for j in range(i + 1, N - 1): tmp = y[i] + y[j] ans += bisect_left(y[(j + 1) :], tmp) print(ans)
false
16.666667
[ "-import bisect as bs", "+from bisect import bisect_left", "- ans += bs.bisect_left(y[(j + 1) :], tmp)", "+ ans += bisect_left(y[(j + 1) :], tmp)" ]
false
0.126168
0.038485
3.278344
[ "s803556165", "s690718547" ]
u033524082
p02707
python
s804136391
s474952623
237
150
121,972
32,228
Accepted
Accepted
36.71
import collections n=int(eval(input())) a=list(map(int,input().split())) m=max(a) c=collections.Counter(a) c=c.most_common() l=[0]*n for i in range(len(c)): l[c[i][0]-1]=c[i][1] print((l[0])) for j in range(1,n): print((l[j]))
n=int(eval(input())) a=list(map(int,input().split())) l=[0]*(n+1) check=[False]*(n+1) for i in a: l[i]+=1 for i in range(1,n+1): print((l[i]))
12
9
236
147
import collections n = int(eval(input())) a = list(map(int, input().split())) m = max(a) c = collections.Counter(a) c = c.most_common() l = [0] * n for i in range(len(c)): l[c[i][0] - 1] = c[i][1] print((l[0])) for j in range(1, n): print((l[j]))
n = int(eval(input())) a = list(map(int, input().split())) l = [0] * (n + 1) check = [False] * (n + 1) for i in a: l[i] += 1 for i in range(1, n + 1): print((l[i]))
false
25
[ "-import collections", "-", "-m = max(a)", "-c = collections.Counter(a)", "-c = c.most_common()", "-l = [0] * n", "-for i in range(len(c)):", "- l[c[i][0] - 1] = c[i][1]", "-print((l[0]))", "-for j in range(1, n):", "- print((l[j]))", "+l = [0] * (n + 1)", "+check = [False] * (n + 1)", "+for i in a:", "+ l[i] += 1", "+for i in range(1, n + 1):", "+ print((l[i]))" ]
false
0.147562
0.036033
4.095249
[ "s804136391", "s474952623" ]
u869790980
p03266
python
s471509801
s586840013
443
75
84,960
64,016
Accepted
Accepted
83.07
n,k = list(map(int, input().split(' '))) a = n / k b = n/k + (1 if 0 < k / 2 <= n % k else 0) print(a ** 3 + (b ** 3 if k % 2 == 0 else 0))
n,k = list(map(int, input().split(' '))) a,b = n / k, n / k + (1 if 0 < k / 2 <= n % k else 0) print(a ** 3 + (b ** 3 if k % 2 == 0 else 0))
4
3
139
140
n, k = list(map(int, input().split(" "))) a = n / k b = n / k + (1 if 0 < k / 2 <= n % k else 0) print(a**3 + (b**3 if k % 2 == 0 else 0))
n, k = list(map(int, input().split(" "))) a, b = n / k, n / k + (1 if 0 < k / 2 <= n % k else 0) print(a**3 + (b**3 if k % 2 == 0 else 0))
false
25
[ "-a = n / k", "-b = n / k + (1 if 0 < k / 2 <= n % k else 0)", "+a, b = n / k, n / k + (1 if 0 < k / 2 <= n % k else 0)" ]
false
0.095832
0.053964
1.775867
[ "s471509801", "s586840013" ]
u920103253
p02681
python
s123670022
s720016947
24
20
9,132
9,020
Accepted
Accepted
16.67
def s0():return input() def s1():return input().split() def s2(n):return [input() for x in range(n)] def s3(n):return [[input().split()] for _ in range(n)] def n0():return int(input()) def n1():return [int(x) for x in input().split()] def n2(n):return [int(input()) for _ in range(n)] def n3(n):return [[int(x) for x in input().split()] for _ in range(n)] def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)] def p0(b,yes,no): print(yes) if b else print(no) # from collections import Counter,deque,defaultdict # import itertools # import math # import networkx # from bisect import bisect_left,bisect_right s=s0() t=s0() p0(s==t[:-1],"Yes","No")
def s0():return input() def s1():return input().split() def s2(n):return [input() for x in range(n)] def s3(n):return [[input().split()] for _ in range(n)] def n0():return int(input()) def n1():return [int(x) for x in input().split()] def n2(n):return [int(input()) for _ in range(n)] def n3(n):return [[int(x) for x in input().split()] for _ in range(n)] def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)] def p0(b,yes="Yes",no="No"): print(yes) if b else print(no) # from collections import Counter,deque,defaultdict # import itertools # import math # import networkx # from bisect import bisect_left,bisect_right s=s0() t=s0() p0(s==t[:-1])
21
20
695
689
def s0(): return input() def s1(): return input().split() def s2(n): return [input() for x in range(n)] def s3(n): return [[input().split()] for _ in range(n)] def n0(): return int(input()) def n1(): return [int(x) for x in input().split()] def n2(n): return [int(input()) for _ in range(n)] def n3(n): return [[int(x) for x in input().split()] for _ in range(n)] def t3(n): return [tuple(int(x) for x in input().split()) for _ in range(n)] def p0(b, yes, no): print(yes) if b else print(no) # from collections import Counter,deque,defaultdict # import itertools # import math # import networkx # from bisect import bisect_left,bisect_right s = s0() t = s0() p0(s == t[:-1], "Yes", "No")
def s0(): return input() def s1(): return input().split() def s2(n): return [input() for x in range(n)] def s3(n): return [[input().split()] for _ in range(n)] def n0(): return int(input()) def n1(): return [int(x) for x in input().split()] def n2(n): return [int(input()) for _ in range(n)] def n3(n): return [[int(x) for x in input().split()] for _ in range(n)] def t3(n): return [tuple(int(x) for x in input().split()) for _ in range(n)] def p0(b, yes="Yes", no="No"): print(yes) if b else print(no) # from collections import Counter,deque,defaultdict # import itertools # import math # import networkx # from bisect import bisect_left,bisect_right s = s0() t = s0() p0(s == t[:-1])
false
4.761905
[ "-def p0(b, yes, no):", "+def p0(b, yes=\"Yes\", no=\"No\"):", "-p0(s == t[:-1], \"Yes\", \"No\")", "+p0(s == t[:-1])" ]
false
0.04055
0.233167
0.173908
[ "s123670022", "s720016947" ]
u490642448
p03095
python
s326671355
s676112389
265
183
42,604
39,024
Accepted
Accepted
30.94
n = int(eval(input())) s = eval(input()) mod = 10**9 + 7 ans = 0 cnt = [1] * 26 for i,ch in enumerate(s): tmp = 1 for j in range(26): if(j==(ord(ch) - 97)): continue tmp *= cnt[j] tmp %= mod ans += tmp ans %= mod cnt[ord(ch) - 97] += 1 print(ans)
n = int(eval(input())) s = eval(input()) mod = 10**9 + 7 cnt = [0] * 26 for i in range(26): cnt[i] = s.count(chr(i+97)) + 1 ans = 1 for i in cnt: ans *= i ans %= mod ans -= 1 ans %= mod print(ans)
18
16
309
214
n = int(eval(input())) s = eval(input()) mod = 10**9 + 7 ans = 0 cnt = [1] * 26 for i, ch in enumerate(s): tmp = 1 for j in range(26): if j == (ord(ch) - 97): continue tmp *= cnt[j] tmp %= mod ans += tmp ans %= mod cnt[ord(ch) - 97] += 1 print(ans)
n = int(eval(input())) s = eval(input()) mod = 10**9 + 7 cnt = [0] * 26 for i in range(26): cnt[i] = s.count(chr(i + 97)) + 1 ans = 1 for i in cnt: ans *= i ans %= mod ans -= 1 ans %= mod print(ans)
false
11.111111
[ "-ans = 0", "-cnt = [1] * 26", "-for i, ch in enumerate(s):", "- tmp = 1", "- for j in range(26):", "- if j == (ord(ch) - 97):", "- continue", "- tmp *= cnt[j]", "- tmp %= mod", "- ans += tmp", "+cnt = [0] * 26", "+for i in range(26):", "+ cnt[i] = s.count(chr(i + 97)) + 1", "+ans = 1", "+for i in cnt:", "+ ans *= i", "- cnt[ord(ch) - 97] += 1", "+ans -= 1", "+ans %= mod" ]
false
0.047903
0.047055
1.018018
[ "s326671355", "s676112389" ]
u968166680
p03330
python
s897825226
s178795490
794
114
11,588
11,816
Accepted
Accepted
85.64
import sys from itertools import permutations read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, C = list(map(int, readline().split())) D = [0] * C for i in range(C): D[i] = list(map(int, readline().split())) G = [0] * N for i in range(N): G[i] = [int(s) - 1 for s in readline().split()] cost = [[0] * C for _ in range(3)] for x in range(N): for y in range(N): color = G[x][y] cost_current = cost[(x + y) % 3] for i in range(C): cost_current[i] += D[color][i] ans = INF for c1, c2, c3 in permutations(list(range(C)), 3): if ans > cost[0][c1] + cost[1][c2] + cost[2][c3]: ans = cost[0][c1] + cost[1][c2] + cost[2][c3] print(ans) return if __name__ == '__main__': main()
import sys from collections import Counter from itertools import permutations read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, C = list(map(int, readline().split())) D = [0] * C for i in range(C): D[i] = list(map(int, readline().split())) G = [0] * N for i in range(N): G[i] = [int(s) - 1 for s in readline().split()] counter = [[0] * C for _ in range(3)] cost = [[0] * C for _ in range(3)] for x in range(N): for y in range(N): counter[(x + y) % 3][G[x][y]] += 1 for cur_cost, cur_counter in zip(cost, counter): for i in range(C): for j in range(C): cur_cost[i] += cur_counter[j] * D[j][i] ans = INF for c1, c2, c3 in permutations(list(range(C)), 3): if ans > cost[0][c1] + cost[1][c2] + cost[2][c3]: ans = cost[0][c1] + cost[1][c2] + cost[2][c3] print(ans) return if __name__ == '__main__': main()
39
43
957
1,099
import sys from itertools import permutations read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, C = list(map(int, readline().split())) D = [0] * C for i in range(C): D[i] = list(map(int, readline().split())) G = [0] * N for i in range(N): G[i] = [int(s) - 1 for s in readline().split()] cost = [[0] * C for _ in range(3)] for x in range(N): for y in range(N): color = G[x][y] cost_current = cost[(x + y) % 3] for i in range(C): cost_current[i] += D[color][i] ans = INF for c1, c2, c3 in permutations(list(range(C)), 3): if ans > cost[0][c1] + cost[1][c2] + cost[2][c3]: ans = cost[0][c1] + cost[1][c2] + cost[2][c3] print(ans) return if __name__ == "__main__": main()
import sys from collections import Counter from itertools import permutations read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, C = list(map(int, readline().split())) D = [0] * C for i in range(C): D[i] = list(map(int, readline().split())) G = [0] * N for i in range(N): G[i] = [int(s) - 1 for s in readline().split()] counter = [[0] * C for _ in range(3)] cost = [[0] * C for _ in range(3)] for x in range(N): for y in range(N): counter[(x + y) % 3][G[x][y]] += 1 for cur_cost, cur_counter in zip(cost, counter): for i in range(C): for j in range(C): cur_cost[i] += cur_counter[j] * D[j][i] ans = INF for c1, c2, c3 in permutations(list(range(C)), 3): if ans > cost[0][c1] + cost[1][c2] + cost[2][c3]: ans = cost[0][c1] + cost[1][c2] + cost[2][c3] print(ans) return if __name__ == "__main__": main()
false
9.302326
[ "+from collections import Counter", "+ counter = [[0] * C for _ in range(3)]", "- color = G[x][y]", "- cost_current = cost[(x + y) % 3]", "- for i in range(C):", "- cost_current[i] += D[color][i]", "+ counter[(x + y) % 3][G[x][y]] += 1", "+ for cur_cost, cur_counter in zip(cost, counter):", "+ for i in range(C):", "+ for j in range(C):", "+ cur_cost[i] += cur_counter[j] * D[j][i]" ]
false
0.060479
0.038571
1.567973
[ "s897825226", "s178795490" ]
u898967808
p02726
python
s266495345
s041557358
1,888
1,482
3,444
3,572
Accepted
Accepted
21.5
n,x,y = list(map(int,input().split())) x,y = x-1,y-1 ans = [0]*(n) for i in range(n): for j in range(i+1,n): sp = min(abs(j-i), abs(x-i)+abs(j-y)+1, abs(y-i)+1+abs(j-x)) ans[sp]+=1 for a in ans[1:]: print(a)
n,x,y = list(map(int,input().split())) x,y = x-1,y-1 ans = [0]*(n) for i in range(n): for j in range(i+1,n): sp = min(abs(j-i), abs(x-i)+abs(j-y)+1) ans[sp]+=1 for a in ans[1:]: print(a)
11
11
233
212
n, x, y = list(map(int, input().split())) x, y = x - 1, y - 1 ans = [0] * (n) for i in range(n): for j in range(i + 1, n): sp = min(abs(j - i), abs(x - i) + abs(j - y) + 1, abs(y - i) + 1 + abs(j - x)) ans[sp] += 1 for a in ans[1:]: print(a)
n, x, y = list(map(int, input().split())) x, y = x - 1, y - 1 ans = [0] * (n) for i in range(n): for j in range(i + 1, n): sp = min(abs(j - i), abs(x - i) + abs(j - y) + 1) ans[sp] += 1 for a in ans[1:]: print(a)
false
0
[ "- sp = min(abs(j - i), abs(x - i) + abs(j - y) + 1, abs(y - i) + 1 + abs(j - x))", "+ sp = min(abs(j - i), abs(x - i) + abs(j - y) + 1)" ]
false
0.034547
0.036683
0.94178
[ "s266495345", "s041557358" ]
u724687935
p02548
python
s823696459
s031682437
340
179
148,076
9,140
Accepted
Accepted
47.35
from bisect import bisect_right N = int(eval(input())) num = [i for i in range(1, N)] cnt = 0 for a in range(1, N): n = (N - 1) // a b = bisect_right(num, n) cnt += b print(cnt)
N = int(eval(input())) cnt = 0 for a in range(1, N): n = (N - 1) // a cnt += n print(cnt)
11
7
196
99
from bisect import bisect_right N = int(eval(input())) num = [i for i in range(1, N)] cnt = 0 for a in range(1, N): n = (N - 1) // a b = bisect_right(num, n) cnt += b print(cnt)
N = int(eval(input())) cnt = 0 for a in range(1, N): n = (N - 1) // a cnt += n print(cnt)
false
36.363636
[ "-from bisect import bisect_right", "-", "-num = [i for i in range(1, N)]", "- b = bisect_right(num, n)", "- cnt += b", "+ cnt += n" ]
false
0.228035
0.079758
2.859078
[ "s823696459", "s031682437" ]
u693378622
p02726
python
s374457752
s495775300
1,250
233
3,188
43,244
Accepted
Accepted
81.36
n, x, y = list(map(int, input().split())) x -= 1 y -= 1 ans = [0] * n for j in range(n): for i in range(j): d = min(j-i, abs(x-i)+1+abs(j-y)) ans[d] += 1 print(( "\n".join( [str(d) for d in ans[1:]] )))
n,x,y = list(map(int, input().split())) x -= 1 y -= 1 ans = [0] * (n-1) for j in range(n): for i in range(j): ans[min(j-i, abs(x-i)+1+abs(j-y)) - 1] += 1 print(("\n".join([str(d) for d in ans])))
12
11
219
206
n, x, y = list(map(int, input().split())) x -= 1 y -= 1 ans = [0] * n for j in range(n): for i in range(j): d = min(j - i, abs(x - i) + 1 + abs(j - y)) ans[d] += 1 print(("\n".join([str(d) for d in ans[1:]])))
n, x, y = list(map(int, input().split())) x -= 1 y -= 1 ans = [0] * (n - 1) for j in range(n): for i in range(j): ans[min(j - i, abs(x - i) + 1 + abs(j - y)) - 1] += 1 print(("\n".join([str(d) for d in ans])))
false
8.333333
[ "-ans = [0] * n", "+ans = [0] * (n - 1)", "- d = min(j - i, abs(x - i) + 1 + abs(j - y))", "- ans[d] += 1", "-print((\"\\n\".join([str(d) for d in ans[1:]])))", "+ ans[min(j - i, abs(x - i) + 1 + abs(j - y)) - 1] += 1", "+print((\"\\n\".join([str(d) for d in ans])))" ]
false
0.037734
0.038782
0.972964
[ "s374457752", "s495775300" ]
u693378622
p02803
python
s394480862
s496566622
501
248
32,352
18,760
Accepted
Accepted
50.5
H, W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] N = W * H E = [[0] * N for _ in range(N)] dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] for i in range(H): for j in range(W): if S[i][j] == ".": for di, dj in dij: ni, nj = i + di, j + dj if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == ".": E[W * i + j][W * ni + nj] = 1 from scipy.sparse.csgraph import floyd_warshall A = floyd_warshall(E) INF = float("inf") print((int(max(max(a if a != INF else 0 for a in a) for a in A))))
INF = float("inf") H, W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] N = W * H E = [[INF] * N for _ in range(N)] dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] for i in range(H): for j in range(W): if S[i][j] == ".": for di, dj in dij: ni, nj = i + di, j + dj if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == ".": E[W * i + j][W * ni + nj] = 1 from scipy.sparse.csgraph import floyd_warshall A = floyd_warshall(E) INF = float("inf") print((int(max(max(a if a != INF else 0 for a in a) for a in A))))
21
23
586
611
H, W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] N = W * H E = [[0] * N for _ in range(N)] dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] for i in range(H): for j in range(W): if S[i][j] == ".": for di, dj in dij: ni, nj = i + di, j + dj if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == ".": E[W * i + j][W * ni + nj] = 1 from scipy.sparse.csgraph import floyd_warshall A = floyd_warshall(E) INF = float("inf") print((int(max(max(a if a != INF else 0 for a in a) for a in A))))
INF = float("inf") H, W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] N = W * H E = [[INF] * N for _ in range(N)] dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] for i in range(H): for j in range(W): if S[i][j] == ".": for di, dj in dij: ni, nj = i + di, j + dj if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == ".": E[W * i + j][W * ni + nj] = 1 from scipy.sparse.csgraph import floyd_warshall A = floyd_warshall(E) INF = float("inf") print((int(max(max(a if a != INF else 0 for a in a) for a in A))))
false
8.695652
[ "+INF = float(\"inf\")", "-E = [[0] * N for _ in range(N)]", "+E = [[INF] * N for _ in range(N)]" ]
false
0.243995
0.159948
1.525461
[ "s394480862", "s496566622" ]
u844646164
p02883
python
s121789705
s545716729
604
332
121,164
113,648
Accepted
Accepted
45.03
N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A = sorted(A) F = sorted(F, reverse=True) l = -1 # 絶対にfalse r = 10**12+5 while (l+1<r): c = (l+r)//2 s = 0 for i in range(N): s += max(0, A[i]-(c//F[i])) if s <= K: r = c else: l = c print(r)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A = sorted(A) F = sorted(F, reverse=True) l = -1 r = 10**12+5 while (l+1<r): c = (l+r)//2 tmp = 0 for i in range(N): tmp += max(0, A[i]-(c//F[i])) if tmp <= K: r = c else: l = c print(r)
20
22
340
341
N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A = sorted(A) F = sorted(F, reverse=True) l = -1 # 絶対にfalse r = 10**12 + 5 while l + 1 < r: c = (l + r) // 2 s = 0 for i in range(N): s += max(0, A[i] - (c // F[i])) if s <= K: r = c else: l = c print(r)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A = sorted(A) F = sorted(F, reverse=True) l = -1 r = 10**12 + 5 while l + 1 < r: c = (l + r) // 2 tmp = 0 for i in range(N): tmp += max(0, A[i] - (c // F[i])) if tmp <= K: r = c else: l = c print(r)
false
9.090909
[ "-l = -1 # 絶対にfalse", "+l = -1", "- s = 0", "+ tmp = 0", "- s += max(0, A[i] - (c // F[i]))", "- if s <= K:", "+ tmp += max(0, A[i] - (c // F[i]))", "+ if tmp <= K:" ]
false
0.078708
0.065988
1.192762
[ "s121789705", "s545716729" ]
u074220993
p03456
python
s950582769
s085117699
116
29
27,012
8,988
Accepted
Accepted
75
import numpy as np n = np.sqrt(int(''.join(input().split()))) print(('Yes' if n == int(n) else 'No'))
from math import sqrt a, b = input().split() n = int(a+b) print(('Yes' if sqrt(n) == int(sqrt(n)) else 'No'))
3
4
101
111
import numpy as np n = np.sqrt(int("".join(input().split()))) print(("Yes" if n == int(n) else "No"))
from math import sqrt a, b = input().split() n = int(a + b) print(("Yes" if sqrt(n) == int(sqrt(n)) else "No"))
false
25
[ "-import numpy as np", "+from math import sqrt", "-n = np.sqrt(int(\"\".join(input().split())))", "-print((\"Yes\" if n == int(n) else \"No\"))", "+a, b = input().split()", "+n = int(a + b)", "+print((\"Yes\" if sqrt(n) == int(sqrt(n)) else \"No\"))" ]
false
0.66042
0.035094
18.818747
[ "s950582769", "s085117699" ]
u440566786
p02574
python
s344771380
s479739018
439
359
191,040
191,508
Accepted
Accepted
18.22
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() # https://qiita.com/Kiri8128/items/eca965fe86ea5f4cbb98 def isPrimeMR(n): d = n - 1 d = d // (d & -d) L = [2] for a in L: t = d y = pow(a, t, n) if y == 1: continue while y != n - 1: y = (y * y) % n if y == 1 or t == n - 1: return 0 t <<= 1 return 1 def findFactorRho(n): m = 1 << n.bit_length() // 8 for c in range(1, 99): f = lambda x: (x * x + c) % n y, r, q, g = 2, 1, 1, 1 while g == 1: x = y for i in range(r): y = f(y) k = 0 while k < r and g == 1: ys = y for i in range(min(m, r - k)): y = f(y) q = q * abs(x - y) % n g = gcd(q, n) k += m r <<= 1 if g == n: g = 1 while g == 1: ys = f(ys) g = gcd(abs(x - ys), n) if g < n: if isPrimeMR(g): return g elif isPrimeMR(n // g): return n // g return findFactorRho(g) def primeFactor(n): i = 2 ret = {} rhoFlg = 0 while i*i <= n: k = 0 while n % i == 0: n //= i k += 1 if k: ret[i] = k i += 1 + i % 2 if i == 101 and n >= 2 ** 20: while n > 1: if isPrimeMR(n): ret[n], n = 1, 1 else: rhoFlg = 1 j = findFactorRho(n) k = 0 while n % j == 0: n //= j k += 1 ret[j] = k if n > 1: ret[n] = 1 if rhoFlg: ret = {x: ret[x] for x in sorted(ret)} return ret from math import gcd from functools import reduce def resolve(): n = int(eval(input())) A = list(map(int, input().split())) if reduce(gcd, A) != 1: print("not coprime") return used = set() for a in A: for p in primeFactor(a): if p in used: print("setwise coprime") return used.add(p) print("pairwise coprime") resolve()
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() from functools import reduce from math import gcd def resolve(): n = int(eval(input())) A = list(map(int, input().split())) if reduce(gcd, A) != 1: print("not coprime") return M = max(A) sieve = list(range(M + 1)) sieve[0] = sieve[1] = INF for p in range(2, M + 1): if sieve[p] != p: continue for i in range(2 * p, M + 1, p): sieve[i] = min(sieve[i], p) used = set() for a in A: primes = set() while a > 1: p = sieve[a] primes.add(p) a //= p for p in primes: if p in used: print("setwise coprime") return used.add(p) print("pairwise coprime") resolve()
95
39
2,460
932
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda: sys.stdin.readline().rstrip() # https://qiita.com/Kiri8128/items/eca965fe86ea5f4cbb98 def isPrimeMR(n): d = n - 1 d = d // (d & -d) L = [2] for a in L: t = d y = pow(a, t, n) if y == 1: continue while y != n - 1: y = (y * y) % n if y == 1 or t == n - 1: return 0 t <<= 1 return 1 def findFactorRho(n): m = 1 << n.bit_length() // 8 for c in range(1, 99): f = lambda x: (x * x + c) % n y, r, q, g = 2, 1, 1, 1 while g == 1: x = y for i in range(r): y = f(y) k = 0 while k < r and g == 1: ys = y for i in range(min(m, r - k)): y = f(y) q = q * abs(x - y) % n g = gcd(q, n) k += m r <<= 1 if g == n: g = 1 while g == 1: ys = f(ys) g = gcd(abs(x - ys), n) if g < n: if isPrimeMR(g): return g elif isPrimeMR(n // g): return n // g return findFactorRho(g) def primeFactor(n): i = 2 ret = {} rhoFlg = 0 while i * i <= n: k = 0 while n % i == 0: n //= i k += 1 if k: ret[i] = k i += 1 + i % 2 if i == 101 and n >= 2**20: while n > 1: if isPrimeMR(n): ret[n], n = 1, 1 else: rhoFlg = 1 j = findFactorRho(n) k = 0 while n % j == 0: n //= j k += 1 ret[j] = k if n > 1: ret[n] = 1 if rhoFlg: ret = {x: ret[x] for x in sorted(ret)} return ret from math import gcd from functools import reduce def resolve(): n = int(eval(input())) A = list(map(int, input().split())) if reduce(gcd, A) != 1: print("not coprime") return used = set() for a in A: for p in primeFactor(a): if p in used: print("setwise coprime") return used.add(p) print("pairwise coprime") resolve()
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda: sys.stdin.readline().rstrip() from functools import reduce from math import gcd def resolve(): n = int(eval(input())) A = list(map(int, input().split())) if reduce(gcd, A) != 1: print("not coprime") return M = max(A) sieve = list(range(M + 1)) sieve[0] = sieve[1] = INF for p in range(2, M + 1): if sieve[p] != p: continue for i in range(2 * p, M + 1, p): sieve[i] = min(sieve[i], p) used = set() for a in A: primes = set() while a > 1: p = sieve[a] primes.add(p) a //= p for p in primes: if p in used: print("setwise coprime") return used.add(p) print("pairwise coprime") resolve()
false
58.947368
[ "-# https://qiita.com/Kiri8128/items/eca965fe86ea5f4cbb98", "-def isPrimeMR(n):", "- d = n - 1", "- d = d // (d & -d)", "- L = [2]", "- for a in L:", "- t = d", "- y = pow(a, t, n)", "- if y == 1:", "- continue", "- while y != n - 1:", "- y = (y * y) % n", "- if y == 1 or t == n - 1:", "- return 0", "- t <<= 1", "- return 1", "-", "-", "-def findFactorRho(n):", "- m = 1 << n.bit_length() // 8", "- for c in range(1, 99):", "- f = lambda x: (x * x + c) % n", "- y, r, q, g = 2, 1, 1, 1", "- while g == 1:", "- x = y", "- for i in range(r):", "- y = f(y)", "- k = 0", "- while k < r and g == 1:", "- ys = y", "- for i in range(min(m, r - k)):", "- y = f(y)", "- q = q * abs(x - y) % n", "- g = gcd(q, n)", "- k += m", "- r <<= 1", "- if g == n:", "- g = 1", "- while g == 1:", "- ys = f(ys)", "- g = gcd(abs(x - ys), n)", "- if g < n:", "- if isPrimeMR(g):", "- return g", "- elif isPrimeMR(n // g):", "- return n // g", "- return findFactorRho(g)", "-", "-", "-def primeFactor(n):", "- i = 2", "- ret = {}", "- rhoFlg = 0", "- while i * i <= n:", "- k = 0", "- while n % i == 0:", "- n //= i", "- k += 1", "- if k:", "- ret[i] = k", "- i += 1 + i % 2", "- if i == 101 and n >= 2**20:", "- while n > 1:", "- if isPrimeMR(n):", "- ret[n], n = 1, 1", "- else:", "- rhoFlg = 1", "- j = findFactorRho(n)", "- k = 0", "- while n % j == 0:", "- n //= j", "- k += 1", "- ret[j] = k", "- if n > 1:", "- ret[n] = 1", "- if rhoFlg:", "- ret = {x: ret[x] for x in sorted(ret)}", "- return ret", "-", "-", "+from functools import reduce", "-from functools import reduce", "+ M = max(A)", "+ sieve = list(range(M + 1))", "+ sieve[0] = sieve[1] = INF", "+ for p in range(2, M + 1):", "+ if sieve[p] != p:", "+ continue", "+ for i in range(2 * p, M + 1, p):", "+ sieve[i] = min(sieve[i], p)", "- for p in primeFactor(a):", "+ primes = set()", "+ while a > 1:", "+ p = sieve[a]", "+ primes.add(p)", "+ a //= p", "+ for p in primes:" ]
false
0.14932
0.047699
3.130435
[ "s344771380", "s479739018" ]
u475077336
p03338
python
s682132143
s237685655
32
19
3,444
3,316
Accepted
Accepted
40.62
from collections import OrderedDict # Function to remove all duplicates from string # and order does not matter def removeDupWithoutOrder(str): # set() --> A Set is an unordered collection # data type that is iterable, mutable, # and has no duplicate elements. # "".join() --> It joins two adjacent elements in # iterable with any symbol defined in # "" ( double quotes ) and returns a # single string return "".join(set(str)) # Function to remove all duplicates from string # and keep the order of characters same def removeDupWithOrder(str): s = "".join(OrderedDict.fromkeys(str)) return "".join(sorted(s)) n = int(eval(input())) s = eval(input()) maxcnt = 0 oset = set() for i in range(1,n): s1 = removeDupWithOrder(s[0:i]) s2 = removeDupWithOrder(s[i:n]) oset.add(s1+' '+s2) ls = list(oset) for x in ls: s1,s2 = list(map(str,x.split())) cnt = 0 for i in range(len(s1)): if s1[i] in s2: cnt += 1 if maxcnt < cnt: maxcnt = cnt print(maxcnt)
n = int(eval(input())) s = eval(input()) answer = 0 for i in range(1,n): a = s[:i] b = s[i:] oset = set() oset = set(a) & set(b) answer = max(answer, len(oset)) print(answer)
39
10
1,152
191
from collections import OrderedDict # Function to remove all duplicates from string # and order does not matter def removeDupWithoutOrder(str): # set() --> A Set is an unordered collection # data type that is iterable, mutable, # and has no duplicate elements. # "".join() --> It joins two adjacent elements in # iterable with any symbol defined in # "" ( double quotes ) and returns a # single string return "".join(set(str)) # Function to remove all duplicates from string # and keep the order of characters same def removeDupWithOrder(str): s = "".join(OrderedDict.fromkeys(str)) return "".join(sorted(s)) n = int(eval(input())) s = eval(input()) maxcnt = 0 oset = set() for i in range(1, n): s1 = removeDupWithOrder(s[0:i]) s2 = removeDupWithOrder(s[i:n]) oset.add(s1 + " " + s2) ls = list(oset) for x in ls: s1, s2 = list(map(str, x.split())) cnt = 0 for i in range(len(s1)): if s1[i] in s2: cnt += 1 if maxcnt < cnt: maxcnt = cnt print(maxcnt)
n = int(eval(input())) s = eval(input()) answer = 0 for i in range(1, n): a = s[:i] b = s[i:] oset = set() oset = set(a) & set(b) answer = max(answer, len(oset)) print(answer)
false
74.358974
[ "-from collections import OrderedDict", "-", "-# Function to remove all duplicates from string", "-# and order does not matter", "-def removeDupWithoutOrder(str):", "- # set() --> A Set is an unordered collection", "- # data type that is iterable, mutable,", "- # and has no duplicate elements.", "- # \"\".join() --> It joins two adjacent elements in", "- # iterable with any symbol defined in", "- # \"\" ( double quotes ) and returns a", "- # single string", "- return \"\".join(set(str))", "-", "-", "-# Function to remove all duplicates from string", "-# and keep the order of characters same", "-def removeDupWithOrder(str):", "- s = \"\".join(OrderedDict.fromkeys(str))", "- return \"\".join(sorted(s))", "-", "-", "-maxcnt = 0", "-oset = set()", "+answer = 0", "- s1 = removeDupWithOrder(s[0:i])", "- s2 = removeDupWithOrder(s[i:n])", "- oset.add(s1 + \" \" + s2)", "-ls = list(oset)", "-for x in ls:", "- s1, s2 = list(map(str, x.split()))", "- cnt = 0", "- for i in range(len(s1)):", "- if s1[i] in s2:", "- cnt += 1", "- if maxcnt < cnt:", "- maxcnt = cnt", "-print(maxcnt)", "+ a = s[:i]", "+ b = s[i:]", "+ oset = set()", "+ oset = set(a) & set(b)", "+ answer = max(answer, len(oset))", "+print(answer)" ]
false
0.038239
0.043843
0.872178
[ "s682132143", "s237685655" ]
u729133443
p03723
python
s455905707
s389282429
169
30
39,888
9,068
Accepted
Accepted
82.25
a,b,c=list(map(int,input().split())) if a==b==c: print((-(a%2<1))) else: s=0 while a%2<1and b%2<1and c%2<1: a,b,c=(b+c)//2,(c+a)//2,(a+b)//2 s+=1 print(s)
a,b,c=list(map(int,input().split())) e=a-b|b-c print(((e!=b%2)*(e^e-1).bit_length()-1))
9
3
170
81
a, b, c = list(map(int, input().split())) if a == b == c: print((-(a % 2 < 1))) else: s = 0 while a % 2 < 1 and b % 2 < 1 and c % 2 < 1: a, b, c = (b + c) // 2, (c + a) // 2, (a + b) // 2 s += 1 print(s)
a, b, c = list(map(int, input().split())) e = a - b | b - c print(((e != b % 2) * (e ^ e - 1).bit_length() - 1))
false
66.666667
[ "-if a == b == c:", "- print((-(a % 2 < 1)))", "-else:", "- s = 0", "- while a % 2 < 1 and b % 2 < 1 and c % 2 < 1:", "- a, b, c = (b + c) // 2, (c + a) // 2, (a + b) // 2", "- s += 1", "- print(s)", "+e = a - b | b - c", "+print(((e != b % 2) * (e ^ e - 1).bit_length() - 1))" ]
false
0.041985
0.044238
0.949067
[ "s455905707", "s389282429" ]
u941438707
p03031
python
s794392677
s020498956
41
30
3,064
3,060
Accepted
Accepted
26.83
n,m=list(map(int,input().split())) s=[list(map(int,input().split())) for _ in range(m)] p=list(map(int,input().split())) ans=0 for i in range(2**n): b=0 for j in range(m): a=0 for k in s[j][1:]: if (i>>(k-1))&1: a+=1 if a%2==p[j]: a+=1 b+=1 if b==m: ans+=1 print(ans)
n,m=list(map(int,input().split())) s=[list(map(int,input().split())) for _ in range(m)] *p,=list(map(int,input().split())) a=0 for i in range(2**n): a+=all(sum((i>>(k-1))&1 for k in s[j][1:])%2==p[j] for j in range(m)) print(a)
17
7
382
225
n, m = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(m)] p = list(map(int, input().split())) ans = 0 for i in range(2**n): b = 0 for j in range(m): a = 0 for k in s[j][1:]: if (i >> (k - 1)) & 1: a += 1 if a % 2 == p[j]: a += 1 b += 1 if b == m: ans += 1 print(ans)
n, m = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(m)] (*p,) = list(map(int, input().split())) a = 0 for i in range(2**n): a += all(sum((i >> (k - 1)) & 1 for k in s[j][1:]) % 2 == p[j] for j in range(m)) print(a)
false
58.823529
[ "-p = list(map(int, input().split()))", "-ans = 0", "+(*p,) = list(map(int, input().split()))", "+a = 0", "- b = 0", "- for j in range(m):", "- a = 0", "- for k in s[j][1:]:", "- if (i >> (k - 1)) & 1:", "- a += 1", "- if a % 2 == p[j]:", "- a += 1", "- b += 1", "- if b == m:", "- ans += 1", "-print(ans)", "+ a += all(sum((i >> (k - 1)) & 1 for k in s[j][1:]) % 2 == p[j] for j in range(m))", "+print(a)" ]
false
0.036135
0.036428
0.991977
[ "s794392677", "s020498956" ]
u389910364
p02991
python
s866103901
s477533319
851
712
87,468
76,408
Accepted
Accepted
16.33
import heapq import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 N, M = list(map(int, sys.stdin.readline().split())) UV = [list(map(int, sys.stdin.readline().split())) for _ in range(M)] S, T = list(map(int, sys.stdin.readline().split())) U = [] V = [] for u, v in UV: U.extend([u, u + N, u + N * 2]) V.extend([v + N, v + N * 2, v]) # graph = csr_matrix(([1] * (M * 3), (U, V)), shape=(N * 3 + 1, N * 3 + 1)) # dist = dijkstra(graph, indices=S)[T] # if dist < np.inf: # print(int(dist // 3)) # else: # print(-1) #: :type: list of (list of int) graph = [[] for _ in range(N * 3 + 1)] for u, v in zip(U, V): graph[u].append(v) # S から T までの距離 heap = [(0, S)] dist = [IINF] * (N * 3 + 1) while heap: d, v = heapq.heappop(heap) if v == T: print((int(d // 3))) exit() for u in graph[v]: if d + 1 < dist[u]: dist[u] = d + 1 heapq.heappush(heap, (d + 1, u)) print((-1))
import heapq import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 N, M = list(map(int, sys.stdin.readline().split())) VU = [list(map(int, sys.stdin.readline().split())) for _ in range(M)] S, T = list(map(int, sys.stdin.readline().split())) #: :type: list of (list of int) graph = [[] for _ in range(N * 3 + 1)] for v, u in VU: graph[v].append(u + N) graph[v + N].append(u + N * 2) graph[v + N * 2].append(u) heap = [(0, S)] dist = [INF] * (N * 3 + 1) ans = -1 while heap: d, v = heapq.heappop(heap) if v == T and d % 3 == 0: ans = int(d // 3) break for u in graph[v]: if d + 1 < dist[u]: dist[u] = d + 1 heapq.heappush(heap, (d + 1, u)) print(ans)
46
35
1,088
856
import heapq import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 N, M = list(map(int, sys.stdin.readline().split())) UV = [list(map(int, sys.stdin.readline().split())) for _ in range(M)] S, T = list(map(int, sys.stdin.readline().split())) U = [] V = [] for u, v in UV: U.extend([u, u + N, u + N * 2]) V.extend([v + N, v + N * 2, v]) # graph = csr_matrix(([1] * (M * 3), (U, V)), shape=(N * 3 + 1, N * 3 + 1)) # dist = dijkstra(graph, indices=S)[T] # if dist < np.inf: # print(int(dist // 3)) # else: # print(-1) #: :type: list of (list of int) graph = [[] for _ in range(N * 3 + 1)] for u, v in zip(U, V): graph[u].append(v) # S から T までの距離 heap = [(0, S)] dist = [IINF] * (N * 3 + 1) while heap: d, v = heapq.heappop(heap) if v == T: print((int(d // 3))) exit() for u in graph[v]: if d + 1 < dist[u]: dist[u] = d + 1 heapq.heappush(heap, (d + 1, u)) print((-1))
import heapq import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 N, M = list(map(int, sys.stdin.readline().split())) VU = [list(map(int, sys.stdin.readline().split())) for _ in range(M)] S, T = list(map(int, sys.stdin.readline().split())) #: :type: list of (list of int) graph = [[] for _ in range(N * 3 + 1)] for v, u in VU: graph[v].append(u + N) graph[v + N].append(u + N * 2) graph[v + N * 2].append(u) heap = [(0, S)] dist = [INF] * (N * 3 + 1) ans = -1 while heap: d, v = heapq.heappop(heap) if v == T and d % 3 == 0: ans = int(d // 3) break for u in graph[v]: if d + 1 < dist[u]: dist[u] = d + 1 heapq.heappush(heap, (d + 1, u)) print(ans)
false
23.913043
[ "-UV = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]", "+VU = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]", "-U = []", "-V = []", "-for u, v in UV:", "- U.extend([u, u + N, u + N * 2])", "- V.extend([v + N, v + N * 2, v])", "-# graph = csr_matrix(([1] * (M * 3), (U, V)), shape=(N * 3 + 1, N * 3 + 1))", "-# dist = dijkstra(graph, indices=S)[T]", "-# if dist < np.inf:", "-# print(int(dist // 3))", "-# else:", "-# print(-1)", "-for u, v in zip(U, V):", "- graph[u].append(v)", "-# S から T までの距離", "+for v, u in VU:", "+ graph[v].append(u + N)", "+ graph[v + N].append(u + N * 2)", "+ graph[v + N * 2].append(u)", "-dist = [IINF] * (N * 3 + 1)", "+dist = [INF] * (N * 3 + 1)", "+ans = -1", "- if v == T:", "- print((int(d // 3)))", "- exit()", "+ if v == T and d % 3 == 0:", "+ ans = int(d // 3)", "+ break", "-print((-1))", "+print(ans)" ]
false
0.038935
0.083748
0.464904
[ "s866103901", "s477533319" ]
u573754721
p03073
python
s105223544
s342856259
50
18
3,188
3,188
Accepted
Accepted
64
s=eval(input()) a=0 for i in range(len(s)): if i%2==0: if s[i]=="0": a+=1 elif s[i]=="1": a+=1 print((min(a,len(s)-a)))
s=eval(input()) a=s[::2].count("0") b=s[1::2].count("1") a=a+b print((min(a,len(s)-a)))
9
5
173
83
s = eval(input()) a = 0 for i in range(len(s)): if i % 2 == 0: if s[i] == "0": a += 1 elif s[i] == "1": a += 1 print((min(a, len(s) - a)))
s = eval(input()) a = s[::2].count("0") b = s[1::2].count("1") a = a + b print((min(a, len(s) - a)))
false
44.444444
[ "-a = 0", "-for i in range(len(s)):", "- if i % 2 == 0:", "- if s[i] == \"0\":", "- a += 1", "- elif s[i] == \"1\":", "- a += 1", "+a = s[::2].count(\"0\")", "+b = s[1::2].count(\"1\")", "+a = a + b" ]
false
0.038627
0.008077
4.782312
[ "s105223544", "s342856259" ]
u119148115
p02552
python
s685530510
s727549752
75
68
61,692
61,776
Accepted
Accepted
9.33
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし print((1-I()))
import sys def I(): return int(sys.stdin.readline().rstrip()) print((1-I()))
13
5
505
81
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり def LI2(): return list(map(int, sys.stdin.readline().rstrip())) # 空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) # 空白あり def LS2(): return list(sys.stdin.readline().rstrip()) # 空白なし print((1 - I()))
import sys def I(): return int(sys.stdin.readline().rstrip()) print((1 - I()))
false
61.538462
[ "-", "-sys.setrecursionlimit(10**7)", "-def MI():", "- return list(map(int, sys.stdin.readline().rstrip().split()))", "-", "-", "-def LI():", "- return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり", "-", "-", "-def LI2():", "- return list(map(int, sys.stdin.readline().rstrip())) # 空白なし", "-", "-", "-def S():", "- return sys.stdin.readline().rstrip()", "-", "-", "-def LS():", "- return list(sys.stdin.readline().rstrip().split()) # 空白あり", "-", "-", "-def LS2():", "- return list(sys.stdin.readline().rstrip()) # 空白なし", "-", "-" ]
false
0.049075
0.047308
1.037352
[ "s685530510", "s727549752" ]
u767995501
p02952
python
s927225320
s434683117
55
43
2,940
2,940
Accepted
Accepted
21.82
n = int(eval(input())) ans = 0 for i in range(1,n+1): if len(str(i)) & 1: ans += 1 print(ans)
N = int(eval(input())) answer = sum(len(str(i))&1 for i in range(1,N+1)) print(answer)
7
4
106
84
n = int(eval(input())) ans = 0 for i in range(1, n + 1): if len(str(i)) & 1: ans += 1 print(ans)
N = int(eval(input())) answer = sum(len(str(i)) & 1 for i in range(1, N + 1)) print(answer)
false
42.857143
[ "-n = int(eval(input()))", "-ans = 0", "-for i in range(1, n + 1):", "- if len(str(i)) & 1:", "- ans += 1", "-print(ans)", "+N = int(eval(input()))", "+answer = sum(len(str(i)) & 1 for i in range(1, N + 1))", "+print(answer)" ]
false
0.055339
0.183433
0.301687
[ "s927225320", "s434683117" ]
u780475861
p03276
python
s485437576
s102200757
64
57
14,052
14,052
Accepted
Accepted
10.94
import bisect def main(): n, k, *lst = list(map(int, open(0).read().split())) z = bisect.bisect_left(lst, 0) if not z: print((lst[k - 1])) elif z >= n - 1: print((-lst[-k])) else: res = float('inf') for i in range(max(z - k + 1, 0), min(z, n - k) + 1): tmp = lst[i + k - 1] - lst[i] + min(abs(lst[i]), lst[i + k - 1]) if tmp < res: res = tmp print(res) if __name__ == '__main__': main()
import bisect def main(): n, k, *lst = list(map(int, open(0).read().split())) z = bisect.bisect_left(lst, 0) if not z: print((lst[k - 1])) elif z >= n - 1: print((-lst[-k])) else: idx = max(z - k + 1, 0) print((min(min(abs(i), j) + j - i for i, j in zip(lst[idx:], lst[idx + k - 1:])))) if __name__ == '__main__': main()
19
15
448
352
import bisect def main(): n, k, *lst = list(map(int, open(0).read().split())) z = bisect.bisect_left(lst, 0) if not z: print((lst[k - 1])) elif z >= n - 1: print((-lst[-k])) else: res = float("inf") for i in range(max(z - k + 1, 0), min(z, n - k) + 1): tmp = lst[i + k - 1] - lst[i] + min(abs(lst[i]), lst[i + k - 1]) if tmp < res: res = tmp print(res) if __name__ == "__main__": main()
import bisect def main(): n, k, *lst = list(map(int, open(0).read().split())) z = bisect.bisect_left(lst, 0) if not z: print((lst[k - 1])) elif z >= n - 1: print((-lst[-k])) else: idx = max(z - k + 1, 0) print( (min(min(abs(i), j) + j - i for i, j in zip(lst[idx:], lst[idx + k - 1 :]))) ) if __name__ == "__main__": main()
false
21.052632
[ "- res = float(\"inf\")", "- for i in range(max(z - k + 1, 0), min(z, n - k) + 1):", "- tmp = lst[i + k - 1] - lst[i] + min(abs(lst[i]), lst[i + k - 1])", "- if tmp < res:", "- res = tmp", "- print(res)", "+ idx = max(z - k + 1, 0)", "+ print(", "+ (min(min(abs(i), j) + j - i for i, j in zip(lst[idx:], lst[idx + k - 1 :])))", "+ )" ]
false
0.040522
0.042786
0.947076
[ "s485437576", "s102200757" ]
u646412443
p02725
python
s537542978
s136262957
170
150
26,444
26,444
Accepted
Accepted
11.76
# -*- coding: utf-8 -*- k, n = list(map(int,input().split())) a = [int(i) for i in input().split()] a.append(k + a[0]) l = 0 for i in range(n): l = max(l, a[i + 1] - a[i]) ans = k - l print(ans)
k, n = list(map(int, input().split())) a = list(map(int, input().split())) a.append(k + a[0]) dist = 0 for i in range(n): dist = max(dist, a[i + 1] - a[i]) print((k - dist))
9
7
201
176
# -*- coding: utf-8 -*- k, n = list(map(int, input().split())) a = [int(i) for i in input().split()] a.append(k + a[0]) l = 0 for i in range(n): l = max(l, a[i + 1] - a[i]) ans = k - l print(ans)
k, n = list(map(int, input().split())) a = list(map(int, input().split())) a.append(k + a[0]) dist = 0 for i in range(n): dist = max(dist, a[i + 1] - a[i]) print((k - dist))
false
22.222222
[ "-# -*- coding: utf-8 -*-", "-a = [int(i) for i in input().split()]", "+a = list(map(int, input().split()))", "-l = 0", "+dist = 0", "- l = max(l, a[i + 1] - a[i])", "-ans = k - l", "-print(ans)", "+ dist = max(dist, a[i + 1] - a[i])", "+print((k - dist))" ]
false
0.046849
0.070543
0.664122
[ "s537542978", "s136262957" ]
u279493135
p02925
python
s579927429
s633166690
1,940
946
207,024
133,720
Accepted
Accepted
51.24
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 def main(): N = INT() A = [LIST() for _ in range(N)] graph_out = defaultdict(list) graph_in = defaultdict(list) match_id = [[0]*N for _ in range(N)] def toid(i, j): # 選手から試合IDに変換 if i > j: i, j = j, i return match_id[i][j] cnt = 0 for i in range(N): for j in range(N): if i < j: match_id[i][j] = cnt cnt += 1 V = N*(N-1)//2 gout = [[] for _ in range(V)] gin = [[] for _ in range(V)] deg = [0]*(V) for i in range(N): for j in range(N-2): gout[toid(i, A[i][j]-1)].append(toid(i, A[i][j+1]-1)) deg[toid(i, A[i][j+1]-1)] += 1 gin[toid(i, A[i][j+1]-1)].append(toid(i, A[i][j]-1)) # トポロジカルソート ans = [v for v in range(V) if deg[v]==0] deq = deque(ans) used = [0]*V while deq: v = deq.popleft() for t in gout[v]: deg[t] -= 1 if deg[t]==0: deq.append(t) ans.append(t) if any(deg): print((-1)) exit() cnt = [0]*V # cntが入り次数に達したら発火 day = [0]*V q = deque(ans) ans = 0 while q: n = q.popleft() for node in gout[n]: cnt[node] += 1 if cnt[node] == len(gin[node]): q.append(node) day[node] = day[n] + 1 ans = day[node] print((ans+1)) if __name__ == '__main__': main()
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 def main(): N = INT() A = [LIST() for _ in range(N)] match_id = [[0]*N for _ in range(N)] def toid(i, j): # 選手から試合IDに変換 if i > j: i, j = j, i return match_id[i][j] cnt = 0 for i in range(N): for j in range(N): if i < j: match_id[i][j] = cnt cnt += 1 V = N*(N-1)//2 gout = [[] for _ in range(V)] deg = [0]*(V) for i in range(N): for j in range(N-2): gout[toid(i, A[i][j]-1)].append(toid(i, A[i][j+1]-1)) deg[toid(i, A[i][j+1]-1)] += 1 topo = [v for v in range(V) if deg[v]==0] day = [0]*V deq = deque(topo) ans = 0 while deq: v = deq.popleft() for t in gout[v]: deg[t] -= 1 if deg[t]==0: deq.append(t) day[t] = day[v] + 1 ans = day[t] if any(deg): # 閉路あり print((-1)) exit() print((ans+1)) if __name__ == '__main__': main()
79
64
1,973
1,611
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 def main(): N = INT() A = [LIST() for _ in range(N)] graph_out = defaultdict(list) graph_in = defaultdict(list) match_id = [[0] * N for _ in range(N)] def toid(i, j): # 選手から試合IDに変換 if i > j: i, j = j, i return match_id[i][j] cnt = 0 for i in range(N): for j in range(N): if i < j: match_id[i][j] = cnt cnt += 1 V = N * (N - 1) // 2 gout = [[] for _ in range(V)] gin = [[] for _ in range(V)] deg = [0] * (V) for i in range(N): for j in range(N - 2): gout[toid(i, A[i][j] - 1)].append(toid(i, A[i][j + 1] - 1)) deg[toid(i, A[i][j + 1] - 1)] += 1 gin[toid(i, A[i][j + 1] - 1)].append(toid(i, A[i][j] - 1)) # トポロジカルソート ans = [v for v in range(V) if deg[v] == 0] deq = deque(ans) used = [0] * V while deq: v = deq.popleft() for t in gout[v]: deg[t] -= 1 if deg[t] == 0: deq.append(t) ans.append(t) if any(deg): print((-1)) exit() cnt = [0] * V # cntが入り次数に達したら発火 day = [0] * V q = deque(ans) ans = 0 while q: n = q.popleft() for node in gout[n]: cnt[node] += 1 if cnt[node] == len(gin[node]): q.append(node) day[node] = day[n] + 1 ans = day[node] print((ans + 1)) if __name__ == "__main__": main()
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 def main(): N = INT() A = [LIST() for _ in range(N)] match_id = [[0] * N for _ in range(N)] def toid(i, j): # 選手から試合IDに変換 if i > j: i, j = j, i return match_id[i][j] cnt = 0 for i in range(N): for j in range(N): if i < j: match_id[i][j] = cnt cnt += 1 V = N * (N - 1) // 2 gout = [[] for _ in range(V)] deg = [0] * (V) for i in range(N): for j in range(N - 2): gout[toid(i, A[i][j] - 1)].append(toid(i, A[i][j + 1] - 1)) deg[toid(i, A[i][j + 1] - 1)] += 1 topo = [v for v in range(V) if deg[v] == 0] day = [0] * V deq = deque(topo) ans = 0 while deq: v = deq.popleft() for t in gout[v]: deg[t] -= 1 if deg[t] == 0: deq.append(t) day[t] = day[v] + 1 ans = day[t] if any(deg): # 閉路あり print((-1)) exit() print((ans + 1)) if __name__ == "__main__": main()
false
18.987342
[ "- graph_out = defaultdict(list)", "- graph_in = defaultdict(list)", "- gin = [[] for _ in range(V)]", "- gin[toid(i, A[i][j + 1] - 1)].append(toid(i, A[i][j] - 1))", "- # トポロジカルソート", "- ans = [v for v in range(V) if deg[v] == 0]", "- deq = deque(ans)", "- used = [0] * V", "+ topo = [v for v in range(V) if deg[v] == 0]", "+ day = [0] * V", "+ deq = deque(topo)", "+ ans = 0", "- ans.append(t)", "- if any(deg):", "+ day[t] = day[v] + 1", "+ ans = day[t]", "+ if any(deg): # 閉路あり", "- cnt = [0] * V # cntが入り次数に達したら発火", "- day = [0] * V", "- q = deque(ans)", "- ans = 0", "- while q:", "- n = q.popleft()", "- for node in gout[n]:", "- cnt[node] += 1", "- if cnt[node] == len(gin[node]):", "- q.append(node)", "- day[node] = day[n] + 1", "- ans = day[node]" ]
false
0.045528
0.049041
0.928363
[ "s579927429", "s633166690" ]
u600402037
p02888
python
s136582700
s533517672
883
213
3,188
41,452
Accepted
Accepted
75.88
N = int(eval(input())) L = list(map(int, input().split())) L.sort() answer = 0 for i in range(N-1, 1, -1): # iは辺の最大値 s = 0 # aは1番短い辺 l = i-1 while l > s: if L[s] + L[l] > L[i]: answer += l - s l -= 1 else: s += 1 print(answer)
N = int(eval(input())) L = list(map(int, input().split())) L.sort() answer = 0 for i in range(N-1, 1, -1): # iは辺の最大値 s = 0 # sは1番短い辺 l = i-1 while l > s: if L[s] + L[l] > L[i]: answer += l - s l -= 1 else: s += 1 print(answer)
14
14
298
298
N = int(eval(input())) L = list(map(int, input().split())) L.sort() answer = 0 for i in range(N - 1, 1, -1): # iは辺の最大値 s = 0 # aは1番短い辺 l = i - 1 while l > s: if L[s] + L[l] > L[i]: answer += l - s l -= 1 else: s += 1 print(answer)
N = int(eval(input())) L = list(map(int, input().split())) L.sort() answer = 0 for i in range(N - 1, 1, -1): # iは辺の最大値 s = 0 # sは1番短い辺 l = i - 1 while l > s: if L[s] + L[l] > L[i]: answer += l - s l -= 1 else: s += 1 print(answer)
false
0
[ "- s = 0 # aは1番短い辺", "+ s = 0 # sは1番短い辺" ]
false
0.035156
0.038048
0.923976
[ "s136582700", "s533517672" ]
u279605379
p02242
python
s204881959
s139255315
40
30
6,228
5,952
Accepted
Accepted
25
from collections import deque import sys import heapq n = int(eval(input())) V = [[int(i) for i in input().split()] for _ in range(n)] dis = [sys.maxsize for _ in range(n)] dis[0] = 0 h = [] for i in range(n): heapq.heappush(h,(dis[i],i)) while(len(h)>0): node = heapq.heappop(h) tmp = node[1] for i in range(V[tmp][1]): ind = V[tmp][2*i+2] cos = V[tmp][2*i+3] if cos + dis[tmp] < dis[ind]: dis[ind] = cos + dis[tmp] heapq.heappush(h,(dis[ind],ind)) for i,j in enumerate(dis): print((i,j))
import sys import heapq n = int(eval(input())) V = [[int(i) for i in input().split()] for _ in range(n)] dis = [sys.maxsize for _ in range(n)] dis[0] = 0 h = [] for i in range(n): heapq.heappush(h,(dis[i],i)) while(len(h)>0): node = heapq.heappop(h) tmp = node[1] for i in range(V[tmp][1]): ind = V[tmp][2*i+2] cos = V[tmp][2*i+3] if cos + dis[tmp] < dis[ind]: dis[ind] = cos + dis[tmp] heapq.heappush(h,(dis[ind],ind)) for i,j in enumerate(dis): print((i,j))
21
20
570
539
from collections import deque import sys import heapq n = int(eval(input())) V = [[int(i) for i in input().split()] for _ in range(n)] dis = [sys.maxsize for _ in range(n)] dis[0] = 0 h = [] for i in range(n): heapq.heappush(h, (dis[i], i)) while len(h) > 0: node = heapq.heappop(h) tmp = node[1] for i in range(V[tmp][1]): ind = V[tmp][2 * i + 2] cos = V[tmp][2 * i + 3] if cos + dis[tmp] < dis[ind]: dis[ind] = cos + dis[tmp] heapq.heappush(h, (dis[ind], ind)) for i, j in enumerate(dis): print((i, j))
import sys import heapq n = int(eval(input())) V = [[int(i) for i in input().split()] for _ in range(n)] dis = [sys.maxsize for _ in range(n)] dis[0] = 0 h = [] for i in range(n): heapq.heappush(h, (dis[i], i)) while len(h) > 0: node = heapq.heappop(h) tmp = node[1] for i in range(V[tmp][1]): ind = V[tmp][2 * i + 2] cos = V[tmp][2 * i + 3] if cos + dis[tmp] < dis[ind]: dis[ind] = cos + dis[tmp] heapq.heappush(h, (dis[ind], ind)) for i, j in enumerate(dis): print((i, j))
false
4.761905
[ "-from collections import deque" ]
false
0.11503
0.039953
2.879128
[ "s204881959", "s139255315" ]
u994988729
p03724
python
s575129437
s525931194
639
343
15,176
5,620
Accepted
Accepted
46.32
import numpy as np import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, m = list(map(int, readline().split())) edge = np.zeros(n, dtype=int) for _ in range(m): a, b = list(map(int, readline().split())) edge[a - 1] += 1 edge[b - 1] -= 1 np.add.accumulate(edge, out=edge) if all(edge % 2 == 0): ans = "YES" else: ans = "NO" print(ans)
N, M = list(map(int, input().split())) # 木だったらなんでもOK? # いもす法 edge = [0] * (N + 1) for _ in range(M): a, b = list(map(int, input().split())) edge[a] += 1 edge[b] -= 1 ans = "YES" for i in range(N): edge[i + 1] += edge[i] if edge[i + 1] % 2 == 1: ans = "NO" break print(ans)
22
18
463
317
import numpy as np import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) n, m = list(map(int, readline().split())) edge = np.zeros(n, dtype=int) for _ in range(m): a, b = list(map(int, readline().split())) edge[a - 1] += 1 edge[b - 1] -= 1 np.add.accumulate(edge, out=edge) if all(edge % 2 == 0): ans = "YES" else: ans = "NO" print(ans)
N, M = list(map(int, input().split())) # 木だったらなんでもOK? # いもす法 edge = [0] * (N + 1) for _ in range(M): a, b = list(map(int, input().split())) edge[a] += 1 edge[b] -= 1 ans = "YES" for i in range(N): edge[i + 1] += edge[i] if edge[i + 1] % 2 == 1: ans = "NO" break print(ans)
false
18.181818
[ "-import numpy as np", "-import sys", "-", "-read = sys.stdin.buffer.read", "-readline = sys.stdin.buffer.readline", "-readlines = sys.stdin.buffer.readlines", "-sys.setrecursionlimit(10**7)", "-n, m = list(map(int, readline().split()))", "-edge = np.zeros(n, dtype=int)", "-for _ in range(m):", "- a, b = list(map(int, readline().split()))", "- edge[a - 1] += 1", "- edge[b - 1] -= 1", "-np.add.accumulate(edge, out=edge)", "-if all(edge % 2 == 0):", "- ans = \"YES\"", "-else:", "- ans = \"NO\"", "+N, M = list(map(int, input().split()))", "+# 木だったらなんでもOK?", "+# いもす法", "+edge = [0] * (N + 1)", "+for _ in range(M):", "+ a, b = list(map(int, input().split()))", "+ edge[a] += 1", "+ edge[b] -= 1", "+ans = \"YES\"", "+for i in range(N):", "+ edge[i + 1] += edge[i]", "+ if edge[i + 1] % 2 == 1:", "+ ans = \"NO\"", "+ break" ]
false
0.303747
0.042182
7.200886
[ "s575129437", "s525931194" ]
u869154953
p03631
python
s219003120
s648194273
29
25
8,908
8,960
Accepted
Accepted
13.79
N=eval(input()) if N==N[::-1]: print("Yes") else: print("No")
N=eval(input()) if N[0]==N[2]: print("Yes") else: print("No")
6
6
63
64
N = eval(input()) if N == N[::-1]: print("Yes") else: print("No")
N = eval(input()) if N[0] == N[2]: print("Yes") else: print("No")
false
0
[ "-if N == N[::-1]:", "+if N[0] == N[2]:" ]
false
0.043184
0.046358
0.931526
[ "s219003120", "s648194273" ]
u666415539
p02928
python
s351688322
s508695738
1,082
760
3,188
3,188
Accepted
Accepted
29.76
N,K=list(map(int,input().split())) a=list(map(int,input().split())) tentou1=0 for i in range(N): for j in range(i+1,N): if(a[i]>a[j]): tentou1+=1 stentou=0 for i in range(N): for j in range(N): if(a[i]>a[j]): stentou+=1 answer=int(tentou1*K + stentou*K*(K-1)//int(2)) print((answer%1000000007))
N,K=list(map(int,input().split())) a=list(map(int,input().split())) tentou1=0 for i in range(len(a)): for j in range(i+1,len(a)): if(a[i]>a[j]): tentou1+=1 a.sort() a.reverse() stentou=0 for i in range(len(a)): for j in range(i+1,len(a)): if(a[i]>a[j]): stentou+=1 answer=int(tentou1*K + int(stentou*K*(K-1)//2)) print((answer%1000000007))
15
17
327
373
N, K = list(map(int, input().split())) a = list(map(int, input().split())) tentou1 = 0 for i in range(N): for j in range(i + 1, N): if a[i] > a[j]: tentou1 += 1 stentou = 0 for i in range(N): for j in range(N): if a[i] > a[j]: stentou += 1 answer = int(tentou1 * K + stentou * K * (K - 1) // int(2)) print((answer % 1000000007))
N, K = list(map(int, input().split())) a = list(map(int, input().split())) tentou1 = 0 for i in range(len(a)): for j in range(i + 1, len(a)): if a[i] > a[j]: tentou1 += 1 a.sort() a.reverse() stentou = 0 for i in range(len(a)): for j in range(i + 1, len(a)): if a[i] > a[j]: stentou += 1 answer = int(tentou1 * K + int(stentou * K * (K - 1) // 2)) print((answer % 1000000007))
false
11.764706
[ "-for i in range(N):", "- for j in range(i + 1, N):", "+for i in range(len(a)):", "+ for j in range(i + 1, len(a)):", "+a.sort()", "+a.reverse()", "-for i in range(N):", "- for j in range(N):", "+for i in range(len(a)):", "+ for j in range(i + 1, len(a)):", "-answer = int(tentou1 * K + stentou * K * (K - 1) // int(2))", "+answer = int(tentou1 * K + int(stentou * K * (K - 1) // 2))" ]
false
0.044065
0.044548
0.989169
[ "s351688322", "s508695738" ]
u553987207
p02701
python
s609094646
s857094398
295
113
31,072
30,972
Accepted
Accepted
61.69
N = int(eval(input())) x = set() for _ in range(N): s = eval(input()) x.add(s) print((len(x)))
import sys N = int(eval(input())) x = set() for _ in range(N): s = sys.stdin.readline() x.add(s) print((len(x)))
6
7
93
118
N = int(eval(input())) x = set() for _ in range(N): s = eval(input()) x.add(s) print((len(x)))
import sys N = int(eval(input())) x = set() for _ in range(N): s = sys.stdin.readline() x.add(s) print((len(x)))
false
14.285714
[ "+import sys", "+", "- s = eval(input())", "+ s = sys.stdin.readline()" ]
false
0.036189
0.036428
0.993454
[ "s609094646", "s857094398" ]
u230621983
p03993
python
s677642415
s891281979
144
69
21,940
14,068
Accepted
Accepted
52.08
n, *a_l= list(map(int, open(0).read().split())) lovedBy = [[] for _ in range(n)] for i, a in enumerate(a_l): lovedBy[a-1].append(i) cnt = 0 for i, a in enumerate(a_l): if a-1 in lovedBy[i]: cnt += 1 print((cnt//2))
n, *a_l= list(map(int, open(0).read().split())) cnt = 0 for i, a in enumerate(a_l): if a_l[a-1] == i+1: cnt += 1 print((cnt//2))
9
6
230
137
n, *a_l = list(map(int, open(0).read().split())) lovedBy = [[] for _ in range(n)] for i, a in enumerate(a_l): lovedBy[a - 1].append(i) cnt = 0 for i, a in enumerate(a_l): if a - 1 in lovedBy[i]: cnt += 1 print((cnt // 2))
n, *a_l = list(map(int, open(0).read().split())) cnt = 0 for i, a in enumerate(a_l): if a_l[a - 1] == i + 1: cnt += 1 print((cnt // 2))
false
33.333333
[ "-lovedBy = [[] for _ in range(n)]", "-for i, a in enumerate(a_l):", "- lovedBy[a - 1].append(i)", "- if a - 1 in lovedBy[i]:", "+ if a_l[a - 1] == i + 1:" ]
false
0.037197
0.035089
1.060068
[ "s677642415", "s891281979" ]
u638902622
p03127
python
s503728291
s541302811
139
65
14,224
14,596
Accepted
Accepted
53.24
import sys IS = lambda: sys.stdin.readline().rstrip() II = lambda: int(IS()) MII = lambda: list(map(int, IS().split())) def main(): n = II() a_lst = sorted(MII(), reverse=True) while True: minv = a_lst[-1] a_lst = [a%minv for a in a_lst[:-1] if a%minv != 0] a_lst.append(minv) a_lst.sort(reverse=True) if len(a_lst) == 1: break print((a_lst[0])) if __name__ == '__main__': main()
""" keywords: 最大公約数、ユークリッドの互除法 """ import sys IS = lambda: sys.stdin.readline().rstrip() II = lambda: int(IS()) MII = lambda: list(map(int, IS().split())) from functools import reduce def gcd(a, b): while b: a, b = b, a%b return a def main(): n = II() a_lst = MII() print((reduce(gcd, a_lst))) if __name__ == '__main__': main()
18
21
457
381
import sys IS = lambda: sys.stdin.readline().rstrip() II = lambda: int(IS()) MII = lambda: list(map(int, IS().split())) def main(): n = II() a_lst = sorted(MII(), reverse=True) while True: minv = a_lst[-1] a_lst = [a % minv for a in a_lst[:-1] if a % minv != 0] a_lst.append(minv) a_lst.sort(reverse=True) if len(a_lst) == 1: break print((a_lst[0])) if __name__ == "__main__": main()
""" keywords: 最大公約数、ユークリッドの互除法 """ import sys IS = lambda: sys.stdin.readline().rstrip() II = lambda: int(IS()) MII = lambda: list(map(int, IS().split())) from functools import reduce def gcd(a, b): while b: a, b = b, a % b return a def main(): n = II() a_lst = MII() print((reduce(gcd, a_lst))) if __name__ == "__main__": main()
false
14.285714
[ "+\"\"\"", "+keywords: 最大公約数、ユークリッドの互除法", "+\"\"\"", "+from functools import reduce", "+", "+", "+def gcd(a, b):", "+ while b:", "+ a, b = b, a % b", "+ return a", "- a_lst = sorted(MII(), reverse=True)", "- while True:", "- minv = a_lst[-1]", "- a_lst = [a % minv for a in a_lst[:-1] if a % minv != 0]", "- a_lst.append(minv)", "- a_lst.sort(reverse=True)", "- if len(a_lst) == 1:", "- break", "- print((a_lst[0]))", "+ a_lst = MII()", "+ print((reduce(gcd, a_lst)))" ]
false
0.093621
0.068245
1.371836
[ "s503728291", "s541302811" ]
u812576525
p03379
python
s864621927
s094781138
349
315
25,472
25,220
Accepted
Accepted
9.74
N = int(eval(input())) A = list(map(int,input().split())) X = sorted(A,reverse=False) for i in range(N): if A[i] < X[N//2 ]: print((X[N//2 ])) else: print((X[N//2 - 1]))
N = int(eval(input())) A = list(map(int,input().split())) B = sorted(A) X = B[N//2-1] Y = B[N//2] for i in range(N): if A[i] <= X: print(Y) else: print(X)
9
12
193
186
N = int(eval(input())) A = list(map(int, input().split())) X = sorted(A, reverse=False) for i in range(N): if A[i] < X[N // 2]: print((X[N // 2])) else: print((X[N // 2 - 1]))
N = int(eval(input())) A = list(map(int, input().split())) B = sorted(A) X = B[N // 2 - 1] Y = B[N // 2] for i in range(N): if A[i] <= X: print(Y) else: print(X)
false
25
[ "-X = sorted(A, reverse=False)", "+B = sorted(A)", "+X = B[N // 2 - 1]", "+Y = B[N // 2]", "- if A[i] < X[N // 2]:", "- print((X[N // 2]))", "+ if A[i] <= X:", "+ print(Y)", "- print((X[N // 2 - 1]))", "+ print(X)" ]
false
0.046469
0.048813
0.951985
[ "s864621927", "s094781138" ]
u200887663
p02899
python
s129168209
s133465836
157
86
24,796
15,588
Accepted
Accepted
45.22
n=int(input()) al=list(map(int,input().split())) d={} for i in range(n): d[al[i]]=i+1 l=[] for k,v in sorted(d.items()): l.append(v) print(*l,sep=" ")
n=int(eval(input())) al=list(map(int,input().split())) l=[0 for i in range(n)] for i in range(n): l[al[i]-1]=str(i+1) print((" ".join(l)))
12
6
171
140
n = int(input()) al = list(map(int, input().split())) d = {} for i in range(n): d[al[i]] = i + 1 l = [] for k, v in sorted(d.items()): l.append(v) print(*l, sep=" ")
n = int(eval(input())) al = list(map(int, input().split())) l = [0 for i in range(n)] for i in range(n): l[al[i] - 1] = str(i + 1) print((" ".join(l)))
false
50
[ "-n = int(input())", "+n = int(eval(input()))", "-d = {}", "+l = [0 for i in range(n)]", "- d[al[i]] = i + 1", "-l = []", "-for k, v in sorted(d.items()):", "- l.append(v)", "-print(*l, sep=\" \")", "+ l[al[i] - 1] = str(i + 1)", "+print((\" \".join(l)))" ]
false
0.031265
0.053631
0.582959
[ "s129168209", "s133465836" ]
u683406607
p02854
python
s949062536
s599804162
447
182
36,252
26,060
Accepted
Accepted
59.28
import numpy as np n = int(eval(input())) a = list(map(int, input().split())) cum = np.cumsum(a) mid = cum[-1]/2 diff = 10**10 for each in cum: diff = min(diff, abs(mid-each)) print((int(diff/0.5)))
n = int(eval(input())) a = list(map(int, input().split())) mid = sum(a)/2 cum = 0 diff = 10**10 for each in a: cum += each diff = min(diff, abs(mid-cum)) print((int(diff/0.5)))
12
11
208
186
import numpy as np n = int(eval(input())) a = list(map(int, input().split())) cum = np.cumsum(a) mid = cum[-1] / 2 diff = 10**10 for each in cum: diff = min(diff, abs(mid - each)) print((int(diff / 0.5)))
n = int(eval(input())) a = list(map(int, input().split())) mid = sum(a) / 2 cum = 0 diff = 10**10 for each in a: cum += each diff = min(diff, abs(mid - cum)) print((int(diff / 0.5)))
false
8.333333
[ "-import numpy as np", "-", "-cum = np.cumsum(a)", "-mid = cum[-1] / 2", "+mid = sum(a) / 2", "+cum = 0", "-for each in cum:", "- diff = min(diff, abs(mid - each))", "+for each in a:", "+ cum += each", "+ diff = min(diff, abs(mid - cum))" ]
false
0.496349
0.048635
10.20559
[ "s949062536", "s599804162" ]
u633068244
p00631
python
s059795119
s265165843
2,210
70
25,716
4,248
Accepted
Accepted
96.83
while 1: n = eval(input()) if n == 0: break a = sorted(map(int,input().split()))[::-1] s = sum(a) L = [0] for i in a: L += [i+j for j in L if j < s/2] print(min(abs(s-2*i) for i in L))
def S(a,i,x,y): if 2*x >= A: return 2*x-A if 2*y >= A: return 2*y-A return min(S(a,i+1,x+a[i],y),S(a,i+1,x,y+a[i])) while 1: n = eval(input()) if n == 0: break a = sorted(map(int,input().split()))[::-1] A = sum(a) print(S(a,1,a[0],0))
9
10
198
248
while 1: n = eval(input()) if n == 0: break a = sorted(map(int, input().split()))[::-1] s = sum(a) L = [0] for i in a: L += [i + j for j in L if j < s / 2] print(min(abs(s - 2 * i) for i in L))
def S(a, i, x, y): if 2 * x >= A: return 2 * x - A if 2 * y >= A: return 2 * y - A return min(S(a, i + 1, x + a[i], y), S(a, i + 1, x, y + a[i])) while 1: n = eval(input()) if n == 0: break a = sorted(map(int, input().split()))[::-1] A = sum(a) print(S(a, 1, a[0], 0))
false
10
[ "+def S(a, i, x, y):", "+ if 2 * x >= A:", "+ return 2 * x - A", "+ if 2 * y >= A:", "+ return 2 * y - A", "+ return min(S(a, i + 1, x + a[i], y), S(a, i + 1, x, y + a[i]))", "+", "+", "- s = sum(a)", "- L = [0]", "- for i in a:", "- L += [i + j for j in L if j < s / 2]", "- print(min(abs(s - 2 * i) for i in L))", "+ A = sum(a)", "+ print(S(a, 1, a[0], 0))" ]
false
0.073715
0.034143
2.159032
[ "s059795119", "s265165843" ]
u372144784
p03164
python
s488755514
s586435190
1,046
435
311,176
120,044
Accepted
Accepted
58.41
n,w = list(map(int,input().split())) dp = [[float("inf")]*(10**5+1) for _ in range(n+1)] dp[0][0] = 0 for i in range(1,n+1): weight,value = list(map(int,input().split())) for j in range(10**5+1): if j < value: dp[i][j] = dp[i-1][j] else: dp[i][j] = min(dp[i-1][j],dp[i-1][j-value]+weight) ans = 0 for i in range(10**5+1): if dp[-1][i] <= w: ans = i print(ans)
import sys readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0 else 0 n,w = list(map(int,readline().split())) WV = [] for i in range(n): WV.append(list(map(int,readline().split()))) dp = [[10**12]*(10**5+1) for _ in range(n+1)] dp[0][0] = 0 #価値j以上で重さがwを満たすようなものの最大値 for i in range(n): for j in range(10**5+1): if WV[i][1] - j > 0: dp[i+1][j] = dp[i][j] else: dp[i+1][j] = min(dp[i][j],dp[i][j-WV[i][1]]+WV[i][0]) ans = 0 for idx,i in enumerate(dp[-1]): if i <= w: ans = idx print(ans)
19
26
429
540
n, w = list(map(int, input().split())) dp = [[float("inf")] * (10**5 + 1) for _ in range(n + 1)] dp[0][0] = 0 for i in range(1, n + 1): weight, value = list(map(int, input().split())) for j in range(10**5 + 1): if j < value: dp[i][j] = dp[i - 1][j] else: dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - value] + weight) ans = 0 for i in range(10**5 + 1): if dp[-1][i] <= w: ans = i print(ans)
import sys readline = sys.stdin.buffer.readline def even(n): return 1 if n % 2 == 0 else 0 n, w = list(map(int, readline().split())) WV = [] for i in range(n): WV.append(list(map(int, readline().split()))) dp = [[10**12] * (10**5 + 1) for _ in range(n + 1)] dp[0][0] = 0 # 価値j以上で重さがwを満たすようなものの最大値 for i in range(n): for j in range(10**5 + 1): if WV[i][1] - j > 0: dp[i + 1][j] = dp[i][j] else: dp[i + 1][j] = min(dp[i][j], dp[i][j - WV[i][1]] + WV[i][0]) ans = 0 for idx, i in enumerate(dp[-1]): if i <= w: ans = idx print(ans)
false
26.923077
[ "-n, w = list(map(int, input().split()))", "-dp = [[float(\"inf\")] * (10**5 + 1) for _ in range(n + 1)]", "+import sys", "+", "+readline = sys.stdin.buffer.readline", "+", "+", "+def even(n):", "+ return 1 if n % 2 == 0 else 0", "+", "+", "+n, w = list(map(int, readline().split()))", "+WV = []", "+for i in range(n):", "+ WV.append(list(map(int, readline().split())))", "+dp = [[10**12] * (10**5 + 1) for _ in range(n + 1)]", "-for i in range(1, n + 1):", "- weight, value = list(map(int, input().split()))", "+# 価値j以上で重さがwを満たすようなものの最大値", "+for i in range(n):", "- if j < value:", "- dp[i][j] = dp[i - 1][j]", "+ if WV[i][1] - j > 0:", "+ dp[i + 1][j] = dp[i][j]", "- dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - value] + weight)", "+ dp[i + 1][j] = min(dp[i][j], dp[i][j - WV[i][1]] + WV[i][0])", "-for i in range(10**5 + 1):", "- if dp[-1][i] <= w:", "- ans = i", "+for idx, i in enumerate(dp[-1]):", "+ if i <= w:", "+ ans = idx" ]
false
0.360491
0.493024
0.731183
[ "s488755514", "s586435190" ]
u588341295
p03354
python
s731071811
s243050034
599
554
14,008
15,968
Accepted
Accepted
7.51
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 class UnionFind: """ Union-Find木 """ def __init__(self, n): self.n = n # 親要素のノード番号を格納。par[x] == xの時そのノードは根 # 1-indexedのままでOK、その場合は[0]は未使用 self.par = [i for i in range(n+1)] # 木の高さを格納する(初期状態では0) self.rank = [0] * (n+1) # あるノードを根とする集合に属するノード数 self.size = [1] * (n+1) # あるノードを根とする集合が木かどうか self.tree = [True] * (n+1) def find(self, x): """ 根の検索(グループ番号と言えなくもない) """ # 根ならその番号を返す if self.par[x] == x: return x else: # 走査していく過程で親を書き換える self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): """ 併合 """ # 根を探す x = self.find(x) y = self.find(y) # 木かどうかの判定用 if x == y: self.tree[x] = False return if not self.tree[x] or not self.tree[y]: self.tree[x] = self.tree[y] = False # 木の高さを比較し、低いほうから高いほうに辺を張る if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] # 木の高さが同じなら片方を1増やす if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): """ 同じ集合に属するか判定 """ return self.find(x) == self.find(y) def get_size(self, x): """ あるノードの属する集合のノード数 """ return self.size[self.find(x)] def is_tree(self, x): """ 木かどうかの判定 """ return self.tree[self.find(x)] def len(self): """ 集合の数 """ res = set() for i in range(self.n+1): res.add(self.find(i)) # グループ0の分を引いて返却 return len(res) - 1 N, M = MAP() P = [p-1 for p in LIST()] uf = UnionFind(N) for i in range(M): a, b = MAP() a -= 1 b -= 1 uf.union(P[a], P[b]) cnt = 0 for i in range(N): p = P[i] if uf.same(p, i): cnt += 1 print(cnt)
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 class UnionFind: """ Union-Find木 """ def __init__(self, n): self.n = n # 親要素のノード番号を格納。par[x] == xの時そのノードは根 # 1-indexedのままでOK、その場合は[0]は未使用 self.par = [i for i in range(n+1)] # 木の高さを格納する(初期状態では0) self.rank = [0] * (n+1) # あるノードを根とする集合に属するノード数 self.size = [1] * (n+1) # あるノードを根とする集合が木かどうか self.tree = [True] * (n+1) def find(self, x): """ 根の検索(グループ番号と言えなくもない) """ # 根ならその番号を返す if self.par[x] == x: return x else: # 走査していく過程で親を書き換える self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): """ 併合 """ # 根を探す x = self.find(x) y = self.find(y) # 木かどうかの判定用 if x == y: self.tree[x] = False return if not self.tree[x] or not self.tree[y]: self.tree[x] = self.tree[y] = False # 木の高さを比較し、低いほうから高いほうに辺を張る if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] # 木の高さが同じなら片方を1増やす if self.rank[x] == self.rank[y]: self.rank[x] += 1 def is_same(self, x, y): """ 同じ集合に属するか判定 """ return self.find(x) == self.find(y) def get_size(self, x=None): if x is not None: """ あるノードの属する集合のノード数 """ return self.size[self.find(x)] else: """ 集合の数 """ res = set() for i in range(self.n+1): res.add(self.find(i)) # グループ0の分を引いて返却 return len(res) - 1 def is_tree(self, x): """ 木かどうかの判定 """ return self.tree[self.find(x)] N, M = MAP() A = LIST() uf = UnionFind(N) for i in range(M): a, b = MAP() uf.union(a, b) ans = 0 for i, a in enumerate(A): # UnionFindが繋がっているなら、スワップを繰り返してその場所に移動できる if uf.is_same(i+1, a): ans += 1 print(ans)
105
102
2,791
2,845
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 class UnionFind: """Union-Find木""" def __init__(self, n): self.n = n # 親要素のノード番号を格納。par[x] == xの時そのノードは根 # 1-indexedのままでOK、その場合は[0]は未使用 self.par = [i for i in range(n + 1)] # 木の高さを格納する(初期状態では0) self.rank = [0] * (n + 1) # あるノードを根とする集合に属するノード数 self.size = [1] * (n + 1) # あるノードを根とする集合が木かどうか self.tree = [True] * (n + 1) def find(self, x): """根の検索(グループ番号と言えなくもない)""" # 根ならその番号を返す if self.par[x] == x: return x else: # 走査していく過程で親を書き換える self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): """併合""" # 根を探す x = self.find(x) y = self.find(y) # 木かどうかの判定用 if x == y: self.tree[x] = False return if not self.tree[x] or not self.tree[y]: self.tree[x] = self.tree[y] = False # 木の高さを比較し、低いほうから高いほうに辺を張る if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] # 木の高さが同じなら片方を1増やす if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): """同じ集合に属するか判定""" return self.find(x) == self.find(y) def get_size(self, x): """あるノードの属する集合のノード数""" return self.size[self.find(x)] def is_tree(self, x): """木かどうかの判定""" return self.tree[self.find(x)] def len(self): """集合の数""" res = set() for i in range(self.n + 1): res.add(self.find(i)) # グループ0の分を引いて返却 return len(res) - 1 N, M = MAP() P = [p - 1 for p in LIST()] uf = UnionFind(N) for i in range(M): a, b = MAP() a -= 1 b -= 1 uf.union(P[a], P[b]) cnt = 0 for i in range(N): p = P[i] if uf.same(p, i): cnt += 1 print(cnt)
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 class UnionFind: """Union-Find木""" def __init__(self, n): self.n = n # 親要素のノード番号を格納。par[x] == xの時そのノードは根 # 1-indexedのままでOK、その場合は[0]は未使用 self.par = [i for i in range(n + 1)] # 木の高さを格納する(初期状態では0) self.rank = [0] * (n + 1) # あるノードを根とする集合に属するノード数 self.size = [1] * (n + 1) # あるノードを根とする集合が木かどうか self.tree = [True] * (n + 1) def find(self, x): """根の検索(グループ番号と言えなくもない)""" # 根ならその番号を返す if self.par[x] == x: return x else: # 走査していく過程で親を書き換える self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): """併合""" # 根を探す x = self.find(x) y = self.find(y) # 木かどうかの判定用 if x == y: self.tree[x] = False return if not self.tree[x] or not self.tree[y]: self.tree[x] = self.tree[y] = False # 木の高さを比較し、低いほうから高いほうに辺を張る if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] # 木の高さが同じなら片方を1増やす if self.rank[x] == self.rank[y]: self.rank[x] += 1 def is_same(self, x, y): """同じ集合に属するか判定""" return self.find(x) == self.find(y) def get_size(self, x=None): if x is not None: """あるノードの属する集合のノード数""" return self.size[self.find(x)] else: """集合の数""" res = set() for i in range(self.n + 1): res.add(self.find(i)) # グループ0の分を引いて返却 return len(res) - 1 def is_tree(self, x): """木かどうかの判定""" return self.tree[self.find(x)] N, M = MAP() A = LIST() uf = UnionFind(N) for i in range(M): a, b = MAP() uf.union(a, b) ans = 0 for i, a in enumerate(A): # UnionFindが繋がっているなら、スワップを繰り返してその場所に移動できる if uf.is_same(i + 1, a): ans += 1 print(ans)
false
2.857143
[ "-INF = float(\"inf\")", "+INF = 10**18", "- def same(self, x, y):", "+ def is_same(self, x, y):", "- def get_size(self, x):", "- \"\"\"あるノードの属する集合のノード数\"\"\"", "- return self.size[self.find(x)]", "+ def get_size(self, x=None):", "+ if x is not None:", "+ \"\"\"あるノードの属する集合のノード数\"\"\"", "+ return self.size[self.find(x)]", "+ else:", "+ \"\"\"集合の数\"\"\"", "+ res = set()", "+ for i in range(self.n + 1):", "+ res.add(self.find(i))", "+ # グループ0の分を引いて返却", "+ return len(res) - 1", "- def len(self):", "- \"\"\"集合の数\"\"\"", "- res = set()", "- for i in range(self.n + 1):", "- res.add(self.find(i))", "- # グループ0の分を引いて返却", "- return len(res) - 1", "-", "-P = [p - 1 for p in LIST()]", "+A = LIST()", "- a -= 1", "- b -= 1", "- uf.union(P[a], P[b])", "-cnt = 0", "-for i in range(N):", "- p = P[i]", "- if uf.same(p, i):", "- cnt += 1", "-print(cnt)", "+ uf.union(a, b)", "+ans = 0", "+for i, a in enumerate(A):", "+ # UnionFindが繋がっているなら、スワップを繰り返してその場所に移動できる", "+ if uf.is_same(i + 1, a):", "+ ans += 1", "+print(ans)" ]
false
0.038707
0.04188
0.924242
[ "s731071811", "s243050034" ]
u098012509
p02627
python
s500379755
s620252613
31
25
9,092
9,020
Accepted
Accepted
19.35
import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): S = input().strip() if ord('A') <= ord(S[0]) <= ord('Z'): print("A") else: print("a") if __name__ == '__main__': main()
import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): S = input().strip() if S.islower(): print("a") else: print("A") if __name__ == '__main__': main()
19
20
259
239
import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline def main(): S = input().strip() if ord("A") <= ord(S[0]) <= ord("Z"): print("A") else: print("a") if __name__ == "__main__": main()
import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline def main(): S = input().strip() if S.islower(): print("a") else: print("A") if __name__ == "__main__": main()
false
5
[ "- if ord(\"A\") <= ord(S[0]) <= ord(\"Z\"):", "+ if S.islower():", "+ print(\"a\")", "+ else:", "- else:", "- print(\"a\")" ]
false
0.042399
0.03554
1.192964
[ "s500379755", "s620252613" ]
u582415761
p03127
python
s141689659
s575667729
213
75
25,008
14,252
Accepted
Accepted
64.79
from sys import stdin import numpy as np #import math as math import fractions as math N = int(stdin.readline()) A = list(map(int,stdin.readline().strip().split())) ans = A[0] for i in range(1,N): ans = math.gcd(ans,A[i]) print(ans)
from sys import stdin def gcd(a, b): while b: a, b = b, a % b return a N = int(stdin.readline()) A = list(map(int,stdin.readline().strip().split())) ans = A[0] for i in range(1,N): ans = gcd(ans,A[i]) print(ans)
14
15
253
250
from sys import stdin import numpy as np # import math as math import fractions as math N = int(stdin.readline()) A = list(map(int, stdin.readline().strip().split())) ans = A[0] for i in range(1, N): ans = math.gcd(ans, A[i]) print(ans)
from sys import stdin def gcd(a, b): while b: a, b = b, a % b return a N = int(stdin.readline()) A = list(map(int, stdin.readline().strip().split())) ans = A[0] for i in range(1, N): ans = gcd(ans, A[i]) print(ans)
false
6.666667
[ "-import numpy as np", "-# import math as math", "-import fractions as math", "+", "+def gcd(a, b):", "+ while b:", "+ a, b = b, a % b", "+ return a", "+", "- ans = math.gcd(ans, A[i])", "+ ans = gcd(ans, A[i])" ]
false
0.045997
0.036166
1.271836
[ "s141689659", "s575667729" ]
u657361950
p02273
python
s416737462
s573586253
40
30
5,724
5,736
Accepted
Accepted
25
import math class Pos: def __init__(self, x, y): self.x = x self.y = y def __str__(self): return str(self.x) + ' ' + str(self.y) def koch_curve(i, n, start, end): if i < n: f = get_pos(start, end, 1/3) t = get_pos(start, end, 2/3) s = get_sec_pos(start, end, f, t) koch_curve(i + 1, n, start, f) print(f) koch_curve(i + 1, n, f, s) print(s) koch_curve(i + 1, n, s, t) print(t) koch_curve(i + 1, n, t, end) def get_pos(start, end, m): dX = (end.x - start.x) * m dY = (end.y - start.y) * m return Pos(start.x + dX, start.y + dY) def get_sec_pos(start, end, f, t): if f.y == t.y: x = start.x + (end.x - start.x) / 2 len = math.fabs(t.x - f.x) h = math.sqrt(len**2 - (len/2)**2) if start.x < end.x: y = start.y + h else: y = start.y - h elif f.x < t.x and f.y < t.y: x = start.x y = t.y elif f.x > t.x and f.y < t.y: x = end.x y = f.y elif f.x > t.x and f.y > t.y: x = start.x y = t.y else: x = end.x y = f.y return Pos(x, y) n = int(eval(input())) start = Pos(0, 0) end = Pos(100, 0) print(start) koch_curve(0, n, start, end) print(end)
import math class Point: def __init__(self,x,y): self.x=x self.y=y def __str__(self): return str(self.x)+' '+str(self.y) def koch(n,a,b): if n==0: return s=Point(0,0) t=Point(0,0) u=Point(0,0) th=math.pi*60/180 s.x=(2*a.x+1*b.x)/3 s.y=(2*a.y+1*b.y)/3 t.x=(1*a.x+2*b.x)/3 t.y=(1*a.y+2*b.y)/3 u.x=(t.x-s.x)*math.cos(th)-(t.y-s.y)*math.sin(th)+s.x u.y=(t.x-s.x)*math.sin(th)+(t.y-s.y)*math.cos(th)+s.y koch(n-1,a,s) print(s) koch(n-1,s,u) print(u) koch(n-1,u,t) print(t) koch(n-1,t,b) n=int(eval(input())) a=Point(0,0) b=Point(100,0) print(a) koch(n,a,b) print(b)
57
36
1,161
622
import math class Pos: def __init__(self, x, y): self.x = x self.y = y def __str__(self): return str(self.x) + " " + str(self.y) def koch_curve(i, n, start, end): if i < n: f = get_pos(start, end, 1 / 3) t = get_pos(start, end, 2 / 3) s = get_sec_pos(start, end, f, t) koch_curve(i + 1, n, start, f) print(f) koch_curve(i + 1, n, f, s) print(s) koch_curve(i + 1, n, s, t) print(t) koch_curve(i + 1, n, t, end) def get_pos(start, end, m): dX = (end.x - start.x) * m dY = (end.y - start.y) * m return Pos(start.x + dX, start.y + dY) def get_sec_pos(start, end, f, t): if f.y == t.y: x = start.x + (end.x - start.x) / 2 len = math.fabs(t.x - f.x) h = math.sqrt(len**2 - (len / 2) ** 2) if start.x < end.x: y = start.y + h else: y = start.y - h elif f.x < t.x and f.y < t.y: x = start.x y = t.y elif f.x > t.x and f.y < t.y: x = end.x y = f.y elif f.x > t.x and f.y > t.y: x = start.x y = t.y else: x = end.x y = f.y return Pos(x, y) n = int(eval(input())) start = Pos(0, 0) end = Pos(100, 0) print(start) koch_curve(0, n, start, end) print(end)
import math class Point: def __init__(self, x, y): self.x = x self.y = y def __str__(self): return str(self.x) + " " + str(self.y) def koch(n, a, b): if n == 0: return s = Point(0, 0) t = Point(0, 0) u = Point(0, 0) th = math.pi * 60 / 180 s.x = (2 * a.x + 1 * b.x) / 3 s.y = (2 * a.y + 1 * b.y) / 3 t.x = (1 * a.x + 2 * b.x) / 3 t.y = (1 * a.y + 2 * b.y) / 3 u.x = (t.x - s.x) * math.cos(th) - (t.y - s.y) * math.sin(th) + s.x u.y = (t.x - s.x) * math.sin(th) + (t.y - s.y) * math.cos(th) + s.y koch(n - 1, a, s) print(s) koch(n - 1, s, u) print(u) koch(n - 1, u, t) print(t) koch(n - 1, t, b) n = int(eval(input())) a = Point(0, 0) b = Point(100, 0) print(a) koch(n, a, b) print(b)
false
36.842105
[ "-class Pos:", "+class Point:", "-def koch_curve(i, n, start, end):", "- if i < n:", "- f = get_pos(start, end, 1 / 3)", "- t = get_pos(start, end, 2 / 3)", "- s = get_sec_pos(start, end, f, t)", "- koch_curve(i + 1, n, start, f)", "- print(f)", "- koch_curve(i + 1, n, f, s)", "- print(s)", "- koch_curve(i + 1, n, s, t)", "- print(t)", "- koch_curve(i + 1, n, t, end)", "-", "-", "-def get_pos(start, end, m):", "- dX = (end.x - start.x) * m", "- dY = (end.y - start.y) * m", "- return Pos(start.x + dX, start.y + dY)", "-", "-", "-def get_sec_pos(start, end, f, t):", "- if f.y == t.y:", "- x = start.x + (end.x - start.x) / 2", "- len = math.fabs(t.x - f.x)", "- h = math.sqrt(len**2 - (len / 2) ** 2)", "- if start.x < end.x:", "- y = start.y + h", "- else:", "- y = start.y - h", "- elif f.x < t.x and f.y < t.y:", "- x = start.x", "- y = t.y", "- elif f.x > t.x and f.y < t.y:", "- x = end.x", "- y = f.y", "- elif f.x > t.x and f.y > t.y:", "- x = start.x", "- y = t.y", "- else:", "- x = end.x", "- y = f.y", "- return Pos(x, y)", "+def koch(n, a, b):", "+ if n == 0:", "+ return", "+ s = Point(0, 0)", "+ t = Point(0, 0)", "+ u = Point(0, 0)", "+ th = math.pi * 60 / 180", "+ s.x = (2 * a.x + 1 * b.x) / 3", "+ s.y = (2 * a.y + 1 * b.y) / 3", "+ t.x = (1 * a.x + 2 * b.x) / 3", "+ t.y = (1 * a.y + 2 * b.y) / 3", "+ u.x = (t.x - s.x) * math.cos(th) - (t.y - s.y) * math.sin(th) + s.x", "+ u.y = (t.x - s.x) * math.sin(th) + (t.y - s.y) * math.cos(th) + s.y", "+ koch(n - 1, a, s)", "+ print(s)", "+ koch(n - 1, s, u)", "+ print(u)", "+ koch(n - 1, u, t)", "+ print(t)", "+ koch(n - 1, t, b)", "-start = Pos(0, 0)", "-end = Pos(100, 0)", "-print(start)", "-koch_curve(0, n, start, end)", "-print(end)", "+a = Point(0, 0)", "+b = Point(100, 0)", "+print(a)", "+koch(n, a, b)", "+print(b)" ]
false
0.051263
0.05163
0.992896
[ "s416737462", "s573586253" ]
u102461423
p03821
python
s975943061
s802331666
201
150
21,876
27,688
Accepted
Accepted
25.37
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) # 右から N = int(eval(input())) AB = [[int(x) for x in input().split()] for _ in range(N)] push = 0 for a,b in AB[::-1]: a += push push += (-a)%b print(push)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) m = list(map(int,read().split())) A,B = list(zip(*list(zip(m,m)))) # 末尾から add = 0 for a,b in zip(A[::-1],B[::-1]): a += add add += (-a) % b print(add)
13
17
239
296
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) # 右から N = int(eval(input())) AB = [[int(x) for x in input().split()] for _ in range(N)] push = 0 for a, b in AB[::-1]: a += push push += (-a) % b print(push)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) m = list(map(int, read().split())) A, B = list(zip(*list(zip(m, m)))) # 末尾から add = 0 for a, b in zip(A[::-1], B[::-1]): a += add add += (-a) % b print(add)
false
23.529412
[ "-input = sys.stdin.readline", "-sys.setrecursionlimit(10**7)", "-# 右から", "-N = int(eval(input()))", "-AB = [[int(x) for x in input().split()] for _ in range(N)]", "-push = 0", "-for a, b in AB[::-1]:", "- a += push", "- push += (-a) % b", "-print(push)", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+N = int(readline())", "+m = list(map(int, read().split()))", "+A, B = list(zip(*list(zip(m, m))))", "+# 末尾から", "+add = 0", "+for a, b in zip(A[::-1], B[::-1]):", "+ a += add", "+ add += (-a) % b", "+print(add)" ]
false
0.042698
0.041688
1.024206
[ "s975943061", "s802331666" ]
u317779196
p03998
python
s591171523
s168332729
31
25
9,312
8,984
Accepted
Accepted
19.35
from collections import deque a = deque(eval(input())) b = deque(eval(input())) c = deque(eval(input())) i = 0 turn = 'a' while True: if turn == 'a': if len(a) == 0: ans = 'A' break a0 = a.popleft() if a0 == 'a': turn = 'a' elif a0 == 'b': turn = 'b' elif a0 == 'c': turn = 'c' elif turn == 'b': if len(b) == 0: ans = 'B' break b0 = b.popleft() if b0 == 'a': turn = 'a' elif b0 == 'b': turn = 'b' elif b0 == 'c': turn = 'c' elif turn == 'c': if len(c) == 0: ans = 'C' break c0 = c.popleft() if c0 == 'a': turn = 'a' elif c0 == 'b': turn = 'b' elif c0 == 'c': turn = 'c' print(ans)
S = dict() S['a'] = list(eval(input()))[::-1] S['b'] = list(eval(input()))[::-1] S['c'] = list(eval(input()))[::-1] p = 'a' while S[p]: p = S[p].pop() print((p.upper()))
42
9
916
162
from collections import deque a = deque(eval(input())) b = deque(eval(input())) c = deque(eval(input())) i = 0 turn = "a" while True: if turn == "a": if len(a) == 0: ans = "A" break a0 = a.popleft() if a0 == "a": turn = "a" elif a0 == "b": turn = "b" elif a0 == "c": turn = "c" elif turn == "b": if len(b) == 0: ans = "B" break b0 = b.popleft() if b0 == "a": turn = "a" elif b0 == "b": turn = "b" elif b0 == "c": turn = "c" elif turn == "c": if len(c) == 0: ans = "C" break c0 = c.popleft() if c0 == "a": turn = "a" elif c0 == "b": turn = "b" elif c0 == "c": turn = "c" print(ans)
S = dict() S["a"] = list(eval(input()))[::-1] S["b"] = list(eval(input()))[::-1] S["c"] = list(eval(input()))[::-1] p = "a" while S[p]: p = S[p].pop() print((p.upper()))
false
78.571429
[ "-from collections import deque", "-", "-a = deque(eval(input()))", "-b = deque(eval(input()))", "-c = deque(eval(input()))", "-i = 0", "-turn = \"a\"", "-while True:", "- if turn == \"a\":", "- if len(a) == 0:", "- ans = \"A\"", "- break", "- a0 = a.popleft()", "- if a0 == \"a\":", "- turn = \"a\"", "- elif a0 == \"b\":", "- turn = \"b\"", "- elif a0 == \"c\":", "- turn = \"c\"", "- elif turn == \"b\":", "- if len(b) == 0:", "- ans = \"B\"", "- break", "- b0 = b.popleft()", "- if b0 == \"a\":", "- turn = \"a\"", "- elif b0 == \"b\":", "- turn = \"b\"", "- elif b0 == \"c\":", "- turn = \"c\"", "- elif turn == \"c\":", "- if len(c) == 0:", "- ans = \"C\"", "- break", "- c0 = c.popleft()", "- if c0 == \"a\":", "- turn = \"a\"", "- elif c0 == \"b\":", "- turn = \"b\"", "- elif c0 == \"c\":", "- turn = \"c\"", "-print(ans)", "+S = dict()", "+S[\"a\"] = list(eval(input()))[::-1]", "+S[\"b\"] = list(eval(input()))[::-1]", "+S[\"c\"] = list(eval(input()))[::-1]", "+p = \"a\"", "+while S[p]:", "+ p = S[p].pop()", "+print((p.upper()))" ]
false
0.043386
0.043788
0.990822
[ "s591171523", "s168332729" ]
u954858867
p02412
python
s457428846
s070252348
290
30
6,392
6,444
Accepted
Accepted
89.66
ret = [] while True: n, x = list(map(int, input().split())) num_arr = [i for i in range(1, n+1)] if (n, x) == (0, 0): break cnt = 0 for i in range(n, 0, -1): if x - i <= 2: continue #print "i : %d" % i for j in range(i -1, 0, -1): if x-i-j <= 0: continue #print "j : %d" % j for k in range(j - 1, 0 , -1): if x-i-j-k < 0: continue if x -i-j-k == 0: cnt += 1 #print "k : %d" % k break ret += [cnt] for i in ret: print(i)
ret = [] while True: n, x = list(map(int, input().split())) num_arr = [i for i in range(1, n+1)] if (n, x) == (0, 0): break cnt = 0 for i in range(n, 0, -1): for j in range(i -1, 0, -1): if 0 < x - i - j < j: cnt += 1 ret += [cnt] for i in ret: print(i)
26
16
647
339
ret = [] while True: n, x = list(map(int, input().split())) num_arr = [i for i in range(1, n + 1)] if (n, x) == (0, 0): break cnt = 0 for i in range(n, 0, -1): if x - i <= 2: continue # print "i : %d" % i for j in range(i - 1, 0, -1): if x - i - j <= 0: continue # print "j : %d" % j for k in range(j - 1, 0, -1): if x - i - j - k < 0: continue if x - i - j - k == 0: cnt += 1 # print "k : %d" % k break ret += [cnt] for i in ret: print(i)
ret = [] while True: n, x = list(map(int, input().split())) num_arr = [i for i in range(1, n + 1)] if (n, x) == (0, 0): break cnt = 0 for i in range(n, 0, -1): for j in range(i - 1, 0, -1): if 0 < x - i - j < j: cnt += 1 ret += [cnt] for i in ret: print(i)
false
38.461538
[ "- if x - i <= 2:", "- continue", "- # print \"i : %d\" % i", "- if x - i - j <= 0:", "- continue", "- # print \"j : %d\" % j", "- for k in range(j - 1, 0, -1):", "- if x - i - j - k < 0:", "- continue", "- if x - i - j - k == 0:", "- cnt += 1", "- # print \"k : %d\" % k", "- break", "+ if 0 < x - i - j < j:", "+ cnt += 1" ]
false
0.163171
0.043401
3.759593
[ "s457428846", "s070252348" ]
u046187684
p02660
python
s171142448
s657288702
230
101
20,224
9,424
Accepted
Accepted
56.09
def find_primes(n): ps = [] t = [True] * n t[0] = t[1] = False for i in range(2, n): if not t[i]: continue ps.append(i) for j in range(i, n, i): t[j] = False return ps def solve(string): n = int(string) if n == 1: return "0" rn = int(n**0.5 + 1) ps = find_primes(rn) ans = 0 for i in ps: k = 1 while n % (i**k) == 0: ans += 1 n //= i**k k += 1 return str(ans + (n >= rn)) if __name__ == '__main__': import sys print((solve(sys.stdin.read().strip())))
import collections n = int(eval(input())) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a if n == 1: # 1 print((0)) exit() c = collections.Counter(prime_factorize(n)) _, counts = list(zip(*c.most_common())) l = list(counts) ans = 0 if l == [1]: # prime number print((1)) exit() for i in l: for j in range(1, i+1): if i >= j: i -= j ans += 1 print(ans)
32
41
648
661
def find_primes(n): ps = [] t = [True] * n t[0] = t[1] = False for i in range(2, n): if not t[i]: continue ps.append(i) for j in range(i, n, i): t[j] = False return ps def solve(string): n = int(string) if n == 1: return "0" rn = int(n**0.5 + 1) ps = find_primes(rn) ans = 0 for i in ps: k = 1 while n % (i**k) == 0: ans += 1 n //= i**k k += 1 return str(ans + (n >= rn)) if __name__ == "__main__": import sys print((solve(sys.stdin.read().strip())))
import collections n = int(eval(input())) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a if n == 1: # 1 print((0)) exit() c = collections.Counter(prime_factorize(n)) _, counts = list(zip(*c.most_common())) l = list(counts) ans = 0 if l == [1]: # prime number print((1)) exit() for i in l: for j in range(1, i + 1): if i >= j: i -= j ans += 1 print(ans)
false
21.95122
[ "-def find_primes(n):", "- ps = []", "- t = [True] * n", "- t[0] = t[1] = False", "- for i in range(2, n):", "- if not t[i]:", "- continue", "- ps.append(i)", "- for j in range(i, n, i):", "- t[j] = False", "- return ps", "+import collections", "+", "+n = int(eval(input()))", "-def solve(string):", "- n = int(string)", "- if n == 1:", "- return \"0\"", "- rn = int(n**0.5 + 1)", "- ps = find_primes(rn)", "- ans = 0", "- for i in ps:", "- k = 1", "- while n % (i**k) == 0:", "- ans += 1", "- n //= i**k", "- k += 1", "- return str(ans + (n >= rn))", "+def prime_factorize(n):", "+ a = []", "+ while n % 2 == 0:", "+ a.append(2)", "+ n //= 2", "+ f = 3", "+ while f * f <= n:", "+ if n % f == 0:", "+ a.append(f)", "+ n //= f", "+ else:", "+ f += 2", "+ if n != 1:", "+ a.append(n)", "+ return a", "-if __name__ == \"__main__\":", "- import sys", "-", "- print((solve(sys.stdin.read().strip())))", "+if n == 1: # 1", "+ print((0))", "+ exit()", "+c = collections.Counter(prime_factorize(n))", "+_, counts = list(zip(*c.most_common()))", "+l = list(counts)", "+ans = 0", "+if l == [1]: # prime number", "+ print((1))", "+ exit()", "+for i in l:", "+ for j in range(1, i + 1):", "+ if i >= j:", "+ i -= j", "+ ans += 1", "+print(ans)" ]
false
0.085063
0.037713
2.255505
[ "s171142448", "s657288702" ]
u440161695
p03107
python
s380665176
s703980325
64
26
4,212
3,444
Accepted
Accepted
59.38
from collections import deque s=deque(eval(input())) N=len(s) A=[] for i in range(N): a=s.popleft() if len(A)!=0: if A[-1]!=a: A.pop() else: A.append(a) else: A.append(a) print((N-len(A)))
from collections import Counter d={chr(i):0 for i in range(2)} s=Counter(eval(input())) d=d.update(s) print((min(s["0"],s["1"])*2))
14
5
223
127
from collections import deque s = deque(eval(input())) N = len(s) A = [] for i in range(N): a = s.popleft() if len(A) != 0: if A[-1] != a: A.pop() else: A.append(a) else: A.append(a) print((N - len(A)))
from collections import Counter d = {chr(i): 0 for i in range(2)} s = Counter(eval(input())) d = d.update(s) print((min(s["0"], s["1"]) * 2))
false
64.285714
[ "-from collections import deque", "+from collections import Counter", "-s = deque(eval(input()))", "-N = len(s)", "-A = []", "-for i in range(N):", "- a = s.popleft()", "- if len(A) != 0:", "- if A[-1] != a:", "- A.pop()", "- else:", "- A.append(a)", "- else:", "- A.append(a)", "-print((N - len(A)))", "+d = {chr(i): 0 for i in range(2)}", "+s = Counter(eval(input()))", "+d = d.update(s)", "+print((min(s[\"0\"], s[\"1\"]) * 2))" ]
false
0.008688
0.033695
0.257854
[ "s380665176", "s703980325" ]
u597374218
p02952
python
s476795169
s350706070
62
49
2,940
2,940
Accepted
Accepted
20.97
N=int(eval(input())) count=0 for i in range(1,N+1): if len(str(i))%2==1:count+=1 print(count)
N=int(eval(input())) print((sum(len(str(i))%2==1 for i in range(1,N+1))))
5
2
95
66
N = int(eval(input())) count = 0 for i in range(1, N + 1): if len(str(i)) % 2 == 1: count += 1 print(count)
N = int(eval(input())) print((sum(len(str(i)) % 2 == 1 for i in range(1, N + 1))))
false
60
[ "-count = 0", "-for i in range(1, N + 1):", "- if len(str(i)) % 2 == 1:", "- count += 1", "-print(count)", "+print((sum(len(str(i)) % 2 == 1 for i in range(1, N + 1))))" ]
false
0.043423
0.047544
0.913324
[ "s476795169", "s350706070" ]
u426764965
p03295
python
s653020369
s906171964
859
250
24,676
24,740
Accepted
Accepted
70.9
N, M = list(map(int, input().split())) Q = [tuple(map(int, input().split())) for _ in range(M)] # 右側が小さい順にソート、制約a<bなのでそのまま使ってよい Q = sorted(Q, key=lambda x: x[1]) # 境界、右側の区間の始まり border = [] for a, b in Q: flag = True for x in border: # 既存の境界で分けられるか if a < x and x <= b: flag = False break if flag: border.append(b) ans = len(border) print(ans)
N, M = list(map(int, input().split())) Q = [tuple(map(int, input().split())) for _ in range(M)] # 右側が小さい順にソート、制約a<bなのでそのまま使ってよい Q = sorted(Q, key=lambda x: x[1]) # 境界、右側の区間の始まり border = -1 ans = 0 for a, b in Q: # 既存の境界で分けられないときは右にずらす if border <= a: ans += 1 border = b print(ans)
20
16
418
317
N, M = list(map(int, input().split())) Q = [tuple(map(int, input().split())) for _ in range(M)] # 右側が小さい順にソート、制約a<bなのでそのまま使ってよい Q = sorted(Q, key=lambda x: x[1]) # 境界、右側の区間の始まり border = [] for a, b in Q: flag = True for x in border: # 既存の境界で分けられるか if a < x and x <= b: flag = False break if flag: border.append(b) ans = len(border) print(ans)
N, M = list(map(int, input().split())) Q = [tuple(map(int, input().split())) for _ in range(M)] # 右側が小さい順にソート、制約a<bなのでそのまま使ってよい Q = sorted(Q, key=lambda x: x[1]) # 境界、右側の区間の始まり border = -1 ans = 0 for a, b in Q: # 既存の境界で分けられないときは右にずらす if border <= a: ans += 1 border = b print(ans)
false
20
[ "-border = []", "+border = -1", "+ans = 0", "- flag = True", "- for x in border:", "- # 既存の境界で分けられるか", "- if a < x and x <= b:", "- flag = False", "- break", "- if flag:", "- border.append(b)", "-ans = len(border)", "+ # 既存の境界で分けられないときは右にずらす", "+ if border <= a:", "+ ans += 1", "+ border = b" ]
false
0.038042
0.096982
0.392254
[ "s653020369", "s906171964" ]
u422104747
p03295
python
s455153972
s360143579
446
401
17,008
16,996
Accepted
Accepted
10.09
n,m=input().split() n=int(n) m=int(m) l=[] for i in range(m): t=input().split() l.append((int(t[0]),int(t[1]))) l.sort() i=0 res=0 flag=False while True: ra=l[i][1] while l[i][0]<ra: if i==m-1: flag=True break ra=min(ra,l[i][1]) i+=1 res+=1 if flag: break print(res)
s=input().split() n=int(s[0]) m=int(s[1]) l=[] for i in range(m): s=input().split() l.append((int(s[1]),int(s[0]))) l.sort() o=[] for p in l: if len(o)>0 and p[0]>=o[-1]>p[1]: continue else: o.append(p[0]) print((len(o)))
23
15
369
266
n, m = input().split() n = int(n) m = int(m) l = [] for i in range(m): t = input().split() l.append((int(t[0]), int(t[1]))) l.sort() i = 0 res = 0 flag = False while True: ra = l[i][1] while l[i][0] < ra: if i == m - 1: flag = True break ra = min(ra, l[i][1]) i += 1 res += 1 if flag: break print(res)
s = input().split() n = int(s[0]) m = int(s[1]) l = [] for i in range(m): s = input().split() l.append((int(s[1]), int(s[0]))) l.sort() o = [] for p in l: if len(o) > 0 and p[0] >= o[-1] > p[1]: continue else: o.append(p[0]) print((len(o)))
false
34.782609
[ "-n, m = input().split()", "-n = int(n)", "-m = int(m)", "+s = input().split()", "+n = int(s[0])", "+m = int(s[1])", "- t = input().split()", "- l.append((int(t[0]), int(t[1])))", "+ s = input().split()", "+ l.append((int(s[1]), int(s[0])))", "-i = 0", "-res = 0", "-flag = False", "-while True:", "- ra = l[i][1]", "- while l[i][0] < ra:", "- if i == m - 1:", "- flag = True", "- break", "- ra = min(ra, l[i][1])", "- i += 1", "- res += 1", "- if flag:", "- break", "-print(res)", "+o = []", "+for p in l:", "+ if len(o) > 0 and p[0] >= o[-1] > p[1]:", "+ continue", "+ else:", "+ o.append(p[0])", "+print((len(o)))" ]
false
0.036862
0.037635
0.97946
[ "s455153972", "s360143579" ]
u631277801
p03032
python
s644247512
s319378177
210
36
42,984
3,064
Accepted
Accepted
82.86
import sys stdin = sys.stdin sys.setrecursionlimit(10 ** 7) 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()) from heapq import heappop n, k = li() v = list(li()) ans = 0 for x in range(-(-k//2)): if 2*x > k: continue get = k - x if get >= n: cnt = 0 heap = sorted(v) while heap[0] < 0 and cnt < x: _ = heappop(heap) cnt += 1 ans = max(ans, sum(heap)) else: for i in range(get+1): cnt = 0 heap = sorted(v[:i] + v[n-(get-i):]) while heap[0] < 0 and cnt < x: _ = heappop(heap) cnt += 1 ans = max(ans, sum(heap)) print(ans)
import sys stdin = sys.stdin sys.setrecursionlimit(10 ** 7) 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, k = li() v = list(li()) # 個数m決め打ち ans = 0 for m in range(n+1): rest = k rest -= m if rest < 0: continue # 左からi個、右からm-i個 for i in range(m+1): a = v[:i] + v[n-m+i:] a.sort() suma = sum(a) # kを超えないようにマイナスを詰める for j in range(rest): if j >= len(a): break if a[j] < 0: suma += abs(a[j]) else: break ans = max(ans, suma) print(ans)
47
46
1,065
976
import sys stdin = sys.stdin sys.setrecursionlimit(10**7) 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()) from heapq import heappop n, k = li() v = list(li()) ans = 0 for x in range(-(-k // 2)): if 2 * x > k: continue get = k - x if get >= n: cnt = 0 heap = sorted(v) while heap[0] < 0 and cnt < x: _ = heappop(heap) cnt += 1 ans = max(ans, sum(heap)) else: for i in range(get + 1): cnt = 0 heap = sorted(v[:i] + v[n - (get - i) :]) while heap[0] < 0 and cnt < x: _ = heappop(heap) cnt += 1 ans = max(ans, sum(heap)) print(ans)
import sys stdin = sys.stdin sys.setrecursionlimit(10**7) 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, k = li() v = list(li()) # 個数m決め打ち ans = 0 for m in range(n + 1): rest = k rest -= m if rest < 0: continue # 左からi個、右からm-i個 for i in range(m + 1): a = v[:i] + v[n - m + i :] a.sort() suma = sum(a) # kを超えないようにマイナスを詰める for j in range(rest): if j >= len(a): break if a[j] < 0: suma += abs(a[j]) else: break ans = max(ans, suma) print(ans)
false
2.12766
[ "-from heapq import heappop", "-", "+# 入力", "+# 個数m決め打ち", "-for x in range(-(-k // 2)):", "- if 2 * x > k:", "+for m in range(n + 1):", "+ rest = k", "+ rest -= m", "+ if rest < 0:", "- get = k - x", "- if get >= n:", "- cnt = 0", "- heap = sorted(v)", "- while heap[0] < 0 and cnt < x:", "- _ = heappop(heap)", "- cnt += 1", "- ans = max(ans, sum(heap))", "- else:", "- for i in range(get + 1):", "- cnt = 0", "- heap = sorted(v[:i] + v[n - (get - i) :])", "- while heap[0] < 0 and cnt < x:", "- _ = heappop(heap)", "- cnt += 1", "- ans = max(ans, sum(heap))", "+ # 左からi個、右からm-i個", "+ for i in range(m + 1):", "+ a = v[:i] + v[n - m + i :]", "+ a.sort()", "+ suma = sum(a)", "+ # kを超えないようにマイナスを詰める", "+ for j in range(rest):", "+ if j >= len(a):", "+ break", "+ if a[j] < 0:", "+ suma += abs(a[j])", "+ else:", "+ break", "+ ans = max(ans, suma)" ]
false
0.042532
0.067063
0.634213
[ "s644247512", "s319378177" ]
u504836877
p03659
python
s721470362
s791719584
245
221
24,824
24,832
Accepted
Accepted
9.8
N = int(eval(input())) A = [int(a) for a in input().split()] S = [0]*(N+1) for i in range(N): S[i+1] += S[i] + A[i] ans = 10**12 for i in range(N-1): ans = min(ans, abs(S[i+1]-(S[N]-S[i+1]))) print(ans)
N = int(eval(input())) A = [int(a) for a in input().split()] for i in range(N-1): A[i+1] += A[i] ans = 10**15 for i in range(N-1): ans = min(ans, abs(A[N-1]-2*A[i])) print(ans)
12
10
226
189
N = int(eval(input())) A = [int(a) for a in input().split()] S = [0] * (N + 1) for i in range(N): S[i + 1] += S[i] + A[i] ans = 10**12 for i in range(N - 1): ans = min(ans, abs(S[i + 1] - (S[N] - S[i + 1]))) print(ans)
N = int(eval(input())) A = [int(a) for a in input().split()] for i in range(N - 1): A[i + 1] += A[i] ans = 10**15 for i in range(N - 1): ans = min(ans, abs(A[N - 1] - 2 * A[i])) print(ans)
false
16.666667
[ "-S = [0] * (N + 1)", "-for i in range(N):", "- S[i + 1] += S[i] + A[i]", "-ans = 10**12", "- ans = min(ans, abs(S[i + 1] - (S[N] - S[i + 1])))", "+ A[i + 1] += A[i]", "+ans = 10**15", "+for i in range(N - 1):", "+ ans = min(ans, abs(A[N - 1] - 2 * A[i]))" ]
false
0.101284
0.103217
0.981282
[ "s721470362", "s791719584" ]
u172035535
p03074
python
s653719033
s152365433
61
48
7,156
7,156
Accepted
Accepted
21.31
N,K = list(map(int,input().split())) S = eval(input()) L = [0] ans = 0 res = '1' i = 0 for s in S: if s != res: L.append(i) i += 1 else: i += 1 res = s L.append(i) L.append(i) if len(L)<=2*K+1: ans = N for i in range(0,len(L)-K*2-1,2): ans = max(ans,L[i+K*2+1]-L[i]) print(ans)
def func(): N,K = list(map(int,input().split())) S = eval(input()) L = [] L.append(0) if S[0] == '0' else 0 num = '2' for i in range(N): if num != S[i]: L.append(i) num = S[i] L.append(N) L.append(N) ans = 0 for i in range(0,len(L)-K*2-1,2): ans = max(ans,L[i+K*2+1]-L[i]) return N if N < 3 or K >= len(L)//2 else ans print((func()))
20
17
328
419
N, K = list(map(int, input().split())) S = eval(input()) L = [0] ans = 0 res = "1" i = 0 for s in S: if s != res: L.append(i) i += 1 else: i += 1 res = s L.append(i) L.append(i) if len(L) <= 2 * K + 1: ans = N for i in range(0, len(L) - K * 2 - 1, 2): ans = max(ans, L[i + K * 2 + 1] - L[i]) print(ans)
def func(): N, K = list(map(int, input().split())) S = eval(input()) L = [] L.append(0) if S[0] == "0" else 0 num = "2" for i in range(N): if num != S[i]: L.append(i) num = S[i] L.append(N) L.append(N) ans = 0 for i in range(0, len(L) - K * 2 - 1, 2): ans = max(ans, L[i + K * 2 + 1] - L[i]) return N if N < 3 or K >= len(L) // 2 else ans print((func()))
false
15
[ "-N, K = list(map(int, input().split()))", "-S = eval(input())", "-L = [0]", "-ans = 0", "-res = \"1\"", "-i = 0", "-for s in S:", "- if s != res:", "- L.append(i)", "- i += 1", "- else:", "- i += 1", "- res = s", "-L.append(i)", "-L.append(i)", "-if len(L) <= 2 * K + 1:", "- ans = N", "-for i in range(0, len(L) - K * 2 - 1, 2):", "- ans = max(ans, L[i + K * 2 + 1] - L[i])", "-print(ans)", "+def func():", "+ N, K = list(map(int, input().split()))", "+ S = eval(input())", "+ L = []", "+ L.append(0) if S[0] == \"0\" else 0", "+ num = \"2\"", "+ for i in range(N):", "+ if num != S[i]:", "+ L.append(i)", "+ num = S[i]", "+ L.append(N)", "+ L.append(N)", "+ ans = 0", "+ for i in range(0, len(L) - K * 2 - 1, 2):", "+ ans = max(ans, L[i + K * 2 + 1] - L[i])", "+ return N if N < 3 or K >= len(L) // 2 else ans", "+", "+", "+print((func()))" ]
false
0.10565
0.038738
2.727308
[ "s653719033", "s152365433" ]
u023515228
p03163
python
s910403634
s162277652
310
231
15,928
15,648
Accepted
Accepted
25.48
from numpy import* f=lambda:list(map(int,input().split())) N,W=f() J=arange(0,W+1,1,'i8') T=J*0 exec('w,v=f();T=maximum(T,(T[J-w]+v)*(J>=w));'*N) print((T[-1]))
from numpy import* f=lambda:list(map(int,input().split())) N,W=f() T=zeros(W+1,'i8') exec('w,v=f();T[w:]=maximum(T[w:],T[:-w]+v);'*N) print((T[-1]))
7
6
158
145
from numpy import * f = lambda: list(map(int, input().split())) N, W = f() J = arange(0, W + 1, 1, "i8") T = J * 0 exec("w,v=f();T=maximum(T,(T[J-w]+v)*(J>=w));" * N) print((T[-1]))
from numpy import * f = lambda: list(map(int, input().split())) N, W = f() T = zeros(W + 1, "i8") exec("w,v=f();T[w:]=maximum(T[w:],T[:-w]+v);" * N) print((T[-1]))
false
14.285714
[ "-J = arange(0, W + 1, 1, \"i8\")", "-T = J * 0", "-exec(\"w,v=f();T=maximum(T,(T[J-w]+v)*(J>=w));\" * N)", "+T = zeros(W + 1, \"i8\")", "+exec(\"w,v=f();T[w:]=maximum(T[w:],T[:-w]+v);\" * N)" ]
false
0.230401
0.185042
1.245132
[ "s910403634", "s162277652" ]
u144913062
p02990
python
s528512431
s049524096
1,745
26
356,084
3,316
Accepted
Accepted
98.51
N, K = list(map(int, input().split())) mod = 10**9+7 dp = [[0] * (K+1) for i in range(K+1)] # the number of ways to split j into i parts dp[0][0] = 1 for i in range(1, K+1): for j in range(1, K+1): dp[i][j] = dp[i][j-1] + dp[i-1][j-1] combination = 1 for i in range(1, K+1): combination = (combination * (N-K-i+2) * pow(i, mod-2, mod)) % mod print(((dp[i][K] * combination) % mod))
N, K = list(map(int, input().split())) mod = 10**9+7 ans = N-K+1 print(ans) for i in range(2, K+1): ans = (ans * (N-K-i+2) * (K-i+1) * pow(i * (i-1), mod-2, mod)) % mod print(ans)
12
8
407
190
N, K = list(map(int, input().split())) mod = 10**9 + 7 dp = [[0] * (K + 1) for i in range(K + 1)] # the number of ways to split j into i parts dp[0][0] = 1 for i in range(1, K + 1): for j in range(1, K + 1): dp[i][j] = dp[i][j - 1] + dp[i - 1][j - 1] combination = 1 for i in range(1, K + 1): combination = (combination * (N - K - i + 2) * pow(i, mod - 2, mod)) % mod print(((dp[i][K] * combination) % mod))
N, K = list(map(int, input().split())) mod = 10**9 + 7 ans = N - K + 1 print(ans) for i in range(2, K + 1): ans = (ans * (N - K - i + 2) * (K - i + 1) * pow(i * (i - 1), mod - 2, mod)) % mod print(ans)
false
33.333333
[ "-dp = [[0] * (K + 1) for i in range(K + 1)] # the number of ways to split j into i parts", "-dp[0][0] = 1", "-for i in range(1, K + 1):", "- for j in range(1, K + 1):", "- dp[i][j] = dp[i][j - 1] + dp[i - 1][j - 1]", "-combination = 1", "-for i in range(1, K + 1):", "- combination = (combination * (N - K - i + 2) * pow(i, mod - 2, mod)) % mod", "- print(((dp[i][K] * combination) % mod))", "+ans = N - K + 1", "+print(ans)", "+for i in range(2, K + 1):", "+ ans = (ans * (N - K - i + 2) * (K - i + 1) * pow(i * (i - 1), mod - 2, mod)) % mod", "+ print(ans)" ]
false
0.101142
0.050084
2.019464
[ "s528512431", "s049524096" ]
u077898957
p03211
python
s355791828
s506272410
149
17
12,468
2,940
Accepted
Accepted
88.59
import numpy as np import sys s = eval(input()) ans = 753 for i in range(len(s)-2): value = abs(753 - int(s[i:i+3])) ans = min(ans,value) print(ans)
s=eval(input()) ans=1000 for i in range(len(s)-2): if abs(753-int(s[i:i+3]))<=ans: ans=abs(753-int(s[i:i+3])) print(ans)
8
6
158
132
import numpy as np import sys s = eval(input()) ans = 753 for i in range(len(s) - 2): value = abs(753 - int(s[i : i + 3])) ans = min(ans, value) print(ans)
s = eval(input()) ans = 1000 for i in range(len(s) - 2): if abs(753 - int(s[i : i + 3])) <= ans: ans = abs(753 - int(s[i : i + 3])) print(ans)
false
25
[ "-import numpy as np", "-import sys", "-", "-ans = 753", "+ans = 1000", "- value = abs(753 - int(s[i : i + 3]))", "- ans = min(ans, value)", "+ if abs(753 - int(s[i : i + 3])) <= ans:", "+ ans = abs(753 - int(s[i : i + 3]))" ]
false
0.036523
0.037015
0.986726
[ "s355791828", "s506272410" ]
u606878291
p03221
python
s601503385
s583816223
727
637
44,128
35,260
Accepted
Accepted
12.38
from collections import Counter N, M = list(map(int, input().split(' '))) records = [tuple(map(int, input().split(' '))) for _ in range(M)] s_records = sorted(records) counter = Counter() d = {} for p, y in s_records: counter[p] += 1 d[(p, y)] = '{:06}{:06}'.format(p, counter[p]) for p, y in records: print((d[(p, y)]))
import bisect from collections import defaultdict N, M = list(map(int, input().split(' '))) cities = [] years = defaultdict(list) for _ in range(M): p, y = list(map(int, input().split(' '))) cities.append((p, y)) years[p].append(y) for p in list(years.keys()): years[p].sort() for p, y in cities: print(('{:06}{:06}'.format(p, bisect.bisect_right(years[p], y))))
15
16
343
381
from collections import Counter N, M = list(map(int, input().split(" "))) records = [tuple(map(int, input().split(" "))) for _ in range(M)] s_records = sorted(records) counter = Counter() d = {} for p, y in s_records: counter[p] += 1 d[(p, y)] = "{:06}{:06}".format(p, counter[p]) for p, y in records: print((d[(p, y)]))
import bisect from collections import defaultdict N, M = list(map(int, input().split(" "))) cities = [] years = defaultdict(list) for _ in range(M): p, y = list(map(int, input().split(" "))) cities.append((p, y)) years[p].append(y) for p in list(years.keys()): years[p].sort() for p, y in cities: print(("{:06}{:06}".format(p, bisect.bisect_right(years[p], y))))
false
6.25
[ "-from collections import Counter", "+import bisect", "+from collections import defaultdict", "-records = [tuple(map(int, input().split(\" \"))) for _ in range(M)]", "-s_records = sorted(records)", "-counter = Counter()", "-d = {}", "-for p, y in s_records:", "- counter[p] += 1", "- d[(p, y)] = \"{:06}{:06}\".format(p, counter[p])", "-for p, y in records:", "- print((d[(p, y)]))", "+cities = []", "+years = defaultdict(list)", "+for _ in range(M):", "+ p, y = list(map(int, input().split(\" \")))", "+ cities.append((p, y))", "+ years[p].append(y)", "+for p in list(years.keys()):", "+ years[p].sort()", "+for p, y in cities:", "+ print((\"{:06}{:06}\".format(p, bisect.bisect_right(years[p], y))))" ]
false
0.044433
0.046126
0.963303
[ "s601503385", "s583816223" ]
u020390084
p03274
python
s904562490
s356273165
121
110
14,128
19,884
Accepted
Accepted
9.09
n,k=list(map(int,input().split())) x = list(map(int,input().split())) import bisect zero_index = bisect.bisect_left(x,0) start_index = max(0,zero_index-k) x = x[start_index:zero_index+k] answer = (x[-1]-x[0])*k for i in range(len(x)-k+1): if x[i+k-1]*x[i]>0: answer = min(answer,max(abs(x[i+k-1]),abs(x[i]))) else: answer = min(answer,min(abs(x[i+k-1]),abs(x[i]))*2+max(abs(x[i+k-1]),abs(x[i]))) print(answer)
#!/usr/bin/env python3 import sys from itertools import accumulate def solve(N: int, K: int, x: "List[int]"): minus = [] plus = [] answer = 10**9 for i in range(N): if x[i] >= 0: plus.append(x[i]) else: minus.append(abs(x[i])) minus = minus[::-1] for plus_count in range(0,K+1): minus_count = K- plus_count if 0 <= plus_count <= len(plus) and 0 <= minus_count <= len(minus): if plus_count == 0: answer = min(answer,minus[minus_count-1]) elif minus_count ==0: answer = min(answer,plus[plus_count-1]) else: answer = min(answer,plus[plus_count-1]+minus[minus_count-1]*2,plus[plus_count-1]*2+minus[minus_count-1]) 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 K = int(next(tokens)) # type: int x = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, K, x) if __name__ == '__main__': main()
17
44
436
1,231
n, k = list(map(int, input().split())) x = list(map(int, input().split())) import bisect zero_index = bisect.bisect_left(x, 0) start_index = max(0, zero_index - k) x = x[start_index : zero_index + k] answer = (x[-1] - x[0]) * k for i in range(len(x) - k + 1): if x[i + k - 1] * x[i] > 0: answer = min(answer, max(abs(x[i + k - 1]), abs(x[i]))) else: answer = min( answer, min(abs(x[i + k - 1]), abs(x[i])) * 2 + max(abs(x[i + k - 1]), abs(x[i])), ) print(answer)
#!/usr/bin/env python3 import sys from itertools import accumulate def solve(N: int, K: int, x: "List[int]"): minus = [] plus = [] answer = 10**9 for i in range(N): if x[i] >= 0: plus.append(x[i]) else: minus.append(abs(x[i])) minus = minus[::-1] for plus_count in range(0, K + 1): minus_count = K - plus_count if 0 <= plus_count <= len(plus) and 0 <= minus_count <= len(minus): if plus_count == 0: answer = min(answer, minus[minus_count - 1]) elif minus_count == 0: answer = min(answer, plus[plus_count - 1]) else: answer = min( answer, plus[plus_count - 1] + minus[minus_count - 1] * 2, plus[plus_count - 1] * 2 + minus[minus_count - 1], ) 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 K = int(next(tokens)) # type: int x = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, K, x) if __name__ == "__main__": main()
false
61.363636
[ "-n, k = list(map(int, input().split()))", "-x = list(map(int, input().split()))", "-import bisect", "+#!/usr/bin/env python3", "+import sys", "+from itertools import accumulate", "-zero_index = bisect.bisect_left(x, 0)", "-start_index = max(0, zero_index - k)", "-x = x[start_index : zero_index + k]", "-answer = (x[-1] - x[0]) * k", "-for i in range(len(x) - k + 1):", "- if x[i + k - 1] * x[i] > 0:", "- answer = min(answer, max(abs(x[i + k - 1]), abs(x[i])))", "- else:", "- answer = min(", "- answer,", "- min(abs(x[i + k - 1]), abs(x[i])) * 2 + max(abs(x[i + k - 1]), abs(x[i])),", "- )", "-print(answer)", "+", "+def solve(N: int, K: int, x: \"List[int]\"):", "+ minus = []", "+ plus = []", "+ answer = 10**9", "+ for i in range(N):", "+ if x[i] >= 0:", "+ plus.append(x[i])", "+ else:", "+ minus.append(abs(x[i]))", "+ minus = minus[::-1]", "+ for plus_count in range(0, K + 1):", "+ minus_count = K - plus_count", "+ if 0 <= plus_count <= len(plus) and 0 <= minus_count <= len(minus):", "+ if plus_count == 0:", "+ answer = min(answer, minus[minus_count - 1])", "+ elif minus_count == 0:", "+ answer = min(answer, plus[plus_count - 1])", "+ else:", "+ answer = min(", "+ answer,", "+ plus[plus_count - 1] + minus[minus_count - 1] * 2,", "+ plus[plus_count - 1] * 2 + minus[minus_count - 1],", "+ )", "+ 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", "+ K = int(next(tokens)) # type: int", "+ x = [int(next(tokens)) for _ in range(N)] # type: \"List[int]\"", "+ solve(N, K, x)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.039386
0.040118
0.981775
[ "s904562490", "s356273165" ]