user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
list | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
list |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u422104747 | p02609 | python | s808016502 | s334422150 | 353 | 282 | 82,376 | 81,008 | Accepted | Accepted | 20.11 | def popcount(x):
return bin(x)[2:].count("1")
def f(x):
cnt=0
while(x>0):
x%=popcount(x)
cnt+=1
return cnt
n=int(eval(input()))
s=eval(input())
d=s.count("1")
if d==0:
for i in range(n):
print((1))
elif d==1:
if s[-1]=="1":
for i in range(n-1):
print((2))
else:
print((0))
else:
for i in range(n-1):
if s[i]=="1":
print((0))
else:
print((1))
print((2))
else:
s=s[::-1]
toaddm=1
toaddM=1
m=0
M=0
for i in range(n):
if s[i]=="1":
m+=toaddm
M+=toaddM
m%=d-1
M%=d+1
toaddm*=2
toaddm%=d-1
toaddM*=2
toaddM%=d+1
toaddm=-1
toaddM=1
res=[None for i in range(n)]
for i in range(n):
if s[i]=="1":
res[i]=f((m+toaddm)%(d-1))+1
else:
res[i]=f((M+toaddM)%(d+1))+1
toaddm*=2
toaddm%=d-1
toaddM*=2
toaddM%=d+1
for i in res[::-1]:
print(i)
| def popcount(x):
return bin(x)[2:].count("1")
def f(x):
cnt=0
while(x>0):
x%=popcount(x)
cnt+=1
return cnt
n=int(eval(input()))
s=eval(input())
d=s.count("1")
if d==0:
for i in range(n):
print((1))
elif d==1:
if s[-1]=="1":
for i in range(n-1):
print((2))
else:
print((0))
else:
for i in range(n-1):
if s[i]=="1":
print((0))
else:
print((1))
print((2))
else:
ints=int(s,2)
m=ints%(d-1)
M=ints%(d+1)
s=s[::-1]
toaddm=-1
toaddM=1
res=[None for i in range(n)]
for i in range(n):
if s[i]=="1":
res[i]=f((m+toaddm)%(d-1))+1
else:
res[i]=f((M+toaddM)%(d+1))+1
toaddm*=2
toaddm%=d-1
toaddM*=2
toaddM%=d+1
for i in res[::-1]:
print(i)
| 59 | 48 | 1,136 | 932 | def popcount(x):
return bin(x)[2:].count("1")
def f(x):
cnt = 0
while x > 0:
x %= popcount(x)
cnt += 1
return cnt
n = int(eval(input()))
s = eval(input())
d = s.count("1")
if d == 0:
for i in range(n):
print((1))
elif d == 1:
if s[-1] == "1":
for i in range(n - 1):
print((2))
else:
print((0))
else:
for i in range(n - 1):
if s[i] == "1":
print((0))
else:
print((1))
print((2))
else:
s = s[::-1]
toaddm = 1
toaddM = 1
m = 0
M = 0
for i in range(n):
if s[i] == "1":
m += toaddm
M += toaddM
m %= d - 1
M %= d + 1
toaddm *= 2
toaddm %= d - 1
toaddM *= 2
toaddM %= d + 1
toaddm = -1
toaddM = 1
res = [None for i in range(n)]
for i in range(n):
if s[i] == "1":
res[i] = f((m + toaddm) % (d - 1)) + 1
else:
res[i] = f((M + toaddM) % (d + 1)) + 1
toaddm *= 2
toaddm %= d - 1
toaddM *= 2
toaddM %= d + 1
for i in res[::-1]:
print(i)
| def popcount(x):
return bin(x)[2:].count("1")
def f(x):
cnt = 0
while x > 0:
x %= popcount(x)
cnt += 1
return cnt
n = int(eval(input()))
s = eval(input())
d = s.count("1")
if d == 0:
for i in range(n):
print((1))
elif d == 1:
if s[-1] == "1":
for i in range(n - 1):
print((2))
else:
print((0))
else:
for i in range(n - 1):
if s[i] == "1":
print((0))
else:
print((1))
print((2))
else:
ints = int(s, 2)
m = ints % (d - 1)
M = ints % (d + 1)
s = s[::-1]
toaddm = -1
toaddM = 1
res = [None for i in range(n)]
for i in range(n):
if s[i] == "1":
res[i] = f((m + toaddm) % (d - 1)) + 1
else:
res[i] = f((M + toaddM) % (d + 1)) + 1
toaddm *= 2
toaddm %= d - 1
toaddM *= 2
toaddM %= d + 1
for i in res[::-1]:
print(i)
| false | 18.644068 | [
"+ ints = int(s, 2)",
"+ m = ints % (d - 1)",
"+ M = ints % (d + 1)",
"- toaddm = 1",
"- toaddM = 1",
"- m = 0",
"- M = 0",
"- for i in range(n):",
"- if s[i] == \"1\":",
"- m += toaddm",
"- M += toaddM",
"- m %= d - 1",
"- M %= d + 1",
"- toaddm *= 2",
"- toaddm %= d - 1",
"- toaddM *= 2",
"- toaddM %= d + 1"
] | false | 0.040552 | 0.041972 | 0.96615 | [
"s808016502",
"s334422150"
] |
u630511239 | p02995 | python | s459586394 | s441468792 | 35 | 30 | 5,076 | 9,184 | Accepted | Accepted | 14.29 | A, B, C, D = list(map(int, input().split()))
import fractions
g = fractions.gcd(C, D)
ac = (A-1)//C
bc = B//C
c = bc-ac
ad = (A-1)//D
bd = B//D
d = bd-ad
cdg = (C*D)//g
acd = (A-1)//cdg
bcd = B//cdg
cd = bcd-acd
ans = B-A+1-c-d+cd
print(ans) | A, B, C, D = list(map(int, input().split()))
A -= 1
import math
g = C*D//math.gcd(C, D)
a = A//C + A//D - A//g
b = B//C + B//D - B//g
ans = B - A - b + a
print(ans) | 15 | 8 | 249 | 165 | A, B, C, D = list(map(int, input().split()))
import fractions
g = fractions.gcd(C, D)
ac = (A - 1) // C
bc = B // C
c = bc - ac
ad = (A - 1) // D
bd = B // D
d = bd - ad
cdg = (C * D) // g
acd = (A - 1) // cdg
bcd = B // cdg
cd = bcd - acd
ans = B - A + 1 - c - d + cd
print(ans)
| A, B, C, D = list(map(int, input().split()))
A -= 1
import math
g = C * D // math.gcd(C, D)
a = A // C + A // D - A // g
b = B // C + B // D - B // g
ans = B - A - b + a
print(ans)
| false | 46.666667 | [
"-import fractions",
"+A -= 1",
"+import math",
"-g = fractions.gcd(C, D)",
"-ac = (A - 1) // C",
"-bc = B // C",
"-c = bc - ac",
"-ad = (A - 1) // D",
"-bd = B // D",
"-d = bd - ad",
"-cdg = (C * D) // g",
"-acd = (A - 1) // cdg",
"-bcd = B // cdg",
"-cd = bcd - acd",
"-ans = B - A + 1 - c - d + cd",
"+g = C * D // math.gcd(C, D)",
"+a = A // C + A // D - A // g",
"+b = B // C + B // D - B // g",
"+ans = B - A - b + a"
] | false | 0.136314 | 0.090219 | 1.510921 | [
"s459586394",
"s441468792"
] |
u047796752 | p02722 | python | s879302323 | s000791510 | 233 | 208 | 39,152 | 39,024 | Accepted | Accepted | 10.73 | def make_div(n):
divs = []
for i in range(1, int(n**0.5)+1):
if n%i==0:
divs.append(i)
if i!=n//i:
divs.append(n//i)
divs.sort()
return divs
N = int(eval(input()))
d = make_div(N)
d = d[1:]
s = set()
for di in d:
N2 = N
while N2%di==0:
N2 //= di
if (N2-1)%di==0:
s.add(di)
d = make_div(N-1)
d = d[1:]
for di in d:
s.add(di)
print((len(s))) | def make_divs(n):
divs = []
for i in range(1, int(n**0.5)+1):
if n%i==0:
divs.append(i)
if i!=n//i:
divs.append(n//i)
return divs
N = int(eval(input()))
divs = make_divs(N)
ans = 0
for d in divs:
if d==1:
continue
N2 = N
while N2%d==0:
N2 //= d
if (N2-1)%d==0:
ans += 1
divs = make_divs(N-1)
ans += len(divs)-1
print(ans) | 35 | 32 | 504 | 488 | def make_div(n):
divs = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divs.append(i)
if i != n // i:
divs.append(n // i)
divs.sort()
return divs
N = int(eval(input()))
d = make_div(N)
d = d[1:]
s = set()
for di in d:
N2 = N
while N2 % di == 0:
N2 //= di
if (N2 - 1) % di == 0:
s.add(di)
d = make_div(N - 1)
d = d[1:]
for di in d:
s.add(di)
print((len(s)))
| def make_divs(n):
divs = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divs.append(i)
if i != n // i:
divs.append(n // i)
return divs
N = int(eval(input()))
divs = make_divs(N)
ans = 0
for d in divs:
if d == 1:
continue
N2 = N
while N2 % d == 0:
N2 //= d
if (N2 - 1) % d == 0:
ans += 1
divs = make_divs(N - 1)
ans += len(divs) - 1
print(ans)
| false | 8.571429 | [
"-def make_div(n):",
"+def make_divs(n):",
"- divs.sort()",
"-d = make_div(N)",
"-d = d[1:]",
"-s = set()",
"-for di in d:",
"+divs = make_divs(N)",
"+ans = 0",
"+for d in divs:",
"+ if d == 1:",
"+ continue",
"- while N2 % di == 0:",
"- N2 //= di",
"- if (N2 - 1) % di == 0:",
"- s.add(di)",
"-d = make_div(N - 1)",
"-d = d[1:]",
"-for di in d:",
"- s.add(di)",
"-print((len(s)))",
"+ while N2 % d == 0:",
"+ N2 //= d",
"+ if (N2 - 1) % d == 0:",
"+ ans += 1",
"+divs = make_divs(N - 1)",
"+ans += len(divs) - 1",
"+print(ans)"
] | false | 0.007929 | 0.054625 | 0.145161 | [
"s879302323",
"s000791510"
] |
u790710233 | p03546 | python | s760551271 | s399302858 | 260 | 33 | 17,364 | 3,064 | Accepted | Accepted | 87.31 | from scipy.sparse.csgraph import dijkstra, csgraph_from_dense
from collections import defaultdict
h, w = list(map(int, input().split()))
table = [list(map(int, input().split())) for _ in range(10)]
dd = defaultdict(int)
for _ in range(h):
for x in map(int, input().split()):
if x == -1:
continue
dd[x] += 1
trans_table = list(zip(*table))
scores = dijkstra(csgraph_from_dense(trans_table), indices=1)
ans = 0
for k, v in list(dd.items()):
ans += int(scores[k])*v
print(ans) | import heapq
h, w = list(map(int, input().split()))
graph = [list(map(int, input().split())) for _ in range(10)]
trans_graph = list(zip(*graph))
next_nodes = []
for idx, d in enumerate(trans_graph[1]):
next_nodes.append((d, idx))
heapq.heapify(next_nodes)
INF = 10**9
decided = [0]*10
decided[1] = 1
dist = [INF]*10
dist[1] = 0
while 0 in decided:
distance, v = heapq.heappop(next_nodes)
if decided[v]:
continue
decided[v] = 1
dist[v] = distance
for v2, x in enumerate(trans_graph[v]):
if decided[v2]:
continue
heapq.heappush(next_nodes, (dist[v]+x, v2))
ans = 0
for _ in range(h):
for x in map(int, input().split()):
if x == -1:
continue
ans += dist[x]
print(ans) | 18 | 35 | 516 | 789 | from scipy.sparse.csgraph import dijkstra, csgraph_from_dense
from collections import defaultdict
h, w = list(map(int, input().split()))
table = [list(map(int, input().split())) for _ in range(10)]
dd = defaultdict(int)
for _ in range(h):
for x in map(int, input().split()):
if x == -1:
continue
dd[x] += 1
trans_table = list(zip(*table))
scores = dijkstra(csgraph_from_dense(trans_table), indices=1)
ans = 0
for k, v in list(dd.items()):
ans += int(scores[k]) * v
print(ans)
| import heapq
h, w = list(map(int, input().split()))
graph = [list(map(int, input().split())) for _ in range(10)]
trans_graph = list(zip(*graph))
next_nodes = []
for idx, d in enumerate(trans_graph[1]):
next_nodes.append((d, idx))
heapq.heapify(next_nodes)
INF = 10**9
decided = [0] * 10
decided[1] = 1
dist = [INF] * 10
dist[1] = 0
while 0 in decided:
distance, v = heapq.heappop(next_nodes)
if decided[v]:
continue
decided[v] = 1
dist[v] = distance
for v2, x in enumerate(trans_graph[v]):
if decided[v2]:
continue
heapq.heappush(next_nodes, (dist[v] + x, v2))
ans = 0
for _ in range(h):
for x in map(int, input().split()):
if x == -1:
continue
ans += dist[x]
print(ans)
| false | 48.571429 | [
"-from scipy.sparse.csgraph import dijkstra, csgraph_from_dense",
"-from collections import defaultdict",
"+import heapq",
"-table = [list(map(int, input().split())) for _ in range(10)]",
"-dd = defaultdict(int)",
"+graph = [list(map(int, input().split())) for _ in range(10)]",
"+trans_graph = list(zip(*graph))",
"+next_nodes = []",
"+for idx, d in enumerate(trans_graph[1]):",
"+ next_nodes.append((d, idx))",
"+heapq.heapify(next_nodes)",
"+INF = 10**9",
"+decided = [0] * 10",
"+decided[1] = 1",
"+dist = [INF] * 10",
"+dist[1] = 0",
"+while 0 in decided:",
"+ distance, v = heapq.heappop(next_nodes)",
"+ if decided[v]:",
"+ continue",
"+ decided[v] = 1",
"+ dist[v] = distance",
"+ for v2, x in enumerate(trans_graph[v]):",
"+ if decided[v2]:",
"+ continue",
"+ heapq.heappush(next_nodes, (dist[v] + x, v2))",
"+ans = 0",
"- dd[x] += 1",
"-trans_table = list(zip(*table))",
"-scores = dijkstra(csgraph_from_dense(trans_table), indices=1)",
"-ans = 0",
"-for k, v in list(dd.items()):",
"- ans += int(scores[k]) * v",
"+ ans += dist[x]"
] | false | 0.562601 | 0.037959 | 14.821453 | [
"s760551271",
"s399302858"
] |
u618251217 | p02862 | python | s701566994 | s619830753 | 1,027 | 558 | 9,220 | 93,156 | Accepted | Accepted | 45.67 | mod = 10**9 + 7
def nCk(n,k,p):
global mod
k = min(k, n-k)
X = 1
for i in range(k):
X = X * (n - i) % p
X = X * pow(i + 1, p - 2, p) % p
return X
X,Y = list(map(int, input().split()))
ans = 0
if X <= 2*Y and Y <= 2*X and (X + Y) % 3 == 0:
a = (2*Y-X) // 3
b = (2*X-Y) // 3
ans = nCk(a + b, b, mod)
print(ans) | X,Y = list(map(int, input().split()))
mod = 10**9 + 7
def nCk(n,k,p):
fact = [1,1] + [0]*(n-1)
inv = [0,1] + [0]*(n-1)
factinv = [1,1] + [0]*(n-1)
for i in range(2, n+1):
fact[i] = i * fact[i-1] % p
inv[i] = - inv[p % i] * (p // i) % p
factinv[i] = factinv[i-1] * inv[i] % p
return fact[n] * factinv[k] * factinv[n-k] % p
ans = 0
if (X + Y) % 3 == 0 and X <= 2*Y and Y <= 2*X:
a = (2*Y - X) // 3
b = (2*X - Y) // 3
ans = nCk(a+b, a, mod)
print(ans) | 20 | 21 | 377 | 537 | mod = 10**9 + 7
def nCk(n, k, p):
global mod
k = min(k, n - k)
X = 1
for i in range(k):
X = X * (n - i) % p
X = X * pow(i + 1, p - 2, p) % p
return X
X, Y = list(map(int, input().split()))
ans = 0
if X <= 2 * Y and Y <= 2 * X and (X + Y) % 3 == 0:
a = (2 * Y - X) // 3
b = (2 * X - Y) // 3
ans = nCk(a + b, b, mod)
print(ans)
| X, Y = list(map(int, input().split()))
mod = 10**9 + 7
def nCk(n, k, p):
fact = [1, 1] + [0] * (n - 1)
inv = [0, 1] + [0] * (n - 1)
factinv = [1, 1] + [0] * (n - 1)
for i in range(2, n + 1):
fact[i] = i * fact[i - 1] % p
inv[i] = -inv[p % i] * (p // i) % p
factinv[i] = factinv[i - 1] * inv[i] % p
return fact[n] * factinv[k] * factinv[n - k] % p
ans = 0
if (X + Y) % 3 == 0 and X <= 2 * Y and Y <= 2 * X:
a = (2 * Y - X) // 3
b = (2 * X - Y) // 3
ans = nCk(a + b, a, mod)
print(ans)
| false | 4.761905 | [
"+X, Y = list(map(int, input().split()))",
"- global mod",
"- k = min(k, n - k)",
"- X = 1",
"- for i in range(k):",
"- X = X * (n - i) % p",
"- X = X * pow(i + 1, p - 2, p) % p",
"- return X",
"+ fact = [1, 1] + [0] * (n - 1)",
"+ inv = [0, 1] + [0] * (n - 1)",
"+ factinv = [1, 1] + [0] * (n - 1)",
"+ for i in range(2, n + 1):",
"+ fact[i] = i * fact[i - 1] % p",
"+ inv[i] = -inv[p % i] * (p // i) % p",
"+ factinv[i] = factinv[i - 1] * inv[i] % p",
"+ return fact[n] * factinv[k] * factinv[n - k] % p",
"-X, Y = list(map(int, input().split()))",
"-if X <= 2 * Y and Y <= 2 * X and (X + Y) % 3 == 0:",
"+if (X + Y) % 3 == 0 and X <= 2 * Y and Y <= 2 * X:",
"- ans = nCk(a + b, b, mod)",
"+ ans = nCk(a + b, a, mod)"
] | false | 0.007092 | 0.39419 | 0.017991 | [
"s701566994",
"s619830753"
] |
u094191970 | p02912 | python | s914933148 | s113307058 | 171 | 154 | 14,180 | 14,180 | Accepted | Accepted | 9.94 | import heapq
n,m=list(map(int,input().split()))
a=[-int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
max=-heapq.heappop(a)
heapq.heappush(a,-1*(max//2))
print((sum([-int(i) for i in a]))) | import heapq
n,m=list(map(int,input().split()))
a=[-int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
max=-heapq.heappop(a)
heapq.heappush(a,-1*(max//2))
print((-sum(a))) | 11 | 11 | 214 | 196 | import heapq
n, m = list(map(int, input().split()))
a = [-int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
max = -heapq.heappop(a)
heapq.heappush(a, -1 * (max // 2))
print((sum([-int(i) for i in a])))
| import heapq
n, m = list(map(int, input().split()))
a = [-int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
max = -heapq.heappop(a)
heapq.heappush(a, -1 * (max // 2))
print((-sum(a)))
| false | 0 | [
"-print((sum([-int(i) for i in a])))",
"+print((-sum(a)))"
] | false | 0.050229 | 0.046035 | 1.091102 | [
"s914933148",
"s113307058"
] |
u263830634 | p03722 | python | s045443928 | s753640845 | 835 | 341 | 3,444 | 45,292 | Accepted | Accepted | 59.16 | #単一始点最短経路問題
#負の辺があっても動作する
#最短経路を求める
#計算量O(N * M)
INF = 10 ** 15
#入力
N, M = list(map(int, input().split()))
# 入力は1-index
# 内部で0-indexにして処理
G = []
for _ in range(M): #M個の辺の情報を受け取る
l, r, s = list(map(int, input().split())) #lからrへ重みsの辺が存在
G += [[l-1, r-1, -s]] #有向グラフのときはここだけ
#メイン文
d = [INF] * N #最短距離を記録しておくリスト
prev = [-1] * N
#最短経路復元
def restore(g): #gまでの最短経路を復元
path = []
g -= 1 #0-indexに直す
path.append(g)
g = prev[g]
count = 0
while g != -1:
# print ('C')
path.append(g)
g = prev[g]
count += 1
if count == N + 2:
break
path.reverse()
return path
def shortest_path(s): #S番目の頂点から各頂点への最短距離を求める
s -= 1
for i in range(N):
d[i] = INF
d[s] = 0
count = 0
while True:
if count == N:
# print ('B')
path = restore(N)
# print (prev)
# print (path)
update = False
for i in range(M): #無向グラフのときは辺は実質的には2倍
e = G[i]
if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
d[e[1]] = d[e[0]] + e[2]
if e[1] in path:
return False
update = True
prev[e[1]] = e[0]
return True
count += 1
# print ('A')
update = False
for i in range(M): #無向グラフのときは辺は実質的には2倍
e = G[i]
if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
d[e[1]] = d[e[0]] + e[2]
update = True
prev[e[1]] = e[0]
if not update:
return True
#呼び出しスタート地点を入れる
if shortest_path(1):
print((-d[N - 1]))
else:
print ('inf')
# print (d) | #単一始点最短経路問題
#負の辺があっても動作する
#最短経路を求める
#計算量O(N * M)
INF = 10 ** 15
#入力
N, M = list(map(int, input().split()))
# 入力は1-index
# 内部で0-indexにして処理
G = []
for _ in range(M): #M個の辺の情報を受け取る
l, r, s = list(map(int, input().split())) #lからrへ重みsの辺が存在
G += [[l-1, r-1, -s]] #有向グラフのときはここだけ
#メイン文
d = [INF] * N #最短距離を記録しておくリスト
# prev = [-1] * N
negative = [False] * N
#最短経路復元
def restore(g): #gまでの最短経路を復元
path = []
g -= 1 #0-indexに直す
path.append(g)
g = prev[g]
count = 0
while g != -1:
# print ('C')
path.append(g)
g = prev[g]
count += 1
if count == N + 2:
break
path.reverse()
return path
def shortest_path(s): #S番目の頂点から各頂点への最短距離を求める
s -= 1
for i in range(N):
d[i] = INF
d[s] = 0
count = 0
while count < N -1:
count += 1
# print ('A')
# update = False
for i in range(M): #無向グラフのときは辺は実質的には2倍
e = G[i]
if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
d[e[1]] = d[e[0]] + e[2]
# update = True
# prev[e[1]] = e[0]
# if not update:
# return True
count = 0
while count < N:
count += 1
# print ('A')
for i in range(M): #無向グラフのときは辺は実質的には2倍
e = G[i]
if d[e[0]] == INF:
continue
if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
d[e[1]] = d[e[0]] + e[2]
negative[e[1]] = True
if negative[e[0]]:
negative[e[1]] = True
#呼び出しスタート地点を入れる
shortest_path(1)
if not negative[N - 1]:
print((-d[N - 1]))
else:
print ('inf')
# print (d) | 81 | 81 | 1,810 | 1,766 | # 単一始点最短経路問題
# 負の辺があっても動作する
# 最短経路を求める
# 計算量O(N * M)
INF = 10**15
# 入力
N, M = list(map(int, input().split()))
# 入力は1-index
# 内部で0-indexにして処理
G = []
for _ in range(M): # M個の辺の情報を受け取る
l, r, s = list(map(int, input().split())) # lからrへ重みsの辺が存在
G += [[l - 1, r - 1, -s]] # 有向グラフのときはここだけ
# メイン文
d = [INF] * N # 最短距離を記録しておくリスト
prev = [-1] * N
# 最短経路復元
def restore(g): # gまでの最短経路を復元
path = []
g -= 1 # 0-indexに直す
path.append(g)
g = prev[g]
count = 0
while g != -1:
# print ('C')
path.append(g)
g = prev[g]
count += 1
if count == N + 2:
break
path.reverse()
return path
def shortest_path(s): # S番目の頂点から各頂点への最短距離を求める
s -= 1
for i in range(N):
d[i] = INF
d[s] = 0
count = 0
while True:
if count == N:
# print ('B')
path = restore(N)
# print (prev)
# print (path)
update = False
for i in range(M): # 無向グラフのときは辺は実質的には2倍
e = G[i]
if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
d[e[1]] = d[e[0]] + e[2]
if e[1] in path:
return False
update = True
prev[e[1]] = e[0]
return True
count += 1
# print ('A')
update = False
for i in range(M): # 無向グラフのときは辺は実質的には2倍
e = G[i]
if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
d[e[1]] = d[e[0]] + e[2]
update = True
prev[e[1]] = e[0]
if not update:
return True
# 呼び出しスタート地点を入れる
if shortest_path(1):
print((-d[N - 1]))
else:
print("inf")
# print (d)
| # 単一始点最短経路問題
# 負の辺があっても動作する
# 最短経路を求める
# 計算量O(N * M)
INF = 10**15
# 入力
N, M = list(map(int, input().split()))
# 入力は1-index
# 内部で0-indexにして処理
G = []
for _ in range(M): # M個の辺の情報を受け取る
l, r, s = list(map(int, input().split())) # lからrへ重みsの辺が存在
G += [[l - 1, r - 1, -s]] # 有向グラフのときはここだけ
# メイン文
d = [INF] * N # 最短距離を記録しておくリスト
# prev = [-1] * N
negative = [False] * N
# 最短経路復元
def restore(g): # gまでの最短経路を復元
path = []
g -= 1 # 0-indexに直す
path.append(g)
g = prev[g]
count = 0
while g != -1:
# print ('C')
path.append(g)
g = prev[g]
count += 1
if count == N + 2:
break
path.reverse()
return path
def shortest_path(s): # S番目の頂点から各頂点への最短距離を求める
s -= 1
for i in range(N):
d[i] = INF
d[s] = 0
count = 0
while count < N - 1:
count += 1
# print ('A')
# update = False
for i in range(M): # 無向グラフのときは辺は実質的には2倍
e = G[i]
if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
d[e[1]] = d[e[0]] + e[2]
# update = True
# prev[e[1]] = e[0]
# if not update:
# return True
count = 0
while count < N:
count += 1
# print ('A')
for i in range(M): # 無向グラフのときは辺は実質的には2倍
e = G[i]
if d[e[0]] == INF:
continue
if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
d[e[1]] = d[e[0]] + e[2]
negative[e[1]] = True
if negative[e[0]]:
negative[e[1]] = True
# 呼び出しスタート地点を入れる
shortest_path(1)
if not negative[N - 1]:
print((-d[N - 1]))
else:
print("inf")
# print (d)
| false | 0 | [
"-prev = [-1] * N",
"+# prev = [-1] * N",
"+negative = [False] * N",
"- while True:",
"- if count == N:",
"- # print ('B')",
"- path = restore(N)",
"- # print (prev)",
"- # print (path)",
"- update = False",
"- for i in range(M): # 無向グラフのときは辺は実質的には2倍",
"- e = G[i]",
"- if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:",
"- d[e[1]] = d[e[0]] + e[2]",
"- if e[1] in path:",
"- return False",
"- update = True",
"- prev[e[1]] = e[0]",
"- return True",
"+ while count < N - 1:",
"- update = False",
"+ # update = False",
"- update = True",
"- prev[e[1]] = e[0]",
"- if not update:",
"- return True",
"+ # update = True",
"+ # prev[e[1]] = e[0]",
"+ # if not update:",
"+ # return True",
"+ count = 0",
"+ while count < N:",
"+ count += 1",
"+ # print ('A')",
"+ for i in range(M): # 無向グラフのときは辺は実質的には2倍",
"+ e = G[i]",
"+ if d[e[0]] == INF:",
"+ continue",
"+ if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:",
"+ d[e[1]] = d[e[0]] + e[2]",
"+ negative[e[1]] = True",
"+ if negative[e[0]]:",
"+ negative[e[1]] = True",
"-if shortest_path(1):",
"+shortest_path(1)",
"+if not negative[N - 1]:"
] | false | 0.038242 | 0.039035 | 0.979703 | [
"s045443928",
"s753640845"
] |
u462329577 | p03013 | python | s350287155 | s949845142 | 493 | 449 | 51,032 | 460,020 | Accepted | Accepted | 8.92 | n,m = list(map(int,input().split()))
#a = [int(input()) for i in range(m)]
a=set()
for i in range(m):
tmp=int(eval(input()))
a.add(tmp)
mod = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
j=0
for i in range(1,n+1):
if i in a:
#dp[a[j]] = 0
continue
if i==1:
dp[1] = dp[0]
continue
dp[i] = dp[i-1]+dp[i-2]
dp[i]%=mod
print((dp[n])) | #!/usr/bin/env python3
n,m = list(map(int,input().split()))
a = [int(eval(input())) for _ in range(m)]
dp = [-1]*(n+2)#dp[k]はk-1段目に到達する方法
dp[0] = 0
dp[1] = 1
mod = 10**9+7
for i in a:
dp[i+1] = 0
for i in range(n+2):
if dp[i] == -1:#already visited or prepared
dp[i] = (dp[i-1]+dp[i-2])
#print(dp)
print((dp[n+1]%mod)) | 20 | 14 | 355 | 333 | n, m = list(map(int, input().split()))
# a = [int(input()) for i in range(m)]
a = set()
for i in range(m):
tmp = int(eval(input()))
a.add(tmp)
mod = 10**9 + 7
dp = [0] * (n + 1)
dp[0] = 1
j = 0
for i in range(1, n + 1):
if i in a:
# dp[a[j]] = 0
continue
if i == 1:
dp[1] = dp[0]
continue
dp[i] = dp[i - 1] + dp[i - 2]
dp[i] %= mod
print((dp[n]))
| #!/usr/bin/env python3
n, m = list(map(int, input().split()))
a = [int(eval(input())) for _ in range(m)]
dp = [-1] * (n + 2) # dp[k]はk-1段目に到達する方法
dp[0] = 0
dp[1] = 1
mod = 10**9 + 7
for i in a:
dp[i + 1] = 0
for i in range(n + 2):
if dp[i] == -1: # already visited or prepared
dp[i] = dp[i - 1] + dp[i - 2]
# print(dp)
print((dp[n + 1] % mod))
| false | 30 | [
"+#!/usr/bin/env python3",
"-# a = [int(input()) for i in range(m)]",
"-a = set()",
"-for i in range(m):",
"- tmp = int(eval(input()))",
"- a.add(tmp)",
"+a = [int(eval(input())) for _ in range(m)]",
"+dp = [-1] * (n + 2) # dp[k]はk-1段目に到達する方法",
"+dp[0] = 0",
"+dp[1] = 1",
"-dp = [0] * (n + 1)",
"-dp[0] = 1",
"-j = 0",
"-for i in range(1, n + 1):",
"- if i in a:",
"- # dp[a[j]] = 0",
"- continue",
"- if i == 1:",
"- dp[1] = dp[0]",
"- continue",
"- dp[i] = dp[i - 1] + dp[i - 2]",
"- dp[i] %= mod",
"-print((dp[n]))",
"+for i in a:",
"+ dp[i + 1] = 0",
"+for i in range(n + 2):",
"+ if dp[i] == -1: # already visited or prepared",
"+ dp[i] = dp[i - 1] + dp[i - 2]",
"+# print(dp)",
"+print((dp[n + 1] % mod))"
] | false | 0.04013 | 0.040398 | 0.993368 | [
"s350287155",
"s949845142"
] |
u867826040 | p02580 | python | s246546231 | s571223278 | 2,153 | 942 | 156,420 | 138,456 | Accepted | Accepted | 56.25 | #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)
| #from random import randint
def f(h,w,m,ins):
yp = [0]*h
xp = [0]*w
s = set()
for hi,wi in ins:
s.add((hi-1,wi-1))
yp[hi-1] += 1
xp[wi-1] += 1
ypm = max(yp)
xpm = max(xp)
yps = [i for i in range(h) if yp[i] == ypm]
xps = [i for i in range(w) if xp[i] == xpm]
ans = ypm+xpm
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)
| 35 | 33 | 991 | 923 | # 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)
| # from random import randint
def f(h, w, m, ins):
yp = [0] * h
xp = [0] * w
s = set()
for hi, wi in ins:
s.add((hi - 1, wi - 1))
yp[hi - 1] += 1
xp[wi - 1] += 1
ypm = max(yp)
xpm = max(xp)
yps = [i for i in range(h) if yp[i] == ypm]
xps = [i for i in range(w) if xp[i] == xpm]
ans = ypm + xpm
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 | 5.714286 | [
"-import numpy as np",
"-",
"-",
"- yp = np.zeros(h, dtype=np.int32)",
"- xp = np.zeros(w, dtype=np.int32)",
"+ yp = [0] * h",
"+ xp = [0] * w",
"- 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]]",
"+ ypm = max(yp)",
"+ xpm = max(xp)",
"+ yps = [i for i in range(h) if yp[i] == ypm]",
"+ xps = [i for i in range(w) if xp[i] == xpm]",
"+ ans = ypm + xpm"
] | false | 0.276936 | 0.042963 | 6.445843 | [
"s246546231",
"s571223278"
] |
u844005364 | p03329 | python | s540022218 | s394660385 | 168 | 26 | 38,384 | 3,936 | Accepted | Accepted | 84.52 | import bisect
from functools import lru_cache
six_list = [6 ** i for i in range(7)]
nine_list = [9 ** i for i in range(6)]
@lru_cache(maxsize=1000)
def six_nine(n):
if n < 6:
return n
else:
six = six_list[bisect.bisect_right(six_list, n) - 1]
nine = nine_list[bisect.bisect_right(nine_list, n) - 1]
return min(n // six + six_nine(n % six), 1 + six_nine(n - nine))
if __name__ == '__main__':
x = int(eval(input()))
print((six_nine(x))) | import bisect
six_list = [6 ** i for i in range(7)]
nine_list = [9 ** i for i in range(6)]
from functools import lru_cache
@lru_cache(maxsize=1000)
def six_nine(n):
if n < 6:
return n
else:
six = six_list[bisect.bisect_right(six_list, n) - 1]
nine = nine_list[bisect.bisect_right(nine_list, n) - 1]
return min(n // six + six_nine(n % six), 1 + six_nine(n - nine))
if __name__ == '__main__':
x = int(eval(input()))
print((six_nine(x))) | 20 | 21 | 498 | 500 | import bisect
from functools import lru_cache
six_list = [6**i for i in range(7)]
nine_list = [9**i for i in range(6)]
@lru_cache(maxsize=1000)
def six_nine(n):
if n < 6:
return n
else:
six = six_list[bisect.bisect_right(six_list, n) - 1]
nine = nine_list[bisect.bisect_right(nine_list, n) - 1]
return min(n // six + six_nine(n % six), 1 + six_nine(n - nine))
if __name__ == "__main__":
x = int(eval(input()))
print((six_nine(x)))
| import bisect
six_list = [6**i for i in range(7)]
nine_list = [9**i for i in range(6)]
from functools import lru_cache
@lru_cache(maxsize=1000)
def six_nine(n):
if n < 6:
return n
else:
six = six_list[bisect.bisect_right(six_list, n) - 1]
nine = nine_list[bisect.bisect_right(nine_list, n) - 1]
return min(n // six + six_nine(n % six), 1 + six_nine(n - nine))
if __name__ == "__main__":
x = int(eval(input()))
print((six_nine(x)))
| false | 4.761905 | [
"-from functools import lru_cache",
"+from functools import lru_cache"
] | false | 0.04259 | 0.034043 | 1.25105 | [
"s540022218",
"s394660385"
] |
u729133443 | p02936 | python | s265580012 | s243159640 | 1,160 | 1,072 | 178,100 | 55,764 | Accepted | Accepted | 7.59 | (n,q),*t=[list(map(int,t.split()))for t in open(0)]
s=[0]
d=s*n
f=s*n
e=[[]for _ in d]
for a,b in t:
if~-n:n-=1;e[a-1]+=b-1,;e[b-1]+=a-1,
else:d[a-1]+=b
while s:
v=s.pop();f[v]=-1
for w in e[v]:
if~f[w]:d[w]+=d[v];s+=w,
print((*d)) | def main():
import sys
入力 = sys.stdin.readline
範囲, 出力 = range, print
真, 偽 = True, False
何もしない = None
一行に複数個の入力 = lambda:map(int, 入力().split())
頂点の数, 操作回数 = 一行に複数個の入力()
辺 = [[] for _ in 範囲(頂点の数)]
カウンター = [0] * 頂点の数
辺の数 = 頂点の数-1
for _ in 範囲(辺の数):
頂点1, 頂点2 = 一行に複数個の入力()
頂点1 -= 1
頂点2 -= 1
辺[頂点1] += 頂点2,
辺[頂点2] += 頂点1,
for _ in 範囲(操作回数):
頂点, 足す値 = 一行に複数個の入力()
頂点 -= 1
カウンター[頂点] += 足す値
到達済み = [偽] * 頂点の数
親 = 0
到達済み[親] = 真
スタック = [親]
while スタック:
親 = スタック.pop()
for 子 in 辺[親]:
if 到達済み[子]:
何もしない
else:
到達済み[子] = 真
カウンター[子] += カウンター[親]
スタック += 子,
出力(*カウンター)
main()
| 13 | 36 | 241 | 831 | (n, q), *t = [list(map(int, t.split())) for t in open(0)]
s = [0]
d = s * n
f = s * n
e = [[] for _ in d]
for a, b in t:
if ~-n:
n -= 1
e[a - 1] += (b - 1,)
e[b - 1] += (a - 1,)
else:
d[a - 1] += b
while s:
v = s.pop()
f[v] = -1
for w in e[v]:
if ~f[w]:
d[w] += d[v]
s += (w,)
print((*d))
| def main():
import sys
入力 = sys.stdin.readline
範囲, 出力 = range, print
真, 偽 = True, False
何もしない = None
一行に複数個の入力 = lambda: map(int, 入力().split())
頂点の数, 操作回数 = 一行に複数個の入力()
辺 = [[] for _ in 範囲(頂点の数)]
カウンター = [0] * 頂点の数
辺の数 = 頂点の数 - 1
for _ in 範囲(辺の数):
頂点1, 頂点2 = 一行に複数個の入力()
頂点1 -= 1
頂点2 -= 1
辺[頂点1] += (頂点2,)
辺[頂点2] += (頂点1,)
for _ in 範囲(操作回数):
頂点, 足す値 = 一行に複数個の入力()
頂点 -= 1
カウンター[頂点] += 足す値
到達済み = [偽] * 頂点の数
親 = 0
到達済み[親] = 真
スタック = [親]
while スタック:
親 = スタック.pop()
for 子 in 辺[親]:
if 到達済み[子]:
何もしない
else:
到達済み[子] = 真
カウンター[子] += カウンター[親]
スタック += (子,)
出力(*カウンター)
main()
| false | 63.888889 | [
"-(n, q), *t = [list(map(int, t.split())) for t in open(0)]",
"-s = [0]",
"-d = s * n",
"-f = s * n",
"-e = [[] for _ in d]",
"-for a, b in t:",
"- if ~-n:",
"- n -= 1",
"- e[a - 1] += (b - 1,)",
"- e[b - 1] += (a - 1,)",
"- else:",
"- d[a - 1] += b",
"-while s:",
"- v = s.pop()",
"- f[v] = -1",
"- for w in e[v]:",
"- if ~f[w]:",
"- d[w] += d[v]",
"- s += (w,)",
"-print((*d))",
"+def main():",
"+ import sys",
"+",
"+ 入力 = sys.stdin.readline",
"+ 範囲, 出力 = range, print",
"+ 真, 偽 = True, False",
"+ 何もしない = None",
"+ 一行に複数個の入力 = lambda: map(int, 入力().split())",
"+ 頂点の数, 操作回数 = 一行に複数個の入力()",
"+ 辺 = [[] for _ in 範囲(頂点の数)]",
"+ カウンター = [0] * 頂点の数",
"+ 辺の数 = 頂点の数 - 1",
"+ for _ in 範囲(辺の数):",
"+ 頂点1, 頂点2 = 一行に複数個の入力()",
"+ 頂点1 -= 1",
"+ 頂点2 -= 1",
"+ 辺[頂点1] += (頂点2,)",
"+ 辺[頂点2] += (頂点1,)",
"+ for _ in 範囲(操作回数):",
"+ 頂点, 足す値 = 一行に複数個の入力()",
"+ 頂点 -= 1",
"+ カウンター[頂点] += 足す値",
"+ 到達済み = [偽] * 頂点の数",
"+ 親 = 0",
"+ 到達済み[親] = 真",
"+ スタック = [親]",
"+ while スタック:",
"+ 親 = スタック.pop()",
"+ for 子 in 辺[親]:",
"+ if 到達済み[子]:",
"+ 何もしない",
"+ else:",
"+ 到達済み[子] = 真",
"+ カウンター[子] += カウンター[親]",
"+ スタック += (子,)",
"+ 出力(*カウンター)",
"+",
"+",
"+main()"
] | false | 0.044215 | 0.070688 | 0.625502 | [
"s265580012",
"s243159640"
] |
u413165887 | p02913 | python | s321166192 | s730580805 | 1,658 | 1,507 | 42,296 | 3,188 | Accepted | Accepted | 9.11 | n = int(eval(input()))
s = eval(input())
j = 1
result = [0]
for i in range(n):
while (j < n-1) and (s[i:j] in s[:i]+"0"+s[j:]):
j += 1
result.append(j-i-1)
print((max(result))) | n = int(eval(input()))
s = eval(input())
j = 1
result = []
for i in range(n):
while (j < n-1) and (s[i:j] in s[:i]+"0"+s[j:]):
j += 1
result.append(j-i-1)
print((max(result))) | 9 | 9 | 186 | 185 | n = int(eval(input()))
s = eval(input())
j = 1
result = [0]
for i in range(n):
while (j < n - 1) and (s[i:j] in s[:i] + "0" + s[j:]):
j += 1
result.append(j - i - 1)
print((max(result)))
| n = int(eval(input()))
s = eval(input())
j = 1
result = []
for i in range(n):
while (j < n - 1) and (s[i:j] in s[:i] + "0" + s[j:]):
j += 1
result.append(j - i - 1)
print((max(result)))
| false | 0 | [
"-result = [0]",
"+result = []"
] | false | 0.039673 | 0.037837 | 1.048541 | [
"s321166192",
"s730580805"
] |
u380524497 | p03426 | python | s866568286 | s958469562 | 1,134 | 996 | 27,100 | 20,724 | Accepted | Accepted | 12.17 | h, w, d = list(map(int, input().split()))
A = []
for _ in range(h):
line = list(map(int, input().split()))
A.append(line)
num_to_xy = [[0, 0] for i in range(h*w + 1)]
for y in range(h):
for x in range(w):
num = A[y][x]
num_to_xy[num] = [x, y]
costs = [[] for i in range(d+1)]
for mod in range(1, d+1):
num = mod
sx, sy = num_to_xy[num]
cost = 0
while num <= h*w:
nx, ny = num_to_xy[num]
cost += abs(nx-sx) + abs(ny-sy)
costs[mod].append(cost)
num += d
sx, sy = nx, ny
q = int(eval(input()))
for _ in range(q):
l, r = list(map(int, input().split()))
mod = l % d
if mod == 0:
mod = d
idx = (l-mod) // d
step = (r-l) // d
res = costs[mod][idx+step] - costs[mod][idx]
print(res) | h, w, d = list(map(int, input().split()))
A = []
for _ in range(h):
line = list(map(int, input().split()))
A.append(line)
num_to_xy = [[0, 0] for i in range(h*w + 1)]
for y in range(h):
for x in range(w):
num = A[y][x]
num_to_xy[num] = [x, y]
costs = [0] * (h*w+1)
for start in range(1, d+1):
cost = 0
num = start
sx, sy = num_to_xy[num]
while num <= h*w:
nx, ny = num_to_xy[num]
cost += abs(nx-sx) + abs(ny-sy)
costs[num] = cost
sx, sy = nx, ny
num += d
q = int(eval(input()))
for _ in range(q):
l, r = list(map(int, input().split()))
print((costs[r] - costs[l])) | 38 | 32 | 820 | 674 | h, w, d = list(map(int, input().split()))
A = []
for _ in range(h):
line = list(map(int, input().split()))
A.append(line)
num_to_xy = [[0, 0] for i in range(h * w + 1)]
for y in range(h):
for x in range(w):
num = A[y][x]
num_to_xy[num] = [x, y]
costs = [[] for i in range(d + 1)]
for mod in range(1, d + 1):
num = mod
sx, sy = num_to_xy[num]
cost = 0
while num <= h * w:
nx, ny = num_to_xy[num]
cost += abs(nx - sx) + abs(ny - sy)
costs[mod].append(cost)
num += d
sx, sy = nx, ny
q = int(eval(input()))
for _ in range(q):
l, r = list(map(int, input().split()))
mod = l % d
if mod == 0:
mod = d
idx = (l - mod) // d
step = (r - l) // d
res = costs[mod][idx + step] - costs[mod][idx]
print(res)
| h, w, d = list(map(int, input().split()))
A = []
for _ in range(h):
line = list(map(int, input().split()))
A.append(line)
num_to_xy = [[0, 0] for i in range(h * w + 1)]
for y in range(h):
for x in range(w):
num = A[y][x]
num_to_xy[num] = [x, y]
costs = [0] * (h * w + 1)
for start in range(1, d + 1):
cost = 0
num = start
sx, sy = num_to_xy[num]
while num <= h * w:
nx, ny = num_to_xy[num]
cost += abs(nx - sx) + abs(ny - sy)
costs[num] = cost
sx, sy = nx, ny
num += d
q = int(eval(input()))
for _ in range(q):
l, r = list(map(int, input().split()))
print((costs[r] - costs[l]))
| false | 15.789474 | [
"-costs = [[] for i in range(d + 1)]",
"-for mod in range(1, d + 1):",
"- num = mod",
"+costs = [0] * (h * w + 1)",
"+for start in range(1, d + 1):",
"+ cost = 0",
"+ num = start",
"- cost = 0",
"- costs[mod].append(cost)",
"+ costs[num] = cost",
"+ sx, sy = nx, ny",
"- sx, sy = nx, ny",
"- mod = l % d",
"- if mod == 0:",
"- mod = d",
"- idx = (l - mod) // d",
"- step = (r - l) // d",
"- res = costs[mod][idx + step] - costs[mod][idx]",
"- print(res)",
"+ print((costs[r] - costs[l]))"
] | false | 0.046538 | 0.045994 | 1.01183 | [
"s866568286",
"s958469562"
] |
u054514819 | p03786 | python | s678904688 | s034367711 | 126 | 109 | 14,320 | 92,544 | Accepted | Accepted | 13.49 | N = int(eval(input()))
As = list(map(int, input().split()))
As.sort()
from itertools import accumulate
cum = list(accumulate(As))
cnt = 0
for n in range(N-1):
if cum[n]*2>=As[n+1]:
cnt += 1
else:
cnt = 0
cnt += 1
print(cnt) | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
N = int(eval(input()))
As = [0]+list(mapint())
As.sort()
from itertools import accumulate
cAs = list(accumulate(As))
cAs.sort(reverse=True)
As.sort(reverse=True)
ans = 1
for i in range(1, N):
if cAs[i]*2<As[i-1]:
break
ans += 1
print(ans) | 13 | 20 | 253 | 406 | N = int(eval(input()))
As = list(map(int, input().split()))
As.sort()
from itertools import accumulate
cum = list(accumulate(As))
cnt = 0
for n in range(N - 1):
if cum[n] * 2 >= As[n + 1]:
cnt += 1
else:
cnt = 0
cnt += 1
print(cnt)
| import sys
def input():
return sys.stdin.readline().strip()
def mapint():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
N = int(eval(input()))
As = [0] + list(mapint())
As.sort()
from itertools import accumulate
cAs = list(accumulate(As))
cAs.sort(reverse=True)
As.sort(reverse=True)
ans = 1
for i in range(1, N):
if cAs[i] * 2 < As[i - 1]:
break
ans += 1
print(ans)
| false | 35 | [
"+import sys",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+",
"+def mapint():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+sys.setrecursionlimit(10**9)",
"-As = list(map(int, input().split()))",
"+As = [0] + list(mapint())",
"-cum = list(accumulate(As))",
"-cnt = 0",
"-for n in range(N - 1):",
"- if cum[n] * 2 >= As[n + 1]:",
"- cnt += 1",
"- else:",
"- cnt = 0",
"-cnt += 1",
"-print(cnt)",
"+cAs = list(accumulate(As))",
"+cAs.sort(reverse=True)",
"+As.sort(reverse=True)",
"+ans = 1",
"+for i in range(1, N):",
"+ if cAs[i] * 2 < As[i - 1]:",
"+ break",
"+ ans += 1",
"+print(ans)"
] | false | 0.038861 | 0.038551 | 1.008035 | [
"s678904688",
"s034367711"
] |
u607563136 | p02675 | python | s839678862 | s788279691 | 29 | 26 | 9,148 | 9,160 | Accepted | Accepted | 10.34 | n = eval(input())
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
if int(n[-1]) in hon:
print("hon")
elif int(n[-1]) in pon:
print("pon")
elif int(n[-1]) in bon:
print("bon") | n = int(eval(input()))
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
print(("hon" if n%10 in hon else "pon" if n%10 in pon else "bon")) | 12 | 6 | 189 | 131 | n = eval(input())
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]
if int(n[-1]) in hon:
print("hon")
elif int(n[-1]) in pon:
print("pon")
elif int(n[-1]) in bon:
print("bon")
| n = int(eval(input()))
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]
print(("hon" if n % 10 in hon else "pon" if n % 10 in pon else "bon"))
| false | 50 | [
"-n = eval(input())",
"+n = int(eval(input()))",
"-if int(n[-1]) in hon:",
"- print(\"hon\")",
"-elif int(n[-1]) in pon:",
"- print(\"pon\")",
"-elif int(n[-1]) in bon:",
"- print(\"bon\")",
"+print((\"hon\" if n % 10 in hon else \"pon\" if n % 10 in pon else \"bon\"))"
] | false | 0.066878 | 0.048316 | 1.384173 | [
"s839678862",
"s788279691"
] |
u635277286 | p03661 | python | s557498501 | s810699179 | 240 | 196 | 24,832 | 23,800 | Accepted | Accepted | 18.33 | N = int(eval(input()))
a = list(map(int,input().split()))
cum_sum = [0]*N
cum_sum[0] = a[0]
for i in range(1,N):
cum_sum[i] = cum_sum[i-1] + a[i]
res = 10**15
for i in range(N-1):
x = cum_sum[i]
y = cum_sum[N-1] - cum_sum[i]
res = min(res, abs(x-y))
print(res) | N = int(eval(input()))
a = list(map(int,input().split()))
x = a[0]
y = sum(a[1:])
res = abs(x - y)
for i in range(1, N - 1):
x += a[i]
y -= a[i]
res = min(res, abs(x - y))
print(res) | 16 | 13 | 277 | 194 | N = int(eval(input()))
a = list(map(int, input().split()))
cum_sum = [0] * N
cum_sum[0] = a[0]
for i in range(1, N):
cum_sum[i] = cum_sum[i - 1] + a[i]
res = 10**15
for i in range(N - 1):
x = cum_sum[i]
y = cum_sum[N - 1] - cum_sum[i]
res = min(res, abs(x - y))
print(res)
| N = int(eval(input()))
a = list(map(int, input().split()))
x = a[0]
y = sum(a[1:])
res = abs(x - y)
for i in range(1, N - 1):
x += a[i]
y -= a[i]
res = min(res, abs(x - y))
print(res)
| false | 18.75 | [
"-cum_sum = [0] * N",
"-cum_sum[0] = a[0]",
"-for i in range(1, N):",
"- cum_sum[i] = cum_sum[i - 1] + a[i]",
"-res = 10**15",
"-for i in range(N - 1):",
"- x = cum_sum[i]",
"- y = cum_sum[N - 1] - cum_sum[i]",
"+x = a[0]",
"+y = sum(a[1:])",
"+res = abs(x - y)",
"+for i in range(1, N - 1):",
"+ x += a[i]",
"+ y -= a[i]"
] | false | 0.039536 | 0.043406 | 0.910851 | [
"s557498501",
"s810699179"
] |
u754022296 | p02863 | python | s206477754 | s965120566 | 393 | 170 | 114,652 | 97,576 | Accepted | Accepted | 56.74 | import sys
input = sys.stdin.readline
read = sys.stdin.read
n, t = list(map(int, input().split()))
m = list(map(int, read().split()))
AB = sorted(zip(m, m))
A, B = list(zip(*AB))
dp = [[0]*t for _ in range(n+1)]
for i, a in enumerate(A[:-1]):
for j in range(t):
if j < a:
dp[i+1][j] = dp[i][j]
else:
dp[i+1][j] = max(dp[i][j-a]+B[i], dp[i][j])
ans = 0
maxB = [B[-1]]*n
for i in range(n-2, 0, -1):
maxB[i] = max(B[i], maxB[i+1])
for i in range(n-1):
ans = max(ans, dp[i+1][-1] + maxB[i+1])
print(ans) | import sys
input = sys.stdin.readline
read = sys.stdin.read
import numpy as np
n, t = list(map(int, input().split()))
m = list(map(int, read().split()))
AB = sorted(zip(m, m))
A, B = list(zip(*AB))
dp = np.zeros((n+1, t), dtype=np.int64)
for i, (a, b) in enumerate(AB):
np.maximum(dp[i, a:], dp[i, :-a]+b, out=dp[i+1, a:])
maxB = np.maximum.accumulate(B[::-1])[::-1]
ans = (dp[1:-1, -1]+maxB[1:]).max()
print(ans) | 22 | 15 | 529 | 412 | import sys
input = sys.stdin.readline
read = sys.stdin.read
n, t = list(map(int, input().split()))
m = list(map(int, read().split()))
AB = sorted(zip(m, m))
A, B = list(zip(*AB))
dp = [[0] * t for _ in range(n + 1)]
for i, a in enumerate(A[:-1]):
for j in range(t):
if j < a:
dp[i + 1][j] = dp[i][j]
else:
dp[i + 1][j] = max(dp[i][j - a] + B[i], dp[i][j])
ans = 0
maxB = [B[-1]] * n
for i in range(n - 2, 0, -1):
maxB[i] = max(B[i], maxB[i + 1])
for i in range(n - 1):
ans = max(ans, dp[i + 1][-1] + maxB[i + 1])
print(ans)
| import sys
input = sys.stdin.readline
read = sys.stdin.read
import numpy as np
n, t = list(map(int, input().split()))
m = list(map(int, read().split()))
AB = sorted(zip(m, m))
A, B = list(zip(*AB))
dp = np.zeros((n + 1, t), dtype=np.int64)
for i, (a, b) in enumerate(AB):
np.maximum(dp[i, a:], dp[i, :-a] + b, out=dp[i + 1, a:])
maxB = np.maximum.accumulate(B[::-1])[::-1]
ans = (dp[1:-1, -1] + maxB[1:]).max()
print(ans)
| false | 31.818182 | [
"+import numpy as np",
"+",
"-dp = [[0] * t for _ in range(n + 1)]",
"-for i, a in enumerate(A[:-1]):",
"- for j in range(t):",
"- if j < a:",
"- dp[i + 1][j] = dp[i][j]",
"- else:",
"- dp[i + 1][j] = max(dp[i][j - a] + B[i], dp[i][j])",
"-ans = 0",
"-maxB = [B[-1]] * n",
"-for i in range(n - 2, 0, -1):",
"- maxB[i] = max(B[i], maxB[i + 1])",
"-for i in range(n - 1):",
"- ans = max(ans, dp[i + 1][-1] + maxB[i + 1])",
"+dp = np.zeros((n + 1, t), dtype=np.int64)",
"+for i, (a, b) in enumerate(AB):",
"+ np.maximum(dp[i, a:], dp[i, :-a] + b, out=dp[i + 1, a:])",
"+maxB = np.maximum.accumulate(B[::-1])[::-1]",
"+ans = (dp[1:-1, -1] + maxB[1:]).max()"
] | false | 0.1442 | 0.370917 | 0.388765 | [
"s206477754",
"s965120566"
] |
u312025627 | p02915 | python | s749415730 | s226452358 | 183 | 160 | 38,384 | 38,256 | Accepted | Accepted | 12.57 | n = int(eval(input()))
print((n**3)) | def main():
N = int(eval(input()))
print((N**3))
if __name__ == '__main__':
main()
| 2 | 7 | 29 | 95 | n = int(eval(input()))
print((n**3))
| def main():
N = int(eval(input()))
print((N**3))
if __name__ == "__main__":
main()
| false | 71.428571 | [
"-n = int(eval(input()))",
"-print((n**3))",
"+def main():",
"+ N = int(eval(input()))",
"+ print((N**3))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.04589 | 0.045535 | 1.007809 | [
"s749415730",
"s226452358"
] |
u378691508 | p02711 | python | s106583758 | s450290223 | 22 | 19 | 8,988 | 9,116 | Accepted | Accepted | 13.64 | N=eval(input())
if '7' in N:
print('Yes')
else:
print('No')
| N=eval(input())
print(("Yes" if "7" in N else "No")) | 5 | 3 | 66 | 47 | N = eval(input())
if "7" in N:
print("Yes")
else:
print("No")
| N = eval(input())
print(("Yes" if "7" in N else "No"))
| false | 40 | [
"-if \"7\" in N:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+print((\"Yes\" if \"7\" in N else \"No\"))"
] | false | 0.079375 | 0.040645 | 1.952894 | [
"s106583758",
"s450290223"
] |
u920254817 | p02990 | python | s301968241 | s890318407 | 997 | 60 | 98,388 | 3,444 | Accepted | Accepted | 93.98 | N, K = list(map(int, input().split()))
MOD = 10**9 + 7
kai = []
kai.append(1)
for idx in range(1, N+5):
kai.append((kai[idx-1] * idx) % MOD)
#Mod pow
#def modpow(ori, po, mod):
# res = 1;
# while(po > 0):
# if(po&1):
# res *= ori;
# res %= mod;
# ori *= ori;
# ori %= mod;
# po >>= 1;
# return res;
comb = [[0] * 2005 for i in range(2005)]
def combination():
for i in range(2000):
comb[i][0] = 1;
for j in range(1, i+1):
comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
comb[i][j] %= MOD
#def comb(n, k):
# return (kai[n] * modpow(kai[k], MOD-2, MOD) * modpow(kai[n-k], MOD-2, MOD))%MOD
combination()
for i in range(K):
blue=comb[K-1][i]%MOD
red=comb[N-K+1][i+1]%MOD
print(((blue*red)%MOD)) | N, K = list(map(int, input().split()))
MOD = 10**9 + 7
kai = []
kai.append(1)
for idx in range(1, N+5):
kai.append((kai[-1] * idx) % MOD)
#Mod pow
def modpow(ori, po):
res = 1;
while(po > 0):
if(po&1):
res *= ori
res %= MOD
ori *= ori
ori %= MOD
po >>= 1
return res
def comb(n, k):
if(n == 0 and k == 0):
return 1
if(n < k or n < 0):
return 0
ans = kai[n]
ans *= modpow(kai[k], MOD-2)
ans %= MOD
ans *= modpow(kai[n-k], MOD-2)
ans %= MOD
return ans
for i in range(K):
blue=comb(K-1, i)%MOD
red=comb(N-K+1, i+1)%MOD
print(((blue*red)%MOD)) | 43 | 35 | 754 | 600 | N, K = list(map(int, input().split()))
MOD = 10**9 + 7
kai = []
kai.append(1)
for idx in range(1, N + 5):
kai.append((kai[idx - 1] * idx) % MOD)
# Mod pow
# def modpow(ori, po, mod):
# res = 1;
# while(po > 0):
# if(po&1):
# res *= ori;
# res %= mod;
# ori *= ori;
# ori %= mod;
# po >>= 1;
# return res;
comb = [[0] * 2005 for i in range(2005)]
def combination():
for i in range(2000):
comb[i][0] = 1
for j in range(1, i + 1):
comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]
comb[i][j] %= MOD
# def comb(n, k):
# return (kai[n] * modpow(kai[k], MOD-2, MOD) * modpow(kai[n-k], MOD-2, MOD))%MOD
combination()
for i in range(K):
blue = comb[K - 1][i] % MOD
red = comb[N - K + 1][i + 1] % MOD
print(((blue * red) % MOD))
| N, K = list(map(int, input().split()))
MOD = 10**9 + 7
kai = []
kai.append(1)
for idx in range(1, N + 5):
kai.append((kai[-1] * idx) % MOD)
# Mod pow
def modpow(ori, po):
res = 1
while po > 0:
if po & 1:
res *= ori
res %= MOD
ori *= ori
ori %= MOD
po >>= 1
return res
def comb(n, k):
if n == 0 and k == 0:
return 1
if n < k or n < 0:
return 0
ans = kai[n]
ans *= modpow(kai[k], MOD - 2)
ans %= MOD
ans *= modpow(kai[n - k], MOD - 2)
ans %= MOD
return ans
for i in range(K):
blue = comb(K - 1, i) % MOD
red = comb(N - K + 1, i + 1) % MOD
print(((blue * red) % MOD))
| false | 18.604651 | [
"- kai.append((kai[idx - 1] * idx) % MOD)",
"+ kai.append((kai[-1] * idx) % MOD)",
"-# def modpow(ori, po, mod):",
"-# \tres = 1;",
"-# \twhile(po > 0):",
"-# \t\tif(po&1):",
"-# \t\t\tres *= ori;",
"-# \t\t\tres %= mod;",
"-# \t\tori *= ori;",
"-# \t\tori %= mod;",
"-# \t\tpo >>= 1;",
"-# \treturn res;",
"-comb = [[0] * 2005 for i in range(2005)]",
"+def modpow(ori, po):",
"+ res = 1",
"+ while po > 0:",
"+ if po & 1:",
"+ res *= ori",
"+ res %= MOD",
"+ ori *= ori",
"+ ori %= MOD",
"+ po >>= 1",
"+ return res",
"-def combination():",
"- for i in range(2000):",
"- comb[i][0] = 1",
"- for j in range(1, i + 1):",
"- comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]",
"- comb[i][j] %= MOD",
"+def comb(n, k):",
"+ if n == 0 and k == 0:",
"+ return 1",
"+ if n < k or n < 0:",
"+ return 0",
"+ ans = kai[n]",
"+ ans *= modpow(kai[k], MOD - 2)",
"+ ans %= MOD",
"+ ans *= modpow(kai[n - k], MOD - 2)",
"+ ans %= MOD",
"+ return ans",
"-# def comb(n, k):",
"-# \treturn (kai[n] * modpow(kai[k], MOD-2, MOD) * modpow(kai[n-k], MOD-2, MOD))%MOD",
"-combination()",
"- blue = comb[K - 1][i] % MOD",
"- red = comb[N - K + 1][i + 1] % MOD",
"+ blue = comb(K - 1, i) % MOD",
"+ red = comb(N - K + 1, i + 1) % MOD"
] | false | 2.018003 | 0.037332 | 54.05499 | [
"s301968241",
"s890318407"
] |
u585482323 | p04034 | python | s937091287 | s912819450 | 313 | 277 | 43,868 | 44,464 | Accepted | Accepted | 11.5 | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
return
#B
def B():
n,m = LI()
f = [1]*n
l = [0]*n
l[0] = 1
for i in range(m):
x,y = LI()
x -= 1
y -= 1
if l[x]:
l[y] = 1
f[x] -= 1
f[y] += 1
if f[x] == 0:
l[x] = 0
ans = 0
for i in range(n):
if l[i]:
ans += 1
print(ans)
return
#C
def C():
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#Solve
if __name__ == "__main__":
B()
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n,m = LI()
s = [1]*n
f = [0]*n
f[0] = 1
for _ in range(m):
a,b = LI()
a -= 1
b -= 1
s[a] -= 1
s[b] += 1
if f[a]:
f[b] = 1
if s[a] == 0:
f[a] = 0
print((sum(f)))
return
#Solve
if __name__ == "__main__":
solve()
| 78 | 48 | 1,269 | 1,091 | #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
# A
def A():
return
# B
def B():
n, m = LI()
f = [1] * n
l = [0] * n
l[0] = 1
for i in range(m):
x, y = LI()
x -= 1
y -= 1
if l[x]:
l[y] = 1
f[x] -= 1
f[y] += 1
if f[x] == 0:
l[x] = 0
ans = 0
for i in range(n):
if l[i]:
ans += 1
print(ans)
return
# C
def C():
return
# D
def D():
return
# E
def E():
return
# F
def F():
return
# Solve
if __name__ == "__main__":
B()
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n, m = LI()
s = [1] * n
f = [0] * n
f[0] = 1
for _ in range(m):
a, b = LI()
a -= 1
b -= 1
s[a] -= 1
s[b] += 1
if f[a]:
f[b] = 1
if s[a] == 0:
f[a] = 0
print((sum(f)))
return
# Solve
if __name__ == "__main__":
solve()
| false | 38.461538 | [
"+from itertools import permutations, accumulate",
"-import random",
"-# A",
"-def A():",
"- return",
"-# B",
"-def B():",
"+def solve():",
"- f = [1] * n",
"- l = [0] * n",
"- l[0] = 1",
"- for i in range(m):",
"- x, y = LI()",
"- x -= 1",
"- y -= 1",
"- if l[x]:",
"- l[y] = 1",
"- f[x] -= 1",
"- f[y] += 1",
"- if f[x] == 0:",
"- l[x] = 0",
"- ans = 0",
"- for i in range(n):",
"- if l[i]:",
"- ans += 1",
"- print(ans)",
"- return",
"-",
"-",
"-# C",
"-def C():",
"- return",
"-",
"-",
"-# D",
"-def D():",
"- return",
"-",
"-",
"-# E",
"-def E():",
"- return",
"-",
"-",
"-# F",
"-def F():",
"+ s = [1] * n",
"+ f = [0] * n",
"+ f[0] = 1",
"+ for _ in range(m):",
"+ a, b = LI()",
"+ a -= 1",
"+ b -= 1",
"+ s[a] -= 1",
"+ s[b] += 1",
"+ if f[a]:",
"+ f[b] = 1",
"+ if s[a] == 0:",
"+ f[a] = 0",
"+ print((sum(f)))",
"- B()",
"+ solve()"
] | false | 0.036498 | 0.041902 | 0.87103 | [
"s937091287",
"s912819450"
] |
u137226361 | p02832 | python | s013916070 | s831301520 | 94 | 85 | 32,248 | 31,480 | Accepted | Accepted | 9.57 | n = int(eval(input()))
an = list(map(int, input().split()))
num = 1
for i in an:
if i == num:
num +=1
if num == 1:
print((-1))
exit(0)
ans = 1+n-num
print(ans) | import sys
n = int(eval(input()))
a = list(map(int, sys.stdin.readline().split()))
m = 1
for i in a:
if i == m:
m += 1
if m == 1:
print((-1))
exit(0)
print((1+n-m)) | 11 | 11 | 181 | 184 | n = int(eval(input()))
an = list(map(int, input().split()))
num = 1
for i in an:
if i == num:
num += 1
if num == 1:
print((-1))
exit(0)
ans = 1 + n - num
print(ans)
| import sys
n = int(eval(input()))
a = list(map(int, sys.stdin.readline().split()))
m = 1
for i in a:
if i == m:
m += 1
if m == 1:
print((-1))
exit(0)
print((1 + n - m))
| false | 0 | [
"+import sys",
"+",
"-an = list(map(int, input().split()))",
"-num = 1",
"-for i in an:",
"- if i == num:",
"- num += 1",
"-if num == 1:",
"+a = list(map(int, sys.stdin.readline().split()))",
"+m = 1",
"+for i in a:",
"+ if i == m:",
"+ m += 1",
"+if m == 1:",
"-ans = 1 + n - num",
"-print(ans)",
"+print((1 + n - m))"
] | false | 0.04725 | 0.04906 | 0.963108 | [
"s013916070",
"s831301520"
] |
u417365712 | p02735 | python | s231277678 | s755356354 | 362 | 240 | 21,052 | 12,680 | Accepted | Accepted | 33.7 | inputs = [s.strip() for s in open(0).readlines()]
import numpy as np
class Grid():
def __init__(self, grid, w=0, h=0, function=lambda x: x):
self.w = w = w if w else len(grid[0])
self.h = h = h if h else len(grid)
dtype = type(function(grid[0][0]))
self.grid = np.empty((h, w), dtype=dtype)
for i, row in zip(list(range(h)), grid):
for j, val in zip(list(range(w)), row):
self.grid[i][j] = function(val)
def is_valid_x(self, x):
return 0 <= x < self.w
def is_valid_y(self, y):
return 0 <= y < self.h
def is_valid_xy(self, x, y):
return self.is_valid_x(x) and self.is_valid_y(y)
def __iter__(self):
return iter(self.grid)
def __repr__(self):
return '\n'.join([' '.join(map(str, row)) for row in self.grid])
def __getitem__(self, x):
return self.grid[x]
def __setitem__(self, x, val):
self.grid[x] = val
h, w = list(map(int, inputs[0].split()))
grid = Grid(inputs[1:]).grid
dp = np.zeros((h, w), np.int)
if grid[0][0] == '#':
dp[0, 0] = 1
for i in range(1, w):
dp[0, i] = dp[0, i-1] + int(grid[0, i-1] + grid[0, i] == '.#')
for i in range(1, h):
dp[i, 0] = dp[i-1, 0] + int(grid[i-1, 0] + grid[i, 0] == '.#')
x = y = 1
while not (x == w-1 and y == h-1):
for i in range(x, w):
dp[y, i] = min(dp[y, i-1] + int(grid[y, i-1] + grid[y, i] == '.#'),
dp[y-1, i] + int(grid[y-1, i] + grid[y, i] == '.#'))
for i in range(y+1, h):
dp[i, x] = min(dp[i-1, x] + int(grid[i-1, x] + grid[i, x] == '.#'),
dp[i, x-1] + int(grid[i, x-1] + grid[i, x] == '.#'))
x, y = min(x+1, w-1), min(y+1, h-1)
print((min(dp[y-1, x] + int(grid[y-1, x] + grid[y, x] == '.#'),
dp[y, x-1] + int(grid[y, x-1] + grid[y, x] == '.#')))) | inputs = [s.strip() for s in open(0).readlines()]
import numpy as np
class Grid():
def __init__(self, grid, w=0, h=0, function=lambda x: x):
self.w = w = w if w else len(grid[0])
self.h = h = h if h else len(grid)
dtype = type(function(grid[0][0]))
self.grid = np.empty((h, w), dtype=dtype)
for i, row in zip(list(range(h)), grid):
for j, val in zip(list(range(w)), row):
self.grid[i][j] = function(val)
def is_valid_x(self, x):
return 0 <= x < self.w
def is_valid_y(self, y):
return 0 <= y < self.h
def is_valid_xy(self, x, y):
return self.is_valid_x(x) and self.is_valid_y(y)
def __iter__(self):
return iter(self.grid)
def __repr__(self):
return '\n'.join([' '.join(map(str, row)) for row in self.grid])
def __getitem__(self, x):
return self.grid[x]
def __setitem__(self, x, val):
self.grid[x] = val
h, w = list(map(int, inputs[0].split()))
grid = Grid(inputs[1:]).grid
h, w = list(map(int, inputs[0].split()))
grid = Grid(inputs[1:])
dp = Grid(np.zeros((h, w), np.int))
dp[0, 0] = int(grid[0, 0] == '#')
for i in range(1, w):
dp[0, i] = dp[0, i-1] + int(grid[0, i-1] + grid[0, i] == '.#')
for i in range(1, h):
dp[i, 0] = dp[i-1, 0] + int(grid[i-1, 0] + grid[i, 0] == '.#')
x = y = 1
while not (x == w-1 and y == h-1):
for i in range(x, w):
dp[y, i] = min(dp[y, i-1] + int(grid[y, i-1] + grid[y, i] == '.#'),
dp[y-1, i] + int(grid[y-1, i] + grid[y, i] == '.#'))
for i in range(y+1, h):
dp[i, x] = min(dp[i-1, x] + int(grid[i-1, x] + grid[i, x] == '.#'),
dp[i, x-1] + int(grid[i, x-1] + grid[i, x] == '.#'))
x, y = min(x+1, w-1), min(y+1, h-1)
print((min(dp[y-1, x] + int(grid[y-1, x] + grid[y, x] == '.#'),
dp[y, x-1] + int(grid[y, x-1] + grid[y, x] == '.#')))) | 49 | 51 | 1,888 | 1,951 | inputs = [s.strip() for s in open(0).readlines()]
import numpy as np
class Grid:
def __init__(self, grid, w=0, h=0, function=lambda x: x):
self.w = w = w if w else len(grid[0])
self.h = h = h if h else len(grid)
dtype = type(function(grid[0][0]))
self.grid = np.empty((h, w), dtype=dtype)
for i, row in zip(list(range(h)), grid):
for j, val in zip(list(range(w)), row):
self.grid[i][j] = function(val)
def is_valid_x(self, x):
return 0 <= x < self.w
def is_valid_y(self, y):
return 0 <= y < self.h
def is_valid_xy(self, x, y):
return self.is_valid_x(x) and self.is_valid_y(y)
def __iter__(self):
return iter(self.grid)
def __repr__(self):
return "\n".join([" ".join(map(str, row)) for row in self.grid])
def __getitem__(self, x):
return self.grid[x]
def __setitem__(self, x, val):
self.grid[x] = val
h, w = list(map(int, inputs[0].split()))
grid = Grid(inputs[1:]).grid
dp = np.zeros((h, w), np.int)
if grid[0][0] == "#":
dp[0, 0] = 1
for i in range(1, w):
dp[0, i] = dp[0, i - 1] + int(grid[0, i - 1] + grid[0, i] == ".#")
for i in range(1, h):
dp[i, 0] = dp[i - 1, 0] + int(grid[i - 1, 0] + grid[i, 0] == ".#")
x = y = 1
while not (x == w - 1 and y == h - 1):
for i in range(x, w):
dp[y, i] = min(
dp[y, i - 1] + int(grid[y, i - 1] + grid[y, i] == ".#"),
dp[y - 1, i] + int(grid[y - 1, i] + grid[y, i] == ".#"),
)
for i in range(y + 1, h):
dp[i, x] = min(
dp[i - 1, x] + int(grid[i - 1, x] + grid[i, x] == ".#"),
dp[i, x - 1] + int(grid[i, x - 1] + grid[i, x] == ".#"),
)
x, y = min(x + 1, w - 1), min(y + 1, h - 1)
print(
(
min(
dp[y - 1, x] + int(grid[y - 1, x] + grid[y, x] == ".#"),
dp[y, x - 1] + int(grid[y, x - 1] + grid[y, x] == ".#"),
)
)
)
| inputs = [s.strip() for s in open(0).readlines()]
import numpy as np
class Grid:
def __init__(self, grid, w=0, h=0, function=lambda x: x):
self.w = w = w if w else len(grid[0])
self.h = h = h if h else len(grid)
dtype = type(function(grid[0][0]))
self.grid = np.empty((h, w), dtype=dtype)
for i, row in zip(list(range(h)), grid):
for j, val in zip(list(range(w)), row):
self.grid[i][j] = function(val)
def is_valid_x(self, x):
return 0 <= x < self.w
def is_valid_y(self, y):
return 0 <= y < self.h
def is_valid_xy(self, x, y):
return self.is_valid_x(x) and self.is_valid_y(y)
def __iter__(self):
return iter(self.grid)
def __repr__(self):
return "\n".join([" ".join(map(str, row)) for row in self.grid])
def __getitem__(self, x):
return self.grid[x]
def __setitem__(self, x, val):
self.grid[x] = val
h, w = list(map(int, inputs[0].split()))
grid = Grid(inputs[1:]).grid
h, w = list(map(int, inputs[0].split()))
grid = Grid(inputs[1:])
dp = Grid(np.zeros((h, w), np.int))
dp[0, 0] = int(grid[0, 0] == "#")
for i in range(1, w):
dp[0, i] = dp[0, i - 1] + int(grid[0, i - 1] + grid[0, i] == ".#")
for i in range(1, h):
dp[i, 0] = dp[i - 1, 0] + int(grid[i - 1, 0] + grid[i, 0] == ".#")
x = y = 1
while not (x == w - 1 and y == h - 1):
for i in range(x, w):
dp[y, i] = min(
dp[y, i - 1] + int(grid[y, i - 1] + grid[y, i] == ".#"),
dp[y - 1, i] + int(grid[y - 1, i] + grid[y, i] == ".#"),
)
for i in range(y + 1, h):
dp[i, x] = min(
dp[i - 1, x] + int(grid[i - 1, x] + grid[i, x] == ".#"),
dp[i, x - 1] + int(grid[i, x - 1] + grid[i, x] == ".#"),
)
x, y = min(x + 1, w - 1), min(y + 1, h - 1)
print(
(
min(
dp[y - 1, x] + int(grid[y - 1, x] + grid[y, x] == ".#"),
dp[y, x - 1] + int(grid[y, x - 1] + grid[y, x] == ".#"),
)
)
)
| false | 3.921569 | [
"-dp = np.zeros((h, w), np.int)",
"-if grid[0][0] == \"#\":",
"- dp[0, 0] = 1",
"+h, w = list(map(int, inputs[0].split()))",
"+grid = Grid(inputs[1:])",
"+dp = Grid(np.zeros((h, w), np.int))",
"+dp[0, 0] = int(grid[0, 0] == \"#\")"
] | false | 0.251769 | 0.209617 | 1.201091 | [
"s231277678",
"s755356354"
] |
u888092736 | p03523 | python | s149152171 | s648767960 | 32 | 26 | 9,052 | 8,980 | Accepted | Accepted | 18.75 | from itertools import product
candidates = set()
non_as = ["KIH", "B", "R", ""]
for seps in product(["A", ""], repeat=4):
candidates.add("".join(sep + non_a for sep, non_a in zip(seps, non_as)))
print("YES") if input() in candidates else print("NO")
| from itertools import product
candidates = []
non_as = ["KIH", "B", "R", ""]
for seps in product(["A", ""], repeat=4):
candidates.append("".join(sep + non_a for sep, non_a in zip(seps, non_as)))
print("YES") if input() in candidates else print("NO")
| 9 | 9 | 265 | 265 | from itertools import product
candidates = set()
non_as = ["KIH", "B", "R", ""]
for seps in product(["A", ""], repeat=4):
candidates.add("".join(sep + non_a for sep, non_a in zip(seps, non_as)))
print("YES") if input() in candidates else print("NO")
| from itertools import product
candidates = []
non_as = ["KIH", "B", "R", ""]
for seps in product(["A", ""], repeat=4):
candidates.append("".join(sep + non_a for sep, non_a in zip(seps, non_as)))
print("YES") if input() in candidates else print("NO")
| false | 0 | [
"-candidates = set()",
"+candidates = []",
"- candidates.add(\"\".join(sep + non_a for sep, non_a in zip(seps, non_as)))",
"+ candidates.append(\"\".join(sep + non_a for sep, non_a in zip(seps, non_as)))"
] | false | 0.035928 | 0.033776 | 1.06372 | [
"s149152171",
"s648767960"
] |
u707124227 | p02585 | python | s461318973 | s404731510 | 538 | 280 | 75,000 | 75,112 | Accepted | Accepted | 47.96 | n,k=list(map(int,input().split()))
p=list(map(int,input().split()))
c=list(map(int,input().split()))
root=[]
mi=set(range(n))
while mi:
v=mi.pop()
r=[c[v]]
while p[v]-1 in mi:
r.append(c[p[v]-1])
mi.discard(p[v]-1)
v=p[v]-1
root.append(r)
inf=float('inf')
ans=-inf
for r in root:
ansr=-inf
k1=k%len(r)
k0=k//len(r)
cr=[0]
tmp=0
for ri in r:
tmp+=ri
cr.append(tmp)
sumr=cr[-1]
for ri in r:
tmp+=ri
cr.append(tmp)
for i in range(len(r)):
for j in range(i,i+min(k,len(r))):
ansr=max(ansr,cr[j+1]-cr[i])
if sumr>0:
ans=max(ans,ansr+sumr*(k0-1))
else:
ans=max(ans,ansr)
if sumr>0:
ansr=0
for i in range(len(r)):
for j in range(i,i+k1):
ansr=max(ansr,cr[j+1]-cr[i])
ans=max(ans,ansr+sumr*k0)
print(ans)
| n,k=list(map(int,input().split()))
p=list(map(int,input().split()))
c=list(map(int,input().split()))
p=[x-1 for x in p]
mi=set(range(n))
g={}
# g[id]=[ary]
while mi:
x0=mi.pop()
ary=[c[x0]]
x=x0
while p[x]!=x0:
x=p[x]
mi.discard(x)
ary.append(c[x])
cnt=len(ary)
tmp=0
ary*=2
cary=[tmp]
for x in ary:
tmp+=x
cary.append(tmp)
g[x0]=[cnt,cary]
ans=-float('inf')
for cnt,cary in list(g.values()):
x,y=divmod(k,cnt)
tmp1=max(0,cary[cnt]*x)
tmp2=-float('inf')
for i in range(cnt):
for j in range(y):
tmp2=max(tmp2,cary[i+j+1]-cary[i])
ans=max(ans,tmp1+tmp2)
if x:
tmp1=max(0,cary[cnt]*(x-1))
tmp2=-float('inf')
for i in range(cnt):
for j in range(cnt):
tmp2=max(tmp2,cary[i+j+1]-cary[i])
ans=max(ans,tmp1+tmp2)
print(ans)
| 42 | 42 | 840 | 841 | n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
c = list(map(int, input().split()))
root = []
mi = set(range(n))
while mi:
v = mi.pop()
r = [c[v]]
while p[v] - 1 in mi:
r.append(c[p[v] - 1])
mi.discard(p[v] - 1)
v = p[v] - 1
root.append(r)
inf = float("inf")
ans = -inf
for r in root:
ansr = -inf
k1 = k % len(r)
k0 = k // len(r)
cr = [0]
tmp = 0
for ri in r:
tmp += ri
cr.append(tmp)
sumr = cr[-1]
for ri in r:
tmp += ri
cr.append(tmp)
for i in range(len(r)):
for j in range(i, i + min(k, len(r))):
ansr = max(ansr, cr[j + 1] - cr[i])
if sumr > 0:
ans = max(ans, ansr + sumr * (k0 - 1))
else:
ans = max(ans, ansr)
if sumr > 0:
ansr = 0
for i in range(len(r)):
for j in range(i, i + k1):
ansr = max(ansr, cr[j + 1] - cr[i])
ans = max(ans, ansr + sumr * k0)
print(ans)
| n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
c = list(map(int, input().split()))
p = [x - 1 for x in p]
mi = set(range(n))
g = {}
# g[id]=[ary]
while mi:
x0 = mi.pop()
ary = [c[x0]]
x = x0
while p[x] != x0:
x = p[x]
mi.discard(x)
ary.append(c[x])
cnt = len(ary)
tmp = 0
ary *= 2
cary = [tmp]
for x in ary:
tmp += x
cary.append(tmp)
g[x0] = [cnt, cary]
ans = -float("inf")
for cnt, cary in list(g.values()):
x, y = divmod(k, cnt)
tmp1 = max(0, cary[cnt] * x)
tmp2 = -float("inf")
for i in range(cnt):
for j in range(y):
tmp2 = max(tmp2, cary[i + j + 1] - cary[i])
ans = max(ans, tmp1 + tmp2)
if x:
tmp1 = max(0, cary[cnt] * (x - 1))
tmp2 = -float("inf")
for i in range(cnt):
for j in range(cnt):
tmp2 = max(tmp2, cary[i + j + 1] - cary[i])
ans = max(ans, tmp1 + tmp2)
print(ans)
| false | 0 | [
"-root = []",
"+p = [x - 1 for x in p]",
"+g = {}",
"+# g[id]=[ary]",
"- v = mi.pop()",
"- r = [c[v]]",
"- while p[v] - 1 in mi:",
"- r.append(c[p[v] - 1])",
"- mi.discard(p[v] - 1)",
"- v = p[v] - 1",
"- root.append(r)",
"-inf = float(\"inf\")",
"-ans = -inf",
"-for r in root:",
"- ansr = -inf",
"- k1 = k % len(r)",
"- k0 = k // len(r)",
"- cr = [0]",
"+ x0 = mi.pop()",
"+ ary = [c[x0]]",
"+ x = x0",
"+ while p[x] != x0:",
"+ x = p[x]",
"+ mi.discard(x)",
"+ ary.append(c[x])",
"+ cnt = len(ary)",
"- for ri in r:",
"- tmp += ri",
"- cr.append(tmp)",
"- sumr = cr[-1]",
"- for ri in r:",
"- tmp += ri",
"- cr.append(tmp)",
"- for i in range(len(r)):",
"- for j in range(i, i + min(k, len(r))):",
"- ansr = max(ansr, cr[j + 1] - cr[i])",
"- if sumr > 0:",
"- ans = max(ans, ansr + sumr * (k0 - 1))",
"- else:",
"- ans = max(ans, ansr)",
"- if sumr > 0:",
"- ansr = 0",
"- for i in range(len(r)):",
"- for j in range(i, i + k1):",
"- ansr = max(ansr, cr[j + 1] - cr[i])",
"- ans = max(ans, ansr + sumr * k0)",
"+ ary *= 2",
"+ cary = [tmp]",
"+ for x in ary:",
"+ tmp += x",
"+ cary.append(tmp)",
"+ g[x0] = [cnt, cary]",
"+ans = -float(\"inf\")",
"+for cnt, cary in list(g.values()):",
"+ x, y = divmod(k, cnt)",
"+ tmp1 = max(0, cary[cnt] * x)",
"+ tmp2 = -float(\"inf\")",
"+ for i in range(cnt):",
"+ for j in range(y):",
"+ tmp2 = max(tmp2, cary[i + j + 1] - cary[i])",
"+ ans = max(ans, tmp1 + tmp2)",
"+ if x:",
"+ tmp1 = max(0, cary[cnt] * (x - 1))",
"+ tmp2 = -float(\"inf\")",
"+ for i in range(cnt):",
"+ for j in range(cnt):",
"+ tmp2 = max(tmp2, cary[i + j + 1] - cary[i])",
"+ ans = max(ans, tmp1 + tmp2)"
] | false | 0.070658 | 0.047568 | 1.485403 | [
"s461318973",
"s404731510"
] |
u600402037 | p03074 | python | s268398298 | s990550280 | 1,880 | 424 | 16,760 | 14,136 | Accepted | Accepted | 77.45 | import numpy as np
N, K = list(map(int, input().split()))
S = np.array([int(x) for x in eval(input())] + [2])
blocks = [] # 同じ数の塊
seq = 1
for i in range(N):
if S[i+1] == S[i]:
seq += 1
else:
blocks.append(seq)
seq = 1
blocks = np.array(blocks)
answer = blocks[:2*K].sum()
start = 0 if S[0] == 1 else 1
for i in range(start, len(blocks), 2):
answer = max(answer, blocks[i:i+(2*K+1)].sum())
print(answer) | import numpy as np
N, K = list(map(int, input().split()))
S = [int(x) for x in eval(input())]
cur = 1 # 最初は1が0人立っている
blocks = np.zeros(10**5+1, dtype = np.int64)
seq = 0
p = 0
for s in S:
if s == cur:
blocks[p] += 1
else:
p += 1
blocks[p] += 1
cur = 1 - cur
W = min(2*K, 10**5)
answer = sum = blocks[:W+1].sum()
for i in range(W+1, 10**5, 2):
if i+1 > 10 ** 5:
break
sum = sum + blocks[i] + blocks[i+1] - blocks[i-W-1] - blocks[i-W]
if sum > answer:
answer = sum
print(answer) | 22 | 25 | 452 | 566 | import numpy as np
N, K = list(map(int, input().split()))
S = np.array([int(x) for x in eval(input())] + [2])
blocks = [] # 同じ数の塊
seq = 1
for i in range(N):
if S[i + 1] == S[i]:
seq += 1
else:
blocks.append(seq)
seq = 1
blocks = np.array(blocks)
answer = blocks[: 2 * K].sum()
start = 0 if S[0] == 1 else 1
for i in range(start, len(blocks), 2):
answer = max(answer, blocks[i : i + (2 * K + 1)].sum())
print(answer)
| import numpy as np
N, K = list(map(int, input().split()))
S = [int(x) for x in eval(input())]
cur = 1 # 最初は1が0人立っている
blocks = np.zeros(10**5 + 1, dtype=np.int64)
seq = 0
p = 0
for s in S:
if s == cur:
blocks[p] += 1
else:
p += 1
blocks[p] += 1
cur = 1 - cur
W = min(2 * K, 10**5)
answer = sum = blocks[: W + 1].sum()
for i in range(W + 1, 10**5, 2):
if i + 1 > 10**5:
break
sum = sum + blocks[i] + blocks[i + 1] - blocks[i - W - 1] - blocks[i - W]
if sum > answer:
answer = sum
print(answer)
| false | 12 | [
"-S = np.array([int(x) for x in eval(input())] + [2])",
"-blocks = [] # 同じ数の塊",
"-seq = 1",
"-for i in range(N):",
"- if S[i + 1] == S[i]:",
"- seq += 1",
"+S = [int(x) for x in eval(input())]",
"+cur = 1 # 最初は1が0人立っている",
"+blocks = np.zeros(10**5 + 1, dtype=np.int64)",
"+seq = 0",
"+p = 0",
"+for s in S:",
"+ if s == cur:",
"+ blocks[p] += 1",
"- blocks.append(seq)",
"- seq = 1",
"-blocks = np.array(blocks)",
"-answer = blocks[: 2 * K].sum()",
"-start = 0 if S[0] == 1 else 1",
"-for i in range(start, len(blocks), 2):",
"- answer = max(answer, blocks[i : i + (2 * K + 1)].sum())",
"+ p += 1",
"+ blocks[p] += 1",
"+ cur = 1 - cur",
"+W = min(2 * K, 10**5)",
"+answer = sum = blocks[: W + 1].sum()",
"+for i in range(W + 1, 10**5, 2):",
"+ if i + 1 > 10**5:",
"+ break",
"+ sum = sum + blocks[i] + blocks[i + 1] - blocks[i - W - 1] - blocks[i - W]",
"+ if sum > answer:",
"+ answer = sum"
] | false | 0.179907 | 0.17702 | 1.016308 | [
"s268398298",
"s990550280"
] |
u156383602 | p02729 | python | s370195273 | s693115311 | 19 | 17 | 3,444 | 2,940 | Accepted | Accepted | 10.53 | a,b=list(map(int,input().split()))
import itertools
a1 = len(list(itertools.combinations(list(range(a)), 2)))
b1 = len(list(itertools.combinations(list(range(b)), 2)))
print((a1+b1)) | a,b=list(map(int,input().split()))
print((a*(a-1)//2+b*(b-1)//2)) | 5 | 2 | 166 | 58 | a, b = list(map(int, input().split()))
import itertools
a1 = len(list(itertools.combinations(list(range(a)), 2)))
b1 = len(list(itertools.combinations(list(range(b)), 2)))
print((a1 + b1))
| a, b = list(map(int, input().split()))
print((a * (a - 1) // 2 + b * (b - 1) // 2))
| false | 60 | [
"-import itertools",
"-",
"-a1 = len(list(itertools.combinations(list(range(a)), 2)))",
"-b1 = len(list(itertools.combinations(list(range(b)), 2)))",
"-print((a1 + b1))",
"+print((a * (a - 1) // 2 + b * (b - 1) // 2))"
] | false | 0.037231 | 0.061498 | 0.605392 | [
"s370195273",
"s693115311"
] |
u363768711 | p03556 | python | s955712666 | s167367886 | 67 | 17 | 3,444 | 3,060 | Accepted | Accepted | 74.63 | N = int(eval(input()))
if N < 4:
print((1))
exit()
for i in range(N,1,-1):
if i**0.5 == int(i**0.5):
print(i)
exit() | N = int(eval(input()))
print((int(N**0.5)**2)) | 8 | 2 | 129 | 39 | N = int(eval(input()))
if N < 4:
print((1))
exit()
for i in range(N, 1, -1):
if i**0.5 == int(i**0.5):
print(i)
exit()
| N = int(eval(input()))
print((int(N**0.5) ** 2))
| false | 75 | [
"-if N < 4:",
"- print((1))",
"- exit()",
"-for i in range(N, 1, -1):",
"- if i**0.5 == int(i**0.5):",
"- print(i)",
"- exit()",
"+print((int(N**0.5) ** 2))"
] | false | 0.076849 | 0.037887 | 2.028383 | [
"s955712666",
"s167367886"
] |
u796942881 | p03111 | python | s648989770 | s503219812 | 71 | 21 | 3,064 | 3,064 | Accepted | Accepted | 70.42 | N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]
def dfs(cur, a, b, c):
if cur == N:
return abs(a - A) + abs(b - B) + abs(c - C) - 30\
if 0 < min(a, b, c) else int(1e9+7)
ret1 = dfs(cur + 1, a + L[cur], b, c) + 10
ret2 = dfs(cur + 1, a, b + L[cur], c) + 10
ret3 = dfs(cur + 1, a, b, c + L[cur]) + 10
ret4 = dfs(cur + 1, a, b, c)
return min(ret1, ret2, ret3, ret4)
def main():
print(dfs(0, 0, 0, 0))
main()
| from itertools import combinations
from itertools import permutations
def f(x, lst, rem):
d = abs(x - min(lst))
min_lst = min(lst)
tpl = None
for v in range(len(lst) - rem + 1):
for t in combinations(lst, v + 1):
if abs(x - sum(t)) + 10 * v < d:
d = abs(x - sum(t)) + 10 * v
tpl = t
if tpl is None:
lst.remove(min_lst)
else:
for v in tpl:
lst.remove(v)
return d, lst
def main():
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for i in range(N)]
ans = int(1e9+7)
for ABC in permutations((A, B, C), 3):
lst = L[:]
accum = 0
for i, v in enumerate(ABC):
d, lst = f(v, lst, 3 - i)
accum += d
ans = min(ans, accum)
print(ans)
main()
| 22 | 37 | 510 | 864 | N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]
def dfs(cur, a, b, c):
if cur == N:
return (
abs(a - A) + abs(b - B) + abs(c - C) - 30
if 0 < min(a, b, c)
else int(1e9 + 7)
)
ret1 = dfs(cur + 1, a + L[cur], b, c) + 10
ret2 = dfs(cur + 1, a, b + L[cur], c) + 10
ret3 = dfs(cur + 1, a, b, c + L[cur]) + 10
ret4 = dfs(cur + 1, a, b, c)
return min(ret1, ret2, ret3, ret4)
def main():
print(dfs(0, 0, 0, 0))
main()
| from itertools import combinations
from itertools import permutations
def f(x, lst, rem):
d = abs(x - min(lst))
min_lst = min(lst)
tpl = None
for v in range(len(lst) - rem + 1):
for t in combinations(lst, v + 1):
if abs(x - sum(t)) + 10 * v < d:
d = abs(x - sum(t)) + 10 * v
tpl = t
if tpl is None:
lst.remove(min_lst)
else:
for v in tpl:
lst.remove(v)
return d, lst
def main():
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for i in range(N)]
ans = int(1e9 + 7)
for ABC in permutations((A, B, C), 3):
lst = L[:]
accum = 0
for i, v in enumerate(ABC):
d, lst = f(v, lst, 3 - i)
accum += d
ans = min(ans, accum)
print(ans)
main()
| false | 40.540541 | [
"-N, A, B, C = map(int, input().split())",
"-L = [int(input()) for i in range(N)]",
"+from itertools import combinations",
"+from itertools import permutations",
"-def dfs(cur, a, b, c):",
"- if cur == N:",
"- return (",
"- abs(a - A) + abs(b - B) + abs(c - C) - 30",
"- if 0 < min(a, b, c)",
"- else int(1e9 + 7)",
"- )",
"- ret1 = dfs(cur + 1, a + L[cur], b, c) + 10",
"- ret2 = dfs(cur + 1, a, b + L[cur], c) + 10",
"- ret3 = dfs(cur + 1, a, b, c + L[cur]) + 10",
"- ret4 = dfs(cur + 1, a, b, c)",
"- return min(ret1, ret2, ret3, ret4)",
"+def f(x, lst, rem):",
"+ d = abs(x - min(lst))",
"+ min_lst = min(lst)",
"+ tpl = None",
"+ for v in range(len(lst) - rem + 1):",
"+ for t in combinations(lst, v + 1):",
"+ if abs(x - sum(t)) + 10 * v < d:",
"+ d = abs(x - sum(t)) + 10 * v",
"+ tpl = t",
"+ if tpl is None:",
"+ lst.remove(min_lst)",
"+ else:",
"+ for v in tpl:",
"+ lst.remove(v)",
"+ return d, lst",
"- print(dfs(0, 0, 0, 0))",
"+ N, A, B, C = list(map(int, input().split()))",
"+ L = [int(eval(input())) for i in range(N)]",
"+ ans = int(1e9 + 7)",
"+ for ABC in permutations((A, B, C), 3):",
"+ lst = L[:]",
"+ accum = 0",
"+ for i, v in enumerate(ABC):",
"+ d, lst = f(v, lst, 3 - i)",
"+ accum += d",
"+ ans = min(ans, accum)",
"+ print(ans)"
] | false | 0.087752 | 0.090703 | 0.967468 | [
"s648989770",
"s503219812"
] |
u325282913 | p03244 | python | s113382747 | s760430447 | 176 | 120 | 20,572 | 23,764 | Accepted | Accepted | 31.82 | from collections import Counter
n = int(eval(input()))
array = list(map(int,input().split()))
if len(set(array)) == 1:
print((n//2))
exit()
gu = []
ki = []
for i in range(n):
if i % 2 == 0:
gu.append(array[i])
else:
ki.append(array[i])
gu_c = Counter(gu)
ki_c = Counter(ki)
if gu_c.most_common()[0][0] != ki_c.most_common()[0][0]:
print((n-(gu_c.most_common()[0][1]+ki_c.most_common()[0][1])))
elif gu_c.most_common()[0][1] < ki_c.most_common()[0][1]:
print((n-(gu_c.most_common()[1][1]+ki_c.most_common()[0][1])))
elif gu_c.most_common()[0][1] > ki_c.most_common()[0][1]:
print((n-(gu_c.most_common()[0][1]+ki_c.most_common()[1][1])))
else:
print((n-(gu_c.most_common()[0][1]+max(gu_c.most_common()[1][1],ki_c.most_common()[1][1])))) | from collections import Counter
n = int(eval(input()))
array = list(map(int,input().split()))
if len(set(array)) == 1:
print((n//2))
exit()
gu = []
ki = []
for i in range(n):
if i % 2 == 0:
gu.append(array[i])
else:
ki.append(array[i])
gu_c = Counter(gu)
ki_c = Counter(ki)
gu_m = gu_c.most_common()
ki_m = ki_c.most_common()
if gu_m[0][0] != ki_m[0][0]:
print((n-(gu_m[0][1]+ki_m[0][1])))
elif gu_m[0][1] < ki_m[0][1]:
print((n-(gu_m[1][1]+ki_m[0][1])))
elif gu_m[0][1] > ki_m[0][1]:
print((n-(gu_m[0][1]+ki_m[1][1])))
else:
print((n-(gu_m[0][1]+max(gu_m[1][1],ki_m[1][1])))) | 23 | 25 | 788 | 632 | from collections import Counter
n = int(eval(input()))
array = list(map(int, input().split()))
if len(set(array)) == 1:
print((n // 2))
exit()
gu = []
ki = []
for i in range(n):
if i % 2 == 0:
gu.append(array[i])
else:
ki.append(array[i])
gu_c = Counter(gu)
ki_c = Counter(ki)
if gu_c.most_common()[0][0] != ki_c.most_common()[0][0]:
print((n - (gu_c.most_common()[0][1] + ki_c.most_common()[0][1])))
elif gu_c.most_common()[0][1] < ki_c.most_common()[0][1]:
print((n - (gu_c.most_common()[1][1] + ki_c.most_common()[0][1])))
elif gu_c.most_common()[0][1] > ki_c.most_common()[0][1]:
print((n - (gu_c.most_common()[0][1] + ki_c.most_common()[1][1])))
else:
print(
(
n
- (
gu_c.most_common()[0][1]
+ max(gu_c.most_common()[1][1], ki_c.most_common()[1][1])
)
)
)
| from collections import Counter
n = int(eval(input()))
array = list(map(int, input().split()))
if len(set(array)) == 1:
print((n // 2))
exit()
gu = []
ki = []
for i in range(n):
if i % 2 == 0:
gu.append(array[i])
else:
ki.append(array[i])
gu_c = Counter(gu)
ki_c = Counter(ki)
gu_m = gu_c.most_common()
ki_m = ki_c.most_common()
if gu_m[0][0] != ki_m[0][0]:
print((n - (gu_m[0][1] + ki_m[0][1])))
elif gu_m[0][1] < ki_m[0][1]:
print((n - (gu_m[1][1] + ki_m[0][1])))
elif gu_m[0][1] > ki_m[0][1]:
print((n - (gu_m[0][1] + ki_m[1][1])))
else:
print((n - (gu_m[0][1] + max(gu_m[1][1], ki_m[1][1]))))
| false | 8 | [
"-if gu_c.most_common()[0][0] != ki_c.most_common()[0][0]:",
"- print((n - (gu_c.most_common()[0][1] + ki_c.most_common()[0][1])))",
"-elif gu_c.most_common()[0][1] < ki_c.most_common()[0][1]:",
"- print((n - (gu_c.most_common()[1][1] + ki_c.most_common()[0][1])))",
"-elif gu_c.most_common()[0][1] > ki_c.most_common()[0][1]:",
"- print((n - (gu_c.most_common()[0][1] + ki_c.most_common()[1][1])))",
"+gu_m = gu_c.most_common()",
"+ki_m = ki_c.most_common()",
"+if gu_m[0][0] != ki_m[0][0]:",
"+ print((n - (gu_m[0][1] + ki_m[0][1])))",
"+elif gu_m[0][1] < ki_m[0][1]:",
"+ print((n - (gu_m[1][1] + ki_m[0][1])))",
"+elif gu_m[0][1] > ki_m[0][1]:",
"+ print((n - (gu_m[0][1] + ki_m[1][1])))",
"- print(",
"- (",
"- n",
"- - (",
"- gu_c.most_common()[0][1]",
"- + max(gu_c.most_common()[1][1], ki_c.most_common()[1][1])",
"- )",
"- )",
"- )",
"+ print((n - (gu_m[0][1] + max(gu_m[1][1], ki_m[1][1]))))"
] | false | 0.035047 | 0.031972 | 1.096194 | [
"s113382747",
"s760430447"
] |
u392319141 | p03017 | python | s781816991 | s214942340 | 20 | 18 | 3,700 | 3,636 | Accepted | Accepted | 10 | N, A, B, C, D = list(map(int, input().split()))
S = '$' + eval(input()) + '$'
def isOk(fr, to):
if S[fr: to + 1].count('##') > 0:
return False
return True
if not (isOk(A, C) and isOk(C, D)):
print('No')
exit()
def canSwitch():
if A + 1 == B and D < C and S[A: A + 3] == '...':
return True
if B + 1 == A and C < D and S[B: B + 3] == '...':
return True
if C + 1 == D and B < A and S[C - 1: D + 1] == '...':
return True
if D + 1 == C and A < B and S[D - 1: C + 1] == '...':
return True
if A < B and S[B - 1: B + 2] == '...':
return True
if B < A and S[A - 1: A + 2] == '...':
return True
if C < D and S[C - 1: C + 2] == '...':
return True
if D < C and S[D - 1: D + 2] == '...':
return True
if S[max(A, B): min(C, D) + 1].count('...'):
return True
return False
if A < B and D < C or B < A and C < D:
if not canSwitch():
print('No')
exit()
print('Yes')
| N, A, B, C, D = list(map(int, input().split()))
S = '$' + eval(input()) + '$'
def isOk(fr, to):
if S[fr: to + 1].count('##') > 0:
return False
return True
if not (isOk(A, C) and isOk(C, D)):
print('No')
exit()
def canSwitch():
if S[max(A, B) - 1: min(C, D) + 2].count('...'):
return True
return False
if A < B and D < C or B < A and C < D:
if not canSwitch():
print('No')
exit()
print('Yes')
| 39 | 23 | 1,035 | 467 | N, A, B, C, D = list(map(int, input().split()))
S = "$" + eval(input()) + "$"
def isOk(fr, to):
if S[fr : to + 1].count("##") > 0:
return False
return True
if not (isOk(A, C) and isOk(C, D)):
print("No")
exit()
def canSwitch():
if A + 1 == B and D < C and S[A : A + 3] == "...":
return True
if B + 1 == A and C < D and S[B : B + 3] == "...":
return True
if C + 1 == D and B < A and S[C - 1 : D + 1] == "...":
return True
if D + 1 == C and A < B and S[D - 1 : C + 1] == "...":
return True
if A < B and S[B - 1 : B + 2] == "...":
return True
if B < A and S[A - 1 : A + 2] == "...":
return True
if C < D and S[C - 1 : C + 2] == "...":
return True
if D < C and S[D - 1 : D + 2] == "...":
return True
if S[max(A, B) : min(C, D) + 1].count("..."):
return True
return False
if A < B and D < C or B < A and C < D:
if not canSwitch():
print("No")
exit()
print("Yes")
| N, A, B, C, D = list(map(int, input().split()))
S = "$" + eval(input()) + "$"
def isOk(fr, to):
if S[fr : to + 1].count("##") > 0:
return False
return True
if not (isOk(A, C) and isOk(C, D)):
print("No")
exit()
def canSwitch():
if S[max(A, B) - 1 : min(C, D) + 2].count("..."):
return True
return False
if A < B and D < C or B < A and C < D:
if not canSwitch():
print("No")
exit()
print("Yes")
| false | 41.025641 | [
"- if A + 1 == B and D < C and S[A : A + 3] == \"...\":",
"- return True",
"- if B + 1 == A and C < D and S[B : B + 3] == \"...\":",
"- return True",
"- if C + 1 == D and B < A and S[C - 1 : D + 1] == \"...\":",
"- return True",
"- if D + 1 == C and A < B and S[D - 1 : C + 1] == \"...\":",
"- return True",
"- if A < B and S[B - 1 : B + 2] == \"...\":",
"- return True",
"- if B < A and S[A - 1 : A + 2] == \"...\":",
"- return True",
"- if C < D and S[C - 1 : C + 2] == \"...\":",
"- return True",
"- if D < C and S[D - 1 : D + 2] == \"...\":",
"- return True",
"- if S[max(A, B) : min(C, D) + 1].count(\"...\"):",
"+ if S[max(A, B) - 1 : min(C, D) + 2].count(\"...\"):"
] | false | 0.047867 | 0.081946 | 0.58413 | [
"s781816991",
"s214942340"
] |
u263830634 | p03221 | python | s708565915 | s519817516 | 1,158 | 1,008 | 42,528 | 38,520 | Accepted | Accepted | 12.95 | N, M = list(map(int, input().split()))
lst = []
for i in range(M):
a = list(map(int, input().split()))
a += [i] #i: 市の番号
lst += [a]
#print (lst)
lst.sort()
#print (lst)
ken = -1
x = 0
ans = []
for j in range(M):
if ken != lst[j][0]: #1つ前と市の名前が違う
x = 1 #
ken = lst[j][0]
# P = '{:0>6}'.format(ken)
#print ('A')
else: #1つ前と市の名前が同じ
x += 1
#print ('B')
# X = '{:0>6}'.format(x)
ans += [[lst[j][2], ken, x]]
ans.sort()
#print (ans)
for k in range(M):
P = '{:0>6}'.format(ans[k][1])
X = '{:0>6}'.format(ans[k][2])
print((P+X)) | N, M = map(int, input().split())
PY = [list(map(int, input().split())) + [i] for i in range(M)]
PY.sort(key = lambda x: x[1])
PY.sort(key = lambda x: x[0])
ans_lst = []
x = 1
tmp_p = None
for p, y, i in PY:
if p == tmp_p: #属している県が同じ時
ans_lst.append([p, x, i])
x += 1
else:
ans_lst.append([p, 1, i])
tmp_p = p
x = 2
ans_lst.sort(key = lambda x: x[2])
#output
for p, x, i in ans_lst:
ans_p = str('000000') + str(p)
ans_x = str('000000') + str(x)
# print (ans_p, ans_x)
# print (ans_p[-6:])
print (ans_p[-6:], ans_x[-6:], sep = '')
| 32 | 27 | 633 | 627 | N, M = list(map(int, input().split()))
lst = []
for i in range(M):
a = list(map(int, input().split()))
a += [i] # i: 市の番号
lst += [a]
# print (lst)
lst.sort()
# print (lst)
ken = -1
x = 0
ans = []
for j in range(M):
if ken != lst[j][0]: # 1つ前と市の名前が違う
x = 1 #
ken = lst[j][0]
# P = '{:0>6}'.format(ken)
# print ('A')
else: # 1つ前と市の名前が同じ
x += 1
# print ('B')
# X = '{:0>6}'.format(x)
ans += [[lst[j][2], ken, x]]
ans.sort()
# print (ans)
for k in range(M):
P = "{:0>6}".format(ans[k][1])
X = "{:0>6}".format(ans[k][2])
print((P + X))
| N, M = map(int, input().split())
PY = [list(map(int, input().split())) + [i] for i in range(M)]
PY.sort(key=lambda x: x[1])
PY.sort(key=lambda x: x[0])
ans_lst = []
x = 1
tmp_p = None
for p, y, i in PY:
if p == tmp_p: # 属している県が同じ時
ans_lst.append([p, x, i])
x += 1
else:
ans_lst.append([p, 1, i])
tmp_p = p
x = 2
ans_lst.sort(key=lambda x: x[2])
# output
for p, x, i in ans_lst:
ans_p = str("000000") + str(p)
ans_x = str("000000") + str(x)
# print (ans_p, ans_x)
# print (ans_p[-6:])
print(ans_p[-6:], ans_x[-6:], sep="")
| false | 15.625 | [
"-N, M = list(map(int, input().split()))",
"-lst = []",
"-for i in range(M):",
"- a = list(map(int, input().split()))",
"- a += [i] # i: 市の番号",
"- lst += [a]",
"-# print (lst)",
"-lst.sort()",
"-# print (lst)",
"-ken = -1",
"-x = 0",
"-ans = []",
"-for j in range(M):",
"- if ken != lst[j][0]: # 1つ前と市の名前が違う",
"- x = 1 #",
"- ken = lst[j][0]",
"- # P = '{:0>6}'.format(ken)",
"- # print ('A')",
"- else: # 1つ前と市の名前が同じ",
"+N, M = map(int, input().split())",
"+PY = [list(map(int, input().split())) + [i] for i in range(M)]",
"+PY.sort(key=lambda x: x[1])",
"+PY.sort(key=lambda x: x[0])",
"+ans_lst = []",
"+x = 1",
"+tmp_p = None",
"+for p, y, i in PY:",
"+ if p == tmp_p: # 属している県が同じ時",
"+ ans_lst.append([p, x, i])",
"- # print ('B')",
"- # X = '{:0>6}'.format(x)",
"- ans += [[lst[j][2], ken, x]]",
"-ans.sort()",
"-# print (ans)",
"-for k in range(M):",
"- P = \"{:0>6}\".format(ans[k][1])",
"- X = \"{:0>6}\".format(ans[k][2])",
"- print((P + X))",
"+ else:",
"+ ans_lst.append([p, 1, i])",
"+ tmp_p = p",
"+ x = 2",
"+ans_lst.sort(key=lambda x: x[2])",
"+# output",
"+for p, x, i in ans_lst:",
"+ ans_p = str(\"000000\") + str(p)",
"+ ans_x = str(\"000000\") + str(x)",
"+ # print (ans_p, ans_x)",
"+ # print (ans_p[-6:])",
"+ print(ans_p[-6:], ans_x[-6:], sep=\"\")"
] | false | 0.039522 | 0.080658 | 0.490001 | [
"s708565915",
"s519817516"
] |
u912237403 | p00170 | python | s550547916 | s264094851 | 4,620 | 290 | 100,444 | 4,288 | Accepted | Accepted | 93.72 | def solve(placed, w1, w2):
n = len(N) - len(placed)
x = list(set(N) - set(placed))
if x == []:
a = tuple(placed)
D1[a] = w1
D2[a] = w2
return
for e in x:
w = Food[e][0]
if w2 > Food[e][1]: return
a = w1 + w * n
b = w2 + w
solve(placed+[e], a, b)
return
while 1:
n = eval(input())
if n==0: break
D1 = {}
D2 = {}
Name = {}
Food = {}
N = list(range(n))
for i in N:
a = input().split()
Food[i] = list(map(int, a[1:]))
Name[i] = a[0]
solve([], 0, 0)
Index, e = sorted(list(D1.items()), key = lambda x: x[1])[0]
for e in list(Index)[::-1]:
print(Name[e]) | def solve(placed, w1, w2):
global weight, D
n = len(N) - len(placed)
x = list(set(N) - set(placed))
if x == []:
if weight > w1:
D = placed
weight = w1
return
for e in x:
w = Food[0][e]
if w2 > Food[1][e]: return
a = w1 + w * n
if a > weight: return
b = w2 + w
solve(placed+[e], a, b)
return
while 1:
n = eval(input())
if n==0: break
Food = {}
weight = 1e9
N = list(range(n))
x = []
for i in N:
a = input().split()
x.append(list(map(int, a[1:]))+[a[0]])
Food = list(zip(*sorted(x)))
solve([], 0, 0)
for e in D[::-1]:
print(Food[2][e]) | 35 | 33 | 657 | 638 | def solve(placed, w1, w2):
n = len(N) - len(placed)
x = list(set(N) - set(placed))
if x == []:
a = tuple(placed)
D1[a] = w1
D2[a] = w2
return
for e in x:
w = Food[e][0]
if w2 > Food[e][1]:
return
a = w1 + w * n
b = w2 + w
solve(placed + [e], a, b)
return
while 1:
n = eval(input())
if n == 0:
break
D1 = {}
D2 = {}
Name = {}
Food = {}
N = list(range(n))
for i in N:
a = input().split()
Food[i] = list(map(int, a[1:]))
Name[i] = a[0]
solve([], 0, 0)
Index, e = sorted(list(D1.items()), key=lambda x: x[1])[0]
for e in list(Index)[::-1]:
print(Name[e])
| def solve(placed, w1, w2):
global weight, D
n = len(N) - len(placed)
x = list(set(N) - set(placed))
if x == []:
if weight > w1:
D = placed
weight = w1
return
for e in x:
w = Food[0][e]
if w2 > Food[1][e]:
return
a = w1 + w * n
if a > weight:
return
b = w2 + w
solve(placed + [e], a, b)
return
while 1:
n = eval(input())
if n == 0:
break
Food = {}
weight = 1e9
N = list(range(n))
x = []
for i in N:
a = input().split()
x.append(list(map(int, a[1:])) + [a[0]])
Food = list(zip(*sorted(x)))
solve([], 0, 0)
for e in D[::-1]:
print(Food[2][e])
| false | 5.714286 | [
"+ global weight, D",
"- a = tuple(placed)",
"- D1[a] = w1",
"- D2[a] = w2",
"+ if weight > w1:",
"+ D = placed",
"+ weight = w1",
"- w = Food[e][0]",
"- if w2 > Food[e][1]:",
"+ w = Food[0][e]",
"+ if w2 > Food[1][e]:",
"+ if a > weight:",
"+ return",
"- D1 = {}",
"- D2 = {}",
"- Name = {}",
"+ weight = 1e9",
"+ x = []",
"- Food[i] = list(map(int, a[1:]))",
"- Name[i] = a[0]",
"+ x.append(list(map(int, a[1:])) + [a[0]])",
"+ Food = list(zip(*sorted(x)))",
"- Index, e = sorted(list(D1.items()), key=lambda x: x[1])[0]",
"- for e in list(Index)[::-1]:",
"- print(Name[e])",
"+ for e in D[::-1]:",
"+ print(Food[2][e])"
] | false | 0.042946 | 0.041431 | 1.036583 | [
"s550547916",
"s264094851"
] |
u214617707 | p03814 | python | s580940025 | s647777787 | 60 | 35 | 3,516 | 3,512 | Accepted | Accepted | 41.67 | s = eval(input())
i = 0
while i < len(s) and s[i] != "A":
i += 1
j = len(s) - 1
while j > 0 and s[j] != "Z":
j -= 1
print((j - i + 1)) | S = eval(input())
N = len(S)
s, t = 0, 0
for i in range(N):
if S[i] == "A":
s = i
break
for i in range(N - 1, -1, -1):
if S[i] == "Z":
t = i
break
print((t - s + 1)) | 10 | 14 | 145 | 212 | s = eval(input())
i = 0
while i < len(s) and s[i] != "A":
i += 1
j = len(s) - 1
while j > 0 and s[j] != "Z":
j -= 1
print((j - i + 1))
| S = eval(input())
N = len(S)
s, t = 0, 0
for i in range(N):
if S[i] == "A":
s = i
break
for i in range(N - 1, -1, -1):
if S[i] == "Z":
t = i
break
print((t - s + 1))
| false | 28.571429 | [
"-s = eval(input())",
"-i = 0",
"-while i < len(s) and s[i] != \"A\":",
"- i += 1",
"-j = len(s) - 1",
"-while j > 0 and s[j] != \"Z\":",
"- j -= 1",
"-print((j - i + 1))",
"+S = eval(input())",
"+N = len(S)",
"+s, t = 0, 0",
"+for i in range(N):",
"+ if S[i] == \"A\":",
"+ s = i",
"+ break",
"+for i in range(N - 1, -1, -1):",
"+ if S[i] == \"Z\":",
"+ t = i",
"+ break",
"+print((t - s + 1))"
] | false | 0.008557 | 0.041886 | 0.204291 | [
"s580940025",
"s647777787"
] |
u716530146 | p02898 | python | s137688523 | s605111448 | 215 | 53 | 55,152 | 12,308 | Accepted | Accepted | 75.35 | #!/usr/bin/env python3
import sys, math
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0
n,k=list(map(int,input().split()))
h=list(map(int,input().split()))
for hi in h:
if hi>=k:
count+=1
print(count) | #!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0
n,k=list(map(int,input().split()))
h=list(map(int,input().split()))
for hi in h:
if hi>=k:
ans+=1
print(ans) | 14 | 13 | 302 | 339 | #!/usr/bin/env python3
import sys, math
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
sys.setrecursionlimit(10**8)
inf = float("inf")
ans = count = 0
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
for hi in h:
if hi >= k:
count += 1
print(count)
| #!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
sys.setrecursionlimit(10**8)
inf = float("inf")
ans = count = 0
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
for hi in h:
if hi >= k:
ans += 1
print(ans)
| false | 7.142857 | [
"-import sys, math",
"+import sys, math, itertools, heapq, collections, bisect",
"- count += 1",
"-print(count)",
"+ ans += 1",
"+print(ans)"
] | false | 0.058903 | 0.076659 | 0.768377 | [
"s137688523",
"s605111448"
] |
u543954314 | p03805 | python | s602724323 | s144603699 | 44 | 27 | 3,064 | 3,064 | Accepted | Accepted | 38.64 | n,m = list(map(int, input().split()))
arr = [[0]*n for _ in range(n)]
for _ in range(m):
a,b = list(map(int, input().split()))
arr[a-1][b-1] = 1
arr[b-1][a-1] = 1
d = [0]*n
d[0] = 1
cnt = 0
def dfs(x):
global cnt
if all(d):
cnt += 1
for i in range(1,n+1):
if arr[x-1][i-1] and d[i-1] == 0:
d[i-1] = 1
dfs(i)
d[i-1] = 0
dfs(1)
print(cnt) | n,m = list(map(int, input().split()))
arr = [list() for _ in range(n)]
for _ in range(m):
a,b = list(map(int, input().split()))
arr[a-1].append(b)
arr[b-1].append(a)
d = [0]*n
d[0] = 1
cnt = 0
def dfs(x):
global cnt
if all(d):
cnt += 1
return
for i in arr[x-1]:
if d[i-1] == 0:
d[i-1] = 1
dfs(i)
d[i-1] = 0
dfs(1)
print(cnt) | 20 | 21 | 381 | 374 | n, m = list(map(int, input().split()))
arr = [[0] * n for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
arr[a - 1][b - 1] = 1
arr[b - 1][a - 1] = 1
d = [0] * n
d[0] = 1
cnt = 0
def dfs(x):
global cnt
if all(d):
cnt += 1
for i in range(1, n + 1):
if arr[x - 1][i - 1] and d[i - 1] == 0:
d[i - 1] = 1
dfs(i)
d[i - 1] = 0
dfs(1)
print(cnt)
| n, m = list(map(int, input().split()))
arr = [list() for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
arr[a - 1].append(b)
arr[b - 1].append(a)
d = [0] * n
d[0] = 1
cnt = 0
def dfs(x):
global cnt
if all(d):
cnt += 1
return
for i in arr[x - 1]:
if d[i - 1] == 0:
d[i - 1] = 1
dfs(i)
d[i - 1] = 0
dfs(1)
print(cnt)
| false | 4.761905 | [
"-arr = [[0] * n for _ in range(n)]",
"+arr = [list() for _ in range(n)]",
"- arr[a - 1][b - 1] = 1",
"- arr[b - 1][a - 1] = 1",
"+ arr[a - 1].append(b)",
"+ arr[b - 1].append(a)",
"- for i in range(1, n + 1):",
"- if arr[x - 1][i - 1] and d[i - 1] == 0:",
"+ return",
"+ for i in arr[x - 1]:",
"+ if d[i - 1] == 0:"
] | false | 0.035346 | 0.04528 | 0.7806 | [
"s602724323",
"s144603699"
] |
u367130284 | p03106 | python | s268817166 | s949954463 | 38 | 18 | 5,304 | 2,940 | Accepted | Accepted | 52.63 | import fractions as f
a,b,k=list(map(int,input().split()))
g=f.gcd(a,b)
count=0
for s in range(g,0,-1):
if g%s==0:
count+=1
if count==k:
print(s)
exit() | a,b,k=list(map(int,input().split()))
l=[]
for i in range(min(a,b),0,-1):
if a%i==b%i==0:
l.append(i)
print((l[k-1])) | 10 | 6 | 188 | 125 | import fractions as f
a, b, k = list(map(int, input().split()))
g = f.gcd(a, b)
count = 0
for s in range(g, 0, -1):
if g % s == 0:
count += 1
if count == k:
print(s)
exit()
| a, b, k = list(map(int, input().split()))
l = []
for i in range(min(a, b), 0, -1):
if a % i == b % i == 0:
l.append(i)
print((l[k - 1]))
| false | 40 | [
"-import fractions as f",
"-",
"-g = f.gcd(a, b)",
"-count = 0",
"-for s in range(g, 0, -1):",
"- if g % s == 0:",
"- count += 1",
"- if count == k:",
"- print(s)",
"- exit()",
"+l = []",
"+for i in range(min(a, b), 0, -1):",
"+ if a % i == b % i == 0:",
"+ l.append(i)",
"+print((l[k - 1]))"
] | false | 0.053531 | 0.047181 | 1.134585 | [
"s268817166",
"s949954463"
] |
u170201762 | p03326 | python | s325677995 | s302344011 | 1,979 | 27 | 21,616 | 3,316 | Accepted | Accepted | 98.64 | import numpy as np
N,M = list(map(int,input().split()))
a = np.zeros((8,N))
for i in range(N):
x,y,z = list(map(int,input().split()))
j=0
for j1 in range(2):
for j2 in range(2):
for j3 in range(2):
a[j][i] = (-1)**j1*x+(-1)**j2*y+(-1)**j3*z
j += 1
ans = 0
for j in range(8):
ref = sum(sorted(a[j])[-M:])
ans = max(ans,ref)
if M == 0:
ans = 0
print((int(ans))) | N,M = list(map(int,input().split()))
xyz = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for n in range(8):
n = bin(n)[2:]
n = (3-len(n))*'0' + n
n = [1-2*int(s) for s in n]
S = [0]*N
for i in range(N):
S[i] = n[0]*xyz[i][0]+n[1]*xyz[i][1]+n[2]*xyz[i][2]
S.sort()
ans = max(ans,sum(S[N-M:]))
print(ans) | 18 | 15 | 438 | 361 | import numpy as np
N, M = list(map(int, input().split()))
a = np.zeros((8, N))
for i in range(N):
x, y, z = list(map(int, input().split()))
j = 0
for j1 in range(2):
for j2 in range(2):
for j3 in range(2):
a[j][i] = (-1) ** j1 * x + (-1) ** j2 * y + (-1) ** j3 * z
j += 1
ans = 0
for j in range(8):
ref = sum(sorted(a[j])[-M:])
ans = max(ans, ref)
if M == 0:
ans = 0
print((int(ans)))
| N, M = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for n in range(8):
n = bin(n)[2:]
n = (3 - len(n)) * "0" + n
n = [1 - 2 * int(s) for s in n]
S = [0] * N
for i in range(N):
S[i] = n[0] * xyz[i][0] + n[1] * xyz[i][1] + n[2] * xyz[i][2]
S.sort()
ans = max(ans, sum(S[N - M :]))
print(ans)
| false | 16.666667 | [
"-import numpy as np",
"-",
"-a = np.zeros((8, N))",
"-for i in range(N):",
"- x, y, z = list(map(int, input().split()))",
"- j = 0",
"- for j1 in range(2):",
"- for j2 in range(2):",
"- for j3 in range(2):",
"- a[j][i] = (-1) ** j1 * x + (-1) ** j2 * y + (-1) ** j3 * z",
"- j += 1",
"+xyz = [list(map(int, input().split())) for _ in range(N)]",
"-for j in range(8):",
"- ref = sum(sorted(a[j])[-M:])",
"- ans = max(ans, ref)",
"-if M == 0:",
"- ans = 0",
"-print((int(ans)))",
"+for n in range(8):",
"+ n = bin(n)[2:]",
"+ n = (3 - len(n)) * \"0\" + n",
"+ n = [1 - 2 * int(s) for s in n]",
"+ S = [0] * N",
"+ for i in range(N):",
"+ S[i] = n[0] * xyz[i][0] + n[1] * xyz[i][1] + n[2] * xyz[i][2]",
"+ S.sort()",
"+ ans = max(ans, sum(S[N - M :]))",
"+print(ans)"
] | false | 0.641674 | 0.045028 | 14.250669 | [
"s325677995",
"s302344011"
] |
u119148115 | p03047 | python | s522435664 | s689183915 | 71 | 63 | 61,952 | 61,336 | Accepted | Accepted | 11.27 | import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N,K = MI()
print((N-K+1))
| import sys
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,K = MI()
print((N-K+1))
| 14 | 6 | 517 | 106 | import sys
sys.setrecursionlimit(10**7)
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
def LI2():
return list(map(int, sys.stdin.readline().rstrip())) # 空白なし
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split()) # 空白あり
def LS2():
return list(sys.stdin.readline().rstrip()) # 空白なし
N, K = MI()
print((N - K + 1))
| import sys
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
N, K = MI()
print((N - K + 1))
| false | 57.142857 | [
"-",
"-sys.setrecursionlimit(10**7)",
"-",
"-",
"-def I():",
"- return int(sys.stdin.readline().rstrip())",
"-def LI():",
"- return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり",
"-",
"-",
"-def LI2():",
"- return list(map(int, sys.stdin.readline().rstrip())) # 空白なし",
"-",
"-",
"-def S():",
"- return sys.stdin.readline().rstrip()",
"-",
"-",
"-def LS():",
"- return list(sys.stdin.readline().rstrip().split()) # 空白あり",
"-",
"-",
"-def LS2():",
"- return list(sys.stdin.readline().rstrip()) # 空白なし",
"-",
"-"
] | false | 0.066728 | 0.033855 | 1.971002 | [
"s522435664",
"s689183915"
] |
u316386814 | p02998 | python | s363798557 | s865713702 | 539 | 491 | 102,488 | 114,524 | Accepted | Accepted | 8.91 | import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
from collections import defaultdict
def main():
N = II()
xy2g = defaultdict(int)
g2xy = defaultdict(set)
for _ in range(N):
x, y = LI()
y = -y
gx = xy2g[x]
gy = xy2g[y]
if gx != 0 and gy != 0: # merge
if gx == gy:
continue
if len(g2xy[gx]) < len(g2xy[gy]):
gx, gy = gy, gx
for xy in g2xy[gy]:
xy2g[xy] = gx
g2xy[gx] |= g2xy[gy]
g2xy[gy].clear()
else:
g = gx or gy or x
xy2g[x] = xy2g[y] = g
g2xy[g] |= {x, y}
ans = -N
for xys in list(g2xy.values()):
nx = sum(xy > 0 for xy in xys)
ny = len(xys) - nx
ans += nx * ny
return ans
print((main())) | import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
from collections import defaultdict
def main():
N = II()
xy = []
for _ in range(N):
xy.append(LI())
xy2g = defaultdict(int)
g2xy = defaultdict(set)
for x, y in xy:
y = -y
gx = xy2g[x]
gy = xy2g[y]
if gx != 0 and gy != 0: # merge
if gx == gy:
continue
if len(g2xy[gx]) < len(g2xy[gy]):
gx, gy = gy, gx
for xy in g2xy[gy]:
xy2g[xy] = gx
g2xy[gx] |= g2xy[gy]
g2xy[gy].clear()
else:
g = gx or gy or x
xy2g[x] = xy2g[y] = g
g2xy[g] |= {x, y}
ans = -N
for xys in list(g2xy.values()):
nx = sum(xy > 0 for xy in xys)
ny = len(xys) - nx
ans += nx * ny
return ans
print((main())) | 43 | 45 | 1,250 | 1,288 | import sys
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
def YesNo(x):
return "Yes" if x else "No"
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return eval(input())
from collections import defaultdict
def main():
N = II()
xy2g = defaultdict(int)
g2xy = defaultdict(set)
for _ in range(N):
x, y = LI()
y = -y
gx = xy2g[x]
gy = xy2g[y]
if gx != 0 and gy != 0: # merge
if gx == gy:
continue
if len(g2xy[gx]) < len(g2xy[gy]):
gx, gy = gy, gx
for xy in g2xy[gy]:
xy2g[xy] = gx
g2xy[gx] |= g2xy[gy]
g2xy[gy].clear()
else:
g = gx or gy or x
xy2g[x] = xy2g[y] = g
g2xy[g] |= {x, y}
ans = -N
for xys in list(g2xy.values()):
nx = sum(xy > 0 for xy in xys)
ny = len(xys) - nx
ans += nx * ny
return ans
print((main()))
| import sys
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
def YesNo(x):
return "Yes" if x else "No"
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return eval(input())
from collections import defaultdict
def main():
N = II()
xy = []
for _ in range(N):
xy.append(LI())
xy2g = defaultdict(int)
g2xy = defaultdict(set)
for x, y in xy:
y = -y
gx = xy2g[x]
gy = xy2g[y]
if gx != 0 and gy != 0: # merge
if gx == gy:
continue
if len(g2xy[gx]) < len(g2xy[gy]):
gx, gy = gy, gx
for xy in g2xy[gy]:
xy2g[xy] = gx
g2xy[gx] |= g2xy[gy]
g2xy[gy].clear()
else:
g = gx or gy or x
xy2g[x] = xy2g[y] = g
g2xy[g] |= {x, y}
ans = -N
for xys in list(g2xy.values()):
nx = sum(xy > 0 for xy in xys)
ny = len(xys) - nx
ans += nx * ny
return ans
print((main()))
| false | 4.444444 | [
"+ xy = []",
"+ for _ in range(N):",
"+ xy.append(LI())",
"- for _ in range(N):",
"- x, y = LI()",
"+ for x, y in xy:"
] | false | 0.040513 | 0.046217 | 0.876583 | [
"s363798557",
"s865713702"
] |
u397638621 | p02713 | python | s426337313 | s788708173 | 1,982 | 1,201 | 9,104 | 9,084 | Accepted | Accepted | 39.4 | k = int(eval(input()))
from math import gcd
ans = 0
for a in range(1, k+1):
for b in range(1, k+1):
for c in range(1, k+1):
ans += gcd(a, gcd(b, c))
print(ans) | k = int(eval(input()))
from math import gcd
ans = 0
for a in range(1, k+1):
for b in range(1, k+1):
ab = gcd(a, b)
for c in range(1, k+1):
ans += gcd(ab, c)
print(ans) | 9 | 10 | 186 | 206 | k = int(eval(input()))
from math import gcd
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
for c in range(1, k + 1):
ans += gcd(a, gcd(b, c))
print(ans)
| k = int(eval(input()))
from math import gcd
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
ab = gcd(a, b)
for c in range(1, k + 1):
ans += gcd(ab, c)
print(ans)
| false | 10 | [
"+ ab = gcd(a, b)",
"- ans += gcd(a, gcd(b, c))",
"+ ans += gcd(ab, c)"
] | false | 0.064646 | 0.062432 | 1.035457 | [
"s426337313",
"s788708173"
] |
u863370423 | p03323 | python | s729578498 | s921011465 | 17 | 10 | 2,940 | 2,568 | Accepted | Accepted | 41.18 | a, b = list(map(int, input().split()))
if a > 8 or b > 8:
print(':(')
else:
print('Yay!')
| parameters = list(map(int, input().split()))
if(parameters[0] <= 8 and parameters[1] <= 8):
print('Yay!')
else:
print(':(') | 6 | 6 | 98 | 135 | a, b = list(map(int, input().split()))
if a > 8 or b > 8:
print(":(")
else:
print("Yay!")
| parameters = list(map(int, input().split()))
if parameters[0] <= 8 and parameters[1] <= 8:
print("Yay!")
else:
print(":(")
| false | 0 | [
"-a, b = list(map(int, input().split()))",
"-if a > 8 or b > 8:",
"+parameters = list(map(int, input().split()))",
"+if parameters[0] <= 8 and parameters[1] <= 8:",
"+ print(\"Yay!\")",
"+else:",
"-else:",
"- print(\"Yay!\")"
] | false | 0.03627 | 0.035641 | 1.017628 | [
"s729578498",
"s921011465"
] |
u389910364 | p03325 | python | s957511860 | s011465485 | 338 | 86 | 23,660 | 3,956 | Accepted | Accepted | 74.56 | import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
ans = 0
for a in A:
while a % 2 == 0:
a //= 2
ans += 1
print(ans)
| import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))
ans = 0
for a in A:
while a % 2 == 0:
a //= 2
ans += 1
print(ans)
| 34 | 21 | 674 | 386 | import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
ans = 0
for a in A:
while a % 2 == 0:
a //= 2
ans += 1
print(ans)
| import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))
ans = 0
for a in A:
while a % 2 == 0:
a //= 2
ans += 1
print(ans)
| false | 38.235294 | [
"-import bisect",
"-import heapq",
"-import itertools",
"-import math",
"-import re",
"-import string",
"-from collections import Counter, deque, defaultdict",
"-from copy import deepcopy",
"-from decimal import Decimal",
"-from fractions import gcd",
"-from functools import lru_cache, reduce",
"-from operator import itemgetter",
"-import numpy as np",
"-sys.setrecursionlimit(2147483647)",
"+sys.setrecursionlimit(10**9)",
"-N = int(sys.stdin.readline())",
"-A = list(map(int, sys.stdin.readline().split()))",
"+# MOD = 998244353",
"+N = int(sys.stdin.buffer.readline())",
"+A = list(map(int, sys.stdin.buffer.readline().split()))"
] | false | 0.128397 | 0.069696 | 1.842253 | [
"s957511860",
"s011465485"
] |
u654470292 | p03053 | python | s622635849 | s506262034 | 602 | 445 | 140,892 | 87,004 | Accepted | Accepted | 26.08 | import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
h,w=list(map(int,input().split()))
a=[eval(input()) for i in range(h)]
cnt=0
itta=[[10**9]*w for i in range(h)]
d=deque()
# aaa=d.append
for i in range(h):
for j in range(w):
if a[i][j]=="#":
d.append([i,j])
itta[i][j]=0
# print(d)
# print(itta)
while d:
cnt+=1
for l in range(len(d)):
nh,nw=d.popleft()
for i in range(4):
d1,d2=direction[i]
if 0<=nh+d1<h and 0<=nw+d2<w:
if itta[nh+d1][nw+d2]==10**9:
itta[nh+d1][nw+d2]=cnt
d.append([nh+d1,nw+d2])
# print(d)
# print(itta)
print((cnt-1)) | import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
h,w=list(map(int,input().split()))
a=[eval(input()) for i in range(h)]
cnt=0
itta=[[10**9]*w for i in range(h)]
d=deque()
# aaa=d.append
for i in range(h):
for j in range(w):
if a[i][j]=="#":
d.append((i,j))
itta[i][j]=0
# print(d)
# print(itta)
while d:
cnt+=1
for l in range(len(d)):
nh,nw=d.popleft()
for i in range(4):
d1,d2=direction[i]
if 0<=nh+d1<h and 0<=nw+d2<w:
if itta[nh+d1][nw+d2]==10**9:
itta[nh+d1][nw+d2]=cnt
d.append((nh+d1,nw+d2))
# print(d)
# print(itta)
print((cnt-1)) | 48 | 48 | 1,054 | 1,054 | import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0] + list(accumulate(lst))
mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
h, w = list(map(int, input().split()))
a = [eval(input()) for i in range(h)]
cnt = 0
itta = [[10**9] * w for i in range(h)]
d = deque()
# aaa=d.append
for i in range(h):
for j in range(w):
if a[i][j] == "#":
d.append([i, j])
itta[i][j] = 0
# print(d)
# print(itta)
while d:
cnt += 1
for l in range(len(d)):
nh, nw = d.popleft()
for i in range(4):
d1, d2 = direction[i]
if 0 <= nh + d1 < h and 0 <= nw + d2 < w:
if itta[nh + d1][nw + d2] == 10**9:
itta[nh + d1][nw + d2] = cnt
d.append([nh + d1, nw + d2])
# print(d)
# print(itta)
print((cnt - 1))
| import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0] + list(accumulate(lst))
mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
h, w = list(map(int, input().split()))
a = [eval(input()) for i in range(h)]
cnt = 0
itta = [[10**9] * w for i in range(h)]
d = deque()
# aaa=d.append
for i in range(h):
for j in range(w):
if a[i][j] == "#":
d.append((i, j))
itta[i][j] = 0
# print(d)
# print(itta)
while d:
cnt += 1
for l in range(len(d)):
nh, nw = d.popleft()
for i in range(4):
d1, d2 = direction[i]
if 0 <= nh + d1 < h and 0 <= nw + d2 < w:
if itta[nh + d1][nw + d2] == 10**9:
itta[nh + d1][nw + d2] = cnt
d.append((nh + d1, nw + d2))
# print(d)
# print(itta)
print((cnt - 1))
| false | 0 | [
"- d.append([i, j])",
"+ d.append((i, j))",
"- d.append([nh + d1, nw + d2])",
"+ d.append((nh + d1, nw + d2))"
] | false | 0.044537 | 0.047055 | 0.946469 | [
"s622635849",
"s506262034"
] |
u477320129 | p02550 | python | s289348138 | s552252380 | 172 | 122 | 17,520 | 9,180 | Accepted | Accepted | 29.07 | #!/usr/bin/env python3
import sys
# https://en.wikipedia.org/wiki/Cycle_detection
def floyd_cycle_finding(f, x0):
'''
循環していない部分の長さをlam
循環部分の長さをmuとして
(lam, mu)
を返す
>>> floyd_cycle_finding(lambda x: x**2 % 3, 2)
(1, 1)
>>> floyd_cycle_finding(lambda x: x**2 % 1001, 2)
(2, 4)
>>> floyd_cycle_finding(lambda x: x**2 % 16, 2)
(2, 1)
>>> floyd_cycle_finding(lambda x: x*2 % 5, 3)
(0, 4)
>>> floyd_cycle_finding(lambda x: x*2 % 5, 0)
(0, 1)
'''
# a_i = a_j
# の関係が成り立つ時
# a_{lam+n+k*mu} = a_{lam+n+k'*mu}
# より|i-j|は循環の長さの整数倍になる
# そこで
# a_m = a_2m
# なるmを見つける
# 前述の性質からmは循環の長さの整数倍となっているため
# 2m - m = m = k*mu = lam + n + k'*mu
# したがって、lam + nはmuの倍数となるので
# 地点mからlamステップ進むと循環の開始点に到達する
# lamが求まれば後は流れでmuも求まる
tortoise = f(x0)
hare = f(f(x0))
while tortoise != hare:
tortoise = f(tortoise)
hare = f(f(hare))
lam = 0
tortoise = x0
while tortoise != hare:
tortoise = f(tortoise)
hare = f(hare)
lam += 1
mu = 1
hare = f(tortoise)
while tortoise != hare:
hare = f(hare)
mu += 1
return lam, mu
def solve(N: int, X: int, M: int):
f = lambda x: x**2 % M
def g(x):
while True:
yield x
x = f(x)
lam, mu = floyd_cycle_finding(f, X)
ans = 0
gg = g(X)
k = max((N - lam) // mu, 0)
for i in range(min(N, lam)):
ans += next(gg)
for i in range(mu):
ans += k * next(gg)
for i in range((N-lam)%mu):
ans += next(gg)
return ans
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
X = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
print((solve(N, X, M)))
def test():
import doctest
doctest.testmod()
if __name__ == '__main__':
test()
main()
| #!/usr/bin/env python3
import sys
# https://en.wikipedia.org/wiki/Cycle_detection
def floyd_cycle_finding(f, x0):
'''
循環していない部分の長さをlam
循環部分の長さをmuとして
(lam, mu)
を返す
>>> floyd_cycle_finding(lambda x: x**2 % 3, 2)
(1, 1)
>>> floyd_cycle_finding(lambda x: x**2 % 1001, 2)
(2, 4)
>>> floyd_cycle_finding(lambda x: x**2 % 16, 2)
(2, 1)
>>> floyd_cycle_finding(lambda x: x*2 % 5, 3)
(0, 4)
>>> floyd_cycle_finding(lambda x: x*2 % 5, 0)
(0, 1)
'''
# a_i = a_j
# の関係が成り立つ時
# a_{lam+n+k*mu} = a_{lam+n+k'*mu}
# より|i-j|は循環の長さの整数倍になる
# そこで
# a_m = a_2m
# なるmを見つける
# 前述の性質からmは循環の長さの整数倍となっているため
# 2m - m = m = k*mu = lam + n + k'*mu
# したがって、lam + nはmuの倍数となるので
# 地点mからlamステップ進むと循環の開始点に到達する
# lamが求まれば後は流れでmuも求まる
tortoise = f(x0)
hare = f(f(x0))
while tortoise != hare:
tortoise = f(tortoise)
hare = f(f(hare))
lam = 0
tortoise = x0
while tortoise != hare:
tortoise = f(tortoise)
hare = f(hare)
lam += 1
mu = 1
hare = f(tortoise)
while tortoise != hare:
hare = f(hare)
mu += 1
return lam, mu
def solve(N: int, X: int, M: int):
f = lambda x: x**2 % M
def g(x):
while True:
yield x
x = f(x)
lam, mu = floyd_cycle_finding(f, X)
ans = 0
gg = g(X)
k = max((N - lam) // mu, 0)
for i in range(min(N, lam)):
ans += next(gg)
for i in range(mu):
ans += k * next(gg)
for i in range((N-lam)%mu):
ans += next(gg)
return ans
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
X = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
print((solve(N, X, M)))
def test():
import doctest
doctest.testmod()
if __name__ == '__main__':
#test()
main()
| 92 | 92 | 2,193 | 2,194 | #!/usr/bin/env python3
import sys
# https://en.wikipedia.org/wiki/Cycle_detection
def floyd_cycle_finding(f, x0):
"""
循環していない部分の長さをlam
循環部分の長さをmuとして
(lam, mu)
を返す
>>> floyd_cycle_finding(lambda x: x**2 % 3, 2)
(1, 1)
>>> floyd_cycle_finding(lambda x: x**2 % 1001, 2)
(2, 4)
>>> floyd_cycle_finding(lambda x: x**2 % 16, 2)
(2, 1)
>>> floyd_cycle_finding(lambda x: x*2 % 5, 3)
(0, 4)
>>> floyd_cycle_finding(lambda x: x*2 % 5, 0)
(0, 1)
"""
# a_i = a_j
# の関係が成り立つ時
# a_{lam+n+k*mu} = a_{lam+n+k'*mu}
# より|i-j|は循環の長さの整数倍になる
# そこで
# a_m = a_2m
# なるmを見つける
# 前述の性質からmは循環の長さの整数倍となっているため
# 2m - m = m = k*mu = lam + n + k'*mu
# したがって、lam + nはmuの倍数となるので
# 地点mからlamステップ進むと循環の開始点に到達する
# lamが求まれば後は流れでmuも求まる
tortoise = f(x0)
hare = f(f(x0))
while tortoise != hare:
tortoise = f(tortoise)
hare = f(f(hare))
lam = 0
tortoise = x0
while tortoise != hare:
tortoise = f(tortoise)
hare = f(hare)
lam += 1
mu = 1
hare = f(tortoise)
while tortoise != hare:
hare = f(hare)
mu += 1
return lam, mu
def solve(N: int, X: int, M: int):
f = lambda x: x**2 % M
def g(x):
while True:
yield x
x = f(x)
lam, mu = floyd_cycle_finding(f, X)
ans = 0
gg = g(X)
k = max((N - lam) // mu, 0)
for i in range(min(N, lam)):
ans += next(gg)
for i in range(mu):
ans += k * next(gg)
for i in range((N - lam) % mu):
ans += next(gg)
return ans
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
X = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
print((solve(N, X, M)))
def test():
import doctest
doctest.testmod()
if __name__ == "__main__":
test()
main()
| #!/usr/bin/env python3
import sys
# https://en.wikipedia.org/wiki/Cycle_detection
def floyd_cycle_finding(f, x0):
"""
循環していない部分の長さをlam
循環部分の長さをmuとして
(lam, mu)
を返す
>>> floyd_cycle_finding(lambda x: x**2 % 3, 2)
(1, 1)
>>> floyd_cycle_finding(lambda x: x**2 % 1001, 2)
(2, 4)
>>> floyd_cycle_finding(lambda x: x**2 % 16, 2)
(2, 1)
>>> floyd_cycle_finding(lambda x: x*2 % 5, 3)
(0, 4)
>>> floyd_cycle_finding(lambda x: x*2 % 5, 0)
(0, 1)
"""
# a_i = a_j
# の関係が成り立つ時
# a_{lam+n+k*mu} = a_{lam+n+k'*mu}
# より|i-j|は循環の長さの整数倍になる
# そこで
# a_m = a_2m
# なるmを見つける
# 前述の性質からmは循環の長さの整数倍となっているため
# 2m - m = m = k*mu = lam + n + k'*mu
# したがって、lam + nはmuの倍数となるので
# 地点mからlamステップ進むと循環の開始点に到達する
# lamが求まれば後は流れでmuも求まる
tortoise = f(x0)
hare = f(f(x0))
while tortoise != hare:
tortoise = f(tortoise)
hare = f(f(hare))
lam = 0
tortoise = x0
while tortoise != hare:
tortoise = f(tortoise)
hare = f(hare)
lam += 1
mu = 1
hare = f(tortoise)
while tortoise != hare:
hare = f(hare)
mu += 1
return lam, mu
def solve(N: int, X: int, M: int):
f = lambda x: x**2 % M
def g(x):
while True:
yield x
x = f(x)
lam, mu = floyd_cycle_finding(f, X)
ans = 0
gg = g(X)
k = max((N - lam) // mu, 0)
for i in range(min(N, lam)):
ans += next(gg)
for i in range(mu):
ans += k * next(gg)
for i in range((N - lam) % mu):
ans += next(gg)
return ans
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
X = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
print((solve(N, X, M)))
def test():
import doctest
doctest.testmod()
if __name__ == "__main__":
# test()
main()
| false | 0 | [
"- test()",
"+ # test()"
] | false | 0.276917 | 0.05981 | 4.629963 | [
"s289348138",
"s552252380"
] |
u075012704 | p03472 | python | s213606897 | s058891832 | 1,864 | 370 | 11,692 | 11,764 | Accepted | Accepted | 80.15 | import math
N, H = list(map(int, input().split()))
A = []
B = []
for i in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
amax = max(A)
# 最強の振り刀より強い攻撃力を持つものを抽出
B = list([x for x in B if x > amax])
B.sort(reverse=True)
ans = 0
while H > 0:
# まだ投げれる
if not B == []:
H -= B[0]
del B[0]
# もう投げれない
else:
ans += math.ceil(H/amax)
break
ans += 1
print(ans)
| import math
N, H = list(map(int, input().split()))
A = []
B = []
for i in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
amax = max(A)
# 最強の振り刀より強い攻撃力を持つものを抽出
B = list([x for x in B if x > amax])
B.sort()
ans = 0
while H > 0:
# まだ投げれる
if B:
H -= B.pop()
# もう投げれない
else:
ans += math.ceil(H/amax)
break
ans += 1
print(ans)
| 27 | 26 | 459 | 422 | import math
N, H = list(map(int, input().split()))
A = []
B = []
for i in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
amax = max(A)
# 最強の振り刀より強い攻撃力を持つものを抽出
B = list([x for x in B if x > amax])
B.sort(reverse=True)
ans = 0
while H > 0:
# まだ投げれる
if not B == []:
H -= B[0]
del B[0]
# もう投げれない
else:
ans += math.ceil(H / amax)
break
ans += 1
print(ans)
| import math
N, H = list(map(int, input().split()))
A = []
B = []
for i in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
amax = max(A)
# 最強の振り刀より強い攻撃力を持つものを抽出
B = list([x for x in B if x > amax])
B.sort()
ans = 0
while H > 0:
# まだ投げれる
if B:
H -= B.pop()
# もう投げれない
else:
ans += math.ceil(H / amax)
break
ans += 1
print(ans)
| false | 3.703704 | [
"-B.sort(reverse=True)",
"+B.sort()",
"- if not B == []:",
"- H -= B[0]",
"- del B[0]",
"+ if B:",
"+ H -= B.pop()"
] | false | 0.195651 | 0.115688 | 1.691198 | [
"s213606897",
"s058891832"
] |
u677121387 | p02773 | python | s748479559 | s902653253 | 718 | 501 | 35,220 | 35,952 | Accepted | Accepted | 30.22 | n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
d = {}
for i in range(n):
d[s[i]] = d.get(s[i],0)+1
m = max(d.values())
lst = []
for key in d:
if d[key] == m:
lst.append(key)
lst.sort()
for i in lst:
print(i)
| from collections import Counter
n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
c = Counter(s)
m = max(c.values())
ans = sorted(k for k,v in list(c.items()) if v == m)
print(("\n".join(ans))) | 17 | 7 | 250 | 190 | n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
d = {}
for i in range(n):
d[s[i]] = d.get(s[i], 0) + 1
m = max(d.values())
lst = []
for key in d:
if d[key] == m:
lst.append(key)
lst.sort()
for i in lst:
print(i)
| from collections import Counter
n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
c = Counter(s)
m = max(c.values())
ans = sorted(k for k, v in list(c.items()) if v == m)
print(("\n".join(ans)))
| false | 58.823529 | [
"+from collections import Counter",
"+",
"-d = {}",
"-for i in range(n):",
"- d[s[i]] = d.get(s[i], 0) + 1",
"-m = max(d.values())",
"-lst = []",
"-for key in d:",
"- if d[key] == m:",
"- lst.append(key)",
"-lst.sort()",
"-for i in lst:",
"- print(i)",
"+c = Counter(s)",
"+m = max(c.values())",
"+ans = sorted(k for k, v in list(c.items()) if v == m)",
"+print((\"\\n\".join(ans)))"
] | false | 0.05993 | 0.072024 | 0.832081 | [
"s748479559",
"s902653253"
] |
u724687935 | p03798 | python | s363926950 | s435214579 | 180 | 163 | 4,988 | 5,116 | Accepted | Accepted | 9.44 | def main():
# import sys
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines
N = int(eval(input()))
L = eval(input())
A = [None] * (N + 1)
for a0, a1 in [(0, 0), (0, 1), (1, 0), (1, 1)]:
A[0] = a0
A[1] = a1
for i in range(2, N + 1):
a = A[i - 1]
s = 0 if L[i - 1] == 'o' else 1
# if a == 0:
# if s == 0:
# A[i] = A[i - 2]
# elif s == 1:
# A[i] = A[i - 2] ^ 1
# elif a == 1:
# if s == 0:
# A[i] = A[i - 2] ^ 1
# elif s == 1:
# A[i] = A[i - 2]
A[i] = A[i - 2] ^ (a ^ s)
am = A[1] ^ (A[0] ^ (L[0] == 'x'))
if A[0] == A[N] and am == A[N - 1]:
exists = True
break
else:
exists = False
if exists:
ans = []
for i in range(N):
c = 'W' if A[i] else 'S'
ans.append(c)
print((''.join(ans)))
else:
print((-1))
if __name__ == "__main__":
main()
| def main():
# import sys
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines
N = int(eval(input()))
L = eval(input())
A = [None] * (N + 2)
for a0, a1 in [(0, 0), (0, 1), (1, 0), (1, 1)]:
A[0] = a0
A[1] = a1
for i in range(2, N + 1):
a = A[i - 1]
s = (L[i - 1] == 'x')
A[i] = A[i - 2] ^ (a ^ s)
A[N + 1] = A[N - 1] ^ (A[N] ^ (L[0] == 'x'))
if A[0] == A[N] and A[1] == A[N + 1]:
exists = True
break
else:
exists = False
if exists:
ans = []
for i in range(N):
c = 'W' if A[i] else 'S'
ans.append(c)
print((''.join(ans)))
else:
print((-1))
if __name__ == "__main__":
main()
| 44 | 34 | 1,167 | 827 | def main():
# import sys
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines
N = int(eval(input()))
L = eval(input())
A = [None] * (N + 1)
for a0, a1 in [(0, 0), (0, 1), (1, 0), (1, 1)]:
A[0] = a0
A[1] = a1
for i in range(2, N + 1):
a = A[i - 1]
s = 0 if L[i - 1] == "o" else 1
# if a == 0:
# if s == 0:
# A[i] = A[i - 2]
# elif s == 1:
# A[i] = A[i - 2] ^ 1
# elif a == 1:
# if s == 0:
# A[i] = A[i - 2] ^ 1
# elif s == 1:
# A[i] = A[i - 2]
A[i] = A[i - 2] ^ (a ^ s)
am = A[1] ^ (A[0] ^ (L[0] == "x"))
if A[0] == A[N] and am == A[N - 1]:
exists = True
break
else:
exists = False
if exists:
ans = []
for i in range(N):
c = "W" if A[i] else "S"
ans.append(c)
print(("".join(ans)))
else:
print((-1))
if __name__ == "__main__":
main()
| def main():
# import sys
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines
N = int(eval(input()))
L = eval(input())
A = [None] * (N + 2)
for a0, a1 in [(0, 0), (0, 1), (1, 0), (1, 1)]:
A[0] = a0
A[1] = a1
for i in range(2, N + 1):
a = A[i - 1]
s = L[i - 1] == "x"
A[i] = A[i - 2] ^ (a ^ s)
A[N + 1] = A[N - 1] ^ (A[N] ^ (L[0] == "x"))
if A[0] == A[N] and A[1] == A[N + 1]:
exists = True
break
else:
exists = False
if exists:
ans = []
for i in range(N):
c = "W" if A[i] else "S"
ans.append(c)
print(("".join(ans)))
else:
print((-1))
if __name__ == "__main__":
main()
| false | 22.727273 | [
"- A = [None] * (N + 1)",
"+ A = [None] * (N + 2)",
"- s = 0 if L[i - 1] == \"o\" else 1",
"- # if a == 0:",
"- # if s == 0:",
"- # A[i] = A[i - 2]",
"- # elif s == 1:",
"- # A[i] = A[i - 2] ^ 1",
"- # elif a == 1:",
"- # if s == 0:",
"- # A[i] = A[i - 2] ^ 1",
"- # elif s == 1:",
"- # A[i] = A[i - 2]",
"+ s = L[i - 1] == \"x\"",
"- am = A[1] ^ (A[0] ^ (L[0] == \"x\"))",
"- if A[0] == A[N] and am == A[N - 1]:",
"+ A[N + 1] = A[N - 1] ^ (A[N] ^ (L[0] == \"x\"))",
"+ if A[0] == A[N] and A[1] == A[N + 1]:"
] | false | 0.047103 | 0.046633 | 1.010069 | [
"s363926950",
"s435214579"
] |
u691018832 | p03283 | python | s414701090 | s174119820 | 810 | 619 | 68,496 | 15,640 | Accepted | Accepted | 23.58 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
import numpy as np
n, m, q = list(map(int, readline().split()))
lr = [list(map(int, readline().split())) for _ in range(m)]
cnt = [[0] * (n + 1) for _ in range(n + 1)]
for l, r in lr:
cnt[l][r] += 1
cnt = np.cumsum(cnt, axis=0).cumsum(axis=1).tolist()
for _ in range(q):
p, q = list(map(int, readline().split()))
p -= 1
ans = cnt[q][q] + cnt[p][p]
ans -= cnt[q][p] + cnt[p][q]
print(ans)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
# da[i][j]:(0,0)~(i,j)の長方形の和
def da_generate(h, w, a):
da = [[0] * w for j in range(h)]
da[0][0] = a[0][0]
for i in range(1, w):
da[0][i] = da[0][i-1] + a[0][i]
for i in range(1, h):
cnt_w = 0
for j in range(w):
cnt_w += a[i][j]
da[i][j] = da[i-1][j] + cnt_w
return da
# da_calc(p,q,x,y):(p,q)~(x,y)の長方形の和
def da_calc(p, q, x, y):
if p > x or q > y:
return 0
if p == 0 and q == 0:
return da[x][y]
if p == 0:
return da[x][y] - da[x][q-1]
if q == 0:
return da[x][y] - da[p-1][y]
return da[x][y] - da[p-1][y] - da[x][q-1] + da[p-1][q-1]
n, m, q = list(map(int, readline().split()))
lr = [[0] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
l, r = list(map(int, readline().split()))
lr[l][r] += 1
da = da_generate(n + 1, n + 1, lr)
for _ in range(q):
p, q = list(map(int, readline().split()))
print((da_calc(p, p, q, q)))
| 20 | 43 | 568 | 1,133 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
import numpy as np
n, m, q = list(map(int, readline().split()))
lr = [list(map(int, readline().split())) for _ in range(m)]
cnt = [[0] * (n + 1) for _ in range(n + 1)]
for l, r in lr:
cnt[l][r] += 1
cnt = np.cumsum(cnt, axis=0).cumsum(axis=1).tolist()
for _ in range(q):
p, q = list(map(int, readline().split()))
p -= 1
ans = cnt[q][q] + cnt[p][p]
ans -= cnt[q][p] + cnt[p][q]
print(ans)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
# da[i][j]:(0,0)~(i,j)の長方形の和
def da_generate(h, w, a):
da = [[0] * w for j in range(h)]
da[0][0] = a[0][0]
for i in range(1, w):
da[0][i] = da[0][i - 1] + a[0][i]
for i in range(1, h):
cnt_w = 0
for j in range(w):
cnt_w += a[i][j]
da[i][j] = da[i - 1][j] + cnt_w
return da
# da_calc(p,q,x,y):(p,q)~(x,y)の長方形の和
def da_calc(p, q, x, y):
if p > x or q > y:
return 0
if p == 0 and q == 0:
return da[x][y]
if p == 0:
return da[x][y] - da[x][q - 1]
if q == 0:
return da[x][y] - da[p - 1][y]
return da[x][y] - da[p - 1][y] - da[x][q - 1] + da[p - 1][q - 1]
n, m, q = list(map(int, readline().split()))
lr = [[0] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
l, r = list(map(int, readline().split()))
lr[l][r] += 1
da = da_generate(n + 1, n + 1, lr)
for _ in range(q):
p, q = list(map(int, readline().split()))
print((da_calc(p, p, q, q)))
| false | 53.488372 | [
"-import numpy as np",
"+# da[i][j]:(0,0)~(i,j)の長方形の和",
"+def da_generate(h, w, a):",
"+ da = [[0] * w for j in range(h)]",
"+ da[0][0] = a[0][0]",
"+ for i in range(1, w):",
"+ da[0][i] = da[0][i - 1] + a[0][i]",
"+ for i in range(1, h):",
"+ cnt_w = 0",
"+ for j in range(w):",
"+ cnt_w += a[i][j]",
"+ da[i][j] = da[i - 1][j] + cnt_w",
"+ return da",
"+",
"+",
"+# da_calc(p,q,x,y):(p,q)~(x,y)の長方形の和",
"+def da_calc(p, q, x, y):",
"+ if p > x or q > y:",
"+ return 0",
"+ if p == 0 and q == 0:",
"+ return da[x][y]",
"+ if p == 0:",
"+ return da[x][y] - da[x][q - 1]",
"+ if q == 0:",
"+ return da[x][y] - da[p - 1][y]",
"+ return da[x][y] - da[p - 1][y] - da[x][q - 1] + da[p - 1][q - 1]",
"+",
"-lr = [list(map(int, readline().split())) for _ in range(m)]",
"-cnt = [[0] * (n + 1) for _ in range(n + 1)]",
"-for l, r in lr:",
"- cnt[l][r] += 1",
"-cnt = np.cumsum(cnt, axis=0).cumsum(axis=1).tolist()",
"+lr = [[0] * (n + 1) for _ in range(n + 1)]",
"+for _ in range(m):",
"+ l, r = list(map(int, readline().split()))",
"+ lr[l][r] += 1",
"+da = da_generate(n + 1, n + 1, lr)",
"- p -= 1",
"- ans = cnt[q][q] + cnt[p][p]",
"- ans -= cnt[q][p] + cnt[p][q]",
"- print(ans)",
"+ print((da_calc(p, p, q, q)))"
] | false | 0.391675 | 0.106467 | 3.678854 | [
"s414701090",
"s174119820"
] |
u223904637 | p02781 | python | s575431808 | s643967041 | 1,031 | 183 | 43,356 | 38,256 | Accepted | Accepted | 82.25 | n=int(eval(input()))
k=int(eval(input()))
s=len(list(str(n)))
if k==1:
ans=(s-1)*9
for i in range(9):
if n>=(10**(s-1))*(i+1):
ans+=1
elif k==2:
ans=9*9*(s-1)*(s-2)//2
for i in range(9):
for j in range(s-1):
for p in range(9):
if n>=(10**(s-1))*(i+1)+(10**j)*(p+1):
ans+=1
else:
ans=9*81*(s-1)*(s-2)*(s-3)//6
f=int(list(str(n))[0])
ans+=(f-1)*81*(s-1)*(s-2)//2
for p in range(s-1):
for q in range(s-1):
if p<q:
for t in range(1,10):
for u in range(1,10):
if n>=(10**(s-1))*f+(10**p)*t+(10**q)*u:
ans+=1
print(ans)
| n = int(eval(input()))
N = len(str(n))
k = int(eval(input()))
s = [int(i) for i in str(n)]
dpi = [[0]*(k+1) for _ in range(N+1)]
dpj = [[0]*(k+1) for _ in range(N+1)]
dpi[0][0] = 1
for i in range(N):
for j in range(k+1):
dpi[i+1][j] += dpi[i][j]*(s[i]==0)
dpj[i+1][j] += dpj[i][j]+dpi[i][j]*(s[i]>0)
if j < k:
dpi[i+1][j+1]+=dpi[i][j]*(s[i]>0)
dpj[i+1][j+1]+=dpj[i][j]*9+dpi[i][j]*max(0,s[i]-1)
print((dpi[N][k]+dpj[N][k]))
| 27 | 15 | 744 | 476 | n = int(eval(input()))
k = int(eval(input()))
s = len(list(str(n)))
if k == 1:
ans = (s - 1) * 9
for i in range(9):
if n >= (10 ** (s - 1)) * (i + 1):
ans += 1
elif k == 2:
ans = 9 * 9 * (s - 1) * (s - 2) // 2
for i in range(9):
for j in range(s - 1):
for p in range(9):
if n >= (10 ** (s - 1)) * (i + 1) + (10**j) * (p + 1):
ans += 1
else:
ans = 9 * 81 * (s - 1) * (s - 2) * (s - 3) // 6
f = int(list(str(n))[0])
ans += (f - 1) * 81 * (s - 1) * (s - 2) // 2
for p in range(s - 1):
for q in range(s - 1):
if p < q:
for t in range(1, 10):
for u in range(1, 10):
if n >= (10 ** (s - 1)) * f + (10**p) * t + (10**q) * u:
ans += 1
print(ans)
| n = int(eval(input()))
N = len(str(n))
k = int(eval(input()))
s = [int(i) for i in str(n)]
dpi = [[0] * (k + 1) for _ in range(N + 1)]
dpj = [[0] * (k + 1) for _ in range(N + 1)]
dpi[0][0] = 1
for i in range(N):
for j in range(k + 1):
dpi[i + 1][j] += dpi[i][j] * (s[i] == 0)
dpj[i + 1][j] += dpj[i][j] + dpi[i][j] * (s[i] > 0)
if j < k:
dpi[i + 1][j + 1] += dpi[i][j] * (s[i] > 0)
dpj[i + 1][j + 1] += dpj[i][j] * 9 + dpi[i][j] * max(0, s[i] - 1)
print((dpi[N][k] + dpj[N][k]))
| false | 44.444444 | [
"+N = len(str(n))",
"-s = len(list(str(n)))",
"-if k == 1:",
"- ans = (s - 1) * 9",
"- for i in range(9):",
"- if n >= (10 ** (s - 1)) * (i + 1):",
"- ans += 1",
"-elif k == 2:",
"- ans = 9 * 9 * (s - 1) * (s - 2) // 2",
"- for i in range(9):",
"- for j in range(s - 1):",
"- for p in range(9):",
"- if n >= (10 ** (s - 1)) * (i + 1) + (10**j) * (p + 1):",
"- ans += 1",
"-else:",
"- ans = 9 * 81 * (s - 1) * (s - 2) * (s - 3) // 6",
"- f = int(list(str(n))[0])",
"- ans += (f - 1) * 81 * (s - 1) * (s - 2) // 2",
"- for p in range(s - 1):",
"- for q in range(s - 1):",
"- if p < q:",
"- for t in range(1, 10):",
"- for u in range(1, 10):",
"- if n >= (10 ** (s - 1)) * f + (10**p) * t + (10**q) * u:",
"- ans += 1",
"-print(ans)",
"+s = [int(i) for i in str(n)]",
"+dpi = [[0] * (k + 1) for _ in range(N + 1)]",
"+dpj = [[0] * (k + 1) for _ in range(N + 1)]",
"+dpi[0][0] = 1",
"+for i in range(N):",
"+ for j in range(k + 1):",
"+ dpi[i + 1][j] += dpi[i][j] * (s[i] == 0)",
"+ dpj[i + 1][j] += dpj[i][j] + dpi[i][j] * (s[i] > 0)",
"+ if j < k:",
"+ dpi[i + 1][j + 1] += dpi[i][j] * (s[i] > 0)",
"+ dpj[i + 1][j + 1] += dpj[i][j] * 9 + dpi[i][j] * max(0, s[i] - 1)",
"+print((dpi[N][k] + dpj[N][k]))"
] | false | 0.116247 | 0.035381 | 3.285588 | [
"s575431808",
"s643967041"
] |
u515740713 | p03163 | python | s885706920 | s437122588 | 657 | 210 | 171,400 | 15,480 | Accepted | Accepted | 68.04 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,W = list(map(int, readline().split()))
w=[];v=[]
for _ in range(N):
a,b = list(map(int, readline().split()))
w.append(a)
v.append(b)
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(N):
for j in range(W+1):
if j >= w[i]:
dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i])
else:
dp[i+1][j] = dp[i][j]
print((dp[N][W])) | import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,W = list(map(int,readline().split()))
WV = [list(map(int,readline().split())) for _ in range(N)]
dp = np.zeros(W+1,np.int64)
for w,v in WV:
np.maximum(dp[w:],dp[:-w].copy() +v,out=dp[w:])
print((dp.max())) | 19 | 12 | 481 | 348 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, W = list(map(int, readline().split()))
w = []
v = []
for _ in range(N):
a, b = list(map(int, readline().split()))
w.append(a)
v.append(b)
dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
for i in range(N):
for j in range(W + 1):
if j >= w[i]:
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i])
else:
dp[i + 1][j] = dp[i][j]
print((dp[N][W]))
| import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, W = list(map(int, readline().split()))
WV = [list(map(int, readline().split())) for _ in range(N)]
dp = np.zeros(W + 1, np.int64)
for w, v in WV:
np.maximum(dp[w:], dp[:-w].copy() + v, out=dp[w:])
print((dp.max()))
| false | 36.842105 | [
"+import numpy as np",
"-w = []",
"-v = []",
"-for _ in range(N):",
"- a, b = list(map(int, readline().split()))",
"- w.append(a)",
"- v.append(b)",
"-dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]",
"-for i in range(N):",
"- for j in range(W + 1):",
"- if j >= w[i]:",
"- dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i])",
"- else:",
"- dp[i + 1][j] = dp[i][j]",
"-print((dp[N][W]))",
"+WV = [list(map(int, readline().split())) for _ in range(N)]",
"+dp = np.zeros(W + 1, np.int64)",
"+for w, v in WV:",
"+ np.maximum(dp[w:], dp[:-w].copy() + v, out=dp[w:])",
"+print((dp.max()))"
] | false | 0.083676 | 0.22449 | 0.372738 | [
"s885706920",
"s437122588"
] |
u631277801 | p02990 | python | s338167958 | s910528866 | 128 | 24 | 15,276 | 3,828 | Accepted | Accepted | 81.25 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x) - 1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
class CombTools(object):
def __init__(self, cap: int, mod: int):
self.cap = cap
self.mod = mod
self.inv = self._calc_inv()
self.fac = self._calc_fac()
self.fac_inv = self._calc_fac_inv()
def _calc_inv(self):
inv = [0, 1]
for i in range(2, self.cap+1):
inv.append((self.mod - (self.mod // i) * inv[self.mod % i]) % self.mod)
return inv
def _calc_fac(self):
fac = [1]
for i in range(1, self.cap+1):
fac.append((i * fac[-1]) % self.mod)
return fac
def _calc_fac_inv(self):
fac_inv = [1]
for i in range(1, self.cap+1):
fac_inv.append((self.inv[i] * fac_inv[-1]) % self.mod)
return fac_inv
def nCr(self, n: int, r: int):
# validation
if r > n:
raise ValueError("n must be larger than r (n={}, r={})".format(n, r))
# calculation
return self.fac[n] * self.fac_inv[n-r] * self.fac_inv[r] % self.mod
def nPr(self, n: int, r: int):
# validation
if r > n:
raise ValueError("n must be larger than r (n={}, r={})".format(n, r))
# calculation
return self.fac[n] * self.fac_inv[n-r] % self.mod
def nHr(self, n: int, r: int):
return self.nCr(n+r-1, n)
n, k = li()
CAP = 10**5
MOD = 10**9 + 7
ct = CombTools(CAP, MOD)
for i in range(1, k+1):
if n-k-i+1 < 0:
print((0))
else:
ans = ct.nHr(n-k-i+1, i+1) * ct.nHr(k-i, i)
print((ans % MOD)) | import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x) - 1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
class CombTools(object):
def __init__(self, cap: int, mod: int):
self.cap = cap
self.mod = mod
self.inv = self._calc_inv()
self.fac = self._calc_fac()
self.fac_inv = self._calc_fac_inv()
def _calc_inv(self):
inv = [0, 1]
for i in range(2, self.cap+1):
inv.append((self.mod - (self.mod // i) * inv[self.mod % i]) % self.mod)
return inv
def _calc_fac(self):
fac = [1]
for i in range(1, self.cap+1):
fac.append((i * fac[-1]) % self.mod)
return fac
def _calc_fac_inv(self):
fac_inv = [1]
for i in range(1, self.cap+1):
fac_inv.append((self.inv[i] * fac_inv[-1]) % self.mod)
return fac_inv
def nCr(self, n: int, r: int):
# validation
# if r > n:
# raise ValueError("n must be larger than r (n={}, r={})".format(n, r))
# calculation
return self.fac[n] * self.fac_inv[n-r] * self.fac_inv[r] % self.mod
def nPr(self, n: int, r: int):
# validation
if r > n:
raise ValueError("n must be larger than r (n={}, r={})".format(n, r))
# calculation
return self.fac[n] * self.fac_inv[n-r] % self.mod
def nHr(self, n: int, r: int):
return self.nCr(n+r-1, n)
n, k = li()
mod = 10 ** 9 + 7
ct = CombTools(2*n+1, mod)
for i in range(1, k+1):
if n-k-i+1 < 0:
print((0))
else:
print((ct.nHr(k-i, i) * ct.nHr(n-k-i+1, i+1) % mod)) | 76 | 73 | 2,043 | 2,017 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
def li():
return list(map(int, stdin.readline().split()))
def li_():
return [int(x) - 1 for x in stdin.readline().split()]
def lf():
return list(map(float, stdin.readline().split()))
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
class CombTools(object):
def __init__(self, cap: int, mod: int):
self.cap = cap
self.mod = mod
self.inv = self._calc_inv()
self.fac = self._calc_fac()
self.fac_inv = self._calc_fac_inv()
def _calc_inv(self):
inv = [0, 1]
for i in range(2, self.cap + 1):
inv.append((self.mod - (self.mod // i) * inv[self.mod % i]) % self.mod)
return inv
def _calc_fac(self):
fac = [1]
for i in range(1, self.cap + 1):
fac.append((i * fac[-1]) % self.mod)
return fac
def _calc_fac_inv(self):
fac_inv = [1]
for i in range(1, self.cap + 1):
fac_inv.append((self.inv[i] * fac_inv[-1]) % self.mod)
return fac_inv
def nCr(self, n: int, r: int):
# validation
if r > n:
raise ValueError("n must be larger than r (n={}, r={})".format(n, r))
# calculation
return self.fac[n] * self.fac_inv[n - r] * self.fac_inv[r] % self.mod
def nPr(self, n: int, r: int):
# validation
if r > n:
raise ValueError("n must be larger than r (n={}, r={})".format(n, r))
# calculation
return self.fac[n] * self.fac_inv[n - r] % self.mod
def nHr(self, n: int, r: int):
return self.nCr(n + r - 1, n)
n, k = li()
CAP = 10**5
MOD = 10**9 + 7
ct = CombTools(CAP, MOD)
for i in range(1, k + 1):
if n - k - i + 1 < 0:
print((0))
else:
ans = ct.nHr(n - k - i + 1, i + 1) * ct.nHr(k - i, i)
print((ans % MOD))
| import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
def li():
return list(map(int, stdin.readline().split()))
def li_():
return [int(x) - 1 for x in stdin.readline().split()]
def lf():
return list(map(float, stdin.readline().split()))
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
class CombTools(object):
def __init__(self, cap: int, mod: int):
self.cap = cap
self.mod = mod
self.inv = self._calc_inv()
self.fac = self._calc_fac()
self.fac_inv = self._calc_fac_inv()
def _calc_inv(self):
inv = [0, 1]
for i in range(2, self.cap + 1):
inv.append((self.mod - (self.mod // i) * inv[self.mod % i]) % self.mod)
return inv
def _calc_fac(self):
fac = [1]
for i in range(1, self.cap + 1):
fac.append((i * fac[-1]) % self.mod)
return fac
def _calc_fac_inv(self):
fac_inv = [1]
for i in range(1, self.cap + 1):
fac_inv.append((self.inv[i] * fac_inv[-1]) % self.mod)
return fac_inv
def nCr(self, n: int, r: int):
# validation
# if r > n:
# raise ValueError("n must be larger than r (n={}, r={})".format(n, r))
# calculation
return self.fac[n] * self.fac_inv[n - r] * self.fac_inv[r] % self.mod
def nPr(self, n: int, r: int):
# validation
if r > n:
raise ValueError("n must be larger than r (n={}, r={})".format(n, r))
# calculation
return self.fac[n] * self.fac_inv[n - r] % self.mod
def nHr(self, n: int, r: int):
return self.nCr(n + r - 1, n)
n, k = li()
mod = 10**9 + 7
ct = CombTools(2 * n + 1, mod)
for i in range(1, k + 1):
if n - k - i + 1 < 0:
print((0))
else:
print((ct.nHr(k - i, i) * ct.nHr(n - k - i + 1, i + 1) % mod))
| false | 3.947368 | [
"- if r > n:",
"- raise ValueError(\"n must be larger than r (n={}, r={})\".format(n, r))",
"+ # if r > n:",
"+ # raise ValueError(\"n must be larger than r (n={}, r={})\".format(n, r))",
"-CAP = 10**5",
"-MOD = 10**9 + 7",
"-ct = CombTools(CAP, MOD)",
"+mod = 10**9 + 7",
"+ct = CombTools(2 * n + 1, mod)",
"- ans = ct.nHr(n - k - i + 1, i + 1) * ct.nHr(k - i, i)",
"- print((ans % MOD))",
"+ print((ct.nHr(k - i, i) * ct.nHr(n - k - i + 1, i + 1) % mod))"
] | false | 0.259354 | 0.037035 | 7.002924 | [
"s338167958",
"s910528866"
] |
u945080461 | p03198 | python | s186533085 | s956565834 | 1,754 | 463 | 36,168 | 42,696 | Accepted | Accepted | 73.6 | from sys import stdin
from itertools import repeat
def f(a):
n = len(a)
l = [0] * (n + 1)
st = [(a[0], a[0], 1)]
pu = st.append
po = st.pop
for i in range(1, n):
ad = 0
y = a[i]
k = 1
while st and y > st[-1][0]:
x, z, q = po()
c = (((y - 1) / x).bit_length() + 1) / 2 * 2
ad += c * q
k += q
y = z << c
pu((a[i], y, k))
l[i+1] = l[i] + ad
return l
def main():
n = int(stdin.readline())
a = list(map(int, stdin.readline().split(), repeat(10, n)))
l = f(a)
r = f(a[::-1])[::-1]
ans = 10 ** 12
for i in range(n + 1):
if ans > l[i] + i + r[i]:
ans = l[i] + i + r[i]
print(ans)
main()
| from sys import stdin
from itertools import repeat
def f(a):
n = len(a)
l = [0] * (n + 1)
st = [(0, 0, 0, 1)]
pu = st.append
po = st.pop
for i in range(1, n):
ad = 0
r = i
u = 0
k = 1
while st:
y = a[r] << u
x = a[st[-1][0]]
if x >= y:
break
_, r, u, q = po()
c = 0
while x < y:
x *= 4
c += 2
ad += c * q
k += q
u += c
pu((i, r, u, k))
l[i+1] = l[i] + ad
return l
def main():
n = int(stdin.readline())
a = list(map(int, stdin.readline().split(), repeat(10, n)))
l = f(a)
r = f(a[::-1])[::-1]
ans = 10 ** 12
for i in range(n + 1):
if ans > l[i] + i + r[i]:
ans = l[i] + i + r[i]
print(ans)
main()
| 33 | 41 | 792 | 921 | from sys import stdin
from itertools import repeat
def f(a):
n = len(a)
l = [0] * (n + 1)
st = [(a[0], a[0], 1)]
pu = st.append
po = st.pop
for i in range(1, n):
ad = 0
y = a[i]
k = 1
while st and y > st[-1][0]:
x, z, q = po()
c = (((y - 1) / x).bit_length() + 1) / 2 * 2
ad += c * q
k += q
y = z << c
pu((a[i], y, k))
l[i + 1] = l[i] + ad
return l
def main():
n = int(stdin.readline())
a = list(map(int, stdin.readline().split(), repeat(10, n)))
l = f(a)
r = f(a[::-1])[::-1]
ans = 10**12
for i in range(n + 1):
if ans > l[i] + i + r[i]:
ans = l[i] + i + r[i]
print(ans)
main()
| from sys import stdin
from itertools import repeat
def f(a):
n = len(a)
l = [0] * (n + 1)
st = [(0, 0, 0, 1)]
pu = st.append
po = st.pop
for i in range(1, n):
ad = 0
r = i
u = 0
k = 1
while st:
y = a[r] << u
x = a[st[-1][0]]
if x >= y:
break
_, r, u, q = po()
c = 0
while x < y:
x *= 4
c += 2
ad += c * q
k += q
u += c
pu((i, r, u, k))
l[i + 1] = l[i] + ad
return l
def main():
n = int(stdin.readline())
a = list(map(int, stdin.readline().split(), repeat(10, n)))
l = f(a)
r = f(a[::-1])[::-1]
ans = 10**12
for i in range(n + 1):
if ans > l[i] + i + r[i]:
ans = l[i] + i + r[i]
print(ans)
main()
| false | 19.512195 | [
"- st = [(a[0], a[0], 1)]",
"+ st = [(0, 0, 0, 1)]",
"- y = a[i]",
"+ r = i",
"+ u = 0",
"- while st and y > st[-1][0]:",
"- x, z, q = po()",
"- c = (((y - 1) / x).bit_length() + 1) / 2 * 2",
"+ while st:",
"+ y = a[r] << u",
"+ x = a[st[-1][0]]",
"+ if x >= y:",
"+ break",
"+ _, r, u, q = po()",
"+ c = 0",
"+ while x < y:",
"+ x *= 4",
"+ c += 2",
"- y = z << c",
"- pu((a[i], y, k))",
"+ u += c",
"+ pu((i, r, u, k))"
] | false | 0.035706 | 0.041318 | 0.86418 | [
"s186533085",
"s956565834"
] |
u102902647 | p03329 | python | s207326237 | s561010314 | 511 | 334 | 3,828 | 3,828 | Accepted | Accepted | 34.64 | ans = [0] * 100100
ans[0] = 0
n = int(eval(input()))
#n = 127
for i in range(1,n+1):
cand1 = ans[i-1]
cand2 = 100001
cand3 = 100001
x = 6
while (x<=i):
cand2 = min(ans[i-x], cand2)
x=6*x
y = 9
while (y<=i):
cand3 = min(ans[i-y], cand3)
y=9*y
ans[i] = min(cand1,cand2,cand3) + 1
print((ans[n]))
| # -*- coding: utf-8 -*-
"""
Created on Mon Aug 6 17:34:40 2018
@author: Yuki
"""
ans = [0] * 100100
ans[0] = 0
n = int(eval(input()))
#n = 127
for i in range(1,n+1):
cand1 = ans[i-1]
cand2 = 100001
cand3 = 100001
x = 6
while (x<=i):
#cand2 = min(ans[i-x], cand2)
cand2 = ans[i-x]
x=6*x
y = 9
while (y<=i):
#cand3 = min(ans[i-y], cand3)
cand3 = ans[i-y]
y=9*y
ans[i] = min(cand1,cand2,cand3) + 1
print((ans[n]))
| 21 | 31 | 373 | 520 | ans = [0] * 100100
ans[0] = 0
n = int(eval(input()))
# n = 127
for i in range(1, n + 1):
cand1 = ans[i - 1]
cand2 = 100001
cand3 = 100001
x = 6
while x <= i:
cand2 = min(ans[i - x], cand2)
x = 6 * x
y = 9
while y <= i:
cand3 = min(ans[i - y], cand3)
y = 9 * y
ans[i] = min(cand1, cand2, cand3) + 1
print((ans[n]))
| # -*- coding: utf-8 -*-
"""
Created on Mon Aug 6 17:34:40 2018
@author: Yuki
"""
ans = [0] * 100100
ans[0] = 0
n = int(eval(input()))
# n = 127
for i in range(1, n + 1):
cand1 = ans[i - 1]
cand2 = 100001
cand3 = 100001
x = 6
while x <= i:
# cand2 = min(ans[i-x], cand2)
cand2 = ans[i - x]
x = 6 * x
y = 9
while y <= i:
# cand3 = min(ans[i-y], cand3)
cand3 = ans[i - y]
y = 9 * y
ans[i] = min(cand1, cand2, cand3) + 1
print((ans[n]))
| false | 32.258065 | [
"+# -*- coding: utf-8 -*-",
"+\"\"\"",
"+Created on Mon Aug 6 17:34:40 2018",
"+@author: Yuki",
"+\"\"\"",
"- cand2 = min(ans[i - x], cand2)",
"+ # cand2 = min(ans[i-x], cand2)",
"+ cand2 = ans[i - x]",
"- cand3 = min(ans[i - y], cand3)",
"+ # cand3 = min(ans[i-y], cand3)",
"+ cand3 = ans[i - y]"
] | false | 0.192411 | 0.067448 | 2.852707 | [
"s207326237",
"s561010314"
] |
u086566114 | p02412 | python | s207975963 | s567028339 | 200 | 130 | 6,420 | 6,420 | Accepted | Accepted | 35 | def get_num(n, m):
ans = 0
for x in range(n, 2, -1):
if 3 * x - 2 < m:
return ans
for y in range(x - 1, 1, -1):
if x + 2 * y - 1 < m:
break
for z in range(y - 1, 0, -1):
s = x + y + z
if s == m:
ans += 1
break
return ans
while True:
[n, m] = [int(x) for x in input().split()]
if [n, m] == [0, 0]:
break
print((get_num(n, m))) | def get_num(n, m):
ans = 0
for x in range(min(n, m), (m + 2) / 3, -1):
for y in range(x - 1, 1, -1):
if x + 2 * y - 1 < m:
break
for z in range(y - 1, 0, -1):
s = x + y + z
if s == m:
ans += 1
break
return ans
while True:
[n, x] = [int(m) for m in input().split()]
if [n, x] == [0, 0]:
break
print((get_num(n, x))) | 21 | 19 | 522 | 488 | def get_num(n, m):
ans = 0
for x in range(n, 2, -1):
if 3 * x - 2 < m:
return ans
for y in range(x - 1, 1, -1):
if x + 2 * y - 1 < m:
break
for z in range(y - 1, 0, -1):
s = x + y + z
if s == m:
ans += 1
break
return ans
while True:
[n, m] = [int(x) for x in input().split()]
if [n, m] == [0, 0]:
break
print((get_num(n, m)))
| def get_num(n, m):
ans = 0
for x in range(min(n, m), (m + 2) / 3, -1):
for y in range(x - 1, 1, -1):
if x + 2 * y - 1 < m:
break
for z in range(y - 1, 0, -1):
s = x + y + z
if s == m:
ans += 1
break
return ans
while True:
[n, x] = [int(m) for m in input().split()]
if [n, x] == [0, 0]:
break
print((get_num(n, x)))
| false | 9.52381 | [
"- for x in range(n, 2, -1):",
"- if 3 * x - 2 < m:",
"- return ans",
"+ for x in range(min(n, m), (m + 2) / 3, -1):",
"- [n, m] = [int(x) for x in input().split()]",
"- if [n, m] == [0, 0]:",
"+ [n, x] = [int(m) for m in input().split()]",
"+ if [n, x] == [0, 0]:",
"- print((get_num(n, m)))",
"+ print((get_num(n, x)))"
] | false | 0.042454 | 0.082914 | 0.512028 | [
"s207975963",
"s567028339"
] |
u144913062 | p02892 | python | s400140808 | s516036523 | 428 | 351 | 55,772 | 54,236 | Accepted | Accepted | 17.99 | import sys
input = sys.stdin.readline
def floyd_warshall(dist):
for k in range(N):
for i in range(N):
for j in range(N):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
def is_bipartite(u):
for v in range(N):
if u == v or dist[u][v] != 1:
continue
if color[v] == -1:
color[v] = 1 - color[u]
if not is_bipartite(v):
return False
elif color[u] == color[v]:
return False
return True
N = int(eval(input()))
S = [input().rstrip() for _ in range(N)]
dist = [[1 if S[i][j] == '1' else (0 if i == j else float('inf')) for j in range(N)] for i in range(N)]
color = [-1] * N
color[0] = 0
ans = 0
if is_bipartite(0):
floyd_warshall(dist)
ans = max(max(d) for d in dist) + 1
else:
ans = -1
print(ans)
| def b(u,x):
c[u]=x
return all((c[u]!=c[v])&(c[v]or b(v,-x))for v in X if d[u][v]==1)
N=int(eval(input()))
X=list(range(N))
S=[eval(input())for _ in X]
d=[[1 if S[i][j]=='1'else(N if i^j else 0)for j in X]for i in X]
for k in X:
for i in X:
for j in X:d[i][j]=min(d[i][j],d[i][k]+d[k][j])
c=[0]*N
print((max(max(e)for e in d)+1 if b(0,1)else-1)) | 33 | 12 | 872 | 340 | import sys
input = sys.stdin.readline
def floyd_warshall(dist):
for k in range(N):
for i in range(N):
for j in range(N):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
def is_bipartite(u):
for v in range(N):
if u == v or dist[u][v] != 1:
continue
if color[v] == -1:
color[v] = 1 - color[u]
if not is_bipartite(v):
return False
elif color[u] == color[v]:
return False
return True
N = int(eval(input()))
S = [input().rstrip() for _ in range(N)]
dist = [
[1 if S[i][j] == "1" else (0 if i == j else float("inf")) for j in range(N)]
for i in range(N)
]
color = [-1] * N
color[0] = 0
ans = 0
if is_bipartite(0):
floyd_warshall(dist)
ans = max(max(d) for d in dist) + 1
else:
ans = -1
print(ans)
| def b(u, x):
c[u] = x
return all((c[u] != c[v]) & (c[v] or b(v, -x)) for v in X if d[u][v] == 1)
N = int(eval(input()))
X = list(range(N))
S = [eval(input()) for _ in X]
d = [[1 if S[i][j] == "1" else (N if i ^ j else 0) for j in X] for i in X]
for k in X:
for i in X:
for j in X:
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
c = [0] * N
print((max(max(e) for e in d) + 1 if b(0, 1) else -1))
| false | 63.636364 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-",
"-",
"-def floyd_warshall(dist):",
"- for k in range(N):",
"- for i in range(N):",
"- for j in range(N):",
"- dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])",
"-",
"-",
"-def is_bipartite(u):",
"- for v in range(N):",
"- if u == v or dist[u][v] != 1:",
"- continue",
"- if color[v] == -1:",
"- color[v] = 1 - color[u]",
"- if not is_bipartite(v):",
"- return False",
"- elif color[u] == color[v]:",
"- return False",
"- return True",
"+def b(u, x):",
"+ c[u] = x",
"+ return all((c[u] != c[v]) & (c[v] or b(v, -x)) for v in X if d[u][v] == 1)",
"-S = [input().rstrip() for _ in range(N)]",
"-dist = [",
"- [1 if S[i][j] == \"1\" else (0 if i == j else float(\"inf\")) for j in range(N)]",
"- for i in range(N)",
"-]",
"-color = [-1] * N",
"-color[0] = 0",
"-ans = 0",
"-if is_bipartite(0):",
"- floyd_warshall(dist)",
"- ans = max(max(d) for d in dist) + 1",
"-else:",
"- ans = -1",
"-print(ans)",
"+X = list(range(N))",
"+S = [eval(input()) for _ in X]",
"+d = [[1 if S[i][j] == \"1\" else (N if i ^ j else 0) for j in X] for i in X]",
"+for k in X:",
"+ for i in X:",
"+ for j in X:",
"+ d[i][j] = min(d[i][j], d[i][k] + d[k][j])",
"+c = [0] * N",
"+print((max(max(e) for e in d) + 1 if b(0, 1) else -1))"
] | false | 0.051662 | 0.105823 | 0.488196 | [
"s400140808",
"s516036523"
] |
u256678932 | p02397 | python | s849025391 | s840153579 | 60 | 50 | 5,608 | 5,608 | Accepted | Accepted | 16.67 | while True:
x, y = list(map(int, input().split()))
if x == y == 0:
break
if x <= y:
print(("{} {}".format(x, y)))
else:
print(("{} {}".format(y, x)))
| while True:
x, y = list(map(int, input().split()))
if x == y == 0:
break
if x <= y:
print((x, y))
else:
print((y, x))
| 11 | 11 | 193 | 161 | while True:
x, y = list(map(int, input().split()))
if x == y == 0:
break
if x <= y:
print(("{} {}".format(x, y)))
else:
print(("{} {}".format(y, x)))
| while True:
x, y = list(map(int, input().split()))
if x == y == 0:
break
if x <= y:
print((x, y))
else:
print((y, x))
| false | 0 | [
"- print((\"{} {}\".format(x, y)))",
"+ print((x, y))",
"- print((\"{} {}\".format(y, x)))",
"+ print((y, x))"
] | false | 0.038725 | 0.090807 | 0.426451 | [
"s849025391",
"s840153579"
] |
u802963389 | p03160 | python | s650985994 | s808165138 | 163 | 131 | 13,908 | 13,976 | Accepted | Accepted | 19.63 | n = int(eval(input()))
h = list(map(int, input().split()))
dp = [0] * n
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
dp[i] = min(dp[i - k] + abs(h[i]-h[i-k]) for k in [1, 2])
print((dp[-1])) | n = int(eval(input()))
H = list(map(int, input().split()))
dp = [10 ** 12] * (n)
dp[0] = 0
dp[1] = abs(H[1] - H[0])
for i in range(1, n-1):
dp[i+1] = min(dp[i] + abs(H[i+1] - H[i]), dp[i-1] + abs(H[i+1] - H[i-1]))
ans = dp[n-1]
print(ans) | 9 | 13 | 196 | 252 | n = int(eval(input()))
h = list(map(int, input().split()))
dp = [0] * n
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
dp[i] = min(dp[i - k] + abs(h[i] - h[i - k]) for k in [1, 2])
print((dp[-1]))
| n = int(eval(input()))
H = list(map(int, input().split()))
dp = [10**12] * (n)
dp[0] = 0
dp[1] = abs(H[1] - H[0])
for i in range(1, n - 1):
dp[i + 1] = min(dp[i] + abs(H[i + 1] - H[i]), dp[i - 1] + abs(H[i + 1] - H[i - 1]))
ans = dp[n - 1]
print(ans)
| false | 30.769231 | [
"-h = list(map(int, input().split()))",
"-dp = [0] * n",
"-dp[1] = abs(h[0] - h[1])",
"-for i in range(2, n):",
"- dp[i] = min(dp[i - k] + abs(h[i] - h[i - k]) for k in [1, 2])",
"-print((dp[-1]))",
"+H = list(map(int, input().split()))",
"+dp = [10**12] * (n)",
"+dp[0] = 0",
"+dp[1] = abs(H[1] - H[0])",
"+for i in range(1, n - 1):",
"+ dp[i + 1] = min(dp[i] + abs(H[i + 1] - H[i]), dp[i - 1] + abs(H[i + 1] - H[i - 1]))",
"+ans = dp[n - 1]",
"+print(ans)"
] | false | 0.106569 | 0.007052 | 15.111935 | [
"s650985994",
"s808165138"
] |
u380524497 | p02803 | python | s782166234 | s624568907 | 727 | 215 | 57,308 | 3,316 | Accepted | Accepted | 70.43 | import heapq
h, w = list(map(int, input().split()))
meiro = []
for i in range(h):
line = eval(input())
meiro.append(line)
def dfs(y, x):
dist = [[-1]*w for _ in range(h)]
if meiro[y][x] == '#':
return 0
dist[y][x] = 0
pattern = [[-1, 0], [1, 0], [0, -1], [0, 1]]
todo = []
for dy, dx in pattern:
ny, nx = y + dy, x + dx
if 0 <= ny <= h-1 and 0 <= nx <= w-1:
if meiro[ny][nx] == '.':
heapq.heappush(todo, [1, ny, nx])
while todo:
d, y, x = heapq.heappop(todo)
if meiro[y][x] == '#':
continue
if dist[y][x] != -1:
continue
dist[y][x] = d
for dy, dx in pattern:
ny, nx = y + dy, x + dx
if 0 <= ny <= h - 1 and 0 <= nx <= w - 1:
if dist[ny][nx] == -1 and meiro[ny][nx] == '.':
heapq.heappush(todo, [d+1, ny, nx])
res = 0
for line in dist:
res = max(max(line), res)
return res
ans = []
for y in range(h):
for x in range(w):
ans.append(dfs(y, x))
print((max(ans)))
| from collections import deque
h, w = list(map(int, input().split()))
graph = '#' * (w+2)
for _ in range(h):
line = '#' + eval(input()) + '#'
graph = graph + line
graph = graph + '#' * (w+2)
def bfs(x):
if graph[x] == '#':
return 0
seen = [-1] * ((h+2)*(w+2))
seen[x] = 0
pattern = [-(w+2), -1, 1, w+2]
todo = deque([])
for delta in pattern:
if graph[x+delta] == '.':
todo.append([x+delta, 1])
while todo:
node, dist = todo.popleft()
if seen[node] != -1:
continue
seen[node] = dist
for delta in pattern:
if graph[node+delta] == '.' and seen[node+delta] == -1:
todo.append([node+delta, dist+1])
return max(seen)
ans = []
for i in range((h+1)*(w+1)):
ans.append(bfs(i))
print((max(ans))) | 51 | 40 | 1,155 | 863 | import heapq
h, w = list(map(int, input().split()))
meiro = []
for i in range(h):
line = eval(input())
meiro.append(line)
def dfs(y, x):
dist = [[-1] * w for _ in range(h)]
if meiro[y][x] == "#":
return 0
dist[y][x] = 0
pattern = [[-1, 0], [1, 0], [0, -1], [0, 1]]
todo = []
for dy, dx in pattern:
ny, nx = y + dy, x + dx
if 0 <= ny <= h - 1 and 0 <= nx <= w - 1:
if meiro[ny][nx] == ".":
heapq.heappush(todo, [1, ny, nx])
while todo:
d, y, x = heapq.heappop(todo)
if meiro[y][x] == "#":
continue
if dist[y][x] != -1:
continue
dist[y][x] = d
for dy, dx in pattern:
ny, nx = y + dy, x + dx
if 0 <= ny <= h - 1 and 0 <= nx <= w - 1:
if dist[ny][nx] == -1 and meiro[ny][nx] == ".":
heapq.heappush(todo, [d + 1, ny, nx])
res = 0
for line in dist:
res = max(max(line), res)
return res
ans = []
for y in range(h):
for x in range(w):
ans.append(dfs(y, x))
print((max(ans)))
| from collections import deque
h, w = list(map(int, input().split()))
graph = "#" * (w + 2)
for _ in range(h):
line = "#" + eval(input()) + "#"
graph = graph + line
graph = graph + "#" * (w + 2)
def bfs(x):
if graph[x] == "#":
return 0
seen = [-1] * ((h + 2) * (w + 2))
seen[x] = 0
pattern = [-(w + 2), -1, 1, w + 2]
todo = deque([])
for delta in pattern:
if graph[x + delta] == ".":
todo.append([x + delta, 1])
while todo:
node, dist = todo.popleft()
if seen[node] != -1:
continue
seen[node] = dist
for delta in pattern:
if graph[node + delta] == "." and seen[node + delta] == -1:
todo.append([node + delta, dist + 1])
return max(seen)
ans = []
for i in range((h + 1) * (w + 1)):
ans.append(bfs(i))
print((max(ans)))
| false | 21.568627 | [
"-import heapq",
"+from collections import deque",
"-meiro = []",
"-for i in range(h):",
"- line = eval(input())",
"- meiro.append(line)",
"+graph = \"#\" * (w + 2)",
"+for _ in range(h):",
"+ line = \"#\" + eval(input()) + \"#\"",
"+ graph = graph + line",
"+graph = graph + \"#\" * (w + 2)",
"-def dfs(y, x):",
"- dist = [[-1] * w for _ in range(h)]",
"- if meiro[y][x] == \"#\":",
"+def bfs(x):",
"+ if graph[x] == \"#\":",
"- dist[y][x] = 0",
"- pattern = [[-1, 0], [1, 0], [0, -1], [0, 1]]",
"- todo = []",
"- for dy, dx in pattern:",
"- ny, nx = y + dy, x + dx",
"- if 0 <= ny <= h - 1 and 0 <= nx <= w - 1:",
"- if meiro[ny][nx] == \".\":",
"- heapq.heappush(todo, [1, ny, nx])",
"+ seen = [-1] * ((h + 2) * (w + 2))",
"+ seen[x] = 0",
"+ pattern = [-(w + 2), -1, 1, w + 2]",
"+ todo = deque([])",
"+ for delta in pattern:",
"+ if graph[x + delta] == \".\":",
"+ todo.append([x + delta, 1])",
"- d, y, x = heapq.heappop(todo)",
"- if meiro[y][x] == \"#\":",
"+ node, dist = todo.popleft()",
"+ if seen[node] != -1:",
"- if dist[y][x] != -1:",
"- continue",
"- dist[y][x] = d",
"- for dy, dx in pattern:",
"- ny, nx = y + dy, x + dx",
"- if 0 <= ny <= h - 1 and 0 <= nx <= w - 1:",
"- if dist[ny][nx] == -1 and meiro[ny][nx] == \".\":",
"- heapq.heappush(todo, [d + 1, ny, nx])",
"- res = 0",
"- for line in dist:",
"- res = max(max(line), res)",
"- return res",
"+ seen[node] = dist",
"+ for delta in pattern:",
"+ if graph[node + delta] == \".\" and seen[node + delta] == -1:",
"+ todo.append([node + delta, dist + 1])",
"+ return max(seen)",
"-for y in range(h):",
"- for x in range(w):",
"- ans.append(dfs(y, x))",
"+for i in range((h + 1) * (w + 1)):",
"+ ans.append(bfs(i))"
] | false | 0.078768 | 0.046491 | 1.694262 | [
"s782166234",
"s624568907"
] |
u745087332 | p03480 | python | s671946286 | s082477699 | 61 | 49 | 3,316 | 3,188 | Accepted | Accepted | 19.67 | s = eval(input())
n = len(s)
ans = n
for i, (c1, c2) in enumerate(zip(s[:-1], s[1:])):
if c1 == c2:
continue
ans = min(ans, max(i + 1, n - i - 1))
print(ans)
| s = eval(input())
n = len(s)
k = 0
tmp = set()
while k * 2 < n and len(tmp) < 2:
tmp.add(s[n // 2 + k])
tmp.add(s[(n - 1) // 2 - k])
k += 1
print((n // 2 + k - (len(tmp) == 2))) | 10 | 9 | 179 | 189 | s = eval(input())
n = len(s)
ans = n
for i, (c1, c2) in enumerate(zip(s[:-1], s[1:])):
if c1 == c2:
continue
ans = min(ans, max(i + 1, n - i - 1))
print(ans)
| s = eval(input())
n = len(s)
k = 0
tmp = set()
while k * 2 < n and len(tmp) < 2:
tmp.add(s[n // 2 + k])
tmp.add(s[(n - 1) // 2 - k])
k += 1
print((n // 2 + k - (len(tmp) == 2)))
| false | 10 | [
"-ans = n",
"-for i, (c1, c2) in enumerate(zip(s[:-1], s[1:])):",
"- if c1 == c2:",
"- continue",
"- ans = min(ans, max(i + 1, n - i - 1))",
"-print(ans)",
"+k = 0",
"+tmp = set()",
"+while k * 2 < n and len(tmp) < 2:",
"+ tmp.add(s[n // 2 + k])",
"+ tmp.add(s[(n - 1) // 2 - k])",
"+ k += 1",
"+print((n // 2 + k - (len(tmp) == 2)))"
] | false | 0.043935 | 0.039253 | 1.119277 | [
"s671946286",
"s082477699"
] |
u484229314 | p03575 | python | s918802741 | s695240194 | 730 | 25 | 47,580 | 3,188 | Accepted | Accepted | 96.58 | N, M = [int(_) for _ in input().split()]
paths = [[0] * (N + 1) for _ in range(N + 1)]
def has_path(c, t, arrived):
if c == t: return True
for i in range(1, N + 1):
if i in arrived: continue
if paths[c][i]:
arrived.append(i)
if has_path(i, t, arrived):
return True
arrived.pop()
return False
edge = []
for i in range(M):
a, b = [int(_) for _ in input().split()]
paths[a][b] = 1
paths[b][a] = 1
edge.append((a, b,))
ans = 0
for e in edge:
paths[e[0]][e[1]] = 0
paths[e[1]][e[0]] = 0
if not has_path(e[0], e[1], []):
ans += 1
paths[e[0]][e[1]] = 1
paths[e[1]][e[0]] = 1
print(ans) | N, M = [int(_) for _ in input().split()]
paths = [[0] * (N + 1) for _ in range(N + 1)]
edges = []
for i in range(M):
a, b = [int(_) for _ in input().split()]
paths[a][b] = 1
paths[b][a] = 1
edges.append((a, b))
class UF:
def __init__(self, v):
self.parent = None
self.val = v
@property
def root(self):
if not self.parent:
return self
return self.parent.root
def __str__(self):
if self.parent:
return str(self.val) + ' ' + str(self.parent.val)
return str(self.val) + ' None'
def merge(u1, u2):
r1 = u1.root
r2 = u2.root
if r1 == r2:
return
r1.parent = r2
def chk(a, b):
nodes = [UF(i) for i in range(N + 1)]
for i in range(1, N):
for j in range(i + 1, N + 1):
if paths[i][j]:
merge(nodes[i], nodes[j])
return int(nodes[a].root != nodes[b].root)
ans = 0
for e in edges:
paths[e[0]][e[1]] = 0
paths[e[1]][e[0]] = 0
ans += chk(e[0], e[1])
paths[e[0]][e[1]] = 1
paths[e[1]][e[0]] = 1
print(ans) | 33 | 54 | 740 | 1,150 | N, M = [int(_) for _ in input().split()]
paths = [[0] * (N + 1) for _ in range(N + 1)]
def has_path(c, t, arrived):
if c == t:
return True
for i in range(1, N + 1):
if i in arrived:
continue
if paths[c][i]:
arrived.append(i)
if has_path(i, t, arrived):
return True
arrived.pop()
return False
edge = []
for i in range(M):
a, b = [int(_) for _ in input().split()]
paths[a][b] = 1
paths[b][a] = 1
edge.append(
(
a,
b,
)
)
ans = 0
for e in edge:
paths[e[0]][e[1]] = 0
paths[e[1]][e[0]] = 0
if not has_path(e[0], e[1], []):
ans += 1
paths[e[0]][e[1]] = 1
paths[e[1]][e[0]] = 1
print(ans)
| N, M = [int(_) for _ in input().split()]
paths = [[0] * (N + 1) for _ in range(N + 1)]
edges = []
for i in range(M):
a, b = [int(_) for _ in input().split()]
paths[a][b] = 1
paths[b][a] = 1
edges.append((a, b))
class UF:
def __init__(self, v):
self.parent = None
self.val = v
@property
def root(self):
if not self.parent:
return self
return self.parent.root
def __str__(self):
if self.parent:
return str(self.val) + " " + str(self.parent.val)
return str(self.val) + " None"
def merge(u1, u2):
r1 = u1.root
r2 = u2.root
if r1 == r2:
return
r1.parent = r2
def chk(a, b):
nodes = [UF(i) for i in range(N + 1)]
for i in range(1, N):
for j in range(i + 1, N + 1):
if paths[i][j]:
merge(nodes[i], nodes[j])
return int(nodes[a].root != nodes[b].root)
ans = 0
for e in edges:
paths[e[0]][e[1]] = 0
paths[e[1]][e[0]] = 0
ans += chk(e[0], e[1])
paths[e[0]][e[1]] = 1
paths[e[1]][e[0]] = 1
print(ans)
| false | 38.888889 | [
"-",
"-",
"-def has_path(c, t, arrived):",
"- if c == t:",
"- return True",
"- for i in range(1, N + 1):",
"- if i in arrived:",
"- continue",
"- if paths[c][i]:",
"- arrived.append(i)",
"- if has_path(i, t, arrived):",
"- return True",
"- arrived.pop()",
"- return False",
"-",
"-",
"-edge = []",
"+edges = []",
"- edge.append(",
"- (",
"- a,",
"- b,",
"- )",
"- )",
"+ edges.append((a, b))",
"+",
"+",
"+class UF:",
"+ def __init__(self, v):",
"+ self.parent = None",
"+ self.val = v",
"+",
"+ @property",
"+ def root(self):",
"+ if not self.parent:",
"+ return self",
"+ return self.parent.root",
"+",
"+ def __str__(self):",
"+ if self.parent:",
"+ return str(self.val) + \" \" + str(self.parent.val)",
"+ return str(self.val) + \" None\"",
"+",
"+",
"+def merge(u1, u2):",
"+ r1 = u1.root",
"+ r2 = u2.root",
"+ if r1 == r2:",
"+ return",
"+ r1.parent = r2",
"+",
"+",
"+def chk(a, b):",
"+ nodes = [UF(i) for i in range(N + 1)]",
"+ for i in range(1, N):",
"+ for j in range(i + 1, N + 1):",
"+ if paths[i][j]:",
"+ merge(nodes[i], nodes[j])",
"+ return int(nodes[a].root != nodes[b].root)",
"+",
"+",
"-for e in edge:",
"+for e in edges:",
"- if not has_path(e[0], e[1], []):",
"- ans += 1",
"+ ans += chk(e[0], e[1])"
] | false | 0.040617 | 0.03454 | 1.175948 | [
"s918802741",
"s695240194"
] |
u923573620 | p00003 | python | s901631192 | s352834469 | 50 | 40 | 5,664 | 5,676 | Accepted | Accepted | 20 | import math
N = int(eval(input()))
for i in range(N):
side_len = list(map(int, input().split(" ")))
side_len.sort()
if int(math.pow(side_len[0], 2)) + int(math.pow(side_len[1], 2)) == int(math.pow(side_len[2], 2)):
print("YES")
else:
print("NO")
| import math
num = int(eval(input()))
for i in range(num):
try:
sides = list(map(int, input().split(" ")))
sides.sort()
if int(math.pow(sides[0], 2)) + int(math.pow(sides[1], 2)) == int(math.pow(sides[2], 2)):
print("YES")
else:
print("NO")
except:
break
| 11 | 16 | 268 | 339 | import math
N = int(eval(input()))
for i in range(N):
side_len = list(map(int, input().split(" ")))
side_len.sort()
if int(math.pow(side_len[0], 2)) + int(math.pow(side_len[1], 2)) == int(
math.pow(side_len[2], 2)
):
print("YES")
else:
print("NO")
| import math
num = int(eval(input()))
for i in range(num):
try:
sides = list(map(int, input().split(" ")))
sides.sort()
if int(math.pow(sides[0], 2)) + int(math.pow(sides[1], 2)) == int(
math.pow(sides[2], 2)
):
print("YES")
else:
print("NO")
except:
break
| false | 31.25 | [
"-N = int(eval(input()))",
"-for i in range(N):",
"- side_len = list(map(int, input().split(\" \")))",
"- side_len.sort()",
"- if int(math.pow(side_len[0], 2)) + int(math.pow(side_len[1], 2)) == int(",
"- math.pow(side_len[2], 2)",
"- ):",
"- print(\"YES\")",
"- else:",
"- print(\"NO\")",
"+num = int(eval(input()))",
"+for i in range(num):",
"+ try:",
"+ sides = list(map(int, input().split(\" \")))",
"+ sides.sort()",
"+ if int(math.pow(sides[0], 2)) + int(math.pow(sides[1], 2)) == int(",
"+ math.pow(sides[2], 2)",
"+ ):",
"+ print(\"YES\")",
"+ else:",
"+ print(\"NO\")",
"+ except:",
"+ break"
] | false | 0.043133 | 0.047343 | 0.911088 | [
"s901631192",
"s352834469"
] |
u886747123 | p02838 | python | s229104728 | s719506124 | 1,291 | 1,052 | 122,808 | 122,928 | Accepted | Accepted | 18.51 | N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
bit = [0] * 61
for i in range(N):
for x in range(61):
if 2**x > A[i]:
break
elif (1<<x) & A[i] > 0:
bit[x] += 1
ans = 0
for i in range(61):
ans += 2**i * (bit[i] * (N-bit[i]))
ans %= MOD
print(ans) | N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
bit = [0] * 61
for i in range(N):
for x in range(61):
if 2**x > A[i]:
break
else:
bit[x] += (A[i]>>x)&1
ans = 0
for i in range(61):
ans += 2**i * (bit[i] * (N-bit[i]))
ans %= MOD
print(ans) | 18 | 18 | 338 | 330 | N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
bit = [0] * 61
for i in range(N):
for x in range(61):
if 2**x > A[i]:
break
elif (1 << x) & A[i] > 0:
bit[x] += 1
ans = 0
for i in range(61):
ans += 2**i * (bit[i] * (N - bit[i]))
ans %= MOD
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
bit = [0] * 61
for i in range(N):
for x in range(61):
if 2**x > A[i]:
break
else:
bit[x] += (A[i] >> x) & 1
ans = 0
for i in range(61):
ans += 2**i * (bit[i] * (N - bit[i]))
ans %= MOD
print(ans)
| false | 0 | [
"- elif (1 << x) & A[i] > 0:",
"- bit[x] += 1",
"+ else:",
"+ bit[x] += (A[i] >> x) & 1"
] | false | 0.038256 | 0.038146 | 1.002883 | [
"s229104728",
"s719506124"
] |
u038024401 | p03162 | python | s916697496 | s869133987 | 725 | 521 | 42,572 | 42,572 | Accepted | Accepted | 28.14 | N = int(eval(input()))
ABC = [[None]*3 for i in range(N)]
for i in range(N):
ABC[i][0], ABC[i][1], ABC[i][2] = list(map(int, input().split()))
happiness = [[0] *3 for i in range(N+1)]
for i in range(N):
for j in range(3):
happiness[i+1][j] = max(happiness[i][j-1] + ABC[i][j], happiness[i][j-2] + ABC[i][j])
print((max(happiness[N]))) | import sys
N = int(sys.stdin.readline())
ABC = [[None]*3 for i in range(N)]
for i in range(N):
ABC[i][0], ABC[i][1], ABC[i][2] = list(map(int, sys.stdin.readline().split()))
happiness = [[0] *3 for i in range(N+1)]
for i in range(N):
for j in range(3):
happiness[i+1][j] = max(happiness[i][j-1] + ABC[i][j], happiness[i][j-2] + ABC[i][j])
print((max(happiness[N]))) | 13 | 15 | 352 | 392 | N = int(eval(input()))
ABC = [[None] * 3 for i in range(N)]
for i in range(N):
ABC[i][0], ABC[i][1], ABC[i][2] = list(map(int, input().split()))
happiness = [[0] * 3 for i in range(N + 1)]
for i in range(N):
for j in range(3):
happiness[i + 1][j] = max(
happiness[i][j - 1] + ABC[i][j], happiness[i][j - 2] + ABC[i][j]
)
print((max(happiness[N])))
| import sys
N = int(sys.stdin.readline())
ABC = [[None] * 3 for i in range(N)]
for i in range(N):
ABC[i][0], ABC[i][1], ABC[i][2] = list(map(int, sys.stdin.readline().split()))
happiness = [[0] * 3 for i in range(N + 1)]
for i in range(N):
for j in range(3):
happiness[i + 1][j] = max(
happiness[i][j - 1] + ABC[i][j], happiness[i][j - 2] + ABC[i][j]
)
print((max(happiness[N])))
| false | 13.333333 | [
"-N = int(eval(input()))",
"+import sys",
"+",
"+N = int(sys.stdin.readline())",
"- ABC[i][0], ABC[i][1], ABC[i][2] = list(map(int, input().split()))",
"+ ABC[i][0], ABC[i][1], ABC[i][2] = list(map(int, sys.stdin.readline().split()))"
] | false | 0.094592 | 0.048094 | 1.966807 | [
"s916697496",
"s869133987"
] |
u760794812 | p03168 | python | s901886280 | s674359827 | 1,767 | 138 | 27,804 | 27,428 | Accepted | Accepted | 92.19 | import numpy as np
n= int(eval(input()))
ppp = list(map(float,input().split()))
dp = [0]*(n+1)
dp[0]=1
for p in ppp:
ndp = [item*(1-p) for item in dp]
ndp = [ndp[i] if i == 0 else ndp[i]+dp[i-1]*p for i in range(n+1)]
dp = ndp
print((sum(dp[n//2+1:]))) | import numpy as np
n= int(eval(input()))
ppp = list(map(float,input().split()))
dp = np.array([0.0]*(n+1),dtype=np.float64)
dp[0]=1
for p in ppp:
ndp = dp*(1-p)
ndp[1:] += dp[:-1]*p
dp = ndp
print((sum(dp[n//2+1:]))) | 10 | 10 | 259 | 223 | import numpy as np
n = int(eval(input()))
ppp = list(map(float, input().split()))
dp = [0] * (n + 1)
dp[0] = 1
for p in ppp:
ndp = [item * (1 - p) for item in dp]
ndp = [ndp[i] if i == 0 else ndp[i] + dp[i - 1] * p for i in range(n + 1)]
dp = ndp
print((sum(dp[n // 2 + 1 :])))
| import numpy as np
n = int(eval(input()))
ppp = list(map(float, input().split()))
dp = np.array([0.0] * (n + 1), dtype=np.float64)
dp[0] = 1
for p in ppp:
ndp = dp * (1 - p)
ndp[1:] += dp[:-1] * p
dp = ndp
print((sum(dp[n // 2 + 1 :])))
| false | 0 | [
"-dp = [0] * (n + 1)",
"+dp = np.array([0.0] * (n + 1), dtype=np.float64)",
"- ndp = [item * (1 - p) for item in dp]",
"- ndp = [ndp[i] if i == 0 else ndp[i] + dp[i - 1] * p for i in range(n + 1)]",
"+ ndp = dp * (1 - p)",
"+ ndp[1:] += dp[:-1] * p"
] | false | 0.07617 | 0.214168 | 0.355657 | [
"s901886280",
"s674359827"
] |
u707498674 | p03197 | python | s830883393 | s897143120 | 379 | 161 | 22,016 | 14,548 | Accepted | Accepted | 57.52 | import numpy as np
def main():
stdin = np.fromstring(open(0).read(), dtype=np.int32, sep=' ')
N = stdin[0]
A = stdin[1:]
A = np.mod(A, 2)
print("first") if np.count_nonzero(A) else print("second")
if __name__ == "__main__":
main()
| import numpy as np
def main():
stdin = np.fromstring(open(0).read(), dtype=np.int64, sep=' ')
A = stdin[1:]
A = np.mod(A, 2)
print("first") if np.count_nonzero(A) else print("second")
if __name__ == "__main__":
main()
| 10 | 9 | 264 | 248 | import numpy as np
def main():
stdin = np.fromstring(open(0).read(), dtype=np.int32, sep=" ")
N = stdin[0]
A = stdin[1:]
A = np.mod(A, 2)
print("first") if np.count_nonzero(A) else print("second")
if __name__ == "__main__":
main()
| import numpy as np
def main():
stdin = np.fromstring(open(0).read(), dtype=np.int64, sep=" ")
A = stdin[1:]
A = np.mod(A, 2)
print("first") if np.count_nonzero(A) else print("second")
if __name__ == "__main__":
main()
| false | 10 | [
"- stdin = np.fromstring(open(0).read(), dtype=np.int32, sep=\" \")",
"- N = stdin[0]",
"+ stdin = np.fromstring(open(0).read(), dtype=np.int64, sep=\" \")"
] | false | 0.201054 | 0.203597 | 0.98751 | [
"s830883393",
"s897143120"
] |
u493520238 | p03252 | python | s307564589 | s297369820 | 194 | 75 | 41,968 | 74,008 | Accepted | Accepted | 61.34 | s = eval(input())
t = eval(input())
s_d = {}
t_d = {}
for i in range(len(s)):
if s[i] not in s_d:
new_num = len(s_d)+1
s_d[s[i]] = new_num
s_valid = -1
else:
s_valid = s_d[s[i]]
if t[i] not in t_d:
new_num = len(t_d)+1
t_d[t[i]] = new_num
t_valid = -1
else:
t_valid = t_d[t[i]]
if s_valid != t_valid:
print('No')
break
else:
print('Yes') | s = eval(input())
t = eval(input())
d = {}
for si,ti in zip(s,t):
if not si in d:
d[si] = ti
else:
if d[si] != ti:
print('No')
break
else:
sset = set()
for v in list(d.values()):
if v in sset:
print('No')
break
sset.add(v)
else:
print('Yes') | 26 | 20 | 458 | 351 | s = eval(input())
t = eval(input())
s_d = {}
t_d = {}
for i in range(len(s)):
if s[i] not in s_d:
new_num = len(s_d) + 1
s_d[s[i]] = new_num
s_valid = -1
else:
s_valid = s_d[s[i]]
if t[i] not in t_d:
new_num = len(t_d) + 1
t_d[t[i]] = new_num
t_valid = -1
else:
t_valid = t_d[t[i]]
if s_valid != t_valid:
print("No")
break
else:
print("Yes")
| s = eval(input())
t = eval(input())
d = {}
for si, ti in zip(s, t):
if not si in d:
d[si] = ti
else:
if d[si] != ti:
print("No")
break
else:
sset = set()
for v in list(d.values()):
if v in sset:
print("No")
break
sset.add(v)
else:
print("Yes")
| false | 23.076923 | [
"-s_d = {}",
"-t_d = {}",
"-for i in range(len(s)):",
"- if s[i] not in s_d:",
"- new_num = len(s_d) + 1",
"- s_d[s[i]] = new_num",
"- s_valid = -1",
"+d = {}",
"+for si, ti in zip(s, t):",
"+ if not si in d:",
"+ d[si] = ti",
"- s_valid = s_d[s[i]]",
"- if t[i] not in t_d:",
"- new_num = len(t_d) + 1",
"- t_d[t[i]] = new_num",
"- t_valid = -1",
"+ if d[si] != ti:",
"+ print(\"No\")",
"+ break",
"+else:",
"+ sset = set()",
"+ for v in list(d.values()):",
"+ if v in sset:",
"+ print(\"No\")",
"+ break",
"+ sset.add(v)",
"- t_valid = t_d[t[i]]",
"- if s_valid != t_valid:",
"- print(\"No\")",
"- break",
"-else:",
"- print(\"Yes\")",
"+ print(\"Yes\")"
] | false | 0.037467 | 0.043379 | 0.86372 | [
"s307564589",
"s297369820"
] |
u163320134 | p03612 | python | s847003248 | s479466185 | 80 | 73 | 14,008 | 14,008 | Accepted | Accepted | 8.75 | n=int(eval(input()))
arr=list(map(int,input().split()))
ans=0
for i in range(n-2):
if arr[i]==i+1:
arr[i],arr[i+1]=arr[i+1],arr[i]
ans+=1
elif arr[i+1]==i+1:
arr[i+1],arr[i+2]=arr[i+2],arr[i+1]
if arr[-1]==n or arr[-2]==n-1:
ans+=1
print(ans)
| n=int(eval(input()))
arr=list(map(int,input().split()))
ans=0
for i in range(n-1,-1,-1):
if arr[i]==i+1:
arr[i],arr[i-1]=arr[i-1],arr[i]
ans+=1
print(ans) | 12 | 8 | 266 | 165 | n = int(eval(input()))
arr = list(map(int, input().split()))
ans = 0
for i in range(n - 2):
if arr[i] == i + 1:
arr[i], arr[i + 1] = arr[i + 1], arr[i]
ans += 1
elif arr[i + 1] == i + 1:
arr[i + 1], arr[i + 2] = arr[i + 2], arr[i + 1]
if arr[-1] == n or arr[-2] == n - 1:
ans += 1
print(ans)
| n = int(eval(input()))
arr = list(map(int, input().split()))
ans = 0
for i in range(n - 1, -1, -1):
if arr[i] == i + 1:
arr[i], arr[i - 1] = arr[i - 1], arr[i]
ans += 1
print(ans)
| false | 33.333333 | [
"-for i in range(n - 2):",
"+for i in range(n - 1, -1, -1):",
"- arr[i], arr[i + 1] = arr[i + 1], arr[i]",
"+ arr[i], arr[i - 1] = arr[i - 1], arr[i]",
"- elif arr[i + 1] == i + 1:",
"- arr[i + 1], arr[i + 2] = arr[i + 2], arr[i + 1]",
"-if arr[-1] == n or arr[-2] == n - 1:",
"- ans += 1"
] | false | 0.043929 | 0.043676 | 1.005777 | [
"s847003248",
"s479466185"
] |
u977193988 | p03018 | python | s593128942 | s916500707 | 81 | 35 | 11,368 | 3,500 | Accepted | Accepted | 56.79 | import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
def main():
S = eval(input())
S = S.replace("BC", "X")
S = S.replace("C", "B")
S = S.split("B")
answer = 0
for s in S:
place = []
c = 0
n = len(s)
for i in range(n):
if s[i] == "A":
c += 1
place.append(i + 1)
for p in place:
c -= 1
answer += n - c - p
print(answer)
if __name__ == "__main__":
main()
| import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
def main():
S = eval(input())
S = S.replace("BC", "X")
cnt_a = 0
answer = 0
for s in S:
if s == "A":
cnt_a += 1
elif s == "X":
answer += cnt_a
else:
cnt_a = 0
print(answer)
if __name__ == "__main__":
main()
| 32 | 27 | 568 | 418 | import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10**9)
def main():
S = eval(input())
S = S.replace("BC", "X")
S = S.replace("C", "B")
S = S.split("B")
answer = 0
for s in S:
place = []
c = 0
n = len(s)
for i in range(n):
if s[i] == "A":
c += 1
place.append(i + 1)
for p in place:
c -= 1
answer += n - c - p
print(answer)
if __name__ == "__main__":
main()
| import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10**9)
def main():
S = eval(input())
S = S.replace("BC", "X")
cnt_a = 0
answer = 0
for s in S:
if s == "A":
cnt_a += 1
elif s == "X":
answer += cnt_a
else:
cnt_a = 0
print(answer)
if __name__ == "__main__":
main()
| false | 15.625 | [
"- S = S.replace(\"C\", \"B\")",
"- S = S.split(\"B\")",
"+ cnt_a = 0",
"- place = []",
"- c = 0",
"- n = len(s)",
"- for i in range(n):",
"- if s[i] == \"A\":",
"- c += 1",
"- place.append(i + 1)",
"- for p in place:",
"- c -= 1",
"- answer += n - c - p",
"+ if s == \"A\":",
"+ cnt_a += 1",
"+ elif s == \"X\":",
"+ answer += cnt_a",
"+ else:",
"+ cnt_a = 0"
] | false | 0.040974 | 0.038594 | 1.061671 | [
"s593128942",
"s916500707"
] |
u683134447 | p02947 | python | s440983734 | s094217115 | 1,799 | 1,059 | 101,848 | 117,508 | Accepted | Accepted | 41.13 | # coding: utf-8
# Your code here!
import collections
n = int(eval(input()))
sl = []
for _ in range(n):
s = sorted(list(eval(input())))
sl.append(s)
before_s = ""
ans = 0
point = 1
for i in sorted(sl):
if i == before_s:
point += 1
else:
before_s = i
ans += int(point * (point - 1) / 2)
point = 1
ans += int(point * (point - 1) / 2)
print(ans)
| n = int(eval(input()))
from collections import defaultdict
dic = defaultdict(int)
for _ in range(n):
s = list(eval(input()))
s = tuple(sorted(s))
dic[s] += 1
ans = 0
for s in dic:
ans += dic[s] * (dic[s] - 1) // 2
print(ans)
| 24 | 18 | 409 | 253 | # coding: utf-8
# Your code here!
import collections
n = int(eval(input()))
sl = []
for _ in range(n):
s = sorted(list(eval(input())))
sl.append(s)
before_s = ""
ans = 0
point = 1
for i in sorted(sl):
if i == before_s:
point += 1
else:
before_s = i
ans += int(point * (point - 1) / 2)
point = 1
ans += int(point * (point - 1) / 2)
print(ans)
| n = int(eval(input()))
from collections import defaultdict
dic = defaultdict(int)
for _ in range(n):
s = list(eval(input()))
s = tuple(sorted(s))
dic[s] += 1
ans = 0
for s in dic:
ans += dic[s] * (dic[s] - 1) // 2
print(ans)
| false | 25 | [
"-# coding: utf-8",
"-# Your code here!",
"-import collections",
"+n = int(eval(input()))",
"+from collections import defaultdict",
"-n = int(eval(input()))",
"-sl = []",
"+dic = defaultdict(int)",
"- s = sorted(list(eval(input())))",
"- sl.append(s)",
"-before_s = \"\"",
"+ s = list(eval(input()))",
"+ s = tuple(sorted(s))",
"+ dic[s] += 1",
"-point = 1",
"-for i in sorted(sl):",
"- if i == before_s:",
"- point += 1",
"- else:",
"- before_s = i",
"- ans += int(point * (point - 1) / 2)",
"- point = 1",
"-ans += int(point * (point - 1) / 2)",
"+for s in dic:",
"+ ans += dic[s] * (dic[s] - 1) // 2"
] | false | 0.036934 | 0.034879 | 1.058907 | [
"s440983734",
"s094217115"
] |
u057109575 | p03074 | python | s594607439 | s847679107 | 227 | 159 | 59,000 | 88,104 | Accepted | Accepted | 29.96 | N, K = list(map(int, input().split()))
S = eval(input())
que = [(S[0], 0)]
cur = S[0]
for i in range(1, N):
if cur != S[i]:
que.append((S[i], i))
cur = S[i]
ans = []
LEN = len(que)
for i in range(LEN):
if que[i][0] == '0':
if i + 2 * K < LEN:
ans.append(que[i + 2 * K][1] - que[i][1])
else:
ans.append(N - que[i][1])
else:
if i + 2 * K + 1 < LEN:
ans.append(que[i + 2 * K + 1][1] - que[i][1])
else:
ans.append(N - que[i][1])
print((max(ans)))
|
N, K = list(map(int, input().split()))
S = eval(input())
q = [(S[0], 0)]
cur = S[0]
for i in range(1, N):
if S[i] != cur:
q.append((S[i], i))
cur = S[i]
lim = len(q)
ans = []
for i in range(lim):
if q[i][0] == "0":
j = i + 2 * K
else:
j = i + 2 * K + 1
if j < lim:
ans.append(q[j][1] - q[i][1])
else:
ans.append(N - q[i][1])
print((max(ans)))
| 25 | 25 | 576 | 426 | N, K = list(map(int, input().split()))
S = eval(input())
que = [(S[0], 0)]
cur = S[0]
for i in range(1, N):
if cur != S[i]:
que.append((S[i], i))
cur = S[i]
ans = []
LEN = len(que)
for i in range(LEN):
if que[i][0] == "0":
if i + 2 * K < LEN:
ans.append(que[i + 2 * K][1] - que[i][1])
else:
ans.append(N - que[i][1])
else:
if i + 2 * K + 1 < LEN:
ans.append(que[i + 2 * K + 1][1] - que[i][1])
else:
ans.append(N - que[i][1])
print((max(ans)))
| N, K = list(map(int, input().split()))
S = eval(input())
q = [(S[0], 0)]
cur = S[0]
for i in range(1, N):
if S[i] != cur:
q.append((S[i], i))
cur = S[i]
lim = len(q)
ans = []
for i in range(lim):
if q[i][0] == "0":
j = i + 2 * K
else:
j = i + 2 * K + 1
if j < lim:
ans.append(q[j][1] - q[i][1])
else:
ans.append(N - q[i][1])
print((max(ans)))
| false | 0 | [
"-que = [(S[0], 0)]",
"+q = [(S[0], 0)]",
"- if cur != S[i]:",
"- que.append((S[i], i))",
"+ if S[i] != cur:",
"+ q.append((S[i], i))",
"+lim = len(q)",
"-LEN = len(que)",
"-for i in range(LEN):",
"- if que[i][0] == \"0\":",
"- if i + 2 * K < LEN:",
"- ans.append(que[i + 2 * K][1] - que[i][1])",
"- else:",
"- ans.append(N - que[i][1])",
"+for i in range(lim):",
"+ if q[i][0] == \"0\":",
"+ j = i + 2 * K",
"- if i + 2 * K + 1 < LEN:",
"- ans.append(que[i + 2 * K + 1][1] - que[i][1])",
"- else:",
"- ans.append(N - que[i][1])",
"+ j = i + 2 * K + 1",
"+ if j < lim:",
"+ ans.append(q[j][1] - q[i][1])",
"+ else:",
"+ ans.append(N - q[i][1])"
] | false | 0.047343 | 0.047135 | 1.004427 | [
"s594607439",
"s847679107"
] |
u130900604 | p02639 | python | s977751089 | s604539562 | 64 | 24 | 61,644 | 9,052 | Accepted | Accepted | 62.5 | x=list(map(int,input().split()))
print((x.index(0)+1)) | print((15-sum(map(int,input().split())))) | 2 | 1 | 53 | 39 | x = list(map(int, input().split()))
print((x.index(0) + 1))
| print((15 - sum(map(int, input().split()))))
| false | 50 | [
"-x = list(map(int, input().split()))",
"-print((x.index(0) + 1))",
"+print((15 - sum(map(int, input().split()))))"
] | false | 0.045378 | 0.047068 | 0.964094 | [
"s977751089",
"s604539562"
] |
u562016607 | p04016 | python | s471641011 | s426551007 | 292 | 261 | 3,064 | 3,064 | Accepted | Accepted | 10.62 | import math
def f(b,n):
if n<b:
return n
else:
return f(b,n//b)+(n%b)
N=int(eval(input()))
S=int(eval(input()))
if N==S:
print((N+1))
else:
for b in range(2,int(math.sqrt(N))+2):
if f(b,N)==S:
print(b)
exit()
ans=10**13
for p in range(1,int(math.sqrt(N))+2):
if (N-S)%p!=0:
continue
b=(N-S)//p+1
if b<=1:
continue
if f(b,N)==S:
ans=b
if ans==10**13:
print((-1))
else:
print(ans)
| import math
n=int(eval(input()))
s=int(eval(input()))
def f(b,n):
if n<b:
return n
else:
return f(b,n//b)+(n%b)
def abc(N,S):
if N==S:
return N+1
else:
for b in range(2,int(math.sqrt(N))+2):
if f(b,N)==S:
return b
tmp=-1
for p in range(1,int(math.sqrt(N))+2):
if (N-S)%p!=0:
continue
b=(N-S)//p+1
if b<=1:
continue
if f(b,N)==S:
tmp=b
return tmp
ans=abc(n,s)
print(ans) | 29 | 30 | 556 | 585 | import math
def f(b, n):
if n < b:
return n
else:
return f(b, n // b) + (n % b)
N = int(eval(input()))
S = int(eval(input()))
if N == S:
print((N + 1))
else:
for b in range(2, int(math.sqrt(N)) + 2):
if f(b, N) == S:
print(b)
exit()
ans = 10**13
for p in range(1, int(math.sqrt(N)) + 2):
if (N - S) % p != 0:
continue
b = (N - S) // p + 1
if b <= 1:
continue
if f(b, N) == S:
ans = b
if ans == 10**13:
print((-1))
else:
print(ans)
| import math
n = int(eval(input()))
s = int(eval(input()))
def f(b, n):
if n < b:
return n
else:
return f(b, n // b) + (n % b)
def abc(N, S):
if N == S:
return N + 1
else:
for b in range(2, int(math.sqrt(N)) + 2):
if f(b, N) == S:
return b
tmp = -1
for p in range(1, int(math.sqrt(N)) + 2):
if (N - S) % p != 0:
continue
b = (N - S) // p + 1
if b <= 1:
continue
if f(b, N) == S:
tmp = b
return tmp
ans = abc(n, s)
print(ans)
| false | 3.333333 | [
"+",
"+n = int(eval(input()))",
"+s = int(eval(input()))",
"-N = int(eval(input()))",
"-S = int(eval(input()))",
"-if N == S:",
"- print((N + 1))",
"-else:",
"- for b in range(2, int(math.sqrt(N)) + 2):",
"- if f(b, N) == S:",
"- print(b)",
"- exit()",
"- ans = 10**13",
"- for p in range(1, int(math.sqrt(N)) + 2):",
"- if (N - S) % p != 0:",
"- continue",
"- b = (N - S) // p + 1",
"- if b <= 1:",
"- continue",
"- if f(b, N) == S:",
"- ans = b",
"- if ans == 10**13:",
"- print((-1))",
"+def abc(N, S):",
"+ if N == S:",
"+ return N + 1",
"- print(ans)",
"+ for b in range(2, int(math.sqrt(N)) + 2):",
"+ if f(b, N) == S:",
"+ return b",
"+ tmp = -1",
"+ for p in range(1, int(math.sqrt(N)) + 2):",
"+ if (N - S) % p != 0:",
"+ continue",
"+ b = (N - S) // p + 1",
"+ if b <= 1:",
"+ continue",
"+ if f(b, N) == S:",
"+ tmp = b",
"+ return tmp",
"+",
"+",
"+ans = abc(n, s)",
"+print(ans)"
] | false | 0.046102 | 0.049027 | 0.940335 | [
"s471641011",
"s426551007"
] |
u305366205 | p03018 | python | s029415347 | s148760094 | 106 | 47 | 3,500 | 3,500 | Accepted | Accepted | 55.66 | s = eval(input())
cnt = 0
ans = 0
flag = False
for i in range(len(s) - 1):
if flag:
flag = False
continue
if s[i: i + 2] == 'BC':
ans += cnt
flag = True
elif s[i] == 'A':
cnt += 1
else:
cnt = 0
print(ans) | s = input().replace('BC', 'D')
cnt = 0
ans = 0
for c in s:
if c == 'A':
cnt += 1
elif c == 'D':
ans += cnt
else:
cnt = 0
print(ans) | 16 | 11 | 277 | 177 | s = eval(input())
cnt = 0
ans = 0
flag = False
for i in range(len(s) - 1):
if flag:
flag = False
continue
if s[i : i + 2] == "BC":
ans += cnt
flag = True
elif s[i] == "A":
cnt += 1
else:
cnt = 0
print(ans)
| s = input().replace("BC", "D")
cnt = 0
ans = 0
for c in s:
if c == "A":
cnt += 1
elif c == "D":
ans += cnt
else:
cnt = 0
print(ans)
| false | 31.25 | [
"-s = eval(input())",
"+s = input().replace(\"BC\", \"D\")",
"-flag = False",
"-for i in range(len(s) - 1):",
"- if flag:",
"- flag = False",
"- continue",
"- if s[i : i + 2] == \"BC\":",
"+for c in s:",
"+ if c == \"A\":",
"+ cnt += 1",
"+ elif c == \"D\":",
"- flag = True",
"- elif s[i] == \"A\":",
"- cnt += 1"
] | false | 0.037476 | 0.064751 | 0.578766 | [
"s029415347",
"s148760094"
] |
u761320129 | p03157 | python | s106499877 | s082441306 | 914 | 586 | 22,248 | 35,504 | Accepted | Accepted | 35.89 | from collections import Counter
H,W = list(map(int,input().split()))
S = [eval(input()) for i in range(H)]
class UnionFind:
def __init__(self,N):
self.parent = [i for i in range(N)]
self.rank = [0] * N
self.count = 0
def root(self,a):
if self.parent[a] == a:
return a
else:
self.parent[a] = self.root(self.parent[a])
return self.parent[a]
def is_same(self,a,b):
return self.root(a) == self.root(b)
def unite(self,a,b):
ra = self.root(a)
rb = self.root(b)
if ra == rb: return
if self.rank[ra] < self.rank[rb]:
self.parent[ra] = rb
else:
self.parent[rb] = ra
if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
self.count += 1
uf = UnionFind(H*W)
for i in range(H):
for j in range(W):
if j < W-1 and S[i][j] != S[i][j+1]:
uf.unite(i*W+j, i*W+j+1)
if i < H-1 and S[i][j] != S[i+1][j]:
uf.unite(i*W+j, (i+1)*W+j)
for i in range(H*W):
uf.root(i)
c1 = Counter()
c2 = Counter()
for i in range(H):
for j in range(W):
k = i*W+j
if S[i][j] == '.':
c1[uf.root(k)] += 1
else:
c2[uf.root(k)] += 1
ans = 0
for k in list(c1.keys()):
ans += c1[k] * c2[k]
print(ans) | H,W = list(map(int,input().split()))
S = [eval(input()) for i in range(H)]
class UnionFind:
def __init__(self,N):
self.parent = [i for i in range(N)]
self._size = [1] * N
self.count = 0
def root(self,a):
if self.parent[a] == a:
return a
else:
self.parent[a] = self.root(self.parent[a])
return self.parent[a]
def is_same(self,a,b):
return self.root(a) == self.root(b)
def unite(self,a,b):
ra = self.root(a)
rb = self.root(b)
if ra == rb: return
if self._size[ra] < self._size[rb]: ra,rb = rb,ra
self._size[ra] += self._size[rb]
self.parent[rb] = ra
self.count += 1
def size(self,a):
return self._size[self.root(a)]
uf = UnionFind(H*W)
for i in range(H):
for j in range(W):
if i < H-1 and S[i][j] != S[i+1][j]:
uf.unite(i*W+j, (i+1)*W+j)
if j < W-1 and S[i][j] != S[i][j+1]:
uf.unite(i*W+j, i*W+j+1)
for i in range(H*W):
uf.root(i)
from collections import defaultdict
bl = defaultdict(lambda: 0)
wh = defaultdict(lambda: 0)
for i in range(H):
for j in range(W):
v = i*W+j
r = uf.root(v)
if S[i][j]=='#':
bl[r] += 1
else:
wh[r] += 1
ans = 0
for k in list(bl.keys()):
ans += bl[k] * wh[k]
print(ans) | 55 | 53 | 1,382 | 1,413 | from collections import Counter
H, W = list(map(int, input().split()))
S = [eval(input()) for i in range(H)]
class UnionFind:
def __init__(self, N):
self.parent = [i for i in range(N)]
self.rank = [0] * N
self.count = 0
def root(self, a):
if self.parent[a] == a:
return a
else:
self.parent[a] = self.root(self.parent[a])
return self.parent[a]
def is_same(self, a, b):
return self.root(a) == self.root(b)
def unite(self, a, b):
ra = self.root(a)
rb = self.root(b)
if ra == rb:
return
if self.rank[ra] < self.rank[rb]:
self.parent[ra] = rb
else:
self.parent[rb] = ra
if self.rank[ra] == self.rank[rb]:
self.rank[ra] += 1
self.count += 1
uf = UnionFind(H * W)
for i in range(H):
for j in range(W):
if j < W - 1 and S[i][j] != S[i][j + 1]:
uf.unite(i * W + j, i * W + j + 1)
if i < H - 1 and S[i][j] != S[i + 1][j]:
uf.unite(i * W + j, (i + 1) * W + j)
for i in range(H * W):
uf.root(i)
c1 = Counter()
c2 = Counter()
for i in range(H):
for j in range(W):
k = i * W + j
if S[i][j] == ".":
c1[uf.root(k)] += 1
else:
c2[uf.root(k)] += 1
ans = 0
for k in list(c1.keys()):
ans += c1[k] * c2[k]
print(ans)
| H, W = list(map(int, input().split()))
S = [eval(input()) for i in range(H)]
class UnionFind:
def __init__(self, N):
self.parent = [i for i in range(N)]
self._size = [1] * N
self.count = 0
def root(self, a):
if self.parent[a] == a:
return a
else:
self.parent[a] = self.root(self.parent[a])
return self.parent[a]
def is_same(self, a, b):
return self.root(a) == self.root(b)
def unite(self, a, b):
ra = self.root(a)
rb = self.root(b)
if ra == rb:
return
if self._size[ra] < self._size[rb]:
ra, rb = rb, ra
self._size[ra] += self._size[rb]
self.parent[rb] = ra
self.count += 1
def size(self, a):
return self._size[self.root(a)]
uf = UnionFind(H * W)
for i in range(H):
for j in range(W):
if i < H - 1 and S[i][j] != S[i + 1][j]:
uf.unite(i * W + j, (i + 1) * W + j)
if j < W - 1 and S[i][j] != S[i][j + 1]:
uf.unite(i * W + j, i * W + j + 1)
for i in range(H * W):
uf.root(i)
from collections import defaultdict
bl = defaultdict(lambda: 0)
wh = defaultdict(lambda: 0)
for i in range(H):
for j in range(W):
v = i * W + j
r = uf.root(v)
if S[i][j] == "#":
bl[r] += 1
else:
wh[r] += 1
ans = 0
for k in list(bl.keys()):
ans += bl[k] * wh[k]
print(ans)
| false | 3.636364 | [
"-from collections import Counter",
"-",
"- self.rank = [0] * N",
"+ self._size = [1] * N",
"- if self.rank[ra] < self.rank[rb]:",
"- self.parent[ra] = rb",
"- else:",
"- self.parent[rb] = ra",
"- if self.rank[ra] == self.rank[rb]:",
"- self.rank[ra] += 1",
"+ if self._size[ra] < self._size[rb]:",
"+ ra, rb = rb, ra",
"+ self._size[ra] += self._size[rb]",
"+ self.parent[rb] = ra",
"+",
"+ def size(self, a):",
"+ return self._size[self.root(a)]",
"+ if i < H - 1 and S[i][j] != S[i + 1][j]:",
"+ uf.unite(i * W + j, (i + 1) * W + j)",
"- if i < H - 1 and S[i][j] != S[i + 1][j]:",
"- uf.unite(i * W + j, (i + 1) * W + j)",
"-c1 = Counter()",
"-c2 = Counter()",
"+from collections import defaultdict",
"+",
"+bl = defaultdict(lambda: 0)",
"+wh = defaultdict(lambda: 0)",
"- k = i * W + j",
"- if S[i][j] == \".\":",
"- c1[uf.root(k)] += 1",
"+ v = i * W + j",
"+ r = uf.root(v)",
"+ if S[i][j] == \"#\":",
"+ bl[r] += 1",
"- c2[uf.root(k)] += 1",
"+ wh[r] += 1",
"-for k in list(c1.keys()):",
"- ans += c1[k] * c2[k]",
"+for k in list(bl.keys()):",
"+ ans += bl[k] * wh[k]"
] | false | 0.043893 | 0.08299 | 0.528892 | [
"s106499877",
"s082441306"
] |
u150984829 | p02269 | python | s524515862 | s041055295 | 830 | 740 | 118,068 | 33,668 | Accepted | Accepted | 10.84 | import sys
def m():
d={}
for e in sys.stdin.readlines()[1:]:
if'f'==e[0]:print(('yes'if e[5:]in d else'no'))
else:d[e[7:]]=0
if'__main__'==__name__:m()
| import sys
def m():
d={};eval(input())
for e in sys.stdin:
if'f'==e[0]:print(('yes'if e[5:]in d else'no'))
else:d[e[7:]]=0
if'__main__'==__name__:m()
| 7 | 7 | 162 | 154 | import sys
def m():
d = {}
for e in sys.stdin.readlines()[1:]:
if "f" == e[0]:
print(("yes" if e[5:] in d else "no"))
else:
d[e[7:]] = 0
if "__main__" == __name__:
m()
| import sys
def m():
d = {}
eval(input())
for e in sys.stdin:
if "f" == e[0]:
print(("yes" if e[5:] in d else "no"))
else:
d[e[7:]] = 0
if "__main__" == __name__:
m()
| false | 0 | [
"- for e in sys.stdin.readlines()[1:]:",
"+ eval(input())",
"+ for e in sys.stdin:"
] | false | 0.079274 | 0.042841 | 1.850412 | [
"s524515862",
"s041055295"
] |
u576917603 | p02917 | python | s766976992 | s738417613 | 182 | 20 | 38,384 | 3,060 | Accepted | Accepted | 89.01 | n=int(eval(input()))
a=[None]*n
b=list(map(int,input().split()))
a[0]=b[0]
a[-1]=b[-1]
for i in range(1,n-1):
if b[i]>=b[i-1]:
a[i]=b[i-1]
else:
a[i]=b[i]
print((sum(a))) | n=int(eval(input()))
b=list(map(int,input().split()))
a=[0]*n
a[0]=b[0]
for i in range(n-2):
a[i+1]=min(b[i],b[i+1])
a[-1]=b[-1]
print((sum(a))) | 11 | 8 | 196 | 147 | n = int(eval(input()))
a = [None] * n
b = list(map(int, input().split()))
a[0] = b[0]
a[-1] = b[-1]
for i in range(1, n - 1):
if b[i] >= b[i - 1]:
a[i] = b[i - 1]
else:
a[i] = b[i]
print((sum(a)))
| n = int(eval(input()))
b = list(map(int, input().split()))
a = [0] * n
a[0] = b[0]
for i in range(n - 2):
a[i + 1] = min(b[i], b[i + 1])
a[-1] = b[-1]
print((sum(a)))
| false | 27.272727 | [
"-a = [None] * n",
"+a = [0] * n",
"+for i in range(n - 2):",
"+ a[i + 1] = min(b[i], b[i + 1])",
"-for i in range(1, n - 1):",
"- if b[i] >= b[i - 1]:",
"- a[i] = b[i - 1]",
"- else:",
"- a[i] = b[i]"
] | false | 0.039031 | 0.035179 | 1.109482 | [
"s766976992",
"s738417613"
] |
u500376440 | p03355 | python | s656329827 | s334267549 | 481 | 70 | 69,544 | 69,576 | Accepted | Accepted | 85.45 | import sys
def input():
return sys.stdin.readline().rstrip()
S=eval(input())
K=int(eval(input()))
vec=[]
for i in range(len(S)):
for j in range(i+1,K+i+1):
tmp=S[i:j]
if not tmp in vec:
vec.append(tmp)
vec.sort()
print((vec[K-1]))
| import sys
def input():
return sys.stdin.readline().rstrip()
S=eval(input())
K=int(eval(input()))
vec=set()
for i in range(len(S)):
for j in range(i+1,min(len(S)+1,K+i+1)):
tmp=S[i:j]
vec.add(tmp)
vec=list(vec)
vec.sort()
print((vec[K-1]))
| 16 | 17 | 253 | 258 | import sys
def input():
return sys.stdin.readline().rstrip()
S = eval(input())
K = int(eval(input()))
vec = []
for i in range(len(S)):
for j in range(i + 1, K + i + 1):
tmp = S[i:j]
if not tmp in vec:
vec.append(tmp)
vec.sort()
print((vec[K - 1]))
| import sys
def input():
return sys.stdin.readline().rstrip()
S = eval(input())
K = int(eval(input()))
vec = set()
for i in range(len(S)):
for j in range(i + 1, min(len(S) + 1, K + i + 1)):
tmp = S[i:j]
vec.add(tmp)
vec = list(vec)
vec.sort()
print((vec[K - 1]))
| false | 5.882353 | [
"-vec = []",
"+vec = set()",
"- for j in range(i + 1, K + i + 1):",
"+ for j in range(i + 1, min(len(S) + 1, K + i + 1)):",
"- if not tmp in vec:",
"- vec.append(tmp)",
"+ vec.add(tmp)",
"+vec = list(vec)"
] | false | 0.079946 | 0.040416 | 1.978099 | [
"s656329827",
"s334267549"
] |
u636683284 | p03038 | python | s234372578 | s320015989 | 390 | 250 | 97,264 | 107,564 | Accepted | Accepted | 35.9 | import sys
import heapq
input = sys.stdin.readline
n,m = list(map(int,input().split()))
A = list(map(int,input().split()))
heapq.heapify(A)
BC = [list(map(int, input().split())) for i in range(m)]
BC = sorted(BC,key = lambda x:-x[1])
for b,c in BC:
for i in range(b):
a = heapq.heappop(A)
if a < c:
heapq.heappush(A,c)
else:
heapq.heappush(A,a)
break
print((sum(A))) | import sys
input = sys.stdin.readline
n,m = list(map(int,input().split()))
A = list(map(int,input().split()))
BC = [tuple(map(int,input().split())) for i in range(m)]
BC = sorted(BC,key=lambda x:-x[1])
cnt = 0
flag = True
while True:
for b,c in BC:
A += [c]*b
cnt += b
if cnt > n:
break
break
A = sorted(A,reverse=True)
print((sum(A[:n]))) | 20 | 18 | 444 | 393 | import sys
import heapq
input = sys.stdin.readline
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
heapq.heapify(A)
BC = [list(map(int, input().split())) for i in range(m)]
BC = sorted(BC, key=lambda x: -x[1])
for b, c in BC:
for i in range(b):
a = heapq.heappop(A)
if a < c:
heapq.heappush(A, c)
else:
heapq.heappush(A, a)
break
print((sum(A)))
| import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [tuple(map(int, input().split())) for i in range(m)]
BC = sorted(BC, key=lambda x: -x[1])
cnt = 0
flag = True
while True:
for b, c in BC:
A += [c] * b
cnt += b
if cnt > n:
break
break
A = sorted(A, reverse=True)
print((sum(A[:n])))
| false | 10 | [
"-import heapq",
"-heapq.heapify(A)",
"-BC = [list(map(int, input().split())) for i in range(m)]",
"+BC = [tuple(map(int, input().split())) for i in range(m)]",
"-for b, c in BC:",
"- for i in range(b):",
"- a = heapq.heappop(A)",
"- if a < c:",
"- heapq.heappush(A, c)",
"- else:",
"- heapq.heappush(A, a)",
"+cnt = 0",
"+flag = True",
"+while True:",
"+ for b, c in BC:",
"+ A += [c] * b",
"+ cnt += b",
"+ if cnt > n:",
"-print((sum(A)))",
"+ break",
"+A = sorted(A, reverse=True)",
"+print((sum(A[:n])))"
] | false | 0.035333 | 0.069191 | 0.510653 | [
"s234372578",
"s320015989"
] |
u970899068 | p02792 | python | s002642543 | s607073079 | 227 | 205 | 40,812 | 40,428 | Accepted | Accepted | 9.69 | n=int(eval(input()))
v=[0]*100
ans=0
for i in range(1,n+1):
x=int(str(i)[0])
y=int(str(i)[-1])
v[x*10+y]+=1
for i in range(len(v)):
x=int(str(i)[0])
y=int(str(i)[-1])
ans+=v[i]*v[10*y+x]
print(ans) | n=int(eval(input()))
x=[0]*101
ans=0
for i in range(1,n+1):
v=str(i)
w=int(v[0]+v[-1])
x[w]+=1
for i in range(101):
if x[i]!=0:
v=str(i)
w=int(v[-1]+v[0])
ans+=x[i]*x[w]
print(ans) | 13 | 14 | 228 | 228 | n = int(eval(input()))
v = [0] * 100
ans = 0
for i in range(1, n + 1):
x = int(str(i)[0])
y = int(str(i)[-1])
v[x * 10 + y] += 1
for i in range(len(v)):
x = int(str(i)[0])
y = int(str(i)[-1])
ans += v[i] * v[10 * y + x]
print(ans)
| n = int(eval(input()))
x = [0] * 101
ans = 0
for i in range(1, n + 1):
v = str(i)
w = int(v[0] + v[-1])
x[w] += 1
for i in range(101):
if x[i] != 0:
v = str(i)
w = int(v[-1] + v[0])
ans += x[i] * x[w]
print(ans)
| false | 7.142857 | [
"-v = [0] * 100",
"+x = [0] * 101",
"- x = int(str(i)[0])",
"- y = int(str(i)[-1])",
"- v[x * 10 + y] += 1",
"-for i in range(len(v)):",
"- x = int(str(i)[0])",
"- y = int(str(i)[-1])",
"- ans += v[i] * v[10 * y + x]",
"+ v = str(i)",
"+ w = int(v[0] + v[-1])",
"+ x[w] += 1",
"+for i in range(101):",
"+ if x[i] != 0:",
"+ v = str(i)",
"+ w = int(v[-1] + v[0])",
"+ ans += x[i] * x[w]"
] | false | 0.085251 | 0.073653 | 1.157471 | [
"s002642543",
"s607073079"
] |
u198440493 | p03128 | python | s856220290 | s004718964 | 39 | 18 | 14,452 | 3,064 | Accepted | Accepted | 53.85 | INF = float('inf')
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cost = [2, 5, 5, 4, 5, 6, 3, 7, 6]
l = [[x, cost[x-1]] for x in a]
l = sorted(l, key = lambda x: x[1]*10-x[0])
r = l[0]
_max = [0] + [-INF]*n
for i in range(1, n+1):
if 42 < i < n-42:
_max[i] = max(_max[i], _max[i-r[1]]*10 + r[0])
else:
for x in l:
ind = i-x[1]
if ind >= 0:
_max[i] = max(_max[i], _max[ind]*10 + x[0])
ans = str(_max[n])
print(ans) | INF = float('inf')
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cost = [2, 5, 5, 4, 5, 6, 3, 7, 6]
l = [[x, cost[x-1]] for x in a]
l = sorted(l, key = lambda x: x[1]*10-x[0])
r = l[0]
k = max(n-200, 0)//r[1]
n -= r[1]*k
_max = [0] + [-INF]*n
for i in range(1, n+1):
if 50 < i < n-50:
_max[i] = max(_max[i], _max[i-r[1]]*10 + r[0])
else:
for x in l:
ind = i-x[1]
if ind >= 0:
_max[i] = max(_max[i], _max[ind]*10 + x[0])
ans = str(_max[n])
ans = ans[:10] + str(r[0])*k + ans[10:]
print(ans) | 18 | 21 | 485 | 564 | INF = float("inf")
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cost = [2, 5, 5, 4, 5, 6, 3, 7, 6]
l = [[x, cost[x - 1]] for x in a]
l = sorted(l, key=lambda x: x[1] * 10 - x[0])
r = l[0]
_max = [0] + [-INF] * n
for i in range(1, n + 1):
if 42 < i < n - 42:
_max[i] = max(_max[i], _max[i - r[1]] * 10 + r[0])
else:
for x in l:
ind = i - x[1]
if ind >= 0:
_max[i] = max(_max[i], _max[ind] * 10 + x[0])
ans = str(_max[n])
print(ans)
| INF = float("inf")
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cost = [2, 5, 5, 4, 5, 6, 3, 7, 6]
l = [[x, cost[x - 1]] for x in a]
l = sorted(l, key=lambda x: x[1] * 10 - x[0])
r = l[0]
k = max(n - 200, 0) // r[1]
n -= r[1] * k
_max = [0] + [-INF] * n
for i in range(1, n + 1):
if 50 < i < n - 50:
_max[i] = max(_max[i], _max[i - r[1]] * 10 + r[0])
else:
for x in l:
ind = i - x[1]
if ind >= 0:
_max[i] = max(_max[i], _max[ind] * 10 + x[0])
ans = str(_max[n])
ans = ans[:10] + str(r[0]) * k + ans[10:]
print(ans)
| false | 14.285714 | [
"+k = max(n - 200, 0) // r[1]",
"+n -= r[1] * k",
"- if 42 < i < n - 42:",
"+ if 50 < i < n - 50:",
"+ans = ans[:10] + str(r[0]) * k + ans[10:]"
] | false | 0.039492 | 0.043077 | 0.916777 | [
"s856220290",
"s004718964"
] |
u464032595 | p03086 | python | s644811629 | s702681331 | 179 | 30 | 38,384 | 8,980 | Accepted | Accepted | 83.24 | s = eval(input())
maxs = 0
cnt = 0
for i, x in enumerate(s):
if x in ['A', 'C', 'G', 'T']:
cnt += 1
else:
if cnt > 0:
maxs = max(maxs, cnt)
cnt = 0
if cnt > 0:
maxs = max(maxs, cnt)
print(maxs) | s = eval(input())
max_cnt = 0
cnt = 0
for i in s:
if i in ['A', 'C', 'G', 'T']:
cnt += 1
else:
max_cnt = max(cnt, max_cnt)
cnt = 0
print((max(max_cnt, cnt))) | 13 | 12 | 251 | 194 | s = eval(input())
maxs = 0
cnt = 0
for i, x in enumerate(s):
if x in ["A", "C", "G", "T"]:
cnt += 1
else:
if cnt > 0:
maxs = max(maxs, cnt)
cnt = 0
if cnt > 0:
maxs = max(maxs, cnt)
print(maxs)
| s = eval(input())
max_cnt = 0
cnt = 0
for i in s:
if i in ["A", "C", "G", "T"]:
cnt += 1
else:
max_cnt = max(cnt, max_cnt)
cnt = 0
print((max(max_cnt, cnt)))
| false | 7.692308 | [
"-maxs = 0",
"+max_cnt = 0",
"-for i, x in enumerate(s):",
"- if x in [\"A\", \"C\", \"G\", \"T\"]:",
"+for i in s:",
"+ if i in [\"A\", \"C\", \"G\", \"T\"]:",
"- if cnt > 0:",
"- maxs = max(maxs, cnt)",
"- cnt = 0",
"-if cnt > 0:",
"- maxs = max(maxs, cnt)",
"-print(maxs)",
"+ max_cnt = max(cnt, max_cnt)",
"+ cnt = 0",
"+print((max(max_cnt, cnt)))"
] | false | 0.081913 | 0.036972 | 2.215542 | [
"s644811629",
"s702681331"
] |
u647999897 | p03013 | python | s114991749 | s126342159 | 596 | 478 | 470,648 | 45,016 | Accepted | Accepted | 19.8 | def solve():
N, M = list(map(int, input().split()))
a = []
for _ in range(M):
a.append(int(eval(input())))
dp = [0] * (N + 1)
dp[0] = 1
a_ind = 0
for i in range(1, N+1):
if a_ind < M and i == a[a_ind]:
a_ind += 1
dp[i] = 0
continue
dp[i] += dp[i - 1]
if i > 1:
dp[i] += dp[i - 2]
print((dp[N] % 1000000007))
if __name__ == '__main__':
solve()
| def solve():
mod = 10 ** 9 + 7
N, M = list(map(int, input().split()))
isBreakable = [False] * (N+1)
for i in range(M):
a = int(eval(input()))
isBreakable[a] = True
dp = [0] * (N+1)
dp[0] = 1
for i in range(1, N+1):
if isBreakable[i]:
continue
if i == 1:
dp[1] = 1
continue
dp[i] = dp[i-1] + dp[i-2]
dp[i] %= mod
print((dp[-1]))
if __name__ == '__main__':
solve() | 23 | 23 | 475 | 497 | def solve():
N, M = list(map(int, input().split()))
a = []
for _ in range(M):
a.append(int(eval(input())))
dp = [0] * (N + 1)
dp[0] = 1
a_ind = 0
for i in range(1, N + 1):
if a_ind < M and i == a[a_ind]:
a_ind += 1
dp[i] = 0
continue
dp[i] += dp[i - 1]
if i > 1:
dp[i] += dp[i - 2]
print((dp[N] % 1000000007))
if __name__ == "__main__":
solve()
| def solve():
mod = 10**9 + 7
N, M = list(map(int, input().split()))
isBreakable = [False] * (N + 1)
for i in range(M):
a = int(eval(input()))
isBreakable[a] = True
dp = [0] * (N + 1)
dp[0] = 1
for i in range(1, N + 1):
if isBreakable[i]:
continue
if i == 1:
dp[1] = 1
continue
dp[i] = dp[i - 1] + dp[i - 2]
dp[i] %= mod
print((dp[-1]))
if __name__ == "__main__":
solve()
| false | 0 | [
"+ mod = 10**9 + 7",
"- a = []",
"- for _ in range(M):",
"- a.append(int(eval(input())))",
"+ isBreakable = [False] * (N + 1)",
"+ for i in range(M):",
"+ a = int(eval(input()))",
"+ isBreakable[a] = True",
"- a_ind = 0",
"- if a_ind < M and i == a[a_ind]:",
"- a_ind += 1",
"- dp[i] = 0",
"+ if isBreakable[i]:",
"- dp[i] += dp[i - 1]",
"- if i > 1:",
"- dp[i] += dp[i - 2]",
"- print((dp[N] % 1000000007))",
"+ if i == 1:",
"+ dp[1] = 1",
"+ continue",
"+ dp[i] = dp[i - 1] + dp[i - 2]",
"+ dp[i] %= mod",
"+ print((dp[-1]))"
] | false | 0.102417 | 0.041282 | 2.480905 | [
"s114991749",
"s126342159"
] |
u744920373 | p03111 | python | s551980491 | s627868227 | 706 | 197 | 3,316 | 3,064 | Accepted | Accepted | 72.1 | import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import itertools
N, *A = mi()
L = [ii() for _ in range(N)]
L_ = [L[i] for i in range(N)]
N_ = N
A = sorted(A)
#sum_l = sum(L)
tmp = [0] * 3
ans = float('inf')
for k in itertools.product([0,1], repeat=N_):
N = sum(k)
if N < 3:
continue
L = []
for x in range(N_):
if k[x]:
L.append(L_[x]*k[x])
#L = [L_[x]*k[x] for x in range(N_)]
sum_l = sum(L)
for i in range(1, N+1):
for koho_i in range(1, 2**i):
for koho_j in range(1, 2**i):
j = i
#print(koho_i, koho_j)
if koho_i & koho_j:
continue
#tmp[0] = [L[x]*koho_i[x] for x in range(i)]
tmp[0] = sum([L[x]*min((koho_i & 1<<x), 1) for x in range(i)])
#tmp[1] = [L[x]*koho_j[x] for x in range(j)]
tmp[1] = sum([L[x]*min((koho_j & 1<<x), 1) for x in range(j)])
tmp[2] = sum_l - tmp[0] - tmp[1]
#print(tmp)
if 0 in tmp:
continue
tmp = sorted(tmp)
cost = (N-3) * 10 + sum([abs(tmp[x]-A[x]) for x in range(3)])
#if cost < ans:
#print(tmp, cost, N)
#if tmp[0] == 80 and tmp[1] == 91 and tmp[2] == 98:
#print(cost)
ans = min(ans, cost)
print(ans)
| import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import itertools
N, *A = mi()
L = [ii() for _ in range(N)]
A = sorted(A)
sum_a = sum(A)
def dfs(i, a, b, c, use):
if (0 not in [a, b, c]) and use > 2:
global ans
abc = sorted([a, b, c])
ans = min(ans, (use-3)*10 + sum([abs(abc[i]-A[i]) for i in range(3)]))
if i > N-1:
return
dfs(i+1, a+L[i], b, c, use+1)
dfs(i+1, a, b+L[i], c, use+1)
dfs(i+1, a, b, c+L[i], use+1)
dfs(i+1, a, b, c, use)
ans = float('inf')
dfs(0, 0, 0, 0, 0)
print(ans) | 60 | 37 | 2,020 | 1,111 | import sys
sys.setrecursionlimit(10**8)
def ii():
return int(sys.stdin.readline())
def mi():
return list(map(int, sys.stdin.readline().split()))
def li():
return list(map(int, sys.stdin.readline().split()))
def li2(N):
return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j):
return [[ini] * i for _ in range(j)]
# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
# from collections import Counter # a = Counter(A).most_common()
# from itertools import accumulate #list(accumulate(A))
import itertools
N, *A = mi()
L = [ii() for _ in range(N)]
L_ = [L[i] for i in range(N)]
N_ = N
A = sorted(A)
# sum_l = sum(L)
tmp = [0] * 3
ans = float("inf")
for k in itertools.product([0, 1], repeat=N_):
N = sum(k)
if N < 3:
continue
L = []
for x in range(N_):
if k[x]:
L.append(L_[x] * k[x])
# L = [L_[x]*k[x] for x in range(N_)]
sum_l = sum(L)
for i in range(1, N + 1):
for koho_i in range(1, 2**i):
for koho_j in range(1, 2**i):
j = i
# print(koho_i, koho_j)
if koho_i & koho_j:
continue
# tmp[0] = [L[x]*koho_i[x] for x in range(i)]
tmp[0] = sum([L[x] * min((koho_i & 1 << x), 1) for x in range(i)])
# tmp[1] = [L[x]*koho_j[x] for x in range(j)]
tmp[1] = sum([L[x] * min((koho_j & 1 << x), 1) for x in range(j)])
tmp[2] = sum_l - tmp[0] - tmp[1]
# print(tmp)
if 0 in tmp:
continue
tmp = sorted(tmp)
cost = (N - 3) * 10 + sum([abs(tmp[x] - A[x]) for x in range(3)])
# if cost < ans:
# print(tmp, cost, N)
# if tmp[0] == 80 and tmp[1] == 91 and tmp[2] == 98:
# print(cost)
ans = min(ans, cost)
print(ans)
| import sys
sys.setrecursionlimit(10**8)
def ii():
return int(sys.stdin.readline())
def mi():
return list(map(int, sys.stdin.readline().split()))
def li():
return list(map(int, sys.stdin.readline().split()))
def li2(N):
return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j):
return [[ini] * i for _ in range(j)]
# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
# from collections import Counter # a = Counter(A).most_common()
# from itertools import accumulate #list(accumulate(A))
import itertools
N, *A = mi()
L = [ii() for _ in range(N)]
A = sorted(A)
sum_a = sum(A)
def dfs(i, a, b, c, use):
if (0 not in [a, b, c]) and use > 2:
global ans
abc = sorted([a, b, c])
ans = min(ans, (use - 3) * 10 + sum([abs(abc[i] - A[i]) for i in range(3)]))
if i > N - 1:
return
dfs(i + 1, a + L[i], b, c, use + 1)
dfs(i + 1, a, b + L[i], c, use + 1)
dfs(i + 1, a, b, c + L[i], use + 1)
dfs(i + 1, a, b, c, use)
ans = float("inf")
dfs(0, 0, 0, 0, 0)
print(ans)
| false | 38.333333 | [
"-L_ = [L[i] for i in range(N)]",
"-N_ = N",
"-# sum_l = sum(L)",
"-tmp = [0] * 3",
"+sum_a = sum(A)",
"+",
"+",
"+def dfs(i, a, b, c, use):",
"+ if (0 not in [a, b, c]) and use > 2:",
"+ global ans",
"+ abc = sorted([a, b, c])",
"+ ans = min(ans, (use - 3) * 10 + sum([abs(abc[i] - A[i]) for i in range(3)]))",
"+ if i > N - 1:",
"+ return",
"+ dfs(i + 1, a + L[i], b, c, use + 1)",
"+ dfs(i + 1, a, b + L[i], c, use + 1)",
"+ dfs(i + 1, a, b, c + L[i], use + 1)",
"+ dfs(i + 1, a, b, c, use)",
"+",
"+",
"-for k in itertools.product([0, 1], repeat=N_):",
"- N = sum(k)",
"- if N < 3:",
"- continue",
"- L = []",
"- for x in range(N_):",
"- if k[x]:",
"- L.append(L_[x] * k[x])",
"- # L = [L_[x]*k[x] for x in range(N_)]",
"- sum_l = sum(L)",
"- for i in range(1, N + 1):",
"- for koho_i in range(1, 2**i):",
"- for koho_j in range(1, 2**i):",
"- j = i",
"- # print(koho_i, koho_j)",
"- if koho_i & koho_j:",
"- continue",
"- # tmp[0] = [L[x]*koho_i[x] for x in range(i)]",
"- tmp[0] = sum([L[x] * min((koho_i & 1 << x), 1) for x in range(i)])",
"- # tmp[1] = [L[x]*koho_j[x] for x in range(j)]",
"- tmp[1] = sum([L[x] * min((koho_j & 1 << x), 1) for x in range(j)])",
"- tmp[2] = sum_l - tmp[0] - tmp[1]",
"- # print(tmp)",
"- if 0 in tmp:",
"- continue",
"- tmp = sorted(tmp)",
"- cost = (N - 3) * 10 + sum([abs(tmp[x] - A[x]) for x in range(3)])",
"- # if cost < ans:",
"- # print(tmp, cost, N)",
"- # if tmp[0] == 80 and tmp[1] == 91 and tmp[2] == 98:",
"- # print(cost)",
"- ans = min(ans, cost)",
"+dfs(0, 0, 0, 0, 0)"
] | false | 0.385168 | 0.162134 | 2.37562 | [
"s551980491",
"s627868227"
] |
u606045429 | p03040 | python | s132247186 | s886955340 | 587 | 403 | 43,748 | 43,632 | Accepted | Accepted | 31.35 | from heapq import heappush, heappop
def main():
INF = 10 ** 18
sum_B = 0
L, R = [INF], [INF]
sum_L = sum_R = 0
L_size = R_size = 0
A = list(map(int, open(0).read().split()))
Q = next(A)
for _ in range(Q):
q = next(A)
if q == 1:
a, b = next(A), next(A)
sum_B += b
max_L = -heappop(L)
min_R = heappop(R)
sum_L -= max_L
sum_R -= min_R
l, m, r = sorted((max_L, a, min_R))
heappush(L, -l)
heappush(R, r)
sum_L += l
sum_R += r
if L_size == R_size:
heappush(L, -m)
L_size += 1
sum_L += m
else:
heappush(R, m)
R_size += 1
sum_R += m
else:
median = -L[0]
min_value = sum_B + sum_R - sum_L
if L_size != R_size:
min_value += median
print((median, min_value))
if __name__ == '__main__':
main()
| from heapq import heappush, heappushpop
def main():
INF = 10 ** 18
sum_B = 0
L, R = [INF], [INF]
sum_L = sum_R = 0
A = list(map(int, open(0).read().split()))
Q = next(A)
for _ in range(Q):
q = next(A)
if q == 1:
a, b = next(A), next(A)
sum_B += b
if len(L) > len(R):
l = -L[0]
if a >= l:
heappush(R, a)
sum_R += a
else:
heappushpop(L, -a)
sum_L += a - l
heappush(R, l)
sum_R += l
elif len(L) == 0:
heappush(R, a)
sum_L += a
else:
r = R[0]
if a <= r:
heappush(L, -a)
sum_L += a
else:
heappushpop(R, a)
sum_R += a - r
heappush(L, -r)
sum_L += r
else:
median = -L[0]
res = (median * len(L) - sum_L) + (sum_R - median * len(R)) + sum_B
print((median, res))
if __name__ == '__main__':
main()
| 52 | 50 | 1,114 | 1,256 | from heapq import heappush, heappop
def main():
INF = 10**18
sum_B = 0
L, R = [INF], [INF]
sum_L = sum_R = 0
L_size = R_size = 0
A = list(map(int, open(0).read().split()))
Q = next(A)
for _ in range(Q):
q = next(A)
if q == 1:
a, b = next(A), next(A)
sum_B += b
max_L = -heappop(L)
min_R = heappop(R)
sum_L -= max_L
sum_R -= min_R
l, m, r = sorted((max_L, a, min_R))
heappush(L, -l)
heappush(R, r)
sum_L += l
sum_R += r
if L_size == R_size:
heappush(L, -m)
L_size += 1
sum_L += m
else:
heappush(R, m)
R_size += 1
sum_R += m
else:
median = -L[0]
min_value = sum_B + sum_R - sum_L
if L_size != R_size:
min_value += median
print((median, min_value))
if __name__ == "__main__":
main()
| from heapq import heappush, heappushpop
def main():
INF = 10**18
sum_B = 0
L, R = [INF], [INF]
sum_L = sum_R = 0
A = list(map(int, open(0).read().split()))
Q = next(A)
for _ in range(Q):
q = next(A)
if q == 1:
a, b = next(A), next(A)
sum_B += b
if len(L) > len(R):
l = -L[0]
if a >= l:
heappush(R, a)
sum_R += a
else:
heappushpop(L, -a)
sum_L += a - l
heappush(R, l)
sum_R += l
elif len(L) == 0:
heappush(R, a)
sum_L += a
else:
r = R[0]
if a <= r:
heappush(L, -a)
sum_L += a
else:
heappushpop(R, a)
sum_R += a - r
heappush(L, -r)
sum_L += r
else:
median = -L[0]
res = (median * len(L) - sum_L) + (sum_R - median * len(R)) + sum_B
print((median, res))
if __name__ == "__main__":
main()
| false | 3.846154 | [
"-from heapq import heappush, heappop",
"+from heapq import heappush, heappushpop",
"- L_size = R_size = 0",
"- max_L = -heappop(L)",
"- min_R = heappop(R)",
"- sum_L -= max_L",
"- sum_R -= min_R",
"- l, m, r = sorted((max_L, a, min_R))",
"- heappush(L, -l)",
"- heappush(R, r)",
"- sum_L += l",
"- sum_R += r",
"- if L_size == R_size:",
"- heappush(L, -m)",
"- L_size += 1",
"- sum_L += m",
"+ if len(L) > len(R):",
"+ l = -L[0]",
"+ if a >= l:",
"+ heappush(R, a)",
"+ sum_R += a",
"+ else:",
"+ heappushpop(L, -a)",
"+ sum_L += a - l",
"+ heappush(R, l)",
"+ sum_R += l",
"+ elif len(L) == 0:",
"+ heappush(R, a)",
"+ sum_L += a",
"- heappush(R, m)",
"- R_size += 1",
"- sum_R += m",
"+ r = R[0]",
"+ if a <= r:",
"+ heappush(L, -a)",
"+ sum_L += a",
"+ else:",
"+ heappushpop(R, a)",
"+ sum_R += a - r",
"+ heappush(L, -r)",
"+ sum_L += r",
"- min_value = sum_B + sum_R - sum_L",
"- if L_size != R_size:",
"- min_value += median",
"- print((median, min_value))",
"+ res = (median * len(L) - sum_L) + (sum_R - median * len(R)) + sum_B",
"+ print((median, res))"
] | false | 0.041075 | 0.040931 | 1.0035 | [
"s132247186",
"s886955340"
] |
u780475861 | p03475 | python | s001664079 | s585404104 | 102 | 73 | 3,688 | 3,188 | Accepted | Accepted | 28.43 | import sys
sys.setrecursionlimit(2000)
n = int(eval(input()))
lst = []
for _ in range(n - 1):
lst.append([int(i) for i in input().split()])
def time_cost(i, now, lst):
if i == n - 1:
return now
if now >= lst[i][1]:
if now % lst[i][2] == 0:
now += lst[i][0]
else:
now += lst[i][0] + lst[i][2] - now % lst[i][2]
else:
now = lst[i][1] + lst[i][0]
return time_cost(i+1, now, lst)
for i in range(n):
print((time_cost(i, 0, lst)))
| n = int(eval(input()))
lst = []
for _ in range(n - 1):
lst.append([int(i) for i in input().split()])
for i in range(n):
now = 0
for c, s, f in lst[i:]:
if now < s:
now = c + s
else:
mod = now % f
if mod == 0:
now += c
else:
now += c + f - mod
print(now)
| 22 | 17 | 481 | 321 | import sys
sys.setrecursionlimit(2000)
n = int(eval(input()))
lst = []
for _ in range(n - 1):
lst.append([int(i) for i in input().split()])
def time_cost(i, now, lst):
if i == n - 1:
return now
if now >= lst[i][1]:
if now % lst[i][2] == 0:
now += lst[i][0]
else:
now += lst[i][0] + lst[i][2] - now % lst[i][2]
else:
now = lst[i][1] + lst[i][0]
return time_cost(i + 1, now, lst)
for i in range(n):
print((time_cost(i, 0, lst)))
| n = int(eval(input()))
lst = []
for _ in range(n - 1):
lst.append([int(i) for i in input().split()])
for i in range(n):
now = 0
for c, s, f in lst[i:]:
if now < s:
now = c + s
else:
mod = now % f
if mod == 0:
now += c
else:
now += c + f - mod
print(now)
| false | 22.727273 | [
"-import sys",
"-",
"-sys.setrecursionlimit(2000)",
"-",
"-",
"-def time_cost(i, now, lst):",
"- if i == n - 1:",
"- return now",
"- if now >= lst[i][1]:",
"- if now % lst[i][2] == 0:",
"- now += lst[i][0]",
"+for i in range(n):",
"+ now = 0",
"+ for c, s, f in lst[i:]:",
"+ if now < s:",
"+ now = c + s",
"- now += lst[i][0] + lst[i][2] - now % lst[i][2]",
"- else:",
"- now = lst[i][1] + lst[i][0]",
"- return time_cost(i + 1, now, lst)",
"-",
"-",
"-for i in range(n):",
"- print((time_cost(i, 0, lst)))",
"+ mod = now % f",
"+ if mod == 0:",
"+ now += c",
"+ else:",
"+ now += c + f - mod",
"+ print(now)"
] | false | 0.04304 | 0.082382 | 0.52244 | [
"s001664079",
"s585404104"
] |
u844646164 | p03503 | python | s039723488 | s094475683 | 635 | 95 | 13,268 | 74,284 | Accepted | Accepted | 85.04 | import itertools
import numpy as np
N = int(eval(input()))
F = np.array([list(map(int, input().split())) for _ in range(N)])
P = [list(map(int, input().split())) for _ in range(N)]
benefit = -float("inf")
for i in itertools.product((0, 1), repeat=10):
if sum(i) != 0:
C = np.array(list(i)) + F
pre_benefit = 0
for j in range(N):
count = len(np.where(C[j]==2)[0])
pre_benefit += P[j][count]
if benefit < pre_benefit:
benefit = pre_benefit
print(benefit) | N = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float('inf')
for i in range(2**10):
bag = []
for j in range(10):
if (i>>j)&1:
bag += [j]
tmp = 0
is_cnt = False
for n in range(N):
f = F[n]
cnt = 0
for b in bag:
if f[b] == 1:
cnt += 1
tmp += P[n][cnt]
if cnt:
is_cnt = True
if is_cnt:
ans = max(ans, tmp)
print(ans)
| 17 | 34 | 535 | 594 | import itertools
import numpy as np
N = int(eval(input()))
F = np.array([list(map(int, input().split())) for _ in range(N)])
P = [list(map(int, input().split())) for _ in range(N)]
benefit = -float("inf")
for i in itertools.product((0, 1), repeat=10):
if sum(i) != 0:
C = np.array(list(i)) + F
pre_benefit = 0
for j in range(N):
count = len(np.where(C[j] == 2)[0])
pre_benefit += P[j][count]
if benefit < pre_benefit:
benefit = pre_benefit
print(benefit)
| N = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float("inf")
for i in range(2**10):
bag = []
for j in range(10):
if (i >> j) & 1:
bag += [j]
tmp = 0
is_cnt = False
for n in range(N):
f = F[n]
cnt = 0
for b in bag:
if f[b] == 1:
cnt += 1
tmp += P[n][cnt]
if cnt:
is_cnt = True
if is_cnt:
ans = max(ans, tmp)
print(ans)
| false | 50 | [
"-import itertools",
"-import numpy as np",
"-",
"-F = np.array([list(map(int, input().split())) for _ in range(N)])",
"+F = [list(map(int, input().split())) for _ in range(N)]",
"-benefit = -float(\"inf\")",
"-for i in itertools.product((0, 1), repeat=10):",
"- if sum(i) != 0:",
"- C = np.array(list(i)) + F",
"- pre_benefit = 0",
"- for j in range(N):",
"- count = len(np.where(C[j] == 2)[0])",
"- pre_benefit += P[j][count]",
"- if benefit < pre_benefit:",
"- benefit = pre_benefit",
"-print(benefit)",
"+ans = -float(\"inf\")",
"+for i in range(2**10):",
"+ bag = []",
"+ for j in range(10):",
"+ if (i >> j) & 1:",
"+ bag += [j]",
"+ tmp = 0",
"+ is_cnt = False",
"+ for n in range(N):",
"+ f = F[n]",
"+ cnt = 0",
"+ for b in bag:",
"+ if f[b] == 1:",
"+ cnt += 1",
"+ tmp += P[n][cnt]",
"+ if cnt:",
"+ is_cnt = True",
"+ if is_cnt:",
"+ ans = max(ans, tmp)",
"+print(ans)"
] | false | 0.269607 | 0.065574 | 4.111489 | [
"s039723488",
"s094475683"
] |
u929217794 | p02628 | python | s169753686 | s822322986 | 30 | 26 | 9,164 | 9,132 | Accepted | Accepted | 13.33 | inp1 = eval(input())
inp2 = eval(input())
lists1 = inp1.split()
lists2 = inp2.split()
N = int(lists1[0])
K = int(lists1[1])
values = sorted([int(i) for i in lists2])
result = sum(values[:K])
print(result)
| n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()
ans = 0
for i in range(k):
ans += p.pop(0)
print(ans) | 13 | 10 | 209 | 147 | inp1 = eval(input())
inp2 = eval(input())
lists1 = inp1.split()
lists2 = inp2.split()
N = int(lists1[0])
K = int(lists1[1])
values = sorted([int(i) for i in lists2])
result = sum(values[:K])
print(result)
| n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()
ans = 0
for i in range(k):
ans += p.pop(0)
print(ans)
| false | 23.076923 | [
"-inp1 = eval(input())",
"-inp2 = eval(input())",
"-lists1 = inp1.split()",
"-lists2 = inp2.split()",
"-N = int(lists1[0])",
"-K = int(lists1[1])",
"-values = sorted([int(i) for i in lists2])",
"-result = sum(values[:K])",
"-print(result)",
"+n, k = list(map(int, input().split()))",
"+p = list(map(int, input().split()))",
"+p.sort()",
"+ans = 0",
"+for i in range(k):",
"+ ans += p.pop(0)",
"+print(ans)"
] | false | 0.03183 | 0.033708 | 0.944291 | [
"s169753686",
"s822322986"
] |
u049979154 | p02642 | python | s543972696 | s524707792 | 538 | 464 | 32,236 | 32,248 | Accepted | Accepted | 13.75 | n = int(eval(input()))
a = list(map(int, input().split()))
m = 10 ** 6 + 7
count = [0] * m
for x in a:
if count[x] != 0:
count[x] = 2
continue
for i in range(x, m, x):
count[i] += 1
ans = 0
for x in a:
if count[x] == 1:
ans += 1
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
m = max(a) + 1
a = sorted(a)
count = [0] * m
for x in a:
if count[x] != 0:
count[x] = 2
continue
for i in range(x, m, x):
count[i] += 1
ans = 0
for x in a:
if count[x] == 1:
ans += 1
print(ans) | 21 | 22 | 303 | 317 | n = int(eval(input()))
a = list(map(int, input().split()))
m = 10**6 + 7
count = [0] * m
for x in a:
if count[x] != 0:
count[x] = 2
continue
for i in range(x, m, x):
count[i] += 1
ans = 0
for x in a:
if count[x] == 1:
ans += 1
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
m = max(a) + 1
a = sorted(a)
count = [0] * m
for x in a:
if count[x] != 0:
count[x] = 2
continue
for i in range(x, m, x):
count[i] += 1
ans = 0
for x in a:
if count[x] == 1:
ans += 1
print(ans)
| false | 4.545455 | [
"-m = 10**6 + 7",
"+m = max(a) + 1",
"+a = sorted(a)"
] | false | 0.286877 | 0.044333 | 6.470954 | [
"s543972696",
"s524707792"
] |
u137912513 | p03031 | python | s178319278 | s210979881 | 50 | 43 | 3,064 | 3,064 | Accepted | Accepted | 14 | n,m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]#2次元配列
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):#全てのスイッチの場合に対して
check = True#全点灯かどうか調べる
for j in range(m):#電球ごと
light = 0#スイッチオンの数
for k in range(1,len(l[j])):
if((i>>l[j][k] -1) &1):#j番目の電球のk個目のスイッチが入ってるなら
light +=1#スイッチオンの数+1
if light%2 != p[j]:
check = False#スイッチオフならfalse
if check:
ans +=1
print(ans) | import math
n,m = list(map(int, input().split()))
switch = [list(map(int,input().split())) for _ in range(m)]
p = list(map(int, input().split()))
count = 0
for j in range(2**n):#スイッチ
flag = True
for i in range(m):
on = 0
for k in switch[i][1:]:
if (j >> k-1) & 1:
on += 1
if on % 2 != p[i]:
flag = False
#break
if flag:
count +=1
print(count) | 16 | 19 | 514 | 451 | n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)] # 2次元配列
p = list(map(int, input().split()))
ans = 0
for i in range(2**n): # 全てのスイッチの場合に対して
check = True # 全点灯かどうか調べる
for j in range(m): # 電球ごと
light = 0 # スイッチオンの数
for k in range(1, len(l[j])):
if (i >> l[j][k] - 1) & 1: # j番目の電球のk個目のスイッチが入ってるなら
light += 1 # スイッチオンの数+1
if light % 2 != p[j]:
check = False # スイッチオフならfalse
if check:
ans += 1
print(ans)
| import math
n, m = list(map(int, input().split()))
switch = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
count = 0
for j in range(2**n): # スイッチ
flag = True
for i in range(m):
on = 0
for k in switch[i][1:]:
if (j >> k - 1) & 1:
on += 1
if on % 2 != p[i]:
flag = False
# break
if flag:
count += 1
print(count)
| false | 15.789474 | [
"+import math",
"+",
"-l = [list(map(int, input().split())) for i in range(m)] # 2次元配列",
"+switch = [list(map(int, input().split())) for _ in range(m)]",
"-ans = 0",
"-for i in range(2**n): # 全てのスイッチの場合に対して",
"- check = True # 全点灯かどうか調べる",
"- for j in range(m): # 電球ごと",
"- light = 0 # スイッチオンの数",
"- for k in range(1, len(l[j])):",
"- if (i >> l[j][k] - 1) & 1: # j番目の電球のk個目のスイッチが入ってるなら",
"- light += 1 # スイッチオンの数+1",
"- if light % 2 != p[j]:",
"- check = False # スイッチオフならfalse",
"- if check:",
"- ans += 1",
"-print(ans)",
"+count = 0",
"+for j in range(2**n): # スイッチ",
"+ flag = True",
"+ for i in range(m):",
"+ on = 0",
"+ for k in switch[i][1:]:",
"+ if (j >> k - 1) & 1:",
"+ on += 1",
"+ if on % 2 != p[i]:",
"+ flag = False",
"+ # break",
"+ if flag:",
"+ count += 1",
"+print(count)"
] | false | 0.044855 | 0.039521 | 1.134963 | [
"s178319278",
"s210979881"
] |
u857428111 | p03733 | python | s153502029 | s874175663 | 214 | 188 | 29,804 | 29,932 | Accepted | Accepted | 12.15 | # coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe
# my functions here!
#標準エラー出力
def printargs2err(*args):
names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
print(x,file=sys.stderr)
def printglobals():
for (symbol, value) in globals().items():
print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
for (symbol, value) in locals().items():
print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力(後でいじる)
def pin(type=int):
return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう?
def worstdata():
a=0
return a
#solution:
def vacation(N,act):
lastact =[]
dp=[0,max(act[0])]*(N+1) #[i]日目のActivity で得られる最大幸福量
return 0
#input
N,T=pin()
timing=list(pin())
ans=0
for i in range(N):
if i!=(N-1):ans+=min(timing[i+1]-timing[i],T)
else:ans+=T
print(ans)
#output
#print(solution(H,N))
#print(["No","Yes"][cond])
| # coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe
# my functions here!
#標準エラー出力
def printargs2err(*args):
names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
print(x,file=sys.stderr)
def printglobals():
for (symbol, value) in globals().items():
print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
for (symbol, value) in locals().items():
print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力(後でいじる)
def pin(type=int):
return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう?
def worstdata():
a=0
return a
#solution:
def vacation(N,act):
lastact =[]
dp=[0,max(act[0])]*(N+1) #[i]日目のActivity で得られる最大幸福量
return 0
#input
N,T=pin()
timing=tuple(pin())
ans=0
for i in range(N):
if i!=(N-1):ans+=min(timing[i+1]-timing[i],T)
else:ans+=T
print(ans)
#output
#print(solution(H,N))
#print(["No","Yes"][cond])
| 52 | 52 | 1,240 | 1,241 | # coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe
# my functions here!
# 標準エラー出力
def printargs2err(*args):
names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
print(
", ".join(names.get(id(arg), "???") + " : " + repr(arg) for arg in args),
file=sys.stderr,
)
def debug(x):
print(x, file=sys.stderr)
def printglobals():
for (symbol, value) in globals().items():
print('symbol="%s"、value=%s' % (symbol, value), file=sys.stderr)
def printlocals():
for (symbol, value) in locals().items():
print('symbol="%s"、value=%s' % (symbol, value), file=sys.stderr)
# 入力(後でいじる)
def pin(type=int):
return map(type, input().split())
# どっかで最悪計算量の入力データを用意する関数を作ろう?
def worstdata():
a = 0
return a
# solution:
def vacation(N, act):
lastact = []
dp = [0, max(act[0])] * (N + 1) # [i]日目のActivity で得られる最大幸福量
return 0
# input
N, T = pin()
timing = list(pin())
ans = 0
for i in range(N):
if i != (N - 1):
ans += min(timing[i + 1] - timing[i], T)
else:
ans += T
print(ans)
# output
# print(solution(H,N))
# print(["No","Yes"][cond])
| # coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe
# my functions here!
# 標準エラー出力
def printargs2err(*args):
names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
print(
", ".join(names.get(id(arg), "???") + " : " + repr(arg) for arg in args),
file=sys.stderr,
)
def debug(x):
print(x, file=sys.stderr)
def printglobals():
for (symbol, value) in globals().items():
print('symbol="%s"、value=%s' % (symbol, value), file=sys.stderr)
def printlocals():
for (symbol, value) in locals().items():
print('symbol="%s"、value=%s' % (symbol, value), file=sys.stderr)
# 入力(後でいじる)
def pin(type=int):
return map(type, input().split())
# どっかで最悪計算量の入力データを用意する関数を作ろう?
def worstdata():
a = 0
return a
# solution:
def vacation(N, act):
lastact = []
dp = [0, max(act[0])] * (N + 1) # [i]日目のActivity で得られる最大幸福量
return 0
# input
N, T = pin()
timing = tuple(pin())
ans = 0
for i in range(N):
if i != (N - 1):
ans += min(timing[i + 1] - timing[i], T)
else:
ans += T
print(ans)
# output
# print(solution(H,N))
# print(["No","Yes"][cond])
| false | 0 | [
"-timing = list(pin())",
"+timing = tuple(pin())"
] | false | 0.05464 | 0.053449 | 1.022284 | [
"s153502029",
"s874175663"
] |
u201856486 | p03145 | python | s506826247 | s759332571 | 28 | 19 | 3,316 | 3,192 | Accepted | Accepted | 32.14 | import sys
"""テンプレ"""
# 高速
input = sys.stdin.readline
# 1行を空白でリストにする(int)
def intline():
return list(map(int, input().split()))
# 上のstrヴァージョン
def strline():
return list(map(str, input().split()))
# 1列に並んだ数
def intlines(n):
return [int(eval(input()) for _ in range(n))]
# 上の文字列ヴァージョン
def lines(n):
return [eval(input()) for _ in range(n)]
"""ここからメインコード"""
a, b, _ = intline()
print((a * b // 2)) | import sys
"""テンプレ"""
# 高速
input = sys.stdin.readline
# 1行を空白でリストにする(int)
def intline():
return list(map(int, input().split()))
# 上のstrヴァージョン
def strline():
return list(map(str, input().split()))
# 1列に並んだ数
def intlines(n):
return [int(eval(input()) for _ in range(n))]
# 上の文字列ヴァージョン
def lines(n):
return [eval(input()) for _ in range(n)]
# Union-Find木 http://at274.hatenablog.com/entry/2018/02/02/173000
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
# 重み付きのUnion-Find木 http://at274.hatenablog.com/entry/2018/02/03/140504
class WeightedUnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
# 根への距離を管理
self.weight = [0] * (n+1)
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
y = self.find(self.par[x])
# 親への重みを追加しながら根まで走査
self.weight[x] += self.weight[self.par[x]]
self.par[x] = y
return y
# 併合
def union(self, x, y, w):
rx = self.find(x)
ry = self.find(y)
# xの木の高さ < yの木の高さ
if self.rank[rx] < self.rank[ry]:
self.par[rx] = ry
self.weight[rx] = w - self.weight[x] + self.weight[y]
# xの木の高さ ≧ yの木の高さ
else:
self.par[ry] = rx
self.weight[ry] = -w - self.weight[y] + self.weight[x]
# 木の高さが同じだった場合の処理
if self.rank[rx] == self.rank[ry]:
self.rank[rx] += 1
# 同じ集合に属するか
def same(self, x, y):
return self.find(x) == self.find(y)
# xからyへのコスト
def diff(self, x, y):
return self.weight[x] - self.weight[y]
"""ここからメインコード"""
a, b, _ = intline()
print((a * b // 2))
| 31 | 108 | 442 | 2,466 | import sys
"""テンプレ"""
# 高速
input = sys.stdin.readline
# 1行を空白でリストにする(int)
def intline():
return list(map(int, input().split()))
# 上のstrヴァージョン
def strline():
return list(map(str, input().split()))
# 1列に並んだ数
def intlines(n):
return [int(eval(input()) for _ in range(n))]
# 上の文字列ヴァージョン
def lines(n):
return [eval(input()) for _ in range(n)]
"""ここからメインコード"""
a, b, _ = intline()
print((a * b // 2))
| import sys
"""テンプレ"""
# 高速
input = sys.stdin.readline
# 1行を空白でリストにする(int)
def intline():
return list(map(int, input().split()))
# 上のstrヴァージョン
def strline():
return list(map(str, input().split()))
# 1列に並んだ数
def intlines(n):
return [int(eval(input()) for _ in range(n))]
# 上の文字列ヴァージョン
def lines(n):
return [eval(input()) for _ in range(n)]
# Union-Find木 http://at274.hatenablog.com/entry/2018/02/02/173000
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n + 1)]
self.rank = [0] * (n + 1)
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
# 重み付きのUnion-Find木 http://at274.hatenablog.com/entry/2018/02/03/140504
class WeightedUnionFind:
def __init__(self, n):
self.par = [i for i in range(n + 1)]
self.rank = [0] * (n + 1)
# 根への距離を管理
self.weight = [0] * (n + 1)
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
y = self.find(self.par[x])
# 親への重みを追加しながら根まで走査
self.weight[x] += self.weight[self.par[x]]
self.par[x] = y
return y
# 併合
def union(self, x, y, w):
rx = self.find(x)
ry = self.find(y)
# xの木の高さ < yの木の高さ
if self.rank[rx] < self.rank[ry]:
self.par[rx] = ry
self.weight[rx] = w - self.weight[x] + self.weight[y]
# xの木の高さ ≧ yの木の高さ
else:
self.par[ry] = rx
self.weight[ry] = -w - self.weight[y] + self.weight[x]
# 木の高さが同じだった場合の処理
if self.rank[rx] == self.rank[ry]:
self.rank[rx] += 1
# 同じ集合に属するか
def same(self, x, y):
return self.find(x) == self.find(y)
# xからyへのコスト
def diff(self, x, y):
return self.weight[x] - self.weight[y]
"""ここからメインコード"""
a, b, _ = intline()
print((a * b // 2))
| false | 71.296296 | [
"+# Union-Find木 http://at274.hatenablog.com/entry/2018/02/02/173000",
"+class UnionFind:",
"+ def __init__(self, n):",
"+ self.par = [i for i in range(n + 1)]",
"+ self.rank = [0] * (n + 1)",
"+",
"+ # 検索",
"+ def find(self, x):",
"+ if self.par[x] == x:",
"+ return x",
"+ else:",
"+ self.par[x] = self.find(self.par[x])",
"+ return self.par[x]",
"+",
"+ # 併合",
"+ def union(self, x, y):",
"+ x = self.find(x)",
"+ y = self.find(y)",
"+ if self.rank[x] < self.rank[y]:",
"+ self.par[x] = y",
"+ else:",
"+ self.par[y] = x",
"+ if self.rank[x] == self.rank[y]:",
"+ self.rank[x] += 1",
"+",
"+ # 同じ集合に属するか判定",
"+ def same_check(self, x, y):",
"+ return self.find(x) == self.find(y)",
"+",
"+",
"+# 重み付きのUnion-Find木 http://at274.hatenablog.com/entry/2018/02/03/140504",
"+class WeightedUnionFind:",
"+ def __init__(self, n):",
"+ self.par = [i for i in range(n + 1)]",
"+ self.rank = [0] * (n + 1)",
"+ # 根への距離を管理",
"+ self.weight = [0] * (n + 1)",
"+",
"+ # 検索",
"+ def find(self, x):",
"+ if self.par[x] == x:",
"+ return x",
"+ else:",
"+ y = self.find(self.par[x])",
"+ # 親への重みを追加しながら根まで走査",
"+ self.weight[x] += self.weight[self.par[x]]",
"+ self.par[x] = y",
"+ return y",
"+",
"+ # 併合",
"+ def union(self, x, y, w):",
"+ rx = self.find(x)",
"+ ry = self.find(y)",
"+ # xの木の高さ < yの木の高さ",
"+ if self.rank[rx] < self.rank[ry]:",
"+ self.par[rx] = ry",
"+ self.weight[rx] = w - self.weight[x] + self.weight[y]",
"+ # xの木の高さ ≧ yの木の高さ",
"+ else:",
"+ self.par[ry] = rx",
"+ self.weight[ry] = -w - self.weight[y] + self.weight[x]",
"+ # 木の高さが同じだった場合の処理",
"+ if self.rank[rx] == self.rank[ry]:",
"+ self.rank[rx] += 1",
"+",
"+ # 同じ集合に属するか",
"+ def same(self, x, y):",
"+ return self.find(x) == self.find(y)",
"+",
"+ # xからyへのコスト",
"+ def diff(self, x, y):",
"+ return self.weight[x] - self.weight[y]",
"+",
"+"
] | false | 0.040355 | 0.036906 | 1.093449 | [
"s506826247",
"s759332571"
] |
u652057333 | p02720 | python | s226830419 | s748456821 | 266 | 198 | 71,024 | 40,816 | Accepted | Accepted | 25.56 | import sys
sys.setrecursionlimit(20000000)
k = int(eval(input()))
def dfs(l, lim):
if lim == 10:
return l
new_l = []
for num in l:
last = num % 10
base = num * 10
if 1 <= last <= 8:
for i in [last-1, last, last+1]:
if base + i <= 3234566667:
new_l.append(base + i)
elif last == 0:
for i in [0, 1]:
if base + i <= 3234566667:
new_l.append(base + i)
else:
for i in [8, 9]:
if base + i <= 3234566667:
new_l.append(base + i)
return l + new_l + dfs(new_l, lim+1)
ans = list(set(dfs([1, 2, 3, 4, 5, 6, 7, 8, 9], 0)))
ans.sort()
print((ans[k-1]))
| from collections import deque
k = int(eval(input()))
que = deque([i for i in range(1, 10)])
i = 0
while True:
i += 1
num = que.popleft()
if i == k:
print(num)
exit()
if num % 10 > 0:
que.append(num * 10 + ((num % 10) - 1))
que.append(num * 10 + (num % 10))
if num % 10 < 9:
que.append(num * 10 + ((num % 10) + 1))
| 29 | 16 | 771 | 380 | import sys
sys.setrecursionlimit(20000000)
k = int(eval(input()))
def dfs(l, lim):
if lim == 10:
return l
new_l = []
for num in l:
last = num % 10
base = num * 10
if 1 <= last <= 8:
for i in [last - 1, last, last + 1]:
if base + i <= 3234566667:
new_l.append(base + i)
elif last == 0:
for i in [0, 1]:
if base + i <= 3234566667:
new_l.append(base + i)
else:
for i in [8, 9]:
if base + i <= 3234566667:
new_l.append(base + i)
return l + new_l + dfs(new_l, lim + 1)
ans = list(set(dfs([1, 2, 3, 4, 5, 6, 7, 8, 9], 0)))
ans.sort()
print((ans[k - 1]))
| from collections import deque
k = int(eval(input()))
que = deque([i for i in range(1, 10)])
i = 0
while True:
i += 1
num = que.popleft()
if i == k:
print(num)
exit()
if num % 10 > 0:
que.append(num * 10 + ((num % 10) - 1))
que.append(num * 10 + (num % 10))
if num % 10 < 9:
que.append(num * 10 + ((num % 10) + 1))
| false | 44.827586 | [
"-import sys",
"+from collections import deque",
"-sys.setrecursionlimit(20000000)",
"-",
"-",
"-def dfs(l, lim):",
"- if lim == 10:",
"- return l",
"- new_l = []",
"- for num in l:",
"- last = num % 10",
"- base = num * 10",
"- if 1 <= last <= 8:",
"- for i in [last - 1, last, last + 1]:",
"- if base + i <= 3234566667:",
"- new_l.append(base + i)",
"- elif last == 0:",
"- for i in [0, 1]:",
"- if base + i <= 3234566667:",
"- new_l.append(base + i)",
"- else:",
"- for i in [8, 9]:",
"- if base + i <= 3234566667:",
"- new_l.append(base + i)",
"- return l + new_l + dfs(new_l, lim + 1)",
"-",
"-",
"-ans = list(set(dfs([1, 2, 3, 4, 5, 6, 7, 8, 9], 0)))",
"-ans.sort()",
"-print((ans[k - 1]))",
"+que = deque([i for i in range(1, 10)])",
"+i = 0",
"+while True:",
"+ i += 1",
"+ num = que.popleft()",
"+ if i == k:",
"+ print(num)",
"+ exit()",
"+ if num % 10 > 0:",
"+ que.append(num * 10 + ((num % 10) - 1))",
"+ que.append(num * 10 + (num % 10))",
"+ if num % 10 < 9:",
"+ que.append(num * 10 + ((num % 10) + 1))"
] | false | 0.731723 | 0.121523 | 6.021245 | [
"s226830419",
"s748456821"
] |
u226155577 | p03143 | python | s065153614 | s676729406 | 1,497 | 926 | 137,516 | 46,740 | Accepted | Accepted | 38.14 | import sys
sys.setrecursionlimit(10**6)
N, M = list(map(int, input().split()))
*X, = list(map(int, input().split()))
E = []
for i in range(M):
a, b, y = list(map(int, input().split()))
E.append((y, a-1, b-1))
E.sort()
*p, = list(range(N))
Z = [0]*M
A = X[:]
C = [-1]*N
def root(x):
if x == p[x]:
return x
p[x] = y = root(p[x])
return y
def unite(x, y):
px = root(x); py = root(y)
if px == py:
return 0
if px < py:
p[py] = px
A[px] += A[py]
else:
p[px] = py
A[py] += A[px]
return 1
G = [None for i in range(M)]
ans = 0
for i, (y, a, b) in enumerate(E):
pa = root(a); pb = root(b)
ca = C[pa]; cb = C[pb]
if unite(a, b):
pa = root(a)
Z[i] = 1
C[pa] = i
#print(">", i, pa, pb, A[pa], y)
if A[pa] < y:
G[i] = []
if ca != -1:
G[i].append(ca)
if cb != -1:
G[i].append(cb)
else:
if A[pa] < y:
G[i] = []
if ca != -1:
G[i].append(ca)
C[pa] = i
sx = sum(X)
#print(Z)
if N > 1:
from collections import deque
que = deque()
if sx < E[C[0]][0]:
que.append(C[0])
#print(G, C)
while que:
v = que.popleft()
#print(v)
if G[v] is not None:
ans += 1
for w in G[v]:
que.append(w)
print(ans) | from collections import deque
import operator
N, M = list(map(int, input().split()))
*X, = list(map(int, input().split()))
E = []
for i in range(M):
a, b, y = list(map(int, input().split()))
E.append((y, a-1, b-1))
E.sort()
*Y, = list(map(operator.itemgetter(0), E))
*p, = list(range(N))
def root(x):
if x == p[x]:
return x
p[x] = y = root(p[x])
return y
A = X[:]
def unite(x, y):
px = root(x); py = root(y)
if px == py:
return 0
if px < py:
p[py] = px
A[px] += A[py]
else:
p[px] = py
A[py] += A[px]
return 1
G = [[] for i in range(M)]
B = [0]*M
C = [-1]*N
ans = 0
for i, (y, a, b) in enumerate(E):
pa = root(a); pb = root(b)
ca = C[pa]; cb = C[pb]
if unite(a, b):
if ca != -1:
G[i].append(ca)
if cb != -1:
G[i].append(cb)
pa = root(a)
else:
if ca != -1:
G[i].append(ca)
B[i] = A[pa]
C[pa] = i
if N > 1 and sum(X) < E[C[0]][0]:
que = deque()
que.append(C[0])
while que:
v = que.popleft()
if B[v] < Y[v]:
ans += 1
que.extend(G[v])
print(ans) | 74 | 61 | 1,488 | 1,208 | import sys
sys.setrecursionlimit(10**6)
N, M = list(map(int, input().split()))
(*X,) = list(map(int, input().split()))
E = []
for i in range(M):
a, b, y = list(map(int, input().split()))
E.append((y, a - 1, b - 1))
E.sort()
(*p,) = list(range(N))
Z = [0] * M
A = X[:]
C = [-1] * N
def root(x):
if x == p[x]:
return x
p[x] = y = root(p[x])
return y
def unite(x, y):
px = root(x)
py = root(y)
if px == py:
return 0
if px < py:
p[py] = px
A[px] += A[py]
else:
p[px] = py
A[py] += A[px]
return 1
G = [None for i in range(M)]
ans = 0
for i, (y, a, b) in enumerate(E):
pa = root(a)
pb = root(b)
ca = C[pa]
cb = C[pb]
if unite(a, b):
pa = root(a)
Z[i] = 1
C[pa] = i
# print(">", i, pa, pb, A[pa], y)
if A[pa] < y:
G[i] = []
if ca != -1:
G[i].append(ca)
if cb != -1:
G[i].append(cb)
else:
if A[pa] < y:
G[i] = []
if ca != -1:
G[i].append(ca)
C[pa] = i
sx = sum(X)
# print(Z)
if N > 1:
from collections import deque
que = deque()
if sx < E[C[0]][0]:
que.append(C[0])
# print(G, C)
while que:
v = que.popleft()
# print(v)
if G[v] is not None:
ans += 1
for w in G[v]:
que.append(w)
print(ans)
| from collections import deque
import operator
N, M = list(map(int, input().split()))
(*X,) = list(map(int, input().split()))
E = []
for i in range(M):
a, b, y = list(map(int, input().split()))
E.append((y, a - 1, b - 1))
E.sort()
(*Y,) = list(map(operator.itemgetter(0), E))
(*p,) = list(range(N))
def root(x):
if x == p[x]:
return x
p[x] = y = root(p[x])
return y
A = X[:]
def unite(x, y):
px = root(x)
py = root(y)
if px == py:
return 0
if px < py:
p[py] = px
A[px] += A[py]
else:
p[px] = py
A[py] += A[px]
return 1
G = [[] for i in range(M)]
B = [0] * M
C = [-1] * N
ans = 0
for i, (y, a, b) in enumerate(E):
pa = root(a)
pb = root(b)
ca = C[pa]
cb = C[pb]
if unite(a, b):
if ca != -1:
G[i].append(ca)
if cb != -1:
G[i].append(cb)
pa = root(a)
else:
if ca != -1:
G[i].append(ca)
B[i] = A[pa]
C[pa] = i
if N > 1 and sum(X) < E[C[0]][0]:
que = deque()
que.append(C[0])
while que:
v = que.popleft()
if B[v] < Y[v]:
ans += 1
que.extend(G[v])
print(ans)
| false | 17.567568 | [
"-import sys",
"+from collections import deque",
"+import operator",
"-sys.setrecursionlimit(10**6)",
"+(*Y,) = list(map(operator.itemgetter(0), E))",
"-Z = [0] * M",
"-A = X[:]",
"-C = [-1] * N",
"+",
"+",
"+A = X[:]",
"-G = [None for i in range(M)]",
"+G = [[] for i in range(M)]",
"+B = [0] * M",
"+C = [-1] * N",
"+ if ca != -1:",
"+ G[i].append(ca)",
"+ if cb != -1:",
"+ G[i].append(cb)",
"- Z[i] = 1",
"- C[pa] = i",
"- # print(\">\", i, pa, pb, A[pa], y)",
"- if A[pa] < y:",
"- G[i] = []",
"- if ca != -1:",
"- G[i].append(ca)",
"- if cb != -1:",
"- G[i].append(cb)",
"- if A[pa] < y:",
"- G[i] = []",
"- if ca != -1:",
"- G[i].append(ca)",
"- C[pa] = i",
"-sx = sum(X)",
"-# print(Z)",
"-if N > 1:",
"- from collections import deque",
"-",
"+ if ca != -1:",
"+ G[i].append(ca)",
"+ B[i] = A[pa]",
"+ C[pa] = i",
"+if N > 1 and sum(X) < E[C[0]][0]:",
"- if sx < E[C[0]][0]:",
"- que.append(C[0])",
"- # print(G, C)",
"+ que.append(C[0])",
"- # print(v)",
"- if G[v] is not None:",
"+ if B[v] < Y[v]:",
"- for w in G[v]:",
"- que.append(w)",
"+ que.extend(G[v])"
] | false | 0.045592 | 0.045867 | 0.994018 | [
"s065153614",
"s676729406"
] |
u423665486 | p03633 | python | s776064443 | s945046919 | 178 | 17 | 38,256 | 3,060 | Accepted | Accepted | 90.45 | def gcd(a, b):
"""Compute the greatest common divisor of a and b"""
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
"""Compute the lowest common multiple of a and b"""
return a * b // gcd(a, b)
def resolve():
n = int(eval(input()))
t = [int(eval(input())) for _ in range(n)]
ans = t[0]
for i in t[1:]:
ans = lcm(ans, i)
print(ans)
resolve() | def resolve():
n = int(eval(input()))
ans = int(eval(input()))
for i in range(n-1):
v = int(eval(input()))
a = ans
b = v
r = a%b
while r:
a = b
b = r
r = a % b
ans = ans * v // b
print(ans)
resolve() | 18 | 15 | 366 | 220 | def gcd(a, b):
"""Compute the greatest common divisor of a and b"""
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
"""Compute the lowest common multiple of a and b"""
return a * b // gcd(a, b)
def resolve():
n = int(eval(input()))
t = [int(eval(input())) for _ in range(n)]
ans = t[0]
for i in t[1:]:
ans = lcm(ans, i)
print(ans)
resolve()
| def resolve():
n = int(eval(input()))
ans = int(eval(input()))
for i in range(n - 1):
v = int(eval(input()))
a = ans
b = v
r = a % b
while r:
a = b
b = r
r = a % b
ans = ans * v // b
print(ans)
resolve()
| false | 16.666667 | [
"-def gcd(a, b):",
"- \"\"\"Compute the greatest common divisor of a and b\"\"\"",
"- while b > 0:",
"- a, b = b, a % b",
"- return a",
"-",
"-",
"-def lcm(a, b):",
"- \"\"\"Compute the lowest common multiple of a and b\"\"\"",
"- return a * b // gcd(a, b)",
"-",
"-",
"- t = [int(eval(input())) for _ in range(n)]",
"- ans = t[0]",
"- for i in t[1:]:",
"- ans = lcm(ans, i)",
"+ ans = int(eval(input()))",
"+ for i in range(n - 1):",
"+ v = int(eval(input()))",
"+ a = ans",
"+ b = v",
"+ r = a % b",
"+ while r:",
"+ a = b",
"+ b = r",
"+ r = a % b",
"+ ans = ans * v // b"
] | false | 0.060929 | 0.042488 | 1.434034 | [
"s776064443",
"s945046919"
] |
u021548497 | p02862 | python | s186304612 | s060136465 | 899 | 702 | 45,580 | 44,148 | Accepted | Accepted | 21.91 | inf = 10**9+7
import sys
a = 0
def nCr(n, r):
r = min(r, n - r)
if r == 0: return 1;
if r == 1: return n;
numerator = [n - r + i + 1 for i in range(r)]
denominator = [i + 1 for i in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result = (result * numerator[k])%inf
return result
x, y = list(map(int, input().split()))
key = 0
if x == 2*y:
print((1))
sys.exit()
if y == 2*x:
print((1))
sys.exit()
while x>0 and y>0:
x, y = x-3, y-3
key += 1
if x == 2*y:
a = 1
break
if y == 2*x:
a = -1
break
if x < 0 or y < 0:
print((0))
sys.exit()
if a == 0:
print((0))
elif a == 1:
print((int(nCr(key*2+y ,key))))
else:
print((int(nCr(key*2+x ,key)))) | import sys
x, y = list(map(int, input().split()))
inf = 10**9+7
if (x+y)%3 != 0:
print((0))
sys.exit()
a = (2*x-y)//3
b = (2*y-x)//3
if a<0 or b<0:
print((0))
sys.exit()
def nCr(n, r):
r = min(r, n - r)
if r == 0: return 1;
if r == 1: return int(n%inf);
numerator = [n - r + i + 1 for i in range(r)]
denominator = [i + 1 for i in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result = (result*numerator[k])%inf
return int(result)
print((nCr(a+b, a))) | 50 | 37 | 1,071 | 818 | inf = 10**9 + 7
import sys
a = 0
def nCr(n, r):
r = min(r, n - r)
if r == 0:
return 1
if r == 1:
return n
numerator = [n - r + i + 1 for i in range(r)]
denominator = [i + 1 for i in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result = (result * numerator[k]) % inf
return result
x, y = list(map(int, input().split()))
key = 0
if x == 2 * y:
print((1))
sys.exit()
if y == 2 * x:
print((1))
sys.exit()
while x > 0 and y > 0:
x, y = x - 3, y - 3
key += 1
if x == 2 * y:
a = 1
break
if y == 2 * x:
a = -1
break
if x < 0 or y < 0:
print((0))
sys.exit()
if a == 0:
print((0))
elif a == 1:
print((int(nCr(key * 2 + y, key))))
else:
print((int(nCr(key * 2 + x, key))))
| import sys
x, y = list(map(int, input().split()))
inf = 10**9 + 7
if (x + y) % 3 != 0:
print((0))
sys.exit()
a = (2 * x - y) // 3
b = (2 * y - x) // 3
if a < 0 or b < 0:
print((0))
sys.exit()
def nCr(n, r):
r = min(r, n - r)
if r == 0:
return 1
if r == 1:
return int(n % inf)
numerator = [n - r + i + 1 for i in range(r)]
denominator = [i + 1 for i in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result = (result * numerator[k]) % inf
return int(result)
print((nCr(a + b, a)))
| false | 26 | [
"-inf = 10**9 + 7",
"-a = 0",
"+x, y = list(map(int, input().split()))",
"+inf = 10**9 + 7",
"+if (x + y) % 3 != 0:",
"+ print((0))",
"+ sys.exit()",
"+a = (2 * x - y) // 3",
"+b = (2 * y - x) // 3",
"+if a < 0 or b < 0:",
"+ print((0))",
"+ sys.exit()",
"- return n",
"+ return int(n % inf)",
"- return result",
"+ return int(result)",
"-x, y = list(map(int, input().split()))",
"-key = 0",
"-if x == 2 * y:",
"- print((1))",
"- sys.exit()",
"-if y == 2 * x:",
"- print((1))",
"- sys.exit()",
"-while x > 0 and y > 0:",
"- x, y = x - 3, y - 3",
"- key += 1",
"- if x == 2 * y:",
"- a = 1",
"- break",
"- if y == 2 * x:",
"- a = -1",
"- break",
"-if x < 0 or y < 0:",
"- print((0))",
"- sys.exit()",
"-if a == 0:",
"- print((0))",
"-elif a == 1:",
"- print((int(nCr(key * 2 + y, key))))",
"-else:",
"- print((int(nCr(key * 2 + x, key))))",
"+print((nCr(a + b, a)))"
] | false | 0.212653 | 0.172355 | 1.233812 | [
"s186304612",
"s060136465"
] |
u237958405 | p02773 | python | s785216727 | s934699128 | 770 | 658 | 45,788 | 32,096 | Accepted | Accepted | 14.55 | n = int(eval(input()))
mymap = {}
for x in range(n):
inp = eval(input())
if inp in mymap:
mymap[inp] += 1
else:
mymap[inp] = 0
sorted_map = sorted(list(mymap.items()), key=lambda kv: kv[1], reverse = True )
maxi = sorted_map[0][1]
# print(maxi)
answer = []
for x in sorted_map:
if x[1] == maxi:
answer.append(x[0])
else:
break
answer.sort()
for x in answer:
print(x) | n = int(eval(input()))
mymap = {}
maxi = 1
for x in range(n):
inp = eval(input())
if inp in mymap:
mymap[inp] += 1
if mymap[inp] > maxi:
maxi = mymap[inp]
else:
mymap[inp] = 1
answer = []
for x in mymap:
if mymap[x] == maxi:
answer.append(x)
answer.sort()
for x in answer:
print(x) | 26 | 22 | 393 | 310 | n = int(eval(input()))
mymap = {}
for x in range(n):
inp = eval(input())
if inp in mymap:
mymap[inp] += 1
else:
mymap[inp] = 0
sorted_map = sorted(list(mymap.items()), key=lambda kv: kv[1], reverse=True)
maxi = sorted_map[0][1]
# print(maxi)
answer = []
for x in sorted_map:
if x[1] == maxi:
answer.append(x[0])
else:
break
answer.sort()
for x in answer:
print(x)
| n = int(eval(input()))
mymap = {}
maxi = 1
for x in range(n):
inp = eval(input())
if inp in mymap:
mymap[inp] += 1
if mymap[inp] > maxi:
maxi = mymap[inp]
else:
mymap[inp] = 1
answer = []
for x in mymap:
if mymap[x] == maxi:
answer.append(x)
answer.sort()
for x in answer:
print(x)
| false | 15.384615 | [
"+maxi = 1",
"+ if mymap[inp] > maxi:",
"+ maxi = mymap[inp]",
"- mymap[inp] = 0",
"-sorted_map = sorted(list(mymap.items()), key=lambda kv: kv[1], reverse=True)",
"-maxi = sorted_map[0][1]",
"-# print(maxi)",
"+ mymap[inp] = 1",
"-for x in sorted_map:",
"- if x[1] == maxi:",
"- answer.append(x[0])",
"- else:",
"- break",
"+for x in mymap:",
"+ if mymap[x] == maxi:",
"+ answer.append(x)"
] | false | 0.039162 | 0.039229 | 0.998312 | [
"s785216727",
"s934699128"
] |
u667806071 | p00761 | python | s723292190 | s716905260 | 50 | 30 | 7,680 | 5,596 | Accepted | Accepted | 40 | while True:
n, d = list(map(int, input().split()))
if n == 0 and d == 0: break
a = [n]
cnt = 0
while True:
t = list(map(int, list(("{:0%d}"%d).format(n))))
n = int("".join(map(str, sorted(t, reverse=True)))) - int("".join(map(str, sorted(t))))
if n in a:
break
a.append(n)
cnt += 1
i = a.index(n)
print((i, n, cnt - i + 1)) | def solve(n, l):
results = [n]
for i in range(20):
s = list(("%0" + str(l) + "d") % n)
s.sort()
n = int("".join(s[::-1])) - int("".join(s))
if n in results:
break
results.append(n)
j = results.index(n)
print((j, n, i - j + 1))
while True:
n, l = list(map(int, input().split()))
if n == l == 0:
break
solve(n, l)
| 15 | 18 | 410 | 411 | while True:
n, d = list(map(int, input().split()))
if n == 0 and d == 0:
break
a = [n]
cnt = 0
while True:
t = list(map(int, list(("{:0%d}" % d).format(n))))
n = int("".join(map(str, sorted(t, reverse=True)))) - int(
"".join(map(str, sorted(t)))
)
if n in a:
break
a.append(n)
cnt += 1
i = a.index(n)
print((i, n, cnt - i + 1))
| def solve(n, l):
results = [n]
for i in range(20):
s = list(("%0" + str(l) + "d") % n)
s.sort()
n = int("".join(s[::-1])) - int("".join(s))
if n in results:
break
results.append(n)
j = results.index(n)
print((j, n, i - j + 1))
while True:
n, l = list(map(int, input().split()))
if n == l == 0:
break
solve(n, l)
| false | 16.666667 | [
"+def solve(n, l):",
"+ results = [n]",
"+ for i in range(20):",
"+ s = list((\"%0\" + str(l) + \"d\") % n)",
"+ s.sort()",
"+ n = int(\"\".join(s[::-1])) - int(\"\".join(s))",
"+ if n in results:",
"+ break",
"+ results.append(n)",
"+ j = results.index(n)",
"+ print((j, n, i - j + 1))",
"+",
"+",
"- n, d = list(map(int, input().split()))",
"- if n == 0 and d == 0:",
"+ n, l = list(map(int, input().split()))",
"+ if n == l == 0:",
"- a = [n]",
"- cnt = 0",
"- while True:",
"- t = list(map(int, list((\"{:0%d}\" % d).format(n))))",
"- n = int(\"\".join(map(str, sorted(t, reverse=True)))) - int(",
"- \"\".join(map(str, sorted(t)))",
"- )",
"- if n in a:",
"- break",
"- a.append(n)",
"- cnt += 1",
"- i = a.index(n)",
"- print((i, n, cnt - i + 1))",
"+ solve(n, l)"
] | false | 0.046591 | 0.046395 | 1.004222 | [
"s723292190",
"s716905260"
] |
u562935282 | p03157 | python | s269700117 | s053143548 | 1,492 | 478 | 12,728 | 72,696 | Accepted | Accepted | 67.96 | from collections import Counter
class UnionFind:
def __init__(self, n):
self.v = [-1 for _ in range(n)]
def find(self, x):
if self.v[x] < 0: # (負)は根
return x
else:
self.v[x] = self.find(self.v[x])
return self.v[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if -self.v[x] < -self.v[y]:
x, y = y, x
self.v[x] += self.v[y]
self.v[y] = x
def root(self, x):
return self.v[x] < 0
def size(self, x):
return -self.v[self.find(x)]
def main():
import sys
input = sys.stdin.readline
h, w = list(map(int, input().split()))
s = [input().rstrip() for _ in range(h)]
d = (1, 0), (-1, 0), (0, 1), (0, -1)
uf = UnionFind(h * w * 2)
for r in range(h):
for c in range(w):
id_ = (r * w + c) + (h * w if s[r][c] == '#' else 0)
for dr, dc in d:
nr = r + dr
if nr < 0 or h <= nr:
continue
nc = c + dc
if nc < 0 or w <= nc:
continue
if s[nr][nc] == s[r][c]:
continue
nid = (nr * w + nc) + (h * w if s[nr][nc] == '#' else 0)
uf.unite(id_, nid)
for r in range(h):
for c in range(w):
id_ = (r * w + c) + (h * w if s[r][c] == '#' else 0)
uf.find(id_)
# 葉の親が更新されていなかったために、連結成分の大きさが小さく判定されていた
checked = [False] * (h * w * 2)
ctr_dot = Counter(uf.v[:h * w])
ctr_sharp = Counter(uf.v[h * w:])
ret = 0
for r in range(h):
for c in range(w):
id_ = (r * w + c) + (h * w if s[r][c] == '#' else 0)
root = uf.find(id_)
if checked[root]:
continue
checked[root] = True
dot = ctr_dot[root]
sharp = ctr_sharp[root]
if root < h * w:
dot += 1
else:
sharp += 1
ret += dot * sharp
print(ret)
if __name__ == '__main__':
main()
| from collections import Counter
class UnionFind:
def __init__(self, n):
self.v = [-1] * n
def find(self, x):
if self.v[x] < 0:
return x
else:
self.v[x] = self.find(self.v[x])
return self.v[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
else:
if self.v[x] > self.v[y]:
x, y = y, x
self.v[x] += self.v[y]
self.v[y] = x
return True
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.v[self.find(x)]
def main():
import sys
input = sys.stdin.readline
h, w = list(map(int, input().split()))
s = [input().rstrip() for _ in range(h)]
d = (1, 0), (-1, 0), (0, 1), (0, -1)
uf = UnionFind(h * w * 2)
for r in range(h):
for c in range(w):
id_ = (r * w + c) + (h * w if s[r][c] == '#' else 0)
for dr, dc in d:
nr = r + dr
if nr < 0 or h <= nr:
continue
nc = c + dc
if nc < 0 or w <= nc:
continue
if s[nr][nc] == s[r][c]:
continue
nid = (nr * w + nc) + (h * w if s[nr][nc] == '#' else 0)
uf.unite(id_, nid)
for r in range(h):
for c in range(w):
id_ = (r * w + c) + (h * w if s[r][c] == '#' else 0)
uf.find(id_)
# 葉の親が更新されていなかったために、連結成分の大きさが小さく判定されていた
checked = [False] * (h * w * 2)
ctr_dot = Counter(uf.v[:h * w])
ctr_sharp = Counter(uf.v[h * w:])
ret = 0
for r in range(h):
for c in range(w):
id_ = (r * w + c) + (h * w if s[r][c] == '#' else 0)
root = uf.find(id_)
if checked[root]:
continue
checked[root] = True
dot = ctr_dot[root]
sharp = ctr_sharp[root]
if root < h * w:
dot += 1
else:
sharp += 1
ret += dot * sharp
print(ret)
if __name__ == '__main__':
main()
| 93 | 96 | 2,261 | 2,318 | from collections import Counter
class UnionFind:
def __init__(self, n):
self.v = [-1 for _ in range(n)]
def find(self, x):
if self.v[x] < 0: # (負)は根
return x
else:
self.v[x] = self.find(self.v[x])
return self.v[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if -self.v[x] < -self.v[y]:
x, y = y, x
self.v[x] += self.v[y]
self.v[y] = x
def root(self, x):
return self.v[x] < 0
def size(self, x):
return -self.v[self.find(x)]
def main():
import sys
input = sys.stdin.readline
h, w = list(map(int, input().split()))
s = [input().rstrip() for _ in range(h)]
d = (1, 0), (-1, 0), (0, 1), (0, -1)
uf = UnionFind(h * w * 2)
for r in range(h):
for c in range(w):
id_ = (r * w + c) + (h * w if s[r][c] == "#" else 0)
for dr, dc in d:
nr = r + dr
if nr < 0 or h <= nr:
continue
nc = c + dc
if nc < 0 or w <= nc:
continue
if s[nr][nc] == s[r][c]:
continue
nid = (nr * w + nc) + (h * w if s[nr][nc] == "#" else 0)
uf.unite(id_, nid)
for r in range(h):
for c in range(w):
id_ = (r * w + c) + (h * w if s[r][c] == "#" else 0)
uf.find(id_)
# 葉の親が更新されていなかったために、連結成分の大きさが小さく判定されていた
checked = [False] * (h * w * 2)
ctr_dot = Counter(uf.v[: h * w])
ctr_sharp = Counter(uf.v[h * w :])
ret = 0
for r in range(h):
for c in range(w):
id_ = (r * w + c) + (h * w if s[r][c] == "#" else 0)
root = uf.find(id_)
if checked[root]:
continue
checked[root] = True
dot = ctr_dot[root]
sharp = ctr_sharp[root]
if root < h * w:
dot += 1
else:
sharp += 1
ret += dot * sharp
print(ret)
if __name__ == "__main__":
main()
| from collections import Counter
class UnionFind:
def __init__(self, n):
self.v = [-1] * n
def find(self, x):
if self.v[x] < 0:
return x
else:
self.v[x] = self.find(self.v[x])
return self.v[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
else:
if self.v[x] > self.v[y]:
x, y = y, x
self.v[x] += self.v[y]
self.v[y] = x
return True
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.v[self.find(x)]
def main():
import sys
input = sys.stdin.readline
h, w = list(map(int, input().split()))
s = [input().rstrip() for _ in range(h)]
d = (1, 0), (-1, 0), (0, 1), (0, -1)
uf = UnionFind(h * w * 2)
for r in range(h):
for c in range(w):
id_ = (r * w + c) + (h * w if s[r][c] == "#" else 0)
for dr, dc in d:
nr = r + dr
if nr < 0 or h <= nr:
continue
nc = c + dc
if nc < 0 or w <= nc:
continue
if s[nr][nc] == s[r][c]:
continue
nid = (nr * w + nc) + (h * w if s[nr][nc] == "#" else 0)
uf.unite(id_, nid)
for r in range(h):
for c in range(w):
id_ = (r * w + c) + (h * w if s[r][c] == "#" else 0)
uf.find(id_)
# 葉の親が更新されていなかったために、連結成分の大きさが小さく判定されていた
checked = [False] * (h * w * 2)
ctr_dot = Counter(uf.v[: h * w])
ctr_sharp = Counter(uf.v[h * w :])
ret = 0
for r in range(h):
for c in range(w):
id_ = (r * w + c) + (h * w if s[r][c] == "#" else 0)
root = uf.find(id_)
if checked[root]:
continue
checked[root] = True
dot = ctr_dot[root]
sharp = ctr_sharp[root]
if root < h * w:
dot += 1
else:
sharp += 1
ret += dot * sharp
print(ret)
if __name__ == "__main__":
main()
| false | 3.125 | [
"- self.v = [-1 for _ in range(n)]",
"+ self.v = [-1] * n",
"- if self.v[x] < 0: # (負)は根",
"+ if self.v[x] < 0:",
"- return",
"- if -self.v[x] < -self.v[y]:",
"- x, y = y, x",
"- self.v[x] += self.v[y]",
"- self.v[y] = x",
"+ return False",
"+ else:",
"+ if self.v[x] > self.v[y]:",
"+ x, y = y, x",
"+ self.v[x] += self.v[y]",
"+ self.v[y] = x",
"+ return True",
"- def root(self, x):",
"- return self.v[x] < 0",
"+ def same(self, x, y):",
"+ return self.find(x) == self.find(y)"
] | false | 0.037613 | 0.041771 | 0.900462 | [
"s269700117",
"s053143548"
] |
u945181840 | p03682 | python | s901004225 | s151426315 | 1,404 | 1,201 | 71,516 | 35,556 | Accepted | Accepted | 14.46 | import sys
import numpy as np
read = sys.stdin.read
class UnionFind():
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
# root[x]<0ならそのノードが根かつその値が木の要素数
# rootノードでその木の要素数を記録する
self.root = [-1]*(n+1)
# 木をくっつける時にアンバランスにならないように調整する
self.rnk = [0]*(n+1)
# ノードxのrootノードを見つける
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
# ここで代入しておくことで、後の繰り返しを避ける
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
# 木の併合、入力は併合したい各ノード
def Unite(self, x, y):
# 入力ノードのrootノードを見つける
x = self.Find_Root(x)
y = self.Find_Root(y)
# すでに同じ木に属していた場合
if x == y:
return
# 違う木に属していた場合rnkを見てくっつける方を決める
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
# rnkが同じ(深さに差がない場合)は1増やす
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
# xとyが同じグループに属するか判断
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
# ノードxが属する木のサイズを返す
def Count(self, x):
return -self.root[self.Find_Root(x)]
N, *xy = list(map(int, read().split()))
xy = np.array(xy, np.int64).reshape(N, 2)
town = np.arange(N)
arg_x = np.argsort(xy[:, 0])
arg_y = np.argsort(xy[:, 1])
edges_x = (xy[arg_x[1:], 0] - xy[arg_x[:-1], 0]).tolist()
town_x = town[arg_x].tolist()
town_x = list(zip(town_x[1:], town_x[:-1]))
edges_y = (xy[arg_y[1:], 1] - xy[arg_y[:-1], 1]).tolist()
town_y = town[arg_y].tolist()
town_y = list(zip(town_y[1:], town_y[:-1]))
edges = list(zip(edges_x, town_x)) + list(zip(edges_y, town_y))
edges.sort()
tree = UnionFind(N)
answer = 0
for d, (t1, t2) in edges:
if tree.isSameGroup(t1, t2):
continue
tree.Unite(t1, t2)
answer += d
print(answer) | import sys
import numpy as np
read = sys.stdin.read
class UnionFind():
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
# root[x]<0ならそのノードが根かつその値が木の要素数
# rootノードでその木の要素数を記録する
self.root = [-1]*(n+1)
# 木をくっつける時にアンバランスにならないように調整する
self.rnk = [0]*(n+1)
# ノードxのrootノードを見つける
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
# ここで代入しておくことで、後の繰り返しを避ける
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
# 木の併合、入力は併合したい各ノード
def Unite(self, x, y):
# 入力ノードのrootノードを見つける
x = self.Find_Root(x)
y = self.Find_Root(y)
# すでに同じ木に属していた場合
if x == y:
return
# 違う木に属していた場合rnkを見てくっつける方を決める
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
# rnkが同じ(深さに差がない場合)は1増やす
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
# xとyが同じグループに属するか判断
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
# ノードxが属する木のサイズを返す
def Count(self, x):
return -self.root[self.Find_Root(x)]
N, *xy = list(map(int, read().split()))
xy = np.array(xy, np.int64).reshape(N, 2)
x = xy[:, 0]
y = xy[:, 1]
arg_x = np.argsort(x)
arg_y = np.argsort(y)
edges_x = x[arg_x[1:]] - x[arg_x[:-1]]
edges_y = y[arg_y[1:]] - y[arg_y[:-1]]
edges = np.concatenate([edges_x, edges_y])
towns_1 = np.concatenate([arg_x[:-1], arg_y[:-1]])
towns_2 = np.concatenate([arg_x[1:], arg_y[1:]])
arg_edges = np.argsort(edges)
graph = list(zip(edges[arg_edges], towns_1[arg_edges], towns_2[arg_edges]))
tree = UnionFind(N)
answer = 0
for d, t1, t2 in graph:
if tree.isSameGroup(t1, t2):
continue
tree.Unite(t1, t2)
answer += d
print(answer) | 83 | 83 | 2,062 | 2,044 | import sys
import numpy as np
read = sys.stdin.read
class UnionFind:
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
# root[x]<0ならそのノードが根かつその値が木の要素数
# rootノードでその木の要素数を記録する
self.root = [-1] * (n + 1)
# 木をくっつける時にアンバランスにならないように調整する
self.rnk = [0] * (n + 1)
# ノードxのrootノードを見つける
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
# ここで代入しておくことで、後の繰り返しを避ける
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
# 木の併合、入力は併合したい各ノード
def Unite(self, x, y):
# 入力ノードのrootノードを見つける
x = self.Find_Root(x)
y = self.Find_Root(y)
# すでに同じ木に属していた場合
if x == y:
return
# 違う木に属していた場合rnkを見てくっつける方を決める
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
# rnkが同じ(深さに差がない場合)は1増やす
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
# xとyが同じグループに属するか判断
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
# ノードxが属する木のサイズを返す
def Count(self, x):
return -self.root[self.Find_Root(x)]
N, *xy = list(map(int, read().split()))
xy = np.array(xy, np.int64).reshape(N, 2)
town = np.arange(N)
arg_x = np.argsort(xy[:, 0])
arg_y = np.argsort(xy[:, 1])
edges_x = (xy[arg_x[1:], 0] - xy[arg_x[:-1], 0]).tolist()
town_x = town[arg_x].tolist()
town_x = list(zip(town_x[1:], town_x[:-1]))
edges_y = (xy[arg_y[1:], 1] - xy[arg_y[:-1], 1]).tolist()
town_y = town[arg_y].tolist()
town_y = list(zip(town_y[1:], town_y[:-1]))
edges = list(zip(edges_x, town_x)) + list(zip(edges_y, town_y))
edges.sort()
tree = UnionFind(N)
answer = 0
for d, (t1, t2) in edges:
if tree.isSameGroup(t1, t2):
continue
tree.Unite(t1, t2)
answer += d
print(answer)
| import sys
import numpy as np
read = sys.stdin.read
class UnionFind:
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
# root[x]<0ならそのノードが根かつその値が木の要素数
# rootノードでその木の要素数を記録する
self.root = [-1] * (n + 1)
# 木をくっつける時にアンバランスにならないように調整する
self.rnk = [0] * (n + 1)
# ノードxのrootノードを見つける
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
# ここで代入しておくことで、後の繰り返しを避ける
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
# 木の併合、入力は併合したい各ノード
def Unite(self, x, y):
# 入力ノードのrootノードを見つける
x = self.Find_Root(x)
y = self.Find_Root(y)
# すでに同じ木に属していた場合
if x == y:
return
# 違う木に属していた場合rnkを見てくっつける方を決める
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
# rnkが同じ(深さに差がない場合)は1増やす
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
# xとyが同じグループに属するか判断
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
# ノードxが属する木のサイズを返す
def Count(self, x):
return -self.root[self.Find_Root(x)]
N, *xy = list(map(int, read().split()))
xy = np.array(xy, np.int64).reshape(N, 2)
x = xy[:, 0]
y = xy[:, 1]
arg_x = np.argsort(x)
arg_y = np.argsort(y)
edges_x = x[arg_x[1:]] - x[arg_x[:-1]]
edges_y = y[arg_y[1:]] - y[arg_y[:-1]]
edges = np.concatenate([edges_x, edges_y])
towns_1 = np.concatenate([arg_x[:-1], arg_y[:-1]])
towns_2 = np.concatenate([arg_x[1:], arg_y[1:]])
arg_edges = np.argsort(edges)
graph = list(zip(edges[arg_edges], towns_1[arg_edges], towns_2[arg_edges]))
tree = UnionFind(N)
answer = 0
for d, t1, t2 in graph:
if tree.isSameGroup(t1, t2):
continue
tree.Unite(t1, t2)
answer += d
print(answer)
| false | 0 | [
"-town = np.arange(N)",
"-arg_x = np.argsort(xy[:, 0])",
"-arg_y = np.argsort(xy[:, 1])",
"-edges_x = (xy[arg_x[1:], 0] - xy[arg_x[:-1], 0]).tolist()",
"-town_x = town[arg_x].tolist()",
"-town_x = list(zip(town_x[1:], town_x[:-1]))",
"-edges_y = (xy[arg_y[1:], 1] - xy[arg_y[:-1], 1]).tolist()",
"-town_y = town[arg_y].tolist()",
"-town_y = list(zip(town_y[1:], town_y[:-1]))",
"-edges = list(zip(edges_x, town_x)) + list(zip(edges_y, town_y))",
"-edges.sort()",
"+x = xy[:, 0]",
"+y = xy[:, 1]",
"+arg_x = np.argsort(x)",
"+arg_y = np.argsort(y)",
"+edges_x = x[arg_x[1:]] - x[arg_x[:-1]]",
"+edges_y = y[arg_y[1:]] - y[arg_y[:-1]]",
"+edges = np.concatenate([edges_x, edges_y])",
"+towns_1 = np.concatenate([arg_x[:-1], arg_y[:-1]])",
"+towns_2 = np.concatenate([arg_x[1:], arg_y[1:]])",
"+arg_edges = np.argsort(edges)",
"+graph = list(zip(edges[arg_edges], towns_1[arg_edges], towns_2[arg_edges]))",
"-for d, (t1, t2) in edges:",
"+for d, t1, t2 in graph:"
] | false | 0.252352 | 0.288937 | 0.87338 | [
"s901004225",
"s151426315"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.