user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u592248346
p03777
python
s310157151
s460244523
33
30
9,044
9,032
Accepted
Accepted
9.09
a,b = input().split() if a=="H": if b=="H": print("H") else: print("D") else: if b=="H": print("D") else: print("H")
a,b = input().split() if a==b: print("H") else: print("D")
7
3
139
60
a, b = input().split() if a == "H": if b == "H": print("H") else: print("D") else: if b == "H": print("D") else: print("H")
a, b = input().split() if a == b: print("H") else: print("D")
false
57.142857
[ "-if a == \"H\":", "- if b == \"H\":", "- print(\"H\")", "- else:", "- print(\"D\")", "+if a == b:", "+ print(\"H\")", "- if b == \"H\":", "- print(\"D\")", "- else:", "- print(\"H\")", "+ print(\"D\")" ]
false
0.035441
0.054693
0.647995
[ "s310157151", "s460244523" ]
u706786134
p02786
python
s161833963
s028378791
24
17
3,316
2,940
Accepted
Accepted
29.17
h = int(eval(input())) i = 0 ans = 1 while h: h = h // 2 i += 1 for _ in range(1, i): ans = 2 * ans + 1 print(ans)
import math h = int(eval(input())) print((2**(math.floor(math.log2(h))+1)-1))
10
3
131
72
h = int(eval(input())) i = 0 ans = 1 while h: h = h // 2 i += 1 for _ in range(1, i): ans = 2 * ans + 1 print(ans)
import math h = int(eval(input())) print((2 ** (math.floor(math.log2(h)) + 1) - 1))
false
70
[ "+import math", "+", "-i = 0", "-ans = 1", "-while h:", "- h = h // 2", "- i += 1", "-for _ in range(1, i):", "- ans = 2 * ans + 1", "-print(ans)", "+print((2 ** (math.floor(math.log2(h)) + 1) - 1))" ]
false
0.071359
0.038929
1.833024
[ "s161833963", "s028378791" ]
u078932560
p02803
python
s828388154
s118172028
446
273
3,192
3,316
Accepted
Accepted
38.79
# from collections import deque H, W = list(map(int, input().split())) # dp = [[1000 for _ in range(W)] for _ in range(H)] S = [['#']*(W+2)] + [['#']+list(eval(input()))+['#'] for h in range(H)] + [['#']*(W+2)] # S = (H+2, W+2) # S = [input().split() for h in range(H)] max_n = 0 for h1 in range(1,H+1): for w1 in range(1,W+1): if S[h1][w1] == '#': continue distance = [[1000 for _ in range(W+2)] for _ in range(H+2)] done_que = [[0 for _ in range(W+2)] for _ in range(H+2)] distance[h1][w1] = 0 que = [] que.append([h1,w1]) que_i = 0 while que_i < len(que): h, w = que[que_i] if S[h-1][w] == '.' and done_que[h-1][w] == 0: done_que[h-1][w] = 1 que.append([h-1,w]) distance[h-1][w] = min(distance[h][w] + 1, distance[h-1][w]) if S[h+1][w] == '.' and done_que[h+1][w] == 0: done_que[h+1][w] = 1 que.append([h+1,w]) distance[h+1][w] = min(distance[h][w] + 1, distance[h+1][w]) if S[h][w-1] == '.' and done_que[h][w-1] == 0: done_que[h][w-1] = 1 que.append([h,w-1]) distance[h][w-1] = min(distance[h][w] + 1, distance[h][w-1]) if S[h][w+1] == '.' and done_que[h][w+1] == 0: done_que[h][w+1] = 1 que.append([h,w+1]) distance[h][w+1] = min(distance[h][w] + 1, distance[h][w+1]) que_i += 1 hw_max_n = 0 for h2 in range(1,H+1): for w2 in range(1,W+1): if distance[h2][w2] != 1000: hw_max_n = max(hw_max_n, distance[h2][w2]) max_n = max(max_n, hw_max_n) print(max_n)
from collections import deque H, W = list(map(int, input().split())) S = [['#']*(W+2)] + [['#']+list(eval(input()))+['#'] for h in range(H)] + [['#']*(W+2)] max_n = 0 for h1 in range(1,H+1): for w1 in range(1,W+1): if S[h1][w1] == '#': continue distance = [[-1 for _ in range(W+2)] for _ in range(H+2)] distance[h1][w1] = 0 que = deque([]) que.append([h1,w1]) while que: h, w = que.popleft() if S[h-1][w] == '.' and distance[h-1][w] == -1: que.append([h-1,w]) distance[h-1][w] = distance[h][w] + 1 if S[h+1][w] == '.' and distance[h+1][w] == -1: que.append([h+1,w]) distance[h+1][w] = distance[h][w] + 1 if S[h][w-1] == '.' and distance[h][w-1] == -1: que.append([h,w-1]) distance[h][w-1] = distance[h][w] + 1 if S[h][w+1] == '.' and distance[h][w+1] == -1: que.append([h,w+1]) distance[h][w+1] = distance[h][w] + 1 hw_max_n = max([max(dis) for dis in distance]) max_n = max(max_n, hw_max_n) print(max_n)
45
31
1,607
1,064
# from collections import deque H, W = list(map(int, input().split())) # dp = [[1000 for _ in range(W)] for _ in range(H)] S = ( [["#"] * (W + 2)] + [["#"] + list(eval(input())) + ["#"] for h in range(H)] + [["#"] * (W + 2)] ) # S = (H+2, W+2) # S = [input().split() for h in range(H)] max_n = 0 for h1 in range(1, H + 1): for w1 in range(1, W + 1): if S[h1][w1] == "#": continue distance = [[1000 for _ in range(W + 2)] for _ in range(H + 2)] done_que = [[0 for _ in range(W + 2)] for _ in range(H + 2)] distance[h1][w1] = 0 que = [] que.append([h1, w1]) que_i = 0 while que_i < len(que): h, w = que[que_i] if S[h - 1][w] == "." and done_que[h - 1][w] == 0: done_que[h - 1][w] = 1 que.append([h - 1, w]) distance[h - 1][w] = min(distance[h][w] + 1, distance[h - 1][w]) if S[h + 1][w] == "." and done_que[h + 1][w] == 0: done_que[h + 1][w] = 1 que.append([h + 1, w]) distance[h + 1][w] = min(distance[h][w] + 1, distance[h + 1][w]) if S[h][w - 1] == "." and done_que[h][w - 1] == 0: done_que[h][w - 1] = 1 que.append([h, w - 1]) distance[h][w - 1] = min(distance[h][w] + 1, distance[h][w - 1]) if S[h][w + 1] == "." and done_que[h][w + 1] == 0: done_que[h][w + 1] = 1 que.append([h, w + 1]) distance[h][w + 1] = min(distance[h][w] + 1, distance[h][w + 1]) que_i += 1 hw_max_n = 0 for h2 in range(1, H + 1): for w2 in range(1, W + 1): if distance[h2][w2] != 1000: hw_max_n = max(hw_max_n, distance[h2][w2]) max_n = max(max_n, hw_max_n) print(max_n)
from collections import deque H, W = list(map(int, input().split())) S = ( [["#"] * (W + 2)] + [["#"] + list(eval(input())) + ["#"] for h in range(H)] + [["#"] * (W + 2)] ) max_n = 0 for h1 in range(1, H + 1): for w1 in range(1, W + 1): if S[h1][w1] == "#": continue distance = [[-1 for _ in range(W + 2)] for _ in range(H + 2)] distance[h1][w1] = 0 que = deque([]) que.append([h1, w1]) while que: h, w = que.popleft() if S[h - 1][w] == "." and distance[h - 1][w] == -1: que.append([h - 1, w]) distance[h - 1][w] = distance[h][w] + 1 if S[h + 1][w] == "." and distance[h + 1][w] == -1: que.append([h + 1, w]) distance[h + 1][w] = distance[h][w] + 1 if S[h][w - 1] == "." and distance[h][w - 1] == -1: que.append([h, w - 1]) distance[h][w - 1] = distance[h][w] + 1 if S[h][w + 1] == "." and distance[h][w + 1] == -1: que.append([h, w + 1]) distance[h][w + 1] = distance[h][w] + 1 hw_max_n = max([max(dis) for dis in distance]) max_n = max(max_n, hw_max_n) print(max_n)
false
31.111111
[ "-# from collections import deque", "+from collections import deque", "+", "-# dp = [[1000 for _ in range(W)] for _ in range(H)]", "-# S = (H+2, W+2)", "-# S = [input().split() for h in range(H)]", "- distance = [[1000 for _ in range(W + 2)] for _ in range(H + 2)]", "- done_que = [[0 for _ in range(W + 2)] for _ in range(H + 2)]", "+ distance = [[-1 for _ in range(W + 2)] for _ in range(H + 2)]", "- que = []", "+ que = deque([])", "- que_i = 0", "- while que_i < len(que):", "- h, w = que[que_i]", "- if S[h - 1][w] == \".\" and done_que[h - 1][w] == 0:", "- done_que[h - 1][w] = 1", "+ while que:", "+ h, w = que.popleft()", "+ if S[h - 1][w] == \".\" and distance[h - 1][w] == -1:", "- distance[h - 1][w] = min(distance[h][w] + 1, distance[h - 1][w])", "- if S[h + 1][w] == \".\" and done_que[h + 1][w] == 0:", "- done_que[h + 1][w] = 1", "+ distance[h - 1][w] = distance[h][w] + 1", "+ if S[h + 1][w] == \".\" and distance[h + 1][w] == -1:", "- distance[h + 1][w] = min(distance[h][w] + 1, distance[h + 1][w])", "- if S[h][w - 1] == \".\" and done_que[h][w - 1] == 0:", "- done_que[h][w - 1] = 1", "+ distance[h + 1][w] = distance[h][w] + 1", "+ if S[h][w - 1] == \".\" and distance[h][w - 1] == -1:", "- distance[h][w - 1] = min(distance[h][w] + 1, distance[h][w - 1])", "- if S[h][w + 1] == \".\" and done_que[h][w + 1] == 0:", "- done_que[h][w + 1] = 1", "+ distance[h][w - 1] = distance[h][w] + 1", "+ if S[h][w + 1] == \".\" and distance[h][w + 1] == -1:", "- distance[h][w + 1] = min(distance[h][w] + 1, distance[h][w + 1])", "- que_i += 1", "- hw_max_n = 0", "- for h2 in range(1, H + 1):", "- for w2 in range(1, W + 1):", "- if distance[h2][w2] != 1000:", "- hw_max_n = max(hw_max_n, distance[h2][w2])", "+ distance[h][w + 1] = distance[h][w] + 1", "+ hw_max_n = max([max(dis) for dis in distance])" ]
false
0.116168
0.089138
1.303229
[ "s828388154", "s118172028" ]
u020604402
p03456
python
s094946570
s330293846
19
17
3,188
3,060
Accepted
Accepted
10.53
x1 , x2 = input().split() s = int(x1 + x2) root_s = s ** (1 / 2) if int(root_s) ** 2 == s: print("Yes") else: print("No")
x1 , x2 = input().split() s = int(x1 + x2) table = [] for i in range(1,1000): table.append(i * i) for x in table: if x == s: print("Yes") quit() print("No")
9
11
140
192
x1, x2 = input().split() s = int(x1 + x2) root_s = s ** (1 / 2) if int(root_s) ** 2 == s: print("Yes") else: print("No")
x1, x2 = input().split() s = int(x1 + x2) table = [] for i in range(1, 1000): table.append(i * i) for x in table: if x == s: print("Yes") quit() print("No")
false
18.181818
[ "-root_s = s ** (1 / 2)", "-if int(root_s) ** 2 == s:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+table = []", "+for i in range(1, 1000):", "+ table.append(i * i)", "+for x in table:", "+ if x == s:", "+ print(\"Yes\")", "+ quit()", "+print(\"No\")" ]
false
0.046094
0.045503
1.012991
[ "s094946570", "s330293846" ]
u268793453
p03175
python
s306186740
s564197242
1,077
961
131,744
121,888
Accepted
Accepted
10.77
#n == 1でバグるけど2が返ってくるのでヨシ! from sys import setrecursionlimit setrecursionlimit(10 ** 9) n = int(eval(input())) X = [[int(i) for i in input().split()] for j in range(n-1)] p = 10 ** 9 + 7 V = [[] for i in range(n+1)] for x, y in X: V[x].append(y) V[y].append(x) root = 0 for i, v in enumerate(V): if len(v) == 1: root = i break w = 0 b = 1 DP = [[0] * 2 for i in range(n+1)] def dfs(i): if DP[i] != [0, 0]: return 0 DP[i][w] = 1 DP[i][b] = 1 for v in V[i]: if dfs(v) == 0: continue DP[i][w] *= DP[v][w] + DP[v][b] DP[i][b] *= DP[v][w] DP[i][w] %= p DP[i][b] %= p dfs(root) print((sum(DP[root]) % p))
#n == 1でバグるけど2が返ってくるのでヨシ! from sys import setrecursionlimit setrecursionlimit(10 ** 9) n = int(eval(input())) X = [[int(i) for i in input().split()] for j in range(n-1)] p = 10 ** 9 + 7 V = [[] for i in range(n+1)] for x, y in X: V[x].append(y) V[y].append(x) w = 0 b = 1 DP = [[0] * 2 for i in range(n+1)] def dfs(i): if DP[i] != [0, 0]: return 0 DP[i][w] = 1 DP[i][b] = 1 for v in V[i]: if dfs(v) == 0: continue DP[i][w] *= DP[v][w] + DP[v][b] DP[i][b] *= DP[v][w] DP[i][w] %= p DP[i][b] %= p dfs(1) print((sum(DP[1]) % p))
38
32
745
646
# n == 1でバグるけど2が返ってくるのでヨシ! from sys import setrecursionlimit setrecursionlimit(10**9) n = int(eval(input())) X = [[int(i) for i in input().split()] for j in range(n - 1)] p = 10**9 + 7 V = [[] for i in range(n + 1)] for x, y in X: V[x].append(y) V[y].append(x) root = 0 for i, v in enumerate(V): if len(v) == 1: root = i break w = 0 b = 1 DP = [[0] * 2 for i in range(n + 1)] def dfs(i): if DP[i] != [0, 0]: return 0 DP[i][w] = 1 DP[i][b] = 1 for v in V[i]: if dfs(v) == 0: continue DP[i][w] *= DP[v][w] + DP[v][b] DP[i][b] *= DP[v][w] DP[i][w] %= p DP[i][b] %= p dfs(root) print((sum(DP[root]) % p))
# n == 1でバグるけど2が返ってくるのでヨシ! from sys import setrecursionlimit setrecursionlimit(10**9) n = int(eval(input())) X = [[int(i) for i in input().split()] for j in range(n - 1)] p = 10**9 + 7 V = [[] for i in range(n + 1)] for x, y in X: V[x].append(y) V[y].append(x) w = 0 b = 1 DP = [[0] * 2 for i in range(n + 1)] def dfs(i): if DP[i] != [0, 0]: return 0 DP[i][w] = 1 DP[i][b] = 1 for v in V[i]: if dfs(v) == 0: continue DP[i][w] *= DP[v][w] + DP[v][b] DP[i][b] *= DP[v][w] DP[i][w] %= p DP[i][b] %= p dfs(1) print((sum(DP[1]) % p))
false
15.789474
[ "-root = 0", "-for i, v in enumerate(V):", "- if len(v) == 1:", "- root = i", "- break", "-dfs(root)", "-print((sum(DP[root]) % p))", "+dfs(1)", "+print((sum(DP[1]) % p))" ]
false
0.037522
0.036727
1.021645
[ "s306186740", "s564197242" ]
u995004106
p02996
python
s033181974
s418971760
1,242
924
88,024
53,728
Accepted
Accepted
25.6
N=int(eval(input())) task=[list(map(int,input().split())) for _ in range(N)] time=0 flag=1 task.sort(lambda x:x[1]) #print(task) for i in range(N): time=time+task[i][0] if not(time<=task[i][1]): flag=0 break if flag==1: print("Yes") else: print("No")
N=int(eval(input())) task=[list(map(int,input().split())) for _ in range(N)] time=0 flag=1 task.sort(key=lambda x:x[1]) #print(task) for i in range(N): time=time+task[i][0] if not(time<=task[i][1]): flag=0 break if flag==1: print("Yes") else: print("No")
15
15
291
294
N = int(eval(input())) task = [list(map(int, input().split())) for _ in range(N)] time = 0 flag = 1 task.sort(lambda x: x[1]) # print(task) for i in range(N): time = time + task[i][0] if not (time <= task[i][1]): flag = 0 break if flag == 1: print("Yes") else: print("No")
N = int(eval(input())) task = [list(map(int, input().split())) for _ in range(N)] time = 0 flag = 1 task.sort(key=lambda x: x[1]) # print(task) for i in range(N): time = time + task[i][0] if not (time <= task[i][1]): flag = 0 break if flag == 1: print("Yes") else: print("No")
false
0
[ "-task.sort(lambda x: x[1])", "+task.sort(key=lambda x: x[1])" ]
false
0.077272
0.041409
1.866069
[ "s033181974", "s418971760" ]
u216392490
p02572
python
s554416103
s774015499
142
125
31,596
31,680
Accepted
Accepted
11.97
n = int(eval(input())) mod = int(1e9+7) ans, t = 0, 0 for a in list(map(int, input().split())): ans = (ans+a*t) % mod t = (t + a) % mod print(ans)
n = int(eval(input())) mod = int(1e9+7) ans, t = 0, 0 for a in list(map(int, input().split())): ans = (ans+a*t) % mod t += a print(ans)
8
8
157
146
n = int(eval(input())) mod = int(1e9 + 7) ans, t = 0, 0 for a in list(map(int, input().split())): ans = (ans + a * t) % mod t = (t + a) % mod print(ans)
n = int(eval(input())) mod = int(1e9 + 7) ans, t = 0, 0 for a in list(map(int, input().split())): ans = (ans + a * t) % mod t += a print(ans)
false
0
[ "- t = (t + a) % mod", "+ t += a" ]
false
0.043958
0.058124
0.756281
[ "s554416103", "s774015499" ]
u970308980
p03244
python
s221450172
s987057619
147
118
22,484
24,300
Accepted
Accepted
19.73
from collections import defaultdict N = int(eval(input())) L = list(map(int, input().split())) if len(set(L)) == 1: print((N//2)) exit() if N == 2: print((0)) exit() d_even = defaultdict(int) d_odd = defaultdict(int) for i in range(N): v = L[i] if i % 2 == 0: d_even[v] += 1 else: d_odd[v] += 1 l_even = sorted(list(d_even.items()), key=lambda x: -x[1]) l_odd = sorted(list(d_odd.items()), key=lambda x: -x[1]) if l_even[0][0] != l_odd[0][0]: print((N - l_odd[0][1] - l_even[0][1])) exit() ans = N ans = min(ans, N - l_odd[0][1] - l_even[1][1]) ans = min(ans, N - l_odd[1][1] - l_even[0][1]) print(ans)
from collections import Counter N = int(eval(input())) L = list(map(int, input().split())) odd = [v for i, v in enumerate(L) if i % 2 == 0] even = [v for i, v in enumerate(L) if i % 2 == 1] if len(set(L)) == 1: print((N//2)) exit() if N == 2: print((0)) exit() c_odd = sorted(list(dict(Counter(odd)).items()), key=lambda x: -x[1]) c_even = sorted(list(dict(Counter(even)).items()), key=lambda x: -x[1]) odd_1 = c_odd[0] even_1 = c_even[0] if odd_1[0] != even_1[0]: print((N - odd_1[1] - even_1[1])) exit() even_2 = c_even[1] odd_2 = c_odd[1] ans = N ans = min(ans, N - odd_1[1] - even_2[1]) ans = min(ans, N - odd_2[1] - even_1[1]) print(ans)
34
32
672
682
from collections import defaultdict N = int(eval(input())) L = list(map(int, input().split())) if len(set(L)) == 1: print((N // 2)) exit() if N == 2: print((0)) exit() d_even = defaultdict(int) d_odd = defaultdict(int) for i in range(N): v = L[i] if i % 2 == 0: d_even[v] += 1 else: d_odd[v] += 1 l_even = sorted(list(d_even.items()), key=lambda x: -x[1]) l_odd = sorted(list(d_odd.items()), key=lambda x: -x[1]) if l_even[0][0] != l_odd[0][0]: print((N - l_odd[0][1] - l_even[0][1])) exit() ans = N ans = min(ans, N - l_odd[0][1] - l_even[1][1]) ans = min(ans, N - l_odd[1][1] - l_even[0][1]) print(ans)
from collections import Counter N = int(eval(input())) L = list(map(int, input().split())) odd = [v for i, v in enumerate(L) if i % 2 == 0] even = [v for i, v in enumerate(L) if i % 2 == 1] if len(set(L)) == 1: print((N // 2)) exit() if N == 2: print((0)) exit() c_odd = sorted(list(dict(Counter(odd)).items()), key=lambda x: -x[1]) c_even = sorted(list(dict(Counter(even)).items()), key=lambda x: -x[1]) odd_1 = c_odd[0] even_1 = c_even[0] if odd_1[0] != even_1[0]: print((N - odd_1[1] - even_1[1])) exit() even_2 = c_even[1] odd_2 = c_odd[1] ans = N ans = min(ans, N - odd_1[1] - even_2[1]) ans = min(ans, N - odd_2[1] - even_1[1]) print(ans)
false
5.882353
[ "-from collections import defaultdict", "+from collections import Counter", "+odd = [v for i, v in enumerate(L) if i % 2 == 0]", "+even = [v for i, v in enumerate(L) if i % 2 == 1]", "-d_even = defaultdict(int)", "-d_odd = defaultdict(int)", "-for i in range(N):", "- v = L[i]", "- if i % 2 == 0:", "- d_even[v] += 1", "- else:", "- d_odd[v] += 1", "-l_even = sorted(list(d_even.items()), key=lambda x: -x[1])", "-l_odd = sorted(list(d_odd.items()), key=lambda x: -x[1])", "-if l_even[0][0] != l_odd[0][0]:", "- print((N - l_odd[0][1] - l_even[0][1]))", "+c_odd = sorted(list(dict(Counter(odd)).items()), key=lambda x: -x[1])", "+c_even = sorted(list(dict(Counter(even)).items()), key=lambda x: -x[1])", "+odd_1 = c_odd[0]", "+even_1 = c_even[0]", "+if odd_1[0] != even_1[0]:", "+ print((N - odd_1[1] - even_1[1]))", "+even_2 = c_even[1]", "+odd_2 = c_odd[1]", "-ans = min(ans, N - l_odd[0][1] - l_even[1][1])", "-ans = min(ans, N - l_odd[1][1] - l_even[0][1])", "+ans = min(ans, N - odd_1[1] - even_2[1])", "+ans = min(ans, N - odd_2[1] - even_1[1])" ]
false
0.038084
0.036453
1.044738
[ "s221450172", "s987057619" ]
u095021077
p02727
python
s223835048
s554737632
272
233
23,216
23,328
Accepted
Accepted
14.34
X, Y, A, B, C=list(map(int, input().split())) p=list(map(int, input().split())) p.sort() q=list(map(int, input().split())) q.sort() r=list(map(int, input().split())) r.sort(reverse=True) i=-X j=-Y k=0 deru=0 while deru==0 and k<C and (r[k]>p[i] or r[k]>q[j]): if p[i]>q[j] and j<0: j+=1 k+=1 elif p[i]>q[j] and j>=0 and i<0 and p[i]<r[k]: i+=1 k+=1 elif p[i]<=q[j] and i<0: i+=1 k+=1 elif p[i]<=q[j] and i>=0 and j<0 and q[j]<r[k]: j+=1 k+=1 else: deru=1 if i==0: a=0 else: a=sum(p[i:]) if j==0: b=0 else: b=sum(q[j:]) if k==0: c=0 else: c=sum(r[:k]) print((a+b+c))
X, Y, A, B, C=list(map(int, input().split())) p=list(map(int, input().split())) q=list(map(int, input().split())) r=list(map(int, input().split())) p.sort() q.sort() nums=p[-X:]+q[-Y:]+r nums.sort() print((sum(nums[-(X+Y):])))
44
9
673
226
X, Y, A, B, C = list(map(int, input().split())) p = list(map(int, input().split())) p.sort() q = list(map(int, input().split())) q.sort() r = list(map(int, input().split())) r.sort(reverse=True) i = -X j = -Y k = 0 deru = 0 while deru == 0 and k < C and (r[k] > p[i] or r[k] > q[j]): if p[i] > q[j] and j < 0: j += 1 k += 1 elif p[i] > q[j] and j >= 0 and i < 0 and p[i] < r[k]: i += 1 k += 1 elif p[i] <= q[j] and i < 0: i += 1 k += 1 elif p[i] <= q[j] and i >= 0 and j < 0 and q[j] < r[k]: j += 1 k += 1 else: deru = 1 if i == 0: a = 0 else: a = sum(p[i:]) if j == 0: b = 0 else: b = sum(q[j:]) if k == 0: c = 0 else: c = sum(r[:k]) print((a + b + c))
X, Y, A, B, C = list(map(int, input().split())) p = list(map(int, input().split())) q = list(map(int, input().split())) r = list(map(int, input().split())) p.sort() q.sort() nums = p[-X:] + q[-Y:] + r nums.sort() print((sum(nums[-(X + Y) :])))
false
79.545455
[ "+q = list(map(int, input().split()))", "+r = list(map(int, input().split()))", "-q = list(map(int, input().split()))", "-r = list(map(int, input().split()))", "-r.sort(reverse=True)", "-i = -X", "-j = -Y", "-k = 0", "-deru = 0", "-while deru == 0 and k < C and (r[k] > p[i] or r[k] > q[j]):", "- if p[i] > q[j] and j < 0:", "- j += 1", "- k += 1", "- elif p[i] > q[j] and j >= 0 and i < 0 and p[i] < r[k]:", "- i += 1", "- k += 1", "- elif p[i] <= q[j] and i < 0:", "- i += 1", "- k += 1", "- elif p[i] <= q[j] and i >= 0 and j < 0 and q[j] < r[k]:", "- j += 1", "- k += 1", "- else:", "- deru = 1", "-if i == 0:", "- a = 0", "-else:", "- a = sum(p[i:])", "-if j == 0:", "- b = 0", "-else:", "- b = sum(q[j:])", "-if k == 0:", "- c = 0", "-else:", "- c = sum(r[:k])", "-print((a + b + c))", "+nums = p[-X:] + q[-Y:] + r", "+nums.sort()", "+print((sum(nums[-(X + Y) :])))" ]
false
0.076182
0.077131
0.987696
[ "s223835048", "s554737632" ]
u754022296
p02889
python
s512659935
s175471488
1,485
734
19,868
20,144
Accepted
Accepted
50.57
import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix n, m, l = list(map(int, input().split())) F = np.zeros((n, n)) for _ in range(m): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 F[a, b] = c F[b, a] = c csr = csr_matrix(F) A = floyd_warshall(csr) G = np.zeros((n, n)) for i in range(n-1): for j in range(i+1, n): if A[i][j] <= l: G[i, j] = 1 G[j, i] = 1 ncsr = csr_matrix(G) B = floyd_warshall(ncsr) q = int(eval(input())) for _ in range(q): s, t = list(map(int, input().split())) k = B[s-1][t-1] if k == float("inf"): print((-1)) else: print((int(k)-1))
import sys input = sys.stdin.readline import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix def main(): n, m, l = list(map(int, input().split())) F = np.zeros((n, n)) for _ in range(m): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 F[a, b] = c F[b, a] = c csr = csr_matrix(F) A = floyd_warshall(csr) G = np.zeros((n, n)) for i in range(n-1): for j in range(i+1, n): if A[i][j] <= l: G[i, j] = 1 G[j, i] = 1 ncsr = csr_matrix(G) B = floyd_warshall(ncsr) q = int(eval(input())) for _ in range(q): s, t = list(map(int, input().split())) k = B[s-1][t-1] if k == float("inf"): print((-1)) else: print((int(k)-1)) if __name__ == "__main__": main()
29
37
661
816
import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix n, m, l = list(map(int, input().split())) F = np.zeros((n, n)) for _ in range(m): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 F[a, b] = c F[b, a] = c csr = csr_matrix(F) A = floyd_warshall(csr) G = np.zeros((n, n)) for i in range(n - 1): for j in range(i + 1, n): if A[i][j] <= l: G[i, j] = 1 G[j, i] = 1 ncsr = csr_matrix(G) B = floyd_warshall(ncsr) q = int(eval(input())) for _ in range(q): s, t = list(map(int, input().split())) k = B[s - 1][t - 1] if k == float("inf"): print((-1)) else: print((int(k) - 1))
import sys input = sys.stdin.readline import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix def main(): n, m, l = list(map(int, input().split())) F = np.zeros((n, n)) for _ in range(m): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 F[a, b] = c F[b, a] = c csr = csr_matrix(F) A = floyd_warshall(csr) G = np.zeros((n, n)) for i in range(n - 1): for j in range(i + 1, n): if A[i][j] <= l: G[i, j] = 1 G[j, i] = 1 ncsr = csr_matrix(G) B = floyd_warshall(ncsr) q = int(eval(input())) for _ in range(q): s, t = list(map(int, input().split())) k = B[s - 1][t - 1] if k == float("inf"): print((-1)) else: print((int(k) - 1)) if __name__ == "__main__": main()
false
21.621622
[ "+import sys", "+", "+input = sys.stdin.readline", "-n, m, l = list(map(int, input().split()))", "-F = np.zeros((n, n))", "-for _ in range(m):", "- a, b, c = list(map(int, input().split()))", "- a -= 1", "- b -= 1", "- F[a, b] = c", "- F[b, a] = c", "-csr = csr_matrix(F)", "-A = floyd_warshall(csr)", "-G = np.zeros((n, n))", "-for i in range(n - 1):", "- for j in range(i + 1, n):", "- if A[i][j] <= l:", "- G[i, j] = 1", "- G[j, i] = 1", "-ncsr = csr_matrix(G)", "-B = floyd_warshall(ncsr)", "-q = int(eval(input()))", "-for _ in range(q):", "- s, t = list(map(int, input().split()))", "- k = B[s - 1][t - 1]", "- if k == float(\"inf\"):", "- print((-1))", "- else:", "- print((int(k) - 1))", "+", "+def main():", "+ n, m, l = list(map(int, input().split()))", "+ F = np.zeros((n, n))", "+ for _ in range(m):", "+ a, b, c = list(map(int, input().split()))", "+ a -= 1", "+ b -= 1", "+ F[a, b] = c", "+ F[b, a] = c", "+ csr = csr_matrix(F)", "+ A = floyd_warshall(csr)", "+ G = np.zeros((n, n))", "+ for i in range(n - 1):", "+ for j in range(i + 1, n):", "+ if A[i][j] <= l:", "+ G[i, j] = 1", "+ G[j, i] = 1", "+ ncsr = csr_matrix(G)", "+ B = floyd_warshall(ncsr)", "+ q = int(eval(input()))", "+ for _ in range(q):", "+ s, t = list(map(int, input().split()))", "+ k = B[s - 1][t - 1]", "+ if k == float(\"inf\"):", "+ print((-1))", "+ else:", "+ print((int(k) - 1))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.302909
0.389082
0.778523
[ "s512659935", "s175471488" ]
u970197315
p02850
python
s325943485
s281108229
487
332
18,548
23,152
Accepted
Accepted
31.83
# ABC146 D - Coloring Edges on Tree from collections import deque n = int(eval(input())) E = [[] for _ in range(n + 1)] edge_order = [] for i in range(n-1): a,b=list(map(int,input().split())) E[a].append(b) edge_order.append(b) # 頂点1からBFS q = deque([1]) color = [0] * (n+1) while q: V = q.popleft() c = 1 for nv in E[V]: if c == color[V]: c += 1 color[nv] = c c += 1 q.append(nv) print((max(color))) for i in edge_order: print((color[i]))
n=int(eval(input())) G=[[] for i in range(n+1)] G_order=[] for i in range(n-1): a,b=list(map(int,input().split())) G[a].append(b) G_order.append(b) from collections import deque q=deque([1]) color=[0]*(n+1) while q: cur=q.popleft() c=1 for nx in G[cur]: if c==color[cur]: c+=1 color[nx]=c c+=1 q.append(nx) print((max(color))) for i in G_order: print((color[i]))
29
24
529
408
# ABC146 D - Coloring Edges on Tree from collections import deque n = int(eval(input())) E = [[] for _ in range(n + 1)] edge_order = [] for i in range(n - 1): a, b = list(map(int, input().split())) E[a].append(b) edge_order.append(b) # 頂点1からBFS q = deque([1]) color = [0] * (n + 1) while q: V = q.popleft() c = 1 for nv in E[V]: if c == color[V]: c += 1 color[nv] = c c += 1 q.append(nv) print((max(color))) for i in edge_order: print((color[i]))
n = int(eval(input())) G = [[] for i in range(n + 1)] G_order = [] for i in range(n - 1): a, b = list(map(int, input().split())) G[a].append(b) G_order.append(b) from collections import deque q = deque([1]) color = [0] * (n + 1) while q: cur = q.popleft() c = 1 for nx in G[cur]: if c == color[cur]: c += 1 color[nx] = c c += 1 q.append(nx) print((max(color))) for i in G_order: print((color[i]))
false
17.241379
[ "-# ABC146 D - Coloring Edges on Tree", "+n = int(eval(input()))", "+G = [[] for i in range(n + 1)]", "+G_order = []", "+for i in range(n - 1):", "+ a, b = list(map(int, input().split()))", "+ G[a].append(b)", "+ G_order.append(b)", "-n = int(eval(input()))", "-E = [[] for _ in range(n + 1)]", "-edge_order = []", "-for i in range(n - 1):", "- a, b = list(map(int, input().split()))", "- E[a].append(b)", "- edge_order.append(b)", "-# 頂点1からBFS", "- V = q.popleft()", "+ cur = q.popleft()", "- for nv in E[V]:", "- if c == color[V]:", "+ for nx in G[cur]:", "+ if c == color[cur]:", "- color[nv] = c", "+ color[nx] = c", "- q.append(nv)", "+ q.append(nx)", "-for i in edge_order:", "+for i in G_order:" ]
false
0.035564
0.035051
1.014617
[ "s325943485", "s281108229" ]
u711539583
p02804
python
s183059958
s794102120
278
243
64,296
14,044
Accepted
Accepted
12.59
n, k = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10 ** 9 + 7 a.sort(reverse = True) N = n+2 P = mod inv_t = [0]+[1] for i in range(2,N): inv_t += [inv_t[P % i] * (P - int(P / i)) % P] base = 1 for item in range(n-k+1, n): base = (base * item) % mod for i in range(1, k): base = (base * inv_t[i]) % mod base2 = base ans = 0 ans2 = 0 top = n - 1 for ai in a: if top < k-1: break if ai > 0: ans += base * ai ans %= mod else: ans2 += abs(base * ai) ans2 %= mod base = base * inv_t[top] * (top - k + 1) % mod top -= 1 top = n-1 for ai in reversed(a): if top < k-1: break if ai > 0: ans2 += base2 * ai ans2 %= mod else: ans += abs(base2 * ai) ans %= mod base2 = base2 * inv_t[top] * (top - k + 1) % mod top -= 1 print(((ans - ans2) % mod))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10 ** 9 + 7 a.sort(reverse = True) N = n+2 P = mod inv_t = [0]+[1] for i in range(2,N): inv_t += [inv_t[P % i] * (P - int(P / i)) % P] base = 1 for item in range(n-k+1, n): base = (base * item) % mod for i in range(1, k): base = (base * inv_t[i]) % mod base2 = base ans = 0 top = n - 1 for ai in a: if top < k-1: break ans += base * ai ans %= mod base = base * inv_t[top] * (top - k + 1) % mod top -= 1 top = n-1 for ai in reversed(a): if top < k-1: break ans -= base2 * ai ans %= mod base2 = base2 * inv_t[top] * (top - k + 1) % mod top -= 1 print((ans % mod))
47
38
942
745
n, k = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10**9 + 7 a.sort(reverse=True) N = n + 2 P = mod inv_t = [0] + [1] for i in range(2, N): inv_t += [inv_t[P % i] * (P - int(P / i)) % P] base = 1 for item in range(n - k + 1, n): base = (base * item) % mod for i in range(1, k): base = (base * inv_t[i]) % mod base2 = base ans = 0 ans2 = 0 top = n - 1 for ai in a: if top < k - 1: break if ai > 0: ans += base * ai ans %= mod else: ans2 += abs(base * ai) ans2 %= mod base = base * inv_t[top] * (top - k + 1) % mod top -= 1 top = n - 1 for ai in reversed(a): if top < k - 1: break if ai > 0: ans2 += base2 * ai ans2 %= mod else: ans += abs(base2 * ai) ans %= mod base2 = base2 * inv_t[top] * (top - k + 1) % mod top -= 1 print(((ans - ans2) % mod))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10**9 + 7 a.sort(reverse=True) N = n + 2 P = mod inv_t = [0] + [1] for i in range(2, N): inv_t += [inv_t[P % i] * (P - int(P / i)) % P] base = 1 for item in range(n - k + 1, n): base = (base * item) % mod for i in range(1, k): base = (base * inv_t[i]) % mod base2 = base ans = 0 top = n - 1 for ai in a: if top < k - 1: break ans += base * ai ans %= mod base = base * inv_t[top] * (top - k + 1) % mod top -= 1 top = n - 1 for ai in reversed(a): if top < k - 1: break ans -= base2 * ai ans %= mod base2 = base2 * inv_t[top] * (top - k + 1) % mod top -= 1 print((ans % mod))
false
19.148936
[ "-ans2 = 0", "- if ai > 0:", "- ans += base * ai", "- ans %= mod", "- else:", "- ans2 += abs(base * ai)", "- ans2 %= mod", "+ ans += base * ai", "+ ans %= mod", "- if ai > 0:", "- ans2 += base2 * ai", "- ans2 %= mod", "- else:", "- ans += abs(base2 * ai)", "- ans %= mod", "+ ans -= base2 * ai", "+ ans %= mod", "-print(((ans - ans2) % mod))", "+print((ans % mod))" ]
false
0.143174
0.182541
0.78434
[ "s183059958", "s794102120" ]
u977389981
p03804
python
s891039433
s368963418
25
18
3,060
3,064
Accepted
Accepted
28
n, m = list(map(int,input().split())) A = [eval(input()) for _ in range(n)] B = [eval(input()) for _ in range(m)] ans = 'No' for i in range(n - m + 1): for j in range(n - m + 1): C = [] for k in range(m): c = A[i + k][j : j + m] C.append(c) if B == C: ans = 'Yes' break print(ans)
n, m = list(map(int, input().split())) A = [eval(input()) for i in range(n)] B = [eval(input()) for i in range(m)] ans = 'No' for i in range(n - m + 1): C = [] for j in range(n): C.append(A[j][i : i + m]) for k in range(n - m +1): if B == C[k : k + m]: ans = 'Yes' break print(ans)
15
15
353
343
n, m = list(map(int, input().split())) A = [eval(input()) for _ in range(n)] B = [eval(input()) for _ in range(m)] ans = "No" for i in range(n - m + 1): for j in range(n - m + 1): C = [] for k in range(m): c = A[i + k][j : j + m] C.append(c) if B == C: ans = "Yes" break print(ans)
n, m = list(map(int, input().split())) A = [eval(input()) for i in range(n)] B = [eval(input()) for i in range(m)] ans = "No" for i in range(n - m + 1): C = [] for j in range(n): C.append(A[j][i : i + m]) for k in range(n - m + 1): if B == C[k : k + m]: ans = "Yes" break print(ans)
false
0
[ "-A = [eval(input()) for _ in range(n)]", "-B = [eval(input()) for _ in range(m)]", "+A = [eval(input()) for i in range(n)]", "+B = [eval(input()) for i in range(m)]", "- for j in range(n - m + 1):", "- C = []", "- for k in range(m):", "- c = A[i + k][j : j + m]", "- C.append(c)", "- if B == C:", "+ C = []", "+ for j in range(n):", "+ C.append(A[j][i : i + m])", "+ for k in range(n - m + 1):", "+ if B == C[k : k + m]:" ]
false
0.08695
0.107653
0.807692
[ "s891039433", "s368963418" ]
u489959379
p02912
python
s692128524
s363764210
200
150
14,532
14,180
Accepted
Accepted
25
import heapq import math n, m = list(map(int, input().split())) a = list(map(int, input().split())) q = [] heapq.heapify(q) for i in range(n): heapq.heappush(q, -a[i]) for _ in range(m): b = heapq.heappop(q) / 2 heapq.heappush(q, math.ceil(b)) print((sum(q) * -1))
import sys from heapq import heapify, heappop, heappush sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, m = list(map(int, input().split())) A = list([int(x) * (-1) for x in input().split()]) heapify(A) for _ in range(m): a = (heappop(A) * (-1)) // 2 heappush(A, a * (-1)) print((sum(A) * (-1))) if __name__ == '__main__': resolve()
16
22
288
463
import heapq import math n, m = list(map(int, input().split())) a = list(map(int, input().split())) q = [] heapq.heapify(q) for i in range(n): heapq.heappush(q, -a[i]) for _ in range(m): b = heapq.heappop(q) / 2 heapq.heappush(q, math.ceil(b)) print((sum(q) * -1))
import sys from heapq import heapify, heappop, heappush sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): n, m = list(map(int, input().split())) A = list([int(x) * (-1) for x in input().split()]) heapify(A) for _ in range(m): a = (heappop(A) * (-1)) // 2 heappush(A, a * (-1)) print((sum(A) * (-1))) if __name__ == "__main__": resolve()
false
27.272727
[ "-import heapq", "-import math", "+import sys", "+from heapq import heapify, heappop, heappush", "-n, m = list(map(int, input().split()))", "-a = list(map(int, input().split()))", "-q = []", "-heapq.heapify(q)", "-for i in range(n):", "- heapq.heappush(q, -a[i])", "-for _ in range(m):", "- b = heapq.heappop(q) / 2", "- heapq.heappush(q, math.ceil(b))", "-print((sum(q) * -1))", "+sys.setrecursionlimit(10**7)", "+input = sys.stdin.readline", "+f_inf = float(\"inf\")", "+mod = 10**9 + 7", "+", "+", "+def resolve():", "+ n, m = list(map(int, input().split()))", "+ A = list([int(x) * (-1) for x in input().split()])", "+ heapify(A)", "+ for _ in range(m):", "+ a = (heappop(A) * (-1)) // 2", "+ heappush(A, a * (-1))", "+ print((sum(A) * (-1)))", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.083655
0.036835
2.271062
[ "s692128524", "s363764210" ]
u434428594
p00461
python
s190486881
s703477259
600
480
26,888
9,368
Accepted
Accepted
20
from array import array; while True: n = int(input()) if n == 0: break m = int(input()) s = input() cache = array('i', (0 for x in range(m))) for i in range(len(s) - 2): if s[i:i+3] == 'IOI': cache[i + 2] = cache[i] + 1 print(len([x for x in cache if x >= n]))
from array import array; while True: n = int(input()) if n == 0: break m = int(input()) s = input() cache = array('i', (0 for x in range(m))) for i in range(len(s) - 2): if s[i:i+3] == 'IOI': cache[i + 2] = cache[i] + 1 print(sum(1 for x in cache if x >= n))
16
16
351
346
from array import array while True: n = int(input()) if n == 0: break m = int(input()) s = input() cache = array("i", (0 for x in range(m))) for i in range(len(s) - 2): if s[i : i + 3] == "IOI": cache[i + 2] = cache[i] + 1 print(len([x for x in cache if x >= n]))
from array import array while True: n = int(input()) if n == 0: break m = int(input()) s = input() cache = array("i", (0 for x in range(m))) for i in range(len(s) - 2): if s[i : i + 3] == "IOI": cache[i + 2] = cache[i] + 1 print(sum(1 for x in cache if x >= n))
false
0
[ "- print(len([x for x in cache if x >= n]))", "+ print(sum(1 for x in cache if x >= n))" ]
false
0.087271
0.086669
1.006952
[ "s190486881", "s703477259" ]
u871980676
p02936
python
s179561499
s464038746
1,976
1,527
265,372
290,500
Accepted
Accepted
22.72
import sys input = sys.stdin.readline sys.setrecursionlimit(1000000) N,Q = list(map(int,input().split())) ab = [ tuple(map(int,input().split())) for i in range(N-1) ] px = [ tuple(map(int,input().split())) for i in range(Q) ] dic = {} dic2=[0]*(N+1) dic3=[0]*N for i in range(N): dic[i+1] = [] for i in range(N-1): tmp1 = ab[i][0] tmp2 = ab[i][1] dic[tmp1].append(tmp2) dic[tmp2].append(tmp1) ab=0 for i in range(Q): dic2[px[i][0]] += px[i][1] px=0 def rec(now_node,prevval): nowval = prevval + dic2[now_node] dic3[now_node-1] = nowval tg_list = dic[now_node][:] for elem in tg_list: dic[elem].remove(now_node) rec(elem,nowval) rec(1,0) res = [str(dic3[i-1]) for i in range(1,N+1)] print((' '.join(res)))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline sys.setrecursionlimit(1000000) N,Q = list(map(int,readline().split())) abpx = list(map(int,read().split())) ab = iter(abpx[:N+N-2]) px = iter(abpx[N+N-2:]) dic = {} dic2=[0]*(N+1) dic3=[0]*N for i in range(N): dic[i+1] = [] for a,b in zip(ab,ab): dic[a].append(b) dic[b].append(a) for p,x in zip(px,px): dic2[p] += x def rec(now_node,prevval): nowval = prevval + dic2[now_node] dic3[now_node-1] = nowval tg_list = dic[now_node][:] for elem in tg_list: dic[elem].remove(now_node) rec(elem,nowval) rec(1,0) res = [str(dic3[i-1]) for i in range(1,N+1)] print((' '.join(res)))
31
29
784
719
import sys input = sys.stdin.readline sys.setrecursionlimit(1000000) N, Q = list(map(int, input().split())) ab = [tuple(map(int, input().split())) for i in range(N - 1)] px = [tuple(map(int, input().split())) for i in range(Q)] dic = {} dic2 = [0] * (N + 1) dic3 = [0] * N for i in range(N): dic[i + 1] = [] for i in range(N - 1): tmp1 = ab[i][0] tmp2 = ab[i][1] dic[tmp1].append(tmp2) dic[tmp2].append(tmp1) ab = 0 for i in range(Q): dic2[px[i][0]] += px[i][1] px = 0 def rec(now_node, prevval): nowval = prevval + dic2[now_node] dic3[now_node - 1] = nowval tg_list = dic[now_node][:] for elem in tg_list: dic[elem].remove(now_node) rec(elem, nowval) rec(1, 0) res = [str(dic3[i - 1]) for i in range(1, N + 1)] print((" ".join(res)))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline sys.setrecursionlimit(1000000) N, Q = list(map(int, readline().split())) abpx = list(map(int, read().split())) ab = iter(abpx[: N + N - 2]) px = iter(abpx[N + N - 2 :]) dic = {} dic2 = [0] * (N + 1) dic3 = [0] * N for i in range(N): dic[i + 1] = [] for a, b in zip(ab, ab): dic[a].append(b) dic[b].append(a) for p, x in zip(px, px): dic2[p] += x def rec(now_node, prevval): nowval = prevval + dic2[now_node] dic3[now_node - 1] = nowval tg_list = dic[now_node][:] for elem in tg_list: dic[elem].remove(now_node) rec(elem, nowval) rec(1, 0) res = [str(dic3[i - 1]) for i in range(1, N + 1)] print((" ".join(res)))
false
6.451613
[ "-input = sys.stdin.readline", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "-N, Q = list(map(int, input().split()))", "-ab = [tuple(map(int, input().split())) for i in range(N - 1)]", "-px = [tuple(map(int, input().split())) for i in range(Q)]", "+N, Q = list(map(int, readline().split()))", "+abpx = list(map(int, read().split()))", "+ab = iter(abpx[: N + N - 2])", "+px = iter(abpx[N + N - 2 :])", "-for i in range(N - 1):", "- tmp1 = ab[i][0]", "- tmp2 = ab[i][1]", "- dic[tmp1].append(tmp2)", "- dic[tmp2].append(tmp1)", "-ab = 0", "-for i in range(Q):", "- dic2[px[i][0]] += px[i][1]", "-px = 0", "+for a, b in zip(ab, ab):", "+ dic[a].append(b)", "+ dic[b].append(a)", "+for p, x in zip(px, px):", "+ dic2[p] += x" ]
false
0.048376
0.007441
6.501194
[ "s179561499", "s464038746" ]
u767995501
p03126
python
s882933666
s503433523
21
18
2,940
3,060
Accepted
Accepted
14.29
n,m=list(map(int,input().split())) S=set(range(1,m+1)) for i in range(n): K,*A=list(map(int,input().split())) S&=set(A) print((len(S)))
n, m = list(map(int, input().split())) l = [] for i in range(n): a = [int(x) for x in input().split()] for j in range(1, a[0] + 1): l.append(a[j]) ans = 0 for i in range(m + 1): if l.count(i) == n: ans += 1 print(ans)
6
14
134
241
n, m = list(map(int, input().split())) S = set(range(1, m + 1)) for i in range(n): K, *A = list(map(int, input().split())) S &= set(A) print((len(S)))
n, m = list(map(int, input().split())) l = [] for i in range(n): a = [int(x) for x in input().split()] for j in range(1, a[0] + 1): l.append(a[j]) ans = 0 for i in range(m + 1): if l.count(i) == n: ans += 1 print(ans)
false
57.142857
[ "-S = set(range(1, m + 1))", "+l = []", "- K, *A = list(map(int, input().split()))", "- S &= set(A)", "-print((len(S)))", "+ a = [int(x) for x in input().split()]", "+ for j in range(1, a[0] + 1):", "+ l.append(a[j])", "+ans = 0", "+for i in range(m + 1):", "+ if l.count(i) == n:", "+ ans += 1", "+print(ans)" ]
false
0.036218
0.036235
0.999532
[ "s882933666", "s503433523" ]
u816587940
p02728
python
s419968752
s328198039
2,954
2,543
175,956
147,256
Accepted
Accepted
13.91
from fractions import gcd import sys sys.setrecursionlimit(4100000) def os(): return eval(input()) def oi(): return int(eval(input())) def oli(): return list(map(int, input().split())) def olai(): return list(map(int, input().split())) def olas(): return list(input().split()) def mlai(L): return [int(eval(input())) for _ in range(L)] def mlas(L): return [eval(input()) for _ in range(L)] def ar(a, b, c=-1, d=-1, INIT=0): if(c==-1): return [[INIT]*b for _ in range(a)] if(d==-1): return [[[INIT]*c for _ in range(b)] for __ in range(a)] return [[[[INIT]*d for _ in range(c)] for __ in range(b)] for ___ in range(a)] def lcm(a, b): return (a*b)//gcd(a, b) #MOD P = 10**9 + 7 N = 200001 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心 inv = [0] + [1] # 1/x finv = [1] + [1] # 1/x! fac = [1] + [1] # x! for i in range(2, N): inv += [inv[P % i] * (P - int(P / i)) % P] fac += [(fac[i-1] * i) % P] finv += [(finv[i-1] * inv[i]) % P] def comb(a, b): if a<b or b < 0: return 0 # error return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P class T: num = 1 child = 0 def __init__(self, a, b): self.num = a self.child = b def step(x): return T(x.num, x.child+1) def merge(x, y): if(x.num==-1): return y if(y.num==-1): return x return T((x.num*y.num*comb(x.child+y.child, x.child))%P, x.child+y.child) G = [[] for _ in range(200001)] down_data = [T(-1, -1) for _ in range(200001)] dat = [T(-1, -1) for _ in range(200001)] def dfs(now, parent): cnt = 0 for to in G[now]: if(to==parent): continue cnt += 1 dfs(to, now) down_data[now] = merge(down_data[now], step(down_data[to])) if(cnt==0): down_data[now] = T(1, 0) def dfs_rev(now, parent, rev): left = [] right = [] cnt = 0 for to in G[now]: if(to==parent): continue if(len(left)==0): left.append(step(down_data[to])) else: left.append(merge(left[cnt-1], step(down_data[to]))) cnt += 1 cnt = 0 for to in reversed(G[now]): if(to==parent): continue if(len(right)==0): right.append(step(down_data[to])) else: right.append(merge(right[cnt-1], step(down_data[to]))) cnt += 1 cnt = 0 dat[now] = merge(rev, down_data[now]) for to in G[now]: if(to==parent): continue x = T(-1, -1) if cnt==0 else left[cnt-1] y = T(-1, -1) if cnt==len(right)-1 else right[len(right)-2-cnt] dfs_rev(to, now, step(merge(rev, merge(x, y)))) cnt += 1 def main(): n = oi() for i in range(n-1): a, b = oli() G[a].append(b) G[b].append(a) root = -1 for i in range(1, n+1): if(len(G[i]) == 1): root = i break dfs(root, -1) dfs_rev(root, -1, T(1, 0)) for i in range(1, n+1): print((dat[i].num)) if __name__ == "__main__": main()
from fractions import gcd import sys sys.setrecursionlimit(4100000) def os(): return eval(input()) def oi(): return int(eval(input())) def oli(): return list(map(int, input().split())) def olai(): return list(map(int, input().split())) def olas(): return list(input().split()) def mlai(L): return [int(eval(input())) for _ in range(L)] def mlas(L): return [eval(input()) for _ in range(L)] def ar(a, b, c=-1, d=-1, INIT=0): if(c==-1): return [[INIT]*b for _ in range(a)] if(d==-1): return [[[INIT]*c for _ in range(b)] for __ in range(a)] return [[[[INIT]*d for _ in range(c)] for __ in range(b)] for ___ in range(a)] def lcm(a, b): return (a*b)//gcd(a, b) #MOD P = 10**9 + 7 N = 200001 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心 inv = [0] + [1] # 1/x finv = [1] + [1] # 1/x! fac = [1] + [1] # x! for i in range(2, N): inv += [inv[P % i] * (P - int(P / i)) % P] fac += [(fac[i-1] * i) % P] finv += [(finv[i-1] * inv[i]) % P] def comb(a, b): if a<b or b < 0: return 0 # error return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P #------------------------------------------------------------------- #全方位木dpで扱うクラス class T: num = 1 child = 0 def __init__(self, a, b): self.num = a self.child = b #零元 zero = T(1, 0) #一個遷移した時の変化 def step(x): return T(x.num, x.child+1) #マージ def merge(x, y): if(x.num==-1): return y if(y.num==-1): return x return T((x.num*y.num*comb(x.child+y.child, x.child))%P, x.child+y.child) G = [[] for _ in range(200001)] down_data = [zero for _ in range(200001)] dat = [zero for _ in range(200001)] def dfs(now, parent): cnt = 0 for to in G[now]: if(to==parent): continue cnt += 1 dfs(to, now) down_data[now] = merge(down_data[now], step(down_data[to])) def dfs_rev(now, parent, rev): #累積 left = [] right = [] cnt = 0 for to in G[now]: if(to==parent): continue if(len(left)==0): left.append(step(down_data[to])) else: left.append(merge(left[cnt-1], step(down_data[to]))) cnt += 1 cnt = 0 for to in reversed(G[now]): if(to==parent): continue if(len(right)==0): right.append(step(down_data[to])) else: right.append(merge(right[cnt-1], step(down_data[to]))) cnt += 1 cnt = 0 dat[now] = merge(rev, down_data[now]) for to in G[now]: if(to==parent): continue x = zero if cnt==0 else left[cnt-1] y = zero if cnt==len(right)-1 else right[len(right)-2-cnt] dfs_rev(to, now, step(merge(rev, merge(x, y)))) cnt += 1 #------------------------------------------------------------------- def main(): n = oi() for i in range(n-1): a, b = oli() G[a].append(b) G[b].append(a) root = -1 for i in range(1, n+1): if(len(G[i]) == 1): root = i break dfs(root, -1) dfs_rev(root, -1, zero) for i in range(1, n+1): print((dat[i].num)) if __name__ == "__main__": main()
106
108
2,952
3,081
from fractions import gcd import sys sys.setrecursionlimit(4100000) def os(): return eval(input()) def oi(): return int(eval(input())) def oli(): return list(map(int, input().split())) def olai(): return list(map(int, input().split())) def olas(): return list(input().split()) def mlai(L): return [int(eval(input())) for _ in range(L)] def mlas(L): return [eval(input()) for _ in range(L)] def ar(a, b, c=-1, d=-1, INIT=0): if c == -1: return [[INIT] * b for _ in range(a)] if d == -1: return [[[INIT] * c for _ in range(b)] for __ in range(a)] return [[[[INIT] * d for _ in range(c)] for __ in range(b)] for ___ in range(a)] def lcm(a, b): return (a * b) // gcd(a, b) # MOD P = 10**9 + 7 N = 200001 # 使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心 inv = [0] + [1] # 1/x finv = [1] + [1] # 1/x! fac = [1] + [1] # x! for i in range(2, N): inv += [inv[P % i] * (P - int(P / i)) % P] fac += [(fac[i - 1] * i) % P] finv += [(finv[i - 1] * inv[i]) % P] def comb(a, b): if a < b or b < 0: return 0 # error return (fac[a] * ((finv[b] * finv[a - b]) % P)) % P class T: num = 1 child = 0 def __init__(self, a, b): self.num = a self.child = b def step(x): return T(x.num, x.child + 1) def merge(x, y): if x.num == -1: return y if y.num == -1: return x return T((x.num * y.num * comb(x.child + y.child, x.child)) % P, x.child + y.child) G = [[] for _ in range(200001)] down_data = [T(-1, -1) for _ in range(200001)] dat = [T(-1, -1) for _ in range(200001)] def dfs(now, parent): cnt = 0 for to in G[now]: if to == parent: continue cnt += 1 dfs(to, now) down_data[now] = merge(down_data[now], step(down_data[to])) if cnt == 0: down_data[now] = T(1, 0) def dfs_rev(now, parent, rev): left = [] right = [] cnt = 0 for to in G[now]: if to == parent: continue if len(left) == 0: left.append(step(down_data[to])) else: left.append(merge(left[cnt - 1], step(down_data[to]))) cnt += 1 cnt = 0 for to in reversed(G[now]): if to == parent: continue if len(right) == 0: right.append(step(down_data[to])) else: right.append(merge(right[cnt - 1], step(down_data[to]))) cnt += 1 cnt = 0 dat[now] = merge(rev, down_data[now]) for to in G[now]: if to == parent: continue x = T(-1, -1) if cnt == 0 else left[cnt - 1] y = T(-1, -1) if cnt == len(right) - 1 else right[len(right) - 2 - cnt] dfs_rev(to, now, step(merge(rev, merge(x, y)))) cnt += 1 def main(): n = oi() for i in range(n - 1): a, b = oli() G[a].append(b) G[b].append(a) root = -1 for i in range(1, n + 1): if len(G[i]) == 1: root = i break dfs(root, -1) dfs_rev(root, -1, T(1, 0)) for i in range(1, n + 1): print((dat[i].num)) if __name__ == "__main__": main()
from fractions import gcd import sys sys.setrecursionlimit(4100000) def os(): return eval(input()) def oi(): return int(eval(input())) def oli(): return list(map(int, input().split())) def olai(): return list(map(int, input().split())) def olas(): return list(input().split()) def mlai(L): return [int(eval(input())) for _ in range(L)] def mlas(L): return [eval(input()) for _ in range(L)] def ar(a, b, c=-1, d=-1, INIT=0): if c == -1: return [[INIT] * b for _ in range(a)] if d == -1: return [[[INIT] * c for _ in range(b)] for __ in range(a)] return [[[[INIT] * d for _ in range(c)] for __ in range(b)] for ___ in range(a)] def lcm(a, b): return (a * b) // gcd(a, b) # MOD P = 10**9 + 7 N = 200001 # 使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心 inv = [0] + [1] # 1/x finv = [1] + [1] # 1/x! fac = [1] + [1] # x! for i in range(2, N): inv += [inv[P % i] * (P - int(P / i)) % P] fac += [(fac[i - 1] * i) % P] finv += [(finv[i - 1] * inv[i]) % P] def comb(a, b): if a < b or b < 0: return 0 # error return (fac[a] * ((finv[b] * finv[a - b]) % P)) % P # ------------------------------------------------------------------- # 全方位木dpで扱うクラス class T: num = 1 child = 0 def __init__(self, a, b): self.num = a self.child = b # 零元 zero = T(1, 0) # 一個遷移した時の変化 def step(x): return T(x.num, x.child + 1) # マージ def merge(x, y): if x.num == -1: return y if y.num == -1: return x return T((x.num * y.num * comb(x.child + y.child, x.child)) % P, x.child + y.child) G = [[] for _ in range(200001)] down_data = [zero for _ in range(200001)] dat = [zero for _ in range(200001)] def dfs(now, parent): cnt = 0 for to in G[now]: if to == parent: continue cnt += 1 dfs(to, now) down_data[now] = merge(down_data[now], step(down_data[to])) def dfs_rev(now, parent, rev): # 累積 left = [] right = [] cnt = 0 for to in G[now]: if to == parent: continue if len(left) == 0: left.append(step(down_data[to])) else: left.append(merge(left[cnt - 1], step(down_data[to]))) cnt += 1 cnt = 0 for to in reversed(G[now]): if to == parent: continue if len(right) == 0: right.append(step(down_data[to])) else: right.append(merge(right[cnt - 1], step(down_data[to]))) cnt += 1 cnt = 0 dat[now] = merge(rev, down_data[now]) for to in G[now]: if to == parent: continue x = zero if cnt == 0 else left[cnt - 1] y = zero if cnt == len(right) - 1 else right[len(right) - 2 - cnt] dfs_rev(to, now, step(merge(rev, merge(x, y)))) cnt += 1 # ------------------------------------------------------------------- def main(): n = oi() for i in range(n - 1): a, b = oli() G[a].append(b) G[b].append(a) root = -1 for i in range(1, n + 1): if len(G[i]) == 1: root = i break dfs(root, -1) dfs_rev(root, -1, zero) for i in range(1, n + 1): print((dat[i].num)) if __name__ == "__main__": main()
false
1.851852
[ "+# 全方位木dpで扱うクラス", "+# 零元", "+zero = T(1, 0)", "+# 一個遷移した時の変化", "+# マージ", "-down_data = [T(-1, -1) for _ in range(200001)]", "-dat = [T(-1, -1) for _ in range(200001)]", "+down_data = [zero for _ in range(200001)]", "+dat = [zero for _ in range(200001)]", "- if cnt == 0:", "- down_data[now] = T(1, 0)", "+ # 累積", "- x = T(-1, -1) if cnt == 0 else left[cnt - 1]", "- y = T(-1, -1) if cnt == len(right) - 1 else right[len(right) - 2 - cnt]", "+ x = zero if cnt == 0 else left[cnt - 1]", "+ y = zero if cnt == len(right) - 1 else right[len(right) - 2 - cnt]", "- dfs_rev(root, -1, T(1, 0))", "+ dfs_rev(root, -1, zero)" ]
false
1.585975
0.980912
1.616836
[ "s419968752", "s328198039" ]
u562935282
p03127
python
s578803989
s554493313
86
79
14,224
14,596
Accepted
Accepted
8.14
def gcd(x, y): if y == 0: return x return gcd(y, x % y) N = int(eval(input())) a = list(map(int, input().split())) g = a[0] for aa in a[1:]: g = gcd(g, aa) print(g)
from functools import reduce def gcd(a, b): if b == 0: return a return gcd(b, a % b) n = int(eval(input())) a = list(map(int, input().split())) print((reduce(gcd, a)))
12
12
185
184
def gcd(x, y): if y == 0: return x return gcd(y, x % y) N = int(eval(input())) a = list(map(int, input().split())) g = a[0] for aa in a[1:]: g = gcd(g, aa) print(g)
from functools import reduce def gcd(a, b): if b == 0: return a return gcd(b, a % b) n = int(eval(input())) a = list(map(int, input().split())) print((reduce(gcd, a)))
false
0
[ "-def gcd(x, y):", "- if y == 0:", "- return x", "- return gcd(y, x % y)", "+from functools import reduce", "-N = int(eval(input()))", "+def gcd(a, b):", "+ if b == 0:", "+ return a", "+ return gcd(b, a % b)", "+", "+", "+n = int(eval(input()))", "-g = a[0]", "-for aa in a[1:]:", "- g = gcd(g, aa)", "-print(g)", "+print((reduce(gcd, a)))" ]
false
0.059028
0.071605
0.824351
[ "s578803989", "s554493313" ]
u562935282
p03074
python
s736209875
s813899553
259
97
52,356
3,316
Accepted
Accepted
62.55
from bisect import bisect_right N, K = list(map(int, input().split())) s = eval(input()) t = [] abs_t = [] cur = s[0] cnt = 0 for ss in s: if cur == ss: cnt += 1 else: sgn = 1 if cur == '1' else -1 # 逆立ちでないなら-1 t.append(cnt * sgn) abs_t.append(cnt) cur = ss cnt = 1 sgn = 1 if cur == '1' else -1 # 逆立ちでないなら-1 t.append(cnt * sgn) abs_t.append(cnt) M = len(t) sgn_cnt = [0] for tt in t: sgn_cnt.append(sgn_cnt[-1] + (1 if tt < 0 else 0)) # 反転が必要な箇所数の累積和 c_abst = [0] for att in abs_t: c_abst.append(c_abst[-1] + att) # print(t, abs_t, c_abst, sgn_cnt) ans = 0 for i in range(M): ok = bisect_right(sgn_cnt, (K + sgn_cnt[i])) ok -= 1 # print(ok, i, K + sgn_cnt[i]) # print(c_abst) ans = max(ans, c_abst[min(ok, M)] - c_abst[i]) print(ans)
N, K = list(map(int, input().split())) s = eval(input()) l, r = 0, 0 for i in range(K): while r < N and s[r] == '1': r += 1 while r < N and s[r] == '0': r += 1 # K回直立→逆立ちの反転操作を行う while r < N and s[r] == '1': r += 1 # 元々逆立ちしている人の右端まで行く ans = r - l # 区間の人数をansに代入 while r < N: while l < r and s[l] == '1': l += 1 while l < r and s[l] == '0': l += 1 # 左端を右にずらす # 出来るだけ人数が多くなるように区間を縮めるので、 # 0==直立の区間直後まで動かす while r < N and s[r] == '0': r += 1 while r < N and s[r] == '1': r += 1 # 右端を右にずらす # できるだけ人数が多くなるように区間を広げるので、 # 1==逆立ちの区間の直後まで動かす ans = max(ans, r - l) # 区間の人数をansに代入 print(ans) # 尺取り法
47
28
870
660
from bisect import bisect_right N, K = list(map(int, input().split())) s = eval(input()) t = [] abs_t = [] cur = s[0] cnt = 0 for ss in s: if cur == ss: cnt += 1 else: sgn = 1 if cur == "1" else -1 # 逆立ちでないなら-1 t.append(cnt * sgn) abs_t.append(cnt) cur = ss cnt = 1 sgn = 1 if cur == "1" else -1 # 逆立ちでないなら-1 t.append(cnt * sgn) abs_t.append(cnt) M = len(t) sgn_cnt = [0] for tt in t: sgn_cnt.append(sgn_cnt[-1] + (1 if tt < 0 else 0)) # 反転が必要な箇所数の累積和 c_abst = [0] for att in abs_t: c_abst.append(c_abst[-1] + att) # print(t, abs_t, c_abst, sgn_cnt) ans = 0 for i in range(M): ok = bisect_right(sgn_cnt, (K + sgn_cnt[i])) ok -= 1 # print(ok, i, K + sgn_cnt[i]) # print(c_abst) ans = max(ans, c_abst[min(ok, M)] - c_abst[i]) print(ans)
N, K = list(map(int, input().split())) s = eval(input()) l, r = 0, 0 for i in range(K): while r < N and s[r] == "1": r += 1 while r < N and s[r] == "0": r += 1 # K回直立→逆立ちの反転操作を行う while r < N and s[r] == "1": r += 1 # 元々逆立ちしている人の右端まで行く ans = r - l # 区間の人数をansに代入 while r < N: while l < r and s[l] == "1": l += 1 while l < r and s[l] == "0": l += 1 # 左端を右にずらす # 出来るだけ人数が多くなるように区間を縮めるので、 # 0==直立の区間直後まで動かす while r < N and s[r] == "0": r += 1 while r < N and s[r] == "1": r += 1 # 右端を右にずらす # できるだけ人数が多くなるように区間を広げるので、 # 1==逆立ちの区間の直後まで動かす ans = max(ans, r - l) # 区間の人数をansに代入 print(ans) # 尺取り法
false
40.425532
[ "-from bisect import bisect_right", "-", "-t = []", "-abs_t = []", "-cur = s[0]", "-cnt = 0", "-for ss in s:", "- if cur == ss:", "- cnt += 1", "- else:", "- sgn = 1 if cur == \"1\" else -1", "- # 逆立ちでないなら-1", "- t.append(cnt * sgn)", "- abs_t.append(cnt)", "- cur = ss", "- cnt = 1", "-sgn = 1 if cur == \"1\" else -1", "-# 逆立ちでないなら-1", "-t.append(cnt * sgn)", "-abs_t.append(cnt)", "-M = len(t)", "-sgn_cnt = [0]", "-for tt in t:", "- sgn_cnt.append(sgn_cnt[-1] + (1 if tt < 0 else 0))", "-# 反転が必要な箇所数の累積和", "-c_abst = [0]", "-for att in abs_t:", "- c_abst.append(c_abst[-1] + att)", "-# print(t, abs_t, c_abst, sgn_cnt)", "-ans = 0", "-for i in range(M):", "- ok = bisect_right(sgn_cnt, (K + sgn_cnt[i]))", "- ok -= 1", "- # print(ok, i, K + sgn_cnt[i])", "- # print(c_abst)", "- ans = max(ans, c_abst[min(ok, M)] - c_abst[i])", "+l, r = 0, 0", "+for i in range(K):", "+ while r < N and s[r] == \"1\":", "+ r += 1", "+ while r < N and s[r] == \"0\":", "+ r += 1", "+# K回直立→逆立ちの反転操作を行う", "+while r < N and s[r] == \"1\":", "+ r += 1", "+# 元々逆立ちしている人の右端まで行く", "+ans = r - l", "+# 区間の人数をansに代入", "+while r < N:", "+ while l < r and s[l] == \"1\":", "+ l += 1", "+ while l < r and s[l] == \"0\":", "+ l += 1", "+ # 左端を右にずらす", "+ # 出来るだけ人数が多くなるように区間を縮めるので、", "+ # 0==直立の区間直後まで動かす", "+ while r < N and s[r] == \"0\":", "+ r += 1", "+ while r < N and s[r] == \"1\":", "+ r += 1", "+ # 右端を右にずらす", "+ # できるだけ人数が多くなるように区間を広げるので、", "+ # 1==逆立ちの区間の直後まで動かす", "+ ans = max(ans, r - l)", "+ # 区間の人数をansに代入", "+# 尺取り法" ]
false
0.041491
0.129568
0.320222
[ "s736209875", "s813899553" ]
u321035578
p03627
python
s555595247
s143136719
133
102
20,772
21,540
Accepted
Accepted
23.31
import collections def main(): n = int(eval(input())) a = list(map(int,input().split())) cnt = collections.Counter(a) set_a = set(a) a = [] a = list(set_a) a.sort(reverse=True) select = 0 ans = 1 tmp = 0 flg = 0 for i, aa in enumerate(a): if cnt[aa] >= 4 and flg == 0: tmp = aa * aa flg = 1 if cnt[aa] >= 2: select += 1 ans *= aa if select == 2: ans = max(tmp,ans) print(ans) return print((0)) if __name__ == '__main__': main()
import collections def main(): n = int(eval(input())) a = list(map(int,input().split())) # a.sort(reverse=True) c = collections.Counter(a) cl = c.most_common() # cl.sort(reverse = True) cnt = 1 lst = [] now = a[0] ans = 0 for i, cc in enumerate(cl): if cc[1] >= 4: ans = max(ans,cc[0]**2) if cc[1] >= 2: lst.append(cc[0]) # if len(lst) == 2: # print(lst[0] * lst[1]) # return if len(lst) >= 2: lst.sort(reverse=True) ans = max(ans, lst[0] * lst[1]) print(ans) if __name__ == '__main__': main()
31
30
618
665
import collections def main(): n = int(eval(input())) a = list(map(int, input().split())) cnt = collections.Counter(a) set_a = set(a) a = [] a = list(set_a) a.sort(reverse=True) select = 0 ans = 1 tmp = 0 flg = 0 for i, aa in enumerate(a): if cnt[aa] >= 4 and flg == 0: tmp = aa * aa flg = 1 if cnt[aa] >= 2: select += 1 ans *= aa if select == 2: ans = max(tmp, ans) print(ans) return print((0)) if __name__ == "__main__": main()
import collections def main(): n = int(eval(input())) a = list(map(int, input().split())) # a.sort(reverse=True) c = collections.Counter(a) cl = c.most_common() # cl.sort(reverse = True) cnt = 1 lst = [] now = a[0] ans = 0 for i, cc in enumerate(cl): if cc[1] >= 4: ans = max(ans, cc[0] ** 2) if cc[1] >= 2: lst.append(cc[0]) # if len(lst) == 2: # print(lst[0] * lst[1]) # return if len(lst) >= 2: lst.sort(reverse=True) ans = max(ans, lst[0] * lst[1]) print(ans) if __name__ == "__main__": main()
false
3.225806
[ "- cnt = collections.Counter(a)", "- set_a = set(a)", "- a = []", "- a = list(set_a)", "- a.sort(reverse=True)", "- select = 0", "- ans = 1", "- tmp = 0", "- flg = 0", "- for i, aa in enumerate(a):", "- if cnt[aa] >= 4 and flg == 0:", "- tmp = aa * aa", "- flg = 1", "- if cnt[aa] >= 2:", "- select += 1", "- ans *= aa", "- if select == 2:", "- ans = max(tmp, ans)", "- print(ans)", "- return", "- print((0))", "+ # a.sort(reverse=True)", "+ c = collections.Counter(a)", "+ cl = c.most_common()", "+ # cl.sort(reverse = True)", "+ cnt = 1", "+ lst = []", "+ now = a[0]", "+ ans = 0", "+ for i, cc in enumerate(cl):", "+ if cc[1] >= 4:", "+ ans = max(ans, cc[0] ** 2)", "+ if cc[1] >= 2:", "+ lst.append(cc[0])", "+ # if len(lst) == 2:", "+ # print(lst[0] * lst[1])", "+ # return", "+ if len(lst) >= 2:", "+ lst.sort(reverse=True)", "+ ans = max(ans, lst[0] * lst[1])", "+ print(ans)" ]
false
0.040559
0.096685
0.4195
[ "s555595247", "s143136719" ]
u013956357
p02813
python
s258230568
s429769534
112
44
4,752
3,060
Accepted
Accepted
60.71
import itertools import math N = int(eval(input())) P = int(''.join(input().split())) Q = int(''.join(input().split())) N_list = [] for i in itertools.permutations(list(range(1,N+1))): N_list.append(int(''.join([str(x) for x in i]))) pointer1 = 0 pointer2 = 0 for i,x in enumerate(N_list): if x == P: pointer1 = i if x == Q: pointer2 = i print((abs(pointer1 - pointer2)))
import itertools n = int(eval(input())) p = [int(x) for x in input().split()] q = [int(x) for x in input().split()] a,b = 0,0 for i,x in enumerate(itertools.permutations(list(range(1,n+1)))): if list(x) == p: a = i if list(x) == q: b = i print((abs(a-b)))
21
15
402
291
import itertools import math N = int(eval(input())) P = int("".join(input().split())) Q = int("".join(input().split())) N_list = [] for i in itertools.permutations(list(range(1, N + 1))): N_list.append(int("".join([str(x) for x in i]))) pointer1 = 0 pointer2 = 0 for i, x in enumerate(N_list): if x == P: pointer1 = i if x == Q: pointer2 = i print((abs(pointer1 - pointer2)))
import itertools n = int(eval(input())) p = [int(x) for x in input().split()] q = [int(x) for x in input().split()] a, b = 0, 0 for i, x in enumerate(itertools.permutations(list(range(1, n + 1)))): if list(x) == p: a = i if list(x) == q: b = i print((abs(a - b)))
false
28.571429
[ "-import math", "-N = int(eval(input()))", "-P = int(\"\".join(input().split()))", "-Q = int(\"\".join(input().split()))", "-N_list = []", "-for i in itertools.permutations(list(range(1, N + 1))):", "- N_list.append(int(\"\".join([str(x) for x in i])))", "-pointer1 = 0", "-pointer2 = 0", "-for i, x in enumerate(N_list):", "- if x == P:", "- pointer1 = i", "- if x == Q:", "- pointer2 = i", "-print((abs(pointer1 - pointer2)))", "+n = int(eval(input()))", "+p = [int(x) for x in input().split()]", "+q = [int(x) for x in input().split()]", "+a, b = 0, 0", "+for i, x in enumerate(itertools.permutations(list(range(1, n + 1)))):", "+ if list(x) == p:", "+ a = i", "+ if list(x) == q:", "+ b = i", "+print((abs(a - b)))" ]
false
0.044155
0.040154
1.099642
[ "s258230568", "s429769534" ]
u730769327
p03479
python
s337867150
s127949669
171
60
38,384
61,852
Accepted
Accepted
64.91
x,y=list(map(int,input().split())) i=1 while True: x*=2 if x>y: break i+=1 print(i)
x,y=list(map(int,input().split())) a=0 while x<=y: x*=2 a+=1 print(a)
8
6
94
72
x, y = list(map(int, input().split())) i = 1 while True: x *= 2 if x > y: break i += 1 print(i)
x, y = list(map(int, input().split())) a = 0 while x <= y: x *= 2 a += 1 print(a)
false
25
[ "-i = 1", "-while True:", "+a = 0", "+while x <= y:", "- if x > y:", "- break", "- i += 1", "-print(i)", "+ a += 1", "+print(a)" ]
false
0.041346
0.041374
0.999329
[ "s337867150", "s127949669" ]
u654558363
p02947
python
s675806667
s450072120
773
480
18,232
18,228
Accepted
Accepted
37.9
from collections import defaultdict from math import factorial if __name__ == "__main__": n = int(eval(input())) lst = [] count = 0 words = defaultdict(lambda: 0) for i in range(n): words[''.join(sorted(eval(input())))] += 1 sum = 0 for word in words: sum += int(factorial(words[word]) / (factorial(2) * factorial(abs(words[word] - 2)))) print(sum)
from collections import defaultdict if __name__ == "__main__": n = int(eval(input())) lst = [] count = 0 words = defaultdict(lambda: 0) for i in range(n): words[''.join(sorted(eval(input())))] += 1 sum = 0 for word in words: sum += int(words[word]*(words[word] - 1)/2) print(sum)
13
13
397
329
from collections import defaultdict from math import factorial if __name__ == "__main__": n = int(eval(input())) lst = [] count = 0 words = defaultdict(lambda: 0) for i in range(n): words["".join(sorted(eval(input())))] += 1 sum = 0 for word in words: sum += int( factorial(words[word]) / (factorial(2) * factorial(abs(words[word] - 2))) ) print(sum)
from collections import defaultdict if __name__ == "__main__": n = int(eval(input())) lst = [] count = 0 words = defaultdict(lambda: 0) for i in range(n): words["".join(sorted(eval(input())))] += 1 sum = 0 for word in words: sum += int(words[word] * (words[word] - 1) / 2) print(sum)
false
0
[ "-from math import factorial", "- sum += int(", "- factorial(words[word]) / (factorial(2) * factorial(abs(words[word] - 2)))", "- )", "+ sum += int(words[word] * (words[word] - 1) / 2)" ]
false
0.085445
0.072868
1.172602
[ "s675806667", "s450072120" ]
u816171517
p02657
python
s518064437
s799527056
24
21
9,148
9,032
Accepted
Accepted
12.5
a,b=list(map(int,input().split())) print((a*b))
a,b=list(map(float,input().split())) import math a=int(math.floor(a)) b=int(math.floor(b*100)) c=math.floor(a*b/100) print(c)
3
10
43
133
a, b = list(map(int, input().split())) print((a * b))
a, b = list(map(float, input().split())) import math a = int(math.floor(a)) b = int(math.floor(b * 100)) c = math.floor(a * b / 100) print(c)
false
70
[ "-a, b = list(map(int, input().split()))", "-print((a * b))", "+a, b = list(map(float, input().split()))", "+import math", "+", "+a = int(math.floor(a))", "+b = int(math.floor(b * 100))", "+c = math.floor(a * b / 100)", "+print(c)" ]
false
0.046936
0.040135
1.169469
[ "s518064437", "s799527056" ]
u133936772
p02685
python
s088786085
s650052084
782
447
9,192
24,948
Accepted
Accepted
42.84
M=998244353 n,m,k=list(map(int,input().split())) a,c=0,1 for i in range(k+1): a+=c*m*pow(m-1,n+~i,M) c=c*(n+~i)*pow(i+1,-1,M)%M print((a%M))
M=998244353 n,m,k=list(map(int,input().split())) p,c=[m],[1] for i in range(1,n): p+=[p[-1]*(m-1)%M] c+=[c[-1]*(n-i)*pow(i,-1,M)%M] print((sum(p[n-i-1]*c[i] for i in range(k+1))%M))
7
7
142
183
M = 998244353 n, m, k = list(map(int, input().split())) a, c = 0, 1 for i in range(k + 1): a += c * m * pow(m - 1, n + ~i, M) c = c * (n + ~i) * pow(i + 1, -1, M) % M print((a % M))
M = 998244353 n, m, k = list(map(int, input().split())) p, c = [m], [1] for i in range(1, n): p += [p[-1] * (m - 1) % M] c += [c[-1] * (n - i) * pow(i, -1, M) % M] print((sum(p[n - i - 1] * c[i] for i in range(k + 1)) % M))
false
0
[ "-a, c = 0, 1", "-for i in range(k + 1):", "- a += c * m * pow(m - 1, n + ~i, M)", "- c = c * (n + ~i) * pow(i + 1, -1, M) % M", "-print((a % M))", "+p, c = [m], [1]", "+for i in range(1, n):", "+ p += [p[-1] * (m - 1) % M]", "+ c += [c[-1] * (n - i) * pow(i, -1, M) % M]", "+print((sum(p[n - i - 1] * c[i] for i in range(k + 1)) % M))" ]
false
0.067568
0.376557
0.179436
[ "s088786085", "s650052084" ]
u782098901
p03228
python
s167313973
s308040910
19
17
3,060
2,940
Accepted
Accepted
10.53
A, B, K = list(map(int, input().split())) for i in range(K): if A % 2 == 1: A -= 1 A /= 2 A, B = B + A, A if K % 2 == 1: A, B = B, A print((int(A), int(B)))
A, B, K = list(map(int, input().split())) for i in range(K): if i % 2 == 0: A, B = A // 2, B + A // 2 else: A, B = A + B // 2, B // 2 print((int(A), int(B)))
11
9
184
183
A, B, K = list(map(int, input().split())) for i in range(K): if A % 2 == 1: A -= 1 A /= 2 A, B = B + A, A if K % 2 == 1: A, B = B, A print((int(A), int(B)))
A, B, K = list(map(int, input().split())) for i in range(K): if i % 2 == 0: A, B = A // 2, B + A // 2 else: A, B = A + B // 2, B // 2 print((int(A), int(B)))
false
18.181818
[ "- if A % 2 == 1:", "- A -= 1", "- A /= 2", "- A, B = B + A, A", "-if K % 2 == 1:", "- A, B = B, A", "+ if i % 2 == 0:", "+ A, B = A // 2, B + A // 2", "+ else:", "+ A, B = A + B // 2, B // 2" ]
false
0.064097
0.065532
0.978111
[ "s167313973", "s308040910" ]
u729133443
p03110
python
s706455609
s767915879
163
17
38,256
2,940
Accepted
Accepted
89.57
print((sum(380000**('B'in s)*float(s[:-4])for s in open(0).readlines()[1:])))
print((sum(38e4**('B'in s)*float(s[:-4])for s in open(0).readlines()[1:])))
1
1
75
73
print((sum(380000 ** ("B" in s) * float(s[:-4]) for s in open(0).readlines()[1:])))
print((sum(38e4 ** ("B" in s) * float(s[:-4]) for s in open(0).readlines()[1:])))
false
0
[ "-print((sum(380000 ** (\"B\" in s) * float(s[:-4]) for s in open(0).readlines()[1:])))", "+print((sum(38e4 ** (\"B\" in s) * float(s[:-4]) for s in open(0).readlines()[1:])))" ]
false
0.082741
0.081374
1.016796
[ "s706455609", "s767915879" ]
u401487574
p03215
python
s705501308
s381353276
530
112
110,308
117,056
Accepted
Accepted
78.87
ma = lambda :map(int,input().split()) lma = lambda :list(map(int,input().split())) tma = lambda :tuple(map(int,input().split())) ni = lambda:int(input()) yn = lambda fl:print("Yes") if fl else print("No") import collections import math import itertools import heapq as hq n,k = ma() A = lma() bu = [] for i in range(n): tmp=0 for j in range(i,n): tmp+=A[j] bu.append(tmp) mb = bin(max(bu)) ls = [0]*(len(mb)-2) for b in bu: for i in range(len(bin(b))-2): if (b>>i &1): ls[i]+=1 ans = 0 tmp=bu for i in range(len(mb)-3,-1,-1): if ls[i]<k: continue tmp2=[] for b in tmp: if (b>>i &1): tmp2.append(b) if len(tmp2)>=k: ans+=2**i tmp=tmp2 else: pass print(ans)
ma = lambda :list(map(int,input().split())) lma = lambda :list(map(int,input().split())) n,k = ma() A = lma() bu = [] for i in range(n): tmp=0 for j in range(i,n): tmp+=A[j] bu.append(tmp) mb = bin(max(bu)) ans = 0 for i in range(len(mb)-3,-1,-1): tmp=[] for b in bu: if (b>>i &1): tmp.append(b) if len(tmp)>=k: ans+=2**i bu=tmp else: pass print(ans)
39
24
815
453
ma = lambda: map(int, input().split()) lma = lambda: list(map(int, input().split())) tma = lambda: tuple(map(int, input().split())) ni = lambda: int(input()) yn = lambda fl: print("Yes") if fl else print("No") import collections import math import itertools import heapq as hq n, k = ma() A = lma() bu = [] for i in range(n): tmp = 0 for j in range(i, n): tmp += A[j] bu.append(tmp) mb = bin(max(bu)) ls = [0] * (len(mb) - 2) for b in bu: for i in range(len(bin(b)) - 2): if b >> i & 1: ls[i] += 1 ans = 0 tmp = bu for i in range(len(mb) - 3, -1, -1): if ls[i] < k: continue tmp2 = [] for b in tmp: if b >> i & 1: tmp2.append(b) if len(tmp2) >= k: ans += 2**i tmp = tmp2 else: pass print(ans)
ma = lambda: list(map(int, input().split())) lma = lambda: list(map(int, input().split())) n, k = ma() A = lma() bu = [] for i in range(n): tmp = 0 for j in range(i, n): tmp += A[j] bu.append(tmp) mb = bin(max(bu)) ans = 0 for i in range(len(mb) - 3, -1, -1): tmp = [] for b in bu: if b >> i & 1: tmp.append(b) if len(tmp) >= k: ans += 2**i bu = tmp else: pass print(ans)
false
38.461538
[ "-ma = lambda: map(int, input().split())", "+ma = lambda: list(map(int, input().split()))", "-tma = lambda: tuple(map(int, input().split()))", "-ni = lambda: int(input())", "-yn = lambda fl: print(\"Yes\") if fl else print(\"No\")", "-import collections", "-import math", "-import itertools", "-import heapq as hq", "-", "-ls = [0] * (len(mb) - 2)", "-for b in bu:", "- for i in range(len(bin(b)) - 2):", "+ans = 0", "+for i in range(len(mb) - 3, -1, -1):", "+ tmp = []", "+ for b in bu:", "- ls[i] += 1", "-ans = 0", "-tmp = bu", "-for i in range(len(mb) - 3, -1, -1):", "- if ls[i] < k:", "- continue", "- tmp2 = []", "- for b in tmp:", "- if b >> i & 1:", "- tmp2.append(b)", "- if len(tmp2) >= k:", "+ tmp.append(b)", "+ if len(tmp) >= k:", "- tmp = tmp2", "+ bu = tmp" ]
false
0.046645
0.080899
0.576589
[ "s705501308", "s381353276" ]
u633068244
p00158
python
s628008316
s533035680
20
10
4,192
4,196
Accepted
Accepted
50
def collatz(n): c = 0 while n > 1: if n%2: n = 3*n+1 else: n /= 2 c += 1 return c while True: n = int(input()) if n == 0: break print(collatz(n))
def f(n): c=0 while n>1: if n%2:n=3*n+1 else:n /= 2 c += 1 print(c) while 1: n=eval(input()) if n==0:break f(n)
12
12
173
129
def collatz(n): c = 0 while n > 1: if n % 2: n = 3 * n + 1 else: n /= 2 c += 1 return c while True: n = int(input()) if n == 0: break print(collatz(n))
def f(n): c = 0 while n > 1: if n % 2: n = 3 * n + 1 else: n /= 2 c += 1 print(c) while 1: n = eval(input()) if n == 0: break f(n)
false
0
[ "-def collatz(n):", "+def f(n):", "- return c", "+ print(c)", "-while True:", "- n = int(input())", "+while 1:", "+ n = eval(input())", "- print(collatz(n))", "+ f(n)" ]
false
0.041473
0.036891
1.124221
[ "s628008316", "s533035680" ]
u077291787
p02913
python
s182555950
s093032935
74
68
6,388
3,376
Accepted
Accepted
8.11
# ABC141E - Who Says a Pun? def main(): N = int(eval(input())) S = input().rstrip() ok, ng = 0, N // 2 + 1 while ng - ok > 1: mid = (ok + ng) // 2 flg, checked = 0, set() for i in range(N - 2 * mid + 1): checked.add(S[i : i + mid]) if S[i + mid : i + 2 * mid] in checked: flg = 1 break if flg: ok = mid # next mid will be longer else: ng = mid # next mid will be shorter print(ok) # max length of substrings appeared twice or more if __name__ == "__main__": main()
# ABC141E - Who Says a Pun? def resolve(): N = int(eval(input())) S = input().rstrip() ok, ng = 0, N // 2 + 1 while ng - ok > 1: mid = (ok + ng) // 2 flg, checked = 0, set() for i in range(N - 2 * mid + 1): checked.add(hash(S[i : i + mid])) if hash(S[i + mid : i + 2 * mid]) in checked: flg = 1 break if flg: ok = mid # next mid will be longer else: ng = mid # next mid will be shorter print(ok) # max length of substrings appeared twice or more resolve()
22
21
628
614
# ABC141E - Who Says a Pun? def main(): N = int(eval(input())) S = input().rstrip() ok, ng = 0, N // 2 + 1 while ng - ok > 1: mid = (ok + ng) // 2 flg, checked = 0, set() for i in range(N - 2 * mid + 1): checked.add(S[i : i + mid]) if S[i + mid : i + 2 * mid] in checked: flg = 1 break if flg: ok = mid # next mid will be longer else: ng = mid # next mid will be shorter print(ok) # max length of substrings appeared twice or more if __name__ == "__main__": main()
# ABC141E - Who Says a Pun? def resolve(): N = int(eval(input())) S = input().rstrip() ok, ng = 0, N // 2 + 1 while ng - ok > 1: mid = (ok + ng) // 2 flg, checked = 0, set() for i in range(N - 2 * mid + 1): checked.add(hash(S[i : i + mid])) if hash(S[i + mid : i + 2 * mid]) in checked: flg = 1 break if flg: ok = mid # next mid will be longer else: ng = mid # next mid will be shorter print(ok) # max length of substrings appeared twice or more resolve()
false
4.545455
[ "-def main():", "+def resolve():", "- checked.add(S[i : i + mid])", "- if S[i + mid : i + 2 * mid] in checked:", "+ checked.add(hash(S[i : i + mid]))", "+ if hash(S[i + mid : i + 2 * mid]) in checked:", "-if __name__ == \"__main__\":", "- main()", "+resolve()" ]
false
0.03581
0.037021
0.967285
[ "s182555950", "s093032935" ]
u523087093
p02601
python
s349331087
s338627640
37
30
9,208
9,208
Accepted
Accepted
18.92
import itertools A, B, C = list(map(int, input().split())) K = int(eval(input())) targets = [A, B, C] answer = 'No' def check(targets): if targets[1] > targets[0] and targets[2] > targets[1]: return True else: return False cases = itertools.product([0, 1, 2], repeat=K) for case in cases: copy_targets = targets.copy() for i in case: copy_targets[i] = copy_targets[i] * 2 if check(copy_targets): answer = 'Yes' break print(answer)
import itertools def check(targets): if targets[1] > targets[0] and targets[2] > targets[1]: return True else: return False if __name__ == "__main__": A, B, C = list(map(int, input().split())) K = int(eval(input())) targets = [A, B, C] answer = 'No' cases = itertools.product([0, 1, 2], repeat=K) for case in cases: copy_targets = targets.copy() for i in case: copy_targets[i] = copy_targets[i] * 2 if check(copy_targets): answer = 'Yes' break print(answer)
22
25
502
586
import itertools A, B, C = list(map(int, input().split())) K = int(eval(input())) targets = [A, B, C] answer = "No" def check(targets): if targets[1] > targets[0] and targets[2] > targets[1]: return True else: return False cases = itertools.product([0, 1, 2], repeat=K) for case in cases: copy_targets = targets.copy() for i in case: copy_targets[i] = copy_targets[i] * 2 if check(copy_targets): answer = "Yes" break print(answer)
import itertools def check(targets): if targets[1] > targets[0] and targets[2] > targets[1]: return True else: return False if __name__ == "__main__": A, B, C = list(map(int, input().split())) K = int(eval(input())) targets = [A, B, C] answer = "No" cases = itertools.product([0, 1, 2], repeat=K) for case in cases: copy_targets = targets.copy() for i in case: copy_targets[i] = copy_targets[i] * 2 if check(copy_targets): answer = "Yes" break print(answer)
false
12
[ "-", "-A, B, C = list(map(int, input().split()))", "-K = int(eval(input()))", "-targets = [A, B, C]", "-answer = \"No\"", "-cases = itertools.product([0, 1, 2], repeat=K)", "-for case in cases:", "- copy_targets = targets.copy()", "- for i in case:", "- copy_targets[i] = copy_targets[i] * 2", "- if check(copy_targets):", "- answer = \"Yes\"", "- break", "-print(answer)", "+if __name__ == \"__main__\":", "+ A, B, C = list(map(int, input().split()))", "+ K = int(eval(input()))", "+ targets = [A, B, C]", "+ answer = \"No\"", "+ cases = itertools.product([0, 1, 2], repeat=K)", "+ for case in cases:", "+ copy_targets = targets.copy()", "+ for i in case:", "+ copy_targets[i] = copy_targets[i] * 2", "+ if check(copy_targets):", "+ answer = \"Yes\"", "+ break", "+ print(answer)" ]
false
0.045369
0.046788
0.969665
[ "s349331087", "s338627640" ]
u141610915
p02744
python
s394165036
s503315912
409
196
64,476
87,992
Accepted
Accepted
52.08
import sys input = sys.stdin.readline N = int(eval(input())) res = set() a = ord("a") def dfs(s, x): global res if len(s) == N: res.add(s) return for i in range(x + 1): dfs(s + chr(a + i), x) dfs(s + chr(a + x + 1), x + 1) dfs("a", 0) res = sorted(res) for r in res: print(r)
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) N = int(eval(input())) res = set() a = ord("a") mx = lambda x: max(list(map(ord, x))) - a def dfs(s): if len(s) == N: res.add("".join(s)) return for k in range(mx(s) + 2): dfs(s + [chr(k + a)]) dfs(["a"]) for r in sorted(res): print(r)
17
14
306
323
import sys input = sys.stdin.readline N = int(eval(input())) res = set() a = ord("a") def dfs(s, x): global res if len(s) == N: res.add(s) return for i in range(x + 1): dfs(s + chr(a + i), x) dfs(s + chr(a + x + 1), x + 1) dfs("a", 0) res = sorted(res) for r in res: print(r)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) N = int(eval(input())) res = set() a = ord("a") mx = lambda x: max(list(map(ord, x))) - a def dfs(s): if len(s) == N: res.add("".join(s)) return for k in range(mx(s) + 2): dfs(s + [chr(k + a)]) dfs(["a"]) for r in sorted(res): print(r)
false
17.647059
[ "+sys.setrecursionlimit(10**6)", "+mx = lambda x: max(list(map(ord, x))) - a", "-def dfs(s, x):", "- global res", "+def dfs(s):", "- res.add(s)", "+ res.add(\"\".join(s))", "- for i in range(x + 1):", "- dfs(s + chr(a + i), x)", "- dfs(s + chr(a + x + 1), x + 1)", "+ for k in range(mx(s) + 2):", "+ dfs(s + [chr(k + a)])", "-dfs(\"a\", 0)", "-res = sorted(res)", "-for r in res:", "+dfs([\"a\"])", "+for r in sorted(res):" ]
false
0.058726
0.059405
0.988571
[ "s394165036", "s503315912" ]
u923662841
p02994
python
s854739418
s962264262
31
27
9,104
9,044
Accepted
Accepted
12.9
N,L = list(map(int, input().split())) r = [L+i-1 for i in range(1,N+1)] e = min(r, key=abs) print((sum(r)-e))
N,L=list(map(int,input().split())) taste=list(range(L,L+N)) print((sum(taste)-min(taste,key=abs)))
4
3
104
86
N, L = list(map(int, input().split())) r = [L + i - 1 for i in range(1, N + 1)] e = min(r, key=abs) print((sum(r) - e))
N, L = list(map(int, input().split())) taste = list(range(L, L + N)) print((sum(taste) - min(taste, key=abs)))
false
25
[ "-r = [L + i - 1 for i in range(1, N + 1)]", "-e = min(r, key=abs)", "-print((sum(r) - e))", "+taste = list(range(L, L + N))", "+print((sum(taste) - min(taste, key=abs)))" ]
false
0.099251
0.099196
1.000557
[ "s854739418", "s962264262" ]
u814265211
p02719
python
s961871209
s571515264
31
25
9,144
9,156
Accepted
Accepted
19.35
N, K = list(map(int, input().split())) print((min(abs(N - (K*(N//K+1))), abs(N - (K*(N//K))))))
N, K = list(map(int, input().split())) A = abs(N - (K*(N//K+1))) B = abs(N - (K*(N//K))) print((min(A, B)))
2
4
94
109
N, K = list(map(int, input().split())) print((min(abs(N - (K * (N // K + 1))), abs(N - (K * (N // K))))))
N, K = list(map(int, input().split())) A = abs(N - (K * (N // K + 1))) B = abs(N - (K * (N // K))) print((min(A, B)))
false
50
[ "-print((min(abs(N - (K * (N // K + 1))), abs(N - (K * (N // K))))))", "+A = abs(N - (K * (N // K + 1)))", "+B = abs(N - (K * (N // K)))", "+print((min(A, B)))" ]
false
0.108754
0.035934
3.026475
[ "s961871209", "s571515264" ]
u156815136
p02608
python
s379938702
s544346762
871
177
14,632
83,324
Accepted
Accepted
79.68
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(input()) n = I() dp = [0] * (500000) for x in range(1,101): for y in range(1,101): for z in range(1,101): pe = x**2 + y**2 + z**2 + x*y + y*z + z*x dp[pe] += 1 print(*dp[1:n+1],sep='\n')
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入 import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(eval(input())) NUM = [0] * 500000 for x in range(1,101): for y in range(1,101): for z in range(1,101): nya = x**2 + y**2 + z**2 + x*y + y*z + z*x NUM[nya] += 1 n = I() for i in range(1,n+1): print((NUM[i]))
36
38
888
961
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations, permutations, accumulate # (string,3) 3回 # from collections import deque from collections import deque, defaultdict, Counter import decimal import re # import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 # mod = 9982443453 def readInts(): return list(map(int, input().split())) def I(): return int(input()) n = I() dp = [0] * (500000) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): pe = x**2 + y**2 + z**2 + x * y + y * z + z * x dp[pe] += 1 print(*dp[1 : n + 1], sep="\n")
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations, permutations, accumulate # (string,3) 3回 # from collections import deque from collections import deque, defaultdict, Counter import decimal import re # import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入 import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 # mod = 9982443453 def readInts(): return list(map(int, input().split())) def I(): return int(eval(input())) NUM = [0] * 500000 for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): nya = x**2 + y**2 + z**2 + x * y + y * z + z * x NUM[nya] += 1 n = I() for i in range(1, n + 1): print((NUM[i]))
false
5.263158
[ "+# my_round_int = lambda x:np.round((x*2 + 1)//2)", "+# 四捨五入", "- return int(input())", "+ return int(eval(input()))", "-n = I()", "-dp = [0] * (500000)", "+NUM = [0] * 500000", "- pe = x**2 + y**2 + z**2 + x * y + y * z + z * x", "- dp[pe] += 1", "-print(*dp[1 : n + 1], sep=\"\\n\")", "+ nya = x**2 + y**2 + z**2 + x * y + y * z + z * x", "+ NUM[nya] += 1", "+n = I()", "+for i in range(1, n + 1):", "+ print((NUM[i]))" ]
false
2.129552
2.258148
0.943053
[ "s379938702", "s544346762" ]
u073852194
p03165
python
s663939049
s684747522
491
351
120,284
147,812
Accepted
Accepted
28.51
def LCS(s,t,restore=False): dp = [[0 for j in range(len(t)+1)] for i in range(len(s)+1)] for i in range(len(s)): for j in range(len(t)): if s[i] == t[j]: dp[i+1][j+1] = dp[i][j]+1 else: dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]) if restore: lcs = [] stack = [(len(s),len(t))] while stack: x,y = stack.pop() if dp[x][y] == 0: break if x-1 >= 0 and dp[x][y] == dp[x-1][y]: stack.append((x-1,y)) elif y-1 >= 0 and dp[x][y] == dp[x][y-1]: stack.append((x,y-1)) else: lcs.append(s[x-1]) stack.append((x-1,y-1)) lcs = ''.join(lcs)[::-1] return dp[-1][-1],lcs return dp[-1][-1] S = eval(input()) T = eval(input()) print((LCS(S,T,True)[1]))
S = eval(input()) T = eval(input()) dp = [[0 for j in range(len(T) + 1)] for i in range(len(S) + 1)] for i in range(len(S)): for j in range(len(T)): if S[i] == T[j]: dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1]) else: dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]) res = [] stack = [(len(S), len(T))] while stack: x, y = stack.pop() if dp[x][y] == 0: break if x - 1 >= 0 and dp[x][y] == dp[x - 1][y]: stack.append((x - 1, y)) elif y - 1 >= 0 and dp[x][y] == dp[x][y - 1]: stack.append((x, y - 1)) else: res.append(S[x - 1]) stack.append((x - 1, y - 1)) print((''.join(res[::-1])))
30
28
910
725
def LCS(s, t, restore=False): dp = [[0 for j in range(len(t) + 1)] for i in range(len(s) + 1)] for i in range(len(s)): for j in range(len(t)): if s[i] == t[j]: dp[i + 1][j + 1] = dp[i][j] + 1 else: dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]) if restore: lcs = [] stack = [(len(s), len(t))] while stack: x, y = stack.pop() if dp[x][y] == 0: break if x - 1 >= 0 and dp[x][y] == dp[x - 1][y]: stack.append((x - 1, y)) elif y - 1 >= 0 and dp[x][y] == dp[x][y - 1]: stack.append((x, y - 1)) else: lcs.append(s[x - 1]) stack.append((x - 1, y - 1)) lcs = "".join(lcs)[::-1] return dp[-1][-1], lcs return dp[-1][-1] S = eval(input()) T = eval(input()) print((LCS(S, T, True)[1]))
S = eval(input()) T = eval(input()) dp = [[0 for j in range(len(T) + 1)] for i in range(len(S) + 1)] for i in range(len(S)): for j in range(len(T)): if S[i] == T[j]: dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1]) else: dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]) res = [] stack = [(len(S), len(T))] while stack: x, y = stack.pop() if dp[x][y] == 0: break if x - 1 >= 0 and dp[x][y] == dp[x - 1][y]: stack.append((x - 1, y)) elif y - 1 >= 0 and dp[x][y] == dp[x][y - 1]: stack.append((x, y - 1)) else: res.append(S[x - 1]) stack.append((x - 1, y - 1)) print(("".join(res[::-1])))
false
6.666667
[ "-def LCS(s, t, restore=False):", "- dp = [[0 for j in range(len(t) + 1)] for i in range(len(s) + 1)]", "- for i in range(len(s)):", "- for j in range(len(t)):", "- if s[i] == t[j]:", "- dp[i + 1][j + 1] = dp[i][j] + 1", "- else:", "- dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])", "- if restore:", "- lcs = []", "- stack = [(len(s), len(t))]", "- while stack:", "- x, y = stack.pop()", "- if dp[x][y] == 0:", "- break", "- if x - 1 >= 0 and dp[x][y] == dp[x - 1][y]:", "- stack.append((x - 1, y))", "- elif y - 1 >= 0 and dp[x][y] == dp[x][y - 1]:", "- stack.append((x, y - 1))", "- else:", "- lcs.append(s[x - 1])", "- stack.append((x - 1, y - 1))", "- lcs = \"\".join(lcs)[::-1]", "- return dp[-1][-1], lcs", "- return dp[-1][-1]", "-", "-", "-print((LCS(S, T, True)[1]))", "+dp = [[0 for j in range(len(T) + 1)] for i in range(len(S) + 1)]", "+for i in range(len(S)):", "+ for j in range(len(T)):", "+ if S[i] == T[j]:", "+ dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1])", "+ else:", "+ dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])", "+res = []", "+stack = [(len(S), len(T))]", "+while stack:", "+ x, y = stack.pop()", "+ if dp[x][y] == 0:", "+ break", "+ if x - 1 >= 0 and dp[x][y] == dp[x - 1][y]:", "+ stack.append((x - 1, y))", "+ elif y - 1 >= 0 and dp[x][y] == dp[x][y - 1]:", "+ stack.append((x, y - 1))", "+ else:", "+ res.append(S[x - 1])", "+ stack.append((x - 1, y - 1))", "+print((\"\".join(res[::-1])))" ]
false
0.040826
0.032119
1.271069
[ "s663939049", "s684747522" ]
u033606236
p03574
python
s837569335
s059563480
30
27
3,064
3,064
Accepted
Accepted
10
y, x= list(map(int,input().split())) bomb = [0 for i in range(y)] ary = [[0 for i in range(x)]for i in range(y)] for i in range(y): bomb[i] = list(eval(input())) for a in range(y): for b in range(x): if bomb[a][b] == "#": ary[a][b] = "#" else : ary[a][b] = 0 # この配列を用意することによって’#’の周りの計算を楽にできるようになる height_ary =[-1,-1,-1, 0,0, 1,1,1] width_ary =[-1, 0 ,1,-1,1,-1,0,1] for a in range(y): for b in range(x): if ary[a][b] == "#": for i in range(8): h = height_ary[i] + a w = width_ary [i] + b if h < 0 or h >= y: continue if w < 0 or w >= x: continue if not ary[h][w] == "#": ary[h][w] += 1 for i in range(y): result = list(map(str,ary[i])) print(("".join(result)))
h, w = list(map(int,input().split())) a = [eval(input()) for _ in range(h)] for i in range(h): l ="" for j in range(w): if a[i][j] == "#": l += "#" else: l+=str(sum([s[max(0,j-1):min(w,j+2)].count("#") for s in a[max(0,i-1):min(h,i+2)]])) print(l)
31
10
855
296
y, x = list(map(int, input().split())) bomb = [0 for i in range(y)] ary = [[0 for i in range(x)] for i in range(y)] for i in range(y): bomb[i] = list(eval(input())) for a in range(y): for b in range(x): if bomb[a][b] == "#": ary[a][b] = "#" else: ary[a][b] = 0 # この配列を用意することによって’#’の周りの計算を楽にできるようになる height_ary = [-1, -1, -1, 0, 0, 1, 1, 1] width_ary = [-1, 0, 1, -1, 1, -1, 0, 1] for a in range(y): for b in range(x): if ary[a][b] == "#": for i in range(8): h = height_ary[i] + a w = width_ary[i] + b if h < 0 or h >= y: continue if w < 0 or w >= x: continue if not ary[h][w] == "#": ary[h][w] += 1 for i in range(y): result = list(map(str, ary[i])) print(("".join(result)))
h, w = list(map(int, input().split())) a = [eval(input()) for _ in range(h)] for i in range(h): l = "" for j in range(w): if a[i][j] == "#": l += "#" else: l += str( sum( [ s[max(0, j - 1) : min(w, j + 2)].count("#") for s in a[max(0, i - 1) : min(h, i + 2)] ] ) ) print(l)
false
67.741935
[ "-y, x = list(map(int, input().split()))", "-bomb = [0 for i in range(y)]", "-ary = [[0 for i in range(x)] for i in range(y)]", "-for i in range(y):", "- bomb[i] = list(eval(input()))", "-for a in range(y):", "- for b in range(x):", "- if bomb[a][b] == \"#\":", "- ary[a][b] = \"#\"", "+h, w = list(map(int, input().split()))", "+a = [eval(input()) for _ in range(h)]", "+for i in range(h):", "+ l = \"\"", "+ for j in range(w):", "+ if a[i][j] == \"#\":", "+ l += \"#\"", "- ary[a][b] = 0", "-# この配列を用意することによって’#’の周りの計算を楽にできるようになる", "-height_ary = [-1, -1, -1, 0, 0, 1, 1, 1]", "-width_ary = [-1, 0, 1, -1, 1, -1, 0, 1]", "-for a in range(y):", "- for b in range(x):", "- if ary[a][b] == \"#\":", "- for i in range(8):", "- h = height_ary[i] + a", "- w = width_ary[i] + b", "- if h < 0 or h >= y:", "- continue", "- if w < 0 or w >= x:", "- continue", "- if not ary[h][w] == \"#\":", "- ary[h][w] += 1", "-for i in range(y):", "- result = list(map(str, ary[i]))", "- print((\"\".join(result)))", "+ l += str(", "+ sum(", "+ [", "+ s[max(0, j - 1) : min(w, j + 2)].count(\"#\")", "+ for s in a[max(0, i - 1) : min(h, i + 2)]", "+ ]", "+ )", "+ )", "+ print(l)" ]
false
0.048836
0.048386
1.009293
[ "s837569335", "s059563480" ]
u254871849
p03478
python
s041190018
s857614004
36
32
3,060
3,060
Accepted
Accepted
11.11
import sys # import collections # import math # import string # import bisect # import re # import itertools # import statistics def main(): n, a, b = (int(x) for x in sys.stdin.read().split()) total = 0 for i in range(1, n+1): s = sum(list(int(x) for x in str(i))) if a <= s <= b: total += i print(total) if __name__ == "__main__": # execute only if run as a script main()
import sys n, a, b = list(map(int, sys.stdin.readline().split())) def main(): res = 0 for i in range(1, n+1): s = sum([int(d) for d in str(i)]) if a <= s <= b: res += i return res if __name__ == '__main__': ans = main() print(ans)
20
15
435
293
import sys # import collections # import math # import string # import bisect # import re # import itertools # import statistics def main(): n, a, b = (int(x) for x in sys.stdin.read().split()) total = 0 for i in range(1, n + 1): s = sum(list(int(x) for x in str(i))) if a <= s <= b: total += i print(total) if __name__ == "__main__": # execute only if run as a script main()
import sys n, a, b = list(map(int, sys.stdin.readline().split())) def main(): res = 0 for i in range(1, n + 1): s = sum([int(d) for d in str(i)]) if a <= s <= b: res += i return res if __name__ == "__main__": ans = main() print(ans)
false
25
[ "-# import collections", "-# import math", "-# import string", "-# import bisect", "-# import re", "-# import itertools", "-# import statistics", "+n, a, b = list(map(int, sys.stdin.readline().split()))", "+", "+", "- n, a, b = (int(x) for x in sys.stdin.read().split())", "- total = 0", "+ res = 0", "- s = sum(list(int(x) for x in str(i)))", "+ s = sum([int(d) for d in str(i)])", "- total += i", "- print(total)", "+ res += i", "+ return res", "- # execute only if run as a script", "- main()", "+ ans = main()", "+ print(ans)" ]
false
0.045943
0.044887
1.023529
[ "s041190018", "s857614004" ]
u259861571
p03160
python
s168037726
s211209224
132
121
13,980
20,420
Accepted
Accepted
8.33
n = int(eval(input())) lst = [int(i) for i in input().split()] dp = [1e7]*n dp[0] = 0 dp[1] = abs(lst[1]-lst[0]) for i in range(2, len(lst)): dp[i] = min(dp[i-1]+abs(lst[i]-lst[i-1]), dp[i-2]+abs(lst[i]-lst[i-2])) print((dp[-1]))
N = int(eval(input())) h = list(map(int, input().split())) dp = [1e7]*N dp[0] = 0 dp[1] = abs(h[1]-h[0]) for i in range(2, N): dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2])) print((dp[-1]))
11
11
238
216
n = int(eval(input())) lst = [int(i) for i in input().split()] dp = [1e7] * n dp[0] = 0 dp[1] = abs(lst[1] - lst[0]) for i in range(2, len(lst)): dp[i] = min( dp[i - 1] + abs(lst[i] - lst[i - 1]), dp[i - 2] + abs(lst[i] - lst[i - 2]) ) print((dp[-1]))
N = int(eval(input())) h = list(map(int, input().split())) dp = [1e7] * N dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, N): dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[-1]))
false
0
[ "-n = int(eval(input()))", "-lst = [int(i) for i in input().split()]", "-dp = [1e7] * n", "+N = int(eval(input()))", "+h = list(map(int, input().split()))", "+dp = [1e7] * N", "-dp[1] = abs(lst[1] - lst[0])", "-for i in range(2, len(lst)):", "- dp[i] = min(", "- dp[i - 1] + abs(lst[i] - lst[i - 1]), dp[i - 2] + abs(lst[i] - lst[i - 2])", "- )", "+dp[1] = abs(h[1] - h[0])", "+for i in range(2, N):", "+ dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))" ]
false
0.043652
0.170287
0.256345
[ "s168037726", "s211209224" ]
u475503988
p02889
python
s658423927
s364839551
1,951
1,677
60,120
19,908
Accepted
Accepted
14.04
INF = 1001001001 N, M, L = list(map(int, input().split())) fuel = [[INF] * N for _ in range(N)] for i in range(M): A, B, C = list(map(int, input().split())) A -= 1 B -= 1 fuel[A][B] = C fuel[B][A] = C for i in range(N): fuel[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): fuel[i][j] = min(fuel[i][j], fuel[i][k] + fuel[k][j]) dist = [[INF] * N for _ in range(N)] for i in range(N): for j in range(N): if i == j: dist[i][j] = 0 elif fuel[i][j] <= L: dist[i][j] = 1 for k in range(N): for i in range(N): for j in range(N): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) Q = int(eval(input())) for i in range(Q): s, t = list(map(int, input().split())) s -= 1 t -= 1 if dist[s][t] == INF: print((-1)) else: print((dist[s][t] - 1))
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall INF = 1001001001 N, M, L = list(map(int, input().split())) fuel = [[INF] * N for _ in range(N)] for i in range(M): A, B, C = list(map(int, input().split())) A -= 1 B -= 1 fuel[A][B] = C fuel[B][A] = C for i in range(N): fuel[i][i] = 0 fuel = floyd_warshall(csgraph_from_dense(fuel)) # for k in range(N): # for i in range(N): # for j in range(N): # fuel[i][j] = min(fuel[i][j], fuel[i][k] + fuel[k][j]) dist = [[INF] * N for _ in range(N)] for i in range(N): for j in range(N): if i == j: dist[i][j] = 0 elif fuel[i][j] <= L: dist[i][j] = 1 dist = floyd_warshall(csgraph_from_dense(dist)) # for k in range(N): # for i in range(N): # for j in range(N): # dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) Q = int(eval(input())) for i in range(Q): s, t = list(map(int, input().split())) s -= 1 t -= 1 if dist[s][t] == INF: print((-1)) else: print((int(dist[s][t]) - 1))
41
44
924
1,112
INF = 1001001001 N, M, L = list(map(int, input().split())) fuel = [[INF] * N for _ in range(N)] for i in range(M): A, B, C = list(map(int, input().split())) A -= 1 B -= 1 fuel[A][B] = C fuel[B][A] = C for i in range(N): fuel[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): fuel[i][j] = min(fuel[i][j], fuel[i][k] + fuel[k][j]) dist = [[INF] * N for _ in range(N)] for i in range(N): for j in range(N): if i == j: dist[i][j] = 0 elif fuel[i][j] <= L: dist[i][j] = 1 for k in range(N): for i in range(N): for j in range(N): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) Q = int(eval(input())) for i in range(Q): s, t = list(map(int, input().split())) s -= 1 t -= 1 if dist[s][t] == INF: print((-1)) else: print((dist[s][t] - 1))
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall INF = 1001001001 N, M, L = list(map(int, input().split())) fuel = [[INF] * N for _ in range(N)] for i in range(M): A, B, C = list(map(int, input().split())) A -= 1 B -= 1 fuel[A][B] = C fuel[B][A] = C for i in range(N): fuel[i][i] = 0 fuel = floyd_warshall(csgraph_from_dense(fuel)) # for k in range(N): # for i in range(N): # for j in range(N): # fuel[i][j] = min(fuel[i][j], fuel[i][k] + fuel[k][j]) dist = [[INF] * N for _ in range(N)] for i in range(N): for j in range(N): if i == j: dist[i][j] = 0 elif fuel[i][j] <= L: dist[i][j] = 1 dist = floyd_warshall(csgraph_from_dense(dist)) # for k in range(N): # for i in range(N): # for j in range(N): # dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) Q = int(eval(input())) for i in range(Q): s, t = list(map(int, input().split())) s -= 1 t -= 1 if dist[s][t] == INF: print((-1)) else: print((int(dist[s][t]) - 1))
false
6.818182
[ "+from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall", "+", "-for k in range(N):", "- for i in range(N):", "- for j in range(N):", "- fuel[i][j] = min(fuel[i][j], fuel[i][k] + fuel[k][j])", "+fuel = floyd_warshall(csgraph_from_dense(fuel))", "+# for k in range(N):", "+# for i in range(N):", "+# for j in range(N):", "+# fuel[i][j] = min(fuel[i][j], fuel[i][k] + fuel[k][j])", "-for k in range(N):", "- for i in range(N):", "- for j in range(N):", "- dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])", "+dist = floyd_warshall(csgraph_from_dense(dist))", "+# for k in range(N):", "+# for i in range(N):", "+# for j in range(N):", "+# dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])", "- print((dist[s][t] - 1))", "+ print((int(dist[s][t]) - 1))" ]
false
0.044112
0.400476
0.11015
[ "s658423927", "s364839551" ]
u497046426
p03145
python
s233735635
s441766501
19
17
3,316
2,940
Accepted
Accepted
10.53
AB, BC, CA = list(map(int, input().split())) print((AB * BC//2))
A, B, C = list(map(int, input().split())) print((A * B // 2))
2
2
57
54
AB, BC, CA = list(map(int, input().split())) print((AB * BC // 2))
A, B, C = list(map(int, input().split())) print((A * B // 2))
false
0
[ "-AB, BC, CA = list(map(int, input().split()))", "-print((AB * BC // 2))", "+A, B, C = list(map(int, input().split()))", "+print((A * B // 2))" ]
false
0.065558
0.056896
1.152248
[ "s233735635", "s441766501" ]
u972591645
p02582
python
s792526098
s263413647
38
29
9,924
8,976
Accepted
Accepted
23.68
import re s = eval(input()) print((max(list(map(len, re.split('S', s))))))
print((len(max((input().split('S'))))))
3
1
62
37
import re s = eval(input()) print((max(list(map(len, re.split("S", s))))))
print((len(max((input().split("S"))))))
false
66.666667
[ "-import re", "-", "-s = eval(input())", "-print((max(list(map(len, re.split(\"S\", s))))))", "+print((len(max((input().split(\"S\"))))))" ]
false
0.049939
0.037244
1.340852
[ "s792526098", "s263413647" ]
u630211216
p02711
python
s589052248
s392417799
30
27
9,004
9,004
Accepted
Accepted
10
if '7' in eval(input()): print("Yes") else: print("No")
print(("YNeos"['7' not in eval(input())::2]))
4
1
61
38
if "7" in eval(input()): print("Yes") else: print("No")
print(("YNeos"["7" not in eval(input()) :: 2]))
false
75
[ "-if \"7\" in eval(input()):", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+print((\"YNeos\"[\"7\" not in eval(input()) :: 2]))" ]
false
0.038239
0.039371
0.971264
[ "s589052248", "s392417799" ]
u232852711
p03027
python
s539124905
s083275210
1,556
1,340
84,716
84,972
Accepted
Accepted
13.88
import sys input = sys.stdin.readline MOD = 10**6+3 q = int(eval(input())) fact = [1]*MOD for i in range(1, MOD): fact[i] = fact[i-1]*i%MOD finv = [1]*(MOD-1) + [pow(fact[-1], MOD-2, MOD)] for i in range(MOD-1, 0, -1): finv[i-1] = finv[i]*i%MOD for _ in range(q): x, d, n = list(map(int, input().split())) if d == 0: ans = pow(x, n, MOD) else: x_div = x*pow(d, MOD-2, MOD)%MOD if x_div+n-1 > MOD: ans = 0 else: if x_div+n-1 >= MOD: ans = 0 else: f = fact[x_div+n-1] fi = pow(fact[x_div-1], MOD-2, MOD) ans = f*fi%MOD*pow(d, n, MOD)%MOD print(ans)
import sys input = sys.stdin.readline MOD = 10**6+3 q = int(eval(input())) fact = [1]*MOD for i in range(1, MOD): fact[i] = fact[i-1]*i%MOD finv = [1]*(MOD-1) + [pow(fact[-1], MOD-2, MOD)] for i in range(MOD-1, 0, -1): finv[i-1] = finv[i]*i%MOD for _ in range(q): x, d, n = list(map(int, input().split())) if d == 0: ans = pow(x, n, MOD) else: x_div = x*pow(d, MOD-2, MOD)%MOD if x_div+n-1 > MOD: ans = 0 else: if x_div+n-1 >= MOD: ans = 0 else: ans = fact[x_div+n-1]*finv[x_div-1]%MOD*pow(d, n, MOD)%MOD print(ans)
28
26
720
655
import sys input = sys.stdin.readline MOD = 10**6 + 3 q = int(eval(input())) fact = [1] * MOD for i in range(1, MOD): fact[i] = fact[i - 1] * i % MOD finv = [1] * (MOD - 1) + [pow(fact[-1], MOD - 2, MOD)] for i in range(MOD - 1, 0, -1): finv[i - 1] = finv[i] * i % MOD for _ in range(q): x, d, n = list(map(int, input().split())) if d == 0: ans = pow(x, n, MOD) else: x_div = x * pow(d, MOD - 2, MOD) % MOD if x_div + n - 1 > MOD: ans = 0 else: if x_div + n - 1 >= MOD: ans = 0 else: f = fact[x_div + n - 1] fi = pow(fact[x_div - 1], MOD - 2, MOD) ans = f * fi % MOD * pow(d, n, MOD) % MOD print(ans)
import sys input = sys.stdin.readline MOD = 10**6 + 3 q = int(eval(input())) fact = [1] * MOD for i in range(1, MOD): fact[i] = fact[i - 1] * i % MOD finv = [1] * (MOD - 1) + [pow(fact[-1], MOD - 2, MOD)] for i in range(MOD - 1, 0, -1): finv[i - 1] = finv[i] * i % MOD for _ in range(q): x, d, n = list(map(int, input().split())) if d == 0: ans = pow(x, n, MOD) else: x_div = x * pow(d, MOD - 2, MOD) % MOD if x_div + n - 1 > MOD: ans = 0 else: if x_div + n - 1 >= MOD: ans = 0 else: ans = fact[x_div + n - 1] * finv[x_div - 1] % MOD * pow(d, n, MOD) % MOD print(ans)
false
7.142857
[ "- f = fact[x_div + n - 1]", "- fi = pow(fact[x_div - 1], MOD - 2, MOD)", "- ans = f * fi % MOD * pow(d, n, MOD) % MOD", "+ ans = fact[x_div + n - 1] * finv[x_div - 1] % MOD * pow(d, n, MOD) % MOD" ]
false
0.822089
0.812412
1.011912
[ "s539124905", "s083275210" ]
u150984829
p00040
python
s892188849
s478990897
160
140
5,596
5,600
Accepted
Accepted
12.5
z='abcdefghijklmnopqrstuvwxyz' for _ in[0]*int(eval(input())): e=eval(input()) for i in range(1,26,2): for j in range(26): a='' for c in e: a+=z[(z.index(c)*i+j)%26]if c in z else c if'that'in a or'this'in a:print(a);break
z='abcdefghijklmnopqrstuvwxyz' for _ in[0]*int(eval(input())): e=eval(input()) for i in range(1,26,2): for j in range(26): a=''.join(z[(z.index(c)*i+j)%26]if c in z else c for c in e) if'that'in a or'this'in a:print(a);break
9
7
236
229
z = "abcdefghijklmnopqrstuvwxyz" for _ in [0] * int(eval(input())): e = eval(input()) for i in range(1, 26, 2): for j in range(26): a = "" for c in e: a += z[(z.index(c) * i + j) % 26] if c in z else c if "that" in a or "this" in a: print(a) break
z = "abcdefghijklmnopqrstuvwxyz" for _ in [0] * int(eval(input())): e = eval(input()) for i in range(1, 26, 2): for j in range(26): a = "".join(z[(z.index(c) * i + j) % 26] if c in z else c for c in e) if "that" in a or "this" in a: print(a) break
false
22.222222
[ "- a = \"\"", "- for c in e:", "- a += z[(z.index(c) * i + j) % 26] if c in z else c", "+ a = \"\".join(z[(z.index(c) * i + j) % 26] if c in z else c for c in e)" ]
false
0.0473
0.039934
1.184434
[ "s892188849", "s478990897" ]
u285891772
p03852
python
s518678145
s043472361
170
155
14,500
13,680
Accepted
Accepted
8.82
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2 from itertools import accumulate, permutations, combinations, product, groupby from operator import itemgetter, mul from copy import deepcopy, copy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce import numpy as np def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 boin = ["a", "e", "i", "o", "u"] c = eval(input()) print(("vowel" if c in boin else "consonant"))
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2 from itertools import accumulate, permutations, combinations, product, groupby from operator import itemgetter, mul from copy import deepcopy, copy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce import numpy as np def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 boin = ["a", "e", "i", "o", "u"] c = eval(input()) if c in boin: print("vowel") else: print("consonant")
25
28
908
922
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2 from itertools import accumulate, permutations, combinations, product, groupby from operator import itemgetter, mul from copy import deepcopy, copy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce import numpy as np def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 boin = ["a", "e", "i", "o", "u"] c = eval(input()) print(("vowel" if c in boin else "consonant"))
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2 from itertools import accumulate, permutations, combinations, product, groupby from operator import itemgetter, mul from copy import deepcopy, copy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce import numpy as np def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 boin = ["a", "e", "i", "o", "u"] c = eval(input()) if c in boin: print("vowel") else: print("consonant")
false
10.714286
[ "-print((\"vowel\" if c in boin else \"consonant\"))", "+if c in boin:", "+ print(\"vowel\")", "+else:", "+ print(\"consonant\")" ]
false
0.036394
0.043214
0.842193
[ "s518678145", "s043472361" ]
u058781705
p03281
python
s040102441
s621459083
171
73
38,768
63,564
Accepted
Accepted
57.31
import collections def solve(): N = int(eval(input())) def GetDivider(num): cnt = 0 for i in range(1, num+1): if num % i == 0: cnt += 1 return cnt ans = 0 for i in range(1, N+1): if GetDivider(i) == 8: if i % 2 != 0: ans += 1 print(ans) if __name__ == "__main__": solve()
N = int(eval(input())) def GetDivider(num): cnt = 0 for i in range(1, num+1): if num % i == 0: cnt += 1 return cnt ans = 0 for i in range(1, N+1): if GetDivider(i) == 8: if i % 2 != 0: ans += 1 print(ans)
29
17
418
275
import collections def solve(): N = int(eval(input())) def GetDivider(num): cnt = 0 for i in range(1, num + 1): if num % i == 0: cnt += 1 return cnt ans = 0 for i in range(1, N + 1): if GetDivider(i) == 8: if i % 2 != 0: ans += 1 print(ans) if __name__ == "__main__": solve()
N = int(eval(input())) def GetDivider(num): cnt = 0 for i in range(1, num + 1): if num % i == 0: cnt += 1 return cnt ans = 0 for i in range(1, N + 1): if GetDivider(i) == 8: if i % 2 != 0: ans += 1 print(ans)
false
41.37931
[ "-import collections", "+N = int(eval(input()))", "-def solve():", "- N = int(eval(input()))", "-", "- def GetDivider(num):", "- cnt = 0", "- for i in range(1, num + 1):", "- if num % i == 0:", "- cnt += 1", "- return cnt", "-", "- ans = 0", "- for i in range(1, N + 1):", "- if GetDivider(i) == 8:", "- if i % 2 != 0:", "- ans += 1", "- print(ans)", "+def GetDivider(num):", "+ cnt = 0", "+ for i in range(1, num + 1):", "+ if num % i == 0:", "+ cnt += 1", "+ return cnt", "-if __name__ == \"__main__\":", "- solve()", "+ans = 0", "+for i in range(1, N + 1):", "+ if GetDivider(i) == 8:", "+ if i % 2 != 0:", "+ ans += 1", "+print(ans)" ]
false
0.039805
0.041406
0.961319
[ "s040102441", "s621459083" ]
u426534722
p02272
python
s979054770
s671080542
4,330
3,870
63,760
61,656
Accepted
Accepted
10.62
SENTINEL = 2000000000 L = R = [0] cnt = 0 def merge(A, n, left, mid, right): L = A[left:mid] + [SENTINEL] R = A[mid:right] + [SENTINEL] i = j = 0 global cnt for k in range(left, right): cnt += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, n, left, right): if left + 1 < right: mid = (left + right) // 2 mergeSort(A, n, left, mid) mergeSort(A, n, mid, right) merge(A, n, left, mid, right) n = int(eval(input())) A = [int(i) for i in input().split()] mergeSort(A, n, 0, n) print((*A)) print(cnt)
INF = float("inf") cnt = 0 def merge(A, left, mid, right): global cnt n1 = mid - left n2 = right - mid L = A[left: left + n1] + [INF] R = A[mid: mid + n2] + [INF] i = j = 0 for k in range(left, right): cnt += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, left, right): if left + 1 < right: mid = (left + right) // 2 mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) n = int(eval(input())) S = list(map(int, input().split())) mergeSort(S, 0, n) print((*S)) print(cnt)
27
29
673
684
SENTINEL = 2000000000 L = R = [0] cnt = 0 def merge(A, n, left, mid, right): L = A[left:mid] + [SENTINEL] R = A[mid:right] + [SENTINEL] i = j = 0 global cnt for k in range(left, right): cnt += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, n, left, right): if left + 1 < right: mid = (left + right) // 2 mergeSort(A, n, left, mid) mergeSort(A, n, mid, right) merge(A, n, left, mid, right) n = int(eval(input())) A = [int(i) for i in input().split()] mergeSort(A, n, 0, n) print((*A)) print(cnt)
INF = float("inf") cnt = 0 def merge(A, left, mid, right): global cnt n1 = mid - left n2 = right - mid L = A[left : left + n1] + [INF] R = A[mid : mid + n2] + [INF] i = j = 0 for k in range(left, right): cnt += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, left, right): if left + 1 < right: mid = (left + right) // 2 mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) n = int(eval(input())) S = list(map(int, input().split())) mergeSort(S, 0, n) print((*S)) print(cnt)
false
6.896552
[ "-SENTINEL = 2000000000", "-L = R = [0]", "+INF = float(\"inf\")", "-def merge(A, n, left, mid, right):", "- L = A[left:mid] + [SENTINEL]", "- R = A[mid:right] + [SENTINEL]", "+def merge(A, left, mid, right):", "+ global cnt", "+ n1 = mid - left", "+ n2 = right - mid", "+ L = A[left : left + n1] + [INF]", "+ R = A[mid : mid + n2] + [INF]", "- global cnt", "-def mergeSort(A, n, left, right):", "+def mergeSort(A, left, right):", "- mergeSort(A, n, left, mid)", "- mergeSort(A, n, mid, right)", "- merge(A, n, left, mid, right)", "+ mergeSort(A, left, mid)", "+ mergeSort(A, mid, right)", "+ merge(A, left, mid, right)", "-A = [int(i) for i in input().split()]", "-mergeSort(A, n, 0, n)", "-print((*A))", "+S = list(map(int, input().split()))", "+mergeSort(S, 0, n)", "+print((*S))" ]
false
0.040776
0.038911
1.047918
[ "s979054770", "s671080542" ]
u442948527
p03844
python
s244666549
s668950503
35
30
9,108
9,088
Accepted
Accepted
14.29
a,o,b=input().split() a=int(a) b=int(b) print(([a+b,a-b][o=="-"]))
print((eval(input())))
4
1
67
20
a, o, b = input().split() a = int(a) b = int(b) print(([a + b, a - b][o == "-"]))
print((eval(input())))
false
75
[ "-a, o, b = input().split()", "-a = int(a)", "-b = int(b)", "-print(([a + b, a - b][o == \"-\"]))", "+print((eval(input())))" ]
false
0.040236
0.091138
0.441488
[ "s244666549", "s668950503" ]
u981931040
p03472
python
s990787067
s999521317
1,844
266
11,264
17,052
Accepted
Accepted
85.57
import math N , H = list(map(int , input().split())) slash = [] throw = [] for _ in range(N): a , b = list(map(int , input().split())) slash.append(a) throw.append(b) count = 0 #print(slash) slash_max = max(slash) #print(throw) throw.sort(reverse = True) #print(throw) while H > 0: #print(H) if not throw or throw[0] < slash_max : count += math.ceil(H / slash_max) break else: H -= throw[0] throw.pop(0) #print(throw) count += 1 print(count)
import math N, H = list(map(int, input().split())) a_l = [] b_l = [] for _ in range(N): a, b = list(map(int, input().split())) a_l.append(a) b_l.append(b) a_l.sort(reverse=True) b_l.sort(reverse=True) ans = 0 for i in range(N): if a_l[0] >= b_l[i]: break else: ans += 1 H = max(H - b_l[i], 0) if H <= 0: break ans += math.ceil(H / a_l[0]) print(ans)
25
23
522
425
import math N, H = list(map(int, input().split())) slash = [] throw = [] for _ in range(N): a, b = list(map(int, input().split())) slash.append(a) throw.append(b) count = 0 # print(slash) slash_max = max(slash) # print(throw) throw.sort(reverse=True) # print(throw) while H > 0: # print(H) if not throw or throw[0] < slash_max: count += math.ceil(H / slash_max) break else: H -= throw[0] throw.pop(0) # print(throw) count += 1 print(count)
import math N, H = list(map(int, input().split())) a_l = [] b_l = [] for _ in range(N): a, b = list(map(int, input().split())) a_l.append(a) b_l.append(b) a_l.sort(reverse=True) b_l.sort(reverse=True) ans = 0 for i in range(N): if a_l[0] >= b_l[i]: break else: ans += 1 H = max(H - b_l[i], 0) if H <= 0: break ans += math.ceil(H / a_l[0]) print(ans)
false
8
[ "-slash = []", "-throw = []", "+a_l = []", "+b_l = []", "- slash.append(a)", "- throw.append(b)", "-count = 0", "-# print(slash)", "-slash_max = max(slash)", "-# print(throw)", "-throw.sort(reverse=True)", "-# print(throw)", "-while H > 0:", "- # print(H)", "- if not throw or throw[0] < slash_max:", "- count += math.ceil(H / slash_max)", "+ a_l.append(a)", "+ b_l.append(b)", "+a_l.sort(reverse=True)", "+b_l.sort(reverse=True)", "+ans = 0", "+for i in range(N):", "+ if a_l[0] >= b_l[i]:", "- H -= throw[0]", "- throw.pop(0)", "- # print(throw)", "- count += 1", "-print(count)", "+ ans += 1", "+ H = max(H - b_l[i], 0)", "+ if H <= 0:", "+ break", "+ans += math.ceil(H / a_l[0])", "+print(ans)" ]
false
0.034935
0.041814
0.835497
[ "s990787067", "s999521317" ]
u353919145
p03013
python
s340557651
s283216465
391
183
460,020
4,016
Accepted
Accepted
53.2
line = eval(input()) X, Y = [int(n) for n in line.split()] broken_steps = set() for _ in range(Y): line = eval(input()) broken_steps.add(int(line)) if 1 not in broken_steps: if 2 not in broken_steps: stairs = [1, 2] else: stairs = [1, 0] elif 2 not in broken_steps: stairs = [0, 1] else: stairs = [0, 0] for i in range(2, X): number_of_steps = 0 if i+1 not in broken_steps: number_of_steps = stairs[i - 1] + stairs[i-2] stairs.append(number_of_steps) predicted_value = stairs[X-1] print((predicted_value % 1000000007))
fib = [1,1,1,2] def fibonacci(n): if n<len(fib): return fib[n] x = len(fib) a = fib[len(fib)-2] b = fib[len(fib)-1] while x<=n: c = b b = a+b a = c x+=1 return b h = input().split(" ") n = int(h[0]) a = [] for i in range(n+1): a.append(1) m = int(h[1]) for i in range(m): an = int(eval(input())) a[an]=0 prod=1 ck = 0 sum = 0 for i in range(n+1): if a[i]==0: if ck==1: prod =0 break prod*=fibonacci(sum) sum=0 ck=1 else: sum+=1 ck=0 prod*=fibonacci(sum) print((prod%1000000007))
25
42
591
671
line = eval(input()) X, Y = [int(n) for n in line.split()] broken_steps = set() for _ in range(Y): line = eval(input()) broken_steps.add(int(line)) if 1 not in broken_steps: if 2 not in broken_steps: stairs = [1, 2] else: stairs = [1, 0] elif 2 not in broken_steps: stairs = [0, 1] else: stairs = [0, 0] for i in range(2, X): number_of_steps = 0 if i + 1 not in broken_steps: number_of_steps = stairs[i - 1] + stairs[i - 2] stairs.append(number_of_steps) predicted_value = stairs[X - 1] print((predicted_value % 1000000007))
fib = [1, 1, 1, 2] def fibonacci(n): if n < len(fib): return fib[n] x = len(fib) a = fib[len(fib) - 2] b = fib[len(fib) - 1] while x <= n: c = b b = a + b a = c x += 1 return b h = input().split(" ") n = int(h[0]) a = [] for i in range(n + 1): a.append(1) m = int(h[1]) for i in range(m): an = int(eval(input())) a[an] = 0 prod = 1 ck = 0 sum = 0 for i in range(n + 1): if a[i] == 0: if ck == 1: prod = 0 break prod *= fibonacci(sum) sum = 0 ck = 1 else: sum += 1 ck = 0 prod *= fibonacci(sum) print((prod % 1000000007))
false
40.47619
[ "-line = eval(input())", "-X, Y = [int(n) for n in line.split()]", "-broken_steps = set()", "-for _ in range(Y):", "- line = eval(input())", "- broken_steps.add(int(line))", "-if 1 not in broken_steps:", "- if 2 not in broken_steps:", "- stairs = [1, 2]", "+fib = [1, 1, 1, 2]", "+", "+", "+def fibonacci(n):", "+ if n < len(fib):", "+ return fib[n]", "+ x = len(fib)", "+ a = fib[len(fib) - 2]", "+ b = fib[len(fib) - 1]", "+ while x <= n:", "+ c = b", "+ b = a + b", "+ a = c", "+ x += 1", "+ return b", "+", "+", "+h = input().split(\" \")", "+n = int(h[0])", "+a = []", "+for i in range(n + 1):", "+ a.append(1)", "+m = int(h[1])", "+for i in range(m):", "+ an = int(eval(input()))", "+ a[an] = 0", "+prod = 1", "+ck = 0", "+sum = 0", "+for i in range(n + 1):", "+ if a[i] == 0:", "+ if ck == 1:", "+ prod = 0", "+ break", "+ prod *= fibonacci(sum)", "+ sum = 0", "+ ck = 1", "- stairs = [1, 0]", "-elif 2 not in broken_steps:", "- stairs = [0, 1]", "-else:", "- stairs = [0, 0]", "-for i in range(2, X):", "- number_of_steps = 0", "- if i + 1 not in broken_steps:", "- number_of_steps = stairs[i - 1] + stairs[i - 2]", "- stairs.append(number_of_steps)", "-predicted_value = stairs[X - 1]", "-print((predicted_value % 1000000007))", "+ sum += 1", "+ ck = 0", "+prod *= fibonacci(sum)", "+print((prod % 1000000007))" ]
false
0.035696
0.03677
0.970808
[ "s340557651", "s283216465" ]
u675844759
p02393
python
s965282104
s862571232
30
20
7,588
7,656
Accepted
Accepted
33.33
a = [int(i) for i in input().split()] print((" ".join(map(str,sorted(a)))))
a = [int(i) for i in input().split()] a.sort() print((a[0],a[1],a[2]))
2
3
74
70
a = [int(i) for i in input().split()] print((" ".join(map(str, sorted(a)))))
a = [int(i) for i in input().split()] a.sort() print((a[0], a[1], a[2]))
false
33.333333
[ "-print((\" \".join(map(str, sorted(a)))))", "+a.sort()", "+print((a[0], a[1], a[2]))" ]
false
0.081332
0.079928
1.017565
[ "s965282104", "s862571232" ]
u761320129
p02608
python
s435681814
s910305364
635
451
11,812
9,308
Accepted
Accepted
28.98
N = int(eval(input())) from collections import Counter c = Counter() for x in range(1,101): for y in range(1,101): for z in range(1,101): n = x*x + y*y + z*z + x*y + y*z + z*x c[n] += 1 for i in range(1,N+1): print((c[i]))
N = int(input()) ans = [0]*(N+1) for x in range(1,101): for y in range(1,101): for z in range(1,101): n = x*x + y*y + z*z + x*y + y*z + z*x if n <= N: ans[n] += 1 print(*ans[1:], sep='\n')
10
9
263
248
N = int(eval(input())) from collections import Counter c = Counter() for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): n = x * x + y * y + z * z + x * y + y * z + z * x c[n] += 1 for i in range(1, N + 1): print((c[i]))
N = int(input()) ans = [0] * (N + 1) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): n = x * x + y * y + z * z + x * y + y * z + z * x if n <= N: ans[n] += 1 print(*ans[1:], sep="\n")
false
10
[ "-N = int(eval(input()))", "-from collections import Counter", "-", "-c = Counter()", "+N = int(input())", "+ans = [0] * (N + 1)", "- c[n] += 1", "-for i in range(1, N + 1):", "- print((c[i]))", "+ if n <= N:", "+ ans[n] += 1", "+print(*ans[1:], sep=\"\\n\")" ]
false
1.765622
1.091117
1.618179
[ "s435681814", "s910305364" ]
u989345508
p03379
python
s077108595
s917291756
333
307
25,472
25,220
Accepted
Accepted
7.81
n=int(eval(input())) x=[int(i) for i in input().split()] y=sorted(x) l=y[n//2-1] m=y[n//2] for i in range(n): if x[i]<=l: print(m) else: print(l)
n=int(eval(input())) x=list(map(int,input().split())) y=sorted(x) k,l=y[n//2-1],y[n//2] for i in range(n): if x[i]<=k: print(l) else: print(k)
10
9
173
168
n = int(eval(input())) x = [int(i) for i in input().split()] y = sorted(x) l = y[n // 2 - 1] m = y[n // 2] for i in range(n): if x[i] <= l: print(m) else: print(l)
n = int(eval(input())) x = list(map(int, input().split())) y = sorted(x) k, l = y[n // 2 - 1], y[n // 2] for i in range(n): if x[i] <= k: print(l) else: print(k)
false
10
[ "-x = [int(i) for i in input().split()]", "+x = list(map(int, input().split()))", "-l = y[n // 2 - 1]", "-m = y[n // 2]", "+k, l = y[n // 2 - 1], y[n // 2]", "- if x[i] <= l:", "- print(m)", "+ if x[i] <= k:", "+ print(l)", "- print(l)", "+ print(k)" ]
false
0.049646
0.04977
0.997511
[ "s077108595", "s917291756" ]
u541610817
p03331
python
s995139940
s249667414
163
92
3,060
3,060
Accepted
Accepted
43.56
N = int(eval(input())) def SumDigits(num): sum = 0 while True: sum += num % 10 num //= 10 if num == 0: break return sum infinity = float('inf') min = infinity for x in range(1, N): if SumDigits(x) + SumDigits(N - x) < min: min = SumDigits(x) + SumDigits(N - x) print(min)
N = int(eval(input())) def SumDigits(num): sum = 0 while True: sum += num % 10 num //= 10 if num == 0: break return sum infinity = float('inf') min = infinity for x in range(1, N//2 + 1): #print('============') #print(x, N - x) #print(SumDigits(x) + SumDigits(N - x)) if SumDigits(x) + SumDigits(N - x) < min: min = SumDigits(x) + SumDigits(N - x) print(min)
18
21
346
448
N = int(eval(input())) def SumDigits(num): sum = 0 while True: sum += num % 10 num //= 10 if num == 0: break return sum infinity = float("inf") min = infinity for x in range(1, N): if SumDigits(x) + SumDigits(N - x) < min: min = SumDigits(x) + SumDigits(N - x) print(min)
N = int(eval(input())) def SumDigits(num): sum = 0 while True: sum += num % 10 num //= 10 if num == 0: break return sum infinity = float("inf") min = infinity for x in range(1, N // 2 + 1): # print('============') # print(x, N - x) # print(SumDigits(x) + SumDigits(N - x)) if SumDigits(x) + SumDigits(N - x) < min: min = SumDigits(x) + SumDigits(N - x) print(min)
false
14.285714
[ "-for x in range(1, N):", "+for x in range(1, N // 2 + 1):", "+ # print('============')", "+ # print(x, N - x)", "+ # print(SumDigits(x) + SumDigits(N - x))" ]
false
0.052635
0.048801
1.07857
[ "s995139940", "s249667414" ]
u627600101
p02722
python
s461134496
s321084004
330
96
20,132
9,404
Accepted
Accepted
70.91
N = int(eval(input())) originalN = 0 +N if N == 2: print((1)) exit() ans = 0 primenum = [2] count = [0 for _ in range(int(N**0.5)+2)] for k in range(3, len(count), 2): if count[k] == 0: primenum.append(k) for j in range(k, len(count), k): count[j] = 1 def factorization(n): lis = [] k = 0 while primenum[k] <= n: if n%primenum[k] == 0: c = 0 while n%primenum[k] == 0: n //= primenum[k] c += 1 lis.append([primenum[k], c]) else: k += 1 if k > len(primenum)-1: break if n > 1: lis.append([n, 1]) return lis list1 = factorization(N-1) #print(factorization(N-1)) ans1 = 1 for k in range(len(list1)): ans1*= list1[k][1]+1 ans1 -= 1 ans += ans1 #print(ans1) def operation(K): N = originalN while N%K == 0: N //= K if N%K == 1: return True else: return False list2 = factorization(N) #print(list2) factorlist = [1] for l in range(len(list2)): list3 = [] for j in range(list2[l][1]): for k in range(len(factorlist)): list3.append(factorlist[k]*list2[l][0]**(j+1)) factorlist += list3 factorlist = factorlist[1:-1] #print(factorlist) ans2 = 1 for item in factorlist: if operation(item): #print(item) ans2 +=1 ans += ans2 #print(ans2) print(ans)
N = int(eval(input())) originalN = 0 +N if N == 2: print((1)) exit() ans = 0 """ primenum = [2] count = [0 for _ in range(int(N**0.5)+2)] for k in range(3, len(count), 2): if count[k] == 0: primenum.append(k) for j in range(k, len(count), k): count[j] = 1 def factorization(n): lis = [] k = 0 while primenum[k] <= n: if n%primenum[k] == 0: c = 0 while n%primenum[k] == 0: n //= primenum[k] c += 1 lis.append([primenum[k], c]) else: k += 1 if k > len(primenum)-1: break if n > 1: lis.append([n, 1]) return lis """ def factorization(n): lis = [] if n % 2 == 0: c = 0 while n%2 == 0: n //= 2 c += 1 lis.append([2, c]) k = 3 while k*k <= n: if n%k == 0: c = 0 while n%k == 0: n //= k c += 1 lis.append([k, c]) else: k += 2 if n > 1: lis.append([n, 1]) return lis list1 = factorization(N-1) #print(factorization(N-1)) ans1 = 1 for k in range(len(list1)): ans1*= list1[k][1]+1 ans1 -= 1 ans += ans1 #print(ans1) def operation(K): N = originalN while N%K == 0: N //= K if N%K == 1: return True else: return False list2 = factorization(N) #print(list2) factorlist = [1] for l in range(len(list2)): list3 = [] for j in range(list2[l][1]): for k in range(len(factorlist)): list3.append(factorlist[k]*list2[l][0]**(j+1)) factorlist += list3 factorlist = factorlist[1:-1] #print(factorlist) ans2 = 1 for item in factorlist: if operation(item): #print(item) ans2 +=1 ans += ans2 #print(ans2) print(ans)
75
98
1,360
1,726
N = int(eval(input())) originalN = 0 + N if N == 2: print((1)) exit() ans = 0 primenum = [2] count = [0 for _ in range(int(N**0.5) + 2)] for k in range(3, len(count), 2): if count[k] == 0: primenum.append(k) for j in range(k, len(count), k): count[j] = 1 def factorization(n): lis = [] k = 0 while primenum[k] <= n: if n % primenum[k] == 0: c = 0 while n % primenum[k] == 0: n //= primenum[k] c += 1 lis.append([primenum[k], c]) else: k += 1 if k > len(primenum) - 1: break if n > 1: lis.append([n, 1]) return lis list1 = factorization(N - 1) # print(factorization(N-1)) ans1 = 1 for k in range(len(list1)): ans1 *= list1[k][1] + 1 ans1 -= 1 ans += ans1 # print(ans1) def operation(K): N = originalN while N % K == 0: N //= K if N % K == 1: return True else: return False list2 = factorization(N) # print(list2) factorlist = [1] for l in range(len(list2)): list3 = [] for j in range(list2[l][1]): for k in range(len(factorlist)): list3.append(factorlist[k] * list2[l][0] ** (j + 1)) factorlist += list3 factorlist = factorlist[1:-1] # print(factorlist) ans2 = 1 for item in factorlist: if operation(item): # print(item) ans2 += 1 ans += ans2 # print(ans2) print(ans)
N = int(eval(input())) originalN = 0 + N if N == 2: print((1)) exit() ans = 0 """ primenum = [2] count = [0 for _ in range(int(N**0.5)+2)] for k in range(3, len(count), 2): if count[k] == 0: primenum.append(k) for j in range(k, len(count), k): count[j] = 1 def factorization(n): lis = [] k = 0 while primenum[k] <= n: if n%primenum[k] == 0: c = 0 while n%primenum[k] == 0: n //= primenum[k] c += 1 lis.append([primenum[k], c]) else: k += 1 if k > len(primenum)-1: break if n > 1: lis.append([n, 1]) return lis """ def factorization(n): lis = [] if n % 2 == 0: c = 0 while n % 2 == 0: n //= 2 c += 1 lis.append([2, c]) k = 3 while k * k <= n: if n % k == 0: c = 0 while n % k == 0: n //= k c += 1 lis.append([k, c]) else: k += 2 if n > 1: lis.append([n, 1]) return lis list1 = factorization(N - 1) # print(factorization(N-1)) ans1 = 1 for k in range(len(list1)): ans1 *= list1[k][1] + 1 ans1 -= 1 ans += ans1 # print(ans1) def operation(K): N = originalN while N % K == 0: N //= K if N % K == 1: return True else: return False list2 = factorization(N) # print(list2) factorlist = [1] for l in range(len(list2)): list3 = [] for j in range(list2[l][1]): for k in range(len(factorlist)): list3.append(factorlist[k] * list2[l][0] ** (j + 1)) factorlist += list3 factorlist = factorlist[1:-1] # print(factorlist) ans2 = 1 for item in factorlist: if operation(item): # print(item) ans2 += 1 ans += ans2 # print(ans2) print(ans)
false
23.469388
[ "+\"\"\"", "-count = [0 for _ in range(int(N**0.5) + 2)]", "+count = [0 for _ in range(int(N**0.5)+2)]", "- if count[k] == 0:", "- primenum.append(k)", "- for j in range(k, len(count), k):", "- count[j] = 1", "+ if count[k] == 0:", "+ primenum.append(k)", "+ for j in range(k, len(count), k):", "+ count[j] = 1", "+def factorization(n):", "+ lis = []", "+ k = 0", "+ while primenum[k] <= n:", "+ if n%primenum[k] == 0:", "+ c = 0", "+ while n%primenum[k] == 0:", "+ n //= primenum[k]", "+ c += 1", "+ lis.append([primenum[k], c])", "+ else:", "+ k += 1", "+ if k > len(primenum)-1:", "+ break", "+ if n > 1:", "+ lis.append([n, 1])", "+ return lis", "+\"\"\"", "- k = 0", "- while primenum[k] <= n:", "- if n % primenum[k] == 0:", "+ if n % 2 == 0:", "+ c = 0", "+ while n % 2 == 0:", "+ n //= 2", "+ c += 1", "+ lis.append([2, c])", "+ k = 3", "+ while k * k <= n:", "+ if n % k == 0:", "- while n % primenum[k] == 0:", "- n //= primenum[k]", "+ while n % k == 0:", "+ n //= k", "- lis.append([primenum[k], c])", "+ lis.append([k, c])", "- k += 1", "- if k > len(primenum) - 1:", "- break", "+ k += 2" ]
false
0.447758
0.071398
6.271295
[ "s461134496", "s321084004" ]
u488401358
p02703
python
s165593976
s123780002
1,840
839
241,672
158,144
Accepted
Accepted
54.4
class Dijkstra(): """ ダイクストラ法 重み付きグラフにおける単一始点最短路アルゴリズム * 使用条件 - 負のコストがないこと - 有向グラフ、無向グラフともにOK * 計算量はO(E*log(V)) * ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい """ class Edge(): """ 重み付き有向辺 """ def __init__(self, _to, _cost): self.to = _to self.cost = _cost def __init__(self, V): """ 重み付き有向辺 無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい Args: V(int): 頂点の数 """ self.G = [[] for i in range(V)] # 隣接リストG[u][i] := 頂点uのi個目の隣接辺 self._E = 0 # 辺の数 self._V = V # 頂点の数 @property def E(self): """ 辺数 無向グラフのときは、辺数は有向グラフの倍になる """ return self._E @property def V(self): """ 頂点数 """ return self._V def add(self, _from, _to, _cost): """ 2頂点と、辺のコストを追加する """ self.G[_from].append(self.Edge(_to, _cost)) self._E += 1 def shortest_path(self, s): """ 始点sから頂点iまでの最短路を格納したリストを返す Args: s(int): 始点s Returns: d(list): d[i] := 始点sから頂点iまでの最短コストを格納したリスト。 到達不可の場合、値はfloat("inf") """ import heapq que = [] # プライオリティキュー(ヒープ木) d = [float("inf")] * self.V d[s] = 0 heapq.heappush(que, (0, s)) # 始点の(最短距離, 頂点番号)をヒープに追加する while len(que) != 0: cost, v = heapq.heappop(que) # キューに格納されている最短経路の候補がdの距離よりも大きければ、他の経路で最短経路が存在するので、処理をスキップ if d[v] < cost: continue for i in range(len(self.G[v])): # 頂点vに隣接する各頂点に関して、頂点vを経由した場合の距離を計算し、今までの距離(d)よりも小さければ更新する e = self.G[v][i] # vのi個目の隣接辺e if d[e.to] > d[v] + e.cost: d[e.to] = d[v] + e.cost # dの更新 heapq.heappush(que, (d[e.to], e.to)) # キューに新たな最短経路の候補(最短距離, 頂点番号)の情報をpush return d N,M,S=list(map(int,input().split())) pro=Dijkstra(N*5001) for i in range(0,M): u,v,a,b=list(map(int,input().split())) for j in range(a,5001): pro.add(N*j+u-1,N*(j-a)+v-1,b) pro.add(N*j+v-1,N*(j-a)+u-1,b) for i in range(0,N): c,d=list(map(int,input().split())) for j in range(0,5000): to=min(5000,j+c) pro.add(N*j+i,N*to+i,d) S=min(5000,S) ans=pro.shortest_path(N*S) for i in range(1,N): p=float("inf") for j in range(0,5001): p=min(p,ans[N*j+i]) print(p)
class Dijkstra(): """ ダイクストラ法 重み付きグラフにおける単一始点最短路アルゴリズム * 使用条件 - 負のコストがないこと - 有向グラフ、無向グラフともにOK * 計算量はO(E*log(V)) * ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい """ class Edge(): """ 重み付き有向辺 """ def __init__(self, _to, _cost): self.to = _to self.cost = _cost def __init__(self, V): """ 重み付き有向辺 無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい Args: V(int): 頂点の数 """ self.G = [[] for i in range(V)] # 隣接リストG[u][i] := 頂点uのi個目の隣接辺 self._E = 0 # 辺の数 self._V = V # 頂点の数 @property def E(self): """ 辺数 無向グラフのときは、辺数は有向グラフの倍になる """ return self._E @property def V(self): """ 頂点数 """ return self._V def add(self, _from, _to, _cost): """ 2頂点と、辺のコストを追加する """ self.G[_from].append(self.Edge(_to, _cost)) self._E += 1 def shortest_path(self, s): """ 始点sから頂点iまでの最短路を格納したリストを返す Args: s(int): 始点s Returns: d(list): d[i] := 始点sから頂点iまでの最短コストを格納したリスト。 到達不可の場合、値はfloat("inf") """ import heapq que = [] # プライオリティキュー(ヒープ木) d = [float("inf")] * self.V d[s] = 0 heapq.heappush(que, (0, s)) # 始点の(最短距離, 頂点番号)をヒープに追加する while len(que) != 0: cost, v = heapq.heappop(que) # キューに格納されている最短経路の候補がdの距離よりも大きければ、他の経路で最短経路が存在するので、処理をスキップ if d[v] < cost: continue for i in range(len(self.G[v])): # 頂点vに隣接する各頂点に関して、頂点vを経由した場合の距離を計算し、今までの距離(d)よりも小さければ更新する e = self.G[v][i] # vのi個目の隣接辺e if d[e.to] > d[v] + e.cost: d[e.to] = d[v] + e.cost # dの更新 heapq.heappush(que, (d[e.to], e.to)) # キューに新たな最短経路の候補(最短距離, 頂点番号)の情報をpush return d N,M,S=list(map(int,input().split())) pro=Dijkstra(N*(50*(N-1)+1)) for i in range(0,M): u,v,a,b=list(map(int,input().split())) for j in range(a,50*(N-1)+1): pro.add(N*j+u-1,N*(j-a)+v-1,b) pro.add(N*j+v-1,N*(j-a)+u-1,b) for i in range(0,N): c,d=list(map(int,input().split())) for j in range(0,50*(N-1)): to=min(50*(N-1),j+c) pro.add(N*j+i,N*to+i,d) S=min(50*(N-1),S) ans=pro.shortest_path(N*S) for i in range(1,N): p=float("inf") for j in range(0,50*(N-1)+1): p=min(p,ans[N*j+i]) print(p)
94
94
2,507
2,540
class Dijkstra: """ダイクストラ法 重み付きグラフにおける単一始点最短路アルゴリズム * 使用条件 - 負のコストがないこと - 有向グラフ、無向グラフともにOK * 計算量はO(E*log(V)) * ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい """ class Edge: """重み付き有向辺""" def __init__(self, _to, _cost): self.to = _to self.cost = _cost def __init__(self, V): """重み付き有向辺 無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい Args: V(int): 頂点の数 """ self.G = [[] for i in range(V)] # 隣接リストG[u][i] := 頂点uのi個目の隣接辺 self._E = 0 # 辺の数 self._V = V # 頂点の数 @property def E(self): """辺数 無向グラフのときは、辺数は有向グラフの倍になる """ return self._E @property def V(self): """頂点数""" return self._V def add(self, _from, _to, _cost): """2頂点と、辺のコストを追加する""" self.G[_from].append(self.Edge(_to, _cost)) self._E += 1 def shortest_path(self, s): """始点sから頂点iまでの最短路を格納したリストを返す Args: s(int): 始点s Returns: d(list): d[i] := 始点sから頂点iまでの最短コストを格納したリスト。 到達不可の場合、値はfloat("inf") """ import heapq que = [] # プライオリティキュー(ヒープ木) d = [float("inf")] * self.V d[s] = 0 heapq.heappush(que, (0, s)) # 始点の(最短距離, 頂点番号)をヒープに追加する while len(que) != 0: cost, v = heapq.heappop(que) # キューに格納されている最短経路の候補がdの距離よりも大きければ、他の経路で最短経路が存在するので、処理をスキップ if d[v] < cost: continue for i in range(len(self.G[v])): # 頂点vに隣接する各頂点に関して、頂点vを経由した場合の距離を計算し、今までの距離(d)よりも小さければ更新する e = self.G[v][i] # vのi個目の隣接辺e if d[e.to] > d[v] + e.cost: d[e.to] = d[v] + e.cost # dの更新 heapq.heappush( que, (d[e.to], e.to) ) # キューに新たな最短経路の候補(最短距離, 頂点番号)の情報をpush return d N, M, S = list(map(int, input().split())) pro = Dijkstra(N * 5001) for i in range(0, M): u, v, a, b = list(map(int, input().split())) for j in range(a, 5001): pro.add(N * j + u - 1, N * (j - a) + v - 1, b) pro.add(N * j + v - 1, N * (j - a) + u - 1, b) for i in range(0, N): c, d = list(map(int, input().split())) for j in range(0, 5000): to = min(5000, j + c) pro.add(N * j + i, N * to + i, d) S = min(5000, S) ans = pro.shortest_path(N * S) for i in range(1, N): p = float("inf") for j in range(0, 5001): p = min(p, ans[N * j + i]) print(p)
class Dijkstra: """ダイクストラ法 重み付きグラフにおける単一始点最短路アルゴリズム * 使用条件 - 負のコストがないこと - 有向グラフ、無向グラフともにOK * 計算量はO(E*log(V)) * ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい """ class Edge: """重み付き有向辺""" def __init__(self, _to, _cost): self.to = _to self.cost = _cost def __init__(self, V): """重み付き有向辺 無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい Args: V(int): 頂点の数 """ self.G = [[] for i in range(V)] # 隣接リストG[u][i] := 頂点uのi個目の隣接辺 self._E = 0 # 辺の数 self._V = V # 頂点の数 @property def E(self): """辺数 無向グラフのときは、辺数は有向グラフの倍になる """ return self._E @property def V(self): """頂点数""" return self._V def add(self, _from, _to, _cost): """2頂点と、辺のコストを追加する""" self.G[_from].append(self.Edge(_to, _cost)) self._E += 1 def shortest_path(self, s): """始点sから頂点iまでの最短路を格納したリストを返す Args: s(int): 始点s Returns: d(list): d[i] := 始点sから頂点iまでの最短コストを格納したリスト。 到達不可の場合、値はfloat("inf") """ import heapq que = [] # プライオリティキュー(ヒープ木) d = [float("inf")] * self.V d[s] = 0 heapq.heappush(que, (0, s)) # 始点の(最短距離, 頂点番号)をヒープに追加する while len(que) != 0: cost, v = heapq.heappop(que) # キューに格納されている最短経路の候補がdの距離よりも大きければ、他の経路で最短経路が存在するので、処理をスキップ if d[v] < cost: continue for i in range(len(self.G[v])): # 頂点vに隣接する各頂点に関して、頂点vを経由した場合の距離を計算し、今までの距離(d)よりも小さければ更新する e = self.G[v][i] # vのi個目の隣接辺e if d[e.to] > d[v] + e.cost: d[e.to] = d[v] + e.cost # dの更新 heapq.heappush( que, (d[e.to], e.to) ) # キューに新たな最短経路の候補(最短距離, 頂点番号)の情報をpush return d N, M, S = list(map(int, input().split())) pro = Dijkstra(N * (50 * (N - 1) + 1)) for i in range(0, M): u, v, a, b = list(map(int, input().split())) for j in range(a, 50 * (N - 1) + 1): pro.add(N * j + u - 1, N * (j - a) + v - 1, b) pro.add(N * j + v - 1, N * (j - a) + u - 1, b) for i in range(0, N): c, d = list(map(int, input().split())) for j in range(0, 50 * (N - 1)): to = min(50 * (N - 1), j + c) pro.add(N * j + i, N * to + i, d) S = min(50 * (N - 1), S) ans = pro.shortest_path(N * S) for i in range(1, N): p = float("inf") for j in range(0, 50 * (N - 1) + 1): p = min(p, ans[N * j + i]) print(p)
false
0
[ "-pro = Dijkstra(N * 5001)", "+pro = Dijkstra(N * (50 * (N - 1) + 1))", "- for j in range(a, 5001):", "+ for j in range(a, 50 * (N - 1) + 1):", "- for j in range(0, 5000):", "- to = min(5000, j + c)", "+ for j in range(0, 50 * (N - 1)):", "+ to = min(50 * (N - 1), j + c)", "-S = min(5000, S)", "+S = min(50 * (N - 1), S)", "- for j in range(0, 5001):", "+ for j in range(0, 50 * (N - 1) + 1):" ]
false
0.504174
0.087032
5.793002
[ "s165593976", "s123780002" ]
u341087021
p03721
python
s161677384
s435788654
198
175
5,744
5,740
Accepted
Accepted
11.62
import sys r = [0]*100000 n,k = [int(x) for x in sys.stdin.readline().split()] for i in range(n): a, b = [int(x) for x in sys.stdin.readline().split()] r[a-1] += b c = 0 for i,j in enumerate(r): c += j if c >= k: print((i+1)) break
import sys r = [0]*(100000+1) n,k = [int(x) for x in sys.stdin.readline().split()] for i in range(n): a, b = [int(x) for x in sys.stdin.readline().split()] r[a] += b c = 0 for i,j in enumerate(r): c += j if c >= k: print(i) break
12
12
248
248
import sys r = [0] * 100000 n, k = [int(x) for x in sys.stdin.readline().split()] for i in range(n): a, b = [int(x) for x in sys.stdin.readline().split()] r[a - 1] += b c = 0 for i, j in enumerate(r): c += j if c >= k: print((i + 1)) break
import sys r = [0] * (100000 + 1) n, k = [int(x) for x in sys.stdin.readline().split()] for i in range(n): a, b = [int(x) for x in sys.stdin.readline().split()] r[a] += b c = 0 for i, j in enumerate(r): c += j if c >= k: print(i) break
false
0
[ "-r = [0] * 100000", "+r = [0] * (100000 + 1)", "- r[a - 1] += b", "+ r[a] += b", "- print((i + 1))", "+ print(i)" ]
false
0.049384
0.092107
0.536165
[ "s161677384", "s435788654" ]
u068727970
p03805
python
s543636473
s937604722
98
38
9,568
9,004
Accepted
Accepted
61.22
from collections import deque import copy # https://atcoder.jp/contests/abc054/tasks/abc054_c # n!の全探索が答えというのは知っているが、自分の開放の誤りを見つけるために自分のやり方でといてみる。 N, M = list(map(int, input().split())) V = [[] for _ in range(N)] cont = [0 for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) V[a-1].append([b, copy.deepcopy(cont)]) V[b-1].append([a, copy.deepcopy(cont)]) # solution q = deque() q.append([1, copy.deepcopy(cont)]) count = 0 while q: c_v = q.pop() c_v[1][c_v[0]-1] = 1 next_vs = V[c_v[0]-1] ifComplete = 1 for v in next_vs: if c_v[1][v[0]-1] == 1: continue else: ifComplete = 0 # ここで続くvの探索が始まる時に全て訪問されていればcountを増やす。 # その状態をどうやって管理すればいい? v[1] = copy.deepcopy(c_v[1]) q.append(v) # 遷移先のノードが存在しない場合 if ifComplete: flag = 1 for x in c_v[1]: if x == 0: flag = 0 break if flag: count += 1 print(count)
import itertools N, M = list(map(int, input().split())) V = [[] for _ in range(N)] bag = set() for _ in range(M): a, b = list(map(int, input().split())) bag.add(a) bag.add(b) V[a-1].append(b) V[b-1].append(a) count = 0 for c in itertools.permutations(bag): if not c[0] == 1: continue flag = False for i in range(N-1): if not c[i+1] in V[c[i]-1]: flag = True break if not flag: count += 1 print(count)
41
24
1,041
498
from collections import deque import copy # https://atcoder.jp/contests/abc054/tasks/abc054_c # n!の全探索が答えというのは知っているが、自分の開放の誤りを見つけるために自分のやり方でといてみる。 N, M = list(map(int, input().split())) V = [[] for _ in range(N)] cont = [0 for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) V[a - 1].append([b, copy.deepcopy(cont)]) V[b - 1].append([a, copy.deepcopy(cont)]) # solution q = deque() q.append([1, copy.deepcopy(cont)]) count = 0 while q: c_v = q.pop() c_v[1][c_v[0] - 1] = 1 next_vs = V[c_v[0] - 1] ifComplete = 1 for v in next_vs: if c_v[1][v[0] - 1] == 1: continue else: ifComplete = 0 # ここで続くvの探索が始まる時に全て訪問されていればcountを増やす。 # その状態をどうやって管理すればいい? v[1] = copy.deepcopy(c_v[1]) q.append(v) # 遷移先のノードが存在しない場合 if ifComplete: flag = 1 for x in c_v[1]: if x == 0: flag = 0 break if flag: count += 1 print(count)
import itertools N, M = list(map(int, input().split())) V = [[] for _ in range(N)] bag = set() for _ in range(M): a, b = list(map(int, input().split())) bag.add(a) bag.add(b) V[a - 1].append(b) V[b - 1].append(a) count = 0 for c in itertools.permutations(bag): if not c[0] == 1: continue flag = False for i in range(N - 1): if not c[i + 1] in V[c[i] - 1]: flag = True break if not flag: count += 1 print(count)
false
41.463415
[ "-from collections import deque", "-import copy", "+import itertools", "-# https://atcoder.jp/contests/abc054/tasks/abc054_c", "-# n!の全探索が答えというのは知っているが、自分の開放の誤りを見つけるために自分のやり方でといてみる。", "-cont = [0 for _ in range(N)]", "+bag = set()", "- V[a - 1].append([b, copy.deepcopy(cont)])", "- V[b - 1].append([a, copy.deepcopy(cont)])", "-# solution", "-q = deque()", "-q.append([1, copy.deepcopy(cont)])", "+ bag.add(a)", "+ bag.add(b)", "+ V[a - 1].append(b)", "+ V[b - 1].append(a)", "-while q:", "- c_v = q.pop()", "- c_v[1][c_v[0] - 1] = 1", "- next_vs = V[c_v[0] - 1]", "- ifComplete = 1", "- for v in next_vs:", "- if c_v[1][v[0] - 1] == 1:", "- continue", "- else:", "- ifComplete = 0", "- # ここで続くvの探索が始まる時に全て訪問されていればcountを増やす。", "- # その状態をどうやって管理すればいい?", "- v[1] = copy.deepcopy(c_v[1])", "- q.append(v)", "- # 遷移先のノードが存在しない場合", "- if ifComplete:", "- flag = 1", "- for x in c_v[1]:", "- if x == 0:", "- flag = 0", "- break", "- if flag:", "- count += 1", "+for c in itertools.permutations(bag):", "+ if not c[0] == 1:", "+ continue", "+ flag = False", "+ for i in range(N - 1):", "+ if not c[i + 1] in V[c[i] - 1]:", "+ flag = True", "+ break", "+ if not flag:", "+ count += 1" ]
false
0.04517
0.042877
1.05349
[ "s543636473", "s937604722" ]
u179169725
p03078
python
s018618288
s938360496
584
79
4,116
5,972
Accepted
Accepted
86.47
# ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方 # これもなかなか早い # ヒープは追加も要素の取り出しもO(log n)で住むので、 # 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが # not in があるのでO(n K log n)では? # pythonのヒープは使い方に癖があるのでこの機会に習得しよう import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) X, Y, Z, K = read_ints() A = read_ints() B = read_ints() C = read_ints() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) heap = [] # ヒープといっても順序を工夫したただのリスト from heapq import heapify, heappop, heappush, heappushpop heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0)) ans = [] for k_th in range(1, K+1): heap_max, i, j, k = heappop(heap) # print(heap_max) ans.append(-heap_max) for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]): i_new, j_new, k_new = i + di, j + dj, k + dk if i_new >= X or j_new >= Y or k_new >= Z: continue tmp = (-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new) if tmp in heap: # ここが計算量がおおい continue heappush(heap, tmp) # print(heap) print(*ans, sep='\n')
# ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方 # これもなかなか早い # ヒープは追加も要素の取り出しもO(log n)で住むので、 # 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが # not in があるのでO(n K log n)では? # pythonのヒープは使い方に癖があるのでこの機会に習得しよう import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) X, Y, Z, K = read_ints() A = read_ints() B = read_ints() C = read_ints() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) heap = [] # ヒープといっても順序を工夫したただのリスト from queue import PriorityQueue heap = PriorityQueue() heap.put((-(A[0] + B[0] + C[0]), 0, 0, 0)) considerd = set() ans = [] for k_th in range(1, K+1): heap_max, i, j, k = heap.get() # print(heap_max) ans.append(-heap_max) for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]): i_new, j_new, k_new = i + di, j + dj, k + dk if i_new >= X or j_new >= Y or k_new >= Z: continue if (i_new, j_new, k_new) in considerd: continue considerd.add((i_new, j_new, k_new)) heap.put((-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new)) print(*ans, sep='\n')
45
47
1,125
1,142
# ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方 # これもなかなか早い # ヒープは追加も要素の取り出しもO(log n)で住むので、 # 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが # not in があるのでO(n K log n)では? # pythonのヒープは使い方に癖があるのでこの機会に習得しよう import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) X, Y, Z, K = read_ints() A = read_ints() B = read_ints() C = read_ints() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) heap = [] # ヒープといっても順序を工夫したただのリスト from heapq import heapify, heappop, heappush, heappushpop heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0)) ans = [] for k_th in range(1, K + 1): heap_max, i, j, k = heappop(heap) # print(heap_max) ans.append(-heap_max) for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]): i_new, j_new, k_new = i + di, j + dj, k + dk if i_new >= X or j_new >= Y or k_new >= Z: continue tmp = (-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new) if tmp in heap: # ここが計算量がおおい continue heappush(heap, tmp) # print(heap) print(*ans, sep="\n")
# ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方 # これもなかなか早い # ヒープは追加も要素の取り出しもO(log n)で住むので、 # 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが # not in があるのでO(n K log n)では? # pythonのヒープは使い方に癖があるのでこの機会に習得しよう import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) X, Y, Z, K = read_ints() A = read_ints() B = read_ints() C = read_ints() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) heap = [] # ヒープといっても順序を工夫したただのリスト from queue import PriorityQueue heap = PriorityQueue() heap.put((-(A[0] + B[0] + C[0]), 0, 0, 0)) considerd = set() ans = [] for k_th in range(1, K + 1): heap_max, i, j, k = heap.get() # print(heap_max) ans.append(-heap_max) for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]): i_new, j_new, k_new = i + di, j + dj, k + dk if i_new >= X or j_new >= Y or k_new >= Z: continue if (i_new, j_new, k_new) in considerd: continue considerd.add((i_new, j_new, k_new)) heap.put((-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new)) print(*ans, sep="\n")
false
4.255319
[ "-from heapq import heapify, heappop, heappush, heappushpop", "+from queue import PriorityQueue", "-heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0))", "+heap = PriorityQueue()", "+heap.put((-(A[0] + B[0] + C[0]), 0, 0, 0))", "+considerd = set()", "- heap_max, i, j, k = heappop(heap)", "+ heap_max, i, j, k = heap.get()", "- tmp = (-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new)", "- if tmp in heap: # ここが計算量がおおい", "+ if (i_new, j_new, k_new) in considerd:", "- heappush(heap, tmp)", "- # print(heap)", "+ considerd.add((i_new, j_new, k_new))", "+ heap.put((-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new))" ]
false
0.042147
0.046147
0.913335
[ "s018618288", "s938360496" ]
u260980560
p00009
python
s626843424
s735199469
820
460
67,888
23,520
Accepted
Accepted
43.9
p = [1] n = [0,0] c = 0 for i in range(1,1000000): p.append(0) for i in range(2,1000000): if p[i]==1 : n.append(c) continue c += 1 n.append(c) for j in range(i*i,1000000,i): if p[j]==0 : p[j]=1 while True: try: nn = int(input()) print(n[nn]) except(EOFError) : break
M = 10**6 p = [0]*(M+60) sM = M**0.5 for x in range(1, int(sM/2)+1): v = 4*x*x + 1; y = 8 while v <= M: if v % 12 != 9: # v % 12 in [1, 5] p[v] ^= 1 v += y; y += 8 for x in range(1, int(sM/3**0.5)+1, 2): v = 3*x*x + 4; y = 12 while v <= M: if v % 12 == 7: p[v] ^= 1 v += y; y += 8 for x in range(2, int(sM/2**0.5)+1): v = 2*x*(x+1)-1; y = 4*x-8 while 0 <= y and v <= M: if v % 12 == 11: p[v] ^= 1 v += y; y -= 8 for n in range(5, int(sM)+1): if p[n]: for z in range(n*n, M, n*n): p[z] = 0 p[2] = p[3] = 1 c = [0]*M cnt = 0 for i in range(M): if p[i]: cnt += 1 c[i] = cnt while 1: try: n = int(eval(input())) except: break print((c[n]))
18
42
354
849
p = [1] n = [0, 0] c = 0 for i in range(1, 1000000): p.append(0) for i in range(2, 1000000): if p[i] == 1: n.append(c) continue c += 1 n.append(c) for j in range(i * i, 1000000, i): if p[j] == 0: p[j] = 1 while True: try: nn = int(input()) print(n[nn]) except (EOFError): break
M = 10**6 p = [0] * (M + 60) sM = M**0.5 for x in range(1, int(sM / 2) + 1): v = 4 * x * x + 1 y = 8 while v <= M: if v % 12 != 9: # v % 12 in [1, 5] p[v] ^= 1 v += y y += 8 for x in range(1, int(sM / 3**0.5) + 1, 2): v = 3 * x * x + 4 y = 12 while v <= M: if v % 12 == 7: p[v] ^= 1 v += y y += 8 for x in range(2, int(sM / 2**0.5) + 1): v = 2 * x * (x + 1) - 1 y = 4 * x - 8 while 0 <= y and v <= M: if v % 12 == 11: p[v] ^= 1 v += y y -= 8 for n in range(5, int(sM) + 1): if p[n]: for z in range(n * n, M, n * n): p[z] = 0 p[2] = p[3] = 1 c = [0] * M cnt = 0 for i in range(M): if p[i]: cnt += 1 c[i] = cnt while 1: try: n = int(eval(input())) except: break print((c[n]))
false
57.142857
[ "-p = [1]", "-n = [0, 0]", "-c = 0", "-for i in range(1, 1000000):", "- p.append(0)", "-for i in range(2, 1000000):", "- if p[i] == 1:", "- n.append(c)", "- continue", "- c += 1", "- n.append(c)", "- for j in range(i * i, 1000000, i):", "- if p[j] == 0:", "- p[j] = 1", "-while True:", "+M = 10**6", "+p = [0] * (M + 60)", "+sM = M**0.5", "+for x in range(1, int(sM / 2) + 1):", "+ v = 4 * x * x + 1", "+ y = 8", "+ while v <= M:", "+ if v % 12 != 9: # v % 12 in [1, 5]", "+ p[v] ^= 1", "+ v += y", "+ y += 8", "+for x in range(1, int(sM / 3**0.5) + 1, 2):", "+ v = 3 * x * x + 4", "+ y = 12", "+ while v <= M:", "+ if v % 12 == 7:", "+ p[v] ^= 1", "+ v += y", "+ y += 8", "+for x in range(2, int(sM / 2**0.5) + 1):", "+ v = 2 * x * (x + 1) - 1", "+ y = 4 * x - 8", "+ while 0 <= y and v <= M:", "+ if v % 12 == 11:", "+ p[v] ^= 1", "+ v += y", "+ y -= 8", "+for n in range(5, int(sM) + 1):", "+ if p[n]:", "+ for z in range(n * n, M, n * n):", "+ p[z] = 0", "+p[2] = p[3] = 1", "+c = [0] * M", "+cnt = 0", "+for i in range(M):", "+ if p[i]:", "+ cnt += 1", "+ c[i] = cnt", "+while 1:", "- nn = int(input())", "- print(n[nn])", "- except (EOFError):", "+ n = int(eval(input()))", "+ except:", "+ print((c[n]))" ]
false
1.103652
0.858862
1.285017
[ "s626843424", "s735199469" ]
u057964173
p03478
python
s422916227
s953536382
41
30
3,404
3,064
Accepted
Accepted
26.83
import sys def input(): return sys.stdin.readline().strip() def resolve(): n,a,b=list(map(int, input().split())) l=[] for i in range(1,n+1): cnt=0 for j in range(len(str(i))): cnt+=int(str(i)[j]) if a<=cnt<=b: l.append(i) print((sum(l))) resolve()
import sys def input(): return sys.stdin.readline().strip() def resolve(): n,a,b=list(map(int, input().split())) ans=0 for i in range(1,n+1): cnt=0 for j in str(i): cnt+=int(j) if a<=cnt<=b: ans+=i print(ans) resolve()
14
15
317
292
import sys def input(): return sys.stdin.readline().strip() def resolve(): n, a, b = list(map(int, input().split())) l = [] for i in range(1, n + 1): cnt = 0 for j in range(len(str(i))): cnt += int(str(i)[j]) if a <= cnt <= b: l.append(i) print((sum(l))) resolve()
import sys def input(): return sys.stdin.readline().strip() def resolve(): n, a, b = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): cnt = 0 for j in str(i): cnt += int(j) if a <= cnt <= b: ans += i print(ans) resolve()
false
6.666667
[ "- l = []", "+ ans = 0", "- for j in range(len(str(i))):", "- cnt += int(str(i)[j])", "+ for j in str(i):", "+ cnt += int(j)", "- l.append(i)", "- print((sum(l)))", "+ ans += i", "+ print(ans)" ]
false
0.087431
0.035532
2.460621
[ "s422916227", "s953536382" ]
u505564549
p02606
python
s162077089
s024887382
71
62
61,628
61,824
Accepted
Accepted
12.68
import sys input = sys.stdin.readline l,r,d=list(map(int,input().split())) ans = 0 for i in range(l,r+1): if i%d==0: ans+=1 print(ans)
import sys input = sys.stdin.readline l,r,d=list(map(int,input().split())) v1 = l//d if l%d==0: v1-=1 v2 = r//d print((v2-v1))
8
9
148
132
import sys input = sys.stdin.readline l, r, d = list(map(int, input().split())) ans = 0 for i in range(l, r + 1): if i % d == 0: ans += 1 print(ans)
import sys input = sys.stdin.readline l, r, d = list(map(int, input().split())) v1 = l // d if l % d == 0: v1 -= 1 v2 = r // d print((v2 - v1))
false
11.111111
[ "-ans = 0", "-for i in range(l, r + 1):", "- if i % d == 0:", "- ans += 1", "-print(ans)", "+v1 = l // d", "+if l % d == 0:", "+ v1 -= 1", "+v2 = r // d", "+print((v2 - v1))" ]
false
0.092976
0.159166
0.584144
[ "s162077089", "s024887382" ]
u588341295
p03343
python
s528244883
s107277058
553
508
53,724
52,188
Accepted
Accepted
8.14
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 N, K, Q = MAP() A = LIST() ans = INF # 使う要素の最小値とする値xを全探索 for x in A: # 数列Aをx未満の値で区切った数列Bを作る B = [] tmp = [] for i in range(N): if A[i] >= x: tmp.append(A[i]) else: B.append(tmp) tmp = [] B.append(tmp) # 数列B内の各数列から、使える要素を集める C = [] for li in B: m = len(li) li.sort() C += li[:max(m-K+1, 0)] # 集めた要素からQ個をクエリで使うので、小さい方からQ番目が使う要素の最大値y C.sort() if len(C) < Q: continue y = C[Q-1] ans = min(ans, y - x) print(ans)
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 N, K, Q = MAP() A = LIST() ans = INF # 使う要素の最小値とする値xを全探索 for x in A: # 数列Aをx未満の値で区切った数列Bを作る B = [] tmp = [] for i in range(N): if A[i] >= x: tmp.append(A[i]) else: B.append(tmp) tmp = [] B.append(tmp) # 数列B内の各数列から、使える要素を集める C = [] for li in B: m = len(li) if m-K+1 >= 1: li.sort() C += li[:m-K+1] # 集めた要素からQ個をクエリで使うので、小さい方からQ番目が使う要素の最大値y C.sort() if len(C) < Q: continue y = C[Q-1] ans = min(ans, y - x) print(ans)
49
50
1,271
1,295
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 N, K, Q = MAP() A = LIST() ans = INF # 使う要素の最小値とする値xを全探索 for x in A: # 数列Aをx未満の値で区切った数列Bを作る B = [] tmp = [] for i in range(N): if A[i] >= x: tmp.append(A[i]) else: B.append(tmp) tmp = [] B.append(tmp) # 数列B内の各数列から、使える要素を集める C = [] for li in B: m = len(li) li.sort() C += li[: max(m - K + 1, 0)] # 集めた要素からQ個をクエリで使うので、小さい方からQ番目が使う要素の最大値y C.sort() if len(C) < Q: continue y = C[Q - 1] ans = min(ans, y - x) print(ans)
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 N, K, Q = MAP() A = LIST() ans = INF # 使う要素の最小値とする値xを全探索 for x in A: # 数列Aをx未満の値で区切った数列Bを作る B = [] tmp = [] for i in range(N): if A[i] >= x: tmp.append(A[i]) else: B.append(tmp) tmp = [] B.append(tmp) # 数列B内の各数列から、使える要素を集める C = [] for li in B: m = len(li) if m - K + 1 >= 1: li.sort() C += li[: m - K + 1] # 集めた要素からQ個をクエリで使うので、小さい方からQ番目が使う要素の最大値y C.sort() if len(C) < Q: continue y = C[Q - 1] ans = min(ans, y - x) print(ans)
false
2
[ "- li.sort()", "- C += li[: max(m - K + 1, 0)]", "+ if m - K + 1 >= 1:", "+ li.sort()", "+ C += li[: m - K + 1]" ]
false
0.048589
0.066795
0.727432
[ "s528244883", "s107277058" ]
u619144316
p03274
python
s538877271
s556253364
97
87
14,660
20,108
Accepted
Accepted
10.31
import bisect N, K = list(map(int,input().split())) X = list(map(int,input().split())) s = bisect.bisect_left(X,0) if 0 in X: K -= 1 else: bisect.insort_left(X,0) N += 1 MIN = 2 * 10**9 for i in range(K+1): if s - K + i >= 0 and s + i <N: f = X[s -K+i] l = X[s+i] if abs(f) < abs(l): ans = abs(f) * 2 + abs(l) else: ans = abs(l) * 2 + abs(f) MIN =min(MIN,ans) print(MIN)
def main(): n,k = list(map(int,input().split())) X = list(map(int,input().split())) ans = 10**9 for i in range(n-k+1): t1 = abs(X[i]) + abs(X[i] - X[i+k-1]) t2 = abs(X[i+k-1]) + abs(X[i] - X[i+k-1]) t = min(t1,t2) ans = min(ans,t) print(ans) main()
24
18
471
318
import bisect N, K = list(map(int, input().split())) X = list(map(int, input().split())) s = bisect.bisect_left(X, 0) if 0 in X: K -= 1 else: bisect.insort_left(X, 0) N += 1 MIN = 2 * 10**9 for i in range(K + 1): if s - K + i >= 0 and s + i < N: f = X[s - K + i] l = X[s + i] if abs(f) < abs(l): ans = abs(f) * 2 + abs(l) else: ans = abs(l) * 2 + abs(f) MIN = min(MIN, ans) print(MIN)
def main(): n, k = list(map(int, input().split())) X = list(map(int, input().split())) ans = 10**9 for i in range(n - k + 1): t1 = abs(X[i]) + abs(X[i] - X[i + k - 1]) t2 = abs(X[i + k - 1]) + abs(X[i] - X[i + k - 1]) t = min(t1, t2) ans = min(ans, t) print(ans) main()
false
25
[ "-import bisect", "+def main():", "+ n, k = list(map(int, input().split()))", "+ X = list(map(int, input().split()))", "+ ans = 10**9", "+ for i in range(n - k + 1):", "+ t1 = abs(X[i]) + abs(X[i] - X[i + k - 1])", "+ t2 = abs(X[i + k - 1]) + abs(X[i] - X[i + k - 1])", "+ t = min(t1, t2)", "+ ans = min(ans, t)", "+ print(ans)", "-N, K = list(map(int, input().split()))", "-X = list(map(int, input().split()))", "-s = bisect.bisect_left(X, 0)", "-if 0 in X:", "- K -= 1", "-else:", "- bisect.insort_left(X, 0)", "- N += 1", "-MIN = 2 * 10**9", "-for i in range(K + 1):", "- if s - K + i >= 0 and s + i < N:", "- f = X[s - K + i]", "- l = X[s + i]", "- if abs(f) < abs(l):", "- ans = abs(f) * 2 + abs(l)", "- else:", "- ans = abs(l) * 2 + abs(f)", "- MIN = min(MIN, ans)", "-print(MIN)", "+", "+main()" ]
false
0.112348
0.048495
2.316692
[ "s538877271", "s556253364" ]
u145950990
p03546
python
s850743702
s108547392
707
201
45,532
40,412
Accepted
Accepted
71.57
import itertools import collections h,w = list(map(int,input().split())) c = [list(map(int,input().split())) for _ in range(10)] a = [list(map(int,input().split())) for _ in range(h)] a = list(itertools.chain.from_iterable(a)) b = collections.Counter(a) ans = 0 def bfs(x): if x[-1]==1: global s buf = 0 for i in range(len(x)-1): buf += c[x[i]][x[i+1]] s = min(s,buf) else: for i in range(10): if not i in x: bfs(x+[i]) for i in b: if not i in [1,-1]: s = 10**9 bfs([i]) ans += s*b[i] print(ans)
h,w = list(map(int,input().split())) c = [list(map(int,input().split())) for _ in range(10)] a = [list(map(int,input().split())) for _ in range(h)] n = 10 for k in range(n): for i in range(n): for j in range(n): c[i][j] = min(c[i][j],c[i][k]+c[k][j]) ans = 0 for i in a: for j in i: if j!=-1: ans += c[j][1] print(ans)
27
13
633
360
import itertools import collections h, w = list(map(int, input().split())) c = [list(map(int, input().split())) for _ in range(10)] a = [list(map(int, input().split())) for _ in range(h)] a = list(itertools.chain.from_iterable(a)) b = collections.Counter(a) ans = 0 def bfs(x): if x[-1] == 1: global s buf = 0 for i in range(len(x) - 1): buf += c[x[i]][x[i + 1]] s = min(s, buf) else: for i in range(10): if not i in x: bfs(x + [i]) for i in b: if not i in [1, -1]: s = 10**9 bfs([i]) ans += s * b[i] print(ans)
h, w = list(map(int, input().split())) c = [list(map(int, input().split())) for _ in range(10)] a = [list(map(int, input().split())) for _ in range(h)] n = 10 for k in range(n): for i in range(n): for j in range(n): c[i][j] = min(c[i][j], c[i][k] + c[k][j]) ans = 0 for i in a: for j in i: if j != -1: ans += c[j][1] print(ans)
false
51.851852
[ "-import itertools", "-import collections", "-", "-a = list(itertools.chain.from_iterable(a))", "-b = collections.Counter(a)", "+n = 10", "+for k in range(n):", "+ for i in range(n):", "+ for j in range(n):", "+ c[i][j] = min(c[i][j], c[i][k] + c[k][j])", "-", "-", "-def bfs(x):", "- if x[-1] == 1:", "- global s", "- buf = 0", "- for i in range(len(x) - 1):", "- buf += c[x[i]][x[i + 1]]", "- s = min(s, buf)", "- else:", "- for i in range(10):", "- if not i in x:", "- bfs(x + [i])", "-", "-", "-for i in b:", "- if not i in [1, -1]:", "- s = 10**9", "- bfs([i])", "- ans += s * b[i]", "+for i in a:", "+ for j in i:", "+ if j != -1:", "+ ans += c[j][1]" ]
false
0.687838
0.038657
17.793368
[ "s850743702", "s108547392" ]
u150984829
p00470
python
s220924778
s773980275
70
60
7,832
7,832
Accepted
Accepted
14.29
for e in iter(input,'0 0'): w,h=list(map(int,e.split())) M=[[[1,0]*2 for _ in[0]*h]for _ in[0]*w] for i in range(1,w): for j in range(1,h): a,b=M[i-1][j][:2] c,d=M[i][j-1][2:] M[i][j]=[d,a+b,b,c+d] print(((sum(M[w-2][h-1][:2])+sum(M[w-1][h-2][2:]))%10**5))
for e in iter(input,'0 0'): w,h=list(map(int,e.split())) M=[[[1,0]*2 for _ in[0]*h]for _ in[0]*w] for i in range(1,w): for j in range(1,h): a,b,c,d=[*M[i-1][j][:2],*M[i][j-1][2:]] M[i][j]=[d,a+b,b,c+d] print(((sum(M[w-2][h-1][:2])+sum(M[w-1][h-2][2:]))%10**5))
9
8
272
272
for e in iter(input, "0 0"): w, h = list(map(int, e.split())) M = [[[1, 0] * 2 for _ in [0] * h] for _ in [0] * w] for i in range(1, w): for j in range(1, h): a, b = M[i - 1][j][:2] c, d = M[i][j - 1][2:] M[i][j] = [d, a + b, b, c + d] print(((sum(M[w - 2][h - 1][:2]) + sum(M[w - 1][h - 2][2:])) % 10**5))
for e in iter(input, "0 0"): w, h = list(map(int, e.split())) M = [[[1, 0] * 2 for _ in [0] * h] for _ in [0] * w] for i in range(1, w): for j in range(1, h): a, b, c, d = [*M[i - 1][j][:2], *M[i][j - 1][2:]] M[i][j] = [d, a + b, b, c + d] print(((sum(M[w - 2][h - 1][:2]) + sum(M[w - 1][h - 2][2:])) % 10**5))
false
11.111111
[ "- a, b = M[i - 1][j][:2]", "- c, d = M[i][j - 1][2:]", "+ a, b, c, d = [*M[i - 1][j][:2], *M[i][j - 1][2:]]" ]
false
0.10303
0.043796
2.352514
[ "s220924778", "s773980275" ]
u042885182
p02394
python
s788431415
s925843859
30
20
7,664
7,660
Accepted
Accepted
33.33
# coding: utf-8 # Here your code ! import math def func(): try: line=input().rstrip() numbers=line.split(" ") width=float(numbers[0]) height=float(numbers[1]) x=float(numbers[2]) y=float(numbers[3]) r=abs(float(numbers[4])) except: print("input error") return -1 wsign=math.copysign(1,width) hsign=math.copysign(1,height) result=(wsign*x+r <= wsign*width) result=result and (wsign*x-r >= 0) result=result and (hsign*y+r <= hsign*height) result=result and (hsign*y-r >= 0) if result: print("Yes") else: print("No") func()
# coding: utf-8 # Here your code ! import math def func(): try: line=input().rstrip() numbers=line.split(" ") width=float(numbers[0]) height=float(numbers[1]) x=float(numbers[2]) y=float(numbers[3]) r=abs(float(numbers[4])) except: print("input error") return -1 wsign=math.copysign(1,width) hsign=math.copysign(1,height) result="No" if(wsign*x+r <= wsign*width): if(wsign*x-r >= 0): if(hsign*y+r <= hsign*height): if(hsign*y-r >= 0): result="Yes" print(result) func()
33
33
723
698
# coding: utf-8 # Here your code ! import math def func(): try: line = input().rstrip() numbers = line.split(" ") width = float(numbers[0]) height = float(numbers[1]) x = float(numbers[2]) y = float(numbers[3]) r = abs(float(numbers[4])) except: print("input error") return -1 wsign = math.copysign(1, width) hsign = math.copysign(1, height) result = wsign * x + r <= wsign * width result = result and (wsign * x - r >= 0) result = result and (hsign * y + r <= hsign * height) result = result and (hsign * y - r >= 0) if result: print("Yes") else: print("No") func()
# coding: utf-8 # Here your code ! import math def func(): try: line = input().rstrip() numbers = line.split(" ") width = float(numbers[0]) height = float(numbers[1]) x = float(numbers[2]) y = float(numbers[3]) r = abs(float(numbers[4])) except: print("input error") return -1 wsign = math.copysign(1, width) hsign = math.copysign(1, height) result = "No" if wsign * x + r <= wsign * width: if wsign * x - r >= 0: if hsign * y + r <= hsign * height: if hsign * y - r >= 0: result = "Yes" print(result) func()
false
0
[ "- result = wsign * x + r <= wsign * width", "- result = result and (wsign * x - r >= 0)", "- result = result and (hsign * y + r <= hsign * height)", "- result = result and (hsign * y - r >= 0)", "- if result:", "- print(\"Yes\")", "- else:", "- print(\"No\")", "+ result = \"No\"", "+ if wsign * x + r <= wsign * width:", "+ if wsign * x - r >= 0:", "+ if hsign * y + r <= hsign * height:", "+ if hsign * y - r >= 0:", "+ result = \"Yes\"", "+ print(result)" ]
false
0.035491
0.036291
0.977944
[ "s788431415", "s925843859" ]
u644907318
p03457
python
s373240206
s779847528
641
223
60,504
90,300
Accepted
Accepted
65.21
def dist(x,y): return abs(x[0]-y[0])+abs(x[1]-y[1]) N = int(eval(input())) X = [list(map(int,input().split())) for _ in range(N)] X.insert(0,[0,0,0]) flag = 0 for i in range(1,N+1): dx = dist(X[i][1:],X[i-1][1:]) dt = X[i][0]-X[i-1][0] if dt>=dx and (dt-dx)%2==0: continue else: flag = 1 break if flag==0: print("Yes") else: print("No")
def dist(x,y): return abs(x[0]-y[0])+abs(x[1]-y[1]) N = int(eval(input())) X = [list(map(int,input().split())) for _ in range(N)] flag = 0 t1,x1,y1 = 0,0,0 for i in range(N): t2,x2,y2 = X[i] d = dist((x1,y1),(x2,y2)) dt = t2-t1 if dt>=d and (dt-d)%2==0: t1,x1,y1 = X[i] else: flag=1 break if flag==0: print("Yes") else: print("No")
18
19
399
399
def dist(x, y): return abs(x[0] - y[0]) + abs(x[1] - y[1]) N = int(eval(input())) X = [list(map(int, input().split())) for _ in range(N)] X.insert(0, [0, 0, 0]) flag = 0 for i in range(1, N + 1): dx = dist(X[i][1:], X[i - 1][1:]) dt = X[i][0] - X[i - 1][0] if dt >= dx and (dt - dx) % 2 == 0: continue else: flag = 1 break if flag == 0: print("Yes") else: print("No")
def dist(x, y): return abs(x[0] - y[0]) + abs(x[1] - y[1]) N = int(eval(input())) X = [list(map(int, input().split())) for _ in range(N)] flag = 0 t1, x1, y1 = 0, 0, 0 for i in range(N): t2, x2, y2 = X[i] d = dist((x1, y1), (x2, y2)) dt = t2 - t1 if dt >= d and (dt - d) % 2 == 0: t1, x1, y1 = X[i] else: flag = 1 break if flag == 0: print("Yes") else: print("No")
false
5.263158
[ "-X.insert(0, [0, 0, 0])", "-for i in range(1, N + 1):", "- dx = dist(X[i][1:], X[i - 1][1:])", "- dt = X[i][0] - X[i - 1][0]", "- if dt >= dx and (dt - dx) % 2 == 0:", "- continue", "+t1, x1, y1 = 0, 0, 0", "+for i in range(N):", "+ t2, x2, y2 = X[i]", "+ d = dist((x1, y1), (x2, y2))", "+ dt = t2 - t1", "+ if dt >= d and (dt - d) % 2 == 0:", "+ t1, x1, y1 = X[i]" ]
false
0.038799
0.066118
0.586821
[ "s373240206", "s779847528" ]
u871201743
p03168
python
s402512809
s732317412
853
338
252,424
43,868
Accepted
Accepted
60.38
n = int(eval(input())) probs = [float(c) for c in input().split()] dp = [[0] * (n+1) for _ in range(n+1)] dp[0][0] = 1 for coin in range(1, n+1): for heads in range(n+1): dp[coin][heads] = dp[coin-1][heads] * (1 - probs[coin-1]) if heads > 0: dp[coin][heads] += dp[coin-1][heads-1] * probs[coin-1] ans = 0 for i in range(n//2 + 1, n+1): ans += dp[n][i] print(ans)
n = int(eval(input())) probs = [float(c) for c in input().split()] dp = [0] * (n+1) dp[0] = 1 for coin in range(n): for heads in reversed(list(range(n+1))): dp[heads] = dp[heads] * (1 - probs[coin-1]) if heads > 0: dp[heads] += dp[heads-1] * probs[coin-1] ans = 0 for heads in range(n+1): tails = n - heads if heads > tails: ans += dp[heads] print(ans)
16
18
411
408
n = int(eval(input())) probs = [float(c) for c in input().split()] dp = [[0] * (n + 1) for _ in range(n + 1)] dp[0][0] = 1 for coin in range(1, n + 1): for heads in range(n + 1): dp[coin][heads] = dp[coin - 1][heads] * (1 - probs[coin - 1]) if heads > 0: dp[coin][heads] += dp[coin - 1][heads - 1] * probs[coin - 1] ans = 0 for i in range(n // 2 + 1, n + 1): ans += dp[n][i] print(ans)
n = int(eval(input())) probs = [float(c) for c in input().split()] dp = [0] * (n + 1) dp[0] = 1 for coin in range(n): for heads in reversed(list(range(n + 1))): dp[heads] = dp[heads] * (1 - probs[coin - 1]) if heads > 0: dp[heads] += dp[heads - 1] * probs[coin - 1] ans = 0 for heads in range(n + 1): tails = n - heads if heads > tails: ans += dp[heads] print(ans)
false
11.111111
[ "-dp = [[0] * (n + 1) for _ in range(n + 1)]", "-dp[0][0] = 1", "-for coin in range(1, n + 1):", "- for heads in range(n + 1):", "- dp[coin][heads] = dp[coin - 1][heads] * (1 - probs[coin - 1])", "+dp = [0] * (n + 1)", "+dp[0] = 1", "+for coin in range(n):", "+ for heads in reversed(list(range(n + 1))):", "+ dp[heads] = dp[heads] * (1 - probs[coin - 1])", "- dp[coin][heads] += dp[coin - 1][heads - 1] * probs[coin - 1]", "+ dp[heads] += dp[heads - 1] * probs[coin - 1]", "-for i in range(n // 2 + 1, n + 1):", "- ans += dp[n][i]", "+for heads in range(n + 1):", "+ tails = n - heads", "+ if heads > tails:", "+ ans += dp[heads]" ]
false
0.035874
0.063137
0.568197
[ "s402512809", "s732317412" ]
u746428948
p02645
python
s478431935
s420305054
26
23
9,092
9,020
Accepted
Accepted
11.54
s = eval(input()) print(('{}{}{}'.format(s[0],s[1],s[2])))
print((input()[0:3]))
2
1
51
19
s = eval(input()) print(("{}{}{}".format(s[0], s[1], s[2])))
print((input()[0:3]))
false
50
[ "-s = eval(input())", "-print((\"{}{}{}\".format(s[0], s[1], s[2])))", "+print((input()[0:3]))" ]
false
0.036744
0.033201
1.106714
[ "s478431935", "s420305054" ]
u358254559
p03805
python
s420136322
s056940471
199
179
40,432
40,432
Accepted
Accepted
10.05
n, m = list(map(int, input().split())) link = [[] for _ in range(n)] for i in range(m): tmp = list(map(int,input().split())) link[tmp[0]-1].append(tmp[1]-1) link[tmp[1]-1].append(tmp[0]-1) lis=[] for i in range(1,n): lis.append(i) ans=0 from itertools import * for perm in list(permutations(lis)): last=0 ok=True for i in range(len(perm)): if perm[i] not in link[last]: ok=False break last=perm[i] if ok: ans+=1 print(ans)
n, m = list(map(int, input().split())) link = [[] for _ in range(n)] for i in range(m): tmp = list(map(int,input().split())) link[tmp[0]-1].append(tmp[1]-1) link[tmp[1]-1].append(tmp[0]-1) lis = list(range(1,n)) ans=0 from itertools import * for perm in list(permutations(lis)): last=0 ok=1 for i in range(len(perm)): if perm[i] not in link[last]: ok=0 last=perm[i] ans+=ok print(ans)
23
18
519
451
n, m = list(map(int, input().split())) link = [[] for _ in range(n)] for i in range(m): tmp = list(map(int, input().split())) link[tmp[0] - 1].append(tmp[1] - 1) link[tmp[1] - 1].append(tmp[0] - 1) lis = [] for i in range(1, n): lis.append(i) ans = 0 from itertools import * for perm in list(permutations(lis)): last = 0 ok = True for i in range(len(perm)): if perm[i] not in link[last]: ok = False break last = perm[i] if ok: ans += 1 print(ans)
n, m = list(map(int, input().split())) link = [[] for _ in range(n)] for i in range(m): tmp = list(map(int, input().split())) link[tmp[0] - 1].append(tmp[1] - 1) link[tmp[1] - 1].append(tmp[0] - 1) lis = list(range(1, n)) ans = 0 from itertools import * for perm in list(permutations(lis)): last = 0 ok = 1 for i in range(len(perm)): if perm[i] not in link[last]: ok = 0 last = perm[i] ans += ok print(ans)
false
21.73913
[ "-lis = []", "-for i in range(1, n):", "- lis.append(i)", "+lis = list(range(1, n))", "- ok = True", "+ ok = 1", "- ok = False", "- break", "+ ok = 0", "- if ok:", "- ans += 1", "+ ans += ok" ]
false
0.048664
0.107545
0.452503
[ "s420136322", "s056940471" ]
u653041271
p03244
python
s052569797
s333232112
105
96
25,656
26,672
Accepted
Accepted
8.57
import sys, bisect, math, itertools, string, queue, copy #import numpy as np #import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(eval(input())) def inpm(): return list(map(int,input().split())) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(eval(input())) for _ in range(n)) def inplL(n): return [list(eval(input())) for _ in range(n)] def inplT(n): return [tuple(eval(input())) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() a = inpl() cnt_even = defaultdict(int) cnt_odd = defaultdict(int) for i in range(0,n,2): cnt_even[a[i]] += 1 for i in range(1,n,2): cnt_odd[a[i]] += 1 cnt_even = list(reversed(sorted(list(cnt_even.items()),key=lambda x:x[1]))) cnt_odd = list(reversed(sorted(list(cnt_odd.items()),key=lambda x:x[1]))) flg = False for i in range(min(2,len(cnt_even),len(cnt_odd))): a,b = (cnt_even[i],cnt_odd[i]) if a[0] != b[0]: if flg == False: n -= a[1]+b[1] else: n -= max(a[1],b[1]) break else: n -= a[1] flg = True print(n)
import sys, bisect, math, itertools, string, queue, copy #import numpy as np #import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(eval(input())) def inpm(): return list(map(int,input().split())) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(eval(input())) for _ in range(n)) def inplL(n): return [list(eval(input())) for _ in range(n)] def inplT(n): return [tuple(eval(input())) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() a = inpl() cnt_even = Counter(a[::2]).most_common()+[(0,0)] cnt_odd = Counter(a[1::2]).most_common()+[(0,0)] ans = 0 if cnt_even[0][0] == cnt_odd[0][0]: ans = n - max(cnt_even[0][1],cnt_odd[0][1]) - max(cnt_even[1][1],cnt_odd[1][1]) else: ans = n - cnt_even[0][1] - cnt_odd[0][1] print(ans)
47
33
1,418
1,155
import sys, bisect, math, itertools, string, queue, copy # import numpy as np # import scipy from collections import Counter, defaultdict, deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9 + 7 def inp(): return int(eval(input())) def inpm(): return list(map(int, input().split())) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(eval(input())) for _ in range(n)) def inplL(n): return [list(eval(input())) for _ in range(n)] def inplT(n): return [tuple(eval(input())) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() a = inpl() cnt_even = defaultdict(int) cnt_odd = defaultdict(int) for i in range(0, n, 2): cnt_even[a[i]] += 1 for i in range(1, n, 2): cnt_odd[a[i]] += 1 cnt_even = list(reversed(sorted(list(cnt_even.items()), key=lambda x: x[1]))) cnt_odd = list(reversed(sorted(list(cnt_odd.items()), key=lambda x: x[1]))) flg = False for i in range(min(2, len(cnt_even), len(cnt_odd))): a, b = (cnt_even[i], cnt_odd[i]) if a[0] != b[0]: if flg == False: n -= a[1] + b[1] else: n -= max(a[1], b[1]) break else: n -= a[1] flg = True print(n)
import sys, bisect, math, itertools, string, queue, copy # import numpy as np # import scipy from collections import Counter, defaultdict, deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9 + 7 def inp(): return int(eval(input())) def inpm(): return list(map(int, input().split())) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(eval(input())) for _ in range(n)) def inplL(n): return [list(eval(input())) for _ in range(n)] def inplT(n): return [tuple(eval(input())) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() a = inpl() cnt_even = Counter(a[::2]).most_common() + [(0, 0)] cnt_odd = Counter(a[1::2]).most_common() + [(0, 0)] ans = 0 if cnt_even[0][0] == cnt_odd[0][0]: ans = n - max(cnt_even[0][1], cnt_odd[0][1]) - max(cnt_even[1][1], cnt_odd[1][1]) else: ans = n - cnt_even[0][1] - cnt_odd[0][1] print(ans)
false
29.787234
[ "-cnt_even = defaultdict(int)", "-cnt_odd = defaultdict(int)", "-for i in range(0, n, 2):", "- cnt_even[a[i]] += 1", "-for i in range(1, n, 2):", "- cnt_odd[a[i]] += 1", "-cnt_even = list(reversed(sorted(list(cnt_even.items()), key=lambda x: x[1])))", "-cnt_odd = list(reversed(sorted(list(cnt_odd.items()), key=lambda x: x[1])))", "-flg = False", "-for i in range(min(2, len(cnt_even), len(cnt_odd))):", "- a, b = (cnt_even[i], cnt_odd[i])", "- if a[0] != b[0]:", "- if flg == False:", "- n -= a[1] + b[1]", "- else:", "- n -= max(a[1], b[1])", "- break", "- else:", "- n -= a[1]", "- flg = True", "-print(n)", "+cnt_even = Counter(a[::2]).most_common() + [(0, 0)]", "+cnt_odd = Counter(a[1::2]).most_common() + [(0, 0)]", "+ans = 0", "+if cnt_even[0][0] == cnt_odd[0][0]:", "+ ans = n - max(cnt_even[0][1], cnt_odd[0][1]) - max(cnt_even[1][1], cnt_odd[1][1])", "+else:", "+ ans = n - cnt_even[0][1] - cnt_odd[0][1]", "+print(ans)" ]
false
0.037519
0.03533
1.061968
[ "s052569797", "s333232112" ]
u790012205
p03162
python
s153227596
s477374528
983
665
47,388
50,092
Accepted
Accepted
32.35
N = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(N)] dp = [[0] * 3 for _ in range(N)] dp[0][0] = abc[0][0] dp[0][1] = abc[0][1] dp[0][2] = abc[0][2] for i in range(1, N): for j in range(3): for k in range(3): if j == k: continue dpp = dp[i - 1][j] + abc[i][k] dp[i][k] = max(dp[i][k], dpp) print((max(dp[-1])))
N = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(N)] dp = [[0] * 3 for _ in range(N + 1)] dp[0][0] = 0 dp[0][1] = 0 dp[0][2] = 0 for i in range(1, N + 1): for j in range(3): for k in range(3): if j == k: continue dp[i][j] = max(dp[i][j], dp[i - 1][k] + abc[i - 1][j]) print((max(dp[-1])))
17
13
413
372
N = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(N)] dp = [[0] * 3 for _ in range(N)] dp[0][0] = abc[0][0] dp[0][1] = abc[0][1] dp[0][2] = abc[0][2] for i in range(1, N): for j in range(3): for k in range(3): if j == k: continue dpp = dp[i - 1][j] + abc[i][k] dp[i][k] = max(dp[i][k], dpp) print((max(dp[-1])))
N = int(eval(input())) abc = [list(map(int, input().split())) for _ in range(N)] dp = [[0] * 3 for _ in range(N + 1)] dp[0][0] = 0 dp[0][1] = 0 dp[0][2] = 0 for i in range(1, N + 1): for j in range(3): for k in range(3): if j == k: continue dp[i][j] = max(dp[i][j], dp[i - 1][k] + abc[i - 1][j]) print((max(dp[-1])))
false
23.529412
[ "-dp = [[0] * 3 for _ in range(N)]", "-dp[0][0] = abc[0][0]", "-dp[0][1] = abc[0][1]", "-dp[0][2] = abc[0][2]", "-for i in range(1, N):", "+dp = [[0] * 3 for _ in range(N + 1)]", "+dp[0][0] = 0", "+dp[0][1] = 0", "+dp[0][2] = 0", "+for i in range(1, N + 1):", "- dpp = dp[i - 1][j] + abc[i][k]", "- dp[i][k] = max(dp[i][k], dpp)", "+ dp[i][j] = max(dp[i][j], dp[i - 1][k] + abc[i - 1][j])" ]
false
0.035312
0.041693
0.846961
[ "s153227596", "s477374528" ]
u644907318
p03043
python
s924007865
s638908020
176
88
39,024
73,868
Accepted
Accepted
50
def f(n): x = 1 while n*2**x<K: x += 1 return x N,K = list(map(int,input().split())) ans = 0 for i in range(1,N+1): if i<K: ans += 2**(-f(i))/N else: ans += 1/N print(ans)
def f(n): k = 0 while n*2**k<K: k += 1 return k N,K = list(map(int,input().split())) if K<=N: P = (N-K+1)/N for i in range(1,K): P += 2**(-f(i))/N else: P = 0 for i in range(1,N+1): P += 2**(-f(i))/N print(P)
13
15
221
268
def f(n): x = 1 while n * 2**x < K: x += 1 return x N, K = list(map(int, input().split())) ans = 0 for i in range(1, N + 1): if i < K: ans += 2 ** (-f(i)) / N else: ans += 1 / N print(ans)
def f(n): k = 0 while n * 2**k < K: k += 1 return k N, K = list(map(int, input().split())) if K <= N: P = (N - K + 1) / N for i in range(1, K): P += 2 ** (-f(i)) / N else: P = 0 for i in range(1, N + 1): P += 2 ** (-f(i)) / N print(P)
false
13.333333
[ "- x = 1", "- while n * 2**x < K:", "- x += 1", "- return x", "+ k = 0", "+ while n * 2**k < K:", "+ k += 1", "+ return k", "-ans = 0", "-for i in range(1, N + 1):", "- if i < K:", "- ans += 2 ** (-f(i)) / N", "- else:", "- ans += 1 / N", "-print(ans)", "+if K <= N:", "+ P = (N - K + 1) / N", "+ for i in range(1, K):", "+ P += 2 ** (-f(i)) / N", "+else:", "+ P = 0", "+ for i in range(1, N + 1):", "+ P += 2 ** (-f(i)) / N", "+print(P)" ]
false
0.06365
0.035245
1.805936
[ "s924007865", "s638908020" ]
u360116509
p03061
python
s458132601
s600086251
193
176
14,436
14,432
Accepted
Accepted
8.81
def gcd(a, b): r = a % b if r == 0: return b return gcd(b, r) def main(): N = int(eval(input())) A = list(map(int, input().split())) A.sort() L = [A[0]] R = [A[-1]] for i in range(1, N - 1): L.append(gcd(L[-1], A[i])) for j in range(N - 2, 0, -1): R.append(gcd(R[-1], A[j])) ans = R[-1] for k in range(1, N - 1): ans = max(ans, gcd(L[k - 1], R[N - 2 - k])) print((max(ans, L[-1]))) main()
def gcd(a, b): r = a % b if r == 0: return b return gcd(b, r) def main(): N = int(eval(input())) A = list(map(int, input().split())) L = [A[0]] R = [A[-1]] for i in range(1, N - 1): L.append(gcd(L[-1], A[i])) for j in range(N - 2, 0, -1): R.append(gcd(R[-1], A[j])) ans = R[-1] for k in range(1, N - 1): ans = max(ans, gcd(L[k - 1], R[N - 2 - k])) print((max(ans, L[-1]))) main()
22
21
492
478
def gcd(a, b): r = a % b if r == 0: return b return gcd(b, r) def main(): N = int(eval(input())) A = list(map(int, input().split())) A.sort() L = [A[0]] R = [A[-1]] for i in range(1, N - 1): L.append(gcd(L[-1], A[i])) for j in range(N - 2, 0, -1): R.append(gcd(R[-1], A[j])) ans = R[-1] for k in range(1, N - 1): ans = max(ans, gcd(L[k - 1], R[N - 2 - k])) print((max(ans, L[-1]))) main()
def gcd(a, b): r = a % b if r == 0: return b return gcd(b, r) def main(): N = int(eval(input())) A = list(map(int, input().split())) L = [A[0]] R = [A[-1]] for i in range(1, N - 1): L.append(gcd(L[-1], A[i])) for j in range(N - 2, 0, -1): R.append(gcd(R[-1], A[j])) ans = R[-1] for k in range(1, N - 1): ans = max(ans, gcd(L[k - 1], R[N - 2 - k])) print((max(ans, L[-1]))) main()
false
4.545455
[ "- A.sort()" ]
false
0.049751
0.047707
1.042843
[ "s458132601", "s600086251" ]
u499381410
p02666
python
s145512832
s260520514
1,643
1,362
241,784
237,456
Accepted
Accepted
17.1
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 ceil, floor, cos, radians, pi, sin from operator import mul from functools import reduce from operator import mul from functools import lru_cache mod = 10 ** 9 + 7 sys.setrecursionlimit(2147483647) INF = 10 ** 13 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)] @lru_cache(maxsize=None) def factorial(n): if n == 0: return 1 else: return (n*factorial(n-1)) % mod class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} n = I() P = LI() fac = [1] * (n + 1) inv = [1] * (n + 1) for j in range(1, n + 1): fac[j] = fac[j-1] * j % mod inv[n] = pow(fac[n], mod-2, mod) for j in range(n-1, -1, -1): inv[j] = inv[j+1] * (j+1) % mod def comb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod U = UnionFind(n) for i in range(n): if P[i] != -1: U.union(P[i] - 1, i) k = 0 L = [] for j in range(n): if P[j] == -1: L += [U.size(j)] k += 1 dp = [0]*(k+1) dp[0] = 1 dp_new = dp[:] for i in range(1, k+1): for j in range(i): dp_new[j+1] += dp[j]*L[i-1] dp = dp_new[:] if k: dp[1] = sum(L) - len(L) cycle_count = 0 for i in range(1, k + 1): # i個のグループからなるサイクルがひとつできる buf = dp[i] * factorial(i - 1) buf %= mod buf *= pow(n - 1, k - i, mod) buf %= mod cycle_count += buf # すでに固定サイクルがあれば数える cycle_count += (U.group_count() - k) * pow(n - 1, k, mod) ans = n * pow(n - 1, k, mod) ans %= mod ans = ans - cycle_count ans %= mod 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, cos, radians, pi, sin from operator import mul from functools import reduce from operator import mul mod = 10 ** 9 + 7 sys.setrecursionlimit(2147483647) INF = 10 ** 13 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)] class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} n = I() P = LI() fac = [1] * (n + 1) inv = [1] * (n + 1) for j in range(1, n + 1): fac[j] = fac[j-1] * j % mod inv[n] = pow(fac[n], mod-2, mod) for j in range(n-1, -1, -1): inv[j] = inv[j+1] * (j+1) % mod def comb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod ret = 0 for p in P: if p == -1: ret += 1 U = UnionFind(n) for i in range(n): if P[i] != -1: U.union(P[i] - 1, i) L = [] for j in range(n): if P[j] == -1: L += [U.size(j)] dp = [0] * (len(L) + 1) dp[0] = 1 for l in range(1, len(L) + 1): for m in range(l, 0, -1): dp[m] += dp[m - 1] * L[l - 1] if L: dp[1] = sum(L) - len(L) cycle_cnt = 0 for i in range(1, len(L) + 1): cycle_cnt = (cycle_cnt + fac[i - 1] * dp[i] * pow(n - 1, len(L) - i, mod)) % mod ans = (n - (U.group_count() - ret)) * pow(n - 1, ret, mod) % mod print(((ans - cycle_cnt) % mod))
144
123
3,418
3,141
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 ceil, floor, cos, radians, pi, sin from operator import mul from functools import reduce from operator import mul from functools import lru_cache mod = 10**9 + 7 sys.setrecursionlimit(2147483647) INF = 10**13 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)] @lru_cache(maxsize=None) def factorial(n): if n == 0: return 1 else: return (n * factorial(n - 1)) % mod class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} n = I() P = LI() fac = [1] * (n + 1) inv = [1] * (n + 1) for j in range(1, n + 1): fac[j] = fac[j - 1] * j % mod inv[n] = pow(fac[n], mod - 2, mod) for j in range(n - 1, -1, -1): inv[j] = inv[j + 1] * (j + 1) % mod def comb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod U = UnionFind(n) for i in range(n): if P[i] != -1: U.union(P[i] - 1, i) k = 0 L = [] for j in range(n): if P[j] == -1: L += [U.size(j)] k += 1 dp = [0] * (k + 1) dp[0] = 1 dp_new = dp[:] for i in range(1, k + 1): for j in range(i): dp_new[j + 1] += dp[j] * L[i - 1] dp = dp_new[:] if k: dp[1] = sum(L) - len(L) cycle_count = 0 for i in range(1, k + 1): # i個のグループからなるサイクルがひとつできる buf = dp[i] * factorial(i - 1) buf %= mod buf *= pow(n - 1, k - i, mod) buf %= mod cycle_count += buf # すでに固定サイクルがあれば数える cycle_count += (U.group_count() - k) * pow(n - 1, k, mod) ans = n * pow(n - 1, k, mod) ans %= mod ans = ans - cycle_count ans %= mod 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, cos, radians, pi, sin from operator import mul from functools import reduce from operator import mul mod = 10**9 + 7 sys.setrecursionlimit(2147483647) INF = 10**13 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)] class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} n = I() P = LI() fac = [1] * (n + 1) inv = [1] * (n + 1) for j in range(1, n + 1): fac[j] = fac[j - 1] * j % mod inv[n] = pow(fac[n], mod - 2, mod) for j in range(n - 1, -1, -1): inv[j] = inv[j + 1] * (j + 1) % mod def comb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod ret = 0 for p in P: if p == -1: ret += 1 U = UnionFind(n) for i in range(n): if P[i] != -1: U.union(P[i] - 1, i) L = [] for j in range(n): if P[j] == -1: L += [U.size(j)] dp = [0] * (len(L) + 1) dp[0] = 1 for l in range(1, len(L) + 1): for m in range(l, 0, -1): dp[m] += dp[m - 1] * L[l - 1] if L: dp[1] = sum(L) - len(L) cycle_cnt = 0 for i in range(1, len(L) + 1): cycle_cnt = (cycle_cnt + fac[i - 1] * dp[i] * pow(n - 1, len(L) - i, mod)) % mod ans = (n - (U.group_count() - ret)) * pow(n - 1, ret, mod) % mod print(((ans - cycle_cnt) % mod))
false
14.583333
[ "-from math import ceil, floor, cos, radians, pi, sin", "+from math import factorial, ceil, floor, cos, radians, pi, sin", "-from functools import lru_cache", "-", "-", "-@lru_cache(maxsize=None)", "-def factorial(n):", "- if n == 0:", "- return 1", "- else:", "- return (n * factorial(n - 1)) % mod", "+ret = 0", "+for p in P:", "+ if p == -1:", "+ ret += 1", "-k = 0", "- k += 1", "-dp = [0] * (k + 1)", "+dp = [0] * (len(L) + 1)", "-dp_new = dp[:]", "-for i in range(1, k + 1):", "- for j in range(i):", "- dp_new[j + 1] += dp[j] * L[i - 1]", "- dp = dp_new[:]", "-if k:", "+for l in range(1, len(L) + 1):", "+ for m in range(l, 0, -1):", "+ dp[m] += dp[m - 1] * L[l - 1]", "+if L:", "-cycle_count = 0", "-for i in range(1, k + 1):", "- # i個のグループからなるサイクルがひとつできる", "- buf = dp[i] * factorial(i - 1)", "- buf %= mod", "- buf *= pow(n - 1, k - i, mod)", "- buf %= mod", "- cycle_count += buf", "-# すでに固定サイクルがあれば数える", "-cycle_count += (U.group_count() - k) * pow(n - 1, k, mod)", "-ans = n * pow(n - 1, k, mod)", "-ans %= mod", "-ans = ans - cycle_count", "-ans %= mod", "-print(ans)", "+cycle_cnt = 0", "+for i in range(1, len(L) + 1):", "+ cycle_cnt = (cycle_cnt + fac[i - 1] * dp[i] * pow(n - 1, len(L) - i, mod)) % mod", "+ans = (n - (U.group_count() - ret)) * pow(n - 1, ret, mod) % mod", "+print(((ans - cycle_cnt) % mod))" ]
false
0.044015
0.116918
0.376459
[ "s145512832", "s260520514" ]
u395202850
p03945
python
s763928415
s235170357
46
38
3,188
3,188
Accepted
Accepted
17.39
s = eval(input()) cnt = 0 for i in range(len(s)-1): if s[i] != s[i + 1]: cnt += 1 print(cnt)
s = eval(input()) print((sum(s[i] != s[i + 1] for i in range(len(s)-1))))
6
2
104
67
s = eval(input()) cnt = 0 for i in range(len(s) - 1): if s[i] != s[i + 1]: cnt += 1 print(cnt)
s = eval(input()) print((sum(s[i] != s[i + 1] for i in range(len(s) - 1))))
false
66.666667
[ "-cnt = 0", "-for i in range(len(s) - 1):", "- if s[i] != s[i + 1]:", "- cnt += 1", "-print(cnt)", "+print((sum(s[i] != s[i + 1] for i in range(len(s) - 1))))" ]
false
0.044779
0.041185
1.087248
[ "s763928415", "s235170357" ]
u706695185
p03212
python
s082105892
s867555048
106
73
7,028
4,724
Accepted
Accepted
31.13
N = int(eval(input())) dp = [] def dfs(x): if len(set(str(x))) == 3: dp.append(x) if x < 10**9: dfs(x*10+3) dfs(x*10+5) dfs(x*10+7) dfs(0) print((len([item for item in dp if item <= N])))
from collections import deque N = int(eval(input())) q = deque() q.append(0) memo = [] while q: x = q.pop() if x < 10**9: if len(set(str(x))) == 3: memo.append(x) q.append(10*x+3) q.append(10*x+5) q.append(10*x+7) print((len([num for num in memo if num <= N])))
14
15
236
321
N = int(eval(input())) dp = [] def dfs(x): if len(set(str(x))) == 3: dp.append(x) if x < 10**9: dfs(x * 10 + 3) dfs(x * 10 + 5) dfs(x * 10 + 7) dfs(0) print((len([item for item in dp if item <= N])))
from collections import deque N = int(eval(input())) q = deque() q.append(0) memo = [] while q: x = q.pop() if x < 10**9: if len(set(str(x))) == 3: memo.append(x) q.append(10 * x + 3) q.append(10 * x + 5) q.append(10 * x + 7) print((len([num for num in memo if num <= N])))
false
6.666667
[ "+from collections import deque", "+", "-dp = []", "-", "-", "-def dfs(x):", "- if len(set(str(x))) == 3:", "- dp.append(x)", "+q = deque()", "+q.append(0)", "+memo = []", "+while q:", "+ x = q.pop()", "- dfs(x * 10 + 3)", "- dfs(x * 10 + 5)", "- dfs(x * 10 + 7)", "-", "-", "-dfs(0)", "-print((len([item for item in dp if item <= N])))", "+ if len(set(str(x))) == 3:", "+ memo.append(x)", "+ q.append(10 * x + 3)", "+ q.append(10 * x + 5)", "+ q.append(10 * x + 7)", "+print((len([num for num in memo if num <= N])))" ]
false
0.135942
0.369825
0.367585
[ "s082105892", "s867555048" ]
u080364835
p02831
python
s490323117
s030865413
28
23
2,940
9,064
Accepted
Accepted
17.86
a, b = list(map(int, input().split())) gcd = 0 for i in range(max(a, b), 0, -1): if a % i == 0 and b % i == 0: gcd = i break print((a * b // gcd))
import math a, b = list(map(int, input().split())) print(((a*b)//math.gcd(a, b)))
7
4
164
77
a, b = list(map(int, input().split())) gcd = 0 for i in range(max(a, b), 0, -1): if a % i == 0 and b % i == 0: gcd = i break print((a * b // gcd))
import math a, b = list(map(int, input().split())) print(((a * b) // math.gcd(a, b)))
false
42.857143
[ "+import math", "+", "-gcd = 0", "-for i in range(max(a, b), 0, -1):", "- if a % i == 0 and b % i == 0:", "- gcd = i", "- break", "-print((a * b // gcd))", "+print(((a * b) // math.gcd(a, b)))" ]
false
0.048267
0.041899
1.151979
[ "s490323117", "s030865413" ]
u558242240
p03289
python
s838018541
s819256257
21
17
3,316
2,940
Accepted
Accepted
19.05
s = eval(input()) if s[0] != 'A': print('WA') exit() import collections cnt = collections.Counter(s[2:-1]) if cnt['C'] != 1: print('WA') exit() s2 = s[1:].replace('C', '') if not s2.islower(): print('WA') exit() print('AC')
s = eval(input()) if s[0] != 'A': print('WA') exit() if s.count('C', 2, -1) != 1: print('WA') exit() s2 = s[1:].replace('C', '') if not s2.islower(): print('WA') exit() print('AC')
20
18
267
222
s = eval(input()) if s[0] != "A": print("WA") exit() import collections cnt = collections.Counter(s[2:-1]) if cnt["C"] != 1: print("WA") exit() s2 = s[1:].replace("C", "") if not s2.islower(): print("WA") exit() print("AC")
s = eval(input()) if s[0] != "A": print("WA") exit() if s.count("C", 2, -1) != 1: print("WA") exit() s2 = s[1:].replace("C", "") if not s2.islower(): print("WA") exit() print("AC")
false
10
[ "-import collections", "-", "-cnt = collections.Counter(s[2:-1])", "-if cnt[\"C\"] != 1:", "+if s.count(\"C\", 2, -1) != 1:" ]
false
0.03994
0.039856
1.00211
[ "s838018541", "s819256257" ]
u970197315
p02725
python
s251967014
s024885298
259
151
26,444
32,256
Accepted
Accepted
41.7
# ABC160_C k,n=list(map(int,input().split())) a=list(map(int,input().split())) # mid=(a[0]+a[-1])/2 d=[] for i in range(n-1): d.append(a[i+1]-a[i]) # d.append(k-a[-1]) # d=[k-a[-1]]+d # print(d) ans=10**10 d=[k-a[-1]+a[0]]+d d+=[k-a[-1]+a[0]] # print(d) for i in range(1,n): t=min(k-d[i-1],k-d[i+1]) ans=min(t,ans) print(ans)
k,n=list(map(int,input().split())) a=list(map(int,input().split())) d=[] d.append(k-a[-1]+a[0]) for i in range(1,n): d.append(a[i]-a[i-1]) ans=10**18 for di in d: t=k-di ans=min(ans,t) print(ans)
19
11
351
205
# ABC160_C k, n = list(map(int, input().split())) a = list(map(int, input().split())) # mid=(a[0]+a[-1])/2 d = [] for i in range(n - 1): d.append(a[i + 1] - a[i]) # d.append(k-a[-1]) # d=[k-a[-1]]+d # print(d) ans = 10**10 d = [k - a[-1] + a[0]] + d d += [k - a[-1] + a[0]] # print(d) for i in range(1, n): t = min(k - d[i - 1], k - d[i + 1]) ans = min(t, ans) print(ans)
k, n = list(map(int, input().split())) a = list(map(int, input().split())) d = [] d.append(k - a[-1] + a[0]) for i in range(1, n): d.append(a[i] - a[i - 1]) ans = 10**18 for di in d: t = k - di ans = min(ans, t) print(ans)
false
42.105263
[ "-# ABC160_C", "-# mid=(a[0]+a[-1])/2", "-for i in range(n - 1):", "- d.append(a[i + 1] - a[i])", "-# d.append(k-a[-1])", "-# d=[k-a[-1]]+d", "-# print(d)", "-ans = 10**10", "-d = [k - a[-1] + a[0]] + d", "-d += [k - a[-1] + a[0]]", "-# print(d)", "+d.append(k - a[-1] + a[0])", "- t = min(k - d[i - 1], k - d[i + 1])", "- ans = min(t, ans)", "+ d.append(a[i] - a[i - 1])", "+ans = 10**18", "+for di in d:", "+ t = k - di", "+ ans = min(ans, t)" ]
false
0.036709
0.039023
0.94071
[ "s251967014", "s024885298" ]
u133936772
p03087
python
s992432619
s442781029
870
286
6,292
6,332
Accepted
Accepted
67.13
f = lambda : list(map(int,input().split())) n, q = f() s = eval(input()) cnt = 0 ln = [0]*n for i in range(1,n): if s[i-1:i+1] == 'AC': cnt += 1 ln[i] = cnt for _ in range(q): l, r = f() print((ln[r-1]-ln[l-1]))
import sys input = sys.stdin.readline f = lambda : list(map(int,input().split())) n, q = f() s = eval(input()) cnt = 0 ln = [0]*n for i in range(1,n): if s[i-1:i+1] == 'AC': cnt += 1 ln[i] = cnt for _ in range(q): l, r = f() print((ln[r-1]-ln[l-1]))
14
16
224
264
f = lambda: list(map(int, input().split())) n, q = f() s = eval(input()) cnt = 0 ln = [0] * n for i in range(1, n): if s[i - 1 : i + 1] == "AC": cnt += 1 ln[i] = cnt for _ in range(q): l, r = f() print((ln[r - 1] - ln[l - 1]))
import sys input = sys.stdin.readline f = lambda: list(map(int, input().split())) n, q = f() s = eval(input()) cnt = 0 ln = [0] * n for i in range(1, n): if s[i - 1 : i + 1] == "AC": cnt += 1 ln[i] = cnt for _ in range(q): l, r = f() print((ln[r - 1] - ln[l - 1]))
false
12.5
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.083702
0.037539
2.229726
[ "s992432619", "s442781029" ]
u074220993
p03487
python
s502024010
s043878314
190
66
20,592
22,452
Accepted
Accepted
65.26
N = eval(input()) A = sorted([int(x) for x in input().split()]) import bisect as bs ans = 0 f = lambda X, x: bs.bisect_right(X,x) - bs.bisect_left(X,x) for a in set(A): cnt = f(A,a) if cnt < a: ans += cnt else: ans += cnt-a print(ans)
from collections import Counter from itertools import starmap def main(): N = eval(input()) A = list(map(int, input().split())) count = Counter(A) remove = lambda x,y: y-x if y >= x else y ans = sum(starmap(remove, list(count.items()))) print(ans) main()
12
11
267
277
N = eval(input()) A = sorted([int(x) for x in input().split()]) import bisect as bs ans = 0 f = lambda X, x: bs.bisect_right(X, x) - bs.bisect_left(X, x) for a in set(A): cnt = f(A, a) if cnt < a: ans += cnt else: ans += cnt - a print(ans)
from collections import Counter from itertools import starmap def main(): N = eval(input()) A = list(map(int, input().split())) count = Counter(A) remove = lambda x, y: y - x if y >= x else y ans = sum(starmap(remove, list(count.items()))) print(ans) main()
false
8.333333
[ "-N = eval(input())", "-A = sorted([int(x) for x in input().split()])", "-import bisect as bs", "+from collections import Counter", "+from itertools import starmap", "-ans = 0", "-f = lambda X, x: bs.bisect_right(X, x) - bs.bisect_left(X, x)", "-for a in set(A):", "- cnt = f(A, a)", "- if cnt < a:", "- ans += cnt", "- else:", "- ans += cnt - a", "-print(ans)", "+", "+def main():", "+ N = eval(input())", "+ A = list(map(int, input().split()))", "+ count = Counter(A)", "+ remove = lambda x, y: y - x if y >= x else y", "+ ans = sum(starmap(remove, list(count.items())))", "+ print(ans)", "+", "+", "+main()" ]
false
0.040151
0.043178
0.929891
[ "s502024010", "s043878314" ]
u960171798
p03316
python
s307104563
s493139484
19
17
2,940
2,940
Accepted
Accepted
10.53
N = eval(input()) S = 0 for n in N: S += int(n) N = int(N) print(("Yes" if N%S == 0 else "No"))
n = eval(input()) N = int(n) n = list(n) for i in range(len(n)): n[i] = int(n[i]) sum_n = sum(n) if N%sum_n==0: print("Yes") else: print("No")
6
10
95
158
N = eval(input()) S = 0 for n in N: S += int(n) N = int(N) print(("Yes" if N % S == 0 else "No"))
n = eval(input()) N = int(n) n = list(n) for i in range(len(n)): n[i] = int(n[i]) sum_n = sum(n) if N % sum_n == 0: print("Yes") else: print("No")
false
40
[ "-N = eval(input())", "-S = 0", "-for n in N:", "- S += int(n)", "-N = int(N)", "-print((\"Yes\" if N % S == 0 else \"No\"))", "+n = eval(input())", "+N = int(n)", "+n = list(n)", "+for i in range(len(n)):", "+ n[i] = int(n[i])", "+sum_n = sum(n)", "+if N % sum_n == 0:", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.046198
0.0479
0.964468
[ "s307104563", "s493139484" ]
u863442865
p03325
python
s764362479
s187601097
111
89
4,148
4,148
Accepted
Accepted
19.82
n = int(eval(input())) ni = list(map(int, input().split())) cnt = 0 for i in ni: while (i % 2==0): i /= 2 cnt += 1 print(cnt)
n = int(eval(input())) ni = list(map(int, input().split())) cnt = 0 for i in ni: while ( i % 2==0): i //= 2 cnt += 1 print(cnt)
8
8
137
139
n = int(eval(input())) ni = list(map(int, input().split())) cnt = 0 for i in ni: while i % 2 == 0: i /= 2 cnt += 1 print(cnt)
n = int(eval(input())) ni = list(map(int, input().split())) cnt = 0 for i in ni: while i % 2 == 0: i //= 2 cnt += 1 print(cnt)
false
0
[ "- i /= 2", "+ i //= 2" ]
false
0.050182
0.069275
0.724392
[ "s764362479", "s187601097" ]
u047796752
p03039
python
s396391636
s554316027
195
96
43,632
79,728
Accepted
Accepted
50.77
MAX = 2*10**5+100 MOD = 10**9+7 fact = [0]*MAX #fact[i]: i! inv = [0]*MAX #inv[i]: iの逆元 finv = [0]*MAX #finv[i]: i!の逆元 fact[0] = 1 fact[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2, MAX): fact[i] = fact[i-1]*i%MOD inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD finv[i] = finv[i-1]*inv[i]%MOD def C(n, r): if n<r: return 0 if n<0 or r<0: return 0 return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD N, M, K = list(map(int, input().split())) ans = 0 for d in range(1, N): ans += d*(N-d)*M**2 ans %= MOD for d in range(1, M): ans += d*(M-d)*N**2 ans %= MOD ans *= C(N*M-2, K-2) ans %= MOD print(ans)
MAX = 2*10**5+100 MOD = 10**9+7 fact = [0]*MAX #fact[i]: i! inv = [0]*MAX #inv[i]: iの逆元 finv = [0]*MAX #finv[i]: i!の逆元 fact[0] = 1 fact[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2, MAX): fact[i] = fact[i-1]*i%MOD inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD finv[i] = finv[i-1]*inv[i]%MOD def C(n, r): if n<r: return 0 if n<0 or r<0: return 0 return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD N, M, K = list(map(int, input().split())) ans = 0 for i in range(1, N): ans += i*(N-i)*M*M*C(N*M-2, K-2) ans %= MOD for i in range(1, M): ans += i*(M-i)*N*N*C(N*M-2, K-2) ans %= MOD print(ans)
38
35
693
679
MAX = 2 * 10**5 + 100 MOD = 10**9 + 7 fact = [0] * MAX # fact[i]: i! inv = [0] * MAX # inv[i]: iの逆元 finv = [0] * MAX # finv[i]: i!の逆元 fact[0] = 1 fact[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2, MAX): fact[i] = fact[i - 1] * i % MOD inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD def C(n, r): if n < r: return 0 if n < 0 or r < 0: return 0 return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD N, M, K = list(map(int, input().split())) ans = 0 for d in range(1, N): ans += d * (N - d) * M**2 ans %= MOD for d in range(1, M): ans += d * (M - d) * N**2 ans %= MOD ans *= C(N * M - 2, K - 2) ans %= MOD print(ans)
MAX = 2 * 10**5 + 100 MOD = 10**9 + 7 fact = [0] * MAX # fact[i]: i! inv = [0] * MAX # inv[i]: iの逆元 finv = [0] * MAX # finv[i]: i!の逆元 fact[0] = 1 fact[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2, MAX): fact[i] = fact[i - 1] * i % MOD inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD def C(n, r): if n < r: return 0 if n < 0 or r < 0: return 0 return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD N, M, K = list(map(int, input().split())) ans = 0 for i in range(1, N): ans += i * (N - i) * M * M * C(N * M - 2, K - 2) ans %= MOD for i in range(1, M): ans += i * (M - i) * N * N * C(N * M - 2, K - 2) ans %= MOD print(ans)
false
7.894737
[ "-for d in range(1, N):", "- ans += d * (N - d) * M**2", "+for i in range(1, N):", "+ ans += i * (N - i) * M * M * C(N * M - 2, K - 2)", "-for d in range(1, M):", "- ans += d * (M - d) * N**2", "+for i in range(1, M):", "+ ans += i * (M - i) * N * N * C(N * M - 2, K - 2)", "-ans *= C(N * M - 2, K - 2)", "-ans %= MOD" ]
false
1.076703
1.18189
0.911001
[ "s396391636", "s554316027" ]
u472065247
p03798
python
s659181382
s486756903
176
131
7,000
5,644
Accepted
Accepted
25.57
N = int(input()) s = input() s += s[0] l = [0] * (N + 2) # S: 1, W: 0 for a0, a1 in ((0, 0), (0, 1), (1, 0), (1, 1)): l[0], l[1] = a0, a1 for i in range(1, N + 1): if s[i] == 'o': l[i + 1] = not (l[i] ^ l[i - 1]) else: l[i + 1] = l[i] ^ l[i - 1] if (l[0] == l[-2]) and (l[1] == l[-1]): print(*['S' if i == 1 else 'W' for i in l[:-2]], sep='') exit() print(-1)
N = int(eval(input())) s = eval(input()) s += s[0] # S: 1, W: 0 for a0, a1 in ((0, 0), (0, 1), (1, 0), (1, 1)): l = [a0, a1] for i in range(1, N + 1): if s[i] == 'o': a0, a1 = a1, not (a0 ^ a1) else: a0, a1 = a1, (a0 ^ a1) l.append(a1) if (l[0] == l[-2]) and (l[1] == l[-1]): s = ''.join(['S' if i == 1 else 'W' for i in l[:-2]]) print(s) exit() print((-1))
18
21
402
409
N = int(input()) s = input() s += s[0] l = [0] * (N + 2) # S: 1, W: 0 for a0, a1 in ((0, 0), (0, 1), (1, 0), (1, 1)): l[0], l[1] = a0, a1 for i in range(1, N + 1): if s[i] == "o": l[i + 1] = not (l[i] ^ l[i - 1]) else: l[i + 1] = l[i] ^ l[i - 1] if (l[0] == l[-2]) and (l[1] == l[-1]): print(*["S" if i == 1 else "W" for i in l[:-2]], sep="") exit() print(-1)
N = int(eval(input())) s = eval(input()) s += s[0] # S: 1, W: 0 for a0, a1 in ((0, 0), (0, 1), (1, 0), (1, 1)): l = [a0, a1] for i in range(1, N + 1): if s[i] == "o": a0, a1 = a1, not (a0 ^ a1) else: a0, a1 = a1, (a0 ^ a1) l.append(a1) if (l[0] == l[-2]) and (l[1] == l[-1]): s = "".join(["S" if i == 1 else "W" for i in l[:-2]]) print(s) exit() print((-1))
false
14.285714
[ "-N = int(input())", "-s = input()", "+N = int(eval(input()))", "+s = eval(input())", "-l = [0] * (N + 2)", "- l[0], l[1] = a0, a1", "+ l = [a0, a1]", "- l[i + 1] = not (l[i] ^ l[i - 1])", "+ a0, a1 = a1, not (a0 ^ a1)", "- l[i + 1] = l[i] ^ l[i - 1]", "+ a0, a1 = a1, (a0 ^ a1)", "+ l.append(a1)", "- print(*[\"S\" if i == 1 else \"W\" for i in l[:-2]], sep=\"\")", "+ s = \"\".join([\"S\" if i == 1 else \"W\" for i in l[:-2]])", "+ print(s)", "-print(-1)", "+print((-1))" ]
false
0.084813
0.058557
1.448377
[ "s659181382", "s486756903" ]
u989345508
p02691
python
s805578430
s091488149
283
246
57,676
63,352
Accepted
Accepted
13.07
n=int(eval(input())) a=list(map(int,input().split())) c,d=dict(),dict() for i in range(n): if i+1-a[i] in c: c[i+1-a[i]]+=1 else: c[i+1-a[i]]=1 if i+1+a[i] in d: d[i+1+a[i]]+=1 else: d[i+1+a[i]]=1 ans=0 for i in c: if i in d: ans+=(c[i]*d[i]) print(ans)
import collections N = int(eval(input())) A = list(map(int, input().split())) L = [i + A[i] for i in range(N)] R = [i - A[i] for i in range(N)] countL = collections.Counter(L) countR = collections.Counter(R) print((sum([countL[n] * countR[n] for n in list(countL.keys())])))
17
12
324
275
n = int(eval(input())) a = list(map(int, input().split())) c, d = dict(), dict() for i in range(n): if i + 1 - a[i] in c: c[i + 1 - a[i]] += 1 else: c[i + 1 - a[i]] = 1 if i + 1 + a[i] in d: d[i + 1 + a[i]] += 1 else: d[i + 1 + a[i]] = 1 ans = 0 for i in c: if i in d: ans += c[i] * d[i] print(ans)
import collections N = int(eval(input())) A = list(map(int, input().split())) L = [i + A[i] for i in range(N)] R = [i - A[i] for i in range(N)] countL = collections.Counter(L) countR = collections.Counter(R) print((sum([countL[n] * countR[n] for n in list(countL.keys())])))
false
29.411765
[ "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-c, d = dict(), dict()", "-for i in range(n):", "- if i + 1 - a[i] in c:", "- c[i + 1 - a[i]] += 1", "- else:", "- c[i + 1 - a[i]] = 1", "- if i + 1 + a[i] in d:", "- d[i + 1 + a[i]] += 1", "- else:", "- d[i + 1 + a[i]] = 1", "-ans = 0", "-for i in c:", "- if i in d:", "- ans += c[i] * d[i]", "-print(ans)", "+import collections", "+", "+N = int(eval(input()))", "+A = list(map(int, input().split()))", "+L = [i + A[i] for i in range(N)]", "+R = [i - A[i] for i in range(N)]", "+countL = collections.Counter(L)", "+countR = collections.Counter(R)", "+print((sum([countL[n] * countR[n] for n in list(countL.keys())])))" ]
false
0.036057
0.036427
0.989849
[ "s805578430", "s091488149" ]
u877415670
p02744
python
s838440817
s612839302
155
109
4,412
17,376
Accepted
Accepted
29.68
import sys sys.setrecursionlimit(10**9) N = int(eval(input())) def bfs(s, cnt, m): if cnt == N: print(s) return for i in range(97,ord(m)+2): if chr(i) > m: bfs(s+chr(i), cnt+1, chr(i)) else: bfs(s+chr(i), cnt+1, m) bfs('a',1,'a')
def dfs(cnt, s, now): if cnt == n: ans.append(s) return for i in range(now+1): dfs(cnt+1, s+al[i], max(i+1, now)) n = int(eval(input())) ans = [] al = [chr(i) for i in range(97, 97+26)] dfs(0, "", 0) for i in ans: print(i)
17
13
259
265
import sys sys.setrecursionlimit(10**9) N = int(eval(input())) def bfs(s, cnt, m): if cnt == N: print(s) return for i in range(97, ord(m) + 2): if chr(i) > m: bfs(s + chr(i), cnt + 1, chr(i)) else: bfs(s + chr(i), cnt + 1, m) bfs("a", 1, "a")
def dfs(cnt, s, now): if cnt == n: ans.append(s) return for i in range(now + 1): dfs(cnt + 1, s + al[i], max(i + 1, now)) n = int(eval(input())) ans = [] al = [chr(i) for i in range(97, 97 + 26)] dfs(0, "", 0) for i in ans: print(i)
false
23.529412
[ "-import sys", "-", "-sys.setrecursionlimit(10**9)", "-N = int(eval(input()))", "+def dfs(cnt, s, now):", "+ if cnt == n:", "+ ans.append(s)", "+ return", "+ for i in range(now + 1):", "+ dfs(cnt + 1, s + al[i], max(i + 1, now))", "-def bfs(s, cnt, m):", "- if cnt == N:", "- print(s)", "- return", "- for i in range(97, ord(m) + 2):", "- if chr(i) > m:", "- bfs(s + chr(i), cnt + 1, chr(i))", "- else:", "- bfs(s + chr(i), cnt + 1, m)", "-", "-", "-bfs(\"a\", 1, \"a\")", "+n = int(eval(input()))", "+ans = []", "+al = [chr(i) for i in range(97, 97 + 26)]", "+dfs(0, \"\", 0)", "+for i in ans:", "+ print(i)" ]
false
0.060792
0.043869
1.385781
[ "s838440817", "s612839302" ]
u225388820
p02713
python
s361707784
s555595454
1,870
970
70,280
69,352
Accepted
Accepted
48.13
def gcd(a,b): while b: a,b=b,a%b return a from functools import reduce def gcd_list(numbers): return reduce(gcd, numbers) k=int(eval(input())) ans=0 for i in range(1,k+1): for j in range(1,k+1): for x in range(1,k+1): ans+=gcd_list([i,j,x]) print(ans)
from math import gcd from functools import reduce def gcd_list(numbers): return reduce(gcd, numbers) k=int(eval(input())) ans=0 for i in range(1,k+1): for j in range(1,k+1): for x in range(1,k+1): ans+=gcd_list([i,j,x]) print(ans)
14
11
301
261
def gcd(a, b): while b: a, b = b, a % b return a from functools import reduce def gcd_list(numbers): return reduce(gcd, numbers) k = int(eval(input())) ans = 0 for i in range(1, k + 1): for j in range(1, k + 1): for x in range(1, k + 1): ans += gcd_list([i, j, x]) print(ans)
from math import gcd from functools import reduce def gcd_list(numbers): return reduce(gcd, numbers) k = int(eval(input())) ans = 0 for i in range(1, k + 1): for j in range(1, k + 1): for x in range(1, k + 1): ans += gcd_list([i, j, x]) print(ans)
false
21.428571
[ "-def gcd(a, b):", "- while b:", "- a, b = b, a % b", "- return a", "-", "-", "+from math import gcd" ]
false
0.041971
0.107187
0.391567
[ "s361707784", "s555595454" ]
u223663729
p03061
python
s101333904
s777088856
193
80
16,144
23,412
Accepted
Accepted
58.55
from fractions import gcd N, *A, = list(map(int, open(0).read().split())) l = [0]*N r = [0]*N # [0,i]のgcd l[0] = A[0] for i in range(1, N): l[i] = gcd(l[i-1],A[i]) # [i,N-1]のgcd r[N-1] = A[N-1] for i in range(N-1)[::-1]: r[i] = gcd(r[i+1],A[i]) m = [0]*N for i in range(1, N-1): m[i] = gcd(l[i-1], r[i+1]) m[0] = r[1] m[N-1] = l[N-2] print((max(m)))
from itertools import accumulate from math import gcd N = int(eval(input())) *A, = list(map(int, input().split())) L = list(accumulate(A, gcd)) R = list(accumulate(A[::-1], gcd))[::-1] ans = max(gcd(l, r) for l, r in zip([0]+L[:-1], R[1:]+[0])) print(ans)
21
10
376
255
from fractions import gcd ( N, *A, ) = list(map(int, open(0).read().split())) l = [0] * N r = [0] * N # [0,i]のgcd l[0] = A[0] for i in range(1, N): l[i] = gcd(l[i - 1], A[i]) # [i,N-1]のgcd r[N - 1] = A[N - 1] for i in range(N - 1)[::-1]: r[i] = gcd(r[i + 1], A[i]) m = [0] * N for i in range(1, N - 1): m[i] = gcd(l[i - 1], r[i + 1]) m[0] = r[1] m[N - 1] = l[N - 2] print((max(m)))
from itertools import accumulate from math import gcd N = int(eval(input())) (*A,) = list(map(int, input().split())) L = list(accumulate(A, gcd)) R = list(accumulate(A[::-1], gcd))[::-1] ans = max(gcd(l, r) for l, r in zip([0] + L[:-1], R[1:] + [0])) print(ans)
false
52.380952
[ "-from fractions import gcd", "+from itertools import accumulate", "+from math import gcd", "-(", "- N,", "- *A,", "-) = list(map(int, open(0).read().split()))", "-l = [0] * N", "-r = [0] * N", "-# [0,i]のgcd", "-l[0] = A[0]", "-for i in range(1, N):", "- l[i] = gcd(l[i - 1], A[i])", "-# [i,N-1]のgcd", "-r[N - 1] = A[N - 1]", "-for i in range(N - 1)[::-1]:", "- r[i] = gcd(r[i + 1], A[i])", "-m = [0] * N", "-for i in range(1, N - 1):", "- m[i] = gcd(l[i - 1], r[i + 1])", "-m[0] = r[1]", "-m[N - 1] = l[N - 2]", "-print((max(m)))", "+N = int(eval(input()))", "+(*A,) = list(map(int, input().split()))", "+L = list(accumulate(A, gcd))", "+R = list(accumulate(A[::-1], gcd))[::-1]", "+ans = max(gcd(l, r) for l, r in zip([0] + L[:-1], R[1:] + [0]))", "+print(ans)" ]
false
0.05932
0.03812
1.556133
[ "s101333904", "s777088856" ]
u796942881
p02772
python
s293321069
s886274372
21
18
3,060
2,940
Accepted
Accepted
14.29
def main(): N, *A = list(map(int, open(0).read().split())) print(("DENIED" if sum( [1 for Ai in A if not Ai % 2 and Ai % 3 and Ai % 5]) else "APPROVED")) return main()
def main(): N, *A = list(map(int, open(0).read().split())) for Ai in A: if not Ai % 2 and Ai % 3 and Ai % 5: print("DENIED") return print("APPROVED") return main()
8
11
189
218
def main(): N, *A = list(map(int, open(0).read().split())) print( ( "DENIED" if sum([1 for Ai in A if not Ai % 2 and Ai % 3 and Ai % 5]) else "APPROVED" ) ) return main()
def main(): N, *A = list(map(int, open(0).read().split())) for Ai in A: if not Ai % 2 and Ai % 3 and Ai % 5: print("DENIED") return print("APPROVED") return main()
false
27.272727
[ "- print(", "- (", "- \"DENIED\"", "- if sum([1 for Ai in A if not Ai % 2 and Ai % 3 and Ai % 5])", "- else \"APPROVED\"", "- )", "- )", "+ for Ai in A:", "+ if not Ai % 2 and Ai % 3 and Ai % 5:", "+ print(\"DENIED\")", "+ return", "+ print(\"APPROVED\")" ]
false
0.045246
0.043922
1.030166
[ "s293321069", "s886274372" ]
u150984829
p00040
python
s121593703
s262226739
40
30
5,608
5,600
Accepted
Accepted
25
z='abcdefghijklmnopqrstuvwxyz' e=lambda x,i,j:z[(z.index(x)*i+j)%26] def f(): for i in range(1,26,2): for j in range(26): if''.join(e(c,i,j)for c in'that')in s or''.join(e(c,i,j)for c in'this')in s:return(i,j) def g(x,y,s=0,t=1): q,r=x//y,x%y return g(y,r,t,s-q*t) if r else t for _ in[0]*int(eval(input())): s=eval(input()) a,b=f() h=g(26,a) print((''.join(z[h*(z.index(c)-b)%26]if c in z else c for c in s)))
z='abcdefghijklmnopqrstuvwxyz' e=lambda x,i,j:z[(z.index(x)*i+j)%26] def f(): for i in(1,3,5,7,9,11,15,17,19,21,23,25): for j in range(26): if''.join(e(c,i,j)for c in'that')in s or''.join(e(c,i,j)for c in'this')in s:return(i,j) def g(x,y,s=0,t=1): q,r=x//y,x%y return g(y,r,t,s-q*t) if r else t for _ in[0]*int(eval(input())): s=eval(input()) a,b=f() h=g(26,a) print((''.join(z[h*(z.index(c)-b)%26]if c in z else c for c in s)))
14
14
422
440
z = "abcdefghijklmnopqrstuvwxyz" e = lambda x, i, j: z[(z.index(x) * i + j) % 26] def f(): for i in range(1, 26, 2): for j in range(26): if ( "".join(e(c, i, j) for c in "that") in s or "".join(e(c, i, j) for c in "this") in s ): return (i, j) def g(x, y, s=0, t=1): q, r = x // y, x % y return g(y, r, t, s - q * t) if r else t for _ in [0] * int(eval(input())): s = eval(input()) a, b = f() h = g(26, a) print(("".join(z[h * (z.index(c) - b) % 26] if c in z else c for c in s)))
z = "abcdefghijklmnopqrstuvwxyz" e = lambda x, i, j: z[(z.index(x) * i + j) % 26] def f(): for i in (1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25): for j in range(26): if ( "".join(e(c, i, j) for c in "that") in s or "".join(e(c, i, j) for c in "this") in s ): return (i, j) def g(x, y, s=0, t=1): q, r = x // y, x % y return g(y, r, t, s - q * t) if r else t for _ in [0] * int(eval(input())): s = eval(input()) a, b = f() h = g(26, a) print(("".join(z[h * (z.index(c) - b) % 26] if c in z else c for c in s)))
false
0
[ "- for i in range(1, 26, 2):", "+ for i in (1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25):" ]
false
0.035056
0.036083
0.971539
[ "s121593703", "s262226739" ]
u102461423
p03283
python
s682651050
s980653700
1,679
615
26,252
98,212
Accepted
Accepted
63.37
# count p<=x<=q and p<=y <=q # 長方形に含まれる格子点の数 import numpy as np N,M,Q = list(map(int,input().split())) cnt = [[0]*(N+1) for _ in range(N+1)] for _ in range(M): x,y = list(map(int,input().split())) cnt[x][y] += 1 # cumsumだけnumpyを使って、添字アクセスするときはlistの方が速い cnt = np.cumsum(cnt,axis=0).cumsum(axis=1).tolist() for _ in range(Q): p,q = list(map(int,input().split())) p -= 1 x = cnt[q][q] x -= cnt[q][p] x -= cnt[p][q] x += cnt[p][p] print(x)
import numpy as np import sys readline = sys.stdin.readline readlines = sys.stdin.readlines N,M,Q = list(map(int,readline().split())) lines = readlines() L,R = np.array([line.split() for line in lines[:M]],np.int32).T P,Q = np.array([line.split() for line in lines[M:]],np.int32).T cnt = np.zeros((N+1,N+1),dtype=np.int32) np.add.at(cnt,(L,R),1) np.cumsum(cnt,axis=0,out=cnt) np.cumsum(cnt,axis=1,out=cnt) P -= 1 x = cnt[Q,Q] - cnt[Q,P] - cnt[P,Q] + cnt[P,P] print(('\n'.join(x.astype(str))))
21
19
458
506
# count p<=x<=q and p<=y <=q # 長方形に含まれる格子点の数 import numpy as np N, M, Q = list(map(int, input().split())) cnt = [[0] * (N + 1) for _ in range(N + 1)] for _ in range(M): x, y = list(map(int, input().split())) cnt[x][y] += 1 # cumsumだけnumpyを使って、添字アクセスするときはlistの方が速い cnt = np.cumsum(cnt, axis=0).cumsum(axis=1).tolist() for _ in range(Q): p, q = list(map(int, input().split())) p -= 1 x = cnt[q][q] x -= cnt[q][p] x -= cnt[p][q] x += cnt[p][p] print(x)
import numpy as np import sys readline = sys.stdin.readline readlines = sys.stdin.readlines N, M, Q = list(map(int, readline().split())) lines = readlines() L, R = np.array([line.split() for line in lines[:M]], np.int32).T P, Q = np.array([line.split() for line in lines[M:]], np.int32).T cnt = np.zeros((N + 1, N + 1), dtype=np.int32) np.add.at(cnt, (L, R), 1) np.cumsum(cnt, axis=0, out=cnt) np.cumsum(cnt, axis=1, out=cnt) P -= 1 x = cnt[Q, Q] - cnt[Q, P] - cnt[P, Q] + cnt[P, P] print(("\n".join(x.astype(str))))
false
9.52381
[ "-# count p<=x<=q and p<=y <=q", "-# 長方形に含まれる格子点の数", "+import sys", "-N, M, Q = list(map(int, input().split()))", "-cnt = [[0] * (N + 1) for _ in range(N + 1)]", "-for _ in range(M):", "- x, y = list(map(int, input().split()))", "- cnt[x][y] += 1", "-# cumsumだけnumpyを使って、添字アクセスするときはlistの方が速い", "-cnt = np.cumsum(cnt, axis=0).cumsum(axis=1).tolist()", "-for _ in range(Q):", "- p, q = list(map(int, input().split()))", "- p -= 1", "- x = cnt[q][q]", "- x -= cnt[q][p]", "- x -= cnt[p][q]", "- x += cnt[p][p]", "- print(x)", "+readline = sys.stdin.readline", "+readlines = sys.stdin.readlines", "+N, M, Q = list(map(int, readline().split()))", "+lines = readlines()", "+L, R = np.array([line.split() for line in lines[:M]], np.int32).T", "+P, Q = np.array([line.split() for line in lines[M:]], np.int32).T", "+cnt = np.zeros((N + 1, N + 1), dtype=np.int32)", "+np.add.at(cnt, (L, R), 1)", "+np.cumsum(cnt, axis=0, out=cnt)", "+np.cumsum(cnt, axis=1, out=cnt)", "+P -= 1", "+x = cnt[Q, Q] - cnt[Q, P] - cnt[P, Q] + cnt[P, P]", "+print((\"\\n\".join(x.astype(str))))" ]
false
0.450368
0.266438
1.69033
[ "s682651050", "s980653700" ]
u858523893
p03805
python
s822415184
s087150706
106
35
3,064
3,064
Accepted
Accepted
66.98
N, M = list(map(int, input().split())) paths = set() for i in range(M) : _f, _t = list(map(int, input().split())) paths.add((_f - 1, _t - 1)) paths.add((_t - 1, _f - 1)) zeromask = "".join(['0' for x in range(N)]) fullmask = "".join(['1' for x in range(N)]) cnt = 0 def do_mask(m, idx) : return m[:idx] + '1' + m[idx + 1:] def dfs(m, idx) : global cnt new_mask = do_mask(m, idx) if new_mask == fullmask : cnt += 1 else : for i in range(N) : if i != idx and m[idx] != '1' and (idx, i) in paths: dfs(new_mask, i) dfs(zeromask, 0) print(cnt)
N, M = list(map(int, input().split())) a, b = [], [] for i in range(M) : _a, _b = list(map(int, input().split())) a.append(_a - 1) b.append(_b - 1) zero_mask = "".join(['0' for x in range(N)]) full_mask = "".join(['1' for x in range(N)]) paths_cnt = 0 paths_set = set() def do_mask(m, idx) : newmask = m[:idx] + '1' + m[idx + 1:] return newmask def dfs(m, idx) : global paths_cnt # print("DBG, do dfs with : ", m, idx) # do mask for current idx newmask = do_mask(m, idx) if newmask == full_mask : paths_cnt += 1 else : for i in range(N) : # print("DBG2 : ", idx != i, newmask[i] != '1', (idx, i) in paths_set, (idx, i)) if idx != i and newmask[i] != '1' and (idx, i) in paths_set: dfs(newmask, i) # generate map for i in range(M) : paths_set.add((a[i], b[i])) paths_set.add((b[i], a[i])) dfs(zero_mask, 0) print(paths_cnt)
28
39
651
980
N, M = list(map(int, input().split())) paths = set() for i in range(M): _f, _t = list(map(int, input().split())) paths.add((_f - 1, _t - 1)) paths.add((_t - 1, _f - 1)) zeromask = "".join(["0" for x in range(N)]) fullmask = "".join(["1" for x in range(N)]) cnt = 0 def do_mask(m, idx): return m[:idx] + "1" + m[idx + 1 :] def dfs(m, idx): global cnt new_mask = do_mask(m, idx) if new_mask == fullmask: cnt += 1 else: for i in range(N): if i != idx and m[idx] != "1" and (idx, i) in paths: dfs(new_mask, i) dfs(zeromask, 0) print(cnt)
N, M = list(map(int, input().split())) a, b = [], [] for i in range(M): _a, _b = list(map(int, input().split())) a.append(_a - 1) b.append(_b - 1) zero_mask = "".join(["0" for x in range(N)]) full_mask = "".join(["1" for x in range(N)]) paths_cnt = 0 paths_set = set() def do_mask(m, idx): newmask = m[:idx] + "1" + m[idx + 1 :] return newmask def dfs(m, idx): global paths_cnt # print("DBG, do dfs with : ", m, idx) # do mask for current idx newmask = do_mask(m, idx) if newmask == full_mask: paths_cnt += 1 else: for i in range(N): # print("DBG2 : ", idx != i, newmask[i] != '1', (idx, i) in paths_set, (idx, i)) if idx != i and newmask[i] != "1" and (idx, i) in paths_set: dfs(newmask, i) # generate map for i in range(M): paths_set.add((a[i], b[i])) paths_set.add((b[i], a[i])) dfs(zero_mask, 0) print(paths_cnt)
false
28.205128
[ "-paths = set()", "+a, b = [], []", "- _f, _t = list(map(int, input().split()))", "- paths.add((_f - 1, _t - 1))", "- paths.add((_t - 1, _f - 1))", "-zeromask = \"\".join([\"0\" for x in range(N)])", "-fullmask = \"\".join([\"1\" for x in range(N)])", "-cnt = 0", "+ _a, _b = list(map(int, input().split()))", "+ a.append(_a - 1)", "+ b.append(_b - 1)", "+zero_mask = \"\".join([\"0\" for x in range(N)])", "+full_mask = \"\".join([\"1\" for x in range(N)])", "+paths_cnt = 0", "+paths_set = set()", "- return m[:idx] + \"1\" + m[idx + 1 :]", "+ newmask = m[:idx] + \"1\" + m[idx + 1 :]", "+ return newmask", "- global cnt", "- new_mask = do_mask(m, idx)", "- if new_mask == fullmask:", "- cnt += 1", "+ global paths_cnt", "+ # print(\"DBG, do dfs with : \", m, idx)", "+ # do mask for current idx", "+ newmask = do_mask(m, idx)", "+ if newmask == full_mask:", "+ paths_cnt += 1", "- if i != idx and m[idx] != \"1\" and (idx, i) in paths:", "- dfs(new_mask, i)", "+ # print(\"DBG2 : \", idx != i, newmask[i] != '1', (idx, i) in paths_set, (idx, i))", "+ if idx != i and newmask[i] != \"1\" and (idx, i) in paths_set:", "+ dfs(newmask, i)", "-dfs(zeromask, 0)", "-print(cnt)", "+# generate map", "+for i in range(M):", "+ paths_set.add((a[i], b[i]))", "+ paths_set.add((b[i], a[i]))", "+dfs(zero_mask, 0)", "+print(paths_cnt)" ]
false
0.035863
0.035743
1.003353
[ "s822415184", "s087150706" ]
u813102292
p03583
python
s821855509
s004725006
1,933
1,179
3,064
3,064
Accepted
Accepted
39.01
N = int(eval(input())) w1 = 10**5 w2 = 1 try: for h in range(1,3501): for n in range(1,3501): if (4*h*n-N*(h+n))>0: w1 = (N*h*n)//(4*h*n-N*(h+n)) w2 = (N*h*n)/(4*h*n-N*(h+n)) if w1==w2 and w1>0: raise(Exception) except Exception: print((h,n,w1))
def main(): N = int(eval(input())) w1 = 10**5 w2 = 1 try: for h in range(1,3501): for n in range(1,3501): if (4*h*n-N*(h+n))>0: w1 = (N*h*n)//(4*h*n-N*(h+n)) w2 = (N*h*n)/(4*h*n-N*(h+n)) if w1==w2 and w1>0: raise(Exception) except Exception: print((h,n,w1)) if __name__ == '__main__': main()
13
16
337
442
N = int(eval(input())) w1 = 10**5 w2 = 1 try: for h in range(1, 3501): for n in range(1, 3501): if (4 * h * n - N * (h + n)) > 0: w1 = (N * h * n) // (4 * h * n - N * (h + n)) w2 = (N * h * n) / (4 * h * n - N * (h + n)) if w1 == w2 and w1 > 0: raise (Exception) except Exception: print((h, n, w1))
def main(): N = int(eval(input())) w1 = 10**5 w2 = 1 try: for h in range(1, 3501): for n in range(1, 3501): if (4 * h * n - N * (h + n)) > 0: w1 = (N * h * n) // (4 * h * n - N * (h + n)) w2 = (N * h * n) / (4 * h * n - N * (h + n)) if w1 == w2 and w1 > 0: raise (Exception) except Exception: print((h, n, w1)) if __name__ == "__main__": main()
false
18.75
[ "-N = int(eval(input()))", "-w1 = 10**5", "-w2 = 1", "-try:", "- for h in range(1, 3501):", "- for n in range(1, 3501):", "- if (4 * h * n - N * (h + n)) > 0:", "- w1 = (N * h * n) // (4 * h * n - N * (h + n))", "- w2 = (N * h * n) / (4 * h * n - N * (h + n))", "- if w1 == w2 and w1 > 0:", "- raise (Exception)", "-except Exception:", "- print((h, n, w1))", "+def main():", "+ N = int(eval(input()))", "+ w1 = 10**5", "+ w2 = 1", "+ try:", "+ for h in range(1, 3501):", "+ for n in range(1, 3501):", "+ if (4 * h * n - N * (h + n)) > 0:", "+ w1 = (N * h * n) // (4 * h * n - N * (h + n))", "+ w2 = (N * h * n) / (4 * h * n - N * (h + n))", "+ if w1 == w2 and w1 > 0:", "+ raise (Exception)", "+ except Exception:", "+ print((h, n, w1))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.482844
0.466191
1.035722
[ "s821855509", "s004725006" ]
u707808519
p02555
python
s331220396
s531786971
1,240
60
127,604
9,192
Accepted
Accepted
95.16
MOD = 10**9+7 MAX = 1000010 fac = [0] * MAX finv = [0] * MAX inv = [0] * MAX def COMinit(): fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2, MAX): fac[i] = fac[i-1] * i % MOD inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD finv[i] = finv[i-1] * inv[i] % MOD def COM(n, k): res = 1 for i in range(k): res = res * (n-i) % MOD return res * finv[k] % MOD s = int(eval(input())) x = s//3 COMinit() ans = 0 for i in range(x): ans = (ans + COM(s-2*(i+1)-1, i)) % MOD #print(COM(s-2*(i+1)-1, i)) print(ans)
MOD = 10**9+7 s = int(eval(input())) x = s//3 MAX = s+1 fac = [0] * MAX finv = [0] * MAX inv = [0] * MAX def COMinit(): fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2, MAX): fac[i] = fac[i-1] * i % MOD inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD finv[i] = finv[i-1] * inv[i] % MOD def COM(n, k): res = 1 for i in range(k): res = res * (n-i) % MOD return res * finv[k] % MOD COMinit() ans = 0 for i in range(x): ans = (ans + COM(s-2*(i+1)-1, i)) % MOD #print(COM(s-2*(i+1)-1, i)) print(ans)
32
31
615
610
MOD = 10**9 + 7 MAX = 1000010 fac = [0] * MAX finv = [0] * MAX inv = [0] * MAX def COMinit(): fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2, MAX): fac[i] = fac[i - 1] * i % MOD inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD def COM(n, k): res = 1 for i in range(k): res = res * (n - i) % MOD return res * finv[k] % MOD s = int(eval(input())) x = s // 3 COMinit() ans = 0 for i in range(x): ans = (ans + COM(s - 2 * (i + 1) - 1, i)) % MOD # print(COM(s-2*(i+1)-1, i)) print(ans)
MOD = 10**9 + 7 s = int(eval(input())) x = s // 3 MAX = s + 1 fac = [0] * MAX finv = [0] * MAX inv = [0] * MAX def COMinit(): fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2, MAX): fac[i] = fac[i - 1] * i % MOD inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD def COM(n, k): res = 1 for i in range(k): res = res * (n - i) % MOD return res * finv[k] % MOD COMinit() ans = 0 for i in range(x): ans = (ans + COM(s - 2 * (i + 1) - 1, i)) % MOD # print(COM(s-2*(i+1)-1, i)) print(ans)
false
3.125
[ "-MAX = 1000010", "+s = int(eval(input()))", "+x = s // 3", "+MAX = s + 1", "-s = int(eval(input()))", "-x = s // 3" ]
false
1.257313
0.040729
30.870202
[ "s331220396", "s531786971" ]
u678167152
p03096
python
s163902448
s382209185
919
291
52,120
120,760
Accepted
Accepted
68.34
from collections import defaultdict from bisect import * def solve(): mod = 10**9+7 d = defaultdict(lambda: []) N = int(eval(input())) for i in range(N): a = int(eval(input())) d[a].append(i) selist = [[-1,-1]] ends = [-1] for l in list(d.values()): for i in range(len(l)-1): if l[i+1]-1>l[i]: selist.append([l[i],l[i+1]]) ends.append(l[i+1]) selist = sorted(selist,key=lambda x:x[1]) ends.sort() dp = [0]*(len(selist)) for i in range(1,len(selist)): dp[i] = dp[i-1]+1 ind = bisect_right(ends,selist[i][0]) dp[i] += dp[ind-1] dp[i] %= mod ans = dp[-1]+1 ans %= mod return ans print((solve()))
from collections import defaultdict def solve(): ans = 0 N = int(eval(input())) C = [int(eval(input())) for _ in range(N)] d = defaultdict(lambda: -1) dp = [1]*N d[C[0]] = 0 mod = 10**9+7 for i in range(1,N): dp[i] = dp[i-1] if d[C[i]]>-1 and d[C[i]]!=i-1: dp[i] += dp[d[C[i]]] dp[i] %= mod d[C[i]] = i return dp[-1] print((solve()))
28
17
756
377
from collections import defaultdict from bisect import * def solve(): mod = 10**9 + 7 d = defaultdict(lambda: []) N = int(eval(input())) for i in range(N): a = int(eval(input())) d[a].append(i) selist = [[-1, -1]] ends = [-1] for l in list(d.values()): for i in range(len(l) - 1): if l[i + 1] - 1 > l[i]: selist.append([l[i], l[i + 1]]) ends.append(l[i + 1]) selist = sorted(selist, key=lambda x: x[1]) ends.sort() dp = [0] * (len(selist)) for i in range(1, len(selist)): dp[i] = dp[i - 1] + 1 ind = bisect_right(ends, selist[i][0]) dp[i] += dp[ind - 1] dp[i] %= mod ans = dp[-1] + 1 ans %= mod return ans print((solve()))
from collections import defaultdict def solve(): ans = 0 N = int(eval(input())) C = [int(eval(input())) for _ in range(N)] d = defaultdict(lambda: -1) dp = [1] * N d[C[0]] = 0 mod = 10**9 + 7 for i in range(1, N): dp[i] = dp[i - 1] if d[C[i]] > -1 and d[C[i]] != i - 1: dp[i] += dp[d[C[i]]] dp[i] %= mod d[C[i]] = i return dp[-1] print((solve()))
false
39.285714
[ "-from bisect import *", "+ ans = 0", "+ N = int(eval(input()))", "+ C = [int(eval(input())) for _ in range(N)]", "+ d = defaultdict(lambda: -1)", "+ dp = [1] * N", "+ d[C[0]] = 0", "- d = defaultdict(lambda: [])", "- N = int(eval(input()))", "- for i in range(N):", "- a = int(eval(input()))", "- d[a].append(i)", "- selist = [[-1, -1]]", "- ends = [-1]", "- for l in list(d.values()):", "- for i in range(len(l) - 1):", "- if l[i + 1] - 1 > l[i]:", "- selist.append([l[i], l[i + 1]])", "- ends.append(l[i + 1])", "- selist = sorted(selist, key=lambda x: x[1])", "- ends.sort()", "- dp = [0] * (len(selist))", "- for i in range(1, len(selist)):", "- dp[i] = dp[i - 1] + 1", "- ind = bisect_right(ends, selist[i][0])", "- dp[i] += dp[ind - 1]", "- dp[i] %= mod", "- ans = dp[-1] + 1", "- ans %= mod", "- return ans", "+ for i in range(1, N):", "+ dp[i] = dp[i - 1]", "+ if d[C[i]] > -1 and d[C[i]] != i - 1:", "+ dp[i] += dp[d[C[i]]]", "+ dp[i] %= mod", "+ d[C[i]] = i", "+ return dp[-1]" ]
false
0.007331
0.03578
0.204894
[ "s163902448", "s382209185" ]