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
u761529120
p03061
python
s312256646
s777120528
368
101
89,952
86,428
Accepted
Accepted
72.55
import fractions def main(): N = int(eval(input())) A = list(map(int, input().split())) gcd_ans = [] l = [0] * N r =[0] * N for i in range(N-1): l[i+1] = fractions.gcd(l[i],A[i]) r[i+1] = fractions.gcd(r[i],A[N-1-i]) r.reverse() for i in range(N): gcd_ans.append(fractions.gcd(l[i],r[i])) print((max(gcd_ans))) main()
from math import gcd def main(): N = int(eval(input())) A = list(map(int, input().split())) R = [0] * (N+1) L = [0] * (N+1) for i in range(N): L[i+1] = gcd(L[i], A[i]) for i in range(N-1,-1,-1): R[i] = gcd(R[i+1], A[i]) ans = 0 for i in range(N): ans = max(ans, gcd(L[i],R[i+1])) print(ans) if __name__ == "__main__": main()
23
19
402
403
import fractions def main(): N = int(eval(input())) A = list(map(int, input().split())) gcd_ans = [] l = [0] * N r = [0] * N for i in range(N - 1): l[i + 1] = fractions.gcd(l[i], A[i]) r[i + 1] = fractions.gcd(r[i], A[N - 1 - i]) r.reverse() for i in range(N): gcd_ans.append(fractions.gcd(l[i], r[i])) print((max(gcd_ans))) main()
from math import gcd def main(): N = int(eval(input())) A = list(map(int, input().split())) R = [0] * (N + 1) L = [0] * (N + 1) for i in range(N): L[i + 1] = gcd(L[i], A[i]) for i in range(N - 1, -1, -1): R[i] = gcd(R[i + 1], A[i]) ans = 0 for i in range(N): ans = max(ans, gcd(L[i], R[i + 1])) print(ans) if __name__ == "__main__": main()
false
17.391304
[ "-import fractions", "+from math import gcd", "- gcd_ans = []", "- l = [0] * N", "- r = [0] * N", "- for i in range(N - 1):", "- l[i + 1] = fractions.gcd(l[i], A[i])", "- r[i + 1] = fractions.gcd(r[i], A[N - 1 - i])", "- r.reverse()", "+ R = [0] * (N + 1)", "+ L = [0] * (N + 1)", "- gcd_ans.append(fractions.gcd(l[i], r[i]))", "- print((max(gcd_ans)))", "+ L[i + 1] = gcd(L[i], A[i])", "+ for i in range(N - 1, -1, -1):", "+ R[i] = gcd(R[i + 1], A[i])", "+ ans = 0", "+ for i in range(N):", "+ ans = max(ans, gcd(L[i], R[i + 1]))", "+ print(ans)", "-main()", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.061269
0.041534
1.475155
[ "s312256646", "s777120528" ]
u473952728
p03324
python
s078326178
s765424615
19
17
3,188
3,060
Accepted
Accepted
10.53
from itertools import * def nth(iterable, n, default=None): "Returns the nth item or a default value" return next(islice(iterable, n, None), default) D, N = list(map(int, input().split())) delta = 100 ** D ite = (x for x in count(delta, delta) if x % (delta * 100) != 0) print((nth(ite, N - 1)))
from itertools import * d, n = list(map(int, input().split())) delta = 100 ** d ite = (x for x in count(delta, delta) if x % (delta * 100) != 0) print((list(islice(ite, n - 1, n))[0]))
10
5
306
180
from itertools import * def nth(iterable, n, default=None): "Returns the nth item or a default value" return next(islice(iterable, n, None), default) D, N = list(map(int, input().split())) delta = 100**D ite = (x for x in count(delta, delta) if x % (delta * 100) != 0) print((nth(ite, N - 1)))
from itertools import * d, n = list(map(int, input().split())) delta = 100**d ite = (x for x in count(delta, delta) if x % (delta * 100) != 0) print((list(islice(ite, n - 1, n))[0]))
false
50
[ "-", "-def nth(iterable, n, default=None):", "- \"Returns the nth item or a default value\"", "- return next(islice(iterable, n, None), default)", "-", "-", "-D, N = list(map(int, input().split()))", "-delta = 100**D", "+d, n = list(map(int, input().split()))", "+delta = 100**d", "-print((nth(ite, N - 1)))", "+print((list(islice(ite, n - 1, n))[0]))" ]
false
0.044128
0.140231
0.314677
[ "s078326178", "s765424615" ]
u670567845
p02823
python
s932413081
s956572127
64
28
61,936
9,040
Accepted
Accepted
56.25
N, A, B = list(map(int, input().split())) if ((B-A)%2 == 0): print(((B-A)//2)) else: print((min([A+(B-A-1)//2 ,N-B+ 1 +(B-A-1)//2])))
N, A, B = list(map(int,input().split())) if ((A-B)%2==0): ans = abs(A-B)//2 elif (N-B <= A-1): ans = (2*N -A-B+1)//2 elif (N-B > A-1): ans = (B+A-1)//2 print(ans)
5
8
132
169
N, A, B = list(map(int, input().split())) if (B - A) % 2 == 0: print(((B - A) // 2)) else: print((min([A + (B - A - 1) // 2, N - B + 1 + (B - A - 1) // 2])))
N, A, B = list(map(int, input().split())) if (A - B) % 2 == 0: ans = abs(A - B) // 2 elif N - B <= A - 1: ans = (2 * N - A - B + 1) // 2 elif N - B > A - 1: ans = (B + A - 1) // 2 print(ans)
false
37.5
[ "-if (B - A) % 2 == 0:", "- print(((B - A) // 2))", "-else:", "- print((min([A + (B - A - 1) // 2, N - B + 1 + (B - A - 1) // 2])))", "+if (A - B) % 2 == 0:", "+ ans = abs(A - B) // 2", "+elif N - B <= A - 1:", "+ ans = (2 * N - A - B + 1) // 2", "+elif N - B > A - 1:", "+ ans = (B + A - 1) // 2", "+print(ans)" ]
false
0.041276
0.035349
1.167659
[ "s932413081", "s956572127" ]
u686036872
p03112
python
s618177035
s538396508
1,851
1,711
13,496
14,176
Accepted
Accepted
7.56
import bisect A, B, Q = list(map(int, input().split())) a=[-float("inf")] b=[-float("inf")] for i in range(A): a.append(int(eval(input()))) for i in range(B): b.append(int(eval(input()))) a+=[float("inf")] b+=[float("inf")] for i in range(Q): q = int(eval(input())) x = bisect.bisect_left(a, q) y = bisect.bisect_left(b, q) ans = float("inf") for j in [a[x-1], a[x]]: for k in [b[y-1], b[y]]: ans1 = abs(j-q)+abs(j-k) ans2 = abs(k-q)+abs(j-k) ans = min(ans, ans1, ans2) print(ans)
import bisect A, B, Q = list(map(int, input().split())) INF=10**18 S=[-INF]+[int(eval(input())) for i in range(A)]+[INF] T=[-INF]+[int(eval(input())) for i in range(B)]+[INF] for i in range(Q): x = int(eval(input())) s = bisect.bisect_left(S, x) t = bisect.bisect_left(T, x) saisyo = float("inf") for j in [S[s], S[s-1]]: for k in [T[t], T[t-1]]: saisyo = min(saisyo, abs(j-x)+abs(k-j), abs(k-x)+abs(j-k)) print(saisyo)
23
17
559
458
import bisect A, B, Q = list(map(int, input().split())) a = [-float("inf")] b = [-float("inf")] for i in range(A): a.append(int(eval(input()))) for i in range(B): b.append(int(eval(input()))) a += [float("inf")] b += [float("inf")] for i in range(Q): q = int(eval(input())) x = bisect.bisect_left(a, q) y = bisect.bisect_left(b, q) ans = float("inf") for j in [a[x - 1], a[x]]: for k in [b[y - 1], b[y]]: ans1 = abs(j - q) + abs(j - k) ans2 = abs(k - q) + abs(j - k) ans = min(ans, ans1, ans2) print(ans)
import bisect A, B, Q = list(map(int, input().split())) INF = 10**18 S = [-INF] + [int(eval(input())) for i in range(A)] + [INF] T = [-INF] + [int(eval(input())) for i in range(B)] + [INF] for i in range(Q): x = int(eval(input())) s = bisect.bisect_left(S, x) t = bisect.bisect_left(T, x) saisyo = float("inf") for j in [S[s], S[s - 1]]: for k in [T[t], T[t - 1]]: saisyo = min(saisyo, abs(j - x) + abs(k - j), abs(k - x) + abs(j - k)) print(saisyo)
false
26.086957
[ "-a = [-float(\"inf\")]", "-b = [-float(\"inf\")]", "-for i in range(A):", "- a.append(int(eval(input())))", "-for i in range(B):", "- b.append(int(eval(input())))", "-a += [float(\"inf\")]", "-b += [float(\"inf\")]", "+INF = 10**18", "+S = [-INF] + [int(eval(input())) for i in range(A)] + [INF]", "+T = [-INF] + [int(eval(input())) for i in range(B)] + [INF]", "- q = int(eval(input()))", "- x = bisect.bisect_left(a, q)", "- y = bisect.bisect_left(b, q)", "- ans = float(\"inf\")", "- for j in [a[x - 1], a[x]]:", "- for k in [b[y - 1], b[y]]:", "- ans1 = abs(j - q) + abs(j - k)", "- ans2 = abs(k - q) + abs(j - k)", "- ans = min(ans, ans1, ans2)", "- print(ans)", "+ x = int(eval(input()))", "+ s = bisect.bisect_left(S, x)", "+ t = bisect.bisect_left(T, x)", "+ saisyo = float(\"inf\")", "+ for j in [S[s], S[s - 1]]:", "+ for k in [T[t], T[t - 1]]:", "+ saisyo = min(saisyo, abs(j - x) + abs(k - j), abs(k - x) + abs(j - k))", "+ print(saisyo)" ]
false
0.090504
0.075124
1.204723
[ "s618177035", "s538396508" ]
u561231954
p03163
python
s263204885
s902835393
513
230
120,044
92,088
Accepted
Accepted
55.17
n,W=list(map(int,input().split())) items=[list(map(int,input().split())) for i in range(n)] dp=[[0]*(W+1) for i in range(n+1)] for i in range(n-1,-1,-1): for j in range(W+1): if j<items[i][0]: dp[i][j]=dp[i+1][j] else: dp[i][j]=max(dp[i+1][j],dp[i+1][j-items[i][0]]+items[i][1]) print((dp[0][W]))
def main(): import numpy as np import sys input=sys.stdin.readline n,w=list(map(int,input().split())) items=np.array([list(map(int,input().split())) for _ in range(n)]) dp=np.zeros([n+1,w+1],dtype=np.int64) for i in range(n): wi=items[i][0] vi=items[i][1] dp[i+1][:wi]=dp[i][:wi] dp[i+1][wi:]=np.maximum(dp[i][wi:],dp[i][:-wi]+vi) print((dp[-1][-1])) if __name__=='__main__': main()
13
19
330
477
n, W = list(map(int, input().split())) items = [list(map(int, input().split())) for i in range(n)] dp = [[0] * (W + 1) for i in range(n + 1)] for i in range(n - 1, -1, -1): for j in range(W + 1): if j < items[i][0]: dp[i][j] = dp[i + 1][j] else: dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - items[i][0]] + items[i][1]) print((dp[0][W]))
def main(): import numpy as np import sys input = sys.stdin.readline n, w = list(map(int, input().split())) items = np.array([list(map(int, input().split())) for _ in range(n)]) dp = np.zeros([n + 1, w + 1], dtype=np.int64) for i in range(n): wi = items[i][0] vi = items[i][1] dp[i + 1][:wi] = dp[i][:wi] dp[i + 1][wi:] = np.maximum(dp[i][wi:], dp[i][:-wi] + vi) print((dp[-1][-1])) if __name__ == "__main__": main()
false
31.578947
[ "-n, W = list(map(int, input().split()))", "-items = [list(map(int, input().split())) for i in range(n)]", "-dp = [[0] * (W + 1) for i in range(n + 1)]", "-for i in range(n - 1, -1, -1):", "- for j in range(W + 1):", "- if j < items[i][0]:", "- dp[i][j] = dp[i + 1][j]", "- else:", "- dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - items[i][0]] + items[i][1])", "-print((dp[0][W]))", "+def main():", "+ import numpy as np", "+ import sys", "+", "+ input = sys.stdin.readline", "+ n, w = list(map(int, input().split()))", "+ items = np.array([list(map(int, input().split())) for _ in range(n)])", "+ dp = np.zeros([n + 1, w + 1], dtype=np.int64)", "+ for i in range(n):", "+ wi = items[i][0]", "+ vi = items[i][1]", "+ dp[i + 1][:wi] = dp[i][:wi]", "+ dp[i + 1][wi:] = np.maximum(dp[i][wi:], dp[i][:-wi] + vi)", "+ print((dp[-1][-1]))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.06162
0.332037
0.185581
[ "s263204885", "s902835393" ]
u844646164
p02973
python
s852047695
s567135415
546
338
56,152
49,884
Accepted
Accepted
38.1
import bisect N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] b = [] for a in A[::-1]: idx = bisect.bisect_right(b, a) if len(b) <= idx: b.append(a) else: b[idx] = a print((len(b)))
import bisect import sys input = sys.stdin.readline N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] dp = [float('inf')]*(N+1) for a in A[::-1]: idx = bisect.bisect_right(dp, a) dp[idx] = a ans = 0 for n in dp: if n != float('inf'): ans += 1 print(ans)
12
16
212
284
import bisect N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] b = [] for a in A[::-1]: idx = bisect.bisect_right(b, a) if len(b) <= idx: b.append(a) else: b[idx] = a print((len(b)))
import bisect import sys input = sys.stdin.readline N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] dp = [float("inf")] * (N + 1) for a in A[::-1]: idx = bisect.bisect_right(dp, a) dp[idx] = a ans = 0 for n in dp: if n != float("inf"): ans += 1 print(ans)
false
25
[ "+import sys", "+input = sys.stdin.readline", "-b = []", "+dp = [float(\"inf\")] * (N + 1)", "- idx = bisect.bisect_right(b, a)", "- if len(b) <= idx:", "- b.append(a)", "- else:", "- b[idx] = a", "-print((len(b)))", "+ idx = bisect.bisect_right(dp, a)", "+ dp[idx] = a", "+ans = 0", "+for n in dp:", "+ if n != float(\"inf\"):", "+ ans += 1", "+print(ans)" ]
false
0.055278
0.048634
1.136611
[ "s852047695", "s567135415" ]
u992910889
p03910
python
s628725262
s792436634
258
209
44,784
41,712
Accepted
Accepted
18.99
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): N = int(eval(input())) def main(N): i = 1 ans = 0 while True: ans += i if ans >= N: print(i) if N - i != 0: if N-i<i: print((N - i)) return True else: main(N-i) return True else: return True else: i += 1 main(N) resolve()
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): n=int(eval(input())) ans=0 i=0 while ans<n: i+=1 ans+=i print(i) rem=n-i i-=1 if rem!=0: while i>0: if rem-i>=0: print(i) rem -=i i-=1 else: i-=1 resolve()
35
28
660
437
import sys sys.setrecursionlimit(10**5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): N = int(eval(input())) def main(N): i = 1 ans = 0 while True: ans += i if ans >= N: print(i) if N - i != 0: if N - i < i: print((N - i)) return True else: main(N - i) return True else: return True else: i += 1 main(N) resolve()
import sys sys.setrecursionlimit(10**5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): n = int(eval(input())) ans = 0 i = 0 while ans < n: i += 1 ans += i print(i) rem = n - i i -= 1 if rem != 0: while i > 0: if rem - i >= 0: print(i) rem -= i i -= 1 else: i -= 1 resolve()
false
20
[ "- N = int(eval(input()))", "-", "- def main(N):", "- i = 1", "- ans = 0", "- while True:", "- ans += i", "- if ans >= N:", "+ n = int(eval(input()))", "+ ans = 0", "+ i = 0", "+ while ans < n:", "+ i += 1", "+ ans += i", "+ print(i)", "+ rem = n - i", "+ i -= 1", "+ if rem != 0:", "+ while i > 0:", "+ if rem - i >= 0:", "- if N - i != 0:", "- if N - i < i:", "- print((N - i))", "- return True", "- else:", "- main(N - i)", "- return True", "- else:", "- return True", "+ rem -= i", "+ i -= 1", "- i += 1", "-", "- main(N)", "+ i -= 1" ]
false
0.041953
0.115567
0.363021
[ "s628725262", "s792436634" ]
u326609687
p03074
python
s319292568
s781586138
65
49
4,460
4,468
Accepted
Accepted
24.62
from collections import deque def nextj(n): while S[n] == '0': n += 1 if n == N: return N q.appendleft(n) while S[n] == '1': n += 1 if n == N: return N return n def init(n): while S[n] == '1': n += 1 if n == N: return N return n def calc(): q.appendleft(0) ans = 0 j = init(0) if j == N: return N for _ in range(K - 1): j = nextj(j) if j == N: return N while True: j = nextj(j) ans = max(ans, j - q.pop()) if j == N: return ans N, K = list(map(int, input().split())) S = eval(input()) q = deque() print((calc()))
from collections import deque def calc(): q.appendleft(0) ans = 0 d = '1' kc = 0 for i, c in enumerate(S): if c != d: d = c if c == '0': if kc == K: ans = max(ans, i - q.pop()) else: kc += 1 else: q.appendleft(i) return max(ans, N - q.pop()) N, K = list(map(int, input().split())) S = eval(input()) q = deque() print((calc()))
45
25
755
497
from collections import deque def nextj(n): while S[n] == "0": n += 1 if n == N: return N q.appendleft(n) while S[n] == "1": n += 1 if n == N: return N return n def init(n): while S[n] == "1": n += 1 if n == N: return N return n def calc(): q.appendleft(0) ans = 0 j = init(0) if j == N: return N for _ in range(K - 1): j = nextj(j) if j == N: return N while True: j = nextj(j) ans = max(ans, j - q.pop()) if j == N: return ans N, K = list(map(int, input().split())) S = eval(input()) q = deque() print((calc()))
from collections import deque def calc(): q.appendleft(0) ans = 0 d = "1" kc = 0 for i, c in enumerate(S): if c != d: d = c if c == "0": if kc == K: ans = max(ans, i - q.pop()) else: kc += 1 else: q.appendleft(i) return max(ans, N - q.pop()) N, K = list(map(int, input().split())) S = eval(input()) q = deque() print((calc()))
false
44.444444
[ "-", "-", "-def nextj(n):", "- while S[n] == \"0\":", "- n += 1", "- if n == N:", "- return N", "- q.appendleft(n)", "- while S[n] == \"1\":", "- n += 1", "- if n == N:", "- return N", "- return n", "-", "-", "-def init(n):", "- while S[n] == \"1\":", "- n += 1", "- if n == N:", "- return N", "- return n", "- j = init(0)", "- if j == N:", "- return N", "- for _ in range(K - 1):", "- j = nextj(j)", "- if j == N:", "- return N", "- while True:", "- j = nextj(j)", "- ans = max(ans, j - q.pop())", "- if j == N:", "- return ans", "+ d = \"1\"", "+ kc = 0", "+ for i, c in enumerate(S):", "+ if c != d:", "+ d = c", "+ if c == \"0\":", "+ if kc == K:", "+ ans = max(ans, i - q.pop())", "+ else:", "+ kc += 1", "+ else:", "+ q.appendleft(i)", "+ return max(ans, N - q.pop())" ]
false
0.039282
0.04741
0.828559
[ "s319292568", "s781586138" ]
u786150969
p03331
python
s217027209
s820784309
233
129
9,500
9,232
Accepted
Accepted
44.64
# AGC 025 A - Digits Sum N = int(eval(input())) def sum_of(num): list_b = [] k = 0 while num > 0: list_b.append(num%10) num //= 10 for i in range(len(list_b)): k += list_b[i] return k list_a =[] if N <= 10: print((str(N))) if N > 10: for i in range(2,N-1): A = i B = N - i list_a.append(sum_of(A) + sum_of(B)) print((min(list_a)))
# AGC 025 A - Digits Sum N = int(eval(input())) def sum_of(num): list_b = [] k = 0 while num > 0: list_b.append(num%10) num //= 10 for i in range(len(list_b)): k += list_b[i] return k list_a =[] if N <= 10: print((str(N))) if N > 10: for i in range(2,(N-1)//2+1): A = i B = N - i list_a.append(sum_of(A) + sum_of(B)) print((min(list_a)))
22
22
425
432
# AGC 025 A - Digits Sum N = int(eval(input())) def sum_of(num): list_b = [] k = 0 while num > 0: list_b.append(num % 10) num //= 10 for i in range(len(list_b)): k += list_b[i] return k list_a = [] if N <= 10: print((str(N))) if N > 10: for i in range(2, N - 1): A = i B = N - i list_a.append(sum_of(A) + sum_of(B)) print((min(list_a)))
# AGC 025 A - Digits Sum N = int(eval(input())) def sum_of(num): list_b = [] k = 0 while num > 0: list_b.append(num % 10) num //= 10 for i in range(len(list_b)): k += list_b[i] return k list_a = [] if N <= 10: print((str(N))) if N > 10: for i in range(2, (N - 1) // 2 + 1): A = i B = N - i list_a.append(sum_of(A) + sum_of(B)) print((min(list_a)))
false
0
[ "- for i in range(2, N - 1):", "+ for i in range(2, (N - 1) // 2 + 1):" ]
false
0.198389
0.122796
1.615593
[ "s217027209", "s820784309" ]
u225388820
p03488
python
s102525948
s050345047
322
278
83,780
83,512
Accepted
Accepted
13.66
from copy import copy s = eval(input()) + "T" n=len(s) x, y = list(map(int, input().split())) xy=[[],[]] sgn = 1 now = n for i in range(n): if s[i] == "T": x -= i now = i + 1 break for i in range(now, n): if s[i] == "T": xy[sgn].append(i - now) now = i + 1 sgn ^= 1 cur = {0} for i in xy[0]: nxt = set() for j in cur: nxt.add(j + i) nxt.add(j - i) cur = copy(nxt) flag = x in cur cur = {0} for i in xy[1]: nxt = set() for j in cur: nxt.add(j + i) nxt.add(j - i) cur = copy(nxt) print(("Yes" if flag and y in cur else "No"))
from copy import copy s = eval(input()) n=len(s) x, y = list(map(int, input().split())) d = [len(v) for v in s.split("T")] x -= d[0] a = d[2::2] b = d[1::2] def c(d, x): cur = {0} for i in d: nxt = set() for j in cur: nxt.add(j + i) nxt.add(j - i) cur = copy(nxt) return x in cur print(("Yes" if c(a, x) and c(b, y) else "No"))
40
22
667
398
from copy import copy s = eval(input()) + "T" n = len(s) x, y = list(map(int, input().split())) xy = [[], []] sgn = 1 now = n for i in range(n): if s[i] == "T": x -= i now = i + 1 break for i in range(now, n): if s[i] == "T": xy[sgn].append(i - now) now = i + 1 sgn ^= 1 cur = {0} for i in xy[0]: nxt = set() for j in cur: nxt.add(j + i) nxt.add(j - i) cur = copy(nxt) flag = x in cur cur = {0} for i in xy[1]: nxt = set() for j in cur: nxt.add(j + i) nxt.add(j - i) cur = copy(nxt) print(("Yes" if flag and y in cur else "No"))
from copy import copy s = eval(input()) n = len(s) x, y = list(map(int, input().split())) d = [len(v) for v in s.split("T")] x -= d[0] a = d[2::2] b = d[1::2] def c(d, x): cur = {0} for i in d: nxt = set() for j in cur: nxt.add(j + i) nxt.add(j - i) cur = copy(nxt) return x in cur print(("Yes" if c(a, x) and c(b, y) else "No"))
false
45
[ "-s = eval(input()) + \"T\"", "+s = eval(input())", "-xy = [[], []]", "-sgn = 1", "-now = n", "-for i in range(n):", "- if s[i] == \"T\":", "- x -= i", "- now = i + 1", "- break", "-for i in range(now, n):", "- if s[i] == \"T\":", "- xy[sgn].append(i - now)", "- now = i + 1", "- sgn ^= 1", "-cur = {0}", "-for i in xy[0]:", "- nxt = set()", "- for j in cur:", "- nxt.add(j + i)", "- nxt.add(j - i)", "- cur = copy(nxt)", "-flag = x in cur", "-cur = {0}", "-for i in xy[1]:", "- nxt = set()", "- for j in cur:", "- nxt.add(j + i)", "- nxt.add(j - i)", "- cur = copy(nxt)", "-print((\"Yes\" if flag and y in cur else \"No\"))", "+d = [len(v) for v in s.split(\"T\")]", "+x -= d[0]", "+a = d[2::2]", "+b = d[1::2]", "+", "+", "+def c(d, x):", "+ cur = {0}", "+ for i in d:", "+ nxt = set()", "+ for j in cur:", "+ nxt.add(j + i)", "+ nxt.add(j - i)", "+ cur = copy(nxt)", "+ return x in cur", "+", "+", "+print((\"Yes\" if c(a, x) and c(b, y) else \"No\"))" ]
false
0.048093
0.085971
0.559404
[ "s102525948", "s050345047" ]
u867826040
p02580
python
s991951701
s999325639
2,884
2,357
214,376
144,488
Accepted
Accepted
18.27
from random import randint import numpy as np from numba import njit @njit(cache=True) def f(h,w,m,yp,xp,s): ypm = yp[:,0].max() xpm = xp[:,0].max() yps = yp[yp[:,0] == ypm][:,1] xps = xp[xp[:,0] == xpm][:,1] ans = 0 for ypsi in yps: for xpsi in xps: a = yp[ypsi,0]+xp[xpsi,0] if (ypsi,xpsi) in s: a -= 1 ans = max(ans,a) else: return a return ans h,w,m = list(map(int,input().split())) s = set() yp = np.zeros((h,2),dtype=np.int) xp = np.zeros((w,2),dtype=np.int) yp[:,1] = np.arange(h) xp[:,1] = np.arange(w) for i in range(m): hi,wi = list(map(int,input().split())) s.add((hi-1,wi-1)) yp[hi-1,0] += 1 xp[wi-1,0] += 1 ans = f(h,w,m,yp,xp,s) print(ans)
#from random import randint import numpy as np #@njit def f(h,w,m,ins): yp = np.zeros(h,dtype=np.int) xp = np.zeros(w,dtype=np.int) #yp[:,1] = np.arange(h) #xp[:,1] = np.arange(w) ans = 0 s = set() for hi,wi in ins: s.add((hi-1,wi-1)) yp[hi-1] += 1 xp[wi-1] += 1 ypm = yp[yp.argmax()] xpm = xp[xp.argmax()] yps = np.where(yp == ypm)[0].tolist() xps = np.where(xp == xpm)[0].tolist() #y = yp[yps] for ypsi in yps: for xpsi in xps: a = yp[ypsi]+xp[xpsi] if (ypsi,xpsi) in s: a -= 1 ans = max(ans,a) else: return a return ans if False: while True: h,w = randint(1,10**5*3),randint(1,10**5*3) m = randint(1,min(h*w,10**5*3)) ins = [(randint(1,h),randint(1,w)) for i in range(m)] ans = f(h,w,m,ins) print(ans) else: h,w,m = list(map(int,input().split())) ans = f(h,w,m,[tuple(map(int,input().split())) for i in range(m)]) print(ans)
36
43
817
1,096
from random import randint import numpy as np from numba import njit @njit(cache=True) def f(h, w, m, yp, xp, s): ypm = yp[:, 0].max() xpm = xp[:, 0].max() yps = yp[yp[:, 0] == ypm][:, 1] xps = xp[xp[:, 0] == xpm][:, 1] ans = 0 for ypsi in yps: for xpsi in xps: a = yp[ypsi, 0] + xp[xpsi, 0] if (ypsi, xpsi) in s: a -= 1 ans = max(ans, a) else: return a return ans h, w, m = list(map(int, input().split())) s = set() yp = np.zeros((h, 2), dtype=np.int) xp = np.zeros((w, 2), dtype=np.int) yp[:, 1] = np.arange(h) xp[:, 1] = np.arange(w) for i in range(m): hi, wi = list(map(int, input().split())) s.add((hi - 1, wi - 1)) yp[hi - 1, 0] += 1 xp[wi - 1, 0] += 1 ans = f(h, w, m, yp, xp, s) print(ans)
# from random import randint import numpy as np # @njit def f(h, w, m, ins): yp = np.zeros(h, dtype=np.int) xp = np.zeros(w, dtype=np.int) # yp[:,1] = np.arange(h) # xp[:,1] = np.arange(w) ans = 0 s = set() for hi, wi in ins: s.add((hi - 1, wi - 1)) yp[hi - 1] += 1 xp[wi - 1] += 1 ypm = yp[yp.argmax()] xpm = xp[xp.argmax()] yps = np.where(yp == ypm)[0].tolist() xps = np.where(xp == xpm)[0].tolist() # y = yp[yps] for ypsi in yps: for xpsi in xps: a = yp[ypsi] + xp[xpsi] if (ypsi, xpsi) in s: a -= 1 ans = max(ans, a) else: return a return ans if False: while True: h, w = randint(1, 10**5 * 3), randint(1, 10**5 * 3) m = randint(1, min(h * w, 10**5 * 3)) ins = [(randint(1, h), randint(1, w)) for i in range(m)] ans = f(h, w, m, ins) print(ans) else: h, w, m = list(map(int, input().split())) ans = f(h, w, m, [tuple(map(int, input().split())) for i in range(m)]) print(ans)
false
16.27907
[ "-from random import randint", "+# from random import randint", "-from numba import njit", "-", "-@njit(cache=True)", "-def f(h, w, m, yp, xp, s):", "- ypm = yp[:, 0].max()", "- xpm = xp[:, 0].max()", "- yps = yp[yp[:, 0] == ypm][:, 1]", "- xps = xp[xp[:, 0] == xpm][:, 1]", "+# @njit", "+def f(h, w, m, ins):", "+ yp = np.zeros(h, dtype=np.int)", "+ xp = np.zeros(w, dtype=np.int)", "+ # yp[:,1] = np.arange(h)", "+ # xp[:,1] = np.arange(w)", "+ s = set()", "+ for hi, wi in ins:", "+ s.add((hi - 1, wi - 1))", "+ yp[hi - 1] += 1", "+ xp[wi - 1] += 1", "+ ypm = yp[yp.argmax()]", "+ xpm = xp[xp.argmax()]", "+ yps = np.where(yp == ypm)[0].tolist()", "+ xps = np.where(xp == xpm)[0].tolist()", "+ # y = yp[yps]", "- a = yp[ypsi, 0] + xp[xpsi, 0]", "+ a = yp[ypsi] + xp[xpsi]", "-h, w, m = list(map(int, input().split()))", "-s = set()", "-yp = np.zeros((h, 2), dtype=np.int)", "-xp = np.zeros((w, 2), dtype=np.int)", "-yp[:, 1] = np.arange(h)", "-xp[:, 1] = np.arange(w)", "-for i in range(m):", "- hi, wi = list(map(int, input().split()))", "- s.add((hi - 1, wi - 1))", "- yp[hi - 1, 0] += 1", "- xp[wi - 1, 0] += 1", "-ans = f(h, w, m, yp, xp, s)", "-print(ans)", "+if False:", "+ while True:", "+ h, w = randint(1, 10**5 * 3), randint(1, 10**5 * 3)", "+ m = randint(1, min(h * w, 10**5 * 3))", "+ ins = [(randint(1, h), randint(1, w)) for i in range(m)]", "+ ans = f(h, w, m, ins)", "+ print(ans)", "+else:", "+ h, w, m = list(map(int, input().split()))", "+ ans = f(h, w, m, [tuple(map(int, input().split())) for i in range(m)])", "+ print(ans)" ]
false
0.473722
0.539299
0.878402
[ "s991951701", "s999325639" ]
u392319141
p02709
python
s851278322
s279145608
155
134
105,664
96,320
Accepted
Accepted
13.55
N = int(eval(input())) A = [(a, i) for i, a in enumerate(map(int, input().split()), start=1)] A.sort(reverse=True) dp = [[0] * (N + 1) for _ in range(N + 1)] for s, (a, i) in enumerate(A): for l in range(s + 1): r = s - l dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + a * (i - (l + 1))) dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + a * (N - r - i)) ans = max([max(d) for d in dp]) print(ans)
N = int(eval(input())) A = [(a, i) for i, a in enumerate(map(int, input().split()), start=1)] A.sort(reverse=True) dp = [[0] * (N + 1) for _ in range(N + 1)] for s, (a, i) in enumerate(A): for l in range(s + 1): r = s - l dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + a * (i - (l + 1))) dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + a * (N - r - i)) ans = 0 for i in range(N + 1): ans = max(ans, dp[i][N - i]) print(ans)
14
16
427
461
N = int(eval(input())) A = [(a, i) for i, a in enumerate(map(int, input().split()), start=1)] A.sort(reverse=True) dp = [[0] * (N + 1) for _ in range(N + 1)] for s, (a, i) in enumerate(A): for l in range(s + 1): r = s - l dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + a * (i - (l + 1))) dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + a * (N - r - i)) ans = max([max(d) for d in dp]) print(ans)
N = int(eval(input())) A = [(a, i) for i, a in enumerate(map(int, input().split()), start=1)] A.sort(reverse=True) dp = [[0] * (N + 1) for _ in range(N + 1)] for s, (a, i) in enumerate(A): for l in range(s + 1): r = s - l dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + a * (i - (l + 1))) dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + a * (N - r - i)) ans = 0 for i in range(N + 1): ans = max(ans, dp[i][N - i]) print(ans)
false
12.5
[ "-ans = max([max(d) for d in dp])", "+ans = 0", "+for i in range(N + 1):", "+ ans = max(ans, dp[i][N - i])" ]
false
0.042893
0.160083
0.267942
[ "s851278322", "s279145608" ]
u325282913
p03626
python
s622123482
s982151276
163
67
38,256
61,888
Accepted
Accepted
58.9
MOD = 10**9 + 7 N = int(eval(input())) S = eval(input()) S2 = eval(input()) check = [] flg = False for i in range(N-1): if flg: check.append(2) flg = False continue if S[i] == S[i+1]: flg = True else: check.append(1) if flg: check.append(2) else: check.append(1) ans = 3 if check[0] == 1 else 6 for i in range(1,len(check)): if check[i-1] == 1: ans *= 2 elif check[i] == 2 and check[i-1] == 2: ans *= 3 print((ans%MOD))
MOD = 10**9 + 7 N = int(eval(input())) S1 = eval(input()) S2 = eval(input()) check = [] index = 0 while index < N: if S1[index] == S2[index]: check.append(1) index += 1 else: check.append(2) index += 2 ans = 3 if check[0] == 1 else 6 for i in range(1,len(check)): if check[i-1] == 1: ans *= 2 elif check[i] == 2: ans *= 3 ans %= MOD print(ans)
26
21
508
413
MOD = 10**9 + 7 N = int(eval(input())) S = eval(input()) S2 = eval(input()) check = [] flg = False for i in range(N - 1): if flg: check.append(2) flg = False continue if S[i] == S[i + 1]: flg = True else: check.append(1) if flg: check.append(2) else: check.append(1) ans = 3 if check[0] == 1 else 6 for i in range(1, len(check)): if check[i - 1] == 1: ans *= 2 elif check[i] == 2 and check[i - 1] == 2: ans *= 3 print((ans % MOD))
MOD = 10**9 + 7 N = int(eval(input())) S1 = eval(input()) S2 = eval(input()) check = [] index = 0 while index < N: if S1[index] == S2[index]: check.append(1) index += 1 else: check.append(2) index += 2 ans = 3 if check[0] == 1 else 6 for i in range(1, len(check)): if check[i - 1] == 1: ans *= 2 elif check[i] == 2: ans *= 3 ans %= MOD print(ans)
false
19.230769
[ "-S = eval(input())", "+S1 = eval(input())", "-flg = False", "-for i in range(N - 1):", "- if flg:", "+index = 0", "+while index < N:", "+ if S1[index] == S2[index]:", "+ check.append(1)", "+ index += 1", "+ else:", "- flg = False", "- continue", "- if S[i] == S[i + 1]:", "- flg = True", "- else:", "- check.append(1)", "-if flg:", "- check.append(2)", "-else:", "- check.append(1)", "+ index += 2", "- elif check[i] == 2 and check[i - 1] == 2:", "+ elif check[i] == 2:", "-print((ans % MOD))", "+ ans %= MOD", "+print(ans)" ]
false
0.054262
0.035465
1.530041
[ "s622123482", "s982151276" ]
u193264896
p03044
python
s122294220
s598985994
940
409
155,824
39,144
Accepted
Accepted
56.49
from collections import deque from collections import Counter from itertools import product, permutations,combinations from operator import itemgetter from heapq import heappop, heappush import math import sys input = sys.stdin.readline #文字列のときはうまく行かないのでコメントアウトすること sys.setrecursionlimit(2147483647) def main(): N = int(eval(input())) G = [[] for i in range(N)] C = [-1] * N C[0] = 0 for i in range(N-1): u, v, w = list(map(int, input().split())) u, v = u-1, v-1 G[u].append((v,w)) G[v].append((u,w)) def dfs(now): for ne_xt, w in G[now]: if C[ne_xt]==-1: C[ne_xt]=(C[now]+w)%2 dfs(ne_xt) dfs(0) for i in range(N): print((C[i])) if __name__ == '__main__': main()
import sys from collections import deque readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N = int(readline()) tree = [[] for _ in range(N)] for i in range(N-1): u, v, w = list(map(int, readline().split())) u, v = u-1, v-1 tree[u].append((v,w)) tree[v].append((u,w)) color = [-1]*N color[0]=0 que = deque([0]) while que: index = que.popleft() for next_, weight in tree[index]: if color[next_]==-1: if weight%2==0: color[next_] = color[index] else: color[next_] = color[index]^1 que.append(next_) for c in color: print(c) if __name__ == '__main__': main()
33
34
751
844
from collections import deque from collections import Counter from itertools import product, permutations, combinations from operator import itemgetter from heapq import heappop, heappush import math import sys input = sys.stdin.readline # 文字列のときはうまく行かないのでコメントアウトすること sys.setrecursionlimit(2147483647) def main(): N = int(eval(input())) G = [[] for i in range(N)] C = [-1] * N C[0] = 0 for i in range(N - 1): u, v, w = list(map(int, input().split())) u, v = u - 1, v - 1 G[u].append((v, w)) G[v].append((u, w)) def dfs(now): for ne_xt, w in G[now]: if C[ne_xt] == -1: C[ne_xt] = (C[now] + w) % 2 dfs(ne_xt) dfs(0) for i in range(N): print((C[i])) if __name__ == "__main__": main()
import sys from collections import deque readline = sys.stdin.buffer.readline sys.setrecursionlimit(10**8) INF = float("inf") MOD = 10**9 + 7 def main(): N = int(readline()) tree = [[] for _ in range(N)] for i in range(N - 1): u, v, w = list(map(int, readline().split())) u, v = u - 1, v - 1 tree[u].append((v, w)) tree[v].append((u, w)) color = [-1] * N color[0] = 0 que = deque([0]) while que: index = que.popleft() for next_, weight in tree[index]: if color[next_] == -1: if weight % 2 == 0: color[next_] = color[index] else: color[next_] = color[index] ^ 1 que.append(next_) for c in color: print(c) if __name__ == "__main__": main()
false
2.941176
[ "+import sys", "-from collections import Counter", "-from itertools import product, permutations, combinations", "-from operator import itemgetter", "-from heapq import heappop, heappush", "-import math", "-import sys", "-input = sys.stdin.readline", "-# 文字列のときはうまく行かないのでコメントアウトすること", "-sys.setrecursionlimit(2147483647)", "+readline = sys.stdin.buffer.readline", "+sys.setrecursionlimit(10**8)", "+INF = float(\"inf\")", "+MOD = 10**9 + 7", "- N = int(eval(input()))", "- G = [[] for i in range(N)]", "- C = [-1] * N", "- C[0] = 0", "+ N = int(readline())", "+ tree = [[] for _ in range(N)]", "- u, v, w = list(map(int, input().split()))", "+ u, v, w = list(map(int, readline().split()))", "- G[u].append((v, w))", "- G[v].append((u, w))", "-", "- def dfs(now):", "- for ne_xt, w in G[now]:", "- if C[ne_xt] == -1:", "- C[ne_xt] = (C[now] + w) % 2", "- dfs(ne_xt)", "-", "- dfs(0)", "- for i in range(N):", "- print((C[i]))", "+ tree[u].append((v, w))", "+ tree[v].append((u, w))", "+ color = [-1] * N", "+ color[0] = 0", "+ que = deque([0])", "+ while que:", "+ index = que.popleft()", "+ for next_, weight in tree[index]:", "+ if color[next_] == -1:", "+ if weight % 2 == 0:", "+ color[next_] = color[index]", "+ else:", "+ color[next_] = color[index] ^ 1", "+ que.append(next_)", "+ for c in color:", "+ print(c)" ]
false
0.044112
0.043022
1.02535
[ "s122294220", "s598985994" ]
u936985471
p03141
python
s603404546
s428739645
527
245
30,056
32,588
Accepted
Accepted
53.51
N=int(eval(input())) A=[0]*N B=[0]*N diff=[0]*N for i in range(N): A[i],B[i]=list(map(int,input().split())) diff[i]=[A[i]+B[i],i] diff=sorted(diff,key=lambda x:x[0])[::-1] taka=0 aoki=0 for i in range(len(diff)): if i%2==0: taka+=A[diff[i][1]] else: aoki+=B[diff[i][1]] print((taka-aoki))
import sys readline = sys.stdin.readline N = int(readline()) A = [0] * N B = [0] * N C = [0] * N for i in range(N): A[i],B[i] = list(map(int,readline().split())) C[i] = (A[i] + B[i], i) C = sorted(C, key = lambda x:x[0], reverse = True) ans = 0 for i in range(len(C)): if i % 2 == 0: ans += A[C[i][1]] else: ans -= B[C[i][1]] print(ans)
18
21
311
376
N = int(eval(input())) A = [0] * N B = [0] * N diff = [0] * N for i in range(N): A[i], B[i] = list(map(int, input().split())) diff[i] = [A[i] + B[i], i] diff = sorted(diff, key=lambda x: x[0])[::-1] taka = 0 aoki = 0 for i in range(len(diff)): if i % 2 == 0: taka += A[diff[i][1]] else: aoki += B[diff[i][1]] print((taka - aoki))
import sys readline = sys.stdin.readline N = int(readline()) A = [0] * N B = [0] * N C = [0] * N for i in range(N): A[i], B[i] = list(map(int, readline().split())) C[i] = (A[i] + B[i], i) C = sorted(C, key=lambda x: x[0], reverse=True) ans = 0 for i in range(len(C)): if i % 2 == 0: ans += A[C[i][1]] else: ans -= B[C[i][1]] print(ans)
false
14.285714
[ "-N = int(eval(input()))", "+import sys", "+", "+readline = sys.stdin.readline", "+N = int(readline())", "-diff = [0] * N", "+C = [0] * N", "- A[i], B[i] = list(map(int, input().split()))", "- diff[i] = [A[i] + B[i], i]", "-diff = sorted(diff, key=lambda x: x[0])[::-1]", "-taka = 0", "-aoki = 0", "-for i in range(len(diff)):", "+ A[i], B[i] = list(map(int, readline().split()))", "+ C[i] = (A[i] + B[i], i)", "+C = sorted(C, key=lambda x: x[0], reverse=True)", "+ans = 0", "+for i in range(len(C)):", "- taka += A[diff[i][1]]", "+ ans += A[C[i][1]]", "- aoki += B[diff[i][1]]", "-print((taka - aoki))", "+ ans -= B[C[i][1]]", "+print(ans)" ]
false
0.036838
0.037508
0.98214
[ "s603404546", "s428739645" ]
u120691615
p03456
python
s995756049
s307832894
23
18
2,940
2,940
Accepted
Accepted
21.74
a,b = list(map(str,input().split())) x = int(a + b) ans = "No" for i in range(x // 2): if x == i * i: ans = "Yes" print(ans)
a,b = list(map(str,input().split())) x = int(a + b) if x ** 0.5 == int(x ** 0.5): print("Yes") else: print("No")
7
6
136
119
a, b = list(map(str, input().split())) x = int(a + b) ans = "No" for i in range(x // 2): if x == i * i: ans = "Yes" print(ans)
a, b = list(map(str, input().split())) x = int(a + b) if x**0.5 == int(x**0.5): print("Yes") else: print("No")
false
14.285714
[ "-ans = \"No\"", "-for i in range(x // 2):", "- if x == i * i:", "- ans = \"Yes\"", "-print(ans)", "+if x**0.5 == int(x**0.5):", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.095423
0.049071
1.944576
[ "s995756049", "s307832894" ]
u392319141
p03209
python
s620928313
s844846709
32
24
3,932
3,684
Accepted
Accepted
25
from functools import lru_cache N, X = list(map(int, input().split())) @lru_cache(maxsize=None) def length(level): if level <= 0: return 1 return length(level - 1) * 2 + 3 @lru_cache(maxsize=None) def search(level, right): if level == 0: return 1 ret = 0 right -= 1 if length(level - 1) <= right: ret += search(level - 1, length(level - 1)) right -= length(level - 1) if right > 0: ret += 1 right -= 1 if 0 < right: ret += search(level - 1, right) return ret print((search(N, X)))
from functools import lru_cache N, X = list(map(int, input().split())) @lru_cache(maxsize=None) def size(level): return 1 if level == 0 else size(level - 1) * 2 + 3 @lru_cache(maxsize=None) def calc(level, N): if level == 0: return 1 if N > 0 else 0 N = min(N, size(level)) ret = 0 N -= 1 if N >= size(level - 1): ret += calc(level - 1, size(level - 1)) N -= size(level - 1) if N >= 1: ret += 1 N -= 1 return ret + calc(level - 1, N) print((calc(N, X)))
30
29
609
567
from functools import lru_cache N, X = list(map(int, input().split())) @lru_cache(maxsize=None) def length(level): if level <= 0: return 1 return length(level - 1) * 2 + 3 @lru_cache(maxsize=None) def search(level, right): if level == 0: return 1 ret = 0 right -= 1 if length(level - 1) <= right: ret += search(level - 1, length(level - 1)) right -= length(level - 1) if right > 0: ret += 1 right -= 1 if 0 < right: ret += search(level - 1, right) return ret print((search(N, X)))
from functools import lru_cache N, X = list(map(int, input().split())) @lru_cache(maxsize=None) def size(level): return 1 if level == 0 else size(level - 1) * 2 + 3 @lru_cache(maxsize=None) def calc(level, N): if level == 0: return 1 if N > 0 else 0 N = min(N, size(level)) ret = 0 N -= 1 if N >= size(level - 1): ret += calc(level - 1, size(level - 1)) N -= size(level - 1) if N >= 1: ret += 1 N -= 1 return ret + calc(level - 1, N) print((calc(N, X)))
false
3.333333
[ "-def length(level):", "- if level <= 0:", "- return 1", "- return length(level - 1) * 2 + 3", "+def size(level):", "+ return 1 if level == 0 else size(level - 1) * 2 + 3", "-def search(level, right):", "+def calc(level, N):", "- return 1", "+ return 1 if N > 0 else 0", "+ N = min(N, size(level))", "- right -= 1", "- if length(level - 1) <= right:", "- ret += search(level - 1, length(level - 1))", "- right -= length(level - 1)", "- if right > 0:", "+ N -= 1", "+ if N >= size(level - 1):", "+ ret += calc(level - 1, size(level - 1))", "+ N -= size(level - 1)", "+ if N >= 1:", "- right -= 1", "- if 0 < right:", "- ret += search(level - 1, right)", "- return ret", "+ N -= 1", "+ return ret + calc(level - 1, N)", "-print((search(N, X)))", "+print((calc(N, X)))" ]
false
0.036909
0.036861
1.001306
[ "s620928313", "s844846709" ]
u046158516
p02628
python
s143405525
s305494938
74
61
62,304
62,472
Accepted
Accepted
17.57
n,k=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() ans=0 for i in range(k): ans+=a[i] print(ans)
n,k=list(map(int,input().split())) p=list(map(int,input().split())) p.sort() ans=0 for i in range(k): ans+=p[i] print(ans)
7
7
124
124
n, k = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() ans = 0 for i in range(k): ans += a[i] print(ans)
n, k = list(map(int, input().split())) p = list(map(int, input().split())) p.sort() ans = 0 for i in range(k): ans += p[i] print(ans)
false
0
[ "-a = list(map(int, input().split()))", "-a.sort()", "+p = list(map(int, input().split()))", "+p.sort()", "- ans += a[i]", "+ ans += p[i]" ]
false
0.046737
0.046724
1.000278
[ "s143405525", "s305494938" ]
u682730715
p03062
python
s998203200
s772761148
266
102
29,252
16,644
Accepted
Accepted
61.65
# coding: UTF-8 import sys #sys.setrecursionlimit(n) import heapq import re import bisect import random import math import itertools from collections import defaultdict, deque from copy import deepcopy from decimal import * n = int(eval(input())) a = list(map(int, input().split())) dp = [[0 for i in range(2)] for i in range(n + 1)] dp[0][1] = float('inf') * -1 for i in range(n): dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]) dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]) print((dp[n][0]))
# coding: UTF-8 import sys #sys.setrecursionlimit(n) import heapq import re import bisect import random import math import itertools from collections import defaultdict, deque from copy import deepcopy from decimal import * n = int(eval(input())) a = list(map(int, input().split())) count = 0 s = 0 b = [] for i in range(n): count += 1 if a[i] < 0 else 0 b.append(abs(a[i])) flg = False if count % 2 == 1: flg = True ans = sum(b) if flg: ans -= min(b) * 2 print(ans)
23
29
530
506
# coding: UTF-8 import sys # sys.setrecursionlimit(n) import heapq import re import bisect import random import math import itertools from collections import defaultdict, deque from copy import deepcopy from decimal import * n = int(eval(input())) a = list(map(int, input().split())) dp = [[0 for i in range(2)] for i in range(n + 1)] dp[0][1] = float("inf") * -1 for i in range(n): dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]) dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]) print((dp[n][0]))
# coding: UTF-8 import sys # sys.setrecursionlimit(n) import heapq import re import bisect import random import math import itertools from collections import defaultdict, deque from copy import deepcopy from decimal import * n = int(eval(input())) a = list(map(int, input().split())) count = 0 s = 0 b = [] for i in range(n): count += 1 if a[i] < 0 else 0 b.append(abs(a[i])) flg = False if count % 2 == 1: flg = True ans = sum(b) if flg: ans -= min(b) * 2 print(ans)
false
20.689655
[ "-dp = [[0 for i in range(2)] for i in range(n + 1)]", "-dp[0][1] = float(\"inf\") * -1", "+count = 0", "+s = 0", "+b = []", "- dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i])", "- dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i])", "-print((dp[n][0]))", "+ count += 1 if a[i] < 0 else 0", "+ b.append(abs(a[i]))", "+flg = False", "+if count % 2 == 1:", "+ flg = True", "+ans = sum(b)", "+if flg:", "+ ans -= min(b) * 2", "+print(ans)" ]
false
0.064724
0.043326
1.493875
[ "s998203200", "s772761148" ]
u001024152
p03497
python
s735609592
s199225878
231
169
41,116
32,540
Accepted
Accepted
26.84
from collections import defaultdict from operator import itemgetter N,K = list(map(int, input().split())) a = list(map(int, input().split())) cnt_d = defaultdict(lambda: 0) for ai in a: cnt_d[ai] += 1 cnt_l = sorted(list(cnt_d.items()), key=itemgetter(1)) ans = sum([v for k,v in cnt_l[:-K]]) print(ans)
from collections import defaultdict N,K = list(map(int, input().split())) a = list(map(int, input().split())) cnt_d = defaultdict(lambda: 0) for ai in a: cnt_d[ai] += 1 cnt_v = sorted([v for k,v in list(cnt_d.items())]) print((sum(cnt_v[:-K])))
12
10
309
246
from collections import defaultdict from operator import itemgetter N, K = list(map(int, input().split())) a = list(map(int, input().split())) cnt_d = defaultdict(lambda: 0) for ai in a: cnt_d[ai] += 1 cnt_l = sorted(list(cnt_d.items()), key=itemgetter(1)) ans = sum([v for k, v in cnt_l[:-K]]) print(ans)
from collections import defaultdict N, K = list(map(int, input().split())) a = list(map(int, input().split())) cnt_d = defaultdict(lambda: 0) for ai in a: cnt_d[ai] += 1 cnt_v = sorted([v for k, v in list(cnt_d.items())]) print((sum(cnt_v[:-K])))
false
16.666667
[ "-from operator import itemgetter", "-cnt_l = sorted(list(cnt_d.items()), key=itemgetter(1))", "-ans = sum([v for k, v in cnt_l[:-K]])", "-print(ans)", "+cnt_v = sorted([v for k, v in list(cnt_d.items())])", "+print((sum(cnt_v[:-K])))" ]
false
0.036067
0.07719
0.467247
[ "s735609592", "s199225878" ]
u298297089
p03637
python
s746438596
s596075491
73
63
11,480
11,096
Accepted
Accepted
13.7
n = int(eval(input())) zero = 0 two = 0 four = 0 for i in map(int, input().split()): if i % 4 == 0: four += 1 elif i % 2 == 0 and i % 4 != 0: two += 1 else : zero += 1 flag = True if zero > four: flag = False if zero == four + 1 and two == 0: flag = True print(('Yes' if flag else 'No'))
n = int(eval(input())) two = 0 four = 0 for i in map(int, input().split()): if i % 4 == 0: four += 1 elif i % 2 == 0: two += 1 tmp = two * (two > 1) print(('Yes' if (four * 2 + (four == n // 2) + two * (two > 1)) >= n else 'No'))
18
12
323
259
n = int(eval(input())) zero = 0 two = 0 four = 0 for i in map(int, input().split()): if i % 4 == 0: four += 1 elif i % 2 == 0 and i % 4 != 0: two += 1 else: zero += 1 flag = True if zero > four: flag = False if zero == four + 1 and two == 0: flag = True print(("Yes" if flag else "No"))
n = int(eval(input())) two = 0 four = 0 for i in map(int, input().split()): if i % 4 == 0: four += 1 elif i % 2 == 0: two += 1 tmp = two * (two > 1) print(("Yes" if (four * 2 + (four == n // 2) + two * (two > 1)) >= n else "No"))
false
33.333333
[ "-zero = 0", "- elif i % 2 == 0 and i % 4 != 0:", "+ elif i % 2 == 0:", "- else:", "- zero += 1", "-flag = True", "-if zero > four:", "- flag = False", "- if zero == four + 1 and two == 0:", "- flag = True", "-print((\"Yes\" if flag else \"No\"))", "+tmp = two * (two > 1)", "+print((\"Yes\" if (four * 2 + (four == n // 2) + two * (two > 1)) >= n else \"No\"))" ]
false
0.044849
0.03708
1.209522
[ "s746438596", "s596075491" ]
u411203878
p02720
python
s689097593
s450616095
945
110
42,864
76,692
Accepted
Accepted
88.36
n=int(eval(input())) query = [1, 2, 3, 4, 5, 6, 7, 8, 9] if n <= 9: print(n) else: count = 9 while count<=n: i = query.pop(0) if i%10-1>=0: query.append(i*10+(i%10-1)) count += 1 if count == n: print((i*10+(i%10-1))) break query.append(i*10+(i%10)) count += 1 if count == n: print((i*10+(i%10))) break if i%10+1<=9: query.append(i*10+(i%10+1)) count += 1 if count == n: print((i*10+(i%10+1))) break
from collections import deque n=int(eval(input())) if n < 10: print(n) else: check_box = deque([1,2,3,4,5,6,7,8,9]) check_num = 9 while True: add_num = check_box.popleft() add_num = str(add_num) if int(add_num[-1]) - 1 >= 0: check_box.append(int(add_num + str(int(add_num[-1]) - 1))) check_num += 1 if check_num == n: print((add_num + str(int(add_num[-1]) - 1))) exit() check_num += 1 check_box.append(int(add_num + add_num[-1])) if check_num == n: print((add_num + add_num[-1])) exit() if int(add_num[-1]) + 1 <= 9: check_box.append(int(add_num + str(int(add_num[-1]) + 1))) check_num += 1 if check_num == n: print((add_num + str(int(add_num[-1]) + 1))) exit()
30
33
640
951
n = int(eval(input())) query = [1, 2, 3, 4, 5, 6, 7, 8, 9] if n <= 9: print(n) else: count = 9 while count <= n: i = query.pop(0) if i % 10 - 1 >= 0: query.append(i * 10 + (i % 10 - 1)) count += 1 if count == n: print((i * 10 + (i % 10 - 1))) break query.append(i * 10 + (i % 10)) count += 1 if count == n: print((i * 10 + (i % 10))) break if i % 10 + 1 <= 9: query.append(i * 10 + (i % 10 + 1)) count += 1 if count == n: print((i * 10 + (i % 10 + 1))) break
from collections import deque n = int(eval(input())) if n < 10: print(n) else: check_box = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) check_num = 9 while True: add_num = check_box.popleft() add_num = str(add_num) if int(add_num[-1]) - 1 >= 0: check_box.append(int(add_num + str(int(add_num[-1]) - 1))) check_num += 1 if check_num == n: print((add_num + str(int(add_num[-1]) - 1))) exit() check_num += 1 check_box.append(int(add_num + add_num[-1])) if check_num == n: print((add_num + add_num[-1])) exit() if int(add_num[-1]) + 1 <= 9: check_box.append(int(add_num + str(int(add_num[-1]) + 1))) check_num += 1 if check_num == n: print((add_num + str(int(add_num[-1]) + 1))) exit()
false
9.090909
[ "+from collections import deque", "+", "-query = [1, 2, 3, 4, 5, 6, 7, 8, 9]", "-if n <= 9:", "+if n < 10:", "- count = 9", "- while count <= n:", "- i = query.pop(0)", "- if i % 10 - 1 >= 0:", "- query.append(i * 10 + (i % 10 - 1))", "- count += 1", "- if count == n:", "- print((i * 10 + (i % 10 - 1)))", "- break", "- query.append(i * 10 + (i % 10))", "- count += 1", "- if count == n:", "- print((i * 10 + (i % 10)))", "- break", "- if i % 10 + 1 <= 9:", "- query.append(i * 10 + (i % 10 + 1))", "- count += 1", "- if count == n:", "- print((i * 10 + (i % 10 + 1)))", "- break", "+ check_box = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])", "+ check_num = 9", "+ while True:", "+ add_num = check_box.popleft()", "+ add_num = str(add_num)", "+ if int(add_num[-1]) - 1 >= 0:", "+ check_box.append(int(add_num + str(int(add_num[-1]) - 1)))", "+ check_num += 1", "+ if check_num == n:", "+ print((add_num + str(int(add_num[-1]) - 1)))", "+ exit()", "+ check_num += 1", "+ check_box.append(int(add_num + add_num[-1]))", "+ if check_num == n:", "+ print((add_num + add_num[-1]))", "+ exit()", "+ if int(add_num[-1]) + 1 <= 9:", "+ check_box.append(int(add_num + str(int(add_num[-1]) + 1)))", "+ check_num += 1", "+ if check_num == n:", "+ print((add_num + str(int(add_num[-1]) + 1)))", "+ exit()" ]
false
0.079465
0.121684
0.653045
[ "s689097593", "s450616095" ]
u200228637
p02627
python
s481944051
s174948209
28
22
9,080
9,024
Accepted
Accepted
21.43
a = eval(input()) if a.isupper() == False: print('a') else: print('A')
a = eval(input()) if a.islower() == True: print('a') else: print('A')
5
5
72
72
a = eval(input()) if a.isupper() == False: print("a") else: print("A")
a = eval(input()) if a.islower() == True: print("a") else: print("A")
false
0
[ "-if a.isupper() == False:", "+if a.islower() == True:" ]
false
0.038118
0.111476
0.341939
[ "s481944051", "s174948209" ]
u287132915
p02695
python
s689900285
s902760045
1,552
744
9,136
9,228
Accepted
Accepted
52.06
import itertools n, m, q = list(map(int, input().split())) kumi = [] for i in range(q): kumii = list(map(int, input().split())) kumi.append(kumii) ans = 0 for a in itertools.combinations_with_replacement(list(range(1, m+1)), n): temp = 0 for i in range(q): ai, bi, ci, di = kumi[i] ai, bi = ai-1, bi-1 if a[bi] - a[ai] == ci: temp += di ans = max(ans, temp) print(ans)
n, m, q = list(map(int, input().split())) kumi = [] for i in range(q): kumii = list(map(int, input().split())) kumi.append(kumii) ans = 0 a = [0 for i in range(n)] def dfs(p): global ans if p == 0: for i in range(1, m+1): a[p] = i dfs(p+1) else: for i in range(a[p-1], m+1): a[p] = i if p != n-1: dfs(p+1) else: temp = 0 for j in range(q): ai, bi, ci, di = kumi[j] ai, bi = ai-1, bi-1 if a[bi] - a[ai] == ci: temp += di ans = max(ans, temp) dfs(0) print(ans)
19
30
433
727
import itertools n, m, q = list(map(int, input().split())) kumi = [] for i in range(q): kumii = list(map(int, input().split())) kumi.append(kumii) ans = 0 for a in itertools.combinations_with_replacement(list(range(1, m + 1)), n): temp = 0 for i in range(q): ai, bi, ci, di = kumi[i] ai, bi = ai - 1, bi - 1 if a[bi] - a[ai] == ci: temp += di ans = max(ans, temp) print(ans)
n, m, q = list(map(int, input().split())) kumi = [] for i in range(q): kumii = list(map(int, input().split())) kumi.append(kumii) ans = 0 a = [0 for i in range(n)] def dfs(p): global ans if p == 0: for i in range(1, m + 1): a[p] = i dfs(p + 1) else: for i in range(a[p - 1], m + 1): a[p] = i if p != n - 1: dfs(p + 1) else: temp = 0 for j in range(q): ai, bi, ci, di = kumi[j] ai, bi = ai - 1, bi - 1 if a[bi] - a[ai] == ci: temp += di ans = max(ans, temp) dfs(0) print(ans)
false
36.666667
[ "-import itertools", "-", "-for a in itertools.combinations_with_replacement(list(range(1, m + 1)), n):", "- temp = 0", "- for i in range(q):", "- ai, bi, ci, di = kumi[i]", "- ai, bi = ai - 1, bi - 1", "- if a[bi] - a[ai] == ci:", "- temp += di", "- ans = max(ans, temp)", "+a = [0 for i in range(n)]", "+", "+", "+def dfs(p):", "+ global ans", "+ if p == 0:", "+ for i in range(1, m + 1):", "+ a[p] = i", "+ dfs(p + 1)", "+ else:", "+ for i in range(a[p - 1], m + 1):", "+ a[p] = i", "+ if p != n - 1:", "+ dfs(p + 1)", "+ else:", "+ temp = 0", "+ for j in range(q):", "+ ai, bi, ci, di = kumi[j]", "+ ai, bi = ai - 1, bi - 1", "+ if a[bi] - a[ai] == ci:", "+ temp += di", "+ ans = max(ans, temp)", "+", "+", "+dfs(0)" ]
false
0.123799
0.04998
2.476975
[ "s689900285", "s902760045" ]
u230621983
p03043
python
s611534376
s394664690
48
42
3,060
2,940
Accepted
Accepted
12.5
n, k = list(map(int, input().split())) ans = 0 for i in range(1,n+1): point = i cnt = 0 while point <= k-1: point = point*2 cnt += 1 ans += (1/n) * (1/2)**cnt print(ans)
n, k = list(map(int, input().split())) ans = 0 for i in range(1,n+1): point = i cnt = 0 while point <= k-1: point = point*2 cnt += 1 ans += (1/2)**cnt print((ans/n))
10
10
188
182
n, k = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): point = i cnt = 0 while point <= k - 1: point = point * 2 cnt += 1 ans += (1 / n) * (1 / 2) ** cnt print(ans)
n, k = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): point = i cnt = 0 while point <= k - 1: point = point * 2 cnt += 1 ans += (1 / 2) ** cnt print((ans / n))
false
0
[ "- ans += (1 / n) * (1 / 2) ** cnt", "-print(ans)", "+ ans += (1 / 2) ** cnt", "+print((ans / n))" ]
false
0.166668
0.134246
1.241517
[ "s611534376", "s394664690" ]
u554698951
p03163
python
s000068330
s446341090
137
120
28,540
69,720
Accepted
Accepted
12.41
N, W = list(map(int, input().split())) import numpy as np dp = np.zeros(W + 1, dtype=int) for i in range(N): w, v = list(map(int, input().split())) np.maximum(dp[:-w] + v, dp[w:], out=dp[w:]) print((dp[-1]))
a = [int(x) for x in input().split()] weight = a[1] dp = [0] * weight + [0] for x in range(a[0]): b = [int(x) for x in input().split()] for x in range(weight, b[0] - 1, -1): dp[x] = max(dp[x], dp[x - b[0]] + b[1]) print((dp[-1]))
11
8
215
251
N, W = list(map(int, input().split())) import numpy as np dp = np.zeros(W + 1, dtype=int) for i in range(N): w, v = list(map(int, input().split())) np.maximum(dp[:-w] + v, dp[w:], out=dp[w:]) print((dp[-1]))
a = [int(x) for x in input().split()] weight = a[1] dp = [0] * weight + [0] for x in range(a[0]): b = [int(x) for x in input().split()] for x in range(weight, b[0] - 1, -1): dp[x] = max(dp[x], dp[x - b[0]] + b[1]) print((dp[-1]))
false
27.272727
[ "-N, W = list(map(int, input().split()))", "-import numpy as np", "-", "-dp = np.zeros(W + 1, dtype=int)", "-for i in range(N):", "- w, v = list(map(int, input().split()))", "- np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])", "+a = [int(x) for x in input().split()]", "+weight = a[1]", "+dp = [0] * weight + [0]", "+for x in range(a[0]):", "+ b = [int(x) for x in input().split()]", "+ for x in range(weight, b[0] - 1, -1):", "+ dp[x] = max(dp[x], dp[x - b[0]] + b[1])" ]
false
0.249053
0.049806
5.000413
[ "s000068330", "s446341090" ]
u926412290
p03162
python
s859265035
s792939742
263
235
105,996
83,460
Accepted
Accepted
10.65
N = int(eval(input())) event = [tuple(map(int, input().split())) for _ in range(N)] dp = [[0, 0, 0] for _ in range(N)] dp[0] = event[0] for i in range(1, N): for j in range(3): for k in range(3): if j != k: dp[i][j] = max(dp[i][j], dp[i - 1][k] + event[i][j]) print((max(dp[N - 1])))
N = int(eval(input())) dp = [[0, 0, 0] for _ in range(N + 1)] for i in range(1, N + 1): a = tuple(map(int, input().split())) for j in range(3): for k in range(3): if j != k: dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[j]) print((max(dp[N])))
12
10
329
285
N = int(eval(input())) event = [tuple(map(int, input().split())) for _ in range(N)] dp = [[0, 0, 0] for _ in range(N)] dp[0] = event[0] for i in range(1, N): for j in range(3): for k in range(3): if j != k: dp[i][j] = max(dp[i][j], dp[i - 1][k] + event[i][j]) print((max(dp[N - 1])))
N = int(eval(input())) dp = [[0, 0, 0] for _ in range(N + 1)] for i in range(1, N + 1): a = tuple(map(int, input().split())) for j in range(3): for k in range(3): if j != k: dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[j]) print((max(dp[N])))
false
16.666667
[ "-event = [tuple(map(int, input().split())) for _ in range(N)]", "-dp = [[0, 0, 0] for _ in range(N)]", "-dp[0] = event[0]", "-for i in range(1, N):", "+dp = [[0, 0, 0] for _ in range(N + 1)]", "+for i in range(1, N + 1):", "+ a = tuple(map(int, input().split()))", "- dp[i][j] = max(dp[i][j], dp[i - 1][k] + event[i][j])", "-print((max(dp[N - 1])))", "+ dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[j])", "+print((max(dp[N])))" ]
false
0.043544
0.109472
0.39776
[ "s859265035", "s792939742" ]
u580697892
p03111
python
s932989955
s805846705
560
75
3,188
3,064
Accepted
Accepted
86.61
# coding: utf-8 def Base_10_to_n(X, n): X_dumy = X out = '' while X_dumy>0: out = str(X_dumy%n)+out X_dumy = int(X_dumy/n) return out N, A, B, C = list(map(int, input().split())) L = [int(eval(input())) for _ in range(N)] ans = float("inf") for i in range(4**N): bits = Base_10_to_n(i, 4).zfill(N) a, b, c = 0, 0, 0 cost = 0 for j in range(len(bits)): if bits[j] == "0": pass elif bits[j] == "1": a += L[j] cost += 10 elif bits[j] == "2": b += L[j] cost += 10 else: c += L[j] cost += 10 if min(a, b, c) > 0: ans = min(ans, cost + abs(a-A)+abs(b-B)+abs(c-C) - 10*3) print(ans)
# coding: utf-8 import sys sys.setrecursionlimit(10**9) def Base_10_to_n(X, n): X_dumy = X out = '' while X_dumy>0: out = str(X_dumy%n)+out X_dumy = int(X_dumy/n) return out N, A, B, C = list(map(int, input().split())) L = [] for i in range(N): L.append(int(eval(input()))) # L.sort() def dfs(cnt, a, b, c): if cnt == N: return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a,b,c) > 0 else 10**9 r0 = dfs(cnt+1, a, b, c) r1 = dfs(cnt+1, a+L[cnt], b, c) + 10 r2 = dfs(cnt+1, a, b+L[cnt], c) + 10 r3 = dfs(cnt+1, a, b, c+L[cnt]) + 10 return min(r0, r1, r2, r3) print((dfs(0,0,0,0)))
31
25
774
666
# coding: utf-8 def Base_10_to_n(X, n): X_dumy = X out = "" while X_dumy > 0: out = str(X_dumy % n) + out X_dumy = int(X_dumy / n) return out N, A, B, C = list(map(int, input().split())) L = [int(eval(input())) for _ in range(N)] ans = float("inf") for i in range(4**N): bits = Base_10_to_n(i, 4).zfill(N) a, b, c = 0, 0, 0 cost = 0 for j in range(len(bits)): if bits[j] == "0": pass elif bits[j] == "1": a += L[j] cost += 10 elif bits[j] == "2": b += L[j] cost += 10 else: c += L[j] cost += 10 if min(a, b, c) > 0: ans = min(ans, cost + abs(a - A) + abs(b - B) + abs(c - C) - 10 * 3) print(ans)
# coding: utf-8 import sys sys.setrecursionlimit(10**9) def Base_10_to_n(X, n): X_dumy = X out = "" while X_dumy > 0: out = str(X_dumy % n) + out X_dumy = int(X_dumy / n) return out N, A, B, C = list(map(int, input().split())) L = [] for i in range(N): L.append(int(eval(input()))) # L.sort() def dfs(cnt, a, b, c): if cnt == N: return ( abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else 10**9 ) r0 = dfs(cnt + 1, a, b, c) r1 = dfs(cnt + 1, a + L[cnt], b, c) + 10 r2 = dfs(cnt + 1, a, b + L[cnt], c) + 10 r3 = dfs(cnt + 1, a, b, c + L[cnt]) + 10 return min(r0, r1, r2, r3) print((dfs(0, 0, 0, 0)))
false
19.354839
[ "+import sys", "+", "+sys.setrecursionlimit(10**9)", "+", "+", "-L = [int(eval(input())) for _ in range(N)]", "-ans = float(\"inf\")", "-for i in range(4**N):", "- bits = Base_10_to_n(i, 4).zfill(N)", "- a, b, c = 0, 0, 0", "- cost = 0", "- for j in range(len(bits)):", "- if bits[j] == \"0\":", "- pass", "- elif bits[j] == \"1\":", "- a += L[j]", "- cost += 10", "- elif bits[j] == \"2\":", "- b += L[j]", "- cost += 10", "- else:", "- c += L[j]", "- cost += 10", "- if min(a, b, c) > 0:", "- ans = min(ans, cost + abs(a - A) + abs(b - B) + abs(c - C) - 10 * 3)", "-print(ans)", "+L = []", "+for i in range(N):", "+ L.append(int(eval(input())))", "+# L.sort()", "+def dfs(cnt, a, b, c):", "+ if cnt == N:", "+ return (", "+ abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else 10**9", "+ )", "+ r0 = dfs(cnt + 1, a, b, c)", "+ r1 = dfs(cnt + 1, a + L[cnt], b, c) + 10", "+ r2 = dfs(cnt + 1, a, b + L[cnt], c) + 10", "+ r3 = dfs(cnt + 1, a, b, c + L[cnt]) + 10", "+ return min(r0, r1, r2, r3)", "+", "+", "+print((dfs(0, 0, 0, 0)))" ]
false
0.834013
0.061893
13.475067
[ "s932989955", "s805846705" ]
u070201429
p03325
python
s527830958
s950995748
97
66
73,420
9,964
Accepted
Accepted
31.96
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in a: while i % 32 == 0: i //= 32 ans += 5 while i % 2 == 0: i //= 2 ans += 1 print(ans)
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in a: while i % 2 == 0: i //= 2 ans += 1 print(ans)
13
10
209
150
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in a: while i % 32 == 0: i //= 32 ans += 5 while i % 2 == 0: i //= 2 ans += 1 print(ans)
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in a: while i % 2 == 0: i //= 2 ans += 1 print(ans)
false
23.076923
[ "- while i % 32 == 0:", "- i //= 32", "- ans += 5" ]
false
0.108351
0.107657
1.006446
[ "s527830958", "s950995748" ]
u840310460
p03814
python
s727889795
s104378079
185
59
47,968
11,464
Accepted
Accepted
68.11
S = eval(input()) A_index = [i for i in range(len(S)) if S[i] == "A"] Z_index = [i for i in range(len(S)) if S[i] == "Z"] print((len(S[A_index[0] : Z_index[-1] + 1])))
S = eval(input()) head = [i for i in range(0, len(S)) if S[i]=="A"] tail = [i for i in range(0, len(S)) if S[i]=="Z"] print((max(tail)-min(head)+1))
4
6
162
147
S = eval(input()) A_index = [i for i in range(len(S)) if S[i] == "A"] Z_index = [i for i in range(len(S)) if S[i] == "Z"] print((len(S[A_index[0] : Z_index[-1] + 1])))
S = eval(input()) head = [i for i in range(0, len(S)) if S[i] == "A"] tail = [i for i in range(0, len(S)) if S[i] == "Z"] print((max(tail) - min(head) + 1))
false
33.333333
[ "-A_index = [i for i in range(len(S)) if S[i] == \"A\"]", "-Z_index = [i for i in range(len(S)) if S[i] == \"Z\"]", "-print((len(S[A_index[0] : Z_index[-1] + 1])))", "+head = [i for i in range(0, len(S)) if S[i] == \"A\"]", "+tail = [i for i in range(0, len(S)) if S[i] == \"Z\"]", "+print((max(tail) - min(head) + 1))" ]
false
0.04608
0.037502
1.228747
[ "s727889795", "s104378079" ]
u072053884
p00909
python
s026135728
s380944703
5,270
4,640
133,988
134,640
Accepted
Accepted
11.95
def solve(): def measurement(a, b, w): a_root = root[a] b_root = root[b] if a_root != b_root: a_member = member[a_root] b_member = member[b_root] offset = w - (weight[b] - weight[a]) if len(a_member) > len(b_member): a_member.extend(b_member) for n in b_member: root[n] = a_root weight[n] += offset else: b_member.extend(a_member) for n in a_member: root[n] = b_root weight[n] -= offset def inquiry(a, b): if root[a] == root[b]: return weight[b] - weight[a] else: return 'UNKNOWN' def operation(line): if line[0] == '!': a, b, w = map(int, line[2:].split()) measurement(a, b, w) else: a, b = map(int, line[2:].split()) return inquiry(a, b) import sys file_input = sys.stdin.readlines() while True: N, M = map(int, file_input[0].split()) if N == 0: break root = [i for i in range(N + 1)] member = [[i] for i in range(N + 1)] weight = [0] * (N + 1) ans = (operation(line) for line in file_input[1:M+1]) ans = filter(lambda x: x != None, ans) print(*ans, sep='\n') del file_input[:M+1] solve()
def solve(): def measurement(a, b, w): a_root = root[a] b_root = root[b] if a_root != b_root: a_member = member[a_root] b_member = member[b_root] offset = w - (weight[b] - weight[a]) if len(a_member) > len(b_member): a_member.extend(b_member) for n in b_member: root[n] = a_root weight[n] += offset else: b_member.extend(a_member) for n in a_member: root[n] = b_root weight[n] -= offset def inquiry(a, b): if root[a] == root[b]: return weight[b] - weight[a] else: return 'UNKNOWN' import sys file_input = sys.stdin.readlines() ans = [] while True: N, M = map(int, file_input[0].split()) if N == 0: break root = [i for i in range(N + 1)] member = [[i] for i in range(N + 1)] weight = [0] * (N + 1) for line in file_input[1:M+1]: if line[0] == '!': a, b, w = map(int, line[2:].split()) measurement(a, b, w) else: a, b= map(int, line[2:].split()) ans.append(inquiry(a, b)) del file_input[:M+1] print(*ans, sep='\n') solve()
52
51
1,530
1,494
def solve(): def measurement(a, b, w): a_root = root[a] b_root = root[b] if a_root != b_root: a_member = member[a_root] b_member = member[b_root] offset = w - (weight[b] - weight[a]) if len(a_member) > len(b_member): a_member.extend(b_member) for n in b_member: root[n] = a_root weight[n] += offset else: b_member.extend(a_member) for n in a_member: root[n] = b_root weight[n] -= offset def inquiry(a, b): if root[a] == root[b]: return weight[b] - weight[a] else: return "UNKNOWN" def operation(line): if line[0] == "!": a, b, w = map(int, line[2:].split()) measurement(a, b, w) else: a, b = map(int, line[2:].split()) return inquiry(a, b) import sys file_input = sys.stdin.readlines() while True: N, M = map(int, file_input[0].split()) if N == 0: break root = [i for i in range(N + 1)] member = [[i] for i in range(N + 1)] weight = [0] * (N + 1) ans = (operation(line) for line in file_input[1 : M + 1]) ans = filter(lambda x: x != None, ans) print(*ans, sep="\n") del file_input[: M + 1] solve()
def solve(): def measurement(a, b, w): a_root = root[a] b_root = root[b] if a_root != b_root: a_member = member[a_root] b_member = member[b_root] offset = w - (weight[b] - weight[a]) if len(a_member) > len(b_member): a_member.extend(b_member) for n in b_member: root[n] = a_root weight[n] += offset else: b_member.extend(a_member) for n in a_member: root[n] = b_root weight[n] -= offset def inquiry(a, b): if root[a] == root[b]: return weight[b] - weight[a] else: return "UNKNOWN" import sys file_input = sys.stdin.readlines() ans = [] while True: N, M = map(int, file_input[0].split()) if N == 0: break root = [i for i in range(N + 1)] member = [[i] for i in range(N + 1)] weight = [0] * (N + 1) for line in file_input[1 : M + 1]: if line[0] == "!": a, b, w = map(int, line[2:].split()) measurement(a, b, w) else: a, b = map(int, line[2:].split()) ans.append(inquiry(a, b)) del file_input[: M + 1] print(*ans, sep="\n") solve()
false
1.923077
[ "- def operation(line):", "- if line[0] == \"!\":", "- a, b, w = map(int, line[2:].split())", "- measurement(a, b, w)", "- else:", "- a, b = map(int, line[2:].split())", "- return inquiry(a, b)", "-", "+ ans = []", "- ans = (operation(line) for line in file_input[1 : M + 1])", "- ans = filter(lambda x: x != None, ans)", "- print(*ans, sep=\"\\n\")", "+ for line in file_input[1 : M + 1]:", "+ if line[0] == \"!\":", "+ a, b, w = map(int, line[2:].split())", "+ measurement(a, b, w)", "+ else:", "+ a, b = map(int, line[2:].split())", "+ ans.append(inquiry(a, b))", "+ print(*ans, sep=\"\\n\")" ]
false
0.078806
0.068734
1.146534
[ "s026135728", "s380944703" ]
u638902622
p02695
python
s222176597
s715531219
605
321
9,612
9,168
Accepted
Accepted
46.94
import sys ## io ## def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) def MIIZ(): return list([x-1 for x in MII()]) ## dp ## def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)] def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)] ## math ## def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2) def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8) def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16) MOD=10**9+7 def divc(x,y) -> int: return -(-x//y) def divf(x,y) -> int: return x//y def gcd(x,y): while y: x,y = y,x%y return x def lcm(x,y): return x*y//gcd(x,y) def enumerate_divs(n): """Return a tuple list of divisor of n""" return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0] def get_primes(MAX_NUM=10**3): """Return a list of prime numbers n or less""" is_prime = [True]*(MAX_NUM+1) is_prime[0] = is_prime[1] = False for i in range(2, int(MAX_NUM**0.5)+1): if not is_prime[i]: continue for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False return [i for i in range(MAX_NUM+1) if is_prime[i]] ## libs ## from itertools import accumulate as acc from itertools import combinations_with_replacement as combi from collections import deque, Counter from heapq import heapify, heappop, heappush from bisect import bisect_left #======================================================# def main(): n, m, q = MII() query = [MII() for _ in range(q)] # l = [i for i in range(1,m+1)] # maxv = 0 # for v in combi(l,n): # sumv = 0 # for a,b,c,d in query: # if v[b-1]-v[a-1] == c: # sumv += d # maxv = max(maxv, sumv) # print(maxv) def score(A): res = 0 for a, b, c, d in query: if A[b-1]-A[a-1] == c: res += d return res def dfs(A): if len(A) == n: return score(A) res = 0 prev_last = A[-1] if len(A) > 0 else 0 for v in range(prev_last, m): A.append(v) res = max(res, dfs(A)) A.pop() return res print((dfs([]))) if __name__ == '__main__': main()
import sys ## io ## def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) #======================================================# def main(): n, m, q = MII() query = [MII() for _ in range(q)] def calc_point(lst): sumv = 0 for a, b, c, d in query: if lst[b-1] - lst[a-1] == c: sumv += d return sumv def dfs(lst): if len(lst) == n: return calc_point(lst) point = 0 last_elm = lst[-1] for i in range(last_elm, m+1): point = max(point, dfs(lst+[i])) return point print((dfs([1]))) if __name__ == '__main__': main()
74
32
2,369
753
import sys ## io ## def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) def MIIZ(): return list([x - 1 for x in MII()]) ## dp ## def DD2(d1, d2, init=0): return [[init] * d2 for _ in range(d1)] def DD3(d1, d2, d3, init=0): return [DD2(d2, d3, init) for _ in range(d1)] ## math ## def to_bin(x: int) -> str: return format(x, "b") # rev => int(res, 2) def to_oct(x: int) -> str: return format(x, "o") # rev => int(res, 8) def to_hex(x: int) -> str: return format(x, "x") # rev => int(res, 16) MOD = 10**9 + 7 def divc(x, y) -> int: return -(-x // y) def divf(x, y) -> int: return x // y def gcd(x, y): while y: x, y = y, x % y return x def lcm(x, y): return x * y // gcd(x, y) def enumerate_divs(n): """Return a tuple list of divisor of n""" return [(i, n // i) for i in range(1, int(n**0.5) + 1) if n % i == 0] def get_primes(MAX_NUM=10**3): """Return a list of prime numbers n or less""" is_prime = [True] * (MAX_NUM + 1) is_prime[0] = is_prime[1] = False for i in range(2, int(MAX_NUM**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, MAX_NUM + 1, i): is_prime[j] = False return [i for i in range(MAX_NUM + 1) if is_prime[i]] ## libs ## from itertools import accumulate as acc from itertools import combinations_with_replacement as combi from collections import deque, Counter from heapq import heapify, heappop, heappush from bisect import bisect_left # ======================================================# def main(): n, m, q = MII() query = [MII() for _ in range(q)] # l = [i for i in range(1,m+1)] # maxv = 0 # for v in combi(l,n): # sumv = 0 # for a,b,c,d in query: # if v[b-1]-v[a-1] == c: # sumv += d # maxv = max(maxv, sumv) # print(maxv) def score(A): res = 0 for a, b, c, d in query: if A[b - 1] - A[a - 1] == c: res += d return res def dfs(A): if len(A) == n: return score(A) res = 0 prev_last = A[-1] if len(A) > 0 else 0 for v in range(prev_last, m): A.append(v) res = max(res, dfs(A)) A.pop() return res print((dfs([]))) if __name__ == "__main__": main()
import sys ## io ## def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) # ======================================================# def main(): n, m, q = MII() query = [MII() for _ in range(q)] def calc_point(lst): sumv = 0 for a, b, c, d in query: if lst[b - 1] - lst[a - 1] == c: sumv += d return sumv def dfs(lst): if len(lst) == n: return calc_point(lst) point = 0 last_elm = lst[-1] for i in range(last_elm, m + 1): point = max(point, dfs(lst + [i])) return point print((dfs([1]))) if __name__ == "__main__": main()
false
56.756757
[ "-def MIIZ():", "- return list([x - 1 for x in MII()])", "-", "-", "-## dp ##", "-def DD2(d1, d2, init=0):", "- return [[init] * d2 for _ in range(d1)]", "-", "-", "-def DD3(d1, d2, d3, init=0):", "- return [DD2(d2, d3, init) for _ in range(d1)]", "-", "-", "-## math ##", "-def to_bin(x: int) -> str:", "- return format(x, \"b\") # rev => int(res, 2)", "-", "-", "-def to_oct(x: int) -> str:", "- return format(x, \"o\") # rev => int(res, 8)", "-", "-", "-def to_hex(x: int) -> str:", "- return format(x, \"x\") # rev => int(res, 16)", "-", "-", "-MOD = 10**9 + 7", "-", "-", "-def divc(x, y) -> int:", "- return -(-x // y)", "-", "-", "-def divf(x, y) -> int:", "- return x // y", "-", "-", "-def gcd(x, y):", "- while y:", "- x, y = y, x % y", "- return x", "-", "-", "-def lcm(x, y):", "- return x * y // gcd(x, y)", "-", "-", "-def enumerate_divs(n):", "- \"\"\"Return a tuple list of divisor of n\"\"\"", "- return [(i, n // i) for i in range(1, int(n**0.5) + 1) if n % i == 0]", "-", "-", "-def get_primes(MAX_NUM=10**3):", "- \"\"\"Return a list of prime numbers n or less\"\"\"", "- is_prime = [True] * (MAX_NUM + 1)", "- is_prime[0] = is_prime[1] = False", "- for i in range(2, int(MAX_NUM**0.5) + 1):", "- if not is_prime[i]:", "- continue", "- for j in range(i * 2, MAX_NUM + 1, i):", "- is_prime[j] = False", "- return [i for i in range(MAX_NUM + 1) if is_prime[i]]", "-", "-", "-## libs ##", "-from itertools import accumulate as acc", "-from itertools import combinations_with_replacement as combi", "-from collections import deque, Counter", "-from heapq import heapify, heappop, heappush", "-from bisect import bisect_left", "-", "- # l = [i for i in range(1,m+1)]", "- # maxv = 0", "- # for v in combi(l,n):", "- # sumv = 0", "- # for a,b,c,d in query:", "- # if v[b-1]-v[a-1] == c:", "- # sumv += d", "- # maxv = max(maxv, sumv)", "- # print(maxv)", "- def score(A):", "- res = 0", "+", "+ def calc_point(lst):", "+ sumv = 0", "- if A[b - 1] - A[a - 1] == c:", "- res += d", "- return res", "+ if lst[b - 1] - lst[a - 1] == c:", "+ sumv += d", "+ return sumv", "- def dfs(A):", "- if len(A) == n:", "- return score(A)", "- res = 0", "- prev_last = A[-1] if len(A) > 0 else 0", "- for v in range(prev_last, m):", "- A.append(v)", "- res = max(res, dfs(A))", "- A.pop()", "- return res", "+ def dfs(lst):", "+ if len(lst) == n:", "+ return calc_point(lst)", "+ point = 0", "+ last_elm = lst[-1]", "+ for i in range(last_elm, m + 1):", "+ point = max(point, dfs(lst + [i]))", "+ return point", "- print((dfs([])))", "+ print((dfs([1])))" ]
false
0.190992
0.155249
1.230229
[ "s222176597", "s715531219" ]
u562935282
p02727
python
s620906002
s364874721
251
153
23,328
29,448
Accepted
Accepted
39.04
x, y, a, b, c = list(map(int, input().split())) *p, = list(map(int, input().split())) *q, = list(map(int, input().split())) *r, = list(map(int, input().split())) p.sort(reverse=True) q.sort(reverse=True) pool = p[:x] + q[:y] + r pool.sort(reverse=True) pool = pool[:x + y] ans = sum(pool) print(ans)
def main(): X, Y, A, B, C = list(map(int, input().split())) *P, = list(map(int, input().split())) *Q, = list(map(int, input().split())) *R, = list(map(int, input().split())) P.sort(reverse=True) Q.sort(reverse=True) ans = sum(sorted(P[:X] + Q[:Y] + R, reverse=True)[:X + Y]) print(ans) if __name__ == '__main__': main()
14
15
292
350
x, y, a, b, c = list(map(int, input().split())) (*p,) = list(map(int, input().split())) (*q,) = list(map(int, input().split())) (*r,) = list(map(int, input().split())) p.sort(reverse=True) q.sort(reverse=True) pool = p[:x] + q[:y] + r pool.sort(reverse=True) pool = pool[: x + y] ans = sum(pool) print(ans)
def main(): X, Y, A, B, C = list(map(int, input().split())) (*P,) = list(map(int, input().split())) (*Q,) = list(map(int, input().split())) (*R,) = list(map(int, input().split())) P.sort(reverse=True) Q.sort(reverse=True) ans = sum(sorted(P[:X] + Q[:Y] + R, reverse=True)[: X + Y]) print(ans) if __name__ == "__main__": main()
false
6.666667
[ "-x, y, a, b, c = list(map(int, input().split()))", "-(*p,) = list(map(int, input().split()))", "-(*q,) = list(map(int, input().split()))", "-(*r,) = list(map(int, input().split()))", "-p.sort(reverse=True)", "-q.sort(reverse=True)", "-pool = p[:x] + q[:y] + r", "-pool.sort(reverse=True)", "-pool = pool[: x + y]", "-ans = sum(pool)", "-print(ans)", "+def main():", "+ X, Y, A, B, C = list(map(int, input().split()))", "+ (*P,) = list(map(int, input().split()))", "+ (*Q,) = list(map(int, input().split()))", "+ (*R,) = list(map(int, input().split()))", "+ P.sort(reverse=True)", "+ Q.sort(reverse=True)", "+ ans = sum(sorted(P[:X] + Q[:Y] + R, reverse=True)[: X + Y])", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.082385
0.048094
1.713025
[ "s620906002", "s364874721" ]
u649591440
p02897
python
s317053808
s571095851
19
17
2,940
2,940
Accepted
Accepted
10.53
#question1 N = eval(input()) if int(N) % 2 == 0: ans = 0.5 elif int(N) == 1: ans = 1 else: ans = ((int(N) - 1) /2 + 1) / int(N) print(ans)
#question1 N = eval(input()) if int(N) % 2 == 0: ans = 0.5 else: ans = ((int(N) - 1) /2 + 1) / int(N) print(ans)
11
9
150
120
# question1 N = eval(input()) if int(N) % 2 == 0: ans = 0.5 elif int(N) == 1: ans = 1 else: ans = ((int(N) - 1) / 2 + 1) / int(N) print(ans)
# question1 N = eval(input()) if int(N) % 2 == 0: ans = 0.5 else: ans = ((int(N) - 1) / 2 + 1) / int(N) print(ans)
false
18.181818
[ "-elif int(N) == 1:", "- ans = 1" ]
false
0.067668
0.038933
1.738061
[ "s317053808", "s571095851" ]
u952708174
p03494
python
s860875358
s992981453
19
17
3,060
3,060
Accepted
Accepted
10.53
def b_shift_only(N, A): def is_even(lst): # リストの要素がすべて偶数か? for x in lst: if x % 2 == 1: return False return True a = A[:] count = 0 # 奇数が要素に現れるまで要素を2で割る while is_even(a): a = [x // 2 for x in a] count += 1 return count N = int(eval(input())) A = [int(i) for i in input().split()] print((b_shift_only(N, A)))
def b_shift_only(N, A): # Aの全要素についてbitごとorを取った値が # 何回2で割れるかが解となる bitwise_or = 0 for a in A: bitwise_or |= a ans = 0 while bitwise_or % 2 == 0: bitwise_or //= 2 ans += 1 return ans N = int(eval(input())) A = [int(i) for i in input().split()] print((b_shift_only(N, A)))
18
16
409
333
def b_shift_only(N, A): def is_even(lst): # リストの要素がすべて偶数か? for x in lst: if x % 2 == 1: return False return True a = A[:] count = 0 # 奇数が要素に現れるまで要素を2で割る while is_even(a): a = [x // 2 for x in a] count += 1 return count N = int(eval(input())) A = [int(i) for i in input().split()] print((b_shift_only(N, A)))
def b_shift_only(N, A): # Aの全要素についてbitごとorを取った値が # 何回2で割れるかが解となる bitwise_or = 0 for a in A: bitwise_or |= a ans = 0 while bitwise_or % 2 == 0: bitwise_or //= 2 ans += 1 return ans N = int(eval(input())) A = [int(i) for i in input().split()] print((b_shift_only(N, A)))
false
11.111111
[ "- def is_even(lst):", "- # リストの要素がすべて偶数か?", "- for x in lst:", "- if x % 2 == 1:", "- return False", "- return True", "-", "- a = A[:]", "- count = 0", "- # 奇数が要素に現れるまで要素を2で割る", "- while is_even(a):", "- a = [x // 2 for x in a]", "- count += 1", "- return count", "+ # Aの全要素についてbitごとorを取った値が", "+ # 何回2で割れるかが解となる", "+ bitwise_or = 0", "+ for a in A:", "+ bitwise_or |= a", "+ ans = 0", "+ while bitwise_or % 2 == 0:", "+ bitwise_or //= 2", "+ ans += 1", "+ return ans" ]
false
0.046593
0.045904
1.015006
[ "s860875358", "s992981453" ]
u418826171
p02773
python
s090402964
s795144850
510
447
25,248
38,904
Accepted
Accepted
12.35
n = int(eval(input())) S = ['']*n T = [] for i in range(n): S[i] = eval(input()) S.sort() if n == 1: print((S[0])) exit() cnt = 1 mxcnt = 1 for i in range(n-1): if S[i] == S[i+1]: cnt += 1 else: cnt = 1 mxcnt = max(mxcnt,cnt) cnt = 1 for i in range(n-1): if S[i] == S[i+1]: cnt += 1 else: cnt = 1 if cnt == mxcnt: T.append(S[i]) if mxcnt == 1: T.append(S[-1]) for t in T: print(t)
from collections import Counter n = int(eval(input())) s = [eval(input()) for i in range(n)] num = Counter(s) mx = max(num.values()) T = [] for n in sorted(num): if num[n] == mx: print(n)
29
9
478
195
n = int(eval(input())) S = [""] * n T = [] for i in range(n): S[i] = eval(input()) S.sort() if n == 1: print((S[0])) exit() cnt = 1 mxcnt = 1 for i in range(n - 1): if S[i] == S[i + 1]: cnt += 1 else: cnt = 1 mxcnt = max(mxcnt, cnt) cnt = 1 for i in range(n - 1): if S[i] == S[i + 1]: cnt += 1 else: cnt = 1 if cnt == mxcnt: T.append(S[i]) if mxcnt == 1: T.append(S[-1]) for t in T: print(t)
from collections import Counter n = int(eval(input())) s = [eval(input()) for i in range(n)] num = Counter(s) mx = max(num.values()) T = [] for n in sorted(num): if num[n] == mx: print(n)
false
68.965517
[ "+from collections import Counter", "+", "-S = [\"\"] * n", "+s = [eval(input()) for i in range(n)]", "+num = Counter(s)", "+mx = max(num.values())", "-for i in range(n):", "- S[i] = eval(input())", "-S.sort()", "-if n == 1:", "- print((S[0]))", "- exit()", "-cnt = 1", "-mxcnt = 1", "-for i in range(n - 1):", "- if S[i] == S[i + 1]:", "- cnt += 1", "- else:", "- cnt = 1", "- mxcnt = max(mxcnt, cnt)", "-cnt = 1", "-for i in range(n - 1):", "- if S[i] == S[i + 1]:", "- cnt += 1", "- else:", "- cnt = 1", "- if cnt == mxcnt:", "- T.append(S[i])", "-if mxcnt == 1:", "- T.append(S[-1])", "-for t in T:", "- print(t)", "+for n in sorted(num):", "+ if num[n] == mx:", "+ print(n)" ]
false
0.038582
0.046075
0.83738
[ "s090402964", "s795144850" ]
u254871849
p04013
python
s796553860
s176401400
136
24
5,604
3,572
Accepted
Accepted
82.35
import sys n, a, *x = list(map(int, sys.stdin.read().split())) def main(): for i in range(n): x[i] -= a x.sort() res = [[0] * 99*n for _ in range(n+1)] # res[i][49*n]を中心とする。 res[0][49*n] = 1 for i in range(n): for j in range(99*n): res[i+1][j] += res[i][j] cur = x[i] if cur >= 0: if j >= cur: res[i+1][j] += res[i][j-cur] else: if j - cur <= 99 * n - 1: res[i+1][j] += res[i][j-cur] ans = res[n][49*n] - 1 return ans if __name__ == '__main__': ans = main() print(ans)
import sys from collections import defaultdict n, a, *x = list(map(int, sys.stdin.read().split())) def main(): for i in range(n): x[i] -= a c = defaultdict(int) c[0] = 1 for i in x: for val, cnt in tuple(c.items()): c[val+i] += cnt ans = c[0] - 1 return ans if __name__ == '__main__': ans = main() print(ans)
29
20
679
389
import sys n, a, *x = list(map(int, sys.stdin.read().split())) def main(): for i in range(n): x[i] -= a x.sort() res = [[0] * 99 * n for _ in range(n + 1)] # res[i][49*n]を中心とする。 res[0][49 * n] = 1 for i in range(n): for j in range(99 * n): res[i + 1][j] += res[i][j] cur = x[i] if cur >= 0: if j >= cur: res[i + 1][j] += res[i][j - cur] else: if j - cur <= 99 * n - 1: res[i + 1][j] += res[i][j - cur] ans = res[n][49 * n] - 1 return ans if __name__ == "__main__": ans = main() print(ans)
import sys from collections import defaultdict n, a, *x = list(map(int, sys.stdin.read().split())) def main(): for i in range(n): x[i] -= a c = defaultdict(int) c[0] = 1 for i in x: for val, cnt in tuple(c.items()): c[val + i] += cnt ans = c[0] - 1 return ans if __name__ == "__main__": ans = main() print(ans)
false
31.034483
[ "+from collections import defaultdict", "- x.sort()", "- res = [[0] * 99 * n for _ in range(n + 1)]", "- # res[i][49*n]を中心とする。", "- res[0][49 * n] = 1", "- for i in range(n):", "- for j in range(99 * n):", "- res[i + 1][j] += res[i][j]", "- cur = x[i]", "- if cur >= 0:", "- if j >= cur:", "- res[i + 1][j] += res[i][j - cur]", "- else:", "- if j - cur <= 99 * n - 1:", "- res[i + 1][j] += res[i][j - cur]", "- ans = res[n][49 * n] - 1", "+ c = defaultdict(int)", "+ c[0] = 1", "+ for i in x:", "+ for val, cnt in tuple(c.items()):", "+ c[val + i] += cnt", "+ ans = c[0] - 1" ]
false
0.040183
0.047394
0.847836
[ "s796553860", "s176401400" ]
u753803401
p03601
python
s343677808
s092852630
235
210
41,200
39,828
Accepted
Accepted
10.64
def slove(): import sys input = sys.stdin.readline a, b, c, d, e, f = list(map(int, input().rstrip('\n').split())) abcd = 0 cd = 0 md = 0 for ai in range(0, f + 1, a * 100): for bi in range(0, f + 1, b * 100): for ci in range(0, f + 1, c): for di in range(0, f + 1, d): if 0 < ai + bi + ci + di <= f: if ai + bi != 0: if md < (ci + di) / (ai + bi + ci + di) <= e / (100 + e): md = (ci + di) / (ai + bi + ci + di) abcd = ai + bi + ci + di cd = ci + di else: break print((abcd if abcd != 0 else a * 100, cd)) if __name__ == '__main__': slove()
def slove(): import sys input = sys.stdin.readline a, b, c, d, e, f = list(map(int, input().rstrip('\n').split())) mt = a * 100 ms = 0 mn = 0 for i in range(0, f + 1, a * 100): for j in range(0, f - i + 1, b * 100): for k in range(0, f - i - j + 1, c): for l in range(0, f - i - j - k + 1, d): t = i + j s = k + l if 0 < t + s <= f: if s / (t + s) <= e / (100 + e): if s / (t + s) > mn: mn = s / (t + s) mt = t ms = s print((mt + ms, ms)) if __name__ == '__main__': slove()
24
24
849
777
def slove(): import sys input = sys.stdin.readline a, b, c, d, e, f = list(map(int, input().rstrip("\n").split())) abcd = 0 cd = 0 md = 0 for ai in range(0, f + 1, a * 100): for bi in range(0, f + 1, b * 100): for ci in range(0, f + 1, c): for di in range(0, f + 1, d): if 0 < ai + bi + ci + di <= f: if ai + bi != 0: if md < (ci + di) / (ai + bi + ci + di) <= e / (100 + e): md = (ci + di) / (ai + bi + ci + di) abcd = ai + bi + ci + di cd = ci + di else: break print((abcd if abcd != 0 else a * 100, cd)) if __name__ == "__main__": slove()
def slove(): import sys input = sys.stdin.readline a, b, c, d, e, f = list(map(int, input().rstrip("\n").split())) mt = a * 100 ms = 0 mn = 0 for i in range(0, f + 1, a * 100): for j in range(0, f - i + 1, b * 100): for k in range(0, f - i - j + 1, c): for l in range(0, f - i - j - k + 1, d): t = i + j s = k + l if 0 < t + s <= f: if s / (t + s) <= e / (100 + e): if s / (t + s) > mn: mn = s / (t + s) mt = t ms = s print((mt + ms, ms)) if __name__ == "__main__": slove()
false
0
[ "- abcd = 0", "- cd = 0", "- md = 0", "- for ai in range(0, f + 1, a * 100):", "- for bi in range(0, f + 1, b * 100):", "- for ci in range(0, f + 1, c):", "- for di in range(0, f + 1, d):", "- if 0 < ai + bi + ci + di <= f:", "- if ai + bi != 0:", "- if md < (ci + di) / (ai + bi + ci + di) <= e / (100 + e):", "- md = (ci + di) / (ai + bi + ci + di)", "- abcd = ai + bi + ci + di", "- cd = ci + di", "- else:", "- break", "- print((abcd if abcd != 0 else a * 100, cd))", "+ mt = a * 100", "+ ms = 0", "+ mn = 0", "+ for i in range(0, f + 1, a * 100):", "+ for j in range(0, f - i + 1, b * 100):", "+ for k in range(0, f - i - j + 1, c):", "+ for l in range(0, f - i - j - k + 1, d):", "+ t = i + j", "+ s = k + l", "+ if 0 < t + s <= f:", "+ if s / (t + s) <= e / (100 + e):", "+ if s / (t + s) > mn:", "+ mn = s / (t + s)", "+ mt = t", "+ ms = s", "+ print((mt + ms, ms))" ]
false
0.047213
0.044398
1.06341
[ "s343677808", "s092852630" ]
u577170763
p02821
python
s144493667
s805731507
1,083
326
57,008
21,436
Accepted
Accepted
69.9
import sys from collections import defaultdict import bisect import itertools readline = sys.stdin.buffer.readline # sys.setrecursionlimit(10**5) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): N, M = geta(int) A = list(geta(int)) A.sort() def c(x): """ @return # of handshake where hapiness >= x """ ret = 0 for a in A: ret += bisect.bisect_left(A, x - a) return N * N - ret left, right = 0, 2 * A[-1] + 1 while left + 1 < right: middle = (left + right) // 2 if c(middle) >= M: left = middle else: right = middle ans = 0 Acum = list(itertools.accumulate(A[::-1]))[::-1] for a in A: idx = bisect.bisect_left(A, right - a) if idx < N: ans += Acum[idx] + a * (N - idx) ans += left * (M - c(right)) print(ans) if __name__ == "__main__": main()
import sys from collections import defaultdict readline = sys.stdin.buffer.readline # sys.setrecursionlimit(10**5) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) import numpy as np def main(): N, M = geta(int) A = np.array(list(geta(int))) A.sort() def c(x): """ @return # of handshake where hapiness >= x """ X = np.searchsorted(A, x - A) return N * N - X.sum() left, right = 0, 2 * A[-1] + 1 while left + 1 < right: middle = (left + right) // 2 if c(middle) >= M: left = middle else: right = middle ans = 0 Acum = np.zeros(N + 1, np.int64) Acum[:-1] = np.cumsum(A[::-1])[::-1] X = np.searchsorted(A, right - A) ans = Acum[X].sum() + (A * (N - X)).sum() ans += left * (M - (N * N - X.sum())) print(ans) if __name__ == "__main__": main()
52
52
1,097
1,047
import sys from collections import defaultdict import bisect import itertools readline = sys.stdin.buffer.readline # sys.setrecursionlimit(10**5) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): N, M = geta(int) A = list(geta(int)) A.sort() def c(x): """ @return # of handshake where hapiness >= x """ ret = 0 for a in A: ret += bisect.bisect_left(A, x - a) return N * N - ret left, right = 0, 2 * A[-1] + 1 while left + 1 < right: middle = (left + right) // 2 if c(middle) >= M: left = middle else: right = middle ans = 0 Acum = list(itertools.accumulate(A[::-1]))[::-1] for a in A: idx = bisect.bisect_left(A, right - a) if idx < N: ans += Acum[idx] + a * (N - idx) ans += left * (M - c(right)) print(ans) if __name__ == "__main__": main()
import sys from collections import defaultdict readline = sys.stdin.buffer.readline # sys.setrecursionlimit(10**5) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) import numpy as np def main(): N, M = geta(int) A = np.array(list(geta(int))) A.sort() def c(x): """ @return # of handshake where hapiness >= x """ X = np.searchsorted(A, x - A) return N * N - X.sum() left, right = 0, 2 * A[-1] + 1 while left + 1 < right: middle = (left + right) // 2 if c(middle) >= M: left = middle else: right = middle ans = 0 Acum = np.zeros(N + 1, np.int64) Acum[:-1] = np.cumsum(A[::-1])[::-1] X = np.searchsorted(A, right - A) ans = Acum[X].sum() + (A * (N - X)).sum() ans += left * (M - (N * N - X.sum())) print(ans) if __name__ == "__main__": main()
false
0
[ "-import bisect", "-import itertools", "+import numpy as np", "+", "+", "- A = list(geta(int))", "+ A = np.array(list(geta(int)))", "- ret = 0", "- for a in A:", "- ret += bisect.bisect_left(A, x - a)", "- return N * N - ret", "+ X = np.searchsorted(A, x - A)", "+ return N * N - X.sum()", "- Acum = list(itertools.accumulate(A[::-1]))[::-1]", "- for a in A:", "- idx = bisect.bisect_left(A, right - a)", "- if idx < N:", "- ans += Acum[idx] + a * (N - idx)", "- ans += left * (M - c(right))", "+ Acum = np.zeros(N + 1, np.int64)", "+ Acum[:-1] = np.cumsum(A[::-1])[::-1]", "+ X = np.searchsorted(A, right - A)", "+ ans = Acum[X].sum() + (A * (N - X)).sum()", "+ ans += left * (M - (N * N - X.sum()))" ]
false
0.111578
0.232434
0.480043
[ "s144493667", "s805731507" ]
u729133443
p03579
python
s704009258
s931048125
1,178
1,079
173,872
174,468
Accepted
Accepted
8.4
from networkx import* n,*t=[t.split()for t in open(0)] n,m=list(map(int,n)) g=Graph() g.add_edges_from(t) try:a,b=list(map(len,bipartite.sets(g)));a*=b except:a=n*~-n//2 print((a-m))
from networkx import* n,*t=list(map(str.split,open(0))) n,m=list(map(int,n)) g=Graph() g.add_edges_from(t) try:a,b=list(map(len,bipartite.sets(g)));a*=b except:a=n*~-n//2 print((a-m))
8
8
175
170
from networkx import * n, *t = [t.split() for t in open(0)] n, m = list(map(int, n)) g = Graph() g.add_edges_from(t) try: a, b = list(map(len, bipartite.sets(g))) a *= b except: a = n * ~-n // 2 print((a - m))
from networkx import * n, *t = list(map(str.split, open(0))) n, m = list(map(int, n)) g = Graph() g.add_edges_from(t) try: a, b = list(map(len, bipartite.sets(g))) a *= b except: a = n * ~-n // 2 print((a - m))
false
0
[ "-n, *t = [t.split() for t in open(0)]", "+n, *t = list(map(str.split, open(0)))" ]
false
0.124321
0.133687
0.929944
[ "s704009258", "s931048125" ]
u968404618
p02685
python
s889032459
s880351267
1,292
258
9,236
67,592
Accepted
Accepted
80.03
n, m, k = list(map(int, input().split())) MOD = 998244353 ans, N, K = 0, 1, 1 for i in range(k+1): ans += N * pow(K, MOD-2, MOD) * pow(m-1, n-1-i, MOD) ans %= MOD N *= n-1-i N %= MOD K *= i+1 K %= MOD ans *= m ans %= MOD print(ans)
def main(): ## IMPORT MODULE #import sys #sys.setrecursionlimit(100000) #input=lambda :sys.stdin.readline().rstrip() #f_inf=float("inf") MOD=998244353 if 'get_ipython' in globals(): ## SAMPLE INPUT n, m, k = 60522, 114575, 7559 else: ##INPUT #n = input() n, m, k = list(map(int, input().split())) ## SUBMITION CODES HERE ans, N, K = 0, 1, 1 for i in range(k+1): ans += N * pow(K, MOD-2, MOD) * pow(m-1, n-1-i, MOD) ans %= MOD N *= n-1-i N %= MOD K *= i+1 K %= MOD ans *= m ans %= MOD print(ans) main()
15
35
265
616
n, m, k = list(map(int, input().split())) MOD = 998244353 ans, N, K = 0, 1, 1 for i in range(k + 1): ans += N * pow(K, MOD - 2, MOD) * pow(m - 1, n - 1 - i, MOD) ans %= MOD N *= n - 1 - i N %= MOD K *= i + 1 K %= MOD ans *= m ans %= MOD print(ans)
def main(): ## IMPORT MODULE # import sys # sys.setrecursionlimit(100000) # input=lambda :sys.stdin.readline().rstrip() # f_inf=float("inf") MOD = 998244353 if "get_ipython" in globals(): ## SAMPLE INPUT n, m, k = 60522, 114575, 7559 else: ##INPUT # n = input() n, m, k = list(map(int, input().split())) ## SUBMITION CODES HERE ans, N, K = 0, 1, 1 for i in range(k + 1): ans += N * pow(K, MOD - 2, MOD) * pow(m - 1, n - 1 - i, MOD) ans %= MOD N *= n - 1 - i N %= MOD K *= i + 1 K %= MOD ans *= m ans %= MOD print(ans) main()
false
57.142857
[ "-n, m, k = list(map(int, input().split()))", "-MOD = 998244353", "-ans, N, K = 0, 1, 1", "-for i in range(k + 1):", "- ans += N * pow(K, MOD - 2, MOD) * pow(m - 1, n - 1 - i, MOD)", "+def main():", "+ ## IMPORT MODULE", "+ # import sys", "+ # sys.setrecursionlimit(100000)", "+ # input=lambda :sys.stdin.readline().rstrip()", "+ # f_inf=float(\"inf\")", "+ MOD = 998244353", "+ if \"get_ipython\" in globals():", "+ ## SAMPLE INPUT", "+ n, m, k = 60522, 114575, 7559", "+ else:", "+ ##INPUT", "+ # n = input()", "+ n, m, k = list(map(int, input().split()))", "+ ## SUBMITION CODES HERE", "+ ans, N, K = 0, 1, 1", "+ for i in range(k + 1):", "+ ans += N * pow(K, MOD - 2, MOD) * pow(m - 1, n - 1 - i, MOD)", "+ ans %= MOD", "+ N *= n - 1 - i", "+ N %= MOD", "+ K *= i + 1", "+ K %= MOD", "+ ans *= m", "- N *= n - 1 - i", "- N %= MOD", "- K *= i + 1", "- K %= MOD", "-ans *= m", "-ans %= MOD", "-print(ans)", "+ print(ans)", "+", "+", "+main()" ]
false
0.115335
0.661007
0.174483
[ "s889032459", "s880351267" ]
u703528810
p02695
python
s263661729
s467434107
1,510
999
9,280
12,600
Accepted
Accepted
33.84
def comb(n,r): r=min(r,n-r) c=1 for i in range(r): c=c*(n-i)/(r-i) return int(c) N,M,Q=list(map(int,input().split())) a=[list(map(int,input().split())) for _ in range(Q)] npat=comb(N+M,M) A=[1 for _ in range(N)] ans=0 for i in range(npat): temp=0 for j in range(Q): if A[a[j][1]-1]-A[a[j][0]-1]==a[j][2]: temp+=a[j][3] ans=max(ans,temp) # print(A) # print(temp) A[-1]+=1 if A[-1]>M and i<npat-1: k=1 while max(A)>M and k<N: A[N-k-1]+=1 A[N-k]=A[N-k-1] k+=1 for l in range(1,k): A[N-l]=A[N-k] if min(A)>M: break print(ans)
def dfs(A): if len(A)==N: temp=0 for j in range(Q): if A[a[j][1]-1]-A[a[j][0]-1]==a[j][2]: temp+=a[j][3] ans.append(temp) return else: if len(A)>0: m=A[-1] else: m=1 for i in range(m,M+1): A.append(i) dfs(A) A.pop() N,M,Q=list(map(int,input().split())) a=[list(map(int,input().split())) for _ in range(Q)] ans=[] dfs([]) print((max(ans)))
34
23
713
513
def comb(n, r): r = min(r, n - r) c = 1 for i in range(r): c = c * (n - i) / (r - i) return int(c) N, M, Q = list(map(int, input().split())) a = [list(map(int, input().split())) for _ in range(Q)] npat = comb(N + M, M) A = [1 for _ in range(N)] ans = 0 for i in range(npat): temp = 0 for j in range(Q): if A[a[j][1] - 1] - A[a[j][0] - 1] == a[j][2]: temp += a[j][3] ans = max(ans, temp) # print(A) # print(temp) A[-1] += 1 if A[-1] > M and i < npat - 1: k = 1 while max(A) > M and k < N: A[N - k - 1] += 1 A[N - k] = A[N - k - 1] k += 1 for l in range(1, k): A[N - l] = A[N - k] if min(A) > M: break print(ans)
def dfs(A): if len(A) == N: temp = 0 for j in range(Q): if A[a[j][1] - 1] - A[a[j][0] - 1] == a[j][2]: temp += a[j][3] ans.append(temp) return else: if len(A) > 0: m = A[-1] else: m = 1 for i in range(m, M + 1): A.append(i) dfs(A) A.pop() N, M, Q = list(map(int, input().split())) a = [list(map(int, input().split())) for _ in range(Q)] ans = [] dfs([]) print((max(ans)))
false
32.352941
[ "-def comb(n, r):", "- r = min(r, n - r)", "- c = 1", "- for i in range(r):", "- c = c * (n - i) / (r - i)", "- return int(c)", "+def dfs(A):", "+ if len(A) == N:", "+ temp = 0", "+ for j in range(Q):", "+ if A[a[j][1] - 1] - A[a[j][0] - 1] == a[j][2]:", "+ temp += a[j][3]", "+ ans.append(temp)", "+ return", "+ else:", "+ if len(A) > 0:", "+ m = A[-1]", "+ else:", "+ m = 1", "+ for i in range(m, M + 1):", "+ A.append(i)", "+ dfs(A)", "+ A.pop()", "-npat = comb(N + M, M)", "-A = [1 for _ in range(N)]", "-ans = 0", "-for i in range(npat):", "- temp = 0", "- for j in range(Q):", "- if A[a[j][1] - 1] - A[a[j][0] - 1] == a[j][2]:", "- temp += a[j][3]", "- ans = max(ans, temp)", "- # print(A)", "- # print(temp)", "- A[-1] += 1", "- if A[-1] > M and i < npat - 1:", "- k = 1", "- while max(A) > M and k < N:", "- A[N - k - 1] += 1", "- A[N - k] = A[N - k - 1]", "- k += 1", "- for l in range(1, k):", "- A[N - l] = A[N - k]", "- if min(A) > M:", "- break", "-print(ans)", "+ans = []", "+dfs([])", "+print((max(ans)))" ]
false
0.1205
0.071268
1.690801
[ "s263661729", "s467434107" ]
u947243063
p03161
python
s834034142
s991431268
335
237
85,204
84,876
Accepted
Accepted
29.25
#!/usr/bin/env pypy import sys inp = sys.stdin.readline out = print MAX = 10**9 n, k = map(int, inp().split()) cost = list(map(int, inp().split())) dp = [MAX] * (n) dp[0] = 0 for i in range(1, n): dp[i] = min(dp[j] + abs(cost[i] - cost[j]) for j in range(max(0, i - k), i)) out(dp[-1])
#!/usr/bin/env pypy import sys inp = sys.stdin.readline out = print MAX = 10**9 n, k = map(int, inp().split()) cost = list(map(int, inp().split())) dp = [MAX] * (n) dp[0] = 0 for i in range(1, n): for j in range(max(0, i-k), i+1): dp[i] = min(dp[i] ,dp[j] + abs(cost[i] - cost[j])) print(dp[-1])
16
17
311
339
#!/usr/bin/env pypy import sys inp = sys.stdin.readline out = print MAX = 10**9 n, k = map(int, inp().split()) cost = list(map(int, inp().split())) dp = [MAX] * (n) dp[0] = 0 for i in range(1, n): dp[i] = min(dp[j] + abs(cost[i] - cost[j]) for j in range(max(0, i - k), i)) out(dp[-1])
#!/usr/bin/env pypy import sys inp = sys.stdin.readline out = print MAX = 10**9 n, k = map(int, inp().split()) cost = list(map(int, inp().split())) dp = [MAX] * (n) dp[0] = 0 for i in range(1, n): for j in range(max(0, i - k), i + 1): dp[i] = min(dp[i], dp[j] + abs(cost[i] - cost[j])) print(dp[-1])
false
5.882353
[ "- dp[i] = min(dp[j] + abs(cost[i] - cost[j]) for j in range(max(0, i - k), i))", "-out(dp[-1])", "+ for j in range(max(0, i - k), i + 1):", "+ dp[i] = min(dp[i], dp[j] + abs(cost[i] - cost[j]))", "+print(dp[-1])" ]
false
0.037058
0.035303
1.049718
[ "s834034142", "s991431268" ]
u498487134
p02850
python
s862242593
s436693318
878
533
95,392
116,296
Accepted
Accepted
39.29
N = int(input()) d = {} E = [[] for _ in range(N)] for i in range(N-1): a,b = map(int,input().split()) E[a-1].append(b-1) E[b-1].append(a-1) d[(a-1,b-1)]=i d[(b-1,a-1)]=i K = 0 ans = [None]*(N-1) #queueに(node,par)を入れる. q = [(0,-1)] while q: node,p = q.pop() col = 1 for to in E[node]: if to!=p: q.append((to,node)) if p!=-1: if col==ans[d[(node,p)]]: col+=1 ans[d[(node,to)]]=col K=max(K,col) col+=1 print(K) print(*ans,sep="\n")
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N=I() P=[-1]*N#親から来た辺の色だけ持っておく C=[0]*(N-1) adj=[[]for _ in range(N)] from collections import defaultdict dd = defaultdict(lambda : -1) dd2 = defaultdict(lambda : -1) for i in range(N-1): a,b=MI() a-=1 b-=1 adj[a].append(b) adj[b].append(a) dd[(a,b)] = i dd2[i]=(a,b) import queue q=queue.Queue() q.put((0,-1)) while not q.empty(): v,p=q.get() col=0 for i in range(len(adj[v])): nv=adj[v][i] if nv==p: continue if col==P[v]: col+=1 a=min(v,nv) b=max(v,nv) ii=dd[(a,b)] C[ii]=col P[nv]=col col+=1 q.put((nv,v)) K=0 for i in range(N): K=max(K,len(adj[i])) print(K) for i in range(N-1): print((C[i]+1)) main()
32
69
605
1,320
N = int(input()) d = {} E = [[] for _ in range(N)] for i in range(N - 1): a, b = map(int, input().split()) E[a - 1].append(b - 1) E[b - 1].append(a - 1) d[(a - 1, b - 1)] = i d[(b - 1, a - 1)] = i K = 0 ans = [None] * (N - 1) # queueに(node,par)を入れる. q = [(0, -1)] while q: node, p = q.pop() col = 1 for to in E[node]: if to != p: q.append((to, node)) if p != -1: if col == ans[d[(node, p)]]: col += 1 ans[d[(node, to)]] = col K = max(K, col) col += 1 print(K) print(*ans, sep="\n")
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod = 10**9 + 7 N = I() P = [-1] * N # 親から来た辺の色だけ持っておく C = [0] * (N - 1) adj = [[] for _ in range(N)] from collections import defaultdict dd = defaultdict(lambda: -1) dd2 = defaultdict(lambda: -1) for i in range(N - 1): a, b = MI() a -= 1 b -= 1 adj[a].append(b) adj[b].append(a) dd[(a, b)] = i dd2[i] = (a, b) import queue q = queue.Queue() q.put((0, -1)) while not q.empty(): v, p = q.get() col = 0 for i in range(len(adj[v])): nv = adj[v][i] if nv == p: continue if col == P[v]: col += 1 a = min(v, nv) b = max(v, nv) ii = dd[(a, b)] C[ii] = col P[nv] = col col += 1 q.put((nv, v)) K = 0 for i in range(N): K = max(K, len(adj[i])) print(K) for i in range(N - 1): print((C[i] + 1)) main()
false
53.623188
[ "-N = int(input())", "-d = {}", "-E = [[] for _ in range(N)]", "-for i in range(N - 1):", "- a, b = map(int, input().split())", "- E[a - 1].append(b - 1)", "- E[b - 1].append(a - 1)", "- d[(a - 1, b - 1)] = i", "- d[(b - 1, a - 1)] = i", "-K = 0", "-ans = [None] * (N - 1)", "-# queueに(node,par)を入れる.", "-q = [(0, -1)]", "-while q:", "- node, p = q.pop()", "- col = 1", "- for to in E[node]:", "- if to != p:", "- q.append((to, node))", "- if p != -1:", "- if col == ans[d[(node, p)]]:", "- col += 1", "- ans[d[(node, to)]] = col", "- K = max(K, col)", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def I():", "+ return int(eval(input()))", "+", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+def main():", "+ mod = 10**9 + 7", "+ N = I()", "+ P = [-1] * N # 親から来た辺の色だけ持っておく", "+ C = [0] * (N - 1)", "+ adj = [[] for _ in range(N)]", "+ from collections import defaultdict", "+", "+ dd = defaultdict(lambda: -1)", "+ dd2 = defaultdict(lambda: -1)", "+ for i in range(N - 1):", "+ a, b = MI()", "+ a -= 1", "+ b -= 1", "+ adj[a].append(b)", "+ adj[b].append(a)", "+ dd[(a, b)] = i", "+ dd2[i] = (a, b)", "+ import queue", "+", "+ q = queue.Queue()", "+ q.put((0, -1))", "+ while not q.empty():", "+ v, p = q.get()", "+ col = 0", "+ for i in range(len(adj[v])):", "+ nv = adj[v][i]", "+ if nv == p:", "+ continue", "+ if col == P[v]:", "+ col += 1", "+ a = min(v, nv)", "+ b = max(v, nv)", "+ ii = dd[(a, b)]", "+ C[ii] = col", "+ P[nv] = col", "-print(K)", "-print(*ans, sep=\"\\n\")", "+ q.put((nv, v))", "+ K = 0", "+ for i in range(N):", "+ K = max(K, len(adj[i]))", "+ print(K)", "+ for i in range(N - 1):", "+ print((C[i] + 1))", "+", "+", "+main()" ]
false
0.0548
0.077344
0.708528
[ "s862242593", "s436693318" ]
u912237403
p00096
python
s871361941
s859329011
170
30
4,316
4,308
Accepted
Accepted
82.35
import sys n=1001 a=[0]*2001 for i in range(n): for j in range(n): a[i+j]+=1 for n in map(int,sys.stdin): x=0 for i in range(max(0,n-2000),min(n,2000)+1): x+=a[i]*a[n-i] print(x)
import sys n=1001 a=list(range(1,n)) a+=[n]+a[::-1] for n in map(int,sys.stdin): x=0 for i in range(max(0,n-2000),min(n,2000)+1): x+=a[i]*a[n-i] print(x)
12
9
205
164
import sys n = 1001 a = [0] * 2001 for i in range(n): for j in range(n): a[i + j] += 1 for n in map(int, sys.stdin): x = 0 for i in range(max(0, n - 2000), min(n, 2000) + 1): x += a[i] * a[n - i] print(x)
import sys n = 1001 a = list(range(1, n)) a += [n] + a[::-1] for n in map(int, sys.stdin): x = 0 for i in range(max(0, n - 2000), min(n, 2000) + 1): x += a[i] * a[n - i] print(x)
false
25
[ "-a = [0] * 2001", "-for i in range(n):", "- for j in range(n):", "- a[i + j] += 1", "+a = list(range(1, n))", "+a += [n] + a[::-1]" ]
false
0.326481
0.118635
2.751974
[ "s871361941", "s859329011" ]
u429319815
p03814
python
s466382816
s402505905
59
18
4,840
3,512
Accepted
Accepted
69.49
S = list(eval(input())) count = 0 for i in range(len(S)): if (S[i] == "A") and (count == 0): start = i count = 1 if S[i] == "Z": end = i print((end - start + 1))
s = eval(input()) start = s.find("A") end = s.rfind("Z") print((end - start + 1))
9
4
194
76
S = list(eval(input())) count = 0 for i in range(len(S)): if (S[i] == "A") and (count == 0): start = i count = 1 if S[i] == "Z": end = i print((end - start + 1))
s = eval(input()) start = s.find("A") end = s.rfind("Z") print((end - start + 1))
false
55.555556
[ "-S = list(eval(input()))", "-count = 0", "-for i in range(len(S)):", "- if (S[i] == \"A\") and (count == 0):", "- start = i", "- count = 1", "- if S[i] == \"Z\":", "- end = i", "+s = eval(input())", "+start = s.find(\"A\")", "+end = s.rfind(\"Z\")" ]
false
0.046528
0.088645
0.524879
[ "s466382816", "s402505905" ]
u645250356
p02689
python
s966114684
s265025597
500
233
100,496
100,528
Accepted
Accepted
53.4
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify 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() g = [[] for _ in range(n)] for i in range(m): z,x = inpl() g[z-1].append(x-1) g[x-1].append(z-1) res = 0 # print(g) for i in range(n): ok = True for v in g[i]: if a[v] >= a[i]: ok = False if ok: # print(i) res += 1 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() h = inpl() g = [[] for _ in range(n)] for _ in range(m): a,b = inpl() a,b = a-1,b-1 g[a].append(b) g[b].append(a) res = 0 for i in range(n): for j in g[i]: if h[j] >= h[i]: break else: res += 1 print(res)
28
26
688
638
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify 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() g = [[] for _ in range(n)] for i in range(m): z, x = inpl() g[z - 1].append(x - 1) g[x - 1].append(z - 1) res = 0 # print(g) for i in range(n): ok = True for v in g[i]: if a[v] >= a[i]: ok = False if ok: # print(i) res += 1 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() h = inpl() g = [[] for _ in range(n)] for _ in range(m): a, b = inpl() a, b = a - 1, b - 1 g[a].append(b) g[b].append(a) res = 0 for i in range(n): for j in g[i]: if h[j] >= h[i]: break else: res += 1 print(res)
false
7.142857
[ "-from heapq import heappop, heappush, heapify", "+from heapq import heappop, heappush", "-a = inpl()", "+h = inpl()", "-for i in range(m):", "- z, x = inpl()", "- g[z - 1].append(x - 1)", "- g[x - 1].append(z - 1)", "+for _ in range(m):", "+ a, b = inpl()", "+ a, b = a - 1, b - 1", "+ g[a].append(b)", "+ g[b].append(a)", "-# print(g)", "- ok = True", "- for v in g[i]:", "- if a[v] >= a[i]:", "- ok = False", "- if ok:", "- # print(i)", "+ for j in g[i]:", "+ if h[j] >= h[i]:", "+ break", "+ else:" ]
false
0.035796
0.037717
0.949059
[ "s966114684", "s265025597" ]
u790710233
p03074
python
s579248851
s812972651
81
68
3,316
8,660
Accepted
Accepted
16.05
n, k = list(map(int, input().split())) s = eval(input()) prev_R = '1' for R in range(n): if (prev_R, s[R]) == ('1', '0'): k -= 1 if k < 0: R -= 1 break prev_R = s[R] ans = R+1 for L in range(n-1): if (s[L], s[L+1]) != ('0', '1'): continue R += 1 while R < n-1 and (s[R], s[R+1]) != ('1', '0'): R += 1 if ans < R-L: ans = R-L print(ans)
n, k = list(map(int, input().split())) s = list(eval(input())) L = [0] R = [] for i, (a, b) in enumerate(zip(s, s[1:])): if (a, b) == ('0', '1'): L.append(i+1) if (a, b) == ('1', '0'): R.append(i) else: R.append(n-1) ans = R[0]-L[0]+1 if s[0] == '0': k -= 1 k = min(k, len(R)-1) for l, r in zip(L, R[k:]): x = r-l+1 if ans < x: ans = x print(ans)
22
24
434
410
n, k = list(map(int, input().split())) s = eval(input()) prev_R = "1" for R in range(n): if (prev_R, s[R]) == ("1", "0"): k -= 1 if k < 0: R -= 1 break prev_R = s[R] ans = R + 1 for L in range(n - 1): if (s[L], s[L + 1]) != ("0", "1"): continue R += 1 while R < n - 1 and (s[R], s[R + 1]) != ("1", "0"): R += 1 if ans < R - L: ans = R - L print(ans)
n, k = list(map(int, input().split())) s = list(eval(input())) L = [0] R = [] for i, (a, b) in enumerate(zip(s, s[1:])): if (a, b) == ("0", "1"): L.append(i + 1) if (a, b) == ("1", "0"): R.append(i) else: R.append(n - 1) ans = R[0] - L[0] + 1 if s[0] == "0": k -= 1 k = min(k, len(R) - 1) for l, r in zip(L, R[k:]): x = r - l + 1 if ans < x: ans = x print(ans)
false
8.333333
[ "-s = eval(input())", "-prev_R = \"1\"", "-for R in range(n):", "- if (prev_R, s[R]) == (\"1\", \"0\"):", "- k -= 1", "- if k < 0:", "- R -= 1", "- break", "- prev_R = s[R]", "-ans = R + 1", "-for L in range(n - 1):", "- if (s[L], s[L + 1]) != (\"0\", \"1\"):", "- continue", "- R += 1", "- while R < n - 1 and (s[R], s[R + 1]) != (\"1\", \"0\"):", "- R += 1", "- if ans < R - L:", "- ans = R - L", "+s = list(eval(input()))", "+L = [0]", "+R = []", "+for i, (a, b) in enumerate(zip(s, s[1:])):", "+ if (a, b) == (\"0\", \"1\"):", "+ L.append(i + 1)", "+ if (a, b) == (\"1\", \"0\"):", "+ R.append(i)", "+else:", "+ R.append(n - 1)", "+ans = R[0] - L[0] + 1", "+if s[0] == \"0\":", "+ k -= 1", "+k = min(k, len(R) - 1)", "+for l, r in zip(L, R[k:]):", "+ x = r - l + 1", "+ if ans < x:", "+ ans = x" ]
false
0.035558
0.035279
1.007901
[ "s579248851", "s812972651" ]
u631543593
p02647
python
s695238474
s271948350
678
584
172,072
171,764
Accepted
Accepted
13.86
import sys from itertools import accumulate N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] current_arr = A if K > 41: print((*([N]*N))) else: for _ in range(K): imos = [0] * N ruiseki = [0] * (N+1) for i, ai in enumerate(current_arr): imos[max([0, i-ai])] += 1 if i+ai+1 < N: imos[i+ai+1] -= 1 for j, im in enumerate(imos): ruiseki[j+1] = ruiseki[j] + im current_arr = ruiseki[1:] #print(imos) #print(ruiseki) #print(*accumulate(imos)) print((*current_arr))
from itertools import accumulate N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] current_arr = A if K > 41: print((*([N]*N))) exit() for _ in range(K): imos = [0] * N ruiseki = [0] * (N+1) for i, ai in enumerate(current_arr): imos[max([0, i-ai])] += 1 if i+ai+1 < N: imos[i+ai+1] -= 1 for j, im in enumerate(imos): ruiseki[j+1] = ruiseki[j] + im current_arr = ruiseki[1:] #print(imos) #print(ruiseki) #print(*accumulate(imos)) print((*current_arr))
24
23
615
564
import sys from itertools import accumulate N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] current_arr = A if K > 41: print((*([N] * N))) else: for _ in range(K): imos = [0] * N ruiseki = [0] * (N + 1) for i, ai in enumerate(current_arr): imos[max([0, i - ai])] += 1 if i + ai + 1 < N: imos[i + ai + 1] -= 1 for j, im in enumerate(imos): ruiseki[j + 1] = ruiseki[j] + im current_arr = ruiseki[1:] # print(imos) # print(ruiseki) # print(*accumulate(imos)) print((*current_arr))
from itertools import accumulate N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] current_arr = A if K > 41: print((*([N] * N))) exit() for _ in range(K): imos = [0] * N ruiseki = [0] * (N + 1) for i, ai in enumerate(current_arr): imos[max([0, i - ai])] += 1 if i + ai + 1 < N: imos[i + ai + 1] -= 1 for j, im in enumerate(imos): ruiseki[j + 1] = ruiseki[j] + im current_arr = ruiseki[1:] # print(imos) # print(ruiseki) # print(*accumulate(imos)) print((*current_arr))
false
4.166667
[ "-import sys", "-else:", "- for _ in range(K):", "- imos = [0] * N", "- ruiseki = [0] * (N + 1)", "- for i, ai in enumerate(current_arr):", "- imos[max([0, i - ai])] += 1", "- if i + ai + 1 < N:", "- imos[i + ai + 1] -= 1", "- for j, im in enumerate(imos):", "- ruiseki[j + 1] = ruiseki[j] + im", "- current_arr = ruiseki[1:]", "- # print(imos)", "- # print(ruiseki)", "- # print(*accumulate(imos))", "- print((*current_arr))", "+ exit()", "+for _ in range(K):", "+ imos = [0] * N", "+ ruiseki = [0] * (N + 1)", "+ for i, ai in enumerate(current_arr):", "+ imos[max([0, i - ai])] += 1", "+ if i + ai + 1 < N:", "+ imos[i + ai + 1] -= 1", "+ for j, im in enumerate(imos):", "+ ruiseki[j + 1] = ruiseki[j] + im", "+ current_arr = ruiseki[1:]", "+# print(imos)", "+# print(ruiseki)", "+# print(*accumulate(imos))", "+print((*current_arr))" ]
false
0.041177
0.038347
1.073796
[ "s695238474", "s271948350" ]
u573754721
p02813
python
s273149727
s737148234
228
194
46,572
46,572
Accepted
Accepted
14.91
from itertools import permutations n=int(eval(input())) P=list(map(str,input().split())) Q=list(map(str,input().split())) S=sorted(P) S=list(permutations(S)) A=[] for i in S: A.append(int("".join(i))) A.sort() for i in range(len(A)): if A[i]==int("".join(P)): pp=i if A[i]==int("".join(Q)): qq=i print((abs(pp-qq)))
from itertools import permutations n=int(eval(input())) P=list(input().split()) Q=list(input().split()) A=[] for i in list(permutations(P)): A.append(int("".join(i))) A.sort() print((abs(A.index(int("".join(P)))-A.index(int("".join(Q))))))
21
9
360
242
from itertools import permutations n = int(eval(input())) P = list(map(str, input().split())) Q = list(map(str, input().split())) S = sorted(P) S = list(permutations(S)) A = [] for i in S: A.append(int("".join(i))) A.sort() for i in range(len(A)): if A[i] == int("".join(P)): pp = i if A[i] == int("".join(Q)): qq = i print((abs(pp - qq)))
from itertools import permutations n = int(eval(input())) P = list(input().split()) Q = list(input().split()) A = [] for i in list(permutations(P)): A.append(int("".join(i))) A.sort() print((abs(A.index(int("".join(P))) - A.index(int("".join(Q))))))
false
57.142857
[ "-P = list(map(str, input().split()))", "-Q = list(map(str, input().split()))", "-S = sorted(P)", "-S = list(permutations(S))", "+P = list(input().split())", "+Q = list(input().split())", "-for i in S:", "+for i in list(permutations(P)):", "-for i in range(len(A)):", "- if A[i] == int(\"\".join(P)):", "- pp = i", "- if A[i] == int(\"\".join(Q)):", "- qq = i", "-print((abs(pp - qq)))", "+print((abs(A.index(int(\"\".join(P))) - A.index(int(\"\".join(Q))))))" ]
false
0.046348
0.052543
0.882094
[ "s273149727", "s737148234" ]
u532966492
p02724
python
s083105208
s388625258
46
19
3,060
2,940
Accepted
Accepted
58.7
def main(): n = int(eval(input())) ans = 1000*(n//500) n %= 500 ans += 5*(n//5) print(ans) main()
def main(): x = int(eval(input())) cnt = 0 cnt += 1000*(x//500) x %= 500 cnt += 5*(x//5) print(cnt) main()
9
10
122
136
def main(): n = int(eval(input())) ans = 1000 * (n // 500) n %= 500 ans += 5 * (n // 5) print(ans) main()
def main(): x = int(eval(input())) cnt = 0 cnt += 1000 * (x // 500) x %= 500 cnt += 5 * (x // 5) print(cnt) main()
false
10
[ "- n = int(eval(input()))", "- ans = 1000 * (n // 500)", "- n %= 500", "- ans += 5 * (n // 5)", "- print(ans)", "+ x = int(eval(input()))", "+ cnt = 0", "+ cnt += 1000 * (x // 500)", "+ x %= 500", "+ cnt += 5 * (x // 5)", "+ print(cnt)" ]
false
0.088002
0.044981
1.956427
[ "s083105208", "s388625258" ]
u413165887
p02762
python
s977565675
s414391946
1,247
1,053
60,676
60,504
Accepted
Accepted
15.56
class UnionFind(): # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1]*(n+1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0]*(n+1) # ノードxのrootノードを見つける def Find_Root(self, x): if(self.root[x] < 0): return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if(x == y): return # 違う木に属していた場合rnkを見てくっつける方を決める elif(self.rnk[x] > self.rnk[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if(self.rnk[x] == self.rnk[y]): self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] n, m, k = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] cd = [list(map(int, input().split())) for _ in range(k)] con = [1 for _ in range(n+1)] uni = UnionFind(n+1) for i in range(m): a, b = ab[i] con[a] += 1 con[b] += 1 uni.Unite(a, b) for i in range(k): c, d = cd[i] if uni.isSameGroup(c,d): con[c] += 1 con[d] += 1 result = [] for i in range(1, n+1): result.append(uni.Count(i)-con[i]) print((*result))
n, m, k = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] cd = [list(map(int, input().split())) for _ in range(k)] con = [1 for _ in range(n+1)] uni = [-1 for i in range(n+1)] rank = [0 for _ in range(n+1)] def root(num, pea): if pea[num] < 0: return num else: pea[num] = root(pea[num], pea) return pea[num] for i in range(m): a, b = ab[i] con[a] += 1 con[b] += 1 root_a = root(a, uni) root_b = root(b, uni) if root_a!=root_b: if rank[root_a] < rank[root_b]: uni[root_b] += uni[root_a] uni[root_a] = root_b else: uni[root_a] += uni[root_b] uni[root_b] = root_a if rank[root_a] == rank[root_b]: rank[root_a] += 1 for i in range(k): c, d = cd[i] if root(c, uni) == root(d, uni): con[c] += 1 con[d] += 1 result = [] for i in range(1, n+1): root_i = root(i, uni) result.append(-uni[root_i]-con[i]) print((*result))
70
43
1,835
1,072
class UnionFind: # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1] * (n + 1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0] * (n + 1) # ノードxのrootノードを見つける def Find_Root(self, x): if self.root[x] < 0: return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if x == y: return # 違う木に属していた場合rnkを見てくっつける方を決める elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] n, m, k = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] cd = [list(map(int, input().split())) for _ in range(k)] con = [1 for _ in range(n + 1)] uni = UnionFind(n + 1) for i in range(m): a, b = ab[i] con[a] += 1 con[b] += 1 uni.Unite(a, b) for i in range(k): c, d = cd[i] if uni.isSameGroup(c, d): con[c] += 1 con[d] += 1 result = [] for i in range(1, n + 1): result.append(uni.Count(i) - con[i]) print((*result))
n, m, k = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] cd = [list(map(int, input().split())) for _ in range(k)] con = [1 for _ in range(n + 1)] uni = [-1 for i in range(n + 1)] rank = [0 for _ in range(n + 1)] def root(num, pea): if pea[num] < 0: return num else: pea[num] = root(pea[num], pea) return pea[num] for i in range(m): a, b = ab[i] con[a] += 1 con[b] += 1 root_a = root(a, uni) root_b = root(b, uni) if root_a != root_b: if rank[root_a] < rank[root_b]: uni[root_b] += uni[root_a] uni[root_a] = root_b else: uni[root_a] += uni[root_b] uni[root_b] = root_a if rank[root_a] == rank[root_b]: rank[root_a] += 1 for i in range(k): c, d = cd[i] if root(c, uni) == root(d, uni): con[c] += 1 con[d] += 1 result = [] for i in range(1, n + 1): root_i = root(i, uni) result.append(-uni[root_i] - con[i]) print((*result))
false
38.571429
[ "-class UnionFind:", "- # 作りたい要素数nで初期化", "- # 使用するインスタンス変数の初期化", "- def __init__(self, n):", "- self.n = n", "- # root[x]<0ならそのノードが根かつその値が木の要素数", "- # rootノードでその木の要素数を記録する", "- self.root = [-1] * (n + 1)", "- # 木をくっつける時にアンバランスにならないように調整する", "- self.rnk = [0] * (n + 1)", "-", "- # ノードxのrootノードを見つける", "- def Find_Root(self, x):", "- if self.root[x] < 0:", "- return x", "- else:", "- # ここで代入しておくことで、後の繰り返しを避ける", "- self.root[x] = self.Find_Root(self.root[x])", "- return self.root[x]", "-", "- # 木の併合、入力は併合したい各ノード", "- def Unite(self, x, y):", "- # 入力ノードのrootノードを見つける", "- x = self.Find_Root(x)", "- y = self.Find_Root(y)", "- # すでに同じ木に属していた場合", "- if x == y:", "- return", "- # 違う木に属していた場合rnkを見てくっつける方を決める", "- elif self.rnk[x] > self.rnk[y]:", "- self.root[x] += self.root[y]", "- self.root[y] = x", "- else:", "- self.root[y] += self.root[x]", "- self.root[x] = y", "- # rnkが同じ(深さに差がない場合)は1増やす", "- if self.rnk[x] == self.rnk[y]:", "- self.rnk[y] += 1", "-", "- # xとyが同じグループに属するか判断", "- def isSameGroup(self, x, y):", "- return self.Find_Root(x) == self.Find_Root(y)", "-", "- # ノードxが属する木のサイズを返す", "- def Count(self, x):", "- return -self.root[self.Find_Root(x)]", "-", "-", "-uni = UnionFind(n + 1)", "+uni = [-1 for i in range(n + 1)]", "+rank = [0 for _ in range(n + 1)]", "+", "+", "+def root(num, pea):", "+ if pea[num] < 0:", "+ return num", "+ else:", "+ pea[num] = root(pea[num], pea)", "+ return pea[num]", "+", "+", "- uni.Unite(a, b)", "+ root_a = root(a, uni)", "+ root_b = root(b, uni)", "+ if root_a != root_b:", "+ if rank[root_a] < rank[root_b]:", "+ uni[root_b] += uni[root_a]", "+ uni[root_a] = root_b", "+ else:", "+ uni[root_a] += uni[root_b]", "+ uni[root_b] = root_a", "+ if rank[root_a] == rank[root_b]:", "+ rank[root_a] += 1", "- if uni.isSameGroup(c, d):", "+ if root(c, uni) == root(d, uni):", "- result.append(uni.Count(i) - con[i])", "+ root_i = root(i, uni)", "+ result.append(-uni[root_i] - con[i])" ]
false
0.04784
0.043018
1.11209
[ "s977565675", "s414391946" ]
u002459665
p02755
python
s188422925
s366012298
76
23
3,064
2,940
Accepted
Accepted
69.74
A, B = list(map(int, input().split())) ans = None for i in range(100000): a = int(i * 0.08) b = int(i * 0.1) if a == A and b == B: ans = i break if ans is None: print((-1)) else: print(ans)
A, B = list(map(int, input().split())) ans = -1 for yen in range(10000): a = int(yen * (8/100)) b = int(yen * (10/100)) if A == a and B == b: ans = yen break print(ans)
15
11
241
208
A, B = list(map(int, input().split())) ans = None for i in range(100000): a = int(i * 0.08) b = int(i * 0.1) if a == A and b == B: ans = i break if ans is None: print((-1)) else: print(ans)
A, B = list(map(int, input().split())) ans = -1 for yen in range(10000): a = int(yen * (8 / 100)) b = int(yen * (10 / 100)) if A == a and B == b: ans = yen break print(ans)
false
26.666667
[ "-ans = None", "-for i in range(100000):", "- a = int(i * 0.08)", "- b = int(i * 0.1)", "- if a == A and b == B:", "- ans = i", "+ans = -1", "+for yen in range(10000):", "+ a = int(yen * (8 / 100))", "+ b = int(yen * (10 / 100))", "+ if A == a and B == b:", "+ ans = yen", "-if ans is None:", "- print((-1))", "-else:", "- print(ans)", "+print(ans)" ]
false
0.199527
0.129034
1.54632
[ "s188422925", "s366012298" ]
u006657459
p03837
python
s481570795
s383648320
515
473
14,928
21,212
Accepted
Accepted
8.16
import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix N, M = list(map(int, input().split())) a, b, c = [], [], [] for i in range(M): ai, bi, ci = list(map(int, input().split())) a.append(ai-1) b.append(bi-1) c.append(ci) G = csr_matrix((c, (a, b)), shape=(N, N), dtype=int) D, P = floyd_warshall(G, directed=False, return_predecessors=True) edges = [] for i in range(N): for j in range(N): if P[j][i] < 0 or i == P[j][i]: continue edges.append((min(i, P[j][i]), max(i, P[j][i]))) edges = list(set(edges)) print((M - len(edges)))
from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix fn = lambda: [int(x) for x in input().split()] N, M = fn() data, row_idx, col_idx = [0]*M, [0]*M, [0]*M for i in range(M): ai, bi, ci = fn() row_idx[i] = ai - 1 col_idx[i] = bi - 1 data[i] = ci G = csr_matrix((data, (row_idx, col_idx)), shape=(N, N), dtype=int) D, P = floyd_warshall(G, directed=False, return_predecessors=True) edges = [] for i in range(N): for j in range(N): Pji = P[j][i] if Pji < 0 or i == Pji: continue edges.append((min(i, Pji), max(i, Pji))) edges = set(edges) print((M - len(edges)))
21
22
633
668
import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix N, M = list(map(int, input().split())) a, b, c = [], [], [] for i in range(M): ai, bi, ci = list(map(int, input().split())) a.append(ai - 1) b.append(bi - 1) c.append(ci) G = csr_matrix((c, (a, b)), shape=(N, N), dtype=int) D, P = floyd_warshall(G, directed=False, return_predecessors=True) edges = [] for i in range(N): for j in range(N): if P[j][i] < 0 or i == P[j][i]: continue edges.append((min(i, P[j][i]), max(i, P[j][i]))) edges = list(set(edges)) print((M - len(edges)))
from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix fn = lambda: [int(x) for x in input().split()] N, M = fn() data, row_idx, col_idx = [0] * M, [0] * M, [0] * M for i in range(M): ai, bi, ci = fn() row_idx[i] = ai - 1 col_idx[i] = bi - 1 data[i] = ci G = csr_matrix((data, (row_idx, col_idx)), shape=(N, N), dtype=int) D, P = floyd_warshall(G, directed=False, return_predecessors=True) edges = [] for i in range(N): for j in range(N): Pji = P[j][i] if Pji < 0 or i == Pji: continue edges.append((min(i, Pji), max(i, Pji))) edges = set(edges) print((M - len(edges)))
false
4.545455
[ "-import numpy as np", "-N, M = list(map(int, input().split()))", "-a, b, c = [], [], []", "+fn = lambda: [int(x) for x in input().split()]", "+N, M = fn()", "+data, row_idx, col_idx = [0] * M, [0] * M, [0] * M", "- ai, bi, ci = list(map(int, input().split()))", "- a.append(ai - 1)", "- b.append(bi - 1)", "- c.append(ci)", "-G = csr_matrix((c, (a, b)), shape=(N, N), dtype=int)", "+ ai, bi, ci = fn()", "+ row_idx[i] = ai - 1", "+ col_idx[i] = bi - 1", "+ data[i] = ci", "+G = csr_matrix((data, (row_idx, col_idx)), shape=(N, N), dtype=int)", "- if P[j][i] < 0 or i == P[j][i]:", "+ Pji = P[j][i]", "+ if Pji < 0 or i == Pji:", "- edges.append((min(i, P[j][i]), max(i, P[j][i])))", "-edges = list(set(edges))", "+ edges.append((min(i, Pji), max(i, Pji)))", "+edges = set(edges)" ]
false
0.400626
0.289252
1.385042
[ "s481570795", "s383648320" ]
u648868410
p03176
python
s925621081
s776095179
291
215
146,320
115,164
Accepted
Accepted
26.12
# EDPC Q - Flowers # 重み付きのLISと言って良いような問題 # これは、LISのdpを少し改造すれば解ける # import numpy as np ## test data # 4 # 3 1 4 2 # 10 20 30 40 ## ans=60 # import bisect class SegTree: def __init__(self,size,func,init_val,undef): self.specSize = size self.datSize = 1 self.compareFunc = func # suppose to min or max self.INIT_VAL = init_val # 0 etc self.UNDEFINED_VAL = undef # 1e18 -1e18 etc while self.datSize < size: self.datSize *= 2 # the tree is implemented by sequencial list self.datTree = [self.INIT_VAL for _ in range(2*self.datSize+1)] # self.datTree = np.full(2*self.datSize+1,self.INIT_VAL,int) def update(self, i, val ): i -= 1 # 1-orderで指定され、内部では0-Order想定? i += (self.datSize - 1) # print("upd",i,val) self.datTree[i] = val while 0 < i: i = (i-1) >> 1 # (i-1)//2 self.datTree[i] = self.compareFunc( self.datTree[i*2+1], self.datTree[i*2+2] ) # print("upd",i,self.datTree[i]) def query(self,a,b): return self.query_2(a,b,0,0,self.datSize) def query_(self,a,b,i,l,r): """ get minimun/maximum value of range[a,b) all 1-indexed i is the root vertex of search l,r is range of the root vertex """ if r <= a or b <= l: # (a,b) and (l,r) is not intersected return self.UNDEFINED_VAL if a <= l and r <= b: # i is index required return self.datTree[i] else: # search children m = (l+r) >> 1 #(l+r) // 2 # vl = self.query_(a, b, i*2 + 1, l, m ) # vr = self.query_(a, b, i*2 + 2, m, r ) vl = self.query_(a, b, (i << 1) + 1, l, m ) vr = self.query_(a, b, (i << 1) + 2, m, r ) return self.compareFunc(vl,vr) def query_2(self,a,b,i,l,r): """ get minimun/maximum value of range[a,b) all 1-indexed i is the root vertex of search l,r is range of the root vertex """ ret = self.UNDEFINED_VAL a += self.datSize b += self.datSize while a < b: if b & 1: b -= 1 ret = self.compareFunc(ret, self.datTree[b-1]) if a & 1: ret = self.compareFunc(ret, self.datTree[a-1]) a += 1 a >>= 1; b >>= 1 return ret # if r <= a or b <= l: # # (a,b) and (l,r) is not intersected # return self.UNDEFINED_VAL # if a <= l and r <= b: # # i is index required # return self.datTree[i] # else: # # search children # m = (l+r) >> 1 #(l+r) // 2 # # vl = self.query_(a, b, i*2 + 1, l, m ) # # vr = self.query_(a, b, i*2 + 2, m, r ) # vl = self.query_(a, b, (i << 1) + 1, l, m ) # vr = self.query_(a, b, (i << 1) + 2, m, r ) # return self.compareFunc(vl,vr) def LongestIncreaseSeaquence(H,A): # === Coordinate compression === # unique and sort asc N = len(H) # sortedA = sorted(list(set(A))) lis = 0 # === Range Maximum Query === # ここでは、各要素iに、最後の値がiの時のLISを登録 tree = SegTree(N,max,0,-1e18) for n in range(N): # i=bisect.bisect_left(sortedA,A[n]) maxValOfCurrentRange = tree.query(0,H[n]) # valOfNext = tree.query(H[n],H[n]+1) # # i+=1 # if valOfNext < maxValOfCurrentRange + A[n]: # print( H[n], maxValOfCurrentRange + A[n] ) # tree.debugPrint() tree.update( H[n], maxValOfCurrentRange + A[n] ) lis = tree.query(0,N+1) return lis def main(): N = int(eval(input())) # 高さは、N以下で全部違うらしい H = list(map(int, input().split())) A = list(map(int, input().split())) # A = [ int(input()) for _ in range(N)] print((LongestIncreaseSeaquence(H,A))) if __name__ == "__main__": main()
# EDPC Q - Flowers # 重み付きのLISと言って良いような問題 # これは、LISのdpを少し改造すれば解ける # import numpy as np ## test data # 4 # 3 1 4 2 # 10 20 30 40 ## ans=60 # import bisect class BIT: def __init__(self,size): self.N = size self.bit = [0] * (self.N+1) def getSum(self,i): s = 0 while 0 < i: s += self.bit[i] i -= i & -i return s def getMax(self,i): s = 0 while 0 < i: s = max(s, self.bit[i]) i -= i & -i return s def add(self,i,val): while i <= self.N: # for range summary query # self.bit[i] += val # for range maximum query self.bit[i] = max( self.bit[i], val ) i += i & -i def LongestIncreaseSeaquence(H,A): # === Coordinate compression === # unique and sort asc N = len(H) # sortedA = sorted(list(set(A))) lis = 0 # === Range Maximum Query === # ここでは、各要素iに、最後の値がiの時のLISを登録 tree = BIT(N) for n in range(N): tree.add( H[n], tree.getMax(H[n]) + A[n] ) lis = tree.getMax(N) return lis def main(): N = int(eval(input())) # 高さは、N以下で全部違うらしい H = list(map(int, input().split())) A = list(map(int, input().split())) # A = [ int(input()) for _ in range(N)] print((LongestIncreaseSeaquence(H,A))) if __name__ == "__main__": main()
142
76
3,492
1,259
# EDPC Q - Flowers # 重み付きのLISと言って良いような問題 # これは、LISのdpを少し改造すれば解ける # import numpy as np ## test data # 4 # 3 1 4 2 # 10 20 30 40 ## ans=60 # import bisect class SegTree: def __init__(self, size, func, init_val, undef): self.specSize = size self.datSize = 1 self.compareFunc = func # suppose to min or max self.INIT_VAL = init_val # 0 etc self.UNDEFINED_VAL = undef # 1e18 -1e18 etc while self.datSize < size: self.datSize *= 2 # the tree is implemented by sequencial list self.datTree = [self.INIT_VAL for _ in range(2 * self.datSize + 1)] # self.datTree = np.full(2*self.datSize+1,self.INIT_VAL,int) def update(self, i, val): i -= 1 # 1-orderで指定され、内部では0-Order想定? i += self.datSize - 1 # print("upd",i,val) self.datTree[i] = val while 0 < i: i = (i - 1) >> 1 # (i-1)//2 self.datTree[i] = self.compareFunc( self.datTree[i * 2 + 1], self.datTree[i * 2 + 2] ) # print("upd",i,self.datTree[i]) def query(self, a, b): return self.query_2(a, b, 0, 0, self.datSize) def query_(self, a, b, i, l, r): """get minimun/maximum value of range[a,b) all 1-indexed i is the root vertex of search l,r is range of the root vertex """ if r <= a or b <= l: # (a,b) and (l,r) is not intersected return self.UNDEFINED_VAL if a <= l and r <= b: # i is index required return self.datTree[i] else: # search children m = (l + r) >> 1 # (l+r) // 2 # vl = self.query_(a, b, i*2 + 1, l, m ) # vr = self.query_(a, b, i*2 + 2, m, r ) vl = self.query_(a, b, (i << 1) + 1, l, m) vr = self.query_(a, b, (i << 1) + 2, m, r) return self.compareFunc(vl, vr) def query_2(self, a, b, i, l, r): """get minimun/maximum value of range[a,b) all 1-indexed i is the root vertex of search l,r is range of the root vertex """ ret = self.UNDEFINED_VAL a += self.datSize b += self.datSize while a < b: if b & 1: b -= 1 ret = self.compareFunc(ret, self.datTree[b - 1]) if a & 1: ret = self.compareFunc(ret, self.datTree[a - 1]) a += 1 a >>= 1 b >>= 1 return ret # if r <= a or b <= l: # # (a,b) and (l,r) is not intersected # return self.UNDEFINED_VAL # if a <= l and r <= b: # # i is index required # return self.datTree[i] # else: # # search children # m = (l+r) >> 1 #(l+r) // 2 # # vl = self.query_(a, b, i*2 + 1, l, m ) # # vr = self.query_(a, b, i*2 + 2, m, r ) # vl = self.query_(a, b, (i << 1) + 1, l, m ) # vr = self.query_(a, b, (i << 1) + 2, m, r ) # return self.compareFunc(vl,vr) def LongestIncreaseSeaquence(H, A): # === Coordinate compression === # unique and sort asc N = len(H) # sortedA = sorted(list(set(A))) lis = 0 # === Range Maximum Query === # ここでは、各要素iに、最後の値がiの時のLISを登録 tree = SegTree(N, max, 0, -1e18) for n in range(N): # i=bisect.bisect_left(sortedA,A[n]) maxValOfCurrentRange = tree.query(0, H[n]) # valOfNext = tree.query(H[n],H[n]+1) # # i+=1 # if valOfNext < maxValOfCurrentRange + A[n]: # print( H[n], maxValOfCurrentRange + A[n] ) # tree.debugPrint() tree.update(H[n], maxValOfCurrentRange + A[n]) lis = tree.query(0, N + 1) return lis def main(): N = int(eval(input())) # 高さは、N以下で全部違うらしい H = list(map(int, input().split())) A = list(map(int, input().split())) # A = [ int(input()) for _ in range(N)] print((LongestIncreaseSeaquence(H, A))) if __name__ == "__main__": main()
# EDPC Q - Flowers # 重み付きのLISと言って良いような問題 # これは、LISのdpを少し改造すれば解ける # import numpy as np ## test data # 4 # 3 1 4 2 # 10 20 30 40 ## ans=60 # import bisect class BIT: def __init__(self, size): self.N = size self.bit = [0] * (self.N + 1) def getSum(self, i): s = 0 while 0 < i: s += self.bit[i] i -= i & -i return s def getMax(self, i): s = 0 while 0 < i: s = max(s, self.bit[i]) i -= i & -i return s def add(self, i, val): while i <= self.N: # for range summary query # self.bit[i] += val # for range maximum query self.bit[i] = max(self.bit[i], val) i += i & -i def LongestIncreaseSeaquence(H, A): # === Coordinate compression === # unique and sort asc N = len(H) # sortedA = sorted(list(set(A))) lis = 0 # === Range Maximum Query === # ここでは、各要素iに、最後の値がiの時のLISを登録 tree = BIT(N) for n in range(N): tree.add(H[n], tree.getMax(H[n]) + A[n]) lis = tree.getMax(N) return lis def main(): N = int(eval(input())) # 高さは、N以下で全部違うらしい H = list(map(int, input().split())) A = list(map(int, input().split())) # A = [ int(input()) for _ in range(N)] print((LongestIncreaseSeaquence(H, A))) if __name__ == "__main__": main()
false
46.478873
[ "-class SegTree:", "- def __init__(self, size, func, init_val, undef):", "- self.specSize = size", "- self.datSize = 1", "- self.compareFunc = func # suppose to min or max", "- self.INIT_VAL = init_val # 0 etc", "- self.UNDEFINED_VAL = undef # 1e18 -1e18 etc", "- while self.datSize < size:", "- self.datSize *= 2", "- # the tree is implemented by sequencial list", "- self.datTree = [self.INIT_VAL for _ in range(2 * self.datSize + 1)]", "- # self.datTree = np.full(2*self.datSize+1,self.INIT_VAL,int)", "+class BIT:", "+ def __init__(self, size):", "+ self.N = size", "+ self.bit = [0] * (self.N + 1)", "- def update(self, i, val):", "- i -= 1 # 1-orderで指定され、内部では0-Order想定?", "- i += self.datSize - 1", "- # print(\"upd\",i,val)", "- self.datTree[i] = val", "+ def getSum(self, i):", "+ s = 0", "- i = (i - 1) >> 1 # (i-1)//2", "- self.datTree[i] = self.compareFunc(", "- self.datTree[i * 2 + 1], self.datTree[i * 2 + 2]", "- )", "- # print(\"upd\",i,self.datTree[i])", "+ s += self.bit[i]", "+ i -= i & -i", "+ return s", "- def query(self, a, b):", "- return self.query_2(a, b, 0, 0, self.datSize)", "+ def getMax(self, i):", "+ s = 0", "+ while 0 < i:", "+ s = max(s, self.bit[i])", "+ i -= i & -i", "+ return s", "- def query_(self, a, b, i, l, r):", "- \"\"\"get minimun/maximum value of range[a,b)", "- all 1-indexed", "- i is the root vertex of search", "- l,r is range of the root vertex", "- \"\"\"", "- if r <= a or b <= l:", "- # (a,b) and (l,r) is not intersected", "- return self.UNDEFINED_VAL", "- if a <= l and r <= b:", "- # i is index required", "- return self.datTree[i]", "- else:", "- # search children", "- m = (l + r) >> 1 # (l+r) // 2", "- # vl = self.query_(a, b, i*2 + 1, l, m )", "- # vr = self.query_(a, b, i*2 + 2, m, r )", "- vl = self.query_(a, b, (i << 1) + 1, l, m)", "- vr = self.query_(a, b, (i << 1) + 2, m, r)", "- return self.compareFunc(vl, vr)", "-", "- def query_2(self, a, b, i, l, r):", "- \"\"\"get minimun/maximum value of range[a,b)", "- all 1-indexed", "- i is the root vertex of search", "- l,r is range of the root vertex", "- \"\"\"", "- ret = self.UNDEFINED_VAL", "- a += self.datSize", "- b += self.datSize", "- while a < b:", "- if b & 1:", "- b -= 1", "- ret = self.compareFunc(ret, self.datTree[b - 1])", "- if a & 1:", "- ret = self.compareFunc(ret, self.datTree[a - 1])", "- a += 1", "- a >>= 1", "- b >>= 1", "- return ret", "- # if r <= a or b <= l:", "- # \t# (a,b) and (l,r) is not intersected", "- # \treturn self.UNDEFINED_VAL", "- # if a <= l and r <= b:", "- # \t# i is index required", "- # \treturn self.datTree[i]", "- # else:", "- # \t# search children", "- # \tm = (l+r) >> 1 #(l+r) // 2", "- # \t# vl = self.query_(a, b, i*2 + 1, l, m )", "- # \t# vr = self.query_(a, b, i*2 + 2, m, r )", "- # \tvl = self.query_(a, b, (i << 1) + 1, l, m )", "- # \tvr = self.query_(a, b, (i << 1) + 2, m, r )", "- # \treturn self.compareFunc(vl,vr)", "+ def add(self, i, val):", "+ while i <= self.N:", "+ # for range summary query", "+ # self.bit[i] += val", "+ # for range maximum query", "+ self.bit[i] = max(self.bit[i], val)", "+ i += i & -i", "- tree = SegTree(N, max, 0, -1e18)", "+ tree = BIT(N)", "- # i=bisect.bisect_left(sortedA,A[n])", "- maxValOfCurrentRange = tree.query(0, H[n])", "- # valOfNext = tree.query(H[n],H[n]+1)", "- # # i+=1", "- # if valOfNext < maxValOfCurrentRange + A[n]:", "- # print( H[n], maxValOfCurrentRange + A[n] )", "- # tree.debugPrint()", "- tree.update(H[n], maxValOfCurrentRange + A[n])", "- lis = tree.query(0, N + 1)", "+ tree.add(H[n], tree.getMax(H[n]) + A[n])", "+ lis = tree.getMax(N)" ]
false
0.046947
0.046792
1.003315
[ "s925621081", "s776095179" ]
u282228874
p03086
python
s423660351
s006088404
19
17
2,940
2,940
Accepted
Accepted
10.53
S = eval(input())+'Z' X = 'ATCG' res = [0] count = 0 for i in S: if i in X: count += 1 else: res.append(count) count = 0 print((max(res)))
S = list(eval(input())) A = "ATCG" count = 0 res = [0] for s in S: if s in A: count += 1 res.append(count) else: count = 0 print((max(res)))
11
11
173
150
S = eval(input()) + "Z" X = "ATCG" res = [0] count = 0 for i in S: if i in X: count += 1 else: res.append(count) count = 0 print((max(res)))
S = list(eval(input())) A = "ATCG" count = 0 res = [0] for s in S: if s in A: count += 1 res.append(count) else: count = 0 print((max(res)))
false
0
[ "-S = eval(input()) + \"Z\"", "-X = \"ATCG\"", "+S = list(eval(input()))", "+A = \"ATCG\"", "+count = 0", "-count = 0", "-for i in S:", "- if i in X:", "+for s in S:", "+ if s in A:", "+ res.append(count)", "- res.append(count)" ]
false
0.061255
0.046942
1.304908
[ "s423660351", "s006088404" ]
u297574184
p03141
python
s429580741
s813439309
816
450
80,600
25,528
Accepted
Accepted
44.85
from heapq import heapify, heappush, heappop N = int(eval(input())) As, Bs = [], [] for _ in range(N): A, B = list(map(int, input().split())) As.append(A) Bs.append(B) PQ = [(-A-B, i) for i, (A, B) in enumerate(zip(As, Bs))] heapify(PQ) t = 1 hT = hA = 0 while PQ: H, i = heappop(PQ) if t % 2: hT += As[i] else: hA += Bs[i] t += 1 print((hT - hA))
N = int(eval(input())) As, Bs = [], [] for _ in range(N): A, B = list(map(int, input().split())) As.append(A) Bs.append(B) Cs = [(A+B, i) for i, (A, B) in enumerate(zip(As, Bs))] Cs.sort(reverse=True) hA = sum([As[i] for C, i in Cs[::2]]) hB = sum([Bs[i] for C, i in Cs[1::2]]) print((hA - hB))
23
13
404
307
from heapq import heapify, heappush, heappop N = int(eval(input())) As, Bs = [], [] for _ in range(N): A, B = list(map(int, input().split())) As.append(A) Bs.append(B) PQ = [(-A - B, i) for i, (A, B) in enumerate(zip(As, Bs))] heapify(PQ) t = 1 hT = hA = 0 while PQ: H, i = heappop(PQ) if t % 2: hT += As[i] else: hA += Bs[i] t += 1 print((hT - hA))
N = int(eval(input())) As, Bs = [], [] for _ in range(N): A, B = list(map(int, input().split())) As.append(A) Bs.append(B) Cs = [(A + B, i) for i, (A, B) in enumerate(zip(As, Bs))] Cs.sort(reverse=True) hA = sum([As[i] for C, i in Cs[::2]]) hB = sum([Bs[i] for C, i in Cs[1::2]]) print((hA - hB))
false
43.478261
[ "-from heapq import heapify, heappush, heappop", "-", "-PQ = [(-A - B, i) for i, (A, B) in enumerate(zip(As, Bs))]", "-heapify(PQ)", "-t = 1", "-hT = hA = 0", "-while PQ:", "- H, i = heappop(PQ)", "- if t % 2:", "- hT += As[i]", "- else:", "- hA += Bs[i]", "- t += 1", "-print((hT - hA))", "+Cs = [(A + B, i) for i, (A, B) in enumerate(zip(As, Bs))]", "+Cs.sort(reverse=True)", "+hA = sum([As[i] for C, i in Cs[::2]])", "+hB = sum([Bs[i] for C, i in Cs[1::2]])", "+print((hA - hB))" ]
false
0.037057
0.035951
1.030765
[ "s429580741", "s813439309" ]
u408260374
p02373
python
s426917104
s259590242
2,320
1,910
41,016
110,136
Accepted
Accepted
17.67
class HeavyLightDecomposition: def __init__(self, g, root=0): self.g = g self.vid, self.head, self.heavy, self.parent = [0] * len(g), [-1] * len(g), [-1] * len(g), [-1] * len(g) self.dfs(root) self.bfs(root) def dfs(self, root): stack = [(root, -1)] sub, max_sub = [1] * len(self.g), [(0, -1)] * len(self.g) used = [False] * len(self.g) while stack: v, par = stack.pop() if not used[v]: used[v] = True self.parent[v] = par stack.append((v, par)) stack.extend((c, v) for c in self.g[v] if c != par) else: if par != -1: sub[par] += sub[v] max_sub[par] = max(max_sub[par], (sub[v], v)) self.heavy[v] = max_sub[v][1] def bfs(self, root=0): from collections import deque k, que = 0, deque([root]) while que: r = v = que.popleft() while v != -1: self.vid[v], self.head[v] = k, r for c in self.g[v]: if c != self.parent[v] and c != self.heavy[v]: que.append(c) k += 1 v = self.heavy[v] def lca(self, u, v): while self.head[u] != self.head[v]: if self.vid[u] > self.vid[v]: u, v = v, u v = self.parent[self.head[v]] else: if self.vid[u] > self.vid[v]: u, v = v, u return u N = int(eval(input())) g = [[] for _ in range(N)] for i in range(N): for c in map(int, input().split()[1:]): g[i].append(c) g[c].append(i) hld = HeavyLightDecomposition(g) Q = int(eval(input())) for _ in range(Q): u, v = list(map(int, input().split())) print((hld.lca(u, v)))
import sys if sys.version[0] == '2': range, input = xrange, raw_input class Edge: def __init__(self, dst, weight): self.dst, self.weight = dst, weight def __lt__(self, e): return self.weight > e.weight class Graph: def __init__(self, V): self.V = V self.E = [[] for _ in range(V)] def add_edge(self, src, dst, weight): self.E[src].append(Edge(dst, weight)) class HeavyLightDecomposition: def __init__(self, g, root=0): self.g = g self.vid, self.head, self.heavy, self.parent = [0] * g.V, [-1] * g.V, [-1] * g.V, [-1] * g.V self.dfs(root) self.bfs(root) def dfs(self, root): stack = [(root, -1)] sub, max_sub = [1] * self.g.V, [(0, -1)] * self.g.V used = [False] * self.g.V while stack: v, par = stack.pop() if not used[v]: used[v] = True self.parent[v] = par stack.append((v, par)) stack.extend((e.dst, v) for e in self.g.E[v] if e.dst != par) else: if par != -1: sub[par] += sub[v] max_sub[par] = max(max_sub[par], (sub[v], v)) self.heavy[v] = max_sub[v][1] def bfs(self, root=0): from collections import deque k, que = 0, deque([root]) while que: r = v = que.popleft() while v != -1: self.vid[v], self.head[v] = k, r for e in self.g.E[v]: if e.dst != self.parent[v] and e.dst != self.heavy[v]: que.append(e.dst) k += 1 v = self.heavy[v] def lca(self, u, v): while self.head[u] != self.head[v]: if self.vid[u] > self.vid[v]: u, v = v, u v = self.parent[self.head[v]] else: if self.vid[u] > self.vid[v]: u, v = v, u return u N = int(eval(input())) g = Graph(N) for i in range(N): for c in map(int, input().split()[1:]): g.add_edge(i, c, 1) g.add_edge(c, i, 1) hld = HeavyLightDecomposition(g) Q = int(eval(input())) for _ in range(Q): u, v = list(map(int, input().split())) print((hld.lca(u, v)))
59
81
1,911
2,357
class HeavyLightDecomposition: def __init__(self, g, root=0): self.g = g self.vid, self.head, self.heavy, self.parent = ( [0] * len(g), [-1] * len(g), [-1] * len(g), [-1] * len(g), ) self.dfs(root) self.bfs(root) def dfs(self, root): stack = [(root, -1)] sub, max_sub = [1] * len(self.g), [(0, -1)] * len(self.g) used = [False] * len(self.g) while stack: v, par = stack.pop() if not used[v]: used[v] = True self.parent[v] = par stack.append((v, par)) stack.extend((c, v) for c in self.g[v] if c != par) else: if par != -1: sub[par] += sub[v] max_sub[par] = max(max_sub[par], (sub[v], v)) self.heavy[v] = max_sub[v][1] def bfs(self, root=0): from collections import deque k, que = 0, deque([root]) while que: r = v = que.popleft() while v != -1: self.vid[v], self.head[v] = k, r for c in self.g[v]: if c != self.parent[v] and c != self.heavy[v]: que.append(c) k += 1 v = self.heavy[v] def lca(self, u, v): while self.head[u] != self.head[v]: if self.vid[u] > self.vid[v]: u, v = v, u v = self.parent[self.head[v]] else: if self.vid[u] > self.vid[v]: u, v = v, u return u N = int(eval(input())) g = [[] for _ in range(N)] for i in range(N): for c in map(int, input().split()[1:]): g[i].append(c) g[c].append(i) hld = HeavyLightDecomposition(g) Q = int(eval(input())) for _ in range(Q): u, v = list(map(int, input().split())) print((hld.lca(u, v)))
import sys if sys.version[0] == "2": range, input = xrange, raw_input class Edge: def __init__(self, dst, weight): self.dst, self.weight = dst, weight def __lt__(self, e): return self.weight > e.weight class Graph: def __init__(self, V): self.V = V self.E = [[] for _ in range(V)] def add_edge(self, src, dst, weight): self.E[src].append(Edge(dst, weight)) class HeavyLightDecomposition: def __init__(self, g, root=0): self.g = g self.vid, self.head, self.heavy, self.parent = ( [0] * g.V, [-1] * g.V, [-1] * g.V, [-1] * g.V, ) self.dfs(root) self.bfs(root) def dfs(self, root): stack = [(root, -1)] sub, max_sub = [1] * self.g.V, [(0, -1)] * self.g.V used = [False] * self.g.V while stack: v, par = stack.pop() if not used[v]: used[v] = True self.parent[v] = par stack.append((v, par)) stack.extend((e.dst, v) for e in self.g.E[v] if e.dst != par) else: if par != -1: sub[par] += sub[v] max_sub[par] = max(max_sub[par], (sub[v], v)) self.heavy[v] = max_sub[v][1] def bfs(self, root=0): from collections import deque k, que = 0, deque([root]) while que: r = v = que.popleft() while v != -1: self.vid[v], self.head[v] = k, r for e in self.g.E[v]: if e.dst != self.parent[v] and e.dst != self.heavy[v]: que.append(e.dst) k += 1 v = self.heavy[v] def lca(self, u, v): while self.head[u] != self.head[v]: if self.vid[u] > self.vid[v]: u, v = v, u v = self.parent[self.head[v]] else: if self.vid[u] > self.vid[v]: u, v = v, u return u N = int(eval(input())) g = Graph(N) for i in range(N): for c in map(int, input().split()[1:]): g.add_edge(i, c, 1) g.add_edge(c, i, 1) hld = HeavyLightDecomposition(g) Q = int(eval(input())) for _ in range(Q): u, v = list(map(int, input().split())) print((hld.lca(u, v)))
false
27.160494
[ "+import sys", "+", "+if sys.version[0] == \"2\":", "+ range, input = xrange, raw_input", "+", "+", "+class Edge:", "+ def __init__(self, dst, weight):", "+ self.dst, self.weight = dst, weight", "+", "+ def __lt__(self, e):", "+ return self.weight > e.weight", "+", "+", "+class Graph:", "+ def __init__(self, V):", "+ self.V = V", "+ self.E = [[] for _ in range(V)]", "+", "+ def add_edge(self, src, dst, weight):", "+ self.E[src].append(Edge(dst, weight))", "+", "+", "- [0] * len(g),", "- [-1] * len(g),", "- [-1] * len(g),", "- [-1] * len(g),", "+ [0] * g.V,", "+ [-1] * g.V,", "+ [-1] * g.V,", "+ [-1] * g.V,", "- sub, max_sub = [1] * len(self.g), [(0, -1)] * len(self.g)", "- used = [False] * len(self.g)", "+ sub, max_sub = [1] * self.g.V, [(0, -1)] * self.g.V", "+ used = [False] * self.g.V", "- stack.extend((c, v) for c in self.g[v] if c != par)", "+ stack.extend((e.dst, v) for e in self.g.E[v] if e.dst != par)", "- for c in self.g[v]:", "- if c != self.parent[v] and c != self.heavy[v]:", "- que.append(c)", "+ for e in self.g.E[v]:", "+ if e.dst != self.parent[v] and e.dst != self.heavy[v]:", "+ que.append(e.dst)", "-g = [[] for _ in range(N)]", "+g = Graph(N)", "- g[i].append(c)", "- g[c].append(i)", "+ g.add_edge(i, c, 1)", "+ g.add_edge(c, i, 1)" ]
false
0.086226
0.043248
1.993747
[ "s426917104", "s259590242" ]
u411478442
p02582
python
s126470232
s159053115
33
29
8,960
8,872
Accepted
Accepted
12.12
s = eval(input()) R_list = s.split('S') ans = 0 for s in R_list: if ans < len(s): ans = len(s) print(ans)
s = eval(input()) n = 0 ans = 0 for ch in s: if ch == 'R': n += 1 else: if ans < n: ans = n n = 0 if ans < n: ans = n print(ans)
10
16
121
166
s = eval(input()) R_list = s.split("S") ans = 0 for s in R_list: if ans < len(s): ans = len(s) print(ans)
s = eval(input()) n = 0 ans = 0 for ch in s: if ch == "R": n += 1 else: if ans < n: ans = n n = 0 if ans < n: ans = n print(ans)
false
37.5
[ "-R_list = s.split(\"S\")", "+n = 0", "-for s in R_list:", "- if ans < len(s):", "- ans = len(s)", "+for ch in s:", "+ if ch == \"R\":", "+ n += 1", "+ else:", "+ if ans < n:", "+ ans = n", "+ n = 0", "+if ans < n:", "+ ans = n" ]
false
0.040006
0.079687
0.50204
[ "s126470232", "s159053115" ]
u297574184
p02937
python
s524272809
s955727007
499
120
126,452
14,700
Accepted
Accepted
75.95
import sys numChar = 26 ordA = ord('a') Ss = input().rstrip() Ts = input().rstrip() setS, setT = set(Ss), set(Ts) for T in setT: if T not in setS: print((-1)) sys.exit() def getDistNextss(As, numChar): lenA = len(As) poss = [-1] * numChar for i, A in enumerate(As): if poss[A] == -1: poss[A] = i + lenA distNextss = [[0]*(numChar) for _ in range(lenA)] for i in reversed(list(range(lenA))): poss[As[i]] = i distNextss[i] = [pos-i for pos in poss] return distNextss As = [ord(S)-ordA for S in Ss] distNextss = getDistNextss(As, numChar) lenS = len(Ss) i = 0 for T in Ts: T = ord(T) - ordA i += distNextss[i%lenS][T] i += 1 print(i)
from bisect import bisect_left, bisect_right import sys def solve(): numChar = 26 ordA = ord('a') Ss = input().rstrip() Ts = input().rstrip() lenS = len(Ss) Ss = [ord(S)-ordA for S in Ss] Ts = [ord(T)-ordA for T in Ts] setS, setT = set(Ss), set(Ts) for T in setT: if T not in setS: print((-1)) sys.exit() posChs = [[] for _ in range(numChar)] for i, S in enumerate(Ss+Ss): posChs[S].append(i) ans = 0 i = -1 for T in Ts: iPos = bisect_right(posChs[T], i) i2 = posChs[T][iPos] ans += i2 - i i = i2 % lenS print(ans) solve()
37
36
758
697
import sys numChar = 26 ordA = ord("a") Ss = input().rstrip() Ts = input().rstrip() setS, setT = set(Ss), set(Ts) for T in setT: if T not in setS: print((-1)) sys.exit() def getDistNextss(As, numChar): lenA = len(As) poss = [-1] * numChar for i, A in enumerate(As): if poss[A] == -1: poss[A] = i + lenA distNextss = [[0] * (numChar) for _ in range(lenA)] for i in reversed(list(range(lenA))): poss[As[i]] = i distNextss[i] = [pos - i for pos in poss] return distNextss As = [ord(S) - ordA for S in Ss] distNextss = getDistNextss(As, numChar) lenS = len(Ss) i = 0 for T in Ts: T = ord(T) - ordA i += distNextss[i % lenS][T] i += 1 print(i)
from bisect import bisect_left, bisect_right import sys def solve(): numChar = 26 ordA = ord("a") Ss = input().rstrip() Ts = input().rstrip() lenS = len(Ss) Ss = [ord(S) - ordA for S in Ss] Ts = [ord(T) - ordA for T in Ts] setS, setT = set(Ss), set(Ts) for T in setT: if T not in setS: print((-1)) sys.exit() posChs = [[] for _ in range(numChar)] for i, S in enumerate(Ss + Ss): posChs[S].append(i) ans = 0 i = -1 for T in Ts: iPos = bisect_right(posChs[T], i) i2 = posChs[T][iPos] ans += i2 - i i = i2 % lenS print(ans) solve()
false
2.702703
[ "+from bisect import bisect_left, bisect_right", "-numChar = 26", "-ordA = ord(\"a\")", "-Ss = input().rstrip()", "-Ts = input().rstrip()", "-setS, setT = set(Ss), set(Ts)", "-for T in setT:", "- if T not in setS:", "- print((-1))", "- sys.exit()", "+", "+def solve():", "+ numChar = 26", "+ ordA = ord(\"a\")", "+ Ss = input().rstrip()", "+ Ts = input().rstrip()", "+ lenS = len(Ss)", "+ Ss = [ord(S) - ordA for S in Ss]", "+ Ts = [ord(T) - ordA for T in Ts]", "+ setS, setT = set(Ss), set(Ts)", "+ for T in setT:", "+ if T not in setS:", "+ print((-1))", "+ sys.exit()", "+ posChs = [[] for _ in range(numChar)]", "+ for i, S in enumerate(Ss + Ss):", "+ posChs[S].append(i)", "+ ans = 0", "+ i = -1", "+ for T in Ts:", "+ iPos = bisect_right(posChs[T], i)", "+ i2 = posChs[T][iPos]", "+ ans += i2 - i", "+ i = i2 % lenS", "+ print(ans)", "-def getDistNextss(As, numChar):", "- lenA = len(As)", "- poss = [-1] * numChar", "- for i, A in enumerate(As):", "- if poss[A] == -1:", "- poss[A] = i + lenA", "- distNextss = [[0] * (numChar) for _ in range(lenA)]", "- for i in reversed(list(range(lenA))):", "- poss[As[i]] = i", "- distNextss[i] = [pos - i for pos in poss]", "- return distNextss", "-", "-", "-As = [ord(S) - ordA for S in Ss]", "-distNextss = getDistNextss(As, numChar)", "-lenS = len(Ss)", "-i = 0", "-for T in Ts:", "- T = ord(T) - ordA", "- i += distNextss[i % lenS][T]", "- i += 1", "-print(i)", "+solve()" ]
false
0.037371
0.035692
1.04704
[ "s524272809", "s955727007" ]
u893063840
p03148
python
s741183219
s748498112
613
453
38,136
30,800
Accepted
Accepted
26.1
from heapq import heappush, heappop n, k = list(map(int, input().split())) td = [list(map(int, input().split())) for _ in range(n)] td.sort(key=lambda x: x[1], reverse=True) types = set() can_remove = [] d_sm = 0 for t, d in td[:k]: d_sm += d if t in types: can_remove.append(d) else: types.add(t) type_cnt = len(types) ans = d_sm + type_cnt ** 2 left = [] for t, d in td[k:]: d = -d heappush(left, [d, t]) while can_remove and left: d, t = heappop(left) d = -d if t not in types: types.add(t) d_rmv = can_remove.pop() d_sm += d - d_rmv type_cnt += 1 ans = max(ans, d_sm + type_cnt ** 2) print(ans)
n, k = list(map(int, input().split())) td = [list(map(int, input().split())) for _ in range(n)] td.sort(key=lambda x: x[1], reverse=True) types = set() can_remove = [] d_sm = 0 for t, d in td[:k]: d_sm += d if t in types: can_remove.append(d) else: types.add(t) type_cnt = len(types) ans = d_sm + type_cnt ** 2 left = td[k:][::-1] while can_remove and left: t, d = left.pop() if t not in types: types.add(t) d_rmv = can_remove.pop() d_sm += d - d_rmv type_cnt += 1 ans = max(ans, d_sm + type_cnt ** 2) print(ans)
38
32
661
565
from heapq import heappush, heappop n, k = list(map(int, input().split())) td = [list(map(int, input().split())) for _ in range(n)] td.sort(key=lambda x: x[1], reverse=True) types = set() can_remove = [] d_sm = 0 for t, d in td[:k]: d_sm += d if t in types: can_remove.append(d) else: types.add(t) type_cnt = len(types) ans = d_sm + type_cnt**2 left = [] for t, d in td[k:]: d = -d heappush(left, [d, t]) while can_remove and left: d, t = heappop(left) d = -d if t not in types: types.add(t) d_rmv = can_remove.pop() d_sm += d - d_rmv type_cnt += 1 ans = max(ans, d_sm + type_cnt**2) print(ans)
n, k = list(map(int, input().split())) td = [list(map(int, input().split())) for _ in range(n)] td.sort(key=lambda x: x[1], reverse=True) types = set() can_remove = [] d_sm = 0 for t, d in td[:k]: d_sm += d if t in types: can_remove.append(d) else: types.add(t) type_cnt = len(types) ans = d_sm + type_cnt**2 left = td[k:][::-1] while can_remove and left: t, d = left.pop() if t not in types: types.add(t) d_rmv = can_remove.pop() d_sm += d - d_rmv type_cnt += 1 ans = max(ans, d_sm + type_cnt**2) print(ans)
false
15.789474
[ "-from heapq import heappush, heappop", "-", "-left = []", "-for t, d in td[k:]:", "- d = -d", "- heappush(left, [d, t])", "+left = td[k:][::-1]", "- d, t = heappop(left)", "- d = -d", "+ t, d = left.pop()" ]
false
0.03638
0.036295
1.002349
[ "s741183219", "s748498112" ]
u296518383
p02573
python
s045588136
s970861683
513
320
117,516
117,876
Accepted
Accepted
37.62
class UnionFind: def __init__(self, n): self.root = [i for i in range(n + 1)] self.size = [1] * (n + 1) def find(self, x): y = self.root[x] if x == y: return x else: z = self.find(y) self.root[x] = z return z def union(self, x, y): rx = self.find(x) ry = self.find(y) sx = self.size[rx] sy = self.size[ry] if rx == ry: return 0 else: if sx >= sy: self.root[ry] = rx self.size[rx] = sx + sy else: self.root[rx] = ry self.size[ry] = sx + sy return sx * sy N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] uf = UnionFind(N) for a, b in AB: uf.union(a, b) cnt = [0] * (N + 1) for i in range(1, N + 1): cnt[uf.find(i)] += 1 print((max(cnt)))
from sys import stdin, setrecursionlimit input = stdin.buffer.readline setrecursionlimit(10 ** 7) from heapq import heappush, heappop from bisect import bisect_left, bisect_right from collections import deque, defaultdict, Counter from itertools import combinations, permutations, combinations_with_replacement from itertools import accumulate from math import ceil, sqrt, pi, radians, sin, cos class UnionFind: def __init__(self, n): self.root = [i for i in range(n + 1)] self.size = [1] * (n + 1) def find(self, x): y = self.root[x] if x == y: return x else: z = self.find(y) self.root[x] = z return z def union(self, x, y): rx = self.find(x) ry = self.find(y) sx = self.size[rx] sy = self.size[ry] if rx == ry: return 0 else: if sx >= sy: self.root[ry] = rx self.size[rx] = sx + sy else: self.root[rx] = ry self.size[ry] = sx + sy return sx * sy def check(self): print([self.find(i) for i in range(1, len(self.root))]) MOD = 10 ** 9 + 7 INF = 10 ** 18 N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] uf = UnionFind(N) for a, b in AB: uf.union(a, b) cnt = [0] * (N + 1) for i in range(1, N + 1): cnt[uf.find(i)] += 1 print((max(cnt)))
40
56
982
1,514
class UnionFind: def __init__(self, n): self.root = [i for i in range(n + 1)] self.size = [1] * (n + 1) def find(self, x): y = self.root[x] if x == y: return x else: z = self.find(y) self.root[x] = z return z def union(self, x, y): rx = self.find(x) ry = self.find(y) sx = self.size[rx] sy = self.size[ry] if rx == ry: return 0 else: if sx >= sy: self.root[ry] = rx self.size[rx] = sx + sy else: self.root[rx] = ry self.size[ry] = sx + sy return sx * sy N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] uf = UnionFind(N) for a, b in AB: uf.union(a, b) cnt = [0] * (N + 1) for i in range(1, N + 1): cnt[uf.find(i)] += 1 print((max(cnt)))
from sys import stdin, setrecursionlimit input = stdin.buffer.readline setrecursionlimit(10**7) from heapq import heappush, heappop from bisect import bisect_left, bisect_right from collections import deque, defaultdict, Counter from itertools import combinations, permutations, combinations_with_replacement from itertools import accumulate from math import ceil, sqrt, pi, radians, sin, cos class UnionFind: def __init__(self, n): self.root = [i for i in range(n + 1)] self.size = [1] * (n + 1) def find(self, x): y = self.root[x] if x == y: return x else: z = self.find(y) self.root[x] = z return z def union(self, x, y): rx = self.find(x) ry = self.find(y) sx = self.size[rx] sy = self.size[ry] if rx == ry: return 0 else: if sx >= sy: self.root[ry] = rx self.size[rx] = sx + sy else: self.root[rx] = ry self.size[ry] = sx + sy return sx * sy def check(self): print([self.find(i) for i in range(1, len(self.root))]) MOD = 10**9 + 7 INF = 10**18 N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] uf = UnionFind(N) for a, b in AB: uf.union(a, b) cnt = [0] * (N + 1) for i in range(1, N + 1): cnt[uf.find(i)] += 1 print((max(cnt)))
false
28.571429
[ "+from sys import stdin, setrecursionlimit", "+", "+input = stdin.buffer.readline", "+setrecursionlimit(10**7)", "+from heapq import heappush, heappop", "+from bisect import bisect_left, bisect_right", "+from collections import deque, defaultdict, Counter", "+from itertools import combinations, permutations, combinations_with_replacement", "+from itertools import accumulate", "+from math import ceil, sqrt, pi, radians, sin, cos", "+", "+", "+ def check(self):", "+ print([self.find(i) for i in range(1, len(self.root))])", "+", "+MOD = 10**9 + 7", "+INF = 10**18" ]
false
0.03605
0.073655
0.489449
[ "s045588136", "s970861683" ]
u811967730
p02972
python
s474736282
s986188238
878
275
14,484
14,484
Accepted
Accepted
68.68
from collections import deque N = int(eval(input())) A = list(map(int, input().split())) check = [0] * N for i in reversed(list(range(1, N + 1))): x = i total = 0 while x <= N: total += check[x - 1] x += i if total % 2 != A[i - 1]: check[i - 1] = 1 M = sum(check) ans = deque() for index, value in enumerate(check): if value == 1: ans.append(index + 1) print(M) if M > 0: print((*ans))
from collections import deque N = int(eval(input())) A = list(map(int, input().split())) check = [0] * N for i in reversed(list(range(1, N + 1))): if sum(check[i - 1::i]) % 2 != A[i - 1]: check[i - 1] = 1 M = sum(check) ans = deque() for index, value in enumerate(check): if value == 1: ans.append(index + 1) print(M) if M > 0: print((*ans))
26
21
459
382
from collections import deque N = int(eval(input())) A = list(map(int, input().split())) check = [0] * N for i in reversed(list(range(1, N + 1))): x = i total = 0 while x <= N: total += check[x - 1] x += i if total % 2 != A[i - 1]: check[i - 1] = 1 M = sum(check) ans = deque() for index, value in enumerate(check): if value == 1: ans.append(index + 1) print(M) if M > 0: print((*ans))
from collections import deque N = int(eval(input())) A = list(map(int, input().split())) check = [0] * N for i in reversed(list(range(1, N + 1))): if sum(check[i - 1 :: i]) % 2 != A[i - 1]: check[i - 1] = 1 M = sum(check) ans = deque() for index, value in enumerate(check): if value == 1: ans.append(index + 1) print(M) if M > 0: print((*ans))
false
19.230769
[ "- x = i", "- total = 0", "- while x <= N:", "- total += check[x - 1]", "- x += i", "- if total % 2 != A[i - 1]:", "+ if sum(check[i - 1 :: i]) % 2 != A[i - 1]:" ]
false
0.04051
0.036629
1.105955
[ "s474736282", "s986188238" ]
u495667483
p03803
python
s386354059
s503165155
181
33
38,384
9,488
Accepted
Accepted
81.77
A, B = list(map(int,input().split())) if A == 1: A = 14 if B == 1: B = 14 print(('Alice' if A > B else 'Bob' if A < B else 'Draw'))
import sys, math from functools import lru_cache from itertools import accumulate sys.setrecursionlimit(10**9) MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] def mi(): return list(map(int, input().split())) def ii(): return int(eval(input())) def i2(n): tmp = [list(mi()) for i in range(n)] return [list(i) for i in zip(*tmp)] A, B = mi() if A == B: print('Draw') elif A == 1: print('Alice') elif B == 1: print('Bob') else: if A > B: print('Alice') else: print('Bob')
7
32
144
561
A, B = list(map(int, input().split())) if A == 1: A = 14 if B == 1: B = 14 print(("Alice" if A > B else "Bob" if A < B else "Draw"))
import sys, math from functools import lru_cache from itertools import accumulate sys.setrecursionlimit(10**9) MOD = 10**9 + 7 def input(): return sys.stdin.readline()[:-1] def mi(): return list(map(int, input().split())) def ii(): return int(eval(input())) def i2(n): tmp = [list(mi()) for i in range(n)] return [list(i) for i in zip(*tmp)] A, B = mi() if A == B: print("Draw") elif A == 1: print("Alice") elif B == 1: print("Bob") else: if A > B: print("Alice") else: print("Bob")
false
78.125
[ "-A, B = list(map(int, input().split()))", "-if A == 1:", "- A = 14", "-if B == 1:", "- B = 14", "-print((\"Alice\" if A > B else \"Bob\" if A < B else \"Draw\"))", "+import sys, math", "+from functools import lru_cache", "+from itertools import accumulate", "+", "+sys.setrecursionlimit(10**9)", "+MOD = 10**9 + 7", "+", "+", "+def input():", "+ return sys.stdin.readline()[:-1]", "+", "+", "+def mi():", "+ return list(map(int, input().split()))", "+", "+", "+def ii():", "+ return int(eval(input()))", "+", "+", "+def i2(n):", "+ tmp = [list(mi()) for i in range(n)]", "+ return [list(i) for i in zip(*tmp)]", "+", "+", "+A, B = mi()", "+if A == B:", "+ print(\"Draw\")", "+elif A == 1:", "+ print(\"Alice\")", "+elif B == 1:", "+ print(\"Bob\")", "+else:", "+ if A > B:", "+ print(\"Alice\")", "+ else:", "+ print(\"Bob\")" ]
false
0.072099
0.037491
1.923073
[ "s386354059", "s503165155" ]
u784022244
p03043
python
s033078954
s519072314
210
97
14,428
2,940
Accepted
Accepted
53.81
from math import ceil import numpy as np N,K=list(map(int, input().split())) #サイコロを振る 1以上K未満→コイン K以上ゲーム終了、す抜けのかち #コイン 表なら2倍 裏なら0 0なったら負け ans=max( (N-K+1),0) /N #(K-1)/N # M*(2**x)>=K M:サイコロの目 # x*log(2)>=log(K/M) lim=min(K-1,N) for i in range(1,lim+1): x=ceil(np.log(K/i)/np.log(2)) ans+=(1/N)*((0.5)**x) print(ans)
from math import ceil, log N,K=list(map(int, input().split())) ans=0 for i in range(1,N+1): n=ceil(log(K/i, 2)) if n>=0: ans+=(1/(N*2**n)) else: ans+=1/N #print(n) print(ans)
15
12
332
212
from math import ceil import numpy as np N, K = list(map(int, input().split())) # サイコロを振る 1以上K未満→コイン K以上ゲーム終了、す抜けのかち # コイン 表なら2倍 裏なら0 0なったら負け ans = max((N - K + 1), 0) / N # (K-1)/N # M*(2**x)>=K M:サイコロの目 # x*log(2)>=log(K/M) lim = min(K - 1, N) for i in range(1, lim + 1): x = ceil(np.log(K / i) / np.log(2)) ans += (1 / N) * ((0.5) ** x) print(ans)
from math import ceil, log N, K = list(map(int, input().split())) ans = 0 for i in range(1, N + 1): n = ceil(log(K / i, 2)) if n >= 0: ans += 1 / (N * 2**n) else: ans += 1 / N # print(n) print(ans)
false
20
[ "-from math import ceil", "-import numpy as np", "+from math import ceil, log", "-# サイコロを振る 1以上K未満→コイン K以上ゲーム終了、す抜けのかち", "-# コイン 表なら2倍 裏なら0 0なったら負け", "-ans = max((N - K + 1), 0) / N", "-# (K-1)/N", "-# M*(2**x)>=K M:サイコロの目", "-# x*log(2)>=log(K/M)", "-lim = min(K - 1, N)", "-for i in range(1, lim + 1):", "- x = ceil(np.log(K / i) / np.log(2))", "- ans += (1 / N) * ((0.5) ** x)", "+ans = 0", "+for i in range(1, N + 1):", "+ n = ceil(log(K / i, 2))", "+ if n >= 0:", "+ ans += 1 / (N * 2**n)", "+ else:", "+ ans += 1 / N", "+ # print(n)" ]
false
0.229937
0.098841
2.326329
[ "s033078954", "s519072314" ]
u399616977
p02899
python
s088434129
s313978840
306
165
19,964
24,632
Accepted
Accepted
46.08
n=int(input()) l=[] tem=list(map(int,input().split())) for i in range(n): l.append((tem[i],i+1)) l=sorted(l,key=lambda s: s[0]) for x in range(n): if x==0: print(l[x][1],end="") else: print(" %d"%l[x][1],end="")
n=int(eval(input())) l=[] tem=list(map(int,input().split())) for i in range(n): l.append((tem[i],i+1)) l=sorted(l,key=lambda s: s[0]) print((" ".join(list([str(x[1]) for x in l]))))
12
8
252
190
n = int(input()) l = [] tem = list(map(int, input().split())) for i in range(n): l.append((tem[i], i + 1)) l = sorted(l, key=lambda s: s[0]) for x in range(n): if x == 0: print(l[x][1], end="") else: print(" %d" % l[x][1], end="")
n = int(eval(input())) l = [] tem = list(map(int, input().split())) for i in range(n): l.append((tem[i], i + 1)) l = sorted(l, key=lambda s: s[0]) print((" ".join(list([str(x[1]) for x in l]))))
false
33.333333
[ "-n = int(input())", "+n = int(eval(input()))", "-for x in range(n):", "- if x == 0:", "- print(l[x][1], end=\"\")", "- else:", "- print(\" %d\" % l[x][1], end=\"\")", "+print((\" \".join(list([str(x[1]) for x in l]))))" ]
false
0.083508
0.058444
1.428866
[ "s088434129", "s313978840" ]
u046187684
p02912
python
s705987191
s525272210
141
118
15,176
14,224
Accepted
Accepted
16.31
from heapq import heappush, heappop def solve(string): n, m, *a = list(map(int, string.split())) h = [] for _a in a: heappush(h, -_a) for _ in range(m): heappush(h, -(-heappop(h) // 2)) return str(-sum(h)) if __name__ == '__main__': print((solve('\n'.join([eval(input()), eval(input())]))))
n,m = list(map(int,input().split())) arr = list(map(int,input().split())) l = len(arr) while m != 0 : arr.sort(reverse=True) j = arr[0] // 2 for i in range(l): if arr[i] > j: if m != 0: m -= 1 else: break arr[i] //= 2 else: break if arr[0] == 0: break print((sum(arr)))
15
21
329
457
from heapq import heappush, heappop def solve(string): n, m, *a = list(map(int, string.split())) h = [] for _a in a: heappush(h, -_a) for _ in range(m): heappush(h, -(-heappop(h) // 2)) return str(-sum(h)) if __name__ == "__main__": print((solve("\n".join([eval(input()), eval(input())]))))
n, m = list(map(int, input().split())) arr = list(map(int, input().split())) l = len(arr) while m != 0: arr.sort(reverse=True) j = arr[0] // 2 for i in range(l): if arr[i] > j: if m != 0: m -= 1 else: break arr[i] //= 2 else: break if arr[0] == 0: break print((sum(arr)))
false
28.571429
[ "-from heapq import heappush, heappop", "-", "-", "-def solve(string):", "- n, m, *a = list(map(int, string.split()))", "- h = []", "- for _a in a:", "- heappush(h, -_a)", "- for _ in range(m):", "- heappush(h, -(-heappop(h) // 2))", "- return str(-sum(h))", "-", "-", "-if __name__ == \"__main__\":", "- print((solve(\"\\n\".join([eval(input()), eval(input())]))))", "+n, m = list(map(int, input().split()))", "+arr = list(map(int, input().split()))", "+l = len(arr)", "+while m != 0:", "+ arr.sort(reverse=True)", "+ j = arr[0] // 2", "+ for i in range(l):", "+ if arr[i] > j:", "+ if m != 0:", "+ m -= 1", "+ else:", "+ break", "+ arr[i] //= 2", "+ else:", "+ break", "+ if arr[0] == 0:", "+ break", "+print((sum(arr)))" ]
false
0.035632
0.03687
0.96641
[ "s705987191", "s525272210" ]
u496344397
p03329
python
s932446566
s322376840
514
434
6,900
6,900
Accepted
Accepted
15.56
N = int(eval(input())) dp = list(range(N+1)) for amount in range(6, N+1): unit = 6 while unit <= amount: dp[amount] = min(dp[amount], dp[amount-unit]+1) unit *= 6 unit = 9 while unit <= amount: dp[amount] = min(dp[amount], dp[amount-unit]+1) unit *= 9 print((dp[N]))
N = int(eval(input())) dp = list(range(N+1)) def calc(unit_base): unit = unit_base while unit <= amount: dp[amount] = min(dp[amount], dp[amount-unit]+1) unit *= unit_base for amount in range(6, N+1): calc(6) calc(9) print((dp[N]))
16
15
325
272
N = int(eval(input())) dp = list(range(N + 1)) for amount in range(6, N + 1): unit = 6 while unit <= amount: dp[amount] = min(dp[amount], dp[amount - unit] + 1) unit *= 6 unit = 9 while unit <= amount: dp[amount] = min(dp[amount], dp[amount - unit] + 1) unit *= 9 print((dp[N]))
N = int(eval(input())) dp = list(range(N + 1)) def calc(unit_base): unit = unit_base while unit <= amount: dp[amount] = min(dp[amount], dp[amount - unit] + 1) unit *= unit_base for amount in range(6, N + 1): calc(6) calc(9) print((dp[N]))
false
6.25
[ "-for amount in range(6, N + 1):", "- unit = 6", "+", "+", "+def calc(unit_base):", "+ unit = unit_base", "- unit *= 6", "- unit = 9", "- while unit <= amount:", "- dp[amount] = min(dp[amount], dp[amount - unit] + 1)", "- unit *= 9", "+ unit *= unit_base", "+", "+", "+for amount in range(6, N + 1):", "+ calc(6)", "+ calc(9)" ]
false
0.099253
0.215109
0.461408
[ "s932446566", "s322376840" ]
u729133443
p02756
python
s683202293
s246354903
1,465
716
18,300
4,412
Accepted
Accepted
51.13
s,_,*q=open(0) a='%s' p=1 for q in q: try: q,f,c=q.split() if(f<'2')^p:a+=c else:a=c+a except:p^=1 print(((a%s[:-1])[::p or-1]))
S = str(eval(input())) Q = int(eval(input())) head = "" tail = "" main = S status = 0 while Q: Q -= 1 l = list(map(str,input().split())) if l[0] == "1": status = (status+1)%2 else: letter = l[2] if l[1] == "1": if status == 0: head += letter else: tail += letter else: if status == 0: tail += letter else: head += letter if status == 0: print((head[::-1]+main+tail)) else: print((tail[::-1]+main[::-1]+head))
10
31
151
511
s, _, *q = open(0) a = "%s" p = 1 for q in q: try: q, f, c = q.split() if (f < "2") ^ p: a += c else: a = c + a except: p ^= 1 print(((a % s[:-1])[:: p or -1]))
S = str(eval(input())) Q = int(eval(input())) head = "" tail = "" main = S status = 0 while Q: Q -= 1 l = list(map(str, input().split())) if l[0] == "1": status = (status + 1) % 2 else: letter = l[2] if l[1] == "1": if status == 0: head += letter else: tail += letter else: if status == 0: tail += letter else: head += letter if status == 0: print((head[::-1] + main + tail)) else: print((tail[::-1] + main[::-1] + head))
false
67.741935
[ "-s, _, *q = open(0)", "-a = \"%s\"", "-p = 1", "-for q in q:", "- try:", "- q, f, c = q.split()", "- if (f < \"2\") ^ p:", "- a += c", "+S = str(eval(input()))", "+Q = int(eval(input()))", "+head = \"\"", "+tail = \"\"", "+main = S", "+status = 0", "+while Q:", "+ Q -= 1", "+ l = list(map(str, input().split()))", "+ if l[0] == \"1\":", "+ status = (status + 1) % 2", "+ else:", "+ letter = l[2]", "+ if l[1] == \"1\":", "+ if status == 0:", "+ head += letter", "+ else:", "+ tail += letter", "- a = c + a", "- except:", "- p ^= 1", "-print(((a % s[:-1])[:: p or -1]))", "+ if status == 0:", "+ tail += letter", "+ else:", "+ head += letter", "+if status == 0:", "+ print((head[::-1] + main + tail))", "+else:", "+ print((tail[::-1] + main[::-1] + head))" ]
false
0.048129
0.045577
1.055981
[ "s683202293", "s246354903" ]
u562935282
p03588
python
s977026603
s336052044
330
289
16,604
3,060
Accepted
Accepted
12.42
n = int(eval(input())) M = [tuple(map(int, input().split()))for _ in range(n)] a, b = -1, -1 for i in range(n): ta, tb = M[i] if ta > a: a = ta b = tb print((a + b))
n = int(eval(input())) a, b = 0, float('inf') for i in range(n): ta, tb = list(map(int, input().split())) if a < ta: a = ta b = tb print((a + b))
9
9
189
166
n = int(eval(input())) M = [tuple(map(int, input().split())) for _ in range(n)] a, b = -1, -1 for i in range(n): ta, tb = M[i] if ta > a: a = ta b = tb print((a + b))
n = int(eval(input())) a, b = 0, float("inf") for i in range(n): ta, tb = list(map(int, input().split())) if a < ta: a = ta b = tb print((a + b))
false
0
[ "-M = [tuple(map(int, input().split())) for _ in range(n)]", "-a, b = -1, -1", "+a, b = 0, float(\"inf\")", "- ta, tb = M[i]", "- if ta > a:", "+ ta, tb = list(map(int, input().split()))", "+ if a < ta:" ]
false
0.041189
0.038383
1.073122
[ "s977026603", "s336052044" ]
u215268883
p02596
python
s563180394
s913663684
380
174
92,764
9,028
Accepted
Accepted
54.21
K = int(eval(input())) dic = {} x = 0 count = 0 while 1: x = (x * 10 + 7) % K count += 1 if x == 0: print(count) exit() if x in dic: print((-1)) exit() dic[x] = 1
K = int(eval(input())) x = 0 for i in range(K + 5): x = (x * 10 + 7) % K if x == 0: print((i + 1)) exit() print((-1))
14
8
220
139
K = int(eval(input())) dic = {} x = 0 count = 0 while 1: x = (x * 10 + 7) % K count += 1 if x == 0: print(count) exit() if x in dic: print((-1)) exit() dic[x] = 1
K = int(eval(input())) x = 0 for i in range(K + 5): x = (x * 10 + 7) % K if x == 0: print((i + 1)) exit() print((-1))
false
42.857143
[ "-dic = {}", "-count = 0", "-while 1:", "+for i in range(K + 5):", "- count += 1", "- print(count)", "+ print((i + 1))", "- if x in dic:", "- print((-1))", "- exit()", "- dic[x] = 1", "+print((-1))" ]
false
0.220313
0.069924
3.150755
[ "s563180394", "s913663684" ]
u075303794
p02712
python
s881879336
s077524062
1,183
109
34,468
34,144
Accepted
Accepted
90.79
import numpy as np N = int(eval(input())) list_num = np.arange(1, N+1) for i in list_num: if i % 3 == 0: list_num[i-1] = 0 elif i % 5 == 0: list_num[i-1] = 0 elif i % 15 == 0: list_num[i-1] = 0 print((list_num.sum()))
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(read()) ans = np.arange(N+1, dtype=np.int64) ans[::3] = 0 ans[::5] = 0 print((ans.sum()))
13
14
241
247
import numpy as np N = int(eval(input())) list_num = np.arange(1, N + 1) for i in list_num: if i % 3 == 0: list_num[i - 1] = 0 elif i % 5 == 0: list_num[i - 1] = 0 elif i % 15 == 0: list_num[i - 1] = 0 print((list_num.sum()))
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(read()) ans = np.arange(N + 1, dtype=np.int64) ans[::3] = 0 ans[::5] = 0 print((ans.sum()))
false
7.142857
[ "+import sys", "-N = int(eval(input()))", "-list_num = np.arange(1, N + 1)", "-for i in list_num:", "- if i % 3 == 0:", "- list_num[i - 1] = 0", "- elif i % 5 == 0:", "- list_num[i - 1] = 0", "- elif i % 15 == 0:", "- list_num[i - 1] = 0", "-print((list_num.sum()))", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+N = int(read())", "+ans = np.arange(N + 1, dtype=np.int64)", "+ans[::3] = 0", "+ans[::5] = 0", "+print((ans.sum()))" ]
false
0.682623
0.169672
4.023201
[ "s881879336", "s077524062" ]
u841623074
p03805
python
s991465319
s569813610
298
20
5,552
3,064
Accepted
Accepted
93.29
N,M=list(map(int,input().split())) import copy a=[0]*M b=[0]*M for i in range(M): a[i],b[i]=list(map(int,input().split())) D=[[1]] def route(D): E=[] D1=copy.deepcopy(D) for j in range(len(D)): x=D[j][-1] for i in range(M): if a[i]==x: if not b[i] in D1[j]: D[j]=copy.deepcopy(D1[j]) D[j].append(b[i]) E.append(D[j]) elif b[i]==x: if not a[i] in D1[j]: D[j]=copy.deepcopy(D1[j]) D[j].append(a[i]) E.append(D[j]) return E for i in range(N-1): D=copy.deepcopy(route(D)) print((len(D)))
def bit_DP(N,Adj): dp=[[0]*N for i in range(1<<N)] dp[1][0]=1 for S in range(1<<N): for v in range(N): if (S&(1<<v))==0: continue sub=S^(1<<v) for u in range(N): if (sub&(1<<u)) and (Adj[u][v]): dp[S][v]+=dp[sub][u] ans=sum(dp[(1<<N)-1][u] for u in range(1,N)) return ans def main(): N,M=list(map(int,input().split())) Adj=[[0]*N for i in range(N)] for _ in range(M): a,b=list(map(int,input().split())) Adj[a-1][b-1]=1 Adj[b-1][a-1]=1 ans=bit_DP(N,Adj) print(ans) if __name__=='__main__': main()
30
25
721
684
N, M = list(map(int, input().split())) import copy a = [0] * M b = [0] * M for i in range(M): a[i], b[i] = list(map(int, input().split())) D = [[1]] def route(D): E = [] D1 = copy.deepcopy(D) for j in range(len(D)): x = D[j][-1] for i in range(M): if a[i] == x: if not b[i] in D1[j]: D[j] = copy.deepcopy(D1[j]) D[j].append(b[i]) E.append(D[j]) elif b[i] == x: if not a[i] in D1[j]: D[j] = copy.deepcopy(D1[j]) D[j].append(a[i]) E.append(D[j]) return E for i in range(N - 1): D = copy.deepcopy(route(D)) print((len(D)))
def bit_DP(N, Adj): dp = [[0] * N for i in range(1 << N)] dp[1][0] = 1 for S in range(1 << N): for v in range(N): if (S & (1 << v)) == 0: continue sub = S ^ (1 << v) for u in range(N): if (sub & (1 << u)) and (Adj[u][v]): dp[S][v] += dp[sub][u] ans = sum(dp[(1 << N) - 1][u] for u in range(1, N)) return ans def main(): N, M = list(map(int, input().split())) Adj = [[0] * N for i in range(N)] for _ in range(M): a, b = list(map(int, input().split())) Adj[a - 1][b - 1] = 1 Adj[b - 1][a - 1] = 1 ans = bit_DP(N, Adj) print(ans) if __name__ == "__main__": main()
false
16.666667
[ "-N, M = list(map(int, input().split()))", "-import copy", "-", "-a = [0] * M", "-b = [0] * M", "-for i in range(M):", "- a[i], b[i] = list(map(int, input().split()))", "-D = [[1]]", "+def bit_DP(N, Adj):", "+ dp = [[0] * N for i in range(1 << N)]", "+ dp[1][0] = 1", "+ for S in range(1 << N):", "+ for v in range(N):", "+ if (S & (1 << v)) == 0:", "+ continue", "+ sub = S ^ (1 << v)", "+ for u in range(N):", "+ if (sub & (1 << u)) and (Adj[u][v]):", "+ dp[S][v] += dp[sub][u]", "+ ans = sum(dp[(1 << N) - 1][u] for u in range(1, N))", "+ return ans", "-def route(D):", "- E = []", "- D1 = copy.deepcopy(D)", "- for j in range(len(D)):", "- x = D[j][-1]", "- for i in range(M):", "- if a[i] == x:", "- if not b[i] in D1[j]:", "- D[j] = copy.deepcopy(D1[j])", "- D[j].append(b[i])", "- E.append(D[j])", "- elif b[i] == x:", "- if not a[i] in D1[j]:", "- D[j] = copy.deepcopy(D1[j])", "- D[j].append(a[i])", "- E.append(D[j])", "- return E", "+def main():", "+ N, M = list(map(int, input().split()))", "+ Adj = [[0] * N for i in range(N)]", "+ for _ in range(M):", "+ a, b = list(map(int, input().split()))", "+ Adj[a - 1][b - 1] = 1", "+ Adj[b - 1][a - 1] = 1", "+ ans = bit_DP(N, Adj)", "+ print(ans)", "-for i in range(N - 1):", "- D = copy.deepcopy(route(D))", "-print((len(D)))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.044908
0.044949
0.999075
[ "s991465319", "s569813610" ]
u367130284
p03221
python
s250170186
s152318588
728
607
72,128
45,360
Accepted
Accepted
16.62
from collections import* import sys input=sys.stdin.readline n,m=list(map(int,input().split())) d=defaultdict(list) l=[] for i in range(m): p,y=list(map(int,input().split())) l.append([p,y]) d[p].append(y) for k,v in list(d.items()): d[k]=list(enumerate(sorted(v))) d2=defaultdict(int) for k,v in list(d.items()): for s,t in v: d2[(k,t)]=s+1 for i in l: print((str(i[0]).zfill(6)+str(d2[tuple(i)]).zfill(6)))
#from numpy import* #from scipy import* from collections import* #defaultdict Counter deque from fractions import gcd from functools import* #reduce from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) from operator import mul from bisect import* #bisect_left bisect_right from heapq import* #heapify heappop heappushpop from math import factorial from copy import deepcopy import sys input=sys.stdin.readline sys.setrecursionlimit(10**6) #enumerate input def main(): n,m=list(map(int,input().split())) py=[list(map(int,input().split()))+[i]for i in range(m)] py=sorted(sorted(py,key=lambda x:x[1]),key=lambda x:x[0]) d=defaultdict(list) pre=py[0][0] num=1 for p,_,i in py: if p==pre: d[i]=[p,num] num+=1 else: num=2 pre=p d[i]=[p,1] # print(d) for i in range(m): s,t=d[i] print((str(s).zfill(6)+str(t).zfill(6))) if __name__ == '__main__': main()
20
40
435
1,053
from collections import * import sys input = sys.stdin.readline n, m = list(map(int, input().split())) d = defaultdict(list) l = [] for i in range(m): p, y = list(map(int, input().split())) l.append([p, y]) d[p].append(y) for k, v in list(d.items()): d[k] = list(enumerate(sorted(v))) d2 = defaultdict(int) for k, v in list(d.items()): for s, t in v: d2[(k, t)] = s + 1 for i in l: print((str(i[0]).zfill(6) + str(d2[tuple(i)]).zfill(6)))
# from numpy import* # from scipy import* from collections import * # defaultdict Counter deque from fractions import gcd from functools import * # reduce from itertools import * # permutations("AB",repeat=2) combinations("AB",2) product("AB",2) from operator import mul from bisect import * # bisect_left bisect_right from heapq import * # heapify heappop heappushpop from math import factorial from copy import deepcopy import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) # enumerate input def main(): n, m = list(map(int, input().split())) py = [list(map(int, input().split())) + [i] for i in range(m)] py = sorted(sorted(py, key=lambda x: x[1]), key=lambda x: x[0]) d = defaultdict(list) pre = py[0][0] num = 1 for p, _, i in py: if p == pre: d[i] = [p, num] num += 1 else: num = 2 pre = p d[i] = [p, 1] # print(d) for i in range(m): s, t = d[i] print((str(s).zfill(6) + str(t).zfill(6))) if __name__ == "__main__": main()
false
50
[ "-from collections import *", "+# from numpy import*", "+# from scipy import*", "+from collections import * # defaultdict Counter deque", "+from fractions import gcd", "+from functools import * # reduce", "+from itertools import * # permutations(\"AB\",repeat=2) combinations(\"AB\",2) product(\"AB\",2)", "+from operator import mul", "+from bisect import * # bisect_left bisect_right", "+from heapq import * # heapify heappop heappushpop", "+from math import factorial", "+from copy import deepcopy", "-n, m = list(map(int, input().split()))", "-d = defaultdict(list)", "-l = []", "-for i in range(m):", "- p, y = list(map(int, input().split()))", "- l.append([p, y])", "- d[p].append(y)", "-for k, v in list(d.items()):", "- d[k] = list(enumerate(sorted(v)))", "-d2 = defaultdict(int)", "-for k, v in list(d.items()):", "- for s, t in v:", "- d2[(k, t)] = s + 1", "-for i in l:", "- print((str(i[0]).zfill(6) + str(d2[tuple(i)]).zfill(6)))", "+sys.setrecursionlimit(10**6)", "+# enumerate input", "+def main():", "+ n, m = list(map(int, input().split()))", "+ py = [list(map(int, input().split())) + [i] for i in range(m)]", "+ py = sorted(sorted(py, key=lambda x: x[1]), key=lambda x: x[0])", "+ d = defaultdict(list)", "+ pre = py[0][0]", "+ num = 1", "+ for p, _, i in py:", "+ if p == pre:", "+ d[i] = [p, num]", "+ num += 1", "+ else:", "+ num = 2", "+ pre = p", "+ d[i] = [p, 1]", "+ # print(d)", "+ for i in range(m):", "+ s, t = d[i]", "+ print((str(s).zfill(6) + str(t).zfill(6)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.049629
0.050172
0.989184
[ "s250170186", "s152318588" ]
u670180528
p02852
python
s437880143
s181176577
155
112
14,460
10,648
Accepted
Accepted
27.74
n,m=list(map(int,input().split())) su=eval(input()) rev=su[::-1] if "1"*m in su: print((-1)) exit() dist_f_n=[float('inf')]*(n+1) dist_f_n[0]=0 for i in range(1,m+1): if rev[i]=="0": dist_f_n[i]=1 last=i if i==n: break while last<n: for i in range(last+1,last+m+1): if rev[i]=="0": dist_f_n[i]=dist_f_n[last]+1 _last=i if i==n: break last=_last cur=dist_f_n[-1] _i=0 ans=[] for i,x in enumerate(dist_f_n[::-1]): if x==cur-1: ans.append(i-_i) cur-=1 _i=i print((" ".join(map(str,ans))))
def main(): n, m = list(map(int, input().split())) rev = input()[::-1] ans = [] cur = nxt = 0 while cur < n: for i in range(cur + 1, cur + m + 1): if i==n: nxt = i break if rev[i]=="0": nxt = i if cur==nxt: print((-1)) exit() ans += [str(nxt - cur)] cur = nxt print((" ".join(ans[::-1]))) if __name__=="__main__": main()
31
22
536
373
n, m = list(map(int, input().split())) su = eval(input()) rev = su[::-1] if "1" * m in su: print((-1)) exit() dist_f_n = [float("inf")] * (n + 1) dist_f_n[0] = 0 for i in range(1, m + 1): if rev[i] == "0": dist_f_n[i] = 1 last = i if i == n: break while last < n: for i in range(last + 1, last + m + 1): if rev[i] == "0": dist_f_n[i] = dist_f_n[last] + 1 _last = i if i == n: break last = _last cur = dist_f_n[-1] _i = 0 ans = [] for i, x in enumerate(dist_f_n[::-1]): if x == cur - 1: ans.append(i - _i) cur -= 1 _i = i print((" ".join(map(str, ans))))
def main(): n, m = list(map(int, input().split())) rev = input()[::-1] ans = [] cur = nxt = 0 while cur < n: for i in range(cur + 1, cur + m + 1): if i == n: nxt = i break if rev[i] == "0": nxt = i if cur == nxt: print((-1)) exit() ans += [str(nxt - cur)] cur = nxt print((" ".join(ans[::-1]))) if __name__ == "__main__": main()
false
29.032258
[ "-n, m = list(map(int, input().split()))", "-su = eval(input())", "-rev = su[::-1]", "-if \"1\" * m in su:", "- print((-1))", "- exit()", "-dist_f_n = [float(\"inf\")] * (n + 1)", "-dist_f_n[0] = 0", "-for i in range(1, m + 1):", "- if rev[i] == \"0\":", "- dist_f_n[i] = 1", "- last = i", "- if i == n:", "- break", "-while last < n:", "- for i in range(last + 1, last + m + 1):", "- if rev[i] == \"0\":", "- dist_f_n[i] = dist_f_n[last] + 1", "- _last = i", "+def main():", "+ n, m = list(map(int, input().split()))", "+ rev = input()[::-1]", "+ ans = []", "+ cur = nxt = 0", "+ while cur < n:", "+ for i in range(cur + 1, cur + m + 1):", "+ nxt = i", "- last = _last", "-cur = dist_f_n[-1]", "-_i = 0", "-ans = []", "-for i, x in enumerate(dist_f_n[::-1]):", "- if x == cur - 1:", "- ans.append(i - _i)", "- cur -= 1", "- _i = i", "-print((\" \".join(map(str, ans))))", "+ if rev[i] == \"0\":", "+ nxt = i", "+ if cur == nxt:", "+ print((-1))", "+ exit()", "+ ans += [str(nxt - cur)]", "+ cur = nxt", "+ print((\" \".join(ans[::-1])))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.047712
0.119679
0.398671
[ "s437880143", "s181176577" ]
u484229314
p02947
python
s420585981
s858161968
1,921
514
74,200
23,904
Accepted
Accepted
73.24
def f(x): return 10 ** (ord(x) - ord('a') + 1) import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) from collections import Counter N = int(eval(input())) counter = Counter() for i in range(N): counter[sum([f(i) for i in eval(input())])] += 1 res = 0 for v in list(counter.values()): if v > 1: res += combinations_count(v, 2) print(res)
from collections import Counter N = int(eval(input())) counter = Counter() for i in range(N): counter[tuple(sorted(eval(input())))] += 1 res = 0 for v in list(counter.values()): res += v * (v - 1) / 2 print((int(res)))
22
12
431
220
def f(x): return 10 ** (ord(x) - ord("a") + 1) import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) from collections import Counter N = int(eval(input())) counter = Counter() for i in range(N): counter[sum([f(i) for i in eval(input())])] += 1 res = 0 for v in list(counter.values()): if v > 1: res += combinations_count(v, 2) print(res)
from collections import Counter N = int(eval(input())) counter = Counter() for i in range(N): counter[tuple(sorted(eval(input())))] += 1 res = 0 for v in list(counter.values()): res += v * (v - 1) / 2 print((int(res)))
false
45.454545
[ "-def f(x):", "- return 10 ** (ord(x) - ord(\"a\") + 1)", "-", "-", "-import math", "-", "-", "-def combinations_count(n, r):", "- return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))", "-", "-", "- counter[sum([f(i) for i in eval(input())])] += 1", "+ counter[tuple(sorted(eval(input())))] += 1", "- if v > 1:", "- res += combinations_count(v, 2)", "-print(res)", "+ res += v * (v - 1) / 2", "+print((int(res)))" ]
false
0.068061
0.037596
1.810315
[ "s420585981", "s858161968" ]
u296518383
p02820
python
s079457998
s240080852
222
76
44,144
4,656
Accepted
Accepted
65.77
N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) T = eval(input()) def janken(s): if s == "r": return P if s == "s": return R if s == "p": return S answer = 0 for i in range(K): j = 0 flag = 0 while i + K * j < N: if j == 0: answer += janken(T[i + K * j]) else: if T[i + K * j] != T[i + K * (j - 1)] or flag == 1: answer += janken(T[i + K * j]) flag = 0 else: flag = 1 #print(T[i + K * j], answer) j += 1 print(answer)
def win(t): if t == "g": return "p" if t == "c": return "g" if t == "p": return "c" N, K = list(map(int, input().split())) G, C, P = list(map(int, input().split())) T = input().replace("r", "g").replace("s", "c") point = {"g": G, "c": C, "p": P} check = [None] * (N + K) answer = 0 for i in range(N): w = win(T[i]) if check[i] != w: answer += point[w] check[i + K] = w print(answer)
28
23
543
430
N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) T = eval(input()) def janken(s): if s == "r": return P if s == "s": return R if s == "p": return S answer = 0 for i in range(K): j = 0 flag = 0 while i + K * j < N: if j == 0: answer += janken(T[i + K * j]) else: if T[i + K * j] != T[i + K * (j - 1)] or flag == 1: answer += janken(T[i + K * j]) flag = 0 else: flag = 1 # print(T[i + K * j], answer) j += 1 print(answer)
def win(t): if t == "g": return "p" if t == "c": return "g" if t == "p": return "c" N, K = list(map(int, input().split())) G, C, P = list(map(int, input().split())) T = input().replace("r", "g").replace("s", "c") point = {"g": G, "c": C, "p": P} check = [None] * (N + K) answer = 0 for i in range(N): w = win(T[i]) if check[i] != w: answer += point[w] check[i + K] = w print(answer)
false
17.857143
[ "-N, K = list(map(int, input().split()))", "-R, S, P = list(map(int, input().split()))", "-T = eval(input())", "+def win(t):", "+ if t == \"g\":", "+ return \"p\"", "+ if t == \"c\":", "+ return \"g\"", "+ if t == \"p\":", "+ return \"c\"", "-def janken(s):", "- if s == \"r\":", "- return P", "- if s == \"s\":", "- return R", "- if s == \"p\":", "- return S", "-", "-", "+N, K = list(map(int, input().split()))", "+G, C, P = list(map(int, input().split()))", "+T = input().replace(\"r\", \"g\").replace(\"s\", \"c\")", "+point = {\"g\": G, \"c\": C, \"p\": P}", "+check = [None] * (N + K)", "-for i in range(K):", "- j = 0", "- flag = 0", "- while i + K * j < N:", "- if j == 0:", "- answer += janken(T[i + K * j])", "- else:", "- if T[i + K * j] != T[i + K * (j - 1)] or flag == 1:", "- answer += janken(T[i + K * j])", "- flag = 0", "- else:", "- flag = 1", "- # print(T[i + K * j], answer)", "- j += 1", "+for i in range(N):", "+ w = win(T[i])", "+ if check[i] != w:", "+ answer += point[w]", "+ check[i + K] = w" ]
false
0.039785
0.041112
0.967713
[ "s079457998", "s240080852" ]
u357751375
p03030
python
s247936165
s453135430
26
24
9,172
9,204
Accepted
Accepted
7.69
n = int(eval(input())) l = [list(input().split()) for i in range(n)] s,p = [list(i) for i in zip(*l)] p = [int(i) for i in p] z = list(set(s)) z.sort() m = list(p) m.sort(reverse = True) l = [] k = 0 for i in range(len(z)): l.append(k) k += 200 o = [] for i in range(n): w = l[z.index(s[i])] w += m.index(p[i]) o.append(w) r = list(o) r.sort() for i in range(n): print((o.index(r[i]) + 1))
n = int(eval(input())) l = [] for i in range(1,n+1): s,p = input().split() t = [s,int(p),i] l.append(t) l.sort() def check(m,i): z = list(l[m:i]) z.sort(key = lambda x: x[1] , reverse = True) for j in range(i-m): print((z[j][2])) m = 0 for i in range(1,n): if l[m][0] != l[i][0]: check(m,i) m = i check(m,n)
25
18
436
368
n = int(eval(input())) l = [list(input().split()) for i in range(n)] s, p = [list(i) for i in zip(*l)] p = [int(i) for i in p] z = list(set(s)) z.sort() m = list(p) m.sort(reverse=True) l = [] k = 0 for i in range(len(z)): l.append(k) k += 200 o = [] for i in range(n): w = l[z.index(s[i])] w += m.index(p[i]) o.append(w) r = list(o) r.sort() for i in range(n): print((o.index(r[i]) + 1))
n = int(eval(input())) l = [] for i in range(1, n + 1): s, p = input().split() t = [s, int(p), i] l.append(t) l.sort() def check(m, i): z = list(l[m:i]) z.sort(key=lambda x: x[1], reverse=True) for j in range(i - m): print((z[j][2])) m = 0 for i in range(1, n): if l[m][0] != l[i][0]: check(m, i) m = i check(m, n)
false
28
[ "-l = [list(input().split()) for i in range(n)]", "-s, p = [list(i) for i in zip(*l)]", "-p = [int(i) for i in p]", "-z = list(set(s))", "-z.sort()", "-m = list(p)", "-m.sort(reverse=True)", "-k = 0", "-for i in range(len(z)):", "- l.append(k)", "- k += 200", "-o = []", "-for i in range(n):", "- w = l[z.index(s[i])]", "- w += m.index(p[i])", "- o.append(w)", "-r = list(o)", "-r.sort()", "-for i in range(n):", "- print((o.index(r[i]) + 1))", "+for i in range(1, n + 1):", "+ s, p = input().split()", "+ t = [s, int(p), i]", "+ l.append(t)", "+l.sort()", "+", "+", "+def check(m, i):", "+ z = list(l[m:i])", "+ z.sort(key=lambda x: x[1], reverse=True)", "+ for j in range(i - m):", "+ print((z[j][2]))", "+", "+", "+m = 0", "+for i in range(1, n):", "+ if l[m][0] != l[i][0]:", "+ check(m, i)", "+ m = i", "+check(m, n)" ]
false
0.159055
0.115359
1.378782
[ "s247936165", "s453135430" ]
u936985471
p02883
python
s825695518
s907241868
556
326
37,280
53,224
Accepted
Accepted
41.37
import sys readline = sys.stdin.readline import numpy as np N,K = list(map(int,readline().split())) A = np.array(sorted(list(map(int,readline().split())))) F = np.array(sorted(list(map(int,readline().split())),reverse = True)) ok = A[-1] * F[0] ng = -1 def isOk(x): # 時間がxになるためには、A_iをx/F_i以下まで減らす必要がある return A.sum() - np.minimum(A,x // F).sum() <= K while (ok - ng)>1: mid = (ok + ng) // 2 if isOk(mid): ok = mid else: ng = mid print(ok)
import sys readline = sys.stdin.readline import numpy as np N,K = list(map(int,readline().split())) A = np.sort(np.array(readline().split(), dtype = int)) F = np.sort(np.array(readline().split(), dtype = int))[::-1] # X秒で完食できるか二分探索 ng = -1 ok = F[0] * A[-1] def isOk(x): return A.sum() - np.minimum(A, x // F).sum() <= K while abs(ok - ng) > 1: mid = abs(ok + ng) // 2 if isOk(mid): ok = mid else: ng = mid print(ok)
23
26
479
466
import sys readline = sys.stdin.readline import numpy as np N, K = list(map(int, readline().split())) A = np.array(sorted(list(map(int, readline().split())))) F = np.array(sorted(list(map(int, readline().split())), reverse=True)) ok = A[-1] * F[0] ng = -1 def isOk(x): # 時間がxになるためには、A_iをx/F_i以下まで減らす必要がある return A.sum() - np.minimum(A, x // F).sum() <= K while (ok - ng) > 1: mid = (ok + ng) // 2 if isOk(mid): ok = mid else: ng = mid print(ok)
import sys readline = sys.stdin.readline import numpy as np N, K = list(map(int, readline().split())) A = np.sort(np.array(readline().split(), dtype=int)) F = np.sort(np.array(readline().split(), dtype=int))[::-1] # X秒で完食できるか二分探索 ng = -1 ok = F[0] * A[-1] def isOk(x): return A.sum() - np.minimum(A, x // F).sum() <= K while abs(ok - ng) > 1: mid = abs(ok + ng) // 2 if isOk(mid): ok = mid else: ng = mid print(ok)
false
11.538462
[ "-A = np.array(sorted(list(map(int, readline().split()))))", "-F = np.array(sorted(list(map(int, readline().split())), reverse=True))", "-ok = A[-1] * F[0]", "+A = np.sort(np.array(readline().split(), dtype=int))", "+F = np.sort(np.array(readline().split(), dtype=int))[::-1]", "+# X秒で完食できるか二分探索", "+ok = F[0] * A[-1]", "- # 時間がxになるためには、A_iをx/F_i以下まで減らす必要がある", "-while (ok - ng) > 1:", "- mid = (ok + ng) // 2", "+while abs(ok - ng) > 1:", "+ mid = abs(ok + ng) // 2" ]
false
0.256705
0.304122
0.844084
[ "s825695518", "s907241868" ]
u261103969
p02683
python
s908764784
s484386510
89
82
68,344
68,708
Accepted
Accepted
7.87
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n, m, x = list(map(int, readline().split())) c = [] a = [] for i in range(n): temp = list(map(int, readline().split())) ctemp = temp[0] atemp = temp[1:] c.append(ctemp) a.append(atemp) ans = INF for bit in range(1 << n): money = 0 learn = [0] * m for i in range(n): if bit >> i & 1: money += c[i] for j, le in enumerate(a[i]): learn[j] += le ok = True for j in range(m): if learn[j] < x: ok = False if ok: ans = min(ans, money) if ans == INF: ans = -1 print(ans) if __name__ == '__main__': main()
def check(learn_total): for i in range(m): if learn_total[i] < x: return False return True def calc_price(bit): price_total = 0 # 値段の合計 learn_total = [0] * m # 理解度 for i in range(n): if (bit >> i) & 1: # i桁目が0か1か見て、i番目を買うか買わないか判定します price_total += c[i] # 買うので、i番目の値段を加算します learn = a[i] # 「i番目の参考書を読んで増える、各アルゴリズムの理解度」のリストです for j, le in enumerate(learn): # 理解度を足します。 enumerateを使うと、range(n)よりスマートです learn_total[j] += le # 条件を満たすか、check関数で確認します if check(learn_total): return price_total else: return INF if __name__ == '__main__': INF = float("inf") n, m, x = list(map(int, input().split())) # 空のリストを作って、appendで追加していきます c = [] # 参考書の値段です a = [] # 各参考書に入る理解度です for i in range(n): c_temp, *a_temp = list(map(int, input().split())) # こうすると、2つ目以降をリストで受け取れます c.append(c_temp) a.append(a_temp) ans = INF for bit in range(1 << n): price = calc_price(bit) # 条件を満たすなら価格、満たさないならINFが返ってきます ans = min(ans, price) # 答えを更新します if ans == INF: print((-1)) else: print(ans)
45
49
908
1,246
import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): n, m, x = list(map(int, readline().split())) c = [] a = [] for i in range(n): temp = list(map(int, readline().split())) ctemp = temp[0] atemp = temp[1:] c.append(ctemp) a.append(atemp) ans = INF for bit in range(1 << n): money = 0 learn = [0] * m for i in range(n): if bit >> i & 1: money += c[i] for j, le in enumerate(a[i]): learn[j] += le ok = True for j in range(m): if learn[j] < x: ok = False if ok: ans = min(ans, money) if ans == INF: ans = -1 print(ans) if __name__ == "__main__": main()
def check(learn_total): for i in range(m): if learn_total[i] < x: return False return True def calc_price(bit): price_total = 0 # 値段の合計 learn_total = [0] * m # 理解度 for i in range(n): if (bit >> i) & 1: # i桁目が0か1か見て、i番目を買うか買わないか判定します price_total += c[i] # 買うので、i番目の値段を加算します learn = a[i] # 「i番目の参考書を読んで増える、各アルゴリズムの理解度」のリストです for j, le in enumerate(learn): # 理解度を足します。 enumerateを使うと、range(n)よりスマートです learn_total[j] += le # 条件を満たすか、check関数で確認します if check(learn_total): return price_total else: return INF if __name__ == "__main__": INF = float("inf") n, m, x = list(map(int, input().split())) # 空のリストを作って、appendで追加していきます c = [] # 参考書の値段です a = [] # 各参考書に入る理解度です for i in range(n): c_temp, *a_temp = list(map(int, input().split())) # こうすると、2つ目以降をリストで受け取れます c.append(c_temp) a.append(a_temp) ans = INF for bit in range(1 << n): price = calc_price(bit) # 条件を満たすなら価格、満たさないならINFが返ってきます ans = min(ans, price) # 答えを更新します if ans == INF: print((-1)) else: print(ans)
false
8.163265
[ "-import sys", "-", "-readline = sys.stdin.readline", "-MOD = 10**9 + 7", "-INF = float(\"INF\")", "-sys.setrecursionlimit(10**5)", "+def check(learn_total):", "+ for i in range(m):", "+ if learn_total[i] < x:", "+ return False", "+ return True", "-def main():", "- n, m, x = list(map(int, readline().split()))", "- c = []", "- a = []", "+def calc_price(bit):", "+ price_total = 0 # 値段の合計", "+ learn_total = [0] * m # 理解度", "- temp = list(map(int, readline().split()))", "- ctemp = temp[0]", "- atemp = temp[1:]", "- c.append(ctemp)", "- a.append(atemp)", "- ans = INF", "- for bit in range(1 << n):", "- money = 0", "- learn = [0] * m", "- for i in range(n):", "- if bit >> i & 1:", "- money += c[i]", "- for j, le in enumerate(a[i]):", "- learn[j] += le", "- ok = True", "- for j in range(m):", "- if learn[j] < x:", "- ok = False", "- if ok:", "- ans = min(ans, money)", "- if ans == INF:", "- ans = -1", "- print(ans)", "+ if (bit >> i) & 1: # i桁目が0か1か見て、i番目を買うか買わないか判定します", "+ price_total += c[i] # 買うので、i番目の値段を加算します", "+ learn = a[i] # 「i番目の参考書を読んで増える、各アルゴリズムの理解度」のリストです", "+ for j, le in enumerate(learn): # 理解度を足します。 enumerateを使うと、range(n)よりスマートです", "+ learn_total[j] += le", "+ # 条件を満たすか、check関数で確認します", "+ if check(learn_total):", "+ return price_total", "+ else:", "+ return INF", "- main()", "+ INF = float(\"inf\")", "+ n, m, x = list(map(int, input().split()))", "+ # 空のリストを作って、appendで追加していきます", "+ c = [] # 参考書の値段です", "+ a = [] # 各参考書に入る理解度です", "+ for i in range(n):", "+ c_temp, *a_temp = list(map(int, input().split())) # こうすると、2つ目以降をリストで受け取れます", "+ c.append(c_temp)", "+ a.append(a_temp)", "+ ans = INF", "+ for bit in range(1 << n):", "+ price = calc_price(bit) # 条件を満たすなら価格、満たさないならINFが返ってきます", "+ ans = min(ans, price) # 答えを更新します", "+ if ans == INF:", "+ print((-1))", "+ else:", "+ print(ans)" ]
false
0.075368
0.038548
1.955171
[ "s908764784", "s484386510" ]
u218843509
p02651
python
s236226419
s869315012
306
93
70,816
68,644
Accepted
Accepted
69.61
import sys def input(): return sys.stdin.readline()[:-1] def least_bit_set(x): return x & (-x) def delete_zeros_from(values, start): i = start for j in range(start, len(values)): if values[j] != 0: values[i] = values[j] i += 1 del values[i:] def eliminate(values): values = list(values) i = 0 while True: delete_zeros_from(values, i) if i >= len(values): return values j = i for k in range(i + 1, len(values)): if least_bit_set(values[k]) < least_bit_set(values[j]): j = k values[i], values[j] = (values[j], values[i]) for k in range(i + 1, len(values)): if least_bit_set(values[k]) == least_bit_set(values[i]): values[k] ^= values[i] i += 1 def in_span(x, eliminated_values): for y in eliminated_values: if least_bit_set(y) & x != 0: x ^= y return x == 0 #values = [1, 5, 8, 2, 10] #eliminated_values = eliminate(values) #print(eliminated_values) #x = int(input()) #print(in_span(x, eliminated_values)) t = int(eval(input())) for _ in range(t): n = int(eval(input())) a = list(map(int, input().split())) s = eval(input()) values = [] ok = True for i in range(n-1, -1, -1): if s[i] == "0": values.append(a[i]) else: elim = eliminate(values) if not in_span(a[i], elim): ok = False break if ok: print((0)) else: print((1))
t = int(eval(input())) for _ in range(t): n = int(eval(input())) a = list(map(int, input().split())) s = eval(input()) basis = [] ans = 0 for i in range(n-1, -1, -1): if s[i] == "0": for b in basis: a[i] = min(a[i], a[i]^b) if a[i]: basis.append(a[i]) else: for b in basis: a[i] = min(a[i], a[i]^b) if a[i]: ans = 1 break print(ans)
68
20
1,363
376
import sys def input(): return sys.stdin.readline()[:-1] def least_bit_set(x): return x & (-x) def delete_zeros_from(values, start): i = start for j in range(start, len(values)): if values[j] != 0: values[i] = values[j] i += 1 del values[i:] def eliminate(values): values = list(values) i = 0 while True: delete_zeros_from(values, i) if i >= len(values): return values j = i for k in range(i + 1, len(values)): if least_bit_set(values[k]) < least_bit_set(values[j]): j = k values[i], values[j] = (values[j], values[i]) for k in range(i + 1, len(values)): if least_bit_set(values[k]) == least_bit_set(values[i]): values[k] ^= values[i] i += 1 def in_span(x, eliminated_values): for y in eliminated_values: if least_bit_set(y) & x != 0: x ^= y return x == 0 # values = [1, 5, 8, 2, 10] # eliminated_values = eliminate(values) # print(eliminated_values) # x = int(input()) # print(in_span(x, eliminated_values)) t = int(eval(input())) for _ in range(t): n = int(eval(input())) a = list(map(int, input().split())) s = eval(input()) values = [] ok = True for i in range(n - 1, -1, -1): if s[i] == "0": values.append(a[i]) else: elim = eliminate(values) if not in_span(a[i], elim): ok = False break if ok: print((0)) else: print((1))
t = int(eval(input())) for _ in range(t): n = int(eval(input())) a = list(map(int, input().split())) s = eval(input()) basis = [] ans = 0 for i in range(n - 1, -1, -1): if s[i] == "0": for b in basis: a[i] = min(a[i], a[i] ^ b) if a[i]: basis.append(a[i]) else: for b in basis: a[i] = min(a[i], a[i] ^ b) if a[i]: ans = 1 break print(ans)
false
70.588235
[ "-import sys", "-", "-", "-def input():", "- return sys.stdin.readline()[:-1]", "-", "-", "-def least_bit_set(x):", "- return x & (-x)", "-", "-", "-def delete_zeros_from(values, start):", "- i = start", "- for j in range(start, len(values)):", "- if values[j] != 0:", "- values[i] = values[j]", "- i += 1", "- del values[i:]", "-", "-", "-def eliminate(values):", "- values = list(values)", "- i = 0", "- while True:", "- delete_zeros_from(values, i)", "- if i >= len(values):", "- return values", "- j = i", "- for k in range(i + 1, len(values)):", "- if least_bit_set(values[k]) < least_bit_set(values[j]):", "- j = k", "- values[i], values[j] = (values[j], values[i])", "- for k in range(i + 1, len(values)):", "- if least_bit_set(values[k]) == least_bit_set(values[i]):", "- values[k] ^= values[i]", "- i += 1", "-", "-", "-def in_span(x, eliminated_values):", "- for y in eliminated_values:", "- if least_bit_set(y) & x != 0:", "- x ^= y", "- return x == 0", "-", "-", "-# values = [1, 5, 8, 2, 10]", "-# eliminated_values = eliminate(values)", "-# print(eliminated_values)", "-# x = int(input())", "-# print(in_span(x, eliminated_values))", "- values = []", "- ok = True", "+ basis = []", "+ ans = 0", "- values.append(a[i])", "+ for b in basis:", "+ a[i] = min(a[i], a[i] ^ b)", "+ if a[i]:", "+ basis.append(a[i])", "- elim = eliminate(values)", "- if not in_span(a[i], elim):", "- ok = False", "+ for b in basis:", "+ a[i] = min(a[i], a[i] ^ b)", "+ if a[i]:", "+ ans = 1", "- if ok:", "- print((0))", "- else:", "- print((1))", "+ print(ans)" ]
false
0.068441
0.037275
1.836102
[ "s236226419", "s869315012" ]
u562935282
p03164
python
s410511017
s786038037
1,992
991
321,648
311,048
Accepted
Accepted
50.25
import sys input = sys.stdin.readline N, W = list(map(int, input().split())) w, v = [], [] for _ in range(N): tw, tv = list(map(int, input().split())) w.append(tw) v.append(tv) dp = [[float('inf') for _ in range(sum(v) + 1)] for _ in range(N + 1)] dp[0][0] = 0 # dp[何番目までの品物で][この価値以下を達成する]:=最小の重量 for i in range(N): for j in range(sum(v) + 1): if j - v[i] >= 0: dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]) else: dp[i + 1][j] = dp[i][j] for j in sorted(list(range(sum(v) + 1)), reverse=True): t = dp[N][j] if t <= W: print(j) break
inf = float('inf') n, w = list(map(int, input().split())) wv = tuple(tuple(map(int, input().split())) for _ in range(n)) dp = tuple([inf] * (pow(10, 3) * n + 1) for _ in range(n + 1)) dp[0][0] = 0 for ind, (wi, vi) in enumerate(wv, 1): for v in range(pow(10, 3) * n + 1): if vi <= v: dp[ind][v] = min(dp[ind - 1][v], dp[ind - 1][v - vi] + wi) else: dp[ind][v] = dp[ind - 1][v] for v in range(pow(10, 3) * n, 0, -1): if dp[n][v] <= w: print(v) exit()
27
19
633
530
import sys input = sys.stdin.readline N, W = list(map(int, input().split())) w, v = [], [] for _ in range(N): tw, tv = list(map(int, input().split())) w.append(tw) v.append(tv) dp = [[float("inf") for _ in range(sum(v) + 1)] for _ in range(N + 1)] dp[0][0] = 0 # dp[何番目までの品物で][この価値以下を達成する]:=最小の重量 for i in range(N): for j in range(sum(v) + 1): if j - v[i] >= 0: dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]) else: dp[i + 1][j] = dp[i][j] for j in sorted(list(range(sum(v) + 1)), reverse=True): t = dp[N][j] if t <= W: print(j) break
inf = float("inf") n, w = list(map(int, input().split())) wv = tuple(tuple(map(int, input().split())) for _ in range(n)) dp = tuple([inf] * (pow(10, 3) * n + 1) for _ in range(n + 1)) dp[0][0] = 0 for ind, (wi, vi) in enumerate(wv, 1): for v in range(pow(10, 3) * n + 1): if vi <= v: dp[ind][v] = min(dp[ind - 1][v], dp[ind - 1][v - vi] + wi) else: dp[ind][v] = dp[ind - 1][v] for v in range(pow(10, 3) * n, 0, -1): if dp[n][v] <= w: print(v) exit()
false
29.62963
[ "-import sys", "-", "-input = sys.stdin.readline", "-N, W = list(map(int, input().split()))", "-w, v = [], []", "-for _ in range(N):", "- tw, tv = list(map(int, input().split()))", "- w.append(tw)", "- v.append(tv)", "-dp = [[float(\"inf\") for _ in range(sum(v) + 1)] for _ in range(N + 1)]", "+inf = float(\"inf\")", "+n, w = list(map(int, input().split()))", "+wv = tuple(tuple(map(int, input().split())) for _ in range(n))", "+dp = tuple([inf] * (pow(10, 3) * n + 1) for _ in range(n + 1))", "-# dp[何番目までの品物で][この価値以下を達成する]:=最小の重量", "-for i in range(N):", "- for j in range(sum(v) + 1):", "- if j - v[i] >= 0:", "- dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])", "+for ind, (wi, vi) in enumerate(wv, 1):", "+ for v in range(pow(10, 3) * n + 1):", "+ if vi <= v:", "+ dp[ind][v] = min(dp[ind - 1][v], dp[ind - 1][v - vi] + wi)", "- dp[i + 1][j] = dp[i][j]", "-for j in sorted(list(range(sum(v) + 1)), reverse=True):", "- t = dp[N][j]", "- if t <= W:", "- print(j)", "- break", "+ dp[ind][v] = dp[ind - 1][v]", "+for v in range(pow(10, 3) * n, 0, -1):", "+ if dp[n][v] <= w:", "+ print(v)", "+ exit()" ]
false
0.036823
0.053636
0.686538
[ "s410511017", "s786038037" ]
u028973125
p03575
python
s228335327
s583784323
204
35
40,944
9,448
Accepted
Accepted
82.84
import sys 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()) N, M = list(map(int, sys.stdin.readline().rstrip().split())) edges = [] for _ in range(M): a, b = list(map(int, sys.stdin.readline().rstrip().split())) edges.append((a-1, b-1)) ans = 0 for i in range(M): uf = UnionFind(N) for j, (a, b) in enumerate(edges): if i == j: continue uf.union(a, b) if uf.group_count() != 1: ans += 1 print(ans)
import sys from collections import deque input = sys.stdin.readline N, M = list(map(int, input().split())) edges = [[] for _ in range(N)] edge_set = set() for _ in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 edges[a].append(b) edges[b].append(a) edge_set.add((a, b)) ans = 0 for a, b in edge_set: q = deque() q.append(0) visited = set() while q: p = q.popleft() if p in visited: continue visited.add(p) for np in edges[p]: if (p, np) == (a, b) or (np, p) == (a, b): continue q.append(np) if len(visited) != N: ans += 1 print(ans)
66
35
1,607
711
import sys 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()) N, M = list(map(int, sys.stdin.readline().rstrip().split())) edges = [] for _ in range(M): a, b = list(map(int, sys.stdin.readline().rstrip().split())) edges.append((a - 1, b - 1)) ans = 0 for i in range(M): uf = UnionFind(N) for j, (a, b) in enumerate(edges): if i == j: continue uf.union(a, b) if uf.group_count() != 1: ans += 1 print(ans)
import sys from collections import deque input = sys.stdin.readline N, M = list(map(int, input().split())) edges = [[] for _ in range(N)] edge_set = set() for _ in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 edges[a].append(b) edges[b].append(a) edge_set.add((a, b)) ans = 0 for a, b in edge_set: q = deque() q.append(0) visited = set() while q: p = q.popleft() if p in visited: continue visited.add(p) for np in edges[p]: if (p, np) == (a, b) or (np, p) == (a, b): continue q.append(np) if len(visited) != N: ans += 1 print(ans)
false
46.969697
[ "+from collections import deque", "-", "-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())", "-", "-", "-N, M = list(map(int, sys.stdin.readline().rstrip().split()))", "-edges = []", "+input = sys.stdin.readline", "+N, M = list(map(int, input().split()))", "+edges = [[] for _ in range(N)]", "+edge_set = set()", "- a, b = list(map(int, sys.stdin.readline().rstrip().split()))", "- edges.append((a - 1, b - 1))", "+ a, b = list(map(int, input().split()))", "+ a -= 1", "+ b -= 1", "+ edges[a].append(b)", "+ edges[b].append(a)", "+ edge_set.add((a, b))", "-for i in range(M):", "- uf = UnionFind(N)", "- for j, (a, b) in enumerate(edges):", "- if i == j:", "+for a, b in edge_set:", "+ q = deque()", "+ q.append(0)", "+ visited = set()", "+ while q:", "+ p = q.popleft()", "+ if p in visited:", "- uf.union(a, b)", "- if uf.group_count() != 1:", "+ visited.add(p)", "+ for np in edges[p]:", "+ if (p, np) == (a, b) or (np, p) == (a, b):", "+ continue", "+ q.append(np)", "+ if len(visited) != N:" ]
false
0.045697
0.007492
6.099808
[ "s228335327", "s583784323" ]
u576432509
p03240
python
s386652728
s708564673
36
31
3,064
3,064
Accepted
Accepted
13.89
def abs(x1,x2): if x1>x2: return x1-x2 else: return x2-x1 n=int(eval(input())) x=[] y=[] h=[] for i in range(n): xi,yi,hi=list(map(int,input().split())) x.append(xi) y.append(yi) h.append(hi) hmax=h[0] xhmax=x[0] yhmax=y[0] ihmax=0 for i in range(n): if hmax<h[i]: hmax=h[i] xhmax=x[i] yhmax=y[i] ihmax=i for cx in range(101): for cy in range(101): hh=hmax+abs(xhmax,cx)+abs(yhmax,cy) yesno="yes" for i in range(n): if h[i]!=max(hh-abs(x[i],cx)-abs(y[i],cy),0): yesno="no" break if yesno=="yes": print((cx,cy,hh)) break if yesno=="yes": break
cc=0 if cc==0: n=int(eval(input())) xyh=[[0]*3 for i in range(n)] for i in range(n): xyh[i]=list(map(int,input().split())) if xyh[i][2]>=1: px=xyh[i][0] py=xyh[i][1] ph=xyh[i][2] else: n=4 px=3 py=2 ph=5 xyh=[[0]*3 for i in range(n)] xyh[0]=[2,3,5] xyh[1]=[2,1,5] xyh[2]=[1,2,5] xyh[3]=[3,2,5] yn="" for cx in range(102): for cy in range(102): h=ph+abs(px-cx)+abs(py-cy) yn="" for i in range(n): if xyh[i][2]!=max(0,h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)): yn="No" break if yn=="No": # print(cx,cy,h,i,xyh[i][2],h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)) continue else: # print("1:",cx,cy,i,xyh[i][2],h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)) yn="Yes" break # print("2:",yn,cx,cy,h,i,xyh[i][2],h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)) if yn=="Yes": break print((cx,cy,h))
42
45
774
1,083
def abs(x1, x2): if x1 > x2: return x1 - x2 else: return x2 - x1 n = int(eval(input())) x = [] y = [] h = [] for i in range(n): xi, yi, hi = list(map(int, input().split())) x.append(xi) y.append(yi) h.append(hi) hmax = h[0] xhmax = x[0] yhmax = y[0] ihmax = 0 for i in range(n): if hmax < h[i]: hmax = h[i] xhmax = x[i] yhmax = y[i] ihmax = i for cx in range(101): for cy in range(101): hh = hmax + abs(xhmax, cx) + abs(yhmax, cy) yesno = "yes" for i in range(n): if h[i] != max(hh - abs(x[i], cx) - abs(y[i], cy), 0): yesno = "no" break if yesno == "yes": print((cx, cy, hh)) break if yesno == "yes": break
cc = 0 if cc == 0: n = int(eval(input())) xyh = [[0] * 3 for i in range(n)] for i in range(n): xyh[i] = list(map(int, input().split())) if xyh[i][2] >= 1: px = xyh[i][0] py = xyh[i][1] ph = xyh[i][2] else: n = 4 px = 3 py = 2 ph = 5 xyh = [[0] * 3 for i in range(n)] xyh[0] = [2, 3, 5] xyh[1] = [2, 1, 5] xyh[2] = [1, 2, 5] xyh[3] = [3, 2, 5] yn = "" for cx in range(102): for cy in range(102): h = ph + abs(px - cx) + abs(py - cy) yn = "" for i in range(n): if xyh[i][2] != max(0, h - abs(xyh[i][0] - cx) - abs(xyh[i][1] - cy)): yn = "No" break if yn == "No": # print(cx,cy,h,i,xyh[i][2],h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)) continue else: # print("1:",cx,cy,i,xyh[i][2],h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)) yn = "Yes" break # print("2:",yn,cx,cy,h,i,xyh[i][2],h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)) if yn == "Yes": break print((cx, cy, h))
false
6.666667
[ "-def abs(x1, x2):", "- if x1 > x2:", "- return x1 - x2", "- else:", "- return x2 - x1", "-", "-", "-n = int(eval(input()))", "-x = []", "-y = []", "-h = []", "-for i in range(n):", "- xi, yi, hi = list(map(int, input().split()))", "- x.append(xi)", "- y.append(yi)", "- h.append(hi)", "-hmax = h[0]", "-xhmax = x[0]", "-yhmax = y[0]", "-ihmax = 0", "-for i in range(n):", "- if hmax < h[i]:", "- hmax = h[i]", "- xhmax = x[i]", "- yhmax = y[i]", "- ihmax = i", "-for cx in range(101):", "- for cy in range(101):", "- hh = hmax + abs(xhmax, cx) + abs(yhmax, cy)", "- yesno = \"yes\"", "+cc = 0", "+if cc == 0:", "+ n = int(eval(input()))", "+ xyh = [[0] * 3 for i in range(n)]", "+ for i in range(n):", "+ xyh[i] = list(map(int, input().split()))", "+ if xyh[i][2] >= 1:", "+ px = xyh[i][0]", "+ py = xyh[i][1]", "+ ph = xyh[i][2]", "+else:", "+ n = 4", "+ px = 3", "+ py = 2", "+ ph = 5", "+ xyh = [[0] * 3 for i in range(n)]", "+ xyh[0] = [2, 3, 5]", "+ xyh[1] = [2, 1, 5]", "+ xyh[2] = [1, 2, 5]", "+ xyh[3] = [3, 2, 5]", "+yn = \"\"", "+for cx in range(102):", "+ for cy in range(102):", "+ h = ph + abs(px - cx) + abs(py - cy)", "+ yn = \"\"", "- if h[i] != max(hh - abs(x[i], cx) - abs(y[i], cy), 0):", "- yesno = \"no\"", "+ if xyh[i][2] != max(0, h - abs(xyh[i][0] - cx) - abs(xyh[i][1] - cy)):", "+ yn = \"No\"", "- if yesno == \"yes\":", "- print((cx, cy, hh))", "+ if yn == \"No\":", "+ # print(cx,cy,h,i,xyh[i][2],h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy))", "+ continue", "+ else:", "+ # print(\"1:\",cx,cy,i,xyh[i][2],h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy))", "+ yn = \"Yes\"", "- if yesno == \"yes\":", "+ # print(\"2:\",yn,cx,cy,h,i,xyh[i][2],h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy))", "+ if yn == \"Yes\":", "+print((cx, cy, h))" ]
false
0.087494
0.057142
1.531162
[ "s386652728", "s708564673" ]
u124498235
p03645
python
s585646419
s600133216
915
614
71,128
6,312
Accepted
Accepted
32.9
n, m = list(map(int, input().split())) ab = [] c = [] for i in range(m): a, b = list(map(int, input().split())) if a == 1: ab.append(b) if b == n: c.append(a) if len(set(ab) & set(c)) == 0: print ("IMPOSSIBLE") else: print ("POSSIBLE")
n, m = list(map(int, input().split())) c = [False for i in range(200001)] d = [False for i in range(200001)] for i in range(m): a, b = list(map(int, input().split())) if a == 1: c[b] = True if b == n: d[a] = True for i in range(200001): if c[i] and d[i]: print ("POSSIBLE") exit() print ("IMPOSSIBLE")
13
14
244
314
n, m = list(map(int, input().split())) ab = [] c = [] for i in range(m): a, b = list(map(int, input().split())) if a == 1: ab.append(b) if b == n: c.append(a) if len(set(ab) & set(c)) == 0: print("IMPOSSIBLE") else: print("POSSIBLE")
n, m = list(map(int, input().split())) c = [False for i in range(200001)] d = [False for i in range(200001)] for i in range(m): a, b = list(map(int, input().split())) if a == 1: c[b] = True if b == n: d[a] = True for i in range(200001): if c[i] and d[i]: print("POSSIBLE") exit() print("IMPOSSIBLE")
false
7.142857
[ "-ab = []", "-c = []", "+c = [False for i in range(200001)]", "+d = [False for i in range(200001)]", "- ab.append(b)", "+ c[b] = True", "- c.append(a)", "-if len(set(ab) & set(c)) == 0:", "- print(\"IMPOSSIBLE\")", "-else:", "- print(\"POSSIBLE\")", "+ d[a] = True", "+for i in range(200001):", "+ if c[i] and d[i]:", "+ print(\"POSSIBLE\")", "+ exit()", "+print(\"IMPOSSIBLE\")" ]
false
0.043973
0.069418
0.633462
[ "s585646419", "s600133216" ]
u427344224
p03252
python
s359452806
s096642303
279
121
3,632
3,632
Accepted
Accepted
56.63
S = eval(input()) T = eval(input()) S_dic = [-1 for _ in range(26)] T_dic = [-1 for _ in range(26)] alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] for i in range(len(S)): s = S[i] t = T[i] si = alphabet.index(s) ti = alphabet.index(t) if S_dic[si] == -1: S_dic[si] = ti elif S_dic[si] != ti: print("No") exit() if T_dic[ti] == -1: T_dic[ti] = si elif T_dic[ti] != si: print("No") exit() print("Yes")
S = eval(input()) T = eval(input()) S_dic = {} T_dic = {} for i in range(len(S)): s = S[i] t = T[i] if s in S_dic: S_dic[s] += 1 else: S_dic[s] = 1 if t in T_dic: T_dic[t] +=1 else: T_dic[t] = 1 S_dic = sorted(list(S_dic.items()), key= lambda x:x[1]) T_dic = sorted(list(T_dic.items()), key=lambda x:x[1]) f = True if len(S_dic) >= len(T_dic): length = len(T_dic) else: length = len(S_dic) for i in range(length): s = S_dic[i][1] t = T_dic[i][1] if s != t: f = False if f: print("Yes") else: print("No")
28
36
618
612
S = eval(input()) T = eval(input()) S_dic = [-1 for _ in range(26)] T_dic = [-1 for _ in range(26)] alphabet = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] for i in range(len(S)): s = S[i] t = T[i] si = alphabet.index(s) ti = alphabet.index(t) if S_dic[si] == -1: S_dic[si] = ti elif S_dic[si] != ti: print("No") exit() if T_dic[ti] == -1: T_dic[ti] = si elif T_dic[ti] != si: print("No") exit() print("Yes")
S = eval(input()) T = eval(input()) S_dic = {} T_dic = {} for i in range(len(S)): s = S[i] t = T[i] if s in S_dic: S_dic[s] += 1 else: S_dic[s] = 1 if t in T_dic: T_dic[t] += 1 else: T_dic[t] = 1 S_dic = sorted(list(S_dic.items()), key=lambda x: x[1]) T_dic = sorted(list(T_dic.items()), key=lambda x: x[1]) f = True if len(S_dic) >= len(T_dic): length = len(T_dic) else: length = len(S_dic) for i in range(length): s = S_dic[i][1] t = T_dic[i][1] if s != t: f = False if f: print("Yes") else: print("No")
false
22.222222
[ "-S_dic = [-1 for _ in range(26)]", "-T_dic = [-1 for _ in range(26)]", "-alphabet = [", "- \"a\",", "- \"b\",", "- \"c\",", "- \"d\",", "- \"e\",", "- \"f\",", "- \"g\",", "- \"h\",", "- \"i\",", "- \"j\",", "- \"k\",", "- \"l\",", "- \"m\",", "- \"n\",", "- \"o\",", "- \"p\",", "- \"q\",", "- \"r\",", "- \"s\",", "- \"t\",", "- \"u\",", "- \"v\",", "- \"w\",", "- \"x\",", "- \"y\",", "- \"z\",", "-]", "+S_dic = {}", "+T_dic = {}", "- si = alphabet.index(s)", "- ti = alphabet.index(t)", "- if S_dic[si] == -1:", "- S_dic[si] = ti", "- elif S_dic[si] != ti:", "- print(\"No\")", "- exit()", "- if T_dic[ti] == -1:", "- T_dic[ti] = si", "- elif T_dic[ti] != si:", "- print(\"No\")", "- exit()", "-print(\"Yes\")", "+ if s in S_dic:", "+ S_dic[s] += 1", "+ else:", "+ S_dic[s] = 1", "+ if t in T_dic:", "+ T_dic[t] += 1", "+ else:", "+ T_dic[t] = 1", "+S_dic = sorted(list(S_dic.items()), key=lambda x: x[1])", "+T_dic = sorted(list(T_dic.items()), key=lambda x: x[1])", "+f = True", "+if len(S_dic) >= len(T_dic):", "+ length = len(T_dic)", "+else:", "+ length = len(S_dic)", "+for i in range(length):", "+ s = S_dic[i][1]", "+ t = T_dic[i][1]", "+ if s != t:", "+ f = False", "+if f:", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.037357
0.04494
0.831271
[ "s359452806", "s096642303" ]
u263830634
p03680
python
s436993402
s489654403
245
93
7,960
7,852
Accepted
Accepted
62.04
N = int(eval(input())) a = [] for _ in range(N): a += [int(eval(input()))] lst = [0] * N flag = True i = 0 count = 0 while flag: if lst[i] == 1: print((-1)) exit() elif a[i] == 2: print((count + 1)) exit() else: lst[i] = 1 i = a[i] - 1 count += 1
import sys input = sys.stdin.readline N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] check = [True] * (N + 1) count = 0 tmp = 1 while check[tmp]: count += 1 check[tmp] = False if A[tmp - 1] == 2: print (count) exit() tmp = A[tmp - 1] print((-1))
22
19
329
305
N = int(eval(input())) a = [] for _ in range(N): a += [int(eval(input()))] lst = [0] * N flag = True i = 0 count = 0 while flag: if lst[i] == 1: print((-1)) exit() elif a[i] == 2: print((count + 1)) exit() else: lst[i] = 1 i = a[i] - 1 count += 1
import sys input = sys.stdin.readline N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] check = [True] * (N + 1) count = 0 tmp = 1 while check[tmp]: count += 1 check[tmp] = False if A[tmp - 1] == 2: print(count) exit() tmp = A[tmp - 1] print((-1))
false
13.636364
[ "+import sys", "+", "+input = sys.stdin.readline", "-a = []", "-for _ in range(N):", "- a += [int(eval(input()))]", "-lst = [0] * N", "-flag = True", "-i = 0", "+A = [int(eval(input())) for _ in range(N)]", "+check = [True] * (N + 1)", "-while flag:", "- if lst[i] == 1:", "- print((-1))", "+tmp = 1", "+while check[tmp]:", "+ count += 1", "+ check[tmp] = False", "+ if A[tmp - 1] == 2:", "+ print(count)", "- elif a[i] == 2:", "- print((count + 1))", "- exit()", "- else:", "- lst[i] = 1", "- i = a[i] - 1", "- count += 1", "+ tmp = A[tmp - 1]", "+print((-1))" ]
false
0.062497
0.037295
1.675758
[ "s436993402", "s489654403" ]
u703812436
p02712
python
s995273163
s896352447
189
21
9,108
9,116
Accepted
Accepted
88.89
N = int(eval(input())) ans = 0 for i in range(N): if (i + 1) % 3 != 0 and (i + 1) % 5 != 0: ans += i + 1 print(ans)
N = int(eval(input())) ans = int(N * (N + 1) / 2 - (N // 3) * (N // 3 + 1) / 2 * 3 - (N // 5) * (N // 5 + 1) / 2 * 5 + (N // 15) * (N // 15 + 1) / 2 * 15) print(ans)
6
3
126
161
N = int(eval(input())) ans = 0 for i in range(N): if (i + 1) % 3 != 0 and (i + 1) % 5 != 0: ans += i + 1 print(ans)
N = int(eval(input())) ans = int( N * (N + 1) / 2 - (N // 3) * (N // 3 + 1) / 2 * 3 - (N // 5) * (N // 5 + 1) / 2 * 5 + (N // 15) * (N // 15 + 1) / 2 * 15 ) print(ans)
false
50
[ "-ans = 0", "-for i in range(N):", "- if (i + 1) % 3 != 0 and (i + 1) % 5 != 0:", "- ans += i + 1", "+ans = int(", "+ N * (N + 1) / 2", "+ - (N // 3) * (N // 3 + 1) / 2 * 3", "+ - (N // 5) * (N // 5 + 1) / 2 * 5", "+ + (N // 15) * (N // 15 + 1) / 2 * 15", "+)" ]
false
0.471239
0.037735
12.488091
[ "s995273163", "s896352447" ]
u683987726
p02683
python
s996170003
s204665659
553
87
9,068
9,096
Accepted
Accepted
84.27
n, m, x = list(map(int, input().split())) inn = [ list( map(int, input().split() ) ) for _ in range(n) ] c = [inn[_][0] for _ in range(n) ] ara = [ inn[_][1:] for _ in range(n)] ans = 1e9 for mask in range(2**15): cost = 0 cnt = [0 for _ in range(m)] for i in range(n): if ( (1 << i) & mask ) == 0: continue cost += c[i] for j in range(m): cnt[j] += ara[i][j] ok = 1 for i in range(m): if cnt[i] < x: ok = 0 if ok: ans = min(ans, cost) if ans == 1e9: ans = -1 print(ans)
n, m, x = list(map(int, input().split())) inn = [ list( map(int, input().split() ) ) for _ in range(n) ] c = [inn[_][0] for _ in range(n) ] ara = [ inn[_][1:] for _ in range(n)] ans = 1e9 for mask in range(2**n): cost = 0 cnt = [0 for _ in range(m)] for i in range(n): if ( (1 << i) & mask ) == 0: continue cost += c[i] for j in range(m): cnt[j] += ara[i][j] ok = 1 for i in range(m): if cnt[i] < x: ok = 0 if ok: ans = min(ans, cost) if ans == 1e9: ans = -1 print(ans)
30
30
527
526
n, m, x = list(map(int, input().split())) inn = [list(map(int, input().split())) for _ in range(n)] c = [inn[_][0] for _ in range(n)] ara = [inn[_][1:] for _ in range(n)] ans = 1e9 for mask in range(2**15): cost = 0 cnt = [0 for _ in range(m)] for i in range(n): if ((1 << i) & mask) == 0: continue cost += c[i] for j in range(m): cnt[j] += ara[i][j] ok = 1 for i in range(m): if cnt[i] < x: ok = 0 if ok: ans = min(ans, cost) if ans == 1e9: ans = -1 print(ans)
n, m, x = list(map(int, input().split())) inn = [list(map(int, input().split())) for _ in range(n)] c = [inn[_][0] for _ in range(n)] ara = [inn[_][1:] for _ in range(n)] ans = 1e9 for mask in range(2**n): cost = 0 cnt = [0 for _ in range(m)] for i in range(n): if ((1 << i) & mask) == 0: continue cost += c[i] for j in range(m): cnt[j] += ara[i][j] ok = 1 for i in range(m): if cnt[i] < x: ok = 0 if ok: ans = min(ans, cost) if ans == 1e9: ans = -1 print(ans)
false
0
[ "-for mask in range(2**15):", "+for mask in range(2**n):" ]
false
0.468973
0.035614
13.168182
[ "s996170003", "s204665659" ]
u553987207
p03037
python
s813112549
s423144273
318
128
3,060
8,980
Accepted
Accepted
59.75
N, M = list(map(int, input().split())) ansl = 1 ansr = N for _ in range(M): L, R = list(map(int, input().split())) ansl = max(ansl, L) ansr = min(ansr, R) ans = max(ansr - ansl + 1, 0) print(ans)
import sys N, M = list(map(int, input().split())) ansl = 1 ansr = N for _ in range(M): l, r = list(map(int, sys.stdin.readline().split())) ansl = max(ansl, l) ansr = min(ansr, r) ans = max(0, ansr - ansl + 1) print(ans)
9
10
203
228
N, M = list(map(int, input().split())) ansl = 1 ansr = N for _ in range(M): L, R = list(map(int, input().split())) ansl = max(ansl, L) ansr = min(ansr, R) ans = max(ansr - ansl + 1, 0) print(ans)
import sys N, M = list(map(int, input().split())) ansl = 1 ansr = N for _ in range(M): l, r = list(map(int, sys.stdin.readline().split())) ansl = max(ansl, l) ansr = min(ansr, r) ans = max(0, ansr - ansl + 1) print(ans)
false
10
[ "+import sys", "+", "- L, R = list(map(int, input().split()))", "- ansl = max(ansl, L)", "- ansr = min(ansr, R)", "-ans = max(ansr - ansl + 1, 0)", "+ l, r = list(map(int, sys.stdin.readline().split()))", "+ ansl = max(ansl, l)", "+ ansr = min(ansr, r)", "+ans = max(0, ansr - ansl + 1)" ]
false
0.077719
0.078091
0.995229
[ "s813112549", "s423144273" ]
u355853184
p02837
python
s635805049
s308846423
193
174
9,156
9,184
Accepted
Accepted
9.84
n = int(eval(input())) a_list = [] person_list = [] syogen_list = [] ans = 0 for i in range(0, n): w = [] v = [] a = int(eval(input())) for j in range(0, a): x,y = list(map(int,input().split())) w.append(x) v.append(y) person_list.append(w) syogen_list.append(v) #print(person_list) #print(syogen_list) for bit in range(1 << n): break_flag = 0 bit_1_cnt = 0 for i in range(n): if break_flag: break if (bit >> i) & 1: #人iが正直 for j in range(len(syogen_list[i])): if syogen_list[i][j] != ((bit>>(person_list[i][j]-1))&1): #矛盾 : 正直としているのに証言が食い違えばbreak break_flag = 1 break bit_1_cnt += 1 if break_flag==0 and i==n-1: ans = max(ans, bit_1_cnt) print(ans)
N = int(eval(input())) syougen = [ [] for _ in range(N) ] for i in range(N): num = int(eval(input())) for j in range(num): x, y = list(map(int, input().split())) syougen[i].append([x, y]) #print(syougen) ans = 0 for bit in range(1 << N): break_flag = 0 for i in range(N): if (bit >> i) & 1: for j in range(len(syougen[i])): if ((bit>>(syougen[i][j][0]-1))&1) != syougen[i][j][1]: break_flag = 1 break if break_flag == 1: break if i == N-1: ans = max(ans, bin(bit).count("1")) print(ans)
35
24
857
649
n = int(eval(input())) a_list = [] person_list = [] syogen_list = [] ans = 0 for i in range(0, n): w = [] v = [] a = int(eval(input())) for j in range(0, a): x, y = list(map(int, input().split())) w.append(x) v.append(y) person_list.append(w) syogen_list.append(v) # print(person_list) # print(syogen_list) for bit in range(1 << n): break_flag = 0 bit_1_cnt = 0 for i in range(n): if break_flag: break if (bit >> i) & 1: # 人iが正直 for j in range(len(syogen_list[i])): if syogen_list[i][j] != ( (bit >> (person_list[i][j] - 1)) & 1 ): # 矛盾 : 正直としているのに証言が食い違えばbreak break_flag = 1 break bit_1_cnt += 1 if break_flag == 0 and i == n - 1: ans = max(ans, bit_1_cnt) print(ans)
N = int(eval(input())) syougen = [[] for _ in range(N)] for i in range(N): num = int(eval(input())) for j in range(num): x, y = list(map(int, input().split())) syougen[i].append([x, y]) # print(syougen) ans = 0 for bit in range(1 << N): break_flag = 0 for i in range(N): if (bit >> i) & 1: for j in range(len(syougen[i])): if ((bit >> (syougen[i][j][0] - 1)) & 1) != syougen[i][j][1]: break_flag = 1 break if break_flag == 1: break if i == N - 1: ans = max(ans, bin(bit).count("1")) print(ans)
false
31.428571
[ "-n = int(eval(input()))", "-a_list = []", "-person_list = []", "-syogen_list = []", "+N = int(eval(input()))", "+syougen = [[] for _ in range(N)]", "+for i in range(N):", "+ num = int(eval(input()))", "+ for j in range(num):", "+ x, y = list(map(int, input().split()))", "+ syougen[i].append([x, y])", "+# print(syougen)", "-for i in range(0, n):", "- w = []", "- v = []", "- a = int(eval(input()))", "- for j in range(0, a):", "- x, y = list(map(int, input().split()))", "- w.append(x)", "- v.append(y)", "- person_list.append(w)", "- syogen_list.append(v)", "-# print(person_list)", "-# print(syogen_list)", "-for bit in range(1 << n):", "+for bit in range(1 << N):", "- bit_1_cnt = 0", "- for i in range(n):", "- if break_flag:", "- break", "- if (bit >> i) & 1: # 人iが正直", "- for j in range(len(syogen_list[i])):", "- if syogen_list[i][j] != (", "- (bit >> (person_list[i][j] - 1)) & 1", "- ): # 矛盾 : 正直としているのに証言が食い違えばbreak", "+ for i in range(N):", "+ if (bit >> i) & 1:", "+ for j in range(len(syougen[i])):", "+ if ((bit >> (syougen[i][j][0] - 1)) & 1) != syougen[i][j][1]:", "- bit_1_cnt += 1", "- if break_flag == 0 and i == n - 1:", "- ans = max(ans, bit_1_cnt)", "+ if break_flag == 1:", "+ break", "+ if i == N - 1:", "+ ans = max(ans, bin(bit).count(\"1\"))" ]
false
0.080159
0.084908
0.944059
[ "s635805049", "s308846423" ]
u046187684
p03014
python
s972860892
s390143316
1,588
1,314
198,128
197,872
Accepted
Accepted
17.25
def solve(string): h, w, *s = string.split() h, w = list(map(int, [h, w])) hg = [] hi = [] vg = [] vi = [] for _s in s: gn = 0 _hi = [0] * w _hg = [] c = 0 for i, __s in enumerate(_s): if __s == "#": _hi[i] = -1 gn += 1 _hg.append(c) c = 0 continue _hi[i] = gn c += 1 _hg.append(c) hg.append(_hg) hi.append(_hi) for _s in zip(*s): gn = 0 _vi = [0] * h _vg = [] c = 0 for i, __s in enumerate(_s): if __s == "#": _vi[i] = -1 gn += 1 _vg.append(c) c = 0 continue _vi[i] = gn c += 1 _vg.append(c) vg.append(_vg) vi.append(_vi) ans = 0 for i in range(h): ans = max(ans, max([hg[i][hi[i][j]] + vg[j][vi[j][i]] for j in range(w)])) return str(ans - 1) if __name__ == '__main__': n, m = list(map(int, input().split())) print((solve('{} {}\n'.format(n, m) + '\n'.join([eval(input()) for _ in range(n)]))))
def solve(string): h, w, *s = string.split() h, w = list(map(int, [h, w])) hg = [] hi = [] vg = [] vi = [] for _s in s: gn = 0 _hi = [0] * w _hg = [] c = 0 for i, __s in enumerate(_s): if __s == "#": _hi[i] = -1 gn += 1 _hg.append(c) c = 0 continue _hi[i] = gn c += 1 _hg.append(c) hg.append(_hg) hi.append(_hi) for _s in zip(*s): gn = 0 _vi = [0] * h _vg = [] c = 0 for i, __s in enumerate(_s): if __s == "#": _vi[i] = -1 gn += 1 _vg.append(c) c = 0 continue _vi[i] = gn c += 1 _vg.append(c) vg.append(_vg) vi.append(_vi) ans = 0 for i in range(h): for j in range(w): ans = max(ans, hg[i][hi[i][j]] + vg[j][vi[j][i]]) return str(ans - 1) if __name__ == '__main__': n, m = list(map(int, input().split())) print((solve('{} {}\n'.format(n, m) + '\n'.join([eval(input()) for _ in range(n)]))))
51
53
1,250
1,259
def solve(string): h, w, *s = string.split() h, w = list(map(int, [h, w])) hg = [] hi = [] vg = [] vi = [] for _s in s: gn = 0 _hi = [0] * w _hg = [] c = 0 for i, __s in enumerate(_s): if __s == "#": _hi[i] = -1 gn += 1 _hg.append(c) c = 0 continue _hi[i] = gn c += 1 _hg.append(c) hg.append(_hg) hi.append(_hi) for _s in zip(*s): gn = 0 _vi = [0] * h _vg = [] c = 0 for i, __s in enumerate(_s): if __s == "#": _vi[i] = -1 gn += 1 _vg.append(c) c = 0 continue _vi[i] = gn c += 1 _vg.append(c) vg.append(_vg) vi.append(_vi) ans = 0 for i in range(h): ans = max(ans, max([hg[i][hi[i][j]] + vg[j][vi[j][i]] for j in range(w)])) return str(ans - 1) if __name__ == "__main__": n, m = list(map(int, input().split())) print( (solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(n)]))) )
def solve(string): h, w, *s = string.split() h, w = list(map(int, [h, w])) hg = [] hi = [] vg = [] vi = [] for _s in s: gn = 0 _hi = [0] * w _hg = [] c = 0 for i, __s in enumerate(_s): if __s == "#": _hi[i] = -1 gn += 1 _hg.append(c) c = 0 continue _hi[i] = gn c += 1 _hg.append(c) hg.append(_hg) hi.append(_hi) for _s in zip(*s): gn = 0 _vi = [0] * h _vg = [] c = 0 for i, __s in enumerate(_s): if __s == "#": _vi[i] = -1 gn += 1 _vg.append(c) c = 0 continue _vi[i] = gn c += 1 _vg.append(c) vg.append(_vg) vi.append(_vi) ans = 0 for i in range(h): for j in range(w): ans = max(ans, hg[i][hi[i][j]] + vg[j][vi[j][i]]) return str(ans - 1) if __name__ == "__main__": n, m = list(map(int, input().split())) print( (solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(n)]))) )
false
3.773585
[ "- ans = max(ans, max([hg[i][hi[i][j]] + vg[j][vi[j][i]] for j in range(w)]))", "+ for j in range(w):", "+ ans = max(ans, hg[i][hi[i][j]] + vg[j][vi[j][i]])" ]
false
0.044138
0.044121
1.00038
[ "s972860892", "s390143316" ]
u923668099
p02266
python
s619511995
s259149993
3,190
30
8,512
8,032
Accepted
Accepted
99.06
""" O(n^2)??????????§£??? """ danmen = eval(input()) depth = [] tmp_dpt = 0 for line in danmen: depth.append(tmp_dpt) if line == "\\": tmp_dpt -= 1 elif line == "/": tmp_dpt += 1 # len(depth) = len(danmen) + 1?????¨??? depth.append(tmp_dpt) # print(depth) i = 0 L = [] while i < len(danmen): if len(set(danmen[i:])) == 1: break if danmen[i] == "\\": if depth[i] in depth[i + 1:]: stack = 0 area = 0 for line in danmen[i:]: if line == "\\": area += 1 + 2 * stack stack += 1 elif line == "/": stack -= 1 area += 1 + 2 * stack else: area += 2 * stack if stack == 0: break if area != 0: L.append(area // 2) i += depth[i + 1:].index(depth[i]) i += 1 print((sum(L))) print((len(L), *L))
danmen = eval(input()) down = [] edge = [] pool = [] for (i, line) in enumerate(danmen): if line == "\\": down.append(i) elif down and line == "/": left = down.pop() area = i - left while edge: if edge[-1] > left: edge.pop() area += pool.pop() else: break edge.append(left) pool.append(area) print((sum(pool))) print((len(pool), *pool))
54
25
1,056
483
""" O(n^2)??????????§£??? """ danmen = eval(input()) depth = [] tmp_dpt = 0 for line in danmen: depth.append(tmp_dpt) if line == "\\": tmp_dpt -= 1 elif line == "/": tmp_dpt += 1 # len(depth) = len(danmen) + 1?????¨??? depth.append(tmp_dpt) # print(depth) i = 0 L = [] while i < len(danmen): if len(set(danmen[i:])) == 1: break if danmen[i] == "\\": if depth[i] in depth[i + 1 :]: stack = 0 area = 0 for line in danmen[i:]: if line == "\\": area += 1 + 2 * stack stack += 1 elif line == "/": stack -= 1 area += 1 + 2 * stack else: area += 2 * stack if stack == 0: break if area != 0: L.append(area // 2) i += depth[i + 1 :].index(depth[i]) i += 1 print((sum(L))) print((len(L), *L))
danmen = eval(input()) down = [] edge = [] pool = [] for (i, line) in enumerate(danmen): if line == "\\": down.append(i) elif down and line == "/": left = down.pop() area = i - left while edge: if edge[-1] > left: edge.pop() area += pool.pop() else: break edge.append(left) pool.append(area) print((sum(pool))) print((len(pool), *pool))
false
53.703704
[ "-\"\"\"", "-O(n^2)??????????§£???", "-\"\"\"", "-depth = []", "-tmp_dpt = 0", "-for line in danmen:", "- depth.append(tmp_dpt)", "+down = []", "+edge = []", "+pool = []", "+for (i, line) in enumerate(danmen):", "- tmp_dpt -= 1", "- elif line == \"/\":", "- tmp_dpt += 1", "-# len(depth) = len(danmen) + 1?????¨???", "-depth.append(tmp_dpt)", "-# print(depth)", "-i = 0", "-L = []", "-while i < len(danmen):", "- if len(set(danmen[i:])) == 1:", "- break", "- if danmen[i] == \"\\\\\":", "- if depth[i] in depth[i + 1 :]:", "- stack = 0", "- area = 0", "- for line in danmen[i:]:", "- if line == \"\\\\\":", "- area += 1 + 2 * stack", "- stack += 1", "- elif line == \"/\":", "- stack -= 1", "- area += 1 + 2 * stack", "- else:", "- area += 2 * stack", "- if stack == 0:", "- break", "- if area != 0:", "- L.append(area // 2)", "- i += depth[i + 1 :].index(depth[i])", "- i += 1", "-print((sum(L)))", "-print((len(L), *L))", "+ down.append(i)", "+ elif down and line == \"/\":", "+ left = down.pop()", "+ area = i - left", "+ while edge:", "+ if edge[-1] > left:", "+ edge.pop()", "+ area += pool.pop()", "+ else:", "+ break", "+ edge.append(left)", "+ pool.append(area)", "+print((sum(pool)))", "+print((len(pool), *pool))" ]
false
0.047636
0.051633
0.922588
[ "s619511995", "s259149993" ]
u028973125
p03096
python
s160247367
s826925724
379
147
123,736
123,160
Accepted
Accepted
61.21
import sys mod = 10**9 + 7 N = int(sys.stdin.readline()) stones = [] for _ in range(N): stones.append(int(sys.stdin.readline())) left = [-1 for _ in range(2*10**5+1)] dp = [0 for _ in range(N+5)] dp[0] = 1 for i in range(N): dp[i+1] = dp[i] # 同じ色が前回出現した位置 c = stones[i] if 0 <= left[c] < i - 1: dp[i+1] += dp[left[c] + 1] dp[i+1] %= mod left[c] = i print((dp[N]))
import sys mod = 10**9 + 7 N = int(sys.stdin.readline()) stones = [] for _ in range(N): stones.append(int(sys.stdin.readline())) left = {} dp = [0 for _ in range(N+5)] dp[0] = 1 for i in range(N): dp[i+1] = dp[i] # 同じ色が前回出現した位置 c = stones[i] if c in left and 0 <= left[c] < i - 1: dp[i+1] += dp[left[c] + 1] dp[i+1] %= mod left[c] = i print((dp[N]))
23
23
428
414
import sys mod = 10**9 + 7 N = int(sys.stdin.readline()) stones = [] for _ in range(N): stones.append(int(sys.stdin.readline())) left = [-1 for _ in range(2 * 10**5 + 1)] dp = [0 for _ in range(N + 5)] dp[0] = 1 for i in range(N): dp[i + 1] = dp[i] # 同じ色が前回出現した位置 c = stones[i] if 0 <= left[c] < i - 1: dp[i + 1] += dp[left[c] + 1] dp[i + 1] %= mod left[c] = i print((dp[N]))
import sys mod = 10**9 + 7 N = int(sys.stdin.readline()) stones = [] for _ in range(N): stones.append(int(sys.stdin.readline())) left = {} dp = [0 for _ in range(N + 5)] dp[0] = 1 for i in range(N): dp[i + 1] = dp[i] # 同じ色が前回出現した位置 c = stones[i] if c in left and 0 <= left[c] < i - 1: dp[i + 1] += dp[left[c] + 1] dp[i + 1] %= mod left[c] = i print((dp[N]))
false
0
[ "-left = [-1 for _ in range(2 * 10**5 + 1)]", "+left = {}", "- if 0 <= left[c] < i - 1:", "+ if c in left and 0 <= left[c] < i - 1:" ]
false
0.046102
0.037223
1.238532
[ "s160247367", "s826925724" ]
u094191970
p02899
python
s999996253
s536088320
597
512
23,404
23,356
Accepted
Accepted
14.24
import numpy as np n=int(eval(input())) a=np.array(list(map(int,input().split()))) l=np.argsort(a) ans=[i+1 for i in l] print((*ans))
import numpy as np n=int(eval(input())) a=np.array(list(map(int,input().split()))) l=np.argsort(a)+1 print((*l))
6
5
130
108
import numpy as np n = int(eval(input())) a = np.array(list(map(int, input().split()))) l = np.argsort(a) ans = [i + 1 for i in l] print((*ans))
import numpy as np n = int(eval(input())) a = np.array(list(map(int, input().split()))) l = np.argsort(a) + 1 print((*l))
false
16.666667
[ "-l = np.argsort(a)", "-ans = [i + 1 for i in l]", "-print((*ans))", "+l = np.argsort(a) + 1", "+print((*l))" ]
false
0.217298
0.241672
0.899146
[ "s999996253", "s536088320" ]
u584174687
p02901
python
s306316166
s060510287
1,920
326
112,088
48,344
Accepted
Accepted
83.02
from collections import Counter, defaultdict import sys sys.setrecursionlimit(10 ** 5 + 10) input = sys.stdin.readline from math import factorial import heapq, bisect import math import itertools from copy import deepcopy, copy import queue from collections import deque def divisor(n): #nの約数を全て求める i = 1 table = set() while i * i <= n: if n%i == 0: table.add(i) table.add(n//i) i += 1 return table ans = 10 ** 10 def check(box_num, kagi_num, kagi_data, ind, now_data_kari, money, data): now_data = copy(now_data_kari) if ind == box_num: for i in range(box_num): if now_data[i] == 0: break else: global ans ans = min(ans, money) return if now_data[ind]: check(box_num, kagi_num, kagi_data, ind + 1, now_data, money, data) return check_set = set() for i in range(len(kagi_data[ind + 1])): aaa = kagi_data[ind + 1][i] now_data = copy(now_data_kari) bbb = ['0' for i in range(box_num)] flg = 1 for ele in data[aaa][2]: if now_data[ele - 1] == 0: now_data[ele - 1] = 1 flg = 0 if ele >= ind + 1: bbb[ele - 1] = '1' if flg: continue bbb = ''.join(bbb) if bbb in check_set: continue check_set.add(bbb) check(box_num, kagi_num, kagi_data, ind + 1, now_data, money + data[aaa][0], data) def main(): box_num, kagi_num = list(map(int, input().split())) data = [0 for i in range(kagi_num)] kari = set() for i in range(kagi_num): a = list(map(int, input().split())) b = list(map(int, input().split())) kari |= set(b) data[i] = [a[0], a[1], b] kagi_data = defaultdict(int) for i in range(kagi_num): a = data[i] aaa = 0 for ele in a[2]: aaa += 2 ** (ele - 1) bin_data = bin(aaa)[2:] bin_data = bin_data.zfill(box_num) if bin_data in kagi_data: kagi_data[bin_data] = min(a[0], kagi_data[bin_data]) else: kagi_data[bin_data] = a[0] aaaaaa = list(kagi_data.items()) for key, value in list(aaaaaa): aaa = ['0' for i in range(box_num)] for i in range(box_num): if key[i] == '1' or bin_data[i] == '1': aaa[i] = '1' aaa = ''.join(aaa) if aaa in kagi_data: kagi_data[aaa] = min(value + a[0], kagi_data[aaa]) else: kagi_data[aaa] = value + a[0] # print(kagi_data) aaa = ['1' for i in range(box_num)] aaa = ''.join(aaa) if aaa in kagi_data: print((kagi_data[aaa])) else: print((-1)) # def test(): # for i in : # print(i) if __name__ == '__main__': main() # test()
from collections import Counter, defaultdict import sys sys.setrecursionlimit(10 ** 5 + 10) input = sys.stdin.readline from math import factorial import heapq, bisect import math import itertools from copy import deepcopy, copy import queue from collections import deque def main(): box_num, kagi_num = list(map(int, input().split())) kagi_data = defaultdict(lambda: 10 ** 10) for i in range(kagi_num): a = list(map(int, input().split())) b = list(map(int, input().split())) money = a[0] ind = 0 for ele in b: ind += 2 ** (ele - 1) kagi_data[ind] = min(kagi_data[ind], money) for key, value in list(kagi_data.items()): kari = ind | key kagi_data[kari] = min(money + value, kagi_data[kari]) ans = kagi_data[2 ** (box_num) - 1] if ans == 10 ** 10: print((-1)) else: print(ans) if __name__ == '__main__': main()
125
43
3,067
990
from collections import Counter, defaultdict import sys sys.setrecursionlimit(10**5 + 10) input = sys.stdin.readline from math import factorial import heapq, bisect import math import itertools from copy import deepcopy, copy import queue from collections import deque def divisor(n): # nの約数を全て求める i = 1 table = set() while i * i <= n: if n % i == 0: table.add(i) table.add(n // i) i += 1 return table ans = 10**10 def check(box_num, kagi_num, kagi_data, ind, now_data_kari, money, data): now_data = copy(now_data_kari) if ind == box_num: for i in range(box_num): if now_data[i] == 0: break else: global ans ans = min(ans, money) return if now_data[ind]: check(box_num, kagi_num, kagi_data, ind + 1, now_data, money, data) return check_set = set() for i in range(len(kagi_data[ind + 1])): aaa = kagi_data[ind + 1][i] now_data = copy(now_data_kari) bbb = ["0" for i in range(box_num)] flg = 1 for ele in data[aaa][2]: if now_data[ele - 1] == 0: now_data[ele - 1] = 1 flg = 0 if ele >= ind + 1: bbb[ele - 1] = "1" if flg: continue bbb = "".join(bbb) if bbb in check_set: continue check_set.add(bbb) check( box_num, kagi_num, kagi_data, ind + 1, now_data, money + data[aaa][0], data ) def main(): box_num, kagi_num = list(map(int, input().split())) data = [0 for i in range(kagi_num)] kari = set() for i in range(kagi_num): a = list(map(int, input().split())) b = list(map(int, input().split())) kari |= set(b) data[i] = [a[0], a[1], b] kagi_data = defaultdict(int) for i in range(kagi_num): a = data[i] aaa = 0 for ele in a[2]: aaa += 2 ** (ele - 1) bin_data = bin(aaa)[2:] bin_data = bin_data.zfill(box_num) if bin_data in kagi_data: kagi_data[bin_data] = min(a[0], kagi_data[bin_data]) else: kagi_data[bin_data] = a[0] aaaaaa = list(kagi_data.items()) for key, value in list(aaaaaa): aaa = ["0" for i in range(box_num)] for i in range(box_num): if key[i] == "1" or bin_data[i] == "1": aaa[i] = "1" aaa = "".join(aaa) if aaa in kagi_data: kagi_data[aaa] = min(value + a[0], kagi_data[aaa]) else: kagi_data[aaa] = value + a[0] # print(kagi_data) aaa = ["1" for i in range(box_num)] aaa = "".join(aaa) if aaa in kagi_data: print((kagi_data[aaa])) else: print((-1)) # def test(): # for i in : # print(i) if __name__ == "__main__": main() # test()
from collections import Counter, defaultdict import sys sys.setrecursionlimit(10**5 + 10) input = sys.stdin.readline from math import factorial import heapq, bisect import math import itertools from copy import deepcopy, copy import queue from collections import deque def main(): box_num, kagi_num = list(map(int, input().split())) kagi_data = defaultdict(lambda: 10**10) for i in range(kagi_num): a = list(map(int, input().split())) b = list(map(int, input().split())) money = a[0] ind = 0 for ele in b: ind += 2 ** (ele - 1) kagi_data[ind] = min(kagi_data[ind], money) for key, value in list(kagi_data.items()): kari = ind | key kagi_data[kari] = min(money + value, kagi_data[kari]) ans = kagi_data[2 ** (box_num) - 1] if ans == 10**10: print((-1)) else: print(ans) if __name__ == "__main__": main()
false
65.6
[ "-def divisor(n): # nの約数を全て求める", "- i = 1", "- table = set()", "- while i * i <= n:", "- if n % i == 0:", "- table.add(i)", "- table.add(n // i)", "- i += 1", "- return table", "-", "-", "-ans = 10**10", "-", "-", "-def check(box_num, kagi_num, kagi_data, ind, now_data_kari, money, data):", "- now_data = copy(now_data_kari)", "- if ind == box_num:", "- for i in range(box_num):", "- if now_data[i] == 0:", "- break", "- else:", "- global ans", "- ans = min(ans, money)", "- return", "- if now_data[ind]:", "- check(box_num, kagi_num, kagi_data, ind + 1, now_data, money, data)", "- return", "- check_set = set()", "- for i in range(len(kagi_data[ind + 1])):", "- aaa = kagi_data[ind + 1][i]", "- now_data = copy(now_data_kari)", "- bbb = [\"0\" for i in range(box_num)]", "- flg = 1", "- for ele in data[aaa][2]:", "- if now_data[ele - 1] == 0:", "- now_data[ele - 1] = 1", "- flg = 0", "- if ele >= ind + 1:", "- bbb[ele - 1] = \"1\"", "- if flg:", "- continue", "- bbb = \"\".join(bbb)", "- if bbb in check_set:", "- continue", "- check_set.add(bbb)", "- check(", "- box_num, kagi_num, kagi_data, ind + 1, now_data, money + data[aaa][0], data", "- )", "-", "-", "- data = [0 for i in range(kagi_num)]", "- kari = set()", "+ kagi_data = defaultdict(lambda: 10**10)", "- kari |= set(b)", "- data[i] = [a[0], a[1], b]", "- kagi_data = defaultdict(int)", "- for i in range(kagi_num):", "- a = data[i]", "- aaa = 0", "- for ele in a[2]:", "- aaa += 2 ** (ele - 1)", "- bin_data = bin(aaa)[2:]", "- bin_data = bin_data.zfill(box_num)", "- if bin_data in kagi_data:", "- kagi_data[bin_data] = min(a[0], kagi_data[bin_data])", "- else:", "- kagi_data[bin_data] = a[0]", "- aaaaaa = list(kagi_data.items())", "- for key, value in list(aaaaaa):", "- aaa = [\"0\" for i in range(box_num)]", "- for i in range(box_num):", "- if key[i] == \"1\" or bin_data[i] == \"1\":", "- aaa[i] = \"1\"", "- aaa = \"\".join(aaa)", "- if aaa in kagi_data:", "- kagi_data[aaa] = min(value + a[0], kagi_data[aaa])", "- else:", "- kagi_data[aaa] = value + a[0]", "- # print(kagi_data)", "- aaa = [\"1\" for i in range(box_num)]", "- aaa = \"\".join(aaa)", "- if aaa in kagi_data:", "- print((kagi_data[aaa]))", "+ money = a[0]", "+ ind = 0", "+ for ele in b:", "+ ind += 2 ** (ele - 1)", "+ kagi_data[ind] = min(kagi_data[ind], money)", "+ for key, value in list(kagi_data.items()):", "+ kari = ind | key", "+ kagi_data[kari] = min(money + value, kagi_data[kari])", "+ ans = kagi_data[2 ** (box_num) - 1]", "+ if ans == 10**10:", "+ print((-1))", "- print((-1))", "+ print(ans)", "-# def test():", "-# for i in :", "-# print(i)", "- # test()" ]
false
0.049085
0.038192
1.285235
[ "s306316166", "s060510287" ]
u389910364
p03558
python
s668677685
s830318365
423
152
10,952
9,200
Accepted
Accepted
64.07
import sys from collections import deque sys.setrecursionlimit(10000) INF = float('inf') K = int(eval(input())) # ある数に 1 を足すと各桁の和は 1 増える # ある数に 10 を掛けると各桁の和は 0 増える # mod K の世界で同じことやっても同じなので # このグラフ上で 1 から 0 への最短距離が答え。 distances = [INF for _ in range(K)] # 01BFS remains = deque() remains.append((1, 1)) while distances[0] == INF: d, mod_k = remains.popleft() distances[mod_k] = d if distances[(mod_k + 1) % K] == INF: remains.append((d + 1, (mod_k + 1) % K)) if distances[mod_k * 10 % K] == INF: remains.appendleft((d, mod_k * 10 % K)) print((distances[0]))
import sys from collections import deque sys.setrecursionlimit(10000) INF = float('inf') K = int(eval(input())) # ある数に 1 を足すと各桁の和は 1 増える # ある数に 10 を掛けると各桁の和は 0 増える # mod K の世界で同じことやっても同じなので # このグラフ上で 1 から 0 への最短距離が答え。 distances = [INF for _ in range(K)] # 01BFS distances[1] = 1 remains = deque() remains.append((1, 1)) while True: d, mod_k = remains.popleft() if mod_k == 0: break if d + 1 < distances[(mod_k + 1) % K]: distances[(mod_k + 1) % K] = d + 1 remains.append((d + 1, (mod_k + 1) % K)) if d < distances[mod_k * 10 % K]: distances[mod_k * 10 % K] = d remains.appendleft((d, mod_k * 10 % K)) print((distances[0]))
26
30
612
705
import sys from collections import deque sys.setrecursionlimit(10000) INF = float("inf") K = int(eval(input())) # ある数に 1 を足すと各桁の和は 1 増える # ある数に 10 を掛けると各桁の和は 0 増える # mod K の世界で同じことやっても同じなので # このグラフ上で 1 から 0 への最短距離が答え。 distances = [INF for _ in range(K)] # 01BFS remains = deque() remains.append((1, 1)) while distances[0] == INF: d, mod_k = remains.popleft() distances[mod_k] = d if distances[(mod_k + 1) % K] == INF: remains.append((d + 1, (mod_k + 1) % K)) if distances[mod_k * 10 % K] == INF: remains.appendleft((d, mod_k * 10 % K)) print((distances[0]))
import sys from collections import deque sys.setrecursionlimit(10000) INF = float("inf") K = int(eval(input())) # ある数に 1 を足すと各桁の和は 1 増える # ある数に 10 を掛けると各桁の和は 0 増える # mod K の世界で同じことやっても同じなので # このグラフ上で 1 から 0 への最短距離が答え。 distances = [INF for _ in range(K)] # 01BFS distances[1] = 1 remains = deque() remains.append((1, 1)) while True: d, mod_k = remains.popleft() if mod_k == 0: break if d + 1 < distances[(mod_k + 1) % K]: distances[(mod_k + 1) % K] = d + 1 remains.append((d + 1, (mod_k + 1) % K)) if d < distances[mod_k * 10 % K]: distances[mod_k * 10 % K] = d remains.appendleft((d, mod_k * 10 % K)) print((distances[0]))
false
13.333333
[ "+distances[1] = 1", "-while distances[0] == INF:", "+while True:", "- distances[mod_k] = d", "- if distances[(mod_k + 1) % K] == INF:", "+ if mod_k == 0:", "+ break", "+ if d + 1 < distances[(mod_k + 1) % K]:", "+ distances[(mod_k + 1) % K] = d + 1", "- if distances[mod_k * 10 % K] == INF:", "+ if d < distances[mod_k * 10 % K]:", "+ distances[mod_k * 10 % K] = d" ]
false
0.101494
0.127217
0.797802
[ "s668677685", "s830318365" ]
u539367121
p02713
python
s568782527
s049555621
1,714
934
9,012
11,668
Accepted
Accepted
45.51
def main(): import math N = int(eval(input())) ans=0 for i in range(1,N+1): for j in range(1, N+1): for k in range(1, N+1): t=math.gcd(i,j) t=math.gcd(t,k) ans+=t print(ans) if __name__=='__main__': main()
def main(): import math N = int(eval(input())) gcd={} ans=0 for i in range(1,N+1): for j in range(1, N+1): key=i*N+j gcd[key]=math.gcd(i,j) for k, i in list(gcd.items()): for j in range(1, N+1): key=j*N+i ans+=gcd[key] print(ans) if __name__=='__main__': main()
15
19
276
329
def main(): import math N = int(eval(input())) ans = 0 for i in range(1, N + 1): for j in range(1, N + 1): for k in range(1, N + 1): t = math.gcd(i, j) t = math.gcd(t, k) ans += t print(ans) if __name__ == "__main__": main()
def main(): import math N = int(eval(input())) gcd = {} ans = 0 for i in range(1, N + 1): for j in range(1, N + 1): key = i * N + j gcd[key] = math.gcd(i, j) for k, i in list(gcd.items()): for j in range(1, N + 1): key = j * N + i ans += gcd[key] print(ans) if __name__ == "__main__": main()
false
21.052632
[ "+ gcd = {}", "- for k in range(1, N + 1):", "- t = math.gcd(i, j)", "- t = math.gcd(t, k)", "- ans += t", "+ key = i * N + j", "+ gcd[key] = math.gcd(i, j)", "+ for k, i in list(gcd.items()):", "+ for j in range(1, N + 1):", "+ key = j * N + i", "+ ans += gcd[key]" ]
false
0.151896
0.205025
0.740865
[ "s568782527", "s049555621" ]
u191874006
p03324
python
s240725886
s749363243
153
17
12,396
2,940
Accepted
Accepted
88.89
#!/usr/bin/env python3 import numpy as np import math import re x = eval(input()) x = re.split(" ",x) D = int(x[0]) N = int(x[1]) if (N==100): print((100**D*N+100**D)) else: print((100**D*N))
#!/usr/bin/env python3 #ABC100 B D,N = list(map(int,input().split())) if N == 100: print((100**D*N+100**D)) else: print((100**D*N))
14
9
201
140
#!/usr/bin/env python3 import numpy as np import math import re x = eval(input()) x = re.split(" ", x) D = int(x[0]) N = int(x[1]) if N == 100: print((100**D * N + 100**D)) else: print((100**D * N))
#!/usr/bin/env python3 # ABC100 B D, N = list(map(int, input().split())) if N == 100: print((100**D * N + 100**D)) else: print((100**D * N))
false
35.714286
[ "-import numpy as np", "-import math", "-import re", "-", "-x = eval(input())", "-x = re.split(\" \", x)", "-D = int(x[0])", "-N = int(x[1])", "+# ABC100 B", "+D, N = list(map(int, input().split()))" ]
false
0.095264
0.037155
2.563934
[ "s240725886", "s749363243" ]
u802963389
p03937
python
s836243733
s014679660
170
18
38,256
3,060
Accepted
Accepted
89.41
H, W = list(map(int,input().split())) S = [eval(input()) for _ in range(H)] endSh = 0 for i in S: startSh = i.find("#") if startSh != endSh: print("Impossible") exit() endSh = i.rfind("#") print("Possible")
h, w = list(map(int, input().split())) A = [eval(input()) for _ in range(h)] sp = 0 for line in A: if line.find("#") != sp: print("Impossible") exit() sp = line.rfind("#") print("Possible")
10
10
217
201
H, W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] endSh = 0 for i in S: startSh = i.find("#") if startSh != endSh: print("Impossible") exit() endSh = i.rfind("#") print("Possible")
h, w = list(map(int, input().split())) A = [eval(input()) for _ in range(h)] sp = 0 for line in A: if line.find("#") != sp: print("Impossible") exit() sp = line.rfind("#") print("Possible")
false
0
[ "-H, W = list(map(int, input().split()))", "-S = [eval(input()) for _ in range(H)]", "-endSh = 0", "-for i in S:", "- startSh = i.find(\"#\")", "- if startSh != endSh:", "+h, w = list(map(int, input().split()))", "+A = [eval(input()) for _ in range(h)]", "+sp = 0", "+for line in A:", "+ if line.find(\"#\") != sp:", "- endSh = i.rfind(\"#\")", "+ sp = line.rfind(\"#\")" ]
false
0.043713
0.042695
1.023827
[ "s836243733", "s014679660" ]