user_id stringlengths 10 10 | problem_id stringlengths 6 6 | language stringclasses 1 value | submission_id_v0 stringlengths 10 10 | submission_id_v1 stringlengths 10 10 | cpu_time_v0 int64 10 38.3k | cpu_time_v1 int64 0 24.7k | memory_v0 int64 2.57k 1.02M | memory_v1 int64 2.57k 869k | status_v0 stringclasses 1 value | status_v1 stringclasses 1 value | improvement_frac float64 7.51 100 | input stringlengths 20 4.55k | target stringlengths 17 3.34k | code_v0_loc int64 1 148 | code_v1_loc int64 1 184 | code_v0_num_chars int64 13 4.55k | code_v1_num_chars int64 14 3.34k | code_v0_no_empty_lines stringlengths 21 6.88k | code_v1_no_empty_lines stringlengths 20 4.93k | code_same bool 1 class | relative_loc_diff_percent float64 0 79.8 | diff list | diff_only_import_comment bool 1 class | measured_runtime_v0 float64 0.01 4.45 | measured_runtime_v1 float64 0.01 4.31 | runtime_lift float64 0 359 | key list |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u562016607 | p03324 | python | s896452324 | s516405849 | 48 | 17 | 2,940 | 2,940 | Accepted | Accepted | 64.58 | D,N=list(map(int,input().split()))
if N!=100:
print((N*100**D))
else:
print((101*100**D))
| D,N=list(map(int,input().split()))
print(((N+N//100)*100**D)) | 5 | 2 | 92 | 54 | D, N = list(map(int, input().split()))
if N != 100:
print((N * 100**D))
else:
print((101 * 100**D))
| D, N = list(map(int, input().split()))
print(((N + N // 100) * 100**D))
| false | 60 | [
"-if N != 100:",
"- print((N * 100**D))",
"-else:",
"- print((101 * 100**D))",
"+print(((N + N // 100) * 100**D))"
] | false | 0.040611 | 0.072439 | 0.560627 | [
"s896452324",
"s516405849"
] |
u192154323 | p02695 | python | s988822385 | s323664818 | 578 | 318 | 9,228 | 9,204 | Accepted | Accepted | 44.98 | N,M,Q = list(map(int,input().split()))
req_ls = []
l_ind_ls = [0] * Q
r_ind_ls = [0] * Q
diff_ls = [0] * Q
point_ls = [0] * Q
for i in range(Q):
l_ind_ls[i], r_ind_ls[i], diff_ls[i], point_ls[i] = list(map(int, input().split()))
l_ind_ls[i] -= 1
r_ind_ls[i] -= 1
def score(ls):
tmp = 0
for l_ind, r_ind, diff, point in zip(l_ind_ls,r_ind_ls,diff_ls,point_ls):
if ls[r_ind] - ls[l_ind] == diff:
tmp += point
return tmp
def dfs(ls):
if len(ls) == N:
return score(ls)
res = 0
last = ls[-1] if len(ls) > 0 else 1
for nex in range(last, M+1):
ls.append(nex)
res = max(res, dfs(ls))
ls.pop()
return res
print((dfs([])))
| length, Max, q = list(map(int,input().split()))
query = [[0]*4 for _ in range(q)]
for i in range(q):
a,b,c,d = list(map(int,input().split()))
query[i] = [a-1,b-1,c,d]
ans = 0
def dfs(A):
if len(A) == length:
global ans
score = 0
for i in range(q):
a,b,c,d = query[i]
if A[b] - A[a] == c:
score += d
ans = max(ans, score)
return
last = A[-1]
for i in range(last,Max+1):
A.append(i)
dfs(A)
A.pop()
dfs([1])
print(ans)
| 31 | 26 | 730 | 556 | N, M, Q = list(map(int, input().split()))
req_ls = []
l_ind_ls = [0] * Q
r_ind_ls = [0] * Q
diff_ls = [0] * Q
point_ls = [0] * Q
for i in range(Q):
l_ind_ls[i], r_ind_ls[i], diff_ls[i], point_ls[i] = list(map(int, input().split()))
l_ind_ls[i] -= 1
r_ind_ls[i] -= 1
def score(ls):
tmp = 0
for l_ind, r_ind, diff, point in zip(l_ind_ls, r_ind_ls, diff_ls, point_ls):
if ls[r_ind] - ls[l_ind] == diff:
tmp += point
return tmp
def dfs(ls):
if len(ls) == N:
return score(ls)
res = 0
last = ls[-1] if len(ls) > 0 else 1
for nex in range(last, M + 1):
ls.append(nex)
res = max(res, dfs(ls))
ls.pop()
return res
print((dfs([])))
| length, Max, q = list(map(int, input().split()))
query = [[0] * 4 for _ in range(q)]
for i in range(q):
a, b, c, d = list(map(int, input().split()))
query[i] = [a - 1, b - 1, c, d]
ans = 0
def dfs(A):
if len(A) == length:
global ans
score = 0
for i in range(q):
a, b, c, d = query[i]
if A[b] - A[a] == c:
score += d
ans = max(ans, score)
return
last = A[-1]
for i in range(last, Max + 1):
A.append(i)
dfs(A)
A.pop()
dfs([1])
print(ans)
| false | 16.129032 | [
"-N, M, Q = list(map(int, input().split()))",
"-req_ls = []",
"-l_ind_ls = [0] * Q",
"-r_ind_ls = [0] * Q",
"-diff_ls = [0] * Q",
"-point_ls = [0] * Q",
"-for i in range(Q):",
"- l_ind_ls[i], r_ind_ls[i], diff_ls[i], point_ls[i] = list(map(int, input().split()))",
"- l_ind_ls[i] -= 1",
"- ... | false | 0.119973 | 0.057313 | 2.093303 | [
"s988822385",
"s323664818"
] |
u186967328 | p03283 | python | s782449569 | s349025375 | 2,774 | 1,600 | 56,024 | 15,528 | Accepted | Accepted | 42.32 | N,M,Q = list(map(int,input().split()))
train = [[0 for i in range(N)] for j in range(N)]
for m in range(M):
L,R = list(map(int,input().split()))
train[L-1][R-1] += 1
c = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
cnt = 0
for j in range(N):
cnt += train[i][j]
c[i][j] = cnt
for x in range(Q):
p,q = list(map(int,input().split()))
p -= 1
q -= 1
cnt2 = 0
for i in range(p,q+1):
if p == 0:
cnt2 += c[i][q]
else:
cnt2 += c[i][q] - c[i][p-1]
print(cnt2)
| N,M,Q = list(map(int,input().split()))
train = [[0 for i in range(N+1)] for j in range(N+1)]
for m in range(M):
L,R = list(map(int,input().split()))
train[L][R] += 1
c = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1,N+1):
cnt = 0
for j in range(1,N+1):
c[i][j] = train[i][j] + c[i-1][j] + c[i][j-1] - c[i-1][j-1]
for x in range(Q):
p,q = list(map(int,input().split()))
print((c[q][q]-c[q][p-1]-c[p-1][q]+c[p-1][p-1])) | 26 | 16 | 573 | 464 | N, M, Q = list(map(int, input().split()))
train = [[0 for i in range(N)] for j in range(N)]
for m in range(M):
L, R = list(map(int, input().split()))
train[L - 1][R - 1] += 1
c = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
cnt = 0
for j in range(N):
cnt += train[i][j]
c[i][j] = cnt
for x in range(Q):
p, q = list(map(int, input().split()))
p -= 1
q -= 1
cnt2 = 0
for i in range(p, q + 1):
if p == 0:
cnt2 += c[i][q]
else:
cnt2 += c[i][q] - c[i][p - 1]
print(cnt2)
| N, M, Q = list(map(int, input().split()))
train = [[0 for i in range(N + 1)] for j in range(N + 1)]
for m in range(M):
L, R = list(map(int, input().split()))
train[L][R] += 1
c = [[0 for i in range(N + 1)] for j in range(N + 1)]
for i in range(1, N + 1):
cnt = 0
for j in range(1, N + 1):
c[i][j] = train[i][j] + c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1]
for x in range(Q):
p, q = list(map(int, input().split()))
print((c[q][q] - c[q][p - 1] - c[p - 1][q] + c[p - 1][p - 1]))
| false | 38.461538 | [
"-train = [[0 for i in range(N)] for j in range(N)]",
"+train = [[0 for i in range(N + 1)] for j in range(N + 1)]",
"- train[L - 1][R - 1] += 1",
"-c = [[0 for i in range(N)] for j in range(N)]",
"-for i in range(N):",
"+ train[L][R] += 1",
"+c = [[0 for i in range(N + 1)] for j in range(N + 1)]",... | false | 0.113161 | 0.036509 | 3.099524 | [
"s782449569",
"s349025375"
] |
u977389981 | p03730 | python | s763563314 | s507717975 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | a, b, c = list(map(int, input().split()))
for i in range(1, b + 1):
if (a * i) % b == c:
ans = 'YES'
break
else:
ans = 'NO'
print(ans) | a, b, c = list(map(int, input().split()))
ans = 'NO'
for i in range(1, b + 1):
if (a * i) % b == c:
ans = 'YES'
print(ans) | 8 | 7 | 167 | 144 | a, b, c = list(map(int, input().split()))
for i in range(1, b + 1):
if (a * i) % b == c:
ans = "YES"
break
else:
ans = "NO"
print(ans)
| a, b, c = list(map(int, input().split()))
ans = "NO"
for i in range(1, b + 1):
if (a * i) % b == c:
ans = "YES"
print(ans)
| false | 12.5 | [
"+ans = \"NO\"",
"- break",
"- else:",
"- ans = \"NO\""
] | false | 0.046559 | 0.041832 | 1.113004 | [
"s763563314",
"s507717975"
] |
u851704997 | p02785 | python | s583999853 | s280273080 | 151 | 112 | 26,024 | 31,680 | Accepted | Accepted | 25.83 | N,K = list(map(int,input().split()))
H = list(map(int,input().split()))
H = sorted(H)[::-1]
del H [0:K]
print((str(sum(H)))) | N,K = list(map(int,input().split()))
H = list(map(int,input().split()))
H = sorted(H)[::-1]
H = H[K:N]
print((str(sum(H)))) | 5 | 5 | 120 | 119 | N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
H = sorted(H)[::-1]
del H[0:K]
print((str(sum(H))))
| N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
H = sorted(H)[::-1]
H = H[K:N]
print((str(sum(H))))
| false | 0 | [
"-del H[0:K]",
"+H = H[K:N]"
] | false | 0.092572 | 0.045086 | 2.053231 | [
"s583999853",
"s280273080"
] |
u392319141 | p03880 | python | s714782629 | s362624448 | 253 | 205 | 11,036 | 7,072 | Accepted | Accepted | 18.97 | N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A.sort(reverse=True, key=lambda a: (a & -a))
xor = 0
for a in A:
xor ^= a
left = 0
ans = 0
for digit in range(xor.bit_length() + 1)[:: -1]:
if (xor & (1 << digit)) > 0:
while left < N and ((A[left] & -A[left]).bit_length() - 1) > digit:
left += 1
if left >= N or ((A[left] & -A[left]).bit_length() - 1) != digit:
print((-1))
exit()
ans += 1
xor ^= ((1 << (digit + 1)) - 1)
print(ans) | N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
digits = set()
for a in A:
digits.add((a & -a).bit_length() - 1)
xor = 0
for a in A:
xor ^= a
ans = 0
for digit in range(xor.bit_length() + 1)[:: -1]:
if (xor & (1 << digit)) > 0:
if digit in digits:
ans += 1
xor ^= ((1 << (digit + 1)) - 1)
else:
print((-1))
exit()
print(ans) | 25 | 24 | 542 | 433 | N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A.sort(reverse=True, key=lambda a: (a & -a))
xor = 0
for a in A:
xor ^= a
left = 0
ans = 0
for digit in range(xor.bit_length() + 1)[::-1]:
if (xor & (1 << digit)) > 0:
while left < N and ((A[left] & -A[left]).bit_length() - 1) > digit:
left += 1
if left >= N or ((A[left] & -A[left]).bit_length() - 1) != digit:
print((-1))
exit()
ans += 1
xor ^= (1 << (digit + 1)) - 1
print(ans)
| N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
digits = set()
for a in A:
digits.add((a & -a).bit_length() - 1)
xor = 0
for a in A:
xor ^= a
ans = 0
for digit in range(xor.bit_length() + 1)[::-1]:
if (xor & (1 << digit)) > 0:
if digit in digits:
ans += 1
xor ^= (1 << (digit + 1)) - 1
else:
print((-1))
exit()
print(ans)
| false | 4 | [
"-A.sort(reverse=True, key=lambda a: (a & -a))",
"+digits = set()",
"+for a in A:",
"+ digits.add((a & -a).bit_length() - 1)",
"-left = 0",
"- while left < N and ((A[left] & -A[left]).bit_length() - 1) > digit:",
"- left += 1",
"- if left >= N or ((A[left] & -A[left]).bit_l... | false | 0.036582 | 0.060102 | 0.608654 | [
"s714782629",
"s362624448"
] |
u347600233 | p02642 | python | s847495178 | s474849491 | 472 | 428 | 31,952 | 31,992 | Accepted | Accepted | 9.32 | n = int(eval(input()))
a = sorted([int(i) for i in input().split()])
max_a = max(a)
cnt_d = [0] * (max_a + 1)
for ai in a:
for multi in range(ai, max_a + 1, ai):
cnt_d[multi] += 1
print((sum(cnt_d[ai] == 1 for ai in a))) | n = int(eval(input()))
a = [int(i) for i in input().split()]
max_a = max(a)
cnt_d = [0] * (max_a + 1)
for ai in a:
for multi in range(ai, max_a + 1, ai):
cnt_d[multi] += 1
print((sum(cnt_d[ai] == 1 for ai in a))) | 10 | 10 | 235 | 227 | n = int(eval(input()))
a = sorted([int(i) for i in input().split()])
max_a = max(a)
cnt_d = [0] * (max_a + 1)
for ai in a:
for multi in range(ai, max_a + 1, ai):
cnt_d[multi] += 1
print((sum(cnt_d[ai] == 1 for ai in a)))
| n = int(eval(input()))
a = [int(i) for i in input().split()]
max_a = max(a)
cnt_d = [0] * (max_a + 1)
for ai in a:
for multi in range(ai, max_a + 1, ai):
cnt_d[multi] += 1
print((sum(cnt_d[ai] == 1 for ai in a)))
| false | 0 | [
"-a = sorted([int(i) for i in input().split()])",
"+a = [int(i) for i in input().split()]"
] | false | 0.0366 | 0.034985 | 1.046173 | [
"s847495178",
"s474849491"
] |
u368780724 | p03148 | python | s073160636 | s454446010 | 723 | 575 | 23,788 | 59,368 | Accepted | Accepted | 20.47 | import sys, itertools
#def input(): return sys.stdin.readline()
def inpl(): return [int(i) for i in input().split()]
N, K = inpl()
Sushi = []
Neta = set()
ans = 0
for _ in range(N):
t, d = inpl()
Sushi.append((d, t))
Sushi.sort(reverse = True)
Db = []
Nd = []
for i in range(K):
d, t = Sushi[i]
if t not in Neta:
Neta.add(t)
ans += d
else:
Db.append(d)
neta = len(Neta)
Db = [0] + list(itertools.accumulate(Db))
Db.reverse()
for i in range(N-K):
d, t = Sushi[K+i]
if t not in Neta:
Neta.add(t)
Nd.append(d)
Nd = [0] + list(itertools.accumulate(Nd))
print((ans + max([(neta + i)**2 + j + k for i, (j, k) in enumerate(zip(Db, Nd))]))) | import sys, itertools
def input(): return sys.stdin.readline()
def inpl(): return [int(i) for i in input().split()]
N, K = inpl()
Sushi = []
Neta = set()
ans = 0
for _ in range(N):
t, d = inpl()
Sushi.append((d, t))
Sushi.sort(reverse = True)
Db = []
Nd = []
for i in range(K):
d, t = Sushi[i]
if t not in Neta:
Neta.add(t)
ans += d
else:
Db.append(d)
neta = len(Neta)
Db = [0] + list(itertools.accumulate(Db))
Db.reverse()
for i in range(N-K):
d, t = Sushi[K+i]
if t not in Neta:
Neta.add(t)
Nd.append(d)
Nd = [0] + list(itertools.accumulate(Nd))
print((ans + max([(neta + i)**2 + j + k for i, (j, k) in enumerate(zip(Db, Nd))]))) | 30 | 30 | 727 | 726 | import sys, itertools
# def input(): return sys.stdin.readline()
def inpl():
return [int(i) for i in input().split()]
N, K = inpl()
Sushi = []
Neta = set()
ans = 0
for _ in range(N):
t, d = inpl()
Sushi.append((d, t))
Sushi.sort(reverse=True)
Db = []
Nd = []
for i in range(K):
d, t = Sushi[i]
if t not in Neta:
Neta.add(t)
ans += d
else:
Db.append(d)
neta = len(Neta)
Db = [0] + list(itertools.accumulate(Db))
Db.reverse()
for i in range(N - K):
d, t = Sushi[K + i]
if t not in Neta:
Neta.add(t)
Nd.append(d)
Nd = [0] + list(itertools.accumulate(Nd))
print((ans + max([(neta + i) ** 2 + j + k for i, (j, k) in enumerate(zip(Db, Nd))])))
| import sys, itertools
def input():
return sys.stdin.readline()
def inpl():
return [int(i) for i in input().split()]
N, K = inpl()
Sushi = []
Neta = set()
ans = 0
for _ in range(N):
t, d = inpl()
Sushi.append((d, t))
Sushi.sort(reverse=True)
Db = []
Nd = []
for i in range(K):
d, t = Sushi[i]
if t not in Neta:
Neta.add(t)
ans += d
else:
Db.append(d)
neta = len(Neta)
Db = [0] + list(itertools.accumulate(Db))
Db.reverse()
for i in range(N - K):
d, t = Sushi[K + i]
if t not in Neta:
Neta.add(t)
Nd.append(d)
Nd = [0] + list(itertools.accumulate(Nd))
print((ans + max([(neta + i) ** 2 + j + k for i, (j, k) in enumerate(zip(Db, Nd))])))
| false | 0 | [
"-# def input(): return sys.stdin.readline()",
"+",
"+def input():",
"+ return sys.stdin.readline()",
"+",
"+"
] | false | 0.04732 | 0.042725 | 1.107558 | [
"s073160636",
"s454446010"
] |
u350997995 | p03221 | python | s792813473 | s077137910 | 1,736 | 709 | 30,396 | 32,028 | Accepted | Accepted | 59.16 | N,M = list(map(int,input().split()))
P = []
Y = []
arr = [[]for j in range(10**5+1)]
for i in range(M):
listA = list(map(int,input().split()))
P.append(listA[0])
Y.append(listA[1])
arr[listA[0]].append(listA[1])
for i in range(N+1):
arr[i].sort()
for i in range(M):
#二部探索
left = 0
right = len(arr[P[i]])-1
while left <= right:
mid = (left+right)//2
if arr[P[i]][mid] == Y[i]:
k = mid
break
elif arr[P[i]][mid] > Y[i]:
right = mid-1
else:
left = mid+1
print((str(P[i]).rjust(6,'0')+str(k+1).rjust(6,'0'))) | N,M = list(map(int,input().split()))
A = []
for i in range(M):
p,y = list(map(int,input().split()))
A.append([p,y,i])
A.sort(key=lambda x:(x[0],x[1]))
ans = ["" for i in range(M)]
p = -1
y = 1
for a in A:
if p!=a[0]:
y = 1
p = a[0]
b = "0"*(6-len(str(a[0])))+str(a[0])+"0"*(6-len(str(y)))+str(y)
ans[a[2]] = b
y+=1
for i in ans:
print(i) | 25 | 18 | 580 | 386 | N, M = list(map(int, input().split()))
P = []
Y = []
arr = [[] for j in range(10**5 + 1)]
for i in range(M):
listA = list(map(int, input().split()))
P.append(listA[0])
Y.append(listA[1])
arr[listA[0]].append(listA[1])
for i in range(N + 1):
arr[i].sort()
for i in range(M):
# 二部探索
left = 0
right = len(arr[P[i]]) - 1
while left <= right:
mid = (left + right) // 2
if arr[P[i]][mid] == Y[i]:
k = mid
break
elif arr[P[i]][mid] > Y[i]:
right = mid - 1
else:
left = mid + 1
print((str(P[i]).rjust(6, "0") + str(k + 1).rjust(6, "0")))
| N, M = list(map(int, input().split()))
A = []
for i in range(M):
p, y = list(map(int, input().split()))
A.append([p, y, i])
A.sort(key=lambda x: (x[0], x[1]))
ans = ["" for i in range(M)]
p = -1
y = 1
for a in A:
if p != a[0]:
y = 1
p = a[0]
b = "0" * (6 - len(str(a[0]))) + str(a[0]) + "0" * (6 - len(str(y))) + str(y)
ans[a[2]] = b
y += 1
for i in ans:
print(i)
| false | 28 | [
"-P = []",
"-Y = []",
"-arr = [[] for j in range(10**5 + 1)]",
"+A = []",
"- listA = list(map(int, input().split()))",
"- P.append(listA[0])",
"- Y.append(listA[1])",
"- arr[listA[0]].append(listA[1])",
"-for i in range(N + 1):",
"- arr[i].sort()",
"-for i in range(M):",
"- #... | false | 0.072819 | 0.087984 | 0.82764 | [
"s792813473",
"s077137910"
] |
u970899068 | p03048 | python | s639406158 | s360723551 | 455 | 281 | 130,660 | 40,812 | Accepted | Accepted | 38.24 | import math
r,g,b,n=list(map(int, input().split()))
count=0
k=[]
for i in range(n+1):
for j in range(n+1):
if n-(i*g+j*r)>=0:
k.append(i*g+j*r)
else:
break
for i in range(len(k)):
if (n-k[i])%b==0:
count+=1
print(count)
| r,g,b,n= list(map(int, input().split()))
x=n//r
y=n//g
ans=0
for i in range(x+1):
for j in range(y+1):
v=n-r*i-g*j
if v<0:
continue
else:
if v%b==0:
ans+=1
print(ans) | 31 | 14 | 413 | 242 | import math
r, g, b, n = list(map(int, input().split()))
count = 0
k = []
for i in range(n + 1):
for j in range(n + 1):
if n - (i * g + j * r) >= 0:
k.append(i * g + j * r)
else:
break
for i in range(len(k)):
if (n - k[i]) % b == 0:
count += 1
print(count)
| r, g, b, n = list(map(int, input().split()))
x = n // r
y = n // g
ans = 0
for i in range(x + 1):
for j in range(y + 1):
v = n - r * i - g * j
if v < 0:
continue
else:
if v % b == 0:
ans += 1
print(ans)
| false | 54.83871 | [
"-import math",
"-",
"-count = 0",
"-k = []",
"-for i in range(n + 1):",
"- for j in range(n + 1):",
"- if n - (i * g + j * r) >= 0:",
"- k.append(i * g + j * r)",
"+x = n // r",
"+y = n // g",
"+ans = 0",
"+for i in range(x + 1):",
"+ for j in range(y + 1):",
"+ ... | false | 0.256224 | 0.119711 | 2.140345 | [
"s639406158",
"s360723551"
] |
u968166680 | p02659 | python | s291502516 | s788827988 | 85 | 61 | 71,340 | 61,928 | Accepted | Accepted | 28.24 | import sys
from decimal import Decimal
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def main():
A, B = list(map(Decimal, readline().split()))
print((int(A * B)))
return
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def main():
A, B = readline().split()
A = int(A)
B = int(B.replace('.', ''))
print((A * B // 100))
return
if __name__ == '__main__':
main()
| 19 | 20 | 319 | 327 | import sys
from decimal import Decimal
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def main():
A, B = list(map(Decimal, readline().split()))
print((int(A * B)))
return
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def main():
A, B = readline().split()
A = int(A)
B = int(B.replace(".", ""))
print((A * B // 100))
return
if __name__ == "__main__":
main()
| false | 5 | [
"-from decimal import Decimal",
"- A, B = list(map(Decimal, readline().split()))",
"- print((int(A * B)))",
"+ A, B = readline().split()",
"+ A = int(A)",
"+ B = int(B.replace(\".\", \"\"))",
"+ print((A * B // 100))"
] | false | 0.115536 | 0.048413 | 2.38647 | [
"s291502516",
"s788827988"
] |
u958506960 | p03146 | python | s913707932 | s202255298 | 339 | 27 | 17,016 | 9,180 | Accepted | Accepted | 92.04 | s = int(eval(input()))
def f(n):
if n%2 == 0:
return n // 2
else:
return 3*n + 1
a = []
for i in range(1, 1000001):
if i == 1:
a.append(s)
else:
n = a[i-2]
a.append(f(n))
b = []
for i, num in enumerate(a):
if num in b:
print((i+1))
break
b.append(num) | s = int(eval(input()))
def f(n):
if n%2 == 0:
return n // 2
else:
return 3*n + 1
a = [s]
for i in range(1, 1000001):
if a[i-1] in a[:i-1]:
print(i)
break
else:
a.append(f(a[i-1])) | 22 | 15 | 347 | 245 | s = int(eval(input()))
def f(n):
if n % 2 == 0:
return n // 2
else:
return 3 * n + 1
a = []
for i in range(1, 1000001):
if i == 1:
a.append(s)
else:
n = a[i - 2]
a.append(f(n))
b = []
for i, num in enumerate(a):
if num in b:
print((i + 1))
break
b.append(num)
| s = int(eval(input()))
def f(n):
if n % 2 == 0:
return n // 2
else:
return 3 * n + 1
a = [s]
for i in range(1, 1000001):
if a[i - 1] in a[: i - 1]:
print(i)
break
else:
a.append(f(a[i - 1]))
| false | 31.818182 | [
"-a = []",
"+a = [s]",
"- if i == 1:",
"- a.append(s)",
"+ if a[i - 1] in a[: i - 1]:",
"+ print(i)",
"+ break",
"- n = a[i - 2]",
"- a.append(f(n))",
"-b = []",
"-for i, num in enumerate(a):",
"- if num in b:",
"- print((i + 1))",
"- ... | false | 3.163334 | 0.036638 | 86.339903 | [
"s913707932",
"s202255298"
] |
u562935282 | p03331 | python | s075393090 | s644571537 | 183 | 156 | 3,060 | 9,076 | Accepted | Accepted | 14.75 | N = int(eval(input()))
ans = float('inf')
for a in range(1, N // 2 + 1):
b = N - a
t = 0
while a > 0:
a, r = divmod(a, 10)
t += r
while b > 0:
b, r = divmod(b, 10)
t += r
ans = min(t, ans)
print(ans)
| N = int(eval(input()))
def f(x):
ret = 0
while x:
x, r = divmod(x, 10)
ret += r
return ret
ret = 10 ** 9
for a in range(1, N):
b = N - a
ret = min(ret, f(a) + f(b))
print(ret)
| 17 | 16 | 266 | 225 | N = int(eval(input()))
ans = float("inf")
for a in range(1, N // 2 + 1):
b = N - a
t = 0
while a > 0:
a, r = divmod(a, 10)
t += r
while b > 0:
b, r = divmod(b, 10)
t += r
ans = min(t, ans)
print(ans)
| N = int(eval(input()))
def f(x):
ret = 0
while x:
x, r = divmod(x, 10)
ret += r
return ret
ret = 10**9
for a in range(1, N):
b = N - a
ret = min(ret, f(a) + f(b))
print(ret)
| false | 5.882353 | [
"-ans = float(\"inf\")",
"-for a in range(1, N // 2 + 1):",
"+",
"+",
"+def f(x):",
"+ ret = 0",
"+ while x:",
"+ x, r = divmod(x, 10)",
"+ ret += r",
"+ return ret",
"+",
"+",
"+ret = 10**9",
"+for a in range(1, N):",
"- t = 0",
"- while a > 0:",
"- ... | false | 0.081013 | 0.104032 | 0.778727 | [
"s075393090",
"s644571537"
] |
u716530146 | p03030 | python | s309673719 | s357939091 | 180 | 21 | 38,256 | 3,316 | Accepted | Accepted | 88.33 | n=int(eval(input()))
data=[tuple(input().split()+[i+1]) for i in range(n)]
data.sort(key=lambda tup:(tup[0],-int(tup[1])))
for i in data:
print((i[2])) | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n = int(eval(input()))
data = [input().split()+[i+1] for i in range(n)]
data.sort(key = lambda tup: (tup[0],-int(tup[1])))
for city , k,number in data:
print(number) | 5 | 11 | 148 | 387 | n = int(eval(input()))
data = [tuple(input().split() + [i + 1]) for i in range(n)]
data.sort(key=lambda tup: (tup[0], -int(tup[1])))
for i in data:
print((i[2]))
| #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
n = int(eval(input()))
data = [input().split() + [i + 1] for i in range(n)]
data.sort(key=lambda tup: (tup[0], -int(tup[1])))
for city, k, number in data:
print(number)
| false | 54.545455 | [
"+#!/usr/bin/env python3",
"+import sys, math, itertools, collections, bisect",
"+",
"+input = lambda: sys.stdin.buffer.readline().rstrip().decode(\"utf-8\")",
"+inf = float(\"inf\")",
"+mod = 10**9 + 7",
"+mans = inf",
"+ans = 0",
"+count = 0",
"+pro = 1",
"-data = [tuple(input().split() + [i +... | false | 0.036545 | 0.053063 | 0.688722 | [
"s309673719",
"s357939091"
] |
u392319141 | p03967 | python | s531395202 | s542518480 | 195 | 37 | 39,408 | 3,316 | Accepted | Accepted | 81.03 | S = eval(input())
count = 0
for s in S :
if s == 'p' :
count += 1
ans = -count + len(S) // 2
print(ans) | S = eval(input())
now = 0
ans = 0
for s in S:
if now == 0:
now += 1
if s == 'p':
ans -= 1
continue
if s == 'g':
ans += 1
now -= 1
print(ans)
| 9 | 15 | 119 | 207 | S = eval(input())
count = 0
for s in S:
if s == "p":
count += 1
ans = -count + len(S) // 2
print(ans)
| S = eval(input())
now = 0
ans = 0
for s in S:
if now == 0:
now += 1
if s == "p":
ans -= 1
continue
if s == "g":
ans += 1
now -= 1
print(ans)
| false | 40 | [
"-count = 0",
"+now = 0",
"+ans = 0",
"- if s == \"p\":",
"- count += 1",
"-ans = -count + len(S) // 2",
"+ if now == 0:",
"+ now += 1",
"+ if s == \"p\":",
"+ ans -= 1",
"+ continue",
"+ if s == \"g\":",
"+ ans += 1",
"+ now -= 1"
... | false | 0.052568 | 0.03989 | 1.317823 | [
"s531395202",
"s542518480"
] |
u325119213 | p02712 | python | s369469549 | s009986002 | 187 | 170 | 9,092 | 9,152 | Accepted | Accepted | 9.09 | N = int(eval(input()))
amount = 0
for i in range(1, N + 1):
is_fizzbuzz = (i % 3 == 0) or (i % 5 == 0)
if not is_fizzbuzz:
amount += i
print(amount)
| n = int(eval(input()))
summation = 0
for i in range(1, n + 1):
if (i % 3 != 0) and (i % 5 != 0):
summation += i
print(summation)
| 11 | 9 | 173 | 150 | N = int(eval(input()))
amount = 0
for i in range(1, N + 1):
is_fizzbuzz = (i % 3 == 0) or (i % 5 == 0)
if not is_fizzbuzz:
amount += i
print(amount)
| n = int(eval(input()))
summation = 0
for i in range(1, n + 1):
if (i % 3 != 0) and (i % 5 != 0):
summation += i
print(summation)
| false | 18.181818 | [
"-N = int(eval(input()))",
"-amount = 0",
"-for i in range(1, N + 1):",
"- is_fizzbuzz = (i % 3 == 0) or (i % 5 == 0)",
"- if not is_fizzbuzz:",
"- amount += i",
"-print(amount)",
"+n = int(eval(input()))",
"+summation = 0",
"+for i in range(1, n + 1):",
"+ if (i % 3 != 0) and (i... | false | 0.199214 | 0.171664 | 1.160486 | [
"s369469549",
"s009986002"
] |
u678167152 | p03162 | python | s257358123 | s990589504 | 569 | 246 | 47,288 | 87,548 | Accepted | Accepted | 56.77 | N = int(eval(input()))
A = [0]*N
for i in range(N):
A[i] = list(map(int, input().split()))
def solve(N,A):
dp = [[0]*3 for i in range(N)]
dp[0][0] = A[0][0]
dp[0][1] = A[0][1]
dp[0][2] = A[0][2]
for i in range(1,N):
dp[i][0] = max(dp[i-1][1],dp[i-1][2])+A[i][0]
dp[i][1] = max(dp[i-1][0],dp[i-1][2])+A[i][1]
dp[i][2] = max(dp[i-1][0],dp[i-1][1])+A[i][2]
ans = max(dp[-1])
return ans
print((solve(N,A))) | def solve():
N = int(eval(input()))
dp = [[float('inf')]*3 for _ in range(N)]
dp[0] = list(map(int, input().split()))
for i in range(1,N):
a, b, c = list(map(int, input().split()))
dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a
dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b
dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c
ans = max(dp[-1])
return ans
print((solve())) | 16 | 12 | 465 | 371 | N = int(eval(input()))
A = [0] * N
for i in range(N):
A[i] = list(map(int, input().split()))
def solve(N, A):
dp = [[0] * 3 for i in range(N)]
dp[0][0] = A[0][0]
dp[0][1] = A[0][1]
dp[0][2] = A[0][2]
for i in range(1, N):
dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + A[i][0]
dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + A[i][1]
dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + A[i][2]
ans = max(dp[-1])
return ans
print((solve(N, A)))
| def solve():
N = int(eval(input()))
dp = [[float("inf")] * 3 for _ in range(N)]
dp[0] = list(map(int, input().split()))
for i in range(1, N):
a, b, c = list(map(int, input().split()))
dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a
dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b
dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c
ans = max(dp[-1])
return ans
print((solve()))
| false | 25 | [
"-N = int(eval(input()))",
"-A = [0] * N",
"-for i in range(N):",
"- A[i] = list(map(int, input().split()))",
"-",
"-",
"-def solve(N, A):",
"- dp = [[0] * 3 for i in range(N)]",
"- dp[0][0] = A[0][0]",
"- dp[0][1] = A[0][1]",
"- dp[0][2] = A[0][2]",
"+def solve():",
"+ N =... | false | 0.036086 | 0.040646 | 0.887798 | [
"s257358123",
"s990589504"
] |
u386819480 | p02848 | python | s564249464 | s446213993 | 22 | 20 | 3,188 | 3,060 | Accepted | Accepted | 9.09 | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32
a = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
def solve(N: int, S: str):
al = a+a
ans = []
for i in range(len(S)):
ans += al[al.index(S[i])+N]
print((''.join(ans)))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
solve(N, S)
if __name__ == '__main__':
main() | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32
def solve(N: int, S: str):
print((''.join([chr((ord(i)+N-ord('A'))%26 + ord('A')) for i in S])))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
solve(N, S)
if __name__ == '__main__':
main()
| 30 | 24 | 595 | 508 | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1 << 32
a = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
def solve(N: int, S: str):
al = a + a
ans = []
for i in range(len(S)):
ans += al[al.index(S[i]) + N]
print(("".join(ans)))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
solve(N, S)
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1 << 32
def solve(N: int, S: str):
print(("".join([chr((ord(i) + N - ord("A")) % 26 + ord("A")) for i in S])))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
solve(N, S)
if __name__ == "__main__":
main()
| false | 20 | [
"-a = list(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\")",
"- al = a + a",
"- ans = []",
"- for i in range(len(S)):",
"- ans += al[al.index(S[i]) + N]",
"- print((\"\".join(ans)))",
"+ print((\"\".join([chr((ord(i) + N - ord(\"A\")) % 26 + ord(\"A\")) for i in S])))"
] | false | 0.046074 | 0.046048 | 1.000562 | [
"s564249464",
"s446213993"
] |
u600402037 | p02792 | python | s215088243 | s118732898 | 748 | 343 | 12,496 | 12,500 | Accepted | Accepted | 54.14 | import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
# Aの先頭の桁と末尾の桁の組み合わせは9*10=90通りだけ
table = np.zeros((10, 10)).astype(int)
for x in range(1, N+1):
x = str(x)
i = int(x[0])
j = int(x[-1])
table[i][j] += 1
table = np.array(table)
answer = (table * table.T).sum()
print(answer)
| import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
# Aの先頭の桁と末尾の桁の組み合わせは9*10=90通りだけ
table = [[0] * 10 for i in range(10)]
for x in range(1, N+1):
x = str(x)
i = int(x[0])
j = int(x[-1])
table[i][j] += 1
table = np.array(table)
answer = (table * table.T).sum()
print(answer)
| 19 | 19 | 407 | 406 | import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
# Aの先頭の桁と末尾の桁の組み合わせは9*10=90通りだけ
table = np.zeros((10, 10)).astype(int)
for x in range(1, N + 1):
x = str(x)
i = int(x[0])
j = int(x[-1])
table[i][j] += 1
table = np.array(table)
answer = (table * table.T).sum()
print(answer)
| import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
# Aの先頭の桁と末尾の桁の組み合わせは9*10=90通りだけ
table = [[0] * 10 for i in range(10)]
for x in range(1, N + 1):
x = str(x)
i = int(x[0])
j = int(x[-1])
table[i][j] += 1
table = np.array(table)
answer = (table * table.T).sum()
print(answer)
| false | 0 | [
"-table = np.zeros((10, 10)).astype(int)",
"+table = [[0] * 10 for i in range(10)]"
] | false | 0.353256 | 0.457673 | 0.771852 | [
"s215088243",
"s118732898"
] |
u891635666 | p03385 | python | s838812382 | s102087456 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | if ''.join(sorted(input().strip())) == 'abc':
print('Yes')
else:
print('No') | if len(set(input().strip())) == 3:
print('Yes')
else:
print('No') | 4 | 4 | 87 | 76 | if "".join(sorted(input().strip())) == "abc":
print("Yes")
else:
print("No")
| if len(set(input().strip())) == 3:
print("Yes")
else:
print("No")
| false | 0 | [
"-if \"\".join(sorted(input().strip())) == \"abc\":",
"+if len(set(input().strip())) == 3:"
] | false | 0.042565 | 0.04313 | 0.986902 | [
"s838812382",
"s102087456"
] |
u945181840 | p03682 | python | s151426315 | s967193530 | 1,201 | 742 | 35,556 | 49,012 | Accepted | Accepted | 38.22 | import sys
import numpy as np
read = sys.stdin.read
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, *xy = list(map(int, read().split()))
xy = np.array(xy, np.int64).reshape(N, 2)
x = xy[:, 0]
y = xy[:, 1]
arg_x = np.argsort(x)
arg_y = np.argsort(y)
edges_x = x[arg_x[1:]] - x[arg_x[:-1]]
edges_y = y[arg_y[1:]] - y[arg_y[:-1]]
edges = np.concatenate([edges_x, edges_y])
towns_1 = np.concatenate([arg_x[:-1], arg_y[:-1]])
towns_2 = np.concatenate([arg_x[1:], arg_y[1:]])
arg_edges = np.argsort(edges)
graph = list(zip(edges[arg_edges], towns_1[arg_edges], towns_2[arg_edges]))
tree = UnionFind(N)
answer = 0
for d, t1, t2 in graph:
if tree.isSameGroup(t1, t2):
continue
tree.Unite(t1, t2)
answer += d
print(answer) | import sys
import numpy as np
read = sys.stdin.read
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, *xy = list(map(int, read().split()))
xy = np.array(xy, np.int64).reshape(N, 2)
x = xy[:, 0]
y = xy[:, 1]
arg_x = np.argsort(x)
arg_y = np.argsort(y)
edges_x = x[arg_x[1:]] - x[arg_x[:-1]]
edges_y = y[arg_y[1:]] - y[arg_y[:-1]]
edges = np.concatenate([edges_x, edges_y])
towns_1 = np.concatenate([arg_x[:-1], arg_y[:-1]])
towns_2 = np.concatenate([arg_x[1:], arg_y[1:]])
arg_edges = np.argsort(edges)
graph = list(zip(edges[arg_edges].tolist(), towns_1[arg_edges].tolist(), towns_2[arg_edges].tolist()))
tree = UnionFind(N)
answer = 0
for d, t1, t2 in graph:
if tree.isSameGroup(t1, t2):
continue
tree.Unite(t1, t2)
answer += d
print(answer) | 83 | 83 | 2,044 | 2,071 | import sys
import numpy as np
read = sys.stdin.read
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, *xy = list(map(int, read().split()))
xy = np.array(xy, np.int64).reshape(N, 2)
x = xy[:, 0]
y = xy[:, 1]
arg_x = np.argsort(x)
arg_y = np.argsort(y)
edges_x = x[arg_x[1:]] - x[arg_x[:-1]]
edges_y = y[arg_y[1:]] - y[arg_y[:-1]]
edges = np.concatenate([edges_x, edges_y])
towns_1 = np.concatenate([arg_x[:-1], arg_y[:-1]])
towns_2 = np.concatenate([arg_x[1:], arg_y[1:]])
arg_edges = np.argsort(edges)
graph = list(zip(edges[arg_edges], towns_1[arg_edges], towns_2[arg_edges]))
tree = UnionFind(N)
answer = 0
for d, t1, t2 in graph:
if tree.isSameGroup(t1, t2):
continue
tree.Unite(t1, t2)
answer += d
print(answer)
| import sys
import numpy as np
read = sys.stdin.read
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, *xy = list(map(int, read().split()))
xy = np.array(xy, np.int64).reshape(N, 2)
x = xy[:, 0]
y = xy[:, 1]
arg_x = np.argsort(x)
arg_y = np.argsort(y)
edges_x = x[arg_x[1:]] - x[arg_x[:-1]]
edges_y = y[arg_y[1:]] - y[arg_y[:-1]]
edges = np.concatenate([edges_x, edges_y])
towns_1 = np.concatenate([arg_x[:-1], arg_y[:-1]])
towns_2 = np.concatenate([arg_x[1:], arg_y[1:]])
arg_edges = np.argsort(edges)
graph = list(
zip(
edges[arg_edges].tolist(),
towns_1[arg_edges].tolist(),
towns_2[arg_edges].tolist(),
)
)
tree = UnionFind(N)
answer = 0
for d, t1, t2 in graph:
if tree.isSameGroup(t1, t2):
continue
tree.Unite(t1, t2)
answer += d
print(answer)
| false | 0 | [
"-graph = list(zip(edges[arg_edges], towns_1[arg_edges], towns_2[arg_edges]))",
"+graph = list(",
"+ zip(",
"+ edges[arg_edges].tolist(),",
"+ towns_1[arg_edges].tolist(),",
"+ towns_2[arg_edges].tolist(),",
"+ )",
"+)"
] | false | 0.288937 | 0.226156 | 1.277604 | [
"s151426315",
"s967193530"
] |
u930705402 | p02720 | python | s071642716 | s141735864 | 280 | 64 | 56,060 | 7,964 | Accepted | Accepted | 77.14 | from collections import deque
li=[i for i in range(1,10)]
def bfs(K):
d=deque()
for i in range(1,10):
d.append(str(i))
while(len(li)<K):
s=d[0]
d.popleft()
now=[int(s+s[-1])]
if(s[-1]!='0'):
now.append(int(s+str(int(s[-1])-1)))
if(s[-1]!='9'):
now.append(int(s+str(int(s[-1])+1)))
now.sort()
for i in range(len(now)):
li.append(now[i])
d.append(str(now[i]))
K=int(eval(input()))
bfs(K)
print((li[K-1])) | from collections import deque
lunlun=[i for i in range(1,10)]
def bfs(K):
d=deque([1,2,3,4,5,6,7,8,9])
while(len(lunlun)<K):
s=d[0]
d.popleft()
n=[]
if(s%10!=0):
n.append((s%10-1)+s*10)
n.append(s%10+s*10)
if(s%10!=9):
n.append((s%10+1)+s*10)
lunlun.extend(n);d.extend(n)
K=int(eval(input()))
bfs(K)
print((lunlun[K-1])) | 21 | 17 | 538 | 416 | from collections import deque
li = [i for i in range(1, 10)]
def bfs(K):
d = deque()
for i in range(1, 10):
d.append(str(i))
while len(li) < K:
s = d[0]
d.popleft()
now = [int(s + s[-1])]
if s[-1] != "0":
now.append(int(s + str(int(s[-1]) - 1)))
if s[-1] != "9":
now.append(int(s + str(int(s[-1]) + 1)))
now.sort()
for i in range(len(now)):
li.append(now[i])
d.append(str(now[i]))
K = int(eval(input()))
bfs(K)
print((li[K - 1]))
| from collections import deque
lunlun = [i for i in range(1, 10)]
def bfs(K):
d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
while len(lunlun) < K:
s = d[0]
d.popleft()
n = []
if s % 10 != 0:
n.append((s % 10 - 1) + s * 10)
n.append(s % 10 + s * 10)
if s % 10 != 9:
n.append((s % 10 + 1) + s * 10)
lunlun.extend(n)
d.extend(n)
K = int(eval(input()))
bfs(K)
print((lunlun[K - 1]))
| false | 19.047619 | [
"-li = [i for i in range(1, 10)]",
"+lunlun = [i for i in range(1, 10)]",
"- d = deque()",
"- for i in range(1, 10):",
"- d.append(str(i))",
"- while len(li) < K:",
"+ d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])",
"+ while len(lunlun) < K:",
"- now = [int(s + s[-1])]",
"- ... | false | 0.091144 | 0.040466 | 2.252381 | [
"s071642716",
"s141735864"
] |
u498487134 | p03295 | python | s245852531 | s732830335 | 837 | 622 | 54,432 | 57,556 | Accepted | Accepted | 25.69 | N,M=list(map(int,input().split()))
ba=[[0,0] for _ in range(M)]
for i in range(M):
ba[i][1],ba[i][0]=list(map(int,input().split()))
ba.sort()
ans=0
prev=-1#直近で橋を落とした位置
for i in range(M):
if prev<ba[i][1] or prev>ba[i][0]:
ans+=1
prev=ba[i][0]-1
print(ans)
| 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,M=MI()
ab=[[0,0]for _ in range(M)]
for i in range(M):
ab[i][0],ab[i][1]=MI()
ab.sort(key=lambda x:(x[0],-1*x[1]))
ans=0
left=-1
right=N+1
for i in range(M):
if ab[i][0]>=right:
left=ab[i][0]
right=ab[i][1]
ans+=1
else:
left=ab[i][0]
right=min(right,ab[i][1])
print((ans+1))
main()
| 20 | 33 | 307 | 684 | N, M = list(map(int, input().split()))
ba = [[0, 0] for _ in range(M)]
for i in range(M):
ba[i][1], ba[i][0] = list(map(int, input().split()))
ba.sort()
ans = 0
prev = -1 # 直近で橋を落とした位置
for i in range(M):
if prev < ba[i][1] or prev > ba[i][0]:
ans += 1
prev = ba[i][0] - 1
print(ans)
| 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, M = MI()
ab = [[0, 0] for _ in range(M)]
for i in range(M):
ab[i][0], ab[i][1] = MI()
ab.sort(key=lambda x: (x[0], -1 * x[1]))
ans = 0
left = -1
right = N + 1
for i in range(M):
if ab[i][0] >= right:
left = ab[i][0]
right = ab[i][1]
ans += 1
else:
left = ab[i][0]
right = min(right, ab[i][1])
print((ans + 1))
main()
| false | 39.393939 | [
"-N, M = list(map(int, input().split()))",
"-ba = [[0, 0] for _ in range(M)]",
"-for i in range(M):",
"- ba[i][1], ba[i][0] = list(map(int, input().split()))",
"-ba.sort()",
"-ans = 0",
"-prev = -1 # 直近で橋を落とした位置",
"-for i in range(M):",
"- if prev < ba[i][1] or prev > ba[i][0]:",
"- ... | false | 0.038071 | 0.038014 | 1.0015 | [
"s245852531",
"s732830335"
] |
u640319601 | p03240 | python | s297622283 | s942979929 | 607 | 407 | 3,316 | 3,316 | Accepted | Accepted | 32.95 | from collections import defaultdict
N = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(N)]
for x, y, h in l:
if h == 0:
continue
for Cx in range(0, 101):
for Cy in range(0, 101):
ans = True
H = abs(Cx-x) + abs(Cy-y) + h
for xx, yy, hh in l:
if hh != max(H - abs(Cx-xx) - abs(Cy-yy), 0):
ans = False
if ans:
print((Cx, Cy, H))
exit()
| from collections import defaultdict
N = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(N)]
for x, y, h in l:
if h == 0:
continue
for Cx in range(0, 101):
for Cy in range(0, 101):
H = abs(Cx-x) + abs(Cy-y) + h
if all([hh == max(H - abs(Cx-xx) - abs(Cy-yy), 0) for xx, yy, hh in l]):
print((Cx, Cy, H))
exit() | 20 | 14 | 519 | 418 | from collections import defaultdict
N = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(N)]
for x, y, h in l:
if h == 0:
continue
for Cx in range(0, 101):
for Cy in range(0, 101):
ans = True
H = abs(Cx - x) + abs(Cy - y) + h
for xx, yy, hh in l:
if hh != max(H - abs(Cx - xx) - abs(Cy - yy), 0):
ans = False
if ans:
print((Cx, Cy, H))
exit()
| from collections import defaultdict
N = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(N)]
for x, y, h in l:
if h == 0:
continue
for Cx in range(0, 101):
for Cy in range(0, 101):
H = abs(Cx - x) + abs(Cy - y) + h
if all([hh == max(H - abs(Cx - xx) - abs(Cy - yy), 0) for xx, yy, hh in l]):
print((Cx, Cy, H))
exit()
| false | 30 | [
"- ans = True",
"- for xx, yy, hh in l:",
"- if hh != max(H - abs(Cx - xx) - abs(Cy - yy), 0):",
"- ans = False",
"- if ans:",
"+ if all([hh == max(H - abs(Cx - xx) - abs(Cy - yy), 0) for xx, yy, hh in l]):"
] | false | 0.052765 | 0.05272 | 1.00086 | [
"s297622283",
"s942979929"
] |
u652656291 | p02813 | python | s320132093 | s889376681 | 32 | 18 | 8,052 | 3,064 | Accepted | Accepted | 43.75 | from itertools import *
n = int(eval(input()))
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
a = [i+1 for i in range(n)]
for i,per in enumerate(list(permutations(a))):
if per == p:
x = i
if per == q:
y = i
print((abs(x-y)))
| N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
L = [i+1 for i in range(N)]
R = [i+1 for i in range(N)]
A,B = 0,0
for i in range(N-1):
A *= N-i
B *= N-i
A += L.index(P[i])
B += R.index(Q[i])
L[L.index(P[i])] = 100
R[R.index(Q[i])] = 100
L.sort()
R.sort()
print((abs(A-B)))
| 12 | 16 | 278 | 357 | from itertools import *
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
a = [i + 1 for i in range(n)]
for i, per in enumerate(list(permutations(a))):
if per == p:
x = i
if per == q:
y = i
print((abs(x - y)))
| N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
L = [i + 1 for i in range(N)]
R = [i + 1 for i in range(N)]
A, B = 0, 0
for i in range(N - 1):
A *= N - i
B *= N - i
A += L.index(P[i])
B += R.index(Q[i])
L[L.index(P[i])] = 100
R[R.index(Q[i])] = 100
L.sort()
R.sort()
print((abs(A - B)))
| false | 25 | [
"-from itertools import *",
"-",
"-n = int(eval(input()))",
"-p = tuple(map(int, input().split()))",
"-q = tuple(map(int, input().split()))",
"-a = [i + 1 for i in range(n)]",
"-for i, per in enumerate(list(permutations(a))):",
"- if per == p:",
"- x = i",
"- if per == q:",
"- ... | false | 0.040678 | 0.047709 | 0.852634 | [
"s320132093",
"s889376681"
] |
u620084012 | p04031 | python | s934445180 | s312081695 | 186 | 23 | 38,896 | 3,060 | Accepted | Accepted | 87.63 | N = int(eval(input()))
A = list(map(int,input().split()))
ans = 100*100*100
for d in range(-100,101):
t = 0
for e in A:
t += (e-d)**2
ans = min(t,ans)
print(ans)
| import sys, math
def input():
return sys.stdin.readline()[:-1]
def main():
N = int(eval(input()))
a = list(map(int,input().split()))
ans = 10**9
for k in range(-100,101):
temp = 0
for e in a:
temp += (k-e)**2
ans = min(ans,temp)
print(ans)
if __name__ == '__main__':
main()
| 9 | 17 | 184 | 350 | N = int(eval(input()))
A = list(map(int, input().split()))
ans = 100 * 100 * 100
for d in range(-100, 101):
t = 0
for e in A:
t += (e - d) ** 2
ans = min(t, ans)
print(ans)
| import sys, math
def input():
return sys.stdin.readline()[:-1]
def main():
N = int(eval(input()))
a = list(map(int, input().split()))
ans = 10**9
for k in range(-100, 101):
temp = 0
for e in a:
temp += (k - e) ** 2
ans = min(ans, temp)
print(ans)
if __name__ == "__main__":
main()
| false | 47.058824 | [
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-ans = 100 * 100 * 100",
"-for d in range(-100, 101):",
"- t = 0",
"- for e in A:",
"- t += (e - d) ** 2",
"- ans = min(t, ans)",
"-print(ans)",
"+import sys, math",
"+",
"+",
"+def input():",
"+ return ... | false | 0.036429 | 0.035857 | 1.015968 | [
"s934445180",
"s312081695"
] |
u263830634 | p03033 | python | s490660882 | s379607230 | 1,544 | 1,062 | 79,120 | 67,736 | Accepted | Accepted | 31.22 | def main():
import sys
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
used = defaultdict(int)
tank = []
p = []
p_append = p.append
for i in range(N):
s, t, x = list(map(int, input().split()))
p_append((s - x, x))
p_append((t - x, -x))
p.sort()
cnt = 0
for i in range(Q):
d = int(eval(input()))
while cnt <= len(p) - 1 and p[cnt][0] <= d:
w = p[cnt][1]
if w >= 0:
used[w] += 1
heappush(tank, w)
else:
used[-w] -= 1
cnt += 1
while True:
if len(tank) == 0:
print((-1))
break
kouho = tank[0]
if used[kouho] > 0:
print (kouho)
break
else:
heappop(tank)
if __name__ == '__main__':
main() | def main():
import sys
input = sys.stdin.readline
from bisect import bisect_left
N, Q = list(map(int, input().split()))
c = []
c_append = c.append
for _ in range(N):
s, t, x = list(map(int, input().split()))
c_append((x, s, t))
c.sort()
D = [int(eval(input())) for _ in range(Q)]
ans = [-1] * Q
skip = [-1] * Q
for x, s, t in c:
left = bisect_left(D, s - x)
right = bisect_left(D, t - x)
while left < right:
if skip[left] == -1:
ans[left] = x
skip[left] = right
left += 1
else:
left = skip[left]
print(('\n'.join(map(str, ans))))
if __name__ == '__main__':
main() | 42 | 33 | 1,030 | 766 | def main():
import sys
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
used = defaultdict(int)
tank = []
p = []
p_append = p.append
for i in range(N):
s, t, x = list(map(int, input().split()))
p_append((s - x, x))
p_append((t - x, -x))
p.sort()
cnt = 0
for i in range(Q):
d = int(eval(input()))
while cnt <= len(p) - 1 and p[cnt][0] <= d:
w = p[cnt][1]
if w >= 0:
used[w] += 1
heappush(tank, w)
else:
used[-w] -= 1
cnt += 1
while True:
if len(tank) == 0:
print((-1))
break
kouho = tank[0]
if used[kouho] > 0:
print(kouho)
break
else:
heappop(tank)
if __name__ == "__main__":
main()
| def main():
import sys
input = sys.stdin.readline
from bisect import bisect_left
N, Q = list(map(int, input().split()))
c = []
c_append = c.append
for _ in range(N):
s, t, x = list(map(int, input().split()))
c_append((x, s, t))
c.sort()
D = [int(eval(input())) for _ in range(Q)]
ans = [-1] * Q
skip = [-1] * Q
for x, s, t in c:
left = bisect_left(D, s - x)
right = bisect_left(D, t - x)
while left < right:
if skip[left] == -1:
ans[left] = x
skip[left] = right
left += 1
else:
left = skip[left]
print(("\n".join(map(str, ans))))
if __name__ == "__main__":
main()
| false | 21.428571 | [
"- from collections import defaultdict",
"- from heapq import heappop, heappush",
"+ from bisect import bisect_left",
"+",
"- used = defaultdict(int)",
"- tank = []",
"- p = []",
"- p_append = p.append",
"- for i in range(N):",
"+ c = []",
"+ c_append = c.append",
... | false | 0.037643 | 0.035465 | 1.061399 | [
"s490660882",
"s379607230"
] |
u035472582 | p02595 | python | s585559277 | s962462626 | 370 | 303 | 107,200 | 74,432 | Accepted | Accepted | 18.11 | def main():
from math import sqrt
N, D = list(map(int, input().split()))
P = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
if sqrt(P[i][0]**2 + P[i][1]**2) <= D:
ans += 1
print(ans)
main() | def main():
N, D = list(map(int, input().split()))
ans = 0
for i in range(N):
x, y = list(map(int, input().split()))
if x**2 + y**2 <= D**2:
ans += 1
print(ans)
main() | 10 | 9 | 246 | 185 | def main():
from math import sqrt
N, D = list(map(int, input().split()))
P = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
if sqrt(P[i][0] ** 2 + P[i][1] ** 2) <= D:
ans += 1
print(ans)
main()
| def main():
N, D = list(map(int, input().split()))
ans = 0
for i in range(N):
x, y = list(map(int, input().split()))
if x**2 + y**2 <= D**2:
ans += 1
print(ans)
main()
| false | 10 | [
"- from math import sqrt",
"-",
"- P = [list(map(int, input().split())) for i in range(N)]",
"- if sqrt(P[i][0] ** 2 + P[i][1] ** 2) <= D:",
"+ x, y = list(map(int, input().split()))",
"+ if x**2 + y**2 <= D**2:"
] | false | 0.088033 | 0.12534 | 0.702351 | [
"s585559277",
"s962462626"
] |
u285681431 | p03078 | python | s486952142 | s901310570 | 808 | 157 | 217,760 | 78,568 | Accepted | Accepted | 80.57 | X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
# A+Bの上位K個
tmp = []
for a in A:
for b in B:
tmp.append(a + b)
tmp.sort(reverse=True)
tmp = tmp[:K]
ans = []
for ab in tmp:
for c in C:
ans.append(ab + c)
ans.sort(reverse=True)
for i in range(K):
print((ans[i]))
| from heapq import heappop, heappush
X, Y, Z, K = list(map(int, input().split()))
# heahqで最大値を扱いたいのでマイナスにしておく
A = sorted(list([-int(x) for x in input().split()]))
B = sorted(list([-int(x) for x in input().split()]))
C = sorted(list([-int(x) for x in input().split()]))
# プライオリティキュー
# heapqの要素はタプルに出来る
hq = []
u = (A[0] + B[0] + C[0], 0, 0, 0)
heappush(hq, u)
# 同じものを複数回追加しないようにチェック
visited = set()
visited.add(u)
for i in range(K):
x, i, j, k = heappop(hq)
print((-x))
# A, B, Cについての次の値をpush
if i + 1 <= X - 1:
next_i = (A[i + 1] + B[j] + C[k], i + 1, j, k)
if next_i not in visited:
heappush(hq, next_i)
visited.add(next_i)
if j + 1 <= Y - 1:
next_j = (A[i] + B[j + 1] + C[k], i, j + 1, k)
if next_j not in visited:
heappush(hq, next_j)
visited.add(next_j)
if k + 1 <= Z - 1:
next_k = (A[i] + B[j] + C[k + 1], i, j, k + 1)
if next_k not in visited:
heappush(hq, next_k)
visited.add(next_k)
| 21 | 38 | 408 | 1,083 | X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
# A+Bの上位K個
tmp = []
for a in A:
for b in B:
tmp.append(a + b)
tmp.sort(reverse=True)
tmp = tmp[:K]
ans = []
for ab in tmp:
for c in C:
ans.append(ab + c)
ans.sort(reverse=True)
for i in range(K):
print((ans[i]))
| from heapq import heappop, heappush
X, Y, Z, K = list(map(int, input().split()))
# heahqで最大値を扱いたいのでマイナスにしておく
A = sorted(list([-int(x) for x in input().split()]))
B = sorted(list([-int(x) for x in input().split()]))
C = sorted(list([-int(x) for x in input().split()]))
# プライオリティキュー
# heapqの要素はタプルに出来る
hq = []
u = (A[0] + B[0] + C[0], 0, 0, 0)
heappush(hq, u)
# 同じものを複数回追加しないようにチェック
visited = set()
visited.add(u)
for i in range(K):
x, i, j, k = heappop(hq)
print((-x))
# A, B, Cについての次の値をpush
if i + 1 <= X - 1:
next_i = (A[i + 1] + B[j] + C[k], i + 1, j, k)
if next_i not in visited:
heappush(hq, next_i)
visited.add(next_i)
if j + 1 <= Y - 1:
next_j = (A[i] + B[j + 1] + C[k], i, j + 1, k)
if next_j not in visited:
heappush(hq, next_j)
visited.add(next_j)
if k + 1 <= Z - 1:
next_k = (A[i] + B[j] + C[k + 1], i, j, k + 1)
if next_k not in visited:
heappush(hq, next_k)
visited.add(next_k)
| false | 44.736842 | [
"+from heapq import heappop, heappush",
"+",
"-A = list(map(int, input().split()))",
"-B = list(map(int, input().split()))",
"-C = list(map(int, input().split()))",
"-# A+Bの上位K個",
"-tmp = []",
"-for a in A:",
"- for b in B:",
"- tmp.append(a + b)",
"-tmp.sort(reverse=True)",
"-tmp = ... | false | 0.035001 | 0.036891 | 0.948764 | [
"s486952142",
"s901310570"
] |
u991567869 | p03325 | python | s357076636 | s959933070 | 101 | 79 | 4,148 | 4,148 | Accepted | Accepted | 21.78 | n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n):
while a[i]%2 == 0:
ans += 1
a[i] //= 2
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in a:
while i%2 == 0:
ans += 1
i //= 2
print(ans) | 10 | 10 | 160 | 147 | n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n):
while a[i] % 2 == 0:
ans += 1
a[i] //= 2
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in a:
while i % 2 == 0:
ans += 1
i //= 2
print(ans)
| false | 0 | [
"-for i in range(n):",
"- while a[i] % 2 == 0:",
"+for i in a:",
"+ while i % 2 == 0:",
"- a[i] //= 2",
"+ i //= 2"
] | false | 0.056226 | 0.036608 | 1.535867 | [
"s357076636",
"s959933070"
] |
u620084012 | p02843 | python | s600349067 | s914170193 | 164 | 17 | 38,384 | 2,940 | Accepted | Accepted | 89.63 | X = int(eval(input()))
t = X//100
if 0 <= X%100 <= t*5:
print((1))
else:
print((0))
| X = int(eval(input()))
if 0 <= X%100 <= 5*(X//100):
print((1))
else:
print((0))
| 6 | 5 | 87 | 82 | X = int(eval(input()))
t = X // 100
if 0 <= X % 100 <= t * 5:
print((1))
else:
print((0))
| X = int(eval(input()))
if 0 <= X % 100 <= 5 * (X // 100):
print((1))
else:
print((0))
| false | 16.666667 | [
"-t = X // 100",
"-if 0 <= X % 100 <= t * 5:",
"+if 0 <= X % 100 <= 5 * (X // 100):"
] | false | 0.042282 | 0.036029 | 1.173564 | [
"s600349067",
"s914170193"
] |
u312025627 | p03476 | python | s260473113 | s736487904 | 1,065 | 655 | 62,308 | 72,676 | Accepted | Accepted | 38.5 | from math import sqrt
q = int(eval(input()))
primes = {i for i in range(2,10**5 + 1)}
for i in range(2,int(sqrt(10**5+1)) + 1):
if i in primes:
mul = 2
while i*mul <= 10**5:
primes.discard(i*mul)
mul += 1
ret = [0]*(1 + 10**5)
for i in range(3,1 + 10**5):
if i&1:
if i in primes and (i+1)/2 in primes:
ret[i] = ret[i-1] + 1
else:
ret[i] = ret[i-1]
else:
ret[i] = ret[i-1]
for i in range(q):
l, r = (int(i) for i in input().split())
print((ret[r] - ret[l-1])) | def main():
from itertools import accumulate
def Eratosthenes(x: int) -> set:
from math import sqrt
sup = int(x)
primes = {i for i in range(2, sup+1)}
for i in range(2, int(sqrt(sup+1))+1):
if i in primes:
mul = 2
while i*mul <= sup:
primes.discard(i*mul)
mul += 1
return primes
P = Eratosthenes(10**5+5)
A = [0]*(10**5+5)
for i in range(3, 10**5+5):
if i in P and (i+1)//2 in P:
A[i] += 1
S = list(accumulate(A))
Q = int(eval(input()))
LR = [[int(i) for i in input().split()] for j in range(Q)]
for le, ri in LR:
print((S[ri] - S[le-1]))
if __name__ == '__main__':
main()
| 24 | 29 | 584 | 789 | from math import sqrt
q = int(eval(input()))
primes = {i for i in range(2, 10**5 + 1)}
for i in range(2, int(sqrt(10**5 + 1)) + 1):
if i in primes:
mul = 2
while i * mul <= 10**5:
primes.discard(i * mul)
mul += 1
ret = [0] * (1 + 10**5)
for i in range(3, 1 + 10**5):
if i & 1:
if i in primes and (i + 1) / 2 in primes:
ret[i] = ret[i - 1] + 1
else:
ret[i] = ret[i - 1]
else:
ret[i] = ret[i - 1]
for i in range(q):
l, r = (int(i) for i in input().split())
print((ret[r] - ret[l - 1]))
| def main():
from itertools import accumulate
def Eratosthenes(x: int) -> set:
from math import sqrt
sup = int(x)
primes = {i for i in range(2, sup + 1)}
for i in range(2, int(sqrt(sup + 1)) + 1):
if i in primes:
mul = 2
while i * mul <= sup:
primes.discard(i * mul)
mul += 1
return primes
P = Eratosthenes(10**5 + 5)
A = [0] * (10**5 + 5)
for i in range(3, 10**5 + 5):
if i in P and (i + 1) // 2 in P:
A[i] += 1
S = list(accumulate(A))
Q = int(eval(input()))
LR = [[int(i) for i in input().split()] for j in range(Q)]
for le, ri in LR:
print((S[ri] - S[le - 1]))
if __name__ == "__main__":
main()
| false | 17.241379 | [
"-from math import sqrt",
"+def main():",
"+ from itertools import accumulate",
"-q = int(eval(input()))",
"-primes = {i for i in range(2, 10**5 + 1)}",
"-for i in range(2, int(sqrt(10**5 + 1)) + 1):",
"- if i in primes:",
"- mul = 2",
"- while i * mul <= 10**5:",
"- ... | false | 0.461406 | 0.117081 | 3.940924 | [
"s260473113",
"s736487904"
] |
u729133443 | p02958 | python | s590566673 | s344118801 | 193 | 17 | 38,384 | 2,940 | Accepted | Accepted | 91.19 | _,p=open(0);print(('YNEOS'[sum(i!=int(p)for i,p in enumerate(p.split(),1))>2::2])) | _,p=open(0)
i=a=0
for p in p.split():i+=1;a+=int(p)!=i
print(('YNEOS'[a>2::2])) | 1 | 4 | 80 | 80 | _, p = open(0)
print(("YNEOS"[sum(i != int(p) for i, p in enumerate(p.split(), 1)) > 2 :: 2]))
| _, p = open(0)
i = a = 0
for p in p.split():
i += 1
a += int(p) != i
print(("YNEOS"[a > 2 :: 2]))
| false | 75 | [
"-print((\"YNEOS\"[sum(i != int(p) for i, p in enumerate(p.split(), 1)) > 2 :: 2]))",
"+i = a = 0",
"+for p in p.split():",
"+ i += 1",
"+ a += int(p) != i",
"+print((\"YNEOS\"[a > 2 :: 2]))"
] | false | 0.083594 | 0.037855 | 2.208253 | [
"s590566673",
"s344118801"
] |
u873482706 | p00184 | python | s119678191 | s144978501 | 1,610 | 1,320 | 4,240 | 4,220 | Accepted | Accepted | 18.01 | while 1:
n = int(input())
if not n: break
c = [0 for i in range(7)]
for i in range(n):
age = int(input())
if age < 10: c[0] += 1
elif 10 <= age < 20: c[1] += 1
elif 20 <= age < 30: c[2] += 1
elif 30 <= age < 40: c[3] += 1
elif 40 <= age < 50: c[4] += 1
elif 50 <= age < 60: c[5] += 1
else: c[6] += 1
for i in range(len(c)):
print(c[i]) | while True:
n = int(input())
if n == 0: break
ans = [0]*7
for i in range(n):
age = int(input())
if age <= 9:
ans[0] += 1
elif age <= 19:
ans[1] += 1
elif age <= 29:
ans[2] += 1
elif age <= 39:
ans[3] += 1
elif age <= 49:
ans[4] += 1
elif age <= 59:
ans[5] += 1
else:
ans[6] += 1
for c in ans:
print(c) | 15 | 22 | 451 | 506 | while 1:
n = int(input())
if not n:
break
c = [0 for i in range(7)]
for i in range(n):
age = int(input())
if age < 10:
c[0] += 1
elif 10 <= age < 20:
c[1] += 1
elif 20 <= age < 30:
c[2] += 1
elif 30 <= age < 40:
c[3] += 1
elif 40 <= age < 50:
c[4] += 1
elif 50 <= age < 60:
c[5] += 1
else:
c[6] += 1
for i in range(len(c)):
print(c[i])
| while True:
n = int(input())
if n == 0:
break
ans = [0] * 7
for i in range(n):
age = int(input())
if age <= 9:
ans[0] += 1
elif age <= 19:
ans[1] += 1
elif age <= 29:
ans[2] += 1
elif age <= 39:
ans[3] += 1
elif age <= 49:
ans[4] += 1
elif age <= 59:
ans[5] += 1
else:
ans[6] += 1
for c in ans:
print(c)
| false | 31.818182 | [
"-while 1:",
"+while True:",
"- if not n:",
"+ if n == 0:",
"- c = [0 for i in range(7)]",
"+ ans = [0] * 7",
"- if age < 10:",
"- c[0] += 1",
"- elif 10 <= age < 20:",
"- c[1] += 1",
"- elif 20 <= age < 30:",
"- c[2] += 1",
"... | false | 0.036165 | 0.035572 | 1.016655 | [
"s119678191",
"s144978501"
] |
u064505481 | p03183 | python | s454493449 | s197034948 | 231 | 158 | 75,216 | 75,016 | Accepted | Accepted | 31.6 | from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
rlf = lambda: list(map(float, stdin.readline().split()))
INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7
def main():
n = int(rl())
A = []
for _ in range(n):
w, s, v = rli()
A.append((w, s, v))
ans = 0
A.sort(key = lambda I: (I[0] + I[1]))
maxs = 2*10**4 + 100
dp = [0 for _ in range(maxs+1)]
for w, s, v in A:
for i in range(maxs, -1, -1):
if i - w < 0: continue
if i - w > s: continue
dp[i] = max(dp[i], dp[i-w] + v)
ans = max(ans, dp[i])
print(ans)
stdout.close()
if __name__ == "__main__":
main() | from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
rlf = lambda: list(map(float, stdin.readline().split()))
INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7
def main():
n = int(rl())
A = []
mw, ms = 0, 0
for _ in range(n):
w, s, v = rli()
mw, ms = max(mw, w), max(ms, s)
A.append((w, s, v))
ans = 0
A.sort(key = lambda I: (I[0] + I[1]))
maxs = mw + ms + 100
dp = [0 for _ in range(maxs+1)]
for w, s, v in A:
for i in range(maxs, -1, -1):
if i - w < 0: break
if i - w > s: continue
dp[i] = max(dp[i], dp[i-w] + v)
ans = max(ans, dp[i])
print(ans)
stdout.close()
if __name__ == "__main__":
main() | 36 | 38 | 894 | 942 | from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
rlf = lambda: list(map(float, stdin.readline().split()))
INF, NINF = float("inf"), float("-inf")
MOD = 10**9 + 7
def main():
n = int(rl())
A = []
for _ in range(n):
w, s, v = rli()
A.append((w, s, v))
ans = 0
A.sort(key=lambda I: (I[0] + I[1]))
maxs = 2 * 10**4 + 100
dp = [0 for _ in range(maxs + 1)]
for w, s, v in A:
for i in range(maxs, -1, -1):
if i - w < 0:
continue
if i - w > s:
continue
dp[i] = max(dp[i], dp[i - w] + v)
ans = max(ans, dp[i])
print(ans)
stdout.close()
if __name__ == "__main__":
main()
| from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
rlf = lambda: list(map(float, stdin.readline().split()))
INF, NINF = float("inf"), float("-inf")
MOD = 10**9 + 7
def main():
n = int(rl())
A = []
mw, ms = 0, 0
for _ in range(n):
w, s, v = rli()
mw, ms = max(mw, w), max(ms, s)
A.append((w, s, v))
ans = 0
A.sort(key=lambda I: (I[0] + I[1]))
maxs = mw + ms + 100
dp = [0 for _ in range(maxs + 1)]
for w, s, v in A:
for i in range(maxs, -1, -1):
if i - w < 0:
break
if i - w > s:
continue
dp[i] = max(dp[i], dp[i - w] + v)
ans = max(ans, dp[i])
print(ans)
stdout.close()
if __name__ == "__main__":
main()
| false | 5.263158 | [
"+ mw, ms = 0, 0",
"+ mw, ms = max(mw, w), max(ms, s)",
"- maxs = 2 * 10**4 + 100",
"+ maxs = mw + ms + 100",
"- continue",
"+ break"
] | false | 0.071132 | 0.055427 | 1.283346 | [
"s454493449",
"s197034948"
] |
u119148115 | p03222 | python | s458670862 | s028183767 | 71 | 62 | 62,800 | 62,708 | Accepted | Accepted | 12.68 | import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
H,W,K = MI()
mod = 10**9+7
if W == 1:
print((1))
exit()
fib = [1,1,2,3,5,8,13,21,34]
dp = [[0]*(W+1) for _ in range(H+1)]
dp[0][1] = 1
for i in range(1,H+1):
for j in range(1,W+1):
if W == 2:
if j == 1:
dp[i][j] = dp[i-1][j] + dp[i-1][j+1]
dp[i][j] %= mod
else:
dp[i][j] = dp[i-1][j] + dp[i-1][j-1]
dp[i][j] %= mod
else:
if j == 1:
dp[i][j] = dp[i-1][j+1]*fib[W-2] + dp[i-1][j]*fib[W-j]
dp[i][j] %= mod
elif j == W:
dp[i][j] = dp[i-1][j-1]*fib[W-2] + dp[i-1][j]*fib[j-1]
dp[i][j] %= mod
else:
dp[i][j] = dp[i-1][j-1]*fib[j-2]*fib[W-j] + dp[i-1][j+1]*fib[j-1]*fib[W-j-1] + dp[i-1][j]*(fib[W-j]*fib[j-1])
dp[i][j] %= mod
print((dp[H][K]))
| import sys
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
H,W,K = MI()
mod = 10**9+7
if W == 1:
print((1))
exit()
fib = [1,1,2,3,5,8,13,21] # fib[i] = i本のあみだくじの、ある列に横線を引く方法の数
dp = [[0]*(W+1) for _ in range(H+1)] # dp[i][j] = i段横線を引いたときに1からKに至るような横線の引き方
dp[0][1] = 1
for i in range(1,H+1):
for j in range(1,W+1):
if j == 1:
dp[i][j] = dp[i-1][j+1]*fib[W-j-1] + dp[i-1][j]*fib[W-j]
dp[i][j] %= mod
elif j == W:
dp[i][j] = dp[i-1][j-1]*fib[j-2] + dp[i-1][j]*fib[j-1]
dp[i][j] %= mod
else:
dp[i][j] = dp[i-1][j-1]*fib[j-2]*fib[W-j] + dp[i-1][j+1]*fib[j-1]*fib[W-j-1] + dp[i-1][j]*fib[W-j]*fib[j-1]
dp[i][j] %= mod
print((dp[H][K]))
| 43 | 27 | 1,406 | 782 | import sys
sys.setrecursionlimit(10**7)
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
def LI2():
return list(map(int, sys.stdin.readline().rstrip())) # 空白なし
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split()) # 空白あり
def LS2():
return list(sys.stdin.readline().rstrip()) # 空白なし
H, W, K = MI()
mod = 10**9 + 7
if W == 1:
print((1))
exit()
fib = [1, 1, 2, 3, 5, 8, 13, 21, 34]
dp = [[0] * (W + 1) for _ in range(H + 1)]
dp[0][1] = 1
for i in range(1, H + 1):
for j in range(1, W + 1):
if W == 2:
if j == 1:
dp[i][j] = dp[i - 1][j] + dp[i - 1][j + 1]
dp[i][j] %= mod
else:
dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1]
dp[i][j] %= mod
else:
if j == 1:
dp[i][j] = dp[i - 1][j + 1] * fib[W - 2] + dp[i - 1][j] * fib[W - j]
dp[i][j] %= mod
elif j == W:
dp[i][j] = dp[i - 1][j - 1] * fib[W - 2] + dp[i - 1][j] * fib[j - 1]
dp[i][j] %= mod
else:
dp[i][j] = (
dp[i - 1][j - 1] * fib[j - 2] * fib[W - j]
+ dp[i - 1][j + 1] * fib[j - 1] * fib[W - j - 1]
+ dp[i - 1][j] * (fib[W - j] * fib[j - 1])
)
dp[i][j] %= mod
print((dp[H][K]))
| import sys
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
H, W, K = MI()
mod = 10**9 + 7
if W == 1:
print((1))
exit()
fib = [1, 1, 2, 3, 5, 8, 13, 21] # fib[i] = i本のあみだくじの、ある列に横線を引く方法の数
dp = [[0] * (W + 1) for _ in range(H + 1)] # dp[i][j] = i段横線を引いたときに1からKに至るような横線の引き方
dp[0][1] = 1
for i in range(1, H + 1):
for j in range(1, W + 1):
if j == 1:
dp[i][j] = dp[i - 1][j + 1] * fib[W - j - 1] + dp[i - 1][j] * fib[W - j]
dp[i][j] %= mod
elif j == W:
dp[i][j] = dp[i - 1][j - 1] * fib[j - 2] + dp[i - 1][j] * fib[j - 1]
dp[i][j] %= mod
else:
dp[i][j] = (
dp[i - 1][j - 1] * fib[j - 2] * fib[W - j]
+ dp[i - 1][j + 1] * fib[j - 1] * fib[W - j - 1]
+ dp[i - 1][j] * fib[W - j] * fib[j - 1]
)
dp[i][j] %= mod
print((dp[H][K]))
| false | 37.209302 | [
"-",
"-sys.setrecursionlimit(10**7)",
"-",
"-",
"-def I():",
"- return int(sys.stdin.readline().rstrip())",
"-",
"-",
"-def LI():",
"- return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり",
"-",
"-",
"-def LI2():",
"- return list(map(int, sys.stdin.readline().rstri... | false | 0.047799 | 0.081802 | 0.584328 | [
"s458670862",
"s028183767"
] |
u821775079 | p03545 | python | s619132974 | s741043321 | 30 | 25 | 9,184 | 8,984 | Accepted | Accepted | 16.67 | s = eval(input())
ans1=s[0]
def solve(i,tmp,ans):
global ans1
if i==3:
if tmp==7:
ans1=ans
return True
else:
return False
if solve(i+1,tmp+int(s[i+1]),ans+"+"+s[i+1]): return True
if solve(i+1,tmp-int(s[i+1]),ans+"-"+s[i+1]): return True
if solve(0,int(s[0]),ans1):
print((ans1+"=7")) | s = eval(input())
for bit in range(1<<3):
ans=""
for i in range(3):
if bit & (1<<i):
ans+="+"
else:
ans+="-"
ans=s[0]+ans[0]+s[1]+ans[1]+s[2]+ans[2]+s[3]
if eval(ans)==7:
print((ans+"=7"))
break | 17 | 13 | 333 | 235 | s = eval(input())
ans1 = s[0]
def solve(i, tmp, ans):
global ans1
if i == 3:
if tmp == 7:
ans1 = ans
return True
else:
return False
if solve(i + 1, tmp + int(s[i + 1]), ans + "+" + s[i + 1]):
return True
if solve(i + 1, tmp - int(s[i + 1]), ans + "-" + s[i + 1]):
return True
if solve(0, int(s[0]), ans1):
print((ans1 + "=7"))
| s = eval(input())
for bit in range(1 << 3):
ans = ""
for i in range(3):
if bit & (1 << i):
ans += "+"
else:
ans += "-"
ans = s[0] + ans[0] + s[1] + ans[1] + s[2] + ans[2] + s[3]
if eval(ans) == 7:
print((ans + "=7"))
break
| false | 23.529412 | [
"-ans1 = s[0]",
"-",
"-",
"-def solve(i, tmp, ans):",
"- global ans1",
"- if i == 3:",
"- if tmp == 7:",
"- ans1 = ans",
"- return True",
"+for bit in range(1 << 3):",
"+ ans = \"\"",
"+ for i in range(3):",
"+ if bit & (1 << i):",
"+ ... | false | 0.043488 | 0.100735 | 0.43171 | [
"s619132974",
"s741043321"
] |
u498487134 | p02768 | python | s963508962 | s548630180 | 372 | 187 | 108,236 | 38,512 | Accepted | Accepted | 49.73 | n,a,b=list(map(int,input().split()))
mod=10**9+7
def cmb(n, r):
if n - r < r: r = n - r
if r == 0: return 1
if r == 1: return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2,r+1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p-1,r,p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
result%=mod
return result
allp=pow(2,n,mod)-1
ans=(allp-cmb(n,a)%mod-cmb(n,b)%mod+mod)%mod
if n==2:
ans=0
print(ans) | n,a,b=list(map(int,input().split()))
mod=10**9+7
def cmb(n, r,mod):
if n - r < r: r = n - r
if r == 0: return 1
if r == 1: return n
#X//Y
X=1
Y=1
for i in range(r):
X*=(n-i)
X%=mod
Y*=(i+1)
Y%=mod
inv=pow(Y,mod-2,mod)
return (X*inv)%mod
allp=pow(2,n,mod)-1
ans=(allp-cmb(n,a,mod)-cmb(n,b,mod))%mod
if n==2:
ans=0
print(ans) | 34 | 29 | 753 | 449 | n, a, b = list(map(int, input().split()))
mod = 10**9 + 7
def cmb(n, r):
if n - r < r:
r = n - r
if r == 0:
return 1
if r == 1:
return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
result %= mod
return result
allp = pow(2, n, mod) - 1
ans = (allp - cmb(n, a) % mod - cmb(n, b) % mod + mod) % mod
if n == 2:
ans = 0
print(ans)
| n, a, b = list(map(int, input().split()))
mod = 10**9 + 7
def cmb(n, r, mod):
if n - r < r:
r = n - r
if r == 0:
return 1
if r == 1:
return n
# X//Y
X = 1
Y = 1
for i in range(r):
X *= n - i
X %= mod
Y *= i + 1
Y %= mod
inv = pow(Y, mod - 2, mod)
return (X * inv) % mod
allp = pow(2, n, mod) - 1
ans = (allp - cmb(n, a, mod) - cmb(n, b, mod)) % mod
if n == 2:
ans = 0
print(ans)
| false | 14.705882 | [
"-def cmb(n, r):",
"+def cmb(n, r, mod):",
"- numerator = [n - r + k + 1 for k in range(r)]",
"- denominator = [k + 1 for k in range(r)]",
"- for p in range(2, r + 1):",
"- pivot = denominator[p - 1]",
"- if pivot > 1:",
"- offset = (n - r) % p",
"- for k... | false | 0.951838 | 0.207615 | 4.584625 | [
"s963508962",
"s548630180"
] |
u948524308 | p02756 | python | s261937231 | s251608739 | 1,849 | 689 | 4,432 | 10,100 | Accepted | Accepted | 62.74 | S=eval(input())
Q=int(eval(input()))
R=0
S1=""
S2=""
for i in range(Q):
temp=list(input().split())
if int(temp[0])==1:
S=S1+S+S2
S1=""
S2=""
R+=1
elif int(temp[0])==2:
F=int(temp[1])
c=temp[2]
if F==1:
if R%2==0:
S1=c+S1
else:
S2=S2+c
elif F==2:
if R%2==0:
S2=S2+c
else:
S1=c+S1
S=S1+S+S2
if R%2==1:
ans=S[-1::-1]
print(ans)
else:
print(S)
| from collections import deque
S=eval(input())
Q=int(eval(input()))
R=0
S=deque(S)
for i in range(Q):
temp=list(input().split())
if int(temp[0])==1:
R+=1
elif int(temp[0])==2:
F=int(temp[1])
c=temp[2]
if F==1:
if R%2==0:
S.appendleft(c)
else:
S.append(c)
elif F==2:
if R%2==0:
S.append(c)
else:
S.appendleft(c)
if R%2==1:
S=list(S)
ans=S[-1::-1]
ans=list(map(str,ans))
else:
ans=list(map(str,S))
print(("".join(ans)))
| 35 | 37 | 566 | 615 | S = eval(input())
Q = int(eval(input()))
R = 0
S1 = ""
S2 = ""
for i in range(Q):
temp = list(input().split())
if int(temp[0]) == 1:
S = S1 + S + S2
S1 = ""
S2 = ""
R += 1
elif int(temp[0]) == 2:
F = int(temp[1])
c = temp[2]
if F == 1:
if R % 2 == 0:
S1 = c + S1
else:
S2 = S2 + c
elif F == 2:
if R % 2 == 0:
S2 = S2 + c
else:
S1 = c + S1
S = S1 + S + S2
if R % 2 == 1:
ans = S[-1::-1]
print(ans)
else:
print(S)
| from collections import deque
S = eval(input())
Q = int(eval(input()))
R = 0
S = deque(S)
for i in range(Q):
temp = list(input().split())
if int(temp[0]) == 1:
R += 1
elif int(temp[0]) == 2:
F = int(temp[1])
c = temp[2]
if F == 1:
if R % 2 == 0:
S.appendleft(c)
else:
S.append(c)
elif F == 2:
if R % 2 == 0:
S.append(c)
else:
S.appendleft(c)
if R % 2 == 1:
S = list(S)
ans = S[-1::-1]
ans = list(map(str, ans))
else:
ans = list(map(str, S))
print(("".join(ans)))
| false | 5.405405 | [
"+from collections import deque",
"+",
"-S1 = \"\"",
"-S2 = \"\"",
"+S = deque(S)",
"- S = S1 + S + S2",
"- S1 = \"\"",
"- S2 = \"\"",
"- S1 = c + S1",
"+ S.appendleft(c)",
"- S2 = S2 + c",
"+ S.append(c)",
"- ... | false | 0.04547 | 0.046175 | 0.984726 | [
"s261937231",
"s251608739"
] |
u638902622 | p03687 | python | s182477978 | s823191896 | 45 | 17 | 4,024 | 3,064 | Accepted | Accepted | 62.22 | 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 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(n=10**3):
"""Return a list of prime numbers n or less"""
is_prime = [True]*(n+1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(n**0.5)+1):
if not is_prime[i]: continue
for j in range(i*2, n+1, i): is_prime[j] = False
return [i for i in range(n+1) if is_prime[i]]
def prime_factor(n):
"""Return a list of prime factorization numbers of n"""
res = []
for i in range(2,int(n**0.5)+1):
while n%i==0: res.append(i); n //= i
if n != 1: res.append(n)
return res
## const ##
MOD=10**9+7
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
import string
#======================================================#
def main():
s = IS()
n = len(s)
sc = set(s)
ans = 10**9
for c in string.ascii_lowercase:
if c not in sc: continue
cnt = 0
t = s
for l in range(n):
u = ''
if set(t) == {c}: break
for i in range(len(t)-1):
if t[i] == c or t[i+1] == c:
u += c
else:
u += t[i]
cnt += 1
t = u
ans = min(cnt, ans)
print(ans)
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 MIIZ(): return list([x-1 for x in MII()])
#======================================================#
def main():
s = IS()
cnt = len(s)
for c in set(s):
dist = 0
max_d = 0
for si in s:
if c != si:
dist += 1
else:
max_d = max(max_d, dist)
dist = 0
cnt = min(cnt, max(max_d, dist))
print(cnt)
if __name__ == '__main__':
main() | 70 | 24 | 2,053 | 619 | 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 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(n=10**3):
"""Return a list of prime numbers n or less"""
is_prime = [True] * (n + 1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, n + 1, i):
is_prime[j] = False
return [i for i in range(n + 1) if is_prime[i]]
def prime_factor(n):
"""Return a list of prime factorization numbers of n"""
res = []
for i in range(2, int(n**0.5) + 1):
while n % i == 0:
res.append(i)
n //= i
if n != 1:
res.append(n)
return res
## const ##
MOD = 10**9 + 7
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
import string
# ======================================================#
def main():
s = IS()
n = len(s)
sc = set(s)
ans = 10**9
for c in string.ascii_lowercase:
if c not in sc:
continue
cnt = 0
t = s
for l in range(n):
u = ""
if set(t) == {c}:
break
for i in range(len(t) - 1):
if t[i] == c or t[i + 1] == c:
u += c
else:
u += t[i]
cnt += 1
t = u
ans = min(cnt, ans)
print(ans)
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 MIIZ():
return list([x - 1 for x in MII()])
# ======================================================#
def main():
s = IS()
cnt = len(s)
for c in set(s):
dist = 0
max_d = 0
for si in s:
if c != si:
dist += 1
else:
max_d = max(max_d, dist)
dist = 0
cnt = min(cnt, max(max_d, dist))
print(cnt)
if __name__ == "__main__":
main()
| false | 65.714286 | [
"-## 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 divc(x, y) -> int:",
"- return -(-x // y)",
"-",
"-",
"-def divf(x,... | false | 0.042001 | 0.047463 | 0.88492 | [
"s182477978",
"s823191896"
] |
u548303713 | p02720 | python | s163189556 | s068071036 | 317 | 278 | 52,956 | 47,580 | Accepted | Accepted | 12.3 | import sys
k=int(eval(input()))
ans=[""]
for i in range(1,13):
ans.append(i)
for i in range(1,8):
a=10*(i+1)+(i)
for j in range(3):
ans.append(a)
a+=1
ans.append(98)
ans.append(99)
#print(ans)
#print(len(ans))
if k<=35:
print((ans[k]))
else:
def search(i,j):
total=0
if i==1:
#print(j)
return 1
for m in range(10):
if abs(j-m)<=1:
total+=search(i-1,m)
return total
def search2(i,j,anss):
global plus,aaa
if i==1:
plus+=1
#print(kind)
#print(anss)
#print(aaa+plus)
if k==aaa+plus:
#print(aaa+plus)
print(anss)
return
for m in range(10):
if abs(j-m)<=1:
search2(i-1,m,anss+str(m))
num=[35] #各桁の種類(累計
for i in range(3,11): #桁数
for j in range(1,10): #先頭の数字
count=search(i,j)
num.append(num[-1]+count)
#print(num)
ab=0
while num[ab]<k:
ab+=1
#print(ab)
rank=ab//9
sento=ab%9
if sento==0:
sento=9
#where=sento*(10**(2+rank))
#print(where)
aaa=num[ab-1]
plus=0
search2(3+rank,sento,str(sento)) | k=int(eval(input()))
total=0
def count(keta,s,ans):
global total
if keta==1:
total+=1
if k==total:
print(ans) #ここで終了させたい
return
for m in range(10):
if abs(s-m)<=1:
count(keta-1,m,ans+str(m))
for i in range(1,11):
for j in range(1,10):
count(i,j,str(j)) | 59 | 15 | 1,321 | 341 | import sys
k = int(eval(input()))
ans = [""]
for i in range(1, 13):
ans.append(i)
for i in range(1, 8):
a = 10 * (i + 1) + (i)
for j in range(3):
ans.append(a)
a += 1
ans.append(98)
ans.append(99)
# print(ans)
# print(len(ans))
if k <= 35:
print((ans[k]))
else:
def search(i, j):
total = 0
if i == 1:
# print(j)
return 1
for m in range(10):
if abs(j - m) <= 1:
total += search(i - 1, m)
return total
def search2(i, j, anss):
global plus, aaa
if i == 1:
plus += 1
# print(kind)
# print(anss)
# print(aaa+plus)
if k == aaa + plus:
# print(aaa+plus)
print(anss)
return
for m in range(10):
if abs(j - m) <= 1:
search2(i - 1, m, anss + str(m))
num = [35] # 各桁の種類(累計
for i in range(3, 11): # 桁数
for j in range(1, 10): # 先頭の数字
count = search(i, j)
num.append(num[-1] + count)
# print(num)
ab = 0
while num[ab] < k:
ab += 1
# print(ab)
rank = ab // 9
sento = ab % 9
if sento == 0:
sento = 9
# where=sento*(10**(2+rank))
# print(where)
aaa = num[ab - 1]
plus = 0
search2(3 + rank, sento, str(sento))
| k = int(eval(input()))
total = 0
def count(keta, s, ans):
global total
if keta == 1:
total += 1
if k == total:
print(ans) # ここで終了させたい
return
for m in range(10):
if abs(s - m) <= 1:
count(keta - 1, m, ans + str(m))
for i in range(1, 11):
for j in range(1, 10):
count(i, j, str(j))
| false | 74.576271 | [
"-import sys",
"+k = int(eval(input()))",
"+total = 0",
"-k = int(eval(input()))",
"-ans = [\"\"]",
"-for i in range(1, 13):",
"- ans.append(i)",
"-for i in range(1, 8):",
"- a = 10 * (i + 1) + (i)",
"- for j in range(3):",
"- ans.append(a)",
"- a += 1",
"-ans.append(9... | false | 0.389487 | 0.596142 | 0.653347 | [
"s163189556",
"s068071036"
] |
u989345508 | p03086 | python | s829446079 | s240558230 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | s=eval(input())
a=0
b=["A","C","G","T"]
k=0
for i in range(len(s)):
if s[i] in b:
k+=1
if i==len(s)-1 and k>a:
a=k
else:
if k>a:
a=k
k=0
print(a)
| x=["A","G","C","T"]
ans=0
now=0
for i in eval(input()):
if i in x:
now+=1
else:
now=0
ans=max(now,ans)
print(ans)
| 15 | 10 | 219 | 145 | s = eval(input())
a = 0
b = ["A", "C", "G", "T"]
k = 0
for i in range(len(s)):
if s[i] in b:
k += 1
if i == len(s) - 1 and k > a:
a = k
else:
if k > a:
a = k
k = 0
print(a)
| x = ["A", "G", "C", "T"]
ans = 0
now = 0
for i in eval(input()):
if i in x:
now += 1
else:
now = 0
ans = max(now, ans)
print(ans)
| false | 33.333333 | [
"-s = eval(input())",
"-a = 0",
"-b = [\"A\", \"C\", \"G\", \"T\"]",
"-k = 0",
"-for i in range(len(s)):",
"- if s[i] in b:",
"- k += 1",
"- if i == len(s) - 1 and k > a:",
"- a = k",
"+x = [\"A\", \"G\", \"C\", \"T\"]",
"+ans = 0",
"+now = 0",
"+for i in eval(inp... | false | 0.048812 | 0.048749 | 1.001302 | [
"s829446079",
"s240558230"
] |
u074220993 | p03503 | python | s519157524 | s449632608 | 160 | 138 | 27,220 | 26,932 | Accepted | Accepted | 13.75 | import numpy as np
import heapq as hq
N = int(eval(input()))
F = np.array([[int(x) for x in input().split()] for _ in range(N)])
P = np.array([[int(x) for x in input().split()] for _ in range(N)])
Profit = []
for i in range(1,2**10): #営業時間帯についてbit全探索
Open = np.array([int(x) for x in format(i, '010b')]).T #2進数を縦ベクトルに変換
c = np.dot(F, Open) #店別に被る時間帯の個数をベクトルとして算出
hq.heappush(Profit, -sum(P[i, c[i]] for i in range(N))) #-1倍した利益をProfitにpush。
print((-Profit[0])) #heapから最小値を取得
| import numpy as np
def main():
with open(0) as f:
N = int(f.readline())
F = np.array([list(map(int, f.readline().split())) for _ in range(N)])
P = [list(map(int, f.readline().split())) for _ in range(N)]
max_profit = -np.inf
for i in range(1,2**10):
Open = np.array([(i>>j)&1 for j in range(10)])
conflict = np.dot(F, Open.T)
profit = sum(P[i][v] for i,v in enumerate(conflict))
max_profit = max(max_profit, profit)
print(max_profit)
main() | 13 | 17 | 500 | 531 | import numpy as np
import heapq as hq
N = int(eval(input()))
F = np.array([[int(x) for x in input().split()] for _ in range(N)])
P = np.array([[int(x) for x in input().split()] for _ in range(N)])
Profit = []
for i in range(1, 2**10): # 営業時間帯についてbit全探索
Open = np.array([int(x) for x in format(i, "010b")]).T # 2進数を縦ベクトルに変換
c = np.dot(F, Open) # 店別に被る時間帯の個数をベクトルとして算出
hq.heappush(Profit, -sum(P[i, c[i]] for i in range(N))) # -1倍した利益をProfitにpush。
print((-Profit[0])) # heapから最小値を取得
| import numpy as np
def main():
with open(0) as f:
N = int(f.readline())
F = np.array([list(map(int, f.readline().split())) for _ in range(N)])
P = [list(map(int, f.readline().split())) for _ in range(N)]
max_profit = -np.inf
for i in range(1, 2**10):
Open = np.array([(i >> j) & 1 for j in range(10)])
conflict = np.dot(F, Open.T)
profit = sum(P[i][v] for i, v in enumerate(conflict))
max_profit = max(max_profit, profit)
print(max_profit)
main()
| false | 23.529412 | [
"-import heapq as hq",
"-N = int(eval(input()))",
"-F = np.array([[int(x) for x in input().split()] for _ in range(N)])",
"-P = np.array([[int(x) for x in input().split()] for _ in range(N)])",
"-Profit = []",
"-for i in range(1, 2**10): # 営業時間帯についてbit全探索",
"- Open = np.array([int(x) for x in format... | false | 0.214777 | 0.2055 | 1.045146 | [
"s519157524",
"s449632608"
] |
u888092736 | p03346 | python | s373437246 | s499680804 | 435 | 104 | 38,724 | 31,656 | Accepted | Accepted | 76.09 | N, *P = list(map(int, open(0).read().split()))
pairs = sorted((P[i], i) for i in range(N))
sub = 1
right = 0
for left in range(N):
while right < N - 1 and pairs[right + 1][1] > pairs[right][1]:
right += 1
sub = max(sub, right - left + 1)
if left == right:
right += 1
print((N - sub))
| N, *P = list(map(int, open(0).read().split()))
dp = [0] * (N + 1)
for p in P:
dp[p] = dp[p - 1] + 1
print((N - max(dp)))
| 14 | 5 | 320 | 121 | N, *P = list(map(int, open(0).read().split()))
pairs = sorted((P[i], i) for i in range(N))
sub = 1
right = 0
for left in range(N):
while right < N - 1 and pairs[right + 1][1] > pairs[right][1]:
right += 1
sub = max(sub, right - left + 1)
if left == right:
right += 1
print((N - sub))
| N, *P = list(map(int, open(0).read().split()))
dp = [0] * (N + 1)
for p in P:
dp[p] = dp[p - 1] + 1
print((N - max(dp)))
| false | 64.285714 | [
"-pairs = sorted((P[i], i) for i in range(N))",
"-sub = 1",
"-right = 0",
"-for left in range(N):",
"- while right < N - 1 and pairs[right + 1][1] > pairs[right][1]:",
"- right += 1",
"- sub = max(sub, right - left + 1)",
"- if left == right:",
"- right += 1",
"-print((N - s... | false | 0.042068 | 0.035954 | 1.170024 | [
"s373437246",
"s499680804"
] |
u467736898 | p02868 | python | s364080294 | s987154964 | 1,557 | 1,326 | 37,004 | 124,248 | Accepted | Accepted | 14.84 | # いろいろ高速化
# https://atcoder.jp/contests/nikkei2019-2-qual/submissions/8436413
class Rmq:
# 平方分割
# 値を変更すると元のリストの値も書き換わる
# 検証: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3990681
def __init__(self, a, sqrt_n=150, inf=(1<<31)-1):
self.sqrt_n = sqrt_n
if hasattr(a, "__iter__"):
from itertools import zip_longest
self.n = len(a)
self.layer0 = [min(values) for values in zip_longest(*[iter(a)]*sqrt_n, fillvalue=inf)]
self.layer1 = a
elif isinstance(a, int):
self.n = a
self.layer0 = [inf] * ((a - 1) // sqrt_n + 1)
self.layer1 = [inf] * a
else:
raise TypeError
def get_min(self, l, r):
sqrt_n = self.sqrt_n
parent_l, parent_r = l//sqrt_n+1, (r-1)//sqrt_n
if parent_l < parent_r:
return min(min(self.layer0[parent_l:parent_r]),
min(self.layer1[l:parent_l*sqrt_n]),
min(self.layer1[parent_r*sqrt_n:r]))
else:
return min(self.layer1[l:r])
def set_value(self, idx, val):
self.layer1[idx] = val
idx0 = idx // self.sqrt_n
idx1 = idx0 * self.sqrt_n
self.layer0[idx0] = min(self.layer1[idx1:idx1+self.sqrt_n])
def chmin(self, idx, val):
if self.layer1[idx] > val:
self.layer1[idx] = val
idx //= self.sqrt_n
self.layer0[idx] = min(self.layer0[idx], val)
def debug(self):
print(("layer0=", self.layer0))
print(("layer1=", self.layer1))
def __getitem__(self, item):
return self.layer1[item]
def __setitem__(self, key, value):
self.set_value(key, value)
from operator import itemgetter
def main():
N, M, *LRC = list(map(int, open(0).read().split()))
LRC = list(zip(*[iter(LRC)]*3))
LRC.sort(key=itemgetter(0))
idx_LRC = 0
q = []
inf = 10**18
seg = Rmq(N+1, inf=inf)
seg.set_value(1, 0)
for v in range(1, N + 1):
d = seg.get_min(v, N + 1)
while idx_LRC < M:
l, r, c = LRC[idx_LRC]
if l <= v:
seg.chmin(r, d+c)
idx_LRC += 1
else:
break
ans = seg[N]
print((ans if ans != inf else -1))
main()
| # min の実験
from functools import reduce, partial
min = partial(reduce, lambda x, y: x if x < y else y)
class Rmq:
# 平方分割
# 値を変更すると元のリストの値も書き換わる
# 検証: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3990681
def __init__(self, a, sqrt_n=150, inf=(1<<31)-1):
self.sqrt_n = sqrt_n
if hasattr(a, "__iter__"):
from itertools import zip_longest
self.n = len(a)
self.layer0 = [min(values) for values in zip_longest(*[iter(a)]*sqrt_n, fillvalue=inf)]
self.layer1 = a
elif isinstance(a, int):
self.n = a
self.layer0 = [inf] * ((a - 1) // sqrt_n + 1)
self.layer1 = [inf] * a
else:
raise TypeError
def get_min(self, l, r):
sqrt_n = self.sqrt_n
parent_l, parent_r = l//sqrt_n+1, (r-1)//sqrt_n
if parent_l < parent_r:
return min([min(self.layer0[parent_l:parent_r]),
min(self.layer1[l:parent_l*sqrt_n]),
min(self.layer1[parent_r*sqrt_n:r])])
else:
return min(self.layer1[l:r])
def set_value(self, idx, val):
self.layer1[idx] = val
idx0 = idx // self.sqrt_n
idx1 = idx0 * self.sqrt_n
self.layer0[idx0] = min(self.layer1[idx1:idx1+self.sqrt_n])
def chmin(self, idx, val):
if self.layer1[idx] > val:
self.layer1[idx] = val
idx //= self.sqrt_n
self.layer0[idx] = min([self.layer0[idx], val])
def debug(self):
print(("layer0=", self.layer0))
print(("layer1=", self.layer1))
def __getitem__(self, item):
return self.layer1[item]
def __setitem__(self, key, value):
self.set_value(key, value)
from operator import itemgetter
def main():
inf = 10**18
N, M, *LRC = list(map(int, open(0).read().split()))
LRC = list(zip(*[iter(LRC)]*3))
LRC.sort(key=itemgetter(0))
idx_LRC = 0
q = []
seg = Rmq(N+1, inf=inf)
seg.set_value(1, 0)
for v in range(1, N + 1):
d = seg.get_min(v, N + 1)
while idx_LRC < M:
l, r, c = LRC[idx_LRC]
if l <= v:
seg.chmin(r, d+c)
idx_LRC += 1
else:
break
ans = seg[N]
print((ans if ans != inf else -1))
main()
| 79 | 81 | 2,382 | 2,413 | # いろいろ高速化
# https://atcoder.jp/contests/nikkei2019-2-qual/submissions/8436413
class Rmq:
# 平方分割
# 値を変更すると元のリストの値も書き換わる
# 検証: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3990681
def __init__(self, a, sqrt_n=150, inf=(1 << 31) - 1):
self.sqrt_n = sqrt_n
if hasattr(a, "__iter__"):
from itertools import zip_longest
self.n = len(a)
self.layer0 = [
min(values)
for values in zip_longest(*[iter(a)] * sqrt_n, fillvalue=inf)
]
self.layer1 = a
elif isinstance(a, int):
self.n = a
self.layer0 = [inf] * ((a - 1) // sqrt_n + 1)
self.layer1 = [inf] * a
else:
raise TypeError
def get_min(self, l, r):
sqrt_n = self.sqrt_n
parent_l, parent_r = l // sqrt_n + 1, (r - 1) // sqrt_n
if parent_l < parent_r:
return min(
min(self.layer0[parent_l:parent_r]),
min(self.layer1[l : parent_l * sqrt_n]),
min(self.layer1[parent_r * sqrt_n : r]),
)
else:
return min(self.layer1[l:r])
def set_value(self, idx, val):
self.layer1[idx] = val
idx0 = idx // self.sqrt_n
idx1 = idx0 * self.sqrt_n
self.layer0[idx0] = min(self.layer1[idx1 : idx1 + self.sqrt_n])
def chmin(self, idx, val):
if self.layer1[idx] > val:
self.layer1[idx] = val
idx //= self.sqrt_n
self.layer0[idx] = min(self.layer0[idx], val)
def debug(self):
print(("layer0=", self.layer0))
print(("layer1=", self.layer1))
def __getitem__(self, item):
return self.layer1[item]
def __setitem__(self, key, value):
self.set_value(key, value)
from operator import itemgetter
def main():
N, M, *LRC = list(map(int, open(0).read().split()))
LRC = list(zip(*[iter(LRC)] * 3))
LRC.sort(key=itemgetter(0))
idx_LRC = 0
q = []
inf = 10**18
seg = Rmq(N + 1, inf=inf)
seg.set_value(1, 0)
for v in range(1, N + 1):
d = seg.get_min(v, N + 1)
while idx_LRC < M:
l, r, c = LRC[idx_LRC]
if l <= v:
seg.chmin(r, d + c)
idx_LRC += 1
else:
break
ans = seg[N]
print((ans if ans != inf else -1))
main()
| # min の実験
from functools import reduce, partial
min = partial(reduce, lambda x, y: x if x < y else y)
class Rmq:
# 平方分割
# 値を変更すると元のリストの値も書き換わる
# 検証: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3990681
def __init__(self, a, sqrt_n=150, inf=(1 << 31) - 1):
self.sqrt_n = sqrt_n
if hasattr(a, "__iter__"):
from itertools import zip_longest
self.n = len(a)
self.layer0 = [
min(values)
for values in zip_longest(*[iter(a)] * sqrt_n, fillvalue=inf)
]
self.layer1 = a
elif isinstance(a, int):
self.n = a
self.layer0 = [inf] * ((a - 1) // sqrt_n + 1)
self.layer1 = [inf] * a
else:
raise TypeError
def get_min(self, l, r):
sqrt_n = self.sqrt_n
parent_l, parent_r = l // sqrt_n + 1, (r - 1) // sqrt_n
if parent_l < parent_r:
return min(
[
min(self.layer0[parent_l:parent_r]),
min(self.layer1[l : parent_l * sqrt_n]),
min(self.layer1[parent_r * sqrt_n : r]),
]
)
else:
return min(self.layer1[l:r])
def set_value(self, idx, val):
self.layer1[idx] = val
idx0 = idx // self.sqrt_n
idx1 = idx0 * self.sqrt_n
self.layer0[idx0] = min(self.layer1[idx1 : idx1 + self.sqrt_n])
def chmin(self, idx, val):
if self.layer1[idx] > val:
self.layer1[idx] = val
idx //= self.sqrt_n
self.layer0[idx] = min([self.layer0[idx], val])
def debug(self):
print(("layer0=", self.layer0))
print(("layer1=", self.layer1))
def __getitem__(self, item):
return self.layer1[item]
def __setitem__(self, key, value):
self.set_value(key, value)
from operator import itemgetter
def main():
inf = 10**18
N, M, *LRC = list(map(int, open(0).read().split()))
LRC = list(zip(*[iter(LRC)] * 3))
LRC.sort(key=itemgetter(0))
idx_LRC = 0
q = []
seg = Rmq(N + 1, inf=inf)
seg.set_value(1, 0)
for v in range(1, N + 1):
d = seg.get_min(v, N + 1)
while idx_LRC < M:
l, r, c = LRC[idx_LRC]
if l <= v:
seg.chmin(r, d + c)
idx_LRC += 1
else:
break
ans = seg[N]
print((ans if ans != inf else -1))
main()
| false | 2.469136 | [
"-# いろいろ高速化",
"-# https://atcoder.jp/contests/nikkei2019-2-qual/submissions/8436413",
"+# min の実験",
"+from functools import reduce, partial",
"+",
"+min = partial(reduce, lambda x, y: x if x < y else y)",
"+",
"+",
"- min(self.layer0[parent_l:parent_r]),",
"- min(self... | false | 0.036464 | 0.03656 | 0.997369 | [
"s364080294",
"s987154964"
] |
u086566114 | p02269 | python | s540014037 | s024668686 | 6,960 | 1,190 | 557,484 | 32,904 | Accepted | Accepted | 82.9 | # -*- coding: utf-8 -*-
def input_converter(key_string):
key_string = key_string.replace('A', '1')
key_string = key_string.replace('T', '2')
key_string = key_string.replace('C', '3')
key_string = key_string.replace('G', '4')
return int(key_string)
class HashTable(object):
def __init__(self, hash_size = 2 ** 26):
self.hash_size = hash_size
self.hash_array = [None] * self.hash_size
def insert_value(self, data, key):
collision_number = 0
next_index = self.hash_function(key, collision_number)
while self.hash_array[next_index] is not None:
collision_number += 1
next_index = self.hash_function(key, collision_number)
self.hash_array[next_index] = data
def search_value(self, data, key):
collision_number = 0
next_index = self.hash_function(key, collision_number)
next_data = self.hash_array[next_index]
while True:
if (next_data is None) or (collision_number > self.hash_size):
return False
elif next_data == data:
return True
else:
collision_number +=1
next_index = self.hash_function(key, collision_number)
next_data = self.hash_array[next_index]
def hash_function(self, key, collision_number):
def h1(key):
return key % self.hash_size
def h2(key):
return key % (self.hash_size - 1)
return (h1(key) + collision_number * h2(key)) % self.hash_size
def main():
input_size = int(input())
hash_table = HashTable()
counter = 0
while counter < input_size:
command, key = input().split(' ')
if command == 'insert':
hash_table.insert_value(key, input_converter(key))
else:
if hash_table.search_value(key, input_converter(key)):
print('yes')
else:
print('no')
counter += 1
if __name__ == '__main__':
main() | # -*- coding: utf-8 -*-
def main():
dictionary = {}
input_num = int(input())
counter = 0
while counter < input_num:
command, key = input().split(' ')
if command == 'insert':
dictionary[key] = True
else:
if key in dictionary:
print('yes')
else:
print('no')
counter += 1
if __name__ == '__main__':
main() | 65 | 21 | 2,119 | 450 | # -*- coding: utf-8 -*-
def input_converter(key_string):
key_string = key_string.replace("A", "1")
key_string = key_string.replace("T", "2")
key_string = key_string.replace("C", "3")
key_string = key_string.replace("G", "4")
return int(key_string)
class HashTable(object):
def __init__(self, hash_size=2**26):
self.hash_size = hash_size
self.hash_array = [None] * self.hash_size
def insert_value(self, data, key):
collision_number = 0
next_index = self.hash_function(key, collision_number)
while self.hash_array[next_index] is not None:
collision_number += 1
next_index = self.hash_function(key, collision_number)
self.hash_array[next_index] = data
def search_value(self, data, key):
collision_number = 0
next_index = self.hash_function(key, collision_number)
next_data = self.hash_array[next_index]
while True:
if (next_data is None) or (collision_number > self.hash_size):
return False
elif next_data == data:
return True
else:
collision_number += 1
next_index = self.hash_function(key, collision_number)
next_data = self.hash_array[next_index]
def hash_function(self, key, collision_number):
def h1(key):
return key % self.hash_size
def h2(key):
return key % (self.hash_size - 1)
return (h1(key) + collision_number * h2(key)) % self.hash_size
def main():
input_size = int(input())
hash_table = HashTable()
counter = 0
while counter < input_size:
command, key = input().split(" ")
if command == "insert":
hash_table.insert_value(key, input_converter(key))
else:
if hash_table.search_value(key, input_converter(key)):
print("yes")
else:
print("no")
counter += 1
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
def main():
dictionary = {}
input_num = int(input())
counter = 0
while counter < input_num:
command, key = input().split(" ")
if command == "insert":
dictionary[key] = True
else:
if key in dictionary:
print("yes")
else:
print("no")
counter += 1
if __name__ == "__main__":
main()
| false | 67.692308 | [
"-def input_converter(key_string):",
"- key_string = key_string.replace(\"A\", \"1\")",
"- key_string = key_string.replace(\"T\", \"2\")",
"- key_string = key_string.replace(\"C\", \"3\")",
"- key_string = key_string.replace(\"G\", \"4\")",
"- return int(key_string)",
"-",
"-",
"-clas... | false | 0.056373 | 0.073944 | 0.762366 | [
"s540014037",
"s024668686"
] |
u905329882 | p03112 | python | s782776811 | s863956616 | 1,956 | 1,287 | 131,800 | 124,508 | Accepted | Accepted | 34.2 | a,b,q=list(map(int,input().split()))
s=[int(eval(input())) for i in range(a)]
t=[int(eval(input())) for i in range(b)]
x=[int(eval(input())) for i in range(q)]
import bisect
inf=10**11
def tansak(lis,lis2,dis):
ind=bisect.bisect_left(lis,dis)
ind2=bisect.bisect_left(lis2,dis)
return ind,ind2
for i in range(q):
now = x[i]
ind,ind2 = tansak(s,t,now)
if ind==0:
one=-inf
else:
one=s[ind-1]
if ind==a:
two=inf
else:
two=s[ind]
if ind2==0:
thr=-inf
else:
thr=t[ind2-1]
if ind2==b:
fo=inf
else:
fo=t[ind2]
tmp1=max(two,fo)-now
tmp2=2*two-thr-now
tmp3=2*fo-one-now
tmp4=now-min(one,thr)
tmp5=now-thr+two-thr
tmp6=now-one+fo-one
print((min(tmp1,tmp2,tmp3,tmp4,tmp5,tmp6)))
| import sys
import math
def input():
return sys.stdin.readline()[:-1]
a,b,q=list(map(int,input().split()))
s=[int(eval(input())) for i in range(a)]
t=[int(eval(input())) for i in range(b)]
x=[int(eval(input())) for i in range(q)]
import bisect
inf=10**11
def tansak(lis,lis2,dis):
ind=bisect.bisect_left(lis,dis)
ind2=bisect.bisect_left(lis2,dis)
return ind,ind2
for i in range(q):
now = x[i]
ind,ind2 = tansak(s,t,now)
if ind==0:
one=-inf
else:
one=s[ind-1]
if ind==a:
two=inf
else:
two=s[ind]
if ind2==0:
thr=-inf
else:
thr=t[ind2-1]
if ind2==b:
fo=inf
else:
fo=t[ind2]
tmp1=max(two,fo)-now
tmp2=2*two-thr-now
tmp3=2*fo-one-now
tmp4=now-min(one,thr)
tmp5=now-thr+two-thr
tmp6=now-one+fo-one
print((min(tmp1,tmp2,tmp3,tmp4,tmp5,tmp6)))
| 39 | 43 | 827 | 904 | a, b, q = list(map(int, input().split()))
s = [int(eval(input())) for i in range(a)]
t = [int(eval(input())) for i in range(b)]
x = [int(eval(input())) for i in range(q)]
import bisect
inf = 10**11
def tansak(lis, lis2, dis):
ind = bisect.bisect_left(lis, dis)
ind2 = bisect.bisect_left(lis2, dis)
return ind, ind2
for i in range(q):
now = x[i]
ind, ind2 = tansak(s, t, now)
if ind == 0:
one = -inf
else:
one = s[ind - 1]
if ind == a:
two = inf
else:
two = s[ind]
if ind2 == 0:
thr = -inf
else:
thr = t[ind2 - 1]
if ind2 == b:
fo = inf
else:
fo = t[ind2]
tmp1 = max(two, fo) - now
tmp2 = 2 * two - thr - now
tmp3 = 2 * fo - one - now
tmp4 = now - min(one, thr)
tmp5 = now - thr + two - thr
tmp6 = now - one + fo - one
print((min(tmp1, tmp2, tmp3, tmp4, tmp5, tmp6)))
| import sys
import math
def input():
return sys.stdin.readline()[:-1]
a, b, q = list(map(int, input().split()))
s = [int(eval(input())) for i in range(a)]
t = [int(eval(input())) for i in range(b)]
x = [int(eval(input())) for i in range(q)]
import bisect
inf = 10**11
def tansak(lis, lis2, dis):
ind = bisect.bisect_left(lis, dis)
ind2 = bisect.bisect_left(lis2, dis)
return ind, ind2
for i in range(q):
now = x[i]
ind, ind2 = tansak(s, t, now)
if ind == 0:
one = -inf
else:
one = s[ind - 1]
if ind == a:
two = inf
else:
two = s[ind]
if ind2 == 0:
thr = -inf
else:
thr = t[ind2 - 1]
if ind2 == b:
fo = inf
else:
fo = t[ind2]
tmp1 = max(two, fo) - now
tmp2 = 2 * two - thr - now
tmp3 = 2 * fo - one - now
tmp4 = now - min(one, thr)
tmp5 = now - thr + two - thr
tmp6 = now - one + fo - one
print((min(tmp1, tmp2, tmp3, tmp4, tmp5, tmp6)))
| false | 9.302326 | [
"+import sys",
"+import math",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline()[:-1]",
"+",
"+"
] | false | 0.042804 | 0.0432 | 0.99083 | [
"s782776811",
"s863956616"
] |
u133936772 | p03805 | python | s960201100 | s846839094 | 37 | 30 | 9,360 | 9,244 | Accepted | Accepted | 18.92 | f=lambda:list(map(int,input().split()))
n,m=f()
g=[[0]*n for _ in range(n)]
for _ in range(m):
a,b=f()
g[a-1][b-1]=1
g[b-1][a-1]=1
from itertools import *
p=[*permutations(list(range(1,n)))]
a=0
for t in p:
v=0
for c in t:
if g[v][c]: v=c
else: break
else: a+=1
print(a) | f=lambda:list(map(int,input().split()))
n,m=f()
g=[[] for _ in range(n)]
for _ in range(m):
a,b=f()
g[a-1]+=[b-1]
g[b-1]+=[a-1]
from itertools import *
p=[*permutations(list(range(1,n)))]
a=0
for t in p:
v=0
for c in t:
if c in g[v]: v=c
else: break
else: a+=1
print(a) | 17 | 17 | 294 | 293 | f = lambda: list(map(int, input().split()))
n, m = f()
g = [[0] * n for _ in range(n)]
for _ in range(m):
a, b = f()
g[a - 1][b - 1] = 1
g[b - 1][a - 1] = 1
from itertools import *
p = [*permutations(list(range(1, n)))]
a = 0
for t in p:
v = 0
for c in t:
if g[v][c]:
v = c
else:
break
else:
a += 1
print(a)
| f = lambda: list(map(int, input().split()))
n, m = f()
g = [[] for _ in range(n)]
for _ in range(m):
a, b = f()
g[a - 1] += [b - 1]
g[b - 1] += [a - 1]
from itertools import *
p = [*permutations(list(range(1, n)))]
a = 0
for t in p:
v = 0
for c in t:
if c in g[v]:
v = c
else:
break
else:
a += 1
print(a)
| false | 0 | [
"-g = [[0] * n for _ in range(n)]",
"+g = [[] for _ in range(n)]",
"- g[a - 1][b - 1] = 1",
"- g[b - 1][a - 1] = 1",
"+ g[a - 1] += [b - 1]",
"+ g[b - 1] += [a - 1]",
"- if g[v][c]:",
"+ if c in g[v]:"
] | false | 0.040793 | 0.044455 | 0.917624 | [
"s960201100",
"s846839094"
] |
u952467214 | p03162 | python | s082331220 | s264493545 | 602 | 363 | 34,616 | 61,532 | Accepted | Accepted | 39.7 | N = int(eval(input()))
a = [0]*N
b = [0]*N
c = [0]*N
for i in range(N):
a[i], b[i], c[i] = [int(_) for _ in input().split()]
dp = [[0] * 3 for _ in range(N)]
dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]
for i in range(N-1):
dp[i+1][0] = max(dp[i+1][0], dp[i][1] + a[i+1], dp[i][2] + a[i+1] )
dp[i+1][1] = max(dp[i+1][1], dp[i][2] + b[i+1], dp[i][0] + b[i+1] )
dp[i+1][2] = max(dp[i+1][2], dp[i][0] + c[i+1], dp[i][1] + c[i+1] )
print((max(dp[N-1])))
| import sys
input = sys.stdin.readline
n = int(eval(input()))
abc = [tuple(map(int,input().split())) for i in range(n)]
dp_a = [0]*n
dp_b = [0]*n
dp_c = [0]*n
a,b,c = abc[0]
dp_a[0] = a
dp_b[0] = b
dp_c[0] = c
for i in range(1,n):
a, b, c = abc[i]
dp_a[i] = max(dp_b[i-1]+a, dp_c[i-1]+a)
dp_b[i] = max(dp_c[i-1]+b, dp_a[i-1]+b)
dp_c[i] = max(dp_a[i-1]+c, dp_b[i-1]+c)
print((max(dp_a[-1], dp_b[-1], dp_c[-1])))
| 20 | 21 | 486 | 442 | N = int(eval(input()))
a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
a[i], b[i], c[i] = [int(_) for _ in input().split()]
dp = [[0] * 3 for _ in range(N)]
dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]
for i in range(N - 1):
dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + a[i + 1], dp[i][2] + a[i + 1])
dp[i + 1][1] = max(dp[i + 1][1], dp[i][2] + b[i + 1], dp[i][0] + b[i + 1])
dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + c[i + 1], dp[i][1] + c[i + 1])
print((max(dp[N - 1])))
| import sys
input = sys.stdin.readline
n = int(eval(input()))
abc = [tuple(map(int, input().split())) for i in range(n)]
dp_a = [0] * n
dp_b = [0] * n
dp_c = [0] * n
a, b, c = abc[0]
dp_a[0] = a
dp_b[0] = b
dp_c[0] = c
for i in range(1, n):
a, b, c = abc[i]
dp_a[i] = max(dp_b[i - 1] + a, dp_c[i - 1] + a)
dp_b[i] = max(dp_c[i - 1] + b, dp_a[i - 1] + b)
dp_c[i] = max(dp_a[i - 1] + c, dp_b[i - 1] + c)
print((max(dp_a[-1], dp_b[-1], dp_c[-1])))
| false | 4.761905 | [
"-N = int(eval(input()))",
"-a = [0] * N",
"-b = [0] * N",
"-c = [0] * N",
"-for i in range(N):",
"- a[i], b[i], c[i] = [int(_) for _ in input().split()]",
"-dp = [[0] * 3 for _ in range(N)]",
"-dp[0][0] = a[0]",
"-dp[0][1] = b[0]",
"-dp[0][2] = c[0]",
"-for i in range(N - 1):",
"- dp[i ... | false | 0.071538 | 0.034268 | 2.087608 | [
"s082331220",
"s264493545"
] |
u391731808 | p03835 | python | s481818640 | s771315322 | 1,564 | 1,016 | 3,060 | 2,940 | Accepted | Accepted | 35.04 | K,S=list(map(int,input().split()))
ans=0
for x in range(K+1):
for y in range(K+1):z=S-x-y;ans+=(0<=z<=K)
print(ans) | K,S=list(map(int,input().split()))
print((sum(0<=S-x-y<=K for x in range(K+1)for y in range(K+1)))) | 5 | 2 | 114 | 92 | K, S = list(map(int, input().split()))
ans = 0
for x in range(K + 1):
for y in range(K + 1):
z = S - x - y
ans += 0 <= z <= K
print(ans)
| K, S = list(map(int, input().split()))
print((sum(0 <= S - x - y <= K for x in range(K + 1) for y in range(K + 1))))
| false | 60 | [
"-ans = 0",
"-for x in range(K + 1):",
"- for y in range(K + 1):",
"- z = S - x - y",
"- ans += 0 <= z <= K",
"-print(ans)",
"+print((sum(0 <= S - x - y <= K for x in range(K + 1) for y in range(K + 1))))"
] | false | 0.07026 | 0.043222 | 1.625564 | [
"s481818640",
"s771315322"
] |
u712335892 | p04045 | python | s128207314 | s395023390 | 1,502 | 105 | 7,396 | 3,064 | Accepted | Accepted | 93.01 | def no_dislike_number(num, D):
for dislike in D:
if dislike in num:
return False
return True
MAX = 10000
N, K = list(map(int, input().split()))
D = input().split()
num = N
while(True):
if no_dislike_number(str(num), D):
print(num)
break
num += 1 | def no_dislike_number(num, D):
for digit in num:
if digit in D:
return False
return True
# for dislike in D:
# if dislike in num:
# return False
# return True
MAX = 10000
N, K = list(map(int, input().split()))
D = input().split()
num = N
while(True):
if no_dislike_number(str(num), D):
print(num)
break
num += 1 | 15 | 19 | 306 | 404 | def no_dislike_number(num, D):
for dislike in D:
if dislike in num:
return False
return True
MAX = 10000
N, K = list(map(int, input().split()))
D = input().split()
num = N
while True:
if no_dislike_number(str(num), D):
print(num)
break
num += 1
| def no_dislike_number(num, D):
for digit in num:
if digit in D:
return False
return True
# for dislike in D:
# if dislike in num:
# return False
# return True
MAX = 10000
N, K = list(map(int, input().split()))
D = input().split()
num = N
while True:
if no_dislike_number(str(num), D):
print(num)
break
num += 1
| false | 21.052632 | [
"- for dislike in D:",
"- if dislike in num:",
"+ for digit in num:",
"+ if digit in D:",
"+ # for dislike in D:",
"+ # if dislike in num:",
"+ # return False",
"+ # return True"
] | false | 0.149976 | 0.040653 | 3.689175 | [
"s128207314",
"s395023390"
] |
u633068244 | p00629 | python | s542920975 | s540353760 | 20 | 10 | 4,284 | 4,272 | Accepted | Accepted | 50 | while 1:
n=eval(input())
if n==0:break
t=[list(map(int,input().split())) for i in [1]*n]
t=sorted(sorted(sorted(t),key=lambda x:x[3])[::-1],key=lambda x:x[2])[::-1]
u=[0 for i in range(1001)]
s=0
for i in t:
if (s<10 and u[i[1]]<3) or (s<20 and u[i[1]]<2) or (s<26 and u[i[1]]<1):
print(i[0])
u[i[1]]+=1
s+=1
| while 1:
n=eval(input())
if n==0:break
t=[list(map(int,input().split())) for i in [1]*n]
t=sorted(sorted(sorted(t),key=lambda x:x[3])[::-1],key=lambda x:x[2])[::-1]
u=[0]*1001
s=0
for i in t:
if (s<10 and u[i[1]]<3) or (s<20 and u[i[1]]<2) or (s<26 and u[i[1]]<1):
print(i[0])
u[i[1]]+=1
s+=1 | 13 | 12 | 367 | 366 | while 1:
n = eval(input())
if n == 0:
break
t = [list(map(int, input().split())) for i in [1] * n]
t = sorted(sorted(sorted(t), key=lambda x: x[3])[::-1], key=lambda x: x[2])[::-1]
u = [0 for i in range(1001)]
s = 0
for i in t:
if (
(s < 10 and u[i[1]] < 3)
or (s < 20 and u[i[1]] < 2)
or (s < 26 and u[i[1]] < 1)
):
print(i[0])
u[i[1]] += 1
s += 1
| while 1:
n = eval(input())
if n == 0:
break
t = [list(map(int, input().split())) for i in [1] * n]
t = sorted(sorted(sorted(t), key=lambda x: x[3])[::-1], key=lambda x: x[2])[::-1]
u = [0] * 1001
s = 0
for i in t:
if (
(s < 10 and u[i[1]] < 3)
or (s < 20 and u[i[1]] < 2)
or (s < 26 and u[i[1]] < 1)
):
print(i[0])
u[i[1]] += 1
s += 1
| false | 7.692308 | [
"- u = [0 for i in range(1001)]",
"+ u = [0] * 1001"
] | false | 0.037437 | 0.037113 | 1.008738 | [
"s542920975",
"s540353760"
] |
u056358163 | p02695 | python | s150753852 | s553701645 | 167 | 149 | 84,624 | 68,200 | Accepted | Accepted | 10.78 | import itertools
N, M, Q = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(Q)]
n = [i+1 for i in range(M)]
A_list = list(itertools.combinations_with_replacement(n,N))
ans = 0
for A in A_list:
ans_ = 0
for a, b, c, d in l:
if A[b-1] - A[a-1] == c:
ans_ += d
ans = max(ans, ans_)
print(ans) | N, M, Q = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(Q)]
A = [1] * N
ans = 0
for a, b, c, d in l:
if A[b-1] - A[a-1] == c:
ans += d
if M > 1:
while True:
A[-1] += 1
if A[-1] == M + 1:
for i in range(1, N):
A[-(i+1)] += 1
for k in range(N-(i+1), N):
A[k] = A[-(i+1)]
if A[-(i+1)] != M + 1:
break
ans_ = 0
for a, b, c, d in l:
if A[b-1] - A[a-1] == c:
ans_ += d
ans = max(ans, ans_)
if A[0] == M:
break
print(ans)
| 15 | 36 | 370 | 717 | import itertools
N, M, Q = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(Q)]
n = [i + 1 for i in range(M)]
A_list = list(itertools.combinations_with_replacement(n, N))
ans = 0
for A in A_list:
ans_ = 0
for a, b, c, d in l:
if A[b - 1] - A[a - 1] == c:
ans_ += d
ans = max(ans, ans_)
print(ans)
| N, M, Q = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(Q)]
A = [1] * N
ans = 0
for a, b, c, d in l:
if A[b - 1] - A[a - 1] == c:
ans += d
if M > 1:
while True:
A[-1] += 1
if A[-1] == M + 1:
for i in range(1, N):
A[-(i + 1)] += 1
for k in range(N - (i + 1), N):
A[k] = A[-(i + 1)]
if A[-(i + 1)] != M + 1:
break
ans_ = 0
for a, b, c, d in l:
if A[b - 1] - A[a - 1] == c:
ans_ += d
ans = max(ans, ans_)
if A[0] == M:
break
print(ans)
| false | 58.333333 | [
"-import itertools",
"-",
"-n = [i + 1 for i in range(M)]",
"-A_list = list(itertools.combinations_with_replacement(n, N))",
"+A = [1] * N",
"-for A in A_list:",
"- ans_ = 0",
"- for a, b, c, d in l:",
"- if A[b - 1] - A[a - 1] == c:",
"- ans_ += d",
"+for a, b, c, d in l... | false | 0.113556 | 0.065232 | 1.740796 | [
"s150753852",
"s553701645"
] |
u010110540 | p03599 | python | s200222477 | s825995233 | 469 | 362 | 45,316 | 45,312 | Accepted | Accepted | 22.81 | A, B, C, D, E, F = list(map(int, input().split()))
memo = []
for a in range(31):
for b in range(31):
for c in range(101):
for d in range(101):
w = (100*A)*a + (100*B)*b
s = C*c + D*d
if w+s > F:
break
else:
if w/100 * E >= s:
memo.append([w+s,s])
print((*sorted(memo, key=lambda x: (100*x[1] / x[0] if x[0] else 0))[-1])) | def solve():
A, B, C, D, E, F = list(map(int, input().split()))
memo = []
for a in range(31):
for b in range(31):
for c in range(101):
for d in range(101):
w = (100*A)*a + (100*B)*b
s = C*c + D*d
if w+s > F:
break
else:
if w/100 * E >= s:
memo.append([w+s,s])
print((*sorted(memo, key=lambda x: (100*x[1] / x[0] if x[0] else 0))[-1]))
if __name__ == '__main__':
solve() | 16 | 21 | 482 | 609 | A, B, C, D, E, F = list(map(int, input().split()))
memo = []
for a in range(31):
for b in range(31):
for c in range(101):
for d in range(101):
w = (100 * A) * a + (100 * B) * b
s = C * c + D * d
if w + s > F:
break
else:
if w / 100 * E >= s:
memo.append([w + s, s])
print((*sorted(memo, key=lambda x: (100 * x[1] / x[0] if x[0] else 0))[-1]))
| def solve():
A, B, C, D, E, F = list(map(int, input().split()))
memo = []
for a in range(31):
for b in range(31):
for c in range(101):
for d in range(101):
w = (100 * A) * a + (100 * B) * b
s = C * c + D * d
if w + s > F:
break
else:
if w / 100 * E >= s:
memo.append([w + s, s])
print((*sorted(memo, key=lambda x: (100 * x[1] / x[0] if x[0] else 0))[-1]))
if __name__ == "__main__":
solve()
| false | 23.809524 | [
"-A, B, C, D, E, F = list(map(int, input().split()))",
"-memo = []",
"-for a in range(31):",
"- for b in range(31):",
"- for c in range(101):",
"- for d in range(101):",
"- w = (100 * A) * a + (100 * B) * b",
"- s = C * c + D * d",
"- ... | false | 0.281145 | 0.23175 | 1.213139 | [
"s200222477",
"s825995233"
] |
u844789719 | p03725 | python | s260845200 | s741597074 | 1,004 | 606 | 114,524 | 77,020 | Accepted | Accepted | 39.64 | import itertools, math, collections, sys
input = sys.stdin.readline
H, W, K = [int(_) for _ in input().split()]
A = [list(eval(input())) for _ in range(H)]
for i, j in itertools.product(list(range(H)), list(range(W))):
if A[i][j] == 'S':
break
Q = collections.deque([[i, j, 0]])
sH = set()
sW = set()
while Q:
h, w, dist = Q.popleft()
if A[h][w] == '#':
continue
A[h][w] = '#'
sH.add(h)
sW.add(w)
if dist < K:
for nh, nw in [[h - 1, w], [h + 1, w], [h, w - 1], [h, w + 1]]:
if 0 <= nh < H and 0 <= nw < W:
Q += [[nh, nw, dist + 1]]
print((1 + min([
math.ceil(_ / K)
for _ in (min(sH), H - 1 - max(sH), min(sW), W - 1 - max(sW))
])))
| import itertools, math, collections, sys
input = sys.stdin.readline
H, W, K = [int(_) for _ in input().split()]
A = [list(eval(input())) for _ in range(H)]
for i, j in itertools.product(list(range(H)), list(range(W))):
if A[i][j] == 'S':
break
Q = collections.deque([[i, j, 0]])
sH = set()
sW = set()
while Q:
h, w, dist = Q.popleft()
sH.add(h)
sW.add(w)
if dist < K:
for nh, nw in [[h - 1, w], [h + 1, w], [h, w - 1], [h, w + 1]]:
if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == '.':
A[nh][nw] = '#'
Q += [[nh, nw, dist + 1]]
print((1 + min([
math.ceil(_ / K)
for _ in (min(sH), H - 1 - max(sH), min(sW), W - 1 - max(sW))
])))
| 25 | 23 | 725 | 718 | import itertools, math, collections, sys
input = sys.stdin.readline
H, W, K = [int(_) for _ in input().split()]
A = [list(eval(input())) for _ in range(H)]
for i, j in itertools.product(list(range(H)), list(range(W))):
if A[i][j] == "S":
break
Q = collections.deque([[i, j, 0]])
sH = set()
sW = set()
while Q:
h, w, dist = Q.popleft()
if A[h][w] == "#":
continue
A[h][w] = "#"
sH.add(h)
sW.add(w)
if dist < K:
for nh, nw in [[h - 1, w], [h + 1, w], [h, w - 1], [h, w + 1]]:
if 0 <= nh < H and 0 <= nw < W:
Q += [[nh, nw, dist + 1]]
print(
(
1
+ min(
[
math.ceil(_ / K)
for _ in (min(sH), H - 1 - max(sH), min(sW), W - 1 - max(sW))
]
)
)
)
| import itertools, math, collections, sys
input = sys.stdin.readline
H, W, K = [int(_) for _ in input().split()]
A = [list(eval(input())) for _ in range(H)]
for i, j in itertools.product(list(range(H)), list(range(W))):
if A[i][j] == "S":
break
Q = collections.deque([[i, j, 0]])
sH = set()
sW = set()
while Q:
h, w, dist = Q.popleft()
sH.add(h)
sW.add(w)
if dist < K:
for nh, nw in [[h - 1, w], [h + 1, w], [h, w - 1], [h, w + 1]]:
if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == ".":
A[nh][nw] = "#"
Q += [[nh, nw, dist + 1]]
print(
(
1
+ min(
[
math.ceil(_ / K)
for _ in (min(sH), H - 1 - max(sH), min(sW), W - 1 - max(sW))
]
)
)
)
| false | 8 | [
"- if A[h][w] == \"#\":",
"- continue",
"- A[h][w] = \"#\"",
"- if 0 <= nh < H and 0 <= nw < W:",
"+ if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == \".\":",
"+ A[nh][nw] = \"#\""
] | false | 0.120595 | 0.042353 | 2.847401 | [
"s260845200",
"s741597074"
] |
u729133443 | p03262 | python | s116657514 | s215713588 | 447 | 81 | 62,704 | 11,596 | Accepted | Accepted | 81.88 | N,X=list(map(int,input().split()))
x=sorted([abs(int(x)-X) for x in input().split()])
for i in range(x[0]+1)[::-1]:
if x[0]%i:continue
if sum([x%i for x in x])==0:
print(i)
break | from functools import reduce
def g(a,b):
while b:a,b=b,a%b
return a
def f(x):return reduce(g,x)
X=int(input().split()[1]);print((f([abs(int(x)-X) for x in input().split()]))) | 7 | 6 | 208 | 184 | N, X = list(map(int, input().split()))
x = sorted([abs(int(x) - X) for x in input().split()])
for i in range(x[0] + 1)[::-1]:
if x[0] % i:
continue
if sum([x % i for x in x]) == 0:
print(i)
break
| from functools import reduce
def g(a, b):
while b:
a, b = b, a % b
return a
def f(x):
return reduce(g, x)
X = int(input().split()[1])
print((f([abs(int(x) - X) for x in input().split()])))
| false | 14.285714 | [
"-N, X = list(map(int, input().split()))",
"-x = sorted([abs(int(x) - X) for x in input().split()])",
"-for i in range(x[0] + 1)[::-1]:",
"- if x[0] % i:",
"- continue",
"- if sum([x % i for x in x]) == 0:",
"- print(i)",
"- break",
"+from functools import reduce",
"+",
... | false | 0.041213 | 0.087034 | 0.473527 | [
"s116657514",
"s215713588"
] |
u423665486 | p03575 | python | s452201051 | s273514459 | 265 | 67 | 53,208 | 68,876 | Accepted | Accepted | 74.72 | import sys
from io import StringIO
import unittest
sys.setrecursionlimit(10**5)
def dfs(u, visited, g, seq):
visited[u] = True
for v in g[u]:
if visited[v] == True or not seq[u][v]:
continue
dfs(v, visited, g, seq)
def resolve():
n, m = list(map(int, input().split()))
seq = [[True]*n for _ in range(n)]
g = [[] for _ in range(n)]
edges = []
ans = 0
for _ in range(m):
a, b = list(map(int, input().split()))
edges.append([a-1, b-1])
for i in range(m):
g[edges[i][0]].append(edges[i][1])
g[edges[i][1]].append(edges[i][0])
for i in range(m):
visited = [False]*n
seq[edges[i][1]][edges[i][0]] = False
seq[edges[i][0]][edges[i][1]] = False
dfs(0, visited, g, seq)
if len(visited) != visited.count(True):
ans += 1
seq[edges[i][1]][edges[i][0]] = True
seq[edges[i][0]][edges[i][1]] = True
print(ans)
resolve() | def search(u, g, visited):
if visited[u]:
return
visited[u] = True
for v in g[u]:
search(v, g, visited)
def resolve():
n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]
ans = 0
for i in range(m):
g = [[] for _ in range(n)]
for j in range(m):
if i == j:
continue
a, b = edges[j]
g[a-1].append(b-1)
g[b-1].append(a-1)
visited = [False]*n
search(0, g, visited)
if visited.count(True) != n:
ans += 1
print(ans)
resolve() | 39 | 25 | 879 | 525 | import sys
from io import StringIO
import unittest
sys.setrecursionlimit(10**5)
def dfs(u, visited, g, seq):
visited[u] = True
for v in g[u]:
if visited[v] == True or not seq[u][v]:
continue
dfs(v, visited, g, seq)
def resolve():
n, m = list(map(int, input().split()))
seq = [[True] * n for _ in range(n)]
g = [[] for _ in range(n)]
edges = []
ans = 0
for _ in range(m):
a, b = list(map(int, input().split()))
edges.append([a - 1, b - 1])
for i in range(m):
g[edges[i][0]].append(edges[i][1])
g[edges[i][1]].append(edges[i][0])
for i in range(m):
visited = [False] * n
seq[edges[i][1]][edges[i][0]] = False
seq[edges[i][0]][edges[i][1]] = False
dfs(0, visited, g, seq)
if len(visited) != visited.count(True):
ans += 1
seq[edges[i][1]][edges[i][0]] = True
seq[edges[i][0]][edges[i][1]] = True
print(ans)
resolve()
| def search(u, g, visited):
if visited[u]:
return
visited[u] = True
for v in g[u]:
search(v, g, visited)
def resolve():
n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]
ans = 0
for i in range(m):
g = [[] for _ in range(n)]
for j in range(m):
if i == j:
continue
a, b = edges[j]
g[a - 1].append(b - 1)
g[b - 1].append(a - 1)
visited = [False] * n
search(0, g, visited)
if visited.count(True) != n:
ans += 1
print(ans)
resolve()
| false | 35.897436 | [
"-import sys",
"-from io import StringIO",
"-import unittest",
"-",
"-sys.setrecursionlimit(10**5)",
"-",
"-",
"-def dfs(u, visited, g, seq):",
"+def search(u, g, visited):",
"+ if visited[u]:",
"+ return",
"- if visited[v] == True or not seq[u][v]:",
"- continue"... | false | 0.035864 | 0.049047 | 0.731202 | [
"s452201051",
"s273514459"
] |
u352394527 | p00461 | python | s517767334 | s786798060 | 350 | 230 | 7,300 | 7,300 | Accepted | Accepted | 34.29 | while True:
n = int(eval(input()))
if not n: break
m = int(eval(input()))
s = eval(input())
ind = 0
ans = 0
while ind < m:
if s[ind] == "I":
count = 0
while ind + 2 < m:
if s[ind + 1] == "O" and s[ind + 2] == "I":
count += 1
ind += 2
else:
break
if count - n + 1 >= 0:
ans += (count - n + 1)
ind += 1
print(ans)
| def solve():
while True:
n = int(eval(input()))
if not n: break
m = int(eval(input()))
s = eval(input())
ind = 0
ans = 0
while ind < m:
if s[ind] == "I":
count = 0
while ind + 2 < m:
if s[ind + 1] == "O" and s[ind + 2] == "I":
count += 1
ind += 2
else:
break
if count - n + 1 >= 0:
ans += (count - n + 1)
ind += 1
print(ans)
solve()
| 20 | 22 | 409 | 472 | while True:
n = int(eval(input()))
if not n:
break
m = int(eval(input()))
s = eval(input())
ind = 0
ans = 0
while ind < m:
if s[ind] == "I":
count = 0
while ind + 2 < m:
if s[ind + 1] == "O" and s[ind + 2] == "I":
count += 1
ind += 2
else:
break
if count - n + 1 >= 0:
ans += count - n + 1
ind += 1
print(ans)
| def solve():
while True:
n = int(eval(input()))
if not n:
break
m = int(eval(input()))
s = eval(input())
ind = 0
ans = 0
while ind < m:
if s[ind] == "I":
count = 0
while ind + 2 < m:
if s[ind + 1] == "O" and s[ind + 2] == "I":
count += 1
ind += 2
else:
break
if count - n + 1 >= 0:
ans += count - n + 1
ind += 1
print(ans)
solve()
| false | 9.090909 | [
"-while True:",
"- n = int(eval(input()))",
"- if not n:",
"- break",
"- m = int(eval(input()))",
"- s = eval(input())",
"- ind = 0",
"- ans = 0",
"- while ind < m:",
"- if s[ind] == \"I\":",
"- count = 0",
"- while ind + 2 < m:",
"- ... | false | 0.045011 | 0.046695 | 0.963933 | [
"s517767334",
"s786798060"
] |
u804455323 | p02813 | python | s004756493 | s989424908 | 201 | 173 | 40,300 | 39,024 | Accepted | Accepted | 13.93 | from itertools import permutations
N = int(eval(input()))
P, Q = input().replace(' ', ''), input().replace(' ', '')
a = b = x = 0
for d in permutations(''.join(map(str, list(range(1, N+1)))), N):
x += 1
s = ''.join(d)
if s == P:
a = x
if s == Q:
b = x
print((abs(a - b))) | from itertools import permutations
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
i = a = b = 0
for x in permutations(list(range(1, N+1)), N):
i += 1
if x == P:
a = i
if x == Q:
b = i
print((abs(a - b))) | 12 | 12 | 284 | 264 | from itertools import permutations
N = int(eval(input()))
P, Q = input().replace(" ", ""), input().replace(" ", "")
a = b = x = 0
for d in permutations("".join(map(str, list(range(1, N + 1)))), N):
x += 1
s = "".join(d)
if s == P:
a = x
if s == Q:
b = x
print((abs(a - b)))
| from itertools import permutations
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
i = a = b = 0
for x in permutations(list(range(1, N + 1)), N):
i += 1
if x == P:
a = i
if x == Q:
b = i
print((abs(a - b)))
| false | 0 | [
"-P, Q = input().replace(\" \", \"\"), input().replace(\" \", \"\")",
"-a = b = x = 0",
"-for d in permutations(\"\".join(map(str, list(range(1, N + 1)))), N):",
"- x += 1",
"- s = \"\".join(d)",
"- if s == P:",
"- a = x",
"- if s == Q:",
"- b = x",
"+P = tuple(map(int, i... | false | 0.045461 | 0.04484 | 1.013845 | [
"s004756493",
"s989424908"
] |
u809819902 | p02987 | python | s376168503 | s697205061 | 27 | 23 | 8,956 | 9,108 | Accepted | Accepted | 14.81 | s = eval(input())
a = sorted(s)
print(("Yes" if a[0]==a[1] and a[2]==a[3] and a[0] != a[2] else "No"))
| s=eval(input())
d={}
for i in range(4):
if s[i] not in d:
d[s[i]]=1
else:
d[s[i]]+=1
ans="Yes"
for i in d:
if d[i]!=2:
ans="No"
print(ans) | 3 | 12 | 97 | 179 | s = eval(input())
a = sorted(s)
print(("Yes" if a[0] == a[1] and a[2] == a[3] and a[0] != a[2] else "No"))
| s = eval(input())
d = {}
for i in range(4):
if s[i] not in d:
d[s[i]] = 1
else:
d[s[i]] += 1
ans = "Yes"
for i in d:
if d[i] != 2:
ans = "No"
print(ans)
| false | 75 | [
"-a = sorted(s)",
"-print((\"Yes\" if a[0] == a[1] and a[2] == a[3] and a[0] != a[2] else \"No\"))",
"+d = {}",
"+for i in range(4):",
"+ if s[i] not in d:",
"+ d[s[i]] = 1",
"+ else:",
"+ d[s[i]] += 1",
"+ans = \"Yes\"",
"+for i in d:",
"+ if d[i] != 2:",
"+ ans ... | false | 0.050707 | 0.070099 | 0.723367 | [
"s376168503",
"s697205061"
] |
u603958124 | p03818 | python | s853533052 | s606302037 | 86 | 65 | 22,748 | 22,748 | Accepted | Accepted | 24.42 | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(eval(input()))
def MAP() : return list(map(int,input().split()))
def LIST() : return list(MAP())
n = INT()
a = Counter(LIST())
tmp = 0
f = False
for x in a:
while a[x] > 1:
if a[x] == 2:
a[x] -= 1
if f:
f = False
else:
tmp += 1
f = True
else:
a[x] -= 2
tmp += 1
ans = n - tmp*2
print(ans) | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(eval(input()))
def MAP() : return list(map(int,input().split()))
def LIST() : return list(MAP())
n = INT()
a = Counter(LIST())
ans = len(a) if len(a) % 2 == 1 else len(a) - 1
print(ans) | 36 | 21 | 989 | 800 | from math import (
ceil,
floor,
factorial,
gcd,
sqrt,
log2,
cos,
sin,
tan,
acos,
asin,
atan,
degrees,
radians,
pi,
inf,
)
from itertools import (
accumulate,
groupby,
permutations,
combinations,
product,
combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(MAP())
n = INT()
a = Counter(LIST())
tmp = 0
f = False
for x in a:
while a[x] > 1:
if a[x] == 2:
a[x] -= 1
if f:
f = False
else:
tmp += 1
f = True
else:
a[x] -= 2
tmp += 1
ans = n - tmp * 2
print(ans)
| from math import (
ceil,
floor,
factorial,
gcd,
sqrt,
log2,
cos,
sin,
tan,
acos,
asin,
atan,
degrees,
radians,
pi,
inf,
)
from itertools import (
accumulate,
groupby,
permutations,
combinations,
product,
combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(MAP())
n = INT()
a = Counter(LIST())
ans = len(a) if len(a) % 2 == 1 else len(a) - 1
print(ans)
| false | 41.666667 | [
"-tmp = 0",
"-f = False",
"-for x in a:",
"- while a[x] > 1:",
"- if a[x] == 2:",
"- a[x] -= 1",
"- if f:",
"- f = False",
"- else:",
"- tmp += 1",
"- f = True",
"- else:",
"- a[x] -= 2"... | false | 0.033758 | 0.068206 | 0.494937 | [
"s853533052",
"s606302037"
] |
u558242240 | p02720 | python | s698225591 | s376526256 | 220 | 148 | 42,972 | 24,052 | Accepted | Accepted | 32.73 | k = int(eval(input()))
n = 0
def ff(s, i):
for j in range(i+1, len(s)):
#print(s[j-1])
if s[j-1] > 0:
s[j] = s[j-1] - 1
else:
s[j] = 0
return s
def next(s):
ls = len(s)
for i in range(ls-1, 0, -1):
if s[i-1] >= s[i] and s[i] != 9:
s[i] += 1
#print(s[i-1],s[i])
return ff(s, i)
if s[0] == 9:
return [1] + ([0] * ls)
else:
s[0] += 1
return ff(s, 0)
if k < 10:
print(k)
exit()
ans = [1,0]
for i in range(k - 10):
ans = next(ans)
#print(ans)
print((''.join(map(str, ans))))
| k = int(eval(input()))
r = [[i] for i in range(1,10)]
from collections import deque
que = deque(r)
if k < 10:
print(k)
exit()
while len(r) <= k:
ri = que.popleft()
for j in range(max(0, ri[-1]-1), min(9, ri[-1]+1)+1):
rj = ri.copy()
rj.append(j)
r.append(rj)
que.append(rj)
#print(que)
#print(r[k-1])
print((''.join(map(str, r[k-1]))))
| 38 | 20 | 659 | 406 | k = int(eval(input()))
n = 0
def ff(s, i):
for j in range(i + 1, len(s)):
# print(s[j-1])
if s[j - 1] > 0:
s[j] = s[j - 1] - 1
else:
s[j] = 0
return s
def next(s):
ls = len(s)
for i in range(ls - 1, 0, -1):
if s[i - 1] >= s[i] and s[i] != 9:
s[i] += 1
# print(s[i-1],s[i])
return ff(s, i)
if s[0] == 9:
return [1] + ([0] * ls)
else:
s[0] += 1
return ff(s, 0)
if k < 10:
print(k)
exit()
ans = [1, 0]
for i in range(k - 10):
ans = next(ans)
# print(ans)
print(("".join(map(str, ans))))
| k = int(eval(input()))
r = [[i] for i in range(1, 10)]
from collections import deque
que = deque(r)
if k < 10:
print(k)
exit()
while len(r) <= k:
ri = que.popleft()
for j in range(max(0, ri[-1] - 1), min(9, ri[-1] + 1) + 1):
rj = ri.copy()
rj.append(j)
r.append(rj)
que.append(rj)
# print(que)
# print(r[k-1])
print(("".join(map(str, r[k - 1]))))
| false | 47.368421 | [
"-n = 0",
"+r = [[i] for i in range(1, 10)]",
"+from collections import deque",
"-",
"-def ff(s, i):",
"- for j in range(i + 1, len(s)):",
"- # print(s[j-1])",
"- if s[j - 1] > 0:",
"- s[j] = s[j - 1] - 1",
"- else:",
"- s[j] = 0",
"- return s",... | false | 0.085237 | 0.124673 | 0.683683 | [
"s698225591",
"s376526256"
] |
u102278909 | p02712 | python | s603239561 | s456076691 | 86 | 76 | 67,900 | 68,100 | Accepted | Accepted | 11.63 | # coding: utf-8
import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
N = I()
ans = 0
for i in range(1, N+1):
if i % 3 == 0 or i % 5 == 0:
continue
else:
ans += i
print(ans)
| # coding: utf-8
import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")
N = I()
ans = 0
for i in range(1, N+1):
if i % 3 == 0 or i % 5 == 0:
continue
else:
ans += i
print(ans)
| 30 | 31 | 750 | 834 | # coding: utf-8
import sys
import math
import collections
import itertools
INF = 10**13
MOD = 10**9 + 7
def input():
return sys.stdin.readline().strip()
def lcm(x, y):
return (x * y) // math.gcd(x, y)
def I():
return int(input())
def LI():
return [int(x) for x in input().split()]
def RI(N):
return [int(input()) for _ in range(N)]
def LRI(N):
return [[int(x) for x in input().split()] for _ in range(N)]
def LS():
return input().split()
def RS(N):
return [input() for _ in range(N)]
def LRS(N):
return [input().split() for _ in range(N)]
def PL(L):
print(*L, sep="\n")
N = I()
ans = 0
for i in range(1, N + 1):
if i % 3 == 0 or i % 5 == 0:
continue
else:
ans += i
print(ans)
| # coding: utf-8
import sys
import math
import collections
import itertools
INF = 10**13
MOD = 10**9 + 7
def input():
return sys.stdin.readline().strip()
def lcm(x, y):
return (x * y) // math.gcd(x, y)
def I():
return int(input())
def LI():
return [int(x) for x in input().split()]
def RI(N):
return [int(input()) for _ in range(N)]
def LRI(N):
return [[int(x) for x in input().split()] for _ in range(N)]
def LS():
return input().split()
def RS(N):
return [input() for _ in range(N)]
def LRS(N):
return [input().split() for _ in range(N)]
def PL(L):
print(*L, sep="\n")
def YesNo(B):
print("Yes" if B else "No")
def YESNO(B):
print("YES" if B else "NO")
N = I()
ans = 0
for i in range(1, N + 1):
if i % 3 == 0 or i % 5 == 0:
continue
else:
ans += i
print(ans)
| false | 3.225806 | [
"+def YesNo(B):",
"+ print(\"Yes\" if B else \"No\")",
"+",
"+",
"+def YESNO(B):",
"+ print(\"YES\" if B else \"NO\")",
"+",
"+"
] | false | 0.171851 | 0.456484 | 0.376466 | [
"s603239561",
"s456076691"
] |
u340781749 | p03078 | python | s411007484 | s402014612 | 933 | 36 | 137,868 | 5,312 | Accepted | Accepted | 96.14 | x, y, z, k = list(map(int, input().split()))
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ccc = list(map(int, input().split()))
aabb = [a + b for a in aaa for b in bbb]
aabb.sort(reverse=True)
aabb = aabb[:k]
aabbcc = [ab + c for ab in aabb for c in ccc]
aabbcc.sort(reverse=True)
aabbcc = aabbcc[:k]
print(('\n'.join(map(str, aabbcc))))
| from heapq import heappop, heappush
x, y, z, k = list(map(int, input().split()))
aaa = sorted(map(int, input().split()), reverse=True)
bbb = sorted(map(int, input().split()), reverse=True)
ccc = sorted(map(int, input().split()), reverse=True)
q = [(-(aaa[0] + bbb[0] + ccc[0]), 0, 0, 0)]
ans = []
added = {(0, 0, 0)}
for _ in [0] * k:
s, ai, bi, ci = heappop(q)
ans.append(-s)
for da, db, dc in ((1, 0, 0), (0, 1, 0), (0, 0, 1)):
aj, bj, cj = ai + da, bi + db, ci + dc
if aj >= x or bj >= y or cj >= z:
continue
if (aj, bj, cj) in added:
continue
added.add((aj, bj, cj))
heappush(q, (-(aaa[aj] + bbb[bj] + ccc[cj]), aj, bj, cj))
print(('\n'.join(map(str, ans))))
| 14 | 23 | 377 | 756 | x, y, z, k = list(map(int, input().split()))
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ccc = list(map(int, input().split()))
aabb = [a + b for a in aaa for b in bbb]
aabb.sort(reverse=True)
aabb = aabb[:k]
aabbcc = [ab + c for ab in aabb for c in ccc]
aabbcc.sort(reverse=True)
aabbcc = aabbcc[:k]
print(("\n".join(map(str, aabbcc))))
| from heapq import heappop, heappush
x, y, z, k = list(map(int, input().split()))
aaa = sorted(map(int, input().split()), reverse=True)
bbb = sorted(map(int, input().split()), reverse=True)
ccc = sorted(map(int, input().split()), reverse=True)
q = [(-(aaa[0] + bbb[0] + ccc[0]), 0, 0, 0)]
ans = []
added = {(0, 0, 0)}
for _ in [0] * k:
s, ai, bi, ci = heappop(q)
ans.append(-s)
for da, db, dc in ((1, 0, 0), (0, 1, 0), (0, 0, 1)):
aj, bj, cj = ai + da, bi + db, ci + dc
if aj >= x or bj >= y or cj >= z:
continue
if (aj, bj, cj) in added:
continue
added.add((aj, bj, cj))
heappush(q, (-(aaa[aj] + bbb[bj] + ccc[cj]), aj, bj, cj))
print(("\n".join(map(str, ans))))
| false | 39.130435 | [
"+from heapq import heappop, heappush",
"+",
"-aaa = list(map(int, input().split()))",
"-bbb = list(map(int, input().split()))",
"-ccc = list(map(int, input().split()))",
"-aabb = [a + b for a in aaa for b in bbb]",
"-aabb.sort(reverse=True)",
"-aabb = aabb[:k]",
"-aabbcc = [ab + c for ab in aabb fo... | false | 0.059881 | 0.034093 | 1.756374 | [
"s411007484",
"s402014612"
] |
u186838327 | p02768 | python | s150764182 | s130137107 | 497 | 67 | 38,512 | 63,212 | Accepted | Accepted | 86.52 | n, a, b = list(map(int, input().split()))
mod = 10**9+7
def cmb2(n, r, mod):
res = 1
for k in range(1, r+1):
res *= (n-k+1)*pow(k,(mod-2),mod)%mod
res %= mod
return res
def power(a, n, mod):
bi=str(format(n,"b")) #2進数
res=1
for i in range(len(bi)):
res=(res*res) %mod
if bi[i]=="1":
res=(res*a) %mod
return res
ans = power(2, n, mod) - cmb2(n, a, mod) - cmb2(n, b, mod) -1
ans %= mod
print(ans) | n, a, b = list(map(int, input().split()))
mod = 10**9+7
def cmb2(n, r, mod):
res = 1
temp = 1
for k in range(1, r+1):
res *= (n-k+1)
temp *= k
res %= mod
temp %= mod
res *= pow(temp,(mod-2),mod)
res %= mod
return res
def power(a, n, mod):
bi=str(format(n,"b")) #2進数
res=1
for i in range(len(bi)):
res=(res*res) %mod
if bi[i]=="1":
res=(res*a) %mod
return res
ans = power(2, n, mod) - cmb2(n, a, mod) - cmb2(n, b, mod) -1
ans %= mod
print(ans)
| 22 | 27 | 462 | 566 | n, a, b = list(map(int, input().split()))
mod = 10**9 + 7
def cmb2(n, r, mod):
res = 1
for k in range(1, r + 1):
res *= (n - k + 1) * pow(k, (mod - 2), mod) % mod
res %= mod
return res
def power(a, n, mod):
bi = str(format(n, "b")) # 2進数
res = 1
for i in range(len(bi)):
res = (res * res) % mod
if bi[i] == "1":
res = (res * a) % mod
return res
ans = power(2, n, mod) - cmb2(n, a, mod) - cmb2(n, b, mod) - 1
ans %= mod
print(ans)
| n, a, b = list(map(int, input().split()))
mod = 10**9 + 7
def cmb2(n, r, mod):
res = 1
temp = 1
for k in range(1, r + 1):
res *= n - k + 1
temp *= k
res %= mod
temp %= mod
res *= pow(temp, (mod - 2), mod)
res %= mod
return res
def power(a, n, mod):
bi = str(format(n, "b")) # 2進数
res = 1
for i in range(len(bi)):
res = (res * res) % mod
if bi[i] == "1":
res = (res * a) % mod
return res
ans = power(2, n, mod) - cmb2(n, a, mod) - cmb2(n, b, mod) - 1
ans %= mod
print(ans)
| false | 18.518519 | [
"+ temp = 1",
"- res *= (n - k + 1) * pow(k, (mod - 2), mod) % mod",
"+ res *= n - k + 1",
"+ temp *= k",
"+ temp %= mod",
"+ res *= pow(temp, (mod - 2), mod)",
"+ res %= mod"
] | false | 0.005738 | 0.09076 | 0.063225 | [
"s150764182",
"s130137107"
] |
u716529032 | p02788 | python | s336472357 | s823226027 | 1,401 | 1,272 | 88,884 | 41,068 | Accepted | Accepted | 9.21 | from bisect import bisect_right
N, D, A = list(map(int, input().split()))
M = []
for i in range(N):
x, h = list(map(int, input().split()))
M.append((x, -(-h//A)))
M.sort(key=lambda x: x[0])
X = list([x[0] for x in M])
H = list([x[1] for x in M])
dmg = [0] * (N+1)
ans = 0
for i in range(N):
x, h = M[i]
h = max(0, h - dmg[i])
dmg[i] += h
dmg[bisect_right(X, x + 2*D)] -= h
dmg[i+1] += dmg[i]
ans += h
print(ans) | from bisect import bisect_right
N, D, A = list(map(int, input().split()))
M = []
for i in range(N):
x, h = list(map(int, input().split()))
M.append((x, -(-h//A)))
M.sort(key=lambda x: x[0])
X = list([x[0] for x in M])
H = list([x[1] for x in M])
dmg = [0] * (N+1)
ans = 0
for i in range(N):
x, h = M[i]
h = max(0, h - dmg[i])
dmg[bisect_right(X, x + 2*D)] -= h
dmg[i+1] += dmg[i] + h
ans += h
print(ans) | 22 | 21 | 449 | 438 | from bisect import bisect_right
N, D, A = list(map(int, input().split()))
M = []
for i in range(N):
x, h = list(map(int, input().split()))
M.append((x, -(-h // A)))
M.sort(key=lambda x: x[0])
X = list([x[0] for x in M])
H = list([x[1] for x in M])
dmg = [0] * (N + 1)
ans = 0
for i in range(N):
x, h = M[i]
h = max(0, h - dmg[i])
dmg[i] += h
dmg[bisect_right(X, x + 2 * D)] -= h
dmg[i + 1] += dmg[i]
ans += h
print(ans)
| from bisect import bisect_right
N, D, A = list(map(int, input().split()))
M = []
for i in range(N):
x, h = list(map(int, input().split()))
M.append((x, -(-h // A)))
M.sort(key=lambda x: x[0])
X = list([x[0] for x in M])
H = list([x[1] for x in M])
dmg = [0] * (N + 1)
ans = 0
for i in range(N):
x, h = M[i]
h = max(0, h - dmg[i])
dmg[bisect_right(X, x + 2 * D)] -= h
dmg[i + 1] += dmg[i] + h
ans += h
print(ans)
| false | 4.545455 | [
"- dmg[i] += h",
"- dmg[i + 1] += dmg[i]",
"+ dmg[i + 1] += dmg[i] + h"
] | false | 0.035601 | 0.037032 | 0.961377 | [
"s336472357",
"s823226027"
] |
u563199095 | p03835 | python | s223487467 | s217376907 | 1,187 | 952 | 9,008 | 9,132 | Accepted | Accepted | 19.8 | K,S=[ int(r) for r in input().split(' ') if r != '' ]
max_loop=min(K,S)+1
cnt=0
for x in range(max_loop):
for y in range(max_loop):
z= S-x-y
if 0 > z:
break
if z <= K:
cnt+=1
print(cnt)
| K,S=[ int(r) for r in input().split(' ') if r != '' ]
max_range=min(K,S)
cnt=0
for x in range(max_range+1):
for y in range(min(max_range,max(0,S-x-max_range)),min(max_range,S-x)+1):
z= S-x-y
if 0 > z:
break
if z <= max_range:
cnt+=1
print(cnt)
| 11 | 11 | 248 | 306 | K, S = [int(r) for r in input().split(" ") if r != ""]
max_loop = min(K, S) + 1
cnt = 0
for x in range(max_loop):
for y in range(max_loop):
z = S - x - y
if 0 > z:
break
if z <= K:
cnt += 1
print(cnt)
| K, S = [int(r) for r in input().split(" ") if r != ""]
max_range = min(K, S)
cnt = 0
for x in range(max_range + 1):
for y in range(
min(max_range, max(0, S - x - max_range)), min(max_range, S - x) + 1
):
z = S - x - y
if 0 > z:
break
if z <= max_range:
cnt += 1
print(cnt)
| false | 0 | [
"-max_loop = min(K, S) + 1",
"+max_range = min(K, S)",
"-for x in range(max_loop):",
"- for y in range(max_loop):",
"+for x in range(max_range + 1):",
"+ for y in range(",
"+ min(max_range, max(0, S - x - max_range)), min(max_range, S - x) + 1",
"+ ):",
"- if z <= K:",
"+ ... | false | 0.041941 | 0.130418 | 0.321587 | [
"s223487467",
"s217376907"
] |
u729133443 | p03246 | python | s150062876 | s381917595 | 446 | 210 | 75,372 | 35,220 | Accepted | Accepted | 52.91 | n=int(eval(input()))
v=list(map(int,input().split()))
a=[[0,i]for i in range(10**5+1)]
b=[[0,i]for i in range(10**5+1)]
for t in sorted(v[0::2]):a[t][0]+=1
for t in sorted(v[1::2]):b[t][0]+=1
c=sorted(a)[::-1]
d=sorted(b)[::-1]
print((n-c[0][0]-[max(c[1][0],d[1][0]),d[0][0]][c[0][1]!=d[0][1]])) | n=int(eval(input()))
*v,=list(map(int,input().split()))
a=[[0,i]for i in range(10**5+1)]
b=[[0,i]for i in range(10**5+1)]
for t,u in zip(sorted(v[::2]),sorted(v[1::2])):a[t][0]+=1;b[u][0]+=1
a.sort(reverse=1)
b.sort(reverse=1)
print((n-a[0][0]-[max(a[1][0],b[1][0]),b[0][0]][a[0][1]!=b[0][1]])) | 9 | 8 | 295 | 287 | n = int(eval(input()))
v = list(map(int, input().split()))
a = [[0, i] for i in range(10**5 + 1)]
b = [[0, i] for i in range(10**5 + 1)]
for t in sorted(v[0::2]):
a[t][0] += 1
for t in sorted(v[1::2]):
b[t][0] += 1
c = sorted(a)[::-1]
d = sorted(b)[::-1]
print((n - c[0][0] - [max(c[1][0], d[1][0]), d[0][0]][c[0][1] != d[0][1]]))
| n = int(eval(input()))
(*v,) = list(map(int, input().split()))
a = [[0, i] for i in range(10**5 + 1)]
b = [[0, i] for i in range(10**5 + 1)]
for t, u in zip(sorted(v[::2]), sorted(v[1::2])):
a[t][0] += 1
b[u][0] += 1
a.sort(reverse=1)
b.sort(reverse=1)
print((n - a[0][0] - [max(a[1][0], b[1][0]), b[0][0]][a[0][1] != b[0][1]]))
| false | 11.111111 | [
"-v = list(map(int, input().split()))",
"+(*v,) = list(map(int, input().split()))",
"-for t in sorted(v[0::2]):",
"+for t, u in zip(sorted(v[::2]), sorted(v[1::2])):",
"-for t in sorted(v[1::2]):",
"- b[t][0] += 1",
"-c = sorted(a)[::-1]",
"-d = sorted(b)[::-1]",
"-print((n - c[0][0] - [max(c[1][... | false | 0.207844 | 0.189566 | 1.096419 | [
"s150062876",
"s381917595"
] |
u294520705 | p02995 | python | s048650294 | s051485701 | 42 | 35 | 5,344 | 5,088 | Accepted | Accepted | 16.67 | import fractions
# 最小公倍数
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
a, b, c, d = list(map(int, input().split()))
e = lcm(c, d)
#print("e: {}".format(e))
#print("c: {} - {}".format(b // c, (a - 1) // c))
#print("d: {} - {}".format(b // d, (a - 1) // d))
#print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
#print("count_c: {}".format(count_c))
#print("count_d: {}".format(count_d))
#print("count_e: {}".format(count_e))
print((b - a + 1 - (count_c + count_d - count_e))) | import fractions
import sys
input = sys.stdin.readline# 最小公倍数
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
a, b, c, d = list(map(int, input().split()))
e = lcm(c, d)
#print("e: {}".format(e))
#print("c: {} - {}".format(b // c, (a - 1) // c))
#print("d: {} - {}".format(b // d, (a - 1) // d))
#print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
#print("count_c: {}".format(count_c))
#print("count_d: {}".format(count_d))
#print("count_e: {}".format(count_e))
print((b - a + 1 - (count_c + count_d - count_e))) | 18 | 20 | 615 | 655 | import fractions
# 最小公倍数
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
a, b, c, d = list(map(int, input().split()))
e = lcm(c, d)
# print("e: {}".format(e))
# print("c: {} - {}".format(b // c, (a - 1) // c))
# print("d: {} - {}".format(b // d, (a - 1) // d))
# print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
# print("count_c: {}".format(count_c))
# print("count_d: {}".format(count_d))
# print("count_e: {}".format(count_e))
print((b - a + 1 - (count_c + count_d - count_e)))
| import fractions
import sys
input = sys.stdin.readline # 最小公倍数
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
a, b, c, d = list(map(int, input().split()))
e = lcm(c, d)
# print("e: {}".format(e))
# print("c: {} - {}".format(b // c, (a - 1) // c))
# print("d: {} - {}".format(b // d, (a - 1) // d))
# print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
# print("count_c: {}".format(count_c))
# print("count_d: {}".format(count_d))
# print("count_e: {}".format(count_e))
print((b - a + 1 - (count_c + count_d - count_e)))
| false | 10 | [
"+import sys",
"-# 最小公倍数",
"+input = sys.stdin.readline # 最小公倍数",
"+",
"+"
] | false | 0.051162 | 0.098318 | 0.520377 | [
"s048650294",
"s051485701"
] |
u811733736 | p02412 | python | s584734885 | s546117384 | 820 | 560 | 7,736 | 7,708 | Accepted | Accepted | 31.71 | from itertools import combinations
if __name__ == '__main__':
while True:
# ?????????????????\???
data = [int(x) for x in input().split(' ')]
upper_limit = data[0]
target_number = data[1]
if upper_limit == 0 and target_number == 0:
break
# ????????????????????????
choices = combinations(list(range(1, upper_limit+1)), 3)
# ????¨???????X????????´????????°????¢????????????????
hit_count = 0
for c in choices:
# print(c)
if sum(c) == target_number:
hit_count += 1
print(hit_count) | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=jp
"""
import sys
from sys import stdin
from itertools import combinations
input = stdin.readline
def main(args):
while True:
n, x = list(map(int, input().split()))
if n == 0 and x == 0:
break
ans = 0
for c in combinations(list(range(1, n+1)), 3):
if sum(c) == x:
ans += 1
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| 21 | 28 | 640 | 543 | from itertools import combinations
if __name__ == "__main__":
while True:
# ?????????????????\???
data = [int(x) for x in input().split(" ")]
upper_limit = data[0]
target_number = data[1]
if upper_limit == 0 and target_number == 0:
break
# ????????????????????????
choices = combinations(list(range(1, upper_limit + 1)), 3)
# ????¨???????X????????´????????°????¢????????????????
hit_count = 0
for c in choices:
# print(c)
if sum(c) == target_number:
hit_count += 1
print(hit_count)
| # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=jp
"""
import sys
from sys import stdin
from itertools import combinations
input = stdin.readline
def main(args):
while True:
n, x = list(map(int, input().split()))
if n == 0 and x == 0:
break
ans = 0
for c in combinations(list(range(1, n + 1)), 3):
if sum(c) == x:
ans += 1
print(ans)
if __name__ == "__main__":
main(sys.argv[1:])
| false | 25 | [
"+# -*- coding: utf-8 -*-",
"+\"\"\"",
"+http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=jp",
"+\"\"\"",
"+import sys",
"+from sys import stdin",
"+input = stdin.readline",
"+",
"+",
"+def main(args):",
"+ while True:",
"+ n, x = list(map(int, input().split()))... | false | 0.034776 | 0.034421 | 1.010303 | [
"s584734885",
"s546117384"
] |
u454524105 | p02820 | python | s853824294 | s061490554 | 82 | 67 | 4,212 | 4,212 | Accepted | Accepted | 18.29 | n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = [i for i in eval(input())]
ans = 0
rsp = {"r": 0, "s": 0, "p": 0}
for i in range(n):
if t[i] == "r":
ans += p
elif t[i] == "s":
ans += r
else:
ans += s
if i >= k and t[i] == t[i-k]:
rsp[t[i]] += 1
t[i] = "o"
mi = int(rsp["r"] * p + rsp["s"] * r + rsp["p"] * s)
print((ans-mi)) | n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = [i for i in eval(input())]
ans = 0
for i in range(n):
if i >= k and t[i] == t[i-k]:
t[i] = "o"
continue
if t[i] == "r":
ans += p
elif t[i] == "s":
ans += r
else:
ans += s
print(ans) | 17 | 15 | 413 | 318 | n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = [i for i in eval(input())]
ans = 0
rsp = {"r": 0, "s": 0, "p": 0}
for i in range(n):
if t[i] == "r":
ans += p
elif t[i] == "s":
ans += r
else:
ans += s
if i >= k and t[i] == t[i - k]:
rsp[t[i]] += 1
t[i] = "o"
mi = int(rsp["r"] * p + rsp["s"] * r + rsp["p"] * s)
print((ans - mi))
| n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = [i for i in eval(input())]
ans = 0
for i in range(n):
if i >= k and t[i] == t[i - k]:
t[i] = "o"
continue
if t[i] == "r":
ans += p
elif t[i] == "s":
ans += r
else:
ans += s
print(ans)
| false | 11.764706 | [
"-rsp = {\"r\": 0, \"s\": 0, \"p\": 0}",
"+ if i >= k and t[i] == t[i - k]:",
"+ t[i] = \"o\"",
"+ continue",
"- if i >= k and t[i] == t[i - k]:",
"- rsp[t[i]] += 1",
"- t[i] = \"o\"",
"-mi = int(rsp[\"r\"] * p + rsp[\"s\"] * r + rsp[\"p\"] * s)",
"-print((ans - mi)... | false | 0.036981 | 0.037067 | 0.997684 | [
"s853824294",
"s061490554"
] |
u970197315 | p02973 | python | s638772046 | s048175427 | 251 | 196 | 7,964 | 86,928 | Accepted | Accepted | 21.91 | n=int(eval(input()))
a=[-int(eval(input())) for i in range(n)]
from bisect import bisect_right
l=[]
for aa in a:
idx=bisect_right(l,aa)
if idx==len(l):
l.append(aa)
else:
l[idx]=aa
print((len(l))) | from bisect import bisect_right
def LIS(l):
length = [l[0]]
for i in range(1, len(l)):
if l[i] >= length[-1]:
length.append(l[i])
else:
pos = bisect_right(length, l[i])
length[pos] = l[i]
return len(length)
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
a = a[::-1]
print((LIS(a)))
| 11 | 15 | 206 | 366 | n = int(eval(input()))
a = [-int(eval(input())) for i in range(n)]
from bisect import bisect_right
l = []
for aa in a:
idx = bisect_right(l, aa)
if idx == len(l):
l.append(aa)
else:
l[idx] = aa
print((len(l)))
| from bisect import bisect_right
def LIS(l):
length = [l[0]]
for i in range(1, len(l)):
if l[i] >= length[-1]:
length.append(l[i])
else:
pos = bisect_right(length, l[i])
length[pos] = l[i]
return len(length)
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
a = a[::-1]
print((LIS(a)))
| false | 26.666667 | [
"-n = int(eval(input()))",
"-a = [-int(eval(input())) for i in range(n)]",
"-l = []",
"-for aa in a:",
"- idx = bisect_right(l, aa)",
"- if idx == len(l):",
"- l.append(aa)",
"- else:",
"- l[idx] = aa",
"-print((len(l)))",
"+",
"+def LIS(l):",
"+ length = [l[0]]",
... | false | 0.040037 | 0.073932 | 0.541542 | [
"s638772046",
"s048175427"
] |
u918601425 | p02912 | python | s939601172 | s128549077 | 345 | 244 | 14,280 | 14,436 | Accepted | Accepted | 29.28 | import math
N,M=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
ls.sort(reverse=True)
x=ls[0]
L=int(math.log2(x))
#2**L より大きいものをわける
def cut(lst,exp):
for ii in range(len(lst)):
if ii+1==len(lst):
break
if lst[ii+1]<exp:
break
return ii
m=M #残り回数
b=-1
ls3=[]
while True:
if m==0:
break
a=b+1
b=cut(ls,2**L)
ls2=ls[a:b+1]
ls3=ls3+ls2
ls3.sort(reverse=True)
for j in range(len(ls3)):
ls3[j]=ls3[j]//2
m-=1
if m==0:
break
L-=1
# print(ls3,m,b)
#print(ls3,ls[b+1:])
s=sum(ls3)+sum(ls[b+1:])
print(s)
| import math
N,M=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
ls.sort(reverse=True)
x=ls[0]
L=int(math.log2(x))
#2**L より大きいものをわける
def cut(lst,exp):
for ii in range(len(lst)):
if ii+1==len(lst):
break
if lst[ii+1]<exp:
break
return ii
m=M #残り回数
b=-1
ls3=[]
while True:
if m==0:
break
a=b+1
b=cut(ls,2**L)
ls2=ls[a:b+1]
ls3=ls3+ls2
if ls2!=[]:
ls3.sort(reverse=True)
for j in range(len(ls3)):
ls3[j]=ls3[j]//2
m-=1
if m==0:
break
L-=1
# print(ls3,m,b)
#print(ls3,ls[b+1:])
s=sum(ls3)+sum(ls[b+1:])
print(s)
| 36 | 37 | 683 | 704 | import math
N, M = [int(s) for s in input().split()]
ls = [int(s) for s in input().split()]
ls.sort(reverse=True)
x = ls[0]
L = int(math.log2(x))
# 2**L より大きいものをわける
def cut(lst, exp):
for ii in range(len(lst)):
if ii + 1 == len(lst):
break
if lst[ii + 1] < exp:
break
return ii
m = M # 残り回数
b = -1
ls3 = []
while True:
if m == 0:
break
a = b + 1
b = cut(ls, 2**L)
ls2 = ls[a : b + 1]
ls3 = ls3 + ls2
ls3.sort(reverse=True)
for j in range(len(ls3)):
ls3[j] = ls3[j] // 2
m -= 1
if m == 0:
break
L -= 1
# print(ls3,m,b)
# print(ls3,ls[b+1:])
s = sum(ls3) + sum(ls[b + 1 :])
print(s)
| import math
N, M = [int(s) for s in input().split()]
ls = [int(s) for s in input().split()]
ls.sort(reverse=True)
x = ls[0]
L = int(math.log2(x))
# 2**L より大きいものをわける
def cut(lst, exp):
for ii in range(len(lst)):
if ii + 1 == len(lst):
break
if lst[ii + 1] < exp:
break
return ii
m = M # 残り回数
b = -1
ls3 = []
while True:
if m == 0:
break
a = b + 1
b = cut(ls, 2**L)
ls2 = ls[a : b + 1]
ls3 = ls3 + ls2
if ls2 != []:
ls3.sort(reverse=True)
for j in range(len(ls3)):
ls3[j] = ls3[j] // 2
m -= 1
if m == 0:
break
L -= 1
# print(ls3,m,b)
# print(ls3,ls[b+1:])
s = sum(ls3) + sum(ls[b + 1 :])
print(s)
| false | 2.702703 | [
"- ls3.sort(reverse=True)",
"+ if ls2 != []:",
"+ ls3.sort(reverse=True)"
] | false | 0.069842 | 0.066722 | 1.046771 | [
"s939601172",
"s128549077"
] |
u591503175 | p03361 | python | s018384503 | s805859336 | 22 | 19 | 3,064 | 3,064 | Accepted | Accepted | 13.64 | def resolve():
'''
code here
'''
H, W = [int(item) for item in input().split()]
grid = [[item for item in eval(input())] for _ in range(H)]
# print(grid)
def chk(i,j):
next_node_list = [
[max(0, i-1), j],
[min(H-1, i+1), j],
[i, max(0, j-1)],
[i, min(W-1, j+1)]
]
if grid[i][j] == '#':
for next_node in next_node_list:
if next_node == [i, j]:
pass
else:
if grid[next_node[0]][next_node[1]] == '#':
return True
else:
return False
else:
return True
def loop_chk(H, W):
for i in range(H):
for j in range(W):
# print(i,j, chk(i,j))
if chk(i,j):
pass
else:
return False
else:
return True
if loop_chk(H, W):
print('Yes')
else:
print('No')
if __name__ == "__main__":
resolve()
| def resolve():
'''
code here
'''
H, W = [int(item) for item in input().split()]
grid = [[item for item in eval(input())] for _ in range(H)]
def chk(i,j):
if grid[i][j] == '#':
if 0 <= i-1:
if grid[i-1][j] == '#':
return True
if i +1 < H:
if grid[i+1][j] == '#':
return True
if 0 <= j -1:
if grid[i][j-1] == '#':
return True
if j + 1 < W:
if grid[i][j+1] == '#':
return True
return False
else:
return False
for i in range(H):
end_flag = False
for j in range(W):
# print(chk(i,j), grid[i][j])
if grid[i][j] == '#':
if chk(i,j) == True:
pass
else:
print('No')
end_flag = True
break
if end_flag:
break
else:
print('Yes')
if __name__ == "__main__":
resolve()
| 51 | 45 | 1,144 | 1,169 | def resolve():
"""
code here
"""
H, W = [int(item) for item in input().split()]
grid = [[item for item in eval(input())] for _ in range(H)]
# print(grid)
def chk(i, j):
next_node_list = [
[max(0, i - 1), j],
[min(H - 1, i + 1), j],
[i, max(0, j - 1)],
[i, min(W - 1, j + 1)],
]
if grid[i][j] == "#":
for next_node in next_node_list:
if next_node == [i, j]:
pass
else:
if grid[next_node[0]][next_node[1]] == "#":
return True
else:
return False
else:
return True
def loop_chk(H, W):
for i in range(H):
for j in range(W):
# print(i,j, chk(i,j))
if chk(i, j):
pass
else:
return False
else:
return True
if loop_chk(H, W):
print("Yes")
else:
print("No")
if __name__ == "__main__":
resolve()
| def resolve():
"""
code here
"""
H, W = [int(item) for item in input().split()]
grid = [[item for item in eval(input())] for _ in range(H)]
def chk(i, j):
if grid[i][j] == "#":
if 0 <= i - 1:
if grid[i - 1][j] == "#":
return True
if i + 1 < H:
if grid[i + 1][j] == "#":
return True
if 0 <= j - 1:
if grid[i][j - 1] == "#":
return True
if j + 1 < W:
if grid[i][j + 1] == "#":
return True
return False
else:
return False
for i in range(H):
end_flag = False
for j in range(W):
# print(chk(i,j), grid[i][j])
if grid[i][j] == "#":
if chk(i, j) == True:
pass
else:
print("No")
end_flag = True
break
if end_flag:
break
else:
print("Yes")
if __name__ == "__main__":
resolve()
| false | 11.764706 | [
"- # print(grid)",
"+",
"- next_node_list = [",
"- [max(0, i - 1), j],",
"- [min(H - 1, i + 1), j],",
"- [i, max(0, j - 1)],",
"- [i, min(W - 1, j + 1)],",
"- ]",
"- for next_node in next_node_list:",
"- if next... | false | 0.108892 | 0.045684 | 2.383596 | [
"s018384503",
"s805859336"
] |
u729133443 | p03287 | python | s087935469 | s943121206 | 423 | 357 | 15,020 | 62,704 | Accepted | Accepted | 15.6 | import math
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=[a[0]]
c={}
c[b[0]%m]=1
for i in range(1,n):
b.append(b[i-1]+a[i])
c[b[i]%m]=c.get(b[i]%m,0)+1
print((sum([math.factorial(x)//(math.factorial(x-2)*math.factorial(2))if x>1else 0 for x in list(c.values())])+c.get(0,0))) | import math
n,m=list(map(int,input().split()))
b=0
c={}
for a in input().split():
b+=int(a)
c[b%m]=c.get(b%m,0)+1
print((sum([math.factorial(x)//(math.factorial(x-2)*math.factorial(2))if x>1else 0 for x in list(c.values())])+c.get(0,0))) | 10 | 8 | 302 | 237 | import math
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [a[0]]
c = {}
c[b[0] % m] = 1
for i in range(1, n):
b.append(b[i - 1] + a[i])
c[b[i] % m] = c.get(b[i] % m, 0) + 1
print(
(
sum(
[
math.factorial(x) // (math.factorial(x - 2) * math.factorial(2))
if x > 1
else 0
for x in list(c.values())
]
)
+ c.get(0, 0)
)
)
| import math
n, m = list(map(int, input().split()))
b = 0
c = {}
for a in input().split():
b += int(a)
c[b % m] = c.get(b % m, 0) + 1
print(
(
sum(
[
math.factorial(x) // (math.factorial(x - 2) * math.factorial(2))
if x > 1
else 0
for x in list(c.values())
]
)
+ c.get(0, 0)
)
)
| false | 20 | [
"-a = list(map(int, input().split()))",
"-b = [a[0]]",
"+b = 0",
"-c[b[0] % m] = 1",
"-for i in range(1, n):",
"- b.append(b[i - 1] + a[i])",
"- c[b[i] % m] = c.get(b[i] % m, 0) + 1",
"+for a in input().split():",
"+ b += int(a)",
"+ c[b % m] = c.get(b % m, 0) + 1"
] | false | 0.043995 | 0.04217 | 1.043277 | [
"s087935469",
"s943121206"
] |
u010072501 | p02909 | python | s423748691 | s050410827 | 31 | 24 | 8,884 | 8,796 | Accepted | Accepted | 22.58 | # A - Weather Prediction
# 1日毎に 晴れ(Sunny) 曇り(Cloudy) 雨(Rainy) の順に変化する
# 晴 → 曇 → 雨 → 晴 → 曇 → 雨 → ...
# 文字列 S の入力
S = eval(input())
# print(S)
# 明日の天気を表示させる
# 今日の天気で分岐し、printで表示
if S == 'Sunny':
print('Cloudy')
elif S == 'Cloudy':
print('Rainy')
elif S == 'Rainy':
print('Sunny')
| # A - Weather Prediction
# 1日毎に 晴れ(Sunny) 曇り(Cloudy) 雨(Rainy) の順に変化する
# 晴 → 曇 → 雨 → 晴 → 曇 → 雨 → ...
# 文字列 S の入力
S = eval(input())
# print(S)
# 明日の天気を表示させる
# 今日の天気で分岐し、printで表示
if S == 'Sunny':
# print('Cloudy')
answer = 'Cloudy'
elif S == 'Cloudy':
# print('Rainy')
answer = 'Rainy'
elif S == 'Rainy':
# print('Sunny')
answer = 'Sunny'
print(answer)
| 16 | 21 | 301 | 391 | # A - Weather Prediction
# 1日毎に 晴れ(Sunny) 曇り(Cloudy) 雨(Rainy) の順に変化する
# 晴 → 曇 → 雨 → 晴 → 曇 → 雨 → ...
# 文字列 S の入力
S = eval(input())
# print(S)
# 明日の天気を表示させる
# 今日の天気で分岐し、printで表示
if S == "Sunny":
print("Cloudy")
elif S == "Cloudy":
print("Rainy")
elif S == "Rainy":
print("Sunny")
| # A - Weather Prediction
# 1日毎に 晴れ(Sunny) 曇り(Cloudy) 雨(Rainy) の順に変化する
# 晴 → 曇 → 雨 → 晴 → 曇 → 雨 → ...
# 文字列 S の入力
S = eval(input())
# print(S)
# 明日の天気を表示させる
# 今日の天気で分岐し、printで表示
if S == "Sunny":
# print('Cloudy')
answer = "Cloudy"
elif S == "Cloudy":
# print('Rainy')
answer = "Rainy"
elif S == "Rainy":
# print('Sunny')
answer = "Sunny"
print(answer)
| false | 23.809524 | [
"- print(\"Cloudy\")",
"+ # print('Cloudy')",
"+ answer = \"Cloudy\"",
"- print(\"Rainy\")",
"+ # print('Rainy')",
"+ answer = \"Rainy\"",
"- print(\"Sunny\")",
"+ # print('Sunny')",
"+ answer = \"Sunny\"",
"+print(answer)"
] | false | 0.048526 | 0.04948 | 0.980724 | [
"s423748691",
"s050410827"
] |
u793868662 | p02755 | python | s715929253 | s852554485 | 186 | 18 | 38,640 | 2,940 | Accepted | Accepted | 90.32 | def resolve():
a, b = list(map(int, input().split()))
j=-1
for i in range(1263):
c = i*0.08//1
d = i*0.1//1
if c==a and d==b:
j=i
break
print(j)
resolve() | def resolve():
a, b = list(map(int, input().split()))
for i in range(1300):
if int(i*0.08) == a and int(i*0.1) == b:
print(i)
exit()
print((-1))
resolve() | 11 | 8 | 222 | 197 | def resolve():
a, b = list(map(int, input().split()))
j = -1
for i in range(1263):
c = i * 0.08 // 1
d = i * 0.1 // 1
if c == a and d == b:
j = i
break
print(j)
resolve()
| def resolve():
a, b = list(map(int, input().split()))
for i in range(1300):
if int(i * 0.08) == a and int(i * 0.1) == b:
print(i)
exit()
print((-1))
resolve()
| false | 27.272727 | [
"- j = -1",
"- for i in range(1263):",
"- c = i * 0.08 // 1",
"- d = i * 0.1 // 1",
"- if c == a and d == b:",
"- j = i",
"- break",
"- print(j)",
"+ for i in range(1300):",
"+ if int(i * 0.08) == a and int(i * 0.1) == b:",
"+ ... | false | 0.0805 | 0.035394 | 2.274363 | [
"s715929253",
"s852554485"
] |
u638795007 | p03959 | python | s843146990 | s643811385 | 406 | 142 | 82,520 | 20,272 | Accepted | Accepted | 65.02 | def examA():
S = SI()
ans = "No"
flag = False
for s in S:
if flag:
if s=="F":
ans = "Yes"
break
else:
if s=="C":
flag = True
print(ans)
return
def examB():
K, T = LI()
A = LI(); A.sort()
ans = max(0,A[-1]*2-sum(A)-1)
print(ans)
return
def examC(mod):
N = I()
T = LI(); A = LI()
H = [0]*N
ans = 1
if T[-1] != A[0]:
ans = 0
H[0] = T[0]; H[N-1] = A[N-1]
for i in range(N-1):
if T[i+1]>T[i]:
if H[i+1]==0:
H[i+1] = T[i+1]
elif H[i+1]!=T[i+1]:
ans = 0
else:
if H[i+1]==0:
H[i+1] = -T[i+1]
for i in range(N-1,0,-1):
if A[i-1]>A[i]:
if H[i-1]==0:
H[i-1] = A[i-1]
elif H[i-1]<0:
if -H[i-1]<A[i-1]:
ans = 0
else:
H[i-1] = A[i-1]
elif H[i-1]!=A[i-1]:
ans = 0
# print(H)
flag = False; cur = 0
for i in H:
if flag:
if i<0:
cur +=1
else:
ans *=(min(now,i)**cur)%mod
ans %=mod
flag = False
cur = 0; now = i
else:
if i<0:
cur = 1
flag = True
else:
now = i
print((ans%mod))
return
import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')
if __name__ == '__main__':
examC(mod)
| def examA():
N = I()
T = LI()
A = LI()
S = [-1]*N
S[0] = T[0]; S[-1]=A[-1]
ans = 1
for i in range(1,N):
if T[i]==T[i-1]:
continue
S[i] = T[i]
flag = -1
for i in range(N):
if S[i]==A[i]:
flag = i
break
if not (A[flag]==A[0] and A[flag]==T[-1]):
print((0))
return
for i in range(N-1)[::-1]:
if A[i]==A[i+1]:
continue
if S[i]==-1:
S[i] = A[i]
else:
S[i] = max(S[i],A[i])
#print(S)
P = []
pindex = []
for i in range(N):
if S[i]==-1:
continue
P.append(S[i])
pindex.append(i)
flag_U = True
for i in range(len(P)-1):
if P[i+1]>P[i]:
if not flag_U:
print((0))
return
elif P[i+1]<P[i]:
flag_U = False
ans = 1
p = -1
for i in range(N):
if S[i]==-1:
cur = min(P[p + 1], P[p])
ans *= cur
ans %= mod
else:
p += 1
print(ans)
return
def examB():
ans = 0
print(ans)
return
def examC():
ans = 0
print(ans)
return
def examD():
ans = 0
print(ans)
return
import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]
if __name__ == '__main__':
examA()
"""
""" | 83 | 91 | 2,051 | 1,953 | def examA():
S = SI()
ans = "No"
flag = False
for s in S:
if flag:
if s == "F":
ans = "Yes"
break
else:
if s == "C":
flag = True
print(ans)
return
def examB():
K, T = LI()
A = LI()
A.sort()
ans = max(0, A[-1] * 2 - sum(A) - 1)
print(ans)
return
def examC(mod):
N = I()
T = LI()
A = LI()
H = [0] * N
ans = 1
if T[-1] != A[0]:
ans = 0
H[0] = T[0]
H[N - 1] = A[N - 1]
for i in range(N - 1):
if T[i + 1] > T[i]:
if H[i + 1] == 0:
H[i + 1] = T[i + 1]
elif H[i + 1] != T[i + 1]:
ans = 0
else:
if H[i + 1] == 0:
H[i + 1] = -T[i + 1]
for i in range(N - 1, 0, -1):
if A[i - 1] > A[i]:
if H[i - 1] == 0:
H[i - 1] = A[i - 1]
elif H[i - 1] < 0:
if -H[i - 1] < A[i - 1]:
ans = 0
else:
H[i - 1] = A[i - 1]
elif H[i - 1] != A[i - 1]:
ans = 0
# print(H)
flag = False
cur = 0
for i in H:
if flag:
if i < 0:
cur += 1
else:
ans *= (min(now, i) ** cur) % mod
ans %= mod
flag = False
cur = 0
now = i
else:
if i < 0:
cur = 1
flag = True
else:
now = i
print((ans % mod))
return
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float("inf")
if __name__ == "__main__":
examC(mod)
| def examA():
N = I()
T = LI()
A = LI()
S = [-1] * N
S[0] = T[0]
S[-1] = A[-1]
ans = 1
for i in range(1, N):
if T[i] == T[i - 1]:
continue
S[i] = T[i]
flag = -1
for i in range(N):
if S[i] == A[i]:
flag = i
break
if not (A[flag] == A[0] and A[flag] == T[-1]):
print((0))
return
for i in range(N - 1)[::-1]:
if A[i] == A[i + 1]:
continue
if S[i] == -1:
S[i] = A[i]
else:
S[i] = max(S[i], A[i])
# print(S)
P = []
pindex = []
for i in range(N):
if S[i] == -1:
continue
P.append(S[i])
pindex.append(i)
flag_U = True
for i in range(len(P) - 1):
if P[i + 1] > P[i]:
if not flag_U:
print((0))
return
elif P[i + 1] < P[i]:
flag_U = False
ans = 1
p = -1
for i in range(N):
if S[i] == -1:
cur = min(P[p + 1], P[p])
ans *= cur
ans %= mod
else:
p += 1
print(ans)
return
def examB():
ans = 0
print(ans)
return
def examC():
ans = 0
print(ans)
return
def examD():
ans = 0
print(ans)
return
import sys, copy, bisect, itertools, heapq, math, random
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10 ** (-12)
alphabet = [chr(ord("a") + i) for i in range(26)]
if __name__ == "__main__":
examA()
"""
"""
| false | 8.791209 | [
"- S = SI()",
"- ans = \"No\"",
"- flag = False",
"- for s in S:",
"- if flag:",
"- if s == \"F\":",
"- ans = \"Yes\"",
"- break",
"+ N = I()",
"+ T = LI()",
"+ A = LI()",
"+ S = [-1] * N",
"+ S[0] = T[0]",
"+ S[... | false | 0.037023 | 0.03803 | 0.973528 | [
"s843146990",
"s643811385"
] |
u353919145 | p04044 | python | s581444748 | s378880125 | 302 | 18 | 45,296 | 3,060 | Accepted | Accepted | 94.04 | n,l=map(int, input().split())
s=[list(input()) for i in range(n)]
s.sort()
for i in s:
for j in i:
print(j,end="")
print()
| n, m = list(map(int, input().split()))
s = []
for i in range(n):
s.append(input())
s.sort()
for i in range(n):
print(s[i], end = '')
| 7 | 11 | 140 | 154 | n, l = map(int, input().split())
s = [list(input()) for i in range(n)]
s.sort()
for i in s:
for j in i:
print(j, end="")
print()
| n, m = list(map(int, input().split()))
s = []
for i in range(n):
s.append(input())
s.sort()
for i in range(n):
print(s[i], end="")
| false | 36.363636 | [
"-n, l = map(int, input().split())",
"-s = [list(input()) for i in range(n)]",
"+n, m = list(map(int, input().split()))",
"+s = []",
"+for i in range(n):",
"+ s.append(input())",
"-for i in s:",
"- for j in i:",
"- print(j, end=\"\")",
"-print()",
"+for i in range(n):",
"+ prin... | false | 0.06544 | 0.034855 | 1.877505 | [
"s581444748",
"s378880125"
] |
u343977188 | p03325 | python | s830842355 | s869345903 | 74 | 33 | 10,112 | 10,160 | Accepted | Accepted | 55.41 | N=int(eval(input()))
a=list(map(int,input().split()))
ans=0
for i in a:
while 1:
if i%2!=0:
break
i=i//2
ans+=1
print(ans) | import math
N=int(eval(input()))
a=list(map(int,input().split()))
ans=0
for i in a:
ans+=math.log2(i & -i)
print((int(ans))) | 10 | 7 | 145 | 124 | N = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in a:
while 1:
if i % 2 != 0:
break
i = i // 2
ans += 1
print(ans)
| import math
N = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in a:
ans += math.log2(i & -i)
print((int(ans)))
| false | 30 | [
"+import math",
"+",
"- while 1:",
"- if i % 2 != 0:",
"- break",
"- i = i // 2",
"- ans += 1",
"-print(ans)",
"+ ans += math.log2(i & -i)",
"+print((int(ans)))"
] | false | 0.044804 | 0.033396 | 1.341574 | [
"s830842355",
"s869345903"
] |
u600402037 | p02785 | python | s161991899 | s172057549 | 168 | 155 | 26,024 | 26,024 | Accepted | Accepted | 7.74 | import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
H = lr()
H.sort(reverse=True)
answer = sum(H[K:])
print(answer)
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
H = lr()
H.sort(reverse=True)
H = H[K:]
answer = sum(H)
print(answer)
| 11 | 13 | 207 | 231 | import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
H = lr()
H.sort(reverse=True)
answer = sum(H[K:])
print(answer)
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
H = lr()
H.sort(reverse=True)
H = H[K:]
answer = sum(H)
print(answer)
| false | 15.384615 | [
"+# coding: utf-8",
"-answer = sum(H[K:])",
"+H = H[K:]",
"+answer = sum(H)"
] | false | 0.042917 | 0.033084 | 1.297225 | [
"s161991899",
"s172057549"
] |
u307622233 | p02623 | python | s294994455 | s925526483 | 487 | 221 | 53,720 | 47,388 | Accepted | Accepted | 54.62 | import numpy as np
def main():
N, M, K = list(map(int, input().split()))
A = np.array([0] + [int(i) for i in input().split()])
B = np.array([0] + [int(i) for i in input().split()])
A.cumsum(out=A)
B.cumsum(out=B)
ans = 0
j = M
for i in range(N + 1):
if A[i] > K:
break
while B[j] + A[i] > K:
j -= 1
ans = max(ans, i + j)
print(ans)
if __name__ == '__main__':
main() | def main():
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
a.append(a[i] + A[i])
for i in range(M):
b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
if a[i] > K:
break
while b[j] > K - a[i]:
j -= 1
ans = max(ans, i + j)
print(ans)
if __name__ == '__main__':
main() | 25 | 24 | 478 | 502 | import numpy as np
def main():
N, M, K = list(map(int, input().split()))
A = np.array([0] + [int(i) for i in input().split()])
B = np.array([0] + [int(i) for i in input().split()])
A.cumsum(out=A)
B.cumsum(out=B)
ans = 0
j = M
for i in range(N + 1):
if A[i] > K:
break
while B[j] + A[i] > K:
j -= 1
ans = max(ans, i + j)
print(ans)
if __name__ == "__main__":
main()
| def main():
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
a.append(a[i] + A[i])
for i in range(M):
b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
if a[i] > K:
break
while b[j] > K - a[i]:
j -= 1
ans = max(ans, i + j)
print(ans)
if __name__ == "__main__":
main()
| false | 4 | [
"-import numpy as np",
"-",
"-",
"- A = np.array([0] + [int(i) for i in input().split()])",
"- B = np.array([0] + [int(i) for i in input().split()])",
"- A.cumsum(out=A)",
"- B.cumsum(out=B)",
"- ans = 0",
"- j = M",
"+ A = list(map(int, input().split()))",
"+ B = list(ma... | false | 0.264038 | 0.037367 | 7.066152 | [
"s294994455",
"s925526483"
] |
u077291787 | p03038 | python | s680049398 | s556553990 | 294 | 260 | 23,244 | 39,516 | Accepted | Accepted | 11.56 | # ABC127D - Integer Cards
import sys
input = sys.stdin.readline
def main():
n, m = list(map(int, input().rstrip().split()))
num = sorted(list(map(int, input().rstrip().split())))
lst = sorted(
[tuple(map(int, input().rstrip().split())) for _ in range(m)],
key=lambda x: x[1],
reverse=True,
)
ans, idx = 0, 0
flg = False
for i, j in lst:
for _ in range(i):
if idx < n and num[idx] < j:
ans += j
idx += 1
else:
flg = True
break
if flg:
break
if idx < n:
ans += sum(num[idx:])
print(ans)
if __name__ == "__main__":
main() | # ABC127D - Integer Cards
from operator import itemgetter as gt
def main():
N, M, *X = list(map(int, open(0).read().split()))
A, B = X[:N], [i for i in zip(*[iter(X[N:])] * 2)]
A.sort(), B.sort(key=gt(1), reverse=1)
ans, flg, idx = 0, 0, 0
for i, j in B:
for _ in range(i):
if idx < N and A[idx] < j:
ans += j
idx += 1
else:
flg = 1
break
if flg:
break
if idx < N:
ans += sum(A[idx:])
print(ans)
if __name__ == "__main__":
main() | 33 | 26 | 743 | 608 | # ABC127D - Integer Cards
import sys
input = sys.stdin.readline
def main():
n, m = list(map(int, input().rstrip().split()))
num = sorted(list(map(int, input().rstrip().split())))
lst = sorted(
[tuple(map(int, input().rstrip().split())) for _ in range(m)],
key=lambda x: x[1],
reverse=True,
)
ans, idx = 0, 0
flg = False
for i, j in lst:
for _ in range(i):
if idx < n and num[idx] < j:
ans += j
idx += 1
else:
flg = True
break
if flg:
break
if idx < n:
ans += sum(num[idx:])
print(ans)
if __name__ == "__main__":
main()
| # ABC127D - Integer Cards
from operator import itemgetter as gt
def main():
N, M, *X = list(map(int, open(0).read().split()))
A, B = X[:N], [i for i in zip(*[iter(X[N:])] * 2)]
A.sort(), B.sort(key=gt(1), reverse=1)
ans, flg, idx = 0, 0, 0
for i, j in B:
for _ in range(i):
if idx < N and A[idx] < j:
ans += j
idx += 1
else:
flg = 1
break
if flg:
break
if idx < N:
ans += sum(A[idx:])
print(ans)
if __name__ == "__main__":
main()
| false | 21.212121 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"+from operator import itemgetter as gt",
"- n, m = list(map(int, input().rstrip().split()))",
"- num = sorted(list(map(int, input().rstrip().split())))",
"- lst = sorted(",
"- [tuple(map(int, input().rstrip().split())) for _ in range(... | false | 0.051924 | 0.098384 | 0.527769 | [
"s680049398",
"s556553990"
] |
u115682115 | p03611 | python | s471509200 | s854997739 | 109 | 79 | 14,564 | 13,964 | Accepted | Accepted | 27.52 | from collections import Counter
N = int(eval(input()))
a = list(map(int,input().split()))
counter = Counter(a)
ans=[]
for k,v in list(counter.items()):
if k-1 in counter:
v+=counter[k-1]
if k+1 in counter:
v+=counter[k+1]
ans.append(v)
print((max(ans))) | n = int(eval(input()))
a = list(map(int, input().split()))
c = [0] * (max(a)+3)
for v in a:
c[v] += 1
c[v+1] += 1
c[v+2] += 1
print((max(c))) | 12 | 8 | 278 | 152 | from collections import Counter
N = int(eval(input()))
a = list(map(int, input().split()))
counter = Counter(a)
ans = []
for k, v in list(counter.items()):
if k - 1 in counter:
v += counter[k - 1]
if k + 1 in counter:
v += counter[k + 1]
ans.append(v)
print((max(ans)))
| n = int(eval(input()))
a = list(map(int, input().split()))
c = [0] * (max(a) + 3)
for v in a:
c[v] += 1
c[v + 1] += 1
c[v + 2] += 1
print((max(c)))
| false | 33.333333 | [
"-from collections import Counter",
"-",
"-N = int(eval(input()))",
"+n = int(eval(input()))",
"-counter = Counter(a)",
"-ans = []",
"-for k, v in list(counter.items()):",
"- if k - 1 in counter:",
"- v += counter[k - 1]",
"- if k + 1 in counter:",
"- v += counter[k + 1]",
... | false | 0.040449 | 0.04683 | 0.863744 | [
"s471509200",
"s854997739"
] |
u033524082 | p02608 | python | s591594673 | s387377732 | 434 | 197 | 147,952 | 147,488 | Accepted | Accepted | 54.61 | n=int(eval(input()))
l=[0]*10**7
s=int(n**0.7)+10
for x in range(1,s):
for y in range(1,s-x):
for z in range(1,s-x-y):
l[x*x+y*y+z*z+x*y+y*z+z*x-1]+=1
for i in range(n):
print((l[i])) | n=int(eval(input()))
l=[0]*10**7
s=int(n**0.65)+1
for x in range(1,s):
for y in range(1,s-x):
for z in range(1,s-x-y):
l[x*x+y*y+z*z+x*y+y*z+z*x-1]+=1
for i in range(n):
print((l[i]))
| 9 | 9 | 211 | 212 | n = int(eval(input()))
l = [0] * 10**7
s = int(n**0.7) + 10
for x in range(1, s):
for y in range(1, s - x):
for z in range(1, s - x - y):
l[x * x + y * y + z * z + x * y + y * z + z * x - 1] += 1
for i in range(n):
print((l[i]))
| n = int(eval(input()))
l = [0] * 10**7
s = int(n**0.65) + 1
for x in range(1, s):
for y in range(1, s - x):
for z in range(1, s - x - y):
l[x * x + y * y + z * z + x * y + y * z + z * x - 1] += 1
for i in range(n):
print((l[i]))
| false | 0 | [
"-s = int(n**0.7) + 10",
"+s = int(n**0.65) + 1"
] | false | 0.284114 | 0.205631 | 1.381668 | [
"s591594673",
"s387377732"
] |
u754022296 | p03364 | python | s138835138 | s654876791 | 887 | 535 | 15,940 | 13,908 | Accepted | Accepted | 39.68 | import numpy as np
n = int(eval(input()))
S = np.array([ list(eval(input())) for _ in range(n) ])
ans = 0
for j in range(n):
M = S[:, [(l+j)%n for l in range(n)]]
if (M==M.T).all():
ans += n
print(ans) | import numpy as np
n = int(eval(input()))
S = np.array([ list(eval(input())) for _ in range(n) ])
ans = 0
for j in range(n):
M = np.roll(S, j, axis=0)
if (M==M.T).all():
ans += n
print(ans) | 9 | 9 | 205 | 193 | import numpy as np
n = int(eval(input()))
S = np.array([list(eval(input())) for _ in range(n)])
ans = 0
for j in range(n):
M = S[:, [(l + j) % n for l in range(n)]]
if (M == M.T).all():
ans += n
print(ans)
| import numpy as np
n = int(eval(input()))
S = np.array([list(eval(input())) for _ in range(n)])
ans = 0
for j in range(n):
M = np.roll(S, j, axis=0)
if (M == M.T).all():
ans += n
print(ans)
| false | 0 | [
"- M = S[:, [(l + j) % n for l in range(n)]]",
"+ M = np.roll(S, j, axis=0)"
] | false | 0.254089 | 0.282024 | 0.900948 | [
"s138835138",
"s654876791"
] |
u581187895 | p03339 | python | s510593465 | s388885908 | 223 | 120 | 29,936 | 40,092 | Accepted | Accepted | 46.19 | from itertools import accumulate
from operator import add
N = int(eval(input()))
S = eval(input())
cnt_w = [0] * (N+1) # 左からWの数
for i in range(N): # cumsum
if S[i] == "W":
cnt_w[i+1] = cnt_w[i] + 1
else:
cnt_w[i+1] = cnt_w[i]
cnt_e = [0] * (N+1) # 右からEの数
for i in range(N-1, -1, -1):
if S[i] == "E":
cnt_e[i] = cnt_e[i+1] + 1
else:
cnt_e[i] = cnt_e[i+1]
ans = [w+e for w, e in zip(cnt_w, cnt_e)]
print((min(ans))) | from itertools import accumulate
N = int(eval(input()))
S = eval(input())
turn_E = [0] + list(accumulate([s=="W" for s in S[:-1]]))
turn_W = list(reversed(list(accumulate([s=="E" for s in S[:0:-1]])))) + [0]
ans = [e+w for e, w in zip(turn_E, turn_W)]
print((min(ans))) | 21 | 10 | 452 | 267 | from itertools import accumulate
from operator import add
N = int(eval(input()))
S = eval(input())
cnt_w = [0] * (N + 1) # 左からWの数
for i in range(N): # cumsum
if S[i] == "W":
cnt_w[i + 1] = cnt_w[i] + 1
else:
cnt_w[i + 1] = cnt_w[i]
cnt_e = [0] * (N + 1) # 右からEの数
for i in range(N - 1, -1, -1):
if S[i] == "E":
cnt_e[i] = cnt_e[i + 1] + 1
else:
cnt_e[i] = cnt_e[i + 1]
ans = [w + e for w, e in zip(cnt_w, cnt_e)]
print((min(ans)))
| from itertools import accumulate
N = int(eval(input()))
S = eval(input())
turn_E = [0] + list(accumulate([s == "W" for s in S[:-1]]))
turn_W = list(reversed(list(accumulate([s == "E" for s in S[:0:-1]])))) + [0]
ans = [e + w for e, w in zip(turn_E, turn_W)]
print((min(ans)))
| false | 52.380952 | [
"-from operator import add",
"-cnt_w = [0] * (N + 1) # 左からWの数",
"-for i in range(N): # cumsum",
"- if S[i] == \"W\":",
"- cnt_w[i + 1] = cnt_w[i] + 1",
"- else:",
"- cnt_w[i + 1] = cnt_w[i]",
"-cnt_e = [0] * (N + 1) # 右からEの数",
"-for i in range(N - 1, -1, -1):",
"- if S[i]... | false | 0.084315 | 0.079428 | 1.061516 | [
"s510593465",
"s388885908"
] |
u476604182 | p04000 | python | s845739986 | s247043658 | 1,305 | 1,188 | 115,468 | 116,276 | Accepted | Accepted | 8.97 | H, W, N, *L = list(map(int, open(0).read().split()))
dic = {}
for a, b in zip(*[iter(L)]*2):
for i in range(a-2,a+1):
for j in range(b-2,b+1):
if 0<i and i+2<=H and 0<j and j+2<=W:
dic[i*W+j] = dic.get(i*W+j,0)+1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in list(dic.keys()):
ans[dic[k]] += 1
ans[0] -= 1
print(('\n'.join(map(str,ans)))) | from collections import Counter
H, W, N, *L = list(map(int, open(0).read().split()))
dic = {}
for a, b in zip(*[iter(L)]*2):
for i in range(a-2,a+1):
for j in range(b-2,b+1):
if 0<i and i+2<=H and 0<j and j+2<=W:
dic[i*W+j] = dic.get(i*W+j,0)+1
c = Counter(list(dic.values()))
ans = [(H-2)*(W-2)]+[0]*9
for k in list(c.keys()):
ans[k] = c[k]
ans[0] -= c[k]
print(('\n'.join(map(str,ans)))) | 13 | 14 | 357 | 406 | H, W, N, *L = list(map(int, open(0).read().split()))
dic = {}
for a, b in zip(*[iter(L)] * 2):
for i in range(a - 2, a + 1):
for j in range(b - 2, b + 1):
if 0 < i and i + 2 <= H and 0 < j and j + 2 <= W:
dic[i * W + j] = dic.get(i * W + j, 0) + 1
ans = [0] * 10
ans[0] = (W - 2) * (H - 2)
for k in list(dic.keys()):
ans[dic[k]] += 1
ans[0] -= 1
print(("\n".join(map(str, ans))))
| from collections import Counter
H, W, N, *L = list(map(int, open(0).read().split()))
dic = {}
for a, b in zip(*[iter(L)] * 2):
for i in range(a - 2, a + 1):
for j in range(b - 2, b + 1):
if 0 < i and i + 2 <= H and 0 < j and j + 2 <= W:
dic[i * W + j] = dic.get(i * W + j, 0) + 1
c = Counter(list(dic.values()))
ans = [(H - 2) * (W - 2)] + [0] * 9
for k in list(c.keys()):
ans[k] = c[k]
ans[0] -= c[k]
print(("\n".join(map(str, ans))))
| false | 7.142857 | [
"+from collections import Counter",
"+",
"-ans = [0] * 10",
"-ans[0] = (W - 2) * (H - 2)",
"-for k in list(dic.keys()):",
"- ans[dic[k]] += 1",
"- ans[0] -= 1",
"+c = Counter(list(dic.values()))",
"+ans = [(H - 2) * (W - 2)] + [0] * 9",
"+for k in list(c.keys()):",
"+ ans[k] = c[k]",
... | false | 0.048266 | 0.044497 | 1.084722 | [
"s845739986",
"s247043658"
] |
u562935282 | p03329 | python | s434939225 | s197382242 | 407 | 336 | 3,828 | 3,828 | Accepted | Accepted | 17.44 | def funcDP(n):
dp = [float('inf')] * (n + 10)
dp[0] = 0
for i in range(1, n + 1):
for base in [6, 9]:
powered = 1
while powered <= i:
dp[i] = min(dp[i], dp[i - powered] + 1)
powered *= base
return dp[n]
if __name__ == '__main__':
print((funcDP(int(eval(input()))))) | def main():
inf = 1 << 30
N = int(eval(input()))
dp = [inf] * (N + 1)
dp[0] = 0
for i in range(1, N + 1):
t = inf
x = 1
while x <= i:
t = min(t, dp[i - x])
x *= 6
x = 1
while x <= i:
t = min(t, dp[i - x])
x *= 9
dp[i] = t + 1
print((dp[N]))
if __name__ == '__main__':
main()
| 13 | 25 | 354 | 421 | def funcDP(n):
dp = [float("inf")] * (n + 10)
dp[0] = 0
for i in range(1, n + 1):
for base in [6, 9]:
powered = 1
while powered <= i:
dp[i] = min(dp[i], dp[i - powered] + 1)
powered *= base
return dp[n]
if __name__ == "__main__":
print((funcDP(int(eval(input())))))
| def main():
inf = 1 << 30
N = int(eval(input()))
dp = [inf] * (N + 1)
dp[0] = 0
for i in range(1, N + 1):
t = inf
x = 1
while x <= i:
t = min(t, dp[i - x])
x *= 6
x = 1
while x <= i:
t = min(t, dp[i - x])
x *= 9
dp[i] = t + 1
print((dp[N]))
if __name__ == "__main__":
main()
| false | 48 | [
"-def funcDP(n):",
"- dp = [float(\"inf\")] * (n + 10)",
"+def main():",
"+ inf = 1 << 30",
"+ N = int(eval(input()))",
"+ dp = [inf] * (N + 1)",
"- for i in range(1, n + 1):",
"- for base in [6, 9]:",
"- powered = 1",
"- while powered <= i:",
"- ... | false | 0.092045 | 0.197481 | 0.466094 | [
"s434939225",
"s197382242"
] |
u352394527 | p00464 | python | s411804089 | s957697464 | 1,180 | 1,070 | 30,336 | 30,336 | Accepted | Accepted | 9.32 | def solve():
while True:
h,w,n = list(map(int,input().split()))
if not h: break
sss = [[1 if s == "1" else 0 for s in input().split()] for i in range(h)]
dp = [[0 for i in range(w + 1)] for j in range(h + 1)]
dp[0][0] = n - 1
for x in range(h):
for y in range(w):
a = dp[x][y]
if sss[x][y]:
if a % 2:
dp[x + 1][y] += a // 2
dp[x][y + 1] += a // 2 + 1
else:
dp[x + 1][y] += a // 2
dp[x][y + 1] += a // 2
else:
if a % 2:
dp[x + 1][y] += a // 2 + 1
dp[x][y + 1] += a // 2
else:
dp[x + 1][y] += a // 2
dp[x][y + 1] += a // 2
sss[x][y] = (sss[x][y] + dp[x][y]) % 2
# print(sss)
# print(dp)
x = y = 0
while x < h and y < w:
if sss[x][y]:
y += 1
else:
x += 1
print((x + 1,y + 1))
# print(sss)
solve()
| def solve():
while True:
h,w,n = list(map(int,input().split()))
if not h: break
sss = [[1 if s == "1" else 0 for s in input().split()] for i in range(h)]
dp = [[0 for i in range(w + 1)] for j in range(h + 1)]
dp[0][0] = n - 1
for x in range(h):
for y in range(w):
a = dp[x][y]
b = sss[x][y]
if b:
if a % 2:
dp[x + 1][y] += a // 2
dp[x][y + 1] += a // 2 + 1
else:
dp[x + 1][y] += a // 2
dp[x][y + 1] += a // 2
else:
if a % 2:
dp[x + 1][y] += a // 2 + 1
dp[x][y + 1] += a // 2
else:
dp[x + 1][y] += a // 2
dp[x][y + 1] += a // 2
sss[x][y] = (a + b) % 2
# print(sss)
# print(dp)
x = y = 0
while x < h and y < w:
if sss[x][y]:
y += 1
else:
x += 1
print((x + 1,y + 1))
# print(sss)
solve()
| 37 | 38 | 974 | 974 | def solve():
while True:
h, w, n = list(map(int, input().split()))
if not h:
break
sss = [[1 if s == "1" else 0 for s in input().split()] for i in range(h)]
dp = [[0 for i in range(w + 1)] for j in range(h + 1)]
dp[0][0] = n - 1
for x in range(h):
for y in range(w):
a = dp[x][y]
if sss[x][y]:
if a % 2:
dp[x + 1][y] += a // 2
dp[x][y + 1] += a // 2 + 1
else:
dp[x + 1][y] += a // 2
dp[x][y + 1] += a // 2
else:
if a % 2:
dp[x + 1][y] += a // 2 + 1
dp[x][y + 1] += a // 2
else:
dp[x + 1][y] += a // 2
dp[x][y + 1] += a // 2
sss[x][y] = (sss[x][y] + dp[x][y]) % 2
# print(sss)
# print(dp)
x = y = 0
while x < h and y < w:
if sss[x][y]:
y += 1
else:
x += 1
print((x + 1, y + 1))
# print(sss)
solve()
| def solve():
while True:
h, w, n = list(map(int, input().split()))
if not h:
break
sss = [[1 if s == "1" else 0 for s in input().split()] for i in range(h)]
dp = [[0 for i in range(w + 1)] for j in range(h + 1)]
dp[0][0] = n - 1
for x in range(h):
for y in range(w):
a = dp[x][y]
b = sss[x][y]
if b:
if a % 2:
dp[x + 1][y] += a // 2
dp[x][y + 1] += a // 2 + 1
else:
dp[x + 1][y] += a // 2
dp[x][y + 1] += a // 2
else:
if a % 2:
dp[x + 1][y] += a // 2 + 1
dp[x][y + 1] += a // 2
else:
dp[x + 1][y] += a // 2
dp[x][y + 1] += a // 2
sss[x][y] = (a + b) % 2
# print(sss)
# print(dp)
x = y = 0
while x < h and y < w:
if sss[x][y]:
y += 1
else:
x += 1
print((x + 1, y + 1))
# print(sss)
solve()
| false | 2.631579 | [
"- if sss[x][y]:",
"+ b = sss[x][y]",
"+ if b:",
"- sss[x][y] = (sss[x][y] + dp[x][y]) % 2",
"+ sss[x][y] = (a + b) % 2"
] | false | 0.046355 | 0.040821 | 1.135559 | [
"s411804089",
"s957697464"
] |
u188827677 | p04044 | python | s333202529 | s342887463 | 28 | 25 | 9,176 | 9,176 | Accepted | Accepted | 10.71 | n,l = list(map(int, input().split()))
s = sorted([eval(input()) for _ in range(n)])
print(("".join(s))) | n,l = list(map(int, input().split()))
print(("".join(sorted([eval(input()) for _ in range(n)])))) | 4 | 2 | 93 | 84 | n, l = list(map(int, input().split()))
s = sorted([eval(input()) for _ in range(n)])
print(("".join(s)))
| n, l = list(map(int, input().split()))
print(("".join(sorted([eval(input()) for _ in range(n)]))))
| false | 50 | [
"-s = sorted([eval(input()) for _ in range(n)])",
"-print((\"\".join(s)))",
"+print((\"\".join(sorted([eval(input()) for _ in range(n)]))))"
] | false | 0.072886 | 0.071805 | 1.015058 | [
"s333202529",
"s342887463"
] |
u143509139 | p03345 | python | s168353278 | s712508612 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | a,b,c,k=list(map(int,input().split()))
if k%2==0:
print((a-b))
else:
print((b-a)) | a,b,c,k = list(map(int, input().split()))
if k % 2:
print((b - a))
else:
print((a - b)) | 5 | 5 | 79 | 85 | a, b, c, k = list(map(int, input().split()))
if k % 2 == 0:
print((a - b))
else:
print((b - a))
| a, b, c, k = list(map(int, input().split()))
if k % 2:
print((b - a))
else:
print((a - b))
| false | 0 | [
"-if k % 2 == 0:",
"+if k % 2:",
"+ print((b - a))",
"+else:",
"-else:",
"- print((b - a))"
] | false | 0.04055 | 0.077585 | 0.522649 | [
"s168353278",
"s712508612"
] |
u736443076 | p02713 | python | s433898209 | s854896778 | 1,365 | 671 | 9,180 | 9,184 | Accepted | Accepted | 50.84 | import sys
from math import gcd
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline
def solve():
k = int(rl())
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
for c in range(1, k + 1):
d = gcd(a, b)
ans += gcd(c, d)
print(ans)
if __name__ == '__main__':
solve()
| import sys
from math import gcd
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline
def solve():
k = int(rl())
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
d = gcd(a, b)
for c in range(1, k + 1):
ans += gcd(c, d)
print(ans)
if __name__ == '__main__':
solve()
| 20 | 20 | 373 | 369 | import sys
from math import gcd
sys.setrecursionlimit(10**7)
rl = sys.stdin.readline
def solve():
k = int(rl())
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
for c in range(1, k + 1):
d = gcd(a, b)
ans += gcd(c, d)
print(ans)
if __name__ == "__main__":
solve()
| import sys
from math import gcd
sys.setrecursionlimit(10**7)
rl = sys.stdin.readline
def solve():
k = int(rl())
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
d = gcd(a, b)
for c in range(1, k + 1):
ans += gcd(c, d)
print(ans)
if __name__ == "__main__":
solve()
| false | 0 | [
"+ d = gcd(a, b)",
"- d = gcd(a, b)"
] | false | 0.144601 | 0.087291 | 1.656546 | [
"s433898209",
"s854896778"
] |
u312025627 | p02761 | python | s390367716 | s967384650 | 171 | 18 | 38,256 | 3,064 | Accepted | Accepted | 89.47 | def main():
N, M = (int(i) for i in input().split())
from collections import defaultdict
dic = defaultdict(set)
for i in range(M):
s, c = (int(i) for i in input().split())
dic[s].add(c)
if 0 in dic[1] and N != 1:
return print(-1)
for i in range(1, N+1):
if len(dic[i]) > 1:
return print(-1)
elif not(dic[i]):
dic[i].add(0 if i != 1 or N == 1 else 1)
# print(dic)
s = ""
for i in range(1, N+1):
s = s + str(dic[i].pop())
print(s)
if __name__ == '__main__':
main()
| def main():
N, M = (int(i) for i in input().split())
dic = {}
for i in range(M):
s, c = (i for i in input().split())
if s in dic.keys() and dic[s] != c:
return print(-1)
dic[s] = c
for t in range(1000):
t = str(t)
if len(t) != N:
continue
for k, v in dic.items():
if t[int(k)-1] != v:
break
else:
return print(t)
print(-1)
if __name__ == '__main__':
main()
| 23 | 22 | 603 | 524 | def main():
N, M = (int(i) for i in input().split())
from collections import defaultdict
dic = defaultdict(set)
for i in range(M):
s, c = (int(i) for i in input().split())
dic[s].add(c)
if 0 in dic[1] and N != 1:
return print(-1)
for i in range(1, N + 1):
if len(dic[i]) > 1:
return print(-1)
elif not (dic[i]):
dic[i].add(0 if i != 1 or N == 1 else 1)
# print(dic)
s = ""
for i in range(1, N + 1):
s = s + str(dic[i].pop())
print(s)
if __name__ == "__main__":
main()
| def main():
N, M = (int(i) for i in input().split())
dic = {}
for i in range(M):
s, c = (i for i in input().split())
if s in dic.keys() and dic[s] != c:
return print(-1)
dic[s] = c
for t in range(1000):
t = str(t)
if len(t) != N:
continue
for k, v in dic.items():
if t[int(k) - 1] != v:
break
else:
return print(t)
print(-1)
if __name__ == "__main__":
main()
| false | 4.347826 | [
"- from collections import defaultdict",
"-",
"- dic = defaultdict(set)",
"+ dic = {}",
"- s, c = (int(i) for i in input().split())",
"- dic[s].add(c)",
"- if 0 in dic[1] and N != 1:",
"- return print(-1)",
"- for i in range(1, N + 1):",
"- if len(dic[i])... | false | 0.083036 | 0.040681 | 2.041148 | [
"s390367716",
"s967384650"
] |
u978313283 | p02630 | python | s296954422 | s478443099 | 783 | 425 | 38,224 | 90,756 | Accepted | Accepted | 45.72 | import numpy as np
N=int(eval(input()))
A=list(map(int,input().split()))
SUM=sum(A)
Q=int(eval(input()))
List=np.array([0 for _ in range(10**5+1)])
for a in A:
List[a]+=1
for q in range(Q):
B,C=list(map(int,input().split()))
SUM-=B*List[B]
SUM+=C*List[B]
List[C]+=List[B]
List[B]=0
print(SUM) | N=int(eval(input()))
A=list(map(int,input().split()))
SUM=sum(A)
Q=int(eval(input()))
List=[0 for _ in range(10**5+1)]
for a in A:
List[a]+=1
for q in range(Q):
B,C=list(map(int,input().split()))
SUM-=B*List[B]
SUM+=C*List[B]
List[C]+=List[B]
List[B]=0
print(SUM) | 15 | 14 | 316 | 286 | import numpy as np
N = int(eval(input()))
A = list(map(int, input().split()))
SUM = sum(A)
Q = int(eval(input()))
List = np.array([0 for _ in range(10**5 + 1)])
for a in A:
List[a] += 1
for q in range(Q):
B, C = list(map(int, input().split()))
SUM -= B * List[B]
SUM += C * List[B]
List[C] += List[B]
List[B] = 0
print(SUM)
| N = int(eval(input()))
A = list(map(int, input().split()))
SUM = sum(A)
Q = int(eval(input()))
List = [0 for _ in range(10**5 + 1)]
for a in A:
List[a] += 1
for q in range(Q):
B, C = list(map(int, input().split()))
SUM -= B * List[B]
SUM += C * List[B]
List[C] += List[B]
List[B] = 0
print(SUM)
| false | 6.666667 | [
"-import numpy as np",
"-",
"-List = np.array([0 for _ in range(10**5 + 1)])",
"+List = [0 for _ in range(10**5 + 1)]"
] | false | 0.394937 | 0.04567 | 8.647578 | [
"s296954422",
"s478443099"
] |
u445624660 | p03785 | python | s439247848 | s659292768 | 240 | 183 | 8,280 | 14,156 | Accepted | Accepted | 23.75 | # 乗せれるだけ乗っけるのがいいと思うだけなんだけどどうなんでしょう
# なんか実装しにくい 世界一プログラミングが下手
# 二重whileなんてやるからだ forでいいやろ
n, c, k = list(map(int, input().split()))
ans = 0
arr = sorted([int(eval(input())) for _ in range(n)])
cur_passenger = 0
limit = arr[0] + k
for i in range(n):
if cur_passenger < c and arr[i] <= limit:
cur_passenger += 1
# print("{}番目の人は{}のバスに乗せた".format(i, ans))
else:
cur_passenger = 1
limit = arr[i] + k
ans += 1
# print("{}番目の人を{}のバスの最初の客にした".format(i, ans))
# あぶれた人を救済
if cur_passenger > 0:
ans += 1
print(ans)
| n, c, k = list(map(int, input().split()))
t = sorted([int(eval(input())) for _ in range(n)])
ans = 1
passenger = 0
limit = t[0] + k
for p in t:
if passenger < c and p <= limit:
passenger += 1
else:
ans += 1
passenger = 1
limit = p + k
print(ans)
| 21 | 14 | 571 | 288 | # 乗せれるだけ乗っけるのがいいと思うだけなんだけどどうなんでしょう
# なんか実装しにくい 世界一プログラミングが下手
# 二重whileなんてやるからだ forでいいやろ
n, c, k = list(map(int, input().split()))
ans = 0
arr = sorted([int(eval(input())) for _ in range(n)])
cur_passenger = 0
limit = arr[0] + k
for i in range(n):
if cur_passenger < c and arr[i] <= limit:
cur_passenger += 1
# print("{}番目の人は{}のバスに乗せた".format(i, ans))
else:
cur_passenger = 1
limit = arr[i] + k
ans += 1
# print("{}番目の人を{}のバスの最初の客にした".format(i, ans))
# あぶれた人を救済
if cur_passenger > 0:
ans += 1
print(ans)
| n, c, k = list(map(int, input().split()))
t = sorted([int(eval(input())) for _ in range(n)])
ans = 1
passenger = 0
limit = t[0] + k
for p in t:
if passenger < c and p <= limit:
passenger += 1
else:
ans += 1
passenger = 1
limit = p + k
print(ans)
| false | 33.333333 | [
"-# 乗せれるだけ乗っけるのがいいと思うだけなんだけどどうなんでしょう",
"-# なんか実装しにくい 世界一プログラミングが下手",
"-# 二重whileなんてやるからだ forでいいやろ",
"-ans = 0",
"-arr = sorted([int(eval(input())) for _ in range(n)])",
"-cur_passenger = 0",
"-limit = arr[0] + k",
"-for i in range(n):",
"- if cur_passenger < c and arr[i] <= limit:",
"- c... | false | 0.06058 | 0.059324 | 1.021187 | [
"s439247848",
"s659292768"
] |
u145035045 | p04013 | python | s547416976 | s877565608 | 685 | 203 | 4,596 | 40,176 | Accepted | Accepted | 70.36 | def main():
n, a = list(map(int, input().split()))
xlst = list(map(int, input().split()))
"""
dp[i][j][k] ... iまででj個使ってkを作る
dp[i][j][k] += dp[i - 1][j - 1][k - x]
"""
"""
xlst.insert(0, 0)
dp = [[[0] * (50 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(n + 1):
dp[i][0][0] = 1
for i in range(1, n + 1):
x = xlst[i]
dpi = dp[i]
dpi_1 = dp[i - 1]
for j in range(1, n + 1):
dpij = dpi[j]
dpi_1j = dpi_1[j]
dpi_1j_1 = dpi_1[j - 1]
for k in range(1, n * 50 + 1):
if k >= x:
#dp[i][j][k] += dp[i - 1][j - 1][k - x] + dp[i - 1][j][k]
dpij[k] += dpi_1j_1[k - x] + dpi_1j[k]
else:
#dp[i][j][k] += dp[i - 1][j][k]
dpij[k] += dpi_1j[k]
ans = 0
for j in range(1, n + 1):
ans += dp[n][j][j * a]
print(ans)
"""
dp = [[0] * (n * 50 + 1) for _ in range(n + 1)]
dp[0][0] = 1
for x in xlst:
for j in range(n, 0, -1):
dpj = dp[j]
dpj1 = dp[j - 1]
for k in range(n * 50, x - 1, -1):
dpj[k] += dpj1[k - x]
print((sum([dp[j][j * a] for j in range(1, n + 1)])))
main() | def main():
n, a = list(map(int, input().split()))
xlst = list(map(int, input().split()))
"""
#dp[i][j][k] ... iまででj個使ってkを作る
#dp[i][j][k] += dp[i - 1][j - 1][k - x]
xlst.insert(0, 0)
dp = [[[0] * (50 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(n + 1):
dp[i][0][0] = 1
for i in range(1, n + 1):
x = xlst[i]
dpi = dp[i]
dpi_1 = dp[i - 1]
for j in range(1, n + 1):
dpij = dpi[j]
dpi_1j = dpi_1[j]
dpi_1j_1 = dpi_1[j - 1]
for k in range(1, n * 50 + 1):
if k >= x:
#dp[i][j][k] += dp[i - 1][j - 1][k - x] + dp[i - 1][j][k]
dpij[k] += dpi_1j_1[k - x] + dpi_1j[k]
else:
#dp[i][j][k] += dp[i - 1][j][k]
dpij[k] += dpi_1j[k]
ans = 0
for j in range(1, n + 1):
ans += dp[n][j][j * a]
print(ans)
"""
dp = [[0] * (n * 50 + 1) for _ in range(n + 1)]
dp[0][0] = 1
for x in xlst:
for j in range(n, 0, -1):
dpj = dp[j]
dpj1 = dp[j - 1]
for k in range(x, n * 50 + 1):
dpj[k] += dpj1[k - x]
print((sum([dp[j][j * a] for j in range(1, n + 1)])))
main() | 52 | 50 | 1,202 | 1,186 | def main():
n, a = list(map(int, input().split()))
xlst = list(map(int, input().split()))
"""
dp[i][j][k] ... iまででj個使ってkを作る
dp[i][j][k] += dp[i - 1][j - 1][k - x]
"""
"""
xlst.insert(0, 0)
dp = [[[0] * (50 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(n + 1):
dp[i][0][0] = 1
for i in range(1, n + 1):
x = xlst[i]
dpi = dp[i]
dpi_1 = dp[i - 1]
for j in range(1, n + 1):
dpij = dpi[j]
dpi_1j = dpi_1[j]
dpi_1j_1 = dpi_1[j - 1]
for k in range(1, n * 50 + 1):
if k >= x:
#dp[i][j][k] += dp[i - 1][j - 1][k - x] + dp[i - 1][j][k]
dpij[k] += dpi_1j_1[k - x] + dpi_1j[k]
else:
#dp[i][j][k] += dp[i - 1][j][k]
dpij[k] += dpi_1j[k]
ans = 0
for j in range(1, n + 1):
ans += dp[n][j][j * a]
print(ans)
"""
dp = [[0] * (n * 50 + 1) for _ in range(n + 1)]
dp[0][0] = 1
for x in xlst:
for j in range(n, 0, -1):
dpj = dp[j]
dpj1 = dp[j - 1]
for k in range(n * 50, x - 1, -1):
dpj[k] += dpj1[k - x]
print((sum([dp[j][j * a] for j in range(1, n + 1)])))
main()
| def main():
n, a = list(map(int, input().split()))
xlst = list(map(int, input().split()))
"""
#dp[i][j][k] ... iまででj個使ってkを作る
#dp[i][j][k] += dp[i - 1][j - 1][k - x]
xlst.insert(0, 0)
dp = [[[0] * (50 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(n + 1):
dp[i][0][0] = 1
for i in range(1, n + 1):
x = xlst[i]
dpi = dp[i]
dpi_1 = dp[i - 1]
for j in range(1, n + 1):
dpij = dpi[j]
dpi_1j = dpi_1[j]
dpi_1j_1 = dpi_1[j - 1]
for k in range(1, n * 50 + 1):
if k >= x:
#dp[i][j][k] += dp[i - 1][j - 1][k - x] + dp[i - 1][j][k]
dpij[k] += dpi_1j_1[k - x] + dpi_1j[k]
else:
#dp[i][j][k] += dp[i - 1][j][k]
dpij[k] += dpi_1j[k]
ans = 0
for j in range(1, n + 1):
ans += dp[n][j][j * a]
print(ans)
"""
dp = [[0] * (n * 50 + 1) for _ in range(n + 1)]
dp[0][0] = 1
for x in xlst:
for j in range(n, 0, -1):
dpj = dp[j]
dpj1 = dp[j - 1]
for k in range(x, n * 50 + 1):
dpj[k] += dpj1[k - x]
print((sum([dp[j][j * a] for j in range(1, n + 1)])))
main()
| false | 3.846154 | [
"- dp[i][j][k] ... iまででj個使ってkを作る",
"- dp[i][j][k] += dp[i - 1][j - 1][k - x]",
"- \"\"\"",
"- \"\"\"",
"+ #dp[i][j][k] ... iまででj個使ってkを作る",
"+ #dp[i][j][k] += dp[i - 1][j - 1][k - x]",
"- for k in range(n * 50, x - 1, -1):",
"+ for k in range(x, n * 50 + 1):"
] | false | 0.040366 | 0.07889 | 0.511672 | [
"s547416976",
"s877565608"
] |
u969850098 | p03274 | python | s760184446 | s067986683 | 843 | 84 | 14,844 | 14,780 | Accepted | Accepted | 90.04 | import sys
readline = sys.stdin.readline
def main():
N, K = list(map(int, readline().rstrip().split()))
X = list(map(int, readline().rstrip().split()))
len_m = len([x for x in X if x < 0])
len_p = len([x for x in X if x > 0])
ans = 10**10
idx = max(0, len_m-K)
s = [0] + X[idx:idx+K-1]
for i in range(max(0, len_m-K), min(len_m+K, N-K+1)):
s.pop(0)
s.append(X[i+K-1])
if s[0] < 0 and s[-1] > 0:
c = min(abs(s[0]) * 2 + s[-1], abs(s[0]) + s[-1] * 2)
else:
c = max(abs(s[0]), abs(s[-1]))
ans = min(ans, c)
print(ans)
if __name__ == '__main__':
main() | import sys
readline = sys.stdin.readline
def main():
N, K = list(map(int, readline().rstrip().split()))
X = list(map(int, readline().rstrip().split()))
len_m = len([x for x in X if x < 0])
len_p = len([x for x in X if x > 0])
ans = 10**10
for i in range(max(0, len_m-K), min(len_m+K, N-K+1)):
l = X[i]
r = X[i+K-1]
if l < 0 and r > 0:
c = min(abs(l) * 2 + r, abs(l) + r * 2)
else:
c = max(abs(l), abs(r))
ans = min(ans, c)
print(ans)
if __name__ == '__main__':
main() | 25 | 23 | 674 | 583 | import sys
readline = sys.stdin.readline
def main():
N, K = list(map(int, readline().rstrip().split()))
X = list(map(int, readline().rstrip().split()))
len_m = len([x for x in X if x < 0])
len_p = len([x for x in X if x > 0])
ans = 10**10
idx = max(0, len_m - K)
s = [0] + X[idx : idx + K - 1]
for i in range(max(0, len_m - K), min(len_m + K, N - K + 1)):
s.pop(0)
s.append(X[i + K - 1])
if s[0] < 0 and s[-1] > 0:
c = min(abs(s[0]) * 2 + s[-1], abs(s[0]) + s[-1] * 2)
else:
c = max(abs(s[0]), abs(s[-1]))
ans = min(ans, c)
print(ans)
if __name__ == "__main__":
main()
| import sys
readline = sys.stdin.readline
def main():
N, K = list(map(int, readline().rstrip().split()))
X = list(map(int, readline().rstrip().split()))
len_m = len([x for x in X if x < 0])
len_p = len([x for x in X if x > 0])
ans = 10**10
for i in range(max(0, len_m - K), min(len_m + K, N - K + 1)):
l = X[i]
r = X[i + K - 1]
if l < 0 and r > 0:
c = min(abs(l) * 2 + r, abs(l) + r * 2)
else:
c = max(abs(l), abs(r))
ans = min(ans, c)
print(ans)
if __name__ == "__main__":
main()
| false | 8 | [
"- idx = max(0, len_m - K)",
"- s = [0] + X[idx : idx + K - 1]",
"- s.pop(0)",
"- s.append(X[i + K - 1])",
"- if s[0] < 0 and s[-1] > 0:",
"- c = min(abs(s[0]) * 2 + s[-1], abs(s[0]) + s[-1] * 2)",
"+ l = X[i]",
"+ r = X[i + K - 1]",
"+ if l... | false | 0.042521 | 0.036089 | 1.178238 | [
"s760184446",
"s067986683"
] |
u047796752 | p03332 | python | s729806084 | s243534379 | 237 | 100 | 48,376 | 87,640 | Accepted | Accepted | 57.81 | import sys
input = sys.stdin.readline
from collections import *
MAX = 3*10**5+100
MOD = 998244353
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fact[i] = fact[i-1]*i%MOD
inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
finv[i] = finv[i-1]*inv[i]%MOD
def C(n, r):
if n<r:
return 0
if n<0 or r<0:
return 0
return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD
N, A, B, K = list(map(int, input().split()))
ans = 0
for i in range(N+1):
if (K-i*A)%B!=0:
continue
j = (K-i*A)//B
ans += C(N, i)*C(N, j)
ans %= MOD
print(ans) | MAX = 3*10**5+100
MOD = 998244353
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fact[i] = fact[i-1]*i%MOD
inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
finv[i] = finv[i-1]*inv[i]%MOD
def C(n, r):
if n<r:
return 0
if n<0 or r<0:
return 0
return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD
N, A, B, K = list(map(int, input().split()))
ans = 0
for i in range(N+1):
if (K-A*i)%B==0:
j = (K-A*i)//B
ans += C(N, i)*C(N, j)
ans %= MOD
print(ans) | 39 | 33 | 729 | 648 | import sys
input = sys.stdin.readline
from collections import *
MAX = 3 * 10**5 + 100
MOD = 998244353
fact = [0] * MAX # fact[i]: i!
inv = [0] * MAX # inv[i]: iの逆元
finv = [0] * MAX # finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fact[i] = fact[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def C(n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD
N, A, B, K = list(map(int, input().split()))
ans = 0
for i in range(N + 1):
if (K - i * A) % B != 0:
continue
j = (K - i * A) // B
ans += C(N, i) * C(N, j)
ans %= MOD
print(ans)
| MAX = 3 * 10**5 + 100
MOD = 998244353
fact = [0] * MAX # fact[i]: i!
inv = [0] * MAX # inv[i]: iの逆元
finv = [0] * MAX # finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fact[i] = fact[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def C(n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD
N, A, B, K = list(map(int, input().split()))
ans = 0
for i in range(N + 1):
if (K - A * i) % B == 0:
j = (K - A * i) // B
ans += C(N, i) * C(N, j)
ans %= MOD
print(ans)
| false | 15.384615 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-from collections import *",
"-",
"- if (K - i * A) % B != 0:",
"- continue",
"- j = (K - i * A) // B",
"- ans += C(N, i) * C(N, j)",
"- ans %= MOD",
"+ if (K - A * i) % B == 0:",
"+ j = (K - A * i) // B",
"+ ... | false | 1.790711 | 0.794177 | 2.2548 | [
"s729806084",
"s243534379"
] |
u207241407 | p02844 | python | s687752497 | s671729115 | 370 | 186 | 10,212 | 9,544 | Accepted | Accepted | 49.73 | n = int(eval(input()))
s = list(map(int, eval(input())))
ans = []
for i in range(10):
if i in s:
a = s.index(i)
for j in range(10):
if j in s[a + 1 :]:
b = [x for x, y in enumerate(s) if x > a and y == j][0]
for k in range(10):
if k in s[b + 1 :]:
ans.append(f"{i}{j}{k}")
print((len(ans))) | n = int(eval(input()))
s = list(map(int, eval(input())))
ans = []
for i in range(10):
if i in s:
a = s.index(i)
for j in range(10):
if j in s[a + 1 :]:
b = a + s[a + 1 :].index(j) + 1
for k in range(10):
if k in s[b + 1 :]:
ans.append(f"{i}{j}{k}")
print((len(ans))) | 15 | 15 | 400 | 376 | n = int(eval(input()))
s = list(map(int, eval(input())))
ans = []
for i in range(10):
if i in s:
a = s.index(i)
for j in range(10):
if j in s[a + 1 :]:
b = [x for x, y in enumerate(s) if x > a and y == j][0]
for k in range(10):
if k in s[b + 1 :]:
ans.append(f"{i}{j}{k}")
print((len(ans)))
| n = int(eval(input()))
s = list(map(int, eval(input())))
ans = []
for i in range(10):
if i in s:
a = s.index(i)
for j in range(10):
if j in s[a + 1 :]:
b = a + s[a + 1 :].index(j) + 1
for k in range(10):
if k in s[b + 1 :]:
ans.append(f"{i}{j}{k}")
print((len(ans)))
| false | 0 | [
"- b = [x for x, y in enumerate(s) if x > a and y == j][0]",
"+ b = a + s[a + 1 :].index(j) + 1"
] | false | 0.0453 | 0.060799 | 0.74507 | [
"s687752497",
"s671729115"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.