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
u530383736
p02598
python
s642951492
s417325001
1,402
1,061
32,712
31,924
Accepted
Accepted
24.32
# -*- coding: utf-8 -*- import sys from decimal import Decimal, ROUND_HALF_UP def main(): N,K = list(map(int, sys.stdin.readline().split())) A_list = list(map(int, sys.stdin.readline().split())) def check(length :int) -> bool: cnt = 0 for a in A_list: if a >= length: quotient = a / length divide = -(-quotient // 1) # round up cnt += (divide - 1) return (True if cnt <= K else False) L = 0 # the minimum length R = max(A_list) # the maximum length while (R - L) > 1: M = L + (R - L) // 2 if check(M): R = M else: L = M print(R) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys import math def main(): N,K = list(map(int, sys.stdin.readline().split())) A_list = list(map(int, sys.stdin.readline().split())) def check(length :int) -> bool: cnt = 0 for a in A_list: if a >= length: quotient = a / length #divide = -(-quotient // 1) # round up divide = math.ceil(quotient) # round up cnt += (divide - 1) return (True if cnt <= K else False) L = 0 # the minimum length R = max(A_list) # the maximum length while (R - L) > 1: M = L + (R - L) // 2 if check(M): R = M else: L = M print(R) if __name__ == "__main__": main()
39
40
800
828
# -*- coding: utf-8 -*- import sys from decimal import Decimal, ROUND_HALF_UP def main(): N, K = list(map(int, sys.stdin.readline().split())) A_list = list(map(int, sys.stdin.readline().split())) def check(length: int) -> bool: cnt = 0 for a in A_list: if a >= length: quotient = a / length divide = -(-quotient // 1) # round up cnt += divide - 1 return True if cnt <= K else False L = 0 # the minimum length R = max(A_list) # the maximum length while (R - L) > 1: M = L + (R - L) // 2 if check(M): R = M else: L = M print(R) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys import math def main(): N, K = list(map(int, sys.stdin.readline().split())) A_list = list(map(int, sys.stdin.readline().split())) def check(length: int) -> bool: cnt = 0 for a in A_list: if a >= length: quotient = a / length # divide = -(-quotient // 1) # round up divide = math.ceil(quotient) # round up cnt += divide - 1 return True if cnt <= K else False L = 0 # the minimum length R = max(A_list) # the maximum length while (R - L) > 1: M = L + (R - L) // 2 if check(M): R = M else: L = M print(R) if __name__ == "__main__": main()
false
2.5
[ "-from decimal import Decimal, ROUND_HALF_UP", "+import math", "- divide = -(-quotient // 1) # round up", "+ # divide = -(-quotient // 1) # round up", "+ divide = math.ceil(quotient) # round up" ]
false
0.101769
0.049693
2.047976
[ "s642951492", "s417325001" ]
u143278390
p03160
python
s464296434
s333128642
218
188
13,976
14,052
Accepted
Accepted
13.76
n=int(eval(input())) h=[int(i) for i in input().split()] h.append(10000) dp=[float('inf') for i in range(n+1)] dp[0]=0 for i in range(n-1): dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1])) if(i<n-2): dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2])) print((dp[n-1]))
n=int(eval(input())) h=[int(i) for i in input().split()] h.append(10000) dp=[float('inf') for i in range(n+1)] dp[0]=0 for i in range(n-1): dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1])) dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2])) print((dp[n-1]))
10
9
272
252
n = int(eval(input())) h = [int(i) for i in input().split()] h.append(10000) dp = [float("inf") for i in range(n + 1)] dp[0] = 0 for i in range(n - 1): dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1])) if i < n - 2: dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2])) print((dp[n - 1]))
n = int(eval(input())) h = [int(i) for i in input().split()] h.append(10000) dp = [float("inf") for i in range(n + 1)] dp[0] = 0 for i in range(n - 1): dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1])) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2])) print((dp[n - 1]))
false
10
[ "- if i < n - 2:", "- dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))", "+ dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))" ]
false
0.046905
0.040602
1.155263
[ "s464296434", "s333128642" ]
u263830634
p03295
python
s320875865
s386211593
605
478
20,556
29,140
Accepted
Accepted
20.99
N, M = list(map(int, input().split())) lst = [] for i in range(M): a = list(map(int, input().split())) lst += [a[::-1]] lst.sort() count = 0 position = 0 for i in range(M): if position <= lst[i][1]: count += 1 position = lst[i][0] print(count)
N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] AB.sort(key = lambda x: x[0]) MAX = 10 ** 9 count = 1 min_ = MAX for a, b in AB: if a < min_: min_ = min(min_, b) else: count += 1 min_ = b print (count)
18
18
295
298
N, M = list(map(int, input().split())) lst = [] for i in range(M): a = list(map(int, input().split())) lst += [a[::-1]] lst.sort() count = 0 position = 0 for i in range(M): if position <= lst[i][1]: count += 1 position = lst[i][0] print(count)
N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] AB.sort(key=lambda x: x[0]) MAX = 10**9 count = 1 min_ = MAX for a, b in AB: if a < min_: min_ = min(min_, b) else: count += 1 min_ = b print(count)
false
0
[ "-lst = []", "-for i in range(M):", "- a = list(map(int, input().split()))", "- lst += [a[::-1]]", "-lst.sort()", "-count = 0", "-position = 0", "-for i in range(M):", "- if position <= lst[i][1]:", "+AB = [list(map(int, input().split())) for _ in range(M)]", "+AB.sort(key=lambda x: x[0])", "+MAX = 10**9", "+count = 1", "+min_ = MAX", "+for a, b in AB:", "+ if a < min_:", "+ min_ = min(min_, b)", "+ else:", "- position = lst[i][0]", "+ min_ = b" ]
false
0.067238
0.051634
1.302202
[ "s320875865", "s386211593" ]
u375695365
p02971
python
s651396844
s393945714
548
359
14,088
18,796
Accepted
Accepted
34.49
a=int(eval(input())) b=[int(eval(input())) for i in range(a)] m=max(b) if b.count(m)>=2: for i in range(a): print (m) else: c=b.copy() c.sort(reverse=True) m2=c[1] for i in range(a): if b[i]==m: print(m2) else: print (m)
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] maxa = max(a) # print(maxa) if a.count(maxa) == 1: b = sorted(a, reverse=True) maxa2 = b[1] for i in range(n): if a[i] == maxa: print(maxa2) else: print(maxa) else: for i in range(n): print(maxa)
18
17
310
332
a = int(eval(input())) b = [int(eval(input())) for i in range(a)] m = max(b) if b.count(m) >= 2: for i in range(a): print(m) else: c = b.copy() c.sort(reverse=True) m2 = c[1] for i in range(a): if b[i] == m: print(m2) else: print(m)
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] maxa = max(a) # print(maxa) if a.count(maxa) == 1: b = sorted(a, reverse=True) maxa2 = b[1] for i in range(n): if a[i] == maxa: print(maxa2) else: print(maxa) else: for i in range(n): print(maxa)
false
5.555556
[ "-a = int(eval(input()))", "-b = [int(eval(input())) for i in range(a)]", "-m = max(b)", "-if b.count(m) >= 2:", "- for i in range(a):", "- print(m)", "+n = int(eval(input()))", "+a = [int(eval(input())) for _ in range(n)]", "+maxa = max(a)", "+# print(maxa)", "+if a.count(maxa) == 1:", "+ b = sorted(a, reverse=True)", "+ maxa2 = b[1]", "+ for i in range(n):", "+ if a[i] == maxa:", "+ print(maxa2)", "+ else:", "+ print(maxa)", "- c = b.copy()", "- c.sort(reverse=True)", "- m2 = c[1]", "- for i in range(a):", "- if b[i] == m:", "- print(m2)", "- else:", "- print(m)", "+ for i in range(n):", "+ print(maxa)" ]
false
0.081339
0.043762
1.858674
[ "s651396844", "s393945714" ]
u877415670
p02642
python
s982725409
s490481731
597
430
32,248
32,260
Accepted
Accepted
27.97
n = int(eval(input())) a = list(map(int, input().split())) M = max(a) ok = [0]*(M+1) a.sort() for i in range(n): ok[a[i]] += 1 for i in range(n): if ok[a[i]] != 0: for g in range(a[i], M+1, a[i]): if g != a[i]: ok[g] = 0 print((ok.count(1)))
n = int(eval(input())) a = list(map(int, input().split())) a.sort() MAX = a[-1] l = [0]*(MAX+1) for i in range(n): l[a[i]] += 1 ans = 0 for i in range(n): if l[a[i]] == 1: ans += 1 for g in range(a[i], MAX+1, a[i]): l[g] = 10 print(ans)
16
16
295
276
n = int(eval(input())) a = list(map(int, input().split())) M = max(a) ok = [0] * (M + 1) a.sort() for i in range(n): ok[a[i]] += 1 for i in range(n): if ok[a[i]] != 0: for g in range(a[i], M + 1, a[i]): if g != a[i]: ok[g] = 0 print((ok.count(1)))
n = int(eval(input())) a = list(map(int, input().split())) a.sort() MAX = a[-1] l = [0] * (MAX + 1) for i in range(n): l[a[i]] += 1 ans = 0 for i in range(n): if l[a[i]] == 1: ans += 1 for g in range(a[i], MAX + 1, a[i]): l[g] = 10 print(ans)
false
0
[ "-M = max(a)", "-ok = [0] * (M + 1)", "+MAX = a[-1]", "+l = [0] * (MAX + 1)", "- ok[a[i]] += 1", "+ l[a[i]] += 1", "+ans = 0", "- if ok[a[i]] != 0:", "- for g in range(a[i], M + 1, a[i]):", "- if g != a[i]:", "- ok[g] = 0", "-print((ok.count(1)))", "+ if l[a[i]] == 1:", "+ ans += 1", "+ for g in range(a[i], MAX + 1, a[i]):", "+ l[g] = 10", "+print(ans)" ]
false
0.068026
0.03783
1.798215
[ "s982725409", "s490481731" ]
u970308980
p03387
python
s824319038
s750060661
185
17
38,384
2,940
Accepted
Accepted
90.81
A, B, C = list(map(int, input().split())) M = max(A, B, C) if M % 2 == (A + B + C) % 2: X = M else: X = M + 1 ans = (3 * X - (A + B + C)) // 2 print(ans)
ABC = list(map(int, input().split())) sm = sum(ABC) mx = max(ABC) if (mx * 3) % 2 == sm % 2: ans = (mx * 3 - sm) // 2 else: ans = ((mx + 1) * 3 - sm) // 2 print(ans)
11
11
169
187
A, B, C = list(map(int, input().split())) M = max(A, B, C) if M % 2 == (A + B + C) % 2: X = M else: X = M + 1 ans = (3 * X - (A + B + C)) // 2 print(ans)
ABC = list(map(int, input().split())) sm = sum(ABC) mx = max(ABC) if (mx * 3) % 2 == sm % 2: ans = (mx * 3 - sm) // 2 else: ans = ((mx + 1) * 3 - sm) // 2 print(ans)
false
0
[ "-A, B, C = list(map(int, input().split()))", "-M = max(A, B, C)", "-if M % 2 == (A + B + C) % 2:", "- X = M", "+ABC = list(map(int, input().split()))", "+sm = sum(ABC)", "+mx = max(ABC)", "+if (mx * 3) % 2 == sm % 2:", "+ ans = (mx * 3 - sm) // 2", "- X = M + 1", "-ans = (3 * X - (A + B + C)) // 2", "+ ans = ((mx + 1) * 3 - sm) // 2" ]
false
0.077204
0.039884
1.93574
[ "s824319038", "s750060661" ]
u327532412
p03353
python
s994795319
s966031509
1,120
45
5,564
7,600
Accepted
Accepted
95.98
S = eval(input()) N = len(S) K = int(eval(input())) cnt = {i: [] for i in range(N)} for i in range(N): for j in range(N - i): s = S[j:j+i+1] l = len(s) if s not in cnt[l-1]: cnt[l-1].append(s) if i > K: break ttl = [] for k, v in list(cnt.items()): ttl.extend(v) ttl.sort() print((ttl[K-1]))
S = eval(input()) N = len(S) K = int(eval(input())) ttl = [] for i in range(N): for j in range(N - i): ttl.append(S[j:j+i+1]) if i > K: break ttl = sorted(list(set(ttl))) print((ttl[K-1]))
17
11
343
208
S = eval(input()) N = len(S) K = int(eval(input())) cnt = {i: [] for i in range(N)} for i in range(N): for j in range(N - i): s = S[j : j + i + 1] l = len(s) if s not in cnt[l - 1]: cnt[l - 1].append(s) if i > K: break ttl = [] for k, v in list(cnt.items()): ttl.extend(v) ttl.sort() print((ttl[K - 1]))
S = eval(input()) N = len(S) K = int(eval(input())) ttl = [] for i in range(N): for j in range(N - i): ttl.append(S[j : j + i + 1]) if i > K: break ttl = sorted(list(set(ttl))) print((ttl[K - 1]))
false
35.294118
[ "-cnt = {i: [] for i in range(N)}", "+ttl = []", "- s = S[j : j + i + 1]", "- l = len(s)", "- if s not in cnt[l - 1]:", "- cnt[l - 1].append(s)", "+ ttl.append(S[j : j + i + 1])", "-ttl = []", "-for k, v in list(cnt.items()):", "- ttl.extend(v)", "-ttl.sort()", "+ttl = sorted(list(set(ttl)))" ]
false
0.121805
0.034681
3.512144
[ "s994795319", "s966031509" ]
u608088992
p03274
python
s554402981
s320206932
283
77
23,072
14,940
Accepted
Accepted
72.79
import numpy as np N, K =list(map(int, input().split())) X = [int(_) for _ in input().split()] X2 = np.zeros((N,)) X2 += X minus = X2[X2 < 0] * (-1) minus.sort() plus = X2[X2 >= 0] lenM, lenP = len(minus), len(plus) def length(i, j): if i == 0: return plus[j-1] if j == 0: return minus[i-1] else: LtoR = min(minus[i-1], plus[j-1]) return plus[j-1] + minus[i-1] + LtoR minLength = 1000000000 for i in range(0, K+1): a, b = i, K-i if lenM >= a and lenP >= b : minLength = min(minLength, length(a, b)) print((int(minLength)))
import sys def solve(): input = sys.stdin.readline N, K = list(map(int, input().split())) X = [int(x) for x in input().split()] left = [0] right = [0] for x in X: if x < 0: left.append(-x) else: right.append(x) left.sort() lenl = len(left) lenr = len(right) Ans = 100000000000000 for l in range(min(lenl, K + 1)): r = K - l if r < lenr: Ans = min(min(left[l], right[r]) + left[l] + right[r], Ans) #print(left, right) print(Ans) return 0 if __name__ == "__main__": solve()
26
26
603
597
import numpy as np N, K = list(map(int, input().split())) X = [int(_) for _ in input().split()] X2 = np.zeros((N,)) X2 += X minus = X2[X2 < 0] * (-1) minus.sort() plus = X2[X2 >= 0] lenM, lenP = len(minus), len(plus) def length(i, j): if i == 0: return plus[j - 1] if j == 0: return minus[i - 1] else: LtoR = min(minus[i - 1], plus[j - 1]) return plus[j - 1] + minus[i - 1] + LtoR minLength = 1000000000 for i in range(0, K + 1): a, b = i, K - i if lenM >= a and lenP >= b: minLength = min(minLength, length(a, b)) print((int(minLength)))
import sys def solve(): input = sys.stdin.readline N, K = list(map(int, input().split())) X = [int(x) for x in input().split()] left = [0] right = [0] for x in X: if x < 0: left.append(-x) else: right.append(x) left.sort() lenl = len(left) lenr = len(right) Ans = 100000000000000 for l in range(min(lenl, K + 1)): r = K - l if r < lenr: Ans = min(min(left[l], right[r]) + left[l] + right[r], Ans) # print(left, right) print(Ans) return 0 if __name__ == "__main__": solve()
false
0
[ "-import numpy as np", "-", "-N, K = list(map(int, input().split()))", "-X = [int(_) for _ in input().split()]", "-X2 = np.zeros((N,))", "-X2 += X", "-minus = X2[X2 < 0] * (-1)", "-minus.sort()", "-plus = X2[X2 >= 0]", "-lenM, lenP = len(minus), len(plus)", "+import sys", "-def length(i, j):", "- if i == 0:", "- return plus[j - 1]", "- if j == 0:", "- return minus[i - 1]", "- else:", "- LtoR = min(minus[i - 1], plus[j - 1])", "- return plus[j - 1] + minus[i - 1] + LtoR", "+def solve():", "+ input = sys.stdin.readline", "+ N, K = list(map(int, input().split()))", "+ X = [int(x) for x in input().split()]", "+ left = [0]", "+ right = [0]", "+ for x in X:", "+ if x < 0:", "+ left.append(-x)", "+ else:", "+ right.append(x)", "+ left.sort()", "+ lenl = len(left)", "+ lenr = len(right)", "+ Ans = 100000000000000", "+ for l in range(min(lenl, K + 1)):", "+ r = K - l", "+ if r < lenr:", "+ Ans = min(min(left[l], right[r]) + left[l] + right[r], Ans)", "+ # print(left, right)", "+ print(Ans)", "+ return 0", "-minLength = 1000000000", "-for i in range(0, K + 1):", "- a, b = i, K - i", "- if lenM >= a and lenP >= b:", "- minLength = min(minLength, length(a, b))", "-print((int(minLength)))", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.3012
0.03685
8.173741
[ "s554402981", "s320206932" ]
u562935282
p03045
python
s165585332
s410725599
524
371
63,152
49,028
Accepted
Accepted
29.2
import sys input = sys.stdin.readline class UnionFind: def __init__(self, n): self.v = [-1 for _ in range(n)] # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed) def find(self, x): # xを含む木における根の頂点番号を返す if self.v[x] < 0: # (負)は根 return x else: # 根の頂点番号 self.v[x] = self.find(self.v[x]) # uniteでは, 旧根に属する頂点の根が旧根のままなので更新 return self.v[x] def unite(self, x, y): # 違う根に属していたらrankが低くなるように連結 x = self.find(x) y = self.find(y) if x == y: return if -self.v[x] < -self.v[y]: # size比較,  (-1) * (連結頂点数 * (-1)), (正)同士の大小比較 x, y = y, x # 連結頂点数が少ない方をyにすると, findでの更新回数が減る? self.v[x] += self.v[y] # 連結頂点数の和を取る, 連結頂点数 * (-1) self.v[y] = x # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする def root(self, x): return self.v[x] < 0 # (負)は根 def same(self, x, y): return self.find(x) == self.find(y) # 同じ根に属するか def size(self, x): return -self.v[self.find(x)] # 連結頂点数を返す n, m = list(map(int, input().split())) uf = UnionFind(n) for _ in range(m): x, y, z = list(map(int, input().split())) x -= 1 y -= 1 uf.unite(x, y) print((sum(uf.root(j) for j in range(n))))
def main(): from collections import deque import sys input = sys.stdin.readline N, M = list(map(int, input().split())) g = tuple(set() for _ in range(N)) for _ in range(M): x, y, _ = (int(x) - 1 for x in input().split()) g[x].add(y) g[y].add(x) ans = 0 checked = [False] * N for s in range(N): if checked[s]: continue checked[s] = True ans += 1 dq = deque([s]) while dq: v = dq.popleft() for u in g[v]: if checked[u]: continue checked[u] = True dq.append(u) print(ans) if __name__ == '__main__': main()
46
33
1,278
716
import sys input = sys.stdin.readline class UnionFind: def __init__(self, n): self.v = [-1 for _ in range(n)] # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed) def find(self, x): # xを含む木における根の頂点番号を返す if self.v[x] < 0: # (負)は根 return x else: # 根の頂点番号 self.v[x] = self.find(self.v[x]) # uniteでは, 旧根に属する頂点の根が旧根のままなので更新 return self.v[x] def unite(self, x, y): # 違う根に属していたらrankが低くなるように連結 x = self.find(x) y = self.find(y) if x == y: return if -self.v[x] < -self.v[y]: # size比較,  (-1) * (連結頂点数 * (-1)), (正)同士の大小比較 x, y = y, x # 連結頂点数が少ない方をyにすると, findでの更新回数が減る? self.v[x] += self.v[y] # 連結頂点数の和を取る, 連結頂点数 * (-1) self.v[y] = x # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする def root(self, x): return self.v[x] < 0 # (負)は根 def same(self, x, y): return self.find(x) == self.find(y) # 同じ根に属するか def size(self, x): return -self.v[self.find(x)] # 連結頂点数を返す n, m = list(map(int, input().split())) uf = UnionFind(n) for _ in range(m): x, y, z = list(map(int, input().split())) x -= 1 y -= 1 uf.unite(x, y) print((sum(uf.root(j) for j in range(n))))
def main(): from collections import deque import sys input = sys.stdin.readline N, M = list(map(int, input().split())) g = tuple(set() for _ in range(N)) for _ in range(M): x, y, _ = (int(x) - 1 for x in input().split()) g[x].add(y) g[y].add(x) ans = 0 checked = [False] * N for s in range(N): if checked[s]: continue checked[s] = True ans += 1 dq = deque([s]) while dq: v = dq.popleft() for u in g[v]: if checked[u]: continue checked[u] = True dq.append(u) print(ans) if __name__ == "__main__": main()
false
28.26087
[ "-import sys", "+def main():", "+ from collections import deque", "+ import sys", "-input = sys.stdin.readline", "+ input = sys.stdin.readline", "+ N, M = list(map(int, input().split()))", "+ g = tuple(set() for _ in range(N))", "+ for _ in range(M):", "+ x, y, _ = (int(x) - 1 for x in input().split())", "+ g[x].add(y)", "+ g[y].add(x)", "+ ans = 0", "+ checked = [False] * N", "+ for s in range(N):", "+ if checked[s]:", "+ continue", "+ checked[s] = True", "+ ans += 1", "+ dq = deque([s])", "+ while dq:", "+ v = dq.popleft()", "+ for u in g[v]:", "+ if checked[u]:", "+ continue", "+ checked[u] = True", "+ dq.append(u)", "+ print(ans)", "-class UnionFind:", "- def __init__(self, n):", "- self.v = [-1 for _ in range(n)] # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed)", "-", "- def find(self, x): # xを含む木における根の頂点番号を返す", "- if self.v[x] < 0: # (負)は根", "- return x", "- else: # 根の頂点番号", "- self.v[x] = self.find(self.v[x]) # uniteでは, 旧根に属する頂点の根が旧根のままなので更新", "- return self.v[x]", "-", "- def unite(self, x, y): # 違う根に属していたらrankが低くなるように連結", "- x = self.find(x)", "- y = self.find(y)", "- if x == y:", "- return", "- if -self.v[x] < -self.v[y]: # size比較,  (-1) * (連結頂点数 * (-1)), (正)同士の大小比較", "- x, y = y, x # 連結頂点数が少ない方をyにすると, findでの更新回数が減る?", "- self.v[x] += self.v[y] # 連結頂点数の和を取る, 連結頂点数 * (-1)", "- self.v[y] = x # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする", "-", "- def root(self, x):", "- return self.v[x] < 0 # (負)は根", "-", "- def same(self, x, y):", "- return self.find(x) == self.find(y) # 同じ根に属するか", "-", "- def size(self, x):", "- return -self.v[self.find(x)] # 連結頂点数を返す", "-", "-", "-n, m = list(map(int, input().split()))", "-uf = UnionFind(n)", "-for _ in range(m):", "- x, y, z = list(map(int, input().split()))", "- x -= 1", "- y -= 1", "- uf.unite(x, y)", "-print((sum(uf.root(j) for j in range(n))))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.041607
0.072775
0.571726
[ "s165585332", "s410725599" ]
u794161347
p03030
python
s771366284
s269623977
23
18
3,064
3,064
Accepted
Accepted
21.74
#B N = int(eval(input())) S = [""] * N P = [0] * N P2 = [""] * N NUM = [0] * N for i in range(0, N): S[i], P2[i] = list(map(str, input().split())) P[i] = int(P2[i]) NUM[i] = i + 1 for i in range(0, N): for j in range(1, N): if S[j] < S[j-1]: S[j-1], S[j] = S[j], S[j-1] P[j-1], P[j] = P[j], P[j-1] NUM[j-1], NUM[j] = NUM[j], NUM[j-1] if S[j] == S[j-1]: if P[j] > P[j-1]: S[j-1], S[j] = S[j], S[j-1] P[j-1], P[j] = P[j], P[j-1] NUM[j-1], NUM[j] = NUM[j], NUM[j-1] for i in range(0,N): print((NUM[i]))
from operator import itemgetter N = int(eval(input())) S = [""] * N P = [0] * N P2 = [""] * N NUM = [0] * N lst = [""] * N for i in range(0, N): S[i], P2[i] = list(map(str, input().split())) P[i] = int(P2[i]) NUM[i] = i + 1 lst[i] = (S[i], P[i], NUM[i]) sorted1 = sorted(lst, key=itemgetter(1), reverse=True) sorted2 = sorted(sorted1, key=itemgetter(0)) for i in range(0,N): print((sorted2[i][2]))
23
16
639
419
# B N = int(eval(input())) S = [""] * N P = [0] * N P2 = [""] * N NUM = [0] * N for i in range(0, N): S[i], P2[i] = list(map(str, input().split())) P[i] = int(P2[i]) NUM[i] = i + 1 for i in range(0, N): for j in range(1, N): if S[j] < S[j - 1]: S[j - 1], S[j] = S[j], S[j - 1] P[j - 1], P[j] = P[j], P[j - 1] NUM[j - 1], NUM[j] = NUM[j], NUM[j - 1] if S[j] == S[j - 1]: if P[j] > P[j - 1]: S[j - 1], S[j] = S[j], S[j - 1] P[j - 1], P[j] = P[j], P[j - 1] NUM[j - 1], NUM[j] = NUM[j], NUM[j - 1] for i in range(0, N): print((NUM[i]))
from operator import itemgetter N = int(eval(input())) S = [""] * N P = [0] * N P2 = [""] * N NUM = [0] * N lst = [""] * N for i in range(0, N): S[i], P2[i] = list(map(str, input().split())) P[i] = int(P2[i]) NUM[i] = i + 1 lst[i] = (S[i], P[i], NUM[i]) sorted1 = sorted(lst, key=itemgetter(1), reverse=True) sorted2 = sorted(sorted1, key=itemgetter(0)) for i in range(0, N): print((sorted2[i][2]))
false
30.434783
[ "-# B", "+from operator import itemgetter", "+", "+lst = [\"\"] * N", "+ lst[i] = (S[i], P[i], NUM[i])", "+sorted1 = sorted(lst, key=itemgetter(1), reverse=True)", "+sorted2 = sorted(sorted1, key=itemgetter(0))", "- for j in range(1, N):", "- if S[j] < S[j - 1]:", "- S[j - 1], S[j] = S[j], S[j - 1]", "- P[j - 1], P[j] = P[j], P[j - 1]", "- NUM[j - 1], NUM[j] = NUM[j], NUM[j - 1]", "- if S[j] == S[j - 1]:", "- if P[j] > P[j - 1]:", "- S[j - 1], S[j] = S[j], S[j - 1]", "- P[j - 1], P[j] = P[j], P[j - 1]", "- NUM[j - 1], NUM[j] = NUM[j], NUM[j - 1]", "-for i in range(0, N):", "- print((NUM[i]))", "+ print((sorted2[i][2]))" ]
false
0.059439
0.03629
1.637868
[ "s771366284", "s269623977" ]
u367130284
p03568
python
s949006784
s599098892
162
17
38,256
2,940
Accepted
Accepted
89.51
print((3**int(eval(input()))-2**sum(~int(s)%2 for s in input().split())))
print((3**int(eval(input()))-2**sum(int(s)%2==0for s in input().split())))
1
1
65
66
print((3 ** int(eval(input())) - 2 ** sum(~int(s) % 2 for s in input().split())))
print((3 ** int(eval(input())) - 2 ** sum(int(s) % 2 == 0 for s in input().split())))
false
0
[ "-print((3 ** int(eval(input())) - 2 ** sum(~int(s) % 2 for s in input().split())))", "+print((3 ** int(eval(input())) - 2 ** sum(int(s) % 2 == 0 for s in input().split())))" ]
false
0.04204
0.036343
1.156737
[ "s949006784", "s599098892" ]
u855831834
p02691
python
s382984201
s180537099
201
138
40,404
120,588
Accepted
Accepted
31.34
#E N = int(eval(input())) A = list(map(int,input().split())) p = {} ans = 0 for i in range(N): if i+1-A[i] in p: ans += p[i+1-A[i]] if A[i] + (i+1) in p: p[i+1+A[i]] += 1 else: p[i+1+A[i]] = 1 #print(p) print(ans)
n = int(eval(input())) A = [0]+list(map(int,input().split())) d = {} ans = 0 for i in range(1,n+1): if i+A[i] not in d: d[i+A[i]] = 1 else: d[i+A[i]] += 1 if i-A[i] in d: ans += d[i-A[i]] print(ans)
16
15
264
253
# E N = int(eval(input())) A = list(map(int, input().split())) p = {} ans = 0 for i in range(N): if i + 1 - A[i] in p: ans += p[i + 1 - A[i]] if A[i] + (i + 1) in p: p[i + 1 + A[i]] += 1 else: p[i + 1 + A[i]] = 1 # print(p) print(ans)
n = int(eval(input())) A = [0] + list(map(int, input().split())) d = {} ans = 0 for i in range(1, n + 1): if i + A[i] not in d: d[i + A[i]] = 1 else: d[i + A[i]] += 1 if i - A[i] in d: ans += d[i - A[i]] print(ans)
false
6.25
[ "-# E", "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-p = {}", "+n = int(eval(input()))", "+A = [0] + list(map(int, input().split()))", "+d = {}", "-for i in range(N):", "- if i + 1 - A[i] in p:", "- ans += p[i + 1 - A[i]]", "- if A[i] + (i + 1) in p:", "- p[i + 1 + A[i]] += 1", "+for i in range(1, n + 1):", "+ if i + A[i] not in d:", "+ d[i + A[i]] = 1", "- p[i + 1 + A[i]] = 1", "-# print(p)", "+ d[i + A[i]] += 1", "+ if i - A[i] in d:", "+ ans += d[i - A[i]]" ]
false
0.048427
0.04204
1.151939
[ "s382984201", "s180537099" ]
u600402037
p02756
python
s886906113
s746719929
1,392
307
4,548
4,340
Accepted
Accepted
77.95
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) S = sr() Q = ir() dir = 0 #最初の向きを0、逆向きを1 head_tail = ['', ''] for _ in range(Q): x = sr().split() if x[0] == '1': dir = (1 - dir) else: t, f, c = x h_d = dir if f == '2': h_d = (1 - h_d) head_tail[h_d] += c if dir == 0: answer = head_tail[0][::-1] + S + head_tail[1] else: answer = head_tail[1][::-1] + S[::-1] + head_tail[0] print(answer)
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) S = sr() Q = ir() rev = 0 top = '' tail = '' # xor for _ in range(Q): x = sr().split() if x[0] == '1': rev ^= 1 else: _, f, c = x if (int(f)^rev) & 1: top += c else: tail += c answer = top[::-1] + S + tail if rev&1: answer = answer[::-1] print(answer) # 40
27
29
561
495
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) S = sr() Q = ir() dir = 0 # 最初の向きを0、逆向きを1 head_tail = ["", ""] for _ in range(Q): x = sr().split() if x[0] == "1": dir = 1 - dir else: t, f, c = x h_d = dir if f == "2": h_d = 1 - h_d head_tail[h_d] += c if dir == 0: answer = head_tail[0][::-1] + S + head_tail[1] else: answer = head_tail[1][::-1] + S[::-1] + head_tail[0] print(answer)
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) S = sr() Q = ir() rev = 0 top = "" tail = "" # xor for _ in range(Q): x = sr().split() if x[0] == "1": rev ^= 1 else: _, f, c = x if (int(f) ^ rev) & 1: top += c else: tail += c answer = top[::-1] + S + tail if rev & 1: answer = answer[::-1] print(answer) # 40
false
6.896552
[ "+# coding: utf-8", "-dir = 0 # 最初の向きを0、逆向きを1", "-head_tail = [\"\", \"\"]", "+rev = 0", "+top = \"\"", "+tail = \"\"", "+# xor", "- dir = 1 - dir", "+ rev ^= 1", "- t, f, c = x", "- h_d = dir", "- if f == \"2\":", "- h_d = 1 - h_d", "- head_tail[h_d] += c", "-if dir == 0:", "- answer = head_tail[0][::-1] + S + head_tail[1]", "-else:", "- answer = head_tail[1][::-1] + S[::-1] + head_tail[0]", "+ _, f, c = x", "+ if (int(f) ^ rev) & 1:", "+ top += c", "+ else:", "+ tail += c", "+answer = top[::-1] + S + tail", "+if rev & 1:", "+ answer = answer[::-1]", "+# 40" ]
false
0.043953
0.036491
1.204476
[ "s886906113", "s746719929" ]
u811733736
p02276
python
s175092328
s741659742
100
70
18,336
18,152
Accepted
Accepted
30
def partition(A, p, r): x = A[r - 1] i = p - 1 for j in range(p, r-1): if A[j] <= x: i += 1 temp = A[i] A[i] = A[j] A[j] = temp temp = A[i+1] A[i+1] = A[r-1] A[r-1] = temp return i if __name__ == '__main__': # ??????????????\??? # A = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11] num_of_data = int(eval(input())) A = [int(x) for x in input().split(' ')] # ??????????????? p = partition(A, 0, len(A)) # ???????????¨??? left = A[:p+1] partition = A[p+1] right = A[p+2:] print(('{0} [{1}] {2}'.format(' '.join(map(str, left)), partition, ' '.join(map(str, right)))))
def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] <= x: i += 1 temp = A[i] A[i] = A[j] A[j] = temp temp = A[i+1] A[i+1] = A[r] A[r] = temp return i if __name__ == '__main__': # ??????????????\??? # A = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11] num_of_data = int(eval(input())) A = [int(x) for x in input().split(' ')] # ??????????????? p = partition(A, 0, len(A)-1) # ???????????¨??? left = A[:p+1] partition = A[p+1] right = A[p+2:] print(('{0} [{1}] {2}'.format(' '.join(map(str, left)), partition, ' '.join(map(str, right)))))
31
31
716
708
def partition(A, p, r): x = A[r - 1] i = p - 1 for j in range(p, r - 1): if A[j] <= x: i += 1 temp = A[i] A[i] = A[j] A[j] = temp temp = A[i + 1] A[i + 1] = A[r - 1] A[r - 1] = temp return i if __name__ == "__main__": # ??????????????\??? # A = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11] num_of_data = int(eval(input())) A = [int(x) for x in input().split(" ")] # ??????????????? p = partition(A, 0, len(A)) # ???????????¨??? left = A[: p + 1] partition = A[p + 1] right = A[p + 2 :] print( ( "{0} [{1}] {2}".format( " ".join(map(str, left)), partition, " ".join(map(str, right)) ) ) )
def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] <= x: i += 1 temp = A[i] A[i] = A[j] A[j] = temp temp = A[i + 1] A[i + 1] = A[r] A[r] = temp return i if __name__ == "__main__": # ??????????????\??? # A = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11] num_of_data = int(eval(input())) A = [int(x) for x in input().split(" ")] # ??????????????? p = partition(A, 0, len(A) - 1) # ???????????¨??? left = A[: p + 1] partition = A[p + 1] right = A[p + 2 :] print( ( "{0} [{1}] {2}".format( " ".join(map(str, left)), partition, " ".join(map(str, right)) ) ) )
false
0
[ "- x = A[r - 1]", "+ x = A[r]", "- for j in range(p, r - 1):", "+ for j in range(p, r):", "- A[i + 1] = A[r - 1]", "- A[r - 1] = temp", "+ A[i + 1] = A[r]", "+ A[r] = temp", "- p = partition(A, 0, len(A))", "+ p = partition(A, 0, len(A) - 1)" ]
false
0.039375
0.040108
0.98173
[ "s175092328", "s741659742" ]
u638456847
p02679
python
s524650998
s105318732
618
409
72,812
72,596
Accepted
Accepted
33.82
from math import gcd from collections import Counter import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines MOD = 10**9+7 def main(): N,*ab = list(map(int, read().split())) ab_zero = 0 ratio = [] for a, b in zip(*[iter(ab)]*2): if a == 0 and b == 0: ab_zero += 1 else: if b < 0: a, b = -a, -b if b == 0: a = 1 g = gcd(a, b) a //= g b //= g ratio.append((a, b)) ab_zero %= MOD s = Counter(ratio) bad = 1 for k, v in list(s.items()): if v == 0: continue a, b = k if (-b, a) in s: bad *= (pow(2, v, MOD) + pow(2, s[(-b, a)], MOD) -1) % MOD bad %= MOD s[(-b, a)] = 0 elif (b, -a) in s: bad *= (pow(2, v, MOD) + pow(2, s[(b, -a)], MOD) -1) % MOD bad %= MOD s[(b, -a)] = 0 else: bad *= pow(2, v, MOD) bad %= MOD s[k] = 0 ans = (bad + ab_zero -1) % MOD print(ans) if __name__ == "__main__": main()
from math import gcd from collections import Counter import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines MOD = 10**9+7 def main(): N,*ab = list(map(int, read().split())) ab_zero = 0 ratio = [] for a, b in zip(*[iter(ab)]*2): if a == 0 and b == 0: ab_zero += 1 else: if b < 0: a, b = -a, -b if b == 0: a = 1 g = gcd(a, b) a //= g b //= g ratio.append((a, b)) s = Counter(ratio) bad = 1 no_pair = 0 for k, v in list(s.items()): a, b = k if a > 0: if (-b, a) in s: bad *= pow(2, v, MOD) + pow(2, s[(-b, a)], MOD) -1 bad %= MOD else: no_pair += v elif (b, -a) not in s: no_pair += v bad *= pow(2, no_pair, MOD) bad %= MOD ans = (bad + ab_zero -1) % MOD print(ans) if __name__ == "__main__": main()
54
52
1,256
1,094
from math import gcd from collections import Counter import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines MOD = 10**9 + 7 def main(): N, *ab = list(map(int, read().split())) ab_zero = 0 ratio = [] for a, b in zip(*[iter(ab)] * 2): if a == 0 and b == 0: ab_zero += 1 else: if b < 0: a, b = -a, -b if b == 0: a = 1 g = gcd(a, b) a //= g b //= g ratio.append((a, b)) ab_zero %= MOD s = Counter(ratio) bad = 1 for k, v in list(s.items()): if v == 0: continue a, b = k if (-b, a) in s: bad *= (pow(2, v, MOD) + pow(2, s[(-b, a)], MOD) - 1) % MOD bad %= MOD s[(-b, a)] = 0 elif (b, -a) in s: bad *= (pow(2, v, MOD) + pow(2, s[(b, -a)], MOD) - 1) % MOD bad %= MOD s[(b, -a)] = 0 else: bad *= pow(2, v, MOD) bad %= MOD s[k] = 0 ans = (bad + ab_zero - 1) % MOD print(ans) if __name__ == "__main__": main()
from math import gcd from collections import Counter import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines MOD = 10**9 + 7 def main(): N, *ab = list(map(int, read().split())) ab_zero = 0 ratio = [] for a, b in zip(*[iter(ab)] * 2): if a == 0 and b == 0: ab_zero += 1 else: if b < 0: a, b = -a, -b if b == 0: a = 1 g = gcd(a, b) a //= g b //= g ratio.append((a, b)) s = Counter(ratio) bad = 1 no_pair = 0 for k, v in list(s.items()): a, b = k if a > 0: if (-b, a) in s: bad *= pow(2, v, MOD) + pow(2, s[(-b, a)], MOD) - 1 bad %= MOD else: no_pair += v elif (b, -a) not in s: no_pair += v bad *= pow(2, no_pair, MOD) bad %= MOD ans = (bad + ab_zero - 1) % MOD print(ans) if __name__ == "__main__": main()
false
3.703704
[ "- ab_zero %= MOD", "+ no_pair = 0", "- if v == 0:", "- continue", "- if (-b, a) in s:", "- bad *= (pow(2, v, MOD) + pow(2, s[(-b, a)], MOD) - 1) % MOD", "- bad %= MOD", "- s[(-b, a)] = 0", "- elif (b, -a) in s:", "- bad *= (pow(2, v, MOD) + pow(2, s[(b, -a)], MOD) - 1) % MOD", "- bad %= MOD", "- s[(b, -a)] = 0", "- else:", "- bad *= pow(2, v, MOD)", "- bad %= MOD", "- s[k] = 0", "+ if a > 0:", "+ if (-b, a) in s:", "+ bad *= pow(2, v, MOD) + pow(2, s[(-b, a)], MOD) - 1", "+ bad %= MOD", "+ else:", "+ no_pair += v", "+ elif (b, -a) not in s:", "+ no_pair += v", "+ bad *= pow(2, no_pair, MOD)", "+ bad %= MOD" ]
false
0.046135
0.045886
1.005423
[ "s524650998", "s105318732" ]
u888092736
p02923
python
s688929216
s284310923
88
78
14,224
14,224
Accepted
Accepted
11.36
n = int(eval(input())) H = list(map(int, input().split())) ans = 0 curr = 0 for i in range(1, n): if H[i] <= H[i - 1]: curr += 1 else: curr = 0 ans = max(ans, curr) print(ans)
n = int(eval(input())) H = list(map(int, input().split())) ans = 0 curr = 0 for i in range(1, n): if H[i] <= H[i - 1]: curr += 1 else: ans = max(ans, curr) curr = 0 ans = max(ans, curr) print(ans)
12
13
210
236
n = int(eval(input())) H = list(map(int, input().split())) ans = 0 curr = 0 for i in range(1, n): if H[i] <= H[i - 1]: curr += 1 else: curr = 0 ans = max(ans, curr) print(ans)
n = int(eval(input())) H = list(map(int, input().split())) ans = 0 curr = 0 for i in range(1, n): if H[i] <= H[i - 1]: curr += 1 else: ans = max(ans, curr) curr = 0 ans = max(ans, curr) print(ans)
false
7.692308
[ "+ ans = max(ans, curr)", "- ans = max(ans, curr)", "+ans = max(ans, curr)" ]
false
0.051467
0.037002
1.390927
[ "s688929216", "s284310923" ]
u562935282
p02901
python
s008955681
s270688672
294
207
46,296
42,844
Accepted
Accepted
29.59
inf = 10 ** 8 + 10 n, m = list(map(int, input().split())) keys = set() for i in range(m): price, _ = list(map(int, input().split())) key = 0 for ind in (int(x) - 1 for x in input().split()): key += (1 << ind) keys.add((price, key)) dp = [inf] * (1 << n) dp[0] = 0 for price, key in sorted(keys): for mask in range(1 << n): dp[mask | key] = min(dp[mask | key], dp[mask] + price) ans = dp[(1 << n) - 1] print((ans if ans != inf else -1))
def main(): import sys input = sys.stdin.readline inf = 10 ** 8 + 10 n, m = list(map(int, input().split())) size = (1 << n) dp = [inf] * size dp[0] = 0 for _ in range(m): price, _ = list(map(int, input().split())) key = sum(1 << ind for ind in (int(x) - 1 for x in input().split())) for mask in range(size): dp[mask | key] = min(dp[mask | key], dp[mask] + price) ans = dp[size - 1] print((ans if ans != inf else -1)) if __name__ == '__main__': main()
22
26
485
551
inf = 10**8 + 10 n, m = list(map(int, input().split())) keys = set() for i in range(m): price, _ = list(map(int, input().split())) key = 0 for ind in (int(x) - 1 for x in input().split()): key += 1 << ind keys.add((price, key)) dp = [inf] * (1 << n) dp[0] = 0 for price, key in sorted(keys): for mask in range(1 << n): dp[mask | key] = min(dp[mask | key], dp[mask] + price) ans = dp[(1 << n) - 1] print((ans if ans != inf else -1))
def main(): import sys input = sys.stdin.readline inf = 10**8 + 10 n, m = list(map(int, input().split())) size = 1 << n dp = [inf] * size dp[0] = 0 for _ in range(m): price, _ = list(map(int, input().split())) key = sum(1 << ind for ind in (int(x) - 1 for x in input().split())) for mask in range(size): dp[mask | key] = min(dp[mask | key], dp[mask] + price) ans = dp[size - 1] print((ans if ans != inf else -1)) if __name__ == "__main__": main()
false
15.384615
[ "-inf = 10**8 + 10", "-n, m = list(map(int, input().split()))", "-keys = set()", "-for i in range(m):", "- price, _ = list(map(int, input().split()))", "- key = 0", "- for ind in (int(x) - 1 for x in input().split()):", "- key += 1 << ind", "- keys.add((price, key))", "-dp = [inf] * (1 << n)", "-dp[0] = 0", "-for price, key in sorted(keys):", "- for mask in range(1 << n):", "- dp[mask | key] = min(dp[mask | key], dp[mask] + price)", "-ans = dp[(1 << n) - 1]", "-print((ans if ans != inf else -1))", "+def main():", "+ import sys", "+", "+ input = sys.stdin.readline", "+ inf = 10**8 + 10", "+ n, m = list(map(int, input().split()))", "+ size = 1 << n", "+ dp = [inf] * size", "+ dp[0] = 0", "+ for _ in range(m):", "+ price, _ = list(map(int, input().split()))", "+ key = sum(1 << ind for ind in (int(x) - 1 for x in input().split()))", "+ for mask in range(size):", "+ dp[mask | key] = min(dp[mask | key], dp[mask] + price)", "+ ans = dp[size - 1]", "+ print((ans if ans != inf else -1))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.037024
0.036793
1.006277
[ "s008955681", "s270688672" ]
u726615467
p03147
python
s915854971
s942383442
21
18
3,060
3,064
Accepted
Accepted
14.29
N = int(eval(input())) h = list(map(int, input().split())) ans = 0 for h_ref in range(1, 101): prev = 0 for i, hi in enumerate(h): curr = int(hi >= h_ref) if curr > prev: ans += 1 prev = curr print(ans)
N = int(eval(input())) h = list(map(int, input().split())) h += [0] prev = 0 imos = [None] * (N + 1) for i in range(N + 1): imos[i] = h[i] - prev prev = h[i] # print("#", h) # print("#", imos) ans = sum([int(item > 0) * item for item in imos]) print(ans)
12
14
241
275
N = int(eval(input())) h = list(map(int, input().split())) ans = 0 for h_ref in range(1, 101): prev = 0 for i, hi in enumerate(h): curr = int(hi >= h_ref) if curr > prev: ans += 1 prev = curr print(ans)
N = int(eval(input())) h = list(map(int, input().split())) h += [0] prev = 0 imos = [None] * (N + 1) for i in range(N + 1): imos[i] = h[i] - prev prev = h[i] # print("#", h) # print("#", imos) ans = sum([int(item > 0) * item for item in imos]) print(ans)
false
14.285714
[ "-ans = 0", "-for h_ref in range(1, 101):", "- prev = 0", "- for i, hi in enumerate(h):", "- curr = int(hi >= h_ref)", "- if curr > prev:", "- ans += 1", "- prev = curr", "+h += [0]", "+prev = 0", "+imos = [None] * (N + 1)", "+for i in range(N + 1):", "+ imos[i] = h[i] - prev", "+ prev = h[i]", "+# print(\"#\", h)", "+# print(\"#\", imos)", "+ans = sum([int(item > 0) * item for item in imos])" ]
false
0.117356
0.087798
1.33665
[ "s915854971", "s942383442" ]
u325282913
p02735
python
s507096191
s113807170
211
91
41,456
74,104
Accepted
Accepted
56.87
H, W = list(map(int, input().split())) grid = [eval(input()) for _ in range(H)] dp = [[float('inf')] * W for i in range(H)] dp[0][0] = 1 if grid[0][0] == '#' else 0 for i in range(H): for j in range(W): for y, x in ((1,0), (0,1)): ni, nj = i + y, j + x if ni >= H or nj >= W: continue c = 0 if grid[ni][nj] == '#' and grid[i][j] == '.': c = 1 dp[ni][nj] = min(dp[ni][nj], dp[i][j] + c) print((dp[H-1][W-1]))
H, W = list(map(int,input().split())) grid = [eval(input()) for _ in range(H)] dp = [[float('inf')]*(W) for _ in range(H)] dp[0][0] = 0 if grid[0][0] == '.' else 1 for i in range(H): for k in range(W): if i+1 < H: if grid[i][k] == '.' and grid[i+1][k] == '#': dp[i+1][k] = min(dp[i][k]+1,dp[i+1][k]) else: dp[i+1][k] = min(dp[i][k],dp[i+1][k]) if k+1 < W: if grid[i][k] == '.' and grid[i][k+1] == '#': dp[i][k+1] = min(dp[i][k]+1,dp[i][k+1]) else: dp[i][k+1] = min(dp[i][k],dp[i][k+1]) print((dp[-1][-1]))
17
17
515
639
H, W = list(map(int, input().split())) grid = [eval(input()) for _ in range(H)] dp = [[float("inf")] * W for i in range(H)] dp[0][0] = 1 if grid[0][0] == "#" else 0 for i in range(H): for j in range(W): for y, x in ((1, 0), (0, 1)): ni, nj = i + y, j + x if ni >= H or nj >= W: continue c = 0 if grid[ni][nj] == "#" and grid[i][j] == ".": c = 1 dp[ni][nj] = min(dp[ni][nj], dp[i][j] + c) print((dp[H - 1][W - 1]))
H, W = list(map(int, input().split())) grid = [eval(input()) for _ in range(H)] dp = [[float("inf")] * (W) for _ in range(H)] dp[0][0] = 0 if grid[0][0] == "." else 1 for i in range(H): for k in range(W): if i + 1 < H: if grid[i][k] == "." and grid[i + 1][k] == "#": dp[i + 1][k] = min(dp[i][k] + 1, dp[i + 1][k]) else: dp[i + 1][k] = min(dp[i][k], dp[i + 1][k]) if k + 1 < W: if grid[i][k] == "." and grid[i][k + 1] == "#": dp[i][k + 1] = min(dp[i][k] + 1, dp[i][k + 1]) else: dp[i][k + 1] = min(dp[i][k], dp[i][k + 1]) print((dp[-1][-1]))
false
0
[ "-dp = [[float(\"inf\")] * W for i in range(H)]", "-dp[0][0] = 1 if grid[0][0] == \"#\" else 0", "+dp = [[float(\"inf\")] * (W) for _ in range(H)]", "+dp[0][0] = 0 if grid[0][0] == \".\" else 1", "- for j in range(W):", "- for y, x in ((1, 0), (0, 1)):", "- ni, nj = i + y, j + x", "- if ni >= H or nj >= W:", "- continue", "- c = 0", "- if grid[ni][nj] == \"#\" and grid[i][j] == \".\":", "- c = 1", "- dp[ni][nj] = min(dp[ni][nj], dp[i][j] + c)", "-print((dp[H - 1][W - 1]))", "+ for k in range(W):", "+ if i + 1 < H:", "+ if grid[i][k] == \".\" and grid[i + 1][k] == \"#\":", "+ dp[i + 1][k] = min(dp[i][k] + 1, dp[i + 1][k])", "+ else:", "+ dp[i + 1][k] = min(dp[i][k], dp[i + 1][k])", "+ if k + 1 < W:", "+ if grid[i][k] == \".\" and grid[i][k + 1] == \"#\":", "+ dp[i][k + 1] = min(dp[i][k] + 1, dp[i][k + 1])", "+ else:", "+ dp[i][k + 1] = min(dp[i][k], dp[i][k + 1])", "+print((dp[-1][-1]))" ]
false
0.061064
0.034243
1.783276
[ "s507096191", "s113807170" ]
u060793972
p02911
python
s696972893
s231149659
277
221
6,576
5,032
Accepted
Accepted
20.22
n,k,q=list(map(int,input().split())) l=[k for i in range(n)] for i in range(q): l[int(eval(input()))-1]+=1 for i in range(n): print(('Yes' if l[i]-q>0 else 'No'))
n,k,q=list(map(int,input().split())) l=[0 for i in range(n)] for i in range(q): l[int(eval(input()))-1]+=1 print(('\n'.join('Yes' if l[i]-q+k>0 else 'No' for i in range(n))))
6
5
161
168
n, k, q = list(map(int, input().split())) l = [k for i in range(n)] for i in range(q): l[int(eval(input())) - 1] += 1 for i in range(n): print(("Yes" if l[i] - q > 0 else "No"))
n, k, q = list(map(int, input().split())) l = [0 for i in range(n)] for i in range(q): l[int(eval(input())) - 1] += 1 print(("\n".join("Yes" if l[i] - q + k > 0 else "No" for i in range(n))))
false
16.666667
[ "-l = [k for i in range(n)]", "+l = [0 for i in range(n)]", "-for i in range(n):", "- print((\"Yes\" if l[i] - q > 0 else \"No\"))", "+print((\"\\n\".join(\"Yes\" if l[i] - q + k > 0 else \"No\" for i in range(n))))" ]
false
0.044061
0.088902
0.495606
[ "s696972893", "s231149659" ]
u599114793
p03610
python
s490023067
s664884695
38
20
4,268
4,264
Accepted
Accepted
47.37
s = list(eval(input())) ans = [] for i in range(len(s)): if i % 2 == 0: ans.append(s[i]) print(("".join(ans)))
s = list(eval(input())) print(("".join(s[0:len(s):2])))
6
3
120
51
s = list(eval(input())) ans = [] for i in range(len(s)): if i % 2 == 0: ans.append(s[i]) print(("".join(ans)))
s = list(eval(input())) print(("".join(s[0 : len(s) : 2])))
false
50
[ "-ans = []", "-for i in range(len(s)):", "- if i % 2 == 0:", "- ans.append(s[i])", "-print((\"\".join(ans)))", "+print((\"\".join(s[0 : len(s) : 2])))" ]
false
0.042296
0.055757
0.758572
[ "s490023067", "s664884695" ]
u394721319
p02831
python
s439427025
s305583522
36
30
5,048
8,996
Accepted
Accepted
16.67
from fractions import gcd A,B = [int(zz) for zz in input().split()] def lcm(a,b): return a*b//gcd(a,b) print((lcm(A,B)))
from math import gcd A,B = [int(i) for i in input().split()] print((A*B//gcd(A,B)))
8
5
133
88
from fractions import gcd A, B = [int(zz) for zz in input().split()] def lcm(a, b): return a * b // gcd(a, b) print((lcm(A, B)))
from math import gcd A, B = [int(i) for i in input().split()] print((A * B // gcd(A, B)))
false
37.5
[ "-from fractions import gcd", "+from math import gcd", "-A, B = [int(zz) for zz in input().split()]", "-", "-", "-def lcm(a, b):", "- return a * b // gcd(a, b)", "-", "-", "-print((lcm(A, B)))", "+A, B = [int(i) for i in input().split()]", "+print((A * B // gcd(A, B)))" ]
false
0.040676
0.035688
1.139751
[ "s439427025", "s305583522" ]
u033602950
p02678
python
s134757795
s984622490
463
275
104,592
105,296
Accepted
Accepted
40.6
import sys #import time #import copy from collections import deque, Counter, defaultdict #from fractions import gcd #import bisect #import itertools #input = sys.stdin.readline sys.setrecursionlimit(10**6) def ri(): return list(map(int, input().split())) def rs(): return list(input().strip()) n,m = ri() edge=[[] for _ in range(n)] for i in range(m): a, b = ri() a+=-1 b+=-1 edge[a].append(b) edge[b].append(a) visited=[0]*n dis = [0]*n ans=[0]*n def bfs(now, p=-1): q = deque([]) q.append((now, p, -1)) while len(q): now, p, d = q.popleft() dis[now] = d+1 visited[now]=1 ans[now]=p+1 for e in edge[now]: if visited[e]==1: continue if e==now: continue q.append((e, now, dis[now])) visited[e]=1 bfs(0) flag=True for i in range(n): if visited[i]==0: flag=False if flag: print("Yes") for i in range(1,n): print((ans[i])) else: print("No")
import sys #import time #import copy from collections import deque, Counter, defaultdict #from fractions import gcd #import bisect #import itertools input = sys.stdin.readline sys.setrecursionlimit(10**6) def ri(): return list(map(int, input().split())) def rs(): return list(input().strip()) n,m = ri() edge=[[] for _ in range(n)] for i in range(m): a, b = ri() a+=-1 b+=-1 edge[a].append(b) edge[b].append(a) visited=[0]*n dis = [0]*n ans=[0]*n def bfs(now, p=-1): q = deque([]) q.append((now, p, -1)) visited[now]=1 while len(q): now, p, d = q.popleft() dis[now] = d+1 ans[now]=p+1 for e in edge[now]: if visited[e]==1: continue q.append((e, now, dis[now])) visited[e]=1 bfs(0) flag=True for i in range(n): if visited[i]==0: flag=False if flag: print("Yes") for i in range(1,n): print((ans[i])) else: print("No")
58
56
1,132
1,077
import sys # import time # import copy from collections import deque, Counter, defaultdict # from fractions import gcd # import bisect # import itertools # input = sys.stdin.readline sys.setrecursionlimit(10**6) def ri(): return list(map(int, input().split())) def rs(): return list(input().strip()) n, m = ri() edge = [[] for _ in range(n)] for i in range(m): a, b = ri() a += -1 b += -1 edge[a].append(b) edge[b].append(a) visited = [0] * n dis = [0] * n ans = [0] * n def bfs(now, p=-1): q = deque([]) q.append((now, p, -1)) while len(q): now, p, d = q.popleft() dis[now] = d + 1 visited[now] = 1 ans[now] = p + 1 for e in edge[now]: if visited[e] == 1: continue if e == now: continue q.append((e, now, dis[now])) visited[e] = 1 bfs(0) flag = True for i in range(n): if visited[i] == 0: flag = False if flag: print("Yes") for i in range(1, n): print((ans[i])) else: print("No")
import sys # import time # import copy from collections import deque, Counter, defaultdict # from fractions import gcd # import bisect # import itertools input = sys.stdin.readline sys.setrecursionlimit(10**6) def ri(): return list(map(int, input().split())) def rs(): return list(input().strip()) n, m = ri() edge = [[] for _ in range(n)] for i in range(m): a, b = ri() a += -1 b += -1 edge[a].append(b) edge[b].append(a) visited = [0] * n dis = [0] * n ans = [0] * n def bfs(now, p=-1): q = deque([]) q.append((now, p, -1)) visited[now] = 1 while len(q): now, p, d = q.popleft() dis[now] = d + 1 ans[now] = p + 1 for e in edge[now]: if visited[e] == 1: continue q.append((e, now, dis[now])) visited[e] = 1 bfs(0) flag = True for i in range(n): if visited[i] == 0: flag = False if flag: print("Yes") for i in range(1, n): print((ans[i])) else: print("No")
false
3.448276
[ "-# input = sys.stdin.readline", "+input = sys.stdin.readline", "+ visited[now] = 1", "- visited[now] = 1", "- continue", "- if e == now:" ]
false
0.0428
0.059939
0.714062
[ "s134757795", "s984622490" ]
u731235119
p00706
python
s516586507
s494227261
1,780
90
4,372
4,396
Accepted
Accepted
94.94
while 1: n = int(input()) if n == 0: break w,h = list(map(int,input().split(" "))) field = [[0 for i in range(0,w+1)] for j in range(0,h+1)] for i in range(n): x,y = list(map(int,input().split(" "))) field[y][x] = 1 s,t = list(map(int,input().split(" "))) tree_max = 0 for i in range(1,w-s+2): for j in range(1,h-t+2): tmp_sum = 0 for k in range(i,i+s): for l in range(j,j+t): tmp_sum += field[l][k] tree_max = max(tree_max, tmp_sum) print(tree_max)
while 1: n = int(input()) if n == 0: break w,h = list(map(int,input().split(" "))) tree_loc = [list(map(int,input().split(" "))) for i in range(n)] s,t = list(map(int,input().split(" "))) get_field = [[0 for i in range(0,w-s+2)] for j in range(0,h-t+2)] for x,y in tree_loc: get_field[max(y-t+1,1)][max(x-s+1,1)] += 1 if y + 1 <= h - t + 1: get_field[y+1][max(x-s+1,1)] -= 1 if x + 1 <= w - s + 1: get_field[max(y-t+1,1)][x+1] -= 1 if y + 1 <= h - t + 1 and x + 1 <= w - s + 1: get_field[y+1][x+1] += 1 for i in range(1,w-s+1): for j in range(1,h-t+2): get_field[j][i+1] += get_field[j][i] for j in range(1,h-t+1): for i in range(1,w-s+2): get_field[j+1][i] += get_field[j][i] tree_max = max([max(get_field[j]) for j in range(1,h-t+2)]) print(tree_max)
20
26
502
818
while 1: n = int(input()) if n == 0: break w, h = list(map(int, input().split(" "))) field = [[0 for i in range(0, w + 1)] for j in range(0, h + 1)] for i in range(n): x, y = list(map(int, input().split(" "))) field[y][x] = 1 s, t = list(map(int, input().split(" "))) tree_max = 0 for i in range(1, w - s + 2): for j in range(1, h - t + 2): tmp_sum = 0 for k in range(i, i + s): for l in range(j, j + t): tmp_sum += field[l][k] tree_max = max(tree_max, tmp_sum) print(tree_max)
while 1: n = int(input()) if n == 0: break w, h = list(map(int, input().split(" "))) tree_loc = [list(map(int, input().split(" "))) for i in range(n)] s, t = list(map(int, input().split(" "))) get_field = [[0 for i in range(0, w - s + 2)] for j in range(0, h - t + 2)] for x, y in tree_loc: get_field[max(y - t + 1, 1)][max(x - s + 1, 1)] += 1 if y + 1 <= h - t + 1: get_field[y + 1][max(x - s + 1, 1)] -= 1 if x + 1 <= w - s + 1: get_field[max(y - t + 1, 1)][x + 1] -= 1 if y + 1 <= h - t + 1 and x + 1 <= w - s + 1: get_field[y + 1][x + 1] += 1 for i in range(1, w - s + 1): for j in range(1, h - t + 2): get_field[j][i + 1] += get_field[j][i] for j in range(1, h - t + 1): for i in range(1, w - s + 2): get_field[j + 1][i] += get_field[j][i] tree_max = max([max(get_field[j]) for j in range(1, h - t + 2)]) print(tree_max)
false
23.076923
[ "- field = [[0 for i in range(0, w + 1)] for j in range(0, h + 1)]", "- for i in range(n):", "- x, y = list(map(int, input().split(\" \")))", "- field[y][x] = 1", "+ tree_loc = [list(map(int, input().split(\" \"))) for i in range(n)]", "- tree_max = 0", "- for i in range(1, w - s + 2):", "+ get_field = [[0 for i in range(0, w - s + 2)] for j in range(0, h - t + 2)]", "+ for x, y in tree_loc:", "+ get_field[max(y - t + 1, 1)][max(x - s + 1, 1)] += 1", "+ if y + 1 <= h - t + 1:", "+ get_field[y + 1][max(x - s + 1, 1)] -= 1", "+ if x + 1 <= w - s + 1:", "+ get_field[max(y - t + 1, 1)][x + 1] -= 1", "+ if y + 1 <= h - t + 1 and x + 1 <= w - s + 1:", "+ get_field[y + 1][x + 1] += 1", "+ for i in range(1, w - s + 1):", "- tmp_sum = 0", "- for k in range(i, i + s):", "- for l in range(j, j + t):", "- tmp_sum += field[l][k]", "- tree_max = max(tree_max, tmp_sum)", "+ get_field[j][i + 1] += get_field[j][i]", "+ for j in range(1, h - t + 1):", "+ for i in range(1, w - s + 2):", "+ get_field[j + 1][i] += get_field[j][i]", "+ tree_max = max([max(get_field[j]) for j in range(1, h - t + 2)])" ]
false
0.076533
0.036361
2.104829
[ "s516586507", "s494227261" ]
u863442865
p02787
python
s575555810
s170002573
841
427
43,676
42,460
Accepted
Accepted
49.23
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil #from operator import itemgetter inf = 10**17 #mod = 10**9 + 7 h,n = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] dp = [inf] * (3*(10**4)) dp[0] = 0 for i in range(3*(10**4)): for a,b in ab: if i-a >= 0: dp[i] = min(dp[i], dp[i-a]+b) res = inf for i in range(h, 3*(10**4)): res = min(res, dp[i]) print(res) if __name__ == '__main__': main()
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil #from operator import itemgetter inf = 10**17 #mod = 10**9 + 7 h,n = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] dp = [inf] * (h+1) dp[0] = 0 for i in range(h+1): for a,b in ab: if i+a > h: c = h else: c = i + a dp[c] = min(dp[c], dp[i]+b) print((dp[-1])) if __name__ == '__main__': main()
30
31
890
865
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque # from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left, bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil # from operator import itemgetter inf = 10**17 # mod = 10**9 + 7 h, n = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] dp = [inf] * (3 * (10**4)) dp[0] = 0 for i in range(3 * (10**4)): for a, b in ab: if i - a >= 0: dp[i] = min(dp[i], dp[i - a] + b) res = inf for i in range(h, 3 * (10**4)): res = min(res, dp[i]) print(res) if __name__ == "__main__": main()
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque # from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left, bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil # from operator import itemgetter inf = 10**17 # mod = 10**9 + 7 h, n = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] dp = [inf] * (h + 1) dp[0] = 0 for i in range(h + 1): for a, b in ab: if i + a > h: c = h else: c = i + a dp[c] = min(dp[c], dp[i] + b) print((dp[-1])) if __name__ == "__main__": main()
false
3.225806
[ "- dp = [inf] * (3 * (10**4))", "+ dp = [inf] * (h + 1)", "- for i in range(3 * (10**4)):", "+ for i in range(h + 1):", "- if i - a >= 0:", "- dp[i] = min(dp[i], dp[i - a] + b)", "- res = inf", "- for i in range(h, 3 * (10**4)):", "- res = min(res, dp[i])", "- print(res)", "+ if i + a > h:", "+ c = h", "+ else:", "+ c = i + a", "+ dp[c] = min(dp[c], dp[i] + b)", "+ print((dp[-1]))" ]
false
0.406533
0.093317
4.356477
[ "s575555810", "s170002573" ]
u023127434
p03369
python
s010193019
s343303714
27
24
9,088
9,072
Accepted
Accepted
11.11
s = eval(input()) ex = s.count("o") print((700 + 100 * ex))
s = eval(input()) ex = int(s.count("o")) print((700 + 100 * ex))
3
3
53
58
s = eval(input()) ex = s.count("o") print((700 + 100 * ex))
s = eval(input()) ex = int(s.count("o")) print((700 + 100 * ex))
false
0
[ "-ex = s.count(\"o\")", "+ex = int(s.count(\"o\"))" ]
false
0.085712
0.085453
1.003033
[ "s010193019", "s343303714" ]
u947327691
p02689
python
s975016630
s797425922
283
247
20,012
20,036
Accepted
Accepted
12.72
n,m=list(map(int,input().split())) l=list(map(int,input().split())) tmp=[0]*n for i in range(m): a,b=list(map(int,input().split())) if l[a-1] > l[b-1]: tmp[b-1]=-1 if l[a-1] < l[b-1]: tmp[a-1]=-1 if l[a-1] == l[b-1]: tmp[b-1]=-1 tmp[a-1]=-1 print((tmp.count(0)))
n,m=list(map(int,input().split())) l=list(map(int,input().split())) tmp=[0]*n for i in range(m): a,b=list(map(int,input().split())) if l[a-1] > l[b-1]: tmp[b-1]=-1 elif l[a-1] == l[b-1]: tmp[a-1]=-1 tmp[b-1]=-1 else: tmp[a-1]=-1 print((tmp.count(0)))
15
18
312
307
n, m = list(map(int, input().split())) l = list(map(int, input().split())) tmp = [0] * n for i in range(m): a, b = list(map(int, input().split())) if l[a - 1] > l[b - 1]: tmp[b - 1] = -1 if l[a - 1] < l[b - 1]: tmp[a - 1] = -1 if l[a - 1] == l[b - 1]: tmp[b - 1] = -1 tmp[a - 1] = -1 print((tmp.count(0)))
n, m = list(map(int, input().split())) l = list(map(int, input().split())) tmp = [0] * n for i in range(m): a, b = list(map(int, input().split())) if l[a - 1] > l[b - 1]: tmp[b - 1] = -1 elif l[a - 1] == l[b - 1]: tmp[a - 1] = -1 tmp[b - 1] = -1 else: tmp[a - 1] = -1 print((tmp.count(0)))
false
16.666667
[ "- if l[a - 1] < l[b - 1]:", "+ elif l[a - 1] == l[b - 1]:", "- if l[a - 1] == l[b - 1]:", "+ else:" ]
false
0.068725
0.057176
1.201988
[ "s975016630", "s797425922" ]
u186838327
p04030
python
s085530070
s150653651
170
71
38,384
61,816
Accepted
Accepted
58.24
s = str(eval(input())) l = [] for i in range(len(s)): if s[i] == '0': l.append('0') elif s[i] == '1': l.append('1') else: if l: l.pop() print((''.join(l)))
s = str(eval(input())) ans = [] for i in range(len(s)): if s[i] == '0': ans.append('0') elif s[i] == '1': ans.append('1') else: if ans: ans.pop() print((''.join(ans)))
11
11
206
218
s = str(eval(input())) l = [] for i in range(len(s)): if s[i] == "0": l.append("0") elif s[i] == "1": l.append("1") else: if l: l.pop() print(("".join(l)))
s = str(eval(input())) ans = [] for i in range(len(s)): if s[i] == "0": ans.append("0") elif s[i] == "1": ans.append("1") else: if ans: ans.pop() print(("".join(ans)))
false
0
[ "-l = []", "+ans = []", "- l.append(\"0\")", "+ ans.append(\"0\")", "- l.append(\"1\")", "+ ans.append(\"1\")", "- if l:", "- l.pop()", "-print((\"\".join(l)))", "+ if ans:", "+ ans.pop()", "+print((\"\".join(ans)))" ]
false
0.058769
0.057636
1.019668
[ "s085530070", "s150653651" ]
u113971909
p02983
python
s524908004
s750090114
1,094
938
148,260
148,408
Accepted
Accepted
14.26
L,R=list(map(int, input().split())) LR = list(range(L,R+1)) from itertools import permutations, combinations,combinations_with_replacement,product if (R+1-L)<2019: C = combinations(LR, 2) Ret = 2019 for i in list(C): Ret = min(Ret,(i[0]*i[1])%2019) else: Ret = 0 print(Ret)
L,R=list(map(int, input().split())) from itertools import permutations, combinations,combinations_with_replacement,product if (R+1-L)<2019: LR = list(range(L,R+1)) LRA = [] for i in LR: LRA.append(i%2019) LRAA = set(LRA) C = combinations(LRAA, 2) Ret = 2019 for i in list(C): Ret = min(Ret,(i[0]*i[1])%2019) else: Ret = 0 print(Ret)
11
15
283
359
L, R = list(map(int, input().split())) LR = list(range(L, R + 1)) from itertools import permutations, combinations, combinations_with_replacement, product if (R + 1 - L) < 2019: C = combinations(LR, 2) Ret = 2019 for i in list(C): Ret = min(Ret, (i[0] * i[1]) % 2019) else: Ret = 0 print(Ret)
L, R = list(map(int, input().split())) from itertools import permutations, combinations, combinations_with_replacement, product if (R + 1 - L) < 2019: LR = list(range(L, R + 1)) LRA = [] for i in LR: LRA.append(i % 2019) LRAA = set(LRA) C = combinations(LRAA, 2) Ret = 2019 for i in list(C): Ret = min(Ret, (i[0] * i[1]) % 2019) else: Ret = 0 print(Ret)
false
26.666667
[ "-LR = list(range(L, R + 1))", "- C = combinations(LR, 2)", "+ LR = list(range(L, R + 1))", "+ LRA = []", "+ for i in LR:", "+ LRA.append(i % 2019)", "+ LRAA = set(LRA)", "+ C = combinations(LRAA, 2)" ]
false
0.054194
0.136056
0.39832
[ "s524908004", "s750090114" ]
u827202523
p03241
python
s599823865
s517991588
275
173
64,364
38,772
Accepted
Accepted
37.09
import sys # input = sys.stdin.buffer.readline def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getlist(): return list(map(int, input().split())) import math import heapq import fractions from collections import defaultdict, Counter, deque MOD = 10**9 + 7 INF = 10**15 def getyaku(n): res = [] for i in range(1, int(math.sqrt(n)) + 1): if n % i == 0: res.append(i) res.append(n // i) return(sorted(list(set(res)))) def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr def main(): n,m = getlist() arr = getyaku(m) for num in arr: if num >= n: print((m//num)) return print((1)) # print(arr) return if __name__ == '__main__': main() """ 9999 3 2916 """
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) from collections import defaultdict, deque from sys import exit import math import copy from bisect import bisect_left, bisect_right import heapq import sys # sys.setrecursionlimit(1000000) INF = 10 ** 17 MOD = 998244353 def mint(lis): return list(map(int, lis)) def bifind(arr_sorted, x): idx = bisect_left(arr_sorted, x) if idx == len(arr_sorted): return False if arr_sorted[idx] == x: return True else: return False def getyaku(n): ret = [] for i in range(1, int(math.sqrt(n) + 1)): if n % i == 0: ret.append(i) ret.append(n // i) return ret def main(): n, m = getList() ans = 0 for yaku in getyaku(m): if m // yaku >= n: if ans < yaku: ans = yaku print(ans) if __name__ == "__main__": main()
63
49
1,162
1,038
import sys # input = sys.stdin.buffer.readline def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getlist(): return list(map(int, input().split())) import math import heapq import fractions from collections import defaultdict, Counter, deque MOD = 10**9 + 7 INF = 10**15 def getyaku(n): res = [] for i in range(1, int(math.sqrt(n)) + 1): if n % i == 0: res.append(i) res.append(n // i) return sorted(list(set(res))) def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr def main(): n, m = getlist() arr = getyaku(m) for num in arr: if num >= n: print((m // num)) return print((1)) # print(arr) return if __name__ == "__main__": main() """ 9999 3 2916 """
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) from collections import defaultdict, deque from sys import exit import math import copy from bisect import bisect_left, bisect_right import heapq import sys # sys.setrecursionlimit(1000000) INF = 10**17 MOD = 998244353 def mint(lis): return list(map(int, lis)) def bifind(arr_sorted, x): idx = bisect_left(arr_sorted, x) if idx == len(arr_sorted): return False if arr_sorted[idx] == x: return True else: return False def getyaku(n): ret = [] for i in range(1, int(math.sqrt(n) + 1)): if n % i == 0: ret.append(i) ret.append(n // i) return ret def main(): n, m = getList() ans = 0 for yaku in getyaku(m): if m // yaku >= n: if ans < yaku: ans = yaku print(ans) if __name__ == "__main__": main()
false
22.222222
[ "-import sys", "-", "-# input = sys.stdin.buffer.readline", "-def getlist():", "+def getList():", "+from collections import defaultdict, deque", "+from sys import exit", "+import copy", "+from bisect import bisect_left, bisect_right", "-import fractions", "-from collections import defaultdict, Counter, deque", "+import sys", "-MOD = 10**9 + 7", "-INF = 10**15", "+# sys.setrecursionlimit(1000000)", "+INF = 10**17", "+MOD = 998244353", "+", "+", "+def mint(lis):", "+ return list(map(int, lis))", "+", "+", "+def bifind(arr_sorted, x):", "+ idx = bisect_left(arr_sorted, x)", "+ if idx == len(arr_sorted):", "+ return False", "+ if arr_sorted[idx] == x:", "+ return True", "+ else:", "+ return False", "- res = []", "- for i in range(1, int(math.sqrt(n)) + 1):", "+ ret = []", "+ for i in range(1, int(math.sqrt(n) + 1)):", "- res.append(i)", "- res.append(n // i)", "- return sorted(list(set(res)))", "-", "-", "-def factorization(n):", "- arr = []", "- temp = n", "- for i in range(2, int(-(-(n**0.5) // 1)) + 1):", "- if temp % i == 0:", "- cnt = 0", "- while temp % i == 0:", "- cnt += 1", "- temp //= i", "- arr.append([i, cnt])", "- if temp != 1:", "- arr.append([temp, 1])", "- if arr == []:", "- arr.append([n, 1])", "- return arr", "+ ret.append(i)", "+ ret.append(n // i)", "+ return ret", "- n, m = getlist()", "- arr = getyaku(m)", "- for num in arr:", "- if num >= n:", "- print((m // num))", "- return", "- print((1))", "- # print(arr)", "- return", "+ n, m = getList()", "+ ans = 0", "+ for yaku in getyaku(m):", "+ if m // yaku >= n:", "+ if ans < yaku:", "+ ans = yaku", "+ print(ans)", "-\"\"\"", "-9999", "-3", "-2916", "-\"\"\"" ]
false
0.066576
0.042098
1.581438
[ "s599823865", "s517991588" ]
u600402037
p02971
python
s358716453
s151900644
838
418
29,104
50,852
Accepted
Accepted
50.12
import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N = ir() A = np.zeros(N+2, np.int32) A[1:-1] = np.array([ir() for _ in range(N)]) left_max = np.maximum.accumulate(A[:-2]) right_max = np.maximum.accumulate(A[::-1])[::-1][2:] answer = np.maximum(left_max, right_max) print(('\n'.join(map(str, answer))))
import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N = ir() A = np.zeros(N+2, np.int32) A[1:-1] = np.array([ir() for _ in range(N)]) left_max = np.maximum.accumulate(A[:-2]) right_max = np.maximum.accumulate(A[::-1])[::-1][2:] answer = np.maximum(left_max, right_max) print(('\n'.join(answer.astype(str))))
15
15
407
409
import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N = ir() A = np.zeros(N + 2, np.int32) A[1:-1] = np.array([ir() for _ in range(N)]) left_max = np.maximum.accumulate(A[:-2]) right_max = np.maximum.accumulate(A[::-1])[::-1][2:] answer = np.maximum(left_max, right_max) print(("\n".join(map(str, answer))))
import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N = ir() A = np.zeros(N + 2, np.int32) A[1:-1] = np.array([ir() for _ in range(N)]) left_max = np.maximum.accumulate(A[:-2]) right_max = np.maximum.accumulate(A[::-1])[::-1][2:] answer = np.maximum(left_max, right_max) print(("\n".join(answer.astype(str))))
false
0
[ "-print((\"\\n\".join(map(str, answer))))", "+print((\"\\n\".join(answer.astype(str))))" ]
false
0.287504
0.49001
0.586732
[ "s358716453", "s151900644" ]
u733814820
p03103
python
s559286873
s196952748
517
467
27,756
20,072
Accepted
Accepted
9.67
# ABC 121 C N, M = list(map(int, input().split())) arr = [] for i in range(N): arr.append(list(map(int, input().split()))) arr.sort() sum = 0 for i in range(N): if arr[i][1] < M: sum += arr[i][0] * arr[i][1] M -= arr[i][1] else: sum += arr[i][0] * M break print(sum)
def resolve(): n, m = list(map(int, input().split())) l = [] for i in range(n): a, b = list(map(int, input().split())) l.append([a, b]) l.sort() ans = 0 for ab in l: if ab[1] < m: m -= ab[1] ans += ab[0] * ab[1] else: ans += ab[0] * m m = 0 break print(ans) return if __name__ == "__main__": resolve()
22
21
333
375
# ABC 121 C N, M = list(map(int, input().split())) arr = [] for i in range(N): arr.append(list(map(int, input().split()))) arr.sort() sum = 0 for i in range(N): if arr[i][1] < M: sum += arr[i][0] * arr[i][1] M -= arr[i][1] else: sum += arr[i][0] * M break print(sum)
def resolve(): n, m = list(map(int, input().split())) l = [] for i in range(n): a, b = list(map(int, input().split())) l.append([a, b]) l.sort() ans = 0 for ab in l: if ab[1] < m: m -= ab[1] ans += ab[0] * ab[1] else: ans += ab[0] * m m = 0 break print(ans) return if __name__ == "__main__": resolve()
false
4.545455
[ "-# ABC 121 C", "-N, M = list(map(int, input().split()))", "-arr = []", "-for i in range(N):", "- arr.append(list(map(int, input().split())))", "-arr.sort()", "-sum = 0", "-for i in range(N):", "- if arr[i][1] < M:", "- sum += arr[i][0] * arr[i][1]", "- M -= arr[i][1]", "- else:", "- sum += arr[i][0] * M", "- break", "-print(sum)", "+def resolve():", "+ n, m = list(map(int, input().split()))", "+ l = []", "+ for i in range(n):", "+ a, b = list(map(int, input().split()))", "+ l.append([a, b])", "+ l.sort()", "+ ans = 0", "+ for ab in l:", "+ if ab[1] < m:", "+ m -= ab[1]", "+ ans += ab[0] * ab[1]", "+ else:", "+ ans += ab[0] * m", "+ m = 0", "+ break", "+ print(ans)", "+ return", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.03617
0.040555
0.891871
[ "s559286873", "s196952748" ]
u017415492
p03681
python
s721181572
s085979982
204
68
83,316
3,064
Accepted
Accepted
66.67
n,m=list(map(int,input().split())) mod=10**9+7 import sys sys.setrecursionlimit(100002) def kaijou(x): if x==1: return 1 else: return ((x%mod)*kaijou(x-1))%mod if abs(m-n)==1: n2=kaijou(n) m2=kaijou(m) print(((n2*m2)%mod)) elif abs(m-n)==0: n2=kaijou(n) m2=kaijou(m) print((2*(n2*m2)%mod)) else: print((0))
n,m=list(map(int,input().split())) mod=10**9+7 nkai=1 mkai=1 for i in range(1,n+1): nkai*=(i%mod) nkai=(nkai%mod) for i in range(1,m+1): mkai*=(i%mod) mkai=(mkai%mod) if abs(n-m)>=2: print((0)) elif abs(n-m)==1: print(((mkai*nkai)%mod)) elif abs(n-m)==0: print(((mkai*nkai*2)%mod))
20
16
340
298
n, m = list(map(int, input().split())) mod = 10**9 + 7 import sys sys.setrecursionlimit(100002) def kaijou(x): if x == 1: return 1 else: return ((x % mod) * kaijou(x - 1)) % mod if abs(m - n) == 1: n2 = kaijou(n) m2 = kaijou(m) print(((n2 * m2) % mod)) elif abs(m - n) == 0: n2 = kaijou(n) m2 = kaijou(m) print((2 * (n2 * m2) % mod)) else: print((0))
n, m = list(map(int, input().split())) mod = 10**9 + 7 nkai = 1 mkai = 1 for i in range(1, n + 1): nkai *= i % mod nkai = nkai % mod for i in range(1, m + 1): mkai *= i % mod mkai = mkai % mod if abs(n - m) >= 2: print((0)) elif abs(n - m) == 1: print(((mkai * nkai) % mod)) elif abs(n - m) == 0: print(((mkai * nkai * 2) % mod))
false
20
[ "-import sys", "-", "-sys.setrecursionlimit(100002)", "-", "-", "-def kaijou(x):", "- if x == 1:", "- return 1", "- else:", "- return ((x % mod) * kaijou(x - 1)) % mod", "-", "-", "-if abs(m - n) == 1:", "- n2 = kaijou(n)", "- m2 = kaijou(m)", "- print(((n2 * m2) % mod))", "-elif abs(m - n) == 0:", "- n2 = kaijou(n)", "- m2 = kaijou(m)", "- print((2 * (n2 * m2) % mod))", "-else:", "+nkai = 1", "+mkai = 1", "+for i in range(1, n + 1):", "+ nkai *= i % mod", "+ nkai = nkai % mod", "+for i in range(1, m + 1):", "+ mkai *= i % mod", "+ mkai = mkai % mod", "+if abs(n - m) >= 2:", "+elif abs(n - m) == 1:", "+ print(((mkai * nkai) % mod))", "+elif abs(n - m) == 0:", "+ print(((mkai * nkai * 2) % mod))" ]
false
0.041468
0.037907
1.093955
[ "s721181572", "s085979982" ]
u119148115
p02714
python
s954702232
s228502340
1,112
232
9,220
74,136
Accepted
Accepted
79.14
N = int(eval(input())) S = list(eval(input())) r = 0 g = 0 b = 0 for i in range(N): if S[i] == 'R': r += 1 elif S[i] == 'G': g += 1 else: b += 1 ans = r*g*b for i in range(1,N-1): for j in range(1,min(i,N-i-1)+1): if S[i] != S[i-j] and S[i] != S[i+j] and S[i-j] != S[i+j]: ans -= 1 print(ans)
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N = I() S = [''] + LS2() R = [0]*(N+1) G = [0]*(N+1) B = [0]*(N+1) for i in range(1,N+1): s = S[i] R[i] = R[i-1] G[i] = G[i-1] B[i] = B[i-1] if s == 'R': R[i] += 1 elif s == 'G': G[i] += 1 else: B[i] += 1 ans = 0 for i in range(2,N): if S[i] == 'R': ans += G[i-1]*(B[-1]-B[i]) ans += B[i-1]*(G[-1]-G[i]) for j in range(1,N+1): if 1 <= i-j <= N and 1 <= i+j <= N: if (S[i-j] == 'G' and S[i+j] == 'B') or (S[i-j] == 'B' and S[i+j] == 'G'): ans -= 1 elif S[i] == 'G': ans += R[i-1]*(B[-1]-B[i]) ans += B[i-1]*(R[-1]-R[i]) for j in range(1,N+1): if 1 <= i-j <= N and 1 <= i+j <= N: if (S[i-j] == 'R' and S[i+j] == 'B') or (S[i-j] == 'B' and S[i+j] == 'R'): ans -= 1 else: ans += G[i-1]*(R[-1]-R[i]) ans += R[i-1]*(G[-1]-G[i]) for j in range(1,N+1): if 1 <= i-j <= N and 1 <= i+j <= N: if (S[i-j] == 'R' and S[i+j] == 'G') or (S[i-j] == 'G' and S[i+j] == 'R'): ans -= 1 print(ans)
22
56
341
1,695
N = int(eval(input())) S = list(eval(input())) r = 0 g = 0 b = 0 for i in range(N): if S[i] == "R": r += 1 elif S[i] == "G": g += 1 else: b += 1 ans = r * g * b for i in range(1, N - 1): for j in range(1, min(i, N - i - 1) + 1): if S[i] != S[i - j] and S[i] != S[i + j] and S[i - j] != S[i + j]: ans -= 1 print(ans)
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり def LI2(): return list(map(int, sys.stdin.readline().rstrip())) # 空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) # 空白あり def LS2(): return list(sys.stdin.readline().rstrip()) # 空白なし N = I() S = [""] + LS2() R = [0] * (N + 1) G = [0] * (N + 1) B = [0] * (N + 1) for i in range(1, N + 1): s = S[i] R[i] = R[i - 1] G[i] = G[i - 1] B[i] = B[i - 1] if s == "R": R[i] += 1 elif s == "G": G[i] += 1 else: B[i] += 1 ans = 0 for i in range(2, N): if S[i] == "R": ans += G[i - 1] * (B[-1] - B[i]) ans += B[i - 1] * (G[-1] - G[i]) for j in range(1, N + 1): if 1 <= i - j <= N and 1 <= i + j <= N: if (S[i - j] == "G" and S[i + j] == "B") or ( S[i - j] == "B" and S[i + j] == "G" ): ans -= 1 elif S[i] == "G": ans += R[i - 1] * (B[-1] - B[i]) ans += B[i - 1] * (R[-1] - R[i]) for j in range(1, N + 1): if 1 <= i - j <= N and 1 <= i + j <= N: if (S[i - j] == "R" and S[i + j] == "B") or ( S[i - j] == "B" and S[i + j] == "R" ): ans -= 1 else: ans += G[i - 1] * (R[-1] - R[i]) ans += R[i - 1] * (G[-1] - G[i]) for j in range(1, N + 1): if 1 <= i - j <= N and 1 <= i + j <= N: if (S[i - j] == "R" and S[i + j] == "G") or ( S[i - j] == "G" and S[i + j] == "R" ): ans -= 1 print(ans)
false
60.714286
[ "-N = int(eval(input()))", "-S = list(eval(input()))", "-r = 0", "-g = 0", "-b = 0", "-for i in range(N):", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+", "+", "+def I():", "+ return int(sys.stdin.readline().rstrip())", "+", "+", "+def MI():", "+ return list(map(int, sys.stdin.readline().rstrip().split()))", "+", "+", "+def LI():", "+ return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり", "+", "+", "+def LI2():", "+ return list(map(int, sys.stdin.readline().rstrip())) # 空白なし", "+", "+", "+def S():", "+ return sys.stdin.readline().rstrip()", "+", "+", "+def LS():", "+ return list(sys.stdin.readline().rstrip().split()) # 空白あり", "+", "+", "+def LS2():", "+ return list(sys.stdin.readline().rstrip()) # 空白なし", "+", "+", "+N = I()", "+S = [\"\"] + LS2()", "+R = [0] * (N + 1)", "+G = [0] * (N + 1)", "+B = [0] * (N + 1)", "+for i in range(1, N + 1):", "+ s = S[i]", "+ R[i] = R[i - 1]", "+ G[i] = G[i - 1]", "+ B[i] = B[i - 1]", "+ if s == \"R\":", "+ R[i] += 1", "+ elif s == \"G\":", "+ G[i] += 1", "+ else:", "+ B[i] += 1", "+ans = 0", "+for i in range(2, N):", "- r += 1", "+ ans += G[i - 1] * (B[-1] - B[i])", "+ ans += B[i - 1] * (G[-1] - G[i])", "+ for j in range(1, N + 1):", "+ if 1 <= i - j <= N and 1 <= i + j <= N:", "+ if (S[i - j] == \"G\" and S[i + j] == \"B\") or (", "+ S[i - j] == \"B\" and S[i + j] == \"G\"", "+ ):", "+ ans -= 1", "- g += 1", "+ ans += R[i - 1] * (B[-1] - B[i])", "+ ans += B[i - 1] * (R[-1] - R[i])", "+ for j in range(1, N + 1):", "+ if 1 <= i - j <= N and 1 <= i + j <= N:", "+ if (S[i - j] == \"R\" and S[i + j] == \"B\") or (", "+ S[i - j] == \"B\" and S[i + j] == \"R\"", "+ ):", "+ ans -= 1", "- b += 1", "-ans = r * g * b", "-for i in range(1, N - 1):", "- for j in range(1, min(i, N - i - 1) + 1):", "- if S[i] != S[i - j] and S[i] != S[i + j] and S[i - j] != S[i + j]:", "- ans -= 1", "+ ans += G[i - 1] * (R[-1] - R[i])", "+ ans += R[i - 1] * (G[-1] - G[i])", "+ for j in range(1, N + 1):", "+ if 1 <= i - j <= N and 1 <= i + j <= N:", "+ if (S[i - j] == \"R\" and S[i + j] == \"G\") or (", "+ S[i - j] == \"G\" and S[i + j] == \"R\"", "+ ):", "+ ans -= 1" ]
false
0.076661
0.043119
1.77791
[ "s954702232", "s228502340" ]
u185896732
p03037
python
s132576205
s500365569
568
334
43,780
6,900
Accepted
Accepted
41.2
n,m=list(map(int,input().split())) maxl,minr=0,n for i in range(m): l,r=list(map(int,input().split())) maxl=max(maxl,l) minr=min(minr,r) print((max(0,minr-maxl+1)))
n,m=list(map(int,input().split())) card=[0]*(n+1) for _ in range(m): l,r=list(map(int,input().split())) card[l-1]+=1 card[r]-=1 for i in range(1,n+1): card[i]+=card[i-1] print((card.count(m)))
7
9
168
202
n, m = list(map(int, input().split())) maxl, minr = 0, n for i in range(m): l, r = list(map(int, input().split())) maxl = max(maxl, l) minr = min(minr, r) print((max(0, minr - maxl + 1)))
n, m = list(map(int, input().split())) card = [0] * (n + 1) for _ in range(m): l, r = list(map(int, input().split())) card[l - 1] += 1 card[r] -= 1 for i in range(1, n + 1): card[i] += card[i - 1] print((card.count(m)))
false
22.222222
[ "-maxl, minr = 0, n", "-for i in range(m):", "+card = [0] * (n + 1)", "+for _ in range(m):", "- maxl = max(maxl, l)", "- minr = min(minr, r)", "-print((max(0, minr - maxl + 1)))", "+ card[l - 1] += 1", "+ card[r] -= 1", "+for i in range(1, n + 1):", "+ card[i] += card[i - 1]", "+print((card.count(m)))" ]
false
0.042416
0.111111
0.381747
[ "s132576205", "s500365569" ]
u562935282
p02949
python
s757746048
s990764707
1,793
1,302
46,852
49,628
Accepted
Accepted
27.38
def Bellman_Ford(s, g, inf=1 << 60): # https://tjkendev.github.io/procon-library/python/graph/bellman-ford.html N = len(g) dist = [inf] * N dist[s] = 0 for _ in range(N): not_updated = True for v in range(N): for u, c in g[v]: if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue dist[u] = dist[v] + c not_updated = False if not_updated: return max(0, -dist[N - 1]) # 負閉路が存在する for _ in range(N): not_updated = True for v in range(N): for u, c in g[v]: if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue dist[u] = -inf not_updated = False if not_updated: break if dist[N - 1] == -inf: return -1 else: return max(0, -dist[N - 1]) def main(): import sys input = sys.stdin.readline N, M, P = list(map(int, input().split())) g = tuple(set() for _ in range(N)) for _ in range(M): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 g[a].add((b, -(c - P))) # to,coin(負辺) ret = Bellman_Ford(0, g) print(ret) if __name__ == '__main__': main()
def main(): from collections import deque import sys input = sys.stdin.readline inf = 1 << 60 N, M, P = list(map(int, input().split())) to = tuple(set() for _ in range(N)) ot = tuple(set() for _ in range(N)) for _ in range(M): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 to[a].add((b, -(c - P))) # to,coin(負辺) ot[b].add((a, -(c - P))) # to,coin(負辺) def reach(s, g, result): dq = deque() dq.append(s) while dq: v = dq.popleft() for u, _ in g[v]: if result[u]: continue result[u] = 1 dq.append(u) reachable_from_N = [0] * N reachable_from_N[N - 1] = 1 reach(N - 1, ot, reachable_from_N) reachable_from_1 = [0] * N reachable_from_1[0] = 1 reach(0, to, reachable_from_1) unreachable = tuple(1 ^ (rn & r1) for rn, r1 in zip(reachable_from_N, reachable_from_1)) def bellman_ford(dist): for _ in range(N): not_updated = True for v in range(N): for u, c in to[v]: if unreachable[u]: continue if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue dist[u] = dist[v] + c not_updated = False if not_updated: return False for v in range(N): # 負閉路検知 for u, c in to[v]: if unreachable[u]: continue if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue return True return False dist = [inf] * N dist[0] = 0 cond = bellman_ford(dist=dist) if cond: print((-1)) else: print((max(0, -dist[N - 1]))) if __name__ == '__main__': main()
51
68
1,295
1,860
def Bellman_Ford(s, g, inf=1 << 60): # https://tjkendev.github.io/procon-library/python/graph/bellman-ford.html N = len(g) dist = [inf] * N dist[s] = 0 for _ in range(N): not_updated = True for v in range(N): for u, c in g[v]: if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue dist[u] = dist[v] + c not_updated = False if not_updated: return max(0, -dist[N - 1]) # 負閉路が存在する for _ in range(N): not_updated = True for v in range(N): for u, c in g[v]: if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue dist[u] = -inf not_updated = False if not_updated: break if dist[N - 1] == -inf: return -1 else: return max(0, -dist[N - 1]) def main(): import sys input = sys.stdin.readline N, M, P = list(map(int, input().split())) g = tuple(set() for _ in range(N)) for _ in range(M): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 g[a].add((b, -(c - P))) # to,coin(負辺) ret = Bellman_Ford(0, g) print(ret) if __name__ == "__main__": main()
def main(): from collections import deque import sys input = sys.stdin.readline inf = 1 << 60 N, M, P = list(map(int, input().split())) to = tuple(set() for _ in range(N)) ot = tuple(set() for _ in range(N)) for _ in range(M): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 to[a].add((b, -(c - P))) # to,coin(負辺) ot[b].add((a, -(c - P))) # to,coin(負辺) def reach(s, g, result): dq = deque() dq.append(s) while dq: v = dq.popleft() for u, _ in g[v]: if result[u]: continue result[u] = 1 dq.append(u) reachable_from_N = [0] * N reachable_from_N[N - 1] = 1 reach(N - 1, ot, reachable_from_N) reachable_from_1 = [0] * N reachable_from_1[0] = 1 reach(0, to, reachable_from_1) unreachable = tuple( 1 ^ (rn & r1) for rn, r1 in zip(reachable_from_N, reachable_from_1) ) def bellman_ford(dist): for _ in range(N): not_updated = True for v in range(N): for u, c in to[v]: if unreachable[u]: continue if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue dist[u] = dist[v] + c not_updated = False if not_updated: return False for v in range(N): # 負閉路検知 for u, c in to[v]: if unreachable[u]: continue if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue return True return False dist = [inf] * N dist[0] = 0 cond = bellman_ford(dist=dist) if cond: print((-1)) else: print((max(0, -dist[N - 1]))) if __name__ == "__main__": main()
false
25
[ "-def Bellman_Ford(s, g, inf=1 << 60):", "- # https://tjkendev.github.io/procon-library/python/graph/bellman-ford.html", "- N = len(g)", "- dist = [inf] * N", "- dist[s] = 0", "- for _ in range(N):", "- not_updated = True", "- for v in range(N):", "- for u, c in g[v]:", "- if (dist[v] == inf) or (dist[v] + c >= dist[u]):", "- continue", "- dist[u] = dist[v] + c", "- not_updated = False", "- if not_updated:", "- return max(0, -dist[N - 1])", "- # 負閉路が存在する", "- for _ in range(N):", "- not_updated = True", "- for v in range(N):", "- for u, c in g[v]:", "- if (dist[v] == inf) or (dist[v] + c >= dist[u]):", "- continue", "- dist[u] = -inf", "- not_updated = False", "- if not_updated:", "- break", "- if dist[N - 1] == -inf:", "- return -1", "- else:", "- return max(0, -dist[N - 1])", "-", "-", "+ from collections import deque", "+ inf = 1 << 60", "- g = tuple(set() for _ in range(N))", "+ to = tuple(set() for _ in range(N))", "+ ot = tuple(set() for _ in range(N))", "- g[a].add((b, -(c - P))) # to,coin(負辺)", "- ret = Bellman_Ford(0, g)", "- print(ret)", "+ to[a].add((b, -(c - P))) # to,coin(負辺)", "+ ot[b].add((a, -(c - P))) # to,coin(負辺)", "+", "+ def reach(s, g, result):", "+ dq = deque()", "+ dq.append(s)", "+ while dq:", "+ v = dq.popleft()", "+ for u, _ in g[v]:", "+ if result[u]:", "+ continue", "+ result[u] = 1", "+ dq.append(u)", "+", "+ reachable_from_N = [0] * N", "+ reachable_from_N[N - 1] = 1", "+ reach(N - 1, ot, reachable_from_N)", "+ reachable_from_1 = [0] * N", "+ reachable_from_1[0] = 1", "+ reach(0, to, reachable_from_1)", "+ unreachable = tuple(", "+ 1 ^ (rn & r1) for rn, r1 in zip(reachable_from_N, reachable_from_1)", "+ )", "+", "+ def bellman_ford(dist):", "+ for _ in range(N):", "+ not_updated = True", "+ for v in range(N):", "+ for u, c in to[v]:", "+ if unreachable[u]:", "+ continue", "+ if (dist[v] == inf) or (dist[v] + c >= dist[u]):", "+ continue", "+ dist[u] = dist[v] + c", "+ not_updated = False", "+ if not_updated:", "+ return False", "+ for v in range(N): # 負閉路検知", "+ for u, c in to[v]:", "+ if unreachable[u]:", "+ continue", "+ if (dist[v] == inf) or (dist[v] + c >= dist[u]):", "+ continue", "+ return True", "+ return False", "+", "+ dist = [inf] * N", "+ dist[0] = 0", "+ cond = bellman_ford(dist=dist)", "+ if cond:", "+ print((-1))", "+ else:", "+ print((max(0, -dist[N - 1])))" ]
false
0.03932
0.095566
0.411438
[ "s757746048", "s990764707" ]
u729133443
p03073
python
s911709712
s413882097
198
66
47,452
3,188
Accepted
Accepted
66.67
*s,=list(map(int,eval(input())));a=0 for i in range(1,len(s)):a+=s[i]==s[i-1];s[i]=1-s[i-1] print(a)
a=0 for i,s in enumerate(eval(input())):a+=i%2^int(s) print((min(a,i-a+1)))
3
3
90
69
(*s,) = list(map(int, eval(input()))) a = 0 for i in range(1, len(s)): a += s[i] == s[i - 1] s[i] = 1 - s[i - 1] print(a)
a = 0 for i, s in enumerate(eval(input())): a += i % 2 ^ int(s) print((min(a, i - a + 1)))
false
0
[ "-(*s,) = list(map(int, eval(input())))", "-for i in range(1, len(s)):", "- a += s[i] == s[i - 1]", "- s[i] = 1 - s[i - 1]", "-print(a)", "+for i, s in enumerate(eval(input())):", "+ a += i % 2 ^ int(s)", "+print((min(a, i - a + 1)))" ]
false
0.037721
0.087848
0.429389
[ "s911709712", "s413882097" ]
u340781749
p03472
python
s283557299
s682406987
473
347
59,096
12,084
Accepted
Accepted
26.64
from math import ceil def solve(h, aa, bb): max_a = max(aa) i = 0 for b in sorted(bb, reverse=True): if b <= max_a: break i += 1 h -= b if h <= 0: return i return i + ceil(h / max_a) n, h = list(map(int, input().split())) aa, bb = list(zip(*(list(map(int, input().split())) for _ in range(n)))) print((solve(h, aa, bb)))
from math import ceil def solve(h, aa, bb): max_a = max(aa) i = 0 for b in sorted(bb, reverse=True): if b <= max_a: break i += 1 h -= b if h <= 0: return i return i + ceil(h / max_a) n, h = list(map(int, input().split())) aa, bb = [], [] for _ in range(n): a, b = list(map(int, input().split())) aa.append(a) bb.append(b) print((solve(h, aa, bb)))
20
24
397
446
from math import ceil def solve(h, aa, bb): max_a = max(aa) i = 0 for b in sorted(bb, reverse=True): if b <= max_a: break i += 1 h -= b if h <= 0: return i return i + ceil(h / max_a) n, h = list(map(int, input().split())) aa, bb = list(zip(*(list(map(int, input().split())) for _ in range(n)))) print((solve(h, aa, bb)))
from math import ceil def solve(h, aa, bb): max_a = max(aa) i = 0 for b in sorted(bb, reverse=True): if b <= max_a: break i += 1 h -= b if h <= 0: return i return i + ceil(h / max_a) n, h = list(map(int, input().split())) aa, bb = [], [] for _ in range(n): a, b = list(map(int, input().split())) aa.append(a) bb.append(b) print((solve(h, aa, bb)))
false
16.666667
[ "-aa, bb = list(zip(*(list(map(int, input().split())) for _ in range(n))))", "+aa, bb = [], []", "+for _ in range(n):", "+ a, b = list(map(int, input().split()))", "+ aa.append(a)", "+ bb.append(b)" ]
false
0.038092
0.03517
1.083066
[ "s283557299", "s682406987" ]
u067694718
p02779
python
s010054813
s607179000
188
103
25,168
25,936
Accepted
Accepted
45.21
n = int(eval(input())) a = [int(i) for i in input().split()] a.sort() for i in range(n-1): if a[i] == a[i+1]: print("NO") exit() print("YES")
n = int(eval(input())) a = [int(i) for i in input().split()] aset = set(a) print(("YES" if len(a) == len(aset) else "NO"))
10
5
166
119
n = int(eval(input())) a = [int(i) for i in input().split()] a.sort() for i in range(n - 1): if a[i] == a[i + 1]: print("NO") exit() print("YES")
n = int(eval(input())) a = [int(i) for i in input().split()] aset = set(a) print(("YES" if len(a) == len(aset) else "NO"))
false
50
[ "-a.sort()", "-for i in range(n - 1):", "- if a[i] == a[i + 1]:", "- print(\"NO\")", "- exit()", "-print(\"YES\")", "+aset = set(a)", "+print((\"YES\" if len(a) == len(aset) else \"NO\"))" ]
false
0.072132
0.085073
0.847887
[ "s010054813", "s607179000" ]
u608088992
p04035
python
s871010429
s821157096
157
124
14,068
14,072
Accepted
Accepted
21.02
N, L = list(map(int, input().split())) A = [int(a) for a in input().split()] CanRemain = [] CutFirst = [] for i in range(N-1): if A[i] + A[i+1] >= L: CanRemain.append(i+1) else: CutFirst.append(i+1) if not CanRemain: print("Impossible") else: print("Possible") for num in CutFirst: if num < CanRemain[-1]: print(num) else: break for i in reversed(list(range(len(CutFirst)))): if CutFirst[i] > CanRemain[-1]: print((CutFirst[i])) else: break for num in CanRemain: print(num)
import sys def solve(): input = sys.stdin.readline N, L = list(map(int, input().split())) A = [int(a) for a in input().split()] for i in range(N - 1): if A[i] + A[i+1] >= L: print("Possible") for k in range(i): print((k + 1)) for k in reversed(list(range(i + 1, N - 1))): print((k + 1)) print((i + 1)) break else: print("Impossible") return 0 if __name__ == "__main__": solve()
19
19
535
476
N, L = list(map(int, input().split())) A = [int(a) for a in input().split()] CanRemain = [] CutFirst = [] for i in range(N - 1): if A[i] + A[i + 1] >= L: CanRemain.append(i + 1) else: CutFirst.append(i + 1) if not CanRemain: print("Impossible") else: print("Possible") for num in CutFirst: if num < CanRemain[-1]: print(num) else: break for i in reversed(list(range(len(CutFirst)))): if CutFirst[i] > CanRemain[-1]: print((CutFirst[i])) else: break for num in CanRemain: print(num)
import sys def solve(): input = sys.stdin.readline N, L = list(map(int, input().split())) A = [int(a) for a in input().split()] for i in range(N - 1): if A[i] + A[i + 1] >= L: print("Possible") for k in range(i): print((k + 1)) for k in reversed(list(range(i + 1, N - 1))): print((k + 1)) print((i + 1)) break else: print("Impossible") return 0 if __name__ == "__main__": solve()
false
0
[ "-N, L = list(map(int, input().split()))", "-A = [int(a) for a in input().split()]", "-CanRemain = []", "-CutFirst = []", "-for i in range(N - 1):", "- if A[i] + A[i + 1] >= L:", "- CanRemain.append(i + 1)", "+import sys", "+", "+", "+def solve():", "+ input = sys.stdin.readline", "+ N, L = list(map(int, input().split()))", "+ A = [int(a) for a in input().split()]", "+ for i in range(N - 1):", "+ if A[i] + A[i + 1] >= L:", "+ print(\"Possible\")", "+ for k in range(i):", "+ print((k + 1))", "+ for k in reversed(list(range(i + 1, N - 1))):", "+ print((k + 1))", "+ print((i + 1))", "+ break", "- CutFirst.append(i + 1)", "-if not CanRemain:", "- print(\"Impossible\")", "-else:", "- print(\"Possible\")", "- for num in CutFirst:", "- if num < CanRemain[-1]:", "- print(num)", "- else:", "- break", "- for i in reversed(list(range(len(CutFirst)))):", "- if CutFirst[i] > CanRemain[-1]:", "- print((CutFirst[i]))", "- else:", "- break", "- for num in CanRemain:", "- print(num)", "+ print(\"Impossible\")", "+ return 0", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.05739
0.041164
1.39419
[ "s871010429", "s821157096" ]
u753803401
p03588
python
s401291021
s910432178
571
525
56,412
54,748
Accepted
Accepted
8.06
def slove(): import sys input = sys.stdin.readline n = int(input().rstrip('\n')) ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)] ab.sort() print((ab[-1][0] + ab[-1][1])) if __name__ == '__main__': slove()
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 n = int(readline()) ab = [list(map(int, readline().split())) for _ in range(n)] ab.sort() print(((ab[-1][0] - ab[0][0] + 1) + (ab[0][0] - 1) + (ab[-1][1]))) if __name__ == '__main__': solve()
11
14
265
314
def slove(): import sys input = sys.stdin.readline n = int(input().rstrip("\n")) ab = [list(map(int, input().rstrip("\n").split())) for _ in range(n)] ab.sort() print((ab[-1][0] + ab[-1][1])) if __name__ == "__main__": slove()
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10**9 + 7 n = int(readline()) ab = [list(map(int, readline().split())) for _ in range(n)] ab.sort() print(((ab[-1][0] - ab[0][0] + 1) + (ab[0][0] - 1) + (ab[-1][1]))) if __name__ == "__main__": solve()
false
21.428571
[ "-def slove():", "- import sys", "+import sys", "- input = sys.stdin.readline", "- n = int(input().rstrip(\"\\n\"))", "- ab = [list(map(int, input().rstrip(\"\\n\").split())) for _ in range(n)]", "+", "+def solve():", "+ readline = sys.stdin.buffer.readline", "+ mod = 10**9 + 7", "+ n = int(readline())", "+ ab = [list(map(int, readline().split())) for _ in range(n)]", "- print((ab[-1][0] + ab[-1][1]))", "+ print(((ab[-1][0] - ab[0][0] + 1) + (ab[0][0] - 1) + (ab[-1][1])))", "- slove()", "+ solve()" ]
false
0.043702
0.055596
0.786061
[ "s401291021", "s910432178" ]
u823044869
p03433
python
s772732554
s374301915
20
17
2,940
2,940
Accepted
Accepted
15
N = int(eval(input())) A = int(eval(input())) amari = N % 500 if amari <= A: print('Yes') else: print('No')
n = int(eval(input())) a = int(eval(input())) if n%500 <= a: print("Yes") else: print("No")
9
8
113
93
N = int(eval(input())) A = int(eval(input())) amari = N % 500 if amari <= A: print("Yes") else: print("No")
n = int(eval(input())) a = int(eval(input())) if n % 500 <= a: print("Yes") else: print("No")
false
11.111111
[ "-N = int(eval(input()))", "-A = int(eval(input()))", "-amari = N % 500", "-if amari <= A:", "+n = int(eval(input()))", "+a = int(eval(input()))", "+if n % 500 <= a:" ]
false
0.046155
0.043793
1.05393
[ "s772732554", "s374301915" ]
u077291787
p03274
python
s478470509
s255491125
66
57
14,052
14,052
Accepted
Accepted
13.64
# ABC107C - Candles (ARC101C) def main(): N, K, *X = list(map(int, open(0).read().split())) ans = float("inf") for l, r in zip(X, X[K - 1 :]): ans = min(ans, r - l + min(abs(l), abs(r))) print(ans) if __name__ == "__main__": main()
# ABC107C - Candles (ARC101C) def main(): N, K, *X = list(map(int, open(0).read().split())) ans = float("inf") for l, r in zip(X, X[K - 1 :]): x = r - l + min(abs(l), abs(r)) ans = x if x < ans else ans print(ans) if __name__ == "__main__": main()
11
12
265
290
# ABC107C - Candles (ARC101C) def main(): N, K, *X = list(map(int, open(0).read().split())) ans = float("inf") for l, r in zip(X, X[K - 1 :]): ans = min(ans, r - l + min(abs(l), abs(r))) print(ans) if __name__ == "__main__": main()
# ABC107C - Candles (ARC101C) def main(): N, K, *X = list(map(int, open(0).read().split())) ans = float("inf") for l, r in zip(X, X[K - 1 :]): x = r - l + min(abs(l), abs(r)) ans = x if x < ans else ans print(ans) if __name__ == "__main__": main()
false
8.333333
[ "- ans = min(ans, r - l + min(abs(l), abs(r)))", "+ x = r - l + min(abs(l), abs(r))", "+ ans = x if x < ans else ans" ]
false
0.127162
0.038272
3.322579
[ "s478470509", "s255491125" ]
u094191970
p03062
python
s157729738
s033726511
106
69
14,412
14,224
Accepted
Accepted
34.91
n=int(eval(input())) a=list(map(int, input().split())) a_s=sorted(a) for i in range(0,n-1,2): if a_s[i]<0 and a_s[i+1]<0: a_s[i]=-a_s[i] a_s[i+1]=-a_s[i+1] elif a_s[i]<0 and -a_s[i]>a_s[i+1]: a_s[i]=-a_s[i] a_s[i+1]=-a_s[i+1] else: break print((sum(a_s)))
n=int(eval(input())) a=list(map(int, input().split())) b=list(map(abs, a)) cnt = 0 for i in range(n): if a[i]<0: cnt+=1 if cnt%2==0: print((sum(b))) else: print((sum(b)-2*min(b)))
13
11
311
199
n = int(eval(input())) a = list(map(int, input().split())) a_s = sorted(a) for i in range(0, n - 1, 2): if a_s[i] < 0 and a_s[i + 1] < 0: a_s[i] = -a_s[i] a_s[i + 1] = -a_s[i + 1] elif a_s[i] < 0 and -a_s[i] > a_s[i + 1]: a_s[i] = -a_s[i] a_s[i + 1] = -a_s[i + 1] else: break print((sum(a_s)))
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(abs, a)) cnt = 0 for i in range(n): if a[i] < 0: cnt += 1 if cnt % 2 == 0: print((sum(b))) else: print((sum(b) - 2 * min(b)))
false
15.384615
[ "-a_s = sorted(a)", "-for i in range(0, n - 1, 2):", "- if a_s[i] < 0 and a_s[i + 1] < 0:", "- a_s[i] = -a_s[i]", "- a_s[i + 1] = -a_s[i + 1]", "- elif a_s[i] < 0 and -a_s[i] > a_s[i + 1]:", "- a_s[i] = -a_s[i]", "- a_s[i + 1] = -a_s[i + 1]", "- else:", "- break", "-print((sum(a_s)))", "+b = list(map(abs, a))", "+cnt = 0", "+for i in range(n):", "+ if a[i] < 0:", "+ cnt += 1", "+if cnt % 2 == 0:", "+ print((sum(b)))", "+else:", "+ print((sum(b) - 2 * min(b)))" ]
false
0.035718
0.03638
0.981819
[ "s157729738", "s033726511" ]
u167681750
p03487
python
s742127105
s528102359
78
71
18,672
18,672
Accepted
Accepted
8.97
from collections import Counter N = int(eval(input())) a = list(map(int, input().split())) ca = Counter(a) ans = 0 for num, freq in list(ca.items()): ans += freq- num if freq >= num else freq print(ans)
from collections import Counter N = int(eval(input())) a = list(map(int, input().split())) ans = 0 for num, freq in list(Counter(a).items()): ans += freq- num if freq >= num else freq print(ans)
12
10
209
198
from collections import Counter N = int(eval(input())) a = list(map(int, input().split())) ca = Counter(a) ans = 0 for num, freq in list(ca.items()): ans += freq - num if freq >= num else freq print(ans)
from collections import Counter N = int(eval(input())) a = list(map(int, input().split())) ans = 0 for num, freq in list(Counter(a).items()): ans += freq - num if freq >= num else freq print(ans)
false
16.666667
[ "-ca = Counter(a)", "-for num, freq in list(ca.items()):", "+for num, freq in list(Counter(a).items()):" ]
false
0.055366
0.054485
1.016179
[ "s742127105", "s528102359" ]
u528748570
p03161
python
s703605281
s217233644
1,428
456
56,320
52,448
Accepted
Accepted
68.07
import heapq N, K = list(map(int, input().split())) h = list(map(int, input().split())) dp = [0] * N dp[1] = dp[0] + abs(h[1]-h[0]) for i in range(2, N): compare = [] heapq.heapify(compare) cnt = min(K, i) for j in range(cnt): heapq.heappush(compare, dp[i-j-1] + abs(h[i]-h[i-j-1])) dp[i] = heapq.heappop(compare) print((dp[-1]))
N, K = list(map(int, input().split())) h = list(map(int, input().split())) dp = [0] * N dp[1] = dp[0] + abs(h[1]-h[0]) for i in range(2, N): compare = [] cnt = min(K, i) for j in range(cnt): compare.append(dp[i-j-1] + abs(h[i]-h[i-j-1])) dp[i] = min(compare) print((dp[-1]))
16
14
369
308
import heapq N, K = list(map(int, input().split())) h = list(map(int, input().split())) dp = [0] * N dp[1] = dp[0] + abs(h[1] - h[0]) for i in range(2, N): compare = [] heapq.heapify(compare) cnt = min(K, i) for j in range(cnt): heapq.heappush(compare, dp[i - j - 1] + abs(h[i] - h[i - j - 1])) dp[i] = heapq.heappop(compare) print((dp[-1]))
N, K = list(map(int, input().split())) h = list(map(int, input().split())) dp = [0] * N dp[1] = dp[0] + abs(h[1] - h[0]) for i in range(2, N): compare = [] cnt = min(K, i) for j in range(cnt): compare.append(dp[i - j - 1] + abs(h[i] - h[i - j - 1])) dp[i] = min(compare) print((dp[-1]))
false
12.5
[ "-import heapq", "-", "- heapq.heapify(compare)", "- heapq.heappush(compare, dp[i - j - 1] + abs(h[i] - h[i - j - 1]))", "- dp[i] = heapq.heappop(compare)", "+ compare.append(dp[i - j - 1] + abs(h[i] - h[i - j - 1]))", "+ dp[i] = min(compare)" ]
false
0.034235
0.043463
0.787669
[ "s703605281", "s217233644" ]
u888092736
p03178
python
s621350021
s035090457
976
816
86,380
129,008
Accepted
Accepted
16.39
def solve(K, D): N = len(K) MOD = 1_000_000_007 dp = [[[0] * D for _ in range(2)] for _ in range(N + 1)] dp[0][0][0] = 1 for i in range(N): for is_less in range(2): for k in range(D): for l in range(10 if is_less else K[i] + 1): is_less_ = is_less or l < K[i] k_ = (k + l) % D dp[i + 1][is_less_][k_] += dp[i][is_less][k] dp[i + 1][is_less_][k_] %= MOD return (dp[N][0][0] + dp[N][1][0] - 1) % MOD print((solve(list(map(int, eval(input()))), int(eval(input())))))
# 25:27 import numpy as np from numba import njit @njit("i8(i8[:],i8)") def solve(K, D): N = len(K) MOD = 1_000_000_007 dp = np.zeros((N + 1, 2, D), dtype=np.int64) dp[0][0][0] = 1 for i in range(N): for is_less in range(2): for k in range(D): for l in range(10 if is_less else K[i] + 1): is_less_ = is_less or l < K[i] k_ = (k + l) % D dp[i + 1][is_less_][k_] += dp[i][is_less][k] dp[i + 1][is_less_][k_] %= MOD return (dp[N][0][0] + dp[N][1][0] - 1) % MOD print((solve(np.array(list(map(int, eval(input())))), int(eval(input())))))
17
23
608
686
def solve(K, D): N = len(K) MOD = 1_000_000_007 dp = [[[0] * D for _ in range(2)] for _ in range(N + 1)] dp[0][0][0] = 1 for i in range(N): for is_less in range(2): for k in range(D): for l in range(10 if is_less else K[i] + 1): is_less_ = is_less or l < K[i] k_ = (k + l) % D dp[i + 1][is_less_][k_] += dp[i][is_less][k] dp[i + 1][is_less_][k_] %= MOD return (dp[N][0][0] + dp[N][1][0] - 1) % MOD print((solve(list(map(int, eval(input()))), int(eval(input())))))
# 25:27 import numpy as np from numba import njit @njit("i8(i8[:],i8)") def solve(K, D): N = len(K) MOD = 1_000_000_007 dp = np.zeros((N + 1, 2, D), dtype=np.int64) dp[0][0][0] = 1 for i in range(N): for is_less in range(2): for k in range(D): for l in range(10 if is_less else K[i] + 1): is_less_ = is_less or l < K[i] k_ = (k + l) % D dp[i + 1][is_less_][k_] += dp[i][is_less][k] dp[i + 1][is_less_][k_] %= MOD return (dp[N][0][0] + dp[N][1][0] - 1) % MOD print((solve(np.array(list(map(int, eval(input())))), int(eval(input())))))
false
26.086957
[ "+# 25:27", "+import numpy as np", "+from numba import njit", "+", "+", "+@njit(\"i8(i8[:],i8)\")", "- dp = [[[0] * D for _ in range(2)] for _ in range(N + 1)]", "+ dp = np.zeros((N + 1, 2, D), dtype=np.int64)", "-print((solve(list(map(int, eval(input()))), int(eval(input())))))", "+print((solve(np.array(list(map(int, eval(input())))), int(eval(input())))))" ]
false
0.048199
0.560681
0.085964
[ "s621350021", "s035090457" ]
u949517845
p02279
python
s717024258
s994742347
4,450
2,880
254,592
176,224
Accepted
Accepted
35.28
# -*- coding:utf-8 -*- import sys from collections import OrderedDict def cleate_node_dict(children): node_dict = OrderedDict() for val in children: node_dict[val] = OrderedDict() return node_dict def cleate_tree(nodes): tree = nodes.copy() for node, children in list(nodes.items()): for key in list(children.keys()): children[key] = nodes[key] del tree[key] return tree def rec(current, acc, parent=-1, depth=0): if current == {}: return for node, children in list(current.items()): cld_lst = list(children.keys()) acc[node] = "node {0}: parent = {1}, depth = {2}, {3}, {4}".format( node, parent, depth, node_type(parent, children), cld_lst) rec(children, acc, node, depth+1) def node_type(parent, children): if parent == -1: return "root" elif children != {}: return "internal node" else: return "leaf" if __name__ == "__main__": n = int(eval(input())) lst = [[int(n) for n in val.split()] for val in sys.stdin.readlines()] nodes = {val[0]: cleate_node_dict(val[2:]) for val in lst} tree = cleate_tree(nodes) node_info = {} rec(tree, node_info) for key, val in sorted(node_info.items()): print(val)
# -*- coding:utf-8 -*- import sys from collections import OrderedDict def cleate_node_dict(children): node_dict = OrderedDict() for val in children: node_dict[val] = None return node_dict def cleate_tree(nodes): tree = nodes.copy() for node, children in list(nodes.items()): for key in list(children.keys()): children[key] = nodes[key] del tree[key] return tree def rec(current, acc, parent=-1, depth=0): if current == {}: return for node, children in list(current.items()): cld_lst = list(children.keys()) acc[node] = "node {0}: parent = {1}, depth = {2}, {3}, {4}".format( node, parent, depth, node_type(parent, children), cld_lst) rec(children, acc, node, depth+1) def node_type(parent, children): if parent == -1: return "root" elif children != {}: return "internal node" else: return "leaf" def rooted_trees(lst, n): nodes = {val[0]: cleate_node_dict(val[2:]) for val in lst} tree = cleate_tree(nodes) node_info = [None] * n rec(tree, node_info) print(("\n".join(node_info))) if __name__ == "__main__": n = int(eval(input())) lst = [[int(n) for n in val.split()] for val in sys.stdin.readlines()] rooted_trees(lst, n)
50
53
1,328
1,349
# -*- coding:utf-8 -*- import sys from collections import OrderedDict def cleate_node_dict(children): node_dict = OrderedDict() for val in children: node_dict[val] = OrderedDict() return node_dict def cleate_tree(nodes): tree = nodes.copy() for node, children in list(nodes.items()): for key in list(children.keys()): children[key] = nodes[key] del tree[key] return tree def rec(current, acc, parent=-1, depth=0): if current == {}: return for node, children in list(current.items()): cld_lst = list(children.keys()) acc[node] = "node {0}: parent = {1}, depth = {2}, {3}, {4}".format( node, parent, depth, node_type(parent, children), cld_lst ) rec(children, acc, node, depth + 1) def node_type(parent, children): if parent == -1: return "root" elif children != {}: return "internal node" else: return "leaf" if __name__ == "__main__": n = int(eval(input())) lst = [[int(n) for n in val.split()] for val in sys.stdin.readlines()] nodes = {val[0]: cleate_node_dict(val[2:]) for val in lst} tree = cleate_tree(nodes) node_info = {} rec(tree, node_info) for key, val in sorted(node_info.items()): print(val)
# -*- coding:utf-8 -*- import sys from collections import OrderedDict def cleate_node_dict(children): node_dict = OrderedDict() for val in children: node_dict[val] = None return node_dict def cleate_tree(nodes): tree = nodes.copy() for node, children in list(nodes.items()): for key in list(children.keys()): children[key] = nodes[key] del tree[key] return tree def rec(current, acc, parent=-1, depth=0): if current == {}: return for node, children in list(current.items()): cld_lst = list(children.keys()) acc[node] = "node {0}: parent = {1}, depth = {2}, {3}, {4}".format( node, parent, depth, node_type(parent, children), cld_lst ) rec(children, acc, node, depth + 1) def node_type(parent, children): if parent == -1: return "root" elif children != {}: return "internal node" else: return "leaf" def rooted_trees(lst, n): nodes = {val[0]: cleate_node_dict(val[2:]) for val in lst} tree = cleate_tree(nodes) node_info = [None] * n rec(tree, node_info) print(("\n".join(node_info))) if __name__ == "__main__": n = int(eval(input())) lst = [[int(n) for n in val.split()] for val in sys.stdin.readlines()] rooted_trees(lst, n)
false
5.660377
[ "- node_dict[val] = OrderedDict()", "+ node_dict[val] = None", "+def rooted_trees(lst, n):", "+ nodes = {val[0]: cleate_node_dict(val[2:]) for val in lst}", "+ tree = cleate_tree(nodes)", "+ node_info = [None] * n", "+ rec(tree, node_info)", "+ print((\"\\n\".join(node_info)))", "+", "+", "- nodes = {val[0]: cleate_node_dict(val[2:]) for val in lst}", "- tree = cleate_tree(nodes)", "- node_info = {}", "- rec(tree, node_info)", "- for key, val in sorted(node_info.items()):", "- print(val)", "+ rooted_trees(lst, n)" ]
false
0.038356
0.039475
0.971639
[ "s717024258", "s994742347" ]
u166621202
p03102
python
s758204829
s443837901
151
18
12,504
3,060
Accepted
Accepted
88.08
import numpy as np N,M,C = list(map(int,input().split())) B=np.array(list(map(int,input().split()))) ans=0 for i in range(N): A=np.array(list(map(int,input().split()))) if sum(A*B)+C > 0: ans+=1 print(ans)
N,M,C = list(map(int,input().split())) B = list(map(int,input().split())) ans=0 for i in range(N): ab=0 A = list(map(int,input().split())) for j in range(M): ab += A[j] * B[j] if ab + C > 0: ans+=1 print(ans)
11
12
220
230
import numpy as np N, M, C = list(map(int, input().split())) B = np.array(list(map(int, input().split()))) ans = 0 for i in range(N): A = np.array(list(map(int, input().split()))) if sum(A * B) + C > 0: ans += 1 print(ans)
N, M, C = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 for i in range(N): ab = 0 A = list(map(int, input().split())) for j in range(M): ab += A[j] * B[j] if ab + C > 0: ans += 1 print(ans)
false
8.333333
[ "-import numpy as np", "-", "-B = np.array(list(map(int, input().split())))", "+B = list(map(int, input().split()))", "- A = np.array(list(map(int, input().split())))", "- if sum(A * B) + C > 0:", "+ ab = 0", "+ A = list(map(int, input().split()))", "+ for j in range(M):", "+ ab += A[j] * B[j]", "+ if ab + C > 0:" ]
false
0.163475
0.034939
4.678902
[ "s758204829", "s443837901" ]
u712429027
p02597
python
s638404069
s477202080
68
61
12,616
12,684
Accepted
Accepted
10.29
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print('\n'.join(map(str, x))) n = ini() s = list(ins()) t = sorted(s) ans = 0 for i in range(n): if t[i] != "R": break if s[i] != t[i]: ans += 1 print(ans)
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print('\n'.join(map(str, x))) n = ini() s = list(ins()) n = s.count("R") t = sorted(s) ans = 0 for i in range(n): if s[i] != t[i]: ans += 1 print(ans)
18
17
405
386
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print("\n".join(map(str, x))) n = ini() s = list(ins()) t = sorted(s) ans = 0 for i in range(n): if t[i] != "R": break if s[i] != t[i]: ans += 1 print(ans)
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print("\n".join(map(str, x))) n = ini() s = list(ins()) n = s.count("R") t = sorted(s) ans = 0 for i in range(n): if s[i] != t[i]: ans += 1 print(ans)
false
5.555556
[ "+n = s.count(\"R\")", "- if t[i] != \"R\":", "- break" ]
false
0.046552
0.040589
1.146918
[ "s638404069", "s477202080" ]
u847497464
p02971
python
s459526694
s587997949
560
515
14,112
14,112
Accepted
Accepted
8.04
n = int(eval(input())) a = [ int(eval(input())) for x in range(n) ] b = sorted(a, reverse = True) maximum = b[0] for i in a: if i == maximum: print((b[1])) else: print(maximum)
n = int(eval(input())) a = [ int(eval(input())) for x in range(n) ] b = sorted(a, reverse = True) maximum = b[0] for i in a: print(( b[1] if i == maximum else maximum ))
11
8
199
168
n = int(eval(input())) a = [int(eval(input())) for x in range(n)] b = sorted(a, reverse=True) maximum = b[0] for i in a: if i == maximum: print((b[1])) else: print(maximum)
n = int(eval(input())) a = [int(eval(input())) for x in range(n)] b = sorted(a, reverse=True) maximum = b[0] for i in a: print((b[1] if i == maximum else maximum))
false
27.272727
[ "- if i == maximum:", "- print((b[1]))", "- else:", "- print(maximum)", "+ print((b[1] if i == maximum else maximum))" ]
false
0.036076
0.045619
0.79082
[ "s459526694", "s587997949" ]
u896741788
p03715
python
s701857962
s654768375
193
75
40,496
67,768
Accepted
Accepted
61.14
h,w=list(map(int,input().split())) if h*w%3: ans=min(h,w) for x in range(1,w+1): ans=min(ans,max(h*x,h//2*(w-x),(h-h//2)*(w-x))-min(h*x,h//2*(w-x),(h-h//2)*(w-x))) h,w=w,h for x in range(1,w+1): ans=min(ans,max(h*x,h//2*(w-x),(h-h//2)*(w-x))-min(h*x,h//2*(w-x),(h-h//2)*(w-x))) print(ans) else:print((0))
h,w=list(map(int,input().split())) def f(x,y): ret=(1 if x%3 else 0)*y for i in range(1,x): f=sorted((i*y,y//2*(x-i),(1+y)//2*(x-i))) ret=min(ret,f[2]-f[0]) return ret print((min(f(h,w),f(w,h))))
10
8
323
222
h, w = list(map(int, input().split())) if h * w % 3: ans = min(h, w) for x in range(1, w + 1): ans = min( ans, max(h * x, h // 2 * (w - x), (h - h // 2) * (w - x)) - min(h * x, h // 2 * (w - x), (h - h // 2) * (w - x)), ) h, w = w, h for x in range(1, w + 1): ans = min( ans, max(h * x, h // 2 * (w - x), (h - h // 2) * (w - x)) - min(h * x, h // 2 * (w - x), (h - h // 2) * (w - x)), ) print(ans) else: print((0))
h, w = list(map(int, input().split())) def f(x, y): ret = (1 if x % 3 else 0) * y for i in range(1, x): f = sorted((i * y, y // 2 * (x - i), (1 + y) // 2 * (x - i))) ret = min(ret, f[2] - f[0]) return ret print((min(f(h, w), f(w, h))))
false
20
[ "-if h * w % 3:", "- ans = min(h, w)", "- for x in range(1, w + 1):", "- ans = min(", "- ans,", "- max(h * x, h // 2 * (w - x), (h - h // 2) * (w - x))", "- - min(h * x, h // 2 * (w - x), (h - h // 2) * (w - x)),", "- )", "- h, w = w, h", "- for x in range(1, w + 1):", "- ans = min(", "- ans,", "- max(h * x, h // 2 * (w - x), (h - h // 2) * (w - x))", "- - min(h * x, h // 2 * (w - x), (h - h // 2) * (w - x)),", "- )", "- print(ans)", "-else:", "- print((0))", "+", "+", "+def f(x, y):", "+ ret = (1 if x % 3 else 0) * y", "+ for i in range(1, x):", "+ f = sorted((i * y, y // 2 * (x - i), (1 + y) // 2 * (x - i)))", "+ ret = min(ret, f[2] - f[0])", "+ return ret", "+", "+", "+print((min(f(h, w), f(w, h))))" ]
false
0.055113
0.042082
1.309654
[ "s701857962", "s654768375" ]
u536560967
p03220
python
s448269978
s580997934
152
18
12,600
3,060
Accepted
Accepted
88.16
#!/usr/bin/env python3 import numpy as np n = int(eval(input())) t, a = list(map(int, input().split())) h = list(map(int, input().split())) a_t = [] for i in h: a_t.append(t - i * 0.006) print((np.abs(np.asarray(a_t) - a).argmin() + 1))
#!/usr/bin/env python3 n = int(eval(input())) t, a = list(map(int, input().split())) h = [abs(t - x * 0.006 - a) for x in map(int, input().split())] print((h.index(min(h)) + 1))
9
5
235
168
#!/usr/bin/env python3 import numpy as np n = int(eval(input())) t, a = list(map(int, input().split())) h = list(map(int, input().split())) a_t = [] for i in h: a_t.append(t - i * 0.006) print((np.abs(np.asarray(a_t) - a).argmin() + 1))
#!/usr/bin/env python3 n = int(eval(input())) t, a = list(map(int, input().split())) h = [abs(t - x * 0.006 - a) for x in map(int, input().split())] print((h.index(min(h)) + 1))
false
44.444444
[ "-import numpy as np", "-", "-h = list(map(int, input().split()))", "-a_t = []", "-for i in h:", "- a_t.append(t - i * 0.006)", "-print((np.abs(np.asarray(a_t) - a).argmin() + 1))", "+h = [abs(t - x * 0.006 - a) for x in map(int, input().split())]", "+print((h.index(min(h)) + 1))" ]
false
0.915126
0.047118
19.422193
[ "s448269978", "s580997934" ]
u298297089
p02948
python
s118079152
s640737495
687
475
35,784
27,428
Accepted
Accepted
30.86
from heapq import heappop, heappush n,m = list(map(int,input().split())) byte = {} for i in range(n): a,b = list(map(int,input().split())) if a not in byte: byte[a] = [] heappush(byte[a], [-b,a]) ans = 0 res = [] for i in range(1, m+1): if i in byte: heappush(res, heappop(byte[i])) if not res: continue b,a = heappop(res) ans -= b if byte[a]: heappush(res, heappop(byte[a])) print(ans)
from heapq import heappop, heappush n,m = list(map(int,input().split())) byte = {} for i in range(n): a,b = list(map(int,input().split())) if a > m: continue if a not in byte: byte[a] = [] heappush(byte[a], -b) ans = 0 res = [] for i in range(1, m+1): if i in byte: while byte[i]: heappush(res, heappop(byte[i])) if res: ans -= heappop(res) print(ans)
23
21
468
429
from heapq import heappop, heappush n, m = list(map(int, input().split())) byte = {} for i in range(n): a, b = list(map(int, input().split())) if a not in byte: byte[a] = [] heappush(byte[a], [-b, a]) ans = 0 res = [] for i in range(1, m + 1): if i in byte: heappush(res, heappop(byte[i])) if not res: continue b, a = heappop(res) ans -= b if byte[a]: heappush(res, heappop(byte[a])) print(ans)
from heapq import heappop, heappush n, m = list(map(int, input().split())) byte = {} for i in range(n): a, b = list(map(int, input().split())) if a > m: continue if a not in byte: byte[a] = [] heappush(byte[a], -b) ans = 0 res = [] for i in range(1, m + 1): if i in byte: while byte[i]: heappush(res, heappop(byte[i])) if res: ans -= heappop(res) print(ans)
false
8.695652
[ "+ if a > m:", "+ continue", "- heappush(byte[a], [-b, a])", "+ heappush(byte[a], -b)", "- heappush(res, heappop(byte[i]))", "- if not res:", "- continue", "- b, a = heappop(res)", "- ans -= b", "- if byte[a]:", "- heappush(res, heappop(byte[a]))", "+ while byte[i]:", "+ heappush(res, heappop(byte[i]))", "+ if res:", "+ ans -= heappop(res)" ]
false
0.070237
0.065029
1.080085
[ "s118079152", "s640737495" ]
u887207211
p03835
python
s387941242
s610259052
1,805
1,368
2,940
2,940
Accepted
Accepted
24.21
K, S = list(map(int,input().split())) cnt = 0 for i in range(K+1): for j in range(K+1): if(S-(i+j) <= K and S-(i+j) >= 0): cnt += 1 print(cnt)
K, S = list(map(int,input().split())) cnt = 0 for i in range(K+1): for j in range(K+1): if(0 <= S-i-j < K+1): cnt += 1 print(cnt)
8
7
156
141
K, S = list(map(int, input().split())) cnt = 0 for i in range(K + 1): for j in range(K + 1): if S - (i + j) <= K and S - (i + j) >= 0: cnt += 1 print(cnt)
K, S = list(map(int, input().split())) cnt = 0 for i in range(K + 1): for j in range(K + 1): if 0 <= S - i - j < K + 1: cnt += 1 print(cnt)
false
12.5
[ "- if S - (i + j) <= K and S - (i + j) >= 0:", "+ if 0 <= S - i - j < K + 1:" ]
false
0.087699
0.047572
1.843514
[ "s387941242", "s610259052" ]
u474561976
p02614
python
s338660566
s080479476
131
54
9,240
9,116
Accepted
Accepted
58.78
import io,sys,copy sys.setrecursionlimit(10**6) def main(): h,w,poi = list(map(int,input().split())) G = [] for _ in range(h): s = eval(input()) temp = [] for i in s: temp.append(i) G.append(temp) ans = 0 for i in range(0b1<<w): for j in range(0b1<<h): G_sub = copy.deepcopy(G) s = i k = 0 while s > 0: r = s%2 s = s//2 if r == 1: for y in range(h): G_sub[y][k] = "%" k+=1 s = j k = 0 while s > 0: r = s%2 s = s//2 if r == 1: for x in range(w): G_sub[k][x] = "%" k+=1 ct = 0 for g in G_sub: ct+=g.count("#") if ct == poi: ans+=1 print(ans) main()
def main2(): h,w,k = list(map(int,input().split())) G = [] for _ in range(h): c = list(eval(input())) G.append(c) ans = 0 for ib in range(1<<h): for jb in range(1<<w): ct = 0 for i in range(h): for j in range(w): if (ib>>i)&1 and (jb>>j)&1 and G[i][j]=="#": ct+=1 if ct == k: ans+=1 print(ans) main2()
46
21
1,061
489
import io, sys, copy sys.setrecursionlimit(10**6) def main(): h, w, poi = list(map(int, input().split())) G = [] for _ in range(h): s = eval(input()) temp = [] for i in s: temp.append(i) G.append(temp) ans = 0 for i in range(0b1 << w): for j in range(0b1 << h): G_sub = copy.deepcopy(G) s = i k = 0 while s > 0: r = s % 2 s = s // 2 if r == 1: for y in range(h): G_sub[y][k] = "%" k += 1 s = j k = 0 while s > 0: r = s % 2 s = s // 2 if r == 1: for x in range(w): G_sub[k][x] = "%" k += 1 ct = 0 for g in G_sub: ct += g.count("#") if ct == poi: ans += 1 print(ans) main()
def main2(): h, w, k = list(map(int, input().split())) G = [] for _ in range(h): c = list(eval(input())) G.append(c) ans = 0 for ib in range(1 << h): for jb in range(1 << w): ct = 0 for i in range(h): for j in range(w): if (ib >> i) & 1 and (jb >> j) & 1 and G[i][j] == "#": ct += 1 if ct == k: ans += 1 print(ans) main2()
false
54.347826
[ "-import io, sys, copy", "-", "-sys.setrecursionlimit(10**6)", "-", "-", "-def main():", "- h, w, poi = list(map(int, input().split()))", "+def main2():", "+ h, w, k = list(map(int, input().split()))", "- s = eval(input())", "- temp = []", "- for i in s:", "- temp.append(i)", "- G.append(temp)", "+ c = list(eval(input()))", "+ G.append(c)", "- for i in range(0b1 << w):", "- for j in range(0b1 << h):", "- G_sub = copy.deepcopy(G)", "- s = i", "- k = 0", "- while s > 0:", "- r = s % 2", "- s = s // 2", "- if r == 1:", "- for y in range(h):", "- G_sub[y][k] = \"%\"", "- k += 1", "- s = j", "- k = 0", "- while s > 0:", "- r = s % 2", "- s = s // 2", "- if r == 1:", "- for x in range(w):", "- G_sub[k][x] = \"%\"", "- k += 1", "+ for ib in range(1 << h):", "+ for jb in range(1 << w):", "- for g in G_sub:", "- ct += g.count(\"#\")", "- if ct == poi:", "+ for i in range(h):", "+ for j in range(w):", "+ if (ib >> i) & 1 and (jb >> j) & 1 and G[i][j] == \"#\":", "+ ct += 1", "+ if ct == k:", "-main()", "+main2()" ]
false
0.043407
0.036348
1.194217
[ "s338660566", "s080479476" ]
u562016607
p03026
python
s018942408
s788924767
357
312
50,136
49,240
Accepted
Accepted
12.61
from collections import deque N=int(eval(input())) A=[0 for i in range(N-1)] B=[0 for i in range(N-1)] G=[[] for i in range(N)] for i in range(N-1): a,b=list(map(int,input().split())) a-=1;b-=1 A[i],B[i]=a,b G[a].append(b) G[b].append(a) j=0 for i in range(N): if len(G[i])>len(G[j]): j=i c=sorted([int(i) for i in input().split()]) M=sum(c)-max(c) d=[-1 for i in range(N)] q=deque([j]) while(len(q)>0): r=q.popleft() d[r]=c.pop() for p in G[r]: if d[p]==-1: q.appendleft(p) print(M) print((" ".join([str(i) for i in d])))
from collections import deque N=int(eval(input())) G=[[] for i in range(N)] for i in range(N-1): a,b=list(map(int,input().split())) a-=1;b-=1 G[a].append(b) G[b].append(a) j=0 for i in range(N): if len(G[i])>len(G[j]): j=i c=sorted([int(i) for i in input().split()]) M=sum(c)-max(c) d=[-1 for i in range(N)] q=deque([j]) while(len(q)>0): r=q.popleft() d[r]=c.pop() for p in G[r]: if d[p]==-1: q.appendleft(p) print(M) print((" ".join([str(i) for i in d])))
27
24
599
526
from collections import deque N = int(eval(input())) A = [0 for i in range(N - 1)] B = [0 for i in range(N - 1)] G = [[] for i in range(N)] for i in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 A[i], B[i] = a, b G[a].append(b) G[b].append(a) j = 0 for i in range(N): if len(G[i]) > len(G[j]): j = i c = sorted([int(i) for i in input().split()]) M = sum(c) - max(c) d = [-1 for i in range(N)] q = deque([j]) while len(q) > 0: r = q.popleft() d[r] = c.pop() for p in G[r]: if d[p] == -1: q.appendleft(p) print(M) print((" ".join([str(i) for i in d])))
from collections import deque N = int(eval(input())) G = [[] for i in range(N)] for i in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) j = 0 for i in range(N): if len(G[i]) > len(G[j]): j = i c = sorted([int(i) for i in input().split()]) M = sum(c) - max(c) d = [-1 for i in range(N)] q = deque([j]) while len(q) > 0: r = q.popleft() d[r] = c.pop() for p in G[r]: if d[p] == -1: q.appendleft(p) print(M) print((" ".join([str(i) for i in d])))
false
11.111111
[ "-A = [0 for i in range(N - 1)]", "-B = [0 for i in range(N - 1)]", "- A[i], B[i] = a, b" ]
false
0.040886
0.041875
0.976387
[ "s018942408", "s788924767" ]
u054514819
p02722
python
s771816363
s737927073
289
186
3,956
65,508
Accepted
Accepted
35.64
from math import sqrt N = int(eval(input())) ans = 0 divisors = [] for i in range(2, int(sqrt(N))+1): if N%i==0: divisors.append(i) divisors.append(N//i) for d in set(divisors): i = 1 while N%(d**i)==0: i += 1 n = N//(d**(i-1)) if n%d==1: ans+=1 for i in range(2, int(sqrt(N))+1): if (N-1)%i==0: if i**2!=N-1: ans += 2 else: ans += 1 if N==2: print((1)) else: print((ans+2))
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] N = int(eval(input())) ans = len(make_divisors(N-1))-1 lis = make_divisors(N) for n in lis: G = N if n==1: continue while G%n==0: G //= n if G%n==1: ans += 1 print(ans)
28
28
498
661
from math import sqrt N = int(eval(input())) ans = 0 divisors = [] for i in range(2, int(sqrt(N)) + 1): if N % i == 0: divisors.append(i) divisors.append(N // i) for d in set(divisors): i = 1 while N % (d**i) == 0: i += 1 n = N // (d ** (i - 1)) if n % d == 1: ans += 1 for i in range(2, int(sqrt(N)) + 1): if (N - 1) % i == 0: if i**2 != N - 1: ans += 2 else: ans += 1 if N == 2: print((1)) else: print((ans + 2))
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) def make_divisors(n): lower_divisors, upper_divisors = [], [] i = 1 while i * i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n // i) i += 1 return lower_divisors + upper_divisors[::-1] N = int(eval(input())) ans = len(make_divisors(N - 1)) - 1 lis = make_divisors(N) for n in lis: G = N if n == 1: continue while G % n == 0: G //= n if G % n == 1: ans += 1 print(ans)
false
0
[ "-from math import sqrt", "+import sys", "+", "+", "+def input():", "+ return sys.stdin.readline().strip()", "+", "+", "+def mapint():", "+ return list(map(int, input().split()))", "+", "+", "+sys.setrecursionlimit(10**9)", "+", "+", "+def make_divisors(n):", "+ lower_divisors, upper_divisors = [], []", "+ i = 1", "+ while i * i <= n:", "+ if n % i == 0:", "+ lower_divisors.append(i)", "+ if i != n // i:", "+ upper_divisors.append(n // i)", "+ i += 1", "+ return lower_divisors + upper_divisors[::-1]", "+", "-ans = 0", "-divisors = []", "-for i in range(2, int(sqrt(N)) + 1):", "- if N % i == 0:", "- divisors.append(i)", "- divisors.append(N // i)", "-for d in set(divisors):", "- i = 1", "- while N % (d**i) == 0:", "- i += 1", "- n = N // (d ** (i - 1))", "- if n % d == 1:", "+ans = len(make_divisors(N - 1)) - 1", "+lis = make_divisors(N)", "+for n in lis:", "+ G = N", "+ if n == 1:", "+ continue", "+ while G % n == 0:", "+ G //= n", "+ if G % n == 1:", "-for i in range(2, int(sqrt(N)) + 1):", "- if (N - 1) % i == 0:", "- if i**2 != N - 1:", "- ans += 2", "- else:", "- ans += 1", "-if N == 2:", "- print((1))", "-else:", "- print((ans + 2))", "+print(ans)" ]
false
0.121291
0.10629
1.141126
[ "s771816363", "s737927073" ]
u919633157
p03524
python
s775357822
s600251992
26
18
3,444
3,188
Accepted
Accepted
30.77
# 2019/09/27 from collections import Counter s=eval(input()) n=len(s) c=Counter(s) res=list(c.values()) if len(res)<3: if n==len(res): print('YES') else:print('NO') exit() if max(res)-min(res)>1 : print('NO') else: print('YES')
s=eval(input()) a=s.count('a') b=s.count('b') c=s.count('c') print(('YES' if max(a,b,c)-min(a,b,c)<=1 else 'NO'))
19
6
266
111
# 2019/09/27 from collections import Counter s = eval(input()) n = len(s) c = Counter(s) res = list(c.values()) if len(res) < 3: if n == len(res): print("YES") else: print("NO") exit() if max(res) - min(res) > 1: print("NO") else: print("YES")
s = eval(input()) a = s.count("a") b = s.count("b") c = s.count("c") print(("YES" if max(a, b, c) - min(a, b, c) <= 1 else "NO"))
false
68.421053
[ "-# 2019/09/27", "-from collections import Counter", "-", "-n = len(s)", "-c = Counter(s)", "-res = list(c.values())", "-if len(res) < 3:", "- if n == len(res):", "- print(\"YES\")", "- else:", "- print(\"NO\")", "- exit()", "-if max(res) - min(res) > 1:", "- print(\"NO\")", "-else:", "- print(\"YES\")", "+a = s.count(\"a\")", "+b = s.count(\"b\")", "+c = s.count(\"c\")", "+print((\"YES\" if max(a, b, c) - min(a, b, c) <= 1 else \"NO\"))" ]
false
0.043353
0.034021
1.274272
[ "s775357822", "s600251992" ]
u644907318
p02888
python
s796391884
s586447063
638
361
75,288
74,612
Accepted
Accepted
43.42
from bisect import bisect_right,bisect_left N = int(eval(input())) L = sorted(list(map(int,input().split()))) cnt = 0 for i in range(N-1): for j in range(i+1,N): a = L[i] b = L[j] indU = bisect_left(L,a+b) indL = bisect_right(L,b-a) if j<indU and i>= indL: cnt += indU-indL-2 elif indL<=i<indU and j>=indU or i<indL and indL<=j<indU: cnt += indU-indL-1 elif j<indL or i>=indU: cnt += indU-indL print((cnt//3))
from bisect import bisect_left N = int(eval(input())) L = sorted(list(map(int,input().split()))) cnt = 0 for i in range(N-2): for j in range(i+1,N-1): a = L[i] b = L[j] ind = bisect_left(L,a+b) cnt += ind-j-1 print(cnt)
17
11
513
259
from bisect import bisect_right, bisect_left N = int(eval(input())) L = sorted(list(map(int, input().split()))) cnt = 0 for i in range(N - 1): for j in range(i + 1, N): a = L[i] b = L[j] indU = bisect_left(L, a + b) indL = bisect_right(L, b - a) if j < indU and i >= indL: cnt += indU - indL - 2 elif indL <= i < indU and j >= indU or i < indL and indL <= j < indU: cnt += indU - indL - 1 elif j < indL or i >= indU: cnt += indU - indL print((cnt // 3))
from bisect import bisect_left N = int(eval(input())) L = sorted(list(map(int, input().split()))) cnt = 0 for i in range(N - 2): for j in range(i + 1, N - 1): a = L[i] b = L[j] ind = bisect_left(L, a + b) cnt += ind - j - 1 print(cnt)
false
35.294118
[ "-from bisect import bisect_right, bisect_left", "+from bisect import bisect_left", "-for i in range(N - 1):", "- for j in range(i + 1, N):", "+for i in range(N - 2):", "+ for j in range(i + 1, N - 1):", "- indU = bisect_left(L, a + b)", "- indL = bisect_right(L, b - a)", "- if j < indU and i >= indL:", "- cnt += indU - indL - 2", "- elif indL <= i < indU and j >= indU or i < indL and indL <= j < indU:", "- cnt += indU - indL - 1", "- elif j < indL or i >= indU:", "- cnt += indU - indL", "-print((cnt // 3))", "+ ind = bisect_left(L, a + b)", "+ cnt += ind - j - 1", "+print(cnt)" ]
false
0.035542
0.047424
0.749455
[ "s796391884", "s586447063" ]
u842964692
p02781
python
s898643000
s580909728
1,157
22
3,064
3,188
Accepted
Accepted
98.1
N=eval(input()) K=int(eval(input())) def rec(N,K): if K==0: return 1#N以下の数で、0以外の数が0、すなわち残りの桁が全て0になるパターン if len(N)<K: return 0 lsb=int(N[-1]) if len(N)==1: return lsb return rec(N[:-1],K-1)*(lsb)+rec(str(int(N[:-1])-1),K-1)*(9-lsb)+rec(N[:-1],K) print((rec(N,K)))
N=eval(input()) K=int(eval(input())) dp=[[[0 for _ in range(K+2)] for _ in range(2)] for _ in range(len(N)+1)] dp[0][0][0]=1 for i in range(len(N)): for smaller in range(2): for j in range(K+1): for x in range(10 if smaller==1 else int(N[i])+1): dp[i+1][smaller or (x < int(N[i]))][j+1 if x!=0 else j]+=dp[i][smaller][j] print((dp[len(N)][1][K]+dp[len(N)][0][K]))
18
13
326
404
N = eval(input()) K = int(eval(input())) def rec(N, K): if K == 0: return 1 # N以下の数で、0以外の数が0、すなわち残りの桁が全て0になるパターン if len(N) < K: return 0 lsb = int(N[-1]) if len(N) == 1: return lsb return ( rec(N[:-1], K - 1) * (lsb) + rec(str(int(N[:-1]) - 1), K - 1) * (9 - lsb) + rec(N[:-1], K) ) print((rec(N, K)))
N = eval(input()) K = int(eval(input())) dp = [[[0 for _ in range(K + 2)] for _ in range(2)] for _ in range(len(N) + 1)] dp[0][0][0] = 1 for i in range(len(N)): for smaller in range(2): for j in range(K + 1): for x in range(10 if smaller == 1 else int(N[i]) + 1): dp[i + 1][smaller or (x < int(N[i]))][j + 1 if x != 0 else j] += dp[i][ smaller ][j] print((dp[len(N)][1][K] + dp[len(N)][0][K]))
false
27.777778
[ "-", "-", "-def rec(N, K):", "- if K == 0:", "- return 1 # N以下の数で、0以外の数が0、すなわち残りの桁が全て0になるパターン", "- if len(N) < K:", "- return 0", "- lsb = int(N[-1])", "- if len(N) == 1:", "- return lsb", "- return (", "- rec(N[:-1], K - 1) * (lsb)", "- + rec(str(int(N[:-1]) - 1), K - 1) * (9 - lsb)", "- + rec(N[:-1], K)", "- )", "-", "-", "-print((rec(N, K)))", "+dp = [[[0 for _ in range(K + 2)] for _ in range(2)] for _ in range(len(N) + 1)]", "+dp[0][0][0] = 1", "+for i in range(len(N)):", "+ for smaller in range(2):", "+ for j in range(K + 1):", "+ for x in range(10 if smaller == 1 else int(N[i]) + 1):", "+ dp[i + 1][smaller or (x < int(N[i]))][j + 1 if x != 0 else j] += dp[i][", "+ smaller", "+ ][j]", "+print((dp[len(N)][1][K] + dp[len(N)][0][K]))" ]
false
0.104919
0.050022
2.097448
[ "s898643000", "s580909728" ]
u936985471
p02813
python
s014666279
s816401791
265
37
6,244
9,084
Accepted
Accepted
86.04
N=int(eval(input())) P=list(map(int,input().split())) ps="" for i in range(N): ps+=str(P[i]) Q=list(map(int,input().split())) qs="" for i in range(N): qs+=str(Q[i]) stack=[] stack.append("") res=[] while stack: d=stack.pop() if len(d)==N: res.append(d) continue for i in range(1,N+1): if str(i) not in d: stack.append(d+str(i)) res=res[::-1] a=0 b=0 for i in range(len(res)): if res[i]==ps: a=i+1 if res[i]==qs: b=i+1 print((abs(a-b)))
import sys readline = sys.stdin.readline N = int(readline()) P = tuple(map(int,readline().split())) Q = tuple(map(int,readline().split())) import itertools a = 0 b = 0 cnt = 0 for perm in itertools.permutations(list(range(1, N + 1))): cnt += 1 if perm == P: a = cnt if perm == Q: b = cnt print((abs(a - b)))
32
19
504
342
N = int(eval(input())) P = list(map(int, input().split())) ps = "" for i in range(N): ps += str(P[i]) Q = list(map(int, input().split())) qs = "" for i in range(N): qs += str(Q[i]) stack = [] stack.append("") res = [] while stack: d = stack.pop() if len(d) == N: res.append(d) continue for i in range(1, N + 1): if str(i) not in d: stack.append(d + str(i)) res = res[::-1] a = 0 b = 0 for i in range(len(res)): if res[i] == ps: a = i + 1 if res[i] == qs: b = i + 1 print((abs(a - b)))
import sys readline = sys.stdin.readline N = int(readline()) P = tuple(map(int, readline().split())) Q = tuple(map(int, readline().split())) import itertools a = 0 b = 0 cnt = 0 for perm in itertools.permutations(list(range(1, N + 1))): cnt += 1 if perm == P: a = cnt if perm == Q: b = cnt print((abs(a - b)))
false
40.625
[ "-N = int(eval(input()))", "-P = list(map(int, input().split()))", "-ps = \"\"", "-for i in range(N):", "- ps += str(P[i])", "-Q = list(map(int, input().split()))", "-qs = \"\"", "-for i in range(N):", "- qs += str(Q[i])", "-stack = []", "-stack.append(\"\")", "-res = []", "-while stack:", "- d = stack.pop()", "- if len(d) == N:", "- res.append(d)", "- continue", "- for i in range(1, N + 1):", "- if str(i) not in d:", "- stack.append(d + str(i))", "-res = res[::-1]", "+import sys", "+", "+readline = sys.stdin.readline", "+N = int(readline())", "+P = tuple(map(int, readline().split()))", "+Q = tuple(map(int, readline().split()))", "+import itertools", "+", "-for i in range(len(res)):", "- if res[i] == ps:", "- a = i + 1", "- if res[i] == qs:", "- b = i + 1", "+cnt = 0", "+for perm in itertools.permutations(list(range(1, N + 1))):", "+ cnt += 1", "+ if perm == P:", "+ a = cnt", "+ if perm == Q:", "+ b = cnt" ]
false
0.039364
0.056655
0.694801
[ "s014666279", "s816401791" ]
u496821919
p02607
python
s891999270
s386076496
27
22
9,108
8,996
Accepted
Accepted
18.52
n = int(eval(input())) A = list(map(int,input().split())) ans = 0 for i in range(n): if i %2 == 1: continue if A[i] % 2 == 1: ans += 1 print(ans)
n = eval(input()) ans = 0 for i,j in enumerate(map(int,input().split())): ans += (~i&1 and j&1) print(ans)
9
5
171
108
n = int(eval(input())) A = list(map(int, input().split())) ans = 0 for i in range(n): if i % 2 == 1: continue if A[i] % 2 == 1: ans += 1 print(ans)
n = eval(input()) ans = 0 for i, j in enumerate(map(int, input().split())): ans += ~i & 1 and j & 1 print(ans)
false
44.444444
[ "-n = int(eval(input()))", "-A = list(map(int, input().split()))", "+n = eval(input())", "-for i in range(n):", "- if i % 2 == 1:", "- continue", "- if A[i] % 2 == 1:", "- ans += 1", "+for i, j in enumerate(map(int, input().split())):", "+ ans += ~i & 1 and j & 1" ]
false
0.070083
0.070041
1.000605
[ "s891999270", "s386076496" ]
u008079810
p02698
python
s169861260
s832200024
1,527
1,270
239,368
78,108
Accepted
Accepted
16.83
import bisect import sys sys.setrecursionlimit(10**7) def dfs(v): pos=bisect.bisect_left(dp,arr[v]) changes.append((pos,dp[pos])) dp[pos]=arr[v] ans[v]=bisect.bisect_left(dp,10**18) for u in g[v]: if checked[u]==0: checked[u]=1 dfs(u) pos,val=changes.pop() dp[pos]=val n=int(eval(input())) arr=[0]+list(map(int,input().split())) g=[[] for _ in range(n+1)] for _ in range(n-1): a,b=list(map(int,input().split())) g[a].append(b) g[b].append(a) ans=[0]*(n+1) checked=[0]*(n+1) checked[1]=1 dp=[10**18 for _ in range(n+1)] changes=[] dfs(1) for i in range(1,n+1): print((ans[i]))
from collections import deque import bisect N=int(eval(input())) A=list(map(int,input().split())) ans=[0]*N Edge=[[] for _ in range(N)] loute=[str(0)]*N for i in range(N-1): u,v=list(map(int,input().split())) Edge[u-1].append(v-1) Edge[v-1].append(u-1) tmp=deque(str(0)) CHN=deque() LIS=[10**18]*N label=[False]*N while tmp: T0=int(tmp[-1]) if label[T0]: tmp.pop() pos,Val=CHN.pop() LIS[pos]=Val continue pos=bisect.bisect_left(LIS,A[T0]) CHN.append((pos,LIS[pos])) LIS[pos]=A[T0] ans[T0]=bisect.bisect_left(LIS,10**18) if Edge[T0]: for i in Edge[T0]: if label[i]==False: tmp.append(i) label[T0]=True else: label[T0]=True for i in range(N): print((ans[i]))
32
40
671
824
import bisect import sys sys.setrecursionlimit(10**7) def dfs(v): pos = bisect.bisect_left(dp, arr[v]) changes.append((pos, dp[pos])) dp[pos] = arr[v] ans[v] = bisect.bisect_left(dp, 10**18) for u in g[v]: if checked[u] == 0: checked[u] = 1 dfs(u) pos, val = changes.pop() dp[pos] = val n = int(eval(input())) arr = [0] + list(map(int, input().split())) g = [[] for _ in range(n + 1)] for _ in range(n - 1): a, b = list(map(int, input().split())) g[a].append(b) g[b].append(a) ans = [0] * (n + 1) checked = [0] * (n + 1) checked[1] = 1 dp = [10**18 for _ in range(n + 1)] changes = [] dfs(1) for i in range(1, n + 1): print((ans[i]))
from collections import deque import bisect N = int(eval(input())) A = list(map(int, input().split())) ans = [0] * N Edge = [[] for _ in range(N)] loute = [str(0)] * N for i in range(N - 1): u, v = list(map(int, input().split())) Edge[u - 1].append(v - 1) Edge[v - 1].append(u - 1) tmp = deque(str(0)) CHN = deque() LIS = [10**18] * N label = [False] * N while tmp: T0 = int(tmp[-1]) if label[T0]: tmp.pop() pos, Val = CHN.pop() LIS[pos] = Val continue pos = bisect.bisect_left(LIS, A[T0]) CHN.append((pos, LIS[pos])) LIS[pos] = A[T0] ans[T0] = bisect.bisect_left(LIS, 10**18) if Edge[T0]: for i in Edge[T0]: if label[i] == False: tmp.append(i) label[T0] = True else: label[T0] = True for i in range(N): print((ans[i]))
false
20
[ "+from collections import deque", "-import sys", "-sys.setrecursionlimit(10**7)", "-", "-", "-def dfs(v):", "- pos = bisect.bisect_left(dp, arr[v])", "- changes.append((pos, dp[pos]))", "- dp[pos] = arr[v]", "- ans[v] = bisect.bisect_left(dp, 10**18)", "- for u in g[v]:", "- if checked[u] == 0:", "- checked[u] = 1", "- dfs(u)", "- pos, val = changes.pop()", "- dp[pos] = val", "-", "-", "-n = int(eval(input()))", "-arr = [0] + list(map(int, input().split()))", "-g = [[] for _ in range(n + 1)]", "-for _ in range(n - 1):", "- a, b = list(map(int, input().split()))", "- g[a].append(b)", "- g[b].append(a)", "-ans = [0] * (n + 1)", "-checked = [0] * (n + 1)", "-checked[1] = 1", "-dp = [10**18 for _ in range(n + 1)]", "-changes = []", "-dfs(1)", "-for i in range(1, n + 1):", "+N = int(eval(input()))", "+A = list(map(int, input().split()))", "+ans = [0] * N", "+Edge = [[] for _ in range(N)]", "+loute = [str(0)] * N", "+for i in range(N - 1):", "+ u, v = list(map(int, input().split()))", "+ Edge[u - 1].append(v - 1)", "+ Edge[v - 1].append(u - 1)", "+tmp = deque(str(0))", "+CHN = deque()", "+LIS = [10**18] * N", "+label = [False] * N", "+while tmp:", "+ T0 = int(tmp[-1])", "+ if label[T0]:", "+ tmp.pop()", "+ pos, Val = CHN.pop()", "+ LIS[pos] = Val", "+ continue", "+ pos = bisect.bisect_left(LIS, A[T0])", "+ CHN.append((pos, LIS[pos]))", "+ LIS[pos] = A[T0]", "+ ans[T0] = bisect.bisect_left(LIS, 10**18)", "+ if Edge[T0]:", "+ for i in Edge[T0]:", "+ if label[i] == False:", "+ tmp.append(i)", "+ label[T0] = True", "+ else:", "+ label[T0] = True", "+for i in range(N):" ]
false
0.007497
0.042064
0.178218
[ "s169861260", "s832200024" ]
u312025627
p02864
python
s086040081
s194656253
345
304
42,460
42,216
Accepted
Accepted
11.88
def main(): import sys input = sys.stdin.buffer.readline N, K = (int(i) for i in input().split()) H = [0] + [int(i) for i in input().split()] if N == K: return print(0) elif K == 0: ans = 0 for i in range(N): ans += max(H[i+1] - H[i], 0) return print(ans) dp = [[10**10]*(N-K+1) for i in range(N+1)] dp[0][0] = 0 for i, h in enumerate(H): if i == 0: continue dp[i][1] = h for i in range(1, N+1): for j in range(1, N-K+1): for x in range(1, i): dp[i][j] = min(dp[i][j], dp[x][j-1] + max(0, H[i] - H[x])) ans = 10**10 for i in range(N+1): # print(dp[i]) ans = min(ans, dp[i][N-K]) print(ans) if __name__ == '__main__': main()
def main(): N, K = (int(i) for i in input().split()) H = [0] + [int(i) for i in input().split()] # 1-indexed if N == K: return print(0) elif K == 0: ans = 0 for i in range(N): ans += max(H[i+1] - H[i], 0) return print(ans) dp = [[10**12]*(N-K+1) for _ in range(N+1)] for x in range(N+1): dp[x][1] = H[x] for y in range(2, N-K+1): for x in range(N+1): for i in range(1, x): dp[x][y] = min(dp[x][y], dp[i][y-1] + max(0, H[x] - H[i])) ans = dp[0][N-K] for i in range(1, N+1): ans = min(ans, dp[i][N-K]) print(ans) if __name__ == '__main__': main()
32
29
838
722
def main(): import sys input = sys.stdin.buffer.readline N, K = (int(i) for i in input().split()) H = [0] + [int(i) for i in input().split()] if N == K: return print(0) elif K == 0: ans = 0 for i in range(N): ans += max(H[i + 1] - H[i], 0) return print(ans) dp = [[10**10] * (N - K + 1) for i in range(N + 1)] dp[0][0] = 0 for i, h in enumerate(H): if i == 0: continue dp[i][1] = h for i in range(1, N + 1): for j in range(1, N - K + 1): for x in range(1, i): dp[i][j] = min(dp[i][j], dp[x][j - 1] + max(0, H[i] - H[x])) ans = 10**10 for i in range(N + 1): # print(dp[i]) ans = min(ans, dp[i][N - K]) print(ans) if __name__ == "__main__": main()
def main(): N, K = (int(i) for i in input().split()) H = [0] + [int(i) for i in input().split()] # 1-indexed if N == K: return print(0) elif K == 0: ans = 0 for i in range(N): ans += max(H[i + 1] - H[i], 0) return print(ans) dp = [[10**12] * (N - K + 1) for _ in range(N + 1)] for x in range(N + 1): dp[x][1] = H[x] for y in range(2, N - K + 1): for x in range(N + 1): for i in range(1, x): dp[x][y] = min(dp[x][y], dp[i][y - 1] + max(0, H[x] - H[i])) ans = dp[0][N - K] for i in range(1, N + 1): ans = min(ans, dp[i][N - K]) print(ans) if __name__ == "__main__": main()
false
9.375
[ "- import sys", "-", "- input = sys.stdin.buffer.readline", "+ # 1-indexed", "- dp = [[10**10] * (N - K + 1) for i in range(N + 1)]", "- dp[0][0] = 0", "- for i, h in enumerate(H):", "- if i == 0:", "- continue", "- dp[i][1] = h", "+ dp = [[10**12] * (N - K + 1) for _ in range(N + 1)]", "+ for x in range(N + 1):", "+ dp[x][1] = H[x]", "+ for y in range(2, N - K + 1):", "+ for x in range(N + 1):", "+ for i in range(1, x):", "+ dp[x][y] = min(dp[x][y], dp[i][y - 1] + max(0, H[x] - H[i]))", "+ ans = dp[0][N - K]", "- for j in range(1, N - K + 1):", "- for x in range(1, i):", "- dp[i][j] = min(dp[i][j], dp[x][j - 1] + max(0, H[i] - H[x]))", "- ans = 10**10", "- for i in range(N + 1):", "- # print(dp[i])" ]
false
0.033723
0.05211
0.647156
[ "s086040081", "s194656253" ]
u966695411
p04045
python
s677247769
s195578349
911
94
3,700
2,940
Accepted
Accepted
89.68
N, L = list(map(int, input().split())) D = input().split() ans = N while 1: s = str(ans) f = 1 for i in D: if i in s : f = 0 if f : break ans += 1 print(ans)
def main(): N, L = list(map(int, input().split())) D = input().split() ans = N while 1: s = str(ans) if not [1 for i in D if i in s] : break ans += 1 print(ans) if __name__ == '__main__': main()
11
11
189
246
N, L = list(map(int, input().split())) D = input().split() ans = N while 1: s = str(ans) f = 1 for i in D: if i in s: f = 0 if f: break ans += 1 print(ans)
def main(): N, L = list(map(int, input().split())) D = input().split() ans = N while 1: s = str(ans) if not [1 for i in D if i in s]: break ans += 1 print(ans) if __name__ == "__main__": main()
false
0
[ "-N, L = list(map(int, input().split()))", "-D = input().split()", "-ans = N", "-while 1:", "- s = str(ans)", "- f = 1", "- for i in D:", "- if i in s:", "- f = 0", "- if f:", "- break", "- ans += 1", "-print(ans)", "+def main():", "+ N, L = list(map(int, input().split()))", "+ D = input().split()", "+ ans = N", "+ while 1:", "+ s = str(ans)", "+ if not [1 for i in D if i in s]:", "+ break", "+ ans += 1", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.123678
0.119821
1.032189
[ "s677247769", "s195578349" ]
u644907318
p03776
python
s251557662
s519404697
189
69
38,768
69,848
Accepted
Accepted
63.49
from math import factorial N,A,B = list(map(int,input().split())) V = sorted(list(map(int,input().split())),reverse=True) C = {} for i in range(N): if V[i] not in C: C[V[i]] = 0 C[V[i]] += 1 v = V[A-1] avg = sum(V[:A])/A print(avg) cnt = V[:A].count(v) if cnt<A: tot = factorial(C[v])//factorial(cnt)//factorial(C[v]-cnt) else:#cnt==A tot = 0 for j in range(A,min(B,C[v])+1): tot += factorial(C[v])//factorial(j)//factorial(C[v]-j) print(tot)
memo = {} def f(m,k): if k>m: return 0 if m==1: return 1 if k==0: return 1 if k==1: return m if (m,k) in memo: return memo[(m,k)] memo[(m,k)]=f(m-1,k-1)+f(m-1,k) return memo[(m,k)] N,A,B = list(map(int,input().split())) V = sorted(list(map(int,input().split())),reverse=True) amin = 10**15+10 for i in range(A): amin = min(amin,V[i]) av = sum(V[:A])/A cnt = 0 for i in range(N): if V[i]==amin: cnt += 1 cntB = 0 for i in range(B): if V[i]==amin: cntB += 1 cntA = 0 for i in range(A): if V[i]==amin: cntA += 1 print(av) if V[0]>amin: print((f(cnt,cntA))) else: tot = 0 for i in range(cntA,cntB+1): tot += f(cnt,i) print(tot)
19
41
490
788
from math import factorial N, A, B = list(map(int, input().split())) V = sorted(list(map(int, input().split())), reverse=True) C = {} for i in range(N): if V[i] not in C: C[V[i]] = 0 C[V[i]] += 1 v = V[A - 1] avg = sum(V[:A]) / A print(avg) cnt = V[:A].count(v) if cnt < A: tot = factorial(C[v]) // factorial(cnt) // factorial(C[v] - cnt) else: # cnt==A tot = 0 for j in range(A, min(B, C[v]) + 1): tot += factorial(C[v]) // factorial(j) // factorial(C[v] - j) print(tot)
memo = {} def f(m, k): if k > m: return 0 if m == 1: return 1 if k == 0: return 1 if k == 1: return m if (m, k) in memo: return memo[(m, k)] memo[(m, k)] = f(m - 1, k - 1) + f(m - 1, k) return memo[(m, k)] N, A, B = list(map(int, input().split())) V = sorted(list(map(int, input().split())), reverse=True) amin = 10**15 + 10 for i in range(A): amin = min(amin, V[i]) av = sum(V[:A]) / A cnt = 0 for i in range(N): if V[i] == amin: cnt += 1 cntB = 0 for i in range(B): if V[i] == amin: cntB += 1 cntA = 0 for i in range(A): if V[i] == amin: cntA += 1 print(av) if V[0] > amin: print((f(cnt, cntA))) else: tot = 0 for i in range(cntA, cntB + 1): tot += f(cnt, i) print(tot)
false
53.658537
[ "-from math import factorial", "+memo = {}", "+", "+", "+def f(m, k):", "+ if k > m:", "+ return 0", "+ if m == 1:", "+ return 1", "+ if k == 0:", "+ return 1", "+ if k == 1:", "+ return m", "+ if (m, k) in memo:", "+ return memo[(m, k)]", "+ memo[(m, k)] = f(m - 1, k - 1) + f(m - 1, k)", "+ return memo[(m, k)]", "+", "-C = {}", "+amin = 10**15 + 10", "+for i in range(A):", "+ amin = min(amin, V[i])", "+av = sum(V[:A]) / A", "+cnt = 0", "- if V[i] not in C:", "- C[V[i]] = 0", "- C[V[i]] += 1", "-v = V[A - 1]", "-avg = sum(V[:A]) / A", "-print(avg)", "-cnt = V[:A].count(v)", "-if cnt < A:", "- tot = factorial(C[v]) // factorial(cnt) // factorial(C[v] - cnt)", "-else: # cnt==A", "+ if V[i] == amin:", "+ cnt += 1", "+cntB = 0", "+for i in range(B):", "+ if V[i] == amin:", "+ cntB += 1", "+cntA = 0", "+for i in range(A):", "+ if V[i] == amin:", "+ cntA += 1", "+print(av)", "+if V[0] > amin:", "+ print((f(cnt, cntA)))", "+else:", "- for j in range(A, min(B, C[v]) + 1):", "- tot += factorial(C[v]) // factorial(j) // factorial(C[v] - j)", "-print(tot)", "+ for i in range(cntA, cntB + 1):", "+ tot += f(cnt, i)", "+ print(tot)" ]
false
0.092722
0.041907
2.212562
[ "s251557662", "s519404697" ]
u631277801
p04013
python
s869774719
s956072730
176
37
5,744
3,572
Accepted
Accepted
78.98
N,A = list(map(int,input().split())) X = list(map(int, input().split())) for i in range(N): X[i] -= A dp = [[0 for _ in range(100*N+1)] for _ in range(N+1)] dp[0][50*N] = 1 for i in range(1,N+1): for summ in range(2*50*N+1): if 0 <= summ-X[i-1] <= 100*N: dp[i][summ] = dp[i-1][summ] + dp[i-1][summ-X[i-1]] else: dp[i][summ] = dp[i-1][summ] print((dp[N][50*N]-1))
from collections import Counter N,A = list(map(int,input().split())) X = list(map(int, input().split())) X = [X[i] - A for i in range(N)] sums = Counter([0, X[0]]) for x in X[1:]: c = Counter() for k,v in list(sums.items()): c[x+k] = v sums += c print((sums[0]-1))
17
16
434
294
N, A = list(map(int, input().split())) X = list(map(int, input().split())) for i in range(N): X[i] -= A dp = [[0 for _ in range(100 * N + 1)] for _ in range(N + 1)] dp[0][50 * N] = 1 for i in range(1, N + 1): for summ in range(2 * 50 * N + 1): if 0 <= summ - X[i - 1] <= 100 * N: dp[i][summ] = dp[i - 1][summ] + dp[i - 1][summ - X[i - 1]] else: dp[i][summ] = dp[i - 1][summ] print((dp[N][50 * N] - 1))
from collections import Counter N, A = list(map(int, input().split())) X = list(map(int, input().split())) X = [X[i] - A for i in range(N)] sums = Counter([0, X[0]]) for x in X[1:]: c = Counter() for k, v in list(sums.items()): c[x + k] = v sums += c print((sums[0] - 1))
false
5.882353
[ "+from collections import Counter", "+", "-for i in range(N):", "- X[i] -= A", "-dp = [[0 for _ in range(100 * N + 1)] for _ in range(N + 1)]", "-dp[0][50 * N] = 1", "-for i in range(1, N + 1):", "- for summ in range(2 * 50 * N + 1):", "- if 0 <= summ - X[i - 1] <= 100 * N:", "- dp[i][summ] = dp[i - 1][summ] + dp[i - 1][summ - X[i - 1]]", "- else:", "- dp[i][summ] = dp[i - 1][summ]", "-print((dp[N][50 * N] - 1))", "+X = [X[i] - A for i in range(N)]", "+sums = Counter([0, X[0]])", "+for x in X[1:]:", "+ c = Counter()", "+ for k, v in list(sums.items()):", "+ c[x + k] = v", "+ sums += c", "+print((sums[0] - 1))" ]
false
0.037282
0.035958
1.036835
[ "s869774719", "s956072730" ]
u489124637
p02720
python
s674398775
s902379817
303
192
70,364
84,360
Accepted
Accepted
36.63
from collections import deque K = int(eval(input())) que = deque(["1","2","3","4","5","6","7","8","9"]) cnt = 0 while cnt < K: q = que.popleft() a = int(q[-1]) q = int(q) cnt += 1 if a == 0: que.append(str(q*10+a)) que.append(str(q*10+a+1)) elif a == 9: que.append(str(q*10+a-1)) que.append(str(q*10+a)) else: que.append(str(q*10+a-1)) que.append(str(q*10+a)) que.append(str(q*10+a+1)) ans = q print(ans)
import sys sys.setrecursionlimit(10**9) k = int(eval(input())) l = 10 A = [str(i+1) for i in range(9)] B = ["0"] + A ans = [] #print(l) def dfs(num,l): if len(num) >= l: ans.append(int(num)) else: ans.append(int(num)) for i in B: if abs(int(num[-1])-int(i)) < 2: dfs(num + i,l) if k <= 9: print(k) else: for i in A: dfs(i,l) ans = sorted(ans) #print(ans) print((ans[k-1]))
25
26
515
479
from collections import deque K = int(eval(input())) que = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"]) cnt = 0 while cnt < K: q = que.popleft() a = int(q[-1]) q = int(q) cnt += 1 if a == 0: que.append(str(q * 10 + a)) que.append(str(q * 10 + a + 1)) elif a == 9: que.append(str(q * 10 + a - 1)) que.append(str(q * 10 + a)) else: que.append(str(q * 10 + a - 1)) que.append(str(q * 10 + a)) que.append(str(q * 10 + a + 1)) ans = q print(ans)
import sys sys.setrecursionlimit(10**9) k = int(eval(input())) l = 10 A = [str(i + 1) for i in range(9)] B = ["0"] + A ans = [] # print(l) def dfs(num, l): if len(num) >= l: ans.append(int(num)) else: ans.append(int(num)) for i in B: if abs(int(num[-1]) - int(i)) < 2: dfs(num + i, l) if k <= 9: print(k) else: for i in A: dfs(i, l) ans = sorted(ans) # print(ans) print((ans[k - 1]))
false
3.846154
[ "-from collections import deque", "+import sys", "-K = int(eval(input()))", "-que = deque([\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"])", "-cnt = 0", "-while cnt < K:", "- q = que.popleft()", "- a = int(q[-1])", "- q = int(q)", "- cnt += 1", "- if a == 0:", "- que.append(str(q * 10 + a))", "- que.append(str(q * 10 + a + 1))", "- elif a == 9:", "- que.append(str(q * 10 + a - 1))", "- que.append(str(q * 10 + a))", "+sys.setrecursionlimit(10**9)", "+k = int(eval(input()))", "+l = 10", "+A = [str(i + 1) for i in range(9)]", "+B = [\"0\"] + A", "+ans = []", "+# print(l)", "+def dfs(num, l):", "+ if len(num) >= l:", "+ ans.append(int(num))", "- que.append(str(q * 10 + a - 1))", "- que.append(str(q * 10 + a))", "- que.append(str(q * 10 + a + 1))", "- ans = q", "-print(ans)", "+ ans.append(int(num))", "+ for i in B:", "+ if abs(int(num[-1]) - int(i)) < 2:", "+ dfs(num + i, l)", "+", "+", "+if k <= 9:", "+ print(k)", "+else:", "+ for i in A:", "+ dfs(i, l)", "+ ans = sorted(ans)", "+ # print(ans)", "+ print((ans[k - 1]))" ]
false
0.06195
0.604382
0.102501
[ "s674398775", "s902379817" ]
u392319141
p02644
python
s221005672
s860803839
2,267
1,817
38,468
36,712
Accepted
Accepted
19.85
from collections import deque import sys input = sys.stdin.buffer.readline H, W, K = list(map(int, input().split())) sx, sy, tx, ty = [int(a) - 1 for a in input().split()] INF = 10**18 A = [input().decode() for _ in range(H)] minDist = [[INF] * W for _ in range(H)] minDist[sx][sy] = 0 que = deque([(0, sx, sy)]) while que: dist, nx, ny = que.popleft() for i in range(1, K + 1): if nx + i >= H: break if minDist[nx + i][ny] <= dist or A[nx + i][ny] == '@': break if minDist[nx + i][ny] > dist + 1: minDist[nx + i][ny] = dist + 1 que.append((dist + 1, nx + i, ny)) for i in range(1, K + 1): if nx - i < 0: break if minDist[nx - i][ny] <= dist or A[nx - i][ny] == '@': break if minDist[nx - i][ny] > dist + 1: minDist[nx - i][ny] = dist + 1 que.append((dist + 1, nx - i, ny)) for i in range(1, K + 1): if ny + i >= W: break if minDist[nx][ny + i] <= dist or A[nx][ny + i] == '@': break if minDist[nx][ny + i] > dist + 1: minDist[nx][ny + i] = dist + 1 que.append((dist + 1, nx, ny + i)) for i in range(1, K + 1): if ny - i < 0: break if minDist[nx][ny - i] <= dist or A[nx][ny - i] == '@': break if minDist[nx][ny - i] > dist + 1: minDist[nx][ny - i] = dist + 1 que.append((dist + 1, nx, ny - i)) ans = minDist[tx][ty] print((ans if ans < INF else -1))
from collections import deque H, W, K = list(map(int, input().split())) sx, sy, tx, ty = [int(a) - 1 for a in input().split()] INF = 10**18 A = [eval(input()) for _ in range(H)] minDist = [[INF] * W for _ in range(H)] minDist[sx][sy] = 0 que = deque([(0, sx, sy)]) while que: dist, nx, ny = que.popleft() if nx == tx and ny == ty: break for i in range(1, K + 1): if nx + i >= H: break if minDist[nx + i][ny] <= dist or A[nx + i][ny] == '@': break if minDist[nx + i][ny] > dist + 1: minDist[nx + i][ny] = dist + 1 que.append((dist + 1, nx + i, ny)) for i in range(1, K + 1): if nx - i < 0: break if minDist[nx - i][ny] <= dist or A[nx - i][ny] == '@': break if minDist[nx - i][ny] > dist + 1: minDist[nx - i][ny] = dist + 1 que.append((dist + 1, nx - i, ny)) for i in range(1, K + 1): if ny + i >= W: break if minDist[nx][ny + i] <= dist or A[nx][ny + i] == '@': break if minDist[nx][ny + i] > dist + 1: minDist[nx][ny + i] = dist + 1 que.append((dist + 1, nx, ny + i)) for i in range(1, K + 1): if ny - i < 0: break if minDist[nx][ny - i] <= dist or A[nx][ny - i] == '@': break if minDist[nx][ny - i] > dist + 1: minDist[nx][ny - i] = dist + 1 que.append((dist + 1, nx, ny - i)) ans = minDist[tx][ty] print((ans if ans < INF else -1))
52
52
1,613
1,603
from collections import deque import sys input = sys.stdin.buffer.readline H, W, K = list(map(int, input().split())) sx, sy, tx, ty = [int(a) - 1 for a in input().split()] INF = 10**18 A = [input().decode() for _ in range(H)] minDist = [[INF] * W for _ in range(H)] minDist[sx][sy] = 0 que = deque([(0, sx, sy)]) while que: dist, nx, ny = que.popleft() for i in range(1, K + 1): if nx + i >= H: break if minDist[nx + i][ny] <= dist or A[nx + i][ny] == "@": break if minDist[nx + i][ny] > dist + 1: minDist[nx + i][ny] = dist + 1 que.append((dist + 1, nx + i, ny)) for i in range(1, K + 1): if nx - i < 0: break if minDist[nx - i][ny] <= dist or A[nx - i][ny] == "@": break if minDist[nx - i][ny] > dist + 1: minDist[nx - i][ny] = dist + 1 que.append((dist + 1, nx - i, ny)) for i in range(1, K + 1): if ny + i >= W: break if minDist[nx][ny + i] <= dist or A[nx][ny + i] == "@": break if minDist[nx][ny + i] > dist + 1: minDist[nx][ny + i] = dist + 1 que.append((dist + 1, nx, ny + i)) for i in range(1, K + 1): if ny - i < 0: break if minDist[nx][ny - i] <= dist or A[nx][ny - i] == "@": break if minDist[nx][ny - i] > dist + 1: minDist[nx][ny - i] = dist + 1 que.append((dist + 1, nx, ny - i)) ans = minDist[tx][ty] print((ans if ans < INF else -1))
from collections import deque H, W, K = list(map(int, input().split())) sx, sy, tx, ty = [int(a) - 1 for a in input().split()] INF = 10**18 A = [eval(input()) for _ in range(H)] minDist = [[INF] * W for _ in range(H)] minDist[sx][sy] = 0 que = deque([(0, sx, sy)]) while que: dist, nx, ny = que.popleft() if nx == tx and ny == ty: break for i in range(1, K + 1): if nx + i >= H: break if minDist[nx + i][ny] <= dist or A[nx + i][ny] == "@": break if minDist[nx + i][ny] > dist + 1: minDist[nx + i][ny] = dist + 1 que.append((dist + 1, nx + i, ny)) for i in range(1, K + 1): if nx - i < 0: break if minDist[nx - i][ny] <= dist or A[nx - i][ny] == "@": break if minDist[nx - i][ny] > dist + 1: minDist[nx - i][ny] = dist + 1 que.append((dist + 1, nx - i, ny)) for i in range(1, K + 1): if ny + i >= W: break if minDist[nx][ny + i] <= dist or A[nx][ny + i] == "@": break if minDist[nx][ny + i] > dist + 1: minDist[nx][ny + i] = dist + 1 que.append((dist + 1, nx, ny + i)) for i in range(1, K + 1): if ny - i < 0: break if minDist[nx][ny - i] <= dist or A[nx][ny - i] == "@": break if minDist[nx][ny - i] > dist + 1: minDist[nx][ny - i] = dist + 1 que.append((dist + 1, nx, ny - i)) ans = minDist[tx][ty] print((ans if ans < INF else -1))
false
0
[ "-import sys", "-input = sys.stdin.buffer.readline", "-A = [input().decode() for _ in range(H)]", "+A = [eval(input()) for _ in range(H)]", "+ if nx == tx and ny == ty:", "+ break" ]
false
0.048957
0.051359
0.953236
[ "s221005672", "s860803839" ]
u194894739
p03044
python
s295577768
s127879693
837
472
72,608
68,400
Accepted
Accepted
43.61
from collections import deque N = int(eval(input())) adj = [[] for i in range(N)] for _ in range(N-1): u, v, w = list(map(int, input().split())) adj[u-1].append((v-1,w)) adj[v-1].append((u-1,w)) color = [0]*N visited = [0]*N visited[0] = 1 q = deque() q.append((0,0)) while q: v, l = q.pop() visited[v] = 1 if l % 2 == 1: color[v] = 1 for u, w in adj[v]: if not visited[u]: q.append((u, l+w)) for i in range(N): print((color[i]))
import sys input = sys.stdin.readline from collections import deque N = int(eval(input())) adj = [[] for i in range(N)] for _ in range(N-1): u, v, w = list(map(int, input().split())) adj[u-1].append((v-1,w)) adj[v-1].append((u-1,w)) color = [0]*N visited = [0]*N visited[0] = 1 q = deque() q.append((0,0)) while q: v, l = q.pop() visited[v] = 1 if l % 2 == 1: color[v] = 1 for u, w in adj[v]: if not visited[u]: q.append((u, l+w)) for i in range(N): print((color[i]))
26
28
505
545
from collections import deque N = int(eval(input())) adj = [[] for i in range(N)] for _ in range(N - 1): u, v, w = list(map(int, input().split())) adj[u - 1].append((v - 1, w)) adj[v - 1].append((u - 1, w)) color = [0] * N visited = [0] * N visited[0] = 1 q = deque() q.append((0, 0)) while q: v, l = q.pop() visited[v] = 1 if l % 2 == 1: color[v] = 1 for u, w in adj[v]: if not visited[u]: q.append((u, l + w)) for i in range(N): print((color[i]))
import sys input = sys.stdin.readline from collections import deque N = int(eval(input())) adj = [[] for i in range(N)] for _ in range(N - 1): u, v, w = list(map(int, input().split())) adj[u - 1].append((v - 1, w)) adj[v - 1].append((u - 1, w)) color = [0] * N visited = [0] * N visited[0] = 1 q = deque() q.append((0, 0)) while q: v, l = q.pop() visited[v] = 1 if l % 2 == 1: color[v] = 1 for u, w in adj[v]: if not visited[u]: q.append((u, l + w)) for i in range(N): print((color[i]))
false
7.142857
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.041372
0.036477
1.134189
[ "s295577768", "s127879693" ]
u519939795
p03102
python
s500195527
s756936209
298
17
21,500
3,060
Accepted
Accepted
94.3
import numpy as np N, M, C = list(map(int, input().split())) B = np.array(list(map(int, input().split()))) ans = 0 for i in range(N): tmp = np.dot(np.array(list(map(int, input().split()))), B) if (tmp.sum() + C) > 0: ans += 1 print(ans)
n,m,c=list(map(int,input().split())) b=list(map(int,input().split())) ans=0 sum1=0 for i in range(n): a=list(map(int,input().split())) for j in range(m): sum1+=a[j]*b[j] if sum1+c>0: ans+=1 sum1=0 print(ans)
12
12
261
244
import numpy as np N, M, C = list(map(int, input().split())) B = np.array(list(map(int, input().split()))) ans = 0 for i in range(N): tmp = np.dot(np.array(list(map(int, input().split()))), B) if (tmp.sum() + C) > 0: ans += 1 print(ans)
n, m, c = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 sum1 = 0 for i in range(n): a = list(map(int, input().split())) for j in range(m): sum1 += a[j] * b[j] if sum1 + c > 0: ans += 1 sum1 = 0 print(ans)
false
0
[ "-import numpy as np", "-", "-N, M, C = list(map(int, input().split()))", "-B = np.array(list(map(int, input().split())))", "+n, m, c = list(map(int, input().split()))", "+b = list(map(int, input().split()))", "-for i in range(N):", "- tmp = np.dot(np.array(list(map(int, input().split()))), B)", "- if (tmp.sum() + C) > 0:", "+sum1 = 0", "+for i in range(n):", "+ a = list(map(int, input().split()))", "+ for j in range(m):", "+ sum1 += a[j] * b[j]", "+ if sum1 + c > 0:", "+ sum1 = 0" ]
false
0.190422
0.034619
5.500566
[ "s500195527", "s756936209" ]
u303059352
p03424
python
s272499684
s146570131
19
17
3,060
2,940
Accepted
Accepted
10.53
eval(input()) print(("Four" if "Y" in eval(input()) else "Three"))
print(("TFhoruere"['Y'in open(0).read()::2]))
2
1
53
43
eval(input()) print(("Four" if "Y" in eval(input()) else "Three"))
print(("TFhoruere"["Y" in open(0).read() :: 2]))
false
50
[ "-eval(input())", "-print((\"Four\" if \"Y\" in eval(input()) else \"Three\"))", "+print((\"TFhoruere\"[\"Y\" in open(0).read() :: 2]))" ]
false
0.043375
0.043853
0.989115
[ "s272499684", "s146570131" ]
u744920373
p03212
python
s775064964
s723693044
61
50
4,272
4,008
Accepted
Accepted
18.03
import sys sys.setrecursionlimit(10**8) 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 li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini]*i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)] #import bisect #bisect.bisect_left(B, a) #from collections import defaultdict #d = defaultdict(int) d[key] += value import itertools #list(accumulate(A)) N = ii() l = [] for keta in range(3, 10): for koho in itertools.product(['3', '5', '7'], repeat=keta): l.append(int(''.join(koho))) l.sort() ele = ['3', '5', '7'] cnt = 0 for num in l: if num > N: break num = str(num) if all(e in num for e in ele): cnt += 1 print(cnt)
import sys sys.setrecursionlimit(10**8) 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 li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini]*i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)] #import bisect #bisect.bisect_left(B, a) #from collections import defaultdict #d = defaultdict(int) d[key] += value #import itertools #list(accumulate(A)) #from collections import deque ## FlagをもたせたDFS N = ii() ele = [3, 5, 7] l = [] def dfs(num, flag): if num > N: return if flag == 7: l.append(num) num *= 10 for i, e in enumerate(ele): dfs(num+e, flag | 1<<i) dfs(0, 0) print((len(l)))
31
30
915
878
import sys sys.setrecursionlimit(10**8) 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 li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini] * i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini] * i for _ in range(j)] for _ in range(k)] # import bisect #bisect.bisect_left(B, a) # from collections import defaultdict #d = defaultdict(int) d[key] += value import itertools # list(accumulate(A)) N = ii() l = [] for keta in range(3, 10): for koho in itertools.product(["3", "5", "7"], repeat=keta): l.append(int("".join(koho))) l.sort() ele = ["3", "5", "7"] cnt = 0 for num in l: if num > N: break num = str(num) if all(e in num for e in ele): cnt += 1 print(cnt)
import sys sys.setrecursionlimit(10**8) 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 li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def dp2(ini, i, j): return [[ini] * i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini] * i for _ in range(j)] for _ in range(k)] # import bisect #bisect.bisect_left(B, a) # from collections import defaultdict #d = defaultdict(int) d[key] += value # import itertools #list(accumulate(A)) # from collections import deque ## FlagをもたせたDFS N = ii() ele = [3, 5, 7] l = [] def dfs(num, flag): if num > N: return if flag == 7: l.append(num) num *= 10 for i, e in enumerate(ele): dfs(num + e, flag | 1 << i) dfs(0, 0) print((len(l)))
false
3.225806
[ "-import itertools # list(accumulate(A))", "+# import itertools #list(accumulate(A))", "+# from collections import deque", "+## FlagをもたせたDFS", "+N = ii()", "+ele = [3, 5, 7]", "+l = []", "-N = ii()", "-l = []", "-for keta in range(3, 10):", "- for koho in itertools.product([\"3\", \"5\", \"7\"], repeat=keta):", "- l.append(int(\"\".join(koho)))", "-l.sort()", "-ele = [\"3\", \"5\", \"7\"]", "-cnt = 0", "-for num in l:", "+", "+def dfs(num, flag):", "- break", "- num = str(num)", "- if all(e in num for e in ele):", "- cnt += 1", "-print(cnt)", "+ return", "+ if flag == 7:", "+ l.append(num)", "+ num *= 10", "+ for i, e in enumerate(ele):", "+ dfs(num + e, flag | 1 << i)", "+", "+", "+dfs(0, 0)", "+print((len(l)))" ]
false
0.055975
0.037378
1.497549
[ "s775064964", "s723693044" ]
u807864121
p02984
python
s772147610
s120078680
752
92
71,192
19,096
Accepted
Accepted
87.77
import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.linalg import spsolve N = int(input()) A = 2 * np.array(list(map(int, input().split()))) r, c, v = [None] * 2 * N, [None] * 2 * N, [None] * 2 * N for n in range(N): r[2 * n] = n r[2 * n + 1] = n c[2 * n] = n c[2 * n + 1] = n + 1 if n != N - 1 else 0 v[2 * n] = 1 v[2 * n + 1] = 1 C = csr_matrix((v, (r, c)), shape=(N, N)) a = list(map(int, spsolve(C, A))) for aa in a: print(aa, end=' ')
N = int(eval(input())) A = list(map(int, input().split())) X = [None] * N X[0] = sum(A) - 2 * sum(A[1::2]) for n in range(1, N): X[n] = 2 * A[n - 1] - X[n - 1] print((' '.join(map(str, X))))
18
7
492
190
import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.linalg import spsolve N = int(input()) A = 2 * np.array(list(map(int, input().split()))) r, c, v = [None] * 2 * N, [None] * 2 * N, [None] * 2 * N for n in range(N): r[2 * n] = n r[2 * n + 1] = n c[2 * n] = n c[2 * n + 1] = n + 1 if n != N - 1 else 0 v[2 * n] = 1 v[2 * n + 1] = 1 C = csr_matrix((v, (r, c)), shape=(N, N)) a = list(map(int, spsolve(C, A))) for aa in a: print(aa, end=" ")
N = int(eval(input())) A = list(map(int, input().split())) X = [None] * N X[0] = sum(A) - 2 * sum(A[1::2]) for n in range(1, N): X[n] = 2 * A[n - 1] - X[n - 1] print((" ".join(map(str, X))))
false
61.111111
[ "-import numpy as np", "-from scipy.sparse import csr_matrix", "-from scipy.sparse.linalg import spsolve", "-", "-N = int(input())", "-A = 2 * np.array(list(map(int, input().split())))", "-r, c, v = [None] * 2 * N, [None] * 2 * N, [None] * 2 * N", "-for n in range(N):", "- r[2 * n] = n", "- r[2 * n + 1] = n", "- c[2 * n] = n", "- c[2 * n + 1] = n + 1 if n != N - 1 else 0", "- v[2 * n] = 1", "- v[2 * n + 1] = 1", "-C = csr_matrix((v, (r, c)), shape=(N, N))", "-a = list(map(int, spsolve(C, A)))", "-for aa in a:", "- print(aa, end=\" \")", "+N = int(eval(input()))", "+A = list(map(int, input().split()))", "+X = [None] * N", "+X[0] = sum(A) - 2 * sum(A[1::2])", "+for n in range(1, N):", "+ X[n] = 2 * A[n - 1] - X[n - 1]", "+print((\" \".join(map(str, X))))" ]
false
0.51516
0.043976
11.714461
[ "s772147610", "s120078680" ]
u425177436
p03486
python
s861325214
s011960513
19
17
2,940
3,064
Accepted
Accepted
10.53
s=eval(input()) t=eval(input()) print(("Yes"if"".join(sorted(s))<"".join(reversed(sorted(t)))else"No"))
print(("Yes"if"".join(sorted(eval(input())))<"".join(sorted(eval(input()))[::-1])else"No"))
3
1
91
77
s = eval(input()) t = eval(input()) print(("Yes" if "".join(sorted(s)) < "".join(reversed(sorted(t))) else "No"))
print( ( "Yes" if "".join(sorted(eval(input()))) < "".join(sorted(eval(input()))[::-1]) else "No" ) )
false
66.666667
[ "-s = eval(input())", "-t = eval(input())", "-print((\"Yes\" if \"\".join(sorted(s)) < \"\".join(reversed(sorted(t))) else \"No\"))", "+print(", "+ (", "+ \"Yes\"", "+ if \"\".join(sorted(eval(input()))) < \"\".join(sorted(eval(input()))[::-1])", "+ else \"No\"", "+ )", "+)" ]
false
0.04085
0.048747
0.838004
[ "s861325214", "s011960513" ]
u279493135
p03175
python
s595827248
s724032160
623
442
167,908
124,516
Accepted
Accepted
29.05
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product, islice from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 N = INT() xy = [LIST() for _ in range(N-1)] tree = [[] for _ in range(N)] for x, y in xy: tree[x-1].append(y-1) tree[y-1].append(x-1) @lru_cache(maxsize=None) def DFS(i, par, c): # c:0->white, 1->black if par and len(tree[i]) == 1: return 1 if c == 0: cnt = 1 for node in tree[i]: if node != par: cnt *= (DFS(node, i, 0) + DFS(node, i, 1)) cnt %= mod return cnt elif c == 1: cnt = 1 for node in tree[i]: if node != par: cnt *= DFS(node, i, 0) cnt %= mod return cnt ans = DFS(0, None, 0)+DFS(0, None, 1) print((ans%mod))
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product, islice from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 N = INT() xy = [LIST() for _ in range(N-1)] tree = [[] for _ in range(N)] for x, y in xy: tree[x-1].append(y-1) tree[y-1].append(x-1) def rec(n, par): f, g = 1, 1 for node in tree[n]: if node == par: continue fn, gn = rec(node, n) f *= gn f %= mod g *= fn g %= mod return (f+g)%mod, g print((rec(0, None)[0]))
48
41
1,503
1,204
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product, islice from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N = INT() xy = [LIST() for _ in range(N - 1)] tree = [[] for _ in range(N)] for x, y in xy: tree[x - 1].append(y - 1) tree[y - 1].append(x - 1) @lru_cache(maxsize=None) def DFS(i, par, c): # c:0->white, 1->black if par and len(tree[i]) == 1: return 1 if c == 0: cnt = 1 for node in tree[i]: if node != par: cnt *= DFS(node, i, 0) + DFS(node, i, 1) cnt %= mod return cnt elif c == 1: cnt = 1 for node in tree[i]: if node != par: cnt *= DFS(node, i, 0) cnt %= mod return cnt ans = DFS(0, None, 0) + DFS(0, None, 1) print((ans % mod))
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product, islice from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N = INT() xy = [LIST() for _ in range(N - 1)] tree = [[] for _ in range(N)] for x, y in xy: tree[x - 1].append(y - 1) tree[y - 1].append(x - 1) def rec(n, par): f, g = 1, 1 for node in tree[n]: if node == par: continue fn, gn = rec(node, n) f *= gn f %= mod g *= fn g %= mod return (f + g) % mod, g print((rec(0, None)[0]))
false
14.583333
[ "-@lru_cache(maxsize=None)", "-def DFS(i, par, c): # c:0->white, 1->black", "- if par and len(tree[i]) == 1:", "- return 1", "- if c == 0:", "- cnt = 1", "- for node in tree[i]:", "- if node != par:", "- cnt *= DFS(node, i, 0) + DFS(node, i, 1)", "- cnt %= mod", "- return cnt", "- elif c == 1:", "- cnt = 1", "- for node in tree[i]:", "- if node != par:", "- cnt *= DFS(node, i, 0)", "- cnt %= mod", "- return cnt", "+def rec(n, par):", "+ f, g = 1, 1", "+ for node in tree[n]:", "+ if node == par:", "+ continue", "+ fn, gn = rec(node, n)", "+ f *= gn", "+ f %= mod", "+ g *= fn", "+ g %= mod", "+ return (f + g) % mod, g", "-ans = DFS(0, None, 0) + DFS(0, None, 1)", "-print((ans % mod))", "+print((rec(0, None)[0]))" ]
false
0.03825
0.037143
1.029816
[ "s595827248", "s724032160" ]
u331606500
p03078
python
s724855492
s288191795
1,029
134
141,000
9,584
Accepted
Accepted
86.98
r=range;x,y,z,k=list(map(int,input().split())) a,b,c=eval("list(map(int,input().split())), "*3) ab=sorted([a[i]+b[j]for i in r(x)for j in r(y)],reverse=True) abc=sorted([ab[i]+c[j]for i in r(min(3000,x*y))for j in r(z)],reverse=True) print((*[abc[i]for i in r(k)]))
r=range;x,y,z,k=list(map(int,input().split())) a,b,c=eval("sorted(list(map(int,input().split())),reverse=True),"*3) abc=[] for l in r(x): for m in r(y): if -~l*-~m>k:break for n in r(z): if -~l*-~m*-~n>k:break abc+=[a[l]+b[m]+c[n]] print((*sorted(abc,reverse=True)[:k]))
5
10
261
282
r = range x, y, z, k = list(map(int, input().split())) a, b, c = eval("list(map(int,input().split())), " * 3) ab = sorted([a[i] + b[j] for i in r(x) for j in r(y)], reverse=True) abc = sorted([ab[i] + c[j] for i in r(min(3000, x * y)) for j in r(z)], reverse=True) print((*[abc[i] for i in r(k)]))
r = range x, y, z, k = list(map(int, input().split())) a, b, c = eval("sorted(list(map(int,input().split())),reverse=True)," * 3) abc = [] for l in r(x): for m in r(y): if -~l * -~m > k: break for n in r(z): if -~l * -~m * -~n > k: break abc += [a[l] + b[m] + c[n]] print((*sorted(abc, reverse=True)[:k]))
false
50
[ "-a, b, c = eval(\"list(map(int,input().split())), \" * 3)", "-ab = sorted([a[i] + b[j] for i in r(x) for j in r(y)], reverse=True)", "-abc = sorted([ab[i] + c[j] for i in r(min(3000, x * y)) for j in r(z)], reverse=True)", "-print((*[abc[i] for i in r(k)]))", "+a, b, c = eval(\"sorted(list(map(int,input().split())),reverse=True),\" * 3)", "+abc = []", "+for l in r(x):", "+ for m in r(y):", "+ if -~l * -~m > k:", "+ break", "+ for n in r(z):", "+ if -~l * -~m * -~n > k:", "+ break", "+ abc += [a[l] + b[m] + c[n]]", "+print((*sorted(abc, reverse=True)[:k]))" ]
false
0.03545
0.036085
0.982403
[ "s724855492", "s288191795" ]
u921773161
p03211
python
s913102539
s714507271
297
17
21,676
2,940
Accepted
Accepted
94.28
import numpy as np S = eval(input()) l = [] for i in range(len(S)-2): l.append(int(S[i:i+3])) l = np.array(l) l -= 753 for i in range(len(l)): if l[i] <0: l[i] = - l[i] print((min(l)))
S = eval(input()) l = [] for i in range(len(S)-2): tmp = int(S[i:i+3]) l.append(abs(tmp-753)) print((min(l)))
14
7
208
117
import numpy as np S = eval(input()) l = [] for i in range(len(S) - 2): l.append(int(S[i : i + 3])) l = np.array(l) l -= 753 for i in range(len(l)): if l[i] < 0: l[i] = -l[i] print((min(l)))
S = eval(input()) l = [] for i in range(len(S) - 2): tmp = int(S[i : i + 3]) l.append(abs(tmp - 753)) print((min(l)))
false
50
[ "-import numpy as np", "-", "- l.append(int(S[i : i + 3]))", "-l = np.array(l)", "-l -= 753", "-for i in range(len(l)):", "- if l[i] < 0:", "- l[i] = -l[i]", "+ tmp = int(S[i : i + 3])", "+ l.append(abs(tmp - 753))" ]
false
0.192423
0.035933
5.355056
[ "s913102539", "s714507271" ]
u671060652
p02700
python
s627939163
s705958293
99
69
72,804
61,764
Accepted
Accepted
30.3
import itertools import math import fractions import functools a, b, c, d = list(map(int, input().split())) # if c // b > a // d: # print("Yes") # else: # print("No") while c > 0 and a > 0: c = c - b if c <= 0: print('Yes') quit() a = a - d if a<= 0: print("No") quit()
a, b, c, d = list(map(int, input().split())) if (c+b-1) // b <= (a+d-1) // d: print("Yes") else: print("No")
22
7
348
118
import itertools import math import fractions import functools a, b, c, d = list(map(int, input().split())) # if c // b > a // d: # print("Yes") # else: # print("No") while c > 0 and a > 0: c = c - b if c <= 0: print("Yes") quit() a = a - d if a <= 0: print("No") quit()
a, b, c, d = list(map(int, input().split())) if (c + b - 1) // b <= (a + d - 1) // d: print("Yes") else: print("No")
false
68.181818
[ "-import itertools", "-import math", "-import fractions", "-import functools", "-", "-# if c // b > a // d:", "-# print(\"Yes\")", "-# else:", "-# print(\"No\")", "-while c > 0 and a > 0:", "- c = c - b", "- if c <= 0:", "- print(\"Yes\")", "- quit()", "- a = a - d", "- if a <= 0:", "- print(\"No\")", "- quit()", "+if (c + b - 1) // b <= (a + d - 1) // d:", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.043975
0.042383
1.037558
[ "s627939163", "s705958293" ]
u688055251
p02612
python
s402101335
s476442426
33
28
9,100
9,104
Accepted
Accepted
15.15
n=int(eval(input())) res=0 cont=1 while n>0: n=n-(1000*cont) print((abs(n)))
n = int(eval(input())) while n>0: n=n-1000 print((abs(n)))
7
6
79
62
n = int(eval(input())) res = 0 cont = 1 while n > 0: n = n - (1000 * cont) print((abs(n)))
n = int(eval(input())) while n > 0: n = n - 1000 print((abs(n)))
false
14.285714
[ "-res = 0", "-cont = 1", "- n = n - (1000 * cont)", "+ n = n - 1000" ]
false
0.099018
0.039041
2.536216
[ "s402101335", "s476442426" ]
u186838327
p04034
python
s989980357
s391780331
319
193
75,888
75,932
Accepted
Accepted
39.5
n, m = list(map(int, input().split())) X = [0]*n C = [1]*n X[0] = 1 for i in range(m): x, y = list(map(int, input().split())) x, y = x-1, y-1 if X[x] == 1: X[y] = 1 if C[x] == 1: X[x] = 0 C[x] -= 1 C[y] += 1 else: C[x] -= 1 C[y] += 1 ans = sum(X) print(ans)
n, m = list(map(int, input().split())) X = [0]*n X[0] = 1 C = [1]*n for i in range(m): x, y = list(map(int, input().split())) x, y = x-1, y-1 if X[x] == 1: if C[x] == 1: X[x] = 0 X[y] = 1 C[x] -= 1 C[y] += 1 else: X[x] = 1 X[y] = 1 C[x] -= 1 C[y] += 1 else: C[x] -= 1 C[y] += 1 print((sum(X)))
21
23
345
447
n, m = list(map(int, input().split())) X = [0] * n C = [1] * n X[0] = 1 for i in range(m): x, y = list(map(int, input().split())) x, y = x - 1, y - 1 if X[x] == 1: X[y] = 1 if C[x] == 1: X[x] = 0 C[x] -= 1 C[y] += 1 else: C[x] -= 1 C[y] += 1 ans = sum(X) print(ans)
n, m = list(map(int, input().split())) X = [0] * n X[0] = 1 C = [1] * n for i in range(m): x, y = list(map(int, input().split())) x, y = x - 1, y - 1 if X[x] == 1: if C[x] == 1: X[x] = 0 X[y] = 1 C[x] -= 1 C[y] += 1 else: X[x] = 1 X[y] = 1 C[x] -= 1 C[y] += 1 else: C[x] -= 1 C[y] += 1 print((sum(X)))
false
8.695652
[ "+X[0] = 1", "-X[0] = 1", "- X[y] = 1", "- C[x] -= 1", "- C[y] += 1", "+ X[y] = 1", "+ C[x] -= 1", "+ C[y] += 1", "+ else:", "+ X[x] = 1", "+ X[y] = 1", "+ C[x] -= 1", "+ C[y] += 1", "-ans = sum(X)", "-print(ans)", "+print((sum(X)))" ]
false
0.065916
0.070627
0.933293
[ "s989980357", "s391780331" ]
u588341295
p02791
python
s437962816
s917937410
1,292
97
25,864
25,860
Accepted
Accepted
92.49
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 class BIT: """ Binary Indexed Tree """ def __init__(self, n): # 0-indexed n += 1 nv = 1 while nv < n: nv *= 2 self.size = nv self.tree = [0] * nv def sum(self, i): """ [0, i]を合計する """ s = 0 i += 1 while i > 0: s += self.tree[i-1] i -= i & -i return s def add(self, i, x): """ 値の追加:添字i, 値x """ i += 1 while i <= self.size: self.tree[i-1] += x i += i & -i def get(self, l, r=None): """ 区間和の取得 [l, r) """ # 引数が1つなら一点の値を取得 if r is None: r = l + 1 res = 0 if r: res += self.sum(r-1) if l: res -= self.sum(l-1) return res N = INT() A = LIST() bit = BIT(N) ans = 0 for i in range(N): # 自分より左にある、自分より小さな数の個数 if bit.sum(A[i]) == 0: ans += 1 bit.add(A[i], 1) print(ans)
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 N = INT() A = LIST() ans = 0 mn = INF for a in A: if a < mn: mn = a ans += 1 print(ans)
68
30
1,678
815
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 class BIT: """Binary Indexed Tree""" def __init__(self, n): # 0-indexed n += 1 nv = 1 while nv < n: nv *= 2 self.size = nv self.tree = [0] * nv def sum(self, i): """[0, i]を合計する""" s = 0 i += 1 while i > 0: s += self.tree[i - 1] i -= i & -i return s def add(self, i, x): """値の追加:添字i, 値x""" i += 1 while i <= self.size: self.tree[i - 1] += x i += i & -i def get(self, l, r=None): """区間和の取得 [l, r)""" # 引数が1つなら一点の値を取得 if r is None: r = l + 1 res = 0 if r: res += self.sum(r - 1) if l: res -= self.sum(l - 1) return res N = INT() A = LIST() bit = BIT(N) ans = 0 for i in range(N): # 自分より左にある、自分より小さな数の個数 if bit.sum(A[i]) == 0: ans += 1 bit.add(A[i], 1) print(ans)
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 N = INT() A = LIST() ans = 0 mn = INF for a in A: if a < mn: mn = a ans += 1 print(ans)
false
55.882353
[ "-", "-", "-class BIT:", "- \"\"\"Binary Indexed Tree\"\"\"", "-", "- def __init__(self, n):", "- # 0-indexed", "- n += 1", "- nv = 1", "- while nv < n:", "- nv *= 2", "- self.size = nv", "- self.tree = [0] * nv", "-", "- def sum(self, i):", "- \"\"\"[0, i]を合計する\"\"\"", "- s = 0", "- i += 1", "- while i > 0:", "- s += self.tree[i - 1]", "- i -= i & -i", "- return s", "-", "- def add(self, i, x):", "- \"\"\"値の追加:添字i, 値x\"\"\"", "- i += 1", "- while i <= self.size:", "- self.tree[i - 1] += x", "- i += i & -i", "-", "- def get(self, l, r=None):", "- \"\"\"区間和の取得 [l, r)\"\"\"", "- # 引数が1つなら一点の値を取得", "- if r is None:", "- r = l + 1", "- res = 0", "- if r:", "- res += self.sum(r - 1)", "- if l:", "- res -= self.sum(l - 1)", "- return res", "-", "-", "-bit = BIT(N)", "-for i in range(N):", "- # 自分より左にある、自分より小さな数の個数", "- if bit.sum(A[i]) == 0:", "+mn = INF", "+for a in A:", "+ if a < mn:", "+ mn = a", "- bit.add(A[i], 1)" ]
false
0.111125
0.046208
2.404895
[ "s437962816", "s917937410" ]
u394731058
p02699
python
s367439832
s171163272
23
19
9,100
9,136
Accepted
Accepted
17.39
def main(): ans = 'safe' s,w = list(map(int, input().split())) if w >= s: ans = 'unsafe' print(ans) if __name__ == '__main__': main()
s,w = list(map(int, input().split())) if s <= w: print('unsafe') else: print('safe')
10
5
170
86
def main(): ans = "safe" s, w = list(map(int, input().split())) if w >= s: ans = "unsafe" print(ans) if __name__ == "__main__": main()
s, w = list(map(int, input().split())) if s <= w: print("unsafe") else: print("safe")
false
50
[ "-def main():", "- ans = \"safe\"", "- s, w = list(map(int, input().split()))", "- if w >= s:", "- ans = \"unsafe\"", "- print(ans)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+s, w = list(map(int, input().split()))", "+if s <= w:", "+ print(\"unsafe\")", "+else:", "+ print(\"safe\")" ]
false
0.041436
0.074207
0.558388
[ "s367439832", "s171163272" ]
u972658925
p03427
python
s733201115
s799316347
29
26
9,200
9,112
Accepted
Accepted
10.34
def ketawa(x): l = list(str(x)) wa = 0 for a in l: wa += int(a) return wa n = int(eval(input())) lst = list(str(n)) keta = len(str(n)) nine = int("".join([lst[0]] + ["9"]*(keta-1))) if nine <= n: print((ketawa(nine))) else: lst_head = str(int(lst[0]) - 1) nine = int("".join([lst_head] + ["9"]*(keta-1))) print((ketawa(nine)))
n = int(eval(input())) lst = list(map(int,str(n))) if len(lst) == 1: print(n) elif set(lst[1:]) == {9}: print((lst[0] + 9*(len(lst)-1))) else: print(((lst[0]-1) + 9*(len(lst)-1)))
22
9
383
190
def ketawa(x): l = list(str(x)) wa = 0 for a in l: wa += int(a) return wa n = int(eval(input())) lst = list(str(n)) keta = len(str(n)) nine = int("".join([lst[0]] + ["9"] * (keta - 1))) if nine <= n: print((ketawa(nine))) else: lst_head = str(int(lst[0]) - 1) nine = int("".join([lst_head] + ["9"] * (keta - 1))) print((ketawa(nine)))
n = int(eval(input())) lst = list(map(int, str(n))) if len(lst) == 1: print(n) elif set(lst[1:]) == {9}: print((lst[0] + 9 * (len(lst) - 1))) else: print(((lst[0] - 1) + 9 * (len(lst) - 1)))
false
59.090909
[ "-def ketawa(x):", "- l = list(str(x))", "- wa = 0", "- for a in l:", "- wa += int(a)", "- return wa", "-", "-", "-lst = list(str(n))", "-keta = len(str(n))", "-nine = int(\"\".join([lst[0]] + [\"9\"] * (keta - 1)))", "-if nine <= n:", "- print((ketawa(nine)))", "+lst = list(map(int, str(n)))", "+if len(lst) == 1:", "+ print(n)", "+elif set(lst[1:]) == {9}:", "+ print((lst[0] + 9 * (len(lst) - 1)))", "- lst_head = str(int(lst[0]) - 1)", "- nine = int(\"\".join([lst_head] + [\"9\"] * (keta - 1)))", "- print((ketawa(nine)))", "+ print(((lst[0] - 1) + 9 * (len(lst) - 1)))" ]
false
0.039467
0.052097
0.757571
[ "s733201115", "s799316347" ]
u150984829
p02414
python
s508971380
s987136922
120
110
7,008
6,996
Accepted
Accepted
8.33
n,m,l=map(int,input().split()) a=[list(map(int,input().split()))for _ in range(n)] b=[list(map(int,input().split()))for _ in range(m)] [print(*x)for x in[[sum([s*t for s,t in zip(c,l)])for l in zip(*b)]for c in a]]
n,m,l=list(map(int,input().split())) a=[list(map(int,input().split()))for _ in range(n)] b=[list(map(int,input().split()))for _ in range(m)] for x in[[sum([s*t for s,t in zip(c,l)])for l in zip(*b)]for c in a]:print((*x))
4
4
217
217
n, m, l = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(n)] b = [list(map(int, input().split())) for _ in range(m)] [print(*x) for x in [[sum([s * t for s, t in zip(c, l)]) for l in zip(*b)] for c in a]]
n, m, l = list(map(int, input().split())) a = [list(map(int, input().split())) for _ in range(n)] b = [list(map(int, input().split())) for _ in range(m)] for x in [[sum([s * t for s, t in zip(c, l)]) for l in zip(*b)] for c in a]: print((*x))
false
0
[ "-n, m, l = map(int, input().split())", "+n, m, l = list(map(int, input().split()))", "-[print(*x) for x in [[sum([s * t for s, t in zip(c, l)]) for l in zip(*b)] for c in a]]", "+for x in [[sum([s * t for s, t in zip(c, l)]) for l in zip(*b)] for c in a]:", "+ print((*x))" ]
false
0.041735
0.12177
0.342736
[ "s508971380", "s987136922" ]
u606045429
p02874
python
s232603078
s319024910
542
299
24,940
27,440
Accepted
Accepted
44.83
def main(): N = int(eval(input())) L, R = [0] * N, [0] * N for i in range(N): L[i], R[i] = list(map(int, input().split())) max_l = max(L) min_r = min(R) ab = [(max(0, r - max_l + 1), -max(0, min_r - l + 1)) for l, r in zip(L, R)] ab.sort() mi = float("inf") ma = max(r - l + 1 for l, r in zip(L, R)) + max(0, min_r - max_l + 1) for i in range(N - 1): mi = min(mi, -ab[i][1]) ma = max(ma, mi + ab[i + 1][0]) print(ma) main()
from sys import stdin def main(): N, *LR = list(map(int, stdin.buffer.read().split())) L, R = LR[::2], LR[1::2] max_l = max(L) min_r = min(R) ab = [(max(0, r - max_l + 1), -max(0, min_r - l + 1)) for l, r in zip(L, R)] ab.sort() mi = float("inf") ma = max(r - l + 1 for l, r in zip(L, R)) + max(0, min_r - max_l + 1) for (_, r), (l, _) in zip(ab, ab[1:]): mi = min(mi, -r) ma = max(ma, mi + l) print(ma) main()
21
22
505
489
def main(): N = int(eval(input())) L, R = [0] * N, [0] * N for i in range(N): L[i], R[i] = list(map(int, input().split())) max_l = max(L) min_r = min(R) ab = [(max(0, r - max_l + 1), -max(0, min_r - l + 1)) for l, r in zip(L, R)] ab.sort() mi = float("inf") ma = max(r - l + 1 for l, r in zip(L, R)) + max(0, min_r - max_l + 1) for i in range(N - 1): mi = min(mi, -ab[i][1]) ma = max(ma, mi + ab[i + 1][0]) print(ma) main()
from sys import stdin def main(): N, *LR = list(map(int, stdin.buffer.read().split())) L, R = LR[::2], LR[1::2] max_l = max(L) min_r = min(R) ab = [(max(0, r - max_l + 1), -max(0, min_r - l + 1)) for l, r in zip(L, R)] ab.sort() mi = float("inf") ma = max(r - l + 1 for l, r in zip(L, R)) + max(0, min_r - max_l + 1) for (_, r), (l, _) in zip(ab, ab[1:]): mi = min(mi, -r) ma = max(ma, mi + l) print(ma) main()
false
4.545455
[ "+from sys import stdin", "+", "+", "- N = int(eval(input()))", "- L, R = [0] * N, [0] * N", "- for i in range(N):", "- L[i], R[i] = list(map(int, input().split()))", "+ N, *LR = list(map(int, stdin.buffer.read().split()))", "+ L, R = LR[::2], LR[1::2]", "- for i in range(N - 1):", "- mi = min(mi, -ab[i][1])", "- ma = max(ma, mi + ab[i + 1][0])", "+ for (_, r), (l, _) in zip(ab, ab[1:]):", "+ mi = min(mi, -r)", "+ ma = max(ma, mi + l)" ]
false
0.060696
0.036827
1.648128
[ "s232603078", "s319024910" ]
u891635666
p02912
python
s789079770
s842896981
686
163
145,064
14,180
Accepted
Accepted
76.24
n, m = list(map(int, input().split())) ps = list(map(int, input().split())) s = sum(ps) ls = [] for p in ps: prev = p while p > 0: p //= 2 ls.append(prev - p) prev = p ls.sort(reverse=True) print((s - sum(ls[:m])))
import heapq n, m = list(map(int, input().split())) ps = list([-x for x in list(map(int, input().split()))]) heapq.heapify(ps) for _ in range(m): p = -heapq.heappop(ps) heapq.heappush(ps, -(p // 2)) print((-sum(ps)))
12
10
249
226
n, m = list(map(int, input().split())) ps = list(map(int, input().split())) s = sum(ps) ls = [] for p in ps: prev = p while p > 0: p //= 2 ls.append(prev - p) prev = p ls.sort(reverse=True) print((s - sum(ls[:m])))
import heapq n, m = list(map(int, input().split())) ps = list([-x for x in list(map(int, input().split()))]) heapq.heapify(ps) for _ in range(m): p = -heapq.heappop(ps) heapq.heappush(ps, -(p // 2)) print((-sum(ps)))
false
16.666667
[ "+import heapq", "+", "-ps = list(map(int, input().split()))", "-s = sum(ps)", "-ls = []", "-for p in ps:", "- prev = p", "- while p > 0:", "- p //= 2", "- ls.append(prev - p)", "- prev = p", "-ls.sort(reverse=True)", "-print((s - sum(ls[:m])))", "+ps = list([-x for x in list(map(int, input().split()))])", "+heapq.heapify(ps)", "+for _ in range(m):", "+ p = -heapq.heappop(ps)", "+ heapq.heappush(ps, -(p // 2))", "+print((-sum(ps)))" ]
false
0.041662
0.104522
0.398594
[ "s789079770", "s842896981" ]
u761320129
p03674
python
s069519604
s266971365
1,508
398
29,164
33,324
Accepted
Accepted
73.61
from collections import Counter N = int(input()) src = list(map(int,input().split())) ctr = Counter(src) most = ctr.most_common(1)[0][0] i1 = src.index(most) i2 = src[i1+1:].index(most) + i1+1 d = i2 - i1 MOD = 10**9+7 def mul(a,b): return (a*b) % MOD def pow(a,n): # a^n ret = 1 mag = a while n > 0: if n & 1: ret = mul(ret, mag) mag = mul(mag, mag) n >>= 1 return ret def inv(a): return pow(a, MOD-2) fac = [1] fac_inv = [1] for n in range (1,N+3): f = mul(fac[n-1], n) fac.append(f) fac_inv.append(inv(f)) def ncr(n,r): return mul(mul(fac[n], fac_inv[n-r]), fac_inv[r]) anss = [] for r in range(1,N+2): anss.append(ncr(N+1,r)) n = N-d for r in range(n+1): anss[r] -= ncr(n,r) anss[r] %= MOD print(*anss, sep='\n')
from collections import Counter N = int(input()) src = list(map(int,input().split())) ctr = Counter(src) doub = ctr.most_common()[0][0] i1 = src.index(doub) i2 = src[::-1].index(doub) doub_len = (i1+i2+1) MOD = 10**9+7 fac = [1,1] + [0]*N finv = [1,1] + [0]*N inv = [0,1] + [0]*N for i in range(2,N+2): fac[i] = fac[i-1] * i % MOD inv[i] = -inv[MOD%i] * (MOD // i) % MOD finv[i] = finv[i-1] * inv[i] % MOD def ncr(n,r): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD ans = [] for i in range(1,N+2): ans.append(ncr(N+1,i)) for i in range(doub_len): ans[i] -= ncr(doub_len-1, i) ans[i] %= MOD print(*ans,sep='\n')
48
31
862
731
from collections import Counter N = int(input()) src = list(map(int, input().split())) ctr = Counter(src) most = ctr.most_common(1)[0][0] i1 = src.index(most) i2 = src[i1 + 1 :].index(most) + i1 + 1 d = i2 - i1 MOD = 10**9 + 7 def mul(a, b): return (a * b) % MOD def pow(a, n): # a^n ret = 1 mag = a while n > 0: if n & 1: ret = mul(ret, mag) mag = mul(mag, mag) n >>= 1 return ret def inv(a): return pow(a, MOD - 2) fac = [1] fac_inv = [1] for n in range(1, N + 3): f = mul(fac[n - 1], n) fac.append(f) fac_inv.append(inv(f)) def ncr(n, r): return mul(mul(fac[n], fac_inv[n - r]), fac_inv[r]) anss = [] for r in range(1, N + 2): anss.append(ncr(N + 1, r)) n = N - d for r in range(n + 1): anss[r] -= ncr(n, r) anss[r] %= MOD print(*anss, sep="\n")
from collections import Counter N = int(input()) src = list(map(int, input().split())) ctr = Counter(src) doub = ctr.most_common()[0][0] i1 = src.index(doub) i2 = src[::-1].index(doub) doub_len = i1 + i2 + 1 MOD = 10**9 + 7 fac = [1, 1] + [0] * N finv = [1, 1] + [0] * N inv = [0, 1] + [0] * N for i in range(2, N + 2): fac[i] = fac[i - 1] * i % MOD inv[i] = -inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD def ncr(n, r): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD ans = [] for i in range(1, N + 2): ans.append(ncr(N + 1, i)) for i in range(doub_len): ans[i] -= ncr(doub_len - 1, i) ans[i] %= MOD print(*ans, sep="\n")
false
35.416667
[ "-most = ctr.most_common(1)[0][0]", "-i1 = src.index(most)", "-i2 = src[i1 + 1 :].index(most) + i1 + 1", "-d = i2 - i1", "+doub = ctr.most_common()[0][0]", "+i1 = src.index(doub)", "+i2 = src[::-1].index(doub)", "+doub_len = i1 + i2 + 1", "-", "-", "-def mul(a, b):", "- return (a * b) % MOD", "-", "-", "-def pow(a, n): # a^n", "- ret = 1", "- mag = a", "- while n > 0:", "- if n & 1:", "- ret = mul(ret, mag)", "- mag = mul(mag, mag)", "- n >>= 1", "- return ret", "-", "-", "-def inv(a):", "- return pow(a, MOD - 2)", "-", "-", "-fac = [1]", "-fac_inv = [1]", "-for n in range(1, N + 3):", "- f = mul(fac[n - 1], n)", "- fac.append(f)", "- fac_inv.append(inv(f))", "+fac = [1, 1] + [0] * N", "+finv = [1, 1] + [0] * N", "+inv = [0, 1] + [0] * N", "+for i in range(2, N + 2):", "+ fac[i] = fac[i - 1] * i % MOD", "+ inv[i] = -inv[MOD % i] * (MOD // i) % MOD", "+ finv[i] = finv[i - 1] * inv[i] % MOD", "- return mul(mul(fac[n], fac_inv[n - r]), fac_inv[r])", "+ if n < r:", "+ return 0", "+ if n < 0 or r < 0:", "+ return 0", "+ return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD", "-anss = []", "-for r in range(1, N + 2):", "- anss.append(ncr(N + 1, r))", "-n = N - d", "-for r in range(n + 1):", "- anss[r] -= ncr(n, r)", "- anss[r] %= MOD", "-print(*anss, sep=\"\\n\")", "+ans = []", "+for i in range(1, N + 2):", "+ ans.append(ncr(N + 1, i))", "+for i in range(doub_len):", "+ ans[i] -= ncr(doub_len - 1, i)", "+ ans[i] %= MOD", "+print(*ans, sep=\"\\n\")" ]
false
0.037582
0.036065
1.042061
[ "s069519604", "s266971365" ]
u569960318
p02272
python
s080998844
s627474162
4,960
4,270
63,772
63,748
Accepted
Accepted
13.91
cnt = 0 def merge(L,R): global cnt A = [] i = j = 0 n = len(L)+len(R) L.append(float("inf")) R.append(float("inf")) for _ in range(n): cnt += 1 if L[i] <= R[j]: A.append(L[i]) i += 1 else: A.append(R[j]) j += 1 return A def mergeSort(A): if len(A)==1: return A m = len(A)//2 return merge(mergeSort(A[:m]),mergeSort(A[m:])) if __name__=='__main__': n=int(eval(input())) A=list(map(int,input().split())) print((*mergeSort(A))) print(cnt)
cnt = 0 def merge(L,R): global cnt n = len(L)+len(R) cnt += n A = [] i = j = 0 L.append(float("inf")) R.append(float("inf")) for _ in range(n): if L[i] <= R[j]: A.append(L[i]) i += 1 else: A.append(R[j]) j += 1 return A def mergeSort(A): if len(A)==1: return A m = len(A)//2 return merge(mergeSort(A[:m]),mergeSort(A[m:])) if __name__=='__main__': n=int(eval(input())) A=list(map(int,input().split())) print((*mergeSort(A))) print(cnt)
29
29
596
592
cnt = 0 def merge(L, R): global cnt A = [] i = j = 0 n = len(L) + len(R) L.append(float("inf")) R.append(float("inf")) for _ in range(n): cnt += 1 if L[i] <= R[j]: A.append(L[i]) i += 1 else: A.append(R[j]) j += 1 return A def mergeSort(A): if len(A) == 1: return A m = len(A) // 2 return merge(mergeSort(A[:m]), mergeSort(A[m:])) if __name__ == "__main__": n = int(eval(input())) A = list(map(int, input().split())) print((*mergeSort(A))) print(cnt)
cnt = 0 def merge(L, R): global cnt n = len(L) + len(R) cnt += n A = [] i = j = 0 L.append(float("inf")) R.append(float("inf")) for _ in range(n): if L[i] <= R[j]: A.append(L[i]) i += 1 else: A.append(R[j]) j += 1 return A def mergeSort(A): if len(A) == 1: return A m = len(A) // 2 return merge(mergeSort(A[:m]), mergeSort(A[m:])) if __name__ == "__main__": n = int(eval(input())) A = list(map(int, input().split())) print((*mergeSort(A))) print(cnt)
false
0
[ "+ n = len(L) + len(R)", "+ cnt += n", "- n = len(L) + len(R)", "- cnt += 1" ]
false
0.035805
0.035252
1.015684
[ "s080998844", "s627474162" ]
u992910889
p02831
python
s742911236
s225565345
288
40
65,388
5,304
Accepted
Accepted
86.11
# import bisect # import copy import fractions # import math # import numpy as np # from collections import Counter, deque # from itertools import accumulate,permutations, combinations,combinations_with_replacement,product def resolve(): A,B=list(map(int,input().split())) print((A*B//fractions.gcd(A,B))) resolve()
import fractions import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): A,B=list(map(int,input().split())) val=A* B //fractions.gcd(A, B) print(val) resolve()
14
11
331
233
# import bisect # import copy import fractions # import math # import numpy as np # from collections import Counter, deque # from itertools import accumulate,permutations, combinations,combinations_with_replacement,product def resolve(): A, B = list(map(int, input().split())) print((A * B // fractions.gcd(A, B))) resolve()
import fractions import sys sys.setrecursionlimit(10**5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): A, B = list(map(int, input().split())) val = A * B // fractions.gcd(A, B) print(val) resolve()
false
21.428571
[ "-# import bisect", "-# import copy", "+import sys", "-# import math", "-# import numpy as np", "-# from collections import Counter, deque", "-# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product", "+sys.setrecursionlimit(10**5 + 10)", "+", "+", "+def input():", "+ return sys.stdin.readline().strip()", "+", "+", "- print((A * B // fractions.gcd(A, B)))", "+ val = A * B // fractions.gcd(A, B)", "+ print(val)" ]
false
0.043728
0.125762
0.347701
[ "s742911236", "s225565345" ]
u556589653
p02682
python
s377183974
s502804959
24
20
9,160
9,136
Accepted
Accepted
16.67
#Solver:Rute a,b,c,k = list(map(int,input().split())) if k<=a: print(k) elif a<k<a+b: print(k) else: #-1のカードの枚数超過 (k-(a+b))枚 print((a-(k-(a+b))))
#Solver:Rute a,b,c,k = list(map(int,input().split())) if 0<=k<=a: print(k) elif a<k<=a+b: print(a) else: print((a-(k-(a+b))))
9
8
153
130
# Solver:Rute a, b, c, k = list(map(int, input().split())) if k <= a: print(k) elif a < k < a + b: print(k) else: # -1のカードの枚数超過 (k-(a+b))枚 print((a - (k - (a + b))))
# Solver:Rute a, b, c, k = list(map(int, input().split())) if 0 <= k <= a: print(k) elif a < k <= a + b: print(a) else: print((a - (k - (a + b))))
false
11.111111
[ "-if k <= a:", "+if 0 <= k <= a:", "-elif a < k < a + b:", "- print(k)", "+elif a < k <= a + b:", "+ print(a)", "- # -1のカードの枚数超過 (k-(a+b))枚" ]
false
0.050614
0.049395
1.024689
[ "s377183974", "s502804959" ]
u083960235
p03208
python
s076924997
s990332446
227
168
7,384
8,120
Accepted
Accepted
25.99
n,k=list(map(int,input().split())) h=[int(eval(input())) for i in range(n)] h.sort() #for i in range(n-k+1): print((min(h[i+k-1]-h[i] for i in range(n-k+1))))
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from heapq import heapify, heappop, heappush def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, K = MAP() H = [INT() for i in range(N)] H.sort() ans = INF for i in range(N-K+1): ans = min(H[i+K-1] - H[i], ans) print(ans)
6
28
154
885
n, k = list(map(int, input().split())) h = [int(eval(input())) for i in range(n)] h.sort() # for i in range(n-k+1): print((min(h[i + k - 1] - h[i] for i in range(n - k + 1))))
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from heapq import heapify, heappop, heappush def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, K = MAP() H = [INT() for i in range(N)] H.sort() ans = INF for i in range(N - K + 1): ans = min(H[i + K - 1] - H[i], ans) print(ans)
false
78.571429
[ "-n, k = list(map(int, input().split()))", "-h = [int(eval(input())) for i in range(n)]", "-h.sort()", "-# for i in range(n-k+1):", "-print((min(h[i + k - 1] - h[i] for i in range(n - k + 1))))", "+import sys, re, os", "+from collections import deque, defaultdict, Counter", "+from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians", "+from itertools import permutations, combinations, product, accumulate", "+from operator import itemgetter, mul", "+from copy import deepcopy", "+from string import ascii_lowercase, ascii_uppercase, digits", "+from heapq import heapify, heappop, heappush", "+", "+", "+def input():", "+ return sys.stdin.readline().strip()", "+", "+", "+def INT():", "+ return int(eval(input()))", "+", "+", "+def MAP():", "+ return list(map(int, input().split()))", "+", "+", "+def S_MAP():", "+ return list(map(str, input().split()))", "+", "+", "+def LIST():", "+ return list(map(int, input().split()))", "+", "+", "+def S_LIST():", "+ return list(map(str, input().split()))", "+", "+", "+sys.setrecursionlimit(10**9)", "+INF = float(\"inf\")", "+mod = 10**9 + 7", "+N, K = MAP()", "+H = [INT() for i in range(N)]", "+H.sort()", "+ans = INF", "+for i in range(N - K + 1):", "+ ans = min(H[i + K - 1] - H[i], ans)", "+print(ans)" ]
false
0.047918
0.070587
0.678847
[ "s076924997", "s990332446" ]
u658627575
p03043
python
s964262307
s248994197
50
34
2,940
2,940
Accepted
Accepted
32
import math N, K = list(map(int,input().split())) #N, K = 100000, 5 ans = 0 for i in range(1,N+1): a = i b = 1 while a < K: a *= 2 b *= 0.50000000000 ans += b print((ans/N))
import math N, K = list(map(int,input().split())) #N, K = 100000, 5 ans = 0 total = 0 for i in range(0,N): if i < K: #dice_times = math.ceil(math.log2(K/(i+1))) dice_times = math.ceil(math.log2(K/(i+1))) total = total + (0.50000000000**dice_times) #print(total) else: total += 1 print((total/N))
16
17
193
318
import math N, K = list(map(int, input().split())) # N, K = 100000, 5 ans = 0 for i in range(1, N + 1): a = i b = 1 while a < K: a *= 2 b *= 0.50000000000 ans += b print((ans / N))
import math N, K = list(map(int, input().split())) # N, K = 100000, 5 ans = 0 total = 0 for i in range(0, N): if i < K: # dice_times = math.ceil(math.log2(K/(i+1))) dice_times = math.ceil(math.log2(K / (i + 1))) total = total + (0.50000000000**dice_times) # print(total) else: total += 1 print((total / N))
false
5.882353
[ "-for i in range(1, N + 1):", "- a = i", "- b = 1", "- while a < K:", "- a *= 2", "- b *= 0.50000000000", "- ans += b", "-print((ans / N))", "+total = 0", "+for i in range(0, N):", "+ if i < K:", "+ # dice_times = math.ceil(math.log2(K/(i+1)))", "+ dice_times = math.ceil(math.log2(K / (i + 1)))", "+ total = total + (0.50000000000**dice_times)", "+ # print(total)", "+ else:", "+ total += 1", "+print((total / N))" ]
false
0.050937
0.047622
1.069616
[ "s964262307", "s248994197" ]
u805332733
p02713
python
s320185982
s225391620
1,819
1,034
71,968
72,184
Accepted
Accepted
43.16
from math import gcd from functools import reduce import itertools def resolve(): K = int(eval(input())) gcds = sum([ gcd(gcd(x[0], x[1]), x[2]) for x in itertools.product(list(range(1, K+1)), list(range(1, K+1)), list(range(1, K+1))) ]) print(gcds) if __name__ == "__main__": resolve()
from math import gcd from functools import reduce from itertools import product def resolve(): K = int(eval(input())) # result = sum([ gcd(gcd(x[0], x[1]), x[2]) for x in itertools.product(range(1, K+1), range(1, K+1), range(1, K+1)) ]) step1 = [ gcd(x[0], x[1]) for x in product(list(range(1, K+1)), list(range(1, K+1))) ] result = sum([ gcd(x[0], x[1]) for x in product(step1, list(range(1, K+1))) ]) print(result) if __name__ == "__main__": resolve()
11
13
285
457
from math import gcd from functools import reduce import itertools def resolve(): K = int(eval(input())) gcds = sum( [ gcd(gcd(x[0], x[1]), x[2]) for x in itertools.product( list(range(1, K + 1)), list(range(1, K + 1)), list(range(1, K + 1)) ) ] ) print(gcds) if __name__ == "__main__": resolve()
from math import gcd from functools import reduce from itertools import product def resolve(): K = int(eval(input())) # result = sum([ gcd(gcd(x[0], x[1]), x[2]) for x in itertools.product(range(1, K+1), range(1, K+1), range(1, K+1)) ]) step1 = [ gcd(x[0], x[1]) for x in product(list(range(1, K + 1)), list(range(1, K + 1))) ] result = sum([gcd(x[0], x[1]) for x in product(step1, list(range(1, K + 1)))]) print(result) if __name__ == "__main__": resolve()
false
15.384615
[ "-import itertools", "+from itertools import product", "- gcds = sum(", "- [", "- gcd(gcd(x[0], x[1]), x[2])", "- for x in itertools.product(", "- list(range(1, K + 1)), list(range(1, K + 1)), list(range(1, K + 1))", "- )", "- ]", "- )", "- print(gcds)", "+ # result = sum([ gcd(gcd(x[0], x[1]), x[2]) for x in itertools.product(range(1, K+1), range(1, K+1), range(1, K+1)) ])", "+ step1 = [", "+ gcd(x[0], x[1]) for x in product(list(range(1, K + 1)), list(range(1, K + 1)))", "+ ]", "+ result = sum([gcd(x[0], x[1]) for x in product(step1, list(range(1, K + 1)))])", "+ print(result)" ]
false
0.102795
0.094783
1.084528
[ "s320185982", "s225391620" ]
u077291787
p03197
python
s070388722
s572656301
237
216
71,228
71,228
Accepted
Accepted
8.86
# caddi2018D - Harlequin def main(): N, *A = list(map(int, open(0).read().split())) flg = all(i % 2 == 0 for i in A) print(("second" if flg else "first")) if __name__ == "__main__": main()
# caddi2018D - Harlequin def main(): N, *A = list(map(int, open(0).read().split())) flg = any(i & 1 for i in A) print(("first" if flg else "second")) if __name__ == "__main__": main()
9
9
206
201
# caddi2018D - Harlequin def main(): N, *A = list(map(int, open(0).read().split())) flg = all(i % 2 == 0 for i in A) print(("second" if flg else "first")) if __name__ == "__main__": main()
# caddi2018D - Harlequin def main(): N, *A = list(map(int, open(0).read().split())) flg = any(i & 1 for i in A) print(("first" if flg else "second")) if __name__ == "__main__": main()
false
0
[ "- flg = all(i % 2 == 0 for i in A)", "- print((\"second\" if flg else \"first\"))", "+ flg = any(i & 1 for i in A)", "+ print((\"first\" if flg else \"second\"))" ]
false
0.043211
0.042431
1.018384
[ "s070388722", "s572656301" ]
u753803401
p02901
python
s641378118
s607433251
359
210
43,228
42,460
Accepted
Accepted
41.5
import sys def solve(): input = sys.stdin.readline mod = 10 ** 9 + 7 n, m = list(map(int, input().rstrip('\n').split())) pw = 2 ** n dp = [10 ** 20] * pw dp[0] = 0 for i in range(m): a, b = list(map(int, input().rstrip('\n').split())) c = sum(2 ** (i - 1) for i in list(map(int, input().rstrip('\n').split()))) for j in range(pw): if dp[j | c] > dp[j] + a: dp[j | c] = dp[j] + a if dp[-1] == 10 ** 20: print((-1)) else: print((dp[-1])) if __name__ == '__main__': solve()
import sys def solve(): input = sys.stdin.readline mod = 10 ** 9 + 7 n, m = list(map(int, input().rstrip('\n').split())) pw = pow(2, n) dp = [10 ** 15] * pw dp[0] = 0 for _ in range(m): a, b = list(map(int, input().rstrip('\n').split())) c = sum(2 ** (i - 1) for i in list(map(int, input().rstrip('\n').split()))) for i in range(pw): dp[c | i] = min(dp[c | i], dp[i] + a) print((dp[-1] if dp[-1] != 10 ** 15 else -1)) if __name__ == '__main__': solve()
24
20
602
546
import sys def solve(): input = sys.stdin.readline mod = 10**9 + 7 n, m = list(map(int, input().rstrip("\n").split())) pw = 2**n dp = [10**20] * pw dp[0] = 0 for i in range(m): a, b = list(map(int, input().rstrip("\n").split())) c = sum(2 ** (i - 1) for i in list(map(int, input().rstrip("\n").split()))) for j in range(pw): if dp[j | c] > dp[j] + a: dp[j | c] = dp[j] + a if dp[-1] == 10**20: print((-1)) else: print((dp[-1])) if __name__ == "__main__": solve()
import sys def solve(): input = sys.stdin.readline mod = 10**9 + 7 n, m = list(map(int, input().rstrip("\n").split())) pw = pow(2, n) dp = [10**15] * pw dp[0] = 0 for _ in range(m): a, b = list(map(int, input().rstrip("\n").split())) c = sum(2 ** (i - 1) for i in list(map(int, input().rstrip("\n").split()))) for i in range(pw): dp[c | i] = min(dp[c | i], dp[i] + a) print((dp[-1] if dp[-1] != 10**15 else -1)) if __name__ == "__main__": solve()
false
16.666667
[ "- pw = 2**n", "- dp = [10**20] * pw", "+ pw = pow(2, n)", "+ dp = [10**15] * pw", "- for i in range(m):", "+ for _ in range(m):", "- for j in range(pw):", "- if dp[j | c] > dp[j] + a:", "- dp[j | c] = dp[j] + a", "- if dp[-1] == 10**20:", "- print((-1))", "- else:", "- print((dp[-1]))", "+ for i in range(pw):", "+ dp[c | i] = min(dp[c | i], dp[i] + a)", "+ print((dp[-1] if dp[-1] != 10**15 else -1))" ]
false
0.036943
0.1024
0.360776
[ "s641378118", "s607433251" ]
u941407962
p02888
python
s533019647
s667493721
1,992
1,339
84,216
3,188
Accepted
Accepted
32.78
n = int(eval(input())) xs = list(map(int, input().split())) xs = sorted(list(xs)) ts = [] for i in range(n): for j in range(i+1, n): ts.append(xs[i] + xs[j]) ts.sort() i = 0 j = 0 r = 0 xs.append(10**18) while True: if j == len(xs) or i == len(ts): break if ts[i] <= xs[j]: i += 1 r += n-j else: j += 1 print((n*(n-1)*(n-2)//6-r))
n = int(eval(input())) X = list(map(int, input().split())) X.sort() k=r=0 for i in range(n): k = i for j in range(i+1, n): while k<n and X[i]+X[j]>X[k]: k +=1 r += k-j-1 print(r)
21
11
395
219
n = int(eval(input())) xs = list(map(int, input().split())) xs = sorted(list(xs)) ts = [] for i in range(n): for j in range(i + 1, n): ts.append(xs[i] + xs[j]) ts.sort() i = 0 j = 0 r = 0 xs.append(10**18) while True: if j == len(xs) or i == len(ts): break if ts[i] <= xs[j]: i += 1 r += n - j else: j += 1 print((n * (n - 1) * (n - 2) // 6 - r))
n = int(eval(input())) X = list(map(int, input().split())) X.sort() k = r = 0 for i in range(n): k = i for j in range(i + 1, n): while k < n and X[i] + X[j] > X[k]: k += 1 r += k - j - 1 print(r)
false
47.619048
[ "-xs = list(map(int, input().split()))", "-xs = sorted(list(xs))", "-ts = []", "+X = list(map(int, input().split()))", "+X.sort()", "+k = r = 0", "+ k = i", "- ts.append(xs[i] + xs[j])", "-ts.sort()", "-i = 0", "-j = 0", "-r = 0", "-xs.append(10**18)", "-while True:", "- if j == len(xs) or i == len(ts):", "- break", "- if ts[i] <= xs[j]:", "- i += 1", "- r += n - j", "- else:", "- j += 1", "-print((n * (n - 1) * (n - 2) // 6 - r))", "+ while k < n and X[i] + X[j] > X[k]:", "+ k += 1", "+ r += k - j - 1", "+print(r)" ]
false
0.041135
0.041262
0.99692
[ "s533019647", "s667493721" ]
u879309973
p02580
python
s448391295
s829526079
1,573
1,354
183,620
166,020
Accepted
Accepted
13.92
import numpy as np def solve(H, W, M, h, w): f = [0] * (H+1) g = [0] * (W+1) for r, c in zip(h, w): f[r] += 1 g[c] += 1 p = np.max(f) q = np.max(g) num = len(list(filter(p.__eq__, f))) * len(list(filter(q.__eq__, g))) for r, c in zip(h, w): if (f[r] == p) and (g[c] == q): num -= 1 return p + q - (num <= 0) H, W, M = list(map(int, input().split())) h, w = list(zip(*[list(map(int, input().split())) for i in range(M)])) print((solve(H, W, M, h, w)))
def solve(H, W, M, h, w): f = [0] * (H+1) g = [0] * (W+1) for r, c in zip(h, w): f[r] += 1 g[c] += 1 p = max(f) q = max(g) num = len(list(filter(p.__eq__, f))) * len(list(filter(q.__eq__, g))) num -= len(list([_ for _ in zip(h, w) if f[_[0]] + g[_[1]] == p + q])) return p + q - (num <= 0) H, W, M = list(map(int, input().split())) h, w = list(zip(*[list(map(int, input().split())) for i in range(M)])) print((solve(H, W, M, h, w)))
19
15
518
478
import numpy as np def solve(H, W, M, h, w): f = [0] * (H + 1) g = [0] * (W + 1) for r, c in zip(h, w): f[r] += 1 g[c] += 1 p = np.max(f) q = np.max(g) num = len(list(filter(p.__eq__, f))) * len(list(filter(q.__eq__, g))) for r, c in zip(h, w): if (f[r] == p) and (g[c] == q): num -= 1 return p + q - (num <= 0) H, W, M = list(map(int, input().split())) h, w = list(zip(*[list(map(int, input().split())) for i in range(M)])) print((solve(H, W, M, h, w)))
def solve(H, W, M, h, w): f = [0] * (H + 1) g = [0] * (W + 1) for r, c in zip(h, w): f[r] += 1 g[c] += 1 p = max(f) q = max(g) num = len(list(filter(p.__eq__, f))) * len(list(filter(q.__eq__, g))) num -= len(list([_ for _ in zip(h, w) if f[_[0]] + g[_[1]] == p + q])) return p + q - (num <= 0) H, W, M = list(map(int, input().split())) h, w = list(zip(*[list(map(int, input().split())) for i in range(M)])) print((solve(H, W, M, h, w)))
false
21.052632
[ "-import numpy as np", "-", "-", "- p = np.max(f)", "- q = np.max(g)", "+ p = max(f)", "+ q = max(g)", "- for r, c in zip(h, w):", "- if (f[r] == p) and (g[c] == q):", "- num -= 1", "+ num -= len(list([_ for _ in zip(h, w) if f[_[0]] + g[_[1]] == p + q]))" ]
false
0.282475
0.075868
3.723256
[ "s448391295", "s829526079" ]
u489959379
p03325
python
s723241572
s764439096
82
62
4,148
4,148
Accepted
Accepted
24.39
n = int(eval(input())) a = list(map(int, input().split())) res = 0 for i in range(n): if a[i] % 2 == 0: k = a[i] while k % 2 == 0: k //= 2 res += 1 print(res)
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(eval(input())) A = list(map(int, input().split())) even = [A[i] for i in range(n) if A[i] % 2 == 0] res = 0 for number in even: while number % 2 == 0: res += 1 number //= 2 print(res) if __name__ == '__main__': resolve()
12
24
210
410
n = int(eval(input())) a = list(map(int, input().split())) res = 0 for i in range(n): if a[i] % 2 == 0: k = a[i] while k % 2 == 0: k //= 2 res += 1 print(res)
import sys sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 def resolve(): n = int(eval(input())) A = list(map(int, input().split())) even = [A[i] for i in range(n) if A[i] % 2 == 0] res = 0 for number in even: while number % 2 == 0: res += 1 number //= 2 print(res) if __name__ == "__main__": resolve()
false
50
[ "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-res = 0", "-for i in range(n):", "- if a[i] % 2 == 0:", "- k = a[i]", "- while k % 2 == 0:", "- k //= 2", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+f_inf = float(\"inf\")", "+mod = 10**9 + 7", "+", "+", "+def resolve():", "+ n = int(eval(input()))", "+ A = list(map(int, input().split()))", "+ even = [A[i] for i in range(n) if A[i] % 2 == 0]", "+ res = 0", "+ for number in even:", "+ while number % 2 == 0:", "-print(res)", "+ number //= 2", "+ print(res)", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.046684
0.048984
0.95304
[ "s723241572", "s764439096" ]