user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u317423698
p02732
python
s778252123
s083390161
316
194
40,864
32,196
Accepted
Accepted
38.61
import sys from collections import Counter from functools import lru_cache c = None @lru_cache(maxsize=200000) def _num_of_ways_to_choose(x): v = c[x] return (v * (v - 1)) // 2 def resolve(in_, out): n = int(in_.readline()) a = tuple(map(int, in_.readline().split())) global c c = dict(Counter(a)) _num_of_ways_to_choose.cache_clear() total = sum(map(_num_of_ways_to_choose, c.keys())) for ai in a: ans = total - _num_of_ways_to_choose(ai) + ((c[ai] - 1) * (c[ai] - 2)) // 2 print(ans, file=out) def main(): resolve(sys.stdin.buffer, sys.stdout) if __name__ == '__main__': main()
import sys from collections import Counter c = None def resolve(in_, out): n = int(in_.readline()) a = tuple(map(int, in_.readline().split())) c = dict(Counter(a)) total = sum(v * (v - 1) // 2 for v in c.values()) for ai in a: ans = total - (c[ai] - 1) print(ans, file=out) def main(): resolve(sys.stdin.buffer, sys.stdout) if __name__ == '__main__': main()
32
24
681
434
import sys from collections import Counter from functools import lru_cache c = None @lru_cache(maxsize=200000) def _num_of_ways_to_choose(x): v = c[x] return (v * (v - 1)) // 2 def resolve(in_, out): n = int(in_.readline()) a = tuple(map(int, in_.readline().split())) global c c = dict(Counter(a)) _num_of_ways_to_choose.cache_clear() total = sum(map(_num_of_ways_to_choose, c.keys())) for ai in a: ans = total - _num_of_ways_to_choose(ai) + ((c[ai] - 1) * (c[ai] - 2)) // 2 print(ans, file=out) def main(): resolve(sys.stdin.buffer, sys.stdout) if __name__ == "__main__": main()
import sys from collections import Counter c = None def resolve(in_, out): n = int(in_.readline()) a = tuple(map(int, in_.readline().split())) c = dict(Counter(a)) total = sum(v * (v - 1) // 2 for v in c.values()) for ai in a: ans = total - (c[ai] - 1) print(ans, file=out) def main(): resolve(sys.stdin.buffer, sys.stdout) if __name__ == "__main__": main()
false
25
[ "-from functools import lru_cache", "-", "-", "-@lru_cache(maxsize=200000)", "-def _num_of_ways_to_choose(x):", "- v = c[x]", "- return (v * (v - 1)) // 2", "- global c", "- _num_of_ways_to_choose.cache_clear()", "- total = sum(map(_num_of_ways_to_choose, c.keys()))", "+ total = sum(v * (v - 1) // 2 for v in c.values())", "- ans = total - _num_of_ways_to_choose(ai) + ((c[ai] - 1) * (c[ai] - 2)) // 2", "+ ans = total - (c[ai] - 1)" ]
false
0.103405
0.108836
0.950101
[ "s778252123", "s083390161" ]
u163320134
p02632
python
s387846324
s150296080
1,531
1,395
227,552
241,796
Accepted
Accepted
8.88
mod=10**9+7 k=int(eval(input())) s=eval(input()) l=len(s) fact=[1] for i in range(1,k+l+1): fact.append((fact[-1]*i)%mod) revfact=[] for i in range(k+l+1): revfact.append(pow(fact[i],mod-2,mod)) pow1=[1] pow2=[1] for i in range(1,k+l+1): pow1.append((pow1[-1]*25)%mod) pow2.append((pow2[-1]*26)%mod) ans=0 for i in range(k+l): coef1=(pow1[k-i]*pow2[i])%mod if i<=k: coef2=(fact[k+l-1-i]*revfact[l-1]*revfact[k-i])%mod else: coef2=0 ans+=coef1*coef2 ans%=mod print(ans)
mod=10**9+7 k=int(eval(input())) s=eval(input()) l=len(s) fact=[1] for i in range(1,k+l+1): fact.append((fact[-1]*i)%mod) revfact=[] for i in range(k+l+1): revfact.append(pow(fact[i],mod-2,mod)) pows=[1] for i in range(1,k+l+1): pows.append((pows[-1]*25)%mod) ans=0 for i in range(l,l+k+1): ans+=fact[l+k]*revfact[i]*revfact[l+k-i]*pows[l+k-i] ans%=mod print(ans)
25
18
506
378
mod = 10**9 + 7 k = int(eval(input())) s = eval(input()) l = len(s) fact = [1] for i in range(1, k + l + 1): fact.append((fact[-1] * i) % mod) revfact = [] for i in range(k + l + 1): revfact.append(pow(fact[i], mod - 2, mod)) pow1 = [1] pow2 = [1] for i in range(1, k + l + 1): pow1.append((pow1[-1] * 25) % mod) pow2.append((pow2[-1] * 26) % mod) ans = 0 for i in range(k + l): coef1 = (pow1[k - i] * pow2[i]) % mod if i <= k: coef2 = (fact[k + l - 1 - i] * revfact[l - 1] * revfact[k - i]) % mod else: coef2 = 0 ans += coef1 * coef2 ans %= mod print(ans)
mod = 10**9 + 7 k = int(eval(input())) s = eval(input()) l = len(s) fact = [1] for i in range(1, k + l + 1): fact.append((fact[-1] * i) % mod) revfact = [] for i in range(k + l + 1): revfact.append(pow(fact[i], mod - 2, mod)) pows = [1] for i in range(1, k + l + 1): pows.append((pows[-1] * 25) % mod) ans = 0 for i in range(l, l + k + 1): ans += fact[l + k] * revfact[i] * revfact[l + k - i] * pows[l + k - i] ans %= mod print(ans)
false
28
[ "-pow1 = [1]", "-pow2 = [1]", "+pows = [1]", "- pow1.append((pow1[-1] * 25) % mod)", "- pow2.append((pow2[-1] * 26) % mod)", "+ pows.append((pows[-1] * 25) % mod)", "-for i in range(k + l):", "- coef1 = (pow1[k - i] * pow2[i]) % mod", "- if i <= k:", "- coef2 = (fact[k + l - 1 - i] * revfact[l - 1] * revfact[k - i]) % mod", "- else:", "- coef2 = 0", "- ans += coef1 * coef2", "+for i in range(l, l + k + 1):", "+ ans += fact[l + k] * revfact[i] * revfact[l + k - i] * pows[l + k - i]" ]
false
0.040373
0.039864
1.01276
[ "s387846324", "s150296080" ]
u994988729
p03450
python
s537285540
s640632665
1,224
909
69,572
69,636
Accepted
Accepted
25.74
N, M = list(map(int, input().split())) e_IN = [[] for _ in range(N+1)] e_OUT = [[] for _ in range(N+1)] for _ in range(M): l, r, d = list(map(int, input().split())) e_OUT[l].append((r, d)) e_IN[r].append((l, d)) posx = [-1] * (N + 1) def dfs(v): # 0<=x<=10**9に注意 node = [v] posx[v] = 0 diameter = 0 while node: s = node.pop() ds = posx[s] for t, dt in e_OUT[s]: dist = ds + dt if posx[t] != -1: if posx[t] != dist: return False else: continue posx[t] = dist node.append(t) diameter = max(diameter, dist) if diameter <= 10 ** 9: return True else: return False ans = "Yes" for i in range(N + 1): if len(e_IN[i]) == 0: posx[i] = 0 bl = dfs(i) if not bl: ans = "No" break if - 1 in posx: ans = "No" print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) N, M = list(map(int, readline().split())) e_IN = [[] for _ in range(N+1)] e_OUT = [[] for _ in range(N+1)] for _ in range(M): l, r, d = list(map(int, readline().split())) e_OUT[l].append((r, d)) e_IN[r].append((l, d)) posx = [-1] * (N + 1) def dfs(v): # 0<=x<=10**9に注意 node = [v] posx[v] = 0 diameter = 0 while node: s = node.pop() ds = posx[s] for t, dt in e_OUT[s]: dist = ds + dt if posx[t] != -1: if posx[t] != dist: return False else: continue posx[t] = dist node.append(t) diameter = max(diameter, dist) if diameter <= 10 ** 9: return True else: return False ans = "Yes" for i in range(N + 1): if len(e_IN[i]) == 0: posx[i] = 0 bl = dfs(i) if not bl: ans = "No" break if - 1 in posx: ans = "No" print(ans)
50
56
1,020
1,179
N, M = list(map(int, input().split())) e_IN = [[] for _ in range(N + 1)] e_OUT = [[] for _ in range(N + 1)] for _ in range(M): l, r, d = list(map(int, input().split())) e_OUT[l].append((r, d)) e_IN[r].append((l, d)) posx = [-1] * (N + 1) def dfs(v): #  0<=x<=10**9に注意 node = [v] posx[v] = 0 diameter = 0 while node: s = node.pop() ds = posx[s] for t, dt in e_OUT[s]: dist = ds + dt if posx[t] != -1: if posx[t] != dist: return False else: continue posx[t] = dist node.append(t) diameter = max(diameter, dist) if diameter <= 10**9: return True else: return False ans = "Yes" for i in range(N + 1): if len(e_IN[i]) == 0: posx[i] = 0 bl = dfs(i) if not bl: ans = "No" break if -1 in posx: ans = "No" print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) N, M = list(map(int, readline().split())) e_IN = [[] for _ in range(N + 1)] e_OUT = [[] for _ in range(N + 1)] for _ in range(M): l, r, d = list(map(int, readline().split())) e_OUT[l].append((r, d)) e_IN[r].append((l, d)) posx = [-1] * (N + 1) def dfs(v): #  0<=x<=10**9に注意 node = [v] posx[v] = 0 diameter = 0 while node: s = node.pop() ds = posx[s] for t, dt in e_OUT[s]: dist = ds + dt if posx[t] != -1: if posx[t] != dist: return False else: continue posx[t] = dist node.append(t) diameter = max(diameter, dist) if diameter <= 10**9: return True else: return False ans = "Yes" for i in range(N + 1): if len(e_IN[i]) == 0: posx[i] = 0 bl = dfs(i) if not bl: ans = "No" break if -1 in posx: ans = "No" print(ans)
false
10.714286
[ "-N, M = list(map(int, input().split()))", "+import sys", "+", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+sys.setrecursionlimit(10**7)", "+N, M = list(map(int, readline().split()))", "- l, r, d = list(map(int, input().split()))", "+ l, r, d = list(map(int, readline().split()))" ]
false
0.094284
0.038138
2.472199
[ "s537285540", "s640632665" ]
u609061751
p03033
python
s188711126
s405322120
1,885
1,633
69,600
69,604
Accepted
Accepted
13.37
import sys input = lambda : sys.stdin.readline().rstrip() from heapq import heappush, heappop running = [] events = [] delete = set() n, q = list(map(int, input().split())) for _ in range(n): s, t, x = list(map(int, input().split())) time = max(s - x, 0) if t - x < 0: continue events.append((s - x, x, 1)) # 追加イベント events.append((t - x, x, 0)) # 削除イベント events.sort() ans = [] idx = -1 for _ in range(q): d = int(eval(input())) if d >= events[-1][0]: print((-1)) #ans.append(-1) continue while events[idx + 1][0] <= d: idx += 1 if events[idx][2] == 1: heappush(running, events[idx][1]) delete.discard(events[idx][1]) else: delete.add(events[idx][1]) flag = 1 while running: x = heappop(running) if x not in delete: heappush(running, x) print(x) #ans.append(x) flag = 0 break if flag: print((-1))
def main(): import sys input = lambda : sys.stdin.readline().rstrip() from heapq import heappush, heappop running = [] events = [] delete = set() n, q = list(map(int, input().split())) for _ in range(n): s, t, x = list(map(int, input().split())) time = max(s - x, 0) if t - x < 0: continue events.append((s - x, x, 1)) # 追加イベント events.append((t - x, x, 0)) # 削除イベント events.sort() ans = [] idx = -1 for _ in range(q): d = int(eval(input())) if d >= events[-1][0]: print((-1)) continue while events[idx + 1][0] <= d: idx += 1 if events[idx][2] == 1: heappush(running, events[idx][1]) delete.discard(events[idx][1]) else: delete.add(events[idx][1]) flag = 1 while running: x = heappop(running) if x not in delete: heappush(running, x) print(x) flag = 0 break if flag: print((-1)) if __name__ == '__main__': main()
44
48
1,040
1,203
import sys input = lambda: sys.stdin.readline().rstrip() from heapq import heappush, heappop running = [] events = [] delete = set() n, q = list(map(int, input().split())) for _ in range(n): s, t, x = list(map(int, input().split())) time = max(s - x, 0) if t - x < 0: continue events.append((s - x, x, 1)) # 追加イベント events.append((t - x, x, 0)) # 削除イベント events.sort() ans = [] idx = -1 for _ in range(q): d = int(eval(input())) if d >= events[-1][0]: print((-1)) # ans.append(-1) continue while events[idx + 1][0] <= d: idx += 1 if events[idx][2] == 1: heappush(running, events[idx][1]) delete.discard(events[idx][1]) else: delete.add(events[idx][1]) flag = 1 while running: x = heappop(running) if x not in delete: heappush(running, x) print(x) # ans.append(x) flag = 0 break if flag: print((-1))
def main(): import sys input = lambda: sys.stdin.readline().rstrip() from heapq import heappush, heappop running = [] events = [] delete = set() n, q = list(map(int, input().split())) for _ in range(n): s, t, x = list(map(int, input().split())) time = max(s - x, 0) if t - x < 0: continue events.append((s - x, x, 1)) # 追加イベント events.append((t - x, x, 0)) # 削除イベント events.sort() ans = [] idx = -1 for _ in range(q): d = int(eval(input())) if d >= events[-1][0]: print((-1)) continue while events[idx + 1][0] <= d: idx += 1 if events[idx][2] == 1: heappush(running, events[idx][1]) delete.discard(events[idx][1]) else: delete.add(events[idx][1]) flag = 1 while running: x = heappop(running) if x not in delete: heappush(running, x) print(x) flag = 0 break if flag: print((-1)) if __name__ == "__main__": main()
false
8.333333
[ "-import sys", "+def main():", "+ import sys", "-input = lambda: sys.stdin.readline().rstrip()", "-from heapq import heappush, heappop", "+ input = lambda: sys.stdin.readline().rstrip()", "+ from heapq import heappush, heappop", "-running = []", "-events = []", "-delete = set()", "-n, q = list(map(int, input().split()))", "-for _ in range(n):", "- s, t, x = list(map(int, input().split()))", "- time = max(s - x, 0)", "- if t - x < 0:", "- continue", "- events.append((s - x, x, 1)) # 追加イベント", "- events.append((t - x, x, 0)) # 削除イベント", "-events.sort()", "-ans = []", "-idx = -1", "-for _ in range(q):", "- d = int(eval(input()))", "- if d >= events[-1][0]:", "- print((-1))", "- # ans.append(-1)", "- continue", "- while events[idx + 1][0] <= d:", "- idx += 1", "- if events[idx][2] == 1:", "- heappush(running, events[idx][1])", "- delete.discard(events[idx][1])", "- else:", "- delete.add(events[idx][1])", "- flag = 1", "- while running:", "- x = heappop(running)", "- if x not in delete:", "- heappush(running, x)", "- print(x)", "- # ans.append(x)", "- flag = 0", "- break", "- if flag:", "- print((-1))", "+ running = []", "+ events = []", "+ delete = set()", "+ n, q = list(map(int, input().split()))", "+ for _ in range(n):", "+ s, t, x = list(map(int, input().split()))", "+ time = max(s - x, 0)", "+ if t - x < 0:", "+ continue", "+ events.append((s - x, x, 1)) # 追加イベント", "+ events.append((t - x, x, 0)) # 削除イベント", "+ events.sort()", "+ ans = []", "+ idx = -1", "+ for _ in range(q):", "+ d = int(eval(input()))", "+ if d >= events[-1][0]:", "+ print((-1))", "+ continue", "+ while events[idx + 1][0] <= d:", "+ idx += 1", "+ if events[idx][2] == 1:", "+ heappush(running, events[idx][1])", "+ delete.discard(events[idx][1])", "+ else:", "+ delete.add(events[idx][1])", "+ flag = 1", "+ while running:", "+ x = heappop(running)", "+ if x not in delete:", "+ heappush(running, x)", "+ print(x)", "+ flag = 0", "+ break", "+ if flag:", "+ print((-1))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.046404
0.045978
1.009277
[ "s188711126", "s405322120" ]
u992910889
p03546
python
s595410889
s234950282
197
33
14,644
3,444
Accepted
Accepted
83.25
from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): H, W = list(map(int, input().split())) graph = [[i for i in list(map(int, input().split()))] for _ in range(10)] graph = csr_matrix(graph) dist_matrix = floyd_warshall(csgraph=graph, directed=True, return_predecessors=False) dist_matrix = list(dist_matrix) wall = [[i for i in list(map(int, input().split()))] for _ in range(H)] cnt = 0 for h in range(H): for w in range(W): val = wall[h][w] if val != -1 and val != 1: cnt += dist_matrix[val][1] print((int(cnt))) resolve()
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): # 最短経路問題で使われるアルゴリズムの1つ。 # グラフ上の全ての頂点間の最短経路を探す # 負の閉路(辺の重みの和が負になるような閉路)がない限り、負の辺があっても使える。 # 負の閉路を持つ場合は'NEGATIVE CYCLE'を、そうでない場合には(i,j)成分に # 頂点iから頂点jへの最短経路の距離を格納するdist_listをprintする関数 def warshall_floyd(v_num, dist_lst): # 負の閉路を持つか negative_cycle_flag = False # 頂点iから頂点jへの経路と、頂点kを経由した場合の経路とを比較して # よりコストの合計が小さい方を配列に入れる動的計画法 for k in range(v_num): for i in range(v_num): for j in range(v_num): # i→k→jがつながっててしかもi→jルートよりもイケてるなら更新 if dist_lst[i][k] != INF and dist_lst[k][j] != INF: if dist_lst[i][j] > dist_lst[i][k] + dist_lst[k][j]: dist_lst[i][j] = dist_lst[i][k] + dist_lst[k][j] for v in range(v_num): # dist_lstに負の数が格納されているとは、 # グラフが負の閉路を持つことを意味する if dist_lst[v][v] < 0: negative_cycle_flag = True return dist_lst H, W = list(map(int, input().split())) # 頂点の数と辺の数 v_num, e_num = 10, 100 # 配列dist_lst[a][b]には頂点a,b間の辺のコストを入れておき、 # a=bの時は0を、a,b間の辺が存在しないときはINFを入れておく。 INF = 10 ** 20 dist_lst = [[INF] * v_num for _ in range(v_num)] costs = [[i for i in list(map(int, input().split()))] for _ in range(10)] for s in range(10): for t in range(10): dist_lst[s][t] = costs[s][t] dist_lst = warshall_floyd(v_num, dist_lst) wall = [[i for i in list(map(int, input().split()))] for _ in range(H)] cnt = 0 for h in range(H): for w in range(W): val = wall[h][w] if val != -1: cnt += dist_lst[val][1] print(cnt) resolve()
32
63
787
1,867
from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall import sys sys.setrecursionlimit(10**5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): H, W = list(map(int, input().split())) graph = [[i for i in list(map(int, input().split()))] for _ in range(10)] graph = csr_matrix(graph) dist_matrix = floyd_warshall( csgraph=graph, directed=True, return_predecessors=False ) dist_matrix = list(dist_matrix) wall = [[i for i in list(map(int, input().split()))] for _ in range(H)] cnt = 0 for h in range(H): for w in range(W): val = wall[h][w] if val != -1 and val != 1: cnt += dist_matrix[val][1] print((int(cnt))) resolve()
import sys sys.setrecursionlimit(10**5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): # 最短経路問題で使われるアルゴリズムの1つ。 # グラフ上の全ての頂点間の最短経路を探す # 負の閉路(辺の重みの和が負になるような閉路)がない限り、負の辺があっても使える。 # 負の閉路を持つ場合は'NEGATIVE CYCLE'を、そうでない場合には(i,j)成分に # 頂点iから頂点jへの最短経路の距離を格納するdist_listをprintする関数 def warshall_floyd(v_num, dist_lst): # 負の閉路を持つか negative_cycle_flag = False # 頂点iから頂点jへの経路と、頂点kを経由した場合の経路とを比較して # よりコストの合計が小さい方を配列に入れる動的計画法 for k in range(v_num): for i in range(v_num): for j in range(v_num): # i→k→jがつながっててしかもi→jルートよりもイケてるなら更新 if dist_lst[i][k] != INF and dist_lst[k][j] != INF: if dist_lst[i][j] > dist_lst[i][k] + dist_lst[k][j]: dist_lst[i][j] = dist_lst[i][k] + dist_lst[k][j] for v in range(v_num): # dist_lstに負の数が格納されているとは、 # グラフが負の閉路を持つことを意味する if dist_lst[v][v] < 0: negative_cycle_flag = True return dist_lst H, W = list(map(int, input().split())) # 頂点の数と辺の数 v_num, e_num = 10, 100 # 配列dist_lst[a][b]には頂点a,b間の辺のコストを入れておき、 # a=bの時は0を、a,b間の辺が存在しないときはINFを入れておく。 INF = 10**20 dist_lst = [[INF] * v_num for _ in range(v_num)] costs = [[i for i in list(map(int, input().split()))] for _ in range(10)] for s in range(10): for t in range(10): dist_lst[s][t] = costs[s][t] dist_lst = warshall_floyd(v_num, dist_lst) wall = [[i for i in list(map(int, input().split()))] for _ in range(H)] cnt = 0 for h in range(H): for w in range(W): val = wall[h][w] if val != -1: cnt += dist_lst[val][1] print(cnt) resolve()
false
49.206349
[ "-from scipy.sparse import csr_matrix", "-from scipy.sparse.csgraph import floyd_warshall", "+ # 最短経路問題で使われるアルゴリズムの1つ。", "+ # グラフ上の全ての頂点間の最短経路を探す", "+ # 負の閉路(辺の重みの和が負になるような閉路)がない限り、負の辺があっても使える。", "+ # 負の閉路を持つ場合は'NEGATIVE CYCLE'を、そうでない場合には(i,j)成分に", "+ # 頂点iから頂点jへの最短経路の距離を格納するdist_listをprintする関数", "+ def warshall_floyd(v_num, dist_lst):", "+ # 負の閉路を持つか", "+ negative_cycle_flag = False", "+ # 頂点iから頂点jへの経路と、頂点kを経由した場合の経路とを比較して", "+ # よりコストの合計が小さい方を配列に入れる動的計画法", "+ for k in range(v_num):", "+ for i in range(v_num):", "+ for j in range(v_num):", "+ # i→k→jがつながっててしかもi→jルートよりもイケてるなら更新", "+ if dist_lst[i][k] != INF and dist_lst[k][j] != INF:", "+ if dist_lst[i][j] > dist_lst[i][k] + dist_lst[k][j]:", "+ dist_lst[i][j] = dist_lst[i][k] + dist_lst[k][j]", "+ for v in range(v_num):", "+ # dist_lstに負の数が格納されているとは、", "+ # グラフが負の閉路を持つことを意味する", "+ if dist_lst[v][v] < 0:", "+ negative_cycle_flag = True", "+ return dist_lst", "+", "- graph = [[i for i in list(map(int, input().split()))] for _ in range(10)]", "- graph = csr_matrix(graph)", "- dist_matrix = floyd_warshall(", "- csgraph=graph, directed=True, return_predecessors=False", "- )", "- dist_matrix = list(dist_matrix)", "+ # 頂点の数と辺の数", "+ v_num, e_num = 10, 100", "+ # 配列dist_lst[a][b]には頂点a,b間の辺のコストを入れておき、", "+ # a=bの時は0を、a,b間の辺が存在しないときはINFを入れておく。", "+ INF = 10**20", "+ dist_lst = [[INF] * v_num for _ in range(v_num)]", "+ costs = [[i for i in list(map(int, input().split()))] for _ in range(10)]", "+ for s in range(10):", "+ for t in range(10):", "+ dist_lst[s][t] = costs[s][t]", "+ dist_lst = warshall_floyd(v_num, dist_lst)", "- if val != -1 and val != 1:", "- cnt += dist_matrix[val][1]", "- print((int(cnt)))", "+ if val != -1:", "+ cnt += dist_lst[val][1]", "+ print(cnt)" ]
false
0.568569
0.043032
13.212777
[ "s595410889", "s234950282" ]
u517910772
p04045
python
s516519647
s888813293
66
59
3,060
2,940
Accepted
Accepted
10.61
numbers = {str(i) for i in range(10)} N, K = list(map(int, input().split())) *D, = list(map(str, input().split())) D = set(D) available = numbers - D ans = 0 for i in range(N, 100000): nums = set(str(i)) if nums <= available: print(i) break
def problem_c(): N, K = list(map(int, input().split())) D = list(map(str, input().split())) numbers = {str(i) for i in range(10)} availables = set(numbers) - set(D) for i in range(N, 100000): nums = set(str(i)) if nums <= availables: print(i) return ########## problem_c()
11
14
263
342
numbers = {str(i) for i in range(10)} N, K = list(map(int, input().split())) (*D,) = list(map(str, input().split())) D = set(D) available = numbers - D ans = 0 for i in range(N, 100000): nums = set(str(i)) if nums <= available: print(i) break
def problem_c(): N, K = list(map(int, input().split())) D = list(map(str, input().split())) numbers = {str(i) for i in range(10)} availables = set(numbers) - set(D) for i in range(N, 100000): nums = set(str(i)) if nums <= availables: print(i) return ########## problem_c()
false
21.428571
[ "-numbers = {str(i) for i in range(10)}", "-N, K = list(map(int, input().split()))", "-(*D,) = list(map(str, input().split()))", "-D = set(D)", "-available = numbers - D", "-ans = 0", "-for i in range(N, 100000):", "- nums = set(str(i))", "- if nums <= available:", "- print(i)", "- break", "+def problem_c():", "+ N, K = list(map(int, input().split()))", "+ D = list(map(str, input().split()))", "+ numbers = {str(i) for i in range(10)}", "+ availables = set(numbers) - set(D)", "+ for i in range(N, 100000):", "+ nums = set(str(i))", "+ if nums <= availables:", "+ print(i)", "+ return", "+", "+", "+##########", "+problem_c()" ]
false
0.116699
0.048419
2.4102
[ "s516519647", "s888813293" ]
u367130284
p02949
python
s390815377
s126011158
1,480
944
50,140
46,920
Accepted
Accepted
36.22
import sys input=sys.stdin.readline #危険!基本オフにしろ! def BELLMANFORD(point,n,d,p): cost = [-float("inf")]*(n+1) #infじゃないと閉路検出がうまくいかない cost[point]= 0 for i in range(n-1): #経路の長さは最大n-1であるため for now,lis in list(d.items()): for nex,c in lis: if cost[nex]<cost[now]+c-p: cost[nex]=cost[now]+c-p negative=[0]*(n+1) #負閉路の長さは最大nであるため for i in range(n): #閉路判定 negativeの1は閉路に入っている部分を表す for now,lis in list(d.items()): for nex,c in lis: if negative[now]==1: negative[nex]=1 if cost[nex]<cost[now]+c-p: cost[nex]=cost[now]+c-p negative[now]=1 return cost,negative def main(): n,m,p=list(map(int,input().split())) d={} for s in range(m): a,b,c=list(map(int,input().split())) if a in d: d[a].append((b,c)) else: d[a]=[(b,c)] x,y=(BELLMANFORD(1,n,d,p)) if y[n]==1: print((-1)) else: print((max(x[n],0))) if __name__ == '__main__': main()
import sys input=sys.stdin.readline #危険!基本オフにしろ! def BELLMANFORD(point,n,d,p): cost = [-float("inf")]*(n+1) #infじゃないと閉路検出がうまくいかない cost[point]= 0 for i in range(n-1): #経路の長さは最大n-1であるため for nownode,nextnode,c in d: if cost[nextnode]<cost[nownode]+c-p: cost[nextnode]=cost[nownode]+c-p negative=[0]*(n+1) #負閉路の長さは最大nであるため for i in range(n): #閉路判定 negativeの1は閉路に入っている部分を表す for nownode,nextnode,c in d: if negative[nownode]==1: negative[nextnode]=1 if cost[nextnode]<cost[nownode]+c-p: cost[nextnode]=cost[nownode]+c-p negative[nownode]=1 return cost,negative def main(): n,m,p=list(map(int,input().split())) d=[tuple(map(int,input().split()))for i in [0]*m] x,y=(BELLMANFORD(1,n,d,p)) if y[n]==1: print((-1)) else: print((max(x[n],0))) if __name__ == '__main__': main()
46
38
1,247
1,100
import sys input = sys.stdin.readline # 危険!基本オフにしろ! def BELLMANFORD(point, n, d, p): cost = [-float("inf")] * (n + 1) # infじゃないと閉路検出がうまくいかない cost[point] = 0 for i in range(n - 1): # 経路の長さは最大n-1であるため for now, lis in list(d.items()): for nex, c in lis: if cost[nex] < cost[now] + c - p: cost[nex] = cost[now] + c - p negative = [0] * (n + 1) # 負閉路の長さは最大nであるため for i in range(n): # 閉路判定 negativeの1は閉路に入っている部分を表す for now, lis in list(d.items()): for nex, c in lis: if negative[now] == 1: negative[nex] = 1 if cost[nex] < cost[now] + c - p: cost[nex] = cost[now] + c - p negative[now] = 1 return cost, negative def main(): n, m, p = list(map(int, input().split())) d = {} for s in range(m): a, b, c = list(map(int, input().split())) if a in d: d[a].append((b, c)) else: d[a] = [(b, c)] x, y = BELLMANFORD(1, n, d, p) if y[n] == 1: print((-1)) else: print((max(x[n], 0))) if __name__ == "__main__": main()
import sys input = sys.stdin.readline # 危険!基本オフにしろ! def BELLMANFORD(point, n, d, p): cost = [-float("inf")] * (n + 1) # infじゃないと閉路検出がうまくいかない cost[point] = 0 for i in range(n - 1): # 経路の長さは最大n-1であるため for nownode, nextnode, c in d: if cost[nextnode] < cost[nownode] + c - p: cost[nextnode] = cost[nownode] + c - p negative = [0] * (n + 1) # 負閉路の長さは最大nであるため for i in range(n): # 閉路判定 negativeの1は閉路に入っている部分を表す for nownode, nextnode, c in d: if negative[nownode] == 1: negative[nextnode] = 1 if cost[nextnode] < cost[nownode] + c - p: cost[nextnode] = cost[nownode] + c - p negative[nownode] = 1 return cost, negative def main(): n, m, p = list(map(int, input().split())) d = [tuple(map(int, input().split())) for i in [0] * m] x, y = BELLMANFORD(1, n, d, p) if y[n] == 1: print((-1)) else: print((max(x[n], 0))) if __name__ == "__main__": main()
false
17.391304
[ "- for now, lis in list(d.items()):", "- for nex, c in lis:", "- if cost[nex] < cost[now] + c - p:", "- cost[nex] = cost[now] + c - p", "+ for nownode, nextnode, c in d:", "+ if cost[nextnode] < cost[nownode] + c - p:", "+ cost[nextnode] = cost[nownode] + c - p", "- for now, lis in list(d.items()):", "- for nex, c in lis:", "- if negative[now] == 1:", "- negative[nex] = 1", "- if cost[nex] < cost[now] + c - p:", "- cost[nex] = cost[now] + c - p", "- negative[now] = 1", "+ for nownode, nextnode, c in d:", "+ if negative[nownode] == 1:", "+ negative[nextnode] = 1", "+ if cost[nextnode] < cost[nownode] + c - p:", "+ cost[nextnode] = cost[nownode] + c - p", "+ negative[nownode] = 1", "- d = {}", "- for s in range(m):", "- a, b, c = list(map(int, input().split()))", "- if a in d:", "- d[a].append((b, c))", "- else:", "- d[a] = [(b, c)]", "+ d = [tuple(map(int, input().split())) for i in [0] * m]" ]
false
0.037971
0.037452
1.013849
[ "s390815377", "s126011158" ]
u606045429
p02834
python
s701678020
s071885652
362
311
32,500
31,732
Accepted
Accepted
14.09
from collections import deque N, T, A, *AB = list(map(int, open(0).read().split())) E = [[] for _ in range(N + 1)] for a, b in zip(*[iter(AB)] * 2): E[a].append(b) E[b].append(a) takahashi = [-1] * (N + 1) takahashi[T] = 0 Q = deque([T]) while Q: a = Q.popleft() for b in E[a]: if takahashi[b] != -1: continue takahashi[b] = takahashi[a] + 1 Q.append(b) aoki = [-1] * (N + 1) aoki[A] = 0 Q = deque([A]) while Q: a = Q.popleft() for b in E[a]: if aoki[b] != -1: continue aoki[b] = aoki[a] + 1 Q.append(b) ma = 0 for t, a in zip(takahashi[1:], aoki[1:]): if t < a: ma = max(ma, a) print((ma - 1))
from collections import deque N, u, v, *AB = list(map(int, open(0).read().split())) E = [[] for _ in range(N + 1)] for a, b in zip(*[iter(AB)] * 2): E[a].append(b) E[b].append(a) def solve(s): D = [-1] * (N + 1) D[s] = 0 Q = deque([s]) while Q: a = Q.popleft() for b in E[a]: if D[b] != -1: continue D[b] = D[a] + 1 Q.append(b) return D[1:] T = solve(u) A = solve(v) print((-1 + max(a for t, a in zip(T, A) if t < a)))
37
28
737
540
from collections import deque N, T, A, *AB = list(map(int, open(0).read().split())) E = [[] for _ in range(N + 1)] for a, b in zip(*[iter(AB)] * 2): E[a].append(b) E[b].append(a) takahashi = [-1] * (N + 1) takahashi[T] = 0 Q = deque([T]) while Q: a = Q.popleft() for b in E[a]: if takahashi[b] != -1: continue takahashi[b] = takahashi[a] + 1 Q.append(b) aoki = [-1] * (N + 1) aoki[A] = 0 Q = deque([A]) while Q: a = Q.popleft() for b in E[a]: if aoki[b] != -1: continue aoki[b] = aoki[a] + 1 Q.append(b) ma = 0 for t, a in zip(takahashi[1:], aoki[1:]): if t < a: ma = max(ma, a) print((ma - 1))
from collections import deque N, u, v, *AB = list(map(int, open(0).read().split())) E = [[] for _ in range(N + 1)] for a, b in zip(*[iter(AB)] * 2): E[a].append(b) E[b].append(a) def solve(s): D = [-1] * (N + 1) D[s] = 0 Q = deque([s]) while Q: a = Q.popleft() for b in E[a]: if D[b] != -1: continue D[b] = D[a] + 1 Q.append(b) return D[1:] T = solve(u) A = solve(v) print((-1 + max(a for t, a in zip(T, A) if t < a)))
false
24.324324
[ "-N, T, A, *AB = list(map(int, open(0).read().split()))", "+N, u, v, *AB = list(map(int, open(0).read().split()))", "-takahashi = [-1] * (N + 1)", "-takahashi[T] = 0", "-Q = deque([T])", "-while Q:", "- a = Q.popleft()", "- for b in E[a]:", "- if takahashi[b] != -1:", "- continue", "- takahashi[b] = takahashi[a] + 1", "- Q.append(b)", "-aoki = [-1] * (N + 1)", "-aoki[A] = 0", "-Q = deque([A])", "-while Q:", "- a = Q.popleft()", "- for b in E[a]:", "- if aoki[b] != -1:", "- continue", "- aoki[b] = aoki[a] + 1", "- Q.append(b)", "-ma = 0", "-for t, a in zip(takahashi[1:], aoki[1:]):", "- if t < a:", "- ma = max(ma, a)", "-print((ma - 1))", "+", "+", "+def solve(s):", "+ D = [-1] * (N + 1)", "+ D[s] = 0", "+ Q = deque([s])", "+ while Q:", "+ a = Q.popleft()", "+ for b in E[a]:", "+ if D[b] != -1:", "+ continue", "+ D[b] = D[a] + 1", "+ Q.append(b)", "+ return D[1:]", "+", "+", "+T = solve(u)", "+A = solve(v)", "+print((-1 + max(a for t, a in zip(T, A) if t < a)))" ]
false
0.047053
0.036505
1.288941
[ "s701678020", "s071885652" ]
u340781749
p03295
python
s749781064
s854585960
740
424
33,868
17,016
Accepted
Accepted
42.7
n, m = list(map(int, input().split())) ab = [] for i in range(m): a, b = list(map(int, input().split())) ab.append((a - 1, 2, i)) ab.append((b - 1, 1, i)) ab.sort() ans = 0 separated = [False] * m buf = set() for island, ab, i in ab: if ab == 1: if separated[i]: continue else: ans += 1 for j in buf: separated[j] = True buf.clear() else: buf.add(i) print(ans)
n, m = list(map(int, input().split())) disputes = [] for i in range(m): a, b = list(map(int, input().split())) disputes.append((b, a)) disputes.sort() ans = 0 most_right_bridge = 0 for b, a in disputes: if most_right_bridge <= a: ans += 1 most_right_bridge = b print(ans)
23
13
480
300
n, m = list(map(int, input().split())) ab = [] for i in range(m): a, b = list(map(int, input().split())) ab.append((a - 1, 2, i)) ab.append((b - 1, 1, i)) ab.sort() ans = 0 separated = [False] * m buf = set() for island, ab, i in ab: if ab == 1: if separated[i]: continue else: ans += 1 for j in buf: separated[j] = True buf.clear() else: buf.add(i) print(ans)
n, m = list(map(int, input().split())) disputes = [] for i in range(m): a, b = list(map(int, input().split())) disputes.append((b, a)) disputes.sort() ans = 0 most_right_bridge = 0 for b, a in disputes: if most_right_bridge <= a: ans += 1 most_right_bridge = b print(ans)
false
43.478261
[ "-ab = []", "+disputes = []", "- ab.append((a - 1, 2, i))", "- ab.append((b - 1, 1, i))", "-ab.sort()", "+ disputes.append((b, a))", "+disputes.sort()", "-separated = [False] * m", "-buf = set()", "-for island, ab, i in ab:", "- if ab == 1:", "- if separated[i]:", "- continue", "- else:", "- ans += 1", "- for j in buf:", "- separated[j] = True", "- buf.clear()", "- else:", "- buf.add(i)", "+most_right_bridge = 0", "+for b, a in disputes:", "+ if most_right_bridge <= a:", "+ ans += 1", "+ most_right_bridge = b" ]
false
0.046914
0.046002
1.019829
[ "s749781064", "s854585960" ]
u512212329
p02837
python
s382335135
s960580520
1,206
377
3,064
3,064
Accepted
Accepted
68.74
n = int(eval(input())) g = [[-1] * n for _ in range(n)] # Graph for testimonies. for i in range(n): m = int(eval(input())) for _ in range(m): x, y = [int(z) for z in input().split()] x -= 1 # Zero-indexed. g[i][x] = y # Person i says that person x is honest or not. ans = set() for bb in range(2 ** n): tmp = [0] * n possible = True for shift in range(n): if bb >> shift & 1: tmp[shift] = 1 # Assumes person i is honest or not. for i, j in enumerate(tmp): if j: # Assumed honest. for k in range(n): if g[i][k] == -1: # No testimony. continue if g[i][k] != tmp[k]: # Contradiction! possible = False if possible: ans.add(bin(bb).count('1')) print((max(ans)))
def main(): n = int(eval(input())) ttn = [[-1] * n for _ in range(n)] # Testimonies. for i in range(n): a = int(eval(input())) for j in range(a): x, y = [int(z) for z in input().split()] x -= 1 ttn[i][x] = y # i says that x is honest guy or not. ans = set() # for else で頑張ったが,フラグを作ったほうがずっと分かりやすいだろう。 for i in range(2 ** n): tmp = [i >> j & 1 for j in range(n)] # Bit-shift. for k, tm in enumerate(tmp): if tm: for l, tt in enumerate(ttn[k]): if tt == -1: continue if tt != tmp[l]: break else: continue break else: ans.add(bin(i).count('1')) return max(ans) if __name__ == '__main__': print((main()))
29
30
890
908
n = int(eval(input())) g = [[-1] * n for _ in range(n)] # Graph for testimonies. for i in range(n): m = int(eval(input())) for _ in range(m): x, y = [int(z) for z in input().split()] x -= 1 # Zero-indexed. g[i][x] = y # Person i says that person x is honest or not. ans = set() for bb in range(2**n): tmp = [0] * n possible = True for shift in range(n): if bb >> shift & 1: tmp[shift] = 1 # Assumes person i is honest or not. for i, j in enumerate(tmp): if j: # Assumed honest. for k in range(n): if g[i][k] == -1: # No testimony. continue if g[i][k] != tmp[k]: # Contradiction! possible = False if possible: ans.add(bin(bb).count("1")) print((max(ans)))
def main(): n = int(eval(input())) ttn = [[-1] * n for _ in range(n)] # Testimonies. for i in range(n): a = int(eval(input())) for j in range(a): x, y = [int(z) for z in input().split()] x -= 1 ttn[i][x] = y # i says that x is honest guy or not. ans = set() # for else で頑張ったが,フラグを作ったほうがずっと分かりやすいだろう。 for i in range(2**n): tmp = [i >> j & 1 for j in range(n)] # Bit-shift. for k, tm in enumerate(tmp): if tm: for l, tt in enumerate(ttn[k]): if tt == -1: continue if tt != tmp[l]: break else: continue break else: ans.add(bin(i).count("1")) return max(ans) if __name__ == "__main__": print((main()))
false
3.333333
[ "-n = int(eval(input()))", "-g = [[-1] * n for _ in range(n)] # Graph for testimonies.", "-for i in range(n):", "- m = int(eval(input()))", "- for _ in range(m):", "- x, y = [int(z) for z in input().split()]", "- x -= 1 # Zero-indexed.", "- g[i][x] = y # Person i says that person x is honest or not.", "-ans = set()", "-for bb in range(2**n):", "- tmp = [0] * n", "- possible = True", "- for shift in range(n):", "- if bb >> shift & 1:", "- tmp[shift] = 1 # Assumes person i is honest or not.", "- for i, j in enumerate(tmp):", "- if j: # Assumed honest.", "- for k in range(n):", "- if g[i][k] == -1:", "- # No testimony.", "+def main():", "+ n = int(eval(input()))", "+ ttn = [[-1] * n for _ in range(n)] # Testimonies.", "+ for i in range(n):", "+ a = int(eval(input()))", "+ for j in range(a):", "+ x, y = [int(z) for z in input().split()]", "+ x -= 1", "+ ttn[i][x] = y # i says that x is honest guy or not.", "+ ans = set()", "+ # for else で頑張ったが,フラグを作ったほうがずっと分かりやすいだろう。", "+ for i in range(2**n):", "+ tmp = [i >> j & 1 for j in range(n)] # Bit-shift.", "+ for k, tm in enumerate(tmp):", "+ if tm:", "+ for l, tt in enumerate(ttn[k]):", "+ if tt == -1:", "+ continue", "+ if tt != tmp[l]:", "+ break", "+ else:", "- if g[i][k] != tmp[k]:", "- # Contradiction!", "- possible = False", "- if possible:", "- ans.add(bin(bb).count(\"1\"))", "-print((max(ans)))", "+ break", "+ else:", "+ ans.add(bin(i).count(\"1\"))", "+ return max(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ print((main()))" ]
false
0.046695
0.130196
0.358651
[ "s382335135", "s960580520" ]
u600402037
p02774
python
s826162880
s058518382
1,407
1,104
34,340
32,328
Accepted
Accepted
21.54
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # neg, zero, posに分けて、二分探索 N, K = lr() A = np.array(lr()); A.sort() neg = A[A<0] zero = A[A==0] pos = A[A>0] def check(x): '''x以下の積がK個以上あるならTrueを返す''' cnt = 0 # 最後に2でわる if x >= 0: cnt += len(zero) * N cnt += (np.searchsorted(A, x//pos, side='right')).sum() cnt += (N - np.searchsorted(A, (-x-1)//(-neg), side='right')).sum() cnt -= np.count_nonzero(A*A <= x) assert cnt % 2 == 0 return (cnt//2) >= K ok = 10**20; ng = -10**20 while abs(ng-ok) > 1: mid = (ok+ng) // 2 if check(mid): ok = mid else: ng = mid print(ok) # 30
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # neg, zero, posに分けて、二分探索 N, K = lr() A = np.array(lr()); A.sort() neg = A[A<0] zero = A[A==0] pos = A[A>0] def check(x): '''x以下の積がK個以上あるならTrueを返す''' cnt = 0 # 最後に2でわる if x >= 0: cnt += len(zero) * N cnt += (np.searchsorted(A, x//pos, side='right')).sum() cnt += (N - np.searchsorted(A, (-x-1)//(-neg), side='right')).sum() cnt -= np.count_nonzero(A*A <= x) assert cnt % 2 == 0 return (cnt//2) >= K ok = 10**18; ng = -10**18-1 while abs(ng-ok) > 1: mid = (ok+ng) // 2 if check(mid): ok = mid else: ng = mid print(ok) # 30
36
36
782
784
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # neg, zero, posに分けて、二分探索 N, K = lr() A = np.array(lr()) A.sort() neg = A[A < 0] zero = A[A == 0] pos = A[A > 0] def check(x): """x以下の積がK個以上あるならTrueを返す""" cnt = 0 # 最後に2でわる if x >= 0: cnt += len(zero) * N cnt += (np.searchsorted(A, x // pos, side="right")).sum() cnt += (N - np.searchsorted(A, (-x - 1) // (-neg), side="right")).sum() cnt -= np.count_nonzero(A * A <= x) assert cnt % 2 == 0 return (cnt // 2) >= K ok = 10**20 ng = -(10**20) while abs(ng - ok) > 1: mid = (ok + ng) // 2 if check(mid): ok = mid else: ng = mid print(ok) # 30
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # neg, zero, posに分けて、二分探索 N, K = lr() A = np.array(lr()) A.sort() neg = A[A < 0] zero = A[A == 0] pos = A[A > 0] def check(x): """x以下の積がK個以上あるならTrueを返す""" cnt = 0 # 最後に2でわる if x >= 0: cnt += len(zero) * N cnt += (np.searchsorted(A, x // pos, side="right")).sum() cnt += (N - np.searchsorted(A, (-x - 1) // (-neg), side="right")).sum() cnt -= np.count_nonzero(A * A <= x) assert cnt % 2 == 0 return (cnt // 2) >= K ok = 10**18 ng = -(10**18) - 1 while abs(ng - ok) > 1: mid = (ok + ng) // 2 if check(mid): ok = mid else: ng = mid print(ok) # 30
false
0
[ "-ok = 10**20", "-ng = -(10**20)", "+ok = 10**18", "+ng = -(10**18) - 1" ]
false
0.284165
0.647556
0.438827
[ "s826162880", "s058518382" ]
u297574184
p03987
python
s705097307
s215093690
1,089
297
98,896
37,984
Accepted
Accepted
72.73
class BIT_index: def __init__(self, n): self.BIT_prev = [n] * (n + 1) self.BIT_next = [n] * (n + 1) self.n = n def __addElement(self, BIT, idx): value = idx idx += 1 while idx > 0: BIT[idx] = min(BIT[idx], value) idx -= idx & -idx def addElement(self, idx): self.__addElement(self.BIT_prev, self.n - 1 - idx) self.__addElement(self.BIT_next, idx) def __getIndex(self, BIT, idx): idx += 1 ans = self.n while idx <= self.n: ans = min(ans, BIT[idx]) idx += idx & -idx return ans def getIndexPrev(self, idx): return self.__getIndex(self.BIT_prev, self.n - 1 - idx) def getIndexNext(self, idx): return self.__getIndex(self.BIT_next, idx) N = int(eval(input())) As = list(map(int, input().split())) Bs = [i for A, i in sorted([(As[i], i) for i in range(N)])] BIT = BIT_index(N) ans = 0 for i, B in enumerate(Bs): iN = BIT.getIndexNext(B) iP = BIT.getIndexPrev(B) BIT.addElement(B) ans += (i + 1) * (iN - B) * (B - (N - 1 - iP)) print(ans)
N = int(eval(input())) As = list(map(int, input().split())) iAs = [0] * (N + 1) for i, A in enumerate(As): iAs[A] = i ans = 0 iLs = list(range(N + 1)) iRs = list(range(N + 1)) for A in reversed(list(range(1, N + 1))): iA = iAs[A] iL, iR = iLs[iA], iRs[iA] ans += A * (iA - iL + 1) * (iR - iA + 1) iLs[iR + 1] = iL iRs[iL - 1] = iR print(ans)
46
18
1,182
374
class BIT_index: def __init__(self, n): self.BIT_prev = [n] * (n + 1) self.BIT_next = [n] * (n + 1) self.n = n def __addElement(self, BIT, idx): value = idx idx += 1 while idx > 0: BIT[idx] = min(BIT[idx], value) idx -= idx & -idx def addElement(self, idx): self.__addElement(self.BIT_prev, self.n - 1 - idx) self.__addElement(self.BIT_next, idx) def __getIndex(self, BIT, idx): idx += 1 ans = self.n while idx <= self.n: ans = min(ans, BIT[idx]) idx += idx & -idx return ans def getIndexPrev(self, idx): return self.__getIndex(self.BIT_prev, self.n - 1 - idx) def getIndexNext(self, idx): return self.__getIndex(self.BIT_next, idx) N = int(eval(input())) As = list(map(int, input().split())) Bs = [i for A, i in sorted([(As[i], i) for i in range(N)])] BIT = BIT_index(N) ans = 0 for i, B in enumerate(Bs): iN = BIT.getIndexNext(B) iP = BIT.getIndexPrev(B) BIT.addElement(B) ans += (i + 1) * (iN - B) * (B - (N - 1 - iP)) print(ans)
N = int(eval(input())) As = list(map(int, input().split())) iAs = [0] * (N + 1) for i, A in enumerate(As): iAs[A] = i ans = 0 iLs = list(range(N + 1)) iRs = list(range(N + 1)) for A in reversed(list(range(1, N + 1))): iA = iAs[A] iL, iR = iLs[iA], iRs[iA] ans += A * (iA - iL + 1) * (iR - iA + 1) iLs[iR + 1] = iL iRs[iL - 1] = iR print(ans)
false
60.869565
[ "-class BIT_index:", "- def __init__(self, n):", "- self.BIT_prev = [n] * (n + 1)", "- self.BIT_next = [n] * (n + 1)", "- self.n = n", "-", "- def __addElement(self, BIT, idx):", "- value = idx", "- idx += 1", "- while idx > 0:", "- BIT[idx] = min(BIT[idx], value)", "- idx -= idx & -idx", "-", "- def addElement(self, idx):", "- self.__addElement(self.BIT_prev, self.n - 1 - idx)", "- self.__addElement(self.BIT_next, idx)", "-", "- def __getIndex(self, BIT, idx):", "- idx += 1", "- ans = self.n", "- while idx <= self.n:", "- ans = min(ans, BIT[idx])", "- idx += idx & -idx", "- return ans", "-", "- def getIndexPrev(self, idx):", "- return self.__getIndex(self.BIT_prev, self.n - 1 - idx)", "-", "- def getIndexNext(self, idx):", "- return self.__getIndex(self.BIT_next, idx)", "-", "-", "-Bs = [i for A, i in sorted([(As[i], i) for i in range(N)])]", "-BIT = BIT_index(N)", "+iAs = [0] * (N + 1)", "+for i, A in enumerate(As):", "+ iAs[A] = i", "-for i, B in enumerate(Bs):", "- iN = BIT.getIndexNext(B)", "- iP = BIT.getIndexPrev(B)", "- BIT.addElement(B)", "- ans += (i + 1) * (iN - B) * (B - (N - 1 - iP))", "+iLs = list(range(N + 1))", "+iRs = list(range(N + 1))", "+for A in reversed(list(range(1, N + 1))):", "+ iA = iAs[A]", "+ iL, iR = iLs[iA], iRs[iA]", "+ ans += A * (iA - iL + 1) * (iR - iA + 1)", "+ iLs[iR + 1] = iL", "+ iRs[iL - 1] = iR" ]
false
0.038249
0.034619
1.104849
[ "s705097307", "s215093690" ]
u764604930
p02701
python
s990306807
s044565832
289
263
35,520
35,704
Accepted
Accepted
9
num=eval(input("")) li=[] while(num!=0): li.append(eval(input())) num-=1 a=set(li) print((len(a)))
"""write your code in method solve""" def solve(): number=int(eval(input())) items=[] for i in range(number): item=eval(input()) items.append(item) a=set(items) print((len(a))) return solve()
7
13
100
234
num = eval(input("")) li = [] while num != 0: li.append(eval(input())) num -= 1 a = set(li) print((len(a)))
"""write your code in method solve""" def solve(): number = int(eval(input())) items = [] for i in range(number): item = eval(input()) items.append(item) a = set(items) print((len(a))) return solve()
false
46.153846
[ "-num = eval(input(\"\"))", "-li = []", "-while num != 0:", "- li.append(eval(input()))", "- num -= 1", "-a = set(li)", "-print((len(a)))", "+\"\"\"write your code in method solve\"\"\"", "+", "+", "+def solve():", "+ number = int(eval(input()))", "+ items = []", "+ for i in range(number):", "+ item = eval(input())", "+ items.append(item)", "+ a = set(items)", "+ print((len(a)))", "+ return", "+", "+", "+solve()" ]
false
0.046872
0.045354
1.033477
[ "s990306807", "s044565832" ]
u596276291
p03860
python
s605009377
s832393661
24
20
3,316
3,316
Accepted
Accepted
16.67
from collections import defaultdict def main(): S = eval(input()) print(("A{0}C".format(S.split()[1][0]))) if __name__ == '__main__': main()
from collections import defaultdict def main(): print(("A{0}C".format(input().split()[1][0]))) if __name__ == '__main__': main()
10
9
158
147
from collections import defaultdict def main(): S = eval(input()) print(("A{0}C".format(S.split()[1][0]))) if __name__ == "__main__": main()
from collections import defaultdict def main(): print(("A{0}C".format(input().split()[1][0]))) if __name__ == "__main__": main()
false
10
[ "- S = eval(input())", "- print((\"A{0}C\".format(S.split()[1][0])))", "+ print((\"A{0}C\".format(input().split()[1][0])))" ]
false
0.034979
0.039764
0.879673
[ "s605009377", "s832393661" ]
u779455925
p03078
python
s673260521
s917176202
733
471
148,240
82,388
Accepted
Accepted
35.74
# input = sys.stdin.readline from bisect import * from collections import * from heapq import * X,Y,Z,K=list(map(int,input().split())) A=sorted(list(map(int,input().split())),reverse=True) B=sorted(list(map(int,input().split())),reverse=True) C=sorted(list(map(int,input().split())),reverse=True) lst=[] for a in A: for b in B: lst.append(a+b) lst.sort(reverse=True) lst=lst[:K] _lst=[] for a in lst: for c in C: _lst.append(a+c) _lst.sort(reverse=True) for i in range(K): print((_lst[i]))
from bisect import * from collections import * from fractions import gcd from math import factorial from itertools import * from heapq import * import copy X,Y,Z,K=list(map(int,input().split())) A=sorted(list(map(int,input().split())),reverse=True) B=sorted(list(map(int,input().split())),reverse=True) C=sorted(list(map(int,input().split())),reverse=True) dic={A[0]+B[0]+C[0]:["0_0_0"]} usedlst=set(["0_0_0"]) lst=[] D=[-(A[0]+B[0]+C[0])] heapify(D) def strmode(a,b,c): return(str(a)+"_"+str(b)+"_"+str(c),A[a]+B[b]+C[c]) while len(lst)<K: value=heappop(D) lst.append(-value) a,b,c=list(map(int,dic[-value].pop().split("_"))) for x,y,z in ([[a+1,b,c],[a,b+1,c],[a,b,c+1]]): if x<X and y<Y and z<Z: name,value=strmode(x,y,z) if not name in usedlst: usedlst.add(name) heappush(D,-value) if not value in dic: dic.update({value:[name]}) else: dic[value].append(name) for i in lst: print(i)
25
38
539
1,076
# input = sys.stdin.readline from bisect import * from collections import * from heapq import * X, Y, Z, K = list(map(int, input().split())) A = sorted(list(map(int, input().split())), reverse=True) B = sorted(list(map(int, input().split())), reverse=True) C = sorted(list(map(int, input().split())), reverse=True) lst = [] for a in A: for b in B: lst.append(a + b) lst.sort(reverse=True) lst = lst[:K] _lst = [] for a in lst: for c in C: _lst.append(a + c) _lst.sort(reverse=True) for i in range(K): print((_lst[i]))
from bisect import * from collections import * from fractions import gcd from math import factorial from itertools import * from heapq import * import copy X, Y, Z, K = list(map(int, input().split())) A = sorted(list(map(int, input().split())), reverse=True) B = sorted(list(map(int, input().split())), reverse=True) C = sorted(list(map(int, input().split())), reverse=True) dic = {A[0] + B[0] + C[0]: ["0_0_0"]} usedlst = set(["0_0_0"]) lst = [] D = [-(A[0] + B[0] + C[0])] heapify(D) def strmode(a, b, c): return (str(a) + "_" + str(b) + "_" + str(c), A[a] + B[b] + C[c]) while len(lst) < K: value = heappop(D) lst.append(-value) a, b, c = list(map(int, dic[-value].pop().split("_"))) for x, y, z in [[a + 1, b, c], [a, b + 1, c], [a, b, c + 1]]: if x < X and y < Y and z < Z: name, value = strmode(x, y, z) if not name in usedlst: usedlst.add(name) heappush(D, -value) if not value in dic: dic.update({value: [name]}) else: dic[value].append(name) for i in lst: print(i)
false
34.210526
[ "-# input = sys.stdin.readline", "+from fractions import gcd", "+from math import factorial", "+from itertools import *", "+import copy", "+dic = {A[0] + B[0] + C[0]: [\"0_0_0\"]}", "+usedlst = set([\"0_0_0\"])", "-for a in A:", "- for b in B:", "- lst.append(a + b)", "-lst.sort(reverse=True)", "-lst = lst[:K]", "-_lst = []", "-for a in lst:", "- for c in C:", "- _lst.append(a + c)", "-_lst.sort(reverse=True)", "-for i in range(K):", "- print((_lst[i]))", "+D = [-(A[0] + B[0] + C[0])]", "+heapify(D)", "+", "+", "+def strmode(a, b, c):", "+ return (str(a) + \"_\" + str(b) + \"_\" + str(c), A[a] + B[b] + C[c])", "+", "+", "+while len(lst) < K:", "+ value = heappop(D)", "+ lst.append(-value)", "+ a, b, c = list(map(int, dic[-value].pop().split(\"_\")))", "+ for x, y, z in [[a + 1, b, c], [a, b + 1, c], [a, b, c + 1]]:", "+ if x < X and y < Y and z < Z:", "+ name, value = strmode(x, y, z)", "+ if not name in usedlst:", "+ usedlst.add(name)", "+ heappush(D, -value)", "+ if not value in dic:", "+ dic.update({value: [name]})", "+ else:", "+ dic[value].append(name)", "+for i in lst:", "+ print(i)" ]
false
0.060367
0.051714
1.167326
[ "s673260521", "s917176202" ]
u284854859
p03177
python
s448643570
s298984808
585
502
42,092
41,324
Accepted
Accepted
14.19
import sys input = sys.stdin.readline def matDot(A,B,MOD): N,M,L = len(A),len(A[0]),len(B[0]) res = [[0]*L for i in range(N)] for i in range(N): for j in range(L): s = 0 for k in range(M): s = (s + A[i][k]*B[k][j]) % MOD res[i][j] = s return res def matPow(A,x,MOD): N = len(A) res = [[0]*N for i in range(N)] for i in range(N): res[i][i] = 1 for i in range(x.bit_length()): if (x>>i) & 1: res = matDot(res,A,MOD) A = matDot(A,A,MOD) return res n,k = list(map(int,input().split())) mod = 10**9+7 a = [] for i in range(n): a.append(tuple(map(int,input().split()))) b = matPow(a,k,mod) ans = 0 for i in range(n): for j in range(n): ans = (ans+b[i][j])%mod print(ans)
import sys input = sys.stdin.readline def matDot(A,B,MOD): N,M,L = len(A),len(A[0]),len(B[0]) res = [[0]*L for i in range(N)] for i in range(N): for j in range(L): s = 0 for k in range(M): s = (s + A[i][k]*B[k][j]) % MOD res[i][j] = s return res def matPow(A,x,MOD): N = len(A) res = [[0]*N for i in range(N)] for i in range(N): res[i][i] = 1 for i in range(x.bit_length()): if (x>>i) & 1: res = matDot(res,A,MOD) A = matDot(A,A,MOD) return res def main(): n,k = list(map(int,input().split())) mod = 10**9+7 a = [] for i in range(n): a.append(list(map(int,input().split()))) b = matPow(a,k,mod) ans = 0 for i in range(n): for j in range(n): ans = (ans+b[i][j])%mod print(ans) if __name__ == "__main__": main()
46
50
884
982
import sys input = sys.stdin.readline def matDot(A, B, MOD): N, M, L = len(A), len(A[0]), len(B[0]) res = [[0] * L for i in range(N)] for i in range(N): for j in range(L): s = 0 for k in range(M): s = (s + A[i][k] * B[k][j]) % MOD res[i][j] = s return res def matPow(A, x, MOD): N = len(A) res = [[0] * N for i in range(N)] for i in range(N): res[i][i] = 1 for i in range(x.bit_length()): if (x >> i) & 1: res = matDot(res, A, MOD) A = matDot(A, A, MOD) return res n, k = list(map(int, input().split())) mod = 10**9 + 7 a = [] for i in range(n): a.append(tuple(map(int, input().split()))) b = matPow(a, k, mod) ans = 0 for i in range(n): for j in range(n): ans = (ans + b[i][j]) % mod print(ans)
import sys input = sys.stdin.readline def matDot(A, B, MOD): N, M, L = len(A), len(A[0]), len(B[0]) res = [[0] * L for i in range(N)] for i in range(N): for j in range(L): s = 0 for k in range(M): s = (s + A[i][k] * B[k][j]) % MOD res[i][j] = s return res def matPow(A, x, MOD): N = len(A) res = [[0] * N for i in range(N)] for i in range(N): res[i][i] = 1 for i in range(x.bit_length()): if (x >> i) & 1: res = matDot(res, A, MOD) A = matDot(A, A, MOD) return res def main(): n, k = list(map(int, input().split())) mod = 10**9 + 7 a = [] for i in range(n): a.append(list(map(int, input().split()))) b = matPow(a, k, mod) ans = 0 for i in range(n): for j in range(n): ans = (ans + b[i][j]) % mod print(ans) if __name__ == "__main__": main()
false
8
[ "-n, k = list(map(int, input().split()))", "-mod = 10**9 + 7", "-a = []", "-for i in range(n):", "- a.append(tuple(map(int, input().split())))", "-b = matPow(a, k, mod)", "-ans = 0", "-for i in range(n):", "- for j in range(n):", "- ans = (ans + b[i][j]) % mod", "-print(ans)", "+def main():", "+ n, k = list(map(int, input().split()))", "+ mod = 10**9 + 7", "+ a = []", "+ for i in range(n):", "+ a.append(list(map(int, input().split())))", "+ b = matPow(a, k, mod)", "+ ans = 0", "+ for i in range(n):", "+ for j in range(n):", "+ ans = (ans + b[i][j]) % mod", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.046801
0.056611
0.826704
[ "s448643570", "s298984808" ]
u909643606
p03566
python
s248689433
s490579025
26
17
3,064
3,064
Accepted
Accepted
34.62
def calc_area(v_end, v_start, v_max, dt): kouten_v = (v_end + v_start + dt) / 2 kouten_t = kouten_v - v_start kouten_t_limit1 = max(v_max - v_start, 0) kouten_t_limit2 = min(v_end + dt - v_max, dt) if 0 < kouten_t < dt: area = (v_start + kouten_v) * kouten_t / 2 area += (v_end + kouten_v) * (dt - kouten_t) / 2 area -= (kouten_t_limit2 - kouten_t_limit1) * max(0, (kouten_v - v_max)) / 2 else: area = (v_start + v_end) * dt / 2 return area n=int(eval(input())) t=[int(i) for i in input().split()] v=[int(i) for i in input().split()] max_velocity = [0] for i in range(1, n): max_velocity_ = min(v[i-1], v[i], max_velocity[i-1] + t[i-1], sum(t) - sum(t[:i])) max_velocity.append(max_velocity_) max_velocity.append(0) ok = 0 while ok==0: for i in range(n-1): if abs((max_velocity[i+1]-max_velocity[i])/t[i]) >1: max_velocity[i]=max_velocity[i]-1 break else: ok=1 ans = 0 for i in range(n): ans += calc_area(max_velocity[i+1], max_velocity[i], v[i], t[i]) print(ans)
#区間ごとの面積を計算する def calc_area(v_end, v_start, v_max, dt): kouten_v = (v_end + v_start + dt) / 2 kouten_t = kouten_v - v_start if 0 < kouten_t < dt: area = (v_start + kouten_v) * kouten_t / 2 #左側 area += (v_end + kouten_v) * (dt - kouten_t) / 2 #右側 area -= max(0, (kouten_v - v_max))** 2 #上の三角形 else: area = (v_start + v_end) * dt / 2 return area def main(): #与えられた入力を受け取る n=int(eval(input())) t=[int(i) for i in input().split()] v=[int(i) for i in input().split()] #各区間の許容最大速度を計算する #(この段階では傾きが-1未満になる可能性がある) max_velocity = [0] for i in range(1, n): max_velocity_ = min(v[i-1], v[i], max_velocity[i-1] + t[i-1]) max_velocity.append(max_velocity_) max_velocity.append(0) #後ろから走査して、傾きが-1未満を満たすように許容速度をfittingする for i in range(n-1): if max_velocity[-(i+1)] - max_velocity[-(i+2)] < -t[-(i+1)]: max_velocity[-(i+2)] = max_velocity[-(i+1)] + t[-(i+1)] #各区間の面積を計算して足し合わせる ans = 0 for i in range(n): ans += calc_area(max_velocity[i+1], max_velocity[i], v[i], t[i]) print(ans) main()
38
38
1,133
1,168
def calc_area(v_end, v_start, v_max, dt): kouten_v = (v_end + v_start + dt) / 2 kouten_t = kouten_v - v_start kouten_t_limit1 = max(v_max - v_start, 0) kouten_t_limit2 = min(v_end + dt - v_max, dt) if 0 < kouten_t < dt: area = (v_start + kouten_v) * kouten_t / 2 area += (v_end + kouten_v) * (dt - kouten_t) / 2 area -= (kouten_t_limit2 - kouten_t_limit1) * max(0, (kouten_v - v_max)) / 2 else: area = (v_start + v_end) * dt / 2 return area n = int(eval(input())) t = [int(i) for i in input().split()] v = [int(i) for i in input().split()] max_velocity = [0] for i in range(1, n): max_velocity_ = min( v[i - 1], v[i], max_velocity[i - 1] + t[i - 1], sum(t) - sum(t[:i]) ) max_velocity.append(max_velocity_) max_velocity.append(0) ok = 0 while ok == 0: for i in range(n - 1): if abs((max_velocity[i + 1] - max_velocity[i]) / t[i]) > 1: max_velocity[i] = max_velocity[i] - 1 break else: ok = 1 ans = 0 for i in range(n): ans += calc_area(max_velocity[i + 1], max_velocity[i], v[i], t[i]) print(ans)
# 区間ごとの面積を計算する def calc_area(v_end, v_start, v_max, dt): kouten_v = (v_end + v_start + dt) / 2 kouten_t = kouten_v - v_start if 0 < kouten_t < dt: area = (v_start + kouten_v) * kouten_t / 2 # 左側 area += (v_end + kouten_v) * (dt - kouten_t) / 2 # 右側 area -= max(0, (kouten_v - v_max)) ** 2 # 上の三角形 else: area = (v_start + v_end) * dt / 2 return area def main(): # 与えられた入力を受け取る n = int(eval(input())) t = [int(i) for i in input().split()] v = [int(i) for i in input().split()] # 各区間の許容最大速度を計算する # (この段階では傾きが-1未満になる可能性がある) max_velocity = [0] for i in range(1, n): max_velocity_ = min(v[i - 1], v[i], max_velocity[i - 1] + t[i - 1]) max_velocity.append(max_velocity_) max_velocity.append(0) # 後ろから走査して、傾きが-1未満を満たすように許容速度をfittingする for i in range(n - 1): if max_velocity[-(i + 1)] - max_velocity[-(i + 2)] < -t[-(i + 1)]: max_velocity[-(i + 2)] = max_velocity[-(i + 1)] + t[-(i + 1)] # 各区間の面積を計算して足し合わせる ans = 0 for i in range(n): ans += calc_area(max_velocity[i + 1], max_velocity[i], v[i], t[i]) print(ans) main()
false
0
[ "+# 区間ごとの面積を計算する", "- kouten_t_limit1 = max(v_max - v_start, 0)", "- kouten_t_limit2 = min(v_end + dt - v_max, dt)", "- area = (v_start + kouten_v) * kouten_t / 2", "- area += (v_end + kouten_v) * (dt - kouten_t) / 2", "- area -= (kouten_t_limit2 - kouten_t_limit1) * max(0, (kouten_v - v_max)) / 2", "+ area = (v_start + kouten_v) * kouten_t / 2 # 左側", "+ area += (v_end + kouten_v) * (dt - kouten_t) / 2 # 右側", "+ area -= max(0, (kouten_v - v_max)) ** 2 # 上の三角形", "-n = int(eval(input()))", "-t = [int(i) for i in input().split()]", "-v = [int(i) for i in input().split()]", "-max_velocity = [0]", "-for i in range(1, n):", "- max_velocity_ = min(", "- v[i - 1], v[i], max_velocity[i - 1] + t[i - 1], sum(t) - sum(t[:i])", "- )", "- max_velocity.append(max_velocity_)", "-max_velocity.append(0)", "-ok = 0", "-while ok == 0:", "+def main():", "+ # 与えられた入力を受け取る", "+ n = int(eval(input()))", "+ t = [int(i) for i in input().split()]", "+ v = [int(i) for i in input().split()]", "+ # 各区間の許容最大速度を計算する", "+ # (この段階では傾きが-1未満になる可能性がある)", "+ max_velocity = [0]", "+ for i in range(1, n):", "+ max_velocity_ = min(v[i - 1], v[i], max_velocity[i - 1] + t[i - 1])", "+ max_velocity.append(max_velocity_)", "+ max_velocity.append(0)", "+ # 後ろから走査して、傾きが-1未満を満たすように許容速度をfittingする", "- if abs((max_velocity[i + 1] - max_velocity[i]) / t[i]) > 1:", "- max_velocity[i] = max_velocity[i] - 1", "- break", "- else:", "- ok = 1", "-ans = 0", "-for i in range(n):", "- ans += calc_area(max_velocity[i + 1], max_velocity[i], v[i], t[i])", "-print(ans)", "+ if max_velocity[-(i + 1)] - max_velocity[-(i + 2)] < -t[-(i + 1)]:", "+ max_velocity[-(i + 2)] = max_velocity[-(i + 1)] + t[-(i + 1)]", "+ # 各区間の面積を計算して足し合わせる", "+ ans = 0", "+ for i in range(n):", "+ ans += calc_area(max_velocity[i + 1], max_velocity[i], v[i], t[i])", "+ print(ans)", "+", "+", "+main()" ]
false
0.044142
0.070531
0.62586
[ "s248689433", "s490579025" ]
u191874006
p02598
python
s989947935
s210656001
290
168
92,268
104,292
Accepted
Accepted
42.07
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def f(x): cnt = k for i in a: tmp = math.ceil(i / x) cnt -= tmp - 1 if cnt < 0: return False return True n, k = LI() a = LI() a.sort(reverse=True) ok = sum(a) ng = 0 while ok - ng > 1: mid = (ok + ng) // 2 if f(mid): ok = mid else: ng = mid print(ok)
#!/usr/bin/env python3 n, k = list(map(int, input().split())) a = list(map(int, input().split())) def f(x): cnt = 0 for i in a: cnt += (i-1) // x if cnt > k: return False return True ok = 10**9 ng = 0 while ok - ng > 1: mid = (ok + ng) // 2 if f(mid): ok = mid else: ng = mid print(ok)
40
21
907
381
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def f(x): cnt = k for i in a: tmp = math.ceil(i / x) cnt -= tmp - 1 if cnt < 0: return False return True n, k = LI() a = LI() a.sort(reverse=True) ok = sum(a) ng = 0 while ok - ng > 1: mid = (ok + ng) // 2 if f(mid): ok = mid else: ng = mid print(ok)
#!/usr/bin/env python3 n, k = list(map(int, input().split())) a = list(map(int, input().split())) def f(x): cnt = 0 for i in a: cnt += (i - 1) // x if cnt > k: return False return True ok = 10**9 ng = 0 while ok - ng > 1: mid = (ok + ng) // 2 if f(mid): ok = mid else: ng = mid print(ok)
false
47.5
[ "-import sys", "-import math", "-from bisect import bisect_right as br", "-from bisect import bisect_left as bl", "-", "-sys.setrecursionlimit(2147483647)", "-from heapq import heappush, heappop, heappushpop", "-from collections import defaultdict", "-from itertools import accumulate", "-from collections import Counter", "-from collections import deque", "-from operator import itemgetter", "-from itertools import permutations", "-", "-mod = 10**9 + 7", "-inf = float(\"inf\")", "-", "-", "-def I():", "- return int(sys.stdin.readline())", "-", "-", "-def LI():", "- return list(map(int, sys.stdin.readline().split()))", "+n, k = list(map(int, input().split()))", "+a = list(map(int, input().split()))", "- cnt = k", "+ cnt = 0", "- tmp = math.ceil(i / x)", "- cnt -= tmp - 1", "- if cnt < 0:", "+ cnt += (i - 1) // x", "+ if cnt > k:", "-n, k = LI()", "-a = LI()", "-a.sort(reverse=True)", "-ok = sum(a)", "+ok = 10**9" ]
false
0.038474
0.081947
0.469502
[ "s989947935", "s210656001" ]
u537782349
p03338
python
s678704130
s566458175
43
20
3,064
3,064
Accepted
Accepted
53.49
a = int(eval(input())) b = eval(input()) ans = 0 for i in range(1, a-1): c = b[:i] d = b[i:] e = 0 f = [] for j in range(len(c)): for k in range(len(d)): if c[j] == d[k] and c[j] not in f: e += 1 f.append(c[j]) break ans = max(ans, e) print(ans)
a = int(eval(input())) b = list(eval(input())) c = 0 for i in range(a): d = {} e = {} for j in range(0, min(i+1, a)): if b[j] not in d: d[b[j]] = 1 for j in range(i+1, a): if b[j] in d and b[j] not in e: e[b[j]] = 1 c = max(c, len(e)) print(c)
16
15
341
307
a = int(eval(input())) b = eval(input()) ans = 0 for i in range(1, a - 1): c = b[:i] d = b[i:] e = 0 f = [] for j in range(len(c)): for k in range(len(d)): if c[j] == d[k] and c[j] not in f: e += 1 f.append(c[j]) break ans = max(ans, e) print(ans)
a = int(eval(input())) b = list(eval(input())) c = 0 for i in range(a): d = {} e = {} for j in range(0, min(i + 1, a)): if b[j] not in d: d[b[j]] = 1 for j in range(i + 1, a): if b[j] in d and b[j] not in e: e[b[j]] = 1 c = max(c, len(e)) print(c)
false
6.25
[ "-b = eval(input())", "-ans = 0", "-for i in range(1, a - 1):", "- c = b[:i]", "- d = b[i:]", "- e = 0", "- f = []", "- for j in range(len(c)):", "- for k in range(len(d)):", "- if c[j] == d[k] and c[j] not in f:", "- e += 1", "- f.append(c[j])", "- break", "- ans = max(ans, e)", "-print(ans)", "+b = list(eval(input()))", "+c = 0", "+for i in range(a):", "+ d = {}", "+ e = {}", "+ for j in range(0, min(i + 1, a)):", "+ if b[j] not in d:", "+ d[b[j]] = 1", "+ for j in range(i + 1, a):", "+ if b[j] in d and b[j] not in e:", "+ e[b[j]] = 1", "+ c = max(c, len(e))", "+print(c)" ]
false
0.079116
0.068279
1.158723
[ "s678704130", "s566458175" ]
u512212329
p02660
python
s427472443
s333738431
190
124
9,320
9,448
Accepted
Accepted
34.74
from itertools import accumulate from collections import defaultdict def main(): n = int(eval(input())) prime_counter = defaultdict(int) acc = tuple(accumulate(list(range(1, 42)))) # 10^12 < 2^39 def facs(): yield 2 for x in range(10 ** 6): yield x * 2 + 3 for fac in facs(): while fac * fac <= n: if n % fac == 0: n //= fac prime_counter[fac] += 1 else: break if n != 1: prime_counter[n] += 1 ans = 0 for c in list(prime_counter.values()): for i, x in enumerate(acc): if c < x: tmp = i break ans += tmp print(ans) if __name__ == '__main__': main()
from itertools import accumulate from collections import defaultdict def main(): n = int(eval(input())) prime_counter = defaultdict(int) acc = tuple(accumulate(list(range(1, 42)))) # 10^12 < 2^39 def facs(): yield 2 for x in range(10 ** 6): yield x * 2 + 3 for fac in facs(): while n % fac == 0: n //= fac prime_counter[fac] += 1 if fac * fac > n: break if n != 1: prime_counter[n] += 1 ans = 0 for c in list(prime_counter.values()): for i, x in enumerate(acc): if c < x: tmp = i break ans += tmp print(ans) if __name__ == '__main__': main()
36
35
790
754
from itertools import accumulate from collections import defaultdict def main(): n = int(eval(input())) prime_counter = defaultdict(int) acc = tuple(accumulate(list(range(1, 42)))) # 10^12 < 2^39 def facs(): yield 2 for x in range(10**6): yield x * 2 + 3 for fac in facs(): while fac * fac <= n: if n % fac == 0: n //= fac prime_counter[fac] += 1 else: break if n != 1: prime_counter[n] += 1 ans = 0 for c in list(prime_counter.values()): for i, x in enumerate(acc): if c < x: tmp = i break ans += tmp print(ans) if __name__ == "__main__": main()
from itertools import accumulate from collections import defaultdict def main(): n = int(eval(input())) prime_counter = defaultdict(int) acc = tuple(accumulate(list(range(1, 42)))) # 10^12 < 2^39 def facs(): yield 2 for x in range(10**6): yield x * 2 + 3 for fac in facs(): while n % fac == 0: n //= fac prime_counter[fac] += 1 if fac * fac > n: break if n != 1: prime_counter[n] += 1 ans = 0 for c in list(prime_counter.values()): for i, x in enumerate(acc): if c < x: tmp = i break ans += tmp print(ans) if __name__ == "__main__": main()
false
2.777778
[ "- while fac * fac <= n:", "- if n % fac == 0:", "- n //= fac", "- prime_counter[fac] += 1", "- else:", "- break", "+ while n % fac == 0:", "+ n //= fac", "+ prime_counter[fac] += 1", "+ if fac * fac > n:", "+ break" ]
false
0.271702
0.035847
7.579433
[ "s427472443", "s333738431" ]
u135389999
p02773
python
s468811184
s666332549
1,309
801
96,984
45,040
Accepted
Accepted
38.81
n = int(eval(input())) l_d = {} max_n = 0 max_w = [] for i in range(n): n = str(eval(input())) if n in l_d: l_d[n] += 1 if l_d[n] > max_n: max_w = [] max_w.append(n) max_n = l_d[n] elif l_d[n] == max_n: max_w.append(n) else: l_d[n] = 1 if max_n <= 1: max_w.append(n) max_w.sort() for j in max_w: print(j)
import collections n = int(eval(input())) l = [] for i in range(n): l.append(str(eval(input()))) c = collections.Counter(l) c = c.most_common() max_l = c[0][1] ans = [] for i in c: if i[1] == max_l: ans.append(i[0]) else: break ans.sort() for i in ans: print(i)
22
19
442
301
n = int(eval(input())) l_d = {} max_n = 0 max_w = [] for i in range(n): n = str(eval(input())) if n in l_d: l_d[n] += 1 if l_d[n] > max_n: max_w = [] max_w.append(n) max_n = l_d[n] elif l_d[n] == max_n: max_w.append(n) else: l_d[n] = 1 if max_n <= 1: max_w.append(n) max_w.sort() for j in max_w: print(j)
import collections n = int(eval(input())) l = [] for i in range(n): l.append(str(eval(input()))) c = collections.Counter(l) c = c.most_common() max_l = c[0][1] ans = [] for i in c: if i[1] == max_l: ans.append(i[0]) else: break ans.sort() for i in ans: print(i)
false
13.636364
[ "+import collections", "+", "-l_d = {}", "-max_n = 0", "-max_w = []", "+l = []", "- n = str(eval(input()))", "- if n in l_d:", "- l_d[n] += 1", "- if l_d[n] > max_n:", "- max_w = []", "- max_w.append(n)", "- max_n = l_d[n]", "- elif l_d[n] == max_n:", "- max_w.append(n)", "+ l.append(str(eval(input())))", "+c = collections.Counter(l)", "+c = c.most_common()", "+max_l = c[0][1]", "+ans = []", "+for i in c:", "+ if i[1] == max_l:", "+ ans.append(i[0])", "- l_d[n] = 1", "- if max_n <= 1:", "- max_w.append(n)", "-max_w.sort()", "-for j in max_w:", "- print(j)", "+ break", "+ans.sort()", "+for i in ans:", "+ print(i)" ]
false
0.087345
0.101386
0.86151
[ "s468811184", "s666332549" ]
u602702913
p02398
python
s502808222
s307685973
70
20
7,704
5,596
Accepted
Accepted
71.43
a,b,c=list(map(int,input().split())) x=0 for i in range(a,b+1): if c%i==0: x+=1 print(x)
a,b,c=list(map(int,input().split())) y=0 for x in range(a,b+1): if c%x==0: y+=1 print(y)
7
11
99
114
a, b, c = list(map(int, input().split())) x = 0 for i in range(a, b + 1): if c % i == 0: x += 1 print(x)
a, b, c = list(map(int, input().split())) y = 0 for x in range(a, b + 1): if c % x == 0: y += 1 print(y)
false
36.363636
[ "-x = 0", "-for i in range(a, b + 1):", "- if c % i == 0:", "- x += 1", "-print(x)", "+y = 0", "+for x in range(a, b + 1):", "+ if c % x == 0:", "+ y += 1", "+print(y)" ]
false
0.037485
0.038166
0.982156
[ "s502808222", "s307685973" ]
u670180528
p03295
python
s243314904
s691112087
219
141
25,312
25,132
Accepted
Accepted
35.62
n,m,*t=list(map(int,open(0).read().split())) c=d=0 for b,a in sorted([(b,a)for a,b in zip(*[iter(t)]*2)]): if a>d:c+=1;d=b-1 print(c)
n,m,*t=list(map(int,open(0).read().split()));r=[n+1]*(n+1) for a,b in zip(*[iter(t)]*2): r[a]=min(r[a],b) a=0;cur=n+1 for i in range(n+1): cur=min(cur, r[i]) if i==cur: cur=r[i] a+=1 print(a)
5
10
132
201
n, m, *t = list(map(int, open(0).read().split())) c = d = 0 for b, a in sorted([(b, a) for a, b in zip(*[iter(t)] * 2)]): if a > d: c += 1 d = b - 1 print(c)
n, m, *t = list(map(int, open(0).read().split())) r = [n + 1] * (n + 1) for a, b in zip(*[iter(t)] * 2): r[a] = min(r[a], b) a = 0 cur = n + 1 for i in range(n + 1): cur = min(cur, r[i]) if i == cur: cur = r[i] a += 1 print(a)
false
50
[ "-c = d = 0", "-for b, a in sorted([(b, a) for a, b in zip(*[iter(t)] * 2)]):", "- if a > d:", "- c += 1", "- d = b - 1", "-print(c)", "+r = [n + 1] * (n + 1)", "+for a, b in zip(*[iter(t)] * 2):", "+ r[a] = min(r[a], b)", "+a = 0", "+cur = n + 1", "+for i in range(n + 1):", "+ cur = min(cur, r[i])", "+ if i == cur:", "+ cur = r[i]", "+ a += 1", "+print(a)" ]
false
0.043842
0.035886
1.221694
[ "s243314904", "s691112087" ]
u970197315
p03910
python
s177507277
s531006693
625
22
187,168
3,316
Accepted
Accepted
96.48
# B - Exactly N points n=int(eval(input())) if n==1: print((1)) exit() t=0 acc=[] for i in range(1,n+1): t+=i acc.append(t) max_v=-1 for i in range(len(acc)-1): if acc[i]<n<=acc[i+1]: max_v=i+2 break ans=[] ans.append(max_v) cur=max_v vv=acc[i+1] vv-=cur s=max_v while vv and s<n: cur-=1 if vv>cur and s+cur<=n: vv-=cur ans.append(cur) s+=cur elif vv<cur: continue elif vv==cur: vv-=cur ans.append(cur) s+=cur for a in ans: print(a)
n=int(eval(input())) c=0 for i in range(1,n+1): if i*(i+1)//2>=n: c=i break for i in range(c,0,-1): if i<=n: print(i) n-=i
37
10
575
145
# B - Exactly N points n = int(eval(input())) if n == 1: print((1)) exit() t = 0 acc = [] for i in range(1, n + 1): t += i acc.append(t) max_v = -1 for i in range(len(acc) - 1): if acc[i] < n <= acc[i + 1]: max_v = i + 2 break ans = [] ans.append(max_v) cur = max_v vv = acc[i + 1] vv -= cur s = max_v while vv and s < n: cur -= 1 if vv > cur and s + cur <= n: vv -= cur ans.append(cur) s += cur elif vv < cur: continue elif vv == cur: vv -= cur ans.append(cur) s += cur for a in ans: print(a)
n = int(eval(input())) c = 0 for i in range(1, n + 1): if i * (i + 1) // 2 >= n: c = i break for i in range(c, 0, -1): if i <= n: print(i) n -= i
false
72.972973
[ "-# B - Exactly N points", "-if n == 1:", "- print((1))", "- exit()", "-t = 0", "-acc = []", "+c = 0", "- t += i", "- acc.append(t)", "-max_v = -1", "-for i in range(len(acc) - 1):", "- if acc[i] < n <= acc[i + 1]:", "- max_v = i + 2", "+ if i * (i + 1) // 2 >= n:", "+ c = i", "-ans = []", "-ans.append(max_v)", "-cur = max_v", "-vv = acc[i + 1]", "-vv -= cur", "-s = max_v", "-while vv and s < n:", "- cur -= 1", "- if vv > cur and s + cur <= n:", "- vv -= cur", "- ans.append(cur)", "- s += cur", "- elif vv < cur:", "- continue", "- elif vv == cur:", "- vv -= cur", "- ans.append(cur)", "- s += cur", "-for a in ans:", "- print(a)", "+for i in range(c, 0, -1):", "+ if i <= n:", "+ print(i)", "+ n -= i" ]
false
0.143352
0.037147
3.85903
[ "s177507277", "s531006693" ]
u970197315
p02803
python
s237141903
s452845073
300
226
9,332
9,472
Accepted
Accepted
24.67
from collections import deque def bfs(sy,sx): q=deque([[sy,sx]]) visited[sy][sx]=0 while q: y,x=q.popleft() for dy,dx in ([1,0],[-1,0],[0,1],[0,-1]): ny,nx=y+dy,x+dx if ny<0 or ny>h-1 or nx<0 or nx>w-1 or path[ny][nx]=="#":continue if path[ny][nx]=="." and visited[ny][nx]==-1: visited[ny][nx]=visited[y][x]+1 q.append([ny,nx]) res=-1 for i in range(h): for j in range(w): res=max(visited[i][j],res) return res h,w=list(map(int,input().split())) path=[eval(input()) for i in range(h)] visited=[[-1]*w for i in range(h)] sy,sx=0,0 gy,gx=0,0 ans=0 for i in range(h): for j in range(w): if path[i][j]=="#":continue sy=i sx=j visited=[[-1]*w for _ in range(h)] t=bfs(sy,sx) ans=max(t,ans) print(ans)
from collections import deque def bfs(y,x): q=deque([(y,x)]) visited[y][x]=0 while q: cy,cx=q.popleft() for dy,dx in [(1,0),(-1,0),(0,1),(0,-1)]: ny,nx=cy+dy,cx+dx if 0<=ny<h and 0<=nx<w and visited[ny][nx]==-1: if s[ny][nx]=="#":continue visited[ny][nx]=visited[cy][cx]+1 q.append((ny,nx)) res=0 for i in range(h): for j in range(w): if s[i][j]!="#": res=max(res,visited[i][j]) return res h,w=list(map(int,input().split())) s=[eval(input()) for _ in range(h)] ans=0 for i in range(h): for j in range(w): if s[i][j]=="#":continue sh=i sw=j visited=[[-1]*w for _ in range(h)] ans=max(ans,bfs(sh,sw)) print(ans)
34
31
809
726
from collections import deque def bfs(sy, sx): q = deque([[sy, sx]]) visited[sy][sx] = 0 while q: y, x = q.popleft() for dy, dx in ([1, 0], [-1, 0], [0, 1], [0, -1]): ny, nx = y + dy, x + dx if ny < 0 or ny > h - 1 or nx < 0 or nx > w - 1 or path[ny][nx] == "#": continue if path[ny][nx] == "." and visited[ny][nx] == -1: visited[ny][nx] = visited[y][x] + 1 q.append([ny, nx]) res = -1 for i in range(h): for j in range(w): res = max(visited[i][j], res) return res h, w = list(map(int, input().split())) path = [eval(input()) for i in range(h)] visited = [[-1] * w for i in range(h)] sy, sx = 0, 0 gy, gx = 0, 0 ans = 0 for i in range(h): for j in range(w): if path[i][j] == "#": continue sy = i sx = j visited = [[-1] * w for _ in range(h)] t = bfs(sy, sx) ans = max(t, ans) print(ans)
from collections import deque def bfs(y, x): q = deque([(y, x)]) visited[y][x] = 0 while q: cy, cx = q.popleft() for dy, dx in [(1, 0), (-1, 0), (0, 1), (0, -1)]: ny, nx = cy + dy, cx + dx if 0 <= ny < h and 0 <= nx < w and visited[ny][nx] == -1: if s[ny][nx] == "#": continue visited[ny][nx] = visited[cy][cx] + 1 q.append((ny, nx)) res = 0 for i in range(h): for j in range(w): if s[i][j] != "#": res = max(res, visited[i][j]) return res h, w = list(map(int, input().split())) s = [eval(input()) for _ in range(h)] ans = 0 for i in range(h): for j in range(w): if s[i][j] == "#": continue sh = i sw = j visited = [[-1] * w for _ in range(h)] ans = max(ans, bfs(sh, sw)) print(ans)
false
8.823529
[ "-def bfs(sy, sx):", "- q = deque([[sy, sx]])", "- visited[sy][sx] = 0", "+def bfs(y, x):", "+ q = deque([(y, x)])", "+ visited[y][x] = 0", "- y, x = q.popleft()", "- for dy, dx in ([1, 0], [-1, 0], [0, 1], [0, -1]):", "- ny, nx = y + dy, x + dx", "- if ny < 0 or ny > h - 1 or nx < 0 or nx > w - 1 or path[ny][nx] == \"#\":", "- continue", "- if path[ny][nx] == \".\" and visited[ny][nx] == -1:", "- visited[ny][nx] = visited[y][x] + 1", "- q.append([ny, nx])", "- res = -1", "+ cy, cx = q.popleft()", "+ for dy, dx in [(1, 0), (-1, 0), (0, 1), (0, -1)]:", "+ ny, nx = cy + dy, cx + dx", "+ if 0 <= ny < h and 0 <= nx < w and visited[ny][nx] == -1:", "+ if s[ny][nx] == \"#\":", "+ continue", "+ visited[ny][nx] = visited[cy][cx] + 1", "+ q.append((ny, nx))", "+ res = 0", "- res = max(visited[i][j], res)", "+ if s[i][j] != \"#\":", "+ res = max(res, visited[i][j])", "-path = [eval(input()) for i in range(h)]", "-visited = [[-1] * w for i in range(h)]", "-sy, sx = 0, 0", "-gy, gx = 0, 0", "+s = [eval(input()) for _ in range(h)]", "- if path[i][j] == \"#\":", "+ if s[i][j] == \"#\":", "- sy = i", "- sx = j", "+ sh = i", "+ sw = j", "- t = bfs(sy, sx)", "- ans = max(t, ans)", "+ ans = max(ans, bfs(sh, sw))" ]
false
0.03774
0.039527
0.954799
[ "s237141903", "s452845073" ]
u989345508
p02665
python
s990737459
s486879983
674
89
650,744
20,136
Accepted
Accepted
86.8
from itertools import accumulate n=int(eval(input())) a=list(map(int,input().split())) c=list(accumulate(a)) b=[0]*(n+1) #大きくしすぎてしまう場合がある #いや上限を考えろや def f(): global n,a,b for i in range(n+1): if i==0: b[0]=min(c[n]-c[0],1) else: b[i]=min(2*(b[i-1]-a[i-1]),c[n]-c[i-1]) if n==0: if a[0]!=1: print((-1)) else: print((1)) elif b[n]!=a[n]: print((-1)) else: print((sum(b))) #print(b) f()
n,*a=list(map(int,open(0).read().split())) t,v=sum(a),[1] for q in a: v+=[min(2*(v[-1]-q),t:=t-q)] if v[-1]<0:print((-1));exit() print((sum(v)))
26
6
519
147
from itertools import accumulate n = int(eval(input())) a = list(map(int, input().split())) c = list(accumulate(a)) b = [0] * (n + 1) # 大きくしすぎてしまう場合がある # いや上限を考えろや def f(): global n, a, b for i in range(n + 1): if i == 0: b[0] = min(c[n] - c[0], 1) else: b[i] = min(2 * (b[i - 1] - a[i - 1]), c[n] - c[i - 1]) if n == 0: if a[0] != 1: print((-1)) else: print((1)) elif b[n] != a[n]: print((-1)) else: print((sum(b))) # print(b) f()
n, *a = list(map(int, open(0).read().split())) t, v = sum(a), [1] for q in a: v += [min(2 * (v[-1] - q), t := t - q)] if v[-1] < 0: print((-1)) exit() print((sum(v)))
false
76.923077
[ "-from itertools import accumulate", "-", "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-c = list(accumulate(a))", "-b = [0] * (n + 1)", "-# 大きくしすぎてしまう場合がある", "-# いや上限を考えろや", "-def f():", "- global n, a, b", "- for i in range(n + 1):", "- if i == 0:", "- b[0] = min(c[n] - c[0], 1)", "- else:", "- b[i] = min(2 * (b[i - 1] - a[i - 1]), c[n] - c[i - 1])", "- if n == 0:", "- if a[0] != 1:", "- print((-1))", "- else:", "- print((1))", "- elif b[n] != a[n]:", "+n, *a = list(map(int, open(0).read().split()))", "+t, v = sum(a), [1]", "+for q in a:", "+ v += [min(2 * (v[-1] - q), t := t - q)]", "+ if v[-1] < 0:", "- else:", "- print((sum(b)))", "- # print(b)", "-", "-", "-f()", "+ exit()", "+print((sum(v)))" ]
false
0.042428
0.069944
0.606598
[ "s990737459", "s486879983" ]
u498487134
p03780
python
s881060162
s311433104
1,338
1,079
39,536
39,536
Accepted
Accepted
19.36
def main(): def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) N,K=MI() a=LI()#下位の連続するn枚が不要なはず a.sort() for i in range(N):#K以上ならば必要 if a[i]>=K: a=a[:i] break N=len(a) #x番目の数が必要かどうかの判定 #必要なものだけで構成された集合をもとに考えれば良いわけではない,不必要な分も考えなければならない def ch(x): #使い回す,i番目まででjが作れるか dp=[0]*K dp[0]=1 for i in range(N): if i==x: continue else: for j in range(K-1,a[i]-1,-1): dp[j]|=dp[j-a[i]] #K未満K-a[x]以上が作れれば良い for j in range(K-a[x],K): if dp[j]: return True return False ng=-1 ok=N while abs(ok-ng)>1: med=(ok+ng)//2 if ch(med): ok=med else: ng=med print((ng+1)) main()
def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): N,K=MI() a=LI()#下位の連続するn枚が不要なはず a.sort() for i in range(N):#K以上ならば必要 if a[i]>=K: a=a[:i] break N=len(a) #x番目の数が必要かどうかの判定 #必要なものだけで構成された集合をもとに考えれば良いわけではない,不必要な分も考えなければならない def ch(x): #使い回す,i番目まででjが作れるか dp=[0]*K dp[0]=1 for i in range(N): if i==x: continue else: for j in range(K-1,a[i]-1,-1): dp[j]|=dp[j-a[i]] #K未満K-a[x]以上が作れれば良い for j in range(K-a[x],K): if dp[j]: return True return False ng=-1 ok=N while abs(ok-ng)>1: med=(ok+ng)//2 if ch(med): ok=med else: ng=med print((ng+1)) main()
55
61
1,175
1,201
def main(): def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) N, K = MI() a = LI() # 下位の連続するn枚が不要なはず a.sort() for i in range(N): # K以上ならば必要 if a[i] >= K: a = a[:i] break N = len(a) # x番目の数が必要かどうかの判定 # 必要なものだけで構成された集合をもとに考えれば良いわけではない,不必要な分も考えなければならない def ch(x): # 使い回す,i番目まででjが作れるか dp = [0] * K dp[0] = 1 for i in range(N): if i == x: continue else: for j in range(K - 1, a[i] - 1, -1): dp[j] |= dp[j - a[i]] # K未満K-a[x]以上が作れれば良い for j in range(K - a[x], K): if dp[j]: return True return False ng = -1 ok = N while abs(ok - ng) > 1: med = (ok + ng) // 2 if ch(med): ok = med else: ng = med print((ng + 1)) main()
def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): N, K = MI() a = LI() # 下位の連続するn枚が不要なはず a.sort() for i in range(N): # K以上ならば必要 if a[i] >= K: a = a[:i] break N = len(a) # x番目の数が必要かどうかの判定 # 必要なものだけで構成された集合をもとに考えれば良いわけではない,不必要な分も考えなければならない def ch(x): # 使い回す,i番目まででjが作れるか dp = [0] * K dp[0] = 1 for i in range(N): if i == x: continue else: for j in range(K - 1, a[i] - 1, -1): dp[j] |= dp[j - a[i]] # K未満K-a[x]以上が作れれば良い for j in range(K - a[x], K): if dp[j]: return True return False ng = -1 ok = N while abs(ok - ng) > 1: med = (ok + ng) // 2 if ch(med): ok = med else: ng = med print((ng + 1)) main()
false
9.836066
[ "+def I():", "+ return int(eval(input()))", "+", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "- def I():", "- return int(eval(input()))", "-", "- def MI():", "- return list(map(int, input().split()))", "-", "- def LI():", "- return list(map(int, input().split()))", "-" ]
false
0.03728
0.038636
0.96492
[ "s881060162", "s311433104" ]
u671889550
p02572
python
s133930038
s486409401
232
117
49,684
94,196
Accepted
Accepted
49.57
import numpy as np n = int(eval(input())) a = np.array(list(map(int, input().split())), dtype = 'object') mod = 10**9 + 7 sq_sum_a = sum(a)**2 sum_sq_a = sum(a**2) sum_cross = (sq_sum_a - sum_sq_a) // 2 ans = sum_cross % mod # xy = ((x + y)**2 - (x**2 + y**2)) // 2 print(ans)
n = int(eval(input())) a = list(map(int, input().split())) mod = 10**9+7 sq_sum_a = sum(a)**2 sum_sq_a = sum([x**2 for x in a]) sum_cross = (sq_sum_a - sum_sq_a) // 2 ans = sum_cross % mod print(ans)
14
11
287
211
import numpy as np n = int(eval(input())) a = np.array(list(map(int, input().split())), dtype="object") mod = 10**9 + 7 sq_sum_a = sum(a) ** 2 sum_sq_a = sum(a**2) sum_cross = (sq_sum_a - sum_sq_a) // 2 ans = sum_cross % mod # xy = ((x + y)**2 - (x**2 + y**2)) // 2 print(ans)
n = int(eval(input())) a = list(map(int, input().split())) mod = 10**9 + 7 sq_sum_a = sum(a) ** 2 sum_sq_a = sum([x**2 for x in a]) sum_cross = (sq_sum_a - sum_sq_a) // 2 ans = sum_cross % mod print(ans)
false
21.428571
[ "-import numpy as np", "-", "-a = np.array(list(map(int, input().split())), dtype=\"object\")", "+a = list(map(int, input().split()))", "-sum_sq_a = sum(a**2)", "+sum_sq_a = sum([x**2 for x in a])", "-# xy = ((x + y)**2 - (x**2 + y**2)) // 2" ]
false
0.218522
0.095781
2.281479
[ "s133930038", "s486409401" ]
u236720912
p03448
python
s354584009
s694427253
54
18
3,188
3,064
Accepted
Accepted
66.67
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) counter = 0 for i in range(0, A+1): for n in range(0, B+1): for t in range(0, C+1): total = 500 * i + 100 * n + 50 * t if total == X: counter += 1 print(counter)
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) counter = 0 for i in range(0, A+1): ans = X - 500 * i if ans > 0: for n in range(0, B+1): ans1 = ans - 100 * n if ans1 > 0 and (ans1 / 50) <= C: counter += 1 elif ans1 == 0: counter += 1 elif ans == 0: counter += 1 print(counter)
13
18
299
412
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) counter = 0 for i in range(0, A + 1): for n in range(0, B + 1): for t in range(0, C + 1): total = 500 * i + 100 * n + 50 * t if total == X: counter += 1 print(counter)
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) counter = 0 for i in range(0, A + 1): ans = X - 500 * i if ans > 0: for n in range(0, B + 1): ans1 = ans - 100 * n if ans1 > 0 and (ans1 / 50) <= C: counter += 1 elif ans1 == 0: counter += 1 elif ans == 0: counter += 1 print(counter)
false
27.777778
[ "- for n in range(0, B + 1):", "- for t in range(0, C + 1):", "- total = 500 * i + 100 * n + 50 * t", "- if total == X:", "+ ans = X - 500 * i", "+ if ans > 0:", "+ for n in range(0, B + 1):", "+ ans1 = ans - 100 * n", "+ if ans1 > 0 and (ans1 / 50) <= C:", "+ elif ans1 == 0:", "+ counter += 1", "+ elif ans == 0:", "+ counter += 1" ]
false
0.087359
0.036941
2.364814
[ "s354584009", "s694427253" ]
u391875425
p03556
python
s494261745
s653499320
67
17
3,188
3,064
Accepted
Accepted
74.63
N = int(eval(input())) for i in range(N,0,-1): if int(i**(1/2)) == i**(1/2): print(i) break
import math print((int(math.sqrt(int(eval(input()))))**2))
5
2
109
51
N = int(eval(input())) for i in range(N, 0, -1): if int(i ** (1 / 2)) == i ** (1 / 2): print(i) break
import math print((int(math.sqrt(int(eval(input())))) ** 2))
false
60
[ "-N = int(eval(input()))", "-for i in range(N, 0, -1):", "- if int(i ** (1 / 2)) == i ** (1 / 2):", "- print(i)", "- break", "+import math", "+", "+print((int(math.sqrt(int(eval(input())))) ** 2))" ]
false
0.040198
0.038696
1.038812
[ "s494261745", "s653499320" ]
u027622859
p03944
python
s967221912
s637949189
449
356
19,492
21,548
Accepted
Accepted
20.71
import numpy as np W, H, N = list(map(int, input().split())) x = [] y = [] a = [] for _ in range(N): b, c, d = list(map(int, input().split())) x.append(b) y.append(c) a.append(d) A = np.zeros((H, W)) for i in range(N): if a[i] == 1: for j in range(x[i]): for k in range(H): A[k][j] = 1 elif a[i] == 2: for j in range(x[i],W): for k in range(H): A[k][j] = 1 elif a[i] == 3: for j in range(y[i]): for k in range(W): A[j][k] = 1 elif a[i] == 4: for j in range(y[i], H): for k in range(W): A[j][k] = 1 print((np.sum(A==0)))
import numpy as np w, h, n = list(map(int, input().split())) xy = np.zeros((w,h)) xya = [[int(a) for a in input().split()] for _ in range(n)] for i in range(n): if xya[i][2]==1: for x in range(xya[i][0]): xy[x][:h] = 1 elif xya[i][2] == 2: for x in range(xya[i][0], w): xy[x][:h] = 1 elif xya[i][2]==3: for x in range(w): for y in range(xya[i][1]): xy[x][y] = 1 elif xya[i][2] == 4: for x in range(w): for y in range(xya[i][1], h): xy[x][y] = 1 wh = [int(item) for wh in xy for item in wh] print((wh.count(0)))
31
21
714
650
import numpy as np W, H, N = list(map(int, input().split())) x = [] y = [] a = [] for _ in range(N): b, c, d = list(map(int, input().split())) x.append(b) y.append(c) a.append(d) A = np.zeros((H, W)) for i in range(N): if a[i] == 1: for j in range(x[i]): for k in range(H): A[k][j] = 1 elif a[i] == 2: for j in range(x[i], W): for k in range(H): A[k][j] = 1 elif a[i] == 3: for j in range(y[i]): for k in range(W): A[j][k] = 1 elif a[i] == 4: for j in range(y[i], H): for k in range(W): A[j][k] = 1 print((np.sum(A == 0)))
import numpy as np w, h, n = list(map(int, input().split())) xy = np.zeros((w, h)) xya = [[int(a) for a in input().split()] for _ in range(n)] for i in range(n): if xya[i][2] == 1: for x in range(xya[i][0]): xy[x][:h] = 1 elif xya[i][2] == 2: for x in range(xya[i][0], w): xy[x][:h] = 1 elif xya[i][2] == 3: for x in range(w): for y in range(xya[i][1]): xy[x][y] = 1 elif xya[i][2] == 4: for x in range(w): for y in range(xya[i][1], h): xy[x][y] = 1 wh = [int(item) for wh in xy for item in wh] print((wh.count(0)))
false
32.258065
[ "-W, H, N = list(map(int, input().split()))", "-x = []", "-y = []", "-a = []", "-for _ in range(N):", "- b, c, d = list(map(int, input().split()))", "- x.append(b)", "- y.append(c)", "- a.append(d)", "-A = np.zeros((H, W))", "-for i in range(N):", "- if a[i] == 1:", "- for j in range(x[i]):", "- for k in range(H):", "- A[k][j] = 1", "- elif a[i] == 2:", "- for j in range(x[i], W):", "- for k in range(H):", "- A[k][j] = 1", "- elif a[i] == 3:", "- for j in range(y[i]):", "- for k in range(W):", "- A[j][k] = 1", "- elif a[i] == 4:", "- for j in range(y[i], H):", "- for k in range(W):", "- A[j][k] = 1", "-print((np.sum(A == 0)))", "+w, h, n = list(map(int, input().split()))", "+xy = np.zeros((w, h))", "+xya = [[int(a) for a in input().split()] for _ in range(n)]", "+for i in range(n):", "+ if xya[i][2] == 1:", "+ for x in range(xya[i][0]):", "+ xy[x][:h] = 1", "+ elif xya[i][2] == 2:", "+ for x in range(xya[i][0], w):", "+ xy[x][:h] = 1", "+ elif xya[i][2] == 3:", "+ for x in range(w):", "+ for y in range(xya[i][1]):", "+ xy[x][y] = 1", "+ elif xya[i][2] == 4:", "+ for x in range(w):", "+ for y in range(xya[i][1], h):", "+ xy[x][y] = 1", "+wh = [int(item) for wh in xy for item in wh]", "+print((wh.count(0)))" ]
false
0.311396
0.57075
0.545591
[ "s967221912", "s637949189" ]
u312025627
p02856
python
s053846100
s913933795
859
255
47,832
42,748
Accepted
Accepted
70.31
def main(): M = int(eval(input())) ans = 0 dc_sum = 0 for i in range(M): d, c = (int(i) for i in input().split()) dc_sum += d*c ans += c if dc_sum % 9 == 0: print((ans - 1 + dc_sum//9 - 1)) else: print((ans - 1 + dc_sum//9)) if __name__ == '__main__': main()
def main(): import sys input = sys.stdin.buffer.readline M = int(eval(input())) ans = 0 dc_sum = 0 for i in range(M): d, c = (int(i) for i in input().split()) dc_sum += d*c ans += c if dc_sum % 9 == 0: print((ans - 1 + dc_sum//9 - 1)) else: print((ans - 1 + dc_sum//9)) if __name__ == '__main__': main()
16
18
334
389
def main(): M = int(eval(input())) ans = 0 dc_sum = 0 for i in range(M): d, c = (int(i) for i in input().split()) dc_sum += d * c ans += c if dc_sum % 9 == 0: print((ans - 1 + dc_sum // 9 - 1)) else: print((ans - 1 + dc_sum // 9)) if __name__ == "__main__": main()
def main(): import sys input = sys.stdin.buffer.readline M = int(eval(input())) ans = 0 dc_sum = 0 for i in range(M): d, c = (int(i) for i in input().split()) dc_sum += d * c ans += c if dc_sum % 9 == 0: print((ans - 1 + dc_sum // 9 - 1)) else: print((ans - 1 + dc_sum // 9)) if __name__ == "__main__": main()
false
11.111111
[ "+ import sys", "+", "+ input = sys.stdin.buffer.readline" ]
false
0.14957
0.042436
3.524574
[ "s053846100", "s913933795" ]
u790372061
p03073
python
s863360383
s239850916
44
31
10,852
3,188
Accepted
Accepted
29.55
from itertools import zip_longest S = eval(input()) ans = 0 for curr, next in list(zip_longest(S, S[1:]))[::2]: if curr == '0': ans += 1 if next == '1': ans += 1 print((min(ans, len(S) - ans)))
from itertools import zip_longest, islice S = eval(input()) ans = 0 for curr, next in islice(zip_longest(S, S[1:]), 0, None, 2): if curr == '0': ans += 1 if next == '1': ans += 1 print((min(ans, len(S) - ans)))
10
10
201
218
from itertools import zip_longest S = eval(input()) ans = 0 for curr, next in list(zip_longest(S, S[1:]))[::2]: if curr == "0": ans += 1 if next == "1": ans += 1 print((min(ans, len(S) - ans)))
from itertools import zip_longest, islice S = eval(input()) ans = 0 for curr, next in islice(zip_longest(S, S[1:]), 0, None, 2): if curr == "0": ans += 1 if next == "1": ans += 1 print((min(ans, len(S) - ans)))
false
0
[ "-from itertools import zip_longest", "+from itertools import zip_longest, islice", "-for curr, next in list(zip_longest(S, S[1:]))[::2]:", "+for curr, next in islice(zip_longest(S, S[1:]), 0, None, 2):" ]
false
0.043499
0.043626
0.997079
[ "s863360383", "s239850916" ]
u371467115
p03331
python
s653898249
s511276618
431
18
3,060
2,940
Accepted
Accepted
95.82
n=int(eval(input())) ans=n for i in range(1,n): l=[int(j) for j in list(str(i))] m=[int(k) for k in list(str(abs(n-i)))] if ans>sum(l)+sum(m): ans=sum(l)+sum(m) print(ans)
# A NL = list(map(int, list(eval(input())))) if NL[0] == 1 and sum(NL) == 1: print((10)) else: print((sum(NL))) #copy code
8
8
182
128
n = int(eval(input())) ans = n for i in range(1, n): l = [int(j) for j in list(str(i))] m = [int(k) for k in list(str(abs(n - i)))] if ans > sum(l) + sum(m): ans = sum(l) + sum(m) print(ans)
# A NL = list(map(int, list(eval(input())))) if NL[0] == 1 and sum(NL) == 1: print((10)) else: print((sum(NL))) # copy code
false
0
[ "-n = int(eval(input()))", "-ans = n", "-for i in range(1, n):", "- l = [int(j) for j in list(str(i))]", "- m = [int(k) for k in list(str(abs(n - i)))]", "- if ans > sum(l) + sum(m):", "- ans = sum(l) + sum(m)", "-print(ans)", "+# A", "+NL = list(map(int, list(eval(input()))))", "+if NL[0] == 1 and sum(NL) == 1:", "+ print((10))", "+else:", "+ print((sum(NL)))", "+# copy code" ]
false
0.230328
0.006536
35.238551
[ "s653898249", "s511276618" ]
u562935282
p02929
python
s642032765
s643079733
153
117
6,964
5,096
Accepted
Accepted
23.53
mod = 10 ** 9 + 7 n = int(eval(input())) s = eval(input()) t = list([1 if x == 'B' else 0 for x in s]) t = tuple((tt - df) % 2 for tt, df in zip(t, reversed(list(range(n * 2))))) # print(t) ans = 1 zeros = 0 ones = 0 for tt in t: if tt == 0: zeros += 1 else: if zeros == 0: print((0)) exit() ans *= zeros ans %= mod zeros -= 1 ones += 1 if zeros > 0: print((0)) exit() for i in range(1, n + 1): ans *= i ans %= mod print(ans)
mod = 10 ** 9 + 7 n = int(eval(input())) s = eval(input()) t = [(ind % 2) ^ (ss == 'W') for ind, ss in enumerate(s)] # print(t) ans = 1 zeros = 0 for tt in t: if tt == 0: zeros += 1 else: if zeros == 0: print((0)) exit() ans = ans * zeros % mod zeros -= 1 if zeros > 0: print((0)) exit() for i in range(1, n + 1): ans = ans * i % mod print(ans)
32
27
541
436
mod = 10**9 + 7 n = int(eval(input())) s = eval(input()) t = list([1 if x == "B" else 0 for x in s]) t = tuple((tt - df) % 2 for tt, df in zip(t, reversed(list(range(n * 2))))) # print(t) ans = 1 zeros = 0 ones = 0 for tt in t: if tt == 0: zeros += 1 else: if zeros == 0: print((0)) exit() ans *= zeros ans %= mod zeros -= 1 ones += 1 if zeros > 0: print((0)) exit() for i in range(1, n + 1): ans *= i ans %= mod print(ans)
mod = 10**9 + 7 n = int(eval(input())) s = eval(input()) t = [(ind % 2) ^ (ss == "W") for ind, ss in enumerate(s)] # print(t) ans = 1 zeros = 0 for tt in t: if tt == 0: zeros += 1 else: if zeros == 0: print((0)) exit() ans = ans * zeros % mod zeros -= 1 if zeros > 0: print((0)) exit() for i in range(1, n + 1): ans = ans * i % mod print(ans)
false
15.625
[ "-t = list([1 if x == \"B\" else 0 for x in s])", "-t = tuple((tt - df) % 2 for tt, df in zip(t, reversed(list(range(n * 2)))))", "+t = [(ind % 2) ^ (ss == \"W\") for ind, ss in enumerate(s)]", "-ones = 0", "- ans *= zeros", "- ans %= mod", "+ ans = ans * zeros % mod", "- ones += 1", "- ans *= i", "- ans %= mod", "+ ans = ans * i % mod" ]
false
0.037576
0.036067
1.041859
[ "s642032765", "s643079733" ]
u729133443
p02782
python
s020740723
s108847248
1,151
772
161,452
161,268
Accepted
Accepted
32.93
class Factorial: def __init__(self,n,mod): self.f=[1] self.mod=mod for i in range(1,n+1): self.f.append(self.f[-1]*i%mod) self.i=[pow(self.f[-1],mod-2,mod)] for i in range(1,n+1)[::-1]: self.i.append(self.i[-1]*i%mod) self.i.reverse() def factorial(self,i): return self.f[i] def ifactorial(self,i): return self.i[i] def comb(self,n,k): return self.f[n]*self.i[n-k]%self.mod*self.i[k]%self.mod if n>=k else 0 M=10**9+7 a,b,c,d=list(map(int,input().split())) comb=Factorial(c+d+2,M).comb f=lambda r,c:comb(c+r+2,r+1)-c-r-2 print(((f(c,d)-f(c,b-1)-f(a-1,d)+f(a-1,b-1))%M))
class Factorial: def __init__(self,n,mod): self.f=f=[0]*(n+1) f[0]=b=1 self.mod=mod for i in range(1,n+1):f[i]=b=b*i%mod self.inv=inv=[0]*(n+1) inv[n]=b=pow(self.f[n],mod-2,mod) for i in range(n,0,-1):inv[i-1]=b=b*i%mod def factorial(self,i): return self.f[i] def ifactorial(self,i): return self.inv[i] def comb(self,n,k): if n>=k: return self.f[n]*self.inv[n-k]%self.mod*self.inv[k]%self.mod else: return 0 M=10**9+7 a,b,c,d=list(map(int,input().split())) comb=Factorial(c+d+2,M).comb f=lambda r,c:comb(c+r+2,r+1)-c-r-2 print(((f(c,d)-f(c,b-1)-f(a-1,d)+f(a-1,b-1))%M))
21
23
693
711
class Factorial: def __init__(self, n, mod): self.f = [1] self.mod = mod for i in range(1, n + 1): self.f.append(self.f[-1] * i % mod) self.i = [pow(self.f[-1], mod - 2, mod)] for i in range(1, n + 1)[::-1]: self.i.append(self.i[-1] * i % mod) self.i.reverse() def factorial(self, i): return self.f[i] def ifactorial(self, i): return self.i[i] def comb(self, n, k): return ( self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0 ) M = 10**9 + 7 a, b, c, d = list(map(int, input().split())) comb = Factorial(c + d + 2, M).comb f = lambda r, c: comb(c + r + 2, r + 1) - c - r - 2 print(((f(c, d) - f(c, b - 1) - f(a - 1, d) + f(a - 1, b - 1)) % M))
class Factorial: def __init__(self, n, mod): self.f = f = [0] * (n + 1) f[0] = b = 1 self.mod = mod for i in range(1, n + 1): f[i] = b = b * i % mod self.inv = inv = [0] * (n + 1) inv[n] = b = pow(self.f[n], mod - 2, mod) for i in range(n, 0, -1): inv[i - 1] = b = b * i % mod def factorial(self, i): return self.f[i] def ifactorial(self, i): return self.inv[i] def comb(self, n, k): if n >= k: return self.f[n] * self.inv[n - k] % self.mod * self.inv[k] % self.mod else: return 0 M = 10**9 + 7 a, b, c, d = list(map(int, input().split())) comb = Factorial(c + d + 2, M).comb f = lambda r, c: comb(c + r + 2, r + 1) - c - r - 2 print(((f(c, d) - f(c, b - 1) - f(a - 1, d) + f(a - 1, b - 1)) % M))
false
8.695652
[ "- self.f = [1]", "+ self.f = f = [0] * (n + 1)", "+ f[0] = b = 1", "- self.f.append(self.f[-1] * i % mod)", "- self.i = [pow(self.f[-1], mod - 2, mod)]", "- for i in range(1, n + 1)[::-1]:", "- self.i.append(self.i[-1] * i % mod)", "- self.i.reverse()", "+ f[i] = b = b * i % mod", "+ self.inv = inv = [0] * (n + 1)", "+ inv[n] = b = pow(self.f[n], mod - 2, mod)", "+ for i in range(n, 0, -1):", "+ inv[i - 1] = b = b * i % mod", "- return self.i[i]", "+ return self.inv[i]", "- return (", "- self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0", "- )", "+ if n >= k:", "+ return self.f[n] * self.inv[n - k] % self.mod * self.inv[k] % self.mod", "+ else:", "+ return 0" ]
false
0.043102
0.044307
0.972795
[ "s020740723", "s108847248" ]
u214617707
p03546
python
s571779114
s213664297
47
40
3,444
3,444
Accepted
Accepted
14.89
H, W = list(map(int, input().split())) c = [[0]*10 for i in range(10)] for i in range(10): a = list(map(int, input().split())) for j in range(10): c[i][j] = a[j] A = [[0]*W for i in range(H)] for i in range(H): a = list(map(int, input().split())) for j in range(W): A[i][j] = a[j] for k in range(10): for i in range(10): for j in range(10): if i != j: c[i][j] = min(c[i][j], c[i][k]+c[k][j]) ans = 0 for i in range(H): for j in range(W): if A[i][j] != -1 and A[i][j] != 1: ans += c[A[i][j]][1] print(ans)
H, W = list(map(int, input().split())) C = [[] for i in range(10)] A = [[] for i in range(H)] for i in range(10): c = list(map(int, input().split())) C[i] = c for i in range(H): a = list(map(int, input().split())) A[i] = a for k in range(10): for i in range(10): for j in range(10): C[i][j] = min(C[i][j], C[i][k] + C[k][j]) num = 0 for i in range(H): for j in range(W): if A[i][j] != -1: num += C[A[i][j]][1] print(num)
28
23
647
504
H, W = list(map(int, input().split())) c = [[0] * 10 for i in range(10)] for i in range(10): a = list(map(int, input().split())) for j in range(10): c[i][j] = a[j] A = [[0] * W for i in range(H)] for i in range(H): a = list(map(int, input().split())) for j in range(W): A[i][j] = a[j] for k in range(10): for i in range(10): for j in range(10): if i != j: c[i][j] = min(c[i][j], c[i][k] + c[k][j]) ans = 0 for i in range(H): for j in range(W): if A[i][j] != -1 and A[i][j] != 1: ans += c[A[i][j]][1] print(ans)
H, W = list(map(int, input().split())) C = [[] for i in range(10)] A = [[] for i in range(H)] for i in range(10): c = list(map(int, input().split())) C[i] = c for i in range(H): a = list(map(int, input().split())) A[i] = a for k in range(10): for i in range(10): for j in range(10): C[i][j] = min(C[i][j], C[i][k] + C[k][j]) num = 0 for i in range(H): for j in range(W): if A[i][j] != -1: num += C[A[i][j]][1] print(num)
false
17.857143
[ "-c = [[0] * 10 for i in range(10)]", "+C = [[] for i in range(10)]", "+A = [[] for i in range(H)]", "- a = list(map(int, input().split()))", "- for j in range(10):", "- c[i][j] = a[j]", "-A = [[0] * W for i in range(H)]", "+ c = list(map(int, input().split()))", "+ C[i] = c", "- for j in range(W):", "- A[i][j] = a[j]", "+ A[i] = a", "- if i != j:", "- c[i][j] = min(c[i][j], c[i][k] + c[k][j])", "-ans = 0", "+ C[i][j] = min(C[i][j], C[i][k] + C[k][j])", "+num = 0", "- if A[i][j] != -1 and A[i][j] != 1:", "- ans += c[A[i][j]][1]", "-print(ans)", "+ if A[i][j] != -1:", "+ num += C[A[i][j]][1]", "+print(num)" ]
false
0.037221
0.038331
0.971028
[ "s571779114", "s213664297" ]
u072053884
p02266
python
s416854074
s243675541
90
70
8,392
8,352
Accepted
Accepted
22.22
import collections S1 = collections.deque() S2 = collections.deque() S3 = collections.deque() for i, j in enumerate(eval(input())): if j == '\\': S1.append(i) elif j == '/': if S1: left_edge = S1.pop() new_puddle = i - left_edge while True: if S2: if S2[-1] > left_edge: S2.pop() new_puddle += S3.pop() else: break else: break S2.append(left_edge) S3.append(new_puddle) else: pass print((sum(S3))) print((len(S3), *S3))
import collections import sys S1 = collections.deque() S2 = collections.deque() S3 = collections.deque() for i, j in enumerate(sys.stdin.readline()): if j == '\\': S1.append(i) elif j == '/': if S1: left_edge = S1.pop() new_puddle = i - left_edge while True: if S2: if S2[-1] > left_edge: S2.pop() new_puddle += S3.pop() else: break else: break S2.append(left_edge) S3.append(new_puddle) else: pass print((sum(S3))) print((len(S3), *S3))
31
32
712
737
import collections S1 = collections.deque() S2 = collections.deque() S3 = collections.deque() for i, j in enumerate(eval(input())): if j == "\\": S1.append(i) elif j == "/": if S1: left_edge = S1.pop() new_puddle = i - left_edge while True: if S2: if S2[-1] > left_edge: S2.pop() new_puddle += S3.pop() else: break else: break S2.append(left_edge) S3.append(new_puddle) else: pass print((sum(S3))) print((len(S3), *S3))
import collections import sys S1 = collections.deque() S2 = collections.deque() S3 = collections.deque() for i, j in enumerate(sys.stdin.readline()): if j == "\\": S1.append(i) elif j == "/": if S1: left_edge = S1.pop() new_puddle = i - left_edge while True: if S2: if S2[-1] > left_edge: S2.pop() new_puddle += S3.pop() else: break else: break S2.append(left_edge) S3.append(new_puddle) else: pass print((sum(S3))) print((len(S3), *S3))
false
3.125
[ "+import sys", "-for i, j in enumerate(eval(input())):", "+for i, j in enumerate(sys.stdin.readline()):" ]
false
0.047062
0.046738
1.006936
[ "s416854074", "s243675541" ]
u761320129
p03816
python
s136280600
s273825882
81
57
16,380
18,656
Accepted
Accepted
29.63
from collections import Counter N = eval(input()) CARDS = list(map(int, input().split())) hist = Counter(CARDS) dup = N - len(hist) eat = (dup+1)/2 print(N - eat*2)
from collections import Counter N = int(eval(input())) src = list(map(int,input().split())) ctr = Counter(src) even = len([a for a in list(ctr.values()) if a%2==0]) ans = len(ctr) if even%2: ans -= 1 print(ans)
7
9
161
210
from collections import Counter N = eval(input()) CARDS = list(map(int, input().split())) hist = Counter(CARDS) dup = N - len(hist) eat = (dup + 1) / 2 print(N - eat * 2)
from collections import Counter N = int(eval(input())) src = list(map(int, input().split())) ctr = Counter(src) even = len([a for a in list(ctr.values()) if a % 2 == 0]) ans = len(ctr) if even % 2: ans -= 1 print(ans)
false
22.222222
[ "-N = eval(input())", "-CARDS = list(map(int, input().split()))", "-hist = Counter(CARDS)", "-dup = N - len(hist)", "-eat = (dup + 1) / 2", "-print(N - eat * 2)", "+N = int(eval(input()))", "+src = list(map(int, input().split()))", "+ctr = Counter(src)", "+even = len([a for a in list(ctr.values()) if a % 2 == 0])", "+ans = len(ctr)", "+if even % 2:", "+ ans -= 1", "+print(ans)" ]
false
0.037118
0.058993
0.629192
[ "s136280600", "s273825882" ]
u908372127
p02915
python
s938389237
s578315962
19
17
3,060
2,940
Accepted
Accepted
10.53
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) p=input().rstrip() p=int(p) print((p**3))
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) p=input().rstrip() print((int(p)**3))
7
7
115
113
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) p = input().rstrip() p = int(p) print((p**3))
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) p = input().rstrip() print((int(p) ** 3))
false
0
[ "-p = int(p)", "-print((p**3))", "+print((int(p) ** 3))" ]
false
0.043187
0.048637
0.88795
[ "s938389237", "s578315962" ]
u102960641
p02624
python
s338061198
s523843051
75
36
64,788
9,312
Accepted
Accepted
52
import math n = int(eval(input())) ans = 0 SQRT = int(n ** 0.5) for m in range(1,int(n ** 0.5) + 1): ans += m * (m + int(n/m)) * (int(n/m) + 1 - m) ans -= SQRT * (SQRT+1) * (2*SQRT+1) // 6 print(ans)
n = int(eval(input())) ans = 0 SQRT = int(n ** 0.5) for m in range(1,SQRT + 1): b = int(n/m) ans += m * (m + b) * (b + 1 - m) ans -= SQRT * (SQRT+1) * (2*SQRT+1) // 6 print(ans)
9
8
207
186
import math n = int(eval(input())) ans = 0 SQRT = int(n**0.5) for m in range(1, int(n**0.5) + 1): ans += m * (m + int(n / m)) * (int(n / m) + 1 - m) ans -= SQRT * (SQRT + 1) * (2 * SQRT + 1) // 6 print(ans)
n = int(eval(input())) ans = 0 SQRT = int(n**0.5) for m in range(1, SQRT + 1): b = int(n / m) ans += m * (m + b) * (b + 1 - m) ans -= SQRT * (SQRT + 1) * (2 * SQRT + 1) // 6 print(ans)
false
11.111111
[ "-import math", "-", "-for m in range(1, int(n**0.5) + 1):", "- ans += m * (m + int(n / m)) * (int(n / m) + 1 - m)", "+for m in range(1, SQRT + 1):", "+ b = int(n / m)", "+ ans += m * (m + b) * (b + 1 - m)" ]
false
0.041971
0.042218
0.994161
[ "s338061198", "s523843051" ]
u112002050
p04043
python
s706555479
s949785547
43
39
3,064
3,064
Accepted
Accepted
9.3
phrases = [ int(i) for i in input().split() ] if phrases.count(5) == 2 and 5 in phrases: print("YES") else: print("NO")
phrases = [ int(i) for i in input().split() ] if phrases.count(5) == 2 and 7 in phrases: print("YES") else: print("NO")
5
5
125
125
phrases = [int(i) for i in input().split()] if phrases.count(5) == 2 and 5 in phrases: print("YES") else: print("NO")
phrases = [int(i) for i in input().split()] if phrases.count(5) == 2 and 7 in phrases: print("YES") else: print("NO")
false
0
[ "-if phrases.count(5) == 2 and 5 in phrases:", "+if phrases.count(5) == 2 and 7 in phrases:" ]
false
0.04276
0.104435
0.409438
[ "s706555479", "s949785547" ]
u843175622
p03674
python
s451057067
s835380675
1,096
774
23,988
20,200
Accepted
Accepted
29.38
from collections import defaultdict n = int(eval(input())) + 1 a = list(map(int, input().split())) mod = 10 ** 9 + 7 # 1を一つだけ選ぶやつは重複する可能性 d = defaultdict(int) left = right = 0 for i in range(n): if d[a[i]] > 0: right = i left = a.index(a[i]) break d[a[i]] += 1 fac = [1] * (n + 1) for i in range(1, n + 1): fac[i] = fac[i - 1] * i % mod def inv(x): return pow(x, mod - 2, mod) def c(n, k): if n < 0 or k < 0 or n < k: return 0 return fac[n] * inv(fac[n - k] * fac[k] % mod) % mod left_len = left right_len = n - right - 1 print((n - 1)) for i in range(2, n + 1): ans = c(n, i) - (c(left_len + 1 + right_len, i) - c(left_len + right_len, i)) print((ans % mod))
n = int(eval(input())) + 1 a = list(map(int, input().split())) mod = 10 ** 9 + 7 # 1を一つだけ選ぶやつは重複する可能性 d = [False] * (n + 1) left = right = 0 for i in range(n): if d[a[i]]: right = i left = a.index(a[i]) break d[a[i]] = True fac = [1] * (n + 1) for i in range(1, n + 1): fac[i] = fac[i - 1] * i % mod def inv(x): return pow(x, mod - 2, mod) def c(n, k): if n < 0 or k < 0 or n < k: return 0 return fac[n] * inv(fac[n - k] * fac[k] % mod) % mod left_len = left right_len = n - right - 1 print((n - 1)) for i in range(2, n + 1): ans = c(n, i) - c(left_len + right_len, i - 1) print((ans % mod))
40
37
785
692
from collections import defaultdict n = int(eval(input())) + 1 a = list(map(int, input().split())) mod = 10**9 + 7 # 1を一つだけ選ぶやつは重複する可能性 d = defaultdict(int) left = right = 0 for i in range(n): if d[a[i]] > 0: right = i left = a.index(a[i]) break d[a[i]] += 1 fac = [1] * (n + 1) for i in range(1, n + 1): fac[i] = fac[i - 1] * i % mod def inv(x): return pow(x, mod - 2, mod) def c(n, k): if n < 0 or k < 0 or n < k: return 0 return fac[n] * inv(fac[n - k] * fac[k] % mod) % mod left_len = left right_len = n - right - 1 print((n - 1)) for i in range(2, n + 1): ans = c(n, i) - (c(left_len + 1 + right_len, i) - c(left_len + right_len, i)) print((ans % mod))
n = int(eval(input())) + 1 a = list(map(int, input().split())) mod = 10**9 + 7 # 1を一つだけ選ぶやつは重複する可能性 d = [False] * (n + 1) left = right = 0 for i in range(n): if d[a[i]]: right = i left = a.index(a[i]) break d[a[i]] = True fac = [1] * (n + 1) for i in range(1, n + 1): fac[i] = fac[i - 1] * i % mod def inv(x): return pow(x, mod - 2, mod) def c(n, k): if n < 0 or k < 0 or n < k: return 0 return fac[n] * inv(fac[n - k] * fac[k] % mod) % mod left_len = left right_len = n - right - 1 print((n - 1)) for i in range(2, n + 1): ans = c(n, i) - c(left_len + right_len, i - 1) print((ans % mod))
false
7.5
[ "-from collections import defaultdict", "-", "-d = defaultdict(int)", "+d = [False] * (n + 1)", "- if d[a[i]] > 0:", "+ if d[a[i]]:", "- d[a[i]] += 1", "+ d[a[i]] = True", "- ans = c(n, i) - (c(left_len + 1 + right_len, i) - c(left_len + right_len, i))", "+ ans = c(n, i) - c(left_len + right_len, i - 1)" ]
false
0.037596
0.035892
1.047482
[ "s451057067", "s835380675" ]
u077291787
p03308
python
s873746638
s885445947
21
17
3,060
2,940
Accepted
Accepted
19.05
# ABC102B - Maximum Difference n = int(eval(input())) lst = list(map(int, input().rstrip().split())) max_dif = 0 for i in range(n): for j in range(n): max_dif = max(max_dif, abs(lst[i] - lst[j])) print(max_dif)
# ABC102B - Maximum Difference # Better ver. n = int(eval(input())) lst = sorted(list(map(int, input().rstrip().split()))) print((lst[-1] - lst[0]))
10
5
231
144
# ABC102B - Maximum Difference n = int(eval(input())) lst = list(map(int, input().rstrip().split())) max_dif = 0 for i in range(n): for j in range(n): max_dif = max(max_dif, abs(lst[i] - lst[j])) print(max_dif)
# ABC102B - Maximum Difference # Better ver. n = int(eval(input())) lst = sorted(list(map(int, input().rstrip().split()))) print((lst[-1] - lst[0]))
false
50
[ "+# Better ver.", "-lst = list(map(int, input().rstrip().split()))", "-max_dif = 0", "-for i in range(n):", "- for j in range(n):", "- max_dif = max(max_dif, abs(lst[i] - lst[j]))", "-print(max_dif)", "+lst = sorted(list(map(int, input().rstrip().split())))", "+print((lst[-1] - lst[0]))" ]
false
0.040093
0.07644
0.524494
[ "s873746638", "s885445947" ]
u821432765
p03029
python
s193170823
s234866779
172
17
38,256
2,940
Accepted
Accepted
90.12
a,p=list(map(int,input().split())) print(((a*3+p)//2))
A, P = [int(i) for i in input().split()] print(((A*3+P)//2))
2
2
47
59
a, p = list(map(int, input().split())) print(((a * 3 + p) // 2))
A, P = [int(i) for i in input().split()] print(((A * 3 + P) // 2))
false
0
[ "-a, p = list(map(int, input().split()))", "-print(((a * 3 + p) // 2))", "+A, P = [int(i) for i in input().split()]", "+print(((A * 3 + P) // 2))" ]
false
0.136283
0.039405
3.458487
[ "s193170823", "s234866779" ]
u604774382
p02393
python
s080182263
s853892623
30
20
6,724
4,200
Accepted
Accepted
33.33
#coding:utf-8 import sys abc=sys.stdin.readline() nums=abc.split( ' ' ) for i in range( len( nums) ): nums[i] = int( nums[i] ) nums.sort() print(( "{} {} {}".format( nums[0], nums[1], nums[2] ) ))
import sys nums = [ int( val ) for val in sys.stdin.readline().split( " " ) ] nums = sorted( nums ) print(( "{:d} {:d} {:d}".format( nums[0], nums[1], nums[2] ) ))
9
5
205
167
# coding:utf-8 import sys abc = sys.stdin.readline() nums = abc.split(" ") for i in range(len(nums)): nums[i] = int(nums[i]) nums.sort() print(("{} {} {}".format(nums[0], nums[1], nums[2])))
import sys nums = [int(val) for val in sys.stdin.readline().split(" ")] nums = sorted(nums) print(("{:d} {:d} {:d}".format(nums[0], nums[1], nums[2])))
false
44.444444
[ "-# coding:utf-8", "-abc = sys.stdin.readline()", "-nums = abc.split(\" \")", "-for i in range(len(nums)):", "- nums[i] = int(nums[i])", "-nums.sort()", "-print((\"{} {} {}\".format(nums[0], nums[1], nums[2])))", "+nums = [int(val) for val in sys.stdin.readline().split(\" \")]", "+nums = sorted(nums)", "+print((\"{:d} {:d} {:d}\".format(nums[0], nums[1], nums[2])))" ]
false
0.086017
0.039837
2.159221
[ "s080182263", "s853892623" ]
u829249049
p02647
python
s397571647
s154913610
395
340
169,632
168,644
Accepted
Accepted
13.92
N,K=list(map(int,input().split())) A=list(map(int,input().split())) imos=[0 for i in range(N+1)] for t in range(K): for i in range(N): l=max(0,i-A[i]) r=min(N,i+A[i]+1) imos[l]+=1 imos[r]-=1 for i in range(0,N): imos[i+1]+=imos[i] A[i]=imos[i] imos=[0 for i in range(N+1)] if len(set(A))==1 and (N in set(A)): break for i in range(N): A[i]=str(A[i]) ans=" ".join(A) print(ans)
N,K=list(map(int,input().split())) A=list(map(int,input().split())) imos=[0 for i in range(N+1)] zero=[0 for i in range(N+1)] ANS=[str(N)]*N if K>=40: ans=" ".join(ANS) print(ans) else: for t in range(K): for i in range(N): l=max(0,i-A[i]) r=min(N,i+A[i]+1) imos[l]+=1 imos[r]-=1 for i in range(0,N): imos[i+1]+=imos[i] A[i]=imos[i] imos=[0 for i in range(N+1)] for i in range(N): A[i]=str(A[i]) ans=" ".join(A) print(ans)
20
23
430
504
N, K = list(map(int, input().split())) A = list(map(int, input().split())) imos = [0 for i in range(N + 1)] for t in range(K): for i in range(N): l = max(0, i - A[i]) r = min(N, i + A[i] + 1) imos[l] += 1 imos[r] -= 1 for i in range(0, N): imos[i + 1] += imos[i] A[i] = imos[i] imos = [0 for i in range(N + 1)] if len(set(A)) == 1 and (N in set(A)): break for i in range(N): A[i] = str(A[i]) ans = " ".join(A) print(ans)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) imos = [0 for i in range(N + 1)] zero = [0 for i in range(N + 1)] ANS = [str(N)] * N if K >= 40: ans = " ".join(ANS) print(ans) else: for t in range(K): for i in range(N): l = max(0, i - A[i]) r = min(N, i + A[i] + 1) imos[l] += 1 imos[r] -= 1 for i in range(0, N): imos[i + 1] += imos[i] A[i] = imos[i] imos = [0 for i in range(N + 1)] for i in range(N): A[i] = str(A[i]) ans = " ".join(A) print(ans)
false
13.043478
[ "-for t in range(K):", "+zero = [0 for i in range(N + 1)]", "+ANS = [str(N)] * N", "+if K >= 40:", "+ ans = \" \".join(ANS)", "+ print(ans)", "+else:", "+ for t in range(K):", "+ for i in range(N):", "+ l = max(0, i - A[i])", "+ r = min(N, i + A[i] + 1)", "+ imos[l] += 1", "+ imos[r] -= 1", "+ for i in range(0, N):", "+ imos[i + 1] += imos[i]", "+ A[i] = imos[i]", "+ imos = [0 for i in range(N + 1)]", "- l = max(0, i - A[i])", "- r = min(N, i + A[i] + 1)", "- imos[l] += 1", "- imos[r] -= 1", "- for i in range(0, N):", "- imos[i + 1] += imos[i]", "- A[i] = imos[i]", "- imos = [0 for i in range(N + 1)]", "- if len(set(A)) == 1 and (N in set(A)):", "- break", "-for i in range(N):", "- A[i] = str(A[i])", "-ans = \" \".join(A)", "-print(ans)", "+ A[i] = str(A[i])", "+ ans = \" \".join(A)", "+ print(ans)" ]
false
0.042202
0.04176
1.010588
[ "s397571647", "s154913610" ]
u838644735
p03645
python
s953258359
s358897601
571
186
19,024
46,660
Accepted
Accepted
67.43
def solve(): N, M = map(int, input().split()) FROM_1 = set() TO_N = set() for i in range(M): a, b = map(int, input().split()) if a == 1: FROM_1.add(b) elif a == N: TO_N.add(b) if b == 1: FROM_1.add(a) elif b == N: TO_N.add(a) ans = FROM_1 & TO_N print('POSSIBLE') if ans else print('IMPOSSIBLE') if __name__ == '__main__': solve()
def solve(): N, M, *AB = map(int, open(0).read().split()) FROM_1 = set() TO_N = set() for i in range(M): a, b = AB[2*i], AB[2*i + 1] if a == 1: FROM_1.add(b) elif a == N: TO_N.add(b) if b == 1: FROM_1.add(a) elif b == N: TO_N.add(a) ans = FROM_1 & TO_N print('POSSIBLE') if ans else print('IMPOSSIBLE') if __name__ == '__main__': solve()
19
19
466
472
def solve(): N, M = map(int, input().split()) FROM_1 = set() TO_N = set() for i in range(M): a, b = map(int, input().split()) if a == 1: FROM_1.add(b) elif a == N: TO_N.add(b) if b == 1: FROM_1.add(a) elif b == N: TO_N.add(a) ans = FROM_1 & TO_N print("POSSIBLE") if ans else print("IMPOSSIBLE") if __name__ == "__main__": solve()
def solve(): N, M, *AB = map(int, open(0).read().split()) FROM_1 = set() TO_N = set() for i in range(M): a, b = AB[2 * i], AB[2 * i + 1] if a == 1: FROM_1.add(b) elif a == N: TO_N.add(b) if b == 1: FROM_1.add(a) elif b == N: TO_N.add(a) ans = FROM_1 & TO_N print("POSSIBLE") if ans else print("IMPOSSIBLE") if __name__ == "__main__": solve()
false
0
[ "- N, M = map(int, input().split())", "+ N, M, *AB = map(int, open(0).read().split())", "- a, b = map(int, input().split())", "+ a, b = AB[2 * i], AB[2 * i + 1]" ]
false
0.041935
0.144138
0.290938
[ "s953258359", "s358897601" ]
u693716675
p02935
python
s693728122
s199164351
20
17
3,060
2,940
Accepted
Accepted
15
n = int(eval(input())) a = [int(i) for i in input().split()] a.sort() s = a[0] for i in range(n): s = (s+a[i])/2 print(s)
### 138-c n = int(eval(input())) v = [int(i) for i in input().split()] v.sort() ans = v[0] for i in range(1,n): ans = (ans+v[i])/2 print(ans)
9
9
129
148
n = int(eval(input())) a = [int(i) for i in input().split()] a.sort() s = a[0] for i in range(n): s = (s + a[i]) / 2 print(s)
### 138-c n = int(eval(input())) v = [int(i) for i in input().split()] v.sort() ans = v[0] for i in range(1, n): ans = (ans + v[i]) / 2 print(ans)
false
0
[ "+### 138-c", "-a = [int(i) for i in input().split()]", "-a.sort()", "-s = a[0]", "-for i in range(n):", "- s = (s + a[i]) / 2", "-print(s)", "+v = [int(i) for i in input().split()]", "+v.sort()", "+ans = v[0]", "+for i in range(1, n):", "+ ans = (ans + v[i]) / 2", "+print(ans)" ]
false
0.101776
0.039794
2.557549
[ "s693728122", "s199164351" ]
u416011173
p02576
python
s739053569
s167032959
31
28
9,084
9,160
Accepted
Accepted
9.68
# -*- coding: utf-8 -*- # モジュールのインポート import math # 標準入力を取得 N, X, T = list(map(int, input().split())) # 求解処理 ans = math.ceil(N / X) * T # 結果出力 print(ans)
# -*- coding: utf-8 -*- # モジュールのインポート import math def get_input() -> tuple: """ 標準入力を取得する. Returns:\n tuple: 標準入力 """ N, X, T = list(map(int, input().split())) return N, X, T def main(N: int, X: int, T: int) -> None: """ メイン処理. Args:\n N (int): 作るたこ焼きの個数(1 <= N <= 1000) X (int): 1度に作ることができるたこ焼きの個数(1 <= X <= 1000) T (int): たこ焼きを焼くのにかかる時間 """ # 求解処理 ans = math.ceil(N / X) * T # 結果出力 print(ans) if __name__ == "__main__": # 標準入力を取得 N, X, T = get_input() # メイン処理 main(N, X, T)
12
39
168
629
# -*- coding: utf-8 -*- # モジュールのインポート import math # 標準入力を取得 N, X, T = list(map(int, input().split())) # 求解処理 ans = math.ceil(N / X) * T # 結果出力 print(ans)
# -*- coding: utf-8 -*- # モジュールのインポート import math def get_input() -> tuple: """ 標準入力を取得する. Returns:\n tuple: 標準入力 """ N, X, T = list(map(int, input().split())) return N, X, T def main(N: int, X: int, T: int) -> None: """ メイン処理. Args:\n N (int): 作るたこ焼きの個数(1 <= N <= 1000) X (int): 1度に作ることができるたこ焼きの個数(1 <= X <= 1000) T (int): たこ焼きを焼くのにかかる時間 """ # 求解処理 ans = math.ceil(N / X) * T # 結果出力 print(ans) if __name__ == "__main__": # 標準入力を取得 N, X, T = get_input() # メイン処理 main(N, X, T)
false
69.230769
[ "-# 標準入力を取得", "-N, X, T = list(map(int, input().split()))", "-# 求解処理", "-ans = math.ceil(N / X) * T", "-# 結果出力", "-print(ans)", "+", "+def get_input() -> tuple:", "+ \"\"\"", "+ 標準入力を取得する.", "+ Returns:\\n", "+ tuple: 標準入力", "+ \"\"\"", "+ N, X, T = list(map(int, input().split()))", "+ return N, X, T", "+", "+", "+def main(N: int, X: int, T: int) -> None:", "+ \"\"\"", "+ メイン処理.", "+ Args:\\n", "+ N (int): 作るたこ焼きの個数(1 <= N <= 1000)", "+ X (int): 1度に作ることができるたこ焼きの個数(1 <= X <= 1000)", "+ T (int): たこ焼きを焼くのにかかる時間", "+ \"\"\"", "+ # 求解処理", "+ ans = math.ceil(N / X) * T", "+ # 結果出力", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ # 標準入力を取得", "+ N, X, T = get_input()", "+ # メイン処理", "+ main(N, X, T)" ]
false
0.0513
0.049296
1.040661
[ "s739053569", "s167032959" ]
u657361950
p02412
python
s510809367
s346931570
460
30
5,596
5,596
Accepted
Accepted
93.48
while True: arr = list(map(int, input().split())) n = arr[0] x = arr[1] if n == 0 and x == 0: break ans = 0 for i in range(1, n + 1): for j in range(i + 1, n + 1): for k in range(j + 1, n + 1): if i + j + k == x: ans += 1 print(ans)
def subset_sum(n,a,s): cnt=0 for i in range(n): r=s-a[i] j=i+1 k=n-1 while j<k: t=a[j]+a[k] if t<r: j+=1 elif t>r: k-=1 else: cnt+=1 j+=1 k-=1 return cnt while True: n,s=list(map(int,input().split())) if n==0 and s==0: break a=[0]*n for i in range(n): a[i]=i+1 print((subset_sum(n,a,s)))
16
28
274
362
while True: arr = list(map(int, input().split())) n = arr[0] x = arr[1] if n == 0 and x == 0: break ans = 0 for i in range(1, n + 1): for j in range(i + 1, n + 1): for k in range(j + 1, n + 1): if i + j + k == x: ans += 1 print(ans)
def subset_sum(n, a, s): cnt = 0 for i in range(n): r = s - a[i] j = i + 1 k = n - 1 while j < k: t = a[j] + a[k] if t < r: j += 1 elif t > r: k -= 1 else: cnt += 1 j += 1 k -= 1 return cnt while True: n, s = list(map(int, input().split())) if n == 0 and s == 0: break a = [0] * n for i in range(n): a[i] = i + 1 print((subset_sum(n, a, s)))
false
42.857143
[ "+def subset_sum(n, a, s):", "+ cnt = 0", "+ for i in range(n):", "+ r = s - a[i]", "+ j = i + 1", "+ k = n - 1", "+ while j < k:", "+ t = a[j] + a[k]", "+ if t < r:", "+ j += 1", "+ elif t > r:", "+ k -= 1", "+ else:", "+ cnt += 1", "+ j += 1", "+ k -= 1", "+ return cnt", "+", "+", "- arr = list(map(int, input().split()))", "- n = arr[0]", "- x = arr[1]", "- if n == 0 and x == 0:", "+ n, s = list(map(int, input().split()))", "+ if n == 0 and s == 0:", "- ans = 0", "- for i in range(1, n + 1):", "- for j in range(i + 1, n + 1):", "- for k in range(j + 1, n + 1):", "- if i + j + k == x:", "- ans += 1", "- print(ans)", "+ a = [0] * n", "+ for i in range(n):", "+ a[i] = i + 1", "+ print((subset_sum(n, a, s)))" ]
false
0.074401
0.035563
2.09206
[ "s510809367", "s346931570" ]
u762420987
p03137
python
s394119156
s183485932
114
105
13,968
13,968
Accepted
Accepted
7.89
N, M = list(map(int, input().split())) Xlist = sorted(list(map(int, input().split()))) Llist = [] for i in range(M - 1): Llist.append(Xlist[i + 1] - Xlist[i]) Llist.sort() print((sum(Llist[:M - N]) if N < M else 0))
N, M = list(map(int, input().split())) Xlist = sorted(list(map(int, input().split()))) sbn = sorted([abs(Xlist[i + 1] - Xlist[i]) for i in range(M - 1)])[::-1] if N >= M: print((0)) else: print((sum(sbn[N - 1:])))
7
7
218
218
N, M = list(map(int, input().split())) Xlist = sorted(list(map(int, input().split()))) Llist = [] for i in range(M - 1): Llist.append(Xlist[i + 1] - Xlist[i]) Llist.sort() print((sum(Llist[: M - N]) if N < M else 0))
N, M = list(map(int, input().split())) Xlist = sorted(list(map(int, input().split()))) sbn = sorted([abs(Xlist[i + 1] - Xlist[i]) for i in range(M - 1)])[::-1] if N >= M: print((0)) else: print((sum(sbn[N - 1 :])))
false
0
[ "-Llist = []", "-for i in range(M - 1):", "- Llist.append(Xlist[i + 1] - Xlist[i])", "-Llist.sort()", "-print((sum(Llist[: M - N]) if N < M else 0))", "+sbn = sorted([abs(Xlist[i + 1] - Xlist[i]) for i in range(M - 1)])[::-1]", "+if N >= M:", "+ print((0))", "+else:", "+ print((sum(sbn[N - 1 :])))" ]
false
0.039103
0.044259
0.883489
[ "s394119156", "s183485932" ]
u334712262
p02816
python
s363269442
s127555888
859
649
120,744
125,844
Accepted
Accepted
24.45
# -*- coding: utf-8 -*- import sys from collections import Counter, defaultdict buff_readline = sys.stdin.buffer.readline readline = sys.stdin.readline def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) class RollingHash(): """ Original code is https://tjkendev.github.io/procon-library/python/string/rolling_hash.html """ class RH(): def __init__(self, s, base, mod): self.base = base self.mod = mod self.rev = pow(base, mod-2, mod) l = len(s) self.h = h = [0]*(l+1) tmp = 0 for i in range(l): num = s[i] tmp = (tmp*base + num) % mod h[i+1] = tmp self.pw = pw = [1]*(len(s)+1) v = 1 for i in range(l): pw[i+1] = v = v * base % mod def calc(self, l, r): return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod @staticmethod def gen(a, b, num): result = set() while 1: import random import math random.seed() while 1: v = random.randint(a, b)//2*2+1 if v not in result: break for x in range(3, int(math.sqrt(v))+1, 2): if v % x == 0: break else: result.add(v) if len(result) == num: break return result def __init__(self, s, rand=False, num=5): if rand: bases = RollingHash.gen(2, 10**3, num) else: assert num <= 10 bases = [641, 103, 661, 293, 547, 311, 29, 457, 613, 599][:num] MOD = 10**9+7 self.rhs = [self.RH(s, b, MOD) for b in bases] def calc(self, l, r): return tuple(rh.calc(l, r) for rh in self.rhs) def slv(N, A, B): a = [] for i in range(N): a.append(A[i]^A[i-1]) b = [] for i in range(N): b.append(B[i]^B[i-1]) ah = RollingHash(a) bh = RollingHash(b) ans = [] for k in range(N): if ah.calc(k, N) == bh.calc(0, N-k) and ah.calc(0, k) == bh.calc(N-k, N): ans.append('%d %d' % (k, A[k]^B[0])) return ans def main(): N = read_int() A = read_int_n() B = read_int_n() print(*slv(N, A, B), sep='\n') if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import sys from collections import Counter, defaultdict buff_readline = sys.stdin.buffer.readline readline = sys.stdin.readline def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) class RollingHash(): """ Original code is https://tjkendev.github.io/procon-library/python/string/rolling_hash.html """ class RH(): def __init__(self, s, base, mod): self.base = base self.mod = mod self.rev = pow(base, mod-2, mod) l = len(s) self.h = h = [0]*(l+1) tmp = 0 for i in range(l): num = s[i] tmp = (tmp*base + num) % mod h[i+1] = tmp self.pw = pw = [1]*(len(s)+1) v = 1 for i in range(l): pw[i+1] = v = v * base % mod def calc(self, l, r): return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod @staticmethod def gen(a, b, num): result = set() while 1: import random import math random.seed() while 1: v = random.randint(a, b)//2*2+1 if v not in result: break for x in range(3, int(math.sqrt(v))+1, 2): if v % x == 0: break else: result.add(v) if len(result) == num: break return result def __init__(self, s, rand=False, num=5): if rand: bases = RollingHash.gen(2, 10**3, num) else: assert num <= 10 bases = [641, 103, 661, 293, 547, 311, 29, 457, 613, 599][:num] MOD = 10**9+7 self.rhs = [self.RH(s, b, MOD) for b in bases] def calc(self, l, r): return tuple(rh.calc(l, r) for rh in self.rhs) def slv(N, A, B): a = [] for i in range(N): a.append(A[i]^A[i-1]) a = a[:] + a[:] b = [] for i in range(N): b.append(B[i]^B[i-1]) ah = RollingHash(a) bh = RollingHash(b) ans = [] h = bh.calc(0, N) for k in range(N): if ah.calc(k, N+k) == h: ans.append('%d %d' % (k, A[k]^B[0])) return ans def main(): N = read_int() A = read_int_n() B = read_int_n() print(*slv(N, A, B), sep='\n') if __name__ == '__main__': main()
104
105
2,580
2,573
# -*- coding: utf-8 -*- import sys from collections import Counter, defaultdict buff_readline = sys.stdin.buffer.readline readline = sys.stdin.readline def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) class RollingHash: """ Original code is https://tjkendev.github.io/procon-library/python/string/rolling_hash.html """ class RH: def __init__(self, s, base, mod): self.base = base self.mod = mod self.rev = pow(base, mod - 2, mod) l = len(s) self.h = h = [0] * (l + 1) tmp = 0 for i in range(l): num = s[i] tmp = (tmp * base + num) % mod h[i + 1] = tmp self.pw = pw = [1] * (len(s) + 1) v = 1 for i in range(l): pw[i + 1] = v = v * base % mod def calc(self, l, r): return (self.h[r] - self.h[l] * self.pw[r - l]) % self.mod @staticmethod def gen(a, b, num): result = set() while 1: import random import math random.seed() while 1: v = random.randint(a, b) // 2 * 2 + 1 if v not in result: break for x in range(3, int(math.sqrt(v)) + 1, 2): if v % x == 0: break else: result.add(v) if len(result) == num: break return result def __init__(self, s, rand=False, num=5): if rand: bases = RollingHash.gen(2, 10**3, num) else: assert num <= 10 bases = [641, 103, 661, 293, 547, 311, 29, 457, 613, 599][:num] MOD = 10**9 + 7 self.rhs = [self.RH(s, b, MOD) for b in bases] def calc(self, l, r): return tuple(rh.calc(l, r) for rh in self.rhs) def slv(N, A, B): a = [] for i in range(N): a.append(A[i] ^ A[i - 1]) b = [] for i in range(N): b.append(B[i] ^ B[i - 1]) ah = RollingHash(a) bh = RollingHash(b) ans = [] for k in range(N): if ah.calc(k, N) == bh.calc(0, N - k) and ah.calc(0, k) == bh.calc(N - k, N): ans.append("%d %d" % (k, A[k] ^ B[0])) return ans def main(): N = read_int() A = read_int_n() B = read_int_n() print(*slv(N, A, B), sep="\n") if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys from collections import Counter, defaultdict buff_readline = sys.stdin.buffer.readline readline = sys.stdin.readline def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) class RollingHash: """ Original code is https://tjkendev.github.io/procon-library/python/string/rolling_hash.html """ class RH: def __init__(self, s, base, mod): self.base = base self.mod = mod self.rev = pow(base, mod - 2, mod) l = len(s) self.h = h = [0] * (l + 1) tmp = 0 for i in range(l): num = s[i] tmp = (tmp * base + num) % mod h[i + 1] = tmp self.pw = pw = [1] * (len(s) + 1) v = 1 for i in range(l): pw[i + 1] = v = v * base % mod def calc(self, l, r): return (self.h[r] - self.h[l] * self.pw[r - l]) % self.mod @staticmethod def gen(a, b, num): result = set() while 1: import random import math random.seed() while 1: v = random.randint(a, b) // 2 * 2 + 1 if v not in result: break for x in range(3, int(math.sqrt(v)) + 1, 2): if v % x == 0: break else: result.add(v) if len(result) == num: break return result def __init__(self, s, rand=False, num=5): if rand: bases = RollingHash.gen(2, 10**3, num) else: assert num <= 10 bases = [641, 103, 661, 293, 547, 311, 29, 457, 613, 599][:num] MOD = 10**9 + 7 self.rhs = [self.RH(s, b, MOD) for b in bases] def calc(self, l, r): return tuple(rh.calc(l, r) for rh in self.rhs) def slv(N, A, B): a = [] for i in range(N): a.append(A[i] ^ A[i - 1]) a = a[:] + a[:] b = [] for i in range(N): b.append(B[i] ^ B[i - 1]) ah = RollingHash(a) bh = RollingHash(b) ans = [] h = bh.calc(0, N) for k in range(N): if ah.calc(k, N + k) == h: ans.append("%d %d" % (k, A[k] ^ B[0])) return ans def main(): N = read_int() A = read_int_n() B = read_int_n() print(*slv(N, A, B), sep="\n") if __name__ == "__main__": main()
false
0.952381
[ "+ a = a[:] + a[:]", "+ h = bh.calc(0, N)", "- if ah.calc(k, N) == bh.calc(0, N - k) and ah.calc(0, k) == bh.calc(N - k, N):", "+ if ah.calc(k, N + k) == h:" ]
false
0.044858
0.045476
0.986406
[ "s363269442", "s127555888" ]
u747602774
p03569
python
s453681770
s724856809
74
68
8,736
3,316
Accepted
Accepted
8.11
S = eval(input()) N = len(S) ans = [] check = [] for i in range(N): if S[i] != 'x': ans.append(S[i]) check.append(i) if len(ans) == 0: print((0)) exit() if ans != ans[::-1]: print((-1)) exit() if len(ans)%2: cl,cr = check[len(ans)//2],check[len(ans)//2] else: cl,cr = check[len(ans)//2-1],check[len(ans)//2] cnt = 0 while 0 <= cl and cr <= N-1: if S[cl] == S[cr]: cl -= 1 cr += 1 elif S[cl] == 'x': cnt += 1 cl -= 1 else: cnt += 1 cr += 1 cnt += max(cl+1,N-cr) print(cnt)
S = eval(input()) N = len(S) l = 0 r = N-1 ans = 0 while l < r: if S[l] == S[r]: l += 1 r -= 1 elif S[l] == 'x': l += 1 ans += 1 elif S[r] == 'x': r -= 1 ans += 1 else: print((-1)) exit() print(ans)
31
20
596
291
S = eval(input()) N = len(S) ans = [] check = [] for i in range(N): if S[i] != "x": ans.append(S[i]) check.append(i) if len(ans) == 0: print((0)) exit() if ans != ans[::-1]: print((-1)) exit() if len(ans) % 2: cl, cr = check[len(ans) // 2], check[len(ans) // 2] else: cl, cr = check[len(ans) // 2 - 1], check[len(ans) // 2] cnt = 0 while 0 <= cl and cr <= N - 1: if S[cl] == S[cr]: cl -= 1 cr += 1 elif S[cl] == "x": cnt += 1 cl -= 1 else: cnt += 1 cr += 1 cnt += max(cl + 1, N - cr) print(cnt)
S = eval(input()) N = len(S) l = 0 r = N - 1 ans = 0 while l < r: if S[l] == S[r]: l += 1 r -= 1 elif S[l] == "x": l += 1 ans += 1 elif S[r] == "x": r -= 1 ans += 1 else: print((-1)) exit() print(ans)
false
35.483871
[ "-ans = []", "-check = []", "-for i in range(N):", "- if S[i] != \"x\":", "- ans.append(S[i])", "- check.append(i)", "-if len(ans) == 0:", "- print((0))", "- exit()", "-if ans != ans[::-1]:", "- print((-1))", "- exit()", "-if len(ans) % 2:", "- cl, cr = check[len(ans) // 2], check[len(ans) // 2]", "-else:", "- cl, cr = check[len(ans) // 2 - 1], check[len(ans) // 2]", "-cnt = 0", "-while 0 <= cl and cr <= N - 1:", "- if S[cl] == S[cr]:", "- cl -= 1", "- cr += 1", "- elif S[cl] == \"x\":", "- cnt += 1", "- cl -= 1", "+l = 0", "+r = N - 1", "+ans = 0", "+while l < r:", "+ if S[l] == S[r]:", "+ l += 1", "+ r -= 1", "+ elif S[l] == \"x\":", "+ l += 1", "+ ans += 1", "+ elif S[r] == \"x\":", "+ r -= 1", "+ ans += 1", "- cnt += 1", "- cr += 1", "-cnt += max(cl + 1, N - cr)", "-print(cnt)", "+ print((-1))", "+ exit()", "+print(ans)" ]
false
0.04403
0.06215
0.708451
[ "s453681770", "s724856809" ]
u261103969
p02695
python
s726656474
s759660721
1,168
672
9,092
23,164
Accepted
Accepted
42.47
from itertools import combinations_with_replacement as comb_rplc n, m, q = list(map(int, input().split())) # reqは[[a1,b1,c1,d1],[a2,b2,c2,d2]……]が入ったリストのリストです req = [list(map(int, input().split())) for _ in range(q)] ans = 0 # seqは長さnのタプルです for seq in comb_rplc(list(range(1, m + 1)), n): score = 0 for a, b, c, d in req: # 問題文に書いてある数列のk番目は、インデックスだとk-1になるので注意 if seq[b - 1] - seq[a - 1] == c: score += d ans = max(ans, score) print(ans)
from collections import deque # 数列の点数を計算する関数 def calc(seq): score = 0 for a, b, c, d in req: if seq[b - 1] - seq[a - 1] == c: score += d return score n, m, q = list(map(int, input().split())) req = [list(map(int, input().split())) for _ in range(q)] ans = 0 que = deque() # 数列の1番目、[1]~[m]までキューに追加しますが、 # 実は、この問題は数列の最初が[1]の場合だけを考えても解けます。 for i in range(1, m + 1): que.append([i]) while que: seq = que.popleft() if len(seq) == n: # 長さがnになったので、得点を計算します score = calc(seq) ans = max(ans, score) else: # 次に追加する数字は、下限が今の数列の一番後ろの数字、上限がmです for i in range(seq[-1], m + 1): seq_next = seq + [i] que.append(seq_next) print(ans)
17
39
489
771
from itertools import combinations_with_replacement as comb_rplc n, m, q = list(map(int, input().split())) # reqは[[a1,b1,c1,d1],[a2,b2,c2,d2]……]が入ったリストのリストです req = [list(map(int, input().split())) for _ in range(q)] ans = 0 # seqは長さnのタプルです for seq in comb_rplc(list(range(1, m + 1)), n): score = 0 for a, b, c, d in req: # 問題文に書いてある数列のk番目は、インデックスだとk-1になるので注意 if seq[b - 1] - seq[a - 1] == c: score += d ans = max(ans, score) print(ans)
from collections import deque # 数列の点数を計算する関数 def calc(seq): score = 0 for a, b, c, d in req: if seq[b - 1] - seq[a - 1] == c: score += d return score n, m, q = list(map(int, input().split())) req = [list(map(int, input().split())) for _ in range(q)] ans = 0 que = deque() # 数列の1番目、[1]~[m]までキューに追加しますが、 # 実は、この問題は数列の最初が[1]の場合だけを考えても解けます。 for i in range(1, m + 1): que.append([i]) while que: seq = que.popleft() if len(seq) == n: # 長さがnになったので、得点を計算します score = calc(seq) ans = max(ans, score) else: # 次に追加する数字は、下限が今の数列の一番後ろの数字、上限がmです for i in range(seq[-1], m + 1): seq_next = seq + [i] que.append(seq_next) print(ans)
false
56.410256
[ "-from itertools import combinations_with_replacement as comb_rplc", "+from collections import deque", "+", "+# 数列の点数を計算する関数", "+def calc(seq):", "+ score = 0", "+ for a, b, c, d in req:", "+ if seq[b - 1] - seq[a - 1] == c:", "+ score += d", "+ return score", "+", "-# reqは[[a1,b1,c1,d1],[a2,b2,c2,d2]……]が入ったリストのリストです", "-# seqは長さnのタプルです", "-for seq in comb_rplc(list(range(1, m + 1)), n):", "- score = 0", "- for a, b, c, d in req:", "- # 問題文に書いてある数列のk番目は、インデックスだとk-1になるので注意", "- if seq[b - 1] - seq[a - 1] == c:", "- score += d", "- ans = max(ans, score)", "+que = deque()", "+# 数列の1番目、[1]~[m]までキューに追加しますが、", "+# 実は、この問題は数列の最初が[1]の場合だけを考えても解けます。", "+for i in range(1, m + 1):", "+ que.append([i])", "+while que:", "+ seq = que.popleft()", "+ if len(seq) == n:", "+ # 長さがnになったので、得点を計算します", "+ score = calc(seq)", "+ ans = max(ans, score)", "+ else:", "+ # 次に追加する数字は、下限が今の数列の一番後ろの数字、上限がmです", "+ for i in range(seq[-1], m + 1):", "+ seq_next = seq + [i]", "+ que.append(seq_next)" ]
false
0.134772
0.006977
19.315389
[ "s726656474", "s759660721" ]
u077291787
p02767
python
s503792099
s986295984
21
18
3,060
2,940
Accepted
Accepted
14.29
# C - Rally def main(): N, *X = list(map(int, open(0).read().split())) left, right = min(X), max(X) ans = min(sum([(x - p) ** 2 for x in X]) for p in range(left, right + 1)) print(ans) if __name__ == "__main__": main()
# C - Rally def main(): N, *X = list(map(int, open(0).read().split())) calc = lambda x, p: (x - p) ** 2 P = sum(X) // N ans = min(sum(calc(x, p) for x in X) for p in range(P - 2, P + 2)) print(ans) if __name__ == "__main__": main()
10
11
249
262
# C - Rally def main(): N, *X = list(map(int, open(0).read().split())) left, right = min(X), max(X) ans = min(sum([(x - p) ** 2 for x in X]) for p in range(left, right + 1)) print(ans) if __name__ == "__main__": main()
# C - Rally def main(): N, *X = list(map(int, open(0).read().split())) calc = lambda x, p: (x - p) ** 2 P = sum(X) // N ans = min(sum(calc(x, p) for x in X) for p in range(P - 2, P + 2)) print(ans) if __name__ == "__main__": main()
false
9.090909
[ "- left, right = min(X), max(X)", "- ans = min(sum([(x - p) ** 2 for x in X]) for p in range(left, right + 1))", "+ calc = lambda x, p: (x - p) ** 2", "+ P = sum(X) // N", "+ ans = min(sum(calc(x, p) for x in X) for p in range(P - 2, P + 2))" ]
false
0.105322
0.044449
2.369526
[ "s503792099", "s986295984" ]
u724687935
p02683
python
s118042296
s829846362
83
30
9,224
9,332
Accepted
Accepted
63.86
import sys N, M, X = list(map(int, input().split())) A = [None] * N C = [None] * N for i, s in enumerate(sys.stdin.readlines()): C[i], *A[i] = list(map(int, s.split())) ans = 10 ** 8 for i in range(1 << N): k = 0 v = 0 S = [0] * M while (i >> k) > 0: if (i >> k) & 1: for j in range(M): S[j] += A[k][j] v += C[k] k += 1 if all(a >= X for a in S): ans = min(ans, v) if ans < 10 ** 8: print(ans) else: print((-1))
import sys sys.setrecursionlimit(10 ** 6) def dfs(n, v, m): global N, M, X rst = 10 ** 8 if n == N: if all(x >= X for x in m): rst = v else: nv = v + C[n] nm = tuple(m[i] + A[n][i] for i in range(M)) rst = min(dfs(n + 1, v, m), dfs(n + 1, nv, nm)) return rst N, M, X = list(map(int, input().split())) A = [None] * N C = [None] * N for i, s in enumerate(sys.stdin.readlines()): C[i], *A[i] = list(map(int, s.split())) rst = dfs(0, 0, tuple([0] * M)) ans = rst if rst < 10 ** 8 else -1 print(ans)
29
26
536
581
import sys N, M, X = list(map(int, input().split())) A = [None] * N C = [None] * N for i, s in enumerate(sys.stdin.readlines()): C[i], *A[i] = list(map(int, s.split())) ans = 10**8 for i in range(1 << N): k = 0 v = 0 S = [0] * M while (i >> k) > 0: if (i >> k) & 1: for j in range(M): S[j] += A[k][j] v += C[k] k += 1 if all(a >= X for a in S): ans = min(ans, v) if ans < 10**8: print(ans) else: print((-1))
import sys sys.setrecursionlimit(10**6) def dfs(n, v, m): global N, M, X rst = 10**8 if n == N: if all(x >= X for x in m): rst = v else: nv = v + C[n] nm = tuple(m[i] + A[n][i] for i in range(M)) rst = min(dfs(n + 1, v, m), dfs(n + 1, nv, nm)) return rst N, M, X = list(map(int, input().split())) A = [None] * N C = [None] * N for i, s in enumerate(sys.stdin.readlines()): C[i], *A[i] = list(map(int, s.split())) rst = dfs(0, 0, tuple([0] * M)) ans = rst if rst < 10**8 else -1 print(ans)
false
10.344828
[ "+", "+sys.setrecursionlimit(10**6)", "+", "+", "+def dfs(n, v, m):", "+ global N, M, X", "+ rst = 10**8", "+ if n == N:", "+ if all(x >= X for x in m):", "+ rst = v", "+ else:", "+ nv = v + C[n]", "+ nm = tuple(m[i] + A[n][i] for i in range(M))", "+ rst = min(dfs(n + 1, v, m), dfs(n + 1, nv, nm))", "+ return rst", "+", "-ans = 10**8", "-for i in range(1 << N):", "- k = 0", "- v = 0", "- S = [0] * M", "- while (i >> k) > 0:", "- if (i >> k) & 1:", "- for j in range(M):", "- S[j] += A[k][j]", "- v += C[k]", "- k += 1", "- if all(a >= X for a in S):", "- ans = min(ans, v)", "-if ans < 10**8:", "- print(ans)", "-else:", "- print((-1))", "+rst = dfs(0, 0, tuple([0] * M))", "+ans = rst if rst < 10**8 else -1", "+print(ans)" ]
false
0.038859
0.046265
0.839911
[ "s118042296", "s829846362" ]
u279493135
p03645
python
s375376438
s545799987
928
741
93,788
58,448
Accepted
Accepted
20.15
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd from bisect import bisect from heapq import heappush, heappop def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, M = MAP() ab = [LIST() for _ in range(M)] def dijkstra(E, start): N_d = len(E) dist = [INF] * N_d dist[start] = 0 q = [(0, start)] while q: dist_v, v = heappop(q) if dist[v] != dist_v: continue for u, dist_vu in E[v]: dist_u = dist_v + dist_vu if dist_u < dist[u]: dist[u] = dist_u heappush(q, (dist_u, u)) return dist E = [[] for _ in range(N)] for a, b in ab: E[a-1].append((b-1, 1)) d = dijkstra(E, 0) if d[-1] <= 2: print("POSSIBLE") else: print("IMPOSSIBLE")
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 N, M = MAP() graph = defaultdict(list) for _ in range(M): a, b = MAP() graph[a-1].append(b-1) graph[b-1].append(a-1) for i in graph[0]: if N-1 in graph[i]: print("POSSIBLE") break else: print("IMPOSSIBLE")
49
34
1,301
926
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd from bisect import bisect from heapq import heappush, heappop def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, M = MAP() ab = [LIST() for _ in range(M)] def dijkstra(E, start): N_d = len(E) dist = [INF] * N_d dist[start] = 0 q = [(0, start)] while q: dist_v, v = heappop(q) if dist[v] != dist_v: continue for u, dist_vu in E[v]: dist_u = dist_v + dist_vu if dist_u < dist[u]: dist[u] = dist_u heappush(q, (dist_u, u)) return dist E = [[] for _ in range(N)] for a, b in ab: E[a - 1].append((b - 1, 1)) d = dijkstra(E, 0) if d[-1] <= 2: print("POSSIBLE") else: print("IMPOSSIBLE")
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 N, M = MAP() graph = defaultdict(list) for _ in range(M): a, b = MAP() graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) for i in graph[0]: if N - 1 in graph[i]: print("POSSIBLE") break else: print("IMPOSSIBLE")
false
30.612245
[ "-from itertools import permutations, combinations, product, accumulate", "+from itertools import accumulate, permutations, combinations, product", "+from bisect import bisect, bisect_left", "-from bisect import bisect", "-mod = 10**9 + 7", "+MOD = 10**9 + 7", "-ab = [LIST() for _ in range(M)]", "-", "-", "-def dijkstra(E, start):", "- N_d = len(E)", "- dist = [INF] * N_d", "- dist[start] = 0", "- q = [(0, start)]", "- while q:", "- dist_v, v = heappop(q)", "- if dist[v] != dist_v:", "- continue", "- for u, dist_vu in E[v]:", "- dist_u = dist_v + dist_vu", "- if dist_u < dist[u]:", "- dist[u] = dist_u", "- heappush(q, (dist_u, u))", "- return dist", "-", "-", "-E = [[] for _ in range(N)]", "-for a, b in ab:", "- E[a - 1].append((b - 1, 1))", "-d = dijkstra(E, 0)", "-if d[-1] <= 2:", "- print(\"POSSIBLE\")", "+graph = defaultdict(list)", "+for _ in range(M):", "+ a, b = MAP()", "+ graph[a - 1].append(b - 1)", "+ graph[b - 1].append(a - 1)", "+for i in graph[0]:", "+ if N - 1 in graph[i]:", "+ print(\"POSSIBLE\")", "+ break" ]
false
0.041045
0.044467
0.923048
[ "s375376438", "s545799987" ]
u361826811
p02898
python
s725495602
s662511945
264
181
19,488
19,524
Accepted
Accepted
31.44
""" author : halo2halo date : 9, Jan, 2020 """ import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) # N = int(readline()) # D = [int(d) for d in readline().split()] import numpy as np N, K = list(map(int, readline().split())) h = [int(x) - K for x in readline().split()] ha = np.array(h) print((np.count_nonzero(ha >= 0)))
""" author : halo2halo date : 9, Jan, 2020 """ import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) # N = int(readline()) # D = [int(d) for d in readline().split()] import numpy as np N, K = list(map(int, readline().split())) h = [int(x) - K for x in readline().split()] # ha = np.array(h) print((len([x for x in h if x >= 0])))
22
23
436
444
""" author : halo2halo date : 9, Jan, 2020 """ import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) # N = int(readline()) # D = [int(d) for d in readline().split()] import numpy as np N, K = list(map(int, readline().split())) h = [int(x) - K for x in readline().split()] ha = np.array(h) print((np.count_nonzero(ha >= 0)))
""" author : halo2halo date : 9, Jan, 2020 """ import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) # N = int(readline()) # D = [int(d) for d in readline().split()] import numpy as np N, K = list(map(int, readline().split())) h = [int(x) - K for x in readline().split()] # ha = np.array(h) print((len([x for x in h if x >= 0])))
false
4.347826
[ "-ha = np.array(h)", "-print((np.count_nonzero(ha >= 0)))", "+# ha = np.array(h)", "+print((len([x for x in h if x >= 0])))" ]
false
0.712471
0.041027
17.365843
[ "s725495602", "s662511945" ]
u078349616
p02633
python
s318663147
s615620725
29
23
9,148
9,156
Accepted
Accepted
20.69
X = int(eval(input())) theta, k = 0, 0 while theta != 360: theta += X k += 1 if theta > 360: theta -= 360 print(k)
X = int(eval(input())) theta, k = 0, 0 while theta % 360 != 0 or theta == 0: theta += X k += 1 print(k)
9
6
137
110
X = int(eval(input())) theta, k = 0, 0 while theta != 360: theta += X k += 1 if theta > 360: theta -= 360 print(k)
X = int(eval(input())) theta, k = 0, 0 while theta % 360 != 0 or theta == 0: theta += X k += 1 print(k)
false
33.333333
[ "-while theta != 360:", "+while theta % 360 != 0 or theta == 0:", "- if theta > 360:", "- theta -= 360" ]
false
0.046052
0.081951
0.561946
[ "s318663147", "s615620725" ]
u488401358
p03306
python
s896863706
s592821523
770
540
77,984
71,420
Accepted
Accepted
29.87
n,m=list(map(int,input().split())) edge=[[] for i in range(n)] for i in range(m): u,v,s=list(map(int,input().split())) edge[u-1].append((v-1,s)) edge[v-1].append((u-1,s)) ans=[1 for i in range(n)] pm=[True]*n used=[False]*n used[0]=True que=[0] while que: u=que.pop() for v,s in edge[u]: if not used[v]: pm[v]=(not pm[u]) ans[v]=s-ans[u] used[v]=True que.append(v) flag=True bipart=True for u in range(n): for v,s in edge[u]: if ans[u]+ans[v]!=s: flag=False if pm[u]==pm[v]: bipart=False check=(u,v,s) if bipart: upper=float("inf") lower=1 for v in range(1,n): if pm[v]: lower=max(lower,2-ans[v]) else: upper=min(upper,ans[v]) if flag: if upper<lower: print((0)) else: print((upper-lower+1)) else: print((0)) else: u,v,s=check a,b=ans[u],ans[v] if pm[u]: diff=s-(ans[u]+ans[v]) if diff%2==1: print((0)) exit() else: for i in range(n): if pm[i]: ans[i]+=diff//2 if ans[i]<1: print((0)) exit() else: ans[i]-=diff//2 if ans[i]<1: print((0)) exit() flag=True for u in range(n): for v,s in edge[u]: if ans[u]+ans[v]!=s: flag=False print((int(flag))) else: diff=(ans[u]+ans[v])-s if diff%2==1: print((0)) exit() else: for i in range(n): if pm[i]: ans[i]+=diff//2 if ans[i]<1: print((0)) exit() else: ans[i]-=diff//2 if ans[i]<1: print((0)) exit() flag=True for u in range(n): for v,s in edge[u]: if ans[u]+ans[v]!=s: flag=False print((int(flag)))
import sys input=sys.stdin.readline n,m=list(map(int,input().split())) edge=[[] for i in range(n)] for i in range(m): u,v,s=list(map(int,input().split())) edge[u-1].append((v-1,s)) edge[v-1].append((u-1,s)) ans=[1 for i in range(n)] pm=[True]*n used=[False]*n used[0]=True que=[0] while que: u=que.pop() for v,s in edge[u]: if not used[v]: pm[v]=(not pm[u]) ans[v]=s-ans[u] used[v]=True que.append(v) flag=True bipart=True for u in range(n): for v,s in edge[u]: if ans[u]+ans[v]!=s: flag=False if pm[u]==pm[v]: bipart=False check=(u,v,s) if bipart: upper=float("inf") lower=1 for v in range(1,n): if pm[v]: lower=max(lower,2-ans[v]) else: upper=min(upper,ans[v]) if flag: if upper<lower: print((0)) else: print((upper-lower+1)) else: print((0)) else: u,v,s=check a,b=ans[u],ans[v] if pm[u]: diff=s-(ans[u]+ans[v]) if diff%2==1: print((0)) exit() else: for i in range(n): if pm[i]: ans[i]+=diff//2 if ans[i]<1: print((0)) exit() else: ans[i]-=diff//2 if ans[i]<1: print((0)) exit() flag=True for u in range(n): for v,s in edge[u]: if ans[u]+ans[v]!=s: flag=False print((int(flag))) else: diff=(ans[u]+ans[v])-s if diff%2==1: print((0)) exit() else: for i in range(n): if pm[i]: ans[i]+=diff//2 if ans[i]<1: print((0)) exit() else: ans[i]-=diff//2 if ans[i]<1: print((0)) exit() flag=True for u in range(n): for v,s in edge[u]: if ans[u]+ans[v]!=s: flag=False print((int(flag)))
100
104
2,397
2,440
n, m = list(map(int, input().split())) edge = [[] for i in range(n)] for i in range(m): u, v, s = list(map(int, input().split())) edge[u - 1].append((v - 1, s)) edge[v - 1].append((u - 1, s)) ans = [1 for i in range(n)] pm = [True] * n used = [False] * n used[0] = True que = [0] while que: u = que.pop() for v, s in edge[u]: if not used[v]: pm[v] = not pm[u] ans[v] = s - ans[u] used[v] = True que.append(v) flag = True bipart = True for u in range(n): for v, s in edge[u]: if ans[u] + ans[v] != s: flag = False if pm[u] == pm[v]: bipart = False check = (u, v, s) if bipart: upper = float("inf") lower = 1 for v in range(1, n): if pm[v]: lower = max(lower, 2 - ans[v]) else: upper = min(upper, ans[v]) if flag: if upper < lower: print((0)) else: print((upper - lower + 1)) else: print((0)) else: u, v, s = check a, b = ans[u], ans[v] if pm[u]: diff = s - (ans[u] + ans[v]) if diff % 2 == 1: print((0)) exit() else: for i in range(n): if pm[i]: ans[i] += diff // 2 if ans[i] < 1: print((0)) exit() else: ans[i] -= diff // 2 if ans[i] < 1: print((0)) exit() flag = True for u in range(n): for v, s in edge[u]: if ans[u] + ans[v] != s: flag = False print((int(flag))) else: diff = (ans[u] + ans[v]) - s if diff % 2 == 1: print((0)) exit() else: for i in range(n): if pm[i]: ans[i] += diff // 2 if ans[i] < 1: print((0)) exit() else: ans[i] -= diff // 2 if ans[i] < 1: print((0)) exit() flag = True for u in range(n): for v, s in edge[u]: if ans[u] + ans[v] != s: flag = False print((int(flag)))
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) edge = [[] for i in range(n)] for i in range(m): u, v, s = list(map(int, input().split())) edge[u - 1].append((v - 1, s)) edge[v - 1].append((u - 1, s)) ans = [1 for i in range(n)] pm = [True] * n used = [False] * n used[0] = True que = [0] while que: u = que.pop() for v, s in edge[u]: if not used[v]: pm[v] = not pm[u] ans[v] = s - ans[u] used[v] = True que.append(v) flag = True bipart = True for u in range(n): for v, s in edge[u]: if ans[u] + ans[v] != s: flag = False if pm[u] == pm[v]: bipart = False check = (u, v, s) if bipart: upper = float("inf") lower = 1 for v in range(1, n): if pm[v]: lower = max(lower, 2 - ans[v]) else: upper = min(upper, ans[v]) if flag: if upper < lower: print((0)) else: print((upper - lower + 1)) else: print((0)) else: u, v, s = check a, b = ans[u], ans[v] if pm[u]: diff = s - (ans[u] + ans[v]) if diff % 2 == 1: print((0)) exit() else: for i in range(n): if pm[i]: ans[i] += diff // 2 if ans[i] < 1: print((0)) exit() else: ans[i] -= diff // 2 if ans[i] < 1: print((0)) exit() flag = True for u in range(n): for v, s in edge[u]: if ans[u] + ans[v] != s: flag = False print((int(flag))) else: diff = (ans[u] + ans[v]) - s if diff % 2 == 1: print((0)) exit() else: for i in range(n): if pm[i]: ans[i] += diff // 2 if ans[i] < 1: print((0)) exit() else: ans[i] -= diff // 2 if ans[i] < 1: print((0)) exit() flag = True for u in range(n): for v, s in edge[u]: if ans[u] + ans[v] != s: flag = False print((int(flag)))
false
3.846154
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.042732
0.043436
0.983799
[ "s896863706", "s592821523" ]
u345621867
p02813
python
s438902047
s751766995
66
46
10,868
13,972
Accepted
Accepted
30.3
import itertools as it N = int(eval(input())) Q = [] P = [] Q = list(map(int, input().split())) P = list(map(int, input().split())) Jun = [] box = [i+1 for i in range(N)] for num in it.permutations(Q): num = list(num) Jun.append(num) Jun = sorted(Jun) for i, num in enumerate(Jun): if Q == num: a = i if P == num: b = i print((abs(a-b)))
import itertools as it N = int(eval(input())) P = tuple(map(int,input().split())) Q = tuple(map(int,input().split())) a = 0 b = 0 array = list(it.permutations(i for i in range(1,N+1))) for i,ar in enumerate(array): if ar == P: a = i if ar == Q: b = i print((abs(a-b)))
20
13
383
296
import itertools as it N = int(eval(input())) Q = [] P = [] Q = list(map(int, input().split())) P = list(map(int, input().split())) Jun = [] box = [i + 1 for i in range(N)] for num in it.permutations(Q): num = list(num) Jun.append(num) Jun = sorted(Jun) for i, num in enumerate(Jun): if Q == num: a = i if P == num: b = i print((abs(a - b)))
import itertools as it N = int(eval(input())) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) a = 0 b = 0 array = list(it.permutations(i for i in range(1, N + 1))) for i, ar in enumerate(array): if ar == P: a = i if ar == Q: b = i print((abs(a - b)))
false
35
[ "-Q = []", "-P = []", "-Q = list(map(int, input().split()))", "-P = list(map(int, input().split()))", "-Jun = []", "-box = [i + 1 for i in range(N)]", "-for num in it.permutations(Q):", "- num = list(num)", "- Jun.append(num)", "-Jun = sorted(Jun)", "-for i, num in enumerate(Jun):", "- if Q == num:", "+P = tuple(map(int, input().split()))", "+Q = tuple(map(int, input().split()))", "+a = 0", "+b = 0", "+array = list(it.permutations(i for i in range(1, N + 1)))", "+for i, ar in enumerate(array):", "+ if ar == P:", "- if P == num:", "+ if ar == Q:" ]
false
0.046863
0.035853
1.307089
[ "s438902047", "s751766995" ]
u894258749
p03252
python
s392303940
s309626528
951
189
13,184
41,840
Accepted
Accepted
80.13
import numpy as np S = eval(input()) T = eval(input()) F = -np.ones(26,dtype=np.int) G = -np.ones(26,dtype=np.int) for i in range(len(S)): s = ord(S[i])-ord('a') t = ord(T[i])-ord('a') if F[s] < 0: F[s] = t elif F[s] != t: print('No') exit() if G[t] < 0: G[t] = s elif G[t] != s: print('No') exit() print('Yes')
from collections import defaultdict class CountUp: def __init__(self, start=0): self.index = start-1 def __call__(self): self.index += 1 return self.index S = eval(input()) T = eval(input()) N = len(S) Sdic = defaultdict(CountUp()) Tdic = defaultdict(CountUp()) for i in range(N): s = Sdic[S[i]] t = Tdic[T[i]] if s != t: print('No') break else: print('Yes')
23
22
397
433
import numpy as np S = eval(input()) T = eval(input()) F = -np.ones(26, dtype=np.int) G = -np.ones(26, dtype=np.int) for i in range(len(S)): s = ord(S[i]) - ord("a") t = ord(T[i]) - ord("a") if F[s] < 0: F[s] = t elif F[s] != t: print("No") exit() if G[t] < 0: G[t] = s elif G[t] != s: print("No") exit() print("Yes")
from collections import defaultdict class CountUp: def __init__(self, start=0): self.index = start - 1 def __call__(self): self.index += 1 return self.index S = eval(input()) T = eval(input()) N = len(S) Sdic = defaultdict(CountUp()) Tdic = defaultdict(CountUp()) for i in range(N): s = Sdic[S[i]] t = Tdic[T[i]] if s != t: print("No") break else: print("Yes")
false
4.347826
[ "-import numpy as np", "+from collections import defaultdict", "+", "+", "+class CountUp:", "+ def __init__(self, start=0):", "+ self.index = start - 1", "+", "+ def __call__(self):", "+ self.index += 1", "+ return self.index", "+", "-F = -np.ones(26, dtype=np.int)", "-G = -np.ones(26, dtype=np.int)", "-for i in range(len(S)):", "- s = ord(S[i]) - ord(\"a\")", "- t = ord(T[i]) - ord(\"a\")", "- if F[s] < 0:", "- F[s] = t", "- elif F[s] != t:", "+N = len(S)", "+Sdic = defaultdict(CountUp())", "+Tdic = defaultdict(CountUp())", "+for i in range(N):", "+ s = Sdic[S[i]]", "+ t = Tdic[T[i]]", "+ if s != t:", "- exit()", "- if G[t] < 0:", "- G[t] = s", "- elif G[t] != s:", "- print(\"No\")", "- exit()", "-print(\"Yes\")", "+ break", "+else:", "+ print(\"Yes\")" ]
false
0.164565
0.034976
4.70507
[ "s392303940", "s309626528" ]
u373274281
p03112
python
s589498011
s997548521
1,954
1,712
78,220
16,160
Accepted
Accepted
12.38
import bisect A, B, Q = list(map(int, input().split())) INF = 10 ** 18 s = [-INF] + [int(eval(input())) for i in range(A)] + [INF] t = [-INF] + [int(eval(input())) for i in range(B)] + [INF] for q in range(Q): x = int(eval(input())) b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x) res = INF for S in [s[b - 1], s[b]]: for T in [t[d - 1], t[d]]: d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T) res = min(res, d1, d2) print(res)
import sys from bisect import bisect_left a,b,q = list(map(int, sys.stdin.readline().split())) S = [] for _ in range(a): S.append(int(sys.stdin.readline())) T = [] for _ in range(b): T.append(int(sys.stdin.readline())) X = [] for _ in range(q): X.append(int(sys.stdin.readline())) INF = 10 ** 11 def dfs(direction, tors, pos, count): if tors == 1: L = T elif tors == -1: L = S i = bisect_left(L, pos) if i == len(L): if direction == 1: return INF elif direction == -1: res = abs(L[i-1]-pos) next_pos = L[i-1] elif L[i] == pos: res = 0 next_pos = pos else: if direction == 1: res = abs(L[i]-pos) next_pos = L[i] elif direction == -1: if i == 0: return INF res = abs(L[i-1]-pos) next_pos = L[i-1] if count == 1: return res res0 = res + dfs(direction, tors*(-1), next_pos, count-1) res1 = res + dfs(direction*(-1), tors*(-1), next_pos, count-1) return min(res0, res1) for x in X: res0 = dfs(1, 1, x, 2) res1 = dfs(-1, 1, x, 2) res2 = dfs(1, -1, x, 2) res3 = dfs(-1, -1, x, 2) print((min(res0, res1, res2, res3)))
14
55
463
1,190
import bisect A, B, Q = list(map(int, input().split())) INF = 10**18 s = [-INF] + [int(eval(input())) for i in range(A)] + [INF] t = [-INF] + [int(eval(input())) for i in range(B)] + [INF] for q in range(Q): x = int(eval(input())) b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x) res = INF for S in [s[b - 1], s[b]]: for T in [t[d - 1], t[d]]: d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T) res = min(res, d1, d2) print(res)
import sys from bisect import bisect_left a, b, q = list(map(int, sys.stdin.readline().split())) S = [] for _ in range(a): S.append(int(sys.stdin.readline())) T = [] for _ in range(b): T.append(int(sys.stdin.readline())) X = [] for _ in range(q): X.append(int(sys.stdin.readline())) INF = 10**11 def dfs(direction, tors, pos, count): if tors == 1: L = T elif tors == -1: L = S i = bisect_left(L, pos) if i == len(L): if direction == 1: return INF elif direction == -1: res = abs(L[i - 1] - pos) next_pos = L[i - 1] elif L[i] == pos: res = 0 next_pos = pos else: if direction == 1: res = abs(L[i] - pos) next_pos = L[i] elif direction == -1: if i == 0: return INF res = abs(L[i - 1] - pos) next_pos = L[i - 1] if count == 1: return res res0 = res + dfs(direction, tors * (-1), next_pos, count - 1) res1 = res + dfs(direction * (-1), tors * (-1), next_pos, count - 1) return min(res0, res1) for x in X: res0 = dfs(1, 1, x, 2) res1 = dfs(-1, 1, x, 2) res2 = dfs(1, -1, x, 2) res3 = dfs(-1, -1, x, 2) print((min(res0, res1, res2, res3)))
false
74.545455
[ "-import bisect", "+import sys", "+from bisect import bisect_left", "-A, B, Q = list(map(int, input().split()))", "-INF = 10**18", "-s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]", "-t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]", "-for q in range(Q):", "- x = int(eval(input()))", "- b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)", "- res = INF", "- for S in [s[b - 1], s[b]]:", "- for T in [t[d - 1], t[d]]:", "- d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)", "- res = min(res, d1, d2)", "- print(res)", "+a, b, q = list(map(int, sys.stdin.readline().split()))", "+S = []", "+for _ in range(a):", "+ S.append(int(sys.stdin.readline()))", "+T = []", "+for _ in range(b):", "+ T.append(int(sys.stdin.readline()))", "+X = []", "+for _ in range(q):", "+ X.append(int(sys.stdin.readline()))", "+INF = 10**11", "+", "+", "+def dfs(direction, tors, pos, count):", "+ if tors == 1:", "+ L = T", "+ elif tors == -1:", "+ L = S", "+ i = bisect_left(L, pos)", "+ if i == len(L):", "+ if direction == 1:", "+ return INF", "+ elif direction == -1:", "+ res = abs(L[i - 1] - pos)", "+ next_pos = L[i - 1]", "+ elif L[i] == pos:", "+ res = 0", "+ next_pos = pos", "+ else:", "+ if direction == 1:", "+ res = abs(L[i] - pos)", "+ next_pos = L[i]", "+ elif direction == -1:", "+ if i == 0:", "+ return INF", "+ res = abs(L[i - 1] - pos)", "+ next_pos = L[i - 1]", "+ if count == 1:", "+ return res", "+ res0 = res + dfs(direction, tors * (-1), next_pos, count - 1)", "+ res1 = res + dfs(direction * (-1), tors * (-1), next_pos, count - 1)", "+ return min(res0, res1)", "+", "+", "+for x in X:", "+ res0 = dfs(1, 1, x, 2)", "+ res1 = dfs(-1, 1, x, 2)", "+ res2 = dfs(1, -1, x, 2)", "+ res3 = dfs(-1, -1, x, 2)", "+ print((min(res0, res1, res2, res3)))" ]
false
0.043016
0.087286
0.492809
[ "s589498011", "s997548521" ]
u145950990
p03041
python
s333959638
s510294583
171
24
38,256
8,996
Accepted
Accepted
85.96
n,k = list(map(int,input().split())) s = eval(input()) print((s[:k-1]+s[k-1].lower()+s[k:]))
n,k = list(map(int,input().split())) s = list(eval(input())) s[k-1] = s[k-1].lower() print((''.join(s)))
3
5
80
95
n, k = list(map(int, input().split())) s = eval(input()) print((s[: k - 1] + s[k - 1].lower() + s[k:]))
n, k = list(map(int, input().split())) s = list(eval(input())) s[k - 1] = s[k - 1].lower() print(("".join(s)))
false
40
[ "-s = eval(input())", "-print((s[: k - 1] + s[k - 1].lower() + s[k:]))", "+s = list(eval(input()))", "+s[k - 1] = s[k - 1].lower()", "+print((\"\".join(s)))" ]
false
0.038209
0.046098
0.828858
[ "s333959638", "s510294583" ]
u037430802
p03775
python
s423886055
s381382398
48
43
2,940
3,060
Accepted
Accepted
10.42
N = int(eval(input())) a = 1 i = 2 while i * i <= N: if N % i == 0: a = i i += 1 b = N // a print((max(len(str(a)), len(str(b)))))
N = int(eval(input())) ans = 11 a = 1 i = 1 while i * i <= N: if N % i == 0: a = i b = N//a ans = min(ans, len(str((max(a,b))))) i += 1 print(ans)
11
14
150
188
N = int(eval(input())) a = 1 i = 2 while i * i <= N: if N % i == 0: a = i i += 1 b = N // a print((max(len(str(a)), len(str(b)))))
N = int(eval(input())) ans = 11 a = 1 i = 1 while i * i <= N: if N % i == 0: a = i b = N // a ans = min(ans, len(str((max(a, b))))) i += 1 print(ans)
false
21.428571
[ "+ans = 11", "-i = 2", "+i = 1", "+ b = N // a", "+ ans = min(ans, len(str((max(a, b)))))", "-b = N // a", "-print((max(len(str(a)), len(str(b)))))", "+print(ans)" ]
false
0.057447
0.058425
0.983265
[ "s423886055", "s381382398" ]
u312025627
p03038
python
s970427477
s399556817
479
420
26,988
65,080
Accepted
Accepted
12.32
def main(): N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] bcs = [[int(i) for i in input().split()] for _ in range(M)] A.sort() bcs.sort(reverse=True,key=lambda c:c[1]) cards = [] for b,c in bcs: for i in range(b): cards.append(c) if len(cards) == N: break if len(cards) == N: break from itertools import zip_longest ans = 0 for a,card in zip_longest(A,cards,fillvalue=0): if a < card: ans += card else: ans += a print(ans) if __name__ == "__main__": main()
def main(): import sys input = sys.stdin.buffer.readline # from heapq import heappop, heappush N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A.sort(reverse=True) BC = [[int(i) for i in input().split()] for j in range(M)] BC.sort(key=lambda p: p[1], reverse=True) p = 0 flag = False for b, c in BC: for i in range(b): if A and A[-1] < c: A.pop() p += c else: flag = True break if flag: break print((sum(A) + p)) if __name__ == '__main__': main()
27
26
675
671
def main(): N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] bcs = [[int(i) for i in input().split()] for _ in range(M)] A.sort() bcs.sort(reverse=True, key=lambda c: c[1]) cards = [] for b, c in bcs: for i in range(b): cards.append(c) if len(cards) == N: break if len(cards) == N: break from itertools import zip_longest ans = 0 for a, card in zip_longest(A, cards, fillvalue=0): if a < card: ans += card else: ans += a print(ans) if __name__ == "__main__": main()
def main(): import sys input = sys.stdin.buffer.readline # from heapq import heappop, heappush N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A.sort(reverse=True) BC = [[int(i) for i in input().split()] for j in range(M)] BC.sort(key=lambda p: p[1], reverse=True) p = 0 flag = False for b, c in BC: for i in range(b): if A and A[-1] < c: A.pop() p += c else: flag = True break if flag: break print((sum(A) + p)) if __name__ == "__main__": main()
false
3.703704
[ "+ import sys", "+", "+ input = sys.stdin.buffer.readline", "+ # from heapq import heappop, heappush", "- bcs = [[int(i) for i in input().split()] for _ in range(M)]", "- A.sort()", "- bcs.sort(reverse=True, key=lambda c: c[1])", "- cards = []", "- for b, c in bcs:", "+ A.sort(reverse=True)", "+ BC = [[int(i) for i in input().split()] for j in range(M)]", "+ BC.sort(key=lambda p: p[1], reverse=True)", "+ p = 0", "+ flag = False", "+ for b, c in BC:", "- cards.append(c)", "- if len(cards) == N:", "+ if A and A[-1] < c:", "+ A.pop()", "+ p += c", "+ else:", "+ flag = True", "- if len(cards) == N:", "+ if flag:", "- from itertools import zip_longest", "-", "- ans = 0", "- for a, card in zip_longest(A, cards, fillvalue=0):", "- if a < card:", "- ans += card", "- else:", "- ans += a", "- print(ans)", "+ print((sum(A) + p))" ]
false
0.040427
0.134893
0.299697
[ "s970427477", "s399556817" ]
u028973125
p02819
python
s386831234
s764129653
185
114
38,896
25,980
Accepted
Accepted
38.38
import sys from pprint import pprint import math def is_prime(x): if x == 1: return False for k in range(2, int(math.sqrt(x)) + 1): if x % k == 0: return False return True def solve(x): for i in range(x, 10**6): if is_prime(i): print(i) return if __name__ == '__main__': x = int(sys.stdin.readline().strip()) solve(x)
import sys X = int(sys.stdin.readline()) exists = set() for i in range(2, X + 10**5 + 1): if i in exists: continue exists.add(i) if X <= i: # print(exists) print(i) sys.exit() for j in range(i+i, X + 10**5 + 1, i): exists.add(j)
22
15
419
300
import sys from pprint import pprint import math def is_prime(x): if x == 1: return False for k in range(2, int(math.sqrt(x)) + 1): if x % k == 0: return False return True def solve(x): for i in range(x, 10**6): if is_prime(i): print(i) return if __name__ == "__main__": x = int(sys.stdin.readline().strip()) solve(x)
import sys X = int(sys.stdin.readline()) exists = set() for i in range(2, X + 10**5 + 1): if i in exists: continue exists.add(i) if X <= i: # print(exists) print(i) sys.exit() for j in range(i + i, X + 10**5 + 1, i): exists.add(j)
false
31.818182
[ "-from pprint import pprint", "-import math", "-", "-def is_prime(x):", "- if x == 1:", "- return False", "- for k in range(2, int(math.sqrt(x)) + 1):", "- if x % k == 0:", "- return False", "- return True", "-", "-", "-def solve(x):", "- for i in range(x, 10**6):", "- if is_prime(i):", "- print(i)", "- return", "-", "-", "-if __name__ == \"__main__\":", "- x = int(sys.stdin.readline().strip())", "- solve(x)", "+X = int(sys.stdin.readline())", "+exists = set()", "+for i in range(2, X + 10**5 + 1):", "+ if i in exists:", "+ continue", "+ exists.add(i)", "+ if X <= i:", "+ # print(exists)", "+ print(i)", "+ sys.exit()", "+ for j in range(i + i, X + 10**5 + 1, i):", "+ exists.add(j)" ]
false
0.035262
0.082653
0.426629
[ "s386831234", "s764129653" ]
u191394596
p03160
python
s065663811
s584630541
1,024
158
287,328
13,980
Accepted
Accepted
84.57
import sys from functools import lru_cache sys.setrecursionlimit(10**6) INF = sys.maxsize N = int(input().strip()) h = [int(x) for x in input().split()] @lru_cache() def solve(i): if i >= N - 1: return 0 return min( solve(i + 1) + abs(h[i] - h[i + 1]) if i + 1 < N else INF, solve(i + 2) + abs(h[i] - h[i + 2]) if i + 2 < N else INF ) print((solve(0)))
import sys INF = sys.maxsize N = int(input().strip()) h = [int(x) for x in input().split()] memo = [INF] * N for i in range(N - 1, -1, -1): if i == N -1: memo[i] = 0 else: memo[i] = min( memo[i + 1] + abs(h[i] - h[i + 1]) if i + 1 < N else INF, memo[i + 2] + abs(h[i] - h[i + 2]) if i + 2 < N else INF ) print((memo[0]))
20
19
398
395
import sys from functools import lru_cache sys.setrecursionlimit(10**6) INF = sys.maxsize N = int(input().strip()) h = [int(x) for x in input().split()] @lru_cache() def solve(i): if i >= N - 1: return 0 return min( solve(i + 1) + abs(h[i] - h[i + 1]) if i + 1 < N else INF, solve(i + 2) + abs(h[i] - h[i + 2]) if i + 2 < N else INF, ) print((solve(0)))
import sys INF = sys.maxsize N = int(input().strip()) h = [int(x) for x in input().split()] memo = [INF] * N for i in range(N - 1, -1, -1): if i == N - 1: memo[i] = 0 else: memo[i] = min( memo[i + 1] + abs(h[i] - h[i + 1]) if i + 1 < N else INF, memo[i + 2] + abs(h[i] - h[i + 2]) if i + 2 < N else INF, ) print((memo[0]))
false
5
[ "-from functools import lru_cache", "-sys.setrecursionlimit(10**6)", "-", "-", "-@lru_cache()", "-def solve(i):", "- if i >= N - 1:", "- return 0", "- return min(", "- solve(i + 1) + abs(h[i] - h[i + 1]) if i + 1 < N else INF,", "- solve(i + 2) + abs(h[i] - h[i + 2]) if i + 2 < N else INF,", "- )", "-", "-", "-print((solve(0)))", "+memo = [INF] * N", "+for i in range(N - 1, -1, -1):", "+ if i == N - 1:", "+ memo[i] = 0", "+ else:", "+ memo[i] = min(", "+ memo[i + 1] + abs(h[i] - h[i + 1]) if i + 1 < N else INF,", "+ memo[i + 2] + abs(h[i] - h[i + 2]) if i + 2 < N else INF,", "+ )", "+print((memo[0]))" ]
false
0.037472
0.13411
0.279412
[ "s065663811", "s584630541" ]
u191874006
p03142
python
s903061718
s075141909
549
472
71,472
70,832
Accepted
Accepted
14.03
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n,m = LI() edges = [[] for _ in range(n)] cnt = [[0,i] for i in range(n)] for _ in range(n-1+m): a,b = LI() edges[a-1].append(b-1) cnt[b-1][0] += 1 ans = [None]*n que = deque() for i in range(n): if cnt[i][0] == 0: que.append(cnt[i][1]) ans[cnt[i][1]] = 0 while que: v = que.popleft() for i in edges[v]: cnt[i][0] -= 1 if cnt[i][0] == 0: que.append(i) ans[i] = v+1 break for i in ans: print(i)
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) """ [トポロジカルソート] ⇒入次数0の頂点からスタートし、その番号を1とする.  1から出ている有向辺をすべて削除 入次数0になった頂点の番号を2とし、2から出ている有向辺をすべて削除 入次数0になった頂点の番号を3とし、...を繰り返す 常に入次数が0になった頂点を選択してその1つ前を親とするため、 出来上がったグラフの各頂点の親は、そのグラフで最も近い親(距離1) つまり、後から足されたM本の辺ではない よって、トポロジカルソートによって得られるグラフが元の木である. """ n,m = LI() edges = [[] for _ in range(n)] cnt = [[0,i] for i in range(n)] for _ in range(n-1+m): a,b = LI() edges[a-1].append(b-1) cnt[b-1][0] += 1 ans = [None]*n que = deque() for i in range(n): if cnt[i][0] == 0: que.append(cnt[i][1]) ans[cnt[i][1]] = 0 while que: v = que.popleft() for i in edges[v]: cnt[i][0] -= 1 if cnt[i][0] == 0: que.append(i) ans[i] = v+1 break for i in ans: print(i)
45
57
1,130
1,393
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) n, m = LI() edges = [[] for _ in range(n)] cnt = [[0, i] for i in range(n)] for _ in range(n - 1 + m): a, b = LI() edges[a - 1].append(b - 1) cnt[b - 1][0] += 1 ans = [None] * n que = deque() for i in range(n): if cnt[i][0] == 0: que.append(cnt[i][1]) ans[cnt[i][1]] = 0 while que: v = que.popleft() for i in edges[v]: cnt[i][0] -= 1 if cnt[i][0] == 0: que.append(i) ans[i] = v + 1 break for i in ans: print(i)
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) """ [トポロジカルソート] ⇒入次数0の頂点からスタートし、その番号を1とする.  1から出ている有向辺をすべて削除 入次数0になった頂点の番号を2とし、2から出ている有向辺をすべて削除 入次数0になった頂点の番号を3とし、...を繰り返す 常に入次数が0になった頂点を選択してその1つ前を親とするため、 出来上がったグラフの各頂点の親は、そのグラフで最も近い親(距離1) つまり、後から足されたM本の辺ではない よって、トポロジカルソートによって得られるグラフが元の木である. """ n, m = LI() edges = [[] for _ in range(n)] cnt = [[0, i] for i in range(n)] for _ in range(n - 1 + m): a, b = LI() edges[a - 1].append(b - 1) cnt[b - 1][0] += 1 ans = [None] * n que = deque() for i in range(n): if cnt[i][0] == 0: que.append(cnt[i][1]) ans[cnt[i][1]] = 0 while que: v = que.popleft() for i in edges[v]: cnt[i][0] -= 1 if cnt[i][0] == 0: que.append(i) ans[i] = v + 1 break for i in ans: print(i)
false
21.052632
[ "+\"\"\"", "+[トポロジカルソート]", "+⇒入次数0の頂点からスタートし、その番号を1とする.", "+ 1から出ている有向辺をすべて削除", "+ 入次数0になった頂点の番号を2とし、2から出ている有向辺をすべて削除", "+ 入次数0になった頂点の番号を3とし、...を繰り返す", "+常に入次数が0になった頂点を選択してその1つ前を親とするため、", "+出来上がったグラフの各頂点の親は、そのグラフで最も近い親(距離1)", "+つまり、後から足されたM本の辺ではない", "+よって、トポロジカルソートによって得られるグラフが元の木である.", "+\"\"\"" ]
false
0.111763
0.05676
1.96904
[ "s903061718", "s075141909" ]
u930705402
p03061
python
s703336881
s328591932
891
168
88,696
107,072
Accepted
Accepted
81.14
from math import gcd class SEGTree: def __init__(self,n): self.Unit=0 i=1 while(i<n): i*=2 self.SEG=[self.Unit]*(2*i-1) self.d=i def update(self,i,x): i+=self.d-1 self.SEG[i]=x while i>0: i=(i-1)//2 self.SEG[i]=gcd(self.SEG[i*2+1],self.SEG[i*2+2]) def find(self,a,b,k,l,r): if r<=a or b<=l: return self.Unit if a<=l and r<=b: return self.SEG[k] else: c1=self.find(a,b,2*k+1,l,(l+r)//2) c2=self.find(a,b,2*k+2,(l+r)//2,r) return gcd(c1,c2) def get(self,a,b): return self.find(a,b,0,0,self.d) N=int(eval(input())) SEG=SEGTree(N) A=list(map(int,input().split())) for i in range(N): SEG.update(i,A[i]) ans=1 for i in range(N): l,r=SEG.get(0,i),SEG.get(i+1,N) ans=max(ans,gcd(l,r)) print(ans)
from math import gcd class SparseTable: def __init__(self,arr,N,op,e): self.A=arr self.N=N self.Unit=e self.Op=op self.K=N.bit_length()-1 self.pow2=[1] for i in range(self.K): self.pow2.append(self.pow2[-1]*2) self.ST=[[self.Unit]*(self.K+1) for i in range(N)] for i in range(N): self.ST[i][0]=self.A[i] for i in reversed(list(range(N))): for k in range(1,self.K+1): if self.N<i+self.pow2[k]: break self.ST[i][k]=self.Op(self.ST[i][k-1],self.ST[i+self.pow2[k-1]][k-1]) def get(self,l,r): if l==r: return self.Unit x=r-l t=x.bit_length()-1 return self.Op(self.ST[l][t],self.ST[r-self.pow2[t]][t]) N=int(eval(input())) A=list(map(int,input().split())) ST=SparseTable(A,N,gcd,0) ans=1 for i in range(N): l,r=ST.get(0,i),ST.get(i+1,N) ans=max(ans,gcd(l,r)) print(ans)
37
35
938
1,015
from math import gcd class SEGTree: def __init__(self, n): self.Unit = 0 i = 1 while i < n: i *= 2 self.SEG = [self.Unit] * (2 * i - 1) self.d = i def update(self, i, x): i += self.d - 1 self.SEG[i] = x while i > 0: i = (i - 1) // 2 self.SEG[i] = gcd(self.SEG[i * 2 + 1], self.SEG[i * 2 + 2]) def find(self, a, b, k, l, r): if r <= a or b <= l: return self.Unit if a <= l and r <= b: return self.SEG[k] else: c1 = self.find(a, b, 2 * k + 1, l, (l + r) // 2) c2 = self.find(a, b, 2 * k + 2, (l + r) // 2, r) return gcd(c1, c2) def get(self, a, b): return self.find(a, b, 0, 0, self.d) N = int(eval(input())) SEG = SEGTree(N) A = list(map(int, input().split())) for i in range(N): SEG.update(i, A[i]) ans = 1 for i in range(N): l, r = SEG.get(0, i), SEG.get(i + 1, N) ans = max(ans, gcd(l, r)) print(ans)
from math import gcd class SparseTable: def __init__(self, arr, N, op, e): self.A = arr self.N = N self.Unit = e self.Op = op self.K = N.bit_length() - 1 self.pow2 = [1] for i in range(self.K): self.pow2.append(self.pow2[-1] * 2) self.ST = [[self.Unit] * (self.K + 1) for i in range(N)] for i in range(N): self.ST[i][0] = self.A[i] for i in reversed(list(range(N))): for k in range(1, self.K + 1): if self.N < i + self.pow2[k]: break self.ST[i][k] = self.Op( self.ST[i][k - 1], self.ST[i + self.pow2[k - 1]][k - 1] ) def get(self, l, r): if l == r: return self.Unit x = r - l t = x.bit_length() - 1 return self.Op(self.ST[l][t], self.ST[r - self.pow2[t]][t]) N = int(eval(input())) A = list(map(int, input().split())) ST = SparseTable(A, N, gcd, 0) ans = 1 for i in range(N): l, r = ST.get(0, i), ST.get(i + 1, N) ans = max(ans, gcd(l, r)) print(ans)
false
5.405405
[ "-class SEGTree:", "- def __init__(self, n):", "- self.Unit = 0", "- i = 1", "- while i < n:", "- i *= 2", "- self.SEG = [self.Unit] * (2 * i - 1)", "- self.d = i", "+class SparseTable:", "+ def __init__(self, arr, N, op, e):", "+ self.A = arr", "+ self.N = N", "+ self.Unit = e", "+ self.Op = op", "+ self.K = N.bit_length() - 1", "+ self.pow2 = [1]", "+ for i in range(self.K):", "+ self.pow2.append(self.pow2[-1] * 2)", "+ self.ST = [[self.Unit] * (self.K + 1) for i in range(N)]", "+ for i in range(N):", "+ self.ST[i][0] = self.A[i]", "+ for i in reversed(list(range(N))):", "+ for k in range(1, self.K + 1):", "+ if self.N < i + self.pow2[k]:", "+ break", "+ self.ST[i][k] = self.Op(", "+ self.ST[i][k - 1], self.ST[i + self.pow2[k - 1]][k - 1]", "+ )", "- def update(self, i, x):", "- i += self.d - 1", "- self.SEG[i] = x", "- while i > 0:", "- i = (i - 1) // 2", "- self.SEG[i] = gcd(self.SEG[i * 2 + 1], self.SEG[i * 2 + 2])", "-", "- def find(self, a, b, k, l, r):", "- if r <= a or b <= l:", "+ def get(self, l, r):", "+ if l == r:", "- if a <= l and r <= b:", "- return self.SEG[k]", "- else:", "- c1 = self.find(a, b, 2 * k + 1, l, (l + r) // 2)", "- c2 = self.find(a, b, 2 * k + 2, (l + r) // 2, r)", "- return gcd(c1, c2)", "-", "- def get(self, a, b):", "- return self.find(a, b, 0, 0, self.d)", "+ x = r - l", "+ t = x.bit_length() - 1", "+ return self.Op(self.ST[l][t], self.ST[r - self.pow2[t]][t])", "-SEG = SEGTree(N)", "-for i in range(N):", "- SEG.update(i, A[i])", "+ST = SparseTable(A, N, gcd, 0)", "- l, r = SEG.get(0, i), SEG.get(i + 1, N)", "+ l, r = ST.get(0, i), ST.get(i + 1, N)" ]
false
0.047095
0.080422
0.585591
[ "s703336881", "s328591932" ]
u606045429
p02793
python
s921273359
s811304491
1,512
581
6,076
6,072
Accepted
Accepted
61.57
from fractions import gcd mod = 10 ** 9 + 7 N, *A = list(map(int, open(0).read().split())) L = 1 for a in A: L *= a // gcd(L, a) print((sum(L // a for a in A) % mod))
from fractions import gcd mod = 10 ** 9 + 7 N, *A = list(map(int, open(0).read().split())) L = 1 for a in A: L *= a // gcd(L, a) L %= mod print((sum(L * pow(a, mod - 2, mod) % mod for a in A) % mod))
11
13
176
212
from fractions import gcd mod = 10**9 + 7 N, *A = list(map(int, open(0).read().split())) L = 1 for a in A: L *= a // gcd(L, a) print((sum(L // a for a in A) % mod))
from fractions import gcd mod = 10**9 + 7 N, *A = list(map(int, open(0).read().split())) L = 1 for a in A: L *= a // gcd(L, a) L %= mod print((sum(L * pow(a, mod - 2, mod) % mod for a in A) % mod))
false
15.384615
[ "-print((sum(L // a for a in A) % mod))", "+L %= mod", "+print((sum(L * pow(a, mod - 2, mod) % mod for a in A) % mod))" ]
false
0.046114
0.046559
0.990442
[ "s921273359", "s811304491" ]
u539367121
p02732
python
s403688155
s605389641
306
220
34,364
32,180
Accepted
Accepted
28.1
def main(): N=int(eval(input())) A=[int(a) for a in input().split()] Acnt, Aprob={}, {} for a in A: Acnt[a] = Acnt.get(a, 0) + 1 sumA=0 for k, a in list(Acnt.items()): Aprob[k]=a*(a-1)//2 sumA+=Aprob[k] #Acnt=[A.count(n) for n in range(N+1)] #Aprob=[Acnt[n]*(Acnt[n]-1)//2 for n in range(N+1)] #sumA=sum(Aprob) for a in A: ans=(Acnt[a]-1)*(Acnt[a]-2)//2 print((ans+sumA-Aprob[a])) main()
def main(): N=int(eval(input())) A=[int(a) for a in input().split()] cnt={} for a in A: cnt[a] = cnt.get(a, 0) + 1 prob=0 for a in list(cnt.values()): prob+=a*(a-1)//2 for a in A: print((prob-(cnt[a]-1))) main()
20
15
438
247
def main(): N = int(eval(input())) A = [int(a) for a in input().split()] Acnt, Aprob = {}, {} for a in A: Acnt[a] = Acnt.get(a, 0) + 1 sumA = 0 for k, a in list(Acnt.items()): Aprob[k] = a * (a - 1) // 2 sumA += Aprob[k] # Acnt=[A.count(n) for n in range(N+1)] # Aprob=[Acnt[n]*(Acnt[n]-1)//2 for n in range(N+1)] # sumA=sum(Aprob) for a in A: ans = (Acnt[a] - 1) * (Acnt[a] - 2) // 2 print((ans + sumA - Aprob[a])) main()
def main(): N = int(eval(input())) A = [int(a) for a in input().split()] cnt = {} for a in A: cnt[a] = cnt.get(a, 0) + 1 prob = 0 for a in list(cnt.values()): prob += a * (a - 1) // 2 for a in A: print((prob - (cnt[a] - 1))) main()
false
25
[ "- Acnt, Aprob = {}, {}", "+ cnt = {}", "- Acnt[a] = Acnt.get(a, 0) + 1", "- sumA = 0", "- for k, a in list(Acnt.items()):", "- Aprob[k] = a * (a - 1) // 2", "- sumA += Aprob[k]", "- # Acnt=[A.count(n) for n in range(N+1)]", "- # Aprob=[Acnt[n]*(Acnt[n]-1)//2 for n in range(N+1)]", "- # sumA=sum(Aprob)", "+ cnt[a] = cnt.get(a, 0) + 1", "+ prob = 0", "+ for a in list(cnt.values()):", "+ prob += a * (a - 1) // 2", "- ans = (Acnt[a] - 1) * (Acnt[a] - 2) // 2", "- print((ans + sumA - Aprob[a]))", "+ print((prob - (cnt[a] - 1)))" ]
false
0.037117
0.035861
1.035024
[ "s403688155", "s605389641" ]
u539969758
p02550
python
s129888844
s411434845
157
64
18,308
15,828
Accepted
Accepted
59.24
N, X, M = list(map(int, input().split())) candicate = [pow(i, 2, M) for i in range(M)] ans = 0 now = X A = [0] X2 = pow(X, 2, M) d = dict() flag = True for i in range(1, N+1): if i == 1: A.append(X) else: nxt = candicate[A[i-1]] if d.get(nxt) == None: if nxt == 0: A.append(nxt) break else: A.append(nxt) d[nxt] = i else: flag = False break if flag: print((sum(A))) else: l = d[nxt] r = i - 1 circle_total = 0 for j in range(l, r+1): circle_total += A[j] for j in range(1, l): ans += A[j] width = r - l + 1 N -= (l - 1) ans += circle_total * (N // width) for j in range(l, l + N % width): ans += A[j] print(ans)
N,X,M = list(map(int,input().split())) ans = X A = X TF = True srt = 1000000 retu = [X] d = dict() d[X] = 0 loop = X flag = False for i in range(N-1): if TF: A = A**2 % M if d.get(A) != None: srt = d[A] goal = i TF = False if TF: retu.append(A) d[A] = i + 1 loop += A else: flag = True break if flag: n = (N-srt)//(goal-srt+1) saisyo = sum(retu[:srt]) loop -= saisyo print((saisyo + loop*n + sum(retu[srt:N-n*(goal-srt+1)]))) else: print((sum(retu[:N])))
51
35
894
627
N, X, M = list(map(int, input().split())) candicate = [pow(i, 2, M) for i in range(M)] ans = 0 now = X A = [0] X2 = pow(X, 2, M) d = dict() flag = True for i in range(1, N + 1): if i == 1: A.append(X) else: nxt = candicate[A[i - 1]] if d.get(nxt) == None: if nxt == 0: A.append(nxt) break else: A.append(nxt) d[nxt] = i else: flag = False break if flag: print((sum(A))) else: l = d[nxt] r = i - 1 circle_total = 0 for j in range(l, r + 1): circle_total += A[j] for j in range(1, l): ans += A[j] width = r - l + 1 N -= l - 1 ans += circle_total * (N // width) for j in range(l, l + N % width): ans += A[j] print(ans)
N, X, M = list(map(int, input().split())) ans = X A = X TF = True srt = 1000000 retu = [X] d = dict() d[X] = 0 loop = X flag = False for i in range(N - 1): if TF: A = A**2 % M if d.get(A) != None: srt = d[A] goal = i TF = False if TF: retu.append(A) d[A] = i + 1 loop += A else: flag = True break if flag: n = (N - srt) // (goal - srt + 1) saisyo = sum(retu[:srt]) loop -= saisyo print((saisyo + loop * n + sum(retu[srt : N - n * (goal - srt + 1)]))) else: print((sum(retu[:N])))
false
31.372549
[ "-candicate = [pow(i, 2, M) for i in range(M)]", "-ans = 0", "-now = X", "-A = [0]", "-X2 = pow(X, 2, M)", "+ans = X", "+A = X", "+TF = True", "+srt = 1000000", "+retu = [X]", "-flag = True", "-for i in range(1, N + 1):", "- if i == 1:", "- A.append(X)", "+d[X] = 0", "+loop = X", "+flag = False", "+for i in range(N - 1):", "+ if TF:", "+ A = A**2 % M", "+ if d.get(A) != None:", "+ srt = d[A]", "+ goal = i", "+ TF = False", "+ if TF:", "+ retu.append(A)", "+ d[A] = i + 1", "+ loop += A", "- nxt = candicate[A[i - 1]]", "- if d.get(nxt) == None:", "- if nxt == 0:", "- A.append(nxt)", "- break", "- else:", "- A.append(nxt)", "- d[nxt] = i", "- else:", "- flag = False", "- break", "+ flag = True", "+ break", "- print((sum(A)))", "+ n = (N - srt) // (goal - srt + 1)", "+ saisyo = sum(retu[:srt])", "+ loop -= saisyo", "+ print((saisyo + loop * n + sum(retu[srt : N - n * (goal - srt + 1)])))", "- l = d[nxt]", "- r = i - 1", "- circle_total = 0", "- for j in range(l, r + 1):", "- circle_total += A[j]", "- for j in range(1, l):", "- ans += A[j]", "- width = r - l + 1", "- N -= l - 1", "- ans += circle_total * (N // width)", "- for j in range(l, l + N % width):", "- ans += A[j]", "- print(ans)", "+ print((sum(retu[:N])))" ]
false
0.087598
0.104976
0.834456
[ "s129888844", "s411434845" ]
u579699847
p03774
python
s234305006
s137180155
303
149
21,592
12,432
Accepted
Accepted
50.83
import numpy as np,sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,M = LI() ab = np.array([LI() for _ in range(N)],dtype=int) cd = np.array([LI() for _ in range(M)],dtype=int) for x in ab: vector = np.sum(np.abs(cd-x),axis=1).tolist() print((vector.index(min(vector))+1))
import numpy as np,sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,M = LI() ab = np.array([LI() for _ in range(N)]) cd = np.array([LI() for _ in range(M)]) for x in ab: print((np.argmin(np.sum(np.abs(cd-x),axis=1))+1))
8
7
313
255
import numpy as np, sys def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) N, M = LI() ab = np.array([LI() for _ in range(N)], dtype=int) cd = np.array([LI() for _ in range(M)], dtype=int) for x in ab: vector = np.sum(np.abs(cd - x), axis=1).tolist() print((vector.index(min(vector)) + 1))
import numpy as np, sys def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) N, M = LI() ab = np.array([LI() for _ in range(N)]) cd = np.array([LI() for _ in range(M)]) for x in ab: print((np.argmin(np.sum(np.abs(cd - x), axis=1)) + 1))
false
12.5
[ "-ab = np.array([LI() for _ in range(N)], dtype=int)", "-cd = np.array([LI() for _ in range(M)], dtype=int)", "+ab = np.array([LI() for _ in range(N)])", "+cd = np.array([LI() for _ in range(M)])", "- vector = np.sum(np.abs(cd - x), axis=1).tolist()", "- print((vector.index(min(vector)) + 1))", "+ print((np.argmin(np.sum(np.abs(cd - x), axis=1)) + 1))" ]
false
0.206155
0.494352
0.417021
[ "s234305006", "s137180155" ]
u190405389
p02721
python
s433856469
s148548247
343
305
91,112
57,464
Accepted
Accepted
11.08
n,k,c = list(map(int, input().split())) s = eval(input()) # 計算途中はi=0~n-1日とする # [a,b] i日までで、限界まで働くとa回働けてb日まで働けない pre = [[0,0] for i in range(n)] if s[0]=='o': pre[0]=[1,c] for j in range(c): if 1+j < n: pre[1+j] = pre[0] + [] for i in range(1,n): if pre[i]==[0,0]: if s[i]=='o': pre[i][0]=pre[i-1][0]+1 pre[i][1]+=i+c for j in range(c): if i+j+1<n: pre[i+j+1]=pre[i]+[] else: pre[i]=pre[i-1]+[] # i日以降で限界まで働くとa回働ける post = [0 for i in range(n)] if s[-1]=='o': post[-1]=1 for j in range(c): if 0 <= n-1-j-1 < n: post[-1-j-1] = post[-1] for i in range(1,n): if post[n-i-1]==0: if s[n-i-1]=='o': post[n-i-1]=post[n-i]+1 for j in range(c): if 0<=n-i-1-j-1<n: post[n-i-1-j-1]=post[n-i-1] else: post[n-i-1]=post[n-i] # 0日、n+1日を追加。iを1~n日にする pre = [[0,0]]+pre+[[0,0]] post = [0]+post+[0] # i日に休んだときに、働く回数がkに到達するか調べる ans = [] for i in range(1,n+1): if s[i-1]=='o': work, rest = pre[i-1] day = min(max(rest,i)+1,n+1) work = work + post[day] if work<k: ans.append(i) for i in range(len(ans)): print((ans[i]))
# 解説 n,k,c = list(map(int, input().split())) s = eval(input()) l = [0 for i in range(n)] r = [-1 for i in range(n)] a = 1 b = -1 for i in range(n): if s[i]=='o' and b<i: l[i]=a a+=1 b=i+c if a>k: break a = k b = n for i in range(n): if s[-i-1]=='o' and b>n-i-1: r[-i-1]=a a-=1 b=n-i-1-c if a<1: break for i in range(n): if l[i]==r[i]: print((i+1))
58
31
1,350
477
n, k, c = list(map(int, input().split())) s = eval(input()) # 計算途中はi=0~n-1日とする # [a,b] i日までで、限界まで働くとa回働けてb日まで働けない pre = [[0, 0] for i in range(n)] if s[0] == "o": pre[0] = [1, c] for j in range(c): if 1 + j < n: pre[1 + j] = pre[0] + [] for i in range(1, n): if pre[i] == [0, 0]: if s[i] == "o": pre[i][0] = pre[i - 1][0] + 1 pre[i][1] += i + c for j in range(c): if i + j + 1 < n: pre[i + j + 1] = pre[i] + [] else: pre[i] = pre[i - 1] + [] # i日以降で限界まで働くとa回働ける post = [0 for i in range(n)] if s[-1] == "o": post[-1] = 1 for j in range(c): if 0 <= n - 1 - j - 1 < n: post[-1 - j - 1] = post[-1] for i in range(1, n): if post[n - i - 1] == 0: if s[n - i - 1] == "o": post[n - i - 1] = post[n - i] + 1 for j in range(c): if 0 <= n - i - 1 - j - 1 < n: post[n - i - 1 - j - 1] = post[n - i - 1] else: post[n - i - 1] = post[n - i] # 0日、n+1日を追加。iを1~n日にする pre = [[0, 0]] + pre + [[0, 0]] post = [0] + post + [0] # i日に休んだときに、働く回数がkに到達するか調べる ans = [] for i in range(1, n + 1): if s[i - 1] == "o": work, rest = pre[i - 1] day = min(max(rest, i) + 1, n + 1) work = work + post[day] if work < k: ans.append(i) for i in range(len(ans)): print((ans[i]))
# 解説 n, k, c = list(map(int, input().split())) s = eval(input()) l = [0 for i in range(n)] r = [-1 for i in range(n)] a = 1 b = -1 for i in range(n): if s[i] == "o" and b < i: l[i] = a a += 1 b = i + c if a > k: break a = k b = n for i in range(n): if s[-i - 1] == "o" and b > n - i - 1: r[-i - 1] = a a -= 1 b = n - i - 1 - c if a < 1: break for i in range(n): if l[i] == r[i]: print((i + 1))
false
46.551724
[ "+# 解説", "-# 計算途中はi=0~n-1日とする", "-# [a,b] i日までで、限界まで働くとa回働けてb日まで働けない", "-pre = [[0, 0] for i in range(n)]", "-if s[0] == \"o\":", "- pre[0] = [1, c]", "- for j in range(c):", "- if 1 + j < n:", "- pre[1 + j] = pre[0] + []", "-for i in range(1, n):", "- if pre[i] == [0, 0]:", "- if s[i] == \"o\":", "- pre[i][0] = pre[i - 1][0] + 1", "- pre[i][1] += i + c", "- for j in range(c):", "- if i + j + 1 < n:", "- pre[i + j + 1] = pre[i] + []", "- else:", "- pre[i] = pre[i - 1] + []", "-# i日以降で限界まで働くとa回働ける", "-post = [0 for i in range(n)]", "-if s[-1] == \"o\":", "- post[-1] = 1", "- for j in range(c):", "- if 0 <= n - 1 - j - 1 < n:", "- post[-1 - j - 1] = post[-1]", "-for i in range(1, n):", "- if post[n - i - 1] == 0:", "- if s[n - i - 1] == \"o\":", "- post[n - i - 1] = post[n - i] + 1", "- for j in range(c):", "- if 0 <= n - i - 1 - j - 1 < n:", "- post[n - i - 1 - j - 1] = post[n - i - 1]", "- else:", "- post[n - i - 1] = post[n - i]", "-# 0日、n+1日を追加。iを1~n日にする", "-pre = [[0, 0]] + pre + [[0, 0]]", "-post = [0] + post + [0]", "-# i日に休んだときに、働く回数がkに到達するか調べる", "-ans = []", "-for i in range(1, n + 1):", "- if s[i - 1] == \"o\":", "- work, rest = pre[i - 1]", "- day = min(max(rest, i) + 1, n + 1)", "- work = work + post[day]", "- if work < k:", "- ans.append(i)", "-for i in range(len(ans)):", "- print((ans[i]))", "+l = [0 for i in range(n)]", "+r = [-1 for i in range(n)]", "+a = 1", "+b = -1", "+for i in range(n):", "+ if s[i] == \"o\" and b < i:", "+ l[i] = a", "+ a += 1", "+ b = i + c", "+ if a > k:", "+ break", "+a = k", "+b = n", "+for i in range(n):", "+ if s[-i - 1] == \"o\" and b > n - i - 1:", "+ r[-i - 1] = a", "+ a -= 1", "+ b = n - i - 1 - c", "+ if a < 1:", "+ break", "+for i in range(n):", "+ if l[i] == r[i]:", "+ print((i + 1))" ]
false
0.047022
0.168177
0.2796
[ "s433856469", "s148548247" ]
u597374218
p02628
python
s519708458
s808043047
30
27
9,108
9,252
Accepted
Accepted
10
N, K = list(map(int, input().split())) p = sorted(map(int, input().split())) print((sum(p[:K])))
N, K = list(map(int, input().split())) p = list(map(int, input().split())) print((sum(sorted(p)[0:K])))
3
3
90
97
N, K = list(map(int, input().split())) p = sorted(map(int, input().split())) print((sum(p[:K])))
N, K = list(map(int, input().split())) p = list(map(int, input().split())) print((sum(sorted(p)[0:K])))
false
0
[ "-p = sorted(map(int, input().split()))", "-print((sum(p[:K])))", "+p = list(map(int, input().split()))", "+print((sum(sorted(p)[0:K])))" ]
false
0.040126
0.043442
0.923654
[ "s519708458", "s808043047" ]
u645250356
p03338
python
s545362865
s101812412
295
137
64,748
72,744
Accepted
Accepted
53.56
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() s = list(eval(input())) res = 0 for i in range(1,n): x = s[:i] y = s[i:] sx = set(x) sy = set(y) cnt = 0 for i in list(sx): if i in sy: cnt += 1 res = max(res, cnt) print(res)
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() s = eval(input()) res = 0 for i in range(n): a = s[:i] b = s[i:] ss = set(b) ans = 0 sss = set() for x in a: if x in ss and not x in sss: ans += 1 sss.add(x) res = max(res, ans) print(res)
23
25
563
616
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify import sys, bisect, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() s = list(eval(input())) res = 0 for i in range(1, n): x = s[:i] y = s[i:] sx = set(x) sy = set(y) cnt = 0 for i in list(sx): if i in sy: cnt += 1 res = max(res, cnt) print(res)
from collections import Counter, defaultdict, deque from heapq import heappop, heappush from bisect import bisect_left, bisect_right import sys, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() s = eval(input()) res = 0 for i in range(n): a = s[:i] b = s[i:] ss = set(b) ans = 0 sss = set() for x in a: if x in ss and not x in sss: ans += 1 sss.add(x) res = max(res, ans) print(res)
false
8
[ "-from heapq import heappop, heappush, heapify", "-import sys, bisect, math, itertools, fractions, pprint", "+from heapq import heappop, heappush", "+from bisect import bisect_left, bisect_right", "+import sys, math, itertools, fractions, pprint", "-s = list(eval(input()))", "+s = eval(input())", "-for i in range(1, n):", "- x = s[:i]", "- y = s[i:]", "- sx = set(x)", "- sy = set(y)", "- cnt = 0", "- for i in list(sx):", "- if i in sy:", "- cnt += 1", "- res = max(res, cnt)", "+for i in range(n):", "+ a = s[:i]", "+ b = s[i:]", "+ ss = set(b)", "+ ans = 0", "+ sss = set()", "+ for x in a:", "+ if x in ss and not x in sss:", "+ ans += 1", "+ sss.add(x)", "+ res = max(res, ans)" ]
false
0.045602
0.037956
1.201461
[ "s545362865", "s101812412" ]
u810288681
p02813
python
s585055497
s919290708
36
29
8,308
8,052
Accepted
Accepted
19.44
import itertools n = int(eval(input())) p = tuple(list(map(int, input().split()))) q = tuple(list(map(int, input().split()))) po = 0 qo = 0 l = sorted(list(itertools.permutations(list(range(1,n+1))))) for i in range(len(l)): if l[i] == p: po = i if l[i]== q: qo = i print((abs(po-qo)))
import itertools n = int(eval(input())) p = list(map(int, input().split())) q = list(map(int, input().split())) l = sorted(itertools.permutations([i for i in range(1,n+1)])) print((abs(l.index(tuple(p))-l.index(tuple(q)))))
13
6
307
220
import itertools n = int(eval(input())) p = tuple(list(map(int, input().split()))) q = tuple(list(map(int, input().split()))) po = 0 qo = 0 l = sorted(list(itertools.permutations(list(range(1, n + 1))))) for i in range(len(l)): if l[i] == p: po = i if l[i] == q: qo = i print((abs(po - qo)))
import itertools n = int(eval(input())) p = list(map(int, input().split())) q = list(map(int, input().split())) l = sorted(itertools.permutations([i for i in range(1, n + 1)])) print((abs(l.index(tuple(p)) - l.index(tuple(q)))))
false
53.846154
[ "-p = tuple(list(map(int, input().split())))", "-q = tuple(list(map(int, input().split())))", "-po = 0", "-qo = 0", "-l = sorted(list(itertools.permutations(list(range(1, n + 1)))))", "-for i in range(len(l)):", "- if l[i] == p:", "- po = i", "- if l[i] == q:", "- qo = i", "-print((abs(po - qo)))", "+p = list(map(int, input().split()))", "+q = list(map(int, input().split()))", "+l = sorted(itertools.permutations([i for i in range(1, n + 1)]))", "+print((abs(l.index(tuple(p)) - l.index(tuple(q)))))" ]
false
0.144619
0.039514
3.659948
[ "s585055497", "s919290708" ]
u475584892
p02947
python
s425714066
s960863462
392
362
72,540
64,220
Accepted
Accepted
7.65
def slove(): import sys import collections input = sys.stdin.readline n = int(input().rstrip('\n')) s = ["".join(sorted(list(str(input().rstrip('\n'))))) for _ in range(n)] s = collections.Counter(s).most_common() t = 0 for i, v in s: for j in range(v-1, 0, -1): t += j print(t) if __name__ == '__main__': slove()
def slove(): import sys import collections input = sys.stdin.readline n = int(input().rstrip('\n')) s = collections.Counter(["".join(sorted(list(str(input().rstrip('\n'))))) for _ in range(n)]) cnt = 0 for k, v in list(s.items()): for i in range(1, v): cnt += i print(cnt) if __name__ == '__main__': slove()
16
15
391
374
def slove(): import sys import collections input = sys.stdin.readline n = int(input().rstrip("\n")) s = ["".join(sorted(list(str(input().rstrip("\n"))))) for _ in range(n)] s = collections.Counter(s).most_common() t = 0 for i, v in s: for j in range(v - 1, 0, -1): t += j print(t) if __name__ == "__main__": slove()
def slove(): import sys import collections input = sys.stdin.readline n = int(input().rstrip("\n")) s = collections.Counter( ["".join(sorted(list(str(input().rstrip("\n"))))) for _ in range(n)] ) cnt = 0 for k, v in list(s.items()): for i in range(1, v): cnt += i print(cnt) if __name__ == "__main__": slove()
false
6.25
[ "- s = [\"\".join(sorted(list(str(input().rstrip(\"\\n\"))))) for _ in range(n)]", "- s = collections.Counter(s).most_common()", "- t = 0", "- for i, v in s:", "- for j in range(v - 1, 0, -1):", "- t += j", "- print(t)", "+ s = collections.Counter(", "+ [\"\".join(sorted(list(str(input().rstrip(\"\\n\"))))) for _ in range(n)]", "+ )", "+ cnt = 0", "+ for k, v in list(s.items()):", "+ for i in range(1, v):", "+ cnt += i", "+ print(cnt)" ]
false
0.04975
0.047391
1.049792
[ "s425714066", "s960863462" ]
u653837719
p02982
python
s241680855
s342988543
21
17
3,316
3,064
Accepted
Accepted
19.05
import math n, d = list(map(int, input().split())) x = [] cnt = 0 sum = 0 for _ in range(n): tmp = list(map(int, input().split())) x.append(tmp) for i in range(n): for j in range(i + 1, n): sum = 0 for k in range(d): sum += (x[i][k] - x[j][k]) ** 2 distance = math.sqrt(sum) if distance.is_integer(): cnt += 1 print(cnt)
n, d = list(map(int, input().split())) x = [] cnt = 0 sum = 0 for _ in range(n): tmp = list(map(int, input().split())) x.append(tmp) for i in range(n): for j in range(i + 1, n): sum = 0 for k in range(d): sum += (x[i][k] - x[j][k]) ** 2 distance = sum ** 0.5 if distance.is_integer(): cnt += 1 print(cnt)
20
18
405
386
import math n, d = list(map(int, input().split())) x = [] cnt = 0 sum = 0 for _ in range(n): tmp = list(map(int, input().split())) x.append(tmp) for i in range(n): for j in range(i + 1, n): sum = 0 for k in range(d): sum += (x[i][k] - x[j][k]) ** 2 distance = math.sqrt(sum) if distance.is_integer(): cnt += 1 print(cnt)
n, d = list(map(int, input().split())) x = [] cnt = 0 sum = 0 for _ in range(n): tmp = list(map(int, input().split())) x.append(tmp) for i in range(n): for j in range(i + 1, n): sum = 0 for k in range(d): sum += (x[i][k] - x[j][k]) ** 2 distance = sum**0.5 if distance.is_integer(): cnt += 1 print(cnt)
false
10
[ "-import math", "-", "- distance = math.sqrt(sum)", "+ distance = sum**0.5" ]
false
0.040012
0.041601
0.961818
[ "s241680855", "s342988543" ]
u018679195
p02784
python
s038218660
s703101201
55
41
13,964
13,964
Accepted
Accepted
25.45
H,N= list(map(int,input().split())) A=list(map(int,input().split())) x=0 for i in range(N): x=x+A[i] if x>=H: print("Yes") else: print("No")
hn = list(map(int,input().split())) h,n = hn a = list(map(int,input().split())) h -= sum(a) if h > 0: print ("No") else: print ("Yes")
12
8
166
149
H, N = list(map(int, input().split())) A = list(map(int, input().split())) x = 0 for i in range(N): x = x + A[i] if x >= H: print("Yes") else: print("No")
hn = list(map(int, input().split())) h, n = hn a = list(map(int, input().split())) h -= sum(a) if h > 0: print("No") else: print("Yes")
false
33.333333
[ "-H, N = list(map(int, input().split()))", "-A = list(map(int, input().split()))", "-x = 0", "-for i in range(N):", "- x = x + A[i]", "-if x >= H:", "+hn = list(map(int, input().split()))", "+h, n = hn", "+a = list(map(int, input().split()))", "+h -= sum(a)", "+if h > 0:", "+ print(\"No\")", "+else:", "-else:", "- print(\"No\")" ]
false
0.092853
0.040794
2.276134
[ "s038218660", "s703101201" ]
u864197622
p03465
python
s595430936
s872118946
572
467
5,436
9,164
Accepted
Accepted
18.36
N = int(eval(input())) A = [int(a) for a in input().split()] s = 1 for a in A: s |= s << a for i in range((sum(A)+1)//2, sum(A)+1): if s & (1<<i): print(i) break
N = int(eval(input())) A = [int(a) for a in input().split()] s = 1 for a in A: s |= s << a ss = bin(s) for i in range((sum(A)+1)//2, sum(A)+1): if ss[-i-1] == "1": print(i) break
10
11
189
207
N = int(eval(input())) A = [int(a) for a in input().split()] s = 1 for a in A: s |= s << a for i in range((sum(A) + 1) // 2, sum(A) + 1): if s & (1 << i): print(i) break
N = int(eval(input())) A = [int(a) for a in input().split()] s = 1 for a in A: s |= s << a ss = bin(s) for i in range((sum(A) + 1) // 2, sum(A) + 1): if ss[-i - 1] == "1": print(i) break
false
9.090909
[ "+ss = bin(s)", "- if s & (1 << i):", "+ if ss[-i - 1] == \"1\":" ]
false
0.035048
0.035517
0.986785
[ "s595430936", "s872118946" ]
u709304134
p02714
python
s098200696
s456946050
1,906
1,631
9,460
9,468
Accepted
Accepted
14.43
from collections import Counter N = int(eval(input())) S = eval(input()) #c = Counter(S) #print (c.most_common()) #ls = list(c.values()) ans = S.count('R') * S.count('G') * S.count('B') for i in range(N): for j in range(1,N): a = i + j b = i + j + j if (b >= N): break else: l = S[i] m = S[a] r = S[b] if l!=m and m!=r and r!=l: ans -= 1 # if (i-j<0 or i+j>=N): # break # l = S[i-j] # m = S[i] # r = S[i+j] # if l!=m and m!=r and r!=l: # ans -= 1 print (ans)
from collections import Counter N = int(eval(input())) S = eval(input()) ans = S.count('R') * S.count('G') * S.count('B') for i in range(N): for j in range(1,N): if (i-j<0 or i+j>=N): break l = S[i-j] m = S[i] r = S[i+j] if l!=m and m!=r and r!=l: ans -= 1 print (ans)
29
15
653
340
from collections import Counter N = int(eval(input())) S = eval(input()) # c = Counter(S) # print (c.most_common()) # ls = list(c.values()) ans = S.count("R") * S.count("G") * S.count("B") for i in range(N): for j in range(1, N): a = i + j b = i + j + j if b >= N: break else: l = S[i] m = S[a] r = S[b] if l != m and m != r and r != l: ans -= 1 # if (i-j<0 or i+j>=N): # break # l = S[i-j] # m = S[i] # r = S[i+j] # if l!=m and m!=r and r!=l: # ans -= 1 print(ans)
from collections import Counter N = int(eval(input())) S = eval(input()) ans = S.count("R") * S.count("G") * S.count("B") for i in range(N): for j in range(1, N): if i - j < 0 or i + j >= N: break l = S[i - j] m = S[i] r = S[i + j] if l != m and m != r and r != l: ans -= 1 print(ans)
false
48.275862
[ "-# c = Counter(S)", "-# print (c.most_common())", "-# ls = list(c.values())", "- a = i + j", "- b = i + j + j", "- if b >= N:", "+ if i - j < 0 or i + j >= N:", "- else:", "- l = S[i]", "- m = S[a]", "- r = S[b]", "- if l != m and m != r and r != l:", "- ans -= 1", "- # if (i-j<0 or i+j>=N):", "- # break", "- # l = S[i-j]", "- # m = S[i]", "- # r = S[i+j]", "- # if l!=m and m!=r and r!=l:", "- # ans -= 1", "+ l = S[i - j]", "+ m = S[i]", "+ r = S[i + j]", "+ if l != m and m != r and r != l:", "+ ans -= 1" ]
false
0.035497
0.040534
0.87573
[ "s098200696", "s456946050" ]
u869917163
p02755
python
s640962227
s633989087
20
18
3,060
3,060
Accepted
Accepted
10
A, B = list(map(int, input().split())) for i in range(1, 10001): if int(i*0.08) == A and int(i*0.1) == B: print(i) break else: print((-1))
import sys A,B = list(map(int,input().split())) for i in range(1,1251): C_8 = int(i*0.08) C_10 = int(i*0.1) if C_8 == A and C_10 == B: print(i) sys.exit() print((-1))
7
10
160
182
A, B = list(map(int, input().split())) for i in range(1, 10001): if int(i * 0.08) == A and int(i * 0.1) == B: print(i) break else: print((-1))
import sys A, B = list(map(int, input().split())) for i in range(1, 1251): C_8 = int(i * 0.08) C_10 = int(i * 0.1) if C_8 == A and C_10 == B: print(i) sys.exit() print((-1))
false
30
[ "+import sys", "+", "-for i in range(1, 10001):", "- if int(i * 0.08) == A and int(i * 0.1) == B:", "+for i in range(1, 1251):", "+ C_8 = int(i * 0.08)", "+ C_10 = int(i * 0.1)", "+ if C_8 == A and C_10 == B:", "- break", "-else:", "- print((-1))", "+ sys.exit()", "+print((-1))" ]
false
0.04832
0.047995
1.00679
[ "s640962227", "s633989087" ]
u045091221
p03282
python
s084605329
s998952151
39
33
9,704
9,928
Accepted
Accepted
15.38
import re S = eval(input()) K = int(eval(input())) m = re.match(r'\A(1+)([1-9]*)\Z', S) if m: print(('1' if len(m.group(1)) >= K else m.group(2)[0])) else: print((S[0]))
import re S = eval(input()) K = int(eval(input())) m = re.match(r'\A(1*)([1-9]*)\Z', S) print(('1' if len(m.group(1)) >= K else m.group(2)[0]))
10
7
173
138
import re S = eval(input()) K = int(eval(input())) m = re.match(r"\A(1+)([1-9]*)\Z", S) if m: print(("1" if len(m.group(1)) >= K else m.group(2)[0])) else: print((S[0]))
import re S = eval(input()) K = int(eval(input())) m = re.match(r"\A(1*)([1-9]*)\Z", S) print(("1" if len(m.group(1)) >= K else m.group(2)[0]))
false
30
[ "-m = re.match(r\"\\A(1+)([1-9]*)\\Z\", S)", "-if m:", "- print((\"1\" if len(m.group(1)) >= K else m.group(2)[0]))", "-else:", "- print((S[0]))", "+m = re.match(r\"\\A(1*)([1-9]*)\\Z\", S)", "+print((\"1\" if len(m.group(1)) >= K else m.group(2)[0]))" ]
false
0.044335
0.042889
1.033708
[ "s084605329", "s998952151" ]
u562935282
p02959
python
s367712261
s706196317
188
113
18,476
18,624
Accepted
Accepted
39.89
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 for i, bb in enumerate(b): use = min(a[i], b[i]) ans += use a[i] -= use b[i] -= use if b[i] == 0: continue use = min(a[i + 1], b[i]) ans += use a[i + 1] -= use print(ans)
def main(): N = int(eval(input())) *a, = list(map(int, input().split())) *b, = list(map(int, input().split())) b += [0] total_beaten = 0 carry = 0 for beat, number in zip(b, a): by_prev = min(number, carry) total_beaten += by_prev number -= by_prev by_curr = min(number, beat) total_beaten += by_curr carry = beat - by_curr print(total_beaten) if __name__ == '__main__': main()
19
24
330
474
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 for i, bb in enumerate(b): use = min(a[i], b[i]) ans += use a[i] -= use b[i] -= use if b[i] == 0: continue use = min(a[i + 1], b[i]) ans += use a[i + 1] -= use print(ans)
def main(): N = int(eval(input())) (*a,) = list(map(int, input().split())) (*b,) = list(map(int, input().split())) b += [0] total_beaten = 0 carry = 0 for beat, number in zip(b, a): by_prev = min(number, carry) total_beaten += by_prev number -= by_prev by_curr = min(number, beat) total_beaten += by_curr carry = beat - by_curr print(total_beaten) if __name__ == "__main__": main()
false
20.833333
[ "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-b = list(map(int, input().split()))", "-ans = 0", "-for i, bb in enumerate(b):", "- use = min(a[i], b[i])", "- ans += use", "- a[i] -= use", "- b[i] -= use", "- if b[i] == 0:", "- continue", "- use = min(a[i + 1], b[i])", "- ans += use", "- a[i + 1] -= use", "-print(ans)", "+def main():", "+ N = int(eval(input()))", "+ (*a,) = list(map(int, input().split()))", "+ (*b,) = list(map(int, input().split()))", "+ b += [0]", "+ total_beaten = 0", "+ carry = 0", "+ for beat, number in zip(b, a):", "+ by_prev = min(number, carry)", "+ total_beaten += by_prev", "+ number -= by_prev", "+ by_curr = min(number, beat)", "+ total_beaten += by_curr", "+ carry = beat - by_curr", "+ print(total_beaten)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.037536
0.038316
0.979631
[ "s367712261", "s706196317" ]
u411203878
p04034
python
s210894232
s749763129
614
388
66,904
91,496
Accepted
Accepted
36.81
n, m = (int(x) for x in input().split()) ab = [] for _ in range(m): a, b = (int(x) for x in input().split()) ab.append([a-1, b-1]) box = [1]*n red = [0]*n red[0] = 1 for x,y in ab: if 0 < red[x]: red[y] = 1 box[x] -= 1 box[y] += 1 if box[x] == 0: red[x] = 0 print((sum(red)))
N,M = list(map(int,input().split())) XY = [list(map(int,input().split())) for _ in range(M)] ball_count = [1]*N red_ball_cand = [0]*N red_ball_cand[0] = 1 for i in range(M): x,y = XY[i] x,y = x-1,y-1 if 0 < red_ball_cand[x]: red_ball_cand[y] = 1 ball_count[x] -= 1 ball_count[y] += 1 if ball_count[x] == 0: red_ball_cand[x] = 0 print((sum(red_ball_cand)))
21
21
338
425
n, m = (int(x) for x in input().split()) ab = [] for _ in range(m): a, b = (int(x) for x in input().split()) ab.append([a - 1, b - 1]) box = [1] * n red = [0] * n red[0] = 1 for x, y in ab: if 0 < red[x]: red[y] = 1 box[x] -= 1 box[y] += 1 if box[x] == 0: red[x] = 0 print((sum(red)))
N, M = list(map(int, input().split())) XY = [list(map(int, input().split())) for _ in range(M)] ball_count = [1] * N red_ball_cand = [0] * N red_ball_cand[0] = 1 for i in range(M): x, y = XY[i] x, y = x - 1, y - 1 if 0 < red_ball_cand[x]: red_ball_cand[y] = 1 ball_count[x] -= 1 ball_count[y] += 1 if ball_count[x] == 0: red_ball_cand[x] = 0 print((sum(red_ball_cand)))
false
0
[ "-n, m = (int(x) for x in input().split())", "-ab = []", "-for _ in range(m):", "- a, b = (int(x) for x in input().split())", "- ab.append([a - 1, b - 1])", "-box = [1] * n", "-red = [0] * n", "-red[0] = 1", "-for x, y in ab:", "- if 0 < red[x]:", "- red[y] = 1", "- box[x] -= 1", "- box[y] += 1", "- if box[x] == 0:", "- red[x] = 0", "-print((sum(red)))", "+N, M = list(map(int, input().split()))", "+XY = [list(map(int, input().split())) for _ in range(M)]", "+ball_count = [1] * N", "+red_ball_cand = [0] * N", "+red_ball_cand[0] = 1", "+for i in range(M):", "+ x, y = XY[i]", "+ x, y = x - 1, y - 1", "+ if 0 < red_ball_cand[x]:", "+ red_ball_cand[y] = 1", "+ ball_count[x] -= 1", "+ ball_count[y] += 1", "+ if ball_count[x] == 0:", "+ red_ball_cand[x] = 0", "+print((sum(red_ball_cand)))" ]
false
0.037642
0.03836
0.981289
[ "s210894232", "s749763129" ]
u285681431
p02850
python
s608353904
s302411641
371
304
23,148
92,004
Accepted
Accepted
18.06
import sys from collections import deque n = int(eval(input())) G = [[] for _ in range(n + 1)] G_order = [] # a<bが保証されている、aを親、bを子とする for i in range(n - 1): a, b = [int(x) - 1 for x in input().split()] G[a].append(b) G_order.append(b) # どこでも良いが、ここでは0をrootとする que = deque([0]) # 各頂点と「親」を結ぶ辺の色 # 頂点0をrootとするのでC[0]=0で確定, 他を調べる colors = [0] * n while que: # prt = 親 # 幅優先探索 prt = que.popleft() color = 0 # cld = 子 for cld in G[prt]: color += 1 # 「今考えている頂点とその親を結ぶ辺の色」と同じ色は使えない if color == colors[prt]: color += 1 colors[cld] = color que.append(cld) # それぞれの頂点とその親を結ぶ辺の色 # print(colors) # 必要な最小の色数 print((max(colors))) # 辺の番号順に色を出力 for i in G_order: print((colors[i]))
from collections import deque N = int(eval(input())) # 有向グラフと見る、G[親] = [子1, 子2, ...] G = [[] for _ in range(N + 1)] # 子ノードを記録、これで辺の番号を管理 G_order = [] # a<bが保証されている、aを親、bを子とする for i in range(N - 1): a, b = [int(x) - 1 for x in input().split()] G[a].append(b) G_order.append(b) # どこでも良いが、ここでは0をrootとする que = deque([0]) # 各頂点と「親」を結ぶ辺の色 # 頂点0をrootとするのでC[0]=0で確定(「無色」), 他を調べる colors = [0] * N # BFS while que: # prt = 親 # 幅優先探索 prt = que.popleft() color = 0 # cld = 子 for cld in G[prt]: color += 1 # 「今考えている頂点とその親を結ぶ辺の色」と同じ色は使えないので次の色にする if color == colors[prt]: color += 1 colors[cld] = color que.append(cld) # それぞれの頂点とその親を結ぶ辺の色 # print(colors) # 必要な最小の色数 print((max(colors))) # 辺の番号順に色を出力 for i in G_order: print((colors[i]))
43
44
798
860
import sys from collections import deque n = int(eval(input())) G = [[] for _ in range(n + 1)] G_order = [] # a<bが保証されている、aを親、bを子とする for i in range(n - 1): a, b = [int(x) - 1 for x in input().split()] G[a].append(b) G_order.append(b) # どこでも良いが、ここでは0をrootとする que = deque([0]) # 各頂点と「親」を結ぶ辺の色 # 頂点0をrootとするのでC[0]=0で確定, 他を調べる colors = [0] * n while que: # prt = 親 # 幅優先探索 prt = que.popleft() color = 0 # cld = 子 for cld in G[prt]: color += 1 # 「今考えている頂点とその親を結ぶ辺の色」と同じ色は使えない if color == colors[prt]: color += 1 colors[cld] = color que.append(cld) # それぞれの頂点とその親を結ぶ辺の色 # print(colors) # 必要な最小の色数 print((max(colors))) # 辺の番号順に色を出力 for i in G_order: print((colors[i]))
from collections import deque N = int(eval(input())) # 有向グラフと見る、G[親] = [子1, 子2, ...] G = [[] for _ in range(N + 1)] # 子ノードを記録、これで辺の番号を管理 G_order = [] # a<bが保証されている、aを親、bを子とする for i in range(N - 1): a, b = [int(x) - 1 for x in input().split()] G[a].append(b) G_order.append(b) # どこでも良いが、ここでは0をrootとする que = deque([0]) # 各頂点と「親」を結ぶ辺の色 # 頂点0をrootとするのでC[0]=0で確定(「無色」), 他を調べる colors = [0] * N # BFS while que: # prt = 親 # 幅優先探索 prt = que.popleft() color = 0 # cld = 子 for cld in G[prt]: color += 1 # 「今考えている頂点とその親を結ぶ辺の色」と同じ色は使えないので次の色にする if color == colors[prt]: color += 1 colors[cld] = color que.append(cld) # それぞれの頂点とその親を結ぶ辺の色 # print(colors) # 必要な最小の色数 print((max(colors))) # 辺の番号順に色を出力 for i in G_order: print((colors[i]))
false
2.272727
[ "-import sys", "-n = int(eval(input()))", "-G = [[] for _ in range(n + 1)]", "+N = int(eval(input()))", "+# 有向グラフと見る、G[親] = [子1, 子2, ...]", "+G = [[] for _ in range(N + 1)]", "+# 子ノードを記録、これで辺の番号を管理", "-for i in range(n - 1):", "+for i in range(N - 1):", "-# 頂点0をrootとするのでC[0]=0で確定, 他を調べる", "-colors = [0] * n", "+# 頂点0をrootとするのでC[0]=0で確定(「無色」), 他を調べる", "+colors = [0] * N", "+# BFS", "- # 「今考えている頂点とその親を結ぶ辺の色」と同じ色は使えない", "+ # 「今考えている頂点とその親を結ぶ辺の色」と同じ色は使えないので次の色にする" ]
false
0.035212
0.033133
1.062761
[ "s608353904", "s302411641" ]
u186838327
p03627
python
s956189975
s593564226
319
95
67,608
18,060
Accepted
Accepted
70.22
n = int(eval(input())) A = list(map(int, input().split())) d = {} for i in range(n): if A[i] not in d: d[A[i]] = 1 else: d[A[i]] += 1 #print(d) L = [] for k, v in list(d.items()): if v >= 2: L.append([k, v]) L.sort(reverse=True) if len(L) == 0: print((0)) elif len(L) == 1: if L[0][1] < 4: print((0)) else: print(((L[0][0])**2)) else: if L[0][1] >= 4: print(((L[0][0])**2)) else: print((L[0][0]*L[1][0]))
n = int(eval(input())) A =list(map(int, input().split())) d = {} for i in range(n): if A[i] not in d: d[A[i]] = 1 else: d[A[i]] += 1 ans = 0 l = [] for k, v in list(d.items()): if v >= 4: ans = max(ans, k**2) l.append(k) elif v >= 2: l.append(k) else: continue if len(l) <= 1: print(ans) else: l.sort(reverse=True) ans = max(ans, l[0]*l[1]) print(ans)
27
24
498
447
n = int(eval(input())) A = list(map(int, input().split())) d = {} for i in range(n): if A[i] not in d: d[A[i]] = 1 else: d[A[i]] += 1 # print(d) L = [] for k, v in list(d.items()): if v >= 2: L.append([k, v]) L.sort(reverse=True) if len(L) == 0: print((0)) elif len(L) == 1: if L[0][1] < 4: print((0)) else: print(((L[0][0]) ** 2)) else: if L[0][1] >= 4: print(((L[0][0]) ** 2)) else: print((L[0][0] * L[1][0]))
n = int(eval(input())) A = list(map(int, input().split())) d = {} for i in range(n): if A[i] not in d: d[A[i]] = 1 else: d[A[i]] += 1 ans = 0 l = [] for k, v in list(d.items()): if v >= 4: ans = max(ans, k**2) l.append(k) elif v >= 2: l.append(k) else: continue if len(l) <= 1: print(ans) else: l.sort(reverse=True) ans = max(ans, l[0] * l[1]) print(ans)
false
11.111111
[ "-# print(d)", "-L = []", "+ans = 0", "+l = []", "- if v >= 2:", "- L.append([k, v])", "-L.sort(reverse=True)", "-if len(L) == 0:", "- print((0))", "-elif len(L) == 1:", "- if L[0][1] < 4:", "- print((0))", "+ if v >= 4:", "+ ans = max(ans, k**2)", "+ l.append(k)", "+ elif v >= 2:", "+ l.append(k)", "- print(((L[0][0]) ** 2))", "+ continue", "+if len(l) <= 1:", "+ print(ans)", "- if L[0][1] >= 4:", "- print(((L[0][0]) ** 2))", "- else:", "- print((L[0][0] * L[1][0]))", "+ l.sort(reverse=True)", "+ ans = max(ans, l[0] * l[1])", "+ print(ans)" ]
false
0.041575
0.201923
0.205895
[ "s956189975", "s593564226" ]
u943057856
p02989
python
s341418451
s188676742
84
76
14,428
14,428
Accepted
Accepted
9.52
k=int(eval(input())) d=sorted(list(map(int,input().split()))) ans=0 for i in range(d[int(len(d)/2)-1]+1,d[int(len(d)/2)]+1): ans+=1 print(ans)
n=int(eval(input())) a=sorted(list(map(int,input().split()))) p=a[n//2-1] q=a[n//2] print((q-p))
6
5
145
92
k = int(eval(input())) d = sorted(list(map(int, input().split()))) ans = 0 for i in range(d[int(len(d) / 2) - 1] + 1, d[int(len(d) / 2)] + 1): ans += 1 print(ans)
n = int(eval(input())) a = sorted(list(map(int, input().split()))) p = a[n // 2 - 1] q = a[n // 2] print((q - p))
false
16.666667
[ "-k = int(eval(input()))", "-d = sorted(list(map(int, input().split())))", "-ans = 0", "-for i in range(d[int(len(d) / 2) - 1] + 1, d[int(len(d) / 2)] + 1):", "- ans += 1", "-print(ans)", "+n = int(eval(input()))", "+a = sorted(list(map(int, input().split())))", "+p = a[n // 2 - 1]", "+q = a[n // 2]", "+print((q - p))" ]
false
0.0365
0.036632
0.996392
[ "s341418451", "s188676742" ]
u014333473
p02860
python
s102585598
s119211374
26
23
9,160
9,148
Accepted
Accepted
11.54
n=int(eval(input()));s=eval(input());print(('No' if n%2!=0 or s[:n//2]!=s[n//2:] else 'Yes'))
n=int(eval(input()));s=eval(input());print(('No'if s[:n//2]!=s[n//2:] else'Yes'))
1
1
80
67
n = int(eval(input())) s = eval(input()) print(("No" if n % 2 != 0 or s[: n // 2] != s[n // 2 :] else "Yes"))
n = int(eval(input())) s = eval(input()) print(("No" if s[: n // 2] != s[n // 2 :] else "Yes"))
false
0
[ "-print((\"No\" if n % 2 != 0 or s[: n // 2] != s[n // 2 :] else \"Yes\"))", "+print((\"No\" if s[: n // 2] != s[n // 2 :] else \"Yes\"))" ]
false
0.046099
0.046872
0.9835
[ "s102585598", "s119211374" ]
u054514819
p03361
python
s244633745
s529470753
185
65
39,152
64,928
Accepted
Accepted
64.86
H, W = list(map(int, input().split())) Map = [list(str(eval(input()))) for _ in range(H)] dirc = ((0, 1), (1, 0), (-1, 0), (0, -1)) ans = 'Yes' for h in range(H): for w in range(W): if Map[h][w]=='#': for y, x in dirc: if h+y<0 or h+y>=H or w+x<0 or w+x>=W: continue if Map[h+y][w+x]=='#': break else: ans='No' print(ans)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) H, W = mapint() query = [list(eval(input())) for _ in range(H)] def check(): for h in range(H): for w in range(W): if query[h][w]=='.': continue if h!=0 and query[h-1][w]=='#': continue if h<H-1 and query[h+1][w]=='#': continue if w!=0 and query[h][w-1]=='#': continue if w<W-1 and query[h][w+1]=='#': continue return False return True if check(): print('Yes') else: print('No')
17
28
451
714
H, W = list(map(int, input().split())) Map = [list(str(eval(input()))) for _ in range(H)] dirc = ((0, 1), (1, 0), (-1, 0), (0, -1)) ans = "Yes" for h in range(H): for w in range(W): if Map[h][w] == "#": for y, x in dirc: if h + y < 0 or h + y >= H or w + x < 0 or w + x >= W: continue if Map[h + y][w + x] == "#": break else: ans = "No" print(ans)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) H, W = mapint() query = [list(eval(input())) for _ in range(H)] def check(): for h in range(H): for w in range(W): if query[h][w] == ".": continue if h != 0 and query[h - 1][w] == "#": continue if h < H - 1 and query[h + 1][w] == "#": continue if w != 0 and query[h][w - 1] == "#": continue if w < W - 1 and query[h][w + 1] == "#": continue return False return True if check(): print("Yes") else: print("No")
false
39.285714
[ "-H, W = list(map(int, input().split()))", "-Map = [list(str(eval(input()))) for _ in range(H)]", "-dirc = ((0, 1), (1, 0), (-1, 0), (0, -1))", "-ans = \"Yes\"", "-for h in range(H):", "- for w in range(W):", "- if Map[h][w] == \"#\":", "- for y, x in dirc:", "- if h + y < 0 or h + y >= H or w + x < 0 or w + x >= W:", "- continue", "- if Map[h + y][w + x] == \"#\":", "- break", "- else:", "- ans = \"No\"", "-print(ans)", "+import sys", "+", "+", "+def input():", "+ return sys.stdin.readline().strip()", "+", "+", "+def mapint():", "+ return list(map(int, input().split()))", "+", "+", "+sys.setrecursionlimit(10**9)", "+H, W = mapint()", "+query = [list(eval(input())) for _ in range(H)]", "+", "+", "+def check():", "+ for h in range(H):", "+ for w in range(W):", "+ if query[h][w] == \".\":", "+ continue", "+ if h != 0 and query[h - 1][w] == \"#\":", "+ continue", "+ if h < H - 1 and query[h + 1][w] == \"#\":", "+ continue", "+ if w != 0 and query[h][w - 1] == \"#\":", "+ continue", "+ if w < W - 1 and query[h][w + 1] == \"#\":", "+ continue", "+ return False", "+ return True", "+", "+", "+if check():", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.040453
0.036673
1.103062
[ "s244633745", "s529470753" ]
u969850098
p02888
python
s979145663
s333179290
1,699
735
51,360
44,076
Accepted
Accepted
56.74
from bisect import bisect_left def main(): N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N-2): a = L[i] for j in range(i+1, N-1): k = bisect_left(L[j+1:], a + L[j]) ans += k print(ans) if __name__ == "__main__": main()
from bisect import bisect_left def main(): N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N-2): a = L[i] for j in range(i+1, N-1): k = bisect_left(L, a + L[j]) ans += (k - (j + 1)) print(ans) if __name__ == "__main__": main()
19
19
356
362
from bisect import bisect_left def main(): N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N - 2): a = L[i] for j in range(i + 1, N - 1): k = bisect_left(L[j + 1 :], a + L[j]) ans += k print(ans) if __name__ == "__main__": main()
from bisect import bisect_left def main(): N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N - 2): a = L[i] for j in range(i + 1, N - 1): k = bisect_left(L, a + L[j]) ans += k - (j + 1) print(ans) if __name__ == "__main__": main()
false
0
[ "- k = bisect_left(L[j + 1 :], a + L[j])", "- ans += k", "+ k = bisect_left(L, a + L[j])", "+ ans += k - (j + 1)" ]
false
0.037218
0.060055
0.619722
[ "s979145663", "s333179290" ]
u936985471
p02901
python
s934412773
s428996287
1,094
619
9,172
9,244
Accepted
Accepted
43.42
import sys readline = sys.stdin.readline N,M = list(map(int,readline().split())) INF = 10 ** 9 dp = [INF] * (2 ** N) dp[0] = 0 for i in range(M): a,b = list(map(int,readline().split())) C = list(map(int,readline().split())) key = 0 for c in C: key += (1 << (c - 1)) for j in range(len(dp) - 1, -1, -1): if dp[j] == INF: continue dp[j | key] = min(dp[j | key], dp[j] + a) if dp[-1] == INF: print((-1)) else: print((dp[-1]))
import sys readline = sys.stdin.readline N,M = list(map(int,readline().split())) INF = 10 ** 9 dp = [INF] * (2 ** N) dp[0] = 0 for i in range(M): a,b = list(map(int,readline().split())) C = list(map(int,readline().split())) key = 0 for c in C: key += (1 << (c - 1)) for j in range(len(dp) - 1, -1, -1): if dp[j] == INF: continue if dp[j | key] > dp[j] + a: dp[j | key] = dp[j] + a if dp[-1] == INF: print((-1)) else: print((dp[-1]))
23
24
464
481
import sys readline = sys.stdin.readline N, M = list(map(int, readline().split())) INF = 10**9 dp = [INF] * (2**N) dp[0] = 0 for i in range(M): a, b = list(map(int, readline().split())) C = list(map(int, readline().split())) key = 0 for c in C: key += 1 << (c - 1) for j in range(len(dp) - 1, -1, -1): if dp[j] == INF: continue dp[j | key] = min(dp[j | key], dp[j] + a) if dp[-1] == INF: print((-1)) else: print((dp[-1]))
import sys readline = sys.stdin.readline N, M = list(map(int, readline().split())) INF = 10**9 dp = [INF] * (2**N) dp[0] = 0 for i in range(M): a, b = list(map(int, readline().split())) C = list(map(int, readline().split())) key = 0 for c in C: key += 1 << (c - 1) for j in range(len(dp) - 1, -1, -1): if dp[j] == INF: continue if dp[j | key] > dp[j] + a: dp[j | key] = dp[j] + a if dp[-1] == INF: print((-1)) else: print((dp[-1]))
false
4.166667
[ "- dp[j | key] = min(dp[j | key], dp[j] + a)", "+ if dp[j | key] > dp[j] + a:", "+ dp[j | key] = dp[j] + a" ]
false
0.066361
0.107883
0.615119
[ "s934412773", "s428996287" ]
u022407960
p02281
python
s566306840
s496793240
40
20
7,872
7,852
Accepted
Accepted
50
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 9 0 1 4 1 2 3 2 -1 -1 3 -1 -1 4 5 8 5 6 7 6 -1 -1 7 -1 -1 8 -1 -1 output: Preorder 0 1 2 3 4 5 6 7 8 Inorder 2 1 3 0 6 5 7 4 8 Postorder 2 3 1 6 7 5 8 4 0 """ import sys class Node(object): def __init__(self): # init node as a single leaf node. self.parent = -1 self.children = [] self.index = -1 def pre_parse(v): print(' ' + str(v.index), end='') if not v.children: return None left_child_idx = v.children[0] right_child_idx = v.children[1] if left_child_idx != -1: pre_parse(node_list[left_child_idx]) if right_child_idx != -1: pre_parse(node_list[right_child_idx]) return None def in_parse(v): if not v.children: return None left_child_idx = v.children[0] right_child_idx = v.children[1] if left_child_idx != -1: in_parse(node_list[left_child_idx]) print(' ' + str(v.index), end='') if right_child_idx != -1: in_parse(node_list[right_child_idx]) return None def post_parse(v): if not v.children: return None left_child_idx = v.children[0] right_child_idx = v.children[1] if left_child_idx != -1: post_parse(node_list[left_child_idx]) if right_child_idx != -1: post_parse(node_list[right_child_idx]) print(' ' + str(v.index), end='') return None def generate_tree(_array): # add info of each node of a ordered tree for each in _array: idx, *children = [int(x) for x in each] # assert len(children) == 2 and idx >= 0 node_list[idx].index = idx node_list[idx].children = children for child_idx in children: # non-existent node: no parent if child_idx == -1: continue node_list[child_idx].parent = idx # find root node root_idx = [x.index for x in node_list if x.parent == -1][0] # tree walk in 3 ways print('Preorder') pre_parse(node_list[root_idx]) print('\n' + 'Inorder') in_parse(node_list[root_idx]) print('\n' + 'Postorder') post_parse(node_list[root_idx]) print('') return node_list if __name__ == '__main__': _input = sys.stdin.readlines() array_length = int(_input[0]) array = list(map(lambda x: x.split(), _input[1:])) # assert len(array) == array_length node_list = [Node() for _ in range(array_length)] ans = generate_tree(_array=array)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 9 0 1 4 1 2 3 2 -1 -1 3 -1 -1 4 5 8 5 6 7 6 -1 -1 7 -1 -1 8 -1 -1 output: Preorder 0 1 2 3 4 5 6 7 8 Inorder 2 1 3 0 6 5 7 4 8 Postorder 2 3 1 6 7 5 8 4 0 """ import sys class Node(object): def __init__(self): # init node as a single leaf node. self.parent = -1 self.children = [] self.index = -1 def pre_parse(v): print(' ' + str(v.index), end='') if not v.children: return None left_child_idx = v.children[0] right_child_idx = v.children[1] if left_child_idx != -1: pre_parse(node_list[left_child_idx]) if right_child_idx != -1: pre_parse(node_list[right_child_idx]) return None def in_parse(v): if not v.children: return None left_child_idx = v.children[0] right_child_idx = v.children[1] if left_child_idx != -1: in_parse(node_list[left_child_idx]) print(' ' + str(v.index), end='') if right_child_idx != -1: in_parse(node_list[right_child_idx]) return None def post_parse(v): if not v.children: return None left_child_idx = v.children[0] right_child_idx = v.children[1] if left_child_idx != -1: post_parse(node_list[left_child_idx]) if right_child_idx != -1: post_parse(node_list[right_child_idx]) print(' ' + str(v.index), end='') return None def generate_tree(_array): # add info of each node of a ordered tree for each in _array: idx, *children = [int(x) for x in each] # assert len(children) == 2 and idx >= 0 node_list[idx].index = idx node_list[idx].children = children for child_idx in children: # non-existent node: no parent if child_idx == -1: continue node_list[child_idx].parent = idx # find root node root_idx = [x.index for x in node_list if x.parent == -1][0] root_node = node_list[root_idx] # tree walk in 3 ways print('Preorder') pre_parse(root_node) print('\n' + 'Inorder') in_parse(root_node) print('\n' + 'Postorder') post_parse(root_node) print('') return node_list if __name__ == '__main__': _input = sys.stdin.readlines() array_length = int(_input[0]) array = list(map(lambda x: x.split(), _input[1:])) # assert len(array) == array_length node_list = [Node() for _ in range(array_length)] ans = generate_tree(_array=array)
123
124
2,621
2,628
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 9 0 1 4 1 2 3 2 -1 -1 3 -1 -1 4 5 8 5 6 7 6 -1 -1 7 -1 -1 8 -1 -1 output: Preorder 0 1 2 3 4 5 6 7 8 Inorder 2 1 3 0 6 5 7 4 8 Postorder 2 3 1 6 7 5 8 4 0 """ import sys class Node(object): def __init__(self): # init node as a single leaf node. self.parent = -1 self.children = [] self.index = -1 def pre_parse(v): print(" " + str(v.index), end="") if not v.children: return None left_child_idx = v.children[0] right_child_idx = v.children[1] if left_child_idx != -1: pre_parse(node_list[left_child_idx]) if right_child_idx != -1: pre_parse(node_list[right_child_idx]) return None def in_parse(v): if not v.children: return None left_child_idx = v.children[0] right_child_idx = v.children[1] if left_child_idx != -1: in_parse(node_list[left_child_idx]) print(" " + str(v.index), end="") if right_child_idx != -1: in_parse(node_list[right_child_idx]) return None def post_parse(v): if not v.children: return None left_child_idx = v.children[0] right_child_idx = v.children[1] if left_child_idx != -1: post_parse(node_list[left_child_idx]) if right_child_idx != -1: post_parse(node_list[right_child_idx]) print(" " + str(v.index), end="") return None def generate_tree(_array): # add info of each node of a ordered tree for each in _array: idx, *children = [int(x) for x in each] # assert len(children) == 2 and idx >= 0 node_list[idx].index = idx node_list[idx].children = children for child_idx in children: # non-existent node: no parent if child_idx == -1: continue node_list[child_idx].parent = idx # find root node root_idx = [x.index for x in node_list if x.parent == -1][0] # tree walk in 3 ways print("Preorder") pre_parse(node_list[root_idx]) print("\n" + "Inorder") in_parse(node_list[root_idx]) print("\n" + "Postorder") post_parse(node_list[root_idx]) print("") return node_list if __name__ == "__main__": _input = sys.stdin.readlines() array_length = int(_input[0]) array = list(map(lambda x: x.split(), _input[1:])) # assert len(array) == array_length node_list = [Node() for _ in range(array_length)] ans = generate_tree(_array=array)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 9 0 1 4 1 2 3 2 -1 -1 3 -1 -1 4 5 8 5 6 7 6 -1 -1 7 -1 -1 8 -1 -1 output: Preorder 0 1 2 3 4 5 6 7 8 Inorder 2 1 3 0 6 5 7 4 8 Postorder 2 3 1 6 7 5 8 4 0 """ import sys class Node(object): def __init__(self): # init node as a single leaf node. self.parent = -1 self.children = [] self.index = -1 def pre_parse(v): print(" " + str(v.index), end="") if not v.children: return None left_child_idx = v.children[0] right_child_idx = v.children[1] if left_child_idx != -1: pre_parse(node_list[left_child_idx]) if right_child_idx != -1: pre_parse(node_list[right_child_idx]) return None def in_parse(v): if not v.children: return None left_child_idx = v.children[0] right_child_idx = v.children[1] if left_child_idx != -1: in_parse(node_list[left_child_idx]) print(" " + str(v.index), end="") if right_child_idx != -1: in_parse(node_list[right_child_idx]) return None def post_parse(v): if not v.children: return None left_child_idx = v.children[0] right_child_idx = v.children[1] if left_child_idx != -1: post_parse(node_list[left_child_idx]) if right_child_idx != -1: post_parse(node_list[right_child_idx]) print(" " + str(v.index), end="") return None def generate_tree(_array): # add info of each node of a ordered tree for each in _array: idx, *children = [int(x) for x in each] # assert len(children) == 2 and idx >= 0 node_list[idx].index = idx node_list[idx].children = children for child_idx in children: # non-existent node: no parent if child_idx == -1: continue node_list[child_idx].parent = idx # find root node root_idx = [x.index for x in node_list if x.parent == -1][0] root_node = node_list[root_idx] # tree walk in 3 ways print("Preorder") pre_parse(root_node) print("\n" + "Inorder") in_parse(root_node) print("\n" + "Postorder") post_parse(root_node) print("") return node_list if __name__ == "__main__": _input = sys.stdin.readlines() array_length = int(_input[0]) array = list(map(lambda x: x.split(), _input[1:])) # assert len(array) == array_length node_list = [Node() for _ in range(array_length)] ans = generate_tree(_array=array)
false
0.806452
[ "+ root_node = node_list[root_idx]", "- pre_parse(node_list[root_idx])", "+ pre_parse(root_node)", "- in_parse(node_list[root_idx])", "+ in_parse(root_node)", "- post_parse(node_list[root_idx])", "+ post_parse(root_node)" ]
false
0.032639
0.037594
0.868188
[ "s566306840", "s496793240" ]
u745087332
p03608
python
s948438642
s913628819
347
216
7,104
7,104
Accepted
Accepted
37.75
# coding:utf-8 import sys import heapq import itertools from collections import defaultdict INF = float('inf') MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def dijkstra(start: int, size: int, graph: dict) -> list: costs = [INF] * size costs[start] = 0 hp = [] heapq.heappush(hp, (0, start)) while hp: hc, hv = heapq.heappop(hp) for to, move_cost in graph[hv]: if hc + move_cost >= costs[to]: continue costs[to] = hc + move_cost heapq.heappush(hp, (costs[to], to)) return costs n, m, r = LI() R = LI_() G = defaultdict(list) for i in range(m): a, b, c = LI() a -= 1 b -= 1 G[a].append((b, c)) G[b].append((a, c)) C = {} for ri in R: C[ri] = dijkstra(ri, n, G) ans = INF for root in itertools.permutations(R): tmp = 0 for i in range(r - 1): tmp += C[root[i]][root[i + 1]] ans = min(ans, tmp) print(ans)
# coding:utf-8 import sys import heapq import itertools from collections import defaultdict INF = float('inf') MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def dijkstra(start: int, size: int, graph: dict) -> list: costs = [INF] * size costs[start] = 0 visited = set() hp = [] heapq.heappush(hp, (0, start)) while hp: hc, hv = heapq.heappop(hp) if hv in visited: continue for to, move_cost in graph[hv]: if hc + move_cost >= costs[to]: continue costs[to] = hc + move_cost heapq.heappush(hp, (costs[to], to)) visited.add(hv) return costs n, m, r = LI() R = LI_() G = defaultdict(list) for i in range(m): a, b, c = LI() a -= 1 b -= 1 G[a].append((b, c)) G[b].append((a, c)) C = {} for ri in R: C[ri] = dijkstra(ri, n, G) ans = INF for root in itertools.permutations(R): tmp = 0 for i in range(r - 1): tmp += C[root[i]][root[i + 1]] ans = min(ans, tmp) print(ans)
56
61
1,222
1,319
# coding:utf-8 import sys import heapq import itertools from collections import defaultdict INF = float("inf") MOD = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def dijkstra(start: int, size: int, graph: dict) -> list: costs = [INF] * size costs[start] = 0 hp = [] heapq.heappush(hp, (0, start)) while hp: hc, hv = heapq.heappop(hp) for to, move_cost in graph[hv]: if hc + move_cost >= costs[to]: continue costs[to] = hc + move_cost heapq.heappush(hp, (costs[to], to)) return costs n, m, r = LI() R = LI_() G = defaultdict(list) for i in range(m): a, b, c = LI() a -= 1 b -= 1 G[a].append((b, c)) G[b].append((a, c)) C = {} for ri in R: C[ri] = dijkstra(ri, n, G) ans = INF for root in itertools.permutations(R): tmp = 0 for i in range(r - 1): tmp += C[root[i]][root[i + 1]] ans = min(ans, tmp) print(ans)
# coding:utf-8 import sys import heapq import itertools from collections import defaultdict INF = float("inf") MOD = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def dijkstra(start: int, size: int, graph: dict) -> list: costs = [INF] * size costs[start] = 0 visited = set() hp = [] heapq.heappush(hp, (0, start)) while hp: hc, hv = heapq.heappop(hp) if hv in visited: continue for to, move_cost in graph[hv]: if hc + move_cost >= costs[to]: continue costs[to] = hc + move_cost heapq.heappush(hp, (costs[to], to)) visited.add(hv) return costs n, m, r = LI() R = LI_() G = defaultdict(list) for i in range(m): a, b, c = LI() a -= 1 b -= 1 G[a].append((b, c)) G[b].append((a, c)) C = {} for ri in R: C[ri] = dijkstra(ri, n, G) ans = INF for root in itertools.permutations(R): tmp = 0 for i in range(r - 1): tmp += C[root[i]][root[i + 1]] ans = min(ans, tmp) print(ans)
false
8.196721
[ "+ visited = set()", "+ if hv in visited:", "+ continue", "+ visited.add(hv)" ]
false
0.046706
0.044416
1.051561
[ "s948438642", "s913628819" ]
u141610915
p03096
python
s263266438
s352716912
561
488
74,700
73,896
Accepted
Accepted
13.01
import sys from bisect import bisect_left as bl from bisect import bisect_right as br input = sys.stdin.readline N = int(eval(input())) table = [[] for _ in range(2 * pow(10, 5) + 1)] a = [] t = 0 mod = 10 ** 9 + 7 for i in range(N): x = int(eval(input())) if t != x: table[x].append(i) t = x a.append(x) #print(table[4], table[3]) dp = [0] * N dp[0] = 1 for i in range(N): j = br(table[a[i]], i) k = bl(table[a[i]], i) if j < len(table[a[i]]) and (table[a[i]][k] == i): dp[table[a[i]][j]] += dp[i] dp[table[a[i]][j]] %= mod if i + 1 < N: dp[i + 1] += dp[i] dp[i + 1] %= mod #print(dp) print((dp[-1]))
import sys from bisect import bisect_right as br from bisect import bisect_left as bl input = sys.stdin.readline N = int(eval(input())) mod = 10 ** 9 + 7 a = [] for _ in range(N): a.append(int(eval(input()))) t = 0 table = [[] for _ in range(max(a) + 1)] for i in range(N): if a[i] != t: t = a[i] table[a[i]].append(i) dp = [0] * N dp[0] = 1 #print(table) #print(a) for i in range(N): r = br(table[a[i]], i) l = bl(table[a[i]], i) if r < len(table[a[i]]) and (table[a[i]][l] == i): dp[table[a[i]][r]] += dp[i] dp[table[a[i]][r]] %= mod """ for k in range(j, len(table[a[i]])): print(i, table[a[i]][k]) dp[table[a[i]][k]] += dp[i] dp[table[a[i]][k]] %= mod """ if i + 1 < N: dp[i + 1] += dp[i] dp[i + 1] %= mod print((dp[-1]))
29
34
656
808
import sys from bisect import bisect_left as bl from bisect import bisect_right as br input = sys.stdin.readline N = int(eval(input())) table = [[] for _ in range(2 * pow(10, 5) + 1)] a = [] t = 0 mod = 10**9 + 7 for i in range(N): x = int(eval(input())) if t != x: table[x].append(i) t = x a.append(x) # print(table[4], table[3]) dp = [0] * N dp[0] = 1 for i in range(N): j = br(table[a[i]], i) k = bl(table[a[i]], i) if j < len(table[a[i]]) and (table[a[i]][k] == i): dp[table[a[i]][j]] += dp[i] dp[table[a[i]][j]] %= mod if i + 1 < N: dp[i + 1] += dp[i] dp[i + 1] %= mod # print(dp) print((dp[-1]))
import sys from bisect import bisect_right as br from bisect import bisect_left as bl input = sys.stdin.readline N = int(eval(input())) mod = 10**9 + 7 a = [] for _ in range(N): a.append(int(eval(input()))) t = 0 table = [[] for _ in range(max(a) + 1)] for i in range(N): if a[i] != t: t = a[i] table[a[i]].append(i) dp = [0] * N dp[0] = 1 # print(table) # print(a) for i in range(N): r = br(table[a[i]], i) l = bl(table[a[i]], i) if r < len(table[a[i]]) and (table[a[i]][l] == i): dp[table[a[i]][r]] += dp[i] dp[table[a[i]][r]] %= mod """ for k in range(j, len(table[a[i]])): print(i, table[a[i]][k]) dp[table[a[i]][k]] += dp[i] dp[table[a[i]][k]] %= mod """ if i + 1 < N: dp[i + 1] += dp[i] dp[i + 1] %= mod print((dp[-1]))
false
14.705882
[ "+from bisect import bisect_right as br", "-from bisect import bisect_right as br", "-table = [[] for _ in range(2 * pow(10, 5) + 1)]", "+mod = 10**9 + 7", "+for _ in range(N):", "+ a.append(int(eval(input())))", "-mod = 10**9 + 7", "+table = [[] for _ in range(max(a) + 1)]", "- x = int(eval(input()))", "- if t != x:", "- table[x].append(i)", "- t = x", "- a.append(x)", "-# print(table[4], table[3])", "+ if a[i] != t:", "+ t = a[i]", "+ table[a[i]].append(i)", "+# print(table)", "+# print(a)", "- j = br(table[a[i]], i)", "- k = bl(table[a[i]], i)", "- if j < len(table[a[i]]) and (table[a[i]][k] == i):", "- dp[table[a[i]][j]] += dp[i]", "- dp[table[a[i]][j]] %= mod", "+ r = br(table[a[i]], i)", "+ l = bl(table[a[i]], i)", "+ if r < len(table[a[i]]) and (table[a[i]][l] == i):", "+ dp[table[a[i]][r]] += dp[i]", "+ dp[table[a[i]][r]] %= mod", "+ \"\"\"", "+ for k in range(j, len(table[a[i]])):", "+ print(i, table[a[i]][k])", "+ dp[table[a[i]][k]] += dp[i]", "+ dp[table[a[i]][k]] %= mod", "+ \"\"\"", "- # print(dp)" ]
false
0.114198
0.037824
3.019204
[ "s263266438", "s352716912" ]
u496821919
p02609
python
s681901985
s208957294
657
605
9,800
9,404
Accepted
Accepted
7.91
from copy import copy def popcount(x): return bin(x).count("1") def f(x): if x == 0: return 0 return f(x%popcount(x))+1 n = int(eval(input())) x = eval(input()) xx = int(x,2) p = x.count("1") stand1 = xx%(p+1) if p != 1: stand2 = xx%(p-1) for i in range(n): if x[i] == "1": if p != 1: k = copy(stand2) k -= pow(2,n-i-1,p-1) k %= p-1 else: print((0)) continue else: k = copy(stand1) k += pow(2,n-i-1,p+1) k %= p+1 print((1+f(k)))
def popcount(x): return bin(x).count("1") def f(x): if x == 0: return 0 return f(x%popcount(x))+1 n = int(eval(input())) x = eval(input()) xx = int(x,2) p = x.count("1") stand1 = xx%(p+1) if p != 1: stand2 = xx%(p-1) for i in range(n): if x[i] == "1": if p != 1: k = stand2 k -= pow(2,n-i-1,p-1) k %= p-1 else: print((0)) continue else: k = stand1 k += pow(2,n-i-1,p+1) k %= p+1 print((1+f(k)))
31
29
582
545
from copy import copy def popcount(x): return bin(x).count("1") def f(x): if x == 0: return 0 return f(x % popcount(x)) + 1 n = int(eval(input())) x = eval(input()) xx = int(x, 2) p = x.count("1") stand1 = xx % (p + 1) if p != 1: stand2 = xx % (p - 1) for i in range(n): if x[i] == "1": if p != 1: k = copy(stand2) k -= pow(2, n - i - 1, p - 1) k %= p - 1 else: print((0)) continue else: k = copy(stand1) k += pow(2, n - i - 1, p + 1) k %= p + 1 print((1 + f(k)))
def popcount(x): return bin(x).count("1") def f(x): if x == 0: return 0 return f(x % popcount(x)) + 1 n = int(eval(input())) x = eval(input()) xx = int(x, 2) p = x.count("1") stand1 = xx % (p + 1) if p != 1: stand2 = xx % (p - 1) for i in range(n): if x[i] == "1": if p != 1: k = stand2 k -= pow(2, n - i - 1, p - 1) k %= p - 1 else: print((0)) continue else: k = stand1 k += pow(2, n - i - 1, p + 1) k %= p + 1 print((1 + f(k)))
false
6.451613
[ "-from copy import copy", "-", "-", "- k = copy(stand2)", "+ k = stand2", "- k = copy(stand1)", "+ k = stand1" ]
false
0.046742
0.044321
1.054622
[ "s681901985", "s208957294" ]
u624475441
p03681
python
s267120237
s626387242
400
28
4,736
3,064
Accepted
Accepted
93
from math import factorial MOD = 10**9 + 7 n, m = list(map(int, input().split())) if n == m: print((2 * factorial(n)**2 % MOD)) elif n - 1 == m: print((n * factorial(m)**2 % MOD)) elif n == m - 1: print((m * factorial(n)**2 % MOD)) else: print((0))
def factorial(n): ans = 1 for i in range(2, n + 1): ans = ans * i % 1000000007 return ans n, m = list(map(int, input().split())) MOD = 10**9 + 7 if n == m: print((2 * factorial(n) ** 2 % MOD)) elif abs(n - m) == 1: print((factorial(min(m, n)) ** 2 * max(m, n) % MOD)) else: print((0))
11
13
260
316
from math import factorial MOD = 10**9 + 7 n, m = list(map(int, input().split())) if n == m: print((2 * factorial(n) ** 2 % MOD)) elif n - 1 == m: print((n * factorial(m) ** 2 % MOD)) elif n == m - 1: print((m * factorial(n) ** 2 % MOD)) else: print((0))
def factorial(n): ans = 1 for i in range(2, n + 1): ans = ans * i % 1000000007 return ans n, m = list(map(int, input().split())) MOD = 10**9 + 7 if n == m: print((2 * factorial(n) ** 2 % MOD)) elif abs(n - m) == 1: print((factorial(min(m, n)) ** 2 * max(m, n) % MOD)) else: print((0))
false
15.384615
[ "-from math import factorial", "+def factorial(n):", "+ ans = 1", "+ for i in range(2, n + 1):", "+ ans = ans * i % 1000000007", "+ return ans", "+", "+n, m = list(map(int, input().split()))", "-n, m = list(map(int, input().split()))", "-elif n - 1 == m:", "- print((n * factorial(m) ** 2 % MOD))", "-elif n == m - 1:", "- print((m * factorial(n) ** 2 % MOD))", "+elif abs(n - m) == 1:", "+ print((factorial(min(m, n)) ** 2 * max(m, n) % MOD))" ]
false
0.154995
0.038611
4.014335
[ "s267120237", "s626387242" ]