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
u562935282
p03108
python
s066744349
s350716867
665
560
24,048
24,088
Accepted
Accepted
15.79
class UnionFind: def __init__(self, n): self.v = [-1] * n def find(self, x): if self.v[x] < 0: return x else: self.v[x] = self.find(self.v[x]) return self.v[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False else: if self.v[x] > self.v[y]: x, y = y, x self.v[x] += self.v[y] self.v[y] = x return True def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.v[self.find(x)] def main(): import sys input = sys.stdin.readline N, M = map(int, input().split()) collapse_schedule = [] for _ in range(M): A, B = (int(x) - 1 for x in input().split()) collapse_schedule.append((A, B)) collapse_schedule.reverse() uf = UnionFind(N) def evaluate(size): return size * (size - 1) // 2 all_dropped = evaluate(N) curr = all_dropped ret = [-1] * M ret[-1] = all_dropped for i, (a, b) in zip(reversed(range(M - 1)), collapse_schedule): if not uf.same(a, b): sa, sb = uf.size(a), uf.size(b) ea, eb = evaluate(sa), evaluate(sb) curr += ea + eb uf.unite(a, b) sa = uf.size(a) ea = evaluate(sa) curr -= ea ret[i] = curr print(*ret, sep='\n') if __name__ == '__main__': main()
class UnionFind: def __init__(self, n): self.v = [-1] * n def find(self, x): if self.v[x] < 0: return x else: self.v[x] = self.find(self.v[x]) return self.v[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False else: if self.v[x] > self.v[y]: x, y = y, x self.v[x] += self.v[y] self.v[y] = x return True def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.v[self.find(x)] def main(): import sys input = sys.stdin.readline N, M = map(int, input().split()) es = [] for _ in range(M): a, b = (int(x) - 1 for x in input().split()) es.append((a, b)) es.reverse() es.pop() uf = UnionFind(N) ans = [N * (N - 1) // 2] t = ans[-1] for a, b in es: if not uf.same(a, b): t -= uf.size(a) * uf.size(b) ans.append(t) uf.unite(a, b) ans.reverse() print(*ans, sep='\n') if __name__ == '__main__': main()
75
59
1,606
1,239
class UnionFind: def __init__(self, n): self.v = [-1] * n def find(self, x): if self.v[x] < 0: return x else: self.v[x] = self.find(self.v[x]) return self.v[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False else: if self.v[x] > self.v[y]: x, y = y, x self.v[x] += self.v[y] self.v[y] = x return True def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.v[self.find(x)] def main(): import sys input = sys.stdin.readline N, M = map(int, input().split()) collapse_schedule = [] for _ in range(M): A, B = (int(x) - 1 for x in input().split()) collapse_schedule.append((A, B)) collapse_schedule.reverse() uf = UnionFind(N) def evaluate(size): return size * (size - 1) // 2 all_dropped = evaluate(N) curr = all_dropped ret = [-1] * M ret[-1] = all_dropped for i, (a, b) in zip(reversed(range(M - 1)), collapse_schedule): if not uf.same(a, b): sa, sb = uf.size(a), uf.size(b) ea, eb = evaluate(sa), evaluate(sb) curr += ea + eb uf.unite(a, b) sa = uf.size(a) ea = evaluate(sa) curr -= ea ret[i] = curr print(*ret, sep="\n") if __name__ == "__main__": main()
class UnionFind: def __init__(self, n): self.v = [-1] * n def find(self, x): if self.v[x] < 0: return x else: self.v[x] = self.find(self.v[x]) return self.v[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False else: if self.v[x] > self.v[y]: x, y = y, x self.v[x] += self.v[y] self.v[y] = x return True def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.v[self.find(x)] def main(): import sys input = sys.stdin.readline N, M = map(int, input().split()) es = [] for _ in range(M): a, b = (int(x) - 1 for x in input().split()) es.append((a, b)) es.reverse() es.pop() uf = UnionFind(N) ans = [N * (N - 1) // 2] t = ans[-1] for a, b in es: if not uf.same(a, b): t -= uf.size(a) * uf.size(b) ans.append(t) uf.unite(a, b) ans.reverse() print(*ans, sep="\n") if __name__ == "__main__": main()
false
21.333333
[ "- collapse_schedule = []", "+ es = []", "- A, B = (int(x) - 1 for x in input().split())", "- collapse_schedule.append((A, B))", "- collapse_schedule.reverse()", "+ a, b = (int(x) - 1 for x in input().split())", "+ es.append((a, b))", "+ es.reverse()", "+ es.pop()", "-", "- def evaluate(size):", "- return size * (size - 1) // 2", "-", "- all_dropped = evaluate(N)", "- curr = all_dropped", "- ret = [-1] * M", "- ret[-1] = all_dropped", "- for i, (a, b) in zip(reversed(range(M - 1)), collapse_schedule):", "+ ans = [N * (N - 1) // 2]", "+ t = ans[-1]", "+ for a, b in es:", "- sa, sb = uf.size(a), uf.size(b)", "- ea, eb = evaluate(sa), evaluate(sb)", "- curr += ea + eb", "- uf.unite(a, b)", "- sa = uf.size(a)", "- ea = evaluate(sa)", "- curr -= ea", "- ret[i] = curr", "- print(*ret, sep=\"\\n\")", "+ t -= uf.size(a) * uf.size(b)", "+ ans.append(t)", "+ uf.unite(a, b)", "+ ans.reverse()", "+ print(*ans, sep=\"\\n\")" ]
false
0.036181
0.102288
0.353722
[ "s066744349", "s350716867" ]
u711539583
p02763
python
s612225503
s802235707
1,917
1,760
435,324
397,240
Accepted
Accepted
8.19
import sys input = sys.stdin.readline n = int(input().rstrip('\n')) s = input().rstrip('\n') l = [c for c in s] q = int(input().rstrip('\n')) Q = [input().rstrip('\n').split() for _ in range(q)] class SegTree(): def __init__(self, n_): self.n = 1 while self.n < n_: self.n *= 2 self.tree = [2 for _ in range(2 * self.n - 1)] def update(self, k, a): k += self.n - 1 self.tree[k] = a while k > 0: k = (k - 1) // 2 self.tree[k] = min(self.tree[k * 2 + 1], self.tree[k * 2 + 2]) def query(self, l, r): l += self.n - 1 r += self.n - 2 res = 2 while r-l>1: if l&1 == 0: res = min(res,self.tree[l]) if r&1 == 1: res = min(res,self.tree[r]) r -= 1 l = l//2 r = (r-1)//2 if l == r: res = min(res,self.tree[l]) else: res = min(min(res,self.tree[l]),self.tree[r]) return res d = { c: SegTree(n) for c in "abcdefghijklmnopqrstuvwxyz"} for i, c in enumerate(s): d[c].update(i, 1) for a, b, c in Q: if a == "1": b = int(b) - 1 d[l[b]].update(b, 2) d[c].update(b, 1) l[b] = c else: res = 0 b, c = int(b), int(c) for key in d: if d[key].query(b-1, c) == 1: res += 1 print(res)
import sys input = sys.stdin.readline n = int(input().rstrip('\n')) s = input().rstrip('\n') q = int(input().rstrip('\n')) Q = [] for _ in range(q): Q.append(input().rstrip().split()) class SegTree(): def __init__(self, n_): self.n = 1 while self.n < n_: self.n *= 2 self.tree = [] for _ in range(2 * self.n - 1): self.tree.append(2) def update(self, k, a): k += self.n - 1 self.tree[k] = a while k > 0: k = (k - 1) // 2 self.tree[k] = min(self.tree[k * 2 + 1], self.tree[k * 2 + 2]) def query(self, l, r): l += self.n - 1 r += self.n - 2 res = 2 while r-l>1: if l&1 == 0: res = min(res,self.tree[l]) if r&1 == 1: res = min(res,self.tree[r]) r -= 1 l = l//2 r = (r-1)//2 if l == r: res = min(res,self.tree[l]) else: res = min(min(res,self.tree[l]),self.tree[r]) return res d = { c: SegTree(n) for c in "abcdefghijklmnopqrstuvwxyz"} l = [] for i, c in enumerate(s): d[c].update(i, 1) l.append(c) for a, b, c in Q: if a == "1": b = int(b) - 1 d[l[b]].update(b, 2) d[c].update(b, 1) l[b] = c else: res = 0 b, c = int(b), int(c) for key in d: if d[key].query(b-1, c) == 1: res += 1 print(res)
58
63
1,500
1,561
import sys input = sys.stdin.readline n = int(input().rstrip("\n")) s = input().rstrip("\n") l = [c for c in s] q = int(input().rstrip("\n")) Q = [input().rstrip("\n").split() for _ in range(q)] class SegTree: def __init__(self, n_): self.n = 1 while self.n < n_: self.n *= 2 self.tree = [2 for _ in range(2 * self.n - 1)] def update(self, k, a): k += self.n - 1 self.tree[k] = a while k > 0: k = (k - 1) // 2 self.tree[k] = min(self.tree[k * 2 + 1], self.tree[k * 2 + 2]) def query(self, l, r): l += self.n - 1 r += self.n - 2 res = 2 while r - l > 1: if l & 1 == 0: res = min(res, self.tree[l]) if r & 1 == 1: res = min(res, self.tree[r]) r -= 1 l = l // 2 r = (r - 1) // 2 if l == r: res = min(res, self.tree[l]) else: res = min(min(res, self.tree[l]), self.tree[r]) return res d = {c: SegTree(n) for c in "abcdefghijklmnopqrstuvwxyz"} for i, c in enumerate(s): d[c].update(i, 1) for a, b, c in Q: if a == "1": b = int(b) - 1 d[l[b]].update(b, 2) d[c].update(b, 1) l[b] = c else: res = 0 b, c = int(b), int(c) for key in d: if d[key].query(b - 1, c) == 1: res += 1 print(res)
import sys input = sys.stdin.readline n = int(input().rstrip("\n")) s = input().rstrip("\n") q = int(input().rstrip("\n")) Q = [] for _ in range(q): Q.append(input().rstrip().split()) class SegTree: def __init__(self, n_): self.n = 1 while self.n < n_: self.n *= 2 self.tree = [] for _ in range(2 * self.n - 1): self.tree.append(2) def update(self, k, a): k += self.n - 1 self.tree[k] = a while k > 0: k = (k - 1) // 2 self.tree[k] = min(self.tree[k * 2 + 1], self.tree[k * 2 + 2]) def query(self, l, r): l += self.n - 1 r += self.n - 2 res = 2 while r - l > 1: if l & 1 == 0: res = min(res, self.tree[l]) if r & 1 == 1: res = min(res, self.tree[r]) r -= 1 l = l // 2 r = (r - 1) // 2 if l == r: res = min(res, self.tree[l]) else: res = min(min(res, self.tree[l]), self.tree[r]) return res d = {c: SegTree(n) for c in "abcdefghijklmnopqrstuvwxyz"} l = [] for i, c in enumerate(s): d[c].update(i, 1) l.append(c) for a, b, c in Q: if a == "1": b = int(b) - 1 d[l[b]].update(b, 2) d[c].update(b, 1) l[b] = c else: res = 0 b, c = int(b), int(c) for key in d: if d[key].query(b - 1, c) == 1: res += 1 print(res)
false
7.936508
[ "-l = [c for c in s]", "-Q = [input().rstrip(\"\\n\").split() for _ in range(q)]", "+Q = []", "+for _ in range(q):", "+ Q.append(input().rstrip().split())", "- self.tree = [2 for _ in range(2 * self.n - 1)]", "+ self.tree = []", "+ for _ in range(2 * self.n - 1):", "+ self.tree.append(2)", "+l = []", "+ l.append(c)" ]
false
0.039774
0.037822
1.051617
[ "s612225503", "s802235707" ]
u098012509
p03274
python
s175712892
s553256875
97
80
14,940
14,172
Accepted
Accepted
17.53
import sys input = sys.stdin.readline def main(): N, K = [int(x) for x in input().split()] x = [int(x) for x in input().split()] plus = [0] j = 0 for i in range(N): if x[i] >= 0: plus.append(x[i]) j += 1 j = 0 minus = [0] for i in range(N - 1, -1, -1): if x[i] < 0: minus.append(x[i]) j += 1 ans = float("inf") for i in range(0, K + 1): if len(plus) - 1 < i: continue if len(minus) - 1 < K - i: continue rsum = plus[i] lsum = abs(minus[K - i]) if rsum >= lsum: ans = min(ans, rsum + lsum * 2) else: ans = min(ans, rsum * 2 + lsum) print(ans) if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): N, K = [int(x) for x in input().split()] x = [int(x) for x in input().split()] ans = float("inf") for i in range(N + 1 - K): l = x[i] r = x[i + K - 1] if l < 0 < r: ans = min(ans, abs(l) + abs(r) + min(abs(l), abs(r))) else: ans = min(ans, max(abs(l), abs(r))) print(ans) if __name__ == '__main__': main()
47
25
849
473
import sys input = sys.stdin.readline def main(): N, K = [int(x) for x in input().split()] x = [int(x) for x in input().split()] plus = [0] j = 0 for i in range(N): if x[i] >= 0: plus.append(x[i]) j += 1 j = 0 minus = [0] for i in range(N - 1, -1, -1): if x[i] < 0: minus.append(x[i]) j += 1 ans = float("inf") for i in range(0, K + 1): if len(plus) - 1 < i: continue if len(minus) - 1 < K - i: continue rsum = plus[i] lsum = abs(minus[K - i]) if rsum >= lsum: ans = min(ans, rsum + lsum * 2) else: ans = min(ans, rsum * 2 + lsum) print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): N, K = [int(x) for x in input().split()] x = [int(x) for x in input().split()] ans = float("inf") for i in range(N + 1 - K): l = x[i] r = x[i + K - 1] if l < 0 < r: ans = min(ans, abs(l) + abs(r) + min(abs(l), abs(r))) else: ans = min(ans, max(abs(l), abs(r))) print(ans) if __name__ == "__main__": main()
false
46.808511
[ "- plus = [0]", "- j = 0", "- for i in range(N):", "- if x[i] >= 0:", "- plus.append(x[i])", "- j += 1", "- j = 0", "- minus = [0]", "- for i in range(N - 1, -1, -1):", "- if x[i] < 0:", "- minus.append(x[i])", "- j += 1", "- for i in range(0, K + 1):", "- if len(plus) - 1 < i:", "- continue", "- if len(minus) - 1 < K - i:", "- continue", "- rsum = plus[i]", "- lsum = abs(minus[K - i])", "- if rsum >= lsum:", "- ans = min(ans, rsum + lsum * 2)", "+ for i in range(N + 1 - K):", "+ l = x[i]", "+ r = x[i + K - 1]", "+ if l < 0 < r:", "+ ans = min(ans, abs(l) + abs(r) + min(abs(l), abs(r)))", "- ans = min(ans, rsum * 2 + lsum)", "+ ans = min(ans, max(abs(l), abs(r)))" ]
false
0.049524
0.048432
1.022541
[ "s175712892", "s553256875" ]
u703528810
p02683
python
s302432377
s615784183
365
82
85,432
9,756
Accepted
Accepted
77.53
N,M,X=list(map(int,input().split())) A=[list(map(int,input().split())) for _ in range(N)] S=[[0 for _ in range(M)] for _ in range(2**N)] cost=[] for i in range(2**N): b=bin(i)[2:].zfill(N) t_cost=0 for j in range(N): t_cost+=A[j][0]*int(b[j]) for m in range(M): S[i][m]+=A[j][m+1]*int(b[j]) if min(S[i])>=X: cost.append(t_cost) if len(cost)==0: print((-1)) else: print((min(cost)))
def dfs(bit): if len(bit)==N: c=0 s=[0 for _ in range(M)] for i in range(N): c+=A[i][0]*bit[i] if bit[i]==1: for j in range(M): s[j]+=A[i][j+1] cond=True for k in range(M): if s[k]<X: cond=False break if cond: ans.append(c) return else: for i in range(2): bit.append(i) dfs(bit) bit.pop() N,M,X=list(map(int,input().split())) A=[list(map(int,input().split())) for _ in range(N)] ans=[] dfs([]) if len(ans)==0: print((-1)) else: print((min(ans)))
20
35
457
766
N, M, X = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(N)] S = [[0 for _ in range(M)] for _ in range(2**N)] cost = [] for i in range(2**N): b = bin(i)[2:].zfill(N) t_cost = 0 for j in range(N): t_cost += A[j][0] * int(b[j]) for m in range(M): S[i][m] += A[j][m + 1] * int(b[j]) if min(S[i]) >= X: cost.append(t_cost) if len(cost) == 0: print((-1)) else: print((min(cost)))
def dfs(bit): if len(bit) == N: c = 0 s = [0 for _ in range(M)] for i in range(N): c += A[i][0] * bit[i] if bit[i] == 1: for j in range(M): s[j] += A[i][j + 1] cond = True for k in range(M): if s[k] < X: cond = False break if cond: ans.append(c) return else: for i in range(2): bit.append(i) dfs(bit) bit.pop() N, M, X = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(N)] ans = [] dfs([]) if len(ans) == 0: print((-1)) else: print((min(ans)))
false
42.857143
[ "+def dfs(bit):", "+ if len(bit) == N:", "+ c = 0", "+ s = [0 for _ in range(M)]", "+ for i in range(N):", "+ c += A[i][0] * bit[i]", "+ if bit[i] == 1:", "+ for j in range(M):", "+ s[j] += A[i][j + 1]", "+ cond = True", "+ for k in range(M):", "+ if s[k] < X:", "+ cond = False", "+ break", "+ if cond:", "+ ans.append(c)", "+ return", "+ else:", "+ for i in range(2):", "+ bit.append(i)", "+ dfs(bit)", "+ bit.pop()", "+", "+", "-S = [[0 for _ in range(M)] for _ in range(2**N)]", "-cost = []", "-for i in range(2**N):", "- b = bin(i)[2:].zfill(N)", "- t_cost = 0", "- for j in range(N):", "- t_cost += A[j][0] * int(b[j])", "- for m in range(M):", "- S[i][m] += A[j][m + 1] * int(b[j])", "- if min(S[i]) >= X:", "- cost.append(t_cost)", "-if len(cost) == 0:", "+ans = []", "+dfs([])", "+if len(ans) == 0:", "- print((min(cost)))", "+ print((min(ans)))" ]
false
0.040346
0.038025
1.061029
[ "s302432377", "s615784183" ]
u883048396
p03242
python
s117047080
s910314638
19
17
3,060
2,940
Accepted
Accepted
10.53
print((input().rstrip().replace("1","a").replace("9","1").replace("a","9")))
print((1110-int(eval(input()))))
1
1
75
24
print((input().rstrip().replace("1", "a").replace("9", "1").replace("a", "9")))
print((1110 - int(eval(input()))))
false
0
[ "-print((input().rstrip().replace(\"1\", \"a\").replace(\"9\", \"1\").replace(\"a\", \"9\")))", "+print((1110 - int(eval(input()))))" ]
false
0.037389
0.037446
0.998472
[ "s117047080", "s910314638" ]
u733814820
p03029
python
s484120041
s781185811
22
17
3,316
2,940
Accepted
Accepted
22.73
A, P = list(map(int, input().split())) P += A * 3 pie = P // 2 print(pie)
def resolve(): a, p = list(map(int, input().split())) print(((a*3+p) // 2)) return if __name__ == "__main__": resolve()
7
7
77
127
A, P = list(map(int, input().split())) P += A * 3 pie = P // 2 print(pie)
def resolve(): a, p = list(map(int, input().split())) print(((a * 3 + p) // 2)) return if __name__ == "__main__": resolve()
false
0
[ "-A, P = list(map(int, input().split()))", "-P += A * 3", "-pie = P // 2", "-print(pie)", "+def resolve():", "+ a, p = list(map(int, input().split()))", "+ print(((a * 3 + p) // 2))", "+ return", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.03246
0.03123
1.039371
[ "s484120041", "s781185811" ]
u099566485
p03361
python
s494558024
s918374775
204
186
40,176
40,176
Accepted
Accepted
8.82
#ABC096-C def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(eval(input())) def S(): return list(eval(input())) h,w=IL() S=[S() for i in range(h)] ret=True #grid周り探索 for i in range(h): for j in range(w): if S[i][j]==".": continue ans=False for ti in [-1,1]: if 0<=i+ti<h: if S[i+ti][j]=="#": ans=True for tj in [-1,1]: if 0<=j+tj<w: if S[i][j+tj]=="#": ans=True if not ans: ret=False if ret: print("Yes") else: print("No")
#ABC096-C def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(eval(input())) def S(): return list(eval(input())) h,w=IL() G=[["."]*(w+2)] for i in range(h): G.append(["."]+S()+["."]) G.append(["."]*(w+2)) ret=True #grid周り探索 for i in range(1,h): for j in range(1,w): if G[i][j]==".": continue ans=False for ti,tj in[[-1,0],[1,0],[0,1],[0,-1]]: if G[i+ti][j+tj]=="#": ans=True if not ans: ret=False if ret: print("Yes") else: print("No")
28
26
660
597
# ABC096-C def IL(): return list(map(int, input().split())) def SL(): return input().split() def I(): return int(eval(input())) def S(): return list(eval(input())) h, w = IL() S = [S() for i in range(h)] ret = True # grid周り探索 for i in range(h): for j in range(w): if S[i][j] == ".": continue ans = False for ti in [-1, 1]: if 0 <= i + ti < h: if S[i + ti][j] == "#": ans = True for tj in [-1, 1]: if 0 <= j + tj < w: if S[i][j + tj] == "#": ans = True if not ans: ret = False if ret: print("Yes") else: print("No")
# ABC096-C def IL(): return list(map(int, input().split())) def SL(): return input().split() def I(): return int(eval(input())) def S(): return list(eval(input())) h, w = IL() G = [["."] * (w + 2)] for i in range(h): G.append(["."] + S() + ["."]) G.append(["."] * (w + 2)) ret = True # grid周り探索 for i in range(1, h): for j in range(1, w): if G[i][j] == ".": continue ans = False for ti, tj in [[-1, 0], [1, 0], [0, 1], [0, -1]]: if G[i + ti][j + tj] == "#": ans = True if not ans: ret = False if ret: print("Yes") else: print("No")
false
7.142857
[ "-S = [S() for i in range(h)]", "+G = [[\".\"] * (w + 2)]", "+for i in range(h):", "+ G.append([\".\"] + S() + [\".\"])", "+G.append([\".\"] * (w + 2))", "-for i in range(h):", "- for j in range(w):", "- if S[i][j] == \".\":", "+for i in range(1, h):", "+ for j in range(1, w):", "+ if G[i][j] == \".\":", "- for ti in [-1, 1]:", "- if 0 <= i + ti < h:", "- if S[i + ti][j] == \"#\":", "- ans = True", "- for tj in [-1, 1]:", "- if 0 <= j + tj < w:", "- if S[i][j + tj] == \"#\":", "- ans = True", "+ for ti, tj in [[-1, 0], [1, 0], [0, 1], [0, -1]]:", "+ if G[i + ti][j + tj] == \"#\":", "+ ans = True" ]
false
0.047773
0.04744
1.007009
[ "s494558024", "s918374775" ]
u327466606
p02720
python
s243662791
s151819970
143
109
3,064
11,980
Accepted
Accepted
23.78
K = int(input()) N = [0] for _ in range(K): i = 0 while i < len(N) and N[i] == 9: i += 1 while i+1 < len(N) and N[i] == N[i+1]+1: i += 1 if i == len(N): N = [0]*len(N) + [1] else: N[i] += 1 i -= 1 while i >= 0: N[i] = max(N[i+1]-1,0) i -= 1 print(*reversed(N),sep='')
from collections import deque K = int(eval(input())) q = deque(list(range(1,10))) for _ in range(K): x = q.popleft() r = x%10 if r == 0: q.append(x*10) q.append(x*10+1) elif r == 9: q.append(x*10+8) q.append(x*10+9) else: q.append(x*10+r-1) q.append(x*10+r) q.append(x*10+r+1) print(x)
20
21
382
373
K = int(input()) N = [0] for _ in range(K): i = 0 while i < len(N) and N[i] == 9: i += 1 while i + 1 < len(N) and N[i] == N[i + 1] + 1: i += 1 if i == len(N): N = [0] * len(N) + [1] else: N[i] += 1 i -= 1 while i >= 0: N[i] = max(N[i + 1] - 1, 0) i -= 1 print(*reversed(N), sep="")
from collections import deque K = int(eval(input())) q = deque(list(range(1, 10))) for _ in range(K): x = q.popleft() r = x % 10 if r == 0: q.append(x * 10) q.append(x * 10 + 1) elif r == 9: q.append(x * 10 + 8) q.append(x * 10 + 9) else: q.append(x * 10 + r - 1) q.append(x * 10 + r) q.append(x * 10 + r + 1) print(x)
false
4.761905
[ "-K = int(input())", "-N = [0]", "+from collections import deque", "+", "+K = int(eval(input()))", "+q = deque(list(range(1, 10)))", "- i = 0", "- while i < len(N) and N[i] == 9:", "- i += 1", "- while i + 1 < len(N) and N[i] == N[i + 1] + 1:", "- i += 1", "- if i == len(N):", "- N = [0] * len(N) + [1]", "+ x = q.popleft()", "+ r = x % 10", "+ if r == 0:", "+ q.append(x * 10)", "+ q.append(x * 10 + 1)", "+ elif r == 9:", "+ q.append(x * 10 + 8)", "+ q.append(x * 10 + 9)", "- N[i] += 1", "- i -= 1", "- while i >= 0:", "- N[i] = max(N[i + 1] - 1, 0)", "- i -= 1", "-print(*reversed(N), sep=\"\")", "+ q.append(x * 10 + r - 1)", "+ q.append(x * 10 + r)", "+ q.append(x * 10 + r + 1)", "+print(x)" ]
false
0.252729
0.05637
4.483405
[ "s243662791", "s151819970" ]
u562935282
p03674
python
s397000173
s155251071
513
299
28,268
28,292
Accepted
Accepted
41.72
class Calc: def __init__(self, max_value, mod): """combination(max_value, all)""" fact = [-1] * (max_value + 1) fact[0] = 1 fact[1] = 1 for x in range(2, max_value + 1): fact[x] = x * fact[x - 1] % mod invs = [1] * (max_value + 1) invs[max_value] = pow(fact[max_value], mod - 2, mod) for x in range(max_value - 1, 0, -1): invs[x] = invs[x + 1] * (x + 1) % mod self.fact = fact self.invs = invs self.mod = mod def nCr(self, n, r): r = min(n - r, r) if r < 0: return 0 if r == 0: return 1 if r == 1: return n return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod def nHr(self, n, r): return self.nCr(n - 1 + r, r) def main(): MOD = 10 ** 9 + 7 N = int(input()) A = map(int, input().split()) B = [-1] * (N + 1) # はじめて出現する位置(0-ind) d = None # 重複要素の出現位置(2点) for i, x in enumerate(A): if ~B[x]: d = B[x], i break B[x] = i # 重複要素L,R(d[0],d[1]),一度だけ出現する数の列X,Y,Z(|X|>=0,|Y|>=0,|Z|>=0) # X...LY...RZ... # 重複計上: choose(N+1,K) # ここから重複分を差し引く # LRを含む個数 # 0個: 重複計上なし # 1個: (X,L,YZ)と(XY,R,Z)が一致する場合に重複計上になる==(X,L/R,Z) # -> # #==sum(choose(X,a)*choose(Z,K-1-a)),(0<=a<=K-1) # 見方を変える # Yの区間以外からK個選ぶ # ただし,Yの区間外のうちLRから0個取るものと2個取るものを差し引く # 残りは(X,L/R,Z)を二重計上したものなので,半分にする # (choose(N+1-Y,K) - choose(N+1-2-Y,K) - choose(N+1-2-Y,K-2)) // 2 # 2個: 重複計上なし calc = Calc(max_value=N + 1, mod=MOD) ans = [] Y = d[1] - 1 - d[0] div2 = pow(2, MOD - 2, MOD) for k in range(1, N + 2): t = ( calc.nCr(N + 1, k) - ( calc.nCr(N + 1 - Y, k) - calc.nCr(N + 1 - 2 - Y, k) - calc.nCr(N + 1 - 2 - Y, k - 2) ) * div2 % MOD ) % MOD ans.append(t) print(*ans, sep='\n') if __name__ == '__main__': main()
class Calc: def __init__(self, max_value, mod): """combination(max_value, all)""" fact = [-1] * (max_value + 1) fact[0] = 1 fact[1] = 1 for x in range(2, max_value + 1): fact[x] = x * fact[x - 1] % mod invs = [1] * (max_value + 1) invs[max_value] = pow(fact[max_value], mod - 2, mod) for x in range(max_value - 1, 0, -1): invs[x] = invs[x + 1] * (x + 1) % mod self.fact = fact self.invs = invs self.mod = mod def nCr(self, n, r): r = min(n - r, r) if r < 0: return 0 if r == 0: return 1 if r == 1: return n return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod def nHr(self, n, r): return self.nCr(n - 1 + r, r) def main(): MOD = 10 ** 9 + 7 N = int(input()) A = map(int, input().split()) B = [-1] * (N + 1) # はじめて出現する位置(0-ind) d = None # 重複要素の出現位置(2点) for i, x in enumerate(A): if ~B[x]: d = B[x], i break B[x] = i # 重複要素L,R(d[0],d[1]),一度だけ出現する数の列X,Y,Z(|X|>=0,|Y|>=0,|Z|>=0) # X...LY...RZ... # 重複計上: choose(N+1,K) # ここから重複分を差し引く # LRを含む個数 # 0個: 重複計上なし # 1個: (X,L,YZ)と(XY,R,Z)が一致する場合に重複計上になる==(X,L/R,Z) # -> # #==sum(choose(X,a)*choose(Z,K-1-a)),(0<=a<=K-1) # 見方を変える # Yの区間以外からK個選ぶ # ただし,Yの区間外のうちLRから0個取るものと2個取るものを差し引く # 残りは(X,L/R,Z)を二重計上したものなので,半分にする # (choose(N+1-Y,K) - choose(N+1-2-Y,K) - choose(N+1-2-Y,K-2)) // 2 # <editorial> # LRから1個,XZからK-1個取るchoose(XZ,K-1)=choose(N+1-2-Y,K-1)でよい # 2個: 重複計上なし calc = Calc(max_value=N + 1, mod=MOD) ans = [] Y = d[1] - 1 - d[0] for k in range(1, N + 2): ans.append((calc.nCr(N + 1, k) - calc.nCr(N + 1 - 2 - Y, k - 1)) % MOD) print(*ans, sep='\n') if __name__ == '__main__': main()
79
72
2,160
1,957
class Calc: def __init__(self, max_value, mod): """combination(max_value, all)""" fact = [-1] * (max_value + 1) fact[0] = 1 fact[1] = 1 for x in range(2, max_value + 1): fact[x] = x * fact[x - 1] % mod invs = [1] * (max_value + 1) invs[max_value] = pow(fact[max_value], mod - 2, mod) for x in range(max_value - 1, 0, -1): invs[x] = invs[x + 1] * (x + 1) % mod self.fact = fact self.invs = invs self.mod = mod def nCr(self, n, r): r = min(n - r, r) if r < 0: return 0 if r == 0: return 1 if r == 1: return n return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod def nHr(self, n, r): return self.nCr(n - 1 + r, r) def main(): MOD = 10**9 + 7 N = int(input()) A = map(int, input().split()) B = [-1] * (N + 1) # はじめて出現する位置(0-ind) d = None # 重複要素の出現位置(2点) for i, x in enumerate(A): if ~B[x]: d = B[x], i break B[x] = i # 重複要素L,R(d[0],d[1]),一度だけ出現する数の列X,Y,Z(|X|>=0,|Y|>=0,|Z|>=0) # X...LY...RZ... # 重複計上: choose(N+1,K) # ここから重複分を差し引く # LRを含む個数 # 0個: 重複計上なし # 1個: (X,L,YZ)と(XY,R,Z)が一致する場合に重複計上になる==(X,L/R,Z) # -> # #==sum(choose(X,a)*choose(Z,K-1-a)),(0<=a<=K-1) # 見方を変える # Yの区間以外からK個選ぶ # ただし,Yの区間外のうちLRから0個取るものと2個取るものを差し引く # 残りは(X,L/R,Z)を二重計上したものなので,半分にする # (choose(N+1-Y,K) - choose(N+1-2-Y,K) - choose(N+1-2-Y,K-2)) // 2 # 2個: 重複計上なし calc = Calc(max_value=N + 1, mod=MOD) ans = [] Y = d[1] - 1 - d[0] div2 = pow(2, MOD - 2, MOD) for k in range(1, N + 2): t = ( calc.nCr(N + 1, k) - ( calc.nCr(N + 1 - Y, k) - calc.nCr(N + 1 - 2 - Y, k) - calc.nCr(N + 1 - 2 - Y, k - 2) ) * div2 % MOD ) % MOD ans.append(t) print(*ans, sep="\n") if __name__ == "__main__": main()
class Calc: def __init__(self, max_value, mod): """combination(max_value, all)""" fact = [-1] * (max_value + 1) fact[0] = 1 fact[1] = 1 for x in range(2, max_value + 1): fact[x] = x * fact[x - 1] % mod invs = [1] * (max_value + 1) invs[max_value] = pow(fact[max_value], mod - 2, mod) for x in range(max_value - 1, 0, -1): invs[x] = invs[x + 1] * (x + 1) % mod self.fact = fact self.invs = invs self.mod = mod def nCr(self, n, r): r = min(n - r, r) if r < 0: return 0 if r == 0: return 1 if r == 1: return n return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod def nHr(self, n, r): return self.nCr(n - 1 + r, r) def main(): MOD = 10**9 + 7 N = int(input()) A = map(int, input().split()) B = [-1] * (N + 1) # はじめて出現する位置(0-ind) d = None # 重複要素の出現位置(2点) for i, x in enumerate(A): if ~B[x]: d = B[x], i break B[x] = i # 重複要素L,R(d[0],d[1]),一度だけ出現する数の列X,Y,Z(|X|>=0,|Y|>=0,|Z|>=0) # X...LY...RZ... # 重複計上: choose(N+1,K) # ここから重複分を差し引く # LRを含む個数 # 0個: 重複計上なし # 1個: (X,L,YZ)と(XY,R,Z)が一致する場合に重複計上になる==(X,L/R,Z) # -> # #==sum(choose(X,a)*choose(Z,K-1-a)),(0<=a<=K-1) # 見方を変える # Yの区間以外からK個選ぶ # ただし,Yの区間外のうちLRから0個取るものと2個取るものを差し引く # 残りは(X,L/R,Z)を二重計上したものなので,半分にする # (choose(N+1-Y,K) - choose(N+1-2-Y,K) - choose(N+1-2-Y,K-2)) // 2 # <editorial> # LRから1個,XZからK-1個取るchoose(XZ,K-1)=choose(N+1-2-Y,K-1)でよい # 2個: 重複計上なし calc = Calc(max_value=N + 1, mod=MOD) ans = [] Y = d[1] - 1 - d[0] for k in range(1, N + 2): ans.append((calc.nCr(N + 1, k) - calc.nCr(N + 1 - 2 - Y, k - 1)) % MOD) print(*ans, sep="\n") if __name__ == "__main__": main()
false
8.860759
[ "+ # <editorial>", "+ # LRから1個,XZからK-1個取るchoose(XZ,K-1)=choose(N+1-2-Y,K-1)でよい", "- div2 = pow(2, MOD - 2, MOD)", "- t = (", "- calc.nCr(N + 1, k)", "- - (", "- calc.nCr(N + 1 - Y, k)", "- - calc.nCr(N + 1 - 2 - Y, k)", "- - calc.nCr(N + 1 - 2 - Y, k - 2)", "- )", "- * div2", "- % MOD", "- ) % MOD", "- ans.append(t)", "+ ans.append((calc.nCr(N + 1, k) - calc.nCr(N + 1 - 2 - Y, k - 1)) % MOD)" ]
false
0.081318
0.078393
1.037306
[ "s397000173", "s155251071" ]
u622045059
p03162
python
s842033620
s480034301
769
477
100,180
95,960
Accepted
Accepted
37.97
import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9+7 def gcd(a,b):return fractions.gcd(a,b) #最大公約数 def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数 def iin(): return int(eval(input())) #整数読み込み def ifn(): return float(eval(input())) #浮動小数点読み込み def isn(): return input().split() #文字列読み込み def imn(): return list(map(int, input().split())) #整数map取得 def fmn(): return list(map(float, input().split())) #浮動小数点map取得 def iln(): return list(map(int, input().split())) #整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得 def join(l, s=''): return s.join(l) #リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数 def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離 def m_add(a,b): return (a+b) % MOD N = iin() abc = [iln() for _ in range(N)] dp = [[0 for _ in range(3)] for _ in range(N+1)] for i in range(N): for j in range(3): for k in range(3): if j == k: continue dp[i+1][k] = max(dp[i+1][k], dp[i][j]+abc[i][k]) print((max(dp[N])))
# python3.4.2用 import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from decimal import * from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9+7 INF = float('inf') #無限大 def gcd(a,b):return fractions.gcd(a,b) #最大公約数 def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数 def iin(): return int(sys.stdin.readline()) #整数読み込み def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み def isn(): return sys.stdin.readline().split() #文字列読み込み def imn(): return map(int, sys.stdin.readline().split()) #整数map取得 def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得 def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得 def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得 def join(l, s=''): return s.join(l) #リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数 def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離 def m_add(a,b): return (a+b) % MOD def lprint(l): print(*l, sep='\n') def sieves_of_e(n): is_prime = [True] * (n+1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5)+1): if not is_prime[i]: continue for j in range(i * 2, n+1, i): is_prime[j] = False return is_prime N = iin() abc = [iln() for _ in range(N)] dp = [[0 for _ in range(3)] for _ in range(N+1)] for i in range(N): for j in range(3): for k in range(3): if j == k: continue dp[i+1][j] = max(dp[i+1][j], dp[i][k]+abc[i][j]) print(max(dp[N]))
43
55
1,545
2,077
import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9 + 7 def gcd(a, b): return fractions.gcd(a, b) # 最大公約数 def lcm(a, b): return (a * b) // fractions.gcd(a, b) # 最小公倍数 def iin(): return int(eval(input())) # 整数読み込み def ifn(): return float(eval(input())) # 浮動小数点読み込み def isn(): return input().split() # 文字列読み込み def imn(): return list(map(int, input().split())) # 整数map取得 def fmn(): return list(map(float, input().split())) # 浮動小数点map取得 def iln(): return list(map(int, input().split())) # 整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得 def join(l, s=""): return s.join(l) # リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n - r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) # 組み合わせの総数 def two_distance(a, b, c, d): return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2点間の距離 def m_add(a, b): return (a + b) % MOD N = iin() abc = [iln() for _ in range(N)] dp = [[0 for _ in range(3)] for _ in range(N + 1)] for i in range(N): for j in range(3): for k in range(3): if j == k: continue dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abc[i][k]) print((max(dp[N])))
# python3.4.2用 import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from decimal import * from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9 + 7 INF = float("inf") # 無限大 def gcd(a, b): return fractions.gcd(a, b) # 最大公約数 def lcm(a, b): return (a * b) // fractions.gcd(a, b) # 最小公倍数 def iin(): return int(sys.stdin.readline()) # 整数読み込み def ifn(): return float(sys.stdin.readline()) # 浮動小数点読み込み def isn(): return sys.stdin.readline().split() # 文字列読み込み def imn(): return map(int, sys.stdin.readline().split()) # 整数map取得 def imnn(): return map(lambda x: int(x) - 1, sys.stdin.readline().split()) # 整数-1map取得 def fmn(): return map(float, sys.stdin.readline().split()) # 浮動小数点map取得 def iln(): return list(map(int, sys.stdin.readline().split())) # 整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得 def join(l, s=""): return s.join(l) # リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n - r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) # 組み合わせの総数 def two_distance(a, b, c, d): return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2点間の距離 def m_add(a, b): return (a + b) % MOD def lprint(l): print(*l, sep="\n") def sieves_of_e(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return is_prime N = iin() abc = [iln() for _ in range(N)] dp = [[0 for _ in range(3)] for _ in range(N + 1)] for i in range(N): for j in range(3): for k in range(3): if j == k: continue dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + abc[i][j]) print(max(dp[N]))
false
21.818182
[ "+# python3.4.2用", "+from decimal import *", "+INF = float(\"inf\") # 無限大", "- return int(eval(input())) # 整数読み込み", "+ return int(sys.stdin.readline()) # 整数読み込み", "- return float(eval(input())) # 浮動小数点読み込み", "+ return float(sys.stdin.readline()) # 浮動小数点読み込み", "- return input().split() # 文字列読み込み", "+ return sys.stdin.readline().split() # 文字列読み込み", "- return list(map(int, input().split())) # 整数map取得", "+ return map(int, sys.stdin.readline().split()) # 整数map取得", "+", "+", "+def imnn():", "+ return map(lambda x: int(x) - 1, sys.stdin.readline().split()) # 整数-1map取得", "- return list(map(float, input().split())) # 浮動小数点map取得", "+ return map(float, sys.stdin.readline().split()) # 浮動小数点map取得", "- return list(map(int, input().split())) # 整数リスト取得", "+ return list(map(int, sys.stdin.readline().split())) # 整数リスト取得", "- return list(map(float, input().split())) # 浮動小数点リスト取得", "+ return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得", "+def lprint(l):", "+ print(*l, sep=\"\\n\")", "+", "+", "+def sieves_of_e(n):", "+ is_prime = [True] * (n + 1)", "+ is_prime[0] = False", "+ is_prime[1] = False", "+ for i in range(2, int(n**0.5) + 1):", "+ if not is_prime[i]:", "+ continue", "+ for j in range(i * 2, n + 1, i):", "+ is_prime[j] = False", "+ return is_prime", "+", "+", "- dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abc[i][k])", "-print((max(dp[N])))", "+ dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + abc[i][j])", "+print(max(dp[N]))" ]
false
0.156634
0.106677
1.468295
[ "s842033620", "s480034301" ]
u073097598
p03161
python
s082089579
s737830695
380
312
52,448
53,216
Accepted
Accepted
17.89
import sys n,k = list(map(int,input().split())) l = list(map(int, input().split())) dp = [sys.maxsize] *n dp[0] = 0 for i in range(n): for j in range(i+1,i+k+1): if(j<n): dp[j]=min(dp[j],dp[i]+abs(l[i]-l[j])) print((dp[n-1]))
import sys def frog(): for i in range(n): for j in range(i+1,i+k+1): if(j<n): dp[j]=min(dp[j],dp[i]+abs(l[i]-l[j])) return dp[n-1] if __name__ == "__main__": n,k=list(map(int,input().split())) dp = [sys.maxsize] * n dp[0] = 0 l = list(map(int, input().split())) sys.stdout.write(str(frog()))
10
13
250
381
import sys n, k = list(map(int, input().split())) l = list(map(int, input().split())) dp = [sys.maxsize] * n dp[0] = 0 for i in range(n): for j in range(i + 1, i + k + 1): if j < n: dp[j] = min(dp[j], dp[i] + abs(l[i] - l[j])) print((dp[n - 1]))
import sys def frog(): for i in range(n): for j in range(i + 1, i + k + 1): if j < n: dp[j] = min(dp[j], dp[i] + abs(l[i] - l[j])) return dp[n - 1] if __name__ == "__main__": n, k = list(map(int, input().split())) dp = [sys.maxsize] * n dp[0] = 0 l = list(map(int, input().split())) sys.stdout.write(str(frog()))
false
23.076923
[ "-n, k = list(map(int, input().split()))", "-l = list(map(int, input().split()))", "-dp = [sys.maxsize] * n", "-dp[0] = 0", "-for i in range(n):", "- for j in range(i + 1, i + k + 1):", "- if j < n:", "- dp[j] = min(dp[j], dp[i] + abs(l[i] - l[j]))", "-print((dp[n - 1]))", "+", "+def frog():", "+ for i in range(n):", "+ for j in range(i + 1, i + k + 1):", "+ if j < n:", "+ dp[j] = min(dp[j], dp[i] + abs(l[i] - l[j]))", "+ return dp[n - 1]", "+", "+", "+if __name__ == \"__main__\":", "+ n, k = list(map(int, input().split()))", "+ dp = [sys.maxsize] * n", "+ dp[0] = 0", "+ l = list(map(int, input().split()))", "+ sys.stdout.write(str(frog()))" ]
false
0.060885
0.041391
1.470984
[ "s082089579", "s737830695" ]
u142415823
p03495
python
s510126676
s927464753
176
138
32,556
20,184
Accepted
Accepted
21.59
import collections def calc(A, K): dist = {} tmp = collections.Counter(A) type_ = len(tmp) if type_ <= K: return 0 for a, count in list(tmp.items()): if count not in list(dist.keys()): dist[count] = [a] else: dist[count].append(a) rewrite = 0 i = 0 for c in sorted(dist.keys()): for _ in dist[c]: i += 1 rewrite += c if i == type_ - K: return rewrite def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) ans = calc(A, K) print(ans) if __name__ == "__main__": main()
N, K = list(map(int, input().split())) cnt = [0 for _ in range(N)] for i in map(int, input().split()): cnt[i-1] += 1 ans = 0 for i in sorted(cnt)[:N - K]: ans += i print(ans)
36
11
686
189
import collections def calc(A, K): dist = {} tmp = collections.Counter(A) type_ = len(tmp) if type_ <= K: return 0 for a, count in list(tmp.items()): if count not in list(dist.keys()): dist[count] = [a] else: dist[count].append(a) rewrite = 0 i = 0 for c in sorted(dist.keys()): for _ in dist[c]: i += 1 rewrite += c if i == type_ - K: return rewrite def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) ans = calc(A, K) print(ans) if __name__ == "__main__": main()
N, K = list(map(int, input().split())) cnt = [0 for _ in range(N)] for i in map(int, input().split()): cnt[i - 1] += 1 ans = 0 for i in sorted(cnt)[: N - K]: ans += i print(ans)
false
69.444444
[ "-import collections", "-", "-", "-def calc(A, K):", "- dist = {}", "- tmp = collections.Counter(A)", "- type_ = len(tmp)", "- if type_ <= K:", "- return 0", "- for a, count in list(tmp.items()):", "- if count not in list(dist.keys()):", "- dist[count] = [a]", "- else:", "- dist[count].append(a)", "- rewrite = 0", "- i = 0", "- for c in sorted(dist.keys()):", "- for _ in dist[c]:", "- i += 1", "- rewrite += c", "- if i == type_ - K:", "- return rewrite", "-", "-", "-def main():", "- N, K = list(map(int, input().split()))", "- A = list(map(int, input().split()))", "- ans = calc(A, K)", "- print(ans)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+N, K = list(map(int, input().split()))", "+cnt = [0 for _ in range(N)]", "+for i in map(int, input().split()):", "+ cnt[i - 1] += 1", "+ans = 0", "+for i in sorted(cnt)[: N - K]:", "+ ans += i", "+print(ans)" ]
false
0.034024
0.119938
0.283678
[ "s510126676", "s927464753" ]
u857293613
p02887
python
s317585852
s247869703
53
42
15,860
3,316
Accepted
Accepted
20.75
import itertools n = int(eval(input())) s = eval(input()) gr = itertools.groupby(s) print((len(list(gr))))
n = int(eval(input())) s = eval(input()) ans = 1 for i in range(n-1): if s[i] != s[i+1]: ans += 1 print(ans)
5
7
96
114
import itertools n = int(eval(input())) s = eval(input()) gr = itertools.groupby(s) print((len(list(gr))))
n = int(eval(input())) s = eval(input()) ans = 1 for i in range(n - 1): if s[i] != s[i + 1]: ans += 1 print(ans)
false
28.571429
[ "-import itertools", "-", "-gr = itertools.groupby(s)", "-print((len(list(gr))))", "+ans = 1", "+for i in range(n - 1):", "+ if s[i] != s[i + 1]:", "+ ans += 1", "+print(ans)" ]
false
0.100687
0.118373
0.850591
[ "s317585852", "s247869703" ]
u445624660
p03910
python
s726264095
s439960031
299
22
43,740
3,444
Accepted
Accepted
92.64
# 最大値の最小値、ちょうどn/2臭い # あとは帳尻合わせが効きそう # 14とかだと7+4+2+1 (7+5+2でも7+4+3でもいい # かと思いきや 1+2+3+4+5で15いくので, 5+4+3+2でよかった # 10^7なので毎回足してもどうせ間に合う。これで答えの集合のうち最大値は確定 # あとはそれでnを引いて0になるまで -> これだと間に合わない n = int(eval(input())) ans = [] cur = 0 while cur != n: tmp = 0 for i in range(1, n + 1 - cur): if i + tmp >= n - cur: tmp = i break tmp += i ans.append(tmp) cur += tmp # print("tmp = {}, cur = {}".format(tmp, cur)) # print(ans) for a in ans: print(a)
# 解説を観たのでそれをやってみるバージョン # (最初に解いたやつは愚直に毎回最大値を求めていた(なんかしらんけど通った)) n = int(eval(input())) cur = 0 target = 0 for i in range(1, n + 1): if i + cur >= n: target = i break cur += i remove_num = sum([i for i in range(1, target + 1)]) - n for i in range(1, target + 1): if i != remove_num: print(i)
24
16
520
338
# 最大値の最小値、ちょうどn/2臭い # あとは帳尻合わせが効きそう # 14とかだと7+4+2+1 (7+5+2でも7+4+3でもいい # かと思いきや 1+2+3+4+5で15いくので, 5+4+3+2でよかった # 10^7なので毎回足してもどうせ間に合う。これで答えの集合のうち最大値は確定 # あとはそれでnを引いて0になるまで -> これだと間に合わない n = int(eval(input())) ans = [] cur = 0 while cur != n: tmp = 0 for i in range(1, n + 1 - cur): if i + tmp >= n - cur: tmp = i break tmp += i ans.append(tmp) cur += tmp # print("tmp = {}, cur = {}".format(tmp, cur)) # print(ans) for a in ans: print(a)
# 解説を観たのでそれをやってみるバージョン # (最初に解いたやつは愚直に毎回最大値を求めていた(なんかしらんけど通った)) n = int(eval(input())) cur = 0 target = 0 for i in range(1, n + 1): if i + cur >= n: target = i break cur += i remove_num = sum([i for i in range(1, target + 1)]) - n for i in range(1, target + 1): if i != remove_num: print(i)
false
33.333333
[ "-# 最大値の最小値、ちょうどn/2臭い", "-# あとは帳尻合わせが効きそう", "-# 14とかだと7+4+2+1 (7+5+2でも7+4+3でもいい", "-# かと思いきや 1+2+3+4+5で15いくので, 5+4+3+2でよかった", "-# 10^7なので毎回足してもどうせ間に合う。これで答えの集合のうち最大値は確定", "-# あとはそれでnを引いて0になるまで -> これだと間に合わない", "+# 解説を観たのでそれをやってみるバージョン", "+# (最初に解いたやつは愚直に毎回最大値を求めていた(なんかしらんけど通った))", "-ans = []", "-while cur != n:", "- tmp = 0", "- for i in range(1, n + 1 - cur):", "- if i + tmp >= n - cur:", "- tmp = i", "- break", "- tmp += i", "- ans.append(tmp)", "- cur += tmp", "- # print(\"tmp = {}, cur = {}\".format(tmp, cur))", "-# print(ans)", "-for a in ans:", "- print(a)", "+target = 0", "+for i in range(1, n + 1):", "+ if i + cur >= n:", "+ target = i", "+ break", "+ cur += i", "+remove_num = sum([i for i in range(1, target + 1)]) - n", "+for i in range(1, target + 1):", "+ if i != remove_num:", "+ print(i)" ]
false
0.039651
0.035427
1.119233
[ "s726264095", "s439960031" ]
u600402037
p04012
python
s433776851
s819474951
21
17
3,316
2,940
Accepted
Accepted
19.05
import collections W = eval(input()) c = collections.Counter(W) answer = 'Yes' for w in c: if c[w] % 2 == 1: answer = 'No' print(answer)
W = eval(input()) print(('Yes' if all([W.count(x)%2==0 for x in set(W)]) else 'No'))
8
2
149
82
import collections W = eval(input()) c = collections.Counter(W) answer = "Yes" for w in c: if c[w] % 2 == 1: answer = "No" print(answer)
W = eval(input()) print(("Yes" if all([W.count(x) % 2 == 0 for x in set(W)]) else "No"))
false
75
[ "-import collections", "-", "-c = collections.Counter(W)", "-answer = \"Yes\"", "-for w in c:", "- if c[w] % 2 == 1:", "- answer = \"No\"", "-print(answer)", "+print((\"Yes\" if all([W.count(x) % 2 == 0 for x in set(W)]) else \"No\"))" ]
false
0.04174
0.041487
1.006093
[ "s433776851", "s819474951" ]
u451017206
p03078
python
s901400575
s469103340
971
687
138,864
9,528
Accepted
Accepted
29.25
X, Y, Z, K = list(map(int, input().split())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] C = [int(i) for i in input().split()] AB = sorted([a + b for a in A for b in B], reverse=True)[:K] ABC = sorted([ab + c for ab in AB for c in C], reverse=True)[:K] for a in ABC: print(a)
X, Y, Z, K = list(map(int, input().split())) A = sorted([int(i) for i in input().split()], reverse=True) B = sorted([int(i) for i in input().split()], reverse=True) C = sorted([int(i) for i in input().split()], reverse=True) a = [] for x in range(X): for y in range(Y): for z in range(Z): if ((x + 1) * (y + 1) * (z + 1) <= K): a.append(A[x] + B[y] + C[z]) else: break for b in sorted(a, reverse=True)[:K]: print(b)
9
16
315
499
X, Y, Z, K = list(map(int, input().split())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] C = [int(i) for i in input().split()] AB = sorted([a + b for a in A for b in B], reverse=True)[:K] ABC = sorted([ab + c for ab in AB for c in C], reverse=True)[:K] for a in ABC: print(a)
X, Y, Z, K = list(map(int, input().split())) A = sorted([int(i) for i in input().split()], reverse=True) B = sorted([int(i) for i in input().split()], reverse=True) C = sorted([int(i) for i in input().split()], reverse=True) a = [] for x in range(X): for y in range(Y): for z in range(Z): if (x + 1) * (y + 1) * (z + 1) <= K: a.append(A[x] + B[y] + C[z]) else: break for b in sorted(a, reverse=True)[:K]: print(b)
false
43.75
[ "-A = [int(i) for i in input().split()]", "-B = [int(i) for i in input().split()]", "-C = [int(i) for i in input().split()]", "-AB = sorted([a + b for a in A for b in B], reverse=True)[:K]", "-ABC = sorted([ab + c for ab in AB for c in C], reverse=True)[:K]", "-for a in ABC:", "- print(a)", "+A = sorted([int(i) for i in input().split()], reverse=True)", "+B = sorted([int(i) for i in input().split()], reverse=True)", "+C = sorted([int(i) for i in input().split()], reverse=True)", "+a = []", "+for x in range(X):", "+ for y in range(Y):", "+ for z in range(Z):", "+ if (x + 1) * (y + 1) * (z + 1) <= K:", "+ a.append(A[x] + B[y] + C[z])", "+ else:", "+ break", "+for b in sorted(a, reverse=True)[:K]:", "+ print(b)" ]
false
0.037671
0.036138
1.042409
[ "s901400575", "s469103340" ]
u807864121
p02990
python
s237363614
s454741022
468
20
3,820
3,316
Accepted
Accepted
95.73
def comb(n, r): if n < 0 or r < 0: raise ValueError r = min(r, n - r) if n == 0 or r == 0: return 1 return (n - r + 1) * comb(n, r - 1) // r N, K = list(map(int, input().split())) for i in range(K): if N - K + 1 < i + 1: print('0') continue print((comb(N - K + 1, i + 1) * comb(K - 1, i) % (10 ** 9 + 7)))
N, K = list(map(int, input().split())) a = N - K + 1 print(a) for i in range(1, K): a = a * (N - K + 1 - i) * (K - i) // ((i + 1) * i) print((a % (10 ** 9 + 7)))
14
6
345
168
def comb(n, r): if n < 0 or r < 0: raise ValueError r = min(r, n - r) if n == 0 or r == 0: return 1 return (n - r + 1) * comb(n, r - 1) // r N, K = list(map(int, input().split())) for i in range(K): if N - K + 1 < i + 1: print("0") continue print((comb(N - K + 1, i + 1) * comb(K - 1, i) % (10**9 + 7)))
N, K = list(map(int, input().split())) a = N - K + 1 print(a) for i in range(1, K): a = a * (N - K + 1 - i) * (K - i) // ((i + 1) * i) print((a % (10**9 + 7)))
false
57.142857
[ "-def comb(n, r):", "- if n < 0 or r < 0:", "- raise ValueError", "- r = min(r, n - r)", "- if n == 0 or r == 0:", "- return 1", "- return (n - r + 1) * comb(n, r - 1) // r", "-", "-", "-for i in range(K):", "- if N - K + 1 < i + 1:", "- print(\"0\")", "- continue", "- print((comb(N - K + 1, i + 1) * comb(K - 1, i) % (10**9 + 7)))", "+a = N - K + 1", "+print(a)", "+for i in range(1, K):", "+ a = a * (N - K + 1 - i) * (K - i) // ((i + 1) * i)", "+ print((a % (10**9 + 7)))" ]
false
0.071805
0.034889
2.058107
[ "s237363614", "s454741022" ]
u724687935
p02547
python
s134884368
s231187405
30
23
9,172
9,200
Accepted
Accepted
23.33
N = int(eval(input())) D = [tuple(map(int, input().split())) for _ in range(N)] for i in range(N - 2): if all(d[0] == d[1] for d in D[i: i + 3]): print('Yes') exit() else: print('No')
def input_array(): return list(map(int,input().split())) n=int(eval(input())) D=[input_array() for i in range(n)] count=0 for d in D: if d[0]==d[1]: count+=1 else: count=0 if count==3: break if count==3: print("Yes") else: print("No")
8
19
209
263
N = int(eval(input())) D = [tuple(map(int, input().split())) for _ in range(N)] for i in range(N - 2): if all(d[0] == d[1] for d in D[i : i + 3]): print("Yes") exit() else: print("No")
def input_array(): return list(map(int, input().split())) n = int(eval(input())) D = [input_array() for i in range(n)] count = 0 for d in D: if d[0] == d[1]: count += 1 else: count = 0 if count == 3: break if count == 3: print("Yes") else: print("No")
false
57.894737
[ "-N = int(eval(input()))", "-D = [tuple(map(int, input().split())) for _ in range(N)]", "-for i in range(N - 2):", "- if all(d[0] == d[1] for d in D[i : i + 3]):", "- print(\"Yes\")", "- exit()", "+def input_array():", "+ return list(map(int, input().split()))", "+", "+", "+n = int(eval(input()))", "+D = [input_array() for i in range(n)]", "+count = 0", "+for d in D:", "+ if d[0] == d[1]:", "+ count += 1", "+ else:", "+ count = 0", "+ if count == 3:", "+ break", "+if count == 3:", "+ print(\"Yes\")" ]
false
0.033861
0.034875
0.970923
[ "s134884368", "s231187405" ]
u936985471
p02818
python
s028897911
s401721507
20
17
3,316
2,940
Accepted
Accepted
15
A,B,K=list(map(int,input().split())) if A>=K: print((A-K,B)) elif A<K and A+B>K: print((0,B-(K-A))) else: print((0,0))
A,B,K=list(map(int,input().split())) print((max(0,A-K),max(0,B-(max(K-A,0)))))
7
2
118
71
A, B, K = list(map(int, input().split())) if A >= K: print((A - K, B)) elif A < K and A + B > K: print((0, B - (K - A))) else: print((0, 0))
A, B, K = list(map(int, input().split())) print((max(0, A - K), max(0, B - (max(K - A, 0)))))
false
71.428571
[ "-if A >= K:", "- print((A - K, B))", "-elif A < K and A + B > K:", "- print((0, B - (K - A)))", "-else:", "- print((0, 0))", "+print((max(0, A - K), max(0, B - (max(K - A, 0)))))" ]
false
0.092357
0.036758
2.512591
[ "s028897911", "s401721507" ]
u644907318
p03157
python
s791164876
s143434857
524
237
44,784
94,420
Accepted
Accepted
54.77
from collections import deque H,W = list(map(int,input().split())) S = [input().strip() for _ in range(H)] D = {0:".",1:"#"} G = {} C = {} hist = [[-1 for _ in range(W)] for _ in range(H)] col = -1 for i in range(H): for j in range(W): if S[i][j]=="#" and hist[i][j]==-1: col += 1 G[col] = [(i,j)] que = deque([(i,j,1)]) hist[i][j] = col cnt = 0 while que: y,x,a = que.popleft() if x+1<W and S[y][x+1]==D[1-a]: if a==1 and hist[y][x+1]!=col: cnt += 1 que.append((y,x+1,1-a)) hist[y][x+1]=col elif a==0 and hist[y][x+1]==-1: G[col].append((y,x+1)) que.append((y,x+1,1-a)) hist[y][x+1]=col if y-1>-1 and S[y-1][x]==D[1-a]: if a==1 and hist[y-1][x]!=col: cnt += 1 que.append((y-1,x,1-a)) hist[y-1][x]=col elif a==0 and hist[y-1][x]==-1: G[col].append((y-1,x)) que.append((y-1,x,1-a)) hist[y-1][x]=col if x-1>-1 and S[y][x-1]==D[1-a]: if a==1 and hist[y][x-1]!=col: cnt += 1 que.append((y,x-1,1-a)) hist[y][x-1]=col elif a==0 and hist[y][x-1]==-1: G[col].append((y,x-1)) hist[y][x-1]=col que.append((y,x-1,1-a)) if y+1<H and S[y+1][x]==D[1-a]: if a==1 and hist[y+1][x]!=col: cnt += 1 que.append((y+1,x,1-a)) hist[y+1][x]=col elif a==0 and hist[y+1][x]==-1: G[col].append((y+1,x)) que.append((y+1,x,1-a)) hist[y+1][x]=col C[col] = cnt tot = 0 for col in G: tot += len(G[col])*C[col] print(tot)
from collections import deque H,W = list(map(int,input().split())) S = [input().strip() for _ in range(H)] hist = [[0 for _ in range(W)] for _ in range(H)] col = 1 for i in range(H): for j in range(W): if hist[i][j]==0: hist[i][j]=col que = deque([(i,j,S[i][j])]) while que: y,x,c = que.popleft() if x+1<W and S[y][x+1]!=c and hist[y][x+1]==0: hist[y][x+1]=col que.append((y,x+1,S[y][x+1])) if y-1>=0 and S[y-1][x]!=c and hist[y-1][x]==0: hist[y-1][x]=col que.append((y-1,x,S[y-1][x])) if x-1>=0 and S[y][x-1]!=c and hist[y][x-1]==0: hist[y][x-1]=col que.append((y,x-1,S[y][x-1])) if y+1<H and S[y+1][x]!=c and hist[y+1][x]==0: hist[y+1][x]=col que.append((y+1,x,S[y+1][x])) col += 1 C = {} for i in range(H): for j in range(W): col = hist[i][j] if col not in C: C[col] = [0,0] C[col][0] += 1 if S[i][j]=="#": C[col][1] += 1 cnt = 0 for col in C: if col!=0: tot = C[col][0] x = C[col][1] cnt += x*(tot-x) print(cnt)
59
41
2,256
1,337
from collections import deque H, W = list(map(int, input().split())) S = [input().strip() for _ in range(H)] D = {0: ".", 1: "#"} G = {} C = {} hist = [[-1 for _ in range(W)] for _ in range(H)] col = -1 for i in range(H): for j in range(W): if S[i][j] == "#" and hist[i][j] == -1: col += 1 G[col] = [(i, j)] que = deque([(i, j, 1)]) hist[i][j] = col cnt = 0 while que: y, x, a = que.popleft() if x + 1 < W and S[y][x + 1] == D[1 - a]: if a == 1 and hist[y][x + 1] != col: cnt += 1 que.append((y, x + 1, 1 - a)) hist[y][x + 1] = col elif a == 0 and hist[y][x + 1] == -1: G[col].append((y, x + 1)) que.append((y, x + 1, 1 - a)) hist[y][x + 1] = col if y - 1 > -1 and S[y - 1][x] == D[1 - a]: if a == 1 and hist[y - 1][x] != col: cnt += 1 que.append((y - 1, x, 1 - a)) hist[y - 1][x] = col elif a == 0 and hist[y - 1][x] == -1: G[col].append((y - 1, x)) que.append((y - 1, x, 1 - a)) hist[y - 1][x] = col if x - 1 > -1 and S[y][x - 1] == D[1 - a]: if a == 1 and hist[y][x - 1] != col: cnt += 1 que.append((y, x - 1, 1 - a)) hist[y][x - 1] = col elif a == 0 and hist[y][x - 1] == -1: G[col].append((y, x - 1)) hist[y][x - 1] = col que.append((y, x - 1, 1 - a)) if y + 1 < H and S[y + 1][x] == D[1 - a]: if a == 1 and hist[y + 1][x] != col: cnt += 1 que.append((y + 1, x, 1 - a)) hist[y + 1][x] = col elif a == 0 and hist[y + 1][x] == -1: G[col].append((y + 1, x)) que.append((y + 1, x, 1 - a)) hist[y + 1][x] = col C[col] = cnt tot = 0 for col in G: tot += len(G[col]) * C[col] print(tot)
from collections import deque H, W = list(map(int, input().split())) S = [input().strip() for _ in range(H)] hist = [[0 for _ in range(W)] for _ in range(H)] col = 1 for i in range(H): for j in range(W): if hist[i][j] == 0: hist[i][j] = col que = deque([(i, j, S[i][j])]) while que: y, x, c = que.popleft() if x + 1 < W and S[y][x + 1] != c and hist[y][x + 1] == 0: hist[y][x + 1] = col que.append((y, x + 1, S[y][x + 1])) if y - 1 >= 0 and S[y - 1][x] != c and hist[y - 1][x] == 0: hist[y - 1][x] = col que.append((y - 1, x, S[y - 1][x])) if x - 1 >= 0 and S[y][x - 1] != c and hist[y][x - 1] == 0: hist[y][x - 1] = col que.append((y, x - 1, S[y][x - 1])) if y + 1 < H and S[y + 1][x] != c and hist[y + 1][x] == 0: hist[y + 1][x] = col que.append((y + 1, x, S[y + 1][x])) col += 1 C = {} for i in range(H): for j in range(W): col = hist[i][j] if col not in C: C[col] = [0, 0] C[col][0] += 1 if S[i][j] == "#": C[col][1] += 1 cnt = 0 for col in C: if col != 0: tot = C[col][0] x = C[col][1] cnt += x * (tot - x) print(cnt)
false
30.508475
[ "-D = {0: \".\", 1: \"#\"}", "-G = {}", "-C = {}", "-hist = [[-1 for _ in range(W)] for _ in range(H)]", "-col = -1", "+hist = [[0 for _ in range(W)] for _ in range(H)]", "+col = 1", "- if S[i][j] == \"#\" and hist[i][j] == -1:", "+ if hist[i][j] == 0:", "+ hist[i][j] = col", "+ que = deque([(i, j, S[i][j])])", "+ while que:", "+ y, x, c = que.popleft()", "+ if x + 1 < W and S[y][x + 1] != c and hist[y][x + 1] == 0:", "+ hist[y][x + 1] = col", "+ que.append((y, x + 1, S[y][x + 1]))", "+ if y - 1 >= 0 and S[y - 1][x] != c and hist[y - 1][x] == 0:", "+ hist[y - 1][x] = col", "+ que.append((y - 1, x, S[y - 1][x]))", "+ if x - 1 >= 0 and S[y][x - 1] != c and hist[y][x - 1] == 0:", "+ hist[y][x - 1] = col", "+ que.append((y, x - 1, S[y][x - 1]))", "+ if y + 1 < H and S[y + 1][x] != c and hist[y + 1][x] == 0:", "+ hist[y + 1][x] = col", "+ que.append((y + 1, x, S[y + 1][x]))", "- G[col] = [(i, j)]", "- que = deque([(i, j, 1)])", "- hist[i][j] = col", "- cnt = 0", "- while que:", "- y, x, a = que.popleft()", "- if x + 1 < W and S[y][x + 1] == D[1 - a]:", "- if a == 1 and hist[y][x + 1] != col:", "- cnt += 1", "- que.append((y, x + 1, 1 - a))", "- hist[y][x + 1] = col", "- elif a == 0 and hist[y][x + 1] == -1:", "- G[col].append((y, x + 1))", "- que.append((y, x + 1, 1 - a))", "- hist[y][x + 1] = col", "- if y - 1 > -1 and S[y - 1][x] == D[1 - a]:", "- if a == 1 and hist[y - 1][x] != col:", "- cnt += 1", "- que.append((y - 1, x, 1 - a))", "- hist[y - 1][x] = col", "- elif a == 0 and hist[y - 1][x] == -1:", "- G[col].append((y - 1, x))", "- que.append((y - 1, x, 1 - a))", "- hist[y - 1][x] = col", "- if x - 1 > -1 and S[y][x - 1] == D[1 - a]:", "- if a == 1 and hist[y][x - 1] != col:", "- cnt += 1", "- que.append((y, x - 1, 1 - a))", "- hist[y][x - 1] = col", "- elif a == 0 and hist[y][x - 1] == -1:", "- G[col].append((y, x - 1))", "- hist[y][x - 1] = col", "- que.append((y, x - 1, 1 - a))", "- if y + 1 < H and S[y + 1][x] == D[1 - a]:", "- if a == 1 and hist[y + 1][x] != col:", "- cnt += 1", "- que.append((y + 1, x, 1 - a))", "- hist[y + 1][x] = col", "- elif a == 0 and hist[y + 1][x] == -1:", "- G[col].append((y + 1, x))", "- que.append((y + 1, x, 1 - a))", "- hist[y + 1][x] = col", "- C[col] = cnt", "-tot = 0", "-for col in G:", "- tot += len(G[col]) * C[col]", "-print(tot)", "+C = {}", "+for i in range(H):", "+ for j in range(W):", "+ col = hist[i][j]", "+ if col not in C:", "+ C[col] = [0, 0]", "+ C[col][0] += 1", "+ if S[i][j] == \"#\":", "+ C[col][1] += 1", "+cnt = 0", "+for col in C:", "+ if col != 0:", "+ tot = C[col][0]", "+ x = C[col][1]", "+ cnt += x * (tot - x)", "+print(cnt)" ]
false
0.038737
0.041798
0.926752
[ "s791164876", "s143434857" ]
u672475305
p02780
python
s949314271
s251675567
415
351
33,892
34,148
Accepted
Accepted
15.42
import numpy as np n,k = list(map(int,input().split())) lst = list(map(int,input().split())) exp_val = [(l+1)/2 for l in lst] cumsum = np.cumsum(exp_val) for i in range(k-1, n): if i==k-1: val = cumsum[i] else: val = max(val, cumsum[i] - cumsum[i-k]) print(val)
import numpy as np n,k = list(map(int,input().split())) p = list(map(int,input().split())) cs = [] for x in p: cs.append(((x+1)*x//2)/x) cs = [0]+np.cumsum(cs).tolist() ans = 0 for i in range(k, n+1): ans = max(ans, cs[i]-cs[i-k]) print(ans)
14
11
295
253
import numpy as np n, k = list(map(int, input().split())) lst = list(map(int, input().split())) exp_val = [(l + 1) / 2 for l in lst] cumsum = np.cumsum(exp_val) for i in range(k - 1, n): if i == k - 1: val = cumsum[i] else: val = max(val, cumsum[i] - cumsum[i - k]) print(val)
import numpy as np n, k = list(map(int, input().split())) p = list(map(int, input().split())) cs = [] for x in p: cs.append(((x + 1) * x // 2) / x) cs = [0] + np.cumsum(cs).tolist() ans = 0 for i in range(k, n + 1): ans = max(ans, cs[i] - cs[i - k]) print(ans)
false
21.428571
[ "-lst = list(map(int, input().split()))", "-exp_val = [(l + 1) / 2 for l in lst]", "-cumsum = np.cumsum(exp_val)", "-for i in range(k - 1, n):", "- if i == k - 1:", "- val = cumsum[i]", "- else:", "- val = max(val, cumsum[i] - cumsum[i - k])", "-print(val)", "+p = list(map(int, input().split()))", "+cs = []", "+for x in p:", "+ cs.append(((x + 1) * x // 2) / x)", "+cs = [0] + np.cumsum(cs).tolist()", "+ans = 0", "+for i in range(k, n + 1):", "+ ans = max(ans, cs[i] - cs[i - k])", "+print(ans)" ]
false
0.551002
0.177436
3.10535
[ "s949314271", "s251675567" ]
u020373088
p03495
python
s518605228
s494194025
112
98
32,564
32,564
Accepted
Accepted
12.5
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnts = list(Counter(a).values()) print((sum(sorted(cnts)[:-k])))
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnts = list(Counter(a).values()) print((sum(sorted(cnts, reverse=True)[k:])))
5
5
161
174
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnts = list(Counter(a).values()) print((sum(sorted(cnts)[:-k])))
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnts = list(Counter(a).values()) print((sum(sorted(cnts, reverse=True)[k:])))
false
0
[ "-print((sum(sorted(cnts)[:-k])))", "+print((sum(sorted(cnts, reverse=True)[k:])))" ]
false
0.052856
0.05752
0.918914
[ "s518605228", "s494194025" ]
u133936772
p02598
python
s624291667
s719956788
914
764
31,240
31,076
Accepted
Accepted
16.41
from math import * f=lambda:[*list(map(int,input().split()))] n,k=f() a=f() def ok(x): c=0 for i in a: c+=ceil(i/x) return c<=n+k l,r=0,10**9+1 while r-l>0.1: m=(l+r)/2 if ok(m): r=m else: l=m t=ceil(r) print((t-ok(t-1) if t>1 else t))
from math import * f=lambda:[*list(map(int,input().split()))] n,k=f() a=f() def ok(x): c=0 for i in a: c+=ceil(i/x) return c<=n+k l,r=0,10**9 while r-l>1: m=(l+r)/2 if ok(m): r=m else: l=m t=ceil(r) print((t-ok(t-1) if t>1 else t))
16
16
258
254
from math import * f = lambda: [*list(map(int, input().split()))] n, k = f() a = f() def ok(x): c = 0 for i in a: c += ceil(i / x) return c <= n + k l, r = 0, 10**9 + 1 while r - l > 0.1: m = (l + r) / 2 if ok(m): r = m else: l = m t = ceil(r) print((t - ok(t - 1) if t > 1 else t))
from math import * f = lambda: [*list(map(int, input().split()))] n, k = f() a = f() def ok(x): c = 0 for i in a: c += ceil(i / x) return c <= n + k l, r = 0, 10**9 while r - l > 1: m = (l + r) / 2 if ok(m): r = m else: l = m t = ceil(r) print((t - ok(t - 1) if t > 1 else t))
false
0
[ "-l, r = 0, 10**9 + 1", "-while r - l > 0.1:", "+l, r = 0, 10**9", "+while r - l > 1:" ]
false
0.069953
0.043216
1.61866
[ "s624291667", "s719956788" ]
u150984829
p02412
python
s361445566
s460408795
30
20
5,608
5,600
Accepted
Accepted
33.33
while 1: n,x=list(map(int,input().split())) if n+x==0:break print((len([1 for i in range(1,x//3)for j in range(i+1,n)if j<x-i-j<=n])))
while 1: n,x=list(map(int,input().split())) if n+x==0:break print((sum([max(0,(x-a-1)//2-max(a,x-a-1-n))for a in range(1,x//3)])))
4
4
132
128
while 1: n, x = list(map(int, input().split())) if n + x == 0: break print( ( len( [ 1 for i in range(1, x // 3) for j in range(i + 1, n) if j < x - i - j <= n ] ) ) )
while 1: n, x = list(map(int, input().split())) if n + x == 0: break print( ( sum( [ max(0, (x - a - 1) // 2 - max(a, x - a - 1 - n)) for a in range(1, x // 3) ] ) ) )
false
0
[ "- len(", "+ sum(", "- 1", "- for i in range(1, x // 3)", "- for j in range(i + 1, n)", "- if j < x - i - j <= n", "+ max(0, (x - a - 1) // 2 - max(a, x - a - 1 - n))", "+ for a in range(1, x // 3)" ]
false
0.046316
0.091525
0.506053
[ "s361445566", "s460408795" ]
u261103969
p02695
python
s759660721
s078270440
672
316
23,164
9,120
Accepted
Accepted
52.98
from collections import deque # 数列の点数を計算する関数 def calc(seq): score = 0 for a, b, c, d in req: if seq[b - 1] - seq[a - 1] == c: score += d return score n, m, q = list(map(int, input().split())) req = [list(map(int, input().split())) for _ in range(q)] ans = 0 que = deque() # 数列の1番目、[1]~[m]までキューに追加しますが、 # 実は、この問題は数列の最初が[1]の場合だけを考えても解けます。 for i in range(1, m + 1): que.append([i]) while que: seq = que.popleft() if len(seq) == n: # 長さがnになったので、得点を計算します score = calc(seq) ans = max(ans, score) else: # 次に追加する数字は、下限が今の数列の一番後ろの数字、上限がmです for i in range(seq[-1], m + 1): seq_next = seq + [i] que.append(seq_next) print(ans)
def dfs(seq): # 返り値は、すべての数列の得点の最大値 ans です。 ans = 0 if len(seq) == n: # 数列が完成したので、得点を計算します score_ret = 0 for a, b, c, d in req: if seq[b-1] - seq[a-1] == c: score_ret += d return score_ret # この数列の得点を返します else: # まだ数列が完成していません for i in range(seq[-1], m + 1): seq_next = seq + (i,) # 長さ1のタプル(i,)を連結します score = dfs(seq_next) # seq_nextから派生するすベての数列の中での、得点の最大値が返ってきます ans = max(ans, score) # 最大の得点を更新します # すべてが終わったので、得点の最大値を返します return ans n, m, q = list(map(int, input().split())) # reqは[[a1,b1,c1,d1],[a2,b2,c2,d2]……]が入ったリストのリストです req = [list(map(int, input().split())) for _ in range(q)] # 最終的に答えが返ってくるようにします。処理はすべてdfsメソッドでやってもらいます。 # リストだとどこかで間違えて値を書き換えそうで怖いので、タプルにしておきます # 1番目が1の場合以外は考えなくていいので、(1,)だけやります ans = 0 score = dfs((1,)) ans = max(ans, score) print(ans)
39
32
771
938
from collections import deque # 数列の点数を計算する関数 def calc(seq): score = 0 for a, b, c, d in req: if seq[b - 1] - seq[a - 1] == c: score += d return score n, m, q = list(map(int, input().split())) req = [list(map(int, input().split())) for _ in range(q)] ans = 0 que = deque() # 数列の1番目、[1]~[m]までキューに追加しますが、 # 実は、この問題は数列の最初が[1]の場合だけを考えても解けます。 for i in range(1, m + 1): que.append([i]) while que: seq = que.popleft() if len(seq) == n: # 長さがnになったので、得点を計算します score = calc(seq) ans = max(ans, score) else: # 次に追加する数字は、下限が今の数列の一番後ろの数字、上限がmです for i in range(seq[-1], m + 1): seq_next = seq + [i] que.append(seq_next) print(ans)
def dfs(seq): # 返り値は、すべての数列の得点の最大値 ans です。 ans = 0 if len(seq) == n: # 数列が完成したので、得点を計算します score_ret = 0 for a, b, c, d in req: if seq[b - 1] - seq[a - 1] == c: score_ret += d return score_ret # この数列の得点を返します else: # まだ数列が完成していません for i in range(seq[-1], m + 1): seq_next = seq + (i,) # 長さ1のタプル(i,)を連結します score = dfs(seq_next) # seq_nextから派生するすベての数列の中での、得点の最大値が返ってきます ans = max(ans, score) # 最大の得点を更新します # すべてが終わったので、得点の最大値を返します return ans n, m, q = list(map(int, input().split())) # reqは[[a1,b1,c1,d1],[a2,b2,c2,d2]……]が入ったリストのリストです req = [list(map(int, input().split())) for _ in range(q)] # 最終的に答えが返ってくるようにします。処理はすべてdfsメソッドでやってもらいます。 # リストだとどこかで間違えて値を書き換えそうで怖いので、タプルにしておきます # 1番目が1の場合以外は考えなくていいので、(1,)だけやります ans = 0 score = dfs((1,)) ans = max(ans, score) print(ans)
false
17.948718
[ "-from collections import deque", "-", "-# 数列の点数を計算する関数", "-def calc(seq):", "- score = 0", "- for a, b, c, d in req:", "- if seq[b - 1] - seq[a - 1] == c:", "- score += d", "- return score", "+def dfs(seq):", "+ # 返り値は、すべての数列の得点の最大値 ans です。", "+ ans = 0", "+ if len(seq) == n:", "+ # 数列が完成したので、得点を計算します", "+ score_ret = 0", "+ for a, b, c, d in req:", "+ if seq[b - 1] - seq[a - 1] == c:", "+ score_ret += d", "+ return score_ret # この数列の得点を返します", "+ else:", "+ # まだ数列が完成していません", "+ for i in range(seq[-1], m + 1):", "+ seq_next = seq + (i,) # 長さ1のタプル(i,)を連結します", "+ score = dfs(seq_next) # seq_nextから派生するすベての数列の中での、得点の最大値が返ってきます", "+ ans = max(ans, score) # 最大の得点を更新します", "+ # すべてが終わったので、得点の最大値を返します", "+ return ans", "+# reqは[[a1,b1,c1,d1],[a2,b2,c2,d2]……]が入ったリストのリストです", "+# 最終的に答えが返ってくるようにします。処理はすべてdfsメソッドでやってもらいます。", "+# リストだとどこかで間違えて値を書き換えそうで怖いので、タプルにしておきます", "+# 1番目が1の場合以外は考えなくていいので、(1,)だけやります", "-que = deque()", "-# 数列の1番目、[1]~[m]までキューに追加しますが、", "-# 実は、この問題は数列の最初が[1]の場合だけを考えても解けます。", "-for i in range(1, m + 1):", "- que.append([i])", "-while que:", "- seq = que.popleft()", "- if len(seq) == n:", "- # 長さがnになったので、得点を計算します", "- score = calc(seq)", "- ans = max(ans, score)", "- else:", "- # 次に追加する数字は、下限が今の数列の一番後ろの数字、上限がmです", "- for i in range(seq[-1], m + 1):", "- seq_next = seq + [i]", "- que.append(seq_next)", "+score = dfs((1,))", "+ans = max(ans, score)" ]
false
0.006977
0.054168
0.12881
[ "s759660721", "s078270440" ]
u467479913
p02615
python
s251379096
s908036005
170
126
31,672
31,316
Accepted
Accepted
25.88
eval(input()) l = sorted(map(int, input().split(' '))) answer = 0 spots = [l.pop()] x = len(l) for i in range(x): n = l.pop() answer += spots[i] spots.append(n) spots.append(n) print(answer)
n = int(eval(input())) l = list(map(int, input().split(' '))) l.sort() s = l.pop() while n > 3: s += l.pop() * 2 n -= 2 if n == 3: s += l.pop() print(s)
14
10
205
158
eval(input()) l = sorted(map(int, input().split(" "))) answer = 0 spots = [l.pop()] x = len(l) for i in range(x): n = l.pop() answer += spots[i] spots.append(n) spots.append(n) print(answer)
n = int(eval(input())) l = list(map(int, input().split(" "))) l.sort() s = l.pop() while n > 3: s += l.pop() * 2 n -= 2 if n == 3: s += l.pop() print(s)
false
28.571429
[ "-eval(input())", "-l = sorted(map(int, input().split(\" \")))", "-answer = 0", "-spots = [l.pop()]", "-x = len(l)", "-for i in range(x):", "- n = l.pop()", "- answer += spots[i]", "- spots.append(n)", "- spots.append(n)", "-print(answer)", "+n = int(eval(input()))", "+l = list(map(int, input().split(\" \")))", "+l.sort()", "+s = l.pop()", "+while n > 3:", "+ s += l.pop() * 2", "+ n -= 2", "+if n == 3:", "+ s += l.pop()", "+print(s)" ]
false
0.039215
0.039044
1.004363
[ "s251379096", "s908036005" ]
u260036763
p03416
python
s821841002
s836759784
211
35
39,408
2,940
Accepted
Accepted
83.41
a, b = list(map(int, input().split())) count = 0 for i in range(a,b+1): b1 = i%10 s = i//10 b2 = s%10 t = s//10 u = t//10 a2 = u%10 v = u//10 a1 = v%10 if a1 == b1 and a2 == b2: count += 1 print(count)
A, B = list(map(int, input().split())) count = 0 for n in range(A, B+1): if n//10000 == n%10 and (n//1000)%10 == (n//10)%10: count += 1 print(count)
14
6
230
153
a, b = list(map(int, input().split())) count = 0 for i in range(a, b + 1): b1 = i % 10 s = i // 10 b2 = s % 10 t = s // 10 u = t // 10 a2 = u % 10 v = u // 10 a1 = v % 10 if a1 == b1 and a2 == b2: count += 1 print(count)
A, B = list(map(int, input().split())) count = 0 for n in range(A, B + 1): if n // 10000 == n % 10 and (n // 1000) % 10 == (n // 10) % 10: count += 1 print(count)
false
57.142857
[ "-a, b = list(map(int, input().split()))", "+A, B = list(map(int, input().split()))", "-for i in range(a, b + 1):", "- b1 = i % 10", "- s = i // 10", "- b2 = s % 10", "- t = s // 10", "- u = t // 10", "- a2 = u % 10", "- v = u // 10", "- a1 = v % 10", "- if a1 == b1 and a2 == b2:", "+for n in range(A, B + 1):", "+ if n // 10000 == n % 10 and (n // 1000) % 10 == (n // 10) % 10:" ]
false
0.103035
0.040498
2.544168
[ "s821841002", "s836759784" ]
u018679195
p03072
python
s472209866
s018676588
21
18
3,316
3,060
Accepted
Accepted
14.29
n = int(eval(input())) xs = [int(x) for x in input().split()] mx = xs[0] count = 0 for x in xs: if x >= mx: count += 1 mx = x print(count)
line = eval(input()) line = eval(input()) numbers = [int(n) for n in line.split()] predicted_value = 0 for i in range(len(numbers)): is_smaller = False for k in range(i): if numbers[i] < numbers[k]: is_smaller = True break if not is_smaller: predicted_value += 1 print(predicted_value)
12
13
167
337
n = int(eval(input())) xs = [int(x) for x in input().split()] mx = xs[0] count = 0 for x in xs: if x >= mx: count += 1 mx = x print(count)
line = eval(input()) line = eval(input()) numbers = [int(n) for n in line.split()] predicted_value = 0 for i in range(len(numbers)): is_smaller = False for k in range(i): if numbers[i] < numbers[k]: is_smaller = True break if not is_smaller: predicted_value += 1 print(predicted_value)
false
7.692308
[ "-n = int(eval(input()))", "-xs = [int(x) for x in input().split()]", "-mx = xs[0]", "-count = 0", "-for x in xs:", "- if x >= mx:", "- count += 1", "- mx = x", "-print(count)", "+line = eval(input())", "+line = eval(input())", "+numbers = [int(n) for n in line.split()]", "+predicted_value = 0", "+for i in range(len(numbers)):", "+ is_smaller = False", "+ for k in range(i):", "+ if numbers[i] < numbers[k]:", "+ is_smaller = True", "+ break", "+ if not is_smaller:", "+ predicted_value += 1", "+print(predicted_value)" ]
false
0.036647
0.038018
0.963936
[ "s472209866", "s018676588" ]
u525065967
p03288
python
s350335220
s435203330
19
17
2,940
2,940
Accepted
Accepted
10.53
r = int(eval(input())) ans = 'ARC' if r < 1200: ans = 'ABC' elif 2800 <= r: ans = 'AGC' print(ans)
r = int(eval(input())) if r < 1200: print('ABC') elif 2800 <= r: print('AGC') else: print('ARC')
5
4
97
94
r = int(eval(input())) ans = "ARC" if r < 1200: ans = "ABC" elif 2800 <= r: ans = "AGC" print(ans)
r = int(eval(input())) if r < 1200: print("ABC") elif 2800 <= r: print("AGC") else: print("ARC")
false
20
[ "-ans = \"ARC\"", "- ans = \"ABC\"", "+ print(\"ABC\")", "- ans = \"AGC\"", "-print(ans)", "+ print(\"AGC\")", "+else:", "+ print(\"ARC\")" ]
false
0.066437
0.066549
0.998322
[ "s350335220", "s435203330" ]
u256256172
p02407
python
s066430616
s670621601
30
20
7,448
7,448
Accepted
Accepted
33.33
eval(input()) a = list(input().split()) a.reverse() print((" ".join(a)))
eval(input()) print((" ".join(reversed(input().split()))))
4
2
67
51
eval(input()) a = list(input().split()) a.reverse() print((" ".join(a)))
eval(input()) print((" ".join(reversed(input().split()))))
false
50
[ "-a = list(input().split())", "-a.reverse()", "-print((\" \".join(a)))", "+print((\" \".join(reversed(input().split()))))" ]
false
0.195506
0.035395
5.523508
[ "s066430616", "s670621601" ]
u504800764
p02658
python
s846300653
s670570785
91
54
84,632
21,488
Accepted
Accepted
40.66
n = int(eval(input())) a = list(map(int, input().split())) a.sort() ans = 1 for i in range(n): ans *= a[i] if(ans > 1000000000000000000): break if(ans > 1000000000000000000): print((-1)) else: print(ans)
n = int(eval(input())) a = list(map(int,input().split())) if 0 in a: print((0)) exit() ans = 1 for i in a: ans *= i if(ans > 10**18): print((-1)) exit() print(ans)
15
15
245
202
n = int(eval(input())) a = list(map(int, input().split())) a.sort() ans = 1 for i in range(n): ans *= a[i] if ans > 1000000000000000000: break if ans > 1000000000000000000: print((-1)) else: print(ans)
n = int(eval(input())) a = list(map(int, input().split())) if 0 in a: print((0)) exit() ans = 1 for i in a: ans *= i if ans > 10**18: print((-1)) exit() print(ans)
false
0
[ "-a.sort()", "+if 0 in a:", "+ print((0))", "+ exit()", "-for i in range(n):", "- ans *= a[i]", "- if ans > 1000000000000000000:", "- break", "-if ans > 1000000000000000000:", "- print((-1))", "-else:", "- print(ans)", "+for i in a:", "+ ans *= i", "+ if ans > 10**18:", "+ print((-1))", "+ exit()", "+print(ans)" ]
false
0.043952
0.137107
0.32057
[ "s846300653", "s670570785" ]
u006883624
p02768
python
s178762665
s471482584
154
114
3,572
3,572
Accepted
Accepted
25.97
# from math import sqrt # from heapq import heappush, heappop # from collections import deque from operator import mul from functools import reduce # a, b = [int(v) for v in input().split()] def main(): def modcmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) if r == 0: return 1 over = 1 under = 1 # for i in range(n, n-r, -1): # over = over * i % mod # for i in range(1, r+1): # under = under * i % mod over = reduce(lambda v1, v2: (v1 * v2) % mod, list(range(n, n-r, -1))) under = reduce(lambda v1, v2: (v1 * v2) % mod, list(range(1, r+1))) return (over * pow(under, mod - 2, mod)) % mod mod = 1000000007 n, a, b = list(map(int, input().split())) count = pow(2, n, mod) - 1 count -= modcmb(n, a, mod) count -= modcmb(n, b, mod) while count < 0: count += mod print((count % mod)) main()
# from math import sqrt # from heapq import heappush, heappop # from collections import deque from operator import mul from functools import reduce # a, b = [int(v) for v in input().split()] def main(): mod = 1000000007 n, a, b = list(map(int, input().split())) def combi(n, r): if r < 0 or r > n: return 0 r = min(n - r, r) over = 1 under = 1 for i in range(n - r + 1, n + 1): over = over * i % mod for i in range(1, r + 1): under = under * i % mod return over * modpow(under, mod-2) % mod def modpow(n, r): if r == 0: return 1 v = modpow(n, r // 2) v = v * v % mod if r % 2 != 0: v = v * n % mod return v ans = modpow(2, n) - 1 ans -= combi(n, a) ans -= combi(n, b) while ans < 0: ans += mod print(ans) main()
40
50
993
970
# from math import sqrt # from heapq import heappush, heappop # from collections import deque from operator import mul from functools import reduce # a, b = [int(v) for v in input().split()] def main(): def modcmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) if r == 0: return 1 over = 1 under = 1 # for i in range(n, n-r, -1): # over = over * i % mod # for i in range(1, r+1): # under = under * i % mod over = reduce(lambda v1, v2: (v1 * v2) % mod, list(range(n, n - r, -1))) under = reduce(lambda v1, v2: (v1 * v2) % mod, list(range(1, r + 1))) return (over * pow(under, mod - 2, mod)) % mod mod = 1000000007 n, a, b = list(map(int, input().split())) count = pow(2, n, mod) - 1 count -= modcmb(n, a, mod) count -= modcmb(n, b, mod) while count < 0: count += mod print((count % mod)) main()
# from math import sqrt # from heapq import heappush, heappop # from collections import deque from operator import mul from functools import reduce # a, b = [int(v) for v in input().split()] def main(): mod = 1000000007 n, a, b = list(map(int, input().split())) def combi(n, r): if r < 0 or r > n: return 0 r = min(n - r, r) over = 1 under = 1 for i in range(n - r + 1, n + 1): over = over * i % mod for i in range(1, r + 1): under = under * i % mod return over * modpow(under, mod - 2) % mod def modpow(n, r): if r == 0: return 1 v = modpow(n, r // 2) v = v * v % mod if r % 2 != 0: v = v * n % mod return v ans = modpow(2, n) - 1 ans -= combi(n, a) ans -= combi(n, b) while ans < 0: ans += mod print(ans) main()
false
20
[ "- def modcmb(n, r, mod):", "+ mod = 1000000007", "+ n, a, b = list(map(int, input().split()))", "+", "+ def combi(n, r):", "- r = min(r, n - r)", "+ r = min(n - r, r)", "+ over = 1", "+ under = 1", "+ for i in range(n - r + 1, n + 1):", "+ over = over * i % mod", "+ for i in range(1, r + 1):", "+ under = under * i % mod", "+ return over * modpow(under, mod - 2) % mod", "+", "+ def modpow(n, r):", "- over = 1", "- under = 1", "- # for i in range(n, n-r, -1):", "- # over = over * i % mod", "- # for i in range(1, r+1):", "- # under = under * i % mod", "- over = reduce(lambda v1, v2: (v1 * v2) % mod, list(range(n, n - r, -1)))", "- under = reduce(lambda v1, v2: (v1 * v2) % mod, list(range(1, r + 1)))", "- return (over * pow(under, mod - 2, mod)) % mod", "+ v = modpow(n, r // 2)", "+ v = v * v % mod", "+ if r % 2 != 0:", "+ v = v * n % mod", "+ return v", "- mod = 1000000007", "- n, a, b = list(map(int, input().split()))", "- count = pow(2, n, mod) - 1", "- count -= modcmb(n, a, mod)", "- count -= modcmb(n, b, mod)", "- while count < 0:", "- count += mod", "- print((count % mod))", "+ ans = modpow(2, n) - 1", "+ ans -= combi(n, a)", "+ ans -= combi(n, b)", "+ while ans < 0:", "+ ans += mod", "+ print(ans)" ]
false
0.475435
0.12683
3.74859
[ "s178762665", "s471482584" ]
u562935282
p02629
python
s167084265
s248100867
45
38
9,968
9,888
Accepted
Accepted
15.56
def main(): from string import ascii_lowercase N = int(eval(input())) ans = '' while N > 0: N -= 1 N, r = divmod(N, 26) ans = ascii_lowercase[r] + ans print(ans) if __name__ == '__main__': main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
def main(): from string import ascii_lowercase N = int(eval(input())) def rec(n): if n == 0: return '' n -= 1 n, r = divmod(n, 26) return rec(n) + ascii_lowercase[r] print((rec(N))) if __name__ == '__main__': main()
33
16
609
280
def main(): from string import ascii_lowercase N = int(eval(input())) ans = "" while N > 0: N -= 1 N, r = divmod(N, 26) ans = ascii_lowercase[r] + ans print(ans) if __name__ == "__main__": main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
def main(): from string import ascii_lowercase N = int(eval(input())) def rec(n): if n == 0: return "" n -= 1 n, r = divmod(n, 26) return rec(n) + ascii_lowercase[r] print((rec(N))) if __name__ == "__main__": main()
false
51.515152
[ "- ans = \"\"", "- while N > 0:", "- N -= 1", "- N, r = divmod(N, 26)", "- ans = ascii_lowercase[r] + ans", "- print(ans)", "+", "+ def rec(n):", "+ if n == 0:", "+ return \"\"", "+ n -= 1", "+ n, r = divmod(n, 26)", "+ return rec(n) + ascii_lowercase[r]", "+", "+ print((rec(N)))", "-# import sys", "-# input = sys.stdin.readline", "-#", "-# sys.setrecursionlimit(10 ** 7)", "-#", "-# (int(x)-1 for x in input().split())", "-# rstrip()", "-#", "-# def binary_search(*, ok, ng, func):", "-# while abs(ok - ng) > 1:", "-# mid = (ok + ng) // 2", "-# if func(mid):", "-# ok = mid", "-# else:", "-# ng = mid", "-# return ok" ]
false
0.043337
0.102798
0.421571
[ "s167084265", "s248100867" ]
u745514010
p03565
python
s141912502
s670432736
30
26
9,100
9,108
Accepted
Accepted
13.33
s = input()[::-1] t = input()[::-1] if len(s) < len(t): print("UNRESTORABLE") exit() for i in range(len(s) - len(t) + 1): for j in range(len(t)): if s[i + j] == "?": continue elif s[i + j] == t[j]: continue break else: ans = "" for k in range(i): if s[k] == "?": ans += "a" else: ans += s[k] for tt in t: ans += tt for k in range(len(t) + i, len(s)): if s[k] == "?": ans += "a" else: ans += s[k] print((ans[::-1])) exit() print("UNRESTORABLE")
s = input()[::-1] t = input()[::-1] if len(s) < len(t): print("UNRESTORABLE") exit() tmp = s.replace("?", "a") if t in tmp: print((tmp[::-1])) exit() for i in range(len(s) - len(t) + 1): for j in range(len(t)): if s[i + j] == "?": continue elif s[i + j] == t[j]: continue break else: ans = "" for k in range(i): if s[k] == "?": ans += "a" else: ans += s[k] for tt in t: ans += tt for k in range(len(t) + i, len(s)): if s[k] == "?": ans += "a" else: ans += s[k] print((ans[::-1])) exit() print("UNRESTORABLE")
30
35
711
792
s = input()[::-1] t = input()[::-1] if len(s) < len(t): print("UNRESTORABLE") exit() for i in range(len(s) - len(t) + 1): for j in range(len(t)): if s[i + j] == "?": continue elif s[i + j] == t[j]: continue break else: ans = "" for k in range(i): if s[k] == "?": ans += "a" else: ans += s[k] for tt in t: ans += tt for k in range(len(t) + i, len(s)): if s[k] == "?": ans += "a" else: ans += s[k] print((ans[::-1])) exit() print("UNRESTORABLE")
s = input()[::-1] t = input()[::-1] if len(s) < len(t): print("UNRESTORABLE") exit() tmp = s.replace("?", "a") if t in tmp: print((tmp[::-1])) exit() for i in range(len(s) - len(t) + 1): for j in range(len(t)): if s[i + j] == "?": continue elif s[i + j] == t[j]: continue break else: ans = "" for k in range(i): if s[k] == "?": ans += "a" else: ans += s[k] for tt in t: ans += tt for k in range(len(t) + i, len(s)): if s[k] == "?": ans += "a" else: ans += s[k] print((ans[::-1])) exit() print("UNRESTORABLE")
false
14.285714
[ "+ exit()", "+tmp = s.replace(\"?\", \"a\")", "+if t in tmp:", "+ print((tmp[::-1]))" ]
false
0.043936
0.045515
0.965299
[ "s141912502", "s670432736" ]
u923279197
p03107
python
s880049597
s714192326
171
31
39,792
3,188
Accepted
Accepted
81.87
s = eval(input()) a = 0 b = 0 for i in s: if i == "1": a += 1 else: b += 1 print((len(s)-abs(a-b)))
s = eval(input()) r = 0 b = 0 for i in s: if i == "1":r += 1 else: b += 1 now = max(b,r) - min(b,r) ans = len(s)-now print(ans)
9
10
123
139
s = eval(input()) a = 0 b = 0 for i in s: if i == "1": a += 1 else: b += 1 print((len(s) - abs(a - b)))
s = eval(input()) r = 0 b = 0 for i in s: if i == "1": r += 1 else: b += 1 now = max(b, r) - min(b, r) ans = len(s) - now print(ans)
false
10
[ "-a = 0", "+r = 0", "- a += 1", "+ r += 1", "-print((len(s) - abs(a - b)))", "+now = max(b, r) - min(b, r)", "+ans = len(s) - now", "+print(ans)" ]
false
0.046649
0.08882
0.525206
[ "s880049597", "s714192326" ]
u994988729
p03659
python
s973287428
s585271008
258
176
76,880
24,168
Accepted
Accepted
31.78
N = int(eval(input())) A = list(map(int, input().split())) x = sum(A) y = 0 res = 10 ** 18 for i in range(N - 1): x -= A[i] y += A[i] res = min(res, abs(x - y)) print(res)
from itertools import accumulate N = int(eval(input())) A = list(map(int, input().split())) Acum = list(accumulate(A)) ans = 10 ** 20 for a in Acum[:-1]: snuke = a arai = Acum[-1] - a ans = min(ans, abs(snuke - arai)) print(ans)
13
12
193
247
N = int(eval(input())) A = list(map(int, input().split())) x = sum(A) y = 0 res = 10**18 for i in range(N - 1): x -= A[i] y += A[i] res = min(res, abs(x - y)) print(res)
from itertools import accumulate N = int(eval(input())) A = list(map(int, input().split())) Acum = list(accumulate(A)) ans = 10**20 for a in Acum[:-1]: snuke = a arai = Acum[-1] - a ans = min(ans, abs(snuke - arai)) print(ans)
false
7.692308
[ "+from itertools import accumulate", "+", "-x = sum(A)", "-y = 0", "-res = 10**18", "-for i in range(N - 1):", "- x -= A[i]", "- y += A[i]", "- res = min(res, abs(x - y))", "-print(res)", "+Acum = list(accumulate(A))", "+ans = 10**20", "+for a in Acum[:-1]:", "+ snuke = a", "+ arai = Acum[-1] - a", "+ ans = min(ans, abs(snuke - arai))", "+print(ans)" ]
false
0.034087
0.036062
0.945227
[ "s973287428", "s585271008" ]
u690419532
p02621
python
s783723848
s231481735
26
24
9,140
9,148
Accepted
Accepted
7.69
a = int(eval(input())) x = a + a**2 + a**3 print(x)
a = int(eval(input())) print((a + a**2 + a**3))
3
2
47
40
a = int(eval(input())) x = a + a**2 + a**3 print(x)
a = int(eval(input())) print((a + a**2 + a**3))
false
33.333333
[ "-x = a + a**2 + a**3", "-print(x)", "+print((a + a**2 + a**3))" ]
false
0.03602
0.036483
0.987302
[ "s783723848", "s231481735" ]
u252805217
p02912
python
s680185625
s282338963
223
149
14,380
14,380
Accepted
Accepted
33.18
from math import ceil from heapq import * n, m = list(map(int, input().split())) a_s = [-int(a) for a in input().split()] heapify(a_s) for _ in range(m): amax = heappop(a_s) heappush(a_s, ceil(amax / 2)) res = sum([-heappop(a_s) for _ in range(n)]) print(res)
from math import ceil from heapq import * n, m = list(map(int, input().split())) a_s = [-int(a) for a in input().split()] heapify(a_s) for _ in range(m): amax = -heappop(a_s) heappush(a_s, -(amax // 2)) res = -sum(a_s) print(res)
13
13
270
241
from math import ceil from heapq import * n, m = list(map(int, input().split())) a_s = [-int(a) for a in input().split()] heapify(a_s) for _ in range(m): amax = heappop(a_s) heappush(a_s, ceil(amax / 2)) res = sum([-heappop(a_s) for _ in range(n)]) print(res)
from math import ceil from heapq import * n, m = list(map(int, input().split())) a_s = [-int(a) for a in input().split()] heapify(a_s) for _ in range(m): amax = -heappop(a_s) heappush(a_s, -(amax // 2)) res = -sum(a_s) print(res)
false
0
[ "- amax = heappop(a_s)", "- heappush(a_s, ceil(amax / 2))", "-res = sum([-heappop(a_s) for _ in range(n)])", "+ amax = -heappop(a_s)", "+ heappush(a_s, -(amax // 2))", "+res = -sum(a_s)" ]
false
0.048235
0.047413
1.017349
[ "s680185625", "s282338963" ]
u172035535
p03835
python
s149112727
s771467396
1,514
17
3,060
3,064
Accepted
Accepted
98.88
K,S = list(map(int,input().split())) ans = 0 for x in range(K+1): for y in range(K+1): z = S-x-y if 0<=z<=K: ans += 1 print(ans)
k,s = list(map(int,input().split())) a = ((s+1)*(s+2))//2 b = ((s-k)*(s-k+1))//2 c = (((abs(s-k*3))+1)*((abs(s-k*3))+2))//2 if s <= k: print(a) elif s <= k*2: print((a-b*3)) elif s <= k*3: print(c)
8
11
161
212
K, S = list(map(int, input().split())) ans = 0 for x in range(K + 1): for y in range(K + 1): z = S - x - y if 0 <= z <= K: ans += 1 print(ans)
k, s = list(map(int, input().split())) a = ((s + 1) * (s + 2)) // 2 b = ((s - k) * (s - k + 1)) // 2 c = (((abs(s - k * 3)) + 1) * ((abs(s - k * 3)) + 2)) // 2 if s <= k: print(a) elif s <= k * 2: print((a - b * 3)) elif s <= k * 3: print(c)
false
27.272727
[ "-K, S = list(map(int, input().split()))", "-ans = 0", "-for x in range(K + 1):", "- for y in range(K + 1):", "- z = S - x - y", "- if 0 <= z <= K:", "- ans += 1", "-print(ans)", "+k, s = list(map(int, input().split()))", "+a = ((s + 1) * (s + 2)) // 2", "+b = ((s - k) * (s - k + 1)) // 2", "+c = (((abs(s - k * 3)) + 1) * ((abs(s - k * 3)) + 2)) // 2", "+if s <= k:", "+ print(a)", "+elif s <= k * 2:", "+ print((a - b * 3))", "+elif s <= k * 3:", "+ print(c)" ]
false
0.046524
0.046829
0.993501
[ "s149112727", "s771467396" ]
u492910842
p02623
python
s673307974
s887489213
190
156
127,072
132,668
Accepted
Accepted
17.89
import bisect n,m,k=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) ans=0 A,B=[0],[0] for i in range(n): A.append(a[i]+A[i]) for i in range(m): B.append(b[i]+B[i]) for j in range(n+1): K=k-A[j] if K<0: break else: ans=max(ans,bisect.bisect_right(B,K)+j-1) print(ans)
n,m,k=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) ans,right=0,0 A,B=[0],[0] for i in range(n): A.append(a[i]+A[i]) for i in range(m): B.append(b[i]+B[i]) for i in range(m+1): if k<B[i] or i==m: right=i-1 if i==m: right=i ans=right break for j in range(0,n): if k<a[j]: break k-=a[j] while k<B[right]: right-=1 ans=max(ans,right+j+1) print(ans)
20
26
353
461
import bisect n, m, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 A, B = [0], [0] for i in range(n): A.append(a[i] + A[i]) for i in range(m): B.append(b[i] + B[i]) for j in range(n + 1): K = k - A[j] if K < 0: break else: ans = max(ans, bisect.bisect_right(B, K) + j - 1) print(ans)
n, m, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) ans, right = 0, 0 A, B = [0], [0] for i in range(n): A.append(a[i] + A[i]) for i in range(m): B.append(b[i] + B[i]) for i in range(m + 1): if k < B[i] or i == m: right = i - 1 if i == m: right = i ans = right break for j in range(0, n): if k < a[j]: break k -= a[j] while k < B[right]: right -= 1 ans = max(ans, right + j + 1) print(ans)
false
23.076923
[ "-import bisect", "-", "-ans = 0", "+ans, right = 0, 0", "-for j in range(n + 1):", "- K = k - A[j]", "- if K < 0:", "+for i in range(m + 1):", "+ if k < B[i] or i == m:", "+ right = i - 1", "+ if i == m:", "+ right = i", "+ ans = right", "- else:", "- ans = max(ans, bisect.bisect_right(B, K) + j - 1)", "+for j in range(0, n):", "+ if k < a[j]:", "+ break", "+ k -= a[j]", "+ while k < B[right]:", "+ right -= 1", "+ ans = max(ans, right + j + 1)" ]
false
0.039825
0.039431
1.010014
[ "s673307974", "s887489213" ]
u709079466
p02881
python
s534612586
s671713136
374
223
9,124
9,056
Accepted
Accepted
40.37
import math def is_prime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True n = int(eval(input())) a = 1 b = 1 tmp_ans = 0 ans = 10**12 if is_prime(n) == True: print((n - 1)) elif is_prime(n) == False: for i in range(2, int(math.sqrt(n))+1): j = n // i if n == i*j: tmp_ans = (i-a) + (j-b) if tmp_ans < ans: ans = tmp_ans print(ans)
import math n = int(eval(input())) a = 1 b = 1 tmp_ans = 0 ans = 10**12 for i in range(1, int(math.sqrt(n))+1): j = n // i if n == i*j: tmp_ans = (i-a) + (j-b) if tmp_ans < ans: ans = tmp_ans print(ans)
25
15
511
249
import math def is_prime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True n = int(eval(input())) a = 1 b = 1 tmp_ans = 0 ans = 10**12 if is_prime(n) == True: print((n - 1)) elif is_prime(n) == False: for i in range(2, int(math.sqrt(n)) + 1): j = n // i if n == i * j: tmp_ans = (i - a) + (j - b) if tmp_ans < ans: ans = tmp_ans print(ans)
import math n = int(eval(input())) a = 1 b = 1 tmp_ans = 0 ans = 10**12 for i in range(1, int(math.sqrt(n)) + 1): j = n // i if n == i * j: tmp_ans = (i - a) + (j - b) if tmp_ans < ans: ans = tmp_ans print(ans)
false
40
[ "-", "-", "-def is_prime(n):", "- if n == 1:", "- return False", "- for k in range(2, int(math.sqrt(n)) + 1):", "- if n % k == 0:", "- return False", "- return True", "-", "-if is_prime(n) == True:", "- print((n - 1))", "-elif is_prime(n) == False:", "- for i in range(2, int(math.sqrt(n)) + 1):", "- j = n // i", "- if n == i * j:", "- tmp_ans = (i - a) + (j - b)", "- if tmp_ans < ans:", "- ans = tmp_ans", "- print(ans)", "+for i in range(1, int(math.sqrt(n)) + 1):", "+ j = n // i", "+ if n == i * j:", "+ tmp_ans = (i - a) + (j - b)", "+ if tmp_ans < ans:", "+ ans = tmp_ans", "+print(ans)" ]
false
0.042438
0.040518
1.047374
[ "s534612586", "s671713136" ]
u971091945
p02726
python
s828236433
s288967582
1,699
1,296
3,444
3,444
Accepted
Accepted
23.72
n, x, y = list(map(int, input().split())) li = [0]*(n-1) num = 0 for i in range(1,n+1): for j in range(i+1,n+1): if j<=x or y<i: num = j-i elif i<=x and x<j<=y: num = (x-i)+min(j-x, y-j+1) elif i<=x and y<j: num = (x-i)+(j-y)+1 elif x<i and j<=y: num = min(j-i,(i-x)+(y-j)+1) elif x<i<=y and y<j: num = min(i-x+1, y-i)+(j-y) li[num-1] += 1 for i in li: print(i)
n, x, y = list(map(int, input().split())) li = [0] * (n - 1) num = 0 for i in range(1, n + 1): for j in range(i + 1, n + 1): num = min(j-i, abs(i-x)+abs(j-y)+1) li[num - 1] += 1 for i in li: print(i)
20
11
492
229
n, x, y = list(map(int, input().split())) li = [0] * (n - 1) num = 0 for i in range(1, n + 1): for j in range(i + 1, n + 1): if j <= x or y < i: num = j - i elif i <= x and x < j <= y: num = (x - i) + min(j - x, y - j + 1) elif i <= x and y < j: num = (x - i) + (j - y) + 1 elif x < i and j <= y: num = min(j - i, (i - x) + (y - j) + 1) elif x < i <= y and y < j: num = min(i - x + 1, y - i) + (j - y) li[num - 1] += 1 for i in li: print(i)
n, x, y = list(map(int, input().split())) li = [0] * (n - 1) num = 0 for i in range(1, n + 1): for j in range(i + 1, n + 1): num = min(j - i, abs(i - x) + abs(j - y) + 1) li[num - 1] += 1 for i in li: print(i)
false
45
[ "- if j <= x or y < i:", "- num = j - i", "- elif i <= x and x < j <= y:", "- num = (x - i) + min(j - x, y - j + 1)", "- elif i <= x and y < j:", "- num = (x - i) + (j - y) + 1", "- elif x < i and j <= y:", "- num = min(j - i, (i - x) + (y - j) + 1)", "- elif x < i <= y and y < j:", "- num = min(i - x + 1, y - i) + (j - y)", "+ num = min(j - i, abs(i - x) + abs(j - y) + 1)" ]
false
0.100017
0.036221
2.761335
[ "s828236433", "s288967582" ]
u279955105
p02397
python
s086514122
s541607869
80
60
7,540
5,608
Accepted
Accepted
25
while True: a,b = list(map(int, input().split())) if a == 0 and b ==0: break elif a < b: print((a,b)) else: print((b,a))
i = 0 while True: a,b = list(map(int, input().split())) if (a == 0) and (b == 0): break elif a < b: print((str(a)+' '+str(b))) i = i + 1 else: print((str(b)+' '+str(a))) i = i + 1
8
11
163
236
while True: a, b = list(map(int, input().split())) if a == 0 and b == 0: break elif a < b: print((a, b)) else: print((b, a))
i = 0 while True: a, b = list(map(int, input().split())) if (a == 0) and (b == 0): break elif a < b: print((str(a) + " " + str(b))) i = i + 1 else: print((str(b) + " " + str(a))) i = i + 1
false
27.272727
[ "+i = 0", "- if a == 0 and b == 0:", "+ if (a == 0) and (b == 0):", "- print((a, b))", "+ print((str(a) + \" \" + str(b)))", "+ i = i + 1", "- print((b, a))", "+ print((str(b) + \" \" + str(a)))", "+ i = i + 1" ]
false
0.043616
0.037382
1.166768
[ "s086514122", "s541607869" ]
u554954744
p02982
python
s197193511
s364579369
181
166
38,384
38,256
Accepted
Accepted
8.29
import math N, D = list(map(int, input().split())) X = [list(map(int, input().split())) for i in range(N)] cnt = 0 for i in range(N): for j in range(i, N): tmp = 0 if i == j: continue for k in range(D): tmp += (X[i][k] - X[j][k]) ** 2 if math.sqrt(tmp).is_integer(): cnt += 1 print(cnt)
import math N, D = list(map(int, input().split())) X = [list(map(int, input().split())) for i in range(N)] cnt = 0 for i in range(N): for j in range(i+1, N): tmp = 0 for k in range(D): tmp += (X[i][k] - X[j][k]) ** 2 if math.sqrt(tmp).is_integer(): cnt += 1 print(cnt)
17
15
379
339
import math N, D = list(map(int, input().split())) X = [list(map(int, input().split())) for i in range(N)] cnt = 0 for i in range(N): for j in range(i, N): tmp = 0 if i == j: continue for k in range(D): tmp += (X[i][k] - X[j][k]) ** 2 if math.sqrt(tmp).is_integer(): cnt += 1 print(cnt)
import math N, D = list(map(int, input().split())) X = [list(map(int, input().split())) for i in range(N)] cnt = 0 for i in range(N): for j in range(i + 1, N): tmp = 0 for k in range(D): tmp += (X[i][k] - X[j][k]) ** 2 if math.sqrt(tmp).is_integer(): cnt += 1 print(cnt)
false
11.764706
[ "- for j in range(i, N):", "+ for j in range(i + 1, N):", "- if i == j:", "- continue" ]
false
0.074596
0.049457
1.508291
[ "s197193511", "s364579369" ]
u055875839
p02813
python
s152134182
s964705284
151
27
12,480
8,052
Accepted
Accepted
82.12
from numpy import prod n = int(eval(input())) def solve(l:list): now = [i + 1 for i in range(n)] res = 0 for i in range(n): res += now.index(l[i]) * prod([j+1 for j in range(len(now)-1)]) now.remove(l[i]) return res l_p = list(map(int, input().split())) l_q = list(map(int, input().split())) print((int(abs(solve(l_p) - solve(l_q)))))
from itertools import permutations n = int(eval(input())) all_ = list(permutations([i+1 for i in range(n)], n)) l_p = tuple(map(int, input().split())) l_q = tuple(map(int, input().split())) res = abs(all_.index(l_p) - all_.index(l_q)) print(res)
16
9
362
249
from numpy import prod n = int(eval(input())) def solve(l: list): now = [i + 1 for i in range(n)] res = 0 for i in range(n): res += now.index(l[i]) * prod([j + 1 for j in range(len(now) - 1)]) now.remove(l[i]) return res l_p = list(map(int, input().split())) l_q = list(map(int, input().split())) print((int(abs(solve(l_p) - solve(l_q)))))
from itertools import permutations n = int(eval(input())) all_ = list(permutations([i + 1 for i in range(n)], n)) l_p = tuple(map(int, input().split())) l_q = tuple(map(int, input().split())) res = abs(all_.index(l_p) - all_.index(l_q)) print(res)
false
43.75
[ "-from numpy import prod", "+from itertools import permutations", "-", "-", "-def solve(l: list):", "- now = [i + 1 for i in range(n)]", "- res = 0", "- for i in range(n):", "- res += now.index(l[i]) * prod([j + 1 for j in range(len(now) - 1)])", "- now.remove(l[i])", "- return res", "-", "-", "-l_p = list(map(int, input().split()))", "-l_q = list(map(int, input().split()))", "-print((int(abs(solve(l_p) - solve(l_q)))))", "+all_ = list(permutations([i + 1 for i in range(n)], n))", "+l_p = tuple(map(int, input().split()))", "+l_q = tuple(map(int, input().split()))", "+res = abs(all_.index(l_p) - all_.index(l_q))", "+print(res)" ]
false
0.24296
0.046979
5.171686
[ "s152134182", "s964705284" ]
u600402037
p03464
python
s348296417
s249506844
146
98
14,428
14,100
Accepted
Accepted
32.88
import sys sys.setrecursionlimit(10 ** 7) sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) K = ir() A = lr()[::-1] domain = [2, 2] #現在の最小と最大 for i in range(K): x = A[i] left = domain[0]; right = domain[1] if x > right * 2 - 1: print((-1)) exit() left += (-left) % x right -= right % x right += x - 1 if left > right: print((-1)) exit() domain = [left, right] print((*domain)) # 05
import sys sys.setrecursionlimit(10 ** 7) sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) K = ir() A = lr()[::-1] left = 2 right = 2 for x in A: left += (-left) % x right -= right % x right += x - 1 if left > right: print((-1)) else: print((left, right)) # 05
26
21
525
359
import sys sys.setrecursionlimit(10**7) sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) K = ir() A = lr()[::-1] domain = [2, 2] # 現在の最小と最大 for i in range(K): x = A[i] left = domain[0] right = domain[1] if x > right * 2 - 1: print((-1)) exit() left += (-left) % x right -= right % x right += x - 1 if left > right: print((-1)) exit() domain = [left, right] print((*domain)) # 05
import sys sys.setrecursionlimit(10**7) sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) K = ir() A = lr()[::-1] left = 2 right = 2 for x in A: left += (-left) % x right -= right % x right += x - 1 if left > right: print((-1)) else: print((left, right)) # 05
false
19.230769
[ "-domain = [2, 2] # 現在の最小と最大", "-for i in range(K):", "- x = A[i]", "- left = domain[0]", "- right = domain[1]", "- if x > right * 2 - 1:", "- print((-1))", "- exit()", "+left = 2", "+right = 2", "+for x in A:", "- if left > right:", "- print((-1))", "- exit()", "- domain = [left, right]", "-print((*domain))", "+if left > right:", "+ print((-1))", "+else:", "+ print((left, right))" ]
false
0.041498
0.0419
0.990409
[ "s348296417", "s249506844" ]
u476435125
p03244
python
s872351563
s392205690
147
104
17,644
17,632
Accepted
Accepted
29.25
N=int(eval(input())) lv=list(map(int,input().split())) dev={} dod={} #cev=0#devの種類数 #cod=0#dodの種類数 max1_ev=[0,0]#数字,個数 max2_ev=[0,0] max1_od=[0,0]#数字,個数 max2_od=[0,0] for i in range(N): if i%2==0:#even #max1_ev=[0,0]#数字,個数 #max2_ev=[0,0] #毎回初期化していた!! if lv[i] in dev:#辞書の更新 dev[lv[i]]+=1 else: dev[lv[i]]=1 #maxの更新 #cev+=1 #if cev==1: # max1_ev=[i,lv[i]] #elif cev==2: # max2_ev=[i,lv[i]] ##3種目以降 #最大個数の更新 if dev[lv[i]]>max1_ev[1]: max1_ev=[lv[i],dev[lv[i]]] #elif dev[lv[i]]>max2_ev[1]: elif dev[lv[i]]>=max2_ev[1]: max2_ev=[lv[i],dev[lv[i]]] #print("dev[lv[i]]",dev[lv[i]]) #print("max1__ev[1]",max1_ev[1]) #print("max1_ev",max1_ev) #print("max2_ev",max2_ev) #if i==0: # max1=[0,1] #elif i==1: # max2 else:#odd #max1_od=[0,0] #max2_od=[0,0] if lv[i] in dod: dod[lv[i]]+=1 else: dod[lv[i]]=1 if dod[lv[i]]>max1_od[1]: max1_od=[lv[i],dod[lv[i]]] #elif dod[lv[i]]>max2_od[1]: elif dod[lv[i]]>=max2_od[1]: max2_od=[lv[i],dod[lv[i]]] #print("dev",dev)#ok #print("dod",dod)#ok #print("max1_ev",max1_ev) #print("max2_ev",max2_ev) #if len(dev)==1 and len(dod)==1: # print(int(N/2)) #elif len(dev)==1: #for i in range(len(dod)): # if i==0: # max1_od= # if max1_ev[0]!=max1_od[0]: # print(N-max1_ev[1]-max1_od[1]) ## print(max) if max1_ev[0]!=max1_od[0]: print((N-max1_ev[1]-max1_od[1])) elif len(dev)==1 and len(dod)==1: print((int(N/2))) elif len(dev)==1: print((int(N/2)-max2_od[1])) elif len(dod)==1: print((int(N/2)-max2_ev[1])) else: #print(max(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))#minをmaxとしていた print((min(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1])))
N=int(eval(input())) lv=list(map(int,input().split())) dev={} dod={} for i in range(N): if i%2==0:#even if lv[i] in dev: dev[lv[i]]+=1 else: dev[lv[i]]=1 else:#odd if lv[i] in dod: dod[lv[i]]+=1 else: dod[lv[i]]=1 max1_ev=[0,0] max2_ev=[0,0] max1_od=[0,0] max2_od=[0,0] #for i in range(len(dev)): for v in dev:#max even if dev[v]>max1_ev[1]: a=max1_ev max1_ev=[v,dev[v]] max2_ev=a elif dev[v]>max2_ev[1]: max2_ev=[v,dev[v]] for v in dod:#max odd if dod[v]>max1_od[1]: a=max1_od max1_od=[v,dod[v]] max2_od=a elif dod[v]>max2_od[1]: max2_od=[v,dod[v]] if max1_ev[0]!=max1_od[0]: print((N-max1_ev[1]-max1_od[1])) else: print((min(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1])))
80
39
2,089
883
N = int(eval(input())) lv = list(map(int, input().split())) dev = {} dod = {} # cev=0#devの種類数 # cod=0#dodの種類数 max1_ev = [0, 0] # 数字,個数 max2_ev = [0, 0] max1_od = [0, 0] # 数字,個数 max2_od = [0, 0] for i in range(N): if i % 2 == 0: # even # max1_ev=[0,0]#数字,個数 # max2_ev=[0,0] # 毎回初期化していた!! if lv[i] in dev: # 辞書の更新 dev[lv[i]] += 1 else: dev[lv[i]] = 1 # maxの更新 # cev+=1 # if cev==1: # max1_ev=[i,lv[i]] # elif cev==2: # max2_ev=[i,lv[i]] ##3種目以降 # 最大個数の更新 if dev[lv[i]] > max1_ev[1]: max1_ev = [lv[i], dev[lv[i]]] # elif dev[lv[i]]>max2_ev[1]: elif dev[lv[i]] >= max2_ev[1]: max2_ev = [lv[i], dev[lv[i]]] # print("dev[lv[i]]",dev[lv[i]]) # print("max1__ev[1]",max1_ev[1]) # print("max1_ev",max1_ev) # print("max2_ev",max2_ev) # if i==0: # max1=[0,1] # elif i==1: # max2 else: # odd # max1_od=[0,0] # max2_od=[0,0] if lv[i] in dod: dod[lv[i]] += 1 else: dod[lv[i]] = 1 if dod[lv[i]] > max1_od[1]: max1_od = [lv[i], dod[lv[i]]] # elif dod[lv[i]]>max2_od[1]: elif dod[lv[i]] >= max2_od[1]: max2_od = [lv[i], dod[lv[i]]] # print("dev",dev)#ok # print("dod",dod)#ok # print("max1_ev",max1_ev) # print("max2_ev",max2_ev) # if len(dev)==1 and len(dod)==1: # print(int(N/2)) # elif len(dev)==1: # for i in range(len(dod)): # if i==0: # max1_od= # if max1_ev[0]!=max1_od[0]: # print(N-max1_ev[1]-max1_od[1]) ## print(max) if max1_ev[0] != max1_od[0]: print((N - max1_ev[1] - max1_od[1])) elif len(dev) == 1 and len(dod) == 1: print((int(N / 2))) elif len(dev) == 1: print((int(N / 2) - max2_od[1])) elif len(dod) == 1: print((int(N / 2) - max2_ev[1])) else: # print(max(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))#minをmaxとしていた print((min(N - max1_ev[1] - max2_od[1], N - max2_ev[1] - max1_od[1])))
N = int(eval(input())) lv = list(map(int, input().split())) dev = {} dod = {} for i in range(N): if i % 2 == 0: # even if lv[i] in dev: dev[lv[i]] += 1 else: dev[lv[i]] = 1 else: # odd if lv[i] in dod: dod[lv[i]] += 1 else: dod[lv[i]] = 1 max1_ev = [0, 0] max2_ev = [0, 0] max1_od = [0, 0] max2_od = [0, 0] # for i in range(len(dev)): for v in dev: # max even if dev[v] > max1_ev[1]: a = max1_ev max1_ev = [v, dev[v]] max2_ev = a elif dev[v] > max2_ev[1]: max2_ev = [v, dev[v]] for v in dod: # max odd if dod[v] > max1_od[1]: a = max1_od max1_od = [v, dod[v]] max2_od = a elif dod[v] > max2_od[1]: max2_od = [v, dod[v]] if max1_ev[0] != max1_od[0]: print((N - max1_ev[1] - max1_od[1])) else: print((min(N - max1_ev[1] - max2_od[1], N - max2_ev[1] - max1_od[1])))
false
51.25
[ "-# cev=0#devの種類数", "-# cod=0#dodの種類数", "-max1_ev = [0, 0] # 数字,個数", "-max2_ev = [0, 0]", "-max1_od = [0, 0] # 数字,個数", "-max2_od = [0, 0]", "- # max1_ev=[0,0]#数字,個数", "- # max2_ev=[0,0]", "- # 毎回初期化していた!!", "- if lv[i] in dev: # 辞書の更新", "+ if lv[i] in dev:", "- # maxの更新", "- # cev+=1", "- # if cev==1:", "- # max1_ev=[i,lv[i]]", "- # elif cev==2:", "- # max2_ev=[i,lv[i]]", "- ##3種目以降", "- # 最大個数の更新", "- if dev[lv[i]] > max1_ev[1]:", "- max1_ev = [lv[i], dev[lv[i]]]", "- # elif dev[lv[i]]>max2_ev[1]:", "- elif dev[lv[i]] >= max2_ev[1]:", "- max2_ev = [lv[i], dev[lv[i]]]", "- # print(\"dev[lv[i]]\",dev[lv[i]])", "- # print(\"max1__ev[1]\",max1_ev[1])", "- # print(\"max1_ev\",max1_ev)", "- # print(\"max2_ev\",max2_ev)", "- # if i==0:", "- # max1=[0,1]", "- # elif i==1:", "- # max2", "- # max1_od=[0,0]", "- # max2_od=[0,0]", "- if dod[lv[i]] > max1_od[1]:", "- max1_od = [lv[i], dod[lv[i]]]", "- # elif dod[lv[i]]>max2_od[1]:", "- elif dod[lv[i]] >= max2_od[1]:", "- max2_od = [lv[i], dod[lv[i]]]", "-# print(\"dev\",dev)#ok", "-# print(\"dod\",dod)#ok", "-# print(\"max1_ev\",max1_ev)", "-# print(\"max2_ev\",max2_ev)", "-# if len(dev)==1 and len(dod)==1:", "-# print(int(N/2))", "-# elif len(dev)==1:", "-# for i in range(len(dod)):", "-# if i==0:", "-# max1_od=", "-# if max1_ev[0]!=max1_od[0]:", "-# print(N-max1_ev[1]-max1_od[1])", "-## print(max)", "+max1_ev = [0, 0]", "+max2_ev = [0, 0]", "+max1_od = [0, 0]", "+max2_od = [0, 0]", "+# for i in range(len(dev)):", "+for v in dev: # max even", "+ if dev[v] > max1_ev[1]:", "+ a = max1_ev", "+ max1_ev = [v, dev[v]]", "+ max2_ev = a", "+ elif dev[v] > max2_ev[1]:", "+ max2_ev = [v, dev[v]]", "+for v in dod: # max odd", "+ if dod[v] > max1_od[1]:", "+ a = max1_od", "+ max1_od = [v, dod[v]]", "+ max2_od = a", "+ elif dod[v] > max2_od[1]:", "+ max2_od = [v, dod[v]]", "-elif len(dev) == 1 and len(dod) == 1:", "- print((int(N / 2)))", "-elif len(dev) == 1:", "- print((int(N / 2) - max2_od[1]))", "-elif len(dod) == 1:", "- print((int(N / 2) - max2_ev[1]))", "- # print(max(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))#minをmaxとしていた" ]
false
0.038965
0.06831
0.570422
[ "s872351563", "s392205690" ]
u328510800
p03013
python
s095323946
s802833731
562
388
466,584
469,664
Accepted
Accepted
30.96
n, m = list(map(int, input().split())) stairs = [i for i in range(1, n+1)] a = [0 for _ in range(m)] for i in range(m): a[i] = int(eval(input())) a = set(a) dp = [0] * (n + 1) dp[0] = 1 for i in range(1, n+1): if i in a: continue dp[i] = dp[i] + dp[i-1] if i > 1: dp[i] = dp[i] + dp[i-2] print((dp[n] % 1000000007))
n, m = list(map(int, input().split())) stairs = [i for i in range(1, n+1)] a = [0 for _ in range(m)] for i in range(m): a[i] = int(eval(input())) a = set(a) dp = [0] * (n + 1) dp[0] = 1 for i in range(1, n+1): if i in a: continue dp[i] = dp[i-1] if i > 1: dp[i] += dp[i-2] print((dp[n] % 1000000007))
18
18
339
324
n, m = list(map(int, input().split())) stairs = [i for i in range(1, n + 1)] a = [0 for _ in range(m)] for i in range(m): a[i] = int(eval(input())) a = set(a) dp = [0] * (n + 1) dp[0] = 1 for i in range(1, n + 1): if i in a: continue dp[i] = dp[i] + dp[i - 1] if i > 1: dp[i] = dp[i] + dp[i - 2] print((dp[n] % 1000000007))
n, m = list(map(int, input().split())) stairs = [i for i in range(1, n + 1)] a = [0 for _ in range(m)] for i in range(m): a[i] = int(eval(input())) a = set(a) dp = [0] * (n + 1) dp[0] = 1 for i in range(1, n + 1): if i in a: continue dp[i] = dp[i - 1] if i > 1: dp[i] += dp[i - 2] print((dp[n] % 1000000007))
false
0
[ "- dp[i] = dp[i] + dp[i - 1]", "+ dp[i] = dp[i - 1]", "- dp[i] = dp[i] + dp[i - 2]", "+ dp[i] += dp[i - 2]" ]
false
0.074191
0.062551
1.186092
[ "s095323946", "s802833731" ]
u255555420
p03711
python
s630455826
s829086291
22
17
3,060
3,060
Accepted
Accepted
22.73
x, y =list(map( int,input().split())) listA = [1, 3, 5, 7 , 8 , 10 , 12] listB = [4 , 6, 9, 11] listC=[2] if x in listA and y in listA: print("Yes") elif x in listB and y in listB: print("Yes") elif x in listC and y in listC: print("Yes") else: print("No")
x,y =list(map(int,input().split())) L1=[1,3,5,7,8,10,12] L2=[4,6,9,11] L3=[2] if x in L1 and y in L1: print("Yes") elif x in L2 and y in L2: print("Yes") elif x in L3 and y in L3: print("Yes") else: print("No")
17
17
299
250
x, y = list(map(int, input().split())) listA = [1, 3, 5, 7, 8, 10, 12] listB = [4, 6, 9, 11] listC = [2] if x in listA and y in listA: print("Yes") elif x in listB and y in listB: print("Yes") elif x in listC and y in listC: print("Yes") else: print("No")
x, y = list(map(int, input().split())) L1 = [1, 3, 5, 7, 8, 10, 12] L2 = [4, 6, 9, 11] L3 = [2] if x in L1 and y in L1: print("Yes") elif x in L2 and y in L2: print("Yes") elif x in L3 and y in L3: print("Yes") else: print("No")
false
0
[ "-listA = [1, 3, 5, 7, 8, 10, 12]", "-listB = [4, 6, 9, 11]", "-listC = [2]", "-if x in listA and y in listA:", "+L1 = [1, 3, 5, 7, 8, 10, 12]", "+L2 = [4, 6, 9, 11]", "+L3 = [2]", "+if x in L1 and y in L1:", "-elif x in listB and y in listB:", "+elif x in L2 and y in L2:", "-elif x in listC and y in listC:", "+elif x in L3 and y in L3:" ]
false
0.033818
0.046244
0.731284
[ "s630455826", "s829086291" ]
u472065247
p03221
python
s060740332
s746633205
812
653
42,020
49,484
Accepted
Accepted
19.58
from collections import defaultdict N, M = list(map(int, input().split())) l = [] for i in range(M): p, y = list(map(int, input().split())) l.append((y, p, i)) l.sort() d = defaultdict(int) c = [] for y, p, i in l: d[p] += 1 c.append((i, str(p).zfill(6) + str(d[p]).zfill(6))) c.sort() for i, x in c: print(x)
from collections import defaultdict N, M = list(map(int, input().split())) l = [list(map(int, input().split())) for _ in range(M)] d = defaultdict(int) c = {} for p, y in sorted(l, key=lambda x: x[1]): d[p] += 1 c[y] = str(p).zfill(6) + str(d[p]).zfill(6) for p, y in l: print((c[y]))
18
12
329
295
from collections import defaultdict N, M = list(map(int, input().split())) l = [] for i in range(M): p, y = list(map(int, input().split())) l.append((y, p, i)) l.sort() d = defaultdict(int) c = [] for y, p, i in l: d[p] += 1 c.append((i, str(p).zfill(6) + str(d[p]).zfill(6))) c.sort() for i, x in c: print(x)
from collections import defaultdict N, M = list(map(int, input().split())) l = [list(map(int, input().split())) for _ in range(M)] d = defaultdict(int) c = {} for p, y in sorted(l, key=lambda x: x[1]): d[p] += 1 c[y] = str(p).zfill(6) + str(d[p]).zfill(6) for p, y in l: print((c[y]))
false
33.333333
[ "-l = []", "-for i in range(M):", "- p, y = list(map(int, input().split()))", "- l.append((y, p, i))", "-l.sort()", "+l = [list(map(int, input().split())) for _ in range(M)]", "-c = []", "-for y, p, i in l:", "+c = {}", "+for p, y in sorted(l, key=lambda x: x[1]):", "- c.append((i, str(p).zfill(6) + str(d[p]).zfill(6)))", "-c.sort()", "-for i, x in c:", "- print(x)", "+ c[y] = str(p).zfill(6) + str(d[p]).zfill(6)", "+for p, y in l:", "+ print((c[y]))" ]
false
0.087561
0.039408
2.221923
[ "s060740332", "s746633205" ]
u397496203
p02888
python
s281457689
s219520559
945
324
3,188
74,260
Accepted
Accepted
65.71
import bisect def main(): N = int(eval(input())) edges = [int(i) for i in input().split()] edges.sort() ans = 0 for a in range(N - 2): for b in range(a + 1, N - 1): ans += bisect.bisect_left(edges, edges[a] + edges[b])-b-1 print(ans) if __name__ == "__main__": main()
import sys # sys.setrecursionlimit(100000) import bisect def input(): return sys.stdin.readline().strip() def input_int(): return int(eval(input())) def input_int_list(): return [int(i) for i in input().split()] def main(): n = input_int() L = sorted(input_int_list()) ans = 0 for i in range(n - 2): for j in range(i + 1, n - 1): idx = bisect.bisect_left(L, L[i] + L[j]) ans += idx - j - 1 print(ans) return if __name__ == "__main__": main()
17
31
330
548
import bisect def main(): N = int(eval(input())) edges = [int(i) for i in input().split()] edges.sort() ans = 0 for a in range(N - 2): for b in range(a + 1, N - 1): ans += bisect.bisect_left(edges, edges[a] + edges[b]) - b - 1 print(ans) if __name__ == "__main__": main()
import sys # sys.setrecursionlimit(100000) import bisect def input(): return sys.stdin.readline().strip() def input_int(): return int(eval(input())) def input_int_list(): return [int(i) for i in input().split()] def main(): n = input_int() L = sorted(input_int_list()) ans = 0 for i in range(n - 2): for j in range(i + 1, n - 1): idx = bisect.bisect_left(L, L[i] + L[j]) ans += idx - j - 1 print(ans) return if __name__ == "__main__": main()
false
45.16129
[ "+import sys", "+", "+# sys.setrecursionlimit(100000)", "+def input():", "+ return sys.stdin.readline().strip()", "+", "+", "+def input_int():", "+ return int(eval(input()))", "+", "+", "+def input_int_list():", "+ return [int(i) for i in input().split()]", "+", "+", "- N = int(eval(input()))", "- edges = [int(i) for i in input().split()]", "- edges.sort()", "+ n = input_int()", "+ L = sorted(input_int_list())", "- for a in range(N - 2):", "- for b in range(a + 1, N - 1):", "- ans += bisect.bisect_left(edges, edges[a] + edges[b]) - b - 1", "+ for i in range(n - 2):", "+ for j in range(i + 1, n - 1):", "+ idx = bisect.bisect_left(L, L[i] + L[j])", "+ ans += idx - j - 1", "+ return" ]
false
0.038263
0.082512
0.463719
[ "s281457689", "s219520559" ]
u875291233
p02914
python
s112557186
s201286715
645
347
69,536
71,456
Accepted
Accepted
46.2
# Python program to find # maximum XOR subset # Number of bits to # represent int INT_BITS=61 # Function to return # maximum XOR subset # in set[] def maxSubarrayXOR(set,n): # Initialize index of # chosen elements index = 0 # Traverse through all # bits of integer # starting from the most # significant bit (MSB) for i in range(INT_BITS-1,-1,-1): # Initialize index of # maximum element and # the maximum element maxInd = index maxEle = -2147483648 for j in range(index,n): # If i'th bit of set[j] # is set and set[j] is # greater than max so far. if ( (set[j] & (1 << i)) != 0 and set[j] > maxEle ): maxEle = set[j] maxInd = j # If there was no # element with i'th # bit set, move to # smaller i if (maxEle ==-2147483648): continue # Put maximum element # with i'th bit set # at index 'index' temp=set[index] set[index]=set[maxInd] set[maxInd]=temp # Update maxInd and # increment index maxInd = index # Do XOR of set[maxIndex] # with all numbers having # i'th bit as set. for j in range(n): # XOR set[maxInd] those # numbers which have the # i'th bit set if (j != maxInd and (set[j] & (1 << i)) != 0): set[j] = set[j] ^ set[maxInd] # Increment index of # chosen elements index=index + 1 # Final result is # XOR of all elements res = 0 for i in range(n): res =res ^ set[i] return res # This code is contributed # by Anant Agarwal. # coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline #文字列入力のときは注意 #n = int(input()) #n,k = [int(i) for i in readline().split()] n = int(eval(input())) a = [int(i) for i in readline().split()] res = [0]*60 for i in a: b = bin(i)[:1:-1] # print(b) for j,c in enumerate(b): if c == "1": res[j] += 1 omask = 0 emask = 0 for i,c in enumerate(res): if c%2: omask |= 1<<i elif c: emask |= 1<<i #print(bin(omask)[2:]) #print(bin(emask)[2:]) for i in range(n): a[i] &= emask res = maxSubarrayXOR(a, n) #print(bin(res)[2:]) print((omask + res*2))
# coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline #文字列入力のときは注意 n = int(eval(input())) a = [int(i) for i in readline().split()] from functools import reduce from operator import xor NMAX = 62 omask = reduce(xor,a) emask = (1<<NMAX)-1 emask ^= omask for i in range(n): a[i] &= emask k = 0 for i in range(NMAX,-1,-1): for j in range(k,n): if a[j] & (1<<i): if j != k: a[j], a[k] = a[k], a[j] for l in range(n): if l != k and a[l] & (1<<i): a[l] ^= a[k] k += 1 break print((omask + 2*reduce(xor,a)))
130
41
2,745
678
# Python program to find # maximum XOR subset # Number of bits to # represent int INT_BITS = 61 # Function to return # maximum XOR subset # in set[] def maxSubarrayXOR(set, n): # Initialize index of # chosen elements index = 0 # Traverse through all # bits of integer # starting from the most # significant bit (MSB) for i in range(INT_BITS - 1, -1, -1): # Initialize index of # maximum element and # the maximum element maxInd = index maxEle = -2147483648 for j in range(index, n): # If i'th bit of set[j] # is set and set[j] is # greater than max so far. if (set[j] & (1 << i)) != 0 and set[j] > maxEle: maxEle = set[j] maxInd = j # If there was no # element with i'th # bit set, move to # smaller i if maxEle == -2147483648: continue # Put maximum element # with i'th bit set # at index 'index' temp = set[index] set[index] = set[maxInd] set[maxInd] = temp # Update maxInd and # increment index maxInd = index # Do XOR of set[maxIndex] # with all numbers having # i'th bit as set. for j in range(n): # XOR set[maxInd] those # numbers which have the # i'th bit set if j != maxInd and (set[j] & (1 << i)) != 0: set[j] = set[j] ^ set[maxInd] # Increment index of # chosen elements index = index + 1 # Final result is # XOR of all elements res = 0 for i in range(n): res = res ^ set[i] return res # This code is contributed # by Anant Agarwal. # coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline # 文字列入力のときは注意 # n = int(input()) # n,k = [int(i) for i in readline().split()] n = int(eval(input())) a = [int(i) for i in readline().split()] res = [0] * 60 for i in a: b = bin(i)[:1:-1] # print(b) for j, c in enumerate(b): if c == "1": res[j] += 1 omask = 0 emask = 0 for i, c in enumerate(res): if c % 2: omask |= 1 << i elif c: emask |= 1 << i # print(bin(omask)[2:]) # print(bin(emask)[2:]) for i in range(n): a[i] &= emask res = maxSubarrayXOR(a, n) # print(bin(res)[2:]) print((omask + res * 2))
# coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline # 文字列入力のときは注意 n = int(eval(input())) a = [int(i) for i in readline().split()] from functools import reduce from operator import xor NMAX = 62 omask = reduce(xor, a) emask = (1 << NMAX) - 1 emask ^= omask for i in range(n): a[i] &= emask k = 0 for i in range(NMAX, -1, -1): for j in range(k, n): if a[j] & (1 << i): if j != k: a[j], a[k] = a[k], a[j] for l in range(n): if l != k and a[l] & (1 << i): a[l] ^= a[k] k += 1 break print((omask + 2 * reduce(xor, a)))
false
68.461538
[ "-# Python program to find", "-# maximum XOR subset", "-# Number of bits to", "-# represent int", "-INT_BITS = 61", "-# Function to return", "-# maximum XOR subset", "-# in set[]", "-def maxSubarrayXOR(set, n):", "- # Initialize index of", "- # chosen elements", "- index = 0", "- # Traverse through all", "- # bits of integer", "- # starting from the most", "- # significant bit (MSB)", "- for i in range(INT_BITS - 1, -1, -1):", "- # Initialize index of", "- # maximum element and", "- # the maximum element", "- maxInd = index", "- maxEle = -2147483648", "- for j in range(index, n):", "- # If i'th bit of set[j]", "- # is set and set[j] is", "- # greater than max so far.", "- if (set[j] & (1 << i)) != 0 and set[j] > maxEle:", "- maxEle = set[j]", "- maxInd = j", "- # If there was no", "- # element with i'th", "- # bit set, move to", "- # smaller i", "- if maxEle == -2147483648:", "- continue", "- # Put maximum element", "- # with i'th bit set", "- # at index 'index'", "- temp = set[index]", "- set[index] = set[maxInd]", "- set[maxInd] = temp", "- # Update maxInd and", "- # increment index", "- maxInd = index", "- # Do XOR of set[maxIndex]", "- # with all numbers having", "- # i'th bit as set.", "- for j in range(n):", "- # XOR set[maxInd] those", "- # numbers which have the", "- # i'th bit set", "- if j != maxInd and (set[j] & (1 << i)) != 0:", "- set[j] = set[j] ^ set[maxInd]", "- # Increment index of", "- # chosen elements", "- index = index + 1", "- # Final result is", "- # XOR of all elements", "- res = 0", "- for i in range(n):", "- res = res ^ set[i]", "- return res", "-", "-", "-# This code is contributed", "-# by Anant Agarwal.", "-# n = int(input())", "-# n,k = [int(i) for i in readline().split()]", "-res = [0] * 60", "-for i in a:", "- b = bin(i)[:1:-1]", "- # print(b)", "- for j, c in enumerate(b):", "- if c == \"1\":", "- res[j] += 1", "-omask = 0", "-emask = 0", "-for i, c in enumerate(res):", "- if c % 2:", "- omask |= 1 << i", "- elif c:", "- emask |= 1 << i", "-# print(bin(omask)[2:])", "-# print(bin(emask)[2:])", "+from functools import reduce", "+from operator import xor", "+", "+NMAX = 62", "+omask = reduce(xor, a)", "+emask = (1 << NMAX) - 1", "+emask ^= omask", "-res = maxSubarrayXOR(a, n)", "-# print(bin(res)[2:])", "-print((omask + res * 2))", "+k = 0", "+for i in range(NMAX, -1, -1):", "+ for j in range(k, n):", "+ if a[j] & (1 << i):", "+ if j != k:", "+ a[j], a[k] = a[k], a[j]", "+ for l in range(n):", "+ if l != k and a[l] & (1 << i):", "+ a[l] ^= a[k]", "+ k += 1", "+ break", "+print((omask + 2 * reduce(xor, a)))" ]
false
0.076841
0.066546
1.154705
[ "s112557186", "s201286715" ]
u094191970
p03645
python
s292323024
s915908025
1,256
1,074
81,584
79,544
Accepted
Accepted
14.49
from collections import deque n,m=list(map(int,input().split())) l=[list(map(int,input().split())) for i in range(m)] sx=0 gx=n-1 tree=[[] for i in range(n)] for i in l: tree[i[0]-1].append(i[1]-1) tree[i[1]-1].append(i[0]-1) dist=[-1 for i in range(n)] dist[sx]=0 que=deque() que.append(sx) while que: x=que.popleft() if x==gx and dist[gx]==2: print('POSSIBLE') exit() elif x==gx and dist[gx]!=2: print('IMPOSSIBLE') exit() for j in tree[x]: if dist[j]==-1: que.append(j) dist[j]=dist[x]+1 print('IMPOSSIBLE')
n,m=list(map(int,input().split())) l=[list(map(int,input().split())) for i in range(m)] tree=[[] for i in range(n)] for i in l: tree[i[0]-1].append(i[1]-1) tree[i[1]-1].append(i[0]-1) for i in tree: if 0 in i and n-1 in i: print('POSSIBLE') exit() print('IMPOSSIBLE')
35
13
635
303
from collections import deque n, m = list(map(int, input().split())) l = [list(map(int, input().split())) for i in range(m)] sx = 0 gx = n - 1 tree = [[] for i in range(n)] for i in l: tree[i[0] - 1].append(i[1] - 1) tree[i[1] - 1].append(i[0] - 1) dist = [-1 for i in range(n)] dist[sx] = 0 que = deque() que.append(sx) while que: x = que.popleft() if x == gx and dist[gx] == 2: print("POSSIBLE") exit() elif x == gx and dist[gx] != 2: print("IMPOSSIBLE") exit() for j in tree[x]: if dist[j] == -1: que.append(j) dist[j] = dist[x] + 1 print("IMPOSSIBLE")
n, m = list(map(int, input().split())) l = [list(map(int, input().split())) for i in range(m)] tree = [[] for i in range(n)] for i in l: tree[i[0] - 1].append(i[1] - 1) tree[i[1] - 1].append(i[0] - 1) for i in tree: if 0 in i and n - 1 in i: print("POSSIBLE") exit() print("IMPOSSIBLE")
false
62.857143
[ "-from collections import deque", "-", "-sx = 0", "-gx = n - 1", "-dist = [-1 for i in range(n)]", "-dist[sx] = 0", "-que = deque()", "-que.append(sx)", "-while que:", "- x = que.popleft()", "- if x == gx and dist[gx] == 2:", "+for i in tree:", "+ if 0 in i and n - 1 in i:", "- elif x == gx and dist[gx] != 2:", "- print(\"IMPOSSIBLE\")", "- exit()", "- for j in tree[x]:", "- if dist[j] == -1:", "- que.append(j)", "- dist[j] = dist[x] + 1" ]
false
0.04165
0.036422
1.143547
[ "s292323024", "s915908025" ]
u814781830
p02937
python
s486889794
s933587227
359
274
63,012
54,312
Accepted
Accepted
23.68
import bisect S = list(eval(input())) T = list(eval(input())) s_dict = {} # 二週分の文字とインデックス番号の組み合わせを保持 for s in S: s_dict[s] = [] for i, s in enumerate(S+S): bisect.insort_right(s_dict[s], i) N = len(S) try: ret = 0 cnt = 0 pre_t_idx = -1 for t in T: t_idx = s_dict[t][bisect.bisect_right(s_dict[t], pre_t_idx)] if t_idx > N-1: cnt += 1 t_idx -= N ret = t_idx+1 pre_t_idx = t_idx print((cnt*N+ret)) except Exception as e: print((-1))
from bisect import bisect_right def main(): S = eval(input()) T = eval(input()) lens = len(S) s = set(S) t = set(T) for i in t: if not i in s: return -2 S = S + S alpha = [[] for i in range(26)] for i, v in enumerate(S): alpha[ord(v)-ord('a')].append(i) ans = 0 idx = -1 cnt = 0 for i in T: # 二分探索で探す idx = bisect_right(alpha[ord(i)-ord('a')], idx) idx = alpha[ord(i)-ord('a')][idx] cnt += idx // lens idx %= lens ans = cnt * lens + idx return ans print((main()+1))
26
28
531
613
import bisect S = list(eval(input())) T = list(eval(input())) s_dict = {} # 二週分の文字とインデックス番号の組み合わせを保持 for s in S: s_dict[s] = [] for i, s in enumerate(S + S): bisect.insort_right(s_dict[s], i) N = len(S) try: ret = 0 cnt = 0 pre_t_idx = -1 for t in T: t_idx = s_dict[t][bisect.bisect_right(s_dict[t], pre_t_idx)] if t_idx > N - 1: cnt += 1 t_idx -= N ret = t_idx + 1 pre_t_idx = t_idx print((cnt * N + ret)) except Exception as e: print((-1))
from bisect import bisect_right def main(): S = eval(input()) T = eval(input()) lens = len(S) s = set(S) t = set(T) for i in t: if not i in s: return -2 S = S + S alpha = [[] for i in range(26)] for i, v in enumerate(S): alpha[ord(v) - ord("a")].append(i) ans = 0 idx = -1 cnt = 0 for i in T: # 二分探索で探す idx = bisect_right(alpha[ord(i) - ord("a")], idx) idx = alpha[ord(i) - ord("a")][idx] cnt += idx // lens idx %= lens ans = cnt * lens + idx return ans print((main() + 1))
false
7.142857
[ "-import bisect", "+from bisect import bisect_right", "-S = list(eval(input()))", "-T = list(eval(input()))", "-s_dict = {}", "-# 二週分の文字とインデックス番号の組み合わせを保持", "-for s in S:", "- s_dict[s] = []", "-for i, s in enumerate(S + S):", "- bisect.insort_right(s_dict[s], i)", "-N = len(S)", "-try:", "- ret = 0", "+", "+def main():", "+ S = eval(input())", "+ T = eval(input())", "+ lens = len(S)", "+ s = set(S)", "+ t = set(T)", "+ for i in t:", "+ if not i in s:", "+ return -2", "+ S = S + S", "+ alpha = [[] for i in range(26)]", "+ for i, v in enumerate(S):", "+ alpha[ord(v) - ord(\"a\")].append(i)", "+ ans = 0", "+ idx = -1", "- pre_t_idx = -1", "- for t in T:", "- t_idx = s_dict[t][bisect.bisect_right(s_dict[t], pre_t_idx)]", "- if t_idx > N - 1:", "- cnt += 1", "- t_idx -= N", "- ret = t_idx + 1", "- pre_t_idx = t_idx", "- print((cnt * N + ret))", "-except Exception as e:", "- print((-1))", "+ for i in T:", "+ # 二分探索で探す", "+ idx = bisect_right(alpha[ord(i) - ord(\"a\")], idx)", "+ idx = alpha[ord(i) - ord(\"a\")][idx]", "+ cnt += idx // lens", "+ idx %= lens", "+ ans = cnt * lens + idx", "+ return ans", "+", "+", "+print((main() + 1))" ]
false
0.044033
0.074123
0.594059
[ "s486889794", "s933587227" ]
u736788838
p03109
python
s842843935
s620555187
20
17
3,188
2,940
Accepted
Accepted
15
date = eval(input()) import re date_num = int(re.sub("\D", "", date)) if date_num <= 20190430: print("Heisei") else: print("TBD")
date = int(input().replace("/", "")) if date <= 20190430: print("Heisei") else: print("TBD")
9
5
141
104
date = eval(input()) import re date_num = int(re.sub("\D", "", date)) if date_num <= 20190430: print("Heisei") else: print("TBD")
date = int(input().replace("/", "")) if date <= 20190430: print("Heisei") else: print("TBD")
false
44.444444
[ "-date = eval(input())", "-import re", "-", "-date_num = int(re.sub(\"\\D\", \"\", date))", "-if date_num <= 20190430:", "+date = int(input().replace(\"/\", \"\"))", "+if date <= 20190430:" ]
false
0.040025
0.038911
1.028624
[ "s842843935", "s620555187" ]
u037430802
p03221
python
s652021089
s605738416
719
633
36,668
35,568
Accepted
Accepted
11.96
import bisect n, m = list(map(int, input().split())) prefs_list = [] prefs_dict = {} for i in range(m): p, y = list(map(int, input().split())) prefs_list.append([p,y]) if p in prefs_dict: prefs_dict[p].append(y) else: prefs_dict[p] = [y] for key in prefs_dict: prefs_dict[key].sort() for pref in prefs_list: print((str(pref[0]).zfill(6) + str(bisect.bisect_left(prefs_dict[pref[0]], pref[1])+1).zfill(6)))
from collections import defaultdict import bisect N,M = list(map(int, input().split())) PY = [tuple(map(int, input().split())) for _ in range(M)] prefs = defaultdict(list) for p, y in PY: # ここで実際の誕生年をつめてから、あとで県ごとにソートして単なる順番に座標圧縮 prefs[p].append(y) for k in list(prefs.keys()): # 順に並び替えたので、後にbisectで位置を探せば誕生年から順番で取り出せる prefs[k].sort() for p, y in PY: idx = bisect.bisect_left(prefs[p], y) print((str(p).zfill(6) + str(idx+1).zfill(6)))
20
20
436
469
import bisect n, m = list(map(int, input().split())) prefs_list = [] prefs_dict = {} for i in range(m): p, y = list(map(int, input().split())) prefs_list.append([p, y]) if p in prefs_dict: prefs_dict[p].append(y) else: prefs_dict[p] = [y] for key in prefs_dict: prefs_dict[key].sort() for pref in prefs_list: print( ( str(pref[0]).zfill(6) + str(bisect.bisect_left(prefs_dict[pref[0]], pref[1]) + 1).zfill(6) ) )
from collections import defaultdict import bisect N, M = list(map(int, input().split())) PY = [tuple(map(int, input().split())) for _ in range(M)] prefs = defaultdict(list) for p, y in PY: # ここで実際の誕生年をつめてから、あとで県ごとにソートして単なる順番に座標圧縮 prefs[p].append(y) for k in list(prefs.keys()): # 順に並び替えたので、後にbisectで位置を探せば誕生年から順番で取り出せる prefs[k].sort() for p, y in PY: idx = bisect.bisect_left(prefs[p], y) print((str(p).zfill(6) + str(idx + 1).zfill(6)))
false
0
[ "+from collections import defaultdict", "-n, m = list(map(int, input().split()))", "-prefs_list = []", "-prefs_dict = {}", "-for i in range(m):", "- p, y = list(map(int, input().split()))", "- prefs_list.append([p, y])", "- if p in prefs_dict:", "- prefs_dict[p].append(y)", "- else:", "- prefs_dict[p] = [y]", "-for key in prefs_dict:", "- prefs_dict[key].sort()", "-for pref in prefs_list:", "- print(", "- (", "- str(pref[0]).zfill(6)", "- + str(bisect.bisect_left(prefs_dict[pref[0]], pref[1]) + 1).zfill(6)", "- )", "- )", "+N, M = list(map(int, input().split()))", "+PY = [tuple(map(int, input().split())) for _ in range(M)]", "+prefs = defaultdict(list)", "+for p, y in PY:", "+ # ここで実際の誕生年をつめてから、あとで県ごとにソートして単なる順番に座標圧縮", "+ prefs[p].append(y)", "+for k in list(prefs.keys()):", "+ # 順に並び替えたので、後にbisectで位置を探せば誕生年から順番で取り出せる", "+ prefs[k].sort()", "+for p, y in PY:", "+ idx = bisect.bisect_left(prefs[p], y)", "+ print((str(p).zfill(6) + str(idx + 1).zfill(6)))" ]
false
0.046782
0.045233
1.034244
[ "s652021089", "s605738416" ]
u815763296
p02608
python
s510832474
s215055768
834
111
9,184
9,348
Accepted
Accepted
86.69
import math N = int(eval(input())) ans = [0]*(N+1) Nruto = math.sqrt(N) Nruto = math.floor(Nruto)+1 for x in range(1, Nruto): for y in range(1, Nruto): for z in range(1, Nruto): n = x**2+y**2+z**2+x*y+y*z+z*x if n <= N: ans[n] += 1 for i in range(1, N+1): print((ans[i]))
import math N = int(eval(input())) ans = [0]*(N+1) owari = math.sqrt(N) owari = math.ceil(owari) for x in range(1, owari): a = x*x for y in range(1, owari): b = y*y c = x*y for z in range(1, owari): hantei = z*(z+x+y)+a+b+c if hantei > N: break ans[hantei] += 1 for i in range(1, N+1): print((ans[i]))
13
18
332
400
import math N = int(eval(input())) ans = [0] * (N + 1) Nruto = math.sqrt(N) Nruto = math.floor(Nruto) + 1 for x in range(1, Nruto): for y in range(1, Nruto): for z in range(1, Nruto): n = x**2 + y**2 + z**2 + x * y + y * z + z * x if n <= N: ans[n] += 1 for i in range(1, N + 1): print((ans[i]))
import math N = int(eval(input())) ans = [0] * (N + 1) owari = math.sqrt(N) owari = math.ceil(owari) for x in range(1, owari): a = x * x for y in range(1, owari): b = y * y c = x * y for z in range(1, owari): hantei = z * (z + x + y) + a + b + c if hantei > N: break ans[hantei] += 1 for i in range(1, N + 1): print((ans[i]))
false
27.777778
[ "-Nruto = math.sqrt(N)", "-Nruto = math.floor(Nruto) + 1", "-for x in range(1, Nruto):", "- for y in range(1, Nruto):", "- for z in range(1, Nruto):", "- n = x**2 + y**2 + z**2 + x * y + y * z + z * x", "- if n <= N:", "- ans[n] += 1", "+owari = math.sqrt(N)", "+owari = math.ceil(owari)", "+for x in range(1, owari):", "+ a = x * x", "+ for y in range(1, owari):", "+ b = y * y", "+ c = x * y", "+ for z in range(1, owari):", "+ hantei = z * (z + x + y) + a + b + c", "+ if hantei > N:", "+ break", "+ ans[hantei] += 1" ]
false
0.126452
0.042926
2.945799
[ "s510832474", "s215055768" ]
u506858457
p02803
python
s993380973
s827243953
701
358
14,484
3,316
Accepted
Accepted
48.93
from collections import deque import numpy as np H,W = list(map(int,input().split())) maze = [eval(input()) for _ in range(H)]#迷路の入力 ans = 0 for x in range(H):#すべてのマスからスタート for y in range(W): #壁からはスタートできない:スルー if maze[x][y] == "#": continue #初期化:0埋め、HとWの順番に注意 distance = [[0]*W for _ in range(H)] #start位置 stack = deque([[x,y]])#デキューに入れる while stack:#スタックが有るあいだ h,w = stack.popleft()#スタックの先頭を取ってくる for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:#マスの四方 new_h, new_w = h+i, w+j#新しいマス if new_h < 0 or new_w < 0 or new_h >= H or new_w >= W: continue#範囲外ならスルー elif maze[new_h][new_w] != "#" and distance[new_h][new_w] == 0: distance[new_h][new_w] = distance[h][w]+1#BFS、+1 stack.append([new_h, new_w])#新しいマスをスタックへ #start位置は0で初期化 distance[x][y] = 0 ans = max(ans, np.max(distance))#npは二次元のmax取れる print(ans)
'''ika tako スタートが決められたとき、そこから最も遠いマスは、 幅優先探索で最後に訪れたマスとなる。 よって、道である各マスをスタート地点として全て試し、 最長移動距離の最大値が答え。 H,W の上限が小さいので、スタート地点候補が最大400、 1回の探索で探索するマスが最大400、あわせて160000回に 比例する計算量で間に合う。 ''' from collections import deque def bfs(field, s): MOVE = [(0, 1), (1, 0), (0, -1), (-1, 0)] q = deque([(0, s)]) dist = [[-1] * w for _ in range(h)] d, i, j = -1, -1, -1 while q: d, (i, j) = q.popleft() if dist[i][j] != -1: continue dist[i][j] = d for di, dj in MOVE: ni, nj = i + di, j + dj if not 0 <= ni < h or not 0 <= nj < w: continue if field[ni][nj] == '#': continue if dist[ni][nj] != -1: continue q.append((d + 1, (ni, nj))) return d, i, j h, w = list(map(int, input().split())) field = [eval(input()) for _ in range(h)] ans = 0 for i in range(h): for j in range(w): if field[i][j] == '.': d, i, j = bfs(field, (i, j)) ans = max(ans, d) print(ans)
33
42
1,046
1,080
from collections import deque import numpy as np H, W = list(map(int, input().split())) maze = [eval(input()) for _ in range(H)] # 迷路の入力 ans = 0 for x in range(H): # すべてのマスからスタート for y in range(W): # 壁からはスタートできない:スルー if maze[x][y] == "#": continue # 初期化:0埋め、HとWの順番に注意 distance = [[0] * W for _ in range(H)] # start位置 stack = deque([[x, y]]) # デキューに入れる while stack: # スタックが有るあいだ h, w = stack.popleft() # スタックの先頭を取ってくる for i, j in [[1, 0], [-1, 0], [0, 1], [0, -1]]: # マスの四方 new_h, new_w = h + i, w + j # 新しいマス if new_h < 0 or new_w < 0 or new_h >= H or new_w >= W: continue # 範囲外ならスルー elif maze[new_h][new_w] != "#" and distance[new_h][new_w] == 0: distance[new_h][new_w] = distance[h][w] + 1 # BFS、+1 stack.append([new_h, new_w]) # 新しいマスをスタックへ # start位置は0で初期化 distance[x][y] = 0 ans = max(ans, np.max(distance)) # npは二次元のmax取れる print(ans)
"""ika tako スタートが決められたとき、そこから最も遠いマスは、 幅優先探索で最後に訪れたマスとなる。 よって、道である各マスをスタート地点として全て試し、 最長移動距離の最大値が答え。 H,W の上限が小さいので、スタート地点候補が最大400、 1回の探索で探索するマスが最大400、あわせて160000回に 比例する計算量で間に合う。 """ from collections import deque def bfs(field, s): MOVE = [(0, 1), (1, 0), (0, -1), (-1, 0)] q = deque([(0, s)]) dist = [[-1] * w for _ in range(h)] d, i, j = -1, -1, -1 while q: d, (i, j) = q.popleft() if dist[i][j] != -1: continue dist[i][j] = d for di, dj in MOVE: ni, nj = i + di, j + dj if not 0 <= ni < h or not 0 <= nj < w: continue if field[ni][nj] == "#": continue if dist[ni][nj] != -1: continue q.append((d + 1, (ni, nj))) return d, i, j h, w = list(map(int, input().split())) field = [eval(input()) for _ in range(h)] ans = 0 for i in range(h): for j in range(w): if field[i][j] == ".": d, i, j = bfs(field, (i, j)) ans = max(ans, d) print(ans)
false
21.428571
[ "+\"\"\"ika tako", "+スタートが決められたとき、そこから最も遠いマスは、", "+幅優先探索で最後に訪れたマスとなる。", "+よって、道である各マスをスタート地点として全て試し、", "+最長移動距離の最大値が答え。", "+H,W の上限が小さいので、スタート地点候補が最大400、", "+1回の探索で探索するマスが最大400、あわせて160000回に", "+比例する計算量で間に合う。", "+\"\"\"", "-import numpy as np", "-H, W = list(map(int, input().split()))", "-maze = [eval(input()) for _ in range(H)] # 迷路の入力", "+", "+def bfs(field, s):", "+ MOVE = [(0, 1), (1, 0), (0, -1), (-1, 0)]", "+ q = deque([(0, s)])", "+ dist = [[-1] * w for _ in range(h)]", "+ d, i, j = -1, -1, -1", "+ while q:", "+ d, (i, j) = q.popleft()", "+ if dist[i][j] != -1:", "+ continue", "+ dist[i][j] = d", "+ for di, dj in MOVE:", "+ ni, nj = i + di, j + dj", "+ if not 0 <= ni < h or not 0 <= nj < w:", "+ continue", "+ if field[ni][nj] == \"#\":", "+ continue", "+ if dist[ni][nj] != -1:", "+ continue", "+ q.append((d + 1, (ni, nj)))", "+ return d, i, j", "+", "+", "+h, w = list(map(int, input().split()))", "+field = [eval(input()) for _ in range(h)]", "-for x in range(H): # すべてのマスからスタート", "- for y in range(W):", "- # 壁からはスタートできない:スルー", "- if maze[x][y] == \"#\":", "- continue", "- # 初期化:0埋め、HとWの順番に注意", "- distance = [[0] * W for _ in range(H)]", "- # start位置", "- stack = deque([[x, y]]) # デキューに入れる", "- while stack: # スタックが有るあいだ", "- h, w = stack.popleft() # スタックの先頭を取ってくる", "- for i, j in [[1, 0], [-1, 0], [0, 1], [0, -1]]: # マスの四方", "- new_h, new_w = h + i, w + j # 新しいマス", "- if new_h < 0 or new_w < 0 or new_h >= H or new_w >= W:", "- continue # 範囲外ならスルー", "- elif maze[new_h][new_w] != \"#\" and distance[new_h][new_w] == 0:", "- distance[new_h][new_w] = distance[h][w] + 1 # BFS、+1", "- stack.append([new_h, new_w]) # 新しいマスをスタックへ", "- # start位置は0で初期化", "- distance[x][y] = 0", "- ans = max(ans, np.max(distance)) # npは二次元のmax取れる", "+for i in range(h):", "+ for j in range(w):", "+ if field[i][j] == \".\":", "+ d, i, j = bfs(field, (i, j))", "+ ans = max(ans, d)" ]
false
0.472936
0.067305
7.02678
[ "s993380973", "s827243953" ]
u687574784
p03599
python
s979575878
s765323918
41
32
9,952
9,220
Accepted
Accepted
21.95
from decimal import Decimal a,b,c,d,e,f = list(map(int, input().split())) maxn = -1 ans = () for at in range(0,31): for bt in range(0,31-at): water = (at * a + bt * b) * 100 if water > f: continue # 溶け残らないように砂糖を選ぶ maxsugar = water * e // 100 for ct in range(0, (maxsugar+1)//c + 1): for dt in range(0, (maxsugar-ct*c+1)//d + 1): sugar = ct * c + dt * d if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e: # 水100に対して溶けている砂糖の量 n = Decimal(100 * sugar / water) if n == Decimal(e): print((water + sugar, sugar)) exit() if n > maxn: ans = water + sugar, sugar maxn = n print((*ans))
a,b,c,d,e,f = list(map(int, input().split())) maxn = -1 ans = () for at in range(0,31): for bt in range(0,31-at): water = (at * a + bt * b) * 100 if water > f: continue # 溶け残らないように砂糖を選ぶ maxsugar = water * e // 100 for ct in range(0, (maxsugar+1)//c + 1): for dt in range(0, (maxsugar-ct*c+1)//d + 1): sugar = ct * c + dt * d if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e: # 水100に対して溶けている砂糖の量 n = 100 * sugar / water if n == e: print((water + sugar, sugar)) exit() if n > maxn: ans = water + sugar, sugar maxn = n print((*ans))
26
25
886
839
from decimal import Decimal a, b, c, d, e, f = list(map(int, input().split())) maxn = -1 ans = () for at in range(0, 31): for bt in range(0, 31 - at): water = (at * a + bt * b) * 100 if water > f: continue # 溶け残らないように砂糖を選ぶ maxsugar = water * e // 100 for ct in range(0, (maxsugar + 1) // c + 1): for dt in range(0, (maxsugar - ct * c + 1) // d + 1): sugar = ct * c + dt * d if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e: # 水100に対して溶けている砂糖の量 n = Decimal(100 * sugar / water) if n == Decimal(e): print((water + sugar, sugar)) exit() if n > maxn: ans = water + sugar, sugar maxn = n print((*ans))
a, b, c, d, e, f = list(map(int, input().split())) maxn = -1 ans = () for at in range(0, 31): for bt in range(0, 31 - at): water = (at * a + bt * b) * 100 if water > f: continue # 溶け残らないように砂糖を選ぶ maxsugar = water * e // 100 for ct in range(0, (maxsugar + 1) // c + 1): for dt in range(0, (maxsugar - ct * c + 1) // d + 1): sugar = ct * c + dt * d if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e: # 水100に対して溶けている砂糖の量 n = 100 * sugar / water if n == e: print((water + sugar, sugar)) exit() if n > maxn: ans = water + sugar, sugar maxn = n print((*ans))
false
3.846154
[ "-from decimal import Decimal", "-", "- n = Decimal(100 * sugar / water)", "- if n == Decimal(e):", "+ n = 100 * sugar / water", "+ if n == e:" ]
false
0.041072
0.091852
0.447154
[ "s979575878", "s765323918" ]
u241159583
p02627
python
s153337900
s134762226
34
27
9,028
9,020
Accepted
Accepted
20.59
a = eval(input()) print(("A" if a.upper()==a else "a"))
a = eval(input()) print(("A" if a == a.upper() else "a"))
2
2
48
50
a = eval(input()) print(("A" if a.upper() == a else "a"))
a = eval(input()) print(("A" if a == a.upper() else "a"))
false
0
[ "-print((\"A\" if a.upper() == a else \"a\"))", "+print((\"A\" if a == a.upper() else \"a\"))" ]
false
0.116492
0.040227
2.895837
[ "s153337900", "s134762226" ]
u201928947
p02558
python
s952132745
s186035498
388
355
81,308
76,848
Accepted
Accepted
8.51
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: li = [] while self.parents[x] >= 0: li.append(x) x = self.parents[x] for y in li: self.parents[y] = x return x def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) import sys input = sys.stdin.buffer.readline N,Q = list(map(int,input().split())) uf = UnionFind(N) for i in range(Q): t,u,v = list(map(int,input().split())) if t == 0: uf.union(u,v) else: if uf.same(u,v): print((1)) else: print((0))
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: li = [] while self.parents[x] >= 0: if self.parents[self.parents[x]] >= 0: self.parents[x] = self.parents[self.parents[x]] x = self.parents[x] return x def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) import sys input = sys.stdin.buffer.readline N,Q = list(map(int,input().split())) uf = UnionFind(N) for i in range(Q): t,u,v = list(map(int,input().split())) if t == 0: uf.union(u,v) else: if uf.same(u,v): print((1)) else: print((0))
65
64
1,604
1,636
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: li = [] while self.parents[x] >= 0: li.append(x) x = self.parents[x] for y in li: self.parents[y] = x return x def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) import sys input = sys.stdin.buffer.readline N, Q = list(map(int, input().split())) uf = UnionFind(N) for i in range(Q): t, u, v = list(map(int, input().split())) if t == 0: uf.union(u, v) else: if uf.same(u, v): print((1)) else: print((0))
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: li = [] while self.parents[x] >= 0: if self.parents[self.parents[x]] >= 0: self.parents[x] = self.parents[self.parents[x]] x = self.parents[x] return x def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) import sys input = sys.stdin.buffer.readline N, Q = list(map(int, input().split())) uf = UnionFind(N) for i in range(Q): t, u, v = list(map(int, input().split())) if t == 0: uf.union(u, v) else: if uf.same(u, v): print((1)) else: print((0))
false
1.538462
[ "- li.append(x)", "+ if self.parents[self.parents[x]] >= 0:", "+ self.parents[x] = self.parents[self.parents[x]]", "- for y in li:", "- self.parents[y] = x" ]
false
0.035789
0.035044
1.021256
[ "s952132745", "s186035498" ]
u952708174
p02706
python
s647580057
s018463498
24
21
9,888
10,052
Accepted
Accepted
12.5
N, M = [int(i) for i in input().split()] A = [int(i) for i in input().split()] ans = N - sum(A) print((ans if ans >= 0 else -1))
N, M = [int(i) for i in input().split()] A = [int(i) for i in input().split()] print((ans if (ans := N - sum(A)) >= 0 else -1))
5
3
131
127
N, M = [int(i) for i in input().split()] A = [int(i) for i in input().split()] ans = N - sum(A) print((ans if ans >= 0 else -1))
N, M = [int(i) for i in input().split()] A = [int(i) for i in input().split()] print((ans if (ans := N - sum(A)) >= 0 else -1))
false
40
[ "-ans = N - sum(A)", "-print((ans if ans >= 0 else -1))", "+print((ans if (ans := N - sum(A)) >= 0 else -1))" ]
false
0.045612
0.041432
1.100888
[ "s647580057", "s018463498" ]
u353895424
p02989
python
s818285665
s394778427
150
75
14,812
14,428
Accepted
Accepted
50
from collections import Counter n = int(eval(input())) d = list(map(int, input().split())) minD = min(d) maxD = max(d) c = Counter(d) abc = 0 arc = n ans = 0 for i in range(minD, maxD+1): abc += c[i-1] arc -= c[i-1] if abc == arc: ans += 1 print(ans)
n = int(eval(input())) d = list(map(int, input().split())) d.sort() print((max(0, d[n//2] - d[n//2 - 1])))
21
6
294
105
from collections import Counter n = int(eval(input())) d = list(map(int, input().split())) minD = min(d) maxD = max(d) c = Counter(d) abc = 0 arc = n ans = 0 for i in range(minD, maxD + 1): abc += c[i - 1] arc -= c[i - 1] if abc == arc: ans += 1 print(ans)
n = int(eval(input())) d = list(map(int, input().split())) d.sort() print((max(0, d[n // 2] - d[n // 2 - 1])))
false
71.428571
[ "-from collections import Counter", "-", "-minD = min(d)", "-maxD = max(d)", "-c = Counter(d)", "-abc = 0", "-arc = n", "-ans = 0", "-for i in range(minD, maxD + 1):", "- abc += c[i - 1]", "- arc -= c[i - 1]", "- if abc == arc:", "- ans += 1", "-print(ans)", "+d.sort()", "+print((max(0, d[n // 2] - d[n // 2 - 1])))" ]
false
0.103796
0.049141
2.112193
[ "s818285665", "s394778427" ]
u564902833
p03017
python
s925144599
s850148479
192
19
41,328
3,572
Accepted
Accepted
90.1
N, A, B, C, D = list(map(int, input().split())) S = eval(input()) S = '.' + S if C < D: ans = ( 'Yes' if '##' not in S[A:(D + 1)] else 'No' ) else: i = A j = B while i < C: if i + 1 == C or i + 2 == C: ans = 'Yes' break elif i + 1 <= C and S[i + 1] == '.' and i + 1 != j: i += 1 elif i + 2 <= C and S[i + 2] == '.' and i + 2 != j: i += 2 else: if j + 1 <= D and S[j + 1] == '.': j += 1 elif j + 2 <= D and S[j + 2] == '.': j += 2 else: ans = 'No' break print(ans)
# 入力 N, A, B, C, D = list(map(int, input().split())) S = eval(input()) # AからDの間に岩が二つ連続で置かれている箇所があれば不可 # C > D の場合、すぬけ君はふぬけ君を追い越す必要があることに注意 ans = ( 'Yes' if ('##' not in S[(A - 1):max(C, D)]) and ( C < D or '...' in S[(B - 2):(D + 1)] ) else 'No' ) # 出力 print(ans)
29
16
697
297
N, A, B, C, D = list(map(int, input().split())) S = eval(input()) S = "." + S if C < D: ans = "Yes" if "##" not in S[A : (D + 1)] else "No" else: i = A j = B while i < C: if i + 1 == C or i + 2 == C: ans = "Yes" break elif i + 1 <= C and S[i + 1] == "." and i + 1 != j: i += 1 elif i + 2 <= C and S[i + 2] == "." and i + 2 != j: i += 2 else: if j + 1 <= D and S[j + 1] == ".": j += 1 elif j + 2 <= D and S[j + 2] == ".": j += 2 else: ans = "No" break print(ans)
# 入力 N, A, B, C, D = list(map(int, input().split())) S = eval(input()) # AからDの間に岩が二つ連続で置かれている箇所があれば不可 # C > D の場合、すぬけ君はふぬけ君を追い越す必要があることに注意 ans = ( "Yes" if ("##" not in S[(A - 1) : max(C, D)]) and (C < D or "..." in S[(B - 2) : (D + 1)]) else "No" ) # 出力 print(ans)
false
44.827586
[ "+# 入力", "-S = \".\" + S", "-if C < D:", "- ans = \"Yes\" if \"##\" not in S[A : (D + 1)] else \"No\"", "-else:", "- i = A", "- j = B", "- while i < C:", "- if i + 1 == C or i + 2 == C:", "- ans = \"Yes\"", "- break", "- elif i + 1 <= C and S[i + 1] == \".\" and i + 1 != j:", "- i += 1", "- elif i + 2 <= C and S[i + 2] == \".\" and i + 2 != j:", "- i += 2", "- else:", "- if j + 1 <= D and S[j + 1] == \".\":", "- j += 1", "- elif j + 2 <= D and S[j + 2] == \".\":", "- j += 2", "- else:", "- ans = \"No\"", "- break", "+# AからDの間に岩が二つ連続で置かれている箇所があれば不可", "+# C > D の場合、すぬけ君はふぬけ君を追い越す必要があることに注意", "+ans = (", "+ \"Yes\"", "+ if (\"##\" not in S[(A - 1) : max(C, D)]) and (C < D or \"...\" in S[(B - 2) : (D + 1)])", "+ else \"No\"", "+)", "+# 出力" ]
false
0.047909
0.042384
1.130379
[ "s925144599", "s850148479" ]
u294922877
p02394
python
s151782323
s820723639
60
30
7,708
5,600
Accepted
Accepted
50
W,H,x,y,r = list(map(int,input().split())) print(('Yes' if (0<=x-r and x+r<=W and 0<=y-r and y+r<=H) else 'No'))
def judge(w, h, x, y, r): within_range = (0 <= x - r and x + r <= w) and (0 <= y - r and y + r <= h) return 'Yes' if within_range else 'No' if __name__ == '__main__': w, h, x, y, r = list(map(int, input().split(' '))) print((judge(w, h, x, y, r)))
2
8
105
265
W, H, x, y, r = list(map(int, input().split())) print(("Yes" if (0 <= x - r and x + r <= W and 0 <= y - r and y + r <= H) else "No"))
def judge(w, h, x, y, r): within_range = (0 <= x - r and x + r <= w) and (0 <= y - r and y + r <= h) return "Yes" if within_range else "No" if __name__ == "__main__": w, h, x, y, r = list(map(int, input().split(" "))) print((judge(w, h, x, y, r)))
false
75
[ "-W, H, x, y, r = list(map(int, input().split()))", "-print((\"Yes\" if (0 <= x - r and x + r <= W and 0 <= y - r and y + r <= H) else \"No\"))", "+def judge(w, h, x, y, r):", "+ within_range = (0 <= x - r and x + r <= w) and (0 <= y - r and y + r <= h)", "+ return \"Yes\" if within_range else \"No\"", "+", "+", "+if __name__ == \"__main__\":", "+ w, h, x, y, r = list(map(int, input().split(\" \")))", "+ print((judge(w, h, x, y, r)))" ]
false
0.116855
0.077512
1.50757
[ "s151782323", "s820723639" ]
u497952650
p03700
python
s672078989
s685444344
1,927
928
10,300
18,340
Accepted
Accepted
51.84
import sys from math import ceil """ def input(): return sys.stdin.readline().strip() """ def check(k): tmp = list(h) for i in range(N): tmp[i] -= B*k flag = False for i in tmp: if i > 0: flag = True break if not flag: return True lf = 0 for i in tmp: if i > 0: lf += ceil(i/(A-B)) if lf <= k: return True else: return False N,A,B = list(map(int,input().split())) h = tuple(int(eval(input())) for _ in range(N)) left = -1 right = 1e9 while abs(left-right) > 1: mid = (left+right)//2 if check(mid): right = mid else: left = mid print((int(right)))
from math import ceil def is_ok(m): tmp = h[:] for i in range(N): tmp[i] -= m*B flag = True for i in tmp: if i > 0: flag = False break if flag:##全部0以下 return True else: rem = 0 for i in tmp: if i > 0: rem += ceil(i/(A-B)) if rem > m: return False return True N,A,B = list(map(int,input().split())) h = list(int(eval(input())) for _ in range(N)) s = sum(h) ##二分散策 r = 10**10 l = 0 while abs(l-r) > 1: m = (r+l)//2 if is_ok(m): r = m else: l = m print(r)
44
47
739
676
import sys from math import ceil """ def input(): return sys.stdin.readline().strip() """ def check(k): tmp = list(h) for i in range(N): tmp[i] -= B * k flag = False for i in tmp: if i > 0: flag = True break if not flag: return True lf = 0 for i in tmp: if i > 0: lf += ceil(i / (A - B)) if lf <= k: return True else: return False N, A, B = list(map(int, input().split())) h = tuple(int(eval(input())) for _ in range(N)) left = -1 right = 1e9 while abs(left - right) > 1: mid = (left + right) // 2 if check(mid): right = mid else: left = mid print((int(right)))
from math import ceil def is_ok(m): tmp = h[:] for i in range(N): tmp[i] -= m * B flag = True for i in tmp: if i > 0: flag = False break if flag: ##全部0以下 return True else: rem = 0 for i in tmp: if i > 0: rem += ceil(i / (A - B)) if rem > m: return False return True N, A, B = list(map(int, input().split())) h = list(int(eval(input())) for _ in range(N)) s = sum(h) ##二分散策 r = 10**10 l = 0 while abs(l - r) > 1: m = (r + l) // 2 if is_ok(m): r = m else: l = m print(r)
false
6.382979
[ "-import sys", "-\"\"\"", "-def input():", "- return sys.stdin.readline().strip()", "-\"\"\"", "-", "-def check(k):", "- tmp = list(h)", "+def is_ok(m):", "+ tmp = h[:]", "- tmp[i] -= B * k", "- flag = False", "+ tmp[i] -= m * B", "+ flag = True", "- flag = True", "+ flag = False", "- if not flag:", "- return True", "- lf = 0", "- for i in tmp:", "- if i > 0:", "- lf += ceil(i / (A - B))", "- if lf <= k:", "+ if flag: ##全部0以下", "- return False", "+ rem = 0", "+ for i in tmp:", "+ if i > 0:", "+ rem += ceil(i / (A - B))", "+ if rem > m:", "+ return False", "+ return True", "-h = tuple(int(eval(input())) for _ in range(N))", "-left = -1", "-right = 1e9", "-while abs(left - right) > 1:", "- mid = (left + right) // 2", "- if check(mid):", "- right = mid", "+h = list(int(eval(input())) for _ in range(N))", "+s = sum(h)", "+##二分散策", "+r = 10**10", "+l = 0", "+while abs(l - r) > 1:", "+ m = (r + l) // 2", "+ if is_ok(m):", "+ r = m", "- left = mid", "-print((int(right)))", "+ l = m", "+print(r)" ]
false
0.036601
0.034266
1.068155
[ "s672078989", "s685444344" ]
u077898957
p02880
python
s443829921
s422736071
24
19
3,060
3,060
Accepted
Accepted
20.83
import sys n = int(eval(input())) for i in range(9): if n/(i+1) in (1,2,3,4,5,6,7,8,9): print('Yes') sys.exit() print('No')
n=int(eval(input())) ans='No' for i in range(1,10): for j in range(1,10): if i*j==n: ans='Yes' break print(ans)
7
8
143
148
import sys n = int(eval(input())) for i in range(9): if n / (i + 1) in (1, 2, 3, 4, 5, 6, 7, 8, 9): print("Yes") sys.exit() print("No")
n = int(eval(input())) ans = "No" for i in range(1, 10): for j in range(1, 10): if i * j == n: ans = "Yes" break print(ans)
false
12.5
[ "-import sys", "-", "-for i in range(9):", "- if n / (i + 1) in (1, 2, 3, 4, 5, 6, 7, 8, 9):", "- print(\"Yes\")", "- sys.exit()", "-print(\"No\")", "+ans = \"No\"", "+for i in range(1, 10):", "+ for j in range(1, 10):", "+ if i * j == n:", "+ ans = \"Yes\"", "+ break", "+print(ans)" ]
false
0.040774
0.07431
0.548702
[ "s443829921", "s422736071" ]
u761320129
p03127
python
s798301867
s933280354
86
63
16,280
20,476
Accepted
Accepted
26.74
from fractions import gcd N = int(eval(input())) A = list(map(int,input().split())) g = A[0] for a in A: g = gcd(g,a) print(g)
from math import gcd N = int(eval(input())) A = list(map(int,input().split())) g = 0 for a in A: g = gcd(a,g) print(g)
7
7
130
122
from fractions import gcd N = int(eval(input())) A = list(map(int, input().split())) g = A[0] for a in A: g = gcd(g, a) print(g)
from math import gcd N = int(eval(input())) A = list(map(int, input().split())) g = 0 for a in A: g = gcd(a, g) print(g)
false
0
[ "-from fractions import gcd", "+from math import gcd", "-g = A[0]", "+g = 0", "- g = gcd(g, a)", "+ g = gcd(a, g)" ]
false
0.046315
0.077395
0.59842
[ "s798301867", "s933280354" ]
u672475305
p03353
python
s898331418
s625049104
1,777
33
4,084
3,188
Accepted
Accepted
98.14
s = eval(input()) k = int(eval(input())) dct = [] for i in range(len(s)): for j in range(k+1): word = s[i:i+j] if word not in dct: dct.append(word) dct.sort() print((dct[k]))
s = eval(input()) k = int(eval(input())) lst = sorted(list(set(s))) tank = [] for tg in lst: for i in range(len(s)): if s[i]==tg: for j in range(k): if i+j<=len(s) and (s[i:i+j+1] not in tank): tank.append(s[i:i+j+1]) if len(tank) >= k: break tank.sort() print((tank[k-1]))
12
14
205
344
s = eval(input()) k = int(eval(input())) dct = [] for i in range(len(s)): for j in range(k + 1): word = s[i : i + j] if word not in dct: dct.append(word) dct.sort() print((dct[k]))
s = eval(input()) k = int(eval(input())) lst = sorted(list(set(s))) tank = [] for tg in lst: for i in range(len(s)): if s[i] == tg: for j in range(k): if i + j <= len(s) and (s[i : i + j + 1] not in tank): tank.append(s[i : i + j + 1]) if len(tank) >= k: break tank.sort() print((tank[k - 1]))
false
14.285714
[ "-dct = []", "-for i in range(len(s)):", "- for j in range(k + 1):", "- word = s[i : i + j]", "- if word not in dct:", "- dct.append(word)", "-dct.sort()", "-print((dct[k]))", "+lst = sorted(list(set(s)))", "+tank = []", "+for tg in lst:", "+ for i in range(len(s)):", "+ if s[i] == tg:", "+ for j in range(k):", "+ if i + j <= len(s) and (s[i : i + j + 1] not in tank):", "+ tank.append(s[i : i + j + 1])", "+ if len(tank) >= k:", "+ break", "+tank.sort()", "+print((tank[k - 1]))" ]
false
0.039116
0.038659
1.011823
[ "s898331418", "s625049104" ]
u968166680
p03557
python
s536658852
s192669527
378
303
22,720
22,720
Accepted
Accepted
19.84
from sys import stdin from bisect import bisect_right, bisect_left def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 i, j = 0, 0 for b in B: i = bisect_left(A, b, lo=i) j = bisect_right(C, b, lo=j) ans += i * (N - j) print(ans) if __name__ == "__main__": main()
from sys import stdin from bisect import bisect_right, bisect_left def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B) print(ans) if __name__ == "__main__": main()
30
24
543
463
from sys import stdin from bisect import bisect_right, bisect_left def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 i, j = 0, 0 for b in B: i = bisect_left(A, b, lo=i) j = bisect_right(C, b, lo=j) ans += i * (N - j) print(ans) if __name__ == "__main__": main()
from sys import stdin from bisect import bisect_right, bisect_left def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B) print(ans) if __name__ == "__main__": main()
false
20
[ "- ans = 0", "- i, j = 0, 0", "- for b in B:", "- i = bisect_left(A, b, lo=i)", "- j = bisect_right(C, b, lo=j)", "- ans += i * (N - j)", "+ ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)" ]
false
0.046179
0.046057
1.002658
[ "s536658852", "s192669527" ]
u987170100
p03371
python
s629385880
s905960283
193
99
9,188
8,888
Accepted
Accepted
48.7
A, B, C, X, Y = list(map(int, input().split())) ret = A * X + B * Y x = 0 y = 0 c = 0 while (X + Y) * 2 > c : c += 2 x += 1 y += 1 ret = min(ret, A * max(0, X - x) + B * max(0, Y - y) + c * C) print(ret)
A, B, C, X, Y = list(map(int, input().split())) ret = float('inf') for i in range(10 ** 5 + 1): ret = min(ret, A * max(0, X - i) + B * max(0, Y - i) + 2 * i * C) print(ret)
11
5
224
174
A, B, C, X, Y = list(map(int, input().split())) ret = A * X + B * Y x = 0 y = 0 c = 0 while (X + Y) * 2 > c: c += 2 x += 1 y += 1 ret = min(ret, A * max(0, X - x) + B * max(0, Y - y) + c * C) print(ret)
A, B, C, X, Y = list(map(int, input().split())) ret = float("inf") for i in range(10**5 + 1): ret = min(ret, A * max(0, X - i) + B * max(0, Y - i) + 2 * i * C) print(ret)
false
54.545455
[ "-ret = A * X + B * Y", "-x = 0", "-y = 0", "-c = 0", "-while (X + Y) * 2 > c:", "- c += 2", "- x += 1", "- y += 1", "- ret = min(ret, A * max(0, X - x) + B * max(0, Y - y) + c * C)", "+ret = float(\"inf\")", "+for i in range(10**5 + 1):", "+ ret = min(ret, A * max(0, X - i) + B * max(0, Y - i) + 2 * i * C)" ]
false
0.177843
0.339758
0.523441
[ "s629385880", "s905960283" ]
u072053884
p02271
python
s973853010
s145200991
4,250
20
7,768
8,076
Accepted
Accepted
99.53
def solve(A, i, m, n): """Return if it is possible to make value m with some elements in A. n is length of A. i is index. Using Divide-and-Conquer method. """ if m == 0: return True if i >= n or m < 0: return False return solve(A, i + 1, m, n) or solve(A, i + 1, m - A[i], n) import sys n = int(sys.stdin.readline()) A = tuple(map(int, sys.stdin.readline().split())) q = sys.stdin.readline() M = tuple(map(int, sys.stdin.readline().split())) s_A = sum(A) ans = '' for m in M: if s_A < m: ans += 'no\n' elif solve(A, 0, m, n): ans += 'yes\n' else: ans += 'no\n' print(ans, end = '')
def solve(A, i, m, n): """Return if it is possible to make value m with some elements in A. n is length of A. i is index. R is the record of answer i, m. Using Divide-and-Conquer method. """ if R[i][m] != None: return R[i][m] if m == 0: R[i][m] = True return True elif i >= n: R[i][m] = False return False else: ans = solve(A, i + 1, m, n) or solve(A, i + 1, m - A[i], n) R[i][m] = ans return ans import sys n = int(sys.stdin.readline()) A = tuple(map(int, sys.stdin.readline().split())) q = int(sys.stdin.readline()) M = tuple(map(int, sys.stdin.readline().split())) s_A = sum(A) R = [[None] * 2000 for i in range(n + 1)] ans = '' for m in M: if s_A < m: ans += 'no\n' elif solve(A, 0, m, n): ans += 'yes\n' else: ans += 'no\n' print(ans, end = '')
35
44
708
941
def solve(A, i, m, n): """Return if it is possible to make value m with some elements in A. n is length of A. i is index. Using Divide-and-Conquer method. """ if m == 0: return True if i >= n or m < 0: return False return solve(A, i + 1, m, n) or solve(A, i + 1, m - A[i], n) import sys n = int(sys.stdin.readline()) A = tuple(map(int, sys.stdin.readline().split())) q = sys.stdin.readline() M = tuple(map(int, sys.stdin.readline().split())) s_A = sum(A) ans = "" for m in M: if s_A < m: ans += "no\n" elif solve(A, 0, m, n): ans += "yes\n" else: ans += "no\n" print(ans, end="")
def solve(A, i, m, n): """Return if it is possible to make value m with some elements in A. n is length of A. i is index. R is the record of answer i, m. Using Divide-and-Conquer method. """ if R[i][m] != None: return R[i][m] if m == 0: R[i][m] = True return True elif i >= n: R[i][m] = False return False else: ans = solve(A, i + 1, m, n) or solve(A, i + 1, m - A[i], n) R[i][m] = ans return ans import sys n = int(sys.stdin.readline()) A = tuple(map(int, sys.stdin.readline().split())) q = int(sys.stdin.readline()) M = tuple(map(int, sys.stdin.readline().split())) s_A = sum(A) R = [[None] * 2000 for i in range(n + 1)] ans = "" for m in M: if s_A < m: ans += "no\n" elif solve(A, 0, m, n): ans += "yes\n" else: ans += "no\n" print(ans, end="")
false
20.454545
[ "+ R is the record of answer i, m.", "+ if R[i][m] != None:", "+ return R[i][m]", "+ R[i][m] = True", "- if i >= n or m < 0:", "+ elif i >= n:", "+ R[i][m] = False", "- return solve(A, i + 1, m, n) or solve(A, i + 1, m - A[i], n)", "+ else:", "+ ans = solve(A, i + 1, m, n) or solve(A, i + 1, m - A[i], n)", "+ R[i][m] = ans", "+ return ans", "-q = sys.stdin.readline()", "+q = int(sys.stdin.readline())", "+R = [[None] * 2000 for i in range(n + 1)]" ]
false
0.051841
0.051474
1.007121
[ "s973853010", "s145200991" ]
u784022244
p02996
python
s643430675
s676501957
955
873
39,700
33,396
Accepted
Accepted
8.59
N=int(eval(input())) AB=[] for i in range(N): a,b=list(map(int, input().split())) AB.append([a,b]) AB=sorted(AB, key=lambda x: x[1]) addtime=0 nowtime=0 for i in range(N): a=AB[i][0] b=AB[i][1] nowtime+=a if nowtime>b: print("No") exit() print("Yes")
N=int(eval(input())) now=0 L=[] for i in range(N): a,b=list(map(int, input().split())) L.append((a,b)) L=sorted(L, key=lambda x: x[1]) for i in range(N): t=L[i] a,b=t if now+a<=b: now+=a else: print("No") exit() print("Yes")
17
20
275
283
N = int(eval(input())) AB = [] for i in range(N): a, b = list(map(int, input().split())) AB.append([a, b]) AB = sorted(AB, key=lambda x: x[1]) addtime = 0 nowtime = 0 for i in range(N): a = AB[i][0] b = AB[i][1] nowtime += a if nowtime > b: print("No") exit() print("Yes")
N = int(eval(input())) now = 0 L = [] for i in range(N): a, b = list(map(int, input().split())) L.append((a, b)) L = sorted(L, key=lambda x: x[1]) for i in range(N): t = L[i] a, b = t if now + a <= b: now += a else: print("No") exit() print("Yes")
false
15
[ "-AB = []", "+now = 0", "+L = []", "- AB.append([a, b])", "-AB = sorted(AB, key=lambda x: x[1])", "-addtime = 0", "-nowtime = 0", "+ L.append((a, b))", "+L = sorted(L, key=lambda x: x[1])", "- a = AB[i][0]", "- b = AB[i][1]", "- nowtime += a", "- if nowtime > b:", "+ t = L[i]", "+ a, b = t", "+ if now + a <= b:", "+ now += a", "+ else:" ]
false
0.035126
0.035627
0.985941
[ "s643430675", "s676501957" ]
u761320129
p02973
python
s775724597
s303091464
864
237
73,556
7,836
Accepted
Accepted
72.57
from collections import defaultdict N = int(eval(input())) A = [int(eval(input())) for i in range(N)] d = defaultdict(lambda: []) for i,a in enumerate(A): d[a].append(i) B = [None for i in range(N)] for i,k in enumerate(sorted(d.keys())): for j in d[k]: B[j] = i bit = [0] * (N+2) def bit_add(a,w): x = a while x <= N+1: bit[x] += w x += (x & -x) def bit_sum(a): x = a ret = 0 while x > 0: ret += bit[x] x -= (x & -x) return ret for a in B: a += 2 s = bit_sum(a) bit_add(a,1) if s and bit_sum(a-1): t = bit_sum(a-1) ok = a-1 ng = 0 while ok-ng > 1: m = (ok+ng)//2 if bit_sum(m) == t: ok = m else: ng = m bit_add(ok,-1) # for i in range(N+1): # print(i+1, bit_sum(i+1)) print((bit_sum(N+1)))
from bisect import bisect N = int(eval(input())) A = [-int(eval(input())) for i in range(N)] mem = [] for a in A: i = bisect(mem, a) if i==len(mem): mem.append(a) else: mem[i] = a print((len(mem)))
48
12
938
223
from collections import defaultdict N = int(eval(input())) A = [int(eval(input())) for i in range(N)] d = defaultdict(lambda: []) for i, a in enumerate(A): d[a].append(i) B = [None for i in range(N)] for i, k in enumerate(sorted(d.keys())): for j in d[k]: B[j] = i bit = [0] * (N + 2) def bit_add(a, w): x = a while x <= N + 1: bit[x] += w x += x & -x def bit_sum(a): x = a ret = 0 while x > 0: ret += bit[x] x -= x & -x return ret for a in B: a += 2 s = bit_sum(a) bit_add(a, 1) if s and bit_sum(a - 1): t = bit_sum(a - 1) ok = a - 1 ng = 0 while ok - ng > 1: m = (ok + ng) // 2 if bit_sum(m) == t: ok = m else: ng = m bit_add(ok, -1) # for i in range(N+1): # print(i+1, bit_sum(i+1)) print((bit_sum(N + 1)))
from bisect import bisect N = int(eval(input())) A = [-int(eval(input())) for i in range(N)] mem = [] for a in A: i = bisect(mem, a) if i == len(mem): mem.append(a) else: mem[i] = a print((len(mem)))
false
75
[ "-from collections import defaultdict", "+from bisect import bisect", "-A = [int(eval(input())) for i in range(N)]", "-d = defaultdict(lambda: [])", "-for i, a in enumerate(A):", "- d[a].append(i)", "-B = [None for i in range(N)]", "-for i, k in enumerate(sorted(d.keys())):", "- for j in d[k]:", "- B[j] = i", "-bit = [0] * (N + 2)", "-", "-", "-def bit_add(a, w):", "- x = a", "- while x <= N + 1:", "- bit[x] += w", "- x += x & -x", "-", "-", "-def bit_sum(a):", "- x = a", "- ret = 0", "- while x > 0:", "- ret += bit[x]", "- x -= x & -x", "- return ret", "-", "-", "-for a in B:", "- a += 2", "- s = bit_sum(a)", "- bit_add(a, 1)", "- if s and bit_sum(a - 1):", "- t = bit_sum(a - 1)", "- ok = a - 1", "- ng = 0", "- while ok - ng > 1:", "- m = (ok + ng) // 2", "- if bit_sum(m) == t:", "- ok = m", "- else:", "- ng = m", "- bit_add(ok, -1)", "- # for i in range(N+1):", "- # print(i+1, bit_sum(i+1))", "-print((bit_sum(N + 1)))", "+A = [-int(eval(input())) for i in range(N)]", "+mem = []", "+for a in A:", "+ i = bisect(mem, a)", "+ if i == len(mem):", "+ mem.append(a)", "+ else:", "+ mem[i] = a", "+print((len(mem)))" ]
false
0.00719
0.040148
0.179091
[ "s775724597", "s303091464" ]
u785578220
p03472
python
s414485005
s348925053
491
397
25,936
12,236
Accepted
Accepted
19.14
from heapq import heappush, heappop from operator import itemgetter N, K = list(map(int, input().split())) a = [] aa = [] for i in range(N): ta,tb = list(map(int, input().split())) a.append([i,ta,tb]) aa.append(tb) a = sorted(a, key=itemgetter(2), reverse=True) aa.append(0) aa.sort() b = max(a, key=itemgetter(1))[1] n = K//b+1 res = 0 while K>0: t = aa.pop() if t > b: K -= t res+=1 else: res +=-(-K//b) K = 0 break print(res)
from heapq import heappush, heappop from operator import itemgetter N, K = list(map(int, input().split())) a = [] aa = [] for i in range(N): ta,tb = list(map(int, input().split())) a.append(ta) aa.append(tb) a = sorted(a) aa.append(0) aa.sort() b = max(a) n = K//b+1 res = 0 while K>0: t = aa.pop() if t > b: K -= t res+=1 else: res +=-(-K//b) K = 0 break print(res)
26
26
506
444
from heapq import heappush, heappop from operator import itemgetter N, K = list(map(int, input().split())) a = [] aa = [] for i in range(N): ta, tb = list(map(int, input().split())) a.append([i, ta, tb]) aa.append(tb) a = sorted(a, key=itemgetter(2), reverse=True) aa.append(0) aa.sort() b = max(a, key=itemgetter(1))[1] n = K // b + 1 res = 0 while K > 0: t = aa.pop() if t > b: K -= t res += 1 else: res += -(-K // b) K = 0 break print(res)
from heapq import heappush, heappop from operator import itemgetter N, K = list(map(int, input().split())) a = [] aa = [] for i in range(N): ta, tb = list(map(int, input().split())) a.append(ta) aa.append(tb) a = sorted(a) aa.append(0) aa.sort() b = max(a) n = K // b + 1 res = 0 while K > 0: t = aa.pop() if t > b: K -= t res += 1 else: res += -(-K // b) K = 0 break print(res)
false
0
[ "- a.append([i, ta, tb])", "+ a.append(ta)", "-a = sorted(a, key=itemgetter(2), reverse=True)", "+a = sorted(a)", "-b = max(a, key=itemgetter(1))[1]", "+b = max(a)" ]
false
0.045308
0.046073
0.983396
[ "s414485005", "s348925053" ]
u278356323
p03627
python
s884011529
s255952555
153
93
14,748
14,628
Accepted
Accepted
39.22
# ARC081c def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) from collections import Counter import heapq n = int(eval(input())) def fun(i): return -int(i) a = list(map(fun, input().split())) heapq.heapify(a) b = [] heapq.heapify(b) ln = 0 cou = 0 mn = 0 while(len(a) > 0): i = -heapq.heappop(a) # print(i) if ln != i: ln = i cou = 0 cou += 1 if cou > 1: heapq.heappush(b, -i) cou = 0 try: print((heapq.heappop(b)*heapq.heappop(b))) except: print((0)) if __name__ == '__main__': main()
# ARC081c def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) from collections import Counter import heapq n = int(eval(input())) a = list(map(int, input().split())) a.sort(reverse=True) b = [] heapq.heapify(b) ln = 0 cou = 0 for i in a: if ln != i: ln = i cou = 0 cou += 1 if cou > 1: heapq.heappush(b, -i) cou = 0 try: print((heapq.heappop(b)*heapq.heappop(b))) except: print((0)) if __name__ == '__main__': main()
39
33
732
623
# ARC081c def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) from collections import Counter import heapq n = int(eval(input())) def fun(i): return -int(i) a = list(map(fun, input().split())) heapq.heapify(a) b = [] heapq.heapify(b) ln = 0 cou = 0 mn = 0 while len(a) > 0: i = -heapq.heappop(a) # print(i) if ln != i: ln = i cou = 0 cou += 1 if cou > 1: heapq.heappush(b, -i) cou = 0 try: print((heapq.heappop(b) * heapq.heappop(b))) except: print((0)) if __name__ == "__main__": main()
# ARC081c def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) from collections import Counter import heapq n = int(eval(input())) a = list(map(int, input().split())) a.sort(reverse=True) b = [] heapq.heapify(b) ln = 0 cou = 0 for i in a: if ln != i: ln = i cou = 0 cou += 1 if cou > 1: heapq.heappush(b, -i) cou = 0 try: print((heapq.heappop(b) * heapq.heappop(b))) except: print((0)) if __name__ == "__main__": main()
false
15.384615
[ "-", "- def fun(i):", "- return -int(i)", "-", "- a = list(map(fun, input().split()))", "- heapq.heapify(a)", "+ a = list(map(int, input().split()))", "+ a.sort(reverse=True)", "- mn = 0", "- while len(a) > 0:", "- i = -heapq.heappop(a)", "- # print(i)", "+ for i in a:" ]
false
0.169342
0.037867
4.471993
[ "s884011529", "s255952555" ]
u521271655
p03775
python
s739995302
s549328987
68
42
3,060
9,412
Accepted
Accepted
38.24
N = int(eval(input())) for i in range(0,int(N**0.5)): if N % (int(N**0.5) - i) == 0: A = (int(N**0.5) - i) B = N//(int(N**0.5) - i) break print((len(str(B))))
n = int(eval(input())) ans = 10**100 for a in range(1,int(n**(0.5))+2): if n%a == 0: b = n//a f = len(str(b)) ans = min(ans,f) print(ans)
7
8
184
166
N = int(eval(input())) for i in range(0, int(N**0.5)): if N % (int(N**0.5) - i) == 0: A = int(N**0.5) - i B = N // (int(N**0.5) - i) break print((len(str(B))))
n = int(eval(input())) ans = 10**100 for a in range(1, int(n ** (0.5)) + 2): if n % a == 0: b = n // a f = len(str(b)) ans = min(ans, f) print(ans)
false
12.5
[ "-N = int(eval(input()))", "-for i in range(0, int(N**0.5)):", "- if N % (int(N**0.5) - i) == 0:", "- A = int(N**0.5) - i", "- B = N // (int(N**0.5) - i)", "- break", "-print((len(str(B))))", "+n = int(eval(input()))", "+ans = 10**100", "+for a in range(1, int(n ** (0.5)) + 2):", "+ if n % a == 0:", "+ b = n // a", "+ f = len(str(b))", "+ ans = min(ans, f)", "+print(ans)" ]
false
0.059575
0.053204
1.119732
[ "s739995302", "s549328987" ]
u421674761
p02576
python
s376150229
s893189984
35
27
9,088
9,112
Accepted
Accepted
22.86
n,x,t = list(map(int,input().split())) cnt = 0 while n > 0: n -= x cnt += 1 print((cnt*t))
n,x,t = list(map(int,input().split())) cnt = 0 while n > 0: n = n - x cnt += 1 print((cnt*t))
8
8
100
103
n, x, t = list(map(int, input().split())) cnt = 0 while n > 0: n -= x cnt += 1 print((cnt * t))
n, x, t = list(map(int, input().split())) cnt = 0 while n > 0: n = n - x cnt += 1 print((cnt * t))
false
0
[ "- n -= x", "+ n = n - x" ]
false
0.087505
0.036188
2.418099
[ "s376150229", "s893189984" ]
u800058906
p03037
python
s562386709
s995350734
245
204
28,552
16,964
Accepted
Accepted
16.73
n,m=list(map(int,input().split())) c=list() for i in range(m): c.append(list(map(int,input().split()))) s=(list([x[0] for x in c])) b=(list([x[1] for x in c])) maxs=max(s) minb=min(b) if minb<maxs: print('0') else: ans=minb-maxs+1 print(ans)
n,m=list(map(int,input().split())) a=[] b=[] for i in range(m): l,r=list(map(int,input().split())) a.append(l) b.append(r) x=max(a) y=min(b) if y-x<0: print('0') else: print((y-x+1))
17
14
277
202
n, m = list(map(int, input().split())) c = list() for i in range(m): c.append(list(map(int, input().split()))) s = list([x[0] for x in c]) b = list([x[1] for x in c]) maxs = max(s) minb = min(b) if minb < maxs: print("0") else: ans = minb - maxs + 1 print(ans)
n, m = list(map(int, input().split())) a = [] b = [] for i in range(m): l, r = list(map(int, input().split())) a.append(l) b.append(r) x = max(a) y = min(b) if y - x < 0: print("0") else: print((y - x + 1))
false
17.647059
[ "-c = list()", "+a = []", "+b = []", "- c.append(list(map(int, input().split())))", "-s = list([x[0] for x in c])", "-b = list([x[1] for x in c])", "-maxs = max(s)", "-minb = min(b)", "-if minb < maxs:", "+ l, r = list(map(int, input().split()))", "+ a.append(l)", "+ b.append(r)", "+x = max(a)", "+y = min(b)", "+if y - x < 0:", "- ans = minb - maxs + 1", "- print(ans)", "+ print((y - x + 1))" ]
false
0.038184
0.046536
0.820518
[ "s562386709", "s995350734" ]
u203239974
p02657
python
s299245958
s982665826
30
27
9,076
9,028
Accepted
Accepted
10
A,B = list(map(int,input().split(" "))) print((A*B))
if __name__ == "__main__": A,B = list(map(float,input().split(" "))) print((int((int(A)*(int((B)*100)))/100)))
2
3
51
119
A, B = list(map(int, input().split(" "))) print((A * B))
if __name__ == "__main__": A, B = list(map(float, input().split(" "))) print((int((int(A) * (int((B) * 100))) / 100)))
false
33.333333
[ "-A, B = list(map(int, input().split(\" \")))", "-print((A * B))", "+if __name__ == \"__main__\":", "+ A, B = list(map(float, input().split(\" \")))", "+ print((int((int(A) * (int((B) * 100))) / 100)))" ]
false
0.036101
0.038746
0.931745
[ "s299245958", "s982665826" ]
u764956288
p02683
python
s704228099
s859760836
146
56
27,308
9,220
Accepted
Accepted
61.64
import numpy as np from itertools import product def main(): N, M, X = list(map(int, input().split())) books = np.array([list(map(int, input().split())) for _ in range(N)]) min_total_cost = 10**9 for read_flags in product((True, False), repeat=N): to_read_books = books[read_flags, :] total_cost = to_read_books[:, 0].sum() increased_levels = to_read_books[:, 1:].sum(axis=0) if min(increased_levels) >= X: min_total_cost = min(min_total_cost, total_cost) if min_total_cost == 10**9: print('-1') else: print(min_total_cost) if __name__ == "__main__": main()
def main(): N, M, X = list(map(int, input().split())) books = [list(map(int, input().split())) for _ in range(N)] min_total_cost = 10**9 for i in range(2**N): total_cost = 0 learned = [0] * M for j in range(N): if (i >> j) & 1: cost, *points = books[j] total_cost += cost learned = [x + y for x, y in zip(learned, points)] if min(learned) >= X: min_total_cost = min(min_total_cost, total_cost) if min_total_cost == 10**9: print('-1') else: print(min_total_cost) if __name__ == "__main__": main()
27
29
675
675
import numpy as np from itertools import product def main(): N, M, X = list(map(int, input().split())) books = np.array([list(map(int, input().split())) for _ in range(N)]) min_total_cost = 10**9 for read_flags in product((True, False), repeat=N): to_read_books = books[read_flags, :] total_cost = to_read_books[:, 0].sum() increased_levels = to_read_books[:, 1:].sum(axis=0) if min(increased_levels) >= X: min_total_cost = min(min_total_cost, total_cost) if min_total_cost == 10**9: print("-1") else: print(min_total_cost) if __name__ == "__main__": main()
def main(): N, M, X = list(map(int, input().split())) books = [list(map(int, input().split())) for _ in range(N)] min_total_cost = 10**9 for i in range(2**N): total_cost = 0 learned = [0] * M for j in range(N): if (i >> j) & 1: cost, *points = books[j] total_cost += cost learned = [x + y for x, y in zip(learned, points)] if min(learned) >= X: min_total_cost = min(min_total_cost, total_cost) if min_total_cost == 10**9: print("-1") else: print(min_total_cost) if __name__ == "__main__": main()
false
6.896552
[ "-import numpy as np", "-from itertools import product", "-", "-", "- books = np.array([list(map(int, input().split())) for _ in range(N)])", "+ books = [list(map(int, input().split())) for _ in range(N)]", "- for read_flags in product((True, False), repeat=N):", "- to_read_books = books[read_flags, :]", "- total_cost = to_read_books[:, 0].sum()", "- increased_levels = to_read_books[:, 1:].sum(axis=0)", "- if min(increased_levels) >= X:", "+ for i in range(2**N):", "+ total_cost = 0", "+ learned = [0] * M", "+ for j in range(N):", "+ if (i >> j) & 1:", "+ cost, *points = books[j]", "+ total_cost += cost", "+ learned = [x + y for x, y in zip(learned, points)]", "+ if min(learned) >= X:" ]
false
0.272168
0.04566
5.960807
[ "s704228099", "s859760836" ]
u279605379
p02297
python
s571163927
s528688055
30
20
7,732
7,668
Accepted
Accepted
33.33
x=list(range(int(eval(input())))) P=[] for _ in x:P+=[[int(i) for i in input().split()]] _=0 P+=[P[0]] for j in x:_+=P[j][0]*P[j+1][1]-P[j][1]*P[j+1][0] print((_*0.5))
x=list(range(int(eval(input())))) P=[] Q=[] for _ in x:P+=[[int(i) for i in input().split()]] P+=[P[0]] for j in x:Q+=[P[j][0]*P[j+1][1]-P[j][1]*P[j+1][0]] print((sum(Q)*0.5))
7
7
159
167
x = list(range(int(eval(input())))) P = [] for _ in x: P += [[int(i) for i in input().split()]] _ = 0 P += [P[0]] for j in x: _ += P[j][0] * P[j + 1][1] - P[j][1] * P[j + 1][0] print((_ * 0.5))
x = list(range(int(eval(input())))) P = [] Q = [] for _ in x: P += [[int(i) for i in input().split()]] P += [P[0]] for j in x: Q += [P[j][0] * P[j + 1][1] - P[j][1] * P[j + 1][0]] print((sum(Q) * 0.5))
false
0
[ "+Q = []", "-_ = 0", "- _ += P[j][0] * P[j + 1][1] - P[j][1] * P[j + 1][0]", "-print((_ * 0.5))", "+ Q += [P[j][0] * P[j + 1][1] - P[j][1] * P[j + 1][0]]", "+print((sum(Q) * 0.5))" ]
false
0.037044
0.037635
0.984288
[ "s571163927", "s528688055" ]
u340781749
p02930
python
s860484128
s744701582
182
93
3,952
3,952
Accepted
Accepted
48.9
n = int(input()) for i in range(n): for j in range(i + 1, n): print((i ^ j & -(i ^ j)).bit_length(), end=' ') print()
n = int(eval(input())) for i in range(n): print((*((i ^ j & -(i ^ j)).bit_length() for j in range(i + 1, n))))
5
3
138
109
n = int(input()) for i in range(n): for j in range(i + 1, n): print((i ^ j & -(i ^ j)).bit_length(), end=" ") print()
n = int(eval(input())) for i in range(n): print((*((i ^ j & -(i ^ j)).bit_length() for j in range(i + 1, n))))
false
40
[ "-n = int(input())", "+n = int(eval(input()))", "- for j in range(i + 1, n):", "- print((i ^ j & -(i ^ j)).bit_length(), end=\" \")", "- print()", "+ print((*((i ^ j & -(i ^ j)).bit_length() for j in range(i + 1, n))))" ]
false
0.043961
0.037044
1.186741
[ "s860484128", "s744701582" ]
u350049649
p03081
python
s166200857
s681346518
1,977
1,522
25,660
25,588
Accepted
Accepted
23.01
N,Q=list(map(int,input().split())) S='.'+eval(input())+'.' TD=[] for i in range(Q): t, d = input().split() if d=='L': TD.append([t,-1]) else: TD.append([t,1]) def check(place): for i in range(Q): td=TD[i] if td[0]!=S[place]: continue else: place+=td[1] if place<=0: return -1 if place>=N+1: return 1 return 0 l,r=0,N+1 L,R=0,N+1 while abs(r-l)>1: m=(l+r)//2 if check(m)<0: l=m else: r=m L=l l,r=0,N+1 while abs(r-l)>1: m=(l+r)//2 if check(m)>0: r=m else: l=m R=r print((max(R-L-1,0)))
N,Q=list(map(int,input().split())) S=eval(input()) TD=[] for i in range(Q): t, d = input().split() if d=='L': TD.append([t,-1]) else: TD.append([t,1]) def check(place): for td in TD: if td[0]==S[place]: place+=td[1] if place<0: return -1 elif place>=N: return 1 return 0 l,r=-1,N L,R=-1,N while abs(r-l)>1: m=(l+r)//2 if check(m)<0: l=m else: r=m L=l l,r=-1,N while abs(r-l)>1: m=(l+r)//2 if check(m)>0: r=m else: l=m R=r print((max(R-L-1,0)))
47
43
705
647
N, Q = list(map(int, input().split())) S = "." + eval(input()) + "." TD = [] for i in range(Q): t, d = input().split() if d == "L": TD.append([t, -1]) else: TD.append([t, 1]) def check(place): for i in range(Q): td = TD[i] if td[0] != S[place]: continue else: place += td[1] if place <= 0: return -1 if place >= N + 1: return 1 return 0 l, r = 0, N + 1 L, R = 0, N + 1 while abs(r - l) > 1: m = (l + r) // 2 if check(m) < 0: l = m else: r = m L = l l, r = 0, N + 1 while abs(r - l) > 1: m = (l + r) // 2 if check(m) > 0: r = m else: l = m R = r print((max(R - L - 1, 0)))
N, Q = list(map(int, input().split())) S = eval(input()) TD = [] for i in range(Q): t, d = input().split() if d == "L": TD.append([t, -1]) else: TD.append([t, 1]) def check(place): for td in TD: if td[0] == S[place]: place += td[1] if place < 0: return -1 elif place >= N: return 1 return 0 l, r = -1, N L, R = -1, N while abs(r - l) > 1: m = (l + r) // 2 if check(m) < 0: l = m else: r = m L = l l, r = -1, N while abs(r - l) > 1: m = (l + r) // 2 if check(m) > 0: r = m else: l = m R = r print((max(R - L - 1, 0)))
false
8.510638
[ "-S = \".\" + eval(input()) + \".\"", "+S = eval(input())", "- for i in range(Q):", "- td = TD[i]", "- if td[0] != S[place]:", "- continue", "- else:", "+ for td in TD:", "+ if td[0] == S[place]:", "- if place <= 0:", "- return -1", "- if place >= N + 1:", "- return 1", "+ if place < 0:", "+ return -1", "+ elif place >= N:", "+ return 1", "-l, r = 0, N + 1", "-L, R = 0, N + 1", "+l, r = -1, N", "+L, R = -1, N", "-l, r = 0, N + 1", "+l, r = -1, N" ]
false
0.073867
0.11822
0.624831
[ "s166200857", "s681346518" ]
u741397536
p02936
python
s437948968
s673836763
1,801
1,663
227,804
265,280
Accepted
Accepted
7.66
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) N, Q = map(int, input().split()) T = [[]for i in range(N)] for i in range(N-1): a, b = map(int, input().split()) T[a-1].append(b-1) T[b-1].append(a-1) X = [0 for i in range(N)] for i in range(Q): p, x = map(int, input().split()) X[p-1] += x def dfs(x, p): for j in T[x]: if j == p: continue X[j] += X[x] dfs(j, x) dfs(0, -1) for i in range(N): print(X[i], end =" ")
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) N, Q = map(int, input().split()) T = [[]for i in range(N)] for i in range(N-1): a, b = map(int, input().split()) T[a-1].append(b-1) T[b-1].append(a-1) X = [0 for i in range(N)] for i in range(Q): p, x = map(int, input().split()) X[p-1] += x def dfs(x, p): for j in T[x]: if j == p: continue X[j] += X[x] dfs(j, x) dfs(0, -1) for i in range(N): print(X[i], end =" ") main()
30
32
537
676
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) N, Q = map(int, input().split()) T = [[] for i in range(N)] for i in range(N - 1): a, b = map(int, input().split()) T[a - 1].append(b - 1) T[b - 1].append(a - 1) X = [0 for i in range(N)] for i in range(Q): p, x = map(int, input().split()) X[p - 1] += x def dfs(x, p): for j in T[x]: if j == p: continue X[j] += X[x] dfs(j, x) dfs(0, -1) for i in range(N): print(X[i], end=" ")
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) N, Q = map(int, input().split()) T = [[] for i in range(N)] for i in range(N - 1): a, b = map(int, input().split()) T[a - 1].append(b - 1) T[b - 1].append(a - 1) X = [0 for i in range(N)] for i in range(Q): p, x = map(int, input().split()) X[p - 1] += x def dfs(x, p): for j in T[x]: if j == p: continue X[j] += X[x] dfs(j, x) dfs(0, -1) for i in range(N): print(X[i], end=" ") main()
false
6.25
[ "-import sys", "+def main():", "+ import sys", "-input = sys.stdin.readline", "-sys.setrecursionlimit(10**7)", "-N, Q = map(int, input().split())", "-T = [[] for i in range(N)]", "-for i in range(N - 1):", "- a, b = map(int, input().split())", "- T[a - 1].append(b - 1)", "- T[b - 1].append(a - 1)", "-X = [0 for i in range(N)]", "-for i in range(Q):", "- p, x = map(int, input().split())", "- X[p - 1] += x", "+ input = sys.stdin.readline", "+ sys.setrecursionlimit(10**7)", "+ N, Q = map(int, input().split())", "+ T = [[] for i in range(N)]", "+ for i in range(N - 1):", "+ a, b = map(int, input().split())", "+ T[a - 1].append(b - 1)", "+ T[b - 1].append(a - 1)", "+ X = [0 for i in range(N)]", "+ for i in range(Q):", "+ p, x = map(int, input().split())", "+ X[p - 1] += x", "+", "+ def dfs(x, p):", "+ for j in T[x]:", "+ if j == p:", "+ continue", "+ X[j] += X[x]", "+ dfs(j, x)", "+", "+ dfs(0, -1)", "+ for i in range(N):", "+ print(X[i], end=\" \")", "-def dfs(x, p):", "- for j in T[x]:", "- if j == p:", "- continue", "- X[j] += X[x]", "- dfs(j, x)", "-", "-", "-dfs(0, -1)", "-for i in range(N):", "- print(X[i], end=\" \")", "+main()" ]
false
0.040912
0.125502
0.325989
[ "s437948968", "s673836763" ]
u345621867
p02642
python
s028065641
s686560995
1,570
1,114
50,844
50,780
Accepted
Accepted
29.04
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) C = Counter(A) A = set(A) MAX_A = 10 ** 6 X = [0] * (MAX_A + 1) for a in A: for i in range(a, MAX_A + 1, a): X[i] += 1 ans = len([a for a in A if (X[a] == 1) and (C[a] == 1)]) print(ans)
from collections import Counter N = int(eval(input())) A = list(map(int,input().split())) C = Counter(A) A = set(A) B = [True] * (10 ** 6 + 1) for a in A: for i in range(2 * a,10**6 + 1 ,a): B[i] = False cnt = 0 for a in A: if (B[a] == True) and (C[a] == 1): cnt += 1 print(cnt)
14
14
298
309
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) C = Counter(A) A = set(A) MAX_A = 10**6 X = [0] * (MAX_A + 1) for a in A: for i in range(a, MAX_A + 1, a): X[i] += 1 ans = len([a for a in A if (X[a] == 1) and (C[a] == 1)]) print(ans)
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) C = Counter(A) A = set(A) B = [True] * (10**6 + 1) for a in A: for i in range(2 * a, 10**6 + 1, a): B[i] = False cnt = 0 for a in A: if (B[a] == True) and (C[a] == 1): cnt += 1 print(cnt)
false
0
[ "-MAX_A = 10**6", "-X = [0] * (MAX_A + 1)", "+B = [True] * (10**6 + 1)", "- for i in range(a, MAX_A + 1, a):", "- X[i] += 1", "-ans = len([a for a in A if (X[a] == 1) and (C[a] == 1)])", "-print(ans)", "+ for i in range(2 * a, 10**6 + 1, a):", "+ B[i] = False", "+cnt = 0", "+for a in A:", "+ if (B[a] == True) and (C[a] == 1):", "+ cnt += 1", "+print(cnt)" ]
false
0.372999
0.245301
1.520574
[ "s028065641", "s686560995" ]
u994988729
p03162
python
s182682929
s275636068
859
483
14,960
3,064
Accepted
Accepted
43.77
N=int(eval(input())) dp=[[0 for i in range(N+1)] for i in range(3)] for j in range(N): abc=list(map(int,input().split())) for i in range(3): if j==0: dp[i][j]=abc[i] else: dp[i][j]=max([dp[k][j-1]+abc[i] for k in range(3) if k!=i]) print((max([dp[i][N-1] for i in range(3)])))
N = int(eval(input())) dp = list(map(int, input().split())) for i in range(1, N): a, b, c = list(map(int, input().split())) newDP = [0] * 3 newDP[0] = max(dp[1], dp[2]) + a newDP[1] = max(dp[0], dp[2]) + b newDP[2] = max(dp[0], dp[1]) + c dp = newDP[::] ans = max(dp) print(ans)
11
14
327
307
N = int(eval(input())) dp = [[0 for i in range(N + 1)] for i in range(3)] for j in range(N): abc = list(map(int, input().split())) for i in range(3): if j == 0: dp[i][j] = abc[i] else: dp[i][j] = max([dp[k][j - 1] + abc[i] for k in range(3) if k != i]) print((max([dp[i][N - 1] for i in range(3)])))
N = int(eval(input())) dp = list(map(int, input().split())) for i in range(1, N): a, b, c = list(map(int, input().split())) newDP = [0] * 3 newDP[0] = max(dp[1], dp[2]) + a newDP[1] = max(dp[0], dp[2]) + b newDP[2] = max(dp[0], dp[1]) + c dp = newDP[::] ans = max(dp) print(ans)
false
21.428571
[ "-dp = [[0 for i in range(N + 1)] for i in range(3)]", "-for j in range(N):", "- abc = list(map(int, input().split()))", "- for i in range(3):", "- if j == 0:", "- dp[i][j] = abc[i]", "- else:", "- dp[i][j] = max([dp[k][j - 1] + abc[i] for k in range(3) if k != i])", "-print((max([dp[i][N - 1] for i in range(3)])))", "+dp = list(map(int, input().split()))", "+for i in range(1, N):", "+ a, b, c = list(map(int, input().split()))", "+ newDP = [0] * 3", "+ newDP[0] = max(dp[1], dp[2]) + a", "+ newDP[1] = max(dp[0], dp[2]) + b", "+ newDP[2] = max(dp[0], dp[1]) + c", "+ dp = newDP[::]", "+ans = max(dp)", "+print(ans)" ]
false
0.035603
0.040699
0.874798
[ "s182682929", "s275636068" ]
u664373116
p03038
python
s948960404
s976154860
667
591
32,448
32,448
Accepted
Accepted
11.39
from collections import Counter N,M=list(map(int,input().split())) cards=list(map(int,input().split())) all_c=Counter(cards) for i in range(M): time,val=list(map(int,input().split())) try: all_c[val]+=time except: all_c[val]=time tmp=list(all_c.keys()) tmp.sort(reverse=True) total=0 sum_time=0 for i in tmp: if sum_time>=N: break sum_time+=all_c[i] if sum_time<N: total+=i*all_c[i] else: total+=i*(all_c[i]+N-sum_time) print(total)
from collections import Counter N,M=list(map(int,input().split())) cards=list(map(int,input().split())) all_c=Counter(cards) for i in range(M): time,val=list(map(int,input().split())) if val in list(all_c.keys()): all_c[val]+=time else: all_c[val]=time """ try: all_c[val]+=time except: all_c[val]=time """ tmp=list(all_c.keys()) tmp.sort(reverse=True) total=0 sum_time=0 for i in tmp: if sum_time>=N: break sum_time+=all_c[i] if sum_time<N: total+=i*all_c[i] else: total+=i*(all_c[i]+N-sum_time) print(total)
25
31
527
636
from collections import Counter N, M = list(map(int, input().split())) cards = list(map(int, input().split())) all_c = Counter(cards) for i in range(M): time, val = list(map(int, input().split())) try: all_c[val] += time except: all_c[val] = time tmp = list(all_c.keys()) tmp.sort(reverse=True) total = 0 sum_time = 0 for i in tmp: if sum_time >= N: break sum_time += all_c[i] if sum_time < N: total += i * all_c[i] else: total += i * (all_c[i] + N - sum_time) print(total)
from collections import Counter N, M = list(map(int, input().split())) cards = list(map(int, input().split())) all_c = Counter(cards) for i in range(M): time, val = list(map(int, input().split())) if val in list(all_c.keys()): all_c[val] += time else: all_c[val] = time """ try: all_c[val]+=time except: all_c[val]=time """ tmp = list(all_c.keys()) tmp.sort(reverse=True) total = 0 sum_time = 0 for i in tmp: if sum_time >= N: break sum_time += all_c[i] if sum_time < N: total += i * all_c[i] else: total += i * (all_c[i] + N - sum_time) print(total)
false
19.354839
[ "+ if val in list(all_c.keys()):", "+ all_c[val] += time", "+ else:", "+ all_c[val] = time", "+ \"\"\"", "- all_c[val] += time", "+ all_c[val]+=time", "- all_c[val] = time", "+ all_c[val]=time", "+ \"\"\"" ]
false
0.04102
0.079827
0.513859
[ "s948960404", "s976154860" ]
u989345508
p03986
python
s584866420
s730209848
57
44
3,500
3,500
Accepted
Accepted
22.81
x=eval(input()) l=len(x) f=0 c=0 for i in range(l): if x[i]=="S": f+=1 else: if f==0: c+=1 else: f-=1 print((2*c))
x=eval(input()) f=0 c=0 #なかなか良い解法、flag立てる for i in x: if i=="S": f+=1 else: if f==0: c+=1 else: f-=1 print((2*c))
13
13
175
174
x = eval(input()) l = len(x) f = 0 c = 0 for i in range(l): if x[i] == "S": f += 1 else: if f == 0: c += 1 else: f -= 1 print((2 * c))
x = eval(input()) f = 0 c = 0 # なかなか良い解法、flag立てる for i in x: if i == "S": f += 1 else: if f == 0: c += 1 else: f -= 1 print((2 * c))
false
0
[ "-l = len(x)", "-for i in range(l):", "- if x[i] == \"S\":", "+# なかなか良い解法、flag立てる", "+for i in x:", "+ if i == \"S\":" ]
false
0.085205
0.089774
0.949099
[ "s584866420", "s730209848" ]
u591503175
p03163
python
s104718937
s446710120
688
195
171,656
91,548
Accepted
Accepted
71.66
N, W = [int(item) for item in input().split()] item = [[int(item) for item in input().split()] for _ in range(N)] dp = [[0 for _ in range(W+1)] for _ in range(N+1)] for i in range(N): for w in range(W+1): if 0 <= w - item[i][0]: dp[i+1][w] = max(dp[i][w], dp[i][w - item[i][0]] + item[i][1]) else: dp[i+1][w] = dp[i][w] print((dp[N][W]))
import sys input = sys.stdin.readline import numpy as np def main(): N, W = [int(item) for item in input().split()] item = np.array([[int(item) for item in input().split()] for _ in range(N)]) dp = np.zeros((N+1, W+1), dtype='int64') for i in range(N): dp[i+1] = dp[i] w, v = item[i] np.maximum(dp[i][:-w] + v, dp[i][w:], out=dp[i+1][w:]) # print(dp[i+1]) print((dp[N][W])) if __name__ == "__main__": main()
12
19
393
483
N, W = [int(item) for item in input().split()] item = [[int(item) for item in input().split()] for _ in range(N)] dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)] for i in range(N): for w in range(W + 1): if 0 <= w - item[i][0]: dp[i + 1][w] = max(dp[i][w], dp[i][w - item[i][0]] + item[i][1]) else: dp[i + 1][w] = dp[i][w] print((dp[N][W]))
import sys input = sys.stdin.readline import numpy as np def main(): N, W = [int(item) for item in input().split()] item = np.array([[int(item) for item in input().split()] for _ in range(N)]) dp = np.zeros((N + 1, W + 1), dtype="int64") for i in range(N): dp[i + 1] = dp[i] w, v = item[i] np.maximum(dp[i][:-w] + v, dp[i][w:], out=dp[i + 1][w:]) # print(dp[i+1]) print((dp[N][W])) if __name__ == "__main__": main()
false
36.842105
[ "-N, W = [int(item) for item in input().split()]", "-item = [[int(item) for item in input().split()] for _ in range(N)]", "-dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]", "-for i in range(N):", "- for w in range(W + 1):", "- if 0 <= w - item[i][0]:", "- dp[i + 1][w] = max(dp[i][w], dp[i][w - item[i][0]] + item[i][1])", "- else:", "- dp[i + 1][w] = dp[i][w]", "-print((dp[N][W]))", "+import sys", "+", "+input = sys.stdin.readline", "+import numpy as np", "+", "+", "+def main():", "+ N, W = [int(item) for item in input().split()]", "+ item = np.array([[int(item) for item in input().split()] for _ in range(N)])", "+ dp = np.zeros((N + 1, W + 1), dtype=\"int64\")", "+ for i in range(N):", "+ dp[i + 1] = dp[i]", "+ w, v = item[i]", "+ np.maximum(dp[i][:-w] + v, dp[i][w:], out=dp[i + 1][w:])", "+ # print(dp[i+1])", "+ print((dp[N][W]))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.039335
0.176368
0.22303
[ "s104718937", "s446710120" ]
u075012704
p03971
python
s716044248
s053751081
102
78
4,016
9,272
Accepted
Accepted
23.53
N, A, B = list(map(int, input().split())) S = eval(input()) passed = 0 oversea = 0 for s in S: if s == "a" and passed < A + B: passed += 1 print("Yes") continue if s == "b" and passed < A + B and oversea < B: passed += 1 oversea += 1 print("Yes") continue print("No")
N, A, B = list(map(int, input().split())) S = eval(input()) X, Y = 0, 0 for s in S: if s == 'c': print('No') if s == 'a': if X + Y < A + B: print('Yes') X += 1 else: print('No') if s == 'b': if X + Y < A + B and Y < B: print('Yes') Y += 1 else: print('No')
18
21
344
392
N, A, B = list(map(int, input().split())) S = eval(input()) passed = 0 oversea = 0 for s in S: if s == "a" and passed < A + B: passed += 1 print("Yes") continue if s == "b" and passed < A + B and oversea < B: passed += 1 oversea += 1 print("Yes") continue print("No")
N, A, B = list(map(int, input().split())) S = eval(input()) X, Y = 0, 0 for s in S: if s == "c": print("No") if s == "a": if X + Y < A + B: print("Yes") X += 1 else: print("No") if s == "b": if X + Y < A + B and Y < B: print("Yes") Y += 1 else: print("No")
false
14.285714
[ "-passed = 0", "-oversea = 0", "+X, Y = 0, 0", "- if s == \"a\" and passed < A + B:", "- passed += 1", "- print(\"Yes\")", "- continue", "- if s == \"b\" and passed < A + B and oversea < B:", "- passed += 1", "- oversea += 1", "- print(\"Yes\")", "- continue", "- print(\"No\")", "+ if s == \"c\":", "+ print(\"No\")", "+ if s == \"a\":", "+ if X + Y < A + B:", "+ print(\"Yes\")", "+ X += 1", "+ else:", "+ print(\"No\")", "+ if s == \"b\":", "+ if X + Y < A + B and Y < B:", "+ print(\"Yes\")", "+ Y += 1", "+ else:", "+ print(\"No\")" ]
false
0.083181
0.069345
1.199517
[ "s716044248", "s053751081" ]
u186838327
p03696
python
s707013046
s918428180
184
71
38,384
64,720
Accepted
Accepted
61.41
n = int(eval(input())) s = str(eval(input())) ans = s ans = list(ans) cum = 0 for i in range(n): if s[i] == '(': cum += 1 else: cum -= 1 if cum < 0: ans = ['('] + ans cum = 0 else: ans = ans + [')']*cum print((''.join(ans)))
n = int(eval(input())) s = str(eval(input())) c = 0 from collections import deque res = deque([]) for i in range(n): if s[i] =='(': c += 1 else: c -= 1 if c < 0: res.appendleft('(') c = 0 res.append(s[i]) if c > 0: res.append(')'*c) print((''.join(list(res))))
19
17
280
315
n = int(eval(input())) s = str(eval(input())) ans = s ans = list(ans) cum = 0 for i in range(n): if s[i] == "(": cum += 1 else: cum -= 1 if cum < 0: ans = ["("] + ans cum = 0 else: ans = ans + [")"] * cum print(("".join(ans)))
n = int(eval(input())) s = str(eval(input())) c = 0 from collections import deque res = deque([]) for i in range(n): if s[i] == "(": c += 1 else: c -= 1 if c < 0: res.appendleft("(") c = 0 res.append(s[i]) if c > 0: res.append(")" * c) print(("".join(list(res))))
false
10.526316
[ "-ans = s", "-ans = list(ans)", "-cum = 0", "+c = 0", "+from collections import deque", "+", "+res = deque([])", "- cum += 1", "+ c += 1", "- cum -= 1", "- if cum < 0:", "- ans = [\"(\"] + ans", "- cum = 0", "-else:", "- ans = ans + [\")\"] * cum", "-print((\"\".join(ans)))", "+ c -= 1", "+ if c < 0:", "+ res.appendleft(\"(\")", "+ c = 0", "+ res.append(s[i])", "+if c > 0:", "+ res.append(\")\" * c)", "+print((\"\".join(list(res))))" ]
false
0.040328
0.043596
0.925027
[ "s707013046", "s918428180" ]
u280552586
p03862
python
s953195237
s024838319
123
111
14,252
14,252
Accepted
Accepted
9.76
n, x = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 for i in range(1, n): if A[i-1]+A[i] <= x: continue eat = A[i-1]+A[i] - x ans += eat A[i] = max(0, A[i]-eat) print(ans)
n, x = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 for i in range(n): if i == 0: if A[i] <= x: continue eat = A[i] - x ans += eat A[i] = A[i] - eat continue if A[i-1]+A[i] <= x: continue eat = A[i-1] + A[i] - x ans += eat A[i] = A[i] - eat print(ans)
11
18
231
374
n, x = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 for i in range(1, n): if A[i - 1] + A[i] <= x: continue eat = A[i - 1] + A[i] - x ans += eat A[i] = max(0, A[i] - eat) print(ans)
n, x = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 for i in range(n): if i == 0: if A[i] <= x: continue eat = A[i] - x ans += eat A[i] = A[i] - eat continue if A[i - 1] + A[i] <= x: continue eat = A[i - 1] + A[i] - x ans += eat A[i] = A[i] - eat print(ans)
false
38.888889
[ "-for i in range(1, n):", "+for i in range(n):", "+ if i == 0:", "+ if A[i] <= x:", "+ continue", "+ eat = A[i] - x", "+ ans += eat", "+ A[i] = A[i] - eat", "+ continue", "- A[i] = max(0, A[i] - eat)", "+ A[i] = A[i] - eat" ]
false
0.056353
0.052165
1.080286
[ "s953195237", "s024838319" ]
u276192130
p03420
python
s344592921
s545814037
195
121
3,060
2,940
Accepted
Accepted
37.95
n, k = list(map(int, input().split())) ans = 0 if k == 0: ans = n*n else: for i in range(1, n+1): ans += n//i * max(i-k, 0) a = n//i * max(i-k, 0) b = 0 if i >= k and n % i != 0: ans += max(0, (n%i+1)-k) b = max(0, (n%i+1)-k) print(ans)
n, k = list(map(int, input().split())) ans = 0 if k == 0: ans = n * n else: for i in range(1, n + 1): ans += n // i * max(i - k, 0) if i >= k and n % i != 0: ans += max(0, (n % i + 1) - k) print(ans)
13
10
307
239
n, k = list(map(int, input().split())) ans = 0 if k == 0: ans = n * n else: for i in range(1, n + 1): ans += n // i * max(i - k, 0) a = n // i * max(i - k, 0) b = 0 if i >= k and n % i != 0: ans += max(0, (n % i + 1) - k) b = max(0, (n % i + 1) - k) print(ans)
n, k = list(map(int, input().split())) ans = 0 if k == 0: ans = n * n else: for i in range(1, n + 1): ans += n // i * max(i - k, 0) if i >= k and n % i != 0: ans += max(0, (n % i + 1) - k) print(ans)
false
23.076923
[ "- a = n // i * max(i - k, 0)", "- b = 0", "- b = max(0, (n % i + 1) - k)" ]
false
0.043479
0.046292
0.939245
[ "s344592921", "s545814037" ]
u729133443
p02777
python
s458140374
s728267259
161
17
38,256
2,940
Accepted
Accepted
89.44
s,a,u=open(0) i=s.find(u)<1 print((int(a[:2])-i,int(a[2:])-1+i))
s,a,u=open(0);i=u in s;print((int(a[:2])-1+i,int(a[2:])-i))
3
1
64
57
s, a, u = open(0) i = s.find(u) < 1 print((int(a[:2]) - i, int(a[2:]) - 1 + i))
s, a, u = open(0) i = u in s print((int(a[:2]) - 1 + i, int(a[2:]) - i))
false
66.666667
[ "-i = s.find(u) < 1", "-print((int(a[:2]) - i, int(a[2:]) - 1 + i))", "+i = u in s", "+print((int(a[:2]) - 1 + i, int(a[2:]) - i))" ]
false
0.036007
0.035049
1.027317
[ "s458140374", "s728267259" ]
u835482198
p04044
python
s160336765
s940522809
19
17
3,060
3,060
Accepted
Accepted
10.53
# https://atcoder.jp/contests/abc042/tasks/abc042_b N, L = list(map(int, input().split())) s = [eval(input()) for _ in range(N)] s = sorted(s) print(("".join(s)))
n, l = list(map(int, input().split())) print(("".join(sorted([eval(input()) for _ in range(n)]))))
6
2
155
86
# https://atcoder.jp/contests/abc042/tasks/abc042_b N, L = list(map(int, input().split())) s = [eval(input()) for _ in range(N)] s = sorted(s) print(("".join(s)))
n, l = list(map(int, input().split())) print(("".join(sorted([eval(input()) for _ in range(n)]))))
false
66.666667
[ "-# https://atcoder.jp/contests/abc042/tasks/abc042_b", "-N, L = list(map(int, input().split()))", "-s = [eval(input()) for _ in range(N)]", "-s = sorted(s)", "-print((\"\".join(s)))", "+n, l = list(map(int, input().split()))", "+print((\"\".join(sorted([eval(input()) for _ in range(n)]))))" ]
false
0.044515
0.044956
0.990201
[ "s160336765", "s940522809" ]
u294385082
p02881
python
s885261601
s670456567
408
368
2,940
3,060
Accepted
Accepted
9.8
n = int(eval(input())) tmp = 1 for i in range(1,10**6+1): if n%i == 0: if i <= n//i: tmp = i else: break elif tmp == 1 and i >= n/i: break print((tmp + (n//tmp) -2))
n = int(eval(input())) tmp = 1 for i in range(1,10**6+1): #10**12とかにしてしまうとTLE  #たとえばn=2*大きい素数である時を考えると,この時は全回ししてまう if n%i == 0: if i <= n//i: tmp = i else: break elif tmp == 1 and i >= n/i: break print((tmp + (n//tmp) -2))
13
14
207
267
n = int(eval(input())) tmp = 1 for i in range(1, 10**6 + 1): if n % i == 0: if i <= n // i: tmp = i else: break elif tmp == 1 and i >= n / i: break print((tmp + (n // tmp) - 2))
n = int(eval(input())) tmp = 1 for i in range(1, 10**6 + 1): # 10**12とかにしてしまうとTLE # たとえばn=2*大きい素数である時を考えると,この時は全回ししてまう if n % i == 0: if i <= n // i: tmp = i else: break elif tmp == 1 and i >= n / i: break print((tmp + (n // tmp) - 2))
false
7.142857
[ "-for i in range(1, 10**6 + 1):", "+for i in range(1, 10**6 + 1): # 10**12とかにしてしまうとTLE", "+ # たとえばn=2*大きい素数である時を考えると,この時は全回ししてまう" ]
false
0.170913
0.186988
0.91403
[ "s885261601", "s670456567" ]
u901122076
p03087
python
s402245229
s295311390
1,000
359
50,776
52,824
Accepted
Accepted
64.1
N, Q = list(map(int, input().split())) S = eval(input()) hit = [0] * N for i in range(0, N - 1): hit[i + 1] = hit[i] if S[i:i+2] == 'AC': hit[i + 1] += 1 for _ in range(0, Q): l, r = list(map(int, input().split())) result = hit[r - 1] - hit[l - 1] print(result)
import sys def input(): return sys.stdin.readline()[:-1] N, Q = list(map(int, input().split())) S = eval(input()) hit = [0] * N for i in range(0, N - 1): hit[i + 1] = hit[i] if S[i:i+2] == 'AC': hit[i + 1] += 1 for _ in range(0, Q): l, r = list(map(int, input().split())) result = hit[r - 1] - hit[l - 1] print(result)
16
22
292
362
N, Q = list(map(int, input().split())) S = eval(input()) hit = [0] * N for i in range(0, N - 1): hit[i + 1] = hit[i] if S[i : i + 2] == "AC": hit[i + 1] += 1 for _ in range(0, Q): l, r = list(map(int, input().split())) result = hit[r - 1] - hit[l - 1] print(result)
import sys def input(): return sys.stdin.readline()[:-1] N, Q = list(map(int, input().split())) S = eval(input()) hit = [0] * N for i in range(0, N - 1): hit[i + 1] = hit[i] if S[i : i + 2] == "AC": hit[i + 1] += 1 for _ in range(0, Q): l, r = list(map(int, input().split())) result = hit[r - 1] - hit[l - 1] print(result)
false
27.272727
[ "+import sys", "+", "+", "+def input():", "+ return sys.stdin.readline()[:-1]", "+", "+" ]
false
0.036062
0.035724
1.009436
[ "s402245229", "s295311390" ]
u815763296
p02724
python
s412821922
s400295407
30
25
8,992
9,096
Accepted
Accepted
16.67
X = int(eval(input())) ans = X//500*1000 X = X % 500 ans += X//5*5 print(ans)
def LI(): return list(map(int, input().split())) X = int(eval(input())) ans = X//500*1000 X = X % 500 ans += X//5*5 print(ans)
5
9
76
135
X = int(eval(input())) ans = X // 500 * 1000 X = X % 500 ans += X // 5 * 5 print(ans)
def LI(): return list(map(int, input().split())) X = int(eval(input())) ans = X // 500 * 1000 X = X % 500 ans += X // 5 * 5 print(ans)
false
44.444444
[ "+def LI():", "+ return list(map(int, input().split()))", "+", "+" ]
false
0.036381
0.039012
0.932574
[ "s412821922", "s400295407" ]
u891635666
p03000
python
s450873396
s694326417
167
17
38,384
3,064
Accepted
Accepted
89.82
n, x = list(map(int, input().split())) nums = list(map(int, input().split())) count = 1 s = 0 for num in nums: s += num if s <= x: count += 1 else: break print(count)
import sys input = sys.stdin.readline ri = lambda: int(eval(input())) rs = lambda: input().rstrip() ril = lambda: list(map(int, input().split())) rsl = lambda: input().rstrip().split() ris = lambda n: [ri() for _ in range(n)] rss = lambda n: [rs() for _ in range(n)] rils = lambda n: [ril() for _ in range(n)] rsls = lambda n: [rsl() for _ in range(n)] n, x = ril() ls = ril() s = 0 count = 0 for l in ls: s += l if s <= x: count += 1 else: break print((count + 1))
12
24
200
511
n, x = list(map(int, input().split())) nums = list(map(int, input().split())) count = 1 s = 0 for num in nums: s += num if s <= x: count += 1 else: break print(count)
import sys input = sys.stdin.readline ri = lambda: int(eval(input())) rs = lambda: input().rstrip() ril = lambda: list(map(int, input().split())) rsl = lambda: input().rstrip().split() ris = lambda n: [ri() for _ in range(n)] rss = lambda n: [rs() for _ in range(n)] rils = lambda n: [ril() for _ in range(n)] rsls = lambda n: [rsl() for _ in range(n)] n, x = ril() ls = ril() s = 0 count = 0 for l in ls: s += l if s <= x: count += 1 else: break print((count + 1))
false
50
[ "-n, x = list(map(int, input().split()))", "-nums = list(map(int, input().split()))", "-count = 1", "+import sys", "+", "+input = sys.stdin.readline", "+ri = lambda: int(eval(input()))", "+rs = lambda: input().rstrip()", "+ril = lambda: list(map(int, input().split()))", "+rsl = lambda: input().rstrip().split()", "+ris = lambda n: [ri() for _ in range(n)]", "+rss = lambda n: [rs() for _ in range(n)]", "+rils = lambda n: [ril() for _ in range(n)]", "+rsls = lambda n: [rsl() for _ in range(n)]", "+n, x = ril()", "+ls = ril()", "-for num in nums:", "- s += num", "+count = 0", "+for l in ls:", "+ s += l", "-print(count)", "+print((count + 1))" ]
false
0.038255
0.037641
1.016312
[ "s450873396", "s694326417" ]