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
u150984829
p02240
python
s892632596
s271736211
630
520
23,904
23,896
Accepted
Accepted
17.46
n,m=list(map(int,input().split())) P=[[]for _ in[0]*n] C=[0]*n k=0 for _ in[0]*m: s,t=list(map(int,input().split()));P[s]+=[t];P[t]+=[s] for i in range(n): k+=1 if C[i]<1: s=[i];C[i]=k while s: u=s.pop() for v in P[u]: if C[v]<1:C[v]=k;s+=[v] for _ in[0]*int(eval(input())): a,b=list(map(int,input().split())) print((['no','yes'][C[a]==C[b]]))
def s(): n,m=list(map(int,input().split())) P=[[]for _ in[0]*n] C=[0]*n k=0 for _ in[0]*m: s,t=list(map(int,input().split()));P[s]+=[t];P[t]+=[s] for i in range(n): k+=1 if C[i]<1: s=[i];C[i]=k while s: u=s.pop() for v in P[u]: if C[v]<1:C[v]=k;s+=[v] for _ in[0]*int(eval(input())): a,b=list(map(int,input().split())) print((['no','yes'][C[a]==C[b]])) if'__main__'==__name__:s()
17
19
353
408
n, m = list(map(int, input().split())) P = [[] for _ in [0] * n] C = [0] * n k = 0 for _ in [0] * m: s, t = list(map(int, input().split())) P[s] += [t] P[t] += [s] for i in range(n): k += 1 if C[i] < 1: s = [i] C[i] = k while s: u = s.pop() for v in P[u]: if C[v] < 1: C[v] = k s += [v] for _ in [0] * int(eval(input())): a, b = list(map(int, input().split())) print((["no", "yes"][C[a] == C[b]]))
def s(): n, m = list(map(int, input().split())) P = [[] for _ in [0] * n] C = [0] * n k = 0 for _ in [0] * m: s, t = list(map(int, input().split())) P[s] += [t] P[t] += [s] for i in range(n): k += 1 if C[i] < 1: s = [i] C[i] = k while s: u = s.pop() for v in P[u]: if C[v] < 1: C[v] = k s += [v] for _ in [0] * int(eval(input())): a, b = list(map(int, input().split())) print((["no", "yes"][C[a] == C[b]])) if "__main__" == __name__: s()
false
10.526316
[ "-n, m = list(map(int, input().split()))", "-P = [[] for _ in [0] * n]", "-C = [0] * n", "-k = 0", "-for _ in [0] * m:", "- s, t = list(map(int, input().split()))", "- P[s] += [t]", "- P[t] += [s]", "-for i in range(n):", "- k += 1", "- if C[i] < 1:", "- s = [i]", "- C[i] = k", "- while s:", "- u = s.pop()", "- for v in P[u]:", "- if C[v] < 1:", "- C[v] = k", "- s += [v]", "-for _ in [0] * int(eval(input())):", "- a, b = list(map(int, input().split()))", "- print(([\"no\", \"yes\"][C[a] == C[b]]))", "+def s():", "+ n, m = list(map(int, input().split()))", "+ P = [[] for _ in [0] * n]", "+ C = [0] * n", "+ k = 0", "+ for _ in [0] * m:", "+ s, t = list(map(int, input().split()))", "+ P[s] += [t]", "+ P[t] += [s]", "+ for i in range(n):", "+ k += 1", "+ if C[i] < 1:", "+ s = [i]", "+ C[i] = k", "+ while s:", "+ u = s.pop()", "+ for v in P[u]:", "+ if C[v] < 1:", "+ C[v] = k", "+ s += [v]", "+ for _ in [0] * int(eval(input())):", "+ a, b = list(map(int, input().split()))", "+ print(([\"no\", \"yes\"][C[a] == C[b]]))", "+", "+", "+if \"__main__\" == __name__:", "+ s()" ]
false
0.058041
0.038492
1.507871
[ "s892632596", "s271736211" ]
u077291787
p03647
python
s757491257
s726342129
249
143
18,884
46,660
Accepted
Accepted
42.57
# ABC068C - Cat Snuke and a Voyage (ARC079C) import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().split())) s, d = set(), set() # start, destination for _ in range(m): a, b = list(map(int, input().split())) if a == 1: s.add(b) # 1 to X elif b == n: d.add(a) # X to n # if the same X in both s & d -> possible print(("POSSIBLE" if s & d else "IMPOSSIBLE")) if __name__ == "__main__": main()
# ABC068C - Cat Snuke and a Voyage (ARC079C) def main(): N, M, *AB = list(map(int, open(0).read().split())) from_1, to_N = set(), set() for a, b in zip(*[iter(AB)] * 2): if a == 1: from_1.add(b) if b == N: to_N.add(a) flg = from_1 & to_N # intermediate point of both 1, N exists? print(("POSSIBLE" if flg else "IMPOSSIBLE")) if __name__ == "__main__": main()
19
15
497
431
# ABC068C - Cat Snuke and a Voyage (ARC079C) import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().split())) s, d = set(), set() # start, destination for _ in range(m): a, b = list(map(int, input().split())) if a == 1: s.add(b) # 1 to X elif b == n: d.add(a) # X to n # if the same X in both s & d -> possible print(("POSSIBLE" if s & d else "IMPOSSIBLE")) if __name__ == "__main__": main()
# ABC068C - Cat Snuke and a Voyage (ARC079C) def main(): N, M, *AB = list(map(int, open(0).read().split())) from_1, to_N = set(), set() for a, b in zip(*[iter(AB)] * 2): if a == 1: from_1.add(b) if b == N: to_N.add(a) flg = from_1 & to_N # intermediate point of both 1, N exists? print(("POSSIBLE" if flg else "IMPOSSIBLE")) if __name__ == "__main__": main()
false
21.052632
[ "-import sys", "-", "-input = sys.stdin.readline", "-", "-", "- n, m = list(map(int, input().split()))", "- s, d = set(), set() # start, destination", "- for _ in range(m):", "- a, b = list(map(int, input().split()))", "+ N, M, *AB = list(map(int, open(0).read().split()))", "+ from_1, to_N = set(), set()", "+ for a, b in zip(*[iter(AB)] * 2):", "- s.add(b) # 1 to X", "- elif b == n:", "- d.add(a) # X to n", "- # if the same X in both s & d -> possible", "- print((\"POSSIBLE\" if s & d else \"IMPOSSIBLE\"))", "+ from_1.add(b)", "+ if b == N:", "+ to_N.add(a)", "+ flg = from_1 & to_N # intermediate point of both 1, N exists?", "+ print((\"POSSIBLE\" if flg else \"IMPOSSIBLE\"))" ]
false
0.045857
0.044987
1.019342
[ "s757491257", "s726342129" ]
u145231176
p03329
python
s505878202
s306982031
316
276
70,088
88,928
Accepted
Accepted
12.66
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() from collections import defaultdict, deque, Counter from sys import exit import heapq import math import fractions import copy from itertools import permutations from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 N = getN() num = [1] sixsta = 6 while sixsta < 100000: num.append(sixsta) sixsta *= 6 ninesta = 9 while ninesta < 100000: num.append(ninesta) ninesta *= 9 num.sort() dp = [float('inf')] * 100001 dp[0] = 0 for i in range(N + 1): for k in range(len(num)): if i >= num[k]: dp[i] = min(dp[i], dp[i - num[k]] + 1) print((dp[N]))
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * from heapq import heapify, heappop, heappush import math import random import string from copy import deepcopy from itertools import combinations, permutations, product from operator import mul, itemgetter from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# N = getN() coin = [1] sixsta = 6 while sixsta < 100000: coin.append(sixsta) sixsta *= 6 ninesta = 9 while ninesta < 100000: coin.append(ninesta) ninesta *= 9 coin.sort() # NlogNダイクストラ # これも最短経路を求める問題 def dijkstra(n, start): dist = [float('inf')] * n pos = [(0, start)] heapify(pos) dist[start] = 0 while len(pos): cost, u = heappop(pos) if dist[u] < cost: continue # エッジは探索のたびに生成していく for i in range(len(coin)): if u + coin[i] >= n: continue if dist[u] + 1 < dist[u + coin[i]]: dist[u + coin[i]] = dist[u] + 1 heappush(pos, (dist[u] + 1, u + coin[i])) return dist print((dijkstra(N + 1, 0)[N]))
47
89
1,003
2,130
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() from collections import defaultdict, deque, Counter from sys import exit import heapq import math import fractions import copy from itertools import permutations from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10**9 + 7 N = getN() num = [1] sixsta = 6 while sixsta < 100000: num.append(sixsta) sixsta *= 6 ninesta = 9 while ninesta < 100000: num.append(ninesta) ninesta *= 9 num.sort() dp = [float("inf")] * 100001 dp[0] = 0 for i in range(N + 1): for k in range(len(num)): if i >= num[k]: dp[i] = min(dp[i], dp[i - num[k]] + 1) print((dp[N]))
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * from heapq import heapify, heappop, heappush import math import random import string from copy import deepcopy from itertools import combinations, permutations, product from operator import mul, itemgetter from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10**9 + 7 ############# # Main Code # ############# N = getN() coin = [1] sixsta = 6 while sixsta < 100000: coin.append(sixsta) sixsta *= 6 ninesta = 9 while ninesta < 100000: coin.append(ninesta) ninesta *= 9 coin.sort() # NlogNダイクストラ # これも最短経路を求める問題 def dijkstra(n, start): dist = [float("inf")] * n pos = [(0, start)] heapify(pos) dist[start] = 0 while len(pos): cost, u = heappop(pos) if dist[u] < cost: continue # エッジは探索のたびに生成していく for i in range(len(coin)): if u + coin[i] >= n: continue if dist[u] + 1 < dist[u + coin[i]]: dist[u + coin[i]] = dist[u] + 1 heappush(pos, (dist[u] + 1, u + coin[i])) return dist print((dijkstra(N + 1, 0)[N]))
false
47.191011
[ "+def rand_N(ran1, ran2):", "+ return random.randint(ran1, ran2)", "+", "+", "+def rand_List(ran1, ran2, rantime):", "+ return [random.randint(ran1, ran2) for i in range(rantime)]", "+", "+", "+def rand_ints_nodup(ran1, ran2, rantime):", "+ ns = []", "+ while len(ns) < rantime:", "+ n = random.randint(ran1, ran2)", "+ if not n in ns:", "+ ns.append(n)", "+ return sorted(ns)", "+", "+", "+def rand_query(ran1, ran2, rantime):", "+ r_query = []", "+ while len(r_query) < rantime:", "+ n_q = rand_ints_nodup(ran1, ran2, 2)", "+ if not n_q in r_query:", "+ r_query.append(n_q)", "+ return sorted(r_query)", "+", "+", "-import heapq", "+from decimal import *", "+from heapq import heapify, heappop, heappush", "-import fractions", "-import copy", "-from itertools import permutations", "-from operator import mul", "+import random", "+import string", "+from copy import deepcopy", "+from itertools import combinations, permutations, product", "+from operator import mul, itemgetter", "+#############", "+# Main Code #", "+#############", "-num = [1]", "+coin = [1]", "- num.append(sixsta)", "+ coin.append(sixsta)", "- num.append(ninesta)", "+ coin.append(ninesta)", "-num.sort()", "-dp = [float(\"inf\")] * 100001", "-dp[0] = 0", "-for i in range(N + 1):", "- for k in range(len(num)):", "- if i >= num[k]:", "- dp[i] = min(dp[i], dp[i - num[k]] + 1)", "-print((dp[N]))", "+coin.sort()", "+# NlogNダイクストラ", "+# これも最短経路を求める問題", "+def dijkstra(n, start):", "+ dist = [float(\"inf\")] * n", "+ pos = [(0, start)]", "+ heapify(pos)", "+ dist[start] = 0", "+ while len(pos):", "+ cost, u = heappop(pos)", "+ if dist[u] < cost:", "+ continue", "+ # エッジは探索のたびに生成していく", "+ for i in range(len(coin)):", "+ if u + coin[i] >= n:", "+ continue", "+ if dist[u] + 1 < dist[u + coin[i]]:", "+ dist[u + coin[i]] = dist[u] + 1", "+ heappush(pos, (dist[u] + 1, u + coin[i]))", "+ return dist", "+", "+", "+print((dijkstra(N + 1, 0)[N]))" ]
false
0.16692
0.15223
1.096498
[ "s505878202", "s306982031" ]
u934442292
p03037
python
s219433983
s822638220
366
117
10,868
10,868
Accepted
Accepted
68.03
N, M = [int(i) for i in input().strip().split()] L = [0] * M R = [0] * M for i in range(M): L[i], R[i] = [int(i) for i in input().strip().split()] LL, RR = L[0], R[0] is_zero = False for i in range(1, M): if RR < L[i]: is_zero = True break elif LL <= L[i] <= RR: LL = max(LL, L[i]) RR = min(RR, R[i]) elif L[i] < LL <= R[i]: RR = min(RR, R[i]) else: is_zero = True break if is_zero: print((0)) else: print((RR - LL + 1))
import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) L = [None] * M R = [None] * M for i in range(M): L[i], R[i] = list(map(int, input().split())) L_max = max(L) R_min = min(R) if L_max > R_min: print((0)) else: print((R_min - L_max + 1)) if __name__ == "__main__": main()
25
22
527
380
N, M = [int(i) for i in input().strip().split()] L = [0] * M R = [0] * M for i in range(M): L[i], R[i] = [int(i) for i in input().strip().split()] LL, RR = L[0], R[0] is_zero = False for i in range(1, M): if RR < L[i]: is_zero = True break elif LL <= L[i] <= RR: LL = max(LL, L[i]) RR = min(RR, R[i]) elif L[i] < LL <= R[i]: RR = min(RR, R[i]) else: is_zero = True break if is_zero: print((0)) else: print((RR - LL + 1))
import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) L = [None] * M R = [None] * M for i in range(M): L[i], R[i] = list(map(int, input().split())) L_max = max(L) R_min = min(R) if L_max > R_min: print((0)) else: print((R_min - L_max + 1)) if __name__ == "__main__": main()
false
12
[ "-N, M = [int(i) for i in input().strip().split()]", "-L = [0] * M", "-R = [0] * M", "-for i in range(M):", "- L[i], R[i] = [int(i) for i in input().strip().split()]", "-LL, RR = L[0], R[0]", "-is_zero = False", "-for i in range(1, M):", "- if RR < L[i]:", "- is_zero = True", "- break", "- elif LL <= L[i] <= RR:", "- LL = max(LL, L[i])", "- RR = min(RR, R[i])", "- elif L[i] < LL <= R[i]:", "- RR = min(RR, R[i])", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def main():", "+ N, M = list(map(int, input().split()))", "+ L = [None] * M", "+ R = [None] * M", "+ for i in range(M):", "+ L[i], R[i] = list(map(int, input().split()))", "+ L_max = max(L)", "+ R_min = min(R)", "+ if L_max > R_min:", "+ print((0))", "- is_zero = True", "- break", "-if is_zero:", "- print((0))", "-else:", "- print((RR - LL + 1))", "+ print((R_min - L_max + 1))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.038294
0.035098
1.09106
[ "s219433983", "s822638220" ]
u261103969
p02675
python
s306412570
s527381656
64
23
61,640
9,104
Accepted
Accepted
64.06
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n = eval(input()) c = n[-1] if c in ["2", "4", "5", "7", "9"]: print("hon") elif c in ["0", "1", "6", "8"]: print("pon") else: print("bon") if __name__ == '__main__': main()
n = eval(input()) c = n[-1] if c in ["3"]: print("bon") elif c in ["0", "1", "6", "8"]: print("pon") else: print("hon")
22
9
364
128
import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): n = eval(input()) c = n[-1] if c in ["2", "4", "5", "7", "9"]: print("hon") elif c in ["0", "1", "6", "8"]: print("pon") else: print("bon") if __name__ == "__main__": main()
n = eval(input()) c = n[-1] if c in ["3"]: print("bon") elif c in ["0", "1", "6", "8"]: print("pon") else: print("hon")
false
59.090909
[ "-import sys", "-", "-readline = sys.stdin.readline", "-MOD = 10**9 + 7", "-INF = float(\"INF\")", "-sys.setrecursionlimit(10**5)", "-", "-", "-def main():", "- n = eval(input())", "- c = n[-1]", "- if c in [\"2\", \"4\", \"5\", \"7\", \"9\"]:", "- print(\"hon\")", "- elif c in [\"0\", \"1\", \"6\", \"8\"]:", "- print(\"pon\")", "- else:", "- print(\"bon\")", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+n = eval(input())", "+c = n[-1]", "+if c in [\"3\"]:", "+ print(\"bon\")", "+elif c in [\"0\", \"1\", \"6\", \"8\"]:", "+ print(\"pon\")", "+else:", "+ print(\"hon\")" ]
false
0.053488
0.036003
1.485673
[ "s306412570", "s527381656" ]
u572142121
p02597
python
s954481696
s684193403
124
43
9,488
9,496
Accepted
Accepted
65.32
N=int(eval(input())) d=eval(input()) r=d.count('R') w=N-r ans=r leftr,leftw,rightr,rightw=0,0,r,N-r for i in range(N): if d[i]=='R': leftr+=1 rightr-=1 else: leftw+=1 rightw-=1 if leftw==rightr: f=rightr elif leftw<rightr: f=rightr else: f=leftw ans=min(ans,f) print(ans)
N=int(eval(input())) s=eval(input()) r=s.count('R') cnt=0 for i in range(r): if s[i]=='W': cnt+=1 print(cnt)
21
8
319
109
N = int(eval(input())) d = eval(input()) r = d.count("R") w = N - r ans = r leftr, leftw, rightr, rightw = 0, 0, r, N - r for i in range(N): if d[i] == "R": leftr += 1 rightr -= 1 else: leftw += 1 rightw -= 1 if leftw == rightr: f = rightr elif leftw < rightr: f = rightr else: f = leftw ans = min(ans, f) print(ans)
N = int(eval(input())) s = eval(input()) r = s.count("R") cnt = 0 for i in range(r): if s[i] == "W": cnt += 1 print(cnt)
false
61.904762
[ "-d = eval(input())", "-r = d.count(\"R\")", "-w = N - r", "-ans = r", "-leftr, leftw, rightr, rightw = 0, 0, r, N - r", "-for i in range(N):", "- if d[i] == \"R\":", "- leftr += 1", "- rightr -= 1", "- else:", "- leftw += 1", "- rightw -= 1", "- if leftw == rightr:", "- f = rightr", "- elif leftw < rightr:", "- f = rightr", "- else:", "- f = leftw", "- ans = min(ans, f)", "-print(ans)", "+s = eval(input())", "+r = s.count(\"R\")", "+cnt = 0", "+for i in range(r):", "+ if s[i] == \"W\":", "+ cnt += 1", "+print(cnt)" ]
false
0.041808
0.03665
1.140746
[ "s954481696", "s684193403" ]
u729133443
p02771
python
s094067464
s370234639
64
26
61,656
8,896
Accepted
Accepted
59.38
print((len(set(eval(input())))%2*'Yes'or'No'))
print((len({*eval(input())})%2*'Yes'or'No'))
1
1
38
36
print((len(set(eval(input()))) % 2 * "Yes" or "No"))
print((len({*eval(input())}) % 2 * "Yes" or "No"))
false
0
[ "-print((len(set(eval(input()))) % 2 * \"Yes\" or \"No\"))", "+print((len({*eval(input())}) % 2 * \"Yes\" or \"No\"))" ]
false
0.039197
0.048179
0.81356
[ "s094067464", "s370234639" ]
u334712262
p02669
python
s029316394
s426408549
1,962
941
171,976
116,556
Accepted
Accepted
52.04
# -*- coding: utf-8 -*- # import bisect # import heapq # import math # import random # from collections import Counter, defaultdict, deque # from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache # from itertools import combinations, combinations_with_replacement, product, permutations # from operator import add, mul, sub import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap # @mt def slv(N, A, B, C, D): if N == 1: return D @lru_cache(maxsize=None) def f(n): ans = n*D for i in range(-5, 6 if n > 10 else 1): m = n + i i = abs(i) if m < 0: continue if m == 0: ans = min(ans, D*i) continue if m % 5 == 0: ans = min(ans, f(m//5) + C + D*i) # ans = min(ans, f(m//5) + 4*(m//5)*D + D*i) if m % 3 == 0: ans = min(ans, f(m//3) + B + D*i) # ans = min(ans, f(m//3) + 2*(m//3)*D + D*i) if m % 2 == 0: ans = min(ans, f(m//2) + A + D*i) # ans = min(ans, f(m//2) + (m//2)*D + D*i) return ans return f(N) def main(): T = read_int() for _ in range(T): N, A, B, C ,D = read_int_n() print(slv(N, A, B, C, D)) # N, A, B, C, D = 29384293847243, 454353412, 332423423, 934923490, 1 # print(slv(N, A, B, C, D)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- from functools import lru_cache import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap # @mt def slv(N, A, B, C, D): @lru_cache(maxsize=None) def f(n): ans = n*D for i in range(-min(2, n), min(3, n)): m = n + i i = abs(i) if m == 0: continue if m % 5 == 0: ans = min(ans, f(m//5) + C + D*i) if m % 3 == 0: ans = min(ans, f(m//3) + B + D*i) if m % 2 == 0: ans = min(ans, f(m//2) + A + D*i) return ans return f(N) def main(): T = read_int() for _ in range(T): N, A, B, C ,D = read_int_n() print(slv(N, A, B, C, D)) if __name__ == '__main__': main()
105
84
2,331
1,602
# -*- coding: utf-8 -*- # import bisect # import heapq # import math # import random # from collections import Counter, defaultdict, deque # from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache # from itertools import combinations, combinations_with_replacement, product, permutations # from operator import add, mul, sub import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap # @mt def slv(N, A, B, C, D): if N == 1: return D @lru_cache(maxsize=None) def f(n): ans = n * D for i in range(-5, 6 if n > 10 else 1): m = n + i i = abs(i) if m < 0: continue if m == 0: ans = min(ans, D * i) continue if m % 5 == 0: ans = min(ans, f(m // 5) + C + D * i) # ans = min(ans, f(m//5) + 4*(m//5)*D + D*i) if m % 3 == 0: ans = min(ans, f(m // 3) + B + D * i) # ans = min(ans, f(m//3) + 2*(m//3)*D + D*i) if m % 2 == 0: ans = min(ans, f(m // 2) + A + D * i) # ans = min(ans, f(m//2) + (m//2)*D + D*i) return ans return f(N) def main(): T = read_int() for _ in range(T): N, A, B, C, D = read_int_n() print(slv(N, A, B, C, D)) # N, A, B, C, D = 29384293847243, 454353412, 332423423, 934923490, 1 # print(slv(N, A, B, C, D)) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- from functools import lru_cache import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap # @mt def slv(N, A, B, C, D): @lru_cache(maxsize=None) def f(n): ans = n * D for i in range(-min(2, n), min(3, n)): m = n + i i = abs(i) if m == 0: continue if m % 5 == 0: ans = min(ans, f(m // 5) + C + D * i) if m % 3 == 0: ans = min(ans, f(m // 3) + B + D * i) if m % 2 == 0: ans = min(ans, f(m // 2) + A + D * i) return ans return f(N) def main(): T = read_int() for _ in range(T): N, A, B, C, D = read_int_n() print(slv(N, A, B, C, D)) if __name__ == "__main__": main()
false
20
[ "-# import bisect", "-# import heapq", "-# import math", "-# import random", "-# from collections import Counter, defaultdict, deque", "-# from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal", "-", "-# from itertools import combinations, combinations_with_replacement, product, permutations", "-# from operator import add, mul, sub", "- if N == 1:", "- return D", "-", "- for i in range(-5, 6 if n > 10 else 1):", "+ for i in range(-min(2, n), min(3, n)):", "- if m < 0:", "- continue", "- ans = min(ans, D * i)", "- # ans = min(ans, f(m//5) + 4*(m//5)*D + D*i)", "- # ans = min(ans, f(m//3) + 2*(m//3)*D + D*i)", "- # ans = min(ans, f(m//2) + (m//2)*D + D*i)", "- # N, A, B, C, D = 29384293847243, 454353412, 332423423, 934923490, 1", "- # print(slv(N, A, B, C, D))" ]
false
2.737567
0.600875
4.555966
[ "s029316394", "s426408549" ]
u729133443
p03795
python
s098498199
s873590942
163
17
38,256
2,940
Accepted
Accepted
89.57
n=int(eval(input()));print((n*800-n//15*200))
n=int(eval(input()));print((int(40/3*(n*59+n%15))))
1
1
37
43
n = int(eval(input())) print((n * 800 - n // 15 * 200))
n = int(eval(input())) print((int(40 / 3 * (n * 59 + n % 15))))
false
0
[ "-print((n * 800 - n // 15 * 200))", "+print((int(40 / 3 * (n * 59 + n % 15))))" ]
false
0.040361
0.04077
0.989966
[ "s098498199", "s873590942" ]
u699089116
p03831
python
s661403326
s099224354
241
93
63,000
85,292
Accepted
Accepted
61.41
n, a, b = list(map(int, input().split())) x = list(map(int, input().split())) dp = [float("INF") for _ in range(n)] dp[0] = 0 for i in range(n-1): dp[i+1] = min(dp[i] + (x[i+1] - x[i]) * a, dp[i] + b) print((dp[-1]))
n, a, b = list(map(int, input().split())) x = list(map(int, input().split())) fatigue = 0 for i in range(n-1): fatigue += min((x[i+1] - x[i]) * a, b) print(fatigue)
10
8
224
171
n, a, b = list(map(int, input().split())) x = list(map(int, input().split())) dp = [float("INF") for _ in range(n)] dp[0] = 0 for i in range(n - 1): dp[i + 1] = min(dp[i] + (x[i + 1] - x[i]) * a, dp[i] + b) print((dp[-1]))
n, a, b = list(map(int, input().split())) x = list(map(int, input().split())) fatigue = 0 for i in range(n - 1): fatigue += min((x[i + 1] - x[i]) * a, b) print(fatigue)
false
20
[ "-dp = [float(\"INF\") for _ in range(n)]", "-dp[0] = 0", "+fatigue = 0", "- dp[i + 1] = min(dp[i] + (x[i + 1] - x[i]) * a, dp[i] + b)", "-print((dp[-1]))", "+ fatigue += min((x[i + 1] - x[i]) * a, b)", "+print(fatigue)" ]
false
0.043185
0.035477
1.217283
[ "s661403326", "s099224354" ]
u852690916
p03387
python
s921165869
s540234388
176
17
38,384
3,060
Accepted
Accepted
90.34
a,b,c=list(map(int, input().split())) mx=max((a,b,c)) sm=sum((a,b,c)) d=mx*3-sm print(((d+3)//2 if d&1 else d//2))
A,B,C=list(map(int, input().split())) S=max(A,B,C)*3 S+=3 if S&1!=(A+B+C)&1 else 0 print(((S-(A+B+C))//2))
5
4
110
101
a, b, c = list(map(int, input().split())) mx = max((a, b, c)) sm = sum((a, b, c)) d = mx * 3 - sm print(((d + 3) // 2 if d & 1 else d // 2))
A, B, C = list(map(int, input().split())) S = max(A, B, C) * 3 S += 3 if S & 1 != (A + B + C) & 1 else 0 print(((S - (A + B + C)) // 2))
false
20
[ "-a, b, c = list(map(int, input().split()))", "-mx = max((a, b, c))", "-sm = sum((a, b, c))", "-d = mx * 3 - sm", "-print(((d + 3) // 2 if d & 1 else d // 2))", "+A, B, C = list(map(int, input().split()))", "+S = max(A, B, C) * 3", "+S += 3 if S & 1 != (A + B + C) & 1 else 0", "+print(((S - (A + B + C)) // 2))" ]
false
0.043076
0.0383
1.124691
[ "s921165869", "s540234388" ]
u096359533
p03211
python
s945906199
s581995765
19
17
2,940
2,940
Accepted
Accepted
10.53
import math S = eval(input()) thlist = [(753 - int(S[i:i+3]))**2 for i in range(len(S)-2)] print((int(math.sqrt(min(thlist)))))
S = eval(input()) thlist = [abs(753 - int(S[i:i+3])) for i in range(len(S)-2)] print((min(thlist)))
4
3
122
93
import math S = eval(input()) thlist = [(753 - int(S[i : i + 3])) ** 2 for i in range(len(S) - 2)] print((int(math.sqrt(min(thlist)))))
S = eval(input()) thlist = [abs(753 - int(S[i : i + 3])) for i in range(len(S) - 2)] print((min(thlist)))
false
25
[ "-import math", "-", "-thlist = [(753 - int(S[i : i + 3])) ** 2 for i in range(len(S) - 2)]", "-print((int(math.sqrt(min(thlist)))))", "+thlist = [abs(753 - int(S[i : i + 3])) for i in range(len(S) - 2)]", "+print((min(thlist)))" ]
false
0.045257
0.044282
1.022026
[ "s945906199", "s581995765" ]
u785578220
p03163
python
s144305477
s682486749
704
359
171,268
61,040
Accepted
Accepted
49.01
n,k = list(map(int,input().split())) w=[] v=[] dp =[[0 for i in range(k+1)] for j in range(n+1)] for i in range(n): a,b = list(map(int,input().split())) w.append(a) v.append(b) for i in range(n): for sum_w in range(k+1): if sum_w - w[i] >=0: dp[i+1][sum_w]=max(dp[i][sum_w],dp[i][sum_w - w[i]] + v[i]) else: dp[i+1][sum_w]=dp[i][sum_w] print((dp[-1][-1]))
N, W = list(map(int, input().split())) a = [] for i in range(N): x,y = list(map(int,input().split())) a.append([x,y]) dp = [0]*(W+1) max_weight = 0 for w, v in a: max_w = min(max_weight, W-w) for old_v, from_i in zip(dp[max_w::-1], list(range(max_w, -1, -1))): if dp[from_i+w] < old_v + v: dp[from_i+w] = old_v + v max_weight = min(max_weight+w, W) print((max(dp)))
17
16
415
403
n, k = list(map(int, input().split())) w = [] v = [] dp = [[0 for i in range(k + 1)] for j in range(n + 1)] for i in range(n): a, b = list(map(int, input().split())) w.append(a) v.append(b) for i in range(n): for sum_w in range(k + 1): if sum_w - w[i] >= 0: dp[i + 1][sum_w] = max(dp[i][sum_w], dp[i][sum_w - w[i]] + v[i]) else: dp[i + 1][sum_w] = dp[i][sum_w] print((dp[-1][-1]))
N, W = list(map(int, input().split())) a = [] for i in range(N): x, y = list(map(int, input().split())) a.append([x, y]) dp = [0] * (W + 1) max_weight = 0 for w, v in a: max_w = min(max_weight, W - w) for old_v, from_i in zip(dp[max_w::-1], list(range(max_w, -1, -1))): if dp[from_i + w] < old_v + v: dp[from_i + w] = old_v + v max_weight = min(max_weight + w, W) print((max(dp)))
false
5.882353
[ "-n, k = list(map(int, input().split()))", "-w = []", "-v = []", "-dp = [[0 for i in range(k + 1)] for j in range(n + 1)]", "-for i in range(n):", "- a, b = list(map(int, input().split()))", "- w.append(a)", "- v.append(b)", "-for i in range(n):", "- for sum_w in range(k + 1):", "- if sum_w - w[i] >= 0:", "- dp[i + 1][sum_w] = max(dp[i][sum_w], dp[i][sum_w - w[i]] + v[i])", "- else:", "- dp[i + 1][sum_w] = dp[i][sum_w]", "-print((dp[-1][-1]))", "+N, W = list(map(int, input().split()))", "+a = []", "+for i in range(N):", "+ x, y = list(map(int, input().split()))", "+ a.append([x, y])", "+dp = [0] * (W + 1)", "+max_weight = 0", "+for w, v in a:", "+ max_w = min(max_weight, W - w)", "+ for old_v, from_i in zip(dp[max_w::-1], list(range(max_w, -1, -1))):", "+ if dp[from_i + w] < old_v + v:", "+ dp[from_i + w] = old_v + v", "+ max_weight = min(max_weight + w, W)", "+print((max(dp)))" ]
false
0.087753
0.040902
2.145425
[ "s144305477", "s682486749" ]
u747602774
p03806
python
s836525105
s353190801
495
306
98,780
44,908
Accepted
Accepted
38.18
N,Ma,Mb = list(map(int,input().split())) INF = 10000 dp = [[[INF for b in range(401)] for a in range(401)] for i in range(N+1)] dp[0][0][0] = 0 for i in range(1,N+1): ai,bi,ci = list(map(int,input().split())) for a in range(401): for b in range(401): if a-ai >= 0 and b-bi >= 0: dp[i][a][b] = min(dp[i-1][a][b],dp[i-1][a-ai][b-bi]+ci) else: dp[i][a][b] = dp[i-1][a][b] ans = INF for j in range(1,401): if Ma*j >= 400 or Mb*j >= 400: break ans = min(ans,dp[N][Ma*j][Mb*j]) print((ans if ans != INF else -1))
N,Ma,Mb = list(map(int,input().split())) INF = 10000 dp = [[INF for b in range(401)] for a in range(401)] dp[0][0] = 0 for i in range(1,N+1): ai,bi,ci = list(map(int,input().split())) for a in range(400,-1,-1): for b in range(400,-1,-1): if a-ai >= 0 and b-bi >= 0: dp[a][b] = min(dp[a][b],dp[a-ai][b-bi]+ci) ans = INF for j in range(1,401): if Ma*j > 400 or Mb*j > 400: break ans = min(ans,dp[Ma*j][Mb*j]) print((ans if ans != INF else -1))
24
22
610
515
N, Ma, Mb = list(map(int, input().split())) INF = 10000 dp = [[[INF for b in range(401)] for a in range(401)] for i in range(N + 1)] dp[0][0][0] = 0 for i in range(1, N + 1): ai, bi, ci = list(map(int, input().split())) for a in range(401): for b in range(401): if a - ai >= 0 and b - bi >= 0: dp[i][a][b] = min(dp[i - 1][a][b], dp[i - 1][a - ai][b - bi] + ci) else: dp[i][a][b] = dp[i - 1][a][b] ans = INF for j in range(1, 401): if Ma * j >= 400 or Mb * j >= 400: break ans = min(ans, dp[N][Ma * j][Mb * j]) print((ans if ans != INF else -1))
N, Ma, Mb = list(map(int, input().split())) INF = 10000 dp = [[INF for b in range(401)] for a in range(401)] dp[0][0] = 0 for i in range(1, N + 1): ai, bi, ci = list(map(int, input().split())) for a in range(400, -1, -1): for b in range(400, -1, -1): if a - ai >= 0 and b - bi >= 0: dp[a][b] = min(dp[a][b], dp[a - ai][b - bi] + ci) ans = INF for j in range(1, 401): if Ma * j > 400 or Mb * j > 400: break ans = min(ans, dp[Ma * j][Mb * j]) print((ans if ans != INF else -1))
false
8.333333
[ "-dp = [[[INF for b in range(401)] for a in range(401)] for i in range(N + 1)]", "-dp[0][0][0] = 0", "+dp = [[INF for b in range(401)] for a in range(401)]", "+dp[0][0] = 0", "- for a in range(401):", "- for b in range(401):", "+ for a in range(400, -1, -1):", "+ for b in range(400, -1, -1):", "- dp[i][a][b] = min(dp[i - 1][a][b], dp[i - 1][a - ai][b - bi] + ci)", "- else:", "- dp[i][a][b] = dp[i - 1][a][b]", "+ dp[a][b] = min(dp[a][b], dp[a - ai][b - bi] + ci)", "- if Ma * j >= 400 or Mb * j >= 400:", "+ if Ma * j > 400 or Mb * j > 400:", "- ans = min(ans, dp[N][Ma * j][Mb * j])", "+ ans = min(ans, dp[Ma * j][Mb * j])" ]
false
0.686782
0.331027
2.074701
[ "s836525105", "s353190801" ]
u657994700
p03261
python
s541183644
s795197236
19
17
3,064
3,060
Accepted
Accepted
10.53
N = int(eval(input())) W = [] for i in range(0,N): W.append(eval(input())) result = 'Yes' for i,w in enumerate(W): if i>0 and W[i-1][-1] != W[i][0]: result = 'No' Wset = set(W) if len(W) != len(Wset): result = 'No' print(result)
# PROXY N = int(eval(input())) list = [eval(input()) for i in range(N)] def has_duplicates(seq): return len(seq) != len(set(seq)) if has_duplicates(list): print("No") else: i = 1 while i < N: if list[i-1][-1] != list[i][0]: print("No") break else: i += 1 else: print("Yes")
17
18
265
363
N = int(eval(input())) W = [] for i in range(0, N): W.append(eval(input())) result = "Yes" for i, w in enumerate(W): if i > 0 and W[i - 1][-1] != W[i][0]: result = "No" Wset = set(W) if len(W) != len(Wset): result = "No" print(result)
# PROXY N = int(eval(input())) list = [eval(input()) for i in range(N)] def has_duplicates(seq): return len(seq) != len(set(seq)) if has_duplicates(list): print("No") else: i = 1 while i < N: if list[i - 1][-1] != list[i][0]: print("No") break else: i += 1 else: print("Yes")
false
5.555556
[ "+# PROXY", "-W = []", "-for i in range(0, N):", "- W.append(eval(input()))", "-result = \"Yes\"", "-for i, w in enumerate(W):", "- if i > 0 and W[i - 1][-1] != W[i][0]:", "- result = \"No\"", "-Wset = set(W)", "-if len(W) != len(Wset):", "- result = \"No\"", "-print(result)", "+list = [eval(input()) for i in range(N)]", "+", "+", "+def has_duplicates(seq):", "+ return len(seq) != len(set(seq))", "+", "+", "+if has_duplicates(list):", "+ print(\"No\")", "+else:", "+ i = 1", "+ while i < N:", "+ if list[i - 1][-1] != list[i][0]:", "+ print(\"No\")", "+ break", "+ else:", "+ i += 1", "+ else:", "+ print(\"Yes\")" ]
false
0.042163
0.041214
1.023044
[ "s541183644", "s795197236" ]
u094191970
p02678
python
s401541694
s840906965
722
538
35,516
34,732
Accepted
Accepted
25.48
from collections import deque n,m=list(map(int,input().split())) tree=[[] for i in range(n)] for i in range(m): a,b=list(map(int,input().split())) a-=1 b-=1 tree[a].append(b) tree[b].append(a) dist=[-1 for i in range(n)] dist[0]=0 ans=[-1 for i in range(n)] ans[0]=0 dq=deque() dq.append(0) while dq: x=dq.popleft() for i in tree[x]: if ans[i]==-1: ans[i]=x dq.append(i) if -1 in ans: print('No') exit() print('Yes') for i in ans[1:]: print((i+1))
from collections import deque from sys import stdin nii=lambda:list(map(int,stdin.readline().split())) n,m=nii() tree=[[] for i in range(n)] for i in range(m): a,b=nii() a-=1 b-=1 tree[a].append(b) tree[b].append(a) ans=[-1 for i in range(n)] ans[0]=0 dq=deque() dq.append(0) while dq: x=dq.popleft() for i in tree[x]: if ans[i]==-1: ans[i]=x dq.append(i) print('Yes') for i in ans[1:]: print((i+1))
34
29
509
456
from collections import deque n, m = list(map(int, input().split())) tree = [[] for i in range(n)] for i in range(m): a, b = list(map(int, input().split())) a -= 1 b -= 1 tree[a].append(b) tree[b].append(a) dist = [-1 for i in range(n)] dist[0] = 0 ans = [-1 for i in range(n)] ans[0] = 0 dq = deque() dq.append(0) while dq: x = dq.popleft() for i in tree[x]: if ans[i] == -1: ans[i] = x dq.append(i) if -1 in ans: print("No") exit() print("Yes") for i in ans[1:]: print((i + 1))
from collections import deque from sys import stdin nii = lambda: list(map(int, stdin.readline().split())) n, m = nii() tree = [[] for i in range(n)] for i in range(m): a, b = nii() a -= 1 b -= 1 tree[a].append(b) tree[b].append(a) ans = [-1 for i in range(n)] ans[0] = 0 dq = deque() dq.append(0) while dq: x = dq.popleft() for i in tree[x]: if ans[i] == -1: ans[i] = x dq.append(i) print("Yes") for i in ans[1:]: print((i + 1))
false
14.705882
[ "+from sys import stdin", "-n, m = list(map(int, input().split()))", "+nii = lambda: list(map(int, stdin.readline().split()))", "+n, m = nii()", "- a, b = list(map(int, input().split()))", "+ a, b = nii()", "-dist = [-1 for i in range(n)]", "-dist[0] = 0", "-if -1 in ans:", "- print(\"No\")", "- exit()" ]
false
0.037889
0.037682
1.005491
[ "s401541694", "s840906965" ]
u597374218
p02713
python
s408470856
s594384497
1,769
215
9,152
89,652
Accepted
Accepted
87.85
import math K=int(eval(input())) print((sum(math.gcd(math.gcd(a,b),c) for a in range(1,K+1) for b in range(1,K+1) for c in range(1,K+1))))
import numpy as np K=int(eval(input())) k=np.arange(1,K+1) print((np.sum(np.gcd.outer(np.gcd.outer(k,k),k))))
3
4
132
104
import math K = int(eval(input())) print( ( sum( math.gcd(math.gcd(a, b), c) for a in range(1, K + 1) for b in range(1, K + 1) for c in range(1, K + 1) ) ) )
import numpy as np K = int(eval(input())) k = np.arange(1, K + 1) print((np.sum(np.gcd.outer(np.gcd.outer(k, k), k))))
false
25
[ "-import math", "+import numpy as np", "-print(", "- (", "- sum(", "- math.gcd(math.gcd(a, b), c)", "- for a in range(1, K + 1)", "- for b in range(1, K + 1)", "- for c in range(1, K + 1)", "- )", "- )", "-)", "+k = np.arange(1, K + 1)", "+print((np.sum(np.gcd.outer(np.gcd.outer(k, k), k))))" ]
false
0.059571
0.410492
0.14512
[ "s408470856", "s594384497" ]
u102461423
p03092
python
s845868073
s074938538
1,704
1,512
14,536
14,536
Accepted
Accepted
11.27
import numpy as np N,A,B,*P=list(map(int,open(0).read().split())) dp=np.full(N+1,10**18,np.int64) dp[0]=0 for p in P: dp[p]=min(dp[:p]) dp[p+1:]+=B dp[:p]+=A print((min(dp)))
from numpy import * N,A,B,*P=list(map(int,open(0).read().split()));d=full(N+1,1<<60,'int');d[0]=0 for p in P:d[p]=min(d[:p]);d[p+1:]+=B;d[:p]+=A print((min(d)))
9
4
186
155
import numpy as np N, A, B, *P = list(map(int, open(0).read().split())) dp = np.full(N + 1, 10**18, np.int64) dp[0] = 0 for p in P: dp[p] = min(dp[:p]) dp[p + 1 :] += B dp[:p] += A print((min(dp)))
from numpy import * N, A, B, *P = list(map(int, open(0).read().split())) d = full(N + 1, 1 << 60, "int") d[0] = 0 for p in P: d[p] = min(d[:p]) d[p + 1 :] += B d[:p] += A print((min(d)))
false
55.555556
[ "-import numpy as np", "+from numpy import *", "-dp = np.full(N + 1, 10**18, np.int64)", "-dp[0] = 0", "+d = full(N + 1, 1 << 60, \"int\")", "+d[0] = 0", "- dp[p] = min(dp[:p])", "- dp[p + 1 :] += B", "- dp[:p] += A", "-print((min(dp)))", "+ d[p] = min(d[:p])", "+ d[p + 1 :] += B", "+ d[:p] += A", "+print((min(d)))" ]
false
0.553135
0.337761
1.637652
[ "s845868073", "s074938538" ]
u017624958
p03240
python
s349099224
s655578832
127
117
3,064
3,064
Accepted
Accepted
7.87
N = int(eval(input())) xyh = [list(map(int, input().split())) for i in range(N)] # print(N, xyh) height = None found = False for cx in range(0, 101): for cy in range(0, 101): candidate = 0 for x, y, h in xyh: if h == 0: continue dx = abs(x - cx) dy = abs(y - cy) candidate = dx + dy + h break found = True for x, y, h in xyh: _h = candidate - abs(x - cx) - abs(y - cy) if h == 0 and _h <= 0: continue if not h == _h: found = False break if found is True: break if found is True: break height = candidate if candidate is not None else 0 print((cx, cy, height))
N = int(eval(input())) xyh = [list(map(int, input().split())) for i in range(N)] # print(N, xyh) height = None found = False for cx in range(0, 101): for cy in range(0, 101): candidate = 0 for x, y, h in xyh: if h == 0: continue dx = abs(x - cx) dy = abs(y - cy) candidate = dx + dy + h break found = True for x, y, h in xyh: _h = max(candidate - abs(x - cx) - abs(y - cy), 0) if h != _h: found = False break if found is True: break if found is True: break height = candidate if candidate is not None else 0 print((cx, cy, height))
29
28
769
728
N = int(eval(input())) xyh = [list(map(int, input().split())) for i in range(N)] # print(N, xyh) height = None found = False for cx in range(0, 101): for cy in range(0, 101): candidate = 0 for x, y, h in xyh: if h == 0: continue dx = abs(x - cx) dy = abs(y - cy) candidate = dx + dy + h break found = True for x, y, h in xyh: _h = candidate - abs(x - cx) - abs(y - cy) if h == 0 and _h <= 0: continue if not h == _h: found = False break if found is True: break if found is True: break height = candidate if candidate is not None else 0 print((cx, cy, height))
N = int(eval(input())) xyh = [list(map(int, input().split())) for i in range(N)] # print(N, xyh) height = None found = False for cx in range(0, 101): for cy in range(0, 101): candidate = 0 for x, y, h in xyh: if h == 0: continue dx = abs(x - cx) dy = abs(y - cy) candidate = dx + dy + h break found = True for x, y, h in xyh: _h = max(candidate - abs(x - cx) - abs(y - cy), 0) if h != _h: found = False break if found is True: break if found is True: break height = candidate if candidate is not None else 0 print((cx, cy, height))
false
3.448276
[ "- _h = candidate - abs(x - cx) - abs(y - cy)", "- if h == 0 and _h <= 0:", "- continue", "- if not h == _h:", "+ _h = max(candidate - abs(x - cx) - abs(y - cy), 0)", "+ if h != _h:" ]
false
0.094444
0.043339
2.179209
[ "s349099224", "s655578832" ]
u912862653
p02573
python
s541706027
s295801762
772
458
250,308
80,380
Accepted
Accepted
40.67
from functools import reduce from fractions import gcd import math import bisect import itertools import sys sys.setrecursionlimit(10000000) input = sys.stdin.readline INF = float("inf") def dfs(G, visited, v, cnt): visited[v] = True for nv in G[v]: if visited[nv]: continue cnt = dfs(G, visited, nv, cnt + 1) return cnt # 処理内容 def main(): N, M = list(map(int, input().split())) if M == 0: print((1)) return P = set() for _ in range(M): a, b = list(map(int, input().split())) a -= 1; b -= 1 if a > b: a, b = b, a P.add((a, b)) G = [[] for _ in range(N)] for pair in P: a, b = pair G[a].append(b) G[b].append(a) visited = [False] * N ans = 1 for i in range(N): if visited[i]: continue tmp = dfs(G, visited, i, 1) ans = max(ans, tmp) print(ans) if __name__ == '__main__': main()
from functools import reduce from fractions import gcd import math import bisect import itertools import sys sys.setrecursionlimit(10000000) input = sys.stdin.readline INF = float("inf") # 1-indexed class UnionFind(): # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1]*(n+1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0]*(n+1) # ノードxのrootノードを見つける def Find_Root(self, x): if(self.root[x] < 0): return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if(x == y): return # 違う木に属していた場合rnkを見てくっつける方を決める elif(self.rnk[x] > self.rnk[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if(self.rnk[x] == self.rnk[y]): self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] # 処理内容 def main(): N, M = list(map(int, input().split())) T = UnionFind(N) for _ in range(M): a, b = list(map(int, input().split())) T.Unite(a, b) ans = 0 for i in range(1, N+1): ans = max(ans, T.Count(i)) print(ans) if __name__ == '__main__': main()
56
78
1,037
1,861
from functools import reduce from fractions import gcd import math import bisect import itertools import sys sys.setrecursionlimit(10000000) input = sys.stdin.readline INF = float("inf") def dfs(G, visited, v, cnt): visited[v] = True for nv in G[v]: if visited[nv]: continue cnt = dfs(G, visited, nv, cnt + 1) return cnt # 処理内容 def main(): N, M = list(map(int, input().split())) if M == 0: print((1)) return P = set() for _ in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 if a > b: a, b = b, a P.add((a, b)) G = [[] for _ in range(N)] for pair in P: a, b = pair G[a].append(b) G[b].append(a) visited = [False] * N ans = 1 for i in range(N): if visited[i]: continue tmp = dfs(G, visited, i, 1) ans = max(ans, tmp) print(ans) if __name__ == "__main__": main()
from functools import reduce from fractions import gcd import math import bisect import itertools import sys sys.setrecursionlimit(10000000) input = sys.stdin.readline INF = float("inf") # 1-indexed class UnionFind: # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1] * (n + 1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0] * (n + 1) # ノードxのrootノードを見つける def Find_Root(self, x): if self.root[x] < 0: return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if x == y: return # 違う木に属していた場合rnkを見てくっつける方を決める elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] # 処理内容 def main(): N, M = list(map(int, input().split())) T = UnionFind(N) for _ in range(M): a, b = list(map(int, input().split())) T.Unite(a, b) ans = 0 for i in range(1, N + 1): ans = max(ans, T.Count(i)) print(ans) if __name__ == "__main__": main()
false
28.205128
[ "+# 1-indexed", "+class UnionFind:", "+ # 作りたい要素数nで初期化", "+ # 使用するインスタンス変数の初期化", "+ def __init__(self, n):", "+ self.n = n", "+ # root[x]<0ならそのノードが根かつその値が木の要素数", "+ # rootノードでその木の要素数を記録する", "+ self.root = [-1] * (n + 1)", "+ # 木をくっつける時にアンバランスにならないように調整する", "+ self.rnk = [0] * (n + 1)", "+ # ノードxのrootノードを見つける", "+ def Find_Root(self, x):", "+ if self.root[x] < 0:", "+ return x", "+ else:", "+ # ここで代入しておくことで、後の繰り返しを避ける", "+ self.root[x] = self.Find_Root(self.root[x])", "+ return self.root[x]", "-def dfs(G, visited, v, cnt):", "- visited[v] = True", "- for nv in G[v]:", "- if visited[nv]:", "- continue", "- cnt = dfs(G, visited, nv, cnt + 1)", "- return cnt", "+ # 木の併合、入力は併合したい各ノード", "+ def Unite(self, x, y):", "+ # 入力ノードのrootノードを見つける", "+ x = self.Find_Root(x)", "+ y = self.Find_Root(y)", "+ # すでに同じ木に属していた場合", "+ if x == y:", "+ return", "+ # 違う木に属していた場合rnkを見てくっつける方を決める", "+ elif self.rnk[x] > self.rnk[y]:", "+ self.root[x] += self.root[y]", "+ self.root[y] = x", "+ else:", "+ self.root[y] += self.root[x]", "+ self.root[x] = y", "+ # rnkが同じ(深さに差がない場合)は1増やす", "+ if self.rnk[x] == self.rnk[y]:", "+ self.rnk[y] += 1", "+", "+ # xとyが同じグループに属するか判断", "+ def isSameGroup(self, x, y):", "+ return self.Find_Root(x) == self.Find_Root(y)", "+", "+ # ノードxが属する木のサイズを返す", "+ def Count(self, x):", "+ return -self.root[self.Find_Root(x)]", "- if M == 0:", "- print((1))", "- return", "- P = set()", "+ T = UnionFind(N)", "- a -= 1", "- b -= 1", "- if a > b:", "- a, b = b, a", "- P.add((a, b))", "- G = [[] for _ in range(N)]", "- for pair in P:", "- a, b = pair", "- G[a].append(b)", "- G[b].append(a)", "- visited = [False] * N", "- ans = 1", "- for i in range(N):", "- if visited[i]:", "- continue", "- tmp = dfs(G, visited, i, 1)", "- ans = max(ans, tmp)", "+ T.Unite(a, b)", "+ ans = 0", "+ for i in range(1, N + 1):", "+ ans = max(ans, T.Count(i))" ]
false
0.082541
0.062051
1.330227
[ "s541706027", "s295801762" ]
u426534722
p02257
python
s385010368
s249043062
300
190
5,648
5,760
Accepted
Accepted
36.67
import sys readline = sys.stdin.readline prime = set([2]) for i in range(3, 10000, 2): for j in prime: if i % j == 0: break else: prime.add(i) n = int(eval(input())) cnt = 0 for i in (int(readline()) for _ in range(n)): if i in prime: cnt += 1 continue for j in prime: if i % j == 0: break else: cnt += 1 print(cnt)
from sys import stdin import math def isPrime(x): if x == 2 or x == 3: return True elif (x < 2 or x % 2 == 0 or x % 3 == 0): return False s = int(math.sqrt(x) + 1) for i in range(5, s + 1, 2): if x % i == 0: return False return True print((sum([isPrime(int(stdin.readline())) for _ in range(int(stdin.readline()))])))
22
11
424
355
import sys readline = sys.stdin.readline prime = set([2]) for i in range(3, 10000, 2): for j in prime: if i % j == 0: break else: prime.add(i) n = int(eval(input())) cnt = 0 for i in (int(readline()) for _ in range(n)): if i in prime: cnt += 1 continue for j in prime: if i % j == 0: break else: cnt += 1 print(cnt)
from sys import stdin import math def isPrime(x): if x == 2 or x == 3: return True elif x < 2 or x % 2 == 0 or x % 3 == 0: return False s = int(math.sqrt(x) + 1) for i in range(5, s + 1, 2): if x % i == 0: return False return True print((sum([isPrime(int(stdin.readline())) for _ in range(int(stdin.readline()))])))
false
50
[ "-import sys", "+from sys import stdin", "+import math", "-readline = sys.stdin.readline", "-prime = set([2])", "-for i in range(3, 10000, 2):", "- for j in prime:", "- if i % j == 0:", "- break", "- else:", "- prime.add(i)", "-n = int(eval(input()))", "-cnt = 0", "-for i in (int(readline()) for _ in range(n)):", "- if i in prime:", "- cnt += 1", "- continue", "- for j in prime:", "- if i % j == 0:", "- break", "- else:", "- cnt += 1", "-print(cnt)", "+", "+def isPrime(x):", "+ if x == 2 or x == 3:", "+ return True", "+ elif x < 2 or x % 2 == 0 or x % 3 == 0:", "+ return False", "+ s = int(math.sqrt(x) + 1)", "+ for i in range(5, s + 1, 2):", "+ if x % i == 0:", "+ return False", "+ return True", "+", "+", "+print((sum([isPrime(int(stdin.readline())) for _ in range(int(stdin.readline()))])))" ]
false
0.179171
0.040643
4.408393
[ "s385010368", "s249043062" ]
u930705402
p02714
python
s357985588
s135837224
1,939
423
75,940
68,168
Accepted
Accepted
78.18
import bisect import sys input=sys.stdin.readline def main(): N=int(eval(input())) S=input().rstrip() R,G,B=[],[],[] for i in range(N): if S[i]=='R': R.append(i) elif S[i]=='G': G.append(i) elif S[i]=='B': B.append(i) ans=0 for i in range(N): for j in range(i): if(S[i]==S[j]): continue s=set([S[i],S[j]]) if('B' not in s): lon=len(B)-bisect.bisect_left(B,i) mi=bisect.bisect_left(B,i+i-j) if(mi<len(B) and B[mi]==i*2-j): lon-=1 elif('R' not in s): lon=len(R)-bisect.bisect_left(R,i) mi=bisect.bisect_left(R,i+i-j) if(mi<len(R) and R[mi]==i*2-j): lon-=1 elif('G' not in s): lon=len(G)-bisect.bisect_left(G,i) mi=bisect.bisect_left(G,i+i-j) if(mi<len(G) and G[mi]==i*2-j): lon-=1 ans+=lon print(ans) if __name__=='__main__': main()
N=int(eval(input())) S=eval(input()) R,G,B=0,0,0 for i in range(N): if(S[i]=='R'): R+=1 elif(S[i]=='G'): G+=1 else: B+=1 res=R*G*B cnt=0 for i in range(N): lr=0 while(i-lr>=0 and i+lr<N): s=set([S[i],S[i-lr],S[i+lr]]) if(len(s)==3): res-=1 lr+=1 print(res)
41
20
1,170
343
import bisect import sys input = sys.stdin.readline def main(): N = int(eval(input())) S = input().rstrip() R, G, B = [], [], [] for i in range(N): if S[i] == "R": R.append(i) elif S[i] == "G": G.append(i) elif S[i] == "B": B.append(i) ans = 0 for i in range(N): for j in range(i): if S[i] == S[j]: continue s = set([S[i], S[j]]) if "B" not in s: lon = len(B) - bisect.bisect_left(B, i) mi = bisect.bisect_left(B, i + i - j) if mi < len(B) and B[mi] == i * 2 - j: lon -= 1 elif "R" not in s: lon = len(R) - bisect.bisect_left(R, i) mi = bisect.bisect_left(R, i + i - j) if mi < len(R) and R[mi] == i * 2 - j: lon -= 1 elif "G" not in s: lon = len(G) - bisect.bisect_left(G, i) mi = bisect.bisect_left(G, i + i - j) if mi < len(G) and G[mi] == i * 2 - j: lon -= 1 ans += lon print(ans) if __name__ == "__main__": main()
N = int(eval(input())) S = eval(input()) R, G, B = 0, 0, 0 for i in range(N): if S[i] == "R": R += 1 elif S[i] == "G": G += 1 else: B += 1 res = R * G * B cnt = 0 for i in range(N): lr = 0 while i - lr >= 0 and i + lr < N: s = set([S[i], S[i - lr], S[i + lr]]) if len(s) == 3: res -= 1 lr += 1 print(res)
false
51.219512
[ "-import bisect", "-import sys", "-", "-input = sys.stdin.readline", "-", "-", "-def main():", "- N = int(eval(input()))", "- S = input().rstrip()", "- R, G, B = [], [], []", "- for i in range(N):", "- if S[i] == \"R\":", "- R.append(i)", "- elif S[i] == \"G\":", "- G.append(i)", "- elif S[i] == \"B\":", "- B.append(i)", "- ans = 0", "- for i in range(N):", "- for j in range(i):", "- if S[i] == S[j]:", "- continue", "- s = set([S[i], S[j]])", "- if \"B\" not in s:", "- lon = len(B) - bisect.bisect_left(B, i)", "- mi = bisect.bisect_left(B, i + i - j)", "- if mi < len(B) and B[mi] == i * 2 - j:", "- lon -= 1", "- elif \"R\" not in s:", "- lon = len(R) - bisect.bisect_left(R, i)", "- mi = bisect.bisect_left(R, i + i - j)", "- if mi < len(R) and R[mi] == i * 2 - j:", "- lon -= 1", "- elif \"G\" not in s:", "- lon = len(G) - bisect.bisect_left(G, i)", "- mi = bisect.bisect_left(G, i + i - j)", "- if mi < len(G) and G[mi] == i * 2 - j:", "- lon -= 1", "- ans += lon", "- print(ans)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+N = int(eval(input()))", "+S = eval(input())", "+R, G, B = 0, 0, 0", "+for i in range(N):", "+ if S[i] == \"R\":", "+ R += 1", "+ elif S[i] == \"G\":", "+ G += 1", "+ else:", "+ B += 1", "+res = R * G * B", "+cnt = 0", "+for i in range(N):", "+ lr = 0", "+ while i - lr >= 0 and i + lr < N:", "+ s = set([S[i], S[i - lr], S[i + lr]])", "+ if len(s) == 3:", "+ res -= 1", "+ lr += 1", "+print(res)" ]
false
0.038602
0.083412
0.462791
[ "s357985588", "s135837224" ]
u332906195
p02707
python
s729844809
s606762717
214
146
48,788
33,936
Accepted
Accepted
31.78
N = int(eval(input())) ans = {i + 1: 0 for i in range(N)} for a in list(map(int, input().split())): ans[a] += 1 for i in range(N): print((ans[i + 1]))
N = int(eval(input())) ans = [0] * N for a in list(map(int, input().split())): ans[a - 1] += 1 for a in ans: print(a)
7
6
158
125
N = int(eval(input())) ans = {i + 1: 0 for i in range(N)} for a in list(map(int, input().split())): ans[a] += 1 for i in range(N): print((ans[i + 1]))
N = int(eval(input())) ans = [0] * N for a in list(map(int, input().split())): ans[a - 1] += 1 for a in ans: print(a)
false
14.285714
[ "-ans = {i + 1: 0 for i in range(N)}", "+ans = [0] * N", "- ans[a] += 1", "-for i in range(N):", "- print((ans[i + 1]))", "+ ans[a - 1] += 1", "+for a in ans:", "+ print(a)" ]
false
0.034408
0.037602
0.91506
[ "s729844809", "s606762717" ]
u867069435
p03721
python
s736175396
s978128125
531
364
27,872
14,940
Accepted
Accepted
31.45
n, k = list(map(int, input().split())) num = [] for i in range(n): num.append(list(map(int, input().split()))) num.sort() summ = 0 for i in range(len(num)): if k <= summ + num[i][1]: print((num[i][0])) exit() else: summ += num[i][1]
from collections import defaultdict n, k = list(map(int, input().split())) s = defaultdict(int) for j in range(n): i, v = list(map(int, input().split())) s[i] += v f = sorted(s.items()) tmp = 0 for g in f: tmp += g[1] if tmp >= k: print((g[0])) exit()
12
13
271
282
n, k = list(map(int, input().split())) num = [] for i in range(n): num.append(list(map(int, input().split()))) num.sort() summ = 0 for i in range(len(num)): if k <= summ + num[i][1]: print((num[i][0])) exit() else: summ += num[i][1]
from collections import defaultdict n, k = list(map(int, input().split())) s = defaultdict(int) for j in range(n): i, v = list(map(int, input().split())) s[i] += v f = sorted(s.items()) tmp = 0 for g in f: tmp += g[1] if tmp >= k: print((g[0])) exit()
false
7.692308
[ "+from collections import defaultdict", "+", "-num = []", "-for i in range(n):", "- num.append(list(map(int, input().split())))", "-num.sort()", "-summ = 0", "-for i in range(len(num)):", "- if k <= summ + num[i][1]:", "- print((num[i][0]))", "+s = defaultdict(int)", "+for j in range(n):", "+ i, v = list(map(int, input().split()))", "+ s[i] += v", "+f = sorted(s.items())", "+tmp = 0", "+for g in f:", "+ tmp += g[1]", "+ if tmp >= k:", "+ print((g[0]))", "- else:", "- summ += num[i][1]" ]
false
0.041308
0.037387
1.10487
[ "s736175396", "s978128125" ]
u912237403
p02412
python
s913795988
s633291203
350
280
4,228
4,228
Accepted
Accepted
20
while True: n,x = list(map(int, input().split())) if n == 0 and x == 0: break c = 0 for i in range(1, n+1): for j in range(i+1, n+1): ij = i + j for k in range(j+1, n+1): if ij+k == x: c += 1 print(c)
while True: n,x = list(map(int, input().split())) if n == 0 and x == 0: break c = 0 for i in range(1, min(n+1,x/3)): for j in range(i+1, min(n+1,x/2)): for k in range(j+1, n+1): ijk = i + j + k if ijk == x: c += 1 break elif ijk > x: break print(c)
11
13
299
389
while True: n, x = list(map(int, input().split())) if n == 0 and x == 0: break c = 0 for i in range(1, n + 1): for j in range(i + 1, n + 1): ij = i + j for k in range(j + 1, n + 1): if ij + k == x: c += 1 print(c)
while True: n, x = list(map(int, input().split())) if n == 0 and x == 0: break c = 0 for i in range(1, min(n + 1, x / 3)): for j in range(i + 1, min(n + 1, x / 2)): for k in range(j + 1, n + 1): ijk = i + j + k if ijk == x: c += 1 break elif ijk > x: break print(c)
false
15.384615
[ "- for i in range(1, n + 1):", "- for j in range(i + 1, n + 1):", "- ij = i + j", "+ for i in range(1, min(n + 1, x / 3)):", "+ for j in range(i + 1, min(n + 1, x / 2)):", "- if ij + k == x:", "+ ijk = i + j + k", "+ if ijk == x:", "+ break", "+ elif ijk > x:", "+ break" ]
false
0.044317
0.044284
1.00076
[ "s913795988", "s633291203" ]
u312025627
p03470
python
s272147077
s100512005
181
162
38,256
38,256
Accepted
Accepted
10.5
n = int(eval(input())) d = [int(eval(input())) for i in range(n)] cnt = 0 value_before = 0 for i in range(n): value = max(d) if i == 0: value_before = value d.remove(value) cnt += 1 continue if value_before > value: value_before = value cnt += 1 d.remove(value) print(cnt)
def main(): N = int(eval(input())) d = {int(eval(input())) for _ in range(N)} print((len(d))) if __name__ == '__main__': main()
18
8
343
139
n = int(eval(input())) d = [int(eval(input())) for i in range(n)] cnt = 0 value_before = 0 for i in range(n): value = max(d) if i == 0: value_before = value d.remove(value) cnt += 1 continue if value_before > value: value_before = value cnt += 1 d.remove(value) print(cnt)
def main(): N = int(eval(input())) d = {int(eval(input())) for _ in range(N)} print((len(d))) if __name__ == "__main__": main()
false
55.555556
[ "-n = int(eval(input()))", "-d = [int(eval(input())) for i in range(n)]", "-cnt = 0", "-value_before = 0", "-for i in range(n):", "- value = max(d)", "- if i == 0:", "- value_before = value", "- d.remove(value)", "- cnt += 1", "- continue", "- if value_before > value:", "- value_before = value", "- cnt += 1", "- d.remove(value)", "-print(cnt)", "+def main():", "+ N = int(eval(input()))", "+ d = {int(eval(input())) for _ in range(N)}", "+ print((len(d)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.048176
0.047527
1.013642
[ "s272147077", "s100512005" ]
u844005364
p03854
python
s090838608
s314029693
25
19
9,588
3,188
Accepted
Accepted
24
import re print(("YES" if re.match("^(eraser?|dream(er)?)*$",eval(input())) else "NO"))
s = eval(input()) if s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream",""): print("NO") else: print("YES")
2
5
80
143
import re print(("YES" if re.match("^(eraser?|dream(er)?)*$", eval(input())) else "NO"))
s = eval(input()) if ( s.replace("eraser", "") .replace("erase", "") .replace("dreamer", "") .replace("dream", "") ): print("NO") else: print("YES")
false
60
[ "-import re", "-", "-print((\"YES\" if re.match(\"^(eraser?|dream(er)?)*$\", eval(input())) else \"NO\"))", "+s = eval(input())", "+if (", "+ s.replace(\"eraser\", \"\")", "+ .replace(\"erase\", \"\")", "+ .replace(\"dreamer\", \"\")", "+ .replace(\"dream\", \"\")", "+):", "+ print(\"NO\")", "+else:", "+ print(\"YES\")" ]
false
0.037042
0.081097
0.456767
[ "s090838608", "s314029693" ]
u928784113
p04001
python
s632448066
s112065325
309
168
65,900
13,640
Accepted
Accepted
45.63
import itertools from collections import deque,defaultdict,Counter from itertools import accumulate import bisect from heapq import heappop,heappush,heapify from fractions import gcd from copy import deepcopy import math import queue #import numpy as np #import sympy as syp(素因数分解とか) Mod = 1000000007 import sys sys.setrecursionlimit(100000) def sieve_of_eratosthenes(n): if not isinstance(n,int): raise TypeError("n is not int") if n<2: raise ValueError("n is not effective") prime = [1]*(n+1) for i in range(2,int(math.sqrt(n))+1): if prime[i] == 1: for j in range(2*i,n+1): if j%i == 0: prime[j] = 0 res = [] for i in range(2,n+1): if prime[i] == 1: res.append(i) return res class UnionFind: def __init__(self,n): self.parent = [i for i in range(n+1)] self.rank = [0 for i in range(n+1)] def findroot(self,x): if x == self.parent[x]: return x else: y = self.parent[x] y = self.findroot(self.parent[x]) return y def union(self,x,y): px = self.findroot(x) py = self.findroot(y) if px < py: self.parent[py] = px else: self.parent[px] = py def same_group_or_no(self,x,y): return self.findroot(x) == self.findroot(y) def main(): #startline-------------------------------------------- s = eval(input()) sl = [i for i in s] n = len(s) - 1 sublist = [-1]*n anslist = [sl[0]] ans = [] for i in range(1 << n): for j in range(n): if i >> j & 1: sublist[j] = "+" for j in range(n): if sublist[j] == "+": anslist.append("+"+sl[j+1]) else: anslist.append(sl[j+1]) ans.append(eval("".join(anslist))) anslist = [sl[0]] sublist = [-1]*n print((sum(ans))) #endline=============================================== if __name__ == "__main__": main()
import itertools from collections import deque,defaultdict,Counter from itertools import accumulate import bisect from heapq import heappop,heappush,heapify from fractions import gcd from copy import deepcopy import math import queue import numpy as np #import sympy as syp(素因数分解とか) Mod = 1000000007 import sys sys.setrecursionlimit(100000) def sieve_of_eratosthenes(n): if not isinstance(n,int): raise TypeError("n is not int") if n<2: raise ValueError("n is not effective") prime = [1]*(n+1) for i in range(2,int(math.sqrt(n))+1): if prime[i] == 1: for j in range(2*i,n+1): if j%i == 0: prime[j] = 0 res = [] for i in range(2,n+1): if prime[i] == 1: res.append(i) return res class UnionFind: def __init__(self,n): self.parent = [i for i in range(n+1)] self.rank = [0 for i in range(n+1)] def findroot(self,x): if x == self.parent[x]: return x else: y = self.parent[x] y = self.findroot(self.parent[x]) return y def union(self,x,y): px = self.findroot(x) py = self.findroot(y) if px < py: self.parent[py] = px else: self.parent[px] = py def same_group_or_no(self,x,y): return self.findroot(x) == self.findroot(y) def main(): #startline------------------------------------------- s = eval(input()) sl = [i for i in s] anslist = [sl[0]] n = len(s) - 1 sublist = [-1]*n ans = [] for i in range(1 << n): for j in range(n): if i >> j & 1: sublist[j] = "+" for j in range(n): if sublist[j] == "+": anslist.append("+") anslist.append(sl[j+1]) else: anslist.append(sl[j+1]) ans.append(eval("".join(anslist))) sublist = [-1]*n anslist = [sl[0]] print((sum(ans))) if __name__ == "__main__": main() #endline===============================================
80
81
2,161
2,201
import itertools from collections import deque, defaultdict, Counter from itertools import accumulate import bisect from heapq import heappop, heappush, heapify from fractions import gcd from copy import deepcopy import math import queue # import numpy as np # import sympy as syp(素因数分解とか) Mod = 1000000007 import sys sys.setrecursionlimit(100000) def sieve_of_eratosthenes(n): if not isinstance(n, int): raise TypeError("n is not int") if n < 2: raise ValueError("n is not effective") prime = [1] * (n + 1) for i in range(2, int(math.sqrt(n)) + 1): if prime[i] == 1: for j in range(2 * i, n + 1): if j % i == 0: prime[j] = 0 res = [] for i in range(2, n + 1): if prime[i] == 1: res.append(i) return res class UnionFind: def __init__(self, n): self.parent = [i for i in range(n + 1)] self.rank = [0 for i in range(n + 1)] def findroot(self, x): if x == self.parent[x]: return x else: y = self.parent[x] y = self.findroot(self.parent[x]) return y def union(self, x, y): px = self.findroot(x) py = self.findroot(y) if px < py: self.parent[py] = px else: self.parent[px] = py def same_group_or_no(self, x, y): return self.findroot(x) == self.findroot(y) def main(): # startline-------------------------------------------- s = eval(input()) sl = [i for i in s] n = len(s) - 1 sublist = [-1] * n anslist = [sl[0]] ans = [] for i in range(1 << n): for j in range(n): if i >> j & 1: sublist[j] = "+" for j in range(n): if sublist[j] == "+": anslist.append("+" + sl[j + 1]) else: anslist.append(sl[j + 1]) ans.append(eval("".join(anslist))) anslist = [sl[0]] sublist = [-1] * n print((sum(ans))) # endline=============================================== if __name__ == "__main__": main()
import itertools from collections import deque, defaultdict, Counter from itertools import accumulate import bisect from heapq import heappop, heappush, heapify from fractions import gcd from copy import deepcopy import math import queue import numpy as np # import sympy as syp(素因数分解とか) Mod = 1000000007 import sys sys.setrecursionlimit(100000) def sieve_of_eratosthenes(n): if not isinstance(n, int): raise TypeError("n is not int") if n < 2: raise ValueError("n is not effective") prime = [1] * (n + 1) for i in range(2, int(math.sqrt(n)) + 1): if prime[i] == 1: for j in range(2 * i, n + 1): if j % i == 0: prime[j] = 0 res = [] for i in range(2, n + 1): if prime[i] == 1: res.append(i) return res class UnionFind: def __init__(self, n): self.parent = [i for i in range(n + 1)] self.rank = [0 for i in range(n + 1)] def findroot(self, x): if x == self.parent[x]: return x else: y = self.parent[x] y = self.findroot(self.parent[x]) return y def union(self, x, y): px = self.findroot(x) py = self.findroot(y) if px < py: self.parent[py] = px else: self.parent[px] = py def same_group_or_no(self, x, y): return self.findroot(x) == self.findroot(y) def main(): # startline------------------------------------------- s = eval(input()) sl = [i for i in s] anslist = [sl[0]] n = len(s) - 1 sublist = [-1] * n ans = [] for i in range(1 << n): for j in range(n): if i >> j & 1: sublist[j] = "+" for j in range(n): if sublist[j] == "+": anslist.append("+") anslist.append(sl[j + 1]) else: anslist.append(sl[j + 1]) ans.append(eval("".join(anslist))) sublist = [-1] * n anslist = [sl[0]] print((sum(ans))) if __name__ == "__main__": main() # endline===============================================
false
1.234568
[ "+import numpy as np", "-# import numpy as np", "+ anslist = [sl[0]]", "- anslist = [sl[0]]", "- anslist.append(\"+\" + sl[j + 1])", "+ anslist.append(\"+\")", "+ anslist.append(sl[j + 1])", "+ sublist = [-1] * n", "- sublist = [-1] * n", "-# endline===============================================", "- main()", "+ main() # endline===============================================" ]
false
0.050135
0.039724
1.262073
[ "s632448066", "s112065325" ]
u952708174
p03625
python
s856631734
s530246848
191
87
22,920
18,316
Accepted
Accepted
54.45
def C_Make_a_Rectangle(lst): N = lst[0] A = lst[1:] from collections import Counter, deque c = sorted(list(Counter(A).items()), reverse=True) # リストの要素が何回現れたか # cの0番要素は値、1番要素は度数 ans = deque([]) for k, v in c: if v == 1: continue elif v == 2 or v == 3: ans.append(k) if len(ans) == 2: break else: ans.append(k) ans.append(k) break if len(ans) < 2: return 0 else: return ans[0] * ans[1] n = int(eval(input())) l = [int(i) for i in input().split()] x = [n] + l print((C_Make_a_Rectangle(x)))
def c_make_a_rectangle(N, A): from collections import Counter count = Counter(A) # リストの要素が何回現れたか cond = [] # 同じ長さのものが2個ある棒の長さ for k, v in list(count.items()): if v == 1: # 1個しかない棒では長方形を作れない continue else: cond.extend([k] * (v // 2)) if len(cond) <= 1: return 0 # 長方形を作れない cond = sorted(cond, reverse=True) ans = cond[0] * cond[1] # 長いもの2組を使う return ans N = int(eval(input())) A = [int(i) for i in input().split()] print((c_make_a_rectangle(N, A)))
30
19
671
538
def C_Make_a_Rectangle(lst): N = lst[0] A = lst[1:] from collections import Counter, deque c = sorted(list(Counter(A).items()), reverse=True) # リストの要素が何回現れたか # cの0番要素は値、1番要素は度数 ans = deque([]) for k, v in c: if v == 1: continue elif v == 2 or v == 3: ans.append(k) if len(ans) == 2: break else: ans.append(k) ans.append(k) break if len(ans) < 2: return 0 else: return ans[0] * ans[1] n = int(eval(input())) l = [int(i) for i in input().split()] x = [n] + l print((C_Make_a_Rectangle(x)))
def c_make_a_rectangle(N, A): from collections import Counter count = Counter(A) # リストの要素が何回現れたか cond = [] # 同じ長さのものが2個ある棒の長さ for k, v in list(count.items()): if v == 1: # 1個しかない棒では長方形を作れない continue else: cond.extend([k] * (v // 2)) if len(cond) <= 1: return 0 # 長方形を作れない cond = sorted(cond, reverse=True) ans = cond[0] * cond[1] # 長いもの2組を使う return ans N = int(eval(input())) A = [int(i) for i in input().split()] print((c_make_a_rectangle(N, A)))
false
36.666667
[ "-def C_Make_a_Rectangle(lst):", "- N = lst[0]", "- A = lst[1:]", "- from collections import Counter, deque", "+def c_make_a_rectangle(N, A):", "+ from collections import Counter", "- c = sorted(list(Counter(A).items()), reverse=True) # リストの要素が何回現れたか", "- # cの0番要素は値、1番要素は度数", "- ans = deque([])", "- for k, v in c:", "- if v == 1:", "+ count = Counter(A) # リストの要素が何回現れたか", "+ cond = [] # 同じ長さのものが2個ある棒の長さ", "+ for k, v in list(count.items()):", "+ if v == 1: # 1個しかない棒では長方形を作れない", "- elif v == 2 or v == 3:", "- ans.append(k)", "- if len(ans) == 2:", "- break", "- ans.append(k)", "- ans.append(k)", "- break", "- if len(ans) < 2:", "- return 0", "- else:", "- return ans[0] * ans[1]", "+ cond.extend([k] * (v // 2))", "+ if len(cond) <= 1:", "+ return 0 # 長方形を作れない", "+ cond = sorted(cond, reverse=True)", "+ ans = cond[0] * cond[1] # 長いもの2組を使う", "+ return ans", "-n = int(eval(input()))", "-l = [int(i) for i in input().split()]", "-x = [n] + l", "-print((C_Make_a_Rectangle(x)))", "+N = int(eval(input()))", "+A = [int(i) for i in input().split()]", "+print((c_make_a_rectangle(N, A)))" ]
false
0.04617
0.04166
1.108242
[ "s856631734", "s530246848" ]
u591295155
p03417
python
s523327902
s047731773
20
17
3,316
2,940
Accepted
Accepted
15
N, M = list(map(int, input().split())) print((abs(N-2)*abs(M-2)))
N,M= list(map(int,input().split())) print((abs((N-2)*(M-2))))
2
2
58
54
N, M = list(map(int, input().split())) print((abs(N - 2) * abs(M - 2)))
N, M = list(map(int, input().split())) print((abs((N - 2) * (M - 2))))
false
0
[ "-print((abs(N - 2) * abs(M - 2)))", "+print((abs((N - 2) * (M - 2))))" ]
false
0.038356
0.085265
0.449843
[ "s523327902", "s047731773" ]
u893063840
p02697
python
s309131214
s593192078
95
76
9,284
9,228
Accepted
Accepted
20
n, m = list(map(int, input().split())) l = m // 2 * 2 + 1 for i in range(1, l + 1): if i < l - i + 1: print((i, l - i + 1)) r = (m + 1) // 2 * 2 + l for i in range(l + 1, r + 1): if i < r - i + l + 1: print((i, r - i + l + 1))
n, m = list(map(int, input().split())) odd = (m + 1) // 2 even = m - odd l = 1 r = 2 * odd while l < r: print((l, r)) l += 1 r -= 1 l = n - 2 * even r = n while l < r: print((l, r)) l += 1 r -= 1
11
18
253
230
n, m = list(map(int, input().split())) l = m // 2 * 2 + 1 for i in range(1, l + 1): if i < l - i + 1: print((i, l - i + 1)) r = (m + 1) // 2 * 2 + l for i in range(l + 1, r + 1): if i < r - i + l + 1: print((i, r - i + l + 1))
n, m = list(map(int, input().split())) odd = (m + 1) // 2 even = m - odd l = 1 r = 2 * odd while l < r: print((l, r)) l += 1 r -= 1 l = n - 2 * even r = n while l < r: print((l, r)) l += 1 r -= 1
false
38.888889
[ "-l = m // 2 * 2 + 1", "-for i in range(1, l + 1):", "- if i < l - i + 1:", "- print((i, l - i + 1))", "-r = (m + 1) // 2 * 2 + l", "-for i in range(l + 1, r + 1):", "- if i < r - i + l + 1:", "- print((i, r - i + l + 1))", "+odd = (m + 1) // 2", "+even = m - odd", "+l = 1", "+r = 2 * odd", "+while l < r:", "+ print((l, r))", "+ l += 1", "+ r -= 1", "+l = n - 2 * even", "+r = n", "+while l < r:", "+ print((l, r))", "+ l += 1", "+ r -= 1" ]
false
0.042642
0.04447
0.9589
[ "s309131214", "s593192078" ]
u813098295
p03475
python
s175874171
s074170946
128
90
2,692
2,692
Accepted
Accepted
29.69
# coding: utf-8 import math N = int(input()) CSF = [list(map(float, input().split())) for _ in range(N-1)] for i in range(N-1): ans = CSF[i][0] + CSF[i][1] for j in range(i+1, N-1): s, t, u = CSF[j][0], CSF[j][1], CSF[j][2] if t < ans: n = int(math.ceil((ans - t) / u)) ans = int(s + t + u * n) else: ans = s + t print(int(ans)) print(0)
import math N = int(input()) CSF = [list(map(float, input().split())) for _ in range(N-1)] for i in range(N-1): ans = CSF[i][0] + CSF[i][1] for j in range(i+1, N-1): C, S, F = CSF[j][0], CSF[j][1], CSF[j][2] if S < ans: n = math.ceil((ans - S) / F) ans = C + S + F * n else: ans = C + S print(int(ans)) print(0)
19
18
431
405
# coding: utf-8 import math N = int(input()) CSF = [list(map(float, input().split())) for _ in range(N - 1)] for i in range(N - 1): ans = CSF[i][0] + CSF[i][1] for j in range(i + 1, N - 1): s, t, u = CSF[j][0], CSF[j][1], CSF[j][2] if t < ans: n = int(math.ceil((ans - t) / u)) ans = int(s + t + u * n) else: ans = s + t print(int(ans)) print(0)
import math N = int(input()) CSF = [list(map(float, input().split())) for _ in range(N - 1)] for i in range(N - 1): ans = CSF[i][0] + CSF[i][1] for j in range(i + 1, N - 1): C, S, F = CSF[j][0], CSF[j][1], CSF[j][2] if S < ans: n = math.ceil((ans - S) / F) ans = C + S + F * n else: ans = C + S print(int(ans)) print(0)
false
5.263158
[ "-# coding: utf-8", "- s, t, u = CSF[j][0], CSF[j][1], CSF[j][2]", "- if t < ans:", "- n = int(math.ceil((ans - t) / u))", "- ans = int(s + t + u * n)", "+ C, S, F = CSF[j][0], CSF[j][1], CSF[j][2]", "+ if S < ans:", "+ n = math.ceil((ans - S) / F)", "+ ans = C + S + F * n", "- ans = s + t", "+ ans = C + S" ]
false
0.050459
0.038352
1.315683
[ "s175874171", "s074170946" ]
u196746947
p02727
python
s578143325
s085189629
1,842
262
23,328
23,328
Accepted
Accepted
85.78
x,y,a,b,c=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) A.sort(reverse=True) A.sort() B.sort() C.sort(reverse=True) A=A[a-x:] B=B[b-y:] i=0 j=0 k=0 lea=len(A) leb=len(B) while(True): if len(C)<1: break if i<lea and j<leb: if A[i]>B[j]: if B[j]<C[0]: B[j]=C.pop(0) j+=1 else: break else: if A[i]<C[0]: A[i]=C.pop(0) i+=1 else: break elif i<lea and j>=leb: if A[i]<C[0]: A[i]=C.pop(0) i+=1 else: break elif i>=lea and j<leb: if B[j]<C[0]: B[j]=C.pop(0) j+=1 else: break else: break sum=0 for s in range(len(A)): sum+=A[s] for t in range(len(B)): sum+=B[t] print(sum)
x,y,a,b,c=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) A.sort(reverse=True) A.sort() B.sort() A=A[a-x:] B=B[b-y:] D=A+B+C D.sort(reverse=True) sum=0 for i in range(x+y): sum+=D[i] print(sum)
57
16
1,057
290
x, y, a, b, c = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) A.sort() B.sort() C.sort(reverse=True) A = A[a - x :] B = B[b - y :] i = 0 j = 0 k = 0 lea = len(A) leb = len(B) while True: if len(C) < 1: break if i < lea and j < leb: if A[i] > B[j]: if B[j] < C[0]: B[j] = C.pop(0) j += 1 else: break else: if A[i] < C[0]: A[i] = C.pop(0) i += 1 else: break elif i < lea and j >= leb: if A[i] < C[0]: A[i] = C.pop(0) i += 1 else: break elif i >= lea and j < leb: if B[j] < C[0]: B[j] = C.pop(0) j += 1 else: break else: break sum = 0 for s in range(len(A)): sum += A[s] for t in range(len(B)): sum += B[t] print(sum)
x, y, a, b, c = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) A.sort() B.sort() A = A[a - x :] B = B[b - y :] D = A + B + C D.sort(reverse=True) sum = 0 for i in range(x + y): sum += D[i] print(sum)
false
71.929825
[ "-C.sort(reverse=True)", "-i = 0", "-j = 0", "-k = 0", "-lea = len(A)", "-leb = len(B)", "-while True:", "- if len(C) < 1:", "- break", "- if i < lea and j < leb:", "- if A[i] > B[j]:", "- if B[j] < C[0]:", "- B[j] = C.pop(0)", "- j += 1", "- else:", "- break", "- else:", "- if A[i] < C[0]:", "- A[i] = C.pop(0)", "- i += 1", "- else:", "- break", "- elif i < lea and j >= leb:", "- if A[i] < C[0]:", "- A[i] = C.pop(0)", "- i += 1", "- else:", "- break", "- elif i >= lea and j < leb:", "- if B[j] < C[0]:", "- B[j] = C.pop(0)", "- j += 1", "- else:", "- break", "- else:", "- break", "+D = A + B + C", "+D.sort(reverse=True)", "-for s in range(len(A)):", "- sum += A[s]", "-for t in range(len(B)):", "- sum += B[t]", "+for i in range(x + y):", "+ sum += D[i]" ]
false
0.053941
0.034815
1.549348
[ "s578143325", "s085189629" ]
u211160392
p03013
python
s282539367
s500831686
657
230
460,020
7,668
Accepted
Accepted
64.99
N,M = list(map(int,input().split())) a = list(int(eval(input()))for i in range(M)) a= [-1]+a+[N+1] r = [] for i in range(M+1): r.append(a[i+1]-a[i]-1) fi = [0,1,1] for i in range(max(r)): fi.append(fi[-1]+fi[-2]) ans = 1 for i in r: ans = (ans*fi[i])%(10**9+7) print(ans)
MOD = 10**9+7 N,M = list(map(int,input().split())) DP = [0]*(N+3) DP[0] = 1 state = [1]*(N+3) for _ in range(M): i = int(eval(input())) state[i] = 0 for i in range(N): for j in range(1,3): if state[j+i]: DP[j+i] += DP[i] DP[j+i] %= MOD print((DP[N]))
13
16
283
298
N, M = list(map(int, input().split())) a = list(int(eval(input())) for i in range(M)) a = [-1] + a + [N + 1] r = [] for i in range(M + 1): r.append(a[i + 1] - a[i] - 1) fi = [0, 1, 1] for i in range(max(r)): fi.append(fi[-1] + fi[-2]) ans = 1 for i in r: ans = (ans * fi[i]) % (10**9 + 7) print(ans)
MOD = 10**9 + 7 N, M = list(map(int, input().split())) DP = [0] * (N + 3) DP[0] = 1 state = [1] * (N + 3) for _ in range(M): i = int(eval(input())) state[i] = 0 for i in range(N): for j in range(1, 3): if state[j + i]: DP[j + i] += DP[i] DP[j + i] %= MOD print((DP[N]))
false
18.75
[ "+MOD = 10**9 + 7", "-a = list(int(eval(input())) for i in range(M))", "-a = [-1] + a + [N + 1]", "-r = []", "-for i in range(M + 1):", "- r.append(a[i + 1] - a[i] - 1)", "-fi = [0, 1, 1]", "-for i in range(max(r)):", "- fi.append(fi[-1] + fi[-2])", "-ans = 1", "-for i in r:", "- ans = (ans * fi[i]) % (10**9 + 7)", "-print(ans)", "+DP = [0] * (N + 3)", "+DP[0] = 1", "+state = [1] * (N + 3)", "+for _ in range(M):", "+ i = int(eval(input()))", "+ state[i] = 0", "+for i in range(N):", "+ for j in range(1, 3):", "+ if state[j + i]:", "+ DP[j + i] += DP[i]", "+ DP[j + i] %= MOD", "+print((DP[N]))" ]
false
0.046448
0.036668
1.266727
[ "s282539367", "s500831686" ]
u163783894
p03309
python
s737815194
s038376003
515
159
120,596
40,656
Accepted
Accepted
69.13
import sys import numpy as np from numba import njit read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: list(map(int, readline().split())) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: list(map(int, read().split())) in_s = lambda: readline().rstrip().decode('utf-8') @njit('(i8,i8[:],i8,)', cache=True) def sad(N, A, x): s = 0 for i in range(N): s += abs(A[i] - (x + i + 1)) return s @njit('(i8,i8[:],)', cache=True) def solve(N, A): min_n = np.min(A) - 10**9 max_n = np.max(A) + 10**9 while max_n - min_n != 1: tn = (min_n + max_n) // 2 if sad(N, A, tn) < sad(N, A, tn + 1): max_n = tn else: min_n = tn return max_n def main(): N = in_n() A = np.array(readline().split(), np.int64) b = solve(N, A) print((sad(N, A, b))) if __name__ == '__main__': main()
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: list(map(int, readline().split())) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: list(map(int, read().split())) in_s = lambda: readline().rstrip().decode('utf-8') def solve(N, A): def sad(x): s = 0 for i in range(N): s += abs(A[i] - (x + i + 1)) return s min_n = np.min(A) - 10**9 max_n = np.max(A) + 10**9 while max_n - min_n != 1: tn = (min_n + max_n) // 2 if sad(tn) < sad(tn + 1): max_n = tn else: min_n = tn return sad(max_n) def main(): N = in_n() A = np.array(readline().split(), np.int64) print((solve(N, A))) def cc_export(): from numba.pycc import CC cc = CC('my_module') cc.export('solve', '(i8,i8[:],)')(solve) cc.compile() if __name__ == '__main__': import sys if sys.argv[-1] == 'ONLINE_JUDGE': cc_export() exit(0) from my_module import solve main()
49
56
991
1,149
import sys import numpy as np from numba import njit read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: list(map(int, readline().split())) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: list(map(int, read().split())) in_s = lambda: readline().rstrip().decode("utf-8") @njit("(i8,i8[:],i8,)", cache=True) def sad(N, A, x): s = 0 for i in range(N): s += abs(A[i] - (x + i + 1)) return s @njit("(i8,i8[:],)", cache=True) def solve(N, A): min_n = np.min(A) - 10**9 max_n = np.max(A) + 10**9 while max_n - min_n != 1: tn = (min_n + max_n) // 2 if sad(N, A, tn) < sad(N, A, tn + 1): max_n = tn else: min_n = tn return max_n def main(): N = in_n() A = np.array(readline().split(), np.int64) b = solve(N, A) print((sad(N, A, b))) if __name__ == "__main__": main()
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: list(map(int, readline().split())) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: list(map(int, read().split())) in_s = lambda: readline().rstrip().decode("utf-8") def solve(N, A): def sad(x): s = 0 for i in range(N): s += abs(A[i] - (x + i + 1)) return s min_n = np.min(A) - 10**9 max_n = np.max(A) + 10**9 while max_n - min_n != 1: tn = (min_n + max_n) // 2 if sad(tn) < sad(tn + 1): max_n = tn else: min_n = tn return sad(max_n) def main(): N = in_n() A = np.array(readline().split(), np.int64) print((solve(N, A))) def cc_export(): from numba.pycc import CC cc = CC("my_module") cc.export("solve", "(i8,i8[:],)")(solve) cc.compile() if __name__ == "__main__": import sys if sys.argv[-1] == "ONLINE_JUDGE": cc_export() exit(0) from my_module import solve main()
false
12.5
[ "-from numba import njit", "-@njit(\"(i8,i8[:],i8,)\", cache=True)", "-def sad(N, A, x):", "- s = 0", "- for i in range(N):", "- s += abs(A[i] - (x + i + 1))", "- return s", "+def solve(N, A):", "+ def sad(x):", "+ s = 0", "+ for i in range(N):", "+ s += abs(A[i] - (x + i + 1))", "+ return s", "-", "-@njit(\"(i8,i8[:],)\", cache=True)", "-def solve(N, A):", "- if sad(N, A, tn) < sad(N, A, tn + 1):", "+ if sad(tn) < sad(tn + 1):", "- return max_n", "+ return sad(max_n)", "- b = solve(N, A)", "- print((sad(N, A, b)))", "+ print((solve(N, A)))", "+", "+", "+def cc_export():", "+ from numba.pycc import CC", "+", "+ cc = CC(\"my_module\")", "+ cc.export(\"solve\", \"(i8,i8[:],)\")(solve)", "+ cc.compile()", "+ import sys", "+", "+ if sys.argv[-1] == \"ONLINE_JUDGE\":", "+ cc_export()", "+ exit(0)", "+ from my_module import solve", "+" ]
false
0.247095
0.43503
0.567995
[ "s737815194", "s038376003" ]
u797059905
p02647
python
s726938822
s827977096
1,657
1,095
143,600
133,924
Accepted
Accepted
33.92
from numba import jit import sys input = sys.stdin.readline @jit def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) for _ in range(K): B = [0]*(N+1) for i, a in enumerate(A): B[max(0, i-a)] += 1 B[min(N, i+a+1)] -= 1 for j in range(1, N): B[j] += B[j-1] if A == B[:-1]: A = B[:-1] break A = B[:-1] ans = ' '.join(list(map(str, A))) print(ans) if __name__ == '__main__': main()
from numba import jit import sys input = sys.stdin.readline @jit def solve(n, k, X): for _ in range(k): Y = [0]*(n+1) for i, x in enumerate(X): Y[max(0, i-x)] += 1 Y[min(n, i+x+1)] -= 1 for j in range(1, n): Y[j] += Y[j-1] if X == Y[:-1]: break X = Y[:-1] return X def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) ans = solve(N, K, A) print((*ans)) if __name__ == '__main__': main()
28
29
564
563
from numba import jit import sys input = sys.stdin.readline @jit def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) for _ in range(K): B = [0] * (N + 1) for i, a in enumerate(A): B[max(0, i - a)] += 1 B[min(N, i + a + 1)] -= 1 for j in range(1, N): B[j] += B[j - 1] if A == B[:-1]: A = B[:-1] break A = B[:-1] ans = " ".join(list(map(str, A))) print(ans) if __name__ == "__main__": main()
from numba import jit import sys input = sys.stdin.readline @jit def solve(n, k, X): for _ in range(k): Y = [0] * (n + 1) for i, x in enumerate(X): Y[max(0, i - x)] += 1 Y[min(n, i + x + 1)] -= 1 for j in range(1, n): Y[j] += Y[j - 1] if X == Y[:-1]: break X = Y[:-1] return X def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) ans = solve(N, K, A) print((*ans)) if __name__ == "__main__": main()
false
3.448276
[ "+def solve(n, k, X):", "+ for _ in range(k):", "+ Y = [0] * (n + 1)", "+ for i, x in enumerate(X):", "+ Y[max(0, i - x)] += 1", "+ Y[min(n, i + x + 1)] -= 1", "+ for j in range(1, n):", "+ Y[j] += Y[j - 1]", "+ if X == Y[:-1]:", "+ break", "+ X = Y[:-1]", "+ return X", "+", "+", "- for _ in range(K):", "- B = [0] * (N + 1)", "- for i, a in enumerate(A):", "- B[max(0, i - a)] += 1", "- B[min(N, i + a + 1)] -= 1", "- for j in range(1, N):", "- B[j] += B[j - 1]", "- if A == B[:-1]:", "- A = B[:-1]", "- break", "- A = B[:-1]", "- ans = \" \".join(list(map(str, A)))", "- print(ans)", "+ ans = solve(N, K, A)", "+ print((*ans))" ]
false
0.087846
0.039991
2.196663
[ "s726938822", "s827977096" ]
u333768710
p03633
python
s234420698
s040392017
39
17
5,432
3,060
Accepted
Accepted
56.41
import fractions def lcm(a, b): return a * b // fractions.gcd(a, b) def list_lcm(number_list): lcm_number = 1 for j in range(len(number_list)): lcm_number = lcm(lcm_number, number_list[j]) return lcm_number if __name__ == '__main__': number_count = int(eval(input())) numbers = [] for i in range(number_count): numbers.append(int(eval(input()))) print((int(list_lcm(numbers))))
def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) def list_lcm(number_list): lcm_number = 1 for j in range(len(number_list)): lcm_number = lcm(lcm_number, number_list[j]) return lcm_number if __name__ == '__main__': number_count = int(eval(input())) numbers = [] for i in range(number_count): numbers.append(int(eval(input()))) print((int(list_lcm(numbers))))
21
24
439
480
import fractions def lcm(a, b): return a * b // fractions.gcd(a, b) def list_lcm(number_list): lcm_number = 1 for j in range(len(number_list)): lcm_number = lcm(lcm_number, number_list[j]) return lcm_number if __name__ == "__main__": number_count = int(eval(input())) numbers = [] for i in range(number_count): numbers.append(int(eval(input()))) print((int(list_lcm(numbers))))
def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) def list_lcm(number_list): lcm_number = 1 for j in range(len(number_list)): lcm_number = lcm(lcm_number, number_list[j]) return lcm_number if __name__ == "__main__": number_count = int(eval(input())) numbers = [] for i in range(number_count): numbers.append(int(eval(input()))) print((int(list_lcm(numbers))))
false
12.5
[ "-import fractions", "+def gcd(a, b):", "+ while b:", "+ a, b = b, a % b", "+ return a", "- return a * b // fractions.gcd(a, b)", "+ return a * b // gcd(a, b)" ]
false
0.07137
0.118167
0.60397
[ "s234420698", "s040392017" ]
u912237403
p00022
python
s103419986
s239022934
580
40
4,448
4,204
Accepted
Accepted
93.1
n=eval(input()) while n: x=[] m=[] s=0 for i in range(n): a=eval(input()) x=[e+a for e in x]+[a] m.append(max(x)) print(max(m)) n=eval(input())
n=eval(input()) while n: x=-100000 m=x s=0 while n: a=eval(input()) x=max(x,0)+a m=max(m,x) n-=1 print(m) n=eval(input())
11
12
182
169
n = eval(input()) while n: x = [] m = [] s = 0 for i in range(n): a = eval(input()) x = [e + a for e in x] + [a] m.append(max(x)) print(max(m)) n = eval(input())
n = eval(input()) while n: x = -100000 m = x s = 0 while n: a = eval(input()) x = max(x, 0) + a m = max(m, x) n -= 1 print(m) n = eval(input())
false
8.333333
[ "- x = []", "- m = []", "+ x = -100000", "+ m = x", "- for i in range(n):", "+ while n:", "- x = [e + a for e in x] + [a]", "- m.append(max(x))", "- print(max(m))", "+ x = max(x, 0) + a", "+ m = max(m, x)", "+ n -= 1", "+ print(m)" ]
false
0.052954
0.037245
1.421781
[ "s103419986", "s239022934" ]
u278886389
p03560
python
s432397659
s545302195
376
204
13,036
42,864
Accepted
Accepted
45.74
from collections import deque K = int(eval(input())) D = [-1]*K Q = deque() Q.append([1,0]) while D[0] == -1: k,v = Q.popleft() D[k] = v j = (k*10)%K if D[j] == -1: Q.appendleft([j,v]) l = (k+1)%K if D[l] == -1: Q.append([l,v+1]) print((D[0]+1))
from collections import deque K = int(eval(input())) D = [9999]*K D[1] = 1 H = deque() H.append(1) while len(H) != 0: h = H.pop() if D[(h*10)%K] > D[h]: D[(h*10)%K] = D[h] H.append((h*10)%K) if D[(h+1)%K] > D[h] + 1: D[(h+1)%K] = D[h] + 1 H.appendleft((h+1)%K) print((D[0]))
17
17
295
328
from collections import deque K = int(eval(input())) D = [-1] * K Q = deque() Q.append([1, 0]) while D[0] == -1: k, v = Q.popleft() D[k] = v j = (k * 10) % K if D[j] == -1: Q.appendleft([j, v]) l = (k + 1) % K if D[l] == -1: Q.append([l, v + 1]) print((D[0] + 1))
from collections import deque K = int(eval(input())) D = [9999] * K D[1] = 1 H = deque() H.append(1) while len(H) != 0: h = H.pop() if D[(h * 10) % K] > D[h]: D[(h * 10) % K] = D[h] H.append((h * 10) % K) if D[(h + 1) % K] > D[h] + 1: D[(h + 1) % K] = D[h] + 1 H.appendleft((h + 1) % K) print((D[0]))
false
0
[ "-D = [-1] * K", "-Q = deque()", "-Q.append([1, 0])", "-while D[0] == -1:", "- k, v = Q.popleft()", "- D[k] = v", "- j = (k * 10) % K", "- if D[j] == -1:", "- Q.appendleft([j, v])", "- l = (k + 1) % K", "- if D[l] == -1:", "- Q.append([l, v + 1])", "-print((D[0] + 1))", "+D = [9999] * K", "+D[1] = 1", "+H = deque()", "+H.append(1)", "+while len(H) != 0:", "+ h = H.pop()", "+ if D[(h * 10) % K] > D[h]:", "+ D[(h * 10) % K] = D[h]", "+ H.append((h * 10) % K)", "+ if D[(h + 1) % K] > D[h] + 1:", "+ D[(h + 1) % K] = D[h] + 1", "+ H.appendleft((h + 1) % K)", "+print((D[0]))" ]
false
0.046582
0.038854
1.198912
[ "s432397659", "s545302195" ]
u347640436
p02793
python
s177295861
s997473435
1,627
124
11,272
82,764
Accepted
Accepted
92.38
from fractions import gcd from functools import reduce N = int(eval(input())) A = list(map(int, input().split())) m = 1000000007 lcm = reduce(lambda a, b: a * b // gcd(a, b), A) print((sum(lcm // a for a in A) % m))
# エラトステネスの篩, フェルマーの小定理 def make_prime_table(N): sieve = [0] * (N + 1) sieve[0] = -1 sieve[1] = -1 for i in range(2, N + 1): if sieve[i] != 0: continue sieve[i] = i for j in range(i * i, N + 1, i): if sieve[j] == 0: sieve[j] = i return sieve N = int(eval(input())) A = list(map(int, input().split())) m = 1000000007 sieve = make_prime_table(1000000) lcm_factors = {} for i in range(N): t = [] a = A[i] while a != 1: if len(t) != 0 and t[-1][0] == sieve[a]: t[-1][1] += 1 else: t.append([sieve[a], 1]) a //= sieve[a] for k, v in t: if k not in lcm_factors or lcm_factors[k] < v: lcm_factors[k] = v lcm = 1 for k in lcm_factors: for i in range(lcm_factors[k]): lcm *= k lcm %= m result = 0 for i in range(N): result += lcm * pow(A[i], m - 2, m) result %= m print(result)
10
47
220
1,011
from fractions import gcd from functools import reduce N = int(eval(input())) A = list(map(int, input().split())) m = 1000000007 lcm = reduce(lambda a, b: a * b // gcd(a, b), A) print((sum(lcm // a for a in A) % m))
# エラトステネスの篩, フェルマーの小定理 def make_prime_table(N): sieve = [0] * (N + 1) sieve[0] = -1 sieve[1] = -1 for i in range(2, N + 1): if sieve[i] != 0: continue sieve[i] = i for j in range(i * i, N + 1, i): if sieve[j] == 0: sieve[j] = i return sieve N = int(eval(input())) A = list(map(int, input().split())) m = 1000000007 sieve = make_prime_table(1000000) lcm_factors = {} for i in range(N): t = [] a = A[i] while a != 1: if len(t) != 0 and t[-1][0] == sieve[a]: t[-1][1] += 1 else: t.append([sieve[a], 1]) a //= sieve[a] for k, v in t: if k not in lcm_factors or lcm_factors[k] < v: lcm_factors[k] = v lcm = 1 for k in lcm_factors: for i in range(lcm_factors[k]): lcm *= k lcm %= m result = 0 for i in range(N): result += lcm * pow(A[i], m - 2, m) result %= m print(result)
false
78.723404
[ "-from fractions import gcd", "-from functools import reduce", "+# エラトステネスの篩, フェルマーの小定理", "+def make_prime_table(N):", "+ sieve = [0] * (N + 1)", "+ sieve[0] = -1", "+ sieve[1] = -1", "+ for i in range(2, N + 1):", "+ if sieve[i] != 0:", "+ continue", "+ sieve[i] = i", "+ for j in range(i * i, N + 1, i):", "+ if sieve[j] == 0:", "+ sieve[j] = i", "+ return sieve", "+", "-lcm = reduce(lambda a, b: a * b // gcd(a, b), A)", "-print((sum(lcm // a for a in A) % m))", "+sieve = make_prime_table(1000000)", "+lcm_factors = {}", "+for i in range(N):", "+ t = []", "+ a = A[i]", "+ while a != 1:", "+ if len(t) != 0 and t[-1][0] == sieve[a]:", "+ t[-1][1] += 1", "+ else:", "+ t.append([sieve[a], 1])", "+ a //= sieve[a]", "+ for k, v in t:", "+ if k not in lcm_factors or lcm_factors[k] < v:", "+ lcm_factors[k] = v", "+lcm = 1", "+for k in lcm_factors:", "+ for i in range(lcm_factors[k]):", "+ lcm *= k", "+ lcm %= m", "+result = 0", "+for i in range(N):", "+ result += lcm * pow(A[i], m - 2, m)", "+ result %= m", "+print(result)" ]
false
0.127694
0.378208
0.337629
[ "s177295861", "s997473435" ]
u141610915
p03420
python
s856572220
s245983827
177
73
38,896
73,592
Accepted
Accepted
58.76
import sys input = sys.stdin.readline N, K = list(map(int, input().split())) res = 0 for x in range(K + 1, N + 1): res += (N // x) * (x - K) + max(0, N % x - K + (K > 0)) #print(x, res) print(res)
import sys input = sys.stdin.readline N, K = list(map(int, input().split())) if K == 0: print((N ** 2)) exit(0) res = 0 for i in range(1, N + 1): if i <= K: continue res += i - K for j in range(i, N + 1, i): res += min(N + 1, j + i) - min(N + 1, j + K) print(res)
8
13
201
281
import sys input = sys.stdin.readline N, K = list(map(int, input().split())) res = 0 for x in range(K + 1, N + 1): res += (N // x) * (x - K) + max(0, N % x - K + (K > 0)) # print(x, res) print(res)
import sys input = sys.stdin.readline N, K = list(map(int, input().split())) if K == 0: print((N**2)) exit(0) res = 0 for i in range(1, N + 1): if i <= K: continue res += i - K for j in range(i, N + 1, i): res += min(N + 1, j + i) - min(N + 1, j + K) print(res)
false
38.461538
[ "+if K == 0:", "+ print((N**2))", "+ exit(0)", "-for x in range(K + 1, N + 1):", "- res += (N // x) * (x - K) + max(0, N % x - K + (K > 0))", "- # print(x, res)", "+for i in range(1, N + 1):", "+ if i <= K:", "+ continue", "+ res += i - K", "+ for j in range(i, N + 1, i):", "+ res += min(N + 1, j + i) - min(N + 1, j + K)" ]
false
0.03968
0.213123
0.186185
[ "s856572220", "s245983827" ]
u747602774
p02862
python
s725444175
s072581364
547
123
40,428
3,064
Accepted
Accepted
77.51
def modinv(a,m): return pow(a,m-2,m) x,y = list(map(int,input().split())) if (x+y)%3 != 0 or 2*y-x < 0 or 2*x-y < 0: print((0)) else: a = (2*y-x)//3 b = (2*x-y)//3 ans = 1 mod = 10**9+7 for i in range(1,a+1): ans = ans*(i+b)*modinv(i,mod)%mod print(ans)
#nCrをmodで割った余りO(r) def comb(n, r, mod): r = min(r, n-r) mol = 1 deno = 1 for i in range(1, r+1): mol = mol * (n-r+i) % mod deno = deno * i % mod ret = mol * pow(deno, mod-2, mod) % mod return ret x,y = list(map(int,input().split())) if (x+y)%3 != 0 or 2*y-x < 0 or 2*x-y < 0: print((0)) else: a = (2*y-x)//3 b = (2*x-y)//3 mod = 10**9+7 print((comb(a+b,a,mod)))
14
19
300
431
def modinv(a, m): return pow(a, m - 2, m) x, y = list(map(int, input().split())) if (x + y) % 3 != 0 or 2 * y - x < 0 or 2 * x - y < 0: print((0)) else: a = (2 * y - x) // 3 b = (2 * x - y) // 3 ans = 1 mod = 10**9 + 7 for i in range(1, a + 1): ans = ans * (i + b) * modinv(i, mod) % mod print(ans)
# nCrをmodで割った余りO(r) def comb(n, r, mod): r = min(r, n - r) mol = 1 deno = 1 for i in range(1, r + 1): mol = mol * (n - r + i) % mod deno = deno * i % mod ret = mol * pow(deno, mod - 2, mod) % mod return ret x, y = list(map(int, input().split())) if (x + y) % 3 != 0 or 2 * y - x < 0 or 2 * x - y < 0: print((0)) else: a = (2 * y - x) // 3 b = (2 * x - y) // 3 mod = 10**9 + 7 print((comb(a + b, a, mod)))
false
26.315789
[ "-def modinv(a, m):", "- return pow(a, m - 2, m)", "+# nCrをmodで割った余りO(r)", "+def comb(n, r, mod):", "+ r = min(r, n - r)", "+ mol = 1", "+ deno = 1", "+ for i in range(1, r + 1):", "+ mol = mol * (n - r + i) % mod", "+ deno = deno * i % mod", "+ ret = mol * pow(deno, mod - 2, mod) % mod", "+ return ret", "- ans = 1", "- for i in range(1, a + 1):", "- ans = ans * (i + b) * modinv(i, mod) % mod", "- print(ans)", "+ print((comb(a + b, a, mod)))" ]
false
0.681315
0.083726
8.13745
[ "s725444175", "s072581364" ]
u037430802
p03078
python
s166037734
s657380118
685
121
8,708
8,708
Accepted
Accepted
82.34
x,y,z,K = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) abc = [] for i in range (x): for j in range(y): for(k) in range(z): if (i+1)*(j+1)*(k+1) <= K: abc.append(a[i]+b[j]+c[k]) else: break abc.sort(reverse=True) for i in abc[:K]: print(i)
X,Y,Z,K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) ans = [] for i in range(X): if (i+1) > K: break for j in range(Y): if (i+1)*(j+1) > K: break for k in range(Z): if (i+1)*(j+1)*(k+1) > K: break ans.append(A[i]+B[j]+C[k]) ans.sort(reverse=True) for i in range(K): print((ans[i]))
22
27
523
533
x, y, z, K = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) abc = [] for i in range(x): for j in range(y): for k in range(z): if (i + 1) * (j + 1) * (k + 1) <= K: abc.append(a[i] + b[j] + c[k]) else: break abc.sort(reverse=True) for i in abc[:K]: print(i)
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) ans = [] for i in range(X): if (i + 1) > K: break for j in range(Y): if (i + 1) * (j + 1) > K: break for k in range(Z): if (i + 1) * (j + 1) * (k + 1) > K: break ans.append(A[i] + B[j] + C[k]) ans.sort(reverse=True) for i in range(K): print((ans[i]))
false
18.518519
[ "-x, y, z, K = list(map(int, input().split()))", "-a = list(map(int, input().split()))", "-b = list(map(int, input().split()))", "-c = list(map(int, input().split()))", "-a.sort(reverse=True)", "-b.sort(reverse=True)", "-c.sort(reverse=True)", "-abc = []", "-for i in range(x):", "- for j in range(y):", "- for k in range(z):", "- if (i + 1) * (j + 1) * (k + 1) <= K:", "- abc.append(a[i] + b[j] + c[k])", "- else:", "+X, Y, Z, K = list(map(int, input().split()))", "+A = list(map(int, input().split()))", "+B = list(map(int, input().split()))", "+C = list(map(int, input().split()))", "+A.sort(reverse=True)", "+B.sort(reverse=True)", "+C.sort(reverse=True)", "+ans = []", "+for i in range(X):", "+ if (i + 1) > K:", "+ break", "+ for j in range(Y):", "+ if (i + 1) * (j + 1) > K:", "+ break", "+ for k in range(Z):", "+ if (i + 1) * (j + 1) * (k + 1) > K:", "-abc.sort(reverse=True)", "-for i in abc[:K]:", "- print(i)", "+ ans.append(A[i] + B[j] + C[k])", "+ans.sort(reverse=True)", "+for i in range(K):", "+ print((ans[i]))" ]
false
0.03563
0.035993
0.989912
[ "s166037734", "s657380118" ]
u197078193
p03290
python
s910613103
s000517239
33
29
3,064
3,188
Accepted
Accepted
12.12
D,G = list(map(int,input().split())) G = G/100 P = []; C = [] for i in range(D): p,c = list(map(int,input().split())) P.append(p) C.append(c/100) m = 10**3 for k in range(2**D): R = list(range(D))[::-1] point = G prob = 0 for d in range(D): if k%(2**(d+1)) >= 2**d: p = P[d]; c = C[d] point -= (d+1)*p + c prob += p R.remove(d) for r in R: if point > 0: p = P[r] if point/(r+1) <= p: prob += -(-point//(r+1)) point = 0 else: point -= (r+1)*p + C[r] prob += p if m >= prob: m = prob print((int(m)))
D,G = list(map(int,input().split())) G = G/100 P = []; C = [] for i in range(D): p,c = list(map(int,input().split())) P.append(p) C.append(c/100) m = 10**3 for k in range(2**D): R = list(range(D))[::-1] point = G prob = 0 for d in range(D): if k & 1<<d: p = P[d]; c = C[d] point -= (d+1)*p + c prob += p R.remove(d) for r in R: if point > 0: p = P[r] if point/(r+1) <= p: prob += -(-point//(r+1)) point = 0 else: point -= (r+1)*p + C[r] prob += p if m >= prob: m = prob print((int(m)))
30
30
616
604
D, G = list(map(int, input().split())) G = G / 100 P = [] C = [] for i in range(D): p, c = list(map(int, input().split())) P.append(p) C.append(c / 100) m = 10**3 for k in range(2**D): R = list(range(D))[::-1] point = G prob = 0 for d in range(D): if k % (2 ** (d + 1)) >= 2**d: p = P[d] c = C[d] point -= (d + 1) * p + c prob += p R.remove(d) for r in R: if point > 0: p = P[r] if point / (r + 1) <= p: prob += -(-point // (r + 1)) point = 0 else: point -= (r + 1) * p + C[r] prob += p if m >= prob: m = prob print((int(m)))
D, G = list(map(int, input().split())) G = G / 100 P = [] C = [] for i in range(D): p, c = list(map(int, input().split())) P.append(p) C.append(c / 100) m = 10**3 for k in range(2**D): R = list(range(D))[::-1] point = G prob = 0 for d in range(D): if k & 1 << d: p = P[d] c = C[d] point -= (d + 1) * p + c prob += p R.remove(d) for r in R: if point > 0: p = P[r] if point / (r + 1) <= p: prob += -(-point // (r + 1)) point = 0 else: point -= (r + 1) * p + C[r] prob += p if m >= prob: m = prob print((int(m)))
false
0
[ "- if k % (2 ** (d + 1)) >= 2**d:", "+ if k & 1 << d:" ]
false
0.036837
0.036236
1.016572
[ "s910613103", "s000517239" ]
u408071652
p02706
python
s223687745
s109006205
65
25
68,204
9,540
Accepted
Accepted
61.54
n, m = list(map(int, input().split())) a = list(map(int, input().split())) ans = n- sum(a) if ans>=0: print(ans) else: print((-1))
N, M = list(map(int,input().split())) A =list(map(int,input().split())) print((max(-1,N-sum(A))))
9
4
141
87
n, m = list(map(int, input().split())) a = list(map(int, input().split())) ans = n - sum(a) if ans >= 0: print(ans) else: print((-1))
N, M = list(map(int, input().split())) A = list(map(int, input().split())) print((max(-1, N - sum(A))))
false
55.555556
[ "-n, m = list(map(int, input().split()))", "-a = list(map(int, input().split()))", "-ans = n - sum(a)", "-if ans >= 0:", "- print(ans)", "-else:", "- print((-1))", "+N, M = list(map(int, input().split()))", "+A = list(map(int, input().split()))", "+print((max(-1, N - sum(A))))" ]
false
0.04209
0.092765
0.453726
[ "s223687745", "s109006205" ]
u459150945
p02785
python
s085767655
s689224184
188
151
26,024
26,180
Accepted
Accepted
19.68
H, K = list(map(int, input().split())) Hn = list(map(int, input().split())) ans = 0 Hn.sort() try: for _ in range(K): Hn.pop(-1) except: print((0)) exit() ans = sum(Hn) print(ans)
H, K = list(map(int, input().split())) Hn = list(map(int, input().split())) ans = 0 Hn.sort() K = min(H, K) print((sum(Hn[:H-K])))
13
7
205
129
H, K = list(map(int, input().split())) Hn = list(map(int, input().split())) ans = 0 Hn.sort() try: for _ in range(K): Hn.pop(-1) except: print((0)) exit() ans = sum(Hn) print(ans)
H, K = list(map(int, input().split())) Hn = list(map(int, input().split())) ans = 0 Hn.sort() K = min(H, K) print((sum(Hn[: H - K])))
false
46.153846
[ "-try:", "- for _ in range(K):", "- Hn.pop(-1)", "-except:", "- print((0))", "- exit()", "-ans = sum(Hn)", "-print(ans)", "+K = min(H, K)", "+print((sum(Hn[: H - K])))" ]
false
0.045158
0.116438
0.38783
[ "s085767655", "s689224184" ]
u197457087
p02796
python
s331795915
s670922655
461
321
26,460
100,168
Accepted
Accepted
30.37
N = int(eval(input())) X = [] L = [] Y = [] for i in range(N): tx,tL = list(map(int,input().split())) X.append(tx) L.append(tL) Y.append((tx-tL,tx+tL)) Y.sort(key=lambda x : x[1]) select = 0 for i in range(N): if i == 0: temp = Y[i][1] #今の終わり select += 1 else: if Y[i][0] >= temp: #今の終わりより次の始まりの方が後ならおk temp = Y[i][1] select += 1 print(select)
N = int(eval(input())) X = [];L =[] for i in range(N): x,l = list(map(int,input().split())) X.append(x);L.append(l) #print(X,L) Y = [] for i in range(N): a = X[i]-L[i];b=X[i]+L[i] Y.append([a,b]) #print(Y) Y.sort(key=lambda x : x[1]) ans = 0 end = - float("inf") for i in range(N): if end > Y[i][0]: continue ans += 1 end = Y[i][1] print(ans)
24
20
395
368
N = int(eval(input())) X = [] L = [] Y = [] for i in range(N): tx, tL = list(map(int, input().split())) X.append(tx) L.append(tL) Y.append((tx - tL, tx + tL)) Y.sort(key=lambda x: x[1]) select = 0 for i in range(N): if i == 0: temp = Y[i][1] # 今の終わり select += 1 else: if Y[i][0] >= temp: # 今の終わりより次の始まりの方が後ならおk temp = Y[i][1] select += 1 print(select)
N = int(eval(input())) X = [] L = [] for i in range(N): x, l = list(map(int, input().split())) X.append(x) L.append(l) # print(X,L) Y = [] for i in range(N): a = X[i] - L[i] b = X[i] + L[i] Y.append([a, b]) # print(Y) Y.sort(key=lambda x: x[1]) ans = 0 end = -float("inf") for i in range(N): if end > Y[i][0]: continue ans += 1 end = Y[i][1] print(ans)
false
16.666667
[ "+for i in range(N):", "+ x, l = list(map(int, input().split()))", "+ X.append(x)", "+ L.append(l)", "+# print(X,L)", "- tx, tL = list(map(int, input().split()))", "- X.append(tx)", "- L.append(tL)", "- Y.append((tx - tL, tx + tL))", "+ a = X[i] - L[i]", "+ b = X[i] + L[i]", "+ Y.append([a, b])", "+# print(Y)", "-select = 0", "+ans = 0", "+end = -float(\"inf\")", "- if i == 0:", "- temp = Y[i][1] # 今の終わり", "- select += 1", "- else:", "- if Y[i][0] >= temp: # 今の終わりより次の始まりの方が後ならおk", "- temp = Y[i][1]", "- select += 1", "-print(select)", "+ if end > Y[i][0]:", "+ continue", "+ ans += 1", "+ end = Y[i][1]", "+print(ans)" ]
false
0.037479
0.037258
1.005916
[ "s331795915", "s670922655" ]
u562935282
p03111
python
s584807233
s725419344
363
326
3,064
3,064
Accepted
Accepted
10.19
inf = float('inf') def calc(mask): cost = -30 t = [0] * 3 for j in range(n): idx = (mask >> (2 * j)) & 3 if idx == 3: continue t[idx] += l[j] cost += 10 if 0 in t[:3]: return inf cost += sum(abs(tt - gg) for tt, gg in zip(t, goal)) return cost def dfs(cur, mask): # l[cur]をa,b,c,未使用のいずれかにあてがう # base case if cur == n: return calc(mask) res = inf for i in range(4): # i == 0,1,2 : a,b,cにあてがう / i == 3 : 未使用 res = min(res, dfs(cur + 1, mask | i << (2 * cur))) return res n, *goal = list(map(int, input().split())) l = [int(eval(input())) for _ in range(n)] print((dfs(0, 0)))
inf = float('inf') def calc(mask): t = [0] * 3 cnt = 0 for j in range(n): idx = (mask >> (2 * j)) & 3 if idx == 3: cnt += 1 continue t[idx] += l[j] if 0 in t: return inf return sum(abs(tt - gg) for tt, gg in zip(t, goal)) + (n - cnt - 3) * 10 def dfs(cur, mask): # l[cur]をa,b,c,未使用のいずれかにあてがう # base case if cur == n: return calc(mask) res = inf for i in range(4): # i == 0,1,2 : a,b,cにあてがう / i == 3 : 未使用 res = min(res, dfs(cur + 1, mask | i << (2 * cur))) return res n, *goal = list(map(int, input().split())) l = [int(eval(input())) for _ in range(n)] print((dfs(0, 0)))
37
37
719
730
inf = float("inf") def calc(mask): cost = -30 t = [0] * 3 for j in range(n): idx = (mask >> (2 * j)) & 3 if idx == 3: continue t[idx] += l[j] cost += 10 if 0 in t[:3]: return inf cost += sum(abs(tt - gg) for tt, gg in zip(t, goal)) return cost def dfs(cur, mask): # l[cur]をa,b,c,未使用のいずれかにあてがう # base case if cur == n: return calc(mask) res = inf for i in range(4): # i == 0,1,2 : a,b,cにあてがう / i == 3 : 未使用 res = min(res, dfs(cur + 1, mask | i << (2 * cur))) return res n, *goal = list(map(int, input().split())) l = [int(eval(input())) for _ in range(n)] print((dfs(0, 0)))
inf = float("inf") def calc(mask): t = [0] * 3 cnt = 0 for j in range(n): idx = (mask >> (2 * j)) & 3 if idx == 3: cnt += 1 continue t[idx] += l[j] if 0 in t: return inf return sum(abs(tt - gg) for tt, gg in zip(t, goal)) + (n - cnt - 3) * 10 def dfs(cur, mask): # l[cur]をa,b,c,未使用のいずれかにあてがう # base case if cur == n: return calc(mask) res = inf for i in range(4): # i == 0,1,2 : a,b,cにあてがう / i == 3 : 未使用 res = min(res, dfs(cur + 1, mask | i << (2 * cur))) return res n, *goal = list(map(int, input().split())) l = [int(eval(input())) for _ in range(n)] print((dfs(0, 0)))
false
0
[ "- cost = -30", "+ cnt = 0", "+ cnt += 1", "- cost += 10", "- if 0 in t[:3]:", "+ if 0 in t:", "- cost += sum(abs(tt - gg) for tt, gg in zip(t, goal))", "- return cost", "+ return sum(abs(tt - gg) for tt, gg in zip(t, goal)) + (n - cnt - 3) * 10" ]
false
0.192256
0.27122
0.708854
[ "s584807233", "s725419344" ]
u647999897
p02695
python
s782975117
s998295545
488
324
28,664
75,768
Accepted
Accepted
33.61
def solve(): N,M,Q = list(map(int,input().split())) req = [] for i in range(Q): a,b,c,d = list(map(int,input().split())) a -= 1 b -= 1 req.append([a,b,c,d]) res = [] dfs(list(), res,M,N) mx = 0 for p in res: point = 0 for a,b,c,d in req: if p[b] - p[a] == c: point += d mx = max(point, mx) print(mx) def dfs(now,res,M,N): if len(now) == N: res.append(now) return start = 1 if len(now) != 0: start = now[-1] if start > M: return for i in range(start,M+1): nxt = now[:] nxt.append(i) dfs(nxt, res,M,N) if __name__ == '__main__': solve()
def solve(): N,M,Q = list(map(int,input().split())) global info info = [] for _ in range(Q): a,b,c,d = list(map(int,input().split())) a -= 1 b -= 1 info.append([a,b,c,d]) print((dfs(list(),M,N))) def dfs(A,M,N): if len(A) == N: return calcPoint(A) res = 0 prev = A[-1] if len(A) > 0 else 1 for i in range(prev,M+1): A.append(i) res = max(res,dfs(A,M,N)) A.pop() return res def calcPoint(A): result = 0 for a,b,c,d in info: if A[b] - A[a] == c: result += d return result if __name__ == '__main__': solve()
41
34
774
693
def solve(): N, M, Q = list(map(int, input().split())) req = [] for i in range(Q): a, b, c, d = list(map(int, input().split())) a -= 1 b -= 1 req.append([a, b, c, d]) res = [] dfs(list(), res, M, N) mx = 0 for p in res: point = 0 for a, b, c, d in req: if p[b] - p[a] == c: point += d mx = max(point, mx) print(mx) def dfs(now, res, M, N): if len(now) == N: res.append(now) return start = 1 if len(now) != 0: start = now[-1] if start > M: return for i in range(start, M + 1): nxt = now[:] nxt.append(i) dfs(nxt, res, M, N) if __name__ == "__main__": solve()
def solve(): N, M, Q = list(map(int, input().split())) global info info = [] for _ in range(Q): a, b, c, d = list(map(int, input().split())) a -= 1 b -= 1 info.append([a, b, c, d]) print((dfs(list(), M, N))) def dfs(A, M, N): if len(A) == N: return calcPoint(A) res = 0 prev = A[-1] if len(A) > 0 else 1 for i in range(prev, M + 1): A.append(i) res = max(res, dfs(A, M, N)) A.pop() return res def calcPoint(A): result = 0 for a, b, c, d in info: if A[b] - A[a] == c: result += d return result if __name__ == "__main__": solve()
false
17.073171
[ "- req = []", "- for i in range(Q):", "+ global info", "+ info = []", "+ for _ in range(Q):", "- req.append([a, b, c, d])", "- res = []", "- dfs(list(), res, M, N)", "- mx = 0", "- for p in res:", "- point = 0", "- for a, b, c, d in req:", "- if p[b] - p[a] == c:", "- point += d", "- mx = max(point, mx)", "- print(mx)", "+ info.append([a, b, c, d])", "+ print((dfs(list(), M, N)))", "-def dfs(now, res, M, N):", "- if len(now) == N:", "- res.append(now)", "- return", "- start = 1", "- if len(now) != 0:", "- start = now[-1]", "- if start > M:", "- return", "- for i in range(start, M + 1):", "- nxt = now[:]", "- nxt.append(i)", "- dfs(nxt, res, M, N)", "+def dfs(A, M, N):", "+ if len(A) == N:", "+ return calcPoint(A)", "+ res = 0", "+ prev = A[-1] if len(A) > 0 else 1", "+ for i in range(prev, M + 1):", "+ A.append(i)", "+ res = max(res, dfs(A, M, N))", "+ A.pop()", "+ return res", "+", "+", "+def calcPoint(A):", "+ result = 0", "+ for a, b, c, d in info:", "+ if A[b] - A[a] == c:", "+ result += d", "+ return result" ]
false
0.082999
0.057965
1.431889
[ "s782975117", "s998295545" ]
u312025627
p02580
python
s109277054
s916262027
662
586
177,564
170,900
Accepted
Accepted
11.48
def main(): H, W, M = (int(i) for i in input().split()) hc = [0]*(H+1) wc = [0]*(W+1) maps = set() for _ in range(M): h, w = (int(i) for i in input().split()) hc[h] += 1 wc[w] += 1 maps.add((h, w)) mah = max(hc) maw = max(wc) ans = mah+maw hmaps = [] wmaps = [] for i, h in enumerate(hc): if mah == h: hmaps.append(i) for i, w in enumerate(wc): if maw == w: wmaps.append(i) for h in hmaps: for w in wmaps: if (h, w) not in maps: print(ans) return else: print((ans-1)) if __name__ == '__main__': main()
def main(): H, W, M = (int(i) for i in input().split()) hc = [0]*(H+1) wc = [0]*(W+1) maps = set() for _ in range(M): h, w = (int(i) for i in input().split()) hc[h] += 1 wc[w] += 1 maps.add((h, w)) mah = max(hc) maw = max(wc) ans = mah+maw hmaps = set() wmaps = set() for i, h in enumerate(hc): if mah == h: hmaps.add(i) for i, w in enumerate(wc): if maw == w: wmaps.add(i) for h in hmaps: for w in wmaps: if (h, w) not in maps: print(ans) return else: print((ans-1)) if __name__ == '__main__': main()
33
33
727
727
def main(): H, W, M = (int(i) for i in input().split()) hc = [0] * (H + 1) wc = [0] * (W + 1) maps = set() for _ in range(M): h, w = (int(i) for i in input().split()) hc[h] += 1 wc[w] += 1 maps.add((h, w)) mah = max(hc) maw = max(wc) ans = mah + maw hmaps = [] wmaps = [] for i, h in enumerate(hc): if mah == h: hmaps.append(i) for i, w in enumerate(wc): if maw == w: wmaps.append(i) for h in hmaps: for w in wmaps: if (h, w) not in maps: print(ans) return else: print((ans - 1)) if __name__ == "__main__": main()
def main(): H, W, M = (int(i) for i in input().split()) hc = [0] * (H + 1) wc = [0] * (W + 1) maps = set() for _ in range(M): h, w = (int(i) for i in input().split()) hc[h] += 1 wc[w] += 1 maps.add((h, w)) mah = max(hc) maw = max(wc) ans = mah + maw hmaps = set() wmaps = set() for i, h in enumerate(hc): if mah == h: hmaps.add(i) for i, w in enumerate(wc): if maw == w: wmaps.add(i) for h in hmaps: for w in wmaps: if (h, w) not in maps: print(ans) return else: print((ans - 1)) if __name__ == "__main__": main()
false
0
[ "- hmaps = []", "- wmaps = []", "+ hmaps = set()", "+ wmaps = set()", "- hmaps.append(i)", "+ hmaps.add(i)", "- wmaps.append(i)", "+ wmaps.add(i)" ]
false
0.035361
0.04101
0.862273
[ "s109277054", "s916262027" ]
u227082700
p03040
python
s490860439
s712453546
1,131
996
67,792
56,768
Accepted
Accepted
11.94
from heapq import heappop,heappush q=int(eval(input())) queries=[list(map(int,input().split()))for _ in range(q)] l=[] r=[] ans=0 queonecount=0 mid=-1 for query in queries: if query[0]==1: queonecount+=1 _,a,b=query ans+=b heappush(l,-a) heappush(r,a) midl=-heappop(l) midr=heappop(r) ans+=abs(midl-midr) heappush(l,-midr) heappush(r,midl) if query[0]==2: minind=-heappop(l) print((minind,ans)) heappush(l,-minind)
from heapq import heappop,heappush q=int(eval(input())) queries=[list(map(int,input().split()))for _ in range(q)] l=[] r=[] ans=0 quecount=0 for query in queries: if query[0]==1: quecount+=1 _,a,b=query ans+=b if quecount==1: mid=a elif quecount%2==1: if a<-l[0]: mid=-heappop(l) heappush(l,-a) elif r[0]<a: mid=heappop(r) heappush(r,a) else: mid=a ans+=abs(a-mid) else: ans+=abs(a-mid) heappush(l,-min(a,mid)) heappush(r,max(a,mid)) if query[0]==2: if quecount%2==1: ansind=mid else: ansind=-l[0] print((ansind,ans))
24
34
485
682
from heapq import heappop, heappush q = int(eval(input())) queries = [list(map(int, input().split())) for _ in range(q)] l = [] r = [] ans = 0 queonecount = 0 mid = -1 for query in queries: if query[0] == 1: queonecount += 1 _, a, b = query ans += b heappush(l, -a) heappush(r, a) midl = -heappop(l) midr = heappop(r) ans += abs(midl - midr) heappush(l, -midr) heappush(r, midl) if query[0] == 2: minind = -heappop(l) print((minind, ans)) heappush(l, -minind)
from heapq import heappop, heappush q = int(eval(input())) queries = [list(map(int, input().split())) for _ in range(q)] l = [] r = [] ans = 0 quecount = 0 for query in queries: if query[0] == 1: quecount += 1 _, a, b = query ans += b if quecount == 1: mid = a elif quecount % 2 == 1: if a < -l[0]: mid = -heappop(l) heappush(l, -a) elif r[0] < a: mid = heappop(r) heappush(r, a) else: mid = a ans += abs(a - mid) else: ans += abs(a - mid) heappush(l, -min(a, mid)) heappush(r, max(a, mid)) if query[0] == 2: if quecount % 2 == 1: ansind = mid else: ansind = -l[0] print((ansind, ans))
false
29.411765
[ "-queonecount = 0", "-mid = -1", "+quecount = 0", "- queonecount += 1", "+ quecount += 1", "- heappush(l, -a)", "- heappush(r, a)", "- midl = -heappop(l)", "- midr = heappop(r)", "- ans += abs(midl - midr)", "- heappush(l, -midr)", "- heappush(r, midl)", "+ if quecount == 1:", "+ mid = a", "+ elif quecount % 2 == 1:", "+ if a < -l[0]:", "+ mid = -heappop(l)", "+ heappush(l, -a)", "+ elif r[0] < a:", "+ mid = heappop(r)", "+ heappush(r, a)", "+ else:", "+ mid = a", "+ ans += abs(a - mid)", "+ else:", "+ ans += abs(a - mid)", "+ heappush(l, -min(a, mid))", "+ heappush(r, max(a, mid))", "- minind = -heappop(l)", "- print((minind, ans))", "- heappush(l, -minind)", "+ if quecount % 2 == 1:", "+ ansind = mid", "+ else:", "+ ansind = -l[0]", "+ print((ansind, ans))" ]
false
0.052005
0.119213
0.436231
[ "s490860439", "s712453546" ]
u806976856
p02573
python
s476581107
s598030631
469
286
79,868
79,672
Accepted
Accepted
39.02
import sys sys.setrecursionlimit(10**9) n,m=list(map(int,input().split())) root=[-1]*(n+1) def r(x): if root[x]<0: return x else: root[x]=r(root[x]) return root[x] def unite(x,y): x=r(x) y=r(y) if x==y: return if x>y: x,y=y,x root[x]+=root[y] root[y]=x def size(x): x=r(x) return -root[x] for i in range(m): x,y=list(map(int,input().split())) unite(x,y) ans=0 for i in range(n): ans=max(ans,size(i+1)) print(ans)
import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline n,m=list(map(int,input().split())) root=[-1]*(n+1) def r(x): if root[x]<0: return x else: root[x]=r(root[x]) return root[x] def unite(x,y): x=r(x) y=r(y) if x==y: return if x>y: x,y=y,x root[x]+=root[y] root[y]=x def size(x): x=r(x) return -root[x] for i in range(m): x,y=list(map(int,input().split())) unite(x,y) ans=0 for i in range(n): ans=max(ans,size(i+1)) print(ans)
31
34
525
557
import sys sys.setrecursionlimit(10**9) n, m = list(map(int, input().split())) root = [-1] * (n + 1) def r(x): if root[x] < 0: return x else: root[x] = r(root[x]) return root[x] def unite(x, y): x = r(x) y = r(y) if x == y: return if x > y: x, y = y, x root[x] += root[y] root[y] = x def size(x): x = r(x) return -root[x] for i in range(m): x, y = list(map(int, input().split())) unite(x, y) ans = 0 for i in range(n): ans = max(ans, size(i + 1)) print(ans)
import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline n, m = list(map(int, input().split())) root = [-1] * (n + 1) def r(x): if root[x] < 0: return x else: root[x] = r(root[x]) return root[x] def unite(x, y): x = r(x) y = r(y) if x == y: return if x > y: x, y = y, x root[x] += root[y] root[y] = x def size(x): x = r(x) return -root[x] for i in range(m): x, y = list(map(int, input().split())) unite(x, y) ans = 0 for i in range(n): ans = max(ans, size(i + 1)) print(ans)
false
8.823529
[ "+input = sys.stdin.readline" ]
false
0.036913
0.040609
0.90898
[ "s476581107", "s598030631" ]
u660912567
p00767
python
s505912149
s547297270
120
80
8,956
9,060
Accepted
Accepted
33.33
l = [] for i in range(1,151): for j in range(1,151): if i==j or i>j: continue l += [[i**2+j**2,i,j]] l = sorted(l) while True: h,w = map(int,input().split()) if w==h==0: break i = l.index([w**2+h**2,h,w])+1 print(*l[i][1:],sep=' ')
l = [[i**2+j**2,i,j] for j in range(1,151) for i in range(1,151) if i!=j and i<j] l = sorted(l) while True: h,w = map(int,input().split()) if w==h==0: break i = l.index([w**2+h**2,h,w])+1 print(*l[i][1:],sep=' ')
11
7
277
234
l = [] for i in range(1, 151): for j in range(1, 151): if i == j or i > j: continue l += [[i**2 + j**2, i, j]] l = sorted(l) while True: h, w = map(int, input().split()) if w == h == 0: break i = l.index([w**2 + h**2, h, w]) + 1 print(*l[i][1:], sep=" ")
l = [ [i**2 + j**2, i, j] for j in range(1, 151) for i in range(1, 151) if i != j and i < j ] l = sorted(l) while True: h, w = map(int, input().split()) if w == h == 0: break i = l.index([w**2 + h**2, h, w]) + 1 print(*l[i][1:], sep=" ")
false
36.363636
[ "-l = []", "-for i in range(1, 151):", "- for j in range(1, 151):", "- if i == j or i > j:", "- continue", "- l += [[i**2 + j**2, i, j]]", "+l = [", "+ [i**2 + j**2, i, j]", "+ for j in range(1, 151)", "+ for i in range(1, 151)", "+ if i != j and i < j", "+]" ]
false
0.0874
0.079849
1.094562
[ "s505912149", "s547297270" ]
u349091349
p03048
python
s854287471
s405938900
406
198
40,684
67,552
Accepted
Accepted
51.23
r,g,b,N=list(map(int,input().split())) c=0 for i in range(N//r+1): for j in range(N//g + 1): t = (N-i*r-j*g) if t%b ==0 and t>=0: #print(i,j,t//b) c+=1 print(c)
*s,n=list(map(int,input().split())) s.sort() c=0 for i in range(n//s[2]+1): for j in range(n//s[1]+1): if (n-s[2]*i-s[1]*j)%s[0] == 0 and 0<=(n-s[2]*i-s[1]*j): #print(i,j,n-s[2]*i-s[1]*j) c+=1 print(c)
9
9
206
239
r, g, b, N = list(map(int, input().split())) c = 0 for i in range(N // r + 1): for j in range(N // g + 1): t = N - i * r - j * g if t % b == 0 and t >= 0: # print(i,j,t//b) c += 1 print(c)
*s, n = list(map(int, input().split())) s.sort() c = 0 for i in range(n // s[2] + 1): for j in range(n // s[1] + 1): if (n - s[2] * i - s[1] * j) % s[0] == 0 and 0 <= (n - s[2] * i - s[1] * j): # print(i,j,n-s[2]*i-s[1]*j) c += 1 print(c)
false
0
[ "-r, g, b, N = list(map(int, input().split()))", "+*s, n = list(map(int, input().split()))", "+s.sort()", "-for i in range(N // r + 1):", "- for j in range(N // g + 1):", "- t = N - i * r - j * g", "- if t % b == 0 and t >= 0:", "- # print(i,j,t//b)", "+for i in range(n // s[2] + 1):", "+ for j in range(n // s[1] + 1):", "+ if (n - s[2] * i - s[1] * j) % s[0] == 0 and 0 <= (n - s[2] * i - s[1] * j):", "+ # print(i,j,n-s[2]*i-s[1]*j)" ]
false
0.141352
0.063617
2.221912
[ "s854287471", "s405938900" ]
u075836834
p00008
python
s385119052
s493045045
200
50
7,548
7,616
Accepted
Accepted
75
while True: try: n=int(eval(input())) cnt=0 for a in range(10): for b in range(10): for c in range(10): for d in range(10): if a+b+c+d==n: cnt+=1 print(cnt) except EOFError: break
while True: try: n=int(eval(input())) cnt=0 for a in range(10): for b in range(10): for c in range(10): d = n-(a+b+c) if 0<=d<=9: cnt+=1 print(cnt) except EOFError: break
14
14
224
213
while True: try: n = int(eval(input())) cnt = 0 for a in range(10): for b in range(10): for c in range(10): for d in range(10): if a + b + c + d == n: cnt += 1 print(cnt) except EOFError: break
while True: try: n = int(eval(input())) cnt = 0 for a in range(10): for b in range(10): for c in range(10): d = n - (a + b + c) if 0 <= d <= 9: cnt += 1 print(cnt) except EOFError: break
false
0
[ "- for d in range(10):", "- if a + b + c + d == n:", "- cnt += 1", "+ d = n - (a + b + c)", "+ if 0 <= d <= 9:", "+ cnt += 1" ]
false
0.103391
0.041024
2.520252
[ "s385119052", "s493045045" ]
u525065967
p03329
python
s138868246
s036283075
452
366
6,900
7,076
Accepted
Accepted
19.03
coin = [1, 6,6**2,6**3,6**4,6**5,6**6, 9,9**2,9**3,9**4,9**5] n = int(eval(input())) inf = 10**9 dp = [inf]*(n+1) dp[0] = 0 for c in coin: for yen in range(c, n+1): dp[yen] = min(dp[yen], dp[yen-c] + 1) print((dp[n]))
n = int(eval(input())) dp = list(i for i in range(n+1)) def f(yen, p): c = p while yen >= c: dp[yen] = min(dp[yen], dp[yen-c] + 1) c *= p for yen in range(6, n+1): f(yen, 6) f(yen, 9) print((dp[n]))
11
13
232
237
coin = [1, 6, 6**2, 6**3, 6**4, 6**5, 6**6, 9, 9**2, 9**3, 9**4, 9**5] n = int(eval(input())) inf = 10**9 dp = [inf] * (n + 1) dp[0] = 0 for c in coin: for yen in range(c, n + 1): dp[yen] = min(dp[yen], dp[yen - c] + 1) print((dp[n]))
n = int(eval(input())) dp = list(i for i in range(n + 1)) def f(yen, p): c = p while yen >= c: dp[yen] = min(dp[yen], dp[yen - c] + 1) c *= p for yen in range(6, n + 1): f(yen, 6) f(yen, 9) print((dp[n]))
false
15.384615
[ "-coin = [1, 6, 6**2, 6**3, 6**4, 6**5, 6**6, 9, 9**2, 9**3, 9**4, 9**5]", "-inf = 10**9", "-dp = [inf] * (n + 1)", "-dp[0] = 0", "-for c in coin:", "- for yen in range(c, n + 1):", "+dp = list(i for i in range(n + 1))", "+", "+", "+def f(yen, p):", "+ c = p", "+ while yen >= c:", "+ c *= p", "+", "+", "+for yen in range(6, n + 1):", "+ f(yen, 6)", "+ f(yen, 9)" ]
false
0.342867
0.12004
2.856274
[ "s138868246", "s036283075" ]
u137226361
p02725
python
s989226544
s168166312
122
98
31,532
31,512
Accepted
Accepted
19.67
import sys k, n = list(map(int, sys.stdin.readline().split())) an = list(map(int, sys.stdin.readline().split())) dai = an[0]+k-an[-1] for i in range(1, n): dai = max(dai, an[i]-an[i-1]) print((k-dai))
import sys k, n = list(map(int, sys.stdin.readline().split())) an = list(map(int, sys.stdin.readline().split())) dai = an[0]+k-an[-1] for i in range(1, n): if an[i]-an[i-1]>dai: dai = an[i]-an[i-1] print((k-dai))
10
11
208
229
import sys k, n = list(map(int, sys.stdin.readline().split())) an = list(map(int, sys.stdin.readline().split())) dai = an[0] + k - an[-1] for i in range(1, n): dai = max(dai, an[i] - an[i - 1]) print((k - dai))
import sys k, n = list(map(int, sys.stdin.readline().split())) an = list(map(int, sys.stdin.readline().split())) dai = an[0] + k - an[-1] for i in range(1, n): if an[i] - an[i - 1] > dai: dai = an[i] - an[i - 1] print((k - dai))
false
9.090909
[ "- dai = max(dai, an[i] - an[i - 1])", "+ if an[i] - an[i - 1] > dai:", "+ dai = an[i] - an[i - 1]" ]
false
0.077428
0.045495
1.701908
[ "s989226544", "s168166312" ]
u912237403
p00018
python
s845315128
s357362930
20
10
4,188
4,188
Accepted
Accepted
50
x=sorted(map(int, input().split())) for e in x[::-1]: print(e, end=' ') print()
x=sorted(map(int,input().split()))[::-1] for e in x: print(e, end=' ') print()
4
4
79
78
x = sorted(map(int, input().split())) for e in x[::-1]: print(e, end=" ") print()
x = sorted(map(int, input().split()))[::-1] for e in x: print(e, end=" ") print()
false
0
[ "-x = sorted(map(int, input().split()))", "-for e in x[::-1]:", "+x = sorted(map(int, input().split()))[::-1]", "+for e in x:" ]
false
0.127849
0.120521
1.060799
[ "s845315128", "s357362930" ]
u368796742
p02585
python
s823932725
s281866912
961
668
74,320
68,928
Accepted
Accepted
30.49
n,k = list(map(int,input().split())) p = list(map(int,input().split())) used = [0]*n c = list(map(int,input().split())) ans = -float("INF") def calc(x): l = [] now = x score = 0 while used[now] == 0: used[now] = 1 l.append(c[now]) now = p[now]-1 S = sum(l) le = len(l) if S > 0 and k > le: score += (k//le-1)*S mod = k%le+le now = 0 for i in range(le): cal = 0 for j in range(mod): cal += l[(i+j)%le] now = max(now,cal) return score+now else: mod = min(le,k) now = -float("INF") for i in range(le): cal = 0 for j in range(mod): cal += l[(i+j)%le] now = max(now,cal) return score+now for i in range(n): if used[i] == 0: ans = max(ans,calc(i)) print(ans)
n,k = list(map(int,input().split())) p = list(map(int,input().split())) used = [0]*n c = list(map(int,input().split())) ans = -float("INF") def calc(x): l = [] now = x score = 0 while used[now] == 0: used[now] = 1 l.append(c[now]) now = p[now]-1 S = sum(l) le = len(l) if S > 0 and k > le: score += (k//le-1)*S mod = k%le now = 0 for i in range(le): cal = 0 for j in range(le): if j <= mod: now = max(now,cal+S) cal += l[(i+j)%le] now = max(now,cal) return score+now else: mod = min(le,k) now = -float("INF") for i in range(le): cal = 0 for j in range(mod): cal += l[(i+j)%le] now = max(now,cal) return score+now for i in range(n): if used[i] == 0: ans = max(ans,calc(i)) print(ans)
39
41
941
1,009
n, k = list(map(int, input().split())) p = list(map(int, input().split())) used = [0] * n c = list(map(int, input().split())) ans = -float("INF") def calc(x): l = [] now = x score = 0 while used[now] == 0: used[now] = 1 l.append(c[now]) now = p[now] - 1 S = sum(l) le = len(l) if S > 0 and k > le: score += (k // le - 1) * S mod = k % le + le now = 0 for i in range(le): cal = 0 for j in range(mod): cal += l[(i + j) % le] now = max(now, cal) return score + now else: mod = min(le, k) now = -float("INF") for i in range(le): cal = 0 for j in range(mod): cal += l[(i + j) % le] now = max(now, cal) return score + now for i in range(n): if used[i] == 0: ans = max(ans, calc(i)) print(ans)
n, k = list(map(int, input().split())) p = list(map(int, input().split())) used = [0] * n c = list(map(int, input().split())) ans = -float("INF") def calc(x): l = [] now = x score = 0 while used[now] == 0: used[now] = 1 l.append(c[now]) now = p[now] - 1 S = sum(l) le = len(l) if S > 0 and k > le: score += (k // le - 1) * S mod = k % le now = 0 for i in range(le): cal = 0 for j in range(le): if j <= mod: now = max(now, cal + S) cal += l[(i + j) % le] now = max(now, cal) return score + now else: mod = min(le, k) now = -float("INF") for i in range(le): cal = 0 for j in range(mod): cal += l[(i + j) % le] now = max(now, cal) return score + now for i in range(n): if used[i] == 0: ans = max(ans, calc(i)) print(ans)
false
4.878049
[ "- mod = k % le + le", "+ mod = k % le", "- for j in range(mod):", "+ for j in range(le):", "+ if j <= mod:", "+ now = max(now, cal + S)" ]
false
0.03741
0.037602
0.99491
[ "s823932725", "s281866912" ]
u336564899
p02659
python
s502854700
s175168143
27
23
10,040
9,136
Accepted
Accepted
14.81
#a, b = map(float, input().split()) a, b = input().split() from decimal import Decimal import math print((math.floor(int(a)*Decimal(b))))
#解放1 a, b = input().split() b = b.replace(".", "") print((int(a)*int(b)//100))
6
4
142
79
# a, b = map(float, input().split()) a, b = input().split() from decimal import Decimal import math print((math.floor(int(a) * Decimal(b))))
# 解放1 a, b = input().split() b = b.replace(".", "") print((int(a) * int(b) // 100))
false
33.333333
[ "-# a, b = map(float, input().split())", "+# 解放1", "-from decimal import Decimal", "-import math", "-", "-print((math.floor(int(a) * Decimal(b))))", "+b = b.replace(\".\", \"\")", "+print((int(a) * int(b) // 100))" ]
false
0.043724
0.042541
1.027808
[ "s502854700", "s175168143" ]
u028973125
p03681
python
s928158927
s449493511
175
72
38,384
9,144
Accepted
Accepted
58.86
import sys def permutation(n, x, mod=10**9+7): # nPx # 順列 # ex) permutaion(5, 2) = 20 tmp = 1 for i in range(n, n-x, -1): tmp = (tmp * i) % mod return tmp N, M = list(map(int, sys.stdin.readline().strip().split())) if abs(N - M) > 1: print((0)) elif abs(N - M) == 1: print((permutation(N, N) * permutation(M, M) % (10**9+7))) else: print((2 * permutation(N, N) * permutation(M, M) % (10**9+7)))
import sys import math mod = 10**9 + 7 N, M = list(map(int, sys.stdin.readline().split())) diff = abs(N - M) if diff > 1: print((0)) sys.exit() n_p = 1 for i in range(1, N+1): n_p *= i n_p %= mod m_p = 1 for i in range(1, M+1): m_p *= i m_p %= mod if diff == 0: print((2 * n_p * m_p % mod)) else: print((n_p * m_p % mod))
19
23
448
366
import sys def permutation(n, x, mod=10**9 + 7): # nPx # 順列 # ex) permutaion(5, 2) = 20 tmp = 1 for i in range(n, n - x, -1): tmp = (tmp * i) % mod return tmp N, M = list(map(int, sys.stdin.readline().strip().split())) if abs(N - M) > 1: print((0)) elif abs(N - M) == 1: print((permutation(N, N) * permutation(M, M) % (10**9 + 7))) else: print((2 * permutation(N, N) * permutation(M, M) % (10**9 + 7)))
import sys import math mod = 10**9 + 7 N, M = list(map(int, sys.stdin.readline().split())) diff = abs(N - M) if diff > 1: print((0)) sys.exit() n_p = 1 for i in range(1, N + 1): n_p *= i n_p %= mod m_p = 1 for i in range(1, M + 1): m_p *= i m_p %= mod if diff == 0: print((2 * n_p * m_p % mod)) else: print((n_p * m_p % mod))
false
17.391304
[ "+import math", "-", "-def permutation(n, x, mod=10**9 + 7):", "- # nPx", "- # 順列", "- # ex) permutaion(5, 2) = 20", "- tmp = 1", "- for i in range(n, n - x, -1):", "- tmp = (tmp * i) % mod", "- return tmp", "-", "-", "-N, M = list(map(int, sys.stdin.readline().strip().split()))", "-if abs(N - M) > 1:", "+mod = 10**9 + 7", "+N, M = list(map(int, sys.stdin.readline().split()))", "+diff = abs(N - M)", "+if diff > 1:", "-elif abs(N - M) == 1:", "- print((permutation(N, N) * permutation(M, M) % (10**9 + 7)))", "+ sys.exit()", "+n_p = 1", "+for i in range(1, N + 1):", "+ n_p *= i", "+ n_p %= mod", "+m_p = 1", "+for i in range(1, M + 1):", "+ m_p *= i", "+ m_p %= mod", "+if diff == 0:", "+ print((2 * n_p * m_p % mod))", "- print((2 * permutation(N, N) * permutation(M, M) % (10**9 + 7)))", "+ print((n_p * m_p % mod))" ]
false
0.087125
0.116542
0.747588
[ "s928158927", "s449493511" ]
u174158426
p02675
python
s475071092
s593143264
23
21
9,108
9,104
Accepted
Accepted
8.7
number = eval(input()) number = int(number) last_num = number % 10 last_num = str(last_num) if last_num == '3': print('bon') elif last_num in '0168': print('pon') else: print('hon')
number = eval(input()) last_num = number[-1] if last_num == '3': print('bon') elif last_num in '0168': print('pon') else: print('hon')
11
9
198
149
number = eval(input()) number = int(number) last_num = number % 10 last_num = str(last_num) if last_num == "3": print("bon") elif last_num in "0168": print("pon") else: print("hon")
number = eval(input()) last_num = number[-1] if last_num == "3": print("bon") elif last_num in "0168": print("pon") else: print("hon")
false
18.181818
[ "-number = int(number)", "-last_num = number % 10", "-last_num = str(last_num)", "+last_num = number[-1]" ]
false
0.045451
0.039114
1.162028
[ "s475071092", "s593143264" ]
u261103969
p02582
python
s754153995
s275557891
89
32
61,628
9,056
Accepted
Accepted
64.04
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): s = eval(input()) if s == "RRR": print((3)) elif "RR" in s: print((2)) elif "R" in s: print((1)) else: print((0)) if __name__ == '__main__': main()
s = eval(input()) ans = 0 for i in range(1, 4): p = "R" * i if p in s: ans = i print(ans)
23
9
339
110
import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): s = eval(input()) if s == "RRR": print((3)) elif "RR" in s: print((2)) elif "R" in s: print((1)) else: print((0)) if __name__ == "__main__": main()
s = eval(input()) ans = 0 for i in range(1, 4): p = "R" * i if p in s: ans = i print(ans)
false
60.869565
[ "-import sys", "-", "-readline = sys.stdin.readline", "-MOD = 10**9 + 7", "-INF = float(\"INF\")", "-sys.setrecursionlimit(10**5)", "-", "-", "-def main():", "- s = eval(input())", "- if s == \"RRR\":", "- print((3))", "- elif \"RR\" in s:", "- print((2))", "- elif \"R\" in s:", "- print((1))", "- else:", "- print((0))", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+s = eval(input())", "+ans = 0", "+for i in range(1, 4):", "+ p = \"R\" * i", "+ if p in s:", "+ ans = i", "+print(ans)" ]
false
0.035779
0.054354
0.658245
[ "s754153995", "s275557891" ]
u472696272
p02860
python
s188238553
s548527217
19
17
2,940
2,940
Accepted
Accepted
10.53
n = int(eval(input())) s = eval(input()) if n%2!=0: print('No') else: if s[0:int(n/2)] == s[int(n/2):n]: print('Yes') else: print('No')
n = int(eval(input())) s = list(eval(input())) if n%2!=0: print('No') else: s1 = s[0:n//2] s2 = s[n//2:n] if s1==s2: print('Yes') else: print('No')
10
8
147
151
n = int(eval(input())) s = eval(input()) if n % 2 != 0: print("No") else: if s[0 : int(n / 2)] == s[int(n / 2) : n]: print("Yes") else: print("No")
n = int(eval(input())) s = list(eval(input())) if n % 2 != 0: print("No") else: s1 = s[0 : n // 2] s2 = s[n // 2 : n] if s1 == s2: print("Yes") else: print("No")
false
20
[ "-s = eval(input())", "+s = list(eval(input()))", "- if s[0 : int(n / 2)] == s[int(n / 2) : n]:", "+ s1 = s[0 : n // 2]", "+ s2 = s[n // 2 : n]", "+ if s1 == s2:" ]
false
0.072599
0.072653
0.99926
[ "s188238553", "s548527217" ]
u596276291
p03472
python
s523432641
s234129864
637
314
62,808
12,852
Accepted
Accepted
50.71
import sys from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt, floor from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache, reduce from operator import xor from heapq import heappush, heappop INF = float("inf") sys.setrecursionlimit(10**7) # 4近傍(右, 下, 左, 上) dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0] def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W def ceil(a, b):return (a + b - 1) // b def solve(N, H, a_b): max_a = -1 for a, b in a_b: max_a = max(max_a, a) good_b = [] for a, b in a_b: if b >= max_a: good_b.append(b) ans = 0 for b in sorted(good_b, reverse=True): ans += 1 H -= b if H <= 0: return ans return ans + ceil(H, max_a) def main(): N, H = list(map(int, input().split())) l = [] for _ in range(N): a, b = list(map(int, input().split())) l.append((a, b)) print((solve(N, H, l))) if __name__ == '__main__': main()
#!/usr/bin/python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def solve(N, H, A, B): a_max = max(A) ans = 0 for b in sorted(B, reverse=True): if H <= 0: break if b > a_max: H -= b ans += 1 else: break if H > 0: ans += ceil(H, a_max) return ans def main(): N, H = list(map(int, input().split())) A, B = [], [] for _ in range(N): a, b = list(map(int, input().split())) A.append(a) B.append(b) print((solve(N, H, A, B))) if __name__ == '__main__': main()
52
54
1,226
1,170
import sys from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt, floor from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache, reduce from operator import xor from heapq import heappush, heappop INF = float("inf") sys.setrecursionlimit(10**7) # 4近傍(右, 下, 左, 上) dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0] def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def solve(N, H, a_b): max_a = -1 for a, b in a_b: max_a = max(max_a, a) good_b = [] for a, b in a_b: if b >= max_a: good_b.append(b) ans = 0 for b in sorted(good_b, reverse=True): ans += 1 H -= b if H <= 0: return ans return ans + ceil(H, max_a) def main(): N, H = list(map(int, input().split())) l = [] for _ in range(N): a, b = list(map(int, input().split())) l.append((a, b)) print((solve(N, H, l))) if __name__ == "__main__": main()
#!/usr/bin/python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def solve(N, H, A, B): a_max = max(A) ans = 0 for b in sorted(B, reverse=True): if H <= 0: break if b > a_max: H -= b ans += 1 else: break if H > 0: ans += ceil(H, a_max) return ans def main(): N, H = list(map(int, input().split())) A, B = [], [] for _ in range(N): a, b = list(map(int, input().split())) A.append(a) B.append(b) print((solve(N, H, A, B))) if __name__ == "__main__": main()
false
3.703704
[ "-import sys", "+#!/usr/bin/python3", "-from math import pi, sqrt, floor", "+from math import pi, sqrt", "-from functools import lru_cache, reduce", "-from operator import xor", "-from heapq import heappush, heappop", "+from functools import lru_cache", "+import sys", "+sys.setrecursionlimit(10000)", "-sys.setrecursionlimit(10**7)", "-# 4近傍(右, 下, 左, 上)", "-dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]", "+YES, Yes, yes, NO, No, no = \"YES\", \"Yes\", \"yes\", \"NO\", \"No\", \"no\"", "+dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]", "-def inside(y: int, x: int, H: int, W: int) -> bool:", "+def inside(y, x, H, W):", "-def solve(N, H, a_b):", "- max_a = -1", "- for a, b in a_b:", "- max_a = max(max_a, a)", "- good_b = []", "- for a, b in a_b:", "- if b >= max_a:", "- good_b.append(b)", "+def solve(N, H, A, B):", "+ a_max = max(A)", "- for b in sorted(good_b, reverse=True):", "- ans += 1", "- H -= b", "+ for b in sorted(B, reverse=True):", "- return ans", "- return ans + ceil(H, max_a)", "+ break", "+ if b > a_max:", "+ H -= b", "+ ans += 1", "+ else:", "+ break", "+ if H > 0:", "+ ans += ceil(H, a_max)", "+ return ans", "- l = []", "+ A, B = [], []", "- l.append((a, b))", "- print((solve(N, H, l)))", "+ A.append(a)", "+ B.append(b)", "+ print((solve(N, H, A, B)))" ]
false
0.042008
0.093942
0.447173
[ "s523432641", "s234129864" ]
u729939940
p04001
python
s546289815
s637414550
27
24
9,104
8,964
Accepted
Accepted
11.11
S=eval(input()) def dfs(s,i): if i==len(S)-1: return sum(map(int,s.split("+"))) return dfs(s+S[i+1],i+1)+dfs(s+"+"+S[i+1],i+1) print((dfs(S[0],0)))
S=eval(input()) def dfs(s,i): if i==len(S)-1: return sum(map(int,s.split("+"))) return dfs(s+S[i+1],i+1)+dfs(f"{s}+{S[i+1]}",i+1) print((dfs(S[0],0)))
6
6
152
155
S = eval(input()) def dfs(s, i): if i == len(S) - 1: return sum(map(int, s.split("+"))) return dfs(s + S[i + 1], i + 1) + dfs(s + "+" + S[i + 1], i + 1) print((dfs(S[0], 0)))
S = eval(input()) def dfs(s, i): if i == len(S) - 1: return sum(map(int, s.split("+"))) return dfs(s + S[i + 1], i + 1) + dfs(f"{s}+{S[i+1]}", i + 1) print((dfs(S[0], 0)))
false
0
[ "- return dfs(s + S[i + 1], i + 1) + dfs(s + \"+\" + S[i + 1], i + 1)", "+ return dfs(s + S[i + 1], i + 1) + dfs(f\"{s}+{S[i+1]}\", i + 1)" ]
false
0.118969
0.117941
1.008711
[ "s546289815", "s637414550" ]
u644907318
p03740
python
s267479121
s575187320
167
67
38,256
61,820
Accepted
Accepted
59.88
X,Y = list(map(int,input().split())) if abs(X-Y)>=2: print("Alice") else: print("Brown")
X,Y = list(map(int,input().split())) if abs(X-Y)>1: print("Alice") else: print("Brown")
5
5
94
89
X, Y = list(map(int, input().split())) if abs(X - Y) >= 2: print("Alice") else: print("Brown")
X, Y = list(map(int, input().split())) if abs(X - Y) > 1: print("Alice") else: print("Brown")
false
0
[ "-if abs(X - Y) >= 2:", "+if abs(X - Y) > 1:" ]
false
0.041915
0.102519
0.408852
[ "s267479121", "s575187320" ]
u645250356
p03208
python
s439358064
s575853115
182
162
9,592
9,584
Accepted
Accepted
10.99
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions 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,k = inpl() a = [inp() for _ in range(n)] a.sort() res = INF for i in range(n-k+1): res = min(res, a[i+k-1] - a[i]) print(res)
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify 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,k = inpl() a = [inp() for _ in range(n)] a.sort() res = INF for i in range(n-k+1): res = min(res, a[i+k-1] - a[i]) print(res)
16
17
453
499
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify import sys, bisect, math, itertools, fractions 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, k = inpl() a = [inp() for _ in range(n)] a.sort() res = INF for i in range(n - k + 1): res = min(res, a[i + k - 1] - a[i]) print(res)
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify 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, k = inpl() a = [inp() for _ in range(n)] a.sort() res = INF for i in range(n - k + 1): res = min(res, a[i + k - 1] - a[i]) print(res)
false
5.882353
[ "-import sys, bisect, math, itertools, fractions", "+from bisect import bisect_left, bisect_right", "+import sys, math, itertools, fractions, pprint" ]
false
0.094716
0.07654
1.237474
[ "s439358064", "s575853115" ]
u179169725
p03309
python
s427182260
s692951467
514
211
31,008
25,884
Accepted
Accepted
58.95
# https://atcoder.jp/contests/abc102/tasks/arc100_a import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_a_int(): return int(read()) class cumsum1d: def __init__(self, ls: list): ''' 1次元リストを受け取る ''' from itertools import accumulate self.ls_accum = [0] + list(accumulate(ls)) def total(self, i, j): # もとの配列lsにおける[i,j)の中合計 return self.ls_accum[j] - self.ls_accum[i] N = read_a_int() A = read_ints() if N == 1: print((0)) exit() B = [a - i for a, i in zip(A, list(range(1, N + 1)))] B.sort() # 絶対値を区切る境目はどこがよいか? B_cum = cumsum1d(B) ans = 10**15 for k in range(1, N): tmp_sum = -B_cum.total(0, k) + B_cum.total(k, N) add = min((2 * k - N) * B[k - 1], (2 * k - N) * B[k]) ans = min(ans, tmp_sum + add) print(ans) # 式ごちゃごちゃやったけど絶対楽な方法がある。 # 明日復習
# https://atcoder.jp/contests/abc102/tasks/arc100_a # Aの数列を前処理で加工し、順番に依存しない数列Bに加工する # abs(Bi-x)の和を最小化するxはBの中央値である。(立式しxで微分したのちKについて増減表を書いてみよ) # それを答えとすれば良い import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_a_int(): return int(read()) N = read_a_int() A = read_ints() B = [a - i for a, i in zip(A, list(range(1, N + 1)))] B.sort() x = B[N // 2] ans = 0 for b in B: ans += abs(x - b) print(ans)
46
28
929
486
# https://atcoder.jp/contests/abc102/tasks/arc100_a import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_a_int(): return int(read()) class cumsum1d: def __init__(self, ls: list): """ 1次元リストを受け取る """ from itertools import accumulate self.ls_accum = [0] + list(accumulate(ls)) def total(self, i, j): # もとの配列lsにおける[i,j)の中合計 return self.ls_accum[j] - self.ls_accum[i] N = read_a_int() A = read_ints() if N == 1: print((0)) exit() B = [a - i for a, i in zip(A, list(range(1, N + 1)))] B.sort() # 絶対値を区切る境目はどこがよいか? B_cum = cumsum1d(B) ans = 10**15 for k in range(1, N): tmp_sum = -B_cum.total(0, k) + B_cum.total(k, N) add = min((2 * k - N) * B[k - 1], (2 * k - N) * B[k]) ans = min(ans, tmp_sum + add) print(ans) # 式ごちゃごちゃやったけど絶対楽な方法がある。 # 明日復習
# https://atcoder.jp/contests/abc102/tasks/arc100_a # Aの数列を前処理で加工し、順番に依存しない数列Bに加工する # abs(Bi-x)の和を最小化するxはBの中央値である。(立式しxで微分したのちKについて増減表を書いてみよ) # それを答えとすれば良い import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_a_int(): return int(read()) N = read_a_int() A = read_ints() B = [a - i for a, i in zip(A, list(range(1, N + 1)))] B.sort() x = B[N // 2] ans = 0 for b in B: ans += abs(x - b) print(ans)
false
39.130435
[ "+# Aの数列を前処理で加工し、順番に依存しない数列Bに加工する", "+# abs(Bi-x)の和を最小化するxはBの中央値である。(立式しxで微分したのちKについて増減表を書いてみよ)", "+# それを答えとすれば良い", "-class cumsum1d:", "- def __init__(self, ls: list):", "- \"\"\"", "- 1次元リストを受け取る", "- \"\"\"", "- from itertools import accumulate", "-", "- self.ls_accum = [0] + list(accumulate(ls))", "-", "- def total(self, i, j):", "- # もとの配列lsにおける[i,j)の中合計", "- return self.ls_accum[j] - self.ls_accum[i]", "-", "-", "-if N == 1:", "- print((0))", "- exit()", "-# 絶対値を区切る境目はどこがよいか?", "-B_cum = cumsum1d(B)", "-ans = 10**15", "-for k in range(1, N):", "- tmp_sum = -B_cum.total(0, k) + B_cum.total(k, N)", "- add = min((2 * k - N) * B[k - 1], (2 * k - N) * B[k])", "- ans = min(ans, tmp_sum + add)", "+x = B[N // 2]", "+ans = 0", "+for b in B:", "+ ans += abs(x - b)", "-# 式ごちゃごちゃやったけど絶対楽な方法がある。", "-# 明日復習" ]
false
0.035554
0.03269
1.087613
[ "s427182260", "s692951467" ]
u340781749
p03452
python
s090811658
s395166167
1,673
1,473
169,256
93,544
Accepted
Accepted
11.95
import sys sys.setrecursionlimit(100000) def check(i, xs, checked): xi = xs[i] children = set() for j, d in links[i]: if checked[j]: continue if j not in xs: xs[j] = xi + d elif xi + d != xs[j]: return False children.add(j) checked[i] = True for j in children: if not check(j, xs, checked): return False return True def solve(): checked = [False] * n for i in range(n): if not checked[i]: xs = {} xs[i] = 0 if not check(i, xs, checked): return False return True n, m = list(map(int, input().split())) links = [set() for _ in range(n)] for _ in range(m): l, r, d = list(map(int, input().split())) l -= 1 r -= 1 links[l].add((r, d)) links[r].add((l, -d)) print(('Yes' if solve() else 'No'))
def check(si, xs, checked): q = [si] while q: i = q.pop() xi = xs[i] for j, d in links[i]: if checked[j]: continue if j not in xs: xs[j] = xi + d elif xi + d != xs[j]: return False q.append(j) checked[i] = True return True def solve(): checked = [False] * n for i in range(n): if not checked[i]: xs = {} xs[i] = 0 if not check(i, xs, checked): return False return True n, m = list(map(int, input().split())) links = [set() for _ in range(n)] for _ in range(m): l, r, d = list(map(int, input().split())) l -= 1 r -= 1 links[l].add((r, d)) links[r].add((l, -d)) print(('Yes' if solve() else 'No'))
43
37
928
854
import sys sys.setrecursionlimit(100000) def check(i, xs, checked): xi = xs[i] children = set() for j, d in links[i]: if checked[j]: continue if j not in xs: xs[j] = xi + d elif xi + d != xs[j]: return False children.add(j) checked[i] = True for j in children: if not check(j, xs, checked): return False return True def solve(): checked = [False] * n for i in range(n): if not checked[i]: xs = {} xs[i] = 0 if not check(i, xs, checked): return False return True n, m = list(map(int, input().split())) links = [set() for _ in range(n)] for _ in range(m): l, r, d = list(map(int, input().split())) l -= 1 r -= 1 links[l].add((r, d)) links[r].add((l, -d)) print(("Yes" if solve() else "No"))
def check(si, xs, checked): q = [si] while q: i = q.pop() xi = xs[i] for j, d in links[i]: if checked[j]: continue if j not in xs: xs[j] = xi + d elif xi + d != xs[j]: return False q.append(j) checked[i] = True return True def solve(): checked = [False] * n for i in range(n): if not checked[i]: xs = {} xs[i] = 0 if not check(i, xs, checked): return False return True n, m = list(map(int, input().split())) links = [set() for _ in range(n)] for _ in range(m): l, r, d = list(map(int, input().split())) l -= 1 r -= 1 links[l].add((r, d)) links[r].add((l, -d)) print(("Yes" if solve() else "No"))
false
13.953488
[ "-import sys", "-", "-sys.setrecursionlimit(100000)", "-", "-", "-def check(i, xs, checked):", "- xi = xs[i]", "- children = set()", "- for j, d in links[i]:", "- if checked[j]:", "- continue", "- if j not in xs:", "- xs[j] = xi + d", "- elif xi + d != xs[j]:", "- return False", "- children.add(j)", "- checked[i] = True", "- for j in children:", "- if not check(j, xs, checked):", "- return False", "+def check(si, xs, checked):", "+ q = [si]", "+ while q:", "+ i = q.pop()", "+ xi = xs[i]", "+ for j, d in links[i]:", "+ if checked[j]:", "+ continue", "+ if j not in xs:", "+ xs[j] = xi + d", "+ elif xi + d != xs[j]:", "+ return False", "+ q.append(j)", "+ checked[i] = True" ]
false
0.043155
0.043505
0.991963
[ "s090811658", "s395166167" ]
u941753895
p03633
python
s853687424
s926076616
57
38
6,484
5,168
Accepted
Accepted
33.33
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] 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 I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return eval(input()) # GCD -- START -- def gcd(x,y): while y: x,y=y,x%y return x # GCD --- END --- # LCM -- START -- def lcm(x,y): return x*y//gcd(x,y) # LCM --- END --- def main(): n=I() ans=I() for _ in range(n-1): ans=lcm(ans,I()) return ans # main() print((main()))
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return eval(input()) # GCD -- START -- def gcd(x,y): while y: x,y=y,x%y return x # GCD --- END --- # LCM -- START -- def lcm(x,y): return x*y//gcd(x,y) # LCM --- END --- def main(): n=I() ans=1 for _ in range(n): ans=lcm(ans,I()) return ans # main() print((main()))
37
37
799
809
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] 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 I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return eval(input()) # GCD -- START -- def gcd(x, y): while y: x, y = y, x % y return x # GCD --- END --- # LCM -- START -- def lcm(x, y): return x * y // gcd(x, y) # LCM --- END --- def main(): n = I() ans = I() for _ in range(n - 1): ans = lcm(ans, I()) return ans # main() print((main()))
import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return eval(input()) # GCD -- START -- def gcd(x, y): while y: x, y = y, x % y return x # GCD --- END --- # LCM -- START -- def lcm(x, y): return x * y // gcd(x, y) # LCM --- END --- def main(): n = I() ans = 1 for _ in range(n): ans = lcm(ans, I()) return ans # main() print((main()))
false
0
[ "-import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy", "+import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy", "-def LI_():", "- return [int(x) - 1 for x in sys.stdin.readline().split()]", "+def LF():", "+ return [float(x) for x in sys.stdin.readline().split()]", "+", "+", "+def F():", "+ return float(sys.stdin.readline())", "- ans = I()", "- for _ in range(n - 1):", "+ ans = 1", "+ for _ in range(n):" ]
false
0.047685
0.088351
0.539724
[ "s853687424", "s926076616" ]
u186838327
p03408
python
s670286376
s511522508
176
82
38,256
67,020
Accepted
Accepted
53.41
n = int(eval(input())) S = {} for i in range(n): s = str(eval(input())) if s not in S: S[s] = 1 else: S[s] += 1 m = int(eval(input())) T = {} for i in range(m): t = str(eval(input())) if t not in T: T[t] = 1 else: T[t] += 1 ans = 0 for k, v in list(S.items()): if k in T: ans = max(ans, v-T[k]) else: ans = max(ans, v) print(ans)
n = int(eval(input())) S = [str(eval(input())) for _ in range(n)] m = int(eval(input())) T = [str(eval(input())) for _ in range(m)] from collections import Counter CS = Counter(S) CT = Counter(T) ans = 0 for k in list(CS.keys()): if k not in CT: ans = max(CS[k], ans) else: ans = max(ans, max(0, CS[k]-CT[k])) print(ans)
24
16
403
332
n = int(eval(input())) S = {} for i in range(n): s = str(eval(input())) if s not in S: S[s] = 1 else: S[s] += 1 m = int(eval(input())) T = {} for i in range(m): t = str(eval(input())) if t not in T: T[t] = 1 else: T[t] += 1 ans = 0 for k, v in list(S.items()): if k in T: ans = max(ans, v - T[k]) else: ans = max(ans, v) print(ans)
n = int(eval(input())) S = [str(eval(input())) for _ in range(n)] m = int(eval(input())) T = [str(eval(input())) for _ in range(m)] from collections import Counter CS = Counter(S) CT = Counter(T) ans = 0 for k in list(CS.keys()): if k not in CT: ans = max(CS[k], ans) else: ans = max(ans, max(0, CS[k] - CT[k])) print(ans)
false
33.333333
[ "-S = {}", "-for i in range(n):", "- s = str(eval(input()))", "- if s not in S:", "- S[s] = 1", "+S = [str(eval(input())) for _ in range(n)]", "+m = int(eval(input()))", "+T = [str(eval(input())) for _ in range(m)]", "+from collections import Counter", "+", "+CS = Counter(S)", "+CT = Counter(T)", "+ans = 0", "+for k in list(CS.keys()):", "+ if k not in CT:", "+ ans = max(CS[k], ans)", "- S[s] += 1", "-m = int(eval(input()))", "-T = {}", "-for i in range(m):", "- t = str(eval(input()))", "- if t not in T:", "- T[t] = 1", "- else:", "- T[t] += 1", "-ans = 0", "-for k, v in list(S.items()):", "- if k in T:", "- ans = max(ans, v - T[k])", "- else:", "- ans = max(ans, v)", "+ ans = max(ans, max(0, CS[k] - CT[k]))" ]
false
0.03415
0.12187
0.280218
[ "s670286376", "s511522508" ]
u249372595
p03061
python
s889342895
s850247231
237
148
16,144
20,660
Accepted
Accepted
37.55
import fractions from functools import reduce N = int(eval(input())) A = list(map(int,input().split())) #累積GCD left = [0]*(N+1) right = [0]*(N+1) for i in range(N): left[i+1] = (fractions.gcd(left[i],A[i])) right[N-i-1] = (fractions.gcd(right[N-i],A[N-1-i])) ans = 0 for i in range(N): ans = max(ans,fractions.gcd(left[i],right[i + 1])) print(ans)
import math N = int(eval(input())) A = list(map(int,input().split())) dp_left=[0]*(N+1) dp_right=[0]*(N+1) for i in range(N):#左から累積GCD dp_left[i+1]=math.gcd(dp_left[i],A[i]) dp_right[N-i-1]=math.gcd(dp_right[N-i],A[N-1-i])#右から累積GCD ans = 0 for i in range(N): ans = max(ans,math.gcd(dp_left[i],dp_right[i+1])) print(ans)
15
13
362
332
import fractions from functools import reduce N = int(eval(input())) A = list(map(int, input().split())) # 累積GCD left = [0] * (N + 1) right = [0] * (N + 1) for i in range(N): left[i + 1] = fractions.gcd(left[i], A[i]) right[N - i - 1] = fractions.gcd(right[N - i], A[N - 1 - i]) ans = 0 for i in range(N): ans = max(ans, fractions.gcd(left[i], right[i + 1])) print(ans)
import math N = int(eval(input())) A = list(map(int, input().split())) dp_left = [0] * (N + 1) dp_right = [0] * (N + 1) for i in range(N): # 左から累積GCD dp_left[i + 1] = math.gcd(dp_left[i], A[i]) dp_right[N - i - 1] = math.gcd(dp_right[N - i], A[N - 1 - i]) # 右から累積GCD ans = 0 for i in range(N): ans = max(ans, math.gcd(dp_left[i], dp_right[i + 1])) print(ans)
false
13.333333
[ "-import fractions", "-from functools import reduce", "+import math", "-# 累積GCD", "-left = [0] * (N + 1)", "-right = [0] * (N + 1)", "-for i in range(N):", "- left[i + 1] = fractions.gcd(left[i], A[i])", "- right[N - i - 1] = fractions.gcd(right[N - i], A[N - 1 - i])", "+dp_left = [0] * (N + 1)", "+dp_right = [0] * (N + 1)", "+for i in range(N): # 左から累積GCD", "+ dp_left[i + 1] = math.gcd(dp_left[i], A[i])", "+ dp_right[N - i - 1] = math.gcd(dp_right[N - i], A[N - 1 - i]) # 右から累積GCD", "- ans = max(ans, fractions.gcd(left[i], right[i + 1]))", "+ ans = max(ans, math.gcd(dp_left[i], dp_right[i + 1]))" ]
false
0.058714
0.042678
1.375724
[ "s889342895", "s850247231" ]
u227020436
p02682
python
s070728279
s830769896
23
21
9,096
9,152
Accepted
Accepted
8.7
# B - Easy Linear Programming a, b, c, k = list(map(int, input().split())) if k <= a: print(k) elif a < k <= a + b: print(a) else: print((a - (k - (a + b))))
# B - Easy Linear Programming a, b, c, k = list(map(int, input().split())) print((min(k, a, a + a + b - k)))
9
4
171
105
# B - Easy Linear Programming a, b, c, k = list(map(int, input().split())) if k <= a: print(k) elif a < k <= a + b: print(a) else: print((a - (k - (a + b))))
# B - Easy Linear Programming a, b, c, k = list(map(int, input().split())) print((min(k, a, a + a + b - k)))
false
55.555556
[ "-if k <= a:", "- print(k)", "-elif a < k <= a + b:", "- print(a)", "-else:", "- print((a - (k - (a + b))))", "+print((min(k, a, a + a + b - k)))" ]
false
0.040344
0.038518
1.047396
[ "s070728279", "s830769896" ]
u983918956
p03166
python
s008446937
s241892099
542
494
103,936
103,936
Accepted
Accepted
8.86
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) N,M = list(map(int,input().split())) ad = [[] for _ in range(N)] for _ in range(M): x,y = list(map(int,input().split())) x -= 1 y -= 1 ad[y].append(x) dp = [0]*N def rec(v): if dp[v] != 0: return dp[v] res = 0 for nv in ad[v]: res = max(res, rec(nv) + 1) dp[v] = res return dp[v] for v in range(N): rec(v) ans = max(dp) print(ans)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) N,M = list(map(int,input().split())) ad = [[] for _ in range(N)] for _ in range(M): x,y = list(map(int,input().split())) x -= 1 y -= 1 ad[y].append(x) dp = [-1]*N def rec(v): if dp[v] != -1: return dp[v] res = 0 for nv in ad[v]: res = max(res, rec(nv) + 1) dp[v] = res return dp[v] for v in range(N): rec(v) ans = max(dp) print(ans)
28
28
473
475
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) N, M = list(map(int, input().split())) ad = [[] for _ in range(N)] for _ in range(M): x, y = list(map(int, input().split())) x -= 1 y -= 1 ad[y].append(x) dp = [0] * N def rec(v): if dp[v] != 0: return dp[v] res = 0 for nv in ad[v]: res = max(res, rec(nv) + 1) dp[v] = res return dp[v] for v in range(N): rec(v) ans = max(dp) print(ans)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) N, M = list(map(int, input().split())) ad = [[] for _ in range(N)] for _ in range(M): x, y = list(map(int, input().split())) x -= 1 y -= 1 ad[y].append(x) dp = [-1] * N def rec(v): if dp[v] != -1: return dp[v] res = 0 for nv in ad[v]: res = max(res, rec(nv) + 1) dp[v] = res return dp[v] for v in range(N): rec(v) ans = max(dp) print(ans)
false
0
[ "-dp = [0] * N", "+dp = [-1] * N", "- if dp[v] != 0:", "+ if dp[v] != -1:" ]
false
0.079572
0.04201
1.894145
[ "s008446937", "s241892099" ]
u994988729
p03937
python
s318201338
s688381677
274
17
20,548
2,940
Accepted
Accepted
93.8
from collections import deque import numpy as np def isPossible(grid): v = deque([[0, 0]]) while v: x, y = v.popleft() grid[x][y] = 0 if grid[x][y + 1]: v.append([x, y + 1]) continue elif grid[x + 1][y]: v.append([x + 1, y]) continue if grid.sum() == 0: return True else: return False if __name__ == "__main__": h, w = list(map(int, input().split())) grid = [[0 if i == "." else 1 for i in eval(input())+"."] for _ in range(h)] grid.append([0]*(w+1)) grid = np.array(grid) if isPossible(grid): ans = "Possible" else: ans = "Impossible" print(ans)
H, W = list(map(int, input().split())) cnt = 0 for _ in range(H): cnt += input().count("#") if cnt == H + W - 1: print("Possible") else: print("Impossible")
33
10
729
174
from collections import deque import numpy as np def isPossible(grid): v = deque([[0, 0]]) while v: x, y = v.popleft() grid[x][y] = 0 if grid[x][y + 1]: v.append([x, y + 1]) continue elif grid[x + 1][y]: v.append([x + 1, y]) continue if grid.sum() == 0: return True else: return False if __name__ == "__main__": h, w = list(map(int, input().split())) grid = [[0 if i == "." else 1 for i in eval(input()) + "."] for _ in range(h)] grid.append([0] * (w + 1)) grid = np.array(grid) if isPossible(grid): ans = "Possible" else: ans = "Impossible" print(ans)
H, W = list(map(int, input().split())) cnt = 0 for _ in range(H): cnt += input().count("#") if cnt == H + W - 1: print("Possible") else: print("Impossible")
false
69.69697
[ "-from collections import deque", "-import numpy as np", "-", "-", "-def isPossible(grid):", "- v = deque([[0, 0]])", "- while v:", "- x, y = v.popleft()", "- grid[x][y] = 0", "- if grid[x][y + 1]:", "- v.append([x, y + 1])", "- continue", "- elif grid[x + 1][y]:", "- v.append([x + 1, y])", "- continue", "- if grid.sum() == 0:", "- return True", "- else:", "- return False", "-", "-", "-if __name__ == \"__main__\":", "- h, w = list(map(int, input().split()))", "- grid = [[0 if i == \".\" else 1 for i in eval(input()) + \".\"] for _ in range(h)]", "- grid.append([0] * (w + 1))", "- grid = np.array(grid)", "- if isPossible(grid):", "- ans = \"Possible\"", "- else:", "- ans = \"Impossible\"", "- print(ans)", "+H, W = list(map(int, input().split()))", "+cnt = 0", "+for _ in range(H):", "+ cnt += input().count(\"#\")", "+if cnt == H + W - 1:", "+ print(\"Possible\")", "+else:", "+ print(\"Impossible\")" ]
false
0.562469
0.03346
16.809953
[ "s318201338", "s688381677" ]
u413165887
p03610
python
s009352089
s030485331
29
17
4,268
3,192
Accepted
Accepted
41.38
s = list(eval(input())) print(("".join([s[i] for i in range(len(s)) if i%2==0])))
print((input()[::2]))
2
1
74
19
s = list(eval(input())) print(("".join([s[i] for i in range(len(s)) if i % 2 == 0])))
print((input()[::2]))
false
50
[ "-s = list(eval(input()))", "-print((\"\".join([s[i] for i in range(len(s)) if i % 2 == 0])))", "+print((input()[::2]))" ]
false
0.039558
0.061038
0.648088
[ "s009352089", "s030485331" ]
u438662618
p02792
python
s644097552
s857732921
436
243
3,064
3,064
Accepted
Accepted
44.27
n = int(eval(input())) book = [[0] * 9 for i in range(9)] ans = 0 for i in range(1, n+1) : reverse = 0 tmp = i time = 0 flag = False end = -1 while(tmp!=0) : remind = tmp % 10 if time == 0 : if remind == 0 : flag = True break pre = remind tmp = tmp // 10 time += 1 if flag == True : continue if remind != 0 : book[remind-1][pre-1] += 1 for i in range(9) : for j in range(i, 9) : if i == j : ans += book[i][j] * book[j][i] #print('=', i, j, book[i][j] * book[j][i]) continue if book[i][j] != 0 and book[j][i] != 0 : ans += book[i][j] * book[j][i] * 2 #print('!', i, j, book[i][j] * book[j][i] * 2) #for i in range(9) : # print(book[i]) print(ans)
n = int(eval(input())) book = [[0] * 9 for i in range(9)] ans = 0 for i in range(1, n+1) : pre = int(str(i)[0]) end = int(str(i)[-1]) if end != 0 : book[pre-1][end-1] += 1 for i in range(9) : for j in range(i, 9) : if i == j : ans += book[i][j] * book[j][i] #print('=', i, j, book[i][j] * book[j][i]) continue if book[i][j] != 0 and book[j][i] != 0 : ans += book[i][j] * book[j][i] * 2 #print('!', i, j, book[i][j] * book[j][i] * 2) #for i in range(9) : # print(book[i]) print(ans)
39
26
902
610
n = int(eval(input())) book = [[0] * 9 for i in range(9)] ans = 0 for i in range(1, n + 1): reverse = 0 tmp = i time = 0 flag = False end = -1 while tmp != 0: remind = tmp % 10 if time == 0: if remind == 0: flag = True break pre = remind tmp = tmp // 10 time += 1 if flag == True: continue if remind != 0: book[remind - 1][pre - 1] += 1 for i in range(9): for j in range(i, 9): if i == j: ans += book[i][j] * book[j][i] # print('=', i, j, book[i][j] * book[j][i]) continue if book[i][j] != 0 and book[j][i] != 0: ans += book[i][j] * book[j][i] * 2 # print('!', i, j, book[i][j] * book[j][i] * 2) # for i in range(9) : # print(book[i]) print(ans)
n = int(eval(input())) book = [[0] * 9 for i in range(9)] ans = 0 for i in range(1, n + 1): pre = int(str(i)[0]) end = int(str(i)[-1]) if end != 0: book[pre - 1][end - 1] += 1 for i in range(9): for j in range(i, 9): if i == j: ans += book[i][j] * book[j][i] # print('=', i, j, book[i][j] * book[j][i]) continue if book[i][j] != 0 and book[j][i] != 0: ans += book[i][j] * book[j][i] * 2 # print('!', i, j, book[i][j] * book[j][i] * 2) # for i in range(9) : # print(book[i]) print(ans)
false
33.333333
[ "- reverse = 0", "- tmp = i", "- time = 0", "- flag = False", "- end = -1", "- while tmp != 0:", "- remind = tmp % 10", "- if time == 0:", "- if remind == 0:", "- flag = True", "- break", "- pre = remind", "- tmp = tmp // 10", "- time += 1", "- if flag == True:", "- continue", "- if remind != 0:", "- book[remind - 1][pre - 1] += 1", "+ pre = int(str(i)[0])", "+ end = int(str(i)[-1])", "+ if end != 0:", "+ book[pre - 1][end - 1] += 1" ]
false
0.208215
0.075049
2.774382
[ "s644097552", "s857732921" ]
u044220565
p03583
python
s430288270
s925121050
1,292
32
9,196
9,148
Accepted
Accepted
97.52
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) import math #from itertools import product, accumulate, combinations, product #import bisect #import numpy as np #from copy import deepcopy #from collections import deque #from decimal import Decimal #from numba import jit INF = 1 << 50 EPS = 1e-8 mod = 10 ** 9 + 7 def run(): N = int(eval(input())) for h in range(1, 3501): for n in range(1, 3501): v = N * h * n a = 4 * h * n - N * n - N * h if a <= 0:continue if not v % a: w = v // a print(f'{h} {n} {w}') return if __name__ == "__main__": run()
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) import math #from itertools import product, accumulate, combinations, product #import bisect #import numpy as np #from copy import deepcopy #from collections import deque #from decimal import Decimal #from numba import jit INF = 1 << 50 EPS = 1e-8 mod = 10 ** 9 + 7 def run(): N = int(eval(input())) for h in range(1, 3501): if 4 * h - N <= 0: continue s = math.ceil(N * h / (4 * h - N)) for n in range(s, 3501): v = N * h * n a = 4 * h * n - N * n - N * h if a <= 0:continue if not v % a: w = v // a print(f'{h} {n} {w}') return if __name__ == "__main__": run()
36
39
877
971
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read # from heapq import heappop, heappush # from collections import defaultdict sys.setrecursionlimit(10**7) import math # from itertools import product, accumulate, combinations, product # import bisect # import numpy as np # from copy import deepcopy # from collections import deque # from decimal import Decimal # from numba import jit INF = 1 << 50 EPS = 1e-8 mod = 10**9 + 7 def run(): N = int(eval(input())) for h in range(1, 3501): for n in range(1, 3501): v = N * h * n a = 4 * h * n - N * n - N * h if a <= 0: continue if not v % a: w = v // a print(f"{h} {n} {w}") return if __name__ == "__main__": run()
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read # from heapq import heappop, heappush # from collections import defaultdict sys.setrecursionlimit(10**7) import math # from itertools import product, accumulate, combinations, product # import bisect # import numpy as np # from copy import deepcopy # from collections import deque # from decimal import Decimal # from numba import jit INF = 1 << 50 EPS = 1e-8 mod = 10**9 + 7 def run(): N = int(eval(input())) for h in range(1, 3501): if 4 * h - N <= 0: continue s = math.ceil(N * h / (4 * h - N)) for n in range(s, 3501): v = N * h * n a = 4 * h * n - N * n - N * h if a <= 0: continue if not v % a: w = v // a print(f"{h} {n} {w}") return if __name__ == "__main__": run()
false
7.692308
[ "- for n in range(1, 3501):", "+ if 4 * h - N <= 0:", "+ continue", "+ s = math.ceil(N * h / (4 * h - N))", "+ for n in range(s, 3501):" ]
false
1.499808
0.035806
41.886818
[ "s430288270", "s925121050" ]
u341543478
p03160
python
s660845225
s167615575
153
119
20,620
20,644
Accepted
Accepted
22.22
n = int(eval(input())) h = list(map(int, input().split())) dp = [float('inf')] * n dp[0] = 0 for i in range(n - 1): if i <= n - 3: dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1])) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2])) elif i == n - 2: dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1])) print((dp[-1]))
n = int(eval(input())) h = list(map(int, input().split())) dp = [0, abs(h[0] - h[1])] for i in range(2, n): dp.append(min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]))) print((dp[-1]))
13
6
373
208
n = int(eval(input())) h = list(map(int, input().split())) dp = [float("inf")] * n dp[0] = 0 for i in range(n - 1): if i <= n - 3: dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1])) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2])) elif i == n - 2: dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1])) print((dp[-1]))
n = int(eval(input())) h = list(map(int, input().split())) dp = [0, abs(h[0] - h[1])] for i in range(2, n): dp.append(min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]))) print((dp[-1]))
false
53.846154
[ "-dp = [float(\"inf\")] * n", "-dp[0] = 0", "-for i in range(n - 1):", "- if i <= n - 3:", "- dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))", "- dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))", "- elif i == n - 2:", "- dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))", "+dp = [0, abs(h[0] - h[1])]", "+for i in range(2, n):", "+ dp.append(min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i])))" ]
false
0.155903
0.131152
1.188719
[ "s660845225", "s167615575" ]
u669812251
p02774
python
s443078791
s059254622
1,117
560
32,276
89,684
Accepted
Accepted
49.87
# -*- coding: utf-8 -*- #尺取り法 import numpy as np n, k = list(map(int,input().split())) a = np.array(list(map(int,input().split()))) a.sort() posi = a[a>0] zero = a[a==0] nega = a[a<0] #print(posi) # 2分探索, midより小さいものを数える l = -10**18-1 r = 10**18+1 while r-l > 1: mid = (r+l)//2 cnt = 0 if mid >= 0: cnt += len(zero)*n # a.searchsorted(v, side="left"): a[i-1] < v <= a[i]であるvのindexを返す # a.searchsorted(v, side="right"): a[i-1] <= v < a[i]であるvのindexを返す cnt += a.searchsorted(mid//posi, side="right").sum() cnt += (n - a.searchsorted(-(-mid//nega), side="left")).sum() cnt -= np.count_nonzero(a*a <= mid) cnt //= 2 #print("mid:", mid) #print("mid//posi:", mid//posi) #print("search:", a.searchsorted(mid//posi,side="right")) #print("-(-mid//nega):", -(-mid//nega)) #print("search:", a.searchsorted(-(-mid//nega),side="left")) #print("nonzero_count:", np.count_nonzero(a*a<=mid)) #print("count:", cnt) #print('-' * 20) if cnt >= k: r = mid else: l = mid print(r)
from bisect import bisect_left, bisect_right def main(): N, K = [int(i) for i in input().split()] A = sorted(list(map(int, input().split()))) nega_end = bisect_left(A, 0) posi_start = bisect_right(A, 0) posi_cnt = N - posi_start nega_cnt = nega_end zero_cnt = N - (posi_cnt + nega_cnt) nega_pairs_cnt = posi_cnt * nega_cnt zero_pairs_cnt = zero_cnt * (posi_cnt + nega_cnt) + (zero_cnt * (zero_cnt-1) // 2) if K <= nega_pairs_cnt: ok, ng = 0, -10 ** 18 while abs(ok - ng) > 1: X = (ok + ng) // 2 or_higher_cnt, r = 0, posi_start for l in range(nega_end): while (r < N) and (A[l] * A[r] > X): r += 1 or_higher_cnt += posi_cnt - (r - posi_start) if or_higher_cnt >= K: ok = X else: ng = X #print(ok, ng) print(ok) elif nega_pairs_cnt < K <= nega_pairs_cnt + zero_pairs_cnt: print((0)) return else: K -= (nega_pairs_cnt + zero_pairs_cnt) ok, ng = 10 ** 18, 0 while abs(ok - ng) > 1: X = (ok + ng) // 2 or_higher_cnt = 0 r = N - 1 for l in range(posi_start, N): while (r < N) and (A[l] * A[r] > X) and (l < r): r -= 1 or_higher_cnt += max(0, r - l) l = 0 for r in range(nega_end - 1, -1, -1): while (l < N) and (A[l] * A[r] > X) and (l < r): l += 1 or_higher_cnt += max(0, r - l) if or_higher_cnt >= K: ok = X else: ng = X print(ok) if __name__ == "__main__": main()
40
65
1,093
1,850
# -*- coding: utf-8 -*- # 尺取り法 import numpy as np n, k = list(map(int, input().split())) a = np.array(list(map(int, input().split()))) a.sort() posi = a[a > 0] zero = a[a == 0] nega = a[a < 0] # print(posi) # 2分探索, midより小さいものを数える l = -(10**18) - 1 r = 10**18 + 1 while r - l > 1: mid = (r + l) // 2 cnt = 0 if mid >= 0: cnt += len(zero) * n # a.searchsorted(v, side="left"): a[i-1] < v <= a[i]であるvのindexを返す # a.searchsorted(v, side="right"): a[i-1] <= v < a[i]であるvのindexを返す cnt += a.searchsorted(mid // posi, side="right").sum() cnt += (n - a.searchsorted(-(-mid // nega), side="left")).sum() cnt -= np.count_nonzero(a * a <= mid) cnt //= 2 # print("mid:", mid) # print("mid//posi:", mid//posi) # print("search:", a.searchsorted(mid//posi,side="right")) # print("-(-mid//nega):", -(-mid//nega)) # print("search:", a.searchsorted(-(-mid//nega),side="left")) # print("nonzero_count:", np.count_nonzero(a*a<=mid)) # print("count:", cnt) # print('-' * 20) if cnt >= k: r = mid else: l = mid print(r)
from bisect import bisect_left, bisect_right def main(): N, K = [int(i) for i in input().split()] A = sorted(list(map(int, input().split()))) nega_end = bisect_left(A, 0) posi_start = bisect_right(A, 0) posi_cnt = N - posi_start nega_cnt = nega_end zero_cnt = N - (posi_cnt + nega_cnt) nega_pairs_cnt = posi_cnt * nega_cnt zero_pairs_cnt = zero_cnt * (posi_cnt + nega_cnt) + (zero_cnt * (zero_cnt - 1) // 2) if K <= nega_pairs_cnt: ok, ng = 0, -(10**18) while abs(ok - ng) > 1: X = (ok + ng) // 2 or_higher_cnt, r = 0, posi_start for l in range(nega_end): while (r < N) and (A[l] * A[r] > X): r += 1 or_higher_cnt += posi_cnt - (r - posi_start) if or_higher_cnt >= K: ok = X else: ng = X # print(ok, ng) print(ok) elif nega_pairs_cnt < K <= nega_pairs_cnt + zero_pairs_cnt: print((0)) return else: K -= nega_pairs_cnt + zero_pairs_cnt ok, ng = 10**18, 0 while abs(ok - ng) > 1: X = (ok + ng) // 2 or_higher_cnt = 0 r = N - 1 for l in range(posi_start, N): while (r < N) and (A[l] * A[r] > X) and (l < r): r -= 1 or_higher_cnt += max(0, r - l) l = 0 for r in range(nega_end - 1, -1, -1): while (l < N) and (A[l] * A[r] > X) and (l < r): l += 1 or_higher_cnt += max(0, r - l) if or_higher_cnt >= K: ok = X else: ng = X print(ok) if __name__ == "__main__": main()
false
38.461538
[ "-# -*- coding: utf-8 -*-", "-# 尺取り法", "-import numpy as np", "+from bisect import bisect_left, bisect_right", "-n, k = list(map(int, input().split()))", "-a = np.array(list(map(int, input().split())))", "-a.sort()", "-posi = a[a > 0]", "-zero = a[a == 0]", "-nega = a[a < 0]", "-# print(posi)", "-# 2分探索, midより小さいものを数える", "-l = -(10**18) - 1", "-r = 10**18 + 1", "-while r - l > 1:", "- mid = (r + l) // 2", "- cnt = 0", "- if mid >= 0:", "- cnt += len(zero) * n", "- # a.searchsorted(v, side=\"left\"): a[i-1] < v <= a[i]であるvのindexを返す", "- # a.searchsorted(v, side=\"right\"): a[i-1] <= v < a[i]であるvのindexを返す", "- cnt += a.searchsorted(mid // posi, side=\"right\").sum()", "- cnt += (n - a.searchsorted(-(-mid // nega), side=\"left\")).sum()", "- cnt -= np.count_nonzero(a * a <= mid)", "- cnt //= 2", "- # print(\"mid:\", mid)", "- # print(\"mid//posi:\", mid//posi)", "- # print(\"search:\", a.searchsorted(mid//posi,side=\"right\"))", "- # print(\"-(-mid//nega):\", -(-mid//nega))", "- # print(\"search:\", a.searchsorted(-(-mid//nega),side=\"left\"))", "- # print(\"nonzero_count:\", np.count_nonzero(a*a<=mid))", "- # print(\"count:\", cnt)", "- # print('-' * 20)", "- if cnt >= k:", "- r = mid", "+", "+def main():", "+ N, K = [int(i) for i in input().split()]", "+ A = sorted(list(map(int, input().split())))", "+ nega_end = bisect_left(A, 0)", "+ posi_start = bisect_right(A, 0)", "+ posi_cnt = N - posi_start", "+ nega_cnt = nega_end", "+ zero_cnt = N - (posi_cnt + nega_cnt)", "+ nega_pairs_cnt = posi_cnt * nega_cnt", "+ zero_pairs_cnt = zero_cnt * (posi_cnt + nega_cnt) + (zero_cnt * (zero_cnt - 1) // 2)", "+ if K <= nega_pairs_cnt:", "+ ok, ng = 0, -(10**18)", "+ while abs(ok - ng) > 1:", "+ X = (ok + ng) // 2", "+ or_higher_cnt, r = 0, posi_start", "+ for l in range(nega_end):", "+ while (r < N) and (A[l] * A[r] > X):", "+ r += 1", "+ or_higher_cnt += posi_cnt - (r - posi_start)", "+ if or_higher_cnt >= K:", "+ ok = X", "+ else:", "+ ng = X", "+ # print(ok, ng)", "+ print(ok)", "+ elif nega_pairs_cnt < K <= nega_pairs_cnt + zero_pairs_cnt:", "+ print((0))", "+ return", "- l = mid", "-print(r)", "+ K -= nega_pairs_cnt + zero_pairs_cnt", "+ ok, ng = 10**18, 0", "+ while abs(ok - ng) > 1:", "+ X = (ok + ng) // 2", "+ or_higher_cnt = 0", "+ r = N - 1", "+ for l in range(posi_start, N):", "+ while (r < N) and (A[l] * A[r] > X) and (l < r):", "+ r -= 1", "+ or_higher_cnt += max(0, r - l)", "+ l = 0", "+ for r in range(nega_end - 1, -1, -1):", "+ while (l < N) and (A[l] * A[r] > X) and (l < r):", "+ l += 1", "+ or_higher_cnt += max(0, r - l)", "+ if or_higher_cnt >= K:", "+ ok = X", "+ else:", "+ ng = X", "+ print(ok)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.217082
0.041211
5.26752
[ "s443078791", "s059254622" ]
u691018832
p02682
python
s204849577
s842322036
64
21
61,816
9,168
Accepted
Accepted
67.19
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) a, b, c, k = list(map(int, readline().split())) if a + b >= k: print((min(a, k))) else: print((a - (k - a - b)))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) a, b, c, k = list(map(int, read().split())) print((min(a, k) if a + b >= k else 2 * a + b - k))
11
8
269
243
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) a, b, c, k = list(map(int, readline().split())) if a + b >= k: print((min(a, k))) else: print((a - (k - a - b)))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) a, b, c, k = list(map(int, read().split())) print((min(a, k) if a + b >= k else 2 * a + b - k))
false
27.272727
[ "-a, b, c, k = list(map(int, readline().split()))", "-if a + b >= k:", "- print((min(a, k)))", "-else:", "- print((a - (k - a - b)))", "+a, b, c, k = list(map(int, read().split()))", "+print((min(a, k) if a + b >= k else 2 * a + b - k))" ]
false
0.037425
0.037799
0.990106
[ "s204849577", "s842322036" ]
u296150111
p03283
python
s895996951
s894700503
1,258
727
58,332
13,568
Accepted
Accepted
42.21
import sys input=sys.stdin.readline n,m,q=list(map(int,input().split())) num=[[0]*(n+1) for _ in range(n+1)] for i in range(m): l,r=list(map(int,input().split())) num[l][r]+=1 for i in range(n): for j in range(n): num[i+1][j+1]+=num[i+1][j] for i in range(q): p,q=list(map(int,input().split())) ans=0 for i in range(p,q+1): ans+=num[i][q]-num[i][p-1] print(ans)
import sys input=sys.stdin.readline n,m,q=list(map(int,input().split())) num=[[0]*(n+1) for _ in range(n+1)] for i in range(m): l,r=list(map(int,input().split())) num[l][r]+=1 for i in range(n): for j in range(n): num[i+1][j+1]+=num[i+1][j] for i in range(n): for j in range(n): num[i+1][j+1]+=num[i][j+1] for i in range(q): p,q=list(map(int,input().split())) ans=num[q][q]+num[p-1][p-1]-num[p-1][q]-num[q][p-1] print(ans)
18
19
374
436
import sys input = sys.stdin.readline n, m, q = list(map(int, input().split())) num = [[0] * (n + 1) for _ in range(n + 1)] for i in range(m): l, r = list(map(int, input().split())) num[l][r] += 1 for i in range(n): for j in range(n): num[i + 1][j + 1] += num[i + 1][j] for i in range(q): p, q = list(map(int, input().split())) ans = 0 for i in range(p, q + 1): ans += num[i][q] - num[i][p - 1] print(ans)
import sys input = sys.stdin.readline n, m, q = list(map(int, input().split())) num = [[0] * (n + 1) for _ in range(n + 1)] for i in range(m): l, r = list(map(int, input().split())) num[l][r] += 1 for i in range(n): for j in range(n): num[i + 1][j + 1] += num[i + 1][j] for i in range(n): for j in range(n): num[i + 1][j + 1] += num[i][j + 1] for i in range(q): p, q = list(map(int, input().split())) ans = num[q][q] + num[p - 1][p - 1] - num[p - 1][q] - num[q][p - 1] print(ans)
false
5.263158
[ "+for i in range(n):", "+ for j in range(n):", "+ num[i + 1][j + 1] += num[i][j + 1]", "- ans = 0", "- for i in range(p, q + 1):", "- ans += num[i][q] - num[i][p - 1]", "+ ans = num[q][q] + num[p - 1][p - 1] - num[p - 1][q] - num[q][p - 1]" ]
false
0.037638
0.037204
1.011666
[ "s895996951", "s894700503" ]
u682467216
p02936
python
s133520958
s283607958
1,375
1,142
223,348
252,620
Accepted
Accepted
16.95
import sys sys.setrecursionlimit(10**7) N, Q = list(map(int, input().split())) root = [[] for _ in range(N)] ans = [0]*N for _ in range(N-1): a,b=list(map(int, input().split())) a,b=a-1,b-1 root[a].append(b) root[b].append(a) for _ in range(Q): p,x=list(map(int, input().split())) ans[p-1]+=x visited=[False]*N def dfs(v): visited[v] = True for go in root[v]: if visited[go]: continue ans[go] += ans[v] dfs(go) dfs(0) print((*ans))
from math import floor, ceil, sqrt, factorial, log, gcd from itertools import accumulate, permutations, combinations, product, combinations_with_replacement from bisect import bisect_left, bisect_right from collections import Counter, defaultdict from heapq import heappop, heappush, heappushpop import copy import numpy as np import sys INF = float('inf') mod = 10 ** 9 + 7 sys.setrecursionlimit(10 ** 6) def lcm(a, b): return a * b / gcd(a, b) # 1 2 3 # a, b, c = LI() def LI(): return list(map(int, sys.stdin.buffer.readline().rsplit())) # a = I() def I(): return int(sys.stdin.buffer.readline()) # abc def # a, b = LS() def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() # a = S() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') # 2 # 1 # 2 # [1, 2] def IR(n): return [I() for i in range(n)] # 2 # 1 2 3 # 4 5 6 # [[1,2,3], [4,5,6]] def LIR(n): return [LI() for i in range(n)] # 2 # abc # def # [abc, def] def SR(n): return [S() for i in range(n)] # 2 # abc def # ghi jkl # [[abc,def], [ghi,jkl]] def LSR(n): return [LS() for i in range(n)] # 2 # abcd # efgh # [[a,b,c,d], [e,f,g,h]] def SRL(n): return [list(S()) for i in range(n)] n, q = LI() point = [0]*n graph = [[] for i in range(n)] visited = [False]*n def dfs(n): visited[n-1] = True for node in graph[n-1]: if visited[node-1]: continue point[node-1] += point[n-1] dfs(node) def main(): for i in range(n - 1): a, b = LI() graph[a - 1].append(b) graph[b - 1].append(a) for i in range(q): p, x = LI() point[p - 1] += x dfs(1) print((*point)) if __name__ == "__main__": main()
28
111
482
1,837
import sys sys.setrecursionlimit(10**7) N, Q = list(map(int, input().split())) root = [[] for _ in range(N)] ans = [0] * N for _ in range(N - 1): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 root[a].append(b) root[b].append(a) for _ in range(Q): p, x = list(map(int, input().split())) ans[p - 1] += x visited = [False] * N def dfs(v): visited[v] = True for go in root[v]: if visited[go]: continue ans[go] += ans[v] dfs(go) dfs(0) print((*ans))
from math import floor, ceil, sqrt, factorial, log, gcd from itertools import ( accumulate, permutations, combinations, product, combinations_with_replacement, ) from bisect import bisect_left, bisect_right from collections import Counter, defaultdict from heapq import heappop, heappush, heappushpop import copy import numpy as np import sys INF = float("inf") mod = 10**9 + 7 sys.setrecursionlimit(10**6) def lcm(a, b): return a * b / gcd(a, b) # 1 2 3 # a, b, c = LI() def LI(): return list(map(int, sys.stdin.buffer.readline().rsplit())) # a = I() def I(): return int(sys.stdin.buffer.readline()) # abc def # a, b = LS() def LS(): return sys.stdin.buffer.readline().rstrip().decode("utf-8").split() # a = S() def S(): return sys.stdin.buffer.readline().rstrip().decode("utf-8") # 2 # 1 # 2 # [1, 2] def IR(n): return [I() for i in range(n)] # 2 # 1 2 3 # 4 5 6 # [[1,2,3], [4,5,6]] def LIR(n): return [LI() for i in range(n)] # 2 # abc # def # [abc, def] def SR(n): return [S() for i in range(n)] # 2 # abc def # ghi jkl # [[abc,def], [ghi,jkl]] def LSR(n): return [LS() for i in range(n)] # 2 # abcd # efgh # [[a,b,c,d], [e,f,g,h]] def SRL(n): return [list(S()) for i in range(n)] n, q = LI() point = [0] * n graph = [[] for i in range(n)] visited = [False] * n def dfs(n): visited[n - 1] = True for node in graph[n - 1]: if visited[node - 1]: continue point[node - 1] += point[n - 1] dfs(node) def main(): for i in range(n - 1): a, b = LI() graph[a - 1].append(b) graph[b - 1].append(a) for i in range(q): p, x = LI() point[p - 1] += x dfs(1) print((*point)) if __name__ == "__main__": main()
false
74.774775
[ "+from math import floor, ceil, sqrt, factorial, log, gcd", "+from itertools import (", "+ accumulate,", "+ permutations,", "+ combinations,", "+ product,", "+ combinations_with_replacement,", "+)", "+from bisect import bisect_left, bisect_right", "+from collections import Counter, defaultdict", "+from heapq import heappop, heappush, heappushpop", "+import copy", "+import numpy as np", "-sys.setrecursionlimit(10**7)", "-N, Q = list(map(int, input().split()))", "-root = [[] for _ in range(N)]", "-ans = [0] * N", "-for _ in range(N - 1):", "- a, b = list(map(int, input().split()))", "- a, b = a - 1, b - 1", "- root[a].append(b)", "- root[b].append(a)", "-for _ in range(Q):", "- p, x = list(map(int, input().split()))", "- ans[p - 1] += x", "-visited = [False] * N", "+INF = float(\"inf\")", "+mod = 10**9 + 7", "+sys.setrecursionlimit(10**6)", "-def dfs(v):", "- visited[v] = True", "- for go in root[v]:", "- if visited[go]:", "- continue", "- ans[go] += ans[v]", "- dfs(go)", "+def lcm(a, b):", "+ return a * b / gcd(a, b)", "-dfs(0)", "-print((*ans))", "+# 1 2 3", "+# a, b, c = LI()", "+def LI():", "+ return list(map(int, sys.stdin.buffer.readline().rsplit()))", "+", "+", "+# a = I()", "+def I():", "+ return int(sys.stdin.buffer.readline())", "+", "+", "+# abc def", "+# a, b = LS()", "+def LS():", "+ return sys.stdin.buffer.readline().rstrip().decode(\"utf-8\").split()", "+", "+", "+# a = S()", "+def S():", "+ return sys.stdin.buffer.readline().rstrip().decode(\"utf-8\")", "+", "+", "+# 2", "+# 1", "+# 2", "+# [1, 2]", "+def IR(n):", "+ return [I() for i in range(n)]", "+", "+", "+# 2", "+# 1 2 3", "+# 4 5 6", "+# [[1,2,3], [4,5,6]]", "+def LIR(n):", "+ return [LI() for i in range(n)]", "+", "+", "+# 2", "+# abc", "+# def", "+# [abc, def]", "+def SR(n):", "+ return [S() for i in range(n)]", "+", "+", "+# 2", "+# abc def", "+# ghi jkl", "+# [[abc,def], [ghi,jkl]]", "+def LSR(n):", "+ return [LS() for i in range(n)]", "+", "+", "+# 2", "+# abcd", "+# efgh", "+# [[a,b,c,d], [e,f,g,h]]", "+def SRL(n):", "+ return [list(S()) for i in range(n)]", "+", "+", "+n, q = LI()", "+point = [0] * n", "+graph = [[] for i in range(n)]", "+visited = [False] * n", "+", "+", "+def dfs(n):", "+ visited[n - 1] = True", "+ for node in graph[n - 1]:", "+ if visited[node - 1]:", "+ continue", "+ point[node - 1] += point[n - 1]", "+ dfs(node)", "+", "+", "+def main():", "+ for i in range(n - 1):", "+ a, b = LI()", "+ graph[a - 1].append(b)", "+ graph[b - 1].append(a)", "+ for i in range(q):", "+ p, x = LI()", "+ point[p - 1] += x", "+ dfs(1)", "+ print((*point))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.039941
0.110031
0.362999
[ "s133520958", "s283607958" ]
u600402037
p02891
python
s795243305
s286598611
19
17
3,188
3,064
Accepted
Accepted
10.53
S = list(eval(input())) K = int(eval(input())) S2 = S[:] if len(S) == 1: print((K//2)) exit() cons = 0 for i in range(len(S)-1): if S[i] == S[i+1]: cons += 1 S[i+1] = '_' if K == 1: print(cons) exit() if S[0] != S[-1]: print((cons * K)) exit() cons3 = 0 if len(set(S2)) == 1: S2 = S2 * 2 + [''] for i in range(len(S2) - 1): if S2[i] == S2[i+1]: cons3 += 1 S2[i+1] = '_' print((cons3 * (K//2) + cons * (K%2))) exit() # 最初から何文字連続するか # この時最後の連続する文字はすでに奇数でかつ最初の文字と一緒 cons2 = 1 j = 0 while True: if S2[j] == S2[j+1]: cons2 += 1 j += 1 else: break if cons2 % 2 == 0: minus = 0 else: minus = 1 print((cons * K + minus * (K-1) ))
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) S = list(sr()) K = ir() def count(s): t = s.copy() cur = '' ret = 0 for i in range(len(t)): if t[i] == cur: t[i] = '_' ret += 1 cur = t[i] return ret one = count(S) two = count(S + S) diff = count(S * 3) - count(S) if K&1: answer = one + (K//2) * diff else: answer = two + ((K//2)-1) * diff print(answer) # 24
42
31
776
536
S = list(eval(input())) K = int(eval(input())) S2 = S[:] if len(S) == 1: print((K // 2)) exit() cons = 0 for i in range(len(S) - 1): if S[i] == S[i + 1]: cons += 1 S[i + 1] = "_" if K == 1: print(cons) exit() if S[0] != S[-1]: print((cons * K)) exit() cons3 = 0 if len(set(S2)) == 1: S2 = S2 * 2 + [""] for i in range(len(S2) - 1): if S2[i] == S2[i + 1]: cons3 += 1 S2[i + 1] = "_" print((cons3 * (K // 2) + cons * (K % 2))) exit() # 最初から何文字連続するか # この時最後の連続する文字はすでに奇数でかつ最初の文字と一緒 cons2 = 1 j = 0 while True: if S2[j] == S2[j + 1]: cons2 += 1 j += 1 else: break if cons2 % 2 == 0: minus = 0 else: minus = 1 print((cons * K + minus * (K - 1)))
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) S = list(sr()) K = ir() def count(s): t = s.copy() cur = "" ret = 0 for i in range(len(t)): if t[i] == cur: t[i] = "_" ret += 1 cur = t[i] return ret one = count(S) two = count(S + S) diff = count(S * 3) - count(S) if K & 1: answer = one + (K // 2) * diff else: answer = two + ((K // 2) - 1) * diff print(answer) # 24
false
26.190476
[ "-S = list(eval(input()))", "-K = int(eval(input()))", "-S2 = S[:]", "-if len(S) == 1:", "- print((K // 2))", "- exit()", "-cons = 0", "-for i in range(len(S) - 1):", "- if S[i] == S[i + 1]:", "- cons += 1", "- S[i + 1] = \"_\"", "-if K == 1:", "- print(cons)", "- exit()", "-if S[0] != S[-1]:", "- print((cons * K))", "- exit()", "-cons3 = 0", "-if len(set(S2)) == 1:", "- S2 = S2 * 2 + [\"\"]", "- for i in range(len(S2) - 1):", "- if S2[i] == S2[i + 1]:", "- cons3 += 1", "- S2[i + 1] = \"_\"", "- print((cons3 * (K // 2) + cons * (K % 2)))", "- exit()", "-# 最初から何文字連続するか", "-# この時最後の連続する文字はすでに奇数でかつ最初の文字と一緒", "-cons2 = 1", "-j = 0", "-while True:", "- if S2[j] == S2[j + 1]:", "- cons2 += 1", "- j += 1", "- else:", "- break", "-if cons2 % 2 == 0:", "- minus = 0", "+import sys", "+", "+sr = lambda: sys.stdin.readline().rstrip()", "+ir = lambda: int(sr())", "+lr = lambda: list(map(int, sr().split()))", "+S = list(sr())", "+K = ir()", "+", "+", "+def count(s):", "+ t = s.copy()", "+ cur = \"\"", "+ ret = 0", "+ for i in range(len(t)):", "+ if t[i] == cur:", "+ t[i] = \"_\"", "+ ret += 1", "+ cur = t[i]", "+ return ret", "+", "+", "+one = count(S)", "+two = count(S + S)", "+diff = count(S * 3) - count(S)", "+if K & 1:", "+ answer = one + (K // 2) * diff", "- minus = 1", "-print((cons * K + minus * (K - 1)))", "+ answer = two + ((K // 2) - 1) * diff", "+print(answer)", "+# 24" ]
false
0.070423
0.055953
1.258598
[ "s795243305", "s286598611" ]
u891635666
p03087
python
s468911530
s956157701
579
335
32,292
6,436
Accepted
Accepted
42.14
import bisect n, q = list(map(int, input().split())) s = input().strip() lrs = [list(map(int, input().split())) for _ in range(q)] indices = [] for i, (c0, c1) in enumerate(zip(s, s[1:])): if c0 == 'A' and c1 == 'C': indices.append(i) indices_c = [i + 1 for i in indices] for (l, r) in lrs: li = bisect.bisect_left(indices, l - 1) ri = bisect.bisect_left(indices_c, r) print((ri - li))
import sys input = sys.stdin.readline ri = lambda: int(eval(input())) rs = lambda: input().rstrip() ril = lambda: list(map(int, input().split())) rsl = lambda: input().rstrip().split() ris = lambda n: [ri() for _ in range(n)] rss = lambda n: [rs() for _ in range(n)] rils = lambda n: [ril() for _ in range(n)] rsls = lambda n: [rsl() for _ in range(n)] n, q = ril() s = rs() acc = [0] * n for i in range(1, n): if s[i - 1:i + 1] == 'AC': acc[i] = acc[i - 1] + 1 else: acc[i] = acc[i - 1] for _ in range(q): l, r = ril() print((acc[r - 1] - acc[l - 1]))
16
24
419
602
import bisect n, q = list(map(int, input().split())) s = input().strip() lrs = [list(map(int, input().split())) for _ in range(q)] indices = [] for i, (c0, c1) in enumerate(zip(s, s[1:])): if c0 == "A" and c1 == "C": indices.append(i) indices_c = [i + 1 for i in indices] for (l, r) in lrs: li = bisect.bisect_left(indices, l - 1) ri = bisect.bisect_left(indices_c, r) print((ri - li))
import sys input = sys.stdin.readline ri = lambda: int(eval(input())) rs = lambda: input().rstrip() ril = lambda: list(map(int, input().split())) rsl = lambda: input().rstrip().split() ris = lambda n: [ri() for _ in range(n)] rss = lambda n: [rs() for _ in range(n)] rils = lambda n: [ril() for _ in range(n)] rsls = lambda n: [rsl() for _ in range(n)] n, q = ril() s = rs() acc = [0] * n for i in range(1, n): if s[i - 1 : i + 1] == "AC": acc[i] = acc[i - 1] + 1 else: acc[i] = acc[i - 1] for _ in range(q): l, r = ril() print((acc[r - 1] - acc[l - 1]))
false
33.333333
[ "-import bisect", "+import sys", "-n, q = list(map(int, input().split()))", "-s = input().strip()", "-lrs = [list(map(int, input().split())) for _ in range(q)]", "-indices = []", "-for i, (c0, c1) in enumerate(zip(s, s[1:])):", "- if c0 == \"A\" and c1 == \"C\":", "- indices.append(i)", "-indices_c = [i + 1 for i in indices]", "-for (l, r) in lrs:", "- li = bisect.bisect_left(indices, l - 1)", "- ri = bisect.bisect_left(indices_c, r)", "- print((ri - li))", "+input = sys.stdin.readline", "+ri = lambda: int(eval(input()))", "+rs = lambda: input().rstrip()", "+ril = lambda: list(map(int, input().split()))", "+rsl = lambda: input().rstrip().split()", "+ris = lambda n: [ri() for _ in range(n)]", "+rss = lambda n: [rs() for _ in range(n)]", "+rils = lambda n: [ril() for _ in range(n)]", "+rsls = lambda n: [rsl() for _ in range(n)]", "+n, q = ril()", "+s = rs()", "+acc = [0] * n", "+for i in range(1, n):", "+ if s[i - 1 : i + 1] == \"AC\":", "+ acc[i] = acc[i - 1] + 1", "+ else:", "+ acc[i] = acc[i - 1]", "+for _ in range(q):", "+ l, r = ril()", "+ print((acc[r - 1] - acc[l - 1]))" ]
false
0.045848
0.096346
0.475871
[ "s468911530", "s956157701" ]
u912237403
p00084
python
s013790127
s556548040
20
10
4,192
4,200
Accepted
Accepted
50
s=" " x=input().replace(",",s).replace(".",s).split() print(s.join([w for w in x if 2<len(w)<7]))
s=" " x=input().replace(",",s).replace(".",s).split() x=s.join([w for w in x if 2<len(w)<7]) print(x)
3
4
102
107
s = " " x = input().replace(",", s).replace(".", s).split() print(s.join([w for w in x if 2 < len(w) < 7]))
s = " " x = input().replace(",", s).replace(".", s).split() x = s.join([w for w in x if 2 < len(w) < 7]) print(x)
false
25
[ "-print(s.join([w for w in x if 2 < len(w) < 7]))", "+x = s.join([w for w in x if 2 < len(w) < 7])", "+print(x)" ]
false
0.036622
0.035827
1.02221
[ "s013790127", "s556548040" ]
u133936772
p02898
python
s833860301
s513315336
52
43
11,908
9,988
Accepted
Accepted
17.31
n, k = list(map(int, input().split())) l = list(map(int, input().split())) ans = 0 for i in range(n): if l[i] >= k: ans += 1 print(ans)
_, k = list(map(int, input().split())) l = list(map(int, input().split())) print((sum(1 for i in l if i>=k)))
10
4
147
99
n, k = list(map(int, input().split())) l = list(map(int, input().split())) ans = 0 for i in range(n): if l[i] >= k: ans += 1 print(ans)
_, k = list(map(int, input().split())) l = list(map(int, input().split())) print((sum(1 for i in l if i >= k)))
false
60
[ "-n, k = list(map(int, input().split()))", "+_, k = list(map(int, input().split()))", "-ans = 0", "-for i in range(n):", "- if l[i] >= k:", "- ans += 1", "-print(ans)", "+print((sum(1 for i in l if i >= k)))" ]
false
0.043486
0.044225
0.983288
[ "s833860301", "s513315336" ]
u830054172
p03087
python
s962360887
s197409244
903
300
9,540
7,872
Accepted
Accepted
66.78
N, Q = list(map(int, input().split())) S = eval(input()) t = [0] * (N+1) for i in range(N): t[i+1] = t[i]+(1 if S[i:i+2] == "AC" else 0) for i in range(Q): l, r = list(map(int, input().split())) print((t[r-1]-t[l-1]))
import sys import math N, Q = list(map(int, input().split())) S = eval(input()) a = [0 for _ in range(N)] for i in range(1, N): if S[i-1]+S[i] == "AC": a[i] += 1 + a[i-1] else: a[i] += a[i-1] for _ in range(Q): l, r = list(map(int, sys.stdin.readline().strip().split())) print((a[r-1] - a[l-1]))
8
16
216
326
N, Q = list(map(int, input().split())) S = eval(input()) t = [0] * (N + 1) for i in range(N): t[i + 1] = t[i] + (1 if S[i : i + 2] == "AC" else 0) for i in range(Q): l, r = list(map(int, input().split())) print((t[r - 1] - t[l - 1]))
import sys import math N, Q = list(map(int, input().split())) S = eval(input()) a = [0 for _ in range(N)] for i in range(1, N): if S[i - 1] + S[i] == "AC": a[i] += 1 + a[i - 1] else: a[i] += a[i - 1] for _ in range(Q): l, r = list(map(int, sys.stdin.readline().strip().split())) print((a[r - 1] - a[l - 1]))
false
50
[ "+import sys", "+import math", "+", "-t = [0] * (N + 1)", "-for i in range(N):", "- t[i + 1] = t[i] + (1 if S[i : i + 2] == \"AC\" else 0)", "-for i in range(Q):", "- l, r = list(map(int, input().split()))", "- print((t[r - 1] - t[l - 1]))", "+a = [0 for _ in range(N)]", "+for i in range(1, N):", "+ if S[i - 1] + S[i] == \"AC\":", "+ a[i] += 1 + a[i - 1]", "+ else:", "+ a[i] += a[i - 1]", "+for _ in range(Q):", "+ l, r = list(map(int, sys.stdin.readline().strip().split()))", "+ print((a[r - 1] - a[l - 1]))" ]
false
0.05327
0.063297
0.841595
[ "s962360887", "s197409244" ]
u210827208
p02936
python
s743964402
s646661383
1,830
1,433
105,364
223,188
Accepted
Accepted
21.69
from collections import deque n,q=list(map(int,input().split())) g=[[] for _ in range(n)] for i in range(n-1): a,b=list(map(int,input().split())) g[a-1].append(b-1) g[b-1].append(a-1) c=[0]*n for j in range(q): p,x=list(map(int,input().split())) c[p-1]+=x used=[0]*n used[0]=1 next=deque([0]) while next: v=next.popleft() cost=c[v] for nv in g[v]: if used[nv]: continue used[nv]=1 next.append(nv) c[nv]+=cost print((*c))
import sys sys.setrecursionlimit(10**6) n, q = list(map(int, input().split())) g = [[] for _ in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) g[a - 1].append(b - 1) g[b - 1].append(a - 1) c = [0] * n for j in range(q): p, x = list(map(int, input().split())) c[p - 1] += x used = [0] * n used[0] = 1 def dfs(x): cost=c[x] for nx in g[x]: if used[nx]: continue used[nx]=1 c[nx]+=cost dfs(nx) dfs(0) print((*c))
34
29
523
519
from collections import deque n, q = list(map(int, input().split())) g = [[] for _ in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) g[a - 1].append(b - 1) g[b - 1].append(a - 1) c = [0] * n for j in range(q): p, x = list(map(int, input().split())) c[p - 1] += x used = [0] * n used[0] = 1 next = deque([0]) while next: v = next.popleft() cost = c[v] for nv in g[v]: if used[nv]: continue used[nv] = 1 next.append(nv) c[nv] += cost print((*c))
import sys sys.setrecursionlimit(10**6) n, q = list(map(int, input().split())) g = [[] for _ in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) g[a - 1].append(b - 1) g[b - 1].append(a - 1) c = [0] * n for j in range(q): p, x = list(map(int, input().split())) c[p - 1] += x used = [0] * n used[0] = 1 def dfs(x): cost = c[x] for nx in g[x]: if used[nx]: continue used[nx] = 1 c[nx] += cost dfs(nx) dfs(0) print((*c))
false
14.705882
[ "-from collections import deque", "+import sys", "+sys.setrecursionlimit(10**6)", "-next = deque([0])", "-while next:", "- v = next.popleft()", "- cost = c[v]", "- for nv in g[v]:", "- if used[nv]:", "+", "+", "+def dfs(x):", "+ cost = c[x]", "+ for nx in g[x]:", "+ if used[nx]:", "- used[nv] = 1", "- next.append(nv)", "- c[nv] += cost", "+ used[nx] = 1", "+ c[nx] += cost", "+ dfs(nx)", "+", "+", "+dfs(0)" ]
false
0.048508
0.049055
0.988854
[ "s743964402", "s646661383" ]
u489959379
p03062
python
s112515487
s091316306
80
67
14,412
20,144
Accepted
Accepted
16.25
n = int(eval(input())) a = list(map(int, input().split())) cnt = 0 b = [] for i in range(n): if a[i] < 0: cnt += 1 b.append(abs(a[i])) if cnt % 2 == 0: ans = sum(b) print(ans) else: ans = sum(b) - 2 * min(b) print(ans)
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(eval(input())) A = list(map(int, input().split())) cnt = 0 total = 0 mi = f_inf for a in A: total += abs(a) if a < 0: cnt += 1 if mi > abs(a): mi = abs(a) if cnt % 2 == 0: print(total) else: print((total - mi * 2)) if __name__ == '__main__': resolve()
16
30
262
511
n = int(eval(input())) a = list(map(int, input().split())) cnt = 0 b = [] for i in range(n): if a[i] < 0: cnt += 1 b.append(abs(a[i])) if cnt % 2 == 0: ans = sum(b) print(ans) else: ans = sum(b) - 2 * min(b) print(ans)
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): n = int(eval(input())) A = list(map(int, input().split())) cnt = 0 total = 0 mi = f_inf for a in A: total += abs(a) if a < 0: cnt += 1 if mi > abs(a): mi = abs(a) if cnt % 2 == 0: print(total) else: print((total - mi * 2)) if __name__ == "__main__": resolve()
false
46.666667
[ "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-cnt = 0", "-b = []", "-for i in range(n):", "- if a[i] < 0:", "- cnt += 1", "- b.append(abs(a[i]))", "-if cnt % 2 == 0:", "- ans = sum(b)", "- print(ans)", "-else:", "- ans = sum(b) - 2 * min(b)", "- print(ans)", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+input = sys.stdin.readline", "+f_inf = float(\"inf\")", "+mod = 10**9 + 7", "+", "+", "+def resolve():", "+ n = int(eval(input()))", "+ A = list(map(int, input().split()))", "+ cnt = 0", "+ total = 0", "+ mi = f_inf", "+ for a in A:", "+ total += abs(a)", "+ if a < 0:", "+ cnt += 1", "+ if mi > abs(a):", "+ mi = abs(a)", "+ if cnt % 2 == 0:", "+ print(total)", "+ else:", "+ print((total - mi * 2))", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.085468
0.04608
1.854781
[ "s112515487", "s091316306" ]
u923668099
p02265
python
s296555729
s809667862
4,660
2,350
71,868
71,912
Accepted
Accepted
49.57
from collections import deque n = int(eval(input())) linked_list = deque([]) for i in range(n): line = input().split() cmd = line[0] if len(line) == 2: value = line[1] if cmd == "insert": linked_list.appendleft(value) elif cmd == "delete": if value in linked_list: linked_list.remove(value) elif cmd == "deleteFirst": linked_list.popleft() elif cmd == "deleteLast": linked_list.pop() print((*linked_list))
import sys from collections import deque n = int(sys.stdin.readline()) linked_list = deque([]) for i in range(n): line = sys.stdin.readline().split() cmd = line[0] if len(line) == 2: value = line[1] if cmd == "insert": linked_list.appendleft(value) elif cmd == "delete": if value in linked_list: linked_list.remove(value) elif cmd == "deleteFirst": linked_list.popleft() elif cmd == "deleteLast": linked_list.pop() print((*linked_list))
24
25
506
544
from collections import deque n = int(eval(input())) linked_list = deque([]) for i in range(n): line = input().split() cmd = line[0] if len(line) == 2: value = line[1] if cmd == "insert": linked_list.appendleft(value) elif cmd == "delete": if value in linked_list: linked_list.remove(value) elif cmd == "deleteFirst": linked_list.popleft() elif cmd == "deleteLast": linked_list.pop() print((*linked_list))
import sys from collections import deque n = int(sys.stdin.readline()) linked_list = deque([]) for i in range(n): line = sys.stdin.readline().split() cmd = line[0] if len(line) == 2: value = line[1] if cmd == "insert": linked_list.appendleft(value) elif cmd == "delete": if value in linked_list: linked_list.remove(value) elif cmd == "deleteFirst": linked_list.popleft() elif cmd == "deleteLast": linked_list.pop() print((*linked_list))
false
4
[ "+import sys", "-n = int(eval(input()))", "+n = int(sys.stdin.readline())", "- line = input().split()", "+ line = sys.stdin.readline().split()" ]
false
0.088851
0.087451
1.016016
[ "s296555729", "s809667862" ]
u310381103
p03434
python
s190935920
s204280934
32
28
9,112
9,108
Accepted
Accepted
12.5
n=int(eval(input())) a=sorted(list(map(int,input().split())),reverse=True) ans=0 for i in range(n): if i%2==0: ans+=a[i] else: ans-=a[i] print(ans)
N=eval(input()) a=list(map(int,input().split())) alice=0 bob=0 a=sorted(a,reverse=True) for i in range(int(N)): if i%2==0: alice+=a[i] else: bob+=a[i] print((alice-bob))
9
11
161
195
n = int(eval(input())) a = sorted(list(map(int, input().split())), reverse=True) ans = 0 for i in range(n): if i % 2 == 0: ans += a[i] else: ans -= a[i] print(ans)
N = eval(input()) a = list(map(int, input().split())) alice = 0 bob = 0 a = sorted(a, reverse=True) for i in range(int(N)): if i % 2 == 0: alice += a[i] else: bob += a[i] print((alice - bob))
false
18.181818
[ "-n = int(eval(input()))", "-a = sorted(list(map(int, input().split())), reverse=True)", "-ans = 0", "-for i in range(n):", "+N = eval(input())", "+a = list(map(int, input().split()))", "+alice = 0", "+bob = 0", "+a = sorted(a, reverse=True)", "+for i in range(int(N)):", "- ans += a[i]", "+ alice += a[i]", "- ans -= a[i]", "-print(ans)", "+ bob += a[i]", "+print((alice - bob))" ]
false
0.039995
0.036792
1.087082
[ "s190935920", "s204280934" ]
u367130284
p03449
python
s311738027
s685873770
20
18
3,060
2,940
Accepted
Accepted
10
n=int(eval(input()));a=[list(map(int,input().split()))for i in[1]*2] print((max(sum(a[0][:s+1]+a[1][s:])for s in range(n))))
n,*a=list(map(int,open(0).read().split()));print((max(sum(a[:i+1]+a[n+i:])for i in range(n))))
2
1
117
86
n = int(eval(input())) a = [list(map(int, input().split())) for i in [1] * 2] print((max(sum(a[0][: s + 1] + a[1][s:]) for s in range(n))))
n, *a = list(map(int, open(0).read().split())) print((max(sum(a[: i + 1] + a[n + i :]) for i in range(n))))
false
50
[ "-n = int(eval(input()))", "-a = [list(map(int, input().split())) for i in [1] * 2]", "-print((max(sum(a[0][: s + 1] + a[1][s:]) for s in range(n))))", "+n, *a = list(map(int, open(0).read().split()))", "+print((max(sum(a[: i + 1] + a[n + i :]) for i in range(n))))" ]
false
0.037579
0.034691
1.083261
[ "s311738027", "s685873770" ]
u150984829
p02386
python
s798215108
s549344524
80
70
5,616
5,608
Accepted
Accepted
12.5
n=int(eval(input())) a=[list(map(int,input().split()))for _ in range(n)] for k in range(n): b=a[k];b[3],b[4]=b[4],b[3] t=0 for i in range(n-1): if t==1:break d=a[i] for j in range(i+1,n): if t==1:break e=a[j] for p in('012345','152043','215304','302541','410352','514320'): if t==1:break f=[d[int(k)]for k in p] if f[0]==e[0]and f[5]==e[5]: f=f[1:5]*2 for k in range(4): if f[k:k+4]==e[1:5]:t=1;break print((('Yes','No')[t]))
n=int(eval(input())) a=[list(map(int,input().split()))for _ in range(n)] for k in range(n): b=a[k];b[3],b[4]=b[4],b[3] def f(): for i in range(n-1): d=a[i] for j in range(i+1,n): e=a[j] for p in('012345','152043','215304','302541','410352','514320'): f=[d[int(k)]for k in p] if f[0]==e[0]and f[5]==e[5]: f=f[1:5]*2 for k in range(4): if f[k:k+4]==e[1:5]:return 1 return 0 print((('Yes','No')[f()]))
19
17
468
444
n = int(eval(input())) a = [list(map(int, input().split())) for _ in range(n)] for k in range(n): b = a[k] b[3], b[4] = b[4], b[3] t = 0 for i in range(n - 1): if t == 1: break d = a[i] for j in range(i + 1, n): if t == 1: break e = a[j] for p in ("012345", "152043", "215304", "302541", "410352", "514320"): if t == 1: break f = [d[int(k)] for k in p] if f[0] == e[0] and f[5] == e[5]: f = f[1:5] * 2 for k in range(4): if f[k : k + 4] == e[1:5]: t = 1 break print((("Yes", "No")[t]))
n = int(eval(input())) a = [list(map(int, input().split())) for _ in range(n)] for k in range(n): b = a[k] b[3], b[4] = b[4], b[3] def f(): for i in range(n - 1): d = a[i] for j in range(i + 1, n): e = a[j] for p in ("012345", "152043", "215304", "302541", "410352", "514320"): f = [d[int(k)] for k in p] if f[0] == e[0] and f[5] == e[5]: f = f[1:5] * 2 for k in range(4): if f[k : k + 4] == e[1:5]: return 1 return 0 print((("Yes", "No")[f()]))
false
10.526316
[ "-t = 0", "-for i in range(n - 1):", "- if t == 1:", "- break", "- d = a[i]", "- for j in range(i + 1, n):", "- if t == 1:", "- break", "- e = a[j]", "- for p in (\"012345\", \"152043\", \"215304\", \"302541\", \"410352\", \"514320\"):", "- if t == 1:", "- break", "- f = [d[int(k)] for k in p]", "- if f[0] == e[0] and f[5] == e[5]:", "- f = f[1:5] * 2", "- for k in range(4):", "- if f[k : k + 4] == e[1:5]:", "- t = 1", "- break", "-print(((\"Yes\", \"No\")[t]))", "+", "+", "+def f():", "+ for i in range(n - 1):", "+ d = a[i]", "+ for j in range(i + 1, n):", "+ e = a[j]", "+ for p in (\"012345\", \"152043\", \"215304\", \"302541\", \"410352\", \"514320\"):", "+ f = [d[int(k)] for k in p]", "+ if f[0] == e[0] and f[5] == e[5]:", "+ f = f[1:5] * 2", "+ for k in range(4):", "+ if f[k : k + 4] == e[1:5]:", "+ return 1", "+ return 0", "+", "+", "+print(((\"Yes\", \"No\")[f()]))" ]
false
0.067674
0.041361
1.636181
[ "s798215108", "s549344524" ]
u703950586
p03295
python
s017921576
s855575677
386
325
55,596
53,424
Accepted
Accepted
15.8
import sys,queue,math,copy,itertools,bisect,collections,heapq sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N,M = LI() island = [0 for _ in range(N)] req = [[] for _ in range(N)] for _ in range(M): a,b = LI() req[a-1].append(b-1) p = 1 ans = 0 for i in range(N): if island[i] > p: ans += 1 p = island[i] for b in req[i]: island[b] = p+1 print (ans)
import sys LI = lambda : [int(x) for x in sys.stdin.readline().split()] N,M = LI() island = [0 for _ in range(N)] req = [[] for _ in range(N)] for _ in range(M): a,b = LI() req[a-1].append(b-1) p = 1 ans = 0 for i in range(N): if island[i] > p: ans += 1 p = island[i] for b in req[i]: island[b] = p+1 print(ans)
25
19
530
371
import sys, queue, math, copy, itertools, bisect, collections, heapq sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda: [int(x) for x in sys.stdin.readline().split()] NI = lambda: int(sys.stdin.readline()) N, M = LI() island = [0 for _ in range(N)] req = [[] for _ in range(N)] for _ in range(M): a, b = LI() req[a - 1].append(b - 1) p = 1 ans = 0 for i in range(N): if island[i] > p: ans += 1 p = island[i] for b in req[i]: island[b] = p + 1 print(ans)
import sys LI = lambda: [int(x) for x in sys.stdin.readline().split()] N, M = LI() island = [0 for _ in range(N)] req = [[] for _ in range(N)] for _ in range(M): a, b = LI() req[a - 1].append(b - 1) p = 1 ans = 0 for i in range(N): if island[i] > p: ans += 1 p = island[i] for b in req[i]: island[b] = p + 1 print(ans)
false
24
[ "-import sys, queue, math, copy, itertools, bisect, collections, heapq", "+import sys", "-sys.setrecursionlimit(10**7)", "-INF = 10**18", "-MOD = 10**9 + 7", "-NI = lambda: int(sys.stdin.readline())" ]
false
0.04047
0.040997
0.987161
[ "s017921576", "s855575677" ]
u506910932
p03060
python
s991049479
s356966745
568
17
2,940
2,940
Accepted
Accepted
97.01
def dfs(now,val,cost): if now == n: return val - cost else: return max(dfs(now+1,val+v[now],cost+c[now]),dfs(now+1,val,cost)) n = int(eval(input())) v = list(map(int,input().split())) c = list(map(int,input().split())) print((dfs(0,0,0)))
# def dfs(now,val,cost): # if now == n: # return val - cost # else: # return max(dfs(now+1,val+v[now],cost+c[now]),dfs(now+1,val,cost)) n = int(eval(input())) v = list(map(int, input().split())) c = list(map(int, input().split())) # print(dfs(0,0,0)) ans = 0 for i in range(n): tmp = v[i] - c[i] if tmp > 0: ans += tmp print(ans)
11
17
267
382
def dfs(now, val, cost): if now == n: return val - cost else: return max(dfs(now + 1, val + v[now], cost + c[now]), dfs(now + 1, val, cost)) n = int(eval(input())) v = list(map(int, input().split())) c = list(map(int, input().split())) print((dfs(0, 0, 0)))
# def dfs(now,val,cost): # if now == n: # return val - cost # else: # return max(dfs(now+1,val+v[now],cost+c[now]),dfs(now+1,val,cost)) n = int(eval(input())) v = list(map(int, input().split())) c = list(map(int, input().split())) # print(dfs(0,0,0)) ans = 0 for i in range(n): tmp = v[i] - c[i] if tmp > 0: ans += tmp print(ans)
false
35.294118
[ "-def dfs(now, val, cost):", "- if now == n:", "- return val - cost", "- else:", "- return max(dfs(now + 1, val + v[now], cost + c[now]), dfs(now + 1, val, cost))", "-", "-", "+# def dfs(now,val,cost):", "+# if now == n:", "+# return val - cost", "+# else:", "+# return max(dfs(now+1,val+v[now],cost+c[now]),dfs(now+1,val,cost))", "-print((dfs(0, 0, 0)))", "+# print(dfs(0,0,0))", "+ans = 0", "+for i in range(n):", "+ tmp = v[i] - c[i]", "+ if tmp > 0:", "+ ans += tmp", "+print(ans)" ]
false
0.096716
0.036274
2.666303
[ "s991049479", "s356966745" ]
u992910889
p03162
python
s125988117
s764130041
630
407
61,528
72,156
Accepted
Accepted
35.4
# import bisect # import copy # import fractions # import math # import numpy as np # from collections import Counter, deque # from itertools import accumulate,permutations, combinations,combinations_with_replacement,product def resolve(): n=int(eval(input())) [A,B,C]=[[0]*n for _ in range(3)] for i in range(n): A[i],B[i],C[i]=list(map(int,input().split())) dp=[[0]*3 for _ in range(n)] dp[0]=[A[0],B[0],C[0]] for i in range(n-1): dp[i+1][0]=max(dp[i][1]+A[i+1],dp[i][2]+A[i+1]) dp[i+1][1]=max(dp[i][0]+B[i+1],dp[i][2]+B[i+1]) dp[i+1][2]=max(dp[i][0]+C[i+1],dp[i][1]+C[i+1]) print((max(dp[n-1]))) resolve()
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): # https://qiita.com/drken/items/dc53c683d6de8aeacf5a#dp-%E5%AE%9F%E8%A3%85%E3%81%AE%E9%A0%86%E5%BA%8F INF = 10**10 # INF+INFを計算してもオーバーフローしない範囲で大きく N = int(eval(input())) L=[list(map(int,input().split())) for i in range(N+1)] # dpテーブル dp[i][j]:=i日目にjを行なって得られる幸福度のmax W=3 dp = [[-1]*3 for _ in range(N+1)] """ 初期化の値は, 最小化問題:INF, 最大化問題:-INF(0以上の値しか取らないなら-1, あるいは0でもいいかも) 数え上げ問題:0 確率問題:0 Yes/No判定問題:False """ # 初期条件 for j in range(W): dp[0][j] = 0 # ループ for i in range(1,N+1): for j in range(W): """ dp[from] の値の更新が完了していればノード from からノード to への緩和を行っていい.貰うdpであれ配るdpであれ. 両者の違いを意識すべきケースはcf. https://qiita.com/drken/items/ace3142967c4f01d42e9#%E8%B2%B0%E3%81%86-dp-%E3%81%A8%E9%85%8D%E3%82%8B-dp-%E3%81%AE%E6%AF%94%E8%BC%83 # 遷移式がたくさんある場合この中でさらにforループを回したりする cf. https://atcoder.jp/contests/dp/tasks/dp_b """ for k in range(W): if j!=k: dp[i][j]=max(dp[i][j],dp[i-1][k]+L[i-1][k]) # 出力 print((max(dp[N]))) resolve()
29
50
691
1,361
# import bisect # import copy # import fractions # import math # import numpy as np # from collections import Counter, deque # from itertools import accumulate,permutations, combinations,combinations_with_replacement,product def resolve(): n = int(eval(input())) [A, B, C] = [[0] * n for _ in range(3)] for i in range(n): A[i], B[i], C[i] = list(map(int, input().split())) dp = [[0] * 3 for _ in range(n)] dp[0] = [A[0], B[0], C[0]] for i in range(n - 1): dp[i + 1][0] = max(dp[i][1] + A[i + 1], dp[i][2] + A[i + 1]) dp[i + 1][1] = max(dp[i][0] + B[i + 1], dp[i][2] + B[i + 1]) dp[i + 1][2] = max(dp[i][0] + C[i + 1], dp[i][1] + C[i + 1]) print((max(dp[n - 1]))) resolve()
import sys sys.setrecursionlimit(10**5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): # https://qiita.com/drken/items/dc53c683d6de8aeacf5a#dp-%E5%AE%9F%E8%A3%85%E3%81%AE%E9%A0%86%E5%BA%8F INF = 10**10 # INF+INFを計算してもオーバーフローしない範囲で大きく N = int(eval(input())) L = [list(map(int, input().split())) for i in range(N + 1)] # dpテーブル dp[i][j]:=i日目にjを行なって得られる幸福度のmax W = 3 dp = [[-1] * 3 for _ in range(N + 1)] """ 初期化の値は, 最小化問題:INF, 最大化問題:-INF(0以上の値しか取らないなら-1, あるいは0でもいいかも) 数え上げ問題:0 確率問題:0 Yes/No判定問題:False """ # 初期条件 for j in range(W): dp[0][j] = 0 # ループ for i in range(1, N + 1): for j in range(W): """ dp[from] の値の更新が完了していればノード from からノード to への緩和を行っていい.貰うdpであれ配るdpであれ. 両者の違いを意識すべきケースはcf. https://qiita.com/drken/items/ace3142967c4f01d42e9#%E8%B2%B0%E3%81%86-dp-%E3%81%A8%E9%85%8D%E3%82%8B-dp-%E3%81%AE%E6%AF%94%E8%BC%83 # 遷移式がたくさんある場合この中でさらにforループを回したりする cf. https://atcoder.jp/contests/dp/tasks/dp_b """ for k in range(W): if j != k: dp[i][j] = max(dp[i][j], dp[i - 1][k] + L[i - 1][k]) # 出力 print((max(dp[N]))) resolve()
false
42
[ "-# import bisect", "-# import copy", "-# import fractions", "-# import math", "-# import numpy as np", "-# from collections import Counter, deque", "-# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product", "+import sys", "+", "+sys.setrecursionlimit(10**5 + 10)", "+", "+", "+def input():", "+ return sys.stdin.readline().strip()", "+", "+", "- n = int(eval(input()))", "- [A, B, C] = [[0] * n for _ in range(3)]", "- for i in range(n):", "- A[i], B[i], C[i] = list(map(int, input().split()))", "- dp = [[0] * 3 for _ in range(n)]", "- dp[0] = [A[0], B[0], C[0]]", "- for i in range(n - 1):", "- dp[i + 1][0] = max(dp[i][1] + A[i + 1], dp[i][2] + A[i + 1])", "- dp[i + 1][1] = max(dp[i][0] + B[i + 1], dp[i][2] + B[i + 1])", "- dp[i + 1][2] = max(dp[i][0] + C[i + 1], dp[i][1] + C[i + 1])", "- print((max(dp[n - 1])))", "+ # https://qiita.com/drken/items/dc53c683d6de8aeacf5a#dp-%E5%AE%9F%E8%A3%85%E3%81%AE%E9%A0%86%E5%BA%8F", "+ INF = 10**10 # INF+INFを計算してもオーバーフローしない範囲で大きく", "+ N = int(eval(input()))", "+ L = [list(map(int, input().split())) for i in range(N + 1)]", "+ # dpテーブル dp[i][j]:=i日目にjを行なって得られる幸福度のmax", "+ W = 3", "+ dp = [[-1] * 3 for _ in range(N + 1)]", "+ \"\"\"", "+ 初期化の値は,", "+ 最小化問題:INF,", "+ 最大化問題:-INF(0以上の値しか取らないなら-1, あるいは0でもいいかも)", "+ 数え上げ問題:0", "+ 確率問題:0", "+ Yes/No判定問題:False", "+ \"\"\"", "+ # 初期条件", "+ for j in range(W):", "+ dp[0][j] = 0", "+ # ループ", "+ for i in range(1, N + 1):", "+ for j in range(W):", "+ \"\"\"", "+ dp[from] の値の更新が完了していればノード from からノード to への緩和を行っていい.貰うdpであれ配るdpであれ.", "+ 両者の違いを意識すべきケースはcf.", "+ https://qiita.com/drken/items/ace3142967c4f01d42e9#%E8%B2%B0%E3%81%86-dp-%E3%81%A8%E9%85%8D%E3%82%8B-dp-%E3%81%AE%E6%AF%94%E8%BC%83", "+ # 遷移式がたくさんある場合この中でさらにforループを回したりする cf. https://atcoder.jp/contests/dp/tasks/dp_b", "+ \"\"\"", "+ for k in range(W):", "+ if j != k:", "+ dp[i][j] = max(dp[i][j], dp[i - 1][k] + L[i - 1][k])", "+ # 出力", "+ print((max(dp[N])))" ]
false
0.113856
0.042452
2.68197
[ "s125988117", "s764130041" ]
u493520238
p02726
python
s284561754
s012924803
1,930
1,430
3,444
3,444
Accepted
Accepted
25.91
n, x, y = list(map(int, input().split())) ans = [0] * n for i in range(1,n): for j in range(i+1, n+1): r1 = j-i r2 = abs(x-i) + 1 + abs(j-y) r3 = abs(y-i) + 1 + abs(j-x) ans[min(r1,r2,r3)] += 1 for i in range(1,n): print((ans[i]))
def main(): n, x, y = list(map(int, input().split())) ans = [0] * n for i in range(1,n): for j in range(i+1, n+1): r1 = j-i r2 = abs(x-i) + 1 + abs(j-y) r3 = abs(y-i) + 1 + abs(j-x) ans[min(r1,r2,r3)] += 1 for i in range(1,n): print((ans[i])) if __name__ == "__main__": main()
12
16
276
371
n, x, y = list(map(int, input().split())) ans = [0] * n for i in range(1, n): for j in range(i + 1, n + 1): r1 = j - i r2 = abs(x - i) + 1 + abs(j - y) r3 = abs(y - i) + 1 + abs(j - x) ans[min(r1, r2, r3)] += 1 for i in range(1, n): print((ans[i]))
def main(): n, x, y = list(map(int, input().split())) ans = [0] * n for i in range(1, n): for j in range(i + 1, n + 1): r1 = j - i r2 = abs(x - i) + 1 + abs(j - y) r3 = abs(y - i) + 1 + abs(j - x) ans[min(r1, r2, r3)] += 1 for i in range(1, n): print((ans[i])) if __name__ == "__main__": main()
false
25
[ "-n, x, y = list(map(int, input().split()))", "-ans = [0] * n", "-for i in range(1, n):", "- for j in range(i + 1, n + 1):", "- r1 = j - i", "- r2 = abs(x - i) + 1 + abs(j - y)", "- r3 = abs(y - i) + 1 + abs(j - x)", "- ans[min(r1, r2, r3)] += 1", "-for i in range(1, n):", "- print((ans[i]))", "+def main():", "+ n, x, y = list(map(int, input().split()))", "+ ans = [0] * n", "+ for i in range(1, n):", "+ for j in range(i + 1, n + 1):", "+ r1 = j - i", "+ r2 = abs(x - i) + 1 + abs(j - y)", "+ r3 = abs(y - i) + 1 + abs(j - x)", "+ ans[min(r1, r2, r3)] += 1", "+ for i in range(1, n):", "+ print((ans[i]))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.037816
0.042616
0.887356
[ "s284561754", "s012924803" ]
u550146922
p02659
python
s875346364
s509446318
42
30
10,372
10,060
Accepted
Accepted
28.57
from math import floor from fractions import Fraction a, b = input().split() a = int(a) b = Fraction(b) print((floor(a * b)))
from math import floor from decimal import Decimal a, b = input().split() a = int(a) b = Decimal(b) print((floor(a * b)))
6
6
128
124
from math import floor from fractions import Fraction a, b = input().split() a = int(a) b = Fraction(b) print((floor(a * b)))
from math import floor from decimal import Decimal a, b = input().split() a = int(a) b = Decimal(b) print((floor(a * b)))
false
0
[ "-from fractions import Fraction", "+from decimal import Decimal", "-b = Fraction(b)", "+b = Decimal(b)" ]
false
0.045719
0.043815
1.04345
[ "s875346364", "s509446318" ]