user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u802963389
p02831
python
s139496211
s186907919
50
36
5,432
5,048
Accepted
Accepted
28
from fractions import gcd # 最小公倍数 def lcm(x, y): return (x * y) // gcd(x, y) A, B = list(map(int, input().split())) ans = lcm(A, B) print(ans)
# C - Snack # https://atcoder.jp/contests/abc148/tasks/abc148_c from fractions import gcd def lcm(x, y): return (x * y) // gcd(x, y) a, b = list(map(int, input().split())) print((lcm(a, b)))
11
10
154
198
from fractions import gcd # 最小公倍数 def lcm(x, y): return (x * y) // gcd(x, y) A, B = list(map(int, input().split())) ans = lcm(A, B) print(ans)
# C - Snack # https://atcoder.jp/contests/abc148/tasks/abc148_c from fractions import gcd def lcm(x, y): return (x * y) // gcd(x, y) a, b = list(map(int, input().split())) print((lcm(a, b)))
false
9.090909
[ "+# C - Snack", "+# https://atcoder.jp/contests/abc148/tasks/abc148_c", "-# 最小公倍数", "+", "-A, B = list(map(int, input().split()))", "-ans = lcm(A, B)", "-print(ans)", "+a, b = list(map(int, input().split()))", "+print((lcm(a, b)))" ]
false
0.048452
0.042062
1.151912
[ "s139496211", "s186907919" ]
u832526214
p02659
python
s097584801
s121197558
22
20
9,156
9,100
Accepted
Accepted
9.09
# -*- coding: utf-8 -*- a, b = input().split() print((int(a)*int(b.replace('.', ''))//100))
# -*- coding: utf-8 -*- a, b = input().split() b_arr = b.split('.') print((int(a)*int(b_arr[0])+int(a)*int(b_arr[1])//100))
3
4
91
124
# -*- coding: utf-8 -*- a, b = input().split() print((int(a) * int(b.replace(".", "")) // 100))
# -*- coding: utf-8 -*- a, b = input().split() b_arr = b.split(".") print((int(a) * int(b_arr[0]) + int(a) * int(b_arr[1]) // 100))
false
25
[ "-print((int(a) * int(b.replace(\".\", \"\")) // 100))", "+b_arr = b.split(\".\")", "+print((int(a) * int(b_arr[0]) + int(a) * int(b_arr[1]) // 100))" ]
false
0.034722
0.035762
0.970909
[ "s097584801", "s121197558" ]
u038021590
p03241
python
s517040668
s167906309
183
63
39,536
64,032
Accepted
Accepted
65.57
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, M = list(map(int, input().split())) Mlist = make_divisors(M) ans = 0 for i in Mlist: if N * i <= M: ans = i else: break print(ans)
N, M = list(map(int, input().split())) ans = 1 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 A = make_divisors(M) for an, a in zip(A, A[1:]): ans = an if a * N > M: break else: ans = M print(ans)
24
23
418
427
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, M = list(map(int, input().split())) Mlist = make_divisors(M) ans = 0 for i in Mlist: if N * i <= M: ans = i else: break print(ans)
N, M = list(map(int, input().split())) ans = 1 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 A = make_divisors(M) for an, a in zip(A, A[1:]): ans = an if a * N > M: break else: ans = M print(ans)
false
4.166667
[ "+N, M = list(map(int, input().split()))", "+ans = 1", "+", "+", "-N, M = list(map(int, input().split()))", "-Mlist = make_divisors(M)", "-ans = 0", "-for i in Mlist:", "- if N * i <= M:", "- ans = i", "- else:", "+A = make_divisors(M)", "+for an, a in zip(A, A[1:]):", "+ ans = an", "+ if a * N > M:", "+else:", "+ ans = M" ]
false
0.043952
0.04349
1.010643
[ "s517040668", "s167906309" ]
u426572476
p03160
python
s972444199
s483307187
212
151
16,268
16,292
Accepted
Accepted
28.77
import itertools import math import sys from collections import Counter from fractions import gcd from functools import reduce import sys sys.setrecursionlimit(4100000) INF = 1 << 60 # ここから書き始める n = int(eval(input())) h = list(map(int, input().split())) dp = [INF] * n dp[0] = 0 for i in range(n): if i + 1 < n: dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i])) if i + 2 < n: dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i])) print((dp[-1]))
# edpc a import itertools from math import factorial import sys import heapq from collections import Counter from collections import deque from fractions import gcd from functools import reduce sys.setrecursionlimit(4100000) INF = 1 << 60 MOD = 10 ** 9 + 7 # ここから書き始める n = int(eval(input())) h = list(map(int, input().split())) dp = [0] * n dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): cost_from_2 = dp[i - 2] + abs(h[i] - h[i - 2]) cost_from_1 = dp[i - 1] + abs(h[i] - h[i - 1]) dp[i] = min(cost_from_1, cost_from_2) # print(dp) print((dp[n - 1]))
22
27
495
594
import itertools import math import sys from collections import Counter from fractions import gcd from functools import reduce import sys sys.setrecursionlimit(4100000) INF = 1 << 60 # ここから書き始める n = int(eval(input())) h = list(map(int, input().split())) dp = [INF] * n dp[0] = 0 for i in range(n): if i + 1 < n: dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i])) if i + 2 < n: dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i])) print((dp[-1]))
# edpc a import itertools from math import factorial import sys import heapq from collections import Counter from collections import deque from fractions import gcd from functools import reduce sys.setrecursionlimit(4100000) INF = 1 << 60 MOD = 10**9 + 7 # ここから書き始める n = int(eval(input())) h = list(map(int, input().split())) dp = [0] * n dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): cost_from_2 = dp[i - 2] + abs(h[i] - h[i - 2]) cost_from_1 = dp[i - 1] + abs(h[i] - h[i - 1]) dp[i] = min(cost_from_1, cost_from_2) # print(dp) print((dp[n - 1]))
false
18.518519
[ "+# edpc a", "-import math", "+from math import factorial", "+import heapq", "+from collections import deque", "-import sys", "+MOD = 10**9 + 7", "-dp = [INF] * n", "+dp = [0] * n", "-for i in range(n):", "- if i + 1 < n:", "- dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))", "- if i + 2 < n:", "- dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))", "-print((dp[-1]))", "+dp[1] = abs(h[1] - h[0])", "+for i in range(2, n):", "+ cost_from_2 = dp[i - 2] + abs(h[i] - h[i - 2])", "+ cost_from_1 = dp[i - 1] + abs(h[i] - h[i - 1])", "+ dp[i] = min(cost_from_1, cost_from_2)", "+# print(dp)", "+print((dp[n - 1]))" ]
false
0.048946
0.047363
1.033438
[ "s972444199", "s483307187" ]
u489959379
p03014
python
s419906253
s092670762
1,977
1,608
385,556
245,128
Accepted
Accepted
18.66
H, W = list(map(int, input().split())) s = [list(eval(input())) for _ in range(H)] X = [[0] * W for _ in range(H)] for i in range(H): start = 0 cnt = 0 for j in range(W): if s[i][j] == "." and j == W - 1: cnt += 1 for k in range(start, W): if s[i][k] == ".": X[i][k] = cnt elif s[i][j] == ".": cnt += 1 elif s[i][j] == "#": for k in range(start, j): if s[i][k] == ".": X[i][k] = cnt start = j cnt = 0 Y = [[0] * W for _ in range(H)] for i in range(W): start = 0 cnt = 0 for j in range(H): if s[j][i] == "." and j == H - 1: cnt += 1 for k in range(start, H): if s[k][i] == ".": Y[k][i] = cnt elif s[j][i] == ".": cnt += 1 elif s[j][i] == "#": for k in range(start, j): if s[k][i] == ".": Y[k][i] = cnt start = j cnt = 0 XY = [] for i in range(H): for j in range(W): XY.append(X[i][j] + Y[i][j] - 1) print((max(XY)))
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): H, W = list(map(int, input().split())) S = [list(list(input().rstrip())) for _ in range(H)] CW = [[0] * W for _ in range(H)] for h in range(H): cnt = 0 for w in range(W): if S[h][w] == "#": cnt = 0 else: cnt += 1 CW[h][w] = cnt cnt = 0 for w in reversed(list(range(W))): if S[h][w] == ".": cnt = max(cnt, CW[h][w]) CW[h][w] = cnt else: cnt = 0 CH = [[0] * W for _ in range(H)] for w in range(W): cnt = 0 for h in range(H): if S[h][w] == "#": cnt = 0 else: cnt += 1 CH[h][w] = cnt cnt = 0 for h in reversed(list(range(H))): if S[h][w] == ".": cnt = max(cnt, CH[h][w]) CH[h][w] = cnt else: cnt = 0 res = 0 for h in range(H): for w in range(W): C = CW[h][w] + CH[h][w] - 1 res = max(res, C) print(res) if __name__ == '__main__': resolve()
47
56
1,222
1,328
H, W = list(map(int, input().split())) s = [list(eval(input())) for _ in range(H)] X = [[0] * W for _ in range(H)] for i in range(H): start = 0 cnt = 0 for j in range(W): if s[i][j] == "." and j == W - 1: cnt += 1 for k in range(start, W): if s[i][k] == ".": X[i][k] = cnt elif s[i][j] == ".": cnt += 1 elif s[i][j] == "#": for k in range(start, j): if s[i][k] == ".": X[i][k] = cnt start = j cnt = 0 Y = [[0] * W for _ in range(H)] for i in range(W): start = 0 cnt = 0 for j in range(H): if s[j][i] == "." and j == H - 1: cnt += 1 for k in range(start, H): if s[k][i] == ".": Y[k][i] = cnt elif s[j][i] == ".": cnt += 1 elif s[j][i] == "#": for k in range(start, j): if s[k][i] == ".": Y[k][i] = cnt start = j cnt = 0 XY = [] for i in range(H): for j in range(W): XY.append(X[i][j] + Y[i][j] - 1) print((max(XY)))
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): H, W = list(map(int, input().split())) S = [list(list(input().rstrip())) for _ in range(H)] CW = [[0] * W for _ in range(H)] for h in range(H): cnt = 0 for w in range(W): if S[h][w] == "#": cnt = 0 else: cnt += 1 CW[h][w] = cnt cnt = 0 for w in reversed(list(range(W))): if S[h][w] == ".": cnt = max(cnt, CW[h][w]) CW[h][w] = cnt else: cnt = 0 CH = [[0] * W for _ in range(H)] for w in range(W): cnt = 0 for h in range(H): if S[h][w] == "#": cnt = 0 else: cnt += 1 CH[h][w] = cnt cnt = 0 for h in reversed(list(range(H))): if S[h][w] == ".": cnt = max(cnt, CH[h][w]) CH[h][w] = cnt else: cnt = 0 res = 0 for h in range(H): for w in range(W): C = CW[h][w] + CH[h][w] - 1 res = max(res, C) print(res) if __name__ == "__main__": resolve()
false
16.071429
[ "-H, W = list(map(int, input().split()))", "-s = [list(eval(input())) for _ in range(H)]", "-X = [[0] * W for _ in range(H)]", "-for i in range(H):", "- start = 0", "- cnt = 0", "- for j in range(W):", "- if s[i][j] == \".\" and j == W - 1:", "- cnt += 1", "- for k in range(start, W):", "- if s[i][k] == \".\":", "- X[i][k] = cnt", "- elif s[i][j] == \".\":", "- cnt += 1", "- elif s[i][j] == \"#\":", "- for k in range(start, j):", "- if s[i][k] == \".\":", "- X[i][k] = cnt", "- start = j", "- cnt = 0", "-Y = [[0] * W for _ in range(H)]", "-for i in range(W):", "- start = 0", "- cnt = 0", "- for j in range(H):", "- if s[j][i] == \".\" and j == H - 1:", "- cnt += 1", "- for k in range(start, H):", "- if s[k][i] == \".\":", "- Y[k][i] = cnt", "- elif s[j][i] == \".\":", "- cnt += 1", "- elif s[j][i] == \"#\":", "- for k in range(start, j):", "- if s[k][i] == \".\":", "- Y[k][i] = cnt", "- start = j", "- cnt = 0", "-XY = []", "-for i in range(H):", "- for j in range(W):", "- XY.append(X[i][j] + Y[i][j] - 1)", "-print((max(XY)))", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+input = sys.stdin.readline", "+f_inf = float(\"inf\")", "+mod = 10**9 + 7", "+", "+", "+def resolve():", "+ H, W = list(map(int, input().split()))", "+ S = [list(list(input().rstrip())) for _ in range(H)]", "+ CW = [[0] * W for _ in range(H)]", "+ for h in range(H):", "+ cnt = 0", "+ for w in range(W):", "+ if S[h][w] == \"#\":", "+ cnt = 0", "+ else:", "+ cnt += 1", "+ CW[h][w] = cnt", "+ cnt = 0", "+ for w in reversed(list(range(W))):", "+ if S[h][w] == \".\":", "+ cnt = max(cnt, CW[h][w])", "+ CW[h][w] = cnt", "+ else:", "+ cnt = 0", "+ CH = [[0] * W for _ in range(H)]", "+ for w in range(W):", "+ cnt = 0", "+ for h in range(H):", "+ if S[h][w] == \"#\":", "+ cnt = 0", "+ else:", "+ cnt += 1", "+ CH[h][w] = cnt", "+ cnt = 0", "+ for h in reversed(list(range(H))):", "+ if S[h][w] == \".\":", "+ cnt = max(cnt, CH[h][w])", "+ CH[h][w] = cnt", "+ else:", "+ cnt = 0", "+ res = 0", "+ for h in range(H):", "+ for w in range(W):", "+ C = CW[h][w] + CH[h][w] - 1", "+ res = max(res, C)", "+ print(res)", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.065334
0.03442
1.898157
[ "s419906253", "s092670762" ]
u102902647
p03161
python
s212190246
s787219397
1,882
222
20,508
86,168
Accepted
Accepted
88.2
if __name__ == '__main__': N, K = list(map(int, input().split())) h_list = list(map(int, input().split())) dp_list = [0] for n in range(1, N): tmp_h = h_list[n] if n < K: lst = [abs(tmp_h - h_list[i]) + dp_list[i] for i in range(n)] else: lst = [abs(tmp_h - h_list[n-k]) + dp_list[n-k] for k in range(1, K + 1)] dp_list.append(min(lst)) print((dp_list[-1]))
N, K = list(map(int, input().split())) h_list = list(map(int, input().split())) dp_list = [0] for n in range(1, N): tmp_h = h_list[n] if n < K: lst = [abs(tmp_h - h_list[i]) + dp_list[i] for i in range(n)] else: lst = [abs(tmp_h - h_list[n-k]) + dp_list[n-k] for k in range(1, K + 1)] dp_list.append(min(lst)) print((dp_list[-1]))
13
12
439
366
if __name__ == "__main__": N, K = list(map(int, input().split())) h_list = list(map(int, input().split())) dp_list = [0] for n in range(1, N): tmp_h = h_list[n] if n < K: lst = [abs(tmp_h - h_list[i]) + dp_list[i] for i in range(n)] else: lst = [abs(tmp_h - h_list[n - k]) + dp_list[n - k] for k in range(1, K + 1)] dp_list.append(min(lst)) print((dp_list[-1]))
N, K = list(map(int, input().split())) h_list = list(map(int, input().split())) dp_list = [0] for n in range(1, N): tmp_h = h_list[n] if n < K: lst = [abs(tmp_h - h_list[i]) + dp_list[i] for i in range(n)] else: lst = [abs(tmp_h - h_list[n - k]) + dp_list[n - k] for k in range(1, K + 1)] dp_list.append(min(lst)) print((dp_list[-1]))
false
7.692308
[ "-if __name__ == \"__main__\":", "- N, K = list(map(int, input().split()))", "- h_list = list(map(int, input().split()))", "- dp_list = [0]", "- for n in range(1, N):", "- tmp_h = h_list[n]", "- if n < K:", "- lst = [abs(tmp_h - h_list[i]) + dp_list[i] for i in range(n)]", "- else:", "- lst = [abs(tmp_h - h_list[n - k]) + dp_list[n - k] for k in range(1, K + 1)]", "- dp_list.append(min(lst))", "- print((dp_list[-1]))", "+N, K = list(map(int, input().split()))", "+h_list = list(map(int, input().split()))", "+dp_list = [0]", "+for n in range(1, N):", "+ tmp_h = h_list[n]", "+ if n < K:", "+ lst = [abs(tmp_h - h_list[i]) + dp_list[i] for i in range(n)]", "+ else:", "+ lst = [abs(tmp_h - h_list[n - k]) + dp_list[n - k] for k in range(1, K + 1)]", "+ dp_list.append(min(lst))", "+print((dp_list[-1]))" ]
false
0.071948
0.071935
1.000176
[ "s212190246", "s787219397" ]
u380524497
p02803
python
s919842981
s151679415
521
372
3,188
3,316
Accepted
Accepted
28.6
import heapq h, w = list(map(int, input().split())) meiro = [] for i in range(h): line = eval(input()) meiro.append(line) def dfs(y, x): dist = [[-1]*w for _ in range(h)] if meiro[y][x] == '#': return 0 dist[y][x] = 0 pattern = [[-1, 0], [1, 0], [0, -1], [0, 1]] todo = [] for dy, dx in pattern: ny, nx = y + dy, x + dx if 0 <= ny <= h-1 and 0 <= nx <= w-1: if meiro[ny][nx] == '.': heapq.heappush(todo, [1, ny, nx]) while todo: d, y, x = heapq.heappop(todo) if meiro[y][x] == '#': continue if dist[y][x] != -1: continue dist[y][x] = d for dy, dx in pattern: ny, nx = y + dy, x + dx if 0 <= ny <= h - 1 and 0 <= nx <= w - 1: if dist[ny][nx] == -1 and meiro[ny][nx] == '.': heapq.heappush(todo, [d+1, ny, nx]) res = 0 for line in dist: res = max(max(line), res) return res ans = [] for y in range(h): for x in range(w): ans.append(dfs(y, x)) print((max(ans)))
from collections import deque h, w = list(map(int, input().split())) meiro = [] for i in range(h): line = eval(input()) meiro.append(line) def bfs(y, x): dist = [[-1]*w for _ in range(h)] if meiro[y][x] == '#': return 0 dist[y][x] = 0 pattern = [[-1, 0], [1, 0], [0, -1], [0, 1]] todo = deque([]) for dy, dx in pattern: ny, nx = y + dy, x + dx if 0 <= ny <= h-1 and 0 <= nx <= w-1: todo.append([ny, nx, 1]) while todo: y, x, d = todo.popleft() if meiro[y][x] == '#': continue if dist[y][x] != -1: continue dist[y][x] = d for dy, dx in pattern: ny, nx = y + dy, x + dx if 0 <= ny <= h - 1 and 0 <= nx <= w - 1 and dist[ny][nx] == -1: todo.append([ny, nx, d+1]) res = 0 for line in dist: res = max(max(line), res) return res ans = [] for y in range(h): for x in range(w): ans.append(bfs(y, x)) print((max(ans)))
51
49
1,166
1,064
import heapq h, w = list(map(int, input().split())) meiro = [] for i in range(h): line = eval(input()) meiro.append(line) def dfs(y, x): dist = [[-1] * w for _ in range(h)] if meiro[y][x] == "#": return 0 dist[y][x] = 0 pattern = [[-1, 0], [1, 0], [0, -1], [0, 1]] todo = [] for dy, dx in pattern: ny, nx = y + dy, x + dx if 0 <= ny <= h - 1 and 0 <= nx <= w - 1: if meiro[ny][nx] == ".": heapq.heappush(todo, [1, ny, nx]) while todo: d, y, x = heapq.heappop(todo) if meiro[y][x] == "#": continue if dist[y][x] != -1: continue dist[y][x] = d for dy, dx in pattern: ny, nx = y + dy, x + dx if 0 <= ny <= h - 1 and 0 <= nx <= w - 1: if dist[ny][nx] == -1 and meiro[ny][nx] == ".": heapq.heappush(todo, [d + 1, ny, nx]) res = 0 for line in dist: res = max(max(line), res) return res ans = [] for y in range(h): for x in range(w): ans.append(dfs(y, x)) print((max(ans)))
from collections import deque h, w = list(map(int, input().split())) meiro = [] for i in range(h): line = eval(input()) meiro.append(line) def bfs(y, x): dist = [[-1] * w for _ in range(h)] if meiro[y][x] == "#": return 0 dist[y][x] = 0 pattern = [[-1, 0], [1, 0], [0, -1], [0, 1]] todo = deque([]) for dy, dx in pattern: ny, nx = y + dy, x + dx if 0 <= ny <= h - 1 and 0 <= nx <= w - 1: todo.append([ny, nx, 1]) while todo: y, x, d = todo.popleft() if meiro[y][x] == "#": continue if dist[y][x] != -1: continue dist[y][x] = d for dy, dx in pattern: ny, nx = y + dy, x + dx if 0 <= ny <= h - 1 and 0 <= nx <= w - 1 and dist[ny][nx] == -1: todo.append([ny, nx, d + 1]) res = 0 for line in dist: res = max(max(line), res) return res ans = [] for y in range(h): for x in range(w): ans.append(bfs(y, x)) print((max(ans)))
false
3.921569
[ "-import heapq", "+from collections import deque", "-def dfs(y, x):", "+def bfs(y, x):", "- todo = []", "+ todo = deque([])", "- if meiro[ny][nx] == \".\":", "- heapq.heappush(todo, [1, ny, nx])", "+ todo.append([ny, nx, 1])", "- d, y, x = heapq.heappop(todo)", "+ y, x, d = todo.popleft()", "- if 0 <= ny <= h - 1 and 0 <= nx <= w - 1:", "- if dist[ny][nx] == -1 and meiro[ny][nx] == \".\":", "- heapq.heappush(todo, [d + 1, ny, nx])", "+ if 0 <= ny <= h - 1 and 0 <= nx <= w - 1 and dist[ny][nx] == -1:", "+ todo.append([ny, nx, d + 1])", "- ans.append(dfs(y, x))", "+ ans.append(bfs(y, x))" ]
false
0.039572
0.105649
0.374558
[ "s919842981", "s151679415" ]
u327466606
p02728
python
s365938255
s749105012
1,831
1,230
239,264
235,288
Accepted
Accepted
32.82
import sys from functools import reduce def rerooting(N, adj, merge, finalize,identity): """ merge: (T,T) -> T This merges two dp results. (T, operator) must be a monoid. identity: operator(x, identity) = operator(identity, x) = x finalize: T -> T This transforms the merged result to the dp result """ order = [None]*N parent = [None]*N parent[0] = -1 stack = [0] for i in range(N): v = stack.pop() order[i] = v for u in adj[v]: if parent[u] is None: parent[u] = v stack.append(u) # from leaf to parent dp_down = [None]*N for v in reversed(order[1:]): p = parent[v] dp_down[v] = finalize(reduce(merge, (dp_down[c] for c in adj[v] if c != p), identity)) # from parent to leaf dp_up = [None]*N dp_up[0] = identity for v in order: if len(adj[v]) == 1 and adj[v][0] == parent[v]: continue p = parent[v] left = [dp_up[v]] for u in adj[v]: if u != p: left.append(merge(left[-1],dp_down[u])) right = [identity] for u in reversed(adj[v]): if u != p: right.append(merge(dp_down[u],right[-1])) i = 0 for u in adj[v]: if u != p: dp_up[u] = finalize(merge(left[i],right[-i-2])) i += 1 for v,l in enumerate(adj): order[v] = reduce(merge, (dp_down[u] for u in adj[v] if u != parent[v]), identity) order[v] = finalize(merge(order[v], dp_up[v])) return order def solve(N,edges): MOD = 10**9+7 factorio = [1]*(N+1) t = 1 for i in range(1,N+1): t *= i t %= MOD factorio[i] = t adj = [[] for _ in range(N)] for a,b in edges: adj[a].append(b) adj[b].append(a) def func(x,y): cx,nx = x cy,ny = y c = cx*cy*factorio[nx+ny]*pow(factorio[nx]*factorio[ny],MOD-2,MOD) c %= MOD n = nx+ny return c, n def func2(x): c,n = x return c,n+1 identity = (1,0) res = rerooting(N, adj, func, func2, identity) for k,n in res: print(k) if __name__ == '__main__': read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) m = list(map(int, read().split())) edges = tuple((a-1,b-1) for a,b in zip(m, m)) solve(N, edges)
import sys from functools import reduce def rerooting(N, adj, merge, finalize,identity): """ merge: (T,T) -> T This merges two dp results. (T, operator) must be a monoid. identity: identity of (T, operator) finalize: T -> T This transforms the merged result to the dp result """ order = [None]*N parent = [None]*N parent[0] = -1 stack = [0] for i in range(N): v = stack.pop() order[i] = v for u in adj[v]: if parent[u] is None: parent[u] = v stack.append(u) # from leaf to parent dp_down = [None]*N for v in reversed(order[1:]): p = parent[v] dp_down[v] = finalize(reduce(merge, (dp_down[c] for c in adj[v] if c != p), identity)) # from parent to leaf dp_up = [None]*N dp_up[0] = identity for v in order: if len(adj[v]) == 1 and adj[v][0] == parent[v]: continue p = parent[v] left = [dp_up[v]] for u in adj[v]: if u != p: left.append(merge(left[-1],dp_down[u])) right = [identity] for u in reversed(adj[v]): if u != p: right.append(merge(dp_down[u],right[-1])) i = 0 for u in adj[v]: if u != p: dp_up[u] = finalize(merge(left[i],right[-i-2])) i += 1 for v,l in enumerate(adj): order[v] = reduce(merge, (dp_down[u] for u in adj[v] if u != parent[v]), identity) order[v] = finalize(merge(order[v], dp_up[v])) return order def solve(N,edges): MOD = 10**9+7 factorio = [None]*(N+1) factorio[0] = 1 t = 1 for i in range(1,N+1): t *= i t %= MOD factorio[i] = t factorio_inv = [None]*(N+1) factorio_inv[0] = 1 t = pow(factorio[-1],MOD-2,MOD) for i in reversed(list(range(1,N+1))): factorio_inv[i] = t t *= i t %= MOD adj = [[] for _ in range(N)] for a,b in edges: adj[a].append(b) adj[b].append(a) def func(x,y): cx,nx = x cy,ny = y c = cx*cy*factorio[nx+ny]*factorio_inv[nx]*factorio_inv[ny] return c%MOD, nx+ny def func2(x): c,n = x return c,n+1 identity = (1,0) res = rerooting(N, adj, func, func2, identity) for k,n in res: print(k) if __name__ == '__main__': read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) m = list(map(int, read().split())) edges = tuple((a-1,b-1) for a,b in zip(m, m)) solve(N, edges)
110
118
2,689
2,853
import sys from functools import reduce def rerooting(N, adj, merge, finalize, identity): """ merge: (T,T) -> T This merges two dp results. (T, operator) must be a monoid. identity: operator(x, identity) = operator(identity, x) = x finalize: T -> T This transforms the merged result to the dp result """ order = [None] * N parent = [None] * N parent[0] = -1 stack = [0] for i in range(N): v = stack.pop() order[i] = v for u in adj[v]: if parent[u] is None: parent[u] = v stack.append(u) # from leaf to parent dp_down = [None] * N for v in reversed(order[1:]): p = parent[v] dp_down[v] = finalize( reduce(merge, (dp_down[c] for c in adj[v] if c != p), identity) ) # from parent to leaf dp_up = [None] * N dp_up[0] = identity for v in order: if len(adj[v]) == 1 and adj[v][0] == parent[v]: continue p = parent[v] left = [dp_up[v]] for u in adj[v]: if u != p: left.append(merge(left[-1], dp_down[u])) right = [identity] for u in reversed(adj[v]): if u != p: right.append(merge(dp_down[u], right[-1])) i = 0 for u in adj[v]: if u != p: dp_up[u] = finalize(merge(left[i], right[-i - 2])) i += 1 for v, l in enumerate(adj): order[v] = reduce( merge, (dp_down[u] for u in adj[v] if u != parent[v]), identity ) order[v] = finalize(merge(order[v], dp_up[v])) return order def solve(N, edges): MOD = 10**9 + 7 factorio = [1] * (N + 1) t = 1 for i in range(1, N + 1): t *= i t %= MOD factorio[i] = t adj = [[] for _ in range(N)] for a, b in edges: adj[a].append(b) adj[b].append(a) def func(x, y): cx, nx = x cy, ny = y c = cx * cy * factorio[nx + ny] * pow(factorio[nx] * factorio[ny], MOD - 2, MOD) c %= MOD n = nx + ny return c, n def func2(x): c, n = x return c, n + 1 identity = (1, 0) res = rerooting(N, adj, func, func2, identity) for k, n in res: print(k) if __name__ == "__main__": read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) m = list(map(int, read().split())) edges = tuple((a - 1, b - 1) for a, b in zip(m, m)) solve(N, edges)
import sys from functools import reduce def rerooting(N, adj, merge, finalize, identity): """ merge: (T,T) -> T This merges two dp results. (T, operator) must be a monoid. identity: identity of (T, operator) finalize: T -> T This transforms the merged result to the dp result """ order = [None] * N parent = [None] * N parent[0] = -1 stack = [0] for i in range(N): v = stack.pop() order[i] = v for u in adj[v]: if parent[u] is None: parent[u] = v stack.append(u) # from leaf to parent dp_down = [None] * N for v in reversed(order[1:]): p = parent[v] dp_down[v] = finalize( reduce(merge, (dp_down[c] for c in adj[v] if c != p), identity) ) # from parent to leaf dp_up = [None] * N dp_up[0] = identity for v in order: if len(adj[v]) == 1 and adj[v][0] == parent[v]: continue p = parent[v] left = [dp_up[v]] for u in adj[v]: if u != p: left.append(merge(left[-1], dp_down[u])) right = [identity] for u in reversed(adj[v]): if u != p: right.append(merge(dp_down[u], right[-1])) i = 0 for u in adj[v]: if u != p: dp_up[u] = finalize(merge(left[i], right[-i - 2])) i += 1 for v, l in enumerate(adj): order[v] = reduce( merge, (dp_down[u] for u in adj[v] if u != parent[v]), identity ) order[v] = finalize(merge(order[v], dp_up[v])) return order def solve(N, edges): MOD = 10**9 + 7 factorio = [None] * (N + 1) factorio[0] = 1 t = 1 for i in range(1, N + 1): t *= i t %= MOD factorio[i] = t factorio_inv = [None] * (N + 1) factorio_inv[0] = 1 t = pow(factorio[-1], MOD - 2, MOD) for i in reversed(list(range(1, N + 1))): factorio_inv[i] = t t *= i t %= MOD adj = [[] for _ in range(N)] for a, b in edges: adj[a].append(b) adj[b].append(a) def func(x, y): cx, nx = x cy, ny = y c = cx * cy * factorio[nx + ny] * factorio_inv[nx] * factorio_inv[ny] return c % MOD, nx + ny def func2(x): c, n = x return c, n + 1 identity = (1, 0) res = rerooting(N, adj, func, func2, identity) for k, n in res: print(k) if __name__ == "__main__": read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) m = list(map(int, read().split())) edges = tuple((a - 1, b - 1) for a, b in zip(m, m)) solve(N, edges)
false
6.779661
[ "- identity: operator(x, identity) = operator(identity, x) = x", "+ identity: identity of (T, operator)", "- factorio = [1] * (N + 1)", "+ factorio = [None] * (N + 1)", "+ factorio[0] = 1", "+ factorio_inv = [None] * (N + 1)", "+ factorio_inv[0] = 1", "+ t = pow(factorio[-1], MOD - 2, MOD)", "+ for i in reversed(list(range(1, N + 1))):", "+ factorio_inv[i] = t", "+ t *= i", "+ t %= MOD", "- c = cx * cy * factorio[nx + ny] * pow(factorio[nx] * factorio[ny], MOD - 2, MOD)", "- c %= MOD", "- n = nx + ny", "- return c, n", "+ c = cx * cy * factorio[nx + ny] * factorio_inv[nx] * factorio_inv[ny]", "+ return c % MOD, nx + ny" ]
false
0.046272
0.040896
1.131467
[ "s365938255", "s749105012" ]
u156815136
p03352
python
s452640081
s168315349
37
19
5,148
2,940
Accepted
Accepted
48.65
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): x = int(eval(input())) ma_ = 1 for i in range(1,x): for j in range(2,x): if i**j <= x: ma_ = max(ma_,i**j) else: break # break で for j を消してるだけや print(ma_) if __name__ == '__main__': main()
X = int(eval(input())) ans = 1 for i in range(1,X+1): for j in range(2,X+1): if i**j <= X: ans = max(ans,i**j) else: break print(ans)
37
9
846
180
from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int, input().split())) def main(): x = int(eval(input())) ma_ = 1 for i in range(1, x): for j in range(2, x): if i**j <= x: ma_ = max(ma_, i**j) else: break # break で for j を消してるだけや print(ma_) if __name__ == "__main__": main()
X = int(eval(input())) ans = 1 for i in range(1, X + 1): for j in range(2, X + 1): if i**j <= X: ans = max(ans, i**j) else: break print(ans)
false
75.675676
[ "-from statistics import median", "-", "-# import collections", "-# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]", "-from fractions import gcd", "-from itertools import combinations # (string,3) 3回", "-from collections import deque", "-from collections import defaultdict", "-import bisect", "-", "-#", "-# d = m - k[i] - k[j]", "-# if kk[bisect.bisect_right(kk,d) - 1] == d:", "-#", "-#", "-#", "-# pythonで無理なときは、pypyでやると正解するかも!!", "-#", "-#", "-import sys", "-", "-sys.setrecursionlimit(10000000)", "-mod = 10**9 + 7", "-", "-", "-def readInts():", "- return list(map(int, input().split()))", "-", "-", "-def main():", "- x = int(eval(input()))", "- ma_ = 1", "- for i in range(1, x):", "- for j in range(2, x):", "- if i**j <= x:", "- ma_ = max(ma_, i**j)", "- else:", "- break", "- # break で for j を消してるだけや", "- print(ma_)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+X = int(eval(input()))", "+ans = 1", "+for i in range(1, X + 1):", "+ for j in range(2, X + 1):", "+ if i**j <= X:", "+ ans = max(ans, i**j)", "+ else:", "+ break", "+print(ans)" ]
false
0.066747
0.078199
0.853552
[ "s452640081", "s168315349" ]
u991567869
p03252
python
s212391722
s824684485
48
42
6,832
3,888
Accepted
Accepted
12.5
from collections import Counter s = list(eval(input())) t = list(eval(input())) cs = Counter(s) ct = Counter(t) csv = sorted(cs.values()) ctv = sorted(ct.values()) if csv == ctv: print("Yes") exit() print("No")
from collections import Counter s = Counter(eval(input())) t = Counter(eval(input())) sv = sorted(s.values()) tv = sorted(t.values()) if sv == tv: print("Yes") exit() print("No")
16
13
226
190
from collections import Counter s = list(eval(input())) t = list(eval(input())) cs = Counter(s) ct = Counter(t) csv = sorted(cs.values()) ctv = sorted(ct.values()) if csv == ctv: print("Yes") exit() print("No")
from collections import Counter s = Counter(eval(input())) t = Counter(eval(input())) sv = sorted(s.values()) tv = sorted(t.values()) if sv == tv: print("Yes") exit() print("No")
false
18.75
[ "-s = list(eval(input()))", "-t = list(eval(input()))", "-cs = Counter(s)", "-ct = Counter(t)", "-csv = sorted(cs.values())", "-ctv = sorted(ct.values())", "-if csv == ctv:", "+s = Counter(eval(input()))", "+t = Counter(eval(input()))", "+sv = sorted(s.values())", "+tv = sorted(t.values())", "+if sv == tv:" ]
false
0.096346
0.040361
2.387076
[ "s212391722", "s824684485" ]
u489959379
p03576
python
s360572903
s150096905
849
546
47,836
74,348
Accepted
Accepted
35.69
import sys input = sys.stdin.readline def main(): n, k = list(map(int, input().split())) X, Y = [], [] for _ in range(n): x, y = list(map(int, input().split())) X.append(x) Y.append(y) X_s = sorted(X) Y_s = sorted(Y) f_inf = float("inf") res = f_inf for x1 in range(n): for x2 in range(x1 + 1, n): for y1 in range(n): for y2 in range(y1 + 1, n): lx, rx = X_s[x1], X_s[x2] by, uy = Y_s[y1], Y_s[y2] cnt = 0 for i in range(n): if lx <= X[i] <= rx and by <= Y[i] <= uy: cnt += 1 if cnt >= k: res = min(res, (rx - lx) * (uy - by)) print(res) if __name__ == '__main__': main()
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, k = list(map(int, input().split())) X, Y = [], [] for _ in range(n): x, y = list(map(int, input().split())) X.append(x) Y.append(y) X_s = sorted(X) Y_s = sorted(Y) res = f_inf for x1 in range(n): for x2 in range(x1 + 1, n): for y1 in range(n): for y2 in range(y1 + 1, n): lx, rx = X_s[x1], X_s[x2] by, uy = Y_s[y1], Y_s[y2] cnt = 0 for i in range(n): if lx <= X[i] <= rx and by <= Y[i] <= uy: cnt += 1 if cnt >= k: res = min(res, (rx - lx) * (uy - by)) print(res) if __name__ == '__main__': resolve()
33
36
873
932
import sys input = sys.stdin.readline def main(): n, k = list(map(int, input().split())) X, Y = [], [] for _ in range(n): x, y = list(map(int, input().split())) X.append(x) Y.append(y) X_s = sorted(X) Y_s = sorted(Y) f_inf = float("inf") res = f_inf for x1 in range(n): for x2 in range(x1 + 1, n): for y1 in range(n): for y2 in range(y1 + 1, n): lx, rx = X_s[x1], X_s[x2] by, uy = Y_s[y1], Y_s[y2] cnt = 0 for i in range(n): if lx <= X[i] <= rx and by <= Y[i] <= uy: cnt += 1 if cnt >= k: res = min(res, (rx - lx) * (uy - by)) print(res) if __name__ == "__main__": main()
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): n, k = list(map(int, input().split())) X, Y = [], [] for _ in range(n): x, y = list(map(int, input().split())) X.append(x) Y.append(y) X_s = sorted(X) Y_s = sorted(Y) res = f_inf for x1 in range(n): for x2 in range(x1 + 1, n): for y1 in range(n): for y2 in range(y1 + 1, n): lx, rx = X_s[x1], X_s[x2] by, uy = Y_s[y1], Y_s[y2] cnt = 0 for i in range(n): if lx <= X[i] <= rx and by <= Y[i] <= uy: cnt += 1 if cnt >= k: res = min(res, (rx - lx) * (uy - by)) print(res) if __name__ == "__main__": resolve()
false
8.333333
[ "+sys.setrecursionlimit(10**7)", "+f_inf = float(\"inf\")", "+mod = 10**9 + 7", "-def main():", "+def resolve():", "- f_inf = float(\"inf\")", "- main()", "+ resolve()" ]
false
0.035297
0.033154
1.06464
[ "s360572903", "s150096905" ]
u891438775
p03607
python
s015319732
s545697104
199
176
16,268
19,468
Accepted
Accepted
11.56
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] D = {} for a in A: if a in D: D.pop(a) else: D[a] = 1 print((sum(D.values())))
N = int(eval(input())) A = [eval(input()) for _ in range(N)] D = {} for a in A: if a in D: D.pop(a) else: D[a] = 1 print((sum(D.values())))
9
9
162
157
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] D = {} for a in A: if a in D: D.pop(a) else: D[a] = 1 print((sum(D.values())))
N = int(eval(input())) A = [eval(input()) for _ in range(N)] D = {} for a in A: if a in D: D.pop(a) else: D[a] = 1 print((sum(D.values())))
false
0
[ "-A = [int(eval(input())) for _ in range(N)]", "+A = [eval(input()) for _ in range(N)]" ]
false
0.036655
0.042303
0.866495
[ "s015319732", "s545697104" ]
u747602774
p03221
python
s030567562
s834047217
737
651
35,100
34,500
Accepted
Accepted
11.67
N,M = list(map(int,input().split())) PY = [list(map(int,input().split())) + [i] for i in range(M)] PY.sort() ans = [None for i in range(M)] x = 1 P = PY[0][0] for i in range(M): if P != PY[i][0]: x = 1 P = PY[i][0] ans[PY[i][2]] = (P,x) x += 1 for p,x in ans: print((str(p).zfill(6) + str(x).zfill(6)))
N,M = list(map(int,input().split())) PY = [list(map(int,input().split())) + [i] for i in range(M)] PY.sort() pnow = PY[0][0] c = 1 ans = [-1 for i in range(M)] for i in range(M): if pnow != PY[i][0]: c = 1 pnow = PY[i][0] ans[PY[i][2]] = str(PY[i][0]).zfill(6) + str(c).zfill(6) c += 1 print(('\n'.join(ans)))
19
18
350
352
N, M = list(map(int, input().split())) PY = [list(map(int, input().split())) + [i] for i in range(M)] PY.sort() ans = [None for i in range(M)] x = 1 P = PY[0][0] for i in range(M): if P != PY[i][0]: x = 1 P = PY[i][0] ans[PY[i][2]] = (P, x) x += 1 for p, x in ans: print((str(p).zfill(6) + str(x).zfill(6)))
N, M = list(map(int, input().split())) PY = [list(map(int, input().split())) + [i] for i in range(M)] PY.sort() pnow = PY[0][0] c = 1 ans = [-1 for i in range(M)] for i in range(M): if pnow != PY[i][0]: c = 1 pnow = PY[i][0] ans[PY[i][2]] = str(PY[i][0]).zfill(6) + str(c).zfill(6) c += 1 print(("\n".join(ans)))
false
5.263158
[ "-ans = [None for i in range(M)]", "-x = 1", "-P = PY[0][0]", "+pnow = PY[0][0]", "+c = 1", "+ans = [-1 for i in range(M)]", "- if P != PY[i][0]:", "- x = 1", "- P = PY[i][0]", "- ans[PY[i][2]] = (P, x)", "- x += 1", "-for p, x in ans:", "- print((str(p).zfill(6) + str(x).zfill(6)))", "+ if pnow != PY[i][0]:", "+ c = 1", "+ pnow = PY[i][0]", "+ ans[PY[i][2]] = str(PY[i][0]).zfill(6) + str(c).zfill(6)", "+ c += 1", "+print((\"\\n\".join(ans)))" ]
false
0.034698
0.074223
0.467491
[ "s030567562", "s834047217" ]
u919633157
p03425
python
s198177228
s660808418
77
67
3,064
3,188
Accepted
Accepted
12.99
# 2019/07/06 import sys input=sys.stdin.readline n=int(eval(input())) s={} for i in range(n): tmp=eval(input()) if tmp[0] in ['M','A','R','C','H']: s[tmp[0]]=s.get(tmp[0],0)+1 # ↑ここまでできた # ↓ここからわからん ans=0 for ik,iv in list(s.items()): for jk,jv in list(s.items()): if ik==jk:break for kk,kv in list(s.items()): if jk==kk:break ans+=iv*jv*kv print(ans)
import sys from itertools import combinations input=sys.stdin.readline n=int(eval(input())) s={} for i in range(n): tmp=input()[0] if tmp in ['M','A','R','C','H']: s[tmp]=s.get(tmp,0)+1 ans=0 cmb=list(combinations(list(s.values()),3)) for a,b,c in cmb: ans+=a*b*c print(ans)
25
19
411
305
# 2019/07/06 import sys input = sys.stdin.readline n = int(eval(input())) s = {} for i in range(n): tmp = eval(input()) if tmp[0] in ["M", "A", "R", "C", "H"]: s[tmp[0]] = s.get(tmp[0], 0) + 1 # ↑ここまでできた # ↓ここからわからん ans = 0 for ik, iv in list(s.items()): for jk, jv in list(s.items()): if ik == jk: break for kk, kv in list(s.items()): if jk == kk: break ans += iv * jv * kv print(ans)
import sys from itertools import combinations input = sys.stdin.readline n = int(eval(input())) s = {} for i in range(n): tmp = input()[0] if tmp in ["M", "A", "R", "C", "H"]: s[tmp] = s.get(tmp, 0) + 1 ans = 0 cmb = list(combinations(list(s.values()), 3)) for a, b, c in cmb: ans += a * b * c print(ans)
false
24
[ "-# 2019/07/06", "+from itertools import combinations", "- tmp = eval(input())", "- if tmp[0] in [\"M\", \"A\", \"R\", \"C\", \"H\"]:", "- s[tmp[0]] = s.get(tmp[0], 0) + 1", "-# ↑ここまでできた", "-# ↓ここからわからん", "+ tmp = input()[0]", "+ if tmp in [\"M\", \"A\", \"R\", \"C\", \"H\"]:", "+ s[tmp] = s.get(tmp, 0) + 1", "-for ik, iv in list(s.items()):", "- for jk, jv in list(s.items()):", "- if ik == jk:", "- break", "- for kk, kv in list(s.items()):", "- if jk == kk:", "- break", "- ans += iv * jv * kv", "+cmb = list(combinations(list(s.values()), 3))", "+for a, b, c in cmb:", "+ ans += a * b * c" ]
false
0.037898
0.038593
0.981981
[ "s198177228", "s660808418" ]
u281303342
p04046
python
s756476304
s327530695
374
336
26,740
26,740
Accepted
Accepted
10.16
H,W,A,B = list(map(int,input().split())) def init_fact(n,mod): fact,finv,inv = [1]*n,[1]*n,[1]*n for i in range(2,n): fact[i] = (fact[i-1]*i) % mod inv[i] = mod - inv[mod%i] * (mod//i)%mod finv[i] = finv[i-1] * inv[i] % mod return (fact,finv,inv) def nCr(n,r,mod,fact,finv): if n<r: return 0 else: return fact[n] * (finv[r] * finv[n-r] % mod) % mod modulo = 10**9+7 fact,finv,inv = init_fact(200000,modulo) ans = 0 for i in range(H-A): ans += nCr(i+B-1,i,modulo,fact,finv) * nCr(H-i-1+W-B-1,W-B-1,modulo,fact,finv) ans %= modulo print(ans)
# python3 (3.4.3) import sys input = sys.stdin.readline # functions def init_fact(n,mod): fact,finv,inv = [1]*n,[1]*n,[1]*n for i in range(2,n): fact[i] = (fact[i-1]*i) % mod inv[i] = mod - inv[mod%i] * (mod//i)%mod finv[i] = finv[i-1] * inv[i] % mod return (fact,finv,inv) def nCr(n,r,mod,fact,finv): if n<r: return 0 else: return fact[n] * (finv[r] * finv[n-r] % mod) % mod # main H,W,A,B = list(map(int,input().split())) modulo = 10**9+7 fact,finv,inv = init_fact(200000,modulo) ans = 0 for i in range(H-A): ans += nCr(i+B-1,i,modulo,fact,finv) * nCr(H-i-1+W-B-1,W-B-1,modulo,fact,finv) ans %= modulo print(ans)
25
31
631
714
H, W, A, B = list(map(int, input().split())) def init_fact(n, mod): fact, finv, inv = [1] * n, [1] * n, [1] * n for i in range(2, n): fact[i] = (fact[i - 1] * i) % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod finv[i] = finv[i - 1] * inv[i] % mod return (fact, finv, inv) def nCr(n, r, mod, fact, finv): if n < r: return 0 else: return fact[n] * (finv[r] * finv[n - r] % mod) % mod modulo = 10**9 + 7 fact, finv, inv = init_fact(200000, modulo) ans = 0 for i in range(H - A): ans += nCr(i + B - 1, i, modulo, fact, finv) * nCr( H - i - 1 + W - B - 1, W - B - 1, modulo, fact, finv ) ans %= modulo print(ans)
# python3 (3.4.3) import sys input = sys.stdin.readline # functions def init_fact(n, mod): fact, finv, inv = [1] * n, [1] * n, [1] * n for i in range(2, n): fact[i] = (fact[i - 1] * i) % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod finv[i] = finv[i - 1] * inv[i] % mod return (fact, finv, inv) def nCr(n, r, mod, fact, finv): if n < r: return 0 else: return fact[n] * (finv[r] * finv[n - r] % mod) % mod # main H, W, A, B = list(map(int, input().split())) modulo = 10**9 + 7 fact, finv, inv = init_fact(200000, modulo) ans = 0 for i in range(H - A): ans += nCr(i + B - 1, i, modulo, fact, finv) * nCr( H - i - 1 + W - B - 1, W - B - 1, modulo, fact, finv ) ans %= modulo print(ans)
false
19.354839
[ "-H, W, A, B = list(map(int, input().split()))", "+# python3 (3.4.3)", "+import sys", "-", "+input = sys.stdin.readline", "+# functions", "+# main", "+H, W, A, B = list(map(int, input().split()))" ]
false
0.293011
1.065677
0.274953
[ "s756476304", "s327530695" ]
u909643606
p03380
python
s804532845
s344659177
121
72
14,052
14,056
Accepted
Accepted
40.5
n=int(eval(input())) a=[int(i) for i in input().split()] a.sort() enu=max(a) k=(enu)/2 sa=10000000000000000000000000000 for i in range(n-1): if abs(k-a[i])<sa: sa=k-a[i] aru=a[i] print((enu,aru))
n=int(eval(input())) a=[int(i) for i in input().split()] enu=max(a) k=(enu)/2 sa=float("inf") for i in range(n): if abs(k-a[i])<sa and a[i]!=enu: sa=abs(k-a[i]) aru=a[i] print((enu,aru))
14
14
223
219
n = int(eval(input())) a = [int(i) for i in input().split()] a.sort() enu = max(a) k = (enu) / 2 sa = 10000000000000000000000000000 for i in range(n - 1): if abs(k - a[i]) < sa: sa = k - a[i] aru = a[i] print((enu, aru))
n = int(eval(input())) a = [int(i) for i in input().split()] enu = max(a) k = (enu) / 2 sa = float("inf") for i in range(n): if abs(k - a[i]) < sa and a[i] != enu: sa = abs(k - a[i]) aru = a[i] print((enu, aru))
false
0
[ "-a.sort()", "-sa = 10000000000000000000000000000", "-for i in range(n - 1):", "- if abs(k - a[i]) < sa:", "- sa = k - a[i]", "+sa = float(\"inf\")", "+for i in range(n):", "+ if abs(k - a[i]) < sa and a[i] != enu:", "+ sa = abs(k - a[i])" ]
false
0.054582
0.037388
1.459888
[ "s804532845", "s344659177" ]
u580093517
p03292
python
s200482300
s955785936
19
17
3,060
2,940
Accepted
Accepted
10.53
c = list(map(int,input().split())) x = max(c) c.remove(x) y = max(c) c.remove(y) z = max(c) c.remove(z) print((x - z))
*a, = list(map(int,input().split())) print((max(a)-min(a)))
9
2
125
52
c = list(map(int, input().split())) x = max(c) c.remove(x) y = max(c) c.remove(y) z = max(c) c.remove(z) print((x - z))
(*a,) = list(map(int, input().split())) print((max(a) - min(a)))
false
77.777778
[ "-c = list(map(int, input().split()))", "-x = max(c)", "-c.remove(x)", "-y = max(c)", "-c.remove(y)", "-z = max(c)", "-c.remove(z)", "-print((x - z))", "+(*a,) = list(map(int, input().split()))", "+print((max(a) - min(a)))" ]
false
0.053133
0.044139
1.203759
[ "s200482300", "s955785936" ]
u222668979
p03347
python
s440687757
s481677789
369
251
83,504
88,024
Accepted
Accepted
31.98
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] ans, tmp = 0, 0 for i in range(n - 1, 0, -1): if a[i] - a[i - 1] > 1: print((-1)) break if tmp != a[i]: ans += a[i] tmp = max(a[i] - 1, 0) else: print((ans if a[0] == 0 else - 1))
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] ans, tmp = 0, 0 for i in range(n - 1, 0, -1): if a[i] - a[i - 1] > 1: print((-1)) break if tmp != a[i]: ans += a[i] tmp = max(a[i] - 1, 0) else: print((-1 if a[0] > 0 else ans))
13
13
283
281
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] ans, tmp = 0, 0 for i in range(n - 1, 0, -1): if a[i] - a[i - 1] > 1: print((-1)) break if tmp != a[i]: ans += a[i] tmp = max(a[i] - 1, 0) else: print((ans if a[0] == 0 else -1))
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] ans, tmp = 0, 0 for i in range(n - 1, 0, -1): if a[i] - a[i - 1] > 1: print((-1)) break if tmp != a[i]: ans += a[i] tmp = max(a[i] - 1, 0) else: print((-1 if a[0] > 0 else ans))
false
0
[ "- print((ans if a[0] == 0 else -1))", "+ print((-1 if a[0] > 0 else ans))" ]
false
0.034451
0.031812
1.082977
[ "s440687757", "s481677789" ]
u095426154
p03472
python
s082676013
s012348250
493
206
29,296
86,712
Accepted
Accepted
58.22
N,H=list(map(int,input().split())) ab=[] a=[] b=[] for i in range(N): ab.append(list(map(int,input().split()))) a.append(ab[i][0]) b.append(ab[i][1]) a.sort(reverse=True) b.sort(reverse=True) k=0 cnt=0 while a[0]<b[k]: H-=b[k] cnt+=1 if H<=0: break k+=1 if k==len(b): break #print(cnt,H) H=max(H,0) if H%a[0]==0: cnt+=H//a[0] else: cnt+=H//a[0]+1 print(cnt)
# coding: utf-8 N,H=list(map(int,input().split())) A=[] B=[] for i in range(N): a,b=list(map(int,input().split())) A.append(a) B.append(b) MA=max(A) ans=0 B.sort() k=-1 while B[k]>MA: H-=B[k] k-=1 ans+=1 if H<=0: break if k<-N: break if H>=0: ans+=-(-H//MA) print(ans)
33
27
445
338
N, H = list(map(int, input().split())) ab = [] a = [] b = [] for i in range(N): ab.append(list(map(int, input().split()))) a.append(ab[i][0]) b.append(ab[i][1]) a.sort(reverse=True) b.sort(reverse=True) k = 0 cnt = 0 while a[0] < b[k]: H -= b[k] cnt += 1 if H <= 0: break k += 1 if k == len(b): break # print(cnt,H) H = max(H, 0) if H % a[0] == 0: cnt += H // a[0] else: cnt += H // a[0] + 1 print(cnt)
# coding: utf-8 N, H = list(map(int, input().split())) A = [] B = [] for i in range(N): a, b = list(map(int, input().split())) A.append(a) B.append(b) MA = max(A) ans = 0 B.sort() k = -1 while B[k] > MA: H -= B[k] k -= 1 ans += 1 if H <= 0: break if k < -N: break if H >= 0: ans += -(-H // MA) print(ans)
false
18.181818
[ "+# coding: utf-8", "-ab = []", "-a = []", "-b = []", "+A = []", "+B = []", "- ab.append(list(map(int, input().split())))", "- a.append(ab[i][0])", "- b.append(ab[i][1])", "-a.sort(reverse=True)", "-b.sort(reverse=True)", "-k = 0", "-cnt = 0", "-while a[0] < b[k]:", "- H -= b[k]", "- cnt += 1", "+ a, b = list(map(int, input().split()))", "+ A.append(a)", "+ B.append(b)", "+MA = max(A)", "+ans = 0", "+B.sort()", "+k = -1", "+while B[k] > MA:", "+ H -= B[k]", "+ k -= 1", "+ ans += 1", "- k += 1", "- if k == len(b):", "+ if k < -N:", "-# print(cnt,H)", "-H = max(H, 0)", "-if H % a[0] == 0:", "- cnt += H // a[0]", "-else:", "- cnt += H // a[0] + 1", "-print(cnt)", "+if H >= 0:", "+ ans += -(-H // MA)", "+print(ans)" ]
false
0.037534
0.037783
0.993405
[ "s082676013", "s012348250" ]
u077337864
p03865
python
s660871965
s980561684
31
17
3,316
3,316
Accepted
Accepted
45.16
s = input().strip() is_first = True for s1, s2 in zip(s, s[2:]): if s1 != s2: is_first = False if is_first: print('Second') else: if len(s) % 2 == 0: if s[0] == s[-1]: print('First') else: print('Second') else: if s[0] == s[-1]: print('Second') else: print('First')
def main(): s = input().strip() if len(s) % 2 == 0: if s[0] == s[-1]: print('First') else: print('Second') else: if s[0] == s[-1]: print('Second') else: print('First') if __name__ == '__main__': main()
20
16
338
267
s = input().strip() is_first = True for s1, s2 in zip(s, s[2:]): if s1 != s2: is_first = False if is_first: print("Second") else: if len(s) % 2 == 0: if s[0] == s[-1]: print("First") else: print("Second") else: if s[0] == s[-1]: print("Second") else: print("First")
def main(): s = input().strip() if len(s) % 2 == 0: if s[0] == s[-1]: print("First") else: print("Second") else: if s[0] == s[-1]: print("Second") else: print("First") if __name__ == "__main__": main()
false
20
[ "-s = input().strip()", "-is_first = True", "-for s1, s2 in zip(s, s[2:]):", "- if s1 != s2:", "- is_first = False", "-if is_first:", "- print(\"Second\")", "-else:", "+def main():", "+ s = input().strip()", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.050222
0.051437
0.976373
[ "s660871965", "s980561684" ]
u002459665
p02787
python
s908445759
s725562259
766
520
60,252
52,572
Accepted
Accepted
32.11
H, N = list(map(int, input().split())) A = [] for i in range(N): a = list(map(int, input().split())) A.append(a) INF = float('INF') MAX_J = (10 ** 4 + 1) * 2 # DP[i][j]: i番目までの魔法を使って、ダメージの総和をjにする魔力の最小値 DP = [INF] * MAX_J DP[0] = 0 for i in range(N): for j in range(MAX_J): nj = min(j+A[i][0], H) DP[nj] = min(DP[nj], DP[j] + A[i][1]) print((DP[H]))
H, N = list(map(int, input().split())) A = [] for i in range(N): a = list(map(int, input().split())) A.append(a) INF = float('INF') # MAX_J = (10 ** 4 + 1) * 2 MAX_J = 10 ** 4 + 1 # DP[i][j]: i番目までの魔法を使って、ダメージの総和をjにする魔力の最小値 DP = [INF] * MAX_J DP[0] = 0 for i in range(N): for j in range(MAX_J): # nj: 求める添字 # nj: i番目の魔法を使った後のダメージの総和(Hがmax) nj = min(j+A[i][0], H) # DP[nj]はすでに入っている値か、i番目の魔法を使った場合か DP[nj] = min(DP[nj], DP[j] + A[i][1]) # print(i, DP) print((DP[H]))
19
24
396
545
H, N = list(map(int, input().split())) A = [] for i in range(N): a = list(map(int, input().split())) A.append(a) INF = float("INF") MAX_J = (10**4 + 1) * 2 # DP[i][j]: i番目までの魔法を使って、ダメージの総和をjにする魔力の最小値 DP = [INF] * MAX_J DP[0] = 0 for i in range(N): for j in range(MAX_J): nj = min(j + A[i][0], H) DP[nj] = min(DP[nj], DP[j] + A[i][1]) print((DP[H]))
H, N = list(map(int, input().split())) A = [] for i in range(N): a = list(map(int, input().split())) A.append(a) INF = float("INF") # MAX_J = (10 ** 4 + 1) * 2 MAX_J = 10**4 + 1 # DP[i][j]: i番目までの魔法を使って、ダメージの総和をjにする魔力の最小値 DP = [INF] * MAX_J DP[0] = 0 for i in range(N): for j in range(MAX_J): # nj: 求める添字 # nj: i番目の魔法を使った後のダメージの総和(Hがmax) nj = min(j + A[i][0], H) # DP[nj]はすでに入っている値か、i番目の魔法を使った場合か DP[nj] = min(DP[nj], DP[j] + A[i][1]) # print(i, DP) print((DP[H]))
false
20.833333
[ "-MAX_J = (10**4 + 1) * 2", "+# MAX_J = (10 ** 4 + 1) * 2", "+MAX_J = 10**4 + 1", "+ # nj: 求める添字", "+ # nj: i番目の魔法を使った後のダメージの総和(Hがmax)", "+ # DP[nj]はすでに入っている値か、i番目の魔法を使った場合か", "+ # print(i, DP)" ]
false
0.214632
0.341685
0.628158
[ "s908445759", "s725562259" ]
u033606236
p03495
python
s023968502
s498463134
279
104
24,836
32,564
Accepted
Accepted
62.72
nums , types = list(map(int, input().split())) array = list(map(int,input().split())) array.sort() type_count = 0 count = 0 result = 0 ary_count = [] array.append(1000000000) for i in range (nums): if array[i] == array[i +1]: count += 1 elif array[i] < array[i +1]: ary_count.append(count) type_count += 1 count = 0 ary_count.sort() if type_count > types: for i in range(type_count - types): result += ary_count[i]+1 print(result)
from collections import Counter n,k = list(map(int,input().split())) ary = Counter(list(map(int,input().split()))) if len(list(ary.keys())) <= k:print((0));exit() print((sum(sorted(ary.values())[:len(list(ary.keys()))-k])))
23
5
501
205
nums, types = list(map(int, input().split())) array = list(map(int, input().split())) array.sort() type_count = 0 count = 0 result = 0 ary_count = [] array.append(1000000000) for i in range(nums): if array[i] == array[i + 1]: count += 1 elif array[i] < array[i + 1]: ary_count.append(count) type_count += 1 count = 0 ary_count.sort() if type_count > types: for i in range(type_count - types): result += ary_count[i] + 1 print(result)
from collections import Counter n, k = list(map(int, input().split())) ary = Counter(list(map(int, input().split()))) if len(list(ary.keys())) <= k: print((0)) exit() print((sum(sorted(ary.values())[: len(list(ary.keys())) - k])))
false
78.26087
[ "-nums, types = list(map(int, input().split()))", "-array = list(map(int, input().split()))", "-array.sort()", "-type_count = 0", "-count = 0", "-result = 0", "-ary_count = []", "-array.append(1000000000)", "-for i in range(nums):", "- if array[i] == array[i + 1]:", "- count += 1", "- elif array[i] < array[i + 1]:", "- ary_count.append(count)", "- type_count += 1", "- count = 0", "-ary_count.sort()", "-if type_count > types:", "- for i in range(type_count - types):", "- result += ary_count[i] + 1", "-print(result)", "+from collections import Counter", "+", "+n, k = list(map(int, input().split()))", "+ary = Counter(list(map(int, input().split())))", "+if len(list(ary.keys())) <= k:", "+ print((0))", "+ exit()", "+print((sum(sorted(ary.values())[: len(list(ary.keys())) - k])))" ]
false
0.071799
0.071962
0.997734
[ "s023968502", "s498463134" ]
u813387707
p03720
python
s034086702
s796411204
30
27
9,044
9,060
Accepted
Accepted
10
n, m = [int(x) for x in input().split()] ans = [0] * n for _ in range(m): a, b = [int(x) - 1 for x in input().split()] ans[a] += 1 ans[b] += 1 print((*ans))
n, m = [int(x) for x in input().split()] ans = [0] * n for _ in range(m): a, b = [int(x) - 1 for x in input().split()] ans[a] += 1 ans[b] += 1 print(("\n".join([str(x) for x in ans])))
7
7
172
200
n, m = [int(x) for x in input().split()] ans = [0] * n for _ in range(m): a, b = [int(x) - 1 for x in input().split()] ans[a] += 1 ans[b] += 1 print((*ans))
n, m = [int(x) for x in input().split()] ans = [0] * n for _ in range(m): a, b = [int(x) - 1 for x in input().split()] ans[a] += 1 ans[b] += 1 print(("\n".join([str(x) for x in ans])))
false
0
[ "-print((*ans))", "+print((\"\\n\".join([str(x) for x in ans])))" ]
false
0.055696
0.171867
0.324066
[ "s034086702", "s796411204" ]
u353919145
p03307
python
s648757483
s238501837
35
17
27,884
2,940
Accepted
Accepted
51.43
#jiaofhaosfhao n=int(eval(input())) if(n%2==1): n*=2 print(n)
def minDiv(): N = eval(input()) N = int(N) if N%2 == 0: print(N) else: print((N*2)) minDiv()
5
9
60
101
# jiaofhaosfhao n = int(eval(input())) if n % 2 == 1: n *= 2 print(n)
def minDiv(): N = eval(input()) N = int(N) if N % 2 == 0: print(N) else: print((N * 2)) minDiv()
false
44.444444
[ "-# jiaofhaosfhao", "-n = int(eval(input()))", "-if n % 2 == 1:", "- n *= 2", "-print(n)", "+def minDiv():", "+ N = eval(input())", "+ N = int(N)", "+ if N % 2 == 0:", "+ print(N)", "+ else:", "+ print((N * 2))", "+", "+", "+minDiv()" ]
false
0.035051
0.036327
0.964878
[ "s648757483", "s238501837" ]
u017415492
p03472
python
s580313852
s791770340
419
235
28,560
16,836
Accepted
Accepted
43.91
n,h=list(map(int,input().split())) ab=[list(map(int,input().split())) for i in range(n)] a_max=0 b=[] ans=0 kaisuu=0 for i in range(n): if a_max<ab[i][0]: a_max=ab[i][0] for i in range(n): b.append(ab[i][1]) b.sort(reverse=True) i=0 while True: if len(b)>i and a_max<b[i]: h-=b[i] kaisuu+=1 else: if h%a_max==0: kaisuu+=(h//a_max) else: kaisuu+=((h//a_max)+1) break if h<=0: break i+=1 print(kaisuu)
n,h=list(map(int,input().split())) A=[] B=[] for i in range(n): a,b=list(map(int,input().split())) A.append(a) B.append(b) A=max(A) B.sort(reverse=True) count=0 for i in B: if A>i: break else: if h>0: h-=i count+=1 else: break if h%A==0 and h>0: print((count+h//A)) elif h%A!=0 and h>0: print((count+h//A+1)) else: print(count)
27
25
473
381
n, h = list(map(int, input().split())) ab = [list(map(int, input().split())) for i in range(n)] a_max = 0 b = [] ans = 0 kaisuu = 0 for i in range(n): if a_max < ab[i][0]: a_max = ab[i][0] for i in range(n): b.append(ab[i][1]) b.sort(reverse=True) i = 0 while True: if len(b) > i and a_max < b[i]: h -= b[i] kaisuu += 1 else: if h % a_max == 0: kaisuu += h // a_max else: kaisuu += (h // a_max) + 1 break if h <= 0: break i += 1 print(kaisuu)
n, h = list(map(int, input().split())) A = [] B = [] for i in range(n): a, b = list(map(int, input().split())) A.append(a) B.append(b) A = max(A) B.sort(reverse=True) count = 0 for i in B: if A > i: break else: if h > 0: h -= i count += 1 else: break if h % A == 0 and h > 0: print((count + h // A)) elif h % A != 0 and h > 0: print((count + h // A + 1)) else: print(count)
false
7.407407
[ "-ab = [list(map(int, input().split())) for i in range(n)]", "-a_max = 0", "-b = []", "-ans = 0", "-kaisuu = 0", "+A = []", "+B = []", "- if a_max < ab[i][0]:", "- a_max = ab[i][0]", "-for i in range(n):", "- b.append(ab[i][1])", "-b.sort(reverse=True)", "-i = 0", "-while True:", "- if len(b) > i and a_max < b[i]:", "- h -= b[i]", "- kaisuu += 1", "+ a, b = list(map(int, input().split()))", "+ A.append(a)", "+ B.append(b)", "+A = max(A)", "+B.sort(reverse=True)", "+count = 0", "+for i in B:", "+ if A > i:", "+ break", "- if h % a_max == 0:", "- kaisuu += h // a_max", "+ if h > 0:", "+ h -= i", "+ count += 1", "- kaisuu += (h // a_max) + 1", "- break", "- if h <= 0:", "- break", "- i += 1", "-print(kaisuu)", "+ break", "+if h % A == 0 and h > 0:", "+ print((count + h // A))", "+elif h % A != 0 and h > 0:", "+ print((count + h // A + 1))", "+else:", "+ print(count)" ]
false
0.041835
0.03557
1.176156
[ "s580313852", "s791770340" ]
u314050667
p03805
python
s308081746
s368192756
185
35
3,444
3,064
Accepted
Accepted
81.08
import copy N, M = list(map(int,input().split())) E = [list(map(int, input().split())) for _ in range(M)] def dfs(flg, E, i): q = [] for e in E: if e[0] == i: if flg[e[1]-1] == 0: q.append(e[1]) if e[1] == i: if flg[e[0]-1] == 0: q.append(e[0]) if len(q) == 0: if flg.count(0) == 0: return 1 else: return 0 ans = 0 for n in q: temp = copy.deepcopy(flg) temp[n-1] = 1 ans += dfs(temp, E, n) return ans flg = [0 for _ in range(N)] flg[0] = 1 print((dfs(flg, E, 1)))
N, M = list(map(int, input().split())) E = [[] for _ in range(N)] for _ in range(M): ta, tb = list(map(int, input().split())) E[ta-1].append(tb-1) E[tb-1].append(ta-1) def next_permutation(out, cnt, flg): if cnt == N: for i in range(N-1): if out[i+1] not in E[out[i]]: return 0 return 1 ans = 0 for i in range(N): if flg[i] == 0: out.append(i) flg[i] = 1 ans += next_permutation(out, cnt+1, flg) out.pop() flg[i] = 0 return ans perm = [0] cnt = 1 flg = [0 for _ in range(N)] flg[0] = 1 answer = next_permutation(perm, cnt, flg) print(answer)
33
38
534
612
import copy N, M = list(map(int, input().split())) E = [list(map(int, input().split())) for _ in range(M)] def dfs(flg, E, i): q = [] for e in E: if e[0] == i: if flg[e[1] - 1] == 0: q.append(e[1]) if e[1] == i: if flg[e[0] - 1] == 0: q.append(e[0]) if len(q) == 0: if flg.count(0) == 0: return 1 else: return 0 ans = 0 for n in q: temp = copy.deepcopy(flg) temp[n - 1] = 1 ans += dfs(temp, E, n) return ans flg = [0 for _ in range(N)] flg[0] = 1 print((dfs(flg, E, 1)))
N, M = list(map(int, input().split())) E = [[] for _ in range(N)] for _ in range(M): ta, tb = list(map(int, input().split())) E[ta - 1].append(tb - 1) E[tb - 1].append(ta - 1) def next_permutation(out, cnt, flg): if cnt == N: for i in range(N - 1): if out[i + 1] not in E[out[i]]: return 0 return 1 ans = 0 for i in range(N): if flg[i] == 0: out.append(i) flg[i] = 1 ans += next_permutation(out, cnt + 1, flg) out.pop() flg[i] = 0 return ans perm = [0] cnt = 1 flg = [0 for _ in range(N)] flg[0] = 1 answer = next_permutation(perm, cnt, flg) print(answer)
false
13.157895
[ "-import copy", "-", "-E = [list(map(int, input().split())) for _ in range(M)]", "+E = [[] for _ in range(N)]", "+for _ in range(M):", "+ ta, tb = list(map(int, input().split()))", "+ E[ta - 1].append(tb - 1)", "+ E[tb - 1].append(ta - 1)", "-def dfs(flg, E, i):", "- q = []", "- for e in E:", "- if e[0] == i:", "- if flg[e[1] - 1] == 0:", "- q.append(e[1])", "- if e[1] == i:", "- if flg[e[0] - 1] == 0:", "- q.append(e[0])", "- if len(q) == 0:", "- if flg.count(0) == 0:", "- return 1", "- else:", "- return 0", "+def next_permutation(out, cnt, flg):", "+ if cnt == N:", "+ for i in range(N - 1):", "+ if out[i + 1] not in E[out[i]]:", "+ return 0", "+ return 1", "- for n in q:", "- temp = copy.deepcopy(flg)", "- temp[n - 1] = 1", "- ans += dfs(temp, E, n)", "+ for i in range(N):", "+ if flg[i] == 0:", "+ out.append(i)", "+ flg[i] = 1", "+ ans += next_permutation(out, cnt + 1, flg)", "+ out.pop()", "+ flg[i] = 0", "+perm = [0]", "+cnt = 1", "-print((dfs(flg, E, 1)))", "+answer = next_permutation(perm, cnt, flg)", "+print(answer)" ]
false
0.061217
0.043961
1.392537
[ "s308081746", "s368192756" ]
u952708174
p02802
python
s043879045
s560505738
266
245
20,500
4,596
Accepted
Accepted
7.89
def c_welcome_to_atcoder(): N, M = [int(i) for i in input().split()] Results = [] for _ in range(M): p, s = input().split() Results.append((int(p), s)) count_wa = [0] * (N + 1) is_already_ac = [False] * (N + 1) for p, s in Results: if is_already_ac[p]: continue if s == 'AC': is_already_ac[p] = True elif s == 'WA': count_wa[p] += 1 ans_ac = 0 ans_wa = 0 for ac, wa in zip(is_already_ac, count_wa): if ac: ans_ac += 1 ans_wa += wa return '{} {}'.format(ans_ac, ans_wa) print((c_welcome_to_atcoder()))
def c_welcome_to_atcoder(): N, M = [int(i) for i in input().split()] count_wa = [0] * (N + 1) is_already_ac = [False] * (N + 1) for _ in range(M): p, s = input().split() p = int(p) if is_already_ac[p]: continue if s == 'AC': is_already_ac[p] = True elif s == 'WA': count_wa[p] += 1 accepted, wrong = 0, 0 for ac, wa in zip(is_already_ac, count_wa): if ac: accepted += 1 wrong += wa return '{} {}'.format(accepted, wrong) print((c_welcome_to_atcoder()))
28
24
678
613
def c_welcome_to_atcoder(): N, M = [int(i) for i in input().split()] Results = [] for _ in range(M): p, s = input().split() Results.append((int(p), s)) count_wa = [0] * (N + 1) is_already_ac = [False] * (N + 1) for p, s in Results: if is_already_ac[p]: continue if s == "AC": is_already_ac[p] = True elif s == "WA": count_wa[p] += 1 ans_ac = 0 ans_wa = 0 for ac, wa in zip(is_already_ac, count_wa): if ac: ans_ac += 1 ans_wa += wa return "{} {}".format(ans_ac, ans_wa) print((c_welcome_to_atcoder()))
def c_welcome_to_atcoder(): N, M = [int(i) for i in input().split()] count_wa = [0] * (N + 1) is_already_ac = [False] * (N + 1) for _ in range(M): p, s = input().split() p = int(p) if is_already_ac[p]: continue if s == "AC": is_already_ac[p] = True elif s == "WA": count_wa[p] += 1 accepted, wrong = 0, 0 for ac, wa in zip(is_already_ac, count_wa): if ac: accepted += 1 wrong += wa return "{} {}".format(accepted, wrong) print((c_welcome_to_atcoder()))
false
14.285714
[ "- Results = []", "+ count_wa = [0] * (N + 1)", "+ is_already_ac = [False] * (N + 1)", "- Results.append((int(p), s))", "- count_wa = [0] * (N + 1)", "- is_already_ac = [False] * (N + 1)", "- for p, s in Results:", "+ p = int(p)", "- ans_ac = 0", "- ans_wa = 0", "+ accepted, wrong = 0, 0", "- ans_ac += 1", "- ans_wa += wa", "- return \"{} {}\".format(ans_ac, ans_wa)", "+ accepted += 1", "+ wrong += wa", "+ return \"{} {}\".format(accepted, wrong)" ]
false
0.094507
0.095196
0.992765
[ "s043879045", "s560505738" ]
u057964173
p03943
python
s875663261
s233823264
21
17
3,316
2,940
Accepted
Accepted
19.05
def resolve(): a,b,c=list(map(int, input().split())) if a==b+c or b==a+c or c==a+b: print('Yes') else: print('No') resolve()
def resolve(): l=list(map(int, input().split())) l.sort(reverse=True) if l[0]==l[1]+l[2]: print('Yes') else: print('No') resolve()
7
8
152
169
def resolve(): a, b, c = list(map(int, input().split())) if a == b + c or b == a + c or c == a + b: print("Yes") else: print("No") resolve()
def resolve(): l = list(map(int, input().split())) l.sort(reverse=True) if l[0] == l[1] + l[2]: print("Yes") else: print("No") resolve()
false
12.5
[ "- a, b, c = list(map(int, input().split()))", "- if a == b + c or b == a + c or c == a + b:", "+ l = list(map(int, input().split()))", "+ l.sort(reverse=True)", "+ if l[0] == l[1] + l[2]:" ]
false
0.040292
0.03975
1.013617
[ "s875663261", "s233823264" ]
u604774382
p02271
python
s295906456
s366594079
40
20
6,724
4,292
Accepted
Accepted
50
isExist = [False]*2001 n = int( eval(input()) ) A = [ int( val ) for val in input().rstrip().split( ' ' ) ] for i in A: for j in range( 2000-i, 0, -1 ): if isExist[j]: isExist[ i+j ] = True isExist[i] = True q = int( eval(input()) ) M = [ int( val ) for val in input().rstrip().split( ' ' ) ] for i in range( 0, q ): if isExist[ M[i] ]: print( "yes" ) else: print( "no" )
isExist = [False]*2001 n = int( input() ) A = [ int( val ) for val in input().rstrip().split( ' ' ) ] for i in A: for j in range( 2000-i, 0, -1 ): if isExist[j]: isExist[ i+j ] = True isExist[i] = True q = int( input() ) M = [ int( val ) for val in input().rstrip().split( ' ' ) ] for i in range( 0, q ): if isExist[ M[i] ]: print( "yes" ) else: print( "no" )
16
16
389
405
isExist = [False] * 2001 n = int(eval(input())) A = [int(val) for val in input().rstrip().split(" ")] for i in A: for j in range(2000 - i, 0, -1): if isExist[j]: isExist[i + j] = True isExist[i] = True q = int(eval(input())) M = [int(val) for val in input().rstrip().split(" ")] for i in range(0, q): if isExist[M[i]]: print("yes") else: print("no")
isExist = [False] * 2001 n = int(input()) A = [int(val) for val in input().rstrip().split(" ")] for i in A: for j in range(2000 - i, 0, -1): if isExist[j]: isExist[i + j] = True isExist[i] = True q = int(input()) M = [int(val) for val in input().rstrip().split(" ")] for i in range(0, q): if isExist[M[i]]: print("yes") else: print("no")
false
0
[ "-n = int(eval(input()))", "+n = int(input())", "-q = int(eval(input()))", "+q = int(input())" ]
false
0.077154
0.035668
2.163101
[ "s295906456", "s366594079" ]
u241159583
p03796
python
s424334073
s275138002
40
35
2,940
2,940
Accepted
Accepted
12.5
N = int(eval(input())) MOD = 10 ** 9 + 7 power = 1 for i in range(1, N+1): power *= i power %= MOD print(power)
n = int(eval(input())) MOD = 10**9+7 p = 1 for i in range(1,n+1): p = (p*i) % MOD print(p)
8
6
121
91
N = int(eval(input())) MOD = 10**9 + 7 power = 1 for i in range(1, N + 1): power *= i power %= MOD print(power)
n = int(eval(input())) MOD = 10**9 + 7 p = 1 for i in range(1, n + 1): p = (p * i) % MOD print(p)
false
25
[ "-N = int(eval(input()))", "+n = int(eval(input()))", "-power = 1", "-for i in range(1, N + 1):", "- power *= i", "- power %= MOD", "-print(power)", "+p = 1", "+for i in range(1, n + 1):", "+ p = (p * i) % MOD", "+print(p)" ]
false
0.057406
0.042169
1.361318
[ "s424334073", "s275138002" ]
u945181840
p03835
python
s489577397
s102651936
1,884
19
3,060
2,940
Accepted
Accepted
98.99
K, S = list(map(int, input().split())) ans = 0 for i in range(K + 1): if i > S: break for j in range(K + 1): s = i + j if s > S: break Z = S - s if 0 <= Z <= K: ans += 1 print(ans)
K, S = list(map(int, input().split())) ans = 0 for i in range(min(S + 1, K + 1)): s = S - i if s > 2 * K: continue ans += min(K, s) - max(0, s - K) + 1 print(ans)
15
9
262
185
K, S = list(map(int, input().split())) ans = 0 for i in range(K + 1): if i > S: break for j in range(K + 1): s = i + j if s > S: break Z = S - s if 0 <= Z <= K: ans += 1 print(ans)
K, S = list(map(int, input().split())) ans = 0 for i in range(min(S + 1, K + 1)): s = S - i if s > 2 * K: continue ans += min(K, s) - max(0, s - K) + 1 print(ans)
false
40
[ "-for i in range(K + 1):", "- if i > S:", "- break", "- for j in range(K + 1):", "- s = i + j", "- if s > S:", "- break", "- Z = S - s", "- if 0 <= Z <= K:", "- ans += 1", "+for i in range(min(S + 1, K + 1)):", "+ s = S - i", "+ if s > 2 * K:", "+ continue", "+ ans += min(K, s) - max(0, s - K) + 1" ]
false
0.050947
0.051713
0.98519
[ "s489577397", "s102651936" ]
u950708010
p03416
python
s334354402
s002729143
82
39
3,060
3,060
Accepted
Accepted
52.44
a,b = (int(i) for i in input().split()) ct= 0 for i in range(a,b+1): judge = str(i) if judge == judge[4]+judge[3]+judge[2]+judge[1]+judge[0]: ct += 1 print(ct)
def solve(): a,b = (int(i) for i in input().split()) ct = 0 for judge in range(a,b+1): j = str(judge) if j[0] == j[4] and j[1] == j[3]: ct += 1 print(ct) solve()
7
9
173
191
a, b = (int(i) for i in input().split()) ct = 0 for i in range(a, b + 1): judge = str(i) if judge == judge[4] + judge[3] + judge[2] + judge[1] + judge[0]: ct += 1 print(ct)
def solve(): a, b = (int(i) for i in input().split()) ct = 0 for judge in range(a, b + 1): j = str(judge) if j[0] == j[4] and j[1] == j[3]: ct += 1 print(ct) solve()
false
22.222222
[ "-a, b = (int(i) for i in input().split())", "-ct = 0", "-for i in range(a, b + 1):", "- judge = str(i)", "- if judge == judge[4] + judge[3] + judge[2] + judge[1] + judge[0]:", "- ct += 1", "-print(ct)", "+def solve():", "+ a, b = (int(i) for i in input().split())", "+ ct = 0", "+ for judge in range(a, b + 1):", "+ j = str(judge)", "+ if j[0] == j[4] and j[1] == j[3]:", "+ ct += 1", "+ print(ct)", "+", "+", "+solve()" ]
false
0.053339
0.044889
1.188248
[ "s334354402", "s002729143" ]
u979552932
p02936
python
s903396772
s533818632
1,959
864
105,164
91,852
Accepted
Accepted
55.9
from collections import deque def main(): n, q = list(map(int, input().split())) a = [[] for _ in range(n)] for i in range(n - 1): x, y = list(map(int, input().split())) a[x - 1].append(y - 1) a[y - 1].append(x - 1) p = [0] * n for i in range(q): x, y = list(map(int, input().split())) p[x - 1] += y c = [0] * n c[0] = 1 que = deque([]) que.append(0) while len(que) > 0: e = que.popleft() for i in a[e]: if c[i] > 0: continue c[i] = 1 p[i] += p[e] que.append(i) for i in range(n): print((p[i])) main()
from sys import stdin def main(): from collections import deque input = stdin.readline n, q = list(map(int, input().split())) a = [[] for _ in range(n)] for i in range(n - 1): x, y = list(map(int, input().split())) a[x - 1].append(y - 1) a[y - 1].append(x - 1) p = [0] * n for i in range(q): x, y = list(map(int, input().split())) p[x - 1] += y c = [0] * n c[0] = 1 que = deque([]) que.append(0) while len(que) > 0: e = que.popleft() for i in a[e]: if c[i] > 0: continue c[i] = 1 p[i] += p[e] que.append(i) for i in range(n): print((p[i])) main()
28
30
681
736
from collections import deque def main(): n, q = list(map(int, input().split())) a = [[] for _ in range(n)] for i in range(n - 1): x, y = list(map(int, input().split())) a[x - 1].append(y - 1) a[y - 1].append(x - 1) p = [0] * n for i in range(q): x, y = list(map(int, input().split())) p[x - 1] += y c = [0] * n c[0] = 1 que = deque([]) que.append(0) while len(que) > 0: e = que.popleft() for i in a[e]: if c[i] > 0: continue c[i] = 1 p[i] += p[e] que.append(i) for i in range(n): print((p[i])) main()
from sys import stdin def main(): from collections import deque input = stdin.readline n, q = list(map(int, input().split())) a = [[] for _ in range(n)] for i in range(n - 1): x, y = list(map(int, input().split())) a[x - 1].append(y - 1) a[y - 1].append(x - 1) p = [0] * n for i in range(q): x, y = list(map(int, input().split())) p[x - 1] += y c = [0] * n c[0] = 1 que = deque([]) que.append(0) while len(que) > 0: e = que.popleft() for i in a[e]: if c[i] > 0: continue c[i] = 1 p[i] += p[e] que.append(i) for i in range(n): print((p[i])) main()
false
6.666667
[ "-from collections import deque", "+from sys import stdin", "+ from collections import deque", "+", "+ input = stdin.readline" ]
false
0.036022
0.044993
0.80061
[ "s903396772", "s533818632" ]
u797673668
p02318
python
s113441559
s075480679
990
780
44,852
7,564
Accepted
Accepted
21.21
def levenshtein(str1, str2): l1, l2 = len(str1), len(str2) dp = [list(range(l2 + 1))] + [[i + 1] + [0] * l2 for i in range(l1)] for i1, c1 in enumerate(str1): for i2, c2 in enumerate(str2): dp[i1 + 1][i2 + 1] = min(dp[i1][i2 + 1] + 1, dp[i1 + 1][i2] + 1, dp[i1][i2] + int(c1 != c2)) return dp[l1][l2] print((levenshtein(eval(input()), eval(input()))))
def levenshtein(str1, str2): prev_dp = list(range(len(str2) + 1)) for i1, c1 in enumerate(str1): current_dp = [i1 + 1] for i2, c2 in enumerate(str2): current_dp.append(min(prev_dp[i2 + 1] + 1, current_dp[i2] + 1, prev_dp[i2] + int(c1 != c2))) prev_dp = current_dp return prev_dp[-1] print((levenshtein(eval(input()), eval(input()))))
12
13
388
383
def levenshtein(str1, str2): l1, l2 = len(str1), len(str2) dp = [list(range(l2 + 1))] + [[i + 1] + [0] * l2 for i in range(l1)] for i1, c1 in enumerate(str1): for i2, c2 in enumerate(str2): dp[i1 + 1][i2 + 1] = min( dp[i1][i2 + 1] + 1, dp[i1 + 1][i2] + 1, dp[i1][i2] + int(c1 != c2) ) return dp[l1][l2] print((levenshtein(eval(input()), eval(input()))))
def levenshtein(str1, str2): prev_dp = list(range(len(str2) + 1)) for i1, c1 in enumerate(str1): current_dp = [i1 + 1] for i2, c2 in enumerate(str2): current_dp.append( min( prev_dp[i2 + 1] + 1, current_dp[i2] + 1, prev_dp[i2] + int(c1 != c2) ) ) prev_dp = current_dp return prev_dp[-1] print((levenshtein(eval(input()), eval(input()))))
false
7.692308
[ "- l1, l2 = len(str1), len(str2)", "- dp = [list(range(l2 + 1))] + [[i + 1] + [0] * l2 for i in range(l1)]", "+ prev_dp = list(range(len(str2) + 1))", "+ current_dp = [i1 + 1]", "- dp[i1 + 1][i2 + 1] = min(", "- dp[i1][i2 + 1] + 1, dp[i1 + 1][i2] + 1, dp[i1][i2] + int(c1 != c2)", "+ current_dp.append(", "+ min(", "+ prev_dp[i2 + 1] + 1, current_dp[i2] + 1, prev_dp[i2] + int(c1 != c2)", "+ )", "- return dp[l1][l2]", "+ prev_dp = current_dp", "+ return prev_dp[-1]" ]
false
0.047646
0.042211
1.128744
[ "s113441559", "s075480679" ]
u303739137
p02984
python
s943360783
s932885751
132
92
14,028
19,144
Accepted
Accepted
30.3
n = int(eval(input())) aa = list(map(int, input().split())) total_odd = sum(aa[1::2]) total_eve = sum(aa[0::2]) tmp = total_eve - total_odd print(tmp) for i in range(1,n): tmp = 2*aa[i-1] - tmp print(tmp)
n = int(eval(input())) aa = list(map(int, input().split())) total_odd = sum(aa[1::2]) total_eve = sum(aa[0::2]) tmp = total_eve - total_odd outs = [tmp] for i in range(1,n): tmp = 2*aa[i-1] - tmp outs.append(tmp) print((' '.join(list(map(str,outs)))))
9
10
214
260
n = int(eval(input())) aa = list(map(int, input().split())) total_odd = sum(aa[1::2]) total_eve = sum(aa[0::2]) tmp = total_eve - total_odd print(tmp) for i in range(1, n): tmp = 2 * aa[i - 1] - tmp print(tmp)
n = int(eval(input())) aa = list(map(int, input().split())) total_odd = sum(aa[1::2]) total_eve = sum(aa[0::2]) tmp = total_eve - total_odd outs = [tmp] for i in range(1, n): tmp = 2 * aa[i - 1] - tmp outs.append(tmp) print((" ".join(list(map(str, outs)))))
false
10
[ "-print(tmp)", "+outs = [tmp]", "- print(tmp)", "+ outs.append(tmp)", "+print((\" \".join(list(map(str, outs)))))" ]
false
0.037016
0.037094
0.9979
[ "s943360783", "s932885751" ]
u905203728
p03044
python
s023187185
s990553501
842
633
101,336
97,372
Accepted
Accepted
24.82
from collections import deque def BFS(): color=["white" for _ in range(n)] D=[0]*n M=[[] for _ in range(n)] for u,v,w in UVW: M[u-1].append([v-1,w]) M[v-1].append([u-1,w]) D[0]=1 color[0]="gray" queue=deque([0]) while len(queue)>0: u=queue.popleft() for i,j in M[u]: if color[i]=="white": if j%2==0:D[i]=D[u] elif j%2==1:D[i]=-D[u] color[i]="gray" queue.append(i) color[u]="black" return D n=int(eval(input())) UVW=[list(map(int,input().split())) for _ in range(n-1)] for i in BFS(): if i==-1:print((0)) else:print(i)
from collections import deque import sys input=sys.stdin.readline def BFS(): color=["white" for _ in range(n)] D=[0]*n M=[[] for _ in range(n)] for u,v,w in UVW: M[u-1].append([v-1,w]) M[v-1].append([u-1,w]) D[0]=1 color[0]="gray" queue=deque([0]) while len(queue)>0: u=queue.popleft() for i,j in M[u]: if color[i]=="white": if j%2==0:D[i]=D[u] elif j%2==1:D[i]=-D[u] color[i]="gray" queue.append(i) color[u]="black" return D n=int(eval(input())) UVW=[list(map(int,input().split())) for _ in range(n-1)] for i in BFS(): if i==-1:print((0)) else:print(i)
34
36
710
748
from collections import deque def BFS(): color = ["white" for _ in range(n)] D = [0] * n M = [[] for _ in range(n)] for u, v, w in UVW: M[u - 1].append([v - 1, w]) M[v - 1].append([u - 1, w]) D[0] = 1 color[0] = "gray" queue = deque([0]) while len(queue) > 0: u = queue.popleft() for i, j in M[u]: if color[i] == "white": if j % 2 == 0: D[i] = D[u] elif j % 2 == 1: D[i] = -D[u] color[i] = "gray" queue.append(i) color[u] = "black" return D n = int(eval(input())) UVW = [list(map(int, input().split())) for _ in range(n - 1)] for i in BFS(): if i == -1: print((0)) else: print(i)
from collections import deque import sys input = sys.stdin.readline def BFS(): color = ["white" for _ in range(n)] D = [0] * n M = [[] for _ in range(n)] for u, v, w in UVW: M[u - 1].append([v - 1, w]) M[v - 1].append([u - 1, w]) D[0] = 1 color[0] = "gray" queue = deque([0]) while len(queue) > 0: u = queue.popleft() for i, j in M[u]: if color[i] == "white": if j % 2 == 0: D[i] = D[u] elif j % 2 == 1: D[i] = -D[u] color[i] = "gray" queue.append(i) color[u] = "black" return D n = int(eval(input())) UVW = [list(map(int, input().split())) for _ in range(n - 1)] for i in BFS(): if i == -1: print((0)) else: print(i)
false
5.555556
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.067113
0.064352
1.042919
[ "s023187185", "s990553501" ]
u644907318
p03999
python
s005719287
s710831361
187
84
39,024
73,804
Accepted
Accepted
55.08
from itertools import product S = input().strip() N = len(S) cnt = 0 for x in product((0,1),repeat=N-1): y = S[0] for i in range(N-1): if x[i]==1: y += "+" y += S[i+1] cnt += eval(y) print(cnt)
from itertools import product S = input().strip() N = len(S) cnt = 0 for x in product((0,1),repeat=N-1): y = "" for i in range(N-1): y += S[i] if x[i]==1: y += "+" y += S[N-1] cnt += eval(y) print(cnt)
12
13
244
257
from itertools import product S = input().strip() N = len(S) cnt = 0 for x in product((0, 1), repeat=N - 1): y = S[0] for i in range(N - 1): if x[i] == 1: y += "+" y += S[i + 1] cnt += eval(y) print(cnt)
from itertools import product S = input().strip() N = len(S) cnt = 0 for x in product((0, 1), repeat=N - 1): y = "" for i in range(N - 1): y += S[i] if x[i] == 1: y += "+" y += S[N - 1] cnt += eval(y) print(cnt)
false
7.692308
[ "- y = S[0]", "+ y = \"\"", "+ y += S[i]", "- y += S[i + 1]", "+ y += S[N - 1]" ]
false
0.083219
0.044554
1.867815
[ "s005719287", "s710831361" ]
u384679440
p03308
python
s688861335
s576100007
19
17
2,940
2,940
Accepted
Accepted
10.53
N = int(eval(input())) A = list(map(int, input().split())) ans = 0 for i in range(N): for j in range(i, N): ans = max(ans, abs(A[i] - A[j])) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) print((max(A) - min(A)))
7
3
154
77
N = int(eval(input())) A = list(map(int, input().split())) ans = 0 for i in range(N): for j in range(i, N): ans = max(ans, abs(A[i] - A[j])) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) print((max(A) - min(A)))
false
57.142857
[ "-ans = 0", "-for i in range(N):", "- for j in range(i, N):", "- ans = max(ans, abs(A[i] - A[j]))", "-print(ans)", "+print((max(A) - min(A)))" ]
false
0.038662
0.054317
0.711773
[ "s688861335", "s576100007" ]
u756388720
p02580
python
s589025417
s532260959
1,068
611
119,240
199,068
Accepted
Accepted
42.79
import sys H, W, M = list(map(int, input().split())) A = [list([int(x) - 1 for x in input().split()]) for i in range(M)] cnth = [0] * H cntw = [0] * W st = set() for y, x in A: cnth[y] += 1 cntw[x] += 1 st.add((y, x)) my = max(cnth) mx = max(cntw) Y = [] X = [] for i in range(H): if cnth[i] == my: Y.append(i) for i in range(W): if cntw[i] == mx: X.append(i) for y in Y: for x in X: if not (y, x) in st: print((my + mx)) exit(0) print((my + mx - 1))
def solve(): H, W, M = list(map(int, input().split())) N = 3 * 10 ** 5 cnth = [0] * N cntw = [0] * N dic = dict() for i in range(M): h, w = [int(x) - 1 for x in input().split()] cnth[h] += 1 cntw[w] += 1 dic[(h, w)] = 1 mh = max(cnth) mw = max(cntw) Y = [] X = [] for i in range(H): if cnth[i] == mh: Y.append(i) for i in range(W): if cntw[i] == mw: X.append(i) for y in Y: for x in X: if not (y, x) in dic: return mh + mw return mh + mw - 1 print((solve()))
35
28
561
648
import sys H, W, M = list(map(int, input().split())) A = [list([int(x) - 1 for x in input().split()]) for i in range(M)] cnth = [0] * H cntw = [0] * W st = set() for y, x in A: cnth[y] += 1 cntw[x] += 1 st.add((y, x)) my = max(cnth) mx = max(cntw) Y = [] X = [] for i in range(H): if cnth[i] == my: Y.append(i) for i in range(W): if cntw[i] == mx: X.append(i) for y in Y: for x in X: if not (y, x) in st: print((my + mx)) exit(0) print((my + mx - 1))
def solve(): H, W, M = list(map(int, input().split())) N = 3 * 10**5 cnth = [0] * N cntw = [0] * N dic = dict() for i in range(M): h, w = [int(x) - 1 for x in input().split()] cnth[h] += 1 cntw[w] += 1 dic[(h, w)] = 1 mh = max(cnth) mw = max(cntw) Y = [] X = [] for i in range(H): if cnth[i] == mh: Y.append(i) for i in range(W): if cntw[i] == mw: X.append(i) for y in Y: for x in X: if not (y, x) in dic: return mh + mw return mh + mw - 1 print((solve()))
false
20
[ "-import sys", "+def solve():", "+ H, W, M = list(map(int, input().split()))", "+ N = 3 * 10**5", "+ cnth = [0] * N", "+ cntw = [0] * N", "+ dic = dict()", "+ for i in range(M):", "+ h, w = [int(x) - 1 for x in input().split()]", "+ cnth[h] += 1", "+ cntw[w] += 1", "+ dic[(h, w)] = 1", "+ mh = max(cnth)", "+ mw = max(cntw)", "+ Y = []", "+ X = []", "+ for i in range(H):", "+ if cnth[i] == mh:", "+ Y.append(i)", "+ for i in range(W):", "+ if cntw[i] == mw:", "+ X.append(i)", "+ for y in Y:", "+ for x in X:", "+ if not (y, x) in dic:", "+ return mh + mw", "+ return mh + mw - 1", "-H, W, M = list(map(int, input().split()))", "-A = [list([int(x) - 1 for x in input().split()]) for i in range(M)]", "-cnth = [0] * H", "-cntw = [0] * W", "-st = set()", "-for y, x in A:", "- cnth[y] += 1", "- cntw[x] += 1", "- st.add((y, x))", "-my = max(cnth)", "-mx = max(cntw)", "-Y = []", "-X = []", "-for i in range(H):", "- if cnth[i] == my:", "- Y.append(i)", "-for i in range(W):", "- if cntw[i] == mx:", "- X.append(i)", "-for y in Y:", "- for x in X:", "- if not (y, x) in st:", "- print((my + mx))", "- exit(0)", "-print((my + mx - 1))", "+", "+print((solve()))" ]
false
0.042504
0.092234
0.460822
[ "s589025417", "s532260959" ]
u887207211
p03731
python
s801562523
s878347078
154
119
26,708
25,744
Accepted
Accepted
22.73
N, T = list(map(int,input().split())) t = list(map(int,input().split())) cnt = T for i in range(N-1): cnt += min(T, t[i+1]-t[i]) print(cnt)
import sys stdin = sys.stdin ns = lambda : stdin.readline().rstrip() ni = lambda : int(ns()) na = lambda : list(map(int, stdin.readline().split())) def main(): n, T = na() t = na() cnt = T for i in range(n - 1): cnt += min(T, t[i + 1] - t[i]) print(cnt) main()
7
18
142
296
N, T = list(map(int, input().split())) t = list(map(int, input().split())) cnt = T for i in range(N - 1): cnt += min(T, t[i + 1] - t[i]) print(cnt)
import sys stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) def main(): n, T = na() t = na() cnt = T for i in range(n - 1): cnt += min(T, t[i + 1] - t[i]) print(cnt) main()
false
61.111111
[ "-N, T = list(map(int, input().split()))", "-t = list(map(int, input().split()))", "-cnt = T", "-for i in range(N - 1):", "- cnt += min(T, t[i + 1] - t[i])", "-print(cnt)", "+import sys", "+", "+stdin = sys.stdin", "+ns = lambda: stdin.readline().rstrip()", "+ni = lambda: int(ns())", "+na = lambda: list(map(int, stdin.readline().split()))", "+", "+", "+def main():", "+ n, T = na()", "+ t = na()", "+ cnt = T", "+ for i in range(n - 1):", "+ cnt += min(T, t[i + 1] - t[i])", "+ print(cnt)", "+", "+", "+main()" ]
false
0.048909
0.128135
0.381701
[ "s801562523", "s878347078" ]
u145600939
p02623
python
s064608085
s480904536
187
143
111,024
117,796
Accepted
Accepted
23.53
from bisect import * n,m,k = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) sa = [0]*(n+1) sb = [0]*(m+1) for i in range(n): sa[i+1] = sa[i] + A[i] for i in range(m): sb[i+1] = sb[i] + B[i] ans = 0 for i,a in enumerate(sa): if a > k:break will = bisect_right(sb,k-a) ans = max(i + will - 1, ans) print(ans)
n,m,k = list(map(int, input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) def ruiseki(n, A): "長さnの数列Aの累積和を返す ただし[0] = 0" res = [0]*(n+1) for i in range(n): res[i+1] = res[i] + A[i] return res sa = ruiseki(n,A) sb = ruiseki(m,B) ans = 0 j = m for i,a in enumerate(sa): while j >= 0 and a+sb[j] > k: j -= 1 if j < 0:break ans = max(ans,i+j) print(ans)
16
21
390
450
from bisect import * n, m, k = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) sa = [0] * (n + 1) sb = [0] * (m + 1) for i in range(n): sa[i + 1] = sa[i] + A[i] for i in range(m): sb[i + 1] = sb[i] + B[i] ans = 0 for i, a in enumerate(sa): if a > k: break will = bisect_right(sb, k - a) ans = max(i + will - 1, ans) print(ans)
n, m, k = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) def ruiseki(n, A): "長さnの数列Aの累積和を返す ただし[0] = 0" res = [0] * (n + 1) for i in range(n): res[i + 1] = res[i] + A[i] return res sa = ruiseki(n, A) sb = ruiseki(m, B) ans = 0 j = m for i, a in enumerate(sa): while j >= 0 and a + sb[j] > k: j -= 1 if j < 0: break ans = max(ans, i + j) print(ans)
false
23.809524
[ "-from bisect import *", "-", "-sa = [0] * (n + 1)", "-sb = [0] * (m + 1)", "-for i in range(n):", "- sa[i + 1] = sa[i] + A[i]", "-for i in range(m):", "- sb[i + 1] = sb[i] + B[i]", "+", "+", "+def ruiseki(n, A):", "+ \"長さnの数列Aの累積和を返す ただし[0] = 0\"", "+ res = [0] * (n + 1)", "+ for i in range(n):", "+ res[i + 1] = res[i] + A[i]", "+ return res", "+", "+", "+sa = ruiseki(n, A)", "+sb = ruiseki(m, B)", "+j = m", "- if a > k:", "+ while j >= 0 and a + sb[j] > k:", "+ j -= 1", "+ if j < 0:", "- will = bisect_right(sb, k - a)", "- ans = max(i + will - 1, ans)", "+ ans = max(ans, i + j)" ]
false
0.058455
0.08268
0.706997
[ "s064608085", "s480904536" ]
u512212329
p02684
python
s732577196
s025886264
159
129
32,224
33,340
Accepted
Accepted
18.87
def main(): n, k = [int(x) for x in input().split()] teleporter = [int(x) - 1 for x in input().split()] route = [] route_append = route.append seen = [False] * n traveled, now_i = 0, 0 while traveled < n + 100: if seen[now_i]: # テレポートがループしたら,ルート調査は終了する。 break route_append(now_i) seen[now_i] = True now_i = teleporter[now_i] traveled += 1 # 調査終了後,now_1 はループ部分の頭。ループ前にイントロがある。 # ループ頭は何番目に尋ねるか? # intro_length = [i for i, x in enumerate(route) if x == now_i][-1] intro_length = route.index(now_i) loop_length = len(route) - intro_length if k >= intro_length: arriving_i = intro_length + (k - intro_length) % loop_length else: # k が イントロ内に収まっている場合。 arriving_i = k return route[arriving_i] + 1 if __name__ == '__main__': print((main()))
def main(): n, k = [int(x) for x in input().split()] teleporter = [int(x) - 1 for x in input().split()] route = [] route_append = route.append seen = [False] * n traveled, now_i = 0, 0 while True: if seen[now_i]: # テレポートがループしたら,ルート調査は終了する。 break route_append(now_i) seen[now_i] = True now_i = teleporter[now_i] traveled += 1 # 調査終了後,now_1 はループ部分の頭。ループ前にイントロがある。 # ループ頭は何番目に尋ねるか? intro_length = route.index(now_i) loop_length = len(route) - intro_length if k >= intro_length: arriving_i = intro_length + (k - intro_length) % loop_length else: # k が イントロ内に収まる場合。ここを見落としてWA連発! arriving_i = k return route[arriving_i] + 1 if __name__ == '__main__': print((main()))
32
31
918
841
def main(): n, k = [int(x) for x in input().split()] teleporter = [int(x) - 1 for x in input().split()] route = [] route_append = route.append seen = [False] * n traveled, now_i = 0, 0 while traveled < n + 100: if seen[now_i]: # テレポートがループしたら,ルート調査は終了する。 break route_append(now_i) seen[now_i] = True now_i = teleporter[now_i] traveled += 1 # 調査終了後,now_1 はループ部分の頭。ループ前にイントロがある。 # ループ頭は何番目に尋ねるか? # intro_length = [i for i, x in enumerate(route) if x == now_i][-1] intro_length = route.index(now_i) loop_length = len(route) - intro_length if k >= intro_length: arriving_i = intro_length + (k - intro_length) % loop_length else: # k が イントロ内に収まっている場合。 arriving_i = k return route[arriving_i] + 1 if __name__ == "__main__": print((main()))
def main(): n, k = [int(x) for x in input().split()] teleporter = [int(x) - 1 for x in input().split()] route = [] route_append = route.append seen = [False] * n traveled, now_i = 0, 0 while True: if seen[now_i]: # テレポートがループしたら,ルート調査は終了する。 break route_append(now_i) seen[now_i] = True now_i = teleporter[now_i] traveled += 1 # 調査終了後,now_1 はループ部分の頭。ループ前にイントロがある。 # ループ頭は何番目に尋ねるか? intro_length = route.index(now_i) loop_length = len(route) - intro_length if k >= intro_length: arriving_i = intro_length + (k - intro_length) % loop_length else: # k が イントロ内に収まる場合。ここを見落としてWA連発! arriving_i = k return route[arriving_i] + 1 if __name__ == "__main__": print((main()))
false
3.125
[ "- while traveled < n + 100:", "+ while True:", "- # intro_length = [i for i, x in enumerate(route) if x == now_i][-1]", "- # k が イントロ内に収まっている場合。", "+ # k が イントロ内に収まる場合。ここを見落としてWA連発!" ]
false
0.104636
0.121928
0.85818
[ "s732577196", "s025886264" ]
u893063840
p03240
python
s877999575
s362782463
49
44
9,164
9,216
Accepted
Accepted
10.2
n = int(eval(input())) xyh = [list(map(int, input().split())) for _ in range(n)] xyh.sort(key=lambda x: x[2], reverse=True) ans = [None] * 3 for cx in range(101): for cy in range(101): x0, y0, h0 = xyh[0] top = h0 + abs(x0 - cx) + abs(y0 - cy) bl = True for x, y, h in xyh[1:]: h_calc = max(top - abs(x - cx) - abs(y - cy), 0) if h_calc != h: bl = False break if bl: ans = [cx, cy, top] print((*ans))
n = int(eval(input())) xyh = [list(map(int, input().split())) for _ in range(n)] for x, y, h in xyh: if h > 0: x0, y0, h0 = x, y, h break ans = [None] * 3 for cx in range(101): for cy in range(101): top = h0 + abs(x0 - cx) + abs(y0 - cy) bl = True for x, y, h in xyh[1:]: h_calc = max(top - abs(x - cx) - abs(y - cy), 0) if h_calc != h: bl = False break if bl: ans = [cx, cy, top] print((*ans))
20
23
527
537
n = int(eval(input())) xyh = [list(map(int, input().split())) for _ in range(n)] xyh.sort(key=lambda x: x[2], reverse=True) ans = [None] * 3 for cx in range(101): for cy in range(101): x0, y0, h0 = xyh[0] top = h0 + abs(x0 - cx) + abs(y0 - cy) bl = True for x, y, h in xyh[1:]: h_calc = max(top - abs(x - cx) - abs(y - cy), 0) if h_calc != h: bl = False break if bl: ans = [cx, cy, top] print((*ans))
n = int(eval(input())) xyh = [list(map(int, input().split())) for _ in range(n)] for x, y, h in xyh: if h > 0: x0, y0, h0 = x, y, h break ans = [None] * 3 for cx in range(101): for cy in range(101): top = h0 + abs(x0 - cx) + abs(y0 - cy) bl = True for x, y, h in xyh[1:]: h_calc = max(top - abs(x - cx) - abs(y - cy), 0) if h_calc != h: bl = False break if bl: ans = [cx, cy, top] print((*ans))
false
13.043478
[ "-xyh.sort(key=lambda x: x[2], reverse=True)", "+for x, y, h in xyh:", "+ if h > 0:", "+ x0, y0, h0 = x, y, h", "+ break", "- x0, y0, h0 = xyh[0]" ]
false
0.125453
0.052774
2.377163
[ "s877999575", "s362782463" ]
u227082700
p03651
python
s137083384
s232872795
105
88
14,224
14,252
Accepted
Accepted
16.19
n,k=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() g=a[-1] def gcd(a,b): while b:a,b=b,a%b return a for i in a:g=gcd(g,i) if a[-1]<k or k%g!=0:print("IMPOSSIBLE") else:print("POSSIBLE")
def gcd(a,b): while b:a,b=b,a%b return a n,k=list(map(int,input().split())) a=list(map(int,input().split())) g=a[0] for i in a[1:]:g=gcd(g,i) ans="IMPOSSIBLE" for i in a: if k>i:continue if abs(k-i)%g==0:ans="POSSIBLE" print(ans)
10
12
218
242
n, k = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() g = a[-1] def gcd(a, b): while b: a, b = b, a % b return a for i in a: g = gcd(g, i) if a[-1] < k or k % g != 0: print("IMPOSSIBLE") else: print("POSSIBLE")
def gcd(a, b): while b: a, b = b, a % b return a n, k = list(map(int, input().split())) a = list(map(int, input().split())) g = a[0] for i in a[1:]: g = gcd(g, i) ans = "IMPOSSIBLE" for i in a: if k > i: continue if abs(k - i) % g == 0: ans = "POSSIBLE" print(ans)
false
16.666667
[ "-n, k = list(map(int, input().split()))", "-a = list(map(int, input().split()))", "-a.sort()", "-g = a[-1]", "-", "-", "+n, k = list(map(int, input().split()))", "+a = list(map(int, input().split()))", "+g = a[0]", "+for i in a[1:]:", "+ g = gcd(g, i)", "+ans = \"IMPOSSIBLE\"", "- g = gcd(g, i)", "-if a[-1] < k or k % g != 0:", "- print(\"IMPOSSIBLE\")", "-else:", "- print(\"POSSIBLE\")", "+ if k > i:", "+ continue", "+ if abs(k - i) % g == 0:", "+ ans = \"POSSIBLE\"", "+print(ans)" ]
false
0.040661
0.037137
1.094894
[ "s137083384", "s232872795" ]
u597455618
p03478
python
s942895753
s784679708
31
22
2,940
2,940
Accepted
Accepted
29.03
def main(): n, a, b = list(map(int, input().split())) cnt = 0 for i in range(1, n+1): if a <= sum(map(int, list(str(i)))) <= b: cnt += i print(cnt) if __name__ == '__main__': main()
def main(): n, a, b = list(map(int, input().split())) cnt = 0 for i in range(1, n+1): if a <= i//10000 + (i//1000)%10 + (i//100)%10 + (i//10)%10 + i%10<= b: cnt += i print(cnt) if __name__ == '__main__': main()
10
10
207
236
def main(): n, a, b = list(map(int, input().split())) cnt = 0 for i in range(1, n + 1): if a <= sum(map(int, list(str(i)))) <= b: cnt += i print(cnt) if __name__ == "__main__": main()
def main(): n, a, b = list(map(int, input().split())) cnt = 0 for i in range(1, n + 1): if ( a <= i // 10000 + (i // 1000) % 10 + (i // 100) % 10 + (i // 10) % 10 + i % 10 <= b ): cnt += i print(cnt) if __name__ == "__main__": main()
false
0
[ "- if a <= sum(map(int, list(str(i)))) <= b:", "+ if (", "+ a", "+ <= i // 10000 + (i // 1000) % 10 + (i // 100) % 10 + (i // 10) % 10 + i % 10", "+ <= b", "+ ):" ]
false
0.035975
0.05431
0.662397
[ "s942895753", "s784679708" ]
u189594456
p02995
python
s103034898
s832904295
19
17
3,188
3,064
Accepted
Accepted
10.53
def gcd(x, y): while(y): x, y = y, x % y return x a,b,c,d=list(map(int,input().split())) m=((c*d)//(gcd(c,d))) di=b-a+1 c1=(b//c-(a-1)//c) c2=(b//d-(a-1)//d) c3=(b//m-(a-1)//m) print((di-(c1+c2-c3)))
def gcd(x, y): while(y): x, y = y, x % y return x a,b,c,d=list(map(int,input().split())) m=((c*d)//(gcd(c,d))) di=b-a+1 if a%c==0: c1=(b//c-a//c)+1 else: c1=(b//c-a//c) if a%d==0: c2=(b//d-a//d)+1 else: c2=(b//d-a//d) if a%m==0: c3=(b//m-a//m)+1 else: c3=(b//m-a//m) print((di-(c1+c2-c3)))
11
20
214
326
def gcd(x, y): while y: x, y = y, x % y return x a, b, c, d = list(map(int, input().split())) m = (c * d) // (gcd(c, d)) di = b - a + 1 c1 = b // c - (a - 1) // c c2 = b // d - (a - 1) // d c3 = b // m - (a - 1) // m print((di - (c1 + c2 - c3)))
def gcd(x, y): while y: x, y = y, x % y return x a, b, c, d = list(map(int, input().split())) m = (c * d) // (gcd(c, d)) di = b - a + 1 if a % c == 0: c1 = (b // c - a // c) + 1 else: c1 = b // c - a // c if a % d == 0: c2 = (b // d - a // d) + 1 else: c2 = b // d - a // d if a % m == 0: c3 = (b // m - a // m) + 1 else: c3 = b // m - a // m print((di - (c1 + c2 - c3)))
false
45
[ "-c1 = b // c - (a - 1) // c", "-c2 = b // d - (a - 1) // d", "-c3 = b // m - (a - 1) // m", "+if a % c == 0:", "+ c1 = (b // c - a // c) + 1", "+else:", "+ c1 = b // c - a // c", "+if a % d == 0:", "+ c2 = (b // d - a // d) + 1", "+else:", "+ c2 = b // d - a // d", "+if a % m == 0:", "+ c3 = (b // m - a // m) + 1", "+else:", "+ c3 = b // m - a // m" ]
false
0.155253
0.042679
3.637677
[ "s103034898", "s832904295" ]
u175034939
p03862
python
s884916288
s824535472
164
103
14,132
14,132
Accepted
Accepted
37.2
n, x = list(map(int,input().split())) a = list(map(int,input().split())) cnt = 0 for i in range(1, n): if a[i] + a[i-1] > x: b = a[i] + a[i-1] - x minab = min(a[i], b) a[i] -= minab cnt += minab b -= minab cnt += b a[i-1] -= b print(cnt)
n, x = list(map(int,input().split())) a = list(map(int,input().split())) cnt = 0 if a[0] > x: cnt += a[0] - x a[0] = x for i in range(1, n): if a[i] + a[i-1] > x: cnt += a[i] - (x - a[i-1]) a[i] = x - a[i-1] print(cnt)
14
12
313
252
n, x = list(map(int, input().split())) a = list(map(int, input().split())) cnt = 0 for i in range(1, n): if a[i] + a[i - 1] > x: b = a[i] + a[i - 1] - x minab = min(a[i], b) a[i] -= minab cnt += minab b -= minab cnt += b a[i - 1] -= b print(cnt)
n, x = list(map(int, input().split())) a = list(map(int, input().split())) cnt = 0 if a[0] > x: cnt += a[0] - x a[0] = x for i in range(1, n): if a[i] + a[i - 1] > x: cnt += a[i] - (x - a[i - 1]) a[i] = x - a[i - 1] print(cnt)
false
14.285714
[ "+if a[0] > x:", "+ cnt += a[0] - x", "+ a[0] = x", "- b = a[i] + a[i - 1] - x", "- minab = min(a[i], b)", "- a[i] -= minab", "- cnt += minab", "- b -= minab", "- cnt += b", "- a[i - 1] -= b", "+ cnt += a[i] - (x - a[i - 1])", "+ a[i] = x - a[i - 1]" ]
false
0.035446
0.066986
0.52915
[ "s884916288", "s824535472" ]
u226155577
p03333
python
s340830485
s468620032
1,304
524
102,616
18,888
Accepted
Accepted
59.82
from heapq import heappush, heappop N = int(eval(input())) S = [] for i in range(N): l, r = list(map(int, input().split())) S.append((l, r)) S.sort() if all(l <= 0 <= r for l, r in S): print((0)) exit(0) que = [] P = [] Q = [l for l, r in S] Q.reverse() ans = 0 a = b = 0 p = 0 for i in range(N+1): if i < N: l, r = S[i] while que and que[0] <= l: P.append(heappop(que)) cnt = min(len(P), len(Q)) while p < cnt: a += P[p] b += Q[p] p += 1 ans = max(ans, abs(a-b)*2) if len(P) < len(Q): b2 = b + Q[cnt] ans = max(ans, abs(a-b2)*2) elif len(P) > len(Q): a2 = a + P[cnt] ans = max(ans, abs(a2-b)*2) heappush(que, r) if cnt == len(Q) > 0: a -= P[cnt-1] b -= Q[cnt-1] if i < N: Q.pop() print(ans)
from heapq import heappush, heappop N = int(eval(input())) S = [] for i in range(N): l, r = list(map(int, input().split())) S.append((l, r)) if all(l <= 0 <= r for l, r in S): print((0)) exit(0) P = sorted(r for l, r in S) Q = sorted(l for l, r in S) L = R = 0 ans = 0 for i in range(N): if not i < N-1-i: break L += P[i] R += Q[N-1-i] ans = max(ans, abs(R - L)*2) if i+1 < N-1-i: ans = max(ans, abs(R - L - P[i+1])*2) if i < N-1-i-1: ans = max(ans, abs(R + Q[N-1-i-1] - L)*2) print(ans)
43
26
874
564
from heapq import heappush, heappop N = int(eval(input())) S = [] for i in range(N): l, r = list(map(int, input().split())) S.append((l, r)) S.sort() if all(l <= 0 <= r for l, r in S): print((0)) exit(0) que = [] P = [] Q = [l for l, r in S] Q.reverse() ans = 0 a = b = 0 p = 0 for i in range(N + 1): if i < N: l, r = S[i] while que and que[0] <= l: P.append(heappop(que)) cnt = min(len(P), len(Q)) while p < cnt: a += P[p] b += Q[p] p += 1 ans = max(ans, abs(a - b) * 2) if len(P) < len(Q): b2 = b + Q[cnt] ans = max(ans, abs(a - b2) * 2) elif len(P) > len(Q): a2 = a + P[cnt] ans = max(ans, abs(a2 - b) * 2) heappush(que, r) if cnt == len(Q) > 0: a -= P[cnt - 1] b -= Q[cnt - 1] if i < N: Q.pop() print(ans)
from heapq import heappush, heappop N = int(eval(input())) S = [] for i in range(N): l, r = list(map(int, input().split())) S.append((l, r)) if all(l <= 0 <= r for l, r in S): print((0)) exit(0) P = sorted(r for l, r in S) Q = sorted(l for l, r in S) L = R = 0 ans = 0 for i in range(N): if not i < N - 1 - i: break L += P[i] R += Q[N - 1 - i] ans = max(ans, abs(R - L) * 2) if i + 1 < N - 1 - i: ans = max(ans, abs(R - L - P[i + 1]) * 2) if i < N - 1 - i - 1: ans = max(ans, abs(R + Q[N - 1 - i - 1] - L) * 2) print(ans)
false
39.534884
[ "-S.sort()", "-que = []", "-P = []", "-Q = [l for l, r in S]", "-Q.reverse()", "+P = sorted(r for l, r in S)", "+Q = sorted(l for l, r in S)", "+L = R = 0", "-a = b = 0", "-p = 0", "-for i in range(N + 1):", "- if i < N:", "- l, r = S[i]", "- while que and que[0] <= l:", "- P.append(heappop(que))", "- cnt = min(len(P), len(Q))", "- while p < cnt:", "- a += P[p]", "- b += Q[p]", "- p += 1", "- ans = max(ans, abs(a - b) * 2)", "- if len(P) < len(Q):", "- b2 = b + Q[cnt]", "- ans = max(ans, abs(a - b2) * 2)", "- elif len(P) > len(Q):", "- a2 = a + P[cnt]", "- ans = max(ans, abs(a2 - b) * 2)", "- heappush(que, r)", "- if cnt == len(Q) > 0:", "- a -= P[cnt - 1]", "- b -= Q[cnt - 1]", "- if i < N:", "- Q.pop()", "+for i in range(N):", "+ if not i < N - 1 - i:", "+ break", "+ L += P[i]", "+ R += Q[N - 1 - i]", "+ ans = max(ans, abs(R - L) * 2)", "+ if i + 1 < N - 1 - i:", "+ ans = max(ans, abs(R - L - P[i + 1]) * 2)", "+ if i < N - 1 - i - 1:", "+ ans = max(ans, abs(R + Q[N - 1 - i - 1] - L) * 2)" ]
false
0.040965
0.0374
1.095321
[ "s340830485", "s468620032" ]
u729133443
p02763
python
s995042655
s320469496
446
352
45,560
45,552
Accepted
Accepted
21.08
def main(): import sys n,s,_,*t=sys.stdin.buffer.read().split() n=int(n) d=[0]*n+[2**(c-97)for c in s] for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i] r=[] for q,a,b in zip(*[iter(t)]*3): i,s=int(a)+n-1,0 if q<b'2': d[i]=2**(b[0]-97) while i>1: i//=2 d[i]=d[i+i]|d[i-~i] continue j=int(b)+n while i<j: if i&1: s|=d[i] i+=1 if j&1: j-=1 s|=d[j] i//=2 j//=2 r+=bin(s).count('1'), print((' '.join(map(str,r)))) main()
def main(): import sys n,s,_,*t=sys.stdin.buffer.read().split() n=int(n) d=[0]*n+[1<<c-97for c in s] for i in range(n-1,0,-1):d[i]=d[i+i]|d[i+i+1] r=[] for q,a,b in zip(*[iter(t)]*3): i,s=int(a)+n-1,0 if q<b'2': d[i]=1<<b[0]-97 while i>1: i//=2 d[i]=d[i+i]|d[i+i+1] continue j=int(b)+n while i<j: if i&1: s|=d[i] i+=1 if j&1: j-=1 s|=d[j] i//=2 j//=2 r+=bin(s).count('1'), print((' '.join(map(str,r)))) main()
28
28
562
560
def main(): import sys n, s, _, *t = sys.stdin.buffer.read().split() n = int(n) d = [0] * n + [2 ** (c - 97) for c in s] for i in range(n - 1, 0, -1): d[i] = d[i + i] | d[i - ~i] r = [] for q, a, b in zip(*[iter(t)] * 3): i, s = int(a) + n - 1, 0 if q < b"2": d[i] = 2 ** (b[0] - 97) while i > 1: i //= 2 d[i] = d[i + i] | d[i - ~i] continue j = int(b) + n while i < j: if i & 1: s |= d[i] i += 1 if j & 1: j -= 1 s |= d[j] i //= 2 j //= 2 r += (bin(s).count("1"),) print((" ".join(map(str, r)))) main()
def main(): import sys n, s, _, *t = sys.stdin.buffer.read().split() n = int(n) d = [0] * n + [1 << c - 97 for c in s] for i in range(n - 1, 0, -1): d[i] = d[i + i] | d[i + i + 1] r = [] for q, a, b in zip(*[iter(t)] * 3): i, s = int(a) + n - 1, 0 if q < b"2": d[i] = 1 << b[0] - 97 while i > 1: i //= 2 d[i] = d[i + i] | d[i + i + 1] continue j = int(b) + n while i < j: if i & 1: s |= d[i] i += 1 if j & 1: j -= 1 s |= d[j] i //= 2 j //= 2 r += (bin(s).count("1"),) print((" ".join(map(str, r)))) main()
false
0
[ "- d = [0] * n + [2 ** (c - 97) for c in s]", "+ d = [0] * n + [1 << c - 97 for c in s]", "- d[i] = d[i + i] | d[i - ~i]", "+ d[i] = d[i + i] | d[i + i + 1]", "- d[i] = 2 ** (b[0] - 97)", "+ d[i] = 1 << b[0] - 97", "- d[i] = d[i + i] | d[i - ~i]", "+ d[i] = d[i + i] | d[i + i + 1]" ]
false
0.047333
0.047361
0.99942
[ "s995042655", "s320469496" ]
u626337957
p03044
python
s239760935
s519104245
806
702
93,472
41,496
Accepted
Accepted
12.9
import sys sys.setrecursionlimit(100000) N = int(eval(input())) W = [list(map(int, input().split())) for _ in range(N-1)] nodes = [[] for _ in range(N+1)] for w in W: nodes[w[0]].append((w[1], w[2])) nodes[w[1]].append((w[0], w[2])) ans = [-1] * (N+1) ans[1] = 0 def search(num, root, dis): for node in nodes[num]: sum_d = dis if node[0] != root: idx = node[0] sum_d += node[1]%2 if sum_d%2 != 0: ans[idx] = 1 else: ans[idx] = 0 search(idx, num, sum_d) search(1, 0, 0) for answer in ans[1:]: print(answer)
from collections import deque N = int(eval(input())) d_list = [[] for _ in range(N+1)] for _ in range(N-1): a, b, c = list(map(int, input().split())) d_list[a].append((b, a, c)) d_list[b].append((a, b, c)) que = deque([]) for v in d_list[1]: que.append(v) ans = [-1] * (N+1) ans[1] = 0 while len(que) > 0: v = que.popleft() ans[v[0]] = (ans[v[1]]+v[2])%2 for n in d_list[v[0]]: if ans[n[0]] == -1: que.append(n) for a in ans[1:]: print(a)
26
21
651
473
import sys sys.setrecursionlimit(100000) N = int(eval(input())) W = [list(map(int, input().split())) for _ in range(N - 1)] nodes = [[] for _ in range(N + 1)] for w in W: nodes[w[0]].append((w[1], w[2])) nodes[w[1]].append((w[0], w[2])) ans = [-1] * (N + 1) ans[1] = 0 def search(num, root, dis): for node in nodes[num]: sum_d = dis if node[0] != root: idx = node[0] sum_d += node[1] % 2 if sum_d % 2 != 0: ans[idx] = 1 else: ans[idx] = 0 search(idx, num, sum_d) search(1, 0, 0) for answer in ans[1:]: print(answer)
from collections import deque N = int(eval(input())) d_list = [[] for _ in range(N + 1)] for _ in range(N - 1): a, b, c = list(map(int, input().split())) d_list[a].append((b, a, c)) d_list[b].append((a, b, c)) que = deque([]) for v in d_list[1]: que.append(v) ans = [-1] * (N + 1) ans[1] = 0 while len(que) > 0: v = que.popleft() ans[v[0]] = (ans[v[1]] + v[2]) % 2 for n in d_list[v[0]]: if ans[n[0]] == -1: que.append(n) for a in ans[1:]: print(a)
false
19.230769
[ "-import sys", "+from collections import deque", "-sys.setrecursionlimit(100000)", "-W = [list(map(int, input().split())) for _ in range(N - 1)]", "-nodes = [[] for _ in range(N + 1)]", "-for w in W:", "- nodes[w[0]].append((w[1], w[2]))", "- nodes[w[1]].append((w[0], w[2]))", "+d_list = [[] for _ in range(N + 1)]", "+for _ in range(N - 1):", "+ a, b, c = list(map(int, input().split()))", "+ d_list[a].append((b, a, c))", "+ d_list[b].append((a, b, c))", "+que = deque([])", "+for v in d_list[1]:", "+ que.append(v)", "-", "-", "-def search(num, root, dis):", "- for node in nodes[num]:", "- sum_d = dis", "- if node[0] != root:", "- idx = node[0]", "- sum_d += node[1] % 2", "- if sum_d % 2 != 0:", "- ans[idx] = 1", "- else:", "- ans[idx] = 0", "- search(idx, num, sum_d)", "-", "-", "-search(1, 0, 0)", "-for answer in ans[1:]:", "- print(answer)", "+while len(que) > 0:", "+ v = que.popleft()", "+ ans[v[0]] = (ans[v[1]] + v[2]) % 2", "+ for n in d_list[v[0]]:", "+ if ans[n[0]] == -1:", "+ que.append(n)", "+for a in ans[1:]:", "+ print(a)" ]
false
0.036857
0.0374
0.985466
[ "s239760935", "s519104245" ]
u594859393
p03408
python
s066669898
s433318454
26
21
3,436
3,316
Accepted
Accepted
19.23
from collections import Counter n = int(eval(input())) ss = Counter(eval(input()) for _ in range(n)) m = int(eval(input())) ts = Counter(eval(input()) for _ in range(m)) print((max(max(0, cs - ts[s]) for s, cs in list(ss.items()))))
from collections import Counter n = int(eval(input())) ss = Counter(eval(input()) for _ in range(n)) m = int(eval(input())) ts = Counter(eval(input()) for _ in range(m)) answer = max(cs - ts[s] for s, cs in list(ss.items())) print((answer if answer > 0 else 0))
7
8
207
238
from collections import Counter n = int(eval(input())) ss = Counter(eval(input()) for _ in range(n)) m = int(eval(input())) ts = Counter(eval(input()) for _ in range(m)) print((max(max(0, cs - ts[s]) for s, cs in list(ss.items()))))
from collections import Counter n = int(eval(input())) ss = Counter(eval(input()) for _ in range(n)) m = int(eval(input())) ts = Counter(eval(input()) for _ in range(m)) answer = max(cs - ts[s] for s, cs in list(ss.items())) print((answer if answer > 0 else 0))
false
12.5
[ "-print((max(max(0, cs - ts[s]) for s, cs in list(ss.items()))))", "+answer = max(cs - ts[s] for s, cs in list(ss.items()))", "+print((answer if answer > 0 else 0))" ]
false
0.097681
0.081853
1.193366
[ "s066669898", "s433318454" ]
u771365068
p03569
python
s661925143
s562289677
488
61
4,340
3,316
Accepted
Accepted
87.5
from collections import deque S = eval(input()) d = deque(S) left = 0 right = len(d) - 1 count = 0 while left < right: #print(f'{left=}, {right=}') if d[right] == d[left]: left += 1 right -= 1 else: if d[right] == 'x': count += 1 right -= 1 elif d[left] == 'x': count += 1 left += 1 else: count = -1 print((-1)) break if count != -1: print(count)
S = eval(input()) d = S left = 0 right = len(d) - 1 count = 0 while left < right: #print(f'{left=}, {right=}') if d[right] == d[left]: left += 1 right -= 1 else: if d[right] == 'x': count += 1 right -= 1 elif d[left] == 'x': count += 1 left += 1 else: count = -1 print((-1)) break if count != -1: print(count)
30
27
514
472
from collections import deque S = eval(input()) d = deque(S) left = 0 right = len(d) - 1 count = 0 while left < right: # print(f'{left=}, {right=}') if d[right] == d[left]: left += 1 right -= 1 else: if d[right] == "x": count += 1 right -= 1 elif d[left] == "x": count += 1 left += 1 else: count = -1 print((-1)) break if count != -1: print(count)
S = eval(input()) d = S left = 0 right = len(d) - 1 count = 0 while left < right: # print(f'{left=}, {right=}') if d[right] == d[left]: left += 1 right -= 1 else: if d[right] == "x": count += 1 right -= 1 elif d[left] == "x": count += 1 left += 1 else: count = -1 print((-1)) break if count != -1: print(count)
false
10
[ "-from collections import deque", "-", "-d = deque(S)", "+d = S" ]
false
0.063683
0.007167
8.885882
[ "s661925143", "s562289677" ]
u116002573
p02772
python
s891263321
s555267866
167
71
38,384
61,708
Accepted
Accepted
57.49
def main(): N = int(eval(input())) A = list(map(int, input().split())) for v in A: if v % 2 == 0 and (v % 5 != 0 and v % 3 != 0): return "DENIED" return "APPROVED" if __name__ == '__main__': print((main()))
def main(): N = int(eval(input())) A = list(map(int, input().split())) even = [v for v in A if v % 2 == 0] if all((v % 3 == 0) or (v % 5 == 0) for v in even): return "APPROVED" return "DENIED" if __name__ == '__main__': print((main()))
10
11
238
272
def main(): N = int(eval(input())) A = list(map(int, input().split())) for v in A: if v % 2 == 0 and (v % 5 != 0 and v % 3 != 0): return "DENIED" return "APPROVED" if __name__ == "__main__": print((main()))
def main(): N = int(eval(input())) A = list(map(int, input().split())) even = [v for v in A if v % 2 == 0] if all((v % 3 == 0) or (v % 5 == 0) for v in even): return "APPROVED" return "DENIED" if __name__ == "__main__": print((main()))
false
9.090909
[ "- for v in A:", "- if v % 2 == 0 and (v % 5 != 0 and v % 3 != 0):", "- return \"DENIED\"", "- return \"APPROVED\"", "+ even = [v for v in A if v % 2 == 0]", "+ if all((v % 3 == 0) or (v % 5 == 0) for v in even):", "+ return \"APPROVED\"", "+ return \"DENIED\"" ]
false
0.036772
0.079646
0.461691
[ "s891263321", "s555267866" ]
u373047809
p03994
python
s460105233
s697310380
66
61
9,412
9,928
Accepted
Accepted
7.58
s,k,t=eval(input()),int(eval(input())),"" for q in s: if(p:=(123-ord(q))%26)<=k:t+="a";k-=p else:t+=q print((t[:-1]+chr((ord(t[-1])-97+k)%26+97)))
s,k=open(0) k=int(k) *s,t=s for q in s: if(p:=(123-ord(q))%26)<=k:t+="a";k-=p else:t+=q print((t[1:-1]+chr((ord(t[-1])-97+k)%26+97)))
5
7
138
139
s, k, t = eval(input()), int(eval(input())), "" for q in s: if (p := (123 - ord(q)) % 26) <= k: t += "a" k -= p else: t += q print((t[:-1] + chr((ord(t[-1]) - 97 + k) % 26 + 97)))
s, k = open(0) k = int(k) *s, t = s for q in s: if (p := (123 - ord(q)) % 26) <= k: t += "a" k -= p else: t += q print((t[1:-1] + chr((ord(t[-1]) - 97 + k) % 26 + 97)))
false
28.571429
[ "-s, k, t = eval(input()), int(eval(input())), \"\"", "+s, k = open(0)", "+k = int(k)", "+*s, t = s", "-print((t[:-1] + chr((ord(t[-1]) - 97 + k) % 26 + 97)))", "+print((t[1:-1] + chr((ord(t[-1]) - 97 + k) % 26 + 97)))" ]
false
0.103486
0.048367
2.139589
[ "s460105233", "s697310380" ]
u556849401
p03160
python
s079913272
s594093421
272
150
13,928
13,928
Accepted
Accepted
44.85
# -*- coding: utf-8 -*- """ Created on Tue Mar 5 15:34:44 2019 @author: avina """ n = int(eval(input())) L = list(map(int, input().strip().split())) dp = [0 for i in range(n)] dp[1] = abs(L[1] - L[0]) for j in range(2,n): for i in range(j,j+2): if i < n: dp[i] = min(dp[i-2] + abs(L[i]-L[i-2]),dp[i-1] + abs(L[i] - L[i-1])) print((dp[-1]))
# -*- coding: utf-8 -*- """ Created on Tue Oct 8 08:28:30 2019 @author: avina """ n = int(eval(input())) l = list(map(int, input().split())) dp= [0]*n for i in range(1,n): b = 1e6 a = dp[i-1] + abs(l[i] - l[i-1]) if i -2 >-1: b = dp[i-2] + abs(l[i] - l[i-2]) dp[i] = min(a,b) print((dp[-1]))
17
18
376
332
# -*- coding: utf-8 -*- """ Created on Tue Mar 5 15:34:44 2019 @author: avina """ n = int(eval(input())) L = list(map(int, input().strip().split())) dp = [0 for i in range(n)] dp[1] = abs(L[1] - L[0]) for j in range(2, n): for i in range(j, j + 2): if i < n: dp[i] = min( dp[i - 2] + abs(L[i] - L[i - 2]), dp[i - 1] + abs(L[i] - L[i - 1]) ) print((dp[-1]))
# -*- coding: utf-8 -*- """ Created on Tue Oct 8 08:28:30 2019 @author: avina """ n = int(eval(input())) l = list(map(int, input().split())) dp = [0] * n for i in range(1, n): b = 1e6 a = dp[i - 1] + abs(l[i] - l[i - 1]) if i - 2 > -1: b = dp[i - 2] + abs(l[i] - l[i - 2]) dp[i] = min(a, b) print((dp[-1]))
false
5.555556
[ "-Created on Tue Mar 5 15:34:44 2019", "+Created on Tue Oct 8 08:28:30 2019", "-L = list(map(int, input().strip().split()))", "-dp = [0 for i in range(n)]", "-dp[1] = abs(L[1] - L[0])", "-for j in range(2, n):", "- for i in range(j, j + 2):", "- if i < n:", "- dp[i] = min(", "- dp[i - 2] + abs(L[i] - L[i - 2]), dp[i - 1] + abs(L[i] - L[i - 1])", "- )", "+l = list(map(int, input().split()))", "+dp = [0] * n", "+for i in range(1, n):", "+ b = 1e6", "+ a = dp[i - 1] + abs(l[i] - l[i - 1])", "+ if i - 2 > -1:", "+ b = dp[i - 2] + abs(l[i] - l[i - 2])", "+ dp[i] = min(a, b)" ]
false
0.060656
0.043507
1.394183
[ "s079913272", "s594093421" ]
u204842730
p02947
python
s734189260
s299995790
514
380
30,580
23,440
Accepted
Accepted
26.07
import collections n = int(eval(input())) s = [[0 for j in range(10)] for i in range(n)] for i in range(n): t = eval(input()) s[i] = "".join(sorted(t)) ans = 0 c = collections.Counter(s) for i in set(s): n = c[i] ans += n * (n-1) // 2 print(ans)
import collections n = int(eval(input())) s = ["".join(sorted(eval(input()))) for i in range(n)] ans = 0 c = collections.Counter(s) for i in set(s): n = c[i] ans += n * (n-1) // 2 print(ans)
13
10
262
196
import collections n = int(eval(input())) s = [[0 for j in range(10)] for i in range(n)] for i in range(n): t = eval(input()) s[i] = "".join(sorted(t)) ans = 0 c = collections.Counter(s) for i in set(s): n = c[i] ans += n * (n - 1) // 2 print(ans)
import collections n = int(eval(input())) s = ["".join(sorted(eval(input()))) for i in range(n)] ans = 0 c = collections.Counter(s) for i in set(s): n = c[i] ans += n * (n - 1) // 2 print(ans)
false
23.076923
[ "-s = [[0 for j in range(10)] for i in range(n)]", "-for i in range(n):", "- t = eval(input())", "- s[i] = \"\".join(sorted(t))", "+s = [\"\".join(sorted(eval(input()))) for i in range(n)]" ]
false
0.040268
0.039518
1.018977
[ "s734189260", "s299995790" ]
u456936625
p03161
python
s652454328
s614109561
1,995
331
13,980
60,076
Accepted
Accepted
83.41
# @oj:atcoder # @id: hitwanyang # @email: 296866643@qq.com # @date: 2020-04-20 10:31 # @url:https://atcoder.jp/contests/dp/tasks/dp_b import sys def input(): return sys.stdin.readline().strip() def main(): nk=list(map(int,input().split())) h=list(map(int,input().split())) n=nk[0] k=nk[1] dp=[10**9]*n dp[0]=0 dp[1]=abs(h[1]-h[0]) for i in range(2,n): dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i)) # for j in range(max(0,i-k),i): # dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]) print((dp[-1])) if __name__ == "__main__": main()
import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------------------ def main(): nk=list(map(int,input().split())) h=list(map(int,input().split())) n=nk[0] k=nk[1] dp=[10**9]*n dp[0]=0 dp[1]=abs(h[1]-h[0]) for i in range(2,n): # dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i)) for j in range(max(0,i-k),i): dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]) print((dp[-1])) if __name__ == "__main__": main()
27
77
635
2,242
# @oj:atcoder # @id: hitwanyang # @email: 296866643@qq.com # @date: 2020-04-20 10:31 # @url:https://atcoder.jp/contests/dp/tasks/dp_b import sys def input(): return sys.stdin.readline().strip() def main(): nk = list(map(int, input().split())) h = list(map(int, input().split())) n = nk[0] k = nk[1] dp = [10**9] * n dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)) # for j in range(max(0,i-k),i): # dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]) print((dp[-1])) if __name__ == "__main__": main()
import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------------------ def main(): nk = list(map(int, input().split())) h = list(map(int, input().split())) n = nk[0] k = nk[1] dp = [10**9] * n dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): # dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i)) for j in range(max(0, i - k), i): dp[i] = min(dp[j] + abs(h[i] - h[j]), dp[i]) print((dp[-1])) if __name__ == "__main__": main()
false
64.935065
[ "-# @oj:atcoder", "-# @id: hitwanyang", "-# @email: 296866643@qq.com", "-# @date: 2020-04-20 10:31", "-# @url:https://atcoder.jp/contests/dp/tasks/dp_b", "+import os", "+from io import BytesIO, IOBase", "+", "+# region fastio", "+BUFSIZE = 8192", "-def input():", "- return sys.stdin.readline().strip()", "+class FastIO(IOBase):", "+ newlines = 0", "+", "+ def __init__(self, file):", "+ self._fd = file.fileno()", "+ self.buffer = BytesIO()", "+ self.writable = \"x\" in file.mode or \"r\" not in file.mode", "+ self.write = self.buffer.write if self.writable else None", "+", "+ def read(self):", "+ while True:", "+ b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))", "+ if not b:", "+ break", "+ ptr = self.buffer.tell()", "+ self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)", "+ self.newlines = 0", "+ return self.buffer.read()", "+", "+ def readline(self):", "+ while self.newlines == 0:", "+ b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))", "+ self.newlines = b.count(b\"\\n\") + (not b)", "+ ptr = self.buffer.tell()", "+ self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)", "+ self.newlines -= 1", "+ return self.buffer.readline()", "+", "+ def flush(self):", "+ if self.writable:", "+ os.write(self._fd, self.buffer.getvalue())", "+ self.buffer.truncate(0), self.buffer.seek(0)", "+class IOWrapper(IOBase):", "+ def __init__(self, file):", "+ self.buffer = FastIO(file)", "+ self.flush = self.buffer.flush", "+ self.writable = self.buffer.writable", "+ self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))", "+ self.read = lambda: self.buffer.read().decode(\"ascii\")", "+ self.readline = lambda: self.buffer.readline().decode(\"ascii\")", "+", "+", "+sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)", "+input = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")", "- dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i))", "- # for j in range(max(0,i-k),i):", "- # dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i])", "+ # dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))", "+ for j in range(max(0, i - k), i):", "+ dp[i] = min(dp[j] + abs(h[i] - h[j]), dp[i])" ]
false
0.075058
0.035188
2.133066
[ "s652454328", "s614109561" ]
u119148115
p03780
python
s323681305
s646299680
1,826
1,208
75,040
74,376
Accepted
Accepted
33.84
import sys def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり N,K = MI() A = LI() A.sort() def f(n): # Anが必要か否か B = [0] + [A[i] for i in range(N) if i != n] dp = [[0]*K for _ in range(2)] # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる) dp[0][0] = 1 for i in range(1,N): b = B[i] for j in range(K): if j >= b: dp[i%2][j] = dp[1-i%2][j] | dp[1-i%2][j-b] else: dp[i%2][j] = dp[1-i%2][j] if sum(dp[(N-1) % 2][j] for j in range(max(K-A[n],0),K)) != 0: return True else: return False left = -1 # 不必要 right = N # 必要 while left + 1 < right: mid = (left + right)//2 if f(mid): right = mid else: left = mid print(right)
import sys def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり N,K = MI() A = LI() A.sort() def f(n): # Anが必要か否か B = [0] + [A[i] for i in range(N) if i != n] dp = [0]*K # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる) dp[0] = 1 for i in range(1,N): b = B[i] for j in range(K-1,-1,-1): if j >= b: dp[j] |= dp[j-b] else: dp[j] = dp[j] if sum(dp[j] for j in range(max(K-A[n],0),K)) != 0: return True else: return False left = -1 # 不必要 right = N # 必要 while left + 1 < right: mid = (left + right)//2 if f(mid): right = mid else: left = mid print(right)
38
38
885
821
import sys def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり N, K = MI() A = LI() A.sort() def f(n): # Anが必要か否か B = [0] + [A[i] for i in range(N) if i != n] dp = [[0] * K for _ in range(2)] # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる) dp[0][0] = 1 for i in range(1, N): b = B[i] for j in range(K): if j >= b: dp[i % 2][j] = dp[1 - i % 2][j] | dp[1 - i % 2][j - b] else: dp[i % 2][j] = dp[1 - i % 2][j] if sum(dp[(N - 1) % 2][j] for j in range(max(K - A[n], 0), K)) != 0: return True else: return False left = -1 # 不必要 right = N # 必要 while left + 1 < right: mid = (left + right) // 2 if f(mid): right = mid else: left = mid print(right)
import sys def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり N, K = MI() A = LI() A.sort() def f(n): # Anが必要か否か B = [0] + [A[i] for i in range(N) if i != n] dp = [0] * K # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる) dp[0] = 1 for i in range(1, N): b = B[i] for j in range(K - 1, -1, -1): if j >= b: dp[j] |= dp[j - b] else: dp[j] = dp[j] if sum(dp[j] for j in range(max(K - A[n], 0), K)) != 0: return True else: return False left = -1 # 不必要 right = N # 必要 while left + 1 < right: mid = (left + right) // 2 if f(mid): right = mid else: left = mid print(right)
false
0
[ "- dp = [[0] * K for _ in range(2)] # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)", "- dp[0][0] = 1", "+ dp = [0] * K # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)", "+ dp[0] = 1", "- for j in range(K):", "+ for j in range(K - 1, -1, -1):", "- dp[i % 2][j] = dp[1 - i % 2][j] | dp[1 - i % 2][j - b]", "+ dp[j] |= dp[j - b]", "- dp[i % 2][j] = dp[1 - i % 2][j]", "- if sum(dp[(N - 1) % 2][j] for j in range(max(K - A[n], 0), K)) != 0:", "+ dp[j] = dp[j]", "+ if sum(dp[j] for j in range(max(K - A[n], 0), K)) != 0:" ]
false
0.037017
0.037477
0.98773
[ "s323681305", "s646299680" ]
u392319141
p02852
python
s350698753
s762183600
153
138
10,248
10,120
Accepted
Accepted
9.8
from bisect import bisect_right N, M = list(map(int, input().split())) S = [N - i for i, s in enumerate(eval(input())) if s == '0'] S = S[::-1] ans = [] now = 0 while now < N: i = bisect_right(S, now + M) - 1 if S[i] == now: print('-1') exit() ans.append(S[i] - now) now = S[i] print((*ans[::-1]))
from bisect import bisect_left N, M = list(map(int, input().split())) S = [i for i, s in enumerate(eval(input())) if s == '0'] ans = [] now = N while now > 0: nxI = bisect_left(S, now - M) nx = S[nxI] if nx == now: print((-1)) exit() ans.append(now - nx) now = nx print((*ans[::-1]))
19
19
339
327
from bisect import bisect_right N, M = list(map(int, input().split())) S = [N - i for i, s in enumerate(eval(input())) if s == "0"] S = S[::-1] ans = [] now = 0 while now < N: i = bisect_right(S, now + M) - 1 if S[i] == now: print("-1") exit() ans.append(S[i] - now) now = S[i] print((*ans[::-1]))
from bisect import bisect_left N, M = list(map(int, input().split())) S = [i for i, s in enumerate(eval(input())) if s == "0"] ans = [] now = N while now > 0: nxI = bisect_left(S, now - M) nx = S[nxI] if nx == now: print((-1)) exit() ans.append(now - nx) now = nx print((*ans[::-1]))
false
0
[ "-from bisect import bisect_right", "+from bisect import bisect_left", "-S = [N - i for i, s in enumerate(eval(input())) if s == \"0\"]", "-S = S[::-1]", "+S = [i for i, s in enumerate(eval(input())) if s == \"0\"]", "-now = 0", "-while now < N:", "- i = bisect_right(S, now + M) - 1", "- if S[i] == now:", "- print(\"-1\")", "+now = N", "+while now > 0:", "+ nxI = bisect_left(S, now - M)", "+ nx = S[nxI]", "+ if nx == now:", "+ print((-1))", "- ans.append(S[i] - now)", "- now = S[i]", "+ ans.append(now - nx)", "+ now = nx" ]
false
0.049607
0.048748
1.017638
[ "s350698753", "s762183600" ]
u849029577
p03486
python
s668044894
s133182643
177
163
38,256
38,384
Accepted
Accepted
7.91
s = eval(input()) t = eval(input()) s = sorted(s) t = sorted(t, reverse=True) u = min(len(s), len(t)) if s == t: print("No") exit() if len(s) < len(t) and s == t[:len(s)]: print("Yes") exit() else: for i in range(u): if s[i] > t[i]: print("No") exit() elif s[i] == t[i]: pass else: print("Yes") exit() print("No")
s = eval(input()) t = eval(input()) s = sorted(s) t = sorted(t, reverse=True) if s < t: print("Yes") else: print("No")
22
8
430
121
s = eval(input()) t = eval(input()) s = sorted(s) t = sorted(t, reverse=True) u = min(len(s), len(t)) if s == t: print("No") exit() if len(s) < len(t) and s == t[: len(s)]: print("Yes") exit() else: for i in range(u): if s[i] > t[i]: print("No") exit() elif s[i] == t[i]: pass else: print("Yes") exit() print("No")
s = eval(input()) t = eval(input()) s = sorted(s) t = sorted(t, reverse=True) if s < t: print("Yes") else: print("No")
false
63.636364
[ "-u = min(len(s), len(t))", "-if s == t:", "+if s < t:", "+ print(\"Yes\")", "+else:", "- exit()", "-if len(s) < len(t) and s == t[: len(s)]:", "- print(\"Yes\")", "- exit()", "-else:", "- for i in range(u):", "- if s[i] > t[i]:", "- print(\"No\")", "- exit()", "- elif s[i] == t[i]:", "- pass", "- else:", "- print(\"Yes\")", "- exit()", "- print(\"No\")" ]
false
0.045229
0.079591
0.568266
[ "s668044894", "s133182643" ]
u952467214
p03013
python
s269695872
s269310062
231
68
45,148
8,604
Accepted
Accepted
70.56
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline p = 10**9 + 7 n, m = list(map(int, input().split())) A = list(int(eval(input())) for i in range(m)) isHole = [False]*(n+1) dp = [1]*(n+1) for a in A: isHole[a] = True dp[a] = 0 for i in range(2,n+1): if isHole[i] == False: dp[i] = dp[i-2]%p + dp[i-1]%p print((dp[-1]%p))
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline p=10**9+7 n, m = list(map(int, input().split())) a = list(int(eval(input())) for i in range(m)) safe = [1]*(n+1) for aa in a: safe[aa]=0 dp = [0]*(n+1) dp[0] = 1 if safe[1]:dp[1]=1 for i in range(2,n+1): if not safe[i]: continue dp[i] = dp[i-1]%p+dp[i-2]%p print((dp[-1]%p))
22
23
373
377
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline p = 10**9 + 7 n, m = list(map(int, input().split())) A = list(int(eval(input())) for i in range(m)) isHole = [False] * (n + 1) dp = [1] * (n + 1) for a in A: isHole[a] = True dp[a] = 0 for i in range(2, n + 1): if isHole[i] == False: dp[i] = dp[i - 2] % p + dp[i - 1] % p print((dp[-1] % p))
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline p = 10**9 + 7 n, m = list(map(int, input().split())) a = list(int(eval(input())) for i in range(m)) safe = [1] * (n + 1) for aa in a: safe[aa] = 0 dp = [0] * (n + 1) dp[0] = 1 if safe[1]: dp[1] = 1 for i in range(2, n + 1): if not safe[i]: continue dp[i] = dp[i - 1] % p + dp[i - 2] % p print((dp[-1] % p))
false
4.347826
[ "-A = list(int(eval(input())) for i in range(m))", "-isHole = [False] * (n + 1)", "-dp = [1] * (n + 1)", "-for a in A:", "- isHole[a] = True", "- dp[a] = 0", "+a = list(int(eval(input())) for i in range(m))", "+safe = [1] * (n + 1)", "+for aa in a:", "+ safe[aa] = 0", "+dp = [0] * (n + 1)", "+dp[0] = 1", "+if safe[1]:", "+ dp[1] = 1", "- if isHole[i] == False:", "- dp[i] = dp[i - 2] % p + dp[i - 1] % p", "+ if not safe[i]:", "+ continue", "+ dp[i] = dp[i - 1] % p + dp[i - 2] % p" ]
false
0.076022
0.041292
1.841113
[ "s269695872", "s269310062" ]
u485319545
p02971
python
s860159647
s473184547
546
377
20,520
20,752
Accepted
Accepted
30.95
N=int(eval(input())) seq=[] for i in range(N): a= int(eval(input())) seq.append(a) import heapq tmp=list([x*(-1) for x in seq]) heapq.heapify(tmp) a=heapq.heappop(tmp)*(-1) b=heapq.heappop(tmp)*(-1) for j in range(N): if seq[j]==a: print(b) else: print(a)
n=int(eval(input())) a=[] for _ in range(n): a.append(int(eval(input()))) b=a.copy() import heapq #これを加える!!!! def _heappush_max(heap, item): heap.append(item) heapq._siftdown_max(heap, 0, len(heap)-1) def _heappop_max(heap): """Maxheap version of a heappop.""" lastelt = heap.pop() # raises appropriate IndexError if heap is empty if heap: returnitem = heap[0] heap[0] = lastelt heapq._siftup_max(heap, 0) return returnitem return lastelt b = sorted(b,reverse=True) b1 = _heappop_max(b) b2 = _heappop_max(b) for i in range(n): if a[i]==b1: print(b2) else: print(b1)
21
32
305
677
N = int(eval(input())) seq = [] for i in range(N): a = int(eval(input())) seq.append(a) import heapq tmp = list([x * (-1) for x in seq]) heapq.heapify(tmp) a = heapq.heappop(tmp) * (-1) b = heapq.heappop(tmp) * (-1) for j in range(N): if seq[j] == a: print(b) else: print(a)
n = int(eval(input())) a = [] for _ in range(n): a.append(int(eval(input()))) b = a.copy() import heapq # これを加える!!!! def _heappush_max(heap, item): heap.append(item) heapq._siftdown_max(heap, 0, len(heap) - 1) def _heappop_max(heap): """Maxheap version of a heappop.""" lastelt = heap.pop() # raises appropriate IndexError if heap is empty if heap: returnitem = heap[0] heap[0] = lastelt heapq._siftup_max(heap, 0) return returnitem return lastelt b = sorted(b, reverse=True) b1 = _heappop_max(b) b2 = _heappop_max(b) for i in range(n): if a[i] == b1: print(b2) else: print(b1)
false
34.375
[ "-N = int(eval(input()))", "-seq = []", "-for i in range(N):", "- a = int(eval(input()))", "- seq.append(a)", "+n = int(eval(input()))", "+a = []", "+for _ in range(n):", "+ a.append(int(eval(input())))", "+b = a.copy()", "-tmp = list([x * (-1) for x in seq])", "-heapq.heapify(tmp)", "-a = heapq.heappop(tmp) * (-1)", "-b = heapq.heappop(tmp) * (-1)", "-for j in range(N):", "- if seq[j] == a:", "- print(b)", "+# これを加える!!!!", "+def _heappush_max(heap, item):", "+ heap.append(item)", "+ heapq._siftdown_max(heap, 0, len(heap) - 1)", "+", "+", "+def _heappop_max(heap):", "+ \"\"\"Maxheap version of a heappop.\"\"\"", "+ lastelt = heap.pop() # raises appropriate IndexError if heap is empty", "+ if heap:", "+ returnitem = heap[0]", "+ heap[0] = lastelt", "+ heapq._siftup_max(heap, 0)", "+ return returnitem", "+ return lastelt", "+", "+", "+b = sorted(b, reverse=True)", "+b1 = _heappop_max(b)", "+b2 = _heappop_max(b)", "+for i in range(n):", "+ if a[i] == b1:", "+ print(b2)", "- print(a)", "+ print(b1)" ]
false
0.040124
0.040246
0.996978
[ "s860159647", "s473184547" ]
u761320129
p03434
python
s798182719
s132246730
37
19
3,064
2,940
Accepted
Accepted
48.65
N = int(eval(input())) src = list(map(int,input().split())) src.sort(reverse=True) a = sum(src[::2]) b = sum(src[1::2]) print((a-b))
N = int(eval(input())) A = list(map(int,input().split())) A.sort() ali = bob = 0 for i,a in enumerate(reversed(A)): if i%2: bob += a else: ali += a print((ali - bob))
6
11
129
193
N = int(eval(input())) src = list(map(int, input().split())) src.sort(reverse=True) a = sum(src[::2]) b = sum(src[1::2]) print((a - b))
N = int(eval(input())) A = list(map(int, input().split())) A.sort() ali = bob = 0 for i, a in enumerate(reversed(A)): if i % 2: bob += a else: ali += a print((ali - bob))
false
45.454545
[ "-src = list(map(int, input().split()))", "-src.sort(reverse=True)", "-a = sum(src[::2])", "-b = sum(src[1::2])", "-print((a - b))", "+A = list(map(int, input().split()))", "+A.sort()", "+ali = bob = 0", "+for i, a in enumerate(reversed(A)):", "+ if i % 2:", "+ bob += a", "+ else:", "+ ali += a", "+print((ali - bob))" ]
false
0.047131
0.167004
0.282216
[ "s798182719", "s132246730" ]
u067299340
p00002
python
s812563615
s933506075
20
10
4,184
4,180
Accepted
Accepted
50
import sys for n in [sum([int(m) for m in l.split()]) for l in sys.stdin]: print(len(str(n)))
import sys for l in sys.stdin: print(len(str(sum(map(int,l.split())))))
3
3
95
73
import sys for n in [sum([int(m) for m in l.split()]) for l in sys.stdin]: print(len(str(n)))
import sys for l in sys.stdin: print(len(str(sum(map(int, l.split())))))
false
0
[ "-for n in [sum([int(m) for m in l.split()]) for l in sys.stdin]:", "- print(len(str(n)))", "+for l in sys.stdin:", "+ print(len(str(sum(map(int, l.split())))))" ]
false
0.03622
0.049434
0.732704
[ "s812563615", "s933506075" ]
u762420987
p02847
python
s726709270
s222885926
20
17
3,060
2,940
Accepted
Accepted
15
d = ["SUN","MON","TUE","WED","THU","FRI","SAT"] s = eval(input()) print((7 - d.index(s)))
y = ["SUN","MON","TUE","WED","THU","FRI","SAT"] print((7-y.index(eval(input()))))
3
2
84
74
d = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"] s = eval(input()) print((7 - d.index(s)))
y = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"] print((7 - y.index(eval(input()))))
false
33.333333
[ "-d = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\"]", "-s = eval(input())", "-print((7 - d.index(s)))", "+y = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\"]", "+print((7 - y.index(eval(input()))))" ]
false
0.0404
0.04575
0.883076
[ "s726709270", "s222885926" ]
u021019433
p02744
python
s923679975
s608253160
133
121
14,784
14,692
Accepted
Accepted
9.02
n = int(input()) r = 'a', for _ in range(n - 1): r = [s + c for s in r for i, c in enumerate(s + chr(ord(max(s)) + 1)) if c not in s[:i]] print(*r, sep='\n')
n = int(input()) r = 'a', for _ in range(n - 1): r = [s + c for s in r for c in set(s + chr(ord(max(s)) + 1))] print(*sorted(r), sep='\n')
5
5
164
144
n = int(input()) r = ("a",) for _ in range(n - 1): r = [ s + c for s in r for i, c in enumerate(s + chr(ord(max(s)) + 1)) if c not in s[:i] ] print(*r, sep="\n")
n = int(input()) r = ("a",) for _ in range(n - 1): r = [s + c for s in r for c in set(s + chr(ord(max(s)) + 1))] print(*sorted(r), sep="\n")
false
0
[ "- r = [", "- s + c", "- for s in r", "- for i, c in enumerate(s + chr(ord(max(s)) + 1))", "- if c not in s[:i]", "- ]", "-print(*r, sep=\"\\n\")", "+ r = [s + c for s in r for c in set(s + chr(ord(max(s)) + 1))]", "+print(*sorted(r), sep=\"\\n\")" ]
false
0.048515
0.059092
0.82101
[ "s923679975", "s608253160" ]
u980205854
p03745
python
s319550619
s197127668
810
96
23,208
88,452
Accepted
Accepted
88.15
# A - Sorted Arrays import numpy as np N = int(eval(input())) A = list(map(int, input().split())) sgn = 0 ans = 1 for i in range(N-1): tmp = np.sign(A[i+1]-A[i]) if tmp*sgn<0: ans += 1 sgn = 0 else: sgn = np.sign(2*sgn+tmp) print(ans)
import sys from sys import exit from collections import deque from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値) from heapq import heapify, heappop, heappush from math import * sys.setrecursionlimit(10**6) INF = 10**20 eps = 1.0e-20 MOD = 10**9+7 def mint(): return map(int,input().split()) def lint(): return list(map(int,input().split())) def ilint(): return int(input()), list(map(int,input().split())) def judge(x, l=['Yes', 'No']): print(l[0] if x else l[1]) def lprint(l, sep='\n'): for x in l: print(x, end=sep) def sgn(x): if x==0: return x return x//abs(x) N,A = ilint() tmp = A[0] ans = 1 s = 0 for a in A[1:]: if s==0: s = sgn(a-tmp) tmp = a elif s*(a-tmp)>=0: tmp = a else: ans += 1 tmp = a s = 0 print(ans)
17
44
283
912
# A - Sorted Arrays import numpy as np N = int(eval(input())) A = list(map(int, input().split())) sgn = 0 ans = 1 for i in range(N - 1): tmp = np.sign(A[i + 1] - A[i]) if tmp * sgn < 0: ans += 1 sgn = 0 else: sgn = np.sign(2 * sgn + tmp) print(ans)
import sys from sys import exit from collections import deque from bisect import bisect_left, bisect_right, insort_left, insort_right # func(リスト,値) from heapq import heapify, heappop, heappush from math import * sys.setrecursionlimit(10**6) INF = 10**20 eps = 1.0e-20 MOD = 10**9 + 7 def mint(): return map(int, input().split()) def lint(): return list(map(int, input().split())) def ilint(): return int(input()), list(map(int, input().split())) def judge(x, l=["Yes", "No"]): print(l[0] if x else l[1]) def lprint(l, sep="\n"): for x in l: print(x, end=sep) def sgn(x): if x == 0: return x return x // abs(x) N, A = ilint() tmp = A[0] ans = 1 s = 0 for a in A[1:]: if s == 0: s = sgn(a - tmp) tmp = a elif s * (a - tmp) >= 0: tmp = a else: ans += 1 tmp = a s = 0 print(ans)
false
61.363636
[ "-# A - Sorted Arrays", "-import numpy as np", "+import sys", "+from sys import exit", "+from collections import deque", "+from bisect import bisect_left, bisect_right, insort_left, insort_right # func(リスト,値)", "+from heapq import heapify, heappop, heappush", "+from math import *", "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-sgn = 0", "+sys.setrecursionlimit(10**6)", "+INF = 10**20", "+eps = 1.0e-20", "+MOD = 10**9 + 7", "+", "+", "+def mint():", "+ return map(int, input().split())", "+", "+", "+def lint():", "+ return list(map(int, input().split()))", "+", "+", "+def ilint():", "+ return int(input()), list(map(int, input().split()))", "+", "+", "+def judge(x, l=[\"Yes\", \"No\"]):", "+ print(l[0] if x else l[1])", "+", "+", "+def lprint(l, sep=\"\\n\"):", "+ for x in l:", "+ print(x, end=sep)", "+", "+", "+def sgn(x):", "+ if x == 0:", "+ return x", "+ return x // abs(x)", "+", "+", "+N, A = ilint()", "+tmp = A[0]", "-for i in range(N - 1):", "- tmp = np.sign(A[i + 1] - A[i])", "- if tmp * sgn < 0:", "+s = 0", "+for a in A[1:]:", "+ if s == 0:", "+ s = sgn(a - tmp)", "+ tmp = a", "+ elif s * (a - tmp) >= 0:", "+ tmp = a", "+ else:", "- sgn = 0", "- else:", "- sgn = np.sign(2 * sgn + tmp)", "+ tmp = a", "+ s = 0" ]
false
0.007617
0.034765
0.219088
[ "s319550619", "s197127668" ]
u294385082
p02888
python
s389488167
s705619913
1,791
1,099
3,188
3,316
Accepted
Accepted
38.64
n=int(eval(input())) l=list(map(int,input().split())) import bisect ans=0 l.sort() for i in range(n): a=l[i]#一番短い棒を確定 for j in range(i+1,n): b=l[j]#二番目に短い棒を確定 ind=bisect.bisect_left(l,a+b)#二辺の和と同じだったら耐えないので,left ans+=max(0,ind-(j+1))#三角形の成立条件と,一番長い棒であることを考える print(ans)
import bisect def main(): n = int(eval(input())) ls = sorted(list(map(int, input().split()))) ans = 0 for i in range(n-1): for j in range(i+1, n): a = ls[i] b = ls[j] k = bisect.bisect_left(ls, a+b) if k > j: ans += k - j - 1 print(ans) if __name__ == "__main__": main()
16
20
317
388
n = int(eval(input())) l = list(map(int, input().split())) import bisect ans = 0 l.sort() for i in range(n): a = l[i] # 一番短い棒を確定 for j in range(i + 1, n): b = l[j] # 二番目に短い棒を確定 ind = bisect.bisect_left(l, a + b) # 二辺の和と同じだったら耐えないので,left ans += max(0, ind - (j + 1)) # 三角形の成立条件と,一番長い棒であることを考える print(ans)
import bisect def main(): n = int(eval(input())) ls = sorted(list(map(int, input().split()))) ans = 0 for i in range(n - 1): for j in range(i + 1, n): a = ls[i] b = ls[j] k = bisect.bisect_left(ls, a + b) if k > j: ans += k - j - 1 print(ans) if __name__ == "__main__": main()
false
20
[ "-n = int(eval(input()))", "-l = list(map(int, input().split()))", "-ans = 0", "-l.sort()", "-for i in range(n):", "- a = l[i] # 一番短い棒を確定", "- for j in range(i + 1, n):", "- b = l[j] # 二番目に短い棒を確定", "- ind = bisect.bisect_left(l, a + b) # 二辺の和と同じだったら耐えないので,left", "- ans += max(0, ind - (j + 1)) # 三角形の成立条件と,一番長い棒であることを考える", "-print(ans)", "+", "+def main():", "+ n = int(eval(input()))", "+ ls = sorted(list(map(int, input().split())))", "+ ans = 0", "+ for i in range(n - 1):", "+ for j in range(i + 1, n):", "+ a = ls[i]", "+ b = ls[j]", "+ k = bisect.bisect_left(ls, a + b)", "+ if k > j:", "+ ans += k - j - 1", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.038737
0.037581
1.03076
[ "s389488167", "s705619913" ]
u353895424
p02854
python
s518097695
s582386025
607
190
34,208
26,060
Accepted
Accepted
68.7
import numpy as np n = int(eval(input())) a = list(map(int, input().split())) ans = 0 s = sum(a) a_ = np.cumsum(a) diff = [] for i in range(n): diff.append(abs(a_[i] - (s - a_[i]))) print((min(diff)))
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 s = sum(a) al = [] sum1 = 0 for i in range(0,n): # if i == 1: # sum1 = sum(a[0:i]) # else: # sum1 += a[i] sum1 += a[i] sum2 = s - sum1 # print("sum1:"+str(sum1)) # print("sum2:"+str(sum2)) al.append(abs(sum1 - sum2)) if sum1 == sum2: print((0)) exit() minDiffIdx = al.index(min(al)) # print("---") # print(minDiffIdx) # print("---") tmp1 = sum(a[0:minDiffIdx]) tmp2 = sum(a[minDiffIdx:]) # print(tmp1) # print(tmp2) diff1 = abs(tmp1 - tmp2) tmp3 = sum(a[0:minDiffIdx + 1]) tmp4 = sum(a[minDiffIdx + 1:]) # print(tmp3) # print(tmp4) diff2 = abs(tmp3 - tmp4) print((min(diff1, diff2))) # d1 = diff1 # d2 = diff2 # if d1 < d2: # for i in range(n//2): # if a[i] > 1: # d1 -= a[i] # if d1 < 0: # ans += diff1 + d1 # break # elif d1 == 0: # ans += diff1 # break # if # else:
12
56
213
1,202
import numpy as np n = int(eval(input())) a = list(map(int, input().split())) ans = 0 s = sum(a) a_ = np.cumsum(a) diff = [] for i in range(n): diff.append(abs(a_[i] - (s - a_[i]))) print((min(diff)))
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 s = sum(a) al = [] sum1 = 0 for i in range(0, n): # if i == 1: # sum1 = sum(a[0:i]) # else: # sum1 += a[i] sum1 += a[i] sum2 = s - sum1 # print("sum1:"+str(sum1)) # print("sum2:"+str(sum2)) al.append(abs(sum1 - sum2)) if sum1 == sum2: print((0)) exit() minDiffIdx = al.index(min(al)) # print("---") # print(minDiffIdx) # print("---") tmp1 = sum(a[0:minDiffIdx]) tmp2 = sum(a[minDiffIdx:]) # print(tmp1) # print(tmp2) diff1 = abs(tmp1 - tmp2) tmp3 = sum(a[0 : minDiffIdx + 1]) tmp4 = sum(a[minDiffIdx + 1 :]) # print(tmp3) # print(tmp4) diff2 = abs(tmp3 - tmp4) print((min(diff1, diff2))) # d1 = diff1 # d2 = diff2 # if d1 < d2: # for i in range(n//2): # if a[i] > 1: # d1 -= a[i] # if d1 < 0: # ans += diff1 + d1 # break # elif d1 == 0: # ans += diff1 # break # if # else:
false
78.571429
[ "-import numpy as np", "-", "-a_ = np.cumsum(a)", "-diff = []", "-for i in range(n):", "- diff.append(abs(a_[i] - (s - a_[i])))", "-print((min(diff)))", "+al = []", "+sum1 = 0", "+for i in range(0, n):", "+ # if i == 1:", "+ # sum1 = sum(a[0:i])", "+ # else:", "+ # sum1 += a[i]", "+ sum1 += a[i]", "+ sum2 = s - sum1", "+ # print(\"sum1:\"+str(sum1))", "+ # print(\"sum2:\"+str(sum2))", "+ al.append(abs(sum1 - sum2))", "+ if sum1 == sum2:", "+ print((0))", "+ exit()", "+minDiffIdx = al.index(min(al))", "+# print(minDiffIdx)", "+tmp1 = sum(a[0:minDiffIdx])", "+tmp2 = sum(a[minDiffIdx:])", "+# print(tmp1)", "+# print(tmp2)", "+diff1 = abs(tmp1 - tmp2)", "+tmp3 = sum(a[0 : minDiffIdx + 1])", "+tmp4 = sum(a[minDiffIdx + 1 :])", "+# print(tmp3)", "+# print(tmp4)", "+diff2 = abs(tmp3 - tmp4)", "+print((min(diff1, diff2)))", "+# d1 = diff1", "+# d2 = diff2", "+# if d1 < d2:", "+# for i in range(n//2):", "+# if a[i] > 1:", "+# d1 -= a[i]", "+# if d1 < 0:", "+# ans += diff1 + d1", "+# break", "+# elif d1 == 0:", "+# ans += diff1", "+# break", "+# if", "+# else:" ]
false
0.669942
0.038933
17.207681
[ "s518097695", "s582386025" ]
u579324544
p02923
python
s695526230
s012981173
220
93
63,856
14,224
Accepted
Accepted
57.73
if __name__ == "__main__": b = int(eval(input())) a = list(map(int, input().split())) a = a[::-1] count = 0 value = 0 for i in range(1, b): if a[i-1] <= a[i]: count+=1 else: count = 0 value = max(count, value) print(value)
n = eval(input()) a = list(map(int, input().split())) #b = list(map(int, input().split())) #c = list(map(int, input().split())) m = 0 c = 0 for i in range(1, len(a)): if a[i] <= a[i-1]: c += 1 m = max(m, c) else: c = 0 print(m)
12
13
284
265
if __name__ == "__main__": b = int(eval(input())) a = list(map(int, input().split())) a = a[::-1] count = 0 value = 0 for i in range(1, b): if a[i - 1] <= a[i]: count += 1 else: count = 0 value = max(count, value) print(value)
n = eval(input()) a = list(map(int, input().split())) # b = list(map(int, input().split())) # c = list(map(int, input().split())) m = 0 c = 0 for i in range(1, len(a)): if a[i] <= a[i - 1]: c += 1 m = max(m, c) else: c = 0 print(m)
false
7.692308
[ "-if __name__ == \"__main__\":", "- b = int(eval(input()))", "- a = list(map(int, input().split()))", "- a = a[::-1]", "- count = 0", "- value = 0", "- for i in range(1, b):", "- if a[i - 1] <= a[i]:", "- count += 1", "- else:", "- count = 0", "- value = max(count, value)", "- print(value)", "+n = eval(input())", "+a = list(map(int, input().split()))", "+# b = list(map(int, input().split()))", "+# c = list(map(int, input().split()))", "+m = 0", "+c = 0", "+for i in range(1, len(a)):", "+ if a[i] <= a[i - 1]:", "+ c += 1", "+ m = max(m, c)", "+ else:", "+ c = 0", "+print(m)" ]
false
0.040154
0.040026
1.003212
[ "s695526230", "s012981173" ]
u597374218
p03329
python
s557766931
s545510849
331
214
3,060
9,012
Accepted
Accepted
35.35
N = int(eval(input())) ans = N for i in range(N+1): cnt = 0 t = i while t>0: cnt+=t%6 t//=6 j=N-i while j>0: cnt+=j%9 j//=9 ans = min(ans,cnt) print(ans)
N=int(eval(input())) ans=N for i in range(N+1): count=0 t=i while t>0: count+=t%6 t//=6 t=N-i while t>0: count+=t%9 t//=9 ans=min(ans,count) print(ans)
14
14
216
214
N = int(eval(input())) ans = N for i in range(N + 1): cnt = 0 t = i while t > 0: cnt += t % 6 t //= 6 j = N - i while j > 0: cnt += j % 9 j //= 9 ans = min(ans, cnt) print(ans)
N = int(eval(input())) ans = N for i in range(N + 1): count = 0 t = i while t > 0: count += t % 6 t //= 6 t = N - i while t > 0: count += t % 9 t //= 9 ans = min(ans, count) print(ans)
false
0
[ "- cnt = 0", "+ count = 0", "- cnt += t % 6", "+ count += t % 6", "- j = N - i", "- while j > 0:", "- cnt += j % 9", "- j //= 9", "- ans = min(ans, cnt)", "+ t = N - i", "+ while t > 0:", "+ count += t % 9", "+ t //= 9", "+ ans = min(ans, count)" ]
false
0.062061
0.06118
1.014408
[ "s557766931", "s545510849" ]
u063052907
p03353
python
s831760421
s667164998
40
34
4,464
4,464
Accepted
Accepted
15
s = eval(input()) k = int(eval(input())) ans_set = set() for i in range(len(s)): c = s[i] ans_set.add(c) for j in range(i + 1, len(s)): c += s[j] if len(c) > k: break ans_set.add(c) ans_lst = list(ans_set) ans_lst.sort() ans = ans_lst[k-1] print(ans)
s = eval(input()) k = int(eval(input())) set_ans = set() for i in range(k): for j in range(len(s)): set_ans.add(s[j:j+i+1]) lst_ans = list(set_ans) lst_ans.sort() ans = lst_ans[k-1] print(ans)
21
14
312
209
s = eval(input()) k = int(eval(input())) ans_set = set() for i in range(len(s)): c = s[i] ans_set.add(c) for j in range(i + 1, len(s)): c += s[j] if len(c) > k: break ans_set.add(c) ans_lst = list(ans_set) ans_lst.sort() ans = ans_lst[k - 1] print(ans)
s = eval(input()) k = int(eval(input())) set_ans = set() for i in range(k): for j in range(len(s)): set_ans.add(s[j : j + i + 1]) lst_ans = list(set_ans) lst_ans.sort() ans = lst_ans[k - 1] print(ans)
false
33.333333
[ "-ans_set = set()", "-for i in range(len(s)):", "- c = s[i]", "- ans_set.add(c)", "- for j in range(i + 1, len(s)):", "- c += s[j]", "- if len(c) > k:", "- break", "- ans_set.add(c)", "-ans_lst = list(ans_set)", "-ans_lst.sort()", "-ans = ans_lst[k - 1]", "+set_ans = set()", "+for i in range(k):", "+ for j in range(len(s)):", "+ set_ans.add(s[j : j + i + 1])", "+lst_ans = list(set_ans)", "+lst_ans.sort()", "+ans = lst_ans[k - 1]" ]
false
0.048708
0.048656
1.001076
[ "s831760421", "s667164998" ]
u704460404
p02972
python
s083513882
s411380835
469
212
14,108
14,492
Accepted
Accepted
54.8
import sys input = sys.stdin.readline def sumN(n,N,f): total = 0 i = n while i < N: total += f[i] i += n+1 if total % 2: return 1 else: return 0 def main(): N = int(eval(input())) a = list(map(int,input().split())) ball = [] ballNum = 0 f = [0]*N for i in reversed(list(range(1,N))): if sumN(i,N,f) != (a[i] % 2): f[i] = 1 ball.append(i+1) ballNum +=1 if (sum(f) % 2) != (a[0] % 2): f[0] = 1 ball.append(1) ballNum +=1 print(ballNum) print((*ball)) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def sumN(n,N,f): total = 0 i = n while i < N: total += f[i] i += n+1 if total % 2: return 1 else: return 0 def main(): N = int(eval(input())) a = list(map(int,input().split())) ball = [] ballNum = 0 f = [0]*N for i in reversed(list(range(0,N))): if (sum(f[i::i+1])%2) != (a[i] % 2): f[i] = 1 ball.append(i+1) ballNum +=1 if (sum(f) % 2) != (a[0] % 2): f[0] = 1 ball.append(1) ballNum +=1 print(ballNum) print((*ball)) if __name__ == "__main__": main()
38
38
553
560
import sys input = sys.stdin.readline def sumN(n, N, f): total = 0 i = n while i < N: total += f[i] i += n + 1 if total % 2: return 1 else: return 0 def main(): N = int(eval(input())) a = list(map(int, input().split())) ball = [] ballNum = 0 f = [0] * N for i in reversed(list(range(1, N))): if sumN(i, N, f) != (a[i] % 2): f[i] = 1 ball.append(i + 1) ballNum += 1 if (sum(f) % 2) != (a[0] % 2): f[0] = 1 ball.append(1) ballNum += 1 print(ballNum) print((*ball)) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def sumN(n, N, f): total = 0 i = n while i < N: total += f[i] i += n + 1 if total % 2: return 1 else: return 0 def main(): N = int(eval(input())) a = list(map(int, input().split())) ball = [] ballNum = 0 f = [0] * N for i in reversed(list(range(0, N))): if (sum(f[i :: i + 1]) % 2) != (a[i] % 2): f[i] = 1 ball.append(i + 1) ballNum += 1 if (sum(f) % 2) != (a[0] % 2): f[0] = 1 ball.append(1) ballNum += 1 print(ballNum) print((*ball)) if __name__ == "__main__": main()
false
0
[ "- for i in reversed(list(range(1, N))):", "- if sumN(i, N, f) != (a[i] % 2):", "+ for i in reversed(list(range(0, N))):", "+ if (sum(f[i :: i + 1]) % 2) != (a[i] % 2):" ]
false
0.037492
0.04664
0.803861
[ "s083513882", "s411380835" ]
u678167152
p03175
python
s079296220
s431013442
465
184
105,448
96,264
Accepted
Accepted
60.43
import sys sys.setrecursionlimit(10**8) N = int(eval(input())) edge = [[] for _ 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) def dfs(v,mod): black,white = 1,1 for u in edge[v]: if visited[u]==False: visited[u]=True b,w = dfs(u,mod) black *= w white *= b+w black %= mod white %= mod return black,white mod = 10**9+7 visited = [False]*N visited[0]=True black,white = dfs(0,mod) print(((black+white)%mod))
import sys input = sys.stdin.readline N = int(eval(input())) edge = [[] for _ 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) def dfs(start): stack = [start] parent = [N]*N parent[start] = -1 white, black = [1]*N, [1]*N while stack: v = stack[-1] marker = 0 for u in edge[v]: if u==parent[v]: continue if parent[u]==N: #子へ降ろす marker = 1 parent[u]=v stack.append(u) else: #子から吸い上げる white[v] *= white[u]+black[u] white[v] %= mod black[v] *= white[u] black[v] %= mod if marker==0: stack.pop() ans = (black[0]+white[0])%mod return ans mod = 10**9+7 ans = dfs(0) print(ans)
27
38
532
795
import sys sys.setrecursionlimit(10**8) N = int(eval(input())) edge = [[] for _ 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) def dfs(v, mod): black, white = 1, 1 for u in edge[v]: if visited[u] == False: visited[u] = True b, w = dfs(u, mod) black *= w white *= b + w black %= mod white %= mod return black, white mod = 10**9 + 7 visited = [False] * N visited[0] = True black, white = dfs(0, mod) print(((black + white) % mod))
import sys input = sys.stdin.readline N = int(eval(input())) edge = [[] for _ 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) def dfs(start): stack = [start] parent = [N] * N parent[start] = -1 white, black = [1] * N, [1] * N while stack: v = stack[-1] marker = 0 for u in edge[v]: if u == parent[v]: continue if parent[u] == N: # 子へ降ろす marker = 1 parent[u] = v stack.append(u) else: # 子から吸い上げる white[v] *= white[u] + black[u] white[v] %= mod black[v] *= white[u] black[v] %= mod if marker == 0: stack.pop() ans = (black[0] + white[0]) % mod return ans mod = 10**9 + 7 ans = dfs(0) print(ans)
false
28.947368
[ "-sys.setrecursionlimit(10**8)", "+input = sys.stdin.readline", "-def dfs(v, mod):", "- black, white = 1, 1", "- for u in edge[v]:", "- if visited[u] == False:", "- visited[u] = True", "- b, w = dfs(u, mod)", "- black *= w", "- white *= b + w", "- black %= mod", "- white %= mod", "- return black, white", "+def dfs(start):", "+ stack = [start]", "+ parent = [N] * N", "+ parent[start] = -1", "+ white, black = [1] * N, [1] * N", "+ while stack:", "+ v = stack[-1]", "+ marker = 0", "+ for u in edge[v]:", "+ if u == parent[v]:", "+ continue", "+ if parent[u] == N: # 子へ降ろす", "+ marker = 1", "+ parent[u] = v", "+ stack.append(u)", "+ else: # 子から吸い上げる", "+ white[v] *= white[u] + black[u]", "+ white[v] %= mod", "+ black[v] *= white[u]", "+ black[v] %= mod", "+ if marker == 0:", "+ stack.pop()", "+ ans = (black[0] + white[0]) % mod", "+ return ans", "-visited = [False] * N", "-visited[0] = True", "-black, white = dfs(0, mod)", "-print(((black + white) % mod))", "+ans = dfs(0)", "+print(ans)" ]
false
0.085545
0.06242
1.370472
[ "s079296220", "s431013442" ]
u057109575
p03208
python
s895816173
s220221315
219
98
11,292
14,092
Accepted
Accepted
55.25
def main(): N, K = list(map(int, input().split())) h = [int(eval(input())) for _ in range(N)] h.sort() print((min([h[i + K - 1] - h[i] for i in range(N - K + 1)]))) if __name__ == '__main__': main()
N, K, *h = list(map(int, open(0).read().split())) h.sort() ans = [h[i + K - 1] - h[i] for i in range(N - K + 1)] print((min(ans)))
9
4
226
125
def main(): N, K = list(map(int, input().split())) h = [int(eval(input())) for _ in range(N)] h.sort() print((min([h[i + K - 1] - h[i] for i in range(N - K + 1)]))) if __name__ == "__main__": main()
N, K, *h = list(map(int, open(0).read().split())) h.sort() ans = [h[i + K - 1] - h[i] for i in range(N - K + 1)] print((min(ans)))
false
55.555556
[ "-def main():", "- N, K = list(map(int, input().split()))", "- h = [int(eval(input())) for _ in range(N)]", "- h.sort()", "- print((min([h[i + K - 1] - h[i] for i in range(N - K + 1)])))", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+N, K, *h = list(map(int, open(0).read().split()))", "+h.sort()", "+ans = [h[i + K - 1] - h[i] for i in range(N - K + 1)]", "+print((min(ans)))" ]
false
0.040817
0.042021
0.971358
[ "s895816173", "s220221315" ]
u475503988
p02623
python
s458966175
s478106651
177
137
124,652
116,216
Accepted
Accepted
22.6
import sys input = sys.stdin.buffer.readline import bisect N, M, K = list(map(int, input().split())) A = list(map(int, (input().split()))) B = list(map(int, (input().split()))) cumA, cumB = [0], [0] for a in A: cumA.append(cumA[-1]+a) for b in B: cumB.append(cumB[-1]+b) ans = 0 for i in range(N, -1, -1): if cumA[i] > K: continue j = bisect.bisect_right(cumB, K-cumA[i]) ans = max(ans, i+j-1) print(ans)
import sys input = sys.stdin.buffer.readline N, M, K = list(map(int, input().split())) A = list(map(int, (input().split()))) B = list(map(int, (input().split()))) t = sum(B) # 尺取法 j = M # bはmから減らしていく ans = 0 for i in range(N+1): # aは0からnまで増やしていく if i: t += A[i-1] # i個までの累計になるように足す 0個は0 while (j>0 and t>K): # t<=k または j==0 で抜ける j -= 1 t -= B[j] if t>K: break # bが0番まで行っても t>k の場合はだめ ans = max(ans, i+j) print(ans)
18
18
436
471
import sys input = sys.stdin.buffer.readline import bisect N, M, K = list(map(int, input().split())) A = list(map(int, (input().split()))) B = list(map(int, (input().split()))) cumA, cumB = [0], [0] for a in A: cumA.append(cumA[-1] + a) for b in B: cumB.append(cumB[-1] + b) ans = 0 for i in range(N, -1, -1): if cumA[i] > K: continue j = bisect.bisect_right(cumB, K - cumA[i]) ans = max(ans, i + j - 1) print(ans)
import sys input = sys.stdin.buffer.readline N, M, K = list(map(int, input().split())) A = list(map(int, (input().split()))) B = list(map(int, (input().split()))) t = sum(B) # 尺取法 j = M # bはmから減らしていく ans = 0 for i in range(N + 1): # aは0からnまで増やしていく if i: t += A[i - 1] # i個までの累計になるように足す 0個は0 while j > 0 and t > K: # t<=k または j==0 で抜ける j -= 1 t -= B[j] if t > K: break # bが0番まで行っても t>k の場合はだめ ans = max(ans, i + j) print(ans)
false
0
[ "-import bisect", "-", "-cumA, cumB = [0], [0]", "-for a in A:", "- cumA.append(cumA[-1] + a)", "-for b in B:", "- cumB.append(cumB[-1] + b)", "+t = sum(B)", "+# 尺取法", "+j = M # bはmから減らしていく", "-for i in range(N, -1, -1):", "- if cumA[i] > K:", "- continue", "- j = bisect.bisect_right(cumB, K - cumA[i])", "- ans = max(ans, i + j - 1)", "+for i in range(N + 1): # aは0からnまで増やしていく", "+ if i:", "+ t += A[i - 1] # i個までの累計になるように足す 0個は0", "+ while j > 0 and t > K: # t<=k または j==0 で抜ける", "+ j -= 1", "+ t -= B[j]", "+ if t > K:", "+ break # bが0番まで行っても t>k の場合はだめ", "+ ans = max(ans, i + j)" ]
false
0.048088
0.047032
1.022466
[ "s458966175", "s478106651" ]
u411203878
p04031
python
s999911385
s005040274
181
63
38,640
64,412
Accepted
Accepted
65.19
n=int(eval(input())) t = list(map(int,input().split())) t.sort() ans = 100000000000000 for i in range(t[0],t[-1]+1): memo = 0 for j in t: memo += (i-j)**2 ans = min(memo, ans) print(ans)
n=int(eval(input())) t = list(map(int,input().split())) ans = 10000000000 for i in range(-100, 101): memo = 0 for j in t: memo += (i-j)**2 ans = min(ans, memo) print(ans)
14
12
222
198
n = int(eval(input())) t = list(map(int, input().split())) t.sort() ans = 100000000000000 for i in range(t[0], t[-1] + 1): memo = 0 for j in t: memo += (i - j) ** 2 ans = min(memo, ans) print(ans)
n = int(eval(input())) t = list(map(int, input().split())) ans = 10000000000 for i in range(-100, 101): memo = 0 for j in t: memo += (i - j) ** 2 ans = min(ans, memo) print(ans)
false
14.285714
[ "-t.sort()", "-ans = 100000000000000", "-for i in range(t[0], t[-1] + 1):", "+ans = 10000000000", "+for i in range(-100, 101):", "- ans = min(memo, ans)", "+ ans = min(ans, memo)" ]
false
0.041802
0.042435
0.985101
[ "s999911385", "s005040274" ]
u366959492
p03436
python
s584873098
s907894639
211
27
40,688
3,316
Accepted
Accepted
87.2
h,w=list(map(int,input().split())) s=[list(eval(input())) for _ in range(h)] q=[(0,0)] s[0][0]=0 dxy=[(1,0),(-1,0),(0,1),(0,-1)] while q: x,y=q.pop(0) for dx,dy in dxy: nx,ny=x+dx,y+dy if not 0<=nx<w: continue if not 0<=ny<h: continue if s[ny][nx]=="#": continue if s[ny][nx]==".": s[ny][nx]=s[y][x]+1 q.append((nx,ny)) else: continue if s[h-1][w-1]=="." or s[h-1][w-1]=="#": print((-1)) else: kuro=0 for i in range(h): kuro+=s[i].count("#") print((h*w-s[h-1][w-1]-1-kuro))
h,w=list(map(int,input().split())) g=[list(eval(input())) for _ in range(h)] dyx=[(1,0),(-1,0),(0,1),(0,-1)] from collections import deque q=deque() q.append((0,0)) g[0][0]=0 while q: ny,nx=q.popleft() for dy,dx in dyx: y=ny+dy x=nx+dx if 0<=y<h and 0<=x<w and g[y][x]==".": g[y][x]=1+g[ny][nx] q.append((y,x)) if g[h-1][w-1]=="." or g[h-1][w-1]=="#": print((-1)) exit() d={} ans=0 x=g[h-1][w-1] for i in range(h): for j in range(w): if g[i][j]==".": ans+=1 g[i][j]="@" continue if g[i][j]=="#": continue if g[i][j] in d: ans+=1 g[i][j]="@" else: if g[i][j]>x: ans+=1 g[i][j]="@" d[g[i][j]]=1 print(ans)
29
40
640
859
h, w = list(map(int, input().split())) s = [list(eval(input())) for _ in range(h)] q = [(0, 0)] s[0][0] = 0 dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)] while q: x, y = q.pop(0) for dx, dy in dxy: nx, ny = x + dx, y + dy if not 0 <= nx < w: continue if not 0 <= ny < h: continue if s[ny][nx] == "#": continue if s[ny][nx] == ".": s[ny][nx] = s[y][x] + 1 q.append((nx, ny)) else: continue if s[h - 1][w - 1] == "." or s[h - 1][w - 1] == "#": print((-1)) else: kuro = 0 for i in range(h): kuro += s[i].count("#") print((h * w - s[h - 1][w - 1] - 1 - kuro))
h, w = list(map(int, input().split())) g = [list(eval(input())) for _ in range(h)] dyx = [(1, 0), (-1, 0), (0, 1), (0, -1)] from collections import deque q = deque() q.append((0, 0)) g[0][0] = 0 while q: ny, nx = q.popleft() for dy, dx in dyx: y = ny + dy x = nx + dx if 0 <= y < h and 0 <= x < w and g[y][x] == ".": g[y][x] = 1 + g[ny][nx] q.append((y, x)) if g[h - 1][w - 1] == "." or g[h - 1][w - 1] == "#": print((-1)) exit() d = {} ans = 0 x = g[h - 1][w - 1] for i in range(h): for j in range(w): if g[i][j] == ".": ans += 1 g[i][j] = "@" continue if g[i][j] == "#": continue if g[i][j] in d: ans += 1 g[i][j] = "@" else: if g[i][j] > x: ans += 1 g[i][j] = "@" d[g[i][j]] = 1 print(ans)
false
27.5
[ "-s = [list(eval(input())) for _ in range(h)]", "-q = [(0, 0)]", "-s[0][0] = 0", "-dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]", "+g = [list(eval(input())) for _ in range(h)]", "+dyx = [(1, 0), (-1, 0), (0, 1), (0, -1)]", "+from collections import deque", "+", "+q = deque()", "+q.append((0, 0))", "+g[0][0] = 0", "- x, y = q.pop(0)", "- for dx, dy in dxy:", "- nx, ny = x + dx, y + dy", "- if not 0 <= nx < w:", "+ ny, nx = q.popleft()", "+ for dy, dx in dyx:", "+ y = ny + dy", "+ x = nx + dx", "+ if 0 <= y < h and 0 <= x < w and g[y][x] == \".\":", "+ g[y][x] = 1 + g[ny][nx]", "+ q.append((y, x))", "+if g[h - 1][w - 1] == \".\" or g[h - 1][w - 1] == \"#\":", "+ print((-1))", "+ exit()", "+d = {}", "+ans = 0", "+x = g[h - 1][w - 1]", "+for i in range(h):", "+ for j in range(w):", "+ if g[i][j] == \".\":", "+ ans += 1", "+ g[i][j] = \"@\"", "- if not 0 <= ny < h:", "+ if g[i][j] == \"#\":", "- if s[ny][nx] == \"#\":", "- continue", "- if s[ny][nx] == \".\":", "- s[ny][nx] = s[y][x] + 1", "- q.append((nx, ny))", "+ if g[i][j] in d:", "+ ans += 1", "+ g[i][j] = \"@\"", "- continue", "-if s[h - 1][w - 1] == \".\" or s[h - 1][w - 1] == \"#\":", "- print((-1))", "-else:", "- kuro = 0", "- for i in range(h):", "- kuro += s[i].count(\"#\")", "- print((h * w - s[h - 1][w - 1] - 1 - kuro))", "+ if g[i][j] > x:", "+ ans += 1", "+ g[i][j] = \"@\"", "+ d[g[i][j]] = 1", "+print(ans)" ]
false
0.065844
0.042342
1.555059
[ "s584873098", "s907894639" ]
u046158516
p03730
python
s171108285
s817554390
175
72
38,256
61,980
Accepted
Accepted
58.86
def computeGCD(x, y): while(y): x, y = y, x % y return x a,b,c=list(map(int,input().split())) if c%(computeGCD(a,b))==0: print('YES') else: print('NO')
import math a,b,c=list(map(int,input().split())) if c%(math.gcd(a,b))==0: print('YES') else: print('NO')
11
6
182
107
def computeGCD(x, y): while y: x, y = y, x % y return x a, b, c = list(map(int, input().split())) if c % (computeGCD(a, b)) == 0: print("YES") else: print("NO")
import math a, b, c = list(map(int, input().split())) if c % (math.gcd(a, b)) == 0: print("YES") else: print("NO")
false
45.454545
[ "-def computeGCD(x, y):", "- while y:", "- x, y = y, x % y", "- return x", "-", "+import math", "-if c % (computeGCD(a, b)) == 0:", "+if c % (math.gcd(a, b)) == 0:" ]
false
0.007304
0.035293
0.20696
[ "s171108285", "s817554390" ]
u351892848
p02615
python
s874589735
s167384283
171
137
32,608
31,380
Accepted
Accepted
19.88
import sys from collections import deque input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) deq = deque([A[0]]) ans = 0 for x in A[1:]: ans += deq.popleft() deq.append(x) deq.append(x) print(ans)
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = 0 for i in range(1, N): ans += A[i // 2] print(ans)
19
14
282
192
import sys from collections import deque input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) deq = deque([A[0]]) ans = 0 for x in A[1:]: ans += deq.popleft() deq.append(x) deq.append(x) print(ans)
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) A.sort(reverse=True) ans = 0 for i in range(1, N): ans += A[i // 2] print(ans)
false
26.315789
[ "-from collections import deque", "-deq = deque([A[0]])", "-for x in A[1:]:", "- ans += deq.popleft()", "- deq.append(x)", "- deq.append(x)", "+for i in range(1, N):", "+ ans += A[i // 2]" ]
false
0.049275
0.048198
1.022343
[ "s874589735", "s167384283" ]
u796942881
p03262
python
s474230167
s493266659
61
55
14,052
14,052
Accepted
Accepted
9.84
def gcd(a, b): while b: a, b = b, a % b return a def main(): N, X, *xn = list(map(int, open(0).read().split())) ans = None for x in xn: div = abs(X - x) if ans is None: ans = div elif abs(X - x) % ans: ans = gcd(ans, abs(X - x)) print(ans) return main()
def gcd(a, b): while b: a, b = b, a % b return a def main(): N, X, *xn = list(map(int, open(0).read().split())) ans = None for x in xn: div = abs(X - x) if ans is None: ans = div elif div % ans: ans = gcd(ans, div) print(ans) return main()
20
20
355
341
def gcd(a, b): while b: a, b = b, a % b return a def main(): N, X, *xn = list(map(int, open(0).read().split())) ans = None for x in xn: div = abs(X - x) if ans is None: ans = div elif abs(X - x) % ans: ans = gcd(ans, abs(X - x)) print(ans) return main()
def gcd(a, b): while b: a, b = b, a % b return a def main(): N, X, *xn = list(map(int, open(0).read().split())) ans = None for x in xn: div = abs(X - x) if ans is None: ans = div elif div % ans: ans = gcd(ans, div) print(ans) return main()
false
0
[ "- elif abs(X - x) % ans:", "- ans = gcd(ans, abs(X - x))", "+ elif div % ans:", "+ ans = gcd(ans, div)" ]
false
0.038202
0.04899
0.779788
[ "s474230167", "s493266659" ]
u801359367
p03325
python
s385216829
s586527827
104
89
4,152
4,148
Accepted
Accepted
14.42
N = int(eval(input())) A = list(map(int,input().split())) SUM = 0 for i in A: count = 0 while i%2 == 0: i = i/2 count += 1 SUM+=count print(SUM)
N = int(eval(input())) A = list(map(int,input().split())) SUM = 0 for i in A: count = 0 while i%2 == 0: i//=2 count += 1 SUM+=count print(SUM)
11
11
177
175
N = int(eval(input())) A = list(map(int, input().split())) SUM = 0 for i in A: count = 0 while i % 2 == 0: i = i / 2 count += 1 SUM += count print(SUM)
N = int(eval(input())) A = list(map(int, input().split())) SUM = 0 for i in A: count = 0 while i % 2 == 0: i //= 2 count += 1 SUM += count print(SUM)
false
0
[ "- i = i / 2", "+ i //= 2" ]
false
0.038613
0.037504
1.029563
[ "s385216829", "s586527827" ]
u281610856
p02861
python
s333704432
s683818665
470
374
4,504
3,060
Accepted
Accepted
20.43
import itertools N = int(eval(input())) P = [] L_total = [] for i in range(N): p = list(map(int, input().split())) P.append(p) for v in itertools.permutations(P, N): L = [] for i in range(N - 1): l = ((v[i][0] - v[i + 1][0]) ** 2 + (v[i][1] - v[i + 1][1]) ** 2) ** 0.5 L.append(l) L_total.append(sum(L)) ans = sum(L_total) / (len(L_total)) print(ans)
from itertools import permutations import math n = int(eval(input())) arr = [tuple(map(int, input().split())) for _ in range(n)] total = 0 for v in permutations(arr, n): d = 0 for i in range(n-1): x1, y1 = v[i] x2, y2 = v[i+1] d += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) total += d print((total / math.factorial(n)))
16
15
396
365
import itertools N = int(eval(input())) P = [] L_total = [] for i in range(N): p = list(map(int, input().split())) P.append(p) for v in itertools.permutations(P, N): L = [] for i in range(N - 1): l = ((v[i][0] - v[i + 1][0]) ** 2 + (v[i][1] - v[i + 1][1]) ** 2) ** 0.5 L.append(l) L_total.append(sum(L)) ans = sum(L_total) / (len(L_total)) print(ans)
from itertools import permutations import math n = int(eval(input())) arr = [tuple(map(int, input().split())) for _ in range(n)] total = 0 for v in permutations(arr, n): d = 0 for i in range(n - 1): x1, y1 = v[i] x2, y2 = v[i + 1] d += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) total += d print((total / math.factorial(n)))
false
6.25
[ "-import itertools", "+from itertools import permutations", "+import math", "-N = int(eval(input()))", "-P = []", "-L_total = []", "-for i in range(N):", "- p = list(map(int, input().split()))", "- P.append(p)", "-for v in itertools.permutations(P, N):", "- L = []", "- for i in range(N - 1):", "- l = ((v[i][0] - v[i + 1][0]) ** 2 + (v[i][1] - v[i + 1][1]) ** 2) ** 0.5", "- L.append(l)", "- L_total.append(sum(L))", "-ans = sum(L_total) / (len(L_total))", "-print(ans)", "+n = int(eval(input()))", "+arr = [tuple(map(int, input().split())) for _ in range(n)]", "+total = 0", "+for v in permutations(arr, n):", "+ d = 0", "+ for i in range(n - 1):", "+ x1, y1 = v[i]", "+ x2, y2 = v[i + 1]", "+ d += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)", "+ total += d", "+print((total / math.factorial(n)))" ]
false
0.036402
0.036892
0.986719
[ "s333704432", "s683818665" ]
u806976856
p03252
python
s626729325
s587621708
203
109
12,412
9,552
Accepted
Accepted
46.31
s=list(eval(input())) t=list(eval(input())) n=len(s) a=[s.count(chr(97+i)) for i in range(26)] b=[t.count(chr(97+i)) for i in range(26)] if all(a[ord(s[i])-97]==b[ord(t[i])-97] for i in range(n)): print("Yes") else: print("No")
s=eval(input()) t=eval(input()) n=len(s) f=0 a=[[] for i in range(26)] for i in range(n): if len(a[ord(s[i])-97])==0: a[ord(s[i])-97].append(t[i]) else: if a[ord(s[i])-97][0]!=t[i]: f=1 x=[a[i][0] for i in range(26) if len(a[i])==1] if len(x)!=len(set(x)): f=1 print(("Yes" if f==0 else "No"))
10
18
234
348
s = list(eval(input())) t = list(eval(input())) n = len(s) a = [s.count(chr(97 + i)) for i in range(26)] b = [t.count(chr(97 + i)) for i in range(26)] if all(a[ord(s[i]) - 97] == b[ord(t[i]) - 97] for i in range(n)): print("Yes") else: print("No")
s = eval(input()) t = eval(input()) n = len(s) f = 0 a = [[] for i in range(26)] for i in range(n): if len(a[ord(s[i]) - 97]) == 0: a[ord(s[i]) - 97].append(t[i]) else: if a[ord(s[i]) - 97][0] != t[i]: f = 1 x = [a[i][0] for i in range(26) if len(a[i]) == 1] if len(x) != len(set(x)): f = 1 print(("Yes" if f == 0 else "No"))
false
44.444444
[ "-s = list(eval(input()))", "-t = list(eval(input()))", "+s = eval(input())", "+t = eval(input())", "-a = [s.count(chr(97 + i)) for i in range(26)]", "-b = [t.count(chr(97 + i)) for i in range(26)]", "-if all(a[ord(s[i]) - 97] == b[ord(t[i]) - 97] for i in range(n)):", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+f = 0", "+a = [[] for i in range(26)]", "+for i in range(n):", "+ if len(a[ord(s[i]) - 97]) == 0:", "+ a[ord(s[i]) - 97].append(t[i])", "+ else:", "+ if a[ord(s[i]) - 97][0] != t[i]:", "+ f = 1", "+x = [a[i][0] for i in range(26) if len(a[i]) == 1]", "+if len(x) != len(set(x)):", "+ f = 1", "+print((\"Yes\" if f == 0 else \"No\"))" ]
false
0.036268
0.045952
0.789276
[ "s626729325", "s587621708" ]
u896741788
p03775
python
s748692676
s943027983
40
35
7,668
7,668
Accepted
Accepted
12.5
n=int(eval(input())) m=int((n**(1/2))//1+1) l=[] for i in list(range(m+1))[:0:-1]: if n%i==0: l.append(max(len(str(i)),len(str(n//i)))) if len(l)==2: break print((min(l)))
n=int(eval(input())) m=int((n**(1/2))//1+1) l=[] for i in list(range(m+1))[:0:-1]: if n%i==0: l.append(max(len(str(i)),len(str(n//i)))) break print((min(l)))
9
8
183
166
n = int(eval(input())) m = int((n ** (1 / 2)) // 1 + 1) l = [] for i in list(range(m + 1))[:0:-1]: if n % i == 0: l.append(max(len(str(i)), len(str(n // i)))) if len(l) == 2: break print((min(l)))
n = int(eval(input())) m = int((n ** (1 / 2)) // 1 + 1) l = [] for i in list(range(m + 1))[:0:-1]: if n % i == 0: l.append(max(len(str(i)), len(str(n // i)))) break print((min(l)))
false
11.111111
[ "- if len(l) == 2:" ]
false
0.142484
0.046281
3.078695
[ "s748692676", "s943027983" ]
u270144704
p02573
python
s865431986
s236023732
552
480
121,508
109,196
Accepted
Accepted
13.04
from collections import Counter n, m = list(map(int, input().split())) ab = [tuple(map(int, input().split())) for _ in range(m)] class UnionFind: # まずは最初の状態を作る def __init__(self, N): # 最初はみんなバラバラ self.parent = [i for i in range(N)] self.rank = [0] * N self.count = 0 # そのノードの根を返す過程で,集合の要素を根に直接つなぎかえる(木の最適化) def root(self, a): if self.parent[a] == a: return a else: self.parent[a] = self.root(self.parent[a]) return self.parent[a] # aとbの根が同じ,つまり同じ連結成分内かどうかを返す def is_same(self, a, b): return self.root(a) == self.root(b) # 連結成分同士を効率的に(rankが大きい方を動かさずにrankが小さい方をくっつける) def unite(self, a, b): ra = self.root(a) rb = self.root(b) # a, bが同じグループ内にいたから何もしない if ra == rb: return # 異なるグループにいた場合 # 短い方をくっつける if self.rank[ra] < self.rank[rb]: self.parent[ra] = rb else: self.parent[rb] = ra if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1 self.count += 1 # friendsは友達の数を保持する uf = UnionFind(n) for a, b in ab: a, b = a-1, b-1 # aとbが同連結成分内であれば何もする必要がない if uf.is_same(a, b): continue # 異なれば結合 uf.unite(a, b) # 木の高さの最適化 for i in range(n): uf.root(i) tmp = sorted(list(Counter(uf.parent).items()), key=lambda x:x[1]) print((tmp[-1][1]))
from collections import Counter n, m = list(map(int, input().split())) ab = [tuple(map(int, input().split())) for _ in range(m)] class UnionFind(): def __init__(self, n): self.n = n # 要素が根の場合、-(そのグループの要素数)を格納 self.parents = [-1] * n # 要素xが属するグループの根を返す def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] # 要素xが属するグループと要素yが属するグループとを併合する 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 # 要素xが属するグループのサイズ(要素数)を返す def size(self, x): return -self.parents[self.find(x)] # 要素x, yが同じグループに属すかどうか返す def same(self, x, y): return self.find(x) == self.find(y) # 要素xが属するグループに属する要素をリストで返す 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()} # printでの表示用, ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) tree = UnionFind(n) for a, b in ab: a,b = a-1, b-1 if not tree.same(a, b): tree.union(a, b) ans = float("-inf") for i in range(n): ans = max(ans, tree.size(i)) print(ans)
52
70
1,423
1,909
from collections import Counter n, m = list(map(int, input().split())) ab = [tuple(map(int, input().split())) for _ in range(m)] class UnionFind: # まずは最初の状態を作る def __init__(self, N): # 最初はみんなバラバラ self.parent = [i for i in range(N)] self.rank = [0] * N self.count = 0 # そのノードの根を返す過程で,集合の要素を根に直接つなぎかえる(木の最適化) def root(self, a): if self.parent[a] == a: return a else: self.parent[a] = self.root(self.parent[a]) return self.parent[a] # aとbの根が同じ,つまり同じ連結成分内かどうかを返す def is_same(self, a, b): return self.root(a) == self.root(b) # 連結成分同士を効率的に(rankが大きい方を動かさずにrankが小さい方をくっつける) def unite(self, a, b): ra = self.root(a) rb = self.root(b) # a, bが同じグループ内にいたから何もしない if ra == rb: return # 異なるグループにいた場合 # 短い方をくっつける if self.rank[ra] < self.rank[rb]: self.parent[ra] = rb else: self.parent[rb] = ra if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1 self.count += 1 # friendsは友達の数を保持する uf = UnionFind(n) for a, b in ab: a, b = a - 1, b - 1 # aとbが同連結成分内であれば何もする必要がない if uf.is_same(a, b): continue # 異なれば結合 uf.unite(a, b) # 木の高さの最適化 for i in range(n): uf.root(i) tmp = sorted(list(Counter(uf.parent).items()), key=lambda x: x[1]) print((tmp[-1][1]))
from collections import Counter n, m = list(map(int, input().split())) ab = [tuple(map(int, input().split())) for _ in range(m)] class UnionFind: def __init__(self, n): self.n = n # 要素が根の場合、-(そのグループの要素数)を格納 self.parents = [-1] * n # 要素xが属するグループの根を返す def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] # 要素xが属するグループと要素yが属するグループとを併合する 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 # 要素xが属するグループのサイズ(要素数)を返す def size(self, x): return -self.parents[self.find(x)] # 要素x, yが同じグループに属すかどうか返す def same(self, x, y): return self.find(x) == self.find(y) # 要素xが属するグループに属する要素をリストで返す 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()} # printでの表示用, ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) tree = UnionFind(n) for a, b in ab: a, b = a - 1, b - 1 if not tree.same(a, b): tree.union(a, b) ans = float("-inf") for i in range(n): ans = max(ans, tree.size(i)) print(ans)
false
25.714286
[ "- # まずは最初の状態を作る", "- def __init__(self, N):", "- # 最初はみんなバラバラ", "- self.parent = [i for i in range(N)]", "- self.rank = [0] * N", "- self.count = 0", "+ def __init__(self, n):", "+ self.n = n", "+ # 要素が根の場合、-(そのグループの要素数)を格納", "+ self.parents = [-1] * n", "- # そのノードの根を返す過程で,集合の要素を根に直接つなぎかえる(木の最適化)", "- def root(self, a):", "- if self.parent[a] == a:", "- return a", "+ # 要素xが属するグループの根を返す", "+ def find(self, x):", "+ if self.parents[x] < 0:", "+ return x", "- self.parent[a] = self.root(self.parent[a])", "- return self.parent[a]", "+ self.parents[x] = self.find(self.parents[x])", "+ return self.parents[x]", "- # aとbの根が同じ,つまり同じ連結成分内かどうかを返す", "- def is_same(self, a, b):", "- return self.root(a) == self.root(b)", "+ # 要素xが属するグループと要素yが属するグループとを併合する", "+ 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", "- # 連結成分同士を効率的に(rankが大きい方を動かさずにrankが小さい方をくっつける)", "- def unite(self, a, b):", "- ra = self.root(a)", "- rb = self.root(b)", "- # a, bが同じグループ内にいたから何もしない", "- if ra == rb:", "- return", "- # 異なるグループにいた場合", "- # 短い方をくっつける", "- if self.rank[ra] < self.rank[rb]:", "- self.parent[ra] = rb", "- else:", "- self.parent[rb] = ra", "- if self.rank[ra] == self.rank[rb]:", "- self.rank[ra] += 1", "- self.count += 1", "+ # 要素xが属するグループのサイズ(要素数)を返す", "+ def size(self, x):", "+ return -self.parents[self.find(x)]", "+", "+ # 要素x, yが同じグループに属すかどうか返す", "+ def same(self, x, y):", "+ return self.find(x) == self.find(y)", "+", "+ # 要素xが属するグループに属する要素をリストで返す", "+ 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()}", "+", "+ # printでの表示用, ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す", "+ def __str__(self):", "+ return \"\\n\".join(\"{}: {}\".format(r, self.members(r)) for r in self.roots())", "-# friendsは友達の数を保持する", "-uf = UnionFind(n)", "+tree = UnionFind(n)", "- # aとbが同連結成分内であれば何もする必要がない", "- if uf.is_same(a, b):", "- continue", "- # 異なれば結合", "- uf.unite(a, b)", "-# 木の高さの最適化", "+ if not tree.same(a, b):", "+ tree.union(a, b)", "+ans = float(\"-inf\")", "- uf.root(i)", "-tmp = sorted(list(Counter(uf.parent).items()), key=lambda x: x[1])", "-print((tmp[-1][1]))", "+ ans = max(ans, tree.size(i))", "+print(ans)" ]
false
0.054535
0.052923
1.03047
[ "s865431986", "s236023732" ]
u885634168
p02659
python
s260628680
s310587797
133
61
71,136
61,792
Accepted
Accepted
54.14
from decimal import Decimal in_ = list(input().split()) A = int(in_[0]) B = Decimal(in_[1]) ans = A * B print((int(ans)))
in_ = list(input().split()) A = int(in_[0]) B = int(in_[1].replace(".", "")) ans = A * B ans = ans // 100 print(ans)
6
6
124
121
from decimal import Decimal in_ = list(input().split()) A = int(in_[0]) B = Decimal(in_[1]) ans = A * B print((int(ans)))
in_ = list(input().split()) A = int(in_[0]) B = int(in_[1].replace(".", "")) ans = A * B ans = ans // 100 print(ans)
false
0
[ "-from decimal import Decimal", "-", "-B = Decimal(in_[1])", "+B = int(in_[1].replace(\".\", \"\"))", "-print((int(ans)))", "+ans = ans // 100", "+print(ans)" ]
false
0.073161
0.044065
1.660307
[ "s260628680", "s310587797" ]
u371144639
p02658
python
s003040132
s712414886
52
47
21,668
21,700
Accepted
Accepted
9.62
def main(): n = int(eval(input())) a = list(map(int,input().split())) x = 1 if 0 in a: print((0)) return for i in a: x *= i if x > 1000000000000000000: print((-1)) return print(x) main()
def main(): n = int(eval(input())) a = list(map(int,input().split())) x = 1 if 0 in a: print((0)) return for i in range(len(a)): b = a[i] x *= b if x > 1000000000000000000: print((-1)) return print(x) main()
14
15
269
299
def main(): n = int(eval(input())) a = list(map(int, input().split())) x = 1 if 0 in a: print((0)) return for i in a: x *= i if x > 1000000000000000000: print((-1)) return print(x) main()
def main(): n = int(eval(input())) a = list(map(int, input().split())) x = 1 if 0 in a: print((0)) return for i in range(len(a)): b = a[i] x *= b if x > 1000000000000000000: print((-1)) return print(x) main()
false
6.666667
[ "- for i in a:", "- x *= i", "+ for i in range(len(a)):", "+ b = a[i]", "+ x *= b" ]
false
0.048931
0.04866
1.005558
[ "s003040132", "s712414886" ]
u530663965
p02269
python
s148764689
s263734436
1,030
920
108,376
108,356
Accepted
Accepted
10.68
import sys n = int(eval(input())) dic = {} input_ = sys.stdin.readlines() for i in input_: c, s = i.split() if c == 'insert': dic[s] = 0 else: if s in dic: print('yes') else: print('no')
import sys def main(): _ = int(eval(input())) imps = sys.stdin.readlines() db = {} for imp in imps: c, k = imp.split(' ') if c == 'insert': db[k] = 0 elif k in db: print('yes') else: print('no') main()
15
20
258
304
import sys n = int(eval(input())) dic = {} input_ = sys.stdin.readlines() for i in input_: c, s = i.split() if c == "insert": dic[s] = 0 else: if s in dic: print("yes") else: print("no")
import sys def main(): _ = int(eval(input())) imps = sys.stdin.readlines() db = {} for imp in imps: c, k = imp.split(" ") if c == "insert": db[k] = 0 elif k in db: print("yes") else: print("no") main()
false
25
[ "-n = int(eval(input()))", "-dic = {}", "-input_ = sys.stdin.readlines()", "-for i in input_:", "- c, s = i.split()", "- if c == \"insert\":", "- dic[s] = 0", "- else:", "- if s in dic:", "+", "+def main():", "+ _ = int(eval(input()))", "+ imps = sys.stdin.readlines()", "+ db = {}", "+ for imp in imps:", "+ c, k = imp.split(\" \")", "+ if c == \"insert\":", "+ db[k] = 0", "+ elif k in db:", "+", "+", "+main()" ]
false
0.106481
0.131638
0.808891
[ "s148764689", "s263734436" ]
u761320129
p02609
python
s382815484
s150774620
754
579
33,092
33,100
Accepted
Accepted
23.21
import sys sys.setrecursionlimit(10**8) N = int(input()) X = input() if X == '0': for _ in range(N): print(1) exit() mem = [None] * (200005) mem[0] = 0 def f(n): if mem[n] is not None: return mem[n] c = bin(n).count('1') r = 1 + f(n%c) mem[n] = r return r for i in range(200005): f(i) cnt = X.count('1') a,b = cnt+1, cnt-1 ans = [None] * N n = 0 for c in X: n *= 2 n += int(c) n %= a for i,c in reversed(list(enumerate(X))): if c=='1': continue ans[i] = mem[(n+pow(2,N-i-1,a))%a] + 1 if b: n = 0 for c in X: n *= 2 n += int(c) n %= b for i,c in reversed(list(enumerate(X))): if c=='0': continue ans[i] = mem[(n-pow(2,N-i-1,b))%b] + 1 else: for i in range(N): if ans[i] is None: ans[i] = 0 print(*ans, sep='\n')
import sys sys.setrecursionlimit(10**8) N = int(input()) X = input() if X == '0': for _ in range(N): print(1) exit() mem = [None] * (200005) mem[0] = 0 def f(n): if mem[n] is not None: return mem[n] c = bin(n).count('1') r = 1 + f(n%c) mem[n] = r return r for i in range(200005): f(i) cnt = X.count('1') a,b = cnt+1, cnt-1 ans = [None] * N x = int(X,2) n = x % a for i,c in reversed(list(enumerate(X))): if c=='1': continue ans[i] = mem[(n+pow(2,N-i-1,a))%a] + 1 if b: n = x % b for i,c in reversed(list(enumerate(X))): if c=='0': continue ans[i] = mem[(n-pow(2,N-i-1,b))%b] + 1 else: for i in range(N): if ans[i] is None: ans[i] = 0 print(*ans, sep='\n')
50
43
906
804
import sys sys.setrecursionlimit(10**8) N = int(input()) X = input() if X == "0": for _ in range(N): print(1) exit() mem = [None] * (200005) mem[0] = 0 def f(n): if mem[n] is not None: return mem[n] c = bin(n).count("1") r = 1 + f(n % c) mem[n] = r return r for i in range(200005): f(i) cnt = X.count("1") a, b = cnt + 1, cnt - 1 ans = [None] * N n = 0 for c in X: n *= 2 n += int(c) n %= a for i, c in reversed(list(enumerate(X))): if c == "1": continue ans[i] = mem[(n + pow(2, N - i - 1, a)) % a] + 1 if b: n = 0 for c in X: n *= 2 n += int(c) n %= b for i, c in reversed(list(enumerate(X))): if c == "0": continue ans[i] = mem[(n - pow(2, N - i - 1, b)) % b] + 1 else: for i in range(N): if ans[i] is None: ans[i] = 0 print(*ans, sep="\n")
import sys sys.setrecursionlimit(10**8) N = int(input()) X = input() if X == "0": for _ in range(N): print(1) exit() mem = [None] * (200005) mem[0] = 0 def f(n): if mem[n] is not None: return mem[n] c = bin(n).count("1") r = 1 + f(n % c) mem[n] = r return r for i in range(200005): f(i) cnt = X.count("1") a, b = cnt + 1, cnt - 1 ans = [None] * N x = int(X, 2) n = x % a for i, c in reversed(list(enumerate(X))): if c == "1": continue ans[i] = mem[(n + pow(2, N - i - 1, a)) % a] + 1 if b: n = x % b for i, c in reversed(list(enumerate(X))): if c == "0": continue ans[i] = mem[(n - pow(2, N - i - 1, b)) % b] + 1 else: for i in range(N): if ans[i] is None: ans[i] = 0 print(*ans, sep="\n")
false
14
[ "-n = 0", "-for c in X:", "- n *= 2", "- n += int(c)", "- n %= a", "+x = int(X, 2)", "+n = x % a", "- n = 0", "- for c in X:", "- n *= 2", "- n += int(c)", "- n %= b", "+ n = x % b" ]
false
0.404033
0.525753
0.768485
[ "s382815484", "s150774620" ]
u135360096
p02784
python
s536209348
s124264725
45
40
13,964
13,964
Accepted
Accepted
11.11
H, N = [int(x) for x in input().split()] attacks = [int(x) for x in input().split()] print(("Yes" if H - sum(attacks) <= 0 else "No"))
H,N= list(map(int, input().split())) AList = list(map(int,input().split())) if sum(AList)>=H: print("Yes") else: print("No")
3
6
134
127
H, N = [int(x) for x in input().split()] attacks = [int(x) for x in input().split()] print(("Yes" if H - sum(attacks) <= 0 else "No"))
H, N = list(map(int, input().split())) AList = list(map(int, input().split())) if sum(AList) >= H: print("Yes") else: print("No")
false
50
[ "-H, N = [int(x) for x in input().split()]", "-attacks = [int(x) for x in input().split()]", "-print((\"Yes\" if H - sum(attacks) <= 0 else \"No\"))", "+H, N = list(map(int, input().split()))", "+AList = list(map(int, input().split()))", "+if sum(AList) >= H:", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.03872
0.044922
0.861935
[ "s536209348", "s124264725" ]
u222668979
p03593
python
s593768130
s904688474
34
30
9,436
9,464
Accepted
Accepted
11.76
from collections import Counter h, w = list(map(int, input().split())) a = Counter(''.join(eval(input()) for _ in range(h))) center = h * w % 2 side = (h // 2) * (w % 2) + (w // 2) * (h % 2) cnt = 0 for i in a: if cnt == center: break if a[i] % 2 == 1: a[i] -= 1 cnt += 1 cnt = 0 for i in a: if cnt == side: break if a[i] % 4 == 2: a[i] -= 2 cnt += 1 print(('Yes' if sum(a[i] % 4 for i in a) == 0 else 'No'))
from collections import Counter h, w = list(map(int, input().split())) a = Counter(''.join(eval(input()) for _ in range(h))) center = h * w % 2 side = (h // 2) * (w % 2) + (w // 2) * (h % 2) cnt = 0 for i in a: if a[i] % 2 == 1: a[i] -= 1 cnt += 1 if cnt != center: print('No') exit() cnt = 0 for i in a: if cnt == side: break if a[i] % 4 == 2: a[i] -= 2 cnt += 1 print(('Yes' if sum(a[i] % 4 for i in a) == 0 else 'No'))
24
25
486
496
from collections import Counter h, w = list(map(int, input().split())) a = Counter("".join(eval(input()) for _ in range(h))) center = h * w % 2 side = (h // 2) * (w % 2) + (w // 2) * (h % 2) cnt = 0 for i in a: if cnt == center: break if a[i] % 2 == 1: a[i] -= 1 cnt += 1 cnt = 0 for i in a: if cnt == side: break if a[i] % 4 == 2: a[i] -= 2 cnt += 1 print(("Yes" if sum(a[i] % 4 for i in a) == 0 else "No"))
from collections import Counter h, w = list(map(int, input().split())) a = Counter("".join(eval(input()) for _ in range(h))) center = h * w % 2 side = (h // 2) * (w % 2) + (w // 2) * (h % 2) cnt = 0 for i in a: if a[i] % 2 == 1: a[i] -= 1 cnt += 1 if cnt != center: print("No") exit() cnt = 0 for i in a: if cnt == side: break if a[i] % 4 == 2: a[i] -= 2 cnt += 1 print(("Yes" if sum(a[i] % 4 for i in a) == 0 else "No"))
false
4
[ "- if cnt == center:", "- break", "+if cnt != center:", "+ print(\"No\")", "+ exit()" ]
false
0.039786
0.038475
1.034086
[ "s593768130", "s904688474" ]
u309120194
p02818
python
s637787549
s943493410
37
23
9,096
9,044
Accepted
Accepted
37.84
A, B, K = list(map(int, input().split())) if K <= A: A -= K elif A+B >= K > A: B -= K-A A = 0 else: A, B = 0, 0 print((A, B))
A, B, K = list(map(int, input().split())) ans_A, ans_B = A, B if K <= A: ans_A -= K elif A+B >= K > A: ans_B -= K-A ans_A = 0 else: ans_A, ans_B = 0, 0 print((ans_A, ans_B))
11
12
140
189
A, B, K = list(map(int, input().split())) if K <= A: A -= K elif A + B >= K > A: B -= K - A A = 0 else: A, B = 0, 0 print((A, B))
A, B, K = list(map(int, input().split())) ans_A, ans_B = A, B if K <= A: ans_A -= K elif A + B >= K > A: ans_B -= K - A ans_A = 0 else: ans_A, ans_B = 0, 0 print((ans_A, ans_B))
false
8.333333
[ "+ans_A, ans_B = A, B", "- A -= K", "+ ans_A -= K", "- B -= K - A", "- A = 0", "+ ans_B -= K - A", "+ ans_A = 0", "- A, B = 0, 0", "-print((A, B))", "+ ans_A, ans_B = 0, 0", "+print((ans_A, ans_B))" ]
false
0.035511
0.035662
0.995775
[ "s637787549", "s943493410" ]
u655975843
p03013
python
s683853615
s428314923
181
157
7,264
7,276
Accepted
Accepted
13.26
import sys import collections ns = lambda: sys.stdin.readline().rstrip() ni = lambda: int(ns()) nm = lambda: list(map(int, sys.stdin.readline().split())) nl = lambda: list(nm()) nsm = lambda: list(map(str, sys.stdin.readline().split())) nsl = lambda: list(nsm()) mod = 1000000007 n, m = nm() dp = [0] * (n + 1) for i in range(m): tmp = ni() dp[tmp] = -1 dp[0] = 1 for i in range(n): if i + 1 < n + 1: if dp[i + 1] != -1 and dp[i] != -1: dp[i + 1] += dp[i] % mod dp[i + 1] %= mod if i + 2 < n + 1: if dp[i + 2] != -1 and dp[i] != -1: dp[i + 2] += dp[i] % mod dp[i + 2] %= mod print((dp[n] % mod))
import sys import collections ns = lambda: sys.stdin.readline().rstrip() ni = lambda: int(ns()) nm = lambda: list(map(int, sys.stdin.readline().split())) nl = lambda: list(nm()) nsm = lambda: list(map(str, sys.stdin.readline().split())) nsl = lambda: list(nsm()) mod = 1000000007 n, m = nm() dp = [0] * (n + 2) for i in range(m): tmp = ni() dp[tmp] = -1 dp[0] = 1 for i in range(n): if i + 1 <= n: if dp[i + 1] != -1 and dp[i] != -1: dp[i + 1] += dp[i] % mod dp[i + 1] %= mod if i + 2 <= n: if dp[i + 2] != -1 and dp[i] != -1: dp[i + 2] += dp[i] % mod dp[i + 2] %= mod print((dp[n] % mod))
27
27
690
684
import sys import collections ns = lambda: sys.stdin.readline().rstrip() ni = lambda: int(ns()) nm = lambda: list(map(int, sys.stdin.readline().split())) nl = lambda: list(nm()) nsm = lambda: list(map(str, sys.stdin.readline().split())) nsl = lambda: list(nsm()) mod = 1000000007 n, m = nm() dp = [0] * (n + 1) for i in range(m): tmp = ni() dp[tmp] = -1 dp[0] = 1 for i in range(n): if i + 1 < n + 1: if dp[i + 1] != -1 and dp[i] != -1: dp[i + 1] += dp[i] % mod dp[i + 1] %= mod if i + 2 < n + 1: if dp[i + 2] != -1 and dp[i] != -1: dp[i + 2] += dp[i] % mod dp[i + 2] %= mod print((dp[n] % mod))
import sys import collections ns = lambda: sys.stdin.readline().rstrip() ni = lambda: int(ns()) nm = lambda: list(map(int, sys.stdin.readline().split())) nl = lambda: list(nm()) nsm = lambda: list(map(str, sys.stdin.readline().split())) nsl = lambda: list(nsm()) mod = 1000000007 n, m = nm() dp = [0] * (n + 2) for i in range(m): tmp = ni() dp[tmp] = -1 dp[0] = 1 for i in range(n): if i + 1 <= n: if dp[i + 1] != -1 and dp[i] != -1: dp[i + 1] += dp[i] % mod dp[i + 1] %= mod if i + 2 <= n: if dp[i + 2] != -1 and dp[i] != -1: dp[i + 2] += dp[i] % mod dp[i + 2] %= mod print((dp[n] % mod))
false
0
[ "-dp = [0] * (n + 1)", "+dp = [0] * (n + 2)", "- if i + 1 < n + 1:", "+ if i + 1 <= n:", "- if i + 2 < n + 1:", "+ if i + 2 <= n:" ]
false
0.111118
0.064999
1.70954
[ "s683853615", "s428314923" ]
u298976461
p02639
python
s437392916
s888063712
33
26
9,024
9,132
Accepted
Accepted
21.21
x = list(map(int, input().split())) for i in range(len(x)): if x[i] is 0: print((i+1))
x = list(map(int, input().split())) for i in range(len(x)): if x[i] == 0: print((i+1))
5
5
97
97
x = list(map(int, input().split())) for i in range(len(x)): if x[i] is 0: print((i + 1))
x = list(map(int, input().split())) for i in range(len(x)): if x[i] == 0: print((i + 1))
false
0
[ "- if x[i] is 0:", "+ if x[i] == 0:" ]
false
0.050334
0.084992
0.592224
[ "s437392916", "s888063712" ]
u315078622
p02889
python
s514520133
s502394176
1,729
942
18,140
23,340
Accepted
Accepted
45.52
from scipy.sparse.csgraph import floyd_warshall N, M, L = list(map(int, input().split())) graph = [[0] * N for _ in range(N)] for _ in range(M): s, t, w = list(map(int, input().split())) graph[s-1][t-1] = graph[t-1][s-1] = w dist = floyd_warshall(graph, directed=False) graph = [[0] * N for _ in range(N)] for i in range(N): for j in range(i+1, N): if dist[i][j] <= L: graph[i][j] = graph[i][j] = 1 dist = floyd_warshall(graph, directed=False) Q = int(eval(input())) for _ in range(Q): s, t = list(map(int, input().split())) ans = dist[s-1][t-1] if ans == float("inf"): print((-1)) else: print((int(ans - 1)))
def io_tmp(): global input import io, sys f = io.StringIO(open(0).read()) input = f.readline io_tmp() from scipy.sparse.csgraph import floyd_warshall N, M, L = list(map(int, input().split())) graph = [[0] * N for _ in range(N)] for _ in range(M): s, t, w = list(map(int, input().split())) graph[s-1][t-1] = graph[t-1][s-1] = w dist = floyd_warshall(graph, directed=False) graph = [[0] * N for _ in range(N)] for i in range(N): for j in range(i+1, N): if dist[i][j] <= L: graph[i][j] = graph[i][j] = 1 dist = floyd_warshall(graph, directed=False) Q = int(eval(input())) for _ in range(Q): s, t = list(map(int, input().split())) ans = dist[s-1][t-1] if ans == float("inf"): print((-1)) else: print((int(ans - 1)))
24
33
672
802
from scipy.sparse.csgraph import floyd_warshall N, M, L = list(map(int, input().split())) graph = [[0] * N for _ in range(N)] for _ in range(M): s, t, w = list(map(int, input().split())) graph[s - 1][t - 1] = graph[t - 1][s - 1] = w dist = floyd_warshall(graph, directed=False) graph = [[0] * N for _ in range(N)] for i in range(N): for j in range(i + 1, N): if dist[i][j] <= L: graph[i][j] = graph[i][j] = 1 dist = floyd_warshall(graph, directed=False) Q = int(eval(input())) for _ in range(Q): s, t = list(map(int, input().split())) ans = dist[s - 1][t - 1] if ans == float("inf"): print((-1)) else: print((int(ans - 1)))
def io_tmp(): global input import io, sys f = io.StringIO(open(0).read()) input = f.readline io_tmp() from scipy.sparse.csgraph import floyd_warshall N, M, L = list(map(int, input().split())) graph = [[0] * N for _ in range(N)] for _ in range(M): s, t, w = list(map(int, input().split())) graph[s - 1][t - 1] = graph[t - 1][s - 1] = w dist = floyd_warshall(graph, directed=False) graph = [[0] * N for _ in range(N)] for i in range(N): for j in range(i + 1, N): if dist[i][j] <= L: graph[i][j] = graph[i][j] = 1 dist = floyd_warshall(graph, directed=False) Q = int(eval(input())) for _ in range(Q): s, t = list(map(int, input().split())) ans = dist[s - 1][t - 1] if ans == float("inf"): print((-1)) else: print((int(ans - 1)))
false
27.272727
[ "+def io_tmp():", "+ global input", "+ import io, sys", "+", "+ f = io.StringIO(open(0).read())", "+ input = f.readline", "+", "+", "+io_tmp()" ]
false
0.290781
0.312906
0.929292
[ "s514520133", "s502394176" ]
u057109575
p02603
python
s855321125
s016742402
100
65
61,888
61,904
Accepted
Accepted
35
N = int(eval(input())) X = list(map(int, input().split())) state = 1 # 1=buy, 0=sell cur = (1000, 0) # yen, stock for i in range(N - 1): if state == 1 and X[i + 1] > X[i]: n = cur[0] // X[i] cur = (cur[0] - n * X[i], cur[1] + n) state = 0 elif state == 0 and X[i + 1] < X[i]: cur = (cur[0] + cur[1] * X[i], 0) state = 1 # Last print((cur[0] + cur[1] * X[-1]))
N = int(eval(input())) X = list(map(int, input().split())) cur = 1000 for i in range(N - 1): if X[i] < X[i + 1]: stocks = cur // X[i] else: stocks = 0 cur += (X[i + 1] - X[i]) * stocks # Last print(cur)
17
15
421
243
N = int(eval(input())) X = list(map(int, input().split())) state = 1 # 1=buy, 0=sell cur = (1000, 0) # yen, stock for i in range(N - 1): if state == 1 and X[i + 1] > X[i]: n = cur[0] // X[i] cur = (cur[0] - n * X[i], cur[1] + n) state = 0 elif state == 0 and X[i + 1] < X[i]: cur = (cur[0] + cur[1] * X[i], 0) state = 1 # Last print((cur[0] + cur[1] * X[-1]))
N = int(eval(input())) X = list(map(int, input().split())) cur = 1000 for i in range(N - 1): if X[i] < X[i + 1]: stocks = cur // X[i] else: stocks = 0 cur += (X[i + 1] - X[i]) * stocks # Last print(cur)
false
11.764706
[ "-state = 1 # 1=buy, 0=sell", "-cur = (1000, 0) # yen, stock", "+cur = 1000", "- if state == 1 and X[i + 1] > X[i]:", "- n = cur[0] // X[i]", "- cur = (cur[0] - n * X[i], cur[1] + n)", "- state = 0", "- elif state == 0 and X[i + 1] < X[i]:", "- cur = (cur[0] + cur[1] * X[i], 0)", "- state = 1", "+ if X[i] < X[i + 1]:", "+ stocks = cur // X[i]", "+ else:", "+ stocks = 0", "+ cur += (X[i + 1] - X[i]) * stocks", "-print((cur[0] + cur[1] * X[-1]))", "+print(cur)" ]
false
0.038197
0.082742
0.461637
[ "s855321125", "s016742402" ]
u143212659
p03610
python
s729379697
s373692057
65
18
5,284
3,188
Accepted
Accepted
72.31
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import math def main(): S = list(input()) for s in range(0, len(S), 2): print(S[s], end='') if __name__ == "__main__": main()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import math def main(): S = eval(input()) print((S[::2])) if __name__ == "__main__": main()
13
12
209
158
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import math def main(): S = list(input()) for s in range(0, len(S), 2): print(S[s], end="") if __name__ == "__main__": main()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import math def main(): S = eval(input()) print((S[::2])) if __name__ == "__main__": main()
false
7.692308
[ "- S = list(input())", "- for s in range(0, len(S), 2):", "- print(S[s], end=\"\")", "+ S = eval(input())", "+ print((S[::2]))" ]
false
0.040571
0.038874
1.043657
[ "s729379697", "s373692057" ]
u200887663
p02989
python
s662302076
s178129755
82
75
14,396
14,428
Accepted
Accepted
8.54
n=int(eval(input())) li = list(map(int,input().split())) li.sort() ind=int(n//2)-1 count=0 for k in range(li[ind]+1,li[ind+1]+1): count+=1 print(count)
n=int(eval(input())) #a,b=map(int,input().split()) dl=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] ans=1 dl.sort() if n%2==0: mid=n//2 ans=dl[mid]-dl[mid-1] print(ans)
13
10
166
223
n = int(eval(input())) li = list(map(int, input().split())) li.sort() ind = int(n // 2) - 1 count = 0 for k in range(li[ind] + 1, li[ind + 1] + 1): count += 1 print(count)
n = int(eval(input())) # a,b=map(int,input().split()) dl = list(map(int, input().split())) # l=[list(map(int,input().split())) for i in range(n)] ans = 1 dl.sort() if n % 2 == 0: mid = n // 2 ans = dl[mid] - dl[mid - 1] print(ans)
false
23.076923
[ "-li = list(map(int, input().split()))", "-li.sort()", "-ind = int(n // 2) - 1", "-count = 0", "-for k in range(li[ind] + 1, li[ind + 1] + 1):", "- count += 1", "-print(count)", "+# a,b=map(int,input().split())", "+dl = list(map(int, input().split()))", "+# l=[list(map(int,input().split())) for i in range(n)]", "+ans = 1", "+dl.sort()", "+if n % 2 == 0:", "+ mid = n // 2", "+ ans = dl[mid] - dl[mid - 1]", "+print(ans)" ]
false
0.036199
0.034579
1.046831
[ "s662302076", "s178129755" ]
u499381410
p02762
python
s689871241
s811132874
729
627
91,228
113,028
Accepted
Accepted
13.99
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce import pprint sys.setrecursionlimit(10 ** 9) INF = 10 ** 20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 class UnionFind: def __init__(self, n): # 負 : 根であることを示す。絶対値はランクを示す # 非負: 根でないことを示す。値は親を示す self.table = [-1] * n self.size = [1] * n self.group_num = n def root(self, x): if self.table[x] < 0: return x else: self.table[x] = self.root(self.table[x]) return self.table[x] def get_size(self, x): r = self.root(x) return self.size[r] def is_same(self, x, y): return self.root(x) == self.root(y) def union(self, x, y): r1 = self.root(x) r2 = self.root(y) if r1 == r2: return # ランクの取得 d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 self.size[r1] += self.size[r2] if d1 == d2: self.table[r1] -= 1 else: self.table[r1] = r2 self.size[r2] += self.size[r1] self.group_num -= 1 n, m, k = LI() U = UnionFind(n) AB = LIR(m) for a, b in AB: U.union(a - 1, b - 1) ans = [U.get_size(U.root(i)) - 1 for i in range(n)] for a, b in AB: ans[a - 1] -= 1 ans[b - 1] -= 1 for _ in range(k): c, d = LI() if U.is_same(c - 1, d - 1): ans[c - 1] -= 1 ans[d - 1] -= 1 print((*ans))
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce from operator import mul sys.setrecursionlimit(2147483647) INF = 10 ** 20 def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 class UnionFind: def __init__(self, n): # 負 : 根であることを示す。絶対値はランクを示す # 非負: 根でないことを示す。値は親を示す self.table = [-1] * n self.size = [1] * n # self.group_num = n def root(self, x): if self.table[x] < 0: return x else: self.table[x] = self.root(self.table[x]) return self.table[x] def get_size(self, x): r = self.root(x) return self.size[r] def is_same(self, x, y): return self.root(x) == self.root(y) def union(self, x, y): r1 = self.root(x) r2 = self.root(y) if r1 == r2: return # ランクの取得 d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 self.size[r1] += self.size[r2] if d1 == d2: self.table[r1] -= 1 else: self.table[r1] = r2 self.size[r2] += self.size[r1] # self.group_num -= 1 n, m, k = LI() U = UnionFind(n) G1 = [[] for _ in range(n)] for _ in range(m): a, b = LI() G1[a - 1] += [b - 1] G1[b - 1] += [a - 1] U.union(a - 1, b - 1) G2 = [[] for _ in range(n)] for _ in range(k): c, d = LI() G2[c - 1] += [d - 1] G2[d - 1] += [c - 1] for i in range(n): ret = U.get_size(i) - 1 - len(G1[i]) for j in G2[i]: if U.is_same(i, j): ret -= 1 print(ret, end=" ")
89
91
2,413
2,532
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce import pprint sys.setrecursionlimit(10**9) INF = 10**20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode("utf-8").split() def S(): return sys.stdin.buffer.readline().rstrip().decode("utf-8") def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 class UnionFind: def __init__(self, n): # 負 : 根であることを示す。絶対値はランクを示す # 非負: 根でないことを示す。値は親を示す self.table = [-1] * n self.size = [1] * n self.group_num = n def root(self, x): if self.table[x] < 0: return x else: self.table[x] = self.root(self.table[x]) return self.table[x] def get_size(self, x): r = self.root(x) return self.size[r] def is_same(self, x, y): return self.root(x) == self.root(y) def union(self, x, y): r1 = self.root(x) r2 = self.root(y) if r1 == r2: return # ランクの取得 d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 self.size[r1] += self.size[r2] if d1 == d2: self.table[r1] -= 1 else: self.table[r1] = r2 self.size[r2] += self.size[r1] self.group_num -= 1 n, m, k = LI() U = UnionFind(n) AB = LIR(m) for a, b in AB: U.union(a - 1, b - 1) ans = [U.get_size(U.root(i)) - 1 for i in range(n)] for a, b in AB: ans[a - 1] -= 1 ans[b - 1] -= 1 for _ in range(k): c, d = LI() if U.is_same(c - 1, d - 1): ans[c - 1] -= 1 ans[d - 1] -= 1 print((*ans))
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce from operator import mul sys.setrecursionlimit(2147483647) INF = 10**20 def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode("utf-8").split() def S(): return sys.stdin.buffer.readline().rstrip().decode("utf-8") def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 class UnionFind: def __init__(self, n): # 負 : 根であることを示す。絶対値はランクを示す # 非負: 根でないことを示す。値は親を示す self.table = [-1] * n self.size = [1] * n # self.group_num = n def root(self, x): if self.table[x] < 0: return x else: self.table[x] = self.root(self.table[x]) return self.table[x] def get_size(self, x): r = self.root(x) return self.size[r] def is_same(self, x, y): return self.root(x) == self.root(y) def union(self, x, y): r1 = self.root(x) r2 = self.root(y) if r1 == r2: return # ランクの取得 d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 self.size[r1] += self.size[r2] if d1 == d2: self.table[r1] -= 1 else: self.table[r1] = r2 self.size[r2] += self.size[r1] # self.group_num -= 1 n, m, k = LI() U = UnionFind(n) G1 = [[] for _ in range(n)] for _ in range(m): a, b = LI() G1[a - 1] += [b - 1] G1[b - 1] += [a - 1] U.union(a - 1, b - 1) G2 = [[] for _ in range(n)] for _ in range(k): c, d = LI() G2[c - 1] += [d - 1] G2[d - 1] += [c - 1] for i in range(n): ret = U.get_size(i) - 1 - len(G1[i]) for j in G2[i]: if U.is_same(i, j): ret -= 1 print(ret, end=" ")
false
2.197802
[ "-import pprint", "+from operator import mul", "-sys.setrecursionlimit(10**9)", "+sys.setrecursionlimit(2147483647)", "- return list(map(int, sys.stdin.buffer.readline().split()))", "+ return list(map(int, sys.stdin.readline().split()))", "- return int(sys.stdin.buffer.readline())", "+ return int(sys.stdin.readline())", "- self.group_num = n", "+ # self.group_num = n", "- self.group_num -= 1", "+ # self.group_num -= 1", "-AB = LIR(m)", "-for a, b in AB:", "+G1 = [[] for _ in range(n)]", "+for _ in range(m):", "+ a, b = LI()", "+ G1[a - 1] += [b - 1]", "+ G1[b - 1] += [a - 1]", "-ans = [U.get_size(U.root(i)) - 1 for i in range(n)]", "-for a, b in AB:", "- ans[a - 1] -= 1", "- ans[b - 1] -= 1", "+G2 = [[] for _ in range(n)]", "- if U.is_same(c - 1, d - 1):", "- ans[c - 1] -= 1", "- ans[d - 1] -= 1", "-print((*ans))", "+ G2[c - 1] += [d - 1]", "+ G2[d - 1] += [c - 1]", "+for i in range(n):", "+ ret = U.get_size(i) - 1 - len(G1[i])", "+ for j in G2[i]:", "+ if U.is_same(i, j):", "+ ret -= 1", "+ print(ret, end=\" \")" ]
false
0.046647
0.084636
0.551146
[ "s689871241", "s811132874" ]