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
u486065927
p02733
python
s745840572
s735289908
1,692
332
3,188
3,364
Accepted
Accepted
80.38
#na- import itertools H, W, K = list(map(int,input().split())) S = [list(map(int,list(eval(input())))) for _ in range(H)] def check(k): if k <= K: return(True) else: return(False) noans = 0 def make_lst(i): global noans, lst, havelst temp = S[0][i] for h in range(H-1): if y[h]: lst.append(temp) temp = S[h+1][i] else: temp += S[h+1][i] lst.append(temp) if check(max(lst)): havelst = 1 else: noans = 1 def nocut(i): global cutnum, lst, havelst prelst = [] temp = S[0][i] j = 0 for h in range(H-1): if y[h]: lst[j] += temp prelst.append(temp) j += 1 temp = S[h+1][i] else: temp += S[h+1][i] prelst.append(temp) lst[-1] += temp if check(max(lst)): return(True) else: cutnum += 1 lst = prelst ans = float("inf") cutlst = [] for y in itertools.product((0, 1), repeat=H-1): havelst = 0 lst = [] cutnum = sum(y) for x in range(W): if noans: break if havelst: nocut(x) else: make_lst(x) if noans==1: noans = 0 continue ans = min(cutnum, ans) print(ans)
def add(in1, in2): return [a + b for a, b in zip(in1, in2)] def split(ar, k, w): a = 0 if max(max(ar)) > k: return -1 tm = ar[0] for i in range(1, w): tm = add(tm, ar[i]) if max(tm) > k: a += 1 tm = ar[i] return a h, w, k = list(map(int, input().split())) s = [[int(i) for i in eval(input())] for j in range(h)] ans = h*w for i in range(2**(h-1)): data = [] temp = s[0] sp = bin(i+2**h)[4:] if ans < sp.count("1"): continue for j in range(1, h): if sp[j-1] == "0": temp = add(temp, s[j]) else: data.append(temp) temp = s[j] data.append(temp) ans_ = split([list(x) for x in zip(*data)], k, w) if ans_ == -1: continue ans_ += sp.count("1") if ans > ans_: ans = ans_ print(ans)
65
39
1,404
901
# na- import itertools H, W, K = list(map(int, input().split())) S = [list(map(int, list(eval(input())))) for _ in range(H)] def check(k): if k <= K: return True else: return False noans = 0 def make_lst(i): global noans, lst, havelst temp = S[0][i] for h in range(H - 1): if y[h]: lst.append(temp) temp = S[h + 1][i] else: temp += S[h + 1][i] lst.append(temp) if check(max(lst)): havelst = 1 else: noans = 1 def nocut(i): global cutnum, lst, havelst prelst = [] temp = S[0][i] j = 0 for h in range(H - 1): if y[h]: lst[j] += temp prelst.append(temp) j += 1 temp = S[h + 1][i] else: temp += S[h + 1][i] prelst.append(temp) lst[-1] += temp if check(max(lst)): return True else: cutnum += 1 lst = prelst ans = float("inf") cutlst = [] for y in itertools.product((0, 1), repeat=H - 1): havelst = 0 lst = [] cutnum = sum(y) for x in range(W): if noans: break if havelst: nocut(x) else: make_lst(x) if noans == 1: noans = 0 continue ans = min(cutnum, ans) print(ans)
def add(in1, in2): return [a + b for a, b in zip(in1, in2)] def split(ar, k, w): a = 0 if max(max(ar)) > k: return -1 tm = ar[0] for i in range(1, w): tm = add(tm, ar[i]) if max(tm) > k: a += 1 tm = ar[i] return a h, w, k = list(map(int, input().split())) s = [[int(i) for i in eval(input())] for j in range(h)] ans = h * w for i in range(2 ** (h - 1)): data = [] temp = s[0] sp = bin(i + 2**h)[4:] if ans < sp.count("1"): continue for j in range(1, h): if sp[j - 1] == "0": temp = add(temp, s[j]) else: data.append(temp) temp = s[j] data.append(temp) ans_ = split([list(x) for x in zip(*data)], k, w) if ans_ == -1: continue ans_ += sp.count("1") if ans > ans_: ans = ans_ print(ans)
false
40
[ "-# na-", "-import itertools", "-", "-H, W, K = list(map(int, input().split()))", "-S = [list(map(int, list(eval(input())))) for _ in range(H)]", "+def add(in1, in2):", "+ return [a + b for a, b in zip(in1, in2)]", "-def check(k):", "- if k <= K:", "- return True", "- else:", "...
false
0.177599
0.137445
1.292142
[ "s745840572", "s735289908" ]
u697713131
p03073
python
s143290887
s082983640
64
22
3,956
4,268
Accepted
Accepted
65.62
t = list(eval(input())) def count(t,start): ans = 0 for i in range(len(t)): if (i%2 == 0) and (t[i] != start): ans += 1 if (i%2 == 1) and (t[i] == start): ans += 1 return ans ans = min(count(t,'0'), count(t,'1')) print(ans)
t = list(eval(input())) ans = min(t[::2].count('0') + t[1::2].count('1'),t[::2].count('1') + t[1::2].count('0')) print(ans)
13
5
301
129
t = list(eval(input())) def count(t, start): ans = 0 for i in range(len(t)): if (i % 2 == 0) and (t[i] != start): ans += 1 if (i % 2 == 1) and (t[i] == start): ans += 1 return ans ans = min(count(t, "0"), count(t, "1")) print(ans)
t = list(eval(input())) ans = min( t[::2].count("0") + t[1::2].count("1"), t[::2].count("1") + t[1::2].count("0") ) print(ans)
false
61.538462
[ "-", "-", "-def count(t, start):", "- ans = 0", "- for i in range(len(t)):", "- if (i % 2 == 0) and (t[i] != start):", "- ans += 1", "- if (i % 2 == 1) and (t[i] == start):", "- ans += 1", "- return ans", "-", "-", "-ans = min(count(t, \"0\"), cou...
false
0.034876
0.035956
0.969962
[ "s143290887", "s082983640" ]
u657913472
p03662
python
s072994405
s211847461
1,477
1,366
188,532
179,384
Accepted
Accepted
7.52
from networkx import* (N,),*t=[s.split()for s in open(0)] G=Graph() for a,b in t:G.add_edge(a,b) s=shortest_path_length x=s(G,'1') y=s(G,N) c=0 for k in y:c+=x[k]>y[k] print(('FSennunkeec'[c*2>=int(N)::2]))
from networkx import* N,*t=open(0) G=Graph() for s in t:a,b=s.split();G.add_edge(a,b) s=shortest_path_length x=s(G,'1') y=s(G,N[:-1]) print(('FSennunkeec'[sum(x[k]>y[k]for k in x)*2>=int(N)::2]))
10
8
213
200
from networkx import * (N,), *t = [s.split() for s in open(0)] G = Graph() for a, b in t: G.add_edge(a, b) s = shortest_path_length x = s(G, "1") y = s(G, N) c = 0 for k in y: c += x[k] > y[k] print(("FSennunkeec"[c * 2 >= int(N) :: 2]))
from networkx import * N, *t = open(0) G = Graph() for s in t: a, b = s.split() G.add_edge(a, b) s = shortest_path_length x = s(G, "1") y = s(G, N[:-1]) print(("FSennunkeec"[sum(x[k] > y[k] for k in x) * 2 >= int(N) :: 2]))
false
20
[ "-(N,), *t = [s.split() for s in open(0)]", "+N, *t = open(0)", "-for a, b in t:", "+for s in t:", "+ a, b = s.split()", "-y = s(G, N)", "-c = 0", "-for k in y:", "- c += x[k] > y[k]", "-print((\"FSennunkeec\"[c * 2 >= int(N) :: 2]))", "+y = s(G, N[:-1])", "+print((\"FSennunkeec\"[sum(x[...
false
0.043524
0.043916
0.991074
[ "s072994405", "s211847461" ]
u996665352
p02690
python
s899057729
s345338353
30
24
9,152
9,100
Accepted
Accepted
20
import sys import itertools X = int(eval(input())) N = 300 ABs = [] for i in range(N): ABs.append(i**5) for i in range(N): for j in range(N): if ABs[i]-ABs[j] == X: print((i,j)) sys.exit() elif ABs[i]+ABs[j] == X: print((i,-j)) sys.exit()
import sys import itertools X = int(eval(input())) N = 120 ABs = [] for i in range(N): ABs.append(i**5) for i in range(N): for j in range(N): if ABs[i]-ABs[j] == X: print((i,j)) sys.exit() elif ABs[i]+ABs[j] == X: print((i,-j)) sys.exit()
16
16
320
320
import sys import itertools X = int(eval(input())) N = 300 ABs = [] for i in range(N): ABs.append(i**5) for i in range(N): for j in range(N): if ABs[i] - ABs[j] == X: print((i, j)) sys.exit() elif ABs[i] + ABs[j] == X: print((i, -j)) sys.exit()
import sys import itertools X = int(eval(input())) N = 120 ABs = [] for i in range(N): ABs.append(i**5) for i in range(N): for j in range(N): if ABs[i] - ABs[j] == X: print((i, j)) sys.exit() elif ABs[i] + ABs[j] == X: print((i, -j)) sys.exit()
false
0
[ "-N = 300", "+N = 120" ]
false
0.042171
0.040021
1.05371
[ "s899057729", "s345338353" ]
u316386814
p04006
python
s547873178
s054847805
1,998
724
3,316
14,540
Accepted
Accepted
63.76
N, x = list(map(int, input().split())) A = list(map(int, input().split())) A += A INF = 10 ** 18 ans = INF B = [INF] * N for cnt in range(N): for i in range(N): B[i] = min(B[i], A[N + i - cnt]) ans = min(ans, cnt * x + sum(B)) print(ans)
import numpy as np N, x = list(map(int, input().split())) A = list(map(int, input().split())) A += A A = np.array(A, int) INF = 10 ** 18 ans = INF B = np.ones(N, int) * INF for cnt in range(N): np.minimum(A[N-cnt:2*N-cnt], B, B) ans = min(ans, cnt * x + np.sum(B)) print(ans)
12
13
259
290
N, x = list(map(int, input().split())) A = list(map(int, input().split())) A += A INF = 10**18 ans = INF B = [INF] * N for cnt in range(N): for i in range(N): B[i] = min(B[i], A[N + i - cnt]) ans = min(ans, cnt * x + sum(B)) print(ans)
import numpy as np N, x = list(map(int, input().split())) A = list(map(int, input().split())) A += A A = np.array(A, int) INF = 10**18 ans = INF B = np.ones(N, int) * INF for cnt in range(N): np.minimum(A[N - cnt : 2 * N - cnt], B, B) ans = min(ans, cnt * x + np.sum(B)) print(ans)
false
7.692308
[ "+import numpy as np", "+", "+A = np.array(A, int)", "-B = [INF] * N", "+B = np.ones(N, int) * INF", "- for i in range(N):", "- B[i] = min(B[i], A[N + i - cnt])", "- ans = min(ans, cnt * x + sum(B))", "+ np.minimum(A[N - cnt : 2 * N - cnt], B, B)", "+ ans = min(ans, cnt * x + np...
false
0.071739
0.425068
0.16877
[ "s547873178", "s054847805" ]
u214600613
p01138
python
s997286093
s955808598
4,190
3,020
11,500
11,712
Accepted
Accepted
27.92
m=24*60*60 while True: n=int(eval(input())) if n==0:break dp=[0]*(m+1) for _ in range(n): a,d=input().split() a,b,c=list(map(int,a.split(':'))); d,e,f=list(map(int,d.split(':'))); dp[a*3600+b*60+c]+=1 dp[d*3600+e*60+f]-=1 for i in range(m): dp[i+1]+=dp[i] print((max(dp)))
m=24*60*60 while True: n=int(input()) if n==0:break dp=[0]*(m+1) for _ in range(n): a,d=input().split() a,b,c=list(map(int,a.split(':'))); d,e,f=list(map(int,d.split(':'))); dp[a*3600+b*60+c]+=1 dp[d*3600+e*60+f]-=1 for i in range(m): dp[i+1]+=dp[i] print((max(dp)))
14
14
283
291
m = 24 * 60 * 60 while True: n = int(eval(input())) if n == 0: break dp = [0] * (m + 1) for _ in range(n): a, d = input().split() a, b, c = list(map(int, a.split(":"))) d, e, f = list(map(int, d.split(":"))) dp[a * 3600 + b * 60 + c] += 1 dp[d * 3600 + e * 60 + f] -= 1 for i in range(m): dp[i + 1] += dp[i] print((max(dp)))
m = 24 * 60 * 60 while True: n = int(input()) if n == 0: break dp = [0] * (m + 1) for _ in range(n): a, d = input().split() a, b, c = list(map(int, a.split(":"))) d, e, f = list(map(int, d.split(":"))) dp[a * 3600 + b * 60 + c] += 1 dp[d * 3600 + e * 60 + f] -= 1 for i in range(m): dp[i + 1] += dp[i] print((max(dp)))
false
0
[ "- n = int(eval(input()))", "+ n = int(input())" ]
false
0.257326
0.241969
1.063465
[ "s997286093", "s955808598" ]
u137962336
p02681
python
s219188621
s170968314
24
21
8,812
8,808
Accepted
Accepted
12.5
s = eval(input()) t = eval(input()) if t[:-1] == s: print("Yes") else: print("No")
s = eval(input()) t = eval(input()) if s == t[:-1]: print("Yes") else: print("No")
6
6
84
85
s = eval(input()) t = eval(input()) if t[:-1] == s: print("Yes") else: print("No")
s = eval(input()) t = eval(input()) if s == t[:-1]: print("Yes") else: print("No")
false
0
[ "-if t[:-1] == s:", "+if s == t[:-1]:" ]
false
0.042712
0.04685
0.911672
[ "s219188621", "s170968314" ]
u277312083
p03478
python
s813412936
s694177694
37
27
3,060
3,060
Accepted
Accepted
27.03
n, a, b = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): s = sum(list(map(int, list(str(i))))) if a <= s and s <= b: ans += i print(ans)
n, a, b = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): j = i d = 0 while j != 0: d += j % 10 j //= 10 if a <= d and d <= b: ans += i print(ans)
7
11
172
208
n, a, b = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): s = sum(list(map(int, list(str(i))))) if a <= s and s <= b: ans += i print(ans)
n, a, b = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): j = i d = 0 while j != 0: d += j % 10 j //= 10 if a <= d and d <= b: ans += i print(ans)
false
36.363636
[ "- s = sum(list(map(int, list(str(i)))))", "- if a <= s and s <= b:", "+ j = i", "+ d = 0", "+ while j != 0:", "+ d += j % 10", "+ j //= 10", "+ if a <= d and d <= b:" ]
false
0.035912
0.035841
1.001961
[ "s813412936", "s694177694" ]
u857673087
p03292
python
s644412522
s488431342
23
17
3,316
2,940
Accepted
Accepted
26.09
a,b,c = sorted(map(int,input().split())) print(( c - a))
A = list(map(int, input().split())) print((max(A)-min(A)))
3
2
57
57
a, b, c = sorted(map(int, input().split())) print((c - a))
A = list(map(int, input().split())) print((max(A) - min(A)))
false
33.333333
[ "-a, b, c = sorted(map(int, input().split()))", "-print((c - a))", "+A = list(map(int, input().split()))", "+print((max(A) - min(A)))" ]
false
0.075303
0.043901
1.715287
[ "s644412522", "s488431342" ]
u994988729
p03987
python
s643561298
s858153842
606
332
100,860
46,492
Accepted
Accepted
45.21
class BinaryIndexTree: # 1-indexed def __init__(self, N): """ INPUT N [int] -> 全部0で初期化 N [list] -> そのまま初期化 """ if isinstance(N, int): self.N = N self.depth = N.bit_length() self.tree = [0] * (N + 1) self.elem = [0] * (N + 1) elif isinstance(N, list): self.N = len(N) self.depth = self.N.bit_length() self.tree = [0] + N self.elem = [0] + N self._init() else: raise "INVALID INPUT: input must be int or list" def _init(self): size = self.N + 1 for i in range(1, self.N): if i + (i & -i) > size: continue self.tree[i + (i & -i)] += self.tree[i] def add(self, i, x): self.elem[i] += x while i <= self.N: self.tree[i] += x i += i & -i def sum(self, i): res = 0 while i > 0: res += self.tree[i] i -= i & -i return res def lower_bound(self, val): if val <= 0: return 0 i = 0 k = 1 << self.depth while k: if i + k <= self.N and self.tree[i + k] < val: val -= self.tree[i + k] i += k k >>= 1 return i + 1 if __name__ == "__main__": N = int(eval(input())) P = list(map(int, input().split())) idx = {a: i for i, a in enumerate(P, start=1)} bit = BinaryIndexTree(N) ans = 0 for i in range(1, N + 1): bit.add(idx[i], 1) s = bit.sum(idx[i]) l = bit.lower_bound(s)-bit.lower_bound(s-1) r = bit.lower_bound(s+1) - idx[i] ans += i*l*r print(ans)
N = int(eval(input())) A = list(map(int, input().split())) a_to_i = {a: i for i, a in enumerate(A, start=1)} L = [i - 1 for i in range(N + 2)] R = [i + 1 for i in range(N + 2)] ans = 0 for a in range(N, 0, -1): i = a_to_i[a] ans += a * (R[i] - i) * (i - L[i]) L[R[i]] = L[i] R[L[i]] = R[i] print(ans)
68
15
1,822
327
class BinaryIndexTree: # 1-indexed def __init__(self, N): """ INPUT N [int] -> 全部0で初期化 N [list] -> そのまま初期化 """ if isinstance(N, int): self.N = N self.depth = N.bit_length() self.tree = [0] * (N + 1) self.elem = [0] * (N + 1) elif isinstance(N, list): self.N = len(N) self.depth = self.N.bit_length() self.tree = [0] + N self.elem = [0] + N self._init() else: raise "INVALID INPUT: input must be int or list" def _init(self): size = self.N + 1 for i in range(1, self.N): if i + (i & -i) > size: continue self.tree[i + (i & -i)] += self.tree[i] def add(self, i, x): self.elem[i] += x while i <= self.N: self.tree[i] += x i += i & -i def sum(self, i): res = 0 while i > 0: res += self.tree[i] i -= i & -i return res def lower_bound(self, val): if val <= 0: return 0 i = 0 k = 1 << self.depth while k: if i + k <= self.N and self.tree[i + k] < val: val -= self.tree[i + k] i += k k >>= 1 return i + 1 if __name__ == "__main__": N = int(eval(input())) P = list(map(int, input().split())) idx = {a: i for i, a in enumerate(P, start=1)} bit = BinaryIndexTree(N) ans = 0 for i in range(1, N + 1): bit.add(idx[i], 1) s = bit.sum(idx[i]) l = bit.lower_bound(s) - bit.lower_bound(s - 1) r = bit.lower_bound(s + 1) - idx[i] ans += i * l * r print(ans)
N = int(eval(input())) A = list(map(int, input().split())) a_to_i = {a: i for i, a in enumerate(A, start=1)} L = [i - 1 for i in range(N + 2)] R = [i + 1 for i in range(N + 2)] ans = 0 for a in range(N, 0, -1): i = a_to_i[a] ans += a * (R[i] - i) * (i - L[i]) L[R[i]] = L[i] R[L[i]] = R[i] print(ans)
false
77.941176
[ "-class BinaryIndexTree: # 1-indexed", "- def __init__(self, N):", "- \"\"\"", "- INPUT", "- N [int] -> 全部0で初期化", "- N [list] -> そのまま初期化", "- \"\"\"", "- if isinstance(N, int):", "- self.N = N", "- self.depth = N.bit_length()", ...
false
0.036763
0.035784
1.027361
[ "s643561298", "s858153842" ]
u059727354
p02669
python
s553237051
s666736043
1,478
476
145,716
90,240
Accepted
Accepted
67.79
import sys divs = [2, 3, 5] t = int(eval(input())) for _ in range(t): n, a, b, c, d = list(map(int, input().split())) costs = [a, b, c] dp = {} def dfs(x): if x in dp: return dp[x] # print(x, file=sys.stderr) if x == 0: dp[x] = 0 return dp[x] ret = x * d for i in range(-4, 5): if x - i < 0: continue nx = x - i for cost, div in zip(costs, divs): if nx % div != 0 or nx // div >= x: continue ret = min(ret, dfs(nx // div) + cost + abs(i) * d) dp[x] = ret return ret print((dfs(n)))
divs = [2, 3, 5] t = int(eval(input())) for _ in range(t): n, a, b, c, d = list(map(int, input().split())) costs = [a, b, c] dp = {0: 0} def dfs(x): if x in dp: return dp[x] ret = x * d for cost, div in zip(costs, divs): lx = x // div * div ret = min(ret, dfs(lx // div) + cost + (x - lx) * d) if lx == x: continue lx += div if lx // div >= x: continue ret = min(ret, dfs(lx // div) + cost + (lx - x) * d) dp[x] = ret return ret print((dfs(n)))
38
31
739
652
import sys divs = [2, 3, 5] t = int(eval(input())) for _ in range(t): n, a, b, c, d = list(map(int, input().split())) costs = [a, b, c] dp = {} def dfs(x): if x in dp: return dp[x] # print(x, file=sys.stderr) if x == 0: dp[x] = 0 return dp[x] ret = x * d for i in range(-4, 5): if x - i < 0: continue nx = x - i for cost, div in zip(costs, divs): if nx % div != 0 or nx // div >= x: continue ret = min(ret, dfs(nx // div) + cost + abs(i) * d) dp[x] = ret return ret print((dfs(n)))
divs = [2, 3, 5] t = int(eval(input())) for _ in range(t): n, a, b, c, d = list(map(int, input().split())) costs = [a, b, c] dp = {0: 0} def dfs(x): if x in dp: return dp[x] ret = x * d for cost, div in zip(costs, divs): lx = x // div * div ret = min(ret, dfs(lx // div) + cost + (x - lx) * d) if lx == x: continue lx += div if lx // div >= x: continue ret = min(ret, dfs(lx // div) + cost + (lx - x) * d) dp[x] = ret return ret print((dfs(n)))
false
18.421053
[ "-import sys", "-", "- dp = {}", "+ dp = {0: 0}", "- # print(x, file=sys.stderr)", "- if x == 0:", "- dp[x] = 0", "- return dp[x]", "- for i in range(-4, 5):", "- if x - i < 0:", "+ for cost, div in zip(costs, divs):", "+ ...
false
2.339346
0.167254
13.986762
[ "s553237051", "s666736043" ]
u514390882
p02787
python
s615178890
s632855703
487
377
42,220
43,108
Accepted
Accepted
22.59
h, n = list(map(int, input().split())) ab = [] for i in range(n): ab.append(list(map(int, input().split()))) ###一次元DP dp = [100000000] * (h+1) dp[0] = 0 for i in range(1, h+1): for j in range(n): a = ab[j][0] b = ab[j][1] # print(i, j) temp = i - a if temp < 0: temp = 0 need_magic = dp[temp] + b if need_magic < dp[i]: dp[i] = need_magic # dp[i] = min(dp[i], dp[max(i-a, 0)] + b) # print(i, j, a, b, dp) print((dp[-1]))
h, n = list(map(int, input().split())) dp = [1000000000] * (h+1) dp[0] = 0 for i in range(n): a, b = list(map(int, input().split())) for j in range(h): # nj = min(j + a, h) if j + a < h: nj = j + a else: nj = h # dp[nj] = min(dp[nj], dp[j] + b) if dp[nj] > dp[j] + b: dp[nj] = dp[j] + b print((dp[h]))
21
13
536
360
h, n = list(map(int, input().split())) ab = [] for i in range(n): ab.append(list(map(int, input().split()))) ###一次元DP dp = [100000000] * (h + 1) dp[0] = 0 for i in range(1, h + 1): for j in range(n): a = ab[j][0] b = ab[j][1] # print(i, j) temp = i - a if temp < 0: temp = 0 need_magic = dp[temp] + b if need_magic < dp[i]: dp[i] = need_magic # dp[i] = min(dp[i], dp[max(i-a, 0)] + b) # print(i, j, a, b, dp) print((dp[-1]))
h, n = list(map(int, input().split())) dp = [1000000000] * (h + 1) dp[0] = 0 for i in range(n): a, b = list(map(int, input().split())) for j in range(h): # nj = min(j + a, h) if j + a < h: nj = j + a else: nj = h # dp[nj] = min(dp[nj], dp[j] + b) if dp[nj] > dp[j] + b: dp[nj] = dp[j] + b print((dp[h]))
false
38.095238
[ "-ab = []", "+dp = [1000000000] * (h + 1)", "+dp[0] = 0", "- ab.append(list(map(int, input().split())))", "-###一次元DP", "-dp = [100000000] * (h + 1)", "-dp[0] = 0", "-for i in range(1, h + 1):", "- for j in range(n):", "- a = ab[j][0]", "- b = ab[j][1]", "- # print(i,...
false
0.127063
0.095201
1.334685
[ "s615178890", "s632855703" ]
u370331385
p02842
python
s535746489
s221750366
45
32
3,060
2,940
Accepted
Accepted
28.89
N=int(eval(input())) ans = -1 for i in range(50000+10): x1 = int(i*1.08) x2 = i*1.08 #print(i,x1,x2) if(x1 == N): ans = i elif(x2 == N): ans = i if(ans == -1): print(':(') else: print(ans)
N = int(eval(input())) ans = -1 for x in range(N+1): if(int(x*1.08) == N): ans = x break if(ans == -1): print(':(') else: print(ans)
15
10
210
152
N = int(eval(input())) ans = -1 for i in range(50000 + 10): x1 = int(i * 1.08) x2 = i * 1.08 # print(i,x1,x2) if x1 == N: ans = i elif x2 == N: ans = i if ans == -1: print(":(") else: print(ans)
N = int(eval(input())) ans = -1 for x in range(N + 1): if int(x * 1.08) == N: ans = x break if ans == -1: print(":(") else: print(ans)
false
33.333333
[ "-for i in range(50000 + 10):", "- x1 = int(i * 1.08)", "- x2 = i * 1.08", "- # print(i,x1,x2)", "- if x1 == N:", "- ans = i", "- elif x2 == N:", "- ans = i", "+for x in range(N + 1):", "+ if int(x * 1.08) == N:", "+ ans = x", "+ break" ]
false
0.109843
0.039221
2.800584
[ "s535746489", "s221750366" ]
u644907318
p03347
python
s893540939
s096466336
796
262
57,304
87,680
Accepted
Accepted
67.09
N = int(eval(input())) cnt = 0 A = [int(eval(input())) for _ in range(N)] if A[0]!=0: cnt = -1 else: for i in range(1,N): if A[i]==A[i-1]+1: continue elif A[i]<=A[i-1]: cnt += A[i-1] else: cnt = -1 break if cnt>=0: cnt += A[N-1] print(cnt)
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] cnt = A[-1] flag = 0 for i in range(N-2,-1,-1): if A[i]==A[i+1] or A[i]>A[i+1]: cnt += A[i] elif A[i] == A[i+1]-1: continue else: flag = 1 break if A[0]!=0: flag = 1 if flag==0: print(cnt) else: print((-1))
17
18
337
331
N = int(eval(input())) cnt = 0 A = [int(eval(input())) for _ in range(N)] if A[0] != 0: cnt = -1 else: for i in range(1, N): if A[i] == A[i - 1] + 1: continue elif A[i] <= A[i - 1]: cnt += A[i - 1] else: cnt = -1 break if cnt >= 0: cnt += A[N - 1] print(cnt)
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] cnt = A[-1] flag = 0 for i in range(N - 2, -1, -1): if A[i] == A[i + 1] or A[i] > A[i + 1]: cnt += A[i] elif A[i] == A[i + 1] - 1: continue else: flag = 1 break if A[0] != 0: flag = 1 if flag == 0: print(cnt) else: print((-1))
false
5.555556
[ "-cnt = 0", "+cnt = A[-1]", "+flag = 0", "+for i in range(N - 2, -1, -1):", "+ if A[i] == A[i + 1] or A[i] > A[i + 1]:", "+ cnt += A[i]", "+ elif A[i] == A[i + 1] - 1:", "+ continue", "+ else:", "+ flag = 1", "+ break", "- cnt = -1", "+ flag = 1", ...
false
0.037017
0.036872
1.003935
[ "s893540939", "s096466336" ]
u156815136
p03599
python
s117586436
s359014542
332
203
39,652
40,176
Accepted
Accepted
38.86
# # Written by NoKnowledgeGG @YlePhan # ('ω') # #import math #mod = 10**9+7 #import itertools #import fractions #import numpy as np #mod = 10**4 + 7 """def kiri(n,m): r_ = n / m if (r_ - (n // m)) > 0: return (n//m) + 1 else: return (n//m)""" """ n! mod m 階乗 mod = 1e9 + 7 N = 10000000 fac = [0] * N def ini(): fac[0] = 1 % mod for i in range(1,N): fac[i] = fac[i-1] * i % mod""" """mod = 1e9+7 N = 10000000 pw = [0] * N def ini(c): pw[0] = 1 % mod for i in range(1,N): pw[i] = pw[i-1] * c % mod""" """ def YEILD(): yield 'one' yield 'two' yield 'three' generator = YEILD() print(next(generator)) print(next(generator)) print(next(generator)) """ """def gcd_(a,b): if b == 0:#結局はc,0の最大公約数はcなのに return a return gcd_(a,a % b) # a = p * b + q""" """def extgcd(a,b,x,y): d = a if b!=0: d = extgcd(b,a%b,y,x) y -= (a//b) * x print(x,y) else: x = 1 y = 0 return d""" # 最大公約数 と 最小公倍数 """def gcd(a,b): if b == 0: return a return gcd(b, a % b) def lcm(a,b): g = gcd(a,b) return (a * b) // g""" def readInts(): return list(map(int,input().split())) mod = 10**9 + 7 def main(): A,B,C,D,E,F = readInts() dic = {} for a in range(31):# 30まで for b in range(31): # 30まで for c in range(101): # 100まで for d in range(101): w = (100*A)*a + (100 * B ) *b s = C * c + D * d if w == 0: break if w + s > F: break else: if w/100 * E >= s: mitudo = 100 * s / (w + s) dic[a,b,c,d] = mitudo maxV = max(dic.values()) for k,v in list(dic.items()): if v == maxV: print(((100*A)*k[0] + (100*B)*k[1] + C*k[2] + D*k[3],C*k[2] + D*k[3])) exit() if __name__ == '__main__': main()
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] #from itertools import combinations # (string,3) 3回 #from collections import deque #import collections.defaultdict(list) #import bisect # # # pythonで無理なときは、pypyでやると正解するかも!! # # mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): a,b,c,d,e,f = readInts() water = set() sugar = set() # water # A,B の制約が 1 <= A,B <= 30 だから、ループは31まで回せば位 for i in range(31): for j in range(31): w = 100 * a * i + 100 * b * j if w <= f: # 水の合計が F より大きくなってはいけない (砂糖0gの時もあるが、) # -1g とかはないので water.add(w) # sugar # C,D の制約が、 1 <= C,D <= 3000 であるから、 3001 までまわせばい for i in range(3001): for j in range(3001): s = c * i + d * j if s <= f: # 砂糖の合計が F より大きくなってはいけない # 水 0 g はあっても、-1gとかはないから sugar.add(s) # 濃度の限界値を決める nl = e/(100 + e) # *100 すれば、限界の濃度のパーセント noudo = -1 ans1 = 0 ans2 = 0 for s in sugar: for w in water: # 砂糖水をつくる sum = s + w if sum == 0:# 和が0はだめー てか1 <= だから 1からループ回せばええやんけ continue x = s/sum # suger / 砂糖水 * 100 すれば%やで if sum <= f and x <= nl and x > noudo: # 砂糖水は fg以下 , 砂糖水の濃度は限界以下 , 濃度が最大になるまで回せ noudo = x ans1 = sum ans2 = s print((ans1,ans2)) if __name__ == '__main__': main()
95
57
1,880
1,622
# # Written by NoKnowledgeGG @YlePhan # ('ω') # # import math # mod = 10**9+7 # import itertools # import fractions # import numpy as np # mod = 10**4 + 7 """def kiri(n,m): r_ = n / m if (r_ - (n // m)) > 0: return (n//m) + 1 else: return (n//m)""" """ n! mod m 階乗 mod = 1e9 + 7 N = 10000000 fac = [0] * N def ini(): fac[0] = 1 % mod for i in range(1,N): fac[i] = fac[i-1] * i % mod""" """mod = 1e9+7 N = 10000000 pw = [0] * N def ini(c): pw[0] = 1 % mod for i in range(1,N): pw[i] = pw[i-1] * c % mod""" """ def YEILD(): yield 'one' yield 'two' yield 'three' generator = YEILD() print(next(generator)) print(next(generator)) print(next(generator)) """ """def gcd_(a,b): if b == 0:#結局はc,0の最大公約数はcなのに return a return gcd_(a,a % b) # a = p * b + q""" """def extgcd(a,b,x,y): d = a if b!=0: d = extgcd(b,a%b,y,x) y -= (a//b) * x print(x,y) else: x = 1 y = 0 return d""" # 最大公約数 と 最小公倍数 """def gcd(a,b): if b == 0: return a return gcd(b, a % b) def lcm(a,b): g = gcd(a,b) return (a * b) // g""" def readInts(): return list(map(int, input().split())) mod = 10**9 + 7 def main(): A, B, C, D, E, F = readInts() dic = {} for a in range(31): # 30まで for b in range(31): # 30まで for c in range(101): # 100まで for d in range(101): w = (100 * A) * a + (100 * B) * b s = C * c + D * d if w == 0: break if w + s > F: break else: if w / 100 * E >= s: mitudo = 100 * s / (w + s) dic[a, b, c, d] = mitudo maxV = max(dic.values()) for k, v in list(dic.items()): if v == maxV: print( ( (100 * A) * k[0] + (100 * B) * k[1] + C * k[2] + D * k[3], C * k[2] + D * k[3], ) ) exit() if __name__ == "__main__": main()
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] # from itertools import combinations # (string,3) 3回 # from collections import deque # import collections.defaultdict(list) # import bisect # # # pythonで無理なときは、pypyでやると正解するかも!! # # mod = 10**9 + 7 def readInts(): return list(map(int, input().split())) def main(): a, b, c, d, e, f = readInts() water = set() sugar = set() # water # A,B の制約が 1 <= A,B <= 30 だから、ループは31まで回せば位 for i in range(31): for j in range(31): w = 100 * a * i + 100 * b * j if w <= f: # 水の合計が F より大きくなってはいけない (砂糖0gの時もあるが、) # -1g とかはないので water.add(w) # sugar # C,D の制約が、 1 <= C,D <= 3000 であるから、 3001 までまわせばい for i in range(3001): for j in range(3001): s = c * i + d * j if s <= f: # 砂糖の合計が F より大きくなってはいけない # 水 0 g はあっても、-1gとかはないから sugar.add(s) # 濃度の限界値を決める nl = e / (100 + e) # *100 すれば、限界の濃度のパーセント noudo = -1 ans1 = 0 ans2 = 0 for s in sugar: for w in water: # 砂糖水をつくる sum = s + w if sum == 0: # 和が0はだめー てか1 <= だから 1からループ回せばええやんけ continue x = s / sum # suger / 砂糖水 * 100 すれば%やで if sum <= f and x <= nl and x > noudo: # 砂糖水は fg以下 , 砂糖水の濃度は限界以下 , 濃度が最大になるまで回せ noudo = x ans1 = sum ans2 = s print((ans1, ans2)) if __name__ == "__main__": main()
false
40
[ "+# from statistics import median", "+# import collections", "+# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]", "+# from itertools import combinations # (string,3) 3回", "+# from collections import deque", "+# import collections.defaultdict(list)", "+# import bisect",...
false
0.127315
2.287112
0.055666
[ "s117586436", "s359014542" ]
u440180827
p02409
python
s199600179
s453619629
30
20
7,720
7,636
Accepted
Accepted
33.33
rooms = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] n = int(input()) for i in range(n): b, f, r, v= map(int, input().split()) rooms[b-1][f-1][r-1] += v for i in range(4): for j in range(3): for k in range(10): print('', rooms[i][j][k], end='') print() if i < 3: print('####################')
rooms = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] n = int(input()) for i in range(n): b, f, r, v= map(int, input().split()) rooms[b-1][f-1][r-1] += v for i in range(4): for j in range(3): for k in range(10): print('', rooms[i][j][k], end='') print() if i < 3: print('#' * 20)
12
12
373
359
rooms = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] n = int(input()) for i in range(n): b, f, r, v = map(int, input().split()) rooms[b - 1][f - 1][r - 1] += v for i in range(4): for j in range(3): for k in range(10): print("", rooms[i][j][k], end="") print() if i < 3: print("####################")
rooms = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] n = int(input()) for i in range(n): b, f, r, v = map(int, input().split()) rooms[b - 1][f - 1][r - 1] += v for i in range(4): for j in range(3): for k in range(10): print("", rooms[i][j][k], end="") print() if i < 3: print("#" * 20)
false
0
[ "- print(\"####################\")", "+ print(\"#\" * 20)" ]
false
0.042242
0.058111
0.726914
[ "s199600179", "s453619629" ]
u241159583
p03037
python
s363500422
s639726552
332
297
11,020
10,996
Accepted
Accepted
10.54
N, M = [int(x) for x in input().split()] L = [] R = [] for _ in range(M): l, r = [int(x) for x in input().split()] L.append(l) R.append(r) ans = min(R) - max(L) + 1 print((ans if ans >= 0 else 0))
N, M = list(map(int, input().split())) L = [] R = [] for _ in range(M): l, r = list(map(int, input().split())) L.append(l) R.append(r) l = max(L) r = min(R) print((r-l+1 if r-l+1 > 0 else 0))
10
11
210
194
N, M = [int(x) for x in input().split()] L = [] R = [] for _ in range(M): l, r = [int(x) for x in input().split()] L.append(l) R.append(r) ans = min(R) - max(L) + 1 print((ans if ans >= 0 else 0))
N, M = list(map(int, input().split())) L = [] R = [] for _ in range(M): l, r = list(map(int, input().split())) L.append(l) R.append(r) l = max(L) r = min(R) print((r - l + 1 if r - l + 1 > 0 else 0))
false
9.090909
[ "-N, M = [int(x) for x in input().split()]", "+N, M = list(map(int, input().split()))", "- l, r = [int(x) for x in input().split()]", "+ l, r = list(map(int, input().split()))", "-ans = min(R) - max(L) + 1", "-print((ans if ans >= 0 else 0))", "+l = max(L)", "+r = min(R)", "+print((r - l + 1 i...
false
0.041221
0.04239
0.97242
[ "s363500422", "s639726552" ]
u847467233
p02269
python
s294153692
s380978253
4,550
1,040
33,112
33,716
Accepted
Accepted
77.14
# AOJ ALDS1_4_C Dictionary # Python3 2018.7.3 bal4u dic = {} n = int(eval(input())) for i in range(n): id, s = input().split() if id == "insert": dic[s] = 1 else: print(("yes" if s in dic else "no"))
# AOJ ALDS1_4_C Dictionary # Python3 2018.7.3 bal4u import sys from sys import stdin input = stdin.readline dic = {} n = int(eval(input())) for i in range(n): s = eval(input()) if s[0] == 'i': dic[s[7:]] = 1 else: print(("yes" if s[5:] in dic else "no"))
9
13
204
258
# AOJ ALDS1_4_C Dictionary # Python3 2018.7.3 bal4u dic = {} n = int(eval(input())) for i in range(n): id, s = input().split() if id == "insert": dic[s] = 1 else: print(("yes" if s in dic else "no"))
# AOJ ALDS1_4_C Dictionary # Python3 2018.7.3 bal4u import sys from sys import stdin input = stdin.readline dic = {} n = int(eval(input())) for i in range(n): s = eval(input()) if s[0] == "i": dic[s[7:]] = 1 else: print(("yes" if s[5:] in dic else "no"))
false
30.769231
[ "+import sys", "+from sys import stdin", "+", "+input = stdin.readline", "- id, s = input().split()", "- if id == \"insert\":", "- dic[s] = 1", "+ s = eval(input())", "+ if s[0] == \"i\":", "+ dic[s[7:]] = 1", "- print((\"yes\" if s in dic else \"no\"))", "+ ...
false
0.038044
0.041885
0.908305
[ "s294153692", "s380978253" ]
u729133443
p02820
python
s396071339
s686480112
186
47
44,004
3,956
Accepted
Accepted
74.73
*n,t=open(0).read().split() n,k,r,s,p=list(map(int,n)) d={'r':p,'s':r,'p':s} b=['']*n*2 a=0 for i,c in enumerate(t[:n]): if c!=b[i-k]: b[i]=c a+=d[c] print(a)
*n,t=open(0).read().split() n,k,r,s,p=list(map(int,n)) *t,=t for i in range(n-k): if t[i+k]==t[i]:t[i+k]=5 a,b,c=list(map(t.count,'rsp')) print((a*p+b*r+c*s))
10
7
171
152
*n, t = open(0).read().split() n, k, r, s, p = list(map(int, n)) d = {"r": p, "s": r, "p": s} b = [""] * n * 2 a = 0 for i, c in enumerate(t[:n]): if c != b[i - k]: b[i] = c a += d[c] print(a)
*n, t = open(0).read().split() n, k, r, s, p = list(map(int, n)) (*t,) = t for i in range(n - k): if t[i + k] == t[i]: t[i + k] = 5 a, b, c = list(map(t.count, "rsp")) print((a * p + b * r + c * s))
false
30
[ "-d = {\"r\": p, \"s\": r, \"p\": s}", "-b = [\"\"] * n * 2", "-a = 0", "-for i, c in enumerate(t[:n]):", "- if c != b[i - k]:", "- b[i] = c", "- a += d[c]", "-print(a)", "+(*t,) = t", "+for i in range(n - k):", "+ if t[i + k] == t[i]:", "+ t[i + k] = 5", "+a, b, c...
false
0.053104
0.132943
0.399451
[ "s396071339", "s686480112" ]
u620259318
p02594
python
s048749571
s484445775
30
26
8,952
9,160
Accepted
Accepted
13.33
deg = int(eval(input())) if deg >= 30: print("Yes") else: print("No")
n = int(eval(input())) if n < 30: print("No") else: print("Yes")
6
6
78
72
deg = int(eval(input())) if deg >= 30: print("Yes") else: print("No")
n = int(eval(input())) if n < 30: print("No") else: print("Yes")
false
0
[ "-deg = int(eval(input()))", "-if deg >= 30:", "+n = int(eval(input()))", "+if n < 30:", "+ print(\"No\")", "+else:", "-else:", "- print(\"No\")" ]
false
0.033867
0.040165
0.84321
[ "s048749571", "s484445775" ]
u576432509
p03353
python
s821591478
s834702014
48
39
3,060
4,464
Accepted
Accepted
18.75
s=eval(input()) k=int(eval(input())) #s=list(input()) #t=[] #for kk in range(k): # t.append(s) t=["zzzzz"]*k for i in range(len(s)): for j in range(i,min(len(s),i+k)): sij=s[i:j+1] for kk in range(k): if t[kk]==sij: break if t[kk]>sij: t[kk]=sij t.sort() print((t[k-1])) #print(t)
s=eval(input()) k=int(eval(input())) sb=set() for i in range(len(s)): for ii in range(i,i+k): if ii<len(s): # print(s[i:ii+1]) sb.add(s[i:ii+1]) sb2=list(sb) sb2.sort() print((sb2[k-1]))
23
12
392
232
s = eval(input()) k = int(eval(input())) # s=list(input()) # t=[] # for kk in range(k): # t.append(s) t = ["zzzzz"] * k for i in range(len(s)): for j in range(i, min(len(s), i + k)): sij = s[i : j + 1] for kk in range(k): if t[kk] == sij: break if t[kk] > sij: t[kk] = sij t.sort() print((t[k - 1])) # print(t)
s = eval(input()) k = int(eval(input())) sb = set() for i in range(len(s)): for ii in range(i, i + k): if ii < len(s): # print(s[i:ii+1]) sb.add(s[i : ii + 1]) sb2 = list(sb) sb2.sort() print((sb2[k - 1]))
false
47.826087
[ "-# s=list(input())", "-# t=[]", "-# for kk in range(k):", "-# t.append(s)", "-t = [\"zzzzz\"] * k", "+sb = set()", "- for j in range(i, min(len(s), i + k)):", "- sij = s[i : j + 1]", "- for kk in range(k):", "- if t[kk] == sij:", "- break", "- ...
false
0.034716
0.037864
0.916862
[ "s821591478", "s834702014" ]
u204842730
p02695
python
s145556041
s535866120
1,248
1,078
9,136
9,168
Accepted
Accepted
13.62
import itertools n,m,q=list(map(int,input().split())) lis=[] ans=0 for _ in range(q): a,b,c,d = list(map(int, input().split())) lis.append([a-1,b-1,c,d]) for i in itertools.combinations_with_replacement(list(range(1,m+1)),n): tmp=0 for j in range(q): if i[lis[j][1]] - i[lis[j][0]] == lis[j][2]: tmp+=lis[j][3] ans=max(ans,tmp) print(ans)
import itertools n,m,q=list(map(int,input().split())) a=[0 for i in range(q)] b=[0 for i in range(q)] c=[0 for i in range(q)] d=[0 for i in range(q)] for i in range(q): a[i],b[i],c[i],d[i]=list(map(int,input().split())) a[i]-=1 b[i]-=1 ans=0 for i in itertools.combinations_with_replacement(list(range(1,m+1)),n): tmp=0 for j in range(q): if i[b[j]] - i[a[j]] == c[j]: tmp+=d[j] ans=max(ans,tmp) print(ans)
16
19
377
451
import itertools n, m, q = list(map(int, input().split())) lis = [] ans = 0 for _ in range(q): a, b, c, d = list(map(int, input().split())) lis.append([a - 1, b - 1, c, d]) for i in itertools.combinations_with_replacement(list(range(1, m + 1)), n): tmp = 0 for j in range(q): if i[lis[j][1]] - i[lis[j][0]] == lis[j][2]: tmp += lis[j][3] ans = max(ans, tmp) print(ans)
import itertools n, m, q = list(map(int, input().split())) a = [0 for i in range(q)] b = [0 for i in range(q)] c = [0 for i in range(q)] d = [0 for i in range(q)] for i in range(q): a[i], b[i], c[i], d[i] = list(map(int, input().split())) a[i] -= 1 b[i] -= 1 ans = 0 for i in itertools.combinations_with_replacement(list(range(1, m + 1)), n): tmp = 0 for j in range(q): if i[b[j]] - i[a[j]] == c[j]: tmp += d[j] ans = max(ans, tmp) print(ans)
false
15.789474
[ "-lis = []", "+a = [0 for i in range(q)]", "+b = [0 for i in range(q)]", "+c = [0 for i in range(q)]", "+d = [0 for i in range(q)]", "+for i in range(q):", "+ a[i], b[i], c[i], d[i] = list(map(int, input().split()))", "+ a[i] -= 1", "+ b[i] -= 1", "-for _ in range(q):", "- a, b, c, d...
false
0.068176
0.059296
1.149766
[ "s145556041", "s535866120" ]
u936985471
p02792
python
s650046256
s923145262
219
172
3,444
3,316
Accepted
Accepted
21.46
N=int(eval(input())) from collections import defaultdict dic=defaultdict(int) for i in range(1,N+1): n=str(i) dic[(int(n[0]),int(n[-1]))]+=1 ans=0 for i in range(1,10): for j in range(1,10): ans+=dic[(i,j)]*dic[(j,i)] print(ans)
from collections import defaultdict as d dic=d(int) for i in range(1,int(eval(input()))+1): dic[(int(str(i)[0]),i%10)]+=1 ans=0 for i in range(10): for j in range(10): ans+=dic[(i,j)]*dic[(j,i)] print(ans)
14
9
254
215
N = int(eval(input())) from collections import defaultdict dic = defaultdict(int) for i in range(1, N + 1): n = str(i) dic[(int(n[0]), int(n[-1]))] += 1 ans = 0 for i in range(1, 10): for j in range(1, 10): ans += dic[(i, j)] * dic[(j, i)] print(ans)
from collections import defaultdict as d dic = d(int) for i in range(1, int(eval(input())) + 1): dic[(int(str(i)[0]), i % 10)] += 1 ans = 0 for i in range(10): for j in range(10): ans += dic[(i, j)] * dic[(j, i)] print(ans)
false
35.714286
[ "-N = int(eval(input()))", "-from collections import defaultdict", "+from collections import defaultdict as d", "-dic = defaultdict(int)", "-for i in range(1, N + 1):", "- n = str(i)", "- dic[(int(n[0]), int(n[-1]))] += 1", "+dic = d(int)", "+for i in range(1, int(eval(input())) + 1):", "+ ...
false
0.216078
0.070873
3.048818
[ "s650046256", "s923145262" ]
u340781749
p03246
python
s382678019
s406852386
113
76
21,568
18,656
Accepted
Accepted
32.74
from collections import Counter from itertools import takewhile n = int(eval(input())) vvv = list(map(int, input().split())) cnt1 = Counter(vvv[0::2]) cnt2 = Counter(vvv[1::2]) mc1 = cnt1.most_common() mc2 = cnt2.most_common() mcs1 = list(takewhile(lambda x: x[1] == mc1[0][1], mc1)) mcs2 = list(takewhile(lambda x: x[1] == mc2[0][1], mc2)) if len(mcs1) == len(mcs2) and mcs1[0][0] == mcs2[0][0]: if len(mc1) > 1: if len(mc2) > 1: print((min(n - mc1[0][1] - mc2[1][1], n - mc1[1][1] - mc2[0][1]))) else: print((min(n - mc1[0][1], n - mc1[1][1] - mc2[0][1]))) else: if len(mc2) > 1: print((min(n - mc1[0][1] - mc2[1][1], n - mc2[0][1]))) else: print((min(n - mc1[0][1], n - mc2[0][1]))) else: print((n - mc1[0][1] - mc2[0][1]))
from collections import Counter n = int(eval(input())) vvv = list(map(int, input().split())) cnt1 = Counter(vvv[0::2]) cnt2 = Counter(vvv[1::2]) mc1 = cnt1.most_common(2) mc2 = cnt2.most_common(2) if mc1[0][0] == mc2[0][0]: sc1 = mc1[1][1] if len(mc1) > 1 else 0 sc2 = mc2[1][1] if len(mc2) > 1 else 0 print((min(n - mc1[0][1] - sc2, n - sc1 - mc2[0][1]))) else: print((n - mc1[0][1] - mc2[0][1]))
24
14
827
418
from collections import Counter from itertools import takewhile n = int(eval(input())) vvv = list(map(int, input().split())) cnt1 = Counter(vvv[0::2]) cnt2 = Counter(vvv[1::2]) mc1 = cnt1.most_common() mc2 = cnt2.most_common() mcs1 = list(takewhile(lambda x: x[1] == mc1[0][1], mc1)) mcs2 = list(takewhile(lambda x: x[1] == mc2[0][1], mc2)) if len(mcs1) == len(mcs2) and mcs1[0][0] == mcs2[0][0]: if len(mc1) > 1: if len(mc2) > 1: print((min(n - mc1[0][1] - mc2[1][1], n - mc1[1][1] - mc2[0][1]))) else: print((min(n - mc1[0][1], n - mc1[1][1] - mc2[0][1]))) else: if len(mc2) > 1: print((min(n - mc1[0][1] - mc2[1][1], n - mc2[0][1]))) else: print((min(n - mc1[0][1], n - mc2[0][1]))) else: print((n - mc1[0][1] - mc2[0][1]))
from collections import Counter n = int(eval(input())) vvv = list(map(int, input().split())) cnt1 = Counter(vvv[0::2]) cnt2 = Counter(vvv[1::2]) mc1 = cnt1.most_common(2) mc2 = cnt2.most_common(2) if mc1[0][0] == mc2[0][0]: sc1 = mc1[1][1] if len(mc1) > 1 else 0 sc2 = mc2[1][1] if len(mc2) > 1 else 0 print((min(n - mc1[0][1] - sc2, n - sc1 - mc2[0][1]))) else: print((n - mc1[0][1] - mc2[0][1]))
false
41.666667
[ "-from itertools import takewhile", "-mc1 = cnt1.most_common()", "-mc2 = cnt2.most_common()", "-mcs1 = list(takewhile(lambda x: x[1] == mc1[0][1], mc1))", "-mcs2 = list(takewhile(lambda x: x[1] == mc2[0][1], mc2))", "-if len(mcs1) == len(mcs2) and mcs1[0][0] == mcs2[0][0]:", "- if len(mc1) > 1:", "...
false
0.069069
0.100079
0.690142
[ "s382678019", "s406852386" ]
u627803856
p02720
python
s106360108
s686459592
347
223
61,776
65,008
Accepted
Accepted
35.73
k = int(eval(input())) def dfs(d, val, A): A.append(val) if d == 10: return for i in range(-1, 2): add = (val % 10) + i if add >= 0 and add <= 9: dfs(d + 1, val * 10 + add, A) A = [] for v in range(1, 10): # 呼び出し dfs(1, v, A) A.sort() print((A[k - 1]))
def calc_next(arr): res = [] for val in arr: for j in range(-1, 2): add = (val % 10) + j if add >= 0 and add <= 9: res.append(val * 10 + add) return res k = int(eval(input())) cur = [] A = [] for v in range(1, 10): cur.append(v) A.append(v) for d in range(1, 10): cur = calc_next(cur) for val in cur: A.append(val) print((A[k - 1]))
18
24
278
373
k = int(eval(input())) def dfs(d, val, A): A.append(val) if d == 10: return for i in range(-1, 2): add = (val % 10) + i if add >= 0 and add <= 9: dfs(d + 1, val * 10 + add, A) A = [] for v in range(1, 10): # 呼び出し dfs(1, v, A) A.sort() print((A[k - 1]))
def calc_next(arr): res = [] for val in arr: for j in range(-1, 2): add = (val % 10) + j if add >= 0 and add <= 9: res.append(val * 10 + add) return res k = int(eval(input())) cur = [] A = [] for v in range(1, 10): cur.append(v) A.append(v) for d in range(1, 10): cur = calc_next(cur) for val in cur: A.append(val) print((A[k - 1]))
false
25
[ "-k = int(eval(input()))", "+def calc_next(arr):", "+ res = []", "+ for val in arr:", "+ for j in range(-1, 2):", "+ add = (val % 10) + j", "+ if add >= 0 and add <= 9:", "+ res.append(val * 10 + add)", "+ return res", "-def dfs(d, val, A):", ...
false
0.24427
0.141525
1.725982
[ "s106360108", "s686459592" ]
u634046173
p03774
python
s143463593
s602083210
73
66
67,804
66,220
Accepted
Accepted
9.59
N,M = list(map(int,input().split())) students = [list(map(int,input().split()))for i in range(N)] checkPoints = [list(map(int,input().split()))for i in range(M)] for i in range(N): idx = -1 mindis = 3*10**8 sx,sy = students[i] for j in range(M): cx,cy = checkPoints[j] distance = abs(sx-cx)+ abs(sy-cy) if mindis > distance: idx = j+1 mindis = distance print(idx)
N,M = list(map(int,input().split())) students = [list(map(int,input().split()))for i in range(N)] checkPoints = [list(map(int,input().split()))for i in range(M)] for i in range(N): idx = 1 mindis = abs(students[i][0]-checkPoints[0][0])+ abs(students[i][1]-checkPoints[0][1]) sx,sy = students[i] for j in range(1,M): cx,cy = checkPoints[j] distance = abs(sx-cx)+ abs(sy-cy) if mindis > distance: idx = j+1 mindis = distance print(idx)
16
16
443
513
N, M = list(map(int, input().split())) students = [list(map(int, input().split())) for i in range(N)] checkPoints = [list(map(int, input().split())) for i in range(M)] for i in range(N): idx = -1 mindis = 3 * 10**8 sx, sy = students[i] for j in range(M): cx, cy = checkPoints[j] distance = abs(sx - cx) + abs(sy - cy) if mindis > distance: idx = j + 1 mindis = distance print(idx)
N, M = list(map(int, input().split())) students = [list(map(int, input().split())) for i in range(N)] checkPoints = [list(map(int, input().split())) for i in range(M)] for i in range(N): idx = 1 mindis = abs(students[i][0] - checkPoints[0][0]) + abs( students[i][1] - checkPoints[0][1] ) sx, sy = students[i] for j in range(1, M): cx, cy = checkPoints[j] distance = abs(sx - cx) + abs(sy - cy) if mindis > distance: idx = j + 1 mindis = distance print(idx)
false
0
[ "- idx = -1", "- mindis = 3 * 10**8", "+ idx = 1", "+ mindis = abs(students[i][0] - checkPoints[0][0]) + abs(", "+ students[i][1] - checkPoints[0][1]", "+ )", "- for j in range(M):", "+ for j in range(1, M):" ]
false
0.045143
0.040727
1.108447
[ "s143463593", "s602083210" ]
u357751375
p02954
python
s940791530
s182576767
155
101
25,552
17,816
Accepted
Accepted
34.84
s = eval(input()) ans = [0] * len(s) x = 0 y = 'R' z = [] for i in s: if y == i: x += 1 else: z.append([y,x]) x = 1 y = i z.append([y,x]) ans = [0] * len(s) i = 0 j = 0 while i < len(z): x = z[i][1] if z[i][0] == 'R': j += x-1 if x % 2 == 0: ans[j] += x // 2 else: ans[j] += x // 2 + 1 ans[j+1] += x // 2 j -= x-1 j += x if z[i][0] == 'L': if x % 2 == 0: ans[j] += x // 2 else: ans[j] += x // 2 + 1 ans[j-1] += x // 2 j += x i += 1 print((' '.join(map(str,ans))))
s = eval(input()) x = 0 y = 'R' rle = [] for c in s: if y == c: x += 1 else: rle.append(x) x = 1 y = c rle.append(x) ans = [0] * len(s) i = 0 y = 'R' for c in rle: if y == 'R': j = i + c - 1 if c % 2 == 0: ans[j] += c // 2 else: ans[j] += c // 2 + 1 ans[j+1] += c // 2 i += c y = 'L' else: if c % 2 == 0: ans[i] += c // 2 else: ans[i] += c // 2 + 1 ans[i-1] += c // 2 i += c y = 'R' print((' '.join(map(str,ans))))
36
34
674
623
s = eval(input()) ans = [0] * len(s) x = 0 y = "R" z = [] for i in s: if y == i: x += 1 else: z.append([y, x]) x = 1 y = i z.append([y, x]) ans = [0] * len(s) i = 0 j = 0 while i < len(z): x = z[i][1] if z[i][0] == "R": j += x - 1 if x % 2 == 0: ans[j] += x // 2 else: ans[j] += x // 2 + 1 ans[j + 1] += x // 2 j -= x - 1 j += x if z[i][0] == "L": if x % 2 == 0: ans[j] += x // 2 else: ans[j] += x // 2 + 1 ans[j - 1] += x // 2 j += x i += 1 print((" ".join(map(str, ans))))
s = eval(input()) x = 0 y = "R" rle = [] for c in s: if y == c: x += 1 else: rle.append(x) x = 1 y = c rle.append(x) ans = [0] * len(s) i = 0 y = "R" for c in rle: if y == "R": j = i + c - 1 if c % 2 == 0: ans[j] += c // 2 else: ans[j] += c // 2 + 1 ans[j + 1] += c // 2 i += c y = "L" else: if c % 2 == 0: ans[i] += c // 2 else: ans[i] += c // 2 + 1 ans[i - 1] += c // 2 i += c y = "R" print((" ".join(map(str, ans))))
false
5.555556
[ "-ans = [0] * len(s)", "-z = []", "-for i in s:", "- if y == i:", "+rle = []", "+for c in s:", "+ if y == c:", "- z.append([y, x])", "+ rle.append(x)", "- y = i", "-z.append([y, x])", "+ y = c", "+rle.append(x)", "-j = 0", "-while i < len(z):", "- x...
false
0.03764
0.053134
0.7084
[ "s940791530", "s182576767" ]
u729133443
p04006
python
s406843273
s925898463
895
818
35,228
3,188
Accepted
Accepted
8.6
n,x,*a=list(map(int,open(0).read().split()));i,m=0,1e18;exec('m=min(m,sum(a)+x*i);i+=1;a=[min(t)for t in zip(a,a[-1:]+a)];'*n);print(m)
n,x,*a=list(map(int,open(0).read().split())) m=1e18 for i in range(n):m=min(m,sum(a)+x*i);a=[min(t)for t in zip(a,a[-1:]+a)] print(m)
1
4
129
130
n, x, *a = list(map(int, open(0).read().split())) i, m = 0, 1e18 exec("m=min(m,sum(a)+x*i);i+=1;a=[min(t)for t in zip(a,a[-1:]+a)];" * n) print(m)
n, x, *a = list(map(int, open(0).read().split())) m = 1e18 for i in range(n): m = min(m, sum(a) + x * i) a = [min(t) for t in zip(a, a[-1:] + a)] print(m)
false
75
[ "-i, m = 0, 1e18", "-exec(\"m=min(m,sum(a)+x*i);i+=1;a=[min(t)for t in zip(a,a[-1:]+a)];\" * n)", "+m = 1e18", "+for i in range(n):", "+ m = min(m, sum(a) + x * i)", "+ a = [min(t) for t in zip(a, a[-1:] + a)]" ]
false
0.036044
0.073826
0.488224
[ "s406843273", "s925898463" ]
u887207211
p03212
python
s410063945
s994306394
93
45
3,064
5,156
Accepted
Accepted
51.61
N = int(eval(input())) def abc114_c(s): if(int(s) > N): return 0 if(all(s.count(c) > 0 for c in "753")): ans = 1 else: ans = 0 for c in "753": ans += abc114_c(s+c) return ans print((abc114_c("0")))
N = eval(input()) nums = ['3', '5', '7'] for i in range(len(N)): for num in nums: if(len(num) == i): nums.append(num + '3') nums.append(num + '5') nums.append(num + '7') cnt = 0 for num in nums: if(int(num) <= int(N) and '3' in num and '5' in num and '7' in num): cnt += 1 print(cnt)
13
13
228
319
N = int(eval(input())) def abc114_c(s): if int(s) > N: return 0 if all(s.count(c) > 0 for c in "753"): ans = 1 else: ans = 0 for c in "753": ans += abc114_c(s + c) return ans print((abc114_c("0")))
N = eval(input()) nums = ["3", "5", "7"] for i in range(len(N)): for num in nums: if len(num) == i: nums.append(num + "3") nums.append(num + "5") nums.append(num + "7") cnt = 0 for num in nums: if int(num) <= int(N) and "3" in num and "5" in num and "7" in num: cnt += 1 print(cnt)
false
0
[ "-N = int(eval(input()))", "-", "-", "-def abc114_c(s):", "- if int(s) > N:", "- return 0", "- if all(s.count(c) > 0 for c in \"753\"):", "- ans = 1", "- else:", "- ans = 0", "- for c in \"753\":", "- ans += abc114_c(s + c)", "- return ans", "-", ...
false
0.008088
0.076129
0.106239
[ "s410063945", "s994306394" ]
u691018832
p02693
python
s831384385
s771591069
61
22
61,612
9,168
Accepted
Accepted
63.93
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) k = int(readline()) a, b = list(map(int, readline().split())) for i in range(a, b + 1): if i % k == 0: print('OK') exit() print('NG')
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) k, a, b = list(map(int, read().split())) for i in range(a, b + 1): if i % k == 0: print('OK') exit() print('NG')
13
12
308
286
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) k = int(readline()) a, b = list(map(int, readline().split())) for i in range(a, b + 1): if i % k == 0: print("OK") exit() print("NG")
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) k, a, b = list(map(int, read().split())) for i in range(a, b + 1): if i % k == 0: print("OK") exit() print("NG")
false
7.692308
[ "-k = int(readline())", "-a, b = list(map(int, readline().split()))", "+k, a, b = list(map(int, read().split()))" ]
false
0.041175
0.036541
1.126819
[ "s831384385", "s771591069" ]
u621935300
p02918
python
s815242265
s834924341
72
56
52,956
36,892
Accepted
Accepted
22.22
N,K=list(map(int, input().split())) S=list(input()) L=[] now=None for i,s in enumerate(S): if i==0: now=s cnt=1 elif now==s: cnt+=1 elif now!=s: L.append([now,cnt]) cnt=1 now=s else: L.append([now,cnt]) l=len(L) for i in range(1,min(K*2,l),2): s=L[i][0] if s=="L": L[i][0]="R" elif s=="R": L[i][0]="L" ans=0 prev=None for t in L: s=t[0] cnt=t[1] if prev is None: prev=s lcnt=cnt else: if prev==s: lcnt+=cnt elif prev!=s: ans+=(lcnt-1) lcnt=cnt prev=s else: ans+=(lcnt-1) print(ans)
# -*- coding: utf-8 -*- import sys N,K=list(map(int, sys.stdin.readline().split())) S=sys.stdin.readline().strip() L=[] cnt=0 for i,x in enumerate(S): if i==0: cnt+=1 prev=x else: if prev==x: #前の文字と今の文字が同じ cnt+=1 else: #前の文字と今の文字が異なる L.append(cnt) cnt=1 prev=x else: L.append(cnt) print(sum(L)-max(1,len(L)-2*K))
46
21
579
421
N, K = list(map(int, input().split())) S = list(input()) L = [] now = None for i, s in enumerate(S): if i == 0: now = s cnt = 1 elif now == s: cnt += 1 elif now != s: L.append([now, cnt]) cnt = 1 now = s else: L.append([now, cnt]) l = len(L) for i in range(1, min(K * 2, l), 2): s = L[i][0] if s == "L": L[i][0] = "R" elif s == "R": L[i][0] = "L" ans = 0 prev = None for t in L: s = t[0] cnt = t[1] if prev is None: prev = s lcnt = cnt else: if prev == s: lcnt += cnt elif prev != s: ans += lcnt - 1 lcnt = cnt prev = s else: ans += lcnt - 1 print(ans)
# -*- coding: utf-8 -*- import sys N, K = list(map(int, sys.stdin.readline().split())) S = sys.stdin.readline().strip() L = [] cnt = 0 for i, x in enumerate(S): if i == 0: cnt += 1 prev = x else: if prev == x: # 前の文字と今の文字が同じ cnt += 1 else: # 前の文字と今の文字が異なる L.append(cnt) cnt = 1 prev = x else: L.append(cnt) print(sum(L) - max(1, len(L) - 2 * K))
false
54.347826
[ "-N, K = list(map(int, input().split()))", "-S = list(input())", "+# -*- coding: utf-8 -*-", "+import sys", "+", "+N, K = list(map(int, sys.stdin.readline().split()))", "+S = sys.stdin.readline().strip()", "-now = None", "-for i, s in enumerate(S):", "+cnt = 0", "+for i, x in enumerate(S):", "...
false
0.035422
0.048375
0.732229
[ "s815242265", "s834924341" ]
u644907318
p03147
python
s225813481
s436486824
178
64
39,536
67,152
Accepted
Accepted
64.04
N = int(eval(input())) H = list(map(int,input().split())) cnt = 0 while True: flag = 0 for i in range(N): if H[i]>0: cur = i flag = 1 break if flag==0:break cmin = H[cur] flag = 1 for i in range(cur,N): if H[i]>0 and flag==1: cmin = min(cmin,H[i]) elif H[i]>0 and flag==0: cur = i cmin = H[i] flag = 1 else: cnt += cmin for k in range(cur,i): H[k] -= cmin cur = i cmin = 0 flag = 0 cnt += cmin for k in range(cur,N): H[k] -= cmin print(cnt)
N = int(eval(input())) H = list(map(int,input().split())) tot = 0 while True: if H[0]>0: cnt = 1 else: cnt = 0 for i in range(1,N): if H[i]>0 and H[i-1]==0: cnt += 1 tot += cnt for i in range(N): if H[i]>0: H[i] -= 1 flag = 0 for i in range(N): if H[i]>0: flag = 1 break if flag==0:break print(tot)
31
22
696
437
N = int(eval(input())) H = list(map(int, input().split())) cnt = 0 while True: flag = 0 for i in range(N): if H[i] > 0: cur = i flag = 1 break if flag == 0: break cmin = H[cur] flag = 1 for i in range(cur, N): if H[i] > 0 and flag == 1: cmin = min(cmin, H[i]) elif H[i] > 0 and flag == 0: cur = i cmin = H[i] flag = 1 else: cnt += cmin for k in range(cur, i): H[k] -= cmin cur = i cmin = 0 flag = 0 cnt += cmin for k in range(cur, N): H[k] -= cmin print(cnt)
N = int(eval(input())) H = list(map(int, input().split())) tot = 0 while True: if H[0] > 0: cnt = 1 else: cnt = 0 for i in range(1, N): if H[i] > 0 and H[i - 1] == 0: cnt += 1 tot += cnt for i in range(N): if H[i] > 0: H[i] -= 1 flag = 0 for i in range(N): if H[i] > 0: flag = 1 break if flag == 0: break print(tot)
false
29.032258
[ "-cnt = 0", "+tot = 0", "+ if H[0] > 0:", "+ cnt = 1", "+ else:", "+ cnt = 0", "+ for i in range(1, N):", "+ if H[i] > 0 and H[i - 1] == 0:", "+ cnt += 1", "+ tot += cnt", "+ for i in range(N):", "+ if H[i] > 0:", "+ H[i] -= 1"...
false
0.055985
0.042371
1.321312
[ "s225813481", "s436486824" ]
u678167152
p02588
python
s221342522
s311194341
867
266
39,996
95,676
Accepted
Accepted
69.32
from decimal import Decimal def waru(N,num): cnt = 0 while N%num==0: N //= num cnt += 1 return cnt def solve(): N = int(eval(input())) num = [[0]*101 for _ in range(101)] lis = [0]*N for i in range(N): a = int(round(float(eval(input()))*10**9)) p,q = waru(a,2)-9-50,waru(a,5)-9-50 num[p][q] += 1 lis[i] = [p,q] cum2 = [[0]*101 for _ in range(101)] for i in range(99,-1,-1): for j in range(99,-1,-1): cum2[i][j] = cum2[i+1][j]+cum2[i][j+1]-cum2[i+1][j+1]+num[i][j] ans = 0 for i in range(N): p,q = lis[i] x,y = p+50,q+50 p = -x-50 q = -y-50 ans += cum2[p][q] if x>=0 and y>=0: ans -= 1 return ans//2 print((solve()))
import sys input = sys.stdin.readline def waru(N,num): cnt = 0 while N%num==0: N //= num cnt += 1 return cnt def solve(): N = int(eval(input())) num = [[0]*101 for _ in range(101)] lis = [0]*N for i in range(N): a = int(round(float(eval(input()))*10**9)) p,q = waru(a,2)-9-50,waru(a,5)-9-50 num[p][q] += 1 lis[i] = [p,q] cum2 = [[0]*101 for _ in range(101)] for i in range(99,-1,-1): for j in range(99,-1,-1): cum2[i][j] = cum2[i+1][j]+cum2[i][j+1]-cum2[i+1][j+1]+num[i][j] ans = 0 for i in range(N): p,q = lis[i] x,y = p+50,q+50 p = -x-50 q = -y-50 ans += cum2[p][q] if x>=0 and y>=0: ans -= 1 return ans//2 print((solve()))
31
32
719
730
from decimal import Decimal def waru(N, num): cnt = 0 while N % num == 0: N //= num cnt += 1 return cnt def solve(): N = int(eval(input())) num = [[0] * 101 for _ in range(101)] lis = [0] * N for i in range(N): a = int(round(float(eval(input())) * 10**9)) p, q = waru(a, 2) - 9 - 50, waru(a, 5) - 9 - 50 num[p][q] += 1 lis[i] = [p, q] cum2 = [[0] * 101 for _ in range(101)] for i in range(99, -1, -1): for j in range(99, -1, -1): cum2[i][j] = ( cum2[i + 1][j] + cum2[i][j + 1] - cum2[i + 1][j + 1] + num[i][j] ) ans = 0 for i in range(N): p, q = lis[i] x, y = p + 50, q + 50 p = -x - 50 q = -y - 50 ans += cum2[p][q] if x >= 0 and y >= 0: ans -= 1 return ans // 2 print((solve()))
import sys input = sys.stdin.readline def waru(N, num): cnt = 0 while N % num == 0: N //= num cnt += 1 return cnt def solve(): N = int(eval(input())) num = [[0] * 101 for _ in range(101)] lis = [0] * N for i in range(N): a = int(round(float(eval(input())) * 10**9)) p, q = waru(a, 2) - 9 - 50, waru(a, 5) - 9 - 50 num[p][q] += 1 lis[i] = [p, q] cum2 = [[0] * 101 for _ in range(101)] for i in range(99, -1, -1): for j in range(99, -1, -1): cum2[i][j] = ( cum2[i + 1][j] + cum2[i][j + 1] - cum2[i + 1][j + 1] + num[i][j] ) ans = 0 for i in range(N): p, q = lis[i] x, y = p + 50, q + 50 p = -x - 50 q = -y - 50 ans += cum2[p][q] if x >= 0 and y >= 0: ans -= 1 return ans // 2 print((solve()))
false
3.125
[ "-from decimal import Decimal", "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.107452
0.04206
2.554725
[ "s221342522", "s311194341" ]
u945181840
p03578
python
s435592597
s568463137
258
222
57,056
69,344
Accepted
Accepted
13.95
from collections import Counter N = int(eval(input())) D = list(map(int, input().split())) M = int(eval(input())) T = list(map(int, input().split())) d = Counter(D) t = Counter(T) for key, value in list(t.items()): if d.get(key, 0) < value: print('NO') exit() else: print('YES')
from collections import Counter def main(): N = int(eval(input())) D = input().split() M = int(eval(input())) T = input().split() d = Counter(D) t = Counter(T) for key, value in list(t.items()): if d.get(key, 0) < value: print('NO') exit() else: print('YES') if __name__ == '__main__': main()
15
21
300
375
from collections import Counter N = int(eval(input())) D = list(map(int, input().split())) M = int(eval(input())) T = list(map(int, input().split())) d = Counter(D) t = Counter(T) for key, value in list(t.items()): if d.get(key, 0) < value: print("NO") exit() else: print("YES")
from collections import Counter def main(): N = int(eval(input())) D = input().split() M = int(eval(input())) T = input().split() d = Counter(D) t = Counter(T) for key, value in list(t.items()): if d.get(key, 0) < value: print("NO") exit() else: print("YES") if __name__ == "__main__": main()
false
28.571429
[ "-N = int(eval(input()))", "-D = list(map(int, input().split()))", "-M = int(eval(input()))", "-T = list(map(int, input().split()))", "-d = Counter(D)", "-t = Counter(T)", "-for key, value in list(t.items()):", "- if d.get(key, 0) < value:", "- print(\"NO\")", "- exit()", "-else...
false
0.041424
0.041412
1.000295
[ "s435592597", "s568463137" ]
u983918956
p03194
python
s241832365
s842639364
124
59
3,064
3,188
Accepted
Accepted
52.42
import math N,P = list(map(int,input().split())) if N == 1: print(P) exit() ans = 1 for i in range(2,math.floor(pow(P,1/2)) + 1): if P % i == 0: count = 1 P = P // i while P % i == 0: count += 1 P = P // i ans *= pow(i,count // N) print(ans)
import math def factoring(n,dict_count = {}): sup = math.floor(pow(n,1/2)) n_new = n for i in range(2,sup + 1): if n % i == 0: n_new = n // i if i in dict_count: dict_count[i] += 1 else: dict_count[i] = 1 break if n == n_new: if n_new in dict_count: dict_count[n_new] += 1 else: dict_count[n_new] = 1 return sorted(list(dict_count.items())) return factoring(n_new,dict_count) N,P = list(map(int,input().split())) result = factoring(P) ans = 1 for e in result: ans *= pow(e[0],e[1] // N) print(ans)
15
25
317
673
import math N, P = list(map(int, input().split())) if N == 1: print(P) exit() ans = 1 for i in range(2, math.floor(pow(P, 1 / 2)) + 1): if P % i == 0: count = 1 P = P // i while P % i == 0: count += 1 P = P // i ans *= pow(i, count // N) print(ans)
import math def factoring(n, dict_count={}): sup = math.floor(pow(n, 1 / 2)) n_new = n for i in range(2, sup + 1): if n % i == 0: n_new = n // i if i in dict_count: dict_count[i] += 1 else: dict_count[i] = 1 break if n == n_new: if n_new in dict_count: dict_count[n_new] += 1 else: dict_count[n_new] = 1 return sorted(list(dict_count.items())) return factoring(n_new, dict_count) N, P = list(map(int, input().split())) result = factoring(P) ans = 1 for e in result: ans *= pow(e[0], e[1] // N) print(ans)
false
40
[ "+", "+def factoring(n, dict_count={}):", "+ sup = math.floor(pow(n, 1 / 2))", "+ n_new = n", "+ for i in range(2, sup + 1):", "+ if n % i == 0:", "+ n_new = n // i", "+ if i in dict_count:", "+ dict_count[i] += 1", "+ else:", "+ ...
false
0.082093
0.046204
1.77674
[ "s241832365", "s842639364" ]
u763249708
p02641
python
s922292388
s570763489
33
26
8,952
9,004
Accepted
Accepted
21.21
x, n = list(map(int, input().split())) if n == 0: print(x) exit() p = list(map(int, input().split())) for d in range(x + 2): for s in [-1, 1]: a = x + s * d if a not in p: print(a) exit()
x, n = list(map(int, input().split())) if n == 0: print(x) exit() p = list(map(int, input().split())) for d in range(x + 2): if x - d not in p: print((x-d)) exit() if x + d not in p: print((x+d)) exit()
13
13
214
223
x, n = list(map(int, input().split())) if n == 0: print(x) exit() p = list(map(int, input().split())) for d in range(x + 2): for s in [-1, 1]: a = x + s * d if a not in p: print(a) exit()
x, n = list(map(int, input().split())) if n == 0: print(x) exit() p = list(map(int, input().split())) for d in range(x + 2): if x - d not in p: print((x - d)) exit() if x + d not in p: print((x + d)) exit()
false
0
[ "- for s in [-1, 1]:", "- a = x + s * d", "- if a not in p:", "- print(a)", "- exit()", "+ if x - d not in p:", "+ print((x - d))", "+ exit()", "+ if x + d not in p:", "+ print((x + d))", "+ exit()" ]
false
0.046899
0.047755
0.982066
[ "s922292388", "s570763489" ]
u197300260
p03373
python
s754522073
s245392659
143
88
9,700
9,972
Accepted
Accepted
38.46
# Problem: https://atcoder.jp/contests/arc096/tasks/arc096_a # Python 1st Try import sys # from collections import defaultdict # import heapq,copy import pprint as pp # from collections import deque def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] # CONST MAXSIZE = ( 1 << 31 ) -1 MINSIZE = -( 1 << 31) + 1 def solver(a_price, b_price, c_price, target_x, target_y): result = MAXSIZE for mix_i in range(0, 2 * 10**5+1, +1): a_i = target_x - mix_i//2 b_i = target_y - mix_i//2 totalPrice = max(a_i, 0) * a_price + max(b_i,0) * b_price + mix_i * c_price if totalPrice < result: # print("A={},B={},C={} -> total = {}".format(a_i, b_i, mix_i, totalPrice)) result = totalPrice return result if __name__ == "__main__": A, B, C, X, Y = MI() print(("{}".format(solver(A, B, C, X, Y))))
# Problem: https://atcoder.jp/contests/arc096/tasks/arc096_a # Python 2nd Try import sys # from collections import defaultdict # import heapq,copy import pprint as pp # from collections import deque def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] # Const MAXSIZE = ( 1 << 31 ) -1 MINSIZE = -( 1 << 31) + 1 MAXSHEET = 10**5 def solver(a_price, b_price, ab_price, x_sheet , y_sheet): result = MAXSHEET*a_price+MAXSHEET*b_price for j in range(0, 2*MAXSHEET+1, 2): a_buy_sheet = max(x_sheet-j//2,0) b_buy_sheet = max(y_sheet - j//2, 0 ) total = ( a_buy_sheet*a_price + b_buy_sheet*b_price + j*ab_price ) # print("total={}".format(total)) check = ( total < result ) if check: # print("値は{}に".format(total)) result = total return result if __name__ == "__main__": a_price, b_price, ab_price, x_sheet , y_sheet = MI() print(("{}".format(solver(a_price, b_price, ab_price, x_sheet, y_sheet))))
33
38
1,065
1,262
# Problem: https://atcoder.jp/contests/arc096/tasks/arc096_a # Python 1st Try import sys # from collections import defaultdict # import heapq,copy import pprint as pp # from collections import deque def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] # CONST MAXSIZE = (1 << 31) - 1 MINSIZE = -(1 << 31) + 1 def solver(a_price, b_price, c_price, target_x, target_y): result = MAXSIZE for mix_i in range(0, 2 * 10**5 + 1, +1): a_i = target_x - mix_i // 2 b_i = target_y - mix_i // 2 totalPrice = max(a_i, 0) * a_price + max(b_i, 0) * b_price + mix_i * c_price if totalPrice < result: # print("A={},B={},C={} -> total = {}".format(a_i, b_i, mix_i, totalPrice)) result = totalPrice return result if __name__ == "__main__": A, B, C, X, Y = MI() print(("{}".format(solver(A, B, C, X, Y))))
# Problem: https://atcoder.jp/contests/arc096/tasks/arc096_a # Python 2nd Try import sys # from collections import defaultdict # import heapq,copy import pprint as pp # from collections import deque def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] # Const MAXSIZE = (1 << 31) - 1 MINSIZE = -(1 << 31) + 1 MAXSHEET = 10**5 def solver(a_price, b_price, ab_price, x_sheet, y_sheet): result = MAXSHEET * a_price + MAXSHEET * b_price for j in range(0, 2 * MAXSHEET + 1, 2): a_buy_sheet = max(x_sheet - j // 2, 0) b_buy_sheet = max(y_sheet - j // 2, 0) total = a_buy_sheet * a_price + b_buy_sheet * b_price + j * ab_price # print("total={}".format(total)) check = total < result if check: # print("値は{}に".format(total)) result = total return result if __name__ == "__main__": a_price, b_price, ab_price, x_sheet, y_sheet = MI() print(("{}".format(solver(a_price, b_price, ab_price, x_sheet, y_sheet))))
false
13.157895
[ "-# Python 1st Try", "+# Python 2nd Try", "-# CONST", "+# Const", "+MAXSHEET = 10**5", "-def solver(a_price, b_price, c_price, target_x, target_y):", "- result = MAXSIZE", "- for mix_i in range(0, 2 * 10**5 + 1, +1):", "- a_i = target_x - mix_i // 2", "- b_i = target_y - mix_i ...
false
0.177419
0.150622
1.177906
[ "s754522073", "s245392659" ]
u747602774
p03048
python
s814505695
s827644459
267
216
41,068
40,684
Accepted
Accepted
19.1
R,G,B,N = list(map(int,input().split())) ans = 0 for b in range(N+1): for g in range(N+1): if N-B*b-G*g >= 0 and (N-B*b-G*g)%R == 0: ans += 1 print(ans)
R,G,B,N = list(map(int,input().split())) ans = 0 for b in range(N+1): for g in range(N+1): if N-B*b-G*g < 0: break if (N-B*b-G*g)%R == 0: ans += 1 print(ans)
9
10
181
206
R, G, B, N = list(map(int, input().split())) ans = 0 for b in range(N + 1): for g in range(N + 1): if N - B * b - G * g >= 0 and (N - B * b - G * g) % R == 0: ans += 1 print(ans)
R, G, B, N = list(map(int, input().split())) ans = 0 for b in range(N + 1): for g in range(N + 1): if N - B * b - G * g < 0: break if (N - B * b - G * g) % R == 0: ans += 1 print(ans)
false
10
[ "- if N - B * b - G * g >= 0 and (N - B * b - G * g) % R == 0:", "+ if N - B * b - G * g < 0:", "+ break", "+ if (N - B * b - G * g) % R == 0:" ]
false
0.918651
0.397135
2.313195
[ "s814505695", "s827644459" ]
u933341648
p02695
python
s811817403
s614676326
589
540
9,108
9,092
Accepted
Accepted
8.32
n, m, q = list(map(int, input().split())) queries = [tuple(map(int, input().split())) for _ in range(q)] ans = 0 def calc_score(p): score = 0 for a, b, c, d in queries: if p[b-1] - p[a-1] == c: score += d return score def f(p): if len(p) == n: global ans ans = max(ans, calc_score(p)) return l = p[-1] if len(p) else 1 for x in range(l, m+1): f(p + [x]) f([]) print(ans)
from itertools import combinations_with_replacement as comb n, m, q = list(map(int, input().split())) queries = [tuple(map(int, input().split())) for _ in range(q)] ans = 0 def calc_score(p): score = 0 for a, b, c, d in queries: if p[b-1] - p[a-1] == c: score += d return score for p in comb(list(range(1, m+1)), n): ans = max(ans, calc_score(p)) print(ans)
23
17
467
402
n, m, q = list(map(int, input().split())) queries = [tuple(map(int, input().split())) for _ in range(q)] ans = 0 def calc_score(p): score = 0 for a, b, c, d in queries: if p[b - 1] - p[a - 1] == c: score += d return score def f(p): if len(p) == n: global ans ans = max(ans, calc_score(p)) return l = p[-1] if len(p) else 1 for x in range(l, m + 1): f(p + [x]) f([]) print(ans)
from itertools import combinations_with_replacement as comb n, m, q = list(map(int, input().split())) queries = [tuple(map(int, input().split())) for _ in range(q)] ans = 0 def calc_score(p): score = 0 for a, b, c, d in queries: if p[b - 1] - p[a - 1] == c: score += d return score for p in comb(list(range(1, m + 1)), n): ans = max(ans, calc_score(p)) print(ans)
false
26.086957
[ "+from itertools import combinations_with_replacement as comb", "+", "-def f(p):", "- if len(p) == n:", "- global ans", "- ans = max(ans, calc_score(p))", "- return", "- l = p[-1] if len(p) else 1", "- for x in range(l, m + 1):", "- f(p + [x])", "-", "-", ...
false
0.198545
0.144707
1.372053
[ "s811817403", "s614676326" ]
u560867850
p03087
python
s439617648
s553442280
473
332
30,744
9,476
Accepted
Accepted
29.81
from itertools import accumulate n, q = list(map(int, input().split())) s = eval(input()) problems = [list(map(int, input().split())) for _ in range(q)] def count(total, i): return total + 1 if s[i-1:i+1] == 'AC' else total cumsum = list(accumulate(list(range(n)), count)) for l, r in problems: print((cumsum[r-1] - cumsum[l-1]))
from sys import stdin from itertools import accumulate def fin(f): """ INput with Function f(input())と同じ。書きやすさのために作成した。 :param f: 入力に対して呼び出す関数 :return: 関数の処理結果 """ return f(stdin.readline().rstrip()) def gin(f, nl=1): """ INput with function and Generator 空白区切りの入力の各値に対して関数fを用いて初期化を行う。 複数行にも対応。 使い方: 一行の入力例 -> next(gin(int)) 複数行の入力をリストに格納する例 -> list(gin(int, n)) forループで使う例 -> for l, r in gin(int, n): :param f: 各値に適応する関数 :param nl: 行数(デフォルトは1) :returns: 空白区切りのリストたち """ for _ in range(nl): yield list(map(f, stdin.readline().split())) n, q = next(gin(int)) s = eval(input()) def count(total, i): return total + 1 if s[i-1:i+1] == 'AC' else total cumsum = list(accumulate([0] + list(range(n)), count))[1:] for l, r in gin(int, q): print((cumsum[r-1] - cumsum[l-1]))
17
45
342
917
from itertools import accumulate n, q = list(map(int, input().split())) s = eval(input()) problems = [list(map(int, input().split())) for _ in range(q)] def count(total, i): return total + 1 if s[i - 1 : i + 1] == "AC" else total cumsum = list(accumulate(list(range(n)), count)) for l, r in problems: print((cumsum[r - 1] - cumsum[l - 1]))
from sys import stdin from itertools import accumulate def fin(f): """ INput with Function f(input())と同じ。書きやすさのために作成した。 :param f: 入力に対して呼び出す関数 :return: 関数の処理結果 """ return f(stdin.readline().rstrip()) def gin(f, nl=1): """ INput with function and Generator 空白区切りの入力の各値に対して関数fを用いて初期化を行う。 複数行にも対応。 使い方: 一行の入力例 -> next(gin(int)) 複数行の入力をリストに格納する例 -> list(gin(int, n)) forループで使う例 -> for l, r in gin(int, n): :param f: 各値に適応する関数 :param nl: 行数(デフォルトは1) :returns: 空白区切りのリストたち """ for _ in range(nl): yield list(map(f, stdin.readline().split())) n, q = next(gin(int)) s = eval(input()) def count(total, i): return total + 1 if s[i - 1 : i + 1] == "AC" else total cumsum = list(accumulate([0] + list(range(n)), count))[1:] for l, r in gin(int, q): print((cumsum[r - 1] - cumsum[l - 1]))
false
62.222222
[ "+from sys import stdin", "-n, q = list(map(int, input().split()))", "+", "+def fin(f):", "+ \"\"\"", "+ INput with Function", "+ f(input())と同じ。書きやすさのために作成した。", "+ :param f: 入力に対して呼び出す関数", "+ :return: 関数の処理結果", "+ \"\"\"", "+ return f(stdin.readline().rstrip())", "+", "+...
false
0.043335
0.109931
0.394203
[ "s439617648", "s553442280" ]
u411923565
p03486
python
s958784216
s145216194
31
26
9,036
9,064
Accepted
Accepted
16.13
#28 B - Two Anagrams s = list(eval(input())) t = list(eval(input())) s = sorted(s,reverse = False) t = sorted(t,reverse = True) result = 'No' rang = min(len(s),len(t)) for i in range(rang): if ord(s[i]) < ord(t[i]): result = 'Yes' break else: # 文字が一緒で t の方が文字数が多いとき if (s[:rang] == t[:rang]) and len(s) < len(t): result = 'Yes' print(result)
#28 B - Two Anagrams AC s = list(eval(input())) t = list(eval(input())) s = sorted(s,reverse = False) t = sorted(t,reverse = True) s = ''.join(s) t = ''.join(t) if s < t: print('Yes') else: print('No')
18
13
384
211
# 28 B - Two Anagrams s = list(eval(input())) t = list(eval(input())) s = sorted(s, reverse=False) t = sorted(t, reverse=True) result = "No" rang = min(len(s), len(t)) for i in range(rang): if ord(s[i]) < ord(t[i]): result = "Yes" break else: # 文字が一緒で t の方が文字数が多いとき if (s[:rang] == t[:rang]) and len(s) < len(t): result = "Yes" print(result)
# 28 B - Two Anagrams AC s = list(eval(input())) t = list(eval(input())) s = sorted(s, reverse=False) t = sorted(t, reverse=True) s = "".join(s) t = "".join(t) if s < t: print("Yes") else: print("No")
false
27.777778
[ "-# 28 B - Two Anagrams", "+# 28 B - Two Anagrams AC", "-result = \"No\"", "-rang = min(len(s), len(t))", "-for i in range(rang):", "- if ord(s[i]) < ord(t[i]):", "- result = \"Yes\"", "- break", "+s = \"\".join(s)", "+t = \"\".join(t)", "+if s < t:", "+ print(\"Yes\")", ...
false
0.034453
0.059331
0.580683
[ "s958784216", "s145216194" ]
u754022296
p02992
python
s068631985
s610296227
1,707
208
23,404
33,032
Accepted
Accepted
87.81
import sys input = sys.stdin.readline from itertools import accumulate MOD = 10**9+7 def main(): n, k = list(map(int, input().split())) S = set() i = 1 while i * i <= n: S.add(i) S.add(n//i) i += 1 L = [0] + sorted(S) l = len(L) - 1 num = [0]*l for i in range(l): num[i] = L[i+1] - L[i] dp = [0]*l dp[0] = 1 for _ in range(k): A = list(accumulate(dp)) for i in range(l): dp[i] = A[l-1-i] * num[i] dp[i] %= MOD ans = sum(dp) % MOD print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline import numpy as np MOD = 10**9+7 n, k = list(map(int, input().split())) S = set() i = 1 while i * i <= n: S.add(i) S.add(n//i) i += 1 L = np.array([0] + sorted(S), dtype=np.int64) l = len(L) - 1 num = np.diff(L) dp = np.zeros(l, dtype=np.int64) dp[0] = 1 for _ in range(k): A = np.cumsum(dp) dp = A[::-1] * num dp %= MOD ans = dp.sum() % MOD print(ans)
30
23
563
421
import sys input = sys.stdin.readline from itertools import accumulate MOD = 10**9 + 7 def main(): n, k = list(map(int, input().split())) S = set() i = 1 while i * i <= n: S.add(i) S.add(n // i) i += 1 L = [0] + sorted(S) l = len(L) - 1 num = [0] * l for i in range(l): num[i] = L[i + 1] - L[i] dp = [0] * l dp[0] = 1 for _ in range(k): A = list(accumulate(dp)) for i in range(l): dp[i] = A[l - 1 - i] * num[i] dp[i] %= MOD ans = sum(dp) % MOD print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline import numpy as np MOD = 10**9 + 7 n, k = list(map(int, input().split())) S = set() i = 1 while i * i <= n: S.add(i) S.add(n // i) i += 1 L = np.array([0] + sorted(S), dtype=np.int64) l = len(L) - 1 num = np.diff(L) dp = np.zeros(l, dtype=np.int64) dp[0] = 1 for _ in range(k): A = np.cumsum(dp) dp = A[::-1] * num dp %= MOD ans = dp.sum() % MOD print(ans)
false
23.333333
[ "-from itertools import accumulate", "+import numpy as np", "-", "-", "-def main():", "- n, k = list(map(int, input().split()))", "- S = set()", "- i = 1", "- while i * i <= n:", "- S.add(i)", "- S.add(n // i)", "- i += 1", "- L = [0] + sorted(S)", "- ...
false
0.497252
0.344523
1.443309
[ "s068631985", "s610296227" ]
u370331385
p03212
python
s838528176
s460883613
1,974
187
36,980
6,772
Accepted
Accepted
90.53
import itertools N = eval(input()) N1 = int(N) N2 = len(N) num753_comb = [] for i in range(N2): num753_comb.append([0,3,5,7]) All_comb = list(itertools.product(*num753_comb)) count = 0 for i in range(len(All_comb)): tmp = list(All_comb[i]) tmp_num = 0 judge0,judge3,judge5,judge7 = 0,0,0,0 for j in range(N2): tmp_num += tmp[j]*(10**(N2-1-j)) if((tmp_num > 0)and(tmp[j] == 0)): judge0 += 1 elif(tmp[j] == 3): judge3 += 1 elif(tmp[j] == 5): judge5 += 1 elif(tmp[j] == 7): judge7 += 1 if(tmp_num <= N1): if((judge3>=1)and(judge5>=1)and(judge7>=1)and(judge0 == 0)): count += 1 print(count)
import itertools N_ = eval(input()) N = int(N_) n = len(list(N_)) #Nの桁数 #(方針) N<=10**9 だと3,5,7のみを使ってできる数は多くても3**9=2*10**4通りなので全探索 A = ['3','5','7'] ans = 0 if(n >= 3): #桁数が3以上なら for i in range(3,n+1): Comb = list(itertools.product(A, repeat=i)) #重複組み合わせ for j in range(len(Comb)): tmp = list(Comb[j]) #print(tmp) ######### judge = 1 #条件を満たす数: 1,満たさない数: 0 #選んだ数がN以下かの判定 tmp_num = '' for k in range(len(tmp)): tmp_num += tmp[k] tmp_num = int(tmp_num) if(tmp_num > N): judge = 0 #print(tmp_num) ######### #選んだ数が3,5,7を1回以上含むかの判定 three,five,seven = 0,0,0 for k in range(len(tmp)): if(tmp[k]=='3'): three += 1 elif(tmp[k]=='5'): five += 1 elif(tmp[k]=='7'): seven += 1 if(three*five*seven == 0): #どれか1つでも0なら積は0 judge = 0 #条件をみたすならカウント+1 if(judge == 1): ans += 1 print(ans)
29
40
660
901
import itertools N = eval(input()) N1 = int(N) N2 = len(N) num753_comb = [] for i in range(N2): num753_comb.append([0, 3, 5, 7]) All_comb = list(itertools.product(*num753_comb)) count = 0 for i in range(len(All_comb)): tmp = list(All_comb[i]) tmp_num = 0 judge0, judge3, judge5, judge7 = 0, 0, 0, 0 for j in range(N2): tmp_num += tmp[j] * (10 ** (N2 - 1 - j)) if (tmp_num > 0) and (tmp[j] == 0): judge0 += 1 elif tmp[j] == 3: judge3 += 1 elif tmp[j] == 5: judge5 += 1 elif tmp[j] == 7: judge7 += 1 if tmp_num <= N1: if (judge3 >= 1) and (judge5 >= 1) and (judge7 >= 1) and (judge0 == 0): count += 1 print(count)
import itertools N_ = eval(input()) N = int(N_) n = len(list(N_)) # Nの桁数 # (方針) N<=10**9 だと3,5,7のみを使ってできる数は多くても3**9=2*10**4通りなので全探索 A = ["3", "5", "7"] ans = 0 if n >= 3: # 桁数が3以上なら for i in range(3, n + 1): Comb = list(itertools.product(A, repeat=i)) # 重複組み合わせ for j in range(len(Comb)): tmp = list(Comb[j]) # print(tmp) ######### judge = 1 # 条件を満たす数: 1,満たさない数: 0 # 選んだ数がN以下かの判定 tmp_num = "" for k in range(len(tmp)): tmp_num += tmp[k] tmp_num = int(tmp_num) if tmp_num > N: judge = 0 # print(tmp_num) ######### # 選んだ数が3,5,7を1回以上含むかの判定 three, five, seven = 0, 0, 0 for k in range(len(tmp)): if tmp[k] == "3": three += 1 elif tmp[k] == "5": five += 1 elif tmp[k] == "7": seven += 1 if three * five * seven == 0: # どれか1つでも0なら積は0 judge = 0 # 条件をみたすならカウント+1 if judge == 1: ans += 1 print(ans)
false
27.5
[ "-N = eval(input())", "-N1 = int(N)", "-N2 = len(N)", "-num753_comb = []", "-for i in range(N2):", "- num753_comb.append([0, 3, 5, 7])", "-All_comb = list(itertools.product(*num753_comb))", "-count = 0", "-for i in range(len(All_comb)):", "- tmp = list(All_comb[i])", "- tmp_num = 0", ...
false
0.044808
0.04663
0.960939
[ "s838528176", "s460883613" ]
u803848678
p03241
python
s960093635
s682689213
31
22
3,316
3,060
Accepted
Accepted
29.03
from collections import Counter n, m = list(map(int, input().split())) def factorize(m): c = Counter() t = 2 while t**2 <= m: if m % t: t += 1 continue while not m%t: c[t] += 1 m //= t if m > 1: c[m] += 1 return c yakusu = [1] for key, value in list(factorize(m).items()): next_yakusu = [] for i in range(value+1): for j in yakusu: next_yakusu.append(j*key**i) yakusu = next_yakusu ans = 1 for i in yakusu: if n <= m//i: ans = max(ans, i) print(ans)
from math import sqrt n, m = list(map(int, input().split())) ans = 1 for i in range(int(sqrt(m))): if m%(i+1)==0: if n <= m//(i+1) : ans= max(ans, i+1) if n <= i+1 : ans = max(ans,m//(i+1)) print(ans)
29
8
603
221
from collections import Counter n, m = list(map(int, input().split())) def factorize(m): c = Counter() t = 2 while t**2 <= m: if m % t: t += 1 continue while not m % t: c[t] += 1 m //= t if m > 1: c[m] += 1 return c yakusu = [1] for key, value in list(factorize(m).items()): next_yakusu = [] for i in range(value + 1): for j in yakusu: next_yakusu.append(j * key**i) yakusu = next_yakusu ans = 1 for i in yakusu: if n <= m // i: ans = max(ans, i) print(ans)
from math import sqrt n, m = list(map(int, input().split())) ans = 1 for i in range(int(sqrt(m))): if m % (i + 1) == 0: if n <= m // (i + 1): ans = max(ans, i + 1) if n <= i + 1: ans = max(ans, m // (i + 1)) print(ans)
false
72.413793
[ "-from collections import Counter", "+from math import sqrt", "-", "-", "-def factorize(m):", "- c = Counter()", "- t = 2", "- while t**2 <= m:", "- if m % t:", "- t += 1", "- continue", "- while not m % t:", "- c[t] += 1", "- ...
false
0.046633
0.052663
0.885504
[ "s960093635", "s682689213" ]
u046187684
p02947
python
s481493017
s449584311
347
312
27,528
27,852
Accepted
Accepted
10.09
def solve(string): n, *ss = string.split() d = {} for s in ["".join(sorted(x)) for x in ss]: d[s] = 1 + d[s] if s in list(d.keys()) else 1 return str(sum([v * (v - 1) // 2 for v in list(d.values())])) if __name__ == '__main__': n = int(eval(input())) print((solve('{}\n'.format(n) + '\n'.join([eval(input()) for _ in range(n)]))))
from collections import Counter def solve(string): n, *ss = string.split() d = Counter(s for s in ["".join(sorted(x)) for x in ss]) return str(sum([v * (v - 1) // 2 for v in list(d.values())])) if __name__ == '__main__': n = int(eval(input())) print((solve('{}\n'.format(n) + '\n'.join([eval(input()) for _ in range(n)]))))
11
12
354
344
def solve(string): n, *ss = string.split() d = {} for s in ["".join(sorted(x)) for x in ss]: d[s] = 1 + d[s] if s in list(d.keys()) else 1 return str(sum([v * (v - 1) // 2 for v in list(d.values())])) if __name__ == "__main__": n = int(eval(input())) print((solve("{}\n".format(n) + "\n".join([eval(input()) for _ in range(n)]))))
from collections import Counter def solve(string): n, *ss = string.split() d = Counter(s for s in ["".join(sorted(x)) for x in ss]) return str(sum([v * (v - 1) // 2 for v in list(d.values())])) if __name__ == "__main__": n = int(eval(input())) print((solve("{}\n".format(n) + "\n".join([eval(input()) for _ in range(n)]))))
false
8.333333
[ "+from collections import Counter", "+", "+", "- d = {}", "- for s in [\"\".join(sorted(x)) for x in ss]:", "- d[s] = 1 + d[s] if s in list(d.keys()) else 1", "+ d = Counter(s for s in [\"\".join(sorted(x)) for x in ss])" ]
false
0.007056
0.116286
0.06068
[ "s481493017", "s449584311" ]
u422104747
p03286
python
s090158012
s136567782
333
303
116,976
117,872
Accepted
Accepted
9.01
import bisect def put(a,b): #結果の表示 l=max(len(a),len(b)) #aとbの長さが違うときに壊れるので以下で十分な長さの0を結合しておく a="0"*l+a b="0"*l+b s="" for i in range(-1,-l-1,-1): #長さの偶奇を考えたくないので逆順に生成してあとで反転 s+=a[i]+b[i] s=s[-1::-1] #反転 ind=s.find("1") print((s[ind:])) #頭にたくさんついている0を除いて表示 def quad(i): #数値を4進数表記の文字列に直す。16→"100"など。 s="" while i>0: s+=str(i%4) i//=4 return s[-1::-1] l=[0,1] for i in range(1,20): #候補の生成。最長で20ビット。 l+=[4**i+j for j in l] n=int(eval(input())) if n==0: #n==0は出力が空文字になってしまうので別に扱う print("0") else: for i in range(len(l)): ind=bisect.bisect_left(l,(l[i]-n)//2) if l[i]-2*l[ind]==n: put(quad(l[i]),quad(l[ind])) break
import bisect def put(a, b): # 結果の表示 l = max(len(a), len(b)) # aとbの長さが違うときに壊れるので以下で十分な長さの0を結合しておく a = "0" * l + a b = "0" * l + b s = "" for i in range(-1, -l-1, -1): # 長さの偶奇を考えたくないので逆順に生成してあとで反転 s += a[i] + b[i] s = s[-1::-1] # 反転 print((s[s.find("1"):])) # 頭にたくさんついている0を除いて表示 def quad(i): # 数値を4進数表記の文字列に直す。16→"100"など。 s = "" while i > 0: s += str(i % 4) i //= 4 return s[-1::-1] l = [0, 1] for i in range(1, 20): # 候補の生成。最長で20ビット。 l += [4 ** i + j for j in l] n = int(eval(input())) if n == 0: # n==0は出力が空文字になってしまうので別に扱う print("0") else: for i in range(len(l)): ind = bisect.bisect_left(l, (l[i] - n) // 2) if l[i] - 2 * l[ind] == n: put(quad(l[i]), quad(l[ind])) break
32
35
754
829
import bisect def put(a, b): # 結果の表示 l = max(len(a), len(b)) # aとbの長さが違うときに壊れるので以下で十分な長さの0を結合しておく a = "0" * l + a b = "0" * l + b s = "" for i in range(-1, -l - 1, -1): # 長さの偶奇を考えたくないので逆順に生成してあとで反転 s += a[i] + b[i] s = s[-1::-1] # 反転 ind = s.find("1") print((s[ind:])) # 頭にたくさんついている0を除いて表示 def quad(i): # 数値を4進数表記の文字列に直す。16→"100"など。 s = "" while i > 0: s += str(i % 4) i //= 4 return s[-1::-1] l = [0, 1] for i in range(1, 20): # 候補の生成。最長で20ビット。 l += [4**i + j for j in l] n = int(eval(input())) if n == 0: # n==0は出力が空文字になってしまうので別に扱う print("0") else: for i in range(len(l)): ind = bisect.bisect_left(l, (l[i] - n) // 2) if l[i] - 2 * l[ind] == n: put(quad(l[i]), quad(l[ind])) break
import bisect def put(a, b): # 結果の表示 l = max(len(a), len(b)) # aとbの長さが違うときに壊れるので以下で十分な長さの0を結合しておく a = "0" * l + a b = "0" * l + b s = "" for i in range(-1, -l - 1, -1): # 長さの偶奇を考えたくないので逆順に生成してあとで反転 s += a[i] + b[i] s = s[-1::-1] # 反転 print((s[s.find("1") :])) # 頭にたくさんついている0を除いて表示 def quad(i): # 数値を4進数表記の文字列に直す。16→"100"など。 s = "" while i > 0: s += str(i % 4) i //= 4 return s[-1::-1] l = [0, 1] for i in range(1, 20): # 候補の生成。最長で20ビット。 l += [4**i + j for j in l] n = int(eval(input())) if n == 0: # n==0は出力が空文字になってしまうので別に扱う print("0") else: for i in range(len(l)): ind = bisect.bisect_left(l, (l[i] - n) // 2) if l[i] - 2 * l[ind] == n: put(quad(l[i]), quad(l[ind])) break
false
8.571429
[ "- ind = s.find(\"1\")", "- print((s[ind:])) # 頭にたくさんついている0を除いて表示", "+ print((s[s.find(\"1\") :])) # 頭にたくさんついている0を除いて表示" ]
false
0.823783
0.649332
1.268661
[ "s090158012", "s136567782" ]
u957167787
p03086
python
s931228998
s205039962
20
18
2,940
2,940
Accepted
Accepted
10
S = eval(input()) ans = 0 for i in range(len(S)): tmp = 0 for j in range(i, len(S)): if S[j] == 'A' or S[j] == 'T' or S[j] == 'G' or S[j] == 'C': tmp += 1 else: ans = max(ans, tmp) break if j == len(S) - 1: ans = max(ans, tmp) print(ans)
S = eval(input()) ans = 0 for i in range(len(S)): tmp = 0 for j in range(i, len(S)): if S[j] == 'A' or S[j] == 'T' or S[j] == 'G' or S[j] == 'C': tmp += 1 else: break ans = max(ans, tmp) print(ans)
17
15
332
262
S = eval(input()) ans = 0 for i in range(len(S)): tmp = 0 for j in range(i, len(S)): if S[j] == "A" or S[j] == "T" or S[j] == "G" or S[j] == "C": tmp += 1 else: ans = max(ans, tmp) break if j == len(S) - 1: ans = max(ans, tmp) print(ans)
S = eval(input()) ans = 0 for i in range(len(S)): tmp = 0 for j in range(i, len(S)): if S[j] == "A" or S[j] == "T" or S[j] == "G" or S[j] == "C": tmp += 1 else: break ans = max(ans, tmp) print(ans)
false
11.764706
[ "- ans = max(ans, tmp)", "- if j == len(S) - 1:", "- ans = max(ans, tmp)", "+ ans = max(ans, tmp)" ]
false
0.036082
0.037928
0.951339
[ "s931228998", "s205039962" ]
u864197622
p02726
python
s653170008
s594411397
327
267
48,604
46,044
Accepted
Accepted
18.35
N, X, Y = list(map(int, input().split())) X -= 1 Y -= 1 def dist(a, b): return min(abs(b-a), abs(X-a) + 1 + abs(b-Y), abs(Y-a) + 1 + abs(b-X)) ANS = [0] * N for i in range(N): for j in range(i): ANS[dist(i, j)] += 1 for a in ANS[1:]: print(a)
N, X, Y = list(map(int, input().split())) X -= 1 Y -= 1 def dist(a, b): return min(abs(b-a), abs(X-a) + 1 + abs(b-Y)) ANS = [0] * N for i in range(N): for j in range(i): ANS[dist(j, i)] += 1 for a in ANS[1:]: print(a)
14
14
272
247
N, X, Y = list(map(int, input().split())) X -= 1 Y -= 1 def dist(a, b): return min(abs(b - a), abs(X - a) + 1 + abs(b - Y), abs(Y - a) + 1 + abs(b - X)) ANS = [0] * N for i in range(N): for j in range(i): ANS[dist(i, j)] += 1 for a in ANS[1:]: print(a)
N, X, Y = list(map(int, input().split())) X -= 1 Y -= 1 def dist(a, b): return min(abs(b - a), abs(X - a) + 1 + abs(b - Y)) ANS = [0] * N for i in range(N): for j in range(i): ANS[dist(j, i)] += 1 for a in ANS[1:]: print(a)
false
0
[ "- return min(abs(b - a), abs(X - a) + 1 + abs(b - Y), abs(Y - a) + 1 + abs(b - X))", "+ return min(abs(b - a), abs(X - a) + 1 + abs(b - Y))", "- ANS[dist(i, j)] += 1", "+ ANS[dist(j, i)] += 1" ]
false
0.068432
0.053339
1.282955
[ "s653170008", "s594411397" ]
u077291787
p03103
python
s524917725
s975630727
404
321
28,648
27,812
Accepted
Accepted
20.54
# ABC121C - Energy Drink Collector import sys input = sys.stdin.readline n, m = list(map(int, input().rstrip().split())) lst = sorted([list(map(int, input().rstrip().split())) for _ in range(n)]) ans = 0 for i in lst: while i[1] > 0 and m > 0: ans += i[0] i[1] -= 1 m -= 1 print(ans)
# ABC121C - Energy Drink Collector import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, input().split())) for _ in range(n)) ans = 0 for i in lst: while i[1] > 0 and m > 0: ans += i[0] i[1] -= 1 m -= 1 print(ans) if __name__ == "__main__": main()
13
18
324
406
# ABC121C - Energy Drink Collector import sys input = sys.stdin.readline n, m = list(map(int, input().rstrip().split())) lst = sorted([list(map(int, input().rstrip().split())) for _ in range(n)]) ans = 0 for i in lst: while i[1] > 0 and m > 0: ans += i[0] i[1] -= 1 m -= 1 print(ans)
# ABC121C - Energy Drink Collector import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, input().split())) for _ in range(n)) ans = 0 for i in lst: while i[1] > 0 and m > 0: ans += i[0] i[1] -= 1 m -= 1 print(ans) if __name__ == "__main__": main()
false
27.777778
[ "-n, m = list(map(int, input().rstrip().split()))", "-lst = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])", "-ans = 0", "-for i in lst:", "- while i[1] > 0 and m > 0:", "- ans += i[0]", "- i[1] -= 1", "- m -= 1", "-print(ans)", "+", "+", "+def mai...
false
0.04209
0.053421
0.787897
[ "s524917725", "s975630727" ]
u950708010
p03608
python
s490421215
s349090823
1,748
621
9,696
19,420
Accepted
Accepted
64.47
import itertools import sys input = sys.stdin.readline def solve(): n,m,R = (int(i) for i in input().split()) r = list(int(i) for i in input().split()) d = [[float("Inf")]*n for _ in range(n)] for i in range(m): a,b,c = (int(i) for i in input().split()) d[a-1][b-1] = c d[b-1][a-1] = c for k in range(n): for i in range(n): for j in range(n): if d[i][j] > d[i][k] + d[k][j]: d[i][j] = d[i][k] + d[k][j] perm = list(itertools.permutations(list(range(R)))) cost = float("Inf") for i in range(len(perm)): root = perm[i] tempcost = 0 for j in range(R-1): na = r[root[j]]-1 nb = r[root[j+1]]-1 tempcost += d[na][nb] cost = min(tempcost,cost) print(cost) solve()
import itertools from scipy.sparse.csgraph import dijkstra import sys input = sys.stdin.readline def solve(): n,m,R = (int(i) for i in input().split()) r = list(int(i) for i in input().split()) d = [[float("Inf")]*n for _ in range(n)] for i in range(m): a,b,c = (int(i) for i in input().split()) d[a-1][b-1] = c d[b-1][a-1] = c d = dijkstra(d) perm = list(itertools.permutations(list(range(R)))) cost = float("Inf") for i in range(len(perm)): root = perm[i] tempcost = 0 for j in range(R-1): na = r[root[j]]-1 nb = r[root[j+1]]-1 tempcost += d[na][nb] cost = min(tempcost,cost) print((int(cost))) solve()
31
27
782
693
import itertools import sys input = sys.stdin.readline def solve(): n, m, R = (int(i) for i in input().split()) r = list(int(i) for i in input().split()) d = [[float("Inf")] * n for _ in range(n)] for i in range(m): a, b, c = (int(i) for i in input().split()) d[a - 1][b - 1] = c d[b - 1][a - 1] = c for k in range(n): for i in range(n): for j in range(n): if d[i][j] > d[i][k] + d[k][j]: d[i][j] = d[i][k] + d[k][j] perm = list(itertools.permutations(list(range(R)))) cost = float("Inf") for i in range(len(perm)): root = perm[i] tempcost = 0 for j in range(R - 1): na = r[root[j]] - 1 nb = r[root[j + 1]] - 1 tempcost += d[na][nb] cost = min(tempcost, cost) print(cost) solve()
import itertools from scipy.sparse.csgraph import dijkstra import sys input = sys.stdin.readline def solve(): n, m, R = (int(i) for i in input().split()) r = list(int(i) for i in input().split()) d = [[float("Inf")] * n for _ in range(n)] for i in range(m): a, b, c = (int(i) for i in input().split()) d[a - 1][b - 1] = c d[b - 1][a - 1] = c d = dijkstra(d) perm = list(itertools.permutations(list(range(R)))) cost = float("Inf") for i in range(len(perm)): root = perm[i] tempcost = 0 for j in range(R - 1): na = r[root[j]] - 1 nb = r[root[j + 1]] - 1 tempcost += d[na][nb] cost = min(tempcost, cost) print((int(cost))) solve()
false
12.903226
[ "+from scipy.sparse.csgraph import dijkstra", "- for k in range(n):", "- for i in range(n):", "- for j in range(n):", "- if d[i][j] > d[i][k] + d[k][j]:", "- d[i][j] = d[i][k] + d[k][j]", "+ d = dijkstra(d)", "- print(cost)", "+ print((...
false
0.036742
0.66725
0.055065
[ "s490421215", "s349090823" ]
u365512540
p02971
python
s559025616
s478207996
967
461
68,896
25,220
Accepted
Accepted
52.33
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] a_sorted = sorted(a)[::-1][:2] for an in a: print((a_sorted[an == a_sorted[0]]))
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] a_sorted = sorted(a, reverse=True)[:2] print(('\n'.join(map(str, [a_sorted[an == a_sorted[0]] for an in a]))))
5
4
140
165
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] a_sorted = sorted(a)[::-1][:2] for an in a: print((a_sorted[an == a_sorted[0]]))
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] a_sorted = sorted(a, reverse=True)[:2] print(("\n".join(map(str, [a_sorted[an == a_sorted[0]] for an in a]))))
false
20
[ "-a_sorted = sorted(a)[::-1][:2]", "-for an in a:", "- print((a_sorted[an == a_sorted[0]]))", "+a_sorted = sorted(a, reverse=True)[:2]", "+print((\"\\n\".join(map(str, [a_sorted[an == a_sorted[0]] for an in a]))))" ]
false
0.077358
0.043697
1.770319
[ "s559025616", "s478207996" ]
u687159441
p02983
python
s949523126
s738817956
981
44
148,280
3,060
Accepted
Accepted
95.51
# lとrの差が2019以上ならば間に必ず2019の倍数が存在するので0になる # lとrの差が2019より小さければ、余りのリストを作成しi、jの組み合わせをすべて計算してminを求める # 2019C2なので10**8を上回ることはない import itertools l, r = list(map(int, input().split())) l_rest = l % 2019 r_rest = r % 2019 if l_rest == 0 or r_rest == 0: print((0)) elif r-l < 2019: lr_list = list(range(l_rest, r_rest+1)) lr_comb = list(itertools.combinations(lr_list, 2)) min_rest = 2018 for comb in lr_comb: rest = comb[0] * comb[1] min_rest = min(min_rest, rest%2019) print(min_rest) elif r-l >= 2019: print((0))
# 前から計算して見つかったら止めるのが一番早い l,r=list(map(int, input().split())) import sys ans = 2018 for i in range(l,r): for j in range(i+1,r+1): a = (i*j) % 2019 if a < ans: ans = a if ans == 0: print(ans) sys.exit() print(ans)
22
13
571
281
# lとrの差が2019以上ならば間に必ず2019の倍数が存在するので0になる # lとrの差が2019より小さければ、余りのリストを作成しi、jの組み合わせをすべて計算してminを求める # 2019C2なので10**8を上回ることはない import itertools l, r = list(map(int, input().split())) l_rest = l % 2019 r_rest = r % 2019 if l_rest == 0 or r_rest == 0: print((0)) elif r - l < 2019: lr_list = list(range(l_rest, r_rest + 1)) lr_comb = list(itertools.combinations(lr_list, 2)) min_rest = 2018 for comb in lr_comb: rest = comb[0] * comb[1] min_rest = min(min_rest, rest % 2019) print(min_rest) elif r - l >= 2019: print((0))
# 前から計算して見つかったら止めるのが一番早い l, r = list(map(int, input().split())) import sys ans = 2018 for i in range(l, r): for j in range(i + 1, r + 1): a = (i * j) % 2019 if a < ans: ans = a if ans == 0: print(ans) sys.exit() print(ans)
false
40.909091
[ "-# lとrの差が2019以上ならば間に必ず2019の倍数が存在するので0になる", "-# lとrの差が2019より小さければ、余りのリストを作成しi、jの組み合わせをすべて計算してminを求める", "-# 2019C2なので10**8を上回ることはない", "-import itertools", "+# 前から計算して見つかったら止めるのが一番早い", "+l, r = list(map(int, input().split()))", "+import sys", "-l, r = list(map(int, input().split()))", "-l_rest = l % 2...
false
0.084995
0.037784
2.249505
[ "s949523126", "s738817956" ]
u222668979
p03089
python
s720939597
s535375384
262
138
63,564
63,184
Accepted
Accepted
47.33
n = int(input()) b = list(map(int, input().split())) ans = [] for _ in range(n): for i, bi in enumerate(b[::-1]): i = len(b) - i if i == bi: ans.append(b.pop(i-1)) break print(*(ans[::-1] if len(ans) == n else[-1]), sep='\n')
n = int(input()) b = list(map(int, input().split())) ans = [] for _ in range(n): for i, bi in enumerate(b[::-1]): if len(b) == bi + i: ans.append(b.pop(len(b) - i - 1)) break print(*(ans[::-1] if len(ans) == n else [-1]), sep='\n')
11
10
281
278
n = int(input()) b = list(map(int, input().split())) ans = [] for _ in range(n): for i, bi in enumerate(b[::-1]): i = len(b) - i if i == bi: ans.append(b.pop(i - 1)) break print(*(ans[::-1] if len(ans) == n else [-1]), sep="\n")
n = int(input()) b = list(map(int, input().split())) ans = [] for _ in range(n): for i, bi in enumerate(b[::-1]): if len(b) == bi + i: ans.append(b.pop(len(b) - i - 1)) break print(*(ans[::-1] if len(ans) == n else [-1]), sep="\n")
false
9.090909
[ "- i = len(b) - i", "- if i == bi:", "- ans.append(b.pop(i - 1))", "+ if len(b) == bi + i:", "+ ans.append(b.pop(len(b) - i - 1))" ]
false
0.072685
0.10806
0.672634
[ "s720939597", "s535375384" ]
u191874006
p03674
python
s993522319
s069959315
767
412
69,080
57,744
Accepted
Accepted
46.28
#!/usr/bin/env python3 #ABC66 D import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def f(a, b): if b == 0: return 1 if b % 2 == 0: d = f(a, b // 2) return d * d % mod if b % 2 == 1: return (a * f(a, b - 1)) % mod def comb(n,r): if n - r < 0: return 0 return fact[n] * invfact[r] * invfact[n-r] % mod n = I() a = LI() cnt = [0]*(n+1) for i in range(n+1): if cnt[a[i]]: a = cnt[a[i]] b = i+1 break else: cnt[a[i]] = i+1 fact = [1]*(n+2) invfact = [1]*(n+2) for i in range(1,n+2): fact[i] = i*fact[i-1] % mod invfact[i] = invfact[i-1] * f(i,mod-2) % mod for i in range(n+1): res = 0 res = (res + comb(n+1,i+1)) % mod res = (res - comb((a-1)+(n+1-b),i)) % mod print(res)
#!/usr/bin/env python3 #ABC66 D import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def comb(n,r): if n - r < 0: return 0 return fact[n] * invfact[r] * invfact[n-r] % mod n = I() a = LI() cnt = [0]*(n+1) for i in range(n+1): if cnt[a[i]]: a = cnt[a[i]] b = i+1 break else: cnt[a[i]] = i+1 fact = [1]*(n+2) invfact = [1]*(n+2) for i in range(1,n+2): fact[i] = i*fact[i-1] % mod invfact[i] = invfact[i-1] * pow(i,mod-2,mod) % mod for i in range(n+1): res = 0 res = (res + comb(n+1,i+1)) % mod res = (res - comb((a-1)+(n+1-b),i)) % mod print(res)
57
49
1,320
1,143
#!/usr/bin/env python3 # ABC66 D import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def f(a, b): if b == 0: return 1 if b % 2 == 0: d = f(a, b // 2) return d * d % mod if b % 2 == 1: return (a * f(a, b - 1)) % mod def comb(n, r): if n - r < 0: return 0 return fact[n] * invfact[r] * invfact[n - r] % mod n = I() a = LI() cnt = [0] * (n + 1) for i in range(n + 1): if cnt[a[i]]: a = cnt[a[i]] b = i + 1 break else: cnt[a[i]] = i + 1 fact = [1] * (n + 2) invfact = [1] * (n + 2) for i in range(1, n + 2): fact[i] = i * fact[i - 1] % mod invfact[i] = invfact[i - 1] * f(i, mod - 2) % mod for i in range(n + 1): res = 0 res = (res + comb(n + 1, i + 1)) % mod res = (res - comb((a - 1) + (n + 1 - b), i)) % mod print(res)
#!/usr/bin/env python3 # ABC66 D import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def comb(n, r): if n - r < 0: return 0 return fact[n] * invfact[r] * invfact[n - r] % mod n = I() a = LI() cnt = [0] * (n + 1) for i in range(n + 1): if cnt[a[i]]: a = cnt[a[i]] b = i + 1 break else: cnt[a[i]] = i + 1 fact = [1] * (n + 2) invfact = [1] * (n + 2) for i in range(1, n + 2): fact[i] = i * fact[i - 1] % mod invfact[i] = invfact[i - 1] * pow(i, mod - 2, mod) % mod for i in range(n + 1): res = 0 res = (res + comb(n + 1, i + 1)) % mod res = (res - comb((a - 1) + (n + 1 - b), i)) % mod print(res)
false
14.035088
[ "-def f(a, b):", "- if b == 0:", "- return 1", "- if b % 2 == 0:", "- d = f(a, b // 2)", "- return d * d % mod", "- if b % 2 == 1:", "- return (a * f(a, b - 1)) % mod", "-", "-", "- invfact[i] = invfact[i - 1] * f(i, mod - 2) % mod", "+ invfact[i] = i...
false
0.04052
0.035125
1.153612
[ "s993522319", "s069959315" ]
u699296734
p03645
python
s629048695
s021155194
681
437
81,284
23,868
Accepted
Accepted
35.83
n, m = list(map(int, input().split())) root_map = dict() root_map[1] = set() root_map[n] = set() for i in range(m): a, b = list(map(int, input().split())) if a not in root_map: root_map[a] = set() root_map[a].add(b) else: root_map[a].add(b) if b not in root_map: root_map[b] = set() root_map[b].add(a) else: root_map[b].add(a) for i in root_map[1]: if i in root_map[n]: print("POSSIBLE") break else: print("IMPOSSIBLE")
n, m = list(map(int, input().split())) root_map = dict() root_map[1] = set() root_map[n] = set() for i in range(m): a, b = list(map(int, input().split())) if a == 1 or a == n: root_map[a].add(b) if b == 1 or b == n: root_map[b].add(a) for i in root_map[1]: if i in root_map[n]: print("POSSIBLE") break else: print("IMPOSSIBLE")
24
18
525
387
n, m = list(map(int, input().split())) root_map = dict() root_map[1] = set() root_map[n] = set() for i in range(m): a, b = list(map(int, input().split())) if a not in root_map: root_map[a] = set() root_map[a].add(b) else: root_map[a].add(b) if b not in root_map: root_map[b] = set() root_map[b].add(a) else: root_map[b].add(a) for i in root_map[1]: if i in root_map[n]: print("POSSIBLE") break else: print("IMPOSSIBLE")
n, m = list(map(int, input().split())) root_map = dict() root_map[1] = set() root_map[n] = set() for i in range(m): a, b = list(map(int, input().split())) if a == 1 or a == n: root_map[a].add(b) if b == 1 or b == n: root_map[b].add(a) for i in root_map[1]: if i in root_map[n]: print("POSSIBLE") break else: print("IMPOSSIBLE")
false
25
[ "- if a not in root_map:", "- root_map[a] = set()", "+ if a == 1 or a == n:", "- else:", "- root_map[a].add(b)", "- if b not in root_map:", "- root_map[b] = set()", "- root_map[b].add(a)", "- else:", "+ if b == 1 or b == n:" ]
false
0.070648
0.03965
1.781799
[ "s629048695", "s021155194" ]
u308684517
p04031
python
s797727362
s199441764
25
17
3,060
3,060
Accepted
Accepted
32
n = int(eval(input())) A = list(map(int, input().split())) ans = 10**10 for i in range(-100, 101): t = 0 for j in A: t += (j-i)**2 if t < ans: ans = t print(ans)
n = int(eval(input())) A = list(map(int, input().split())) avg = sum(A)//n avg2 = sum(A)//n + 1 ans = 0 ans2 = 0 for i in A: ans += (i-avg)**2 ans2 += (i-avg2)**2 print((min(ans, ans2)))
10
10
192
195
n = int(eval(input())) A = list(map(int, input().split())) ans = 10**10 for i in range(-100, 101): t = 0 for j in A: t += (j - i) ** 2 if t < ans: ans = t print(ans)
n = int(eval(input())) A = list(map(int, input().split())) avg = sum(A) // n avg2 = sum(A) // n + 1 ans = 0 ans2 = 0 for i in A: ans += (i - avg) ** 2 ans2 += (i - avg2) ** 2 print((min(ans, ans2)))
false
0
[ "-ans = 10**10", "-for i in range(-100, 101):", "- t = 0", "- for j in A:", "- t += (j - i) ** 2", "- if t < ans:", "- ans = t", "-print(ans)", "+avg = sum(A) // n", "+avg2 = sum(A) // n + 1", "+ans = 0", "+ans2 = 0", "+for i in A:", "+ ans += (i - avg) ** 2", "...
false
0.068281
0.15891
0.429685
[ "s797727362", "s199441764" ]
u606045429
p03911
python
s529081080
s409439260
525
478
9,148
9,148
Accepted
Accepted
8.95
class UnionFind: def __init__(self, size): self.data = [-1] * size def find(self, x): if self.data[x] < 0: return x else: self.data[x] = self.find(self.data[x]) return self.data[x] def union(self, x, y): x, y = self.find(x), self.find(y) if x != y: if self.data[y] < self.data[x]: x, y = y, x self.data[x] += self.data[y] self.data[y] = x return (x != y) def same(self, x, y): return (self.find(x) == self.find(y)) def size(self, x): return -self.data[self.find(x)] N, M = list(map(int, input().split())) uf = UnionFind(N + M + 1) used = set() for i in range(1, N + 1): K, *L = list(map(int, input().split())) for l in L: uf.union(i, l + N) used.add(l) if uf.size(1) - len(used) == N: print("YES") else: print("NO")
class UnionFind: def __init__(self, size): self.data = [-1] * size def find(self, x): if self.data[x] < 0: return x else: self.data[x] = self.find(self.data[x]) return self.data[x] def union(self, x, y): x, y = self.find(x), self.find(y) if x != y: if self.data[y] < self.data[x]: x, y = y, x self.data[x] += self.data[y] self.data[y] = x return (x != y) def same(self, x, y): return (self.find(x) == self.find(y)) def size(self, x): return -self.data[self.find(x)] N, M = list(map(int, input().split())) uf = UnionFind(M + 1) used = set() for _ in range(N): K, *L = list(map(int, input().split())) for l in L: uf.union(L[0], l) used.update(L) if uf.size(used.pop()) == 1 + len(used): print("YES") else: print("NO")
40
40
954
950
class UnionFind: def __init__(self, size): self.data = [-1] * size def find(self, x): if self.data[x] < 0: return x else: self.data[x] = self.find(self.data[x]) return self.data[x] def union(self, x, y): x, y = self.find(x), self.find(y) if x != y: if self.data[y] < self.data[x]: x, y = y, x self.data[x] += self.data[y] self.data[y] = x return x != y def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.data[self.find(x)] N, M = list(map(int, input().split())) uf = UnionFind(N + M + 1) used = set() for i in range(1, N + 1): K, *L = list(map(int, input().split())) for l in L: uf.union(i, l + N) used.add(l) if uf.size(1) - len(used) == N: print("YES") else: print("NO")
class UnionFind: def __init__(self, size): self.data = [-1] * size def find(self, x): if self.data[x] < 0: return x else: self.data[x] = self.find(self.data[x]) return self.data[x] def union(self, x, y): x, y = self.find(x), self.find(y) if x != y: if self.data[y] < self.data[x]: x, y = y, x self.data[x] += self.data[y] self.data[y] = x return x != y def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.data[self.find(x)] N, M = list(map(int, input().split())) uf = UnionFind(M + 1) used = set() for _ in range(N): K, *L = list(map(int, input().split())) for l in L: uf.union(L[0], l) used.update(L) if uf.size(used.pop()) == 1 + len(used): print("YES") else: print("NO")
false
0
[ "-uf = UnionFind(N + M + 1)", "+uf = UnionFind(M + 1)", "-for i in range(1, N + 1):", "+for _ in range(N):", "- uf.union(i, l + N)", "- used.add(l)", "-if uf.size(1) - len(used) == N:", "+ uf.union(L[0], l)", "+ used.update(L)", "+if uf.size(used.pop()) == 1 + len(used):" ]
false
0.054343
0.040148
1.353589
[ "s529081080", "s409439260" ]
u761989513
p03574
python
s482192061
s693804694
31
22
3,064
3,064
Accepted
Accepted
29.03
h, w = list(map(int, input().split())) s = [list(eval(input())) for _ in range(h)] for i in range(h): ans = [] for j in range(w): bomb = 0 if s[i][j] == ".": for k in [0, -1, 1]: for n in [0, -1, 1]: if i + k < h and j + n < w: if i + k < 0 or j + n < 0: continue if s[i + k][j + n] == "#": bomb += 1 ans.append(str(bomb)) else: ans.append("#") print(("".join(ans)))
h, w = list(map(int, input().split())) s = [list(eval(input())) for i in range(h)] for i in range(h): T = "" for j in range(w): if s[i][j] == ".": count = 0 if i < h - 1: if s[i + 1][j] == "#": count += 1 if j < w - 1: if s[i + 1][j + 1] == "#": count += 1 if j > 0: if s[i + 1][j - 1] == "#": count += 1 if i > 0: if s[i - 1][j] == "#": count += 1 if j < w - 1: if s[i - 1][j + 1] == "#": count += 1 if j > 0: if s[i - 1][j - 1] == "#": count += 1 if j < w - 1: if s[i][j + 1] == "#": count += 1 if j > 0: if s[i][j - 1] == "#": count += 1 T += str(count) else: T += "#" print(T)
18
35
581
1,098
h, w = list(map(int, input().split())) s = [list(eval(input())) for _ in range(h)] for i in range(h): ans = [] for j in range(w): bomb = 0 if s[i][j] == ".": for k in [0, -1, 1]: for n in [0, -1, 1]: if i + k < h and j + n < w: if i + k < 0 or j + n < 0: continue if s[i + k][j + n] == "#": bomb += 1 ans.append(str(bomb)) else: ans.append("#") print(("".join(ans)))
h, w = list(map(int, input().split())) s = [list(eval(input())) for i in range(h)] for i in range(h): T = "" for j in range(w): if s[i][j] == ".": count = 0 if i < h - 1: if s[i + 1][j] == "#": count += 1 if j < w - 1: if s[i + 1][j + 1] == "#": count += 1 if j > 0: if s[i + 1][j - 1] == "#": count += 1 if i > 0: if s[i - 1][j] == "#": count += 1 if j < w - 1: if s[i - 1][j + 1] == "#": count += 1 if j > 0: if s[i - 1][j - 1] == "#": count += 1 if j < w - 1: if s[i][j + 1] == "#": count += 1 if j > 0: if s[i][j - 1] == "#": count += 1 T += str(count) else: T += "#" print(T)
false
48.571429
[ "-s = [list(eval(input())) for _ in range(h)]", "+s = [list(eval(input())) for i in range(h)]", "- ans = []", "+ T = \"\"", "- bomb = 0", "- for k in [0, -1, 1]:", "- for n in [0, -1, 1]:", "- if i + k < h and j + n < w:", "- ...
false
0.040269
0.107202
0.375638
[ "s482192061", "s693804694" ]
u203843959
p03700
python
s617700215
s672167949
784
410
60,456
118,620
Accepted
Accepted
47.7
import sys input=sys.stdin.readline N,A,B=list(map(int,input().split())) hlist=[] for i in range(N): hlist.append(int(eval(input()))) mh=max(hlist) #print(mh,hlist) def isOK(m): if m==0: return False hlist2=list(hlist) for i in range(N): hlist2[i]-=m*B #print(m,hlist2) if max(hlist2)<=0: return True cnt=0 for i in range(N): if hlist2[i]>0: cnt+=-(-hlist2[i]//(A-B)) return cnt<=m l,r=1,mh//B+1 while l<=r: mid=(l+r)//2 #print(l,mid,r) if not isOK(mid-1) and isOK(mid): print(mid) break elif isOK(mid-1): r=mid-1 else: l=mid+1
import sys input=sys.stdin.readline N,A,B=list(map(int,input().split())) hlist=[] mh=0 for i in range(N): h=int(eval(input())) hlist.append(h) mh=max(mh,h) #print(mh,hlist) res_dic={0:False} def isOK(m): if m in res_dic: return res_dic[m] h2list=[] mh2=-float("inf") for i in range(N): h2=hlist[i]-m*B h2list.append(h2) mh2=max(h2,mh2) if mh2<=0: res_dic[m]=True return res_dic[m] cnt=0 for i in range(N): if h2list[i]>0: cnt+=-(-h2list[i]//(A-B)) res_dic[m]=(cnt<=m) return res_dic[m] l,r=1,-(-mh//B) while l<=r: mid=(l+r)//2 #print(l,mid,r) if not isOK(mid-1) and isOK(mid): print(mid) break elif isOK(mid-1): r=mid-1 else: l=mid+1
38
46
627
766
import sys input = sys.stdin.readline N, A, B = list(map(int, input().split())) hlist = [] for i in range(N): hlist.append(int(eval(input()))) mh = max(hlist) # print(mh,hlist) def isOK(m): if m == 0: return False hlist2 = list(hlist) for i in range(N): hlist2[i] -= m * B # print(m,hlist2) if max(hlist2) <= 0: return True cnt = 0 for i in range(N): if hlist2[i] > 0: cnt += -(-hlist2[i] // (A - B)) return cnt <= m l, r = 1, mh // B + 1 while l <= r: mid = (l + r) // 2 # print(l,mid,r) if not isOK(mid - 1) and isOK(mid): print(mid) break elif isOK(mid - 1): r = mid - 1 else: l = mid + 1
import sys input = sys.stdin.readline N, A, B = list(map(int, input().split())) hlist = [] mh = 0 for i in range(N): h = int(eval(input())) hlist.append(h) mh = max(mh, h) # print(mh,hlist) res_dic = {0: False} def isOK(m): if m in res_dic: return res_dic[m] h2list = [] mh2 = -float("inf") for i in range(N): h2 = hlist[i] - m * B h2list.append(h2) mh2 = max(h2, mh2) if mh2 <= 0: res_dic[m] = True return res_dic[m] cnt = 0 for i in range(N): if h2list[i] > 0: cnt += -(-h2list[i] // (A - B)) res_dic[m] = cnt <= m return res_dic[m] l, r = 1, -(-mh // B) while l <= r: mid = (l + r) // 2 # print(l,mid,r) if not isOK(mid - 1) and isOK(mid): print(mid) break elif isOK(mid - 1): r = mid - 1 else: l = mid + 1
false
17.391304
[ "+mh = 0", "- hlist.append(int(eval(input())))", "-mh = max(hlist)", "+ h = int(eval(input()))", "+ hlist.append(h)", "+ mh = max(mh, h)", "+res_dic = {0: False}", "+", "+", "- if m == 0:", "- return False", "- hlist2 = list(hlist)", "+ if m in res_dic:", "+ ...
false
0.041814
0.041914
0.997598
[ "s617700215", "s672167949" ]
u076917070
p03044
python
s092482294
s377495562
934
732
156,208
85,204
Accepted
Accepted
21.63
import sys input = sys.stdin.readline sys.setrecursionlimit(10**5) N = int(eval(input())) G = [[] for _ in range(N)] for _ in range(N-1): u, v, w = list(map(int, input().split())) G[u-1].append([v-1, w]) G[v-1].append([u-1, w]) ans = [0]*N def dfs(v, p, c): global ans ans[v] = c for e in G[v]: nv, cost = e if nv == p: continue if (cost % 2) == 0: dfs(nv, v, c) else: dfs(nv, v, (c+1) % 2) def main(): dfs(0, -1, 0) for c in ans: print(c) if __name__ == '__main__': main()
import sys sys.setrecursionlimit(10**5) input = sys.stdin.readline N = int(eval(input())) G = [[] for _ in range(N)] for _ in range(N-1): u, v, w = list(map(int, input().split())) G[u-1].append([v-1, w]) G[v-1].append([u-1, w]) ans = [0]*N def dfs(v, p, c): global ans ans[v] = c for e in G[v]: nv, cost = e if nv == p: continue if (cost % 2) == 0: dfs(nv, v, c) else: dfs(nv, v, (c+1) % 2) def main(): dfs(0, -1, 0) for c in ans: print(c) if __name__ == '__main__': main()
35
35
616
616
import sys input = sys.stdin.readline sys.setrecursionlimit(10**5) N = int(eval(input())) G = [[] for _ in range(N)] for _ in range(N - 1): u, v, w = list(map(int, input().split())) G[u - 1].append([v - 1, w]) G[v - 1].append([u - 1, w]) ans = [0] * N def dfs(v, p, c): global ans ans[v] = c for e in G[v]: nv, cost = e if nv == p: continue if (cost % 2) == 0: dfs(nv, v, c) else: dfs(nv, v, (c + 1) % 2) def main(): dfs(0, -1, 0) for c in ans: print(c) if __name__ == "__main__": main()
import sys sys.setrecursionlimit(10**5) input = sys.stdin.readline N = int(eval(input())) G = [[] for _ in range(N)] for _ in range(N - 1): u, v, w = list(map(int, input().split())) G[u - 1].append([v - 1, w]) G[v - 1].append([u - 1, w]) ans = [0] * N def dfs(v, p, c): global ans ans[v] = c for e in G[v]: nv, cost = e if nv == p: continue if (cost % 2) == 0: dfs(nv, v, c) else: dfs(nv, v, (c + 1) % 2) def main(): dfs(0, -1, 0) for c in ans: print(c) if __name__ == "__main__": main()
false
0
[ "+sys.setrecursionlimit(10**5)", "-sys.setrecursionlimit(10**5)" ]
false
0.125642
0.044152
2.845686
[ "s092482294", "s377495562" ]
u073852194
p03108
python
s210906531
s916070353
1,142
731
111,960
35,936
Accepted
Accepted
35.99
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) n,m = list(map(int,input().split())) Bridge = [list(map(int,input().split())) for i in range(m)] uf = UnionFind(n) Inconvenience = [n*(n-1)//2] for b in reversed(Bridge): if not uf.same(b[0]-1,b[1]-1): Inconvenience += [Inconvenience[-1]-uf.size(b[0]-1)*uf.size(b[1]-1)] uf.union(b[0]-1,b[1]-1) else: Inconvenience += [Inconvenience[-1]] Inconvenience.pop() for i in reversed(Inconvenience): print(i)
class UnionFind(): def __init__(self, n): self.n = n self.parents = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): root = x while self.parents[root] != root: root = self.parents[root] while self.parents[x] != root: parent = self.parents[x] self.parents[x] = root x = parent return root def unite(self, x, y): xroot = self.find(x) yroot = self.find(y) if xroot == yroot: return xrank = self.rank[xroot] yrank = self.rank[yroot] if xrank < yrank: self.parents[xroot] = yroot self.size[yroot] += self.size[xroot] elif xrank == yrank: self.parents[yroot] = xroot self.rank[yroot] += 1 self.size[xroot] += self.size[yroot] else: self.parents[yroot] = xroot self.size[xroot] += self.size[yroot] def len(self, x): return self.size[self.find(x)] import sys input = sys.stdin.readline N, M = list(map(int, input().split())) bridge = [tuple(map(int, input().split())) for _ in range(M)] uf = UnionFind(N) inc = N * (N - 1) // 2 ans = [inc] for a, b in reversed(bridge): if uf.find(a - 1) != uf.find(b - 1): la = uf.len(a - 1) lb = uf.len(b - 1) uf.unite(a - 1, b - 1) lab = uf.len(a - 1) inc += la * (la - 1) // 2 + lb * (lb - 1) // 2 - lab * (lab - 1) // 2 ans.append(inc) print(('\n'.join(map(str, ans[:-1][::-1]))))
45
59
1,140
1,673
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) n, m = list(map(int, input().split())) Bridge = [list(map(int, input().split())) for i in range(m)] uf = UnionFind(n) Inconvenience = [n * (n - 1) // 2] for b in reversed(Bridge): if not uf.same(b[0] - 1, b[1] - 1): Inconvenience += [Inconvenience[-1] - uf.size(b[0] - 1) * uf.size(b[1] - 1)] uf.union(b[0] - 1, b[1] - 1) else: Inconvenience += [Inconvenience[-1]] Inconvenience.pop() for i in reversed(Inconvenience): print(i)
class UnionFind: def __init__(self, n): self.n = n self.parents = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): root = x while self.parents[root] != root: root = self.parents[root] while self.parents[x] != root: parent = self.parents[x] self.parents[x] = root x = parent return root def unite(self, x, y): xroot = self.find(x) yroot = self.find(y) if xroot == yroot: return xrank = self.rank[xroot] yrank = self.rank[yroot] if xrank < yrank: self.parents[xroot] = yroot self.size[yroot] += self.size[xroot] elif xrank == yrank: self.parents[yroot] = xroot self.rank[yroot] += 1 self.size[xroot] += self.size[yroot] else: self.parents[yroot] = xroot self.size[xroot] += self.size[yroot] def len(self, x): return self.size[self.find(x)] import sys input = sys.stdin.readline N, M = list(map(int, input().split())) bridge = [tuple(map(int, input().split())) for _ in range(M)] uf = UnionFind(N) inc = N * (N - 1) // 2 ans = [inc] for a, b in reversed(bridge): if uf.find(a - 1) != uf.find(b - 1): la = uf.len(a - 1) lb = uf.len(b - 1) uf.unite(a - 1, b - 1) lab = uf.len(a - 1) inc += la * (la - 1) // 2 + lb * (lb - 1) // 2 - lab * (lab - 1) // 2 ans.append(inc) print(("\n".join(map(str, ans[:-1][::-1]))))
false
23.728814
[ "- self.parents = [-1] * n", "+ self.parents = [i for i in range(n)]", "+ self.rank = [0 for _ in range(n)]", "+ self.size = [1 for _ in range(n)]", "- if self.parents[x] < 0:", "- return x", "+ root = x", "+ while self.parents[root] != root:...
false
0.075446
0.046786
1.612594
[ "s210906531", "s916070353" ]
u917558625
p02787
python
s118864264
s032722855
1,671
414
3,668
14,528
Accepted
Accepted
75.22
n,m=list(map(int, input().split())) s=[list(map(int, input().split())) for i in range(m)] x=max(a for a,b in s) dp=[0]*(n+x) for i in range(0,n+x): if i>0: dp[i]=min(dp[i-a]+b for a,b in s) print((min(dp[n:])))
import numpy as np n,m=list(map(int,input().split())) a=np.zeros(m,dtype=int) b=np.zeros(m,dtype=int) for i in range(m): a[i],b[i]=list(map(int,input().split())) dp=np.zeros(10001,dtype=int) for i in range(1,10001): dp[i]=(dp[i-a]+b).min() print((dp[n]))
8
11
215
259
n, m = list(map(int, input().split())) s = [list(map(int, input().split())) for i in range(m)] x = max(a for a, b in s) dp = [0] * (n + x) for i in range(0, n + x): if i > 0: dp[i] = min(dp[i - a] + b for a, b in s) print((min(dp[n:])))
import numpy as np n, m = list(map(int, input().split())) a = np.zeros(m, dtype=int) b = np.zeros(m, dtype=int) for i in range(m): a[i], b[i] = list(map(int, input().split())) dp = np.zeros(10001, dtype=int) for i in range(1, 10001): dp[i] = (dp[i - a] + b).min() print((dp[n]))
false
27.272727
[ "+import numpy as np", "+", "-s = [list(map(int, input().split())) for i in range(m)]", "-x = max(a for a, b in s)", "-dp = [0] * (n + x)", "-for i in range(0, n + x):", "- if i > 0:", "- dp[i] = min(dp[i - a] + b for a, b in s)", "-print((min(dp[n:])))", "+a = np.zeros(m, dtype=int)", ...
false
0.137726
0.223127
0.617254
[ "s118864264", "s032722855" ]
u349449706
p03151
python
s292043676
s408245335
135
123
95,008
95,804
Accepted
Accepted
8.89
import bisect N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = sorted([A[i] - B[i] for i in range(N)]) if sum(C) < 0: print((-1)) elif min(C) >= 0: print((0)) else: D = sorted([i for i in C if i > 0], reverse=True) r = [D[0]] for i in range(len(D)-1): r.append(r[i] + D[i+1]) print((len([i for i in C if i < 0])+bisect.bisect_left(r, sum(-i for i in C if i < 0))+1))
import bisect N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = sorted([A[i] - B[i] for i in range(N)]) if sum(C) < 0: print((-1)) elif min(C) >= 0: print((0)) else: D = [i for i in C if i < 0] m = sum(D) for i in range(N-1,-1,-1): m += C[i] if m >= 0: print((len(D)-i+N)) break
15
17
451
392
import bisect N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = sorted([A[i] - B[i] for i in range(N)]) if sum(C) < 0: print((-1)) elif min(C) >= 0: print((0)) else: D = sorted([i for i in C if i > 0], reverse=True) r = [D[0]] for i in range(len(D) - 1): r.append(r[i] + D[i + 1]) print( ( len([i for i in C if i < 0]) + bisect.bisect_left(r, sum(-i for i in C if i < 0)) + 1 ) )
import bisect N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = sorted([A[i] - B[i] for i in range(N)]) if sum(C) < 0: print((-1)) elif min(C) >= 0: print((0)) else: D = [i for i in C if i < 0] m = sum(D) for i in range(N - 1, -1, -1): m += C[i] if m >= 0: print((len(D) - i + N)) break
false
11.764706
[ "- D = sorted([i for i in C if i > 0], reverse=True)", "- r = [D[0]]", "- for i in range(len(D) - 1):", "- r.append(r[i] + D[i + 1])", "- print(", "- (", "- len([i for i in C if i < 0])", "- + bisect.bisect_left(r, sum(-i for i in C if i < 0))", "- ...
false
0.042346
0.046737
0.906053
[ "s292043676", "s408245335" ]
u644907318
p03951
python
s333495578
s809856040
66
24
61,920
9,184
Accepted
Accepted
63.64
N = int(eval(input())) s = input().strip() t = input().strip() ind = -1 for i in range(N): x = s[i:] y = t[:N-i] if x==y: ind = i break if ind>=0: print((N+i)) else: print((2*N))
N = int(eval(input())) s = input().strip() t = input().strip() lmin = 2*N for i in range(1,N+1): if s[-i:]==t[:i]: lmin = min(lmin,2*N-i) print(lmin)
14
8
217
162
N = int(eval(input())) s = input().strip() t = input().strip() ind = -1 for i in range(N): x = s[i:] y = t[: N - i] if x == y: ind = i break if ind >= 0: print((N + i)) else: print((2 * N))
N = int(eval(input())) s = input().strip() t = input().strip() lmin = 2 * N for i in range(1, N + 1): if s[-i:] == t[:i]: lmin = min(lmin, 2 * N - i) print(lmin)
false
42.857143
[ "-ind = -1", "-for i in range(N):", "- x = s[i:]", "- y = t[: N - i]", "- if x == y:", "- ind = i", "- break", "-if ind >= 0:", "- print((N + i))", "-else:", "- print((2 * N))", "+lmin = 2 * N", "+for i in range(1, N + 1):", "+ if s[-i:] == t[:i]:", "+ ...
false
0.038102
0.035936
1.060264
[ "s333495578", "s809856040" ]
u667135132
p02882
python
s609364928
s905577205
148
17
12,488
3,060
Accepted
Accepted
88.51
import numpy as np a,b,x = list(map(int,input().split())) l = x/(a*a) if l<=b/2.0: f = b**2.0/(2.0*a*l) else: f = 2.0*(b-l)/a ans = np.rad2deg(np.arctan(f)) print(ans)
import math a,b,x = list(map(int,input().split())) l = x/(a*a) if l<=b/2.0: f = b**2.0/(2.0*a*l) else: f = 2.0*(b-l)/a ans = math.degrees(math.atan(f)) print(ans)
13
13
191
186
import numpy as np a, b, x = list(map(int, input().split())) l = x / (a * a) if l <= b / 2.0: f = b**2.0 / (2.0 * a * l) else: f = 2.0 * (b - l) / a ans = np.rad2deg(np.arctan(f)) print(ans)
import math a, b, x = list(map(int, input().split())) l = x / (a * a) if l <= b / 2.0: f = b**2.0 / (2.0 * a * l) else: f = 2.0 * (b - l) / a ans = math.degrees(math.atan(f)) print(ans)
false
0
[ "-import numpy as np", "+import math", "-ans = np.rad2deg(np.arctan(f))", "+ans = math.degrees(math.atan(f))" ]
false
0.730914
0.126649
5.77117
[ "s609364928", "s905577205" ]
u624475441
p03494
python
s086276235
s057389556
35
18
3,064
3,060
Accepted
Accepted
48.57
N=int(eval(input())) A=list(map(int,input().split())) ans=0 while 1 not in[a%2 for a in A]: A=[a//2 for a in A] ans+=1 print(ans)
eval(input()) n=eval(input().replace(' ','|')) print((len(bin(n&-n))-3))
7
3
131
66
N = int(eval(input())) A = list(map(int, input().split())) ans = 0 while 1 not in [a % 2 for a in A]: A = [a // 2 for a in A] ans += 1 print(ans)
eval(input()) n = eval(input().replace(" ", "|")) print((len(bin(n & -n)) - 3))
false
57.142857
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-ans = 0", "-while 1 not in [a % 2 for a in A]:", "- A = [a // 2 for a in A]", "- ans += 1", "-print(ans)", "+eval(input())", "+n = eval(input().replace(\" \", \"|\"))", "+print((len(bin(n & -n)) - 3))" ]
false
0.0456
0.049339
0.924228
[ "s086276235", "s057389556" ]
u150984829
p00099
python
s641331038
s140560122
370
300
13,716
13,712
Accepted
Accepted
18.92
import sys n,q=list(map(int,input().split())) s=[0]*-~n w=m=0 for e in sys.stdin: a,v=list(map(int,e.split())) s[a]+=v if v<0 and a==w:m=max(s);w=s.index(m) elif s[a]>m:w,m=a,s[a] elif s[a]==m:w=min(w,a) print((w,m))
import sys def f(): w=m=0;n,q=list(map(int,input().split()));s=[0]*-~n for e in sys.stdin: a,v=list(map(int,e.split()));s[a]+=v if v<0 and a==w:m=max(s);w=s.index(m) elif s[a]>m:w,m=a,s[a] elif s[a]==m:w=min(w,a) print((w,m)) if'__main__'==__name__:f()
11
10
219
260
import sys n, q = list(map(int, input().split())) s = [0] * -~n w = m = 0 for e in sys.stdin: a, v = list(map(int, e.split())) s[a] += v if v < 0 and a == w: m = max(s) w = s.index(m) elif s[a] > m: w, m = a, s[a] elif s[a] == m: w = min(w, a) print((w, m))
import sys def f(): w = m = 0 n, q = list(map(int, input().split())) s = [0] * -~n for e in sys.stdin: a, v = list(map(int, e.split())) s[a] += v if v < 0 and a == w: m = max(s) w = s.index(m) elif s[a] > m: w, m = a, s[a] elif s[a] == m: w = min(w, a) print((w, m)) if "__main__" == __name__: f()
false
9.090909
[ "-n, q = list(map(int, input().split()))", "-s = [0] * -~n", "-w = m = 0", "-for e in sys.stdin:", "- a, v = list(map(int, e.split()))", "- s[a] += v", "- if v < 0 and a == w:", "- m = max(s)", "- w = s.index(m)", "- elif s[a] > m:", "- w, m = a, s[a]", "- e...
false
0.046319
0.064357
0.719719
[ "s641331038", "s140560122" ]
u466917094
p03291
python
s684718314
s407817383
1,819
1,562
20,768
18,624
Accepted
Accepted
14.13
import numpy as np s=eval(input()) A=np.array([0,0,0,0]) B=np.array([0,0,0,0]) C=np.array([0,0,0,0]) t=0 for c in s: if c=="A": A[0]+=1 if c=="B": B+=A if c=='C': C+=B if c=='?': C[1]+=B[0] C[2]+=B[1] C[3]+=B[2] B[1]+=A[0] B[2]+=A[1] A[1]+=1 t+=1 ans=0 for i in range(4): ans+=pow(3,t-i)*C[i] print((int(ans%1000000007)))
import numpy as np s=eval(input()) A=np.array([0,0,0,0]) B=np.array([0,0,0,0]) C=np.array([0,0,0,0]) t=0 for c in s: if c=="A": A[0]+=1 if c=="B": B+=A if c=='C': C+=B if c=='?': C+=np.roll(B,1) B[1]+=A[0] B[2]+=A[1] A[1]+=1 t+=1 ans=0 for i in range(4): ans+=pow(3,t-i)*C[i] print((int(ans%1000000007)))
25
23
362
339
import numpy as np s = eval(input()) A = np.array([0, 0, 0, 0]) B = np.array([0, 0, 0, 0]) C = np.array([0, 0, 0, 0]) t = 0 for c in s: if c == "A": A[0] += 1 if c == "B": B += A if c == "C": C += B if c == "?": C[1] += B[0] C[2] += B[1] C[3] += B[2] B[1] += A[0] B[2] += A[1] A[1] += 1 t += 1 ans = 0 for i in range(4): ans += pow(3, t - i) * C[i] print((int(ans % 1000000007)))
import numpy as np s = eval(input()) A = np.array([0, 0, 0, 0]) B = np.array([0, 0, 0, 0]) C = np.array([0, 0, 0, 0]) t = 0 for c in s: if c == "A": A[0] += 1 if c == "B": B += A if c == "C": C += B if c == "?": C += np.roll(B, 1) B[1] += A[0] B[2] += A[1] A[1] += 1 t += 1 ans = 0 for i in range(4): ans += pow(3, t - i) * C[i] print((int(ans % 1000000007)))
false
8
[ "- C[1] += B[0]", "- C[2] += B[1]", "- C[3] += B[2]", "+ C += np.roll(B, 1)" ]
false
0.338026
0.186037
1.81698
[ "s684718314", "s407817383" ]
u352394527
p00454
python
s733355738
s895764420
2,730
940
25,332
21,832
Accepted
Accepted
65.57
import sys sys.setrecursionlimit(100000000) while True: w, h = list(map(int, input().split())) if not w: break n = int(eval(input())) xlst = [0, w - 1] ylst = [0, h - 1] plst = [] for i in range(n): x1, y1, x2, y2 = list(map(int, input().split())) plst.append([x1,y1,x2 - 1,y2 - 1]) xlst.append(x1) # xlst.append(x1 + 1) xlst.append(x2) xlst.append(x2 - 1) ylst.append(y1) # ylst.append(y1 + 1) ylst.append(y2) ylst.append(y2 - 1) xlst = list(set(xlst)) ylst = list(set(ylst)) sorted_xlst = sorted(xlst) sorted_ylst = sorted(ylst) xdic = {} ydic = {} for i, v in enumerate(sorted_xlst): xdic[v] = i for i, v in enumerate(sorted_ylst): ydic[v] = i neww = xdic[sorted_xlst[-1]] newh = ydic[sorted_ylst[-1]] # print(neww, newh) painted = [[0] * (newh) for _ in range(neww)] def paint_area(x, y): painted[x][y] = 1 for tx, ty in [(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)]: if 0 <= tx <= neww - 1 and 0 <= ty <= newh - 1 and not painted[tx][ty]: paint_area(tx, ty) for p in plst: x1, y1, x2, y2 = p x1, y1, x2, y2 = xdic[x1], ydic[y1], xdic[x2], ydic[y2] for x in range(x1, x2 + 1): for y in range(y1, y2 + 1): painted[x][y] = 1 # for area in painted: # print(area) # print() ans = 0 for x in range(neww): for y in range(newh): if not painted[x][y]: ans += 1 painted[x][y] = 1 que = [(x, y)] while que: px, py = que.pop() for tx, ty in [(px - 1, py), (px + 1, py), (px, py - 1), (px, py + 1)]: if 0 <= tx <= neww - 1 and 0 <= ty <= newh - 1 and not painted[tx][ty]: painted[tx][ty] = 1 que.append((tx,ty)) print(ans)
def main(): while True: w, h = list(map(int, input().split())) if not w: break n = int(eval(input())) xlst = [0, w - 1] ylst = [0, h - 1] plst = [] for i in range(n): x1, y1, x2, y2 = list(map(int, input().split())) plst.append([x1,y1,x2 - 1,y2 - 1]) xlst.append(x1) xlst.append(x2) xlst.append(x2 - 1) ylst.append(y1) ylst.append(y2) ylst.append(y2 - 1) xlst = list(set(xlst)) ylst = list(set(ylst)) sorted_xlst = sorted(xlst) sorted_ylst = sorted(ylst) xdic = {} ydic = {} for i, v in enumerate(sorted_xlst): xdic[v] = i for i, v in enumerate(sorted_ylst): ydic[v] = i neww = xdic[sorted_xlst[-1]] newh = ydic[sorted_ylst[-1]] painted = [[1] * (newh + 2)] for _ in range(neww): painted.append([1] + [0] * newh + [1]) painted.append([1] * (newh + 2)) for p in plst: x1, y1, x2, y2 = p x1, y1, x2, y2 = xdic[x1] + 1, ydic[y1] + 1, xdic[x2] + 1, ydic[y2] + 1 for x in range(x1, x2 + 1): for y in range(y1, y2 + 1): painted[x][y] = 1 ans = 0 que = [] app = que.append pp = que.pop for x in range(1, neww + 1): for y in range(1, newh + 1): if not painted[x][y]: ans += 1 painted[x][y] = 1 app((x,y)) while que: px, py = pp() for tx, ty in [(px - 1, py), (px + 1, py), (px, py - 1), (px, py + 1)]: if not painted[tx][ty]: painted[tx][ty] = 1 app((tx,ty)) print(ans) main()
78
69
1,854
1,705
import sys sys.setrecursionlimit(100000000) while True: w, h = list(map(int, input().split())) if not w: break n = int(eval(input())) xlst = [0, w - 1] ylst = [0, h - 1] plst = [] for i in range(n): x1, y1, x2, y2 = list(map(int, input().split())) plst.append([x1, y1, x2 - 1, y2 - 1]) xlst.append(x1) # xlst.append(x1 + 1) xlst.append(x2) xlst.append(x2 - 1) ylst.append(y1) # ylst.append(y1 + 1) ylst.append(y2) ylst.append(y2 - 1) xlst = list(set(xlst)) ylst = list(set(ylst)) sorted_xlst = sorted(xlst) sorted_ylst = sorted(ylst) xdic = {} ydic = {} for i, v in enumerate(sorted_xlst): xdic[v] = i for i, v in enumerate(sorted_ylst): ydic[v] = i neww = xdic[sorted_xlst[-1]] newh = ydic[sorted_ylst[-1]] # print(neww, newh) painted = [[0] * (newh) for _ in range(neww)] def paint_area(x, y): painted[x][y] = 1 for tx, ty in [(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)]: if 0 <= tx <= neww - 1 and 0 <= ty <= newh - 1 and not painted[tx][ty]: paint_area(tx, ty) for p in plst: x1, y1, x2, y2 = p x1, y1, x2, y2 = xdic[x1], ydic[y1], xdic[x2], ydic[y2] for x in range(x1, x2 + 1): for y in range(y1, y2 + 1): painted[x][y] = 1 # for area in painted: # print(area) # print() ans = 0 for x in range(neww): for y in range(newh): if not painted[x][y]: ans += 1 painted[x][y] = 1 que = [(x, y)] while que: px, py = que.pop() for tx, ty in [ (px - 1, py), (px + 1, py), (px, py - 1), (px, py + 1), ]: if ( 0 <= tx <= neww - 1 and 0 <= ty <= newh - 1 and not painted[tx][ty] ): painted[tx][ty] = 1 que.append((tx, ty)) print(ans)
def main(): while True: w, h = list(map(int, input().split())) if not w: break n = int(eval(input())) xlst = [0, w - 1] ylst = [0, h - 1] plst = [] for i in range(n): x1, y1, x2, y2 = list(map(int, input().split())) plst.append([x1, y1, x2 - 1, y2 - 1]) xlst.append(x1) xlst.append(x2) xlst.append(x2 - 1) ylst.append(y1) ylst.append(y2) ylst.append(y2 - 1) xlst = list(set(xlst)) ylst = list(set(ylst)) sorted_xlst = sorted(xlst) sorted_ylst = sorted(ylst) xdic = {} ydic = {} for i, v in enumerate(sorted_xlst): xdic[v] = i for i, v in enumerate(sorted_ylst): ydic[v] = i neww = xdic[sorted_xlst[-1]] newh = ydic[sorted_ylst[-1]] painted = [[1] * (newh + 2)] for _ in range(neww): painted.append([1] + [0] * newh + [1]) painted.append([1] * (newh + 2)) for p in plst: x1, y1, x2, y2 = p x1, y1, x2, y2 = xdic[x1] + 1, ydic[y1] + 1, xdic[x2] + 1, ydic[y2] + 1 for x in range(x1, x2 + 1): for y in range(y1, y2 + 1): painted[x][y] = 1 ans = 0 que = [] app = que.append pp = que.pop for x in range(1, neww + 1): for y in range(1, newh + 1): if not painted[x][y]: ans += 1 painted[x][y] = 1 app((x, y)) while que: px, py = pp() for tx, ty in [ (px - 1, py), (px + 1, py), (px, py - 1), (px, py + 1), ]: if not painted[tx][ty]: painted[tx][ty] = 1 app((tx, ty)) print(ans) main()
false
11.538462
[ "-import sys", "+def main():", "+ while True:", "+ w, h = list(map(int, input().split()))", "+ if not w:", "+ break", "+ n = int(eval(input()))", "+ xlst = [0, w - 1]", "+ ylst = [0, h - 1]", "+ plst = []", "+ for i in range(n):", ...
false
0.039371
0.039423
0.99868
[ "s733355738", "s895764420" ]
u477320129
p03546
python
s802549487
s919282979
37
33
3,316
3,316
Accepted
Accepted
10.81
#!/usr/bin/env python3 import sys def solve(H: int, W: int, c: "List[List[int]]", A: "List[List[int]]"): #print(*c, sep='\n') for _ in range(10): for i in range(10): for j in range(10): for k in range(10): c[i][j] = min(c[i][j], c[i][k]+c[k][j]) #print(*c, sep='\n') cost = 0 for a in A: for aa in a: if aa == -1: continue cost += c[aa][1] return cost # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() H = int(next(tokens)) # type: int W = int(next(tokens)) # type: int c = [[int(next(tokens)) for _ in range(9 - 0 + 1)] for _ in range(9 - 0 + 1)] # type: "List[List[int]]" A = [[int(next(tokens)) for _ in range(W)] for _ in range(H)] # type: "List[List[int]]" print((solve(H, W, c, A))) def test(): import doctest doctest.testmod() if __name__ == '__main__': #test() main()
#!/usr/bin/env python3 import sys def solve(H: int, W: int, c: "List[List[int]]", A: "List[List[int]]"): #print(*c, sep='\n') for k in range(10): for i in range(10): for j in range(10): c[i][j] = min(c[i][j], c[i][k]+c[k][j]) #print(*c, sep='\n') cost = 0 for a in A: for aa in a: if aa == -1: continue cost += c[aa][1] return cost # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() H = int(next(tokens)) # type: int W = int(next(tokens)) # type: int c = [[int(next(tokens)) for _ in range(9 - 0 + 1)] for _ in range(9 - 0 + 1)] # type: "List[List[int]]" A = [[int(next(tokens)) for _ in range(W)] for _ in range(H)] # type: "List[List[int]]" print((solve(H, W, c, A))) def test(): import doctest doctest.testmod() if __name__ == '__main__': #test() main()
41
40
1,170
1,129
#!/usr/bin/env python3 import sys def solve(H: int, W: int, c: "List[List[int]]", A: "List[List[int]]"): # print(*c, sep='\n') for _ in range(10): for i in range(10): for j in range(10): for k in range(10): c[i][j] = min(c[i][j], c[i][k] + c[k][j]) # print(*c, sep='\n') cost = 0 for a in A: for aa in a: if aa == -1: continue cost += c[aa][1] return cost # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() H = int(next(tokens)) # type: int W = int(next(tokens)) # type: int c = [ [int(next(tokens)) for _ in range(9 - 0 + 1)] for _ in range(9 - 0 + 1) ] # type: "List[List[int]]" A = [ [int(next(tokens)) for _ in range(W)] for _ in range(H) ] # type: "List[List[int]]" print((solve(H, W, c, A))) def test(): import doctest doctest.testmod() if __name__ == "__main__": # test() main()
#!/usr/bin/env python3 import sys def solve(H: int, W: int, c: "List[List[int]]", A: "List[List[int]]"): # print(*c, sep='\n') for k in range(10): for i in range(10): for j in range(10): c[i][j] = min(c[i][j], c[i][k] + c[k][j]) # print(*c, sep='\n') cost = 0 for a in A: for aa in a: if aa == -1: continue cost += c[aa][1] return cost # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() H = int(next(tokens)) # type: int W = int(next(tokens)) # type: int c = [ [int(next(tokens)) for _ in range(9 - 0 + 1)] for _ in range(9 - 0 + 1) ] # type: "List[List[int]]" A = [ [int(next(tokens)) for _ in range(W)] for _ in range(H) ] # type: "List[List[int]]" print((solve(H, W, c, A))) def test(): import doctest doctest.testmod() if __name__ == "__main__": # test() main()
false
2.439024
[ "- for _ in range(10):", "+ for k in range(10):", "- for k in range(10):", "- c[i][j] = min(c[i][j], c[i][k] + c[k][j])", "+ c[i][j] = min(c[i][j], c[i][k] + c[k][j])" ]
false
0.043149
0.036117
1.194679
[ "s802549487", "s919282979" ]
u677440371
p03353
python
s482152181
s965201407
42
36
5,068
5,068
Accepted
Accepted
14.29
s = str(eval(input())) k = int(eval(input())) check = [] a = min(len(s),k) for i in range(len(s)): for j in range(a): if i <= i+j <=len(s)+1: check.append(s[i:i+j+1]) print((sorted(set(check))[k-1]))
s = str(eval(input())) k = int(eval(input())) check = [] for i in range(len(s)): for j in range(k): check.append(s[i:i+j+1]) print((sorted(list(set(check)))[k-1]))
11
9
233
179
s = str(eval(input())) k = int(eval(input())) check = [] a = min(len(s), k) for i in range(len(s)): for j in range(a): if i <= i + j <= len(s) + 1: check.append(s[i : i + j + 1]) print((sorted(set(check))[k - 1]))
s = str(eval(input())) k = int(eval(input())) check = [] for i in range(len(s)): for j in range(k): check.append(s[i : i + j + 1]) print((sorted(list(set(check)))[k - 1]))
false
18.181818
[ "-a = min(len(s), k)", "- for j in range(a):", "- if i <= i + j <= len(s) + 1:", "- check.append(s[i : i + j + 1])", "-print((sorted(set(check))[k - 1]))", "+ for j in range(k):", "+ check.append(s[i : i + j + 1])", "+print((sorted(list(set(check)))[k - 1]))" ]
false
0.039167
0.038461
1.018372
[ "s482152181", "s965201407" ]
u757117214
p02766
python
s091187768
s555704476
41
18
3,060
2,940
Accepted
Accepted
56.1
def func(x,n): if int(x/n): return func(int(x/n),n)+str(x%n) return str(x%n) N,K=list(map(int,input().split())) print((len(func(N,K))))
N,K = list(map(int,input().split())) cnt = 0 while N > 0: N //= K cnt += 1 print(cnt)
7
6
154
92
def func(x, n): if int(x / n): return func(int(x / n), n) + str(x % n) return str(x % n) N, K = list(map(int, input().split())) print((len(func(N, K))))
N, K = list(map(int, input().split())) cnt = 0 while N > 0: N //= K cnt += 1 print(cnt)
false
14.285714
[ "-def func(x, n):", "- if int(x / n):", "- return func(int(x / n), n) + str(x % n)", "- return str(x % n)", "-", "-", "-print((len(func(N, K))))", "+cnt = 0", "+while N > 0:", "+ N //= K", "+ cnt += 1", "+print(cnt)" ]
false
0.094193
0.075189
1.252745
[ "s091187768", "s555704476" ]
u923668099
p02277
python
s633357206
s662837561
1,280
1,130
23,628
23,528
Accepted
Accepted
11.72
from collections import namedtuple Card = namedtuple('Card', ['suit', 'value', 'init']) def QuickSort(A, begin, end): if end - begin <= 1: return piv = A[end - 1].value left, right = begin, begin for i in range(begin, end - 1): if A[i].value <= piv: if i - left > 0: A[left], A[i] = A[i], A[left] left += 1 A[left], A[end - 1] = A[end - 1], A[left] QuickSort(A, begin, left) QuickSort(A, left + 1, end) n = int(eval(input())) A = [] for i in range(n): suit, value = input().split() value = int(value) A.append(Card(suit, value, i)) QuickSort(A, 0, n) for i in range(n - 1): if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init: print('Not stable') break else: print('Stable') for a in A: print((a.suit, a.value))
from sys import stdin from collections import namedtuple Card = namedtuple('Card', ['suit', 'value', 'init']) def QuickSort(A, begin, end): if end - begin <= 1: return piv = A[end - 1].value left, right = begin, begin for i in range(begin, end - 1): if A[i].value <= piv: if i - left > 0: A[left], A[i] = A[i], A[left] left += 1 A[left], A[end - 1] = A[end - 1], A[left] QuickSort(A, begin, left) QuickSort(A, left + 1, end) n = int(stdin.readline()) A = [None] * n for i in range(n): suit, value = stdin.readline().split() A[i] = Card(suit, int(value), i) QuickSort(A, 0, n) for i in range(n - 1): if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init: print('Not stable') break else: print('Stable') for a in A: print((a.suit, a.value))
42
41
890
915
from collections import namedtuple Card = namedtuple("Card", ["suit", "value", "init"]) def QuickSort(A, begin, end): if end - begin <= 1: return piv = A[end - 1].value left, right = begin, begin for i in range(begin, end - 1): if A[i].value <= piv: if i - left > 0: A[left], A[i] = A[i], A[left] left += 1 A[left], A[end - 1] = A[end - 1], A[left] QuickSort(A, begin, left) QuickSort(A, left + 1, end) n = int(eval(input())) A = [] for i in range(n): suit, value = input().split() value = int(value) A.append(Card(suit, value, i)) QuickSort(A, 0, n) for i in range(n - 1): if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init: print("Not stable") break else: print("Stable") for a in A: print((a.suit, a.value))
from sys import stdin from collections import namedtuple Card = namedtuple("Card", ["suit", "value", "init"]) def QuickSort(A, begin, end): if end - begin <= 1: return piv = A[end - 1].value left, right = begin, begin for i in range(begin, end - 1): if A[i].value <= piv: if i - left > 0: A[left], A[i] = A[i], A[left] left += 1 A[left], A[end - 1] = A[end - 1], A[left] QuickSort(A, begin, left) QuickSort(A, left + 1, end) n = int(stdin.readline()) A = [None] * n for i in range(n): suit, value = stdin.readline().split() A[i] = Card(suit, int(value), i) QuickSort(A, 0, n) for i in range(n - 1): if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init: print("Not stable") break else: print("Stable") for a in A: print((a.suit, a.value))
false
2.380952
[ "+from sys import stdin", "-n = int(eval(input()))", "-A = []", "+n = int(stdin.readline())", "+A = [None] * n", "- suit, value = input().split()", "- value = int(value)", "- A.append(Card(suit, value, i))", "+ suit, value = stdin.readline().split()", "+ A[i] = Card(suit, int(value)...
false
0.046103
0.049155
0.937921
[ "s633357206", "s662837561" ]
u298297089
p02873
python
s310389562
s348816102
220
120
6,300
11,860
Accepted
Accepted
45.45
# for c in '03210120123452101': # 3 2 5 2 s = eval(input()) lst = [] tmp = '' cnt = 1 for c in s: if tmp == c: cnt += 1 else : lst.append(cnt) cnt = 1 tmp = c lst.append(cnt) ans = 0 if s[0] == '<': idx = 1 else: idx = 0 if (len(lst) - idx ) % 2 == 1: lst.append(1) for i in range(idx,len(lst),2): if lst[i] > 1: if lst[i] <= lst[i+1]: lst[i] -= 1 ans += lst[i] * (lst[i]+1) // 2 if lst[i+1] > 1: if lst[i] > lst[i+1]: lst[i+1] -= 1 ans += lst[i+1] * (lst[i+1]+1) // 2 if lst[i] == 1 and lst[i+1] == 1: ans += 1 # print(lst[i], lst[i+1]) print(ans) # print(lst, idx)
def run_length(data, init=''): length = [] tmp = init cnt = 0 for c in data: if tmp != c: length.append(cnt) cnt = 0 tmp = c cnt += 1 length.append(cnt) return length def resolve(): s = eval(input()) if s[0] != '<': s = '<' + s if s[-1] != '>': s = s + '>' array = run_length(s) ans = 0 for i in range(1, len(array), 2): a,b = array[i], array[i+1] mn = min(a,b) - 1 mx = max(a,b) ans += (mn+1) * (mn) // 2 + mx * (mx+1) // 2 # print(a,b, (mn+1) * (mn) // 2 + mx * (mx+1) // 2) # print(array) print(ans) if __name__ == "__main__": resolve()
37
34
726
735
# for c in '03210120123452101': # 3 2 5 2 s = eval(input()) lst = [] tmp = "" cnt = 1 for c in s: if tmp == c: cnt += 1 else: lst.append(cnt) cnt = 1 tmp = c lst.append(cnt) ans = 0 if s[0] == "<": idx = 1 else: idx = 0 if (len(lst) - idx) % 2 == 1: lst.append(1) for i in range(idx, len(lst), 2): if lst[i] > 1: if lst[i] <= lst[i + 1]: lst[i] -= 1 ans += lst[i] * (lst[i] + 1) // 2 if lst[i + 1] > 1: if lst[i] > lst[i + 1]: lst[i + 1] -= 1 ans += lst[i + 1] * (lst[i + 1] + 1) // 2 if lst[i] == 1 and lst[i + 1] == 1: ans += 1 # print(lst[i], lst[i+1]) print(ans) # print(lst, idx)
def run_length(data, init=""): length = [] tmp = init cnt = 0 for c in data: if tmp != c: length.append(cnt) cnt = 0 tmp = c cnt += 1 length.append(cnt) return length def resolve(): s = eval(input()) if s[0] != "<": s = "<" + s if s[-1] != ">": s = s + ">" array = run_length(s) ans = 0 for i in range(1, len(array), 2): a, b = array[i], array[i + 1] mn = min(a, b) - 1 mx = max(a, b) ans += (mn + 1) * (mn) // 2 + mx * (mx + 1) // 2 # print(a,b, (mn+1) * (mn) // 2 + mx * (mx+1) // 2) # print(array) print(ans) if __name__ == "__main__": resolve()
false
8.108108
[ "-# for c in '03210120123452101':", "-# 3 2 5 2", "-s = eval(input())", "-lst = []", "-tmp = \"\"", "-cnt = 1", "-for c in s:", "- if tmp == c:", "+def run_length(data, init=\"\"):", "+ length = []", "+ tmp = init", "+ cnt = 0", "+ for c in data:", "+ if tmp != c:", ...
false
0.08529
0.047497
1.795684
[ "s310389562", "s348816102" ]
u418149936
p02837
python
s550223447
s487504407
276
250
9,196
9,128
Accepted
Accepted
9.42
N = int(eval(input())) testimo_ls = [ [] for i in range(N) ] rst = 0 for i in range(N): A = int(eval(input())) for j in range(A): x, y = list(map(int, input().split(' '))) testimo_ls[i].append([x - 1, y]) for i in range(1 << N): honest_ls = [] for j in range(N): if i >> j & 1: honest_ls.append(j) is_ok = True for s in honest_ls: for t in testimo_ls[s]: if t[0] not in honest_ls and t[1] == 1: is_ok = False break if t[0] in honest_ls and t[1] == 0: is_ok = False break if is_ok: rst = max(rst, len(honest_ls)) print(rst)
N = int(eval(input())) testimo_ls = [ [] for i in range(N) ] rst = 0 for i in range(N): A = int(eval(input())) for j in range(A): x, y = list(map(int, input().split(' '))) testimo_ls[i].append([x - 1, y]) for i in range(1 << N): honest_ls = [] for j in range(N): if i >> j & 1: honest_ls.append(j) is_ok = True for s in honest_ls: for t in testimo_ls[s]: if t[1] == 0 and t[0] in honest_ls: is_ok = False break if t[1] == 1 and t[0] not in honest_ls: is_ok = False break if is_ok: rst = max(rst, len(honest_ls)) print(rst)
25
25
696
696
N = int(eval(input())) testimo_ls = [[] for i in range(N)] rst = 0 for i in range(N): A = int(eval(input())) for j in range(A): x, y = list(map(int, input().split(" "))) testimo_ls[i].append([x - 1, y]) for i in range(1 << N): honest_ls = [] for j in range(N): if i >> j & 1: honest_ls.append(j) is_ok = True for s in honest_ls: for t in testimo_ls[s]: if t[0] not in honest_ls and t[1] == 1: is_ok = False break if t[0] in honest_ls and t[1] == 0: is_ok = False break if is_ok: rst = max(rst, len(honest_ls)) print(rst)
N = int(eval(input())) testimo_ls = [[] for i in range(N)] rst = 0 for i in range(N): A = int(eval(input())) for j in range(A): x, y = list(map(int, input().split(" "))) testimo_ls[i].append([x - 1, y]) for i in range(1 << N): honest_ls = [] for j in range(N): if i >> j & 1: honest_ls.append(j) is_ok = True for s in honest_ls: for t in testimo_ls[s]: if t[1] == 0 and t[0] in honest_ls: is_ok = False break if t[1] == 1 and t[0] not in honest_ls: is_ok = False break if is_ok: rst = max(rst, len(honest_ls)) print(rst)
false
0
[ "- if t[0] not in honest_ls and t[1] == 1:", "+ if t[1] == 0 and t[0] in honest_ls:", "- if t[0] in honest_ls and t[1] == 0:", "+ if t[1] == 1 and t[0] not in honest_ls:" ]
false
0.035216
0.042051
0.837476
[ "s550223447", "s487504407" ]
u312025627
p03610
python
s229725445
s020113354
168
18
39,536
3,188
Accepted
Accepted
89.29
s = eval(input()) print((s[0::2]))
def main(): S = eval(input()) print((S[0::2])) if __name__ == '__main__': main()
2
7
27
93
s = eval(input()) print((s[0::2]))
def main(): S = eval(input()) print((S[0::2])) if __name__ == "__main__": main()
false
71.428571
[ "-s = eval(input())", "-print((s[0::2]))", "+def main():", "+ S = eval(input())", "+ print((S[0::2]))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.089333
0.047714
1.872282
[ "s229725445", "s020113354" ]
u102461423
p03767
python
s163855796
s579357980
197
131
31,500
37,400
Accepted
Accepted
33.5
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,*A = list(map(int,read().split())) A.sort() answer = sum(A[N::2]) print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *A = list(map(int, read().split())) A.sort() x = sum(A[N::2]) print(x)
10
10
202
194
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *A = list(map(int, read().split())) A.sort() answer = sum(A[N::2]) print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *A = list(map(int, read().split())) A.sort() x = sum(A[N::2]) print(x)
false
0
[ "-answer = sum(A[N::2])", "-print(answer)", "+x = sum(A[N::2])", "+print(x)" ]
false
0.035614
0.043842
0.812308
[ "s163855796", "s579357980" ]
u263830634
p03524
python
s762659195
s116683674
42
26
3,956
4,340
Accepted
Accepted
38.1
S = list(eval(input())) lst = [0] * 3 for s in S: if s == 'a': lst[0] += 1 elif s == 'b': lst[1] += 1 elif s == 'c': lst[2] += 1 if max(abs(lst[0] - lst[1]), abs(lst[1] - lst[2]), abs(lst[2] - lst[0])) >= 2: print ('NO') else: print ('YES')
from collections import Counter lst = list(eval(input())) c = Counter(lst) A = c['a'] B = c['b'] C = c['c'] if max(max(A, B), C) - min(min(A, B), C) <= 1: print ('YES') else: print ('NO')
15
14
294
206
S = list(eval(input())) lst = [0] * 3 for s in S: if s == "a": lst[0] += 1 elif s == "b": lst[1] += 1 elif s == "c": lst[2] += 1 if max(abs(lst[0] - lst[1]), abs(lst[1] - lst[2]), abs(lst[2] - lst[0])) >= 2: print("NO") else: print("YES")
from collections import Counter lst = list(eval(input())) c = Counter(lst) A = c["a"] B = c["b"] C = c["c"] if max(max(A, B), C) - min(min(A, B), C) <= 1: print("YES") else: print("NO")
false
6.666667
[ "-S = list(eval(input()))", "-lst = [0] * 3", "-for s in S:", "- if s == \"a\":", "- lst[0] += 1", "- elif s == \"b\":", "- lst[1] += 1", "- elif s == \"c\":", "- lst[2] += 1", "-if max(abs(lst[0] - lst[1]), abs(lst[1] - lst[2]), abs(lst[2] - lst[0])) >= 2:", "+from...
false
0.037122
0.038753
0.9579
[ "s762659195", "s116683674" ]
u759412327
p02791
python
s061827350
s342226029
119
88
32,376
32,380
Accepted
Accepted
26.05
N = int(eval(input())) P = list(map(int,input().split())) a = 0 s = 10**6 for p in P: if p<s: a+=1 s = min(s,p) print(a)
N = int(eval(input())) P = list(map(int,input().split())) a = 0 s = 10**6 for p in P: if p<s: a+=1 s=p print(a)
11
11
134
127
N = int(eval(input())) P = list(map(int, input().split())) a = 0 s = 10**6 for p in P: if p < s: a += 1 s = min(s, p) print(a)
N = int(eval(input())) P = list(map(int, input().split())) a = 0 s = 10**6 for p in P: if p < s: a += 1 s = p print(a)
false
0
[ "- s = min(s, p)", "+ s = p" ]
false
0.040819
0.036691
1.112491
[ "s061827350", "s342226029" ]
u057109575
p02762
python
s723920895
s727207227
1,287
698
117,336
143,236
Accepted
Accepted
45.77
from collections import deque, Counter N, M, K = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] CD = [list(map(int, input().split())) for _ in range(K)] def dfs(s, c): """ s: node c: number """ q = deque() q.append(s) visited[s] = True color[s] = c while q: u = q.pop() for v in graph[u]: if visited[v]: continue visited[v] = True color[v] = c q.append(v) graph = [[] for _ in range(N)] for a, b in AB: graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) visited = [False] * N color = [-1] * N c = 0 for i in range(N): if not visited[i]: dfs(i, c) c += 1 ctr = Counter(color) block = [[] for _ in range(N)] for c, d in CD: if color[c - 1] == color[d - 1]: block[c - 1].append(d - 1) block[d - 1].append(c - 1) ans = [0] * N for i in range(N): ans[i] = ctr[color[i]] - 1 - len(graph[i]) - len(block[i]) print((*ans))
class UnionFind: def __init__(self, n): self.par = list(range(n)) self.rank = [0] * n self.size = [1] * n def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] == self.rank[y]: self.rank[x] += 1 elif self.rank[x] < self.rank[y]: x, y = y, x self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): return self.size[self.find(x)] N, M, K = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(M)] Y = [list(map(int, input().split())) for _ in range(K)] friend = [[] for _ in range(N + 1)] for a, b in X: friend[a].append(b) friend[b].append(a) block = [[] for _ in range(N + 1)] for c, d in Y: block[c].append(d) block[d].append(c) t = UnionFind(N + 1) for a, b in X: t.unite(a, b) ans = [] for i in range(1, N + 1): cnt = t.get_size(i) - len(friend[i]) - 1 for v in block[i]: cnt -= int(t.is_same(i, v)) ans.append(cnt) print((*ans))
55
62
1,119
1,397
from collections import deque, Counter N, M, K = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] CD = [list(map(int, input().split())) for _ in range(K)] def dfs(s, c): """ s: node c: number """ q = deque() q.append(s) visited[s] = True color[s] = c while q: u = q.pop() for v in graph[u]: if visited[v]: continue visited[v] = True color[v] = c q.append(v) graph = [[] for _ in range(N)] for a, b in AB: graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) visited = [False] * N color = [-1] * N c = 0 for i in range(N): if not visited[i]: dfs(i, c) c += 1 ctr = Counter(color) block = [[] for _ in range(N)] for c, d in CD: if color[c - 1] == color[d - 1]: block[c - 1].append(d - 1) block[d - 1].append(c - 1) ans = [0] * N for i in range(N): ans[i] = ctr[color[i]] - 1 - len(graph[i]) - len(block[i]) print((*ans))
class UnionFind: def __init__(self, n): self.par = list(range(n)) self.rank = [0] * n self.size = [1] * n def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] == self.rank[y]: self.rank[x] += 1 elif self.rank[x] < self.rank[y]: x, y = y, x self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): return self.size[self.find(x)] N, M, K = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(M)] Y = [list(map(int, input().split())) for _ in range(K)] friend = [[] for _ in range(N + 1)] for a, b in X: friend[a].append(b) friend[b].append(a) block = [[] for _ in range(N + 1)] for c, d in Y: block[c].append(d) block[d].append(c) t = UnionFind(N + 1) for a, b in X: t.unite(a, b) ans = [] for i in range(1, N + 1): cnt = t.get_size(i) - len(friend[i]) - 1 for v in block[i]: cnt -= int(t.is_same(i, v)) ans.append(cnt) print((*ans))
false
11.290323
[ "-from collections import deque, Counter", "+class UnionFind:", "+ def __init__(self, n):", "+ self.par = list(range(n))", "+ self.rank = [0] * n", "+ self.size = [1] * n", "+", "+ def find(self, x):", "+ if self.par[x] == x:", "+ return x", "+ ...
false
0.043768
0.037171
1.177468
[ "s723920895", "s727207227" ]
u607563136
p02596
python
s444115595
s405067634
1,528
981
9,176
9,168
Accepted
Accepted
35.8
import sys k = int(eval(input())) a =7%k if a == 0: print((1)) sys.exit() for i in range(2,10**7): a = (10*a+7) % k if a == 0: print(i) sys.exit() print((-1))
import sys def main(): k = int(eval(input())) a =7%k if a == 0: print((1)) sys.exit() for i in range(2,10**7): a = (10*a+7) % k if a == 0: print(i) sys.exit() print((-1)) main()
16
18
203
268
import sys k = int(eval(input())) a = 7 % k if a == 0: print((1)) sys.exit() for i in range(2, 10**7): a = (10 * a + 7) % k if a == 0: print(i) sys.exit() print((-1))
import sys def main(): k = int(eval(input())) a = 7 % k if a == 0: print((1)) sys.exit() for i in range(2, 10**7): a = (10 * a + 7) % k if a == 0: print(i) sys.exit() print((-1)) main()
false
11.111111
[ "-k = int(eval(input()))", "-a = 7 % k", "-if a == 0:", "- print((1))", "- sys.exit()", "-for i in range(2, 10**7):", "- a = (10 * a + 7) % k", "+", "+def main():", "+ k = int(eval(input()))", "+ a = 7 % k", "- print(i)", "+ print((1))", "-print((-1))", "+ ...
false
0.298124
1.100333
0.27094
[ "s444115595", "s405067634" ]
u761320129
p04034
python
s430837035
s087065321
355
241
18,120
24,060
Accepted
Accepted
32.11
N,M = list(map(int,input().split())) XY = [tuple(map(int,input().split())) for i in range(M)] rs = [0] * N rs[0] = 1 cs = [1] * N for x,y in XY: x,y = x-1,y-1 if rs[x]: if cs[x]==1: rs[x] = 0 rs[y] = 1 cs[x] -= 1 cs[y] += 1 print((sum(rs)))
N,M = list(map(int,input().split())) XY = [tuple(map(int,input().split())) for i in range(M)] may_red = [0] * N may_red[0] = 1 balls = [1] * N for x,y in XY: x,y = x-1,y-1 if may_red[x]: may_red[y] = 1 if balls[x] == 1: may_red[x] = 0 balls[x] -= 1 balls[y] += 1 print((sum(may_red)))
15
16
291
337
N, M = list(map(int, input().split())) XY = [tuple(map(int, input().split())) for i in range(M)] rs = [0] * N rs[0] = 1 cs = [1] * N for x, y in XY: x, y = x - 1, y - 1 if rs[x]: if cs[x] == 1: rs[x] = 0 rs[y] = 1 cs[x] -= 1 cs[y] += 1 print((sum(rs)))
N, M = list(map(int, input().split())) XY = [tuple(map(int, input().split())) for i in range(M)] may_red = [0] * N may_red[0] = 1 balls = [1] * N for x, y in XY: x, y = x - 1, y - 1 if may_red[x]: may_red[y] = 1 if balls[x] == 1: may_red[x] = 0 balls[x] -= 1 balls[y] += 1 print((sum(may_red)))
false
6.25
[ "-rs = [0] * N", "-rs[0] = 1", "-cs = [1] * N", "+may_red = [0] * N", "+may_red[0] = 1", "+balls = [1] * N", "- if rs[x]:", "- if cs[x] == 1:", "- rs[x] = 0", "- rs[y] = 1", "- cs[x] -= 1", "- cs[y] += 1", "-print((sum(rs)))", "+ if may_red[x]:", "+ ...
false
0.040521
0.037193
1.089484
[ "s430837035", "s087065321" ]
u423966555
p02791
python
s410615898
s235106663
129
92
24,744
24,744
Accepted
Accepted
28.68
n = int(eval(input())) P = list(map(int, input().split())) ans = 0 min_p = P[0] for p in P: if p <= min_p: ans += 1 min_p = min(min_p, p) print(ans)
n = int(eval(input())) P = list(map(int, input().split())) ans = 0 min_p = P[0] for p in P: if p <= min_p: ans += 1 min_p = p print(ans)
11
11
175
163
n = int(eval(input())) P = list(map(int, input().split())) ans = 0 min_p = P[0] for p in P: if p <= min_p: ans += 1 min_p = min(min_p, p) print(ans)
n = int(eval(input())) P = list(map(int, input().split())) ans = 0 min_p = P[0] for p in P: if p <= min_p: ans += 1 min_p = p print(ans)
false
0
[ "- min_p = min(min_p, p)", "+ min_p = p" ]
false
0.046092
0.045866
1.004944
[ "s410615898", "s235106663" ]
u408620326
p03633
python
s163260458
s113853887
21
17
3,316
3,060
Accepted
Accepted
19.05
from collections import deque N = int(eval(input())) T = list(set([int(eval(input())) for _ in range(N)])) ret = T[0] def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) for t in T[1:]: ret = ret * t // gcd(ret, t) print(ret)
import sys input = sys.stdin.readline N = int(eval(input())) def gcd(x, y): if y == 0: return x return gcd(y, x % y) def lcm(x, y): return x * y // gcd(x, y) T = int(eval(input())) for i in range(N-1): T_ = int(eval(input())) T = lcm(T, T_) print(T)
15
18
256
280
from collections import deque N = int(eval(input())) T = list(set([int(eval(input())) for _ in range(N)])) ret = T[0] def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) for t in T[1:]: ret = ret * t // gcd(ret, t) print(ret)
import sys input = sys.stdin.readline N = int(eval(input())) def gcd(x, y): if y == 0: return x return gcd(y, x % y) def lcm(x, y): return x * y // gcd(x, y) T = int(eval(input())) for i in range(N - 1): T_ = int(eval(input())) T = lcm(T, T_) print(T)
false
16.666667
[ "-from collections import deque", "+import sys", "+input = sys.stdin.readline", "-T = list(set([int(eval(input())) for _ in range(N)]))", "-ret = T[0]", "-def gcd(a, b):", "- if b == 0:", "- return a", "- else:", "- return gcd(b, a % b)", "+def gcd(x, y):", "+ if y == 0:...
false
0.046477
0.041661
1.11559
[ "s163260458", "s113853887" ]
u588341295
p02788
python
s412309802
s416857411
1,090
849
104,256
98,112
Accepted
Accepted
22.11
# -*- coding: utf-8 -*- import sys from bisect import bisect_right from operator import itemgetter def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 class BIT2: """ 区間加算BIT(区間加算・区間合計取得) """ def __init__(self, N): # 添字0が使えないので、内部的には全て1-indexedとして扱う N += 1 self.N = N self.data0 = [0] * N self.data1 = [0] * N def _add(self, data, k, x): k += 1 while k < self.N: data[k] += x k += k & -k def _get(self, data, k): k += 1 s = 0 while k: s += data[k] k -= k & -k return s def add(self, l, r, x): """ 区間[l,r)に値xを追加 """ self._add(self.data0, l, -x*(l-1)) self._add(self.data0, r, x*(r-1)) self._add(self.data1, l, x) self._add(self.data1, r, -x) def query(self, l, r): """ 区間[l,r)の和を取得 """ return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \ - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1) N, D, K = MAP() XH = [] for i in range(N): x, h = MAP() XH.append((x, h)) XH.sort(key=itemgetter(0)) X, _ = zip(*XH) D = D * 2 bit = BIT2(N) ans = 0 for i, (x, h) in enumerate(XH): h -= bit.query(i, i+1) * K if h <= 0: continue cnt = ceil(h, K) idx = bisect_right(X, x+D) - 1 bit.add(i, idx+1, cnt) ans += cnt print(ans)
# -*- coding: utf-8 -*- import sys from bisect import bisect_right from operator import itemgetter def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 N, D, K = MAP() XH = [] for i in range(N): x, h = MAP() XH.append((x, h)) XH.sort(key=itemgetter(0)) X, _ = list(zip(*XH)) D = D * 2 imos = [0] * (N+1) ans = 0 for i, (x, h) in enumerate(XH): imos[i+1] += imos[i] h -= imos[i] * K if h <= 0: continue cnt = ceil(h, K) idx = bisect_right(X, x+D) imos[i+1] += cnt imos[idx] -= cnt ans += cnt print(ans)
82
46
2,096
1,181
# -*- coding: utf-8 -*- import sys from bisect import bisect_right from operator import itemgetter def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 class BIT2: """区間加算BIT(区間加算・区間合計取得)""" def __init__(self, N): # 添字0が使えないので、内部的には全て1-indexedとして扱う N += 1 self.N = N self.data0 = [0] * N self.data1 = [0] * N def _add(self, data, k, x): k += 1 while k < self.N: data[k] += x k += k & -k def _get(self, data, k): k += 1 s = 0 while k: s += data[k] k -= k & -k return s def add(self, l, r, x): """区間[l,r)に値xを追加""" self._add(self.data0, l, -x * (l - 1)) self._add(self.data0, r, x * (r - 1)) self._add(self.data1, l, x) self._add(self.data1, r, -x) def query(self, l, r): """区間[l,r)の和を取得""" return ( self._get(self.data1, r - 1) * (r - 1) + self._get(self.data0, r - 1) - self._get(self.data1, l - 1) * (l - 1) - self._get(self.data0, l - 1) ) N, D, K = MAP() XH = [] for i in range(N): x, h = MAP() XH.append((x, h)) XH.sort(key=itemgetter(0)) X, _ = zip(*XH) D = D * 2 bit = BIT2(N) ans = 0 for i, (x, h) in enumerate(XH): h -= bit.query(i, i + 1) * K if h <= 0: continue cnt = ceil(h, K) idx = bisect_right(X, x + D) - 1 bit.add(i, idx + 1, cnt) ans += cnt print(ans)
# -*- coding: utf-8 -*- import sys from bisect import bisect_right from operator import itemgetter def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 N, D, K = MAP() XH = [] for i in range(N): x, h = MAP() XH.append((x, h)) XH.sort(key=itemgetter(0)) X, _ = list(zip(*XH)) D = D * 2 imos = [0] * (N + 1) ans = 0 for i, (x, h) in enumerate(XH): imos[i + 1] += imos[i] h -= imos[i] * K if h <= 0: continue cnt = ceil(h, K) idx = bisect_right(X, x + D) imos[i + 1] += cnt imos[idx] -= cnt ans += cnt print(ans)
false
43.902439
[ "- return int(input())", "+ return int(eval(input()))", "- return map(int, input().split())", "+ return list(map(int, input().split()))", "-", "-", "-class BIT2:", "- \"\"\"区間加算BIT(区間加算・区間合計取得)\"\"\"", "-", "- def __init__(self, N):", "- # 添字0が使えないので、内部的には全て1-indexedとして扱...
false
0.045685
0.042615
1.072044
[ "s412309802", "s416857411" ]
u716530146
p03262
python
s591177303
s237119859
144
123
16,236
14,588
Accepted
Accepted
14.58
#!/usr/bin/env python3 from bisect import insort_left from fractions import gcd def lcm(m,n): return (m*n)//gcd(m,n) n,X=list(map(int,input().split())) x=list(map(int,input().split())) x.append(X) x.sort() g=x[1]-x[0] for i in range(n): g=gcd(g,x[i+1]-x[i]) print(g)
#!/usr/bin/env python3 import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') inf = float('inf') ;mod = 10**9+7 mans = inf ;ans = 0 ;count = 0 ;pro = 1 n,x = list(map(int,input().split())) X = list(map(int,input().split())) X.append(x) X.sort() def gcd(a, b): while(b != 0): a, b = b, a % b return a def lcm(m,n): return (m*n)//gcd(m,n) pro = X[1]-X[0] for i in range(n): pro = gcd(abs(X[i+1]-X[i]),pro) print(pro)
13
23
281
523
#!/usr/bin/env python3 from bisect import insort_left from fractions import gcd def lcm(m, n): return (m * n) // gcd(m, n) n, X = list(map(int, input().split())) x = list(map(int, input().split())) x.append(X) x.sort() g = x[1] - x[0] for i in range(n): g = gcd(g, x[i + 1] - x[i]) print(g)
#!/usr/bin/env python3 import sys, math, itertools, collections, bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8") inf = float("inf") mod = 10**9 + 7 mans = inf ans = 0 count = 0 pro = 1 n, x = list(map(int, input().split())) X = list(map(int, input().split())) X.append(x) X.sort() def gcd(a, b): while b != 0: a, b = b, a % b return a def lcm(m, n): return (m * n) // gcd(m, n) pro = X[1] - X[0] for i in range(n): pro = gcd(abs(X[i + 1] - X[i]), pro) print(pro)
false
43.478261
[ "-from bisect import insort_left", "-from fractions import gcd", "+import sys, math, itertools, collections, bisect", "+", "+input = lambda: sys.stdin.buffer.readline().rstrip().decode(\"utf-8\")", "+inf = float(\"inf\")", "+mod = 10**9 + 7", "+mans = inf", "+ans = 0", "+count = 0", "+pro = 1", ...
false
0.050489
0.041393
1.219735
[ "s591177303", "s237119859" ]
u893063840
p02744
python
s628135476
s497286223
163
127
14,784
14,464
Accepted
Accepted
22.09
n = int(input()) lets = [chr(i) for i in range(ord("a"), ord("a") + n)] d = {e: i for i, e in enumerate(lets)} s = ["a"] for i in range(1, n): nxt = [] for e in s: mx = 0 for l in e: mx = max(mx, d[l]) for j in range(mx + 2): nxt.append(e + lets[j]) s = nxt print(*s, sep="\n")
n = int(input()) lets = [chr(i) for i in range(ord("a"), ord("z") + 1)] ans = [] def dfs(s, l, mx): if l == n: ans.append(s) return for i in range(mx + 2): dfs(s + lets[i], l + 1, max(mx, i)) dfs("", 0, -1) print(*ans, sep="\n")
16
17
355
283
n = int(input()) lets = [chr(i) for i in range(ord("a"), ord("a") + n)] d = {e: i for i, e in enumerate(lets)} s = ["a"] for i in range(1, n): nxt = [] for e in s: mx = 0 for l in e: mx = max(mx, d[l]) for j in range(mx + 2): nxt.append(e + lets[j]) s = nxt print(*s, sep="\n")
n = int(input()) lets = [chr(i) for i in range(ord("a"), ord("z") + 1)] ans = [] def dfs(s, l, mx): if l == n: ans.append(s) return for i in range(mx + 2): dfs(s + lets[i], l + 1, max(mx, i)) dfs("", 0, -1) print(*ans, sep="\n")
false
5.882353
[ "-lets = [chr(i) for i in range(ord(\"a\"), ord(\"a\") + n)]", "-d = {e: i for i, e in enumerate(lets)}", "-s = [\"a\"]", "-for i in range(1, n):", "- nxt = []", "- for e in s:", "- mx = 0", "- for l in e:", "- mx = max(mx, d[l])", "- for j in range(mx + 2):",...
false
0.049358
0.04891
1.009171
[ "s628135476", "s497286223" ]
u627234757
p02975
python
s124731616
s020483479
664
52
14,212
14,704
Accepted
Accepted
92.17
N = int(eval(input())) A = list(map(int, input().split())) for i in range(N): A[i] = bin(A[i]) max_len = len(A[N-1]) - 2 for i in range(N): A[i] = A[i][2:].zfill(max_len) check = True for i in range(max_len): count0 = 0 count1 = 0 for j in range(N): if(A[j][i] == '0'): count0 += 1 else: count1 += 1 if(count1 == 0): continue elif(count1 == count0 * 2): continue else: check = False break if(check): print('Yes') else: print('No')
n = int(eval(input())) nums = list(map(int, input().split())) #set型にしてからlistにキャストすることで,複数存在するものを省いている unq = list(set(nums)) #違う数字が4個以上存在したら,正しい答えは存在しない if len(unq) > 3: print("No") if len(unq) == 3: #list,unqをアンパックしてa,b,cにいれている a,b,c = unq if a ^ b ^ c == 0: if nums.count(a) == nums.count(b) == nums.count(c): print("Yes") else: print("No") else: print("No") if len(unq) == 2: a,b = sorted(unq) if a == 0: if nums.count(a) * 2 == nums.count(b): print("Yes") else: print("No") else: print("No") if len(unq) == 1: a = unq[0] if a != 0: print("No") else: print("Yes")
27
36
506
721
N = int(eval(input())) A = list(map(int, input().split())) for i in range(N): A[i] = bin(A[i]) max_len = len(A[N - 1]) - 2 for i in range(N): A[i] = A[i][2:].zfill(max_len) check = True for i in range(max_len): count0 = 0 count1 = 0 for j in range(N): if A[j][i] == "0": count0 += 1 else: count1 += 1 if count1 == 0: continue elif count1 == count0 * 2: continue else: check = False break if check: print("Yes") else: print("No")
n = int(eval(input())) nums = list(map(int, input().split())) # set型にしてからlistにキャストすることで,複数存在するものを省いている unq = list(set(nums)) # 違う数字が4個以上存在したら,正しい答えは存在しない if len(unq) > 3: print("No") if len(unq) == 3: # list,unqをアンパックしてa,b,cにいれている a, b, c = unq if a ^ b ^ c == 0: if nums.count(a) == nums.count(b) == nums.count(c): print("Yes") else: print("No") else: print("No") if len(unq) == 2: a, b = sorted(unq) if a == 0: if nums.count(a) * 2 == nums.count(b): print("Yes") else: print("No") else: print("No") if len(unq) == 1: a = unq[0] if a != 0: print("No") else: print("Yes")
false
25
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-for i in range(N):", "- A[i] = bin(A[i])", "-max_len = len(A[N - 1]) - 2", "-for i in range(N):", "- A[i] = A[i][2:].zfill(max_len)", "-check = True", "-for i in range(max_len):", "- count0 = 0", "- count1 = 0", "...
false
0.103195
0.043645
2.364402
[ "s124731616", "s020483479" ]
u077898957
p02910
python
s100735696
s842584143
20
18
3,060
3,064
Accepted
Accepted
10
s = eval(input()) x = sorted(set(s[::2])) y = sorted(set(s[1::2])) countx = 0 county = 0 for i in x: if i in 'RDU': countx += 1 for i in y: if i in 'LDU': county += 1 print(('Yes' if countx==len(x) and county==len(y) else 'No'))
s=eval(input()) ans='Yes' for i in range(len(s)): if i%2==0: if s[i]=='L': ans='No' break else: if s[i]=='R': ans='No' break print(ans)
12
12
256
212
s = eval(input()) x = sorted(set(s[::2])) y = sorted(set(s[1::2])) countx = 0 county = 0 for i in x: if i in "RDU": countx += 1 for i in y: if i in "LDU": county += 1 print(("Yes" if countx == len(x) and county == len(y) else "No"))
s = eval(input()) ans = "Yes" for i in range(len(s)): if i % 2 == 0: if s[i] == "L": ans = "No" break else: if s[i] == "R": ans = "No" break print(ans)
false
0
[ "-x = sorted(set(s[::2]))", "-y = sorted(set(s[1::2]))", "-countx = 0", "-county = 0", "-for i in x:", "- if i in \"RDU\":", "- countx += 1", "-for i in y:", "- if i in \"LDU\":", "- county += 1", "-print((\"Yes\" if countx == len(x) and county == len(y) else \"No\"))", "+a...
false
0.042084
0.100422
0.41907
[ "s100735696", "s842584143" ]
u013513417
p02779
python
s429826727
s414294605
184
112
26,812
33,612
Accepted
Accepted
39.13
N=int(eval(input())) S=list(map(int,input().split())) S.sort() banpei=0 for i in range(N): if banpei==S[i]: print("NO") exit() else: banpei=S[i] print("YES")
N=int(eval(input())) S=list(map(int,input().split())) dic={} for i in range(N): dic[S[i]]=1 if len(dic)==N: print("YES") else: print("NO")
13
10
201
154
N = int(eval(input())) S = list(map(int, input().split())) S.sort() banpei = 0 for i in range(N): if banpei == S[i]: print("NO") exit() else: banpei = S[i] print("YES")
N = int(eval(input())) S = list(map(int, input().split())) dic = {} for i in range(N): dic[S[i]] = 1 if len(dic) == N: print("YES") else: print("NO")
false
23.076923
[ "-S.sort()", "-banpei = 0", "+dic = {}", "- if banpei == S[i]:", "- print(\"NO\")", "- exit()", "- else:", "- banpei = S[i]", "-print(\"YES\")", "+ dic[S[i]] = 1", "+if len(dic) == N:", "+ print(\"YES\")", "+else:", "+ print(\"NO\")" ]
false
0.034574
0.035895
0.963208
[ "s429826727", "s414294605" ]
u190405389
p03201
python
s083548002
s560989374
595
404
112,980
113,492
Accepted
Accepted
32.1
import bisect n = int(eval(input())) aa = list(map(int,input().split())) aa.sort() a = [aa[0]] b = [1] for i in range(1,n): if a[-1]==aa[i]: b[-1]+=1 else: a.append(aa[i]) b.append(1) ans = 0 for i in range(len(a)): while b[-i-1]!=0: c = 2**(len(bin(a[-i-1]))-2)-a[-i-1] d = bisect.bisect_left(a,c) if a[d]==c: if b[d]>1: ans += 1 b[-i-1] -= 1 b[d] -= 1 elif b[d]==1 and a[d]!=a[-i-1]: ans += 1 b[-i-1] -= 1 b[d] -= 1 else: break else: break print(ans)
from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) a.sort() c = Counter(a) ans = 0 for x in a[::-1]: if c[x]>0: c[x]-=1 y = 2**x.bit_length()-x if c[y]>0: c[y]-=1 ans += 1 print(ans)
38
17
719
287
import bisect n = int(eval(input())) aa = list(map(int, input().split())) aa.sort() a = [aa[0]] b = [1] for i in range(1, n): if a[-1] == aa[i]: b[-1] += 1 else: a.append(aa[i]) b.append(1) ans = 0 for i in range(len(a)): while b[-i - 1] != 0: c = 2 ** (len(bin(a[-i - 1])) - 2) - a[-i - 1] d = bisect.bisect_left(a, c) if a[d] == c: if b[d] > 1: ans += 1 b[-i - 1] -= 1 b[d] -= 1 elif b[d] == 1 and a[d] != a[-i - 1]: ans += 1 b[-i - 1] -= 1 b[d] -= 1 else: break else: break print(ans)
from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) a.sort() c = Counter(a) ans = 0 for x in a[::-1]: if c[x] > 0: c[x] -= 1 y = 2 ** x.bit_length() - x if c[y] > 0: c[y] -= 1 ans += 1 print(ans)
false
55.263158
[ "-import bisect", "+from collections import Counter", "-aa = list(map(int, input().split()))", "-aa.sort()", "-a = [aa[0]]", "-b = [1]", "-for i in range(1, n):", "- if a[-1] == aa[i]:", "- b[-1] += 1", "- else:", "- a.append(aa[i])", "- b.append(1)", "+a = list(ma...
false
0.036689
0.059393
0.617742
[ "s083548002", "s560989374" ]
u020390084
p03087
python
s019283541
s188288249
593
340
30,316
13,948
Accepted
Accepted
42.66
import bisect n, q = list(map(int,input().split())) s = eval(input()) lr = [list(map(int,input().split())) for _ in range(q)] AC_index = [] for index in range(len(s)-1): if s[index:index+2] == "AC": AC_index.append(index) for i in range(len(lr)): left_index = bisect.bisect_left(AC_index,lr[i][0]-1) right_index = bisect.bisect_left(AC_index,lr[i][1]-1) print((right_index-left_index))
#!/usr/bin/env python3 import sys from bisect import bisect_left def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"): A_index = [] ## ACの場所を全部記録しときたい→Aの場所を全部記録 for i in range(N-1): if S[i] == 'A' and S[i+1] == 'C': A_index.append(i) for j in range(Q): if r[j] <= 1: print((0)) continue left_index = bisect_left(A_index,l[j]-1) right_index = bisect_left(A_index,r[j]-1) print((right_index-left_index)) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int Q = int(next(tokens)) # type: int S = next(tokens) # type: str l = [int()] * (Q) # type: "List[int]" r = [int()] * (Q) # type: "List[int]" for i in range(Q): l[i] = int(next(tokens)) r[i] = int(next(tokens)) solve(N, Q, S, l, r) if __name__ == '__main__': main()
15
40
400
1,077
import bisect n, q = list(map(int, input().split())) s = eval(input()) lr = [list(map(int, input().split())) for _ in range(q)] AC_index = [] for index in range(len(s) - 1): if s[index : index + 2] == "AC": AC_index.append(index) for i in range(len(lr)): left_index = bisect.bisect_left(AC_index, lr[i][0] - 1) right_index = bisect.bisect_left(AC_index, lr[i][1] - 1) print((right_index - left_index))
#!/usr/bin/env python3 import sys from bisect import bisect_left def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"): A_index = [] ## ACの場所を全部記録しときたい→Aの場所を全部記録 for i in range(N - 1): if S[i] == "A" and S[i + 1] == "C": A_index.append(i) for j in range(Q): if r[j] <= 1: print((0)) continue left_index = bisect_left(A_index, l[j] - 1) right_index = bisect_left(A_index, r[j] - 1) print((right_index - left_index)) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int Q = int(next(tokens)) # type: int S = next(tokens) # type: str l = [int()] * (Q) # type: "List[int]" r = [int()] * (Q) # type: "List[int]" for i in range(Q): l[i] = int(next(tokens)) r[i] = int(next(tokens)) solve(N, Q, S, l, r) if __name__ == "__main__": main()
false
62.5
[ "-import bisect", "+#!/usr/bin/env python3", "+import sys", "+from bisect import bisect_left", "-n, q = list(map(int, input().split()))", "-s = eval(input())", "-lr = [list(map(int, input().split())) for _ in range(q)]", "-AC_index = []", "-for index in range(len(s) - 1):", "- if s[index : inde...
false
0.087562
0.044699
1.95894
[ "s019283541", "s188288249" ]
u384793271
p02784
python
s693115932
s098354920
47
41
13,960
13,964
Accepted
Accepted
12.77
h, n = list(map(int, input().split())) a = list(map(int, input().split())) for i in a: h = h-i if h <= 0: print('Yes') else: print('No')
h, n = list(map(int, input().split())) if h <= sum(list(map(int, input().split()))): print('Yes') else: print('No')
9
5
152
122
h, n = list(map(int, input().split())) a = list(map(int, input().split())) for i in a: h = h - i if h <= 0: print("Yes") else: print("No")
h, n = list(map(int, input().split())) if h <= sum(list(map(int, input().split()))): print("Yes") else: print("No")
false
44.444444
[ "-a = list(map(int, input().split()))", "-for i in a:", "- h = h - i", "-if h <= 0:", "+if h <= sum(list(map(int, input().split()))):" ]
false
0.035071
0.034672
1.011506
[ "s693115932", "s098354920" ]
u815878613
p03341
python
s433905798
s212476195
132
83
8,268
5,920
Accepted
Accepted
37.12
def main(): N = int(eval(input())) S = list(eval(input())) S = list([0 if x == "W" else 1 for x in S]) E = 0 W = sum(S[1:N]) p = W for i in range(1, N): E += 1 - S[i-1] W -= S[i] ss = E + W if ss < p: p = ss print(p) main()
def solver(): N = int(eval(input())) S = list(eval(input())) rE = S.count('E') # リーダーより右にいる人の数 rW = N - rE lE = 0 lW = 0 c = N for s in S: if s == 'E': rE -= 1 f = 1 else: rW -= 1 f = -1 candidate = rE + lW # print(candidate) if candidate < c: c = candidate if f == 1: lE += 1 else: lW += 1 print(c) solver()
20
35
317
518
def main(): N = int(eval(input())) S = list(eval(input())) S = list([0 if x == "W" else 1 for x in S]) E = 0 W = sum(S[1:N]) p = W for i in range(1, N): E += 1 - S[i - 1] W -= S[i] ss = E + W if ss < p: p = ss print(p) main()
def solver(): N = int(eval(input())) S = list(eval(input())) rE = S.count("E") # リーダーより右にいる人の数 rW = N - rE lE = 0 lW = 0 c = N for s in S: if s == "E": rE -= 1 f = 1 else: rW -= 1 f = -1 candidate = rE + lW # print(candidate) if candidate < c: c = candidate if f == 1: lE += 1 else: lW += 1 print(c) solver()
false
42.857143
[ "-def main():", "+def solver():", "- S = list([0 if x == \"W\" else 1 for x in S])", "- E = 0", "- W = sum(S[1:N])", "- p = W", "- for i in range(1, N):", "- E += 1 - S[i - 1]", "- W -= S[i]", "- ss = E + W", "- if ss < p:", "- p = ss", "...
false
0.052234
0.054396
0.96025
[ "s433905798", "s212476195" ]
u606045429
p03310
python
s449638173
s950269172
760
573
25,116
24,856
Accepted
Accepted
24.61
from itertools import accumulate from bisect import bisect_left N, *A = list(map(int, open(0).read().split())) A = [0] + list(accumulate(A)) ans = float("inf") for i in range(2, N - 1): lm = A[i] // 2 l = bisect_left(A, lm) if abs(A[l - 1] - lm) < abs(A[l] - lm): l -= 1 rm = (A[i] + A[N]) // 2 r = bisect_left(A, rm) if abs(A[r - 1] - rm) < abs(A[r] - rm): r -= 1 P = A[l] Q = A[i] - A[l] R = A[r] - A[i] S = A[N] - A[r] ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S)) print(ans)
from itertools import accumulate from bisect import bisect_left def main(): N, *A = list(map(int, open(0).read().split())) A = [0] + list(accumulate(A)) ans = float("inf") for i in range(2, N - 1): lm = A[i] // 2 l = bisect_left(A, lm) if abs(A[l - 1] - lm) < abs(A[l] - lm): l -= 1 rm = (A[i] + A[N]) // 2 r = bisect_left(A, rm) if abs(A[r - 1] - rm) < abs(A[r] - rm): r -= 1 P = A[l] Q = A[i] - A[l] R = A[r] - A[i] S = A[N] - A[r] ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S)) print(ans) main()
27
30
570
665
from itertools import accumulate from bisect import bisect_left N, *A = list(map(int, open(0).read().split())) A = [0] + list(accumulate(A)) ans = float("inf") for i in range(2, N - 1): lm = A[i] // 2 l = bisect_left(A, lm) if abs(A[l - 1] - lm) < abs(A[l] - lm): l -= 1 rm = (A[i] + A[N]) // 2 r = bisect_left(A, rm) if abs(A[r - 1] - rm) < abs(A[r] - rm): r -= 1 P = A[l] Q = A[i] - A[l] R = A[r] - A[i] S = A[N] - A[r] ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S)) print(ans)
from itertools import accumulate from bisect import bisect_left def main(): N, *A = list(map(int, open(0).read().split())) A = [0] + list(accumulate(A)) ans = float("inf") for i in range(2, N - 1): lm = A[i] // 2 l = bisect_left(A, lm) if abs(A[l - 1] - lm) < abs(A[l] - lm): l -= 1 rm = (A[i] + A[N]) // 2 r = bisect_left(A, rm) if abs(A[r - 1] - rm) < abs(A[r] - rm): r -= 1 P = A[l] Q = A[i] - A[l] R = A[r] - A[i] S = A[N] - A[r] ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S)) print(ans) main()
false
10
[ "-N, *A = list(map(int, open(0).read().split()))", "-A = [0] + list(accumulate(A))", "-ans = float(\"inf\")", "-for i in range(2, N - 1):", "- lm = A[i] // 2", "- l = bisect_left(A, lm)", "- if abs(A[l - 1] - lm) < abs(A[l] - lm):", "- l -= 1", "- rm = (A[i] + A[N]) // 2", "- ...
false
0.049929
0.07895
0.632412
[ "s449638173", "s950269172" ]
u254871849
p03317
python
s532011022
s248173541
40
18
13,940
3,060
Accepted
Accepted
55
import sys n, k, *a = list(map(int, sys.stdin.read().split())) def main(): return ((n - 1) + (k - 1) - 1) // (k - 1) if __name__ == '__main__': ans = main() print(ans)
import sys n, k = list(map(int, sys.stdin.readline().split())) def main(): print(((n + k - 3) // (k - 1))) if __name__ == '__main__': main()
10
9
185
152
import sys n, k, *a = list(map(int, sys.stdin.read().split())) def main(): return ((n - 1) + (k - 1) - 1) // (k - 1) if __name__ == "__main__": ans = main() print(ans)
import sys n, k = list(map(int, sys.stdin.readline().split())) def main(): print(((n + k - 3) // (k - 1))) if __name__ == "__main__": main()
false
10
[ "-n, k, *a = list(map(int, sys.stdin.read().split()))", "+n, k = list(map(int, sys.stdin.readline().split()))", "- return ((n - 1) + (k - 1) - 1) // (k - 1)", "+ print(((n + k - 3) // (k - 1)))", "- ans = main()", "- print(ans)", "+ main()" ]
false
0.11967
0.126643
0.944941
[ "s532011022", "s248173541" ]
u691018832
p02804
python
s314509448
s943207256
436
306
31,248
19,340
Accepted
Accepted
29.82
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from bisect import bisect_left def comb(n, k): if n < 0 or n < k or k < 0: return 0 return fac[n] * ifac[k] * ifac[n - k] % mod n, k, *a = list(map(int, read().split())) a.sort() mod = 10 ** 9 + 7 max_n = 2 * 10 ** 5 + 1 ans = 0 fac = [1] * max_n inv = [1] * max_n ifac = [1] * max_n for i in range(2, max_n): fac[i] = fac[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod ifac[i] = ifac[i - 1] * inv[i] % mod for i, aa in enumerate(a): ans += aa * (comb(i, k - 1) - comb(n - 1 - i, k - 1)) ans %= mod print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) def comb(n, k): if n < 0 or n < k or k < 0: return 0 return fac[n] * ifac[k] * ifac[n - k] % mod n, k, *a = list(map(int, read().split())) a.sort() mod = 10 ** 9 + 7 ans = 0 fac = [1] * n inv = [1] * n ifac = [1] * n for i in range(2, n): fac[i] = fac[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod ifac[i] = ifac[i - 1] * inv[i] % mod for i, aa in enumerate(a): ans += aa * (comb(i, k - 1) - comb(n - 1 - i, k - 1)) ans %= mod print(ans)
31
28
739
664
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) from bisect import bisect_left def comb(n, k): if n < 0 or n < k or k < 0: return 0 return fac[n] * ifac[k] * ifac[n - k] % mod n, k, *a = list(map(int, read().split())) a.sort() mod = 10**9 + 7 max_n = 2 * 10**5 + 1 ans = 0 fac = [1] * max_n inv = [1] * max_n ifac = [1] * max_n for i in range(2, max_n): fac[i] = fac[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod ifac[i] = ifac[i - 1] * inv[i] % mod for i, aa in enumerate(a): ans += aa * (comb(i, k - 1) - comb(n - 1 - i, k - 1)) ans %= mod print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) def comb(n, k): if n < 0 or n < k or k < 0: return 0 return fac[n] * ifac[k] * ifac[n - k] % mod n, k, *a = list(map(int, read().split())) a.sort() mod = 10**9 + 7 ans = 0 fac = [1] * n inv = [1] * n ifac = [1] * n for i in range(2, n): fac[i] = fac[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod ifac[i] = ifac[i - 1] * inv[i] % mod for i, aa in enumerate(a): ans += aa * (comb(i, k - 1) - comb(n - 1 - i, k - 1)) ans %= mod print(ans)
false
9.677419
[ "-from bisect import bisect_left", "-max_n = 2 * 10**5 + 1", "-fac = [1] * max_n", "-inv = [1] * max_n", "-ifac = [1] * max_n", "-for i in range(2, max_n):", "+fac = [1] * n", "+inv = [1] * n", "+ifac = [1] * n", "+for i in range(2, n):" ]
false
0.724891
0.035526
20.404728
[ "s314509448", "s943207256" ]
u156815136
p02744
python
s224913186
s885361261
259
113
6,504
20,560
Accepted
Accepted
56.37
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): n = int(eval(input())) # 一番大きいものは何か、それを保存してdfs def dfs(cnt, s): if cnt == n: print(s) return biggest = 'a' c = 0 while c < len(s): if s[c] == biggest: biggest = chr(ord(biggest)+1) c += 1 else: c += 1 for i in range(0,ord(biggest) - ord('a') + 1): sc = chr(ord('a')+i) s += sc dfs(cnt + 1, s) s = s[:-1] dfs(0,"") if __name__ == '__main__': main()
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(input()) n = I() ans = ['a'] for i in range(n-1): tmp = [] for s in ans: m = max(s) j = ord(m)-ord('a') + 1 for k in range(j+1): tmp.append(s+chr(ord('a') + k)) ans = tmp print(*ans, sep='\n')
48
40
1,129
975
from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int, input().split())) def main(): n = int(eval(input())) # 一番大きいものは何か、それを保存してdfs def dfs(cnt, s): if cnt == n: print(s) return biggest = "a" c = 0 while c < len(s): if s[c] == biggest: biggest = chr(ord(biggest) + 1) c += 1 else: c += 1 for i in range(0, ord(biggest) - ord("a") + 1): sc = chr(ord("a") + i) s += sc dfs(cnt + 1, s) s = s[:-1] dfs(0, "") if __name__ == "__main__": main()
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations, permutations, accumulate, product # (string,3) 3回 # from collections import deque from collections import deque, defaultdict, Counter import decimal import re # import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 # mod = 9982443453 def readInts(): return list(map(int, input().split())) def I(): return int(input()) n = I() ans = ["a"] for i in range(n - 1): tmp = [] for s in ans: m = max(s) j = ord(m) - ord("a") + 1 for k in range(j + 1): tmp.append(s + chr(ord("a") + k)) ans = tmp print(*ans, sep="\n")
false
16.666667
[ "-from statistics import median", "-", "+# from statistics import median", "-from itertools import combinations # (string,3) 3回", "-from collections import deque", "-from collections import defaultdict", "-import bisect", "+from itertools import combinations, permutations, accumulate, product # (str...
false
0.03974
0.047302
0.840139
[ "s224913186", "s885361261" ]
u010110540
p03721
python
s529720331
s531800104
456
317
24,320
24,360
Accepted
Accepted
30.48
import bisect N, K = list(map(int, input().split())) d = [] for i in range(N): a, b = list(map(int, input().split())) d.append([a,b]) d.sort() l = [0] * N l[0] = d[0][1] for i in range(1, N): l[i] = d[i][1]+ l[i-1] pos = bisect.bisect_left(l, K) print((d[pos][0]))
import sys import bisect N, K = list(map(int, sys.stdin.readline().split())) d = [] for i in range(N): a, b = list(map(int, sys.stdin.readline().split())) d.append([a,b]) d.sort() l = [0] * N l[0] = d[0][1] for i in range(1, N): l[i] = d[i][1]+ l[i-1] pos = bisect.bisect_left(l, K) print((d[pos][0]))
20
21
288
326
import bisect N, K = list(map(int, input().split())) d = [] for i in range(N): a, b = list(map(int, input().split())) d.append([a, b]) d.sort() l = [0] * N l[0] = d[0][1] for i in range(1, N): l[i] = d[i][1] + l[i - 1] pos = bisect.bisect_left(l, K) print((d[pos][0]))
import sys import bisect N, K = list(map(int, sys.stdin.readline().split())) d = [] for i in range(N): a, b = list(map(int, sys.stdin.readline().split())) d.append([a, b]) d.sort() l = [0] * N l[0] = d[0][1] for i in range(1, N): l[i] = d[i][1] + l[i - 1] pos = bisect.bisect_left(l, K) print((d[pos][0]))
false
4.761905
[ "+import sys", "-N, K = list(map(int, input().split()))", "+N, K = list(map(int, sys.stdin.readline().split()))", "- a, b = list(map(int, input().split()))", "+ a, b = list(map(int, sys.stdin.readline().split()))" ]
false
0.037337
0.045573
0.819287
[ "s529720331", "s531800104" ]
u394731058
p03807
python
s309706912
s528139354
50
42
14,108
14,104
Accepted
Accepted
16
def main(): ans = 'YES' n = int(eval(input())) l = list(map(int, input().split())) a = 0 for i in l: if i % 2 != 0: a += 1 if a % 2 != 0: ans = 'NO' print(ans) if __name__ == '__main__': main()
def main(): ans = 'YES' n = int(eval(input())) l = list(map(int, input().split())) if sum(l)%2 != 0: ans = 'NO' print(ans) if __name__ == '__main__': main()
14
10
239
178
def main(): ans = "YES" n = int(eval(input())) l = list(map(int, input().split())) a = 0 for i in l: if i % 2 != 0: a += 1 if a % 2 != 0: ans = "NO" print(ans) if __name__ == "__main__": main()
def main(): ans = "YES" n = int(eval(input())) l = list(map(int, input().split())) if sum(l) % 2 != 0: ans = "NO" print(ans) if __name__ == "__main__": main()
false
28.571429
[ "- a = 0", "- for i in l:", "- if i % 2 != 0:", "- a += 1", "- if a % 2 != 0:", "+ if sum(l) % 2 != 0:" ]
false
0.165858
0.043798
3.786905
[ "s309706912", "s528139354" ]