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
u133936772
p03038
python
s560863961
s227577799
489
372
36,856
36,856
Accepted
Accepted
23.93
import sys f=lambda:list(map(int,sys.stdin.readline().split())) n,m=f() la=sorted(f()) ll=sorted([list(f()) for _ in range(m)],key=lambda k:-k[1]) ls=[] t=a=0 for b,c in ll: if t+b>n: ls+=[c]*(n-t); t=n; break ls+=[c]*b; t+=b for i in range(n): if i<t: a+=max(la[i],ls[i]) else: a+=la[i] print(a)
import sys f=lambda:list(map(int,sys.stdin.readline().split())) n,m=f();l=f();t=n for b,c in sorted([f() for _ in range(m)],key=lambda k:-k[1]): l+=[c]*b;t+=b if t>n*2:break l.sort() print((sum(l[-n:])))
14
8
311
213
import sys f = lambda: list(map(int, sys.stdin.readline().split())) n, m = f() la = sorted(f()) ll = sorted([list(f()) for _ in range(m)], key=lambda k: -k[1]) ls = [] t = a = 0 for b, c in ll: if t + b > n: ls += [c] * (n - t) t = n break ls += [c] * b t += b for i in range(n): if i < t: a += max(la[i], ls[i]) else: a += la[i] print(a)
import sys f = lambda: list(map(int, sys.stdin.readline().split())) n, m = f() l = f() t = n for b, c in sorted([f() for _ in range(m)], key=lambda k: -k[1]): l += [c] * b t += b if t > n * 2: break l.sort() print((sum(l[-n:])))
false
42.857143
[ "-la = sorted(f())", "-ll = sorted([list(f()) for _ in range(m)], key=lambda k: -k[1])", "-ls = []", "-t = a = 0", "-for b, c in ll:", "- if t + b > n:", "- ls += [c] * (n - t)", "- t = n", "+l = f()", "+t = n", "+for b, c in sorted([f() for _ in range(m)], key=lambda k: -k[1]):", "+ l += [c] * b", "+ t += b", "+ if t > n * 2:", "- ls += [c] * b", "- t += b", "-for i in range(n):", "- if i < t:", "- a += max(la[i], ls[i])", "- else:", "- a += la[i]", "-print(a)", "+l.sort()", "+print((sum(l[-n:])))" ]
false
0.068054
0.033468
2.03341
[ "s560863961", "s227577799" ]
u984276646
p02984
python
s325370751
s507594104
243
129
14,156
20,536
Accepted
Accepted
46.91
N = int(input()) A = list(map(int, input().split())) D = 0 for i in range(N): D += A[i] * ((-1) ** i) two_x1 = D for i in range(N - 1): print(two_x1, end = ' ') two_x1 = -two_x1 + 2 * A[i] print(two_x1)
N = int(input()) A = list(map(int, input().split())) S = 0 sign = 1 for i in range(N): S += sign * A[i] sign *= -1 for i in range(N): print(S, end = ' '*(i<N-1)) S *= -1 S += 2*A[i] print()
10
12
217
210
N = int(input()) A = list(map(int, input().split())) D = 0 for i in range(N): D += A[i] * ((-1) ** i) two_x1 = D for i in range(N - 1): print(two_x1, end=" ") two_x1 = -two_x1 + 2 * A[i] print(two_x1)
N = int(input()) A = list(map(int, input().split())) S = 0 sign = 1 for i in range(N): S += sign * A[i] sign *= -1 for i in range(N): print(S, end=" " * (i < N - 1)) S *= -1 S += 2 * A[i] print()
false
16.666667
[ "-D = 0", "+S = 0", "+sign = 1", "- D += A[i] * ((-1) ** i)", "-two_x1 = D", "-for i in range(N - 1):", "- print(two_x1, end=\" \")", "- two_x1 = -two_x1 + 2 * A[i]", "-print(two_x1)", "+ S += sign * A[i]", "+ sign *= -1", "+for i in range(N):", "+ print(S, end=\" \" * (i < N - 1))", "+ S *= -1", "+ S += 2 * A[i]", "+print()" ]
false
0.033494
0.035159
0.952659
[ "s325370751", "s507594104" ]
u657818166
p03354
python
s652021905
s862946315
778
579
14,580
15,220
Accepted
Accepted
25.58
class unionFind(): def __init__(self,n): self.tree=[-1]*n def find(self,x): if self.tree[x]<0: return x else: return self.find(self.tree[x]) def union(self,x,y): xr=self.find(x) yr=self.find(y) if xr!=yr: if self.tree[xr]<self.tree[yr]: self.tree[yr]=xr elif self.tree[xr]>self.tree[yr]: self.tree[xr]=yr else: self.tree[xr]-=1 self.tree[yr]=xr return True return False def main(): ans=0 n,m=list(map(int,input().split())) a=unionFind(n) li=[x-1 for x in list(map(int,input().split()))] for _ in range(m): x,y=list(map(int,input().split())) a.union(x-1,y-1) for x in range(n): ans += a.find(x)==a.find(li[x]) return ans print((main()))
class unionFind(): def __init__(self,n): self.tree=[-1]*n def find(self,x): if self.tree[x]<0: return x else: self.tree[x]=self.find(self.tree[x]) return self.tree[x] def union(self,x,y): xr=self.find(x) yr=self.find(y) if xr!=yr: if self.tree[xr]<self.tree[yr]: self.tree[yr]=xr elif self.tree[xr]>self.tree[yr]: self.tree[xr]=yr else: self.tree[xr]-=1 self.tree[yr]=xr return True return False def main(): ans=0 n,m=list(map(int,input().split())) a=unionFind(n) li=[x-1 for x in list(map(int,input().split()))] for _ in range(m): x,y=list(map(int,input().split())) a.union(x-1,y-1) for x in range(n): ans += a.find(x)==a.find(li[x]) return ans print((main()))
34
35
722
751
class unionFind: def __init__(self, n): self.tree = [-1] * n def find(self, x): if self.tree[x] < 0: return x else: return self.find(self.tree[x]) def union(self, x, y): xr = self.find(x) yr = self.find(y) if xr != yr: if self.tree[xr] < self.tree[yr]: self.tree[yr] = xr elif self.tree[xr] > self.tree[yr]: self.tree[xr] = yr else: self.tree[xr] -= 1 self.tree[yr] = xr return True return False def main(): ans = 0 n, m = list(map(int, input().split())) a = unionFind(n) li = [x - 1 for x in list(map(int, input().split()))] for _ in range(m): x, y = list(map(int, input().split())) a.union(x - 1, y - 1) for x in range(n): ans += a.find(x) == a.find(li[x]) return ans print((main()))
class unionFind: def __init__(self, n): self.tree = [-1] * n def find(self, x): if self.tree[x] < 0: return x else: self.tree[x] = self.find(self.tree[x]) return self.tree[x] def union(self, x, y): xr = self.find(x) yr = self.find(y) if xr != yr: if self.tree[xr] < self.tree[yr]: self.tree[yr] = xr elif self.tree[xr] > self.tree[yr]: self.tree[xr] = yr else: self.tree[xr] -= 1 self.tree[yr] = xr return True return False def main(): ans = 0 n, m = list(map(int, input().split())) a = unionFind(n) li = [x - 1 for x in list(map(int, input().split()))] for _ in range(m): x, y = list(map(int, input().split())) a.union(x - 1, y - 1) for x in range(n): ans += a.find(x) == a.find(li[x]) return ans print((main()))
false
2.857143
[ "- return self.find(self.tree[x])", "+ self.tree[x] = self.find(self.tree[x])", "+ return self.tree[x]" ]
false
0.045322
0.08697
0.521125
[ "s652021905", "s862946315" ]
u153665391
p02264
python
s800691541
s148948765
750
460
15,932
13,276
Accepted
Accepted
38.67
N, Q = list(map(int, input().strip().split())) A = [] D = {} for l in range(N): n, t = input().strip().split() A.append([n, int(t)]) T = 0 while A: l = A.pop(0) if l[1] > Q: l[1] -= Q T += Q A.append(l) else: T += l[1] print((l[0], T))
from collections import deque n,p=list(map(int ,input().split())) que=deque([]) for i in range(n): name,time=input().split() time=int(time) que.append([name,time]) t=0 while len(que)>0: atop=que.popleft() spend=min(atop[1],p) atop[1]-=spend t+=spend if(atop[1]==0): print((atop[0],t)) else: que.append(atop)
18
20
306
377
N, Q = list(map(int, input().strip().split())) A = [] D = {} for l in range(N): n, t = input().strip().split() A.append([n, int(t)]) T = 0 while A: l = A.pop(0) if l[1] > Q: l[1] -= Q T += Q A.append(l) else: T += l[1] print((l[0], T))
from collections import deque n, p = list(map(int, input().split())) que = deque([]) for i in range(n): name, time = input().split() time = int(time) que.append([name, time]) t = 0 while len(que) > 0: atop = que.popleft() spend = min(atop[1], p) atop[1] -= spend t += spend if atop[1] == 0: print((atop[0], t)) else: que.append(atop)
false
10
[ "-N, Q = list(map(int, input().strip().split()))", "-A = []", "-D = {}", "-for l in range(N):", "- n, t = input().strip().split()", "- A.append([n, int(t)])", "-T = 0", "-while A:", "- l = A.pop(0)", "- if l[1] > Q:", "- l[1] -= Q", "- T += Q", "- A.append(l)", "+from collections import deque", "+", "+n, p = list(map(int, input().split()))", "+que = deque([])", "+for i in range(n):", "+ name, time = input().split()", "+ time = int(time)", "+ que.append([name, time])", "+t = 0", "+while len(que) > 0:", "+ atop = que.popleft()", "+ spend = min(atop[1], p)", "+ atop[1] -= spend", "+ t += spend", "+ if atop[1] == 0:", "+ print((atop[0], t))", "- T += l[1]", "- print((l[0], T))", "+ que.append(atop)" ]
false
0.03698
0.036378
1.016546
[ "s800691541", "s148948765" ]
u138083942
p02627
python
s181119287
s496782556
80
27
61,592
9,028
Accepted
Accepted
66.25
def resolve(): import sys input = sys.stdin.readline n = str(input().rstrip()) if n.isupper(): print("A") else: print("a") # a_set = set() # duplicate = set() # for a in input().rstrip().split(): # a = int(a) # if a in a_set: # duplicate.add(a) # else: # a_set.add(a) # a_list = list(a_set) # a_list.sort() # answer = 0 # divisors = set() # for a in a_list: # judge = True # for divisor in divisors: # if a % divisor == 0: # judge = False # break # if judge: # divisors.add(a) # if a in duplicate: # continue # answer += 1 # print(answer) if __name__ == "__main__": resolve()
def resolve(): import sys input = sys.stdin.readline n = input().rstrip() if n.islower(): print("a") else: print("A") if __name__ == "__main__": resolve()
43
15
871
214
def resolve(): import sys input = sys.stdin.readline n = str(input().rstrip()) if n.isupper(): print("A") else: print("a") # a_set = set() # duplicate = set() # for a in input().rstrip().split(): # a = int(a) # if a in a_set: # duplicate.add(a) # else: # a_set.add(a) # a_list = list(a_set) # a_list.sort() # answer = 0 # divisors = set() # for a in a_list: # judge = True # for divisor in divisors: # if a % divisor == 0: # judge = False # break # if judge: # divisors.add(a) # if a in duplicate: # continue # answer += 1 # print(answer) if __name__ == "__main__": resolve()
def resolve(): import sys input = sys.stdin.readline n = input().rstrip() if n.islower(): print("a") else: print("A") if __name__ == "__main__": resolve()
false
65.116279
[ "- n = str(input().rstrip())", "- if n.isupper():", "+ n = input().rstrip()", "+ if n.islower():", "+ print(\"a\")", "+ else:", "- else:", "- print(\"a\")", "- # a_set = set()", "- # duplicate = set()", "- # for a in input().rstrip().split():", "- # a = int(a)", "- # if a in a_set:", "- # duplicate.add(a)", "- # else:", "- # a_set.add(a)", "- # a_list = list(a_set)", "- # a_list.sort()", "- # answer = 0", "- # divisors = set()", "- # for a in a_list:", "- # judge = True", "- # for divisor in divisors:", "- # if a % divisor == 0:", "- # judge = False", "- # break", "- # if judge:", "- # divisors.add(a)", "- # if a in duplicate:", "- # continue", "- # answer += 1", "- # print(answer)" ]
false
0.043068
0.044254
0.973183
[ "s181119287", "s496782556" ]
u654470292
p03775
python
s420364089
s427240799
174
81
39,152
74,912
Accepted
Accepted
53.45
n=int(eval(input())) a,b=0,0 for i in range(1,n+1): if n%i==0: a=i b=n//i if i>n//i: break alog,blog=1,1 i=0 while 1: a=a//10 if a==0: break alog+=1 while 1: b=b//10 if b==0: break blog+=1 print((max(alog,blog)))
import bisect, copy, heapq, math, sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) def celi(a,b): return -(-a//b) sys.setrecursionlimit(5000000) mod=pow(10,9)+7 al=[chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] n=int(eval(input())) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors lst=make_divisors(n) ans=float('inf') for i in lst: # print(i) ans=min(ans,max(len(str(i)),len(str(n//i)))) print(ans)
24
33
302
847
n = int(eval(input())) a, b = 0, 0 for i in range(1, n + 1): if n % i == 0: a = i b = n // i if i > n // i: break alog, blog = 1, 1 i = 0 while 1: a = a // 10 if a == 0: break alog += 1 while 1: b = b // 10 if b == 0: break blog += 1 print((max(alog, blog)))
import bisect, copy, heapq, math, sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0] + list(accumulate(lst)) def celi(a, b): return -(-a // b) sys.setrecursionlimit(5000000) mod = pow(10, 9) + 7 al = [chr(ord("a") + i) for i in range(26)] direction = [[1, 0], [0, 1], [-1, 0], [0, -1]] n = int(eval(input())) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return divisors lst = make_divisors(n) ans = float("inf") for i in lst: # print(i) ans = min(ans, max(len(str(i)), len(str(n // i)))) print(ans)
false
27.272727
[ "+import bisect, copy, heapq, math, sys", "+from collections import *", "+from functools import lru_cache", "+from itertools import accumulate, combinations, permutations, product", "+", "+", "+def input():", "+ return sys.stdin.readline()[:-1]", "+", "+", "+def ruiseki(lst):", "+ return [0] + list(accumulate(lst))", "+", "+", "+def celi(a, b):", "+ return -(-a // b)", "+", "+", "+sys.setrecursionlimit(5000000)", "+mod = pow(10, 9) + 7", "+al = [chr(ord(\"a\") + i) for i in range(26)]", "+direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]", "-a, b = 0, 0", "-for i in range(1, n + 1):", "- if n % i == 0:", "- a = i", "- b = n // i", "- if i > n // i:", "- break", "-alog, blog = 1, 1", "-i = 0", "-while 1:", "- a = a // 10", "- if a == 0:", "- break", "- alog += 1", "-while 1:", "- b = b // 10", "- if b == 0:", "- break", "- blog += 1", "-print((max(alog, blog)))", "+", "+", "+def make_divisors(n):", "+ divisors = []", "+ for i in range(1, int(n**0.5) + 1):", "+ if n % i == 0:", "+ divisors.append(i)", "+ if i != n // i:", "+ divisors.append(n // i)", "+ divisors.sort()", "+ return divisors", "+", "+", "+lst = make_divisors(n)", "+ans = float(\"inf\")", "+for i in lst:", "+ # print(i)", "+ ans = min(ans, max(len(str(i)), len(str(n // i))))", "+print(ans)" ]
false
0.060144
0.051994
1.156741
[ "s420364089", "s427240799" ]
u173148629
p02632
python
s851615691
s602456466
1,875
921
107,572
117,360
Accepted
Accepted
50.88
K=int(eval(input())) S=eval(input()) N=len(S) mod=10**9+7 fact=[0]*(K+N) fact[0]=fact[1]=1 for i in range(2,K+N): fact[i]=fact[i-1]*i%mod def comb(n,r): ret=fact[n]*pow(fact[r],mod-2,mod)*pow(fact[n-r],mod-2,mod)%mod return ret ans=0 for i in range(K+1): ans+=pow(26,i,mod)*pow(25,K-i,mod)*comb(K+N-1-i,N-1) ans%=mod print(ans)
K=int(eval(input())) S=eval(input()) N=len(S) mod=10**9+7 fact=[1]*(K+N) for i in range(2,K+N): fact[i]=fact[i-1]*i%mod inv=[1]*(K+N) inv[K+N-1]=pow(fact[K+N-1],mod-2,mod) for i in range(K+N-2,0,-1): inv[i]=inv[i+1]*(i+1)%mod def comb(n,r): ret=fact[n]*inv[r]*inv[n-r]%mod return ret ans=0 for i in range(K+1): ans+=pow(26,i,mod)*pow(25,K-i,mod)*comb(K+N-1-i,N-1) ans%=mod print(ans)
20
24
358
427
K = int(eval(input())) S = eval(input()) N = len(S) mod = 10**9 + 7 fact = [0] * (K + N) fact[0] = fact[1] = 1 for i in range(2, K + N): fact[i] = fact[i - 1] * i % mod def comb(n, r): ret = fact[n] * pow(fact[r], mod - 2, mod) * pow(fact[n - r], mod - 2, mod) % mod return ret ans = 0 for i in range(K + 1): ans += pow(26, i, mod) * pow(25, K - i, mod) * comb(K + N - 1 - i, N - 1) ans %= mod print(ans)
K = int(eval(input())) S = eval(input()) N = len(S) mod = 10**9 + 7 fact = [1] * (K + N) for i in range(2, K + N): fact[i] = fact[i - 1] * i % mod inv = [1] * (K + N) inv[K + N - 1] = pow(fact[K + N - 1], mod - 2, mod) for i in range(K + N - 2, 0, -1): inv[i] = inv[i + 1] * (i + 1) % mod def comb(n, r): ret = fact[n] * inv[r] * inv[n - r] % mod return ret ans = 0 for i in range(K + 1): ans += pow(26, i, mod) * pow(25, K - i, mod) * comb(K + N - 1 - i, N - 1) ans %= mod print(ans)
false
16.666667
[ "-fact = [0] * (K + N)", "-fact[0] = fact[1] = 1", "+fact = [1] * (K + N)", "+inv = [1] * (K + N)", "+inv[K + N - 1] = pow(fact[K + N - 1], mod - 2, mod)", "+for i in range(K + N - 2, 0, -1):", "+ inv[i] = inv[i + 1] * (i + 1) % mod", "- ret = fact[n] * pow(fact[r], mod - 2, mod) * pow(fact[n - r], mod - 2, mod) % mod", "+ ret = fact[n] * inv[r] * inv[n - r] % mod" ]
false
0.036984
0.036378
1.016678
[ "s851615691", "s602456466" ]
u695811449
p03078
python
s786667493
s877739811
1,060
404
151,768
56,668
Accepted
Accepted
61.89
import sys input = sys.stdin.readline X,Y,Z,K=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) AB=[] for a in A: for b in B: AB.append(a+b) AB.sort(reverse=True) AB=AB[:K] ALL=[] for ab in AB: for c in C: ALL.append(ab+c) ALL.sort(reverse=True) for k in range(K): print((ALL[k]))
import sys import heapq input = sys.stdin.readline X,Y,Z,K=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) ALL=[0]*K for a in A: for b in B: for c in C: if a+b+c>ALL[0]: heapq.heappush(ALL,a+b+c) heapq.heappop(ALL) else: break ALL.sort(reverse=True) for k in range(K): print((ALL[k]))
26
27
412
556
import sys input = sys.stdin.readline X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) AB = [] for a in A: for b in B: AB.append(a + b) AB.sort(reverse=True) AB = AB[:K] ALL = [] for ab in AB: for c in C: ALL.append(ab + c) ALL.sort(reverse=True) for k in range(K): print((ALL[k]))
import sys import heapq input = sys.stdin.readline X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) ALL = [0] * K for a in A: for b in B: for c in C: if a + b + c > ALL[0]: heapq.heappush(ALL, a + b + c) heapq.heappop(ALL) else: break ALL.sort(reverse=True) for k in range(K): print((ALL[k]))
false
3.703704
[ "+import heapq", "-AB = []", "+A.sort(reverse=True)", "+B.sort(reverse=True)", "+C.sort(reverse=True)", "+ALL = [0] * K", "- AB.append(a + b)", "-AB.sort(reverse=True)", "-AB = AB[:K]", "-ALL = []", "-for ab in AB:", "- for c in C:", "- ALL.append(ab + c)", "+ for c in C:", "+ if a + b + c > ALL[0]:", "+ heapq.heappush(ALL, a + b + c)", "+ heapq.heappop(ALL)", "+ else:", "+ break" ]
false
0.036246
0.044817
0.808757
[ "s786667493", "s877739811" ]
u780962115
p03295
python
s202193657
s818519030
589
318
25,372
91,184
Accepted
Accepted
46.01
# islands war n,m=list(map(int,input().split())) lists=[] for i in range(m): a,b=list(map(int,input().split())) lists.append((a,b)) lists=sorted(lists,key=lambda x:(x[0],x[1])) Uselist=[0 for i in range(n)] for j in lists: if not Uselist[j[0]]: Uselist[j[0]]=j else: continue uselist=[] for j in Uselist: if j!=0: uselist.append(j) counter=0 inf=0 maxi=10**15 length=len(uselist) for j in range(length): inf=max(inf,uselist[j][0]) maxi=min(maxi,uselist[j][1]) if inf<maxi: pass elif inf>=maxi: counter+=1 inf=maxi maxi=uselist[j][1] print((counter+1))
# atcoder -take a rest-(easy) def main(): N, M = list(map(int, input().split())) conflict = [tuple(map(int, input().split())) for i in range(M)] newest_destroyed = -1 conflict.sort(key=lambda x: x[1]) res = 0 for l, r in conflict: if not (l <= newest_destroyed < r): res += 1 newest_destroyed = r-1 print(res) return if __name__ == "__main__": main()
33
20
663
437
# islands war n, m = list(map(int, input().split())) lists = [] for i in range(m): a, b = list(map(int, input().split())) lists.append((a, b)) lists = sorted(lists, key=lambda x: (x[0], x[1])) Uselist = [0 for i in range(n)] for j in lists: if not Uselist[j[0]]: Uselist[j[0]] = j else: continue uselist = [] for j in Uselist: if j != 0: uselist.append(j) counter = 0 inf = 0 maxi = 10**15 length = len(uselist) for j in range(length): inf = max(inf, uselist[j][0]) maxi = min(maxi, uselist[j][1]) if inf < maxi: pass elif inf >= maxi: counter += 1 inf = maxi maxi = uselist[j][1] print((counter + 1))
# atcoder -take a rest-(easy) def main(): N, M = list(map(int, input().split())) conflict = [tuple(map(int, input().split())) for i in range(M)] newest_destroyed = -1 conflict.sort(key=lambda x: x[1]) res = 0 for l, r in conflict: if not (l <= newest_destroyed < r): res += 1 newest_destroyed = r - 1 print(res) return if __name__ == "__main__": main()
false
39.393939
[ "-# islands war", "-n, m = list(map(int, input().split()))", "-lists = []", "-for i in range(m):", "- a, b = list(map(int, input().split()))", "- lists.append((a, b))", "-lists = sorted(lists, key=lambda x: (x[0], x[1]))", "-Uselist = [0 for i in range(n)]", "-for j in lists:", "- if not Uselist[j[0]]:", "- Uselist[j[0]] = j", "- else:", "- continue", "-uselist = []", "-for j in Uselist:", "- if j != 0:", "- uselist.append(j)", "-counter = 0", "-inf = 0", "-maxi = 10**15", "-length = len(uselist)", "-for j in range(length):", "- inf = max(inf, uselist[j][0])", "- maxi = min(maxi, uselist[j][1])", "- if inf < maxi:", "- pass", "- elif inf >= maxi:", "- counter += 1", "- inf = maxi", "- maxi = uselist[j][1]", "-print((counter + 1))", "+# atcoder -take a rest-(easy)", "+def main():", "+ N, M = list(map(int, input().split()))", "+ conflict = [tuple(map(int, input().split())) for i in range(M)]", "+ newest_destroyed = -1", "+ conflict.sort(key=lambda x: x[1])", "+ res = 0", "+ for l, r in conflict:", "+ if not (l <= newest_destroyed < r):", "+ res += 1", "+ newest_destroyed = r - 1", "+ print(res)", "+ return", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.038789
0.037782
1.026674
[ "s202193657", "s818519030" ]
u761529120
p03111
python
s322736136
s918065718
576
121
62,044
74,288
Accepted
Accepted
78.99
def dfs(depth): if depth == N: ans.append(cal(v)) return for i in range(4): v[depth] = i dfs(depth+1) def cal(v): tmp = [0] * 3 for i in range(N): if v[i] == 0: tmp[0] += l[i] elif v[i] == 1: tmp[1] += l[i] elif v[i] == 2: tmp[2] += l[i] cnt = 0 if v.count(0) > 1: cnt += v.count(0) - 1 if v.count(1) > 1: cnt += v.count(1) - 1 if v.count(2) > 1: cnt += v.count(2) - 1 if v.count(0) == 0 or v.count(1) == 0 or v.count(2) == 0: return float('inf') diff = cnt * 10 for i in range(3): diff += abs(A[i]-tmp[i]) return diff N, *A= list(map(int, input().split())) l = [int(eval(input())) for _ in range(N)] v = [-1] * N ans = [] dfs(0) print((min(ans)))
from itertools import product def main(): N, A, B, C = list(map(int, input().split())) L = list(int(eval(input())) for _ in range(N)) ans = 0 # A => 0 # B => 1 # C => 2 ans = float('inf') for item in product(list(range(4)), repeat=N): length_A = 0 cnt_A = 0 score_A = 0 length_B = 0 cnt_B = 0 score_B = 0 length_C = 0 cnt_C = 0 score_C = 0 for i,j in enumerate(item): if j == 0: length_A += L[i] cnt_A += 1 if j == 1: length_B += L[i] cnt_B += 1 if j == 2: length_C += L[i] cnt_C += 1 if cnt_A == 0 or cnt_B == 0 or cnt_C == 0: continue score_A += abs(A - length_A) + 10 * (cnt_A - 1) score_B += abs(B - length_B) + 10 * (cnt_B - 1) score_C += abs(C - length_C) + 10 * (cnt_C - 1) ans = min(ans, score_A + score_B + score_C) print(ans) if __name__ == "__main__": main()
44
40
887
1,096
def dfs(depth): if depth == N: ans.append(cal(v)) return for i in range(4): v[depth] = i dfs(depth + 1) def cal(v): tmp = [0] * 3 for i in range(N): if v[i] == 0: tmp[0] += l[i] elif v[i] == 1: tmp[1] += l[i] elif v[i] == 2: tmp[2] += l[i] cnt = 0 if v.count(0) > 1: cnt += v.count(0) - 1 if v.count(1) > 1: cnt += v.count(1) - 1 if v.count(2) > 1: cnt += v.count(2) - 1 if v.count(0) == 0 or v.count(1) == 0 or v.count(2) == 0: return float("inf") diff = cnt * 10 for i in range(3): diff += abs(A[i] - tmp[i]) return diff N, *A = list(map(int, input().split())) l = [int(eval(input())) for _ in range(N)] v = [-1] * N ans = [] dfs(0) print((min(ans)))
from itertools import product def main(): N, A, B, C = list(map(int, input().split())) L = list(int(eval(input())) for _ in range(N)) ans = 0 # A => 0 # B => 1 # C => 2 ans = float("inf") for item in product(list(range(4)), repeat=N): length_A = 0 cnt_A = 0 score_A = 0 length_B = 0 cnt_B = 0 score_B = 0 length_C = 0 cnt_C = 0 score_C = 0 for i, j in enumerate(item): if j == 0: length_A += L[i] cnt_A += 1 if j == 1: length_B += L[i] cnt_B += 1 if j == 2: length_C += L[i] cnt_C += 1 if cnt_A == 0 or cnt_B == 0 or cnt_C == 0: continue score_A += abs(A - length_A) + 10 * (cnt_A - 1) score_B += abs(B - length_B) + 10 * (cnt_B - 1) score_C += abs(C - length_C) + 10 * (cnt_C - 1) ans = min(ans, score_A + score_B + score_C) print(ans) if __name__ == "__main__": main()
false
9.090909
[ "-def dfs(depth):", "- if depth == N:", "- ans.append(cal(v))", "- return", "- for i in range(4):", "- v[depth] = i", "- dfs(depth + 1)", "+from itertools import product", "-def cal(v):", "- tmp = [0] * 3", "- for i in range(N):", "- if v[i] == 0:", "- tmp[0] += l[i]", "- elif v[i] == 1:", "- tmp[1] += l[i]", "- elif v[i] == 2:", "- tmp[2] += l[i]", "- cnt = 0", "- if v.count(0) > 1:", "- cnt += v.count(0) - 1", "- if v.count(1) > 1:", "- cnt += v.count(1) - 1", "- if v.count(2) > 1:", "- cnt += v.count(2) - 1", "- if v.count(0) == 0 or v.count(1) == 0 or v.count(2) == 0:", "- return float(\"inf\")", "- diff = cnt * 10", "- for i in range(3):", "- diff += abs(A[i] - tmp[i])", "- return diff", "+def main():", "+ N, A, B, C = list(map(int, input().split()))", "+ L = list(int(eval(input())) for _ in range(N))", "+ ans = 0", "+ # A => 0", "+ # B => 1", "+ # C => 2", "+ ans = float(\"inf\")", "+ for item in product(list(range(4)), repeat=N):", "+ length_A = 0", "+ cnt_A = 0", "+ score_A = 0", "+ length_B = 0", "+ cnt_B = 0", "+ score_B = 0", "+ length_C = 0", "+ cnt_C = 0", "+ score_C = 0", "+ for i, j in enumerate(item):", "+ if j == 0:", "+ length_A += L[i]", "+ cnt_A += 1", "+ if j == 1:", "+ length_B += L[i]", "+ cnt_B += 1", "+ if j == 2:", "+ length_C += L[i]", "+ cnt_C += 1", "+ if cnt_A == 0 or cnt_B == 0 or cnt_C == 0:", "+ continue", "+ score_A += abs(A - length_A) + 10 * (cnt_A - 1)", "+ score_B += abs(B - length_B) + 10 * (cnt_B - 1)", "+ score_C += abs(C - length_C) + 10 * (cnt_C - 1)", "+ ans = min(ans, score_A + score_B + score_C)", "+ print(ans)", "-N, *A = list(map(int, input().split()))", "-l = [int(eval(input())) for _ in range(N)]", "-v = [-1] * N", "-ans = []", "-dfs(0)", "-print((min(ans)))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.167611
0.150646
1.112614
[ "s322736136", "s918065718" ]
u860829879
p03108
python
s716023632
s748702621
1,074
414
111,192
100,460
Accepted
Accepted
61.45
N,M=list(map(int,input().split())) edge=[list(map(int,input().split())) for _ in range(M)] current=N*(N-1)//2 ret=[0]*M par=list(range(N+1)) cnt=[1]*(N+1) rank=[0]*(N+1) def find(x): if x==par[x]: return x else: par[x]=find(par[x]) return par[x] def same(x,y): return find(x)==find(y) def size(x): return cnt[find(x)] def unite(x,y): x=find(x) y=find(y) if x==y: return 0 if rank[x]<rank[y]: cnt[y]+=size(x) par[x]=y else: cnt[x]+=size(y) par[y]=x if rank[x]==rank[y]:rank[x]+=1 for i in range(M-1,-1,-1): ret[i]=current a,b=edge[i] if not same(a,b): current-=size(a)*size(b) unite(a,b) for r in ret: print(r)
n,m=list(map(int,input().split())) edge=[list(map(int,input().split())) for _ in range(m)] ans=[] class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) 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()) uf=UnionFind(n) ans=[n*(n-1)//2] while len(edge)>1: a,b=edge.pop() a-=1 b-=1 if uf.same(a,b): s=ans[-1] else: s=ans[-1]-uf.size(a)*uf.size(b) uf.union(a,b) ans.append(s) while ans: print((ans.pop()))
50
67
815
1,554
N, M = list(map(int, input().split())) edge = [list(map(int, input().split())) for _ in range(M)] current = N * (N - 1) // 2 ret = [0] * M par = list(range(N + 1)) cnt = [1] * (N + 1) rank = [0] * (N + 1) def find(x): if x == par[x]: return x else: par[x] = find(par[x]) return par[x] def same(x, y): return find(x) == find(y) def size(x): return cnt[find(x)] def unite(x, y): x = find(x) y = find(y) if x == y: return 0 if rank[x] < rank[y]: cnt[y] += size(x) par[x] = y else: cnt[x] += size(y) par[y] = x if rank[x] == rank[y]: rank[x] += 1 for i in range(M - 1, -1, -1): ret[i] = current a, b = edge[i] if not same(a, b): current -= size(a) * size(b) unite(a, b) for r in ret: print(r)
n, m = list(map(int, input().split())) edge = [list(map(int, input().split())) for _ in range(m)] ans = [] class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) 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()) uf = UnionFind(n) ans = [n * (n - 1) // 2] while len(edge) > 1: a, b = edge.pop() a -= 1 b -= 1 if uf.same(a, b): s = ans[-1] else: s = ans[-1] - uf.size(a) * uf.size(b) uf.union(a, b) ans.append(s) while ans: print((ans.pop()))
false
25.373134
[ "-N, M = list(map(int, input().split()))", "-edge = [list(map(int, input().split())) for _ in range(M)]", "-current = N * (N - 1) // 2", "-ret = [0] * M", "-par = list(range(N + 1))", "-cnt = [1] * (N + 1)", "-rank = [0] * (N + 1)", "+n, m = list(map(int, input().split()))", "+edge = [list(map(int, input().split())) for _ in range(m)]", "+ans = []", "-def find(x):", "- if x == par[x]:", "- return x", "- else:", "- par[x] = find(par[x])", "- return par[x]", "+class UnionFind:", "+ def __init__(self, n):", "+ self.n = n", "+ self.parents = [-1] * n", "+", "+ def find(self, x):", "+ if self.parents[x] < 0:", "+ return x", "+ else:", "+ self.parents[x] = self.find(self.parents[x])", "+ return self.parents[x]", "+", "+ def union(self, x, y):", "+ x = self.find(x)", "+ y = self.find(y)", "+ if x == y:", "+ return", "+ if self.parents[x] > self.parents[y]:", "+ x, y = y, x", "+ self.parents[x] += self.parents[y]", "+ self.parents[y] = x", "+", "+ def size(self, x):", "+ return -self.parents[self.find(x)]", "+", "+ def same(self, x, y):", "+ return self.find(x) == self.find(y)", "+", "+ 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())", "-def same(x, y):", "- return find(x) == find(y)", "-", "-", "-def size(x):", "- return cnt[find(x)]", "-", "-", "-def unite(x, y):", "- x = find(x)", "- y = find(y)", "- if x == y:", "- return 0", "- if rank[x] < rank[y]:", "- cnt[y] += size(x)", "- par[x] = y", "+uf = UnionFind(n)", "+ans = [n * (n - 1) // 2]", "+while len(edge) > 1:", "+ a, b = edge.pop()", "+ a -= 1", "+ b -= 1", "+ if uf.same(a, b):", "+ s = ans[-1]", "- cnt[x] += size(y)", "- par[y] = x", "- if rank[x] == rank[y]:", "- rank[x] += 1", "-", "-", "-for i in range(M - 1, -1, -1):", "- ret[i] = current", "- a, b = edge[i]", "- if not same(a, b):", "- current -= size(a) * size(b)", "- unite(a, b)", "-for r in ret:", "- print(r)", "+ s = ans[-1] - uf.size(a) * uf.size(b)", "+ uf.union(a, b)", "+ ans.append(s)", "+while ans:", "+ print((ans.pop()))" ]
false
0.043638
0.043881
0.994444
[ "s716023632", "s748702621" ]
u075012704
p03798
python
s542285034
s999960901
382
156
8,932
14,736
Accepted
Accepted
59.16
N = int(eval(input())) S = eval(input()) # 0: S, 1: Wとする X = ['S', 'W'] for P in [[0, 0], [0, 1], [1, 0], [1, 1]]: for i, s in enumerate(S[1:], start=1): if s == 'o' and P[i] == 0: P.append(P[i - 1]) if s == 'o' and P[i] == 1: P.append(P[i - 1] ^ 1) if s == 'x' and P[i] == 0: P.append(P[i - 1] ^ 1) if s == 'x' and P[i] == 1: P.append(P[i - 1]) P = P[:-1] # 確認 for i in range(N): if (S[i] == 'o') and (P[i] == 0) and (P[i - 1] != P[(i + 1) % N]): break if (S[i] == 'o') and (P[i] == 1) and (P[i - 1] == P[(i + 1) % N]): break if (S[i] == 'x') and (P[i] == 0) and (P[i - 1] == P[(i + 1) % N]): break if (S[i] == 'x') and (P[i] == 1) and (P[i - 1] != P[(i + 1) % N]): break else: ans = [X[p] for p in P] print((''.join(ans))) exit() print((-1))
N = int(eval(input())) S = list(map(int, input().replace('o', '0').replace('x', '1'))) for p in [[0, 0], [0, 1], [1, 0], [1, 1]]: for s in S[1:]: if p[-1] ^ p[-2] ^ s == 1: p.append(1) else: p.append(0) if (p[0] == p[-1]) and (p[-2] ^ p[-3] ^ p[0] ^ S[-1] == 0) and (p[0] ^ p[-2] ^ p[1] ^ S[0] == 0): print((''.join(map(str, p[:-1])).replace('0', 'S').replace('1', 'W'))) break else: print((-1))
40
15
981
470
N = int(eval(input())) S = eval(input()) # 0: S, 1: Wとする X = ["S", "W"] for P in [[0, 0], [0, 1], [1, 0], [1, 1]]: for i, s in enumerate(S[1:], start=1): if s == "o" and P[i] == 0: P.append(P[i - 1]) if s == "o" and P[i] == 1: P.append(P[i - 1] ^ 1) if s == "x" and P[i] == 0: P.append(P[i - 1] ^ 1) if s == "x" and P[i] == 1: P.append(P[i - 1]) P = P[:-1] # 確認 for i in range(N): if (S[i] == "o") and (P[i] == 0) and (P[i - 1] != P[(i + 1) % N]): break if (S[i] == "o") and (P[i] == 1) and (P[i - 1] == P[(i + 1) % N]): break if (S[i] == "x") and (P[i] == 0) and (P[i - 1] == P[(i + 1) % N]): break if (S[i] == "x") and (P[i] == 1) and (P[i - 1] != P[(i + 1) % N]): break else: ans = [X[p] for p in P] print(("".join(ans))) exit() print((-1))
N = int(eval(input())) S = list(map(int, input().replace("o", "0").replace("x", "1"))) for p in [[0, 0], [0, 1], [1, 0], [1, 1]]: for s in S[1:]: if p[-1] ^ p[-2] ^ s == 1: p.append(1) else: p.append(0) if ( (p[0] == p[-1]) and (p[-2] ^ p[-3] ^ p[0] ^ S[-1] == 0) and (p[0] ^ p[-2] ^ p[1] ^ S[0] == 0) ): print(("".join(map(str, p[:-1])).replace("0", "S").replace("1", "W"))) break else: print((-1))
false
62.5
[ "-S = eval(input())", "-# 0: S, 1: Wとする", "-X = [\"S\", \"W\"]", "-for P in [[0, 0], [0, 1], [1, 0], [1, 1]]:", "- for i, s in enumerate(S[1:], start=1):", "- if s == \"o\" and P[i] == 0:", "- P.append(P[i - 1])", "- if s == \"o\" and P[i] == 1:", "- P.append(P[i - 1] ^ 1)", "- if s == \"x\" and P[i] == 0:", "- P.append(P[i - 1] ^ 1)", "- if s == \"x\" and P[i] == 1:", "- P.append(P[i - 1])", "- P = P[:-1]", "- # 確認", "- for i in range(N):", "- if (S[i] == \"o\") and (P[i] == 0) and (P[i - 1] != P[(i + 1) % N]):", "- break", "- if (S[i] == \"o\") and (P[i] == 1) and (P[i - 1] == P[(i + 1) % N]):", "- break", "- if (S[i] == \"x\") and (P[i] == 0) and (P[i - 1] == P[(i + 1) % N]):", "- break", "- if (S[i] == \"x\") and (P[i] == 1) and (P[i - 1] != P[(i + 1) % N]):", "- break", "- else:", "- ans = [X[p] for p in P]", "- print((\"\".join(ans)))", "- exit()", "-print((-1))", "+S = list(map(int, input().replace(\"o\", \"0\").replace(\"x\", \"1\")))", "+for p in [[0, 0], [0, 1], [1, 0], [1, 1]]:", "+ for s in S[1:]:", "+ if p[-1] ^ p[-2] ^ s == 1:", "+ p.append(1)", "+ else:", "+ p.append(0)", "+ if (", "+ (p[0] == p[-1])", "+ and (p[-2] ^ p[-3] ^ p[0] ^ S[-1] == 0)", "+ and (p[0] ^ p[-2] ^ p[1] ^ S[0] == 0)", "+ ):", "+ print((\"\".join(map(str, p[:-1])).replace(\"0\", \"S\").replace(\"1\", \"W\")))", "+ break", "+else:", "+ print((-1))" ]
false
0.089616
0.112004
0.800111
[ "s542285034", "s999960901" ]
u380524497
p04011
python
s001310706
s599430053
19
17
2,940
2,940
Accepted
Accepted
10.53
n, k, x, y = [int(eval(input())) for i in range(4)] sum = 0 for t in range(1, n+1): if t <= k: sum += x else: sum += y print(sum)
n = int(eval(input())) k = int(eval(input())) x = int(eval(input())) y = int(eval(input())) if n <= k: ans = n * x else: ans = k * x + (n-k) * y print(ans)
10
11
159
151
n, k, x, y = [int(eval(input())) for i in range(4)] sum = 0 for t in range(1, n + 1): if t <= k: sum += x else: sum += y print(sum)
n = int(eval(input())) k = int(eval(input())) x = int(eval(input())) y = int(eval(input())) if n <= k: ans = n * x else: ans = k * x + (n - k) * y print(ans)
false
9.090909
[ "-n, k, x, y = [int(eval(input())) for i in range(4)]", "-sum = 0", "-for t in range(1, n + 1):", "- if t <= k:", "- sum += x", "- else:", "- sum += y", "-print(sum)", "+n = int(eval(input()))", "+k = int(eval(input()))", "+x = int(eval(input()))", "+y = int(eval(input()))", "+if n <= k:", "+ ans = n * x", "+else:", "+ ans = k * x + (n - k) * y", "+print(ans)" ]
false
0.041441
0.040107
1.033246
[ "s001310706", "s599430053" ]
u350093546
p03835
python
s138765924
s274634390
260
86
40,940
67,228
Accepted
Accepted
66.92
cnt=0 k,s=list(map(int,input().split())) for i in range(k+1): for j in range(k+1): if 0<=s-i-j<=k: cnt+=1 print(cnt)
k,s=list(map(int,input().split())) ans=0 for i in range(k+1): for j in range(k+1): if 0<=s-i-j<=k: ans+=1 print(ans)
7
9
145
144
cnt = 0 k, s = list(map(int, input().split())) for i in range(k + 1): for j in range(k + 1): if 0 <= s - i - j <= k: cnt += 1 print(cnt)
k, s = list(map(int, input().split())) ans = 0 for i in range(k + 1): for j in range(k + 1): if 0 <= s - i - j <= k: ans += 1 print(ans)
false
22.222222
[ "-cnt = 0", "+ans = 0", "- cnt += 1", "-print(cnt)", "+ ans += 1", "+print(ans)" ]
false
0.036731
0.043911
0.836507
[ "s138765924", "s274634390" ]
u115838990
p02612
python
s512597754
s871035369
31
25
9,136
9,080
Accepted
Accepted
19.35
n = int(eval(input())) r = n % 1000 x = 0 if r == 0 else 1000-r print(x)
print((-int(eval(input()))%1000))
4
1
69
25
n = int(eval(input())) r = n % 1000 x = 0 if r == 0 else 1000 - r print(x)
print((-int(eval(input())) % 1000))
false
75
[ "-n = int(eval(input()))", "-r = n % 1000", "-x = 0 if r == 0 else 1000 - r", "-print(x)", "+print((-int(eval(input())) % 1000))" ]
false
0.042998
0.1043
0.412252
[ "s512597754", "s871035369" ]
u999854911
p01719
python
s906223149
s278407269
440
360
12,352
9,072
Accepted
Accepted
18.18
import sys def calc(x, n, p1, p2): dp = [] for i in range(n): dp.append( [0] * (x + 1) ) pocket = x for i in range(n): for j in range(x + 1): dp[i][j] = dp[i - 1][j] if j - p1[i] >= 0: dp[i][j] = max(dp[i][j], dp[i][j - p1[i]] + p2[i]) pocket = max(pocket, (x - j) + dp[i][j]) return pocket def main(): n,d,x = list(map(int, sys.stdin.readline().split())) pp = [] for i in range(d): pp.append( list(map(int,sys.stdin.readline().split())) ) curr_x = x for i in range(d - 1): curr_x = calc(curr_x, n, pp[i], pp[i + 1]) print(curr_x) if __name__ == '__main__': main()
import sys def main(): n,d,x = list(map(int, sys.stdin.readline().split())) pp = [] for i in range(d): pp.append( list(map(int,sys.stdin.readline().split())) ) dp = [0] * 100001 curr_x = x for k in range(d - 1): next_x = curr_x for i in range(curr_x + 1): dp[i] = 0 for i in range(n): for j in range(curr_x + 1): if j - pp[k][i] >= 0: dp[j] = max(dp[j], dp[j - pp[k][i]] + pp[k + 1][i]) next_x = max(next_x, (curr_x - j) + dp[j]) curr_x = next_x print(curr_x) if __name__ == '__main__': main()
32
26
729
665
import sys def calc(x, n, p1, p2): dp = [] for i in range(n): dp.append([0] * (x + 1)) pocket = x for i in range(n): for j in range(x + 1): dp[i][j] = dp[i - 1][j] if j - p1[i] >= 0: dp[i][j] = max(dp[i][j], dp[i][j - p1[i]] + p2[i]) pocket = max(pocket, (x - j) + dp[i][j]) return pocket def main(): n, d, x = list(map(int, sys.stdin.readline().split())) pp = [] for i in range(d): pp.append(list(map(int, sys.stdin.readline().split()))) curr_x = x for i in range(d - 1): curr_x = calc(curr_x, n, pp[i], pp[i + 1]) print(curr_x) if __name__ == "__main__": main()
import sys def main(): n, d, x = list(map(int, sys.stdin.readline().split())) pp = [] for i in range(d): pp.append(list(map(int, sys.stdin.readline().split()))) dp = [0] * 100001 curr_x = x for k in range(d - 1): next_x = curr_x for i in range(curr_x + 1): dp[i] = 0 for i in range(n): for j in range(curr_x + 1): if j - pp[k][i] >= 0: dp[j] = max(dp[j], dp[j - pp[k][i]] + pp[k + 1][i]) next_x = max(next_x, (curr_x - j) + dp[j]) curr_x = next_x print(curr_x) if __name__ == "__main__": main()
false
18.75
[ "-", "-", "-def calc(x, n, p1, p2):", "- dp = []", "- for i in range(n):", "- dp.append([0] * (x + 1))", "- pocket = x", "- for i in range(n):", "- for j in range(x + 1):", "- dp[i][j] = dp[i - 1][j]", "- if j - p1[i] >= 0:", "- dp[i][j] = max(dp[i][j], dp[i][j - p1[i]] + p2[i])", "- pocket = max(pocket, (x - j) + dp[i][j])", "- return pocket", "+ dp = [0] * 100001", "- for i in range(d - 1):", "- curr_x = calc(curr_x, n, pp[i], pp[i + 1])", "+ for k in range(d - 1):", "+ next_x = curr_x", "+ for i in range(curr_x + 1):", "+ dp[i] = 0", "+ for i in range(n):", "+ for j in range(curr_x + 1):", "+ if j - pp[k][i] >= 0:", "+ dp[j] = max(dp[j], dp[j - pp[k][i]] + pp[k + 1][i])", "+ next_x = max(next_x, (curr_x - j) + dp[j])", "+ curr_x = next_x" ]
false
0.037006
0.036638
1.010031
[ "s906223149", "s278407269" ]
u919633157
p03821
python
s310055234
s263412002
359
192
16,720
16,596
Accepted
Accepted
46.52
# https://atcoder.jp/contests/agc009/tasks/agc009_a n=int(eval(input())) ab=[tuple(map(int,input().split())) for _ in range(n)] ans=0 for a,b in reversed(ab): a+=ans res=a%b if res: ans+=b-res print(ans)
# https://atcoder.jp/contests/agc009/tasks/agc009_a import sys input=sys.stdin.readline n=int(eval(input())) ab=[tuple(map(int,input().split())) for _ in range(n)] ans=0 for a,b in reversed(ab): a+=ans res=a%b if res: ans+=b-res print(ans)
12
15
230
270
# https://atcoder.jp/contests/agc009/tasks/agc009_a n = int(eval(input())) ab = [tuple(map(int, input().split())) for _ in range(n)] ans = 0 for a, b in reversed(ab): a += ans res = a % b if res: ans += b - res print(ans)
# https://atcoder.jp/contests/agc009/tasks/agc009_a import sys input = sys.stdin.readline n = int(eval(input())) ab = [tuple(map(int, input().split())) for _ in range(n)] ans = 0 for a, b in reversed(ab): a += ans res = a % b if res: ans += b - res print(ans)
false
20
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.07334
0.037663
1.94727
[ "s310055234", "s263412002" ]
u796942881
p03739
python
s725466788
s384165740
95
79
14,084
14,084
Accepted
Accepted
16.84
def f(flg, an): accum = 0 ret = 0 for i, ai in enumerate(an): accum += ai if i % 2: if flg and 0 <= accum: ret += accum + 1 accum = -1 elif not flg and accum <= 0: ret += -accum + 1 accum = 1 else: if flg and accum <= 0: ret += -accum + 1 accum = 1 elif not flg and 0 <= accum: ret += accum + 1 accum = -1 return ret def main(): n, *an = list(map(int, open(0).read().split())) print((min(f(0, an), f(1, an)))) return main()
def f(flg, an): accum = 0 ret = 0 for i, ai in enumerate(an): accum += ai if flg: flg = False if accum <= 0: ret += -accum + 1 accum = 1 else: flg = True if 0 <= accum: ret += accum + 1 accum = -1 return ret def main(): n, *an = list(map(int, open(0).read().split())) print((min(f(False, an), f(True, an)))) return main()
30
25
678
506
def f(flg, an): accum = 0 ret = 0 for i, ai in enumerate(an): accum += ai if i % 2: if flg and 0 <= accum: ret += accum + 1 accum = -1 elif not flg and accum <= 0: ret += -accum + 1 accum = 1 else: if flg and accum <= 0: ret += -accum + 1 accum = 1 elif not flg and 0 <= accum: ret += accum + 1 accum = -1 return ret def main(): n, *an = list(map(int, open(0).read().split())) print((min(f(0, an), f(1, an)))) return main()
def f(flg, an): accum = 0 ret = 0 for i, ai in enumerate(an): accum += ai if flg: flg = False if accum <= 0: ret += -accum + 1 accum = 1 else: flg = True if 0 <= accum: ret += accum + 1 accum = -1 return ret def main(): n, *an = list(map(int, open(0).read().split())) print((min(f(False, an), f(True, an)))) return main()
false
16.666667
[ "- if i % 2:", "- if flg and 0 <= accum:", "- ret += accum + 1", "- accum = -1", "- elif not flg and accum <= 0:", "+ if flg:", "+ flg = False", "+ if accum <= 0:", "- if flg and accum <= 0:", "- ret += -accum + 1", "- accum = 1", "- elif not flg and 0 <= accum:", "+ flg = True", "+ if 0 <= accum:", "- print((min(f(0, an), f(1, an))))", "+ print((min(f(False, an), f(True, an))))" ]
false
0.063283
0.036629
1.727661
[ "s725466788", "s384165740" ]
u968166680
p03816
python
s718999395
s156684938
65
54
22,264
20,548
Accepted
Accepted
16.92
import sys from collections import Counter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) counter = Counter(A) odd = even = 0 for v in list(counter.values()): if v % 2 == 0: even += 1 else: odd += 1 if even % 2 == 0: ans = odd + even else: ans = odd + even - 1 print(ans) return if __name__ == '__main__': main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) K = len(set(A)) if K % 2 == 1: ans = K else: ans = K - 1 print(ans) return if __name__ == '__main__': main()
34
25
585
386
import sys from collections import Counter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) counter = Counter(A) odd = even = 0 for v in list(counter.values()): if v % 2 == 0: even += 1 else: odd += 1 if even % 2 == 0: ans = odd + even else: ans = odd + even - 1 print(ans) return if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) K = len(set(A)) if K % 2 == 1: ans = K else: ans = K - 1 print(ans) return if __name__ == "__main__": main()
false
26.470588
[ "-from collections import Counter", "- counter = Counter(A)", "- odd = even = 0", "- for v in list(counter.values()):", "- if v % 2 == 0:", "- even += 1", "- else:", "- odd += 1", "- if even % 2 == 0:", "- ans = odd + even", "+ K = len(set(A))", "+ if K % 2 == 1:", "+ ans = K", "- ans = odd + even - 1", "+ ans = K - 1" ]
false
0.06036
0.058501
1.031787
[ "s718999395", "s156684938" ]
u815763296
p02754
python
s603455700
s645777572
34
27
9,060
9,064
Accepted
Accepted
20.59
import math N, A, B = list(map(int, input().split())) x = math.floor(N/(A+B)) ans = x*A N = N-(A+B)*x if N > A: ans = ans+A else: ans = ans+N print(ans)
def LI(): return list(map(int, input().split())) N, A, B = LI() x = N//(A+B) y = N-A*x-B*x if y >= A: ans = (x+1)*A else: ans = x*A+y print(ans)
10
12
164
170
import math N, A, B = list(map(int, input().split())) x = math.floor(N / (A + B)) ans = x * A N = N - (A + B) * x if N > A: ans = ans + A else: ans = ans + N print(ans)
def LI(): return list(map(int, input().split())) N, A, B = LI() x = N // (A + B) y = N - A * x - B * x if y >= A: ans = (x + 1) * A else: ans = x * A + y print(ans)
false
16.666667
[ "-import math", "+def LI():", "+ return list(map(int, input().split()))", "-N, A, B = list(map(int, input().split()))", "-x = math.floor(N / (A + B))", "-ans = x * A", "-N = N - (A + B) * x", "-if N > A:", "- ans = ans + A", "+", "+N, A, B = LI()", "+x = N // (A + B)", "+y = N - A * x - B * x", "+if y >= A:", "+ ans = (x + 1) * A", "- ans = ans + N", "+ ans = x * A + y" ]
false
0.041013
0.04504
0.910592
[ "s603455700", "s645777572" ]
u119148115
p03043
python
s345670987
s809946013
84
64
65,260
65,248
Accepted
Accepted
23.81
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N,K = MI() ans = 0 if N >= K: ans += (N-K+1)/N for i in range(1,min(K-1,N)+1): a = i r = 0 while a <= K-1: a *= 2 r += 1 ans += 1/(N*2**r) print(ans)
import sys def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,K = MI() ans = 0 for i in range(1,N+1): r = 0 while i <= K-1: i *= 2 r += 1 ans += 1/(N*2**r) print(ans)
25
14
691
226
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり def LI2(): return list(map(int, sys.stdin.readline().rstrip())) # 空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) # 空白あり def LS2(): return list(sys.stdin.readline().rstrip()) # 空白なし N, K = MI() ans = 0 if N >= K: ans += (N - K + 1) / N for i in range(1, min(K - 1, N) + 1): a = i r = 0 while a <= K - 1: a *= 2 r += 1 ans += 1 / (N * 2**r) print(ans)
import sys def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) N, K = MI() ans = 0 for i in range(1, N + 1): r = 0 while i <= K - 1: i *= 2 r += 1 ans += 1 / (N * 2**r) print(ans)
false
44
[ "-", "-sys.setrecursionlimit(10**7)", "-", "-", "-def I():", "- return int(sys.stdin.readline().rstrip())", "-def LI():", "- return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり", "-", "-", "-def LI2():", "- return list(map(int, sys.stdin.readline().rstrip())) # 空白なし", "-", "-", "-def S():", "- return sys.stdin.readline().rstrip()", "-", "-", "-def LS():", "- return list(sys.stdin.readline().rstrip().split()) # 空白あり", "-", "-", "-def LS2():", "- return list(sys.stdin.readline().rstrip()) # 空白なし", "-", "-", "-if N >= K:", "- ans += (N - K + 1) / N", "-for i in range(1, min(K - 1, N) + 1):", "- a = i", "+for i in range(1, N + 1):", "- while a <= K - 1:", "- a *= 2", "+ while i <= K - 1:", "+ i *= 2" ]
false
0.065366
0.147537
0.443046
[ "s345670987", "s809946013" ]
u046187684
p02814
python
s701945041
s903116645
159
142
17,132
15,612
Accepted
Accepted
10.69
from fractions import gcd def lcm(a, b): return a * b // gcd(a, b) def solve(string): n, m, *a = list(map(int, string.split())) c = 2**len(bin(a[0]).split("1")[-1]) l = a[0] for _a in a: if _a % c or not _a // c % 2: return "0" l = lcm(l, _a) return str(max((m - l // 2) // l + 1, 0)) if __name__ == '__main__': import sys print((solve(sys.stdin.read().strip())))
from functools import reduce def lcm(a, b): ab = a * b while b != 0: a, b = b, a % b return ab // a def solve(string): n, m, *a = list(map(int, string.split())) c = 2**len(bin(a[0]).split("1")[-1]) l = reduce(lcm, (2 * m + 2 if _a % c or not _a // c % 2 else _a for _a in a)) return str(max((m - l // 2) // l + 1, 0)) if __name__ == '__main__': import sys print((solve(sys.stdin.read().strip())))
21
20
442
458
from fractions import gcd def lcm(a, b): return a * b // gcd(a, b) def solve(string): n, m, *a = list(map(int, string.split())) c = 2 ** len(bin(a[0]).split("1")[-1]) l = a[0] for _a in a: if _a % c or not _a // c % 2: return "0" l = lcm(l, _a) return str(max((m - l // 2) // l + 1, 0)) if __name__ == "__main__": import sys print((solve(sys.stdin.read().strip())))
from functools import reduce def lcm(a, b): ab = a * b while b != 0: a, b = b, a % b return ab // a def solve(string): n, m, *a = list(map(int, string.split())) c = 2 ** len(bin(a[0]).split("1")[-1]) l = reduce(lcm, (2 * m + 2 if _a % c or not _a // c % 2 else _a for _a in a)) return str(max((m - l // 2) // l + 1, 0)) if __name__ == "__main__": import sys print((solve(sys.stdin.read().strip())))
false
4.761905
[ "-from fractions import gcd", "+from functools import reduce", "- return a * b // gcd(a, b)", "+ ab = a * b", "+ while b != 0:", "+ a, b = b, a % b", "+ return ab // a", "- l = a[0]", "- for _a in a:", "- if _a % c or not _a // c % 2:", "- return \"0\"", "- l = lcm(l, _a)", "+ l = reduce(lcm, (2 * m + 2 if _a % c or not _a // c % 2 else _a for _a in a))" ]
false
0.107997
0.037203
2.902882
[ "s701945041", "s903116645" ]
u758815106
p03168
python
s759770561
s935474530
1,698
218
222,552
204,152
Accepted
Accepted
87.16
import sys input = sys.stdin.readline #import math #import numpy as np N = int(eval(input())) #= input() #= map(int, input().split()) p = list(map(float, input().split())) #= [input(), input()] #= [list(map(int, input().split())) for _ in range(N)] #= {i:[] for i in range(N)} dp = [[0.0] * (N + 1) for _ in range(N + 1)] dp[0][0] = 1 for i, p in enumerate(p, 1): pp = 1 - p dpi = dp[i - 1] for j in range(i + 1): if j == 0: dp[i][j] = dpi[j] * pp elif j == i: dp[i][j] = dpi[j - 1] * p else: dp[i][j] = dpi[j - 1] * p + dpi[j] * pp res = 0.0 n = N // 2 + 1 for cnt in dp[-1][n:]: res += cnt print(res)
#!/usr/bin/env python3 #import #import math #import numpy as np N = int(eval(input())) P = list(map(float, input().split())) # dp[i][j] : i枚投げてj枚表が出る確率 dp = [[0] * (N + 1) for _ in range(N + 1)] dp[0][0] = 1 for i, p in enumerate(P, 1): for j in range(i + 1): if j == 0: dp[i][j] = dp[i - 1][j] * (1 - p) elif j == i: dp[i][j] = dp[i - 1][j - 1] * p else: dp[i][j] = dp[i - 1][j] * (1 - p) + dp[i - 1][j - 1] * p ans = 0 for i in range(N // 2 + 1, N + 1): ans += dp[-1][i] print(ans)
35
26
718
575
import sys input = sys.stdin.readline # import math # import numpy as np N = int(eval(input())) # = input() # = map(int, input().split()) p = list(map(float, input().split())) # = [input(), input()] # = [list(map(int, input().split())) for _ in range(N)] # = {i:[] for i in range(N)} dp = [[0.0] * (N + 1) for _ in range(N + 1)] dp[0][0] = 1 for i, p in enumerate(p, 1): pp = 1 - p dpi = dp[i - 1] for j in range(i + 1): if j == 0: dp[i][j] = dpi[j] * pp elif j == i: dp[i][j] = dpi[j - 1] * p else: dp[i][j] = dpi[j - 1] * p + dpi[j] * pp res = 0.0 n = N // 2 + 1 for cnt in dp[-1][n:]: res += cnt print(res)
#!/usr/bin/env python3 # import # import math # import numpy as np N = int(eval(input())) P = list(map(float, input().split())) # dp[i][j] : i枚投げてj枚表が出る確率 dp = [[0] * (N + 1) for _ in range(N + 1)] dp[0][0] = 1 for i, p in enumerate(P, 1): for j in range(i + 1): if j == 0: dp[i][j] = dp[i - 1][j] * (1 - p) elif j == i: dp[i][j] = dp[i - 1][j - 1] * p else: dp[i][j] = dp[i - 1][j] * (1 - p) + dp[i - 1][j - 1] * p ans = 0 for i in range(N // 2 + 1, N + 1): ans += dp[-1][i] print(ans)
false
25.714286
[ "-import sys", "-", "-input = sys.stdin.readline", "+#!/usr/bin/env python3", "+# import", "-# = input()", "-# = map(int, input().split())", "-p = list(map(float, input().split()))", "-# = [input(), input()]", "-# = [list(map(int, input().split())) for _ in range(N)]", "-# = {i:[] for i in range(N)}", "-dp = [[0.0] * (N + 1) for _ in range(N + 1)]", "+P = list(map(float, input().split()))", "+# dp[i][j] : i枚投げてj枚表が出る確率", "+dp = [[0] * (N + 1) for _ in range(N + 1)]", "-for i, p in enumerate(p, 1):", "- pp = 1 - p", "- dpi = dp[i - 1]", "+for i, p in enumerate(P, 1):", "- dp[i][j] = dpi[j] * pp", "+ dp[i][j] = dp[i - 1][j] * (1 - p)", "- dp[i][j] = dpi[j - 1] * p", "+ dp[i][j] = dp[i - 1][j - 1] * p", "- dp[i][j] = dpi[j - 1] * p + dpi[j] * pp", "-res = 0.0", "-n = N // 2 + 1", "-for cnt in dp[-1][n:]:", "- res += cnt", "-print(res)", "+ dp[i][j] = dp[i - 1][j] * (1 - p) + dp[i - 1][j - 1] * p", "+ans = 0", "+for i in range(N // 2 + 1, N + 1):", "+ ans += dp[-1][i]", "+print(ans)" ]
false
0.149657
0.031758
4.712401
[ "s759770561", "s935474530" ]
u952708174
p02768
python
s146276566
s893137392
639
156
28,328
3,572
Accepted
Accepted
75.59
def d_bouquet(MOD=10**9 + 7): N, A, B = [int(i) for i in input().split()] from operator import mul from functools import reduce def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2, r + 1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p - 1, r, p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) result %= MOD return result ans = pow(2, N, MOD) - 1 ans -= cmb(N, A) ans -= cmb(N, B) return (ans + MOD) % MOD print((d_bouquet()))
from functools import reduce def d_bouquet(MOD=10**9 + 7): from functools import reduce N, A, B = [int(i) for i in input().split()] def comb(m, r): numerator = reduce(lambda x, y: x * y % MOD, list(range(m, m - r, -1))) denominator = reduce(lambda x, y: x * y % MOD, list(range(1, r + 1))) return (numerator * pow(denominator, MOD - 2, MOD)) % MOD return (pow(2, N, MOD) - 1 - (comb(N, A) + comb(N, B))) % MOD print((d_bouquet()))
36
12
961
441
def d_bouquet(MOD=10**9 + 7): N, A, B = [int(i) for i in input().split()] from operator import mul from functools import reduce def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2, r + 1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p - 1, r, p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) result %= MOD return result ans = pow(2, N, MOD) - 1 ans -= cmb(N, A) ans -= cmb(N, B) return (ans + MOD) % MOD print((d_bouquet()))
from functools import reduce def d_bouquet(MOD=10**9 + 7): from functools import reduce N, A, B = [int(i) for i in input().split()] def comb(m, r): numerator = reduce(lambda x, y: x * y % MOD, list(range(m, m - r, -1))) denominator = reduce(lambda x, y: x * y % MOD, list(range(1, r + 1))) return (numerator * pow(denominator, MOD - 2, MOD)) % MOD return (pow(2, N, MOD) - 1 - (comb(N, A) + comb(N, B))) % MOD print((d_bouquet()))
false
66.666667
[ "+from functools import reduce", "+", "+", "- N, A, B = [int(i) for i in input().split()]", "- from operator import mul", "- def cmb(n, r):", "- if n - r < r:", "- r = n - r", "- if r == 0:", "- return 1", "- if r == 1:", "- return n", "- numerator = [n - r + k + 1 for k in range(r)]", "- denominator = [k + 1 for k in range(r)]", "- for p in range(2, r + 1):", "- pivot = denominator[p - 1]", "- if pivot > 1:", "- offset = (n - r) % p", "- for k in range(p - 1, r, p):", "- numerator[k - offset] /= pivot", "- denominator[k] /= pivot", "- result = 1", "- for k in range(r):", "- if numerator[k] > 1:", "- result *= int(numerator[k])", "- result %= MOD", "- return result", "+ N, A, B = [int(i) for i in input().split()]", "- ans = pow(2, N, MOD) - 1", "- ans -= cmb(N, A)", "- ans -= cmb(N, B)", "- return (ans + MOD) % MOD", "+ def comb(m, r):", "+ numerator = reduce(lambda x, y: x * y % MOD, list(range(m, m - r, -1)))", "+ denominator = reduce(lambda x, y: x * y % MOD, list(range(1, r + 1)))", "+ return (numerator * pow(denominator, MOD - 2, MOD)) % MOD", "+", "+ return (pow(2, N, MOD) - 1 - (comb(N, A) + comb(N, B))) % MOD" ]
false
0.314505
0.091867
3.423472
[ "s146276566", "s893137392" ]
u254871849
p03076
python
s891740442
s383141751
149
17
12,548
3,060
Accepted
Accepted
88.59
import sys import math import numpy as np def main(): dish = np.array(sys.stdin.read().split()) minute = [int(dish[i][-1]) for i in range(5)] m = min(x for x in minute if x > 0) if minute.count(0) != 5 else 10 res = (np.ceil(dish.astype(np.int64) / 10) * 10).sum() - 10 + m print((int(res))) if __name__ == "__main__": main()
import sys *T, = list(map(int ,sys.stdin.read().split())) def main(): res = 0 e = 10 for t in T: res += 10 * ((t + 10 - 1) // 10) e = min(e, (t - 1) % 10 + 1) res -= (10 - e) return res if __name__ == '__main__': ans = main() print(ans)
16
17
368
294
import sys import math import numpy as np def main(): dish = np.array(sys.stdin.read().split()) minute = [int(dish[i][-1]) for i in range(5)] m = min(x for x in minute if x > 0) if minute.count(0) != 5 else 10 res = (np.ceil(dish.astype(np.int64) / 10) * 10).sum() - 10 + m print((int(res))) if __name__ == "__main__": main()
import sys (*T,) = list(map(int, sys.stdin.read().split())) def main(): res = 0 e = 10 for t in T: res += 10 * ((t + 10 - 1) // 10) e = min(e, (t - 1) % 10 + 1) res -= 10 - e return res if __name__ == "__main__": ans = main() print(ans)
false
5.882353
[ "-import math", "-import numpy as np", "+", "+(*T,) = list(map(int, sys.stdin.read().split()))", "- dish = np.array(sys.stdin.read().split())", "- minute = [int(dish[i][-1]) for i in range(5)]", "- m = min(x for x in minute if x > 0) if minute.count(0) != 5 else 10", "- res = (np.ceil(dish.astype(np.int64) / 10) * 10).sum() - 10 + m", "- print((int(res)))", "+ res = 0", "+ e = 10", "+ for t in T:", "+ res += 10 * ((t + 10 - 1) // 10)", "+ e = min(e, (t - 1) % 10 + 1)", "+ res -= 10 - e", "+ return res", "- main()", "+ ans = main()", "+ print(ans)" ]
false
0.1995
0.03545
5.6277
[ "s891740442", "s383141751" ]
u241159583
p03633
python
s261799473
s386157259
37
30
5,076
9,196
Accepted
Accepted
18.92
from fractions import gcd from functools import reduce n = int(eval(input())) t = list(int(eval(input())) for _ in range(n)) def lcm_base(x, y): return (x * y) // gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) print((lcm_list(t)))
import math n = int(eval(input())) t = [int(eval(input())) for _ in range(n)] if n == 1: print((t[0])) exit() a = t[0]*t[1]//math.gcd(t[0],t[1]) for i in range(2, n): a = t[i]*a//math.gcd(t[i],a) print(a)
13
10
262
211
from fractions import gcd from functools import reduce n = int(eval(input())) t = list(int(eval(input())) for _ in range(n)) def lcm_base(x, y): return (x * y) // gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) print((lcm_list(t)))
import math n = int(eval(input())) t = [int(eval(input())) for _ in range(n)] if n == 1: print((t[0])) exit() a = t[0] * t[1] // math.gcd(t[0], t[1]) for i in range(2, n): a = t[i] * a // math.gcd(t[i], a) print(a)
false
23.076923
[ "-from fractions import gcd", "-from functools import reduce", "+import math", "-t = list(int(eval(input())) for _ in range(n))", "-", "-", "-def lcm_base(x, y):", "- return (x * y) // gcd(x, y)", "-", "-", "-def lcm_list(numbers):", "- return reduce(lcm_base, numbers, 1)", "-", "-", "-print((lcm_list(t)))", "+t = [int(eval(input())) for _ in range(n)]", "+if n == 1:", "+ print((t[0]))", "+ exit()", "+a = t[0] * t[1] // math.gcd(t[0], t[1])", "+for i in range(2, n):", "+ a = t[i] * a // math.gcd(t[i], a)", "+print(a)" ]
false
0.048427
0.040295
1.201813
[ "s261799473", "s386157259" ]
u038408819
p03436
python
s615331342
s405234783
38
25
3,316
3,316
Accepted
Accepted
34.21
from collections import deque def bfs(): flag = False d = [[float('inf')] * W for i in range(H)] dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] que = deque([]) que.append((0, 0)) d[0][0] = 0 while que: p = que.popleft() if p[0]==H-1 and p[1]==W-1: flag = True break for i in range(4): nx = p[1] + dx[i] ny = p[0] + dy[i] if 0<=nx<W and 0<=ny<H and maze[ny][nx]!='#' and d[ny][nx]==float("inf"): que.append((ny, nx)) d[ny][nx] = d[p[0]][p[1]] + 1 if flag==False: return False return d[H-1][W-1] def notcount(H, W, maze): cnt = 0 for i in range(H): for j in range(W): if maze[i][j]=='#': cnt += 1 return cnt H, W = list(map(int, input().split())) maze = [list(eval(input())) for i in range(H)] if bfs()==False: print((-1)) else: s = (H * W - notcount(H, W, maze)) - (bfs() + 1) #bfs() print(s)
h, w = list(map(int, input().split())) maze = [list(eval(input())) for _ in range(h)] from collections import deque def bfs(maze, sy, sx, gy, gx): d = [[-1] * w for _ in range(h)] que = deque([[sy, sx]]) #print(que) d[sy][sx] = 0 while que: y, x = que.popleft() if y == gy and x == gx: break for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]): ny, nx = y + j, x + k if 0 <= nx < w and 0 <= ny < h and d[ny][nx] == -1 and maze[ny][nx] != "#": d[ny][nx] = d[y][x] + 1 que.append([ny, nx]) return d gx, gy = w - 1, h - 1 def counting(maze, h, w, aim): cnt = 0 for i in range(h): for j in range(w): if maze[i][j] == aim: cnt += 1 return cnt a = bfs(maze, 0, 0, gy, gx) if a[gy][gx] == -1: print((-1)) else: print((h * w - (counting(maze, h, w, '#') + (a[gy][gx] + 1))))
49
32
1,056
968
from collections import deque def bfs(): flag = False d = [[float("inf")] * W for i in range(H)] dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] que = deque([]) que.append((0, 0)) d[0][0] = 0 while que: p = que.popleft() if p[0] == H - 1 and p[1] == W - 1: flag = True break for i in range(4): nx = p[1] + dx[i] ny = p[0] + dy[i] if ( 0 <= nx < W and 0 <= ny < H and maze[ny][nx] != "#" and d[ny][nx] == float("inf") ): que.append((ny, nx)) d[ny][nx] = d[p[0]][p[1]] + 1 if flag == False: return False return d[H - 1][W - 1] def notcount(H, W, maze): cnt = 0 for i in range(H): for j in range(W): if maze[i][j] == "#": cnt += 1 return cnt H, W = list(map(int, input().split())) maze = [list(eval(input())) for i in range(H)] if bfs() == False: print((-1)) else: s = (H * W - notcount(H, W, maze)) - (bfs() + 1) # bfs() print(s)
h, w = list(map(int, input().split())) maze = [list(eval(input())) for _ in range(h)] from collections import deque def bfs(maze, sy, sx, gy, gx): d = [[-1] * w for _ in range(h)] que = deque([[sy, sx]]) # print(que) d[sy][sx] = 0 while que: y, x = que.popleft() if y == gy and x == gx: break for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]): ny, nx = y + j, x + k if 0 <= nx < w and 0 <= ny < h and d[ny][nx] == -1 and maze[ny][nx] != "#": d[ny][nx] = d[y][x] + 1 que.append([ny, nx]) return d gx, gy = w - 1, h - 1 def counting(maze, h, w, aim): cnt = 0 for i in range(h): for j in range(w): if maze[i][j] == aim: cnt += 1 return cnt a = bfs(maze, 0, 0, gy, gx) if a[gy][gx] == -1: print((-1)) else: print((h * w - (counting(maze, h, w, "#") + (a[gy][gx] + 1))))
false
34.693878
[ "+h, w = list(map(int, input().split()))", "+maze = [list(eval(input())) for _ in range(h)]", "-def bfs():", "- flag = False", "- d = [[float(\"inf\")] * W for i in range(H)]", "- dx = [1, 0, -1, 0]", "- dy = [0, 1, 0, -1]", "- que = deque([])", "- que.append((0, 0))", "- d[0][0] = 0", "+def bfs(maze, sy, sx, gy, gx):", "+ d = [[-1] * w for _ in range(h)]", "+ que = deque([[sy, sx]])", "+ # print(que)", "+ d[sy][sx] = 0", "- p = que.popleft()", "- if p[0] == H - 1 and p[1] == W - 1:", "- flag = True", "+ y, x = que.popleft()", "+ if y == gy and x == gx:", "- for i in range(4):", "- nx = p[1] + dx[i]", "- ny = p[0] + dy[i]", "- if (", "- 0 <= nx < W", "- and 0 <= ny < H", "- and maze[ny][nx] != \"#\"", "- and d[ny][nx] == float(\"inf\")", "- ):", "- que.append((ny, nx))", "- d[ny][nx] = d[p[0]][p[1]] + 1", "- if flag == False:", "- return False", "- return d[H - 1][W - 1]", "+ for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):", "+ ny, nx = y + j, x + k", "+ if 0 <= nx < w and 0 <= ny < h and d[ny][nx] == -1 and maze[ny][nx] != \"#\":", "+ d[ny][nx] = d[y][x] + 1", "+ que.append([ny, nx])", "+ return d", "-def notcount(H, W, maze):", "+gx, gy = w - 1, h - 1", "+", "+", "+def counting(maze, h, w, aim):", "- for i in range(H):", "- for j in range(W):", "- if maze[i][j] == \"#\":", "+ for i in range(h):", "+ for j in range(w):", "+ if maze[i][j] == aim:", "-H, W = list(map(int, input().split()))", "-maze = [list(eval(input())) for i in range(H)]", "-if bfs() == False:", "+a = bfs(maze, 0, 0, gy, gx)", "+if a[gy][gx] == -1:", "- s = (H * W - notcount(H, W, maze)) - (bfs() + 1)", "- # bfs()", "- print(s)", "+ print((h * w - (counting(maze, h, w, \"#\") + (a[gy][gx] + 1))))" ]
false
0.040276
0.038645
1.042205
[ "s615331342", "s405234783" ]
u079022693
p03078
python
s728399262
s315834914
998
37
136,812
4,968
Accepted
Accepted
96.29
from sys import stdin def main(): #入力 readline=stdin.readline x,y,z,k=list(map(int,readline().split())) a=list(map(int,readline().split())) b=list(map(int,readline().split())) c=list(map(int,readline().split())) d=list() for i in range(x): for j in range(y): d.append(a[i]+b[j]) d.sort(reverse=True) if x*y>=k: d=d[:k] e=list() for i in range(len(d)): for j in range(z): e.append(d[i]+c[j]) e.sort(reverse=True) for i in range(k): print((e[i])) if __name__=="__main__": main()
from sys import stdin import heapq def main(): #入力 readline=stdin.readline x,y,z,k=list(map(int,readline().split())) a=list(map(int,readline().split())) a.sort(reverse=True) b=list(map(int,readline().split())) b.sort(reverse=True) c=list(map(int,readline().split())) c.sort(reverse=True) s={(0,0,0)} h=[[-(a[0]+b[0]+c[0]),(0,0,0)]] heapq.heapify(h) for _ in range(k): li=heapq.heappop(h) n=-li[0] co=li[1] print(n) if co[0]+1<x: co_1=(co[0]+1,co[1],co[2]) n_1=a[co_1[0]]+b[co_1[1]]+c[co_1[2]] n_1=-n_1 if co_1 not in s: heapq.heappush(h,[n_1,co_1]) s.add(co_1) if co[1]+1<y: co_2=(co[0],co[1]+1,co[2]) n_2=a[co_2[0]]+b[co_2[1]]+c[co_2[2]] n_2=-n_2 if co_2 not in s: heapq.heappush(h,[n_2,co_2]) s.add(co_2) if co[2]+1<z: co_3=(co[0],co[1],co[2]+1) n_3=a[co_3[0]]+b[co_3[1]]+c[co_3[2]] n_3=-n_3 if co_3 not in s: heapq.heappush(h,[n_3,co_3]) s.add(co_3) if __name__=="__main__": main()
29
48
617
1,282
from sys import stdin def main(): # 入力 readline = stdin.readline x, y, z, k = list(map(int, readline().split())) a = list(map(int, readline().split())) b = list(map(int, readline().split())) c = list(map(int, readline().split())) d = list() for i in range(x): for j in range(y): d.append(a[i] + b[j]) d.sort(reverse=True) if x * y >= k: d = d[:k] e = list() for i in range(len(d)): for j in range(z): e.append(d[i] + c[j]) e.sort(reverse=True) for i in range(k): print((e[i])) if __name__ == "__main__": main()
from sys import stdin import heapq def main(): # 入力 readline = stdin.readline x, y, z, k = list(map(int, readline().split())) a = list(map(int, readline().split())) a.sort(reverse=True) b = list(map(int, readline().split())) b.sort(reverse=True) c = list(map(int, readline().split())) c.sort(reverse=True) s = {(0, 0, 0)} h = [[-(a[0] + b[0] + c[0]), (0, 0, 0)]] heapq.heapify(h) for _ in range(k): li = heapq.heappop(h) n = -li[0] co = li[1] print(n) if co[0] + 1 < x: co_1 = (co[0] + 1, co[1], co[2]) n_1 = a[co_1[0]] + b[co_1[1]] + c[co_1[2]] n_1 = -n_1 if co_1 not in s: heapq.heappush(h, [n_1, co_1]) s.add(co_1) if co[1] + 1 < y: co_2 = (co[0], co[1] + 1, co[2]) n_2 = a[co_2[0]] + b[co_2[1]] + c[co_2[2]] n_2 = -n_2 if co_2 not in s: heapq.heappush(h, [n_2, co_2]) s.add(co_2) if co[2] + 1 < z: co_3 = (co[0], co[1], co[2] + 1) n_3 = a[co_3[0]] + b[co_3[1]] + c[co_3[2]] n_3 = -n_3 if co_3 not in s: heapq.heappush(h, [n_3, co_3]) s.add(co_3) if __name__ == "__main__": main()
false
39.583333
[ "+import heapq", "+ a.sort(reverse=True)", "+ b.sort(reverse=True)", "- d = list()", "- for i in range(x):", "- for j in range(y):", "- d.append(a[i] + b[j])", "- d.sort(reverse=True)", "- if x * y >= k:", "- d = d[:k]", "- e = list()", "- for i in range(len(d)):", "- for j in range(z):", "- e.append(d[i] + c[j])", "- e.sort(reverse=True)", "- for i in range(k):", "- print((e[i]))", "+ c.sort(reverse=True)", "+ s = {(0, 0, 0)}", "+ h = [[-(a[0] + b[0] + c[0]), (0, 0, 0)]]", "+ heapq.heapify(h)", "+ for _ in range(k):", "+ li = heapq.heappop(h)", "+ n = -li[0]", "+ co = li[1]", "+ print(n)", "+ if co[0] + 1 < x:", "+ co_1 = (co[0] + 1, co[1], co[2])", "+ n_1 = a[co_1[0]] + b[co_1[1]] + c[co_1[2]]", "+ n_1 = -n_1", "+ if co_1 not in s:", "+ heapq.heappush(h, [n_1, co_1])", "+ s.add(co_1)", "+ if co[1] + 1 < y:", "+ co_2 = (co[0], co[1] + 1, co[2])", "+ n_2 = a[co_2[0]] + b[co_2[1]] + c[co_2[2]]", "+ n_2 = -n_2", "+ if co_2 not in s:", "+ heapq.heappush(h, [n_2, co_2])", "+ s.add(co_2)", "+ if co[2] + 1 < z:", "+ co_3 = (co[0], co[1], co[2] + 1)", "+ n_3 = a[co_3[0]] + b[co_3[1]] + c[co_3[2]]", "+ n_3 = -n_3", "+ if co_3 not in s:", "+ heapq.heappush(h, [n_3, co_3])", "+ s.add(co_3)" ]
false
0.06754
0.03238
2.08584
[ "s728399262", "s315834914" ]
u183422236
p02621
python
s786278320
s070241343
84
22
61,412
9,144
Accepted
Accepted
73.81
a = int(eval(input())) print((a + a ** 2 + a ** 3))
#!/usr/bin/env pypy3 def main(): a = int(eval(input())) print((a + a ** 2 + a ** 3)) if __name__ == '__main__': main()
3
10
46
136
a = int(eval(input())) print((a + a**2 + a**3))
#!/usr/bin/env pypy3 def main(): a = int(eval(input())) print((a + a**2 + a**3)) if __name__ == "__main__": main()
false
70
[ "-a = int(eval(input()))", "-print((a + a**2 + a**3))", "+#!/usr/bin/env pypy3", "+def main():", "+ a = int(eval(input()))", "+ print((a + a**2 + a**3))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.040632
0.035721
1.137483
[ "s786278320", "s070241343" ]
u504836877
p03167
python
s953069366
s997631343
964
265
239,092
51,952
Accepted
Accepted
72.51
from collections import deque H,W = list(map(int, input().split())) L = [eval(input()) for _ in range(H)] dp = [[0]*W for _ in range(H)] dp[0][0] = 1 used = [[0]*W for _ in range(H)] q = deque() q.append((0, 0)) while q: t = q.popleft() i = t[0] j = t[1] used[i][j] = 2 if i != H-1 and L[i+1][j] == "." and used[i+1][j] < 2: dp[i+1][j] += dp[i][j] if used[i+1][j] == 0: q.append((i+1, j)) used[i+1][j] = 1 if j != W-1and L[i][j+1] == "." and used[i][j+1] < 2: dp[i][j+1] += dp[i][j] if used[i][j+1] == 0: q.append((i, j+1)) used[i][j+1] = 1 print((dp[H-1][W-1]%(10**9+7)))
H,W = list(map(int, input().split())) A = [eval(input()) for _ in range(H)] mod = 10**9+7 dp = [[0]*W for _ in range(H)] dp[0][0] = 1 for i in range(H): for j in range(W): if A[i][j] == "#": continue if i > 0: dp[i][j] += dp[i-1][j] if j > 0: dp[i][j] += dp[i][j-1] dp[i][j] %= mod print((dp[H-1][W-1]))
27
18
699
381
from collections import deque H, W = list(map(int, input().split())) L = [eval(input()) for _ in range(H)] dp = [[0] * W for _ in range(H)] dp[0][0] = 1 used = [[0] * W for _ in range(H)] q = deque() q.append((0, 0)) while q: t = q.popleft() i = t[0] j = t[1] used[i][j] = 2 if i != H - 1 and L[i + 1][j] == "." and used[i + 1][j] < 2: dp[i + 1][j] += dp[i][j] if used[i + 1][j] == 0: q.append((i + 1, j)) used[i + 1][j] = 1 if j != W - 1 and L[i][j + 1] == "." and used[i][j + 1] < 2: dp[i][j + 1] += dp[i][j] if used[i][j + 1] == 0: q.append((i, j + 1)) used[i][j + 1] = 1 print((dp[H - 1][W - 1] % (10**9 + 7)))
H, W = list(map(int, input().split())) A = [eval(input()) for _ in range(H)] mod = 10**9 + 7 dp = [[0] * W for _ in range(H)] dp[0][0] = 1 for i in range(H): for j in range(W): if A[i][j] == "#": continue if i > 0: dp[i][j] += dp[i - 1][j] if j > 0: dp[i][j] += dp[i][j - 1] dp[i][j] %= mod print((dp[H - 1][W - 1]))
false
33.333333
[ "-from collections import deque", "-", "-L = [eval(input()) for _ in range(H)]", "+A = [eval(input()) for _ in range(H)]", "+mod = 10**9 + 7", "-used = [[0] * W for _ in range(H)]", "-q = deque()", "-q.append((0, 0))", "-while q:", "- t = q.popleft()", "- i = t[0]", "- j = t[1]", "- used[i][j] = 2", "- if i != H - 1 and L[i + 1][j] == \".\" and used[i + 1][j] < 2:", "- dp[i + 1][j] += dp[i][j]", "- if used[i + 1][j] == 0:", "- q.append((i + 1, j))", "- used[i + 1][j] = 1", "- if j != W - 1 and L[i][j + 1] == \".\" and used[i][j + 1] < 2:", "- dp[i][j + 1] += dp[i][j]", "- if used[i][j + 1] == 0:", "- q.append((i, j + 1))", "- used[i][j + 1] = 1", "-print((dp[H - 1][W - 1] % (10**9 + 7)))", "+for i in range(H):", "+ for j in range(W):", "+ if A[i][j] == \"#\":", "+ continue", "+ if i > 0:", "+ dp[i][j] += dp[i - 1][j]", "+ if j > 0:", "+ dp[i][j] += dp[i][j - 1]", "+ dp[i][j] %= mod", "+print((dp[H - 1][W - 1]))" ]
false
0.046504
0.042541
1.09316
[ "s953069366", "s997631343" ]
u531631168
p03721
python
s994680850
s591564568
247
221
16,236
11,692
Accepted
Accepted
10.53
n, k = list(map(int, input().split())) ab = {} for _ in range(n): a, b = list(map(int, input().split())) ab.setdefault(a, 0) ab[a] += b keys = list(ab.keys()) keys.sort() i = 0 for key in keys: i += ab[key] if i >= k: print(key) break
n, k = list(map(int, input().split())) A_MAX = 10**5 bkt = [0 for _ in range(A_MAX+1)] for _ in range(n): a, b = list(map(int, input().split())) bkt[a] += b sum_count = 0 for i, cnt in enumerate(bkt): sum_count += cnt if sum_count >= k: print(i) break
14
12
271
282
n, k = list(map(int, input().split())) ab = {} for _ in range(n): a, b = list(map(int, input().split())) ab.setdefault(a, 0) ab[a] += b keys = list(ab.keys()) keys.sort() i = 0 for key in keys: i += ab[key] if i >= k: print(key) break
n, k = list(map(int, input().split())) A_MAX = 10**5 bkt = [0 for _ in range(A_MAX + 1)] for _ in range(n): a, b = list(map(int, input().split())) bkt[a] += b sum_count = 0 for i, cnt in enumerate(bkt): sum_count += cnt if sum_count >= k: print(i) break
false
14.285714
[ "-ab = {}", "+A_MAX = 10**5", "+bkt = [0 for _ in range(A_MAX + 1)]", "- ab.setdefault(a, 0)", "- ab[a] += b", "-keys = list(ab.keys())", "-keys.sort()", "-i = 0", "-for key in keys:", "- i += ab[key]", "- if i >= k:", "- print(key)", "+ bkt[a] += b", "+sum_count = 0", "+for i, cnt in enumerate(bkt):", "+ sum_count += cnt", "+ if sum_count >= k:", "+ print(i)" ]
false
0.068936
0.086587
0.796154
[ "s994680850", "s591564568" ]
u778700306
p03599
python
s372509476
s075393970
1,618
180
12,464
12,440
Accepted
Accepted
88.88
a,b,c,d,e,f = list(map(int, input().split())) waters = [] for i in range(f // (100 * a) + 1): for j in range(f // (100 * b) + 1): amount = 100 * (i * a + j * b) if amount <= f: waters.append(amount) sugers = [] for i in range(f // c + 1): for j in range(f // d + 1): amount = i * c + j * d if amount <= f: sugers.append(amount) maxp = -1.0 res_w = 0 res_s = 0 for w in waters: for s in sugers: if w + s > f or w + s == 0: continue capa = w // 100 * e if s > capa: continue p = 100 * s / (w + s) if maxp < p: maxp, res_w, res_s = p, w + s, s print(("%d %d" % (res_w, res_s)))
a,b,c,d,e,f = list(map(int, input().split())) waters = [] for i in range(f // (100 * a) + 1): for j in range(f // (100 * b) + 1): amount = 100 * (i * a + j * b) if amount <= f: waters.append(amount) sugers = [] for i in range(f // c + 1): for j in range(f // d + 1): amount = i * c + j * d if amount <= f: sugers.append(amount) waters = set(waters) sugers = set(sugers) maxp = -1.0 res_w = 0 res_s = 0 for w in waters: for s in sugers: if w + s > f or w + s == 0: continue capa = w // 100 * e if s > capa: continue p = 100 * s / (w + s) if maxp < p: maxp, res_w, res_s = p, w + s, s print(("%d %d" % (res_w, res_s)))
34
37
750
796
a, b, c, d, e, f = list(map(int, input().split())) waters = [] for i in range(f // (100 * a) + 1): for j in range(f // (100 * b) + 1): amount = 100 * (i * a + j * b) if amount <= f: waters.append(amount) sugers = [] for i in range(f // c + 1): for j in range(f // d + 1): amount = i * c + j * d if amount <= f: sugers.append(amount) maxp = -1.0 res_w = 0 res_s = 0 for w in waters: for s in sugers: if w + s > f or w + s == 0: continue capa = w // 100 * e if s > capa: continue p = 100 * s / (w + s) if maxp < p: maxp, res_w, res_s = p, w + s, s print(("%d %d" % (res_w, res_s)))
a, b, c, d, e, f = list(map(int, input().split())) waters = [] for i in range(f // (100 * a) + 1): for j in range(f // (100 * b) + 1): amount = 100 * (i * a + j * b) if amount <= f: waters.append(amount) sugers = [] for i in range(f // c + 1): for j in range(f // d + 1): amount = i * c + j * d if amount <= f: sugers.append(amount) waters = set(waters) sugers = set(sugers) maxp = -1.0 res_w = 0 res_s = 0 for w in waters: for s in sugers: if w + s > f or w + s == 0: continue capa = w // 100 * e if s > capa: continue p = 100 * s / (w + s) if maxp < p: maxp, res_w, res_s = p, w + s, s print(("%d %d" % (res_w, res_s)))
false
8.108108
[ "+waters = set(waters)", "+sugers = set(sugers)" ]
false
0.425462
0.065647
6.481105
[ "s372509476", "s075393970" ]
u835283937
p03231
python
s310432678
s602250876
72
31
19,572
9,400
Accepted
Accepted
56.94
import math def main4(): N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) L = (N * M) // math.gcd(N, M) pair = dict() for i in range(1, N + 1): idx = (i - 1) * (L // N) + 1 pair[idx] = S[i - 1] for i in range(1, M + 1): idx = (i - 1) * (L // M) + 1 if idx in list(pair.keys()): if pair[idx] != T[i - 1]: print((-1)) exit() print(L) if __name__ == "__main__": main4()
import math def main5(): N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) G = math.gcd(N, M) L = (N * M) // G for i in range(G): if S[i * N // G] != T[i * M // G]: print((-1)) exit() print(L) if __name__ == "__main__": main5()
26
18
510
317
import math def main4(): N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) L = (N * M) // math.gcd(N, M) pair = dict() for i in range(1, N + 1): idx = (i - 1) * (L // N) + 1 pair[idx] = S[i - 1] for i in range(1, M + 1): idx = (i - 1) * (L // M) + 1 if idx in list(pair.keys()): if pair[idx] != T[i - 1]: print((-1)) exit() print(L) if __name__ == "__main__": main4()
import math def main5(): N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) G = math.gcd(N, M) L = (N * M) // G for i in range(G): if S[i * N // G] != T[i * M // G]: print((-1)) exit() print(L) if __name__ == "__main__": main5()
false
30.769231
[ "-def main4():", "+def main5():", "- L = (N * M) // math.gcd(N, M)", "- pair = dict()", "- for i in range(1, N + 1):", "- idx = (i - 1) * (L // N) + 1", "- pair[idx] = S[i - 1]", "- for i in range(1, M + 1):", "- idx = (i - 1) * (L // M) + 1", "- if idx in list(pair.keys()):", "- if pair[idx] != T[i - 1]:", "- print((-1))", "- exit()", "+ G = math.gcd(N, M)", "+ L = (N * M) // G", "+ for i in range(G):", "+ if S[i * N // G] != T[i * M // G]:", "+ print((-1))", "+ exit()", "- main4()", "+ main5()" ]
false
0.134059
0.041598
3.222758
[ "s310432678", "s602250876" ]
u747602774
p02918
python
s683768054
s238086931
93
42
4,084
3,316
Accepted
Accepted
54.84
N,K = list(map(int,input().split())) S = list(eval(input())) ch = 0 ans = 0 if N != 1: for i in range(N): if i == 0: if S[i] != S[i+1]: ch += 1 if S[i] == S[i+1] == 'R': ans += 1 elif i == N-1: if S[i] == S[i-1] == 'L': ans += 1 else: if S[i] != S[i+1]: ch += 1 if S[i] == S[i+1] == 'R' or S[i] == S[i-1] == 'L': ans += 1 print((ans+min(K*2,ch)))
n,k = list(map(int,input().split())) s = eval(input()) same = 0 for i in range(n-1): if s[i] == s[i+1]: same += 1 diff = n-1-same print((same + min(2*k,diff)))
23
12
526
173
N, K = list(map(int, input().split())) S = list(eval(input())) ch = 0 ans = 0 if N != 1: for i in range(N): if i == 0: if S[i] != S[i + 1]: ch += 1 if S[i] == S[i + 1] == "R": ans += 1 elif i == N - 1: if S[i] == S[i - 1] == "L": ans += 1 else: if S[i] != S[i + 1]: ch += 1 if S[i] == S[i + 1] == "R" or S[i] == S[i - 1] == "L": ans += 1 print((ans + min(K * 2, ch)))
n, k = list(map(int, input().split())) s = eval(input()) same = 0 for i in range(n - 1): if s[i] == s[i + 1]: same += 1 diff = n - 1 - same print((same + min(2 * k, diff)))
false
47.826087
[ "-N, K = list(map(int, input().split()))", "-S = list(eval(input()))", "-ch = 0", "-ans = 0", "-if N != 1:", "- for i in range(N):", "- if i == 0:", "- if S[i] != S[i + 1]:", "- ch += 1", "- if S[i] == S[i + 1] == \"R\":", "- ans += 1", "- elif i == N - 1:", "- if S[i] == S[i - 1] == \"L\":", "- ans += 1", "- else:", "- if S[i] != S[i + 1]:", "- ch += 1", "- if S[i] == S[i + 1] == \"R\" or S[i] == S[i - 1] == \"L\":", "- ans += 1", "-print((ans + min(K * 2, ch)))", "+n, k = list(map(int, input().split()))", "+s = eval(input())", "+same = 0", "+for i in range(n - 1):", "+ if s[i] == s[i + 1]:", "+ same += 1", "+diff = n - 1 - same", "+print((same + min(2 * k, diff)))" ]
false
0.04662
0.107692
0.432906
[ "s683768054", "s238086931" ]
u057964173
p03385
python
s864289769
s890086686
177
17
38,256
2,940
Accepted
Accepted
90.4
import sys def input(): return sys.stdin.readline().strip() def resolve(): s=eval(input()) if s.count('a')==s.count('b')==s.count('c')==1: print('Yes') else: print('No') resolve()
import sys def input(): return sys.stdin.readline().strip() def resolve(): s=eval(input()) if s in ['abc','acb','bca','bac','cab','cba']: print('Yes') else: print('No') resolve()
10
10
211
210
import sys def input(): return sys.stdin.readline().strip() def resolve(): s = eval(input()) if s.count("a") == s.count("b") == s.count("c") == 1: print("Yes") else: print("No") resolve()
import sys def input(): return sys.stdin.readline().strip() def resolve(): s = eval(input()) if s in ["abc", "acb", "bca", "bac", "cab", "cba"]: print("Yes") else: print("No") resolve()
false
0
[ "- if s.count(\"a\") == s.count(\"b\") == s.count(\"c\") == 1:", "+ if s in [\"abc\", \"acb\", \"bca\", \"bac\", \"cab\", \"cba\"]:" ]
false
0.041871
0.041985
0.997274
[ "s864289769", "s890086686" ]
u229156891
p03341
python
s895986478
s433182275
214
150
3,700
11,556
Accepted
Accepted
29.91
N = int(eval(input())) S = eval(input()) w_left = 0 e_right = S[1:].count("E") ans = float('inf') for i in range(N): if i != 0: if S[i] == "E": e_right -= 1 if S[i-1] == "W": w_left += 1 ans = min(ans, w_left + e_right) print(ans)
N = int(eval(input())) S = list(eval(input())) e_cnt = S.count('E') w_cnt = 0 ans = float('inf') for i in range(N): if S[i] == 'E': e_cnt -= 1 w = w_cnt else: w_cnt += 1 w = w_cnt - 1 ans = min(ans, e_cnt+w) print(ans)
14
17
281
273
N = int(eval(input())) S = eval(input()) w_left = 0 e_right = S[1:].count("E") ans = float("inf") for i in range(N): if i != 0: if S[i] == "E": e_right -= 1 if S[i - 1] == "W": w_left += 1 ans = min(ans, w_left + e_right) print(ans)
N = int(eval(input())) S = list(eval(input())) e_cnt = S.count("E") w_cnt = 0 ans = float("inf") for i in range(N): if S[i] == "E": e_cnt -= 1 w = w_cnt else: w_cnt += 1 w = w_cnt - 1 ans = min(ans, e_cnt + w) print(ans)
false
17.647059
[ "-S = eval(input())", "-w_left = 0", "-e_right = S[1:].count(\"E\")", "+S = list(eval(input()))", "+e_cnt = S.count(\"E\")", "+w_cnt = 0", "- if i != 0:", "- if S[i] == \"E\":", "- e_right -= 1", "- if S[i - 1] == \"W\":", "- w_left += 1", "- ans = min(ans, w_left + e_right)", "+ if S[i] == \"E\":", "+ e_cnt -= 1", "+ w = w_cnt", "+ else:", "+ w_cnt += 1", "+ w = w_cnt - 1", "+ ans = min(ans, e_cnt + w)" ]
false
0.038706
0.118322
0.327124
[ "s895986478", "s433182275" ]
u827885761
p03030
python
s297008037
s635188896
19
17
3,064
3,060
Accepted
Accepted
10.53
n = int(eval(input())) l = [0] * n for i in range(n): l[i] = input().split() #l.sort(key=lambda x: x[0] s = sorted(list(set([l[i][0] for i in range(n)]))) for q in s: p = sorted([int(l[i][1]) for i in range(n) if l[i][0] == q], reverse=1) for pp in p: ans = l.index([q,str(pp)]) + 1 print(ans)
n = int(eval(input())) l = [] for i in range(n): s, p = input().split() l.append((s,-int(p),i)) print(('\n'.join([str(t[2]+1) for t in sorted(l)])))
11
7
326
156
n = int(eval(input())) l = [0] * n for i in range(n): l[i] = input().split() # l.sort(key=lambda x: x[0] s = sorted(list(set([l[i][0] for i in range(n)]))) for q in s: p = sorted([int(l[i][1]) for i in range(n) if l[i][0] == q], reverse=1) for pp in p: ans = l.index([q, str(pp)]) + 1 print(ans)
n = int(eval(input())) l = [] for i in range(n): s, p = input().split() l.append((s, -int(p), i)) print(("\n".join([str(t[2] + 1) for t in sorted(l)])))
false
36.363636
[ "-l = [0] * n", "+l = []", "- l[i] = input().split()", "-# l.sort(key=lambda x: x[0]", "-s = sorted(list(set([l[i][0] for i in range(n)])))", "-for q in s:", "- p = sorted([int(l[i][1]) for i in range(n) if l[i][0] == q], reverse=1)", "- for pp in p:", "- ans = l.index([q, str(pp)]) + 1", "- print(ans)", "+ s, p = input().split()", "+ l.append((s, -int(p), i))", "+print((\"\\n\".join([str(t[2] + 1) for t in sorted(l)])))" ]
false
0.049745
0.065786
0.756168
[ "s297008037", "s635188896" ]
u978178314
p03469
python
s849365100
s789170472
12
11
2,692
2,568
Accepted
Accepted
8.33
import re S = list(input()) S[3] = "8" out = "" for s in S: out += s print(out)
S = input() print("2018"+S[4:])
8
2
93
36
import re S = list(input()) S[3] = "8" out = "" for s in S: out += s print(out)
S = input() print("2018" + S[4:])
false
75
[ "-import re", "-", "-S = list(input())", "-S[3] = \"8\"", "-out = \"\"", "-for s in S:", "- out += s", "-print(out)", "+S = input()", "+print(\"2018\" + S[4:])" ]
false
0.040746
0.049157
0.82888
[ "s849365100", "s789170472" ]
u075012704
p03612
python
s112483342
s002150790
89
64
14,004
14,008
Accepted
Accepted
28.09
N = int(eval(input())) P = list(map(int, input().split())) ans = 0 if P[-1] == N: tmp = P[-1] P[-1] = P[-2] P[-2] = tmp ans += 1 for i in range(N-1): if P[i] == i+1: tmp = P[i] P[i] = P[i+1] P[i+1] = tmp ans += 1 for i in range(N): if P[i] == i+1: ans += 1 print(ans)
N = int(eval(input())) P = list(map(int, input().split())) ans = 0 i = 0 while i < N: if P[i] == i + 1: ans += 1 i += 1 i += 1 print(ans)
23
12
352
169
N = int(eval(input())) P = list(map(int, input().split())) ans = 0 if P[-1] == N: tmp = P[-1] P[-1] = P[-2] P[-2] = tmp ans += 1 for i in range(N - 1): if P[i] == i + 1: tmp = P[i] P[i] = P[i + 1] P[i + 1] = tmp ans += 1 for i in range(N): if P[i] == i + 1: ans += 1 print(ans)
N = int(eval(input())) P = list(map(int, input().split())) ans = 0 i = 0 while i < N: if P[i] == i + 1: ans += 1 i += 1 i += 1 print(ans)
false
47.826087
[ "-if P[-1] == N:", "- tmp = P[-1]", "- P[-1] = P[-2]", "- P[-2] = tmp", "- ans += 1", "-for i in range(N - 1):", "- if P[i] == i + 1:", "- tmp = P[i]", "- P[i] = P[i + 1]", "- P[i + 1] = tmp", "- ans += 1", "-for i in range(N):", "+i = 0", "+while i < N:", "+ i += 1", "+ i += 1" ]
false
0.043436
0.043033
1.009364
[ "s112483342", "s002150790" ]
u167647458
p02713
python
s549611821
s164658189
992
503
69,796
68,312
Accepted
Accepted
49.29
import math from functools import reduce def gcd(*numbers): return reduce(math.gcd, numbers) k = int(eval(input())) ans = 0 for a in range(1, k+1): for b in range(1, k+1): for c in range(1, k+1): ans += gcd(a, b, c) print(ans)
import math def gcd(*numbers): return math.gcd( math.gcd(a, b), c) k = int(eval(input())) ans = 0 for a in range(1, k+1): for b in range(1, k+1): for c in range(1, k+1): ans += gcd(a, b, c) print(ans)
16
15
280
253
import math from functools import reduce def gcd(*numbers): return reduce(math.gcd, numbers) k = int(eval(input())) ans = 0 for a in range(1, k + 1): for b in range(1, k + 1): for c in range(1, k + 1): ans += gcd(a, b, c) print(ans)
import math def gcd(*numbers): return math.gcd(math.gcd(a, b), c) k = int(eval(input())) ans = 0 for a in range(1, k + 1): for b in range(1, k + 1): for c in range(1, k + 1): ans += gcd(a, b, c) print(ans)
false
6.25
[ "-from functools import reduce", "- return reduce(math.gcd, numbers)", "+ return math.gcd(math.gcd(a, b), c)" ]
false
0.007158
0.20904
0.034243
[ "s549611821", "s164658189" ]
u692336506
p02623
python
s438555939
s237231870
343
303
47,348
47,672
Accepted
Accepted
11.66
from bisect import bisect N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) SA = [0] * (N + 1) SB = [0] * (M + 1) for i in range(N): SA[i+1] = SA[i] + A[i] for i in range(M): SB[i+1] = SB[i] + B[i] result = 0 for x in range(N+1): if SA[x] > K: break y = bisect(SB, K - SA[x]) - 1 result = max(result, x + y) print(result)
from bisect import bisect N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) SA = [0] * (N + 1) SB = [0] * (M + 1) for i in range(N): SA[i+1] = SA[i] + A[i] for i in range(M): SB[i+1] = SB[i] + B[i] result = 0 y = M for x in range(N+1): if SA[x] > K: break while y >= 0 and SA[x] + SB[y] > K: y -= 1 result = max(result, x + y) print(result)
17
20
423
454
from bisect import bisect N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) SA = [0] * (N + 1) SB = [0] * (M + 1) for i in range(N): SA[i + 1] = SA[i] + A[i] for i in range(M): SB[i + 1] = SB[i] + B[i] result = 0 for x in range(N + 1): if SA[x] > K: break y = bisect(SB, K - SA[x]) - 1 result = max(result, x + y) print(result)
from bisect import bisect N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) SA = [0] * (N + 1) SB = [0] * (M + 1) for i in range(N): SA[i + 1] = SA[i] + A[i] for i in range(M): SB[i + 1] = SB[i] + B[i] result = 0 y = M for x in range(N + 1): if SA[x] > K: break while y >= 0 and SA[x] + SB[y] > K: y -= 1 result = max(result, x + y) print(result)
false
15
[ "+y = M", "- y = bisect(SB, K - SA[x]) - 1", "+ while y >= 0 and SA[x] + SB[y] > K:", "+ y -= 1" ]
false
0.09056
0.039539
2.290407
[ "s438555939", "s237231870" ]
u148551245
p03455
python
s158052784
s482914534
162
17
38,256
2,940
Accepted
Accepted
89.51
(a, b) = list(map(int, input().split())) if a % 2 == 1 and b % 2 == 1: print("Odd") else: print("Even")
a, b = list(map(int, input().split())) if a % 2 == 1 and b % 2 == 1: print("Odd") else: print("Even")
5
5
109
107
(a, b) = list(map(int, input().split())) if a % 2 == 1 and b % 2 == 1: print("Odd") else: print("Even")
a, b = list(map(int, input().split())) if a % 2 == 1 and b % 2 == 1: print("Odd") else: print("Even")
false
0
[ "-(a, b) = list(map(int, input().split()))", "+a, b = list(map(int, input().split()))" ]
false
0.150199
0.041773
3.595591
[ "s158052784", "s482914534" ]
u309120194
p02801
python
s823636358
s779571918
27
24
9,084
8,896
Accepted
Accepted
11.11
C = eval(input()) # 文字列と数値の変換 # ord('文字') / chr(数値) で変換できる ord_s = ord(C) chr_s = chr(ord_s + 1) print(chr_s)
C = eval(input()) l = list('abcdefghijklmnopqrstuvwxyz') print((l[l.index(C)+1]))
8
4
112
77
C = eval(input()) # 文字列と数値の変換 # ord('文字') / chr(数値) で変換できる ord_s = ord(C) chr_s = chr(ord_s + 1) print(chr_s)
C = eval(input()) l = list("abcdefghijklmnopqrstuvwxyz") print((l[l.index(C) + 1]))
false
50
[ "-# 文字列と数値の変換", "-# ord('文字') / chr(数値) で変換できる", "-ord_s = ord(C)", "-chr_s = chr(ord_s + 1)", "-print(chr_s)", "+l = list(\"abcdefghijklmnopqrstuvwxyz\")", "+print((l[l.index(C) + 1]))" ]
false
0.159542
0.159553
0.999932
[ "s823636358", "s779571918" ]
u545368057
p02954
python
s893987843
s603527258
145
102
9,128
87,356
Accepted
Accepted
29.66
S = eval(input()) # S = "RL" rs = [] ls = [] inds = [] s_inv = S[::-1] rcnt = 0 #Rを数える for i,s in enumerate(S): if s == "R": rcnt += 1 else: if rcnt > 0: #記録 rs.append(rcnt) inds.append(i-1) rcnt = 0 #Lを数える # print(s_inv) lcnt = 0 for i,s in enumerate(s_inv): if s == "L": lcnt += 1 else: if lcnt > 0: ls.append(lcnt) lcnt = 0 ls = ls[::-1] ans = [0]*len(S) for i,r,l in zip(inds,rs,ls): adds = r+l # print(adds,i) if (r+l)%2 == 0: ans[i] = (r+l)//2 ans[i+1] = (r+l)//2 else: if r%2 == 1: ans[i] = (r+l)//2 + 1 ans[i+1] = (r+l)//2 else: ans[i] = (r+l)//2 ans[i+1] = (r+l)//2 + 1 print((*ans))
S = eval(input()) prev = "" cut = [0] inds = [] rs = [] r = 0 for i in range(len(S)): if prev == "L" and S[i] == "R": cut.append(i) if prev == "R" and S[i] == "L": inds.append(i) rs.append(r) r = 0 if S[i] == "R": r += 1 prev = S[i] cut.append(len(S)) diff = [cut[i]-cut[i-1] for i in range(1,len(cut))] ans = [0] * len(S) # print(rs) # print(diff) # print(inds) for d, i, r in zip(diff, inds, rs): ans[i-1] = d//2 ans[i] = d//2 if d%2 == 1 and r%2==1: ans[i-1] += 1 elif d%2 == 1 and r%2 == 0: ans[i] += 1 print((*ans))
46
30
841
630
S = eval(input()) # S = "RL" rs = [] ls = [] inds = [] s_inv = S[::-1] rcnt = 0 # Rを数える for i, s in enumerate(S): if s == "R": rcnt += 1 else: if rcnt > 0: # 記録 rs.append(rcnt) inds.append(i - 1) rcnt = 0 # Lを数える # print(s_inv) lcnt = 0 for i, s in enumerate(s_inv): if s == "L": lcnt += 1 else: if lcnt > 0: ls.append(lcnt) lcnt = 0 ls = ls[::-1] ans = [0] * len(S) for i, r, l in zip(inds, rs, ls): adds = r + l # print(adds,i) if (r + l) % 2 == 0: ans[i] = (r + l) // 2 ans[i + 1] = (r + l) // 2 else: if r % 2 == 1: ans[i] = (r + l) // 2 + 1 ans[i + 1] = (r + l) // 2 else: ans[i] = (r + l) // 2 ans[i + 1] = (r + l) // 2 + 1 print((*ans))
S = eval(input()) prev = "" cut = [0] inds = [] rs = [] r = 0 for i in range(len(S)): if prev == "L" and S[i] == "R": cut.append(i) if prev == "R" and S[i] == "L": inds.append(i) rs.append(r) r = 0 if S[i] == "R": r += 1 prev = S[i] cut.append(len(S)) diff = [cut[i] - cut[i - 1] for i in range(1, len(cut))] ans = [0] * len(S) # print(rs) # print(diff) # print(inds) for d, i, r in zip(diff, inds, rs): ans[i - 1] = d // 2 ans[i] = d // 2 if d % 2 == 1 and r % 2 == 1: ans[i - 1] += 1 elif d % 2 == 1 and r % 2 == 0: ans[i] += 1 print((*ans))
false
34.782609
[ "-# S = \"RL\"", "+prev = \"\"", "+cut = [0]", "+inds = []", "-ls = []", "-inds = []", "-s_inv = S[::-1]", "-rcnt = 0", "-# Rを数える", "-for i, s in enumerate(S):", "- if s == \"R\":", "- rcnt += 1", "- else:", "- if rcnt > 0:", "- # 記録", "- rs.append(rcnt)", "- inds.append(i - 1)", "- rcnt = 0", "-# Lを数える", "-# print(s_inv)", "-lcnt = 0", "-for i, s in enumerate(s_inv):", "- if s == \"L\":", "- lcnt += 1", "- else:", "- if lcnt > 0:", "- ls.append(lcnt)", "- lcnt = 0", "-ls = ls[::-1]", "+r = 0", "+for i in range(len(S)):", "+ if prev == \"L\" and S[i] == \"R\":", "+ cut.append(i)", "+ if prev == \"R\" and S[i] == \"L\":", "+ inds.append(i)", "+ rs.append(r)", "+ r = 0", "+ if S[i] == \"R\":", "+ r += 1", "+ prev = S[i]", "+cut.append(len(S))", "+diff = [cut[i] - cut[i - 1] for i in range(1, len(cut))]", "-for i, r, l in zip(inds, rs, ls):", "- adds = r + l", "- # print(adds,i)", "- if (r + l) % 2 == 0:", "- ans[i] = (r + l) // 2", "- ans[i + 1] = (r + l) // 2", "- else:", "- if r % 2 == 1:", "- ans[i] = (r + l) // 2 + 1", "- ans[i + 1] = (r + l) // 2", "- else:", "- ans[i] = (r + l) // 2", "- ans[i + 1] = (r + l) // 2 + 1", "+# print(rs)", "+# print(diff)", "+# print(inds)", "+for d, i, r in zip(diff, inds, rs):", "+ ans[i - 1] = d // 2", "+ ans[i] = d // 2", "+ if d % 2 == 1 and r % 2 == 1:", "+ ans[i - 1] += 1", "+ elif d % 2 == 1 and r % 2 == 0:", "+ ans[i] += 1" ]
false
0.046365
0.069308
0.668964
[ "s893987843", "s603527258" ]
u604774382
p02408
python
s242643087
s489276879
40
20
6,720
4,220
Accepted
Accepted
50
import sys n = int( sys.stdin.readline() ) cards = { 'S': [ False ] * 13, 'H': [ False ] * 13, 'C': [ False ] * 13, 'D': [ False ] * 13 } for i in range( n ): pattern, num = sys.stdin.readline().split( " " ) cards[ pattern ][ int( num )-1 ] = True for pattern in ( 'S', 'H', 'C', 'D' ): for i in range( 13 ): if not cards[ pattern ][ i ]: print(( "{:s} {:d}".format( pattern, i+1 ) ))
import sys n = int( sys.stdin.readline() ) cards = { pattern:[False]*13 for pattern in ( 'S', 'H', 'C', 'D' ) } for i in range( n ): pattern, num = sys.stdin.readline().split( " " ) cards[ pattern ][ int( num )-1 ] = True for pattern in ( 'S', 'H', 'C', 'D' ): for i in range( 13 ): if not cards[ pattern ][ i ]: print(( "{:s} {:d}".format( pattern, i+1 ) ))
12
12
403
377
import sys n = int(sys.stdin.readline()) cards = {"S": [False] * 13, "H": [False] * 13, "C": [False] * 13, "D": [False] * 13} for i in range(n): pattern, num = sys.stdin.readline().split(" ") cards[pattern][int(num) - 1] = True for pattern in ("S", "H", "C", "D"): for i in range(13): if not cards[pattern][i]: print(("{:s} {:d}".format(pattern, i + 1)))
import sys n = int(sys.stdin.readline()) cards = {pattern: [False] * 13 for pattern in ("S", "H", "C", "D")} for i in range(n): pattern, num = sys.stdin.readline().split(" ") cards[pattern][int(num) - 1] = True for pattern in ("S", "H", "C", "D"): for i in range(13): if not cards[pattern][i]: print(("{:s} {:d}".format(pattern, i + 1)))
false
0
[ "-cards = {\"S\": [False] * 13, \"H\": [False] * 13, \"C\": [False] * 13, \"D\": [False] * 13}", "+cards = {pattern: [False] * 13 for pattern in (\"S\", \"H\", \"C\", \"D\")}" ]
false
0.038423
0.084281
0.455891
[ "s242643087", "s489276879" ]
u756595712
p02255
python
s740733116
s638047194
30
20
7,684
8,084
Accepted
Accepted
33.33
def insertionSort(_list, _length): for i in range(1, _length): ll = [str(_l) for _l in _list] print((' '.join(ll))) val = _list[i] j = i - 1 while j >= 0 and _list[j] > val: _list[j+1] = _list[j] j -= 1 _list[j+1] = val ll = [str(_l) for _l in _list] print((' '.join(ll))) length = int(eval(input())) eles = list(map(int, input().split())) insertionSort(eles, length)
length = int(eval(input())) eles = [int(i) for i in input().split()] for i in range(length): val = eles[i] j = i - 1 while j >= 0 and eles[j] > val: eles[j+1] = eles[j] j -= 1 eles[j+1] = val print((*eles))
18
11
461
245
def insertionSort(_list, _length): for i in range(1, _length): ll = [str(_l) for _l in _list] print((" ".join(ll))) val = _list[i] j = i - 1 while j >= 0 and _list[j] > val: _list[j + 1] = _list[j] j -= 1 _list[j + 1] = val ll = [str(_l) for _l in _list] print((" ".join(ll))) length = int(eval(input())) eles = list(map(int, input().split())) insertionSort(eles, length)
length = int(eval(input())) eles = [int(i) for i in input().split()] for i in range(length): val = eles[i] j = i - 1 while j >= 0 and eles[j] > val: eles[j + 1] = eles[j] j -= 1 eles[j + 1] = val print((*eles))
false
38.888889
[ "-def insertionSort(_list, _length):", "- for i in range(1, _length):", "- ll = [str(_l) for _l in _list]", "- print((\" \".join(ll)))", "- val = _list[i]", "- j = i - 1", "- while j >= 0 and _list[j] > val:", "- _list[j + 1] = _list[j]", "- j -= 1", "- _list[j + 1] = val", "- ll = [str(_l) for _l in _list]", "- print((\" \".join(ll)))", "-", "-", "-eles = list(map(int, input().split()))", "-insertionSort(eles, length)", "+eles = [int(i) for i in input().split()]", "+for i in range(length):", "+ val = eles[i]", "+ j = i - 1", "+ while j >= 0 and eles[j] > val:", "+ eles[j + 1] = eles[j]", "+ j -= 1", "+ eles[j + 1] = val", "+ print((*eles))" ]
false
0.064126
0.050971
1.258098
[ "s740733116", "s638047194" ]
u316386814
p03013
python
s967684394
s710347144
75
68
7,796
7,796
Accepted
Accepted
9.33
import sys sys.setrecursionlimit(10**7) INF = 10 ** 18 MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def main(): N, M = LI() A = [0] * (N + 1) for _ in range(M): A[II()] = 1 dp = [0] * (N + 1) dp[0] = 1 for i in range(1, N + 1): if A[i] == 1: dp[i] = 0 else: dp[i] = (dp[i - 1] + dp[i - 2]) % MOD ans = dp[N] return ans print((main()))
import sys sys.setrecursionlimit(10**7) INF = 10 ** 18 MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def main(): N, M = LI() A = [0] * (N + 1) for _ in range(M): A[II()] = 1 dp = [0] * (N + 1) dp[0] = 1 dp[1] = dp[0] if A[1] == 0 else 0 for i in range(2, N + 1): if A[i] == 1: dp[i] = 0 else: dp[i] = (dp[i - 1] + dp[i - 2]) % MOD ans = dp[N] return ans print((main()))
27
28
726
765
import sys sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def main(): N, M = LI() A = [0] * (N + 1) for _ in range(M): A[II()] = 1 dp = [0] * (N + 1) dp[0] = 1 for i in range(1, N + 1): if A[i] == 1: dp[i] = 0 else: dp[i] = (dp[i - 1] + dp[i - 2]) % MOD ans = dp[N] return ans print((main()))
import sys sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return eval(input()) def main(): N, M = LI() A = [0] * (N + 1) for _ in range(M): A[II()] = 1 dp = [0] * (N + 1) dp[0] = 1 dp[1] = dp[0] if A[1] == 0 else 0 for i in range(2, N + 1): if A[i] == 1: dp[i] = 0 else: dp[i] = (dp[i - 1] + dp[i - 2]) % MOD ans = dp[N] return ans print((main()))
false
3.571429
[ "- for i in range(1, N + 1):", "+ dp[1] = dp[0] if A[1] == 0 else 0", "+ for i in range(2, N + 1):" ]
false
0.042523
0.050359
0.844399
[ "s967684394", "s710347144" ]
u810356688
p02861
python
s738824716
s689751044
257
18
8,052
3,064
Accepted
Accepted
93
import sys from math import sqrt from itertools import permutations def input(): return sys.stdin.readline().rstrip() def main(): n=int(eval(input())) A =[[int(_) for _ in input().split()] for i in range(n)] a_list=list(permutations(A)) a_len=len(a_list) ans_all=0 for i in range(a_len): keiro = a_list[i] ans=0 x0=keiro[0][0] y0=keiro[0][1] for x1,y1 in keiro[1:]: ans+=sqrt((x1-x0)**2+(y1-y0)**2) ans_all+=ans print((ans_all/a_len)) if __name__=='__main__': main()
import sys from math import sqrt def input(): return sys.stdin.readline().rstrip() def main(): n=int(eval(input())) A =[[int(_) for _ in input().split()] for i in range(n)] ans=0 for i in range(n-1): for j in range(i+1,n): ans+=sqrt((A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2) print((ans*2/n)) if __name__=='__main__': main()
21
13
570
372
import sys from math import sqrt from itertools import permutations def input(): return sys.stdin.readline().rstrip() def main(): n = int(eval(input())) A = [[int(_) for _ in input().split()] for i in range(n)] a_list = list(permutations(A)) a_len = len(a_list) ans_all = 0 for i in range(a_len): keiro = a_list[i] ans = 0 x0 = keiro[0][0] y0 = keiro[0][1] for x1, y1 in keiro[1:]: ans += sqrt((x1 - x0) ** 2 + (y1 - y0) ** 2) ans_all += ans print((ans_all / a_len)) if __name__ == "__main__": main()
import sys from math import sqrt def input(): return sys.stdin.readline().rstrip() def main(): n = int(eval(input())) A = [[int(_) for _ in input().split()] for i in range(n)] ans = 0 for i in range(n - 1): for j in range(i + 1, n): ans += sqrt((A[i][0] - A[j][0]) ** 2 + (A[i][1] - A[j][1]) ** 2) print((ans * 2 / n)) if __name__ == "__main__": main()
false
38.095238
[ "-from itertools import permutations", "- a_list = list(permutations(A))", "- a_len = len(a_list)", "- ans_all = 0", "- for i in range(a_len):", "- keiro = a_list[i]", "- ans = 0", "- x0 = keiro[0][0]", "- y0 = keiro[0][1]", "- for x1, y1 in keiro[1:]:", "- ans += sqrt((x1 - x0) ** 2 + (y1 - y0) ** 2)", "- ans_all += ans", "- print((ans_all / a_len))", "+ ans = 0", "+ for i in range(n - 1):", "+ for j in range(i + 1, n):", "+ ans += sqrt((A[i][0] - A[j][0]) ** 2 + (A[i][1] - A[j][1]) ** 2)", "+ print((ans * 2 / n))" ]
false
0.042293
0.044779
0.944476
[ "s738824716", "s689751044" ]
u186838327
p03680
python
s521774227
s485744241
521
233
49,644
95,536
Accepted
Accepted
55.28
n = int(eval(input())) l = [int(eval(input()))-1 for i in range(n)] a = l[0] for i in range(n): if a == 1: print((i+1)) exit() a = l[a] else: print((-1))
n = int(eval(input())) A = [int(eval(input())) for _ in range(n)] g = [[] for _ in range(n)] for i, a in enumerate(A): g[a-1].append(i) from collections import deque q = deque([1]) visit = [-1]*n visit[1] = 0 while q: v = q.popleft() for u in g[v]: if visit[u] == -1: visit[u] = visit[v]+1 q.append(u) if visit[0] == -1: print((-1)) else: print((visit[0]))
11
21
162
415
n = int(eval(input())) l = [int(eval(input())) - 1 for i in range(n)] a = l[0] for i in range(n): if a == 1: print((i + 1)) exit() a = l[a] else: print((-1))
n = int(eval(input())) A = [int(eval(input())) for _ in range(n)] g = [[] for _ in range(n)] for i, a in enumerate(A): g[a - 1].append(i) from collections import deque q = deque([1]) visit = [-1] * n visit[1] = 0 while q: v = q.popleft() for u in g[v]: if visit[u] == -1: visit[u] = visit[v] + 1 q.append(u) if visit[0] == -1: print((-1)) else: print((visit[0]))
false
47.619048
[ "-l = [int(eval(input())) - 1 for i in range(n)]", "-a = l[0]", "-for i in range(n):", "- if a == 1:", "- print((i + 1))", "- exit()", "- a = l[a]", "+A = [int(eval(input())) for _ in range(n)]", "+g = [[] for _ in range(n)]", "+for i, a in enumerate(A):", "+ g[a - 1].append(i)", "+from collections import deque", "+", "+q = deque([1])", "+visit = [-1] * n", "+visit[1] = 0", "+while q:", "+ v = q.popleft()", "+ for u in g[v]:", "+ if visit[u] == -1:", "+ visit[u] = visit[v] + 1", "+ q.append(u)", "+if visit[0] == -1:", "+ print((-1))", "- print((-1))", "+ print((visit[0]))" ]
false
0.042062
0.122654
0.342929
[ "s521774227", "s485744241" ]
u063052907
p03474
python
s050839605
s263623223
20
18
3,188
2,940
Accepted
Accepted
10
# coding: utf-8 import re A, B = list(map(int, input().split())) S = eval(input()) if S[A] != "-": print("No") else: if "-" in S[0:A] or "-" in S[A+1:]: print("No") else: print("Yes")
# coding: utf-8 A, B = list(map(int, input().split())) S = eval(input()) if S[A] != "-": print("No") else: if "-" in S[0:A] or "-" in S[A+1:]: print("No") else: print("Yes")
12
11
211
201
# coding: utf-8 import re A, B = list(map(int, input().split())) S = eval(input()) if S[A] != "-": print("No") else: if "-" in S[0:A] or "-" in S[A + 1 :]: print("No") else: print("Yes")
# coding: utf-8 A, B = list(map(int, input().split())) S = eval(input()) if S[A] != "-": print("No") else: if "-" in S[0:A] or "-" in S[A + 1 :]: print("No") else: print("Yes")
false
8.333333
[ "-import re", "-" ]
false
0.048237
0.047867
1.007743
[ "s050839605", "s263623223" ]
u024782094
p02622
python
s399455921
s568189590
106
66
78,368
9,468
Accepted
Accepted
37.74
import sys import heapq import math import fractions import bisect import itertools from collections import Counter from collections import deque from operator import itemgetter def input(): return sys.stdin.readline().strip() def mp(): return list(map(int,input().split())) def lmp(): return list(map(int,input().split())) s=eval(input()) t=eval(input()) ans=0 for i in range(len(s)): if s[i]!=t[i]: ans+=1 print(ans)
s=eval(input()) t=eval(input()) ans=0 for i in range(len(s)): if s[i]!=t[i]: ans+=1 print(ans)
20
7
432
100
import sys import heapq import math import fractions import bisect import itertools from collections import Counter from collections import deque from operator import itemgetter def input(): return sys.stdin.readline().strip() def mp(): return list(map(int, input().split())) def lmp(): return list(map(int, input().split())) s = eval(input()) t = eval(input()) ans = 0 for i in range(len(s)): if s[i] != t[i]: ans += 1 print(ans)
s = eval(input()) t = eval(input()) ans = 0 for i in range(len(s)): if s[i] != t[i]: ans += 1 print(ans)
false
65
[ "-import sys", "-import heapq", "-import math", "-import fractions", "-import bisect", "-import itertools", "-from collections import Counter", "-from collections import deque", "-from operator import itemgetter", "-", "-", "-def input():", "- return sys.stdin.readline().strip()", "-", "-", "-def mp():", "- return list(map(int, input().split()))", "-", "-", "-def lmp():", "- return list(map(int, input().split()))", "-", "-" ]
false
0.036028
0.035717
1.008684
[ "s399455921", "s568189590" ]
u102461423
p03014
python
s176775626
s710001066
1,049
927
188,708
217,728
Accepted
Accepted
11.63
import numpy as np H,W = list(map(int,input().split())) temp = np.array([list(eval(input())) for _ in range(H)]) # 周りに壁を、0,1化 map = np.zeros((H+2,W+2),dtype=np.int32) map[1:-1,1:-1][temp == '.'] = 1 # x軸正方向の集計 def F(transpose,reverse): x = map.copy() if transpose: x = x.T x = np.ravel(x) if reverse: x = x[::-1] zero_idx = np.nonzero(x==0)[0] x[zero_idx[1:]] = 1-np.diff(zero_idx) # cumsumで求められるように変形 x = x.cumsum() if reverse: x = x[::-1] if transpose: x = x.reshape(map.T.shape).T else: x = x.reshape(map.shape) return x answer = np.zeros_like(map) for t in [True,False]: for r in [True,False]: answer += F(t,r) answer = answer.max() - 3 print(answer)
import numpy as np H,W = list(map(int,input().split())) temp = np.array([list(eval(input())) for _ in range(H)]) # 周りに壁を、0,1化、壁をTrueで持つ map = np.ones((H+2,W+2),dtype=np.bool) map[1:-1,1:-1] = (temp == '#') # x軸正方向の集計 def F(transpose): x = map.copy() if transpose: x = x.T x = np.ravel(x) # to 1D array zero_idx = np.nonzero(x)[0] zero_span = np.diff(zero_idx) - 1 # 次の0までにある1の個数 y = np.zeros(len(x),dtype=np.int32) y[1:][zero_idx[:-1]] = zero_span y[zero_idx[1:]] -= zero_span y = y.cumsum() if transpose: y = y.reshape(map.T.shape).T else: y = y.reshape(map.shape) return y answer = np.zeros(map.shape,dtype=np.int32) for t in [True,False]: answer += F(t) answer = answer.max() - 1 print(answer)
34
33
731
765
import numpy as np H, W = list(map(int, input().split())) temp = np.array([list(eval(input())) for _ in range(H)]) # 周りに壁を、0,1化 map = np.zeros((H + 2, W + 2), dtype=np.int32) map[1:-1, 1:-1][temp == "."] = 1 # x軸正方向の集計 def F(transpose, reverse): x = map.copy() if transpose: x = x.T x = np.ravel(x) if reverse: x = x[::-1] zero_idx = np.nonzero(x == 0)[0] x[zero_idx[1:]] = 1 - np.diff(zero_idx) # cumsumで求められるように変形 x = x.cumsum() if reverse: x = x[::-1] if transpose: x = x.reshape(map.T.shape).T else: x = x.reshape(map.shape) return x answer = np.zeros_like(map) for t in [True, False]: for r in [True, False]: answer += F(t, r) answer = answer.max() - 3 print(answer)
import numpy as np H, W = list(map(int, input().split())) temp = np.array([list(eval(input())) for _ in range(H)]) # 周りに壁を、0,1化、壁をTrueで持つ map = np.ones((H + 2, W + 2), dtype=np.bool) map[1:-1, 1:-1] = temp == "#" # x軸正方向の集計 def F(transpose): x = map.copy() if transpose: x = x.T x = np.ravel(x) # to 1D array zero_idx = np.nonzero(x)[0] zero_span = np.diff(zero_idx) - 1 # 次の0までにある1の個数 y = np.zeros(len(x), dtype=np.int32) y[1:][zero_idx[:-1]] = zero_span y[zero_idx[1:]] -= zero_span y = y.cumsum() if transpose: y = y.reshape(map.T.shape).T else: y = y.reshape(map.shape) return y answer = np.zeros(map.shape, dtype=np.int32) for t in [True, False]: answer += F(t) answer = answer.max() - 1 print(answer)
false
2.941176
[ "-# 周りに壁を、0,1化", "-map = np.zeros((H + 2, W + 2), dtype=np.int32)", "-map[1:-1, 1:-1][temp == \".\"] = 1", "+# 周りに壁を、0,1化、壁をTrueで持つ", "+map = np.ones((H + 2, W + 2), dtype=np.bool)", "+map[1:-1, 1:-1] = temp == \"#\"", "-def F(transpose, reverse):", "+def F(transpose):", "- x = np.ravel(x)", "- if reverse:", "- x = x[::-1]", "- zero_idx = np.nonzero(x == 0)[0]", "- x[zero_idx[1:]] = 1 - np.diff(zero_idx) # cumsumで求められるように変形", "- x = x.cumsum()", "- if reverse:", "- x = x[::-1]", "+ x = np.ravel(x) # to 1D array", "+ zero_idx = np.nonzero(x)[0]", "+ zero_span = np.diff(zero_idx) - 1 # 次の0までにある1の個数", "+ y = np.zeros(len(x), dtype=np.int32)", "+ y[1:][zero_idx[:-1]] = zero_span", "+ y[zero_idx[1:]] -= zero_span", "+ y = y.cumsum()", "- x = x.reshape(map.T.shape).T", "+ y = y.reshape(map.T.shape).T", "- x = x.reshape(map.shape)", "- return x", "+ y = y.reshape(map.shape)", "+ return y", "-answer = np.zeros_like(map)", "+answer = np.zeros(map.shape, dtype=np.int32)", "- for r in [True, False]:", "- answer += F(t, r)", "-answer = answer.max() - 3", "+ answer += F(t)", "+answer = answer.max() - 1" ]
false
0.181329
0.212835
0.851969
[ "s176775626", "s710001066" ]
u123600620
p02777
python
s684450794
s051262541
19
17
3,060
2,940
Accepted
Accepted
10.53
# -*- coding: utf-8 -*- str_1,str_2 = input().split() str_1_count,str_2_count = input().split() del_str = eval(input()) if del_str == str_1: str_1_count = int(str_1_count) - 1 else: str_2_count = int(str_2_count) - 1 print((str(str_1_count) +" " + str(str_2_count)))
ball_1,ball_2 = input().split() ball_1_count,ball_2_count = list(map(int , input().split())) getted_str = eval(input()) if getted_str == ball_1: ball_1_count -= 1 else: ball_2_count -= 1 print((str(ball_1_count) + " " + str(ball_2_count)))
11
8
278
240
# -*- coding: utf-8 -*- str_1, str_2 = input().split() str_1_count, str_2_count = input().split() del_str = eval(input()) if del_str == str_1: str_1_count = int(str_1_count) - 1 else: str_2_count = int(str_2_count) - 1 print((str(str_1_count) + " " + str(str_2_count)))
ball_1, ball_2 = input().split() ball_1_count, ball_2_count = list(map(int, input().split())) getted_str = eval(input()) if getted_str == ball_1: ball_1_count -= 1 else: ball_2_count -= 1 print((str(ball_1_count) + " " + str(ball_2_count)))
false
27.272727
[ "-# -*- coding: utf-8 -*-", "-str_1, str_2 = input().split()", "-str_1_count, str_2_count = input().split()", "-del_str = eval(input())", "-if del_str == str_1:", "- str_1_count = int(str_1_count) - 1", "+ball_1, ball_2 = input().split()", "+ball_1_count, ball_2_count = list(map(int, input().split()))", "+getted_str = eval(input())", "+if getted_str == ball_1:", "+ ball_1_count -= 1", "- str_2_count = int(str_2_count) - 1", "-print((str(str_1_count) + \" \" + str(str_2_count)))", "+ ball_2_count -= 1", "+print((str(ball_1_count) + \" \" + str(ball_2_count)))" ]
false
0.046843
0.049388
0.948477
[ "s684450794", "s051262541" ]
u249218427
p02632
python
s775043871
s895257974
663
481
205,420
193,812
Accepted
Accepted
27.45
# -*- coding: utf-8 -*- K = int(eval(input())) S = len(eval(input())) mod = 10**9+7 answer = 0 tmp = 0 # 組み合わせの数の計算は以下URLからコピーしてきた: # https://qiita.com/derodero24/items/91b6468e66923a87f39f def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod N = K+S g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) pow = -1 for i in range(K+1): if pow == -1: pow = 1 else: pow = (pow*25)%mod answer = (answer+pow*cmb(N,i,mod))%mod print(answer)
# -*- coding: utf-8 -*- K = int(eval(input())) S = len(eval(input())) mod = 10**9+7 N = K+S # mod上の逆元の計算 inverse = [0, 1] for i in range(2, N+1): inverse.append((-inverse[mod%i]*(mod//i))%mod) # 階乗とその逆元の計算 factorial = [1, 1] factorial_inv = [1, 1] for i in range(2, N+1): factorial.append((factorial[-1]*i)%mod) factorial_inv.append((factorial_inv[-1]*inverse[i])%mod) answer = 0 pow = -1 for i in range(K+1): if pow == -1: pow = 1 else: pow = (pow*25)%mod answer = (answer+pow*factorial[N]*factorial_inv[i]*factorial_inv[N-i])%mod print(answer)
36
29
737
606
# -*- coding: utf-8 -*- K = int(eval(input())) S = len(eval(input())) mod = 10**9 + 7 answer = 0 tmp = 0 # 組み合わせの数の計算は以下URLからコピーしてきた: # https://qiita.com/derodero24/items/91b6468e66923a87f39f def cmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod N = K + S g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] # 逆元テーブル計算用テーブル for i in range(2, N + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) pow = -1 for i in range(K + 1): if pow == -1: pow = 1 else: pow = (pow * 25) % mod answer = (answer + pow * cmb(N, i, mod)) % mod print(answer)
# -*- coding: utf-8 -*- K = int(eval(input())) S = len(eval(input())) mod = 10**9 + 7 N = K + S # mod上の逆元の計算 inverse = [0, 1] for i in range(2, N + 1): inverse.append((-inverse[mod % i] * (mod // i)) % mod) # 階乗とその逆元の計算 factorial = [1, 1] factorial_inv = [1, 1] for i in range(2, N + 1): factorial.append((factorial[-1] * i) % mod) factorial_inv.append((factorial_inv[-1] * inverse[i]) % mod) answer = 0 pow = -1 for i in range(K + 1): if pow == -1: pow = 1 else: pow = (pow * 25) % mod answer = ( answer + pow * factorial[N] * factorial_inv[i] * factorial_inv[N - i] ) % mod print(answer)
false
19.444444
[ "+N = K + S", "+# mod上の逆元の計算", "+inverse = [0, 1]", "+for i in range(2, N + 1):", "+ inverse.append((-inverse[mod % i] * (mod // i)) % mod)", "+# 階乗とその逆元の計算", "+factorial = [1, 1]", "+factorial_inv = [1, 1]", "+for i in range(2, N + 1):", "+ factorial.append((factorial[-1] * i) % mod)", "+ factorial_inv.append((factorial_inv[-1] * inverse[i]) % mod)", "-tmp = 0", "-# 組み合わせの数の計算は以下URLからコピーしてきた:", "-# https://qiita.com/derodero24/items/91b6468e66923a87f39f", "-def cmb(n, r, mod):", "- if r < 0 or r > n:", "- return 0", "- r = min(r, n - r)", "- return g1[n] * g2[r] * g2[n - r] % mod", "-", "-", "-N = K + S", "-g1 = [1, 1] # 元テーブル", "-g2 = [1, 1] # 逆元テーブル", "-inverse = [0, 1] # 逆元テーブル計算用テーブル", "-for i in range(2, N + 1):", "- g1.append((g1[-1] * i) % mod)", "- inverse.append((-inverse[mod % i] * (mod // i)) % mod)", "- g2.append((g2[-1] * inverse[-1]) % mod)", "- answer = (answer + pow * cmb(N, i, mod)) % mod", "+ answer = (", "+ answer + pow * factorial[N] * factorial_inv[i] * factorial_inv[N - i]", "+ ) % mod" ]
false
0.037542
0.066503
0.564521
[ "s775043871", "s895257974" ]
u102461423
p03653
python
s045529798
s556606486
510
395
39,276
37,200
Accepted
Accepted
22.55
import sys input = sys.stdin.readline from heapq import heappush, heappushpop """ 銅貨の集合を固定すると、金-銀でソートして貪欲に金をとることになる 逆に金-銀でソートしておくと、金が埋まるまでは金or銅の2択 最後にとる金の番号X+nをfix → 手前は金-銅で貪欲 → queueで管理できる """ X,Y,Z = list(map(int,input().split())) ABC = [[int(x) for x in input().split()] for _ in range(X+Y+Z)] ABC.sort(key = lambda x: x[0]-x[1],reverse=True) q = [] sum_a = 0 sum_c = 0 for a,b,c in ABC[:X]: # 金を入れる。銅-金の優先度 heappush(q,(a-c,a)) sum_a += a A = [0] * (Z+1) LC = [0] * (Z+1) A[0] = sum_a for i,(a,b,c) in enumerate(ABC[X:X+Z],1): sum_a += a x,del_a = heappushpop(q,(a-c,a)) sum_a -= del_a sum_c += del_a-x A[i] = sum_a LC[i] = sum_c ABC_rev = ABC[::-1] q = [] sum_b = 0 sum_c = 0 for a,b,c in ABC_rev[:Y]: heappush(q,(b-c,b)) sum_b += b B = [0] * (Z+1) RC = [0] * (Z+1) B[0] += sum_b for i,(a,b,c) in enumerate(ABC_rev[Y:Y+Z],1): sum_b += b x,del_b = heappushpop(q,(b-c,b)) sum_b -= del_b sum_c += del_b-x B[i] = sum_b RC[i] = sum_c answer = max(sum(x) for x in zip(A,LC,B[::-1],RC[::-1])) print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from heapq import heappop, heappush, heappushpop X,Y,Z = list(map(int,readline().split())) m = list(map(int,read().split())) ABC = sorted(zip(m,m,m), key = lambda x: x[1] - x[0]) # 手前は A or C, 後半はB or Cでとるようにする # A or Cで、AをX個とるルール AC = [0] * (X+Y+Z) q = [] # a -> cと変更する利点をマイナスで格納する S = 0 for i,(a,b,c) in enumerate(ABC): S += a d = a - c if len(q) < X: heappush(q,d) else: S -= heappushpop(q,d) AC[i] = S # B or Cで、BをY個とるルール BC = [0] * (X+Y+Z) q = [] # b -> cと変更する利点をマイナスで格納する S = 0 for i,(a,b,c) in enumerate(ABC[::-1]): S += b d = b - c if len(q) < Y: heappush(q,d) else: S -= heappushpop(q,d) BC[i] = S BC = BC[::-1] answer = max(x+y for x,y in zip(AC[X-1:X+Z],BC[X:])) print(answer)
56
42
1,130
910
import sys input = sys.stdin.readline from heapq import heappush, heappushpop """ 銅貨の集合を固定すると、金-銀でソートして貪欲に金をとることになる 逆に金-銀でソートしておくと、金が埋まるまでは金or銅の2択 最後にとる金の番号X+nをfix → 手前は金-銅で貪欲 → queueで管理できる """ X, Y, Z = list(map(int, input().split())) ABC = [[int(x) for x in input().split()] for _ in range(X + Y + Z)] ABC.sort(key=lambda x: x[0] - x[1], reverse=True) q = [] sum_a = 0 sum_c = 0 for a, b, c in ABC[:X]: # 金を入れる。銅-金の優先度 heappush(q, (a - c, a)) sum_a += a A = [0] * (Z + 1) LC = [0] * (Z + 1) A[0] = sum_a for i, (a, b, c) in enumerate(ABC[X : X + Z], 1): sum_a += a x, del_a = heappushpop(q, (a - c, a)) sum_a -= del_a sum_c += del_a - x A[i] = sum_a LC[i] = sum_c ABC_rev = ABC[::-1] q = [] sum_b = 0 sum_c = 0 for a, b, c in ABC_rev[:Y]: heappush(q, (b - c, b)) sum_b += b B = [0] * (Z + 1) RC = [0] * (Z + 1) B[0] += sum_b for i, (a, b, c) in enumerate(ABC_rev[Y : Y + Z], 1): sum_b += b x, del_b = heappushpop(q, (b - c, b)) sum_b -= del_b sum_c += del_b - x B[i] = sum_b RC[i] = sum_c answer = max(sum(x) for x in zip(A, LC, B[::-1], RC[::-1])) print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from heapq import heappop, heappush, heappushpop X, Y, Z = list(map(int, readline().split())) m = list(map(int, read().split())) ABC = sorted(zip(m, m, m), key=lambda x: x[1] - x[0]) # 手前は A or C, 後半はB or Cでとるようにする # A or Cで、AをX個とるルール AC = [0] * (X + Y + Z) q = [] # a -> cと変更する利点をマイナスで格納する S = 0 for i, (a, b, c) in enumerate(ABC): S += a d = a - c if len(q) < X: heappush(q, d) else: S -= heappushpop(q, d) AC[i] = S # B or Cで、BをY個とるルール BC = [0] * (X + Y + Z) q = [] # b -> cと変更する利点をマイナスで格納する S = 0 for i, (a, b, c) in enumerate(ABC[::-1]): S += b d = b - c if len(q) < Y: heappush(q, d) else: S -= heappushpop(q, d) BC[i] = S BC = BC[::-1] answer = max(x + y for x, y in zip(AC[X - 1 : X + Z], BC[X:])) print(answer)
false
25
[ "-input = sys.stdin.readline", "-from heapq import heappush, heappushpop", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+from heapq import heappop, heappush, heappushpop", "-\"\"\"", "-銅貨の集合を固定すると、金-銀でソートして貪欲に金をとることになる", "-逆に金-銀でソートしておくと、金が埋まるまでは金or銅の2択", "-最後にとる金の番号X+nをfix → 手前は金-銅で貪欲 → queueで管理できる", "-\"\"\"", "-X, Y, Z = list(map(int, input().split()))", "-ABC = [[int(x) for x in input().split()] for _ in range(X + Y + Z)]", "-ABC.sort(key=lambda x: x[0] - x[1], reverse=True)", "-q = []", "-sum_a = 0", "-sum_c = 0", "-for a, b, c in ABC[:X]:", "- # 金を入れる。銅-金の優先度", "- heappush(q, (a - c, a))", "- sum_a += a", "-A = [0] * (Z + 1)", "-LC = [0] * (Z + 1)", "-A[0] = sum_a", "-for i, (a, b, c) in enumerate(ABC[X : X + Z], 1):", "- sum_a += a", "- x, del_a = heappushpop(q, (a - c, a))", "- sum_a -= del_a", "- sum_c += del_a - x", "- A[i] = sum_a", "- LC[i] = sum_c", "-ABC_rev = ABC[::-1]", "-q = []", "-sum_b = 0", "-sum_c = 0", "-for a, b, c in ABC_rev[:Y]:", "- heappush(q, (b - c, b))", "- sum_b += b", "-B = [0] * (Z + 1)", "-RC = [0] * (Z + 1)", "-B[0] += sum_b", "-for i, (a, b, c) in enumerate(ABC_rev[Y : Y + Z], 1):", "- sum_b += b", "- x, del_b = heappushpop(q, (b - c, b))", "- sum_b -= del_b", "- sum_c += del_b - x", "- B[i] = sum_b", "- RC[i] = sum_c", "-answer = max(sum(x) for x in zip(A, LC, B[::-1], RC[::-1]))", "+X, Y, Z = list(map(int, readline().split()))", "+m = list(map(int, read().split()))", "+ABC = sorted(zip(m, m, m), key=lambda x: x[1] - x[0])", "+# 手前は A or C, 後半はB or Cでとるようにする", "+# A or Cで、AをX個とるルール", "+AC = [0] * (X + Y + Z)", "+q = [] # a -> cと変更する利点をマイナスで格納する", "+S = 0", "+for i, (a, b, c) in enumerate(ABC):", "+ S += a", "+ d = a - c", "+ if len(q) < X:", "+ heappush(q, d)", "+ else:", "+ S -= heappushpop(q, d)", "+ AC[i] = S", "+# B or Cで、BをY個とるルール", "+BC = [0] * (X + Y + Z)", "+q = [] # b -> cと変更する利点をマイナスで格納する", "+S = 0", "+for i, (a, b, c) in enumerate(ABC[::-1]):", "+ S += b", "+ d = b - c", "+ if len(q) < Y:", "+ heappush(q, d)", "+ else:", "+ S -= heappushpop(q, d)", "+ BC[i] = S", "+BC = BC[::-1]", "+answer = max(x + y for x, y in zip(AC[X - 1 : X + Z], BC[X:]))" ]
false
0.034427
0.042547
0.809155
[ "s045529798", "s556606486" ]
u723792785
p02577
python
s731867868
s645678204
356
204
81,396
9,192
Accepted
Accepted
42.7
n = eval(input()) ans = 0 for j in n: ans += int(j) if ans % 9 == 0: print("Yes") else: print("No")
n = int(eval(input())) if n % 9 == 0: print("Yes") else: print("No")
8
5
103
70
n = eval(input()) ans = 0 for j in n: ans += int(j) if ans % 9 == 0: print("Yes") else: print("No")
n = int(eval(input())) if n % 9 == 0: print("Yes") else: print("No")
false
37.5
[ "-n = eval(input())", "-ans = 0", "-for j in n:", "- ans += int(j)", "-if ans % 9 == 0:", "+n = int(eval(input()))", "+if n % 9 == 0:" ]
false
0.108671
0.093331
1.164351
[ "s731867868", "s645678204" ]
u149260203
p03363
python
s673866124
s934507407
256
226
25,720
39,508
Accepted
Accepted
11.72
N = int(eval(input())) A = [int(i) for i in input().split()] ca = [A[0]] + [0]*(N-1) for i in range(1,N): ca[i] = ca[i-1] + A[i] count = 1 number = 0 number += ca.count(0) sca = sorted(ca) + ['hoge'] for i in range(1,N+1): if sca[i] == sca[i-1]: count += 1 else: number += count*(count - 1)/2 count = 1 print((int(number)))
N = int(eval(input())) A = [int(i) for i in input().split()] dic = {} S = 0 dic[0] = 1 for i in range(N): S += A[i] if S in dic: dic[S] += 1 else: dic[S] = 1 number = 0 for i in dic: N = dic[i] number += N * (N - 1) / 2 print((int(number)))
20
21
374
294
N = int(eval(input())) A = [int(i) for i in input().split()] ca = [A[0]] + [0] * (N - 1) for i in range(1, N): ca[i] = ca[i - 1] + A[i] count = 1 number = 0 number += ca.count(0) sca = sorted(ca) + ["hoge"] for i in range(1, N + 1): if sca[i] == sca[i - 1]: count += 1 else: number += count * (count - 1) / 2 count = 1 print((int(number)))
N = int(eval(input())) A = [int(i) for i in input().split()] dic = {} S = 0 dic[0] = 1 for i in range(N): S += A[i] if S in dic: dic[S] += 1 else: dic[S] = 1 number = 0 for i in dic: N = dic[i] number += N * (N - 1) / 2 print((int(number)))
false
4.761905
[ "-ca = [A[0]] + [0] * (N - 1)", "-for i in range(1, N):", "- ca[i] = ca[i - 1] + A[i]", "-count = 1", "+dic = {}", "+S = 0", "+dic[0] = 1", "+for i in range(N):", "+ S += A[i]", "+ if S in dic:", "+ dic[S] += 1", "+ else:", "+ dic[S] = 1", "-number += ca.count(0)", "-sca = sorted(ca) + [\"hoge\"]", "-for i in range(1, N + 1):", "- if sca[i] == sca[i - 1]:", "- count += 1", "- else:", "- number += count * (count - 1) / 2", "- count = 1", "+for i in dic:", "+ N = dic[i]", "+ number += N * (N - 1) / 2" ]
false
0.045552
0.048832
0.932831
[ "s673866124", "s934507407" ]
u332906195
p02755
python
s651798002
s310851820
19
17
2,940
2,940
Accepted
Accepted
10.53
A, B = list(map(int, input().split())) for i in range(10101): if i * 8 // 100 == A and i * 10 // 100 == B: print(i) exit() print((-1))
A, B = list(map(int, input().split())) for i in range(1011): if i * 8 // 100 == A and i * 10 // 100 == B: print(i) exit() print((-1))
6
6
152
151
A, B = list(map(int, input().split())) for i in range(10101): if i * 8 // 100 == A and i * 10 // 100 == B: print(i) exit() print((-1))
A, B = list(map(int, input().split())) for i in range(1011): if i * 8 // 100 == A and i * 10 // 100 == B: print(i) exit() print((-1))
false
0
[ "-for i in range(10101):", "+for i in range(1011):" ]
false
0.04914
0.048654
1.009982
[ "s651798002", "s310851820" ]
u581187895
p02953
python
s497251406
s671431923
88
61
14,396
15,020
Accepted
Accepted
30.68
N = int(eval(input())) H = list(map(int, input().split())) for i in range(N-2, 0, -1): if H[i] > H[i+1]+1: print("No") exit() elif H[i] == H[i+1]+1: H[i] -= 1 print("Yes")
N = int(eval(input())) H = list(map(int, input().split())) prev = -1 flag = True for x in H: if x < prev: flag = False break if x == prev: continue prev = x - 1 print(("Yes" if flag else "No"))
12
14
208
222
N = int(eval(input())) H = list(map(int, input().split())) for i in range(N - 2, 0, -1): if H[i] > H[i + 1] + 1: print("No") exit() elif H[i] == H[i + 1] + 1: H[i] -= 1 print("Yes")
N = int(eval(input())) H = list(map(int, input().split())) prev = -1 flag = True for x in H: if x < prev: flag = False break if x == prev: continue prev = x - 1 print(("Yes" if flag else "No"))
false
14.285714
[ "-for i in range(N - 2, 0, -1):", "- if H[i] > H[i + 1] + 1:", "- print(\"No\")", "- exit()", "- elif H[i] == H[i + 1] + 1:", "- H[i] -= 1", "-print(\"Yes\")", "+prev = -1", "+flag = True", "+for x in H:", "+ if x < prev:", "+ flag = False", "+ break", "+ if x == prev:", "+ continue", "+ prev = x - 1", "+print((\"Yes\" if flag else \"No\"))" ]
false
0.081057
0.033581
2.413819
[ "s497251406", "s671431923" ]
u784022244
p03108
python
s739528589
s231964713
839
433
23,660
94,100
Accepted
Accepted
48.39
N,M=list(map(int, input().split())) B=[] class UnionFind(): # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1]*(n+1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0]*(n+1) # ノードxのrootノードを見つける def Find_Root(self, x): if(self.root[x] < 0): return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if (x == y): return # 違う木に属していた場合rnkを見てくっつける方を決める #rnkが大きい方に結合 elif (self.rnk[x] > self.rnk[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if(self.rnk[x] == self.rnk[y]): self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] for i in range(M): a,b=list(map(int, input().split())) B.append((a-1,b-1)) B=B[::-1] uni=UnionFind(N) now=N*(N-1)//2 ans=[] for t in B: ans.append(now) a,b=t if uni.isSameGroup(a,b): uni.Unite(a,b) else: A=uni.Count(a) B=uni.Count(b) now-=(A*B) uni.Unite(a,b) for a in ans[::-1]: print(a)
N,M=list(map(int, input().split())) L=[] for i in range(M): a,b=list(map(int, input().split())) L.append((a-1,b-1)) class UnionFind(): # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1]*(n+1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0]*(n+1) # ノードxのrootノードを見つける def Find_Root(self, x): if(self.root[x] < 0): return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if (x == y): return # 違う木に属していた場合rnkを見てくっつける方を決める #rnkが大きい方に結合 elif (self.rnk[x] > self.rnk[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if(self.rnk[x] == self.rnk[y]): self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] uni=UnionFind(N) L=L[::-1] ans=[N*(N-1)//2] for i in range(0,M): a,b=L[i] size_a=uni.Count(a) size_b=uni.Count(b) if i!=M-1: if not uni.isSameGroup(a,b): ans.append(ans[-1]-size_a*size_b) else: ans.append(ans[-1]) uni.Unite(a,b) ans=ans[::-1] for a in ans: print(a)
73
76
1,572
1,809
N, M = list(map(int, input().split())) B = [] class UnionFind: # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1] * (n + 1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0] * (n + 1) # ノードxのrootノードを見つける def Find_Root(self, x): if self.root[x] < 0: return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if x == y: return # 違う木に属していた場合rnkを見てくっつける方を決める # rnkが大きい方に結合 elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] for i in range(M): a, b = list(map(int, input().split())) B.append((a - 1, b - 1)) B = B[::-1] uni = UnionFind(N) now = N * (N - 1) // 2 ans = [] for t in B: ans.append(now) a, b = t if uni.isSameGroup(a, b): uni.Unite(a, b) else: A = uni.Count(a) B = uni.Count(b) now -= A * B uni.Unite(a, b) for a in ans[::-1]: print(a)
N, M = list(map(int, input().split())) L = [] for i in range(M): a, b = list(map(int, input().split())) L.append((a - 1, b - 1)) class UnionFind: # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1] * (n + 1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0] * (n + 1) # ノードxのrootノードを見つける def Find_Root(self, x): if self.root[x] < 0: return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if x == y: return # 違う木に属していた場合rnkを見てくっつける方を決める # rnkが大きい方に結合 elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] uni = UnionFind(N) L = L[::-1] ans = [N * (N - 1) // 2] for i in range(0, M): a, b = L[i] size_a = uni.Count(a) size_b = uni.Count(b) if i != M - 1: if not uni.isSameGroup(a, b): ans.append(ans[-1] - size_a * size_b) else: ans.append(ans[-1]) uni.Unite(a, b) ans = ans[::-1] for a in ans: print(a)
false
3.947368
[ "-B = []", "+L = []", "+for i in range(M):", "+ a, b = list(map(int, input().split()))", "+ L.append((a - 1, b - 1))", "- # ノードxのrootノードを見つける", "+ # ノードxのrootノードを見つける", "- return self.root[x]", "- # 木の併合、入力は併合したい各ノード", "+ return self.root[x]", "+ # 木の併合、入力は併合したい各ノード", "- # 違う木に属していた場合rnkを見てくっつける方を決める", "- # rnkが大きい方に結合", "+ # 違う木に属していた場合rnkを見てくっつける方を決める", "+ # rnkが大きい方に結合", "- # rnkが同じ(深さに差がない場合)は1増やす", "- if self.rnk[x] == self.rnk[y]:", "- self.rnk[y] += 1", "+ # rnkが同じ(深さに差がない場合)は1増やす", "+ if self.rnk[x] == self.rnk[y]:", "+ self.rnk[y] += 1", "-for i in range(M):", "- a, b = list(map(int, input().split()))", "- B.append((a - 1, b - 1))", "-B = B[::-1]", "-now = N * (N - 1) // 2", "-ans = []", "-for t in B:", "- ans.append(now)", "- a, b = t", "- if uni.isSameGroup(a, b):", "- uni.Unite(a, b)", "- else:", "- A = uni.Count(a)", "- B = uni.Count(b)", "- now -= A * B", "- uni.Unite(a, b)", "-for a in ans[::-1]:", "+L = L[::-1]", "+ans = [N * (N - 1) // 2]", "+for i in range(0, M):", "+ a, b = L[i]", "+ size_a = uni.Count(a)", "+ size_b = uni.Count(b)", "+ if i != M - 1:", "+ if not uni.isSameGroup(a, b):", "+ ans.append(ans[-1] - size_a * size_b)", "+ else:", "+ ans.append(ans[-1])", "+ uni.Unite(a, b)", "+ans = ans[::-1]", "+for a in ans:" ]
false
0.036682
0.036226
1.012592
[ "s739528589", "s231964713" ]
u806976856
p02579
python
s712584901
s597550335
959
876
143,104
142,728
Accepted
Accepted
8.65
from _collections import deque h,w=list(map(int,input().split())) cx,cy=list(map(int,input().split())) dx,dy=list(map(int,input().split())) s=[[] for _ in range(h+2)] for i in range(h): x=list(eval(input())) x.insert(0,"#") x.append("#") s[i+1]=x s[0]=s[-1]=["#"]*(w+2) dep=[[10**10]*(w+2) for _ in range(h+2)] dep[cx][cy]=0 data=deque([[cx,cy]]) data2=deque([]) while len(data)>0: while len(data)>0: xy=data.popleft() x,y=xy[0],xy[1] data2.append([x,y]) if s[x-1][y]=="." and dep[x-1][y]>dep[x][y]: dep[x-1][y]=dep[x][y] data.append([x-1,y]) if s[x+1][y] == "." and dep[x+1][y] > dep[x][y]: dep[x+1][y] = dep[x][y] data.append([x + 1,y]) if s[x][y-1] == "." and dep[x][y-1] > dep[x][y]: dep[x][y-1] = dep[x][y] data.append([x,y-1]) if s[x][y+1] == "." and dep[x][y+1] > dep[x][y]: dep[x][y+1] = dep[x][y] data.append([x,y+1]) while len(data2)>0: xy=data2.popleft() x,y=xy[0],xy[1] for i in range(5): for j in range(5): if 0<=x-2+i<=h+1 and 0<=y-2+j<=w+1 and s[x-2+i][y-2+j]=="." and dep[x-2+i][y-2+j]>dep[x][y]+1: dep[x-2+i][y-2+j]=dep[x][y]+1 data.append([x-2+i,y-2+j]) print((dep[dx][dy] if dep[dx][dy]<10**10 else -1))
from _collections import deque h,w=list(map(int,input().split())) cx,cy=list(map(int,input().split())) dx,dy=list(map(int,input().split())) s=[[] for _ in range(h+2)] for i in range(h): x=list(eval(input())) x.insert(0,"#") x.append("#") s[i+1]=x s[0]=s[-1]=["#"]*(w+2) dep=[[10**10]*(w+2) for _ in range(h+2)] dep[cx][cy]=0 data=deque([[cx,cy,0]]) while len(data)>0: xy=data.popleft() x,y=xy[0],xy[1] if xy[2]==dep[x][y]: if s[x-1][y]=="." and dep[x-1][y]>dep[x][y]: dep[x-1][y]=dep[x][y] data.appendleft([x-1,y,dep[x][y]]) if s[x+1][y] == "." and dep[x+1][y] > dep[x][y]: dep[x+1][y] = dep[x][y] data.appendleft([x + 1,y,dep[x][y]]) if s[x][y-1] == "." and dep[x][y-1] > dep[x][y]: dep[x][y-1] = dep[x][y] data.appendleft([x,y-1,dep[x][y]]) if s[x][y+1] == "." and dep[x][y+1] > dep[x][y]: dep[x][y+1] = dep[x][y] data.appendleft([x,y+1,dep[x][y]]) for i in range(5): for j in range(5): if 0<=x-2+i<=h+1 and 0<=y-2+j<=w+1 and s[x-2+i][y-2+j]=="." and dep[x-2+i][y-2+j]>dep[x][y]+1: dep[x-2+i][y-2+j]=dep[x][y]+1 data.append([x-2+i,y-2+j,dep[x][y]+1]) print((dep[dx][dy] if dep[dx][dy]<10**10 else -1))
50
48
1,423
1,295
from _collections import deque h, w = list(map(int, input().split())) cx, cy = list(map(int, input().split())) dx, dy = list(map(int, input().split())) s = [[] for _ in range(h + 2)] for i in range(h): x = list(eval(input())) x.insert(0, "#") x.append("#") s[i + 1] = x s[0] = s[-1] = ["#"] * (w + 2) dep = [[10**10] * (w + 2) for _ in range(h + 2)] dep[cx][cy] = 0 data = deque([[cx, cy]]) data2 = deque([]) while len(data) > 0: while len(data) > 0: xy = data.popleft() x, y = xy[0], xy[1] data2.append([x, y]) if s[x - 1][y] == "." and dep[x - 1][y] > dep[x][y]: dep[x - 1][y] = dep[x][y] data.append([x - 1, y]) if s[x + 1][y] == "." and dep[x + 1][y] > dep[x][y]: dep[x + 1][y] = dep[x][y] data.append([x + 1, y]) if s[x][y - 1] == "." and dep[x][y - 1] > dep[x][y]: dep[x][y - 1] = dep[x][y] data.append([x, y - 1]) if s[x][y + 1] == "." and dep[x][y + 1] > dep[x][y]: dep[x][y + 1] = dep[x][y] data.append([x, y + 1]) while len(data2) > 0: xy = data2.popleft() x, y = xy[0], xy[1] for i in range(5): for j in range(5): if ( 0 <= x - 2 + i <= h + 1 and 0 <= y - 2 + j <= w + 1 and s[x - 2 + i][y - 2 + j] == "." and dep[x - 2 + i][y - 2 + j] > dep[x][y] + 1 ): dep[x - 2 + i][y - 2 + j] = dep[x][y] + 1 data.append([x - 2 + i, y - 2 + j]) print((dep[dx][dy] if dep[dx][dy] < 10**10 else -1))
from _collections import deque h, w = list(map(int, input().split())) cx, cy = list(map(int, input().split())) dx, dy = list(map(int, input().split())) s = [[] for _ in range(h + 2)] for i in range(h): x = list(eval(input())) x.insert(0, "#") x.append("#") s[i + 1] = x s[0] = s[-1] = ["#"] * (w + 2) dep = [[10**10] * (w + 2) for _ in range(h + 2)] dep[cx][cy] = 0 data = deque([[cx, cy, 0]]) while len(data) > 0: xy = data.popleft() x, y = xy[0], xy[1] if xy[2] == dep[x][y]: if s[x - 1][y] == "." and dep[x - 1][y] > dep[x][y]: dep[x - 1][y] = dep[x][y] data.appendleft([x - 1, y, dep[x][y]]) if s[x + 1][y] == "." and dep[x + 1][y] > dep[x][y]: dep[x + 1][y] = dep[x][y] data.appendleft([x + 1, y, dep[x][y]]) if s[x][y - 1] == "." and dep[x][y - 1] > dep[x][y]: dep[x][y - 1] = dep[x][y] data.appendleft([x, y - 1, dep[x][y]]) if s[x][y + 1] == "." and dep[x][y + 1] > dep[x][y]: dep[x][y + 1] = dep[x][y] data.appendleft([x, y + 1, dep[x][y]]) for i in range(5): for j in range(5): if ( 0 <= x - 2 + i <= h + 1 and 0 <= y - 2 + j <= w + 1 and s[x - 2 + i][y - 2 + j] == "." and dep[x - 2 + i][y - 2 + j] > dep[x][y] + 1 ): dep[x - 2 + i][y - 2 + j] = dep[x][y] + 1 data.append([x - 2 + i, y - 2 + j, dep[x][y] + 1]) print((dep[dx][dy] if dep[dx][dy] < 10**10 else -1))
false
4
[ "-data = deque([[cx, cy]])", "-data2 = deque([])", "+data = deque([[cx, cy, 0]])", "- while len(data) > 0:", "- xy = data.popleft()", "- x, y = xy[0], xy[1]", "- data2.append([x, y])", "+ xy = data.popleft()", "+ x, y = xy[0], xy[1]", "+ if xy[2] == dep[x][y]:", "- data.append([x - 1, y])", "+ data.appendleft([x - 1, y, dep[x][y]])", "- data.append([x + 1, y])", "+ data.appendleft([x + 1, y, dep[x][y]])", "- data.append([x, y - 1])", "+ data.appendleft([x, y - 1, dep[x][y]])", "- data.append([x, y + 1])", "- while len(data2) > 0:", "- xy = data2.popleft()", "- x, y = xy[0], xy[1]", "+ data.appendleft([x, y + 1, dep[x][y]])", "- data.append([x - 2 + i, y - 2 + j])", "+ data.append([x - 2 + i, y - 2 + j, dep[x][y] + 1])" ]
false
0.048793
0.045216
1.079118
[ "s712584901", "s597550335" ]
u796942881
p02953
python
s876988491
s886996167
57
47
11,200
11,200
Accepted
Accepted
17.54
def main(): H = list(map(int, open(0).read().split()[:1:-1])) pre = None for h in H: if pre is None: pre = h if pre + 1 < h: print("No") return if pre + 1 == h: pre = h - 1 else: pre = h print("Yes") return main()
def main(): H = list(map(int, open(0).read().split()[:1:-1])) pre = None for h in H: if pre is None: pre = h elif h <= pre: pre = h elif pre + 1 == h: continue else: # pre + 1 < h print("No") return print("Yes") return main()
19
20
341
366
def main(): H = list(map(int, open(0).read().split()[:1:-1])) pre = None for h in H: if pre is None: pre = h if pre + 1 < h: print("No") return if pre + 1 == h: pre = h - 1 else: pre = h print("Yes") return main()
def main(): H = list(map(int, open(0).read().split()[:1:-1])) pre = None for h in H: if pre is None: pre = h elif h <= pre: pre = h elif pre + 1 == h: continue else: # pre + 1 < h print("No") return print("Yes") return main()
false
5
[ "- if pre + 1 < h:", "+ elif h <= pre:", "+ pre = h", "+ elif pre + 1 == h:", "+ continue", "+ else:", "+ # pre + 1 < h", "- if pre + 1 == h:", "- pre = h - 1", "- else:", "- pre = h" ]
false
0.047164
0.119393
0.395029
[ "s876988491", "s886996167" ]
u426534722
p02234
python
s385446306
s407250712
220
200
5,672
5,672
Accepted
Accepted
9.09
import sys INF = float("inf") n = int(eval(input())) A = [0] for i, a in enumerate(sys.stdin): a = list(map(int, a.split())) if i == 0: A.extend(a) else: A.append(a[1]) C = [[INF] * (n + 1) for _ in range(n + 1)] for i in range(n + 1): C[i][i] = 0 for j in range(1, n): for i in range(1, n - j + 1): for k in range(i + 1, i + j + 1): cost = C[i][k - 1] + C[k][i + j] + A[i] * A[k] * A[i + j + 1] if cost < C[i][i + j]: C[i][i + j] = cost print((C[1][n]))
INF = float("inf") MAX = 101 n = int(eval(input())) z = [] m = [[0] * MAX for _ in range(MAX)] for i in range(1, n + 1): a, b = list(map(int, input().split())) z.append(a) z.append(b) for l in range(2, n + 1): for i in range(1, n - l + 2): j = i + l - 1 m[i][j] = INF for k in range(i, j): m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j]) print((m[1][n]))
21
17
552
429
import sys INF = float("inf") n = int(eval(input())) A = [0] for i, a in enumerate(sys.stdin): a = list(map(int, a.split())) if i == 0: A.extend(a) else: A.append(a[1]) C = [[INF] * (n + 1) for _ in range(n + 1)] for i in range(n + 1): C[i][i] = 0 for j in range(1, n): for i in range(1, n - j + 1): for k in range(i + 1, i + j + 1): cost = C[i][k - 1] + C[k][i + j] + A[i] * A[k] * A[i + j + 1] if cost < C[i][i + j]: C[i][i + j] = cost print((C[1][n]))
INF = float("inf") MAX = 101 n = int(eval(input())) z = [] m = [[0] * MAX for _ in range(MAX)] for i in range(1, n + 1): a, b = list(map(int, input().split())) z.append(a) z.append(b) for l in range(2, n + 1): for i in range(1, n - l + 2): j = i + l - 1 m[i][j] = INF for k in range(i, j): m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j]) print((m[1][n]))
false
19.047619
[ "-import sys", "-", "+MAX = 101", "-A = [0]", "-for i, a in enumerate(sys.stdin):", "- a = list(map(int, a.split()))", "- if i == 0:", "- A.extend(a)", "- else:", "- A.append(a[1])", "-C = [[INF] * (n + 1) for _ in range(n + 1)]", "-for i in range(n + 1):", "- C[i][i] = 0", "-for j in range(1, n):", "- for i in range(1, n - j + 1):", "- for k in range(i + 1, i + j + 1):", "- cost = C[i][k - 1] + C[k][i + j] + A[i] * A[k] * A[i + j + 1]", "- if cost < C[i][i + j]:", "- C[i][i + j] = cost", "-print((C[1][n]))", "+z = []", "+m = [[0] * MAX for _ in range(MAX)]", "+for i in range(1, n + 1):", "+ a, b = list(map(int, input().split()))", "+ z.append(a)", "+z.append(b)", "+for l in range(2, n + 1):", "+ for i in range(1, n - l + 2):", "+ j = i + l - 1", "+ m[i][j] = INF", "+ for k in range(i, j):", "+ m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j])", "+print((m[1][n]))" ]
false
0.040059
0.03798
1.05474
[ "s385446306", "s407250712" ]
u035907840
p03182
python
s799809740
s545621358
1,950
1,725
123,944
123,396
Accepted
Accepted
11.54
N, M = list(map(int,input().split())) interval=[[] for i in range(N)] for i in range(M): l, r, a = list(map(int,input().split())) interval[l-1].append((r-1, a)) # N: 処理する区間の長さ INF = 10**30-1 LV = (N-1).bit_length() N0 = 2**LV data = [0]*(2*N0) lazy = [0]*(2*N0) def gindex(l, r): L = (l + N0) >> 1; R = (r + N0) >> 1 lc = 0 if l & 1 else (L & -L).bit_length() rc = 0 if r & 1 else (R & -R).bit_length() for i in range(LV): if rc <= i: yield R if L < R and lc <= i: yield L L >>= 1; R >>= 1 # 遅延伝搬処理 def propagates(*ids): for i in reversed(ids): v = lazy[i-1] if not v: continue lazy[2*i-1] += v; lazy[2*i] += v data[2*i-1] += v; data[2*i] += v lazy[i-1] = 0 # 区間[l, r)にxを加算 def update(l, r, x): *ids, = gindex(l, r) propagates(*ids) L = N0 + l; R = N0 + r while L < R: if R & 1: R -= 1 lazy[R-1] += x; data[R-1] += x if L & 1: lazy[L-1] += x; data[L-1] += x L += 1 L >>= 1; R >>= 1 for i in ids: data[i-1] = max(data[2*i-1], data[2*i]) # 区間[l, r)内の最大値を求める def query(l, r): propagates(*gindex(l, r)) L = N0 + l; R = N0 + r s = -INF while L < R: if R & 1: R -= 1 s = max(s, data[R-1]) if L & 1: s = max(s, data[L-1]) L += 1 L >>= 1; R >>= 1 return s dp=[0]*N for i in range(N-1, -1, -1): for j in range(len(interval[i])): r, a = interval[i][j] update(i, r+1, a) dp[i] = max(query(0, N), 0) if i>0: update(i-1, i, dp[i]) print((dp[0]))
N, M = list(map(int,input().split())) interval=[[] for i in range(N)] for i in range(M): l, r, a = list(map(int,input().split())) interval[r-1].append((l-1, a)) # N: 処理する区間の長さ INF = 10**30-1 LV = (N-1).bit_length() N0 = 2**LV data = [0]*(2*N0) lazy = [0]*(2*N0) def gindex(l, r): L = (l + N0) >> 1; R = (r + N0) >> 1 lc = 0 if l & 1 else (L & -L).bit_length() rc = 0 if r & 1 else (R & -R).bit_length() for i in range(LV): if rc <= i: yield R if L < R and lc <= i: yield L L >>= 1; R >>= 1 # 遅延伝搬処理 def propagates(*ids): for i in reversed(ids): v = lazy[i-1] if not v: continue lazy[2*i-1] += v; lazy[2*i] += v data[2*i-1] += v; data[2*i] += v lazy[i-1] = 0 # 区間[l, r)にxを加算 def update(l, r, x): *ids, = gindex(l, r) propagates(*ids) L = N0 + l; R = N0 + r while L < R: if R & 1: R -= 1 lazy[R-1] += x; data[R-1] += x if L & 1: lazy[L-1] += x; data[L-1] += x L += 1 L >>= 1; R >>= 1 for i in ids: data[i-1] = max(data[2*i-1], data[2*i]) # 区間[l, r)内の最大値を求める def query(l, r): propagates(*gindex(l, r)) L = N0 + l; R = N0 + r s = -INF while L < R: if R & 1: R -= 1 s = max(s, data[R-1]) if L & 1: s = max(s, data[L-1]) L += 1 L >>= 1; R >>= 1 return s dp=[0]*N # dp[i] = max upto i. SegTree maintans max s.t. rightmost 1 is at i for i in range(N): for j in range(len(interval[i])): l, a = interval[i][j] update(l, i+1, a) dp[i] = max(query(0, i+1), 0) update(i+1, i+2, dp[i]) # write "max up to i" at i+1 so that, in the next step, updates yields "max s.t. rightmost 1 is at i+1" print((dp[-1]))
79
78
1,764
1,913
N, M = list(map(int, input().split())) interval = [[] for i in range(N)] for i in range(M): l, r, a = list(map(int, input().split())) interval[l - 1].append((r - 1, a)) # N: 処理する区間の長さ INF = 10**30 - 1 LV = (N - 1).bit_length() N0 = 2**LV data = [0] * (2 * N0) lazy = [0] * (2 * N0) def gindex(l, r): L = (l + N0) >> 1 R = (r + N0) >> 1 lc = 0 if l & 1 else (L & -L).bit_length() rc = 0 if r & 1 else (R & -R).bit_length() for i in range(LV): if rc <= i: yield R if L < R and lc <= i: yield L L >>= 1 R >>= 1 # 遅延伝搬処理 def propagates(*ids): for i in reversed(ids): v = lazy[i - 1] if not v: continue lazy[2 * i - 1] += v lazy[2 * i] += v data[2 * i - 1] += v data[2 * i] += v lazy[i - 1] = 0 # 区間[l, r)にxを加算 def update(l, r, x): (*ids,) = gindex(l, r) propagates(*ids) L = N0 + l R = N0 + r while L < R: if R & 1: R -= 1 lazy[R - 1] += x data[R - 1] += x if L & 1: lazy[L - 1] += x data[L - 1] += x L += 1 L >>= 1 R >>= 1 for i in ids: data[i - 1] = max(data[2 * i - 1], data[2 * i]) # 区間[l, r)内の最大値を求める def query(l, r): propagates(*gindex(l, r)) L = N0 + l R = N0 + r s = -INF while L < R: if R & 1: R -= 1 s = max(s, data[R - 1]) if L & 1: s = max(s, data[L - 1]) L += 1 L >>= 1 R >>= 1 return s dp = [0] * N for i in range(N - 1, -1, -1): for j in range(len(interval[i])): r, a = interval[i][j] update(i, r + 1, a) dp[i] = max(query(0, N), 0) if i > 0: update(i - 1, i, dp[i]) print((dp[0]))
N, M = list(map(int, input().split())) interval = [[] for i in range(N)] for i in range(M): l, r, a = list(map(int, input().split())) interval[r - 1].append((l - 1, a)) # N: 処理する区間の長さ INF = 10**30 - 1 LV = (N - 1).bit_length() N0 = 2**LV data = [0] * (2 * N0) lazy = [0] * (2 * N0) def gindex(l, r): L = (l + N0) >> 1 R = (r + N0) >> 1 lc = 0 if l & 1 else (L & -L).bit_length() rc = 0 if r & 1 else (R & -R).bit_length() for i in range(LV): if rc <= i: yield R if L < R and lc <= i: yield L L >>= 1 R >>= 1 # 遅延伝搬処理 def propagates(*ids): for i in reversed(ids): v = lazy[i - 1] if not v: continue lazy[2 * i - 1] += v lazy[2 * i] += v data[2 * i - 1] += v data[2 * i] += v lazy[i - 1] = 0 # 区間[l, r)にxを加算 def update(l, r, x): (*ids,) = gindex(l, r) propagates(*ids) L = N0 + l R = N0 + r while L < R: if R & 1: R -= 1 lazy[R - 1] += x data[R - 1] += x if L & 1: lazy[L - 1] += x data[L - 1] += x L += 1 L >>= 1 R >>= 1 for i in ids: data[i - 1] = max(data[2 * i - 1], data[2 * i]) # 区間[l, r)内の最大値を求める def query(l, r): propagates(*gindex(l, r)) L = N0 + l R = N0 + r s = -INF while L < R: if R & 1: R -= 1 s = max(s, data[R - 1]) if L & 1: s = max(s, data[L - 1]) L += 1 L >>= 1 R >>= 1 return s dp = [0] * N # dp[i] = max upto i. SegTree maintans max s.t. rightmost 1 is at i for i in range(N): for j in range(len(interval[i])): l, a = interval[i][j] update(l, i + 1, a) dp[i] = max(query(0, i + 1), 0) update( i + 1, i + 2, dp[i] ) # write "max up to i" at i+1 so that, in the next step, updates yields "max s.t. rightmost 1 is at i+1" print((dp[-1]))
false
1.265823
[ "- interval[l - 1].append((r - 1, a))", "+ interval[r - 1].append((l - 1, a))", "-dp = [0] * N", "-for i in range(N - 1, -1, -1):", "+dp = [0] * N # dp[i] = max upto i. SegTree maintans max s.t. rightmost 1 is at i", "+for i in range(N):", "- r, a = interval[i][j]", "- update(i, r + 1, a)", "- dp[i] = max(query(0, N), 0)", "- if i > 0:", "- update(i - 1, i, dp[i])", "-print((dp[0]))", "+ l, a = interval[i][j]", "+ update(l, i + 1, a)", "+ dp[i] = max(query(0, i + 1), 0)", "+ update(", "+ i + 1, i + 2, dp[i]", "+ ) # write \"max up to i\" at i+1 so that, in the next step, updates yields \"max s.t. rightmost 1 is at i+1\"", "+print((dp[-1]))" ]
false
0.047108
0.042076
1.119594
[ "s799809740", "s545621358" ]
u164727245
p02603
python
s293149293
s839212084
33
28
8,892
9,208
Accepted
Accepted
15.15
# coding: utf-8 def solve(*args: str) -> str: n = int(args[0]) A = list(map(int, args[1].split())) budget = 1000 stock = 0 temp = 0 for i in range(n-1): if A[i] < A[i+1] and A[i] <= temp+budget: budget += temp temp = 0 stock = budget//A[i] budget %= A[i] elif A[i+1] < A[i]: budget += A[i]*stock stock = 0 return str(A[-1]*stock+budget) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
# coding: utf-8 def solve(*args: str) -> str: n = int(args[0]) A = list(map(int, args[1].split())) budget = 1000 stock = 0 for i in range(n-1): if A[i] < A[i+1] and A[i] <= budget: stock, budget = divmod(budget, A[i]) elif A[i+1] < A[i]: budget += A[i]*stock stock = 0 return str(A[-1]*stock+budget) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
25
21
559
478
# coding: utf-8 def solve(*args: str) -> str: n = int(args[0]) A = list(map(int, args[1].split())) budget = 1000 stock = 0 temp = 0 for i in range(n - 1): if A[i] < A[i + 1] and A[i] <= temp + budget: budget += temp temp = 0 stock = budget // A[i] budget %= A[i] elif A[i + 1] < A[i]: budget += A[i] * stock stock = 0 return str(A[-1] * stock + budget) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
# coding: utf-8 def solve(*args: str) -> str: n = int(args[0]) A = list(map(int, args[1].split())) budget = 1000 stock = 0 for i in range(n - 1): if A[i] < A[i + 1] and A[i] <= budget: stock, budget = divmod(budget, A[i]) elif A[i + 1] < A[i]: budget += A[i] * stock stock = 0 return str(A[-1] * stock + budget) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
false
16
[ "- temp = 0", "- if A[i] < A[i + 1] and A[i] <= temp + budget:", "- budget += temp", "- temp = 0", "- stock = budget // A[i]", "- budget %= A[i]", "+ if A[i] < A[i + 1] and A[i] <= budget:", "+ stock, budget = divmod(budget, A[i])" ]
false
0.03544
0.035335
1.002977
[ "s293149293", "s839212084" ]
u028973125
p03032
python
s841646483
s320049227
213
83
43,496
68,672
Accepted
Accepted
61.03
import sys N, K = list(map(int, sys.stdin.readline().strip().split())) V = list(map(int, sys.stdin.readline().strip().split())) ans=0 act = min(N, K) for i in range(act + 1): # 左 for j in range(N - act + i, N+1): # 右 count = V[0:i] + V[j:N] count.sort() ans = max(ans, sum(count)) for x in range(1, K - len(count) + 1): # 正負関係なく小さいものを捨てる # print(sum(count[x:])) ans = max(ans, sum(count[x:])) print(ans)
import sys N, K = list(map(int, sys.stdin.readline().split())) V = list(map(int, sys.stdin.readline().split())) ans = 0 for i in range(N+1): if K < i: continue score = sum(V[0:i]) # print("i", i, "l score", score) ans = max(ans, score) for j in range(N+1): if N < i + j or K < i + j: continue tmp = score tmp += sum(V[N-j:]) ans = max(ans, tmp) # print("i", i, "j", j, "lr score", tmp) # 捨てる最大個数 k = K - i - j if k < 0: continue negs = [] for n in range(0, i): if V[n] < 0: negs.append(V[n]) for n in range(N-j, N): if V[n] < 0: negs.append(V[n]) negs.sort() # print(negs) tmp -= sum(negs[:k]) ans = max(ans, tmp) # print("i", i, "j", j, "k", k, "lrd score", tmp) print(ans)
16
39
475
947
import sys N, K = list(map(int, sys.stdin.readline().strip().split())) V = list(map(int, sys.stdin.readline().strip().split())) ans = 0 act = min(N, K) for i in range(act + 1): # 左 for j in range(N - act + i, N + 1): # 右 count = V[0:i] + V[j:N] count.sort() ans = max(ans, sum(count)) for x in range(1, K - len(count) + 1): # 正負関係なく小さいものを捨てる # print(sum(count[x:])) ans = max(ans, sum(count[x:])) print(ans)
import sys N, K = list(map(int, sys.stdin.readline().split())) V = list(map(int, sys.stdin.readline().split())) ans = 0 for i in range(N + 1): if K < i: continue score = sum(V[0:i]) # print("i", i, "l score", score) ans = max(ans, score) for j in range(N + 1): if N < i + j or K < i + j: continue tmp = score tmp += sum(V[N - j :]) ans = max(ans, tmp) # print("i", i, "j", j, "lr score", tmp) # 捨てる最大個数 k = K - i - j if k < 0: continue negs = [] for n in range(0, i): if V[n] < 0: negs.append(V[n]) for n in range(N - j, N): if V[n] < 0: negs.append(V[n]) negs.sort() # print(negs) tmp -= sum(negs[:k]) ans = max(ans, tmp) # print("i", i, "j", j, "k", k, "lrd score", tmp) print(ans)
false
58.974359
[ "-N, K = list(map(int, sys.stdin.readline().strip().split()))", "-V = list(map(int, sys.stdin.readline().strip().split()))", "+N, K = list(map(int, sys.stdin.readline().split()))", "+V = list(map(int, sys.stdin.readline().split()))", "-act = min(N, K)", "-for i in range(act + 1): # 左", "- for j in range(N - act + i, N + 1): # 右", "- count = V[0:i] + V[j:N]", "- count.sort()", "- ans = max(ans, sum(count))", "- for x in range(1, K - len(count) + 1): # 正負関係なく小さいものを捨てる", "- # print(sum(count[x:]))", "- ans = max(ans, sum(count[x:]))", "+for i in range(N + 1):", "+ if K < i:", "+ continue", "+ score = sum(V[0:i])", "+ # print(\"i\", i, \"l score\", score)", "+ ans = max(ans, score)", "+ for j in range(N + 1):", "+ if N < i + j or K < i + j:", "+ continue", "+ tmp = score", "+ tmp += sum(V[N - j :])", "+ ans = max(ans, tmp)", "+ # print(\"i\", i, \"j\", j, \"lr score\", tmp)", "+ # 捨てる最大個数", "+ k = K - i - j", "+ if k < 0:", "+ continue", "+ negs = []", "+ for n in range(0, i):", "+ if V[n] < 0:", "+ negs.append(V[n])", "+ for n in range(N - j, N):", "+ if V[n] < 0:", "+ negs.append(V[n])", "+ negs.sort()", "+ # print(negs)", "+ tmp -= sum(negs[:k])", "+ ans = max(ans, tmp)", "+ # print(\"i\", i, \"j\", j, \"k\", k, \"lrd score\", tmp)" ]
false
0.062647
0.082763
0.756943
[ "s841646483", "s320049227" ]
u987164499
p02792
python
s497987870
s776481699
254
212
3,064
3,316
Accepted
Accepted
16.54
from sys import stdin n = int(stdin.readline().rstrip()) li = [[0 for i in range(10)]for j in range(10)] for k in range(1,n+1): atama = int(str(k)[0]) ushiro = int(str(k)[-1]) li[atama][ushiro] += 1 point = 0 for l in range(1,10): for m in range(1,10): point += li[l][m]*li[m][l] print(point)
from collections import defaultdict n = int(eval(input())) dic = defaultdict(int) for i in range(1,n+1): s = str(i) dic[int(s[0]),int(s[-1])] += 1 point = 0 for i in range(1,10): for j in range(1,10): point += dic[i,j]*dic[j,i] print(point)
17
16
337
274
from sys import stdin n = int(stdin.readline().rstrip()) li = [[0 for i in range(10)] for j in range(10)] for k in range(1, n + 1): atama = int(str(k)[0]) ushiro = int(str(k)[-1]) li[atama][ushiro] += 1 point = 0 for l in range(1, 10): for m in range(1, 10): point += li[l][m] * li[m][l] print(point)
from collections import defaultdict n = int(eval(input())) dic = defaultdict(int) for i in range(1, n + 1): s = str(i) dic[int(s[0]), int(s[-1])] += 1 point = 0 for i in range(1, 10): for j in range(1, 10): point += dic[i, j] * dic[j, i] print(point)
false
5.882353
[ "-from sys import stdin", "+from collections import defaultdict", "-n = int(stdin.readline().rstrip())", "-li = [[0 for i in range(10)] for j in range(10)]", "-for k in range(1, n + 1):", "- atama = int(str(k)[0])", "- ushiro = int(str(k)[-1])", "- li[atama][ushiro] += 1", "+n = int(eval(input()))", "+dic = defaultdict(int)", "+for i in range(1, n + 1):", "+ s = str(i)", "+ dic[int(s[0]), int(s[-1])] += 1", "-for l in range(1, 10):", "- for m in range(1, 10):", "- point += li[l][m] * li[m][l]", "+for i in range(1, 10):", "+ for j in range(1, 10):", "+ point += dic[i, j] * dic[j, i]" ]
false
0.169593
0.051954
3.264284
[ "s497987870", "s776481699" ]
u644907318
p02603
python
s426810474
s750324258
71
28
61,760
9,244
Accepted
Accepted
60.56
N = int(eval(input())) A = list(map(int,input().split())) m = 1000 s = 0 flag = 0 a = A[0] for i in range(N): if A[i]>a and flag==0: n = m//a s += n m -= n*a flag = 1 elif A[i]<a and flag==1: m += s*a s = 0 flag = 0 a = A[i] if flag==1: m += s*A[-1] print(m)
N = int(eval(input())) A = list(map(int,input().split())) x = 1000 cnt = 0 flag = 0 for i in range(1,N): if flag==0 and A[i]-A[i-1]>0: cnt += x//A[i-1] x = x%A[i-1] flag = 1 elif flag==0 and A[i]-A[i-1]<0: x += cnt*A[i-1] cnt = 0 flag = -1 elif flag==1 and A[i]-A[i-1]<0: x += cnt*A[i-1] cnt = 0 flag = -1 elif flag==-1 and A[i]-A[i-1]>0: cnt += x//A[i-1] x = x%A[i-1] flag = 1 if flag==1: x += cnt*A[N-1] cnt = 0 print(x)
20
26
343
561
N = int(eval(input())) A = list(map(int, input().split())) m = 1000 s = 0 flag = 0 a = A[0] for i in range(N): if A[i] > a and flag == 0: n = m // a s += n m -= n * a flag = 1 elif A[i] < a and flag == 1: m += s * a s = 0 flag = 0 a = A[i] if flag == 1: m += s * A[-1] print(m)
N = int(eval(input())) A = list(map(int, input().split())) x = 1000 cnt = 0 flag = 0 for i in range(1, N): if flag == 0 and A[i] - A[i - 1] > 0: cnt += x // A[i - 1] x = x % A[i - 1] flag = 1 elif flag == 0 and A[i] - A[i - 1] < 0: x += cnt * A[i - 1] cnt = 0 flag = -1 elif flag == 1 and A[i] - A[i - 1] < 0: x += cnt * A[i - 1] cnt = 0 flag = -1 elif flag == -1 and A[i] - A[i - 1] > 0: cnt += x // A[i - 1] x = x % A[i - 1] flag = 1 if flag == 1: x += cnt * A[N - 1] cnt = 0 print(x)
false
23.076923
[ "-m = 1000", "-s = 0", "+x = 1000", "+cnt = 0", "-a = A[0]", "-for i in range(N):", "- if A[i] > a and flag == 0:", "- n = m // a", "- s += n", "- m -= n * a", "+for i in range(1, N):", "+ if flag == 0 and A[i] - A[i - 1] > 0:", "+ cnt += x // A[i - 1]", "+ x = x % A[i - 1]", "- elif A[i] < a and flag == 1:", "- m += s * a", "- s = 0", "- flag = 0", "- a = A[i]", "+ elif flag == 0 and A[i] - A[i - 1] < 0:", "+ x += cnt * A[i - 1]", "+ cnt = 0", "+ flag = -1", "+ elif flag == 1 and A[i] - A[i - 1] < 0:", "+ x += cnt * A[i - 1]", "+ cnt = 0", "+ flag = -1", "+ elif flag == -1 and A[i] - A[i - 1] > 0:", "+ cnt += x // A[i - 1]", "+ x = x % A[i - 1]", "+ flag = 1", "- m += s * A[-1]", "-print(m)", "+ x += cnt * A[N - 1]", "+ cnt = 0", "+print(x)" ]
false
0.037802
0.10033
0.376772
[ "s426810474", "s750324258" ]
u344030307
p02982
python
s649684574
s477783199
31
26
9,188
9,184
Accepted
Accepted
16.13
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(0, n): for j in range(i+1, n): D = [] for k in range(d): D.append((x[i][k] - x[j][k])**2) D = math.sqrt(sum(D)) if isinstance(D, int) == True or D.is_integer() == True: 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(0, n): for j in range(i+1, n): D = math.sqrt(sum((x[i][k] - x[j][k])**2 for k in range(d))) if D.is_integer() == True: cnt += 1 print(cnt)
17
15
364
301
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(0, n): for j in range(i + 1, n): D = [] for k in range(d): D.append((x[i][k] - x[j][k]) ** 2) D = math.sqrt(sum(D)) if isinstance(D, int) == True or D.is_integer() == True: 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(0, n): for j in range(i + 1, n): D = math.sqrt(sum((x[i][k] - x[j][k]) ** 2 for k in range(d))) if D.is_integer() == True: cnt += 1 print(cnt)
false
11.764706
[ "- D = []", "- for k in range(d):", "- D.append((x[i][k] - x[j][k]) ** 2)", "- D = math.sqrt(sum(D))", "- if isinstance(D, int) == True or D.is_integer() == True:", "+ D = math.sqrt(sum((x[i][k] - x[j][k]) ** 2 for k in range(d)))", "+ if D.is_integer() == True:" ]
false
0.037257
0.036593
1.018136
[ "s649684574", "s477783199" ]
u476604182
p02919
python
s071838868
s400341294
463
426
62,956
58,860
Accepted
Accepted
7.99
class BIT: def __init__(self, n): self.N = n self.tree = [0]*(n+1) def BIT_add(self, i): while i <= self.N: self.tree[i] += 1 i += i&(-i) def BIT_sum(self, i): s = 0 while i: s += self.tree[i] i -= i&(-i) return s def BIT_search(self, x): i = 0 s = 0 step = 1<<(self.N.bit_length()-1) while step: if i+step <= self.N and s+self.tree[i+step] < x: i += step s += self.tree[i] step >>= 1 return i+1 N = int(eval(input())) bit = BIT(N) p = [None]+[int(c) for c in input().split()] p_to_i = [None]*(N+1) for i, x in enumerate(p[1:], 1): p_to_i[x] = i ans = 0 for x in range(N,0,-1): c = p_to_i[x] L = bit.BIT_sum(c) bit.BIT_add(c) R = N-x-L a = bit.BIT_search(L-1) if L>=2 else 0 b = bit.BIT_search(L) if L >= 1 else 0 d = bit.BIT_search(L+2) if R >= 1 else N+1 e = bit.BIT_search(L+3) if R >= 1 else N+1 coef = 0 if b != 0: coef += (b-a) * (d-c) if d != 0: coef += (e-d) * (c-b) ans += x*coef print(ans)
class BIT: def __init__(self, N): self.n = N self.tree = [0]*(self.n+1) def bsum(self, i): s = 0 while i: s += self.tree[i] i -= i&(-i) return s def badd(self, i, x): while i<=self.n: self.tree[i] += x i += i&(-i) def bsearch(self, x): i = 0 s = 0 step = 1<<(self.n.bit_length()-1) while step: if i+step<=self.n and s+self.tree[i+step]<x: i += step s += self.tree[i] step >>= 1 return i+1 N = int(eval(input())) P = [0]+[int(c) for c in input().split()] ntoi = [0]*(N+1) for i in range(N+1): ntoi[P[i]] = i bit = BIT(N) ans = 0 for m in range(N, 0, -1): I = ntoi[m] L = bit.bsum(I) bit.badd(I,1) R = N-L-m a = bit.bsearch(L-1) if L>1 else 0 b = bit.bsearch(L) if L>0 else 0 c = bit.bsearch(L+2) if R>0 else N+1 d = bit.bsearch(L+3) if R>1 else N+1 coef = 0 if b!=0: coef += (b-a)*(c-I) if c!=0: coef += (I-b)*(d-c) ans += m*coef print(ans)
55
57
1,109
1,053
class BIT: def __init__(self, n): self.N = n self.tree = [0] * (n + 1) def BIT_add(self, i): while i <= self.N: self.tree[i] += 1 i += i & (-i) def BIT_sum(self, i): s = 0 while i: s += self.tree[i] i -= i & (-i) return s def BIT_search(self, x): i = 0 s = 0 step = 1 << (self.N.bit_length() - 1) while step: if i + step <= self.N and s + self.tree[i + step] < x: i += step s += self.tree[i] step >>= 1 return i + 1 N = int(eval(input())) bit = BIT(N) p = [None] + [int(c) for c in input().split()] p_to_i = [None] * (N + 1) for i, x in enumerate(p[1:], 1): p_to_i[x] = i ans = 0 for x in range(N, 0, -1): c = p_to_i[x] L = bit.BIT_sum(c) bit.BIT_add(c) R = N - x - L a = bit.BIT_search(L - 1) if L >= 2 else 0 b = bit.BIT_search(L) if L >= 1 else 0 d = bit.BIT_search(L + 2) if R >= 1 else N + 1 e = bit.BIT_search(L + 3) if R >= 1 else N + 1 coef = 0 if b != 0: coef += (b - a) * (d - c) if d != 0: coef += (e - d) * (c - b) ans += x * coef print(ans)
class BIT: def __init__(self, N): self.n = N self.tree = [0] * (self.n + 1) def bsum(self, i): s = 0 while i: s += self.tree[i] i -= i & (-i) return s def badd(self, i, x): while i <= self.n: self.tree[i] += x i += i & (-i) def bsearch(self, x): i = 0 s = 0 step = 1 << (self.n.bit_length() - 1) while step: if i + step <= self.n and s + self.tree[i + step] < x: i += step s += self.tree[i] step >>= 1 return i + 1 N = int(eval(input())) P = [0] + [int(c) for c in input().split()] ntoi = [0] * (N + 1) for i in range(N + 1): ntoi[P[i]] = i bit = BIT(N) ans = 0 for m in range(N, 0, -1): I = ntoi[m] L = bit.bsum(I) bit.badd(I, 1) R = N - L - m a = bit.bsearch(L - 1) if L > 1 else 0 b = bit.bsearch(L) if L > 0 else 0 c = bit.bsearch(L + 2) if R > 0 else N + 1 d = bit.bsearch(L + 3) if R > 1 else N + 1 coef = 0 if b != 0: coef += (b - a) * (c - I) if c != 0: coef += (I - b) * (d - c) ans += m * coef print(ans)
false
3.508772
[ "- def __init__(self, n):", "- self.N = n", "- self.tree = [0] * (n + 1)", "+ def __init__(self, N):", "+ self.n = N", "+ self.tree = [0] * (self.n + 1)", "- def BIT_add(self, i):", "- while i <= self.N:", "- self.tree[i] += 1", "- i += i & (-i)", "-", "- def BIT_sum(self, i):", "+ def bsum(self, i):", "- def BIT_search(self, x):", "+ def badd(self, i, x):", "+ while i <= self.n:", "+ self.tree[i] += x", "+ i += i & (-i)", "+", "+ def bsearch(self, x):", "- step = 1 << (self.N.bit_length() - 1)", "+ step = 1 << (self.n.bit_length() - 1)", "- if i + step <= self.N and s + self.tree[i + step] < x:", "+ if i + step <= self.n and s + self.tree[i + step] < x:", "+P = [0] + [int(c) for c in input().split()]", "+ntoi = [0] * (N + 1)", "+for i in range(N + 1):", "+ ntoi[P[i]] = i", "-p = [None] + [int(c) for c in input().split()]", "-p_to_i = [None] * (N + 1)", "-for i, x in enumerate(p[1:], 1):", "- p_to_i[x] = i", "-for x in range(N, 0, -1):", "- c = p_to_i[x]", "- L = bit.BIT_sum(c)", "- bit.BIT_add(c)", "- R = N - x - L", "- a = bit.BIT_search(L - 1) if L >= 2 else 0", "- b = bit.BIT_search(L) if L >= 1 else 0", "- d = bit.BIT_search(L + 2) if R >= 1 else N + 1", "- e = bit.BIT_search(L + 3) if R >= 1 else N + 1", "+for m in range(N, 0, -1):", "+ I = ntoi[m]", "+ L = bit.bsum(I)", "+ bit.badd(I, 1)", "+ R = N - L - m", "+ a = bit.bsearch(L - 1) if L > 1 else 0", "+ b = bit.bsearch(L) if L > 0 else 0", "+ c = bit.bsearch(L + 2) if R > 0 else N + 1", "+ d = bit.bsearch(L + 3) if R > 1 else N + 1", "- coef += (b - a) * (d - c)", "- if d != 0:", "- coef += (e - d) * (c - b)", "- ans += x * coef", "+ coef += (b - a) * (c - I)", "+ if c != 0:", "+ coef += (I - b) * (d - c)", "+ ans += m * coef" ]
false
0.039142
0.038731
1.010625
[ "s071838868", "s400341294" ]
u729133443
p03047
python
s072792273
s167485044
161
17
38,384
2,940
Accepted
Accepted
89.44
print((eval(input().replace(' ','+1-'))))
print((eval(input().replace(' ','-~-'))))
1
1
39
39
print((eval(input().replace(" ", "+1-"))))
print((eval(input().replace(" ", "-~-"))))
false
0
[ "-print((eval(input().replace(\" \", \"+1-\"))))", "+print((eval(input().replace(\" \", \"-~-\"))))" ]
false
0.0365
0.036232
1.007387
[ "s072792273", "s167485044" ]
u102461423
p03014
python
s757591686
s176775626
1,665
1,049
141,856
188,708
Accepted
Accepted
37
import numpy as np H,W = list(map(int,input().split())) temp = np.array([list(eval(input())) for _ in range(H)]) # 周りに壁を、0,1化 map = np.zeros((H+2,W+2),dtype=np.int32) map[1:-1,1:-1][temp == '.'] = 1 # x軸正方向の集計 def F(): x = map.copy() for row in range(1,H+1): zero_idx = np.nonzero(x[row]==0)[0] x[row, zero_idx[1:]] = 1-np.diff(zero_idx) # cumsumで求められるように変形 x = x.cumsum(axis = 1) return x # y軸 def G(): x = map.T.copy() for row in range(1,W+1): zero_idx = np.nonzero(x[row]==0)[0] x[row, zero_idx[1:]] = 1-np.diff(zero_idx) # cumsumで求められるように変形 x = x.cumsum(axis = 1) return x.T answer = np.zeros_like(map) # x軸 answer += F() # 逆順 map = map[:,::-1] answer += F()[:,::-1] map = map[:,::-1] # y軸 answer += G() # 逆順 map = map[::-1,:] answer += G()[::-1,:] answer = np.max(answer) - 3 print(answer)
import numpy as np H,W = list(map(int,input().split())) temp = np.array([list(eval(input())) for _ in range(H)]) # 周りに壁を、0,1化 map = np.zeros((H+2,W+2),dtype=np.int32) map[1:-1,1:-1][temp == '.'] = 1 # x軸正方向の集計 def F(transpose,reverse): x = map.copy() if transpose: x = x.T x = np.ravel(x) if reverse: x = x[::-1] zero_idx = np.nonzero(x==0)[0] x[zero_idx[1:]] = 1-np.diff(zero_idx) # cumsumで求められるように変形 x = x.cumsum() if reverse: x = x[::-1] if transpose: x = x.reshape(map.T.shape).T else: x = x.reshape(map.shape) return x answer = np.zeros_like(map) for t in [True,False]: for r in [True,False]: answer += F(t,r) answer = answer.max() - 3 print(answer)
42
34
862
731
import numpy as np H, W = list(map(int, input().split())) temp = np.array([list(eval(input())) for _ in range(H)]) # 周りに壁を、0,1化 map = np.zeros((H + 2, W + 2), dtype=np.int32) map[1:-1, 1:-1][temp == "."] = 1 # x軸正方向の集計 def F(): x = map.copy() for row in range(1, H + 1): zero_idx = np.nonzero(x[row] == 0)[0] x[row, zero_idx[1:]] = 1 - np.diff(zero_idx) # cumsumで求められるように変形 x = x.cumsum(axis=1) return x # y軸 def G(): x = map.T.copy() for row in range(1, W + 1): zero_idx = np.nonzero(x[row] == 0)[0] x[row, zero_idx[1:]] = 1 - np.diff(zero_idx) # cumsumで求められるように変形 x = x.cumsum(axis=1) return x.T answer = np.zeros_like(map) # x軸 answer += F() # 逆順 map = map[:, ::-1] answer += F()[:, ::-1] map = map[:, ::-1] # y軸 answer += G() # 逆順 map = map[::-1, :] answer += G()[::-1, :] answer = np.max(answer) - 3 print(answer)
import numpy as np H, W = list(map(int, input().split())) temp = np.array([list(eval(input())) for _ in range(H)]) # 周りに壁を、0,1化 map = np.zeros((H + 2, W + 2), dtype=np.int32) map[1:-1, 1:-1][temp == "."] = 1 # x軸正方向の集計 def F(transpose, reverse): x = map.copy() if transpose: x = x.T x = np.ravel(x) if reverse: x = x[::-1] zero_idx = np.nonzero(x == 0)[0] x[zero_idx[1:]] = 1 - np.diff(zero_idx) # cumsumで求められるように変形 x = x.cumsum() if reverse: x = x[::-1] if transpose: x = x.reshape(map.T.shape).T else: x = x.reshape(map.shape) return x answer = np.zeros_like(map) for t in [True, False]: for r in [True, False]: answer += F(t, r) answer = answer.max() - 3 print(answer)
false
19.047619
[ "-def F():", "+def F(transpose, reverse):", "- for row in range(1, H + 1):", "- zero_idx = np.nonzero(x[row] == 0)[0]", "- x[row, zero_idx[1:]] = 1 - np.diff(zero_idx) # cumsumで求められるように変形", "- x = x.cumsum(axis=1)", "+ if transpose:", "+ x = x.T", "+ x = np.ravel(x)", "+ if reverse:", "+ x = x[::-1]", "+ zero_idx = np.nonzero(x == 0)[0]", "+ x[zero_idx[1:]] = 1 - np.diff(zero_idx) # cumsumで求められるように変形", "+ x = x.cumsum()", "+ if reverse:", "+ x = x[::-1]", "+ if transpose:", "+ x = x.reshape(map.T.shape).T", "+ else:", "+ x = x.reshape(map.shape)", "-# y軸", "-def G():", "- x = map.T.copy()", "- for row in range(1, W + 1):", "- zero_idx = np.nonzero(x[row] == 0)[0]", "- x[row, zero_idx[1:]] = 1 - np.diff(zero_idx) # cumsumで求められるように変形", "- x = x.cumsum(axis=1)", "- return x.T", "-", "-", "-# x軸", "-answer += F()", "-# 逆順", "-map = map[:, ::-1]", "-answer += F()[:, ::-1]", "-map = map[:, ::-1]", "-# y軸", "-answer += G()", "-# 逆順", "-map = map[::-1, :]", "-answer += G()[::-1, :]", "-answer = np.max(answer) - 3", "+for t in [True, False]:", "+ for r in [True, False]:", "+ answer += F(t, r)", "+answer = answer.max() - 3" ]
false
0.179584
0.181329
0.99038
[ "s757591686", "s176775626" ]
u062484507
p03494
python
s236059700
s137445814
167
20
38,768
3,060
Accepted
Accepted
88.02
n = int(eval(input())) a = [int(i) for i in input().split()] count = 0 while all(i % 2 == 0 for i in a): a = [i/2 for i in a] count += 1 print(count)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(readline()) a = [int(x) for x in readline().split()] ans = float('inf') for x in a: ans = min(ans, len(bin(x)) - bin(x).rfind('1') - 1) print(ans)
7
11
157
285
n = int(eval(input())) a = [int(i) for i in input().split()] count = 0 while all(i % 2 == 0 for i in a): a = [i / 2 for i in a] count += 1 print(count)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(readline()) a = [int(x) for x in readline().split()] ans = float("inf") for x in a: ans = min(ans, len(bin(x)) - bin(x).rfind("1") - 1) print(ans)
false
36.363636
[ "-n = int(eval(input()))", "-a = [int(i) for i in input().split()]", "-count = 0", "-while all(i % 2 == 0 for i in a):", "- a = [i / 2 for i in a]", "- count += 1", "-print(count)", "+import sys", "+", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+n = int(readline())", "+a = [int(x) for x in readline().split()]", "+ans = float(\"inf\")", "+for x in a:", "+ ans = min(ans, len(bin(x)) - bin(x).rfind(\"1\") - 1)", "+print(ans)" ]
false
0.038202
0.11359
0.336312
[ "s236059700", "s137445814" ]
u089142196
p03487
python
s333933980
s174948758
146
98
18,676
18,676
Accepted
Accepted
32.88
import collections N=int(eval(input())) a=list(map(int,input().split())) a.sort() cnt=0 c=collections.Counter(a) #print(c) for item in c: t=c[item] if t>item: cnt+=t-item elif t==item: pass else: cnt+=t #while len(a)>0: # item=a[0] # t=(item) # #print(item,t,a) # if t>item: # cnt+=t-item # elif t==item: # pass # else: # cnt+=t # del a[0:t] # #print("after",a) print(cnt)
import collections N=int(eval(input())) a=list(map(int,input().split())) c=collections.Counter(a) cnt=0 for item in c: t=c[item] if t>item: cnt+=t-item elif t==item: pass else: cnt+=t print(cnt)
34
18
444
231
import collections N = int(eval(input())) a = list(map(int, input().split())) a.sort() cnt = 0 c = collections.Counter(a) # print(c) for item in c: t = c[item] if t > item: cnt += t - item elif t == item: pass else: cnt += t # while len(a)>0: # item=a[0] # t=(item) # #print(item,t,a) # if t>item: # cnt+=t-item # elif t==item: # pass # else: # cnt+=t # del a[0:t] # #print("after",a) print(cnt)
import collections N = int(eval(input())) a = list(map(int, input().split())) c = collections.Counter(a) cnt = 0 for item in c: t = c[item] if t > item: cnt += t - item elif t == item: pass else: cnt += t print(cnt)
false
47.058824
[ "-a.sort()", "+c = collections.Counter(a)", "-c = collections.Counter(a)", "-# print(c)", "-# while len(a)>0:", "-# item=a[0]", "-# t=(item)", "-# #print(item,t,a)", "-# if t>item:", "-# cnt+=t-item", "-# elif t==item:", "-# pass", "-# else:", "-# cnt+=t", "-# del a[0:t]", "-# #print(\"after\",a)" ]
false
0.039635
0.044381
0.893055
[ "s333933980", "s174948758" ]
u798818115
p02918
python
s938069253
s594280077
88
76
4,772
4,776
Accepted
Accepted
13.64
# coding: utf-8 # Your code here! N,K=list(map(int,input().split())) S=list(eval(input())) l=[] count=1 for i in range(N-1): if S[i]!=S[i+1]: l.append(count) count=1 else: count+=1 l.append(count) flag=False ans=0 idx=0 time=0 while idx<len(l): if time<K: time+=1 ans+=(l[idx]+l[idx+1] if idx!=(len(l)-1) else l[idx]) idx+=1 else: flag=True ans+=(l[idx]-1) idx+=1 if flag: print(ans) else: print((ans-1))
# coding: utf-8 # Your code here! N,K=list(map(int,input().split())) S=list(eval(input())) clu=[] temp=0 for i in range(1,len(S)): if S[i]==S[i-1]: temp+=1 else: clu.append(temp) temp=0 clu.append(temp) ans=sum(clu) base=S[0] zone=False for i in range(1,len(S)): if zone: if S[i]==base: K-=1 ans+=2 zone=False else: S[i]=base else: if S[i]!=base and K>0: zone=True S[i]=base if zone: ans+=1 print(ans)
36
38
532
574
# coding: utf-8 # Your code here! N, K = list(map(int, input().split())) S = list(eval(input())) l = [] count = 1 for i in range(N - 1): if S[i] != S[i + 1]: l.append(count) count = 1 else: count += 1 l.append(count) flag = False ans = 0 idx = 0 time = 0 while idx < len(l): if time < K: time += 1 ans += l[idx] + l[idx + 1] if idx != (len(l) - 1) else l[idx] idx += 1 else: flag = True ans += l[idx] - 1 idx += 1 if flag: print(ans) else: print((ans - 1))
# coding: utf-8 # Your code here! N, K = list(map(int, input().split())) S = list(eval(input())) clu = [] temp = 0 for i in range(1, len(S)): if S[i] == S[i - 1]: temp += 1 else: clu.append(temp) temp = 0 clu.append(temp) ans = sum(clu) base = S[0] zone = False for i in range(1, len(S)): if zone: if S[i] == base: K -= 1 ans += 2 zone = False else: S[i] = base else: if S[i] != base and K > 0: zone = True S[i] = base if zone: ans += 1 print(ans)
false
5.263158
[ "-l = []", "-count = 1", "-for i in range(N - 1):", "- if S[i] != S[i + 1]:", "- l.append(count)", "- count = 1", "+clu = []", "+temp = 0", "+for i in range(1, len(S)):", "+ if S[i] == S[i - 1]:", "+ temp += 1", "- count += 1", "-l.append(count)", "-flag = False", "-ans = 0", "-idx = 0", "-time = 0", "-while idx < len(l):", "- if time < K:", "- time += 1", "- ans += l[idx] + l[idx + 1] if idx != (len(l) - 1) else l[idx]", "- idx += 1", "+ clu.append(temp)", "+ temp = 0", "+clu.append(temp)", "+ans = sum(clu)", "+base = S[0]", "+zone = False", "+for i in range(1, len(S)):", "+ if zone:", "+ if S[i] == base:", "+ K -= 1", "+ ans += 2", "+ zone = False", "+ else:", "+ S[i] = base", "- flag = True", "- ans += l[idx] - 1", "- idx += 1", "-if flag:", "- print(ans)", "-else:", "- print((ans - 1))", "+ if S[i] != base and K > 0:", "+ zone = True", "+ S[i] = base", "+if zone:", "+ ans += 1", "+print(ans)" ]
false
0.050356
0.036953
1.362696
[ "s938069253", "s594280077" ]
u577170763
p03161
python
s514883028
s211538174
537
363
53,216
53,728
Accepted
Accepted
32.4
# import sys # sys.setrecursionlimit(10**5) # from collections import defaultdict geta = lambda fn: list(map(fn, input().split())) gete = lambda fn: fn(eval(input())) def main(): N, K = geta(int) h = geta(int) INF = 1 << 60 dp = [INF]*N dp[0], dp[1] = 0, abs(h[0] - h[1]) for i in range(2, N): lb = max(0, i-K) dp[i] = min((dp[j] + abs(h[i]-h[j]) for j in range(lb,i))) print((dp[-1])) if __name__ == "__main__": main()
# import sys # sys.setrecursionlimit(10**5) # from collections import defaultdict geta = lambda fn: list(map(fn, input().split())) gete = lambda fn: fn(eval(input())) def main(): N, K = geta(int) h = geta(int) INF = 10 << 60 dp = [INF]*N dp[0], dp[1] = 0, abs(h[0] - h[1]) for i in range(2, N): lb = max(0, i-K) tmp, hi = INF, h[i] for dpj, hj in zip(dp[lb:i], h[lb:i]): tmp = min(tmp, dpj + abs(hi-hj)) dp[i] = tmp print((dp[-1])) if __name__ == "__main__": main()
22
25
485
562
# import sys # sys.setrecursionlimit(10**5) # from collections import defaultdict geta = lambda fn: list(map(fn, input().split())) gete = lambda fn: fn(eval(input())) def main(): N, K = geta(int) h = geta(int) INF = 1 << 60 dp = [INF] * N dp[0], dp[1] = 0, abs(h[0] - h[1]) for i in range(2, N): lb = max(0, i - K) dp[i] = min((dp[j] + abs(h[i] - h[j]) for j in range(lb, i))) print((dp[-1])) if __name__ == "__main__": main()
# import sys # sys.setrecursionlimit(10**5) # from collections import defaultdict geta = lambda fn: list(map(fn, input().split())) gete = lambda fn: fn(eval(input())) def main(): N, K = geta(int) h = geta(int) INF = 10 << 60 dp = [INF] * N dp[0], dp[1] = 0, abs(h[0] - h[1]) for i in range(2, N): lb = max(0, i - K) tmp, hi = INF, h[i] for dpj, hj in zip(dp[lb:i], h[lb:i]): tmp = min(tmp, dpj + abs(hi - hj)) dp[i] = tmp print((dp[-1])) if __name__ == "__main__": main()
false
12
[ "- INF = 1 << 60", "+ INF = 10 << 60", "- dp[i] = min((dp[j] + abs(h[i] - h[j]) for j in range(lb, i)))", "+ tmp, hi = INF, h[i]", "+ for dpj, hj in zip(dp[lb:i], h[lb:i]):", "+ tmp = min(tmp, dpj + abs(hi - hj))", "+ dp[i] = tmp" ]
false
0.034184
0.035104
0.973788
[ "s514883028", "s211538174" ]
u392319141
p03252
python
s804565641
s681991204
87
53
3,632
3,632
Accepted
Accepted
39.08
S = eval(input()) T = eval(input()) tToS = {} sToT = {} for s, t in zip(S, T): if not t in tToS: tToS[t] = s if not s in sToT: sToT[s] = t if tToS[t] != s or sToT[s] != t: print('No') exit() print('Yes')
S = eval(input()) T = eval(input()) def isOk(): sToT = {} tToS = {} for s, t in zip(S, T): if not s in sToT: sToT[s] = t elif sToT[s] != t: return False if not t in tToS: tToS[t] = s elif tToS[t] != s: return False return True print(('Yes' if isOk() else 'No'))
16
18
254
363
S = eval(input()) T = eval(input()) tToS = {} sToT = {} for s, t in zip(S, T): if not t in tToS: tToS[t] = s if not s in sToT: sToT[s] = t if tToS[t] != s or sToT[s] != t: print("No") exit() print("Yes")
S = eval(input()) T = eval(input()) def isOk(): sToT = {} tToS = {} for s, t in zip(S, T): if not s in sToT: sToT[s] = t elif sToT[s] != t: return False if not t in tToS: tToS[t] = s elif tToS[t] != s: return False return True print(("Yes" if isOk() else "No"))
false
11.111111
[ "-tToS = {}", "-sToT = {}", "-for s, t in zip(S, T):", "- if not t in tToS:", "- tToS[t] = s", "- if not s in sToT:", "- sToT[s] = t", "- if tToS[t] != s or sToT[s] != t:", "- print(\"No\")", "- exit()", "-print(\"Yes\")", "+", "+", "+def isOk():", "+ sToT = {}", "+ tToS = {}", "+ for s, t in zip(S, T):", "+ if not s in sToT:", "+ sToT[s] = t", "+ elif sToT[s] != t:", "+ return False", "+ if not t in tToS:", "+ tToS[t] = s", "+ elif tToS[t] != s:", "+ return False", "+ return True", "+", "+", "+print((\"Yes\" if isOk() else \"No\"))" ]
false
0.110705
0.035525
3.11622
[ "s804565641", "s681991204" ]
u753803401
p02883
python
s229821814
s837890746
1,982
504
126,448
113,364
Accepted
Accepted
74.57
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): input = sys.stdin.readline mod = 10 ** 9 + 7 n, k = list(map(int, input().rstrip('\n').split())) a = list(map(int, input().rstrip('\n').split())) a.sort() f = list(map(int, input().rstrip('\n').split())) f.sort(reverse=True) cor_v = 10 ** 20 inc_v = -1 while cor_v - inc_v > 1: bin_v = (cor_v + inc_v) // 2 cost = 0 #条件を満たすcostを全検索 for i in range(n): t = a[i] * f[i] if t > bin_v: cost += (t - bin_v + f[i] - 1) // f[i] #costが制約を満たすか if cost <= k: cor_v = bin_v else: inc_v = bin_v print(cor_v) if __name__ == '__main__': solve()
import sys def solve(): input = sys.stdin.readline mod = 10 ** 9 + 7 n, k = list(map(int, input().rstrip('\n').split())) a = list(map(int, input().rstrip('\n').split())) a.sort() f = list(map(int, input().rstrip('\n').split())) f.sort(reverse=True) cor_v = 10 ** 13 inc_v = -1 while cor_v - inc_v > 1: bin_v = (cor_v + inc_v) // 2 cost = 0 #条件を満たすcostを全検索 for i in range(n): t = a[i] * f[i] if t > bin_v: cost += (t - bin_v + f[i] - 1) // f[i] #costが制約を満たすか if cost <= k: cor_v = bin_v else: inc_v = bin_v print(cor_v) if __name__ == '__main__': solve()
40
31
943
756
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): input = sys.stdin.readline mod = 10**9 + 7 n, k = list(map(int, input().rstrip("\n").split())) a = list(map(int, input().rstrip("\n").split())) a.sort() f = list(map(int, input().rstrip("\n").split())) f.sort(reverse=True) cor_v = 10**20 inc_v = -1 while cor_v - inc_v > 1: bin_v = (cor_v + inc_v) // 2 cost = 0 # 条件を満たすcostを全検索 for i in range(n): t = a[i] * f[i] if t > bin_v: cost += (t - bin_v + f[i] - 1) // f[i] # costが制約を満たすか if cost <= k: cor_v = bin_v else: inc_v = bin_v print(cor_v) if __name__ == "__main__": solve()
import sys def solve(): input = sys.stdin.readline mod = 10**9 + 7 n, k = list(map(int, input().rstrip("\n").split())) a = list(map(int, input().rstrip("\n").split())) a.sort() f = list(map(int, input().rstrip("\n").split())) f.sort(reverse=True) cor_v = 10**13 inc_v = -1 while cor_v - inc_v > 1: bin_v = (cor_v + inc_v) // 2 cost = 0 # 条件を満たすcostを全検索 for i in range(n): t = a[i] * f[i] if t > bin_v: cost += (t - bin_v + f[i] - 1) // f[i] # costが制約を満たすか if cost <= k: cor_v = bin_v else: inc_v = bin_v print(cor_v) if __name__ == "__main__": solve()
false
22.5
[ "-import bisect", "-import itertools", "-import collections", "-import fractions", "-import heapq", "-import math", "-from operator import mul", "-from functools import reduce", "-from functools import lru_cache", "- cor_v = 10**20", "+ cor_v = 10**13" ]
false
0.034144
0.047469
0.719296
[ "s229821814", "s837890746" ]
u263830634
p03835
python
s301522141
s128618854
1,665
1,287
2,940
2,940
Accepted
Accepted
22.7
K, S = list(map(int, input().split())) count = 0 for x in range(K + 1): for y in range(K + 1): z = S - x - y if 0 <= z <= K: count += 1 print (count)
K, S = list(map(int, input().split())) ans = 0 for i in range(K + 1): for j in range(K + 1): if 0 <= S - i - j <= K: ans += 1 print (ans)
10
9
186
165
K, S = list(map(int, input().split())) count = 0 for x in range(K + 1): for y in range(K + 1): z = S - x - y if 0 <= z <= K: count += 1 print(count)
K, S = list(map(int, input().split())) ans = 0 for i in range(K + 1): for j in range(K + 1): if 0 <= S - i - j <= K: ans += 1 print(ans)
false
10
[ "-count = 0", "-for x in range(K + 1):", "- for y in range(K + 1):", "- z = S - x - y", "- if 0 <= z <= K:", "- count += 1", "-print(count)", "+ans = 0", "+for i in range(K + 1):", "+ for j in range(K + 1):", "+ if 0 <= S - i - j <= K:", "+ ans += 1", "+print(ans)" ]
false
0.06247
0.044896
1.391435
[ "s301522141", "s128618854" ]
u614181788
p02862
python
s524244980
s729898884
1,282
1,028
3,064
9,148
Accepted
Accepted
19.81
def comb_mod(n,r,m): ans = 1 for i in range(1,r+1): ans *= (n-i+1) % m ans *= pow(i,m-2,m) % m ans = ans % m return ans x,y = list(map(int,input().split())) m = 10**9+7 n = (x+y)//3 c = 0 if x*0.5 <= y <= 2*x and (x+y)%3 == 0: r = x - n c = comb_mod(n,r,m) else: ans = 0 print(c)
def comb_mod(n,r,m): ans = 1 for i in range(1,r+1): ans *= (n-i+1) % m ans *= pow(i,m-2,m) % m ans = ans % m return ans x,y = list(map(int,input().split())) m = 10**9+7 if x > 2*y or 2*x < y or (x+y)%3 != 0: ans = 0 else: n = (x+y)//3 r = x-n ans = comb_mod(n,r,m) print(ans)
17
17
338
338
def comb_mod(n, r, m): ans = 1 for i in range(1, r + 1): ans *= (n - i + 1) % m ans *= pow(i, m - 2, m) % m ans = ans % m return ans x, y = list(map(int, input().split())) m = 10**9 + 7 n = (x + y) // 3 c = 0 if x * 0.5 <= y <= 2 * x and (x + y) % 3 == 0: r = x - n c = comb_mod(n, r, m) else: ans = 0 print(c)
def comb_mod(n, r, m): ans = 1 for i in range(1, r + 1): ans *= (n - i + 1) % m ans *= pow(i, m - 2, m) % m ans = ans % m return ans x, y = list(map(int, input().split())) m = 10**9 + 7 if x > 2 * y or 2 * x < y or (x + y) % 3 != 0: ans = 0 else: n = (x + y) // 3 r = x - n ans = comb_mod(n, r, m) print(ans)
false
0
[ "-n = (x + y) // 3", "-c = 0", "-if x * 0.5 <= y <= 2 * x and (x + y) % 3 == 0:", "+if x > 2 * y or 2 * x < y or (x + y) % 3 != 0:", "+ ans = 0", "+else:", "+ n = (x + y) // 3", "- c = comb_mod(n, r, m)", "-else:", "- ans = 0", "-print(c)", "+ ans = comb_mod(n, r, m)", "+print(ans)" ]
false
0.749565
0.766883
0.977417
[ "s524244980", "s729898884" ]
u390727364
p02689
python
s072325312
s481381268
418
314
45,432
106,656
Accepted
Accepted
24.88
def main(): n, m = list(map(int, input().split())) h = list(map(int, input().split())) ab = [] g = [] for _ in range(n): g.append([]) for _ in range(m): a, b = list(map(int, input().split())) ab.append([a, b]) g[a - 1].append(b - 1) g[b - 1].append(a - 1) ans = 0 for i in range(n): check = True for j in g[i]: if h[j] >= h[i]: check = False if check: ans += 1 print(ans) if __name__ == "__main__": main()
def main(): n, m = list(map(int, input().split())) h = list(map(int, input().split())) ab = [] g = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, input().split())) ab.append([a, b]) g[a - 1].append(b - 1) g[b - 1].append(a - 1) ans = 0 for i in range(n): check = True for j in g[i]: if h[j] >= h[i]: check = False if check: ans += 1 print(ans) if __name__ == "__main__": main()
26
24
566
540
def main(): n, m = list(map(int, input().split())) h = list(map(int, input().split())) ab = [] g = [] for _ in range(n): g.append([]) for _ in range(m): a, b = list(map(int, input().split())) ab.append([a, b]) g[a - 1].append(b - 1) g[b - 1].append(a - 1) ans = 0 for i in range(n): check = True for j in g[i]: if h[j] >= h[i]: check = False if check: ans += 1 print(ans) if __name__ == "__main__": main()
def main(): n, m = list(map(int, input().split())) h = list(map(int, input().split())) ab = [] g = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, input().split())) ab.append([a, b]) g[a - 1].append(b - 1) g[b - 1].append(a - 1) ans = 0 for i in range(n): check = True for j in g[i]: if h[j] >= h[i]: check = False if check: ans += 1 print(ans) if __name__ == "__main__": main()
false
7.692308
[ "- g = []", "- for _ in range(n):", "- g.append([])", "+ g = [[] for _ in range(n)]" ]
false
0.067407
0.046965
1.435251
[ "s072325312", "s481381268" ]
u111652094
p02708
python
s318076804
s514452754
101
24
9,164
9,132
Accepted
Accepted
76.24
N,K=list(map(int,input().split())) ans=0 for i in range(K,N+2): mini=i*(i-1)//2 maxi=i*N-mini ans=ans+(maxi-mini+1) print((ans%(10**9+7)))
N,K=list(map(int,input().split())) M=N+1 A=-M*(M+1)*(2*M+1)//6+(N+1)*M*(M+1)//2+M M=K-1 B=-M*(M+1)*(2*M+1)//6+(N+1)*M*(M+1)//2+M print(((A-B)%(10**9+7)))
9
12
153
162
N, K = list(map(int, input().split())) ans = 0 for i in range(K, N + 2): mini = i * (i - 1) // 2 maxi = i * N - mini ans = ans + (maxi - mini + 1) print((ans % (10**9 + 7)))
N, K = list(map(int, input().split())) M = N + 1 A = -M * (M + 1) * (2 * M + 1) // 6 + (N + 1) * M * (M + 1) // 2 + M M = K - 1 B = -M * (M + 1) * (2 * M + 1) // 6 + (N + 1) * M * (M + 1) // 2 + M print(((A - B) % (10**9 + 7)))
false
25
[ "-ans = 0", "-for i in range(K, N + 2):", "- mini = i * (i - 1) // 2", "- maxi = i * N - mini", "- ans = ans + (maxi - mini + 1)", "-print((ans % (10**9 + 7)))", "+M = N + 1", "+A = -M * (M + 1) * (2 * M + 1) // 6 + (N + 1) * M * (M + 1) // 2 + M", "+M = K - 1", "+B = -M * (M + 1) * (2 * M + 1) // 6 + (N + 1) * M * (M + 1) // 2 + M", "+print(((A - B) % (10**9 + 7)))" ]
false
0.055281
0.061941
0.892481
[ "s318076804", "s514452754" ]
u997648604
p02579
python
s881688829
s241649230
1,192
1,036
123,540
108,812
Accepted
Accepted
13.09
import numpy as np from collections import defaultdict import heapq import sys sys.setrecursionlimit(10**9) def mi(): return list(map(int,input().split())) def ii(): return int(eval(input())) def isp(): return input().split() def deb(text): print(("-------\n{}\n-------".format(text))) INF=1<<18 from numba import njit, b1, i4, i8, f8 @njit((i8,i8,i8), cache=True) # @njit(cache=True) def pos(W,h,w): return h * W + w @njit((i8,i8,i8,i8,i8,i8,b1[:]), cache=True) # @njit(cache=True) def main(H,W,Ch,Cw,Dh,Dw,G): Ch-=1 Cw-=1 Dh-=1 Dw-=1 s = (Ch,Cw) t = (Dh,Dw) hq = [(0,s)] heapq.heapify(hq) dist = [INF] *(H*W) # sからxでの最短距離 dist[pos(W,*s)] = 0 while hq: d,x = heapq.heappop(hq) # sからxまでの最短経路を探索する if dist[pos(W,*x)] < d: continue h,w = x normal = set([(h-1,w),(h+1,w),(h,w+1),(h,w-1)]) for dh in range(-2,3): for dw in range(-2,3): new_h,new_w = h+dh,w+dw e = (new_h,new_w) cost = 1 if dh == 0 and dw == 0: continue if not (0<=new_h<H and 0<=new_w<W): continue if G[pos(W,*e)] == 1: continue if e in normal: cost -= 1 if dist[pos(W,*e)] > dist[pos(W,*x)] + cost: dist[pos(W,*e)] = dist[pos(W,*x)] + cost heapq.heappush(hq,(dist[pos(W,*e)],e)) # print(dist) if dist[pos(W,*t)] == INF: dist[pos(W,*t)] = -1 return dist[pos(W,*t)] if __name__ == "__main__": H,W=mi() Ch,Cw=mi() Dh,Dw=mi() G = [0] * H*W for i in range(H): g = [] for j,s in enumerate(list(eval(input()))): G[i*W+j] = s == "#" ans = main(H,W,Ch,Cw,Dh,Dw,np.array(G)) print(ans)
from numba import njit import numpy as np import heapq import sys sys.setrecursionlimit(10**9) def mi(): return list(map(int,input().split())) def ii(): return int(eval(input())) def isp(): return input().split() def deb(text): print(("-------\n{}\n-------".format(text))) INF=1<<18 @njit(cache=True) def pos(W,h,w): return h * W + w # @njit(cache=True) def solve(H,W,Ch,Cw,Dh,Dw,G): Ch-=1 Cw-=1 Dh-=1 Dw-=1 s = (Ch,Cw) t = (Dh,Dw) hq = [(0,s)] heapq.heapify(hq) dist = [INF] *(H*W) # sからxでの最短距離 dist[pos(W,*s)] = 0 while hq: d,x = heapq.heappop(hq) # sからxまでの最短経路を探索する if dist[pos(W,*x)] < d: continue h,w = x normal = set([(h-1,w),(h+1,w),(h,w+1),(h,w-1)]) for dh in range(-2,3): for dw in range(-2,3): new_h,new_w = h+dh,w+dw e = (new_h,new_w) cost = 1 if dh == 0 and dw == 0: continue if not (0<=new_h<H and 0<=new_w<W): continue if G[pos(W,*e)] == 1: continue if e in normal: cost -= 1 if dist[pos(W,*e)] > dist[pos(W,*x)] + cost: dist[pos(W,*e)] = dist[pos(W,*x)] + cost heapq.heappush(hq,(dist[pos(W,*e)],e)) # print(dist) if dist[pos(W,*t)] == INF: dist[pos(W,*t)] = -1 return dist[pos(W,*t)] def main(): H,W=mi() Ch,Cw=mi() Dh,Dw=mi() G = [0] * H*W for i in range(H): g = [] for j,s in enumerate(list(eval(input()))): G[i*W+j] = s == "#" ans = solve(H,W,Ch,Cw,Dh,Dw,np.array(G)) print(ans) def cc_export(): from numba.pycc import CC cc = CC('my_module') cc.export('pos', '(i8,i8,i8,)')(pos) cc.export('solve', '(i8,i8,i8,i8,i8,i8,b1[:],)')(solve) cc.compile() if __name__ == '__main__': try: from my_module import solve from my_module import pos except: cc_export() exit() main()
78
94
1,909
2,142
import numpy as np from collections import defaultdict import heapq import sys sys.setrecursionlimit(10**9) def mi(): return list(map(int, input().split())) def ii(): return int(eval(input())) def isp(): return input().split() def deb(text): print(("-------\n{}\n-------".format(text))) INF = 1 << 18 from numba import njit, b1, i4, i8, f8 @njit((i8, i8, i8), cache=True) # @njit(cache=True) def pos(W, h, w): return h * W + w @njit((i8, i8, i8, i8, i8, i8, b1[:]), cache=True) # @njit(cache=True) def main(H, W, Ch, Cw, Dh, Dw, G): Ch -= 1 Cw -= 1 Dh -= 1 Dw -= 1 s = (Ch, Cw) t = (Dh, Dw) hq = [(0, s)] heapq.heapify(hq) dist = [INF] * (H * W) # sからxでの最短距離 dist[pos(W, *s)] = 0 while hq: d, x = heapq.heappop(hq) # sからxまでの最短経路を探索する if dist[pos(W, *x)] < d: continue h, w = x normal = set([(h - 1, w), (h + 1, w), (h, w + 1), (h, w - 1)]) for dh in range(-2, 3): for dw in range(-2, 3): new_h, new_w = h + dh, w + dw e = (new_h, new_w) cost = 1 if dh == 0 and dw == 0: continue if not (0 <= new_h < H and 0 <= new_w < W): continue if G[pos(W, *e)] == 1: continue if e in normal: cost -= 1 if dist[pos(W, *e)] > dist[pos(W, *x)] + cost: dist[pos(W, *e)] = dist[pos(W, *x)] + cost heapq.heappush(hq, (dist[pos(W, *e)], e)) # print(dist) if dist[pos(W, *t)] == INF: dist[pos(W, *t)] = -1 return dist[pos(W, *t)] if __name__ == "__main__": H, W = mi() Ch, Cw = mi() Dh, Dw = mi() G = [0] * H * W for i in range(H): g = [] for j, s in enumerate(list(eval(input()))): G[i * W + j] = s == "#" ans = main(H, W, Ch, Cw, Dh, Dw, np.array(G)) print(ans)
from numba import njit import numpy as np import heapq import sys sys.setrecursionlimit(10**9) def mi(): return list(map(int, input().split())) def ii(): return int(eval(input())) def isp(): return input().split() def deb(text): print(("-------\n{}\n-------".format(text))) INF = 1 << 18 @njit(cache=True) def pos(W, h, w): return h * W + w # @njit(cache=True) def solve(H, W, Ch, Cw, Dh, Dw, G): Ch -= 1 Cw -= 1 Dh -= 1 Dw -= 1 s = (Ch, Cw) t = (Dh, Dw) hq = [(0, s)] heapq.heapify(hq) dist = [INF] * (H * W) # sからxでの最短距離 dist[pos(W, *s)] = 0 while hq: d, x = heapq.heappop(hq) # sからxまでの最短経路を探索する if dist[pos(W, *x)] < d: continue h, w = x normal = set([(h - 1, w), (h + 1, w), (h, w + 1), (h, w - 1)]) for dh in range(-2, 3): for dw in range(-2, 3): new_h, new_w = h + dh, w + dw e = (new_h, new_w) cost = 1 if dh == 0 and dw == 0: continue if not (0 <= new_h < H and 0 <= new_w < W): continue if G[pos(W, *e)] == 1: continue if e in normal: cost -= 1 if dist[pos(W, *e)] > dist[pos(W, *x)] + cost: dist[pos(W, *e)] = dist[pos(W, *x)] + cost heapq.heappush(hq, (dist[pos(W, *e)], e)) # print(dist) if dist[pos(W, *t)] == INF: dist[pos(W, *t)] = -1 return dist[pos(W, *t)] def main(): H, W = mi() Ch, Cw = mi() Dh, Dw = mi() G = [0] * H * W for i in range(H): g = [] for j, s in enumerate(list(eval(input()))): G[i * W + j] = s == "#" ans = solve(H, W, Ch, Cw, Dh, Dw, np.array(G)) print(ans) def cc_export(): from numba.pycc import CC cc = CC("my_module") cc.export("pos", "(i8,i8,i8,)")(pos) cc.export("solve", "(i8,i8,i8,i8,i8,i8,b1[:],)")(solve) cc.compile() if __name__ == "__main__": try: from my_module import solve from my_module import pos except: cc_export() exit() main()
false
17.021277
[ "+from numba import njit", "-from collections import defaultdict", "-from numba import njit, b1, i4, i8, f8", "-@njit((i8, i8, i8), cache=True)", "-# @njit(cache=True)", "+@njit(cache=True)", "-@njit((i8, i8, i8, i8, i8, i8, b1[:]), cache=True)", "-def main(H, W, Ch, Cw, Dh, Dw, G):", "+def solve(H, W, Ch, Cw, Dh, Dw, G):", "-if __name__ == \"__main__\":", "+def main():", "- ans = main(H, W, Ch, Cw, Dh, Dw, np.array(G))", "+ ans = solve(H, W, Ch, Cw, Dh, Dw, np.array(G))", "+", "+", "+def cc_export():", "+ from numba.pycc import CC", "+", "+ cc = CC(\"my_module\")", "+ cc.export(\"pos\", \"(i8,i8,i8,)\")(pos)", "+ cc.export(\"solve\", \"(i8,i8,i8,i8,i8,i8,b1[:],)\")(solve)", "+ cc.compile()", "+", "+", "+if __name__ == \"__main__\":", "+ try:", "+ from my_module import solve", "+ from my_module import pos", "+ except:", "+ cc_export()", "+ exit()", "+ main()" ]
false
0.195415
0.037253
5.245567
[ "s881688829", "s241649230" ]
u002459665
p02711
python
s408953352
s893481598
23
21
9,108
9,008
Accepted
Accepted
8.7
N = int(eval(input())) ans = False for _ in range(3): s = N % 10 # print(s) if s == 7: ans = True N //= 10 if ans: print('Yes') else: print('No')
N = eval(input()) ans = False for i in range(3): if N[i] == '7': ans = True if ans: print('Yes') else: print('No')
14
11
186
140
N = int(eval(input())) ans = False for _ in range(3): s = N % 10 # print(s) if s == 7: ans = True N //= 10 if ans: print("Yes") else: print("No")
N = eval(input()) ans = False for i in range(3): if N[i] == "7": ans = True if ans: print("Yes") else: print("No")
false
21.428571
[ "-N = int(eval(input()))", "+N = eval(input())", "-for _ in range(3):", "- s = N % 10", "- # print(s)", "- if s == 7:", "+for i in range(3):", "+ if N[i] == \"7\":", "- N //= 10" ]
false
0.038597
0.039256
0.983228
[ "s408953352", "s893481598" ]
u489959379
p02861
python
s742999080
s594676339
605
467
10,020
3,064
Accepted
Accepted
22.81
import itertools import math n = int(eval(input())) x_y = list(input().split() for i in range(n)) all = list(itertools.permutations(x_y)) l = 0 for i in all: for j in range(n-1): tmp = math.sqrt(math.pow(int(i[j][0])-int(i[j+1][0]), 2) + math.pow(int(i[j][1])-int(i[j+1][1]), 2)) l += tmp print((l/len(all)))
from itertools import permutations n = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(n)] dist = 0 cnt = 0 for pattern in permutations(xy): cnt += 1 for i in range(n - 1): x1, y1 = pattern[i] x2, y2 = pattern[i + 1] dist += pow(pow(x1 - x2, 2) + pow(y1 - y2, 2), 1 / 2) res = dist / cnt print(res)
13
15
334
364
import itertools import math n = int(eval(input())) x_y = list(input().split() for i in range(n)) all = list(itertools.permutations(x_y)) l = 0 for i in all: for j in range(n - 1): tmp = math.sqrt( math.pow(int(i[j][0]) - int(i[j + 1][0]), 2) + math.pow(int(i[j][1]) - int(i[j + 1][1]), 2) ) l += tmp print((l / len(all)))
from itertools import permutations n = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(n)] dist = 0 cnt = 0 for pattern in permutations(xy): cnt += 1 for i in range(n - 1): x1, y1 = pattern[i] x2, y2 = pattern[i + 1] dist += pow(pow(x1 - x2, 2) + pow(y1 - y2, 2), 1 / 2) res = dist / cnt print(res)
false
13.333333
[ "-import itertools", "-import math", "+from itertools import permutations", "-x_y = list(input().split() for i in range(n))", "-all = list(itertools.permutations(x_y))", "-l = 0", "-for i in all:", "- for j in range(n - 1):", "- tmp = math.sqrt(", "- math.pow(int(i[j][0]) - int(i[j + 1][0]), 2)", "- + math.pow(int(i[j][1]) - int(i[j + 1][1]), 2)", "- )", "- l += tmp", "-print((l / len(all)))", "+xy = [list(map(int, input().split())) for _ in range(n)]", "+dist = 0", "+cnt = 0", "+for pattern in permutations(xy):", "+ cnt += 1", "+ for i in range(n - 1):", "+ x1, y1 = pattern[i]", "+ x2, y2 = pattern[i + 1]", "+ dist += pow(pow(x1 - x2, 2) + pow(y1 - y2, 2), 1 / 2)", "+res = dist / cnt", "+print(res)" ]
false
0.104086
0.07661
1.358644
[ "s742999080", "s594676339" ]
u600402037
p02948
python
s894097235
s723318778
475
370
27,740
23,752
Accepted
Accepted
22.11
# D - Summer Vacation from heapq import * from collections import defaultdict n, m = list(map(int, input().split())) jobs = defaultdict(list) for _ in range(n): a, b = list(map(int, input().split())) jobs[a].append(-b) result = 0 pool = [] for i in range(1, m+1): for j in jobs[i]: heappush(pool, j) if 0 < len(pool): result += -heappop(pool) print(result)
import sys from heapq import heappop, heappush sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() works = [[] for _ in range(M+1)] # M-1日後から選んでいく, for _ in range(N): a, b = lr() if a > M: continue works[a].append(-b) heap = [] answer = 0 for i in range(1, M+1): for x in works[i]: heappush(heap, x) if len(heap) == 0: continue answer += heappop(heap) answer *= -1 print(answer) # 08
19
28
397
530
# D - Summer Vacation from heapq import * from collections import defaultdict n, m = list(map(int, input().split())) jobs = defaultdict(list) for _ in range(n): a, b = list(map(int, input().split())) jobs[a].append(-b) result = 0 pool = [] for i in range(1, m + 1): for j in jobs[i]: heappush(pool, j) if 0 < len(pool): result += -heappop(pool) print(result)
import sys from heapq import heappop, heappush sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() works = [[] for _ in range(M + 1)] # M-1日後から選んでいく, for _ in range(N): a, b = lr() if a > M: continue works[a].append(-b) heap = [] answer = 0 for i in range(1, M + 1): for x in works[i]: heappush(heap, x) if len(heap) == 0: continue answer += heappop(heap) answer *= -1 print(answer) # 08
false
32.142857
[ "-# D - Summer Vacation", "-from heapq import *", "-from collections import defaultdict", "+import sys", "+from heapq import heappop, heappush", "-n, m = list(map(int, input().split()))", "-jobs = defaultdict(list)", "-for _ in range(n):", "- a, b = list(map(int, input().split()))", "- jobs[a].append(-b)", "-result = 0", "-pool = []", "-for i in range(1, m + 1):", "- for j in jobs[i]:", "- heappush(pool, j)", "- if 0 < len(pool):", "- result += -heappop(pool)", "-print(result)", "+sr = lambda: sys.stdin.readline().rstrip()", "+ir = lambda: int(sr())", "+lr = lambda: list(map(int, sr().split()))", "+N, M = lr()", "+works = [[] for _ in range(M + 1)]", "+# M-1日後から選んでいく,", "+for _ in range(N):", "+ a, b = lr()", "+ if a > M:", "+ continue", "+ works[a].append(-b)", "+heap = []", "+answer = 0", "+for i in range(1, M + 1):", "+ for x in works[i]:", "+ heappush(heap, x)", "+ if len(heap) == 0:", "+ continue", "+ answer += heappop(heap)", "+answer *= -1", "+print(answer)", "+# 08" ]
false
0.107641
0.101328
1.062305
[ "s894097235", "s723318778" ]
u821588465
p02608
python
s712548763
s587912298
950
486
50,640
9,152
Accepted
Accepted
48.84
import collections import sys input = sys.stdin.readline n= int(eval(input())) # ans = [0]*n tmp = [] for x in range(1, int(n**0.5)+1): for y in range(1, int(n**0.5)+1): for z in range(1, int(n**0.5)+1): tmp.append(x**2+y**2+z**2+x*y+y*z+z*x) cnt = collections.Counter(tmp) for i in range(1,n+1): print((cnt[i]))
n = int(eval(input())) cnt = [0]*11000 for x in range(1,101): for y in range(1, 101): for z in range(1, 101): value = x*x + y*y + z*z + x*y + y*z + z*x if value <= n: cnt[value] += 1 for i in range(1, n+1): print((cnt[i]))
16
13
352
289
import collections import sys input = sys.stdin.readline n = int(eval(input())) # ans = [0]*n tmp = [] for x in range(1, int(n**0.5) + 1): for y in range(1, int(n**0.5) + 1): for z in range(1, int(n**0.5) + 1): tmp.append(x**2 + y**2 + z**2 + x * y + y * z + z * x) cnt = collections.Counter(tmp) for i in range(1, n + 1): print((cnt[i]))
n = int(eval(input())) cnt = [0] * 11000 for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): value = x * x + y * y + z * z + x * y + y * z + z * x if value <= n: cnt[value] += 1 for i in range(1, n + 1): print((cnt[i]))
false
18.75
[ "-import collections", "-import sys", "-", "-input = sys.stdin.readline", "-# ans = [0]*n", "-tmp = []", "-for x in range(1, int(n**0.5) + 1):", "- for y in range(1, int(n**0.5) + 1):", "- for z in range(1, int(n**0.5) + 1):", "- tmp.append(x**2 + y**2 + z**2 + x * y + y * z + z * x)", "-cnt = collections.Counter(tmp)", "+cnt = [0] * 11000", "+for x in range(1, 101):", "+ for y in range(1, 101):", "+ for z in range(1, 101):", "+ value = x * x + y * y + z * z + x * y + y * z + z * x", "+ if value <= n:", "+ cnt[value] += 1" ]
false
0.067597
1.310818
0.051568
[ "s712548763", "s587912298" ]
u644907318
p02744
python
s972942550
s492426423
536
184
73,304
110,300
Accepted
Accepted
65.67
from itertools import combinations def g(i): return chr(i+96) def f(n,i): global Ind if n==0: B.append("".join(A)) return if n==1: j = Ind.pop() A[j] = g(i) B.append("".join(A)) A[j]=0 Ind.append(j) Ind = sorted(Ind) return j0 = Ind.pop(0) Ind1 = Ind[:] A[j0] = g(i) for k in range(n): for x in combinations(Ind1,n-1-k): tmp = [] for j in range(n-1-k): A[x[j]] = g(i) tmp.append(x[j]) for j in tmp: Ind.remove(j) f(k,i+1) for j in tmp: A[j] = 0 Ind.append(j) Ind = sorted(Ind) Ind.append(j0) Ind = sorted(Ind) N = int(eval(input())) A = [0 for _ in range(N)] Ind = list(range(N)) B = [] f(N,1) B = sorted(B) for b in B: print(b)
from collections import deque D1 = {i:chr(i+96) for i in range(1,27)} D2 = {val:key for key,val in list(D1.items())} N = int(eval(input())) heap = deque([(D1[1],1)]) A = [] while heap: a,n = heap.popleft() if n<N: imax = 0 for i in range(len(a)): imax = max(imax,D2[a[i]]) for i in range(1,min(imax+1,26)+1): heap.append((a+D1[i],n+1)) if n==N: A.append(a) A = sorted(list(set(A))) for i in range(len(A)): print((A[i]))
43
20
945
497
from itertools import combinations def g(i): return chr(i + 96) def f(n, i): global Ind if n == 0: B.append("".join(A)) return if n == 1: j = Ind.pop() A[j] = g(i) B.append("".join(A)) A[j] = 0 Ind.append(j) Ind = sorted(Ind) return j0 = Ind.pop(0) Ind1 = Ind[:] A[j0] = g(i) for k in range(n): for x in combinations(Ind1, n - 1 - k): tmp = [] for j in range(n - 1 - k): A[x[j]] = g(i) tmp.append(x[j]) for j in tmp: Ind.remove(j) f(k, i + 1) for j in tmp: A[j] = 0 Ind.append(j) Ind = sorted(Ind) Ind.append(j0) Ind = sorted(Ind) N = int(eval(input())) A = [0 for _ in range(N)] Ind = list(range(N)) B = [] f(N, 1) B = sorted(B) for b in B: print(b)
from collections import deque D1 = {i: chr(i + 96) for i in range(1, 27)} D2 = {val: key for key, val in list(D1.items())} N = int(eval(input())) heap = deque([(D1[1], 1)]) A = [] while heap: a, n = heap.popleft() if n < N: imax = 0 for i in range(len(a)): imax = max(imax, D2[a[i]]) for i in range(1, min(imax + 1, 26) + 1): heap.append((a + D1[i], n + 1)) if n == N: A.append(a) A = sorted(list(set(A))) for i in range(len(A)): print((A[i]))
false
53.488372
[ "-from itertools import combinations", "+from collections import deque", "-", "-def g(i):", "- return chr(i + 96)", "-", "-", "-def f(n, i):", "- global Ind", "- if n == 0:", "- B.append(\"\".join(A))", "- return", "- if n == 1:", "- j = Ind.pop()", "- A[j] = g(i)", "- B.append(\"\".join(A))", "- A[j] = 0", "- Ind.append(j)", "- Ind = sorted(Ind)", "- return", "- j0 = Ind.pop(0)", "- Ind1 = Ind[:]", "- A[j0] = g(i)", "- for k in range(n):", "- for x in combinations(Ind1, n - 1 - k):", "- tmp = []", "- for j in range(n - 1 - k):", "- A[x[j]] = g(i)", "- tmp.append(x[j])", "- for j in tmp:", "- Ind.remove(j)", "- f(k, i + 1)", "- for j in tmp:", "- A[j] = 0", "- Ind.append(j)", "- Ind = sorted(Ind)", "- Ind.append(j0)", "- Ind = sorted(Ind)", "-", "-", "+D1 = {i: chr(i + 96) for i in range(1, 27)}", "+D2 = {val: key for key, val in list(D1.items())}", "-A = [0 for _ in range(N)]", "-Ind = list(range(N))", "-B = []", "-f(N, 1)", "-B = sorted(B)", "-for b in B:", "- print(b)", "+heap = deque([(D1[1], 1)])", "+A = []", "+while heap:", "+ a, n = heap.popleft()", "+ if n < N:", "+ imax = 0", "+ for i in range(len(a)):", "+ imax = max(imax, D2[a[i]])", "+ for i in range(1, min(imax + 1, 26) + 1):", "+ heap.append((a + D1[i], n + 1))", "+ if n == N:", "+ A.append(a)", "+A = sorted(list(set(A)))", "+for i in range(len(A)):", "+ print((A[i]))" ]
false
0.082019
0.043395
1.890052
[ "s972942550", "s492426423" ]
u620945921
p03607
python
s360939581
s763741938
212
170
15,068
17,884
Accepted
Accepted
19.81
n=int(eval(input())) mydict={} for i in range(n): a=int(eval(input())) if a in mydict: if mydict[a]==1: mydict[a]=0 else: mydict[a]=1 else: mydict[a]=1 #print(mydict) mylist=list(mydict.values()) print((sum(mylist)))
mydict={} n=int(eval(input())) #print(n,a) for i in range(n): a=eval(input()) if a in mydict: del mydict[a] else: mydict[a]=1 print((len(mydict)))
17
12
250
164
n = int(eval(input())) mydict = {} for i in range(n): a = int(eval(input())) if a in mydict: if mydict[a] == 1: mydict[a] = 0 else: mydict[a] = 1 else: mydict[a] = 1 # print(mydict) mylist = list(mydict.values()) print((sum(mylist)))
mydict = {} n = int(eval(input())) # print(n,a) for i in range(n): a = eval(input()) if a in mydict: del mydict[a] else: mydict[a] = 1 print((len(mydict)))
false
29.411765
[ "+mydict = {}", "-mydict = {}", "+# print(n,a)", "- a = int(eval(input()))", "+ a = eval(input())", "- if mydict[a] == 1:", "- mydict[a] = 0", "- else:", "- mydict[a] = 1", "+ del mydict[a]", "-# print(mydict)", "-mylist = list(mydict.values())", "-print((sum(mylist)))", "+print((len(mydict)))" ]
false
0.036333
0.036183
1.004128
[ "s360939581", "s763741938" ]
u543954314
p02624
python
s845856091
s996994173
1,220
31
9,084
9,348
Accepted
Accepted
97.46
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n = ni() ans = 0 for i in range(1, n+1): v = n // i ans += v * (v + 1) // 2 * i print(ans) return solve()
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n = ni() m = int((n+1)**.5) u = n // (m + 1) ans = 0 for i in range(1, u+1): v = n // i ans += v * (v + 1) // 2 * i for i in range(m, 0, -1): v = n // i ans += (v * (v + 1) - u * (u + 1)) // 2 * i * (i + 1) // 2 u = v print(ans) return solve()
20
26
440
620
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep="\n") def solve(): n = ni() ans = 0 for i in range(1, n + 1): v = n // i ans += v * (v + 1) // 2 * i print(ans) return solve()
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep="\n") def solve(): n = ni() m = int((n + 1) ** 0.5) u = n // (m + 1) ans = 0 for i in range(1, u + 1): v = n // i ans += v * (v + 1) // 2 * i for i in range(m, 0, -1): v = n // i ans += (v * (v + 1) - u * (u + 1)) // 2 * i * (i + 1) // 2 u = v print(ans) return solve()
false
23.076923
[ "+ m = int((n + 1) ** 0.5)", "+ u = n // (m + 1)", "- for i in range(1, n + 1):", "+ for i in range(1, u + 1):", "+ for i in range(m, 0, -1):", "+ v = n // i", "+ ans += (v * (v + 1) - u * (u + 1)) // 2 * i * (i + 1) // 2", "+ u = v" ]
false
0.821259
0.037619
21.831185
[ "s845856091", "s996994173" ]
u941438707
p03659
python
s488507713
s311515669
167
149
30,424
30,372
Accepted
Accepted
10.78
n,*a=list(map(int,open(0).read().split())) ans=10**100 b=sum(a) c=0 for i in a[:-1]: c+=i b-=i ans=min(ans,abs(b-c)) print(ans)
n,*a=list(map(int,open(0).read().split())) b=sum(a) c=a[0] ans=abs(2*c-b) for i in a[1:-1]: c+=i ans=min(ans,abs(2*c-b)) print(ans)
9
8
138
140
n, *a = list(map(int, open(0).read().split())) ans = 10**100 b = sum(a) c = 0 for i in a[:-1]: c += i b -= i ans = min(ans, abs(b - c)) print(ans)
n, *a = list(map(int, open(0).read().split())) b = sum(a) c = a[0] ans = abs(2 * c - b) for i in a[1:-1]: c += i ans = min(ans, abs(2 * c - b)) print(ans)
false
11.111111
[ "-ans = 10**100", "-c = 0", "-for i in a[:-1]:", "+c = a[0]", "+ans = abs(2 * c - b)", "+for i in a[1:-1]:", "- b -= i", "- ans = min(ans, abs(b - c))", "+ ans = min(ans, abs(2 * c - b))" ]
false
0.044797
0.038214
1.172264
[ "s488507713", "s311515669" ]
u493520238
p03112
python
s284546020
s926817120
1,659
921
94,936
73,308
Accepted
Accepted
44.48
import bisect def main(): a,b,q = list(map(int, input().split())) sl = [int(eval(input())) for _ in range(a)] tl = [int(eval(input())) for _ in range(b)] xl = [int(eval(input())) for _ in range(q)] for x in xl: ans = 10**11 curr_dist = 0 ind_s = bisect.bisect_left(sl, x) ind_t = bisect.bisect_left(tl, x) for next_s in [ind_s, ind_s-1]: if 0 <= next_s < a: curr_dist = abs(x-sl[next_s]) curr_pos = sl[next_s] ind_t2 = bisect.bisect_left(tl, curr_pos) if ind_t2 == 0: curr_dist += abs(tl[0] - curr_pos) elif ind_t2 == b: curr_dist += abs(tl[b-1] - curr_pos) else: curr_dist += min( abs( tl[ind_t2-1] - curr_pos), abs(tl[ind_t2]-curr_pos)) ans = min(curr_dist, ans) for next_t in [ind_t, ind_t-1]: if 0 <= next_t < b: curr_dist = abs(x-tl[next_t]) curr_pos = tl[next_t] ind_s2 = bisect.bisect_left(sl, curr_pos) if ind_s2 == 0: curr_dist += abs(sl[0] - curr_pos) elif ind_s2 == a: curr_dist += abs(sl[a-1] - curr_pos) else: curr_dist += min( abs( sl[ind_s2-1] - curr_pos), abs(sl[ind_s2]-curr_pos)) ans = min(curr_dist, ans) print(ans) if __name__ == "__main__": main()
import bisect import sys input = sys.stdin.readline def main(): a,b,q = list(map(int, input().split())) sl = [int(eval(input())) for _ in range(a)] tl = [int(eval(input())) for _ in range(b)] xl = [int(eval(input())) for _ in range(q)] for x in xl: ans = 10**11 curr_dist = 0 ind_s = bisect.bisect_left(sl, x) ind_t = bisect.bisect_left(tl, x) for next_s in [ind_s, ind_s-1]: if 0 <= next_s < a: curr_dist = abs(x-sl[next_s]) curr_pos = sl[next_s] ind_t2 = bisect.bisect_left(tl, curr_pos) if ind_t2 == 0: curr_dist += abs(tl[0] - curr_pos) elif ind_t2 == b: curr_dist += abs(tl[b-1] - curr_pos) else: curr_dist += min( abs( tl[ind_t2-1] - curr_pos), abs(tl[ind_t2]-curr_pos)) ans = min(curr_dist, ans) for next_t in [ind_t, ind_t-1]: if 0 <= next_t < b: curr_dist = abs(x-tl[next_t]) curr_pos = tl[next_t] ind_s2 = bisect.bisect_left(sl, curr_pos) if ind_s2 == 0: curr_dist += abs(sl[0] - curr_pos) elif ind_s2 == a: curr_dist += abs(sl[a-1] - curr_pos) else: curr_dist += min( abs( sl[ind_s2-1] - curr_pos), abs(sl[ind_s2]-curr_pos)) ans = min(curr_dist, ans) print(ans) if __name__ == "__main__": main()
48
50
1,557
1,597
import bisect def main(): a, b, q = list(map(int, input().split())) sl = [int(eval(input())) for _ in range(a)] tl = [int(eval(input())) for _ in range(b)] xl = [int(eval(input())) for _ in range(q)] for x in xl: ans = 10**11 curr_dist = 0 ind_s = bisect.bisect_left(sl, x) ind_t = bisect.bisect_left(tl, x) for next_s in [ind_s, ind_s - 1]: if 0 <= next_s < a: curr_dist = abs(x - sl[next_s]) curr_pos = sl[next_s] ind_t2 = bisect.bisect_left(tl, curr_pos) if ind_t2 == 0: curr_dist += abs(tl[0] - curr_pos) elif ind_t2 == b: curr_dist += abs(tl[b - 1] - curr_pos) else: curr_dist += min( abs(tl[ind_t2 - 1] - curr_pos), abs(tl[ind_t2] - curr_pos) ) ans = min(curr_dist, ans) for next_t in [ind_t, ind_t - 1]: if 0 <= next_t < b: curr_dist = abs(x - tl[next_t]) curr_pos = tl[next_t] ind_s2 = bisect.bisect_left(sl, curr_pos) if ind_s2 == 0: curr_dist += abs(sl[0] - curr_pos) elif ind_s2 == a: curr_dist += abs(sl[a - 1] - curr_pos) else: curr_dist += min( abs(sl[ind_s2 - 1] - curr_pos), abs(sl[ind_s2] - curr_pos) ) ans = min(curr_dist, ans) print(ans) if __name__ == "__main__": main()
import bisect import sys input = sys.stdin.readline def main(): a, b, q = list(map(int, input().split())) sl = [int(eval(input())) for _ in range(a)] tl = [int(eval(input())) for _ in range(b)] xl = [int(eval(input())) for _ in range(q)] for x in xl: ans = 10**11 curr_dist = 0 ind_s = bisect.bisect_left(sl, x) ind_t = bisect.bisect_left(tl, x) for next_s in [ind_s, ind_s - 1]: if 0 <= next_s < a: curr_dist = abs(x - sl[next_s]) curr_pos = sl[next_s] ind_t2 = bisect.bisect_left(tl, curr_pos) if ind_t2 == 0: curr_dist += abs(tl[0] - curr_pos) elif ind_t2 == b: curr_dist += abs(tl[b - 1] - curr_pos) else: curr_dist += min( abs(tl[ind_t2 - 1] - curr_pos), abs(tl[ind_t2] - curr_pos) ) ans = min(curr_dist, ans) for next_t in [ind_t, ind_t - 1]: if 0 <= next_t < b: curr_dist = abs(x - tl[next_t]) curr_pos = tl[next_t] ind_s2 = bisect.bisect_left(sl, curr_pos) if ind_s2 == 0: curr_dist += abs(sl[0] - curr_pos) elif ind_s2 == a: curr_dist += abs(sl[a - 1] - curr_pos) else: curr_dist += min( abs(sl[ind_s2 - 1] - curr_pos), abs(sl[ind_s2] - curr_pos) ) ans = min(curr_dist, ans) print(ans) if __name__ == "__main__": main()
false
4
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.079177
0.112736
0.702317
[ "s284546020", "s926817120" ]
u218843509
p03027
python
s285564490
s467346541
1,781
1,240
44,820
45,060
Accepted
Accepted
30.38
MOD = 1000003 q = int(eval(input())) cumprod = [1] for i in range(1, MOD): cumprod.append((cumprod[-1] * i) % MOD) def calc(l, r): return (cumprod[r] * pow(cumprod[l-1], MOD-2, MOD)) % MOD def solve(x, d, n): if x == 0: return 0 elif d == 0: return pow(x, n, MOD) else: l = (x * pow(d, MOD-2, MOD)) % MOD if l+n-1 >= MOD: return 0 else: return (calc(l, l+n-1) * pow(d, n, MOD)) % MOD for _ in range(q): x, d, n = list(map(int, input().split())) print((solve(x, d, n)))
import sys def input(): return sys.stdin.readline()[:-1] MOD = 1000003 q = int(eval(input())) cumprod = [1] for i in range(1, MOD): cumprod.append((cumprod[-1] * i) % MOD) def calc(l, r): return (cumprod[r] * pow(cumprod[l-1], MOD-2, MOD)) % MOD def solve(x, d, n): if x == 0: return 0 elif d == 0: return pow(x, n, MOD) else: l = (x * pow(d, MOD-2, MOD)) % MOD if l+n-1 >= MOD: return 0 else: return (calc(l, l+n-1) * pow(d, n, MOD)) % MOD for _ in range(q): x, d, n = list(map(int, input().split())) print((solve(x, d, n)))
24
28
503
566
MOD = 1000003 q = int(eval(input())) cumprod = [1] for i in range(1, MOD): cumprod.append((cumprod[-1] * i) % MOD) def calc(l, r): return (cumprod[r] * pow(cumprod[l - 1], MOD - 2, MOD)) % MOD def solve(x, d, n): if x == 0: return 0 elif d == 0: return pow(x, n, MOD) else: l = (x * pow(d, MOD - 2, MOD)) % MOD if l + n - 1 >= MOD: return 0 else: return (calc(l, l + n - 1) * pow(d, n, MOD)) % MOD for _ in range(q): x, d, n = list(map(int, input().split())) print((solve(x, d, n)))
import sys def input(): return sys.stdin.readline()[:-1] MOD = 1000003 q = int(eval(input())) cumprod = [1] for i in range(1, MOD): cumprod.append((cumprod[-1] * i) % MOD) def calc(l, r): return (cumprod[r] * pow(cumprod[l - 1], MOD - 2, MOD)) % MOD def solve(x, d, n): if x == 0: return 0 elif d == 0: return pow(x, n, MOD) else: l = (x * pow(d, MOD - 2, MOD)) % MOD if l + n - 1 >= MOD: return 0 else: return (calc(l, l + n - 1) * pow(d, n, MOD)) % MOD for _ in range(q): x, d, n = list(map(int, input().split())) print((solve(x, d, n)))
false
14.285714
[ "+import sys", "+", "+", "+def input():", "+ return sys.stdin.readline()[:-1]", "+", "+" ]
false
0.544071
0.496539
1.095727
[ "s285564490", "s467346541" ]
u908984540
p02262
python
s285181700
s747433840
21,520
18,130
47,616
45,512
Accepted
Accepted
15.75
# -*- coding:utf-8 -*- import math def insertion_sort(num_list, length, interval): cnt = 0 for i in range(interval, length): v = num_list[i] j = i - interval while j >= 0 and num_list[j] > v: num_list[j+interval] = num_list[j] j = j - interval cnt = cnt + 1 num_list[j+interval] = v return cnt def shell_sort(num_list, length): cnt = 0 h = 4 intervals = [1,] while length > h: intervals.append(h) h = 3 * h + 1 for i in reversed(list(range(len(intervals)))): cnt = cnt + insertion_sort(num_list, length, intervals[i]) print((len(intervals))) print((*reversed(intervals))) print(cnt) input_num = int(eval(input())) input_list = list() for i in range(input_num): input_list.append(int(eval(input()))) shell_sort(input_list, input_num) for num in input_list: print(num)
def insertion_sort(A, g): cnt = 0 for i in range(g, len(A)): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j -= g cnt += 1 A[j+g] = v return cnt def shell_sort(A): cnt = 0 h = 1 G = [] while h <= len(A)/2: G.append(h) h = 3 * h + 1 if len(G) == 0: G.append(1) print((len(G))) print((*G[::-1])) for g_i in G[::-1]: cnt += insertion_sort(A, g_i) return cnt if __name__ == '__main__': n = int(eval(input())) A = [] for i in range(n): A.append(int(eval(input()))) print((shell_sort(A))) for a in A: print(a)
36
37
927
724
# -*- coding:utf-8 -*- import math def insertion_sort(num_list, length, interval): cnt = 0 for i in range(interval, length): v = num_list[i] j = i - interval while j >= 0 and num_list[j] > v: num_list[j + interval] = num_list[j] j = j - interval cnt = cnt + 1 num_list[j + interval] = v return cnt def shell_sort(num_list, length): cnt = 0 h = 4 intervals = [ 1, ] while length > h: intervals.append(h) h = 3 * h + 1 for i in reversed(list(range(len(intervals)))): cnt = cnt + insertion_sort(num_list, length, intervals[i]) print((len(intervals))) print((*reversed(intervals))) print(cnt) input_num = int(eval(input())) input_list = list() for i in range(input_num): input_list.append(int(eval(input()))) shell_sort(input_list, input_num) for num in input_list: print(num)
def insertion_sort(A, g): cnt = 0 for i in range(g, len(A)): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j + g] = A[j] j -= g cnt += 1 A[j + g] = v return cnt def shell_sort(A): cnt = 0 h = 1 G = [] while h <= len(A) / 2: G.append(h) h = 3 * h + 1 if len(G) == 0: G.append(1) print((len(G))) print((*G[::-1])) for g_i in G[::-1]: cnt += insertion_sort(A, g_i) return cnt if __name__ == "__main__": n = int(eval(input())) A = [] for i in range(n): A.append(int(eval(input()))) print((shell_sort(A))) for a in A: print(a)
false
2.702703
[ "-# -*- coding:utf-8 -*-", "-import math", "-", "-", "-def insertion_sort(num_list, length, interval):", "+def insertion_sort(A, g):", "- for i in range(interval, length):", "- v = num_list[i]", "- j = i - interval", "- while j >= 0 and num_list[j] > v:", "- num_list[j + interval] = num_list[j]", "- j = j - interval", "- cnt = cnt + 1", "- num_list[j + interval] = v", "+ for i in range(g, len(A)):", "+ v = A[i]", "+ j = i - g", "+ while j >= 0 and A[j] > v:", "+ A[j + g] = A[j]", "+ j -= g", "+ cnt += 1", "+ A[j + g] = v", "-def shell_sort(num_list, length):", "+def shell_sort(A):", "- h = 4", "- intervals = [", "- 1,", "- ]", "- while length > h:", "- intervals.append(h)", "+ h = 1", "+ G = []", "+ while h <= len(A) / 2:", "+ G.append(h)", "- for i in reversed(list(range(len(intervals)))):", "- cnt = cnt + insertion_sort(num_list, length, intervals[i])", "- print((len(intervals)))", "- print((*reversed(intervals)))", "- print(cnt)", "+ if len(G) == 0:", "+ G.append(1)", "+ print((len(G)))", "+ print((*G[::-1]))", "+ for g_i in G[::-1]:", "+ cnt += insertion_sort(A, g_i)", "+ return cnt", "-input_num = int(eval(input()))", "-input_list = list()", "-for i in range(input_num):", "- input_list.append(int(eval(input())))", "-shell_sort(input_list, input_num)", "-for num in input_list:", "- print(num)", "+if __name__ == \"__main__\":", "+ n = int(eval(input()))", "+ A = []", "+ for i in range(n):", "+ A.append(int(eval(input())))", "+ print((shell_sort(A)))", "+ for a in A:", "+ print(a)" ]
false
0.036091
0.057107
0.631979
[ "s285181700", "s747433840" ]
u936985471
p02883
python
s043278129
s506336357
1,829
454
122,700
37,220
Accepted
Accepted
75.18
n,k=list(map(int,input().split())) a=list(map(int,input().split())) f=list(map(int,input().split())) a=sorted(a)[::-1] f=sorted(f) ok=10**18 ng=-1 import math def isOK(val,arr,farr,k): s=0 for i in range(len(arr)): s+=max(math.ceil(a[i]-val/f[i]),0) return s<=k while abs(ok-ng)>1: mid=abs(ok+ng)//2 if isOK(mid,a,f,k): ok=mid else: ng=mid print(ok)
import numpy as np n,k=list(map(int,input().split())) a=np.array(input().split(),dtype=int) f=np.array(input().split(),dtype=int) a=np.sort(a)[::-1] f=np.sort(f) ok=10**18 ng=-1 import math def isOK(val,arr,farr,k): return arr.sum()-np.minimum(arr,val//farr).sum()<=k while abs(ok-ng)>1: mid=abs(ok+ng)//2 if isOK(mid,a,f,k): ok=mid else: ng=mid print(ok)
25
24
403
401
n, k = list(map(int, input().split())) a = list(map(int, input().split())) f = list(map(int, input().split())) a = sorted(a)[::-1] f = sorted(f) ok = 10**18 ng = -1 import math def isOK(val, arr, farr, k): s = 0 for i in range(len(arr)): s += max(math.ceil(a[i] - val / f[i]), 0) return s <= k while abs(ok - ng) > 1: mid = abs(ok + ng) // 2 if isOK(mid, a, f, k): ok = mid else: ng = mid print(ok)
import numpy as np n, k = list(map(int, input().split())) a = np.array(input().split(), dtype=int) f = np.array(input().split(), dtype=int) a = np.sort(a)[::-1] f = np.sort(f) ok = 10**18 ng = -1 import math def isOK(val, arr, farr, k): return arr.sum() - np.minimum(arr, val // farr).sum() <= k while abs(ok - ng) > 1: mid = abs(ok + ng) // 2 if isOK(mid, a, f, k): ok = mid else: ng = mid print(ok)
false
4
[ "+import numpy as np", "+", "-a = list(map(int, input().split()))", "-f = list(map(int, input().split()))", "-a = sorted(a)[::-1]", "-f = sorted(f)", "+a = np.array(input().split(), dtype=int)", "+f = np.array(input().split(), dtype=int)", "+a = np.sort(a)[::-1]", "+f = np.sort(f)", "- s = 0", "- for i in range(len(arr)):", "- s += max(math.ceil(a[i] - val / f[i]), 0)", "- return s <= k", "+ return arr.sum() - np.minimum(arr, val // farr).sum() <= k" ]
false
0.085661
0.248671
0.344475
[ "s043278129", "s506336357" ]
u796942881
p02899
python
s973809209
s503840293
159
74
29,772
17,736
Accepted
Accepted
53.46
from operator import itemgetter def main(): A = {k + 1: v for k, v in enumerate(map(int, open(0).read().split()[1:]))} # value `昇順 print((" ".join([str(i[0]) for i in sorted(list(A.items()), key=itemgetter(1))]))) return main()
def main(): N, *A = list(map(int, open(0).read().split())) ans = [0] * N for k, v in enumerate(A, 1): ans[v - 1] = k print((" ".join([str(a) for a in ans]))) return main()
11
10
250
203
from operator import itemgetter def main(): A = {k + 1: v for k, v in enumerate(map(int, open(0).read().split()[1:]))} # value `昇順 print((" ".join([str(i[0]) for i in sorted(list(A.items()), key=itemgetter(1))]))) return main()
def main(): N, *A = list(map(int, open(0).read().split())) ans = [0] * N for k, v in enumerate(A, 1): ans[v - 1] = k print((" ".join([str(a) for a in ans]))) return main()
false
9.090909
[ "-from operator import itemgetter", "-", "-", "- A = {k + 1: v for k, v in enumerate(map(int, open(0).read().split()[1:]))}", "- # value `昇順", "- print((\" \".join([str(i[0]) for i in sorted(list(A.items()), key=itemgetter(1))])))", "+ N, *A = list(map(int, open(0).read().split()))", "+ ans = [0] * N", "+ for k, v in enumerate(A, 1):", "+ ans[v - 1] = k", "+ print((\" \".join([str(a) for a in ans])))" ]
false
0.035593
0.036896
0.964693
[ "s973809209", "s503840293" ]
u698771758
p02971
python
s735092523
s774738517
648
546
18,872
14,112
Accepted
Accepted
15.74
N=int(eval(input())) A=[int(eval(input())) for i in range(N)] LM=[0,A[0]] a=A[::-1] RM=[a[0]] for i in range(1,N-1): LM.append(max(LM[-1],A[i])) RM.append(max(RM[-1],a[i])) RM=RM[::-1]+[0] for i in range(N): print((max(LM[i],RM[i])))
N=int(eval(input())) A=[int(eval(input())) for i in range(N)] M=A[::-1] M.sort() for i in A: if i==M[-1]:print((M[-2])) else:print((M[-1]))
11
7
241
137
N = int(eval(input())) A = [int(eval(input())) for i in range(N)] LM = [0, A[0]] a = A[::-1] RM = [a[0]] for i in range(1, N - 1): LM.append(max(LM[-1], A[i])) RM.append(max(RM[-1], a[i])) RM = RM[::-1] + [0] for i in range(N): print((max(LM[i], RM[i])))
N = int(eval(input())) A = [int(eval(input())) for i in range(N)] M = A[::-1] M.sort() for i in A: if i == M[-1]: print((M[-2])) else: print((M[-1]))
false
36.363636
[ "-LM = [0, A[0]]", "-a = A[::-1]", "-RM = [a[0]]", "-for i in range(1, N - 1):", "- LM.append(max(LM[-1], A[i]))", "- RM.append(max(RM[-1], a[i]))", "-RM = RM[::-1] + [0]", "-for i in range(N):", "- print((max(LM[i], RM[i])))", "+M = A[::-1]", "+M.sort()", "+for i in A:", "+ if i == M[-1]:", "+ print((M[-2]))", "+ else:", "+ print((M[-1]))" ]
false
0.087947
0.074393
1.182191
[ "s735092523", "s774738517" ]
u744920373
p02972
python
s263505049
s637940693
1,473
1,035
10,704
8,600
Accepted
Accepted
29.74
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)] def dp2(ini, i, j): return [[ini]*i for i2 in range(j)] def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)] #import bisect #bisect.bisect_left(B, a) #from collections import defaultdict #d = defaultdict(int) d[key] += value N = ii() A = li() A_f = A[:N//2] A_l = A[N//2:] table = [0] * (N//2) for i in reversed(list(range(N//2))): ind = i+1 while(ind-1 < N): if ind-1 < N//2 and ind!=i+1: table[i] += table[ind-1] else: table[i] += A[ind-1] ind += i+1 table[i] %= 2 table += A_l ans = '' print((sum(table))) for i in range(N): if table[i]%2 == 1: ans += str(i+1) + ' ' print(ans)
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)] def dp2(ini, i, j): return [[ini]*i for i2 in range(j)] def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)] #import bisect #bisect.bisect_left(B, a) #from collections import defaultdict #d = defaultdict(int) d[key] += value N = ii() A = li() for i in reversed(list(range(N))): #for i in reversed(range(N//2)): ind = 2*(i+1) while(ind-1 < N): A[i] ^= A[ind-1] ind += i+1 print((sum(A))) ans = '' for i in range(N): if A[i] == 1: ans += str(i+1) + ' ' if ans != '': print((ans[:-1]))
39
29
1,009
859
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)] def dp2(ini, i, j): return [[ini] * i for i2 in range(j)] def dp3(ini, i, j, k): return [[[ini] * i for i2 in range(j)] for i3 in range(k)] # import bisect #bisect.bisect_left(B, a) # from collections import defaultdict #d = defaultdict(int) d[key] += value N = ii() A = li() A_f = A[: N // 2] A_l = A[N // 2 :] table = [0] * (N // 2) for i in reversed(list(range(N // 2))): ind = i + 1 while ind - 1 < N: if ind - 1 < N // 2 and ind != i + 1: table[i] += table[ind - 1] else: table[i] += A[ind - 1] ind += i + 1 table[i] %= 2 table += A_l ans = "" print((sum(table))) for i in range(N): if table[i] % 2 == 1: ans += str(i + 1) + " " print(ans)
import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)] def dp2(ini, i, j): return [[ini] * i for i2 in range(j)] def dp3(ini, i, j, k): return [[[ini] * i for i2 in range(j)] for i3 in range(k)] # import bisect #bisect.bisect_left(B, a) # from collections import defaultdict #d = defaultdict(int) d[key] += value N = ii() A = li() for i in reversed(list(range(N))): # for i in reversed(range(N//2)): ind = 2 * (i + 1) while ind - 1 < N: A[i] ^= A[ind - 1] ind += i + 1 print((sum(A))) ans = "" for i in range(N): if A[i] == 1: ans += str(i + 1) + " " if ans != "": print((ans[:-1]))
false
25.641026
[ "-A_f = A[: N // 2]", "-A_l = A[N // 2 :]", "-table = [0] * (N // 2)", "-for i in reversed(list(range(N // 2))):", "- ind = i + 1", "+for i in reversed(list(range(N))):", "+ # for i in reversed(range(N//2)):", "+ ind = 2 * (i + 1)", "- if ind - 1 < N // 2 and ind != i + 1:", "- table[i] += table[ind - 1]", "- else:", "- table[i] += A[ind - 1]", "+ A[i] ^= A[ind - 1]", "- table[i] %= 2", "-table += A_l", "+print((sum(A)))", "-print((sum(table)))", "- if table[i] % 2 == 1:", "+ if A[i] == 1:", "-print(ans)", "+if ans != \"\":", "+ print((ans[:-1]))" ]
false
0.081014
0.03718
2.178947
[ "s263505049", "s637940693" ]
u225388820
p02806
python
s324271590
s300483007
170
17
38,256
3,060
Accepted
Accepted
90
n=int(eval(input())) s=[0]*n t=[0]*n for i in range(n): a,b=input().split() b=int(b) s[i]=a t[i]=b x=eval(input()) ans=sum(t) for i in range(n): if s[i]==x: print((ans-t[i])) exit() else: ans-=t[i]
n=int(eval(input())) s=[0]*n t=[0]*n for i in range(n): s[i],t[i]=input().split() t[i]=int(t[i]) print((sum(t[s.index(eval(input()))+1:])))
16
7
246
139
n = int(eval(input())) s = [0] * n t = [0] * n for i in range(n): a, b = input().split() b = int(b) s[i] = a t[i] = b x = eval(input()) ans = sum(t) for i in range(n): if s[i] == x: print((ans - t[i])) exit() else: ans -= t[i]
n = int(eval(input())) s = [0] * n t = [0] * n for i in range(n): s[i], t[i] = input().split() t[i] = int(t[i]) print((sum(t[s.index(eval(input())) + 1 :])))
false
56.25
[ "- a, b = input().split()", "- b = int(b)", "- s[i] = a", "- t[i] = b", "-x = eval(input())", "-ans = sum(t)", "-for i in range(n):", "- if s[i] == x:", "- print((ans - t[i]))", "- exit()", "- else:", "- ans -= t[i]", "+ s[i], t[i] = input().split()", "+ t[i] = int(t[i])", "+print((sum(t[s.index(eval(input())) + 1 :])))" ]
false
0.036856
0.034505
1.068139
[ "s324271590", "s300483007" ]
u952708174
p02732
python
s523589415
s261631239
888
205
39,480
39,300
Accepted
Accepted
76.91
from functools import reduce def d_banned_k(): from collections import Counter from functools import reduce N = int(eval(input())) A = [int(i) for i in input().split()] def comb(n, r): numerator = reduce(lambda x, y: x * y, list(range(n, n - r, -1))) denominator = reduce(lambda x, y: x * y, list(range(1, r + 1))) return numerator // denominator count = Counter(A) total = sum(comb(c, 2) for c in list(count.values())) ans = [] for a in A: v = count[a] ans.append(total - comb(v, 2) + comb(v - 1, 2)) return ' '.join(map(str, ans)) print((d_banned_k()))
def d_banned_k(): from collections import Counter N = int(eval(input())) A = [int(i) for i in input().split()] count = Counter(A) total = sum(c * (c - 1) // 2 for c in list(count.values())) ans = [total - (count[a] - 1) for a in A] return ' '.join(map(str, ans)) print((d_banned_k()))
21
12
603
312
from functools import reduce def d_banned_k(): from collections import Counter from functools import reduce N = int(eval(input())) A = [int(i) for i in input().split()] def comb(n, r): numerator = reduce(lambda x, y: x * y, list(range(n, n - r, -1))) denominator = reduce(lambda x, y: x * y, list(range(1, r + 1))) return numerator // denominator count = Counter(A) total = sum(comb(c, 2) for c in list(count.values())) ans = [] for a in A: v = count[a] ans.append(total - comb(v, 2) + comb(v - 1, 2)) return " ".join(map(str, ans)) print((d_banned_k()))
def d_banned_k(): from collections import Counter N = int(eval(input())) A = [int(i) for i in input().split()] count = Counter(A) total = sum(c * (c - 1) // 2 for c in list(count.values())) ans = [total - (count[a] - 1) for a in A] return " ".join(map(str, ans)) print((d_banned_k()))
false
42.857143
[ "-from functools import reduce", "-", "-", "- from functools import reduce", "-", "- def comb(n, r):", "- numerator = reduce(lambda x, y: x * y, list(range(n, n - r, -1)))", "- denominator = reduce(lambda x, y: x * y, list(range(1, r + 1)))", "- return numerator // denominator", "-", "- total = sum(comb(c, 2) for c in list(count.values()))", "- ans = []", "- for a in A:", "- v = count[a]", "- ans.append(total - comb(v, 2) + comb(v - 1, 2))", "+ total = sum(c * (c - 1) // 2 for c in list(count.values()))", "+ ans = [total - (count[a] - 1) for a in A]" ]
false
0.039855
0.040098
0.993952
[ "s523589415", "s261631239" ]