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
u606090886
p02989
python
s373709386
s742562643
835
76
14,556
14,396
Accepted
Accepted
90.9
n = int(eval(input())) d = list(map(int,input().split())) d.sort() while len(d) > 0: x = d.pop() y = d.pop(0) print((x - y))
n = int(eval(input())) d = list(map(int,input().split())) d.sort() h = len(d)//2 x = d[h] y = d[h - 1] print((x - y))
7
7
138
116
n = int(eval(input())) d = list(map(int, input().split())) d.sort() while len(d) > 0: x = d.pop() y = d.pop(0) print((x - y))
n = int(eval(input())) d = list(map(int, input().split())) d.sort() h = len(d) // 2 x = d[h] y = d[h - 1] print((x - y))
false
0
[ "-while len(d) > 0:", "- x = d.pop()", "- y = d.pop(0)", "+h = len(d) // 2", "+x = d[h]", "+y = d[h - 1]" ]
false
0.082499
0.03438
2.399627
[ "s373709386", "s742562643" ]
u803848678
p03525
python
s947761312
s490534460
207
186
40,944
40,304
Accepted
Accepted
10.14
n = int(eval(input())) d = list(map(int, input().split())) h = [0]*13 for i in d: h[i] += 1 ans = 0 def rec(now, state): global ans if now == 13: state.sort() m = float("Inf") for i in range(len(state)): m = min(m, min(abs(state[i-1]-state[i]), 24-abs(state[i-1]-state[i]))) ans = max(ans, m) elif now == 0: if h[now]: return rec(now+1, state) elif now == 12: if h[now]==0: rec(now+1, state) elif h[now]==1: state.append(now) rec(now+1, state) else: if h[now]==0: rec(now+1, state) elif h[now]==1: s = state[:] s.append(now) rec(now+1,s) s = state[:] s.append(24-now) rec(now+1, s) elif h[now]==2: state.append(now) state.append(24-now) rec(now+1, state) rec(0, [0]) print(ans)
n = int(eval(input())) a = [0]*13 for i in map(int, input().split()): a[i] += 1 ans = 0 if any(i>2 for i in a) or a[0] or a[12]>1: pass else: s = [[0]] for i in range(1, 13): nxt = [] if a[i] == 0: nxt = s elif a[i] == 1: for si in s: nxt.append(si+[i]) nxt.append(si+[24-i]) else: for si in s: nxt.append(si+[i, 24-i]) s = nxt for si in s: si.sort() tmp = float("Inf") for i in range(len(si)): k = abs(si[i]-si[i-1]) k = min(k, 24-k) tmp = min(tmp, k) ans = max(ans, tmp) print(ans)
41
31
1,004
720
n = int(eval(input())) d = list(map(int, input().split())) h = [0] * 13 for i in d: h[i] += 1 ans = 0 def rec(now, state): global ans if now == 13: state.sort() m = float("Inf") for i in range(len(state)): m = min( m, min(abs(state[i - 1] - state[i]), 24 - abs(state[i - 1] - state[i])) ) ans = max(ans, m) elif now == 0: if h[now]: return rec(now + 1, state) elif now == 12: if h[now] == 0: rec(now + 1, state) elif h[now] == 1: state.append(now) rec(now + 1, state) else: if h[now] == 0: rec(now + 1, state) elif h[now] == 1: s = state[:] s.append(now) rec(now + 1, s) s = state[:] s.append(24 - now) rec(now + 1, s) elif h[now] == 2: state.append(now) state.append(24 - now) rec(now + 1, state) rec(0, [0]) print(ans)
n = int(eval(input())) a = [0] * 13 for i in map(int, input().split()): a[i] += 1 ans = 0 if any(i > 2 for i in a) or a[0] or a[12] > 1: pass else: s = [[0]] for i in range(1, 13): nxt = [] if a[i] == 0: nxt = s elif a[i] == 1: for si in s: nxt.append(si + [i]) nxt.append(si + [24 - i]) else: for si in s: nxt.append(si + [i, 24 - i]) s = nxt for si in s: si.sort() tmp = float("Inf") for i in range(len(si)): k = abs(si[i] - si[i - 1]) k = min(k, 24 - k) tmp = min(tmp, k) ans = max(ans, tmp) print(ans)
false
24.390244
[ "-d = list(map(int, input().split()))", "-h = [0] * 13", "-for i in d:", "- h[i] += 1", "+a = [0] * 13", "+for i in map(int, input().split()):", "+ a[i] += 1", "-", "-", "-def rec(now, state):", "- global ans", "- if now == 13:", "- state.sort()", "- m = float(\"I...
false
0.057186
0.039069
1.463697
[ "s947761312", "s490534460" ]
u489959379
p03565
python
s826705707
s328886888
23
17
3,444
3,064
Accepted
Accepted
26.09
import copy s = eval(input()) t = eval(input()) n = len(t) ans = set() flg = False for i in range(len(s)): tmp = s[i: i + n] for j in range(n): try: if tmp[j] != "?" and tmp[j] != t[j]: flg = False break else: flg = True except IndexError: flg = False break if flg: if len(ans) > 0: ans.clear() s_1_l = list(copy.deepcopy(s)) for k in range(len(s_1_l)): if s_1_l[k] == "?": s_1_l[k] = "a" s_1_l[i: i + n] = t ans.add("".join(s_1_l)) if len(ans) == 0: print("UNRESTORABLE") else: print((*ans))
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): s = eval(input()) t = eval(input()) n = len(s) res = [] for i in range(n): ss = list(s) if (s[i] == t[0] or s[i] == "?") and i + len(t) <= n: pos = 0 for j in range(i, i + len(t)): if s[j] != "?" and s[j] != t[pos]: break pos += 1 else: pos = 0 for j in range(i, i + len(t)): ss[j] = t[pos] pos += 1 ss = "".join(ss).replace("?", "a") res.append(ss) if len(res) == 0: print("UNRESTORABLE") else: res = sorted(res) print((res[0])) if __name__ == '__main__': resolve()
34
38
727
857
import copy s = eval(input()) t = eval(input()) n = len(t) ans = set() flg = False for i in range(len(s)): tmp = s[i : i + n] for j in range(n): try: if tmp[j] != "?" and tmp[j] != t[j]: flg = False break else: flg = True except IndexError: flg = False break if flg: if len(ans) > 0: ans.clear() s_1_l = list(copy.deepcopy(s)) for k in range(len(s_1_l)): if s_1_l[k] == "?": s_1_l[k] = "a" s_1_l[i : i + n] = t ans.add("".join(s_1_l)) if len(ans) == 0: print("UNRESTORABLE") else: print((*ans))
import sys sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 def resolve(): s = eval(input()) t = eval(input()) n = len(s) res = [] for i in range(n): ss = list(s) if (s[i] == t[0] or s[i] == "?") and i + len(t) <= n: pos = 0 for j in range(i, i + len(t)): if s[j] != "?" and s[j] != t[pos]: break pos += 1 else: pos = 0 for j in range(i, i + len(t)): ss[j] = t[pos] pos += 1 ss = "".join(ss).replace("?", "a") res.append(ss) if len(res) == 0: print("UNRESTORABLE") else: res = sorted(res) print((res[0])) if __name__ == "__main__": resolve()
false
10.526316
[ "-import copy", "+import sys", "-s = eval(input())", "-t = eval(input())", "-n = len(t)", "-ans = set()", "-flg = False", "-for i in range(len(s)):", "- tmp = s[i : i + n]", "- for j in range(n):", "- try:", "- if tmp[j] != \"?\" and tmp[j] != t[j]:", "- ...
false
0.041863
0.037874
1.105314
[ "s826705707", "s328886888" ]
u695811449
p03847
python
s725438402
s407398317
20
18
3,064
3,064
Accepted
Accepted
10
N=int(eval(input())) mod=10**9+7 ANSLIST=[1] for i in range(61): ANSLIST.append((ANSLIST[-1]*3-1)%mod) ANS=[1, 2, 4, 5] ANSDICT=dict() def ans(k): if 0<=k<=3: return ANS[k] if ANSDICT.get(k)!=None: return ANSDICT[k] for i in range(61): if k==2**i-2: return ANSLIST[i]-1 if k==2**i-1: return ANSLIST[i] if 2**i-1>k: break x=k-(2**(i-1)-1) ANSDICT[k]=(ans(x-1)+ANSLIST[i-1]*2-ans(2**(i-1)-x-2)-1)%mod return ANSDICT[k] print((ans(N)))
import sys sys.setrecursionlimit(10**9) N=int(eval(input())) mod=10**9+7 DP=dict() DP[(0,0)]=1#a+b,a^b DP[(1,0)]=1 DP[(1,1)]=2 def ans(S,X): #print(S,X) if DP.get((S,X))!=None: return DP[(S,X)] if S==0: return 1 #if X>S: # return ans(S,S) DP[(S,X)]=(ans(S//2,X//2)+ans((S-1)//2,(X-1)//2)+ans((S-2)//2,(X-2)//2))%mod #一番下の桁をみて、bitが0,0の場合,1,0の場合,1,1の場合. #三つ目の場合は本来ans((S-2)//2,X//2)だが,今回扱うのはS=Xのときで,X>Sのときは0になるので,ans((S-2)//2,(X-2)//2)で良いはず. return DP[(S,X)] print((ans(N,N)))
27
26
558
556
N = int(eval(input())) mod = 10**9 + 7 ANSLIST = [1] for i in range(61): ANSLIST.append((ANSLIST[-1] * 3 - 1) % mod) ANS = [1, 2, 4, 5] ANSDICT = dict() def ans(k): if 0 <= k <= 3: return ANS[k] if ANSDICT.get(k) != None: return ANSDICT[k] for i in range(61): if k == 2**i - 2: return ANSLIST[i] - 1 if k == 2**i - 1: return ANSLIST[i] if 2**i - 1 > k: break x = k - (2 ** (i - 1) - 1) ANSDICT[k] = (ans(x - 1) + ANSLIST[i - 1] * 2 - ans(2 ** (i - 1) - x - 2) - 1) % mod return ANSDICT[k] print((ans(N)))
import sys sys.setrecursionlimit(10**9) N = int(eval(input())) mod = 10**9 + 7 DP = dict() DP[(0, 0)] = 1 # a+b,a^b DP[(1, 0)] = 1 DP[(1, 1)] = 2 def ans(S, X): # print(S,X) if DP.get((S, X)) != None: return DP[(S, X)] if S == 0: return 1 # if X>S: # return ans(S,S) DP[(S, X)] = ( ans(S // 2, X // 2) + ans((S - 1) // 2, (X - 1) // 2) + ans((S - 2) // 2, (X - 2) // 2) ) % mod # 一番下の桁をみて、bitが0,0の場合,1,0の場合,1,1の場合. # 三つ目の場合は本来ans((S-2)//2,X//2)だが,今回扱うのはS=Xのときで,X>Sのときは0になるので,ans((S-2)//2,(X-2)//2)で良いはず. return DP[(S, X)] print((ans(N, N)))
false
3.703704
[ "+import sys", "+", "+sys.setrecursionlimit(10**9)", "-ANSLIST = [1]", "-for i in range(61):", "- ANSLIST.append((ANSLIST[-1] * 3 - 1) % mod)", "-ANS = [1, 2, 4, 5]", "-ANSDICT = dict()", "+DP = dict()", "+DP[(0, 0)] = 1 # a+b,a^b", "+DP[(1, 0)] = 1", "+DP[(1, 1)] = 2", "-def ans(k):", ...
false
0.249291
0.041599
5.992705
[ "s725438402", "s407398317" ]
u912237403
p02264
python
s307502598
s808995947
740
620
13,496
29,352
Accepted
Accepted
16.22
n, q = list(map(int, input().split())) que = [] for i in range(n): name, time = input().split() que.append([name, int(time)]) stime = 0 while que: job = que.pop(0) if job[1]<=q: stime += job[1] print(job[0], stime) else: stime += q job[1] -= q que.append(job)
import sys class Queue: class Cell: def __init__(self, x, y = None): self.data = x self.next = y def __init__(self): self.size = 0 self.rear = None def enqueue(self, x): if self.size == 0: self.rear = Queue.Cell(x) self.rear.next = self.rear else: new_cell = Queue.Cell(x, self.rear.__next__) self.rear.next = new_cell self.rear = new_cell self.size += 1 def dequeue(self): if self.size == 0: raise IndexError front = self.rear.__next__ self.rear.next = front.__next__ self.size -= 1 if self.size == 0: self.rear = None return front.data def isEmpty(self): return self.size == 0 def generator(n1, n2, step=1): n = n1 while n<n2: yield n n+= step n, q = list(map(int, input().split())) A = Queue() for i in generator(0,n): name, time = input().split() A.enqueue([name, int(time)]) stime = 0 while not A.isEmpty(): job = A.dequeue() if q>=job[1]: stime += job[1] print(job[0], stime) else: stime += q job[1] -= q A.enqueue(job)
17
56
338
1,271
n, q = list(map(int, input().split())) que = [] for i in range(n): name, time = input().split() que.append([name, int(time)]) stime = 0 while que: job = que.pop(0) if job[1] <= q: stime += job[1] print(job[0], stime) else: stime += q job[1] -= q que.append(job)
import sys class Queue: class Cell: def __init__(self, x, y=None): self.data = x self.next = y def __init__(self): self.size = 0 self.rear = None def enqueue(self, x): if self.size == 0: self.rear = Queue.Cell(x) self.rear.next = self.rear else: new_cell = Queue.Cell(x, self.rear.__next__) self.rear.next = new_cell self.rear = new_cell self.size += 1 def dequeue(self): if self.size == 0: raise IndexError front = self.rear.__next__ self.rear.next = front.__next__ self.size -= 1 if self.size == 0: self.rear = None return front.data def isEmpty(self): return self.size == 0 def generator(n1, n2, step=1): n = n1 while n < n2: yield n n += step n, q = list(map(int, input().split())) A = Queue() for i in generator(0, n): name, time = input().split() A.enqueue([name, int(time)]) stime = 0 while not A.isEmpty(): job = A.dequeue() if q >= job[1]: stime += job[1] print(job[0], stime) else: stime += q job[1] -= q A.enqueue(job)
false
69.642857
[ "+import sys", "+", "+", "+class Queue:", "+ class Cell:", "+ def __init__(self, x, y=None):", "+ self.data = x", "+ self.next = y", "+", "+ def __init__(self):", "+ self.size = 0", "+ self.rear = None", "+", "+ def enqueue(self, x):", ...
false
0.067427
0.036611
1.841747
[ "s307502598", "s808995947" ]
u875361824
p03243
python
s443394303
s196521267
29
17
3,316
3,060
Accepted
Accepted
41.38
def main(): N = int(eval(input())) for i in range(N, 999+1): if len(set(list(str(i)))) == 1: print(i) return if __name__ == '__main__': main()
def main(): N = int(eval(input())) ans1 = AC1(N) ans2 = AC2(N) assert ans1 == ans2 print(ans1) def AC1(N): for i in range(N, 999+1): if len(set(list(str(i)))) == 1: return i def AC2(N): for i in range(1, 9+1): if N <= 111 * i: return 111 * i if __name__ == '__main__': main()
11
24
194
373
def main(): N = int(eval(input())) for i in range(N, 999 + 1): if len(set(list(str(i)))) == 1: print(i) return if __name__ == "__main__": main()
def main(): N = int(eval(input())) ans1 = AC1(N) ans2 = AC2(N) assert ans1 == ans2 print(ans1) def AC1(N): for i in range(N, 999 + 1): if len(set(list(str(i)))) == 1: return i def AC2(N): for i in range(1, 9 + 1): if N <= 111 * i: return 111 * i if __name__ == "__main__": main()
false
54.166667
[ "+ ans1 = AC1(N)", "+ ans2 = AC2(N)", "+ assert ans1 == ans2", "+ print(ans1)", "+", "+", "+def AC1(N):", "- print(i)", "- return", "+ return i", "+", "+", "+def AC2(N):", "+ for i in range(1, 9 + 1):", "+ if N <= 111 * i:", "+ ...
false
0.035671
0.036927
0.965982
[ "s443394303", "s196521267" ]
u761320129
p02873
python
s488465495
s013358025
351
184
4,212
6,300
Accepted
Accepted
47.58
S = eval(input()) i = 0 ans = 0 l = r = 0 while i < len(S) and S[i] == '>': l += 1 i += 1 ans += l*(l+1)//2 while i < len(S): l = r = 0 while i < len(S) and S[i] == '<': l += 1 i += 1 while i < len(S) and S[i] == '>': r += 1 i += 1 mx,mn = max(l,r),min(l,r) ans += mx*(mx+1)//2 ans += mn*(mn-1)//2 print(ans)
S = eval(input()) ls = [] rs = [] if S[0] == '>': ls.append(0) pre = None seq = 0 for c in S: if c == pre: seq += 1 else: if pre: if pre=='<': ls.append(seq) else: rs.append(seq) seq = 1 pre = c if pre=='<': ls.append(seq) else: rs.append(seq) if len(ls) > len(rs): rs.append(0) ans = 0 for l,r in zip(ls,rs): if l<r: l,r = r,l ans += l*(l+1)//2 + r*(r-1)//2 print(ans)
22
30
390
513
S = eval(input()) i = 0 ans = 0 l = r = 0 while i < len(S) and S[i] == ">": l += 1 i += 1 ans += l * (l + 1) // 2 while i < len(S): l = r = 0 while i < len(S) and S[i] == "<": l += 1 i += 1 while i < len(S) and S[i] == ">": r += 1 i += 1 mx, mn = max(l, r), min(l, r) ans += mx * (mx + 1) // 2 ans += mn * (mn - 1) // 2 print(ans)
S = eval(input()) ls = [] rs = [] if S[0] == ">": ls.append(0) pre = None seq = 0 for c in S: if c == pre: seq += 1 else: if pre: if pre == "<": ls.append(seq) else: rs.append(seq) seq = 1 pre = c if pre == "<": ls.append(seq) else: rs.append(seq) if len(ls) > len(rs): rs.append(0) ans = 0 for l, r in zip(ls, rs): if l < r: l, r = r, l ans += l * (l + 1) // 2 + r * (r - 1) // 2 print(ans)
false
26.666667
[ "-i = 0", "+ls = []", "+rs = []", "+if S[0] == \">\":", "+ ls.append(0)", "+pre = None", "+seq = 0", "+for c in S:", "+ if c == pre:", "+ seq += 1", "+ else:", "+ if pre:", "+ if pre == \"<\":", "+ ls.append(seq)", "+ else:", ...
false
0.042282
0.081525
0.518636
[ "s488465495", "s013358025" ]
u861109991
p02727
python
s349956331
s013451846
449
253
34,004
24,864
Accepted
Accepted
43.65
import numpy as np x, y, a, b, c = list(map(int, input().split())) p = sorted(list(map(int, input().split()))) q = sorted(list(map(int, input().split()))) r = sorted(list(map(int, input().split()))) filt_p = p[-x:] filt_q = q[-y:] filt_p.extend(filt_q) filt_p.extend(r) all_apples = sorted(filt_p) ans = np.sum(np.array(all_apples)[-x-y:]) print((str(ans)))
x, y, a, b, c = list(map(int, input().split())) p = sorted(list(map(int, input().split()))) q = sorted(list(map(int, input().split()))) r = sorted(list(map(int, input().split()))) filt_p = p[-x:] filt_q = q[-y:] filt_p.extend(filt_q) filt_p.extend(r) all_apples = sorted(filt_p) ans = sum(all_apples[-x-y:]) print((str(ans)))
15
14
366
334
import numpy as np x, y, a, b, c = list(map(int, input().split())) p = sorted(list(map(int, input().split()))) q = sorted(list(map(int, input().split()))) r = sorted(list(map(int, input().split()))) filt_p = p[-x:] filt_q = q[-y:] filt_p.extend(filt_q) filt_p.extend(r) all_apples = sorted(filt_p) ans = np.sum(np.array(all_apples)[-x - y :]) print((str(ans)))
x, y, a, b, c = list(map(int, input().split())) p = sorted(list(map(int, input().split()))) q = sorted(list(map(int, input().split()))) r = sorted(list(map(int, input().split()))) filt_p = p[-x:] filt_q = q[-y:] filt_p.extend(filt_q) filt_p.extend(r) all_apples = sorted(filt_p) ans = sum(all_apples[-x - y :]) print((str(ans)))
false
6.666667
[ "-import numpy as np", "-", "-ans = np.sum(np.array(all_apples)[-x - y :])", "+ans = sum(all_apples[-x - y :])" ]
false
0.304141
0.084857
3.584177
[ "s349956331", "s013451846" ]
u936985471
p02901
python
s987138786
s163990262
1,991
1,067
3,188
3,188
Accepted
Accepted
46.41
n,m=list(map(int,input().split())) cost=[0]*m keys=[0]*m for i in range(m): a,b=list(map(int,input().split())) cost[i]=a k=list(map(int,input().split())) for j in range(b): keys[i]|=(1<<(k[j]-1)) INF=10**9+1 dp=[INF]*(2**n) dp[0]=0 for i in range(len(keys)): for j in range(len(dp)-1,-1,-1): if dp[j]!=INF: dp[j|keys[i]]=min(dp[j|keys[i]],dp[j]+cost[i]) if dp[-1]!=INF: print((dp[-1])) else: print((-1))
n,m=list(map(int,input().split())) cost=[0]*m keys=[0]*m for i in range(m): a,b=list(map(int,input().split())) cost[i]=a k=list(map(int,input().split())) for j in range(b): keys[i]|=(1<<(k[j]-1)) INF=10**9+1 dp=[INF]*(2**n) dp[0]=0 for i in range(len(keys)): for j in range(len(dp)-1,-1,-1): if dp[j]!=INF: if dp[j|keys[i]]>dp[j]+cost[i]: dp[j|keys[i]]=dp[j]+cost[i] if dp[-1]!=INF: print((dp[-1])) else: print((-1))
21
23
436
460
n, m = list(map(int, input().split())) cost = [0] * m keys = [0] * m for i in range(m): a, b = list(map(int, input().split())) cost[i] = a k = list(map(int, input().split())) for j in range(b): keys[i] |= 1 << (k[j] - 1) INF = 10**9 + 1 dp = [INF] * (2**n) dp[0] = 0 for i in range(len(keys)): for j in range(len(dp) - 1, -1, -1): if dp[j] != INF: dp[j | keys[i]] = min(dp[j | keys[i]], dp[j] + cost[i]) if dp[-1] != INF: print((dp[-1])) else: print((-1))
n, m = list(map(int, input().split())) cost = [0] * m keys = [0] * m for i in range(m): a, b = list(map(int, input().split())) cost[i] = a k = list(map(int, input().split())) for j in range(b): keys[i] |= 1 << (k[j] - 1) INF = 10**9 + 1 dp = [INF] * (2**n) dp[0] = 0 for i in range(len(keys)): for j in range(len(dp) - 1, -1, -1): if dp[j] != INF: if dp[j | keys[i]] > dp[j] + cost[i]: dp[j | keys[i]] = dp[j] + cost[i] if dp[-1] != INF: print((dp[-1])) else: print((-1))
false
8.695652
[ "- dp[j | keys[i]] = min(dp[j | keys[i]], dp[j] + cost[i])", "+ if dp[j | keys[i]] > dp[j] + cost[i]:", "+ dp[j | keys[i]] = dp[j] + cost[i]" ]
false
0.087313
0.075906
1.150276
[ "s987138786", "s163990262" ]
u989962753
p03370
python
s204782853
s258082921
45
17
3,064
3,064
Accepted
Accepted
62.22
n, x = input().split() n = int(n) x = int(x) m = [] i_min = 0 result = 0 #リストに値を読み込み for i in range(n): m.append(int(eval(input()))) #一個ずつ作る for i in range(len(m)): x = x - m[i] result = result + 1 #最小量の粉量を確定 for i in range(len(m)): if m[i_min] > m[i]: i_min = i #i_minを作れるだけ作る for i in range(x): if x >= m[i_min]: x = x - m[i_min] result = result + 1 else: break #結果の表示 print(result)
#定義 n, x = input().split() n = int(n) x = int(x) m = [] i_min = 0 gokei = 0 #リストに数値を読み込み for i in range(n): m.append(int(eval(input()))) #一個ずつの合計 for i in range(len(m)): gokei = gokei + m[i] if m[i_min] > m[i]: i_min = i #残量を出す x = x - gokei print((n + int(x/m[i_min])))
26
18
431
289
n, x = input().split() n = int(n) x = int(x) m = [] i_min = 0 result = 0 # リストに値を読み込み for i in range(n): m.append(int(eval(input()))) # 一個ずつ作る for i in range(len(m)): x = x - m[i] result = result + 1 # 最小量の粉量を確定 for i in range(len(m)): if m[i_min] > m[i]: i_min = i # i_minを作れるだけ作る for i in range(x): if x >= m[i_min]: x = x - m[i_min] result = result + 1 else: break # 結果の表示 print(result)
# 定義 n, x = input().split() n = int(n) x = int(x) m = [] i_min = 0 gokei = 0 # リストに数値を読み込み for i in range(n): m.append(int(eval(input()))) # 一個ずつの合計 for i in range(len(m)): gokei = gokei + m[i] if m[i_min] > m[i]: i_min = i # 残量を出す x = x - gokei print((n + int(x / m[i_min])))
false
30.769231
[ "+# 定義", "-result = 0", "-# リストに値を読み込み", "+gokei = 0", "+# リストに数値を読み込み", "-# 一個ずつ作る", "+# 一個ずつの合計", "- x = x - m[i]", "- result = result + 1", "-# 最小量の粉量を確定", "-for i in range(len(m)):", "+ gokei = gokei + m[i]", "-# i_minを作れるだけ作る", "-for i in range(x):", "- if x >= m[i_min]:...
false
0.037992
0.0384
0.989386
[ "s204782853", "s258082921" ]
u729133443
p02763
python
s167836915
s147643770
661
329
257,212
57,620
Accepted
Accepted
50.23
def main(): import sys input=sys.stdin.buffer.readline n=int(eval(input()))+1 data=[[0]*n*2for _ in range(26)] def update(i,x): i+=n for d in data: j=i if d[j]: d[j]=0 j//=2 while j: d[j]=d[j+j]|d[j-~j] j//=2 break d=data[x] d[i]=1 i//=2 while i: d[i]=d[i+i]|d[i-~i] i//=2 def query(l,r): l+=n r+=n s=[0]*26 while l<r: if l&1: for i,d in enumerate(data): s[i]|=d[l] l+=1 if r&1: r-=1 for i,d in enumerate(data): s[i]|=d[r] l//=2 r//=2 return sum(s) for i,c in enumerate(input()[:-1],n): data[c-97][i]=1 for d in data: for i in range(n-1,0,-1): d[i]=d[i+i]|d[i-~i] s=[] for _ in range(int(eval(input()))): q,a,b=input().split() if q[0]>49: s+=query(int(a)-1,int(b)), else: update(int(a)-1,b[0]-97) print((' '.join(map(str,s)))) main()
def main(): import sys input=sys.stdin.buffer.readline n=int(eval(input()))+1 data=[0]*n*2 def update(i,x): i+=n data[i]=x i//=2 while i: data[i]=data[i*2]|data[i*2+1] i//=2 def query(l,r): l+=n r+=n s=0 while l<r: if l&1: s|=data[l] l+=1 if r&1: r-=1 s|=data[r] l//=2 r//=2 return bin(s).count('1') for i,c in enumerate(input()[:-1],n):data[i]=2**(c-97) for i in range(n-1,0,-1):data[i]=data[i*2]|data[i-~i] s=[] for _ in range(int(eval(input()))): q,a,b=input().split() if q[0]>49:s+=query(int(a)-1,int(b)), else:update(int(a)-1,2**(b[0]-97)) print(('\n'.join(map(str,s)))) main()
52
35
1,026
740
def main(): import sys input = sys.stdin.buffer.readline n = int(eval(input())) + 1 data = [[0] * n * 2 for _ in range(26)] def update(i, x): i += n for d in data: j = i if d[j]: d[j] = 0 j //= 2 while j: d[j] = d[j + j] | d[j - ~j] j //= 2 break d = data[x] d[i] = 1 i //= 2 while i: d[i] = d[i + i] | d[i - ~i] i //= 2 def query(l, r): l += n r += n s = [0] * 26 while l < r: if l & 1: for i, d in enumerate(data): s[i] |= d[l] l += 1 if r & 1: r -= 1 for i, d in enumerate(data): s[i] |= d[r] l //= 2 r //= 2 return sum(s) for i, c in enumerate(input()[:-1], n): data[c - 97][i] = 1 for d in data: for i in range(n - 1, 0, -1): d[i] = d[i + i] | d[i - ~i] s = [] for _ in range(int(eval(input()))): q, a, b = input().split() if q[0] > 49: s += (query(int(a) - 1, int(b)),) else: update(int(a) - 1, b[0] - 97) print((" ".join(map(str, s)))) main()
def main(): import sys input = sys.stdin.buffer.readline n = int(eval(input())) + 1 data = [0] * n * 2 def update(i, x): i += n data[i] = x i //= 2 while i: data[i] = data[i * 2] | data[i * 2 + 1] i //= 2 def query(l, r): l += n r += n s = 0 while l < r: if l & 1: s |= data[l] l += 1 if r & 1: r -= 1 s |= data[r] l //= 2 r //= 2 return bin(s).count("1") for i, c in enumerate(input()[:-1], n): data[i] = 2 ** (c - 97) for i in range(n - 1, 0, -1): data[i] = data[i * 2] | data[i - ~i] s = [] for _ in range(int(eval(input()))): q, a, b = input().split() if q[0] > 49: s += (query(int(a) - 1, int(b)),) else: update(int(a) - 1, 2 ** (b[0] - 97)) print(("\n".join(map(str, s)))) main()
false
32.692308
[ "- data = [[0] * n * 2 for _ in range(26)]", "+ data = [0] * n * 2", "- for d in data:", "- j = i", "- if d[j]:", "- d[j] = 0", "- j //= 2", "- while j:", "- d[j] = d[j + j] | d[j - ~j]", "- ...
false
0.04653
0.037942
1.226353
[ "s167836915", "s147643770" ]
u852690916
p03356
python
s296007967
s956220015
490
418
13,876
61,584
Accepted
Accepted
14.69
import sys def main(): input = sys.stdin.readline N, M = list(map(int, input().split())) P = list([int(x)-1 for x in input().split()]) uf = UnionFindTree(N) for _ in range(M): x,y = list(map(int, input().split())) uf.union(x-1,y-1) ind = [-1] * N for i in range(N): ind[P[i]] = i ans = 0 for i in range(N): if P[i] == i: ans += 1 elif uf.same(i, ind[i]): ans += 1 print(ans) class UnionFindTree: def __init__(self, n): self.parent = [-1] * n def find(self, x): p = self.parent while p[x] >= 0: x, p[x] = p[x], p[p[x]] return x def union(self, x, y): x, y, p = self.find(x), self.find(y), self.parent if x == y: return if p[x] > p[y]: x, y = y, x p[x], p[y] = p[x] + p[y], x def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.parent[self.find(x)] if __name__ == '__main__': main()
import sys def main(): input = sys.stdin.readline N,M=list(map(int, input().split())) *P,=list(map(int, input().split())) P=[-1]+P uf=UnionFindTree(N+1) for _ in range(M): x,y=list(map(int, input().split())) uf.union(P[x],P[y]) ans=0 for i in range(1,N+1): if uf.same(P[i], i): ans+=1 print(ans) class UnionFindTree: def __init__(self, n): self.parent = [-1] * n def find(self, x): p = self.parent while p[x] >= 0: x, p[x] = p[x], p[p[x]] return x def union(self, x, y): x, y, p = self.find(x), self.find(y), self.parent if x == y: return if p[x] > p[y]: x, y = y, x p[x], p[y] = p[x] + p[y], x def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.parent[self.find(x)] if __name__ == '__main__': main()
42
35
1,032
908
import sys def main(): input = sys.stdin.readline N, M = list(map(int, input().split())) P = list([int(x) - 1 for x in input().split()]) uf = UnionFindTree(N) for _ in range(M): x, y = list(map(int, input().split())) uf.union(x - 1, y - 1) ind = [-1] * N for i in range(N): ind[P[i]] = i ans = 0 for i in range(N): if P[i] == i: ans += 1 elif uf.same(i, ind[i]): ans += 1 print(ans) class UnionFindTree: def __init__(self, n): self.parent = [-1] * n def find(self, x): p = self.parent while p[x] >= 0: x, p[x] = p[x], p[p[x]] return x def union(self, x, y): x, y, p = self.find(x), self.find(y), self.parent if x == y: return if p[x] > p[y]: x, y = y, x p[x], p[y] = p[x] + p[y], x def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.parent[self.find(x)] if __name__ == "__main__": main()
import sys def main(): input = sys.stdin.readline N, M = list(map(int, input().split())) (*P,) = list(map(int, input().split())) P = [-1] + P uf = UnionFindTree(N + 1) for _ in range(M): x, y = list(map(int, input().split())) uf.union(P[x], P[y]) ans = 0 for i in range(1, N + 1): if uf.same(P[i], i): ans += 1 print(ans) class UnionFindTree: def __init__(self, n): self.parent = [-1] * n def find(self, x): p = self.parent while p[x] >= 0: x, p[x] = p[x], p[p[x]] return x def union(self, x, y): x, y, p = self.find(x), self.find(y), self.parent if x == y: return if p[x] > p[y]: x, y = y, x p[x], p[y] = p[x] + p[y], x def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.parent[self.find(x)] if __name__ == "__main__": main()
false
16.666667
[ "- P = list([int(x) - 1 for x in input().split()])", "- uf = UnionFindTree(N)", "+ (*P,) = list(map(int, input().split()))", "+ P = [-1] + P", "+ uf = UnionFindTree(N + 1)", "- uf.union(x - 1, y - 1)", "- ind = [-1] * N", "- for i in range(N):", "- ind[P[i]] = i", ...
false
0.088023
0.049166
1.790311
[ "s296007967", "s956220015" ]
u989345508
p03732
python
s109478185
s122122032
390
214
3,192
3,188
Accepted
Accepted
45.13
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1]) wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): if wv[i][0]==w0: k=wv[i][1]+x[0][-1] l=len(x[0]) if l*w0<=w:x[0].append(k) elif wv[i][0]==w0+1: k=wv[i][1]+x[1][-1] l=len(x[1]) if l*(w0+1)<=w:x[1].append(k) elif wv[i][0]==w0+2: k=wv[i][1]+x[2][-1] l=len(x[2]) if l*(w0+2)<=w:x[2].append(k) else: k=wv[i][1]+x[3][-1] l=len(x[3]) if l*(w0+3)<=w:x[3].append(k) #print(x) ma=0 for i in range(len(x[0])): for j in range(len(x[1])): for k in range(len(x[2])): for l in range(len(x[3])): ma_sub=0 if i*w0+j*(w0+1)+k*(w0+2)+l*(w0+3)<=w: ma_sub+=x[0][i] ma_sub+=x[1][j] ma_sub+=x[2][k] ma_sub+=x[3][l] ma=max(ma,ma_sub) print(ma)
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1]) wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): if wv[i][0]==w0: k=wv[i][1]+x[0][-1] l=len(x[0]) if l*w0<=w:x[0].append(k) elif wv[i][0]==w0+1: k=wv[i][1]+x[1][-1] l=len(x[1]) if l*(w0+1)<=w:x[1].append(k) elif wv[i][0]==w0+2: k=wv[i][1]+x[2][-1] l=len(x[2]) if l*(w0+2)<=w:x[2].append(k) else: k=wv[i][1]+x[3][-1] l=len(x[3]) if l*(w0+3)<=w:x[3].append(k) #print(x) ma=0 for i in range(len(x[0])): for j in range(len(x[1])): for k in range(len(x[2])): for l in range(len(x[3])): if i*w0+j*(w0+1)+k*(w0+2)+l*(w0+3)<=w: ma_sub=0 ma_sub+=x[0][i] ma_sub+=x[1][j] ma_sub+=x[2][k] ma_sub+=x[3][l] ma=max(ma,ma_sub) else: break print(ma)
38
40
1,073
1,131
n, w = list(map(int, input().split())) wv = [list(map(int, input().split())) for i in range(n)] wv.sort(key=lambda x: -x[1]) wv.sort(key=lambda x: x[0]) # print(wv) w0 = wv[0][0] x = [[0], [0], [0], [0]] for i in range(n): if wv[i][0] == w0: k = wv[i][1] + x[0][-1] l = len(x[0]) if l * w0 <= w: x[0].append(k) elif wv[i][0] == w0 + 1: k = wv[i][1] + x[1][-1] l = len(x[1]) if l * (w0 + 1) <= w: x[1].append(k) elif wv[i][0] == w0 + 2: k = wv[i][1] + x[2][-1] l = len(x[2]) if l * (w0 + 2) <= w: x[2].append(k) else: k = wv[i][1] + x[3][-1] l = len(x[3]) if l * (w0 + 3) <= w: x[3].append(k) # print(x) ma = 0 for i in range(len(x[0])): for j in range(len(x[1])): for k in range(len(x[2])): for l in range(len(x[3])): ma_sub = 0 if i * w0 + j * (w0 + 1) + k * (w0 + 2) + l * (w0 + 3) <= w: ma_sub += x[0][i] ma_sub += x[1][j] ma_sub += x[2][k] ma_sub += x[3][l] ma = max(ma, ma_sub) print(ma)
n, w = list(map(int, input().split())) wv = [list(map(int, input().split())) for i in range(n)] wv.sort(key=lambda x: -x[1]) wv.sort(key=lambda x: x[0]) # print(wv) w0 = wv[0][0] x = [[0], [0], [0], [0]] for i in range(n): if wv[i][0] == w0: k = wv[i][1] + x[0][-1] l = len(x[0]) if l * w0 <= w: x[0].append(k) elif wv[i][0] == w0 + 1: k = wv[i][1] + x[1][-1] l = len(x[1]) if l * (w0 + 1) <= w: x[1].append(k) elif wv[i][0] == w0 + 2: k = wv[i][1] + x[2][-1] l = len(x[2]) if l * (w0 + 2) <= w: x[2].append(k) else: k = wv[i][1] + x[3][-1] l = len(x[3]) if l * (w0 + 3) <= w: x[3].append(k) # print(x) ma = 0 for i in range(len(x[0])): for j in range(len(x[1])): for k in range(len(x[2])): for l in range(len(x[3])): if i * w0 + j * (w0 + 1) + k * (w0 + 2) + l * (w0 + 3) <= w: ma_sub = 0 ma_sub += x[0][i] ma_sub += x[1][j] ma_sub += x[2][k] ma_sub += x[3][l] ma = max(ma, ma_sub) else: break print(ma)
false
5
[ "- ma_sub = 0", "+ ma_sub = 0", "- ma = max(ma, ma_sub)", "+ ma = max(ma, ma_sub)", "+ else:", "+ break" ]
false
0.147182
0.085914
1.713133
[ "s109478185", "s122122032" ]
u911153222
p03162
python
s651357234
s824586717
461
290
22,796
22,772
Accepted
Accepted
37.09
def vacation(): n = int(eval(input())) dp = [[]]*n for i in range(n): a, b, c = list(map(int, input().split())) if i == 0: dp[i] = [a, b, c] else: dp[i] = [a + max(dp[i-1][1], dp[i-1][2]), b + max(dp[i-1][0], dp[i-1][2]), c + max(dp[i-1][0], dp[i-1][1])] print((max(dp[-1]))) if __name__ == '__main__': vacation()
import sys input = sys.stdin.readline def vacation(): n = int(eval(input())) dp = [[]]*n for i in range(n): a, b, c = list(map(int, input().split())) if i == 0: dp[i] = [a, b, c] else: dp[i] = [a + max(dp[i-1][1], dp[i-1][2]), b + max(dp[i-1][0], dp[i-1][2]), c + max(dp[i-1][0], dp[i-1][1])] print((max(dp[-1]))) if __name__ == '__main__': vacation()
14
18
383
427
def vacation(): n = int(eval(input())) dp = [[]] * n for i in range(n): a, b, c = list(map(int, input().split())) if i == 0: dp[i] = [a, b, c] else: dp[i] = [ a + max(dp[i - 1][1], dp[i - 1][2]), b + max(dp[i - 1][0], dp[i - 1][2]), c + max(dp[i - 1][0], dp[i - 1][1]), ] print((max(dp[-1]))) if __name__ == "__main__": vacation()
import sys input = sys.stdin.readline def vacation(): n = int(eval(input())) dp = [[]] * n for i in range(n): a, b, c = list(map(int, input().split())) if i == 0: dp[i] = [a, b, c] else: dp[i] = [ a + max(dp[i - 1][1], dp[i - 1][2]), b + max(dp[i - 1][0], dp[i - 1][2]), c + max(dp[i - 1][0], dp[i - 1][1]), ] print((max(dp[-1]))) if __name__ == "__main__": vacation()
false
22.222222
[ "+import sys", "+", "+input = sys.stdin.readline", "+", "+" ]
false
0.036454
0.199683
0.182561
[ "s651357234", "s824586717" ]
u411923565
p03687
python
s825342661
s186066674
35
28
9,316
9,112
Accepted
Accepted
20
#41 A - Shrinking import collections s = list(eval(input())) cnt = collections.Counter(s) valcnt = list(cnt.values()) M = max(valcnt) # 出現回数が最多の文字リスト mkeys = [i for i,v in list(cnt.items()) if v == M] ans = len(s) for key in s: m = 0 cnt = 0 # 最多の文字の区間の最大値がその文字の最小値 for S in s: if S == key: m = max(m,cnt) cnt = 0 else: cnt += 1 m = max(m,cnt) ans = min(ans,m) print(ans)
s = list(eval(input())) ans = len(s) for t in s: m = 0 cnt = 0 # 同じ文字の区間の最大値がその文字の最小値 for S in s: if S == t: m = max(m,cnt) cnt = 0 else: cnt += 1 m = max(m,cnt) ans = min(ans,m) print(ans)
24
16
462
276
# 41 A - Shrinking import collections s = list(eval(input())) cnt = collections.Counter(s) valcnt = list(cnt.values()) M = max(valcnt) # 出現回数が最多の文字リスト mkeys = [i for i, v in list(cnt.items()) if v == M] ans = len(s) for key in s: m = 0 cnt = 0 # 最多の文字の区間の最大値がその文字の最小値 for S in s: if S == key: m = max(m, cnt) cnt = 0 else: cnt += 1 m = max(m, cnt) ans = min(ans, m) print(ans)
s = list(eval(input())) ans = len(s) for t in s: m = 0 cnt = 0 # 同じ文字の区間の最大値がその文字の最小値 for S in s: if S == t: m = max(m, cnt) cnt = 0 else: cnt += 1 m = max(m, cnt) ans = min(ans, m) print(ans)
false
33.333333
[ "-# 41 A - Shrinking", "-import collections", "-", "-cnt = collections.Counter(s)", "-valcnt = list(cnt.values())", "-M = max(valcnt)", "-# 出現回数が最多の文字リスト", "-mkeys = [i for i, v in list(cnt.items()) if v == M]", "-for key in s:", "+for t in s:", "- # 最多の文字の区間の最大値がその文字の最小値", "+ # 同じ文字の区間の...
false
0.04184
0.042773
0.978183
[ "s825342661", "s186066674" ]
u094191970
p03555
python
s870469690
s953964422
31
28
9,032
9,036
Accepted
Accepted
9.68
c1=eval(input()) c2=eval(input()) if c1==c2[::-1] and c2==c1[::-1]: print('YES') else: print('NO')
c1=eval(input()) c2=eval(input()) print(('YES' if c1==c2[::-1]else 'NO'))
7
4
97
63
c1 = eval(input()) c2 = eval(input()) if c1 == c2[::-1] and c2 == c1[::-1]: print("YES") else: print("NO")
c1 = eval(input()) c2 = eval(input()) print(("YES" if c1 == c2[::-1] else "NO"))
false
42.857143
[ "-if c1 == c2[::-1] and c2 == c1[::-1]:", "- print(\"YES\")", "-else:", "- print(\"NO\")", "+print((\"YES\" if c1 == c2[::-1] else \"NO\"))" ]
false
0.049052
0.067283
0.729038
[ "s870469690", "s953964422" ]
u379142263
p03611
python
s973423249
s361457351
168
144
17,336
14,320
Accepted
Accepted
14.29
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections n = int(eval(input())) a = sorted(list(map(int,input().split()))) c = collections.Counter(a) item = [] for key,Value in list(c.items()): item.append([key,Value]) koho = [] if len(item) == 1: print((item[0][1])) sys.exit() if item[1][0] - item[0][0] == 1: cnt = item[1][1] + item[0][1] else: cnt = item[0][1] koho.append(cnt) cnt = 0 for i in range(1,len(item)-1): cnt = 0 if item[i][0] - item[i-1][0] == 1: cnt += item[i-1][1] + item[i][1] if item[i+1][0] - item[i][0] == 1: cnt += item[i+1][1] koho.append(cnt) cnt = 0 if item[-1][0] - item[-2][0] == 1: cnt += item[-1][1] + item[-2][1] else: cnt += item[-1][1] koho.append(cnt) print((max(koho)))
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections n = int(eval(input())) a = sorted(list(map(int,input().split()))) x = [0]*100002 for i in range(n): x[a[i]]+=1 ans = 0 for i in range(100000): c = x[i] + x[i+1] + x[i+2] ans = max(ans,c) print(ans)
38
17
880
368
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify, heappop, heappush, heappushpop import math import collections n = int(eval(input())) a = sorted(list(map(int, input().split()))) c = collections.Counter(a) item = [] for key, Value in list(c.items()): item.append([key, Value]) koho = [] if len(item) == 1: print((item[0][1])) sys.exit() if item[1][0] - item[0][0] == 1: cnt = item[1][1] + item[0][1] else: cnt = item[0][1] koho.append(cnt) cnt = 0 for i in range(1, len(item) - 1): cnt = 0 if item[i][0] - item[i - 1][0] == 1: cnt += item[i - 1][1] + item[i][1] if item[i + 1][0] - item[i][0] == 1: cnt += item[i + 1][1] koho.append(cnt) cnt = 0 if item[-1][0] - item[-2][0] == 1: cnt += item[-1][1] + item[-2][1] else: cnt += item[-1][1] koho.append(cnt) print((max(koho)))
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify, heappop, heappush, heappushpop import math import collections n = int(eval(input())) a = sorted(list(map(int, input().split()))) x = [0] * 100002 for i in range(n): x[a[i]] += 1 ans = 0 for i in range(100000): c = x[i] + x[i + 1] + x[i + 2] ans = max(ans, c) print(ans)
false
55.263158
[ "-c = collections.Counter(a)", "-item = []", "-for key, Value in list(c.items()):", "- item.append([key, Value])", "-koho = []", "-if len(item) == 1:", "- print((item[0][1]))", "- sys.exit()", "-if item[1][0] - item[0][0] == 1:", "- cnt = item[1][1] + item[0][1]", "-else:", "- c...
false
0.050608
0.112829
0.448542
[ "s973423249", "s361457351" ]
u780475861
p02782
python
s576270520
s377550644
955
357
161,324
90,600
Accepted
Accepted
62.62
import sys read = sys.stdin.read mod = 10 ** 9 + 7 r1, c1, r2, c2 = map(int, read().split()) def prepare(n, MOD): # 1! - n! の計算 f = 1 factorials = [1] # 0!の分 for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) # n!^-1 の計算 inv = pow(f, MOD - 2, MOD) # n!^-1 - 1!^-1 の計算 invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return factorials, invs fac, finv = prepare(2 * 10**6 + 10, mod) def comb(n, k, mod=mod, fac=fac, finv=finv): ''' 二項係数の計算 Parameters n : int 元集合 k : int 元集合から選択する数 mod : int あまり fac : list 階乗のリスト finv : list 逆元のリスト Returns c : int nCkの組み合わせの数 ''' if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n - k] % mod) % mod answer = comb(r2 + c2 + 2, r2 + 1) - comb(r1 + c2 + 1, r1) - \ comb(c1 + r2 + 1, c1) + comb(r1 + c1, r1) answer %= mod print(answer)
import numpy as np import sys read = sys.stdin.read r1, c1, r2, c2 = map(int, read().split()) MOD = 10 ** 9 + 7 def cumprod(A, MOD=MOD): L = len(A) Lsq = int(L**.5 + 1) A = np.resize(A, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): A[:, n] *= A[:, n - 1] A[:, n] %= MOD for n in range(1, Lsq): A[n] *= A[n - 1, -1] A[n] %= MOD return A.ravel()[:L] def make_fact(U, MOD=MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] fact.flags.writeable = False fact_inv.flags.writeable = False return fact, fact_inv fac, finv = make_fact(2 * 10**6 + 10, MOD) def comb(n, k, mod=MOD, fac=fac, finv=finv): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n - k] % mod) % mod answer = comb(r2 + c2 + 2, r2 + 1) - comb(r1 + c2 + 1, r1) - \ comb(c1 + r2 + 1, c1) + comb(r1 + c1, r1) answer %= MOD print(answer)
61
47
1,145
1,141
import sys read = sys.stdin.read mod = 10**9 + 7 r1, c1, r2, c2 = map(int, read().split()) def prepare(n, MOD): # 1! - n! の計算 f = 1 factorials = [1] # 0!の分 for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) # n!^-1 の計算 inv = pow(f, MOD - 2, MOD) # n!^-1 - 1!^-1 の計算 invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return factorials, invs fac, finv = prepare(2 * 10**6 + 10, mod) def comb(n, k, mod=mod, fac=fac, finv=finv): """ 二項係数の計算 Parameters n : int 元集合 k : int 元集合から選択する数 mod : int あまり fac : list 階乗のリスト finv : list 逆元のリスト Returns c : int nCkの組み合わせの数 """ if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n - k] % mod) % mod answer = ( comb(r2 + c2 + 2, r2 + 1) - comb(r1 + c2 + 1, r1) - comb(c1 + r2 + 1, c1) + comb(r1 + c1, r1) ) answer %= mod print(answer)
import numpy as np import sys read = sys.stdin.read r1, c1, r2, c2 = map(int, read().split()) MOD = 10**9 + 7 def cumprod(A, MOD=MOD): L = len(A) Lsq = int(L**0.5 + 1) A = np.resize(A, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): A[:, n] *= A[:, n - 1] A[:, n] %= MOD for n in range(1, Lsq): A[n] *= A[n - 1, -1] A[n] %= MOD return A.ravel()[:L] def make_fact(U, MOD=MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] fact.flags.writeable = False fact_inv.flags.writeable = False return fact, fact_inv fac, finv = make_fact(2 * 10**6 + 10, MOD) def comb(n, k, mod=MOD, fac=fac, finv=finv): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n - k] % mod) % mod answer = ( comb(r2 + c2 + 2, r2 + 1) - comb(r1 + c2 + 1, r1) - comb(c1 + r2 + 1, c1) + comb(r1 + c1, r1) ) answer %= MOD print(answer)
false
22.95082
[ "+import numpy as np", "-mod = 10**9 + 7", "+MOD = 10**9 + 7", "-def prepare(n, MOD):", "- # 1! - n! の計算", "- f = 1", "- factorials = [1] # 0!の分", "- for m in range(1, n + 1):", "- f *= m", "- f %= MOD", "- factorials.append(f)", "- # n!^-1 の計算", "- in...
false
0.041371
0.037366
1.107178
[ "s576270520", "s377550644" ]
u798803522
p00710
python
s898148512
s230744036
70
60
7,664
7,672
Accepted
Accepted
14.29
cond = [int(n) for n in input().split(" ")] while True: case = [] cards = [n for n in range(1,cond[0] + 1)] cards.sort(reverse = True) for c in range(cond[1]): case = [int(n) for n in input().split(" ")] case[0] -= 1 #print(cards[case[0]:case[0]+case[1]],cards[case[1]:case[0]+case[1]],cards[:case[1]],cards[:case[1]]) disp = cards[case[0]:case[0]+case[1]] cards[case[1]:case[0]+case[1]] = cards[0:case[0]] cards[0:case[1]] = disp else: print((cards[0])) cond = [int(n) for n in input().split(" ")] if cond[0] == 0 and cond[1] == 0: break else: continue
cards,trial = (int(n) for n in input().split(" ")) while True: cards = list(reversed([int(n) for n in range(1,(cards)+1)])) for n in range(trial): num,change = (int(n) for n in input().split(" ")) num -= 1 disp = cards[num:num+change] cards[change:change+num] = cards[:num] cards[:change] = disp print((cards[0])) cards,trial = (int(n) for n in input().split(" ")) if cards == 0 and trial == 0: break
20
13
695
478
cond = [int(n) for n in input().split(" ")] while True: case = [] cards = [n for n in range(1, cond[0] + 1)] cards.sort(reverse=True) for c in range(cond[1]): case = [int(n) for n in input().split(" ")] case[0] -= 1 # print(cards[case[0]:case[0]+case[1]],cards[case[1]:case[0]+case[1]],cards[:case[1]],cards[:case[1]]) disp = cards[case[0] : case[0] + case[1]] cards[case[1] : case[0] + case[1]] = cards[0 : case[0]] cards[0 : case[1]] = disp else: print((cards[0])) cond = [int(n) for n in input().split(" ")] if cond[0] == 0 and cond[1] == 0: break else: continue
cards, trial = (int(n) for n in input().split(" ")) while True: cards = list(reversed([int(n) for n in range(1, (cards) + 1)])) for n in range(trial): num, change = (int(n) for n in input().split(" ")) num -= 1 disp = cards[num : num + change] cards[change : change + num] = cards[:num] cards[:change] = disp print((cards[0])) cards, trial = (int(n) for n in input().split(" ")) if cards == 0 and trial == 0: break
false
35
[ "-cond = [int(n) for n in input().split(\" \")]", "+cards, trial = (int(n) for n in input().split(\" \"))", "- case = []", "- cards = [n for n in range(1, cond[0] + 1)]", "- cards.sort(reverse=True)", "- for c in range(cond[1]):", "- case = [int(n) for n in input().split(\" \")]", "...
false
0.046255
0.089391
0.517444
[ "s898148512", "s230744036" ]
u782685137
p03228
python
s322018155
s110237313
19
17
3,316
2,940
Accepted
Accepted
10.53
a,b,k=list(map(int,input().split())) for i in range(k): if i%2==0: a = a//2 b += a else: b = b//2 a += b print((a,b))
a,b,k=list(map(int,input().split())) for i in range(k): if i%2>0:b//=2;a+=b else:a//=2;b+=a print((a,b))
9
5
157
108
a, b, k = list(map(int, input().split())) for i in range(k): if i % 2 == 0: a = a // 2 b += a else: b = b // 2 a += b print((a, b))
a, b, k = list(map(int, input().split())) for i in range(k): if i % 2 > 0: b //= 2 a += b else: a //= 2 b += a print((a, b))
false
44.444444
[ "- if i % 2 == 0:", "- a = a // 2", "+ if i % 2 > 0:", "+ b //= 2", "+ a += b", "+ else:", "+ a //= 2", "- else:", "- b = b // 2", "- a += b" ]
false
0.048419
0.04938
0.980552
[ "s322018155", "s110237313" ]
u175034939
p03262
python
s759516348
s672145086
113
76
14,252
14,252
Accepted
Accepted
32.74
n,m = list(map(int,input().split())) aa = list(map(int,input().split())) bb = [abs(a-m) for a in aa] def gcd(a,b): while b: a, b = b, a % b return a if len(aa) == 1: print((abs(aa[0]-m))) else: while len(bb) > 1: a, b = bb.pop(), bb.pop() bb.append(gcd(a,b)) print((bb[0]))
n,m = list(map(int,input().split())) aa = list(map(int,input().split())) bb = [abs(a-m) for a in aa] def gcd(a,b): while b: a, b = b, a % b return a ans = bb[0] if len(aa) == 1: print((abs(aa[0]-m))) else: for b in bb: ans = gcd(ans,b) print(ans)
17
19
331
302
n, m = list(map(int, input().split())) aa = list(map(int, input().split())) bb = [abs(a - m) for a in aa] def gcd(a, b): while b: a, b = b, a % b return a if len(aa) == 1: print((abs(aa[0] - m))) else: while len(bb) > 1: a, b = bb.pop(), bb.pop() bb.append(gcd(a, b)) print((bb[0]))
n, m = list(map(int, input().split())) aa = list(map(int, input().split())) bb = [abs(a - m) for a in aa] def gcd(a, b): while b: a, b = b, a % b return a ans = bb[0] if len(aa) == 1: print((abs(aa[0] - m))) else: for b in bb: ans = gcd(ans, b) print(ans)
false
10.526316
[ "+ans = bb[0]", "- while len(bb) > 1:", "- a, b = bb.pop(), bb.pop()", "- bb.append(gcd(a, b))", "- print((bb[0]))", "+ for b in bb:", "+ ans = gcd(ans, b)", "+ print(ans)" ]
false
0.036301
0.036324
0.999382
[ "s759516348", "s672145086" ]
u777299405
p00028
python
s660888061
s572138074
50
30
7,892
7,812
Accepted
Accepted
40
import sys import collections l = [] for line in sys.stdin: l.append(int(line)) counted = collections.Counter(l).most_common() maxv = counted[0][1] for k, v in counted: if v == maxv: print(k) else: break
import sys import collections l = [] for line in sys.stdin: l.append(int(line)) counted = collections.Counter(l).most_common() maxv = counted[0][1] for k, v in counted: if v == maxv: print(k)
14
12
246
220
import sys import collections l = [] for line in sys.stdin: l.append(int(line)) counted = collections.Counter(l).most_common() maxv = counted[0][1] for k, v in counted: if v == maxv: print(k) else: break
import sys import collections l = [] for line in sys.stdin: l.append(int(line)) counted = collections.Counter(l).most_common() maxv = counted[0][1] for k, v in counted: if v == maxv: print(k)
false
14.285714
[ "- else:", "- break" ]
false
0.044237
0.122219
0.361945
[ "s660888061", "s572138074" ]
u606878291
p03111
python
s013999371
s437097956
1,698
188
9,280
9,204
Accepted
Accepted
88.93
from itertools import product, permutations N, A, B, C = list(map(int, input().split(' '))) L = [int(eval(input())) for _ in range(N)] ans = 10 ** 9 for groups in product(list(range(4)), repeat=N): items = [] group_a = [] group_b = [] group_c = [] for group, length in zip(groups, L): if group == 0: items.append((length, 0)) elif group == 1: group_a.append(length) elif group == 2: group_b.append(length) elif group == 3: group_c.append(length) if group_a: items.append((sum(group_a), (len(group_a) - 1) * 10)) if group_b: items.append((sum(group_b), (len(group_b) - 1) * 10)) if group_c: items.append((sum(group_c), (len(group_c) - 1) * 10)) if len(items) < 3: continue for one, two, three in permutations((A, B, C), r=3): cost = 0 _items = list(items) _items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1])) cost += abs(_items[0][0] - one) + _items[0][1] _items.pop(0) _items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1])) cost += abs(_items[0][0] - two) + _items[0][1] _items.pop(0) _items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1])) cost += abs(_items[0][0] - three) + _items[0][1] ans = min(ans, cost) print(ans)
from itertools import product N, A, B, C = list(map(int, input().split(' '))) L = [int(eval(input())) for _ in range(N)] ans = 10 ** 9 for groups in product(list(range(4)), repeat=N): length_a = 0 length_b = 0 length_c = 0 cost_a = -10 cost_b = -10 cost_c = -10 for group, length in zip(groups, L): if group == 1: length_a += length cost_a += 10 elif group == 2: length_b += length cost_b += 10 elif group == 3: length_c += length cost_c += 10 if 0 in {length_a, length_b, length_c}: continue ans = min(ans, sum([ abs(A - length_a), abs(B - length_b), abs(C - length_c), cost_a, cost_b, cost_c, ])) print(ans)
50
38
1,431
827
from itertools import product, permutations N, A, B, C = list(map(int, input().split(" "))) L = [int(eval(input())) for _ in range(N)] ans = 10**9 for groups in product(list(range(4)), repeat=N): items = [] group_a = [] group_b = [] group_c = [] for group, length in zip(groups, L): if group == 0: items.append((length, 0)) elif group == 1: group_a.append(length) elif group == 2: group_b.append(length) elif group == 3: group_c.append(length) if group_a: items.append((sum(group_a), (len(group_a) - 1) * 10)) if group_b: items.append((sum(group_b), (len(group_b) - 1) * 10)) if group_c: items.append((sum(group_c), (len(group_c) - 1) * 10)) if len(items) < 3: continue for one, two, three in permutations((A, B, C), r=3): cost = 0 _items = list(items) _items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1])) cost += abs(_items[0][0] - one) + _items[0][1] _items.pop(0) _items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1])) cost += abs(_items[0][0] - two) + _items[0][1] _items.pop(0) _items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1])) cost += abs(_items[0][0] - three) + _items[0][1] ans = min(ans, cost) print(ans)
from itertools import product N, A, B, C = list(map(int, input().split(" "))) L = [int(eval(input())) for _ in range(N)] ans = 10**9 for groups in product(list(range(4)), repeat=N): length_a = 0 length_b = 0 length_c = 0 cost_a = -10 cost_b = -10 cost_c = -10 for group, length in zip(groups, L): if group == 1: length_a += length cost_a += 10 elif group == 2: length_b += length cost_b += 10 elif group == 3: length_c += length cost_c += 10 if 0 in {length_a, length_b, length_c}: continue ans = min( ans, sum( [ abs(A - length_a), abs(B - length_b), abs(C - length_c), cost_a, cost_b, cost_c, ] ), ) print(ans)
false
24
[ "-from itertools import product, permutations", "+from itertools import product", "- items = []", "- group_a = []", "- group_b = []", "- group_c = []", "+ length_a = 0", "+ length_b = 0", "+ length_c = 0", "+ cost_a = -10", "+ cost_b = -10", "+ cost_c = -10", "-...
false
1.124074
0.14058
7.995961
[ "s013999371", "s437097956" ]
u271261336
p02268
python
s566055188
s230948466
260
80
14,852
14,756
Accepted
Accepted
69.23
n = eval(input()) S = list(map(int,input().split())) m = eval(input()) T = list(map(int,input().split())) C=0 def binarySearch(A,p): lens = len(A) ll = -1 ul = lens-1 ms=(ll+ul)/2 while (ll+1<ul): ms=(ll+ul)/2 if A[ms] >= p: ul =ms elif A[ms] < p: ll =ms return A[ul]==p for item in T: if binarySearch(S,item): C += 1 print(C)
n = eval(input()) S = set([int(s) for s in input().split()]) m = eval(input()) T = set([int(s) for s in input().split()]) print(len(S&T))
22
5
412
136
n = eval(input()) S = list(map(int, input().split())) m = eval(input()) T = list(map(int, input().split())) C = 0 def binarySearch(A, p): lens = len(A) ll = -1 ul = lens - 1 ms = (ll + ul) / 2 while ll + 1 < ul: ms = (ll + ul) / 2 if A[ms] >= p: ul = ms elif A[ms] < p: ll = ms return A[ul] == p for item in T: if binarySearch(S, item): C += 1 print(C)
n = eval(input()) S = set([int(s) for s in input().split()]) m = eval(input()) T = set([int(s) for s in input().split()]) print(len(S & T))
false
77.272727
[ "-S = list(map(int, input().split()))", "+S = set([int(s) for s in input().split()])", "-T = list(map(int, input().split()))", "-C = 0", "-", "-", "-def binarySearch(A, p):", "- lens = len(A)", "- ll = -1", "- ul = lens - 1", "- ms = (ll + ul) / 2", "- while ll + 1 < ul:", "- ...
false
0.081647
0.066937
1.219744
[ "s566055188", "s230948466" ]
u440566786
p03476
python
s188043613
s369857241
1,404
377
8,600
52,440
Accepted
Accepted
73.15
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): def prime(n): if n<=1: return False A = [i for i in range(2, n+1)] P = [] lim = n**.5 while True: prime = A[0] if prime > lim: break P.append(prime) i = 0 while i < len(A): if A[i] % prime == 0: A.pop(i) continue i += 1 for a in A: P.append(a) return P C=5+10**5 S=[0]*C T=[0]*C for p in prime(C): S[p]=1 for i in range(C): if i%2==0: continue if S[i]==1 and S[(i+1)//2]==1: T[i]=1 # cumsum for i in range(C-1): T[i+1]+=T[i] # input q=int(eval(input())) for _ in range(q): l,r=list(map(int,input().split())) print((T[r]-T[l-1])) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): c=10**5+1 # S[i]: iがprimeかを指すboolean S=[1]*c S[0]=0; S[1]=0 for i in range(2,c): if S[i]==0: continue for j in range(2*i,c,i): S[j]=0 # T[i]: iが2017-like primeかを指すboolean T=[0]*c for i in range(3,c,2): if S[i] and S[(i+1)//2]: T[i]=1 # cumsum for i in range(c-1): T[i+1]+=T[i] # input q=int(eval(input())) for _ in range(q): l,r=list(map(int,input().split())) print((T[r]-T[l-1])) resolve()
43
28
1,004
660
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): def prime(n): if n <= 1: return False A = [i for i in range(2, n + 1)] P = [] lim = n**0.5 while True: prime = A[0] if prime > lim: break P.append(prime) i = 0 while i < len(A): if A[i] % prime == 0: A.pop(i) continue i += 1 for a in A: P.append(a) return P C = 5 + 10**5 S = [0] * C T = [0] * C for p in prime(C): S[p] = 1 for i in range(C): if i % 2 == 0: continue if S[i] == 1 and S[(i + 1) // 2] == 1: T[i] = 1 # cumsum for i in range(C - 1): T[i + 1] += T[i] # input q = int(eval(input())) for _ in range(q): l, r = list(map(int, input().split())) print((T[r] - T[l - 1])) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): c = 10**5 + 1 # S[i]: iがprimeかを指すboolean S = [1] * c S[0] = 0 S[1] = 0 for i in range(2, c): if S[i] == 0: continue for j in range(2 * i, c, i): S[j] = 0 # T[i]: iが2017-like primeかを指すboolean T = [0] * c for i in range(3, c, 2): if S[i] and S[(i + 1) // 2]: T[i] = 1 # cumsum for i in range(c - 1): T[i + 1] += T[i] # input q = int(eval(input())) for _ in range(q): l, r = list(map(int, input().split())) print((T[r] - T[l - 1])) resolve()
false
34.883721
[ "- def prime(n):", "- if n <= 1:", "- return False", "- A = [i for i in range(2, n + 1)]", "- P = []", "- lim = n**0.5", "- while True:", "- prime = A[0]", "- if prime > lim:", "- break", "- P.append...
false
1.030468
0.080229
12.844099
[ "s188043613", "s369857241" ]
u400336986
p02370
python
s366934787
s585745698
290
230
12,412
11,420
Accepted
Accepted
20.69
import queue nv, ne = map(int, input().split(' ')) in_degs = [0] * nv q = queue.Queue() outs = {} o = [] for _ in range(ne): s, t = map(int, input().split(' ')) if s in outs: outs[s].append(t) else: outs[s] = [t] in_degs[t] += 1 for i in range(nv): if in_degs[i] == 0: q.put(i) while not q.empty(): v = q.get() o.append(v) if v in outs: for out in outs[v]: in_degs[out] -= 1 if in_degs[out] == 0: q.put(out) [print(v) for v in o]
nv, ne = map(int, input().split(' ')) in_degs = [0] * nv q = [] outs = {} o = [] for _ in range(ne): s, t = map(int, input().split(' ')) if s in outs: outs[s].append(t) else: outs[s] = [t] in_degs[t] += 1 for i in range(nv): if in_degs[i] == 0: q.append(i) while len(q) > 0: v = q.pop(0) o.append(v) if v in outs: for out in outs[v]: in_degs[out] -= 1 if in_degs[out] == 0: q.append(out) [print(v) for v in o]
29
27
529
506
import queue nv, ne = map(int, input().split(" ")) in_degs = [0] * nv q = queue.Queue() outs = {} o = [] for _ in range(ne): s, t = map(int, input().split(" ")) if s in outs: outs[s].append(t) else: outs[s] = [t] in_degs[t] += 1 for i in range(nv): if in_degs[i] == 0: q.put(i) while not q.empty(): v = q.get() o.append(v) if v in outs: for out in outs[v]: in_degs[out] -= 1 if in_degs[out] == 0: q.put(out) [print(v) for v in o]
nv, ne = map(int, input().split(" ")) in_degs = [0] * nv q = [] outs = {} o = [] for _ in range(ne): s, t = map(int, input().split(" ")) if s in outs: outs[s].append(t) else: outs[s] = [t] in_degs[t] += 1 for i in range(nv): if in_degs[i] == 0: q.append(i) while len(q) > 0: v = q.pop(0) o.append(v) if v in outs: for out in outs[v]: in_degs[out] -= 1 if in_degs[out] == 0: q.append(out) [print(v) for v in o]
false
6.896552
[ "-import queue", "-", "-q = queue.Queue()", "+q = []", "- q.put(i)", "-while not q.empty():", "- v = q.get()", "+ q.append(i)", "+while len(q) > 0:", "+ v = q.pop(0)", "- q.put(out)", "+ q.append(out)" ]
false
0.040347
0.037152
1.085982
[ "s366934787", "s585745698" ]
u023127434
p03494
python
s067017069
s902843873
30
25
9,176
9,192
Accepted
Accepted
16.67
N = int(eval(input())) A = list(map(int, input().split())) count = 0 while all(a % 2 == 0 for a in A): A = [a / 2 for a in A] count += 1 print(count)
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 while all(i % 2 == 0 for i in a): a = [i / 2 for i in a] ans += 1 print(ans)
7
7
157
147
N = int(eval(input())) A = list(map(int, input().split())) count = 0 while all(a % 2 == 0 for a in A): A = [a / 2 for a in A] count += 1 print(count)
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 while all(i % 2 == 0 for i in a): a = [i / 2 for i in a] ans += 1 print(ans)
false
0
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-count = 0", "-while all(a % 2 == 0 for a in A):", "- A = [a / 2 for a in A]", "- count += 1", "-print(count)", "+n = int(eval(input()))", "+a = list(map(int, input().split()))", "+ans = 0", "+while all(i % 2 == 0 for i in...
false
0.07616
0.039827
1.912257
[ "s067017069", "s902843873" ]
u828766688
p03636
python
s764218436
s999372511
178
17
38,384
2,940
Accepted
Accepted
90.45
s = eval(input()) ans = s[0] + str(len(s)-2) + s[-1] print(ans)
s = eval(input()) n = len (s) - 2 n = str (n) print(( s[0] + n + s[-1] ))
6
4
66
70
s = eval(input()) ans = s[0] + str(len(s) - 2) + s[-1] print(ans)
s = eval(input()) n = len(s) - 2 n = str(n) print((s[0] + n + s[-1]))
false
33.333333
[ "-ans = s[0] + str(len(s) - 2) + s[-1]", "-print(ans)", "+n = len(s) - 2", "+n = str(n)", "+print((s[0] + n + s[-1]))" ]
false
0.043347
0.037431
1.158032
[ "s764218436", "s999372511" ]
u644778646
p02925
python
s925251824
s607140684
1,973
1,277
221,240
154,828
Accepted
Accepted
35.28
import math import collections import heapq from collections import defaultdict import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) def main(): n = int(eval(input())) maxv = n*(n-1)//2 a = [list(map(int, input().split())) for i in range(n)] for i in range(n): for j in range(n-1): a[i][j] -= 1 # 試合を頂点とする(ex 1-2,2-4 : i < j) v = 0 # 頂点数 # 頂点にIDをふる Id = [[-1 for i in range(n)] for j in range(n)] for i in range(n): for j in range(n): if i < j: # 3-1はダメ Id[i][j] = v Id[j][i] = v v += 1 e = [[] for i in range(maxv)] for i in range(n): for j in range(n - 1): # a[i][j]にIDを代入する Id[1][3]=1 => a[1][3] = a[3][1] = 1 # x = i # y = a[i][j] # if x > y: # x, y = y, x # a[i][j] = Id[x][y] # toId(i, a[i][j]) a[i][j] = Id[i][a[i][j]] for j in range(n - 2): e[a[i][j + 1]].append(a[i][j]) calculated = [False for i in range(maxv)] dp = [-1 for i in range(maxv)] def dfs(v): if dp[v] != -1: # サイクル検知 if not calculated[v]: return -1 return dp[v] dp[v] = 1 for u in e[v]: ret = dfs(u) if ret == -1: return -1 dp[v] = max(dp[v], ret + 1) calculated[v] = True return dp[v] ans = 0 for i in range(v): ret = dfs(i) if ret == -1: # detected cycle print((-1)) exit() ans = max(ans, ret) print(ans) if __name__ == '__main__': main()
import math import collections import heapq from collections import defaultdict import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) def main(): n = int(eval(input())) maxv = n*(n-1)//2 a = [list(map(int, input().split())) for i in range(n)] for i in range(n): for j in range(n-1): a[i][j] -= 1 # 試合を頂点とする(ex 1-2,2-4 : i < j) v = 0 # 頂点数 # 頂点にIDをふる Id = [[-1 for i in range(n)] for j in range(n)] for i in range(n): for j in range(n): if i < j: Id[i][j] = v Id[j][i] = v v += 1 # 頂点間の辺を貼る e = [[] for i in range(maxv)] for i in range(n): # a[i][j]にIDを代入する Id[1][3]=1 => a[1][3] = a[3][1] = 1 for j in range(n - 1): a[i][j] = Id[i][a[i][j]] # 逆向きに辺をはる for j in range(n - 2): e[a[i][j]].append(a[i][j+1]) calculated = [False for i in range(maxv)] dp = [-1 for i in range(maxv)] def dfs(v): if dp[v] != -1: # サイクル検知 if not calculated[v]: return -1 return dp[v] dp[v] = 1 for u in e[v]: ret = dfs(u) if ret == -1: return -1 dp[v] = max(dp[v], ret + 1) calculated[v] = True return dp[v] ans = 0 for i in range(v): ret = dfs(i) if ret == -1: # サイクル検知 print((-1)) exit() ans = max(ans, ret) print(ans) if __name__ == '__main__': main()
72
71
1,765
1,623
import math import collections import heapq from collections import defaultdict import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) def main(): n = int(eval(input())) maxv = n * (n - 1) // 2 a = [list(map(int, input().split())) for i in range(n)] for i in range(n): for j in range(n - 1): a[i][j] -= 1 # 試合を頂点とする(ex 1-2,2-4 : i < j) v = 0 # 頂点数 # 頂点にIDをふる Id = [[-1 for i in range(n)] for j in range(n)] for i in range(n): for j in range(n): if i < j: # 3-1はダメ Id[i][j] = v Id[j][i] = v v += 1 e = [[] for i in range(maxv)] for i in range(n): for j in range(n - 1): # a[i][j]にIDを代入する Id[1][3]=1 => a[1][3] = a[3][1] = 1 # x = i # y = a[i][j] # if x > y: # x, y = y, x # a[i][j] = Id[x][y] # toId(i, a[i][j]) a[i][j] = Id[i][a[i][j]] for j in range(n - 2): e[a[i][j + 1]].append(a[i][j]) calculated = [False for i in range(maxv)] dp = [-1 for i in range(maxv)] def dfs(v): if dp[v] != -1: # サイクル検知 if not calculated[v]: return -1 return dp[v] dp[v] = 1 for u in e[v]: ret = dfs(u) if ret == -1: return -1 dp[v] = max(dp[v], ret + 1) calculated[v] = True return dp[v] ans = 0 for i in range(v): ret = dfs(i) if ret == -1: # detected cycle print((-1)) exit() ans = max(ans, ret) print(ans) if __name__ == "__main__": main()
import math import collections import heapq from collections import defaultdict import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) def main(): n = int(eval(input())) maxv = n * (n - 1) // 2 a = [list(map(int, input().split())) for i in range(n)] for i in range(n): for j in range(n - 1): a[i][j] -= 1 # 試合を頂点とする(ex 1-2,2-4 : i < j) v = 0 # 頂点数 # 頂点にIDをふる Id = [[-1 for i in range(n)] for j in range(n)] for i in range(n): for j in range(n): if i < j: Id[i][j] = v Id[j][i] = v v += 1 # 頂点間の辺を貼る e = [[] for i in range(maxv)] for i in range(n): # a[i][j]にIDを代入する Id[1][3]=1 => a[1][3] = a[3][1] = 1 for j in range(n - 1): a[i][j] = Id[i][a[i][j]] # 逆向きに辺をはる for j in range(n - 2): e[a[i][j]].append(a[i][j + 1]) calculated = [False for i in range(maxv)] dp = [-1 for i in range(maxv)] def dfs(v): if dp[v] != -1: # サイクル検知 if not calculated[v]: return -1 return dp[v] dp[v] = 1 for u in e[v]: ret = dfs(u) if ret == -1: return -1 dp[v] = max(dp[v], ret + 1) calculated[v] = True return dp[v] ans = 0 for i in range(v): ret = dfs(i) if ret == -1: # サイクル検知 print((-1)) exit() ans = max(ans, ret) print(ans) if __name__ == "__main__": main()
false
1.388889
[ "- if i < j: # 3-1はダメ", "+ if i < j:", "+ # 頂点間の辺を貼る", "+ # a[i][j]にIDを代入する Id[1][3]=1 => a[1][3] = a[3][1] = 1", "- # a[i][j]にIDを代入する Id[1][3]=1 => a[1][3] = a[3][1] = 1", "- # x = i", "- # y = a[i][j]", "- # if x > y:", "...
false
0.113747
0.135161
0.841563
[ "s925251824", "s607140684" ]
u389910364
p03061
python
s688165916
s133913593
1,473
306
102,248
22,468
Accepted
Accepted
79.23
import fractions import operator import sys sys.setrecursionlimit(10000) INF = float('inf') class SegmentTree: # http://tsutaj.hatenablog.com/entry/2017/03/29/204841 def __init__(self, size, fn=operator.add, default=0): """ :param int size: :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など """ # size 以上である最小の 2 冪 n = 1 while n < size: n *= 2 self._size = n self._tree = [default for _ in range(self._size * 2 - 1)] self._fn = fn def set(self, i, value): """ i 番目に value を設定 :param int i: :param int value: :return: """ x = self._size - 1 + i self._tree[x] = value while x > 0: x = (x - 1) // 2 self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2]) def add(self, i, value): """ もとの i 番目と value に fn を適用したものを i 番目に設定 :param int i: :param int value: :return: """ x = self._size - 1 + i self.set(i, self._fn(self._tree[x], value)) def get(self, from_i, to_i, k=0, L=None, r=None): """ [from_i, to_i) に fn を適用した結果を返す :param int from_i: :param int to_i: :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ :param int L: :param int r: :return: """ L = 0 if L is None else L r = self._size if r is None else r if from_i <= L and r <= to_i: return self._tree[k] if to_i <= L or r <= from_i: return None ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2) ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r) if ret_L is None: return ret_r if ret_r is None: return ret_L return self._fn(ret_L, ret_r) def __len__(self): return self._size N = int(eval(input())) A = list(map(int, input().split())) st = SegmentTree(size=N, fn=fractions.gcd, default=0) for i, a in enumerate(A): st.set(i, a) ans = 0 for i in range(N): ans = max(ans, fractions.gcd(st.get(0, i) or 0, st.get(i + 1, N) or 0)) print(ans)
import bisect import cmath import heapq import itertools import math import operator import os import re import string import sys from collections import Counter, deque, defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter, mul, add, xor import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 N = int(sys.stdin.buffer.readline()) A = list(map(int, sys.stdin.buffer.readline().split())) # 1個の変える先は他のやつの最大公約数にすればいいので、 # N-1個の最大公約数の最大値を求める lefts = list(itertools.accumulate(A, gcd)) rights = list(itertools.accumulate(A[::-1], gcd))[::-1] ans = 0 for i in range(N): if i == 0: ans = max(ans, rights[1]) elif i == N - 1: ans = max(ans, lefts[-2]) else: ans = max(ans, gcd(lefts[i - 1], rights[i + 1])) print(ans)
89
45
2,320
1,032
import fractions import operator import sys sys.setrecursionlimit(10000) INF = float("inf") class SegmentTree: # http://tsutaj.hatenablog.com/entry/2017/03/29/204841 def __init__(self, size, fn=operator.add, default=0): """ :param int size: :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など """ # size 以上である最小の 2 冪 n = 1 while n < size: n *= 2 self._size = n self._tree = [default for _ in range(self._size * 2 - 1)] self._fn = fn def set(self, i, value): """ i 番目に value を設定 :param int i: :param int value: :return: """ x = self._size - 1 + i self._tree[x] = value while x > 0: x = (x - 1) // 2 self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2]) def add(self, i, value): """ もとの i 番目と value に fn を適用したものを i 番目に設定 :param int i: :param int value: :return: """ x = self._size - 1 + i self.set(i, self._fn(self._tree[x], value)) def get(self, from_i, to_i, k=0, L=None, r=None): """ [from_i, to_i) に fn を適用した結果を返す :param int from_i: :param int to_i: :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ :param int L: :param int r: :return: """ L = 0 if L is None else L r = self._size if r is None else r if from_i <= L and r <= to_i: return self._tree[k] if to_i <= L or r <= from_i: return None ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2) ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r) if ret_L is None: return ret_r if ret_r is None: return ret_L return self._fn(ret_L, ret_r) def __len__(self): return self._size N = int(eval(input())) A = list(map(int, input().split())) st = SegmentTree(size=N, fn=fractions.gcd, default=0) for i, a in enumerate(A): st.set(i, a) ans = 0 for i in range(N): ans = max(ans, fractions.gcd(st.get(0, i) or 0, st.get(i + 1, N) or 0)) print(ans)
import bisect import cmath import heapq import itertools import math import operator import os import re import string import sys from collections import Counter, deque, defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter, mul, add, xor import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10**9) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 # MOD = 998244353 N = int(sys.stdin.buffer.readline()) A = list(map(int, sys.stdin.buffer.readline().split())) # 1個の変える先は他のやつの最大公約数にすればいいので、 # N-1個の最大公約数の最大値を求める lefts = list(itertools.accumulate(A, gcd)) rights = list(itertools.accumulate(A[::-1], gcd))[::-1] ans = 0 for i in range(N): if i == 0: ans = max(ans, rights[1]) elif i == N - 1: ans = max(ans, lefts[-2]) else: ans = max(ans, gcd(lefts[i - 1], rights[i + 1])) print(ans)
false
49.438202
[ "-import fractions", "+import bisect", "+import cmath", "+import heapq", "+import itertools", "+import math", "+import os", "+import re", "+import string", "+from collections import Counter, deque, defaultdict", "+from copy import deepcopy", "+from decimal import Decimal", "+from fractions i...
false
0.045879
0.071156
0.644767
[ "s688165916", "s133913593" ]
u556215526
p03448
python
s614215601
s839109564
57
45
3,064
3,064
Accepted
Accepted
21.05
fh = int(eval(input())) oh = int(eval(input())) ft = int(eval(input())) om = int(eval(input())) count = 0 for i in range(fh + 1): for j in range(oh + 1): for k in range(ft + 1): nm = 0 nm = i * 500 + j * 100 + k * 50 if om == nm: count +=1 print(count)
fh = int(eval(input())) oh = int(eval(input())) ft = int(eval(input())) om = int(eval(input())) count = 0 for i in range(fh + 1): if om < i * 500: break for j in range(oh + 1): if om < i * 500 + j * 100: break for k in range(ft + 1): nm = 0 nm = i * 500 + j * 100 + k * 50 if om == nm: count +=1 print(count)
15
20
308
402
fh = int(eval(input())) oh = int(eval(input())) ft = int(eval(input())) om = int(eval(input())) count = 0 for i in range(fh + 1): for j in range(oh + 1): for k in range(ft + 1): nm = 0 nm = i * 500 + j * 100 + k * 50 if om == nm: count += 1 print(count)
fh = int(eval(input())) oh = int(eval(input())) ft = int(eval(input())) om = int(eval(input())) count = 0 for i in range(fh + 1): if om < i * 500: break for j in range(oh + 1): if om < i * 500 + j * 100: break for k in range(ft + 1): nm = 0 nm = i * 500 + j * 100 + k * 50 if om == nm: count += 1 print(count)
false
25
[ "+ if om < i * 500:", "+ break", "+ if om < i * 500 + j * 100:", "+ break" ]
false
0.10229
0.049009
2.087158
[ "s614215601", "s839109564" ]
u981931040
p03945
python
s323537282
s240198031
186
33
49,904
3,188
Accepted
Accepted
82.26
S = list(eval(input())) now = S[0] ans = 0 for i in range(1,len(S)): if now != S[i]: ans += 1 now = S[i] print(ans)
S = eval(input()) now = S[0] ans = 0 for stone in S: if stone != now: now = stone ans += 1 print(ans)
8
8
136
122
S = list(eval(input())) now = S[0] ans = 0 for i in range(1, len(S)): if now != S[i]: ans += 1 now = S[i] print(ans)
S = eval(input()) now = S[0] ans = 0 for stone in S: if stone != now: now = stone ans += 1 print(ans)
false
0
[ "-S = list(eval(input()))", "+S = eval(input())", "-for i in range(1, len(S)):", "- if now != S[i]:", "+for stone in S:", "+ if stone != now:", "+ now = stone", "- now = S[i]" ]
false
0.036312
0.08202
0.442726
[ "s323537282", "s240198031" ]
u844789719
p02802
python
s315133497
s433469705
518
102
68,568
26,040
Accepted
Accepted
80.31
N, M = [int(_) for _ in input().split()] PS = [input().split() for _ in range(M)] count = [0] * (N + 1) isac = [0] * (N + 1) for p, s in PS: p = int(p) if isac[p] == 1: continue if s == 'AC': isac[p] = 1 else: count[p] += 1 wa = 0 ac = 0 for i in range(N + 1): if isac[i] == 1: ac += 1 wa += count[i] print((ac, wa))
N, M, *PS = open(0).read().split() N, M = [int(_) for _ in [N, M]] cor = [0] * (N + 1) pen = [0] * (N + 1) for p, s in zip(PS[::2], PS[1::2]): p = int(p) if cor[p] == 1: continue if s == 'AC': cor[p] = 1 else: pen[p] += 1 ans = [0, 0] for i in range(1, N + 1): if cor[i] == 0: continue ans[0] += 1 ans[1] += pen[i] print((*ans))
19
19
393
405
N, M = [int(_) for _ in input().split()] PS = [input().split() for _ in range(M)] count = [0] * (N + 1) isac = [0] * (N + 1) for p, s in PS: p = int(p) if isac[p] == 1: continue if s == "AC": isac[p] = 1 else: count[p] += 1 wa = 0 ac = 0 for i in range(N + 1): if isac[i] == 1: ac += 1 wa += count[i] print((ac, wa))
N, M, *PS = open(0).read().split() N, M = [int(_) for _ in [N, M]] cor = [0] * (N + 1) pen = [0] * (N + 1) for p, s in zip(PS[::2], PS[1::2]): p = int(p) if cor[p] == 1: continue if s == "AC": cor[p] = 1 else: pen[p] += 1 ans = [0, 0] for i in range(1, N + 1): if cor[i] == 0: continue ans[0] += 1 ans[1] += pen[i] print((*ans))
false
0
[ "-N, M = [int(_) for _ in input().split()]", "-PS = [input().split() for _ in range(M)]", "-count = [0] * (N + 1)", "-isac = [0] * (N + 1)", "-for p, s in PS:", "+N, M, *PS = open(0).read().split()", "+N, M = [int(_) for _ in [N, M]]", "+cor = [0] * (N + 1)", "+pen = [0] * (N + 1)", "+for p, s in ...
false
0.045486
0.060456
0.752372
[ "s315133497", "s433469705" ]
u519832983
p02657
python
s958063886
s279450236
24
22
9,152
9,096
Accepted
Accepted
8.33
A, B = list(map(int, input().split())) print((A * B))
import math A, B = list(map(float, input().split())) B *= 100 mul = math.floor(A * B) print((int(mul/100)))
2
5
46
103
A, B = list(map(int, input().split())) print((A * B))
import math A, B = list(map(float, input().split())) B *= 100 mul = math.floor(A * B) print((int(mul / 100)))
false
60
[ "-A, B = list(map(int, input().split()))", "-print((A * B))", "+import math", "+", "+A, B = list(map(float, input().split()))", "+B *= 100", "+mul = math.floor(A * B)", "+print((int(mul / 100)))" ]
false
0.039321
0.040109
0.980354
[ "s958063886", "s279450236" ]
u136090046
p03157
python
s483471535
s900688714
725
641
186,020
185,848
Accepted
Accepted
11.59
def main(): from collections import defaultdict import sys sys.setrecursionlimit(10 ** 9) H, W = list(map(int, input().split())) G = [list(eval(input())) for i in range(H)] Visited = [[0] * W for i in range(H)] direction = [[0, 1], [0, -1], [1, 0], [-1, 0]] def dfs(ny, nx, color): for dy, dx in direction: if not ((0 <= ny + dy < H) and (0 <= nx + dx < W)): continue if G[ny + dy][nx + dx] == G[ny][nx]: continue if Visited[ny + dy][nx + dx] != 0: continue if G[ny + dy][nx + dx] == '#': Visited[ny + dy][nx + dx] = color else: Visited[ny + dy][nx + dx] = -color dfs(ny + dy, nx + dx, color) Color = 1 for y in range(H): for x in range(W): if Visited[y][x] == 0: if G[y][x] == '#': Visited[y][x] = Color else: Visited[y][x] = -Color dfs(y, x, Color) Color += 1 D = defaultdict(int) for i in range(1, Color + 1): D[i] = 0 D[-i] = 0 for row in Visited: for data in row: D[data] += 1 ans = 0 for key in list(D.keys()): ans += D[key] * D[-key] print((ans // 2)) main()
def main(): from collections import defaultdict import sys sys.setrecursionlimit(10 ** 9) H, W = list(map(int, input().split())) G = [list(input()) for i in range(H)] Visited = [[0] * W for i in range(H)] direction = [[0, 1], [0, -1], [1, 0], [-1, 0]] def dfs(ny, nx, color): for dy, dx in direction: if not ((0 <= ny + dy < H) and (0 <= nx + dx < W)): continue if G[ny + dy][nx + dx] == G[ny][nx]: continue if Visited[ny + dy][nx + dx] != 0: continue if G[ny + dy][nx + dx] == '#': Visited[ny + dy][nx + dx] = color else: Visited[ny + dy][nx + dx] = -color dfs(ny + dy, nx + dx, color) Color = 1 for y in range(H): for x in range(W): if Visited[y][x] == 0: if G[y][x] == '#': Visited[y][x] = Color else: Visited[y][x] = -Color dfs(y, x, Color) Color += 1 D = defaultdict(int) for i in range(1, Color + 1): D[i] = 0 D[-i] = 0 for row in Visited: for data in row: D[data] += 1 ans = 0 for key in list(D.keys()): ans += D[key] * D[-key] print((ans // 2)) main()
58
58
1,476
1,484
def main(): from collections import defaultdict import sys sys.setrecursionlimit(10**9) H, W = list(map(int, input().split())) G = [list(eval(input())) for i in range(H)] Visited = [[0] * W for i in range(H)] direction = [[0, 1], [0, -1], [1, 0], [-1, 0]] def dfs(ny, nx, color): for dy, dx in direction: if not ((0 <= ny + dy < H) and (0 <= nx + dx < W)): continue if G[ny + dy][nx + dx] == G[ny][nx]: continue if Visited[ny + dy][nx + dx] != 0: continue if G[ny + dy][nx + dx] == "#": Visited[ny + dy][nx + dx] = color else: Visited[ny + dy][nx + dx] = -color dfs(ny + dy, nx + dx, color) Color = 1 for y in range(H): for x in range(W): if Visited[y][x] == 0: if G[y][x] == "#": Visited[y][x] = Color else: Visited[y][x] = -Color dfs(y, x, Color) Color += 1 D = defaultdict(int) for i in range(1, Color + 1): D[i] = 0 D[-i] = 0 for row in Visited: for data in row: D[data] += 1 ans = 0 for key in list(D.keys()): ans += D[key] * D[-key] print((ans // 2)) main()
def main(): from collections import defaultdict import sys sys.setrecursionlimit(10**9) H, W = list(map(int, input().split())) G = [list(input()) for i in range(H)] Visited = [[0] * W for i in range(H)] direction = [[0, 1], [0, -1], [1, 0], [-1, 0]] def dfs(ny, nx, color): for dy, dx in direction: if not ((0 <= ny + dy < H) and (0 <= nx + dx < W)): continue if G[ny + dy][nx + dx] == G[ny][nx]: continue if Visited[ny + dy][nx + dx] != 0: continue if G[ny + dy][nx + dx] == "#": Visited[ny + dy][nx + dx] = color else: Visited[ny + dy][nx + dx] = -color dfs(ny + dy, nx + dx, color) Color = 1 for y in range(H): for x in range(W): if Visited[y][x] == 0: if G[y][x] == "#": Visited[y][x] = Color else: Visited[y][x] = -Color dfs(y, x, Color) Color += 1 D = defaultdict(int) for i in range(1, Color + 1): D[i] = 0 D[-i] = 0 for row in Visited: for data in row: D[data] += 1 ans = 0 for key in list(D.keys()): ans += D[key] * D[-key] print((ans // 2)) main()
false
0
[ "- G = [list(eval(input())) for i in range(H)]", "+ G = [list(input()) for i in range(H)]" ]
false
0.058267
0.057191
1.018822
[ "s483471535", "s900688714" ]
u484229314
p02990
python
s940997825
s813299751
213
27
3,444
3,444
Accepted
Accepted
87.32
from math import factorial N, K = [int(_) for _ in input().split()] # N = 10 MOD = 10 ** 9 + 7 kaijo = [0] * (N + 1) kaijo[0] = kaijo[1] = 1 for i in range(2, N + 1): kaijo[i] = (kaijo[i - 1] * i) % MOD gyaku = [0] * (N + 1) gyaku[0] = gyaku[1] = 1 for i in range(2, N + 1): # gyaku[i] = (gyaku[i - 1] * pow(i, MOD - 2, MOD)) % MOD gyaku[i] = pow(kaijo[i], MOD - 2, MOD) def calc(n, k): # return (kaijo[n] * gyaku[n - k] * gyaku[k]) % MOD return factorial(n) // (factorial(n - k) * factorial(k)) def solve(): for i in range(1, K + 1): n = N - K + 1 k = i if k <= n: print(((calc(n, k) * calc(K - 1, i - 1)) % MOD)) else: print((0)) solve()
from math import factorial N, K = [int(_) for _ in input().split()] # N = 10 MOD = 10 ** 9 + 7 kaijo = [0] * (N + 1) kaijo[0] = kaijo[1] = 1 for i in range(2, N + 1): kaijo[i] = (kaijo[i - 1] * i) % MOD gyaku = [0] * (N + 1) gyaku[0] = gyaku[1] = 1 for i in range(2, N + 1): # gyaku[i] = (gyaku[i - 1] * pow(i, MOD - 2, MOD)) % MOD gyaku[i] = pow(kaijo[i], MOD - 2, MOD) def calc(n, k): return (kaijo[n] * gyaku[n - k] * gyaku[k]) % MOD # return factorial(n) // (factorial(n - k) * factorial(k)) def solve(): for i in range(1, K + 1): n = N - K + 1 k = i if k <= n: print(((calc(n, k) * calc(K - 1, i - 1)) % MOD)) else: print((0)) solve()
35
35
760
760
from math import factorial N, K = [int(_) for _ in input().split()] # N = 10 MOD = 10**9 + 7 kaijo = [0] * (N + 1) kaijo[0] = kaijo[1] = 1 for i in range(2, N + 1): kaijo[i] = (kaijo[i - 1] * i) % MOD gyaku = [0] * (N + 1) gyaku[0] = gyaku[1] = 1 for i in range(2, N + 1): # gyaku[i] = (gyaku[i - 1] * pow(i, MOD - 2, MOD)) % MOD gyaku[i] = pow(kaijo[i], MOD - 2, MOD) def calc(n, k): # return (kaijo[n] * gyaku[n - k] * gyaku[k]) % MOD return factorial(n) // (factorial(n - k) * factorial(k)) def solve(): for i in range(1, K + 1): n = N - K + 1 k = i if k <= n: print(((calc(n, k) * calc(K - 1, i - 1)) % MOD)) else: print((0)) solve()
from math import factorial N, K = [int(_) for _ in input().split()] # N = 10 MOD = 10**9 + 7 kaijo = [0] * (N + 1) kaijo[0] = kaijo[1] = 1 for i in range(2, N + 1): kaijo[i] = (kaijo[i - 1] * i) % MOD gyaku = [0] * (N + 1) gyaku[0] = gyaku[1] = 1 for i in range(2, N + 1): # gyaku[i] = (gyaku[i - 1] * pow(i, MOD - 2, MOD)) % MOD gyaku[i] = pow(kaijo[i], MOD - 2, MOD) def calc(n, k): return (kaijo[n] * gyaku[n - k] * gyaku[k]) % MOD # return factorial(n) // (factorial(n - k) * factorial(k)) def solve(): for i in range(1, K + 1): n = N - K + 1 k = i if k <= n: print(((calc(n, k) * calc(K - 1, i - 1)) % MOD)) else: print((0)) solve()
false
0
[ "- # return (kaijo[n] * gyaku[n - k] * gyaku[k]) % MOD", "- return factorial(n) // (factorial(n - k) * factorial(k))", "+ return (kaijo[n] * gyaku[n - k] * gyaku[k]) % MOD", "+ # return factorial(n) // (factorial(n - k) * factorial(k))" ]
false
0.075459
0.039583
1.906346
[ "s940997825", "s813299751" ]
u614314290
p02996
python
s172959969
s896409337
1,034
764
69,928
31,852
Accepted
Accepted
26.11
N = int(eval(input())) AB = [list(map(int, input().split())) for _ in range(N)] ab = sorted(AB, key=lambda x:(x[1],x[0])) now = 0 for a, b in ab: if b < now + a: print("No") break else: now += a else: print("Yes")
from operator import itemgetter as ig # 定数 INF = float("inf") MOD = int(1e9 + 7) # エントリーポイント def main(): N = int(eval(input())) AB = (tuple(map(int, input().split())) for _ in range(N)) ab = sorted(AB, key=ig(1)) sum_a = 0 for a, b in ab: sum_a += a if b < sum_a: print("No") break else: print("Yes") main()
14
20
232
395
N = int(eval(input())) AB = [list(map(int, input().split())) for _ in range(N)] ab = sorted(AB, key=lambda x: (x[1], x[0])) now = 0 for a, b in ab: if b < now + a: print("No") break else: now += a else: print("Yes")
from operator import itemgetter as ig # 定数 INF = float("inf") MOD = int(1e9 + 7) # エントリーポイント def main(): N = int(eval(input())) AB = (tuple(map(int, input().split())) for _ in range(N)) ab = sorted(AB, key=ig(1)) sum_a = 0 for a, b in ab: sum_a += a if b < sum_a: print("No") break else: print("Yes") main()
false
30
[ "-N = int(eval(input()))", "-AB = [list(map(int, input().split())) for _ in range(N)]", "-ab = sorted(AB, key=lambda x: (x[1], x[0]))", "-now = 0", "-for a, b in ab:", "- if b < now + a:", "- print(\"No\")", "- break", "+from operator import itemgetter as ig", "+", "+# 定数", "+...
false
0.102947
0.047085
2.18642
[ "s172959969", "s896409337" ]
u753803401
p02983
python
s775719219
s086360035
198
176
40,688
38,768
Accepted
Accepted
11.11
def slove(): import sys input = sys.stdin.readline l, r = list(map(int, input().rstrip('\n').split())) m = 10 ** 10 for i in range(l, r + 1): for j in range(i + 1, r + 1): m = min(m, (i * j) % 2019) if m == 0: print(m) exit() print(m) if __name__ == '__main__': slove()
import sys def slove(): input = sys.stdin.readline l, r = list(map(int, input().rstrip('\n').split())) mt = 10 ** 10 for i in range(l, r + 1): for j in range(i + 1, r + 1): mt = min(mt, (i * j) % 2019) if mt == 0: print(mt) exit() print(mt) if __name__ == '__main__': slove()
16
18
379
385
def slove(): import sys input = sys.stdin.readline l, r = list(map(int, input().rstrip("\n").split())) m = 10**10 for i in range(l, r + 1): for j in range(i + 1, r + 1): m = min(m, (i * j) % 2019) if m == 0: print(m) exit() print(m) if __name__ == "__main__": slove()
import sys def slove(): input = sys.stdin.readline l, r = list(map(int, input().rstrip("\n").split())) mt = 10**10 for i in range(l, r + 1): for j in range(i + 1, r + 1): mt = min(mt, (i * j) % 2019) if mt == 0: print(mt) exit() print(mt) if __name__ == "__main__": slove()
false
11.111111
[ "+import sys", "+", "+", "- import sys", "-", "- m = 10**10", "+ mt = 10**10", "- m = min(m, (i * j) % 2019)", "- if m == 0:", "- print(m)", "+ mt = min(mt, (i * j) % 2019)", "+ if mt == 0:", "+ print(mt)", ...
false
0.049121
0.07713
0.636862
[ "s775719219", "s086360035" ]
u254871849
p03327
python
s146905306
s944248323
20
17
3,316
2,940
Accepted
Accepted
15
# author: kagemeka # created: 2019-11-08 02:12:52(JST) ## internal modules import sys # import collections # import math # import string # import bisect # import re # import itertools # import statistics # import functools # import operator ## external modules # import scipy.special # if use comb function on AtCoder, # import scipy.misc # select scipy.misc.comb (old version) def main(): n = int(sys.stdin.readline().rstrip()) if n < 1000: ans = 'ABC' else: ans = 'ABD' print(ans) if __name__ == "__main__": # execute only if run as a script main()
import sys n = int(sys.stdin.readline().rstrip()) def main(): return 'ABC' if n < 1000 else 'ABD' if __name__ == '__main__': ans = main() print(ans)
31
10
689
172
# author: kagemeka # created: 2019-11-08 02:12:52(JST) ## internal modules import sys # import collections # import math # import string # import bisect # import re # import itertools # import statistics # import functools # import operator ## external modules # import scipy.special # if use comb function on AtCoder, # import scipy.misc # select scipy.misc.comb (old version) def main(): n = int(sys.stdin.readline().rstrip()) if n < 1000: ans = "ABC" else: ans = "ABD" print(ans) if __name__ == "__main__": # execute only if run as a script main()
import sys n = int(sys.stdin.readline().rstrip()) def main(): return "ABC" if n < 1000 else "ABD" if __name__ == "__main__": ans = main() print(ans)
false
67.741935
[ "-# author: kagemeka", "-# created: 2019-11-08 02:12:52(JST)", "-## internal modules", "-# import collections", "-# import math", "-# import string", "-# import bisect", "-# import re", "-# import itertools", "-# import statistics", "-# import fun...
false
0.042351
0.041982
1.00878
[ "s146905306", "s944248323" ]
u987164499
p03549
python
s368208444
s437502929
327
27
18,388
9,408
Accepted
Accepted
91.74
from sys import stdin import math import bisect import heapq import numpy as np n,m = [int(x) for x in stdin.readline().rstrip().split()] print(((100*(n-m)+1900*m)*2**m))
n,m = list(map(int,input().split())) # 全ての問題に正解する確率 all_ac = (0.5)**m print((int((1900*m+100*(n-m))/all_ac)))
8
6
176
108
from sys import stdin import math import bisect import heapq import numpy as np n, m = [int(x) for x in stdin.readline().rstrip().split()] print(((100 * (n - m) + 1900 * m) * 2**m))
n, m = list(map(int, input().split())) # 全ての問題に正解する確率 all_ac = (0.5) ** m print((int((1900 * m + 100 * (n - m)) / all_ac)))
false
25
[ "-from sys import stdin", "-import math", "-import bisect", "-import heapq", "-import numpy as np", "-", "-n, m = [int(x) for x in stdin.readline().rstrip().split()]", "-print(((100 * (n - m) + 1900 * m) * 2**m))", "+n, m = list(map(int, input().split()))", "+# 全ての問題に正解する確率", "+all_ac = (0.5) **...
false
0.036827
0.037077
0.993253
[ "s368208444", "s437502929" ]
u844789719
p03287
python
s385011624
s690523011
110
78
14,424
21,336
Accepted
Accepted
29.09
N, M = [int(_) for _ in input().split()] A = [int(_) for _ in input().split()] cumsum = 0 count = {} for i in range(N): cumsum += A[i] cumsum %= M count[cumsum] = count.get(cumsum, 0) + 1 ans = count.get(0, 0) for k in count: n = count[k] ans += (n * (n - 1)) // 2 print(ans)
import itertools, collections N, M = [int(_) for _ in input().split()] A = [int(_) for _ in input().split()] cum = [0] + [c % M for c in itertools.accumulate(A)] cnt = collections.Counter(cum) ans = sum(v * (v - 1) // 2 for v in list(cnt.values())) print(ans)
13
7
307
260
N, M = [int(_) for _ in input().split()] A = [int(_) for _ in input().split()] cumsum = 0 count = {} for i in range(N): cumsum += A[i] cumsum %= M count[cumsum] = count.get(cumsum, 0) + 1 ans = count.get(0, 0) for k in count: n = count[k] ans += (n * (n - 1)) // 2 print(ans)
import itertools, collections N, M = [int(_) for _ in input().split()] A = [int(_) for _ in input().split()] cum = [0] + [c % M for c in itertools.accumulate(A)] cnt = collections.Counter(cum) ans = sum(v * (v - 1) // 2 for v in list(cnt.values())) print(ans)
false
46.153846
[ "+import itertools, collections", "+", "-cumsum = 0", "-count = {}", "-for i in range(N):", "- cumsum += A[i]", "- cumsum %= M", "- count[cumsum] = count.get(cumsum, 0) + 1", "-ans = count.get(0, 0)", "-for k in count:", "- n = count[k]", "- ans += (n * (n - 1)) // 2", "+cum =...
false
0.036817
0.036977
0.995663
[ "s385011624", "s690523011" ]
u072717685
p02613
python
s976186929
s139237318
175
142
69,960
16,552
Accepted
Accepted
18.86
import sys read = sys.stdin.read readline = sys.stdin.readline from itertools import accumulate from collections import deque from math import sqrt from collections import defaultdict def main(): n = int(input()) cnt = defaultdict(int) for _ in range(n): s = input() cnt[s] += 1 print('AC x ', end='') print(cnt['AC']) print('WA x ', end='') print(cnt['WA']) print('TLE x ', end='') print(cnt['TLE']) print('RE x ', end='') print(cnt['RE']) if __name__ == '__main__': main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines from collections import Counter def main(): n = int(eval(input())) d1 = {'AC':0, 'WA':0, 'TLE': 0,'RE':0} s = [] for _ in range(n): s.append(eval(input())) sa = Counter(s) for k, v in list(sa.items()): d1[k] += v print(('AC x', d1['AC'])) print(('WA x', d1['WA'])) print(('TLE x', d1['TLE'])) print(('RE x', d1['RE'])) if __name__ == '__main__': main()
23
21
561
503
import sys read = sys.stdin.read readline = sys.stdin.readline from itertools import accumulate from collections import deque from math import sqrt from collections import defaultdict def main(): n = int(input()) cnt = defaultdict(int) for _ in range(n): s = input() cnt[s] += 1 print("AC x ", end="") print(cnt["AC"]) print("WA x ", end="") print(cnt["WA"]) print("TLE x ", end="") print(cnt["TLE"]) print("RE x ", end="") print(cnt["RE"]) if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines from collections import Counter def main(): n = int(eval(input())) d1 = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0} s = [] for _ in range(n): s.append(eval(input())) sa = Counter(s) for k, v in list(sa.items()): d1[k] += v print(("AC x", d1["AC"])) print(("WA x", d1["WA"])) print(("TLE x", d1["TLE"])) print(("RE x", d1["RE"])) if __name__ == "__main__": main()
false
8.695652
[ "-from itertools import accumulate", "-from collections import deque", "-from math import sqrt", "-from collections import defaultdict", "+readlines = sys.stdin.readlines", "+from collections import Counter", "- n = int(input())", "- cnt = defaultdict(int)", "+ n = int(eval(input()))", "+...
false
0.046772
0.047008
0.99498
[ "s976186929", "s139237318" ]
u729133443
p03280
python
s152356268
s677692104
161
17
38,384
2,940
Accepted
Accepted
89.44
eval('print(('+input().replace(' ','-1)*(')+'-1))')
a,b=list(map(int,input().split()));print((~-a*~-b))
1
1
51
43
eval("print((" + input().replace(" ", "-1)*(") + "-1))")
a, b = list(map(int, input().split())) print((~-a * ~-b))
false
0
[ "-eval(\"print((\" + input().replace(\" \", \"-1)*(\") + \"-1))\")", "+a, b = list(map(int, input().split()))", "+print((~-a * ~-b))" ]
false
0.112128
0.03925
2.856767
[ "s152356268", "s677692104" ]
u073852194
p02772
python
s465430170
s793806280
183
17
38,384
2,940
Accepted
Accepted
90.71
N = int(eval(input())) A = list(map(int,input().split())) for i in range(N): if A[i]%2 == 0: if A[i]%3!=0 and A[i]%5!=0: print('DENIED') break else: print('APPROVED')
#!/usr/bin/env python3 #import sys; sys.stdin=open('input_file.txt') #------------------------------------------ N = int(eval(input())) A = list(map(int,input().split())) for i in range(N): if A[i]%2 == 0 and A[i]%3!=0 and A[i]%5!=0: print('DENIED') break else: print('APPROVED')
9
11
208
308
N = int(eval(input())) A = list(map(int, input().split())) for i in range(N): if A[i] % 2 == 0: if A[i] % 3 != 0 and A[i] % 5 != 0: print("DENIED") break else: print("APPROVED")
#!/usr/bin/env python3 # import sys; sys.stdin=open('input_file.txt') # ------------------------------------------ N = int(eval(input())) A = list(map(int, input().split())) for i in range(N): if A[i] % 2 == 0 and A[i] % 3 != 0 and A[i] % 5 != 0: print("DENIED") break else: print("APPROVED")
false
18.181818
[ "+#!/usr/bin/env python3", "+# import sys; sys.stdin=open('input_file.txt')", "- if A[i] % 2 == 0:", "- if A[i] % 3 != 0 and A[i] % 5 != 0:", "- print(\"DENIED\")", "- break", "+ if A[i] % 2 == 0 and A[i] % 3 != 0 and A[i] % 5 != 0:", "+ print(\"DENIED\")", ...
false
0.042028
0.035385
1.187727
[ "s465430170", "s793806280" ]
u547167033
p03078
python
s723426342
s410824121
895
789
4,084
4,084
Accepted
Accepted
11.84
from heapq import nlargest 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=nlargest(k,(x+y for x in a for y in b)) abc=nlargest(k,(xy+z for xy in ab for z in c)) for i in abc: print(i)
from heapq import nlargest 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=nlargest(k,(x+y for x in a for y in b)) abc=nlargest(k,(x+y for x in ab for y in c)) for i in abc: print(i)
9
9
281
279
from heapq import nlargest 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 = nlargest(k, (x + y for x in a for y in b)) abc = nlargest(k, (xy + z for xy in ab for z in c)) for i in abc: print(i)
from heapq import nlargest 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 = nlargest(k, (x + y for x in a for y in b)) abc = nlargest(k, (x + y for x in ab for y in c)) for i in abc: print(i)
false
0
[ "-abc = nlargest(k, (xy + z for xy in ab for z in c))", "+abc = nlargest(k, (x + y for x in ab for y in c))" ]
false
0.104998
0.039402
2.664824
[ "s723426342", "s410824121" ]
u941438707
p03818
python
s437821335
s731442800
54
47
20,084
22,464
Accepted
Accepted
12.96
n,*a=list(map(int,open(0).read().split())) b=len(set(a)) print((b-(n-b)%2))
_,a=open(0);b=len(set(a.split()));print((b+b%2-1))
3
1
69
48
n, *a = list(map(int, open(0).read().split())) b = len(set(a)) print((b - (n - b) % 2))
_, a = open(0) b = len(set(a.split())) print((b + b % 2 - 1))
false
66.666667
[ "-n, *a = list(map(int, open(0).read().split()))", "-b = len(set(a))", "-print((b - (n - b) % 2))", "+_, a = open(0)", "+b = len(set(a.split()))", "+print((b + b % 2 - 1))" ]
false
0.125197
0.0474
2.641313
[ "s437821335", "s731442800" ]
u389910364
p03157
python
s678236870
s726328939
1,958
1,001
249,956
13,928
Accepted
Accepted
48.88
import bisect import heapq import itertools import math import operator import os import re import string import sys from collections import Counter, deque, defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter, mul, add, xor import numpy as np from scipy.misc import comb if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 H, W = list(map(int, sys.stdin.readline().split())) S = [list(sys.stdin.readline().rstrip()) for _ in range(H)] seen = np.zeros((H, W), dtype=bool) def dfs(h, w): if seen[h][w]: return 0, 0 seen[h][w] = True black = int(S[h][w] == '#') white = int(S[h][w] == '.') for dh, dw in zip([h, h, h + 1, h - 1], [w + 1, w - 1, w, w]): if 0 <= dh < H and 0 <= dw < W: if S[h][w] != S[dh][dw]: counts = dfs(dh, dw) black += counts[0] white += counts[1] return black, white ans = 0 for h, w in itertools.product(list(range(H)), list(range(W))): black, white = dfs(h, w) ans += black * white print(ans)
import itertools import itertools import os import sys from collections import deque import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 H, W = list(map(int, sys.stdin.readline().split())) S = [list(sys.stdin.readline().rstrip()) for _ in range(H)] seen = np.zeros((H, W), dtype=bool) ans = 0 for h, w in itertools.product(list(range(H)), list(range(W))): if seen[h][w]: continue que = deque() que.append((h, w)) black = white = 0 while que: h, w = que.popleft() if seen[h][w]: continue seen[h][w] = True if S[h][w] == '#': black += 1 else: white += 1 for dh, dw in zip((h + 1, h - 1, h, h), (w, w, w + 1, w - 1)): if 0 <= dh < H and 0 <= dw < W and not seen[dh][dw]: if S[h][w] != S[dh][dw]: que.append((dh, dw)) ans += black * white print(ans)
52
42
1,276
1,058
import bisect import heapq import itertools import math import operator import os import re import string import sys from collections import Counter, deque, defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter, mul, add, xor import numpy as np from scipy.misc import comb if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 H, W = list(map(int, sys.stdin.readline().split())) S = [list(sys.stdin.readline().rstrip()) for _ in range(H)] seen = np.zeros((H, W), dtype=bool) def dfs(h, w): if seen[h][w]: return 0, 0 seen[h][w] = True black = int(S[h][w] == "#") white = int(S[h][w] == ".") for dh, dw in zip([h, h, h + 1, h - 1], [w + 1, w - 1, w, w]): if 0 <= dh < H and 0 <= dw < W: if S[h][w] != S[dh][dw]: counts = dfs(dh, dw) black += counts[0] white += counts[1] return black, white ans = 0 for h, w in itertools.product(list(range(H)), list(range(W))): black, white = dfs(h, w) ans += black * white print(ans)
import itertools import itertools import os import sys from collections import deque import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 H, W = list(map(int, sys.stdin.readline().split())) S = [list(sys.stdin.readline().rstrip()) for _ in range(H)] seen = np.zeros((H, W), dtype=bool) ans = 0 for h, w in itertools.product(list(range(H)), list(range(W))): if seen[h][w]: continue que = deque() que.append((h, w)) black = white = 0 while que: h, w = que.popleft() if seen[h][w]: continue seen[h][w] = True if S[h][w] == "#": black += 1 else: white += 1 for dh, dw in zip((h + 1, h - 1, h, h), (w, w, w + 1, w - 1)): if 0 <= dh < H and 0 <= dw < W and not seen[dh][dw]: if S[h][w] != S[dh][dw]: que.append((dh, dw)) ans += black * white print(ans)
false
19.230769
[ "-import bisect", "-import heapq", "-import math", "-import operator", "+import itertools", "-import re", "-import string", "-from collections import Counter, deque, defaultdict", "-from copy import deepcopy", "-from decimal import Decimal", "-from fractions import gcd", "-from functools impor...
false
0.515246
0.283858
1.815154
[ "s678236870", "s726328939" ]
u145231176
p03426
python
s065410416
s814436874
678
621
121,688
102,744
Accepted
Accepted
8.41
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import permutations from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# # Dかそれぞれのqueryで固定なのでこの問題は解ける H, W, D = getNM() maze = [] for i in range(H): a = getList() maze.append(a) Q = getN() # piece[0]からpiece[1]まで # 4 → 6 → 8 piece = [] for i in range(Q): l, r = getNM() piece.append([l, r]) place_list = [[-1, -1] for i in range(H * W)] for y in range(H): for x in range(W): place_list[maze[y][x] - 1] = [x, y] # 飛ばし累積和 x_plus = [] y_plus = [] for i in range(D): list_x = [0] list_y = [0] for j in range(i, H * W, D): if j == i: opt_x = 0 opt_y = 0 else: opt_x = abs(place_list[j][0] - place_list[j - D][0]) opt_y = abs(place_list[j][1] - place_list[j - D][1]) list_x.append(list_x[-1] + opt_x) list_y.append(list_y[-1] + opt_y) list_x.pop(0) list_y.pop(0) x_plus.append(list_x) y_plus.append(list_y) def past_exam(piece_query): start = piece_query[0] goal = piece_query[1] mul = (start - 1) % D if D == 1: x_point = x_plus[0][goal - 1] - x_plus[0][start - 1] # 書き間違い!! y_point = y_plus[0][goal - 1] - y_plus[0][start - 1] else: x_point = x_plus[mul][(goal - mul) // D] - x_plus[mul][(start - mul) // D] y_point = y_plus[mul][(goal - mul) // D] - y_plus[mul][(start - mul) // D] return x_point + y_point for i in range(Q): print((past_exam(piece[i])))
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import permutations from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# """ # 飛ばし累積和 N = 10 num = [i for i in range(1, N + 1)] D = 2 lista = [0] * N for i in range(D): for j in range(i, N, D): if j == i: lista[j] = num[j] else: lista[j] = num[j] + lista[j - D] # [1, 2, 4, 6, 9, 12, 16, 20, 25, 30] print(lista) # 9番目までの奇数の数字の合計 - 1番目までの奇数の数字の合計 # 3 + 5 + 7 + 9 print(lista[8] - lista[0]) """ # Dかそれぞれのqueryで固定なのでこの問題は解ける H, W, D = getNM() maze = [] for i in range(H): a = getList() maze.append(a) Q = getN() # piece[0]からpiece[1]まで # 4 → 6 → 8 piece = [] for i in range(Q): l, r = getNM() piece.append([l, r]) place_list = [[-1, -1] for i in range(H * W)] for y in range(H): for x in range(W): place_list[maze[y][x] - 1] = [x, y] # 飛ばし累積和 x_plus = [0] * (H * W) y_plus = [0] * (H * W) for i in range(D): for j in range(i, H * W, D): if j == i: opt_x = 0 opt_y = 0 else: opt_x = abs(place_list[j][0] - place_list[j - D][0]) opt_y = abs(place_list[j][1] - place_list[j - D][1]) x_plus[j] = opt_x + x_plus[j - D] y_plus[j] = opt_y + y_plus[j - D] def past_exam(piece_query): start = piece_query[0] goal = piece_query[1] x_point = x_plus[goal - 1] - x_plus[start - 1] y_point = y_plus[goal - 1] - y_plus[start - 1] return x_point + y_point for i in range(Q): print((past_exam(piece[i])))
109
116
2,727
2,753
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import permutations from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10**9 + 7 ############# # Main Code # ############# # Dかそれぞれのqueryで固定なのでこの問題は解ける H, W, D = getNM() maze = [] for i in range(H): a = getList() maze.append(a) Q = getN() # piece[0]からpiece[1]まで # 4 → 6 → 8 piece = [] for i in range(Q): l, r = getNM() piece.append([l, r]) place_list = [[-1, -1] for i in range(H * W)] for y in range(H): for x in range(W): place_list[maze[y][x] - 1] = [x, y] # 飛ばし累積和 x_plus = [] y_plus = [] for i in range(D): list_x = [0] list_y = [0] for j in range(i, H * W, D): if j == i: opt_x = 0 opt_y = 0 else: opt_x = abs(place_list[j][0] - place_list[j - D][0]) opt_y = abs(place_list[j][1] - place_list[j - D][1]) list_x.append(list_x[-1] + opt_x) list_y.append(list_y[-1] + opt_y) list_x.pop(0) list_y.pop(0) x_plus.append(list_x) y_plus.append(list_y) def past_exam(piece_query): start = piece_query[0] goal = piece_query[1] mul = (start - 1) % D if D == 1: x_point = x_plus[0][goal - 1] - x_plus[0][start - 1] # 書き間違い!! y_point = y_plus[0][goal - 1] - y_plus[0][start - 1] else: x_point = x_plus[mul][(goal - mul) // D] - x_plus[mul][(start - mul) // D] y_point = y_plus[mul][(goal - mul) // D] - y_plus[mul][(start - mul) // D] return x_point + y_point for i in range(Q): print((past_exam(piece[i])))
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import permutations from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10**9 + 7 ############# # Main Code # ############# """ # 飛ばし累積和 N = 10 num = [i for i in range(1, N + 1)] D = 2 lista = [0] * N for i in range(D): for j in range(i, N, D): if j == i: lista[j] = num[j] else: lista[j] = num[j] + lista[j - D] # [1, 2, 4, 6, 9, 12, 16, 20, 25, 30] print(lista) # 9番目までの奇数の数字の合計 - 1番目までの奇数の数字の合計 # 3 + 5 + 7 + 9 print(lista[8] - lista[0]) """ # Dかそれぞれのqueryで固定なのでこの問題は解ける H, W, D = getNM() maze = [] for i in range(H): a = getList() maze.append(a) Q = getN() # piece[0]からpiece[1]まで # 4 → 6 → 8 piece = [] for i in range(Q): l, r = getNM() piece.append([l, r]) place_list = [[-1, -1] for i in range(H * W)] for y in range(H): for x in range(W): place_list[maze[y][x] - 1] = [x, y] # 飛ばし累積和 x_plus = [0] * (H * W) y_plus = [0] * (H * W) for i in range(D): for j in range(i, H * W, D): if j == i: opt_x = 0 opt_y = 0 else: opt_x = abs(place_list[j][0] - place_list[j - D][0]) opt_y = abs(place_list[j][1] - place_list[j - D][1]) x_plus[j] = opt_x + x_plus[j - D] y_plus[j] = opt_y + y_plus[j - D] def past_exam(piece_query): start = piece_query[0] goal = piece_query[1] x_point = x_plus[goal - 1] - x_plus[start - 1] y_point = y_plus[goal - 1] - y_plus[start - 1] return x_point + y_point for i in range(Q): print((past_exam(piece[i])))
false
6.034483
[ "+\"\"\"", "+# 飛ばし累積和", "+N = 10", "+num = [i for i in range(1, N + 1)]", "+D = 2", "+lista = [0] * N", "+for i in range(D):", "+ for j in range(i, N, D):", "+ if j == i:", "+ lista[j] = num[j]", "+ else:", "+ lista[j] = num[j] + lista[j - D]", "+# [1, ...
false
0.040488
0.043838
0.923576
[ "s065410416", "s814436874" ]
u433532588
p03290
python
s839930867
s695880361
147
23
3,316
3,064
Accepted
Accepted
84.35
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) ############################## D, G = list(map(int, input().split())) P = [] * D C = [] * D for i in range(D): p, c = list(map(int, input().split())) P.append(p) C.append(c) ans = float('inf') for i in range(1<<D): total = 0 num = 0 for j in range(D): if ((i >> j) & 1): total += C[j] + 100*P[j]*(j+1) num += P[j] if total >= G: ans = min(ans, num) else: for j in range(D-1, -1, -1): if ((i >> j) & 1): continue for k in range(P[j]-1): if total >= G: break total += 100*(j+1) num += 1 if total >= G: ans = min(ans, num) print(ans)
import sys input = sys.stdin.readline sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # A = [ int(input()) for _ in range(N) ] ############################## D, G = list(map(int, input().split())) P = [] C = [] for i in range(D): p, c = list(map(int, input().split())) P.append(p) C.append(c) ans = INF for i in range(1 << D): score = 0 count = 0 for j in range(D): if ((i >> j) & 1): score += (j+1)*P[j]*100+C[j] count += P[j] else: basic = j remain = G-score if remain <= 0: ans = min(ans, count) continue # print(remain, count, ans) # まだ残ってる場合、もっとも高いやつから if (remain - ( (P[basic]-1)*(basic+1)*100)) > 0: # 全部使っても駄目 continue p = P[basic] while p > 1 and remain > 0: remain -= (basic+1)*100 p -= 1 count += 1 if remain <= 0: ans = min(ans, count) print(ans)
40
50
839
990
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) ############################## D, G = list(map(int, input().split())) P = [] * D C = [] * D for i in range(D): p, c = list(map(int, input().split())) P.append(p) C.append(c) ans = float("inf") for i in range(1 << D): total = 0 num = 0 for j in range(D): if (i >> j) & 1: total += C[j] + 100 * P[j] * (j + 1) num += P[j] if total >= G: ans = min(ans, num) else: for j in range(D - 1, -1, -1): if (i >> j) & 1: continue for k in range(P[j] - 1): if total >= G: break total += 100 * (j + 1) num += 1 if total >= G: ans = min(ans, num) print(ans)
import sys input = sys.stdin.readline sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 # A = [ int(input()) for _ in range(N) ] ############################## D, G = list(map(int, input().split())) P = [] C = [] for i in range(D): p, c = list(map(int, input().split())) P.append(p) C.append(c) ans = INF for i in range(1 << D): score = 0 count = 0 for j in range(D): if (i >> j) & 1: score += (j + 1) * P[j] * 100 + C[j] count += P[j] else: basic = j remain = G - score if remain <= 0: ans = min(ans, count) continue # print(remain, count, ans) # まだ残ってる場合、もっとも高いやつから if (remain - ((P[basic] - 1) * (basic + 1) * 100)) > 0: # 全部使っても駄目 continue p = P[basic] while p > 1 and remain > 0: remain -= (basic + 1) * 100 p -= 1 count += 1 if remain <= 0: ans = min(ans, count) print(ans)
false
20
[ "-sys.setrecursionlimit(10**6)", "+sys.setrecursionlimit(2147483647)", "+INF = float(\"inf\")", "+MOD = 10**9 + 7", "+# A = [ int(input()) for _ in range(N) ]", "-P = [] * D", "-C = [] * D", "+P = []", "+C = []", "-ans = float(\"inf\")", "+ans = INF", "- total = 0", "- num = 0", "+ ...
false
0.097983
0.040138
2.441162
[ "s839930867", "s695880361" ]
u965436898
p02887
python
s808011539
s771106325
295
42
51,552
3,316
Accepted
Accepted
85.76
import re n = int(eval(input())) s = eval(input()) ans = s for i in range(26): ans = re.sub("([a-z])\\1","\\1",ans) print((len(ans)))
#import re n = int(eval(input())) s = eval(input()) ans = 1 for i in range(1,len(s)): if s[i] != s[i-1]: ans += 1 print(ans) # またはa-zまで正規表現をかます # for i in range(26): # ans = re.sub("([a-z])\\1","\\1",ans) # print(len(ans))
7
15
128
236
import re n = int(eval(input())) s = eval(input()) ans = s for i in range(26): ans = re.sub("([a-z])\\1", "\\1", ans) print((len(ans)))
# import re n = int(eval(input())) s = eval(input()) ans = 1 for i in range(1, len(s)): if s[i] != s[i - 1]: ans += 1 print(ans) # またはa-zまで正規表現をかます # for i in range(26): # ans = re.sub("([a-z])\\1","\\1",ans) # print(len(ans))
false
53.333333
[ "-import re", "-", "+# import re", "-ans = s", "-for i in range(26):", "- ans = re.sub(\"([a-z])\\\\1\", \"\\\\1\", ans)", "-print((len(ans)))", "+ans = 1", "+for i in range(1, len(s)):", "+ if s[i] != s[i - 1]:", "+ ans += 1", "+print(ans)", "+# またはa-zまで正規表現をかます", "+# for i i...
false
0.047269
0.034449
1.372144
[ "s808011539", "s771106325" ]
u212328220
p02732
python
s118820344
s925199882
433
278
26,772
33,920
Accepted
Accepted
35.8
from collections import Counter N = int(eval(input())) al = list(map(int, input().split())) C = Counter(al) # print(C) # print(C.values()) ans = 0 for i in list(C.values()): ans += i * (i - 1) / 2 for a in al: k = C[a] print((int(ans - (k * (k - 1) / 2) + (k - 1) * (k - 2) / 2)))
import math from collections import Counter import itertools n = int(eval(input())) al = list(map(int,input().split())) C_al = Counter(al) all = 0 for i in list(C_al.values()): all += i*(i-1)/2 for i in al: k = C_al[i] print((int(all - (k * (k - 1) / 2) + (k - 1) * (k - 2) / 2)))
14
17
294
304
from collections import Counter N = int(eval(input())) al = list(map(int, input().split())) C = Counter(al) # print(C) # print(C.values()) ans = 0 for i in list(C.values()): ans += i * (i - 1) / 2 for a in al: k = C[a] print((int(ans - (k * (k - 1) / 2) + (k - 1) * (k - 2) / 2)))
import math from collections import Counter import itertools n = int(eval(input())) al = list(map(int, input().split())) C_al = Counter(al) all = 0 for i in list(C_al.values()): all += i * (i - 1) / 2 for i in al: k = C_al[i] print((int(all - (k * (k - 1) / 2) + (k - 1) * (k - 2) / 2)))
false
17.647059
[ "+import math", "+import itertools", "-N = int(eval(input()))", "+n = int(eval(input()))", "-C = Counter(al)", "-# print(C)", "-# print(C.values())", "-ans = 0", "-for i in list(C.values()):", "- ans += i * (i - 1) / 2", "-for a in al:", "- k = C[a]", "- print((int(ans - (k * (k - 1...
false
0.042137
0.045996
0.916101
[ "s118820344", "s925199882" ]
u366959492
p02861
python
s893109430
s925920234
231
213
41,068
40,812
Accepted
Accepted
7.79
n=int(eval(input())) s=0 xy=[tuple(map(int,input().split())) for _ in range(n)] import itertools l=[i for i in range(1,n+1)] for y in itertools.permutations(l): for i in range(n-1): s+=((xy[y[i]-1][0]-xy[y[i+1]-1][0])**2+(xy[y[i]-1][1]-xy[y[i+1]-1][1])**2)**0.5 e=1 for i in range(1,n+1): e*=i print((s/e))
n=int(eval(input())) xy=[list(map(int,input().split())) for _ in range(n)] import itertools as it ans=0 for i in it.permutations(list(range(n)),n): x=xy[i[0]][0] y=xy[i[0]][1] for k in range(1,n): j=i[k] ans+=((x-xy[j][0])**2+(y-xy[j][1])**2)**0.5 x=xy[j][0] y=xy[j][1] N=1 for i in range(1,n+1): N*=i print((ans/N))
12
16
326
366
n = int(eval(input())) s = 0 xy = [tuple(map(int, input().split())) for _ in range(n)] import itertools l = [i for i in range(1, n + 1)] for y in itertools.permutations(l): for i in range(n - 1): s += ( (xy[y[i] - 1][0] - xy[y[i + 1] - 1][0]) ** 2 + (xy[y[i] - 1][1] - xy[y[i + 1] - 1][1]) ** 2 ) ** 0.5 e = 1 for i in range(1, n + 1): e *= i print((s / e))
n = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(n)] import itertools as it ans = 0 for i in it.permutations(list(range(n)), n): x = xy[i[0]][0] y = xy[i[0]][1] for k in range(1, n): j = i[k] ans += ((x - xy[j][0]) ** 2 + (y - xy[j][1]) ** 2) ** 0.5 x = xy[j][0] y = xy[j][1] N = 1 for i in range(1, n + 1): N *= i print((ans / N))
false
25
[ "-s = 0", "-xy = [tuple(map(int, input().split())) for _ in range(n)]", "-import itertools", "+xy = [list(map(int, input().split())) for _ in range(n)]", "+import itertools as it", "-l = [i for i in range(1, n + 1)]", "-for y in itertools.permutations(l):", "- for i in range(n - 1):", "- s...
false
0.044363
0.045499
0.975024
[ "s893109430", "s925920234" ]
u899909022
p03044
python
s068373810
s108059662
1,346
813
46,032
47,444
Accepted
Accepted
39.6
n=int(eval(input())) L=[[] for i in range(n)] for i in range(n-1): u,v,w=list(map(int, input().split())) u-=1 v-=1 L[u].append([v,w]) L[v].append([u,w]) ans=[-1]*n ans[0]=0 que=[0] import queue que=queue.Queue() que.put(0) while not que.empty(): v=que.get() for u, w in L[v]: if ans[u]!=-1: continue ans[u]=(ans[v]+w)%2 que.put(u) for a in ans: print(a)
n=int(eval(input())) L=[[] for i in range(n)] for i in range(n-1): u,v,w=list(map(int, input().split())) u-=1 v-=1 L[u].append([v,w]) L[v].append([u,w]) ans=[-1]*n ans[0]=0 from collections import deque stack=deque([]) stack.append(0) while stack: v=stack.popleft() for u, w in L[v]: if ans[u]!=-1: continue ans[u]=(ans[v]+w)%2 stack.appendleft(u) for a in ans: print(a)
23
22
431
448
n = int(eval(input())) L = [[] for i in range(n)] for i in range(n - 1): u, v, w = list(map(int, input().split())) u -= 1 v -= 1 L[u].append([v, w]) L[v].append([u, w]) ans = [-1] * n ans[0] = 0 que = [0] import queue que = queue.Queue() que.put(0) while not que.empty(): v = que.get() for u, w in L[v]: if ans[u] != -1: continue ans[u] = (ans[v] + w) % 2 que.put(u) for a in ans: print(a)
n = int(eval(input())) L = [[] for i in range(n)] for i in range(n - 1): u, v, w = list(map(int, input().split())) u -= 1 v -= 1 L[u].append([v, w]) L[v].append([u, w]) ans = [-1] * n ans[0] = 0 from collections import deque stack = deque([]) stack.append(0) while stack: v = stack.popleft() for u, w in L[v]: if ans[u] != -1: continue ans[u] = (ans[v] + w) % 2 stack.appendleft(u) for a in ans: print(a)
false
4.347826
[ "-que = [0]", "-import queue", "+from collections import deque", "-que = queue.Queue()", "-que.put(0)", "-while not que.empty():", "- v = que.get()", "+stack = deque([])", "+stack.append(0)", "+while stack:", "+ v = stack.popleft()", "- que.put(u)", "+ stack.appendleft(u)...
false
0.089925
0.087046
1.033078
[ "s068373810", "s108059662" ]
u313111801
p03036
python
s246004669
s722191812
31
26
9,084
9,108
Accepted
Accepted
16.13
import itertools x=[0]*1000 r,D,x[0]=list(map(int,input().split())) for i in range(0,99): x[i+1]=r*x[i]-D for i in range(10): print((x[i+1]))
import itertools r,D,x=list(map(int,input().split())) for i in range(10): x=r*x-D print(x)
8
6
150
99
import itertools x = [0] * 1000 r, D, x[0] = list(map(int, input().split())) for i in range(0, 99): x[i + 1] = r * x[i] - D for i in range(10): print((x[i + 1]))
import itertools r, D, x = list(map(int, input().split())) for i in range(10): x = r * x - D print(x)
false
25
[ "-x = [0] * 1000", "-r, D, x[0] = list(map(int, input().split()))", "-for i in range(0, 99):", "- x[i + 1] = r * x[i] - D", "+r, D, x = list(map(int, input().split()))", "- print((x[i + 1]))", "+ x = r * x - D", "+ print(x)" ]
false
0.135387
0.035728
3.789416
[ "s246004669", "s722191812" ]
u315354220
p03030
python
s676569451
s798800601
19
17
3,064
3,060
Accepted
Accepted
10.53
N = int(eval(input())) xy = [] for i in range(N): x, y = list(map(str, input().split())) y = int(y) xy.append([x, y]) sort_xy = sorted(sorted(xy), key=lambda x: (x[0],-x[1])) for i in range(N): for j in range(N): if sort_xy[i][0] == xy[j][0]: if sort_xy[i][1] == xy[j][1]: print((j + 1))
N = int(eval(input())) xy = [] for i in range(N): x, y = input().split() xy.append([i + 1, x, int(y)]) sort_xy = sorted(sorted(xy), key=lambda x: (x[1],-x[2])) for i in range(N): print((sort_xy[i][0]))
15
11
342
219
N = int(eval(input())) xy = [] for i in range(N): x, y = list(map(str, input().split())) y = int(y) xy.append([x, y]) sort_xy = sorted(sorted(xy), key=lambda x: (x[0], -x[1])) for i in range(N): for j in range(N): if sort_xy[i][0] == xy[j][0]: if sort_xy[i][1] == xy[j][1]: print((j + 1))
N = int(eval(input())) xy = [] for i in range(N): x, y = input().split() xy.append([i + 1, x, int(y)]) sort_xy = sorted(sorted(xy), key=lambda x: (x[1], -x[2])) for i in range(N): print((sort_xy[i][0]))
false
26.666667
[ "- x, y = list(map(str, input().split()))", "- y = int(y)", "- xy.append([x, y])", "-sort_xy = sorted(sorted(xy), key=lambda x: (x[0], -x[1]))", "+ x, y = input().split()", "+ xy.append([i + 1, x, int(y)])", "+sort_xy = sorted(sorted(xy), key=lambda x: (x[1], -x[2]))", "- for j in ra...
false
0.044746
0.044292
1.010238
[ "s676569451", "s798800601" ]
u961674365
p02690
python
s408747860
s589095713
1,131
51
9,164
8,996
Accepted
Accepted
95.49
x=int(eval(input())) for i in range(-1000,1000,1): for j in range(-1000,1000,1): if i**5-j**5==x: print((i,j)) exit()
x=int(eval(input())) for i in range(-150,150,1): for j in range(-150,150,1): if i**5-j**5==x: print((i,j)) exit()
6
6
150
147
x = int(eval(input())) for i in range(-1000, 1000, 1): for j in range(-1000, 1000, 1): if i**5 - j**5 == x: print((i, j)) exit()
x = int(eval(input())) for i in range(-150, 150, 1): for j in range(-150, 150, 1): if i**5 - j**5 == x: print((i, j)) exit()
false
0
[ "-for i in range(-1000, 1000, 1):", "- for j in range(-1000, 1000, 1):", "+for i in range(-150, 150, 1):", "+ for j in range(-150, 150, 1):" ]
false
2.76462
0.067004
41.260381
[ "s408747860", "s589095713" ]
u391589398
p02659
python
s194581081
s903027279
28
22
10,068
9,160
Accepted
Accepted
21.43
from decimal import Decimal a, b = list(map(Decimal, input().split())) print((int(a*b)))
a, b = input().split() a = int(a) b = int(b[0]) * 100 + int(b[2]) * 10 + int(b[3]) print((a*b//100))
3
4
83
102
from decimal import Decimal a, b = list(map(Decimal, input().split())) print((int(a * b)))
a, b = input().split() a = int(a) b = int(b[0]) * 100 + int(b[2]) * 10 + int(b[3]) print((a * b // 100))
false
25
[ "-from decimal import Decimal", "-", "-a, b = list(map(Decimal, input().split()))", "-print((int(a * b)))", "+a, b = input().split()", "+a = int(a)", "+b = int(b[0]) * 100 + int(b[2]) * 10 + int(b[3])", "+print((a * b // 100))" ]
false
0.039147
0.035797
1.09359
[ "s194581081", "s903027279" ]
u600402037
p03731
python
s909550198
s900619809
186
150
25,200
26,832
Accepted
Accepted
19.35
N, T = list(map(int, input().split())) TL = [-T] + list(map(int, input().split())) answer = 0 for i in range(1, N+1): answer += T answer -= max(0, TL[i-1] + T - TL[i]) print(answer)
N, T = list(map(int, input().split())) TL = list(map(int, input().split())) answer = T for i in range(N-1): answer += min(TL[i+1] - TL[i], T) print(answer)
8
7
191
160
N, T = list(map(int, input().split())) TL = [-T] + list(map(int, input().split())) answer = 0 for i in range(1, N + 1): answer += T answer -= max(0, TL[i - 1] + T - TL[i]) print(answer)
N, T = list(map(int, input().split())) TL = list(map(int, input().split())) answer = T for i in range(N - 1): answer += min(TL[i + 1] - TL[i], T) print(answer)
false
12.5
[ "-TL = [-T] + list(map(int, input().split()))", "-answer = 0", "-for i in range(1, N + 1):", "- answer += T", "- answer -= max(0, TL[i - 1] + T - TL[i])", "+TL = list(map(int, input().split()))", "+answer = T", "+for i in range(N - 1):", "+ answer += min(TL[i + 1] - TL[i], T)" ]
false
0.075989
0.089372
0.850256
[ "s909550198", "s900619809" ]
u602740328
p03625
python
s686933763
s532755370
472
104
32,060
14,252
Accepted
Accepted
77.97
import numpy as np def search(A): B = list(set(A)) B.sort(reverse=True) if len(A)-len(B) == 0: return 0 a1 = 0 An = np.array(A) for n,(i, j) in enumerate(zip(An[0:-1], An[1:])): if i == j: a1 = i break del(A[:n+2]) return a1 N = int(eval(input())) A = list(map(int, input().split())) A = [a for a in A] A.sort(reverse=True) a1 = search(A) a2 = search(A) if a1 > 0 and a2 > 0: print((a1*a2)) else: print((0))
def search(A): B = list(set(A)) if len(A)-len(B) == 0: return 0 a1 = 0 for n,(i, j) in enumerate(zip(A[0:-1], A[1:])): if i == j: a1 = i break del(A[:n+2]) return a1 N = int(eval(input())) A = list(map(int, input().split())) A = [a for a in A] A.sort(reverse=True) a1 = search(A) a2 = search(A) if a1 > 0 and a2 > 0: print((a1*a2)) else: print((0))
25
21
453
385
import numpy as np def search(A): B = list(set(A)) B.sort(reverse=True) if len(A) - len(B) == 0: return 0 a1 = 0 An = np.array(A) for n, (i, j) in enumerate(zip(An[0:-1], An[1:])): if i == j: a1 = i break del A[: n + 2] return a1 N = int(eval(input())) A = list(map(int, input().split())) A = [a for a in A] A.sort(reverse=True) a1 = search(A) a2 = search(A) if a1 > 0 and a2 > 0: print((a1 * a2)) else: print((0))
def search(A): B = list(set(A)) if len(A) - len(B) == 0: return 0 a1 = 0 for n, (i, j) in enumerate(zip(A[0:-1], A[1:])): if i == j: a1 = i break del A[: n + 2] return a1 N = int(eval(input())) A = list(map(int, input().split())) A = [a for a in A] A.sort(reverse=True) a1 = search(A) a2 = search(A) if a1 > 0 and a2 > 0: print((a1 * a2)) else: print((0))
false
16
[ "-import numpy as np", "-", "-", "- B.sort(reverse=True)", "- An = np.array(A)", "- for n, (i, j) in enumerate(zip(An[0:-1], An[1:])):", "+ for n, (i, j) in enumerate(zip(A[0:-1], A[1:])):" ]
false
0.174386
0.035934
4.852996
[ "s686933763", "s532755370" ]
u347640436
p03231
python
s409907677
s502474300
80
50
17,464
5,344
Accepted
Accepted
37.5
from fractions import gcd def lcm(x, y): return x // gcd(x, y) * y N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) L = lcm(N, M) X = {} for i in range(N): X[(L // N) * i] = S[i] for i in range(M): if (L // M) * i in X and X[(L // M) * i] != T[i]: print((-1)) exit() print(L)
from fractions import gcd def lcm(x, y): return x // gcd(x, y) * y N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) for i in range(N): if M * i % N == 0 and S[i] != T[M * i // N]: print((-1)) exit() print((lcm(N, M)))
22
16
338
265
from fractions import gcd def lcm(x, y): return x // gcd(x, y) * y N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) L = lcm(N, M) X = {} for i in range(N): X[(L // N) * i] = S[i] for i in range(M): if (L // M) * i in X and X[(L // M) * i] != T[i]: print((-1)) exit() print(L)
from fractions import gcd def lcm(x, y): return x // gcd(x, y) * y N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) for i in range(N): if M * i % N == 0 and S[i] != T[M * i // N]: print((-1)) exit() print((lcm(N, M)))
false
27.272727
[ "-L = lcm(N, M)", "-X = {}", "- X[(L // N) * i] = S[i]", "-for i in range(M):", "- if (L // M) * i in X and X[(L // M) * i] != T[i]:", "+ if M * i % N == 0 and S[i] != T[M * i // N]:", "-print(L)", "+print((lcm(N, M)))" ]
false
0.091946
0.047463
1.937214
[ "s409907677", "s502474300" ]
u543954314
p03987
python
s601222921
s483658196
416
325
35,880
40,532
Accepted
Accepted
21.88
n = int(eval(input())) a = list(map(int,input().split())) p = [0]*(n+1) ans = 0 for i in range(n): p[a[i]] = i+1 l = [i-1 for i in range(n+2)] l[0] = 0 r = [i+1 for i in range(n+2)] r[-1] = n+1 for i in range(n,0,-1): ans += (p[i]-l[p[i]])*(r[p[i]]-p[i])*i l[r[p[i]]] = l[p[i]] r[l[p[i]]] = r[p[i]] print(ans)
N = int(eval(input())) a = list(map(int, input().split())) # indexをソート b = [0] * N for i in range(N): b[a[i] - 1] = i # 初期化 端っこ対策としてひとつ余計に取っている left = [0] * (N + 1) right = [0] * (N + 1) for i in range(N + 1): left[i] = i-1 right[i] = i+1 # 更新 for idx in reversed(b): left[right[idx]] = left[idx] right[left[idx]] = right[idx] ans = 0 for i in range(N): ans += a[i] * (i - left[i]) * (right[i] - i) print(ans)
15
25
325
456
n = int(eval(input())) a = list(map(int, input().split())) p = [0] * (n + 1) ans = 0 for i in range(n): p[a[i]] = i + 1 l = [i - 1 for i in range(n + 2)] l[0] = 0 r = [i + 1 for i in range(n + 2)] r[-1] = n + 1 for i in range(n, 0, -1): ans += (p[i] - l[p[i]]) * (r[p[i]] - p[i]) * i l[r[p[i]]] = l[p[i]] r[l[p[i]]] = r[p[i]] print(ans)
N = int(eval(input())) a = list(map(int, input().split())) # indexをソート b = [0] * N for i in range(N): b[a[i] - 1] = i # 初期化 端っこ対策としてひとつ余計に取っている left = [0] * (N + 1) right = [0] * (N + 1) for i in range(N + 1): left[i] = i - 1 right[i] = i + 1 # 更新 for idx in reversed(b): left[right[idx]] = left[idx] right[left[idx]] = right[idx] ans = 0 for i in range(N): ans += a[i] * (i - left[i]) * (right[i] - i) print(ans)
false
40
[ "-n = int(eval(input()))", "+N = int(eval(input()))", "-p = [0] * (n + 1)", "+# indexをソート", "+b = [0] * N", "+for i in range(N):", "+ b[a[i] - 1] = i", "+# 初期化 端っこ対策としてひとつ余計に取っている", "+left = [0] * (N + 1)", "+right = [0] * (N + 1)", "+for i in range(N + 1):", "+ left[i] = i - 1", "+ ...
false
0.008527
0.034264
0.24886
[ "s601222921", "s483658196" ]
u127499732
p03037
python
s853655455
s645480898
117
68
18,292
23,540
Accepted
Accepted
41.88
def main(): IN= open(0).read().split()[2:] left,right=-1*float("inf"),float("inf") for L,R in zip(IN[::2],IN[1::2]): L,R=int(L),int(R) if right<L or R<left: print((0)) break else: tmp=sorted([left,right,L,R]) left,right=tmp[1],tmp[2] else: print((right-left+1)) if __name__=="__main__": main()
def main(): IN=list(map(int,open(0).read().split()[2:]));L,R=max(IN[::2]),min(IN[1::2]);print((R-L+1 if R>=L else 0)) if __name__=="__main__": main()
17
4
361
154
def main(): IN = open(0).read().split()[2:] left, right = -1 * float("inf"), float("inf") for L, R in zip(IN[::2], IN[1::2]): L, R = int(L), int(R) if right < L or R < left: print((0)) break else: tmp = sorted([left, right, L, R]) left, right = tmp[1], tmp[2] else: print((right - left + 1)) if __name__ == "__main__": main()
def main(): IN = list(map(int, open(0).read().split()[2:])) L, R = max(IN[::2]), min(IN[1::2]) print((R - L + 1 if R >= L else 0)) if __name__ == "__main__": main()
false
76.470588
[ "- IN = open(0).read().split()[2:]", "- left, right = -1 * float(\"inf\"), float(\"inf\")", "- for L, R in zip(IN[::2], IN[1::2]):", "- L, R = int(L), int(R)", "- if right < L or R < left:", "- print((0))", "- break", "- else:", "- tmp =...
false
0.041772
0.047046
0.887895
[ "s853655455", "s645480898" ]
u727801592
p03835
python
s525909615
s942520919
1,691
1,466
2,940
3,060
Accepted
Accepted
13.31
K,S=list(map(int,input().split())) crt=0 for x in range(K+1): for y in range(K+1): if S-K<=x+y<=S: crt+=1 print(crt)
K,S=list(map(int,input().split())) crt=0 for x in range(0,K+1): for y in range(0,K+1): z=S-x-y if 0<=z<=K: crt+=1 print(crt)
7
8
128
141
K, S = list(map(int, input().split())) crt = 0 for x in range(K + 1): for y in range(K + 1): if S - K <= x + y <= S: crt += 1 print(crt)
K, S = list(map(int, input().split())) crt = 0 for x in range(0, K + 1): for y in range(0, K + 1): z = S - x - y if 0 <= z <= K: crt += 1 print(crt)
false
12.5
[ "-for x in range(K + 1):", "- for y in range(K + 1):", "- if S - K <= x + y <= S:", "+for x in range(0, K + 1):", "+ for y in range(0, K + 1):", "+ z = S - x - y", "+ if 0 <= z <= K:" ]
false
0.12338
0.046225
2.66909
[ "s525909615", "s942520919" ]
u790710233
p02803
python
s786040602
s394163398
1,587
1,332
3,944
4,080
Accepted
Accepted
16.07
# 上下左右どこでもいける # BFS from queue import Queue h, w = list(map(int, input().split())) MAZE = ['#'*(w+2)] for _ in range(h): MAZE.append("#"+eval(input())+"#") else: MAZE.append('#'*(w+2)) INF = 10**3 directions = [(-1, 0), (0, 1), (1, 0), (0, -1)] def bfs(init_x, init_y): dp = [[INF]*(w+2) for _ in range(h+2)] resisterd = [[0]*(w+2) for _ in range(h+2)] q = Queue() q.put((init_x, init_y)) dp[init_x][init_y] = 0 MAX = 0 while not q.empty(): x, y = q.get() for i, j in directions: if MAZE[x+i][y+j] == '#': continue if resisterd[x+i][y+j]: continue resisterd[x+i][y+j] = 1 q.put((x+i, y+j)) dp[x][y] = min(dp[x][y], min(dp[x+v][y+w]+1 for v, w in directions)) MAX = max(MAX, dp[x][y]) return MAX ans = 0 for i in range(1, h+1): for j in range(1, w+1): if MAZE[i][j] == '#': continue ans = max(ans, bfs(i, j)) print(ans)
from queue import Queue h, w = list(map(int, input().split())) MAZE = ['#'*(w+2)] for _ in range(h): MAZE.append("#"+eval(input())+"#") else: MAZE.append('#'*(w+2)) INF = 10**3 directions = [(-1, 0), (0, 1), (1, 0), (0, -1)] def bfs(init_x, init_y): dist = [[INF]*(w+2) for _ in range(h+2)] q = Queue() q.put((init_x, init_y)) dist[init_x][init_y] = 0 MAX = 0 while not q.empty(): x, y = q.get() for i, j in directions: if MAZE[x+i][y+j] == '#': continue if dist[x+i][y+j] <= dist[x][y]+1: continue dist[x+i][y+j] = dist[x][y]+1 q.put((x+i, y+j)) MAX = max(MAX, dist[x][y]) return MAX ans = 0 for i in range(1, h+1): for j in range(1, w+1): if MAZE[i][j] == '#': continue ans = max(ans, bfs(i, j)) print(ans)
42
38
1,036
911
# 上下左右どこでもいける # BFS from queue import Queue h, w = list(map(int, input().split())) MAZE = ["#" * (w + 2)] for _ in range(h): MAZE.append("#" + eval(input()) + "#") else: MAZE.append("#" * (w + 2)) INF = 10**3 directions = [(-1, 0), (0, 1), (1, 0), (0, -1)] def bfs(init_x, init_y): dp = [[INF] * (w + 2) for _ in range(h + 2)] resisterd = [[0] * (w + 2) for _ in range(h + 2)] q = Queue() q.put((init_x, init_y)) dp[init_x][init_y] = 0 MAX = 0 while not q.empty(): x, y = q.get() for i, j in directions: if MAZE[x + i][y + j] == "#": continue if resisterd[x + i][y + j]: continue resisterd[x + i][y + j] = 1 q.put((x + i, y + j)) dp[x][y] = min(dp[x][y], min(dp[x + v][y + w] + 1 for v, w in directions)) MAX = max(MAX, dp[x][y]) return MAX ans = 0 for i in range(1, h + 1): for j in range(1, w + 1): if MAZE[i][j] == "#": continue ans = max(ans, bfs(i, j)) print(ans)
from queue import Queue h, w = list(map(int, input().split())) MAZE = ["#" * (w + 2)] for _ in range(h): MAZE.append("#" + eval(input()) + "#") else: MAZE.append("#" * (w + 2)) INF = 10**3 directions = [(-1, 0), (0, 1), (1, 0), (0, -1)] def bfs(init_x, init_y): dist = [[INF] * (w + 2) for _ in range(h + 2)] q = Queue() q.put((init_x, init_y)) dist[init_x][init_y] = 0 MAX = 0 while not q.empty(): x, y = q.get() for i, j in directions: if MAZE[x + i][y + j] == "#": continue if dist[x + i][y + j] <= dist[x][y] + 1: continue dist[x + i][y + j] = dist[x][y] + 1 q.put((x + i, y + j)) MAX = max(MAX, dist[x][y]) return MAX ans = 0 for i in range(1, h + 1): for j in range(1, w + 1): if MAZE[i][j] == "#": continue ans = max(ans, bfs(i, j)) print(ans)
false
9.52381
[ "-# 上下左右どこでもいける", "-# BFS", "- dp = [[INF] * (w + 2) for _ in range(h + 2)]", "- resisterd = [[0] * (w + 2) for _ in range(h + 2)]", "+ dist = [[INF] * (w + 2) for _ in range(h + 2)]", "- dp[init_x][init_y] = 0", "+ dist[init_x][init_y] = 0", "- if resisterd[x + i][y + j]:", ...
false
0.048329
0.083027
0.582083
[ "s786040602", "s394163398" ]
u754022296
p02913
python
s942751655
s272790413
1,069
959
232,072
231,944
Accepted
Accepted
10.29
n = int(eval(input())) S = eval(input()) dp = [[0]*n for _ in range(n)] for i in range(n-1, -1, -1): for j in range(n-1, -1, -1): if i == n-1: dp[i][j] = int(S[i] == S[j]) elif j == n-1: dp[i][j] = dp[j][i] else: if S[i] == S[j]: dp[i][j] = dp[i+1][j+1] + 1 ans = 0 for i in range(n): for j in range(n): ans = max(ans, min(dp[i][j], j-i)) print(ans)
def main(): n = int(eval(input())) S = eval(input()) ans = 0 dp = [[0]*n for _ in range(n)] for j in range(n-1, 0, -1): for i in range(j-1, -1, -1): if j == n-1: dp[i][j] = int(S[i] == S[j]) else: if S[i] == S[j]: dp[i][j] = dp[i+1][j+1] + 1 ans = max(ans, min(dp[i][j], j-i)) print(ans) if __name__ == "__main__": main()
17
16
399
386
n = int(eval(input())) S = eval(input()) dp = [[0] * n for _ in range(n)] for i in range(n - 1, -1, -1): for j in range(n - 1, -1, -1): if i == n - 1: dp[i][j] = int(S[i] == S[j]) elif j == n - 1: dp[i][j] = dp[j][i] else: if S[i] == S[j]: dp[i][j] = dp[i + 1][j + 1] + 1 ans = 0 for i in range(n): for j in range(n): ans = max(ans, min(dp[i][j], j - i)) print(ans)
def main(): n = int(eval(input())) S = eval(input()) ans = 0 dp = [[0] * n for _ in range(n)] for j in range(n - 1, 0, -1): for i in range(j - 1, -1, -1): if j == n - 1: dp[i][j] = int(S[i] == S[j]) else: if S[i] == S[j]: dp[i][j] = dp[i + 1][j + 1] + 1 ans = max(ans, min(dp[i][j], j - i)) print(ans) if __name__ == "__main__": main()
false
5.882353
[ "-n = int(eval(input()))", "-S = eval(input())", "-dp = [[0] * n for _ in range(n)]", "-for i in range(n - 1, -1, -1):", "- for j in range(n - 1, -1, -1):", "- if i == n - 1:", "- dp[i][j] = int(S[i] == S[j])", "- elif j == n - 1:", "- dp[i][j] = dp[j][i]", "...
false
0.038438
0.041929
0.916722
[ "s942751655", "s272790413" ]
u408260374
p00271
python
s848648087
s108041583
40
30
6,724
6,728
Accepted
Accepted
25
while True: try: a, b = list(map(int, input().split())) print((a-b)) except: break
for i in range(7): a, b = list(map(int, input().split())) print((a-b))
6
3
111
72
while True: try: a, b = list(map(int, input().split())) print((a - b)) except: break
for i in range(7): a, b = list(map(int, input().split())) print((a - b))
false
50
[ "-while True:", "- try:", "- a, b = list(map(int, input().split()))", "- print((a - b))", "- except:", "- break", "+for i in range(7):", "+ a, b = list(map(int, input().split()))", "+ print((a - b))" ]
false
0.070485
0.18954
0.371874
[ "s848648087", "s108041583" ]
u025945210
p02639
python
s354106609
s301536559
24
22
8,964
9,016
Accepted
Accepted
8.33
x = list(map(int,input().split())) for i in range(5): if x[i] == 0: print((i+1))
x = list(map(int,input().split())) for i in range(0, 5): if x[i] != 0: pass else: print((i+1))
4
6
93
118
x = list(map(int, input().split())) for i in range(5): if x[i] == 0: print((i + 1))
x = list(map(int, input().split())) for i in range(0, 5): if x[i] != 0: pass else: print((i + 1))
false
33.333333
[ "-for i in range(5):", "- if x[i] == 0:", "+for i in range(0, 5):", "+ if x[i] != 0:", "+ pass", "+ else:" ]
false
0.042166
0.040517
1.040713
[ "s354106609", "s301536559" ]
u314050667
p03557
python
s300444719
s953890438
913
280
33,488
26,760
Accepted
Accepted
69.33
import numpy as np import sys input = sys.stdin.readline N = int(eval(input())) A = np.array(input().split(), dtype=np.int64) B = np.array(input().split(), dtype=np.int64) C = np.array(input().split(), dtype=np.int64) A.sort() C.sort() ans = 0 for i in range(N): b = B[i] A_cnt = np.searchsorted(A, b, side='left') C_cnt = np.searchsorted(C, b, side='right') ans += A_cnt * (N-C_cnt) print(ans)
import numpy as np import sys input = sys.stdin.readline N = int(eval(input())) A = np.array(input().split(), dtype=np.int64) B = np.array(input().split(), dtype=np.int64) C = np.array(input().split(), dtype=np.int64) A.sort() C.sort() A_cnt = np.searchsorted(A, B, side='left') C_cnt = np.searchsorted(C, B, side='right') ans = (A_cnt * (N-C_cnt)).sum() print(ans)
20
18
416
382
import numpy as np import sys input = sys.stdin.readline N = int(eval(input())) A = np.array(input().split(), dtype=np.int64) B = np.array(input().split(), dtype=np.int64) C = np.array(input().split(), dtype=np.int64) A.sort() C.sort() ans = 0 for i in range(N): b = B[i] A_cnt = np.searchsorted(A, b, side="left") C_cnt = np.searchsorted(C, b, side="right") ans += A_cnt * (N - C_cnt) print(ans)
import numpy as np import sys input = sys.stdin.readline N = int(eval(input())) A = np.array(input().split(), dtype=np.int64) B = np.array(input().split(), dtype=np.int64) C = np.array(input().split(), dtype=np.int64) A.sort() C.sort() A_cnt = np.searchsorted(A, B, side="left") C_cnt = np.searchsorted(C, B, side="right") ans = (A_cnt * (N - C_cnt)).sum() print(ans)
false
10
[ "-ans = 0", "-for i in range(N):", "- b = B[i]", "- A_cnt = np.searchsorted(A, b, side=\"left\")", "- C_cnt = np.searchsorted(C, b, side=\"right\")", "- ans += A_cnt * (N - C_cnt)", "+A_cnt = np.searchsorted(A, B, side=\"left\")", "+C_cnt = np.searchsorted(C, B, side=\"right\")", "+ans =...
false
0.224964
0.226142
0.994788
[ "s300444719", "s953890438" ]
u601393594
p03737
python
s113974632
s899042218
31
27
9,096
9,048
Accepted
Accepted
12.9
def generate_acronym(l1: list) -> str: answer = "" for i, word in enumerate(l1): # answer.append(word[0].upper()) answer += word[0].upper() return answer lists = list(map(str, input().split())) print((generate_acronym(lists)))
def generate_acronym(l1: list) -> str: answer = "" for word in l1: # answer.append(word[0].upper()) answer += word[0].upper() return answer lists = list(map(str, input().split())) print((generate_acronym(lists)))
11
11
266
252
def generate_acronym(l1: list) -> str: answer = "" for i, word in enumerate(l1): # answer.append(word[0].upper()) answer += word[0].upper() return answer lists = list(map(str, input().split())) print((generate_acronym(lists)))
def generate_acronym(l1: list) -> str: answer = "" for word in l1: # answer.append(word[0].upper()) answer += word[0].upper() return answer lists = list(map(str, input().split())) print((generate_acronym(lists)))
false
0
[ "- for i, word in enumerate(l1):", "+ for word in l1:" ]
false
0.037992
0.037131
1.023192
[ "s113974632", "s899042218" ]
u925782032
p03008
python
s511959529
s725749638
1,923
1,750
227,820
227,820
Accepted
Accepted
9
import sys range = xrange input = raw_input n = int(eval(input())) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] DP = [0]*(n+1) DP[n] = n for j in range(3): sell = A[j] get_back = B[j] if get_back > sell: for i in reversed(list(range(sell,len(DP)))): val1 = DP[i - sell] val2 = DP[i] + get_back - sell if val2 > val1: DP[i-sell] = val2 n = max(DP) A,B = B,A DP = [0]*(n+1) DP[n] = n for j in range(3): sell = A[j] get_back = B[j] if get_back > sell: for i in reversed(list(range(sell,len(DP)))): val1 = DP[i - sell] val2 = DP[i] + get_back - sell if val2 > val1: DP[i-sell] = val2 print((max(DP)))
import sys range = xrange input = raw_input n = int(eval(input())) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] DP = [0]*(n+1) DP[n] = n for j in range(3): sell = A[j] extra = B[j] - sell if extra > 0: for i in reversed(list(range(sell,len(DP)))): if DP[i] + extra > DP[i - sell]: DP[i-sell] = DP[i] + extra n = max(DP) A,B = B,A DP = [0]*(n+1) DP[n] = n for j in range(3): sell = A[j] extra = B[j] - sell if extra > 0: for i in reversed(list(range(sell,len(DP)))): if DP[i] + extra > DP[i - sell]: DP[i-sell] = DP[i] + extra print((max(DP)))
36
31
791
685
import sys range = xrange input = raw_input n = int(eval(input())) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] DP = [0] * (n + 1) DP[n] = n for j in range(3): sell = A[j] get_back = B[j] if get_back > sell: for i in reversed(list(range(sell, len(DP)))): val1 = DP[i - sell] val2 = DP[i] + get_back - sell if val2 > val1: DP[i - sell] = val2 n = max(DP) A, B = B, A DP = [0] * (n + 1) DP[n] = n for j in range(3): sell = A[j] get_back = B[j] if get_back > sell: for i in reversed(list(range(sell, len(DP)))): val1 = DP[i - sell] val2 = DP[i] + get_back - sell if val2 > val1: DP[i - sell] = val2 print((max(DP)))
import sys range = xrange input = raw_input n = int(eval(input())) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] DP = [0] * (n + 1) DP[n] = n for j in range(3): sell = A[j] extra = B[j] - sell if extra > 0: for i in reversed(list(range(sell, len(DP)))): if DP[i] + extra > DP[i - sell]: DP[i - sell] = DP[i] + extra n = max(DP) A, B = B, A DP = [0] * (n + 1) DP[n] = n for j in range(3): sell = A[j] extra = B[j] - sell if extra > 0: for i in reversed(list(range(sell, len(DP)))): if DP[i] + extra > DP[i - sell]: DP[i - sell] = DP[i] + extra print((max(DP)))
false
13.888889
[ "- get_back = B[j]", "- if get_back > sell:", "+ extra = B[j] - sell", "+ if extra > 0:", "- val1 = DP[i - sell]", "- val2 = DP[i] + get_back - sell", "- if val2 > val1:", "- DP[i - sell] = val2", "+ if DP[i] + extra > DP[i - sel...
false
0.040151
0.036937
1.087007
[ "s511959529", "s725749638" ]
u488601719
p00722
python
s772661694
s340450360
620
410
61,752
45,892
Accepted
Accepted
33.87
prime = [False] * (10 ** 6) prime[0] = True prime[1] = True for i in range(2, 10 ** 6): if prime[i] == False: for j in range(i * 2, 10 ** 6, i): prime[j] = True while True: a, d, n = list(map(int, input().split())) if a == 0: break cnt = 0 for i in range(a, 10 ** 6, d): if prime[i] == False: cnt += 1 if cnt == n: print(i) break
import math prime = [False] * (10 ** 6) prime[0] = True prime[1] = True limit = int(math.sqrt(10 ** 6) + 1) for i in range(2, limit): if prime[i] == False: for j in range(i * 2, 10 ** 6, i): prime[j] = True while True: a, d, n = list(map(int, input().split())) if a == 0: break cnt = 0 for i in range(a, 10 ** 6, d): if prime[i] == False: cnt += 1 if cnt == n: print(i) break
22
26
451
503
prime = [False] * (10**6) prime[0] = True prime[1] = True for i in range(2, 10**6): if prime[i] == False: for j in range(i * 2, 10**6, i): prime[j] = True while True: a, d, n = list(map(int, input().split())) if a == 0: break cnt = 0 for i in range(a, 10**6, d): if prime[i] == False: cnt += 1 if cnt == n: print(i) break
import math prime = [False] * (10**6) prime[0] = True prime[1] = True limit = int(math.sqrt(10**6) + 1) for i in range(2, limit): if prime[i] == False: for j in range(i * 2, 10**6, i): prime[j] = True while True: a, d, n = list(map(int, input().split())) if a == 0: break cnt = 0 for i in range(a, 10**6, d): if prime[i] == False: cnt += 1 if cnt == n: print(i) break
false
15.384615
[ "+import math", "+", "-for i in range(2, 10**6):", "+limit = int(math.sqrt(10**6) + 1)", "+for i in range(2, limit):" ]
false
2.092515
0.536579
3.899733
[ "s772661694", "s340450360" ]
u912237403
p00071
python
s122989119
s085413340
20
10
4,288
4,284
Accepted
Accepted
50
def bomb(x,y): global M s=M[y+2] R=[-3,-2,-1,1,2,3] if s[x+2]=="0":return M[y+2]=s[:x+2]+"0"+s[x+3:] for d in R: bomb(x+d,y) bomb(x,y+d) return A=list(range(14)) B=list(range(8)) M=["00000000000000" for i in A] z="000" n=eval(input()) for i in range(n): s=input() for j in B: M[j+3]=z+input()+z x=eval(input()) y=eval(input()) bomb(x,y) print("Data %d:" %(i+1)) for j in B: print(M[j+3][3:-3])
def bomb(x,y): global M s=M[y+2] R=[-3,-2,-1,1,2,3] if s[x+2]=="0":return M[y+2]=s[:x+2]+"0"+s[x+3:] for d in R: bomb(x+d,y) bomb(x,y+d) return A=list(range(14)) B=list(range(3,11)) M=["00000000000000" for i in A] z="000" n=eval(input()) for i in range(n): s=input() for j in B: M[j]=z+input()+z x=eval(input()) y=eval(input()) bomb(x,y) print("Data %d:" %(i+1)) for j in B: print(M[j][3:-3])
26
26
483
482
def bomb(x, y): global M s = M[y + 2] R = [-3, -2, -1, 1, 2, 3] if s[x + 2] == "0": return M[y + 2] = s[: x + 2] + "0" + s[x + 3 :] for d in R: bomb(x + d, y) bomb(x, y + d) return A = list(range(14)) B = list(range(8)) M = ["00000000000000" for i in A] z = "000" n = eval(input()) for i in range(n): s = input() for j in B: M[j + 3] = z + input() + z x = eval(input()) y = eval(input()) bomb(x, y) print("Data %d:" % (i + 1)) for j in B: print(M[j + 3][3:-3])
def bomb(x, y): global M s = M[y + 2] R = [-3, -2, -1, 1, 2, 3] if s[x + 2] == "0": return M[y + 2] = s[: x + 2] + "0" + s[x + 3 :] for d in R: bomb(x + d, y) bomb(x, y + d) return A = list(range(14)) B = list(range(3, 11)) M = ["00000000000000" for i in A] z = "000" n = eval(input()) for i in range(n): s = input() for j in B: M[j] = z + input() + z x = eval(input()) y = eval(input()) bomb(x, y) print("Data %d:" % (i + 1)) for j in B: print(M[j][3:-3])
false
0
[ "-B = list(range(8))", "+B = list(range(3, 11))", "- M[j + 3] = z + input() + z", "+ M[j] = z + input() + z", "- print(M[j + 3][3:-3])", "+ print(M[j][3:-3])" ]
false
0.038078
0.070829
0.537597
[ "s122989119", "s085413340" ]
u562935282
p03045
python
s186053600
s165585332
596
524
5,488
63,152
Accepted
Accepted
12.08
class UnionFind(): def __init__(self, n): self.parent = [-1 for _ in range(n)] # 正==子: 根の頂点番号 / 負==根: 連結頂点数 def find(self, x): if self.parent[x] < 0: return x else: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): x, y = self.find(x), self.find(y) if x == y: return False else: if self.size(x) < self.size(y): x, y = y, x self.parent[x] += self.parent[y] self.parent[y] = x def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): x = self.find(x) return -self.parent[x] def is_root(self, x): return self.parent[x] < 0 n, m = list(map(int, input().split())) uf = UnionFind(n) for _ in range(m): x, y, z = list(map(int, input().split())) x -= 1 y -= 1 uf.unite(x, y) print((sum(uf.is_root(i) for i in range(n))))
import sys input = sys.stdin.readline class UnionFind: def __init__(self, n): self.v = [-1 for _ in range(n)] # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed) def find(self, x): # xを含む木における根の頂点番号を返す if self.v[x] < 0: # (負)は根 return x else: # 根の頂点番号 self.v[x] = self.find(self.v[x]) # uniteでは, 旧根に属する頂点の根が旧根のままなので更新 return self.v[x] def unite(self, x, y): # 違う根に属していたらrankが低くなるように連結 x = self.find(x) y = self.find(y) if x == y: return if -self.v[x] < -self.v[y]: # size比較,  (-1) * (連結頂点数 * (-1)), (正)同士の大小比較 x, y = y, x # 連結頂点数が少ない方をyにすると, findでの更新回数が減る? self.v[x] += self.v[y] # 連結頂点数の和を取る, 連結頂点数 * (-1) self.v[y] = x # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする def root(self, x): return self.v[x] < 0 # (負)は根 def same(self, x, y): return self.find(x) == self.find(y) # 同じ根に属するか def size(self, x): return -self.v[self.find(x)] # 連結頂点数を返す n, m = list(map(int, input().split())) uf = UnionFind(n) for _ in range(m): x, y, z = list(map(int, input().split())) x -= 1 y -= 1 uf.unite(x, y) print((sum(uf.root(j) for j in range(n))))
44
46
1,038
1,278
class UnionFind: def __init__(self, n): self.parent = [-1 for _ in range(n)] # 正==子: 根の頂点番号 / 負==根: 連結頂点数 def find(self, x): if self.parent[x] < 0: return x else: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): x, y = self.find(x), self.find(y) if x == y: return False else: if self.size(x) < self.size(y): x, y = y, x self.parent[x] += self.parent[y] self.parent[y] = x def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): x = self.find(x) return -self.parent[x] def is_root(self, x): return self.parent[x] < 0 n, m = list(map(int, input().split())) uf = UnionFind(n) for _ in range(m): x, y, z = list(map(int, input().split())) x -= 1 y -= 1 uf.unite(x, y) print((sum(uf.is_root(i) for i in range(n))))
import sys input = sys.stdin.readline class UnionFind: def __init__(self, n): self.v = [-1 for _ in range(n)] # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed) def find(self, x): # xを含む木における根の頂点番号を返す if self.v[x] < 0: # (負)は根 return x else: # 根の頂点番号 self.v[x] = self.find(self.v[x]) # uniteでは, 旧根に属する頂点の根が旧根のままなので更新 return self.v[x] def unite(self, x, y): # 違う根に属していたらrankが低くなるように連結 x = self.find(x) y = self.find(y) if x == y: return if -self.v[x] < -self.v[y]: # size比較,  (-1) * (連結頂点数 * (-1)), (正)同士の大小比較 x, y = y, x # 連結頂点数が少ない方をyにすると, findでの更新回数が減る? self.v[x] += self.v[y] # 連結頂点数の和を取る, 連結頂点数 * (-1) self.v[y] = x # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする def root(self, x): return self.v[x] < 0 # (負)は根 def same(self, x, y): return self.find(x) == self.find(y) # 同じ根に属するか def size(self, x): return -self.v[self.find(x)] # 連結頂点数を返す n, m = list(map(int, input().split())) uf = UnionFind(n) for _ in range(m): x, y, z = list(map(int, input().split())) x -= 1 y -= 1 uf.unite(x, y) print((sum(uf.root(j) for j in range(n))))
false
4.347826
[ "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "- self.parent = [-1 for _ in range(n)]", "- # 正==子: 根の頂点番号 / 負==根: 連結頂点数", "+ self.v = [-1 for _ in range(n)] # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed)", "- def find(self, x):", "- if self.parent[x] ...
false
0.08775
0.041607
2.109006
[ "s186053600", "s165585332" ]
u994988729
p02684
python
s524127534
s481726516
1,497
1,176
207,408
207,096
Accepted
Accepted
21.44
N, K = list(map(int, input().split())) D = K.bit_length() to = [[0] * D for _ in range(N)] for i, a in enumerate(map(int, input().split())): to[i][0] = a - 1 for j in range(D - 1): for i in range(N): to[i][j+1] = to[to[i][j]][j] v = 0 for i in reversed(list(range(D))): if (K >> i) & 1: v = to[v][i] print((v + 1))
def main(): N, K = list(map(int, input().split())) D = K.bit_length() to = [[0] * D for _ in range(N)] for i, a in enumerate(map(int, input().split())): to[i][0] = a - 1 for j in range(D - 1): for i in range(N): to[i][j+1] = to[to[i][j]][j] v = 0 for i in reversed(list(range(D))): if (K >> i) & 1: v = to[v][i] print((v + 1)) if __name__ == "__main__": main()
17
22
348
457
N, K = list(map(int, input().split())) D = K.bit_length() to = [[0] * D for _ in range(N)] for i, a in enumerate(map(int, input().split())): to[i][0] = a - 1 for j in range(D - 1): for i in range(N): to[i][j + 1] = to[to[i][j]][j] v = 0 for i in reversed(list(range(D))): if (K >> i) & 1: v = to[v][i] print((v + 1))
def main(): N, K = list(map(int, input().split())) D = K.bit_length() to = [[0] * D for _ in range(N)] for i, a in enumerate(map(int, input().split())): to[i][0] = a - 1 for j in range(D - 1): for i in range(N): to[i][j + 1] = to[to[i][j]][j] v = 0 for i in reversed(list(range(D))): if (K >> i) & 1: v = to[v][i] print((v + 1)) if __name__ == "__main__": main()
false
22.727273
[ "-N, K = list(map(int, input().split()))", "-D = K.bit_length()", "-to = [[0] * D for _ in range(N)]", "-for i, a in enumerate(map(int, input().split())):", "- to[i][0] = a - 1", "-for j in range(D - 1):", "- for i in range(N):", "- to[i][j + 1] = to[to[i][j]][j]", "-v = 0", "-for i i...
false
0.041561
0.084544
0.491594
[ "s524127534", "s481726516" ]
u006880673
p03546
python
s661243419
s086979748
427
76
82,728
68,176
Accepted
Accepted
82.2
H, W = list(map(int, input().split())) c = [list(map(int, input().split())) for _ in range(10)] counter = {i: 0 for i in range(-1, 10)} for i in range(H): tmp = list(map(int, input().split())) for j in range(W): counter[tmp[j]] += 1 MAX = 10**4 INF = float("inf") def f(start): if start == 1: return 0 dp = [[INF]*MAX for _ in range(10)] dp[start][0] = 0 for i in range(1, MAX): for new in range(10): dp[new][i] = min(dp[num][i-1] + c[num][new] for num in range(10)) return min(dp[1]) ans = 0 for i in range(10): if counter[i] == 0: continue else: ans += counter[i] * f(i) print(ans)
"""ABC079D Wall 別解 ワーシャルフロイドでやった場合 """ H, W = list(map(int, input().split())) c = [list(map(int, input().split())) for _ in range(10)] counter = {i: 0 for i in range(-1, 10)} for i in range(H): tmp = list(map(int, input().split())) for j in range(W): counter[tmp[j]] += 1 dp = c.copy() for k in range(10): for i in range(10): for j in range(10): dp[i][j] = min( dp[i][j], dp[i][k] + dp[k][j] ) ans = sum([counter[i]*dp[i][1] for i in range(10)]) print(ans)
27
24
693
561
H, W = list(map(int, input().split())) c = [list(map(int, input().split())) for _ in range(10)] counter = {i: 0 for i in range(-1, 10)} for i in range(H): tmp = list(map(int, input().split())) for j in range(W): counter[tmp[j]] += 1 MAX = 10**4 INF = float("inf") def f(start): if start == 1: return 0 dp = [[INF] * MAX for _ in range(10)] dp[start][0] = 0 for i in range(1, MAX): for new in range(10): dp[new][i] = min(dp[num][i - 1] + c[num][new] for num in range(10)) return min(dp[1]) ans = 0 for i in range(10): if counter[i] == 0: continue else: ans += counter[i] * f(i) print(ans)
"""ABC079D Wall 別解 ワーシャルフロイドでやった場合 """ H, W = list(map(int, input().split())) c = [list(map(int, input().split())) for _ in range(10)] counter = {i: 0 for i in range(-1, 10)} for i in range(H): tmp = list(map(int, input().split())) for j in range(W): counter[tmp[j]] += 1 dp = c.copy() for k in range(10): for i in range(10): for j in range(10): dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) ans = sum([counter[i] * dp[i][1] for i in range(10)]) print(ans)
false
11.111111
[ "+\"\"\"ABC079D Wall 別解", "+ワーシャルフロイドでやった場合", "+\"\"\"", "-MAX = 10**4", "-INF = float(\"inf\")", "-", "-", "-def f(start):", "- if start == 1:", "- return 0", "- dp = [[INF] * MAX for _ in range(10)]", "- dp[start][0] = 0", "- for i in range(1, MAX):", "- for new...
false
0.796691
0.037407
21.297684
[ "s661243419", "s086979748" ]
u667084803
p02722
python
s593316661
s623377446
627
94
9,692
67,760
Accepted
Accepted
85.01
N = int(eval(input())) def divisors(n): ret1 = [] ret2 = [] i = 1 while i**2 <= N: if n%i == 0: ret1 += [i] ret2 += [n//i] i += 1 return ret1 + ret2 ans1 = set(divisors(N-1)) ans2_cand = set(divisors(N)) ans2 = 0 for k in ans2_cand: if k == 1: continue n = N while n%k == 0: n = n//k if n%k == 1: ans2 += 1 print((len(ans1) + ans2 -1))
N = int(eval(input())) def divisors(n): ret1 = [] ret2 = [] i = 1 while i**2 <= N: if n%i == 0: ret1 += [i] ret2 += [n//i] i += 1 return ret1 + ret2 ans1 = len(set(divisors(N-1))) - 1 ans2_cand = set(divisors(N)) ans2 = 0 for k in ans2_cand: if k == 1: continue n = N while n%k == 0: n = n//k if n%k == 1: ans2 += 1 print((ans1 + ans2))
26
26
448
449
N = int(eval(input())) def divisors(n): ret1 = [] ret2 = [] i = 1 while i**2 <= N: if n % i == 0: ret1 += [i] ret2 += [n // i] i += 1 return ret1 + ret2 ans1 = set(divisors(N - 1)) ans2_cand = set(divisors(N)) ans2 = 0 for k in ans2_cand: if k == 1: continue n = N while n % k == 0: n = n // k if n % k == 1: ans2 += 1 print((len(ans1) + ans2 - 1))
N = int(eval(input())) def divisors(n): ret1 = [] ret2 = [] i = 1 while i**2 <= N: if n % i == 0: ret1 += [i] ret2 += [n // i] i += 1 return ret1 + ret2 ans1 = len(set(divisors(N - 1))) - 1 ans2_cand = set(divisors(N)) ans2 = 0 for k in ans2_cand: if k == 1: continue n = N while n % k == 0: n = n // k if n % k == 1: ans2 += 1 print((ans1 + ans2))
false
0
[ "-ans1 = set(divisors(N - 1))", "+ans1 = len(set(divisors(N - 1))) - 1", "-print((len(ans1) + ans2 - 1))", "+print((ans1 + ans2))" ]
false
0.297016
0.118909
2.497852
[ "s593316661", "s623377446" ]
u347640436
p02971
python
s714386283
s855124506
709
559
15,636
14,112
Accepted
Accepted
21.16
# 累積和(max) N = int(eval(input())) a = [int(eval(input())) for _ in range(N)] lcm = a[:] rcm = a[:] for i in range(1, N): lcm[i] = max(lcm[i], lcm[i - 1]) for i in range(N - 2, -1, -1): rcm[i] = max(rcm[i], rcm[i + 1]) print((rcm[1])) for i in range(1, N - 1): print((max(lcm[i - 1], rcm[i + 1]))) print((lcm[N - 2]))
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] b = A[:] b.sort(reverse=True) for i in range(N): if A[i] != b[0]: print((b[0])) else: print((b[1]))
13
10
317
184
# 累積和(max) N = int(eval(input())) a = [int(eval(input())) for _ in range(N)] lcm = a[:] rcm = a[:] for i in range(1, N): lcm[i] = max(lcm[i], lcm[i - 1]) for i in range(N - 2, -1, -1): rcm[i] = max(rcm[i], rcm[i + 1]) print((rcm[1])) for i in range(1, N - 1): print((max(lcm[i - 1], rcm[i + 1]))) print((lcm[N - 2]))
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] b = A[:] b.sort(reverse=True) for i in range(N): if A[i] != b[0]: print((b[0])) else: print((b[1]))
false
23.076923
[ "-# 累積和(max)", "-a = [int(eval(input())) for _ in range(N)]", "-lcm = a[:]", "-rcm = a[:]", "-for i in range(1, N):", "- lcm[i] = max(lcm[i], lcm[i - 1])", "-for i in range(N - 2, -1, -1):", "- rcm[i] = max(rcm[i], rcm[i + 1])", "-print((rcm[1]))", "-for i in range(1, N - 1):", "- print...
false
0.042669
0.043471
0.981563
[ "s714386283", "s855124506" ]
u138486156
p03147
python
s696691566
s843915206
134
18
3,064
2,940
Accepted
Accepted
86.57
n = int(eval(input())) h = list(map(int, input().split())) c = 0 while any(h): ans = 0 for l in range(n): tmp = 0 r = l while h[r]: tmp += 1 r += 1 if r == n: break if ans < tmp: x = l y = r ans = tmp for i in range(x, y): h[i] -= 1 c += 1 print(c)
n = int(eval(input())) h = list(map(int, input().split())) ans = h[0] for i in range(n-1): ans += max(h[i+1]-h[i], 0) print(ans)
22
7
409
134
n = int(eval(input())) h = list(map(int, input().split())) c = 0 while any(h): ans = 0 for l in range(n): tmp = 0 r = l while h[r]: tmp += 1 r += 1 if r == n: break if ans < tmp: x = l y = r ans = tmp for i in range(x, y): h[i] -= 1 c += 1 print(c)
n = int(eval(input())) h = list(map(int, input().split())) ans = h[0] for i in range(n - 1): ans += max(h[i + 1] - h[i], 0) print(ans)
false
68.181818
[ "-c = 0", "-while any(h):", "- ans = 0", "- for l in range(n):", "- tmp = 0", "- r = l", "- while h[r]:", "- tmp += 1", "- r += 1", "- if r == n:", "- break", "- if ans < tmp:", "- x = l", "- ...
false
0.05745
0.034448
1.667762
[ "s696691566", "s843915206" ]
u374051158
p03457
python
s191938573
s561548312
420
375
28,148
27,380
Accepted
Accepted
10.71
N = int(eval(input())) txy = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(N)] result = True for i in range(N): dt = txy[i + 1][0] - txy[i][0] dist = abs(txy[i + 1][1] - txy[i][1]) + abs(txy[i + 1][2] - txy[i][2]) if(dist > dt): result = False if(dist % 2 != dt % 2): result = False print((("No", "Yes")[result]))
N = int(eval(input())) txy = [list(map(int, input().split())) for _ in range(N)] result = True for pol in txy: dist = abs(pol[1]) + abs(pol[2]) if(dist > pol[0]): result = False if(dist % 2 != pol[0] % 2): result = False print((("No", "Yes")[result]))
12
11
355
272
N = int(eval(input())) txy = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(N)] result = True for i in range(N): dt = txy[i + 1][0] - txy[i][0] dist = abs(txy[i + 1][1] - txy[i][1]) + abs(txy[i + 1][2] - txy[i][2]) if dist > dt: result = False if dist % 2 != dt % 2: result = False print((("No", "Yes")[result]))
N = int(eval(input())) txy = [list(map(int, input().split())) for _ in range(N)] result = True for pol in txy: dist = abs(pol[1]) + abs(pol[2]) if dist > pol[0]: result = False if dist % 2 != pol[0] % 2: result = False print((("No", "Yes")[result]))
false
8.333333
[ "-txy = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(N)]", "+txy = [list(map(int, input().split())) for _ in range(N)]", "-for i in range(N):", "- dt = txy[i + 1][0] - txy[i][0]", "- dist = abs(txy[i + 1][1] - txy[i][1]) + abs(txy[i + 1][2] - txy[i][2])", "- if dist > dt:", "+f...
false
0.060472
0.038491
1.571089
[ "s191938573", "s561548312" ]
u642874916
p03476
python
s495974097
s325103198
518
462
80,728
78,552
Accepted
Accepted
10.81
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations, accumulate import sys import bisect import string import math import time from fractions import gcd #import random def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i)-1 for i in input().split()] def StoI(): return [ord(i)-97 for i in input()] def ItoS(nn): return chr(nn+97) def input(): return sys.stdin.readline().rstrip() def show(*inp, end='\n'): if show_flg: print(*inp, end=end) YN = ['Yes', 'No'] MOD = 10**9+7 inf = float('inf') l_alp = string.ascii_lowercase u_alp = string.ascii_uppercase ts = time.time() sys.setrecursionlimit(10**6) # show_flg = True show_flg = False def is_prime(n): """ nの素数判定 :param int n: :rtype: Bool """ if n == 1: return False for i in range(2, int(n**0.5)+1): if n % i == 0: return False return True def main(): Q = I() l = [0] * Q r = [0] * Q for i in range(Q): l[i], r[i] = MI() arr = [] for i in range(10**5+1): if i % 2 == 1: arr.append(int(is_prime(i) and is_prime((i+1)//2))) else: arr.append(0) ARR = list(accumulate([0] + arr)) # print(arr[:100]) # print(ARR[:100]) for i in range(Q): # print(r[i]+1, l[i], ARR[r[i]+1], ARR[l[i]]) # print(ARR[:r[i]+1]) print(ARR[r[i]+1] - ARR[l[i]]) if __name__ == '__main__': main()
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations, accumulate import sys import bisect import string import math import time from fractions import gcd #import random def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i)-1 for i in input().split()] def StoI(): return [ord(i)-97 for i in input()] def ItoS(nn): return chr(nn+97) def input(): return sys.stdin.readline().rstrip() def show(*inp, end='\n'): if show_flg: print(*inp, end=end) YN = ['Yes', 'No'] MOD = 10**9+7 inf = float('inf') l_alp = string.ascii_lowercase u_alp = string.ascii_uppercase ts = time.time() sys.setrecursionlimit(10**6) # show_flg = True show_flg = False # エラトステネスのふるい 素数の列挙 def primes(n): is_prime = [1] * (n + 1) is_prime[0] = 0 is_prime[1] = 0 for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = 0 return is_prime def main(): Q = I() l = [0] * Q r = [0] * Q for i in range(Q): l[i], r[i] = MI() prime_list = primes(10**5+1) arr = [] for i in range(10**5+1): if i % 2 == 1: arr.append(int(prime_list[i] and prime_list[(i+1)//2])) else: arr.append(0) ARR = list(accumulate([0] + arr)) for i in range(Q): # print(r[i]+1, l[i], ARR[r[i]+1], ARR[l[i]]) # print(ARR[:r[i]+1]) print(ARR[r[i]+1] - ARR[l[i]]) if __name__ == '__main__': main()
94
91
1,736
1,788
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations, accumulate import sys import bisect import string import math import time from fractions import gcd # import random def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i) - 1 for i in input().split()] def StoI(): return [ord(i) - 97 for i in input()] def ItoS(nn): return chr(nn + 97) def input(): return sys.stdin.readline().rstrip() def show(*inp, end="\n"): if show_flg: print(*inp, end=end) YN = ["Yes", "No"] MOD = 10**9 + 7 inf = float("inf") l_alp = string.ascii_lowercase u_alp = string.ascii_uppercase ts = time.time() sys.setrecursionlimit(10**6) # show_flg = True show_flg = False def is_prime(n): """ nの素数判定 :param int n: :rtype: Bool """ if n == 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def main(): Q = I() l = [0] * Q r = [0] * Q for i in range(Q): l[i], r[i] = MI() arr = [] for i in range(10**5 + 1): if i % 2 == 1: arr.append(int(is_prime(i) and is_prime((i + 1) // 2))) else: arr.append(0) ARR = list(accumulate([0] + arr)) # print(arr[:100]) # print(ARR[:100]) for i in range(Q): # print(r[i]+1, l[i], ARR[r[i]+1], ARR[l[i]]) # print(ARR[:r[i]+1]) print(ARR[r[i] + 1] - ARR[l[i]]) if __name__ == "__main__": main()
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations, accumulate import sys import bisect import string import math import time from fractions import gcd # import random def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i) - 1 for i in input().split()] def StoI(): return [ord(i) - 97 for i in input()] def ItoS(nn): return chr(nn + 97) def input(): return sys.stdin.readline().rstrip() def show(*inp, end="\n"): if show_flg: print(*inp, end=end) YN = ["Yes", "No"] MOD = 10**9 + 7 inf = float("inf") l_alp = string.ascii_lowercase u_alp = string.ascii_uppercase ts = time.time() sys.setrecursionlimit(10**6) # show_flg = True show_flg = False # エラトステネスのふるい 素数の列挙 def primes(n): is_prime = [1] * (n + 1) is_prime[0] = 0 is_prime[1] = 0 for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = 0 return is_prime def main(): Q = I() l = [0] * Q r = [0] * Q for i in range(Q): l[i], r[i] = MI() prime_list = primes(10**5 + 1) arr = [] for i in range(10**5 + 1): if i % 2 == 1: arr.append(int(prime_list[i] and prime_list[(i + 1) // 2])) else: arr.append(0) ARR = list(accumulate([0] + arr)) for i in range(Q): # print(r[i]+1, l[i], ARR[r[i]+1], ARR[l[i]]) # print(ARR[:r[i]+1]) print(ARR[r[i] + 1] - ARR[l[i]]) if __name__ == "__main__": main()
false
3.191489
[ "-", "-", "-def is_prime(n):", "- \"\"\"", "- nの素数判定", "- :param int n:", "- :rtype: Bool", "- \"\"\"", "- if n == 1:", "- return False", "+# エラトステネスのふるい 素数の列挙", "+def primes(n):", "+ is_prime = [1] * (n + 1)", "+ is_prime[0] = 0", "+ is_prime[1] = 0", ...
false
0.858953
0.344281
2.494917
[ "s495974097", "s325103198" ]
u227082700
p02954
python
s606884795
s942120276
141
130
7,168
6,400
Accepted
Accepted
7.8
s=eval(input()) n=len(s) ans=[1]*n anss=[0]*n for i in range(n): if s[i]=="R": if s[i+1]=="R": ans[i+1]+=ans[i] ans[i]=0 else: anss[i+1]+=ans[i]//2 anss[i]+=0--ans[i]//2 for i in range(n-1,-1,-1): if s[i]=="L": if s[i-1]=="L": ans[i-1]+=ans[i] ans[i]=0 else: anss[i-1]+=ans[i]//2 anss[i]+=0--ans[i]//2 print((*anss))
s=eval(input()) n=len(s) ans=[1]*n for i in range(1,n-1): if s[i-1]==s[i]=="R": ans[i+1]+=ans[i-1] ans[i-1]=0 for i in range(n-2,0,-1): if s[i]==s[i+1]=="L": ans[i-1]+=ans[i+1] ans[i+1]=0 print((*ans))
21
12
396
214
s = eval(input()) n = len(s) ans = [1] * n anss = [0] * n for i in range(n): if s[i] == "R": if s[i + 1] == "R": ans[i + 1] += ans[i] ans[i] = 0 else: anss[i + 1] += ans[i] // 2 anss[i] += 0 - -ans[i] // 2 for i in range(n - 1, -1, -1): if s[i] == "L": if s[i - 1] == "L": ans[i - 1] += ans[i] ans[i] = 0 else: anss[i - 1] += ans[i] // 2 anss[i] += 0 - -ans[i] // 2 print((*anss))
s = eval(input()) n = len(s) ans = [1] * n for i in range(1, n - 1): if s[i - 1] == s[i] == "R": ans[i + 1] += ans[i - 1] ans[i - 1] = 0 for i in range(n - 2, 0, -1): if s[i] == s[i + 1] == "L": ans[i - 1] += ans[i + 1] ans[i + 1] = 0 print((*ans))
false
42.857143
[ "-anss = [0] * n", "-for i in range(n):", "- if s[i] == \"R\":", "- if s[i + 1] == \"R\":", "- ans[i + 1] += ans[i]", "- ans[i] = 0", "- else:", "- anss[i + 1] += ans[i] // 2", "- anss[i] += 0 - -ans[i] // 2", "-for i in range(n - 1, -1,...
false
0.042698
0.043594
0.979429
[ "s606884795", "s942120276" ]
u312025627
p03828
python
s529456672
s959301301
204
168
39,280
38,640
Accepted
Accepted
17.65
def main(): N = int(eval(input())) MOD = 10**9 + 7 ans = 1 primes = sorted(Eratosthenes(N)) for p in primes: cur = 0 k = 1 while p**k <= N: cur += N//(p**k) k += 1 ans = ans * (cur+1) % MOD print((ans%MOD)) def Eratosthenes(x: int) -> set: """x以下の素数のsetを返す""" import math sup = int(x) primes = {i for i in range(2,sup+1)} for i in range(2,int(math.sqrt(sup+1))+1): if i in primes: mul = 2 while i*mul <= sup: primes.discard(i*mul) mul += 1 return primes if __name__ == '__main__': main()
def main(): N = int(eval(input())) MOD = 10**9 + 7 def Eratosthenes(sup: int) -> set: from math import sqrt primes = {i for i in range(2, sup+1)} for i in range(2, int(sqrt(sup+1))+1): if i in primes: mul = 2 while i*mul <= sup: primes.discard(i*mul) mul += 1 return primes ps = Eratosthenes(N) ans = 1 for p in ps: cur = 0 i = 1 while N//(p**i) > 0: cur += N//(p**i) i += 1 ans *= (cur+1) ans %= MOD print((ans % MOD)) if __name__ == '__main__': main()
29
30
681
691
def main(): N = int(eval(input())) MOD = 10**9 + 7 ans = 1 primes = sorted(Eratosthenes(N)) for p in primes: cur = 0 k = 1 while p**k <= N: cur += N // (p**k) k += 1 ans = ans * (cur + 1) % MOD print((ans % MOD)) def Eratosthenes(x: int) -> set: """x以下の素数のsetを返す""" import math sup = int(x) primes = {i for i in range(2, sup + 1)} for i in range(2, int(math.sqrt(sup + 1)) + 1): if i in primes: mul = 2 while i * mul <= sup: primes.discard(i * mul) mul += 1 return primes if __name__ == "__main__": main()
def main(): N = int(eval(input())) MOD = 10**9 + 7 def Eratosthenes(sup: int) -> set: from math import sqrt primes = {i for i in range(2, sup + 1)} for i in range(2, int(sqrt(sup + 1)) + 1): if i in primes: mul = 2 while i * mul <= sup: primes.discard(i * mul) mul += 1 return primes ps = Eratosthenes(N) ans = 1 for p in ps: cur = 0 i = 1 while N // (p**i) > 0: cur += N // (p**i) i += 1 ans *= cur + 1 ans %= MOD print((ans % MOD)) if __name__ == "__main__": main()
false
3.333333
[ "+", "+ def Eratosthenes(sup: int) -> set:", "+ from math import sqrt", "+", "+ primes = {i for i in range(2, sup + 1)}", "+ for i in range(2, int(sqrt(sup + 1)) + 1):", "+ if i in primes:", "+ mul = 2", "+ while i * mul <= sup:", "+...
false
0.080347
0.096757
0.830397
[ "s529456672", "s959301301" ]
u733011130
p02597
python
s976779952
s783672683
112
80
73,772
80,844
Accepted
Accepted
28.57
import sys readline = sys.stdin.readline from collections import deque def solve(): N = int(readline()) C = readline().rstrip() R, W = 'R', 'W' reds = deque(i for i in range(len(C)) if C[i] == 'R') whites = deque(i for i in range(len(C)) if C[i] == 'W') count = 0 while len(whites) > 0 and len(reds) > 0 and whites[0] < reds[-1]: reds.pop() whites.popleft() count += 1 print(count) solve()
import sys readline = sys.stdin.readline def solve(): N = int(readline()) C = readline().rstrip() reds = [i for i in range(len(C)) if C[i] == 'R'] whites = [i for i in range(len(C)) if C[i] == 'W'] i = 0 n = min(len(reds), len(whites)) while i < n and reds[-1-i] > whites[i]: i += 1 print(i) solve()
21
18
474
365
import sys readline = sys.stdin.readline from collections import deque def solve(): N = int(readline()) C = readline().rstrip() R, W = "R", "W" reds = deque(i for i in range(len(C)) if C[i] == "R") whites = deque(i for i in range(len(C)) if C[i] == "W") count = 0 while len(whites) > 0 and len(reds) > 0 and whites[0] < reds[-1]: reds.pop() whites.popleft() count += 1 print(count) solve()
import sys readline = sys.stdin.readline def solve(): N = int(readline()) C = readline().rstrip() reds = [i for i in range(len(C)) if C[i] == "R"] whites = [i for i in range(len(C)) if C[i] == "W"] i = 0 n = min(len(reds), len(whites)) while i < n and reds[-1 - i] > whites[i]: i += 1 print(i) solve()
false
14.285714
[ "-from collections import deque", "- R, W = \"R\", \"W\"", "- reds = deque(i for i in range(len(C)) if C[i] == \"R\")", "- whites = deque(i for i in range(len(C)) if C[i] == \"W\")", "- count = 0", "- while len(whites) > 0 and len(reds) > 0 and whites[0] < reds[-1]:", "- reds.pop()...
false
0.035553
0.069107
0.514466
[ "s976779952", "s783672683" ]
u146816547
p01126
python
s691017639
s094551666
180
160
4,936
4,908
Accepted
Accepted
11.11
while True: n, m, a = list(map(int, input().split())) if n == 0 and m == 0 and a == 0: break hl = [list(map(int, input().split())) for _ in range(m)] hl.sort(key=lambda x:x[0], reverse=True) ans = a for i in range(m): if ans == hl[i][1]: ans = hl[i][2] elif ans == hl[i][2]: ans = hl[i][1] print(ans)
while True: n, m, a = list(map(int, input().split())) if n == 0 and m == 0 and a == 0: break hl = [list(map(int, input().split())) for _ in range(m)] hl.sort(reverse=True) ans = a for i in range(m): if ans == hl[i][1]: ans = hl[i][2] elif ans == hl[i][2]: ans = hl[i][1] print(ans)
19
19
396
377
while True: n, m, a = list(map(int, input().split())) if n == 0 and m == 0 and a == 0: break hl = [list(map(int, input().split())) for _ in range(m)] hl.sort(key=lambda x: x[0], reverse=True) ans = a for i in range(m): if ans == hl[i][1]: ans = hl[i][2] elif ans == hl[i][2]: ans = hl[i][1] print(ans)
while True: n, m, a = list(map(int, input().split())) if n == 0 and m == 0 and a == 0: break hl = [list(map(int, input().split())) for _ in range(m)] hl.sort(reverse=True) ans = a for i in range(m): if ans == hl[i][1]: ans = hl[i][2] elif ans == hl[i][2]: ans = hl[i][1] print(ans)
false
0
[ "- hl.sort(key=lambda x: x[0], reverse=True)", "+ hl.sort(reverse=True)" ]
false
0.036494
0.045744
0.797796
[ "s691017639", "s094551666" ]
u028973125
p03545
python
s981788517
s465249957
184
29
38,512
9,220
Accepted
Accepted
84.24
import sys from pprint import pprint from operator import add, sub from collections import deque s =[int(s_i) for s_i in sys.stdin.readline().strip()] # pprint(s) for op1 in (add, sub): for op2 in (add, sub): for op3 in (add, sub): if op3 ( op2 ( op1 (s[0], s[1]), s[2]), s[3]) == 7: tmp1 = "+" if op1 == add else "-" tmp2 = "+" if op2 == add else "-" tmp3 = "+" if op3 == add else "-" print((str(s[0]) + tmp1 + str(s[1]) + tmp2 + str(s[2]) + tmp3 + str(s[3]) + "=7")) sys.exit()
import sys tmp = list(sys.stdin.readline().strip()) nums = list(map(int, tmp)) for a in range(2): for b in range(2): for c in range(2): tmp = nums[0] exp = str(nums[0]) if a == 0: tmp += nums[1] exp += "+" else: tmp -= nums[1] exp += "-" exp += str(nums[1]) if b == 0: tmp += nums[2] exp += "+" else: tmp -= nums[2] exp += "-" exp += str(nums[2]) if c == 0: tmp += nums[3] exp += "+" else: tmp -= nums[3] exp += "-" exp += str(nums[3]) if tmp == 7: print((exp + "=7")) sys.exit()
18
34
608
892
import sys from pprint import pprint from operator import add, sub from collections import deque s = [int(s_i) for s_i in sys.stdin.readline().strip()] # pprint(s) for op1 in (add, sub): for op2 in (add, sub): for op3 in (add, sub): if op3(op2(op1(s[0], s[1]), s[2]), s[3]) == 7: tmp1 = "+" if op1 == add else "-" tmp2 = "+" if op2 == add else "-" tmp3 = "+" if op3 == add else "-" print( ( str(s[0]) + tmp1 + str(s[1]) + tmp2 + str(s[2]) + tmp3 + str(s[3]) + "=7" ) ) sys.exit()
import sys tmp = list(sys.stdin.readline().strip()) nums = list(map(int, tmp)) for a in range(2): for b in range(2): for c in range(2): tmp = nums[0] exp = str(nums[0]) if a == 0: tmp += nums[1] exp += "+" else: tmp -= nums[1] exp += "-" exp += str(nums[1]) if b == 0: tmp += nums[2] exp += "+" else: tmp -= nums[2] exp += "-" exp += str(nums[2]) if c == 0: tmp += nums[3] exp += "+" else: tmp -= nums[3] exp += "-" exp += str(nums[3]) if tmp == 7: print((exp + "=7")) sys.exit()
false
47.058824
[ "-from pprint import pprint", "-from operator import add, sub", "-from collections import deque", "-s = [int(s_i) for s_i in sys.stdin.readline().strip()]", "-# pprint(s)", "-for op1 in (add, sub):", "- for op2 in (add, sub):", "- for op3 in (add, sub):", "- if op3(op2(op1(s[0],...
false
0.037843
0.169076
0.223819
[ "s981788517", "s465249957" ]
u968166680
p03003
python
s262465182
s067543245
163
139
98,444
98,352
Accepted
Accepted
14.72
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, M = list(map(int, readline().split())) S = list(map(int, readline().split())) T = list(map(int, readline().split())) dp = [[0] * (M + 1) for _ in range(N + 1)] dp[0][0] = 1 for i in range(N + 1): dp[i][0] = 1 for j in range(M + 1): dp[0][j] = 1 for i in range(N): for j in range(M): dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % MOD if S[i] == T[j]: dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD print((dp[N][M])) 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, M = list(map(int, readline().split())) S = list(map(int, readline().split())) T = list(map(int, readline().split())) dp = [[0] * (M + 1) for _ in range(N + 1)] for i in range(N + 1): dp[i][0] = 1 for j in range(M + 1): dp[0][j] = 1 for i in range(N): for j in range(M): if S[i] == T[j]: dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD else: dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % MOD print((dp[N][M])) return if __name__ == '__main__': main()
34
34
793
798
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, M = list(map(int, readline().split())) S = list(map(int, readline().split())) T = list(map(int, readline().split())) dp = [[0] * (M + 1) for _ in range(N + 1)] dp[0][0] = 1 for i in range(N + 1): dp[i][0] = 1 for j in range(M + 1): dp[0][j] = 1 for i in range(N): for j in range(M): dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % MOD if S[i] == T[j]: dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD print((dp[N][M])) 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, M = list(map(int, readline().split())) S = list(map(int, readline().split())) T = list(map(int, readline().split())) dp = [[0] * (M + 1) for _ in range(N + 1)] for i in range(N + 1): dp[i][0] = 1 for j in range(M + 1): dp[0][j] = 1 for i in range(N): for j in range(M): if S[i] == T[j]: dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD else: dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % MOD print((dp[N][M])) return if __name__ == "__main__": main()
false
0
[ "- dp[0][0] = 1", "- dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % MOD", "- dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD", "+ dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD", "+ else:", "+ dp[i + 1][j +...
false
0.115676
0.143553
0.805808
[ "s262465182", "s067543245" ]
u312025627
p03006
python
s447623232
s360134766
190
174
39,152
39,280
Accepted
Accepted
8.42
def main(): N = int(input()) A = [[int(i) for i in input().split()] for j in range(N)] if N == 1: return print(1) A.sort() from collections import defaultdict cnt = defaultdict(int) for i in range(N): for j in range(i+1, N): # print(A[i], A[j], (A[j][0] - A[i][0], A[j][1] - A[i][1])) cnt[(A[j][0] - A[i][0], A[j][1] - A[i][1])] += 1 # print(cnt.values()) ans = (N-1) - (sorted(cnt.values())[-1] - 1) print(ans) if __name__ == '__main__': main()
def main(): import sys input = sys.stdin.buffer.readline N = int(eval(input())) XY = [[int(i) for i in input().split()] for j in range(N)] XY.sort() from collections import Counter c = Counter() for i in range(N-1): for j in range(i+1, N): p = XY[j][0] - XY[i][0] q = XY[j][1] - XY[i][1] c[(p, q)] += 1 ans = N - (c.most_common()[0][1] if c else 0) print(ans) if __name__ == '__main__': main()
19
19
550
496
def main(): N = int(input()) A = [[int(i) for i in input().split()] for j in range(N)] if N == 1: return print(1) A.sort() from collections import defaultdict cnt = defaultdict(int) for i in range(N): for j in range(i + 1, N): # print(A[i], A[j], (A[j][0] - A[i][0], A[j][1] - A[i][1])) cnt[(A[j][0] - A[i][0], A[j][1] - A[i][1])] += 1 # print(cnt.values()) ans = (N - 1) - (sorted(cnt.values())[-1] - 1) print(ans) if __name__ == "__main__": main()
def main(): import sys input = sys.stdin.buffer.readline N = int(eval(input())) XY = [[int(i) for i in input().split()] for j in range(N)] XY.sort() from collections import Counter c = Counter() for i in range(N - 1): for j in range(i + 1, N): p = XY[j][0] - XY[i][0] q = XY[j][1] - XY[i][1] c[(p, q)] += 1 ans = N - (c.most_common()[0][1] if c else 0) print(ans) if __name__ == "__main__": main()
false
0
[ "- N = int(input())", "- A = [[int(i) for i in input().split()] for j in range(N)]", "- if N == 1:", "- return print(1)", "- A.sort()", "- from collections import defaultdict", "+ import sys", "- cnt = defaultdict(int)", "- for i in range(N):", "+ input = sys.stdi...
false
0.041288
0.045932
0.898895
[ "s447623232", "s360134766" ]
u831053714
p02639
python
s900105979
s128039467
28
20
9,108
9,156
Accepted
Accepted
28.57
L=[int(x) for x in input().split(" ")] print((L.index(0)+1))
L=[int(x) for x in input().split(" ")] print((L.index(0)+1)) L.clear()
2
3
59
70
L = [int(x) for x in input().split(" ")] print((L.index(0) + 1))
L = [int(x) for x in input().split(" ")] print((L.index(0) + 1)) L.clear()
false
33.333333
[ "+L.clear()" ]
false
0.039213
0.040031
0.979555
[ "s900105979", "s128039467" ]
u298297089
p03238
python
s138934698
s377867595
168
17
38,384
2,940
Accepted
Accepted
89.88
N = int(eval(input())) if N == 1: print('Hello World') else: print((int(eval(input())) + int(eval(input()))))
n = int(eval(input())) if n == 1: print('Hello World') else : print((int(eval(input())) + int(eval(input()))))
5
5
98
98
N = int(eval(input())) if N == 1: print("Hello World") else: print((int(eval(input())) + int(eval(input()))))
n = int(eval(input())) if n == 1: print("Hello World") else: print((int(eval(input())) + int(eval(input()))))
false
0
[ "-N = int(eval(input()))", "-if N == 1:", "+n = int(eval(input()))", "+if n == 1:" ]
false
0.043833
0.040867
1.072589
[ "s138934698", "s377867595" ]
u669819350
p02720
python
s204062925
s150979380
201
108
46,428
11,980
Accepted
Accepted
46.27
def solve(K): ref = [[['0'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]] if K < 10: return ref[0][K][0] rest = K - 9 i = 0 while True: i += 1 ref.append([[] for _ in range(10)]) for j in range(10): if j == 0: for r in ref[i-1][j] + ref[i-1][j+1]: ref[i][j].append(str(j) + r) elif j == 9: for r in ref[i-1][j-1] + ref[i-1][j]: ref[i][j].append(str(j) + r) rest -= 1 if rest == 0: return str(j) + r else: for r in ref[i-1][j-1] + ref[i-1][j] + ref[i-1][j+1]: ref[i][j].append(str(j) + r) rest -= 1 if rest == 0: return str(j) + r if __name__ == '__main__': K = int(eval(input())) print((solve(K)))
from collections import deque def solve(K): stack = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) for _ in range(K): num = stack.popleft() one_digit = num % 10 if one_digit % 10 == 0: nexts = [num * 10, num * 10 + 1] elif one_digit % 10 == 9: nexts = [num * 10 + 8, num * 10 + 9] else: nexts = [num * 10 + one_digit - 1, num * 10 + one_digit, num * 10 + one_digit + 1] for n in nexts: stack.append(n) return num if __name__ == '__main__': K = int(eval(input())) print((solve(K)))
30
21
971
600
def solve(K): ref = [[["0"], ["1"], ["2"], ["3"], ["4"], ["5"], ["6"], ["7"], ["8"], ["9"]]] if K < 10: return ref[0][K][0] rest = K - 9 i = 0 while True: i += 1 ref.append([[] for _ in range(10)]) for j in range(10): if j == 0: for r in ref[i - 1][j] + ref[i - 1][j + 1]: ref[i][j].append(str(j) + r) elif j == 9: for r in ref[i - 1][j - 1] + ref[i - 1][j]: ref[i][j].append(str(j) + r) rest -= 1 if rest == 0: return str(j) + r else: for r in ref[i - 1][j - 1] + ref[i - 1][j] + ref[i - 1][j + 1]: ref[i][j].append(str(j) + r) rest -= 1 if rest == 0: return str(j) + r if __name__ == "__main__": K = int(eval(input())) print((solve(K)))
from collections import deque def solve(K): stack = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) for _ in range(K): num = stack.popleft() one_digit = num % 10 if one_digit % 10 == 0: nexts = [num * 10, num * 10 + 1] elif one_digit % 10 == 9: nexts = [num * 10 + 8, num * 10 + 9] else: nexts = [ num * 10 + one_digit - 1, num * 10 + one_digit, num * 10 + one_digit + 1, ] for n in nexts: stack.append(n) return num if __name__ == "__main__": K = int(eval(input())) print((solve(K)))
false
30
[ "+from collections import deque", "+", "+", "- ref = [[[\"0\"], [\"1\"], [\"2\"], [\"3\"], [\"4\"], [\"5\"], [\"6\"], [\"7\"], [\"8\"], [\"9\"]]]", "- if K < 10:", "- return ref[0][K][0]", "- rest = K - 9", "- i = 0", "- while True:", "- i += 1", "- ref.append...
false
0.039712
0.044871
0.885045
[ "s204062925", "s150979380" ]
u843175622
p02580
python
s308251016
s706260971
561
265
114,620
34,652
Accepted
Accepted
52.76
import numpy as np import sys from numba import njit, i4 read = sys.stdin.read @njit((i4[:],), cache=True) def solve(stdin): h, w, m = stdin[:3] row = np.zeros(h, np.int32) col = np.zeros(w, np.int32) for i in range(3, m * 2 + 3, 2): y, x = stdin[i: i + 2] - 1 row[y] += 1 col[x] += 1 max_cnt_y = max(row) max_cnt_x = max(col) max_pair = np.sum(row == max_cnt_y) * np.sum(col == max_cnt_x) for i in range(3, m * 2 + 3, 2): y, x = stdin[i: i + 2] - 1 if row[y] == max_cnt_y and col[x] == max_cnt_x: max_pair -= 1 return max_cnt_y + max_cnt_x - (max_pair == 0) print((solve(np.fromstring(read(), dtype=np.int32, sep=' '))))
import numpy as np import sys read = sys.stdin.read if sys.argv[-1] == 'ONLINE_JUDGE': from numba.pycc import CC cc = CC('unko') @cc.export('solve', '(i4[:],)') def solve(stdin): h, w, m = stdin[:3] row = np.zeros(h, np.int32) col = np.zeros(w, np.int32) for i in range(3, m * 2 + 3, 2): y, x = stdin[i: i + 2] - 1 row[y] += 1 col[x] += 1 max_cnt_y = max(row) max_cnt_x = max(col) max_pair = np.sum(row == max_cnt_y) * np.sum(col == max_cnt_x) for i in range(3, m * 2 + 3, 2): y, x = stdin[i: i + 2] - 1 if row[y] == max_cnt_y and col[x] == max_cnt_x: max_pair -= 1 return max_cnt_y + max_cnt_x - (max_pair == 0) cc.compile() exit() from unko import solve print((solve(np.fromstring(read(), dtype=np.int32, sep=' '))))
27
34
672
800
import numpy as np import sys from numba import njit, i4 read = sys.stdin.read @njit((i4[:],), cache=True) def solve(stdin): h, w, m = stdin[:3] row = np.zeros(h, np.int32) col = np.zeros(w, np.int32) for i in range(3, m * 2 + 3, 2): y, x = stdin[i : i + 2] - 1 row[y] += 1 col[x] += 1 max_cnt_y = max(row) max_cnt_x = max(col) max_pair = np.sum(row == max_cnt_y) * np.sum(col == max_cnt_x) for i in range(3, m * 2 + 3, 2): y, x = stdin[i : i + 2] - 1 if row[y] == max_cnt_y and col[x] == max_cnt_x: max_pair -= 1 return max_cnt_y + max_cnt_x - (max_pair == 0) print((solve(np.fromstring(read(), dtype=np.int32, sep=" "))))
import numpy as np import sys read = sys.stdin.read if sys.argv[-1] == "ONLINE_JUDGE": from numba.pycc import CC cc = CC("unko") @cc.export("solve", "(i4[:],)") def solve(stdin): h, w, m = stdin[:3] row = np.zeros(h, np.int32) col = np.zeros(w, np.int32) for i in range(3, m * 2 + 3, 2): y, x = stdin[i : i + 2] - 1 row[y] += 1 col[x] += 1 max_cnt_y = max(row) max_cnt_x = max(col) max_pair = np.sum(row == max_cnt_y) * np.sum(col == max_cnt_x) for i in range(3, m * 2 + 3, 2): y, x = stdin[i : i + 2] - 1 if row[y] == max_cnt_y and col[x] == max_cnt_x: max_pair -= 1 return max_cnt_y + max_cnt_x - (max_pair == 0) cc.compile() exit() from unko import solve print((solve(np.fromstring(read(), dtype=np.int32, sep=" "))))
false
20.588235
[ "-from numba import njit, i4", "+if sys.argv[-1] == \"ONLINE_JUDGE\":", "+ from numba.pycc import CC", "+ cc = CC(\"unko\")", "-@njit((i4[:],), cache=True)", "-def solve(stdin):", "- h, w, m = stdin[:3]", "- row = np.zeros(h, np.int32)", "- col = np.zeros(w, np.int32)", "- for i ...
false
0.496764
0.18224
2.725881
[ "s308251016", "s706260971" ]
u447342168
p03449
python
s035159594
s734506011
151
21
12,444
3,316
Accepted
Accepted
86.09
import numpy as np N = int(eval(input())) first = np.array([int(i) for i in input().split()]) second = np.array([int(i) for i in input().split()]) fstsum = np.cumsum(first) scdsum = np.cumsum(second[::-1])[::-1] result = 0 for i in range(N): res = fstsum[i] + scdsum[i] if result < res: result = res print(result)
N = int(eval(input())) first = [int(i) for i in input().split()] second = [int(i) for i in input().split()] result = 0 for i in range(N+1): res = sum(first[:i]) + sum(second[i-1:]) if result < res: result = res print(result)
12
9
334
242
import numpy as np N = int(eval(input())) first = np.array([int(i) for i in input().split()]) second = np.array([int(i) for i in input().split()]) fstsum = np.cumsum(first) scdsum = np.cumsum(second[::-1])[::-1] result = 0 for i in range(N): res = fstsum[i] + scdsum[i] if result < res: result = res print(result)
N = int(eval(input())) first = [int(i) for i in input().split()] second = [int(i) for i in input().split()] result = 0 for i in range(N + 1): res = sum(first[:i]) + sum(second[i - 1 :]) if result < res: result = res print(result)
false
25
[ "-import numpy as np", "-", "-first = np.array([int(i) for i in input().split()])", "-second = np.array([int(i) for i in input().split()])", "-fstsum = np.cumsum(first)", "-scdsum = np.cumsum(second[::-1])[::-1]", "+first = [int(i) for i in input().split()]", "+second = [int(i) for i in input().split(...
false
0.206114
0.035027
5.884406
[ "s035159594", "s734506011" ]
u794173881
p03321
python
s944343577
s452499186
1,127
594
96,088
114,780
Accepted
Accepted
47.29
from collections import deque n, m = list(map(int, input().split())) info = [list(map(int, input().split())) for i in range(m)] matrix = [[0]*n for i in range(n)] for i in range(m): a, b = info[i] a -= 1 b -= 1 matrix[a][b] = 1 matrix[b][a] = 1 graph = [[] for i in range(n)] for i in range(n): for j in range(i+1, n): if matrix[i][j] == 0: graph[i].append(j) graph[j].append(i) def coloring(graph): n = len(graph) visited = [-1] * n ans = [] for i in range(n): if visited[i] >= 0: continue visited[i] = 0 q = deque([i]) num = [1, 0] while q: _from = q.pop() for to in graph[_from]: if visited[to] == visited[_from]: return [[-1, -1]] if visited[to] >= 0: continue visited[to] = visited[_from] ^ 1 num[visited[to]] += 1 q.append(to) ans.append(num) return ans num = coloring(graph) if num[0][0] == -1: print((-1)) exit() dp = [[False]*(n+1) for _ in range(len(num) + 1)] dp[0][0] = True for i in range(len(num)): a, b = num[i] for j in range(n+1): if j-a >= 0: dp[i+1][j] = dp[i][j-a] or dp[i+1][j] if j-b >= 0: dp[i+1][j] = dp[i][j-b] or dp[i+1][j] ans = 10**20 for i, boolian in enumerate(dp[len(num)]): if boolian: tmp_ans = i * (i-1) // 2 + (n-i) * (n-i-1) // 2 ans = min(tmp_ans, ans) print(ans)
import sys input = sys.stdin.readline def is_bipartite(graph, s): """二部グラフ判定する""" n = len(graph) col = [-1] * n col[s] = 0 stack = [s] used[s] = True while stack: v = stack.pop() for nxt_v in graph[v]: used[nxt_v] = True if col[nxt_v] == -1: col[nxt_v] = col[v] ^ 1 stack.append(nxt_v) elif col[nxt_v] ^ col[v] == 0: return False return True def color_bipartite(graph, s): """二部グラフを彩色する""" n = len(graph) col = [-1] * n col[s] = 0 stack = [s] while stack: v = stack.pop() for nxt_v in graph[v]: if col[nxt_v] == -1: col[nxt_v] = col[v] ^ 1 stack.append(nxt_v) return col n, m = list(map(int, input().split())) info = [list(map(int, input().split())) for i in range(m)] graph = [set() for i in range(n)] for a, b in info: a -= 1 b -= 1 graph[a].add(b) graph[b].add(a) comp_graph = [[] for i in range(n)] for a in range(n): for b in range(n): if b in graph[a] or a == b: continue comp_graph[a].append(b) cnt0 = [] cnt1 = [] used = [False] * n for i in range(n): if used[i]: continue used[i] = True if not is_bipartite(comp_graph, i): print((-1)) exit() col = color_bipartite(comp_graph, i) cnt0.append(col.count(0)) cnt1.append(col.count(1)) dp = [[False] * (n + 1) for i in range(len(cnt0) + 1)] dp[0][0] = True for i in range(len(cnt0)): wei0 = cnt0[i] wei1 = cnt1[i] for w in range(n + 1): if w + wei0 < n + 1: dp[i + 1][w + wei0] = (dp[i][w] or dp[i + 1][w + wei0]) if w + wei1 < n + 1: dp[i + 1][w + wei1] = (dp[i][w] or dp[i + 1][w + wei1]) ans = 10 ** 18 for num in range(n + 1): if dp[-1][num]: c0 = num c1 = n - num res = c0 * (c0 - 1) // 2 + c1 * (c1 - 1) // 2 ans = min(ans, res) print(ans)
67
88
1,626
2,101
from collections import deque n, m = list(map(int, input().split())) info = [list(map(int, input().split())) for i in range(m)] matrix = [[0] * n for i in range(n)] for i in range(m): a, b = info[i] a -= 1 b -= 1 matrix[a][b] = 1 matrix[b][a] = 1 graph = [[] for i in range(n)] for i in range(n): for j in range(i + 1, n): if matrix[i][j] == 0: graph[i].append(j) graph[j].append(i) def coloring(graph): n = len(graph) visited = [-1] * n ans = [] for i in range(n): if visited[i] >= 0: continue visited[i] = 0 q = deque([i]) num = [1, 0] while q: _from = q.pop() for to in graph[_from]: if visited[to] == visited[_from]: return [[-1, -1]] if visited[to] >= 0: continue visited[to] = visited[_from] ^ 1 num[visited[to]] += 1 q.append(to) ans.append(num) return ans num = coloring(graph) if num[0][0] == -1: print((-1)) exit() dp = [[False] * (n + 1) for _ in range(len(num) + 1)] dp[0][0] = True for i in range(len(num)): a, b = num[i] for j in range(n + 1): if j - a >= 0: dp[i + 1][j] = dp[i][j - a] or dp[i + 1][j] if j - b >= 0: dp[i + 1][j] = dp[i][j - b] or dp[i + 1][j] ans = 10**20 for i, boolian in enumerate(dp[len(num)]): if boolian: tmp_ans = i * (i - 1) // 2 + (n - i) * (n - i - 1) // 2 ans = min(tmp_ans, ans) print(ans)
import sys input = sys.stdin.readline def is_bipartite(graph, s): """二部グラフ判定する""" n = len(graph) col = [-1] * n col[s] = 0 stack = [s] used[s] = True while stack: v = stack.pop() for nxt_v in graph[v]: used[nxt_v] = True if col[nxt_v] == -1: col[nxt_v] = col[v] ^ 1 stack.append(nxt_v) elif col[nxt_v] ^ col[v] == 0: return False return True def color_bipartite(graph, s): """二部グラフを彩色する""" n = len(graph) col = [-1] * n col[s] = 0 stack = [s] while stack: v = stack.pop() for nxt_v in graph[v]: if col[nxt_v] == -1: col[nxt_v] = col[v] ^ 1 stack.append(nxt_v) return col n, m = list(map(int, input().split())) info = [list(map(int, input().split())) for i in range(m)] graph = [set() for i in range(n)] for a, b in info: a -= 1 b -= 1 graph[a].add(b) graph[b].add(a) comp_graph = [[] for i in range(n)] for a in range(n): for b in range(n): if b in graph[a] or a == b: continue comp_graph[a].append(b) cnt0 = [] cnt1 = [] used = [False] * n for i in range(n): if used[i]: continue used[i] = True if not is_bipartite(comp_graph, i): print((-1)) exit() col = color_bipartite(comp_graph, i) cnt0.append(col.count(0)) cnt1.append(col.count(1)) dp = [[False] * (n + 1) for i in range(len(cnt0) + 1)] dp[0][0] = True for i in range(len(cnt0)): wei0 = cnt0[i] wei1 = cnt1[i] for w in range(n + 1): if w + wei0 < n + 1: dp[i + 1][w + wei0] = dp[i][w] or dp[i + 1][w + wei0] if w + wei1 < n + 1: dp[i + 1][w + wei1] = dp[i][w] or dp[i + 1][w + wei1] ans = 10**18 for num in range(n + 1): if dp[-1][num]: c0 = num c1 = n - num res = c0 * (c0 - 1) // 2 + c1 * (c1 - 1) // 2 ans = min(ans, res) print(ans)
false
23.863636
[ "-from collections import deque", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def is_bipartite(graph, s):", "+ \"\"\"二部グラフ判定する\"\"\"", "+ n = len(graph)", "+ col = [-1] * n", "+ col[s] = 0", "+ stack = [s]", "+ used[s] = True", "+ while stack:", "+...
false
0.036672
0.062964
0.582426
[ "s944343577", "s452499186" ]
u580697892
p02689
python
s959995530
s384970397
306
265
24,520
20,108
Accepted
Accepted
13.4
#coding: utf-8 #coding: utf-8 N, M = list(map(int, input().split())) H = list(map(int, input().split())) d = {i:H[i-1] for i in range(1, N+1)} F = [True for _ in range(N)] for i in range(M): a, b = list(map(int, input().split())) if d[a] <= H[b-1]: F[a-1] = False if d[b] <= H[a-1]: F[b-1] = False print((sum(F)))
#coding: utf-8 N, M = list(map(int, input().split())) H = list(map(int, input().split())) ans = [True for _ in range(N)] for i in range(M): a, b = list(map(int, input().split())) if H[a-1] <= H[b-1]: ans[a-1] = False if H[b-1] <= H[a-1]: ans[b-1] = False print((sum(ans)))
13
12
339
299
# coding: utf-8 # coding: utf-8 N, M = list(map(int, input().split())) H = list(map(int, input().split())) d = {i: H[i - 1] for i in range(1, N + 1)} F = [True for _ in range(N)] for i in range(M): a, b = list(map(int, input().split())) if d[a] <= H[b - 1]: F[a - 1] = False if d[b] <= H[a - 1]: F[b - 1] = False print((sum(F)))
# coding: utf-8 N, M = list(map(int, input().split())) H = list(map(int, input().split())) ans = [True for _ in range(N)] for i in range(M): a, b = list(map(int, input().split())) if H[a - 1] <= H[b - 1]: ans[a - 1] = False if H[b - 1] <= H[a - 1]: ans[b - 1] = False print((sum(ans)))
false
7.692308
[ "-# coding: utf-8", "-d = {i: H[i - 1] for i in range(1, N + 1)}", "-F = [True for _ in range(N)]", "+ans = [True for _ in range(N)]", "- if d[a] <= H[b - 1]:", "- F[a - 1] = False", "- if d[b] <= H[a - 1]:", "- F[b - 1] = False", "-print((sum(F)))", "+ if H[a - 1] <= H[b - ...
false
0.114618
0.114174
1.003891
[ "s959995530", "s384970397" ]
u044952145
p02838
python
s702206290
s487518546
1,539
919
122,936
137,400
Accepted
Accepted
40.29
N = int(eval(input())) A = list(map(int, input().split())) each_bit_sum = [{"0": 0, "1": 0} for _ in range(62)] result = 0 for a in A: for i, b in enumerate(format(a, "b").zfill(62)[::-1]): each_bit_sum[i][b] += 1 for i, b in enumerate(each_bit_sum): result += ((b["0"] * b["1"]) * (2**i)) % ((10**9) + 7) print((result % ((10**9) + 7)))
N = int(eval(input())) A = list(map(int, input().split())) result = 0 for i in range(60): on = sum([(1 << i) & a for a in A]) >> i result += (on * (N - on)) << i result %= ((10**9) + 7) print(result)
13
10
363
218
N = int(eval(input())) A = list(map(int, input().split())) each_bit_sum = [{"0": 0, "1": 0} for _ in range(62)] result = 0 for a in A: for i, b in enumerate(format(a, "b").zfill(62)[::-1]): each_bit_sum[i][b] += 1 for i, b in enumerate(each_bit_sum): result += ((b["0"] * b["1"]) * (2**i)) % ((10**9) + 7) print((result % ((10**9) + 7)))
N = int(eval(input())) A = list(map(int, input().split())) result = 0 for i in range(60): on = sum([(1 << i) & a for a in A]) >> i result += (on * (N - on)) << i result %= (10**9) + 7 print(result)
false
23.076923
[ "-each_bit_sum = [{\"0\": 0, \"1\": 0} for _ in range(62)]", "-for a in A:", "- for i, b in enumerate(format(a, \"b\").zfill(62)[::-1]):", "- each_bit_sum[i][b] += 1", "-for i, b in enumerate(each_bit_sum):", "- result += ((b[\"0\"] * b[\"1\"]) * (2**i)) % ((10**9) + 7)", "-print((result % ...
false
0.03774
0.046578
0.810258
[ "s702206290", "s487518546" ]
u113835532
p03738
python
s063934268
s647516105
30
27
9,084
9,080
Accepted
Accepted
10
def answer(a: str, b: str) -> str: if a == b: return 'EQUAL' if a < b or len(a) < len(b): return 'LESS' if a > b or len(a) > len(b): return 'GREATER' def main(): a = eval(input()) b = eval(input()) print((answer(a, b))) if __name__ == '__main__': main()
def answer(a: int, b: int) -> str: if a == b: return 'EQUAL' if a < b: return 'LESS' if a > b: return 'GREATER' def main(): a = int(eval(input())) b = int(eval(input())) print((answer(a, b))) if __name__ == '__main__': main()
19
19
315
287
def answer(a: str, b: str) -> str: if a == b: return "EQUAL" if a < b or len(a) < len(b): return "LESS" if a > b or len(a) > len(b): return "GREATER" def main(): a = eval(input()) b = eval(input()) print((answer(a, b))) if __name__ == "__main__": main()
def answer(a: int, b: int) -> str: if a == b: return "EQUAL" if a < b: return "LESS" if a > b: return "GREATER" def main(): a = int(eval(input())) b = int(eval(input())) print((answer(a, b))) if __name__ == "__main__": main()
false
0
[ "-def answer(a: str, b: str) -> str:", "+def answer(a: int, b: int) -> str:", "- if a < b or len(a) < len(b):", "+ if a < b:", "- if a > b or len(a) > len(b):", "+ if a > b:", "- a = eval(input())", "- b = eval(input())", "+ a = int(eval(input()))", "+ b = int(eval(input())...
false
0.035358
0.03445
1.026364
[ "s063934268", "s647516105" ]
u205561862
p03294
python
s701970175
s341207962
21
18
3,316
3,188
Accepted
Accepted
14.29
N=eval(input());print((sum(list(map(int,input().split())))-int(N)))
N=eval(input());print((sum(map(int,input().split()))-int(N)))
1
1
60
54
N = eval(input()) print((sum(list(map(int, input().split()))) - int(N)))
N = eval(input()) print((sum(map(int, input().split())) - int(N)))
false
0
[ "-print((sum(list(map(int, input().split()))) - int(N)))", "+print((sum(map(int, input().split())) - int(N)))" ]
false
0.112145
0.045822
2.447391
[ "s701970175", "s341207962" ]
u123756661
p02812
python
s900952739
s634625616
162
73
38,256
61,828
Accepted
Accepted
54.94
n=int(eval(input())) s=eval(input())+"xxxxxxxx" ans=chk=0 for i in range(n): w=s[i]+s[i+1]+s[i+2] if w=="ABC": ans+=1 print(ans)
n=int(eval(input())) s=eval(input())+"XXX" ans=0 for i in range(n): if s[i]+s[i+1]+s[i+2]=="ABC": ans+=1 print(ans)
8
6
140
112
n = int(eval(input())) s = eval(input()) + "xxxxxxxx" ans = chk = 0 for i in range(n): w = s[i] + s[i + 1] + s[i + 2] if w == "ABC": ans += 1 print(ans)
n = int(eval(input())) s = eval(input()) + "XXX" ans = 0 for i in range(n): if s[i] + s[i + 1] + s[i + 2] == "ABC": ans += 1 print(ans)
false
25
[ "-s = eval(input()) + \"xxxxxxxx\"", "-ans = chk = 0", "+s = eval(input()) + \"XXX\"", "+ans = 0", "- w = s[i] + s[i + 1] + s[i + 2]", "- if w == \"ABC\":", "+ if s[i] + s[i + 1] + s[i + 2] == \"ABC\":" ]
false
0.096042
0.056585
1.6973
[ "s900952739", "s634625616" ]
u620238824
p02690
python
s308076339
s376851515
629
76
73,340
9,076
Accepted
Accepted
87.92
x = int(eval(input())) y = 10**4 for i in range(y): for j in range(-y,y): if i ** 5 - j ** 5 == x: print((i, j)) exit()
x = int(eval(input())) for i in range(-200,200): for j in range(-200, 200): if i ** 5 - j ** 5 == x: print((i, j)) exit()
8
7
155
156
x = int(eval(input())) y = 10**4 for i in range(y): for j in range(-y, y): if i**5 - j**5 == x: print((i, j)) exit()
x = int(eval(input())) for i in range(-200, 200): for j in range(-200, 200): if i**5 - j**5 == x: print((i, j)) exit()
false
12.5
[ "-y = 10**4", "-for i in range(y):", "- for j in range(-y, y):", "+for i in range(-200, 200):", "+ for j in range(-200, 200):" ]
false
0.241379
0.147381
1.63779
[ "s308076339", "s376851515" ]
u839188633
p03132
python
s595554663
s677210746
1,089
979
67,852
67,788
Accepted
Accepted
10.1
a = [int(eval(input())) for _ in range(int(eval(input())))] dp = [[0] * 5 for _ in range(len(a) + 1)] for i, x in enumerate(a): y = x % 2 + (x == 0) * 2 z = (x + 1) % 2 dp[i+1][0] = min(dp[i][0:1]) + x dp[i+1][1] = min(dp[i][0:2]) + y dp[i+1][2] = min(dp[i][0:3]) + z dp[i+1][3] = min(dp[i][0:4]) + y dp[i+1][4] = min(dp[i][0:5]) + x print((min(dp[-1])))
a = [int(eval(input())) for _ in range(int(eval(input())))] dp = [[0] * 5 for _ in range(len(a) + 1)] for i, x in enumerate(a): y = x % 2 + (x == 0) * 2 z = (x + 1) % 2 dp[i+1][0] = dp[i][0] + x dp[i+1][1] = min(dp[i][:2]) + y dp[i+1][2] = min(dp[i][:3]) + z dp[i+1][3] = min(dp[i][:4]) + y dp[i+1][4] = min(dp[i]) + x print((min(dp[-1])))
15
15
390
375
a = [int(eval(input())) for _ in range(int(eval(input())))] dp = [[0] * 5 for _ in range(len(a) + 1)] for i, x in enumerate(a): y = x % 2 + (x == 0) * 2 z = (x + 1) % 2 dp[i + 1][0] = min(dp[i][0:1]) + x dp[i + 1][1] = min(dp[i][0:2]) + y dp[i + 1][2] = min(dp[i][0:3]) + z dp[i + 1][3] = min(dp[i][0:4]) + y dp[i + 1][4] = min(dp[i][0:5]) + x print((min(dp[-1])))
a = [int(eval(input())) for _ in range(int(eval(input())))] dp = [[0] * 5 for _ in range(len(a) + 1)] for i, x in enumerate(a): y = x % 2 + (x == 0) * 2 z = (x + 1) % 2 dp[i + 1][0] = dp[i][0] + x dp[i + 1][1] = min(dp[i][:2]) + y dp[i + 1][2] = min(dp[i][:3]) + z dp[i + 1][3] = min(dp[i][:4]) + y dp[i + 1][4] = min(dp[i]) + x print((min(dp[-1])))
false
0
[ "- dp[i + 1][0] = min(dp[i][0:1]) + x", "- dp[i + 1][1] = min(dp[i][0:2]) + y", "- dp[i + 1][2] = min(dp[i][0:3]) + z", "- dp[i + 1][3] = min(dp[i][0:4]) + y", "- dp[i + 1][4] = min(dp[i][0:5]) + x", "+ dp[i + 1][0] = dp[i][0] + x", "+ dp[i + 1][1] = min(dp[i][:2]) + y", "+ dp[...
false
0.037144
0.042266
0.878812
[ "s595554663", "s677210746" ]