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
sequence | 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
sequence |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u396210538 | p02696 | python | s711102825 | s773268847 | 22 | 20 | 9,156 | 9,160 | Accepted | Accepted | 9.09 | from sys import stdin
A, B, N = [int(x) for x in stdin.readline().rstrip().split()]
ans1 = (A*N)//B-A*(N//B)
if B-1<=N:
ans2 = (A*(B-1))//B
else:
ans2=0
print((max(ans1,ans2))) | from sys import stdin
A, B, N = [int(x) for x in stdin.readline().rstrip().split()]
ans1 = ((A*N)//B)-A*int(N/B)
if B-1<=N:
ans2 = (A*(B-1))//B
else:
ans2=0
print((max(ans1,ans2))) | 12 | 12 | 197 | 201 | from sys import stdin
A, B, N = [int(x) for x in stdin.readline().rstrip().split()]
ans1 = (A * N) // B - A * (N // B)
if B - 1 <= N:
ans2 = (A * (B - 1)) // B
else:
ans2 = 0
print((max(ans1, ans2)))
| from sys import stdin
A, B, N = [int(x) for x in stdin.readline().rstrip().split()]
ans1 = ((A * N) // B) - A * int(N / B)
if B - 1 <= N:
ans2 = (A * (B - 1)) // B
else:
ans2 = 0
print((max(ans1, ans2)))
| false | 0 | [
"-ans1 = (A * N) // B - A * (N // B)",
"+ans1 = ((A * N) // B) - A * int(N / B)"
] | false | 0.042776 | 0.139137 | 0.307435 | [
"s711102825",
"s773268847"
] |
u150984829 | p02410 | python | s592297519 | s114281839 | 30 | 20 | 6,012 | 6,016 | Accepted | Accepted | 33.33 | n,m=list(map(int,input().split()))
A=[[] for _ in range(n)]
for i in range(n):
A[i] = [_ for _ in map(int,input().split())]
b=[]
for i in range(m):
b.append(int(eval(input())))
for i in range(n):
c=0
for j in range(m):
c+=A[i][j]*b[j]
print(c) | n,m=list(map(int,input().split()))
A=[list(map(int,input().split())) for _ in range(n)]
b=[int(eval(input())) for _ in range(m)]
for i in range(n):
print((sum([A[i][j]*b[j] for j in range(m)]))) | 12 | 5 | 249 | 185 | n, m = list(map(int, input().split()))
A = [[] for _ in range(n)]
for i in range(n):
A[i] = [_ for _ in map(int, input().split())]
b = []
for i in range(m):
b.append(int(eval(input())))
for i in range(n):
c = 0
for j in range(m):
c += A[i][j] * b[j]
print(c)
| n, m = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(n)]
b = [int(eval(input())) for _ in range(m)]
for i in range(n):
print((sum([A[i][j] * b[j] for j in range(m)])))
| false | 58.333333 | [
"-A = [[] for _ in range(n)]",
"+A = [list(map(int, input().split())) for _ in range(n)]",
"+b = [int(eval(input())) for _ in range(m)]",
"- A[i] = [_ for _ in map(int, input().split())]",
"-b = []",
"-for i in range(m):",
"- b.append(int(eval(input())))",
"-for i in range(n):",
"- c = 0",
"- for j in range(m):",
"- c += A[i][j] * b[j]",
"- print(c)",
"+ print((sum([A[i][j] * b[j] for j in range(m)])))"
] | false | 0.049107 | 0.04894 | 1.003411 | [
"s592297519",
"s114281839"
] |
u146816547 | p00710 | python | s615648698 | s768787303 | 30 | 20 | 4,648 | 4,648 | Accepted | Accepted | 33.33 | while True:
n, r = list(map(int, input().split()))
if n == 0 and r == 0:
break
Cards = [i for i in range(n, 0, -1)]
for i in range(r):
p, c = list(map(int, input().split()))
Cards = Cards[p-1:p-1+c] + Cards[:p-1] + Cards[p-1+c:]
print(Cards[0])
| while True:
n, r = list(map(int, input().split()))
if n == 0 and r == 0:
break
Cards = list(range(n, 0, -1))
for i in range(r):
p, c = list(map(int, input().split()))
Cards = Cards[p-1:p-1+c] + Cards[:p-1] + Cards[p-1+c:]
print(Cards[0])
| 13 | 14 | 300 | 289 | while True:
n, r = list(map(int, input().split()))
if n == 0 and r == 0:
break
Cards = [i for i in range(n, 0, -1)]
for i in range(r):
p, c = list(map(int, input().split()))
Cards = Cards[p - 1 : p - 1 + c] + Cards[: p - 1] + Cards[p - 1 + c :]
print(Cards[0])
| while True:
n, r = list(map(int, input().split()))
if n == 0 and r == 0:
break
Cards = list(range(n, 0, -1))
for i in range(r):
p, c = list(map(int, input().split()))
Cards = Cards[p - 1 : p - 1 + c] + Cards[: p - 1] + Cards[p - 1 + c :]
print(Cards[0])
| false | 7.142857 | [
"- Cards = [i for i in range(n, 0, -1)]",
"+ Cards = list(range(n, 0, -1))"
] | false | 0.043933 | 0.068003 | 0.646044 | [
"s615648698",
"s768787303"
] |
u332793228 | p03264 | python | s053210896 | s943067256 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | k=int(eval(input()))
print((k**2//4)) | print((int(eval(input()))**2>>2)) | 2 | 1 | 30 | 25 | k = int(eval(input()))
print((k**2 // 4))
| print((int(eval(input())) ** 2 >> 2))
| false | 50 | [
"-k = int(eval(input()))",
"-print((k**2 // 4))",
"+print((int(eval(input())) ** 2 >> 2))"
] | false | 0.047302 | 0.047059 | 1.005157 | [
"s053210896",
"s943067256"
] |
u368796742 | p03158 | python | s549201732 | s667072352 | 1,456 | 1,154 | 103,604 | 24,240 | Accepted | Accepted | 20.74 | import bisect
n,q = list(map(int,input().split()))
A = list(map(int,input().split()))
dic = {}
w = [A[0]]
for i in range(1,n):
w.append(w[-1]+A[i])
w1 = [A[0],0]
w2 = [0,A[1]]
for i in range(2,n):
if i%2 == 0:
w1.append(w1[-2]+A[i])
w2.append(0)
else:
w2.append(w2[-2]+A[i])
w1.append(0)
def solve(x):
if x in dic:
print((dic[x]))
return
if x >= A[-1]:
count = max(w1[-1],w2[-1])
dic[x] = count
print(count)
return
l = 0
r = 10**10
while r > l+1:
m = (r+l)//2
li = bisect.bisect_left(A,x-m)
ri = bisect.bisect_right(A,x+m)
if n-ri == ri-li:
count = w[-1]-w[ri-1]
li -= 1
if li>= 0:
if li%2 == 0:
count += w1[li]
else:
count += w2[li]
dic[x] = count
print(count)
return 0
if n-ri == ri-li+1:
count = w[-1]-w[ri-1]
li -= 2
if li>= 0:
if li%2 == 0:
count += w1[li]
else:
count += w2[li]
dic[x] = count
print(count)
return 0
if A[ri-1] == x+m:
ri2 = ri-1
if n-ri2 == ri2-li:
count = w[-1]-w[ri2-1]
li -= 1
if li>= 0:
if li%2 == 0:
count += w1[li]
else:
count += w2[li]
dic[x] = count
print(count)
return 0
elif n-ri2 == ri2-li+1:
count = w[-1]-w[ri2-1]
li -= 2
if li>= 0:
if li%2 == 0:
count += w1[li]
else:
count += w2[li]
dic[x] = count
print(count)
return 0
if 2*ri > n+li:
r = m
else:
l = m
count = max(w1[-1],w2[-1])
dic[x] = count
print(count)
return
for _ in range(q):
x = int(eval(input()))
solve(x)
| n,q = list(map(int,input().split()))
A = list(map(int,input().split()))
w = [A[0]]
for i in range(1,n):
w.append(w[-1]+A[i])
w1 = [0]*n
for i in range(n):
if (n-1-i)%2 == 0:
w1[i] = A[i]
if i > 0:
w1[i] += w1[i-1]
def solve(x):
l = 0
r = n+1
while r-l > 1:
m = (r+l)//2
if A[n-m] <= x:
r = m
else:
if 2*m-1 > n:
r = m
else:
if A[n-m]-x >= x-A[n-2*m+1]:
l = m
else:
r = m
ans = w[-1]-w[n-l-1]
if n-2*l-1 >= 0:
ans += w1[n-2*l-1]
print(ans)
for _ in range(q):
solve(int(eval(input()))) | 95 | 37 | 2,312 | 724 | import bisect
n, q = list(map(int, input().split()))
A = list(map(int, input().split()))
dic = {}
w = [A[0]]
for i in range(1, n):
w.append(w[-1] + A[i])
w1 = [A[0], 0]
w2 = [0, A[1]]
for i in range(2, n):
if i % 2 == 0:
w1.append(w1[-2] + A[i])
w2.append(0)
else:
w2.append(w2[-2] + A[i])
w1.append(0)
def solve(x):
if x in dic:
print((dic[x]))
return
if x >= A[-1]:
count = max(w1[-1], w2[-1])
dic[x] = count
print(count)
return
l = 0
r = 10**10
while r > l + 1:
m = (r + l) // 2
li = bisect.bisect_left(A, x - m)
ri = bisect.bisect_right(A, x + m)
if n - ri == ri - li:
count = w[-1] - w[ri - 1]
li -= 1
if li >= 0:
if li % 2 == 0:
count += w1[li]
else:
count += w2[li]
dic[x] = count
print(count)
return 0
if n - ri == ri - li + 1:
count = w[-1] - w[ri - 1]
li -= 2
if li >= 0:
if li % 2 == 0:
count += w1[li]
else:
count += w2[li]
dic[x] = count
print(count)
return 0
if A[ri - 1] == x + m:
ri2 = ri - 1
if n - ri2 == ri2 - li:
count = w[-1] - w[ri2 - 1]
li -= 1
if li >= 0:
if li % 2 == 0:
count += w1[li]
else:
count += w2[li]
dic[x] = count
print(count)
return 0
elif n - ri2 == ri2 - li + 1:
count = w[-1] - w[ri2 - 1]
li -= 2
if li >= 0:
if li % 2 == 0:
count += w1[li]
else:
count += w2[li]
dic[x] = count
print(count)
return 0
if 2 * ri > n + li:
r = m
else:
l = m
count = max(w1[-1], w2[-1])
dic[x] = count
print(count)
return
for _ in range(q):
x = int(eval(input()))
solve(x)
| n, q = list(map(int, input().split()))
A = list(map(int, input().split()))
w = [A[0]]
for i in range(1, n):
w.append(w[-1] + A[i])
w1 = [0] * n
for i in range(n):
if (n - 1 - i) % 2 == 0:
w1[i] = A[i]
if i > 0:
w1[i] += w1[i - 1]
def solve(x):
l = 0
r = n + 1
while r - l > 1:
m = (r + l) // 2
if A[n - m] <= x:
r = m
else:
if 2 * m - 1 > n:
r = m
else:
if A[n - m] - x >= x - A[n - 2 * m + 1]:
l = m
else:
r = m
ans = w[-1] - w[n - l - 1]
if n - 2 * l - 1 >= 0:
ans += w1[n - 2 * l - 1]
print(ans)
for _ in range(q):
solve(int(eval(input())))
| false | 61.052632 | [
"-import bisect",
"-",
"-dic = {}",
"-w1 = [A[0], 0]",
"-w2 = [0, A[1]]",
"-for i in range(2, n):",
"- if i % 2 == 0:",
"- w1.append(w1[-2] + A[i])",
"- w2.append(0)",
"- else:",
"- w2.append(w2[-2] + A[i])",
"- w1.append(0)",
"+w1 = [0] * n",
"+for i in range(n):",
"+ if (n - 1 - i) % 2 == 0:",
"+ w1[i] = A[i]",
"+ if i > 0:",
"+ w1[i] += w1[i - 1]",
"- if x in dic:",
"- print((dic[x]))",
"- return",
"- if x >= A[-1]:",
"- count = max(w1[-1], w2[-1])",
"- dic[x] = count",
"- print(count)",
"- return",
"- r = 10**10",
"- while r > l + 1:",
"+ r = n + 1",
"+ while r - l > 1:",
"- li = bisect.bisect_left(A, x - m)",
"- ri = bisect.bisect_right(A, x + m)",
"- if n - ri == ri - li:",
"- count = w[-1] - w[ri - 1]",
"- li -= 1",
"- if li >= 0:",
"- if li % 2 == 0:",
"- count += w1[li]",
"- else:",
"- count += w2[li]",
"- dic[x] = count",
"- print(count)",
"- return 0",
"- if n - ri == ri - li + 1:",
"- count = w[-1] - w[ri - 1]",
"- li -= 2",
"- if li >= 0:",
"- if li % 2 == 0:",
"- count += w1[li]",
"- else:",
"- count += w2[li]",
"- dic[x] = count",
"- print(count)",
"- return 0",
"- if A[ri - 1] == x + m:",
"- ri2 = ri - 1",
"- if n - ri2 == ri2 - li:",
"- count = w[-1] - w[ri2 - 1]",
"- li -= 1",
"- if li >= 0:",
"- if li % 2 == 0:",
"- count += w1[li]",
"- else:",
"- count += w2[li]",
"- dic[x] = count",
"- print(count)",
"- return 0",
"- elif n - ri2 == ri2 - li + 1:",
"- count = w[-1] - w[ri2 - 1]",
"- li -= 2",
"- if li >= 0:",
"- if li % 2 == 0:",
"- count += w1[li]",
"- else:",
"- count += w2[li]",
"- dic[x] = count",
"- print(count)",
"- return 0",
"- if 2 * ri > n + li:",
"+ if A[n - m] <= x:",
"- l = m",
"- count = max(w1[-1], w2[-1])",
"- dic[x] = count",
"- print(count)",
"- return",
"+ if 2 * m - 1 > n:",
"+ r = m",
"+ else:",
"+ if A[n - m] - x >= x - A[n - 2 * m + 1]:",
"+ l = m",
"+ else:",
"+ r = m",
"+ ans = w[-1] - w[n - l - 1]",
"+ if n - 2 * l - 1 >= 0:",
"+ ans += w1[n - 2 * l - 1]",
"+ print(ans)",
"- x = int(eval(input()))",
"- solve(x)",
"+ solve(int(eval(input())))"
] | false | 0.04345 | 0.081681 | 0.531946 | [
"s549201732",
"s667072352"
] |
u864197622 | p02998 | python | s842920137 | s045061454 | 886 | 779 | 122,544 | 117,296 | Accepted | Accepted | 12.08 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
N = int(eval(input()))
K = 10**5+1
P = [i for i in range(K)]
def par(a):
if P[a] == a:
return a
t = par(P[a])
P[a] = t
return t
def cb(a, b):
pa = par(a)
pb = par(b)
if pa != pb:
P[pa] = pb
X = [[] for _ in range(K)]
Y = [[] for _ in range(K)]
for _ in range(N):
x, y = list(map(int, input().split()))
X[x-1].append(y-1)
Y[y-1].append(x-1)
for i in range(K):
for j in range(len(Y[i])-1):
cb(Y[i][j], Y[i][j+1])
M = [[] for _ in range(K)]
for i in range(K):
M[par(i)].append(i)
ans = -N
for i in range(K):
S = []
for j in M[i]:
for k in X[j]:
S.append(k)
S = list(set(S))
ans += len(S)*len(M[i])
print(ans) | import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
N = int(eval(input()))
K = 10**5+1
P = [i for i in range(K)]
def par(a):
if P[a] == a:
return a
t = par(P[a])
P[a] = t
return t
def cb(a, b):
P[par(b)] = par(a)
X = [[] for _ in range(K)]
Y = [[] for _ in range(K)]
for _ in range(N):
x, y = list(map(int, input().split()))
X[x-1].append(y-1)
Y[y-1].append(x-1)
for i in range(K):
for j in range(len(Y[i])-1):
cb(Y[i][j], Y[i][j+1])
M = [[] for _ in range(K)]
for i in range(K):
M[par(i)].append(i)
ans = -N
for i in range(K):
S = []
for j in M[i]:
for k in X[j]:
S.append(k)
S = list(set(S))
ans += len(S)*len(M[i])
print(ans)
| 41 | 38 | 813 | 766 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
N = int(eval(input()))
K = 10**5 + 1
P = [i for i in range(K)]
def par(a):
if P[a] == a:
return a
t = par(P[a])
P[a] = t
return t
def cb(a, b):
pa = par(a)
pb = par(b)
if pa != pb:
P[pa] = pb
X = [[] for _ in range(K)]
Y = [[] for _ in range(K)]
for _ in range(N):
x, y = list(map(int, input().split()))
X[x - 1].append(y - 1)
Y[y - 1].append(x - 1)
for i in range(K):
for j in range(len(Y[i]) - 1):
cb(Y[i][j], Y[i][j + 1])
M = [[] for _ in range(K)]
for i in range(K):
M[par(i)].append(i)
ans = -N
for i in range(K):
S = []
for j in M[i]:
for k in X[j]:
S.append(k)
S = list(set(S))
ans += len(S) * len(M[i])
print(ans)
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
N = int(eval(input()))
K = 10**5 + 1
P = [i for i in range(K)]
def par(a):
if P[a] == a:
return a
t = par(P[a])
P[a] = t
return t
def cb(a, b):
P[par(b)] = par(a)
X = [[] for _ in range(K)]
Y = [[] for _ in range(K)]
for _ in range(N):
x, y = list(map(int, input().split()))
X[x - 1].append(y - 1)
Y[y - 1].append(x - 1)
for i in range(K):
for j in range(len(Y[i]) - 1):
cb(Y[i][j], Y[i][j + 1])
M = [[] for _ in range(K)]
for i in range(K):
M[par(i)].append(i)
ans = -N
for i in range(K):
S = []
for j in M[i]:
for k in X[j]:
S.append(k)
S = list(set(S))
ans += len(S) * len(M[i])
print(ans)
| false | 7.317073 | [
"- pa = par(a)",
"- pb = par(b)",
"- if pa != pb:",
"- P[pa] = pb",
"+ P[par(b)] = par(a)"
] | false | 0.589823 | 0.969475 | 0.608394 | [
"s842920137",
"s045061454"
] |
u606878291 | p02881 | python | s450287939 | s271628871 | 201 | 115 | 3,064 | 3,316 | Accepted | Accepted | 42.79 | import math
def is_prime(q):
q = abs(q)
if q == 2: return True
if q < 2 or q & 1 == 0: return False
return pow(2, q - 1, q) == 1
def main(n):
if is_prime(n):
return n - 1
else:
sqrt = int(math.sqrt(n))
for i in range(sqrt, 1, -1):
div, mod = divmod(n, i)
if mod == 0:
return i + div - 2
if __name__ == '__main__':
N = int(eval(input()))
print((main(N)))
| def get_half_dividers(n):
return {i for i in range(1, int(n ** 0.5) + 1) if n % i == 0}
N = int(eval(input()))
dividers = get_half_dividers(N)
print((min([max(0, d - 1) + max(0, (N // d) - 1) for d in dividers])))
| 24 | 8 | 471 | 220 | import math
def is_prime(q):
q = abs(q)
if q == 2:
return True
if q < 2 or q & 1 == 0:
return False
return pow(2, q - 1, q) == 1
def main(n):
if is_prime(n):
return n - 1
else:
sqrt = int(math.sqrt(n))
for i in range(sqrt, 1, -1):
div, mod = divmod(n, i)
if mod == 0:
return i + div - 2
if __name__ == "__main__":
N = int(eval(input()))
print((main(N)))
| def get_half_dividers(n):
return {i for i in range(1, int(n**0.5) + 1) if n % i == 0}
N = int(eval(input()))
dividers = get_half_dividers(N)
print((min([max(0, d - 1) + max(0, (N // d) - 1) for d in dividers])))
| false | 66.666667 | [
"-import math",
"+def get_half_dividers(n):",
"+ return {i for i in range(1, int(n**0.5) + 1) if n % i == 0}",
"-def is_prime(q):",
"- q = abs(q)",
"- if q == 2:",
"- return True",
"- if q < 2 or q & 1 == 0:",
"- return False",
"- return pow(2, q - 1, q) == 1",
"-",
"-",
"-def main(n):",
"- if is_prime(n):",
"- return n - 1",
"- else:",
"- sqrt = int(math.sqrt(n))",
"- for i in range(sqrt, 1, -1):",
"- div, mod = divmod(n, i)",
"- if mod == 0:",
"- return i + div - 2",
"-",
"-",
"-if __name__ == \"__main__\":",
"- N = int(eval(input()))",
"- print((main(N)))",
"+N = int(eval(input()))",
"+dividers = get_half_dividers(N)",
"+print((min([max(0, d - 1) + max(0, (N // d) - 1) for d in dividers])))"
] | false | 0.036794 | 0.088025 | 0.417988 | [
"s450287939",
"s271628871"
] |
u879870653 | p03575 | python | s694078514 | s535514977 | 130 | 21 | 3,572 | 3,064 | Accepted | Accepted | 83.85 | from collections import deque
from copy import deepcopy
N,M = list(map(int,input().split()))
Matrix = [[False for x in range(N)] for y in range(N)]
Path = []
for i in range(M) :
a,b = list(map(int,input().split()))
a -= 1
b -= 1
Path.append((a,b))
Matrix[a][b] = True
Matrix[b][a] = True
ans = 0
for i in range(M) :
Matrix_duplicated = deepcopy(Matrix)
a,b = Path[i]
Matrix_duplicated[a][b] = False
Matrix_duplicated[b][a] = False
Visited = []
Queue = deque([0])
while Queue :
now = Queue.popleft()
Visited.append(now)
for i in range(N) :
if Matrix_duplicated[now][i] :
Matrix_duplicated[now][i] = False
Matrix_duplicated[i][now] = False
Queue.append(i)
if len(list(set(Visited))) != N :
ans += 1
print(ans)
| class UnionFind:
def __init__(self, num):
self.rank = [0] * num
self.par = [i for i in range(num)]
self.n = num
def find_root(self, node):
if self.par[node] == node:
return node
else:
self.par[node] = self.find_root(self.par[node])
return self.par[node]
def same_root(self, x, y):
return self.find_root(x) == self.find_root(y)
def union(self, x, y):
x = self.find_root(x)
y = self.find_root(y)
if x == y:
return
if self.rank[x] > self.rank[y]:
self.par[y] = x
else:
self.par[x] = y
if self.rank[x] == self.rank[y]:
self.rank[y] += 1
def main():
N, M = list(map(int, input().split()))
L = [list(map(int,input().split())) for i in range(M)]
for i in range(M) :
L[i][0] -= 1
L[i][1] -= 1
ans = 0
for i in range(M) :
UF = UnionFind(N)
for j in range(M) :
if j == i :
continue
UF.union(L[j][0], L[j][1])
ans += (UF.same_root(L[i][0], L[i][1]) == False)
print(ans)
import sys
input = sys.stdin.readline
if __name__ == "__main__":
main()
| 34 | 54 | 880 | 1,321 | from collections import deque
from copy import deepcopy
N, M = list(map(int, input().split()))
Matrix = [[False for x in range(N)] for y in range(N)]
Path = []
for i in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
Path.append((a, b))
Matrix[a][b] = True
Matrix[b][a] = True
ans = 0
for i in range(M):
Matrix_duplicated = deepcopy(Matrix)
a, b = Path[i]
Matrix_duplicated[a][b] = False
Matrix_duplicated[b][a] = False
Visited = []
Queue = deque([0])
while Queue:
now = Queue.popleft()
Visited.append(now)
for i in range(N):
if Matrix_duplicated[now][i]:
Matrix_duplicated[now][i] = False
Matrix_duplicated[i][now] = False
Queue.append(i)
if len(list(set(Visited))) != N:
ans += 1
print(ans)
| class UnionFind:
def __init__(self, num):
self.rank = [0] * num
self.par = [i for i in range(num)]
self.n = num
def find_root(self, node):
if self.par[node] == node:
return node
else:
self.par[node] = self.find_root(self.par[node])
return self.par[node]
def same_root(self, x, y):
return self.find_root(x) == self.find_root(y)
def union(self, x, y):
x = self.find_root(x)
y = self.find_root(y)
if x == y:
return
if self.rank[x] > self.rank[y]:
self.par[y] = x
else:
self.par[x] = y
if self.rank[x] == self.rank[y]:
self.rank[y] += 1
def main():
N, M = list(map(int, input().split()))
L = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
L[i][0] -= 1
L[i][1] -= 1
ans = 0
for i in range(M):
UF = UnionFind(N)
for j in range(M):
if j == i:
continue
UF.union(L[j][0], L[j][1])
ans += UF.same_root(L[i][0], L[i][1]) == False
print(ans)
import sys
input = sys.stdin.readline
if __name__ == "__main__":
main()
| false | 37.037037 | [
"-from collections import deque",
"-from copy import deepcopy",
"+class UnionFind:",
"+ def __init__(self, num):",
"+ self.rank = [0] * num",
"+ self.par = [i for i in range(num)]",
"+ self.n = num",
"-N, M = list(map(int, input().split()))",
"-Matrix = [[False for x in range(N)] for y in range(N)]",
"-Path = []",
"-for i in range(M):",
"- a, b = list(map(int, input().split()))",
"- a -= 1",
"- b -= 1",
"- Path.append((a, b))",
"- Matrix[a][b] = True",
"- Matrix[b][a] = True",
"-ans = 0",
"-for i in range(M):",
"- Matrix_duplicated = deepcopy(Matrix)",
"- a, b = Path[i]",
"- Matrix_duplicated[a][b] = False",
"- Matrix_duplicated[b][a] = False",
"- Visited = []",
"- Queue = deque([0])",
"- while Queue:",
"- now = Queue.popleft()",
"- Visited.append(now)",
"- for i in range(N):",
"- if Matrix_duplicated[now][i]:",
"- Matrix_duplicated[now][i] = False",
"- Matrix_duplicated[i][now] = False",
"- Queue.append(i)",
"- if len(list(set(Visited))) != N:",
"- ans += 1",
"-print(ans)",
"+ def find_root(self, node):",
"+ if self.par[node] == node:",
"+ return node",
"+ else:",
"+ self.par[node] = self.find_root(self.par[node])",
"+ return self.par[node]",
"+",
"+ def same_root(self, x, y):",
"+ return self.find_root(x) == self.find_root(y)",
"+",
"+ def union(self, x, y):",
"+ x = self.find_root(x)",
"+ y = self.find_root(y)",
"+ if x == y:",
"+ return",
"+ if self.rank[x] > self.rank[y]:",
"+ self.par[y] = x",
"+ else:",
"+ self.par[x] = y",
"+ if self.rank[x] == self.rank[y]:",
"+ self.rank[y] += 1",
"+",
"+",
"+def main():",
"+ N, M = list(map(int, input().split()))",
"+ L = [list(map(int, input().split())) for i in range(M)]",
"+ for i in range(M):",
"+ L[i][0] -= 1",
"+ L[i][1] -= 1",
"+ ans = 0",
"+ for i in range(M):",
"+ UF = UnionFind(N)",
"+ for j in range(M):",
"+ if j == i:",
"+ continue",
"+ UF.union(L[j][0], L[j][1])",
"+ ans += UF.same_root(L[i][0], L[i][1]) == False",
"+ print(ans)",
"+",
"+",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.079469 | 0.082999 | 0.957473 | [
"s694078514",
"s535514977"
] |
u981332890 | p02812 | python | s059774432 | s589702268 | 271 | 17 | 18,756 | 2,940 | Accepted | Accepted | 93.73 | import numpy as np
def main():
N = int(eval(input()))
S = eval(input())
print((S.count("ABC")))
return 0
if __name__ == '__main__':
main() | N = int(eval(input()))
S = eval(input())
ans = 0
for i in range(N-2):
if S[i:i+3] == "ABC":
ans += 1
print(ans)
| 12 | 9 | 159 | 122 | import numpy as np
def main():
N = int(eval(input()))
S = eval(input())
print((S.count("ABC")))
return 0
if __name__ == "__main__":
main()
| N = int(eval(input()))
S = eval(input())
ans = 0
for i in range(N - 2):
if S[i : i + 3] == "ABC":
ans += 1
print(ans)
| false | 25 | [
"-import numpy as np",
"-",
"-",
"-def main():",
"- N = int(eval(input()))",
"- S = eval(input())",
"- print((S.count(\"ABC\")))",
"- return 0",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+N = int(eval(input()))",
"+S = eval(input())",
"+ans = 0",
"+for i in range(N - 2):",
"+ if S[i : i + 3] == \"ABC\":",
"+ ans += 1",
"+print(ans)"
] | false | 0.07151 | 0.039717 | 1.800496 | [
"s059774432",
"s589702268"
] |
u102461423 | p03580 | python | s941731230 | s199670444 | 294 | 204 | 8,360 | 8,360 | Accepted | Accepted | 30.61 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = readline().rstrip().decode('utf-8')
def solve_partial(S):
INF = 10**18
"""
・Sは1から始まり、1で終わる
・Sは00を含まない
・したがって、Sは1,01に分解可能
・残る最小個数を調べるdp。これは、1, 101111,111101 の3種を数えることと同じ
・a, b0cccc, dddd0e として、「現在の1がどれであるか -> 最小個数」でdp
・個数はa,b,eのときに数える
"""
S = S.replace('01','2')
a,b,c,d,e = 1,1,INF,0,INF
for x in S[1:]:
if x == '1':
a2 = min(a,c,e)+1
c2 = c
d2 = min(a,c,d,e)
e2 = INF
else:
a2 = min(a,c,e)+1
c2 = a
d2 = min(a,c,e)
e2 = d+1
a,c,d,e = a2,c2,d2,e2
return len(S)-min(a,c,e)
answer = 0
for x in S.split('00'):
x = x.strip('0')
if x:
answer += solve_partial(x)
print(answer) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = readline().rstrip().decode('utf-8')
def solve_partial(S):
INF = 10**18
"""
・Sは1から始まり、1で終わる
・Sは00を含まない
・したがって、Sは1,01に分解可能
・残る最小個数を調べるdp。これは、1, 101111,111101 の3種を数えることと同じ
・a, b0cccc, dddd0e として、「現在の1がどれであるか -> 最小個数」でdp
・個数はa,b,eのときに数える
"""
S = S.replace('01','2')
a,b,c,d,e = 1,1,INF,0,INF
for x in S[1:]:
ace = min(a,c,e)
if x == '1':
a2 = ace+1
c2 = c
d2 = ace if ace<d else d
e2 = INF
else:
a2 = ace+1
c2 = a
d2 = ace
e2 = d+1
a,c,d,e = a2,c2,d2,e2
return len(S)-min(a,c,e)
answer = 0
for x in S.split('00'):
x = x.strip('0')
if x:
answer += solve_partial(x)
print(answer) | 41 | 42 | 942 | 954 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = readline().rstrip().decode("utf-8")
def solve_partial(S):
INF = 10**18
"""
・Sは1から始まり、1で終わる
・Sは00を含まない
・したがって、Sは1,01に分解可能
・残る最小個数を調べるdp。これは、1, 101111,111101 の3種を数えることと同じ
・a, b0cccc, dddd0e として、「現在の1がどれであるか -> 最小個数」でdp
・個数はa,b,eのときに数える
"""
S = S.replace("01", "2")
a, b, c, d, e = 1, 1, INF, 0, INF
for x in S[1:]:
if x == "1":
a2 = min(a, c, e) + 1
c2 = c
d2 = min(a, c, d, e)
e2 = INF
else:
a2 = min(a, c, e) + 1
c2 = a
d2 = min(a, c, e)
e2 = d + 1
a, c, d, e = a2, c2, d2, e2
return len(S) - min(a, c, e)
answer = 0
for x in S.split("00"):
x = x.strip("0")
if x:
answer += solve_partial(x)
print(answer)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = readline().rstrip().decode("utf-8")
def solve_partial(S):
INF = 10**18
"""
・Sは1から始まり、1で終わる
・Sは00を含まない
・したがって、Sは1,01に分解可能
・残る最小個数を調べるdp。これは、1, 101111,111101 の3種を数えることと同じ
・a, b0cccc, dddd0e として、「現在の1がどれであるか -> 最小個数」でdp
・個数はa,b,eのときに数える
"""
S = S.replace("01", "2")
a, b, c, d, e = 1, 1, INF, 0, INF
for x in S[1:]:
ace = min(a, c, e)
if x == "1":
a2 = ace + 1
c2 = c
d2 = ace if ace < d else d
e2 = INF
else:
a2 = ace + 1
c2 = a
d2 = ace
e2 = d + 1
a, c, d, e = a2, c2, d2, e2
return len(S) - min(a, c, e)
answer = 0
for x in S.split("00"):
x = x.strip("0")
if x:
answer += solve_partial(x)
print(answer)
| false | 2.380952 | [
"+ ace = min(a, c, e)",
"- a2 = min(a, c, e) + 1",
"+ a2 = ace + 1",
"- d2 = min(a, c, d, e)",
"+ d2 = ace if ace < d else d",
"- a2 = min(a, c, e) + 1",
"+ a2 = ace + 1",
"- d2 = min(a, c, e)",
"+ d2 = ace"
] | false | 0.036919 | 0.037882 | 0.974572 | [
"s941731230",
"s199670444"
] |
u562935282 | p03546 | python | s474995457 | s618646645 | 38 | 30 | 3,316 | 3,316 | Accepted | Accepted | 21.05 | def warshall_floyd(cost):
# cost[i][j] : iからjへの最短距離
for k in range(10):
for i in range(10):
for j in range(10):
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
return cost
h, w = list(map(int, input().split()))
cost = [list(map(int, input().split())) for _ in range(10)]
a = tuple(tuple(map(int, input().split())) for _ in range(h))
cost = warshall_floyd(cost)
ans = 0
for r in range(h):
for c in range(w):
frm = a[r][c]
if frm == -1:
continue
ans += cost[frm][1]
print(ans)
| def main():
h, w = list(map(int, input().split()))
c = [[int(x) for x in input().split()] for _ in range(10)]
a = [[int(x) for x in input().split()] for _ in range(h)]
for k in range(10):
for i in range(10):
for j in range(10):
c[i][j] = min(c[i][j], c[i][k] + c[k][j])
ret = 0
for row in a:
for cell in row:
if ~cell:
ret += c[cell][1]
print(ret)
if __name__ == '__main__':
main()
| 23 | 22 | 589 | 509 | def warshall_floyd(cost):
# cost[i][j] : iからjへの最短距離
for k in range(10):
for i in range(10):
for j in range(10):
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
return cost
h, w = list(map(int, input().split()))
cost = [list(map(int, input().split())) for _ in range(10)]
a = tuple(tuple(map(int, input().split())) for _ in range(h))
cost = warshall_floyd(cost)
ans = 0
for r in range(h):
for c in range(w):
frm = a[r][c]
if frm == -1:
continue
ans += cost[frm][1]
print(ans)
| def main():
h, w = list(map(int, input().split()))
c = [[int(x) for x in input().split()] for _ in range(10)]
a = [[int(x) for x in input().split()] for _ in range(h)]
for k in range(10):
for i in range(10):
for j in range(10):
c[i][j] = min(c[i][j], c[i][k] + c[k][j])
ret = 0
for row in a:
for cell in row:
if ~cell:
ret += c[cell][1]
print(ret)
if __name__ == "__main__":
main()
| false | 4.347826 | [
"-def warshall_floyd(cost):",
"- # cost[i][j] : iからjへの最短距離",
"+def main():",
"+ h, w = list(map(int, input().split()))",
"+ c = [[int(x) for x in input().split()] for _ in range(10)]",
"+ a = [[int(x) for x in input().split()] for _ in range(h)]",
"- cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])",
"- return cost",
"+ c[i][j] = min(c[i][j], c[i][k] + c[k][j])",
"+ ret = 0",
"+ for row in a:",
"+ for cell in row:",
"+ if ~cell:",
"+ ret += c[cell][1]",
"+ print(ret)",
"-h, w = list(map(int, input().split()))",
"-cost = [list(map(int, input().split())) for _ in range(10)]",
"-a = tuple(tuple(map(int, input().split())) for _ in range(h))",
"-cost = warshall_floyd(cost)",
"-ans = 0",
"-for r in range(h):",
"- for c in range(w):",
"- frm = a[r][c]",
"- if frm == -1:",
"- continue",
"- ans += cost[frm][1]",
"-print(ans)",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.07509 | 0.034335 | 2.186966 | [
"s474995457",
"s618646645"
] |
u562935282 | p02802 | python | s590117745 | s487274478 | 289 | 135 | 3,828 | 4,596 | Accepted | Accepted | 53.29 | def solved(p):
return cwa[p] == -1
n, m = list(map(int, input().split()))
wa = 0
cwa = [0] * n
for _ in range(m):
p, s = input().split()
p = int(p) - 1
if solved(p):
continue
if s == 'AC':
wa += cwa[p]
cwa[p] = -1
else:
cwa[p] += 1
ac = cwa.count(-1)
print((ac, wa))
| def main():
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
ac = [False] * N
wa = [0] * N
for _ in range(M):
it = iter(input().split())
p = int(next(it)) - 1
s = next(it)
if s == 'AC':
ac[p] = True
else:
if not ac[p]:
wa[p] += 1
print((ac.count(True), sum(w for p, w in enumerate(wa) if ac[p])))
if __name__ == '__main__':
main()
| 21 | 22 | 339 | 488 | def solved(p):
return cwa[p] == -1
n, m = list(map(int, input().split()))
wa = 0
cwa = [0] * n
for _ in range(m):
p, s = input().split()
p = int(p) - 1
if solved(p):
continue
if s == "AC":
wa += cwa[p]
cwa[p] = -1
else:
cwa[p] += 1
ac = cwa.count(-1)
print((ac, wa))
| def main():
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
ac = [False] * N
wa = [0] * N
for _ in range(M):
it = iter(input().split())
p = int(next(it)) - 1
s = next(it)
if s == "AC":
ac[p] = True
else:
if not ac[p]:
wa[p] += 1
print((ac.count(True), sum(w for p, w in enumerate(wa) if ac[p])))
if __name__ == "__main__":
main()
| false | 4.545455 | [
"-def solved(p):",
"- return cwa[p] == -1",
"+def main():",
"+ import sys",
"+",
"+ input = sys.stdin.readline",
"+ N, M = list(map(int, input().split()))",
"+ ac = [False] * N",
"+ wa = [0] * N",
"+ for _ in range(M):",
"+ it = iter(input().split())",
"+ p = int(next(it)) - 1",
"+ s = next(it)",
"+ if s == \"AC\":",
"+ ac[p] = True",
"+ else:",
"+ if not ac[p]:",
"+ wa[p] += 1",
"+ print((ac.count(True), sum(w for p, w in enumerate(wa) if ac[p])))",
"-n, m = list(map(int, input().split()))",
"-wa = 0",
"-cwa = [0] * n",
"-for _ in range(m):",
"- p, s = input().split()",
"- p = int(p) - 1",
"- if solved(p):",
"- continue",
"- if s == \"AC\":",
"- wa += cwa[p]",
"- cwa[p] = -1",
"- else:",
"- cwa[p] += 1",
"-ac = cwa.count(-1)",
"-print((ac, wa))",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.048312 | 0.051947 | 0.930027 | [
"s590117745",
"s487274478"
] |
u655975843 | p03112 | python | s507760358 | s077719739 | 1,080 | 665 | 16,380 | 16,364 | Accepted | Accepted | 38.43 | import bisect
a, b, q = list(map(int, input().split()))
INF = 10 ** 18
s = [-INF] + [int(eval(input())) for i in range(a)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(b)] + [INF]
ans = []
for i in range(q):
x = int(eval(input()))
idxs = bisect.bisect(s, x)
idxt = bisect.bisect(t, x)
lis = []
lis.append(x - min(s[idxs - 1], t[idxt -1]))
lis.append(x - s[idxs - 1] + (t[idxt] - s[idxs - 1]))
lis.append(t[idxt] - x + (t[idxt] - s[idxs - 1]))
lis.append(x - t[idxt - 1] + (s[idxs] - t[idxt - 1]))
lis.append(s[idxs] - x + (s[idxs] - t[idxt - 1]))
lis.append(max(s[idxs], t[idxt]) - x)
ans.append(min(lis))
for i in range(q):
print((ans[i]))
| import bisect
import sys
input = sys.stdin.readline
a, b, q = list(map(int, input().split()))
INF = 10 ** 18
s = [-INF] + [int(eval(input())) for i in range(a)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(b)] + [INF]
ans = []
for i in range(q):
x = int(eval(input()))
idxs = bisect.bisect(s, x)
idxt = bisect.bisect(t, x)
lis = []
lis.append(x - min(s[idxs - 1], t[idxt -1]))
lis.append(x - s[idxs - 1] + (t[idxt] - s[idxs - 1]))
lis.append(t[idxt] - x + (t[idxt] - s[idxs - 1]))
lis.append(x - t[idxt - 1] + (s[idxs] - t[idxt - 1]))
lis.append(s[idxs] - x + (s[idxs] - t[idxt - 1]))
lis.append(max(s[idxs], t[idxt]) - x)
ans.append(min(lis))
for i in range(q):
print((ans[i]))
| 24 | 25 | 701 | 739 | import bisect
a, b, q = list(map(int, input().split()))
INF = 10**18
s = [-INF] + [int(eval(input())) for i in range(a)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(b)] + [INF]
ans = []
for i in range(q):
x = int(eval(input()))
idxs = bisect.bisect(s, x)
idxt = bisect.bisect(t, x)
lis = []
lis.append(x - min(s[idxs - 1], t[idxt - 1]))
lis.append(x - s[idxs - 1] + (t[idxt] - s[idxs - 1]))
lis.append(t[idxt] - x + (t[idxt] - s[idxs - 1]))
lis.append(x - t[idxt - 1] + (s[idxs] - t[idxt - 1]))
lis.append(s[idxs] - x + (s[idxs] - t[idxt - 1]))
lis.append(max(s[idxs], t[idxt]) - x)
ans.append(min(lis))
for i in range(q):
print((ans[i]))
| import bisect
import sys
input = sys.stdin.readline
a, b, q = list(map(int, input().split()))
INF = 10**18
s = [-INF] + [int(eval(input())) for i in range(a)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(b)] + [INF]
ans = []
for i in range(q):
x = int(eval(input()))
idxs = bisect.bisect(s, x)
idxt = bisect.bisect(t, x)
lis = []
lis.append(x - min(s[idxs - 1], t[idxt - 1]))
lis.append(x - s[idxs - 1] + (t[idxt] - s[idxs - 1]))
lis.append(t[idxt] - x + (t[idxt] - s[idxs - 1]))
lis.append(x - t[idxt - 1] + (s[idxs] - t[idxt - 1]))
lis.append(s[idxs] - x + (s[idxs] - t[idxt - 1]))
lis.append(max(s[idxs], t[idxt]) - x)
ans.append(min(lis))
for i in range(q):
print((ans[i]))
| false | 4 | [
"+import sys",
"+input = sys.stdin.readline"
] | false | 0.037661 | 0.047708 | 0.789399 | [
"s507760358",
"s077719739"
] |
u594862874 | p02813 | python | s499979024 | s412324987 | 44 | 27 | 15,140 | 8,052 | Accepted | Accepted | 38.64 | import itertools
import math
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
L = list(map(list,list(itertools.permutations(list(i for i in range(1,N+1)),N))))
a = L.index(P)
b = L.index(Q)
print((abs(a-b))) | from itertools import permutations
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
perm = list(permutations(list(range(1, N+1)), N))
print((abs(perm.index(P) - perm.index(Q)))) | 9 | 8 | 253 | 221 | import itertools
import math
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
L = list(map(list, list(itertools.permutations(list(i for i in range(1, N + 1)), N))))
a = L.index(P)
b = L.index(Q)
print((abs(a - b)))
| from itertools import permutations
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
perm = list(permutations(list(range(1, N + 1)), N))
print((abs(perm.index(P) - perm.index(Q))))
| false | 11.111111 | [
"-import itertools",
"-import math",
"+from itertools import permutations",
"-P = list(map(int, input().split()))",
"-Q = list(map(int, input().split()))",
"-L = list(map(list, list(itertools.permutations(list(i for i in range(1, N + 1)), N))))",
"-a = L.index(P)",
"-b = L.index(Q)",
"-print((abs(a - b)))",
"+P = tuple(map(int, input().split()))",
"+Q = tuple(map(int, input().split()))",
"+perm = list(permutations(list(range(1, N + 1)), N))",
"+print((abs(perm.index(P) - perm.index(Q))))"
] | false | 0.038884 | 0.035143 | 1.106452 | [
"s499979024",
"s412324987"
] |
u968166680 | p02839 | python | s908023337 | s340523971 | 1,342 | 179 | 227,308 | 93,700 | Accepted | Accepted | 86.66 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
A = [list(map(int, readline().split())) for _ in range(H)]
B = [list(map(int, readline().split())) for _ in range(H)]
G = [[0] * W for _ in range(H)]
for i in range(H):
for j in range(W):
G[i][j] = abs(A[i][j] - B[i][j])
dp = [set() for j in range(W)]
dp[0].add(G[0][0])
for i in range(H):
for j in range(W):
if i == 0 and j == 0:
continue
s = set()
b = G[i][j]
if i > 0:
for k in dp[j]:
s.add(k + b)
s.add(abs(k - b))
if j > 0:
for k in dp[j - 1]:
s.add(k + b)
s.add(abs(k - b))
dp[j] = s
print((min(dp[W - 1])))
return
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
A = [list(map(int, readline().split())) for _ in range(H)]
B = [list(map(int, readline().split())) for _ in range(H)]
M = 0
G = [[0] * W for _ in range(H)]
for i in range(H):
for j in range(W):
G[i][j] = abs(A[i][j] - B[i][j])
if M < G[i][j]:
M = G[i][j]
M = 20000
dp = [[0] * W for _ in range(H)]
dp[0][0] = 1 << (M + G[0][0]) | 1 << (M - G[0][0])
for i in range(H):
for j in range(W):
if i + 1 < H:
dp[i + 1][j] |= (dp[i][j] >> G[i + 1][j]) | (dp[i][j] << G[i + 1][j])
if j + 1 < W:
dp[i][j + 1] |= (dp[i][j] >> G[i][j + 1]) | (dp[i][j] << G[i][j + 1])
ans = INF
for i in range(2 * M + 2):
if dp[H - 1][W - 1] >> i & 1 and ans > abs(i - M):
ans = abs(i - M)
print(ans)
return
if __name__ == '__main__':
main()
| 45 | 45 | 1,083 | 1,163 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
A = [list(map(int, readline().split())) for _ in range(H)]
B = [list(map(int, readline().split())) for _ in range(H)]
G = [[0] * W for _ in range(H)]
for i in range(H):
for j in range(W):
G[i][j] = abs(A[i][j] - B[i][j])
dp = [set() for j in range(W)]
dp[0].add(G[0][0])
for i in range(H):
for j in range(W):
if i == 0 and j == 0:
continue
s = set()
b = G[i][j]
if i > 0:
for k in dp[j]:
s.add(k + b)
s.add(abs(k - b))
if j > 0:
for k in dp[j - 1]:
s.add(k + b)
s.add(abs(k - b))
dp[j] = s
print((min(dp[W - 1])))
return
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
A = [list(map(int, readline().split())) for _ in range(H)]
B = [list(map(int, readline().split())) for _ in range(H)]
M = 0
G = [[0] * W for _ in range(H)]
for i in range(H):
for j in range(W):
G[i][j] = abs(A[i][j] - B[i][j])
if M < G[i][j]:
M = G[i][j]
M = 20000
dp = [[0] * W for _ in range(H)]
dp[0][0] = 1 << (M + G[0][0]) | 1 << (M - G[0][0])
for i in range(H):
for j in range(W):
if i + 1 < H:
dp[i + 1][j] |= (dp[i][j] >> G[i + 1][j]) | (dp[i][j] << G[i + 1][j])
if j + 1 < W:
dp[i][j + 1] |= (dp[i][j] >> G[i][j + 1]) | (dp[i][j] << G[i][j + 1])
ans = INF
for i in range(2 * M + 2):
if dp[H - 1][W - 1] >> i & 1 and ans > abs(i - M):
ans = abs(i - M)
print(ans)
return
if __name__ == "__main__":
main()
| false | 0 | [
"+ M = 0",
"- dp = [set() for j in range(W)]",
"- dp[0].add(G[0][0])",
"+ if M < G[i][j]:",
"+ M = G[i][j]",
"+ M = 20000",
"+ dp = [[0] * W for _ in range(H)]",
"+ dp[0][0] = 1 << (M + G[0][0]) | 1 << (M - G[0][0])",
"- if i == 0 and j == 0:",
"- continue",
"- s = set()",
"- b = G[i][j]",
"- if i > 0:",
"- for k in dp[j]:",
"- s.add(k + b)",
"- s.add(abs(k - b))",
"- if j > 0:",
"- for k in dp[j - 1]:",
"- s.add(k + b)",
"- s.add(abs(k - b))",
"- dp[j] = s",
"- print((min(dp[W - 1])))",
"+ if i + 1 < H:",
"+ dp[i + 1][j] |= (dp[i][j] >> G[i + 1][j]) | (dp[i][j] << G[i + 1][j])",
"+ if j + 1 < W:",
"+ dp[i][j + 1] |= (dp[i][j] >> G[i][j + 1]) | (dp[i][j] << G[i][j + 1])",
"+ ans = INF",
"+ for i in range(2 * M + 2):",
"+ if dp[H - 1][W - 1] >> i & 1 and ans > abs(i - M):",
"+ ans = abs(i - M)",
"+ print(ans)"
] | false | 0.036759 | 0.059422 | 0.618598 | [
"s908023337",
"s340523971"
] |
u729133443 | p02616 | python | s626241605 | s594520542 | 174 | 160 | 31,680 | 112,196 | Accepted | Accepted | 8.05 | n,k,*a=list(map(int,open(i:=0).read().split()))
a.sort()
p=a.pop
s=b=~k%2or p()
while k>1:
if(x:=a[i]*a[i+1])*b>a[-1]*a[-2]*b:s*=x;i+=2
else:s*=p()*p()
s%=10**9+7;k-=2
print(s) | n,k,*a=list(map(int,open(0).read().split()))
a.sort()
p=a.pop
s=b=~k%2or p()
i=0
while k>1:
x=a[i]*a[i+1]
if x*b>a[-1]*a[-2]*b:s*=x;i+=2
else:s*=p()*p()
s%=10**9+7;k-=2
print(s) | 9 | 11 | 181 | 185 | n, k, *a = list(map(int, open(i := 0).read().split()))
a.sort()
p = a.pop
s = b = ~k % 2 or p()
while k > 1:
if (x := a[i] * a[i + 1]) * b > a[-1] * a[-2] * b:
s *= x
i += 2
else:
s *= p() * p()
s %= 10**9 + 7
k -= 2
print(s)
| n, k, *a = list(map(int, open(0).read().split()))
a.sort()
p = a.pop
s = b = ~k % 2 or p()
i = 0
while k > 1:
x = a[i] * a[i + 1]
if x * b > a[-1] * a[-2] * b:
s *= x
i += 2
else:
s *= p() * p()
s %= 10**9 + 7
k -= 2
print(s)
| false | 18.181818 | [
"-n, k, *a = list(map(int, open(i := 0).read().split()))",
"+n, k, *a = list(map(int, open(0).read().split()))",
"+i = 0",
"- if (x := a[i] * a[i + 1]) * b > a[-1] * a[-2] * b:",
"+ x = a[i] * a[i + 1]",
"+ if x * b > a[-1] * a[-2] * b:"
] | false | 0.033194 | 0.059487 | 0.557999 | [
"s626241605",
"s594520542"
] |
u466331465 | p02814 | python | s150184395 | s591072497 | 471 | 415 | 89,580 | 89,580 | Accepted | Accepted | 11.89 | import fractions
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
N,M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
a = 1
MOD = 10**9+7
cnt = 0
l = 0
for i in A:
i = i//2
a = lcm(a,i)
for i in A:
cnt1=0
i=i//2
b=a//i
if b%2==0:
while b%2==0:
b=b/2
cnt1+=1
if cnt==0:
cnt=cnt1
l+=1
else:
if cnt!=cnt1:
print((0))
exit()
if l==N and cnt!=0:
print((0))
exit()
print(((M//a+2-1)//2)) | import fractions
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
N,M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
a = 1
MOD = 10**9+7
cnt = 10**9
l = 0
for i in A:
i = i//2
a = lcm(a,i)
for i in A:
cnt1=0
b=i//2
if b%2==0:
while b%2==0:
b=b/2
cnt1+=1
if cnt==10**9:
cnt=cnt1
elif cnt!=cnt1:
print((0))
exit()
print(((M//a+2-1)//2))
| 31 | 25 | 499 | 432 | import fractions
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
a = 1
MOD = 10**9 + 7
cnt = 0
l = 0
for i in A:
i = i // 2
a = lcm(a, i)
for i in A:
cnt1 = 0
i = i // 2
b = a // i
if b % 2 == 0:
while b % 2 == 0:
b = b / 2
cnt1 += 1
if cnt == 0:
cnt = cnt1
l += 1
else:
if cnt != cnt1:
print((0))
exit()
if l == N and cnt != 0:
print((0))
exit()
print(((M // a + 2 - 1) // 2))
| import fractions
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
a = 1
MOD = 10**9 + 7
cnt = 10**9
l = 0
for i in A:
i = i // 2
a = lcm(a, i)
for i in A:
cnt1 = 0
b = i // 2
if b % 2 == 0:
while b % 2 == 0:
b = b / 2
cnt1 += 1
if cnt == 10**9:
cnt = cnt1
elif cnt != cnt1:
print((0))
exit()
print(((M // a + 2 - 1) // 2))
| false | 19.354839 | [
"-cnt = 0",
"+cnt = 10**9",
"- i = i // 2",
"- b = a // i",
"+ b = i // 2",
"- if cnt == 0:",
"+ if cnt == 10**9:",
"- l += 1",
"- else:",
"- if cnt != cnt1:",
"- print((0))",
"- exit()",
"-if l == N and cnt != 0:",
"- print((0))",
"- exit()",
"+ elif cnt != cnt1:",
"+ print((0))",
"+ exit()"
] | false | 0.082552 | 0.088251 | 0.935425 | [
"s150184395",
"s591072497"
] |
u864197622 | p02710 | python | s346924926 | s277726801 | 449 | 330 | 137,848 | 116,672 | Accepted | Accepted | 26.5 | import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
C = [int(a) - 1 for a in input().split()]
X = [[] for i in range(N)]
for i in range(N-1):
x, y = map(int, input().split())
X[x-1].append(y-1)
X[y-1].append(x-1)
def EulerTour(n, X, i0):
f = lambda k: k * (k + 1) // 2
USED = [0] * n
ORG = [0] * n
TMP = [0] * n
P = [-1] * n
ct = -1
ET1 = [0] * n
ET2 = [0] * n
ANS = [f(n)] * n
IND = [len(x) for x in X]
i = i0
while i >= 0:
ind = IND[i]
if not ind:
ET2[i] = ct
USED[C[i]] += 1 + TMP[i]
if i:
k = ET2[i] - ET1[i] + 1 - USED[C[P[i]]] + ORG[i]
ANS[C[P[i]]] -= f(k)
TMP[P[i]] += k
i = P[i]
continue
j = X[i][ind - 1]
if P[i] == j:
IND[i] -= 1
continue
P[j] = i
IND[i] -= 1
i = j
ORG[i] = USED[C[P[i]]]
ct += 1
ET1[i] = ct
for i in range(n):
ANS[i] -= f(n - USED[i])
return ANS
print(*EulerTour(N, X, 0), sep = "\n")
| import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
C = [int(a) - 1 for a in input().split()]
X = [[] for i in range(N)]
head = [-1] * (N + 1)
to = [0] * (N - 1 << 1)
nxt = [0] * (N - 1 << 1)
for i in range(N-1):
x, y = map(int, input().split())
x, y = x-1, y-1
nxt[i] = head[x]
to[i] = y
head[x] = i
j = i + N - 1
nxt[j] = head[y]
to[j] = x
head[y] = j
def EulerTour(n, i=0):
f = lambda k: k * (k + 1) // 2
USED = [0] * n
ORG = [0] * n
TMP = [0] * n
ANS = [f(n)] * n
P = [-1] * n
ct = 0
ET1 = [0] * n
ET2 = [0] * n
while i >= 0:
e = head[i]
if e < 0:
ET2[i] = ct
USED[C[i]] += 1 + TMP[i]
if i:
k = ET2[i] - ET1[i] + 1 - USED[C[P[i]]] + ORG[i]
ANS[C[P[i]]] -= f(k)
TMP[P[i]] += k
i = P[i]
continue
j = to[e]
if P[i] == j:
head[i] = nxt[e]
continue
P[j] = i
head[i] = nxt[e]
i = j
ORG[i] = USED[C[P[i]]]
ct += 1
ET1[i] = ct
for i in range(n):
ANS[i] -= f(n - USED[i])
return ANS
print(*EulerTour(N, 0), sep = "\n")
| 51 | 59 | 1,197 | 1,327 | import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
C = [int(a) - 1 for a in input().split()]
X = [[] for i in range(N)]
for i in range(N - 1):
x, y = map(int, input().split())
X[x - 1].append(y - 1)
X[y - 1].append(x - 1)
def EulerTour(n, X, i0):
f = lambda k: k * (k + 1) // 2
USED = [0] * n
ORG = [0] * n
TMP = [0] * n
P = [-1] * n
ct = -1
ET1 = [0] * n
ET2 = [0] * n
ANS = [f(n)] * n
IND = [len(x) for x in X]
i = i0
while i >= 0:
ind = IND[i]
if not ind:
ET2[i] = ct
USED[C[i]] += 1 + TMP[i]
if i:
k = ET2[i] - ET1[i] + 1 - USED[C[P[i]]] + ORG[i]
ANS[C[P[i]]] -= f(k)
TMP[P[i]] += k
i = P[i]
continue
j = X[i][ind - 1]
if P[i] == j:
IND[i] -= 1
continue
P[j] = i
IND[i] -= 1
i = j
ORG[i] = USED[C[P[i]]]
ct += 1
ET1[i] = ct
for i in range(n):
ANS[i] -= f(n - USED[i])
return ANS
print(*EulerTour(N, X, 0), sep="\n")
| import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
C = [int(a) - 1 for a in input().split()]
X = [[] for i in range(N)]
head = [-1] * (N + 1)
to = [0] * (N - 1 << 1)
nxt = [0] * (N - 1 << 1)
for i in range(N - 1):
x, y = map(int, input().split())
x, y = x - 1, y - 1
nxt[i] = head[x]
to[i] = y
head[x] = i
j = i + N - 1
nxt[j] = head[y]
to[j] = x
head[y] = j
def EulerTour(n, i=0):
f = lambda k: k * (k + 1) // 2
USED = [0] * n
ORG = [0] * n
TMP = [0] * n
ANS = [f(n)] * n
P = [-1] * n
ct = 0
ET1 = [0] * n
ET2 = [0] * n
while i >= 0:
e = head[i]
if e < 0:
ET2[i] = ct
USED[C[i]] += 1 + TMP[i]
if i:
k = ET2[i] - ET1[i] + 1 - USED[C[P[i]]] + ORG[i]
ANS[C[P[i]]] -= f(k)
TMP[P[i]] += k
i = P[i]
continue
j = to[e]
if P[i] == j:
head[i] = nxt[e]
continue
P[j] = i
head[i] = nxt[e]
i = j
ORG[i] = USED[C[P[i]]]
ct += 1
ET1[i] = ct
for i in range(n):
ANS[i] -= f(n - USED[i])
return ANS
print(*EulerTour(N, 0), sep="\n")
| false | 13.559322 | [
"+head = [-1] * (N + 1)",
"+to = [0] * (N - 1 << 1)",
"+nxt = [0] * (N - 1 << 1)",
"- X[x - 1].append(y - 1)",
"- X[y - 1].append(x - 1)",
"+ x, y = x - 1, y - 1",
"+ nxt[i] = head[x]",
"+ to[i] = y",
"+ head[x] = i",
"+ j = i + N - 1",
"+ nxt[j] = head[y]",
"+ to[j] = x",
"+ head[y] = j",
"-def EulerTour(n, X, i0):",
"+def EulerTour(n, i=0):",
"+ ANS = [f(n)] * n",
"- ct = -1",
"+ ct = 0",
"- ANS = [f(n)] * n",
"- IND = [len(x) for x in X]",
"- i = i0",
"- ind = IND[i]",
"- if not ind:",
"+ e = head[i]",
"+ if e < 0:",
"- j = X[i][ind - 1]",
"+ j = to[e]",
"- IND[i] -= 1",
"+ head[i] = nxt[e]",
"- IND[i] -= 1",
"+ head[i] = nxt[e]",
"-print(*EulerTour(N, X, 0), sep=\"\\n\")",
"+print(*EulerTour(N, 0), sep=\"\\n\")"
] | false | 0.060713 | 0.044029 | 1.378917 | [
"s346924926",
"s277726801"
] |
u238504302 | p02756 | python | s040586999 | s013691154 | 884 | 376 | 43,136 | 45,844 | Accepted | Accepted | 57.47 | S = eval(input())
Q = int(eval(input()))
Query = list(input().split() for _ in range(Q))
count = 0
L, R = "", ""
for i in range(Q):
if Query[i][0] == "1": count += 1
else:
if Query[i][1] == "1":
if count % 2 == 0: L = Query[i][2] + L
else: R += Query[i][2]
else:
if count % 2 == 0: R += Query[i][2]
else: L = Query[i][2] + L
if count % 2 == 0: print((L + S + R))
else: print((R[::-1] + S[::-1] + L[::-1])) | from queue import deque
S = eval(input())
Q = int(eval(input()))
Query = list(input().split() for _ in range(Q))
count = 0
L, R = deque(), deque()
for i in range(Q):
if Query[i][0] == "1": count += 1
else:
if Query[i][1] == "1":
if count % 2 == 0: L.appendleft(Query[i][2])
else: R.append(Query[i][2])
else:
if count % 2 == 0: R.append(Query[i][2])
else: L.appendleft(Query[i][2])
L, R = "".join(L), "".join(R)
if count % 2 == 0: print((L + S + R))
else: print((R[::-1] + S[::-1] + L[::-1])) | 19 | 20 | 446 | 532 | S = eval(input())
Q = int(eval(input()))
Query = list(input().split() for _ in range(Q))
count = 0
L, R = "", ""
for i in range(Q):
if Query[i][0] == "1":
count += 1
else:
if Query[i][1] == "1":
if count % 2 == 0:
L = Query[i][2] + L
else:
R += Query[i][2]
else:
if count % 2 == 0:
R += Query[i][2]
else:
L = Query[i][2] + L
if count % 2 == 0:
print((L + S + R))
else:
print((R[::-1] + S[::-1] + L[::-1]))
| from queue import deque
S = eval(input())
Q = int(eval(input()))
Query = list(input().split() for _ in range(Q))
count = 0
L, R = deque(), deque()
for i in range(Q):
if Query[i][0] == "1":
count += 1
else:
if Query[i][1] == "1":
if count % 2 == 0:
L.appendleft(Query[i][2])
else:
R.append(Query[i][2])
else:
if count % 2 == 0:
R.append(Query[i][2])
else:
L.appendleft(Query[i][2])
L, R = "".join(L), "".join(R)
if count % 2 == 0:
print((L + S + R))
else:
print((R[::-1] + S[::-1] + L[::-1]))
| false | 5 | [
"+from queue import deque",
"+",
"-L, R = \"\", \"\"",
"+L, R = deque(), deque()",
"- L = Query[i][2] + L",
"+ L.appendleft(Query[i][2])",
"- R += Query[i][2]",
"+ R.append(Query[i][2])",
"- R += Query[i][2]",
"+ R.append(Query[i][2])",
"- L = Query[i][2] + L",
"+ L.appendleft(Query[i][2])",
"+L, R = \"\".join(L), \"\".join(R)"
] | false | 0.084261 | 0.04245 | 1.984958 | [
"s040586999",
"s013691154"
] |
u788137651 | p03006 | python | s698591743 | s739309083 | 200 | 184 | 39,792 | 39,024 | Accepted | Accepted | 8 | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import copy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return list(map(int,input().split()))
def MF(): return list(map(float, input().split()))
def MI_(): return list(map(INT_,input().split()))
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in eval(input())]
def I(): return int(eval(input()))
def F(): return float(eval(input()))
def ST(): return input().replace('\n', '')
def main():
N = I()
XY = LLIN(N)
if N == 1:
print((1))
exit()
XY.sort()
count = defaultdict(int)
for i, (x1, y1) in enumerate(XY):
for j, (x2, y2) in enumerate(XY[i+1:]):
dx, dy = x1 - x2, y1 - y2
count[(dx, dy)] += 1
maxim = -inf
for v in list(count.values()):
maxim = max(maxim, v)
print((N - maxim))
if __name__ == '__main__':
main() | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import copy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return list(map(int,input().split()))
def MF(): return list(map(float, input().split()))
def MI_(): return list(map(INT_,input().split()))
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in eval(input())]
def I(): return int(eval(input()))
def F(): return float(eval(input()))
def ST(): return input().replace('\n', '')
def main():
N = I()
XY = LLIN(N)
XY.sort()
if N == 1:
print((1))
exit()
count = defaultdict(int)
for i, (x1, y1) in enumerate(XY):
for j, (x2, y2) in enumerate(XY[i+1:]):
dx, dy = x1 - x2, y1 - y2
count[(dx, dy)] += 1
print((N - max(count.values())))
if __name__ == '__main__':
main() | 58 | 55 | 1,594 | 1,533 | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log # log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict
from itertools import (
accumulate,
permutations,
combinations,
product,
combinations_with_replacement,
)
from bisect import bisect_left, bisect_right
from copy import copy
inf = float("inf")
mod = 10**9 + 7
def INT_(n):
return int(n) - 1
def MI():
return list(map(int, input().split()))
def MF():
return list(map(float, input().split()))
def MI_():
return list(map(INT_, input().split()))
def LI():
return list(MI())
def LI_():
return [int(x) - 1 for x in input().split()]
def LF():
return list(MF())
def LIN(n: int):
return [I() for _ in range(n)]
def LLIN(n: int):
return [LI() for _ in range(n)]
def LLIN_(n: int):
return [LI_() for _ in range(n)]
def LLI():
return [list(map(int, l.split())) for l in eval(input())]
def I():
return int(eval(input()))
def F():
return float(eval(input()))
def ST():
return input().replace("\n", "")
def main():
N = I()
XY = LLIN(N)
if N == 1:
print((1))
exit()
XY.sort()
count = defaultdict(int)
for i, (x1, y1) in enumerate(XY):
for j, (x2, y2) in enumerate(XY[i + 1 :]):
dx, dy = x1 - x2, y1 - y2
count[(dx, dy)] += 1
maxim = -inf
for v in list(count.values()):
maxim = max(maxim, v)
print((N - maxim))
if __name__ == "__main__":
main()
| #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log # log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict
from itertools import (
accumulate,
permutations,
combinations,
product,
combinations_with_replacement,
)
from bisect import bisect_left, bisect_right
from copy import copy
inf = float("inf")
mod = 10**9 + 7
def INT_(n):
return int(n) - 1
def MI():
return list(map(int, input().split()))
def MF():
return list(map(float, input().split()))
def MI_():
return list(map(INT_, input().split()))
def LI():
return list(MI())
def LI_():
return [int(x) - 1 for x in input().split()]
def LF():
return list(MF())
def LIN(n: int):
return [I() for _ in range(n)]
def LLIN(n: int):
return [LI() for _ in range(n)]
def LLIN_(n: int):
return [LI_() for _ in range(n)]
def LLI():
return [list(map(int, l.split())) for l in eval(input())]
def I():
return int(eval(input()))
def F():
return float(eval(input()))
def ST():
return input().replace("\n", "")
def main():
N = I()
XY = LLIN(N)
XY.sort()
if N == 1:
print((1))
exit()
count = defaultdict(int)
for i, (x1, y1) in enumerate(XY):
for j, (x2, y2) in enumerate(XY[i + 1 :]):
dx, dy = x1 - x2, y1 - y2
count[(dx, dy)] += 1
print((N - max(count.values())))
if __name__ == "__main__":
main()
| false | 5.172414 | [
"+ XY.sort()",
"- XY.sort()",
"- maxim = -inf",
"- for v in list(count.values()):",
"- maxim = max(maxim, v)",
"- print((N - maxim))",
"+ print((N - max(count.values())))"
] | false | 0.088614 | 0.048342 | 1.833052 | [
"s698591743",
"s739309083"
] |
u123756661 | p03136 | python | s918391180 | s360986160 | 191 | 165 | 38,384 | 38,324 | Accepted | Accepted | 13.61 | eval(input())
l=[int(i) for i in input().split()]
print((["No","Yes"][max(l)<sum(l)-max(l)])) | eval(input())
l=[int(i) for i in input().split()]
print((["Yes","No"][max(l)-(sum(l)-max(l))>=0])) | 3 | 3 | 87 | 92 | eval(input())
l = [int(i) for i in input().split()]
print((["No", "Yes"][max(l) < sum(l) - max(l)]))
| eval(input())
l = [int(i) for i in input().split()]
print((["Yes", "No"][max(l) - (sum(l) - max(l)) >= 0]))
| false | 0 | [
"-print(([\"No\", \"Yes\"][max(l) < sum(l) - max(l)]))",
"+print(([\"Yes\", \"No\"][max(l) - (sum(l) - max(l)) >= 0]))"
] | false | 0.043415 | 0.039048 | 1.111852 | [
"s918391180",
"s360986160"
] |
u579699847 | p03163 | python | s387100872 | s689206264 | 1,739 | 799 | 654,572 | 121,200 | Accepted | Accepted | 54.05 | import collections,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,W = LI()
wv = [LI() for _ in range(N)]
dp = [collections.defaultdict(int) for _ in range(N+1)] #1_indexed
dp[0][0] = 0
for i in range(1,N+1):
w,v = wv[i-1]
for dw,dv in list(dp[i-1].items()):
dp[i][dw] = max(dp[i][dw],dv)
if dw+w<=W:
dp[i][dw+w] = max(dp[i][dw+w],dv+v)
print((max(dp[-1].values())))
| import collections,itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,W = LI()
wv = [LI() for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N+1)] #1_indexed
for i,j in itertools.product(list(range(1,N+1)),list(range(W+1))):
w,v = wv[i-1]
if j-w>=0:
dp[i][j] = max(dp[i][j],dp[i-1][j-w]+v)
dp[i][j] = max(dp[i][j],dp[i-1][j])
print((dp[-1][-1]))
| 13 | 11 | 435 | 396 | import collections, sys
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
N, W = LI()
wv = [LI() for _ in range(N)]
dp = [collections.defaultdict(int) for _ in range(N + 1)] # 1_indexed
dp[0][0] = 0
for i in range(1, N + 1):
w, v = wv[i - 1]
for dw, dv in list(dp[i - 1].items()):
dp[i][dw] = max(dp[i][dw], dv)
if dw + w <= W:
dp[i][dw + w] = max(dp[i][dw + w], dv + v)
print((max(dp[-1].values())))
| import collections, itertools, sys
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
N, W = LI()
wv = [LI() for _ in range(N)]
dp = [[0] * (W + 1) for _ in range(N + 1)] # 1_indexed
for i, j in itertools.product(list(range(1, N + 1)), list(range(W + 1))):
w, v = wv[i - 1]
if j - w >= 0:
dp[i][j] = max(dp[i][j], dp[i - 1][j - w] + v)
dp[i][j] = max(dp[i][j], dp[i - 1][j])
print((dp[-1][-1]))
| false | 15.384615 | [
"-import collections, sys",
"+import collections, itertools, sys",
"-dp = [collections.defaultdict(int) for _ in range(N + 1)] # 1_indexed",
"-dp[0][0] = 0",
"-for i in range(1, N + 1):",
"+dp = [[0] * (W + 1) for _ in range(N + 1)] # 1_indexed",
"+for i, j in itertools.product(list(range(1, N + 1)), list(range(W + 1))):",
"- for dw, dv in list(dp[i - 1].items()):",
"- dp[i][dw] = max(dp[i][dw], dv)",
"- if dw + w <= W:",
"- dp[i][dw + w] = max(dp[i][dw + w], dv + v)",
"-print((max(dp[-1].values())))",
"+ if j - w >= 0:",
"+ dp[i][j] = max(dp[i][j], dp[i - 1][j - w] + v)",
"+ dp[i][j] = max(dp[i][j], dp[i - 1][j])",
"+print((dp[-1][-1]))"
] | false | 0.040023 | 0.055759 | 0.717786 | [
"s387100872",
"s689206264"
] |
u329706129 | p03745 | python | s447818801 | s301128499 | 91 | 81 | 14,480 | 14,436 | Accepted | Accepted | 10.99 | N = int(eval(input()))
A = list(map(int, input().split()))
if(N == 1):
print((1))
exit(0)
cur = A[0]
# 昇順(1)か降順(0)かのフラグ
ans = 1
flag = -1
for i in range(1, N):
if(cur == A[i]): continue
if(flag == -1):
if(A[i] > cur): flag = 1
elif(A[i] < cur): flag = 0
cur = A[i]
continue
if(flag == 1 and A[i] < cur):
cur, flag = A[i], -1
ans += 1
continue
if(flag == 1 and A[i] > cur):
cur = A[i]
continue
if(flag == 0 and A[i] > cur):
cur, flag = A[i], -1
ans += 1
continue
if(flag == 0 and A[i] < cur):
cur = A[i]
continue
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
if(N == 1):
print((1))
exit(0)
cur = A[0]
# 昇順(1)か降順(0)かのフラグ
ans = 1
flag = -1
for i in range(1, N):
if(cur == A[i]): continue
if(flag == -1):
if(A[i] > cur): flag = 1
elif(A[i] < cur): flag = 0
elif(flag == 1 and A[i] < cur):
flag = -1
ans += 1
elif(flag == 0 and A[i] > cur):
flag = -1
ans += 1
cur = A[i]
print(ans)
| 31 | 22 | 689 | 467 | N = int(eval(input()))
A = list(map(int, input().split()))
if N == 1:
print((1))
exit(0)
cur = A[0]
# 昇順(1)か降順(0)かのフラグ
ans = 1
flag = -1
for i in range(1, N):
if cur == A[i]:
continue
if flag == -1:
if A[i] > cur:
flag = 1
elif A[i] < cur:
flag = 0
cur = A[i]
continue
if flag == 1 and A[i] < cur:
cur, flag = A[i], -1
ans += 1
continue
if flag == 1 and A[i] > cur:
cur = A[i]
continue
if flag == 0 and A[i] > cur:
cur, flag = A[i], -1
ans += 1
continue
if flag == 0 and A[i] < cur:
cur = A[i]
continue
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
if N == 1:
print((1))
exit(0)
cur = A[0]
# 昇順(1)か降順(0)かのフラグ
ans = 1
flag = -1
for i in range(1, N):
if cur == A[i]:
continue
if flag == -1:
if A[i] > cur:
flag = 1
elif A[i] < cur:
flag = 0
elif flag == 1 and A[i] < cur:
flag = -1
ans += 1
elif flag == 0 and A[i] > cur:
flag = -1
ans += 1
cur = A[i]
print(ans)
| false | 29.032258 | [
"- cur = A[i]",
"- continue",
"- if flag == 1 and A[i] < cur:",
"- cur, flag = A[i], -1",
"+ elif flag == 1 and A[i] < cur:",
"+ flag = -1",
"- continue",
"- if flag == 1 and A[i] > cur:",
"- cur = A[i]",
"- continue",
"- if flag == 0 and A[i] > cur:",
"- cur, flag = A[i], -1",
"+ elif flag == 0 and A[i] > cur:",
"+ flag = -1",
"- continue",
"- if flag == 0 and A[i] < cur:",
"- cur = A[i]",
"- continue",
"+ cur = A[i]"
] | false | 0.043428 | 0.04381 | 0.991279 | [
"s447818801",
"s301128499"
] |
u855199458 | p02343 | python | s359455231 | s594468938 | 940 | 840 | 8,824 | 6,716 | Accepted | Accepted | 10.64 | # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000)
N, Q = tuple(map(int, input().split()))
tree = [[-1, 1] for _ in range(N)] # [next, rank]
def find(i):
if tree[i][0] == -1:
group = i
else:
group = find(tree[i][0])
return group
def unite(x, y):
px = find(x)
py = find(y)
if tree[px][1] == tree[py][1]: # rank is same
tree[py][0] = px
tree[px][1] += 1
else:
if tree[px][1] < tree[py][1]:
px, py = py, px
tree[py][0] = px
for _ in range(Q):
com, x, y = tuple(map(int, input().split()))
if com: # same
print((int(find(x) == find(y))))
else: # unite
if not int(find(x) == find(y)):
unite(x, y) | # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000)
N, Q = tuple(map(int, input().split()))
tree = [[-1, 1] for _ in range(N)] # [next, rank]
def find(i):
if tree[i][0] == -1:
group = i
else:
group = find(tree[i][0])
tree[i][0] = group
return group
def unite(x, y):
px = find(x)
py = find(y)
if tree[px][1] == tree[py][1]: # rank is same
tree[py][0] = px
tree[px][1] += 1
else:
if tree[px][1] < tree[py][1]:
px, py = py, px
tree[py][0] = px
for _ in range(Q):
com, x, y = tuple(map(int, input().split()))
if com: # same
print((int(find(x) == find(y))))
else: # unite
if not int(find(x) == find(y)):
unite(x, y)
| 34 | 35 | 777 | 809 | # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000)
N, Q = tuple(map(int, input().split()))
tree = [[-1, 1] for _ in range(N)] # [next, rank]
def find(i):
if tree[i][0] == -1:
group = i
else:
group = find(tree[i][0])
return group
def unite(x, y):
px = find(x)
py = find(y)
if tree[px][1] == tree[py][1]: # rank is same
tree[py][0] = px
tree[px][1] += 1
else:
if tree[px][1] < tree[py][1]:
px, py = py, px
tree[py][0] = px
for _ in range(Q):
com, x, y = tuple(map(int, input().split()))
if com: # same
print((int(find(x) == find(y))))
else: # unite
if not int(find(x) == find(y)):
unite(x, y)
| # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000)
N, Q = tuple(map(int, input().split()))
tree = [[-1, 1] for _ in range(N)] # [next, rank]
def find(i):
if tree[i][0] == -1:
group = i
else:
group = find(tree[i][0])
tree[i][0] = group
return group
def unite(x, y):
px = find(x)
py = find(y)
if tree[px][1] == tree[py][1]: # rank is same
tree[py][0] = px
tree[px][1] += 1
else:
if tree[px][1] < tree[py][1]:
px, py = py, px
tree[py][0] = px
for _ in range(Q):
com, x, y = tuple(map(int, input().split()))
if com: # same
print((int(find(x) == find(y))))
else: # unite
if not int(find(x) == find(y)):
unite(x, y)
| false | 2.857143 | [
"+ tree[i][0] = group"
] | false | 0.044418 | 0.0405 | 1.096752 | [
"s359455231",
"s594468938"
] |
u352394527 | p00472 | python | s970593016 | s674766640 | 600 | 450 | 9,636 | 9,636 | Accepted | Accepted | 25 | n,m = list(map(int,input().split()))
lst = [0]
for i in range(n - 1):
lst.append(lst[-1] + int(eval(input())))
ans = 0
num = 0
for i in range(m):
a = int(eval(input()))
ans += abs(lst[num] - lst[num + a])
ans %= 100000
num += a
print(ans)
| def solve():
n,m = list(map(int,input().split()))
lst = [0]
for i in range(n - 1):
lst.append(lst[-1] + int(eval(input())))
ans = 0
num = 0
for i in range(m):
a = int(eval(input()))
ans += abs(lst[num] - lst[num + a])
num += a
print((ans % 100000))
solve()
| 13 | 13 | 244 | 279 | n, m = list(map(int, input().split()))
lst = [0]
for i in range(n - 1):
lst.append(lst[-1] + int(eval(input())))
ans = 0
num = 0
for i in range(m):
a = int(eval(input()))
ans += abs(lst[num] - lst[num + a])
ans %= 100000
num += a
print(ans)
| def solve():
n, m = list(map(int, input().split()))
lst = [0]
for i in range(n - 1):
lst.append(lst[-1] + int(eval(input())))
ans = 0
num = 0
for i in range(m):
a = int(eval(input()))
ans += abs(lst[num] - lst[num + a])
num += a
print((ans % 100000))
solve()
| false | 0 | [
"-n, m = list(map(int, input().split()))",
"-lst = [0]",
"-for i in range(n - 1):",
"- lst.append(lst[-1] + int(eval(input())))",
"-ans = 0",
"-num = 0",
"-for i in range(m):",
"- a = int(eval(input()))",
"- ans += abs(lst[num] - lst[num + a])",
"- ans %= 100000",
"- num += a",
"-print(ans)",
"+def solve():",
"+ n, m = list(map(int, input().split()))",
"+ lst = [0]",
"+ for i in range(n - 1):",
"+ lst.append(lst[-1] + int(eval(input())))",
"+ ans = 0",
"+ num = 0",
"+ for i in range(m):",
"+ a = int(eval(input()))",
"+ ans += abs(lst[num] - lst[num + a])",
"+ num += a",
"+ print((ans % 100000))",
"+",
"+",
"+solve()"
] | false | 0.045067 | 0.045248 | 0.995995 | [
"s970593016",
"s674766640"
] |
u497952650 | p03457 | python | s036123778 | s419415334 | 373 | 277 | 3,064 | 22,424 | Accepted | Accepted | 25.74 | N = int(eval(input()))
ans = "Yes"
x = 0
y = 0
t = 0
for i in range(N):
t_i,x_i,y_i = list(map(int,input().split()))
x_i = abs(x_i-x)
y_i = abs(y_i-x)
t_i = abs(t_i-t)
if x_i+y_i <= t_i and (x_i+y_i-t_i)%2 == 0:
continue
else:
ans = "No"
x = x_i
y = y_i
t = t_i
print(ans) | N = int(eval(input()))
txy = list(tuple(map(int,input().split())) for _ in range(N))
t_0 = 0
x_0 = 0
y_0 = 0
for t,x,y in txy:
dt = t - t_0
dx = x - x_0
dy = y - y_0
if (abs(dx) + abs(dy))%2 == dt%2 and (abs(dx)+abs(dy)) <= dt:
t_0 = t
x_0 = x
y_0 = y
else:
print("No")
exit()
print("Yes") | 20 | 21 | 337 | 367 | N = int(eval(input()))
ans = "Yes"
x = 0
y = 0
t = 0
for i in range(N):
t_i, x_i, y_i = list(map(int, input().split()))
x_i = abs(x_i - x)
y_i = abs(y_i - x)
t_i = abs(t_i - t)
if x_i + y_i <= t_i and (x_i + y_i - t_i) % 2 == 0:
continue
else:
ans = "No"
x = x_i
y = y_i
t = t_i
print(ans)
| N = int(eval(input()))
txy = list(tuple(map(int, input().split())) for _ in range(N))
t_0 = 0
x_0 = 0
y_0 = 0
for t, x, y in txy:
dt = t - t_0
dx = x - x_0
dy = y - y_0
if (abs(dx) + abs(dy)) % 2 == dt % 2 and (abs(dx) + abs(dy)) <= dt:
t_0 = t
x_0 = x
y_0 = y
else:
print("No")
exit()
print("Yes")
| false | 4.761905 | [
"-ans = \"Yes\"",
"-x = 0",
"-y = 0",
"-t = 0",
"-for i in range(N):",
"- t_i, x_i, y_i = list(map(int, input().split()))",
"- x_i = abs(x_i - x)",
"- y_i = abs(y_i - x)",
"- t_i = abs(t_i - t)",
"- if x_i + y_i <= t_i and (x_i + y_i - t_i) % 2 == 0:",
"- continue",
"+txy = list(tuple(map(int, input().split())) for _ in range(N))",
"+t_0 = 0",
"+x_0 = 0",
"+y_0 = 0",
"+for t, x, y in txy:",
"+ dt = t - t_0",
"+ dx = x - x_0",
"+ dy = y - y_0",
"+ if (abs(dx) + abs(dy)) % 2 == dt % 2 and (abs(dx) + abs(dy)) <= dt:",
"+ t_0 = t",
"+ x_0 = x",
"+ y_0 = y",
"- ans = \"No\"",
"- x = x_i",
"- y = y_i",
"- t = t_i",
"-print(ans)",
"+ print(\"No\")",
"+ exit()",
"+print(\"Yes\")"
] | false | 0.047582 | 0.045891 | 1.036834 | [
"s036123778",
"s419415334"
] |
u260216890 | p02564 | python | s902989825 | s040208363 | 2,011 | 1,779 | 250,252 | 249,912 | Accepted | Accepted | 11.54 | import sys
input = sys.stdin.readline
n,m = list(map(int, input().split()))
es = [[] for _ in range(n)]
for i in range(m):
a,b=list(map(int, input().split()))
es[a].append(b)
# strongly connected component
def scc(es): # DFSを2回行う
n_node = len(es)
esinv = [[] for _ in range(n_node)]
for i in range(n_node):
for e in es[i]:
esinv[e].append(i)
used = [False]*n_node
dim = [len(es[i]) for i in range(n_node)]
order = []
for st in range(n_node): # DFS 1回目, postorderを求める
if not used[st]:
stack = [(st, 0)] # [(index, 既に辿ったエッジの数)]
while stack:
now, i = stack.pop()
if not i and used[now]:
continue
else:
used[now] = True
if i < dim[now]: # nowから延びるエッジを辿りきってない
stack.append((now,i+1))
stack.append((es[now][i],0))
else: # nowから延びる全てのエッジを辿った
order.append(now)
res = [-1]*n_node # 各ノードが所属するグループのidを保存
used = [False]*n_node
cnt = -1 # idカウンター
for st in order[::-1]: # DFS 2回目, postorderの逆順から
if not used[st]: # 逆向き矢印を辿って通れるノードを記録していく
cnt += 1
stack = [st]
res[st] = cnt
used[st] = True
while stack:
now = stack.pop()
for e in esinv[now]:
if not used[e]:
used[e] = True
res[e] = cnt
stack.append(e)
n_group = cnt+1
components = [[] for _ in range(n_group)]
for i in range(n_node):
components[res[i]].append(i)
return res, components
res,compo= scc(es)
# print(res,compo)
row=max(res)+1
print(row)
for i in range(row):
length = len(compo[i])
print((length, *compo[i])) | import sys
input = sys.stdin.readline
n,m = list(map(int, input().split()))
es = [[] for _ in range(n)]
for i in range(m):
a,b=list(map(int, input().split()))
es[a].append(b)
# strongly connected component
def scc(n_node,es): # DFSを2回行う
esinv = [[] for _ in range(n_node)]
for i in range(n_node):
for e in es[i]:
esinv[e].append(i)
used = [False]*n_node
dim = [len(es[i]) for i in range(n_node)]
order = []
for st in range(n_node): # DFS 1回目, postorderを求める
if not used[st]:
stack = [(st, 0)] # [(index, 既に辿ったエッジの数)]
while stack:
now, i = stack.pop()
if not i and used[now]:
continue
else:
used[now] = True
if i < dim[now]: # nowから延びるエッジを辿りきってない
stack.append((now,i+1))
stack.append((es[now][i],0))
else: # nowから延びる全てのエッジを辿った
order.append(now)
res = [-1]*n_node # 各ノードが所属するグループのidを保存
used = [False]*n_node
cnt = -1 # idカウンター
for st in order[::-1]: # DFS 2回目, postorderの逆順から
if not used[st]: # 逆向き矢印を辿って通れるノードを記録していく
cnt += 1
stack = [st]
res[st] = cnt
used[st] = True
while stack:
now = stack.pop()
for e in esinv[now]:
if not used[e]:
used[e] = True
res[e] = cnt
stack.append(e)
n_group = cnt+1
components = [[] for _ in range(n_group)]
for i in range(n_node):
components[res[i]].append(i)
return res, components
res,compo=scc(n,es)
# print(res,compo)
row=max(res)+1
print(row)
for i in range(row):
length = len(compo[i])
print((length, *compo[i]))
| 63 | 62 | 1,943 | 1,930 | import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
es = [[] for _ in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
es[a].append(b)
# strongly connected component
def scc(es): # DFSを2回行う
n_node = len(es)
esinv = [[] for _ in range(n_node)]
for i in range(n_node):
for e in es[i]:
esinv[e].append(i)
used = [False] * n_node
dim = [len(es[i]) for i in range(n_node)]
order = []
for st in range(n_node): # DFS 1回目, postorderを求める
if not used[st]:
stack = [(st, 0)] # [(index, 既に辿ったエッジの数)]
while stack:
now, i = stack.pop()
if not i and used[now]:
continue
else:
used[now] = True
if i < dim[now]: # nowから延びるエッジを辿りきってない
stack.append((now, i + 1))
stack.append((es[now][i], 0))
else: # nowから延びる全てのエッジを辿った
order.append(now)
res = [-1] * n_node # 各ノードが所属するグループのidを保存
used = [False] * n_node
cnt = -1 # idカウンター
for st in order[::-1]: # DFS 2回目, postorderの逆順から
if not used[st]: # 逆向き矢印を辿って通れるノードを記録していく
cnt += 1
stack = [st]
res[st] = cnt
used[st] = True
while stack:
now = stack.pop()
for e in esinv[now]:
if not used[e]:
used[e] = True
res[e] = cnt
stack.append(e)
n_group = cnt + 1
components = [[] for _ in range(n_group)]
for i in range(n_node):
components[res[i]].append(i)
return res, components
res, compo = scc(es)
# print(res,compo)
row = max(res) + 1
print(row)
for i in range(row):
length = len(compo[i])
print((length, *compo[i]))
| import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
es = [[] for _ in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
es[a].append(b)
# strongly connected component
def scc(n_node, es): # DFSを2回行う
esinv = [[] for _ in range(n_node)]
for i in range(n_node):
for e in es[i]:
esinv[e].append(i)
used = [False] * n_node
dim = [len(es[i]) for i in range(n_node)]
order = []
for st in range(n_node): # DFS 1回目, postorderを求める
if not used[st]:
stack = [(st, 0)] # [(index, 既に辿ったエッジの数)]
while stack:
now, i = stack.pop()
if not i and used[now]:
continue
else:
used[now] = True
if i < dim[now]: # nowから延びるエッジを辿りきってない
stack.append((now, i + 1))
stack.append((es[now][i], 0))
else: # nowから延びる全てのエッジを辿った
order.append(now)
res = [-1] * n_node # 各ノードが所属するグループのidを保存
used = [False] * n_node
cnt = -1 # idカウンター
for st in order[::-1]: # DFS 2回目, postorderの逆順から
if not used[st]: # 逆向き矢印を辿って通れるノードを記録していく
cnt += 1
stack = [st]
res[st] = cnt
used[st] = True
while stack:
now = stack.pop()
for e in esinv[now]:
if not used[e]:
used[e] = True
res[e] = cnt
stack.append(e)
n_group = cnt + 1
components = [[] for _ in range(n_group)]
for i in range(n_node):
components[res[i]].append(i)
return res, components
res, compo = scc(n, es)
# print(res,compo)
row = max(res) + 1
print(row)
for i in range(row):
length = len(compo[i])
print((length, *compo[i]))
| false | 1.587302 | [
"-def scc(es): # DFSを2回行う",
"- n_node = len(es)",
"+def scc(n_node, es): # DFSを2回行う",
"-res, compo = scc(es)",
"+res, compo = scc(n, es)"
] | false | 0.139353 | 0.192999 | 0.722038 | [
"s902989825",
"s040208363"
] |
u836939578 | p02572 | python | s513139495 | s694892068 | 129 | 113 | 104,816 | 105,140 | Accepted | Accepted | 12.4 | N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
x = 0
ans = 0
for i in range(len(A)):
ans += A[i] * x % MOD
x += A[i] % MOD
print((ans%MOD)) | N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
max_edge = sum(A)
tmp = 0
for num in A:
tmp += num ** 2
print(((max_edge ** 2 - tmp) // 2 % MOD)) | 12 | 14 | 187 | 189 | N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
x = 0
ans = 0
for i in range(len(A)):
ans += A[i] * x % MOD
x += A[i] % MOD
print((ans % MOD))
| N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
max_edge = sum(A)
tmp = 0
for num in A:
tmp += num**2
print(((max_edge**2 - tmp) // 2 % MOD))
| false | 14.285714 | [
"-x = 0",
"-ans = 0",
"-for i in range(len(A)):",
"- ans += A[i] * x % MOD",
"- x += A[i] % MOD",
"-print((ans % MOD))",
"+max_edge = sum(A)",
"+tmp = 0",
"+for num in A:",
"+ tmp += num**2",
"+print(((max_edge**2 - tmp) // 2 % MOD))"
] | false | 0.036368 | 0.077216 | 0.470996 | [
"s513139495",
"s694892068"
] |
u970197315 | p03575 | python | s722181888 | s919268330 | 27 | 24 | 3,064 | 3,064 | Accepted | Accepted | 11.11 | # ABC075 C - Bridge
def dfs(v):
visited[v]=True
for nv in range(n):
if G[v][nv]==False:
continue
if visited[nv]:
continue
dfs(nv)
n,m = list(map(int,input().split()))
G = [[False]*n for _ in range(n)]
ans = 0
visited = [False for _ in range(n)]
A,B = [],[]
for i in range(m):
a,b = list(map(int,input().split()))
A.append(b-1)
B.append(a-1)
G[a-1][b-1]=G[b-1][a-1]=True
for i in range(m):
G[A[i]][B[i]]=G[B[i]][A[i]]=False
visited = [False for _ in range(n)]
dfs(0)
if all(visited):
ans += 1
G[A[i]][B[i]]=G[B[i]][A[i]]=True
print((m-ans))
| class UnionFind:
def __init__(self, n):
self.p = [-1]*n
# union by rank
self.r = [1]*n
def find(self, x):
if self.p[x] < 0:
return x
else:
self.p[x] = self.find(self.p[x])
return self.p[x]
def union(self, x, y):
rx, ry = self.find(x), self.find(y)
if rx != ry:
if self.r[rx] > self.r[ry]:
rx, ry = ry, rx
if self.r[rx] == self.r[ry]:
self.r[ry] += 1
self.p[ry] += self.p[rx]
self.p[rx] = ry
def same(self, x, y):
return self.find(x) == self.find(y)
def count_member(self, x):
return -self.p[self.find(x)]
n,m=list(map(int,input().split()))
e=[]
for i in range(m):
a,b=list(map(int,input().split()))
e.append((a-1,b-1))
ans=0
for i in range(m):
uf=UnionFind(n)
ok=False
for j in range(m):
if i!=j:
a,b=e[j]
uf.union(a,b)
for k in range(n):
t=uf.count_member(k)
if t!=n:
ok=True
break
if ok:ans+=1
print(ans)
| 30 | 51 | 658 | 1,115 | # ABC075 C - Bridge
def dfs(v):
visited[v] = True
for nv in range(n):
if G[v][nv] == False:
continue
if visited[nv]:
continue
dfs(nv)
n, m = list(map(int, input().split()))
G = [[False] * n for _ in range(n)]
ans = 0
visited = [False for _ in range(n)]
A, B = [], []
for i in range(m):
a, b = list(map(int, input().split()))
A.append(b - 1)
B.append(a - 1)
G[a - 1][b - 1] = G[b - 1][a - 1] = True
for i in range(m):
G[A[i]][B[i]] = G[B[i]][A[i]] = False
visited = [False for _ in range(n)]
dfs(0)
if all(visited):
ans += 1
G[A[i]][B[i]] = G[B[i]][A[i]] = True
print((m - ans))
| class UnionFind:
def __init__(self, n):
self.p = [-1] * n
# union by rank
self.r = [1] * n
def find(self, x):
if self.p[x] < 0:
return x
else:
self.p[x] = self.find(self.p[x])
return self.p[x]
def union(self, x, y):
rx, ry = self.find(x), self.find(y)
if rx != ry:
if self.r[rx] > self.r[ry]:
rx, ry = ry, rx
if self.r[rx] == self.r[ry]:
self.r[ry] += 1
self.p[ry] += self.p[rx]
self.p[rx] = ry
def same(self, x, y):
return self.find(x) == self.find(y)
def count_member(self, x):
return -self.p[self.find(x)]
n, m = list(map(int, input().split()))
e = []
for i in range(m):
a, b = list(map(int, input().split()))
e.append((a - 1, b - 1))
ans = 0
for i in range(m):
uf = UnionFind(n)
ok = False
for j in range(m):
if i != j:
a, b = e[j]
uf.union(a, b)
for k in range(n):
t = uf.count_member(k)
if t != n:
ok = True
break
if ok:
ans += 1
print(ans)
| false | 41.176471 | [
"-# ABC075 C - Bridge",
"-def dfs(v):",
"- visited[v] = True",
"- for nv in range(n):",
"- if G[v][nv] == False:",
"- continue",
"- if visited[nv]:",
"- continue",
"- dfs(nv)",
"+class UnionFind:",
"+ def __init__(self, n):",
"+ self.p = [-1] * n",
"+ # union by rank",
"+ self.r = [1] * n",
"+",
"+ def find(self, x):",
"+ if self.p[x] < 0:",
"+ return x",
"+ else:",
"+ self.p[x] = self.find(self.p[x])",
"+ return self.p[x]",
"+",
"+ def union(self, x, y):",
"+ rx, ry = self.find(x), self.find(y)",
"+ if rx != ry:",
"+ if self.r[rx] > self.r[ry]:",
"+ rx, ry = ry, rx",
"+ if self.r[rx] == self.r[ry]:",
"+ self.r[ry] += 1",
"+ self.p[ry] += self.p[rx]",
"+ self.p[rx] = ry",
"+",
"+ def same(self, x, y):",
"+ return self.find(x) == self.find(y)",
"+",
"+ def count_member(self, x):",
"+ return -self.p[self.find(x)]",
"-G = [[False] * n for _ in range(n)]",
"-ans = 0",
"-visited = [False for _ in range(n)]",
"-A, B = [], []",
"+e = []",
"- A.append(b - 1)",
"- B.append(a - 1)",
"- G[a - 1][b - 1] = G[b - 1][a - 1] = True",
"+ e.append((a - 1, b - 1))",
"+ans = 0",
"- G[A[i]][B[i]] = G[B[i]][A[i]] = False",
"- visited = [False for _ in range(n)]",
"- dfs(0)",
"- if all(visited):",
"+ uf = UnionFind(n)",
"+ ok = False",
"+ for j in range(m):",
"+ if i != j:",
"+ a, b = e[j]",
"+ uf.union(a, b)",
"+ for k in range(n):",
"+ t = uf.count_member(k)",
"+ if t != n:",
"+ ok = True",
"+ break",
"+ if ok:",
"- G[A[i]][B[i]] = G[B[i]][A[i]] = True",
"-print((m - ans))",
"+print(ans)"
] | false | 0.040954 | 0.042134 | 0.971981 | [
"s722181888",
"s919268330"
] |
u867848444 | p03162 | python | s550108900 | s873754117 | 950 | 650 | 47,320 | 74,968 | Accepted | Accepted | 31.58 | n=int(eval(input()))
l=[list(map(int,input().split())) for i in range(n)]
dp=[[0,0,0] for i in range(n+1)]
for i in range(n):
#j==kの場合を除く
for j in range(3):
for k in range(3):
if j!=k:
dp[i+1][j]=max(dp[i+1][j],dp[i][k]+l[i][j])
print((max(dp[-1]))) | #DP-C
n=int(eval(input()))
l=[list(map(int,input().split())) for i in range(n)]
dp=[[0]*3 for i in range(n)]
dp[0]=l[0]
#print(dp)
for i in range(1,n):
for j in range(3):
for k in range(3):
#同じ活動の場合を除く
if j!=k:
dp[i][j]=max(dp[i-1][k]+l[i][j],dp[i][j])
print((max(dp[-1]))) | 13 | 16 | 328 | 335 | n = int(eval(input()))
l = [list(map(int, input().split())) for i in range(n)]
dp = [[0, 0, 0] for i in range(n + 1)]
for i in range(n):
# j==kの場合を除く
for j in range(3):
for k in range(3):
if j != k:
dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + l[i][j])
print((max(dp[-1])))
| # DP-C
n = int(eval(input()))
l = [list(map(int, input().split())) for i in range(n)]
dp = [[0] * 3 for i in range(n)]
dp[0] = l[0]
# print(dp)
for i in range(1, n):
for j in range(3):
for k in range(3):
# 同じ活動の場合を除く
if j != k:
dp[i][j] = max(dp[i - 1][k] + l[i][j], dp[i][j])
print((max(dp[-1])))
| false | 18.75 | [
"+# DP-C",
"-dp = [[0, 0, 0] for i in range(n + 1)]",
"-for i in range(n):",
"- # j==kの場合を除く",
"+dp = [[0] * 3 for i in range(n)]",
"+dp[0] = l[0]",
"+# print(dp)",
"+for i in range(1, n):",
"+ # 同じ活動の場合を除く",
"- dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + l[i][j])",
"+ dp[i][j] = max(dp[i - 1][k] + l[i][j], dp[i][j])"
] | false | 0.036678 | 0.036715 | 0.999011 | [
"s550108900",
"s873754117"
] |
u691018832 | p02631 | python | s597753009 | s782979509 | 1,164 | 143 | 28,232 | 29,060 | Accepted | Accepted | 87.71 | def main():
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n = int(readline())
a = list(map(int, readline().split()))
ans = [0] * n
v = 2 ** 30
for i in range(30):
v //= 2
check = [False] * n
cnt = 0
for j, aa in enumerate(a):
if aa >= v:
a[j] -= v
check[j] = True
cnt += 1
if cnt % 2 == 1:
for j, c in enumerate(check):
if not c:
ans[j] += v
else:
for j, c in enumerate(check):
if c:
ans[j] += v
print((*ans))
if __name__ == '__main__':
main()
| def main():
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n = int(readline())
a = list(map(int, readline().split()))
memo = 0
for aa in a:
memo ^= aa
for i in range(n):
a[i] ^= memo
print((*a))
if __name__ == '__main__':
main()
| 33 | 19 | 830 | 412 | def main():
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
n = int(readline())
a = list(map(int, readline().split()))
ans = [0] * n
v = 2**30
for i in range(30):
v //= 2
check = [False] * n
cnt = 0
for j, aa in enumerate(a):
if aa >= v:
a[j] -= v
check[j] = True
cnt += 1
if cnt % 2 == 1:
for j, c in enumerate(check):
if not c:
ans[j] += v
else:
for j, c in enumerate(check):
if c:
ans[j] += v
print((*ans))
if __name__ == "__main__":
main()
| def main():
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
n = int(readline())
a = list(map(int, readline().split()))
memo = 0
for aa in a:
memo ^= aa
for i in range(n):
a[i] ^= memo
print((*a))
if __name__ == "__main__":
main()
| false | 42.424242 | [
"- ans = [0] * n",
"- v = 2**30",
"- for i in range(30):",
"- v //= 2",
"- check = [False] * n",
"- cnt = 0",
"- for j, aa in enumerate(a):",
"- if aa >= v:",
"- a[j] -= v",
"- check[j] = True",
"- cnt += 1",
"- if cnt % 2 == 1:",
"- for j, c in enumerate(check):",
"- if not c:",
"- ans[j] += v",
"- else:",
"- for j, c in enumerate(check):",
"- if c:",
"- ans[j] += v",
"- print((*ans))",
"+ memo = 0",
"+ for aa in a:",
"+ memo ^= aa",
"+ for i in range(n):",
"+ a[i] ^= memo",
"+ print((*a))"
] | false | 0.034852 | 0.03735 | 0.933121 | [
"s597753009",
"s782979509"
] |
u072053884 | p02299 | python | s162740219 | s250512024 | 90 | 80 | 7,844 | 7,936 | Accepted | Accepted | 11.11 | def dot(c1, c2):
return c1.real * c2.real + c1.imag * c2.imag
def cross(c1, c2):
return c1.real * c2.imag - c1.imag * c2.real
def string_to_complex(s):
x, y = list(map(int, s.split()))
return x + y * 1j
def contains(polygon, point):
flag = False
for v1, v2 in zip(polygon[0:], polygon[1:]):
a = v1 - point
b = v2 - point
if a.imag > b.imag:
a, b = b, a
cross_ab = cross(a, b)
if a.imag <= 0 and b.imag > 0 and cross_ab > 0:
flag = not flag
if cross_ab == 0 and dot(a, b) <= 0:
return 1
if flag:
return 2
else:
return 0
import sys
file_input = sys.stdin
n = int(file_input.readline())
polygon = [string_to_complex(file_input.readline()) for i in range(n)]
polygon.append(polygon[0])
q = int(file_input.readline())
for line in file_input:
t = string_to_complex(line)
print((contains(polygon, t))) | def dot(c1, c2):
return c1.real * c2.real + c1.imag * c2.imag
def cross(c1, c2):
return c1.real * c2.imag - c1.imag * c2.real
def string_to_complex(s):
x, y = list(map(int, s.split()))
return x + y * 1j
def contains(polygon, point):
flag = False
for v1, v2 in zip(polygon[0:], polygon[1:]):
a = v1 - point
b = v2 - point
if a.imag > b.imag:
a, b = b, a
cross_ab = cross(a, b)
if cross_ab == 0 and dot(a, b) <= 0:
return 1
if a.imag <= 0 and b.imag > 0 and cross_ab > 0:
flag = not flag
if flag:
return 2
else:
return 0
import sys
file_input = sys.stdin
n = int(file_input.readline())
polygon = [string_to_complex(file_input.readline()) for i in range(n)]
polygon.append(polygon[0])
q = int(file_input.readline())
for line in file_input:
t = string_to_complex(line)
print((contains(polygon, t))) | 41 | 41 | 975 | 975 | def dot(c1, c2):
return c1.real * c2.real + c1.imag * c2.imag
def cross(c1, c2):
return c1.real * c2.imag - c1.imag * c2.real
def string_to_complex(s):
x, y = list(map(int, s.split()))
return x + y * 1j
def contains(polygon, point):
flag = False
for v1, v2 in zip(polygon[0:], polygon[1:]):
a = v1 - point
b = v2 - point
if a.imag > b.imag:
a, b = b, a
cross_ab = cross(a, b)
if a.imag <= 0 and b.imag > 0 and cross_ab > 0:
flag = not flag
if cross_ab == 0 and dot(a, b) <= 0:
return 1
if flag:
return 2
else:
return 0
import sys
file_input = sys.stdin
n = int(file_input.readline())
polygon = [string_to_complex(file_input.readline()) for i in range(n)]
polygon.append(polygon[0])
q = int(file_input.readline())
for line in file_input:
t = string_to_complex(line)
print((contains(polygon, t)))
| def dot(c1, c2):
return c1.real * c2.real + c1.imag * c2.imag
def cross(c1, c2):
return c1.real * c2.imag - c1.imag * c2.real
def string_to_complex(s):
x, y = list(map(int, s.split()))
return x + y * 1j
def contains(polygon, point):
flag = False
for v1, v2 in zip(polygon[0:], polygon[1:]):
a = v1 - point
b = v2 - point
if a.imag > b.imag:
a, b = b, a
cross_ab = cross(a, b)
if cross_ab == 0 and dot(a, b) <= 0:
return 1
if a.imag <= 0 and b.imag > 0 and cross_ab > 0:
flag = not flag
if flag:
return 2
else:
return 0
import sys
file_input = sys.stdin
n = int(file_input.readline())
polygon = [string_to_complex(file_input.readline()) for i in range(n)]
polygon.append(polygon[0])
q = int(file_input.readline())
for line in file_input:
t = string_to_complex(line)
print((contains(polygon, t)))
| false | 0 | [
"+ if cross_ab == 0 and dot(a, b) <= 0:",
"+ return 1",
"- if cross_ab == 0 and dot(a, b) <= 0:",
"- return 1"
] | false | 0.063487 | 0.045734 | 1.388187 | [
"s162740219",
"s250512024"
] |
u867826040 | p02580 | python | s999325639 | s246546231 | 2,357 | 2,153 | 144,488 | 156,420 | Accepted | Accepted | 8.66 | #from random import randint
import numpy as np
#@njit
def f(h,w,m,ins):
yp = np.zeros(h,dtype=np.int)
xp = np.zeros(w,dtype=np.int)
#yp[:,1] = np.arange(h)
#xp[:,1] = np.arange(w)
ans = 0
s = set()
for hi,wi in ins:
s.add((hi-1,wi-1))
yp[hi-1] += 1
xp[wi-1] += 1
ypm = yp[yp.argmax()]
xpm = xp[xp.argmax()]
yps = np.where(yp == ypm)[0].tolist()
xps = np.where(xp == xpm)[0].tolist()
#y = yp[yps]
for ypsi in yps:
for xpsi in xps:
a = yp[ypsi]+xp[xpsi]
if (ypsi,xpsi) in s:
a -= 1
ans = max(ans,a)
else:
return a
return ans
if False:
while True:
h,w = randint(1,10**5*3),randint(1,10**5*3)
m = randint(1,min(h*w,10**5*3))
ins = [(randint(1,h),randint(1,w)) for i in range(m)]
ans = f(h,w,m,ins)
print(ans)
else:
h,w,m = list(map(int,input().split()))
ans = f(h,w,m,[tuple(map(int,input().split())) for i in range(m)])
print(ans)
| #from random import randint
import numpy as np
def f(h,w,m,ins):
yp = np.zeros(h,dtype=np.int32)
xp = np.zeros(w,dtype=np.int32)
s = set()
for hi,wi in ins:
s.add((hi-1,wi-1))
yp[hi-1] += 1
xp[wi-1] += 1
ypm = yp.max()
xpm = xp.max()
yps = np.where(yp == ypm)[0].tolist()
xps = np.where(xp == xpm)[0].tolist()
ans = yp[yps[0]]+xp[xps[0]]
for ypsi in yps:
for xpsi in xps:
if not (ypsi,xpsi) in s:
return ans
return ans-1
if __name__ == "__main__":
if False:
while True:
h,w = randint(1,10**5*3),randint(10**5,10**5*3)
m = randint(1,min(h*w,10**5*3))
ins = [(randint(1,h),randint(1,w)) for i in range(m)]
ans = f(h,w,m,ins)
print(ans)
else:
h,w,m = list(map(int,input().split()))
ans = f(h,w,m,[list(map(int,input().split())) for i in range(m)])
print(ans)
| 43 | 35 | 1,096 | 991 | # from random import randint
import numpy as np
# @njit
def f(h, w, m, ins):
yp = np.zeros(h, dtype=np.int)
xp = np.zeros(w, dtype=np.int)
# yp[:,1] = np.arange(h)
# xp[:,1] = np.arange(w)
ans = 0
s = set()
for hi, wi in ins:
s.add((hi - 1, wi - 1))
yp[hi - 1] += 1
xp[wi - 1] += 1
ypm = yp[yp.argmax()]
xpm = xp[xp.argmax()]
yps = np.where(yp == ypm)[0].tolist()
xps = np.where(xp == xpm)[0].tolist()
# y = yp[yps]
for ypsi in yps:
for xpsi in xps:
a = yp[ypsi] + xp[xpsi]
if (ypsi, xpsi) in s:
a -= 1
ans = max(ans, a)
else:
return a
return ans
if False:
while True:
h, w = randint(1, 10**5 * 3), randint(1, 10**5 * 3)
m = randint(1, min(h * w, 10**5 * 3))
ins = [(randint(1, h), randint(1, w)) for i in range(m)]
ans = f(h, w, m, ins)
print(ans)
else:
h, w, m = list(map(int, input().split()))
ans = f(h, w, m, [tuple(map(int, input().split())) for i in range(m)])
print(ans)
| # from random import randint
import numpy as np
def f(h, w, m, ins):
yp = np.zeros(h, dtype=np.int32)
xp = np.zeros(w, dtype=np.int32)
s = set()
for hi, wi in ins:
s.add((hi - 1, wi - 1))
yp[hi - 1] += 1
xp[wi - 1] += 1
ypm = yp.max()
xpm = xp.max()
yps = np.where(yp == ypm)[0].tolist()
xps = np.where(xp == xpm)[0].tolist()
ans = yp[yps[0]] + xp[xps[0]]
for ypsi in yps:
for xpsi in xps:
if not (ypsi, xpsi) in s:
return ans
return ans - 1
if __name__ == "__main__":
if False:
while True:
h, w = randint(1, 10**5 * 3), randint(10**5, 10**5 * 3)
m = randint(1, min(h * w, 10**5 * 3))
ins = [(randint(1, h), randint(1, w)) for i in range(m)]
ans = f(h, w, m, ins)
print(ans)
else:
h, w, m = list(map(int, input().split()))
ans = f(h, w, m, [list(map(int, input().split())) for i in range(m)])
print(ans)
| false | 18.604651 | [
"-# @njit",
"+",
"- yp = np.zeros(h, dtype=np.int)",
"- xp = np.zeros(w, dtype=np.int)",
"- # yp[:,1] = np.arange(h)",
"- # xp[:,1] = np.arange(w)",
"- ans = 0",
"+ yp = np.zeros(h, dtype=np.int32)",
"+ xp = np.zeros(w, dtype=np.int32)",
"- ypm = yp[yp.argmax()]",
"- xpm = xp[xp.argmax()]",
"+ ypm = yp.max()",
"+ xpm = xp.max()",
"- # y = yp[yps]",
"+ ans = yp[yps[0]] + xp[xps[0]]",
"- a = yp[ypsi] + xp[xpsi]",
"- if (ypsi, xpsi) in s:",
"- a -= 1",
"- ans = max(ans, a)",
"- else:",
"- return a",
"- return ans",
"+ if not (ypsi, xpsi) in s:",
"+ return ans",
"+ return ans - 1",
"-if False:",
"- while True:",
"- h, w = randint(1, 10**5 * 3), randint(1, 10**5 * 3)",
"- m = randint(1, min(h * w, 10**5 * 3))",
"- ins = [(randint(1, h), randint(1, w)) for i in range(m)]",
"- ans = f(h, w, m, ins)",
"+if __name__ == \"__main__\":",
"+ if False:",
"+ while True:",
"+ h, w = randint(1, 10**5 * 3), randint(10**5, 10**5 * 3)",
"+ m = randint(1, min(h * w, 10**5 * 3))",
"+ ins = [(randint(1, h), randint(1, w)) for i in range(m)]",
"+ ans = f(h, w, m, ins)",
"+ print(ans)",
"+ else:",
"+ h, w, m = list(map(int, input().split()))",
"+ ans = f(h, w, m, [list(map(int, input().split())) for i in range(m)])",
"-else:",
"- h, w, m = list(map(int, input().split()))",
"- ans = f(h, w, m, [tuple(map(int, input().split())) for i in range(m)])",
"- print(ans)"
] | false | 0.539299 | 0.276936 | 1.947381 | [
"s999325639",
"s246546231"
] |
u203383537 | p02659 | python | s456150732 | s111175605 | 27 | 21 | 10,076 | 9,152 | Accepted | Accepted | 22.22 | from decimal import *
a,b = input().split()
ans = Decimal(a) * Decimal(b)
print((int(ans))) | a,b = input().split()
b = b.replace(".","")
ans = (int(a) * int(b))//100
print(ans) | 5 | 7 | 94 | 92 | from decimal import *
a, b = input().split()
ans = Decimal(a) * Decimal(b)
print((int(ans)))
| a, b = input().split()
b = b.replace(".", "")
ans = (int(a) * int(b)) // 100
print(ans)
| false | 28.571429 | [
"-from decimal import *",
"-",
"-ans = Decimal(a) * Decimal(b)",
"-print((int(ans)))",
"+b = b.replace(\".\", \"\")",
"+ans = (int(a) * int(b)) // 100",
"+print(ans)"
] | false | 0.044444 | 0.03969 | 1.119756 | [
"s456150732",
"s111175605"
] |
u609061751 | p03290 | python | s318478903 | s497578647 | 258 | 152 | 44,912 | 3,064 | Accepted | Accepted | 41.09 | import sys
input = sys.stdin.readline
d, g = [int(x) for x in input().split()]
pc = [[int(x) for x in input().split()] for _ in range(d)]
ans = float("inf")
for i in range(2 ** d):
i_bin = bin(i)[2:].zfill(d)
s = set() # コンプリートボーナスをもらう
for j in range(len(i_bin)):
if i_bin[j] == "1":
s.add(j)
cnt = 0
total = 0
for k in s:
cnt += pc[k][0]
total += (k + 1)*pc[k][0]*100 + pc[k][1]
if total >= g:
ans = min(ans, cnt)
continue
for l in range(d - 1, -1, -1):
flag = 0
if l in s:
continue
for m in range(1, pc[l][0]):
total += (l + 1) * 100
cnt += 1
if total >= g:
flag = 1
break
if flag:
break
if total >= g:
ans = min(ans, cnt)
print(ans)
| import sys
input = sys.stdin.readline
d, g = [int(x) for x in input().split()]
pc = [[int(x) for x in input().split()] for _ in range(d)]
ans = float("inf")
for i in range(2 ** d):
s = set() # コンプリートボーナスをもらう
for j in range(d):
if (i >> j) & 1:
s.add(j)
cnt = 0
total = 0
for k in s:
cnt += pc[k][0]
total += (k + 1)*pc[k][0]*100 + pc[k][1]
if total >= g:
ans = min(ans, cnt)
continue
for l in range(d - 1, -1, -1):
flag = 0
if l in s:
continue
for m in range(1, pc[l][0]):
total += (l + 1) * 100
cnt += 1
if total >= g:
flag = 1
break
if flag:
break
if total >= g:
ans = min(ans, cnt)
print(ans)
| 39 | 38 | 910 | 865 | import sys
input = sys.stdin.readline
d, g = [int(x) for x in input().split()]
pc = [[int(x) for x in input().split()] for _ in range(d)]
ans = float("inf")
for i in range(2**d):
i_bin = bin(i)[2:].zfill(d)
s = set() # コンプリートボーナスをもらう
for j in range(len(i_bin)):
if i_bin[j] == "1":
s.add(j)
cnt = 0
total = 0
for k in s:
cnt += pc[k][0]
total += (k + 1) * pc[k][0] * 100 + pc[k][1]
if total >= g:
ans = min(ans, cnt)
continue
for l in range(d - 1, -1, -1):
flag = 0
if l in s:
continue
for m in range(1, pc[l][0]):
total += (l + 1) * 100
cnt += 1
if total >= g:
flag = 1
break
if flag:
break
if total >= g:
ans = min(ans, cnt)
print(ans)
| import sys
input = sys.stdin.readline
d, g = [int(x) for x in input().split()]
pc = [[int(x) for x in input().split()] for _ in range(d)]
ans = float("inf")
for i in range(2**d):
s = set() # コンプリートボーナスをもらう
for j in range(d):
if (i >> j) & 1:
s.add(j)
cnt = 0
total = 0
for k in s:
cnt += pc[k][0]
total += (k + 1) * pc[k][0] * 100 + pc[k][1]
if total >= g:
ans = min(ans, cnt)
continue
for l in range(d - 1, -1, -1):
flag = 0
if l in s:
continue
for m in range(1, pc[l][0]):
total += (l + 1) * 100
cnt += 1
if total >= g:
flag = 1
break
if flag:
break
if total >= g:
ans = min(ans, cnt)
print(ans)
| false | 2.564103 | [
"- i_bin = bin(i)[2:].zfill(d)",
"- for j in range(len(i_bin)):",
"- if i_bin[j] == \"1\":",
"+ for j in range(d):",
"+ if (i >> j) & 1:"
] | false | 0.03895 | 0.045981 | 0.847101 | [
"s318478903",
"s497578647"
] |
u162773977 | p03241 | python | s833136835 | s509842957 | 22 | 20 | 3,188 | 3,064 | Accepted | Accepted | 9.09 |
def factorize(n):
nn = n
lst = []
for i in range(2, int(1 + n ** 0.5)):
k = 0
while nn % i == 0:
k += 1
nn = nn // i
if k > 0:
lst.append([i, k])
if nn != 1:
lst.append([nn, 1])
return lst
def gen_divisor(m):
# not sorted!
yield 1
factorized = factorize(m)
length = len(factorized)
if length == 0:
return
factor_nexps = [0] * length
while True:
# increment
factor_nexps[0] += 1
for idx in range(length - 1):
if factor_nexps[idx] > factorized[idx][1]:
factor_nexps[idx] = 0
factor_nexps[idx+1] += 1
if factor_nexps[-1] > factorized[-1][1]:
return
divisor = 1
for i, tup in enumerate(factorized):
divisor *= tup[0] ** factor_nexps[i]
yield divisor
N, M = list(map(int, input().split()))
def solve():
divisors = sorted([di for di in gen_divisor(M) if di >= N])
ans = M // divisors[0]
return ans
print((solve()))
| def gen_divisor(n):
ps = []
for i in range(1, int(1 + n ** 0.5)):
if n % i == 0:
yield i
ps.append(n // i)
if n // ps[-1] == ps[-1]:
del ps[-1]
for p in reversed(ps):
yield p
N, M = list(map(int, input().split()))
def solve():
for di in gen_divisor(M):
if di >= N:
ans = M // di
return ans
print((solve())) | 46 | 20 | 1,112 | 420 | def factorize(n):
nn = n
lst = []
for i in range(2, int(1 + n**0.5)):
k = 0
while nn % i == 0:
k += 1
nn = nn // i
if k > 0:
lst.append([i, k])
if nn != 1:
lst.append([nn, 1])
return lst
def gen_divisor(m):
# not sorted!
yield 1
factorized = factorize(m)
length = len(factorized)
if length == 0:
return
factor_nexps = [0] * length
while True:
# increment
factor_nexps[0] += 1
for idx in range(length - 1):
if factor_nexps[idx] > factorized[idx][1]:
factor_nexps[idx] = 0
factor_nexps[idx + 1] += 1
if factor_nexps[-1] > factorized[-1][1]:
return
divisor = 1
for i, tup in enumerate(factorized):
divisor *= tup[0] ** factor_nexps[i]
yield divisor
N, M = list(map(int, input().split()))
def solve():
divisors = sorted([di for di in gen_divisor(M) if di >= N])
ans = M // divisors[0]
return ans
print((solve()))
| def gen_divisor(n):
ps = []
for i in range(1, int(1 + n**0.5)):
if n % i == 0:
yield i
ps.append(n // i)
if n // ps[-1] == ps[-1]:
del ps[-1]
for p in reversed(ps):
yield p
N, M = list(map(int, input().split()))
def solve():
for di in gen_divisor(M):
if di >= N:
ans = M // di
return ans
print((solve()))
| false | 56.521739 | [
"-def factorize(n):",
"- nn = n",
"- lst = []",
"- for i in range(2, int(1 + n**0.5)):",
"- k = 0",
"- while nn % i == 0:",
"- k += 1",
"- nn = nn // i",
"- if k > 0:",
"- lst.append([i, k])",
"- if nn != 1:",
"- lst.append([nn, 1])",
"- return lst",
"-",
"-",
"-def gen_divisor(m):",
"- # not sorted!",
"- yield 1",
"- factorized = factorize(m)",
"- length = len(factorized)",
"- if length == 0:",
"- return",
"- factor_nexps = [0] * length",
"- while True:",
"- # increment",
"- factor_nexps[0] += 1",
"- for idx in range(length - 1):",
"- if factor_nexps[idx] > factorized[idx][1]:",
"- factor_nexps[idx] = 0",
"- factor_nexps[idx + 1] += 1",
"- if factor_nexps[-1] > factorized[-1][1]:",
"- return",
"- divisor = 1",
"- for i, tup in enumerate(factorized):",
"- divisor *= tup[0] ** factor_nexps[i]",
"- yield divisor",
"+def gen_divisor(n):",
"+ ps = []",
"+ for i in range(1, int(1 + n**0.5)):",
"+ if n % i == 0:",
"+ yield i",
"+ ps.append(n // i)",
"+ if n // ps[-1] == ps[-1]:",
"+ del ps[-1]",
"+ for p in reversed(ps):",
"+ yield p",
"- divisors = sorted([di for di in gen_divisor(M) if di >= N])",
"- ans = M // divisors[0]",
"- return ans",
"+ for di in gen_divisor(M):",
"+ if di >= N:",
"+ ans = M // di",
"+ return ans"
] | false | 0.040439 | 0.074754 | 0.540967 | [
"s833136835",
"s509842957"
] |
u853619096 | p02393 | python | s874668232 | s411193957 | 30 | 20 | 7,700 | 7,648 | Accepted | Accepted | 33.33 | z =[int(i) for i in input().split()]
z.sort()
print(("{0} {1} {2}".format(z[0],z[1],z[2]))) | a=list(map(int,input().split()))
a.sort()
print((a[0],a[1],a[2])) | 4 | 3 | 95 | 65 | z = [int(i) for i in input().split()]
z.sort()
print(("{0} {1} {2}".format(z[0], z[1], z[2])))
| a = list(map(int, input().split()))
a.sort()
print((a[0], a[1], a[2]))
| false | 25 | [
"-z = [int(i) for i in input().split()]",
"-z.sort()",
"-print((\"{0} {1} {2}\".format(z[0], z[1], z[2])))",
"+a = list(map(int, input().split()))",
"+a.sort()",
"+print((a[0], a[1], a[2]))"
] | false | 0.054025 | 0.173461 | 0.311452 | [
"s874668232",
"s411193957"
] |
u588341295 | p02588 | python | s451665982 | s298739434 | 1,842 | 331 | 214,772 | 85,224 | Accepted | Accepted | 82.03 | import sys
from collections import Counter
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 19 + 7
EPS = 10 ** -10
def gcd(a, b):
while b: a, b = b, a % b
return a
N = INT()
K = 10**9
L = 10**18
A = [0] * N
C = Counter()
for i in range(N):
a = Decimal(eval(input()))
A[i] = int(a * K)
C[gcd(A[i], L)] += 1
ans = 0
for k1, v1 in list(C.items()):
for k2, v2 in list(C.items()):
if k1 == k2:
if k1*k2 % L == 0:
ans += v1*(v1-1) // 2
elif k1 < k2:
if k1*k2 % L == 0:
ans += v1 * v2
print(ans)
| import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 19 + 7
EPS = 10 ** -10
def gcd(a, b):
while b: a, b = b, a % b
return a
N = INT()
K = 10**9
L = 10**18
A = [0] * N
C = Counter()
for i in range(N):
a = float(eval(input()))
A[i] = round(a * K)
C[gcd(A[i], L)] += 1
ans = 0
for k1, v1 in list(C.items()):
for k2, v2 in list(C.items()):
if k1 == k2:
if k1*k2 % L == 0:
ans += v1*(v1-1) // 2
elif k1 < k2:
if k1*k2 % L == 0:
ans += v1 * v2
print(ans)
| 45 | 44 | 1,227 | 1,198 | import sys
from collections import Counter
from decimal import Decimal
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**19
MOD = 10**19 + 7
EPS = 10**-10
def gcd(a, b):
while b:
a, b = b, a % b
return a
N = INT()
K = 10**9
L = 10**18
A = [0] * N
C = Counter()
for i in range(N):
a = Decimal(eval(input()))
A[i] = int(a * K)
C[gcd(A[i], L)] += 1
ans = 0
for k1, v1 in list(C.items()):
for k2, v2 in list(C.items()):
if k1 == k2:
if k1 * k2 % L == 0:
ans += v1 * (v1 - 1) // 2
elif k1 < k2:
if k1 * k2 % L == 0:
ans += v1 * v2
print(ans)
| import sys
from collections import Counter
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**19
MOD = 10**19 + 7
EPS = 10**-10
def gcd(a, b):
while b:
a, b = b, a % b
return a
N = INT()
K = 10**9
L = 10**18
A = [0] * N
C = Counter()
for i in range(N):
a = float(eval(input()))
A[i] = round(a * K)
C[gcd(A[i], L)] += 1
ans = 0
for k1, v1 in list(C.items()):
for k2, v2 in list(C.items()):
if k1 == k2:
if k1 * k2 % L == 0:
ans += v1 * (v1 - 1) // 2
elif k1 < k2:
if k1 * k2 % L == 0:
ans += v1 * v2
print(ans)
| false | 2.222222 | [
"-from decimal import Decimal",
"- a = Decimal(eval(input()))",
"- A[i] = int(a * K)",
"+ a = float(eval(input()))",
"+ A[i] = round(a * K)"
] | false | 0.045305 | 0.036935 | 1.226612 | [
"s451665982",
"s298739434"
] |
u853187694 | p02848 | python | s348297121 | s120630099 | 35 | 32 | 4,468 | 4,340 | Accepted | Accepted | 8.57 | n = int(input())
st = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
s = input()
for i in range(len(s)):
a = (st.index(s[i]) + n) % 26
print(st[a],end="")
| N = int(input())
S = input()
for s in S:
ans = chr((ord(s) - ord("A") + N) % 26 + ord("A"))
print(ans,end="")
| 6 | 5 | 226 | 121 | n = int(input())
st = [
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
]
s = input()
for i in range(len(s)):
a = (st.index(s[i]) + n) % 26
print(st[a], end="")
| N = int(input())
S = input()
for s in S:
ans = chr((ord(s) - ord("A") + N) % 26 + ord("A"))
print(ans, end="")
| false | 16.666667 | [
"-n = int(input())",
"-st = [",
"- \"A\",",
"- \"B\",",
"- \"C\",",
"- \"D\",",
"- \"E\",",
"- \"F\",",
"- \"G\",",
"- \"H\",",
"- \"I\",",
"- \"J\",",
"- \"K\",",
"- \"L\",",
"- \"M\",",
"- \"N\",",
"- \"O\",",
"- \"P\",",
"- \"Q\",",
"- \"R\",",
"- \"S\",",
"- \"T\",",
"- \"U\",",
"- \"V\",",
"- \"W\",",
"- \"X\",",
"- \"Y\",",
"- \"Z\",",
"-]",
"-s = input()",
"-for i in range(len(s)):",
"- a = (st.index(s[i]) + n) % 26",
"- print(st[a], end=\"\")",
"+N = int(input())",
"+S = input()",
"+for s in S:",
"+ ans = chr((ord(s) - ord(\"A\") + N) % 26 + ord(\"A\"))",
"+ print(ans, end=\"\")"
] | false | 0.067656 | 0.078924 | 0.857229 | [
"s348297121",
"s120630099"
] |
u214304095 | p03329 | python | s901615462 | s760633975 | 720 | 615 | 3,828 | 3,828 | Accepted | Accepted | 14.58 | n = int(eval(input()))
dp = [1000000] * 100010
dp[0] = 0
for i in range(n):
a = 1
while i + a <= 100000:
dp[i + a] = min(dp[i + a], dp[i] + 1)
a *= 6
b = 1
while i + b <= 100000:
dp[i + b] = min(dp[i + b], dp[i] + 1)
b *= 9
print((dp[n]))
| n = int(eval(input()))
dp = [1000000] * 100010
dp[0] = 0
for i in range(1, n + 1):
a = 1
while a <= i:
dp[i] = min(dp[i], dp[i - a] + 1)
a *= 6
b = 1
while b <= i:
dp[i] = min(dp[i], dp[i - b] + 1)
b *= 9
print((dp[n]))
| 13 | 13 | 291 | 272 | n = int(eval(input()))
dp = [1000000] * 100010
dp[0] = 0
for i in range(n):
a = 1
while i + a <= 100000:
dp[i + a] = min(dp[i + a], dp[i] + 1)
a *= 6
b = 1
while i + b <= 100000:
dp[i + b] = min(dp[i + b], dp[i] + 1)
b *= 9
print((dp[n]))
| n = int(eval(input()))
dp = [1000000] * 100010
dp[0] = 0
for i in range(1, n + 1):
a = 1
while a <= i:
dp[i] = min(dp[i], dp[i - a] + 1)
a *= 6
b = 1
while b <= i:
dp[i] = min(dp[i], dp[i - b] + 1)
b *= 9
print((dp[n]))
| false | 0 | [
"-for i in range(n):",
"+for i in range(1, n + 1):",
"- while i + a <= 100000:",
"- dp[i + a] = min(dp[i + a], dp[i] + 1)",
"+ while a <= i:",
"+ dp[i] = min(dp[i], dp[i - a] + 1)",
"- while i + b <= 100000:",
"- dp[i + b] = min(dp[i + b], dp[i] + 1)",
"+ while b <= i:",
"+ dp[i] = min(dp[i], dp[i - b] + 1)"
] | false | 0.373769 | 0.118932 | 3.14271 | [
"s901615462",
"s760633975"
] |
u893063840 | p02787 | python | s647753868 | s077160240 | 1,485 | 1,347 | 369,980 | 381,976 | Accepted | Accepted | 9.29 | h, n = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
dp = [[float("inf")] * (h + 1) for _ in range(n + 1)]
for i in range(n + 1):
dp[i][0] = 0
for i in range(1, n + 1):
for j in range(1, h + 1):
a, b = ab[i-1]
dp[i][j] = min(dp[i-1][j], dp[i][max(j-a, 0)] + b)
ans = dp[n][h]
print(ans)
| h, n = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
dp = [[float("inf")] * (h + 1) for _ in range(n + 1)]
for i in range(n + 1):
dp[i][0] = 0
for i, (a, b) in enumerate(ab, 1):
for j in range(h + 1):
dp[i][j] = min(dp[i-1][j], dp[i][max(j-a, 0)] + b)
ans = dp[n][h]
print(ans)
| 14 | 13 | 364 | 340 | h, n = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
dp = [[float("inf")] * (h + 1) for _ in range(n + 1)]
for i in range(n + 1):
dp[i][0] = 0
for i in range(1, n + 1):
for j in range(1, h + 1):
a, b = ab[i - 1]
dp[i][j] = min(dp[i - 1][j], dp[i][max(j - a, 0)] + b)
ans = dp[n][h]
print(ans)
| h, n = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
dp = [[float("inf")] * (h + 1) for _ in range(n + 1)]
for i in range(n + 1):
dp[i][0] = 0
for i, (a, b) in enumerate(ab, 1):
for j in range(h + 1):
dp[i][j] = min(dp[i - 1][j], dp[i][max(j - a, 0)] + b)
ans = dp[n][h]
print(ans)
| false | 7.142857 | [
"-for i in range(1, n + 1):",
"- for j in range(1, h + 1):",
"- a, b = ab[i - 1]",
"+for i, (a, b) in enumerate(ab, 1):",
"+ for j in range(h + 1):"
] | false | 0.22676 | 0.209284 | 1.083503 | [
"s647753868",
"s077160240"
] |
u105210954 | p02789 | python | s706203086 | s711345761 | 175 | 20 | 38,484 | 3,060 | Accepted | Accepted | 88.57 | n, m = list(map(int, input().split()))
if n == m:
print('Yes')
else:
print('No') | def resolve():
a, b = list(map(int, input().split()))
if a == b:
print('Yes')
else:
print('No')
resolve() | 5 | 9 | 82 | 137 | n, m = list(map(int, input().split()))
if n == m:
print("Yes")
else:
print("No")
| def resolve():
a, b = list(map(int, input().split()))
if a == b:
print("Yes")
else:
print("No")
resolve()
| false | 44.444444 | [
"-n, m = list(map(int, input().split()))",
"-if n == m:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+def resolve():",
"+ a, b = list(map(int, input().split()))",
"+ if a == b:",
"+ print(\"Yes\")",
"+ else:",
"+ print(\"No\")",
"+",
"+",
"+resolve()"
] | false | 0.044217 | 0.035933 | 1.230532 | [
"s706203086",
"s711345761"
] |
u875361824 | p03330 | python | s836729674 | s218863510 | 927 | 535 | 5,620 | 48,988 | Accepted | Accepted | 42.29 | def main():
"""
1 <= N <= 500
3 <= C <= 30
(i!=j): 1 <= D(i,j) <= 1000
(i==j): 0 = D(i,j)
1 <= c(i,j) <= C
"""
N, C = list(map(int, input().split()))
D = [
list(map(int, input().split()))
for _ in range(C)
]
c = [
list(map(int, input().split()))
for _ in range(N)
]
ans = f(N, C, c, D)
print(ans)
def TLE(N, C, c, D):
for i in range(N):
for j in range(N):
for x in range(N):
for y in range(N):
same_type = (i + j) % 3 == (x + y) % 3
c1 = c[i][j]
same_color = c1 == c[x][y]
if same_type != same_color:
D[c1-1]
return
def f(N, C, c, D):
"""
"""
t = [[0] * C for _ in range(3)]
ans = float("inf")
for i in range(N):
for j in range(N):
# 余りのパターンごとに色情報の集計
rem = (i + j) % 3
color = c[i][j]
t[rem][color - 1] += 1
for i in range(C):
for j in range(C):
if i == j:
continue
for k in range(C):
if i == k or j == k:
continue
tmp = 0
for bef in range(C):
for aft, rem in zip((i, j, k), list(range(3))):
tmp += D[bef][aft] * t[rem][bef]
ans = min(ans, tmp)
return ans
if __name__ == '__main__':
main()
| from itertools import product
def main():
"""
1 <= N <= 500
3 <= C <= 30
(i!=j): 1 <= D(i,j) <= 1000
(i==j): 0 = D(i,j)
1 <= c(i,j) <= C
"""
N, C = list(map(int, input().split()))
D = [
list(map(int, input().split()))
for _ in range(C)
]
c = [
list(map(int, input().split()))
for _ in range(N)
]
ans = f(N, C, c, D)
ans1 = fast_f(N, C, c, D)
assert ans == ans1
if N <= 30:
ans2 = TLE(N, C, c, D)
assert ans == ans2
print(ans)
def WA(N, C, c, D):
for i in range(N):
for j in range(N):
for x in range(N):
for y in range(N):
same_type = (i + j) % 3 == (x + y) % 3
c1 = c[i][j]
same_color = c1 == c[x][y]
if same_type != same_color:
D[c1-1]
return
def TLE(N, C, c, D):
"""
3色に割り当てるので C^3
"""
ans = float("inf")
for i, j, k in product(list(range(C)), repeat=3):
if i == j or i == k or j == k:
continue
tmp = 0
for x, y in product(list(range(N)), repeat=2):
rem = (x + y) % 3
bef = c[x][y] - 1
aft = [i, j, k][rem]
tmp += D[bef][aft]
ans = min(ans, tmp)
return ans
def f(N, C, c, D):
"""
"""
t = [[0] * C for _ in range(3)]
ans = float("inf")
for i in range(N):
for j in range(N):
# 余りのパターンごとに色の数を集計して圧縮
rem = (i + j) % 3
color = c[i][j]
t[rem][color - 1] += 1
for i in range(C):
for j in range(C):
if i == j:
continue
for k in range(C):
if i == k or j == k:
continue
# 余りのパターン[0,1,2]について、変更後の色の組合せを全列挙[i,j,k]
# パターンが違うなら、色も異なるので同色にならないように考慮
tmp = 0
for bef in range(C):
for aft, rem in zip((i, j, k), list(range(3))):
# 違和感 × 対象個数
tmp += D[bef][aft] * t[rem][bef]
ans = min(ans, tmp)
return ans
def fast_f(N, C, c, D):
t = [[0] * C for _ in range(3)]
ans = float("inf")
for i, j in product(list(range(N)), repeat=2):
for aft in range(C):
rem = (i + j) % 3
color = c[i][j]
# 個数だけでなく、違和感も前処理に含める
t[rem][aft] += D[color - 1][aft]
for i, j, k in product(list(range(C)), repeat=3):
if i == j or i == k or j == k:
continue
tmp = 0
for aft, rem in zip((i, j, k), list(range(3))):
tmp += t[rem][aft]
ans = min(ans, tmp)
return ans
if __name__ == '__main__':
main()
| 67 | 123 | 1,556 | 2,890 | def main():
"""
1 <= N <= 500
3 <= C <= 30
(i!=j): 1 <= D(i,j) <= 1000
(i==j): 0 = D(i,j)
1 <= c(i,j) <= C
"""
N, C = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in range(C)]
c = [list(map(int, input().split())) for _ in range(N)]
ans = f(N, C, c, D)
print(ans)
def TLE(N, C, c, D):
for i in range(N):
for j in range(N):
for x in range(N):
for y in range(N):
same_type = (i + j) % 3 == (x + y) % 3
c1 = c[i][j]
same_color = c1 == c[x][y]
if same_type != same_color:
D[c1 - 1]
return
def f(N, C, c, D):
""" """
t = [[0] * C for _ in range(3)]
ans = float("inf")
for i in range(N):
for j in range(N):
# 余りのパターンごとに色情報の集計
rem = (i + j) % 3
color = c[i][j]
t[rem][color - 1] += 1
for i in range(C):
for j in range(C):
if i == j:
continue
for k in range(C):
if i == k or j == k:
continue
tmp = 0
for bef in range(C):
for aft, rem in zip((i, j, k), list(range(3))):
tmp += D[bef][aft] * t[rem][bef]
ans = min(ans, tmp)
return ans
if __name__ == "__main__":
main()
| from itertools import product
def main():
"""
1 <= N <= 500
3 <= C <= 30
(i!=j): 1 <= D(i,j) <= 1000
(i==j): 0 = D(i,j)
1 <= c(i,j) <= C
"""
N, C = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in range(C)]
c = [list(map(int, input().split())) for _ in range(N)]
ans = f(N, C, c, D)
ans1 = fast_f(N, C, c, D)
assert ans == ans1
if N <= 30:
ans2 = TLE(N, C, c, D)
assert ans == ans2
print(ans)
def WA(N, C, c, D):
for i in range(N):
for j in range(N):
for x in range(N):
for y in range(N):
same_type = (i + j) % 3 == (x + y) % 3
c1 = c[i][j]
same_color = c1 == c[x][y]
if same_type != same_color:
D[c1 - 1]
return
def TLE(N, C, c, D):
"""
3色に割り当てるので C^3
"""
ans = float("inf")
for i, j, k in product(list(range(C)), repeat=3):
if i == j or i == k or j == k:
continue
tmp = 0
for x, y in product(list(range(N)), repeat=2):
rem = (x + y) % 3
bef = c[x][y] - 1
aft = [i, j, k][rem]
tmp += D[bef][aft]
ans = min(ans, tmp)
return ans
def f(N, C, c, D):
""" """
t = [[0] * C for _ in range(3)]
ans = float("inf")
for i in range(N):
for j in range(N):
# 余りのパターンごとに色の数を集計して圧縮
rem = (i + j) % 3
color = c[i][j]
t[rem][color - 1] += 1
for i in range(C):
for j in range(C):
if i == j:
continue
for k in range(C):
if i == k or j == k:
continue
# 余りのパターン[0,1,2]について、変更後の色の組合せを全列挙[i,j,k]
# パターンが違うなら、色も異なるので同色にならないように考慮
tmp = 0
for bef in range(C):
for aft, rem in zip((i, j, k), list(range(3))):
# 違和感 × 対象個数
tmp += D[bef][aft] * t[rem][bef]
ans = min(ans, tmp)
return ans
def fast_f(N, C, c, D):
t = [[0] * C for _ in range(3)]
ans = float("inf")
for i, j in product(list(range(N)), repeat=2):
for aft in range(C):
rem = (i + j) % 3
color = c[i][j]
# 個数だけでなく、違和感も前処理に含める
t[rem][aft] += D[color - 1][aft]
for i, j, k in product(list(range(C)), repeat=3):
if i == j or i == k or j == k:
continue
tmp = 0
for aft, rem in zip((i, j, k), list(range(3))):
tmp += t[rem][aft]
ans = min(ans, tmp)
return ans
if __name__ == "__main__":
main()
| false | 45.528455 | [
"+from itertools import product",
"+",
"+",
"+ ans1 = fast_f(N, C, c, D)",
"+ assert ans == ans1",
"+ if N <= 30:",
"+ ans2 = TLE(N, C, c, D)",
"+ assert ans == ans2",
"-def TLE(N, C, c, D):",
"+def WA(N, C, c, D):",
"+def TLE(N, C, c, D):",
"+ \"\"\"",
"+ 3色に割り当てるので C^3",
"+ \"\"\"",
"+ ans = float(\"inf\")",
"+ for i, j, k in product(list(range(C)), repeat=3):",
"+ if i == j or i == k or j == k:",
"+ continue",
"+ tmp = 0",
"+ for x, y in product(list(range(N)), repeat=2):",
"+ rem = (x + y) % 3",
"+ bef = c[x][y] - 1",
"+ aft = [i, j, k][rem]",
"+ tmp += D[bef][aft]",
"+ ans = min(ans, tmp)",
"+ return ans",
"+",
"+",
"- # 余りのパターンごとに色情報の集計",
"+ # 余りのパターンごとに色の数を集計して圧縮",
"+ # 余りのパターン[0,1,2]について、変更後の色の組合せを全列挙[i,j,k]",
"+ # パターンが違うなら、色も異なるので同色にならないように考慮",
"+ # 違和感 × 対象個数",
"+def fast_f(N, C, c, D):",
"+ t = [[0] * C for _ in range(3)]",
"+ ans = float(\"inf\")",
"+ for i, j in product(list(range(N)), repeat=2):",
"+ for aft in range(C):",
"+ rem = (i + j) % 3",
"+ color = c[i][j]",
"+ # 個数だけでなく、違和感も前処理に含める",
"+ t[rem][aft] += D[color - 1][aft]",
"+ for i, j, k in product(list(range(C)), repeat=3):",
"+ if i == j or i == k or j == k:",
"+ continue",
"+ tmp = 0",
"+ for aft, rem in zip((i, j, k), list(range(3))):",
"+ tmp += t[rem][aft]",
"+ ans = min(ans, tmp)",
"+ return ans",
"+",
"+"
] | false | 0.043594 | 0.058536 | 0.744737 | [
"s836729674",
"s218863510"
] |
u597455618 | p03855 | python | s379290698 | s640140243 | 714 | 515 | 47,836 | 49,424 | Accepted | Accepted | 27.87 | from collections import Counter
from typing import AnyStr
class UnionFind:
def __init__(self, n):
self.table = [-1] * n
def _root(self, x):
stack = []
tbl = self.table
while tbl[x] >= 0:
stack.append(x)
x = tbl[x]
for y in stack:
tbl[y] = x
return x
def find(self, x, y):
return self._root(x) == self._root(y)
def union(self, x, y):
r1 = self._root(x)
r2 = self._root(y)
if r1 == r2:
return
d1 = self.table[r1]
d2 = self.table[r2]
if d1 <= d2:
self.table[r2] = r1
self.table[r1] += d2
else:
self.table[r1] = r2
self.table[r2] += d1
def main():
n, k, l = list(map(int, input().split()))
a = UnionFind(n)
b = UnionFind(n)
for _ in range(k):
p, q = list(map(int, input().split()))
a.union(p-1, q-1)
for _ in range(l):
r, s = list(map(int, input().split()))
b.union(r-1, s-1)
pairs = []
for i in range(n):
pairs.append((a._root(i), b._root(i)))
d = Counter(pairs)
ans = [d[x] for x in pairs]
print((*ans))
if __name__ == '__main__':
main()
| from collections import Counter
import sys
class UnionFind:
def __init__(self, n):
self.table = [-1] * n
def _root(self, x):
stack = []
tbl = self.table
while tbl[x] >= 0:
stack.append(x)
x = tbl[x]
for y in stack:
tbl[y] = x
return x
def find(self, x, y):
return self._root(x) == self._root(y)
def union(self, x, y):
r1 = self._root(x)
r2 = self._root(y)
if r1 == r2:
return
d1 = self.table[r1]
d2 = self.table[r2]
if d1 <= d2:
self.table[r2] = r1
self.table[r1] += d2
else:
self.table[r1] = r2
self.table[r2] += d1
def main():
n, k, l = list(map(int, sys.stdin.buffer.readline().split()))
a = UnionFind(n)
b = UnionFind(n)
cnt = 0
for x in sys.stdin.buffer.readlines():
p, q = list(map(int, x.split()))
cnt += 1
if cnt <= k:
a.union(p-1, q-1)
else:
b.union(p-1, q-1)
pairs = []
for i in range(n):
pairs.append((a._root(i), b._root(i)))
d = Counter(pairs)
ans = [d[x] for x in pairs]
print((*ans))
if __name__ == '__main__':
main()
| 57 | 60 | 1,290 | 1,321 | from collections import Counter
from typing import AnyStr
class UnionFind:
def __init__(self, n):
self.table = [-1] * n
def _root(self, x):
stack = []
tbl = self.table
while tbl[x] >= 0:
stack.append(x)
x = tbl[x]
for y in stack:
tbl[y] = x
return x
def find(self, x, y):
return self._root(x) == self._root(y)
def union(self, x, y):
r1 = self._root(x)
r2 = self._root(y)
if r1 == r2:
return
d1 = self.table[r1]
d2 = self.table[r2]
if d1 <= d2:
self.table[r2] = r1
self.table[r1] += d2
else:
self.table[r1] = r2
self.table[r2] += d1
def main():
n, k, l = list(map(int, input().split()))
a = UnionFind(n)
b = UnionFind(n)
for _ in range(k):
p, q = list(map(int, input().split()))
a.union(p - 1, q - 1)
for _ in range(l):
r, s = list(map(int, input().split()))
b.union(r - 1, s - 1)
pairs = []
for i in range(n):
pairs.append((a._root(i), b._root(i)))
d = Counter(pairs)
ans = [d[x] for x in pairs]
print((*ans))
if __name__ == "__main__":
main()
| from collections import Counter
import sys
class UnionFind:
def __init__(self, n):
self.table = [-1] * n
def _root(self, x):
stack = []
tbl = self.table
while tbl[x] >= 0:
stack.append(x)
x = tbl[x]
for y in stack:
tbl[y] = x
return x
def find(self, x, y):
return self._root(x) == self._root(y)
def union(self, x, y):
r1 = self._root(x)
r2 = self._root(y)
if r1 == r2:
return
d1 = self.table[r1]
d2 = self.table[r2]
if d1 <= d2:
self.table[r2] = r1
self.table[r1] += d2
else:
self.table[r1] = r2
self.table[r2] += d1
def main():
n, k, l = list(map(int, sys.stdin.buffer.readline().split()))
a = UnionFind(n)
b = UnionFind(n)
cnt = 0
for x in sys.stdin.buffer.readlines():
p, q = list(map(int, x.split()))
cnt += 1
if cnt <= k:
a.union(p - 1, q - 1)
else:
b.union(p - 1, q - 1)
pairs = []
for i in range(n):
pairs.append((a._root(i), b._root(i)))
d = Counter(pairs)
ans = [d[x] for x in pairs]
print((*ans))
if __name__ == "__main__":
main()
| false | 5 | [
"-from typing import AnyStr",
"+import sys",
"- n, k, l = list(map(int, input().split()))",
"+ n, k, l = list(map(int, sys.stdin.buffer.readline().split()))",
"- for _ in range(k):",
"- p, q = list(map(int, input().split()))",
"- a.union(p - 1, q - 1)",
"- for _ in range(l):",
"- r, s = list(map(int, input().split()))",
"- b.union(r - 1, s - 1)",
"+ cnt = 0",
"+ for x in sys.stdin.buffer.readlines():",
"+ p, q = list(map(int, x.split()))",
"+ cnt += 1",
"+ if cnt <= k:",
"+ a.union(p - 1, q - 1)",
"+ else:",
"+ b.union(p - 1, q - 1)"
] | false | 0.075635 | 0.038963 | 1.941219 | [
"s379290698",
"s640140243"
] |
u773265208 | p02923 | python | s513525107 | s368711981 | 217 | 78 | 63,984 | 14,252 | Accepted | Accepted | 64.06 | n = int(eval(input()))
h = list(map(int,input().split()))
ans = 0
height = h[0]
count = 0
i = 1
while i < n:
if h[i] <= height:
count += 1
height = h[i]
i += 1
else:
ans = max(ans,count)
count = 0
height = h[i]
i += 1
print((max(ans,count)))
| n = int(eval(input()))
h = list(map(int,input().split()))
ans = 0
tmp = 0
for i in range(n-1):
if h[i] >= h[i+1]:
tmp += 1
else:
ans = max(ans,tmp)
tmp = 0
ans = max(ans,tmp)
print(ans)
| 18 | 13 | 268 | 201 | n = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
height = h[0]
count = 0
i = 1
while i < n:
if h[i] <= height:
count += 1
height = h[i]
i += 1
else:
ans = max(ans, count)
count = 0
height = h[i]
i += 1
print((max(ans, count)))
| n = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
tmp = 0
for i in range(n - 1):
if h[i] >= h[i + 1]:
tmp += 1
else:
ans = max(ans, tmp)
tmp = 0
ans = max(ans, tmp)
print(ans)
| false | 27.777778 | [
"-height = h[0]",
"-count = 0",
"-i = 1",
"-while i < n:",
"- if h[i] <= height:",
"- count += 1",
"- height = h[i]",
"- i += 1",
"+tmp = 0",
"+for i in range(n - 1):",
"+ if h[i] >= h[i + 1]:",
"+ tmp += 1",
"- ans = max(ans, count)",
"- count = 0",
"- height = h[i]",
"- i += 1",
"-print((max(ans, count)))",
"+ ans = max(ans, tmp)",
"+ tmp = 0",
"+ans = max(ans, tmp)",
"+print(ans)"
] | false | 0.037946 | 0.035626 | 1.065124 | [
"s513525107",
"s368711981"
] |
u883621917 | p03127 | python | s520315826 | s696035249 | 154 | 103 | 85,776 | 85,060 | Accepted | Accepted | 33.12 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(eval(input()))
a = list(map(int, input().split()))
import heapq
ans = 0
heapq.heapify(a)
while a:
t = heapq.heappop(a)
if ans == 0:
ans = t
continue
else:
big = max(ans, t)
small = min(ans, t)
if big % small != 0:
ans = big % small
heapq.heappush(a, small)
print(ans)
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(eval(input()))
a = list(map(int, input().split()))
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
import functools
print((functools.reduce(gcd, a)))
| 24 | 15 | 442 | 274 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(eval(input()))
a = list(map(int, input().split()))
import heapq
ans = 0
heapq.heapify(a)
while a:
t = heapq.heappop(a)
if ans == 0:
ans = t
continue
else:
big = max(ans, t)
small = min(ans, t)
if big % small != 0:
ans = big % small
heapq.heappush(a, small)
print(ans)
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(eval(input()))
a = list(map(int, input().split()))
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
import functools
print((functools.reduce(gcd, a)))
| false | 37.5 | [
"-import heapq",
"-ans = 0",
"-heapq.heapify(a)",
"-while a:",
"- t = heapq.heappop(a)",
"- if ans == 0:",
"- ans = t",
"- continue",
"+",
"+def gcd(a, b):",
"+ if b == 0:",
"+ return a",
"- big = max(ans, t)",
"- small = min(ans, t)",
"- if big % small != 0:",
"- ans = big % small",
"- heapq.heappush(a, small)",
"-print(ans)",
"+ return gcd(b, a % b)",
"+",
"+",
"+import functools",
"+",
"+print((functools.reduce(gcd, a)))"
] | false | 0.042479 | 0.041072 | 1.034255 | [
"s520315826",
"s696035249"
] |
u867826040 | p02558 | python | s210845851 | s386728512 | 777 | 371 | 11,612 | 11,848 | Accepted | Accepted | 52.25 | class UnionFind:
def __init__(self, n: int) -> None:
self.forest = [-1] * n
def union(self, x: int, y: int) -> None:
x = self.findRoot(x)
y = self.findRoot(y)
if x == y:
return
if self.forest[x] > self.forest[y]:
x, y = y, x
self.forest[x] += self.forest[y]
self.forest[y] = x
return
def findRoot(self, x: int) -> int:
if self.forest[x] < 0:
return x
else:
self.forest[x] = self.findRoot(self.forest[x])
return self.forest[x]
def issame(self, x: int, y: int) -> bool:
return self.findRoot(x) == self.findRoot(y)
def size(self, x: int) -> int:
return -self.forest[self.findRoot(x)]
n,q = list(map(int,input().split()))
uf = UnionFind(n)
for i in range(q):
ti,ui,vi = list(map(int,input().split()))
if ti:
print((int(uf.issame(ui,vi))))
else:
uf.union(vi,ui)
| import sys
class UnionFind:
def __init__(self, n: int) -> None:
self.forest = [-1] * n
def union(self, x: int, y: int) -> None:
x = self.findRoot(x)
y = self.findRoot(y)
if x == y:
return
if self.forest[x] > self.forest[y]:
x, y = y, x
self.forest[x] += self.forest[y]
self.forest[y] = x
return
def findRoot(self, x: int) -> int:
if self.forest[x] < 0:
return x
else:
self.forest[x] = self.findRoot(self.forest[x])
return self.forest[x]
def issame(self, x: int, y: int) -> bool:
return self.findRoot(x) == self.findRoot(y)
def size(self, x: int) -> int:
return -self.forest[self.findRoot(x)]
def main():
input = sys.stdin.readline
n,q = list(map(int,input().split()))
uf = UnionFind(n)
for i in range(q):
ti,ui,vi = list(map(int,input().split()))
if ti:
print((int(uf.issame(ui,vi))))
else:
uf.union(vi,ui)
if __name__ == "__main__":
main()
| 37 | 46 | 989 | 1,126 | class UnionFind:
def __init__(self, n: int) -> None:
self.forest = [-1] * n
def union(self, x: int, y: int) -> None:
x = self.findRoot(x)
y = self.findRoot(y)
if x == y:
return
if self.forest[x] > self.forest[y]:
x, y = y, x
self.forest[x] += self.forest[y]
self.forest[y] = x
return
def findRoot(self, x: int) -> int:
if self.forest[x] < 0:
return x
else:
self.forest[x] = self.findRoot(self.forest[x])
return self.forest[x]
def issame(self, x: int, y: int) -> bool:
return self.findRoot(x) == self.findRoot(y)
def size(self, x: int) -> int:
return -self.forest[self.findRoot(x)]
n, q = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(q):
ti, ui, vi = list(map(int, input().split()))
if ti:
print((int(uf.issame(ui, vi))))
else:
uf.union(vi, ui)
| import sys
class UnionFind:
def __init__(self, n: int) -> None:
self.forest = [-1] * n
def union(self, x: int, y: int) -> None:
x = self.findRoot(x)
y = self.findRoot(y)
if x == y:
return
if self.forest[x] > self.forest[y]:
x, y = y, x
self.forest[x] += self.forest[y]
self.forest[y] = x
return
def findRoot(self, x: int) -> int:
if self.forest[x] < 0:
return x
else:
self.forest[x] = self.findRoot(self.forest[x])
return self.forest[x]
def issame(self, x: int, y: int) -> bool:
return self.findRoot(x) == self.findRoot(y)
def size(self, x: int) -> int:
return -self.forest[self.findRoot(x)]
def main():
input = sys.stdin.readline
n, q = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(q):
ti, ui, vi = list(map(int, input().split()))
if ti:
print((int(uf.issame(ui, vi))))
else:
uf.union(vi, ui)
if __name__ == "__main__":
main()
| false | 19.565217 | [
"+import sys",
"+",
"+",
"-n, q = list(map(int, input().split()))",
"-uf = UnionFind(n)",
"-for i in range(q):",
"- ti, ui, vi = list(map(int, input().split()))",
"- if ti:",
"- print((int(uf.issame(ui, vi))))",
"- else:",
"- uf.union(vi, ui)",
"+def main():",
"+ input = sys.stdin.readline",
"+ n, q = list(map(int, input().split()))",
"+ uf = UnionFind(n)",
"+ for i in range(q):",
"+ ti, ui, vi = list(map(int, input().split()))",
"+ if ti:",
"+ print((int(uf.issame(ui, vi))))",
"+ else:",
"+ uf.union(vi, ui)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.101143 | 0.043161 | 2.343356 | [
"s210845851",
"s386728512"
] |
u254871849 | p03475 | python | s614456173 | s037945632 | 73 | 63 | 3,188 | 3,188 | Accepted | Accepted | 13.7 | import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
def main():
n = int(sys.stdin.readline().rstrip())
c, s, f = [], [], []
for i in range(n-1):
ci, si, fi = (int(x) for x in sys.stdin.readline().split())
c.append(ci); s.append(si); f.append(fi)
x = []
for i in range(n-1):
xi = 0
for j in range(i, n-1):
if s[j] >= xi:
xi = s[j]
xi += c[j]
else:
if (xi - s[j]) % f[j] == 0:
xi += c[j]
else:
xi += c[j] + f[j] - (xi - s[j]) % f[j]
x.append(xi)
x.append(0)
for xi in x:
print(xi)
if __name__ == "__main__":
# execute only if run as a script
main()
# 乗り換え時間がなく、一方通行の電車!
| import sys
n = int(sys.stdin.readline().rstrip())
csf = list(zip(*[map(int, sys.stdin.read().split())] * 3))
def main():
take_time = [None] * n
for i in range(n):
cur = i
t = 0
while cur < n - 1:
c, s, f = csf[cur]
if t < s:
t = s
else:
t = s + f * ((t - s + f - 1) // f)
t += c
cur += 1
take_time[i] = t
return take_time
if __name__ == '__main__':
ans = main()
print(*ans, sep='\n')
| 38 | 25 | 903 | 564 | import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
def main():
n = int(sys.stdin.readline().rstrip())
c, s, f = [], [], []
for i in range(n - 1):
ci, si, fi = (int(x) for x in sys.stdin.readline().split())
c.append(ci)
s.append(si)
f.append(fi)
x = []
for i in range(n - 1):
xi = 0
for j in range(i, n - 1):
if s[j] >= xi:
xi = s[j]
xi += c[j]
else:
if (xi - s[j]) % f[j] == 0:
xi += c[j]
else:
xi += c[j] + f[j] - (xi - s[j]) % f[j]
x.append(xi)
x.append(0)
for xi in x:
print(xi)
if __name__ == "__main__":
# execute only if run as a script
main()
# 乗り換え時間がなく、一方通行の電車!
| import sys
n = int(sys.stdin.readline().rstrip())
csf = list(zip(*[map(int, sys.stdin.read().split())] * 3))
def main():
take_time = [None] * n
for i in range(n):
cur = i
t = 0
while cur < n - 1:
c, s, f = csf[cur]
if t < s:
t = s
else:
t = s + f * ((t - s + f - 1) // f)
t += c
cur += 1
take_time[i] = t
return take_time
if __name__ == "__main__":
ans = main()
print(*ans, sep="\n")
| false | 34.210526 | [
"-# import collections",
"-# import math",
"-# import string",
"-# import bisect",
"-# import re",
"-# import itertools",
"-# import statistics",
"+n = int(sys.stdin.readline().rstrip())",
"+csf = list(zip(*[map(int, sys.stdin.read().split())] * 3))",
"+",
"+",
"- n = int(sys.stdin.readline().rstrip())",
"- c, s, f = [], [], []",
"- for i in range(n - 1):",
"- ci, si, fi = (int(x) for x in sys.stdin.readline().split())",
"- c.append(ci)",
"- s.append(si)",
"- f.append(fi)",
"- x = []",
"- for i in range(n - 1):",
"- xi = 0",
"- for j in range(i, n - 1):",
"- if s[j] >= xi:",
"- xi = s[j]",
"- xi += c[j]",
"+ take_time = [None] * n",
"+ for i in range(n):",
"+ cur = i",
"+ t = 0",
"+ while cur < n - 1:",
"+ c, s, f = csf[cur]",
"+ if t < s:",
"+ t = s",
"- if (xi - s[j]) % f[j] == 0:",
"- xi += c[j]",
"- else:",
"- xi += c[j] + f[j] - (xi - s[j]) % f[j]",
"- x.append(xi)",
"- x.append(0)",
"- for xi in x:",
"- print(xi)",
"+ t = s + f * ((t - s + f - 1) // f)",
"+ t += c",
"+ cur += 1",
"+ take_time[i] = t",
"+ return take_time",
"- # execute only if run as a script",
"- main()",
"-# 乗り換え時間がなく、一方通行の電車!",
"+ ans = main()",
"+ print(*ans, sep=\"\\n\")"
] | false | 0.044715 | 0.041527 | 1.076775 | [
"s614456173",
"s037945632"
] |
u594803920 | p02819 | python | s883229581 | s457335364 | 212 | 26 | 3,060 | 3,060 | Accepted | Accepted | 87.74 | a = int(eval(input()))
def hantei(x):
k = 0
for i in range(2, x//2):
if x % i == 0:
k += 1
if k ==0:
return x
c = True
while c:
hantei(a)
b = hantei(a)
if b is not None:
print(b)
c = False
elif b is None:
a += 1 | a = int(eval(input()))
b = True
def hantei(n, x): #素数だとFalseを返す
for i in range(2, n):
if n % i == 0:
x = True
return x
while b:
b = hantei(a, b)
if b is None:
print(a)
break
a += 1
| 18 | 13 | 303 | 251 | a = int(eval(input()))
def hantei(x):
k = 0
for i in range(2, x // 2):
if x % i == 0:
k += 1
if k == 0:
return x
c = True
while c:
hantei(a)
b = hantei(a)
if b is not None:
print(b)
c = False
elif b is None:
a += 1
| a = int(eval(input()))
b = True
def hantei(n, x): # 素数だとFalseを返す
for i in range(2, n):
if n % i == 0:
x = True
return x
while b:
b = hantei(a, b)
if b is None:
print(a)
break
a += 1
| false | 27.777778 | [
"+b = True",
"-def hantei(x):",
"- k = 0",
"- for i in range(2, x // 2):",
"- if x % i == 0:",
"- k += 1",
"- if k == 0:",
"- return x",
"+def hantei(n, x): # 素数だとFalseを返す",
"+ for i in range(2, n):",
"+ if n % i == 0:",
"+ x = True",
"+ return x",
"-c = True",
"-while c:",
"- hantei(a)",
"- b = hantei(a)",
"- if b is not None:",
"- print(b)",
"- c = False",
"- elif b is None:",
"- a += 1",
"+while b:",
"+ b = hantei(a, b)",
"+ if b is None:",
"+ print(a)",
"+ break",
"+ a += 1"
] | false | 0.065036 | 0.088032 | 0.738782 | [
"s883229581",
"s457335364"
] |
u591016708 | p02820 | python | s183371612 | s850796770 | 76 | 49 | 4,084 | 4,084 | Accepted | Accepted | 35.53 | N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
check = [0]*N
ans = 0
for i in range(N):
if i < K or T[i] != T[i-K] or not check[i-K]:
ans += P if T[i] == 'r' else R if T[i] == 's' else S
check[i] = 1
print(ans) |
def solve(N,K,R,S,P,T):
check = [0]*N
ans = 0
for i in range(N):
if i < K or T[i] != T[i-K] or not check[i-K]:
ans += P if T[i] == 'r' else R if T[i] == 's' else S
check[i] = 1
print(ans)
def main():
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
solve(N,K,R,S,P,T)
if __name__ == "__main__":
main() | 10 | 18 | 273 | 421 | N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
check = [0] * N
ans = 0
for i in range(N):
if i < K or T[i] != T[i - K] or not check[i - K]:
ans += P if T[i] == "r" else R if T[i] == "s" else S
check[i] = 1
print(ans)
| def solve(N, K, R, S, P, T):
check = [0] * N
ans = 0
for i in range(N):
if i < K or T[i] != T[i - K] or not check[i - K]:
ans += P if T[i] == "r" else R if T[i] == "s" else S
check[i] = 1
print(ans)
def main():
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
solve(N, K, R, S, P, T)
if __name__ == "__main__":
main()
| false | 44.444444 | [
"-N, K = list(map(int, input().split()))",
"-R, S, P = list(map(int, input().split()))",
"-T = eval(input())",
"-check = [0] * N",
"-ans = 0",
"-for i in range(N):",
"- if i < K or T[i] != T[i - K] or not check[i - K]:",
"- ans += P if T[i] == \"r\" else R if T[i] == \"s\" else S",
"- check[i] = 1",
"-print(ans)",
"+def solve(N, K, R, S, P, T):",
"+ check = [0] * N",
"+ ans = 0",
"+ for i in range(N):",
"+ if i < K or T[i] != T[i - K] or not check[i - K]:",
"+ ans += P if T[i] == \"r\" else R if T[i] == \"s\" else S",
"+ check[i] = 1",
"+ print(ans)",
"+",
"+",
"+def main():",
"+ N, K = list(map(int, input().split()))",
"+ R, S, P = list(map(int, input().split()))",
"+ T = eval(input())",
"+ solve(N, K, R, S, P, T)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.042561 | 0.040973 | 1.03876 | [
"s183371612",
"s850796770"
] |
u047796752 | p02838 | python | s821763225 | s261008031 | 1,686 | 711 | 200,720 | 123,132 | Accepted | Accepted | 57.83 | import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9+7
A = [format(Ai, 'b') for Ai in A]
L = max(len(Ai) for Ai in A)
A = ['0'*(L-len(Ai))+Ai for Ai in A]
ans = 0
for i in range(L):
one, zero = 0, 0
for j in range(N):
if A[j][i]=='1':
one += 1
else:
zero += 1
add = pow(2, L-i-1, MOD)*one*zero%MOD
ans += add
ans %= MOD
print(ans) | import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
MOD = 10**9+7
for i in range(65):
one = 0
zero = 0
for j in range(N):
if (A[j]>>i)&1:
one += 1
else:
zero += 1
ans += one*zero*pow(2, i, MOD)
ans %= MOD
print(ans) | 25 | 22 | 477 | 356 | import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
A = [format(Ai, "b") for Ai in A]
L = max(len(Ai) for Ai in A)
A = ["0" * (L - len(Ai)) + Ai for Ai in A]
ans = 0
for i in range(L):
one, zero = 0, 0
for j in range(N):
if A[j][i] == "1":
one += 1
else:
zero += 1
add = pow(2, L - i - 1, MOD) * one * zero % MOD
ans += add
ans %= MOD
print(ans)
| import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
MOD = 10**9 + 7
for i in range(65):
one = 0
zero = 0
for j in range(N):
if (A[j] >> i) & 1:
one += 1
else:
zero += 1
ans += one * zero * pow(2, i, MOD)
ans %= MOD
print(ans)
| false | 12 | [
"+ans = 0",
"-A = [format(Ai, \"b\") for Ai in A]",
"-L = max(len(Ai) for Ai in A)",
"-A = [\"0\" * (L - len(Ai)) + Ai for Ai in A]",
"-ans = 0",
"-for i in range(L):",
"- one, zero = 0, 0",
"+for i in range(65):",
"+ one = 0",
"+ zero = 0",
"- if A[j][i] == \"1\":",
"+ if (A[j] >> i) & 1:",
"- add = pow(2, L - i - 1, MOD) * one * zero % MOD",
"- ans += add",
"+ ans += one * zero * pow(2, i, MOD)"
] | false | 0.036961 | 0.035903 | 1.029472 | [
"s821763225",
"s261008031"
] |
u075012704 | p03946 | python | s847661415 | s720599976 | 75 | 68 | 15,060 | 15,060 | Accepted | Accepted | 9.33 | from itertools import accumulate
N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
MIN_Acc = list(accumulate(A, func=min))
Profits = [A[i] - MIN_Acc[i] for i in range(N)]
MAX_Profit = max(Profits)
ans = Profits.count(MAX_Profit)
print(ans)
| from itertools import accumulate
N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
A_MIN = list(accumulate(A, func=min))
diff = [a - a_min for a, a_min in zip(A, A_MIN)]
MAX_diff = max(diff)
print((diff.count(MAX_diff)))
| 10 | 9 | 270 | 248 | from itertools import accumulate
N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
MIN_Acc = list(accumulate(A, func=min))
Profits = [A[i] - MIN_Acc[i] for i in range(N)]
MAX_Profit = max(Profits)
ans = Profits.count(MAX_Profit)
print(ans)
| from itertools import accumulate
N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
A_MIN = list(accumulate(A, func=min))
diff = [a - a_min for a, a_min in zip(A, A_MIN)]
MAX_diff = max(diff)
print((diff.count(MAX_diff)))
| false | 10 | [
"-MIN_Acc = list(accumulate(A, func=min))",
"-Profits = [A[i] - MIN_Acc[i] for i in range(N)]",
"-MAX_Profit = max(Profits)",
"-ans = Profits.count(MAX_Profit)",
"-print(ans)",
"+A_MIN = list(accumulate(A, func=min))",
"+diff = [a - a_min for a, a_min in zip(A, A_MIN)]",
"+MAX_diff = max(diff)",
"+print((diff.count(MAX_diff)))"
] | false | 0.039696 | 0.049285 | 0.805439 | [
"s847661415",
"s720599976"
] |
u729133443 | p02782 | python | s513947381 | s984254000 | 342 | 201 | 82,220 | 54,128 | Accepted | Accepted | 41.23 | def main():
M=10**9+7
r1,c1,r2,c2=list(map(int,input().split()))
n=r2+c2+2
fac=[1]
val=1
append=fac.append
for i in range(1,n+1):
val=val*i%M
append(val)
f=lambda r,c:fac[r+c+2]*pow(fac[c+1],M-2,M)*pow(fac[r+1],M-2,M)-c-r-2
print(((f(r2,c2)-f(r2,c1-1)-f(r1-1,c2)+f(r1-1,c1-1))%M))
main() | def main():
M=10**9+7
r1,c1,r2,c2=list(map(int,input().split()))
n=r2+c2+2
fac=[0]*(n+1)
fac[0]=val=1
for i in range(1,n+1):fac[i]=val=val*i%M
f=lambda r,c:fac[r+c+2]*pow(fac[c+1],M-2,M)*pow(fac[r+1],M-2,M)-c-r-2
print(((f(r2,c2)-f(r2,c1-1)-f(r1-1,c2)+f(r1-1,c1-1))%M))
main() | 13 | 10 | 317 | 293 | def main():
M = 10**9 + 7
r1, c1, r2, c2 = list(map(int, input().split()))
n = r2 + c2 + 2
fac = [1]
val = 1
append = fac.append
for i in range(1, n + 1):
val = val * i % M
append(val)
f = (
lambda r, c: fac[r + c + 2]
* pow(fac[c + 1], M - 2, M)
* pow(fac[r + 1], M - 2, M)
- c
- r
- 2
)
print(((f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1)) % M))
main()
| def main():
M = 10**9 + 7
r1, c1, r2, c2 = list(map(int, input().split()))
n = r2 + c2 + 2
fac = [0] * (n + 1)
fac[0] = val = 1
for i in range(1, n + 1):
fac[i] = val = val * i % M
f = (
lambda r, c: fac[r + c + 2]
* pow(fac[c + 1], M - 2, M)
* pow(fac[r + 1], M - 2, M)
- c
- r
- 2
)
print(((f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1)) % M))
main()
| false | 23.076923 | [
"- fac = [1]",
"- val = 1",
"- append = fac.append",
"+ fac = [0] * (n + 1)",
"+ fac[0] = val = 1",
"- val = val * i % M",
"- append(val)",
"+ fac[i] = val = val * i % M"
] | false | 0.037294 | 0.073442 | 0.507805 | [
"s513947381",
"s984254000"
] |
u642874916 | p02735 | python | s251699990 | s799179071 | 341 | 300 | 64,620 | 62,316 | Accepted | Accepted | 12.02 | from decimal import *
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def show(*inp, end='\n'):
if show_flg:
print(*inp, end=end)
YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True
BLOCK = '#'
ROAD = '.'
def print_matrix(mat):
for i in range(len(mat)):
print(*mat[i])
def bfs(graph, initial, goal, H, W):
options = [(1, 0), (0, 1)]
q = deque([initial])
dist = [[10**9 for i in range(W)] for i in range(H)]
dist[initial[0]][initial[1]] = 0 if graph[initial[0]][initial[1]] == ROAD else 1
while len(q) != 0:
p = q.popleft()
for d in options:
i = p[0] + d[0]
j = p[1] + d[1]
if i >= 0 and i < H and j >= 0 and j < W:
if dist[i][j] == 10**9 or dist[p[0]][p[1]] < dist[i][j]:
q.append((i, j))
if graph[p[0]][p[1]] != BLOCK and graph[i][j] == BLOCK:
dist[i][j] = dist[p[0]][p[1]] + 1
else:
dist[i][j] = dist[p[0]][p[1]]
# print_matrix(dist)
return dist[goal[0]][goal[1]]
def main():
H, W = MI()
graph = [None] * H
for i in range(H):
graph[i] = list(S())
ret = bfs(graph, (0, 0), (H-1, W-1), H, W)
print(ret)
if __name__ == '__main__':
main()
| from decimal import *
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def show(*inp, end='\n'):
if show_flg:
print(*inp, end=end)
YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True
BLOCK = '#'
ROAD = '.'
def print_matrix(mat):
for i in range(len(mat)):
print(*mat[i])
def main():
H, W = MI()
graph = [None] * H
for i in range(H):
graph[i] = list(S())
dp = [[IINF] * W for i in range(H)]
dp[0][0] = 0 if graph[0][0] == ROAD else 1
for i in range(H):
for j in range(W):
for p in [(1, 0), (0, 1)]:
ni = i + p[0]
nj = j + p[1]
if ni >= 0 and ni < H and nj >= 0 and nj < W:
cost = 0
if graph[i][j] == ROAD and graph[ni][nj] == BLOCK:
cost = dp[i][j] + 1
else:
cost = dp[i][j]
dp[ni][nj] = min(cost, dp[ni][nj])
# print_matrix(dp)
print(dp[H-1][W-1])
if __name__ == '__main__':
main()
| 105 | 96 | 2,266 | 2,000 | from decimal import *
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
def I():
return int(input())
def S():
return input()
def MI():
return map(int, input().split())
def MS():
return map(str, input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def StoI():
return [ord(i) - 97 for i in input()]
def ItoS(nn):
return chr(nn + 97)
def input():
return sys.stdin.readline().rstrip()
def show(*inp, end="\n"):
if show_flg:
print(*inp, end=end)
YNL = {False: "No", True: "Yes"}
YNU = {False: "NO", True: "YES"}
MOD = 10**9 + 7
inf = float("inf")
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
show_flg = False
# show_flg = True
BLOCK = "#"
ROAD = "."
def print_matrix(mat):
for i in range(len(mat)):
print(*mat[i])
def bfs(graph, initial, goal, H, W):
options = [(1, 0), (0, 1)]
q = deque([initial])
dist = [[10**9 for i in range(W)] for i in range(H)]
dist[initial[0]][initial[1]] = 0 if graph[initial[0]][initial[1]] == ROAD else 1
while len(q) != 0:
p = q.popleft()
for d in options:
i = p[0] + d[0]
j = p[1] + d[1]
if i >= 0 and i < H and j >= 0 and j < W:
if dist[i][j] == 10**9 or dist[p[0]][p[1]] < dist[i][j]:
q.append((i, j))
if graph[p[0]][p[1]] != BLOCK and graph[i][j] == BLOCK:
dist[i][j] = dist[p[0]][p[1]] + 1
else:
dist[i][j] = dist[p[0]][p[1]]
# print_matrix(dist)
return dist[goal[0]][goal[1]]
def main():
H, W = MI()
graph = [None] * H
for i in range(H):
graph[i] = list(S())
ret = bfs(graph, (0, 0), (H - 1, W - 1), H, W)
print(ret)
if __name__ == "__main__":
main()
| from decimal import *
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
def I():
return int(input())
def S():
return input()
def MI():
return map(int, input().split())
def MS():
return map(str, input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def StoI():
return [ord(i) - 97 for i in input()]
def ItoS(nn):
return chr(nn + 97)
def input():
return sys.stdin.readline().rstrip()
def show(*inp, end="\n"):
if show_flg:
print(*inp, end=end)
YNL = {False: "No", True: "Yes"}
YNU = {False: "NO", True: "YES"}
MOD = 10**9 + 7
inf = float("inf")
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
show_flg = False
# show_flg = True
BLOCK = "#"
ROAD = "."
def print_matrix(mat):
for i in range(len(mat)):
print(*mat[i])
def main():
H, W = MI()
graph = [None] * H
for i in range(H):
graph[i] = list(S())
dp = [[IINF] * W for i in range(H)]
dp[0][0] = 0 if graph[0][0] == ROAD else 1
for i in range(H):
for j in range(W):
for p in [(1, 0), (0, 1)]:
ni = i + p[0]
nj = j + p[1]
if ni >= 0 and ni < H and nj >= 0 and nj < W:
cost = 0
if graph[i][j] == ROAD and graph[ni][nj] == BLOCK:
cost = dp[i][j] + 1
else:
cost = dp[i][j]
dp[ni][nj] = min(cost, dp[ni][nj])
# print_matrix(dp)
print(dp[H - 1][W - 1])
if __name__ == "__main__":
main()
| false | 8.571429 | [
"-def bfs(graph, initial, goal, H, W):",
"- options = [(1, 0), (0, 1)]",
"- q = deque([initial])",
"- dist = [[10**9 for i in range(W)] for i in range(H)]",
"- dist[initial[0]][initial[1]] = 0 if graph[initial[0]][initial[1]] == ROAD else 1",
"- while len(q) != 0:",
"- p = q.popleft()",
"- for d in options:",
"- i = p[0] + d[0]",
"- j = p[1] + d[1]",
"- if i >= 0 and i < H and j >= 0 and j < W:",
"- if dist[i][j] == 10**9 or dist[p[0]][p[1]] < dist[i][j]:",
"- q.append((i, j))",
"- if graph[p[0]][p[1]] != BLOCK and graph[i][j] == BLOCK:",
"- dist[i][j] = dist[p[0]][p[1]] + 1",
"- else:",
"- dist[i][j] = dist[p[0]][p[1]]",
"- # print_matrix(dist)",
"- return dist[goal[0]][goal[1]]",
"-",
"-",
"- ret = bfs(graph, (0, 0), (H - 1, W - 1), H, W)",
"- print(ret)",
"+ dp = [[IINF] * W for i in range(H)]",
"+ dp[0][0] = 0 if graph[0][0] == ROAD else 1",
"+ for i in range(H):",
"+ for j in range(W):",
"+ for p in [(1, 0), (0, 1)]:",
"+ ni = i + p[0]",
"+ nj = j + p[1]",
"+ if ni >= 0 and ni < H and nj >= 0 and nj < W:",
"+ cost = 0",
"+ if graph[i][j] == ROAD and graph[ni][nj] == BLOCK:",
"+ cost = dp[i][j] + 1",
"+ else:",
"+ cost = dp[i][j]",
"+ dp[ni][nj] = min(cost, dp[ni][nj])",
"+ # print_matrix(dp)",
"+ print(dp[H - 1][W - 1])"
] | false | 0.056117 | 0.052388 | 1.071194 | [
"s251699990",
"s799179071"
] |
u762420987 | p03031 | python | s798285622 | s251808302 | 35 | 25 | 3,064 | 3,064 | Accepted | Accepted | 28.57 | N, M = list(map(int, input().split()))
slist = [list(map(int, input().split()))[1:] for _ in range(M)]
plist = list(map(int, input().split()))
def count_on_switch(switch_array: list, on: set):
return sum([int(sw in on) for sw in switch_array])
ans = 0
# print("---")
for i in range(2**N):
on = set()
for j in range(N):
if ((i >> j) & 1):
on.add(j+1)
temp = 0
for _ in range(M):
cou_on = count_on_switch(slist[_], on)
# print(i, cou_on)
if cou_on % 2 != plist[_]:
break
else:
ans += 1
print(ans)
| N, M = list(map(int, input().split()))
s_setlist = []
for i in range(M):
k, *s = list(map(int, input().split()))
s_setlist.append(set(s))
plist = list(map(int, input().split()))
ans = 0
for i in range(2**N):
on = set()
for j in range(N):
if ((i >> j) & 1):
on.add(j+1)
light_list = [len(on&s_setlist[k])%2==plist[k] for k in range(M)]
if all(light_list):
ans += 1
print(ans)
| 23 | 17 | 602 | 438 | N, M = list(map(int, input().split()))
slist = [list(map(int, input().split()))[1:] for _ in range(M)]
plist = list(map(int, input().split()))
def count_on_switch(switch_array: list, on: set):
return sum([int(sw in on) for sw in switch_array])
ans = 0
# print("---")
for i in range(2**N):
on = set()
for j in range(N):
if (i >> j) & 1:
on.add(j + 1)
temp = 0
for _ in range(M):
cou_on = count_on_switch(slist[_], on)
# print(i, cou_on)
if cou_on % 2 != plist[_]:
break
else:
ans += 1
print(ans)
| N, M = list(map(int, input().split()))
s_setlist = []
for i in range(M):
k, *s = list(map(int, input().split()))
s_setlist.append(set(s))
plist = list(map(int, input().split()))
ans = 0
for i in range(2**N):
on = set()
for j in range(N):
if (i >> j) & 1:
on.add(j + 1)
light_list = [len(on & s_setlist[k]) % 2 == plist[k] for k in range(M)]
if all(light_list):
ans += 1
print(ans)
| false | 26.086957 | [
"-slist = [list(map(int, input().split()))[1:] for _ in range(M)]",
"+s_setlist = []",
"+for i in range(M):",
"+ k, *s = list(map(int, input().split()))",
"+ s_setlist.append(set(s))",
"-",
"-",
"-def count_on_switch(switch_array: list, on: set):",
"- return sum([int(sw in on) for sw in switch_array])",
"-",
"-",
"- temp = 0",
"- for _ in range(M):",
"- cou_on = count_on_switch(slist[_], on)",
"- # print(i, cou_on)",
"- if cou_on % 2 != plist[_]:",
"- break",
"- else:",
"+ light_list = [len(on & s_setlist[k]) % 2 == plist[k] for k in range(M)]",
"+ if all(light_list):"
] | false | 0.081281 | 0.080726 | 1.006866 | [
"s798285622",
"s251808302"
] |
u334712262 | p03725 | python | s319998257 | s465272866 | 268 | 243 | 94,944 | 95,184 | Accepted | Accepted | 9.33 | # -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(H, W, K, A):
for i in range(H):
for j in range(W):
if A[i][j] == 'S':
s = (i, j)
from collections import deque
q = deque([s])
d = [[None] * W for _ in range(H)]
d[s[0]][s[1]] = 0
ans = INF
while q:
x, y = q.popleft()
t = min(abs(x), abs(x-H+1), abs(y), abs(y-W+1))
ans = min(ans, t)
for vx, vy in [(x-1, y), (x, y-1), (x, y+1), (x+1, y)]:
if not (0 <= vx < H and 0 <= vy < W):
continue
if A[vx][vy] == '#':
continue
if d[vx][vy] is not None:
continue
c = d[x][y]
if c + 1 <= K:
q.append((vx, vy))
d[vx][vy] = c + 1
return 1 + -(-ans // K)
def main():
H, W, K = read_int_n()
A = [read_str() for _ in range(H)]
print(slv(H, W, K, A))
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(H, W, K, A):
for i in range(H):
for j in range(W):
if A[i][j] == 'S':
s = (i, j)
from collections import deque
q = deque([s])
d = [[None] * W for _ in range(H)]
d[s[0]][s[1]] = 0
ans = INF
while q:
x, y = q.popleft()
ans = min(ans, min(abs(x), abs(x-H+1), abs(y), abs(y-W+1)))
c = d[x][y]
if c + 1 > K:
continue
for vx, vy in [(x-1, y), (x, y-1), (x, y+1), (x+1, y)]:
if not (0 <= vx < H and 0 <= vy < W):
continue
if A[vx][vy] == '#':
continue
if d[vx][vy] is not None:
continue
q.append((vx, vy))
d[vx][vy] = c + 1
return 1 + -(-ans // K)
def main():
H, W, K = read_int_n()
A = [read_str() for _ in range(H)]
print(slv(H, W, K, A))
if __name__ == '__main__':
main()
| 93 | 92 | 1,855 | 1,843 | # -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
@mt
def slv(H, W, K, A):
for i in range(H):
for j in range(W):
if A[i][j] == "S":
s = (i, j)
from collections import deque
q = deque([s])
d = [[None] * W for _ in range(H)]
d[s[0]][s[1]] = 0
ans = INF
while q:
x, y = q.popleft()
t = min(abs(x), abs(x - H + 1), abs(y), abs(y - W + 1))
ans = min(ans, t)
for vx, vy in [(x - 1, y), (x, y - 1), (x, y + 1), (x + 1, y)]:
if not (0 <= vx < H and 0 <= vy < W):
continue
if A[vx][vy] == "#":
continue
if d[vx][vy] is not None:
continue
c = d[x][y]
if c + 1 <= K:
q.append((vx, vy))
d[vx][vy] = c + 1
return 1 + -(-ans // K)
def main():
H, W, K = read_int_n()
A = [read_str() for _ in range(H)]
print(slv(H, W, K, A))
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
@mt
def slv(H, W, K, A):
for i in range(H):
for j in range(W):
if A[i][j] == "S":
s = (i, j)
from collections import deque
q = deque([s])
d = [[None] * W for _ in range(H)]
d[s[0]][s[1]] = 0
ans = INF
while q:
x, y = q.popleft()
ans = min(ans, min(abs(x), abs(x - H + 1), abs(y), abs(y - W + 1)))
c = d[x][y]
if c + 1 > K:
continue
for vx, vy in [(x - 1, y), (x, y - 1), (x, y + 1), (x + 1, y)]:
if not (0 <= vx < H and 0 <= vy < W):
continue
if A[vx][vy] == "#":
continue
if d[vx][vy] is not None:
continue
q.append((vx, vy))
d[vx][vy] = c + 1
return 1 + -(-ans // K)
def main():
H, W, K = read_int_n()
A = [read_str() for _ in range(H)]
print(slv(H, W, K, A))
if __name__ == "__main__":
main()
| false | 1.075269 | [
"- t = min(abs(x), abs(x - H + 1), abs(y), abs(y - W + 1))",
"- ans = min(ans, t)",
"+ ans = min(ans, min(abs(x), abs(x - H + 1), abs(y), abs(y - W + 1)))",
"+ c = d[x][y]",
"+ if c + 1 > K:",
"+ continue",
"- c = d[x][y]",
"- if c + 1 <= K:",
"- q.append((vx, vy))",
"- d[vx][vy] = c + 1",
"+ q.append((vx, vy))",
"+ d[vx][vy] = c + 1"
] | false | 0.113384 | 0.049885 | 2.272919 | [
"s319998257",
"s465272866"
] |
u746419473 | p02899 | python | s117353898 | s216788234 | 201 | 150 | 22,564 | 25,556 | Accepted | Accepted | 25.37 | n=int(eval(input()))
a=list(map(int, input().split()))
s=[]
i=1
for _a in a:
s.append([i, _a])
i+=1
s.sort(key=lambda x: x[1])
ans=""
for i, _ in s:
ans+=str(i)+" "
print(ans)
| n = int(eval(input()))
*a, = list(map(int, input().split()))
t = []
for i, j in zip(list(range(1, n+1)), a):
t.append((i, j))
ans = []
for i in sorted(t, key=lambda x: x[1]):
ans.append(i[0])
print((" ".join(map(str, ans))))
| 15 | 11 | 199 | 225 | n = int(eval(input()))
a = list(map(int, input().split()))
s = []
i = 1
for _a in a:
s.append([i, _a])
i += 1
s.sort(key=lambda x: x[1])
ans = ""
for i, _ in s:
ans += str(i) + " "
print(ans)
| n = int(eval(input()))
(*a,) = list(map(int, input().split()))
t = []
for i, j in zip(list(range(1, n + 1)), a):
t.append((i, j))
ans = []
for i in sorted(t, key=lambda x: x[1]):
ans.append(i[0])
print((" ".join(map(str, ans))))
| false | 26.666667 | [
"-a = list(map(int, input().split()))",
"-s = []",
"-i = 1",
"-for _a in a:",
"- s.append([i, _a])",
"- i += 1",
"-s.sort(key=lambda x: x[1])",
"-ans = \"\"",
"-for i, _ in s:",
"- ans += str(i) + \" \"",
"-print(ans)",
"+(*a,) = list(map(int, input().split()))",
"+t = []",
"+for i, j in zip(list(range(1, n + 1)), a):",
"+ t.append((i, j))",
"+ans = []",
"+for i in sorted(t, key=lambda x: x[1]):",
"+ ans.append(i[0])",
"+print((\" \".join(map(str, ans))))"
] | false | 0.039709 | 0.042354 | 0.937553 | [
"s117353898",
"s216788234"
] |
u912237403 | p02242 | python | s317192194 | s254931527 | 30 | 20 | 4,816 | 4,684 | Accepted | Accepted | 33.33 | import sys
global nodes
nodes = {}
def shortest_path(GRAPH):
global nodes
p1 = 0
nodes[p1][1] = 0;
edge={}
total = 0
mini = 0
while True:
nodes[p1][0]=True
for p2 in range(len(nodes)):
if nodes[p2][0]==False and (p1, p2) in GRAPH:
tmp = nodes[p1][1] + GRAPH[(p1, p2)]
if tmp < nodes[p2][1]:
nodes[p2][1] = tmp
p1 = -1
mini = 1000000
for p2 in range(len(nodes)):
if nodes[p2][0]==False and nodes[p2][1]<mini:
p1 = p2
mini = nodes[p2][1]
if mini == 1000000:
break
return
def resultout():
for i in range(len(nodes)):
print("%d %d" %(i, nodes[i][1]))
return
n = int(input())
x = {}
for i in range(n):
seq = list(map(int,input().split()))
i2 = seq.pop(0)
n2 = seq.pop(0)
for j in range(n2):
j2 = seq.pop(0)
weight = seq.pop(0)
x[(i2, j2)] = weight
nodes[i2] = [False, 1000000]
shortest_path(x)
resultout() | import sys
def shortest_path(GRAPH, distance):
nodes = set()
p1 = 0
distance[p1] = 0
while True:
dp1 = distance[p1]
gp1 = GRAPH[p1]
status[p1]=1
for p2 in list(gp1.keys()):
tmp = gp1[p2] + dp1
if status[p2]==0 and tmp < distance[p2]:
distance[p2] = tmp
nodes.add(p2)
p1 = -1
mini = 1000000
for p2 in nodes:
if distance[p2]<mini:
p1 = p2
mini = distance[p2]
if mini == 1000000:
break
nodes.remove(p1)
return
def resultout(distance):
for i in range(len(distance)):
print("%d %d" %(i, distance[i]))
return
n = int(input())
x = [{} for i in range(n)]
status = [0 for i in range(n)]
distance = [1000000 for i in range(n)]
for i in range(n):
seq = list(map(int, input().split()))
tmp={}
for j in range(2, len(seq), 2):
j2, weight = seq[j:j+2]
tmp[j2] = weight
x[seq[0]] = tmp
status[i] = 0
shortest_path(x, distance)
resultout(distance) | 51 | 51 | 1,133 | 1,166 | import sys
global nodes
nodes = {}
def shortest_path(GRAPH):
global nodes
p1 = 0
nodes[p1][1] = 0
edge = {}
total = 0
mini = 0
while True:
nodes[p1][0] = True
for p2 in range(len(nodes)):
if nodes[p2][0] == False and (p1, p2) in GRAPH:
tmp = nodes[p1][1] + GRAPH[(p1, p2)]
if tmp < nodes[p2][1]:
nodes[p2][1] = tmp
p1 = -1
mini = 1000000
for p2 in range(len(nodes)):
if nodes[p2][0] == False and nodes[p2][1] < mini:
p1 = p2
mini = nodes[p2][1]
if mini == 1000000:
break
return
def resultout():
for i in range(len(nodes)):
print("%d %d" % (i, nodes[i][1]))
return
n = int(input())
x = {}
for i in range(n):
seq = list(map(int, input().split()))
i2 = seq.pop(0)
n2 = seq.pop(0)
for j in range(n2):
j2 = seq.pop(0)
weight = seq.pop(0)
x[(i2, j2)] = weight
nodes[i2] = [False, 1000000]
shortest_path(x)
resultout()
| import sys
def shortest_path(GRAPH, distance):
nodes = set()
p1 = 0
distance[p1] = 0
while True:
dp1 = distance[p1]
gp1 = GRAPH[p1]
status[p1] = 1
for p2 in list(gp1.keys()):
tmp = gp1[p2] + dp1
if status[p2] == 0 and tmp < distance[p2]:
distance[p2] = tmp
nodes.add(p2)
p1 = -1
mini = 1000000
for p2 in nodes:
if distance[p2] < mini:
p1 = p2
mini = distance[p2]
if mini == 1000000:
break
nodes.remove(p1)
return
def resultout(distance):
for i in range(len(distance)):
print("%d %d" % (i, distance[i]))
return
n = int(input())
x = [{} for i in range(n)]
status = [0 for i in range(n)]
distance = [1000000 for i in range(n)]
for i in range(n):
seq = list(map(int, input().split()))
tmp = {}
for j in range(2, len(seq), 2):
j2, weight = seq[j : j + 2]
tmp[j2] = weight
x[seq[0]] = tmp
status[i] = 0
shortest_path(x, distance)
resultout(distance)
| false | 0 | [
"-global nodes",
"-nodes = {}",
"-",
"-def shortest_path(GRAPH):",
"- global nodes",
"+def shortest_path(GRAPH, distance):",
"+ nodes = set()",
"- nodes[p1][1] = 0",
"- edge = {}",
"- total = 0",
"- mini = 0",
"+ distance[p1] = 0",
"- nodes[p1][0] = True",
"- for p2 in range(len(nodes)):",
"- if nodes[p2][0] == False and (p1, p2) in GRAPH:",
"- tmp = nodes[p1][1] + GRAPH[(p1, p2)]",
"- if tmp < nodes[p2][1]:",
"- nodes[p2][1] = tmp",
"+ dp1 = distance[p1]",
"+ gp1 = GRAPH[p1]",
"+ status[p1] = 1",
"+ for p2 in list(gp1.keys()):",
"+ tmp = gp1[p2] + dp1",
"+ if status[p2] == 0 and tmp < distance[p2]:",
"+ distance[p2] = tmp",
"+ nodes.add(p2)",
"- for p2 in range(len(nodes)):",
"- if nodes[p2][0] == False and nodes[p2][1] < mini:",
"+ for p2 in nodes:",
"+ if distance[p2] < mini:",
"- mini = nodes[p2][1]",
"+ mini = distance[p2]",
"+ nodes.remove(p1)",
"-def resultout():",
"- for i in range(len(nodes)):",
"- print(\"%d %d\" % (i, nodes[i][1]))",
"+def resultout(distance):",
"+ for i in range(len(distance)):",
"+ print(\"%d %d\" % (i, distance[i]))",
"-x = {}",
"+x = [{} for i in range(n)]",
"+status = [0 for i in range(n)]",
"+distance = [1000000 for i in range(n)]",
"- i2 = seq.pop(0)",
"- n2 = seq.pop(0)",
"- for j in range(n2):",
"- j2 = seq.pop(0)",
"- weight = seq.pop(0)",
"- x[(i2, j2)] = weight",
"- nodes[i2] = [False, 1000000]",
"-shortest_path(x)",
"-resultout()",
"+ tmp = {}",
"+ for j in range(2, len(seq), 2):",
"+ j2, weight = seq[j : j + 2]",
"+ tmp[j2] = weight",
"+ x[seq[0]] = tmp",
"+ status[i] = 0",
"+shortest_path(x, distance)",
"+resultout(distance)"
] | false | 0.11292 | 0.106128 | 1.064001 | [
"s317192194",
"s254931527"
] |
u296518383 | p02578 | python | s604760835 | s190569098 | 128 | 112 | 94,332 | 92,644 | Accepted | Accepted | 12.5 | from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos
MOD = 10 ** 9 + 7
INF = 10 ** 18
N = int(eval(input()))
#N, M = map(int, input().split())
A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]
#S = input()
#S = [input() for _ in range(N)]
if N == 1:
print((0))
exit()
answer = 0
max_a = A[0]
for a in A[1:]:
max_a = max(max_a, a)
answer += max_a - a
print(answer) | from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
N = int(eval(input()))
A = list(map(int, input().split()))
answer = 0
max_a = A[0]
for a in A:
max_a = max(max_a, a)
answer += max_a - a
print(answer) | 34 | 14 | 841 | 240 | from sys import stdin, setrecursionlimit
# input = stdin.buffer.readline
setrecursionlimit(10**7)
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos
MOD = 10**9 + 7
INF = 10**18
N = int(eval(input()))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# A = [int(input()) for _ in range(N)]
# ABC = [list(map(int, input().split())) for _ in range(N)]
# S = input()
# S = [input() for _ in range(N)]
if N == 1:
print((0))
exit()
answer = 0
max_a = A[0]
for a in A[1:]:
max_a = max(max_a, a)
answer += max_a - a
print(answer)
| from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
N = int(eval(input()))
A = list(map(int, input().split()))
answer = 0
max_a = A[0]
for a in A:
max_a = max(max_a, a)
answer += max_a - a
print(answer)
| false | 58.823529 | [
"-# input = stdin.buffer.readline",
"-setrecursionlimit(10**7)",
"-from heapq import heappush, heappop",
"-from bisect import bisect_left, bisect_right",
"-from collections import deque, defaultdict, Counter",
"-from itertools import combinations, permutations, combinations_with_replacement",
"-from itertools import accumulate",
"-from math import ceil, sqrt, pi, radians, sin, cos",
"-",
"-MOD = 10**9 + 7",
"-INF = 10**18",
"+input = stdin.buffer.readline",
"-# N, M = map(int, input().split())",
"-# A = [int(input()) for _ in range(N)]",
"-# ABC = [list(map(int, input().split())) for _ in range(N)]",
"-# S = input()",
"-# S = [input() for _ in range(N)]",
"-if N == 1:",
"- print((0))",
"- exit()",
"-for a in A[1:]:",
"+for a in A:"
] | false | 0.062247 | 0.044766 | 1.390506 | [
"s604760835",
"s190569098"
] |
u014333473 | p03598 | python | s373802449 | s200019737 | 33 | 28 | 9,032 | 9,116 | Accepted | Accepted | 15.15 | _,k=eval(input()),int(eval(input()));print((sum([min(i,(k-i))*2 for i in list(map(int,input().split()))]))) | _,k=eval(input()),int(eval(input()));print((sum(min(i,(k-i))*2 for i in list(map(int,input().split()))))) | 1 | 1 | 93 | 91 | _, k = eval(input()), int(eval(input()))
print((sum([min(i, (k - i)) * 2 for i in list(map(int, input().split()))])))
| _, k = eval(input()), int(eval(input()))
print((sum(min(i, (k - i)) * 2 for i in list(map(int, input().split())))))
| false | 0 | [
"-print((sum([min(i, (k - i)) * 2 for i in list(map(int, input().split()))])))",
"+print((sum(min(i, (k - i)) * 2 for i in list(map(int, input().split())))))"
] | false | 0.04406 | 0.107261 | 0.410774 | [
"s373802449",
"s200019737"
] |
u281610856 | p02695 | python | s838994169 | s632869053 | 601 | 391 | 9,148 | 9,228 | Accepted | Accepted | 34.94 | from itertools import permutations, accumulate, combinations, combinations_with_replacement
import sys
input = sys.stdin.readline
def main():
n, m, q = list(map(int, input().split()))
# <方針>:Aを全列挙する
ans = 0
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
a[i], b[i], c[i], d[i] = list(map(int, input().split()))
a[i] -= 1
b[i] -= 1
for A in combinations_with_replacement(list(range(1, m + 1)), n):
tmp = 0
for i in range(q):
if A[b[i]] - A[a[i]] == c[i]:
tmp += d[i]
ans = max(ans, tmp)
print(ans)
if __name__ == '__main__':
main() | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
n, m, q = list(map(int, input().split()))
l = [tuple(map(int, input().split())) for _ in range(q)]
ans = 0
def dfs(u, A):
global n, m, q, l, ans
if len(A) == n: # lの長さがnになったらscoreの計算をする
score = 0
for i in range(q):
a, b, c, d = l[i]
a, b, = a - 1, b - 1
if A[b] - A[a] == c:
score += d
ans = max(ans, score)
else: # 再帰的にリストに番号を追加していく
for i in range(u, m + 1):
dfs(i, A + [i])
def main():
dfs(1, [1])
print(ans)
if __name__ == '__main__':
main() | 28 | 30 | 683 | 665 | from itertools import (
permutations,
accumulate,
combinations,
combinations_with_replacement,
)
import sys
input = sys.stdin.readline
def main():
n, m, q = list(map(int, input().split()))
# <方針>:Aを全列挙する
ans = 0
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
a[i], b[i], c[i], d[i] = list(map(int, input().split()))
a[i] -= 1
b[i] -= 1
for A in combinations_with_replacement(list(range(1, m + 1)), n):
tmp = 0
for i in range(q):
if A[b[i]] - A[a[i]] == c[i]:
tmp += d[i]
ans = max(ans, tmp)
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
n, m, q = list(map(int, input().split()))
l = [tuple(map(int, input().split())) for _ in range(q)]
ans = 0
def dfs(u, A):
global n, m, q, l, ans
if len(A) == n: # lの長さがnになったらscoreの計算をする
score = 0
for i in range(q):
a, b, c, d = l[i]
a, b, = (
a - 1,
b - 1,
)
if A[b] - A[a] == c:
score += d
ans = max(ans, score)
else: # 再帰的にリストに番号を追加していく
for i in range(u, m + 1):
dfs(i, A + [i])
def main():
dfs(1, [1])
print(ans)
if __name__ == "__main__":
main()
| false | 6.666667 | [
"-from itertools import (",
"- permutations,",
"- accumulate,",
"- combinations,",
"- combinations_with_replacement,",
"-)",
"+sys.setrecursionlimit(10**6)",
"+n, m, q = list(map(int, input().split()))",
"+l = [tuple(map(int, input().split())) for _ in range(q)]",
"+ans = 0",
"+",
"+",
"+def dfs(u, A):",
"+ global n, m, q, l, ans",
"+ if len(A) == n: # lの長さがnになったらscoreの計算をする",
"+ score = 0",
"+ for i in range(q):",
"+ a, b, c, d = l[i]",
"+ a, b, = (",
"+ a - 1,",
"+ b - 1,",
"+ )",
"+ if A[b] - A[a] == c:",
"+ score += d",
"+ ans = max(ans, score)",
"+ else: # 再帰的にリストに番号を追加していく",
"+ for i in range(u, m + 1):",
"+ dfs(i, A + [i])",
"- n, m, q = list(map(int, input().split()))",
"- # <方針>:Aを全列挙する",
"- ans = 0",
"- a = [0] * q",
"- b = [0] * q",
"- c = [0] * q",
"- d = [0] * q",
"- for i in range(q):",
"- a[i], b[i], c[i], d[i] = list(map(int, input().split()))",
"- a[i] -= 1",
"- b[i] -= 1",
"- for A in combinations_with_replacement(list(range(1, m + 1)), n):",
"- tmp = 0",
"- for i in range(q):",
"- if A[b[i]] - A[a[i]] == c[i]:",
"- tmp += d[i]",
"- ans = max(ans, tmp)",
"+ dfs(1, [1])"
] | false | 0.045353 | 0.104949 | 0.432149 | [
"s838994169",
"s632869053"
] |
u607563136 | p02900 | python | s869591646 | s404794218 | 191 | 108 | 9,320 | 9,436 | Accepted | Accepted | 43.46 | def division(n):
if n < 2:
return [1]
prime_factors = [1]
for i in range(2,int(n**0.5)+1):
while n % i == 0:
prime_factors.append(i)
n //= i
if n > 1:
prime_factors.append(n)
return prime_factors
a,b = list(map(int,input().split()))
da = set(division(a))
db = set(division(b))
cnt = 0
for i in da:
if i in db:
cnt += 1
print(cnt) | from math import gcd
def division(n):
if n < 2:
return [1]
prime_factors = [1]
for i in range(2,int(n**0.5)+1):
while n % i == 0:
prime_factors.append(i)
n //= i
if n > 1:
prime_factors.append(n)
return prime_factors
a,b = list(map(int,input().split()))
d = set(division(gcd(a,b)))
print((len(d))) | 23 | 16 | 429 | 373 | def division(n):
if n < 2:
return [1]
prime_factors = [1]
for i in range(2, int(n**0.5) + 1):
while n % i == 0:
prime_factors.append(i)
n //= i
if n > 1:
prime_factors.append(n)
return prime_factors
a, b = list(map(int, input().split()))
da = set(division(a))
db = set(division(b))
cnt = 0
for i in da:
if i in db:
cnt += 1
print(cnt)
| from math import gcd
def division(n):
if n < 2:
return [1]
prime_factors = [1]
for i in range(2, int(n**0.5) + 1):
while n % i == 0:
prime_factors.append(i)
n //= i
if n > 1:
prime_factors.append(n)
return prime_factors
a, b = list(map(int, input().split()))
d = set(division(gcd(a, b)))
print((len(d)))
| false | 30.434783 | [
"+from math import gcd",
"+",
"+",
"-da = set(division(a))",
"-db = set(division(b))",
"-cnt = 0",
"-for i in da:",
"- if i in db:",
"- cnt += 1",
"-print(cnt)",
"+d = set(division(gcd(a, b)))",
"+print((len(d)))"
] | false | 0.047606 | 0.036564 | 1.301995 | [
"s869591646",
"s404794218"
] |
u876742094 | p03944 | python | s783715312 | s370997855 | 121 | 33 | 9,328 | 9,236 | Accepted | Accepted | 72.73 | import itertools
W,H,N=list(map(int,input().split()))
xya=[list(map(int,input().split())) for i in range(N)]
res=[[True for j in range(H)] for i in range(W)]
for j in range(H):
for i in range(W):
for k in range(N):
if (i<xya[k][0] and xya[k][2]==1) or (i>=xya[k][0] and xya[k][2]==2) or (j<xya[k][1] and xya[k][2]==3) or (j>=xya[k][1] and xya[k][2]==4):
res[i][j]=False
break
res2=list(itertools.chain.from_iterable(res))
print((res2.count(True)))
| W,H,N=list(map(int,input().split()))
xya=[list(map(int,input().split())) for i in range(N)]
first=[0,0]
last=[W,H]
for i in range(N):
if first[0]<xya[i][0] and xya[i][2]==1:
first[0]=xya[i][0]
if last[0]>xya[i][0] and xya[i][2]==2:
last[0]=xya[i][0]
if first[1]<xya[i][1] and xya[i][2]==3:
first[1]=xya[i][1]
if last[1]>xya[i][1] and xya[i][2]==4:
last[1]=xya[i][1]
area=0
if last[0]<=first[0] or last[1]<=first[1]:
pass
else:
area=(last[0]-first[0])*(last[1]-first[1])
print(area)
| 14 | 23 | 511 | 558 | import itertools
W, H, N = list(map(int, input().split()))
xya = [list(map(int, input().split())) for i in range(N)]
res = [[True for j in range(H)] for i in range(W)]
for j in range(H):
for i in range(W):
for k in range(N):
if (
(i < xya[k][0] and xya[k][2] == 1)
or (i >= xya[k][0] and xya[k][2] == 2)
or (j < xya[k][1] and xya[k][2] == 3)
or (j >= xya[k][1] and xya[k][2] == 4)
):
res[i][j] = False
break
res2 = list(itertools.chain.from_iterable(res))
print((res2.count(True)))
| W, H, N = list(map(int, input().split()))
xya = [list(map(int, input().split())) for i in range(N)]
first = [0, 0]
last = [W, H]
for i in range(N):
if first[0] < xya[i][0] and xya[i][2] == 1:
first[0] = xya[i][0]
if last[0] > xya[i][0] and xya[i][2] == 2:
last[0] = xya[i][0]
if first[1] < xya[i][1] and xya[i][2] == 3:
first[1] = xya[i][1]
if last[1] > xya[i][1] and xya[i][2] == 4:
last[1] = xya[i][1]
area = 0
if last[0] <= first[0] or last[1] <= first[1]:
pass
else:
area = (last[0] - first[0]) * (last[1] - first[1])
print(area)
| false | 39.130435 | [
"-import itertools",
"-",
"-res = [[True for j in range(H)] for i in range(W)]",
"-for j in range(H):",
"- for i in range(W):",
"- for k in range(N):",
"- if (",
"- (i < xya[k][0] and xya[k][2] == 1)",
"- or (i >= xya[k][0] and xya[k][2] == 2)",
"- or (j < xya[k][1] and xya[k][2] == 3)",
"- or (j >= xya[k][1] and xya[k][2] == 4)",
"- ):",
"- res[i][j] = False",
"- break",
"-res2 = list(itertools.chain.from_iterable(res))",
"-print((res2.count(True)))",
"+first = [0, 0]",
"+last = [W, H]",
"+for i in range(N):",
"+ if first[0] < xya[i][0] and xya[i][2] == 1:",
"+ first[0] = xya[i][0]",
"+ if last[0] > xya[i][0] and xya[i][2] == 2:",
"+ last[0] = xya[i][0]",
"+ if first[1] < xya[i][1] and xya[i][2] == 3:",
"+ first[1] = xya[i][1]",
"+ if last[1] > xya[i][1] and xya[i][2] == 4:",
"+ last[1] = xya[i][1]",
"+area = 0",
"+if last[0] <= first[0] or last[1] <= first[1]:",
"+ pass",
"+else:",
"+ area = (last[0] - first[0]) * (last[1] - first[1])",
"+print(area)"
] | false | 0.075838 | 0.037379 | 2.028909 | [
"s783715312",
"s370997855"
] |
u729133443 | p03547 | python | s271213746 | s991593853 | 168 | 17 | 38,384 | 2,940 | Accepted | Accepted | 89.88 | a,b=input().split();print(('=><'[a>b or-(a<b)])) | x,_,y=eval(input());print(('=><'[(x>y)-(x<y)])) | 1 | 1 | 46 | 39 | a, b = input().split()
print(("=><"[a > b or -(a < b)]))
| x, _, y = eval(input())
print(("=><"[(x > y) - (x < y)]))
| false | 0 | [
"-a, b = input().split()",
"-print((\"=><\"[a > b or -(a < b)]))",
"+x, _, y = eval(input())",
"+print((\"=><\"[(x > y) - (x < y)]))"
] | false | 0.03602 | 0.036569 | 0.984971 | [
"s271213746",
"s991593853"
] |
u098012509 | p02733 | python | s652303069 | s292928915 | 1,310 | 1,087 | 52,060 | 45,916 | Accepted | Accepted | 17.02 | import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
def main():
H, W, K = [int(x) for x in input().split()]
S = [list(input().strip()) for _ in range(H)]
ans = float("inf")
for n in range(2 ** (H - 1)):
tmp = 0
wn = [0] * 10
wi = [set() for _ in range(10)]
ni = 0
for i in range(H):
wi[ni].add(i)
if n >> i & 1:
ni += 1
tmp += 1
for i in range(W):
f = False
for j in range(H):
for wii in range(ni + 1):
if j in wi[wii]:
if wn[wii] + int(S[j][i]) > K:
tmp += 1
f = True
else:
wn[wii] += int(S[j][i])
break
if f:
break
if f:
for wii in range(ni + 1):
wn[wii] = 0
for j in range(H):
for wii in range(ni + 1):
if j in wi[wii]:
wn[wii] += int(S[j][i])
break
for wii in range(ni + 1):
if wn[wii] > K:
tmp = float("inf")
ans = min(ans, tmp)
print(ans)
if __name__ == '__main__':
main()
| import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
def main():
H, W, K = [int(x) for x in input().split()]
S = [list(input().strip()) for _ in range(H)]
ans = float("inf")
for n in range(2 ** (H - 1)):
tmp = 0
wn = [0] * 10
for i in range(H):
if n >> i & 1:
tmp += 1
for i in range(W):
f = False
ni = 0
for j in range(H):
if wn[ni] + int(S[j][i]) > K:
tmp += 1
f = True
break
else:
wn[ni] += int(S[j][i])
if n >> j & 1:
ni += 1
if f:
if i == 0:
tmp = float("inf")
for j in range(H):
wn[j] = 0
ni = 0
for j in range(H):
wn[ni] += int(S[j][i])
if wn[ni] > K:
tmp = float("inf")
if n >> j & 1:
ni += 1
ans = min(ans, tmp)
print(ans)
if __name__ == '__main__':
main()
| 57 | 53 | 1,476 | 1,246 | import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
def main():
H, W, K = [int(x) for x in input().split()]
S = [list(input().strip()) for _ in range(H)]
ans = float("inf")
for n in range(2 ** (H - 1)):
tmp = 0
wn = [0] * 10
wi = [set() for _ in range(10)]
ni = 0
for i in range(H):
wi[ni].add(i)
if n >> i & 1:
ni += 1
tmp += 1
for i in range(W):
f = False
for j in range(H):
for wii in range(ni + 1):
if j in wi[wii]:
if wn[wii] + int(S[j][i]) > K:
tmp += 1
f = True
else:
wn[wii] += int(S[j][i])
break
if f:
break
if f:
for wii in range(ni + 1):
wn[wii] = 0
for j in range(H):
for wii in range(ni + 1):
if j in wi[wii]:
wn[wii] += int(S[j][i])
break
for wii in range(ni + 1):
if wn[wii] > K:
tmp = float("inf")
ans = min(ans, tmp)
print(ans)
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
def main():
H, W, K = [int(x) for x in input().split()]
S = [list(input().strip()) for _ in range(H)]
ans = float("inf")
for n in range(2 ** (H - 1)):
tmp = 0
wn = [0] * 10
for i in range(H):
if n >> i & 1:
tmp += 1
for i in range(W):
f = False
ni = 0
for j in range(H):
if wn[ni] + int(S[j][i]) > K:
tmp += 1
f = True
break
else:
wn[ni] += int(S[j][i])
if n >> j & 1:
ni += 1
if f:
if i == 0:
tmp = float("inf")
for j in range(H):
wn[j] = 0
ni = 0
for j in range(H):
wn[ni] += int(S[j][i])
if wn[ni] > K:
tmp = float("inf")
if n >> j & 1:
ni += 1
ans = min(ans, tmp)
print(ans)
if __name__ == "__main__":
main()
| false | 7.017544 | [
"- wi = [set() for _ in range(10)]",
"- ni = 0",
"- wi[ni].add(i)",
"- ni += 1",
"+ ni = 0",
"- for wii in range(ni + 1):",
"- if j in wi[wii]:",
"- if wn[wii] + int(S[j][i]) > K:",
"- tmp += 1",
"- f = True",
"- else:",
"- wn[wii] += int(S[j][i])",
"- break",
"- if f:",
"+ if wn[ni] + int(S[j][i]) > K:",
"+ tmp += 1",
"+ f = True",
"+ else:",
"+ wn[ni] += int(S[j][i])",
"+ if n >> j & 1:",
"+ ni += 1",
"- for wii in range(ni + 1):",
"- wn[wii] = 0",
"+ if i == 0:",
"+ tmp = float(\"inf\")",
"- for wii in range(ni + 1):",
"- if j in wi[wii]:",
"- wn[wii] += int(S[j][i])",
"- break",
"- for wii in range(ni + 1):",
"- if wn[wii] > K:",
"+ wn[j] = 0",
"+ ni = 0",
"+ for j in range(H):",
"+ wn[ni] += int(S[j][i])",
"+ if wn[ni] > K:",
"+ if n >> j & 1:",
"+ ni += 1"
] | false | 0.041636 | 0.038593 | 1.078844 | [
"s652303069",
"s292928915"
] |
u202751685 | p02681 | python | s421801821 | s762018349 | 24 | 19 | 9,100 | 9,036 | Accepted | Accepted | 20.83 | a = eval(input())
b = eval(input())
ans = True
for i in range(len(a)):
if a[i] != b[i]:
ans = False
break
if ans:
print("Yes")
else:
print("No")
| s = eval(input())
t = eval(input())
t = t[:-1]
if s == t:
print("Yes")
else:
print("No") | 14 | 8 | 167 | 90 | a = eval(input())
b = eval(input())
ans = True
for i in range(len(a)):
if a[i] != b[i]:
ans = False
break
if ans:
print("Yes")
else:
print("No")
| s = eval(input())
t = eval(input())
t = t[:-1]
if s == t:
print("Yes")
else:
print("No")
| false | 42.857143 | [
"-a = eval(input())",
"-b = eval(input())",
"-ans = True",
"-for i in range(len(a)):",
"- if a[i] != b[i]:",
"- ans = False",
"- break",
"-if ans:",
"+s = eval(input())",
"+t = eval(input())",
"+t = t[:-1]",
"+if s == t:"
] | false | 0.114005 | 0.041882 | 2.722056 | [
"s421801821",
"s762018349"
] |
u020604402 | p04000 | python | s781797228 | s711281843 | 2,088 | 1,922 | 143,380 | 143,420 | Accepted | Accepted | 7.95 | H, W , N = list(map(int,input().split()))
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
x,y = list(map(int,input().split()))
x -= 1
y -= 1
matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
for x_r in [-2, -1 , 0]:
for y_r in [-2, -1 , 0]:
nowx = l[0] + x_r
nowy = l[1] + y_r
if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
continue
#ここで起点(左上)nowx, nowy として 9マスに着目する
name = str(nowx) + ' ' +str(nowy)
if name in cand : cand[name] += 1
else: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in list(cand.values()):
ans[x] += 1
tmp -= 1
ans[0] = tmp
for x in ans:
print(x)
| H, W , N = list(map(int,input().split()))
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
x,y = list(map(int,input().split()))
x -= 1
y -= 1
matrix.append([x,y])
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
for x_r in [-2, -1 , 0]:
for y_r in [-2, -1 , 0]:
nowx = l[0] + x_r
nowy = l[1] + y_r
if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
continue
#ここで起点(左上)nowx, nowy として 9マスに着目する
name = str(nowx) + ' ' +str(nowy)
if name in cand : cand[name] += 1
else: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in list(cand.values()):
ans[x] += 1
tmp -= 1
ans[0] = tmp
for x in ans:
print(x)
| 30 | 29 | 819 | 804 | H, W, N = list(map(int, input().split()))
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
x, y = list(map(int, input().split()))
x -= 1
y -= 1
matrix.append([x, y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
for x_r in [-2, -1, 0]:
for y_r in [-2, -1, 0]:
nowx = l[0] + x_r
nowy = l[1] + y_r
if nowx < 0 or nowy < 0 or nowx + 2 >= H or nowy + 2 >= W:
continue
# ここで起点(左上)nowx, nowy として 9マスに着目する
name = str(nowx) + " " + str(nowy)
if name in cand:
cand[name] += 1
else:
cand[name] = 1
tmp = (H - 2) * (W - 2)
for x in list(cand.values()):
ans[x] += 1
tmp -= 1
ans[0] = tmp
for x in ans:
print(x)
| H, W, N = list(map(int, input().split()))
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
x, y = list(map(int, input().split()))
x -= 1
y -= 1
matrix.append([x, y])
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
for x_r in [-2, -1, 0]:
for y_r in [-2, -1, 0]:
nowx = l[0] + x_r
nowy = l[1] + y_r
if nowx < 0 or nowy < 0 or nowx + 2 >= H or nowy + 2 >= W:
continue
# ここで起点(左上)nowx, nowy として 9マスに着目する
name = str(nowx) + " " + str(nowy)
if name in cand:
cand[name] += 1
else:
cand[name] = 1
tmp = (H - 2) * (W - 2)
for x in list(cand.values()):
ans[x] += 1
tmp -= 1
ans[0] = tmp
for x in ans:
print(x)
| false | 3.333333 | [
"-matrix.sort()"
] | false | 0.046087 | 0.086268 | 0.534231 | [
"s781797228",
"s711281843"
] |
u956937655 | p02912 | python | s376281742 | s789091066 | 260 | 226 | 14,380 | 14,380 | Accepted | Accepted | 13.08 | import math
import heapq
N, M = list(map(int, input().split()))
A = list([-int(a) for a in input().split()])
A.sort()
heapq.heapify(A)
for i in range(M):
a = heapq.heappop(A)
a = -(-a / 2.0)
heapq.heappush(A, a)
amount = 0
for a in A:
amount += math.floor(-a)
print(amount) | import math
import heapq
N, M = list(map(int, input().split()))
A = list([-int(a) for a in input().split()])
A.sort()
heapq.heapify(A)
for i in range(M):
a = heapq.heappop(A)
a /= 2.0
heapq.heappush(A, a)
amount = 0
for a in A:
amount += math.floor(-a)
print(amount) | 17 | 17 | 305 | 298 | import math
import heapq
N, M = list(map(int, input().split()))
A = list([-int(a) for a in input().split()])
A.sort()
heapq.heapify(A)
for i in range(M):
a = heapq.heappop(A)
a = -(-a / 2.0)
heapq.heappush(A, a)
amount = 0
for a in A:
amount += math.floor(-a)
print(amount)
| import math
import heapq
N, M = list(map(int, input().split()))
A = list([-int(a) for a in input().split()])
A.sort()
heapq.heapify(A)
for i in range(M):
a = heapq.heappop(A)
a /= 2.0
heapq.heappush(A, a)
amount = 0
for a in A:
amount += math.floor(-a)
print(amount)
| false | 0 | [
"- a = -(-a / 2.0)",
"+ a /= 2.0"
] | false | 0.055262 | 0.054948 | 1.005725 | [
"s376281742",
"s789091066"
] |
u237362582 | p03559 | python | s796184780 | s941120698 | 408 | 360 | 23,328 | 23,360 | Accepted | Accepted | 11.76 | N = int(eval(input()))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
sorted_a = sorted(a)
sorted_b = sorted(b)
sorted_c = sorted(c)
ans = 0
before_a = 0
before_c = 0
count_a = 0
count_c_rest = 0
for each_b in sorted_b:
for ai in range(before_a, len(sorted_a)):
if each_b > sorted_a[ai]:
count_a += 1
before_a += 1
else:
before_a = ai
break
for ci in range(before_c, len(sorted_c)):
if sorted_c[ci] <= each_b:
count_c_rest += 1
before_c += 1
else:
before_c = ci
break
ans += count_a * (len(sorted_c)-count_c_rest)
print(ans)
| import bisect
N = int(eval(input()))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
sorted_a = sorted(a)
sorted_c = sorted(c)
ans = 0
for each_b in b:
ai = bisect.bisect_left(sorted_a, each_b)
ci = bisect.bisect_right(sorted_c, each_b)
ans += ai * (len(c)-ci)
print(ans)
| 32 | 15 | 763 | 363 | N = int(eval(input()))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
c = list(map(int, input().split(" ")))
sorted_a = sorted(a)
sorted_b = sorted(b)
sorted_c = sorted(c)
ans = 0
before_a = 0
before_c = 0
count_a = 0
count_c_rest = 0
for each_b in sorted_b:
for ai in range(before_a, len(sorted_a)):
if each_b > sorted_a[ai]:
count_a += 1
before_a += 1
else:
before_a = ai
break
for ci in range(before_c, len(sorted_c)):
if sorted_c[ci] <= each_b:
count_c_rest += 1
before_c += 1
else:
before_c = ci
break
ans += count_a * (len(sorted_c) - count_c_rest)
print(ans)
| import bisect
N = int(eval(input()))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
c = list(map(int, input().split(" ")))
sorted_a = sorted(a)
sorted_c = sorted(c)
ans = 0
for each_b in b:
ai = bisect.bisect_left(sorted_a, each_b)
ci = bisect.bisect_right(sorted_c, each_b)
ans += ai * (len(c) - ci)
print(ans)
| false | 53.125 | [
"+import bisect",
"+",
"-sorted_b = sorted(b)",
"-before_a = 0",
"-before_c = 0",
"-count_a = 0",
"-count_c_rest = 0",
"-for each_b in sorted_b:",
"- for ai in range(before_a, len(sorted_a)):",
"- if each_b > sorted_a[ai]:",
"- count_a += 1",
"- before_a += 1",
"- else:",
"- before_a = ai",
"- break",
"- for ci in range(before_c, len(sorted_c)):",
"- if sorted_c[ci] <= each_b:",
"- count_c_rest += 1",
"- before_c += 1",
"- else:",
"- before_c = ci",
"- break",
"- ans += count_a * (len(sorted_c) - count_c_rest)",
"+for each_b in b:",
"+ ai = bisect.bisect_left(sorted_a, each_b)",
"+ ci = bisect.bisect_right(sorted_c, each_b)",
"+ ans += ai * (len(c) - ci)"
] | false | 0.046712 | 0.094991 | 0.491757 | [
"s796184780",
"s941120698"
] |
u503111914 | p02971 | python | s424740073 | s625687049 | 661 | 562 | 23,328 | 14,128 | Accepted | Accepted | 14.98 | import numpy as np
N = int(eval(input()))
num_list = [int(eval(input())) for i in range(N)]
a = max(num_list)
if num_list.count(a) > 1:
for j in range(N):
print(a)
else:
b = np.sort(num_list)
c = b[-2]
for k in range(int(num_list.index(a))):
print(a)
print(c)
for l in range(N-int(num_list.index(a))-1):
print(a) | N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
B = sorted(A,reverse=True)
max1 = B[0]
max2 = B[1]
for i in range(N):
if A[i] == max1:
print(max2)
else:
print(max1) | 15 | 10 | 338 | 203 | import numpy as np
N = int(eval(input()))
num_list = [int(eval(input())) for i in range(N)]
a = max(num_list)
if num_list.count(a) > 1:
for j in range(N):
print(a)
else:
b = np.sort(num_list)
c = b[-2]
for k in range(int(num_list.index(a))):
print(a)
print(c)
for l in range(N - int(num_list.index(a)) - 1):
print(a)
| N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
B = sorted(A, reverse=True)
max1 = B[0]
max2 = B[1]
for i in range(N):
if A[i] == max1:
print(max2)
else:
print(max1)
| false | 33.333333 | [
"-import numpy as np",
"-",
"-num_list = [int(eval(input())) for i in range(N)]",
"-a = max(num_list)",
"-if num_list.count(a) > 1:",
"- for j in range(N):",
"- print(a)",
"-else:",
"- b = np.sort(num_list)",
"- c = b[-2]",
"- for k in range(int(num_list.index(a))):",
"- print(a)",
"- print(c)",
"- for l in range(N - int(num_list.index(a)) - 1):",
"- print(a)",
"+A = [int(eval(input())) for i in range(N)]",
"+B = sorted(A, reverse=True)",
"+max1 = B[0]",
"+max2 = B[1]",
"+for i in range(N):",
"+ if A[i] == max1:",
"+ print(max2)",
"+ else:",
"+ print(max1)"
] | false | 0.387541 | 0.074599 | 5.194976 | [
"s424740073",
"s625687049"
] |
u346812984 | p02873 | python | s323463950 | s721953356 | 377 | 319 | 24,092 | 23,336 | Accepted | Accepted | 15.38 | S = eval(input())
ans = [0 for i in range(len(S) + 1)]
for i in range(len(S)):
if "<" == S[i]:
ans[i + 1] = ans[i] + 1
for i in range(len(S) - 1, -1, -1):
if ">" == S[i]:
ans[i] = max(ans[i], ans[i + 1] + 1)
print((sum(ans)))
| S = eval(input())
N = len(S) + 1
ans = [0] * N
for i in range(N - 1):
if S[i] == "<":
if ans[i] < ans[i + 1]:
continue
else:
ans[i + 1] = ans[i] + 1
for i in range(N - 1, 0, -1):
if S[i - 1] == ">":
if ans[i - 1] > ans[i]:
continue
else:
ans[i - 1] = ans[i] + 1
print((sum(ans)))
| 12 | 18 | 256 | 379 | S = eval(input())
ans = [0 for i in range(len(S) + 1)]
for i in range(len(S)):
if "<" == S[i]:
ans[i + 1] = ans[i] + 1
for i in range(len(S) - 1, -1, -1):
if ">" == S[i]:
ans[i] = max(ans[i], ans[i + 1] + 1)
print((sum(ans)))
| S = eval(input())
N = len(S) + 1
ans = [0] * N
for i in range(N - 1):
if S[i] == "<":
if ans[i] < ans[i + 1]:
continue
else:
ans[i + 1] = ans[i] + 1
for i in range(N - 1, 0, -1):
if S[i - 1] == ">":
if ans[i - 1] > ans[i]:
continue
else:
ans[i - 1] = ans[i] + 1
print((sum(ans)))
| false | 33.333333 | [
"-ans = [0 for i in range(len(S) + 1)]",
"-for i in range(len(S)):",
"- if \"<\" == S[i]:",
"- ans[i + 1] = ans[i] + 1",
"-for i in range(len(S) - 1, -1, -1):",
"- if \">\" == S[i]:",
"- ans[i] = max(ans[i], ans[i + 1] + 1)",
"+N = len(S) + 1",
"+ans = [0] * N",
"+for i in range(N - 1):",
"+ if S[i] == \"<\":",
"+ if ans[i] < ans[i + 1]:",
"+ continue",
"+ else:",
"+ ans[i + 1] = ans[i] + 1",
"+for i in range(N - 1, 0, -1):",
"+ if S[i - 1] == \">\":",
"+ if ans[i - 1] > ans[i]:",
"+ continue",
"+ else:",
"+ ans[i - 1] = ans[i] + 1"
] | false | 0.045388 | 0.044937 | 1.010028 | [
"s323463950",
"s721953356"
] |
u380524497 | p02703 | python | s223492002 | s703572133 | 619 | 494 | 24,232 | 23,840 | Accepted | Accepted | 20.19 | def main():
import heapq
n, m, s = list(map(int, input().split()))
if s >= 2500:
s = 2499
edges = [[] for _ in range(n)]
for _ in range(m):
from_, to, cost, time = list(map(int, input().split()))
edges[from_-1].append((to-1, cost, time))
edges[to-1].append((from_-1, cost, time))
banks = []
for i in range(n):
coin, time = list(map(int, input().split()))
banks.append((coin, time))
INF = float('INF')
DP = [[INF] * 2500 for _ in range(n)]
DP[0][s] = 0
ans = [INF] * n
def push_todo(node, coin, time):
if coin < 0:
return
if time >= DP[node][coin]:
return
heapq.heappush(todo, (time, node, coin))
DP[node][coin] = time
def charge(node, current_coin, current_time):
coin, time = banks[node]
new_coin = current_coin + coin
if new_coin >= 2500:
new_coin = 2499
push_todo(node, new_coin, current_time+time)
todo = [(0, 0, s)] # time, node, coin
while todo:
current_time, node, current_coin = heapq.heappop(todo)
if current_time > DP[node][current_coin]:
continue
if current_time < ans[node]:
ans[node] = current_time
charge(node, current_coin, current_time)
for to, cost, time in edges[node]:
push_todo(to, current_coin-cost, current_time+time)
for a in ans[1:]:
print(a)
if __name__ == '__main__':
main()
| def main():
import heapq
n, m, s = list(map(int, input().split()))
edges = [[] for _ in range(n)]
max_cost = 0
for _ in range(m):
from_, to, cost, time = list(map(int, input().split()))
edges[from_-1].append((to-1, cost, time))
edges[to-1].append((from_-1, cost, time))
if cost > max_cost:
max_cost = cost
banks = []
for i in range(n):
coin, time = list(map(int, input().split()))
banks.append((coin, time))
max_coin = max_cost * (n-1)
if s > max_coin:
s = max_coin
INF = float('INF')
DP = [[INF] * (max_coin+1) for _ in range(n)]
DP[0][s] = 0
def push_todo(node, coin, time):
if coin < 0:
return
if time >= DP[node][coin]:
return
heapq.heappush(todo, (time, node, coin))
DP[node][coin] = time
def charge(node, current_coin, current_time):
coin, time = banks[node]
new_coin = current_coin + coin
if new_coin > max_coin:
new_coin = max_coin
push_todo(node, new_coin, current_time+time)
todo = [(0, 0, s)] # time, node, coin
while todo:
current_time, node, current_coin = heapq.heappop(todo)
if current_time > DP[node][current_coin]:
continue
charge(node, current_coin, current_time)
for to, cost, time in edges[node]:
push_todo(to, current_coin-cost, current_time+time)
for node in range(1, n):
print((min(DP[node])))
if __name__ == '__main__':
main() | 58 | 59 | 1,554 | 1,606 | def main():
import heapq
n, m, s = list(map(int, input().split()))
if s >= 2500:
s = 2499
edges = [[] for _ in range(n)]
for _ in range(m):
from_, to, cost, time = list(map(int, input().split()))
edges[from_ - 1].append((to - 1, cost, time))
edges[to - 1].append((from_ - 1, cost, time))
banks = []
for i in range(n):
coin, time = list(map(int, input().split()))
banks.append((coin, time))
INF = float("INF")
DP = [[INF] * 2500 for _ in range(n)]
DP[0][s] = 0
ans = [INF] * n
def push_todo(node, coin, time):
if coin < 0:
return
if time >= DP[node][coin]:
return
heapq.heappush(todo, (time, node, coin))
DP[node][coin] = time
def charge(node, current_coin, current_time):
coin, time = banks[node]
new_coin = current_coin + coin
if new_coin >= 2500:
new_coin = 2499
push_todo(node, new_coin, current_time + time)
todo = [(0, 0, s)] # time, node, coin
while todo:
current_time, node, current_coin = heapq.heappop(todo)
if current_time > DP[node][current_coin]:
continue
if current_time < ans[node]:
ans[node] = current_time
charge(node, current_coin, current_time)
for to, cost, time in edges[node]:
push_todo(to, current_coin - cost, current_time + time)
for a in ans[1:]:
print(a)
if __name__ == "__main__":
main()
| def main():
import heapq
n, m, s = list(map(int, input().split()))
edges = [[] for _ in range(n)]
max_cost = 0
for _ in range(m):
from_, to, cost, time = list(map(int, input().split()))
edges[from_ - 1].append((to - 1, cost, time))
edges[to - 1].append((from_ - 1, cost, time))
if cost > max_cost:
max_cost = cost
banks = []
for i in range(n):
coin, time = list(map(int, input().split()))
banks.append((coin, time))
max_coin = max_cost * (n - 1)
if s > max_coin:
s = max_coin
INF = float("INF")
DP = [[INF] * (max_coin + 1) for _ in range(n)]
DP[0][s] = 0
def push_todo(node, coin, time):
if coin < 0:
return
if time >= DP[node][coin]:
return
heapq.heappush(todo, (time, node, coin))
DP[node][coin] = time
def charge(node, current_coin, current_time):
coin, time = banks[node]
new_coin = current_coin + coin
if new_coin > max_coin:
new_coin = max_coin
push_todo(node, new_coin, current_time + time)
todo = [(0, 0, s)] # time, node, coin
while todo:
current_time, node, current_coin = heapq.heappop(todo)
if current_time > DP[node][current_coin]:
continue
charge(node, current_coin, current_time)
for to, cost, time in edges[node]:
push_todo(to, current_coin - cost, current_time + time)
for node in range(1, n):
print((min(DP[node])))
if __name__ == "__main__":
main()
| false | 1.694915 | [
"- if s >= 2500:",
"- s = 2499",
"+ max_cost = 0",
"+ if cost > max_cost:",
"+ max_cost = cost",
"+ max_coin = max_cost * (n - 1)",
"+ if s > max_coin:",
"+ s = max_coin",
"- DP = [[INF] * 2500 for _ in range(n)]",
"+ DP = [[INF] * (max_coin + 1) for _ in range(n)]",
"- ans = [INF] * n",
"- if new_coin >= 2500:",
"- new_coin = 2499",
"+ if new_coin > max_coin:",
"+ new_coin = max_coin",
"- if current_time < ans[node]:",
"- ans[node] = current_time",
"- for a in ans[1:]:",
"- print(a)",
"+ for node in range(1, n):",
"+ print((min(DP[node])))"
] | false | 0.059817 | 0.049533 | 1.207627 | [
"s223492002",
"s703572133"
] |
u191829404 | p03041 | python | s741455095 | s529010155 | 32 | 23 | 3,796 | 3,540 | Accepted | Accepted | 28.12 | # https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde s=input() s='abcde'
# abcde s=list(input()) s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ) a=int(input()) a=5
# 1 2 | x,y = s_inpl() | x=1,y=2
# 1 2 3 4 5 ... n li = input().split() li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n li = inpl() li=[1,2,3,4,5,...,n]
# FFFTFTTFF li = input().split('T') li=['FFF', 'F', '', 'FF']
# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき,A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def i_inpl(): return int(eval(input()))
def s_inpl(): return list(map(int,input().split()))
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")
############
N, K = s_inpl()
S = eval(input())
ans = ""
for i, s in enumerate(S):
if i+1 == K:
s = s.lower()
ans = ans + s
print(ans) | # abcde s=input() s='abcde'
# abcde s=list(input()) s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ) a=int(input()) a=5
# 1 2 | x,y = s_inpl() | x=1,y=2
# 1 2 3 4 5 ... n li = input().split() li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n li = inpl() li=[1,2,3,4,5,...,n]
# FFFTFTTFF li = input().split('T') li=['FFF', 'F', '', 'FF']
# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき,A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def i_inpl(): return int(eval(input()))
def s_inpl(): return list(map(int,input().split()))
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")
############
############
############
N, K = l_inpl()
S = eval(input())
ans = ""
for i in range(N):
s = S[i]
if i == K-1:
s = s.lower()
ans = ans + s
print(ans) | 57 | 58 | 1,452 | 1,427 | # https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde s=input() s='abcde'
# abcde s=list(input()) s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ) a=int(input()) a=5
# 1 2 | x,y = s_inpl() | x=1,y=2
# 1 2 3 4 5 ... n li = input().split() li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n li = inpl() li=[1,2,3,4,5,...,n]
# FFFTFTTFF li = input().split('T') li=['FFF', 'F', '', 'FF']
# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき,A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def i_inpl():
return int(eval(input()))
def s_inpl():
return list(map(int, input().split()))
def l_inpl():
return list(map(int, input().split()))
INF = float("inf")
############
N, K = s_inpl()
S = eval(input())
ans = ""
for i, s in enumerate(S):
if i + 1 == K:
s = s.lower()
ans = ans + s
print(ans)
| # abcde s=input() s='abcde'
# abcde s=list(input()) s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ) a=int(input()) a=5
# 1 2 | x,y = s_inpl() | x=1,y=2
# 1 2 3 4 5 ... n li = input().split() li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n li = inpl() li=[1,2,3,4,5,...,n]
# FFFTFTTFF li = input().split('T') li=['FFF', 'F', '', 'FF']
# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき,A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def i_inpl():
return int(eval(input()))
def s_inpl():
return list(map(int, input().split()))
def l_inpl():
return list(map(int, input().split()))
INF = float("inf")
############
############
############
N, K = l_inpl()
S = eval(input())
ans = ""
for i in range(N):
s = S[i]
if i == K - 1:
s = s.lower()
ans = ans + s
print(ans)
| false | 1.724138 | [
"-# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0",
"-N, K = s_inpl()",
"+############",
"+############",
"+N, K = l_inpl()",
"-for i, s in enumerate(S):",
"- if i + 1 == K:",
"+for i in range(N):",
"+ s = S[i]",
"+ if i == K - 1:"
] | false | 0.007904 | 0.066134 | 0.119522 | [
"s741455095",
"s529010155"
] |
u303059352 | p02971 | python | s800372603 | s995793357 | 635 | 518 | 15,636 | 14,108 | Accepted | Accepted | 18.43 | n=int(eval(input()))
a=[int(eval(input()))for _ in range(n)]
left=[0]
for i in a:
left.append(max(left[-1],i))
right=[0]
for i in reversed(a):
right.append(max(right[-1],i))
right.reverse()
for i in range(n):
print((max(left[i],right[i+1])))
| n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
b = sorted(a)
max1, max2 = b[-1], b[-2]
for i in a:
if i == max1:
print(max2)
else:
print(max1) | 11 | 9 | 244 | 181 | n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
left = [0]
for i in a:
left.append(max(left[-1], i))
right = [0]
for i in reversed(a):
right.append(max(right[-1], i))
right.reverse()
for i in range(n):
print((max(left[i], right[i + 1])))
| n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
b = sorted(a)
max1, max2 = b[-1], b[-2]
for i in a:
if i == max1:
print(max2)
else:
print(max1)
| false | 18.181818 | [
"-a = [int(eval(input())) for _ in range(n)]",
"-left = [0]",
"+a = [int(eval(input())) for i in range(n)]",
"+b = sorted(a)",
"+max1, max2 = b[-1], b[-2]",
"- left.append(max(left[-1], i))",
"-right = [0]",
"-for i in reversed(a):",
"- right.append(max(right[-1], i))",
"-right.reverse()",
"-for i in range(n):",
"- print((max(left[i], right[i + 1])))",
"+ if i == max1:",
"+ print(max2)",
"+ else:",
"+ print(max1)"
] | false | 0.153555 | 0.169805 | 0.904302 | [
"s800372603",
"s995793357"
] |
u129978636 | p03548 | python | s452207670 | s068274087 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | X, Y, Z = list(map( int, input().split()))
m = X - Z
n = Y + Z
print((m//n)) | X, Y, Z = list(map( int, input().split()))
m = X - Z
print((m//(Y+Z)))
| 4 | 3 | 71 | 65 | X, Y, Z = list(map(int, input().split()))
m = X - Z
n = Y + Z
print((m // n))
| X, Y, Z = list(map(int, input().split()))
m = X - Z
print((m // (Y + Z)))
| false | 25 | [
"-n = Y + Z",
"-print((m // n))",
"+print((m // (Y + Z)))"
] | false | 0.042182 | 0.042327 | 0.996563 | [
"s452207670",
"s068274087"
] |
u560867850 | p03401 | python | s109951688 | s636039741 | 206 | 181 | 14,044 | 14,044 | Accepted | Accepted | 12.14 | import sys
input = sys.stdin.readline
def costs(a):
prev = 0
for x in a:
yield abs(x - prev)
prev = x
def main():
eval(input())
A = [0] + [int(c) for c in input().split()] + [0]
total = sum(costs(A))
for i, x in enumerate(A):
if i == 0 or i == len(A)-1: continue
prev_cost = abs(x - A[i-1])
succ_cost = abs(A[i+1] - x)
print((total - (prev_cost+succ_cost) + abs(A[i+1]-A[i-1])))
if __name__ == "__main__":
main() | import sys
input = sys.stdin.readline
def costs(a):
prev = 0
for x in a:
yield abs(x - prev)
prev = x
def main():
eval(input())
A = [0] + [int(c) for c in input().split()] + [0]
total = sum(costs(A))
for i, x in enumerate(A[1:-1],1):
prev_cost = abs(x - A[i-1])
succ_cost = abs(A[i+1] - x)
print((total - (prev_cost+succ_cost) + abs(A[i+1]-A[i-1])))
if __name__ == "__main__":
main() | 21 | 20 | 503 | 465 | import sys
input = sys.stdin.readline
def costs(a):
prev = 0
for x in a:
yield abs(x - prev)
prev = x
def main():
eval(input())
A = [0] + [int(c) for c in input().split()] + [0]
total = sum(costs(A))
for i, x in enumerate(A):
if i == 0 or i == len(A) - 1:
continue
prev_cost = abs(x - A[i - 1])
succ_cost = abs(A[i + 1] - x)
print((total - (prev_cost + succ_cost) + abs(A[i + 1] - A[i - 1])))
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def costs(a):
prev = 0
for x in a:
yield abs(x - prev)
prev = x
def main():
eval(input())
A = [0] + [int(c) for c in input().split()] + [0]
total = sum(costs(A))
for i, x in enumerate(A[1:-1], 1):
prev_cost = abs(x - A[i - 1])
succ_cost = abs(A[i + 1] - x)
print((total - (prev_cost + succ_cost) + abs(A[i + 1] - A[i - 1])))
if __name__ == "__main__":
main()
| false | 4.761905 | [
"- for i, x in enumerate(A):",
"- if i == 0 or i == len(A) - 1:",
"- continue",
"+ for i, x in enumerate(A[1:-1], 1):"
] | false | 0.039168 | 0.080097 | 0.489008 | [
"s109951688",
"s636039741"
] |
u089230684 | p03165 | python | s813894193 | s553824288 | 406 | 371 | 56,800 | 153,080 | Accepted | Accepted | 8.62 | def main():
import numpy as np
s = np.array(list(eval(input())), np.str)
sl = len(s)
t = np.array(list(eval(input())), np.str)
tl = len(t)
equal = (s[:, None] == t[None, :])
dp = [np.zeros(tl + 1, np.int32)]
for i in range(sl):
tmp = dp[-1].copy()
np.maximum(tmp[1:], tmp[:-1] + equal[i], out=tmp[1:])
np.maximum.accumulate(tmp, out=tmp)
dp.append(tmp)
answer = ''
while sl > 0 and tl > 0:
if s[sl - 1] == t[tl - 1]:
sl -= 1
tl -= 1
answer += s[sl]
continue
if dp[sl - 1][tl] > dp[sl][tl - 1]:
sl -= 1
else:
tl -= 1
print((answer[::-1]))
if __name__ == '__main__':
main() | s = eval(input())
t = eval(input())
n = len(s)
m = len(t)
dp = [[0 for j in range(1 + m)] for i in range(1 + n)]
for i in range(1, n + 1):
for j in range(1, m + 1):
if s[i - 1] == t[j - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1
else:
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
res = ""
i, j = n, m
while i > 0 and j > 0:
if dp[i][j] == dp[i - 1][j]:
i -= 1
elif dp[i][j] == dp[i][j - 1]:
j -= 1
else:
res = s[i - 1] + res
i -= 1
j -= 1
print(res) | 33 | 23 | 691 | 546 | def main():
import numpy as np
s = np.array(list(eval(input())), np.str)
sl = len(s)
t = np.array(list(eval(input())), np.str)
tl = len(t)
equal = s[:, None] == t[None, :]
dp = [np.zeros(tl + 1, np.int32)]
for i in range(sl):
tmp = dp[-1].copy()
np.maximum(tmp[1:], tmp[:-1] + equal[i], out=tmp[1:])
np.maximum.accumulate(tmp, out=tmp)
dp.append(tmp)
answer = ""
while sl > 0 and tl > 0:
if s[sl - 1] == t[tl - 1]:
sl -= 1
tl -= 1
answer += s[sl]
continue
if dp[sl - 1][tl] > dp[sl][tl - 1]:
sl -= 1
else:
tl -= 1
print((answer[::-1]))
if __name__ == "__main__":
main()
| s = eval(input())
t = eval(input())
n = len(s)
m = len(t)
dp = [[0 for j in range(1 + m)] for i in range(1 + n)]
for i in range(1, n + 1):
for j in range(1, m + 1):
if s[i - 1] == t[j - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1
else:
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
res = ""
i, j = n, m
while i > 0 and j > 0:
if dp[i][j] == dp[i - 1][j]:
i -= 1
elif dp[i][j] == dp[i][j - 1]:
j -= 1
else:
res = s[i - 1] + res
i -= 1
j -= 1
print(res)
| false | 30.30303 | [
"-def main():",
"- import numpy as np",
"-",
"- s = np.array(list(eval(input())), np.str)",
"- sl = len(s)",
"- t = np.array(list(eval(input())), np.str)",
"- tl = len(t)",
"- equal = s[:, None] == t[None, :]",
"- dp = [np.zeros(tl + 1, np.int32)]",
"- for i in range(sl):",
"- tmp = dp[-1].copy()",
"- np.maximum(tmp[1:], tmp[:-1] + equal[i], out=tmp[1:])",
"- np.maximum.accumulate(tmp, out=tmp)",
"- dp.append(tmp)",
"- answer = \"\"",
"- while sl > 0 and tl > 0:",
"- if s[sl - 1] == t[tl - 1]:",
"- sl -= 1",
"- tl -= 1",
"- answer += s[sl]",
"- continue",
"- if dp[sl - 1][tl] > dp[sl][tl - 1]:",
"- sl -= 1",
"+s = eval(input())",
"+t = eval(input())",
"+n = len(s)",
"+m = len(t)",
"+dp = [[0 for j in range(1 + m)] for i in range(1 + n)]",
"+for i in range(1, n + 1):",
"+ for j in range(1, m + 1):",
"+ if s[i - 1] == t[j - 1]:",
"+ dp[i][j] = dp[i - 1][j - 1] + 1",
"- tl -= 1",
"- print((answer[::-1]))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])",
"+res = \"\"",
"+i, j = n, m",
"+while i > 0 and j > 0:",
"+ if dp[i][j] == dp[i - 1][j]:",
"+ i -= 1",
"+ elif dp[i][j] == dp[i][j - 1]:",
"+ j -= 1",
"+ else:",
"+ res = s[i - 1] + res",
"+ i -= 1",
"+ j -= 1",
"+print(res)"
] | false | 0.257561 | 0.043155 | 5.968244 | [
"s813894193",
"s553824288"
] |
u109133010 | p03331 | python | s717572469 | s155229718 | 188 | 104 | 2,940 | 3,060 | Accepted | Accepted | 44.68 | N=int(eval(input()))
def f(x):
s=0
while x!=0:
s+=x%10
x//=10
return(s)
minn=50
for i in range(1,N):
minn=min(f(i)+f(N-i),minn)
print(minn) | N=int(eval(input()))
def f(x):
s=0
while x!=0:
s+=x%10
x//=10
return(s)
minn=50
for i in range(1,N//2+1):
minn=min(f(i)+f(N-i),minn)
print(minn) | 11 | 11 | 159 | 164 | N = int(eval(input()))
def f(x):
s = 0
while x != 0:
s += x % 10
x //= 10
return s
minn = 50
for i in range(1, N):
minn = min(f(i) + f(N - i), minn)
print(minn)
| N = int(eval(input()))
def f(x):
s = 0
while x != 0:
s += x % 10
x //= 10
return s
minn = 50
for i in range(1, N // 2 + 1):
minn = min(f(i) + f(N - i), minn)
print(minn)
| false | 0 | [
"-for i in range(1, N):",
"+for i in range(1, N // 2 + 1):"
] | false | 0.102656 | 0.048205 | 2.129587 | [
"s717572469",
"s155229718"
] |
u540877546 | p02659 | python | s661130152 | s450694382 | 26 | 23 | 10,064 | 10,016 | Accepted | Accepted | 11.54 | from decimal import *
getcontext().prec = 32
a, b = list(map(Decimal, input().split()))
print((int(a*b)))
| from decimal import Decimal
a, b = list(map(Decimal, input().split()))
print((int(a*b)))
| 4 | 3 | 107 | 89 | from decimal import *
getcontext().prec = 32
a, b = list(map(Decimal, input().split()))
print((int(a * b)))
| from decimal import Decimal
a, b = list(map(Decimal, input().split()))
print((int(a * b)))
| false | 25 | [
"-from decimal import *",
"+from decimal import Decimal",
"-getcontext().prec = 32"
] | false | 0.079863 | 0.03839 | 2.080334 | [
"s661130152",
"s450694382"
] |
u608241985 | p02725 | python | s174694620 | s791803978 | 124 | 92 | 32,296 | 31,788 | Accepted | Accepted | 25.81 | k, n = list(map(int, input().split()))
A = list(map(int, input().split()))
farthest = (k-A[-1])+A[0]
for i in range(len(A)-1):
farthest = max(farthest, A[i+1]-A[i])
print((k-farthest))
| k, n, *A = list(map(int, open(0).read().split()))
far = k + A[0] - A[-1]
for x, y in zip(A[1:], A):
if far < x - y:
far = x - y
print((k-far)) | 7 | 6 | 188 | 151 | k, n = list(map(int, input().split()))
A = list(map(int, input().split()))
farthest = (k - A[-1]) + A[0]
for i in range(len(A) - 1):
farthest = max(farthest, A[i + 1] - A[i])
print((k - farthest))
| k, n, *A = list(map(int, open(0).read().split()))
far = k + A[0] - A[-1]
for x, y in zip(A[1:], A):
if far < x - y:
far = x - y
print((k - far))
| false | 14.285714 | [
"-k, n = list(map(int, input().split()))",
"-A = list(map(int, input().split()))",
"-farthest = (k - A[-1]) + A[0]",
"-for i in range(len(A) - 1):",
"- farthest = max(farthest, A[i + 1] - A[i])",
"-print((k - farthest))",
"+k, n, *A = list(map(int, open(0).read().split()))",
"+far = k + A[0] - A[-1]",
"+for x, y in zip(A[1:], A):",
"+ if far < x - y:",
"+ far = x - y",
"+print((k - far))"
] | false | 0.039504 | 0.038853 | 1.016757 | [
"s174694620",
"s791803978"
] |
u777923818 | p03602 | python | s829468530 | s936804290 | 643 | 454 | 46,812 | 43,996 | Accepted | Accepted | 29.39 | # -*- coding: utf-8 -*-
from itertools import combinations
def inpl(): return tuple(map(int, input().split()))
N = int(eval(input()))
res = 0
exist = True
A = []
for _ in range(N):
A.append(inpl())
for i, j in combinations(list(range(N)), 2):
vervose = False
for k in range(N):
if A[i][j] > A[i][k] + A[k][j]:
exist = False
break
if not exist:
break
for k in range(N):
if i == k or j == k:
pass
elif A[i][j] == A[i][k] + A[k][j]:
vervose = True
break
if not vervose:
res += A[i][j]
if exist:
print(res)
else:
print((-1)) | # -*- coding: utf-8 -*-
from itertools import combinations
def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
res = 0
exist = True
A = []
for _ in range(N):
A.append(inpl())
for i, j in combinations(list(range(N)), 2):
vervose = False
if not exist:
break
for k in range(N):
if i == k or j == k:
pass
else:
if A[i][j] < A[i][k] + A[k][j]:
pass
elif A[i][j] == A[i][k] + A[k][j]:
vervose = True
else:
exist = False
break
if vervose:
pass
else:
res += A[i][j]
if exist:
print(res)
else:
print((-1)) | 37 | 39 | 698 | 740 | # -*- coding: utf-8 -*-
from itertools import combinations
def inpl():
return tuple(map(int, input().split()))
N = int(eval(input()))
res = 0
exist = True
A = []
for _ in range(N):
A.append(inpl())
for i, j in combinations(list(range(N)), 2):
vervose = False
for k in range(N):
if A[i][j] > A[i][k] + A[k][j]:
exist = False
break
if not exist:
break
for k in range(N):
if i == k or j == k:
pass
elif A[i][j] == A[i][k] + A[k][j]:
vervose = True
break
if not vervose:
res += A[i][j]
if exist:
print(res)
else:
print((-1))
| # -*- coding: utf-8 -*-
from itertools import combinations
def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
res = 0
exist = True
A = []
for _ in range(N):
A.append(inpl())
for i, j in combinations(list(range(N)), 2):
vervose = False
if not exist:
break
for k in range(N):
if i == k or j == k:
pass
else:
if A[i][j] < A[i][k] + A[k][j]:
pass
elif A[i][j] == A[i][k] + A[k][j]:
vervose = True
else:
exist = False
break
if vervose:
pass
else:
res += A[i][j]
if exist:
print(res)
else:
print((-1))
| false | 5.128205 | [
"- return tuple(map(int, input().split()))",
"+ return list(map(int, input().split()))",
"- for k in range(N):",
"- if A[i][j] > A[i][k] + A[k][j]:",
"- exist = False",
"- break",
"- elif A[i][j] == A[i][k] + A[k][j]:",
"- vervose = True",
"- break",
"- if not vervose:",
"+ else:",
"+ if A[i][j] < A[i][k] + A[k][j]:",
"+ pass",
"+ elif A[i][j] == A[i][k] + A[k][j]:",
"+ vervose = True",
"+ else:",
"+ exist = False",
"+ break",
"+ if vervose:",
"+ pass",
"+ else:"
] | false | 0.039544 | 0.04304 | 0.918789 | [
"s829468530",
"s936804290"
] |
u987164499 | p03095 | python | s131333190 | s456982865 | 48 | 25 | 5,328 | 3,444 | Accepted | Accepted | 47.92 | from sys import stdin
import string
from itertools import groupby
n = int(stdin.readline().rstrip())
s = list(stdin.readline().rstrip())
s.sort()
lin = []
for key, value in groupby(s):
lin.append(len(list(value)))
point = 1
for i in lin:
point *= i+1
point %= 10**9+7
print((point-1)) | from collections import Counter
n = int(eval(input()))
s = eval(input())
mod = 10**9+7
c = Counter(s)
point = 1
for i,j in list(c.items()):
point *= j+1
point %= mod
point -= 1
print(point) | 15 | 16 | 309 | 199 | from sys import stdin
import string
from itertools import groupby
n = int(stdin.readline().rstrip())
s = list(stdin.readline().rstrip())
s.sort()
lin = []
for key, value in groupby(s):
lin.append(len(list(value)))
point = 1
for i in lin:
point *= i + 1
point %= 10**9 + 7
print((point - 1))
| from collections import Counter
n = int(eval(input()))
s = eval(input())
mod = 10**9 + 7
c = Counter(s)
point = 1
for i, j in list(c.items()):
point *= j + 1
point %= mod
point -= 1
print(point)
| false | 6.25 | [
"-from sys import stdin",
"-import string",
"-from itertools import groupby",
"+from collections import Counter",
"-n = int(stdin.readline().rstrip())",
"-s = list(stdin.readline().rstrip())",
"-s.sort()",
"-lin = []",
"-for key, value in groupby(s):",
"- lin.append(len(list(value)))",
"+n = int(eval(input()))",
"+s = eval(input())",
"+mod = 10**9 + 7",
"+c = Counter(s)",
"-for i in lin:",
"- point *= i + 1",
"- point %= 10**9 + 7",
"-print((point - 1))",
"+for i, j in list(c.items()):",
"+ point *= j + 1",
"+ point %= mod",
"+point -= 1",
"+print(point)"
] | false | 0.046405 | 0.21153 | 0.219377 | [
"s131333190",
"s456982865"
] |
u844646164 | p03673 | python | s590071191 | s727820384 | 251 | 159 | 26,180 | 116,152 | Accepted | Accepted | 36.65 | n = int(eval(input()))
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
count = 0
i = 0
j = -1
k = -1
for _ in range(n):
if count % 2 == 0:
b[i] = a[k]
i += 1
k -= 1
else:
b[j] = a[k]
j -= 1
k -= 1
count += 1
print((*b)) | n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
b = []
c = []
for i in range(n):
if i == 0:
b.append(a[i])
elif i % 2 == 0:
b.append(a[i])
elif i % 2 == 1:
c.append(a[i])
if n % 2:
ans = b[::-1] + c
else:
ans = c[::-1] + b
print((*ans))
| 20 | 19 | 276 | 290 | n = int(eval(input()))
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
count = 0
i = 0
j = -1
k = -1
for _ in range(n):
if count % 2 == 0:
b[i] = a[k]
i += 1
k -= 1
else:
b[j] = a[k]
j -= 1
k -= 1
count += 1
print((*b))
| n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
b = []
c = []
for i in range(n):
if i == 0:
b.append(a[i])
elif i % 2 == 0:
b.append(a[i])
elif i % 2 == 1:
c.append(a[i])
if n % 2:
ans = b[::-1] + c
else:
ans = c[::-1] + b
print((*ans))
| false | 5 | [
"-b = [0 for _ in range(n)]",
"-count = 0",
"-i = 0",
"-j = -1",
"-k = -1",
"-for _ in range(n):",
"- if count % 2 == 0:",
"- b[i] = a[k]",
"- i += 1",
"- k -= 1",
"- else:",
"- b[j] = a[k]",
"- j -= 1",
"- k -= 1",
"- count += 1",
"-print((*b))",
"+cnt = 0",
"+b = []",
"+c = []",
"+for i in range(n):",
"+ if i == 0:",
"+ b.append(a[i])",
"+ elif i % 2 == 0:",
"+ b.append(a[i])",
"+ elif i % 2 == 1:",
"+ c.append(a[i])",
"+if n % 2:",
"+ ans = b[::-1] + c",
"+else:",
"+ ans = c[::-1] + b",
"+print((*ans))"
] | false | 0.038216 | 0.04128 | 0.925787 | [
"s590071191",
"s727820384"
] |
u859897687 | p02957 | python | s759675821 | s198033356 | 176 | 17 | 38,384 | 2,940 | Accepted | Accepted | 90.34 | a,b=list(map(int,input().split()))
if (a-b)%2==1:
print("IMPOSSIBLE")
else:
print((min(a,b)+abs(a-b)//2)) | a,b=list(map(int,input().split()))
if (a+b)%2==1:
print("IMPOSSIBLE")
else:
print(((a+b)//2)) | 5 | 5 | 105 | 93 | a, b = list(map(int, input().split()))
if (a - b) % 2 == 1:
print("IMPOSSIBLE")
else:
print((min(a, b) + abs(a - b) // 2))
| a, b = list(map(int, input().split()))
if (a + b) % 2 == 1:
print("IMPOSSIBLE")
else:
print(((a + b) // 2))
| false | 0 | [
"-if (a - b) % 2 == 1:",
"+if (a + b) % 2 == 1:",
"- print((min(a, b) + abs(a - b) // 2))",
"+ print(((a + b) // 2))"
] | false | 0.091919 | 0.046185 | 1.990206 | [
"s759675821",
"s198033356"
] |
u189023301 | p02883 | python | s574419095 | s936982018 | 324 | 282 | 51,740 | 52,088 | Accepted | Accepted | 12.96 | import sys
import numpy as np
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('my_module')
@cc.export('is_ok', '(i8[:],u8[:],u8,u8)')
def is_ok(A, F, x, k):
y = A - x // F
tmp = y[y > 0].sum()
return tmp <= k
cc.compile()
exit()
from my_module import is_ok
n, k = list(map(int, input().split()))
A = np.array(input().split(), dtype="i8")
F = np.array(input().split(), dtype="u8")
A = np.sort(A)
F = np.sort(F)[::-1]
ok = 10 ** 12
ng = -1
while ok - ng > 1:
mid = (ok + ng) // 2
if is_ok(A, F, mid, k):
ok = mid
else:
ng = mid
print(ok)
| import sys
import numpy as np
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('my_module')
@cc.export('is_ok', '(u8[:],u8[:],u8,u8)')
def is_ok(A, F, x, k):
tmp = 0
for a, f in zip(A, F):
y = a * f
if y > x:
tmp += a - x // f
return tmp <= k
cc.compile()
sys.exit()
from my_module import is_ok
n, k = list(map(int, input().split()))
A = np.array(input().split(), dtype="u8")
F = np.array(input().split(), dtype="u8")
A = np.sort(A)
F = np.sort(F)[::-1]
ok = 10 ** 12
ng = -1
while ok - ng > 1:
mid = (ok + ng) // 2
if is_ok(A, F, mid, k):
ok = mid
else:
ng = mid
print(ok)
| 35 | 37 | 679 | 747 | import sys
import numpy as np
if sys.argv[-1] == "ONLINE_JUDGE":
from numba.pycc import CC
cc = CC("my_module")
@cc.export("is_ok", "(i8[:],u8[:],u8,u8)")
def is_ok(A, F, x, k):
y = A - x // F
tmp = y[y > 0].sum()
return tmp <= k
cc.compile()
exit()
from my_module import is_ok
n, k = list(map(int, input().split()))
A = np.array(input().split(), dtype="i8")
F = np.array(input().split(), dtype="u8")
A = np.sort(A)
F = np.sort(F)[::-1]
ok = 10**12
ng = -1
while ok - ng > 1:
mid = (ok + ng) // 2
if is_ok(A, F, mid, k):
ok = mid
else:
ng = mid
print(ok)
| import sys
import numpy as np
if sys.argv[-1] == "ONLINE_JUDGE":
from numba.pycc import CC
cc = CC("my_module")
@cc.export("is_ok", "(u8[:],u8[:],u8,u8)")
def is_ok(A, F, x, k):
tmp = 0
for a, f in zip(A, F):
y = a * f
if y > x:
tmp += a - x // f
return tmp <= k
cc.compile()
sys.exit()
from my_module import is_ok
n, k = list(map(int, input().split()))
A = np.array(input().split(), dtype="u8")
F = np.array(input().split(), dtype="u8")
A = np.sort(A)
F = np.sort(F)[::-1]
ok = 10**12
ng = -1
while ok - ng > 1:
mid = (ok + ng) // 2
if is_ok(A, F, mid, k):
ok = mid
else:
ng = mid
print(ok)
| false | 5.405405 | [
"- @cc.export(\"is_ok\", \"(i8[:],u8[:],u8,u8)\")",
"+ @cc.export(\"is_ok\", \"(u8[:],u8[:],u8,u8)\")",
"- y = A - x // F",
"- tmp = y[y > 0].sum()",
"+ tmp = 0",
"+ for a, f in zip(A, F):",
"+ y = a * f",
"+ if y > x:",
"+ tmp += a - x // f",
"- exit()",
"+ sys.exit()",
"-A = np.array(input().split(), dtype=\"i8\")",
"+A = np.array(input().split(), dtype=\"u8\")"
] | false | 0.297099 | 0.282969 | 1.049932 | [
"s574419095",
"s936982018"
] |
u102461423 | p03163 | python | s282576379 | s855593187 | 211 | 138 | 15,488 | 28,944 | Accepted | Accepted | 34.6 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N,W = list(map(int,readline().split()))
m = list(map(int,read().split()))
WV = list(zip(m,m))
# 重さ -> 最大価値
dp = np.zeros(W+1,np.int64)
for w,v in WV:
np.maximum(dp[w:],dp[:-w].copy()+v,out=dp[w:])
answer = dp.max()
print(answer) | import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, lim = list(map(int, readline().split()))
WV = np.array(read().split(), np.int64)
W = WV[::2]
V = WV[1::2]
# weight -> value
dp = np.zeros(lim + 1, np.int64)
for w, v in zip(W, V):
np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])
print((dp.max())) | 20 | 18 | 380 | 396 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N, W = list(map(int, readline().split()))
m = list(map(int, read().split()))
WV = list(zip(m, m))
# 重さ -> 最大価値
dp = np.zeros(W + 1, np.int64)
for w, v in WV:
np.maximum(dp[w:], dp[:-w].copy() + v, out=dp[w:])
answer = dp.max()
print(answer)
| import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, lim = list(map(int, readline().split()))
WV = np.array(read().split(), np.int64)
W = WV[::2]
V = WV[1::2]
# weight -> value
dp = np.zeros(lim + 1, np.int64)
for w, v in zip(W, V):
np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])
print((dp.max()))
| false | 10 | [
"+import numpy as np",
"-import numpy as np",
"-",
"-N, W = list(map(int, readline().split()))",
"-m = list(map(int, read().split()))",
"-WV = list(zip(m, m))",
"-# 重さ -> 最大価値",
"-dp = np.zeros(W + 1, np.int64)",
"-for w, v in WV:",
"- np.maximum(dp[w:], dp[:-w].copy() + v, out=dp[w:])",
"-answer = dp.max()",
"-print(answer)",
"+N, lim = list(map(int, readline().split()))",
"+WV = np.array(read().split(), np.int64)",
"+W = WV[::2]",
"+V = WV[1::2]",
"+# weight -> value",
"+dp = np.zeros(lim + 1, np.int64)",
"+for w, v in zip(W, V):",
"+ np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])",
"+print((dp.max()))"
] | false | 0.250539 | 0.182536 | 1.372544 | [
"s282576379",
"s855593187"
] |
u218834617 | p02761 | python | s635925421 | s152265511 | 75 | 63 | 61,900 | 61,892 | Accepted | Accepted | 16 | import sys
N,M=list(map(int,input().split()))
x=[-1]*N
valid=True
for _ in range(M):
s,c=list(map(int,input().split()))
if x[s-1]!=-1 and x[s-1]!=c:
print((-1))
sys.exit()
x[s-1]=c
if N>1 and x[0]==0:
print((-1))
else:
ans=0
for i in range(N):
if x[i]==-1:
if i>0 or N==1:
x[i]=0
else:
x[i]=1
ans=ans*10+x[i]
print(ans)
| N,M=list(map(int,input().split()))
x=[-1]*N
for _ in range(M):
s,c=list(map(int,input().split()))
s-=1
if ((s==c==0 and N>1) or
x[s]!=-1 and x[s]!=c):
print((-1))
exit()
x[s]=c
if x[0]==-1:
x[0]=0+(N>1)
for i in range(N):
if x[i]==-1: x[i]=0
print((''.join(map(str,x))))
| 25 | 18 | 447 | 322 | import sys
N, M = list(map(int, input().split()))
x = [-1] * N
valid = True
for _ in range(M):
s, c = list(map(int, input().split()))
if x[s - 1] != -1 and x[s - 1] != c:
print((-1))
sys.exit()
x[s - 1] = c
if N > 1 and x[0] == 0:
print((-1))
else:
ans = 0
for i in range(N):
if x[i] == -1:
if i > 0 or N == 1:
x[i] = 0
else:
x[i] = 1
ans = ans * 10 + x[i]
print(ans)
| N, M = list(map(int, input().split()))
x = [-1] * N
for _ in range(M):
s, c = list(map(int, input().split()))
s -= 1
if (s == c == 0 and N > 1) or x[s] != -1 and x[s] != c:
print((-1))
exit()
x[s] = c
if x[0] == -1:
x[0] = 0 + (N > 1)
for i in range(N):
if x[i] == -1:
x[i] = 0
print(("".join(map(str, x))))
| false | 28 | [
"-import sys",
"-",
"-valid = True",
"- if x[s - 1] != -1 and x[s - 1] != c:",
"+ s -= 1",
"+ if (s == c == 0 and N > 1) or x[s] != -1 and x[s] != c:",
"- sys.exit()",
"- x[s - 1] = c",
"-if N > 1 and x[0] == 0:",
"- print((-1))",
"-else:",
"- ans = 0",
"- for i in range(N):",
"- if x[i] == -1:",
"- if i > 0 or N == 1:",
"- x[i] = 0",
"- else:",
"- x[i] = 1",
"- ans = ans * 10 + x[i]",
"- print(ans)",
"+ exit()",
"+ x[s] = c",
"+if x[0] == -1:",
"+ x[0] = 0 + (N > 1)",
"+for i in range(N):",
"+ if x[i] == -1:",
"+ x[i] = 0",
"+print((\"\".join(map(str, x))))"
] | false | 0.033709 | 0.035857 | 0.940109 | [
"s635925421",
"s152265511"
] |
u955248595 | p02640 | python | s637082840 | s626955088 | 63 | 28 | 63,816 | 9,196 | Accepted | Accepted | 55.56 | X,Y = (int(x) for x in input().split())
Flag = False
for A in range(0,X+1):
for B in range(0,X+1):
if A+B==X and 2*A+4*B==Y:
Flag = True
if Flag:
break
if Flag:
print('Yes')
else:
print('No') | X,Y = (int(x) for x in input().split())
Flag = False
for A in range(0,X+1):
B = X-A
if 2*A+4*B==Y:
Flag = True
break
print((['No','Yes'][Flag])) | 12 | 8 | 246 | 173 | X, Y = (int(x) for x in input().split())
Flag = False
for A in range(0, X + 1):
for B in range(0, X + 1):
if A + B == X and 2 * A + 4 * B == Y:
Flag = True
if Flag:
break
if Flag:
print("Yes")
else:
print("No")
| X, Y = (int(x) for x in input().split())
Flag = False
for A in range(0, X + 1):
B = X - A
if 2 * A + 4 * B == Y:
Flag = True
break
print((["No", "Yes"][Flag]))
| false | 33.333333 | [
"- for B in range(0, X + 1):",
"- if A + B == X and 2 * A + 4 * B == Y:",
"- Flag = True",
"- if Flag:",
"+ B = X - A",
"+ if 2 * A + 4 * B == Y:",
"+ Flag = True",
"-if Flag:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+print(([\"No\", \"Yes\"][Flag]))"
] | false | 0.046963 | 0.046921 | 1.000886 | [
"s637082840",
"s626955088"
] |
u798803522 | p02364 | python | s955060228 | s081181670 | 1,190 | 1,040 | 43,800 | 47,584 | Accepted | Accepted | 12.61 | from collections import defaultdict
import heapq
vertices,edges = list(map(int,input().split(" ")))
link = defaultdict(dict)
weight = defaultdict(dict)
way = [float("inf")] * vertices
for e in range(edges):
source,target,w = list(map(int,input().split(" ")))
link[source] = link.get(source,set()) | {target}
link[target] = link.get(target,set()) | {source}
weight[source].update({target:w})
weight[target].update({source:w})
queue = []
heapq.heapify(queue)
heapq.heappush(queue,[0,0])
went = [0] * vertices
now_weight = 0
way[0] = 0
while queue:
here_weight,here = heapq.heappop(queue)
#print(went)
if went[here]:
continue
went[here] = 1
now_weight += here_weight
min_weight,next_t = float("inf"),-1
for c in link[here]:
if not went[c] and way[c] > weight[here][c]:
heapq.heappush(queue,[weight[here][c],c])
way[c] = weight[here][c]
#print(queue)
print(now_weight) | from collections import defaultdict
import heapq
vertices, edges = (int(n) for n in input().split(" "))
conn = defaultdict(set)
weight = defaultdict(dict)
for i in range(edges):
v1, v2, w = (int(n) for n in input().split(" "))
conn[v1] |= {v2}
conn[v2] |= {v1}
weight[v1][v2] = w
weight[v2][v1] = w
queue = []
heapq.heapify(queue)
heapq.heappush(queue, [0,0])
went = set()
went_vertices = 0
answer_weight = 0
while went_vertices < vertices:
here_weight, here_v = heapq.heappop(queue)
if here_v in went:
continue
went |= {here_v}
for c in conn[here_v]:
if c not in went:
heapq.heappush(queue,[weight[here_v][c], c])
answer_weight += here_weight
went_vertices += 1
print(answer_weight) | 34 | 29 | 979 | 784 | from collections import defaultdict
import heapq
vertices, edges = list(map(int, input().split(" ")))
link = defaultdict(dict)
weight = defaultdict(dict)
way = [float("inf")] * vertices
for e in range(edges):
source, target, w = list(map(int, input().split(" ")))
link[source] = link.get(source, set()) | {target}
link[target] = link.get(target, set()) | {source}
weight[source].update({target: w})
weight[target].update({source: w})
queue = []
heapq.heapify(queue)
heapq.heappush(queue, [0, 0])
went = [0] * vertices
now_weight = 0
way[0] = 0
while queue:
here_weight, here = heapq.heappop(queue)
# print(went)
if went[here]:
continue
went[here] = 1
now_weight += here_weight
min_weight, next_t = float("inf"), -1
for c in link[here]:
if not went[c] and way[c] > weight[here][c]:
heapq.heappush(queue, [weight[here][c], c])
way[c] = weight[here][c]
# print(queue)
print(now_weight)
| from collections import defaultdict
import heapq
vertices, edges = (int(n) for n in input().split(" "))
conn = defaultdict(set)
weight = defaultdict(dict)
for i in range(edges):
v1, v2, w = (int(n) for n in input().split(" "))
conn[v1] |= {v2}
conn[v2] |= {v1}
weight[v1][v2] = w
weight[v2][v1] = w
queue = []
heapq.heapify(queue)
heapq.heappush(queue, [0, 0])
went = set()
went_vertices = 0
answer_weight = 0
while went_vertices < vertices:
here_weight, here_v = heapq.heappop(queue)
if here_v in went:
continue
went |= {here_v}
for c in conn[here_v]:
if c not in went:
heapq.heappush(queue, [weight[here_v][c], c])
answer_weight += here_weight
went_vertices += 1
print(answer_weight)
| false | 14.705882 | [
"-vertices, edges = list(map(int, input().split(\" \")))",
"-link = defaultdict(dict)",
"+vertices, edges = (int(n) for n in input().split(\" \"))",
"+conn = defaultdict(set)",
"-way = [float(\"inf\")] * vertices",
"-for e in range(edges):",
"- source, target, w = list(map(int, input().split(\" \")))",
"- link[source] = link.get(source, set()) | {target}",
"- link[target] = link.get(target, set()) | {source}",
"- weight[source].update({target: w})",
"- weight[target].update({source: w})",
"+for i in range(edges):",
"+ v1, v2, w = (int(n) for n in input().split(\" \"))",
"+ conn[v1] |= {v2}",
"+ conn[v2] |= {v1}",
"+ weight[v1][v2] = w",
"+ weight[v2][v1] = w",
"-went = [0] * vertices",
"-now_weight = 0",
"-way[0] = 0",
"-while queue:",
"- here_weight, here = heapq.heappop(queue)",
"- # print(went)",
"- if went[here]:",
"+went = set()",
"+went_vertices = 0",
"+answer_weight = 0",
"+while went_vertices < vertices:",
"+ here_weight, here_v = heapq.heappop(queue)",
"+ if here_v in went:",
"- went[here] = 1",
"- now_weight += here_weight",
"- min_weight, next_t = float(\"inf\"), -1",
"- for c in link[here]:",
"- if not went[c] and way[c] > weight[here][c]:",
"- heapq.heappush(queue, [weight[here][c], c])",
"- way[c] = weight[here][c]",
"- # print(queue)",
"-print(now_weight)",
"+ went |= {here_v}",
"+ for c in conn[here_v]:",
"+ if c not in went:",
"+ heapq.heappush(queue, [weight[here_v][c], c])",
"+ answer_weight += here_weight",
"+ went_vertices += 1",
"+print(answer_weight)"
] | false | 0.054907 | 0.036525 | 1.503291 | [
"s955060228",
"s081181670"
] |
u612975321 | p03721 | python | s525216013 | s228979302 | 425 | 319 | 27,080 | 29,420 | Accepted | Accepted | 24.94 | import heapq
n, k = list(map(int,input().split()))
q = []
for i in range(n):
q.append(list(map(int, input().split())))
heapq.heapify(q)
cnt = 0
while cnt < k:
a, b = heapq.heappop(q)
cnt += b
print(a) | n, k = list(map(int,input().split()))
q = []
for i in range(n):
q.append(list(map(int, input().split())))
q = sorted(q, key=lambda x:x[0])
cnt = 0
i = 0
while cnt < k:
a, b = q[i]
cnt += b
i += 1
print(a) | 16 | 14 | 230 | 229 | import heapq
n, k = list(map(int, input().split()))
q = []
for i in range(n):
q.append(list(map(int, input().split())))
heapq.heapify(q)
cnt = 0
while cnt < k:
a, b = heapq.heappop(q)
cnt += b
print(a)
| n, k = list(map(int, input().split()))
q = []
for i in range(n):
q.append(list(map(int, input().split())))
q = sorted(q, key=lambda x: x[0])
cnt = 0
i = 0
while cnt < k:
a, b = q[i]
cnt += b
i += 1
print(a)
| false | 12.5 | [
"-import heapq",
"-",
"-heapq.heapify(q)",
"+q = sorted(q, key=lambda x: x[0])",
"+i = 0",
"- a, b = heapq.heappop(q)",
"+ a, b = q[i]",
"+ i += 1"
] | false | 0.039767 | 0.197333 | 0.201521 | [
"s525216013",
"s228979302"
] |
u761320129 | p03673 | python | s602746284 | s279393589 | 169 | 145 | 26,180 | 32,376 | Accepted | Accepted | 14.2 | N = int(eval(input()))
src = list(map(int,input().split()))
ans = list(reversed(src[1::2])) + src[::2]
if N%2:
ans.reverse()
print((*ans)) | from collections import deque
N = int(eval(input()))
A = list(map(int,input().split()))
b = deque()
for i,a in enumerate(A):
if i%2:
b.appendleft(a)
else:
b.append(a)
if N%2:
print((*reversed(b)))
else:
print((*b)) | 7 | 15 | 141 | 252 | N = int(eval(input()))
src = list(map(int, input().split()))
ans = list(reversed(src[1::2])) + src[::2]
if N % 2:
ans.reverse()
print((*ans))
| from collections import deque
N = int(eval(input()))
A = list(map(int, input().split()))
b = deque()
for i, a in enumerate(A):
if i % 2:
b.appendleft(a)
else:
b.append(a)
if N % 2:
print((*reversed(b)))
else:
print((*b))
| false | 53.333333 | [
"+from collections import deque",
"+",
"-src = list(map(int, input().split()))",
"-ans = list(reversed(src[1::2])) + src[::2]",
"+A = list(map(int, input().split()))",
"+b = deque()",
"+for i, a in enumerate(A):",
"+ if i % 2:",
"+ b.appendleft(a)",
"+ else:",
"+ b.append(a)",
"- ans.reverse()",
"-print((*ans))",
"+ print((*reversed(b)))",
"+else:",
"+ print((*b))"
] | false | 0.048265 | 0.048216 | 1.001013 | [
"s602746284",
"s279393589"
] |
u945181840 | p03372 | python | s522250017 | s484229246 | 516 | 218 | 38,964 | 38,964 | Accepted | Accepted | 57.75 | import sys
import numpy as np
read = sys.stdin.read
readline = sys.stdin.readline
N, C = list(map(int, readline().split()))
xv = np.array(read().split(), np.int64).reshape(N, 2)
v = xv[:, 1]
x = xv[:, 0]
ax = C - x[::-1]
cx = x.copy()
cx[1:] = cx[1:] - cx[:-1]
acx = C - x
acx[:-1] = acx[:-1] - acx[1:]
clockwise = v - cx
np.cumsum(clockwise, out=clockwise)
anticlockwise = v - acx
anticlockwise = np.cumsum(anticlockwise[::-1])
con_max = np.maximum.accumulate(clockwise)
anti_max = np.maximum.accumulate(anticlockwise)
answer = [0, con_max[-1], anti_max[-1]]
for i in range(N - 1):
answer.append(clockwise[i] - x[i] + anti_max[N - i - 2])
answer.append(anticlockwise[i] - ax[i] + con_max[N - i - 2])
print((max(answer))) | import sys
import numpy as np
read = sys.stdin.read
readline = sys.stdin.readline
N, C = list(map(int, readline().split()))
xv = np.array(read().split(), np.int64).reshape(N, 2)
v = xv[:, 1]
x = xv[:, 0]
ax = C - x[::-1]
cx = x.copy()
cx[1:] = cx[1:] - cx[:-1]
acx = C - x
acx[:-1] = acx[:-1] - acx[1:]
clockwise = np.cumsum(v - cx)
anticlockwise = v - acx
anticlockwise = np.cumsum(anticlockwise[::-1])
con_max = np.maximum.accumulate(clockwise)
anti_max = np.maximum.accumulate(anticlockwise)
answer = [0, con_max[-1], anti_max[-1]]
clockwise = clockwise - x
anti_max = anti_max[::-1]
clockwise[:-1] = clockwise[:-1] + anti_max[1:]
anticlockwise = anticlockwise - ax
con_max = con_max[::-1]
anticlockwise[:-1] = anticlockwise[:-1] + con_max[1:]
answer.append(anticlockwise.max())
answer.append(clockwise.max())
print((max(answer))) | 31 | 36 | 758 | 868 | import sys
import numpy as np
read = sys.stdin.read
readline = sys.stdin.readline
N, C = list(map(int, readline().split()))
xv = np.array(read().split(), np.int64).reshape(N, 2)
v = xv[:, 1]
x = xv[:, 0]
ax = C - x[::-1]
cx = x.copy()
cx[1:] = cx[1:] - cx[:-1]
acx = C - x
acx[:-1] = acx[:-1] - acx[1:]
clockwise = v - cx
np.cumsum(clockwise, out=clockwise)
anticlockwise = v - acx
anticlockwise = np.cumsum(anticlockwise[::-1])
con_max = np.maximum.accumulate(clockwise)
anti_max = np.maximum.accumulate(anticlockwise)
answer = [0, con_max[-1], anti_max[-1]]
for i in range(N - 1):
answer.append(clockwise[i] - x[i] + anti_max[N - i - 2])
answer.append(anticlockwise[i] - ax[i] + con_max[N - i - 2])
print((max(answer)))
| import sys
import numpy as np
read = sys.stdin.read
readline = sys.stdin.readline
N, C = list(map(int, readline().split()))
xv = np.array(read().split(), np.int64).reshape(N, 2)
v = xv[:, 1]
x = xv[:, 0]
ax = C - x[::-1]
cx = x.copy()
cx[1:] = cx[1:] - cx[:-1]
acx = C - x
acx[:-1] = acx[:-1] - acx[1:]
clockwise = np.cumsum(v - cx)
anticlockwise = v - acx
anticlockwise = np.cumsum(anticlockwise[::-1])
con_max = np.maximum.accumulate(clockwise)
anti_max = np.maximum.accumulate(anticlockwise)
answer = [0, con_max[-1], anti_max[-1]]
clockwise = clockwise - x
anti_max = anti_max[::-1]
clockwise[:-1] = clockwise[:-1] + anti_max[1:]
anticlockwise = anticlockwise - ax
con_max = con_max[::-1]
anticlockwise[:-1] = anticlockwise[:-1] + con_max[1:]
answer.append(anticlockwise.max())
answer.append(clockwise.max())
print((max(answer)))
| false | 13.888889 | [
"-clockwise = v - cx",
"-np.cumsum(clockwise, out=clockwise)",
"+clockwise = np.cumsum(v - cx)",
"-for i in range(N - 1):",
"- answer.append(clockwise[i] - x[i] + anti_max[N - i - 2])",
"- answer.append(anticlockwise[i] - ax[i] + con_max[N - i - 2])",
"+clockwise = clockwise - x",
"+anti_max = anti_max[::-1]",
"+clockwise[:-1] = clockwise[:-1] + anti_max[1:]",
"+anticlockwise = anticlockwise - ax",
"+con_max = con_max[::-1]",
"+anticlockwise[:-1] = anticlockwise[:-1] + con_max[1:]",
"+answer.append(anticlockwise.max())",
"+answer.append(clockwise.max())"
] | false | 0.256415 | 0.253434 | 1.011763 | [
"s522250017",
"s484229246"
] |
u445624660 | p02954 | python | s051048149 | s987932005 | 171 | 93 | 12,596 | 17,756 | Accepted | Accepted | 45.61 | s = eval(input())
n = len(s)
arr = [0 for _ in range(n)]
r_arr = [0 for _ in range(n)]
l_arr = [0 for _ in range(n)]
for i in range(n - 1):
if s[i] == "R" and s[i + 1] == "L":
arr[i] += 1
arr[i + 1] += 1
r_pos = []
for i in range(n - 1):
if s[i] == "R":
if s[i + 1] == "L":
for r in r_pos:
if (r - i) % 2 == 0:
r_arr[i] += 1
else:
r_arr[i + 1] += 1
r_pos = []
else:
r_pos.append(i)
l_pos = []
for i in range(n - 1, 0, -1):
if s[i] == "L":
if s[i - 1] == "R":
for l in l_pos:
if (l - i) % 2 == 0:
l_arr[i] += 1
else:
l_arr[i - 1] += 1
l_pos = []
else:
l_pos.append(i)
ans = [0 for _ in range(n)]
for i in range(n):
ans[i] = str(arr[i] + r_arr[i] + l_arr[i])
print((" ".join(ans)))
| a = list(eval(input()))
ans = [0] * len(a)
even_r, odd_r = 0, 0
# 正直変数ガチャ
for i in range(len(a)):
if a[i] == "R":
if i % 2 == 0:
odd_r += 1
else:
even_r += 1
else:
if i % 2 == 0:
ans[i - 1] += even_r
ans[i] += odd_r
else:
ans[i - 1] += odd_r
ans[i] += even_r
odd_r = 0
even_r = 0
even_l, odd_l = 0, 0
for i in range(len(a) - 1, -1, -1):
if a[i] == "L":
if i % 2 == 0:
odd_l += 1
else:
even_l += 1
else:
if i % 2 == 0:
ans[i + 1] += even_l
ans[i] += odd_l
else:
ans[i + 1] += odd_l
ans[i] += even_l
odd_l = 0
even_l = 0
print((" ".join(list(map(str, ans))))) | 43 | 36 | 1,000 | 840 | s = eval(input())
n = len(s)
arr = [0 for _ in range(n)]
r_arr = [0 for _ in range(n)]
l_arr = [0 for _ in range(n)]
for i in range(n - 1):
if s[i] == "R" and s[i + 1] == "L":
arr[i] += 1
arr[i + 1] += 1
r_pos = []
for i in range(n - 1):
if s[i] == "R":
if s[i + 1] == "L":
for r in r_pos:
if (r - i) % 2 == 0:
r_arr[i] += 1
else:
r_arr[i + 1] += 1
r_pos = []
else:
r_pos.append(i)
l_pos = []
for i in range(n - 1, 0, -1):
if s[i] == "L":
if s[i - 1] == "R":
for l in l_pos:
if (l - i) % 2 == 0:
l_arr[i] += 1
else:
l_arr[i - 1] += 1
l_pos = []
else:
l_pos.append(i)
ans = [0 for _ in range(n)]
for i in range(n):
ans[i] = str(arr[i] + r_arr[i] + l_arr[i])
print((" ".join(ans)))
| a = list(eval(input()))
ans = [0] * len(a)
even_r, odd_r = 0, 0
# 正直変数ガチャ
for i in range(len(a)):
if a[i] == "R":
if i % 2 == 0:
odd_r += 1
else:
even_r += 1
else:
if i % 2 == 0:
ans[i - 1] += even_r
ans[i] += odd_r
else:
ans[i - 1] += odd_r
ans[i] += even_r
odd_r = 0
even_r = 0
even_l, odd_l = 0, 0
for i in range(len(a) - 1, -1, -1):
if a[i] == "L":
if i % 2 == 0:
odd_l += 1
else:
even_l += 1
else:
if i % 2 == 0:
ans[i + 1] += even_l
ans[i] += odd_l
else:
ans[i + 1] += odd_l
ans[i] += even_l
odd_l = 0
even_l = 0
print((" ".join(list(map(str, ans)))))
| false | 16.27907 | [
"-s = eval(input())",
"-n = len(s)",
"-arr = [0 for _ in range(n)]",
"-r_arr = [0 for _ in range(n)]",
"-l_arr = [0 for _ in range(n)]",
"-for i in range(n - 1):",
"- if s[i] == \"R\" and s[i + 1] == \"L\":",
"- arr[i] += 1",
"- arr[i + 1] += 1",
"-r_pos = []",
"-for i in range(n - 1):",
"- if s[i] == \"R\":",
"- if s[i + 1] == \"L\":",
"- for r in r_pos:",
"- if (r - i) % 2 == 0:",
"- r_arr[i] += 1",
"- else:",
"- r_arr[i + 1] += 1",
"- r_pos = []",
"+a = list(eval(input()))",
"+ans = [0] * len(a)",
"+even_r, odd_r = 0, 0",
"+# 正直変数ガチャ",
"+for i in range(len(a)):",
"+ if a[i] == \"R\":",
"+ if i % 2 == 0:",
"+ odd_r += 1",
"- r_pos.append(i)",
"-l_pos = []",
"-for i in range(n - 1, 0, -1):",
"- if s[i] == \"L\":",
"- if s[i - 1] == \"R\":",
"- for l in l_pos:",
"- if (l - i) % 2 == 0:",
"- l_arr[i] += 1",
"- else:",
"- l_arr[i - 1] += 1",
"- l_pos = []",
"+ even_r += 1",
"+ else:",
"+ if i % 2 == 0:",
"+ ans[i - 1] += even_r",
"+ ans[i] += odd_r",
"- l_pos.append(i)",
"-ans = [0 for _ in range(n)]",
"-for i in range(n):",
"- ans[i] = str(arr[i] + r_arr[i] + l_arr[i])",
"-print((\" \".join(ans)))",
"+ ans[i - 1] += odd_r",
"+ ans[i] += even_r",
"+ odd_r = 0",
"+ even_r = 0",
"+even_l, odd_l = 0, 0",
"+for i in range(len(a) - 1, -1, -1):",
"+ if a[i] == \"L\":",
"+ if i % 2 == 0:",
"+ odd_l += 1",
"+ else:",
"+ even_l += 1",
"+ else:",
"+ if i % 2 == 0:",
"+ ans[i + 1] += even_l",
"+ ans[i] += odd_l",
"+ else:",
"+ ans[i + 1] += odd_l",
"+ ans[i] += even_l",
"+ odd_l = 0",
"+ even_l = 0",
"+print((\" \".join(list(map(str, ans)))))"
] | false | 0.033373 | 0.048745 | 0.684635 | [
"s051048149",
"s987932005"
] |
u370661635 | p03325 | python | s387607338 | s663894819 | 118 | 28 | 4,148 | 4,148 | Accepted | Accepted | 76.27 | n = int(eval(input()))
a = list(map(int,input().split()))
cnt = 0
for ii in a:
temp = ii
while temp % 2 == 0:
temp = temp /2
cnt += 1
print(cnt) | n = int(eval(input()))
a = list(map(int,input().split()))
c = 0
for ii in range(n):
c += format(a[ii],"b")[::-1].find("1")
print(c) | 11 | 7 | 162 | 134 | n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for ii in a:
temp = ii
while temp % 2 == 0:
temp = temp / 2
cnt += 1
print(cnt)
| n = int(eval(input()))
a = list(map(int, input().split()))
c = 0
for ii in range(n):
c += format(a[ii], "b")[::-1].find("1")
print(c)
| false | 36.363636 | [
"-cnt = 0",
"-for ii in a:",
"- temp = ii",
"- while temp % 2 == 0:",
"- temp = temp / 2",
"- cnt += 1",
"-print(cnt)",
"+c = 0",
"+for ii in range(n):",
"+ c += format(a[ii], \"b\")[::-1].find(\"1\")",
"+print(c)"
] | false | 0.035234 | 0.054911 | 0.641665 | [
"s387607338",
"s663894819"
] |
u054556734 | p03295 | python | s676369779 | s955094604 | 560 | 517 | 37,908 | 37,920 | Accepted | Accepted | 7.68 | import numpy as np
n,m = list(map(int,input().split()))
arr = np.array([list(map(int,input().split())) for i in range(m)])
arr = arr[ arr[:,1].argsort(), :] #各行の1列目だけみて、行インデックスをソート
ans = 0
start,end = 0,0
for ab in arr:
a,b = ab[0],ab[1]
if a < end: continue
start,end = a,b
ans += 1
print(ans)
| import numpy as np
n,m = list(map(int,input().split()))
arr = np.array([list(map(int,input().split())) for i in range(m)])
arr = arr[ arr[:,1].argsort(), :] #各行の1列目だけみて、行インデックスをソート
A = arr.T[0]
B = arr.T[1]
ans = 0
start,end = 0,0
for a,b in zip(A,B):
if a < end: continue
start,end = a,b
ans += 1
print(ans)
| 18 | 18 | 328 | 337 | import numpy as np
n, m = list(map(int, input().split()))
arr = np.array([list(map(int, input().split())) for i in range(m)])
arr = arr[arr[:, 1].argsort(), :] # 各行の1列目だけみて、行インデックスをソート
ans = 0
start, end = 0, 0
for ab in arr:
a, b = ab[0], ab[1]
if a < end:
continue
start, end = a, b
ans += 1
print(ans)
| import numpy as np
n, m = list(map(int, input().split()))
arr = np.array([list(map(int, input().split())) for i in range(m)])
arr = arr[arr[:, 1].argsort(), :] # 各行の1列目だけみて、行インデックスをソート
A = arr.T[0]
B = arr.T[1]
ans = 0
start, end = 0, 0
for a, b in zip(A, B):
if a < end:
continue
start, end = a, b
ans += 1
print(ans)
| false | 0 | [
"+A = arr.T[0]",
"+B = arr.T[1]",
"-for ab in arr:",
"- a, b = ab[0], ab[1]",
"+for a, b in zip(A, B):"
] | false | 0.388062 | 0.439783 | 0.882395 | [
"s676369779",
"s955094604"
] |
u909643606 | p03329 | python | s542480282 | s907748182 | 473 | 232 | 3,064 | 3,064 | Accepted | Accepted | 50.95 | n=int(eval(input()))
s_6=[6**(6-i) for i in range(6)]
s_9=[9**(5-i) for i in range(5)]
amari=[0,1,2,3,4,5,1,2,3,1,2,3,2,3]
best=float("inf")
for i in range(n+1):
count_6=0
n_6=i
for j in range(len(s_6)):
count_6+=n_6//s_6[j]
n_6=n_6%s_6[j]
n_9=n-i
count_9=0
for j in range(len(s_9)):
count_9+=n_9//s_9[j]
n_9=n_9%s_9[j]
best=min(best, count_6+count_9+ amari[n_6+n_9])
print(best) | n = int(eval(input()))
ans = float("inf")
for n_nine in range(0, n//9 + 1):
s = n - 9 * n_nine
n_six = s // 6
n_one = s - 6 * n_six
n_nine2 = 0
n_six2 = 0
pow_nine = 5
pow_six = 6
while n_nine >= 9:
if n_nine >= 9 ** (pow_nine - 1):
n_nine -= 9 ** (pow_nine - 1)
n_nine2 += 1
else:
pow_nine -= 1
while n_six >= 6:
if n_six >= 6 ** (pow_six - 1):
n_six -= 6 ** (pow_six - 1)
n_six2 += 1
else:
pow_six -= 1
ans = min(ans, n_nine2 + n_nine + n_six2 + n_six + n_one)
print(ans) | 22 | 28 | 461 | 672 | n = int(eval(input()))
s_6 = [6 ** (6 - i) for i in range(6)]
s_9 = [9 ** (5 - i) for i in range(5)]
amari = [0, 1, 2, 3, 4, 5, 1, 2, 3, 1, 2, 3, 2, 3]
best = float("inf")
for i in range(n + 1):
count_6 = 0
n_6 = i
for j in range(len(s_6)):
count_6 += n_6 // s_6[j]
n_6 = n_6 % s_6[j]
n_9 = n - i
count_9 = 0
for j in range(len(s_9)):
count_9 += n_9 // s_9[j]
n_9 = n_9 % s_9[j]
best = min(best, count_6 + count_9 + amari[n_6 + n_9])
print(best)
| n = int(eval(input()))
ans = float("inf")
for n_nine in range(0, n // 9 + 1):
s = n - 9 * n_nine
n_six = s // 6
n_one = s - 6 * n_six
n_nine2 = 0
n_six2 = 0
pow_nine = 5
pow_six = 6
while n_nine >= 9:
if n_nine >= 9 ** (pow_nine - 1):
n_nine -= 9 ** (pow_nine - 1)
n_nine2 += 1
else:
pow_nine -= 1
while n_six >= 6:
if n_six >= 6 ** (pow_six - 1):
n_six -= 6 ** (pow_six - 1)
n_six2 += 1
else:
pow_six -= 1
ans = min(ans, n_nine2 + n_nine + n_six2 + n_six + n_one)
print(ans)
| false | 21.428571 | [
"-s_6 = [6 ** (6 - i) for i in range(6)]",
"-s_9 = [9 ** (5 - i) for i in range(5)]",
"-amari = [0, 1, 2, 3, 4, 5, 1, 2, 3, 1, 2, 3, 2, 3]",
"-best = float(\"inf\")",
"-for i in range(n + 1):",
"- count_6 = 0",
"- n_6 = i",
"- for j in range(len(s_6)):",
"- count_6 += n_6 // s_6[j]",
"- n_6 = n_6 % s_6[j]",
"- n_9 = n - i",
"- count_9 = 0",
"- for j in range(len(s_9)):",
"- count_9 += n_9 // s_9[j]",
"- n_9 = n_9 % s_9[j]",
"- best = min(best, count_6 + count_9 + amari[n_6 + n_9])",
"-print(best)",
"+ans = float(\"inf\")",
"+for n_nine in range(0, n // 9 + 1):",
"+ s = n - 9 * n_nine",
"+ n_six = s // 6",
"+ n_one = s - 6 * n_six",
"+ n_nine2 = 0",
"+ n_six2 = 0",
"+ pow_nine = 5",
"+ pow_six = 6",
"+ while n_nine >= 9:",
"+ if n_nine >= 9 ** (pow_nine - 1):",
"+ n_nine -= 9 ** (pow_nine - 1)",
"+ n_nine2 += 1",
"+ else:",
"+ pow_nine -= 1",
"+ while n_six >= 6:",
"+ if n_six >= 6 ** (pow_six - 1):",
"+ n_six -= 6 ** (pow_six - 1)",
"+ n_six2 += 1",
"+ else:",
"+ pow_six -= 1",
"+ ans = min(ans, n_nine2 + n_nine + n_six2 + n_six + n_one)",
"+print(ans)"
] | false | 0.119928 | 0.058043 | 2.066209 | [
"s542480282",
"s907748182"
] |
u652583512 | p02862 | python | s723422137 | s051675328 | 444 | 122 | 38,768 | 3,064 | Accepted | Accepted | 72.52 | def comb(n, k, mod):
if k > (n // 2):
k = n - k
a = 1
for i in range(k):
a *= (n - i)
a %= mod
for i in range(k - 1):
a = (a * pow(k - i, mod - 2, mod)) % mod
return a
X, Y = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
if X > Y:
X, Y = Y, X
##Yのほうが大きいとして考える
if not (X + Y) % 3 == 0 or Y > 2 * X:
ans = 0
else:
n = (X + Y) // 3
d = Y - X
a = 2*n - X
ans = comb(n, a, mod)
print(ans)
| def comb(n, k, mod):
if k > (n // 2):
k = n - k
a = 1
for i in range(k):
a = (a * (n - i)) % mod
b = 1
for i in range(k - 1):
b = (b *(k - i)) % mod
a = (a * pow(b, mod - 2, mod)) % mod
return a
X, Y = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
if X > Y:
X, Y = Y, X
##Yのほうが大きいとして考える
if not (X + Y) % 3 == 0 or Y > 2 * X:
ans = 0
else:
n = (X + Y) // 3
d = Y - X
a = 2*n - X
ans = comb(n, a, mod)
print(ans)
| 26 | 27 | 493 | 521 | def comb(n, k, mod):
if k > (n // 2):
k = n - k
a = 1
for i in range(k):
a *= n - i
a %= mod
for i in range(k - 1):
a = (a * pow(k - i, mod - 2, mod)) % mod
return a
X, Y = list(map(int, input().split()))
ans = 0
mod = 10**9 + 7
if X > Y:
X, Y = Y, X
##Yのほうが大きいとして考える
if not (X + Y) % 3 == 0 or Y > 2 * X:
ans = 0
else:
n = (X + Y) // 3
d = Y - X
a = 2 * n - X
ans = comb(n, a, mod)
print(ans)
| def comb(n, k, mod):
if k > (n // 2):
k = n - k
a = 1
for i in range(k):
a = (a * (n - i)) % mod
b = 1
for i in range(k - 1):
b = (b * (k - i)) % mod
a = (a * pow(b, mod - 2, mod)) % mod
return a
X, Y = list(map(int, input().split()))
ans = 0
mod = 10**9 + 7
if X > Y:
X, Y = Y, X
##Yのほうが大きいとして考える
if not (X + Y) % 3 == 0 or Y > 2 * X:
ans = 0
else:
n = (X + Y) // 3
d = Y - X
a = 2 * n - X
ans = comb(n, a, mod)
print(ans)
| false | 3.703704 | [
"- a *= n - i",
"- a %= mod",
"+ a = (a * (n - i)) % mod",
"+ b = 1",
"- a = (a * pow(k - i, mod - 2, mod)) % mod",
"+ b = (b * (k - i)) % mod",
"+ a = (a * pow(b, mod - 2, mod)) % mod"
] | false | 0.479565 | 0.145114 | 3.304742 | [
"s723422137",
"s051675328"
] |
u032662562 | p00079 | python | s860490203 | s890952804 | 30 | 20 | 7,516 | 7,552 | Accepted | Accepted | 33.33 | import math
f = []
while True:
try:
st = input().strip().split(',')
x,y = list(map(float,st ))
f.append(x + y*1j)
except EOFError:
break
px = [p.real for p in f]
ox = (max(px) + min(px)) / 2.0
py = [p.imag for p in f]
oy = (max(py) + min(py)) / 2.0
fo = ox + oy * 1j
ss = 0.0
for i in range(len(f)):
if i == len(f)-1:
j = 0
else:
j = i + 1
a = abs(f[i]-fo)
b = abs(f[j]-fo)
c = abs(f[j]-f[i])
z = (a + b + c) / 2.0
s = math.sqrt(z*(z-a)*(z-b)*(z-c))
ss += s
print(("%.6f" % ss)) | def cross(x, y):
return (x.conjugate() * y).imag
def area_polygon(points):
area = 0
n = len(points)
for i in range(n):
area += cross(points[i], points[(i+1)%n])
return area / 2
import sys
p = []
for line in sys.stdin:
x, y = list(map(float, line.split(',')))
p.append(complex(x, y))
print((area_polygon(p))) | 31 | 19 | 598 | 371 | import math
f = []
while True:
try:
st = input().strip().split(",")
x, y = list(map(float, st))
f.append(x + y * 1j)
except EOFError:
break
px = [p.real for p in f]
ox = (max(px) + min(px)) / 2.0
py = [p.imag for p in f]
oy = (max(py) + min(py)) / 2.0
fo = ox + oy * 1j
ss = 0.0
for i in range(len(f)):
if i == len(f) - 1:
j = 0
else:
j = i + 1
a = abs(f[i] - fo)
b = abs(f[j] - fo)
c = abs(f[j] - f[i])
z = (a + b + c) / 2.0
s = math.sqrt(z * (z - a) * (z - b) * (z - c))
ss += s
print(("%.6f" % ss))
| def cross(x, y):
return (x.conjugate() * y).imag
def area_polygon(points):
area = 0
n = len(points)
for i in range(n):
area += cross(points[i], points[(i + 1) % n])
return area / 2
import sys
p = []
for line in sys.stdin:
x, y = list(map(float, line.split(",")))
p.append(complex(x, y))
print((area_polygon(p)))
| false | 38.709677 | [
"-import math",
"+def cross(x, y):",
"+ return (x.conjugate() * y).imag",
"-f = []",
"-while True:",
"- try:",
"- st = input().strip().split(\",\")",
"- x, y = list(map(float, st))",
"- f.append(x + y * 1j)",
"- except EOFError:",
"- break",
"-px = [p.real for p in f]",
"-ox = (max(px) + min(px)) / 2.0",
"-py = [p.imag for p in f]",
"-oy = (max(py) + min(py)) / 2.0",
"-fo = ox + oy * 1j",
"-ss = 0.0",
"-for i in range(len(f)):",
"- if i == len(f) - 1:",
"- j = 0",
"- else:",
"- j = i + 1",
"- a = abs(f[i] - fo)",
"- b = abs(f[j] - fo)",
"- c = abs(f[j] - f[i])",
"- z = (a + b + c) / 2.0",
"- s = math.sqrt(z * (z - a) * (z - b) * (z - c))",
"- ss += s",
"-print((\"%.6f\" % ss))",
"+",
"+def area_polygon(points):",
"+ area = 0",
"+ n = len(points)",
"+ for i in range(n):",
"+ area += cross(points[i], points[(i + 1) % n])",
"+ return area / 2",
"+",
"+",
"+import sys",
"+",
"+p = []",
"+for line in sys.stdin:",
"+ x, y = list(map(float, line.split(\",\")))",
"+ p.append(complex(x, y))",
"+print((area_polygon(p)))"
] | false | 0.046723 | 0.045544 | 1.025881 | [
"s860490203",
"s890952804"
] |
u288087195 | p03127 | python | s645165862 | s891439598 | 95 | 79 | 16,240 | 14,224 | Accepted | Accepted | 16.84 | # -*- coding: utf-8 -*-
import fractions
N = int(eval(input()))
A = list(map(int, input().split()))
def calc(monsters):
if len(monsters) == 1:
return monsters[0]
min_monster = min(monsters)
min_index = monsters.index(min_monster)
new_monsters = []
for i in range(len(monsters)):
if i == min_index:
new_monsters.append(monsters[i])
remndr = monsters[i] % min_monster
if remndr != 0:
new_monsters.append(remndr)
return calc(new_monsters)
ans = calc(A)
print(ans) | # -*- coding: utf-8 -*-
N = int(eval(input()))
A = list(map(int, input().split()))
def calc(monsters):
if len(monsters) == 1:
return monsters[0]
min_monster = min(monsters)
min_index = monsters.index(min_monster)
new_monsters = []
for i in range(len(monsters)):
if i == min_index:
new_monsters.append(monsters[i])
remndr = monsters[i] % min_monster
if remndr != 0:
new_monsters.append(remndr)
return calc(new_monsters)
ans = calc(A)
print(ans) | 27 | 26 | 568 | 550 | # -*- coding: utf-8 -*-
import fractions
N = int(eval(input()))
A = list(map(int, input().split()))
def calc(monsters):
if len(monsters) == 1:
return monsters[0]
min_monster = min(monsters)
min_index = monsters.index(min_monster)
new_monsters = []
for i in range(len(monsters)):
if i == min_index:
new_monsters.append(monsters[i])
remndr = monsters[i] % min_monster
if remndr != 0:
new_monsters.append(remndr)
return calc(new_monsters)
ans = calc(A)
print(ans)
| # -*- coding: utf-8 -*-
N = int(eval(input()))
A = list(map(int, input().split()))
def calc(monsters):
if len(monsters) == 1:
return monsters[0]
min_monster = min(monsters)
min_index = monsters.index(min_monster)
new_monsters = []
for i in range(len(monsters)):
if i == min_index:
new_monsters.append(monsters[i])
remndr = monsters[i] % min_monster
if remndr != 0:
new_monsters.append(remndr)
return calc(new_monsters)
ans = calc(A)
print(ans)
| false | 3.703704 | [
"-import fractions",
"-"
] | false | 0.055714 | 0.036268 | 1.536162 | [
"s645165862",
"s891439598"
] |
u671060652 | p03242 | python | s044157015 | s919170929 | 292 | 64 | 64,748 | 61,812 | Accepted | Accepted | 78.08 | import itertools
import math
import fractions
import functools
import copy
n = input()
for i in range(len(n)):
if n[i] == '1':
print('9',end="")
else:
print('1',end="")
print("")
| def main():
# n = int(input())
# h, w, k = map(int, input().split())
# a = list(map(int, input().split()))
s = eval(input())
ans = ""
for i in s:
if i == "1":
ans += "9"
else:
ans += "1"
print(ans)
if __name__ == '__main__':
main()
| 13 | 16 | 215 | 315 | import itertools
import math
import fractions
import functools
import copy
n = input()
for i in range(len(n)):
if n[i] == "1":
print("9", end="")
else:
print("1", end="")
print("")
| def main():
# n = int(input())
# h, w, k = map(int, input().split())
# a = list(map(int, input().split()))
s = eval(input())
ans = ""
for i in s:
if i == "1":
ans += "9"
else:
ans += "1"
print(ans)
if __name__ == "__main__":
main()
| false | 18.75 | [
"-import itertools",
"-import math",
"-import fractions",
"-import functools",
"-import copy",
"+def main():",
"+ # n = int(input())",
"+ # h, w, k = map(int, input().split())",
"+ # a = list(map(int, input().split()))",
"+ s = eval(input())",
"+ ans = \"\"",
"+ for i in s:",
"+ if i == \"1\":",
"+ ans += \"9\"",
"+ else:",
"+ ans += \"1\"",
"+ print(ans)",
"-n = input()",
"-for i in range(len(n)):",
"- if n[i] == \"1\":",
"- print(\"9\", end=\"\")",
"- else:",
"- print(\"1\", end=\"\")",
"-print(\"\")",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.279666 | 0.037272 | 7.503383 | [
"s044157015",
"s919170929"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.