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
u562016607
p03026
python
s158822981
s995689950
366
312
50,264
50,520
Accepted
Accepted
14.75
from collections import deque N=int(eval(input())) A=[0 for i in range(N-1)] B=[0 for i in range(N-1)] G=[[] for i in range(N)] for i in range(N-1): a,b=list(map(int,input().split())) a-=1;b-=1 A[i],B[i]=a,b G[a].append(b) G[b].append(a) j=0 for i in range(N): if len(G[i])>len(G[j]): j=i c=sorted([int(i) for i in input().split()]) d=[-1 for i in range(N)] q=deque([j]) while(len(q)>0): r=q.popleft() d[r]=c.pop() for p in G[r]: if d[p]==-1: q.append(p) M=0 for i in range(N-1): M+=min(d[A[i]],d[B[i]]) print(M) print((" ".join([str(i) for i in d])))
from collections import deque N=int(eval(input())) A=[0 for i in range(N-1)] B=[0 for i in range(N-1)] G=[[] for i in range(N)] for i in range(N-1): a,b=list(map(int,input().split())) a-=1;b-=1 A[i],B[i]=a,b G[a].append(b) G[b].append(a) j=0 for i in range(N): if len(G[i])>len(G[j]): j=i c=sorted([int(i) for i in input().split()]) d=[-1 for i in range(N)] q=deque([j]) while(len(q)>0): r=q.popleft() d[r]=c.pop() for p in G[r]: if d[p]==-1: q.appendleft(p) M=0 for i in range(N-1): M+=min(d[A[i]],d[B[i]]) print(M) print((" ".join([str(i) for i in d])))
29
29
634
638
from collections import deque N = int(eval(input())) A = [0 for i in range(N - 1)] B = [0 for i in range(N - 1)] G = [[] for i in range(N)] for i in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 A[i], B[i] = a, b G[a].append(b) G[b].append(a) j = 0 for i in range(N): if len(G[i]) > len(G[j]): j = i c = sorted([int(i) for i in input().split()]) d = [-1 for i in range(N)] q = deque([j]) while len(q) > 0: r = q.popleft() d[r] = c.pop() for p in G[r]: if d[p] == -1: q.append(p) M = 0 for i in range(N - 1): M += min(d[A[i]], d[B[i]]) print(M) print((" ".join([str(i) for i in d])))
from collections import deque N = int(eval(input())) A = [0 for i in range(N - 1)] B = [0 for i in range(N - 1)] G = [[] for i in range(N)] for i in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 A[i], B[i] = a, b G[a].append(b) G[b].append(a) j = 0 for i in range(N): if len(G[i]) > len(G[j]): j = i c = sorted([int(i) for i in input().split()]) d = [-1 for i in range(N)] q = deque([j]) while len(q) > 0: r = q.popleft() d[r] = c.pop() for p in G[r]: if d[p] == -1: q.appendleft(p) M = 0 for i in range(N - 1): M += min(d[A[i]], d[B[i]]) print(M) print((" ".join([str(i) for i in d])))
false
0
[ "- q.append(p)", "+ q.appendleft(p)" ]
false
0.047276
0.04831
0.978592
[ "s158822981", "s995689950" ]
u188827677
p02947
python
s338368048
s252096938
373
234
19,528
24,216
Accepted
Accepted
37.27
N = int(eval(input())) s = [''.join(sorted(eval(input()))) for _ in range(N)] d = {} for i in s: if i not in d: d[i] = 1 else: d[i] += 1 ans = 0 for i in list(d.values()): ans += i*(i-1)//2 print(ans)
from collections import Counter n = int(eval(input())) s = ["".join(sorted(list(eval(input())))) for _ in range(n)] count = Counter(s) ans = 0 for i in list(count.values()): ans += i*(i-1)//2 print(ans)
14
9
211
195
N = int(eval(input())) s = ["".join(sorted(eval(input()))) for _ in range(N)] d = {} for i in s: if i not in d: d[i] = 1 else: d[i] += 1 ans = 0 for i in list(d.values()): ans += i * (i - 1) // 2 print(ans)
from collections import Counter n = int(eval(input())) s = ["".join(sorted(list(eval(input())))) for _ in range(n)] count = Counter(s) ans = 0 for i in list(count.values()): ans += i * (i - 1) // 2 print(ans)
false
35.714286
[ "-N = int(eval(input()))", "-s = [\"\".join(sorted(eval(input()))) for _ in range(N)]", "-d = {}", "-for i in s:", "- if i not in d:", "- d[i] = 1", "- else:", "- d[i] += 1", "+from collections import Counter", "+", "+n = int(eval(input()))", "+s = [\"\".join(sorted(list(eval(input())))) for _ in range(n)]", "+count = Counter(s)", "-for i in list(d.values()):", "+for i in list(count.values()):" ]
false
0.042203
0.038917
1.084433
[ "s338368048", "s252096938" ]
u242031676
p02861
python
s056356622
s969989037
430
18
3,188
3,060
Accepted
Accepted
95.81
from itertools import permutations n = int(eval(input())) x, y = list(zip(*[list(map(int, input().split()))for i in range(n)])) ans = cnt = 0 for i in permutations(list(range(n))): cnt += 1 for j in range(n-1): f, t = i[j], i[j+1] ans += ((x[f]-x[t])**2 + (y[f]-y[t])**2)**0.5 print((ans/cnt))
n = int(eval(input())) a = [list(map(int,input().split()))for i in range(n)] ans = 0 for i in range(n): for j in range(n): ans += ((a[i][0]-a[j][0])**2 + (a[i][1]-a[j][1])**2)**0.5 print((ans/n))
11
7
332
205
from itertools import permutations n = int(eval(input())) x, y = list(zip(*[list(map(int, input().split())) for i in range(n)])) ans = cnt = 0 for i in permutations(list(range(n))): cnt += 1 for j in range(n - 1): f, t = i[j], i[j + 1] ans += ((x[f] - x[t]) ** 2 + (y[f] - y[t]) ** 2) ** 0.5 print((ans / cnt))
n = int(eval(input())) a = [list(map(int, input().split())) for i in range(n)] ans = 0 for i in range(n): for j in range(n): ans += ((a[i][0] - a[j][0]) ** 2 + (a[i][1] - a[j][1]) ** 2) ** 0.5 print((ans / n))
false
36.363636
[ "-from itertools import permutations", "-", "-x, y = list(zip(*[list(map(int, input().split())) for i in range(n)]))", "-ans = cnt = 0", "-for i in permutations(list(range(n))):", "- cnt += 1", "- for j in range(n - 1):", "- f, t = i[j], i[j + 1]", "- ans += ((x[f] - x[t]) ** 2 + (y[f] - y[t]) ** 2) ** 0.5", "-print((ans / cnt))", "+a = [list(map(int, input().split())) for i in range(n)]", "+ans = 0", "+for i in range(n):", "+ for j in range(n):", "+ ans += ((a[i][0] - a[j][0]) ** 2 + (a[i][1] - a[j][1]) ** 2) ** 0.5", "+print((ans / n))" ]
false
0.040871
0.040763
1.002662
[ "s056356622", "s969989037" ]
u895445743
p03545
python
s556962703
s262437060
169
64
38,384
62,204
Accepted
Accepted
62.13
from itertools import product a=list(eval(input())) for b in product(["+","-"],repeat=3): if(eval(a[0]+b[0]+a[1]+b[1]+a[2]+b[2]+a[3])==7): print((str(a[0]+b[0]+a[1]+b[1]+a[2]+b[2]+a[3]+"=7"))) break
from itertools import product import sys S = str(eval(input())) A = list(product(['+', '-'], repeat=3)) for a in A: ans = 0 tmp = "" for i in range(len(S)-1): tmp += S[i]+a[i] tmp += S[len(S)-1] ans += eval(tmp) if ans == 7: print((tmp+"=7")) sys.exit()
7
16
207
311
from itertools import product a = list(eval(input())) for b in product(["+", "-"], repeat=3): if eval(a[0] + b[0] + a[1] + b[1] + a[2] + b[2] + a[3]) == 7: print((str(a[0] + b[0] + a[1] + b[1] + a[2] + b[2] + a[3] + "=7"))) break
from itertools import product import sys S = str(eval(input())) A = list(product(["+", "-"], repeat=3)) for a in A: ans = 0 tmp = "" for i in range(len(S) - 1): tmp += S[i] + a[i] tmp += S[len(S) - 1] ans += eval(tmp) if ans == 7: print((tmp + "=7")) sys.exit()
false
56.25
[ "+import sys", "-a = list(eval(input()))", "-for b in product([\"+\", \"-\"], repeat=3):", "- if eval(a[0] + b[0] + a[1] + b[1] + a[2] + b[2] + a[3]) == 7:", "- print((str(a[0] + b[0] + a[1] + b[1] + a[2] + b[2] + a[3] + \"=7\")))", "- break", "+S = str(eval(input()))", "+A = list(product([\"+\", \"-\"], repeat=3))", "+for a in A:", "+ ans = 0", "+ tmp = \"\"", "+ for i in range(len(S) - 1):", "+ tmp += S[i] + a[i]", "+ tmp += S[len(S) - 1]", "+ ans += eval(tmp)", "+ if ans == 7:", "+ print((tmp + \"=7\"))", "+ sys.exit()" ]
false
0.053842
0.088123
0.610987
[ "s556962703", "s262437060" ]
u353797797
p02624
python
s763362091
s433263344
1,213
32
9,160
9,080
Accepted
Accepted
97.36
def solve(n): ans=0 for d in range(1,n+1): c=n//d ans+=(c+1)*c//2*d return ans n=int(eval(input())) print((solve(n)))
# O(sqrt(N))solution def solve(n): ans = 0 r = n for c in range(1, n + 1): l = n // (c + 1) if r - l == 1: break ans += (l + 1 + r) * (r - l) // 2 * c * (c + 1) // 2 r = l for d in range(1, r + 1): c = n // d ans += (c + 1) * c // 2 * d return ans n=int(eval(input())) print((solve(n)))
9
17
147
365
def solve(n): ans = 0 for d in range(1, n + 1): c = n // d ans += (c + 1) * c // 2 * d return ans n = int(eval(input())) print((solve(n)))
# O(sqrt(N))solution def solve(n): ans = 0 r = n for c in range(1, n + 1): l = n // (c + 1) if r - l == 1: break ans += (l + 1 + r) * (r - l) // 2 * c * (c + 1) // 2 r = l for d in range(1, r + 1): c = n // d ans += (c + 1) * c // 2 * d return ans n = int(eval(input())) print((solve(n)))
false
47.058824
[ "+# O(sqrt(N))solution", "- for d in range(1, n + 1):", "+ r = n", "+ for c in range(1, n + 1):", "+ l = n // (c + 1)", "+ if r - l == 1:", "+ break", "+ ans += (l + 1 + r) * (r - l) // 2 * c * (c + 1) // 2", "+ r = l", "+ for d in range(1, r + 1):" ]
false
0.826914
0.036897
22.411273
[ "s763362091", "s433263344" ]
u186838327
p03716
python
s171206060
s512201590
783
654
121,488
120,208
Accepted
Accepted
16.48
n = int(eval(input())) as_ = list(map(int, input().split())) l = [0]*n m = [0]*n r = [0]*n for i in range(n): l[i] = as_[i] m[i] = as_[n+i] r[i] = (-1)*as_[2*n+i] import heapq heapq.heapify(l) heapq.heapify(r) l_maxs = [0]*(n+1) r_mins = [0]*(n+1) sl = sum(l) sr = sum(r) for i in range(n+1): if i != 0: j = i-1 heapq.heappush(l, m[j]) a = heapq.heappop(l) sl += m[j] -a k = -i heapq.heappush(r, m[k]*(-1)) b = heapq.heappop(r) sr += m[k]*(-1) - b l_maxs[i] = sl r_mins[i] = sr #print(l_maxs) #print(r_mins) print((max([l_maxs[i] + r_mins[n-i] for i in range(n+1)])))
n = int(eval(input())) A = list(map(int, input().split())) L = A[0:n] R = A[2*n:3*n] import heapq sl = sum(L) heapq.heapify(L) sls = [0]*(n+1) sls[0] = sl for i in range(n, 2*n): heapq.heappush(L, A[i]) x = heapq.heappop(L) sl += A[i]-x sls[i-n+1] = sl #print(sls) sr = sum(R) R = [-c for c in R] heapq.heapify(R) srs = [0]*(n+1) srs[-1] = sr for i in reversed(list(range(n, 2*n))): heapq.heappush(R, -A[i]) x = -heapq.heappop(R) sr += A[i]-x srs[i-n] = sr #print(srs) ans = - 10**18 for i in range(n+1): ans = max(ans, sls[i]-srs[i]) print(ans)
40
32
660
602
n = int(eval(input())) as_ = list(map(int, input().split())) l = [0] * n m = [0] * n r = [0] * n for i in range(n): l[i] = as_[i] m[i] = as_[n + i] r[i] = (-1) * as_[2 * n + i] import heapq heapq.heapify(l) heapq.heapify(r) l_maxs = [0] * (n + 1) r_mins = [0] * (n + 1) sl = sum(l) sr = sum(r) for i in range(n + 1): if i != 0: j = i - 1 heapq.heappush(l, m[j]) a = heapq.heappop(l) sl += m[j] - a k = -i heapq.heappush(r, m[k] * (-1)) b = heapq.heappop(r) sr += m[k] * (-1) - b l_maxs[i] = sl r_mins[i] = sr # print(l_maxs) # print(r_mins) print((max([l_maxs[i] + r_mins[n - i] for i in range(n + 1)])))
n = int(eval(input())) A = list(map(int, input().split())) L = A[0:n] R = A[2 * n : 3 * n] import heapq sl = sum(L) heapq.heapify(L) sls = [0] * (n + 1) sls[0] = sl for i in range(n, 2 * n): heapq.heappush(L, A[i]) x = heapq.heappop(L) sl += A[i] - x sls[i - n + 1] = sl # print(sls) sr = sum(R) R = [-c for c in R] heapq.heapify(R) srs = [0] * (n + 1) srs[-1] = sr for i in reversed(list(range(n, 2 * n))): heapq.heappush(R, -A[i]) x = -heapq.heappop(R) sr += A[i] - x srs[i - n] = sr # print(srs) ans = -(10**18) for i in range(n + 1): ans = max(ans, sls[i] - srs[i]) print(ans)
false
20
[ "-as_ = list(map(int, input().split()))", "-l = [0] * n", "-m = [0] * n", "-r = [0] * n", "-for i in range(n):", "- l[i] = as_[i]", "- m[i] = as_[n + i]", "- r[i] = (-1) * as_[2 * n + i]", "+A = list(map(int, input().split()))", "+L = A[0:n]", "+R = A[2 * n : 3 * n]", "-heapq.heapify(l)", "-heapq.heapify(r)", "-l_maxs = [0] * (n + 1)", "-r_mins = [0] * (n + 1)", "-sl = sum(l)", "-sr = sum(r)", "+sl = sum(L)", "+heapq.heapify(L)", "+sls = [0] * (n + 1)", "+sls[0] = sl", "+for i in range(n, 2 * n):", "+ heapq.heappush(L, A[i])", "+ x = heapq.heappop(L)", "+ sl += A[i] - x", "+ sls[i - n + 1] = sl", "+# print(sls)", "+sr = sum(R)", "+R = [-c for c in R]", "+heapq.heapify(R)", "+srs = [0] * (n + 1)", "+srs[-1] = sr", "+for i in reversed(list(range(n, 2 * n))):", "+ heapq.heappush(R, -A[i])", "+ x = -heapq.heappop(R)", "+ sr += A[i] - x", "+ srs[i - n] = sr", "+# print(srs)", "+ans = -(10**18)", "- if i != 0:", "- j = i - 1", "- heapq.heappush(l, m[j])", "- a = heapq.heappop(l)", "- sl += m[j] - a", "- k = -i", "- heapq.heappush(r, m[k] * (-1))", "- b = heapq.heappop(r)", "- sr += m[k] * (-1) - b", "- l_maxs[i] = sl", "- r_mins[i] = sr", "-# print(l_maxs)", "-# print(r_mins)", "-print((max([l_maxs[i] + r_mins[n - i] for i in range(n + 1)])))", "+ ans = max(ans, sls[i] - srs[i])", "+print(ans)" ]
false
0.047938
0.044679
1.072926
[ "s171206060", "s512201590" ]
u661534240
p02911
python
s850925892
s912365801
241
198
10,528
10,924
Accepted
Accepted
17.84
def t(n, k, q, a): p = [-q + k] * n for i in range(q): p[a[i-1]-1] += 1 return ["Yes" if i > 0 else "No" for i in p] if __name__ == "__main__": n, k, q = list(map(int, input().split())) a = [int(eval(input())) for i in range(q)] r = t(n, k, q, a) for i in r: print(i)
n, k, q = list(map(int, input().split())) a = [int(eval(input())) for i in range(q)] p = [-q + k] * n for i in range(q): p[a[i-1]-1] += 1 print(('\n'.join(["Yes" if i > 0 else "No" for i in p])))
13
6
317
191
def t(n, k, q, a): p = [-q + k] * n for i in range(q): p[a[i - 1] - 1] += 1 return ["Yes" if i > 0 else "No" for i in p] if __name__ == "__main__": n, k, q = list(map(int, input().split())) a = [int(eval(input())) for i in range(q)] r = t(n, k, q, a) for i in r: print(i)
n, k, q = list(map(int, input().split())) a = [int(eval(input())) for i in range(q)] p = [-q + k] * n for i in range(q): p[a[i - 1] - 1] += 1 print(("\n".join(["Yes" if i > 0 else "No" for i in p])))
false
53.846154
[ "-def t(n, k, q, a):", "- p = [-q + k] * n", "- for i in range(q):", "- p[a[i - 1] - 1] += 1", "- return [\"Yes\" if i > 0 else \"No\" for i in p]", "-", "-", "-if __name__ == \"__main__\":", "- n, k, q = list(map(int, input().split()))", "- a = [int(eval(input())) for i in range(q)]", "- r = t(n, k, q, a)", "- for i in r:", "- print(i)", "+n, k, q = list(map(int, input().split()))", "+a = [int(eval(input())) for i in range(q)]", "+p = [-q + k] * n", "+for i in range(q):", "+ p[a[i - 1] - 1] += 1", "+print((\"\\n\".join([\"Yes\" if i > 0 else \"No\" for i in p])))" ]
false
0.049349
0.11476
0.430022
[ "s850925892", "s912365801" ]
u312025627
p02954
python
s941038613
s498408475
1,317
248
23,344
48,060
Accepted
Accepted
81.17
import numpy as np from scipy.sparse import csr_matrix s = np.array(list(eval(input())), dtype='U1') n = len(s) child = np.ones(n, dtype=np.int32) rows = np.arange(n) cols = np.where(s == 'R', rows+1, rows-1) x = csr_matrix((np.ones(n, dtype=np.int32), (rows, cols)), (n, n)) def power(x, n): if n == 1: return x y = power(x, n//2) y = y*y return x*y if n & 1 else y x = power(x, 10**100) print((*(child*x)))
def main(): S = eval(input()) N = len(S) now = 0 ans = [0]*N for i in range(N): if S[i] == "R": now += 1 else: ans[i] += now//2 if i != 0: ans[i-1] += int(0--now//2) now = 0 now = 0 for i in range(N-1, -1, -1): if S[i] == "L": now += 1 else: ans[i] += now//2 if i != N-1: ans[i+1] += int(0--now//2) now = 0 print((*ans)) if __name__ == '__main__': main()
20
28
447
573
import numpy as np from scipy.sparse import csr_matrix s = np.array(list(eval(input())), dtype="U1") n = len(s) child = np.ones(n, dtype=np.int32) rows = np.arange(n) cols = np.where(s == "R", rows + 1, rows - 1) x = csr_matrix((np.ones(n, dtype=np.int32), (rows, cols)), (n, n)) def power(x, n): if n == 1: return x y = power(x, n // 2) y = y * y return x * y if n & 1 else y x = power(x, 10**100) print((*(child * x)))
def main(): S = eval(input()) N = len(S) now = 0 ans = [0] * N for i in range(N): if S[i] == "R": now += 1 else: ans[i] += now // 2 if i != 0: ans[i - 1] += int(0 - -now // 2) now = 0 now = 0 for i in range(N - 1, -1, -1): if S[i] == "L": now += 1 else: ans[i] += now // 2 if i != N - 1: ans[i + 1] += int(0 - -now // 2) now = 0 print((*ans)) if __name__ == "__main__": main()
false
28.571429
[ "-import numpy as np", "-from scipy.sparse import csr_matrix", "-", "-s = np.array(list(eval(input())), dtype=\"U1\")", "-n = len(s)", "-child = np.ones(n, dtype=np.int32)", "-rows = np.arange(n)", "-cols = np.where(s == \"R\", rows + 1, rows - 1)", "-x = csr_matrix((np.ones(n, dtype=np.int32), (rows, cols)), (n, n))", "+def main():", "+ S = eval(input())", "+ N = len(S)", "+ now = 0", "+ ans = [0] * N", "+ for i in range(N):", "+ if S[i] == \"R\":", "+ now += 1", "+ else:", "+ ans[i] += now // 2", "+ if i != 0:", "+ ans[i - 1] += int(0 - -now // 2)", "+ now = 0", "+ now = 0", "+ for i in range(N - 1, -1, -1):", "+ if S[i] == \"L\":", "+ now += 1", "+ else:", "+ ans[i] += now // 2", "+ if i != N - 1:", "+ ans[i + 1] += int(0 - -now // 2)", "+ now = 0", "+ print((*ans))", "-def power(x, n):", "- if n == 1:", "- return x", "- y = power(x, n // 2)", "- y = y * y", "- return x * y if n & 1 else y", "-", "-", "-x = power(x, 10**100)", "-print((*(child * x)))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.258604
0.036457
7.093432
[ "s941038613", "s498408475" ]
u352394527
p00430
python
s506493922
s096903138
110
100
9,776
9,776
Accepted
Accepted
9.09
def main(): dic = [[] for i in range(31)] dic[1].append([1]) def func(n): if dic[n]: return dic[n] else: dic[n].append([n]) for i in range(n - 1, 0, -1): for l in func(n - i): if i >= l[0]: dic[n].append([i] + l) return dic[n] func(30) while True: n = int(eval(input())) if not n: break for l in dic[n]: print((" ".join(map(str, l)))) main()
dic = [[] for i in range(31)] dic[1].append([1]) def func(n): if dic[n]: return dic[n] else: dic[n].append([n]) for i in range(n - 1, 0, -1): for l in func(n - i): if i >= l[0]: dic[n].append([i] + l) return dic[n] func(30) def main(): while True: n = int(eval(input())) if not n: break for l in dic[n]: print((" ".join(map(str, l)))) main()
23
23
458
428
def main(): dic = [[] for i in range(31)] dic[1].append([1]) def func(n): if dic[n]: return dic[n] else: dic[n].append([n]) for i in range(n - 1, 0, -1): for l in func(n - i): if i >= l[0]: dic[n].append([i] + l) return dic[n] func(30) while True: n = int(eval(input())) if not n: break for l in dic[n]: print((" ".join(map(str, l)))) main()
dic = [[] for i in range(31)] dic[1].append([1]) def func(n): if dic[n]: return dic[n] else: dic[n].append([n]) for i in range(n - 1, 0, -1): for l in func(n - i): if i >= l[0]: dic[n].append([i] + l) return dic[n] func(30) def main(): while True: n = int(eval(input())) if not n: break for l in dic[n]: print((" ".join(map(str, l)))) main()
false
0
[ "+dic = [[] for i in range(31)]", "+dic[1].append([1])", "+", "+", "+def func(n):", "+ if dic[n]:", "+ return dic[n]", "+ else:", "+ dic[n].append([n])", "+ for i in range(n - 1, 0, -1):", "+ for l in func(n - i):", "+ if i >= l[0]:", "+ dic[n].append([i] + l)", "+ return dic[n]", "+", "+", "+func(30)", "+", "+", "- dic = [[] for i in range(31)]", "- dic[1].append([1])", "-", "- def func(n):", "- if dic[n]:", "- return dic[n]", "- else:", "- dic[n].append([n])", "- for i in range(n - 1, 0, -1):", "- for l in func(n - i):", "- if i >= l[0]:", "- dic[n].append([i] + l)", "- return dic[n]", "-", "- func(30)" ]
false
0.109502
0.094539
1.158277
[ "s506493922", "s096903138" ]
u531599639
p02659
python
s931637418
s323590203
27
22
10,096
9,160
Accepted
Accepted
18.52
from decimal import Decimal A, B = input().split() A = Decimal(A) B = Decimal(B) print((int(A*B)))
A, B = input().split() C = B.replace('.', '') print((int(A)*int(C)//100))
6
3
102
74
from decimal import Decimal A, B = input().split() A = Decimal(A) B = Decimal(B) print((int(A * B)))
A, B = input().split() C = B.replace(".", "") print((int(A) * int(C) // 100))
false
50
[ "-from decimal import Decimal", "-", "-A = Decimal(A)", "-B = Decimal(B)", "-print((int(A * B)))", "+C = B.replace(\".\", \"\")", "+print((int(A) * int(C) // 100))" ]
false
0.038057
0.036313
1.048034
[ "s931637418", "s323590203" ]
u560988566
p02996
python
s616957253
s038421344
1,191
1,083
42,960
43,100
Accepted
Accepted
9.07
import heapq n = int(eval(input())) abs = [tuple(map(int, input().split())) for _ in range(n)] pq = [] for ab in abs: a,b = ab[0],ab[1] heapq.heappush(pq, tuple([b,a])) dl = 0 tc = 0 ans = "Yes" for i in range(n): ba = heapq.heappop(pq) dl = ba[0] tc += ba[1] if dl < tc: ans = "No" break print(ans)
import heapq def main(): n = int(eval(input())) abs = [tuple(map(int, input().split())) for _ in range(n)] pq = [] for ab in abs: a,b = ab[0],ab[1] heapq.heappush(pq, tuple([b,a])) dl = 0 tc = 0 ans = "Yes" for i in range(n): ba = heapq.heappop(pq) dl = ba[0] tc += ba[1] if dl < tc: ans = "No" break print(ans) if __name__ == "__main__": main()
24
28
344
431
import heapq n = int(eval(input())) abs = [tuple(map(int, input().split())) for _ in range(n)] pq = [] for ab in abs: a, b = ab[0], ab[1] heapq.heappush(pq, tuple([b, a])) dl = 0 tc = 0 ans = "Yes" for i in range(n): ba = heapq.heappop(pq) dl = ba[0] tc += ba[1] if dl < tc: ans = "No" break print(ans)
import heapq def main(): n = int(eval(input())) abs = [tuple(map(int, input().split())) for _ in range(n)] pq = [] for ab in abs: a, b = ab[0], ab[1] heapq.heappush(pq, tuple([b, a])) dl = 0 tc = 0 ans = "Yes" for i in range(n): ba = heapq.heappop(pq) dl = ba[0] tc += ba[1] if dl < tc: ans = "No" break print(ans) if __name__ == "__main__": main()
false
14.285714
[ "-n = int(eval(input()))", "-abs = [tuple(map(int, input().split())) for _ in range(n)]", "-pq = []", "-for ab in abs:", "- a, b = ab[0], ab[1]", "- heapq.heappush(pq, tuple([b, a]))", "-dl = 0", "-tc = 0", "-ans = \"Yes\"", "-for i in range(n):", "- ba = heapq.heappop(pq)", "- dl = ba[0]", "- tc += ba[1]", "- if dl < tc:", "- ans = \"No\"", "- break", "-print(ans)", "+", "+def main():", "+ n = int(eval(input()))", "+ abs = [tuple(map(int, input().split())) for _ in range(n)]", "+ pq = []", "+ for ab in abs:", "+ a, b = ab[0], ab[1]", "+ heapq.heappush(pq, tuple([b, a]))", "+ dl = 0", "+ tc = 0", "+ ans = \"Yes\"", "+ for i in range(n):", "+ ba = heapq.heappop(pq)", "+ dl = ba[0]", "+ tc += ba[1]", "+ if dl < tc:", "+ ans = \"No\"", "+ break", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.045845
0.045121
1.016045
[ "s616957253", "s038421344" ]
u607865971
p02995
python
s656207203
s695484691
38
25
4,020
3,684
Accepted
Accepted
34.21
import sys from collections import Counter, deque, defaultdict from itertools import accumulate, permutations, combinations, takewhile, compress, cycle from functools import reduce from math import ceil, floor, log10, log2, factorial from pprint import pprint sys.setrecursionlimit(1000000) # MOD = 10 ** 9 + 7 # N = int(input()) # A = [int(x) for x in input().split()] # V = [[0] * 100 for _ in range(100)] # A = [int(input()) for _ in range(N)] A, B, C, D = [int(x) for x in input().split()] def gcd(x, y): while (y): x, y = y, x % y return x def lcm(x, y): return (x * y) // gcd(x, y) def f(a, b, c): if a % c == 0: a1 = a // c else: a1 = a // c + 1 b1 = b // c r = b1 - a1 + 1 return r # c = (B - A + 1) // C # d = (B - A + 1) // D # cd = (B - A + 1) // (C * D) c = f(A, B, C) d = f(A, B, D) cd = f(A, B, lcm(C, D)) n = B - A + 1 print((n - c - d + cd))
import sys from collections import Counter, deque, defaultdict from itertools import accumulate, permutations, combinations, takewhile, compress, cycle from functools import reduce from math import ceil, floor, log10, log2, factorial from pprint import pprint sys.setrecursionlimit(1000000) # MOD = 10 ** 9 + 7 # N = int(input()) # A = [int(x) for x in input().split()] # V = [[0] * 100 for _ in range(100)] # A = [int(input()) for _ in range(N)] A, B, C, D = [int(x) for x in input().split()] def gcb(a, b): # a, b = max([a, b]), min([a, b]) return a if b == 0 else gcb(b, a % b) def lcm(a, b): return a * b // gcb(a, b) g = lcm(C, D) c = B // C - (A - 1) // C d = B // D - (A - 1) // D cd = B // g - (A - 1) // g print((B - A + 1 - c - d + cd))
47
32
970
797
import sys from collections import Counter, deque, defaultdict from itertools import accumulate, permutations, combinations, takewhile, compress, cycle from functools import reduce from math import ceil, floor, log10, log2, factorial from pprint import pprint sys.setrecursionlimit(1000000) # MOD = 10 ** 9 + 7 # N = int(input()) # A = [int(x) for x in input().split()] # V = [[0] * 100 for _ in range(100)] # A = [int(input()) for _ in range(N)] A, B, C, D = [int(x) for x in input().split()] def gcd(x, y): while y: x, y = y, x % y return x def lcm(x, y): return (x * y) // gcd(x, y) def f(a, b, c): if a % c == 0: a1 = a // c else: a1 = a // c + 1 b1 = b // c r = b1 - a1 + 1 return r # c = (B - A + 1) // C # d = (B - A + 1) // D # cd = (B - A + 1) // (C * D) c = f(A, B, C) d = f(A, B, D) cd = f(A, B, lcm(C, D)) n = B - A + 1 print((n - c - d + cd))
import sys from collections import Counter, deque, defaultdict from itertools import accumulate, permutations, combinations, takewhile, compress, cycle from functools import reduce from math import ceil, floor, log10, log2, factorial from pprint import pprint sys.setrecursionlimit(1000000) # MOD = 10 ** 9 + 7 # N = int(input()) # A = [int(x) for x in input().split()] # V = [[0] * 100 for _ in range(100)] # A = [int(input()) for _ in range(N)] A, B, C, D = [int(x) for x in input().split()] def gcb(a, b): # a, b = max([a, b]), min([a, b]) return a if b == 0 else gcb(b, a % b) def lcm(a, b): return a * b // gcb(a, b) g = lcm(C, D) c = B // C - (A - 1) // C d = B // D - (A - 1) // D cd = B // g - (A - 1) // g print((B - A + 1 - c - d + cd))
false
31.914894
[ "-def gcd(x, y):", "- while y:", "- x, y = y, x % y", "- return x", "+def gcb(a, b):", "+ # a, b = max([a, b]), min([a, b])", "+ return a if b == 0 else gcb(b, a % b)", "-def lcm(x, y):", "- return (x * y) // gcd(x, y)", "+def lcm(a, b):", "+ return a * b // gcb(a, b)", "-def f(a, b, c):", "- if a % c == 0:", "- a1 = a // c", "- else:", "- a1 = a // c + 1", "- b1 = b // c", "- r = b1 - a1 + 1", "- return r", "-", "-", "-# c = (B - A + 1) // C", "-# d = (B - A + 1) // D", "-# cd = (B - A + 1) // (C * D)", "-c = f(A, B, C)", "-d = f(A, B, D)", "-cd = f(A, B, lcm(C, D))", "-n = B - A + 1", "-print((n - c - d + cd))", "+g = lcm(C, D)", "+c = B // C - (A - 1) // C", "+d = B // D - (A - 1) // D", "+cd = B // g - (A - 1) // g", "+print((B - A + 1 - c - d + cd))" ]
false
0.042594
0.072575
0.586896
[ "s656207203", "s695484691" ]
u562016607
p03363
python
s546952888
s942787581
324
252
41,152
41,152
Accepted
Accepted
22.22
N=int(eval(input())) A=[int(i) for i in input().split()] S=[0 for i in range(N+1)] for i in range(N): S[i+1]=A[i]+S[i] D=dict() for i in range(N+1): x=D.get(S[i],0) x+=1 D[S[i]]=x ans=0 for k in D: ans+=(D[k]*(D[k]-1))//2 print(ans)
#ๅนณๆˆใฎๆฌกใฎๅ…ƒๅทใฏ #ไปคๅ’Œใงใ™๏ผ๏ผ #ไปคๅ’Œโ†’้›ถๅ’Œโ†’Zero-Sum #ใ“ใฎๅ•้กŒใฏZero-Sum-Ranges... N=int(eval(input())) A=[int(i) for i in input().split()] S=[0 for i in range(N+1)] for i in range(N): S[i+1]=A[i]+S[i] D=dict() for i in range(N+1): if S[i] in D: D[S[i]]+=1 else: D[S[i]]=1 ans=0 for k in D: t=D[k] ans+=(t*(t-1))//2 print(ans)
14
20
260
352
N = int(eval(input())) A = [int(i) for i in input().split()] S = [0 for i in range(N + 1)] for i in range(N): S[i + 1] = A[i] + S[i] D = dict() for i in range(N + 1): x = D.get(S[i], 0) x += 1 D[S[i]] = x ans = 0 for k in D: ans += (D[k] * (D[k] - 1)) // 2 print(ans)
# ๅนณๆˆใฎๆฌกใฎๅ…ƒๅทใฏ # ไปคๅ’Œใงใ™๏ผ๏ผ # ไปคๅ’Œโ†’้›ถๅ’Œโ†’Zero-Sum # ใ“ใฎๅ•้กŒใฏZero-Sum-Ranges... N = int(eval(input())) A = [int(i) for i in input().split()] S = [0 for i in range(N + 1)] for i in range(N): S[i + 1] = A[i] + S[i] D = dict() for i in range(N + 1): if S[i] in D: D[S[i]] += 1 else: D[S[i]] = 1 ans = 0 for k in D: t = D[k] ans += (t * (t - 1)) // 2 print(ans)
false
30
[ "+# ๅนณๆˆใฎๆฌกใฎๅ…ƒๅทใฏ", "+# ไปคๅ’Œใงใ™๏ผ๏ผ", "+# ไปคๅ’Œโ†’้›ถๅ’Œโ†’Zero-Sum", "+# ใ“ใฎๅ•้กŒใฏZero-Sum-Ranges...", "- x = D.get(S[i], 0)", "- x += 1", "- D[S[i]] = x", "+ if S[i] in D:", "+ D[S[i]] += 1", "+ else:", "+ D[S[i]] = 1", "- ans += (D[k] * (D[k] - 1)) // 2", "+ t = D[k]", "+ ans += (t * (t - 1)) // 2" ]
false
0.036576
0.035022
1.044371
[ "s546952888", "s942787581" ]
u203843959
p02892
python
s875079872
s723993477
712
650
3,444
3,444
Accepted
Accepted
8.71
N=int(eval(input())) graph=[] for i in range(N): graph.append([]) for i in range(N): S=list(map(int,eval(input()))) for j in range(N): if S[j]==1: graph[i].append(j) #print(graph) max_set=-1 for i in range(N): node_list=[-1]*N #bfs d=1 queue={i} illegal=False while(True): new_queue=set() for q in queue: node_list[q]=d for qq in graph[q]: if node_list[qq]==-1: new_queue.add(qq) elif node_list[qq]!=d-1: illegal=True break if illegal: break elif len(new_queue)==0: #print(node_list,d) max_set=max(max_set,d) break else: #print(node_list,new_queue) queue=new_queue d+=1 print(max_set)
N=int(eval(input())) graph=[] for i in range(N): graph.append([]) for i in range(N): S=list(map(int,eval(input()))) for j in range(N): if S[j]==1: graph[i].append(j) #print(graph) max_set=-1 illegal=False for i in range(N): if illegal: break node_list=[-1]*N #bfs d=1 queue={i} while(True): new_queue=set() for q in queue: node_list[q]=d for qq in graph[q]: if node_list[qq]==-1: new_queue.add(qq) elif node_list[qq]!=d-1: illegal=True break if illegal: break elif len(new_queue)==0: #print(node_list,d) max_set=max(max_set,d) break else: #print(node_list,new_queue) queue=new_queue d+=1 print(max_set)
43
46
786
814
N = int(eval(input())) graph = [] for i in range(N): graph.append([]) for i in range(N): S = list(map(int, eval(input()))) for j in range(N): if S[j] == 1: graph[i].append(j) # print(graph) max_set = -1 for i in range(N): node_list = [-1] * N # bfs d = 1 queue = {i} illegal = False while True: new_queue = set() for q in queue: node_list[q] = d for qq in graph[q]: if node_list[qq] == -1: new_queue.add(qq) elif node_list[qq] != d - 1: illegal = True break if illegal: break elif len(new_queue) == 0: # print(node_list,d) max_set = max(max_set, d) break else: # print(node_list,new_queue) queue = new_queue d += 1 print(max_set)
N = int(eval(input())) graph = [] for i in range(N): graph.append([]) for i in range(N): S = list(map(int, eval(input()))) for j in range(N): if S[j] == 1: graph[i].append(j) # print(graph) max_set = -1 illegal = False for i in range(N): if illegal: break node_list = [-1] * N # bfs d = 1 queue = {i} while True: new_queue = set() for q in queue: node_list[q] = d for qq in graph[q]: if node_list[qq] == -1: new_queue.add(qq) elif node_list[qq] != d - 1: illegal = True break if illegal: break elif len(new_queue) == 0: # print(node_list,d) max_set = max(max_set, d) break else: # print(node_list,new_queue) queue = new_queue d += 1 print(max_set)
false
6.521739
[ "+illegal = False", "+ if illegal:", "+ break", "- illegal = False" ]
false
0.035651
0.03481
1.02414
[ "s875079872", "s723993477" ]
u584850530
p02657
python
s447357266
s679122580
21
18
9,112
9,152
Accepted
Accepted
14.29
a, b = list(map(int, input().split())) print((a * b))
a, b = list(map(str, input().split())) A = int(a) B = round(float(b) * 100) print((A * B // 100))
2
4
46
93
a, b = list(map(int, input().split())) print((a * b))
a, b = list(map(str, input().split())) A = int(a) B = round(float(b) * 100) print((A * B // 100))
false
50
[ "-a, b = list(map(int, input().split()))", "-print((a * b))", "+a, b = list(map(str, input().split()))", "+A = int(a)", "+B = round(float(b) * 100)", "+print((A * B // 100))" ]
false
0.039593
0.04356
0.908911
[ "s447357266", "s679122580" ]
u926046014
p02659
python
s644585570
s216217729
27
24
10,072
9,168
Accepted
Accepted
11.11
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.replace(".","")) print(((a*b)//100))
5
6
86
85
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.replace(".", "")) print(((a * b) // 100))
false
16.666667
[ "-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.replace(\".\", \"\"))", "+print(((a * b) // 100))" ]
false
0.052277
0.070947
0.736848
[ "s644585570", "s216217729" ]
u884087839
p02726
python
s515634765
s920334813
1,305
1,164
3,444
3,444
Accepted
Accepted
10.8
#!/usr/bin/env python3 import sys def solve(N: int, X: int, Y: int): distances = [0] * (N - 1) for i in range(0, N - 1): for j in range(i + 1, N): if j < X - 1 or Y - 1 < i: distance = j - i else: distance = min(j - i, abs(X - 1 - i) + abs(Y - 1 - j) + 1) distances[distance - 1] += 1 for k in distances: print(k) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int solve(N, X, Y) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys def solve(N: int, X: int, Y: int): distances = [0] * (N - 1) for i in range(0, N - 1): for j in range(i + 1, N): distance = min(j - i, abs(X - 1 - i) + abs(Y - 1 - j) + 1) distances[distance - 1] += 1 for k in distances: print(k) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int solve(N, X, Y) if __name__ == '__main__': main()
35
30
979
866
#!/usr/bin/env python3 import sys def solve(N: int, X: int, Y: int): distances = [0] * (N - 1) for i in range(0, N - 1): for j in range(i + 1, N): if j < X - 1 or Y - 1 < i: distance = j - i else: distance = min(j - i, abs(X - 1 - i) + abs(Y - 1 - j) + 1) distances[distance - 1] += 1 for k in distances: print(k) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int solve(N, X, Y) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys def solve(N: int, X: int, Y: int): distances = [0] * (N - 1) for i in range(0, N - 1): for j in range(i + 1, N): distance = min(j - i, abs(X - 1 - i) + abs(Y - 1 - j) + 1) distances[distance - 1] += 1 for k in distances: print(k) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int solve(N, X, Y) if __name__ == "__main__": main()
false
14.285714
[ "- if j < X - 1 or Y - 1 < i:", "- distance = j - i", "- else:", "- distance = min(j - i, abs(X - 1 - i) + abs(Y - 1 - j) + 1)", "+ distance = min(j - i, abs(X - 1 - i) + abs(Y - 1 - j) + 1)" ]
false
0.034733
0.036179
0.960037
[ "s515634765", "s920334813" ]
u325956328
p02595
python
s088017115
s128145217
443
396
9,628
9,184
Accepted
Accepted
10.61
N, D = list(map(int, input().split())) ans = 0 for i in range(N): x, y = list(map(int, input().split())) dist = pow((x * x + y * y), 0.5) # print(dist) if dist <= D: ans += 1 print(ans)
N, D = list(map(int, input().split())) ans = 0 for i in range(N): x, y = list(map(int, input().split())) # dist = pow((x * x + y * y), 0.5) dist = (x * x + y * y) # print(dist) if dist <= D*D: ans += 1 print(ans)
11
13
210
248
N, D = list(map(int, input().split())) ans = 0 for i in range(N): x, y = list(map(int, input().split())) dist = pow((x * x + y * y), 0.5) # print(dist) if dist <= D: ans += 1 print(ans)
N, D = list(map(int, input().split())) ans = 0 for i in range(N): x, y = list(map(int, input().split())) # dist = pow((x * x + y * y), 0.5) dist = x * x + y * y # print(dist) if dist <= D * D: ans += 1 print(ans)
false
15.384615
[ "- dist = pow((x * x + y * y), 0.5)", "+ # dist = pow((x * x + y * y), 0.5)", "+ dist = x * x + y * y", "- if dist <= D:", "+ if dist <= D * D:" ]
false
0.100079
0.100765
0.993195
[ "s088017115", "s128145217" ]
u332793228
p03315
python
s091761571
s821550845
19
17
3,060
2,940
Accepted
Accepted
10.53
s=eval(input()) a=0 b=0 for i in s: if i=="+": a+=1 if i=="-": b+=1 print((1*a-1*b))
s=eval(input()) print((s.count("+")-s.count("-")))
9
2
108
43
s = eval(input()) a = 0 b = 0 for i in s: if i == "+": a += 1 if i == "-": b += 1 print((1 * a - 1 * b))
s = eval(input()) print((s.count("+") - s.count("-")))
false
77.777778
[ "-a = 0", "-b = 0", "-for i in s:", "- if i == \"+\":", "- a += 1", "- if i == \"-\":", "- b += 1", "-print((1 * a - 1 * b))", "+print((s.count(\"+\") - s.count(\"-\")))" ]
false
0.037599
0.038895
0.96669
[ "s091761571", "s821550845" ]
u594859393
p03379
python
s889391993
s231375942
295
209
30,868
30,376
Accepted
Accepted
29.15
from statistics import median_low, median_high n = int(eval(input())) xs = list(map(int, input().split())) m1, m2 = median_low(xs), median_high(xs) medians = [m2 if x < m2 else m1 for x in xs] print(('\n'.join(map(str, medians))))
n = int(eval(input())) xs = list(map(int, input().split())) ys = list(sorted(xs)) m1 = ys[n//2 - 1] m2 = ys[n//2] medians = [m2 if x < m2 else m1 for x in xs] print(('\n'.join(map(str, medians))))
9
9
233
200
from statistics import median_low, median_high n = int(eval(input())) xs = list(map(int, input().split())) m1, m2 = median_low(xs), median_high(xs) medians = [m2 if x < m2 else m1 for x in xs] print(("\n".join(map(str, medians))))
n = int(eval(input())) xs = list(map(int, input().split())) ys = list(sorted(xs)) m1 = ys[n // 2 - 1] m2 = ys[n // 2] medians = [m2 if x < m2 else m1 for x in xs] print(("\n".join(map(str, medians))))
false
0
[ "-from statistics import median_low, median_high", "-", "-m1, m2 = median_low(xs), median_high(xs)", "+ys = list(sorted(xs))", "+m1 = ys[n // 2 - 1]", "+m2 = ys[n // 2]" ]
false
0.098375
0.038289
2.569274
[ "s889391993", "s231375942" ]
u571969099
p02850
python
s605670211
s743556816
810
573
89,716
96,796
Accepted
Accepted
29.26
import sys sys.setrecursionlimit(1000000) n = int(eval(input())) ab = [[] for _ in range(n)] for i in range(n - 1): a, b = [int(i)-1 for i in input().split()] ab[a].append([b, i]) ab[b].append([a, i]) re = [False] * n ed = [0]*(n-1) def c(i=0, used=-1): global re, ed if re[i]: return 0 re[i] = True k = 1 for j in ab[i]: if re[j[0]]: continue if k == used: k += 1 ed[j[1]] = k c(j[0], k) k += 1 c() print((max(ed))) print((" ".join([str(i) for i in ed])))
import sys sys.setrecursionlimit(1000000) def input(): return sys.stdin.readline() n = int(eval(input())) e = [[] for _ in range(n)] for j in range(n - 1): a, b = [int(i)-1 for i in input().split()] e[a].append((b, j)) e[b].append((a, j)) co = [0]*(n-1) def dfs(i=0, r=-1, dis=-1): global co c = 1 for j in e[i]: if j[0] == r: continue if c == dis: c += 1 co[j[1]] = c dfs(j[0], i, c) c += 1 dfs() print((max(co))) for i in co: print(i)
32
32
586
562
import sys sys.setrecursionlimit(1000000) n = int(eval(input())) ab = [[] for _ in range(n)] for i in range(n - 1): a, b = [int(i) - 1 for i in input().split()] ab[a].append([b, i]) ab[b].append([a, i]) re = [False] * n ed = [0] * (n - 1) def c(i=0, used=-1): global re, ed if re[i]: return 0 re[i] = True k = 1 for j in ab[i]: if re[j[0]]: continue if k == used: k += 1 ed[j[1]] = k c(j[0], k) k += 1 c() print((max(ed))) print((" ".join([str(i) for i in ed])))
import sys sys.setrecursionlimit(1000000) def input(): return sys.stdin.readline() n = int(eval(input())) e = [[] for _ in range(n)] for j in range(n - 1): a, b = [int(i) - 1 for i in input().split()] e[a].append((b, j)) e[b].append((a, j)) co = [0] * (n - 1) def dfs(i=0, r=-1, dis=-1): global co c = 1 for j in e[i]: if j[0] == r: continue if c == dis: c += 1 co[j[1]] = c dfs(j[0], i, c) c += 1 dfs() print((max(co))) for i in co: print(i)
false
0
[ "-n = int(eval(input()))", "-ab = [[] for _ in range(n)]", "-for i in range(n - 1):", "- a, b = [int(i) - 1 for i in input().split()]", "- ab[a].append([b, i])", "- ab[b].append([a, i])", "-re = [False] * n", "-ed = [0] * (n - 1)", "-def c(i=0, used=-1):", "- global re, ed", "- if re[i]:", "- return 0", "- re[i] = True", "- k = 1", "- for j in ab[i]:", "- if re[j[0]]:", "- continue", "- if k == used:", "- k += 1", "- ed[j[1]] = k", "- c(j[0], k)", "- k += 1", "+def input():", "+ return sys.stdin.readline()", "-c()", "-print((max(ed)))", "-print((\" \".join([str(i) for i in ed])))", "+n = int(eval(input()))", "+e = [[] for _ in range(n)]", "+for j in range(n - 1):", "+ a, b = [int(i) - 1 for i in input().split()]", "+ e[a].append((b, j))", "+ e[b].append((a, j))", "+co = [0] * (n - 1)", "+", "+", "+def dfs(i=0, r=-1, dis=-1):", "+ global co", "+ c = 1", "+ for j in e[i]:", "+ if j[0] == r:", "+ continue", "+ if c == dis:", "+ c += 1", "+ co[j[1]] = c", "+ dfs(j[0], i, c)", "+ c += 1", "+", "+", "+dfs()", "+print((max(co)))", "+for i in co:", "+ print(i)" ]
false
0.044122
0.043998
1.002799
[ "s605670211", "s743556816" ]
u226108478
p03448
python
s903953085
s227840122
62
43
3,060
3,188
Accepted
Accepted
30.65
# -*- coding: utf-8 -*- # AtCoder Beginner Contest # Problem B if __name__ == '__main__': five_hundred_yen_count = int(eval(input())) one_hundred_yen_count = int(eval(input())) fifty_yen_count = int(eval(input())) total_yen = int(eval(input())) pattern_count = 0 for i in range(five_hundred_yen_count + 1): for j in range(one_hundred_yen_count + 1): for k in range(fifty_yen_count + 1): summed_yen = 500 * i + 100 * j + 50 * k if total_yen - summed_yen == 0: pattern_count += 1 print(pattern_count)
# -*- coding: utf-8 -*- def main(): a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) count = 0 for a in range(a + 1): for b in range(b + 1): for c in range(c + 1): if 500 * a + 100 * b + 50 * c == x: count += 1 print(count) if __name__ == '__main__': main()
22
21
602
391
# -*- coding: utf-8 -*- # AtCoder Beginner Contest # Problem B if __name__ == "__main__": five_hundred_yen_count = int(eval(input())) one_hundred_yen_count = int(eval(input())) fifty_yen_count = int(eval(input())) total_yen = int(eval(input())) pattern_count = 0 for i in range(five_hundred_yen_count + 1): for j in range(one_hundred_yen_count + 1): for k in range(fifty_yen_count + 1): summed_yen = 500 * i + 100 * j + 50 * k if total_yen - summed_yen == 0: pattern_count += 1 print(pattern_count)
# -*- coding: utf-8 -*- def main(): a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) count = 0 for a in range(a + 1): for b in range(b + 1): for c in range(c + 1): if 500 * a + 100 * b + 50 * c == x: count += 1 print(count) if __name__ == "__main__": main()
false
4.545455
[ "-# AtCoder Beginner Contest", "-# Problem B", "+def main():", "+ a = int(eval(input()))", "+ b = int(eval(input()))", "+ c = int(eval(input()))", "+ x = int(eval(input()))", "+ count = 0", "+ for a in range(a + 1):", "+ for b in range(b + 1):", "+ for c in range(c + 1):", "+ if 500 * a + 100 * b + 50 * c == x:", "+ count += 1", "+ print(count)", "+", "+", "- five_hundred_yen_count = int(eval(input()))", "- one_hundred_yen_count = int(eval(input()))", "- fifty_yen_count = int(eval(input()))", "- total_yen = int(eval(input()))", "- pattern_count = 0", "- for i in range(five_hundred_yen_count + 1):", "- for j in range(one_hundred_yen_count + 1):", "- for k in range(fifty_yen_count + 1):", "- summed_yen = 500 * i + 100 * j + 50 * k", "- if total_yen - summed_yen == 0:", "- pattern_count += 1", "- print(pattern_count)", "+ main()" ]
false
0.113249
0.069976
1.618395
[ "s903953085", "s227840122" ]
u312025627
p02754
python
s743558309
s505977570
179
18
38,384
2,940
Accepted
Accepted
89.94
def main(): N, A, B = (int(i) for i in input().split()) ans = (N//(A+B)) * A less = N - (N//(A+B)) * (A+B) print((ans + min(less, A))) if __name__ == '__main__': main()
def main(): N, A, B = (int(i) for i in input().split()) ans = (N//(A+B)) * A print((ans + min(N % (A+B), A))) if __name__ == '__main__': main()
9
8
197
167
def main(): N, A, B = (int(i) for i in input().split()) ans = (N // (A + B)) * A less = N - (N // (A + B)) * (A + B) print((ans + min(less, A))) if __name__ == "__main__": main()
def main(): N, A, B = (int(i) for i in input().split()) ans = (N // (A + B)) * A print((ans + min(N % (A + B), A))) if __name__ == "__main__": main()
false
11.111111
[ "- less = N - (N // (A + B)) * (A + B)", "- print((ans + min(less, A)))", "+ print((ans + min(N % (A + B), A)))" ]
false
0.043435
0.036015
1.20603
[ "s743558309", "s505977570" ]
u947883560
p02774
python
s936961592
s798729145
498
454
95,188
95,188
Accepted
Accepted
8.84
#!/usr/bin/env python3 import sys INF = float("inf") def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() # ่ฒ ๆ•ฐใ€ 0ๆ•ฐใ€ ๆญฃๆ•ฐ neg, zero, pos = [], [], [] for a in A: if a < 0: neg.append(a) elif a == 0: zero.append(a) else: pos.append(a) neg.sort() pos.sort() prod_neg = len(neg) * len(pos) prod_zero = len(zero) * (len(neg)+len(pos))+len(zero)*(len(zero)-1)//2 prod_pos = len(neg)*(len(neg)-1)//2 + len(pos)*(len(pos)-1)//2 # print(prod_neg, prod_zero, prod_pos) # print(prod_neg+prod_zero+prod_pos) # print(N*(N-1)//2) if prod_neg >= K: # ไบŒๅˆ†ๆŽข็ดข left = neg[0]*pos[-1]-1 right = 0 while right-left > 1: mid = (right + left)//2 # ใ—ใ‚ƒใใจใ‚Šๆณ• counter = 0 ns, ps = 0, 0 for ns in range(len(neg)): while ps < len(pos) and neg[ns]*pos[ps] > mid: ps += 1 if ps == len(pos): break counter += len(pos)-ps # print("{} in [{}, {}] => {}".format(mid, left, right, counter)) if counter < K: left = mid else: right = mid print(right) elif prod_zero + prod_neg >= K: print((0)) else: neg.sort(reverse=True) # ไบŒๅˆ†ๆŽข็ดข left = 0 right = 0 if len(neg) > 0: right = max(neg[-1]**2, right) if len(pos) > 0: right = max(pos[-1]**2, right) right += 1 while right - left > 1: mid = (left + right)//2 # ใ—ใ‚ƒใใจใ‚Šๆณ• counter = 0 start, end = 0, len(pos)-1 # print("{} in [{}, {}]".format(mid, left, right)) for start in range(len(pos)): while end >= start and pos[start]*pos[end] >= mid: end -= 1 if end <= start: break counter += end-start # print("addA: ", end-start) start, end = 0, len(neg)-1 for start in range(len(neg)): while end >= start and neg[start]*neg[end] >= mid: end -= 1 if end <= start: break counter += end-start # print("addB: ", end-start) # print("counter: {}".format(counter)) if counter < K-prod_neg-prod_zero: left = mid else: right = mid print(left) if __name__ == '__main__': main()
import sys def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() # ่ฒ ๆ•ฐใ€ 0ๆ•ฐใ€ ๆญฃๆ•ฐ neg, zero, pos = [], [], [] for a in A: if a < 0: neg.append(a) elif a == 0: zero.append(a) else: pos.append(a) prod_neg = len(neg) * len(pos) prod_zero = len(zero) * (len(neg)+len(pos))+len(zero)*(len(zero)-1)//2 prod_pos = len(neg)*(len(neg)-1)//2 + len(pos)*(len(pos)-1)//2 if prod_neg >= K: # ไบŒๅˆ†ๆŽข็ดข left = neg[0]*pos[-1]-1 right = 0 while right-left > 1: mid = (right + left)//2 # ใ—ใ‚ƒใใจใ‚Šๆณ• counter = 0 ps = 0 for ns in range(len(neg)): while ps < len(pos) and neg[ns]*pos[ps] > mid: ps += 1 if ps == len(pos): break counter += len(pos)-ps if counter < K: left = mid else: right = mid print(right) elif prod_zero + prod_neg >= K: print((0)) else: # ไบŒๅˆ†ๆŽข็ดข left = 0 right = 0 if len(neg) > 0: right = max(neg[0]**2, right) if len(pos) > 0: right = max(pos[-1]**2, right) while right - left > 1: mid = (left + right)//2 # ใ—ใ‚ƒใใจใ‚Šๆณ• counter = 0 end = len(pos)-1 for start in range(len(pos)): while end >= start and pos[start]*pos[end] >= mid: end -= 1 if end <= start: break counter += end-start start = 0 for end in range(len(neg)-1, -1, -1): while end >= start and neg[start]*neg[end] >= mid: start += 1 if end <= start: break counter += end-start if counter < K-prod_neg-prod_zero: left = mid else: right = mid print(left) if __name__ == '__main__': main()
94
80
2,763
2,211
#!/usr/bin/env python3 import sys INF = float("inf") def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() # ่ฒ ๆ•ฐใ€ 0ๆ•ฐใ€ ๆญฃๆ•ฐ neg, zero, pos = [], [], [] for a in A: if a < 0: neg.append(a) elif a == 0: zero.append(a) else: pos.append(a) neg.sort() pos.sort() prod_neg = len(neg) * len(pos) prod_zero = len(zero) * (len(neg) + len(pos)) + len(zero) * (len(zero) - 1) // 2 prod_pos = len(neg) * (len(neg) - 1) // 2 + len(pos) * (len(pos) - 1) // 2 # print(prod_neg, prod_zero, prod_pos) # print(prod_neg+prod_zero+prod_pos) # print(N*(N-1)//2) if prod_neg >= K: # ไบŒๅˆ†ๆŽข็ดข left = neg[0] * pos[-1] - 1 right = 0 while right - left > 1: mid = (right + left) // 2 # ใ—ใ‚ƒใใจใ‚Šๆณ• counter = 0 ns, ps = 0, 0 for ns in range(len(neg)): while ps < len(pos) and neg[ns] * pos[ps] > mid: ps += 1 if ps == len(pos): break counter += len(pos) - ps # print("{} in [{}, {}] => {}".format(mid, left, right, counter)) if counter < K: left = mid else: right = mid print(right) elif prod_zero + prod_neg >= K: print((0)) else: neg.sort(reverse=True) # ไบŒๅˆ†ๆŽข็ดข left = 0 right = 0 if len(neg) > 0: right = max(neg[-1] ** 2, right) if len(pos) > 0: right = max(pos[-1] ** 2, right) right += 1 while right - left > 1: mid = (left + right) // 2 # ใ—ใ‚ƒใใจใ‚Šๆณ• counter = 0 start, end = 0, len(pos) - 1 # print("{} in [{}, {}]".format(mid, left, right)) for start in range(len(pos)): while end >= start and pos[start] * pos[end] >= mid: end -= 1 if end <= start: break counter += end - start # print("addA: ", end-start) start, end = 0, len(neg) - 1 for start in range(len(neg)): while end >= start and neg[start] * neg[end] >= mid: end -= 1 if end <= start: break counter += end - start # print("addB: ", end-start) # print("counter: {}".format(counter)) if counter < K - prod_neg - prod_zero: left = mid else: right = mid print(left) if __name__ == "__main__": main()
import sys def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() # ่ฒ ๆ•ฐใ€ 0ๆ•ฐใ€ ๆญฃๆ•ฐ neg, zero, pos = [], [], [] for a in A: if a < 0: neg.append(a) elif a == 0: zero.append(a) else: pos.append(a) prod_neg = len(neg) * len(pos) prod_zero = len(zero) * (len(neg) + len(pos)) + len(zero) * (len(zero) - 1) // 2 prod_pos = len(neg) * (len(neg) - 1) // 2 + len(pos) * (len(pos) - 1) // 2 if prod_neg >= K: # ไบŒๅˆ†ๆŽข็ดข left = neg[0] * pos[-1] - 1 right = 0 while right - left > 1: mid = (right + left) // 2 # ใ—ใ‚ƒใใจใ‚Šๆณ• counter = 0 ps = 0 for ns in range(len(neg)): while ps < len(pos) and neg[ns] * pos[ps] > mid: ps += 1 if ps == len(pos): break counter += len(pos) - ps if counter < K: left = mid else: right = mid print(right) elif prod_zero + prod_neg >= K: print((0)) else: # ไบŒๅˆ†ๆŽข็ดข left = 0 right = 0 if len(neg) > 0: right = max(neg[0] ** 2, right) if len(pos) > 0: right = max(pos[-1] ** 2, right) while right - left > 1: mid = (left + right) // 2 # ใ—ใ‚ƒใใจใ‚Šๆณ• counter = 0 end = len(pos) - 1 for start in range(len(pos)): while end >= start and pos[start] * pos[end] >= mid: end -= 1 if end <= start: break counter += end - start start = 0 for end in range(len(neg) - 1, -1, -1): while end >= start and neg[start] * neg[end] >= mid: start += 1 if end <= start: break counter += end - start if counter < K - prod_neg - prod_zero: left = mid else: right = mid print(left) if __name__ == "__main__": main()
false
14.893617
[ "-#!/usr/bin/env python3", "-", "-INF = float(\"inf\")", "- neg.sort()", "- pos.sort()", "- # print(prod_neg, prod_zero, prod_pos)", "- # print(prod_neg+prod_zero+prod_pos)", "- # print(N*(N-1)//2)", "- ns, ps = 0, 0", "+ ps = 0", "- # print(\"{} in [{}, {}] => {}\".format(mid, left, right, counter))", "- neg.sort(reverse=True)", "- right = max(neg[-1] ** 2, right)", "+ right = max(neg[0] ** 2, right)", "- right += 1", "- start, end = 0, len(pos) - 1", "- # print(\"{} in [{}, {}]\".format(mid, left, right))", "+ end = len(pos) - 1", "- # print(\"addA: \", end-start)", "- start, end = 0, len(neg) - 1", "- for start in range(len(neg)):", "+ start = 0", "+ for end in range(len(neg) - 1, -1, -1):", "- end -= 1", "+ start += 1", "- # print(\"addB: \", end-start)", "- # print(\"counter: {}\".format(counter))" ]
false
0.03678
0.037135
0.990434
[ "s936961592", "s798729145" ]
u454022848
p02402
python
s186162673
s889959069
40
10
8,028
7,156
Accepted
Accepted
75
eval(input()) ia=[int(i) for i in input().split(" ")] print((min(ia),max(ia),sum(ia)))
# encoding:utf-8 count = eval(input()) input = list(map(int, input().split())) min = min(input) max =max(input) sum = sum(input) print((min), end=' ') print((max), end=' ') print(sum)
3
12
80
170
eval(input()) ia = [int(i) for i in input().split(" ")] print((min(ia), max(ia), sum(ia)))
# encoding:utf-8 count = eval(input()) input = list(map(int, input().split())) min = min(input) max = max(input) sum = sum(input) print((min), end=" ") print((max), end=" ") print(sum)
false
75
[ "-eval(input())", "-ia = [int(i) for i in input().split(\" \")]", "-print((min(ia), max(ia), sum(ia)))", "+# encoding:utf-8", "+count = eval(input())", "+input = list(map(int, input().split()))", "+min = min(input)", "+max = max(input)", "+sum = sum(input)", "+print((min), end=\" \")", "+print((max), end=\" \")", "+print(sum)" ]
false
0.042073
0.068235
0.61659
[ "s186162673", "s889959069" ]
u884323674
p03478
python
s672037599
s093318128
37
27
3,060
2,940
Accepted
Accepted
27.03
N, A, B = list(map(int, input().split())) result = 0 for i in range(1, N+1): num = list(str(i)) num_sum = 0 for j in num: num_sum += int(j) if A <= num_sum <= B: result += i print(result)
N, A, B = list(map(int, input().split())) # ๅ„ๆกใ‚’ๅˆ่จˆใ™ใ‚‹้–ขๆ•ฐ def sum_digits(num): sum = 0 while num > 0: sum += num % 10 num = num // 10 return sum result = 0 for i in range(1, N+1): if A <= sum_digits(i) <= B: result += i print(result)
13
17
228
283
N, A, B = list(map(int, input().split())) result = 0 for i in range(1, N + 1): num = list(str(i)) num_sum = 0 for j in num: num_sum += int(j) if A <= num_sum <= B: result += i print(result)
N, A, B = list(map(int, input().split())) # ๅ„ๆกใ‚’ๅˆ่จˆใ™ใ‚‹้–ขๆ•ฐ def sum_digits(num): sum = 0 while num > 0: sum += num % 10 num = num // 10 return sum result = 0 for i in range(1, N + 1): if A <= sum_digits(i) <= B: result += i print(result)
false
23.529412
[ "+# ๅ„ๆกใ‚’ๅˆ่จˆใ™ใ‚‹้–ขๆ•ฐ", "+def sum_digits(num):", "+ sum = 0", "+ while num > 0:", "+ sum += num % 10", "+ num = num // 10", "+ return sum", "+", "+", "- num = list(str(i))", "- num_sum = 0", "- for j in num:", "- num_sum += int(j)", "- if A <= num_sum <= B:", "+ if A <= sum_digits(i) <= B:" ]
false
0.039736
0.040323
0.985432
[ "s672037599", "s093318128" ]
u408071652
p03078
python
s394030431
s462630934
542
123
221,252
77,548
Accepted
Accepted
77.31
import sys import heapq # \n def input(): return sys.stdin.readline().rstrip() def main(): X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) a = 0 b = 0 c = 0 k = 1 L = [] for i in range(X): for j in range(Y): L.append(A[i] + B[j]) L.sort(reverse=True) newL = L[:min(3000, X * Y)] XY = len(newL) L=[] for i in range(XY): for j in range(Z): L.append(newL[i]+C[j]) L.sort(reverse=True) for j in range(K): print((L[j])) if __name__ == "__main__": main()
import sys import heapq # \n def input(): return sys.stdin.readline().rstrip() def main(): X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) L=[] for i in range(X): for j in range(Y): for k in range(X): if (i+1)*(j+1)*(k+1)<=K: L.append(A[i]+B[j]+C[k]) else: break L.sort(reverse=True) for i in range(K): print((L[i])) if __name__ == "__main__": main()
47
38
805
712
import sys import heapq # \n def input(): return sys.stdin.readline().rstrip() def main(): X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) a = 0 b = 0 c = 0 k = 1 L = [] for i in range(X): for j in range(Y): L.append(A[i] + B[j]) L.sort(reverse=True) newL = L[: min(3000, X * Y)] XY = len(newL) L = [] for i in range(XY): for j in range(Z): L.append(newL[i] + C[j]) L.sort(reverse=True) for j in range(K): print((L[j])) if __name__ == "__main__": main()
import sys import heapq # \n def input(): return sys.stdin.readline().rstrip() def main(): X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) L = [] for i in range(X): for j in range(Y): for k in range(X): if (i + 1) * (j + 1) * (k + 1) <= K: L.append(A[i] + B[j] + C[k]) else: break L.sort(reverse=True) for i in range(K): print((L[i])) if __name__ == "__main__": main()
false
19.148936
[ "- a = 0", "- b = 0", "- c = 0", "- k = 1", "- L.append(A[i] + B[j])", "+ for k in range(X):", "+ if (i + 1) * (j + 1) * (k + 1) <= K:", "+ L.append(A[i] + B[j] + C[k])", "+ else:", "+ break", "- newL = L[: min(3000, X * Y)]", "- XY = len(newL)", "- L = []", "- for i in range(XY):", "- for j in range(Z):", "- L.append(newL[i] + C[j])", "- L.sort(reverse=True)", "- for j in range(K):", "- print((L[j]))", "+ for i in range(K):", "+ print((L[i]))" ]
false
0.038673
0.062738
0.616417
[ "s394030431", "s462630934" ]
u620084012
p03127
python
s860449207
s044891876
76
62
14,480
20,284
Accepted
Accepted
18.42
import sys def input(): return sys.stdin.readline()[:-1] def gcd(a,b): if b == 0: return a return gcd(b,a%b) def main(): N = int(eval(input())) A = list(map(int,input().split())) ans = A[0] for e in A[1:]: ans = gcd(ans,e) print(ans) if __name__ == '__main__': main()
from math import gcd N = int(eval(input())) A = list(map(int,input().split())) ans = A[0] for e in A: ans = gcd(e,ans) print(ans)
17
7
331
134
import sys def input(): return sys.stdin.readline()[:-1] def gcd(a, b): if b == 0: return a return gcd(b, a % b) def main(): N = int(eval(input())) A = list(map(int, input().split())) ans = A[0] for e in A[1:]: ans = gcd(ans, e) print(ans) if __name__ == "__main__": main()
from math import gcd N = int(eval(input())) A = list(map(int, input().split())) ans = A[0] for e in A: ans = gcd(e, ans) print(ans)
false
58.823529
[ "-import sys", "+from math import gcd", "-", "-def input():", "- return sys.stdin.readline()[:-1]", "-", "-", "-def gcd(a, b):", "- if b == 0:", "- return a", "- return gcd(b, a % b)", "-", "-", "-def main():", "- N = int(eval(input()))", "- A = list(map(int, input().split()))", "- ans = A[0]", "- for e in A[1:]:", "- ans = gcd(ans, e)", "- print(ans)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+N = int(eval(input()))", "+A = list(map(int, input().split()))", "+ans = A[0]", "+for e in A:", "+ ans = gcd(e, ans)", "+print(ans)" ]
false
0.042953
0.041488
1.035305
[ "s860449207", "s044891876" ]
u086566114
p02264
python
s785916375
s675014642
890
670
44,228
44,340
Accepted
Accepted
24.72
class MyQueue(object): """ My Queue class Attributes: queue: queue head tail """ def __init__(self): """Constructor """ self.length = 100010 self.queue = [] counter = 0 while counter < self.length: self.queue.append(Process()) counter += 1 self.head = 0 self.tail = 0 def enqueue(self, name, time): """enqueue method Args: name: enqueued process name time: enqueued process time Returns: None """ if self.is_full(): print("[ERROR] Queue Overflow") else: self.queue[self.tail % self.length].name = name self.queue[self.tail % self.length].time = time self.tail += 1 def dequeue(self): """dequeue method Returns: None """ if self.is_empty(): print("[ERROR] Queue Underflow") else: self.queue[self.head % self.length].name = "" self.queue[self.head % self.length].time = 0 self.head += 1 def is_empty(self): """check queue is empty or not Returns: Bool """ if self.head == self.tail: return True else: return False def is_full(self): """chech whether queue is full or not""" if self.tail - self.head >= len(self.queue): return True else: return False class Process(object): """process class """ def __init__(self, name="", time=0): """constructor Args: name: name time: time """ self.name = name self.time = time def forward_time(self, time): """time forward method Args: time: forward time interval Returns: remain time """ self.time -= time return self.time def time_forward(my_queue, interval, current_time): """ Args: my_queue: queue interval: time step interval current_time: current time """ value = my_queue.queue[my_queue.head % my_queue.length].forward_time(interval) if value <= 0: current_time += (interval + value) print my_queue.queue[my_queue.head % my_queue.length].name, current_time my_queue.dequeue() # elif value == 0: # current_time += interval # print my_queue.queue[my_queue.head % my_queue.length].name, current_time # my_queue.dequeue() elif value > 0: current_time += interval name, time = my_queue.queue[my_queue.head % my_queue.length].name, \ my_queue.queue[my_queue.head % my_queue.length].time my_queue.dequeue() my_queue.enqueue(name, time) return current_time my_queue = MyQueue() n, q = [int(x) for x in raw_input().split()] counter = 0 while counter < n: name, time = raw_input().split() my_queue.enqueue(name, int(time)) counter += 1 current_time = 0 while not my_queue.is_empty(): current_time = time_forward(my_queue, q, current_time)
class MyQueue(object): """ My Queue class Attributes: queue: queue head tail """ def __init__(self): """Constructor """ self.length = 100010 self.queue = [] counter = 0 while counter < self.length: self.queue.append(Process()) counter += 1 self.head = 0 self.tail = 0 def enqueue(self, name, time): """enqueue method Args: name: enqueued process name time: enqueued process time Returns: None """ # if self.is_full(): # print("[ERROR] Queue Overflow") # else: self.queue[self.tail].name = name self.queue[self.tail].time = time self.tail = (self.tail + 1) % self.length def dequeue(self): """dequeue method Returns: None """ # if self.is_empty(): # print("[ERROR] Queue Underflow") # else: self.queue[self.head].name = "" self.queue[self.head].time = 0 self.head = (self.head + 1) % self.length def is_empty(self): """check queue is empty or not Returns: Bool """ if self.head == self.tail: return True else: return False def is_full(self): """chech whether queue is full or not""" if self.tail - self.head >= len(self.queue): return True else: return False class Process(object): """process class """ def __init__(self, name="", time=0): """constructor Args: name: name time: time """ self.name = name self.time = time def forward_time(self, time): """time forward method Args: time: forward time interval Returns: remain time """ self.time -= time return self.time def time_forward(my_queue, interval, current_time): """ Args: my_queue: queue interval: time step interval current_time: current time """ value = my_queue.queue[my_queue.head].forward_time(interval) if value <= 0: current_time += (interval + value) print my_queue.queue[my_queue.head].name, current_time my_queue.dequeue() elif value > 0: current_time += interval name, time = my_queue.queue[my_queue.head].name, \ my_queue.queue[my_queue.head].time my_queue.dequeue() my_queue.enqueue(name, time) return current_time my_queue = MyQueue() n, q = [int(x) for x in raw_input().split()] counter = 0 while counter < n: name, time = raw_input().split() my_queue.enqueue(name, int(time)) counter += 1 current_time = 0 while not my_queue.is_empty(): current_time = time_forward(my_queue, q, current_time)
140
134
3,364
3,100
class MyQueue(object): """ My Queue class Attributes: queue: queue head tail """ def __init__(self): """Constructor """ self.length = 100010 self.queue = [] counter = 0 while counter < self.length: self.queue.append(Process()) counter += 1 self.head = 0 self.tail = 0 def enqueue(self, name, time): """enqueue method Args: name: enqueued process name time: enqueued process time Returns: None """ if self.is_full(): print("[ERROR] Queue Overflow") else: self.queue[self.tail % self.length].name = name self.queue[self.tail % self.length].time = time self.tail += 1 def dequeue(self): """dequeue method Returns: None """ if self.is_empty(): print("[ERROR] Queue Underflow") else: self.queue[self.head % self.length].name = "" self.queue[self.head % self.length].time = 0 self.head += 1 def is_empty(self): """check queue is empty or not Returns: Bool """ if self.head == self.tail: return True else: return False def is_full(self): """chech whether queue is full or not""" if self.tail - self.head >= len(self.queue): return True else: return False class Process(object): """process class """ def __init__(self, name="", time=0): """constructor Args: name: name time: time """ self.name = name self.time = time def forward_time(self, time): """time forward method Args: time: forward time interval Returns: remain time """ self.time -= time return self.time def time_forward(my_queue, interval, current_time): """ Args: my_queue: queue interval: time step interval current_time: current time """ value = my_queue.queue[my_queue.head % my_queue.length].forward_time(interval) if value <= 0: current_time += (interval + value) print my_queue.queue[my_queue.head % my_queue.length].name, current_time my_queue.dequeue() # elif value == 0: # current_time += interval # print my_queue.queue[my_queue.head % my_queue.length].name, current_time # my_queue.dequeue() elif value > 0: current_time += interval name, time = my_queue.queue[my_queue.head % my_queue.length].name, \ my_queue.queue[my_queue.head % my_queue.length].time my_queue.dequeue() my_queue.enqueue(name, time) return current_time my_queue = MyQueue() n, q = [int(x) for x in raw_input().split()] counter = 0 while counter < n: name, time = raw_input().split() my_queue.enqueue(name, int(time)) counter += 1 current_time = 0 while not my_queue.is_empty(): current_time = time_forward(my_queue, q, current_time)
class MyQueue(object): """ My Queue class Attributes: queue: queue head tail """ def __init__(self): """Constructor """ self.length = 100010 self.queue = [] counter = 0 while counter < self.length: self.queue.append(Process()) counter += 1 self.head = 0 self.tail = 0 def enqueue(self, name, time): """enqueue method Args: name: enqueued process name time: enqueued process time Returns: None """ # if self.is_full(): # print("[ERROR] Queue Overflow") # else: self.queue[self.tail].name = name self.queue[self.tail].time = time self.tail = (self.tail + 1) % self.length def dequeue(self): """dequeue method Returns: None """ # if self.is_empty(): # print("[ERROR] Queue Underflow") # else: self.queue[self.head].name = "" self.queue[self.head].time = 0 self.head = (self.head + 1) % self.length def is_empty(self): """check queue is empty or not Returns: Bool """ if self.head == self.tail: return True else: return False def is_full(self): """chech whether queue is full or not""" if self.tail - self.head >= len(self.queue): return True else: return False class Process(object): """process class """ def __init__(self, name="", time=0): """constructor Args: name: name time: time """ self.name = name self.time = time def forward_time(self, time): """time forward method Args: time: forward time interval Returns: remain time """ self.time -= time return self.time def time_forward(my_queue, interval, current_time): """ Args: my_queue: queue interval: time step interval current_time: current time """ value = my_queue.queue[my_queue.head].forward_time(interval) if value <= 0: current_time += (interval + value) print my_queue.queue[my_queue.head].name, current_time my_queue.dequeue() elif value > 0: current_time += interval name, time = my_queue.queue[my_queue.head].name, \ my_queue.queue[my_queue.head].time my_queue.dequeue() my_queue.enqueue(name, time) return current_time my_queue = MyQueue() n, q = [int(x) for x in raw_input().split()] counter = 0 while counter < n: name, time = raw_input().split() my_queue.enqueue(name, int(time)) counter += 1 current_time = 0 while not my_queue.is_empty(): current_time = time_forward(my_queue, q, current_time)
false
4.285714
[ "- if self.is_full():", "- print(\"[ERROR] Queue Overflow\")", "- else:", "- self.queue[self.tail % self.length].name = name", "- self.queue[self.tail % self.length].time = time", "- self.tail += 1", "+ # if self.is_full():", "+ # print(\"[ERROR] Queue Overflow\")", "+ # else:", "+ self.queue[self.tail].name = name", "+ self.queue[self.tail].time = time", "+ self.tail = (self.tail + 1) % self.length", "- if self.is_empty():", "- print(\"[ERROR] Queue Underflow\")", "- else:", "- self.queue[self.head % self.length].name = \"\"", "- self.queue[self.head % self.length].time = 0", "- self.head += 1", "+ # if self.is_empty():", "+ # print(\"[ERROR] Queue Underflow\")", "+ # else:", "+ self.queue[self.head].name = \"\"", "+ self.queue[self.head].time = 0", "+ self.head = (self.head + 1) % self.length", "- value = my_queue.queue[my_queue.head % my_queue.length].forward_time(interval)", "+ value = my_queue.queue[my_queue.head].forward_time(interval)", "- print my_queue.queue[my_queue.head % my_queue.length].name, current_time", "+ print my_queue.queue[my_queue.head].name, current_time", "- # elif value == 0:", "- # current_time += interval", "- # print my_queue.queue[my_queue.head % my_queue.length].name, current_time", "- # my_queue.dequeue()", "- name, time = my_queue.queue[my_queue.head % my_queue.length].name, \\", "- my_queue.queue[my_queue.head % my_queue.length].time", "+ name, time = my_queue.queue[my_queue.head].name, \\", "+ my_queue.queue[my_queue.head].time" ]
false
0.036761
0.073272
0.501704
[ "s785916375", "s675014642" ]
u562935282
p03361
python
s569211049
s533533934
23
19
3,064
3,064
Accepted
Accepted
17.39
h, w = list(map(int, input().split())) s = [] for i in range(h): s += [eval(input())] dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] ans = True for i in range(h): for j in range(w): if (s[i][j] == '#'): found = False for k in range(4): i2 = i + dx[k] j2 = j + dy[k] if (0 <= i2 < h) and (0 <= j2 < w) and (s[i2][j2] == '#'): found = True if not(found): ans = False if ans: print('Yes') else: print('No')
h, w = list(map(int, input().split())) M = [eval(input()) for _ in range(h)] bk = '#' wt = '.' for r in range(h): for c in range(w): if M[r][c] == bk: flg = False for dx, dy in [(-1, 0), (0, -1), (1, 0), (0, 1)]: r2 = r + dy c2 = c + dx if (0 <= r2 < h) and (0 <= c2 < w): if M[r2][c2] == bk: flg = True break if not flg: print('No') exit() print('Yes')
25
21
553
559
h, w = list(map(int, input().split())) s = [] for i in range(h): s += [eval(input())] dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] ans = True for i in range(h): for j in range(w): if s[i][j] == "#": found = False for k in range(4): i2 = i + dx[k] j2 = j + dy[k] if (0 <= i2 < h) and (0 <= j2 < w) and (s[i2][j2] == "#"): found = True if not (found): ans = False if ans: print("Yes") else: print("No")
h, w = list(map(int, input().split())) M = [eval(input()) for _ in range(h)] bk = "#" wt = "." for r in range(h): for c in range(w): if M[r][c] == bk: flg = False for dx, dy in [(-1, 0), (0, -1), (1, 0), (0, 1)]: r2 = r + dy c2 = c + dx if (0 <= r2 < h) and (0 <= c2 < w): if M[r2][c2] == bk: flg = True break if not flg: print("No") exit() print("Yes")
false
16
[ "-s = []", "-for i in range(h):", "- s += [eval(input())]", "-dx = [1, -1, 0, 0]", "-dy = [0, 0, 1, -1]", "-ans = True", "-for i in range(h):", "- for j in range(w):", "- if s[i][j] == \"#\":", "- found = False", "- for k in range(4):", "- i2 = i + dx[k]", "- j2 = j + dy[k]", "- if (0 <= i2 < h) and (0 <= j2 < w) and (s[i2][j2] == \"#\"):", "- found = True", "- if not (found):", "- ans = False", "-if ans:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+M = [eval(input()) for _ in range(h)]", "+bk = \"#\"", "+wt = \".\"", "+for r in range(h):", "+ for c in range(w):", "+ if M[r][c] == bk:", "+ flg = False", "+ for dx, dy in [(-1, 0), (0, -1), (1, 0), (0, 1)]:", "+ r2 = r + dy", "+ c2 = c + dx", "+ if (0 <= r2 < h) and (0 <= c2 < w):", "+ if M[r2][c2] == bk:", "+ flg = True", "+ break", "+ if not flg:", "+ print(\"No\")", "+ exit()", "+print(\"Yes\")" ]
false
0.042666
0.042458
1.00491
[ "s569211049", "s533533934" ]
u466105944
p03778
python
s122059358
s144483205
21
17
3,316
2,940
Accepted
Accepted
19.05
w,a,b = list(map(int,input().split())) ans = max(a,b)-(min(a,b)+w) if ans > 0: print(ans) else: print((0))
w,a,b = list(map(int,input().split())) print((max(max(a,b)-(min(a,b)+w),0)))
7
2
114
69
w, a, b = list(map(int, input().split())) ans = max(a, b) - (min(a, b) + w) if ans > 0: print(ans) else: print((0))
w, a, b = list(map(int, input().split())) print((max(max(a, b) - (min(a, b) + w), 0)))
false
71.428571
[ "-ans = max(a, b) - (min(a, b) + w)", "-if ans > 0:", "- print(ans)", "-else:", "- print((0))", "+print((max(max(a, b) - (min(a, b) + w), 0)))" ]
false
0.038654
0.04481
0.862629
[ "s122059358", "s144483205" ]
u346629192
p03073
python
s192914957
s225733826
138
112
4,852
3,316
Accepted
Accepted
18.84
s = eval(input()) N = len(s) left_white=[] for i in range(N): if (i%2) == 0: left_white.append(1) else: left_white.append(0) left_black=[] for i in range(N): if (i%2) == 0: left_black.append(0) else: left_black.append(1) count_w = 0 for i in range(N): if int(s[i]) != left_white[i]: count_w = count_w+1 count_b = 0 for i in range(N): if int(s[i]) != left_black[i]: count_b += 1 print((min(count_w,count_b)))
s = eval(input()) N = len(s) count_w = 0 for i in range(N): if ((i%2) == 0 and int(s[i]) == 0) or ((i%2) == 1 and int(s[i]) == 1): count_w += 1 count_b = 0 for i in range(N): if ((i%2) == 0 and int(s[i]) == 1) or ((i%2) == 1 and int(s[i]) == 0): count_b += 1 print((min(count_b,count_w)))
23
11
493
314
s = eval(input()) N = len(s) left_white = [] for i in range(N): if (i % 2) == 0: left_white.append(1) else: left_white.append(0) left_black = [] for i in range(N): if (i % 2) == 0: left_black.append(0) else: left_black.append(1) count_w = 0 for i in range(N): if int(s[i]) != left_white[i]: count_w = count_w + 1 count_b = 0 for i in range(N): if int(s[i]) != left_black[i]: count_b += 1 print((min(count_w, count_b)))
s = eval(input()) N = len(s) count_w = 0 for i in range(N): if ((i % 2) == 0 and int(s[i]) == 0) or ((i % 2) == 1 and int(s[i]) == 1): count_w += 1 count_b = 0 for i in range(N): if ((i % 2) == 0 and int(s[i]) == 1) or ((i % 2) == 1 and int(s[i]) == 0): count_b += 1 print((min(count_b, count_w)))
false
52.173913
[ "-left_white = []", "-for i in range(N):", "- if (i % 2) == 0:", "- left_white.append(1)", "- else:", "- left_white.append(0)", "-left_black = []", "-for i in range(N):", "- if (i % 2) == 0:", "- left_black.append(0)", "- else:", "- left_black.append(1)", "- if int(s[i]) != left_white[i]:", "- count_w = count_w + 1", "+ if ((i % 2) == 0 and int(s[i]) == 0) or ((i % 2) == 1 and int(s[i]) == 1):", "+ count_w += 1", "- if int(s[i]) != left_black[i]:", "+ if ((i % 2) == 0 and int(s[i]) == 1) or ((i % 2) == 1 and int(s[i]) == 0):", "-print((min(count_w, count_b)))", "+print((min(count_b, count_w)))" ]
false
0.047489
0.044438
1.068673
[ "s192914957", "s225733826" ]
u575431498
p03329
python
s283628852
s046765888
917
377
4,308
3,828
Accepted
Accepted
58.89
from math import log N = int(eval(input())) hiki9 = [] hiki6 = [] n = int(log(N) / log(9) + 1) # log9ใฎ่จˆ็ฎ—ใซ่ชคๅทฎใŒใ‚ใ‚‹ใฎใงไธ€ใคๅคšใ‚ใซๅ–ใฃใฆใŠใ for i in range(n+1): hiki9.append(9**i) n = int(log(N) / log(6) + 1) for i in range(n+1): hiki6.append(6**i) hiki9.sort(reverse=True) hiki6.sort(reverse=True) x = [] for i in range(N+1): n9 = i tmpx = 0 for h in hiki9: while h <= n9: n9 -= h tmpx += 1 n6 = N - i for h in hiki6: while h <= n6: n6 -= h tmpx += 1 x.append(tmpx) x.sort() print((x[0]))
N = int(eval(input())) koho = [1] i=1 while True: if i > 1e6: break i *= 6 koho.append(i) i=1 while True: if i > 1e6: break i *= 9 koho.append(i) dp = [0] * (N+1) for i in range(1, N+1): tmp = [] for k in koho: if k > i: continue tmp.append(dp[i - k] + 1) dp[i] = min(tmp) print((dp[N]))
29
24
590
383
from math import log N = int(eval(input())) hiki9 = [] hiki6 = [] n = int(log(N) / log(9) + 1) # log9ใฎ่จˆ็ฎ—ใซ่ชคๅทฎใŒใ‚ใ‚‹ใฎใงไธ€ใคๅคšใ‚ใซๅ–ใฃใฆใŠใ for i in range(n + 1): hiki9.append(9**i) n = int(log(N) / log(6) + 1) for i in range(n + 1): hiki6.append(6**i) hiki9.sort(reverse=True) hiki6.sort(reverse=True) x = [] for i in range(N + 1): n9 = i tmpx = 0 for h in hiki9: while h <= n9: n9 -= h tmpx += 1 n6 = N - i for h in hiki6: while h <= n6: n6 -= h tmpx += 1 x.append(tmpx) x.sort() print((x[0]))
N = int(eval(input())) koho = [1] i = 1 while True: if i > 1e6: break i *= 6 koho.append(i) i = 1 while True: if i > 1e6: break i *= 9 koho.append(i) dp = [0] * (N + 1) for i in range(1, N + 1): tmp = [] for k in koho: if k > i: continue tmp.append(dp[i - k] + 1) dp[i] = min(tmp) print((dp[N]))
false
17.241379
[ "-from math import log", "-", "-hiki9 = []", "-hiki6 = []", "-n = int(log(N) / log(9) + 1) # log9ใฎ่จˆ็ฎ—ใซ่ชคๅทฎใŒใ‚ใ‚‹ใฎใงไธ€ใคๅคšใ‚ใซๅ–ใฃใฆใŠใ", "-for i in range(n + 1):", "- hiki9.append(9**i)", "-n = int(log(N) / log(6) + 1)", "-for i in range(n + 1):", "- hiki6.append(6**i)", "-hiki9.sort(reverse=True)", "-hiki6.sort(reverse=True)", "-x = []", "-for i in range(N + 1):", "- n9 = i", "- tmpx = 0", "- for h in hiki9:", "- while h <= n9:", "- n9 -= h", "- tmpx += 1", "- n6 = N - i", "- for h in hiki6:", "- while h <= n6:", "- n6 -= h", "- tmpx += 1", "- x.append(tmpx)", "-x.sort()", "-print((x[0]))", "+koho = [1]", "+i = 1", "+while True:", "+ if i > 1e6:", "+ break", "+ i *= 6", "+ koho.append(i)", "+i = 1", "+while True:", "+ if i > 1e6:", "+ break", "+ i *= 9", "+ koho.append(i)", "+dp = [0] * (N + 1)", "+for i in range(1, N + 1):", "+ tmp = []", "+ for k in koho:", "+ if k > i:", "+ continue", "+ tmp.append(dp[i - k] + 1)", "+ dp[i] = min(tmp)", "+print((dp[N]))" ]
false
0.135164
0.072244
1.870925
[ "s283628852", "s046765888" ]
u170201762
p03380
python
s705249551
s917885186
94
86
14,428
14,052
Accepted
Accepted
8.51
n = int(eval(input())) l = list(map(int,input().split())) l.sort() a = l[-1] j = 0 while l[j] < int((a+1)/2): j += 1 else: if l[j] - int((a+1)/2) < int((a+1)/2) - l[j-1]: b = l[j] else: b = l[j-1] print(("{} {}".format(a,b)))
N = int(eval(input())) a = list(map(int,input().split())) a.sort() n = a[-1] for i in range(N): if a[i]>=n/2: break if n-a[i]>min(a[i-1],n-a[i-1]): r = a[i] else: r = a[i-1] print(('{} {}'.format(n,r)))
13
13
257
227
n = int(eval(input())) l = list(map(int, input().split())) l.sort() a = l[-1] j = 0 while l[j] < int((a + 1) / 2): j += 1 else: if l[j] - int((a + 1) / 2) < int((a + 1) / 2) - l[j - 1]: b = l[j] else: b = l[j - 1] print(("{} {}".format(a, b)))
N = int(eval(input())) a = list(map(int, input().split())) a.sort() n = a[-1] for i in range(N): if a[i] >= n / 2: break if n - a[i] > min(a[i - 1], n - a[i - 1]): r = a[i] else: r = a[i - 1] print(("{} {}".format(n, r)))
false
0
[ "-n = int(eval(input()))", "-l = list(map(int, input().split()))", "-l.sort()", "-a = l[-1]", "-j = 0", "-while l[j] < int((a + 1) / 2):", "- j += 1", "+N = int(eval(input()))", "+a = list(map(int, input().split()))", "+a.sort()", "+n = a[-1]", "+for i in range(N):", "+ if a[i] >= n / 2:", "+ break", "+if n - a[i] > min(a[i - 1], n - a[i - 1]):", "+ r = a[i]", "- if l[j] - int((a + 1) / 2) < int((a + 1) / 2) - l[j - 1]:", "- b = l[j]", "- else:", "- b = l[j - 1]", "-print((\"{} {}\".format(a, b)))", "+ r = a[i - 1]", "+print((\"{} {}\".format(n, r)))" ]
false
0.202631
0.068454
2.960111
[ "s705249551", "s917885186" ]
u186838327
p03283
python
s896474065
s869763188
1,653
622
16,740
79,924
Accepted
Accepted
62.37
n, m, q = list(map(int, input().split())) x = [[0]*n for _ in range(n)] for i in range(m): l, r = list(map(int, input().split())) l, r = l-1, r-1 x[l][r] += 1 s = [[0]*(n+1) for _ in range(n+1)] for i in range(n): for j in range(n): s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j] + x[i][j] for _ in range(q): a, b = list(map(int, input().split())) a, b = a-1, b-1 print((s[b+1][b+1] - s[b+1][a] - s[a][b+1] + s[a][a]))
n, m, q = list(map(int, input().split())) A = [[0]*n for i in range(n)] for i in range(m): l, r = list(map(int, input().split())) l, r = l-1, r-1 A[l][r] += 1 #print(A) s = [[0]*(n+1) for _ in range(n+1)] for i in range(n): for j in range(n): s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j] + A[i][j] #print(s) for i in range(q): p, q = list(map(int, input().split())) p, q = p-1, q-1 ans = s[q+1][q+1] - s[p][q+1] - s[q+1][p] + s[p][p] print(ans)
18
23
438
490
n, m, q = list(map(int, input().split())) x = [[0] * n for _ in range(n)] for i in range(m): l, r = list(map(int, input().split())) l, r = l - 1, r - 1 x[l][r] += 1 s = [[0] * (n + 1) for _ in range(n + 1)] for i in range(n): for j in range(n): s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + x[i][j] for _ in range(q): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 print((s[b + 1][b + 1] - s[b + 1][a] - s[a][b + 1] + s[a][a]))
n, m, q = list(map(int, input().split())) A = [[0] * n for i in range(n)] for i in range(m): l, r = list(map(int, input().split())) l, r = l - 1, r - 1 A[l][r] += 1 # print(A) s = [[0] * (n + 1) for _ in range(n + 1)] for i in range(n): for j in range(n): s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + A[i][j] # print(s) for i in range(q): p, q = list(map(int, input().split())) p, q = p - 1, q - 1 ans = s[q + 1][q + 1] - s[p][q + 1] - s[q + 1][p] + s[p][p] print(ans)
false
21.73913
[ "-x = [[0] * n for _ in range(n)]", "+A = [[0] * n for i in range(n)]", "- x[l][r] += 1", "+ A[l][r] += 1", "+# print(A)", "- s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + x[i][j]", "-for _ in range(q):", "- a, b = list(map(int, input().split()))", "- a, b = a - 1, b - 1", "- print((s[b + 1][b + 1] - s[b + 1][a] - s[a][b + 1] + s[a][a]))", "+ s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + A[i][j]", "+# print(s)", "+for i in range(q):", "+ p, q = list(map(int, input().split()))", "+ p, q = p - 1, q - 1", "+ ans = s[q + 1][q + 1] - s[p][q + 1] - s[q + 1][p] + s[p][p]", "+ print(ans)" ]
false
0.047111
0.038225
1.232446
[ "s896474065", "s869763188" ]
u010110540
p03565
python
s213560236
s586056678
21
17
3,188
3,064
Accepted
Accepted
19.05
import re def solve(s, t): s = s.replace('?', '.') ls, lt = len(s), len(t) if ls < lt: return 'UNRESTORABLE' ans = [] for i in range(ls - lt + 1): m = re.match(s[i:i+lt], t) if m is None: continue ans.append( (s[:i] + t + s[i+lt:]).replace('.', 'a') ) if not ans: return 'UNRESTORABLE' return min(ans) S = eval(input()) T = eval(input()) print((solve(S, T)))
Sd = eval(input()) T = eval(input()) def check(A, B): for a, b in zip(A, B): if a != '?' and a != b: return False return True for i in range(len(Sd) - len(T) + 1)[::-1]: if check(Sd[i:i + len(T)], T): print(((Sd[:i] + T + Sd[i + len(T):]).replace('?', 'a'))) break else: print('UNRESTORABLE')
24
15
472
346
import re def solve(s, t): s = s.replace("?", ".") ls, lt = len(s), len(t) if ls < lt: return "UNRESTORABLE" ans = [] for i in range(ls - lt + 1): m = re.match(s[i : i + lt], t) if m is None: continue ans.append((s[:i] + t + s[i + lt :]).replace(".", "a")) if not ans: return "UNRESTORABLE" return min(ans) S = eval(input()) T = eval(input()) print((solve(S, T)))
Sd = eval(input()) T = eval(input()) def check(A, B): for a, b in zip(A, B): if a != "?" and a != b: return False return True for i in range(len(Sd) - len(T) + 1)[::-1]: if check(Sd[i : i + len(T)], T): print(((Sd[:i] + T + Sd[i + len(T) :]).replace("?", "a"))) break else: print("UNRESTORABLE")
false
37.5
[ "-import re", "+Sd = eval(input())", "+T = eval(input())", "-def solve(s, t):", "- s = s.replace(\"?\", \".\")", "- ls, lt = len(s), len(t)", "- if ls < lt:", "- return \"UNRESTORABLE\"", "- ans = []", "- for i in range(ls - lt + 1):", "- m = re.match(s[i : i + lt], t)", "- if m is None:", "- continue", "- ans.append((s[:i] + t + s[i + lt :]).replace(\".\", \"a\"))", "- if not ans:", "- return \"UNRESTORABLE\"", "- return min(ans)", "+def check(A, B):", "+ for a, b in zip(A, B):", "+ if a != \"?\" and a != b:", "+ return False", "+ return True", "-S = eval(input())", "-T = eval(input())", "-print((solve(S, T)))", "+for i in range(len(Sd) - len(T) + 1)[::-1]:", "+ if check(Sd[i : i + len(T)], T):", "+ print(((Sd[:i] + T + Sd[i + len(T) :]).replace(\"?\", \"a\")))", "+ break", "+else:", "+ print(\"UNRESTORABLE\")" ]
false
0.036843
0.03788
0.972628
[ "s213560236", "s586056678" ]
u017810624
p02960
python
s927749588
s717162300
798
579
66,876
67,348
Accepted
Accepted
27.44
s=list(eval(input())) n=len(s) s.reverse() mod=10**9+7 dp=[[0]*13 for i in range(n+1)] dp[0][0]=1 x=1 for i in range(n): for j in range(13): if s[i]=='?': for k in range(10): dp[i+1][j]+=dp[i][(j-(k*x)%13+13)%13] else: dp[i+1][j]+=dp[i][(j-(int(s[i])*x)%13+13)%13] dp[i+1][j]%=mod x*=10 x%=13 print((dp[n][5]))
s=list(eval(input())) n=len(s) s.reverse() mod=10**9+7 dp=[[0]*13 for i in range(n+1)] dp[0][0]=1 x=1 for i in range(n): for j in range(13): if s[i]=='?': for k in range(10): dp[i+1][j]+=dp[i][(j-k*x)%13] else: dp[i+1][j]+=dp[i][(j-int(s[i])*x)%13] dp[i+1][j]%=mod x*=10 x%=13 print((dp[n][5]))
18
18
357
341
s = list(eval(input())) n = len(s) s.reverse() mod = 10**9 + 7 dp = [[0] * 13 for i in range(n + 1)] dp[0][0] = 1 x = 1 for i in range(n): for j in range(13): if s[i] == "?": for k in range(10): dp[i + 1][j] += dp[i][(j - (k * x) % 13 + 13) % 13] else: dp[i + 1][j] += dp[i][(j - (int(s[i]) * x) % 13 + 13) % 13] dp[i + 1][j] %= mod x *= 10 x %= 13 print((dp[n][5]))
s = list(eval(input())) n = len(s) s.reverse() mod = 10**9 + 7 dp = [[0] * 13 for i in range(n + 1)] dp[0][0] = 1 x = 1 for i in range(n): for j in range(13): if s[i] == "?": for k in range(10): dp[i + 1][j] += dp[i][(j - k * x) % 13] else: dp[i + 1][j] += dp[i][(j - int(s[i]) * x) % 13] dp[i + 1][j] %= mod x *= 10 x %= 13 print((dp[n][5]))
false
0
[ "- dp[i + 1][j] += dp[i][(j - (k * x) % 13 + 13) % 13]", "+ dp[i + 1][j] += dp[i][(j - k * x) % 13]", "- dp[i + 1][j] += dp[i][(j - (int(s[i]) * x) % 13 + 13) % 13]", "+ dp[i + 1][j] += dp[i][(j - int(s[i]) * x) % 13]" ]
false
0.043685
0.037099
1.177529
[ "s927749588", "s717162300" ]
u113971909
p03160
python
s888845858
s296204588
152
138
13,980
14,012
Accepted
Accepted
9.21
N = int(eval(input())) H = list(map(int,input().split())) DP = [0]*(N+1) #DP[i]ใซๆฅใ‚‹ใŸใ‚ใฎๆœ€ๅฐใ‚ณใ‚นใƒˆ def dH(i,j): return abs(H[i-1] - H[j-1]) DP[2] = dH(1,2) for i in range(3,N+1): DP[i] = min( DP[i-2] + dH(i-2, i) , DP[i-1] + dH(i-1, i) ) print((DP[N]))
#!/usr/bin/env python3 # -*- coding:utf-8 -*- import sys def main(): input = sys.stdin.readline N = int(eval(input())) H = list(map(int, input().split())) def cost(i, jp): return abs(H[i-1] - H[i+jp-1]) dp = [0]*(N+1) dp[2] = cost(1, 1) for i in range(3,N+1): dp[i] = min(dp[i-1]+cost(i-1, 1),dp[i-2]+cost(i-2, 2)) print((dp[N])) if __name__=='__main__': main()
9
20
249
429
N = int(eval(input())) H = list(map(int, input().split())) DP = [0] * (N + 1) # DP[i]ใซๆฅใ‚‹ใŸใ‚ใฎๆœ€ๅฐใ‚ณใ‚นใƒˆ def dH(i, j): return abs(H[i - 1] - H[j - 1]) DP[2] = dH(1, 2) for i in range(3, N + 1): DP[i] = min(DP[i - 2] + dH(i - 2, i), DP[i - 1] + dH(i - 1, i)) print((DP[N]))
#!/usr/bin/env python3 # -*- coding:utf-8 -*- import sys def main(): input = sys.stdin.readline N = int(eval(input())) H = list(map(int, input().split())) def cost(i, jp): return abs(H[i - 1] - H[i + jp - 1]) dp = [0] * (N + 1) dp[2] = cost(1, 1) for i in range(3, N + 1): dp[i] = min(dp[i - 1] + cost(i - 1, 1), dp[i - 2] + cost(i - 2, 2)) print((dp[N])) if __name__ == "__main__": main()
false
55
[ "-N = int(eval(input()))", "-H = list(map(int, input().split()))", "-DP = [0] * (N + 1) # DP[i]ใซๆฅใ‚‹ใŸใ‚ใฎๆœ€ๅฐใ‚ณใ‚นใƒˆ", "+#!/usr/bin/env python3", "+# -*- coding:utf-8 -*-", "+import sys", "-def dH(i, j):", "- return abs(H[i - 1] - H[j - 1])", "+def main():", "+ input = sys.stdin.readline", "+ N = int(eval(input()))", "+ H = list(map(int, input().split()))", "+", "+ def cost(i, jp):", "+ return abs(H[i - 1] - H[i + jp - 1])", "+", "+ dp = [0] * (N + 1)", "+ dp[2] = cost(1, 1)", "+ for i in range(3, N + 1):", "+ dp[i] = min(dp[i - 1] + cost(i - 1, 1), dp[i - 2] + cost(i - 2, 2))", "+ print((dp[N]))", "-DP[2] = dH(1, 2)", "-for i in range(3, N + 1):", "- DP[i] = min(DP[i - 2] + dH(i - 2, i), DP[i - 1] + dH(i - 1, i))", "-print((DP[N]))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.036431
0.034907
1.043649
[ "s888845858", "s296204588" ]
u489959379
p03958
python
s333924641
s813519666
380
19
41,068
3,060
Accepted
Accepted
95
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): k, t = list(map(int, input().split())) A = list(map(int, input().split())) B = [] for i in range(t): B.append([i + 1, A[i]]) B = sorted(B, key=lambda x: x[1]) if t == 1: print((k - 1)) exit() res = 0 pre = 0 for i in range(k): if pre != B[-1][0]: pre = B[-1][0] B[-1][1] -= 1 B = sorted(B, key=lambda x: x[1]) else: if B[-2][1] != 0: pre = B[-2][0] B[-2][1] -= 1 B = sorted(B, key=lambda x: x[1]) else: B[-1][1] -= 1 res += 1 print(res) if __name__ == '__main__': resolve()
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): k, t = list(map(int, input().split())) A = list(map(int, input().split())) etc = sum(A) - max(A) res = max(0, max(A) - 1 - etc) print(res) if __name__ == '__main__': resolve()
40
18
833
339
import sys sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 def resolve(): k, t = list(map(int, input().split())) A = list(map(int, input().split())) B = [] for i in range(t): B.append([i + 1, A[i]]) B = sorted(B, key=lambda x: x[1]) if t == 1: print((k - 1)) exit() res = 0 pre = 0 for i in range(k): if pre != B[-1][0]: pre = B[-1][0] B[-1][1] -= 1 B = sorted(B, key=lambda x: x[1]) else: if B[-2][1] != 0: pre = B[-2][0] B[-2][1] -= 1 B = sorted(B, key=lambda x: x[1]) else: B[-1][1] -= 1 res += 1 print(res) if __name__ == "__main__": resolve()
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): k, t = list(map(int, input().split())) A = list(map(int, input().split())) etc = sum(A) - max(A) res = max(0, max(A) - 1 - etc) print(res) if __name__ == "__main__": resolve()
false
55
[ "+input = sys.stdin.readline", "- B = []", "- for i in range(t):", "- B.append([i + 1, A[i]])", "- B = sorted(B, key=lambda x: x[1])", "- if t == 1:", "- print((k - 1))", "- exit()", "- res = 0", "- pre = 0", "- for i in range(k):", "- if pre != B[-1][0]:", "- pre = B[-1][0]", "- B[-1][1] -= 1", "- B = sorted(B, key=lambda x: x[1])", "- else:", "- if B[-2][1] != 0:", "- pre = B[-2][0]", "- B[-2][1] -= 1", "- B = sorted(B, key=lambda x: x[1])", "- else:", "- B[-1][1] -= 1", "- res += 1", "+ etc = sum(A) - max(A)", "+ res = max(0, max(A) - 1 - etc)" ]
false
0.130527
0.034238
3.812329
[ "s333924641", "s813519666" ]
u606045429
p03240
python
s540932117
s916133580
67
32
3,064
3,064
Accepted
Accepted
52.24
N = int(eval(input())) L = [tuple(map(int, input().split())) for _ in range(N)] def get_H(Cx, Cy): for x, y, h in L: if h == 0: continue H = h + abs(x - Cx) + abs(y - Cy) if H >= 1: return H def check(Cx, Cy, H): for x, y, h in L: if h != max(H - abs(x - Cx) - abs(y - Cy), 0): return False return True for Cx in range(101): for Cy in range(101): H = get_H(Cx, Cy) if check(Cx, Cy, H): print((Cx, Cy, H)) quit()
N = int(eval(input())) L = [tuple(map(int, input().split())) for _ in range(N)] xx, yy, hh = next(l for l in L if l[2] >= 1) for Cx in range(101): for Cy in range(101): H = hh + abs(xx - Cx) + abs(yy - Cy) for x, y, h in L: if h != max(H - abs(x - Cx) - abs(y - Cy), 0): break else: print((Cx, Cy, H)) quit()
23
13
553
393
N = int(eval(input())) L = [tuple(map(int, input().split())) for _ in range(N)] def get_H(Cx, Cy): for x, y, h in L: if h == 0: continue H = h + abs(x - Cx) + abs(y - Cy) if H >= 1: return H def check(Cx, Cy, H): for x, y, h in L: if h != max(H - abs(x - Cx) - abs(y - Cy), 0): return False return True for Cx in range(101): for Cy in range(101): H = get_H(Cx, Cy) if check(Cx, Cy, H): print((Cx, Cy, H)) quit()
N = int(eval(input())) L = [tuple(map(int, input().split())) for _ in range(N)] xx, yy, hh = next(l for l in L if l[2] >= 1) for Cx in range(101): for Cy in range(101): H = hh + abs(xx - Cx) + abs(yy - Cy) for x, y, h in L: if h != max(H - abs(x - Cx) - abs(y - Cy), 0): break else: print((Cx, Cy, H)) quit()
false
43.478261
[ "-", "-", "-def get_H(Cx, Cy):", "- for x, y, h in L:", "- if h == 0:", "- continue", "- H = h + abs(x - Cx) + abs(y - Cy)", "- if H >= 1:", "- return H", "-", "-", "-def check(Cx, Cy, H):", "- for x, y, h in L:", "- if h != max(H - abs(x - Cx) - abs(y - Cy), 0):", "- return False", "- return True", "-", "-", "+xx, yy, hh = next(l for l in L if l[2] >= 1)", "- H = get_H(Cx, Cy)", "- if check(Cx, Cy, H):", "+ H = hh + abs(xx - Cx) + abs(yy - Cy)", "+ for x, y, h in L:", "+ if h != max(H - abs(x - Cx) - abs(y - Cy), 0):", "+ break", "+ else:" ]
false
0.046633
0.049978
0.933059
[ "s540932117", "s916133580" ]
u348805958
p02774
python
s342817194
s939245676
785
722
97,236
97,364
Accepted
Accepted
8.03
#!python3 iim = lambda: list(map(int, input().rstrip().split())) inf = 10**18 + 1 def cnt_val(a, b, x, cache): ans = 0 la, lb = len(a), len(b) J = (i for i in range(lb)) if a == b else (-1 for i in range(la)) if len(cache) == 0: ca = [x, 0] cb = [inf, lb-1] cache.append(ca) cache.append(cb) else: ca, cb = cache if x <= ca[0]: cache[0], cache[1] = ca, cb = cb, ca ca[0] = x j = cb[1] #for i in range(la): for i, k in enumerate(J): xa = a[i] for j in range(j, k, -1): x1 = b[j] * xa if x1 <= x: break else: break ans += j - k if i == 0: ca[1] = j return ans def resolve(): N, K = iim() A = [[] for i in range(3)] for x in input().split(): x = int(x) if x < 0: i = 0 elif x == 0: i = 1 else: i = 2 A[i].append(x) a0 = len(A[0]) * len(A[2]) s1 = len(A[1]) a1 = s1 * (2*N - s1 -1) // 2 K1 = K - 1 if a0 < K1 < a0 + a1: print((0)) return if K1 < a0: A[0].sort() A[2].sort(reverse=True) #print(A[0], A[2]) lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1 cache1 = [] #print((lo, hi), K1) while lo < hi: mid = (lo + hi) // 2 k = cnt_val(A[0], A[2], mid, cache1) #print((lo, hi), mid, k, K1) if k <= K1: lo = mid + 1 else: hi = mid print(lo) return A0 = list([-x for x in A[0]]) A0.sort() A[2].sort() K3 = K - a0 - a1 - 1 #print(A[0], A[2], a0, a1, K3) lo, hi = 0, 10**18 cache1, cache2 = [], [] while lo < hi: mid = (lo + hi) // 2 k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2) #print((lo, hi), k3, K3) if k3 <= K3: lo = mid + 1 else: hi = mid print(lo) if __name__ == "__main__": resolve()
#!python3 iim = lambda: list(map(int, input().rstrip().split())) inf = 10**18 + 1 def cnt_val(a, b, x): ans = 0 la, lb = len(a), len(b) J = (i for i in range(lb)) if a == b else (-1 for i in range(la)) j = lb - 1 for i, k in enumerate(J): xa = a[i] for j in range(j, k, -1): x1 = b[j] * xa if x1 <= x: break else: break ans += j - k return ans def resolve(): N, K = iim() A = [[] for i in range(3)] for x in input().split(): x = int(x) if x < 0: i = 0 elif x == 0: i = 1 else: i = 2 A[i].append(x) a0 = len(A[0]) * len(A[2]) s1 = len(A[1]) a1 = s1 * (2*N - s1 -1) // 2 K1 = K - 1 if a0 < K1 < a0 + a1: print((0)) return if K1 < a0: A[0].sort() A[2].sort(reverse=True) #print(A[0], A[2]) lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1 #print((lo, hi), K1) while lo < hi: mid = (lo + hi) // 2 k = cnt_val(A[0], A[2], mid) #print((lo, hi), mid, k, K1) if k <= K1: lo = mid + 1 else: hi = mid print(lo) return A0 = list([-x for x in A[0]]) A0.sort() A[2].sort() K3 = K - a0 - a1 - 1 #print(A[0], A[2], a0, a1, K3) lo, hi = 0, 10**18 while lo < hi: mid = (lo + hi) // 2 k3 = cnt_val(A0, A0, mid) + cnt_val(A[2], A[2], mid) #print((lo, hi), k3, K3) if k3 <= K3: lo = mid + 1 else: hi = mid print(lo) if __name__ == "__main__": resolve()
99
83
2,221
1,818
#!python3 iim = lambda: list(map(int, input().rstrip().split())) inf = 10**18 + 1 def cnt_val(a, b, x, cache): ans = 0 la, lb = len(a), len(b) J = (i for i in range(lb)) if a == b else (-1 for i in range(la)) if len(cache) == 0: ca = [x, 0] cb = [inf, lb - 1] cache.append(ca) cache.append(cb) else: ca, cb = cache if x <= ca[0]: cache[0], cache[1] = ca, cb = cb, ca ca[0] = x j = cb[1] # for i in range(la): for i, k in enumerate(J): xa = a[i] for j in range(j, k, -1): x1 = b[j] * xa if x1 <= x: break else: break ans += j - k if i == 0: ca[1] = j return ans def resolve(): N, K = iim() A = [[] for i in range(3)] for x in input().split(): x = int(x) if x < 0: i = 0 elif x == 0: i = 1 else: i = 2 A[i].append(x) a0 = len(A[0]) * len(A[2]) s1 = len(A[1]) a1 = s1 * (2 * N - s1 - 1) // 2 K1 = K - 1 if a0 < K1 < a0 + a1: print((0)) return if K1 < a0: A[0].sort() A[2].sort(reverse=True) # print(A[0], A[2]) lo, hi = A[0][0] * A[2][0], A[0][-1] * A[2][-1] + 1 cache1 = [] # print((lo, hi), K1) while lo < hi: mid = (lo + hi) // 2 k = cnt_val(A[0], A[2], mid, cache1) # print((lo, hi), mid, k, K1) if k <= K1: lo = mid + 1 else: hi = mid print(lo) return A0 = list([-x for x in A[0]]) A0.sort() A[2].sort() K3 = K - a0 - a1 - 1 # print(A[0], A[2], a0, a1, K3) lo, hi = 0, 10**18 cache1, cache2 = [], [] while lo < hi: mid = (lo + hi) // 2 k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2) # print((lo, hi), k3, K3) if k3 <= K3: lo = mid + 1 else: hi = mid print(lo) if __name__ == "__main__": resolve()
#!python3 iim = lambda: list(map(int, input().rstrip().split())) inf = 10**18 + 1 def cnt_val(a, b, x): ans = 0 la, lb = len(a), len(b) J = (i for i in range(lb)) if a == b else (-1 for i in range(la)) j = lb - 1 for i, k in enumerate(J): xa = a[i] for j in range(j, k, -1): x1 = b[j] * xa if x1 <= x: break else: break ans += j - k return ans def resolve(): N, K = iim() A = [[] for i in range(3)] for x in input().split(): x = int(x) if x < 0: i = 0 elif x == 0: i = 1 else: i = 2 A[i].append(x) a0 = len(A[0]) * len(A[2]) s1 = len(A[1]) a1 = s1 * (2 * N - s1 - 1) // 2 K1 = K - 1 if a0 < K1 < a0 + a1: print((0)) return if K1 < a0: A[0].sort() A[2].sort(reverse=True) # print(A[0], A[2]) lo, hi = A[0][0] * A[2][0], A[0][-1] * A[2][-1] + 1 # print((lo, hi), K1) while lo < hi: mid = (lo + hi) // 2 k = cnt_val(A[0], A[2], mid) # print((lo, hi), mid, k, K1) if k <= K1: lo = mid + 1 else: hi = mid print(lo) return A0 = list([-x for x in A[0]]) A0.sort() A[2].sort() K3 = K - a0 - a1 - 1 # print(A[0], A[2], a0, a1, K3) lo, hi = 0, 10**18 while lo < hi: mid = (lo + hi) // 2 k3 = cnt_val(A0, A0, mid) + cnt_val(A[2], A[2], mid) # print((lo, hi), k3, K3) if k3 <= K3: lo = mid + 1 else: hi = mid print(lo) if __name__ == "__main__": resolve()
false
16.161616
[ "-def cnt_val(a, b, x, cache):", "+def cnt_val(a, b, x):", "- if len(cache) == 0:", "- ca = [x, 0]", "- cb = [inf, lb - 1]", "- cache.append(ca)", "- cache.append(cb)", "- else:", "- ca, cb = cache", "- if x <= ca[0]:", "- cache[0], cache[1] = ca, cb = cb, ca", "- ca[0] = x", "- j = cb[1]", "- # for i in range(la):", "+ j = lb - 1", "- if i == 0:", "- ca[1] = j", "- cache1 = []", "- k = cnt_val(A[0], A[2], mid, cache1)", "+ k = cnt_val(A[0], A[2], mid)", "- cache1, cache2 = [], []", "- k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)", "+ k3 = cnt_val(A0, A0, mid) + cnt_val(A[2], A[2], mid)" ]
false
0.048118
0.048015
1.002136
[ "s342817194", "s939245676" ]
u936985471
p02973
python
s460287721
s835837902
910
103
7,092
12,724
Accepted
Accepted
88.68
n=int(eval(input())) # ้™้ †ใฎใƒชใ‚นใƒˆใงไบŒๅˆ†ๆŽข็ดข # ่‡ชๅˆ†ใ‚ˆใ‚Šๅฐใ•ใ„ๆ•ฐๅญ—ใงๆœ€ใ‚‚ๅคงใใ„ใ‚‚ใฎใ‚’่‡ชๅˆ†ใงใ‚ขใƒƒใƒ—ใƒ‡ใƒผใƒˆ # ่ฉฒๅฝ“ใŒใชใ‘ใ‚Œใฐๆœ€ๅพŒใซ่ฟฝๅŠ  d=[] d.append(int(eval(input()))) for i in range(n-1): a=int(eval(input())) ok=len(d) ng=-1 while abs(ok-ng)>1: mid=abs(ok+ng)//2 if d[mid]<a: ok=mid else: ng=mid if ok==len(d): d.append(a) else: d[ok]=a print((len(d)))
import sys readline = sys.stdin.readline N = int(readline()) ans = [] import bisect for i in range(N): a = -int(readline()) ind = bisect.bisect_right(ans, a) if ind == len(ans): ans.append(a) else: ans[ind] = a print((len(ans)))
21
15
343
263
n = int(eval(input())) # ้™้ †ใฎใƒชใ‚นใƒˆใงไบŒๅˆ†ๆŽข็ดข # ่‡ชๅˆ†ใ‚ˆใ‚Šๅฐใ•ใ„ๆ•ฐๅญ—ใงๆœ€ใ‚‚ๅคงใใ„ใ‚‚ใฎใ‚’่‡ชๅˆ†ใงใ‚ขใƒƒใƒ—ใƒ‡ใƒผใƒˆ # ่ฉฒๅฝ“ใŒใชใ‘ใ‚Œใฐๆœ€ๅพŒใซ่ฟฝๅŠ  d = [] d.append(int(eval(input()))) for i in range(n - 1): a = int(eval(input())) ok = len(d) ng = -1 while abs(ok - ng) > 1: mid = abs(ok + ng) // 2 if d[mid] < a: ok = mid else: ng = mid if ok == len(d): d.append(a) else: d[ok] = a print((len(d)))
import sys readline = sys.stdin.readline N = int(readline()) ans = [] import bisect for i in range(N): a = -int(readline()) ind = bisect.bisect_right(ans, a) if ind == len(ans): ans.append(a) else: ans[ind] = a print((len(ans)))
false
28.571429
[ "-n = int(eval(input()))", "-# ้™้ †ใฎใƒชใ‚นใƒˆใงไบŒๅˆ†ๆŽข็ดข", "-# ่‡ชๅˆ†ใ‚ˆใ‚Šๅฐใ•ใ„ๆ•ฐๅญ—ใงๆœ€ใ‚‚ๅคงใใ„ใ‚‚ใฎใ‚’่‡ชๅˆ†ใงใ‚ขใƒƒใƒ—ใƒ‡ใƒผใƒˆ", "-# ่ฉฒๅฝ“ใŒใชใ‘ใ‚Œใฐๆœ€ๅพŒใซ่ฟฝๅŠ ", "-d = []", "-d.append(int(eval(input())))", "-for i in range(n - 1):", "- a = int(eval(input()))", "- ok = len(d)", "- ng = -1", "- while abs(ok - ng) > 1:", "- mid = abs(ok + ng) // 2", "- if d[mid] < a:", "- ok = mid", "- else:", "- ng = mid", "- if ok == len(d):", "- d.append(a)", "+import sys", "+", "+readline = sys.stdin.readline", "+N = int(readline())", "+ans = []", "+import bisect", "+", "+for i in range(N):", "+ a = -int(readline())", "+ ind = bisect.bisect_right(ans, a)", "+ if ind == len(ans):", "+ ans.append(a)", "- d[ok] = a", "-print((len(d)))", "+ ans[ind] = a", "+print((len(ans)))" ]
false
0.039641
0.035277
1.123711
[ "s460287721", "s835837902" ]
u298520807
p03495
python
s746494188
s187870777
179
122
36,000
35,868
Accepted
Accepted
31.84
from collections import defaultdict N, K = list(map(int, input().split())) balls = defaultdict(int) for b in input().split(): balls[b] += 1 types = len(list(balls.keys())) balls = sorted(list(balls.values()), reverse=True) ans = 0 while types > K: ans += balls.pop() types -= 1 print(ans)
# ่งฃ่ชฌ็‰ˆ from collections import defaultdict N, K = list(map(int, input().split())) balls = defaultdict(int) for b in input().split(): balls[b] += 1 balls = sorted(balls.values()) print((N - sum(balls[-K:])))
12
9
294
211
from collections import defaultdict N, K = list(map(int, input().split())) balls = defaultdict(int) for b in input().split(): balls[b] += 1 types = len(list(balls.keys())) balls = sorted(list(balls.values()), reverse=True) ans = 0 while types > K: ans += balls.pop() types -= 1 print(ans)
# ่งฃ่ชฌ็‰ˆ from collections import defaultdict N, K = list(map(int, input().split())) balls = defaultdict(int) for b in input().split(): balls[b] += 1 balls = sorted(balls.values()) print((N - sum(balls[-K:])))
false
25
[ "+# ่งฃ่ชฌ็‰ˆ", "-types = len(list(balls.keys()))", "-balls = sorted(list(balls.values()), reverse=True)", "-ans = 0", "-while types > K:", "- ans += balls.pop()", "- types -= 1", "-print(ans)", "+balls = sorted(balls.values())", "+print((N - sum(balls[-K:])))" ]
false
0.031715
0.037836
0.838241
[ "s746494188", "s187870777" ]
u740284863
p03161
python
s790992521
s001023314
394
216
52,448
83,368
Accepted
Accepted
45.18
import sys sys.setrecursionlimit(100000) n,k = list(map(int,input().split())) l = list(map(int,input().split())) A = [0]*(n) if k >= n: k = n for i in range(1,k): A[i] = abs(l[i]-l[0]) for i in range(k,n): tmp = float('Inf') for j in range(1,k+1): dis = A[i-j] + abs(l[i]-l[i-j]) tmp = min(tmp,dis) A[i] = tmp print((A[n-1]))
n,k = list(map(int,input().split())) if n <= k: k = n H = list(map(int,input().split())) dp = [float('inf') for _ in range(n+1)] for i in range(k): dp[i] = abs(H[i] - H[0]) for i in range(k,n): for j in range(k+1): dp[i] = min(dp[i],dp[i-j] + abs(H[i] - H[i-j])) print((dp[-2]))
16
11
376
300
import sys sys.setrecursionlimit(100000) n, k = list(map(int, input().split())) l = list(map(int, input().split())) A = [0] * (n) if k >= n: k = n for i in range(1, k): A[i] = abs(l[i] - l[0]) for i in range(k, n): tmp = float("Inf") for j in range(1, k + 1): dis = A[i - j] + abs(l[i] - l[i - j]) tmp = min(tmp, dis) A[i] = tmp print((A[n - 1]))
n, k = list(map(int, input().split())) if n <= k: k = n H = list(map(int, input().split())) dp = [float("inf") for _ in range(n + 1)] for i in range(k): dp[i] = abs(H[i] - H[0]) for i in range(k, n): for j in range(k + 1): dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j])) print((dp[-2]))
false
31.25
[ "-import sys", "-", "-sys.setrecursionlimit(100000)", "-l = list(map(int, input().split()))", "-A = [0] * (n)", "-if k >= n:", "+if n <= k:", "-for i in range(1, k):", "- A[i] = abs(l[i] - l[0])", "+H = list(map(int, input().split()))", "+dp = [float(\"inf\") for _ in range(n + 1)]", "+for i in range(k):", "+ dp[i] = abs(H[i] - H[0])", "- tmp = float(\"Inf\")", "- for j in range(1, k + 1):", "- dis = A[i - j] + abs(l[i] - l[i - j])", "- tmp = min(tmp, dis)", "- A[i] = tmp", "-print((A[n - 1]))", "+ for j in range(k + 1):", "+ dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))", "+print((dp[-2]))" ]
false
0.038451
0.039449
0.974712
[ "s790992521", "s001023314" ]
u753803401
p04033
python
s111603000
s500526705
179
161
38,256
38,384
Accepted
Accepted
10.06
def slove(): import sys input = sys.stdin.readline a, b = list(map(int, input().rstrip('\n').split())) if a * b > 0 : if a > 0 and b > 0: print("Positive") elif a < 0 and b < 0: print(("Positive" if abs(a - b + 1) % 2 == 0 else "Negative")) elif a < 0 and 0 < b: print(("Positive" if abs(a) % 2 == 0 else "Negative")) else: print("Zero") if __name__ == '__main__': slove()
def slove(): import sys input = sys.stdin.readline a, b = list(map(int, input().rstrip('\n').split())) if a * b <= 0: print("Zero") elif a > 0 and b > 0: print("Positive") else: if a * b >= 0: if abs(a - b + 1) % 2 == 0: print("Positive") else: print("Negative") else: if abs(a) % 2 == 0: print("Positive") else: print("Negative") if __name__ == '__main__': slove()
17
23
479
562
def slove(): import sys input = sys.stdin.readline a, b = list(map(int, input().rstrip("\n").split())) if a * b > 0: if a > 0 and b > 0: print("Positive") elif a < 0 and b < 0: print(("Positive" if abs(a - b + 1) % 2 == 0 else "Negative")) elif a < 0 and 0 < b: print(("Positive" if abs(a) % 2 == 0 else "Negative")) else: print("Zero") if __name__ == "__main__": slove()
def slove(): import sys input = sys.stdin.readline a, b = list(map(int, input().rstrip("\n").split())) if a * b <= 0: print("Zero") elif a > 0 and b > 0: print("Positive") else: if a * b >= 0: if abs(a - b + 1) % 2 == 0: print("Positive") else: print("Negative") else: if abs(a) % 2 == 0: print("Positive") else: print("Negative") if __name__ == "__main__": slove()
false
26.086957
[ "- if a * b > 0:", "- if a > 0 and b > 0:", "- print(\"Positive\")", "- elif a < 0 and b < 0:", "- print((\"Positive\" if abs(a - b + 1) % 2 == 0 else \"Negative\"))", "- elif a < 0 and 0 < b:", "- print((\"Positive\" if abs(a) % 2 == 0 else \"Negative\"))", "+ if a * b <= 0:", "+ print(\"Zero\")", "+ elif a > 0 and b > 0:", "+ print(\"Positive\")", "- print(\"Zero\")", "+ if a * b >= 0:", "+ if abs(a - b + 1) % 2 == 0:", "+ print(\"Positive\")", "+ else:", "+ print(\"Negative\")", "+ else:", "+ if abs(a) % 2 == 0:", "+ print(\"Positive\")", "+ else:", "+ print(\"Negative\")" ]
false
0.041258
0.039004
1.057785
[ "s111603000", "s500526705" ]
u820180033
p02631
python
s511537822
s160185959
175
149
31,336
31,680
Accepted
Accepted
14.86
N = int(eval(input())) A = [int(n) for n in input().split()] X = 0 ans = [] for i in range(N): X = X^A[i] for i in range(N): ans.append(X^A[i]) print((*ans))
from functools import reduce N = int(eval(input())) A = [int(n) for n in input().split()] X = reduce(int.__xor__, A) ans = [X^a for a in A] print((*ans))
9
6
161
150
N = int(eval(input())) A = [int(n) for n in input().split()] X = 0 ans = [] for i in range(N): X = X ^ A[i] for i in range(N): ans.append(X ^ A[i]) print((*ans))
from functools import reduce N = int(eval(input())) A = [int(n) for n in input().split()] X = reduce(int.__xor__, A) ans = [X ^ a for a in A] print((*ans))
false
33.333333
[ "+from functools import reduce", "+", "-X = 0", "-ans = []", "-for i in range(N):", "- X = X ^ A[i]", "-for i in range(N):", "- ans.append(X ^ A[i])", "+X = reduce(int.__xor__, A)", "+ans = [X ^ a for a in A]" ]
false
0.050735
0.067018
0.757033
[ "s511537822", "s160185959" ]
u297574184
p02563
python
s035990742
s100564661
1,669
1,487
305,928
268,960
Accepted
Accepted
10.9
import numpy as np from scipy import signal MOD = 998244353 N, M = list(map(int, input().split())) As = list(map(int, input().split())) Bs = list(map(int, input().split())) def divideArr3(As, numD): arrA = np.array(As, dtype=np.int64) mask = (1<<numD) - 1 arrA0 = arrA & mask arrA1 = (arrA>>numD) & mask arrA2 = arrA>>(2*numD) return arrA2, arrA1, arrA0 def convolveArr(arrA, arrB): arrC = np.rint(signal.fftconvolve(arrA, arrB)).astype(np.int64) return arrC def convolveMOD(As, Bs, MOD): numD = 10 div = 1<<numD arrA2, arrA1, arrA0 = divideArr3(As, numD) arrB2, arrB1, arrB0 = divideArr3(Bs, numD) arrC4 = convolveArr(arrA2, arrB2) % MOD arrC2 = convolveArr(arrA1, arrB1) % MOD arrC0 = convolveArr(arrA0, arrB0) % MOD arrC3 = (convolveArr(arrA2+arrA1, arrB2+arrB1) % MOD - arrC4 - arrC2) % MOD arrC1 = (convolveArr(arrA1+arrA0, arrB1+arrB0) % MOD - arrC2 - arrC0) % MOD arrC2 += (convolveArr(arrA2+arrA0, arrB2+arrB0) % MOD - arrC4 - arrC0) % MOD arrC2 %= MOD div2 = div*div%MOD div3 = div2*div%MOD div4 = div3*div%MOD arrAns = ((arrC4*div4)%MOD + (arrC3*div3)%MOD + (arrC2*div2)%MOD + (arrC1*div)%MOD + arrC0) % MOD return arrAns.tolist() anss = convolveMOD(As, Bs, MOD) print((' '.join(map(str, anss))))
import numpy as np MOD = 998244353 N, M = list(map(int, input().split())) As = list(map(int, input().split())) Bs = list(map(int, input().split())) def divideArr3(As, numD): arrA = np.array(As, dtype=np.int64) mask = (1<<numD) - 1 arrA0 = arrA & mask arrA1 = (arrA>>numD) & mask arrA2 = arrA>>(2*numD) return arrA2, arrA1, arrA0 def convolveArr(arrA, arrB): L = len(arrA) + len(arrB) - 1 lenFFT = 1 << ((L-1).bit_length()) fA = np.fft.rfft(arrA, n=lenFFT) fB = np.fft.rfft(arrB, n=lenFFT) arrC = np.rint(np.fft.irfft(fA * fB, n=lenFFT)).astype(np.int64) return arrC[:L] def convolveMOD(As, Bs, MOD): numD = 10 div = 1<<numD arrA2, arrA1, arrA0 = divideArr3(As, numD) arrB2, arrB1, arrB0 = divideArr3(Bs, numD) arrC4 = convolveArr(arrA2, arrB2) % MOD arrC2 = convolveArr(arrA1, arrB1) % MOD arrC0 = convolveArr(arrA0, arrB0) % MOD arrC3 = (convolveArr(arrA2+arrA1, arrB2+arrB1) % MOD - arrC4 - arrC2) % MOD arrC1 = (convolveArr(arrA1+arrA0, arrB1+arrB0) % MOD - arrC2 - arrC0) % MOD arrC2 += (convolveArr(arrA2+arrA0, arrB2+arrB0) % MOD - arrC4 - arrC0) % MOD arrC2 %= MOD div2 = div*div%MOD div3 = div2*div%MOD div4 = div3*div%MOD arrAns = ((arrC4*div4)%MOD + (arrC3*div3)%MOD + (arrC2*div2)%MOD + (arrC1*div)%MOD + arrC0) % MOD return arrAns.tolist() anss = convolveMOD(As, Bs, MOD) print((' '.join(map(str, anss))))
43
46
1,345
1,475
import numpy as np from scipy import signal MOD = 998244353 N, M = list(map(int, input().split())) As = list(map(int, input().split())) Bs = list(map(int, input().split())) def divideArr3(As, numD): arrA = np.array(As, dtype=np.int64) mask = (1 << numD) - 1 arrA0 = arrA & mask arrA1 = (arrA >> numD) & mask arrA2 = arrA >> (2 * numD) return arrA2, arrA1, arrA0 def convolveArr(arrA, arrB): arrC = np.rint(signal.fftconvolve(arrA, arrB)).astype(np.int64) return arrC def convolveMOD(As, Bs, MOD): numD = 10 div = 1 << numD arrA2, arrA1, arrA0 = divideArr3(As, numD) arrB2, arrB1, arrB0 = divideArr3(Bs, numD) arrC4 = convolveArr(arrA2, arrB2) % MOD arrC2 = convolveArr(arrA1, arrB1) % MOD arrC0 = convolveArr(arrA0, arrB0) % MOD arrC3 = (convolveArr(arrA2 + arrA1, arrB2 + arrB1) % MOD - arrC4 - arrC2) % MOD arrC1 = (convolveArr(arrA1 + arrA0, arrB1 + arrB0) % MOD - arrC2 - arrC0) % MOD arrC2 += (convolveArr(arrA2 + arrA0, arrB2 + arrB0) % MOD - arrC4 - arrC0) % MOD arrC2 %= MOD div2 = div * div % MOD div3 = div2 * div % MOD div4 = div3 * div % MOD arrAns = ( (arrC4 * div4) % MOD + (arrC3 * div3) % MOD + (arrC2 * div2) % MOD + (arrC1 * div) % MOD + arrC0 ) % MOD return arrAns.tolist() anss = convolveMOD(As, Bs, MOD) print((" ".join(map(str, anss))))
import numpy as np MOD = 998244353 N, M = list(map(int, input().split())) As = list(map(int, input().split())) Bs = list(map(int, input().split())) def divideArr3(As, numD): arrA = np.array(As, dtype=np.int64) mask = (1 << numD) - 1 arrA0 = arrA & mask arrA1 = (arrA >> numD) & mask arrA2 = arrA >> (2 * numD) return arrA2, arrA1, arrA0 def convolveArr(arrA, arrB): L = len(arrA) + len(arrB) - 1 lenFFT = 1 << ((L - 1).bit_length()) fA = np.fft.rfft(arrA, n=lenFFT) fB = np.fft.rfft(arrB, n=lenFFT) arrC = np.rint(np.fft.irfft(fA * fB, n=lenFFT)).astype(np.int64) return arrC[:L] def convolveMOD(As, Bs, MOD): numD = 10 div = 1 << numD arrA2, arrA1, arrA0 = divideArr3(As, numD) arrB2, arrB1, arrB0 = divideArr3(Bs, numD) arrC4 = convolveArr(arrA2, arrB2) % MOD arrC2 = convolveArr(arrA1, arrB1) % MOD arrC0 = convolveArr(arrA0, arrB0) % MOD arrC3 = (convolveArr(arrA2 + arrA1, arrB2 + arrB1) % MOD - arrC4 - arrC2) % MOD arrC1 = (convolveArr(arrA1 + arrA0, arrB1 + arrB0) % MOD - arrC2 - arrC0) % MOD arrC2 += (convolveArr(arrA2 + arrA0, arrB2 + arrB0) % MOD - arrC4 - arrC0) % MOD arrC2 %= MOD div2 = div * div % MOD div3 = div2 * div % MOD div4 = div3 * div % MOD arrAns = ( (arrC4 * div4) % MOD + (arrC3 * div3) % MOD + (arrC2 * div2) % MOD + (arrC1 * div) % MOD + arrC0 ) % MOD return arrAns.tolist() anss = convolveMOD(As, Bs, MOD) print((" ".join(map(str, anss))))
false
6.521739
[ "-from scipy import signal", "- arrC = np.rint(signal.fftconvolve(arrA, arrB)).astype(np.int64)", "- return arrC", "+ L = len(arrA) + len(arrB) - 1", "+ lenFFT = 1 << ((L - 1).bit_length())", "+ fA = np.fft.rfft(arrA, n=lenFFT)", "+ fB = np.fft.rfft(arrB, n=lenFFT)", "+ arrC = np.rint(np.fft.irfft(fA * fB, n=lenFFT)).astype(np.int64)", "+ return arrC[:L]" ]
false
1.466463
0.644983
2.273648
[ "s035990742", "s100564661" ]
u982591663
p02683
python
s479148582
s329505029
202
88
27,224
9,124
Accepted
Accepted
56.44
import numpy as np N, M, X = list(map(int, input().split())) CA = [] for _ in range(N): Ci, *A = list(map(int, input().split())) CA.append((Ci, A)) ans = 10**8 studied = np.array([0] * M) for i in range(2**N): flag = True tmp_ans = 0 studied = np.array([0] * M) for j in range(N): if i >> j & 1: tmp_ans += CA[j][0] studied += CA[j][1] for study in studied: if study < X: flag = False break if flag: ans = min(ans, tmp_ans) if ans == 10**8: print((-1)) else: print(ans)
N, M, X = list(map(int, input().split())) CA = [] for _ in range(N): C, *A = list(map(int, input().split())) CA.append((C, A)) ans = 10**9 for i in range(2**N): flag = True tmp_C = 0 tmp_A = [0]*M for j in range(N): if i >> j & 1: tmp_C += CA[j][0] for k in range(M): tmp_A[k] += CA[j][1][k] for tmp_a in tmp_A: if tmp_a < X: flag = False break if flag == True: ans = min(ans, tmp_C) if ans < 10**9: print(ans) else: print((-1))
30
28
601
573
import numpy as np N, M, X = list(map(int, input().split())) CA = [] for _ in range(N): Ci, *A = list(map(int, input().split())) CA.append((Ci, A)) ans = 10**8 studied = np.array([0] * M) for i in range(2**N): flag = True tmp_ans = 0 studied = np.array([0] * M) for j in range(N): if i >> j & 1: tmp_ans += CA[j][0] studied += CA[j][1] for study in studied: if study < X: flag = False break if flag: ans = min(ans, tmp_ans) if ans == 10**8: print((-1)) else: print(ans)
N, M, X = list(map(int, input().split())) CA = [] for _ in range(N): C, *A = list(map(int, input().split())) CA.append((C, A)) ans = 10**9 for i in range(2**N): flag = True tmp_C = 0 tmp_A = [0] * M for j in range(N): if i >> j & 1: tmp_C += CA[j][0] for k in range(M): tmp_A[k] += CA[j][1][k] for tmp_a in tmp_A: if tmp_a < X: flag = False break if flag == True: ans = min(ans, tmp_C) if ans < 10**9: print(ans) else: print((-1))
false
6.666667
[ "-import numpy as np", "-", "- Ci, *A = list(map(int, input().split()))", "- CA.append((Ci, A))", "-ans = 10**8", "-studied = np.array([0] * M)", "+ C, *A = list(map(int, input().split()))", "+ CA.append((C, A))", "+ans = 10**9", "- tmp_ans = 0", "- studied = np.array([0] * M)", "+ tmp_C = 0", "+ tmp_A = [0] * M", "- tmp_ans += CA[j][0]", "- studied += CA[j][1]", "- for study in studied:", "- if study < X:", "+ tmp_C += CA[j][0]", "+ for k in range(M):", "+ tmp_A[k] += CA[j][1][k]", "+ for tmp_a in tmp_A:", "+ if tmp_a < X:", "- if flag:", "- ans = min(ans, tmp_ans)", "-if ans == 10**8:", "+ if flag == True:", "+ ans = min(ans, tmp_C)", "+if ans < 10**9:", "+ print(ans)", "+else:", "-else:", "- print(ans)" ]
false
0.301864
0.091363
3.303995
[ "s479148582", "s329505029" ]
u245870380
p03457
python
s636380941
s688659594
405
370
27,300
3,060
Accepted
Accepted
8.64
N = int(eval(input())) t = [list(map(int, input().split())) for i in range(N)] if N == 1: if t[0][0] >= t[0][1] + t[0][2]: print("Yes") else: print("No") else: for i in range(1,N): a = t[i][0] - t[i-1][0] b = abs(t[i][1] - t[i-1][1]) + abs(t[i][2] - t[i-1][2]) if a >= b and a % 2 == b % 2: continue else: print("No") exit() print("Yes")
N = int(eval(input())) pt, px, py = 0, 0, 0 for i in range(N): t, x, y = list(map(int, input().split())) a = abs(x - px) + abs(y - py) b = t - pt if b < a or (a - b) % 2 != 0: print("No") exit() pt, px, py = t, x, y print("Yes")
19
11
451
262
N = int(eval(input())) t = [list(map(int, input().split())) for i in range(N)] if N == 1: if t[0][0] >= t[0][1] + t[0][2]: print("Yes") else: print("No") else: for i in range(1, N): a = t[i][0] - t[i - 1][0] b = abs(t[i][1] - t[i - 1][1]) + abs(t[i][2] - t[i - 1][2]) if a >= b and a % 2 == b % 2: continue else: print("No") exit() print("Yes")
N = int(eval(input())) pt, px, py = 0, 0, 0 for i in range(N): t, x, y = list(map(int, input().split())) a = abs(x - px) + abs(y - py) b = t - pt if b < a or (a - b) % 2 != 0: print("No") exit() pt, px, py = t, x, y print("Yes")
false
42.105263
[ "-t = [list(map(int, input().split())) for i in range(N)]", "-if N == 1:", "- if t[0][0] >= t[0][1] + t[0][2]:", "- print(\"Yes\")", "- else:", "+pt, px, py = 0, 0, 0", "+for i in range(N):", "+ t, x, y = list(map(int, input().split()))", "+ a = abs(x - px) + abs(y - py)", "+ b = t - pt", "+ if b < a or (a - b) % 2 != 0:", "-else:", "- for i in range(1, N):", "- a = t[i][0] - t[i - 1][0]", "- b = abs(t[i][1] - t[i - 1][1]) + abs(t[i][2] - t[i - 1][2])", "- if a >= b and a % 2 == b % 2:", "- continue", "- else:", "- print(\"No\")", "- exit()", "- print(\"Yes\")", "+ exit()", "+ pt, px, py = t, x, y", "+print(\"Yes\")" ]
false
0.043031
0.07648
0.562645
[ "s636380941", "s688659594" ]
u923279197
p02787
python
s421823674
s527143373
854
382
122,588
41,580
Accepted
Accepted
55.27
H,N = list(map(int,input().split())) AB = [list(map(int,input().split())) for _ in range(N)] dp = [[10**18]*(N+1) for _ in range(H+1)] dp[0][0] = 0 for h in range(H+1): for i in range(N): dp[h][i+1] = min(dp[h][i], dp[max(0,h-AB[i][0])][i+1] + AB[i][1]) print((dp[H][N]))
inf = 10**9 H, N = list(map(int, input().split())) AB = [] for n in range(N): a, b = list(map(int, input().split())) AB.append((a, b)) AB.sort(reverse=True, key=lambda x: x[0]) dp = [inf] * (H + 10 ** 4) dp[0] = 0 for a, b in AB: for h in range(H): if dp[h] != inf: tmp = dp[h] + b if tmp < dp[h + a]: dp[h + a] = tmp print((min(dp[H:])))
8
16
282
400
H, N = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] dp = [[10**18] * (N + 1) for _ in range(H + 1)] dp[0][0] = 0 for h in range(H + 1): for i in range(N): dp[h][i + 1] = min(dp[h][i], dp[max(0, h - AB[i][0])][i + 1] + AB[i][1]) print((dp[H][N]))
inf = 10**9 H, N = list(map(int, input().split())) AB = [] for n in range(N): a, b = list(map(int, input().split())) AB.append((a, b)) AB.sort(reverse=True, key=lambda x: x[0]) dp = [inf] * (H + 10**4) dp[0] = 0 for a, b in AB: for h in range(H): if dp[h] != inf: tmp = dp[h] + b if tmp < dp[h + a]: dp[h + a] = tmp print((min(dp[H:])))
false
50
[ "+inf = 10**9", "-AB = [list(map(int, input().split())) for _ in range(N)]", "-dp = [[10**18] * (N + 1) for _ in range(H + 1)]", "-dp[0][0] = 0", "-for h in range(H + 1):", "- for i in range(N):", "- dp[h][i + 1] = min(dp[h][i], dp[max(0, h - AB[i][0])][i + 1] + AB[i][1])", "-print((dp[H][N]))", "+AB = []", "+for n in range(N):", "+ a, b = list(map(int, input().split()))", "+ AB.append((a, b))", "+AB.sort(reverse=True, key=lambda x: x[0])", "+dp = [inf] * (H + 10**4)", "+dp[0] = 0", "+for a, b in AB:", "+ for h in range(H):", "+ if dp[h] != inf:", "+ tmp = dp[h] + b", "+ if tmp < dp[h + a]:", "+ dp[h + a] = tmp", "+print((min(dp[H:])))" ]
false
0.154483
0.068664
2.249839
[ "s421823674", "s527143373" ]
u112364985
p03254
python
s938758994
s030602198
26
24
9,084
9,092
Accepted
Accepted
7.69
n,x=list(map(int,input().split())) List=list(map(int,input().split())) List.sort() ans=0 if sum(List)==x: print(n) exit() else: for i in range(len(List)-1): if x>=List[i]: ans+=1 x-=List[i] else: break print(ans)
n,x=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() cnt=0 if sum(a)==x: print(n) exit() else: for i in range(n-1): if a[i]<=x: x-=a[i] cnt+=1 print(cnt)
15
13
284
227
n, x = list(map(int, input().split())) List = list(map(int, input().split())) List.sort() ans = 0 if sum(List) == x: print(n) exit() else: for i in range(len(List) - 1): if x >= List[i]: ans += 1 x -= List[i] else: break print(ans)
n, x = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() cnt = 0 if sum(a) == x: print(n) exit() else: for i in range(n - 1): if a[i] <= x: x -= a[i] cnt += 1 print(cnt)
false
13.333333
[ "-List = list(map(int, input().split()))", "-List.sort()", "-ans = 0", "-if sum(List) == x:", "+a = list(map(int, input().split()))", "+a.sort()", "+cnt = 0", "+if sum(a) == x:", "- for i in range(len(List) - 1):", "- if x >= List[i]:", "- ans += 1", "- x -= List[i]", "- else:", "- break", "-print(ans)", "+ for i in range(n - 1):", "+ if a[i] <= x:", "+ x -= a[i]", "+ cnt += 1", "+print(cnt)" ]
false
0.090916
0.039413
2.306713
[ "s938758994", "s030602198" ]
u367130284
p03919
python
s029507524
s901943958
21
17
3,060
3,060
Accepted
Accepted
19.05
h,w,*a=open(0).read().split();b=a.index("snuke");print(([chr(i)for i in range(65,91)][b%int(w)]+str(b//int(w)+1)))
h,w,*a=open(0).read().split();b=a.index("snuke");print((chr(b%int(w)+65)+str(b//int(w)+1)))
1
1
112
89
h, w, *a = open(0).read().split() b = a.index("snuke") print(([chr(i) for i in range(65, 91)][b % int(w)] + str(b // int(w) + 1)))
h, w, *a = open(0).read().split() b = a.index("snuke") print((chr(b % int(w) + 65) + str(b // int(w) + 1)))
false
0
[ "-print(([chr(i) for i in range(65, 91)][b % int(w)] + str(b // int(w) + 1)))", "+print((chr(b % int(w) + 65) + str(b // int(w) + 1)))" ]
false
0.046841
0.041056
1.140907
[ "s029507524", "s901943958" ]
u525065967
p02678
python
s842505803
s034348645
963
688
35,108
34,112
Accepted
Accepted
28.56
import queue n,m = list(map(int, input().split())) V = [[] for _ in range(n+1)] for _ in range(m): a,b = list(map(int, input().split())) V[a].append(b) V[b].append(a) ans = [-1]*(n+1) q = queue.Queue() q.put(1) while not q.empty(): p = q.get() for c in V[p]: if c > 1 and ans[c] < 0: ans[c] = p q.put(c) print('Yes') for x in ans[2:]: print(x)
from collections import deque n,m = list(map(int, input().split())) V = [[] for _ in range(n+1)] for _ in range(m): a,b = list(map(int, input().split())) V[a].append(b) V[b].append(a) ans = [-1]*(n+1) q = deque() q.append(1) while len(q): p = q.popleft() for c in V[p]: if c > 1 and ans[c] < 0: ans[c] = p q.append(c) print('Yes') for i in range(2,n+1): print((ans[i]))
18
18
401
425
import queue n, m = list(map(int, input().split())) V = [[] for _ in range(n + 1)] for _ in range(m): a, b = list(map(int, input().split())) V[a].append(b) V[b].append(a) ans = [-1] * (n + 1) q = queue.Queue() q.put(1) while not q.empty(): p = q.get() for c in V[p]: if c > 1 and ans[c] < 0: ans[c] = p q.put(c) print("Yes") for x in ans[2:]: print(x)
from collections import deque n, m = list(map(int, input().split())) V = [[] for _ in range(n + 1)] for _ in range(m): a, b = list(map(int, input().split())) V[a].append(b) V[b].append(a) ans = [-1] * (n + 1) q = deque() q.append(1) while len(q): p = q.popleft() for c in V[p]: if c > 1 and ans[c] < 0: ans[c] = p q.append(c) print("Yes") for i in range(2, n + 1): print((ans[i]))
false
0
[ "-import queue", "+from collections import deque", "-q = queue.Queue()", "-q.put(1)", "-while not q.empty():", "- p = q.get()", "+q = deque()", "+q.append(1)", "+while len(q):", "+ p = q.popleft()", "- q.put(c)", "+ q.append(c)", "-for x in ans[2:]:", "- print(x)", "+for i in range(2, n + 1):", "+ print((ans[i]))" ]
false
0.087663
0.066288
1.322458
[ "s842505803", "s034348645" ]
u761529120
p03326
python
s225493065
s354859982
226
202
39,920
39,152
Accepted
Accepted
10.62
def main(): N, M = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(N)] ans = 0 for i in [-1,1]: for j in [-1,1]: for k in [-1,1]: tmp = [] for x, y, z in X: tmp.append(i*x + j*y + k*z) tmp.sort(reverse=True) ans = max(ans, sum(tmp[:M])) print(ans) main()
def main(): N, M = list(map(int, input().split())) x = [0] * N y = [0] * N z = [0] * N for i in range(N): x[i], y[i], z[i] = list(map(int, input().split())) ans = 0 for i in [-1,1]: for j in [-1,1]: for k in [-1,1]: cand_list = [] for n in range(N): tmp = i * x[n] + j * y[n] + k * z[n] cand_list.append(tmp) cand_list.sort(reverse=True) a = 0 for m in range(M): a += cand_list[m] ans = max(ans, a) print(ans) if __name__ == "__main__": main()
17
30
431
691
def main(): N, M = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(N)] ans = 0 for i in [-1, 1]: for j in [-1, 1]: for k in [-1, 1]: tmp = [] for x, y, z in X: tmp.append(i * x + j * y + k * z) tmp.sort(reverse=True) ans = max(ans, sum(tmp[:M])) print(ans) main()
def main(): N, M = list(map(int, input().split())) x = [0] * N y = [0] * N z = [0] * N for i in range(N): x[i], y[i], z[i] = list(map(int, input().split())) ans = 0 for i in [-1, 1]: for j in [-1, 1]: for k in [-1, 1]: cand_list = [] for n in range(N): tmp = i * x[n] + j * y[n] + k * z[n] cand_list.append(tmp) cand_list.sort(reverse=True) a = 0 for m in range(M): a += cand_list[m] ans = max(ans, a) print(ans) if __name__ == "__main__": main()
false
43.333333
[ "- X = [list(map(int, input().split())) for _ in range(N)]", "+ x = [0] * N", "+ y = [0] * N", "+ z = [0] * N", "+ for i in range(N):", "+ x[i], y[i], z[i] = list(map(int, input().split()))", "- tmp = []", "- for x, y, z in X:", "- tmp.append(i * x + j * y + k * z)", "- tmp.sort(reverse=True)", "- ans = max(ans, sum(tmp[:M]))", "+ cand_list = []", "+ for n in range(N):", "+ tmp = i * x[n] + j * y[n] + k * z[n]", "+ cand_list.append(tmp)", "+ cand_list.sort(reverse=True)", "+ a = 0", "+ for m in range(M):", "+ a += cand_list[m]", "+ ans = max(ans, a)", "-main()", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.044028
0.044542
0.988455
[ "s225493065", "s354859982" ]
u505420467
p03730
python
s516028968
s129340117
208
19
40,684
3,060
Accepted
Accepted
90.87
a,b,c=list(map(int,input().split())) for i in range(10**6): if (i*b+c)%a==0: print("YES") exit() print("NO")
a, b, c = list(map(int, input().split())) tmp = 0 for i in range(1, b + 1): tmp = a * i if tmp % b == c: print("YES") exit() print("NO")
6
8
128
161
a, b, c = list(map(int, input().split())) for i in range(10**6): if (i * b + c) % a == 0: print("YES") exit() print("NO")
a, b, c = list(map(int, input().split())) tmp = 0 for i in range(1, b + 1): tmp = a * i if tmp % b == c: print("YES") exit() print("NO")
false
25
[ "-for i in range(10**6):", "- if (i * b + c) % a == 0:", "+tmp = 0", "+for i in range(1, b + 1):", "+ tmp = a * i", "+ if tmp % b == c:" ]
false
0.081622
0.034178
2.388135
[ "s516028968", "s129340117" ]
u282228874
p03607
python
s723119050
s719917079
217
197
20,192
16,612
Accepted
Accepted
9.22
from collections import Counter n = int(eval(input())) A = [int(eval(input())) for i in range(n)] A = Counter(A) num = [] for a in list(A.items()): if a[1]%2 != 0: num.append(a[0]) print((len(set(num))))
from collections import Counter n = int(eval(input())) A = [int(eval(input())) for i in range(n)] D = Counter(A) res = 0 for v in list(D.values()): if v%2 != 0: res += 1 print(res)
12
12
209
188
from collections import Counter n = int(eval(input())) A = [int(eval(input())) for i in range(n)] A = Counter(A) num = [] for a in list(A.items()): if a[1] % 2 != 0: num.append(a[0]) print((len(set(num))))
from collections import Counter n = int(eval(input())) A = [int(eval(input())) for i in range(n)] D = Counter(A) res = 0 for v in list(D.values()): if v % 2 != 0: res += 1 print(res)
false
0
[ "-A = Counter(A)", "-num = []", "-for a in list(A.items()):", "- if a[1] % 2 != 0:", "- num.append(a[0])", "-print((len(set(num))))", "+D = Counter(A)", "+res = 0", "+for v in list(D.values()):", "+ if v % 2 != 0:", "+ res += 1", "+print(res)" ]
false
0.039473
0.048521
0.813536
[ "s723119050", "s719917079" ]
u379692329
p03476
python
s861488404
s997762035
564
437
23,148
23,572
Accepted
Accepted
22.52
def prime(i): if i == 2: return True else: if i % 2 == 0: return False for j in range(3, int(i**0.5)+1, 2): if i % j == 0: return False return True Q = int(eval(input())) l_r = [[int(_) for _ in input().split()] for _ in range(Q)] Csum = [0]*(10**5+1) cnt = 0 for i in range(3, 10**5, 2): if prime(i) and prime((i+1)//2): cnt += 1 Csum[i] = cnt for i in l_r: print((Csum[i[1]]-Csum[i[0]-2]))
Q = int(eval(input())) l_r = [[int(_) for _ in input().split()] for _ in range(Q)] prime = [False]*(10**5+1) Csum = [0]*(10**5+1) for i in range(2, 10**5+1): if not prime[i]: for j in range(i*2, 10**5+1, i): prime[j] = True cnt = 0 for i in range(3, 10**5+1, 2): if (not prime[i]) and (not prime[(i+1)//2]): cnt += 1 Csum[i] = cnt for i in l_r: print((Csum[i[1]]-Csum[i[0]-2]))
23
18
508
433
def prime(i): if i == 2: return True else: if i % 2 == 0: return False for j in range(3, int(i**0.5) + 1, 2): if i % j == 0: return False return True Q = int(eval(input())) l_r = [[int(_) for _ in input().split()] for _ in range(Q)] Csum = [0] * (10**5 + 1) cnt = 0 for i in range(3, 10**5, 2): if prime(i) and prime((i + 1) // 2): cnt += 1 Csum[i] = cnt for i in l_r: print((Csum[i[1]] - Csum[i[0] - 2]))
Q = int(eval(input())) l_r = [[int(_) for _ in input().split()] for _ in range(Q)] prime = [False] * (10**5 + 1) Csum = [0] * (10**5 + 1) for i in range(2, 10**5 + 1): if not prime[i]: for j in range(i * 2, 10**5 + 1, i): prime[j] = True cnt = 0 for i in range(3, 10**5 + 1, 2): if (not prime[i]) and (not prime[(i + 1) // 2]): cnt += 1 Csum[i] = cnt for i in l_r: print((Csum[i[1]] - Csum[i[0] - 2]))
false
21.73913
[ "-def prime(i):", "- if i == 2:", "- return True", "- else:", "- if i % 2 == 0:", "- return False", "- for j in range(3, int(i**0.5) + 1, 2):", "- if i % j == 0:", "- return False", "- return True", "-", "-", "+prime = [False] * (10**5 + 1)", "+for i in range(2, 10**5 + 1):", "+ if not prime[i]:", "+ for j in range(i * 2, 10**5 + 1, i):", "+ prime[j] = True", "-for i in range(3, 10**5, 2):", "- if prime(i) and prime((i + 1) // 2):", "+for i in range(3, 10**5 + 1, 2):", "+ if (not prime[i]) and (not prime[(i + 1) // 2]):" ]
false
0.535026
0.154772
3.456872
[ "s861488404", "s997762035" ]
u021019433
p02768
python
s885108687
s727223260
1,496
113
5,468
3,060
Accepted
Accepted
92.45
from math import factorial M = 10**9 + 7 n, a, b = list(map(int, input().split())) r = pow(2, n, M) - 1 c = 1 for i in range(b): c = c * (n - i) % M if i + 1 == a: r -= c * pow(factorial(a) % M, M - 2, M) a = b print((r % M))
M = 10**9 + 7 n, a, b = list(map(int, input().split())) r = pow(2, n, M) - 1 f = c = 1 for i in range(b): f = f * (i + 1) % M c = c * (n - i) % M if i + 1 == a: a = b r -= c * pow(f, M - 2, M) print((r % M))
12
11
243
224
from math import factorial M = 10**9 + 7 n, a, b = list(map(int, input().split())) r = pow(2, n, M) - 1 c = 1 for i in range(b): c = c * (n - i) % M if i + 1 == a: r -= c * pow(factorial(a) % M, M - 2, M) a = b print((r % M))
M = 10**9 + 7 n, a, b = list(map(int, input().split())) r = pow(2, n, M) - 1 f = c = 1 for i in range(b): f = f * (i + 1) % M c = c * (n - i) % M if i + 1 == a: a = b r -= c * pow(f, M - 2, M) print((r % M))
false
8.333333
[ "-from math import factorial", "-", "-c = 1", "+f = c = 1", "+ f = f * (i + 1) % M", "- r -= c * pow(factorial(a) % M, M - 2, M)", "+ r -= c * pow(f, M - 2, M)" ]
false
0.473692
0.102499
4.621428
[ "s885108687", "s727223260" ]
u792720861
p03860
python
s809844031
s764797303
26
24
8,920
9,024
Accepted
Accepted
7.69
print(('A' + input().split()[1][0] + 'C'))
a = input().split() print(*[h[0] for h in a], sep='')
1
2
41
55
print(("A" + input().split()[1][0] + "C"))
a = input().split() print(*[h[0] for h in a], sep="")
false
50
[ "-print((\"A\" + input().split()[1][0] + \"C\"))", "+a = input().split()", "+print(*[h[0] for h in a], sep=\"\")" ]
false
0.03619
0.090983
0.39776
[ "s809844031", "s764797303" ]
u561083515
p03031
python
s238698574
s886838252
200
36
41,968
3,064
Accepted
Accepted
82
N,M = list(map(int,input().split())) k = [0] * M s = [0] * M for i in range(M): ks = list(map(int,input().split())) for j,x in enumerate(ks): if j == 0: k[i] = x continue s[i] += 1 << x-1 p = [int(i) for i in input().split()] answer = 0 for i in range(2**N): count = [0] * M for j in range(M): tmp = s[j] & i while tmp: if tmp & 1: count[j] += 1 tmp >>= 1 # j็•ช็›ฎใฎ้›ป็ƒใŒๅ…‰ใ‚‹ๅ ดๅˆ count[j] = 1 if count[j] % 2 == p[j]: count[j] = 1 else: count[j] = 0 # ๅ…จใฆใฎ้›ป็ƒใŒ็‚น็ฏใ™ใ‚‹ๅ ดๅˆ if not 0 in count: answer += 1 print(answer)
N,M = list(map(int,input().split())) S = [] for _ in range(M): INPUT = tuple(map(int,input().split())) S.append(INPUT[1:]) P = [int(i) for i in input().split()] ans = 0 for i in range(2**N): # state[i]: ใ‚นใ‚คใƒƒใƒiใŒon state = [False] * N for j in range(N): if 1 & (i >> j): state[j] = True # ๅ…จใฆใฎ้›ป็ƒใŒ็‚น็ฏใ™ใ‚‹ใ‹ๅˆคๅฎš flag = True for j in range(M): cnt = 0 for s in S[j]: if state[s-1]: cnt += 1 if cnt % 2 != P[j]: flag = False if flag: ans += 1 print(ans)
33
29
705
601
N, M = list(map(int, input().split())) k = [0] * M s = [0] * M for i in range(M): ks = list(map(int, input().split())) for j, x in enumerate(ks): if j == 0: k[i] = x continue s[i] += 1 << x - 1 p = [int(i) for i in input().split()] answer = 0 for i in range(2**N): count = [0] * M for j in range(M): tmp = s[j] & i while tmp: if tmp & 1: count[j] += 1 tmp >>= 1 # j็•ช็›ฎใฎ้›ป็ƒใŒๅ…‰ใ‚‹ๅ ดๅˆ count[j] = 1 if count[j] % 2 == p[j]: count[j] = 1 else: count[j] = 0 # ๅ…จใฆใฎ้›ป็ƒใŒ็‚น็ฏใ™ใ‚‹ๅ ดๅˆ if not 0 in count: answer += 1 print(answer)
N, M = list(map(int, input().split())) S = [] for _ in range(M): INPUT = tuple(map(int, input().split())) S.append(INPUT[1:]) P = [int(i) for i in input().split()] ans = 0 for i in range(2**N): # state[i]: ใ‚นใ‚คใƒƒใƒiใŒon state = [False] * N for j in range(N): if 1 & (i >> j): state[j] = True # ๅ…จใฆใฎ้›ป็ƒใŒ็‚น็ฏใ™ใ‚‹ใ‹ๅˆคๅฎš flag = True for j in range(M): cnt = 0 for s in S[j]: if state[s - 1]: cnt += 1 if cnt % 2 != P[j]: flag = False if flag: ans += 1 print(ans)
false
12.121212
[ "-k = [0] * M", "-s = [0] * M", "-for i in range(M):", "- ks = list(map(int, input().split()))", "- for j, x in enumerate(ks):", "- if j == 0:", "- k[i] = x", "- continue", "- s[i] += 1 << x - 1", "-p = [int(i) for i in input().split()]", "-answer = 0", "+S = []", "+for _ in range(M):", "+ INPUT = tuple(map(int, input().split()))", "+ S.append(INPUT[1:])", "+P = [int(i) for i in input().split()]", "+ans = 0", "- count = [0] * M", "+ # state[i]: ใ‚นใ‚คใƒƒใƒiใŒon", "+ state = [False] * N", "+ for j in range(N):", "+ if 1 & (i >> j):", "+ state[j] = True", "+ # ๅ…จใฆใฎ้›ป็ƒใŒ็‚น็ฏใ™ใ‚‹ใ‹ๅˆคๅฎš", "+ flag = True", "- tmp = s[j] & i", "- while tmp:", "- if tmp & 1:", "- count[j] += 1", "- tmp >>= 1", "- # j็•ช็›ฎใฎ้›ป็ƒใŒๅ…‰ใ‚‹ๅ ดๅˆ count[j] = 1", "- if count[j] % 2 == p[j]:", "- count[j] = 1", "- else:", "- count[j] = 0", "- # ๅ…จใฆใฎ้›ป็ƒใŒ็‚น็ฏใ™ใ‚‹ๅ ดๅˆ", "- if not 0 in count:", "- answer += 1", "-print(answer)", "+ cnt = 0", "+ for s in S[j]:", "+ if state[s - 1]:", "+ cnt += 1", "+ if cnt % 2 != P[j]:", "+ flag = False", "+ if flag:", "+ ans += 1", "+print(ans)" ]
false
0.045224
0.039397
1.147896
[ "s238698574", "s886838252" ]
u843175622
p03732
python
s042599068
s296671201
388
352
3,064
3,316
Accepted
Accepted
9.28
N,W=list(map(int,input().split())) w=[0]*N;v=[0]*N for i in range(N):w[i],v[i]=list(map(int,input().split())) V=[[] for _ in [0]*4] for i in range(N):V[w[i]-w[0]].append(v[i]) for i in range(4): V[i].sort(reverse=True) for j in range(len(V[i])-1):V[i][j+1]+=V[i][j] V[i].insert(0,0) a=0 for i in range(len(V[0])): for j in range(len(V[1])): for k in range(len(V[2])): for l in range(len(V[3])): if i*w[0]+j*-~w[0]+k*-~-~w[0]+l*-~-~-~w[0]<=W:a=max(a,V[0][i]+V[1][j]+V[2][k]+V[3][l]) print(a)
from collections import defaultdict from itertools import accumulate N, W = list(map(int, input().split())) w = [0] * N; v = [0] * N d = defaultdict(list) for i in range(N): w[i], v[i] = list(map(int, input().split())) d[w[i]].append(v[i]) for i in range(4): d[w[0]+i].sort(reverse=True) d[w[0]+i].insert(0, 0) d[w[0]+i] = list(accumulate(d[w[0]+i])) ans = 0 for i in range(len(d[w[0]])): for j in range(len(d[w[0]+1])): for k in range(len(d[w[0]+2])): for l in range(len(d[w[0]+3])): if i * w[0] + j * (w[0] + 1) + k * (w[0] + 2) + l * (w[0] + 3) <= W: ans = max(ans, d[w[0]][i] + d[w[0]+1][j] + d[w[0]+2][k] + d[w[0]+3][l]) print(ans)
17
23
559
730
N, W = list(map(int, input().split())) w = [0] * N v = [0] * N for i in range(N): w[i], v[i] = list(map(int, input().split())) V = [[] for _ in [0] * 4] for i in range(N): V[w[i] - w[0]].append(v[i]) for i in range(4): V[i].sort(reverse=True) for j in range(len(V[i]) - 1): V[i][j + 1] += V[i][j] V[i].insert(0, 0) a = 0 for i in range(len(V[0])): for j in range(len(V[1])): for k in range(len(V[2])): for l in range(len(V[3])): if i * w[0] + j * -~w[0] + k * -~-~w[0] + l * -~-~-~w[0] <= W: a = max(a, V[0][i] + V[1][j] + V[2][k] + V[3][l]) print(a)
from collections import defaultdict from itertools import accumulate N, W = list(map(int, input().split())) w = [0] * N v = [0] * N d = defaultdict(list) for i in range(N): w[i], v[i] = list(map(int, input().split())) d[w[i]].append(v[i]) for i in range(4): d[w[0] + i].sort(reverse=True) d[w[0] + i].insert(0, 0) d[w[0] + i] = list(accumulate(d[w[0] + i])) ans = 0 for i in range(len(d[w[0]])): for j in range(len(d[w[0] + 1])): for k in range(len(d[w[0] + 2])): for l in range(len(d[w[0] + 3])): if i * w[0] + j * (w[0] + 1) + k * (w[0] + 2) + l * (w[0] + 3) <= W: ans = max( ans, d[w[0]][i] + d[w[0] + 1][j] + d[w[0] + 2][k] + d[w[0] + 3][l], ) print(ans)
false
26.086957
[ "+from collections import defaultdict", "+from itertools import accumulate", "+", "+d = defaultdict(list)", "-V = [[] for _ in [0] * 4]", "-for i in range(N):", "- V[w[i] - w[0]].append(v[i])", "+ d[w[i]].append(v[i])", "- V[i].sort(reverse=True)", "- for j in range(len(V[i]) - 1):", "- V[i][j + 1] += V[i][j]", "- V[i].insert(0, 0)", "-a = 0", "-for i in range(len(V[0])):", "- for j in range(len(V[1])):", "- for k in range(len(V[2])):", "- for l in range(len(V[3])):", "- if i * w[0] + j * -~w[0] + k * -~-~w[0] + l * -~-~-~w[0] <= W:", "- a = max(a, V[0][i] + V[1][j] + V[2][k] + V[3][l])", "-print(a)", "+ d[w[0] + i].sort(reverse=True)", "+ d[w[0] + i].insert(0, 0)", "+ d[w[0] + i] = list(accumulate(d[w[0] + i]))", "+ans = 0", "+for i in range(len(d[w[0]])):", "+ for j in range(len(d[w[0] + 1])):", "+ for k in range(len(d[w[0] + 2])):", "+ for l in range(len(d[w[0] + 3])):", "+ if i * w[0] + j * (w[0] + 1) + k * (w[0] + 2) + l * (w[0] + 3) <= W:", "+ ans = max(", "+ ans,", "+ d[w[0]][i] + d[w[0] + 1][j] + d[w[0] + 2][k] + d[w[0] + 3][l],", "+ )", "+print(ans)" ]
false
0.050725
0.051113
0.992403
[ "s042599068", "s296671201" ]
u827202523
p03795
python
s243385802
s760126750
80
70
65,708
65,748
Accepted
Accepted
12.5
import sys from collections import defaultdict, deque, Counter import math # import copy from bisect import bisect_left, bisect_right # import heapq # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(eval(input())) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = 10 ** 20 MOD = 10**9 + 7 divide = lambda x: pow(x, MOD-2, MOD) def search(pros,tgt,g,d): tmp = 0 cnt = 0 rest = [] for i in range(d): if tgt % 2 == 1: tmp += 100 * (i+1) * pros[i][0] + pros[i][1] cnt += pros[i][0] else: rest.append((i+1,pros[i][0]-1)) tgt //= 2 # print(tmp) if tmp >= g: return cnt for ap, ac in rest[::-1]: if tmp + 100 * ap * ac >= g: cnt += math.ceil((g - tmp)/(100 * ap)) return cnt else: cnt += ac tmp += 100 * ac * ap return INF def main(): n = getN() x = 800 * n y = 200 * (n // 15) print((x-y)) if __name__ == "__main__": main()
import sys from collections import defaultdict, deque, Counter import math # import copy from bisect import bisect_left, bisect_right import heapq # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(eval(input())) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = 10 ** 20 MOD = 10**9 + 7 divide = lambda x: pow(x, MOD-2, MOD) def nck(n, k, kaijyo): return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD def npk(n, k, kaijyo): if k == 0 or k == n: return n % MOD return (kaijyo[n] * divide(kaijyo[n-k])) % MOD def kaijyo(n): ret = [1] for i in range(1, n + 1): ret.append((ret[-1] * i)% MOD) return ret def solve(): n = getN() x = n * 800 y = (n // 15) * 200 print((x - y)) def main(): n = getN() for _ in range(n): solve() if __name__ == "__main__": # main() solve()
56
55
1,207
1,045
import sys from collections import defaultdict, deque, Counter import math # import copy from bisect import bisect_left, bisect_right # import heapq # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(eval(input())) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = 10**20 MOD = 10**9 + 7 divide = lambda x: pow(x, MOD - 2, MOD) def search(pros, tgt, g, d): tmp = 0 cnt = 0 rest = [] for i in range(d): if tgt % 2 == 1: tmp += 100 * (i + 1) * pros[i][0] + pros[i][1] cnt += pros[i][0] else: rest.append((i + 1, pros[i][0] - 1)) tgt //= 2 # print(tmp) if tmp >= g: return cnt for ap, ac in rest[::-1]: if tmp + 100 * ap * ac >= g: cnt += math.ceil((g - tmp) / (100 * ap)) return cnt else: cnt += ac tmp += 100 * ac * ap return INF def main(): n = getN() x = 800 * n y = 200 * (n // 15) print((x - y)) if __name__ == "__main__": main()
import sys from collections import defaultdict, deque, Counter import math # import copy from bisect import bisect_left, bisect_right import heapq # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(eval(input())) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = 10**20 MOD = 10**9 + 7 divide = lambda x: pow(x, MOD - 2, MOD) def nck(n, k, kaijyo): return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD def npk(n, k, kaijyo): if k == 0 or k == n: return n % MOD return (kaijyo[n] * divide(kaijyo[n - k])) % MOD def kaijyo(n): ret = [1] for i in range(1, n + 1): ret.append((ret[-1] * i) % MOD) return ret def solve(): n = getN() x = n * 800 y = (n // 15) * 200 print((x - y)) def main(): n = getN() for _ in range(n): solve() if __name__ == "__main__": # main() solve()
false
1.785714
[ "+import heapq", "-# import heapq", "-def search(pros, tgt, g, d):", "- tmp = 0", "- cnt = 0", "- rest = []", "- for i in range(d):", "- if tgt % 2 == 1:", "- tmp += 100 * (i + 1) * pros[i][0] + pros[i][1]", "- cnt += pros[i][0]", "- else:", "- rest.append((i + 1, pros[i][0] - 1))", "- tgt //= 2", "- # print(tmp)", "- if tmp >= g:", "- return cnt", "- for ap, ac in rest[::-1]:", "- if tmp + 100 * ap * ac >= g:", "- cnt += math.ceil((g - tmp) / (100 * ap))", "- return cnt", "- else:", "- cnt += ac", "- tmp += 100 * ac * ap", "- return INF", "+def nck(n, k, kaijyo):", "+ return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD", "+", "+", "+def npk(n, k, kaijyo):", "+ if k == 0 or k == n:", "+ return n % MOD", "+ return (kaijyo[n] * divide(kaijyo[n - k])) % MOD", "+", "+", "+def kaijyo(n):", "+ ret = [1]", "+ for i in range(1, n + 1):", "+ ret.append((ret[-1] * i) % MOD)", "+ return ret", "+", "+", "+def solve():", "+ n = getN()", "+ x = n * 800", "+ y = (n // 15) * 200", "+ print((x - y))", "- x = 800 * n", "- y = 200 * (n // 15)", "- print((x - y))", "+ for _ in range(n):", "+ solve()", "- main()", "+ # main()", "+ solve()" ]
false
0.052198
0.047202
1.10584
[ "s243385802", "s760126750" ]
u835907423
p03493
python
s938997632
s239869462
23
17
3,188
2,940
Accepted
Accepted
26.09
import re a = eval(input()) regex = '^(\d)(\d)(\d)' s1 = int(re.sub(regex, r'\1', a)) s2 = int(re.sub(regex, r'\2', a)) s3 = int(re.sub(regex, r'\3', a)) i = 0 if s1 == 1: i += 1 if s2 == 1: i += 1 if s3 == 1: i += 1 print(i)
d = list(eval(input())) i = 0 if d[0] == '1': i += 1 if d[1] == '1': i += 1 if d[2] == '1': i += 1 print(i)
14
6
244
106
import re a = eval(input()) regex = "^(\d)(\d)(\d)" s1 = int(re.sub(regex, r"\1", a)) s2 = int(re.sub(regex, r"\2", a)) s3 = int(re.sub(regex, r"\3", a)) i = 0 if s1 == 1: i += 1 if s2 == 1: i += 1 if s3 == 1: i += 1 print(i)
d = list(eval(input())) i = 0 if d[0] == "1": i += 1 if d[1] == "1": i += 1 if d[2] == "1": i += 1 print(i)
false
57.142857
[ "-import re", "-", "-a = eval(input())", "-regex = \"^(\\d)(\\d)(\\d)\"", "-s1 = int(re.sub(regex, r\"\\1\", a))", "-s2 = int(re.sub(regex, r\"\\2\", a))", "-s3 = int(re.sub(regex, r\"\\3\", a))", "+d = list(eval(input()))", "-if s1 == 1:", "+if d[0] == \"1\":", "-if s2 == 1:", "+if d[1] == \"1\":", "-if s3 == 1:", "+if d[2] == \"1\":" ]
false
0.045709
0.081828
0.558594
[ "s938997632", "s239869462" ]
u426534722
p02241
python
s658478414
s197853134
30
20
7,872
7,860
Accepted
Accepted
33.33
from sys import stdin INF = float('inf') WHITE, GRAY, BLACK = 0, 1, 2 n = int(stdin.readline()) M = [[INF] * n for _ in range(n)] for i in range(0, n): for j, e in enumerate(list(map(int, stdin.readline().split()))): if e != -1: M[i][j] = e d = [INF] * n d[0] = 0 color = [0] * n def prim(): while True: minv = INF u = -1 for i in range(0, n): if minv > d[i] and color[i] != BLACK: u = i minv = d[i] if u == -1: break color[u] = BLACK for v in range(0, n): if color[v] != BLACK and d[v] > M[u][v]: d[v] = M[u][v] return sum(d) print((prim()))
from sys import stdin INF = 1<<21 WHITE, GRAY, BLACK = 0, 1, 2 n = int(stdin.readline()) M = [[INF] * n for _ in range(n)] for i in range(0, n): for j, e in enumerate(list(map(int, stdin.readline().split()))): if e != -1: M[i][j] = e d = [INF] * n d[0] = 0 color = [0] * n def prim(): while True: minv = INF u = -1 for i in range(0, n): if minv > d[i] and color[i] != BLACK: u = i minv = d[i] if u == -1: break color[u] = BLACK for v in range(0, n): if color[v] != BLACK and d[v] > M[u][v]: d[v] = M[u][v] return sum(d) print((prim()))
26
26
705
698
from sys import stdin INF = float("inf") WHITE, GRAY, BLACK = 0, 1, 2 n = int(stdin.readline()) M = [[INF] * n for _ in range(n)] for i in range(0, n): for j, e in enumerate(list(map(int, stdin.readline().split()))): if e != -1: M[i][j] = e d = [INF] * n d[0] = 0 color = [0] * n def prim(): while True: minv = INF u = -1 for i in range(0, n): if minv > d[i] and color[i] != BLACK: u = i minv = d[i] if u == -1: break color[u] = BLACK for v in range(0, n): if color[v] != BLACK and d[v] > M[u][v]: d[v] = M[u][v] return sum(d) print((prim()))
from sys import stdin INF = 1 << 21 WHITE, GRAY, BLACK = 0, 1, 2 n = int(stdin.readline()) M = [[INF] * n for _ in range(n)] for i in range(0, n): for j, e in enumerate(list(map(int, stdin.readline().split()))): if e != -1: M[i][j] = e d = [INF] * n d[0] = 0 color = [0] * n def prim(): while True: minv = INF u = -1 for i in range(0, n): if minv > d[i] and color[i] != BLACK: u = i minv = d[i] if u == -1: break color[u] = BLACK for v in range(0, n): if color[v] != BLACK and d[v] > M[u][v]: d[v] = M[u][v] return sum(d) print((prim()))
false
0
[ "-INF = float(\"inf\")", "+INF = 1 << 21" ]
false
0.043188
0.045231
0.954832
[ "s658478414", "s197853134" ]
u562935282
p02873
python
s561541089
s987808858
235
195
49,224
46,448
Accepted
Accepted
17.02
# import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split()) def solve(s): n = len(s) t = [-1] * n if s[0] == '<': t[0] = 0 if s[-1] == '>': t[-1] == 0 for ind, (prev, after) in enumerate(zip(s, s[1:])): if prev + after == '><': t[ind + 1] = 0 ku = 0 hu = 0 ans = 0 for ind, c in enumerate(s): if t[ind] == 0: max_ = max(ku, hu) min_ = min(ku, hu) ans += (max_ + 1) * max_ // 2 ans += (min_ - 1) * min_ // 2 ku = 0 hu = 0 if c == '<': ku += 1 else: hu += 1 max_ = max(ku, hu) min_ = min(ku, hu) ans += (max_ + 1) * max_ // 2 ans += (min_ - 1) * min_ // 2 return ans if __name__ == '__main__': s = eval(input()) print((solve(s)))
s = eval(input()) n = len(s) a = [0] * (n + 1) for i in range(n): if s[i] == '<': a[i + 1] = max(a[i + 1], a[i] + 1) for i in range(n - 1, -1, -1): if s[i] == '>': a[i] = max(a[i], a[i + 1] + 1) print((sum(a)))
47
14
965
244
# import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split()) def solve(s): n = len(s) t = [-1] * n if s[0] == "<": t[0] = 0 if s[-1] == ">": t[-1] == 0 for ind, (prev, after) in enumerate(zip(s, s[1:])): if prev + after == "><": t[ind + 1] = 0 ku = 0 hu = 0 ans = 0 for ind, c in enumerate(s): if t[ind] == 0: max_ = max(ku, hu) min_ = min(ku, hu) ans += (max_ + 1) * max_ // 2 ans += (min_ - 1) * min_ // 2 ku = 0 hu = 0 if c == "<": ku += 1 else: hu += 1 max_ = max(ku, hu) min_ = min(ku, hu) ans += (max_ + 1) * max_ // 2 ans += (min_ - 1) * min_ // 2 return ans if __name__ == "__main__": s = eval(input()) print((solve(s)))
s = eval(input()) n = len(s) a = [0] * (n + 1) for i in range(n): if s[i] == "<": a[i + 1] = max(a[i + 1], a[i] + 1) for i in range(n - 1, -1, -1): if s[i] == ">": a[i] = max(a[i], a[i + 1] + 1) print((sum(a)))
false
70.212766
[ "-# import sys", "-#", "-# sys.setrecursionlimit(10 ** 7)", "-#", "-# input = sys.stdin.readline", "-# rstrip()", "-# int(input())", "-# map(int, input().split())", "-def solve(s):", "- n = len(s)", "- t = [-1] * n", "- if s[0] == \"<\":", "- t[0] = 0", "- if s[-1] == \">\":", "- t[-1] == 0", "- for ind, (prev, after) in enumerate(zip(s, s[1:])):", "- if prev + after == \"><\":", "- t[ind + 1] = 0", "- ku = 0", "- hu = 0", "- ans = 0", "- for ind, c in enumerate(s):", "- if t[ind] == 0:", "- max_ = max(ku, hu)", "- min_ = min(ku, hu)", "- ans += (max_ + 1) * max_ // 2", "- ans += (min_ - 1) * min_ // 2", "- ku = 0", "- hu = 0", "- if c == \"<\":", "- ku += 1", "- else:", "- hu += 1", "- max_ = max(ku, hu)", "- min_ = min(ku, hu)", "- ans += (max_ + 1) * max_ // 2", "- ans += (min_ - 1) * min_ // 2", "- return ans", "-", "-", "-if __name__ == \"__main__\":", "- s = eval(input())", "- print((solve(s)))", "+s = eval(input())", "+n = len(s)", "+a = [0] * (n + 1)", "+for i in range(n):", "+ if s[i] == \"<\":", "+ a[i + 1] = max(a[i + 1], a[i] + 1)", "+for i in range(n - 1, -1, -1):", "+ if s[i] == \">\":", "+ a[i] = max(a[i], a[i + 1] + 1)", "+print((sum(a)))" ]
false
0.043414
0.039114
1.109941
[ "s561541089", "s987808858" ]
u077291787
p03588
python
s963129639
s554791678
256
181
16,992
25,940
Accepted
Accepted
29.3
# tenka1-2017-beginnerB - Different Distribution import sys input = sys.stdin.readline def main(): n = int(eval(input())) A = sorted(tuple(map(int, input().rstrip().split())) for _ in range(n)) print((A[-1][0] + A[-1][1])) if __name__ == "__main__": main()
# tenka1-2017-beginnerB - Different Distribution def main(): N, *AB = list(map(int, open(0).read().split())) A = [(i, j) for i, j in zip(*[iter(AB)] * 2)] A.sort() ans = sum(A[-1]) print(ans) if __name__ == "__main__": main()
12
11
278
255
# tenka1-2017-beginnerB - Different Distribution import sys input = sys.stdin.readline def main(): n = int(eval(input())) A = sorted(tuple(map(int, input().rstrip().split())) for _ in range(n)) print((A[-1][0] + A[-1][1])) if __name__ == "__main__": main()
# tenka1-2017-beginnerB - Different Distribution def main(): N, *AB = list(map(int, open(0).read().split())) A = [(i, j) for i, j in zip(*[iter(AB)] * 2)] A.sort() ans = sum(A[-1]) print(ans) if __name__ == "__main__": main()
false
8.333333
[ "-import sys", "-", "-input = sys.stdin.readline", "-", "-", "- n = int(eval(input()))", "- A = sorted(tuple(map(int, input().rstrip().split())) for _ in range(n))", "- print((A[-1][0] + A[-1][1]))", "+ N, *AB = list(map(int, open(0).read().split()))", "+ A = [(i, j) for i, j in zip(*[iter(AB)] * 2)]", "+ A.sort()", "+ ans = sum(A[-1])", "+ print(ans)" ]
false
0.036315
0.036616
0.991792
[ "s963129639", "s554791678" ]
u146803137
p02547
python
s877680088
s471841851
33
29
9,348
9,204
Accepted
Accepted
12.12
import math ini = lambda : int(eval(input())) inm = lambda : list(map(int,input().split())) inl = lambda : list(map(int,input().split())) gcd = lambda x,y : gcd(y,x%y) if x%y else y def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) mod = 10**9 + 7 #maincode------------------------------------------------- n = ini() ans = 'No' c = 0 for i in range(n): a,b = inm() if a == b: c += 1 else: c = 0 if c >= 3: ans = 'Yes' print(ans)
import math ini = lambda : int(eval(input())) inm = lambda : list(map(int,input().split())) inl = lambda : list(map(int,input().split())) gcd = lambda x,y : gcd(y,x%y) if x%y else y def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) mod = 10**9 + 7 #maincode------------------------------------------------- n = int(eval(input())) x = [0 for i in range(n)] y = [0 for i in range(n)] ans = 'No' for i in range(n): x[i],y[i] = list(map(int,input().split())) for i in range(n-2): if (x[i] == y[i])and(x[i+1] == y[i+1])and(x[i+2] == y[i+2]): ans = 'Yes' print(ans)
92
92
2,233
2,330
import math ini = lambda: int(eval(input())) inm = lambda: list(map(int, input().split())) inl = lambda: list(map(int, input().split())) gcd = lambda x, y: gcd(y, x % y) if x % y else y def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return divisors class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) mod = 10**9 + 7 # maincode------------------------------------------------- n = ini() ans = "No" c = 0 for i in range(n): a, b = inm() if a == b: c += 1 else: c = 0 if c >= 3: ans = "Yes" print(ans)
import math ini = lambda: int(eval(input())) inm = lambda: list(map(int, input().split())) inl = lambda: list(map(int, input().split())) gcd = lambda x, y: gcd(y, x % y) if x % y else y def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return divisors class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) mod = 10**9 + 7 # maincode------------------------------------------------- n = int(eval(input())) x = [0 for i in range(n)] y = [0 for i in range(n)] ans = "No" for i in range(n): x[i], y[i] = list(map(int, input().split())) for i in range(n - 2): if (x[i] == y[i]) and (x[i + 1] == y[i + 1]) and (x[i + 2] == y[i + 2]): ans = "Yes" print(ans)
false
0
[ "-n = ini()", "+n = int(eval(input()))", "+x = [0 for i in range(n)]", "+y = [0 for i in range(n)]", "-c = 0", "- a, b = inm()", "- if a == b:", "- c += 1", "- else:", "- c = 0", "- if c >= 3:", "+ x[i], y[i] = list(map(int, input().split()))", "+for i in range(n - 2):", "+ if (x[i] == y[i]) and (x[i + 1] == y[i + 1]) and (x[i + 2] == y[i + 2]):" ]
false
0.045324
0.048356
0.937298
[ "s877680088", "s471841851" ]
u874644572
p02599
python
s321662766
s862067546
1,708
1,562
248,716
248,656
Accepted
Accepted
8.55
I=lambda:list(map(int,input().split())) N=0xfffff n,q=I() c=list(I()) Q=[] for i in range(q):l,r=I();Q.append(l<<40|r<<20|i) Q.sort() A=[[]for i in range(N)] for i,x in enumerate(c):A[x].append(i) B=[0]*N def P(i,x): i+=1 while i<=n:B[i]+=x;i+=i&-i def G(i): s=0 while i:s+=B[i];i-=i&-i return s for i in A: if i:P(i[0],1);i.reverse() t=0 o=[0]*q for x in Q: l=x>>40 r=x>>20&N i=x&N while t+1<l: b=A[c[t]] P(b[-1],-1) b.pop() if b:P(b[-1],1) t+=1 o[i]=G(r)-G(l-1) for i in o:print(i)
I=lambda:list(map(int,input().split())) N=0xfffff n,q=I() c=list(I()) Q=[] for i in range(q):l,r=I();Q.append(l<<40|r<<20|i) Q.sort() A=[[]for i in range(N)] for i in range(n):A[c[i]].append(i) B=[0]*N def P(i,x): i+=1 while i<=n:B[i]+=x;i+=i&-i def G(i): s=0 while i:s+=B[i];i-=i&-i return s for i in A: if i:P(i[0],1);i.reverse() t=0 o=[0]*q for x in Q: l=x>>40 r=x>>20&N i=x&N while t+1<l: b=A[c[t]] P(b[-1],-1) b.pop() if b:P(b[-1],1) t+=1 o[i]=G(r)-G(l-1) for i in o:print(i)
33
33
530
527
I = lambda: list(map(int, input().split())) N = 0xFFFFF n, q = I() c = list(I()) Q = [] for i in range(q): l, r = I() Q.append(l << 40 | r << 20 | i) Q.sort() A = [[] for i in range(N)] for i, x in enumerate(c): A[x].append(i) B = [0] * N def P(i, x): i += 1 while i <= n: B[i] += x i += i & -i def G(i): s = 0 while i: s += B[i] i -= i & -i return s for i in A: if i: P(i[0], 1) i.reverse() t = 0 o = [0] * q for x in Q: l = x >> 40 r = x >> 20 & N i = x & N while t + 1 < l: b = A[c[t]] P(b[-1], -1) b.pop() if b: P(b[-1], 1) t += 1 o[i] = G(r) - G(l - 1) for i in o: print(i)
I = lambda: list(map(int, input().split())) N = 0xFFFFF n, q = I() c = list(I()) Q = [] for i in range(q): l, r = I() Q.append(l << 40 | r << 20 | i) Q.sort() A = [[] for i in range(N)] for i in range(n): A[c[i]].append(i) B = [0] * N def P(i, x): i += 1 while i <= n: B[i] += x i += i & -i def G(i): s = 0 while i: s += B[i] i -= i & -i return s for i in A: if i: P(i[0], 1) i.reverse() t = 0 o = [0] * q for x in Q: l = x >> 40 r = x >> 20 & N i = x & N while t + 1 < l: b = A[c[t]] P(b[-1], -1) b.pop() if b: P(b[-1], 1) t += 1 o[i] = G(r) - G(l - 1) for i in o: print(i)
false
0
[ "-for i, x in enumerate(c):", "- A[x].append(i)", "+for i in range(n):", "+ A[c[i]].append(i)" ]
false
0.981075
1.148654
0.854109
[ "s321662766", "s862067546" ]
u785578220
p02594
python
s180249583
s177204404
29
26
9,156
9,056
Accepted
Accepted
10.34
a = int(eval(input())) if a >= 30 : print("Yes") else:print("No")
a = int(eval(input())) ans = "Yes" if a>= 30 else "No" print(ans)
4
3
66
61
a = int(eval(input())) if a >= 30: print("Yes") else: print("No")
a = int(eval(input())) ans = "Yes" if a >= 30 else "No" print(ans)
false
25
[ "-if a >= 30:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+ans = \"Yes\" if a >= 30 else \"No\"", "+print(ans)" ]
false
0.046663
0.110585
0.421967
[ "s180249583", "s177204404" ]
u222668979
p02691
python
s160842136
s079484100
233
211
62,856
61,328
Accepted
Accepted
9.44
import sys input = sys.stdin.readline def RunLengthEncoding(list): dict = {} for i in list: if i in list(dict.keys()): dict[i] += 1 else: dict[i] = 1 return dict n = int(eval(input())) a = list(map(int, input().split())) minus = [i-a[i] for i in range(n)] plus = [i+a[i] for i in range(n)] minus_cnt = RunLengthEncoding(minus) plus_cnt = RunLengthEncoding(plus) cnt=0 for i in minus_cnt: if i in plus_cnt: cnt += minus_cnt[i] * plus_cnt[i] print(cnt)
import sys input = sys.stdin.readline def rle(list): dict = {} for i in list: if i in list(dict.keys()): dict[i] += 1 else: dict[i] = 1 return dict n = int(eval(input())) a = list(map(int, input().split())) minus = rle([i-a[i] for i in range(n)]) plus = rle([i+a[i] for i in range(n)]) cnt = 0 for i in minus: if i in plus: cnt += minus[i] * plus[i] print(cnt)
26
24
533
441
import sys input = sys.stdin.readline def RunLengthEncoding(list): dict = {} for i in list: if i in list(dict.keys()): dict[i] += 1 else: dict[i] = 1 return dict n = int(eval(input())) a = list(map(int, input().split())) minus = [i - a[i] for i in range(n)] plus = [i + a[i] for i in range(n)] minus_cnt = RunLengthEncoding(minus) plus_cnt = RunLengthEncoding(plus) cnt = 0 for i in minus_cnt: if i in plus_cnt: cnt += minus_cnt[i] * plus_cnt[i] print(cnt)
import sys input = sys.stdin.readline def rle(list): dict = {} for i in list: if i in list(dict.keys()): dict[i] += 1 else: dict[i] = 1 return dict n = int(eval(input())) a = list(map(int, input().split())) minus = rle([i - a[i] for i in range(n)]) plus = rle([i + a[i] for i in range(n)]) cnt = 0 for i in minus: if i in plus: cnt += minus[i] * plus[i] print(cnt)
false
7.692308
[ "-def RunLengthEncoding(list):", "+def rle(list):", "-minus = [i - a[i] for i in range(n)]", "-plus = [i + a[i] for i in range(n)]", "-minus_cnt = RunLengthEncoding(minus)", "-plus_cnt = RunLengthEncoding(plus)", "+minus = rle([i - a[i] for i in range(n)])", "+plus = rle([i + a[i] for i in range(n)])", "-for i in minus_cnt:", "- if i in plus_cnt:", "- cnt += minus_cnt[i] * plus_cnt[i]", "+for i in minus:", "+ if i in plus:", "+ cnt += minus[i] * plus[i]" ]
false
0.046975
0.048173
0.975133
[ "s160842136", "s079484100" ]
u272525952
p02817
python
s386426741
s296399114
172
26
38,384
9,072
Accepted
Accepted
84.88
s,t=list(map(str,input().split())) print((t+s))
s,t=input().split() print((t+s))
2
2
41
31
s, t = list(map(str, input().split())) print((t + s))
s, t = input().split() print((t + s))
false
0
[ "-s, t = list(map(str, input().split()))", "+s, t = input().split()" ]
false
0.076378
0.054353
1.405226
[ "s386426741", "s296399114" ]
u054514819
p02983
python
s005807588
s390245068
612
71
75,332
66,888
Accepted
Accepted
88.4
L, R = list(map(int, input().split())) if R-L>2019: print((0)) else: lis = [] for i in range(L, R): for j in range(i+1, R+1): lis.append((i*j)%2019) print((min(lis)))
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) L, R = mapint() lis = [] for i in range(L, min(R+1, L+2101)): lis.append(i) leng = len(lis) ans = 10**18 for i in range(leng-1): a = lis[i] for j in range(i+1, leng): b = lis[j] ans = min(ans, (a*b)%2019) print(ans)
10
19
202
400
L, R = list(map(int, input().split())) if R - L > 2019: print((0)) else: lis = [] for i in range(L, R): for j in range(i + 1, R + 1): lis.append((i * j) % 2019) print((min(lis)))
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) L, R = mapint() lis = [] for i in range(L, min(R + 1, L + 2101)): lis.append(i) leng = len(lis) ans = 10**18 for i in range(leng - 1): a = lis[i] for j in range(i + 1, leng): b = lis[j] ans = min(ans, (a * b) % 2019) print(ans)
false
47.368421
[ "-L, R = list(map(int, input().split()))", "-if R - L > 2019:", "- print((0))", "-else:", "- lis = []", "- for i in range(L, R):", "- for j in range(i + 1, R + 1):", "- lis.append((i * j) % 2019)", "- print((min(lis)))", "+import sys", "+", "+", "+def input():", "+ return sys.stdin.readline().strip()", "+", "+", "+def mapint():", "+ return list(map(int, input().split()))", "+", "+", "+sys.setrecursionlimit(10**9)", "+L, R = mapint()", "+lis = []", "+for i in range(L, min(R + 1, L + 2101)):", "+ lis.append(i)", "+leng = len(lis)", "+ans = 10**18", "+for i in range(leng - 1):", "+ a = lis[i]", "+ for j in range(i + 1, leng):", "+ b = lis[j]", "+ ans = min(ans, (a * b) % 2019)", "+print(ans)" ]
false
0.126983
0.160095
0.793169
[ "s005807588", "s390245068" ]
u678167152
p03231
python
s105633495
s020568238
44
28
5,360
9,224
Accepted
Accepted
36.36
N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) from fractions import gcd def solve(N,M,S,T): g = gcd(N,M) for i in range(g): if S[N//g*i]!=T[M//g*i]: return -1 ans = N*M//g return ans print((solve(N,M,S,T)))
from math import gcd def solve(): N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) g = gcd(N,M) ans = N*M//g for i in range(g): if S[N//g*i]!=T[M//g*i]: return -1 return ans print((solve()))
14
12
266
231
N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) from fractions import gcd def solve(N, M, S, T): g = gcd(N, M) for i in range(g): if S[N // g * i] != T[M // g * i]: return -1 ans = N * M // g return ans print((solve(N, M, S, T)))
from math import gcd def solve(): N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) g = gcd(N, M) ans = N * M // g for i in range(g): if S[N // g * i] != T[M // g * i]: return -1 return ans print((solve()))
false
14.285714
[ "-N, M = list(map(int, input().split()))", "-S = eval(input())", "-T = eval(input())", "-from fractions import gcd", "+from math import gcd", "-def solve(N, M, S, T):", "+def solve():", "+ N, M = list(map(int, input().split()))", "+ S = eval(input())", "+ T = eval(input())", "+ ans = N * M // g", "- ans = N * M // g", "-print((solve(N, M, S, T)))", "+print((solve()))" ]
false
0.044189
0.103381
0.427442
[ "s105633495", "s020568238" ]
u579699847
p02732
python
s629611349
s344146835
1,672
337
121,264
26,780
Accepted
Accepted
79.84
import bisect,collections,copy,itertools,math,string def I(): return int(eval(input())) def S(): return eval(input()) def LI(): return list(map(int,input().split())) def LS(): return list(input().split()) ################################################## N = I() A = LI() _123 = [0]*N _123count = [0]*N for x in A: _123[x-1] += 1 _123copy = copy.copy(_123) _123copy.sort(reverse=True) _count = {} for i,x in enumerate(_123copy): if x==0: break if x==1: _123count[i] = 0 elif i!=0 and _123copy[i]==_123copy[i-1]: _123count[i] = _123count[i-1] else: _123count[i] = math.factorial(x)//((math.factorial(x-2))*(math.factorial(2))) _count[x] = _123count[i] _sum = sum(_123count) for x in A: temp = _123[x-1]-1 if temp<=0: print(_sum) elif temp==1: print((_sum-1)) else: if (temp+1) in _count: tempminus = _count[temp+1] else: tempminus = math.factorial(temp+1)//((math.factorial(temp-1))*(math.factorial(2))) _count[temp+1] = tempminus if (temp) in _count: tempplus = _count[temp] else: tempplus = math.factorial(temp)//((math.factorial(temp-2))*(math.factorial(2))) _count[temp] = tempplus print((_sum-tempminus+tempplus))
import collections def I(): return int(eval(input())) def LI(): return list(map(int,input().split())) ################################################## N = I() A = LI() count = collections.Counter(A) sum = 0 for x in list(count.values()): sum += x*(x-1)//2 for x in A: print((sum-(count[x]-1)))
44
12
1,350
300
import bisect, collections, copy, itertools, math, string def I(): return int(eval(input())) def S(): return eval(input()) def LI(): return list(map(int, input().split())) def LS(): return list(input().split()) ################################################## N = I() A = LI() _123 = [0] * N _123count = [0] * N for x in A: _123[x - 1] += 1 _123copy = copy.copy(_123) _123copy.sort(reverse=True) _count = {} for i, x in enumerate(_123copy): if x == 0: break if x == 1: _123count[i] = 0 elif i != 0 and _123copy[i] == _123copy[i - 1]: _123count[i] = _123count[i - 1] else: _123count[i] = math.factorial(x) // ( (math.factorial(x - 2)) * (math.factorial(2)) ) _count[x] = _123count[i] _sum = sum(_123count) for x in A: temp = _123[x - 1] - 1 if temp <= 0: print(_sum) elif temp == 1: print((_sum - 1)) else: if (temp + 1) in _count: tempminus = _count[temp + 1] else: tempminus = math.factorial(temp + 1) // ( (math.factorial(temp - 1)) * (math.factorial(2)) ) _count[temp + 1] = tempminus if (temp) in _count: tempplus = _count[temp] else: tempplus = math.factorial(temp) // ( (math.factorial(temp - 2)) * (math.factorial(2)) ) _count[temp] = tempplus print((_sum - tempminus + tempplus))
import collections def I(): return int(eval(input())) def LI(): return list(map(int, input().split())) ################################################## N = I() A = LI() count = collections.Counter(A) sum = 0 for x in list(count.values()): sum += x * (x - 1) // 2 for x in A: print((sum - (count[x] - 1)))
false
72.727273
[ "-import bisect, collections, copy, itertools, math, string", "+import collections", "-def S():", "- return eval(input())", "-", "-", "-", "-", "-def LS():", "- return list(input().split())", "-_123 = [0] * N", "-_123count = [0] * N", "+count = collections.Counter(A)", "+sum = 0", "+for x in list(count.values()):", "+ sum += x * (x - 1) // 2", "- _123[x - 1] += 1", "-_123copy = copy.copy(_123)", "-_123copy.sort(reverse=True)", "-_count = {}", "-for i, x in enumerate(_123copy):", "- if x == 0:", "- break", "- if x == 1:", "- _123count[i] = 0", "- elif i != 0 and _123copy[i] == _123copy[i - 1]:", "- _123count[i] = _123count[i - 1]", "- else:", "- _123count[i] = math.factorial(x) // (", "- (math.factorial(x - 2)) * (math.factorial(2))", "- )", "- _count[x] = _123count[i]", "-_sum = sum(_123count)", "-for x in A:", "- temp = _123[x - 1] - 1", "- if temp <= 0:", "- print(_sum)", "- elif temp == 1:", "- print((_sum - 1))", "- else:", "- if (temp + 1) in _count:", "- tempminus = _count[temp + 1]", "- else:", "- tempminus = math.factorial(temp + 1) // (", "- (math.factorial(temp - 1)) * (math.factorial(2))", "- )", "- _count[temp + 1] = tempminus", "- if (temp) in _count:", "- tempplus = _count[temp]", "- else:", "- tempplus = math.factorial(temp) // (", "- (math.factorial(temp - 2)) * (math.factorial(2))", "- )", "- _count[temp] = tempplus", "- print((_sum - tempminus + tempplus))", "+ print((sum - (count[x] - 1)))" ]
false
0.044968
0.045468
0.988997
[ "s629611349", "s344146835" ]
u620945921
p03243
python
s799930756
s046599466
20
18
2,940
2,940
Accepted
Accepted
10
n=int(eval(input())) ans=999 for i in range(n,1000): if i%111==0: if i<=ans: ans=i print(ans)
n=int(eval(input())) if n%111==0: ans=n else: while n%111>0: n+=1 ans=n print(ans)
9
11
116
106
n = int(eval(input())) ans = 999 for i in range(n, 1000): if i % 111 == 0: if i <= ans: ans = i print(ans)
n = int(eval(input())) if n % 111 == 0: ans = n else: while n % 111 > 0: n += 1 ans = n print(ans)
false
18.181818
[ "-ans = 999", "-for i in range(n, 1000):", "- if i % 111 == 0:", "- if i <= ans:", "- ans = i", "+if n % 111 == 0:", "+ ans = n", "+else:", "+ while n % 111 > 0:", "+ n += 1", "+ ans = n" ]
false
0.039045
0.037192
1.049814
[ "s799930756", "s046599466" ]
u219197917
p03013
python
s788243758
s086267659
159
76
9,616
17,540
Accepted
Accepted
52.2
import sys def input(): return sys.stdin.readline().rstrip() mod = 10**9 + 7 n, m = [int(i) for i in input().split()] a = [int(eval(input())) for _ in range(m)] notin = [1] * n for i in a: notin[i] = 0 dp = [0] * n dp[n - 1] = 1 if n > 1: dp[n - 2] = 1 + notin[n - 1] for i in range(n - 3, -1, -1): dp[i] += dp[i + 1] * notin[i + 1] % mod dp[i] += dp[i + 2] * notin[i + 2] % mod dp[i] %= mod print((dp[0]))
import sys def read(): return sys.stdin.readline().rstrip() def main(): n, m = list(map(int, read().split())) a = {int(read()) - 1 for _ in range(m)} if n == 1: print((1)) return mod = 10**9 + 7 dp = [0] * n if 0 not in a: dp[0] = 1 if 1 not in a: dp[1] = 1 + dp[0] for i in range(2, n): if i in a: continue dp[i] = (dp[i - 1] + dp[i - 2]) % mod print((dp[-1])) if __name__ == '__main__': main()
18
28
426
523
import sys def input(): return sys.stdin.readline().rstrip() mod = 10**9 + 7 n, m = [int(i) for i in input().split()] a = [int(eval(input())) for _ in range(m)] notin = [1] * n for i in a: notin[i] = 0 dp = [0] * n dp[n - 1] = 1 if n > 1: dp[n - 2] = 1 + notin[n - 1] for i in range(n - 3, -1, -1): dp[i] += dp[i + 1] * notin[i + 1] % mod dp[i] += dp[i + 2] * notin[i + 2] % mod dp[i] %= mod print((dp[0]))
import sys def read(): return sys.stdin.readline().rstrip() def main(): n, m = list(map(int, read().split())) a = {int(read()) - 1 for _ in range(m)} if n == 1: print((1)) return mod = 10**9 + 7 dp = [0] * n if 0 not in a: dp[0] = 1 if 1 not in a: dp[1] = 1 + dp[0] for i in range(2, n): if i in a: continue dp[i] = (dp[i - 1] + dp[i - 2]) % mod print((dp[-1])) if __name__ == "__main__": main()
false
35.714286
[ "-def input():", "+def read():", "-mod = 10**9 + 7", "-n, m = [int(i) for i in input().split()]", "-a = [int(eval(input())) for _ in range(m)]", "-notin = [1] * n", "-for i in a:", "- notin[i] = 0", "-dp = [0] * n", "-dp[n - 1] = 1", "-if n > 1:", "- dp[n - 2] = 1 + notin[n - 1]", "-for i in range(n - 3, -1, -1):", "- dp[i] += dp[i + 1] * notin[i + 1] % mod", "- dp[i] += dp[i + 2] * notin[i + 2] % mod", "- dp[i] %= mod", "-print((dp[0]))", "+def main():", "+ n, m = list(map(int, read().split()))", "+ a = {int(read()) - 1 for _ in range(m)}", "+ if n == 1:", "+ print((1))", "+ return", "+ mod = 10**9 + 7", "+ dp = [0] * n", "+ if 0 not in a:", "+ dp[0] = 1", "+ if 1 not in a:", "+ dp[1] = 1 + dp[0]", "+ for i in range(2, n):", "+ if i in a:", "+ continue", "+ dp[i] = (dp[i - 1] + dp[i - 2]) % mod", "+ print((dp[-1]))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.061559
0.037687
1.633446
[ "s788243758", "s086267659" ]
u844945939
p00881
python
s570525710
s183187505
4,250
3,630
72,584
15,080
Accepted
Accepted
14.59
from collections import Counter while True: m, n = (int(s) for s in input().split()) if not m: break objs = [int(eval(input()), 2) for i in range(n)] dp = [[0] * (1 << m) for i in range(1 << m)] bits = [1 << i for i in range(m)] for mask in reversed(list(range(1 << m))): s = Counter(obj & mask for obj in objs) for masked, value in list(s.items()): if value > 1: dp[mask][masked] = min(max(dp[mask | b][masked], dp[mask | b][masked | b]) + 1 for b in bits if not b & mask) print((dp[0][0]))
from collections import Counter while True: m, n = (int(s) for s in input().split()) if not m: break objs = [int(eval(input()), 2) for i in range(n)] dp = [bytearray(1 << m) for i in range(1 << m)] bits = [1 << i for i in range(m)] for mask in reversed(list(range((1 << m) - 1))): s = Counter(obj & mask for obj in objs) for masked, count in list(s.items()): if count > 1: dp[mask][masked] = min(max(dp[mask + b][masked], dp[mask + b][masked + b]) + 1 for b in bits if not b & mask) print((dp[0][0]))
20
20
656
665
from collections import Counter while True: m, n = (int(s) for s in input().split()) if not m: break objs = [int(eval(input()), 2) for i in range(n)] dp = [[0] * (1 << m) for i in range(1 << m)] bits = [1 << i for i in range(m)] for mask in reversed(list(range(1 << m))): s = Counter(obj & mask for obj in objs) for masked, value in list(s.items()): if value > 1: dp[mask][masked] = min( max(dp[mask | b][masked], dp[mask | b][masked | b]) + 1 for b in bits if not b & mask ) print((dp[0][0]))
from collections import Counter while True: m, n = (int(s) for s in input().split()) if not m: break objs = [int(eval(input()), 2) for i in range(n)] dp = [bytearray(1 << m) for i in range(1 << m)] bits = [1 << i for i in range(m)] for mask in reversed(list(range((1 << m) - 1))): s = Counter(obj & mask for obj in objs) for masked, count in list(s.items()): if count > 1: dp[mask][masked] = min( max(dp[mask + b][masked], dp[mask + b][masked + b]) + 1 for b in bits if not b & mask ) print((dp[0][0]))
false
0
[ "- dp = [[0] * (1 << m) for i in range(1 << m)]", "+ dp = [bytearray(1 << m) for i in range(1 << m)]", "- for mask in reversed(list(range(1 << m))):", "+ for mask in reversed(list(range((1 << m) - 1))):", "- for masked, value in list(s.items()):", "- if value > 1:", "+ for masked, count in list(s.items()):", "+ if count > 1:", "- max(dp[mask | b][masked], dp[mask | b][masked | b]) + 1", "+ max(dp[mask + b][masked], dp[mask + b][masked + b]) + 1" ]
false
0.036662
0.036564
1.002685
[ "s570525710", "s183187505" ]
u645250356
p02821
python
s023816074
s799414232
1,565
493
86,084
93,312
Accepted
Accepted
68.5
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n,m = inpl() a = sorted(inpl()) ng = 10**9+1 ok = -1 def sol(x): cnt = 0 for i,t in enumerate(a): tmp = x - t c = bisect.bisect_left(a,tmp) cnt += n-c return True if cnt >= m else False while ng-ok > 1: mid = (ng+ok)//2 if sol(mid): ok = mid else: ng = mid # print(ok,ng) # print(ok) res = 0 cnt = 0 revc = [0] for i in range(n)[::-1]: revc.append(revc[-1] + a[i]) # print(revc) for i in range(n): j = n-bisect.bisect_left(a,ok-a[i]) res += j*a[i] + revc[j] cnt += j res -= (cnt-m) * ok print(res)
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n,m = inpl() a = inpl(); a.sort() ok = a[0] + a[0] - 1 ng = a[-1] + a[-1] + 1 def sol(x): res = 0 for i in range(n): y = x-a[i] res += n-bisect_left(a,y) return True if res >= m else False while abs(ok-ng) > 1: mid = (ok+ng)//2 if sol(mid): ok = mid else: ng = mid b = [0] for i in range(n)[::-1]: b.append(b[-1]+a[i]) res = 0 cnt = 0 # print(b,ok) for x in a: ind = n-bisect_left(a,ok-x) cnt += ind res += b[ind] + x*ind print((res-(cnt-m)*ok))
40
37
927
896
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify import sys, bisect, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n, m = inpl() a = sorted(inpl()) ng = 10**9 + 1 ok = -1 def sol(x): cnt = 0 for i, t in enumerate(a): tmp = x - t c = bisect.bisect_left(a, tmp) cnt += n - c return True if cnt >= m else False while ng - ok > 1: mid = (ng + ok) // 2 if sol(mid): ok = mid else: ng = mid # print(ok,ng) # print(ok) res = 0 cnt = 0 revc = [0] for i in range(n)[::-1]: revc.append(revc[-1] + a[i]) # print(revc) for i in range(n): j = n - bisect.bisect_left(a, ok - a[i]) res += j * a[i] + revc[j] cnt += j res -= (cnt - m) * ok print(res)
from collections import Counter, defaultdict, deque from heapq import heappop, heappush from bisect import bisect_left, bisect_right import sys, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n, m = inpl() a = inpl() a.sort() ok = a[0] + a[0] - 1 ng = a[-1] + a[-1] + 1 def sol(x): res = 0 for i in range(n): y = x - a[i] res += n - bisect_left(a, y) return True if res >= m else False while abs(ok - ng) > 1: mid = (ok + ng) // 2 if sol(mid): ok = mid else: ng = mid b = [0] for i in range(n)[::-1]: b.append(b[-1] + a[i]) res = 0 cnt = 0 # print(b,ok) for x in a: ind = n - bisect_left(a, ok - x) cnt += ind res += b[ind] + x * ind print((res - (cnt - m) * ok))
false
7.5
[ "-from heapq import heappop, heappush, heapify", "-import sys, bisect, math, itertools, fractions, pprint", "+from heapq import heappop, heappush", "+from bisect import bisect_left, bisect_right", "+import sys, math, itertools, fractions, pprint", "-a = sorted(inpl())", "-ng = 10**9 + 1", "-ok = -1", "+a = inpl()", "+a.sort()", "+ok = a[0] + a[0] - 1", "+ng = a[-1] + a[-1] + 1", "- cnt = 0", "- for i, t in enumerate(a):", "- tmp = x - t", "- c = bisect.bisect_left(a, tmp)", "- cnt += n - c", "- return True if cnt >= m else False", "+ res = 0", "+ for i in range(n):", "+ y = x - a[i]", "+ res += n - bisect_left(a, y)", "+ return True if res >= m else False", "-while ng - ok > 1:", "- mid = (ng + ok) // 2", "+while abs(ok - ng) > 1:", "+ mid = (ok + ng) // 2", "- # print(ok,ng)", "-# print(ok)", "+b = [0]", "+for i in range(n)[::-1]:", "+ b.append(b[-1] + a[i])", "-revc = [0]", "-for i in range(n)[::-1]:", "- revc.append(revc[-1] + a[i])", "-# print(revc)", "-for i in range(n):", "- j = n - bisect.bisect_left(a, ok - a[i])", "- res += j * a[i] + revc[j]", "- cnt += j", "-res -= (cnt - m) * ok", "-print(res)", "+# print(b,ok)", "+for x in a:", "+ ind = n - bisect_left(a, ok - x)", "+ cnt += ind", "+ res += b[ind] + x * ind", "+print((res - (cnt - m) * ok))" ]
false
0.045288
0.112015
0.404306
[ "s023816074", "s799414232" ]
u111365362
p02939
python
s165887512
s825854802
103
85
3,500
11,492
Accepted
Accepted
17.48
s = eval(input()) n = len(s) ans = 1 last = s[0] i = 1 while i < n: if len(last) == 2: last = s[i] i += 1 else: if s[i] != last: last = s[i] i += 1 else: if i != n-1: last = s[i:i+2] i += 2 else: break ans += 1 #print(last,ans) print(ans)
#15:00(2) s = eval(input()) n = len(s) dp = [-1,0,1] for i in range(1,n): if s[i-1] != s[i]: dp.append(dp[-1]+1) else: dp.append(dp[-3]+2) print((dp[-1]))
22
10
325
167
s = eval(input()) n = len(s) ans = 1 last = s[0] i = 1 while i < n: if len(last) == 2: last = s[i] i += 1 else: if s[i] != last: last = s[i] i += 1 else: if i != n - 1: last = s[i : i + 2] i += 2 else: break ans += 1 # print(last,ans) print(ans)
# 15:00(2) s = eval(input()) n = len(s) dp = [-1, 0, 1] for i in range(1, n): if s[i - 1] != s[i]: dp.append(dp[-1] + 1) else: dp.append(dp[-3] + 2) print((dp[-1]))
false
54.545455
[ "+# 15:00(2)", "-ans = 1", "-last = s[0]", "-i = 1", "-while i < n:", "- if len(last) == 2:", "- last = s[i]", "- i += 1", "+dp = [-1, 0, 1]", "+for i in range(1, n):", "+ if s[i - 1] != s[i]:", "+ dp.append(dp[-1] + 1)", "- if s[i] != last:", "- last = s[i]", "- i += 1", "- else:", "- if i != n - 1:", "- last = s[i : i + 2]", "- i += 2", "- else:", "- break", "- ans += 1", "- # print(last,ans)", "-print(ans)", "+ dp.append(dp[-3] + 2)", "+print((dp[-1]))" ]
false
0.045935
0.046808
0.98135
[ "s165887512", "s825854802" ]
u858748695
p03017
python
s305359016
s239609478
111
36
4,984
3,572
Accepted
Accepted
67.57
#!/usr/bin/env python3 n, a, b, c, d = [int(x) - 1 for x in input().split()] s = list(eval(input())) if d < c: s[b] = 'b' while a < b: if a + 1 <= c and s[a + 1] == '.': a += 1 elif a + 2 <= c and s[a + 2] == '.': a += 2 elif b < d: if b + 1 <= d and s[b + 1] == '.': s[b] = '.' s[b + 1] = 'b' b += 1 elif b + 2 <= d and s[b + 2] == '.': s[b] = '.' s[b + 2] = 'b' b += 2 else: print('No') exit() else: print('No') exit() a, b = b, a c, d = d, c while b < d: if b + 1 <= d and s[b + 1] == '.': b += 1 elif b + 2 <= d and s[b + 2] == '.': b += 2 else: print('No') exit() while a < c: if a + 1 <= c and s[a + 1] == '.': a += 1 elif a + 2 <= c and s[a + 2] == '.': a += 2 else: print('No') exit() print('Yes')
#!/usr/bin/env python3 n, a, b, c, d = [int(x) - 1 for x in input().split()] s = eval(input()) if d < c: f = False for i in range(n)[b:d + 1]: if '...' in s[i - 1:i + 2]: f = True if not f: print('No') exit() a, b = b, a c, d = d, c print((['Yes', 'No']['##' in s[a:d + 1]]))
45
15
1,098
344
#!/usr/bin/env python3 n, a, b, c, d = [int(x) - 1 for x in input().split()] s = list(eval(input())) if d < c: s[b] = "b" while a < b: if a + 1 <= c and s[a + 1] == ".": a += 1 elif a + 2 <= c and s[a + 2] == ".": a += 2 elif b < d: if b + 1 <= d and s[b + 1] == ".": s[b] = "." s[b + 1] = "b" b += 1 elif b + 2 <= d and s[b + 2] == ".": s[b] = "." s[b + 2] = "b" b += 2 else: print("No") exit() else: print("No") exit() a, b = b, a c, d = d, c while b < d: if b + 1 <= d and s[b + 1] == ".": b += 1 elif b + 2 <= d and s[b + 2] == ".": b += 2 else: print("No") exit() while a < c: if a + 1 <= c and s[a + 1] == ".": a += 1 elif a + 2 <= c and s[a + 2] == ".": a += 2 else: print("No") exit() print("Yes")
#!/usr/bin/env python3 n, a, b, c, d = [int(x) - 1 for x in input().split()] s = eval(input()) if d < c: f = False for i in range(n)[b : d + 1]: if "..." in s[i - 1 : i + 2]: f = True if not f: print("No") exit() a, b = b, a c, d = d, c print((["Yes", "No"]["##" in s[a : d + 1]]))
false
66.666667
[ "-s = list(eval(input()))", "+s = eval(input())", "- s[b] = \"b\"", "- while a < b:", "- if a + 1 <= c and s[a + 1] == \".\":", "- a += 1", "- elif a + 2 <= c and s[a + 2] == \".\":", "- a += 2", "- elif b < d:", "- if b + 1 <= d and s[b + 1] == \".\":", "- s[b] = \".\"", "- s[b + 1] = \"b\"", "- b += 1", "- elif b + 2 <= d and s[b + 2] == \".\":", "- s[b] = \".\"", "- s[b + 2] = \"b\"", "- b += 2", "- else:", "- print(\"No\")", "- exit()", "- else:", "- print(\"No\")", "- exit()", "+ f = False", "+ for i in range(n)[b : d + 1]:", "+ if \"...\" in s[i - 1 : i + 2]:", "+ f = True", "+ if not f:", "+ print(\"No\")", "+ exit()", "-while b < d:", "- if b + 1 <= d and s[b + 1] == \".\":", "- b += 1", "- elif b + 2 <= d and s[b + 2] == \".\":", "- b += 2", "- else:", "- print(\"No\")", "- exit()", "-while a < c:", "- if a + 1 <= c and s[a + 1] == \".\":", "- a += 1", "- elif a + 2 <= c and s[a + 2] == \".\":", "- a += 2", "- else:", "- print(\"No\")", "- exit()", "-print(\"Yes\")", "+print(([\"Yes\", \"No\"][\"##\" in s[a : d + 1]]))" ]
false
0.035218
0.037675
0.934768
[ "s305359016", "s239609478" ]
u844646164
p03659
python
s143258639
s758110570
208
159
24,832
30,544
Accepted
Accepted
23.56
n = int(eval(input())) a = list(map(int, input().split())) cumsum = [a[0]] for i in range(len(a)-1): cumsum.append(cumsum[i] + a[i+1]) min = float('inf') for i in range(len(cumsum)-1): f1 = cumsum[i] f2 = cumsum[-1] - cumsum[i] d = abs(f1 - f2) if min > d: min = d print(min)
N = int(eval(input())) a = list(map(int, input().split())) sa = a[:] for i in range(N-1): sa[i+1] += sa[i] diff = float('inf') for i in range(N-1): if abs(sa[i] - (sa[-1] - sa[i])) < diff: diff = abs(sa[i] - (sa[-1] - sa[i])) print(diff)
15
12
300
252
n = int(eval(input())) a = list(map(int, input().split())) cumsum = [a[0]] for i in range(len(a) - 1): cumsum.append(cumsum[i] + a[i + 1]) min = float("inf") for i in range(len(cumsum) - 1): f1 = cumsum[i] f2 = cumsum[-1] - cumsum[i] d = abs(f1 - f2) if min > d: min = d print(min)
N = int(eval(input())) a = list(map(int, input().split())) sa = a[:] for i in range(N - 1): sa[i + 1] += sa[i] diff = float("inf") for i in range(N - 1): if abs(sa[i] - (sa[-1] - sa[i])) < diff: diff = abs(sa[i] - (sa[-1] - sa[i])) print(diff)
false
20
[ "-n = int(eval(input()))", "+N = int(eval(input()))", "-cumsum = [a[0]]", "-for i in range(len(a) - 1):", "- cumsum.append(cumsum[i] + a[i + 1])", "-min = float(\"inf\")", "-for i in range(len(cumsum) - 1):", "- f1 = cumsum[i]", "- f2 = cumsum[-1] - cumsum[i]", "- d = abs(f1 - f2)", "- if min > d:", "- min = d", "-print(min)", "+sa = a[:]", "+for i in range(N - 1):", "+ sa[i + 1] += sa[i]", "+diff = float(\"inf\")", "+for i in range(N - 1):", "+ if abs(sa[i] - (sa[-1] - sa[i])) < diff:", "+ diff = abs(sa[i] - (sa[-1] - sa[i]))", "+print(diff)" ]
false
0.038137
0.0411
0.927909
[ "s143258639", "s758110570" ]
u013629972
p03089
python
s211963576
s594009969
394
315
65,644
66,924
Accepted
Accepted
20.05
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10 ** 20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def pf(s): return print(s, flush=True) N = I() b = LI() result = [] while True: # print(b) for i in range(1, len(b)+1): # print(i) if b[-i] == len(b)-i+1: # print('break') result.append(b[-i]) del b[-i] break else: if not b: break print(-1) exit() for i in result[::-1]: print(i)
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10 ** 20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def pf(s): return print(s, flush=True) N = I() b = LI() result = [] while True: # print(b) for i in range(1, len(b)+1): # print(i) if b[-i] == len(b)-i+1: # print('break') result.append(b[-i]) b.pop(-i) break else: if not b: break print(-1) exit() for i in result[::-1]: print(i)
36
37
1,078
1,080
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def pf(s): return print(s, flush=True) N = I() b = LI() result = [] while True: # print(b) for i in range(1, len(b) + 1): # print(i) if b[-i] == len(b) - i + 1: # print('break') result.append(b[-i]) del b[-i] break else: if not b: break print(-1) exit() for i in result[::-1]: print(i)
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def pf(s): return print(s, flush=True) N = I() b = LI() result = [] while True: # print(b) for i in range(1, len(b) + 1): # print(i) if b[-i] == len(b) - i + 1: # print('break') result.append(b[-i]) b.pop(-i) break else: if not b: break print(-1) exit() for i in result[::-1]: print(i)
false
2.702703
[ "- del b[-i]", "+ b.pop(-i)" ]
false
0.041456
0.042315
0.97971
[ "s211963576", "s594009969" ]
u583507988
p03262
python
s096406101
s505256213
139
87
20,516
20,300
Accepted
Accepted
37.41
from math import gcd n, x = list(map(int, input().split())) m = [x]+list(map(int, input().split())) m.sort() if n==1: print((m[1]-m[0])) else: res = gcd(m[1]-m[0], m[2]-m[1]) for i in range(1, n-1): a = m[i+1]-m[i] b = m[i+2]-m[i+1] if res >= gcd(a,b): if res%gcd(a,b)==0: res = gcd(a,b) else: res = gcd(res, gcd(a, b)) else: if gcd(a,b)%res!=0: res = gcd(res, gcd(a, b)) print(res)
import math n,a=list(map(int,input().split())) x=list(map(int,input().split()))+[a] x.sort() if n==1: print((abs(x[0]-x[1]))) exit() res=x[1]-x[0] for i in range(1,n): res=math.gcd(res,x[i+1]-x[i]) print(res)
23
11
465
216
from math import gcd n, x = list(map(int, input().split())) m = [x] + list(map(int, input().split())) m.sort() if n == 1: print((m[1] - m[0])) else: res = gcd(m[1] - m[0], m[2] - m[1]) for i in range(1, n - 1): a = m[i + 1] - m[i] b = m[i + 2] - m[i + 1] if res >= gcd(a, b): if res % gcd(a, b) == 0: res = gcd(a, b) else: res = gcd(res, gcd(a, b)) else: if gcd(a, b) % res != 0: res = gcd(res, gcd(a, b)) print(res)
import math n, a = list(map(int, input().split())) x = list(map(int, input().split())) + [a] x.sort() if n == 1: print((abs(x[0] - x[1]))) exit() res = x[1] - x[0] for i in range(1, n): res = math.gcd(res, x[i + 1] - x[i]) print(res)
false
52.173913
[ "-from math import gcd", "+import math", "-n, x = list(map(int, input().split()))", "-m = [x] + list(map(int, input().split()))", "-m.sort()", "+n, a = list(map(int, input().split()))", "+x = list(map(int, input().split())) + [a]", "+x.sort()", "- print((m[1] - m[0]))", "-else:", "- res = gcd(m[1] - m[0], m[2] - m[1])", "- for i in range(1, n - 1):", "- a = m[i + 1] - m[i]", "- b = m[i + 2] - m[i + 1]", "- if res >= gcd(a, b):", "- if res % gcd(a, b) == 0:", "- res = gcd(a, b)", "- else:", "- res = gcd(res, gcd(a, b))", "- else:", "- if gcd(a, b) % res != 0:", "- res = gcd(res, gcd(a, b))", "- print(res)", "+ print((abs(x[0] - x[1])))", "+ exit()", "+res = x[1] - x[0]", "+for i in range(1, n):", "+ res = math.gcd(res, x[i + 1] - x[i])", "+print(res)" ]
false
0.036247
0.082466
0.439541
[ "s096406101", "s505256213" ]
u173178698
p02583
python
s079565582
s063531615
196
139
20,596
20,524
Accepted
Accepted
29.08
import itertools n = int(eval(input())) l = list(map(int, input().split())) count = 0 ind_list = list(itertools.combinations(list(range(0,n)), 3)) for ind in ind_list: if (l[ind[0]]+l[ind[1]])>l[ind[2]] and (l[ind[1]]+l[ind[2]])>l[ind[0]] and (l[ind[2]]+l[ind[0]])>l[ind[1]]: if l[ind[0]]!=l[ind[1]] and l[ind[0]]!=l[ind[2]] and l[ind[1]]!=l[ind[2]]: count += 1 print(count)
import itertools n = int(eval(input())) l = list(map(int, input().split())) count = 0 c_list = list(itertools.combinations(l, 3)) for c in c_list: if (c[0]+c[1])>c[2] and (c[1]+c[2])>c[0] and (c[2]+c[0])>c[1]: if len(set(c)) == 3: count += 1 print(count)
12
12
403
285
import itertools n = int(eval(input())) l = list(map(int, input().split())) count = 0 ind_list = list(itertools.combinations(list(range(0, n)), 3)) for ind in ind_list: if ( (l[ind[0]] + l[ind[1]]) > l[ind[2]] and (l[ind[1]] + l[ind[2]]) > l[ind[0]] and (l[ind[2]] + l[ind[0]]) > l[ind[1]] ): if l[ind[0]] != l[ind[1]] and l[ind[0]] != l[ind[2]] and l[ind[1]] != l[ind[2]]: count += 1 print(count)
import itertools n = int(eval(input())) l = list(map(int, input().split())) count = 0 c_list = list(itertools.combinations(l, 3)) for c in c_list: if (c[0] + c[1]) > c[2] and (c[1] + c[2]) > c[0] and (c[2] + c[0]) > c[1]: if len(set(c)) == 3: count += 1 print(count)
false
0
[ "-ind_list = list(itertools.combinations(list(range(0, n)), 3))", "-for ind in ind_list:", "- if (", "- (l[ind[0]] + l[ind[1]]) > l[ind[2]]", "- and (l[ind[1]] + l[ind[2]]) > l[ind[0]]", "- and (l[ind[2]] + l[ind[0]]) > l[ind[1]]", "- ):", "- if l[ind[0]] != l[ind[1]] and l[ind[0]] != l[ind[2]] and l[ind[1]] != l[ind[2]]:", "+c_list = list(itertools.combinations(l, 3))", "+for c in c_list:", "+ if (c[0] + c[1]) > c[2] and (c[1] + c[2]) > c[0] and (c[2] + c[0]) > c[1]:", "+ if len(set(c)) == 3:" ]
false
0.039379
0.036289
1.085165
[ "s079565582", "s063531615" ]
u411203878
p03524
python
s515169925
s126165147
193
81
49,392
77,824
Accepted
Accepted
58.03
import collections s=eval(input()) s=list(s) c = collections.Counter(s) score_sorted = sorted(list(c.items()), key=lambda x:-x[1]) val = [] for i, j in score_sorted: val.append(j) if len(val) == 2: val.append(0) elif len(val) == 1: val.append(0) val.append(0) val.sort() if 0<= val[2]-val[0] <=1: print('YES') else: print('NO')
import collections s=list(eval(input())) c = collections.Counter(s) score_sorted = sorted(list(c.items()), key=lambda x:-x[1]) val = [] for i, j in score_sorted: val.append(j) if len(val) == 2: val.append(0) elif len(val) == 1: val.append(0) val.append(0) val.sort() if 0<= val[2]-val[0] <=1: print('YES') else: print('NO')
28
25
380
372
import collections s = eval(input()) s = list(s) c = collections.Counter(s) score_sorted = sorted(list(c.items()), key=lambda x: -x[1]) val = [] for i, j in score_sorted: val.append(j) if len(val) == 2: val.append(0) elif len(val) == 1: val.append(0) val.append(0) val.sort() if 0 <= val[2] - val[0] <= 1: print("YES") else: print("NO")
import collections s = list(eval(input())) c = collections.Counter(s) score_sorted = sorted(list(c.items()), key=lambda x: -x[1]) val = [] for i, j in score_sorted: val.append(j) if len(val) == 2: val.append(0) elif len(val) == 1: val.append(0) val.append(0) val.sort() if 0 <= val[2] - val[0] <= 1: print("YES") else: print("NO")
false
10.714286
[ "-s = eval(input())", "-s = list(s)", "+s = list(eval(input()))" ]
false
0.04923
0.047823
1.029416
[ "s515169925", "s126165147" ]
u173148629
p02669
python
s518675663
s048530087
264
225
11,020
11,524
Accepted
Accepted
14.77
import sys sys.setrecursionlimit(10**8) T=int(eval(input())) def solve(N): if N==0: return 0 if N==1: return D if N in dic: return dic[N] tmp=N*D if N%2==0: tmp=min(tmp,solve(N//2)+A) else: tmp=min(tmp,solve((N-1)//2)+A+D,solve((N+1)//2)+A+D) if N%3==0: tmp=min(tmp,solve(N//3)+B) else: b=N%3 tmp=min(tmp,solve((N+(3-b))//3)+B+(3-b)*D,solve((N-b)//3)+B+b*D) if N%5==0: tmp=min(tmp,solve(N//5)+C) else: c=N%5 tmp=min(tmp,solve((N-c)//5)+C+D*c,solve((N+(5-c))//5)+C+D*(5-c)) dic[N]=tmp return tmp for _ in range(T): N,A,B,C,D=list(map(int,input().split())) dic={} print((solve(N)))
T=int(eval(input())) from functools import lru_cache for _ in range(T): N,A,B,C,D=list(map(int,input().split())) @lru_cache(maxsize=None) def solve(N): if N==0: return 0 if N==1: return D tmp=N*D if N%2==0: tmp=min(tmp,solve(N//2)+A) else: tmp=min(tmp,solve((N-1)//2)+A+D,solve((N+1)//2)+A+D) if N%3==0: tmp=min(tmp,solve(N//3)+B) else: b=N%3 tmp=min(tmp,solve((N+(3-b))//3)+B+(3-b)*D,solve((N-b)//3)+B+b*D) if N%5==0: tmp=min(tmp,solve(N//5)+C) else: c=N%5 tmp=min(tmp,solve((N-c)//5)+C+D*c,solve((N+(5-c))//5)+C+D*(5-c)) return tmp print((solve(N)))
33
29
753
791
import sys sys.setrecursionlimit(10**8) T = int(eval(input())) def solve(N): if N == 0: return 0 if N == 1: return D if N in dic: return dic[N] tmp = N * D if N % 2 == 0: tmp = min(tmp, solve(N // 2) + A) else: tmp = min(tmp, solve((N - 1) // 2) + A + D, solve((N + 1) // 2) + A + D) if N % 3 == 0: tmp = min(tmp, solve(N // 3) + B) else: b = N % 3 tmp = min( tmp, solve((N + (3 - b)) // 3) + B + (3 - b) * D, solve((N - b) // 3) + B + b * D, ) if N % 5 == 0: tmp = min(tmp, solve(N // 5) + C) else: c = N % 5 tmp = min( tmp, solve((N - c) // 5) + C + D * c, solve((N + (5 - c)) // 5) + C + D * (5 - c), ) dic[N] = tmp return tmp for _ in range(T): N, A, B, C, D = list(map(int, input().split())) dic = {} print((solve(N)))
T = int(eval(input())) from functools import lru_cache for _ in range(T): N, A, B, C, D = list(map(int, input().split())) @lru_cache(maxsize=None) def solve(N): if N == 0: return 0 if N == 1: return D tmp = N * D if N % 2 == 0: tmp = min(tmp, solve(N // 2) + A) else: tmp = min(tmp, solve((N - 1) // 2) + A + D, solve((N + 1) // 2) + A + D) if N % 3 == 0: tmp = min(tmp, solve(N // 3) + B) else: b = N % 3 tmp = min( tmp, solve((N + (3 - b)) // 3) + B + (3 - b) * D, solve((N - b) // 3) + B + b * D, ) if N % 5 == 0: tmp = min(tmp, solve(N // 5) + C) else: c = N % 5 tmp = min( tmp, solve((N - c) // 5) + C + D * c, solve((N + (5 - c)) // 5) + C + D * (5 - c), ) return tmp print((solve(N)))
false
12.121212
[ "-import sys", "-", "-sys.setrecursionlimit(10**8)", "-", "-", "-def solve(N):", "- if N == 0:", "- return 0", "- if N == 1:", "- return D", "- if N in dic:", "- return dic[N]", "- tmp = N * D", "- if N % 2 == 0:", "- tmp = min(tmp, solve(N // 2) + A)", "- else:", "- tmp = min(tmp, solve((N - 1) // 2) + A + D, solve((N + 1) // 2) + A + D)", "- if N % 3 == 0:", "- tmp = min(tmp, solve(N // 3) + B)", "- else:", "- b = N % 3", "- tmp = min(", "- tmp,", "- solve((N + (3 - b)) // 3) + B + (3 - b) * D,", "- solve((N - b) // 3) + B + b * D,", "- )", "- if N % 5 == 0:", "- tmp = min(tmp, solve(N // 5) + C)", "- else:", "- c = N % 5", "- tmp = min(", "- tmp,", "- solve((N - c) // 5) + C + D * c,", "- solve((N + (5 - c)) // 5) + C + D * (5 - c),", "- )", "- dic[N] = tmp", "- return tmp", "-", "+from functools import lru_cache", "- dic = {}", "+", "+ @lru_cache(maxsize=None)", "+ def solve(N):", "+ if N == 0:", "+ return 0", "+ if N == 1:", "+ return D", "+ tmp = N * D", "+ if N % 2 == 0:", "+ tmp = min(tmp, solve(N // 2) + A)", "+ else:", "+ tmp = min(tmp, solve((N - 1) // 2) + A + D, solve((N + 1) // 2) + A + D)", "+ if N % 3 == 0:", "+ tmp = min(tmp, solve(N // 3) + B)", "+ else:", "+ b = N % 3", "+ tmp = min(", "+ tmp,", "+ solve((N + (3 - b)) // 3) + B + (3 - b) * D,", "+ solve((N - b) // 3) + B + b * D,", "+ )", "+ if N % 5 == 0:", "+ tmp = min(tmp, solve(N // 5) + C)", "+ else:", "+ c = N % 5", "+ tmp = min(", "+ tmp,", "+ solve((N - c) // 5) + C + D * c,", "+ solve((N + (5 - c)) // 5) + C + D * (5 - c),", "+ )", "+ return tmp", "+" ]
false
0.141136
0.154317
0.91458
[ "s518675663", "s048530087" ]
u777283665
p03031
python
s818695101
s865385934
198
27
40,944
3,064
Accepted
Accepted
86.36
n, m = list(map(int, input().split())) ks = [list(map(int, input().split())) for i in range(m)] p = list(map(int, input().split())) ans = 0 for i in range(2**n): light_on = 0 for j in range(m): switch_on = 0 for k in ks[j][1:]: if (i >> k-1) & 1: switch_on += 1 if switch_on % 2 == p[j]: light_on += 1 if light_on == m: ans += 1 print(ans)
from itertools import product n, m = list(map(int, input().split())) x = [] for i in range(m): x.append(list(map(int, input().split()))[1:]) p = list(map(int, input().split())) ans = 0 for j in product([1,0],repeat=n): for i, s in enumerate(x): if sum([j[k-1] == 1 for k in s]) % 2 != p[i]: break else: ans += 1 print(ans)
19
20
396
393
n, m = list(map(int, input().split())) ks = [list(map(int, input().split())) for i in range(m)] p = list(map(int, input().split())) ans = 0 for i in range(2**n): light_on = 0 for j in range(m): switch_on = 0 for k in ks[j][1:]: if (i >> k - 1) & 1: switch_on += 1 if switch_on % 2 == p[j]: light_on += 1 if light_on == m: ans += 1 print(ans)
from itertools import product n, m = list(map(int, input().split())) x = [] for i in range(m): x.append(list(map(int, input().split()))[1:]) p = list(map(int, input().split())) ans = 0 for j in product([1, 0], repeat=n): for i, s in enumerate(x): if sum([j[k - 1] == 1 for k in s]) % 2 != p[i]: break else: ans += 1 print(ans)
false
5
[ "+from itertools import product", "+", "-ks = [list(map(int, input().split())) for i in range(m)]", "+x = []", "+for i in range(m):", "+ x.append(list(map(int, input().split()))[1:])", "-for i in range(2**n):", "- light_on = 0", "- for j in range(m):", "- switch_on = 0", "- for k in ks[j][1:]:", "- if (i >> k - 1) & 1:", "- switch_on += 1", "- if switch_on % 2 == p[j]:", "- light_on += 1", "- if light_on == m:", "+for j in product([1, 0], repeat=n):", "+ for i, s in enumerate(x):", "+ if sum([j[k - 1] == 1 for k in s]) % 2 != p[i]:", "+ break", "+ else:" ]
false
0.125191
0.035074
3.569315
[ "s818695101", "s865385934" ]
u764956288
p02627
python
s583496036
s127482589
32
26
9,080
8,948
Accepted
Accepted
18.75
# import sys # readline = sys.stdin.readline # generator = (readline().strip() for _ in range(N)) # N, M = map(int, input().split()) # As = list(map(int, input().split())) # queries = (input() for _ in range(N)) def solve(): alpha = eval(input()) if alpha.upper() == alpha: return 'A' return 'a' def main(): print((solve())) if __name__ == "__main__": main()
def solve(): letter = eval(input()) answer = 'A' if letter.upper() == letter else 'a' return answer def main(): print((solve())) if __name__ == "__main__": main()
24
14
411
194
# import sys # readline = sys.stdin.readline # generator = (readline().strip() for _ in range(N)) # N, M = map(int, input().split()) # As = list(map(int, input().split())) # queries = (input() for _ in range(N)) def solve(): alpha = eval(input()) if alpha.upper() == alpha: return "A" return "a" def main(): print((solve())) if __name__ == "__main__": main()
def solve(): letter = eval(input()) answer = "A" if letter.upper() == letter else "a" return answer def main(): print((solve())) if __name__ == "__main__": main()
false
41.666667
[ "-# import sys", "-# readline = sys.stdin.readline", "-# generator = (readline().strip() for _ in range(N))", "-# N, M = map(int, input().split())", "-# As = list(map(int, input().split()))", "-# queries = (input() for _ in range(N))", "- alpha = eval(input())", "- if alpha.upper() == alpha:", "- return \"A\"", "- return \"a\"", "+ letter = eval(input())", "+ answer = \"A\" if letter.upper() == letter else \"a\"", "+ return answer" ]
false
0.04604
0.046041
0.999977
[ "s583496036", "s127482589" ]
u254871849
p03325
python
s696280742
s868376229
65
58
4,212
4,084
Accepted
Accepted
10.77
# author: kagemeka # created: 2019-11-08 12:38:16(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, *a = (int(x) for x in sys.stdin.read().split()) total_count = 0 atmost = math.floor(math.log(10 ** 9, 2)) for i in range(n): current = a[i] count = 0 for _ in range(atmost + 1): if current % 2 == 0: current //= 2 count += 1 else: break total_count += count print(total_count) if __name__ == "__main__": # execute only if run as a script main()
import sys n, *a = list(map(int, sys.stdin.read().split())) def main(): cnt = 0 for i in a: while not i % 2: i //= 2 cnt += 1 return cnt if __name__ == '__main__': ans = main() print(ans)
38
16
971
260
# author: kagemeka # created: 2019-11-08 12:38:16(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, *a = (int(x) for x in sys.stdin.read().split()) total_count = 0 atmost = math.floor(math.log(10**9, 2)) for i in range(n): current = a[i] count = 0 for _ in range(atmost + 1): if current % 2 == 0: current //= 2 count += 1 else: break total_count += count print(total_count) if __name__ == "__main__": # execute only if run as a script main()
import sys n, *a = list(map(int, sys.stdin.read().split())) def main(): cnt = 0 for i in a: while not i % 2: i //= 2 cnt += 1 return cnt if __name__ == "__main__": ans = main() print(ans)
false
57.894737
[ "-# author: kagemeka", "-# created: 2019-11-08 12:38:16(JST)", "-## internal modules", "-# import collections", "-import math", "+n, *a = list(map(int, sys.stdin.read().split()))", "-# 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)", "+", "- n, *a = (int(x) for x in sys.stdin.read().split())", "- total_count = 0", "- atmost = math.floor(math.log(10**9, 2))", "- for i in range(n):", "- current = a[i]", "- count = 0", "- for _ in range(atmost + 1):", "- if current % 2 == 0:", "- current //= 2", "- count += 1", "- else:", "- break", "- total_count += count", "- print(total_count)", "+ cnt = 0", "+ for i in a:", "+ while not i % 2:", "+ i //= 2", "+ cnt += 1", "+ return cnt", "- # execute only if run as a script", "- main()", "+ ans = main()", "+ print(ans)" ]
false
0.061872
0.037868
1.633904
[ "s696280742", "s868376229" ]
u548545174
p03126
python
s402522094
s050980045
23
18
3,316
2,940
Accepted
Accepted
21.74
from collections import Counter n, m = list(map(int, input().split())) L = [] cnt = 0 for _ in range(n): tmp = input().split() a = tmp[1:] L.extend(a) c = Counter(L) for k, v in list(c.items()): if v==n: cnt += 1 print(cnt)
n, m = list(map(int, input().split())) foods = [0] * m for _ in range(n): k, *a = input().split() for food in a: foods[int(food)-1] += 1 print((foods.count(n)))
17
9
259
194
from collections import Counter n, m = list(map(int, input().split())) L = [] cnt = 0 for _ in range(n): tmp = input().split() a = tmp[1:] L.extend(a) c = Counter(L) for k, v in list(c.items()): if v == n: cnt += 1 print(cnt)
n, m = list(map(int, input().split())) foods = [0] * m for _ in range(n): k, *a = input().split() for food in a: foods[int(food) - 1] += 1 print((foods.count(n)))
false
47.058824
[ "-from collections import Counter", "-", "-L = []", "-cnt = 0", "+foods = [0] * m", "- tmp = input().split()", "- a = tmp[1:]", "- L.extend(a)", "-c = Counter(L)", "-for k, v in list(c.items()):", "- if v == n:", "- cnt += 1", "-print(cnt)", "+ k, *a = input().split()", "+ for food in a:", "+ foods[int(food) - 1] += 1", "+print((foods.count(n)))" ]
false
0.041507
0.036718
1.130429
[ "s402522094", "s050980045" ]
u923668099
p02257
python
s877663589
s737820778
940
530
7,688
7,700
Accepted
Accepted
43.62
import sys def solve(): n = int(sys.stdin.readline()) ans = sum(is_prime(int(sys.stdin.readline())) for i in range(n)) print(ans) def is_prime(n): if n < 2: return False p = 2 while p*p <= n: if n % p == 0: return False p += 1 return True if __name__ == '__main__': solve()
import sys def solve(): n = int(sys.stdin.readline()) ans = sum(is_prime(int(sys.stdin.readline())) for i in range(n)) print(ans) def is_prime(n): if n < 2 or (n > 2 and n & 1 == 0): return False p = 3 while p*p <= n: if n % p == 0: return False p += 2 return True if __name__ == '__main__': solve()
25
25
374
400
import sys def solve(): n = int(sys.stdin.readline()) ans = sum(is_prime(int(sys.stdin.readline())) for i in range(n)) print(ans) def is_prime(n): if n < 2: return False p = 2 while p * p <= n: if n % p == 0: return False p += 1 return True if __name__ == "__main__": solve()
import sys def solve(): n = int(sys.stdin.readline()) ans = sum(is_prime(int(sys.stdin.readline())) for i in range(n)) print(ans) def is_prime(n): if n < 2 or (n > 2 and n & 1 == 0): return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True if __name__ == "__main__": solve()
false
0
[ "- if n < 2:", "+ if n < 2 or (n > 2 and n & 1 == 0):", "- p = 2", "+ p = 3", "- p += 1", "+ p += 2" ]
false
0.03812
0.046237
0.824459
[ "s877663589", "s737820778" ]
u188827677
p03816
python
s464440129
s487029676
63
57
21,920
20,756
Accepted
Accepted
9.52
from collections import Counter n = int(eval(input())) a = list(map(int ,input().split())) cnt = Counter(a) # ใ‚ซใƒผใƒ‰ใฎๅ€คใ‚’ใ‚ซใ‚ฆใƒณใƒˆ ans = len(cnt) # ๅญ˜ๅœจใ™ใ‚‹ๅ€คใฎๆ•ฐใ‚’ใ‚ซใ‚ฆใƒณใƒˆ if ans%2 == 0: print((ans-1)) # ๅญ˜ๅœจใ™ใ‚‹ๅ€คใฎๆ•ฐใŒๅถๆ•ฐใงใ‚ใ‚Œใฐ1ๅ›žๅ–ใ‚Š้™คใๅฟ…่ฆใŒใ‚ใ‚‹ใŸใ‚-1ใ‚’ใ™ใ‚‹ else: print(ans) # ๅฅ‡ๆ•ฐใฎๅ ดๅˆใฏใใฎใพใพ
n = int(eval(input())) a = list(map(int, input().split())) n = len(set(a)) if n%2 == 0: print((n-1)) else: print(n)
8
6
245
113
from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) cnt = Counter(a) # ใ‚ซใƒผใƒ‰ใฎๅ€คใ‚’ใ‚ซใ‚ฆใƒณใƒˆ ans = len(cnt) # ๅญ˜ๅœจใ™ใ‚‹ๅ€คใฎๆ•ฐใ‚’ใ‚ซใ‚ฆใƒณใƒˆ if ans % 2 == 0: print((ans - 1)) # ๅญ˜ๅœจใ™ใ‚‹ๅ€คใฎๆ•ฐใŒๅถๆ•ฐใงใ‚ใ‚Œใฐ1ๅ›žๅ–ใ‚Š้™คใๅฟ…่ฆใŒใ‚ใ‚‹ใŸใ‚-1ใ‚’ใ™ใ‚‹ else: print(ans) # ๅฅ‡ๆ•ฐใฎๅ ดๅˆใฏใใฎใพใพ
n = int(eval(input())) a = list(map(int, input().split())) n = len(set(a)) if n % 2 == 0: print((n - 1)) else: print(n)
false
25
[ "-from collections import Counter", "-", "-cnt = Counter(a) # ใ‚ซใƒผใƒ‰ใฎๅ€คใ‚’ใ‚ซใ‚ฆใƒณใƒˆ", "-ans = len(cnt) # ๅญ˜ๅœจใ™ใ‚‹ๅ€คใฎๆ•ฐใ‚’ใ‚ซใ‚ฆใƒณใƒˆ", "-if ans % 2 == 0:", "- print((ans - 1)) # ๅญ˜ๅœจใ™ใ‚‹ๅ€คใฎๆ•ฐใŒๅถๆ•ฐใงใ‚ใ‚Œใฐ1ๅ›žๅ–ใ‚Š้™คใๅฟ…่ฆใŒใ‚ใ‚‹ใŸใ‚-1ใ‚’ใ™ใ‚‹", "+n = len(set(a))", "+if n % 2 == 0:", "+ print((n - 1))", "- print(ans) # ๅฅ‡ๆ•ฐใฎๅ ดๅˆใฏใใฎใพใพ", "+ print(n)" ]
false
0.097399
0.045814
2.12595
[ "s464440129", "s487029676" ]
u272028993
p03947
python
s137460670
s295548179
80
31
2,820
2,692
Accepted
Accepted
61.25
s=input() l=0 r=len(s)-1 news="" i=0 while i<len(s): if s[i]=="W": while i<len(s) and s[i]=="W": i+=1 news+=s[i-1] else: while i<len(s) and s[i]=="B": i+=1 news+=s[i-1] print((len(news)-1))
s=input() now=s[0] ans=0 for i in range(1,len(s)): if now!=s[i]: ans+=1 now=s[i] print(ans)
16
8
271
123
s = input() l = 0 r = len(s) - 1 news = "" i = 0 while i < len(s): if s[i] == "W": while i < len(s) and s[i] == "W": i += 1 news += s[i - 1] else: while i < len(s) and s[i] == "B": i += 1 news += s[i - 1] print((len(news) - 1))
s = input() now = s[0] ans = 0 for i in range(1, len(s)): if now != s[i]: ans += 1 now = s[i] print(ans)
false
50
[ "-l = 0", "-r = len(s) - 1", "-news = \"\"", "-i = 0", "-while i < len(s):", "- if s[i] == \"W\":", "- while i < len(s) and s[i] == \"W\":", "- i += 1", "- news += s[i - 1]", "- else:", "- while i < len(s) and s[i] == \"B\":", "- i += 1", "- news += s[i - 1]", "-print((len(news) - 1))", "+now = s[0]", "+ans = 0", "+for i in range(1, len(s)):", "+ if now != s[i]:", "+ ans += 1", "+ now = s[i]", "+print(ans)" ]
false
0.04217
0.038194
1.104105
[ "s137460670", "s295548179" ]
u858464419
p03478
python
s412547663
s919162333
42
36
3,316
3,060
Accepted
Accepted
14.29
n, a, b = list(map(int, input().split())) ans = 0 for i in range(n+1): if a <= sum(list(map(int, list(str(i))))) <= b: ans += i print(ans)
n,a,b = list(map(int, input().split())) ans = 0 for i in range(1,n+1): if a <= sum(list(map(int, list(str(i))))) <= b: ans += i print(ans)
6
6
144
144
n, a, b = list(map(int, input().split())) ans = 0 for i in range(n + 1): if a <= sum(list(map(int, list(str(i))))) <= b: ans += i print(ans)
n, a, b = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): if a <= sum(list(map(int, list(str(i))))) <= b: ans += i print(ans)
false
0
[ "-for i in range(n + 1):", "+for i in range(1, n + 1):" ]
false
0.045935
0.046259
0.992997
[ "s412547663", "s919162333" ]
u509739538
p02579
python
s052380724
s714096390
833
502
139,224
85,648
Accepted
Accepted
39.74
from collections import defaultdict from collections import deque from collections import Counter import math def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() def p(arr): print("_______________________") for i in arr: for j in i: print(j,end=" ") print() h,w = readInts() ch,cw = readInts() dh,dw = readInts() s = [["#" for i in range(w+2)]]+[["#"]+ list(input())+["#"] for i in range(h)]+[["#" for i in range(w+2)]] q = deque() visited = [[-1]*(w+2) for i in range(h+2)] count = (w+2)*(h+2) for i in range(h+2): for j in range(w+2): if s[i][j]=="#": visited[i][j] = float("inf") count -= 1 from pprint import pprint visited[ch][cw] = 0 q = {(ch,cw)} set_list = set() cost = 0 while count: while len(q) !=0: x,y = q.pop() set_list.add((x,y)) visited[x][y] = cost count-=1 if s[x-1][y]=="." and visited[x-1][y]==-1: q.add((x-1,y)) if s[x][y-1]=="." and visited[x][y-1]==-1: q.add((x,y-1)) if s[x+1][y]=="." and visited[x+1][y]==-1: q.add((x+1,y)) if s[x][y+1]=="." and visited[x][y+1]==-1: q.add((x,y+1)) if len(set_list)==0: break cost+=1 while len(set_list) != 0: x,y = set_list.pop() for dx in range(-2,3): for dy in range(-2,3): x2 = x+dx y2 = y+dy if visited[min(x2,h+1)][min(y2,w+1)]!=-1: continue q.add((x2,y2)) print(visited[dh][dw])
from collections import defaultdict from collections import deque from collections import Counter import math def readInt(): return int(eval(input())) def readInts(): return list(map(int, input().split())) def readChar(): return eval(input()) def readChars(): return input().split() h,w = readInts() ch,cw = readInts() dh,dw = readInts() s = ["#"*(w+2)]+["#"+eval(input())+"#" for i in range(h)]+["#"*(w+2)] visited = [[-2]*(w+2) for i in range(h+2)] for i in range(h+2): for j in range(w+2): if s[i][j]==".": visited[i][j] = -1 delta1 = [[0,1],[1,0],[-1,0],[0,-1]] q = {(ch,cw)} set_list = set() cost = 0 while 1: if len(q)==0: break while len(q) !=0: x,y = q.pop() set_list.add((x,y)) visited[x][y] = cost for dx,dy in delta1: x2 = x+dx y2 = y+dy if visited[x2][y2]==-1: q.add((x2,y2)) cost+=1 while len(set_list) != 0: x,y = set_list.pop() for dx in range(-2,3): for dy in range(-2,3): x2 = x+dx y2 = y+dy if visited[min(x2,h+1)][min(y2,w+1)]!=-1: continue q.add((x2,y2)) print((visited[dh][dw]))
70
52
1,509
1,095
from collections import defaultdict from collections import deque from collections import Counter import math def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() def p(arr): print("_______________________") for i in arr: for j in i: print(j, end=" ") print() h, w = readInts() ch, cw = readInts() dh, dw = readInts() s = ( [["#" for i in range(w + 2)]] + [["#"] + list(input()) + ["#"] for i in range(h)] + [["#" for i in range(w + 2)]] ) q = deque() visited = [[-1] * (w + 2) for i in range(h + 2)] count = (w + 2) * (h + 2) for i in range(h + 2): for j in range(w + 2): if s[i][j] == "#": visited[i][j] = float("inf") count -= 1 from pprint import pprint visited[ch][cw] = 0 q = {(ch, cw)} set_list = set() cost = 0 while count: while len(q) != 0: x, y = q.pop() set_list.add((x, y)) visited[x][y] = cost count -= 1 if s[x - 1][y] == "." and visited[x - 1][y] == -1: q.add((x - 1, y)) if s[x][y - 1] == "." and visited[x][y - 1] == -1: q.add((x, y - 1)) if s[x + 1][y] == "." and visited[x + 1][y] == -1: q.add((x + 1, y)) if s[x][y + 1] == "." and visited[x][y + 1] == -1: q.add((x, y + 1)) if len(set_list) == 0: break cost += 1 while len(set_list) != 0: x, y = set_list.pop() for dx in range(-2, 3): for dy in range(-2, 3): x2 = x + dx y2 = y + dy if visited[min(x2, h + 1)][min(y2, w + 1)] != -1: continue q.add((x2, y2)) print(visited[dh][dw])
from collections import defaultdict from collections import deque from collections import Counter import math def readInt(): return int(eval(input())) def readInts(): return list(map(int, input().split())) def readChar(): return eval(input()) def readChars(): return input().split() h, w = readInts() ch, cw = readInts() dh, dw = readInts() s = ["#" * (w + 2)] + ["#" + eval(input()) + "#" for i in range(h)] + ["#" * (w + 2)] visited = [[-2] * (w + 2) for i in range(h + 2)] for i in range(h + 2): for j in range(w + 2): if s[i][j] == ".": visited[i][j] = -1 delta1 = [[0, 1], [1, 0], [-1, 0], [0, -1]] q = {(ch, cw)} set_list = set() cost = 0 while 1: if len(q) == 0: break while len(q) != 0: x, y = q.pop() set_list.add((x, y)) visited[x][y] = cost for dx, dy in delta1: x2 = x + dx y2 = y + dy if visited[x2][y2] == -1: q.add((x2, y2)) cost += 1 while len(set_list) != 0: x, y = set_list.pop() for dx in range(-2, 3): for dy in range(-2, 3): x2 = x + dx y2 = y + dy if visited[min(x2, h + 1)][min(y2, w + 1)] != -1: continue q.add((x2, y2)) print((visited[dh][dw]))
false
25.714286
[ "- return int(input())", "+ return int(eval(input()))", "- return input()", "+ return eval(input())", "-def p(arr):", "- print(\"_______________________\")", "- for i in arr:", "- for j in i:", "- print(j, end=\" \")", "- print()", "-", "-", "-s = (", "- [[\"#\" for i in range(w + 2)]]", "- + [[\"#\"] + list(input()) + [\"#\"] for i in range(h)]", "- + [[\"#\" for i in range(w + 2)]]", "-)", "-q = deque()", "-visited = [[-1] * (w + 2) for i in range(h + 2)]", "-count = (w + 2) * (h + 2)", "+s = [\"#\" * (w + 2)] + [\"#\" + eval(input()) + \"#\" for i in range(h)] + [\"#\" * (w + 2)]", "+visited = [[-2] * (w + 2) for i in range(h + 2)]", "- if s[i][j] == \"#\":", "- visited[i][j] = float(\"inf\")", "- count -= 1", "-from pprint import pprint", "-", "-visited[ch][cw] = 0", "+ if s[i][j] == \".\":", "+ visited[i][j] = -1", "+delta1 = [[0, 1], [1, 0], [-1, 0], [0, -1]]", "-while count:", "+while 1:", "+ if len(q) == 0:", "+ break", "- count -= 1", "- if s[x - 1][y] == \".\" and visited[x - 1][y] == -1:", "- q.add((x - 1, y))", "- if s[x][y - 1] == \".\" and visited[x][y - 1] == -1:", "- q.add((x, y - 1))", "- if s[x + 1][y] == \".\" and visited[x + 1][y] == -1:", "- q.add((x + 1, y))", "- if s[x][y + 1] == \".\" and visited[x][y + 1] == -1:", "- q.add((x, y + 1))", "- if len(set_list) == 0:", "- break", "+ for dx, dy in delta1:", "+ x2 = x + dx", "+ y2 = y + dy", "+ if visited[x2][y2] == -1:", "+ q.add((x2, y2))", "-print(visited[dh][dw])", "+print((visited[dh][dw]))" ]
false
0.033921
0.097538
0.347773
[ "s052380724", "s714096390" ]
u241159583
p03325
python
s696050297
s853112219
143
111
4,148
4,148
Accepted
Accepted
22.38
N = int(eval(input())) a =list(map(int, input().split())) ans = 0 import math for i in range(N): if a[i] % 2 != 0: continue while a[i] % 2 == 0: a[i] = a[i] /2 ans += 1 print(ans)
N = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in range(N): if a[i] % 2 == 0: while a[i] % 2 == 0: a[i] = a[i] // 2 ans += 1 print(ans)
12
9
201
181
N = int(eval(input())) a = list(map(int, input().split())) ans = 0 import math for i in range(N): if a[i] % 2 != 0: continue while a[i] % 2 == 0: a[i] = a[i] / 2 ans += 1 print(ans)
N = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in range(N): if a[i] % 2 == 0: while a[i] % 2 == 0: a[i] = a[i] // 2 ans += 1 print(ans)
false
25
[ "-import math", "-", "- if a[i] % 2 != 0:", "- continue", "- while a[i] % 2 == 0:", "- a[i] = a[i] / 2", "- ans += 1", "+ if a[i] % 2 == 0:", "+ while a[i] % 2 == 0:", "+ a[i] = a[i] // 2", "+ ans += 1" ]
false
0.037415
0.039276
0.9526
[ "s696050297", "s853112219" ]
u075012704
p03682
python
s223398362
s756260670
1,722
1,512
133,124
59,316
Accepted
Accepted
12.2
N = int(eval(input())) P = [[i, list(map(int, input().split()))] for i in range(N)] X = sorted([[i, xy[0]] for i, xy in P], key=lambda x: x[1]) Y = sorted([[i, xy[1]] for i, xy in P], key=lambda y: y[1]) Xe = [[X[i][0], X[i+1][0], abs(X[i][1]-X[i+1][1])] for i in range(N-1)] Ye = [[Y[i][0], Y[i+1][0], abs(Y[i][1]-Y[i+1][1])] for i in range(N-1)] E = sorted(Xe + Ye, key=lambda e: e[2]) class UnionFind: def __init__(self, n): self.par = [i for i in range(n+1)] self.rank = [0] * (n+1) self.size = [1] * (n+1) # ๆคœ็ดข def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] # ไฝตๅˆ def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 # ๅŒใ˜้›†ๅˆใซๅฑžใ™ใ‚‹ใ‹ๅˆคๅฎš def same_check(self, x, y): return self.find(x) == self.find(y) uf = UnionFind(N) edge_cnt = 0 MST_cost = 0 i = 0 while edge_cnt < N-1: a, b, cost = E[i] if not uf.same_check(a, b): MST_cost += cost uf.union(a, b) edge_cnt += 1 i += 1 print(MST_cost)
N = int(eval(input())) Points = [[i] + list(map(int, input().split())) for i in range(N)] # x, yใใ‚Œใžใ‚Œใซใคใ„ใฆใ‚ฝใƒผใƒˆใ—ใฆใ€ไธ€็•ช่ฟ‘ใ„ใจใ“ใ‚ใ‚’่ฆ‹ใ‚Œใฐๅๅˆ† Edges = [] Points.sort(key=lambda p: p[1]) for i in range(N - 1): n1, x1, y1 = Points[i] n2, x2, y2 = Points[i + 1] Edges.append([n1, n2, x2 - x1]) Points.sort(key=lambda p: p[2]) for i in range(N - 1): n1, x1, y1 = Points[i] n2, x2, y2 = Points[i + 1] Edges.append([n1, n2, y2 - y1]) class UnionFind: def __init__(self, n): self.par = [i for i in range(n+1)] self.rank = [0] * (n+1) self.size = [1] * (n+1) # ๆคœ็ดข def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] # ไฝตๅˆ def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 # ๅŒใ˜้›†ๅˆใซๅฑžใ™ใ‚‹ใ‹ๅˆคๅฎš def same_check(self, x, y): return self.find(x) == self.find(y) uf = UnionFind(N) Edges.sort(key=lambda e: e[2], reverse=True) MST_cost = 0 i = 0 # ่พบใฎใ‚ณใ‚นใƒˆใŒๅฐใ•ใ„ใ‚‚ใฎใ‹ใ‚‰ใ€้–‰่ทฏใ‚’ไฝœใ‚‰ใชใ„ใ‚ˆใ†ใซใ€ๆœจใ‚’ๆง‹ๆˆใ™ใ‚‹ # ๆœ€ๅฐๅ…จๅŸŸๆœจใฎๅฟ…่ฆ่พบใฏ(้ ‚็‚นๆ•ฐ-1)ๆœฌ while i != N - 1: x, y, cost = Edges.pop() # ๅŒใ˜่พบ้›†ๅˆใซๅฑžใ—ใฆใ„ใชใ„ใชใ‚‰ใฐ๏ผˆ้–‰่ทฏใŒ็”Ÿใพใ‚Œใชใ„ใชใ‚‰ใฐ๏ผ‰ if not uf.same_check(x, y): MST_cost += cost uf.union(x, y) i += 1 print(MST_cost)
59
68
1,409
1,571
N = int(eval(input())) P = [[i, list(map(int, input().split()))] for i in range(N)] X = sorted([[i, xy[0]] for i, xy in P], key=lambda x: x[1]) Y = sorted([[i, xy[1]] for i, xy in P], key=lambda y: y[1]) Xe = [[X[i][0], X[i + 1][0], abs(X[i][1] - X[i + 1][1])] for i in range(N - 1)] Ye = [[Y[i][0], Y[i + 1][0], abs(Y[i][1] - Y[i + 1][1])] for i in range(N - 1)] E = sorted(Xe + Ye, key=lambda e: e[2]) class UnionFind: def __init__(self, n): self.par = [i for i in range(n + 1)] self.rank = [0] * (n + 1) self.size = [1] * (n + 1) # ๆคœ็ดข def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] # ไฝตๅˆ def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 # ๅŒใ˜้›†ๅˆใซๅฑžใ™ใ‚‹ใ‹ๅˆคๅฎš def same_check(self, x, y): return self.find(x) == self.find(y) uf = UnionFind(N) edge_cnt = 0 MST_cost = 0 i = 0 while edge_cnt < N - 1: a, b, cost = E[i] if not uf.same_check(a, b): MST_cost += cost uf.union(a, b) edge_cnt += 1 i += 1 print(MST_cost)
N = int(eval(input())) Points = [[i] + list(map(int, input().split())) for i in range(N)] # x, yใใ‚Œใžใ‚Œใซใคใ„ใฆใ‚ฝใƒผใƒˆใ—ใฆใ€ไธ€็•ช่ฟ‘ใ„ใจใ“ใ‚ใ‚’่ฆ‹ใ‚Œใฐๅๅˆ† Edges = [] Points.sort(key=lambda p: p[1]) for i in range(N - 1): n1, x1, y1 = Points[i] n2, x2, y2 = Points[i + 1] Edges.append([n1, n2, x2 - x1]) Points.sort(key=lambda p: p[2]) for i in range(N - 1): n1, x1, y1 = Points[i] n2, x2, y2 = Points[i + 1] Edges.append([n1, n2, y2 - y1]) class UnionFind: def __init__(self, n): self.par = [i for i in range(n + 1)] self.rank = [0] * (n + 1) self.size = [1] * (n + 1) # ๆคœ็ดข def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] # ไฝตๅˆ def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 # ๅŒใ˜้›†ๅˆใซๅฑžใ™ใ‚‹ใ‹ๅˆคๅฎš def same_check(self, x, y): return self.find(x) == self.find(y) uf = UnionFind(N) Edges.sort(key=lambda e: e[2], reverse=True) MST_cost = 0 i = 0 # ่พบใฎใ‚ณใ‚นใƒˆใŒๅฐใ•ใ„ใ‚‚ใฎใ‹ใ‚‰ใ€้–‰่ทฏใ‚’ไฝœใ‚‰ใชใ„ใ‚ˆใ†ใซใ€ๆœจใ‚’ๆง‹ๆˆใ™ใ‚‹ # ๆœ€ๅฐๅ…จๅŸŸๆœจใฎๅฟ…่ฆ่พบใฏ(้ ‚็‚นๆ•ฐ-1)ๆœฌ while i != N - 1: x, y, cost = Edges.pop() # ๅŒใ˜่พบ้›†ๅˆใซๅฑžใ—ใฆใ„ใชใ„ใชใ‚‰ใฐ๏ผˆ้–‰่ทฏใŒ็”Ÿใพใ‚Œใชใ„ใชใ‚‰ใฐ๏ผ‰ if not uf.same_check(x, y): MST_cost += cost uf.union(x, y) i += 1 print(MST_cost)
false
13.235294
[ "-P = [[i, list(map(int, input().split()))] for i in range(N)]", "-X = sorted([[i, xy[0]] for i, xy in P], key=lambda x: x[1])", "-Y = sorted([[i, xy[1]] for i, xy in P], key=lambda y: y[1])", "-Xe = [[X[i][0], X[i + 1][0], abs(X[i][1] - X[i + 1][1])] for i in range(N - 1)]", "-Ye = [[Y[i][0], Y[i + 1][0], abs(Y[i][1] - Y[i + 1][1])] for i in range(N - 1)]", "-E = sorted(Xe + Ye, key=lambda e: e[2])", "+Points = [[i] + list(map(int, input().split())) for i in range(N)]", "+# x, yใใ‚Œใžใ‚Œใซใคใ„ใฆใ‚ฝใƒผใƒˆใ—ใฆใ€ไธ€็•ช่ฟ‘ใ„ใจใ“ใ‚ใ‚’่ฆ‹ใ‚Œใฐๅๅˆ†", "+Edges = []", "+Points.sort(key=lambda p: p[1])", "+for i in range(N - 1):", "+ n1, x1, y1 = Points[i]", "+ n2, x2, y2 = Points[i + 1]", "+ Edges.append([n1, n2, x2 - x1])", "+Points.sort(key=lambda p: p[2])", "+for i in range(N - 1):", "+ n1, x1, y1 = Points[i]", "+ n2, x2, y2 = Points[i + 1]", "+ Edges.append([n1, n2, y2 - y1])", "-edge_cnt = 0", "+Edges.sort(key=lambda e: e[2], reverse=True)", "-while edge_cnt < N - 1:", "- a, b, cost = E[i]", "- if not uf.same_check(a, b):", "+# ่พบใฎใ‚ณใ‚นใƒˆใŒๅฐใ•ใ„ใ‚‚ใฎใ‹ใ‚‰ใ€้–‰่ทฏใ‚’ไฝœใ‚‰ใชใ„ใ‚ˆใ†ใซใ€ๆœจใ‚’ๆง‹ๆˆใ™ใ‚‹", "+# ๆœ€ๅฐๅ…จๅŸŸๆœจใฎๅฟ…่ฆ่พบใฏ(้ ‚็‚นๆ•ฐ-1)ๆœฌ", "+while i != N - 1:", "+ x, y, cost = Edges.pop()", "+ # ๅŒใ˜่พบ้›†ๅˆใซๅฑžใ—ใฆใ„ใชใ„ใชใ‚‰ใฐ๏ผˆ้–‰่ทฏใŒ็”Ÿใพใ‚Œใชใ„ใชใ‚‰ใฐ๏ผ‰", "+ if not uf.same_check(x, y):", "- uf.union(a, b)", "- edge_cnt += 1", "- i += 1", "+ uf.union(x, y)", "+ i += 1" ]
false
0.117928
0.132958
0.886958
[ "s223398362", "s756260670" ]
u017810624
p03201
python
s979195058
s002274138
962
725
26,960
36,500
Accepted
Accepted
24.64
import math import bisect n=int(eval(input())) a=list(map(int,input().split())) a.sort() b=[] for i in range(1,50): b.append(2**i) ct=0 check=[1]*n for i in range(n-1,-1,-1): if a[i]==1: break if check[i]==1 and a[i] not in b: check[i]=0 x=math.floor(math.log2(a[i])) x=b[x]-a[i] y=bisect.bisect_left(a,x) z=bisect.bisect_right(a,x) t=bisect.bisect_left(check[y:z],1)+y if t!=z: check[t]=0 ct+=1 ctb=0 w=1 for i in range(n): if a[i] in b or a[i]==1: if a[i]==w: if check[i]==1: ctb+=1 else: ct+=ctb//2 w=a[i] if check[i]==1: ctb=1 else: ctb=0 else: ct+=ctb//2 ctb=0 ct+=ctb//2 print(ct)
import math import bisect n=int(eval(input())) a=list(map(int,input().split())) a.sort() x=a[0] ctn=1 l=[] l2=[] for i in range(1,n): if x==a[i]: ctn+=1 else: l.append([x,ctn]) l2.append(x) x=a[i] ctn=1 l.append([x,ctn]) l2.append(x) b=[] for i in range(1,50): b.append(2**i) ct=0 for i in range(len(l2)-1,-1,-1): x=math.floor(math.log2(l2[i])) x=b[x]-l2[i] y=bisect.bisect_left(l2,x) if l2[y]==x: if l2[y]!=l2[i]: m=min(l[i][1],l[y][1]) else: m=l[i][1]//2 l[i][1]-=m l[y][1]-=m ct+=m print(ct)
44
38
749
615
import math import bisect n = int(eval(input())) a = list(map(int, input().split())) a.sort() b = [] for i in range(1, 50): b.append(2**i) ct = 0 check = [1] * n for i in range(n - 1, -1, -1): if a[i] == 1: break if check[i] == 1 and a[i] not in b: check[i] = 0 x = math.floor(math.log2(a[i])) x = b[x] - a[i] y = bisect.bisect_left(a, x) z = bisect.bisect_right(a, x) t = bisect.bisect_left(check[y:z], 1) + y if t != z: check[t] = 0 ct += 1 ctb = 0 w = 1 for i in range(n): if a[i] in b or a[i] == 1: if a[i] == w: if check[i] == 1: ctb += 1 else: ct += ctb // 2 w = a[i] if check[i] == 1: ctb = 1 else: ctb = 0 else: ct += ctb // 2 ctb = 0 ct += ctb // 2 print(ct)
import math import bisect n = int(eval(input())) a = list(map(int, input().split())) a.sort() x = a[0] ctn = 1 l = [] l2 = [] for i in range(1, n): if x == a[i]: ctn += 1 else: l.append([x, ctn]) l2.append(x) x = a[i] ctn = 1 l.append([x, ctn]) l2.append(x) b = [] for i in range(1, 50): b.append(2**i) ct = 0 for i in range(len(l2) - 1, -1, -1): x = math.floor(math.log2(l2[i])) x = b[x] - l2[i] y = bisect.bisect_left(l2, x) if l2[y] == x: if l2[y] != l2[i]: m = min(l[i][1], l[y][1]) else: m = l[i][1] // 2 l[i][1] -= m l[y][1] -= m ct += m print(ct)
false
13.636364
[ "+x = a[0]", "+ctn = 1", "+l = []", "+l2 = []", "+for i in range(1, n):", "+ if x == a[i]:", "+ ctn += 1", "+ else:", "+ l.append([x, ctn])", "+ l2.append(x)", "+ x = a[i]", "+ ctn = 1", "+l.append([x, ctn])", "+l2.append(x)", "-check = [1] * n", "-for i in range(n - 1, -1, -1):", "- if a[i] == 1:", "- break", "- if check[i] == 1 and a[i] not in b:", "- check[i] = 0", "- x = math.floor(math.log2(a[i]))", "- x = b[x] - a[i]", "- y = bisect.bisect_left(a, x)", "- z = bisect.bisect_right(a, x)", "- t = bisect.bisect_left(check[y:z], 1) + y", "- if t != z:", "- check[t] = 0", "- ct += 1", "-ctb = 0", "-w = 1", "-for i in range(n):", "- if a[i] in b or a[i] == 1:", "- if a[i] == w:", "- if check[i] == 1:", "- ctb += 1", "+for i in range(len(l2) - 1, -1, -1):", "+ x = math.floor(math.log2(l2[i]))", "+ x = b[x] - l2[i]", "+ y = bisect.bisect_left(l2, x)", "+ if l2[y] == x:", "+ if l2[y] != l2[i]:", "+ m = min(l[i][1], l[y][1])", "- ct += ctb // 2", "- w = a[i]", "- if check[i] == 1:", "- ctb = 1", "- else:", "- ctb = 0", "- else:", "- ct += ctb // 2", "- ctb = 0", "-ct += ctb // 2", "+ m = l[i][1] // 2", "+ l[i][1] -= m", "+ l[y][1] -= m", "+ ct += m" ]
false
0.043457
0.037679
1.153352
[ "s979195058", "s002274138" ]
u633068244
p00211
python
s357305468
s380004557
60
50
4,252
4,252
Accepted
Accepted
16.67
def gcd(a,b): return a if b==0 else gcd(b,a%b) while 1: n=eval(input()) if n==0:break s=[list(map(int,input().split())) for i in range(n)] t=c=1 for i in s:t=t*i[1]/gcd(t,i[1]) for i in range(n): s[i]=t*s[i][0]/s[i][1] c=c*s[i]/gcd(c,s[i]) for i in s:print(c/i)
def g(a,b): return a if b==0 else g(b,a%b) while 1: n=eval(input()) if n==0:break s=[list(map(int,input().split())) for i in [1]*n] t=c=1 for i in s:t*=i[1]/g(t,i[1]) for i in range(n): s[i]=t*s[i][0]/s[i][1] c*=s[i]/g(c,s[i]) for i in s:print(c/i)
13
13
277
264
def gcd(a, b): return a if b == 0 else gcd(b, a % b) while 1: n = eval(input()) if n == 0: break s = [list(map(int, input().split())) for i in range(n)] t = c = 1 for i in s: t = t * i[1] / gcd(t, i[1]) for i in range(n): s[i] = t * s[i][0] / s[i][1] c = c * s[i] / gcd(c, s[i]) for i in s: print(c / i)
def g(a, b): return a if b == 0 else g(b, a % b) while 1: n = eval(input()) if n == 0: break s = [list(map(int, input().split())) for i in [1] * n] t = c = 1 for i in s: t *= i[1] / g(t, i[1]) for i in range(n): s[i] = t * s[i][0] / s[i][1] c *= s[i] / g(c, s[i]) for i in s: print(c / i)
false
0
[ "-def gcd(a, b):", "- return a if b == 0 else gcd(b, a % b)", "+def g(a, b):", "+ return a if b == 0 else g(b, a % b)", "- s = [list(map(int, input().split())) for i in range(n)]", "+ s = [list(map(int, input().split())) for i in [1] * n]", "- t = t * i[1] / gcd(t, i[1])", "+ t *= i[1] / g(t, i[1])", "- c = c * s[i] / gcd(c, s[i])", "+ c *= s[i] / g(c, s[i])" ]
false
0.038677
0.04151
0.931754
[ "s357305468", "s380004557" ]
u017810624
p02913
python
s089113779
s386394715
1,878
714
234,996
50,268
Accepted
Accepted
61.98
n=int(eval(input())) s=list(eval(input())) def Z_algorithm(s): N=len(s) Z_alg=[0]*N Z_alg[0]=N i=1 j=0 while i<N: while i+j<N and s[j]==s[i+j]: j+=1 Z_alg[i]=j if j==0: i+=1 continue k=1 while i+k<N and k+Z_alg[k]<j: Z_alg[i+k]=Z_alg[k] k+=1 i+=k j-=k return Z_alg ans=[0] for i in range(n): S=s[i:n] z=Z_algorithm(S) for j in range(len(z)): if z[j]<=j: ans.append(z[j]) print((max(ans)))
n=int(eval(input())) s=list(eval(input())) def Z_algorithm(s): N=len(s) Z_alg=[0]*N Z_alg[0]=N i=1 j=0 while i<N: while i+j<N and s[j]==s[i+j]: j+=1 Z_alg[i]=j if j==0: i+=1 continue k=1 while i+k<N and k+Z_alg[k]<j: Z_alg[i+k]=Z_alg[k] k+=1 i+=k j-=k return Z_alg ans=0 for i in range(n): S=s[i:n] z=Z_algorithm(S) for j in range(len(z)): if z[j]<=j: if ans<z[j]: ans=z[j] print(ans)
32
33
495
502
n = int(eval(input())) s = list(eval(input())) def Z_algorithm(s): N = len(s) Z_alg = [0] * N Z_alg[0] = N i = 1 j = 0 while i < N: while i + j < N and s[j] == s[i + j]: j += 1 Z_alg[i] = j if j == 0: i += 1 continue k = 1 while i + k < N and k + Z_alg[k] < j: Z_alg[i + k] = Z_alg[k] k += 1 i += k j -= k return Z_alg ans = [0] for i in range(n): S = s[i:n] z = Z_algorithm(S) for j in range(len(z)): if z[j] <= j: ans.append(z[j]) print((max(ans)))
n = int(eval(input())) s = list(eval(input())) def Z_algorithm(s): N = len(s) Z_alg = [0] * N Z_alg[0] = N i = 1 j = 0 while i < N: while i + j < N and s[j] == s[i + j]: j += 1 Z_alg[i] = j if j == 0: i += 1 continue k = 1 while i + k < N and k + Z_alg[k] < j: Z_alg[i + k] = Z_alg[k] k += 1 i += k j -= k return Z_alg ans = 0 for i in range(n): S = s[i:n] z = Z_algorithm(S) for j in range(len(z)): if z[j] <= j: if ans < z[j]: ans = z[j] print(ans)
false
3.030303
[ "-ans = [0]", "+ans = 0", "- ans.append(z[j])", "-print((max(ans)))", "+ if ans < z[j]:", "+ ans = z[j]", "+print(ans)" ]
false
0.038467
0.067711
0.568111
[ "s089113779", "s386394715" ]