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
u744920373
p02787
python
s771772350
s239751525
673
545
120,284
119,644
Accepted
Accepted
19.02
H, N = list(map(int, input().split())) AB = [list(map(int, input().split())) for i in range(N)] INF = 10**10+1 dp = [[INF]*(H+1) for i in range(N+1)] dp[0][0] = 0 for i in range(1, N+1): dp[i][0] = 0 A = AB[i-1][0] for j in range(1, H+1): if j-AB[i-1][0]>=0: dp[i][j] = min(dp[i-1][j], dp[i-1][j-AB[i-1][0]]+AB[i-1][1], dp[i][j-AB[i-1][0]]+AB[i-1][1]) else: dp[i][j] = min(dp[i-1][j], AB[i-1][1]) print((dp[N][H]))
H, N = list(map(int, input().split())) AB = [list(map(int, input().split())) for i in range(N)] INF = 10**10+1 dp = [[INF]*(H+1) for i in range(N+1)] dp[0][0] = 0 for i in range(1, N+1): dp[i][0] = 0 A = AB[i-1][0] for j in range(1, H+1): if j-AB[i-1][0]>=0: dp[i][j] = min(dp[i-1][j], dp[i][j-AB[i-1][0]]+AB[i-1][1]) else: dp[i][j] = min(dp[i-1][j], AB[i-1][1]) print((dp[N][H]))
17
17
477
443
H, N = list(map(int, input().split())) AB = [list(map(int, input().split())) for i in range(N)] INF = 10**10 + 1 dp = [[INF] * (H + 1) for i in range(N + 1)] dp[0][0] = 0 for i in range(1, N + 1): dp[i][0] = 0 A = AB[i - 1][0] for j in range(1, H + 1): if j - AB[i - 1][0] >= 0: dp[i][j] = min( dp[i - 1][j], dp[i - 1][j - AB[i - 1][0]] + AB[i - 1][1], dp[i][j - AB[i - 1][0]] + AB[i - 1][1], ) else: dp[i][j] = min(dp[i - 1][j], AB[i - 1][1]) print((dp[N][H]))
H, N = list(map(int, input().split())) AB = [list(map(int, input().split())) for i in range(N)] INF = 10**10 + 1 dp = [[INF] * (H + 1) for i in range(N + 1)] dp[0][0] = 0 for i in range(1, N + 1): dp[i][0] = 0 A = AB[i - 1][0] for j in range(1, H + 1): if j - AB[i - 1][0] >= 0: dp[i][j] = min(dp[i - 1][j], dp[i][j - AB[i - 1][0]] + AB[i - 1][1]) else: dp[i][j] = min(dp[i - 1][j], AB[i - 1][1]) print((dp[N][H]))
false
0
[ "- dp[i][j] = min(", "- dp[i - 1][j],", "- dp[i - 1][j - AB[i - 1][0]] + AB[i - 1][1],", "- dp[i][j - AB[i - 1][0]] + AB[i - 1][1],", "- )", "+ dp[i][j] = min(dp[i - 1][j], dp[i][j - AB[i - 1][0]] + AB[i - 1][1])" ]
false
0.357347
0.320032
1.1166
[ "s771772350", "s239751525" ]
u264349861
p03167
python
s580382752
s315916496
356
99
251,136
76,840
Accepted
Accepted
72.19
#dt = {} for i in x: dt[i] = dt.get(i,0)+1 import sys;input = sys.stdin.readline inp,ip = lambda :int(eval(input())),lambda :[int(w) for w in input().split()] M = 10**9+7 h,w = ip() grid = [input().strip() for i in range(h)] dp = [[0]*w for i in range(h)] dp[0][0] = 1 for i in range(h): for j in range(w): if i-1 >= 0 and grid[i-1][j] == '.': dp[i][j] += dp[i-1][j] if j-1 >= 0 and grid[i][j-1] == '.': dp[i][j] += dp[i][j-1] print((dp[-1][-1]%M))
#dt = {} for i in x: dt[i] = dt.get(i,0)+1 import sys;input = sys.stdin.readline inp,ip = lambda :int(eval(input())),lambda :[int(w) for w in input().split()] M = 10**9+7 h,w = ip() grid = [input().strip() for i in range(h)] dp = [[0]*w for i in range(h)] dp[0][0] = 1 for i in range(h): for j in range(w): if i-1 >= 0 and grid[i-1][j] == '.': dp[i][j] += dp[i-1][j] if j-1 >= 0 and grid[i][j-1] == '.': dp[i][j] += dp[i][j-1] dp[i][j] %= M print((dp[-1][-1]%M))
16
17
500
524
# dt = {} for i in x: dt[i] = dt.get(i,0)+1 import sys input = sys.stdin.readline inp, ip = lambda: int(eval(input())), lambda: [int(w) for w in input().split()] M = 10**9 + 7 h, w = ip() grid = [input().strip() for i in range(h)] dp = [[0] * w for i in range(h)] dp[0][0] = 1 for i in range(h): for j in range(w): if i - 1 >= 0 and grid[i - 1][j] == ".": dp[i][j] += dp[i - 1][j] if j - 1 >= 0 and grid[i][j - 1] == ".": dp[i][j] += dp[i][j - 1] print((dp[-1][-1] % M))
# dt = {} for i in x: dt[i] = dt.get(i,0)+1 import sys input = sys.stdin.readline inp, ip = lambda: int(eval(input())), lambda: [int(w) for w in input().split()] M = 10**9 + 7 h, w = ip() grid = [input().strip() for i in range(h)] dp = [[0] * w for i in range(h)] dp[0][0] = 1 for i in range(h): for j in range(w): if i - 1 >= 0 and grid[i - 1][j] == ".": dp[i][j] += dp[i - 1][j] if j - 1 >= 0 and grid[i][j - 1] == ".": dp[i][j] += dp[i][j - 1] dp[i][j] %= M print((dp[-1][-1] % M))
false
5.882353
[ "+ dp[i][j] %= M" ]
false
0.092706
0.035854
2.585695
[ "s580382752", "s315916496" ]
u222668979
p02579
python
s799379523
s209708375
1,115
664
97,260
95,300
Accepted
Accepted
40.45
from collections import deque from itertools import product def bfs(x, y): dist = [[10 ** 9] * w for _ in range(h)] dist[y][x] = 0 que = deque([(x, y)]) near = product(list(range(-2, 3)), repeat=2) while len(que) > 0: x, y = que.popleft() if (x, y) == (Dw - 1, Dh - 1): return dist[y][x] for dx, dy in product(list(range(-2, 3)), repeat=2): cnt = (abs(dx) + abs(dy) >= 2) i, j = x + dx, y + dy if (0 <= i < w and 0 <= j < h and dist[j][i] > dist[y][x] + cnt and s[j][i] == '.'): dist[j][i] = dist[y][x] + cnt if cnt == 0: que.appendleft((i, j)) elif cnt == 1: que.append((i, j)) else: return -1 h, w = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] print((bfs(Cw - 1, Ch - 1)))
from collections import deque from itertools import product def bfs(x, y): dist = [[10 ** 9] * w for _ in range(h)] dist[y][x] = 0 que = deque([(x, y)]) near = list(product(list(range(-2, 3)), repeat=2)) while len(que) > 0: x, y = que.popleft() if (x, y) == (Dw - 1, Dh - 1): return dist[y][x] for dx, dy in near: cnt = (abs(dx) + abs(dy) >= 2) i, j = x + dx, y + dy if (0 <= i < w and 0 <= j < h and dist[j][i] > dist[y][x] + cnt and s[j][i] == '.'): dist[j][i] = dist[y][x] + cnt if cnt == 0: que.appendleft((i, j)) elif cnt == 1: que.append((i, j)) else: return -1 h, w = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] print((bfs(Cw - 1, Ch - 1)))
35
35
998
977
from collections import deque from itertools import product def bfs(x, y): dist = [[10**9] * w for _ in range(h)] dist[y][x] = 0 que = deque([(x, y)]) near = product(list(range(-2, 3)), repeat=2) while len(que) > 0: x, y = que.popleft() if (x, y) == (Dw - 1, Dh - 1): return dist[y][x] for dx, dy in product(list(range(-2, 3)), repeat=2): cnt = abs(dx) + abs(dy) >= 2 i, j = x + dx, y + dy if ( 0 <= i < w and 0 <= j < h and dist[j][i] > dist[y][x] + cnt and s[j][i] == "." ): dist[j][i] = dist[y][x] + cnt if cnt == 0: que.appendleft((i, j)) elif cnt == 1: que.append((i, j)) else: return -1 h, w = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] print((bfs(Cw - 1, Ch - 1)))
from collections import deque from itertools import product def bfs(x, y): dist = [[10**9] * w for _ in range(h)] dist[y][x] = 0 que = deque([(x, y)]) near = list(product(list(range(-2, 3)), repeat=2)) while len(que) > 0: x, y = que.popleft() if (x, y) == (Dw - 1, Dh - 1): return dist[y][x] for dx, dy in near: cnt = abs(dx) + abs(dy) >= 2 i, j = x + dx, y + dy if ( 0 <= i < w and 0 <= j < h and dist[j][i] > dist[y][x] + cnt and s[j][i] == "." ): dist[j][i] = dist[y][x] + cnt if cnt == 0: que.appendleft((i, j)) elif cnt == 1: que.append((i, j)) else: return -1 h, w = list(map(int, input().split())) Ch, Cw = list(map(int, input().split())) Dh, Dw = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] print((bfs(Cw - 1, Ch - 1)))
false
0
[ "- near = product(list(range(-2, 3)), repeat=2)", "+ near = list(product(list(range(-2, 3)), repeat=2))", "- for dx, dy in product(list(range(-2, 3)), repeat=2):", "+ for dx, dy in near:" ]
false
0.081711
0.086475
0.944906
[ "s799379523", "s209708375" ]
u318127926
p03714
python
s080749118
s764915914
406
320
42,932
42,684
Accepted
Accepted
21.18
from heapq import heapify, heapreplace n = int(eval(input())) a = list(map(int, input().split())) a1 = a[:n] heapify(a1) a2 = a[n:2*n] a3 = [-i for i in a[2*n:]] heapify(a3) b1 = [sum(a1)] b2 = [sum(a3)] for i in range(n): b1.append(a2[i]-heapreplace(a1, a2[i])) b2.append(-heapreplace(a3, -a2[n-i-1])-a2[n-i-1]) for i in range(n): b1[i+1] += b1[i] b2[i+1] += b2[i] accu = [] mx = b1[0] for i in b1: mx = max(mx, i) accu.append(mx) ans = -10**16 mx = b2[0] for i in range(n+1): mx = max(mx, b2[i]) ans = max(ans, mx+accu[n-i]) print(ans)
from heapq import heapify, heappushpop n = int(eval(input())) a = list(map(int, input().split())) a1 = a[:n] heapify(a1) a2 = a[n:2*n] a3 = [-i for i in a[2*n:]] heapify(a3) b1 = [sum(a1)] b2 = [sum(a3)] for i in range(n): b1.append(b1[-1]+a2[i]-heappushpop(a1, a2[i])) b2.append(b2[-1]-heappushpop(a3, -a2[n-i-1])-a2[n-i-1]) ans = b1[0]+b2[n] for i in range(n+1): ans = max(ans, b1[i]+b2[n-i]) print(ans)
27
17
589
427
from heapq import heapify, heapreplace n = int(eval(input())) a = list(map(int, input().split())) a1 = a[:n] heapify(a1) a2 = a[n : 2 * n] a3 = [-i for i in a[2 * n :]] heapify(a3) b1 = [sum(a1)] b2 = [sum(a3)] for i in range(n): b1.append(a2[i] - heapreplace(a1, a2[i])) b2.append(-heapreplace(a3, -a2[n - i - 1]) - a2[n - i - 1]) for i in range(n): b1[i + 1] += b1[i] b2[i + 1] += b2[i] accu = [] mx = b1[0] for i in b1: mx = max(mx, i) accu.append(mx) ans = -(10**16) mx = b2[0] for i in range(n + 1): mx = max(mx, b2[i]) ans = max(ans, mx + accu[n - i]) print(ans)
from heapq import heapify, heappushpop n = int(eval(input())) a = list(map(int, input().split())) a1 = a[:n] heapify(a1) a2 = a[n : 2 * n] a3 = [-i for i in a[2 * n :]] heapify(a3) b1 = [sum(a1)] b2 = [sum(a3)] for i in range(n): b1.append(b1[-1] + a2[i] - heappushpop(a1, a2[i])) b2.append(b2[-1] - heappushpop(a3, -a2[n - i - 1]) - a2[n - i - 1]) ans = b1[0] + b2[n] for i in range(n + 1): ans = max(ans, b1[i] + b2[n - i]) print(ans)
false
37.037037
[ "-from heapq import heapify, heapreplace", "+from heapq import heapify, heappushpop", "- b1.append(a2[i] - heapreplace(a1, a2[i]))", "- b2.append(-heapreplace(a3, -a2[n - i - 1]) - a2[n - i - 1])", "-for i in range(n):", "- b1[i + 1] += b1[i]", "- b2[i + 1] += b2[i]", "-accu = []", "-mx = b1[0]", "-for i in b1:", "- mx = max(mx, i)", "- accu.append(mx)", "-ans = -(10**16)", "-mx = b2[0]", "+ b1.append(b1[-1] + a2[i] - heappushpop(a1, a2[i]))", "+ b2.append(b2[-1] - heappushpop(a3, -a2[n - i - 1]) - a2[n - i - 1])", "+ans = b1[0] + b2[n]", "- mx = max(mx, b2[i])", "- ans = max(ans, mx + accu[n - i])", "+ ans = max(ans, b1[i] + b2[n - i])" ]
false
0.105138
0.044571
2.35889
[ "s080749118", "s764915914" ]
u968404618
p03265
python
s908133378
s458093760
31
25
9,096
9,056
Accepted
Accepted
19.35
x1, y1, x2, y2 = list(map(int, input().split())) x3 = x2-(y2-y1) y3 = y2+(x2-x1) x4 = x3-(y3-y2) y4 = y3+(x3-x2) print((x3,y3,x4,y4))
x1, y1, x2, y2 = list(map(int, input().split())) X = x2-x1 Y = y2-y1 print((x2-Y, y2+X, x1-Y, y1+X))
8
5
134
97
x1, y1, x2, y2 = list(map(int, input().split())) x3 = x2 - (y2 - y1) y3 = y2 + (x2 - x1) x4 = x3 - (y3 - y2) y4 = y3 + (x3 - x2) print((x3, y3, x4, y4))
x1, y1, x2, y2 = list(map(int, input().split())) X = x2 - x1 Y = y2 - y1 print((x2 - Y, y2 + X, x1 - Y, y1 + X))
false
37.5
[ "-x3 = x2 - (y2 - y1)", "-y3 = y2 + (x2 - x1)", "-x4 = x3 - (y3 - y2)", "-y4 = y3 + (x3 - x2)", "-print((x3, y3, x4, y4))", "+X = x2 - x1", "+Y = y2 - y1", "+print((x2 - Y, y2 + X, x1 - Y, y1 + X))" ]
false
0.043576
0.042817
1.017726
[ "s908133378", "s458093760" ]
u014333473
p03495
python
s766193307
s054287479
114
103
24,744
45,536
Accepted
Accepted
9.65
N,K=list(map(int,input().split())) A=list(map(int,input().split())) count = [0]*max(A) for i in A: count[i-1] += 1 print((sum(sorted(count,reverse=True)[K:])))
import collections as c n,k=list(map(int,input().split()));a=c.Counter(list(map(int,input().split()))) print(([0,sum(sorted([i for i in list(a.values())])[:len(a)-k])][len(a)>k]))
6
3
158
161
N, K = list(map(int, input().split())) A = list(map(int, input().split())) count = [0] * max(A) for i in A: count[i - 1] += 1 print((sum(sorted(count, reverse=True)[K:])))
import collections as c n, k = list(map(int, input().split())) a = c.Counter(list(map(int, input().split()))) print(([0, sum(sorted([i for i in list(a.values())])[: len(a) - k])][len(a) > k]))
false
50
[ "-N, K = list(map(int, input().split()))", "-A = list(map(int, input().split()))", "-count = [0] * max(A)", "-for i in A:", "- count[i - 1] += 1", "-print((sum(sorted(count, reverse=True)[K:])))", "+import collections as c", "+", "+n, k = list(map(int, input().split()))", "+a = c.Counter(list(map(int, input().split())))", "+print(([0, sum(sorted([i for i in list(a.values())])[: len(a) - k])][len(a) > k]))" ]
false
0.039773
0.038743
1.026591
[ "s766193307", "s054287479" ]
u600402037
p03494
python
s895460985
s420041647
23
20
3,060
3,060
Accepted
Accepted
13.04
N = int(eval(input())) A = [int(l) for l in input().split()] count = 0 k = 0 while True: for i in range(N): if A[i]/2** k % 2 !=0: break else: count += 1 k += 1 continue break print(count)
N = int(eval(input())) A = [int(l) for l in input().split()] count = 0 while True: for i in range(N): if A[i] / 2 ** count % 2 !=0: break else: count += 1 continue break print(count)
16
14
259
243
N = int(eval(input())) A = [int(l) for l in input().split()] count = 0 k = 0 while True: for i in range(N): if A[i] / 2**k % 2 != 0: break else: count += 1 k += 1 continue break print(count)
N = int(eval(input())) A = [int(l) for l in input().split()] count = 0 while True: for i in range(N): if A[i] / 2**count % 2 != 0: break else: count += 1 continue break print(count)
false
12.5
[ "-k = 0", "- if A[i] / 2**k % 2 != 0:", "+ if A[i] / 2**count % 2 != 0:", "- k += 1" ]
false
0.037979
0.038182
0.994698
[ "s895460985", "s420041647" ]
u869919400
p03476
python
s545358259
s206859216
1,294
520
66,268
79,328
Accepted
Accepted
59.81
Q = int(eval(input())) from functools import lru_cache @lru_cache(maxsize=None) def is_prime(n: int): if n == 2: return True if n == 1 or n % 2 == 0: return False for p in range(3, int(n**0.5)+1, 2): if n % p == 0: return False return True like_2017s = [] for i in range(3, 10**5, 2): if is_prime(i) and is_prime((i+1)//2): like_2017s.append(i) from bisect import bisect_left, bisect_right for _ in range(Q): l, r = list(map(int, input().split())) li = bisect_left(like_2017s, l) ri = bisect_right(like_2017s, r) print((ri-li))
Q = int(eval(input())) import math def sieve_of_erastosthenes(num): input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)] input_list[0] = input_list[1] = False input_list[2] = input_list[3] = input_list[5] = True sqrt = math.sqrt(num) for serial in range(3, num, 2): if serial >= sqrt: return input_list for s in range(serial ** 2, num, serial): input_list[s] = False primes = sieve_of_erastosthenes(10**5) likes = [] for i in range(3, 10**5, 2): if primes[i] and primes[(i+1)//2]: likes.append(i) from bisect import bisect_left, bisect_right for _ in range(Q): l, r = list(map(int, input().split())) print((bisect_right(likes, r) - bisect_left(likes, l)))
25
25
620
790
Q = int(eval(input())) from functools import lru_cache @lru_cache(maxsize=None) def is_prime(n: int): if n == 2: return True if n == 1 or n % 2 == 0: return False for p in range(3, int(n**0.5) + 1, 2): if n % p == 0: return False return True like_2017s = [] for i in range(3, 10**5, 2): if is_prime(i) and is_prime((i + 1) // 2): like_2017s.append(i) from bisect import bisect_left, bisect_right for _ in range(Q): l, r = list(map(int, input().split())) li = bisect_left(like_2017s, l) ri = bisect_right(like_2017s, r) print((ri - li))
Q = int(eval(input())) import math def sieve_of_erastosthenes(num): input_list = [ False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num) ] input_list[0] = input_list[1] = False input_list[2] = input_list[3] = input_list[5] = True sqrt = math.sqrt(num) for serial in range(3, num, 2): if serial >= sqrt: return input_list for s in range(serial**2, num, serial): input_list[s] = False primes = sieve_of_erastosthenes(10**5) likes = [] for i in range(3, 10**5, 2): if primes[i] and primes[(i + 1) // 2]: likes.append(i) from bisect import bisect_left, bisect_right for _ in range(Q): l, r = list(map(int, input().split())) print((bisect_right(likes, r) - bisect_left(likes, l)))
false
0
[ "-from functools import lru_cache", "+import math", "-@lru_cache(maxsize=None)", "-def is_prime(n: int):", "- if n == 2:", "- return True", "- if n == 1 or n % 2 == 0:", "- return False", "- for p in range(3, int(n**0.5) + 1, 2):", "- if n % p == 0:", "- return False", "- return True", "+def sieve_of_erastosthenes(num):", "+ input_list = [", "+ False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)", "+ ]", "+ input_list[0] = input_list[1] = False", "+ input_list[2] = input_list[3] = input_list[5] = True", "+ sqrt = math.sqrt(num)", "+ for serial in range(3, num, 2):", "+ if serial >= sqrt:", "+ return input_list", "+ for s in range(serial**2, num, serial):", "+ input_list[s] = False", "-like_2017s = []", "+primes = sieve_of_erastosthenes(10**5)", "+likes = []", "- if is_prime(i) and is_prime((i + 1) // 2):", "- like_2017s.append(i)", "+ if primes[i] and primes[(i + 1) // 2]:", "+ likes.append(i)", "- li = bisect_left(like_2017s, l)", "- ri = bisect_right(like_2017s, r)", "- print((ri - li))", "+ print((bisect_right(likes, r) - bisect_left(likes, l)))" ]
false
0.161619
0.064634
2.500542
[ "s545358259", "s206859216" ]
u073852194
p03965
python
s175644397
s415648797
177
46
39,536
3,316
Accepted
Accepted
74.01
s = eval(input()) n = len(s) ans = 0 dif = 0 for i in range(n): if s[i] == 'g': if dif > 0: ans += 1 dif -= 1 else: dif += 1 else: if dif > 0: dif -= 1 else: ans -= 1 dif += 1 print(ans)
s = eval(input()) p = 0 g = 0 res = 0 for i in range(len(s)): if s[i] == 'g': if p < g: p += 1 res += 1 else: g += 1 else: if p < g: p += 1 else: g += 1 res -= 1 print(res)
21
21
327
301
s = eval(input()) n = len(s) ans = 0 dif = 0 for i in range(n): if s[i] == "g": if dif > 0: ans += 1 dif -= 1 else: dif += 1 else: if dif > 0: dif -= 1 else: ans -= 1 dif += 1 print(ans)
s = eval(input()) p = 0 g = 0 res = 0 for i in range(len(s)): if s[i] == "g": if p < g: p += 1 res += 1 else: g += 1 else: if p < g: p += 1 else: g += 1 res -= 1 print(res)
false
0
[ "-n = len(s)", "-ans = 0", "-dif = 0", "-for i in range(n):", "+p = 0", "+g = 0", "+res = 0", "+for i in range(len(s)):", "- if dif > 0:", "- ans += 1", "- dif -= 1", "+ if p < g:", "+ p += 1", "+ res += 1", "- dif += 1", "+ g += 1", "- if dif > 0:", "- dif -= 1", "+ if p < g:", "+ p += 1", "- ans -= 1", "- dif += 1", "-print(ans)", "+ g += 1", "+ res -= 1", "+print(res)" ]
false
0.076359
0.065567
1.164591
[ "s175644397", "s415648797" ]
u094191970
p03659
python
s652495665
s242631675
247
176
24,800
24,824
Accepted
Accepted
28.74
n=int(eval(input())) a=list(map(int,input().split())) ans=n*10**9 b=[0] for i in range(1,n+1): b.append(a[i-1]+b[i-1]) for i in range(n-1): t_ans=abs(b[i+1]-(b[-1]-b[i+1])) ans=min(ans,t_ans) print(ans)
n=int(eval(input())) a=list(map(int,input().split())) ans=n*10**9 t=sum(a) s=0 for i in range(n-1): # s=sum(a[:i]) s+=a[i] ans=min(ans,abs(t-2*s)) print(ans)
14
13
225
177
n = int(eval(input())) a = list(map(int, input().split())) ans = n * 10**9 b = [0] for i in range(1, n + 1): b.append(a[i - 1] + b[i - 1]) for i in range(n - 1): t_ans = abs(b[i + 1] - (b[-1] - b[i + 1])) ans = min(ans, t_ans) print(ans)
n = int(eval(input())) a = list(map(int, input().split())) ans = n * 10**9 t = sum(a) s = 0 for i in range(n - 1): # s=sum(a[:i]) s += a[i] ans = min(ans, abs(t - 2 * s)) print(ans)
false
7.142857
[ "-b = [0]", "-for i in range(1, n + 1):", "- b.append(a[i - 1] + b[i - 1])", "+t = sum(a)", "+s = 0", "- t_ans = abs(b[i + 1] - (b[-1] - b[i + 1]))", "- ans = min(ans, t_ans)", "+ # s=sum(a[:i])", "+ s += a[i]", "+ ans = min(ans, abs(t - 2 * s))" ]
false
0.040228
0.056371
0.713633
[ "s652495665", "s242631675" ]
u309120194
p02831
python
s518234719
s491979834
43
27
9,164
9,156
Accepted
Accepted
37.21
a, b = list(map(int, input().split())) # aの倍数を順に探索する # abはa, bの公倍数なので、高々B回で十分。O(B) lcm = 0 for i in range(1, b+1): if (a * i) % b == 0: lcm = a * i break print(lcm)
import math a, b = list(map(int, input().split())) # 最小公倍数lcmと最大公約数gcdに成り立つ関係:gcd(a,b)*lcm(a,b)=ab を用いる print((a * b // math.gcd(a, b)))
11
5
183
133
a, b = list(map(int, input().split())) # aの倍数を順に探索する # abはa, bの公倍数なので、高々B回で十分。O(B) lcm = 0 for i in range(1, b + 1): if (a * i) % b == 0: lcm = a * i break print(lcm)
import math a, b = list(map(int, input().split())) # 最小公倍数lcmと最大公約数gcdに成り立つ関係:gcd(a,b)*lcm(a,b)=ab を用いる print((a * b // math.gcd(a, b)))
false
54.545455
[ "+import math", "+", "-# aの倍数を順に探索する", "-# abはa, bの公倍数なので、高々B回で十分。O(B)", "-lcm = 0", "-for i in range(1, b + 1):", "- if (a * i) % b == 0:", "- lcm = a * i", "- break", "-print(lcm)", "+# 最小公倍数lcmと最大公約数gcdに成り立つ関係:gcd(a,b)*lcm(a,b)=ab を用いる", "+print((a * b // math.gcd(a, b)))" ]
false
0.052013
0.084223
0.617566
[ "s518234719", "s491979834" ]
u389910364
p04012
python
s160110305
s565473804
1,849
164
23,556
38,384
Accepted
Accepted
91.13
import bisect import heapq import itertools import math import os import re import string import sys from collections import Counter, deque, defaultdict from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 W = sys.stdin.readline().rstrip() if any([w % 2 for w in list(Counter(list(W)).values())]): print('No') else: print('Yes')
import os import sys from collections import Counter if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 W = sys.stdin.readline().rstrip() if any([w % 2 for w in list(Counter(list(W)).values())]): print('No') else: print('Yes')
29
17
585
327
import bisect import heapq import itertools import math import os import re import string import sys from collections import Counter, deque, defaultdict from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 W = sys.stdin.readline().rstrip() if any([w % 2 for w in list(Counter(list(W)).values())]): print("No") else: print("Yes")
import os import sys from collections import Counter if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 W = sys.stdin.readline().rstrip() if any([w % 2 for w in list(Counter(list(W)).values())]): print("No") else: print("Yes")
false
41.37931
[ "-import bisect", "-import heapq", "-import itertools", "-import math", "-import re", "-import string", "-from collections import Counter, deque, defaultdict", "-from decimal import Decimal", "-from fractions import gcd", "-from functools import lru_cache, reduce", "-from operator import itemgetter", "-import numpy as np", "+from collections import Counter" ]
false
0.061722
0.046293
1.333298
[ "s160110305", "s565473804" ]
u761320129
p03425
python
s230910848
s371171550
545
149
10,232
11,008
Accepted
Accepted
72.66
from collections import Counter import itertools N = int(eval(input())) src = [eval(input()) for i in range(N)] ctr = Counter() for s in src: ctr.update(s[0]) ans = 0 for ptn in itertools.combinations('MARCH',3): a,b,c = ptn ans += ctr[a] * ctr[b] * ctr[c] print(ans)
import itertools from collections import Counter N = int(eval(input())) src = [eval(input()) for i in range(N)] ctr = Counter([s[0] for s in src]) ans = 0 for ptn in itertools.combinations('MARCH',3): ans += ctr[ptn[0]]*ctr[ptn[1]]*ctr[ptn[2]] print(ans)
15
10
285
257
from collections import Counter import itertools N = int(eval(input())) src = [eval(input()) for i in range(N)] ctr = Counter() for s in src: ctr.update(s[0]) ans = 0 for ptn in itertools.combinations("MARCH", 3): a, b, c = ptn ans += ctr[a] * ctr[b] * ctr[c] print(ans)
import itertools from collections import Counter N = int(eval(input())) src = [eval(input()) for i in range(N)] ctr = Counter([s[0] for s in src]) ans = 0 for ptn in itertools.combinations("MARCH", 3): ans += ctr[ptn[0]] * ctr[ptn[1]] * ctr[ptn[2]] print(ans)
false
33.333333
[ "+import itertools", "-import itertools", "-ctr = Counter()", "-for s in src:", "- ctr.update(s[0])", "+ctr = Counter([s[0] for s in src])", "- a, b, c = ptn", "- ans += ctr[a] * ctr[b] * ctr[c]", "+ ans += ctr[ptn[0]] * ctr[ptn[1]] * ctr[ptn[2]]" ]
false
0.035449
0.039968
0.886931
[ "s230910848", "s371171550" ]
u379716238
p03805
python
s766088279
s041660830
28
18
3,064
3,064
Accepted
Accepted
35.71
N, M = list(map(int, input().split())) adj_matrix = [[0]*N for _ in range(N)] for i in range(M): a, b = list(map(int, input().split())) adj_matrix[a-1][b-1] = 1 adj_matrix[b-1][a-1] = 1 def dfs(v, used): if not False in used: return 1 ans = 0 for i in range(N): if not adj_matrix[v][i]: continue if used[i]: continue used[i] = True ans += dfs(i, used) used[i] = False return ans used = [False] * N used[0] = True print((dfs(0, used)))
N, M = list(map(int, input().split())) g = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) g[a-1].append(b-1) g[b-1].append(a-1) memo = {} All_used = (1 << N) - 1 def dfs(v, used): if used == All_used: return 1 key = (v, used) if key in memo: return memo[key] ans = 0 for u in g[v]: if (used >> u) & 1 ==1: continue used ^= (1 << u) ans += dfs(u, used) used ^= (1 << u) memo[key] = ans return ans print((dfs(0, 1)))
26
28
557
515
N, M = list(map(int, input().split())) adj_matrix = [[0] * N for _ in range(N)] for i in range(M): a, b = list(map(int, input().split())) adj_matrix[a - 1][b - 1] = 1 adj_matrix[b - 1][a - 1] = 1 def dfs(v, used): if not False in used: return 1 ans = 0 for i in range(N): if not adj_matrix[v][i]: continue if used[i]: continue used[i] = True ans += dfs(i, used) used[i] = False return ans used = [False] * N used[0] = True print((dfs(0, used)))
N, M = list(map(int, input().split())) g = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) g[a - 1].append(b - 1) g[b - 1].append(a - 1) memo = {} All_used = (1 << N) - 1 def dfs(v, used): if used == All_used: return 1 key = (v, used) if key in memo: return memo[key] ans = 0 for u in g[v]: if (used >> u) & 1 == 1: continue used ^= 1 << u ans += dfs(u, used) used ^= 1 << u memo[key] = ans return ans print((dfs(0, 1)))
false
7.142857
[ "-adj_matrix = [[0] * N for _ in range(N)]", "+g = [[] for i in range(N)]", "- adj_matrix[a - 1][b - 1] = 1", "- adj_matrix[b - 1][a - 1] = 1", "+ g[a - 1].append(b - 1)", "+ g[b - 1].append(a - 1)", "+memo = {}", "+All_used = (1 << N) - 1", "- if not False in used:", "+ if used == All_used:", "+ key = (v, used)", "+ if key in memo:", "+ return memo[key]", "- for i in range(N):", "- if not adj_matrix[v][i]:", "+ for u in g[v]:", "+ if (used >> u) & 1 == 1:", "- if used[i]:", "- continue", "- used[i] = True", "- ans += dfs(i, used)", "- used[i] = False", "+ used ^= 1 << u", "+ ans += dfs(u, used)", "+ used ^= 1 << u", "+ memo[key] = ans", "-used = [False] * N", "-used[0] = True", "-print((dfs(0, used)))", "+print((dfs(0, 1)))" ]
false
0.036944
0.055668
0.663641
[ "s766088279", "s041660830" ]
u228223940
p03112
python
s042851568
s976412148
1,066
866
16,132
17,664
Accepted
Accepted
18.76
import sys import bisect input = sys.stdin.readline a,b,q = list(map(int,input().split())) ans = 10**100 s = [-ans] + [int(eval(input())) for i in range(a)] + [ans] t = [-ans] + [int(eval(input())) for i in range(b)] + [ans] x = [int(eval(input())) for i in range(q)] ans = 10**100 for i in range(q): ans = 10**100 s_idx = bisect.bisect_left(s,x[i]) t_idx = bisect.bisect_left(t,x[i]) s_idx -= 1 t_idx -= 1 #print(x[i],s_idx,t_idx) for j in range(2): for k in range(2): ans = min(ans,abs(x[i] - s[s_idx+j]) + abs(s[s_idx+j] - t[t_idx+k]),abs(x[i] - t[t_idx+k]) + abs(s[s_idx+j] - t[t_idx+k])) print(ans)
import sys import bisect input = sys.stdin.readline a,b,q = list(map(int,input().split())) ans = 10**100 s = [-ans] + [int(eval(input())) for i in range(a)] + [ans] t = [-ans] + [int(eval(input())) for i in range(b)] + [ans] x = [int(eval(input())) for i in range(q)] ans = 10**100 for i in range(q): ans = 10**100 s_idx = bisect.bisect_left(s,x[i]) t_idx = bisect.bisect_left(t,x[i]) s_idx -= 1 t_idx -= 1 #print(x[i],s_idx,t_idx) for j in s[s_idx+0],s[s_idx+1]: for k in t[t_idx+0],t[t_idx+1]: ans = min(ans,abs(x[i] - j) + abs(j - k),abs(x[i] - k) + abs(j - k)) print(ans)
27
27
678
650
import sys import bisect input = sys.stdin.readline a, b, q = list(map(int, input().split())) ans = 10**100 s = [-ans] + [int(eval(input())) for i in range(a)] + [ans] t = [-ans] + [int(eval(input())) for i in range(b)] + [ans] x = [int(eval(input())) for i in range(q)] ans = 10**100 for i in range(q): ans = 10**100 s_idx = bisect.bisect_left(s, x[i]) t_idx = bisect.bisect_left(t, x[i]) s_idx -= 1 t_idx -= 1 # print(x[i],s_idx,t_idx) for j in range(2): for k in range(2): ans = min( ans, abs(x[i] - s[s_idx + j]) + abs(s[s_idx + j] - t[t_idx + k]), abs(x[i] - t[t_idx + k]) + abs(s[s_idx + j] - t[t_idx + k]), ) print(ans)
import sys import bisect input = sys.stdin.readline a, b, q = list(map(int, input().split())) ans = 10**100 s = [-ans] + [int(eval(input())) for i in range(a)] + [ans] t = [-ans] + [int(eval(input())) for i in range(b)] + [ans] x = [int(eval(input())) for i in range(q)] ans = 10**100 for i in range(q): ans = 10**100 s_idx = bisect.bisect_left(s, x[i]) t_idx = bisect.bisect_left(t, x[i]) s_idx -= 1 t_idx -= 1 # print(x[i],s_idx,t_idx) for j in s[s_idx + 0], s[s_idx + 1]: for k in t[t_idx + 0], t[t_idx + 1]: ans = min(ans, abs(x[i] - j) + abs(j - k), abs(x[i] - k) + abs(j - k)) print(ans)
false
0
[ "- for j in range(2):", "- for k in range(2):", "- ans = min(", "- ans,", "- abs(x[i] - s[s_idx + j]) + abs(s[s_idx + j] - t[t_idx + k]),", "- abs(x[i] - t[t_idx + k]) + abs(s[s_idx + j] - t[t_idx + k]),", "- )", "+ for j in s[s_idx + 0], s[s_idx + 1]:", "+ for k in t[t_idx + 0], t[t_idx + 1]:", "+ ans = min(ans, abs(x[i] - j) + abs(j - k), abs(x[i] - k) + abs(j - k))" ]
false
0.035893
0.044601
0.804762
[ "s042851568", "s976412148" ]
u321035578
p03244
python
s075519619
s831239816
95
86
23,772
21,952
Accepted
Accepted
9.47
import collections def main(): n = int(eval(input())) v = list(map(int,input().split())) if len(set(v)) == 1: print((n//2)) elif len(set(v)) == 2: cnt1 = 0 cnt2 = 0 tmp1 = list(set(v)) tmp2 = [tmp1[1], tmp1[0]] # even = v[::2] # odd = v[1::2] # for i, a in enumerate(v): if i % 2 == 0: if a == tmp1[0]: cnt1 += 1 if a == tmp2[0]: cnt2 += 1 else : if a == tmp1[1]: cnt1 += 1 if a == tmp2[1]: cnt2 += 1 print((n-max(cnt1,cnt2))) else: even = v[::2] odd = v[1::2] count_e = collections.Counter(even) count_o = collections.Counter(odd) ce = count_e.most_common() co = count_o.most_common() if ce[0][0] != co[0][0]: print((n-ce[0][1] - co[0][1])) else: if len(ce) == 1: print((n-co[1][1])) elif len(co) == 1: print((n-ce[1][1])) else: print((min(n-ce[0][1]-co[1][1], n-ce[1][1]-co[0][1]))) if __name__ == '__main__': main()
import collections def main(): n = int(eval(input())) v = list(map(int,input().split())) even = v[::2] odd = v[1::2] count_e = collections.Counter(even) count_o = collections.Counter(odd) ce = count_e.most_common() co = count_o.most_common() if ce[0][0] != co[0][0]: print((n-ce[0][1] - co[0][1])) else: if len(ce) == 1 and len(co) == 1: print((n//2)) elif len(ce) == 1: print((n-co[1][1])) elif len(co) == 1: print((n-ce[1][1])) else: print((min(n-ce[0][1]-co[1][1], n-ce[1][1]-co[0][1]))) if __name__ == '__main__': main()
49
28
1,286
673
import collections def main(): n = int(eval(input())) v = list(map(int, input().split())) if len(set(v)) == 1: print((n // 2)) elif len(set(v)) == 2: cnt1 = 0 cnt2 = 0 tmp1 = list(set(v)) tmp2 = [tmp1[1], tmp1[0]] # even = v[::2] # odd = v[1::2] # for i, a in enumerate(v): if i % 2 == 0: if a == tmp1[0]: cnt1 += 1 if a == tmp2[0]: cnt2 += 1 else: if a == tmp1[1]: cnt1 += 1 if a == tmp2[1]: cnt2 += 1 print((n - max(cnt1, cnt2))) else: even = v[::2] odd = v[1::2] count_e = collections.Counter(even) count_o = collections.Counter(odd) ce = count_e.most_common() co = count_o.most_common() if ce[0][0] != co[0][0]: print((n - ce[0][1] - co[0][1])) else: if len(ce) == 1: print((n - co[1][1])) elif len(co) == 1: print((n - ce[1][1])) else: print((min(n - ce[0][1] - co[1][1], n - ce[1][1] - co[0][1]))) if __name__ == "__main__": main()
import collections def main(): n = int(eval(input())) v = list(map(int, input().split())) even = v[::2] odd = v[1::2] count_e = collections.Counter(even) count_o = collections.Counter(odd) ce = count_e.most_common() co = count_o.most_common() if ce[0][0] != co[0][0]: print((n - ce[0][1] - co[0][1])) else: if len(ce) == 1 and len(co) == 1: print((n // 2)) elif len(ce) == 1: print((n - co[1][1])) elif len(co) == 1: print((n - ce[1][1])) else: print((min(n - ce[0][1] - co[1][1], n - ce[1][1] - co[0][1]))) if __name__ == "__main__": main()
false
42.857143
[ "- if len(set(v)) == 1:", "- print((n // 2))", "- elif len(set(v)) == 2:", "- cnt1 = 0", "- cnt2 = 0", "- tmp1 = list(set(v))", "- tmp2 = [tmp1[1], tmp1[0]]", "- # even = v[::2]", "- # odd = v[1::2]", "- #", "- for i, a in enumerate(v):", "- if i % 2 == 0:", "- if a == tmp1[0]:", "- cnt1 += 1", "- if a == tmp2[0]:", "- cnt2 += 1", "- else:", "- if a == tmp1[1]:", "- cnt1 += 1", "- if a == tmp2[1]:", "- cnt2 += 1", "- print((n - max(cnt1, cnt2)))", "+ even = v[::2]", "+ odd = v[1::2]", "+ count_e = collections.Counter(even)", "+ count_o = collections.Counter(odd)", "+ ce = count_e.most_common()", "+ co = count_o.most_common()", "+ if ce[0][0] != co[0][0]:", "+ print((n - ce[0][1] - co[0][1]))", "- even = v[::2]", "- odd = v[1::2]", "- count_e = collections.Counter(even)", "- count_o = collections.Counter(odd)", "- ce = count_e.most_common()", "- co = count_o.most_common()", "- if ce[0][0] != co[0][0]:", "- print((n - ce[0][1] - co[0][1]))", "+ if len(ce) == 1 and len(co) == 1:", "+ print((n // 2))", "+ elif len(ce) == 1:", "+ print((n - co[1][1]))", "+ elif len(co) == 1:", "+ print((n - ce[1][1]))", "- if len(ce) == 1:", "- print((n - co[1][1]))", "- elif len(co) == 1:", "- print((n - ce[1][1]))", "- else:", "- print((min(n - ce[0][1] - co[1][1], n - ce[1][1] - co[0][1])))", "+ print((min(n - ce[0][1] - co[1][1], n - ce[1][1] - co[0][1])))" ]
false
0.041349
0.040119
1.030648
[ "s075519619", "s831239816" ]
u102461423
p03595
python
s036607503
s123619103
441
371
64,064
58,576
Accepted
Accepted
15.87
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 998244353 N,M = list(map(int,readline().split())) A = np.array(list(readline().rstrip()),dtype=np.int64) - 48 B = np.array(list(readline().rstrip()),dtype=np.int64) - 48 C = np.array(list(readline().rstrip()),dtype=np.int64) - 48 D = np.array(list(readline().rstrip()),dtype=np.int64) - 48 def cumprod(arr,MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD for n in range(1,Lsq): arr[n] *= arr[n-1,-1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U,MOD): x = np.arange(U,dtype=np.int64); x[0] = 1 fact = cumprod(x,MOD) x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD) fact_inv = cumprod(x,MOD)[::-1] return fact,fact_inv U = 10**6 fact, fact_inv = make_fact(U,MOD) def cnt_vertical(N,M,A,B,C,D): """ ・ABが長さN、CDが長さM。 ・初手に縦線を入れる場合。 ・縦線の右端の位置に応じて場合分けして集計 ・右端の位置を決めると、(左端の位置ごとの左側の入れ方の累積和) x (右側の入れ方の累積和)、適当に重みをつける必要あり """ AB = A+B # ある場所を初めての縦線としたときに、左側にできる部分。上にある点の個数と下にある点の個数 L = C.sum(); LU = A.cumsum() - A; LD = B.cumsum() - B if L >= 1: NL = fact[LU+LD+L-1] * fact_inv[LU+LD] % MOD * fact_inv[L-1] % MOD else: NL = np.zeros(N,dtype=np.int64) i = np.where(AB>0)[0][0] NL[i] = 1 R = D.sum(); RU = A[::-1].cumsum() - A[::-1]; RD = B[::-1].cumsum() - B[::-1] NR = fact[RU+RD+R-1] * fact_inv[RU+RD] % MOD * fact_inv[R-1] % MOD; NR = NR[::-1] x = np.full(N,1,np.int64); x[AB==2] = 2; coef = cumprod(x,MOD) x = np.full(N,1,np.int64); x[AB==2] = (MOD+1)//2; coef_inv = cumprod(x,MOD) NL *= coef_inv; NR *= coef; NL %= MOD; NR %= MOD NL[AB==2] *= 2; NL[NL>=MOD] -= MOD NL[AB==0] = 0; NR[AB==0] = 0 # sum(l<=r) NL[l] NR[r] を求めればよい。 NL_cum = NL.cumsum() % MOD return (NL_cum * NR % MOD).sum() % MOD def AB_only(N,A,B): x = np.ones(N,dtype=np.int64) x[A+B==2] = 2 return cumprod(x,MOD)[-1] def ABC_only(N,M,A,B,C): AB = A+B R = C.sum(); RU = A[::-1].cumsum() - A[::-1]; RD = B[::-1].cumsum() - B[::-1] NR = fact[RU+RD+R-1] * fact_inv[RU+RD] % MOD * fact_inv[R-1] % MOD; NR = NR[::-1] NR[AB==0] = 0 x = np.full(N,1,np.int64); x[AB==2] = 2; coef = cumprod(x,MOD) x=(coef * NR % MOD).sum()%MOD assert x == cnt_vertical(N,M,A,B,np.zeros_like(C),C) n = A.sum()+B.sum()+C.sum()-1; m = C.sum()-1 y = fact[n] * fact_inv[m] % MOD * fact_inv[n-m] % MOD return (x+y)%MOD def F(N,M,A,B,C,D): # 問題の答えを出します。 NA,NB,NC,ND = [np.count_nonzero(x) for x in [A,B,C,D]] if all(x != 0 for x in [NA,NB,NC,ND]): return (cnt_vertical(N,M,A,B,C,D) + cnt_vertical(M,N,C,D,A,B)) % MOD # A,Cに0列を寄せる if NA != 0: NA,NB = NB,NA; A,B = B,A; C = C[::-1]; D = D[::-1] if NC != 0: NC,ND = ND,NC; C,D = D,C; A = A[::-1]; B = B[::-1] if NB == 0: return AB_only(M,C,D) if ND == 0: return AB_only(N,A,B) # B,Dは0ではない if NA == 0 and NC == 0: # 2面B,Dのみ -> binom(B+D,B) return fact[NB+ND] * fact_inv[NB] % MOD * fact_inv[ND] % MOD if NA == 0: return ABC_only(M,N,C,D,B) if NC == 0: return ABC_only(N,M,A,B,D) answer = F(N,M,A,B,C,D) print(answer) N=3 M=2 while True: A=np.random.randint(0,2,N).astype(np.int64) B=np.random.randint(0,2,N).astype(np.int64) C=np.random.randint(0,2,M).astype(np.int64) D=np.random.randint(0,2,M).astype(np.int64) x=F(N,M,A,B,C,D) y=F(M,N,C,D,A,B) z=F(N,M,B,A,C,D) if x != z: break A,B,C,D x,y,z cnt_vertical(N,M,A,B,C,D),cnt_vertical(N,M,B,A,C,D) cnt_vertical(M,N,C,D,A,B),cnt_vertical(M,N,C,D,B,A)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 998244353 N,M = list(map(int,readline().split())) A,B,C,D = [np.array(list(readline().rstrip()))-48 for _ in range(4)] def cumprod(arr,MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD for n in range(1,Lsq): arr[n] *= arr[n-1,-1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U,MOD): x = np.arange(U,dtype=np.int64); x[0] = 1 fact = cumprod(x,MOD) x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD) fact_inv = cumprod(x,MOD)[::-1] return fact,fact_inv U = 10**6 fact, fact_inv = make_fact(U,MOD) def cnt_vertical(N,M,A,B,C,D): """ ・ABが長さN、CDが長さM。 ・初手に縦線を入れる場合。 ・縦線の右端の位置に応じて場合分けして集計 ・右端の位置を決めると、(左端の位置ごとの左側の入れ方の累積和) x (右側の入れ方の累積和)、適当に重みをつける必要あり """ AB=A+B # ある場所を初めての縦線としたときに、左側にできる部分。上にある点の個数と下にある点の個数 L=C.sum(); LU=A.cumsum()-A; LD=B.cumsum()-B NL=fact[LU+LD+L-1]*fact_inv[LU+LD]%MOD*fact_inv[L-1]% MOD R=D.sum(); RU=A[::-1].cumsum()-A[::-1]; RD=B[::-1].cumsum()-B[::-1] NR=fact[RU+RD+R-1]*fact_inv[RU+RD]%MOD*fact_inv[R-1]%MOD; NR=NR[::-1] x=np.ones(N,np.int64); x[AB==2]=2; coef=cumprod(x,MOD) x=np.ones(N,np.int64); x[AB==2]=(MOD+1)//2; coef_inv=cumprod(x,MOD) NL*=coef_inv; NR*=coef; NL%=MOD; NR%=MOD NL[AB==2]*=2 NL[AB==0]=0;NR[AB==0]=0 NL_cum=NL.cumsum()%MOD return (NL_cum*NR%MOD).sum()%MOD def AB_only(N,A,B): x = np.ones(N,np.int64) x[A+B==2] = 2 return cumprod(x,MOD)[-1] def ABC_only(N,M,A,B,C): AB=A+B NA,NB,NC = [np.count_nonzero(x) for x in [A,B,C]] R=NC;RU=A[::-1].cumsum()-A[::-1];RD=B[::-1].cumsum()-B[::-1] NR=fact[RU+RD+R-1]*fact_inv[RU+RD]%MOD*fact_inv[R-1]%MOD; NR=NR[::-1] NR[AB==0]=0 x=np.ones(N,np.int64); x[AB==2]=2; coef=cumprod(x,MOD) x=(coef*NR% MOD).sum()%MOD y=fact[NA+NB+NC-1]*fact_inv[NC-1]%MOD*fact_inv[NA+NB]%MOD return (x+y)%MOD def F(N,M,A,B,C,D): # 問題の答えを出します。 NA,NB,NC,ND = [np.count_nonzero(x) for x in [A,B,C,D]] if all(x != 0 for x in [NA,NB,NC,ND]): return (cnt_vertical(N,M,A,B,C,D) + cnt_vertical(M,N,C,D,A,B)) % MOD # A,Cに0列を寄せる if NA != 0: NA,NB = NB,NA; A,B = B,A; C = C[::-1]; D = D[::-1] if NC != 0: NC,ND = ND,NC; C,D = D,C; A = A[::-1]; B = B[::-1] if NB == 0: return AB_only(M,C,D) if ND == 0: return AB_only(N,A,B) # B,Dは0ではない if NA == 0 and NC == 0: # 2面B,Dのみ -> binom(B+D,B) return fact[NB+ND] * fact_inv[NB] % MOD * fact_inv[ND] % MOD if NA == 0: return ABC_only(M,N,C,D,B) if NC == 0: return ABC_only(N,M,A,B,D) answer = F(N,M,A,B,C,D) print(answer)
127
95
3,975
2,976
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 998244353 N, M = list(map(int, readline().split())) A = np.array(list(readline().rstrip()), dtype=np.int64) - 48 B = np.array(list(readline().rstrip()), dtype=np.int64) - 48 C = np.array(list(readline().rstrip()), dtype=np.int64) - 48 D = np.array(list(readline().rstrip()), dtype=np.int64) - 48 def cumprod(arr, MOD): L = len(arr) Lsq = int(L**0.5 + 1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n - 1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n - 1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 fact, fact_inv = make_fact(U, MOD) def cnt_vertical(N, M, A, B, C, D): """ ・ABが長さN、CDが長さM。 ・初手に縦線を入れる場合。 ・縦線の右端の位置に応じて場合分けして集計 ・右端の位置を決めると、(左端の位置ごとの左側の入れ方の累積和) x (右側の入れ方の累積和)、適当に重みをつける必要あり """ AB = A + B # ある場所を初めての縦線としたときに、左側にできる部分。上にある点の個数と下にある点の個数 L = C.sum() LU = A.cumsum() - A LD = B.cumsum() - B if L >= 1: NL = fact[LU + LD + L - 1] * fact_inv[LU + LD] % MOD * fact_inv[L - 1] % MOD else: NL = np.zeros(N, dtype=np.int64) i = np.where(AB > 0)[0][0] NL[i] = 1 R = D.sum() RU = A[::-1].cumsum() - A[::-1] RD = B[::-1].cumsum() - B[::-1] NR = fact[RU + RD + R - 1] * fact_inv[RU + RD] % MOD * fact_inv[R - 1] % MOD NR = NR[::-1] x = np.full(N, 1, np.int64) x[AB == 2] = 2 coef = cumprod(x, MOD) x = np.full(N, 1, np.int64) x[AB == 2] = (MOD + 1) // 2 coef_inv = cumprod(x, MOD) NL *= coef_inv NR *= coef NL %= MOD NR %= MOD NL[AB == 2] *= 2 NL[NL >= MOD] -= MOD NL[AB == 0] = 0 NR[AB == 0] = 0 # sum(l<=r) NL[l] NR[r] を求めればよい。 NL_cum = NL.cumsum() % MOD return (NL_cum * NR % MOD).sum() % MOD def AB_only(N, A, B): x = np.ones(N, dtype=np.int64) x[A + B == 2] = 2 return cumprod(x, MOD)[-1] def ABC_only(N, M, A, B, C): AB = A + B R = C.sum() RU = A[::-1].cumsum() - A[::-1] RD = B[::-1].cumsum() - B[::-1] NR = fact[RU + RD + R - 1] * fact_inv[RU + RD] % MOD * fact_inv[R - 1] % MOD NR = NR[::-1] NR[AB == 0] = 0 x = np.full(N, 1, np.int64) x[AB == 2] = 2 coef = cumprod(x, MOD) x = (coef * NR % MOD).sum() % MOD assert x == cnt_vertical(N, M, A, B, np.zeros_like(C), C) n = A.sum() + B.sum() + C.sum() - 1 m = C.sum() - 1 y = fact[n] * fact_inv[m] % MOD * fact_inv[n - m] % MOD return (x + y) % MOD def F(N, M, A, B, C, D): # 問題の答えを出します。 NA, NB, NC, ND = [np.count_nonzero(x) for x in [A, B, C, D]] if all(x != 0 for x in [NA, NB, NC, ND]): return (cnt_vertical(N, M, A, B, C, D) + cnt_vertical(M, N, C, D, A, B)) % MOD # A,Cに0列を寄せる if NA != 0: NA, NB = NB, NA A, B = B, A C = C[::-1] D = D[::-1] if NC != 0: NC, ND = ND, NC C, D = D, C A = A[::-1] B = B[::-1] if NB == 0: return AB_only(M, C, D) if ND == 0: return AB_only(N, A, B) # B,Dは0ではない if NA == 0 and NC == 0: # 2面B,Dのみ -> binom(B+D,B) return fact[NB + ND] * fact_inv[NB] % MOD * fact_inv[ND] % MOD if NA == 0: return ABC_only(M, N, C, D, B) if NC == 0: return ABC_only(N, M, A, B, D) answer = F(N, M, A, B, C, D) print(answer) N = 3 M = 2 while True: A = np.random.randint(0, 2, N).astype(np.int64) B = np.random.randint(0, 2, N).astype(np.int64) C = np.random.randint(0, 2, M).astype(np.int64) D = np.random.randint(0, 2, M).astype(np.int64) x = F(N, M, A, B, C, D) y = F(M, N, C, D, A, B) z = F(N, M, B, A, C, D) if x != z: break A, B, C, D x, y, z cnt_vertical(N, M, A, B, C, D), cnt_vertical(N, M, B, A, C, D) cnt_vertical(M, N, C, D, A, B), cnt_vertical(M, N, C, D, B, A)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 998244353 N, M = list(map(int, readline().split())) A, B, C, D = [np.array(list(readline().rstrip())) - 48 for _ in range(4)] def cumprod(arr, MOD): L = len(arr) Lsq = int(L**0.5 + 1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n - 1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n - 1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 fact, fact_inv = make_fact(U, MOD) def cnt_vertical(N, M, A, B, C, D): """ ・ABが長さN、CDが長さM。 ・初手に縦線を入れる場合。 ・縦線の右端の位置に応じて場合分けして集計 ・右端の位置を決めると、(左端の位置ごとの左側の入れ方の累積和) x (右側の入れ方の累積和)、適当に重みをつける必要あり """ AB = A + B # ある場所を初めての縦線としたときに、左側にできる部分。上にある点の個数と下にある点の個数 L = C.sum() LU = A.cumsum() - A LD = B.cumsum() - B NL = fact[LU + LD + L - 1] * fact_inv[LU + LD] % MOD * fact_inv[L - 1] % MOD R = D.sum() RU = A[::-1].cumsum() - A[::-1] RD = B[::-1].cumsum() - B[::-1] NR = fact[RU + RD + R - 1] * fact_inv[RU + RD] % MOD * fact_inv[R - 1] % MOD NR = NR[::-1] x = np.ones(N, np.int64) x[AB == 2] = 2 coef = cumprod(x, MOD) x = np.ones(N, np.int64) x[AB == 2] = (MOD + 1) // 2 coef_inv = cumprod(x, MOD) NL *= coef_inv NR *= coef NL %= MOD NR %= MOD NL[AB == 2] *= 2 NL[AB == 0] = 0 NR[AB == 0] = 0 NL_cum = NL.cumsum() % MOD return (NL_cum * NR % MOD).sum() % MOD def AB_only(N, A, B): x = np.ones(N, np.int64) x[A + B == 2] = 2 return cumprod(x, MOD)[-1] def ABC_only(N, M, A, B, C): AB = A + B NA, NB, NC = [np.count_nonzero(x) for x in [A, B, C]] R = NC RU = A[::-1].cumsum() - A[::-1] RD = B[::-1].cumsum() - B[::-1] NR = fact[RU + RD + R - 1] * fact_inv[RU + RD] % MOD * fact_inv[R - 1] % MOD NR = NR[::-1] NR[AB == 0] = 0 x = np.ones(N, np.int64) x[AB == 2] = 2 coef = cumprod(x, MOD) x = (coef * NR % MOD).sum() % MOD y = fact[NA + NB + NC - 1] * fact_inv[NC - 1] % MOD * fact_inv[NA + NB] % MOD return (x + y) % MOD def F(N, M, A, B, C, D): # 問題の答えを出します。 NA, NB, NC, ND = [np.count_nonzero(x) for x in [A, B, C, D]] if all(x != 0 for x in [NA, NB, NC, ND]): return (cnt_vertical(N, M, A, B, C, D) + cnt_vertical(M, N, C, D, A, B)) % MOD # A,Cに0列を寄せる if NA != 0: NA, NB = NB, NA A, B = B, A C = C[::-1] D = D[::-1] if NC != 0: NC, ND = ND, NC C, D = D, C A = A[::-1] B = B[::-1] if NB == 0: return AB_only(M, C, D) if ND == 0: return AB_only(N, A, B) # B,Dは0ではない if NA == 0 and NC == 0: # 2面B,Dのみ -> binom(B+D,B) return fact[NB + ND] * fact_inv[NB] % MOD * fact_inv[ND] % MOD if NA == 0: return ABC_only(M, N, C, D, B) if NC == 0: return ABC_only(N, M, A, B, D) answer = F(N, M, A, B, C, D) print(answer)
false
25.19685
[ "-A = np.array(list(readline().rstrip()), dtype=np.int64) - 48", "-B = np.array(list(readline().rstrip()), dtype=np.int64) - 48", "-C = np.array(list(readline().rstrip()), dtype=np.int64) - 48", "-D = np.array(list(readline().rstrip()), dtype=np.int64) - 48", "+A, B, C, D = [np.array(list(readline().rstrip())) - 48 for _ in range(4)]", "- if L >= 1:", "- NL = fact[LU + LD + L - 1] * fact_inv[LU + LD] % MOD * fact_inv[L - 1] % MOD", "- else:", "- NL = np.zeros(N, dtype=np.int64)", "- i = np.where(AB > 0)[0][0]", "- NL[i] = 1", "+ NL = fact[LU + LD + L - 1] * fact_inv[LU + LD] % MOD * fact_inv[L - 1] % MOD", "- x = np.full(N, 1, np.int64)", "+ x = np.ones(N, np.int64)", "- x = np.full(N, 1, np.int64)", "+ x = np.ones(N, np.int64)", "- NL[NL >= MOD] -= MOD", "- # sum(l<=r) NL[l] NR[r] を求めればよい。", "- x = np.ones(N, dtype=np.int64)", "+ x = np.ones(N, np.int64)", "- R = C.sum()", "+ NA, NB, NC = [np.count_nonzero(x) for x in [A, B, C]]", "+ R = NC", "- x = np.full(N, 1, np.int64)", "+ x = np.ones(N, np.int64)", "- assert x == cnt_vertical(N, M, A, B, np.zeros_like(C), C)", "- n = A.sum() + B.sum() + C.sum() - 1", "- m = C.sum() - 1", "- y = fact[n] * fact_inv[m] % MOD * fact_inv[n - m] % MOD", "+ y = fact[NA + NB + NC - 1] * fact_inv[NC - 1] % MOD * fact_inv[NA + NB] % MOD", "-N = 3", "-M = 2", "-while True:", "- A = np.random.randint(0, 2, N).astype(np.int64)", "- B = np.random.randint(0, 2, N).astype(np.int64)", "- C = np.random.randint(0, 2, M).astype(np.int64)", "- D = np.random.randint(0, 2, M).astype(np.int64)", "- x = F(N, M, A, B, C, D)", "- y = F(M, N, C, D, A, B)", "- z = F(N, M, B, A, C, D)", "- if x != z:", "- break", "-A, B, C, D", "-x, y, z", "-cnt_vertical(N, M, A, B, C, D), cnt_vertical(N, M, B, A, C, D)", "-cnt_vertical(M, N, C, D, A, B), cnt_vertical(M, N, C, D, B, A)" ]
false
0.746757
0.522016
1.430526
[ "s036607503", "s123619103" ]
u987164499
p02813
python
s308695003
s410302521
55
28
10,484
3,064
Accepted
Accepted
49.09
from sys import stdin import math n = int(stdin.readline().rstrip()) li = list(map(int,stdin.readline().rstrip().split())) lin = list(map(int,stdin.readline().rstrip().split())) from itertools import permutations lis = permutations(li) liv = [] for i in lis: liv.append(list(i)) liv.sort() a = liv.index(li) b = liv.index(lin) print((abs(a-b)))
from itertools import permutations n = int(eval(input())) li = [i for i in range(1,n+1)] p = tuple(map(int,input().split())) q = tuple(map(int,input().split())) for i,j in enumerate(permutations(li)): if j == p: num_p = i if j == q: num_q = i print((abs(num_p-num_q)))
18
14
367
300
from sys import stdin import math n = int(stdin.readline().rstrip()) li = list(map(int, stdin.readline().rstrip().split())) lin = list(map(int, stdin.readline().rstrip().split())) from itertools import permutations lis = permutations(li) liv = [] for i in lis: liv.append(list(i)) liv.sort() a = liv.index(li) b = liv.index(lin) print((abs(a - b)))
from itertools import permutations n = int(eval(input())) li = [i for i in range(1, n + 1)] p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) for i, j in enumerate(permutations(li)): if j == p: num_p = i if j == q: num_q = i print((abs(num_p - num_q)))
false
22.222222
[ "-from sys import stdin", "-import math", "-", "-n = int(stdin.readline().rstrip())", "-li = list(map(int, stdin.readline().rstrip().split()))", "-lin = list(map(int, stdin.readline().rstrip().split()))", "-lis = permutations(li)", "-liv = []", "-for i in lis:", "- liv.append(list(i))", "-liv.sort()", "-a = liv.index(li)", "-b = liv.index(lin)", "-print((abs(a - b)))", "+n = int(eval(input()))", "+li = [i for i in range(1, n + 1)]", "+p = tuple(map(int, input().split()))", "+q = tuple(map(int, input().split()))", "+for i, j in enumerate(permutations(li)):", "+ if j == p:", "+ num_p = i", "+ if j == q:", "+ num_q = i", "+print((abs(num_p - num_q)))" ]
false
0.127352
0.084067
1.514876
[ "s308695003", "s410302521" ]
u554781254
p02695
python
s501709233
s175290792
1,419
677
21,900
9,224
Accepted
Accepted
52.29
import sys sys.setrecursionlimit(10 ** 9) input = sys.stdin.readline from itertools import permutations, combinations, accumulate, product, combinations_with_replacement from functools import * from collections import deque, defaultdict, Counter from heapq import heapify, heappop, heappush, heappushpop N, M, Q = list(map(int, input().split())) abcd_ls = [] for _ in range(Q): abcd_ls.append(list(map(int, input().split()))) a_candidate = list(combinations_with_replacement(list(range(1, M + 1)), N)) max_total = 0 for A in a_candidate: total = 0 for abcd in abcd_ls: a, b, c, d = abcd a -= 1 b -= 1 if c == A[b] - A[a]: total += d max_total = max(total, max_total) print(max_total)
import sys import itertools sys.setrecursionlimit(10 ** 9) input = sys.stdin.readline N, M, Q = list(map(int, input().split())) abcd_ls = [list(map(int, input().split())) for _ in range(Q)] def calc(): score = 0 for abcd in abcd_ls: a, b, c, d = abcd a -= 1 b -= 1 if c == A[b] - A[a]: score += d return score def dfs(i, mx): if i == N: return calc() score = 0 for x in range(mx, M+1): A[i] = x s = dfs(i+1, x) score = max(s, score) return score A = [0] * N ans = dfs(0, 1) print(ans)
31
37
771
629
import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline from itertools import ( permutations, combinations, accumulate, product, combinations_with_replacement, ) from functools import * from collections import deque, defaultdict, Counter from heapq import heapify, heappop, heappush, heappushpop N, M, Q = list(map(int, input().split())) abcd_ls = [] for _ in range(Q): abcd_ls.append(list(map(int, input().split()))) a_candidate = list(combinations_with_replacement(list(range(1, M + 1)), N)) max_total = 0 for A in a_candidate: total = 0 for abcd in abcd_ls: a, b, c, d = abcd a -= 1 b -= 1 if c == A[b] - A[a]: total += d max_total = max(total, max_total) print(max_total)
import sys import itertools sys.setrecursionlimit(10**9) input = sys.stdin.readline N, M, Q = list(map(int, input().split())) abcd_ls = [list(map(int, input().split())) for _ in range(Q)] def calc(): score = 0 for abcd in abcd_ls: a, b, c, d = abcd a -= 1 b -= 1 if c == A[b] - A[a]: score += d return score def dfs(i, mx): if i == N: return calc() score = 0 for x in range(mx, M + 1): A[i] = x s = dfs(i + 1, x) score = max(s, score) return score A = [0] * N ans = dfs(0, 1) print(ans)
false
16.216216
[ "+import itertools", "-from itertools import (", "- permutations,", "- combinations,", "- accumulate,", "- product,", "- combinations_with_replacement,", "-)", "-from functools import *", "-from collections import deque, defaultdict, Counter", "-from heapq import heapify, heappop, heappush, heappushpop", "+N, M, Q = list(map(int, input().split()))", "+abcd_ls = [list(map(int, input().split())) for _ in range(Q)]", "-N, M, Q = list(map(int, input().split()))", "-abcd_ls = []", "-for _ in range(Q):", "- abcd_ls.append(list(map(int, input().split())))", "-a_candidate = list(combinations_with_replacement(list(range(1, M + 1)), N))", "-max_total = 0", "-for A in a_candidate:", "- total = 0", "+", "+def calc():", "+ score = 0", "- total += d", "- max_total = max(total, max_total)", "-print(max_total)", "+ score += d", "+ return score", "+", "+", "+def dfs(i, mx):", "+ if i == N:", "+ return calc()", "+ score = 0", "+ for x in range(mx, M + 1):", "+ A[i] = x", "+ s = dfs(i + 1, x)", "+ score = max(s, score)", "+ return score", "+", "+", "+A = [0] * N", "+ans = dfs(0, 1)", "+print(ans)" ]
false
0.159227
0.051067
3.117979
[ "s501709233", "s175290792" ]
u969850098
p03102
python
s199443104
s628487379
150
18
12,392
3,064
Accepted
Accepted
88
import numpy as np N, M, C = list(map(int, input().split())) B = np.array(list(map(int, input().split()))) cnt = 0 for _ in range(N): A =np.array( list(map(int, input().split()))) if sum(A * B) + C > 0: cnt += 1 print(cnt)
import sys readline = sys.stdin.readline def main(): N, M, C = list(map(int, readline().rstrip().split())) B = list(map(int, readline().rstrip().split())) ans = 0 for _ in range(N): A = list(map(int, readline().rstrip().split())) if sum([a*b for a, b in zip(A, B)]) + C > 0: ans += 1 print(ans) if __name__ == '__main__': main()
9
17
240
398
import numpy as np N, M, C = list(map(int, input().split())) B = np.array(list(map(int, input().split()))) cnt = 0 for _ in range(N): A = np.array(list(map(int, input().split()))) if sum(A * B) + C > 0: cnt += 1 print(cnt)
import sys readline = sys.stdin.readline def main(): N, M, C = list(map(int, readline().rstrip().split())) B = list(map(int, readline().rstrip().split())) ans = 0 for _ in range(N): A = list(map(int, readline().rstrip().split())) if sum([a * b for a, b in zip(A, B)]) + C > 0: ans += 1 print(ans) if __name__ == "__main__": main()
false
47.058824
[ "-import numpy as np", "+import sys", "-N, M, C = list(map(int, input().split()))", "-B = np.array(list(map(int, input().split())))", "-cnt = 0", "-for _ in range(N):", "- A = np.array(list(map(int, input().split())))", "- if sum(A * B) + C > 0:", "- cnt += 1", "-print(cnt)", "+readline = sys.stdin.readline", "+", "+", "+def main():", "+ N, M, C = list(map(int, readline().rstrip().split()))", "+ B = list(map(int, readline().rstrip().split()))", "+ ans = 0", "+ for _ in range(N):", "+ A = list(map(int, readline().rstrip().split()))", "+ if sum([a * b for a, b in zip(A, B)]) + C > 0:", "+ ans += 1", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.189445
0.038296
4.946805
[ "s199443104", "s628487379" ]
u752522099
p02755
python
s483742786
s127032067
22
20
2,940
3,064
Accepted
Accepted
9.09
import math a,b = list(map(int,input().split())) i = math.floor(a/0.08) while i < 10001: if math.floor(i*0.08) == a and math.floor(i*0.1) ==b: print(i) break i += 1 else: print((-1))
a,b = list(map(int,input().split())) for price in range(10000): if price * 8 // 100 == a and price * 10//100 ==b: print(price) exit() else: print((-1))
11
7
214
173
import math a, b = list(map(int, input().split())) i = math.floor(a / 0.08) while i < 10001: if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b: print(i) break i += 1 else: print((-1))
a, b = list(map(int, input().split())) for price in range(10000): if price * 8 // 100 == a and price * 10 // 100 == b: print(price) exit() else: print((-1))
false
36.363636
[ "-import math", "-", "-i = math.floor(a / 0.08)", "-while i < 10001:", "- if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b:", "- print(i)", "- break", "- i += 1", "+for price in range(10000):", "+ if price * 8 // 100 == a and price * 10 // 100 == b:", "+ print(price)", "+ exit()" ]
false
0.042891
0.041187
1.041357
[ "s483742786", "s127032067" ]
u873915460
p02567
python
s502480664
s730309506
1,281
633
139,244
157,632
Accepted
Accepted
50.59
from copy import * def init(N,node,unit,func): n=1 while n<N: n<<=1 for i in range(n*2-1): if len(node)<=i: node.append(deepcopy(unit)) else: node[i]=deepcopy(unit) node.append(func) node.append(unit) node.append(n) def upd(node,x,a): y=node[-1]+x node[y-1]=a while y>1: y=y>>1 node[y-1]=node[-3](node[(y<<1)-1],node[y<<1]) def query(node,l,r): x,y=l,r z=node[-1]-1 r=node[-2] while True: if x==y: return r if x&1: r=node[-3](r,node[x+z]) x+=1 if y&1: r=node[-3](r,node[y+z-1]) x>>=1 y>>=1 z>>=1 if z==0: return r def bis_min_k(node,k,cond): x=k+1 while True: if node[-1]<=x: return x-node[-1] if cond(node[(x<<1)-1]): x=x<<1 else: x=(x<<1)+1 def bis_min(node,l,r,cond): x,y=l,r z=node[-1]-1 for i in range(30): if x+(1<<i)>y: break if x&(1<<i): if cond(node[z+(x>>i)]): return bis_min_k(node,z+(x>>i),cond) x+=(1<<i) if z==0: break z>>=1 for i in range(29,-1,-1): if i and ((node[-1]-1)>>(i-1))==0: continue if x+(1<<i)>y: continue if (y-x)&(1<<i): if cond(node[((node[-1]-1)>>i)+(x>>i)]): return bis_min_k(node,((node[-1]-1)>>i)+(x>>i),cond) x+=(1<<i) return node[-1] N,Q=list(map(int,input().split())) A=list(map(int,input().split())) X=[] init(N+1,X,-1,lambda x,y:max(x,y)) for i in range(N): upd(X,i,A[i]) t,a,b=0,0,0 for i in range(Q): t,a,b=list(map(int,input().split())) if t==1: upd(X,a-1,b) elif t==2: print((query(X,a-1,b))) else: a=bis_min(X,a-1,N,lambda x:b<=x) if a>N: print((N+1)) else: print((a+1))
from copy import * import sys S=sys.stdin.readlines() def init(N,node,unit,func): n=1 while n<N: n<<=1 for i in range(n*2-1): if len(node)<=i: node.append(deepcopy(unit)) else: node[i]=deepcopy(unit) node.append(func) node.append(unit) node.append(n) def upd(node,x,a): y=node[-1]+x node[y-1]=a while y>1: y=y>>1 node[y-1]=node[-3](node[(y<<1)-1],node[y<<1]) def query(node,l,r): x,y=l,r z=node[-1]-1 r=node[-2] while True: if x==y: return r if x&1: r=node[-3](r,node[x+z]) x+=1 if y&1: r=node[-3](r,node[y+z-1]) x>>=1 y>>=1 z>>=1 if z==0: return r def bis_min_k(node,k,cond): x=k+1 while True: if node[-1]<=x: return x-node[-1] if cond(node[(x<<1)-1]): x=x<<1 else: x=(x<<1)+1 def bis_min(node,l,r,cond): x,y=l,r z=node[-1]-1 for i in range(30): if x+(1<<i)>y: break if x&(1<<i): if cond(node[z+(x>>i)]): return bis_min_k(node,z+(x>>i),cond) x+=(1<<i) if z==0: break z>>=1 for i in range(29,-1,-1): if i and ((node[-1]-1)>>(i-1))==0: continue if x+(1<<i)>y: continue if (y-x)&(1<<i): if cond(node[((node[-1]-1)>>i)+(x>>i)]): return bis_min_k(node,((node[-1]-1)>>i)+(x>>i),cond) x+=(1<<i) return node[-1] N,Q=list(map(int,S[0].split())) A=list(map(int,S[1].split())) X=[] init(N+1,X,-1,lambda x,y:max(x,y)) for i in range(N): upd(X,i,A[i]) t,a,b=0,0,0 for i in range(Q): t,a,b=list(map(int,S[i+2].split())) if t==1: upd(X,a-1,b) elif t==2: print((query(X,a-1,b))) else: a=bis_min(X,a-1,N,lambda x:b<=x) if a>N: print((N+1)) else: print((a+1))
93
95
1,788
1,819
from copy import * def init(N, node, unit, func): n = 1 while n < N: n <<= 1 for i in range(n * 2 - 1): if len(node) <= i: node.append(deepcopy(unit)) else: node[i] = deepcopy(unit) node.append(func) node.append(unit) node.append(n) def upd(node, x, a): y = node[-1] + x node[y - 1] = a while y > 1: y = y >> 1 node[y - 1] = node[-3](node[(y << 1) - 1], node[y << 1]) def query(node, l, r): x, y = l, r z = node[-1] - 1 r = node[-2] while True: if x == y: return r if x & 1: r = node[-3](r, node[x + z]) x += 1 if y & 1: r = node[-3](r, node[y + z - 1]) x >>= 1 y >>= 1 z >>= 1 if z == 0: return r def bis_min_k(node, k, cond): x = k + 1 while True: if node[-1] <= x: return x - node[-1] if cond(node[(x << 1) - 1]): x = x << 1 else: x = (x << 1) + 1 def bis_min(node, l, r, cond): x, y = l, r z = node[-1] - 1 for i in range(30): if x + (1 << i) > y: break if x & (1 << i): if cond(node[z + (x >> i)]): return bis_min_k(node, z + (x >> i), cond) x += 1 << i if z == 0: break z >>= 1 for i in range(29, -1, -1): if i and ((node[-1] - 1) >> (i - 1)) == 0: continue if x + (1 << i) > y: continue if (y - x) & (1 << i): if cond(node[((node[-1] - 1) >> i) + (x >> i)]): return bis_min_k(node, ((node[-1] - 1) >> i) + (x >> i), cond) x += 1 << i return node[-1] N, Q = list(map(int, input().split())) A = list(map(int, input().split())) X = [] init(N + 1, X, -1, lambda x, y: max(x, y)) for i in range(N): upd(X, i, A[i]) t, a, b = 0, 0, 0 for i in range(Q): t, a, b = list(map(int, input().split())) if t == 1: upd(X, a - 1, b) elif t == 2: print((query(X, a - 1, b))) else: a = bis_min(X, a - 1, N, lambda x: b <= x) if a > N: print((N + 1)) else: print((a + 1))
from copy import * import sys S = sys.stdin.readlines() def init(N, node, unit, func): n = 1 while n < N: n <<= 1 for i in range(n * 2 - 1): if len(node) <= i: node.append(deepcopy(unit)) else: node[i] = deepcopy(unit) node.append(func) node.append(unit) node.append(n) def upd(node, x, a): y = node[-1] + x node[y - 1] = a while y > 1: y = y >> 1 node[y - 1] = node[-3](node[(y << 1) - 1], node[y << 1]) def query(node, l, r): x, y = l, r z = node[-1] - 1 r = node[-2] while True: if x == y: return r if x & 1: r = node[-3](r, node[x + z]) x += 1 if y & 1: r = node[-3](r, node[y + z - 1]) x >>= 1 y >>= 1 z >>= 1 if z == 0: return r def bis_min_k(node, k, cond): x = k + 1 while True: if node[-1] <= x: return x - node[-1] if cond(node[(x << 1) - 1]): x = x << 1 else: x = (x << 1) + 1 def bis_min(node, l, r, cond): x, y = l, r z = node[-1] - 1 for i in range(30): if x + (1 << i) > y: break if x & (1 << i): if cond(node[z + (x >> i)]): return bis_min_k(node, z + (x >> i), cond) x += 1 << i if z == 0: break z >>= 1 for i in range(29, -1, -1): if i and ((node[-1] - 1) >> (i - 1)) == 0: continue if x + (1 << i) > y: continue if (y - x) & (1 << i): if cond(node[((node[-1] - 1) >> i) + (x >> i)]): return bis_min_k(node, ((node[-1] - 1) >> i) + (x >> i), cond) x += 1 << i return node[-1] N, Q = list(map(int, S[0].split())) A = list(map(int, S[1].split())) X = [] init(N + 1, X, -1, lambda x, y: max(x, y)) for i in range(N): upd(X, i, A[i]) t, a, b = 0, 0, 0 for i in range(Q): t, a, b = list(map(int, S[i + 2].split())) if t == 1: upd(X, a - 1, b) elif t == 2: print((query(X, a - 1, b))) else: a = bis_min(X, a - 1, N, lambda x: b <= x) if a > N: print((N + 1)) else: print((a + 1))
false
2.105263
[ "+import sys", "+", "+S = sys.stdin.readlines()", "-N, Q = list(map(int, input().split()))", "-A = list(map(int, input().split()))", "+N, Q = list(map(int, S[0].split()))", "+A = list(map(int, S[1].split()))", "- t, a, b = list(map(int, input().split()))", "+ t, a, b = list(map(int, S[i + 2].split()))" ]
false
0.045886
0.039579
1.159359
[ "s502480664", "s730309506" ]
u146803137
p02899
python
s153632265
s269957984
179
136
14,024
87,268
Accepted
Accepted
24.02
import math def py(): print("Yes") def pn(): print("No") def iin(): x = int(input()) return x neko = 0 nya = 0 nuko = 0 n = iin() a = [int(x) for x in input().split()] b = [0] * n for i in range(n): b[a[i]-1] = i + 1 for i in range(n): print(b[i],end=' ')
n = int(input()) a = list(map(int,input().split())) b = [None] * n for i in range(n): b[a[i]-1] = i+1 for i in range(n): print(b[i],end = ' ')
21
7
302
157
import math def py(): print("Yes") def pn(): print("No") def iin(): x = int(input()) return x neko = 0 nya = 0 nuko = 0 n = iin() a = [int(x) for x in input().split()] b = [0] * n for i in range(n): b[a[i] - 1] = i + 1 for i in range(n): print(b[i], end=" ")
n = int(input()) a = list(map(int, input().split())) b = [None] * n for i in range(n): b[a[i] - 1] = i + 1 for i in range(n): print(b[i], end=" ")
false
66.666667
[ "-import math", "-", "-", "-def py():", "- print(\"Yes\")", "-", "-", "-def pn():", "- print(\"No\")", "-", "-", "-def iin():", "- x = int(input())", "- return x", "-", "-", "-neko = 0", "-nya = 0", "-nuko = 0", "-n = iin()", "-a = [int(x) for x in input().split()]", "-b = [0] * n", "+n = int(input())", "+a = list(map(int, input().split()))", "+b = [None] * n" ]
false
0.038183
0.007341
5.201476
[ "s153632265", "s269957984" ]
u691018832
p02975
python
s544786322
s467208143
64
56
14,100
12,468
Accepted
Accepted
12.5
import sys input = sys.stdin.readline n = int(eval(input())) a = list(map(int, input().split())) for i in range(1, n): a[i] ^= a[i - 1] if a[n - 1] == 0: print('Yes') else: print('No')
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, *a = list(map(int, read().split())) for af in a[1:]: a[0] ^= af print(('Yes' if a[0] == 0 else 'No'))
11
10
196
258
import sys input = sys.stdin.readline n = int(eval(input())) a = list(map(int, input().split())) for i in range(1, n): a[i] ^= a[i - 1] if a[n - 1] == 0: print("Yes") else: print("No")
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) n, *a = list(map(int, read().split())) for af in a[1:]: a[0] ^= af print(("Yes" if a[0] == 0 else "No"))
false
9.090909
[ "-input = sys.stdin.readline", "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-for i in range(1, n):", "- a[i] ^= a[i - 1]", "-if a[n - 1] == 0:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+sys.setrecursionlimit(10**7)", "+n, *a = list(map(int, read().split()))", "+for af in a[1:]:", "+ a[0] ^= af", "+print((\"Yes\" if a[0] == 0 else \"No\"))" ]
false
0.043625
0.042802
1.019228
[ "s544786322", "s467208143" ]
u459150945
p03212
python
s000658543
s515050131
234
39
45,168
3,188
Accepted
Accepted
83.33
import itertools N = int(eval(input())) ans = 0 for i in range(3, 10): product = list(itertools.product(['3', '5', '7'], repeat=i)) for li in product: if len(set(li)) == 3: if int(''.join(li)) <= N: ans += 1 print(ans)
N = int(eval(input())) def dfs(cur, use, cnt): if cur > N: return if use == 0b111: cnt.append(1) dfs(cur*10 + 7, use | 0b001, cnt) dfs(cur*10 + 5, use | 0b010, cnt) dfs(cur*10 + 3, use | 0b100, cnt) res = [] dfs(0, 0, res) print((sum(res)))
10
16
266
288
import itertools N = int(eval(input())) ans = 0 for i in range(3, 10): product = list(itertools.product(["3", "5", "7"], repeat=i)) for li in product: if len(set(li)) == 3: if int("".join(li)) <= N: ans += 1 print(ans)
N = int(eval(input())) def dfs(cur, use, cnt): if cur > N: return if use == 0b111: cnt.append(1) dfs(cur * 10 + 7, use | 0b001, cnt) dfs(cur * 10 + 5, use | 0b010, cnt) dfs(cur * 10 + 3, use | 0b100, cnt) res = [] dfs(0, 0, res) print((sum(res)))
false
37.5
[ "-import itertools", "+N = int(eval(input()))", "-N = int(eval(input()))", "-ans = 0", "-for i in range(3, 10):", "- product = list(itertools.product([\"3\", \"5\", \"7\"], repeat=i))", "- for li in product:", "- if len(set(li)) == 3:", "- if int(\"\".join(li)) <= N:", "- ans += 1", "-print(ans)", "+", "+def dfs(cur, use, cnt):", "+ if cur > N:", "+ return", "+ if use == 0b111:", "+ cnt.append(1)", "+ dfs(cur * 10 + 7, use | 0b001, cnt)", "+ dfs(cur * 10 + 5, use | 0b010, cnt)", "+ dfs(cur * 10 + 3, use | 0b100, cnt)", "+", "+", "+res = []", "+dfs(0, 0, res)", "+print((sum(res)))" ]
false
0.191591
0.042504
4.507647
[ "s000658543", "s515050131" ]
u067983636
p03201
python
s242172016
s060697361
782
582
56,056
43,728
Accepted
Accepted
25.58
import bisect import math N = int(eval(input())) A = list(map(int, input().split())) T = [2 ** i for i in range(31)] A.sort() already = set() def to_dic(A): d = {} for a in A: d[a] = d.setdefault(a, 0) + 1 return d def is_in(t, num): i = D.setdefault(t, 0) if i == 0: return 0 s = min(i, num) D[t] -= s return s res = 0 D = to_dic(A) A2 = list(D.keys()) A2.sort() for n in range(len(A2) - 1, -1, -1): a = A2[n] if a in T: res += D[a] // 2 D[a] = 0 if D[a] % 2 == 0: continue num = D[a] t = 1 << (int(math.log2(a)) + 1) while t > a: s = is_in(t - a, num) res += s num -= s if num == 0: break t >>= 1 print(res)
import bisect import math N = int(eval(input())) A = list(map(int, input().split())) A.sort() already = set() key = {} def is_in(t, n): i = key.setdefault(t, bisect.bisect_left(A, t)) if i >= n: return -1 while i < n and t == A[i]: if i not in already: already.add(i) key[t] = i return i i += 1 return -1 res = 0 for n in range(len(A) - 1, -1, -1): if n in already: continue a = A[n] t = 1 << (int(math.log2(a)) + 1) while t > a: i = is_in(t - a, n) if i != -1: res += 1 break t >>= 1 print(res) print("")
53
39
825
693
import bisect import math N = int(eval(input())) A = list(map(int, input().split())) T = [2**i for i in range(31)] A.sort() already = set() def to_dic(A): d = {} for a in A: d[a] = d.setdefault(a, 0) + 1 return d def is_in(t, num): i = D.setdefault(t, 0) if i == 0: return 0 s = min(i, num) D[t] -= s return s res = 0 D = to_dic(A) A2 = list(D.keys()) A2.sort() for n in range(len(A2) - 1, -1, -1): a = A2[n] if a in T: res += D[a] // 2 D[a] = 0 if D[a] % 2 == 0: continue num = D[a] t = 1 << (int(math.log2(a)) + 1) while t > a: s = is_in(t - a, num) res += s num -= s if num == 0: break t >>= 1 print(res)
import bisect import math N = int(eval(input())) A = list(map(int, input().split())) A.sort() already = set() key = {} def is_in(t, n): i = key.setdefault(t, bisect.bisect_left(A, t)) if i >= n: return -1 while i < n and t == A[i]: if i not in already: already.add(i) key[t] = i return i i += 1 return -1 res = 0 for n in range(len(A) - 1, -1, -1): if n in already: continue a = A[n] t = 1 << (int(math.log2(a)) + 1) while t > a: i = is_in(t - a, n) if i != -1: res += 1 break t >>= 1 print(res) print("")
false
26.415094
[ "-T = [2**i for i in range(31)]", "+key = {}", "-def to_dic(A):", "- d = {}", "- for a in A:", "- d[a] = d.setdefault(a, 0) + 1", "- return d", "-", "-", "-def is_in(t, num):", "- i = D.setdefault(t, 0)", "- if i == 0:", "- return 0", "- s = min(i, num)", "- D[t] -= s", "- return s", "+def is_in(t, n):", "+ i = key.setdefault(t, bisect.bisect_left(A, t))", "+ if i >= n:", "+ return -1", "+ while i < n and t == A[i]:", "+ if i not in already:", "+ already.add(i)", "+ key[t] = i", "+ return i", "+ i += 1", "+ return -1", "-D = to_dic(A)", "-A2 = list(D.keys())", "-A2.sort()", "-for n in range(len(A2) - 1, -1, -1):", "- a = A2[n]", "- if a in T:", "- res += D[a] // 2", "- D[a] = 0", "- if D[a] % 2 == 0:", "- continue", "- num = D[a]", "+for n in range(len(A) - 1, -1, -1):", "+ if n in already:", "+ continue", "+ a = A[n]", "- s = is_in(t - a, num)", "- res += s", "- num -= s", "- if num == 0:", "+ i = is_in(t - a, n)", "+ if i != -1:", "+ res += 1", "+print(\"\")" ]
false
0.057913
0.129799
0.446175
[ "s242172016", "s060697361" ]
u628070051
p03852
python
s659859193
s634129102
27
23
9,020
8,900
Accepted
Accepted
14.81
c = str.lower(eval(input())) n = ('a', 'e', 'i', 'o', 'u') if c in n: print('vowel') else: print('consonant')
c = str.lower(eval(input())) def answer(c: str) -> str: n = ('a', 'e', 'i', 'o', 'u') if c in n: return 'vowel' else: return 'consonant' print((answer(c)))
7
11
119
189
c = str.lower(eval(input())) n = ("a", "e", "i", "o", "u") if c in n: print("vowel") else: print("consonant")
c = str.lower(eval(input())) def answer(c: str) -> str: n = ("a", "e", "i", "o", "u") if c in n: return "vowel" else: return "consonant" print((answer(c)))
false
36.363636
[ "-n = (\"a\", \"e\", \"i\", \"o\", \"u\")", "-if c in n:", "- print(\"vowel\")", "-else:", "- print(\"consonant\")", "+", "+", "+def answer(c: str) -> str:", "+ n = (\"a\", \"e\", \"i\", \"o\", \"u\")", "+ if c in n:", "+ return \"vowel\"", "+ else:", "+ return \"consonant\"", "+", "+", "+print((answer(c)))" ]
false
0.100084
0.036817
2.718394
[ "s659859193", "s634129102" ]
u512212329
p02579
python
s520921855
s584459644
541
477
193,384
189,704
Accepted
Accepted
11.83
# 01-BFS # 参考: White_Pie_46 # https://atcoder.jp/contests/abc176/submissions/16168825 # 01-BFSのちょっと丁寧な解説 - ARMERIA # https://betrue12.hateblo.jp/entry/2018/12/08/000020 from collections import deque def main(): height, width = [int(x) for x in input().split()] init_h, init_w = [int(x) - 1 for x in input().split()] dest_h, dest_w = [int(x) - 1 for x in input().split()] grid = [list(eval(input())) for _ in range(height)] can_walk = ((1, 0), (0, 1), (-1, 0), (0, -1)) gen_warp_can_reach = ( (h, w, (h, w) in can_walk) # 移動先,徒歩で行けるか for h in range(-2, 3) for w in range(-2, 3) if not h == 0 == w) warp_can_reach = set(gen_warp_can_reach) qu = deque() qu.append((init_h, init_w, 0)) # 座標とワープ回数を保持 while qu: h, w, warps = qu.popleft() if h == dest_h and w == dest_w: return warps if grid[h][w] == 'R': # 同じマスを複数回キューに追加しているかもしれない。 continue grid[h][w] = 'R' # reached for h_delta, w_delta, walking in warp_can_reach: new_h, new_w = h + h_delta, w + w_delta if 0 <= new_h < height and 0 <= new_w < width: if grid[new_h][new_w] == '.': if walking: qu.appendleft((new_h, new_w, warps)) else: qu.append((new_h, new_w, warps + 1)) return -1 if __name__ == '__main__': print((main()))
# 01-BFS # 参考: White_Pie_46 # https://atcoder.jp/contests/abc176/submissions/16168825 # 01-BFSのちょっと丁寧な解説 - ARMERIA # https://betrue12.hateblo.jp/entry/2018/12/08/000020 from collections import deque def main(): height, width = [int(x) for x in input().split()] init_h, init_w = [int(x) - 1 for x in input().split()] dest_h, dest_w = [int(x) - 1 for x in input().split()] grid = [list(eval(input())) for _ in range(height)] can_walk = ((1, 0), (0, 1), (-1, 0), (0, -1)) gen_warp_can_reach = ( (h, w, (h, w) in can_walk) # 移動先,徒歩で行けるか for h in range(-2, 3) for w in range(-2, 3) if not h == 0 == w) warp_can_reach = tuple(gen_warp_can_reach) qu = deque() qu.append((init_h, init_w, 0)) # 座標とワープ回数を保持 while qu: h, w, warps = qu.popleft() if h == dest_h and w == dest_w: return warps if grid[h][w] == 'R': # 同じマスを複数回キューに追加しているかもしれない。 continue grid[h][w] = 'R' # reached for h_delta, w_delta, walking in warp_can_reach: new_h, new_w = h + h_delta, w + w_delta if 0 <= new_h < height and 0 <= new_w < width: if grid[new_h][new_w] == '.': if walking: qu.appendleft((new_h, new_w, warps)) else: qu.append((new_h, new_w, warps + 1)) return -1 if __name__ == '__main__': print((main()))
45
45
1,490
1,492
# 01-BFS # 参考: White_Pie_46 # https://atcoder.jp/contests/abc176/submissions/16168825 # 01-BFSのちょっと丁寧な解説 - ARMERIA # https://betrue12.hateblo.jp/entry/2018/12/08/000020 from collections import deque def main(): height, width = [int(x) for x in input().split()] init_h, init_w = [int(x) - 1 for x in input().split()] dest_h, dest_w = [int(x) - 1 for x in input().split()] grid = [list(eval(input())) for _ in range(height)] can_walk = ((1, 0), (0, 1), (-1, 0), (0, -1)) gen_warp_can_reach = ( (h, w, (h, w) in can_walk) # 移動先,徒歩で行けるか for h in range(-2, 3) for w in range(-2, 3) if not h == 0 == w ) warp_can_reach = set(gen_warp_can_reach) qu = deque() qu.append((init_h, init_w, 0)) # 座標とワープ回数を保持 while qu: h, w, warps = qu.popleft() if h == dest_h and w == dest_w: return warps if grid[h][w] == "R": # 同じマスを複数回キューに追加しているかもしれない。 continue grid[h][w] = "R" # reached for h_delta, w_delta, walking in warp_can_reach: new_h, new_w = h + h_delta, w + w_delta if 0 <= new_h < height and 0 <= new_w < width: if grid[new_h][new_w] == ".": if walking: qu.appendleft((new_h, new_w, warps)) else: qu.append((new_h, new_w, warps + 1)) return -1 if __name__ == "__main__": print((main()))
# 01-BFS # 参考: White_Pie_46 # https://atcoder.jp/contests/abc176/submissions/16168825 # 01-BFSのちょっと丁寧な解説 - ARMERIA # https://betrue12.hateblo.jp/entry/2018/12/08/000020 from collections import deque def main(): height, width = [int(x) for x in input().split()] init_h, init_w = [int(x) - 1 for x in input().split()] dest_h, dest_w = [int(x) - 1 for x in input().split()] grid = [list(eval(input())) for _ in range(height)] can_walk = ((1, 0), (0, 1), (-1, 0), (0, -1)) gen_warp_can_reach = ( (h, w, (h, w) in can_walk) # 移動先,徒歩で行けるか for h in range(-2, 3) for w in range(-2, 3) if not h == 0 == w ) warp_can_reach = tuple(gen_warp_can_reach) qu = deque() qu.append((init_h, init_w, 0)) # 座標とワープ回数を保持 while qu: h, w, warps = qu.popleft() if h == dest_h and w == dest_w: return warps if grid[h][w] == "R": # 同じマスを複数回キューに追加しているかもしれない。 continue grid[h][w] = "R" # reached for h_delta, w_delta, walking in warp_can_reach: new_h, new_w = h + h_delta, w + w_delta if 0 <= new_h < height and 0 <= new_w < width: if grid[new_h][new_w] == ".": if walking: qu.appendleft((new_h, new_w, warps)) else: qu.append((new_h, new_w, warps + 1)) return -1 if __name__ == "__main__": print((main()))
false
0
[ "- warp_can_reach = set(gen_warp_can_reach)", "+ warp_can_reach = tuple(gen_warp_can_reach)" ]
false
0.084923
0.11195
0.758578
[ "s520921855", "s584459644" ]
u844789719
p03277
python
s729530754
s131406514
1,240
813
124,580
121,756
Accepted
Accepted
34.44
import itertools N = int(eval(input())) A = [int(_) for _ in input().split()] class SegmentTree(): """ Parameters ---------- array : list to construct segment tree from f : func binary operation of the monoid e : identity element of the monoid size : int limit for array size """ def __init__(self, array, f, e, size): self.f = f self.e = e self.size = size self.n = n = len(array) self.dat = [e] * n + array + [e] * (2 * size - 2 * n) self.build() def build(self): dat, n, f = self.dat, self.n, self.f for i in range(n - 1, 0, -1): dat[i] = f(dat[i << 1], dat[i << 1 | 1]) def modify(self, p, v): """ set value at position p (0-indexed) """ f, n, dat = self.f, self.n, self.dat p += n dat[p] = v while p > 1: dat[p >> 1] = f(dat[p], dat[p ^ 1]) p >>= 1 def query(self, l, r): """ result on interval [l, r) (0-indexed) """ f, e, n, dat = self.f, self.e, self.n, self.dat res = e l += n r += n while l < r: if l & 1: res = f(res, dat[l]) l += 1 if r & 1: r -= 1 res = f(res, dat[r]) l >>= 1 r >>= 1 return res e = 0 size = 2 * N + 2 f = lambda a, b: a + b offset = N def check(x): cumsum = list(itertools.accumulate([0] + [1 if a <= x else -1 for a in A])) # sum([l:r)) = cumsum[r] - cumsum[l] >= 0 # ⇔ cumsum[l] <= cumsum[r] ST = SegmentTree([e] * size, f=f, e=e, size=size) count = 0 for c in cumsum: c += offset count += ST.query(0, c + 1) ST.modify(c + 1, ST.query(c + 1, c + 2) + 1) return 2 * count > N * (N + 1) // 2 A_sorted = [0] + sorted(set(A)) + [10**10] lb = 0 rb = len(A_sorted) - 1 # check(x) == Trueとなる最小のx while rb - lb > 1: mid = (rb + lb) // 2 if check(A_sorted[mid]): rb = mid else: lb = mid print((A_sorted[rb]))
import itertools N = int(eval(input())) A = [int(_) for _ in input().split()] class BinaryIndexedTree: """ Parameters ---------- array : list to construct BIT from f : func binary operation of the abelian group fi : func inverse mapping of f i.e. f(a, b) == c <-> fi(c, a) == b e : identity element of the abelian group size : int limit for array size """ def __init__(self, array, f, fi, e, size): self.f = f self.fi = fi self.e = e self.size = size self.n = len(array) self.dat = [e] * (size + 1) self.array = [e] * size # self.build(array) def build(self, array_): for i, v in enumerate(array_): self.modify(i, v) def modify(self, p, v): """ set value at position p (0-indexed) """ self.add(p, self.fi(v, self.array[p])) def add(self, p, dv): """ add value at position p (0-indexed) """ fi, dat, f, size, array = self.fi, self.dat, self.f, self.size, self.array array[p] = f(array[p], dv) p += 1 while p <= size: dat[p] = f(dat[p], dv) p += p & -p def query(self, l, r): """ result on interval [l, r) (0-indexed) """ return self.fi(self._query(r), self._query(l)) def _query(self, p): dat, f, res = self.dat, self.f, self.e while p: res = f(res, dat[p]) p -= p & -p return res e = 0 size = 2 * N + 2 f = lambda a, b: a + b fi = lambda c, a: c - a offset = N def check(x): cumsum = list(itertools.accumulate([0] + [1 if a <= x else -1 for a in A])) # sum([l:r)) = cumsum[r] - cumsum[l] >= 0 # ⇔ cumsum[l] <= cumsum[r] BIT = BinaryIndexedTree([e] * size, f=f, fi=fi, e=e, size=size) count = 0 for c in cumsum: c += offset count += BIT._query(c + 1) BIT.add(c + 1, 1) return 2 * count > N * (N + 1) // 2 A_sorted = [0] + sorted(set(A)) + [10**10] lb = 0 rb = len(A_sorted) - 1 # check(x) == Trueとなる最小のx while rb - lb > 1: mid = (rb + lb) // 2 if check(A_sorted[mid]): rb = mid else: lb = mid print((A_sorted[rb]))
93
98
2,270
2,438
import itertools N = int(eval(input())) A = [int(_) for _ in input().split()] class SegmentTree: """ Parameters ---------- array : list to construct segment tree from f : func binary operation of the monoid e : identity element of the monoid size : int limit for array size """ def __init__(self, array, f, e, size): self.f = f self.e = e self.size = size self.n = n = len(array) self.dat = [e] * n + array + [e] * (2 * size - 2 * n) self.build() def build(self): dat, n, f = self.dat, self.n, self.f for i in range(n - 1, 0, -1): dat[i] = f(dat[i << 1], dat[i << 1 | 1]) def modify(self, p, v): """ set value at position p (0-indexed) """ f, n, dat = self.f, self.n, self.dat p += n dat[p] = v while p > 1: dat[p >> 1] = f(dat[p], dat[p ^ 1]) p >>= 1 def query(self, l, r): """ result on interval [l, r) (0-indexed) """ f, e, n, dat = self.f, self.e, self.n, self.dat res = e l += n r += n while l < r: if l & 1: res = f(res, dat[l]) l += 1 if r & 1: r -= 1 res = f(res, dat[r]) l >>= 1 r >>= 1 return res e = 0 size = 2 * N + 2 f = lambda a, b: a + b offset = N def check(x): cumsum = list(itertools.accumulate([0] + [1 if a <= x else -1 for a in A])) # sum([l:r)) = cumsum[r] - cumsum[l] >= 0 # ⇔ cumsum[l] <= cumsum[r] ST = SegmentTree([e] * size, f=f, e=e, size=size) count = 0 for c in cumsum: c += offset count += ST.query(0, c + 1) ST.modify(c + 1, ST.query(c + 1, c + 2) + 1) return 2 * count > N * (N + 1) // 2 A_sorted = [0] + sorted(set(A)) + [10**10] lb = 0 rb = len(A_sorted) - 1 # check(x) == Trueとなる最小のx while rb - lb > 1: mid = (rb + lb) // 2 if check(A_sorted[mid]): rb = mid else: lb = mid print((A_sorted[rb]))
import itertools N = int(eval(input())) A = [int(_) for _ in input().split()] class BinaryIndexedTree: """ Parameters ---------- array : list to construct BIT from f : func binary operation of the abelian group fi : func inverse mapping of f i.e. f(a, b) == c <-> fi(c, a) == b e : identity element of the abelian group size : int limit for array size """ def __init__(self, array, f, fi, e, size): self.f = f self.fi = fi self.e = e self.size = size self.n = len(array) self.dat = [e] * (size + 1) self.array = [e] * size # self.build(array) def build(self, array_): for i, v in enumerate(array_): self.modify(i, v) def modify(self, p, v): """ set value at position p (0-indexed) """ self.add(p, self.fi(v, self.array[p])) def add(self, p, dv): """ add value at position p (0-indexed) """ fi, dat, f, size, array = self.fi, self.dat, self.f, self.size, self.array array[p] = f(array[p], dv) p += 1 while p <= size: dat[p] = f(dat[p], dv) p += p & -p def query(self, l, r): """ result on interval [l, r) (0-indexed) """ return self.fi(self._query(r), self._query(l)) def _query(self, p): dat, f, res = self.dat, self.f, self.e while p: res = f(res, dat[p]) p -= p & -p return res e = 0 size = 2 * N + 2 f = lambda a, b: a + b fi = lambda c, a: c - a offset = N def check(x): cumsum = list(itertools.accumulate([0] + [1 if a <= x else -1 for a in A])) # sum([l:r)) = cumsum[r] - cumsum[l] >= 0 # ⇔ cumsum[l] <= cumsum[r] BIT = BinaryIndexedTree([e] * size, f=f, fi=fi, e=e, size=size) count = 0 for c in cumsum: c += offset count += BIT._query(c + 1) BIT.add(c + 1, 1) return 2 * count > N * (N + 1) // 2 A_sorted = [0] + sorted(set(A)) + [10**10] lb = 0 rb = len(A_sorted) - 1 # check(x) == Trueとなる最小のx while rb - lb > 1: mid = (rb + lb) // 2 if check(A_sorted[mid]): rb = mid else: lb = mid print((A_sorted[rb]))
false
5.102041
[ "-class SegmentTree:", "+class BinaryIndexedTree:", "- to construct segment tree from", "+ to construct BIT from", "- binary operation of the monoid", "+ binary operation of the abelian group", "+ fi : func", "+ inverse mapping of f", "+ i.e. f(a, b) == c <-> fi(c, a) == b", "- identity element of the monoid", "+ identity element of the abelian group", "- def __init__(self, array, f, e, size):", "+ def __init__(self, array, f, fi, e, size):", "+ self.fi = fi", "- self.n = n = len(array)", "- self.dat = [e] * n + array + [e] * (2 * size - 2 * n)", "- self.build()", "+ self.n = len(array)", "+ self.dat = [e] * (size + 1)", "+ self.array = [e] * size", "+ # self.build(array)", "- def build(self):", "- dat, n, f = self.dat, self.n, self.f", "- for i in range(n - 1, 0, -1):", "- dat[i] = f(dat[i << 1], dat[i << 1 | 1])", "+ def build(self, array_):", "+ for i, v in enumerate(array_):", "+ self.modify(i, v)", "- f, n, dat = self.f, self.n, self.dat", "- p += n", "- dat[p] = v", "- while p > 1:", "- dat[p >> 1] = f(dat[p], dat[p ^ 1])", "- p >>= 1", "+ self.add(p, self.fi(v, self.array[p]))", "+", "+ def add(self, p, dv):", "+ \"\"\"", "+ add value at position p (0-indexed)", "+ \"\"\"", "+ fi, dat, f, size, array = self.fi, self.dat, self.f, self.size, self.array", "+ array[p] = f(array[p], dv)", "+ p += 1", "+ while p <= size:", "+ dat[p] = f(dat[p], dv)", "+ p += p & -p", "- f, e, n, dat = self.f, self.e, self.n, self.dat", "- res = e", "- l += n", "- r += n", "- while l < r:", "- if l & 1:", "- res = f(res, dat[l])", "- l += 1", "- if r & 1:", "- r -= 1", "- res = f(res, dat[r])", "- l >>= 1", "- r >>= 1", "+ return self.fi(self._query(r), self._query(l))", "+", "+ def _query(self, p):", "+ dat, f, res = self.dat, self.f, self.e", "+ while p:", "+ res = f(res, dat[p])", "+ p -= p & -p", "+fi = lambda c, a: c - a", "- ST = SegmentTree([e] * size, f=f, e=e, size=size)", "+ BIT = BinaryIndexedTree([e] * size, f=f, fi=fi, e=e, size=size)", "- count += ST.query(0, c + 1)", "- ST.modify(c + 1, ST.query(c + 1, c + 2) + 1)", "+ count += BIT._query(c + 1)", "+ BIT.add(c + 1, 1)" ]
false
0.045417
0.125149
0.362903
[ "s729530754", "s131406514" ]
u956836108
p03835
python
s625111172
s865762426
1,340
1,043
9,124
9,140
Accepted
Accepted
22.16
# -*- coding: utf-8 -*- k, s = list(map(int, input().split())) ans = 0 if s == 3*k: ans = 1 elif s > 3*k: ans = 0 elif s == k: ans = int((k + 1) * (k + 2) / 2) else: l = k while l >= 0: t_sum = s - l m = s - t_sum if t_sum > 2*k: break if m < k: m = k while m >= 0: n = s - l - m if n > k: break if n >= 0: ans += 1 m -= 1 l -= 1 print(ans)
K, S = list(map(int, input().split())) ans = 0 for i in range(0,K+1): for j in range (0,K+1): if (S-K) <= (i + j) <= S: ans += 1 continue print(ans)
39
8
613
185
# -*- coding: utf-8 -*- k, s = list(map(int, input().split())) ans = 0 if s == 3 * k: ans = 1 elif s > 3 * k: ans = 0 elif s == k: ans = int((k + 1) * (k + 2) / 2) else: l = k while l >= 0: t_sum = s - l m = s - t_sum if t_sum > 2 * k: break if m < k: m = k while m >= 0: n = s - l - m if n > k: break if n >= 0: ans += 1 m -= 1 l -= 1 print(ans)
K, S = list(map(int, input().split())) ans = 0 for i in range(0, K + 1): for j in range(0, K + 1): if (S - K) <= (i + j) <= S: ans += 1 continue print(ans)
false
79.487179
[ "-# -*- coding: utf-8 -*-", "-k, s = list(map(int, input().split()))", "+K, S = list(map(int, input().split()))", "-if s == 3 * k:", "- ans = 1", "-elif s > 3 * k:", "- ans = 0", "-elif s == k:", "- ans = int((k + 1) * (k + 2) / 2)", "-else:", "- l = k", "- while l >= 0:", "- t_sum = s - l", "- m = s - t_sum", "- if t_sum > 2 * k:", "- break", "- if m < k:", "- m = k", "- while m >= 0:", "- n = s - l - m", "- if n > k:", "- break", "- if n >= 0:", "- ans += 1", "- m -= 1", "- l -= 1", "+for i in range(0, K + 1):", "+ for j in range(0, K + 1):", "+ if (S - K) <= (i + j) <= S:", "+ ans += 1", "+ continue" ]
false
0.077931
0.04096
1.902602
[ "s625111172", "s865762426" ]
u729133443
p02889
python
s581051320
s093925444
441
348
24,032
36,284
Accepted
Accepted
21.09
import sys from scipy.sparse.csgraph import floyd_warshall as f input=sys.stdin.buffer.readline def main(): n,m,l=list(map(int,input().split())) d=[[0]*(n+1)for _ in range(n+1)] for _ in range(m): a,b,c=list(map(int,input().split())) d[a][b]=c d=f(f(d,0)<=l)-1 d[d>n]=-1 a=[d[tuple(map(int,input().split()))]for _ in range(int(eval(input())))] print(('\n'.join(map(str,list(map(int,a)))))) main()
import sys from scipy.sparse.csgraph import floyd_warshall as f def main(): n,m,l,*t=list(map(int,sys.stdin.buffer.read().split())) d=[[0]*(n+1)for _ in range(n+1)] for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=c d=f(f(d,0)<=l)-1 d[d>n]=-1 print(('\n'.join(map(str,list(map(int,list(map(d.__getitem__,list(zip(*[iter(t[m*3+1:])]*2)))))))))) main()
14
10
405
341
import sys from scipy.sparse.csgraph import floyd_warshall as f input = sys.stdin.buffer.readline def main(): n, m, l = list(map(int, input().split())) d = [[0] * (n + 1) for _ in range(n + 1)] for _ in range(m): a, b, c = list(map(int, input().split())) d[a][b] = c d = f(f(d, 0) <= l) - 1 d[d > n] = -1 a = [d[tuple(map(int, input().split()))] for _ in range(int(eval(input())))] print(("\n".join(map(str, list(map(int, a)))))) main()
import sys from scipy.sparse.csgraph import floyd_warshall as f def main(): n, m, l, *t = list(map(int, sys.stdin.buffer.read().split())) d = [[0] * (n + 1) for _ in range(n + 1)] for a, b, c in zip(*[iter(t[: m * 3])] * 3): d[a][b] = c d = f(f(d, 0) <= l) - 1 d[d > n] = -1 print( ( "\n".join( map( str, list( map( int, list( map( d.__getitem__, list(zip(*[iter(t[m * 3 + 1 :])] * 2)), ) ), ) ), ) ) ) ) main()
false
28.571429
[ "-input = sys.stdin.buffer.readline", "-", "- n, m, l = list(map(int, input().split()))", "+ n, m, l, *t = list(map(int, sys.stdin.buffer.read().split()))", "- for _ in range(m):", "- a, b, c = list(map(int, input().split()))", "+ for a, b, c in zip(*[iter(t[: m * 3])] * 3):", "- a = [d[tuple(map(int, input().split()))] for _ in range(int(eval(input())))]", "- print((\"\\n\".join(map(str, list(map(int, a))))))", "+ print(", "+ (", "+ \"\\n\".join(", "+ map(", "+ str,", "+ list(", "+ map(", "+ int,", "+ list(", "+ map(", "+ d.__getitem__,", "+ list(zip(*[iter(t[m * 3 + 1 :])] * 2)),", "+ )", "+ ),", "+ )", "+ ),", "+ )", "+ )", "+ )", "+ )" ]
false
0.347052
0.695537
0.498969
[ "s581051320", "s093925444" ]
u865383026
p02571
python
s823924965
s302408701
49
44
9,060
9,136
Accepted
Accepted
10.2
S = eval(input()) T = list(eval(input())) l = len(S) - len(T) + 1 ans = len(T) t = len(T) for i in range(l): s = list(S[i:i+t]) ans = min(ans, len([0 for i in range(t) if T[i] != s[i]])) print(ans)
S = eval(input()) T = eval(input()) l = len(S) - len(T) + 1 ans = len(T) t = len(T) for i in range(l): s = S[i:i+t] ans = min(ans, len([0 for i in range(t) if T[i] != s[i]])) print(ans)
9
9
197
185
S = eval(input()) T = list(eval(input())) l = len(S) - len(T) + 1 ans = len(T) t = len(T) for i in range(l): s = list(S[i : i + t]) ans = min(ans, len([0 for i in range(t) if T[i] != s[i]])) print(ans)
S = eval(input()) T = eval(input()) l = len(S) - len(T) + 1 ans = len(T) t = len(T) for i in range(l): s = S[i : i + t] ans = min(ans, len([0 for i in range(t) if T[i] != s[i]])) print(ans)
false
0
[ "-T = list(eval(input()))", "+T = eval(input())", "- s = list(S[i : i + t])", "+ s = S[i : i + t]" ]
false
0.085666
0.087994
0.973541
[ "s823924965", "s302408701" ]
u518042385
p02918
python
s072227320
s898113128
72
56
4,084
4,084
Accepted
Accepted
22.22
n,k=list(map(int,input().split())) l=list(eval(input())) s=l[0] m=0 c=1 for i in range(1,n): if l[i]!=s: c+=1 s=l[i] if c//2<=k: print((n-1)) else: for i in range(1,n-1): if l[i]=="R": if l[i+1]=="R": m+=1 if l[i]=="L": if l[i-1]=="L": m+=1 if l[0]=="R" and l[0]==l[1]: m+=1 if l[-1]=="L" and l[-2]==l[-1]: m+=1 print((m+k*2))
n,k=list(map(int,input().split())) l=list(eval(input())) m=0 if n==1: print((0)) else: for i in range(1,n-1): if l[i]=="R": if l[i+1]=="R": m+=1 if l[i]=="L": if l[i-1]=="L": m+=1 if l[0]=="R" and l[0]==l[1]: m+=1 if l[-1]=="L" and l[-2]==l[-1]: m+=1 print((min(m+k*2,n-1)))
24
18
397
329
n, k = list(map(int, input().split())) l = list(eval(input())) s = l[0] m = 0 c = 1 for i in range(1, n): if l[i] != s: c += 1 s = l[i] if c // 2 <= k: print((n - 1)) else: for i in range(1, n - 1): if l[i] == "R": if l[i + 1] == "R": m += 1 if l[i] == "L": if l[i - 1] == "L": m += 1 if l[0] == "R" and l[0] == l[1]: m += 1 if l[-1] == "L" and l[-2] == l[-1]: m += 1 print((m + k * 2))
n, k = list(map(int, input().split())) l = list(eval(input())) m = 0 if n == 1: print((0)) else: for i in range(1, n - 1): if l[i] == "R": if l[i + 1] == "R": m += 1 if l[i] == "L": if l[i - 1] == "L": m += 1 if l[0] == "R" and l[0] == l[1]: m += 1 if l[-1] == "L" and l[-2] == l[-1]: m += 1 print((min(m + k * 2, n - 1)))
false
25
[ "-s = l[0]", "-c = 1", "-for i in range(1, n):", "- if l[i] != s:", "- c += 1", "- s = l[i]", "-if c // 2 <= k:", "- print((n - 1))", "+if n == 1:", "+ print((0))", "- print((m + k * 2))", "+ print((min(m + k * 2, n - 1)))" ]
false
0.04772
0.048227
0.989483
[ "s072227320", "s898113128" ]
u670180528
p03660
python
s517147760
s528411597
450
334
37,232
37,228
Accepted
Accepted
25.78
from collections import deque n,*L=list(map(int,open(0).read().split())) G=[[]for _ in range(n)] db=[-1]*n;db[0]=0 dw=[-1]*n;dw[-1]=0 for a,b in zip(*[iter(L)]*2): G[a-1]+=[b-1] G[b-1]+=[a-1] q=deque([0]) while q: cur=q.popleft() for nxt in G[cur]: if db[nxt]<0: q.append(nxt) db[nxt]=db[cur]+1 q=deque([n-1]) while q: cur=q.popleft() for nxt in G[cur]: if dw[nxt]<0: q.append(nxt) dw[nxt]=dw[cur]+1 b=w=0 for i,j in zip(db,dw): if i<=j:b+=1 else:w+=1 if b<=w:print("Snuke") else:print("Fennec")
from collections import* n,*L=list(map(int,open(0).read().split())) G=[[]for _ in range(n)] for a,b in zip(*[iter(L)]*2): G[a-1]+=[b-1] G[b-1]+=[a-1] def F(m): q=deque([m]) d=[-1]*n while q: cur=q.popleft() for nxt in G[cur]: if d[nxt]<0: q.append(nxt) d[nxt]=d[cur]+1 return d print(("FSennunkeec"[sum(i>j or-1 for i,j in zip(F(0),F(n-1)))>=0::2]))
28
17
540
378
from collections import deque n, *L = list(map(int, open(0).read().split())) G = [[] for _ in range(n)] db = [-1] * n db[0] = 0 dw = [-1] * n dw[-1] = 0 for a, b in zip(*[iter(L)] * 2): G[a - 1] += [b - 1] G[b - 1] += [a - 1] q = deque([0]) while q: cur = q.popleft() for nxt in G[cur]: if db[nxt] < 0: q.append(nxt) db[nxt] = db[cur] + 1 q = deque([n - 1]) while q: cur = q.popleft() for nxt in G[cur]: if dw[nxt] < 0: q.append(nxt) dw[nxt] = dw[cur] + 1 b = w = 0 for i, j in zip(db, dw): if i <= j: b += 1 else: w += 1 if b <= w: print("Snuke") else: print("Fennec")
from collections import * n, *L = list(map(int, open(0).read().split())) G = [[] for _ in range(n)] for a, b in zip(*[iter(L)] * 2): G[a - 1] += [b - 1] G[b - 1] += [a - 1] def F(m): q = deque([m]) d = [-1] * n while q: cur = q.popleft() for nxt in G[cur]: if d[nxt] < 0: q.append(nxt) d[nxt] = d[cur] + 1 return d print(("FSennunkeec"[sum(i > j or -1 for i, j in zip(F(0), F(n - 1))) >= 0 :: 2]))
false
39.285714
[ "-from collections import deque", "+from collections import *", "-db = [-1] * n", "-db[0] = 0", "-dw = [-1] * n", "-dw[-1] = 0", "-q = deque([0])", "-while q:", "- cur = q.popleft()", "- for nxt in G[cur]:", "- if db[nxt] < 0:", "- q.append(nxt)", "- db[nxt] = db[cur] + 1", "-q = deque([n - 1])", "-while q:", "- cur = q.popleft()", "- for nxt in G[cur]:", "- if dw[nxt] < 0:", "- q.append(nxt)", "- dw[nxt] = dw[cur] + 1", "-b = w = 0", "-for i, j in zip(db, dw):", "- if i <= j:", "- b += 1", "- else:", "- w += 1", "-if b <= w:", "- print(\"Snuke\")", "-else:", "- print(\"Fennec\")", "+", "+", "+def F(m):", "+ q = deque([m])", "+ d = [-1] * n", "+ while q:", "+ cur = q.popleft()", "+ for nxt in G[cur]:", "+ if d[nxt] < 0:", "+ q.append(nxt)", "+ d[nxt] = d[cur] + 1", "+ return d", "+", "+", "+print((\"FSennunkeec\"[sum(i > j or -1 for i, j in zip(F(0), F(n - 1))) >= 0 :: 2]))" ]
false
0.03795
0.037349
1.016105
[ "s517147760", "s528411597" ]
u312025627
p03854
python
s962281228
s397794152
163
19
39,920
3,188
Accepted
Accepted
88.34
def main(): S = input() if S.replace("eraser", "").replace("erase", "")\ .replace("dreamer", "").replace("dream", "") == "": print("YES") else: print("NO") if __name__ == '__main__': main()
def main(): S = input() if S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", ""): return print("NO") else: return print("YES") if __name__ == '__main__': main()
11
10
246
239
def main(): S = input() if ( S.replace("eraser", "") .replace("erase", "") .replace("dreamer", "") .replace("dream", "") == "" ): print("YES") else: print("NO") if __name__ == "__main__": main()
def main(): S = input() if ( S.replace("eraser", "") .replace("erase", "") .replace("dreamer", "") .replace("dream", "") ): return print("NO") else: return print("YES") if __name__ == "__main__": main()
false
9.090909
[ "- == \"\"", "- print(\"YES\")", "+ return print(\"NO\")", "- print(\"NO\")", "+ return print(\"YES\")" ]
false
0.037776
0.046682
0.809205
[ "s962281228", "s397794152" ]
u500376440
p03545
python
s497149946
s976974010
33
28
9,008
9,048
Accepted
Accepted
15.15
num_=eval(input()) op_=len(num_)-1 for i in range(2**op_): op=["-"]*op_ for j in range(op_): if ((i>>j)&1): op[op_-1-j]="+" formula="" op.append("") for p_num,p_op in zip(num_,op): formula+=p_num+p_op if eval(formula)==7: print((formula+"=7")) break
ABCD=eval(input()) f="" for bit in range(1<<3): f=ABCD[0] for i in range(3): if bit&(1<<i): f+="+" else: f+="-" f+=ABCD[i+1] if eval(f)==7: print((f+"=7")) exit()
14
13
289
205
num_ = eval(input()) op_ = len(num_) - 1 for i in range(2**op_): op = ["-"] * op_ for j in range(op_): if (i >> j) & 1: op[op_ - 1 - j] = "+" formula = "" op.append("") for p_num, p_op in zip(num_, op): formula += p_num + p_op if eval(formula) == 7: print((formula + "=7")) break
ABCD = eval(input()) f = "" for bit in range(1 << 3): f = ABCD[0] for i in range(3): if bit & (1 << i): f += "+" else: f += "-" f += ABCD[i + 1] if eval(f) == 7: print((f + "=7")) exit()
false
7.142857
[ "-num_ = eval(input())", "-op_ = len(num_) - 1", "-for i in range(2**op_):", "- op = [\"-\"] * op_", "- for j in range(op_):", "- if (i >> j) & 1:", "- op[op_ - 1 - j] = \"+\"", "- formula = \"\"", "- op.append(\"\")", "- for p_num, p_op in zip(num_, op):", "- formula += p_num + p_op", "- if eval(formula) == 7:", "- print((formula + \"=7\"))", "- break", "+ABCD = eval(input())", "+f = \"\"", "+for bit in range(1 << 3):", "+ f = ABCD[0]", "+ for i in range(3):", "+ if bit & (1 << i):", "+ f += \"+\"", "+ else:", "+ f += \"-\"", "+ f += ABCD[i + 1]", "+ if eval(f) == 7:", "+ print((f + \"=7\"))", "+ exit()" ]
false
0.169489
0.039907
4.247063
[ "s497149946", "s976974010" ]
u343251190
p02255
python
s384131886
s064694246
30
20
8,200
8,096
Accepted
Accepted
33.33
n = int(eval(input())) data = list(map(int, input().split())) def insertion_sort(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)) insertion_sort(data, n)
n = int(eval(input())) data = list(map(int, input().split())) def insertionsort(a, n): for i in range(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)) insertionsort(data, n)
15
14
313
296
n = int(eval(input())) data = list(map(int, input().split())) def insertion_sort(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)) insertion_sort(data, n)
n = int(eval(input())) data = list(map(int, input().split())) def insertionsort(a, n): for i in range(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)) insertionsort(data, n)
false
6.666667
[ "-def insertion_sort(A, N):", "- print((*A))", "- for i in range(1, N):", "- v = A[i]", "+def insertionsort(a, n):", "+ for i in range(n):", "+ v = a[i]", "- while j >= 0 and A[j] > v:", "- A[j + 1] = A[j]", "+ while j >= 0 and a[j] > v:", "+ a[j + 1] = a[j]", "- A[j + 1] = v", "- print((*A))", "+ a[j + 1] = v", "+ print((*a))", "-insertion_sort(data, n)", "+insertionsort(data, n)" ]
false
0.045045
0.052234
0.862371
[ "s384131886", "s064694246" ]
u119148115
p03609
python
s738377740
s564709662
168
73
61,456
61,908
Accepted
Accepted
56.55
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()) #空白なし X,t = MI() print((max(0,X-t)))
import sys def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) X,t = MI() print((max(0,X-t)))
13
5
520
109
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()) # 空白なし X, t = MI() print((max(0, X - t)))
import sys def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) X, t = MI() print((max(0, X - t)))
false
61.538462
[ "-", "-sys.setrecursionlimit(10**7)", "-", "-", "-def I():", "- return int(sys.stdin.readline().rstrip())", "-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.153408
0.071495
2.145708
[ "s738377740", "s564709662" ]
u852690916
p03862
python
s569997993
s536676175
161
95
14,052
84,232
Accepted
Accepted
40.99
N,x=list(map(int,input().split())) A=list(map(int,input().split())) ans=0 pre=0 for i in range(N-1): s=A[i]+A[i+1]-pre ans+=max(0,s-x) pre=min(max(0,s-x),A[i+1]) print(ans)
N, x = list(map(int, input().split())) *A, = list(map(int, input().split())) ans = 0 for i in range(N - 1): w = A[i] + A[i + 1] if w <= x: continue r = max(0, A[i + 1] - (w - x)) l = x - r ans += A[i] - l + A[i + 1] - r A[i + 1] = r print(ans)
9
11
186
266
N, x = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 pre = 0 for i in range(N - 1): s = A[i] + A[i + 1] - pre ans += max(0, s - x) pre = min(max(0, s - x), A[i + 1]) print(ans)
N, x = list(map(int, input().split())) (*A,) = list(map(int, input().split())) ans = 0 for i in range(N - 1): w = A[i] + A[i + 1] if w <= x: continue r = max(0, A[i + 1] - (w - x)) l = x - r ans += A[i] - l + A[i + 1] - r A[i + 1] = r print(ans)
false
18.181818
[ "-A = list(map(int, input().split()))", "+(*A,) = list(map(int, input().split()))", "-pre = 0", "- s = A[i] + A[i + 1] - pre", "- ans += max(0, s - x)", "- pre = min(max(0, s - x), A[i + 1])", "+ w = A[i] + A[i + 1]", "+ if w <= x:", "+ continue", "+ r = max(0, A[i + 1] - (w - x))", "+ l = x - r", "+ ans += A[i] - l + A[i + 1] - r", "+ A[i + 1] = r" ]
false
0.036119
0.036064
1.001523
[ "s569997993", "s536676175" ]
u670180528
p03457
python
s279032116
s049243610
125
100
26,760
26,632
Accepted
Accepted
20
n,*l=list(map(int,open(0).read().split()));print(("YNeos"[any((i+j+k)%2+(i<j+k)for i,j,k in zip(*[iter([abs(i-j)for i,j in zip([0,0,0]+l,l)])]*3))::2]))
_,*l=list(map(int,open(0).read().split()));print(("YNeos"[any((t+x+y)%2+(t<x+y)for t,x,y in zip(*[iter(l)]*3))::2]))
1
1
144
108
n, *l = list(map(int, open(0).read().split())) print( ( "YNeos"[ any( (i + j + k) % 2 + (i < j + k) for i, j, k in zip( *[iter([abs(i - j) for i, j in zip([0, 0, 0] + l, l)])] * 3 ) ) :: 2 ] ) )
_, *l = list(map(int, open(0).read().split())) print( ( "YNeos"[ any((t + x + y) % 2 + (t < x + y) for t, x, y in zip(*[iter(l)] * 3)) :: 2 ] ) )
false
0
[ "-n, *l = list(map(int, open(0).read().split()))", "+_, *l = list(map(int, open(0).read().split()))", "- any(", "- (i + j + k) % 2 + (i < j + k)", "- for i, j, k in zip(", "- *[iter([abs(i - j) for i, j in zip([0, 0, 0] + l, l)])] * 3", "- )", "- ) :: 2", "+ any((t + x + y) % 2 + (t < x + y) for t, x, y in zip(*[iter(l)] * 3)) :: 2" ]
false
0.037746
0.037671
1.001991
[ "s279032116", "s049243610" ]
u935558307
p03221
python
s552605160
s775133760
490
400
96,244
129,700
Accepted
Accepted
18.37
N,M = list(map(int,input().split())) digit = 'zero padding: {:0=6}' dic = [[] for _ in range(N+1)] for i in range(M): p,y = list(map(int,input().split())) dic[p].append((y,i)) for p in dic: p.sort() ans = [None for _ in range(M)] for k in range(1,N+1): p = dic[k] for j in range(len(p)): i = p[j][1] ID = str(k).zfill(6)+str(j+1).zfill(6) ans[i] = ID for a in ans: print(a)
N,M = list(map(int,input().split())) PY = [list(map(int,input().split())) for _ in range(M)] dic = [[] for _ in range(N+1)] for p,y in PY: dic[p].append(y) for a in dic: a.sort() dic2 = [{} for _ in range(N+1)] for p in range(N+1): dic2[p] = {y:i+1 for i,y in enumerate(dic[p])} for p,y in PY: y = dic2[p][y] print((str(p).zfill(6)+str(y).zfill(6)))
21
17
434
382
N, M = list(map(int, input().split())) digit = "zero padding: {:0=6}" dic = [[] for _ in range(N + 1)] for i in range(M): p, y = list(map(int, input().split())) dic[p].append((y, i)) for p in dic: p.sort() ans = [None for _ in range(M)] for k in range(1, N + 1): p = dic[k] for j in range(len(p)): i = p[j][1] ID = str(k).zfill(6) + str(j + 1).zfill(6) ans[i] = ID for a in ans: print(a)
N, M = list(map(int, input().split())) PY = [list(map(int, input().split())) for _ in range(M)] dic = [[] for _ in range(N + 1)] for p, y in PY: dic[p].append(y) for a in dic: a.sort() dic2 = [{} for _ in range(N + 1)] for p in range(N + 1): dic2[p] = {y: i + 1 for i, y in enumerate(dic[p])} for p, y in PY: y = dic2[p][y] print((str(p).zfill(6) + str(y).zfill(6)))
false
19.047619
[ "-digit = \"zero padding: {:0=6}\"", "+PY = [list(map(int, input().split())) for _ in range(M)]", "-for i in range(M):", "- p, y = list(map(int, input().split()))", "- dic[p].append((y, i))", "-for p in dic:", "- p.sort()", "-ans = [None for _ in range(M)]", "-for k in range(1, N + 1):", "- p = dic[k]", "- for j in range(len(p)):", "- i = p[j][1]", "- ID = str(k).zfill(6) + str(j + 1).zfill(6)", "- ans[i] = ID", "-for a in ans:", "- print(a)", "+for p, y in PY:", "+ dic[p].append(y)", "+for a in dic:", "+ a.sort()", "+dic2 = [{} for _ in range(N + 1)]", "+for p in range(N + 1):", "+ dic2[p] = {y: i + 1 for i, y in enumerate(dic[p])}", "+for p, y in PY:", "+ y = dic2[p][y]", "+ print((str(p).zfill(6) + str(y).zfill(6)))" ]
false
0.109641
0.075862
1.445274
[ "s552605160", "s775133760" ]
u633068244
p00176
python
s915435732
s566361339
40
20
4,328
4,340
Accepted
Accepted
50
clr=["black","blue","lime","aqua","red","fuchsia","yellow","white"] hex=["000000","0000ff","00ff00","00ffff","ff0000","ff00ff","ffff00","ffffff"] def L(s1,s2): return ((int(s1[:2],16)-int(s2[:2],16))**2+(int(s1[2:4],16)-int(s2[2:4],16))**2+(int(s1[4:],16)-int(s2[4:],16))**2)**0.5 def nn(s): mn=mni=99999 for i in range(8): if mn>L(hex[i],s): mn=L(hex[i],s);mni=i return mni while 1: rgb=input() if rgb=="0":break print(clr[nn(rgb[1:])])
ff=255 clr=["black","blue","lime","aqua","red","fuchsia","yellow","white"] val=[[0,0,0],[0,0,ff],[0,ff,0],[0,ff,ff],[ff,0,0],[ff,0,ff],[ff,ff,0],[ff,ff,ff]] def L(s1,s2): return ((s1[0]-s2[0])**2+(s1[1]-s2[1])**2+(s1[2]-s2[2])**2)**0.5 while 1: rgb=input() if rgb=="0":break rgb=[int(rgb[1:3],16),int(rgb[3:5],16),int(rgb[5:],16)] print(clr[min([[L(rgb,val[i]),i] for i in range(8)])[1]])
16
12
469
410
clr = ["black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"] hex = ["000000", "0000ff", "00ff00", "00ffff", "ff0000", "ff00ff", "ffff00", "ffffff"] def L(s1, s2): return ( (int(s1[:2], 16) - int(s2[:2], 16)) ** 2 + (int(s1[2:4], 16) - int(s2[2:4], 16)) ** 2 + (int(s1[4:], 16) - int(s2[4:], 16)) ** 2 ) ** 0.5 def nn(s): mn = mni = 99999 for i in range(8): if mn > L(hex[i], s): mn = L(hex[i], s) mni = i return mni while 1: rgb = input() if rgb == "0": break print(clr[nn(rgb[1:])])
ff = 255 clr = ["black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"] val = [ [0, 0, 0], [0, 0, ff], [0, ff, 0], [0, ff, ff], [ff, 0, 0], [ff, 0, ff], [ff, ff, 0], [ff, ff, ff], ] def L(s1, s2): return ((s1[0] - s2[0]) ** 2 + (s1[1] - s2[1]) ** 2 + (s1[2] - s2[2]) ** 2) ** 0.5 while 1: rgb = input() if rgb == "0": break rgb = [int(rgb[1:3], 16), int(rgb[3:5], 16), int(rgb[5:], 16)] print(clr[min([[L(rgb, val[i]), i] for i in range(8)])[1]])
false
25
[ "+ff = 255", "-hex = [\"000000\", \"0000ff\", \"00ff00\", \"00ffff\", \"ff0000\", \"ff00ff\", \"ffff00\", \"ffffff\"]", "+val = [", "+ [0, 0, 0],", "+ [0, 0, ff],", "+ [0, ff, 0],", "+ [0, ff, ff],", "+ [ff, 0, 0],", "+ [ff, 0, ff],", "+ [ff, ff, 0],", "+ [ff, ff, ff],", "+]", "- return (", "- (int(s1[:2], 16) - int(s2[:2], 16)) ** 2", "- + (int(s1[2:4], 16) - int(s2[2:4], 16)) ** 2", "- + (int(s1[4:], 16) - int(s2[4:], 16)) ** 2", "- ) ** 0.5", "-", "-", "-def nn(s):", "- mn = mni = 99999", "- for i in range(8):", "- if mn > L(hex[i], s):", "- mn = L(hex[i], s)", "- mni = i", "- return mni", "+ return ((s1[0] - s2[0]) ** 2 + (s1[1] - s2[1]) ** 2 + (s1[2] - s2[2]) ** 2) ** 0.5", "- print(clr[nn(rgb[1:])])", "+ rgb = [int(rgb[1:3], 16), int(rgb[3:5], 16), int(rgb[5:], 16)]", "+ print(clr[min([[L(rgb, val[i]), i] for i in range(8)])[1]])" ]
false
0.048323
0.107402
0.449929
[ "s915435732", "s566361339" ]
u375616706
p03166
python
s074960554
s503520452
1,305
1,018
242,472
125,028
Accepted
Accepted
21.99
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N, M = list(map(int, input().split())) edges = [set() for _ in range(N)] ins = [0]*N for _ in range(M): a, b = [int(x)-1 for x in input().split()] ins[b] += 1 edges[a].add(b) dp = [-1]*N start = [] for i in range(N): if ins[i] == 0: start.append(i) def dfs(s): if dp[s] != -1: return dp[s] mx = 0 if edges[s]: mx = max([dfs(dest)+1 for dest in edges[s]]) dp[s] = mx return mx ans = -1 for i in range(N): if ins[i] == 0: ans = max(ans, dfs(i)) print(ans)
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N, M = list(map(int, input().split())) edges = [set() for _ in range(N)] ins = [0]*N for _ in range(M): a, b = [int(x)-1 for x in input().split()] ins[b] += 1 edges[a].add(b) dp = [-1]*N def dfs(s): if dp[s] != -1: return dp[s] mx = 0 if edges[s]: mx = max([dfs(dest)+1 for dest in edges[s]]) dp[s] = mx return mx ans = -1 for i in range(N): ans = max(ans, dfs(i)) print(ans)
37
31
667
562
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N, M = list(map(int, input().split())) edges = [set() for _ in range(N)] ins = [0] * N for _ in range(M): a, b = [int(x) - 1 for x in input().split()] ins[b] += 1 edges[a].add(b) dp = [-1] * N start = [] for i in range(N): if ins[i] == 0: start.append(i) def dfs(s): if dp[s] != -1: return dp[s] mx = 0 if edges[s]: mx = max([dfs(dest) + 1 for dest in edges[s]]) dp[s] = mx return mx ans = -1 for i in range(N): if ins[i] == 0: ans = max(ans, dfs(i)) print(ans)
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N, M = list(map(int, input().split())) edges = [set() for _ in range(N)] ins = [0] * N for _ in range(M): a, b = [int(x) - 1 for x in input().split()] ins[b] += 1 edges[a].add(b) dp = [-1] * N def dfs(s): if dp[s] != -1: return dp[s] mx = 0 if edges[s]: mx = max([dfs(dest) + 1 for dest in edges[s]]) dp[s] = mx return mx ans = -1 for i in range(N): ans = max(ans, dfs(i)) print(ans)
false
16.216216
[ "-start = []", "-for i in range(N):", "- if ins[i] == 0:", "- start.append(i)", "- if ins[i] == 0:", "- ans = max(ans, dfs(i))", "+ ans = max(ans, dfs(i))" ]
false
0.044785
0.045091
0.993216
[ "s074960554", "s503520452" ]
u874320250
p02765
python
s341570404
s923000282
73
65
61,432
61,784
Accepted
Accepted
10.96
N, R = list(map(int, input().split())) print((R+max(0, 10-N)*100))
N, R = list(map(int, input().split())) if N >= 10: print(R) else: print((R+100*(10-N)))
2
6
60
94
N, R = list(map(int, input().split())) print((R + max(0, 10 - N) * 100))
N, R = list(map(int, input().split())) if N >= 10: print(R) else: print((R + 100 * (10 - N)))
false
66.666667
[ "-print((R + max(0, 10 - N) * 100))", "+if N >= 10:", "+ print(R)", "+else:", "+ print((R + 100 * (10 - N)))" ]
false
0.045013
0.034894
1.289999
[ "s341570404", "s923000282" ]
u992910889
p03606
python
s679280782
s212399189
199
175
38,768
38,256
Accepted
Accepted
12.06
# import bisect # import copy # import fractions # import math # import numpy as np # from collections import Counter, deque # from itertools import accumulate,permutations, combinations,combinations_with_replacement,product def resolve(): N=int(eval(input())) cnt=0 for i in range(N): l,r=list(map(int,input().split())) cnt+=r-l+1 print(cnt) resolve()
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): cnt=0 N=int(eval(input())) for i in range(N): l,r=list(map(int,input().split())) cnt+=r-l+1 print(cnt) resolve()
18
13
392
257
# import bisect # import copy # import fractions # import math # import numpy as np # from collections import Counter, deque # from itertools import accumulate,permutations, combinations,combinations_with_replacement,product def resolve(): N = int(eval(input())) cnt = 0 for i in range(N): l, r = list(map(int, input().split())) cnt += r - l + 1 print(cnt) resolve()
import sys sys.setrecursionlimit(10**5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): cnt = 0 N = int(eval(input())) for i in range(N): l, r = list(map(int, input().split())) cnt += r - l + 1 print(cnt) resolve()
false
27.777778
[ "-# import bisect", "-# import copy", "-# import fractions", "-# import math", "-# import numpy as np", "-# from collections import Counter, deque", "-# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product", "+import sys", "+", "+sys.setrecursionlimit(10**5 + 10)", "+", "+", "+def input():", "+ return sys.stdin.readline().strip()", "+", "+", "+ cnt = 0", "- cnt = 0" ]
false
0.043284
0.09913
0.436636
[ "s679280782", "s212399189" ]
u183509493
p02819
python
s388083155
s532168997
60
28
10,452
9,400
Accepted
Accepted
53.33
MAX=200000 def get_prime(x): is_prime = [True] * 200000 for i in range(2,MAX): if is_prime[i] and i >= x: return i elif is_prime[i]: for j in range(2 * i, MAX, i): is_prime[j] = False print((get_prime(int(eval(input())))))
# Original Submission At: https://atcoder.jp/contests/abc149/submissions/16823042 import sys sys.setrecursionlimit(1000000) x= int(eval(input())) def prime_check(num,count): if (num % count) != 0: if num <= count**2: print(num) else: prime_check(num,count+1) else : prime_check(num+1,2) if x==2 : print((2)) else: prime_check(x,2)
11
19
258
409
MAX = 200000 def get_prime(x): is_prime = [True] * 200000 for i in range(2, MAX): if is_prime[i] and i >= x: return i elif is_prime[i]: for j in range(2 * i, MAX, i): is_prime[j] = False print((get_prime(int(eval(input())))))
# Original Submission At: https://atcoder.jp/contests/abc149/submissions/16823042 import sys sys.setrecursionlimit(1000000) x = int(eval(input())) def prime_check(num, count): if (num % count) != 0: if num <= count**2: print(num) else: prime_check(num, count + 1) else: prime_check(num + 1, 2) if x == 2: print((2)) else: prime_check(x, 2)
false
42.105263
[ "-MAX = 200000", "+# Original Submission At: https://atcoder.jp/contests/abc149/submissions/16823042", "+import sys", "+", "+sys.setrecursionlimit(1000000)", "+x = int(eval(input()))", "-def get_prime(x):", "- is_prime = [True] * 200000", "- for i in range(2, MAX):", "- if is_prime[i] and i >= x:", "- return i", "- elif is_prime[i]:", "- for j in range(2 * i, MAX, i):", "- is_prime[j] = False", "+def prime_check(num, count):", "+ if (num % count) != 0:", "+ if num <= count**2:", "+ print(num)", "+ else:", "+ prime_check(num, count + 1)", "+ else:", "+ prime_check(num + 1, 2)", "-print((get_prime(int(eval(input())))))", "+if x == 2:", "+ print((2))", "+else:", "+ prime_check(x, 2)" ]
false
0.057095
0.040006
1.42716
[ "s388083155", "s532168997" ]
u644907318
p04011
python
s175664239
s700249847
177
140
38,384
61,200
Accepted
Accepted
20.9
N = int(eval(input())) K = int(eval(input())) X = int(eval(input())) Y = int(eval(input())) if N<=K: c = X*N else: c = X*K+Y*(N-K) print(c)
N = int(eval(input())) K = int(eval(input())) X = int(eval(input())) Y = int(eval(input())) if N<=K: ans = X*N else: ans = X*K ans += Y*(N-K) print(ans)
9
10
131
149
N = int(eval(input())) K = int(eval(input())) X = int(eval(input())) Y = int(eval(input())) if N <= K: c = X * N else: c = X * K + Y * (N - K) print(c)
N = int(eval(input())) K = int(eval(input())) X = int(eval(input())) Y = int(eval(input())) if N <= K: ans = X * N else: ans = X * K ans += Y * (N - K) print(ans)
false
10
[ "- c = X * N", "+ ans = X * N", "- c = X * K + Y * (N - K)", "-print(c)", "+ ans = X * K", "+ ans += Y * (N - K)", "+print(ans)" ]
false
0.034651
0.034145
1.01483
[ "s175664239", "s700249847" ]
u917140501
p03074
python
s204262334
s872616306
145
128
4,792
8,432
Accepted
Accepted
11.72
N,K= list(map(int, input().split())) S=[int(x) for x in list(str(eval(input())))] nums=list() ds={0:1,1:0} now=1 cnt=0 for i in S: if i==now: cnt=cnt+1 else: nums.append(cnt) now=ds[now] cnt=1 if cnt!=0: nums.append(cnt) if len(nums)%2==0: nums.append(0) Add=2*K+1 ans=0 left=0 right=0 tmp=0 for i in range(0,len(nums),2): nextleft=i nextright=min(i+Add,len(nums)) while nextleft>left: tmp=tmp-nums[left] left+=1 while nextright>right: tmp=tmp+nums[right] right+=1 ans=max(ans,tmp) print(ans)
N,K= list(map(int, input().split())) S=[int(x) for x in list(str(eval(input())))] nums=list() ds={0:1,1:0} now=1 cnt=0 for i in S: if i==now: cnt=cnt+1 else: nums.append(cnt) now=ds[now] cnt=1 if cnt!=0: nums.append(cnt) if len(nums)%2==0: nums.append(0) Add=2*K+1 ans=0 sum=[0]*(len(nums)+1) for i in range(len(nums)): sum[i+1]=sum[i]+nums[i] for i in range(0,len(nums),2): left=i right=min(i+Add,len(nums)) tmp=sum[right]-sum[left] ans=max(ans,tmp) print(ans)
42
37
643
567
N, K = list(map(int, input().split())) S = [int(x) for x in list(str(eval(input())))] nums = list() ds = {0: 1, 1: 0} now = 1 cnt = 0 for i in S: if i == now: cnt = cnt + 1 else: nums.append(cnt) now = ds[now] cnt = 1 if cnt != 0: nums.append(cnt) if len(nums) % 2 == 0: nums.append(0) Add = 2 * K + 1 ans = 0 left = 0 right = 0 tmp = 0 for i in range(0, len(nums), 2): nextleft = i nextright = min(i + Add, len(nums)) while nextleft > left: tmp = tmp - nums[left] left += 1 while nextright > right: tmp = tmp + nums[right] right += 1 ans = max(ans, tmp) print(ans)
N, K = list(map(int, input().split())) S = [int(x) for x in list(str(eval(input())))] nums = list() ds = {0: 1, 1: 0} now = 1 cnt = 0 for i in S: if i == now: cnt = cnt + 1 else: nums.append(cnt) now = ds[now] cnt = 1 if cnt != 0: nums.append(cnt) if len(nums) % 2 == 0: nums.append(0) Add = 2 * K + 1 ans = 0 sum = [0] * (len(nums) + 1) for i in range(len(nums)): sum[i + 1] = sum[i] + nums[i] for i in range(0, len(nums), 2): left = i right = min(i + Add, len(nums)) tmp = sum[right] - sum[left] ans = max(ans, tmp) print(ans)
false
11.904762
[ "-left = 0", "-right = 0", "-tmp = 0", "+sum = [0] * (len(nums) + 1)", "+for i in range(len(nums)):", "+ sum[i + 1] = sum[i] + nums[i]", "- nextleft = i", "- nextright = min(i + Add, len(nums))", "- while nextleft > left:", "- tmp = tmp - nums[left]", "- left += 1", "- while nextright > right:", "- tmp = tmp + nums[right]", "- right += 1", "+ left = i", "+ right = min(i + Add, len(nums))", "+ tmp = sum[right] - sum[left]" ]
false
0.04903
0.04886
1.003493
[ "s204262334", "s872616306" ]
u197300260
p03624
python
s656410985
s277390854
30
19
3,316
3,316
Accepted
Accepted
36.67
# _*_ coding:utf-8 _*_ # Atcoder_Beginners_Contest071-B # TODO https://atcoder.jp/contests/abc071/tasks/abc071_b def firstCharNotFound(givenString): # initialize for char checkList = [False for _ in range(0,26,+1)] stringLength = list(range(0,len(givenString),+1)) for pos in stringLength: charIntVersion = ord(givenString[pos]) checkList[charIntVersion-97]=True charRange = list(range(0,26,+1)) firstPosition = -1 for pos in charRange: if checkList[pos]==False: firstPosition = pos break if firstPosition == -1: return "None" else : return chr(firstPosition+97) if __name__ == '__main__': S = input().strip() solution=firstCharNotFound(S) print(("{}".format(solution)))
# Problem: # Python Try import sys # from collections import defaultdict # import heapq,copy # from collections import deque def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def initSet(): result = set() for j in range(ord('a'),ord('z')+1): result.add(chr(j)) return result def solver(inputString,allCharSet): result = '' inputSet = set(inputString) # print("INPUT={}".format(inputSet)) # print("ALL={}".format(allCharSet)) diffset = allCharSet - inputSet # print("DIFF={}".format(diffset)) difflist = list(diffset) difflist.sort() # print("{}".format(difflist)) if len(difflist) == 0: result = "None" else: result = difflist[0] return result if __name__ == "__main__": S = sys.stdin.readline().split('\n') allset = initSet() print(("{}".format(solver(S[0],allset))))
26
38
714
1,080
# _*_ coding:utf-8 _*_ # Atcoder_Beginners_Contest071-B # TODO https://atcoder.jp/contests/abc071/tasks/abc071_b def firstCharNotFound(givenString): # initialize for char checkList = [False for _ in range(0, 26, +1)] stringLength = list(range(0, len(givenString), +1)) for pos in stringLength: charIntVersion = ord(givenString[pos]) checkList[charIntVersion - 97] = True charRange = list(range(0, 26, +1)) firstPosition = -1 for pos in charRange: if checkList[pos] == False: firstPosition = pos break if firstPosition == -1: return "None" else: return chr(firstPosition + 97) if __name__ == "__main__": S = input().strip() solution = firstCharNotFound(S) print(("{}".format(solution)))
# Problem: # Python Try import sys # from collections import defaultdict # import heapq,copy # from collections import deque def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def initSet(): result = set() for j in range(ord("a"), ord("z") + 1): result.add(chr(j)) return result def solver(inputString, allCharSet): result = "" inputSet = set(inputString) # print("INPUT={}".format(inputSet)) # print("ALL={}".format(allCharSet)) diffset = allCharSet - inputSet # print("DIFF={}".format(diffset)) difflist = list(diffset) difflist.sort() # print("{}".format(difflist)) if len(difflist) == 0: result = "None" else: result = difflist[0] return result if __name__ == "__main__": S = sys.stdin.readline().split("\n") allset = initSet() print(("{}".format(solver(S[0], allset))))
false
31.578947
[ "-# _*_ coding:utf-8 _*_", "-# Atcoder_Beginners_Contest071-B", "-# TODO https://atcoder.jp/contests/abc071/tasks/abc071_b", "-def firstCharNotFound(givenString):", "- # initialize for char", "- checkList = [False for _ in range(0, 26, +1)]", "- stringLength = list(range(0, len(givenString), +1))", "- for pos in stringLength:", "- charIntVersion = ord(givenString[pos])", "- checkList[charIntVersion - 97] = True", "- charRange = list(range(0, 26, +1))", "- firstPosition = -1", "- for pos in charRange:", "- if checkList[pos] == False:", "- firstPosition = pos", "- break", "- if firstPosition == -1:", "- return \"None\"", "+# Problem:", "+# Python Try", "+import sys", "+", "+# from collections import defaultdict", "+# import heapq,copy", "+# from collections import deque", "+def II():", "+ return int(sys.stdin.readline())", "+", "+", "+def MI():", "+ return list(map(int, sys.stdin.readline().split()))", "+", "+", "+def LI():", "+ return list(map(int, sys.stdin.readline().split()))", "+", "+", "+def LLI(rows_number):", "+ return [LI() for _ in range(rows_number)]", "+", "+", "+def initSet():", "+ result = set()", "+ for j in range(ord(\"a\"), ord(\"z\") + 1):", "+ result.add(chr(j))", "+ return result", "+", "+", "+def solver(inputString, allCharSet):", "+ result = \"\"", "+ inputSet = set(inputString)", "+ # print(\"INPUT={}\".format(inputSet))", "+ # print(\"ALL={}\".format(allCharSet))", "+ diffset = allCharSet - inputSet", "+ # print(\"DIFF={}\".format(diffset))", "+ difflist = list(diffset)", "+ difflist.sort()", "+ # print(\"{}\".format(difflist))", "+ if len(difflist) == 0:", "+ result = \"None\"", "- return chr(firstPosition + 97)", "+ result = difflist[0]", "+ return result", "- S = input().strip()", "- solution = firstCharNotFound(S)", "- print((\"{}\".format(solution)))", "+ S = sys.stdin.readline().split(\"\\n\")", "+ allset = initSet()", "+ print((\"{}\".format(solver(S[0], allset))))" ]
false
0.076938
0.070209
1.095853
[ "s656410985", "s277390854" ]
u442877951
p03107
python
s222759482
s877030857
29
26
3,188
3,444
Accepted
Accepted
10.34
S = str(eval(input())) zero = 0 one = 0 for i in S: if i == "0": zero += 1 else: one += 1 ans = min(zero,one)*2 print(ans)
from collections import Counter S = str(eval(input())) SC = Counter(S) v,c = list(zip(*SC.most_common())) if len(c) == 2: print((len(S) - abs(c[1]-c[0]))) else: print((0))
10
8
137
166
S = str(eval(input())) zero = 0 one = 0 for i in S: if i == "0": zero += 1 else: one += 1 ans = min(zero, one) * 2 print(ans)
from collections import Counter S = str(eval(input())) SC = Counter(S) v, c = list(zip(*SC.most_common())) if len(c) == 2: print((len(S) - abs(c[1] - c[0]))) else: print((0))
false
20
[ "+from collections import Counter", "+", "-zero = 0", "-one = 0", "-for i in S:", "- if i == \"0\":", "- zero += 1", "- else:", "- one += 1", "-ans = min(zero, one) * 2", "-print(ans)", "+SC = Counter(S)", "+v, c = list(zip(*SC.most_common()))", "+if len(c) == 2:", "+ print((len(S) - abs(c[1] - c[0])))", "+else:", "+ print((0))" ]
false
0.039409
0.040643
0.969641
[ "s222759482", "s877030857" ]
u028973125
p03464
python
s493818265
s767326875
251
109
83,920
20,608
Accepted
Accepted
56.57
import sys K = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) # うまい方法がない気がするため、二分探索で攻める l = 0 r = 2 * 10**15 ans1 = -1 while l != r: n = (l + r) // 2 res = n for a in A: res = res - res % a if res >= 2: r = n if res == 2: ans1 = n else: l = n + 1 l = 0 r = 2 * 10**15 ans2 = -1 while l != r: n = (l + r) // 2 res = n for a in A: res = res - res % a if res <= 2: l = n + 1 if res == 2: ans2 = n else: r = n if ans1 != -1: print((ans1, ans2)) # print(n - n % A[0], A[0] * ((n - 1) // A[0] + 1) - 1) else: print((-1))
import sys K = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) if A[-1] != 2: print((-1)) sys.exit() l = 2 r = 2 for i in range(K-2, -1, -1): l = ((l - 1) // A[i] + 1) * A[i] r = ((r + A[i+1] - 1) // A[i]) * A[i] if l > r: print((-1)) sys.exit() # print(l, r) print((l, r + A[0] - 1))
41
21
722
367
import sys K = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) # うまい方法がない気がするため、二分探索で攻める l = 0 r = 2 * 10**15 ans1 = -1 while l != r: n = (l + r) // 2 res = n for a in A: res = res - res % a if res >= 2: r = n if res == 2: ans1 = n else: l = n + 1 l = 0 r = 2 * 10**15 ans2 = -1 while l != r: n = (l + r) // 2 res = n for a in A: res = res - res % a if res <= 2: l = n + 1 if res == 2: ans2 = n else: r = n if ans1 != -1: print((ans1, ans2)) # print(n - n % A[0], A[0] * ((n - 1) // A[0] + 1) - 1) else: print((-1))
import sys K = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) if A[-1] != 2: print((-1)) sys.exit() l = 2 r = 2 for i in range(K - 2, -1, -1): l = ((l - 1) // A[i] + 1) * A[i] r = ((r + A[i + 1] - 1) // A[i]) * A[i] if l > r: print((-1)) sys.exit() # print(l, r) print((l, r + A[0] - 1))
false
48.780488
[ "-# うまい方法がない気がするため、二分探索で攻める", "-l = 0", "-r = 2 * 10**15", "-ans1 = -1", "-while l != r:", "- n = (l + r) // 2", "- res = n", "- for a in A:", "- res = res - res % a", "- if res >= 2:", "- r = n", "- if res == 2:", "- ans1 = n", "- else:", "- l = n + 1", "-l = 0", "-r = 2 * 10**15", "-ans2 = -1", "-while l != r:", "- n = (l + r) // 2", "- res = n", "- for a in A:", "- res = res - res % a", "- if res <= 2:", "- l = n + 1", "- if res == 2:", "- ans2 = n", "- else:", "- r = n", "-if ans1 != -1:", "- print((ans1, ans2))", "- # print(n - n % A[0], A[0] * ((n - 1) // A[0] + 1) - 1)", "-else:", "+if A[-1] != 2:", "+ sys.exit()", "+l = 2", "+r = 2", "+for i in range(K - 2, -1, -1):", "+ l = ((l - 1) // A[i] + 1) * A[i]", "+ r = ((r + A[i + 1] - 1) // A[i]) * A[i]", "+ if l > r:", "+ print((-1))", "+ sys.exit()", "+# print(l, r)", "+print((l, r + A[0] - 1))" ]
false
0.072368
0.035918
2.014818
[ "s493818265", "s767326875" ]
u506858457
p02713
python
s741882766
s017837349
1,026
181
69,788
68,552
Accepted
Accepted
82.36
import math from functools import reduce def gcd(*numbers): return reduce(math.gcd, numbers) ans=0 K=int(eval(input())) for a in range(1,K+1): for b in range(1,K+1): for c in range(1,K+1): ans+=gcd(a,b,c) print(ans)
k = int(eval(input())) from math import gcd #gcd_sum = [0] * 201 ans = 0 ''' for i in range(1, k+1): for j in range(1, k+1): gcd_sum[i] += gcd(i,j) #print(gcd(i,j)) #print(gcd_sum[i]) ''' for a in range(1,k+1): for b in range(1,k+1): g = gcd(a,b) for c in range(1,k+1): ans += gcd(g,c) #print(g) #print(ans) print(ans)
13
24
240
423
import math from functools import reduce def gcd(*numbers): return reduce(math.gcd, numbers) ans = 0 K = int(eval(input())) for a in range(1, K + 1): for b in range(1, K + 1): for c in range(1, K + 1): ans += gcd(a, b, c) print(ans)
k = int(eval(input())) from math import gcd # gcd_sum = [0] * 201 ans = 0 """ for i in range(1, k+1): for j in range(1, k+1): gcd_sum[i] += gcd(i,j) #print(gcd(i,j)) #print(gcd_sum[i]) """ for a in range(1, k + 1): for b in range(1, k + 1): g = gcd(a, b) for c in range(1, k + 1): ans += gcd(g, c) # print(g) # print(ans) print(ans)
false
45.833333
[ "-import math", "-from functools import reduce", "+k = int(eval(input()))", "+from math import gcd", "-", "-def gcd(*numbers):", "- return reduce(math.gcd, numbers)", "-", "-", "+# gcd_sum = [0] * 201", "-K = int(eval(input()))", "-for a in range(1, K + 1):", "- for b in range(1, K + 1):", "- for c in range(1, K + 1):", "- ans += gcd(a, b, c)", "+\"\"\"", "+for i in range(1, k+1):", "+ for j in range(1, k+1):", "+ gcd_sum[i] += gcd(i,j)", "+ #print(gcd(i,j))", "+ #print(gcd_sum[i])", "+\"\"\"", "+for a in range(1, k + 1):", "+ for b in range(1, k + 1):", "+ g = gcd(a, b)", "+ for c in range(1, k + 1):", "+ ans += gcd(g, c)", "+ # print(g)", "+ # print(ans)" ]
false
0.086705
0.191151
0.453592
[ "s741882766", "s017837349" ]
u503228842
p02614
python
s565464247
s773582740
61
49
9,200
9,056
Accepted
Accepted
19.67
H, W, K = list(map(int, input().split())) g = [eval(input()) for _ in range(H)] ans = 0 for bit in range(2**(H + W)): cnt = 0 for h in range(H): if (bit & (h << 1)): pass if ((bit >> h) & 1): #print(h,"cancel") continue for w in range(W): if (bit & (H + w << 1)): pass if ((bit >> H + w) & 1): continue if g[h][w] == '#': cnt += 1 #print(h, w) if cnt == K: # print(bin(bit), "ok") # for i in range(H): # print(g[i]) ans += 1 print(ans)
h, w, k = list(map(int, input().split())) g = [eval(input()) for _ in range(h)] ans = 0 for bit in range(2**(h+w)): cnt = 0 for hh in range(h): if ((bit >> hh) & 1): continue for ww in range(w): if ((bit >> h + ww) & 1): continue if g[hh][ww] == '#': cnt += 1 if cnt == k: ans += 1 print(ans)
25
16
656
400
H, W, K = list(map(int, input().split())) g = [eval(input()) for _ in range(H)] ans = 0 for bit in range(2 ** (H + W)): cnt = 0 for h in range(H): if bit & (h << 1): pass if (bit >> h) & 1: # print(h,"cancel") continue for w in range(W): if bit & (H + w << 1): pass if (bit >> H + w) & 1: continue if g[h][w] == "#": cnt += 1 # print(h, w) if cnt == K: # print(bin(bit), "ok") # for i in range(H): # print(g[i]) ans += 1 print(ans)
h, w, k = list(map(int, input().split())) g = [eval(input()) for _ in range(h)] ans = 0 for bit in range(2 ** (h + w)): cnt = 0 for hh in range(h): if (bit >> hh) & 1: continue for ww in range(w): if (bit >> h + ww) & 1: continue if g[hh][ww] == "#": cnt += 1 if cnt == k: ans += 1 print(ans)
false
36
[ "-H, W, K = list(map(int, input().split()))", "-g = [eval(input()) for _ in range(H)]", "+h, w, k = list(map(int, input().split()))", "+g = [eval(input()) for _ in range(h)]", "-for bit in range(2 ** (H + W)):", "+for bit in range(2 ** (h + w)):", "- for h in range(H):", "- if bit & (h << 1):", "- pass", "- if (bit >> h) & 1:", "- # print(h,\"cancel\")", "+ for hh in range(h):", "+ if (bit >> hh) & 1:", "- for w in range(W):", "- if bit & (H + w << 1):", "- pass", "- if (bit >> H + w) & 1:", "+ for ww in range(w):", "+ if (bit >> h + ww) & 1:", "- if g[h][w] == \"#\":", "+ if g[hh][ww] == \"#\":", "- # print(h, w)", "- if cnt == K:", "- # print(bin(bit), \"ok\")", "- # for i in range(H):", "- # print(g[i])", "+ if cnt == k:" ]
false
0.083554
0.042234
1.978344
[ "s565464247", "s773582740" ]
u528720841
p02953
python
s902027170
s483893561
84
71
11,152
11,152
Accepted
Accepted
15.48
import sys N = int(eval(input())) H = list(map(int, input().split())) m = 0 for h in H: if m <= h-1 or m-1 <= h: m = max(m, h) else: print("No") sys.exit() print("Yes")
import sys N = int(eval(input())) H = list(map(int, input().split())) m = 0 for h in H: if m-1 <= h: m = max(m, h) else: print("No") sys.exit() print("Yes")
14
14
212
200
import sys N = int(eval(input())) H = list(map(int, input().split())) m = 0 for h in H: if m <= h - 1 or m - 1 <= h: m = max(m, h) else: print("No") sys.exit() print("Yes")
import sys N = int(eval(input())) H = list(map(int, input().split())) m = 0 for h in H: if m - 1 <= h: m = max(m, h) else: print("No") sys.exit() print("Yes")
false
0
[ "- if m <= h - 1 or m - 1 <= h:", "+ if m - 1 <= h:" ]
false
0.039411
0.072869
0.540852
[ "s902027170", "s483893561" ]
u391589398
p02579
python
s998638599
s855050480
834
561
134,528
133,484
Accepted
Accepted
32.73
h, w = list(map(int, input().split())) ch, cw = [int(x)-1 for x in input().split()] dh, dw = [int(x)-1 for x in input().split()] S = [list(eval(input())) for _ in range(h)] from collections import deque # 座標, 座標, ワープカウント q = deque([[ch, cw, 0]]) visited = [[-1] * w for _ in range(h)] visited[ch][cw] = 0 ans = -1 while q: i, j, wc = q.popleft() if i == dh and j == dw: ans = wc break for mi, mj in ((-1, 0), (1, 0), (0, -1), (0, 1)): ni, nj = i + mi, j + mj if 0 <= nj < w and 0 <= ni < h: if S[ni][nj] == '.' and visited[ni][nj] != wc: visited[ni][nj] = wc q.appendleft([ni, nj, wc]) for wi, wj in ((-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1), (-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)): ni, nj = i+wi, j+wj if (0 <= nj < w and 0 <= ni < h and S[ni][nj] == '.' and visited[ni][nj] == -1): visited[ni][nj] = wc+1 q.append([ni, nj, wc+1]) print(ans)
h, w = list(map(int, input().split())) ch, cw = [int(x)-1 for x in input().split()] dh, dw = [int(x)-1 for x in input().split()] S = [list(eval(input())) for _ in range(h)] from collections import deque # 座標, 座標, ワープカウント q = deque([[ch, cw, 0]]) wall = deque() visited = [[-1] * w for _ in range(h)] visited[ch][cw] = 0 ans = -2 while True: # つながっているエリアを探索 while q: i, j, wc = q.popleft() if i == dh and j == dw: ans = wc break next_to_wall = False for mi, mj in ((-1, 0), (1, 0), (0, -1), (0, 1)): ni, nj = i + mi, j + mj if 0 <= nj < w and 0 <= ni < h: if S[ni][nj] == '.' and visited[ni][nj] != wc: visited[ni][nj] = wc q.append([ni, nj, wc]) elif S[ni][nj] == '#': next_to_wall = True if next_to_wall: wall.append([i, j, wc]) else: # 飛ぶ場所がなかったら終了 if not wall: ans = -1 if ans > -2: break while wall: i, j, wc = wall.popleft() for wi, wj in ((-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1), (-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)): ni, nj = i+wi, j+wj if (0 <= nj < w and 0 <= ni < h and S[ni][nj] == '.' and (visited[ni][nj] == -1 or visited[ni][nj] > wc+1)): visited[ni][nj] = wc+1 q.append([ni, nj, wc+1]) print(ans)
35
51
1,198
1,695
h, w = list(map(int, input().split())) ch, cw = [int(x) - 1 for x in input().split()] dh, dw = [int(x) - 1 for x in input().split()] S = [list(eval(input())) for _ in range(h)] from collections import deque # 座標, 座標, ワープカウント q = deque([[ch, cw, 0]]) visited = [[-1] * w for _ in range(h)] visited[ch][cw] = 0 ans = -1 while q: i, j, wc = q.popleft() if i == dh and j == dw: ans = wc break for mi, mj in ((-1, 0), (1, 0), (0, -1), (0, 1)): ni, nj = i + mi, j + mj if 0 <= nj < w and 0 <= ni < h: if S[ni][nj] == "." and visited[ni][nj] != wc: visited[ni][nj] = wc q.appendleft([ni, nj, wc]) for wi, wj in ( (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1), (-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2), ): ni, nj = i + wi, j + wj if 0 <= nj < w and 0 <= ni < h and S[ni][nj] == "." and visited[ni][nj] == -1: visited[ni][nj] = wc + 1 q.append([ni, nj, wc + 1]) print(ans)
h, w = list(map(int, input().split())) ch, cw = [int(x) - 1 for x in input().split()] dh, dw = [int(x) - 1 for x in input().split()] S = [list(eval(input())) for _ in range(h)] from collections import deque # 座標, 座標, ワープカウント q = deque([[ch, cw, 0]]) wall = deque() visited = [[-1] * w for _ in range(h)] visited[ch][cw] = 0 ans = -2 while True: # つながっているエリアを探索 while q: i, j, wc = q.popleft() if i == dh and j == dw: ans = wc break next_to_wall = False for mi, mj in ((-1, 0), (1, 0), (0, -1), (0, 1)): ni, nj = i + mi, j + mj if 0 <= nj < w and 0 <= ni < h: if S[ni][nj] == "." and visited[ni][nj] != wc: visited[ni][nj] = wc q.append([ni, nj, wc]) elif S[ni][nj] == "#": next_to_wall = True if next_to_wall: wall.append([i, j, wc]) else: # 飛ぶ場所がなかったら終了 if not wall: ans = -1 if ans > -2: break while wall: i, j, wc = wall.popleft() for wi, wj in ( (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1), (-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2), ): ni, nj = i + wi, j + wj if ( 0 <= nj < w and 0 <= ni < h and S[ni][nj] == "." and (visited[ni][nj] == -1 or visited[ni][nj] > wc + 1) ): visited[ni][nj] = wc + 1 q.append([ni, nj, wc + 1]) print(ans)
false
31.372549
[ "+wall = deque()", "-ans = -1", "-while q:", "- i, j, wc = q.popleft()", "- if i == dh and j == dw:", "- ans = wc", "+ans = -2", "+while True:", "+ # つながっているエリアを探索", "+ while q:", "+ i, j, wc = q.popleft()", "+ if i == dh and j == dw:", "+ ans = wc", "+ break", "+ next_to_wall = False", "+ for mi, mj in ((-1, 0), (1, 0), (0, -1), (0, 1)):", "+ ni, nj = i + mi, j + mj", "+ if 0 <= nj < w and 0 <= ni < h:", "+ if S[ni][nj] == \".\" and visited[ni][nj] != wc:", "+ visited[ni][nj] = wc", "+ q.append([ni, nj, wc])", "+ elif S[ni][nj] == \"#\":", "+ next_to_wall = True", "+ if next_to_wall:", "+ wall.append([i, j, wc])", "+ else:", "+ # 飛ぶ場所がなかったら終了", "+ if not wall:", "+ ans = -1", "+ if ans > -2:", "- for mi, mj in ((-1, 0), (1, 0), (0, -1), (0, 1)):", "- ni, nj = i + mi, j + mj", "- if 0 <= nj < w and 0 <= ni < h:", "- if S[ni][nj] == \".\" and visited[ni][nj] != wc:", "- visited[ni][nj] = wc", "- q.appendleft([ni, nj, wc])", "- for wi, wj in (", "- (-2, -2),", "- (-2, -1),", "- (-2, 0),", "- (-2, 1),", "- (-2, 2),", "- (-1, -2),", "- (-1, -1),", "- (-1, 1),", "- (-1, 2),", "- (0, -2),", "- (0, 2),", "- (1, -2),", "- (1, -1),", "- (1, 1),", "- (1, 2),", "- (2, -2),", "- (2, -1),", "- (2, 0),", "- (2, 1),", "- (2, 2),", "- ):", "- ni, nj = i + wi, j + wj", "- if 0 <= nj < w and 0 <= ni < h and S[ni][nj] == \".\" and visited[ni][nj] == -1:", "- visited[ni][nj] = wc + 1", "- q.append([ni, nj, wc + 1])", "+ while wall:", "+ i, j, wc = wall.popleft()", "+ for wi, wj in (", "+ (-2, -2),", "+ (-2, -1),", "+ (-2, 0),", "+ (-2, 1),", "+ (-2, 2),", "+ (-1, -2),", "+ (-1, -1),", "+ (-1, 1),", "+ (-1, 2),", "+ (0, -2),", "+ (0, 2),", "+ (1, -2),", "+ (1, -1),", "+ (1, 1),", "+ (1, 2),", "+ (2, -2),", "+ (2, -1),", "+ (2, 0),", "+ (2, 1),", "+ (2, 2),", "+ ):", "+ ni, nj = i + wi, j + wj", "+ if (", "+ 0 <= nj < w", "+ and 0 <= ni < h", "+ and S[ni][nj] == \".\"", "+ and (visited[ni][nj] == -1 or visited[ni][nj] > wc + 1)", "+ ):", "+ visited[ni][nj] = wc + 1", "+ q.append([ni, nj, wc + 1])" ]
false
0.061094
0.036769
1.661545
[ "s998638599", "s855050480" ]
u396495667
p03803
python
s416245039
s104103707
173
17
38,256
3,060
Accepted
Accepted
90.17
a,b = list(map(int, input().split())) if a == 1: a+=13 if b == 1: b+=13 if a >b: print('Alice') elif b>a: print('Bob') elif a == b: print('Draw')
a,b = list(map(int, input().split())) if a==b==1: print('Draw') elif a ==1: print('Alice') elif b ==1: print('Bob') if a !=1 and b !=1: if a>b: print('Alice') elif a<b: print('Bob') elif a==b: print('Draw')
11
15
157
243
a, b = list(map(int, input().split())) if a == 1: a += 13 if b == 1: b += 13 if a > b: print("Alice") elif b > a: print("Bob") elif a == b: print("Draw")
a, b = list(map(int, input().split())) if a == b == 1: print("Draw") elif a == 1: print("Alice") elif b == 1: print("Bob") if a != 1 and b != 1: if a > b: print("Alice") elif a < b: print("Bob") elif a == b: print("Draw")
false
26.666667
[ "-if a == 1:", "- a += 13", "-if b == 1:", "- b += 13", "-if a > b:", "+if a == b == 1:", "+ print(\"Draw\")", "+elif a == 1:", "-elif b > a:", "+elif b == 1:", "-elif a == b:", "- print(\"Draw\")", "+if a != 1 and b != 1:", "+ if a > b:", "+ print(\"Alice\")", "+ elif a < b:", "+ print(\"Bob\")", "+ elif a == b:", "+ print(\"Draw\")" ]
false
0.099303
0.045552
2.179975
[ "s416245039", "s104103707" ]
u969190727
p02822
python
s680486505
s980096467
1,060
818
103,160
103,160
Accepted
Accepted
22.83
import sys input=lambda: sys.stdin.readline().rstrip() mod=10**9+7 n=int(eval(input())) edge=[[] for i in range(n)] for i in range(n-1): a,b=list(map(int,input().split())) edge[a-1].append(b-1) edge[b-1].append(a-1) inf=10**6 Par=[inf]*n Par[0]=-1 Deg=[0]*n Deg[0]=0 Chk=[0] while Chk: c=Chk.pop() for next in edge[c]: if Par[next]==inf: Par[next]=c Deg[next]+=1 Chk.append(next) from collections import deque TS=list(v for v in range(n) if Deg[v]==0) D=deque(TS) while D: v=D.popleft() for t in edge[v]: if t!=Par[v]: Deg[t]-=1 if Deg[t]==0: D.append(t) TS.append(t) Used=[False]*n C=[0]*n for i in reversed(list(range(n))): v=TS[i] Used[v]=True for g in edge[v]: if not Used[g]: C[g]+=C[v]+1 H=[0]*n H[0]=1 H[1]=pow(2,mod-2,mod) for i in range(2,n): H[i]=(H[i-1]*H[1])%mod ans=0 for i in range(n): if len(edge[i])==1: continue else: A=[] for e in edge[i]: if e==Par[i]: A.append(n-1-C[i]) else: A.append(C[e]+1) cur=1+(len(edge[i])-1)*H[-1] for a in A: cur-=H[n-1-a] ans=(ans+cur)%mod print(((ans*H[1])%mod))
import sys input=lambda: sys.stdin.readline().rstrip() mod=10**9+7 n=int(eval(input())) edge=[[] for i in range(n)] for i in range(n-1): a,b=list(map(int,input().split())) edge[a-1].append(b-1) edge[b-1].append(a-1) inf=10**6 Par=[inf]*n Par[0]=-1 Deg=[0]*n Deg[0]=0 Chk=[0] while Chk: c=Chk.pop() for next in edge[c]: if Par[next]==inf: Par[next]=c Deg[next]+=1 Chk.append(next) from collections import deque TS=list(v for v in range(n) if Deg[v]==0) D=deque(TS) while D: v=D.popleft() for t in edge[v]: if t!=Par[v]: Deg[t]-=1 if Deg[t]==0: D.append(t) TS.append(t) Used=[False]*n C=[0]*n for i in reversed(list(range(n))): v=TS[i] Used[v]=True for g in edge[v]: if not Used[g]: C[g]+=C[v]+1 H=[0]*n H[0]=1 H[1]=pow(2,mod-2,mod) for i in range(2,n): H[i]=(H[i-1]*H[1])%mod ans=0 for i in range(n): if len(edge[i])==1: continue else: A=[] for e in edge[i]: if e==Par[i]: A.append(n-1-C[i]) else: A.append(C[e]+1) cur=1+(len(edge[i])-1)*H[-1] for a in A: cur-=H[n-1-a] ans+=cur print(((ans*H[1])%mod))
66
66
1,208
1,199
import sys input = lambda: sys.stdin.readline().rstrip() mod = 10**9 + 7 n = int(eval(input())) edge = [[] for i in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) edge[a - 1].append(b - 1) edge[b - 1].append(a - 1) inf = 10**6 Par = [inf] * n Par[0] = -1 Deg = [0] * n Deg[0] = 0 Chk = [0] while Chk: c = Chk.pop() for next in edge[c]: if Par[next] == inf: Par[next] = c Deg[next] += 1 Chk.append(next) from collections import deque TS = list(v for v in range(n) if Deg[v] == 0) D = deque(TS) while D: v = D.popleft() for t in edge[v]: if t != Par[v]: Deg[t] -= 1 if Deg[t] == 0: D.append(t) TS.append(t) Used = [False] * n C = [0] * n for i in reversed(list(range(n))): v = TS[i] Used[v] = True for g in edge[v]: if not Used[g]: C[g] += C[v] + 1 H = [0] * n H[0] = 1 H[1] = pow(2, mod - 2, mod) for i in range(2, n): H[i] = (H[i - 1] * H[1]) % mod ans = 0 for i in range(n): if len(edge[i]) == 1: continue else: A = [] for e in edge[i]: if e == Par[i]: A.append(n - 1 - C[i]) else: A.append(C[e] + 1) cur = 1 + (len(edge[i]) - 1) * H[-1] for a in A: cur -= H[n - 1 - a] ans = (ans + cur) % mod print(((ans * H[1]) % mod))
import sys input = lambda: sys.stdin.readline().rstrip() mod = 10**9 + 7 n = int(eval(input())) edge = [[] for i in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) edge[a - 1].append(b - 1) edge[b - 1].append(a - 1) inf = 10**6 Par = [inf] * n Par[0] = -1 Deg = [0] * n Deg[0] = 0 Chk = [0] while Chk: c = Chk.pop() for next in edge[c]: if Par[next] == inf: Par[next] = c Deg[next] += 1 Chk.append(next) from collections import deque TS = list(v for v in range(n) if Deg[v] == 0) D = deque(TS) while D: v = D.popleft() for t in edge[v]: if t != Par[v]: Deg[t] -= 1 if Deg[t] == 0: D.append(t) TS.append(t) Used = [False] * n C = [0] * n for i in reversed(list(range(n))): v = TS[i] Used[v] = True for g in edge[v]: if not Used[g]: C[g] += C[v] + 1 H = [0] * n H[0] = 1 H[1] = pow(2, mod - 2, mod) for i in range(2, n): H[i] = (H[i - 1] * H[1]) % mod ans = 0 for i in range(n): if len(edge[i]) == 1: continue else: A = [] for e in edge[i]: if e == Par[i]: A.append(n - 1 - C[i]) else: A.append(C[e] + 1) cur = 1 + (len(edge[i]) - 1) * H[-1] for a in A: cur -= H[n - 1 - a] ans += cur print(((ans * H[1]) % mod))
false
0
[ "- ans = (ans + cur) % mod", "+ ans += cur" ]
false
0.037739
0.037441
1.007943
[ "s680486505", "s980096467" ]
u146346223
p02640
python
s865526489
s487845355
24
22
9,124
9,168
Accepted
Accepted
8.33
x, y = list(map(int, input().split())) for a in range(0, 100): for b in range(0, 100): if (2*a + 4*b) == y: if a + b == x: print('Yes') exit() print('No')
x, y = list(map(int, input().split())) if y % 2 == 0 and (x * 2 <= y) and (y <= x * 4): print('Yes') else: print('No')
10
6
215
126
x, y = list(map(int, input().split())) for a in range(0, 100): for b in range(0, 100): if (2 * a + 4 * b) == y: if a + b == x: print("Yes") exit() print("No")
x, y = list(map(int, input().split())) if y % 2 == 0 and (x * 2 <= y) and (y <= x * 4): print("Yes") else: print("No")
false
40
[ "-for a in range(0, 100):", "- for b in range(0, 100):", "- if (2 * a + 4 * b) == y:", "- if a + b == x:", "- print(\"Yes\")", "- exit()", "-print(\"No\")", "+if y % 2 == 0 and (x * 2 <= y) and (y <= x * 4):", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.049918
0.048718
1.024627
[ "s865526489", "s487845355" ]
u138486156
p03006
python
s550871259
s518674633
464
231
3,188
42,864
Accepted
Accepted
50.22
N = int(eval(input())) XY = sorted([tuple(map(int, input().split())) for _ in range(N)]) PQ = [] for i in range(N-1): for j in range(i, N): PQ.append((XY[j][0]-XY[i][0], XY[j][1]-XY[i][1])) PQ = list(set(PQ)) ans = N for p, q in PQ: tmp1 = 1 check=[0]*N for i in range(N-1): if check[i]: continue else: check[i] = 1 tmp2 = 1 for j in range(i, N): if check[j]: continue else: if XY[j][0] - p == XY[i][0] and XY[j][1] - q == XY[i][1]: check[j] == 1 tmp2 = 0 break tmp1 += tmp2 ans = min(ans, tmp1) print(ans)
from collections import deque from collections import defaultdict from copy import copy N = int(eval(input())) XY = list(sorted([tuple(map(int, input().split())) for _ in range(N)])) PQ = [] for i in range(N-1): for j in range(i, N): PQ.append((XY[j][0]-XY[i][0], XY[j][1]-XY[i][1])) PQ = list(set(PQ)) ans = N for p, q in PQ: tmp1 = 1 T = deque(copy(XY)) x, y = T.popleft() cnt = 1 while cnt < N: tmp2 = 1 for s, t in T: if s - p == x and t - q == y: tmp2 = 0 break if tmp2: x, y = T.popleft() else: T.remove((s, t)) x, y = s, t tmp1 += tmp2 cnt += 1 ans = min(ans, tmp1) print(ans)
34
37
772
802
N = int(eval(input())) XY = sorted([tuple(map(int, input().split())) for _ in range(N)]) PQ = [] for i in range(N - 1): for j in range(i, N): PQ.append((XY[j][0] - XY[i][0], XY[j][1] - XY[i][1])) PQ = list(set(PQ)) ans = N for p, q in PQ: tmp1 = 1 check = [0] * N for i in range(N - 1): if check[i]: continue else: check[i] = 1 tmp2 = 1 for j in range(i, N): if check[j]: continue else: if XY[j][0] - p == XY[i][0] and XY[j][1] - q == XY[i][1]: check[j] == 1 tmp2 = 0 break tmp1 += tmp2 ans = min(ans, tmp1) print(ans)
from collections import deque from collections import defaultdict from copy import copy N = int(eval(input())) XY = list(sorted([tuple(map(int, input().split())) for _ in range(N)])) PQ = [] for i in range(N - 1): for j in range(i, N): PQ.append((XY[j][0] - XY[i][0], XY[j][1] - XY[i][1])) PQ = list(set(PQ)) ans = N for p, q in PQ: tmp1 = 1 T = deque(copy(XY)) x, y = T.popleft() cnt = 1 while cnt < N: tmp2 = 1 for s, t in T: if s - p == x and t - q == y: tmp2 = 0 break if tmp2: x, y = T.popleft() else: T.remove((s, t)) x, y = s, t tmp1 += tmp2 cnt += 1 ans = min(ans, tmp1) print(ans)
false
8.108108
[ "+from collections import deque", "+from collections import defaultdict", "+from copy import copy", "+", "-XY = sorted([tuple(map(int, input().split())) for _ in range(N)])", "+XY = list(sorted([tuple(map(int, input().split())) for _ in range(N)]))", "- check = [0] * N", "- for i in range(N - 1):", "- if check[i]:", "- continue", "+ T = deque(copy(XY))", "+ x, y = T.popleft()", "+ cnt = 1", "+ while cnt < N:", "+ tmp2 = 1", "+ for s, t in T:", "+ if s - p == x and t - q == y:", "+ tmp2 = 0", "+ break", "+ if tmp2:", "+ x, y = T.popleft()", "- check[i] = 1", "- tmp2 = 1", "- for j in range(i, N):", "- if check[j]:", "- continue", "- else:", "- if XY[j][0] - p == XY[i][0] and XY[j][1] - q == XY[i][1]:", "- check[j] == 1", "- tmp2 = 0", "- break", "+ T.remove((s, t))", "+ x, y = s, t", "+ cnt += 1" ]
false
0.077933
0.068093
1.144514
[ "s550871259", "s518674633" ]
u803848678
p03343
python
s193052071
s309578955
523
457
47,196
47,196
Accepted
Accepted
12.62
n,k,q = list(map(int, input().split())) a = list(map(int, input().split())) num_set = set(a) def parse(b): ret = [] tmp = [] for ai in a: if ai >= b: tmp.append(ai) else: if len(tmp) >= k: tmp.sort(reverse=True) for i in range(k-1,len(tmp)): ret.append(tmp[i]) tmp = [] else: if len(tmp) >= k: tmp.sort(reverse=True) for i in range(k-1,len(tmp)): ret.append(tmp[i]) tmp = [] return ret ans = 10**10 for b in num_set: lis = parse(b) if len(lis) < q: continue ans_tmp = sorted(lis)[q-1] - min(lis) ans = min(ans, ans_tmp) print(ans)
n,k,q = list(map(int, input().split())) a = list(map(int, input().split())) def parse(b): ret = [] tmp = [] for ai in a: if ai >= b: tmp.append(ai) else: if len(tmp) >= k: tmp.sort(reverse=True) for i in range(k-1,len(tmp)): ret.append(tmp[i]) tmp = [] else: if len(tmp) >= k: tmp.sort(reverse=True) for i in range(k-1,len(tmp)): ret.append(tmp[i]) tmp = [] return ret ans = 10**10 for b in set(a): lis = parse(b) if len(lis) < q: continue lis.sort() ans_tmp = lis[q-1] - lis[0] ans = min(ans, ans_tmp) print(ans)
34
34
770
756
n, k, q = list(map(int, input().split())) a = list(map(int, input().split())) num_set = set(a) def parse(b): ret = [] tmp = [] for ai in a: if ai >= b: tmp.append(ai) else: if len(tmp) >= k: tmp.sort(reverse=True) for i in range(k - 1, len(tmp)): ret.append(tmp[i]) tmp = [] else: if len(tmp) >= k: tmp.sort(reverse=True) for i in range(k - 1, len(tmp)): ret.append(tmp[i]) tmp = [] return ret ans = 10**10 for b in num_set: lis = parse(b) if len(lis) < q: continue ans_tmp = sorted(lis)[q - 1] - min(lis) ans = min(ans, ans_tmp) print(ans)
n, k, q = list(map(int, input().split())) a = list(map(int, input().split())) def parse(b): ret = [] tmp = [] for ai in a: if ai >= b: tmp.append(ai) else: if len(tmp) >= k: tmp.sort(reverse=True) for i in range(k - 1, len(tmp)): ret.append(tmp[i]) tmp = [] else: if len(tmp) >= k: tmp.sort(reverse=True) for i in range(k - 1, len(tmp)): ret.append(tmp[i]) tmp = [] return ret ans = 10**10 for b in set(a): lis = parse(b) if len(lis) < q: continue lis.sort() ans_tmp = lis[q - 1] - lis[0] ans = min(ans, ans_tmp) print(ans)
false
0
[ "-num_set = set(a)", "-for b in num_set:", "+for b in set(a):", "- ans_tmp = sorted(lis)[q - 1] - min(lis)", "+ lis.sort()", "+ ans_tmp = lis[q - 1] - lis[0]" ]
false
0.037743
0.096573
0.390827
[ "s193052071", "s309578955" ]
u388927326
p02713
python
s734242428
s297719645
854
767
109,600
106,360
Accepted
Accepted
10.19
#!/usr/bin/env python3 from numba import njit def main(): k = int(eval(input())) print((getresult(k))) @njit def getresult(k): res = 0 for a in range(1, k + 1): for b in range(1, k + 1): for c in range(1, k + 1): res += gcd(gcd(a, b), c) return res @njit("i4(i4, i4)", cache=True) def gcd(x, y): if x < y: x, y = y, x # x >= y while y > 0: r = x % y x = y y = r return x if __name__ == "__main__": main()
#!/usr/bin/env python3 import numpy as np from numba import njit def main(): k = int(eval(input())) print((getresult(k))) @njit("i4(i4, i4)", cache=True) def gcd(x, y): if x < y: x, y = y, x # x >= y while y > 0: r = x % y x = y y = r return x @njit("i8(i4)", cache=True) def getresult(k): res = np.array([0], dtype=np.int64) for a in range(1, k + 1): for b in range(1, k + 1): for c in range(1, k + 1): res += gcd(gcd(a, b), c) return res[0] if __name__ == "__main__": main()
29
30
535
608
#!/usr/bin/env python3 from numba import njit def main(): k = int(eval(input())) print((getresult(k))) @njit def getresult(k): res = 0 for a in range(1, k + 1): for b in range(1, k + 1): for c in range(1, k + 1): res += gcd(gcd(a, b), c) return res @njit("i4(i4, i4)", cache=True) def gcd(x, y): if x < y: x, y = y, x # x >= y while y > 0: r = x % y x = y y = r return x if __name__ == "__main__": main()
#!/usr/bin/env python3 import numpy as np from numba import njit def main(): k = int(eval(input())) print((getresult(k))) @njit("i4(i4, i4)", cache=True) def gcd(x, y): if x < y: x, y = y, x # x >= y while y > 0: r = x % y x = y y = r return x @njit("i8(i4)", cache=True) def getresult(k): res = np.array([0], dtype=np.int64) for a in range(1, k + 1): for b in range(1, k + 1): for c in range(1, k + 1): res += gcd(gcd(a, b), c) return res[0] if __name__ == "__main__": main()
false
3.333333
[ "+import numpy as np", "-", "-", "-@njit", "-def getresult(k):", "- res = 0", "- for a in range(1, k + 1):", "- for b in range(1, k + 1):", "- for c in range(1, k + 1):", "- res += gcd(gcd(a, b), c)", "- return res", "+@njit(\"i8(i4)\", cache=True)", "+def getresult(k):", "+ res = np.array([0], dtype=np.int64)", "+ for a in range(1, k + 1):", "+ for b in range(1, k + 1):", "+ for c in range(1, k + 1):", "+ res += gcd(gcd(a, b), c)", "+ return res[0]", "+", "+" ]
false
0.0376
0.198524
0.189396
[ "s734242428", "s297719645" ]
u790710233
p03212
python
s016374119
s386568211
1,474
71
3,188
3,060
Accepted
Accepted
95.18
n = int(eval(input())) def squ(x): if x == 0: return '0' a = "" while x != 0: x, mod = divmod(x, 4) a += str(mod) return a[::-1] ans = 0 for x in range(10**6): x_squ = squ(x) x_str = x_squ.replace('3', '7').replace('2', '5').replace('1', '3') if "0" in x_str: continue if int(x_str) > n: break if len(set(x_str)) != 3: continue ans += 1 print(ans)
N = int(eval(input())) def dfs(x): if int('0'+x) > N: return 0 retval = 1 if len(set(x)) == 3 else 0 for c in '753': retval += dfs(x + c) return retval print((dfs('')))
30
13
468
208
n = int(eval(input())) def squ(x): if x == 0: return "0" a = "" while x != 0: x, mod = divmod(x, 4) a += str(mod) return a[::-1] ans = 0 for x in range(10**6): x_squ = squ(x) x_str = x_squ.replace("3", "7").replace("2", "5").replace("1", "3") if "0" in x_str: continue if int(x_str) > n: break if len(set(x_str)) != 3: continue ans += 1 print(ans)
N = int(eval(input())) def dfs(x): if int("0" + x) > N: return 0 retval = 1 if len(set(x)) == 3 else 0 for c in "753": retval += dfs(x + c) return retval print((dfs("")))
false
56.666667
[ "-n = int(eval(input()))", "+N = int(eval(input()))", "-def squ(x):", "- if x == 0:", "- return \"0\"", "- a = \"\"", "- while x != 0:", "- x, mod = divmod(x, 4)", "- a += str(mod)", "- return a[::-1]", "+def dfs(x):", "+ if int(\"0\" + x) > N:", "+ return 0", "+ retval = 1 if len(set(x)) == 3 else 0", "+ for c in \"753\":", "+ retval += dfs(x + c)", "+ return retval", "-ans = 0", "-for x in range(10**6):", "- x_squ = squ(x)", "- x_str = x_squ.replace(\"3\", \"7\").replace(\"2\", \"5\").replace(\"1\", \"3\")", "- if \"0\" in x_str:", "- continue", "- if int(x_str) > n:", "- break", "- if len(set(x_str)) != 3:", "- continue", "- ans += 1", "-print(ans)", "+print((dfs(\"\")))" ]
false
0.472532
0.044164
10.699555
[ "s016374119", "s386568211" ]
u170201762
p02955
python
s489542977
s816717530
375
286
44,140
42,844
Accepted
Accepted
23.73
def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors N,K = list(map(int,input().split())) A = list(map(int,input().split())) D = sum(A) D = make_divisors(D)[::-1] for d in D: a = [] for i in range(N): a.append(A[i]%d) k = 0 M = max(a) while k <= K and M != 0: i = 0 j = 0 m = d M = 0 for l in range(N): if 0 < a[l] < m: m = a[l] i = l for l in range(N-1,-1,-1): if a[l] > M: M = a[l] j = l if m == d: break if m <= d-M: a[i] = 0 a[j] += m a[j] %= d k += m else: a[i] -= d-M a[i] %= d a[j] = 0 k += d-M if k <= K: break print(d)
N,K = list(map(int,input().split())) A = list(map(int,input().split())) s = sum(A) divisors = [] for i in range(1,int(s**0.5)+1): if s%i==0: divisors.append(i) divisors.append(s//i) divisors = list(set(divisors)) divisors.sort(reverse=True) def possible(n): a = [] for i in range(N): if A[i]%n != 0: a.append(A[i]%n) a.sort() k = 0 while k <= K and a: m = a[0] M = a[-1] if m <= n-M: k += m a[-1] = (M+m)%n a[0] = 0 else: k += n-M a[0] = (m-n+M)%n a[-1] = 0 if a[0]==0: a = a[1:] if a[-1]==0: a = a[:-1] a.sort() return k<=K for n in divisors: if possible(n): ans = n break print(ans)
51
43
1,068
860
def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return divisors N, K = list(map(int, input().split())) A = list(map(int, input().split())) D = sum(A) D = make_divisors(D)[::-1] for d in D: a = [] for i in range(N): a.append(A[i] % d) k = 0 M = max(a) while k <= K and M != 0: i = 0 j = 0 m = d M = 0 for l in range(N): if 0 < a[l] < m: m = a[l] i = l for l in range(N - 1, -1, -1): if a[l] > M: M = a[l] j = l if m == d: break if m <= d - M: a[i] = 0 a[j] += m a[j] %= d k += m else: a[i] -= d - M a[i] %= d a[j] = 0 k += d - M if k <= K: break print(d)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) s = sum(A) divisors = [] for i in range(1, int(s**0.5) + 1): if s % i == 0: divisors.append(i) divisors.append(s // i) divisors = list(set(divisors)) divisors.sort(reverse=True) def possible(n): a = [] for i in range(N): if A[i] % n != 0: a.append(A[i] % n) a.sort() k = 0 while k <= K and a: m = a[0] M = a[-1] if m <= n - M: k += m a[-1] = (M + m) % n a[0] = 0 else: k += n - M a[0] = (m - n + M) % n a[-1] = 0 if a[0] == 0: a = a[1:] if a[-1] == 0: a = a[:-1] a.sort() return k <= K for n in divisors: if possible(n): ans = n break print(ans)
false
15.686275
[ "-def make_divisors(n):", "- divisors = []", "- for i in range(1, int(n**0.5) + 1):", "- if n % i == 0:", "- divisors.append(i)", "- if i != n // i:", "- divisors.append(n // i)", "- divisors.sort()", "- return divisors", "+N, K = list(map(int, input().split()))", "+A = list(map(int, input().split()))", "+s = sum(A)", "+divisors = []", "+for i in range(1, int(s**0.5) + 1):", "+ if s % i == 0:", "+ divisors.append(i)", "+ divisors.append(s // i)", "+divisors = list(set(divisors))", "+divisors.sort(reverse=True)", "-N, K = list(map(int, input().split()))", "-A = list(map(int, input().split()))", "-D = sum(A)", "-D = make_divisors(D)[::-1]", "-for d in D:", "+def possible(n):", "- a.append(A[i] % d)", "+ if A[i] % n != 0:", "+ a.append(A[i] % n)", "+ a.sort()", "- M = max(a)", "- while k <= K and M != 0:", "- i = 0", "- j = 0", "- m = d", "- M = 0", "- for l in range(N):", "- if 0 < a[l] < m:", "- m = a[l]", "- i = l", "- for l in range(N - 1, -1, -1):", "- if a[l] > M:", "- M = a[l]", "- j = l", "- if m == d:", "- break", "- if m <= d - M:", "- a[i] = 0", "- a[j] += m", "- a[j] %= d", "+ while k <= K and a:", "+ m = a[0]", "+ M = a[-1]", "+ if m <= n - M:", "+ a[-1] = (M + m) % n", "+ a[0] = 0", "- a[i] -= d - M", "- a[i] %= d", "- a[j] = 0", "- k += d - M", "- if k <= K:", "+ k += n - M", "+ a[0] = (m - n + M) % n", "+ a[-1] = 0", "+ if a[0] == 0:", "+ a = a[1:]", "+ if a[-1] == 0:", "+ a = a[:-1]", "+ a.sort()", "+ return k <= K", "+", "+", "+for n in divisors:", "+ if possible(n):", "+ ans = n", "-print(d)", "+print(ans)" ]
false
0.087803
0.036155
2.428514
[ "s489542977", "s816717530" ]
u367130284
p03073
python
s405786354
s907740629
113
102
4,852
3,316
Accepted
Accepted
9.73
s=eval(input()) x=[i%2 for i in range(len(s))] y=[~i%2 for i in range(len(s))] #print(x,y) c=0 e=0 for i in range(len(s)): #print(s[i],x[i],y[i]) if int(s[i])!=x[i]: c+=1 if int(s[i])!=y[i]: e+=1 print((min(c,e)))
s=eval(input()) ans=0 ans2=0 for i in range(len(s)): if int(s[i])!=i%2: ans+=1 if int(s[i])!=(i+1)%2: ans2+=1 print((min(ans,ans2)))
13
9
245
156
s = eval(input()) x = [i % 2 for i in range(len(s))] y = [~i % 2 for i in range(len(s))] # print(x,y) c = 0 e = 0 for i in range(len(s)): # print(s[i],x[i],y[i]) if int(s[i]) != x[i]: c += 1 if int(s[i]) != y[i]: e += 1 print((min(c, e)))
s = eval(input()) ans = 0 ans2 = 0 for i in range(len(s)): if int(s[i]) != i % 2: ans += 1 if int(s[i]) != (i + 1) % 2: ans2 += 1 print((min(ans, ans2)))
false
30.769231
[ "-x = [i % 2 for i in range(len(s))]", "-y = [~i % 2 for i in range(len(s))]", "-# print(x,y)", "-c = 0", "-e = 0", "+ans = 0", "+ans2 = 0", "- # print(s[i],x[i],y[i])", "- if int(s[i]) != x[i]:", "- c += 1", "- if int(s[i]) != y[i]:", "- e += 1", "-print((min(c, e)))", "+ if int(s[i]) != i % 2:", "+ ans += 1", "+ if int(s[i]) != (i + 1) % 2:", "+ ans2 += 1", "+print((min(ans, ans2)))" ]
false
0.04387
0.007326
5.988212
[ "s405786354", "s907740629" ]
u367701763
p03163
python
s694997745
s774845126
242
166
152,564
74,520
Accepted
Accepted
31.4
import sys input = sys.stdin.readline M, W = list(map(int, input().split())) # M: 品物の種類 W: 重量制限 single = True # True = 重複なし price_list = [0] weight_list = [0] for _ in range(M): weight, price = list(map(int, input().split())) price_list.append(price) weight_list.append(weight) ################################################################################################################################################ dp_min = 0 # 総和価値の最小値 """ dp[item <= M ][weight <= W] = 重さ上限を固定した時の"最大"価値 """ dp = [[dp_min] * (W + 1) for _ in range(M + 1)] # 左端と上端の境界条件で W, M を一個ずつ多めに取る """ 重さ 0 の時の境界条件 """ for item in range(M+1): dp[item][0] = 0 # 重さ 0 を実現するのに必要な品物の個数は 0 個 """ 品物 0 個の時の境界条件 """ # for weight in range(W+1): # dp[0][weight] = dp_min # 0 種類の品物で実現できる重量は存在しない (dpの初期化で自動的に課せる場合が多い) for item in range(1,M+1): # 境界条件を除いた M 回のループ(※ f[item] = g.f[item-i] の漸化式なので、list index out of range となる) for weight in range(1, W + 1): if weight < weight_list[item]: # weight (重量価値) < weight_list[item] (品物の重量) の時は無視してよい dp[item][weight] = dp[item - 1][weight] else: temp = dp[item - single][weight - weight_list[item]] + price_list[item] # single = True: 重複なし if temp > dp[item-1][weight]: # max(dp[item-1][weight], temp) dp[item][weight] = temp else: dp[item][weight] = dp[item-1][weight] print((dp[M][W]))
import sys input = sys.stdin.readline N, W = list(map(int, input().split())) # N: 品物の種類 W: 重量制限 price_list = [] weight_list = [] for _ in range(N): weight, price = list(map(int, input().split())) price_list.append(price) weight_list.append(weight) ################################################################################################################################################ def max2(x,y): """ pythonの組み込み関数 max は2変数に対しては遅い!! """ if x>y: return x else: return y dp_min = 0 # 総和価値の最小値 """ dp[weight <= W] = 重さ上限を固定した時の"最大"価値 """ dp = [dp_min] * (W + 1) for item in range(N): for weight in reversed(list(range(weight_list[item], W + 1))): dp[weight] = max2(dp[weight], dp[weight - weight_list[item]] + price_list[item]) print((dp[W]))
44
36
1,775
914
import sys input = sys.stdin.readline M, W = list(map(int, input().split())) # M: 品物の種類 W: 重量制限 single = True # True = 重複なし price_list = [0] weight_list = [0] for _ in range(M): weight, price = list(map(int, input().split())) price_list.append(price) weight_list.append(weight) ################################################################################################################################################ dp_min = 0 # 総和価値の最小値 """ dp[item <= M ][weight <= W] = 重さ上限を固定した時の"最大"価値 """ dp = [[dp_min] * (W + 1) for _ in range(M + 1)] # 左端と上端の境界条件で W, M を一個ずつ多めに取る """ 重さ 0 の時の境界条件 """ for item in range(M + 1): dp[item][0] = 0 # 重さ 0 を実現するのに必要な品物の個数は 0 個 """ 品物 0 個の時の境界条件 """ # for weight in range(W+1): # dp[0][weight] = dp_min # 0 種類の品物で実現できる重量は存在しない (dpの初期化で自動的に課せる場合が多い) for item in range( 1, M + 1 ): # 境界条件を除いた M 回のループ(※ f[item] = g.f[item-i] の漸化式なので、list index out of range となる) for weight in range(1, W + 1): if ( weight < weight_list[item] ): # weight (重量価値) < weight_list[item] (品物の重量) の時は無視してよい dp[item][weight] = dp[item - 1][weight] else: temp = ( dp[item - single][weight - weight_list[item]] + price_list[item] ) # single = True: 重複なし if temp > dp[item - 1][weight]: # max(dp[item-1][weight], temp) dp[item][weight] = temp else: dp[item][weight] = dp[item - 1][weight] print((dp[M][W]))
import sys input = sys.stdin.readline N, W = list(map(int, input().split())) # N: 品物の種類 W: 重量制限 price_list = [] weight_list = [] for _ in range(N): weight, price = list(map(int, input().split())) price_list.append(price) weight_list.append(weight) ################################################################################################################################################ def max2(x, y): """pythonの組み込み関数 max は2変数に対しては遅い!!""" if x > y: return x else: return y dp_min = 0 # 総和価値の最小値 """ dp[weight <= W] = 重さ上限を固定した時の"最大"価値 """ dp = [dp_min] * (W + 1) for item in range(N): for weight in reversed(list(range(weight_list[item], W + 1))): dp[weight] = max2(dp[weight], dp[weight - weight_list[item]] + price_list[item]) print((dp[W]))
false
18.181818
[ "-M, W = list(map(int, input().split())) # M: 品物の種類 W: 重量制限", "-single = True # True = 重複なし", "-price_list = [0]", "-weight_list = [0]", "-for _ in range(M):", "+N, W = list(map(int, input().split())) # N: 品物の種類 W: 重量制限", "+price_list = []", "+weight_list = []", "+for _ in range(N):", "+def max2(x, y):", "+ \"\"\"pythonの組み込み関数 max は2変数に対しては遅い!!\"\"\"", "+ if x > y:", "+ return x", "+ else:", "+ return y", "+", "+", "-\"\"\" dp[item <= M ][weight <= W] = 重さ上限を固定した時の\"最大\"価値 \"\"\"", "-dp = [[dp_min] * (W + 1) for _ in range(M + 1)] # 左端と上端の境界条件で W, M を一個ずつ多めに取る", "-\"\"\" 重さ 0 の時の境界条件 \"\"\"", "-for item in range(M + 1):", "- dp[item][0] = 0 # 重さ 0 を実現するのに必要な品物の個数は 0 個", "-\"\"\" 品物 0 個の時の境界条件 \"\"\"", "-# for weight in range(W+1):", "-# dp[0][weight] = dp_min # 0 種類の品物で実現できる重量は存在しない (dpの初期化で自動的に課せる場合が多い)", "-for item in range(", "- 1, M + 1", "-): # 境界条件を除いた M 回のループ(※ f[item] = g.f[item-i] の漸化式なので、list index out of range となる)", "- for weight in range(1, W + 1):", "- if (", "- weight < weight_list[item]", "- ): # weight (重量価値) < weight_list[item] (品物の重量) の時は無視してよい", "- dp[item][weight] = dp[item - 1][weight]", "- else:", "- temp = (", "- dp[item - single][weight - weight_list[item]] + price_list[item]", "- ) # single = True: 重複なし", "- if temp > dp[item - 1][weight]: # max(dp[item-1][weight], temp)", "- dp[item][weight] = temp", "- else:", "- dp[item][weight] = dp[item - 1][weight]", "-print((dp[M][W]))", "+\"\"\" dp[weight <= W] = 重さ上限を固定した時の\"最大\"価値 \"\"\"", "+dp = [dp_min] * (W + 1)", "+for item in range(N):", "+ for weight in reversed(list(range(weight_list[item], W + 1))):", "+ dp[weight] = max2(dp[weight], dp[weight - weight_list[item]] + price_list[item])", "+print((dp[W]))" ]
false
0.040834
0.038084
1.07223
[ "s694997745", "s774845126" ]
u600402037
p02900
python
s480167747
s768457078
174
91
3,064
3,064
Accepted
Accepted
47.7
import sys sys.setrecursionlimit(10 ** 7) def gcd(a, b): while b: a, b = b, a % b return a def prime_decomposition(n): i = 2 table = [] while i * i <= n: while n % i == 0: n //= i table.append(i) i += 1 if n > 1: table.append(n) return table A, B = list(map(int, input().split())) x = gcd(A, B) prime_list = prime_decomposition(x) s = set(prime_list) print((len(s)+1))
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) A, B = lr() 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 primes = prime_factorize(min(A, B)) answer = set() for p in primes: if A % p == 0 and B % p == 0: answer.add(p) print((len(answer) + 1)) # 1をプラス # 35
25
32
438
599
import sys sys.setrecursionlimit(10**7) def gcd(a, b): while b: a, b = b, a % b return a def prime_decomposition(n): i = 2 table = [] while i * i <= n: while n % i == 0: n //= i table.append(i) i += 1 if n > 1: table.append(n) return table A, B = list(map(int, input().split())) x = gcd(A, B) prime_list = prime_decomposition(x) s = set(prime_list) print((len(s) + 1))
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) A, B = lr() 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 primes = prime_factorize(min(A, B)) answer = set() for p in primes: if A % p == 0 and B % p == 0: answer.add(p) print((len(answer) + 1)) # 1をプラス # 35
false
21.875
[ "-sys.setrecursionlimit(10**7)", "+sr = lambda: sys.stdin.readline().rstrip()", "+ir = lambda: int(sr())", "+lr = lambda: list(map(int, sr().split()))", "+A, B = lr()", "-def gcd(a, b):", "- while b:", "- a, b = b, a % b", "+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)", "-def prime_decomposition(n):", "- i = 2", "- table = []", "- while i * i <= n:", "- while n % i == 0:", "- n //= i", "- table.append(i)", "- i += 1", "- if n > 1:", "- table.append(n)", "- return table", "-", "-", "-A, B = list(map(int, input().split()))", "-x = gcd(A, B)", "-prime_list = prime_decomposition(x)", "-s = set(prime_list)", "-print((len(s) + 1))", "+primes = prime_factorize(min(A, B))", "+answer = set()", "+for p in primes:", "+ if A % p == 0 and B % p == 0:", "+ answer.add(p)", "+print((len(answer) + 1)) # 1をプラス", "+# 35" ]
false
0.035533
0.036773
0.96629
[ "s480167747", "s768457078" ]
u254871849
p03379
python
s693630385
s068671035
490
310
25,180
25,052
Accepted
Accepted
36.73
# author: kagemeka # created: 2019-11-07 11:52:43(JST) import sys # import collections # import math # import string import bisect # import re # import itertools # import statistics # import functools # import operator def main(): n, *x = (int(i) for i in sys.stdin.read().split()) s_x = list(sorted(x)) half = n // 2 m_s, m_l = s_x[half -1], s_x[half] for i in x: b = bisect.bisect_left(s_x, i) print((m_l if b < half else m_s)) if __name__ == "__main__": # execute only if run as a script main()
# author: kagemeka # created: 2019-11-07 11:52:43(JST) import sys # import collections # import math # import string # import bisect # import re # import itertools # import statistics # import functools # import operator def main(): n, *x = (int(i) for i in sys.stdin.read().split()) s_x = list(sorted(x)) half = n // 2 m_s, m_l = s_x[half - 1], s_x[half] for i in x: print((m_l if i < m_l else m_s)) if __name__ == "__main__": # execute only if run as a script main()
25
24
616
578
# author: kagemeka # created: 2019-11-07 11:52:43(JST) import sys # import collections # import math # import string import bisect # import re # import itertools # import statistics # import functools # import operator def main(): n, *x = (int(i) for i in sys.stdin.read().split()) s_x = list(sorted(x)) half = n // 2 m_s, m_l = s_x[half - 1], s_x[half] for i in x: b = bisect.bisect_left(s_x, i) print((m_l if b < half else m_s)) if __name__ == "__main__": # execute only if run as a script main()
# author: kagemeka # created: 2019-11-07 11:52:43(JST) import sys # import collections # import math # import string # import bisect # import re # import itertools # import statistics # import functools # import operator def main(): n, *x = (int(i) for i in sys.stdin.read().split()) s_x = list(sorted(x)) half = n // 2 m_s, m_l = s_x[half - 1], s_x[half] for i in x: print((m_l if i < m_l else m_s)) if __name__ == "__main__": # execute only if run as a script main()
false
4
[ "-import bisect", "-", "+# import bisect", "- b = bisect.bisect_left(s_x, i)", "- print((m_l if b < half else m_s))", "+ print((m_l if i < m_l else m_s))" ]
false
0.045152
0.04638
0.973523
[ "s693630385", "s068671035" ]
u197300773
p03291
python
s216313700
s903154804
290
254
3,188
3,188
Accepted
Accepted
12.41
s=eval(input()) a=[1,0,0,0] for i in range(len(s)): if s[i]=="A": a[1]+=a[0] elif s[i]=="B": a[2]+=a[1] elif s[i]=="C": a[3]+=a[2] else: a=[ a[0]*3 ] + [ a[j]*3+a[j-1] for j in range(1,4) ] a=[a[i]%1000000007 for i in range(4)] print((a[3]))
s=eval(input()) a=[1,0,0,0] for i in range(len(s)): c=s[i] if c=="A": a[1]+=a[0] elif c=="B": a[2]+=a[1] elif c=="C": a[3]+=a[2] else: a=[ a[0]*3 ] + [ a[j+1]*3+a[j] for j in range(3) ] a=[a[i]%1000000007 for i in range(4)] print((a[3]))
17
18
305
306
s = eval(input()) a = [1, 0, 0, 0] for i in range(len(s)): if s[i] == "A": a[1] += a[0] elif s[i] == "B": a[2] += a[1] elif s[i] == "C": a[3] += a[2] else: a = [a[0] * 3] + [a[j] * 3 + a[j - 1] for j in range(1, 4)] a = [a[i] % 1000000007 for i in range(4)] print((a[3]))
s = eval(input()) a = [1, 0, 0, 0] for i in range(len(s)): c = s[i] if c == "A": a[1] += a[0] elif c == "B": a[2] += a[1] elif c == "C": a[3] += a[2] else: a = [a[0] * 3] + [a[j + 1] * 3 + a[j] for j in range(3)] a = [a[i] % 1000000007 for i in range(4)] print((a[3]))
false
5.555556
[ "- if s[i] == \"A\":", "+ c = s[i]", "+ if c == \"A\":", "- elif s[i] == \"B\":", "+ elif c == \"B\":", "- elif s[i] == \"C\":", "+ elif c == \"C\":", "- a = [a[0] * 3] + [a[j] * 3 + a[j - 1] for j in range(1, 4)]", "+ a = [a[0] * 3] + [a[j + 1] * 3 + a[j] for j in range(3)]" ]
false
0.084394
0.039694
2.126124
[ "s216313700", "s903154804" ]
u703950586
p03739
python
s439654186
s911235927
620
321
122,232
61,928
Accepted
Accepted
48.23
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) n = NI() bit = [0] * (n+1) A = LI() def add(i,x): while i <= n: bit[i] += x i += i & -i def query(i): x = 0 while i > 0: x += bit[i] i -= i & -i return x for i,a in enumerate(A): add(i+1,int(a)) ans = INF bit_c = copy.deepcopy(bit) for s in (1,-1): bit = copy.deepcopy(bit_c) cnt = 0 x = s for i in range(1,n+1): z = query(i) if z * x <= 0: add(i,x-z) cnt += abs(x-z) x = -x ans = min(ans,cnt) print(ans) if __name__ == '__main__': main()
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) n = NI() bit = [0] * (n+1) def add(i,x): while i <= n: bit[i] += x i += i & -i def query(i): x = 0 while i > 0: x += bit[i] i -= i & -i return x for i,a in enumerate(LI()): add(i+1,int(a)) ans = INF b = [bit,copy.copy(bit)] for s in (1,-1): bit = b[(s+1)//2] cnt = 0 x = s for i in range(1,n+1): z = query(i) if z * x <= 0: add(i,x-z) cnt += abs(x-z) x = -x ans = min(ans,cnt) print(ans) if __name__ == '__main__': main()
45
46
982
964
import sys, queue, math, copy, itertools, bisect, collections, heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda: [int(x) for x in sys.stdin.readline().split()] NI = lambda: int(sys.stdin.readline()) n = NI() bit = [0] * (n + 1) A = LI() def add(i, x): while i <= n: bit[i] += x i += i & -i def query(i): x = 0 while i > 0: x += bit[i] i -= i & -i return x for i, a in enumerate(A): add(i + 1, int(a)) ans = INF bit_c = copy.deepcopy(bit) for s in (1, -1): bit = copy.deepcopy(bit_c) cnt = 0 x = s for i in range(1, n + 1): z = query(i) if z * x <= 0: add(i, x - z) cnt += abs(x - z) x = -x ans = min(ans, cnt) print(ans) if __name__ == "__main__": main()
import sys, queue, math, copy, itertools, bisect, collections, heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda: [int(x) for x in sys.stdin.readline().split()] NI = lambda: int(sys.stdin.readline()) n = NI() bit = [0] * (n + 1) def add(i, x): while i <= n: bit[i] += x i += i & -i def query(i): x = 0 while i > 0: x += bit[i] i -= i & -i return x for i, a in enumerate(LI()): add(i + 1, int(a)) ans = INF b = [bit, copy.copy(bit)] for s in (1, -1): bit = b[(s + 1) // 2] cnt = 0 x = s for i in range(1, n + 1): z = query(i) if z * x <= 0: add(i, x - z) cnt += abs(x - z) x = -x ans = min(ans, cnt) print(ans) if __name__ == "__main__": main()
false
2.173913
[ "- A = LI()", "- for i, a in enumerate(A):", "+ for i, a in enumerate(LI()):", "- bit_c = copy.deepcopy(bit)", "+ b = [bit, copy.copy(bit)]", "- bit = copy.deepcopy(bit_c)", "+ bit = b[(s + 1) // 2]" ]
false
0.061393
0.077174
0.795507
[ "s439654186", "s911235927" ]
u945345165
p00033
python
s894989502
s769551422
30
20
7,756
7,732
Accepted
Accepted
33.33
import sys def solve(balls): ans = distribute(balls, [], []) if ans is True: print('YES') else: print("NO") def distribute(balls, R, L): if len(balls) != 0: next = balls[0] ans = False #case R if isMutch(next, R): neoR = R neoR.append(next) ans = distribute(balls[1:], neoR, L) if ans: return True if isMutch(next, L): neoL = L neoL.append(next) ans =distribute(balls[1:], R, neoL) if ans: return True else: return isOrdered(R) and isOrdered(L) def isMutch(next, lis): if len(lis) != 0: return next >= lis[len(lis)-1] return True def isOrdered(lis): #check both R and L are ordered checker = sorted(lis) return checker == lis limit = 2**11 sys.setrecursionlimit(limit) line = eval(input()) size = -1; while True: if size == -1: size = int(line) else: balls = [] for a in line.split(' '): balls.append(int(a)) solve(balls) size -= 1 if size == 0: break line = eval(input())
import sys def solve(balls): if distribute(balls, [], []): print('YES') else: print("NO") def distribute(balls, R, L): if len(balls) != 0: next = balls[0] if isMutch(next, R): neoR = R neoR.append(next) if distribute(balls[1:], neoR, L): return True if isMutch(next, L): neoL = L neoL.append(next) if distribute(balls[1:], R, neoL): return True else: return isOrdered(R) and isOrdered(L) def isMutch(next, lis): if len(lis) != 0: return next >= lis[len(lis)-1] return True def isOrdered(lis): #check both R and L are ordered checker = sorted(lis) return checker == lis limit = 2**11 sys.setrecursionlimit(limit) size = int(eval(input())); for i in range(0,size): balls = [] for a in input().split(' '): balls.append(int(a)) solve(balls) size -= 1 if size == 0: break
52
41
1,205
1,013
import sys def solve(balls): ans = distribute(balls, [], []) if ans is True: print("YES") else: print("NO") def distribute(balls, R, L): if len(balls) != 0: next = balls[0] ans = False # case R if isMutch(next, R): neoR = R neoR.append(next) ans = distribute(balls[1:], neoR, L) if ans: return True if isMutch(next, L): neoL = L neoL.append(next) ans = distribute(balls[1:], R, neoL) if ans: return True else: return isOrdered(R) and isOrdered(L) def isMutch(next, lis): if len(lis) != 0: return next >= lis[len(lis) - 1] return True def isOrdered(lis): # check both R and L are ordered checker = sorted(lis) return checker == lis limit = 2**11 sys.setrecursionlimit(limit) line = eval(input()) size = -1 while True: if size == -1: size = int(line) else: balls = [] for a in line.split(" "): balls.append(int(a)) solve(balls) size -= 1 if size == 0: break line = eval(input())
import sys def solve(balls): if distribute(balls, [], []): print("YES") else: print("NO") def distribute(balls, R, L): if len(balls) != 0: next = balls[0] if isMutch(next, R): neoR = R neoR.append(next) if distribute(balls[1:], neoR, L): return True if isMutch(next, L): neoL = L neoL.append(next) if distribute(balls[1:], R, neoL): return True else: return isOrdered(R) and isOrdered(L) def isMutch(next, lis): if len(lis) != 0: return next >= lis[len(lis) - 1] return True def isOrdered(lis): # check both R and L are ordered checker = sorted(lis) return checker == lis limit = 2**11 sys.setrecursionlimit(limit) size = int(eval(input())) for i in range(0, size): balls = [] for a in input().split(" "): balls.append(int(a)) solve(balls) size -= 1 if size == 0: break
false
21.153846
[ "- ans = distribute(balls, [], [])", "- if ans is True:", "+ if distribute(balls, [], []):", "- ans = False", "- # case R", "- ans = distribute(balls[1:], neoR, L)", "- if ans:", "- return True", "+ if distribute(balls[1:], neoR, L):", "+ return True", "- ans = distribute(balls[1:], R, neoL)", "- if ans:", "- return True", "+ if distribute(balls[1:], R, neoL):", "+ return True", "-line = eval(input())", "-size = -1", "-while True:", "- if size == -1:", "- size = int(line)", "- else:", "- balls = []", "- for a in line.split(\" \"):", "- balls.append(int(a))", "- solve(balls)", "- size -= 1", "- if size == 0:", "- break", "- line = eval(input())", "+size = int(eval(input()))", "+for i in range(0, size):", "+ balls = []", "+ for a in input().split(\" \"):", "+ balls.append(int(a))", "+ solve(balls)", "+ size -= 1", "+ if size == 0:", "+ break" ]
false
0.156435
0.051577
3.033016
[ "s894989502", "s769551422" ]
u745087332
p04006
python
s263393859
s353931119
1,302
758
3,188
3,188
Accepted
Accepted
41.78
# coding:utf-8 INF = float('inf') def inpl(): return list(map(int, input().split())) N, x = inpl() A = inpl() min_index = A.index(min(A)) B = A[min_index:] + A[:min_index] cost = [B[i] for i in range(N)] ans = INF for magic in range(N): for i in range(N): if i - magic >= 0: cost[i] = min(cost[i], B[i - magic]) ans = min(ans, sum(cost) + x * magic) print(ans)
# coding:utf-8 import sys INF = float('inf') MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def main(): n, x = LI() A = LI() min_a, min_i = INF, -1 res = 0 for i, a in enumerate(A): if a < min_a: min_a = a min_i = i res += a A = A[min_i:] + A[:min_i] dp = [INF] + A for k in range(n - 1): tmp = 0 for i in range(n)[::-1]: if dp[i + 1] > dp[i]: dp[i + 1] = dp[i] tmp += dp[i + 1] res = min(res, tmp + (k + 1) * x) return res print((main()))
25
42
423
914
# coding:utf-8 INF = float("inf") def inpl(): return list(map(int, input().split())) N, x = inpl() A = inpl() min_index = A.index(min(A)) B = A[min_index:] + A[:min_index] cost = [B[i] for i in range(N)] ans = INF for magic in range(N): for i in range(N): if i - magic >= 0: cost[i] = min(cost[i], B[i - magic]) ans = min(ans, sum(cost) + x * magic) print(ans)
# coding:utf-8 import sys INF = float("inf") MOD = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def main(): n, x = LI() A = LI() min_a, min_i = INF, -1 res = 0 for i, a in enumerate(A): if a < min_a: min_a = a min_i = i res += a A = A[min_i:] + A[:min_i] dp = [INF] + A for k in range(n - 1): tmp = 0 for i in range(n)[::-1]: if dp[i + 1] > dp[i]: dp[i + 1] = dp[i] tmp += dp[i + 1] res = min(res, tmp + (k + 1) * x) return res print((main()))
false
40.47619
[ "+import sys", "+", "+MOD = 10**9 + 7", "-def inpl():", "- return list(map(int, input().split()))", "+def LI():", "+ return [int(x) for x in sys.stdin.readline().split()]", "-N, x = inpl()", "-A = inpl()", "-min_index = A.index(min(A))", "-B = A[min_index:] + A[:min_index]", "-cost = [B[i] for i in range(N)]", "-ans = INF", "-for magic in range(N):", "- for i in range(N):", "- if i - magic >= 0:", "- cost[i] = min(cost[i], B[i - magic])", "- ans = min(ans, sum(cost) + x * magic)", "-print(ans)", "+def LI_():", "+ return [int(x) - 1 for x in sys.stdin.readline().split()]", "+", "+", "+def LF():", "+ return [float(x) for x in sys.stdin.readline().split()]", "+", "+", "+def LS():", "+ return sys.stdin.readline().split()", "+", "+", "+def II():", "+ return int(sys.stdin.readline())", "+", "+", "+def SI():", "+ return eval(input())", "+", "+", "+def main():", "+ n, x = LI()", "+ A = LI()", "+ min_a, min_i = INF, -1", "+ res = 0", "+ for i, a in enumerate(A):", "+ if a < min_a:", "+ min_a = a", "+ min_i = i", "+ res += a", "+ A = A[min_i:] + A[:min_i]", "+ dp = [INF] + A", "+ for k in range(n - 1):", "+ tmp = 0", "+ for i in range(n)[::-1]:", "+ if dp[i + 1] > dp[i]:", "+ dp[i + 1] = dp[i]", "+ tmp += dp[i + 1]", "+ res = min(res, tmp + (k + 1) * x)", "+ return res", "+", "+", "+print((main()))" ]
false
0.046122
0.064231
0.718067
[ "s263393859", "s353931119" ]
u305366205
p03476
python
s227739020
s486967062
786
494
67,800
18,932
Accepted
Accepted
37.15
import math def is_prime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True q = int(eval(input())) scope = [tuple(map(int, input().split())) for _ in range(q)] prime_cnt = [0] * (10 ** 5 + 1) for i in range(1, 10 ** 5 + 1): prime_cnt[i] = prime_cnt[i - 1] if ((i + 1) / 2) % 1 == 0 and is_prime(i) and is_prime((i + 1) / 2): prime_cnt[i] += 1 for i in range(q): left = scope[i][0] right = scope[i][1] print((prime_cnt[right] - prime_cnt[left - 1]))
import math q = int(eval(input())) scope = [tuple(map(int, input().split())) for _ in range(q)] prime_flag = [True] * (10 ** 5 + 1) prime_flag[0] = False prime_flag[1] = False prime_cnt = [0] * (10 ** 5 + 1) for i in range(2, math.ceil(math.sqrt(10 ** 5))): for j in range(i + i, 10 ** 5 + 1, i): prime_flag[j] = False for i in range(2, 10 ** 5 + 1): prime_cnt[i] = prime_cnt[i - 1] num = (i + 1) / 2 if num % 1 == 0 and prime_flag[i] and prime_flag[int(num)]: prime_cnt[i] += 1 for i in range(q): left = scope[i][0] right = scope[i][1] print((prime_cnt[right] - prime_cnt[left - 1]))
26
23
599
646
import math def is_prime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True q = int(eval(input())) scope = [tuple(map(int, input().split())) for _ in range(q)] prime_cnt = [0] * (10**5 + 1) for i in range(1, 10**5 + 1): prime_cnt[i] = prime_cnt[i - 1] if ((i + 1) / 2) % 1 == 0 and is_prime(i) and is_prime((i + 1) / 2): prime_cnt[i] += 1 for i in range(q): left = scope[i][0] right = scope[i][1] print((prime_cnt[right] - prime_cnt[left - 1]))
import math q = int(eval(input())) scope = [tuple(map(int, input().split())) for _ in range(q)] prime_flag = [True] * (10**5 + 1) prime_flag[0] = False prime_flag[1] = False prime_cnt = [0] * (10**5 + 1) for i in range(2, math.ceil(math.sqrt(10**5))): for j in range(i + i, 10**5 + 1, i): prime_flag[j] = False for i in range(2, 10**5 + 1): prime_cnt[i] = prime_cnt[i - 1] num = (i + 1) / 2 if num % 1 == 0 and prime_flag[i] and prime_flag[int(num)]: prime_cnt[i] += 1 for i in range(q): left = scope[i][0] right = scope[i][1] print((prime_cnt[right] - prime_cnt[left - 1]))
false
11.538462
[ "-", "-", "-def is_prime(n):", "- if n == 1:", "- return False", "- for k in range(2, int(math.sqrt(n)) + 1):", "- if n % k == 0:", "- return False", "- return True", "-", "+prime_flag = [True] * (10**5 + 1)", "+prime_flag[0] = False", "+prime_flag[1] = False", "-for i in range(1, 10**5 + 1):", "+for i in range(2, math.ceil(math.sqrt(10**5))):", "+ for j in range(i + i, 10**5 + 1, i):", "+ prime_flag[j] = False", "+for i in range(2, 10**5 + 1):", "- if ((i + 1) / 2) % 1 == 0 and is_prime(i) and is_prime((i + 1) / 2):", "+ num = (i + 1) / 2", "+ if num % 1 == 0 and prime_flag[i] and prime_flag[int(num)]:" ]
false
0.713143
0.499538
1.427604
[ "s227739020", "s486967062" ]
u941753895
p03107
python
s062669178
s818060250
829
55
5,536
6,608
Accepted
Accepted
93.37
import queue q=queue.Queue() s=list(eval(input())) c=0 for i in s: if q.empty(): q.put(i) else: a=q.get() if a!=i: c+=2 else: q.put(a) q.put(i) print(c)
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) def main(): s=S() return min(s.count('0'),s.count('1'))*2 print((main()))
15
16
198
370
import queue q = queue.Queue() s = list(eval(input())) c = 0 for i in s: if q.empty(): q.put(i) else: a = q.get() if a != i: c += 2 else: q.put(a) q.put(i) print(c)
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) def main(): s = S() return min(s.count("0"), s.count("1")) * 2 print((main()))
false
6.25
[ "-import queue", "+import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time", "-q = queue.Queue()", "-s = list(eval(input()))", "-c = 0", "-for i in s:", "- if q.empty():", "- q.put(i)", "- else:", "- a = q.get()", "- if a != i:", "- c += 2", "- else:", "- q.put(a)", "- q.put(i)", "-print(c)", "+sys.setrecursionlimit(10**7)", "+inf = 10**20", "+mod = 10**9 + 7", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+def I():", "+ return int(eval(input()))", "+", "+", "+def LS():", "+ return input().split()", "+", "+", "+def S():", "+ return eval(input())", "+", "+", "+def main():", "+ s = S()", "+ return min(s.count(\"0\"), s.count(\"1\")) * 2", "+", "+", "+print((main()))" ]
false
0.100072
0.036698
2.726945
[ "s062669178", "s818060250" ]
u408262366
p02683
python
s487068123
s160174306
1,895
1,247
197,000
164,612
Accepted
Accepted
34.2
import numpy as np from itertools import combinations_with_replacement N,M,X = list(map(int,input().split())) CA = [] for i in range(N): CA.append(list(map(int,input().split()))) OK = True CA = np.array(CA) sums = np.sum(CA,axis=0) for i in range(1,M+1): if sums[i] < X: OK = False break if OK == False: print((-1)) else: # As = [] # for A in combinations_with_replacement(range(0, N), r=M): # As.append(tuple(set(A))) # As = list(map(list, set(As))) min_ = sums[0] hoge = [] kouho = list(range(1,N+1)) for i in combinations_with_replacement(kouho, N): hoge.append(list(set(i))) hoge = list(map(list, set(map(tuple, hoge)))) for i in hoge: mini_CA = [] for j in i: mini_CA.append(CA[j-1]) mini_CA = np.array(mini_CA) OK2 = True sums = np.sum(mini_CA,axis=0) for k in range(1,M+1): if sums[k] < X: OK2 = False break if OK2 == True and sums[0] < min_: min_ = sums[0] print(min_)
import numpy as np from itertools import combinations_with_replacement N,M,X = list(map(int,input().split())) CA = [] for i in range(N): CA.append(list(map(int,input().split()))) OK = True CA = np.array(CA) sums = np.sum(CA,axis=0) for i in range(1,M+1): if sums[i] < X: OK = False break if OK == False: print((-1)) else: As = [] for A in combinations_with_replacement(list(range(0, N)),N): As.append(tuple(set(A))) As = list(map(list, set(As))) min_ = sums[0] for i in As: mini_CA = [] for j in i: mini_CA.append(CA[j-1]) mini_CA = np.array(mini_CA) OK2 = True sums = np.sum(mini_CA,axis=0) for k in range(1,M+1): if sums[k] < X: OK2 = False break if OK2 == True and sums[0] < min_: min_ = sums[0] print(min_)
43
38
1,017
829
import numpy as np from itertools import combinations_with_replacement N, M, X = list(map(int, input().split())) CA = [] for i in range(N): CA.append(list(map(int, input().split()))) OK = True CA = np.array(CA) sums = np.sum(CA, axis=0) for i in range(1, M + 1): if sums[i] < X: OK = False break if OK == False: print((-1)) else: # As = [] # for A in combinations_with_replacement(range(0, N), r=M): # As.append(tuple(set(A))) # As = list(map(list, set(As))) min_ = sums[0] hoge = [] kouho = list(range(1, N + 1)) for i in combinations_with_replacement(kouho, N): hoge.append(list(set(i))) hoge = list(map(list, set(map(tuple, hoge)))) for i in hoge: mini_CA = [] for j in i: mini_CA.append(CA[j - 1]) mini_CA = np.array(mini_CA) OK2 = True sums = np.sum(mini_CA, axis=0) for k in range(1, M + 1): if sums[k] < X: OK2 = False break if OK2 == True and sums[0] < min_: min_ = sums[0] print(min_)
import numpy as np from itertools import combinations_with_replacement N, M, X = list(map(int, input().split())) CA = [] for i in range(N): CA.append(list(map(int, input().split()))) OK = True CA = np.array(CA) sums = np.sum(CA, axis=0) for i in range(1, M + 1): if sums[i] < X: OK = False break if OK == False: print((-1)) else: As = [] for A in combinations_with_replacement(list(range(0, N)), N): As.append(tuple(set(A))) As = list(map(list, set(As))) min_ = sums[0] for i in As: mini_CA = [] for j in i: mini_CA.append(CA[j - 1]) mini_CA = np.array(mini_CA) OK2 = True sums = np.sum(mini_CA, axis=0) for k in range(1, M + 1): if sums[k] < X: OK2 = False break if OK2 == True and sums[0] < min_: min_ = sums[0] print(min_)
false
11.627907
[ "- # As = []", "- # for A in combinations_with_replacement(range(0, N), r=M):", "- # As.append(tuple(set(A)))", "- # As = list(map(list, set(As)))", "+ As = []", "+ for A in combinations_with_replacement(list(range(0, N)), N):", "+ As.append(tuple(set(A)))", "+ As = list(map(list, set(As)))", "- hoge = []", "- kouho = list(range(1, N + 1))", "- for i in combinations_with_replacement(kouho, N):", "- hoge.append(list(set(i)))", "- hoge = list(map(list, set(map(tuple, hoge))))", "- for i in hoge:", "+ for i in As:" ]
false
0.2743
0.246801
1.111421
[ "s487068123", "s160174306" ]
u729008627
p03078
python
s860519474
s834445521
696
118
8,708
8,708
Accepted
Accepted
83.05
# solution 2 X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) L = [] for i in range(X): for j in range(Y): for k in range(Z): if (i+1)*(j+1)*(k+1) <= K: L.append(A[i]+B[j]+C[k]) else: break L.sort(reverse=True) for l in range(K): print((L[l]))
# solution 2 X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) L = [] for i in range(X): for j in range(Y): if (i+1)*(j+1) > K: break for k in range(Z): if (i+1)*(j+1)*(k+1) > K: break else: L.append(A[i] + B[j] + C[k]) L.sort(reverse=True) for l in range(K): print((L[l]))
19
21
492
543
# solution 2 X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) L = [] for i in range(X): for j in range(Y): for k in range(Z): if (i + 1) * (j + 1) * (k + 1) <= K: L.append(A[i] + B[j] + C[k]) else: break L.sort(reverse=True) for l in range(K): print((L[l]))
# solution 2 X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) L = [] for i in range(X): for j in range(Y): if (i + 1) * (j + 1) > K: break for k in range(Z): if (i + 1) * (j + 1) * (k + 1) > K: break else: L.append(A[i] + B[j] + C[k]) L.sort(reverse=True) for l in range(K): print((L[l]))
false
9.52381
[ "+ if (i + 1) * (j + 1) > K:", "+ break", "- if (i + 1) * (j + 1) * (k + 1) <= K:", "+ if (i + 1) * (j + 1) * (k + 1) > K:", "+ break", "+ else:", "- else:", "- break" ]
false
0.037485
0.037762
0.992683
[ "s860519474", "s834445521" ]
u794173881
p03221
python
s177789368
s967962598
1,437
906
103,896
85,080
Accepted
Accepted
36.95
from operator import itemgetter n,m = list(map(int,input().split())) p = [list(map(int,input().split())) for i in range(m)] b=[[i] for i in range(m)] for i in range(m): p[i].extend(b[i]) p = sorted(sorted(p, key=itemgetter(1))) old_p=0 for i in range(m): if p[i][0] != old_p : old_p = p[i][0] count = 1 else: count +=1 p[i][0] = "0"*(6-len(str(p[i][0])))+str(p[i][0])+"0"*(6-len(str(count)))+str(count) p = sorted(p, key=itemgetter(2)) for i in range(m): print((p[i][0]))
from operator import itemgetter n, m = list(map(int, input().split())) info = [list(map(int, input().split())) + [i] for i in range(m)] info = sorted(info, key=itemgetter(1)) ans = [0] * m cnt_ind = [1] * (n + 1) for i in range(m): p, y, ind = info[i] cnt = cnt_ind[p] cnt_ind[p] += 1 ans[ind] = ("0000000"+str(p))[-6:] + ("0000000"+str(cnt))[-6:] for i in ans: print(i)
26
17
522
404
from operator import itemgetter n, m = list(map(int, input().split())) p = [list(map(int, input().split())) for i in range(m)] b = [[i] for i in range(m)] for i in range(m): p[i].extend(b[i]) p = sorted(sorted(p, key=itemgetter(1))) old_p = 0 for i in range(m): if p[i][0] != old_p: old_p = p[i][0] count = 1 else: count += 1 p[i][0] = ( "0" * (6 - len(str(p[i][0]))) + str(p[i][0]) + "0" * (6 - len(str(count))) + str(count) ) p = sorted(p, key=itemgetter(2)) for i in range(m): print((p[i][0]))
from operator import itemgetter n, m = list(map(int, input().split())) info = [list(map(int, input().split())) + [i] for i in range(m)] info = sorted(info, key=itemgetter(1)) ans = [0] * m cnt_ind = [1] * (n + 1) for i in range(m): p, y, ind = info[i] cnt = cnt_ind[p] cnt_ind[p] += 1 ans[ind] = ("0000000" + str(p))[-6:] + ("0000000" + str(cnt))[-6:] for i in ans: print(i)
false
34.615385
[ "-p = [list(map(int, input().split())) for i in range(m)]", "-b = [[i] for i in range(m)]", "+info = [list(map(int, input().split())) + [i] for i in range(m)]", "+info = sorted(info, key=itemgetter(1))", "+ans = [0] * m", "+cnt_ind = [1] * (n + 1)", "- p[i].extend(b[i])", "-p = sorted(sorted(p, key=itemgetter(1)))", "-old_p = 0", "-for i in range(m):", "- if p[i][0] != old_p:", "- old_p = p[i][0]", "- count = 1", "- else:", "- count += 1", "- p[i][0] = (", "- \"0\" * (6 - len(str(p[i][0])))", "- + str(p[i][0])", "- + \"0\" * (6 - len(str(count)))", "- + str(count)", "- )", "-p = sorted(p, key=itemgetter(2))", "-for i in range(m):", "- print((p[i][0]))", "+ p, y, ind = info[i]", "+ cnt = cnt_ind[p]", "+ cnt_ind[p] += 1", "+ ans[ind] = (\"0000000\" + str(p))[-6:] + (\"0000000\" + str(cnt))[-6:]", "+for i in ans:", "+ print(i)" ]
false
0.03749
0.037729
0.993657
[ "s177789368", "s967962598" ]
u340781749
p03665
python
s175511801
s608445096
395
182
24,476
14,228
Accepted
Accepted
53.92
from collections import Counter from scipy.misc import comb n, p = list(map(int, input().split())) ac = Counter(int(x) & 1 for x in input().split()) ans = 0 for c in range(p, ac[1] + 1, 2): ans += comb(ac[1], c, exact=True) ans <<= ac[0] print(ans)
from collections import Counter from scipy.misc import comb n, p = list(map(int, input().split())) ac = Counter(int(x) & 1 for x in input().split()) print((sum(comb(ac[1], c, exact=True) for c in range(p, ac[1] + 1, 2)) << ac[0]))
14
6
265
229
from collections import Counter from scipy.misc import comb n, p = list(map(int, input().split())) ac = Counter(int(x) & 1 for x in input().split()) ans = 0 for c in range(p, ac[1] + 1, 2): ans += comb(ac[1], c, exact=True) ans <<= ac[0] print(ans)
from collections import Counter from scipy.misc import comb n, p = list(map(int, input().split())) ac = Counter(int(x) & 1 for x in input().split()) print((sum(comb(ac[1], c, exact=True) for c in range(p, ac[1] + 1, 2)) << ac[0]))
false
57.142857
[ "-ans = 0", "-for c in range(p, ac[1] + 1, 2):", "- ans += comb(ac[1], c, exact=True)", "-ans <<= ac[0]", "-print(ans)", "+print((sum(comb(ac[1], c, exact=True) for c in range(p, ac[1] + 1, 2)) << ac[0]))" ]
false
0.198015
0.227556
0.870181
[ "s175511801", "s608445096" ]
u488127128
p03607
python
s166660679
s483106591
95
68
19,172
13,196
Accepted
Accepted
28.42
import sys n,*A = sys.stdin B = set() for a in A: if int(a) in B: B.remove(int(a)) else: B.add(int(a)) print((len(B)))
import sys n,*A = list(map(int,sys.stdin)) B = set() for a in A: if a in B: B.remove(a) else: B.add(a) print((len(B)))
9
9
148
142
import sys n, *A = sys.stdin B = set() for a in A: if int(a) in B: B.remove(int(a)) else: B.add(int(a)) print((len(B)))
import sys n, *A = list(map(int, sys.stdin)) B = set() for a in A: if a in B: B.remove(a) else: B.add(a) print((len(B)))
false
0
[ "-n, *A = sys.stdin", "+n, *A = list(map(int, sys.stdin))", "- if int(a) in B:", "- B.remove(int(a))", "+ if a in B:", "+ B.remove(a)", "- B.add(int(a))", "+ B.add(a)" ]
false
0.04267
0.033601
1.269913
[ "s166660679", "s483106591" ]
u923668099
p02343
python
s726636909
s567175891
440
280
10,436
11,272
Accepted
Accepted
36.36
import sys def solve(): n, q = map(int, sys.stdin.readline().split()) uf = UnionFind(n) ans = [] for lp in range(q): c, x, y = map(int, sys.stdin.readline().split()) if c == 0: uf.unite(x, y) else: ans.append(1 if uf.is_same(x, y) else 0) print(*ans, sep='\n') class UnionFind: def __init__(self, n): self.ds = [i for i in range(n)] self.root = [i for i in range(n)] self.rank = [0] * n def find_root(self, x): if x != self.root[x]: self.root[x] = self.find_root(self.root[x]) return self.root[x] def is_same(self, x, y): return self.find_root(x) == self.find_root(y) def unite(self, x, y): p = self.find_root(x) q = self.find_root(y) if p == q: return None if self.rank[p] < self.rank[q]: self.root[p] = q elif self.rank[q] < self.rank[p]: self.root[q] = p else: self.root[q] = p self.rank[p] += 1 def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None if __name__ == '__main__': solve()
import sys def solve(): n, q = map(int, sys.stdin.readline().split()) ds = [[i] for i in range(n)] n2s = [i for i in range(n)] ans = [] for lp in range(q): c, x, y = map(int, sys.stdin.readline().split()) if c == 0: merge(ds, n2s, x, y) else: ans.append(1 if n2s[x] == n2s[y] else 0) print(*ans, sep='\n') def merge(ds, n2s, x, y): u = n2s[x] v = n2s[y] if u == v: return None if len(ds[u]) < len(ds[v]): ds[v].extend(ds[u]) for w in ds[u]: n2s[w] = v del ds[u][:] else: ds[u].extend(ds[v]) for w in ds[v]: n2s[w] = u del ds[v][:] def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None if __name__ == '__main__': solve()
57
44
1,333
966
import sys def solve(): n, q = map(int, sys.stdin.readline().split()) uf = UnionFind(n) ans = [] for lp in range(q): c, x, y = map(int, sys.stdin.readline().split()) if c == 0: uf.unite(x, y) else: ans.append(1 if uf.is_same(x, y) else 0) print(*ans, sep="\n") class UnionFind: def __init__(self, n): self.ds = [i for i in range(n)] self.root = [i for i in range(n)] self.rank = [0] * n def find_root(self, x): if x != self.root[x]: self.root[x] = self.find_root(self.root[x]) return self.root[x] def is_same(self, x, y): return self.find_root(x) == self.find_root(y) def unite(self, x, y): p = self.find_root(x) q = self.find_root(y) if p == q: return None if self.rank[p] < self.rank[q]: self.root[p] = q elif self.rank[q] < self.rank[p]: self.root[q] = p else: self.root[q] = p self.rank[p] += 1 def debug(x, table): for name, val in table.items(): if x is val: print("DEBUG:{} -> {}".format(name, val), file=sys.stderr) return None if __name__ == "__main__": solve()
import sys def solve(): n, q = map(int, sys.stdin.readline().split()) ds = [[i] for i in range(n)] n2s = [i for i in range(n)] ans = [] for lp in range(q): c, x, y = map(int, sys.stdin.readline().split()) if c == 0: merge(ds, n2s, x, y) else: ans.append(1 if n2s[x] == n2s[y] else 0) print(*ans, sep="\n") def merge(ds, n2s, x, y): u = n2s[x] v = n2s[y] if u == v: return None if len(ds[u]) < len(ds[v]): ds[v].extend(ds[u]) for w in ds[u]: n2s[w] = v del ds[u][:] else: ds[u].extend(ds[v]) for w in ds[v]: n2s[w] = u del ds[v][:] def debug(x, table): for name, val in table.items(): if x is val: print("DEBUG:{} -> {}".format(name, val), file=sys.stderr) return None if __name__ == "__main__": solve()
false
22.807018
[ "- uf = UnionFind(n)", "+ ds = [[i] for i in range(n)]", "+ n2s = [i for i in range(n)]", "- uf.unite(x, y)", "+ merge(ds, n2s, x, y)", "- ans.append(1 if uf.is_same(x, y) else 0)", "+ ans.append(1 if n2s[x] == n2s[y] else 0)", "-class UnionFind:", "- def __init__(self, n):", "- self.ds = [i for i in range(n)]", "- self.root = [i for i in range(n)]", "- self.rank = [0] * n", "-", "- def find_root(self, x):", "- if x != self.root[x]:", "- self.root[x] = self.find_root(self.root[x])", "- return self.root[x]", "-", "- def is_same(self, x, y):", "- return self.find_root(x) == self.find_root(y)", "-", "- def unite(self, x, y):", "- p = self.find_root(x)", "- q = self.find_root(y)", "- if p == q:", "- return None", "- if self.rank[p] < self.rank[q]:", "- self.root[p] = q", "- elif self.rank[q] < self.rank[p]:", "- self.root[q] = p", "- else:", "- self.root[q] = p", "- self.rank[p] += 1", "+def merge(ds, n2s, x, y):", "+ u = n2s[x]", "+ v = n2s[y]", "+ if u == v:", "+ return None", "+ if len(ds[u]) < len(ds[v]):", "+ ds[v].extend(ds[u])", "+ for w in ds[u]:", "+ n2s[w] = v", "+ del ds[u][:]", "+ else:", "+ ds[u].extend(ds[v])", "+ for w in ds[v]:", "+ n2s[w] = u", "+ del ds[v][:]" ]
false
0.044459
0.044621
0.996362
[ "s726636909", "s567175891" ]
u794544096
p02830
python
s602080963
s917175243
165
71
38,384
61,760
Accepted
Accepted
56.97
n = int(eval(input())) s, t = input().split() list = [] for i in range(n): list.append(s[i]) list.append(t[i]) print((''.join(list)))
n = int(eval(input())) s, t = input().split() list = [] for i in range(n): list += s[i] list += t[i] print((''.join(list)))
10
9
149
137
n = int(eval(input())) s, t = input().split() list = [] for i in range(n): list.append(s[i]) list.append(t[i]) print(("".join(list)))
n = int(eval(input())) s, t = input().split() list = [] for i in range(n): list += s[i] list += t[i] print(("".join(list)))
false
10
[ "- list.append(s[i])", "- list.append(t[i])", "+ list += s[i]", "+ list += t[i]" ]
false
0.00709
0.04054
0.174887
[ "s602080963", "s917175243" ]
u067095357
p02689
python
s527178229
s611147561
329
283
31,888
19,992
Accepted
Accepted
13.98
n, m = list(map(int, input().split())) hs = list(map(int, input().split())) ans = [1]*n roads = [] for i in range(m): roads += [list(map(int, input().split()))] for road in roads: if hs[road[0]-1] <= hs[road[1]-1]: ans[road[0]-1] = 0 if hs[road[0]-1] >= hs[road[1]-1]: ans[road[1]-1] = 0 print((ans.count(1)))
n, m = list(map(int, input().split())) hs = list(map(int, input().split())) ans = [1]*n for i in range(m): road = list(map(int, input().split())) if hs[road[0]-1] <= hs[road[1]-1]: ans[road[0]-1] = 0 if hs[road[0]-1] >= hs[road[1]-1]: ans[road[1]-1] = 0 print((ans.count(1)))
12
10
348
312
n, m = list(map(int, input().split())) hs = list(map(int, input().split())) ans = [1] * n roads = [] for i in range(m): roads += [list(map(int, input().split()))] for road in roads: if hs[road[0] - 1] <= hs[road[1] - 1]: ans[road[0] - 1] = 0 if hs[road[0] - 1] >= hs[road[1] - 1]: ans[road[1] - 1] = 0 print((ans.count(1)))
n, m = list(map(int, input().split())) hs = list(map(int, input().split())) ans = [1] * n for i in range(m): road = list(map(int, input().split())) if hs[road[0] - 1] <= hs[road[1] - 1]: ans[road[0] - 1] = 0 if hs[road[0] - 1] >= hs[road[1] - 1]: ans[road[1] - 1] = 0 print((ans.count(1)))
false
16.666667
[ "-roads = []", "- roads += [list(map(int, input().split()))]", "-for road in roads:", "+ road = list(map(int, input().split()))" ]
false
0.035999
0.036745
0.979688
[ "s527178229", "s611147561" ]
u143492911
p03455
python
s792408102
s532959443
20
17
3,316
3,064
Accepted
Accepted
15
a,b=list(map(int,input().split())) v=a*b print(("Even" if v%2==0 else "Odd"))
a,b=map(int,input().split()) print("Even") if a*b%2==0 else print("Odd")
3
2
72
74
a, b = list(map(int, input().split())) v = a * b print(("Even" if v % 2 == 0 else "Odd"))
a, b = map(int, input().split()) print("Even") if a * b % 2 == 0 else print("Odd")
false
33.333333
[ "-a, b = list(map(int, input().split()))", "-v = a * b", "-print((\"Even\" if v % 2 == 0 else \"Odd\"))", "+a, b = map(int, input().split())", "+print(\"Even\") if a * b % 2 == 0 else print(\"Odd\")" ]
false
0.038436
0.038767
0.991449
[ "s792408102", "s532959443" ]
u032662562
p00079
python
s360108076
s347269475
30
20
7,668
7,400
Accepted
Accepted
33.33
import math f = [] while True: try: st = input().strip().split(',') x,y = list(map(float,st )) f.append(x + y*1j) except EOFError: break px = [p.real for p in f] ox = (max(px) + min(px)) / 2.0 py = [p.imag for p in f] oy = (max(py) + min(py)) / 2.0 fo = ox + oy * 1j ss = 0.0 for i in range(len(f)): if i == len(f)-1: j = 0 else: j = i + 1 a = abs(f[i]-fo) b = abs(f[j]-fo) c = abs(f[j]-f[i]) z = (a + b + c) / 2.0 s = math.sqrt(z*(z-a)*(z-b)*(z-c)) ss += s print(("%.6f" % ss))
def cross(x, y): return (x.conjugate() * y).imag def area_polygon(points): area = 0 n = len(points) for i in range(n): area += cross(points[i], points[(i+1)%n]) return area / 2 import sys p = [] for line in sys.stdin: x, y = list(map(float, line.split(','))) p.append(complex(x, y)) print((abs(area_polygon(p))))
31
19
598
376
import math f = [] while True: try: st = input().strip().split(",") x, y = list(map(float, st)) f.append(x + y * 1j) except EOFError: break px = [p.real for p in f] ox = (max(px) + min(px)) / 2.0 py = [p.imag for p in f] oy = (max(py) + min(py)) / 2.0 fo = ox + oy * 1j ss = 0.0 for i in range(len(f)): if i == len(f) - 1: j = 0 else: j = i + 1 a = abs(f[i] - fo) b = abs(f[j] - fo) c = abs(f[j] - f[i]) z = (a + b + c) / 2.0 s = math.sqrt(z * (z - a) * (z - b) * (z - c)) ss += s print(("%.6f" % ss))
def cross(x, y): return (x.conjugate() * y).imag def area_polygon(points): area = 0 n = len(points) for i in range(n): area += cross(points[i], points[(i + 1) % n]) return area / 2 import sys p = [] for line in sys.stdin: x, y = list(map(float, line.split(","))) p.append(complex(x, y)) print((abs(area_polygon(p))))
false
38.709677
[ "-import math", "+def cross(x, y):", "+ return (x.conjugate() * y).imag", "-f = []", "-while True:", "- try:", "- st = input().strip().split(\",\")", "- x, y = list(map(float, st))", "- f.append(x + y * 1j)", "- except EOFError:", "- break", "-px = [p.real for p in f]", "-ox = (max(px) + min(px)) / 2.0", "-py = [p.imag for p in f]", "-oy = (max(py) + min(py)) / 2.0", "-fo = ox + oy * 1j", "-ss = 0.0", "-for i in range(len(f)):", "- if i == len(f) - 1:", "- j = 0", "- else:", "- j = i + 1", "- a = abs(f[i] - fo)", "- b = abs(f[j] - fo)", "- c = abs(f[j] - f[i])", "- z = (a + b + c) / 2.0", "- s = math.sqrt(z * (z - a) * (z - b) * (z - c))", "- ss += s", "-print((\"%.6f\" % ss))", "+", "+def area_polygon(points):", "+ area = 0", "+ n = len(points)", "+ for i in range(n):", "+ area += cross(points[i], points[(i + 1) % n])", "+ return area / 2", "+", "+", "+import sys", "+", "+p = []", "+for line in sys.stdin:", "+ x, y = list(map(float, line.split(\",\")))", "+ p.append(complex(x, y))", "+print((abs(area_polygon(p))))" ]
false
0.063893
0.043566
1.466584
[ "s360108076", "s347269475" ]
u498487134
p02838
python
s250604251
s049802616
647
386
122,808
118,728
Accepted
Accepted
40.34
N = int(eval(input())) A = list(map(int, input().split())) #Aiを二進数として,各けたを見れば良い?1の個数*0の個数 ans =0 mod =pow(10,9)+7 #Aiは最大で2^60-1 Max = 61 #i桁目を見る for i in range(Max): count = 0#その桁での1の数 for j in range(N): if(A[j]>>i & 1)==1: count+=1 ans+=count*(N-count)*pow(2,i) ans = ans%mod print(ans)
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N=I() M=65 A=LI() cnt=[0]*M for i in range(N): a=A[i] for j in range(M): if a>>j & 1: cnt[j]+=1 ans=0 for i in range(M): a=cnt[i] b=N-a ans=(ans + a*b*pow(2,i,mod))%mod print(ans) main()
20
30
341
554
N = int(eval(input())) A = list(map(int, input().split())) # Aiを二進数として,各けたを見れば良い?1の個数*0の個数 ans = 0 mod = pow(10, 9) + 7 # Aiは最大で2^60-1 Max = 61 # i桁目を見る for i in range(Max): count = 0 # その桁での1の数 for j in range(N): if (A[j] >> i & 1) == 1: count += 1 ans += count * (N - count) * pow(2, i) ans = ans % mod print(ans)
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod = 10**9 + 7 N = I() M = 65 A = LI() cnt = [0] * M for i in range(N): a = A[i] for j in range(M): if a >> j & 1: cnt[j] += 1 ans = 0 for i in range(M): a = cnt[i] b = N - a ans = (ans + a * b * pow(2, i, mod)) % mod print(ans) main()
false
33.333333
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-# Aiを二進数として,各けたを見れば良い?1の個数*0の個数", "-ans = 0", "-mod = pow(10, 9) + 7", "-# Aiは最大で2^60-1", "-Max = 61", "-# i桁目を見る", "-for i in range(Max):", "- count = 0 # その桁での1の数", "- for j in range(N):", "- if (A[j] >> i & 1) == 1:", "- count += 1", "- ans += count * (N - count) * pow(2, i)", "- ans = ans % mod", "-print(ans)", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def I():", "+ return int(eval(input()))", "+", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+def main():", "+ mod = 10**9 + 7", "+ N = I()", "+ M = 65", "+ A = LI()", "+ cnt = [0] * M", "+ for i in range(N):", "+ a = A[i]", "+ for j in range(M):", "+ if a >> j & 1:", "+ cnt[j] += 1", "+ ans = 0", "+ for i in range(M):", "+ a = cnt[i]", "+ b = N - a", "+ ans = (ans + a * b * pow(2, i, mod)) % mod", "+ print(ans)", "+", "+", "+main()" ]
false
0.035987
0.04205
0.855817
[ "s250604251", "s049802616" ]
u201928947
p02573
python
s253480961
s200687321
425
270
87,916
87,084
Accepted
Accepted
36.47
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) N,M = list(map(int,input().split())) uf = UnionFind(N) for i in range(M): A,B = list(map(int,input().split())) uf.union(A-1,B-1) ans = 0 for i in uf.roots(): ans = max(uf.size(i),ans) print(ans)
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) import sys input = sys.stdin.buffer.readline N,M = list(map(int,input().split())) uf = UnionFind(N) for i in range(M): A,B = list(map(int,input().split())) uf.union(A-1,B-1) ans = 0 for i in uf.roots(): ans = max(uf.size(i),ans) print(ans)
55
58
1,394
1,444
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) N, M = list(map(int, input().split())) uf = UnionFind(N) for i in range(M): A, B = list(map(int, input().split())) uf.union(A - 1, B - 1) ans = 0 for i in uf.roots(): ans = max(uf.size(i), ans) print(ans)
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) import sys input = sys.stdin.buffer.readline N, M = list(map(int, input().split())) uf = UnionFind(N) for i in range(M): A, B = list(map(int, input().split())) uf.union(A - 1, B - 1) ans = 0 for i in uf.roots(): ans = max(uf.size(i), ans) print(ans)
false
5.172414
[ "+import sys", "+", "+input = sys.stdin.buffer.readline" ]
false
0.044306
0.04019
1.10241
[ "s253480961", "s200687321" ]
u790710233
p03361
python
s314975433
s735341028
21
19
3,064
3,064
Accepted
Accepted
9.52
h, w = list(map(int, input().split())) m = [list(eval(input())) for _ in range(h)] for i in range(h): for j in range(w): if m[i][j] == '#': cnt = sum([0 <= i-1, i+1 < h, 0 <= j-1, j+1 < w]) # up if 0 <= i-1: if m[i-1][j] != '#': cnt -= 1 # down if i+1 < h: if m[i+1][j] != '#': cnt -= 1 # left if 0 <= j-1: if m[i][j-1] != '#': cnt -= 1 # right if j+1 < w: if m[i][j+1] != '#': cnt -= 1 if cnt == 0: print('No') exit(0) else: print('Yes')
h, w = list(map(int, input().split())) m = [['.']*(w+2)] for _ in range(h): m.append(list('.' + eval(input()) + '.')) m.append(['.']*(w+2)) for i in range(1, h+1): for j in range(1, w+1): if m[i][j] == '#': if all(m[i+x][j+y] == '.' for x, y in [(-1, 0), (1, 0), (0, -1), (0, 1)]): print('No') exit(0) else: print('Yes')
32
14
775
386
h, w = list(map(int, input().split())) m = [list(eval(input())) for _ in range(h)] for i in range(h): for j in range(w): if m[i][j] == "#": cnt = sum([0 <= i - 1, i + 1 < h, 0 <= j - 1, j + 1 < w]) # up if 0 <= i - 1: if m[i - 1][j] != "#": cnt -= 1 # down if i + 1 < h: if m[i + 1][j] != "#": cnt -= 1 # left if 0 <= j - 1: if m[i][j - 1] != "#": cnt -= 1 # right if j + 1 < w: if m[i][j + 1] != "#": cnt -= 1 if cnt == 0: print("No") exit(0) else: print("Yes")
h, w = list(map(int, input().split())) m = [["."] * (w + 2)] for _ in range(h): m.append(list("." + eval(input()) + ".")) m.append(["."] * (w + 2)) for i in range(1, h + 1): for j in range(1, w + 1): if m[i][j] == "#": if all( m[i + x][j + y] == "." for x, y in [(-1, 0), (1, 0), (0, -1), (0, 1)] ): print("No") exit(0) else: print("Yes")
false
56.25
[ "-m = [list(eval(input())) for _ in range(h)]", "-for i in range(h):", "- for j in range(w):", "+m = [[\".\"] * (w + 2)]", "+for _ in range(h):", "+ m.append(list(\".\" + eval(input()) + \".\"))", "+m.append([\".\"] * (w + 2))", "+for i in range(1, h + 1):", "+ for j in range(1, w + 1):", "- cnt = sum([0 <= i - 1, i + 1 < h, 0 <= j - 1, j + 1 < w])", "- # up", "- if 0 <= i - 1:", "- if m[i - 1][j] != \"#\":", "- cnt -= 1", "- # down", "- if i + 1 < h:", "- if m[i + 1][j] != \"#\":", "- cnt -= 1", "- # left", "- if 0 <= j - 1:", "- if m[i][j - 1] != \"#\":", "- cnt -= 1", "- # right", "- if j + 1 < w:", "- if m[i][j + 1] != \"#\":", "- cnt -= 1", "- if cnt == 0:", "+ if all(", "+ m[i + x][j + y] == \".\" for x, y in [(-1, 0), (1, 0), (0, -1), (0, 1)]", "+ ):" ]
false
0.040123
0.045299
0.885733
[ "s314975433", "s735341028" ]
u909643606
p03074
python
s906554206
s873093536
199
53
45,676
4,396
Accepted
Accepted
73.37
import sys input = sys.stdin.readline def main(): n, k = [int(i) for i in input().split()] s = eval(input()) + "3" s0 = [] s1 = [] cnt = 0 start = 1 for i in range(n+1): if start == 1 and s[i] != "1": s1.append(cnt) cnt = 1 start = 0 elif start == 0 and s[i] != "0": s0.append(cnt) cnt = 1 start = 1 else: cnt += 1 #ans = max(s1) #for i in range(n // 2 +1): # ans = max(ans, sum(s1[i:i+k+1]) + sum(s0[i:i+k])) ans = sum(s1[0:0+k+1]) + sum(s0[0:0+k]) n_ans = ans for i in range(n): try: n_ans = n_ans + s1[k+1+i] + s0[k+i] - s1[i] - s0[i] ans = max(ans, n_ans) except: try: n_ans = n_ans + s0[k+i] - s1[i] - s0[i] ans = max(ans, n_ans) except: pass print(ans) #print(s1, s0) main()
def main(): n, k = [int(i) for i in input().split()] s = eval(input()) + "3" s0 = [] s1 = [] cnt = 0 start = 1 for i in range(n+1): if start == 1 and s[i] != "1": s1.append(cnt) cnt = 1 start = 0 elif start == 0 and s[i] != "0": s0.append(cnt) cnt = 1 start = 1 else: cnt += 1 if len(s0) == len(s1): s1.append(0) ans = sum(s1[0:0+k+1]) + sum(s0[0:0+k]) n_ans = ans for i in range(len(s0) - k): n_ans = n_ans + s1[k+1+i] + s0[k+i] - s1[i] - s0[i] ans = max(ans, n_ans) print(ans) main()
44
30
1,006
699
import sys input = sys.stdin.readline def main(): n, k = [int(i) for i in input().split()] s = eval(input()) + "3" s0 = [] s1 = [] cnt = 0 start = 1 for i in range(n + 1): if start == 1 and s[i] != "1": s1.append(cnt) cnt = 1 start = 0 elif start == 0 and s[i] != "0": s0.append(cnt) cnt = 1 start = 1 else: cnt += 1 # ans = max(s1) # for i in range(n // 2 +1): # ans = max(ans, sum(s1[i:i+k+1]) + sum(s0[i:i+k])) ans = sum(s1[0 : 0 + k + 1]) + sum(s0[0 : 0 + k]) n_ans = ans for i in range(n): try: n_ans = n_ans + s1[k + 1 + i] + s0[k + i] - s1[i] - s0[i] ans = max(ans, n_ans) except: try: n_ans = n_ans + s0[k + i] - s1[i] - s0[i] ans = max(ans, n_ans) except: pass print(ans) # print(s1, s0) main()
def main(): n, k = [int(i) for i in input().split()] s = eval(input()) + "3" s0 = [] s1 = [] cnt = 0 start = 1 for i in range(n + 1): if start == 1 and s[i] != "1": s1.append(cnt) cnt = 1 start = 0 elif start == 0 and s[i] != "0": s0.append(cnt) cnt = 1 start = 1 else: cnt += 1 if len(s0) == len(s1): s1.append(0) ans = sum(s1[0 : 0 + k + 1]) + sum(s0[0 : 0 + k]) n_ans = ans for i in range(len(s0) - k): n_ans = n_ans + s1[k + 1 + i] + s0[k + i] - s1[i] - s0[i] ans = max(ans, n_ans) print(ans) main()
false
31.818182
[ "-import sys", "-", "-input = sys.stdin.readline", "-", "-", "- # ans = max(s1)", "- # for i in range(n // 2 +1):", "- # ans = max(ans, sum(s1[i:i+k+1]) + sum(s0[i:i+k]))", "+ if len(s0) == len(s1):", "+ s1.append(0)", "- for i in range(n):", "- try:", "- n_ans = n_ans + s1[k + 1 + i] + s0[k + i] - s1[i] - s0[i]", "- ans = max(ans, n_ans)", "- except:", "- try:", "- n_ans = n_ans + s0[k + i] - s1[i] - s0[i]", "- ans = max(ans, n_ans)", "- except:", "- pass", "+ for i in range(len(s0) - k):", "+ n_ans = n_ans + s1[k + 1 + i] + s0[k + i] - s1[i] - s0[i]", "+ ans = max(ans, n_ans)", "- # print(s1, s0)" ]
false
0.080365
0.057029
1.409191
[ "s906554206", "s873093536" ]
u282228874
p03087
python
s328235333
s516509398
1,058
859
55,512
8,072
Accepted
Accepted
18.81
n,q = list(map(int,input().split())) S = eval(input()) s = [0]*(n+1) for i in range(1,n): if S[i-1] == 'A' and S[i] == 'C': s[i] = 1 for i in range(1,n): s[i] += s[i-1] for i in range(q): l,r = [int(j)-1 for j in input().split()] print((s[r]-s[l]))
n,q = list(map(int,input().split())) S = eval(input()) b = [0]*(n+1) for i in range(n-1): if S[i] == 'A' and S[i+1] == 'C': b[i+1] += 1 from itertools import accumulate b = list(accumulate(b)) #print(b) for i in range(q): l,r = list(map(int,input().split())) print((b[r-1]-b[l-1]))
11
12
252
291
n, q = list(map(int, input().split())) S = eval(input()) s = [0] * (n + 1) for i in range(1, n): if S[i - 1] == "A" and S[i] == "C": s[i] = 1 for i in range(1, n): s[i] += s[i - 1] for i in range(q): l, r = [int(j) - 1 for j in input().split()] print((s[r] - s[l]))
n, q = list(map(int, input().split())) S = eval(input()) b = [0] * (n + 1) for i in range(n - 1): if S[i] == "A" and S[i + 1] == "C": b[i + 1] += 1 from itertools import accumulate b = list(accumulate(b)) # print(b) for i in range(q): l, r = list(map(int, input().split())) print((b[r - 1] - b[l - 1]))
false
8.333333
[ "-s = [0] * (n + 1)", "-for i in range(1, n):", "- if S[i - 1] == \"A\" and S[i] == \"C\":", "- s[i] = 1", "-for i in range(1, n):", "- s[i] += s[i - 1]", "+b = [0] * (n + 1)", "+for i in range(n - 1):", "+ if S[i] == \"A\" and S[i + 1] == \"C\":", "+ b[i + 1] += 1", "+from itertools import accumulate", "+", "+b = list(accumulate(b))", "+# print(b)", "- l, r = [int(j) - 1 for j in input().split()]", "- print((s[r] - s[l]))", "+ l, r = list(map(int, input().split()))", "+ print((b[r - 1] - b[l - 1]))" ]
false
0.043725
0.083671
0.522591
[ "s328235333", "s516509398" ]
u112364985
p03073
python
s690539223
s891813378
63
53
10,496
9,696
Accepted
Accepted
15.87
s=list(eval(input())) s=[int(s[i]) for i in range(len(s))] tile=s[0] cnt=0 for i in range(1,len(s)): if s[i]==tile: cnt+=1 if tile==1: tile=0 else: tile=1 print(cnt)
s=list(eval(input())) a=["0","1"] cnt=0 for i in range(len(s)): if s[i]!=a[i%2]: cnt+=1 print((min(cnt,len(s)-cnt)))
12
7
206
126
s = list(eval(input())) s = [int(s[i]) for i in range(len(s))] tile = s[0] cnt = 0 for i in range(1, len(s)): if s[i] == tile: cnt += 1 if tile == 1: tile = 0 else: tile = 1 print(cnt)
s = list(eval(input())) a = ["0", "1"] cnt = 0 for i in range(len(s)): if s[i] != a[i % 2]: cnt += 1 print((min(cnt, len(s) - cnt)))
false
41.666667
[ "-s = [int(s[i]) for i in range(len(s))]", "-tile = s[0]", "+a = [\"0\", \"1\"]", "-for i in range(1, len(s)):", "- if s[i] == tile:", "+for i in range(len(s)):", "+ if s[i] != a[i % 2]:", "- if tile == 1:", "- tile = 0", "- else:", "- tile = 1", "-print(cnt)", "+print((min(cnt, len(s) - cnt)))" ]
false
0.038395
0.045027
0.852708
[ "s690539223", "s891813378" ]
u968166680
p02913
python
s048065493
s725097712
751
464
270,220
270,088
Accepted
Accepted
38.22
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) S = readline().strip() dp = [[0] * (N + 1) for _ in range(N + 1)] for i in range(N - 1, -1, -1): for j in range(N - 1, -1, -1): if S[i] == S[j]: dp[i][j] = dp[i + 1][j + 1] + 1 ans = 0 for i in range(N): for j in range(N): if ans < min(dp[i][j], j - i): ans = min(dp[i][j], j - i) print(ans) return if __name__ == '__main__': main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) S = readline().strip() dp = [[0] * (N + 1) for _ in range(N + 1)] for i in range(N - 1, -1, -1): for j in range(N - 1, i, -1): if S[i] == S[j]: dp[i][j] = dp[i + 1][j + 1] + 1 ans = 0 for i in range(N): for j in range(i + 1, N): if ans < min(dp[i][j], j - i): ans = min(dp[i][j], j - i) print(ans) return if __name__ == '__main__': main()
32
32
669
675
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) S = readline().strip() dp = [[0] * (N + 1) for _ in range(N + 1)] for i in range(N - 1, -1, -1): for j in range(N - 1, -1, -1): if S[i] == S[j]: dp[i][j] = dp[i + 1][j + 1] + 1 ans = 0 for i in range(N): for j in range(N): if ans < min(dp[i][j], j - i): ans = min(dp[i][j], j - i) print(ans) return if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) S = readline().strip() dp = [[0] * (N + 1) for _ in range(N + 1)] for i in range(N - 1, -1, -1): for j in range(N - 1, i, -1): if S[i] == S[j]: dp[i][j] = dp[i + 1][j + 1] + 1 ans = 0 for i in range(N): for j in range(i + 1, N): if ans < min(dp[i][j], j - i): ans = min(dp[i][j], j - i) print(ans) return if __name__ == "__main__": main()
false
0
[ "- for j in range(N - 1, -1, -1):", "+ for j in range(N - 1, i, -1):", "- for j in range(N):", "+ for j in range(i + 1, N):" ]
false
0.054232
0.034365
1.578102
[ "s048065493", "s725097712" ]
u150984829
p02264
python
s740116948
s870687982
250
200
18,124
16,940
Accepted
Accepted
20
import sys from collections import deque s=sys.stdin.readlines() q=int(s[0].split()[1]) d=deque(list(e.split())for e in s[1:]) t=0 while d: k,v=d.popleft();v=int(v) if v>q:v-=q;t+=q;d.append([k,v]) else:t+=v;print((k,t))
import sys from collections import deque s=sys.stdin.readlines() q=int(s[0].split()[1]) f=lambda x,y:(x,int(y)) d=deque(f(*e.split())for e in s[1:]) t,a=0,[] while d: k,v=d.popleft() if v>q:v-=q;t+=q;d.append([k,v]) else:t+=v;a+=[f'{k} {t}'] print(*a,sep='\n')
10
12
231
275
import sys from collections import deque s = sys.stdin.readlines() q = int(s[0].split()[1]) d = deque(list(e.split()) for e in s[1:]) t = 0 while d: k, v = d.popleft() v = int(v) if v > q: v -= q t += q d.append([k, v]) else: t += v print((k, t))
import sys from collections import deque s = sys.stdin.readlines() q = int(s[0].split()[1]) f = lambda x, y: (x, int(y)) d = deque(f(*e.split()) for e in s[1:]) t, a = 0, [] while d: k, v = d.popleft() if v > q: v -= q t += q d.append([k, v]) else: t += v a += [f"{k} {t}"] print(*a, sep="\n")
false
16.666667
[ "-d = deque(list(e.split()) for e in s[1:])", "-t = 0", "+f = lambda x, y: (x, int(y))", "+d = deque(f(*e.split()) for e in s[1:])", "+t, a = 0, []", "- v = int(v)", "- print((k, t))", "+ a += [f\"{k} {t}\"]", "+print(*a, sep=\"\\n\")" ]
false
0.03734
0.036971
1.009986
[ "s740116948", "s870687982" ]
u562016607
p03293
python
s598902838
s748252965
169
18
38,256
2,940
Accepted
Accepted
89.35
S=eval(input()) T=eval(input()) N=len(S) for i in range(N): U=T[i:]+T[:i] if S==U: print("Yes") exit() print("No")
# coding: utf-8 S = eval(input()) T = eval(input()) for i in range(100): Scheck=S[i+1:]+S[0:i+1] if(Scheck==T): print("Yes") exit() print("No")
9
9
123
164
S = eval(input()) T = eval(input()) N = len(S) for i in range(N): U = T[i:] + T[:i] if S == U: print("Yes") exit() print("No")
# coding: utf-8 S = eval(input()) T = eval(input()) for i in range(100): Scheck = S[i + 1 :] + S[0 : i + 1] if Scheck == T: print("Yes") exit() print("No")
false
0
[ "+# coding: utf-8", "-N = len(S)", "-for i in range(N):", "- U = T[i:] + T[:i]", "- if S == U:", "+for i in range(100):", "+ Scheck = S[i + 1 :] + S[0 : i + 1]", "+ if Scheck == T:" ]
false
0.099242
0.031991
3.102178
[ "s598902838", "s748252965" ]
u073852194
p02815
python
s975666214
s294324966
991
689
26,800
26,800
Accepted
Accepted
30.47
MOD = 1000000007 N = int(eval(input())) C = list(map(int,input().split())) C.sort(reverse=True) ans = 0 if N > 1: for i in range(N): ans += C[i]*(2+i)*pow(2,N-2,MOD)*pow(2,N,MOD) ans %= MOD else: ans = 2*C[0]%MOD print(ans)
MOD = 1000000007 N = int(eval(input())) C = list(map(int,input().split())) C.sort(reverse=True) ans = 0 for i in range(N): ans += C[i]*(2+i)*pow(4,N-1,MOD) ans %= MOD print(ans)
17
14
262
197
MOD = 1000000007 N = int(eval(input())) C = list(map(int, input().split())) C.sort(reverse=True) ans = 0 if N > 1: for i in range(N): ans += C[i] * (2 + i) * pow(2, N - 2, MOD) * pow(2, N, MOD) ans %= MOD else: ans = 2 * C[0] % MOD print(ans)
MOD = 1000000007 N = int(eval(input())) C = list(map(int, input().split())) C.sort(reverse=True) ans = 0 for i in range(N): ans += C[i] * (2 + i) * pow(4, N - 1, MOD) ans %= MOD print(ans)
false
17.647059
[ "-if N > 1:", "- for i in range(N):", "- ans += C[i] * (2 + i) * pow(2, N - 2, MOD) * pow(2, N, MOD)", "- ans %= MOD", "-else:", "- ans = 2 * C[0] % MOD", "+for i in range(N):", "+ ans += C[i] * (2 + i) * pow(4, N - 1, MOD)", "+ ans %= MOD" ]
false
0.164721
0.034264
4.807354
[ "s975666214", "s294324966" ]
u380524497
p03013
python
s364792419
s240061172
469
66
460,020
11,884
Accepted
Accepted
85.93
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) broken = set() for i in range(m): a = int(eval(input())) broken.add(a) pattern = [0]*(n+1) pattern[0] = 1 if 1 in broken: pattern[1] = 0 else: pattern[1] = 1 for i in range(2, n+1): if i in broken: pattern[i] = 0 else: pattern[i] = pattern[i-1] + pattern[i-2] print((pattern[n] % (10**9+7)))
import sys input = sys.stdin.readline mod = 10**9+7 n, m = list(map(int, input().split())) broken = set(int(eval(input())) for i in range(m)) pattern = [0]*(n+1) pattern[0] = 1 if 1 in broken: pattern[1] = 0 else: pattern[1] = 1 for i in range(2, n+1): if i in broken: continue else: pattern[i] = (pattern[i-1] + pattern[i-2]) % mod print((pattern[n]))
25
21
425
395
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) broken = set() for i in range(m): a = int(eval(input())) broken.add(a) pattern = [0] * (n + 1) pattern[0] = 1 if 1 in broken: pattern[1] = 0 else: pattern[1] = 1 for i in range(2, n + 1): if i in broken: pattern[i] = 0 else: pattern[i] = pattern[i - 1] + pattern[i - 2] print((pattern[n] % (10**9 + 7)))
import sys input = sys.stdin.readline mod = 10**9 + 7 n, m = list(map(int, input().split())) broken = set(int(eval(input())) for i in range(m)) pattern = [0] * (n + 1) pattern[0] = 1 if 1 in broken: pattern[1] = 0 else: pattern[1] = 1 for i in range(2, n + 1): if i in broken: continue else: pattern[i] = (pattern[i - 1] + pattern[i - 2]) % mod print((pattern[n]))
false
16
[ "+mod = 10**9 + 7", "-broken = set()", "-for i in range(m):", "- a = int(eval(input()))", "- broken.add(a)", "+broken = set(int(eval(input())) for i in range(m))", "- pattern[i] = 0", "+ continue", "- pattern[i] = pattern[i - 1] + pattern[i - 2]", "-print((pattern[n] % (10**9 + 7)))", "+ pattern[i] = (pattern[i - 1] + pattern[i - 2]) % mod", "+print((pattern[n]))" ]
false
0.036008
0.034493
1.043922
[ "s364792419", "s240061172" ]
u776402923
p02275
python
s804670011
s676238156
2,270
1,980
241,480
241,484
Accepted
Accepted
12.78
def CountingSort(A, k): C = [0] * (k+1) n = len(A) for a in A: C[a] = C[a] + 1 for i in range(1, k+1): C[i] = C[i] + C[i-1] B = [0] * n for j in range(n-1, -1, -1): rank = C[ A[j] ] B[ rank - 1] = A[j] C[ A[j] ] = C[ A[j] ] - 1 return B n = int(eval(input())) A = [int(i) for i in input().split()] ans = CountingSort(A, 10000) print((' '.join([str(i) for i in ans])))
def CountingSort(A, k): C = [0] * (k+1) n = len(A) for a in A: C[a] = C[a] + 1 for i in range(1, k+1): C[i] = C[i] + C[i-1] B = [0] * n for a in A: rank = C[a] B[rank - 1] = a C[a] = C[a] - 1 return B n = int(eval(input())) A = [int(i) for i in input().split()] ans = CountingSort(A, 10000) print((' '.join([str(i) for i in ans])))
28
28
483
447
def CountingSort(A, k): C = [0] * (k + 1) n = len(A) for a in A: C[a] = C[a] + 1 for i in range(1, k + 1): C[i] = C[i] + C[i - 1] B = [0] * n for j in range(n - 1, -1, -1): rank = C[A[j]] B[rank - 1] = A[j] C[A[j]] = C[A[j]] - 1 return B n = int(eval(input())) A = [int(i) for i in input().split()] ans = CountingSort(A, 10000) print((" ".join([str(i) for i in ans])))
def CountingSort(A, k): C = [0] * (k + 1) n = len(A) for a in A: C[a] = C[a] + 1 for i in range(1, k + 1): C[i] = C[i] + C[i - 1] B = [0] * n for a in A: rank = C[a] B[rank - 1] = a C[a] = C[a] - 1 return B n = int(eval(input())) A = [int(i) for i in input().split()] ans = CountingSort(A, 10000) print((" ".join([str(i) for i in ans])))
false
0
[ "- for j in range(n - 1, -1, -1):", "- rank = C[A[j]]", "- B[rank - 1] = A[j]", "- C[A[j]] = C[A[j]] - 1", "+ for a in A:", "+ rank = C[a]", "+ B[rank - 1] = a", "+ C[a] = C[a] - 1" ]
false
0.045347
0.043618
1.039625
[ "s804670011", "s676238156" ]
u223646582
p03330
python
s838019242
s541506036
593
188
45,148
71,308
Accepted
Accepted
68.3
from collections import defaultdict N, C = list(map(int, input().split())) D = [tuple(map(int, input().split())) for _ in range(C)] d = [defaultdict(int) for i in range(3)] for i in range(N): c = [int(x) for x in input().split()] for j in range(N): for k in range(C): d[(i+j) % 3][k] += D[c[j]-1][k] # print(d) ans = 10**9 for i in range(C): for j in range(C): for k in range(C): if i != j and j != k and k != i: ans = min(ans, d[0][i]+d[1][j]+d[2][k]) print(ans)
from collections import defaultdict N, C = list(map(int, input().split())) D = [[int(i) for i in input().split()] for _ in range(C)] color = [[int(i) for i in input().split()] for _ in range(N)] M = [defaultdict(int) for _ in range(3)] for i in range(N): for j in range(N): M[(i+j) % 3][color[i][j]] += 1 ans = 10**20 for Y0 in range(C): for Y1 in range(C): for Y2 in range(C): if Y0 != Y1 and Y1 != Y2 and Y2 != Y0: Y = (Y0, Y1, Y2) d = 0 for i in range(3): for X, v in list(M[i].items()): d += D[X-1][Y[i]]*v ans = min(ans, d) print(ans)
23
22
554
695
from collections import defaultdict N, C = list(map(int, input().split())) D = [tuple(map(int, input().split())) for _ in range(C)] d = [defaultdict(int) for i in range(3)] for i in range(N): c = [int(x) for x in input().split()] for j in range(N): for k in range(C): d[(i + j) % 3][k] += D[c[j] - 1][k] # print(d) ans = 10**9 for i in range(C): for j in range(C): for k in range(C): if i != j and j != k and k != i: ans = min(ans, d[0][i] + d[1][j] + d[2][k]) print(ans)
from collections import defaultdict N, C = list(map(int, input().split())) D = [[int(i) for i in input().split()] for _ in range(C)] color = [[int(i) for i in input().split()] for _ in range(N)] M = [defaultdict(int) for _ in range(3)] for i in range(N): for j in range(N): M[(i + j) % 3][color[i][j]] += 1 ans = 10**20 for Y0 in range(C): for Y1 in range(C): for Y2 in range(C): if Y0 != Y1 and Y1 != Y2 and Y2 != Y0: Y = (Y0, Y1, Y2) d = 0 for i in range(3): for X, v in list(M[i].items()): d += D[X - 1][Y[i]] * v ans = min(ans, d) print(ans)
false
4.347826
[ "-D = [tuple(map(int, input().split())) for _ in range(C)]", "-d = [defaultdict(int) for i in range(3)]", "+D = [[int(i) for i in input().split()] for _ in range(C)]", "+color = [[int(i) for i in input().split()] for _ in range(N)]", "+M = [defaultdict(int) for _ in range(3)]", "- c = [int(x) for x in input().split()]", "- for k in range(C):", "- d[(i + j) % 3][k] += D[c[j] - 1][k]", "-# print(d)", "-ans = 10**9", "-for i in range(C):", "- for j in range(C):", "- for k in range(C):", "- if i != j and j != k and k != i:", "- ans = min(ans, d[0][i] + d[1][j] + d[2][k])", "+ M[(i + j) % 3][color[i][j]] += 1", "+ans = 10**20", "+for Y0 in range(C):", "+ for Y1 in range(C):", "+ for Y2 in range(C):", "+ if Y0 != Y1 and Y1 != Y2 and Y2 != Y0:", "+ Y = (Y0, Y1, Y2)", "+ d = 0", "+ for i in range(3):", "+ for X, v in list(M[i].items()):", "+ d += D[X - 1][Y[i]] * v", "+ ans = min(ans, d)" ]
false
0.063368
0.061876
1.024121
[ "s838019242", "s541506036" ]
u479462609
p02830
python
s661209948
s053212878
19
17
2,940
3,064
Accepted
Accepted
10.53
N=int(eval(input())) S,T=(x for x in input().split()) alist=[] for i in range(N): alist.append(S[i]) alist.append(T[i]) o="".join(alist) print(o)
N=int(eval(input())) S,T=input().split() l=[] for i in range(N): l.append(S[i]) l.append(T[i]) o="".join(l) print(o)
10
8
154
121
N = int(eval(input())) S, T = (x for x in input().split()) alist = [] for i in range(N): alist.append(S[i]) alist.append(T[i]) o = "".join(alist) print(o)
N = int(eval(input())) S, T = input().split() l = [] for i in range(N): l.append(S[i]) l.append(T[i]) o = "".join(l) print(o)
false
20
[ "-S, T = (x for x in input().split())", "-alist = []", "+S, T = input().split()", "+l = []", "- alist.append(S[i])", "- alist.append(T[i])", "-o = \"\".join(alist)", "+ l.append(S[i])", "+ l.append(T[i])", "+o = \"\".join(l)" ]
false
0.043715
0.041751
1.047053
[ "s661209948", "s053212878" ]
u141610915
p02850
python
s240055817
s058653952
1,242
900
137,692
118,180
Accepted
Accepted
27.54
import sys sys.setrecursionlimit(10 ** 7) from collections import defaultdict as dd input = sys.stdin.readline N = int(eval(input())) e = dd(list) for i in range(N - 1): a, b = tuple(map(int, input().split())) e[a].append((b, i)) e[b].append((a, i)) res = [0] * (N - 1) vis = set() def dfs(x): global vis global res viss = set() svis = set() t = 1 for y, i in e[x]: if i in vis: viss.add(res[i]) #print(x, viss) for y, i in e[x]: #print(x, y, t) while t in viss: t += 1 if i in vis: continue #print(x, y, t) svis.add(y) vis.add(i) res[i] = t t += 1 dfs(y) #print(res) dfs(1) print((max(res))) for r in res: print(r)
import sys from collections import defaultdict as dd input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) N = int(eval(input())) e = dd(list) for i in range(N - 1): u, v = list(map(int, input().split())) e[u].append((v, i)) e[v].append((u, i)) res = [0] * (N - 1) def dfs(x): global res c = 1 vis = set() for y, i in e[x]: vis.add(res[i]) #print(x, vis) for y, i in e[x]: if res[i] > 0: continue while c in vis: c += 1 #print(x, c) res[i] = c vis.add(c) dfs(y) dfs(1) print((max(res))) for r in res: print(r)
37
27
719
567
import sys sys.setrecursionlimit(10**7) from collections import defaultdict as dd input = sys.stdin.readline N = int(eval(input())) e = dd(list) for i in range(N - 1): a, b = tuple(map(int, input().split())) e[a].append((b, i)) e[b].append((a, i)) res = [0] * (N - 1) vis = set() def dfs(x): global vis global res viss = set() svis = set() t = 1 for y, i in e[x]: if i in vis: viss.add(res[i]) # print(x, viss) for y, i in e[x]: # print(x, y, t) while t in viss: t += 1 if i in vis: continue # print(x, y, t) svis.add(y) vis.add(i) res[i] = t t += 1 dfs(y) # print(res) dfs(1) print((max(res))) for r in res: print(r)
import sys from collections import defaultdict as dd input = sys.stdin.readline sys.setrecursionlimit(10**6) N = int(eval(input())) e = dd(list) for i in range(N - 1): u, v = list(map(int, input().split())) e[u].append((v, i)) e[v].append((u, i)) res = [0] * (N - 1) def dfs(x): global res c = 1 vis = set() for y, i in e[x]: vis.add(res[i]) # print(x, vis) for y, i in e[x]: if res[i] > 0: continue while c in vis: c += 1 # print(x, c) res[i] = c vis.add(c) dfs(y) dfs(1) print((max(res))) for r in res: print(r)
false
27.027027
[ "-", "-sys.setrecursionlimit(10**7)", "+sys.setrecursionlimit(10**6)", "- a, b = tuple(map(int, input().split()))", "- e[a].append((b, i))", "- e[b].append((a, i))", "+ u, v = list(map(int, input().split()))", "+ e[u].append((v, i))", "+ e[v].append((u, i))", "-vis = set()", "- global vis", "- viss = set()", "- svis = set()", "- t = 1", "+ c = 1", "+ vis = set()", "- if i in vis:", "- viss.add(res[i])", "- # print(x, viss)", "+ vis.add(res[i])", "+ # print(x, vis)", "- # print(x, y, t)", "- while t in viss:", "- t += 1", "- if i in vis:", "+ if res[i] > 0:", "- # print(x, y, t)", "- svis.add(y)", "- vis.add(i)", "- res[i] = t", "- t += 1", "+ while c in vis:", "+ c += 1", "+ # print(x, c)", "+ res[i] = c", "+ vis.add(c)", "- # print(res)" ]
false
0.059972
0.042403
1.414331
[ "s240055817", "s058653952" ]
u552738814
p03805
python
s267776912
s907660069
39
30
9,208
9,216
Accepted
Accepted
23.08
N,M = [int(a) for a in input().split()] #iから進める場所をリストにして保管 edges = {i:[] for i in range(1,N+1)} for i in range(M): a,b = [int(a) for a in input().split()] edges[a].append(b) edges[b].append(a) #深さ優先探索 def dfs(list): #lst(通過点)の数がN(頂点数)と等しくなったら探索終了(成功) if len(list) == N: return 1 else: a = list[-1] #lstの最後尾(現在地)が次に進める場所をnextとしてリスト化 #nextに以前通った場所が入っていないか確認 next = [n for n in edges[a] if n not in list] #次に進める場所がなくなったら探索終了(失敗) if len(next) == 0: return 0 total = 0 #再帰でさらに探索 for n in next: total += dfs(list + [n]) return total ans = dfs([1]) print(ans)
N,M = list(map(int,input().split())) #iから進める場所をリストにして保管 edges = {i:[] for i in range(1,N+1)} for i in range(M): a,b = [int(a) for a in input().split()] edges[a].append(b) edges[b].append(a) #深さ優先探索 def dfs(list): #lst(通過点)の数がN(頂点数)と等しくなったら探索終了(成功) if len(list) == N: return 1 else: a = list[-1] #lstの最後尾(現在地)が次に進める場所をnextとしてリスト化 #nextに以前通った場所が入っていないか確認 next = [n for n in edges[a] if n not in list] #次に進める場所がなくなったら探索終了(失敗) if len(next) == 0: return 0 total = 0 #再帰でさらに探索 for n in next: total += dfs(list + [n]) return total ans = dfs([1]) print(ans)
36
36
667
658
N, M = [int(a) for a in input().split()] # iから進める場所をリストにして保管 edges = {i: [] for i in range(1, N + 1)} for i in range(M): a, b = [int(a) for a in input().split()] edges[a].append(b) edges[b].append(a) # 深さ優先探索 def dfs(list): # lst(通過点)の数がN(頂点数)と等しくなったら探索終了(成功) if len(list) == N: return 1 else: a = list[-1] # lstの最後尾(現在地)が次に進める場所をnextとしてリスト化 # nextに以前通った場所が入っていないか確認 next = [n for n in edges[a] if n not in list] # 次に進める場所がなくなったら探索終了(失敗) if len(next) == 0: return 0 total = 0 # 再帰でさらに探索 for n in next: total += dfs(list + [n]) return total ans = dfs([1]) print(ans)
N, M = list(map(int, input().split())) # iから進める場所をリストにして保管 edges = {i: [] for i in range(1, N + 1)} for i in range(M): a, b = [int(a) for a in input().split()] edges[a].append(b) edges[b].append(a) # 深さ優先探索 def dfs(list): # lst(通過点)の数がN(頂点数)と等しくなったら探索終了(成功) if len(list) == N: return 1 else: a = list[-1] # lstの最後尾(現在地)が次に進める場所をnextとしてリスト化 # nextに以前通った場所が入っていないか確認 next = [n for n in edges[a] if n not in list] # 次に進める場所がなくなったら探索終了(失敗) if len(next) == 0: return 0 total = 0 # 再帰でさらに探索 for n in next: total += dfs(list + [n]) return total ans = dfs([1]) print(ans)
false
0
[ "-N, M = [int(a) for a in input().split()]", "+N, M = list(map(int, input().split()))" ]
false
0.068808
0.038581
1.783453
[ "s267776912", "s907660069" ]
u788068140
p03634
python
s618228722
s931994573
1,062
814
108,660
197,376
Accepted
Accepted
23.35
from collections import deque # # N = 5 # ARR = [ # [1, 2, 1], # [1, 3, 1], # [2, 4, 1], # [3, 5, 1] # ] # # Q, K = 3, 1 # # BRR = [ # [2, 4], # [2, 3], # [4, 5], # ] # # # N = 7 # ARR = [ # [1, 2, 1], # [1, 3, 3], # [1, 4, 5], # [1, 5, 7], # [1, 6, 9], # [1, 7, 11], # ] # # Q, K = 3, 2 # # BRR = [ # [1, 3], # [4, 5], # [6, 7], # ] # # # N = 10 # ARR = [ # [1, 2, 1000000000], # [2, 3, 1000000000], # [3, 4, 1000000000], # [4, 5, 1000000000], # [5, 6, 1000000000], # [6, 7, 1000000000], # [7, 8, 1000000000], # [8, 9, 1000000000], # [9, 10, 1000000000] # ] # # Q, K = 1, 1 # # BRR = [ # [9, 10] # ] N = int(eval(input())) ARR = [list(map(int,input().split())) for i in range(N-1)] Q, K = list(map(int,input().split())) BRR = [list(map(int,input().split())) for i in range(Q)] def prepare(n, arr): links = {} nodeStatus = {} distances = {} finalDistance = {} for i in range(1, N + 1): nodeStatus.__setitem__(i, False) finalDistance.__setitem__(i, 0) for i in range(len(arr)): tmp = arr[i] startNode = tmp[0] endNode = tmp[1] distance = tmp[2] distances.__setitem__((startNode, endNode), distance) distances.__setitem__((endNode, startNode), distance) if links.get(startNode) == None: links.__setitem__(startNode, [endNode]) else: tmpChild = links.get(startNode) tmpChild.append(endNode) links.__setitem__(startNode, tmpChild) if links.get(endNode) == None: links.__setitem__(endNode, [startNode]) else: tmpChild = links.get(endNode) tmpChild.append(startNode) links.setdefault(endNode, tmpChild) return links, nodeStatus, distances, finalDistance def bfs(startNode): q = deque() q.append((startNode, 0)) while len(q): currentNode, dist = q.popleft() finalDistance.__setitem__(currentNode, dist) nodeStatus.__setitem__(currentNode, True) childNodes = links.get(currentNode) for childNode in childNodes: if nodeStatus.get(childNode) == False: q.append((childNode, dist + distances.get((currentNode, childNode)))) links, nodeStatus, distances, finalDistance = prepare(N, ARR) # print(links) # print(nodeStatus) # print(distances) # print(finalDistance) bfs(K) for i in range(Q): dist1 = finalDistance[BRR[i][0]] dist2 = finalDistance[BRR[i][1]] print((dist1 + dist2))
import sys sys.setrecursionlimit(20000000) # N = 5 # ARR = [ # [1, 2, 1], # [1, 3, 1], # [2, 4, 1], # [3, 5, 1] # ] # # Q, K = 3, 1 # # BRR = [ # [2, 4], # [2, 3], # [4, 5], # ] # # N = int(eval(input())) ARR = [list(map(int,input().split())) for i in range(N-1)] Q, K = list(map(int,input().split())) BRR = [list(map(int,input().split())) for i in range(Q)] def prepare(arr, n): links = [[] for i in range(n)] depth = [0 for i in range(n)] for i in range(n - 1): startNode = arr[i][0] - 1 endNode = arr[i][1] - 1 dist = arr[i][2] links[startNode].append((endNode, dist)) links[endNode].append((startNode, dist)) return links, depth def dfs(currentNode, parrentNode=-1, dist=0): childNodes = links[currentNode] depths[currentNode] = dist for (childNode, childDistance) in childNodes: if childNode == parrentNode: continue dfs(childNode, currentNode, dist + childDistance) links, depths = prepare(ARR, N) dfs(K - 1) for i in range(Q): p1 = BRR[i][0] - 1 p2 = BRR[i][1] - 1 d1 = depths[p1] d2 = depths[p2] print((d1 + d2))
129
66
2,715
1,233
from collections import deque # # N = 5 # ARR = [ # [1, 2, 1], # [1, 3, 1], # [2, 4, 1], # [3, 5, 1] # ] # # Q, K = 3, 1 # # BRR = [ # [2, 4], # [2, 3], # [4, 5], # ] # # # N = 7 # ARR = [ # [1, 2, 1], # [1, 3, 3], # [1, 4, 5], # [1, 5, 7], # [1, 6, 9], # [1, 7, 11], # ] # # Q, K = 3, 2 # # BRR = [ # [1, 3], # [4, 5], # [6, 7], # ] # # # N = 10 # ARR = [ # [1, 2, 1000000000], # [2, 3, 1000000000], # [3, 4, 1000000000], # [4, 5, 1000000000], # [5, 6, 1000000000], # [6, 7, 1000000000], # [7, 8, 1000000000], # [8, 9, 1000000000], # [9, 10, 1000000000] # ] # # Q, K = 1, 1 # # BRR = [ # [9, 10] # ] N = int(eval(input())) ARR = [list(map(int, input().split())) for i in range(N - 1)] Q, K = list(map(int, input().split())) BRR = [list(map(int, input().split())) for i in range(Q)] def prepare(n, arr): links = {} nodeStatus = {} distances = {} finalDistance = {} for i in range(1, N + 1): nodeStatus.__setitem__(i, False) finalDistance.__setitem__(i, 0) for i in range(len(arr)): tmp = arr[i] startNode = tmp[0] endNode = tmp[1] distance = tmp[2] distances.__setitem__((startNode, endNode), distance) distances.__setitem__((endNode, startNode), distance) if links.get(startNode) == None: links.__setitem__(startNode, [endNode]) else: tmpChild = links.get(startNode) tmpChild.append(endNode) links.__setitem__(startNode, tmpChild) if links.get(endNode) == None: links.__setitem__(endNode, [startNode]) else: tmpChild = links.get(endNode) tmpChild.append(startNode) links.setdefault(endNode, tmpChild) return links, nodeStatus, distances, finalDistance def bfs(startNode): q = deque() q.append((startNode, 0)) while len(q): currentNode, dist = q.popleft() finalDistance.__setitem__(currentNode, dist) nodeStatus.__setitem__(currentNode, True) childNodes = links.get(currentNode) for childNode in childNodes: if nodeStatus.get(childNode) == False: q.append((childNode, dist + distances.get((currentNode, childNode)))) links, nodeStatus, distances, finalDistance = prepare(N, ARR) # print(links) # print(nodeStatus) # print(distances) # print(finalDistance) bfs(K) for i in range(Q): dist1 = finalDistance[BRR[i][0]] dist2 = finalDistance[BRR[i][1]] print((dist1 + dist2))
import sys sys.setrecursionlimit(20000000) # N = 5 # ARR = [ # [1, 2, 1], # [1, 3, 1], # [2, 4, 1], # [3, 5, 1] # ] # # Q, K = 3, 1 # # BRR = [ # [2, 4], # [2, 3], # [4, 5], # ] # # N = int(eval(input())) ARR = [list(map(int, input().split())) for i in range(N - 1)] Q, K = list(map(int, input().split())) BRR = [list(map(int, input().split())) for i in range(Q)] def prepare(arr, n): links = [[] for i in range(n)] depth = [0 for i in range(n)] for i in range(n - 1): startNode = arr[i][0] - 1 endNode = arr[i][1] - 1 dist = arr[i][2] links[startNode].append((endNode, dist)) links[endNode].append((startNode, dist)) return links, depth def dfs(currentNode, parrentNode=-1, dist=0): childNodes = links[currentNode] depths[currentNode] = dist for (childNode, childDistance) in childNodes: if childNode == parrentNode: continue dfs(childNode, currentNode, dist + childDistance) links, depths = prepare(ARR, N) dfs(K - 1) for i in range(Q): p1 = BRR[i][0] - 1 p2 = BRR[i][1] - 1 d1 = depths[p1] d2 = depths[p2] print((d1 + d2))
false
48.837209
[ "-from collections import deque", "+import sys", "-#", "+sys.setrecursionlimit(20000000)", "-# N = 7", "-# ARR = [", "-# [1, 2, 1],", "-# [1, 3, 3],", "-# [1, 4, 5],", "-# [1, 5, 7],", "-# [1, 6, 9],", "-# [1, 7, 11],", "-# ]", "-#", "-# Q, K = 3, 2", "-#", "-# BRR = [", "-# [1, 3],", "-# [4, 5],", "-# [6, 7],", "-# ]", "-#", "-#", "-# N = 10", "-# ARR = [", "-# [1, 2, 1000000000],", "-# [2, 3, 1000000000],", "-# [3, 4, 1000000000],", "-# [4, 5, 1000000000],", "-# [5, 6, 1000000000],", "-# [6, 7, 1000000000],", "-# [7, 8, 1000000000],", "-# [8, 9, 1000000000],", "-# [9, 10, 1000000000]", "-# ]", "-#", "-# Q, K = 1, 1", "-#", "-# BRR = [", "-# [9, 10]", "-# ]", "-def prepare(n, arr):", "- links = {}", "- nodeStatus = {}", "- distances = {}", "- finalDistance = {}", "- for i in range(1, N + 1):", "- nodeStatus.__setitem__(i, False)", "- finalDistance.__setitem__(i, 0)", "- for i in range(len(arr)):", "- tmp = arr[i]", "- startNode = tmp[0]", "- endNode = tmp[1]", "- distance = tmp[2]", "- distances.__setitem__((startNode, endNode), distance)", "- distances.__setitem__((endNode, startNode), distance)", "- if links.get(startNode) == None:", "- links.__setitem__(startNode, [endNode])", "- else:", "- tmpChild = links.get(startNode)", "- tmpChild.append(endNode)", "- links.__setitem__(startNode, tmpChild)", "- if links.get(endNode) == None:", "- links.__setitem__(endNode, [startNode])", "- else:", "- tmpChild = links.get(endNode)", "- tmpChild.append(startNode)", "- links.setdefault(endNode, tmpChild)", "- return links, nodeStatus, distances, finalDistance", "+def prepare(arr, n):", "+ links = [[] for i in range(n)]", "+ depth = [0 for i in range(n)]", "+ for i in range(n - 1):", "+ startNode = arr[i][0] - 1", "+ endNode = arr[i][1] - 1", "+ dist = arr[i][2]", "+ links[startNode].append((endNode, dist))", "+ links[endNode].append((startNode, dist))", "+ return links, depth", "-def bfs(startNode):", "- q = deque()", "- q.append((startNode, 0))", "- while len(q):", "- currentNode, dist = q.popleft()", "- finalDistance.__setitem__(currentNode, dist)", "- nodeStatus.__setitem__(currentNode, True)", "- childNodes = links.get(currentNode)", "- for childNode in childNodes:", "- if nodeStatus.get(childNode) == False:", "- q.append((childNode, dist + distances.get((currentNode, childNode))))", "+def dfs(currentNode, parrentNode=-1, dist=0):", "+ childNodes = links[currentNode]", "+ depths[currentNode] = dist", "+ for (childNode, childDistance) in childNodes:", "+ if childNode == parrentNode:", "+ continue", "+ dfs(childNode, currentNode, dist + childDistance)", "-links, nodeStatus, distances, finalDistance = prepare(N, ARR)", "-# print(links)", "-# print(nodeStatus)", "-# print(distances)", "-# print(finalDistance)", "-bfs(K)", "+links, depths = prepare(ARR, N)", "+dfs(K - 1)", "- dist1 = finalDistance[BRR[i][0]]", "- dist2 = finalDistance[BRR[i][1]]", "- print((dist1 + dist2))", "+ p1 = BRR[i][0] - 1", "+ p2 = BRR[i][1] - 1", "+ d1 = depths[p1]", "+ d2 = depths[p2]", "+ print((d1 + d2))" ]
false
0.043254
0.036881
1.1728
[ "s618228722", "s931994573" ]