user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
sequence | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
sequence |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u062147869 | p03782 | python | s996688955 | s254208187 | 1,503 | 1,246 | 42,608 | 42,608 | Accepted | Accepted | 17.1 | import sys
N,K=list(map(int,input().split()))
A=sorted([int(i) for i in input().split()])
sa=sum(A)
def f(x):
y=A[x]
if y>=K:
return True
L=set()
L.add(0)
dp=[False]*(K-y)
dp[0]=True
t=0
for i in range(N):
if i==x:
continue
s=A[i]
for k in range(t,-1,-1):
if not dp[k]:
continue
if k+s>=K:
continue
if k+s+y>=K:
return True
dp[k+s]=True
t=min(t+s,K-y-1)
return False
ma=N-1
mi=0
if not f(N-1):
print(N)
sys.exit()
if f(0):
print((0))
sys.exit()
while ma-mi>1:
#print(ma,mi)
a=(ma+mi)//2
if f(a):
ma=a
else:
mi=a
print(ma)
| import sys
N,K=list(map(int,input().split()))
A=sorted([int(i) for i in input().split()])
sa=sum(A)
def f(x):
y=A[x]
if y>=K:
return True
dp=[False]*(K)
dp[0]=True
t=0
for i in range(N):
if i==x:
continue
s=A[i]
for k in range(t,-1,-1):
if k+s>=K:
continue
dp[k+s]=dp[k+s]|dp[k]
t=min(t+s,K-1)
if sum(dp[K-y:K]):
return True
else:
return False
ma=N-1
mi=0
if not f(N-1):
print(N)
sys.exit()
if f(0):
print((0))
sys.exit()
while ma-mi>1:
#print(ma,mi)
a=(ma+mi)//2
if f(a):
ma=a
else:
mi=a
print(ma)
| 45 | 43 | 792 | 724 | import sys
N, K = list(map(int, input().split()))
A = sorted([int(i) for i in input().split()])
sa = sum(A)
def f(x):
y = A[x]
if y >= K:
return True
L = set()
L.add(0)
dp = [False] * (K - y)
dp[0] = True
t = 0
for i in range(N):
if i == x:
continue
s = A[i]
for k in range(t, -1, -1):
if not dp[k]:
continue
if k + s >= K:
continue
if k + s + y >= K:
return True
dp[k + s] = True
t = min(t + s, K - y - 1)
return False
ma = N - 1
mi = 0
if not f(N - 1):
print(N)
sys.exit()
if f(0):
print((0))
sys.exit()
while ma - mi > 1:
# print(ma,mi)
a = (ma + mi) // 2
if f(a):
ma = a
else:
mi = a
print(ma)
| import sys
N, K = list(map(int, input().split()))
A = sorted([int(i) for i in input().split()])
sa = sum(A)
def f(x):
y = A[x]
if y >= K:
return True
dp = [False] * (K)
dp[0] = True
t = 0
for i in range(N):
if i == x:
continue
s = A[i]
for k in range(t, -1, -1):
if k + s >= K:
continue
dp[k + s] = dp[k + s] | dp[k]
t = min(t + s, K - 1)
if sum(dp[K - y : K]):
return True
else:
return False
ma = N - 1
mi = 0
if not f(N - 1):
print(N)
sys.exit()
if f(0):
print((0))
sys.exit()
while ma - mi > 1:
# print(ma,mi)
a = (ma + mi) // 2
if f(a):
ma = a
else:
mi = a
print(ma)
| false | 4.444444 | [
"- L = set()",
"- L.add(0)",
"- dp = [False] * (K - y)",
"+ dp = [False] * (K)",
"- if not dp[k]:",
"- continue",
"- if k + s + y >= K:",
"- return True",
"- dp[k + s] = True",
"- t = min(t + s, K - y - 1)",
"- return False",
"+ dp[k + s] = dp[k + s] | dp[k]",
"+ t = min(t + s, K - 1)",
"+ if sum(dp[K - y : K]):",
"+ return True",
"+ else:",
"+ return False"
] | false | 0.041205 | 0.039055 | 1.05505 | [
"s996688955",
"s254208187"
] |
u052747412 | p02394 | python | s493339380 | s245240570 | 50 | 40 | 7,708 | 7,708 | Accepted | Accepted | 20 | input_line = eval(input())
# W,H,x,y,r
input_data = input_line.strip().split(' ')
W, H, x, y, r = [int(i) for i in input_data]
if x < 0 or y < 0:
print("No")
elif W >= (x+r) and H >= (y+r):
print("Yes")
else:
print("No") | input_data = input().split(' ')
W, H, x, y, r = [int(i) for i in input_data]
if ((x-r) >= 0 and (y-r) >= 0) and (W >= (x+r) and H >= (y+r)):
print("Yes")
else:
print("No") | 12 | 8 | 239 | 188 | input_line = eval(input())
# W,H,x,y,r
input_data = input_line.strip().split(" ")
W, H, x, y, r = [int(i) for i in input_data]
if x < 0 or y < 0:
print("No")
elif W >= (x + r) and H >= (y + r):
print("Yes")
else:
print("No")
| input_data = input().split(" ")
W, H, x, y, r = [int(i) for i in input_data]
if ((x - r) >= 0 and (y - r) >= 0) and (W >= (x + r) and H >= (y + r)):
print("Yes")
else:
print("No")
| false | 33.333333 | [
"-input_line = eval(input())",
"-# W,H,x,y,r",
"-input_data = input_line.strip().split(\" \")",
"+input_data = input().split(\" \")",
"-if x < 0 or y < 0:",
"- print(\"No\")",
"-elif W >= (x + r) and H >= (y + r):",
"+if ((x - r) >= 0 and (y - r) >= 0) and (W >= (x + r) and H >= (y + r)):"
] | false | 0.038973 | 0.039093 | 0.996921 | [
"s493339380",
"s245240570"
] |
u974231963 | p02802 | python | s230239831 | s819605263 | 299 | 260 | 4,596 | 10,360 | Accepted | Accepted | 13.04 |
n, m = list(map(int,input().split()))
AC = 0
# 各問題でACがとれているか確認用
# 0 = まだ正解していない, 1 = すでに正解済み
AC_list = [0] * (n + 1)
WA = 0
WA_List = [0] * (n + 1)
for i in range(m):
p,S = input().split()
p = int(p)
if S == "AC":
# 初めての正解
if AC_list[p] == 0:
AC += 1
WA += WA_List[p]
AC_list[p] = 1
# ※すでに正解している場合は加算しない
else:
# まだ正解していない場合
if AC_list[p] == 0:
WA_List[p] += 1
# ※すでに正解している場合は加算しない
print((AC,WA)) |
n, m = (int(x) for x in input().split())
# 0 = まだACなし, 1 = AC済み
ans_list = [0] * (n + 1)
# 誤った回数が記録され、ACのタイミングで加算
WA_list = [0] * (n + 1)
ans = 0
penalty = 0
for id in range(m):
# listを紐付けて要素を抜き出すことができる
query = list(map(str, input().split()))
# ACだった場合
if query[1] == 'AC':
if ans_list[int(query[0])] == 0 :
ans_list[int(query[0])] = 1
ans += 1
penalty = penalty + WA_list[int(query[0])]
# WAだった場合
else:
if ans_list[int(query[0])] == 0 :
WA_list[int(query[0])] += 1
print(("{0} {1}".format(ans, penalty))) | 28 | 26 | 531 | 622 | n, m = list(map(int, input().split()))
AC = 0
# 各問題でACがとれているか確認用
# 0 = まだ正解していない, 1 = すでに正解済み
AC_list = [0] * (n + 1)
WA = 0
WA_List = [0] * (n + 1)
for i in range(m):
p, S = input().split()
p = int(p)
if S == "AC":
# 初めての正解
if AC_list[p] == 0:
AC += 1
WA += WA_List[p]
AC_list[p] = 1
# ※すでに正解している場合は加算しない
else:
# まだ正解していない場合
if AC_list[p] == 0:
WA_List[p] += 1
# ※すでに正解している場合は加算しない
print((AC, WA))
| n, m = (int(x) for x in input().split())
# 0 = まだACなし, 1 = AC済み
ans_list = [0] * (n + 1)
# 誤った回数が記録され、ACのタイミングで加算
WA_list = [0] * (n + 1)
ans = 0
penalty = 0
for id in range(m):
# listを紐付けて要素を抜き出すことができる
query = list(map(str, input().split()))
# ACだった場合
if query[1] == "AC":
if ans_list[int(query[0])] == 0:
ans_list[int(query[0])] = 1
ans += 1
penalty = penalty + WA_list[int(query[0])]
# WAだった場合
else:
if ans_list[int(query[0])] == 0:
WA_list[int(query[0])] += 1
print(("{0} {1}".format(ans, penalty)))
| false | 7.142857 | [
"-n, m = list(map(int, input().split()))",
"-AC = 0",
"-# 各問題でACがとれているか確認用",
"-# 0 = まだ正解していない, 1 = すでに正解済み",
"-AC_list = [0] * (n + 1)",
"-WA = 0",
"-WA_List = [0] * (n + 1)",
"-for i in range(m):",
"- p, S = input().split()",
"- p = int(p)",
"- if S == \"AC\":",
"- # 初めての正解",
"- if AC_list[p] == 0:",
"- AC += 1",
"- WA += WA_List[p]",
"- AC_list[p] = 1",
"- # ※すでに正解している場合は加算しない",
"+n, m = (int(x) for x in input().split())",
"+# 0 = まだACなし, 1 = AC済み",
"+ans_list = [0] * (n + 1)",
"+# 誤った回数が記録され、ACのタイミングで加算",
"+WA_list = [0] * (n + 1)",
"+ans = 0",
"+penalty = 0",
"+for id in range(m):",
"+ # listを紐付けて要素を抜き出すことができる",
"+ query = list(map(str, input().split()))",
"+ # ACだった場合",
"+ if query[1] == \"AC\":",
"+ if ans_list[int(query[0])] == 0:",
"+ ans_list[int(query[0])] = 1",
"+ ans += 1",
"+ penalty = penalty + WA_list[int(query[0])]",
"+ # WAだった場合",
"- # まだ正解していない場合",
"- if AC_list[p] == 0:",
"- WA_List[p] += 1",
"- # ※すでに正解している場合は加算しない",
"-print((AC, WA))",
"+ if ans_list[int(query[0])] == 0:",
"+ WA_list[int(query[0])] += 1",
"+print((\"{0} {1}\".format(ans, penalty)))"
] | false | 0.095513 | 0.03687 | 2.590522 | [
"s230239831",
"s819605263"
] |
u022407960 | p02345 | python | s111871625 | s333330456 | 3,110 | 2,730 | 19,720 | 19,596 | Accepted | Accepted | 12.22 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2
output:
1
2
"""
import math
import sys
class SegmentTree(object):
__slots__ = ('dat', 'tree_range')
def __init__(self, n):
"""
Init a SegmentTree with update and find for range minimum queries.
"""
self.tree_range = pow(2, math.ceil(math.log2(n)))
self.dat = [float('inf')] * (2 * self.tree_range - 1)
# let A[k]=a
def update(self, k, a):
k += self.tree_range - 1
self.dat[k] = a
while k > 0:
k = (k - 1) // 2
self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2])
# get min(A[s] A[s+1] ... A[t])
def find(self, s, t, k=0, left=0, right=float('inf')):
if right <= s or t <= left:
return float('inf')
elif s <= left <= right <= t:
return self.dat[k]
else:
vl = self.find(s, t, k * 2 + 1, left, (left + right) // 2)
vr = self.find(s, t, k * 2 + 2, (left + right) // 2, right)
return min(vl, vr)
def cmd_exec(cmd_list, n_num):
case = SegmentTree(n_num)
end = pow(2, math.ceil(math.log2(n_num)))
init_max = pow(2, 31) - 1
for query in cmd_list:
cmd, ele_1, ele_2 = map(int, query)
if cmd == 0:
case.update(ele_1, ele_2)
elif cmd == 1:
assert ele_1 <= ele_2
res = case.find(s=ele_1, t=ele_2 + 1, right=end)
print(res) if not math.isinf(res) else print(init_max)
return None
def solve():
_input = sys.stdin.readlines()
n_num, q_num = map(int, _input[0].split())
q_list = map(lambda x: x.split(), _input[1:])
cmd_exec(q_list, n_num)
return None
if __name__ == '__main__':
solve()
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2
output:
1
2
"""
import math
import sys
INIT_MAX = pow(2, 31) - 1
class SegmentTree(object):
__slots__ = ('dat', 'tree_range')
def __init__(self, n):
"""
Init a SegmentTree with update and find for range minimum queries.
"""
self.tree_range = pow(2, math.ceil(math.log2(n)))
self.dat = [INIT_MAX] * (2 * self.tree_range - 1)
# let A[k]=a
def update(self, k, a):
k += self.tree_range - 1
self.dat[k] = a
while k > 0:
k = (k - 1) // 2
self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2])
# get min(A[s] A[s+1] ... A[t])
def find(self, s, t, k=0, left=0, right=float('inf')):
if right <= s or t <= left:
return INIT_MAX
elif s <= left <= right <= t:
return self.dat[k]
else:
vl = self.find(s, t, k * 2 + 1, left, (left + right) // 2)
vr = self.find(s, t, k * 2 + 2, (left + right) // 2, right)
return min(vl, vr)
def cmd_exec(cmd_list, n_num):
case = SegmentTree(n_num)
end = pow(2, math.ceil(math.log2(n_num)))
for query in cmd_list:
cmd, ele_1, ele_2 = list(map(int, query))
if cmd == 0:
case.update(ele_1, ele_2)
elif cmd == 1:
assert ele_1 <= ele_2
res = case.find(s=ele_1, t=ele_2 + 1, right=end)
print(res)
return None
def solve():
_input = sys.stdin.readlines()
n_num, q_num = list(map(int, _input[0].split()))
q_list = [x.split() for x in _input[1:]]
cmd_exec(q_list, n_num)
return None
if __name__ == '__main__':
solve() | 79 | 80 | 1,875 | 1,821 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2
output:
1
2
"""
import math
import sys
class SegmentTree(object):
__slots__ = ("dat", "tree_range")
def __init__(self, n):
"""
Init a SegmentTree with update and find for range minimum queries.
"""
self.tree_range = pow(2, math.ceil(math.log2(n)))
self.dat = [float("inf")] * (2 * self.tree_range - 1)
# let A[k]=a
def update(self, k, a):
k += self.tree_range - 1
self.dat[k] = a
while k > 0:
k = (k - 1) // 2
self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2])
# get min(A[s] A[s+1] ... A[t])
def find(self, s, t, k=0, left=0, right=float("inf")):
if right <= s or t <= left:
return float("inf")
elif s <= left <= right <= t:
return self.dat[k]
else:
vl = self.find(s, t, k * 2 + 1, left, (left + right) // 2)
vr = self.find(s, t, k * 2 + 2, (left + right) // 2, right)
return min(vl, vr)
def cmd_exec(cmd_list, n_num):
case = SegmentTree(n_num)
end = pow(2, math.ceil(math.log2(n_num)))
init_max = pow(2, 31) - 1
for query in cmd_list:
cmd, ele_1, ele_2 = map(int, query)
if cmd == 0:
case.update(ele_1, ele_2)
elif cmd == 1:
assert ele_1 <= ele_2
res = case.find(s=ele_1, t=ele_2 + 1, right=end)
print(res) if not math.isinf(res) else print(init_max)
return None
def solve():
_input = sys.stdin.readlines()
n_num, q_num = map(int, _input[0].split())
q_list = map(lambda x: x.split(), _input[1:])
cmd_exec(q_list, n_num)
return None
if __name__ == "__main__":
solve()
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2
output:
1
2
"""
import math
import sys
INIT_MAX = pow(2, 31) - 1
class SegmentTree(object):
__slots__ = ("dat", "tree_range")
def __init__(self, n):
"""
Init a SegmentTree with update and find for range minimum queries.
"""
self.tree_range = pow(2, math.ceil(math.log2(n)))
self.dat = [INIT_MAX] * (2 * self.tree_range - 1)
# let A[k]=a
def update(self, k, a):
k += self.tree_range - 1
self.dat[k] = a
while k > 0:
k = (k - 1) // 2
self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2])
# get min(A[s] A[s+1] ... A[t])
def find(self, s, t, k=0, left=0, right=float("inf")):
if right <= s or t <= left:
return INIT_MAX
elif s <= left <= right <= t:
return self.dat[k]
else:
vl = self.find(s, t, k * 2 + 1, left, (left + right) // 2)
vr = self.find(s, t, k * 2 + 2, (left + right) // 2, right)
return min(vl, vr)
def cmd_exec(cmd_list, n_num):
case = SegmentTree(n_num)
end = pow(2, math.ceil(math.log2(n_num)))
for query in cmd_list:
cmd, ele_1, ele_2 = list(map(int, query))
if cmd == 0:
case.update(ele_1, ele_2)
elif cmd == 1:
assert ele_1 <= ele_2
res = case.find(s=ele_1, t=ele_2 + 1, right=end)
print(res)
return None
def solve():
_input = sys.stdin.readlines()
n_num, q_num = list(map(int, _input[0].split()))
q_list = [x.split() for x in _input[1:]]
cmd_exec(q_list, n_num)
return None
if __name__ == "__main__":
solve()
| false | 1.25 | [
"+INIT_MAX = pow(2, 31) - 1",
"+",
"- self.dat = [float(\"inf\")] * (2 * self.tree_range - 1)",
"+ self.dat = [INIT_MAX] * (2 * self.tree_range - 1)",
"- return float(\"inf\")",
"+ return INIT_MAX",
"- init_max = pow(2, 31) - 1",
"- cmd, ele_1, ele_2 = map(int, query)",
"+ cmd, ele_1, ele_2 = list(map(int, query))",
"- print(res) if not math.isinf(res) else print(init_max)",
"+ print(res)",
"- n_num, q_num = map(int, _input[0].split())",
"- q_list = map(lambda x: x.split(), _input[1:])",
"+ n_num, q_num = list(map(int, _input[0].split()))",
"+ q_list = [x.split() for x in _input[1:]]"
] | false | 0.048675 | 0.048821 | 0.997011 | [
"s111871625",
"s333330456"
] |
u191394596 | p03476 | python | s691762436 | s035461044 | 1,216 | 1,072 | 56,280 | 52,952 | Accepted | Accepted | 11.84 | from bisect import bisect, bisect_left
size = 10 ** 5 + 1
is_prime = [True] * size
is_prime[0] = is_prime[1] = False
# √size まで
for i in range(2, 317):
j = 2 * i
while j < size:
is_prime[j] = False
j += i
# 先に like_numbers のテーブルを作っておく
like_numbers = [
i
for i, x in enumerate(is_prime)
if x and (i + 1) % 2 == 0 and is_prime[(i + 1) // 2]
]
Q = int(eval(input()))
for _ in range(Q):
l, r = list(map(int, input().split()))
# l から r まで探索してると 10^5 かかって間に合わないので二分探索を行う
print((bisect(like_numbers, r) - bisect_left(like_numbers, l)))
| from itertools import count
N = 10 ** 5 + 10
is_prime = [True] * N
is_prime[0] = is_prime[1] = False
# ほぼO(N)
for i in range(N):
if is_prime[i]:
for j in count(2 * i, i):
if j >= N:
break
is_prime[j] = False
is_2017_like_number = [0] * N
# O(N)
for i in range(N):
if i % 2 != 0 and is_prime[i] and is_prime[(i + 1) // 2]:
is_2017_like_number[i] = 1
cusum = [0] * (N + 1)
for i in range(N):
cusum[i + 1] = cusum[i] + is_2017_like_number[i]
Q = int(eval(input()))
for _ in range(Q):
l, r = list(map(int, input().split()))
r += 1 # 操作しやすいように [l, r) にする
print((cusum[r] - cusum[l]))
| 29 | 35 | 583 | 666 | from bisect import bisect, bisect_left
size = 10**5 + 1
is_prime = [True] * size
is_prime[0] = is_prime[1] = False
# √size まで
for i in range(2, 317):
j = 2 * i
while j < size:
is_prime[j] = False
j += i
# 先に like_numbers のテーブルを作っておく
like_numbers = [
i
for i, x in enumerate(is_prime)
if x and (i + 1) % 2 == 0 and is_prime[(i + 1) // 2]
]
Q = int(eval(input()))
for _ in range(Q):
l, r = list(map(int, input().split()))
# l から r まで探索してると 10^5 かかって間に合わないので二分探索を行う
print((bisect(like_numbers, r) - bisect_left(like_numbers, l)))
| from itertools import count
N = 10**5 + 10
is_prime = [True] * N
is_prime[0] = is_prime[1] = False
# ほぼO(N)
for i in range(N):
if is_prime[i]:
for j in count(2 * i, i):
if j >= N:
break
is_prime[j] = False
is_2017_like_number = [0] * N
# O(N)
for i in range(N):
if i % 2 != 0 and is_prime[i] and is_prime[(i + 1) // 2]:
is_2017_like_number[i] = 1
cusum = [0] * (N + 1)
for i in range(N):
cusum[i + 1] = cusum[i] + is_2017_like_number[i]
Q = int(eval(input()))
for _ in range(Q):
l, r = list(map(int, input().split()))
r += 1 # 操作しやすいように [l, r) にする
print((cusum[r] - cusum[l]))
| false | 17.142857 | [
"-from bisect import bisect, bisect_left",
"+from itertools import count",
"-size = 10**5 + 1",
"-is_prime = [True] * size",
"+N = 10**5 + 10",
"+is_prime = [True] * N",
"-# √size まで",
"-for i in range(2, 317):",
"- j = 2 * i",
"- while j < size:",
"- is_prime[j] = False",
"- j += i",
"-# 先に like_numbers のテーブルを作っておく",
"-like_numbers = [",
"- i",
"- for i, x in enumerate(is_prime)",
"- if x and (i + 1) % 2 == 0 and is_prime[(i + 1) // 2]",
"-]",
"+# ほぼO(N)",
"+for i in range(N):",
"+ if is_prime[i]:",
"+ for j in count(2 * i, i):",
"+ if j >= N:",
"+ break",
"+ is_prime[j] = False",
"+is_2017_like_number = [0] * N",
"+# O(N)",
"+for i in range(N):",
"+ if i % 2 != 0 and is_prime[i] and is_prime[(i + 1) // 2]:",
"+ is_2017_like_number[i] = 1",
"+cusum = [0] * (N + 1)",
"+for i in range(N):",
"+ cusum[i + 1] = cusum[i] + is_2017_like_number[i]",
"- # l から r まで探索してると 10^5 かかって間に合わないので二分探索を行う",
"- print((bisect(like_numbers, r) - bisect_left(like_numbers, l)))",
"+ r += 1 # 操作しやすいように [l, r) にする",
"+ print((cusum[r] - cusum[l]))"
] | false | 0.190045 | 0.225234 | 0.843769 | [
"s691762436",
"s035461044"
] |
u347640436 | p03167 | python | s238798327 | s054891061 | 1,037 | 452 | 49,564 | 49,532 | Accepted | Accepted | 56.41 | # 配るDP
H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
m = 1000000007
dp = [[0] * W for _ in range(H)]
dp[0][0] = 1
for h in range(H - 1):
for w in range(W - 1):
if a[h][w] == '#':
continue
if a[h][w + 1] != '#':
dp[h][w + 1] = (dp[h][w + 1] + dp[h][w]) % m
if a[h + 1][w] != '#':
dp[h + 1][w] = (dp[h + 1][w] + dp[h][w]) % m
if a[h][W - 1] == '#':
continue
if a[h + 1][W - 1] != '#':
dp[h + 1][W - 1] = (dp[h + 1][W - 1] + dp[h][W - 1]) % m
for w in range(W - 1):
if a[H - 1][w] == '#':
continue
if a[H - 1][w + 1] != '#':
dp[H - 1][w + 1] = (dp[H - 1][w + 1] + dp[H - 1][w]) % m
print((dp[H - 1][W - 1]))
| # 貰うDP
H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
m = 1000000007
dp = [[0] * W for _ in range(H)]
dp[0][0] = 1
for w in range(1, W):
if a[0][w] != '#':
dp[0][w] = dp[0][w - 1]
for h in range(1, H):
if a[h][0] != '#':
dp[h][0] = dp[h - 1][0]
for w in range(1, W):
if a[h][w] != '#':
dp[h][w] = (dp[h][w - 1] + dp[h - 1][w]) % m
print((dp[H - 1][W - 1]))
| 27 | 20 | 763 | 444 | # 配るDP
H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
m = 1000000007
dp = [[0] * W for _ in range(H)]
dp[0][0] = 1
for h in range(H - 1):
for w in range(W - 1):
if a[h][w] == "#":
continue
if a[h][w + 1] != "#":
dp[h][w + 1] = (dp[h][w + 1] + dp[h][w]) % m
if a[h + 1][w] != "#":
dp[h + 1][w] = (dp[h + 1][w] + dp[h][w]) % m
if a[h][W - 1] == "#":
continue
if a[h + 1][W - 1] != "#":
dp[h + 1][W - 1] = (dp[h + 1][W - 1] + dp[h][W - 1]) % m
for w in range(W - 1):
if a[H - 1][w] == "#":
continue
if a[H - 1][w + 1] != "#":
dp[H - 1][w + 1] = (dp[H - 1][w + 1] + dp[H - 1][w]) % m
print((dp[H - 1][W - 1]))
| # 貰うDP
H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
m = 1000000007
dp = [[0] * W for _ in range(H)]
dp[0][0] = 1
for w in range(1, W):
if a[0][w] != "#":
dp[0][w] = dp[0][w - 1]
for h in range(1, H):
if a[h][0] != "#":
dp[h][0] = dp[h - 1][0]
for w in range(1, W):
if a[h][w] != "#":
dp[h][w] = (dp[h][w - 1] + dp[h - 1][w]) % m
print((dp[H - 1][W - 1]))
| false | 25.925926 | [
"-# 配るDP",
"+# 貰うDP",
"-for h in range(H - 1):",
"- for w in range(W - 1):",
"- if a[h][w] == \"#\":",
"- continue",
"- if a[h][w + 1] != \"#\":",
"- dp[h][w + 1] = (dp[h][w + 1] + dp[h][w]) % m",
"- if a[h + 1][w] != \"#\":",
"- dp[h + 1][w] = (dp[h + 1][w] + dp[h][w]) % m",
"- if a[h][W - 1] == \"#\":",
"- continue",
"- if a[h + 1][W - 1] != \"#\":",
"- dp[h + 1][W - 1] = (dp[h + 1][W - 1] + dp[h][W - 1]) % m",
"-for w in range(W - 1):",
"- if a[H - 1][w] == \"#\":",
"- continue",
"- if a[H - 1][w + 1] != \"#\":",
"- dp[H - 1][w + 1] = (dp[H - 1][w + 1] + dp[H - 1][w]) % m",
"+for w in range(1, W):",
"+ if a[0][w] != \"#\":",
"+ dp[0][w] = dp[0][w - 1]",
"+for h in range(1, H):",
"+ if a[h][0] != \"#\":",
"+ dp[h][0] = dp[h - 1][0]",
"+ for w in range(1, W):",
"+ if a[h][w] != \"#\":",
"+ dp[h][w] = (dp[h][w - 1] + dp[h - 1][w]) % m"
] | false | 0.040567 | 0.033889 | 1.197064 | [
"s238798327",
"s054891061"
] |
u747602774 | p02802 | python | s524243216 | s250124425 | 349 | 294 | 27,568 | 3,888 | Accepted | Accepted | 15.76 | N,M = list(map(int,input().split()))
sub = [list(input().split()) for i in range(M)]
wa = [0 for i in range(N)]
ac = [0 for i in range(N)]
waans = 0
acans = 0
for i in range(M):
if sub[i][1] == 'AC' and ac[int(sub[i][0])-1] == 0:
acans += 1
waans += wa[int(sub[i][0])-1]
ac[int(sub[i][0])-1] = 1
elif sub[i][1] == 'WA' and ac[int(sub[i][0])-1] == 0:
wa[int(sub[i][0])-1] += 1
print((acans,waans)) | N,M = list(map(int,input().split()))
pro = [0 for i in range(N+1)]
ac,wa = 0,0
for i in range(M):
p,s = input().split()
p = int(p)
if s == 'AC':
if pro[p] != -1:
ac += 1
wa += pro[p]
pro[p] = -1
else:
if pro[p] != -1:
pro[p] += 1
print((ac,wa))
| 19 | 15 | 451 | 331 | N, M = list(map(int, input().split()))
sub = [list(input().split()) for i in range(M)]
wa = [0 for i in range(N)]
ac = [0 for i in range(N)]
waans = 0
acans = 0
for i in range(M):
if sub[i][1] == "AC" and ac[int(sub[i][0]) - 1] == 0:
acans += 1
waans += wa[int(sub[i][0]) - 1]
ac[int(sub[i][0]) - 1] = 1
elif sub[i][1] == "WA" and ac[int(sub[i][0]) - 1] == 0:
wa[int(sub[i][0]) - 1] += 1
print((acans, waans))
| N, M = list(map(int, input().split()))
pro = [0 for i in range(N + 1)]
ac, wa = 0, 0
for i in range(M):
p, s = input().split()
p = int(p)
if s == "AC":
if pro[p] != -1:
ac += 1
wa += pro[p]
pro[p] = -1
else:
if pro[p] != -1:
pro[p] += 1
print((ac, wa))
| false | 21.052632 | [
"-sub = [list(input().split()) for i in range(M)]",
"-wa = [0 for i in range(N)]",
"-ac = [0 for i in range(N)]",
"-waans = 0",
"-acans = 0",
"+pro = [0 for i in range(N + 1)]",
"+ac, wa = 0, 0",
"- if sub[i][1] == \"AC\" and ac[int(sub[i][0]) - 1] == 0:",
"- acans += 1",
"- waans += wa[int(sub[i][0]) - 1]",
"- ac[int(sub[i][0]) - 1] = 1",
"- elif sub[i][1] == \"WA\" and ac[int(sub[i][0]) - 1] == 0:",
"- wa[int(sub[i][0]) - 1] += 1",
"-print((acans, waans))",
"+ p, s = input().split()",
"+ p = int(p)",
"+ if s == \"AC\":",
"+ if pro[p] != -1:",
"+ ac += 1",
"+ wa += pro[p]",
"+ pro[p] = -1",
"+ else:",
"+ if pro[p] != -1:",
"+ pro[p] += 1",
"+print((ac, wa))"
] | false | 0.074411 | 0.03708 | 2.006761 | [
"s524243216",
"s250124425"
] |
u250664216 | p02948 | python | s206763106 | s406232878 | 442 | 379 | 26,872 | 31,652 | Accepted | Accepted | 14.25 | import sys
import heapq
input = sys.stdin.readline
n,m = list(map(int, input().split()))
job_list = []
for i in range(n):
a,b = list(map(int, input().split()))
job_list.append((a,b))
job_list.sort(key=lambda x:x[0])
# print(job_list)
hq = []
max_income = 0
j = 0
for i in range(1,m+1):
while j < n and job_list[j][0] <= i:
heapq.heappush(hq, (-job_list[j][1],job_list[j][0]))
j += 1
if len(hq) < 1:
continue
b_i, a_i = heapq.heappop(hq)
max_income += -b_i
print(max_income) | import sys
import heapq
input = sys.stdin.readline
n,m = list(map(int, input().split()))
job_list = {}
for i in range(n):
a,b = list(map(int, input().split()))
if a in job_list:
job_list[a].append((-b,a))
else:
job_list[a] = [(-b,a)]
# job_list.sort(key=lambda x:x[0])
# print(job_list)
hq = []
max_income = 0
# j = 0
for i in range(1,m+1):
if i in job_list:
for j in job_list[i]:
heapq.heappush(hq, j)
# while j < n and job_list[j][0] <= i:
# heapq.heappush(hq, (-job_list[j][1],job_list[j][0]))
# j += 1
if len(hq) < 1:
continue
b_i, a_i = heapq.heappop(hq)
max_income += -b_i
print(max_income) | 24 | 30 | 534 | 707 | import sys
import heapq
input = sys.stdin.readline
n, m = list(map(int, input().split()))
job_list = []
for i in range(n):
a, b = list(map(int, input().split()))
job_list.append((a, b))
job_list.sort(key=lambda x: x[0])
# print(job_list)
hq = []
max_income = 0
j = 0
for i in range(1, m + 1):
while j < n and job_list[j][0] <= i:
heapq.heappush(hq, (-job_list[j][1], job_list[j][0]))
j += 1
if len(hq) < 1:
continue
b_i, a_i = heapq.heappop(hq)
max_income += -b_i
print(max_income)
| import sys
import heapq
input = sys.stdin.readline
n, m = list(map(int, input().split()))
job_list = {}
for i in range(n):
a, b = list(map(int, input().split()))
if a in job_list:
job_list[a].append((-b, a))
else:
job_list[a] = [(-b, a)]
# job_list.sort(key=lambda x:x[0])
# print(job_list)
hq = []
max_income = 0
# j = 0
for i in range(1, m + 1):
if i in job_list:
for j in job_list[i]:
heapq.heappush(hq, j)
# while j < n and job_list[j][0] <= i:
# heapq.heappush(hq, (-job_list[j][1],job_list[j][0]))
# j += 1
if len(hq) < 1:
continue
b_i, a_i = heapq.heappop(hq)
max_income += -b_i
print(max_income)
| false | 20 | [
"-job_list = []",
"+job_list = {}",
"- job_list.append((a, b))",
"-job_list.sort(key=lambda x: x[0])",
"+ if a in job_list:",
"+ job_list[a].append((-b, a))",
"+ else:",
"+ job_list[a] = [(-b, a)]",
"+# job_list.sort(key=lambda x:x[0])",
"-j = 0",
"+# j = 0",
"- while j < n and job_list[j][0] <= i:",
"- heapq.heappush(hq, (-job_list[j][1], job_list[j][0]))",
"- j += 1",
"+ if i in job_list:",
"+ for j in job_list[i]:",
"+ heapq.heappush(hq, j)",
"+ # while j < n and job_list[j][0] <= i:",
"+ # heapq.heappush(hq, (-job_list[j][1],job_list[j][0]))",
"+ # j += 1"
] | false | 0.043463 | 0.046966 | 0.925421 | [
"s206763106",
"s406232878"
] |
u188827677 | p02773 | python | s653375292 | s718317207 | 692 | 630 | 44,268 | 35,828 | Accepted | Accepted | 8.96 | from collections import Counter
n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
count = Counter(s)
maxNum = max(count.values())
t = sorted(list(set(s)))
for i in t:
if count[i] == maxNum:
print(i) | from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
count = Counter(s)
t = max(count.values())
ans = []
for i in count.items():
if i[1] == t:
ans.append(i[0])
print(*sorted(ans), sep='\n')
| 10 | 11 | 213 | 235 | from collections import Counter
n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
count = Counter(s)
maxNum = max(count.values())
t = sorted(list(set(s)))
for i in t:
if count[i] == maxNum:
print(i)
| from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
count = Counter(s)
t = max(count.values())
ans = []
for i in count.items():
if i[1] == t:
ans.append(i[0])
print(*sorted(ans), sep="\n")
| false | 9.090909 | [
"-n = int(eval(input()))",
"-s = [eval(input()) for _ in range(n)]",
"+n = int(input())",
"+s = [input() for _ in range(n)]",
"-maxNum = max(count.values())",
"-t = sorted(list(set(s)))",
"-for i in t:",
"- if count[i] == maxNum:",
"- print(i)",
"+t = max(count.values())",
"+ans = []",
"+for i in count.items():",
"+ if i[1] == t:",
"+ ans.append(i[0])",
"+print(*sorted(ans), sep=\"\\n\")"
] | false | 0.04262 | 0.043147 | 0.987781 | [
"s653375292",
"s718317207"
] |
u432805419 | p03826 | python | s894850556 | s715549474 | 21 | 18 | 3,316 | 2,940 | Accepted | Accepted | 14.29 | a = list(map(int,input().split()))
x = a[0] * a[1]
y = a[2] * a[3]
if x >= y:
print(x)
else:
print(y) | a = list(map(int,input().split()))
b = a[0] * a[1]
c = a[2] * a[3]
if b > c:
print(b)
else:
print(c) | 7 | 8 | 111 | 112 | a = list(map(int, input().split()))
x = a[0] * a[1]
y = a[2] * a[3]
if x >= y:
print(x)
else:
print(y)
| a = list(map(int, input().split()))
b = a[0] * a[1]
c = a[2] * a[3]
if b > c:
print(b)
else:
print(c)
| false | 12.5 | [
"-x = a[0] * a[1]",
"-y = a[2] * a[3]",
"-if x >= y:",
"- print(x)",
"+b = a[0] * a[1]",
"+c = a[2] * a[3]",
"+if b > c:",
"+ print(b)",
"- print(y)",
"+ print(c)"
] | false | 0.07779 | 0.042025 | 1.851039 | [
"s894850556",
"s715549474"
] |
u350093546 | p03545 | python | s881442006 | s312367891 | 244 | 26 | 61,156 | 9,204 | Accepted | Accepted | 89.34 | a=list(input())
for i in range(4):
a[i]=int(a[i])
x=sum(a)-7
dict={0:'+',1:'-'}
ans=0
for i in range(2):
for j in range(2):
for k in range(2):
if x==(i*a[1]+j*a[2]+k*a[3])*2:
print(a[0],dict[i],a[1],dict[j],a[2],dict[k],a[3],'=7',sep='')
ans=1
if ans==1:
break
if ans==1:
break
if ans==1:
break
| import itertools
x=list(eval(input()))
for lst in itertools.product(['+','-'],repeat=3):
sum=int(x[0])
for i in range(3):
if lst[i]=='+':
sum+=int(x[i+1])
else:
sum-=int(x[i+1])
if sum==7:
print((x[0]+lst[0]+x[1]+lst[1]+x[2]+lst[2]+x[3]+'=7'))
break | 18 | 13 | 382 | 288 | a = list(input())
for i in range(4):
a[i] = int(a[i])
x = sum(a) - 7
dict = {0: "+", 1: "-"}
ans = 0
for i in range(2):
for j in range(2):
for k in range(2):
if x == (i * a[1] + j * a[2] + k * a[3]) * 2:
print(a[0], dict[i], a[1], dict[j], a[2], dict[k], a[3], "=7", sep="")
ans = 1
if ans == 1:
break
if ans == 1:
break
if ans == 1:
break
| import itertools
x = list(eval(input()))
for lst in itertools.product(["+", "-"], repeat=3):
sum = int(x[0])
for i in range(3):
if lst[i] == "+":
sum += int(x[i + 1])
else:
sum -= int(x[i + 1])
if sum == 7:
print((x[0] + lst[0] + x[1] + lst[1] + x[2] + lst[2] + x[3] + "=7"))
break
| false | 27.777778 | [
"-a = list(input())",
"-for i in range(4):",
"- a[i] = int(a[i])",
"-x = sum(a) - 7",
"-dict = {0: \"+\", 1: \"-\"}",
"-ans = 0",
"-for i in range(2):",
"- for j in range(2):",
"- for k in range(2):",
"- if x == (i * a[1] + j * a[2] + k * a[3]) * 2:",
"- print(a[0], dict[i], a[1], dict[j], a[2], dict[k], a[3], \"=7\", sep=\"\")",
"- ans = 1",
"- if ans == 1:",
"- break",
"- if ans == 1:",
"- break",
"- if ans == 1:",
"+import itertools",
"+",
"+x = list(eval(input()))",
"+for lst in itertools.product([\"+\", \"-\"], repeat=3):",
"+ sum = int(x[0])",
"+ for i in range(3):",
"+ if lst[i] == \"+\":",
"+ sum += int(x[i + 1])",
"+ else:",
"+ sum -= int(x[i + 1])",
"+ if sum == 7:",
"+ print((x[0] + lst[0] + x[1] + lst[1] + x[2] + lst[2] + x[3] + \"=7\"))"
] | false | 0.046325 | 0.043797 | 1.057742 | [
"s881442006",
"s312367891"
] |
u606045429 | p03681 | python | s664816798 | s420653472 | 41 | 29 | 3,060 | 3,060 | Accepted | Accepted | 29.27 | N, M = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
def mod_fact(n, mod = 10 ** 9 + 7):
result = 1
for i in range(2, n + 1):
result = (result * i) % mod
return result
if N == M:
print(((2 * mod_fact(N) * mod_fact(M)) % mod))
elif abs(N - M) == 1:
print(((mod_fact(N) * mod_fact(M)) % mod))
else:
print((0))
| def mod_fact(n, mod):
ans = 1
for i in range(2, n + 1):
ans = ans * i % mod
return ans
mod = 10 ** 9 + 7
N, M = list(map(int, input().split()))
if N == M:
print((2 * mod_fact(N, mod) ** 2 % mod))
elif abs(N - M) == 1:
print((mod_fact(min(M, N), mod) ** 2 * max(M, N) % mod))
else:
print((0))
| 16 | 16 | 358 | 330 | N, M = [int(i) for i in input().split()]
mod = 10**9 + 7
def mod_fact(n, mod=10**9 + 7):
result = 1
for i in range(2, n + 1):
result = (result * i) % mod
return result
if N == M:
print(((2 * mod_fact(N) * mod_fact(M)) % mod))
elif abs(N - M) == 1:
print(((mod_fact(N) * mod_fact(M)) % mod))
else:
print((0))
| def mod_fact(n, mod):
ans = 1
for i in range(2, n + 1):
ans = ans * i % mod
return ans
mod = 10**9 + 7
N, M = list(map(int, input().split()))
if N == M:
print((2 * mod_fact(N, mod) ** 2 % mod))
elif abs(N - M) == 1:
print((mod_fact(min(M, N), mod) ** 2 * max(M, N) % mod))
else:
print((0))
| false | 0 | [
"-N, M = [int(i) for i in input().split()]",
"-mod = 10**9 + 7",
"+def mod_fact(n, mod):",
"+ ans = 1",
"+ for i in range(2, n + 1):",
"+ ans = ans * i % mod",
"+ return ans",
"-def mod_fact(n, mod=10**9 + 7):",
"- result = 1",
"- for i in range(2, n + 1):",
"- result = (result * i) % mod",
"- return result",
"-",
"-",
"+mod = 10**9 + 7",
"+N, M = list(map(int, input().split()))",
"- print(((2 * mod_fact(N) * mod_fact(M)) % mod))",
"+ print((2 * mod_fact(N, mod) ** 2 % mod))",
"- print(((mod_fact(N) * mod_fact(M)) % mod))",
"+ print((mod_fact(min(M, N), mod) ** 2 * max(M, N) % mod))"
] | false | 0.040007 | 0.042309 | 0.945584 | [
"s664816798",
"s420653472"
] |
u274504193 | p02622 | python | s279704191 | s345553426 | 65 | 58 | 9,404 | 9,248 | Accepted | Accepted | 10.77 | s = eval(input())
t = eval(input())
count = 0
for i in range(len(s)):
if s[i] != t[i]:
count += 1
print(count)
| s = eval(input())
t = eval(input())
count = 0
for i in range(len(s)):
count += s[i] != t[i]
print(count)
| 7 | 6 | 111 | 100 | s = eval(input())
t = eval(input())
count = 0
for i in range(len(s)):
if s[i] != t[i]:
count += 1
print(count)
| s = eval(input())
t = eval(input())
count = 0
for i in range(len(s)):
count += s[i] != t[i]
print(count)
| false | 14.285714 | [
"- if s[i] != t[i]:",
"- count += 1",
"+ count += s[i] != t[i]"
] | false | 0.076006 | 0.077812 | 0.976791 | [
"s279704191",
"s345553426"
] |
u167681750 | p03095 | python | s328691605 | s862524392 | 41 | 27 | 4,204 | 3,820 | Accepted | Accepted | 34.15 | from collections import *
from functools import *
n = int(eval(input()))
s = eval(input())
counter_s = [i[1] + 1 for i in Counter(s).most_common()]
ans = reduce(lambda x, y: (x * y) % (10 ** 9 + 7), counter_s)
print((ans - 1)) | from collections import *
from functools import *
n = int(eval(input()))
s = eval(input())
counter_s = [x + 1 for x in list(Counter(s).values())]
ans = reduce(lambda x, y: (x * y) % (10 ** 9 + 7), counter_s)
print((ans - 1)) | 10 | 10 | 224 | 221 | from collections import *
from functools import *
n = int(eval(input()))
s = eval(input())
counter_s = [i[1] + 1 for i in Counter(s).most_common()]
ans = reduce(lambda x, y: (x * y) % (10**9 + 7), counter_s)
print((ans - 1))
| from collections import *
from functools import *
n = int(eval(input()))
s = eval(input())
counter_s = [x + 1 for x in list(Counter(s).values())]
ans = reduce(lambda x, y: (x * y) % (10**9 + 7), counter_s)
print((ans - 1))
| false | 0 | [
"-counter_s = [i[1] + 1 for i in Counter(s).most_common()]",
"+counter_s = [x + 1 for x in list(Counter(s).values())]"
] | false | 0.044219 | 0.095233 | 0.464324 | [
"s328691605",
"s862524392"
] |
u644907318 | p03378 | python | s882178813 | s166198222 | 179 | 72 | 38,288 | 61,712 | Accepted | Accepted | 59.78 | N,M,X = list(map(int,input().split()))
A = list(map(int,input().split()))
cnt = 0
for i in range(X,N+1):
if i in A:
cnt += 1
cntmin = cnt
cnt = 0
for i in range(X,-1,-1):
if i in A:
cnt += 1
cntmin = min(cntmin,cnt)
print(cntmin) | N,M,X = list(map(int,input().split()))
A = list(map(int,input().split()))
cnt = 0
for i in range(M):
if X>A[i]:
cnt += 1
print((min(cnt,M-cnt))) | 13 | 7 | 259 | 154 | N, M, X = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = 0
for i in range(X, N + 1):
if i in A:
cnt += 1
cntmin = cnt
cnt = 0
for i in range(X, -1, -1):
if i in A:
cnt += 1
cntmin = min(cntmin, cnt)
print(cntmin)
| N, M, X = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = 0
for i in range(M):
if X > A[i]:
cnt += 1
print((min(cnt, M - cnt)))
| false | 46.153846 | [
"-for i in range(X, N + 1):",
"- if i in A:",
"+for i in range(M):",
"+ if X > A[i]:",
"-cntmin = cnt",
"-cnt = 0",
"-for i in range(X, -1, -1):",
"- if i in A:",
"- cnt += 1",
"-cntmin = min(cntmin, cnt)",
"-print(cntmin)",
"+print((min(cnt, M - cnt)))"
] | false | 0.039347 | 0.043287 | 0.908995 | [
"s882178813",
"s166198222"
] |
u652737716 | p03474 | python | s591327179 | s979554081 | 25 | 23 | 3,444 | 3,188 | Accepted | Accepted | 8 | import re
A, B = [int(x) for x in input().split()]
S = eval(input())
match = re.match('^[0-9]{' + str(A) + '}-[0-9]{' + str(B) + '}$', S)
if match:
print('Yes')
else:
print('No')
| import re
A, B = [x for x in input().split()]
print(('Yes' if re.match('^[0-9]{' + A + '}-[0-9]{' + B + '}$', eval(input())) else 'No'))
| 11 | 3 | 191 | 131 | import re
A, B = [int(x) for x in input().split()]
S = eval(input())
match = re.match("^[0-9]{" + str(A) + "}-[0-9]{" + str(B) + "}$", S)
if match:
print("Yes")
else:
print("No")
| import re
A, B = [x for x in input().split()]
print(
("Yes" if re.match("^[0-9]{" + A + "}-[0-9]{" + B + "}$", eval(input())) else "No")
)
| false | 72.727273 | [
"-A, B = [int(x) for x in input().split()]",
"-S = eval(input())",
"-match = re.match(\"^[0-9]{\" + str(A) + \"}-[0-9]{\" + str(B) + \"}$\", S)",
"-if match:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+A, B = [x for x in input().split()]",
"+print(",
"+ (\"Yes\" if re.match(\"^[0-9]{\" + A + \"}-[0-9]{\" + B + \"}$\", eval(input())) else \"No\")",
"+)"
] | false | 0.048084 | 0.052201 | 0.921147 | [
"s591327179",
"s979554081"
] |
u291766461 | p03438 | python | s931145850 | s018755487 | 28 | 25 | 4,600 | 4,596 | Accepted | Accepted | 10.71 | import math
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sum_A = sum(A)
sum_B = sum(B)
cnt1 = sum_B - sum_A
cnt2 = 0
for a, b in zip(A, B):
# if a > b:
# cnt2 += a - b
if a < b:
cnt2 += math.ceil((b - a) / 2)
if cnt1 >= cnt2:
print("Yes")
else:
print("No") | import math
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt = 0
for a, b in zip(A, B):
if a > b:
cnt -= a - b
if a < b:
cnt += (b - a) // 2
if cnt < 0:
print("No")
else:
print("Yes") | 18 | 15 | 350 | 274 | import math
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sum_A = sum(A)
sum_B = sum(B)
cnt1 = sum_B - sum_A
cnt2 = 0
for a, b in zip(A, B):
# if a > b:
# cnt2 += a - b
if a < b:
cnt2 += math.ceil((b - a) / 2)
if cnt1 >= cnt2:
print("Yes")
else:
print("No")
| import math
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt = 0
for a, b in zip(A, B):
if a > b:
cnt -= a - b
if a < b:
cnt += (b - a) // 2
if cnt < 0:
print("No")
else:
print("Yes")
| false | 16.666667 | [
"-sum_A = sum(A)",
"-sum_B = sum(B)",
"-cnt1 = sum_B - sum_A",
"-cnt2 = 0",
"+cnt = 0",
"- # if a > b:",
"- # cnt2 += a - b",
"+ if a > b:",
"+ cnt -= a - b",
"- cnt2 += math.ceil((b - a) / 2)",
"-if cnt1 >= cnt2:",
"+ cnt += (b - a) // 2",
"+if cnt < 0:",
"+ print(\"No\")",
"+else:",
"-else:",
"- print(\"No\")"
] | false | 0.041123 | 0.044274 | 0.928823 | [
"s931145850",
"s018755487"
] |
u227082700 | p02754 | python | s798213403 | s471853980 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | n,a,b=list(map(int,input().split()))
m=n//(a+b)
n-=m*(a+b)
print((m*a+min(a,n))) | n,a,b=list(map(int,input().split()))
ans=a*(n//(a+b))
ans+=min(a,n%(a+b))
print(ans)
| 4 | 4 | 75 | 82 | n, a, b = list(map(int, input().split()))
m = n // (a + b)
n -= m * (a + b)
print((m * a + min(a, n)))
| n, a, b = list(map(int, input().split()))
ans = a * (n // (a + b))
ans += min(a, n % (a + b))
print(ans)
| false | 0 | [
"-m = n // (a + b)",
"-n -= m * (a + b)",
"-print((m * a + min(a, n)))",
"+ans = a * (n // (a + b))",
"+ans += min(a, n % (a + b))",
"+print(ans)"
] | false | 0.070019 | 0.048547 | 1.442289 | [
"s798213403",
"s471853980"
] |
u822662438 | p02678 | python | s525472409 | s380477431 | 1,432 | 1,141 | 34,064 | 34,168 | Accepted | Accepted | 20.32 | n , m = list(map(int, input().split()))
root = [[] for _ in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
root[a-1].append(b)
root[b-1].append(a)
kakutei = [1]
answer_li = [0]*n
while kakutei:
k = kakutei.pop(0)
for r in root[k-1]:
if answer_li[r-1] == 0:
kakutei.append(r)
answer_li[r-1] = k
answer_li = answer_li[1:]
if 0 in answer_li:
print('No')
else:
print('Yes')
for i in answer_li:
print(i)
| import sys
input = sys.stdin.readline
n , m = list(map(int, input().split()))
root = [[] for _ in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
root[a-1].append(b)
root[b-1].append(a)
kakutei = [1]
answer_li = [0]*n
while kakutei:
k = kakutei.pop(0)
for r in root[k-1]:
if answer_li[r-1] == 0:
kakutei.append(r)
answer_li[r-1] = k
answer_li = answer_li[1:]
if 0 in answer_li:
print('No')
else:
print('Yes')
for i in answer_li:
print(i)
| 26 | 29 | 510 | 552 | n, m = list(map(int, input().split()))
root = [[] for _ in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
root[a - 1].append(b)
root[b - 1].append(a)
kakutei = [1]
answer_li = [0] * n
while kakutei:
k = kakutei.pop(0)
for r in root[k - 1]:
if answer_li[r - 1] == 0:
kakutei.append(r)
answer_li[r - 1] = k
answer_li = answer_li[1:]
if 0 in answer_li:
print("No")
else:
print("Yes")
for i in answer_li:
print(i)
| import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
root = [[] for _ in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
root[a - 1].append(b)
root[b - 1].append(a)
kakutei = [1]
answer_li = [0] * n
while kakutei:
k = kakutei.pop(0)
for r in root[k - 1]:
if answer_li[r - 1] == 0:
kakutei.append(r)
answer_li[r - 1] = k
answer_li = answer_li[1:]
if 0 in answer_li:
print("No")
else:
print("Yes")
for i in answer_li:
print(i)
| false | 10.344828 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.037293 | 0.076255 | 0.48905 | [
"s525472409",
"s380477431"
] |
u652150585 | p03339 | python | s911216567 | s089536018 | 184 | 157 | 3,740 | 19,956 | Accepted | Accepted | 14.67 | N=int(eval(input()))
S=eval(input())
count=S[1:].count("E")
mincount=count
for i in range(1,N):
if S[i]=="E":
count-=1
if S[i-1]=="W":
count+=1
mincount=min(count,mincount)
print(mincount)
| n=int(eval(input()))
s=list(eval(input()))
ls=[0 if i=='W' else 1 for i in s]
a=sum(ls)
#print(a)
l=[0]*n
for i in range(n):
if ls[i]==1:
a-=1
l[i]=a
elif ls[i]==0:
a+=1
l[i]=a-1
print((min(l))) | 15 | 14 | 227 | 233 | N = int(eval(input()))
S = eval(input())
count = S[1:].count("E")
mincount = count
for i in range(1, N):
if S[i] == "E":
count -= 1
if S[i - 1] == "W":
count += 1
mincount = min(count, mincount)
print(mincount)
| n = int(eval(input()))
s = list(eval(input()))
ls = [0 if i == "W" else 1 for i in s]
a = sum(ls)
# print(a)
l = [0] * n
for i in range(n):
if ls[i] == 1:
a -= 1
l[i] = a
elif ls[i] == 0:
a += 1
l[i] = a - 1
print((min(l)))
| false | 6.666667 | [
"-N = int(eval(input()))",
"-S = eval(input())",
"-count = S[1:].count(\"E\")",
"-mincount = count",
"-for i in range(1, N):",
"- if S[i] == \"E\":",
"- count -= 1",
"- if S[i - 1] == \"W\":",
"- count += 1",
"- mincount = min(count, mincount)",
"-print(mincount)",
"+n = int(eval(input()))",
"+s = list(eval(input()))",
"+ls = [0 if i == \"W\" else 1 for i in s]",
"+a = sum(ls)",
"+# print(a)",
"+l = [0] * n",
"+for i in range(n):",
"+ if ls[i] == 1:",
"+ a -= 1",
"+ l[i] = a",
"+ elif ls[i] == 0:",
"+ a += 1",
"+ l[i] = a - 1",
"+print((min(l)))"
] | false | 0.048628 | 0.04732 | 1.027648 | [
"s911216567",
"s089536018"
] |
u604774382 | p02412 | python | s430774429 | s367038861 | 450 | 300 | 6,724 | 4,228 | Accepted | Accepted | 33.33 | import sys
while True:
n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
if 0 == n and 0 == x:
break
cnt = 0
for i in range( 1, n-1 ):
if x <= i:
break
for j in range( i+1, n ):
if x <= ( i+j ):
break
for k in range( j+1, n+1 ):
s = ( i + j + k )
if x == s:
cnt += 1
break
elif x < s:
break
print( cnt ) | import sys
while True:
n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
if 0 == n and 0 == x:
break
cnt = 0
goto = False
for i in range( 1, n-1 ):
if x < 3*(i+1):
break
for j in range( i+1, n ):
if x <= ( i+j ):
break
for k in range( j+1, n+1 ):
s = ( i + j + k )
if x == s:
cnt += 1
break
elif x < s:
goto = True
break
goto = False
print( cnt ) | 23 | 26 | 403 | 458 | import sys
while True:
n, x = [int(val) for val in sys.stdin.readline().split(" ")]
if 0 == n and 0 == x:
break
cnt = 0
for i in range(1, n - 1):
if x <= i:
break
for j in range(i + 1, n):
if x <= (i + j):
break
for k in range(j + 1, n + 1):
s = i + j + k
if x == s:
cnt += 1
break
elif x < s:
break
print(cnt)
| import sys
while True:
n, x = [int(val) for val in sys.stdin.readline().split(" ")]
if 0 == n and 0 == x:
break
cnt = 0
goto = False
for i in range(1, n - 1):
if x < 3 * (i + 1):
break
for j in range(i + 1, n):
if x <= (i + j):
break
for k in range(j + 1, n + 1):
s = i + j + k
if x == s:
cnt += 1
break
elif x < s:
goto = True
break
goto = False
print(cnt)
| false | 11.538462 | [
"+ goto = False",
"- if x <= i:",
"+ if x < 3 * (i + 1):",
"+ goto = True",
"+ goto = False"
] | false | 0.041648 | 0.041887 | 0.994309 | [
"s430774429",
"s367038861"
] |
u057109575 | p03266 | python | s708560920 | s156490739 | 76 | 26 | 3,316 | 3,316 | Accepted | Accepted | 65.79 | N, K = list(map(int, input().split()))
if K % 2 == 1:
print((sum(1 for n in range(1, N + 1) if n % K == 0) ** 3))
else:
print((sum(1 for n in range(1, N + 1) if n % K == 0) ** 3 + sum(1 for n in range(1, N + 1) if n % K == K // 2) ** 3))
| N, K = list(map(int, input().split()))
ans = (N // K) ** 3
ans += ((N + K // 2) // K) ** 3 if K % 2 == 0 else 0
print(ans) | 5 | 4 | 240 | 119 | N, K = list(map(int, input().split()))
if K % 2 == 1:
print((sum(1 for n in range(1, N + 1) if n % K == 0) ** 3))
else:
print(
(
sum(1 for n in range(1, N + 1) if n % K == 0) ** 3
+ sum(1 for n in range(1, N + 1) if n % K == K // 2) ** 3
)
)
| N, K = list(map(int, input().split()))
ans = (N // K) ** 3
ans += ((N + K // 2) // K) ** 3 if K % 2 == 0 else 0
print(ans)
| false | 20 | [
"-if K % 2 == 1:",
"- print((sum(1 for n in range(1, N + 1) if n % K == 0) ** 3))",
"-else:",
"- print(",
"- (",
"- sum(1 for n in range(1, N + 1) if n % K == 0) ** 3",
"- + sum(1 for n in range(1, N + 1) if n % K == K // 2) ** 3",
"- )",
"- )",
"+ans = (N // K) ** 3",
"+ans += ((N + K // 2) // K) ** 3 if K % 2 == 0 else 0",
"+print(ans)"
] | false | 0.00703 | 0.037914 | 0.185428 | [
"s708560920",
"s156490739"
] |
u126232616 | p03127 | python | s435522458 | s367901829 | 134 | 88 | 16,296 | 14,224 | Accepted | Accepted | 34.33 | from fractions import gcd
N = int(eval(input()))
A = list(map(int, input().split()))
g = 0
for i in range(N):
g = gcd(g, A[i])
print(g) | N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(p,q):
if q == 0: return p
return gcd(q, p%q)
g = 0
for i in range(N):
g = gcd(g, A[i])
print(g) | 8 | 11 | 141 | 180 | from fractions import gcd
N = int(eval(input()))
A = list(map(int, input().split()))
g = 0
for i in range(N):
g = gcd(g, A[i])
print(g)
| N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(p, q):
if q == 0:
return p
return gcd(q, p % q)
g = 0
for i in range(N):
g = gcd(g, A[i])
print(g)
| false | 27.272727 | [
"-from fractions import gcd",
"-",
"+",
"+",
"+def gcd(p, q):",
"+ if q == 0:",
"+ return p",
"+ return gcd(q, p % q)",
"+",
"+"
] | false | 0.052626 | 0.095065 | 0.553584 | [
"s435522458",
"s367901829"
] |
u879870653 | p03733 | python | s910383001 | s414718115 | 168 | 150 | 26,708 | 25,196 | Accepted | Accepted | 10.71 | N,T = list(map(int,input().split()))
L = list(map(int,input().split()))
ans = 0
for i in range(len(L)) :
if i != N-1 :
if L[i+1]-L[i] > T :
ans += T
else :
ans += L[i+1]-L[i]
else :
ans += T
print(ans)
| N,T = list(map(int,input().split()))
L = list(map(int,input().split()))
ans = T
for i in range(N-1) :
ans += min(L[i+1]-L[i],T)
print(ans)
| 12 | 6 | 263 | 142 | N, T = list(map(int, input().split()))
L = list(map(int, input().split()))
ans = 0
for i in range(len(L)):
if i != N - 1:
if L[i + 1] - L[i] > T:
ans += T
else:
ans += L[i + 1] - L[i]
else:
ans += T
print(ans)
| N, T = list(map(int, input().split()))
L = list(map(int, input().split()))
ans = T
for i in range(N - 1):
ans += min(L[i + 1] - L[i], T)
print(ans)
| false | 50 | [
"-ans = 0",
"-for i in range(len(L)):",
"- if i != N - 1:",
"- if L[i + 1] - L[i] > T:",
"- ans += T",
"- else:",
"- ans += L[i + 1] - L[i]",
"- else:",
"- ans += T",
"+ans = T",
"+for i in range(N - 1):",
"+ ans += min(L[i + 1] - L[i], T)"
] | false | 0.062365 | 0.036639 | 1.702155 | [
"s910383001",
"s414718115"
] |
u176796545 | p03494 | python | s209130959 | s594238995 | 21 | 18 | 3,316 | 2,940 | Accepted | Accepted | 14.29 | n=int(eval(input()))
A=list(map(int,input().split()))
c=0
loop=True
while(loop):
for a in A:
if a%2!=0:
loop=False
break
if loop:
A = list([i//2 for i in A])
c+=1
else:
break
print(c) | n=int(eval(input()))
A=list(map(int,input().split()))
c=0
while(all([a%2==0 for a in A])):
A = list([i//2 for i in A])
c+=1
print(c) | 15 | 7 | 263 | 144 | n = int(eval(input()))
A = list(map(int, input().split()))
c = 0
loop = True
while loop:
for a in A:
if a % 2 != 0:
loop = False
break
if loop:
A = list([i // 2 for i in A])
c += 1
else:
break
print(c)
| n = int(eval(input()))
A = list(map(int, input().split()))
c = 0
while all([a % 2 == 0 for a in A]):
A = list([i // 2 for i in A])
c += 1
print(c)
| false | 53.333333 | [
"-loop = True",
"-while loop:",
"- for a in A:",
"- if a % 2 != 0:",
"- loop = False",
"- break",
"- if loop:",
"- A = list([i // 2 for i in A])",
"- c += 1",
"- else:",
"- break",
"+while all([a % 2 == 0 for a in A]):",
"+ A = list([i // 2 for i in A])",
"+ c += 1"
] | false | 0.036008 | 0.036365 | 0.990164 | [
"s209130959",
"s594238995"
] |
u163783894 | p02763 | python | s407840820 | s125531713 | 1,429 | 791 | 441,976 | 52,244 | Accepted | Accepted | 44.65 | import sys
input = lambda: sys.stdin.readline().rstrip()
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.ide_ele = ide_ele
self.segfunc = segfunc
self.num = 2**(n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
def solve():
N = int(eval(input()))
S = list(eval(input()))
Q = int(eval(input()))
seg = [[0 for _ in range(N)] for _ in range(26)]
for i in range(N):
al = ord(S[i]) - ord('a')
seg[al][i] = 1
segtree = []
segfunc = lambda a, b: a | b
for i in range(26):
segtree.append(SegTree(seg[i], segfunc, 0))
ans = []
for i in range(Q):
a, b, c = input().split()
a = int(a)
if a == 1:
b = int(b) - 1
ps = S[b]
S[b] = c
segtree[ord(ps) - ord('a')].update(b, 0)
segtree[ord(c) - ord('a')].update(b, 1)
elif a == 2:
b, c = int(b) - 1, int(c)
count = 0
for i in range(26):
count += segtree[i].query(b, c)
ans.append(count)
print(('\n'.join(map(str, ans))))
if __name__ == '__main__':
solve()
| import sys
input = lambda: sys.stdin.readline().rstrip()
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.ide_ele = ide_ele
self.segfunc = segfunc
self.num = 2**(n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
def solve():
N = int(eval(input()))
S = list(eval(input()))
Q = int(eval(input()))
seg = [1 << (ord(s) - ord('a')) for s in S]
segtree = []
segfunc = lambda a, b: a | b
segtree = SegTree(seg, segfunc, 0)
ans = []
for i in range(Q):
a, b, c = input().split()
a = int(a)
if a == 1:
b = int(b) - 1
al = ord(c) - ord('a')
segtree.update(b, 1 << al)
elif a == 2:
b, c = int(b) - 1, int(c)
res = segtree.query(b, c)
res = sum(list(map(int, bin(res)[2:])))
ans.append(res)
print(('\n'.join(map(str, ans))))
if __name__ == '__main__':
solve()
| 89 | 81 | 2,303 | 2,084 | import sys
input = lambda: sys.stdin.readline().rstrip()
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.ide_ele = ide_ele
self.segfunc = segfunc
self.num = 2 ** (n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
def solve():
N = int(eval(input()))
S = list(eval(input()))
Q = int(eval(input()))
seg = [[0 for _ in range(N)] for _ in range(26)]
for i in range(N):
al = ord(S[i]) - ord("a")
seg[al][i] = 1
segtree = []
segfunc = lambda a, b: a | b
for i in range(26):
segtree.append(SegTree(seg[i], segfunc, 0))
ans = []
for i in range(Q):
a, b, c = input().split()
a = int(a)
if a == 1:
b = int(b) - 1
ps = S[b]
S[b] = c
segtree[ord(ps) - ord("a")].update(b, 0)
segtree[ord(c) - ord("a")].update(b, 1)
elif a == 2:
b, c = int(b) - 1, int(c)
count = 0
for i in range(26):
count += segtree[i].query(b, c)
ans.append(count)
print(("\n".join(map(str, ans))))
if __name__ == "__main__":
solve()
| import sys
input = lambda: sys.stdin.readline().rstrip()
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.ide_ele = ide_ele
self.segfunc = segfunc
self.num = 2 ** (n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
def solve():
N = int(eval(input()))
S = list(eval(input()))
Q = int(eval(input()))
seg = [1 << (ord(s) - ord("a")) for s in S]
segtree = []
segfunc = lambda a, b: a | b
segtree = SegTree(seg, segfunc, 0)
ans = []
for i in range(Q):
a, b, c = input().split()
a = int(a)
if a == 1:
b = int(b) - 1
al = ord(c) - ord("a")
segtree.update(b, 1 << al)
elif a == 2:
b, c = int(b) - 1, int(c)
res = segtree.query(b, c)
res = sum(list(map(int, bin(res)[2:])))
ans.append(res)
print(("\n".join(map(str, ans))))
if __name__ == "__main__":
solve()
| false | 8.988764 | [
"- seg = [[0 for _ in range(N)] for _ in range(26)]",
"- for i in range(N):",
"- al = ord(S[i]) - ord(\"a\")",
"- seg[al][i] = 1",
"+ seg = [1 << (ord(s) - ord(\"a\")) for s in S]",
"- for i in range(26):",
"- segtree.append(SegTree(seg[i], segfunc, 0))",
"+ segtree = SegTree(seg, segfunc, 0)",
"- ps = S[b]",
"- S[b] = c",
"- segtree[ord(ps) - ord(\"a\")].update(b, 0)",
"- segtree[ord(c) - ord(\"a\")].update(b, 1)",
"+ al = ord(c) - ord(\"a\")",
"+ segtree.update(b, 1 << al)",
"- count = 0",
"- for i in range(26):",
"- count += segtree[i].query(b, c)",
"- ans.append(count)",
"+ res = segtree.query(b, c)",
"+ res = sum(list(map(int, bin(res)[2:])))",
"+ ans.append(res)"
] | false | 0.135584 | 0.048536 | 2.793489 | [
"s407840820",
"s125531713"
] |
u297801580 | p03171 | python | s959811389 | s635842340 | 325 | 299 | 111,964 | 111,708 | Accepted | Accepted | 8 | import sys
def input():
return sys.stdin.readline()[:-1]
n = int(eval(input()))
a = [int(x) for x in input().split()]
dp=[]
for i in range(n):
dp.append([0]*n)
for i in range(n):
dp[i][i] = a[i]
for i in range(n - 2, -1, -1):
for j in range(i + 1, n):
dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])
print((dp[0][n - 1])) | n = int(eval(input()))
a = list(map(int, input().split()))
def calc():
dp = [[0] * n for _ in range(n)]
for i in range(n):
dp[i][i] = a[i]
for i in range(n - 2, -1, -1):
for j in range(i + 1, n):
dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])
return dp
dp = calc()
print((dp[0][n - 1])) | 18 | 15 | 364 | 349 | import sys
def input():
return sys.stdin.readline()[:-1]
n = int(eval(input()))
a = [int(x) for x in input().split()]
dp = []
for i in range(n):
dp.append([0] * n)
for i in range(n):
dp[i][i] = a[i]
for i in range(n - 2, -1, -1):
for j in range(i + 1, n):
dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])
print((dp[0][n - 1]))
| n = int(eval(input()))
a = list(map(int, input().split()))
def calc():
dp = [[0] * n for _ in range(n)]
for i in range(n):
dp[i][i] = a[i]
for i in range(n - 2, -1, -1):
for j in range(i + 1, n):
dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])
return dp
dp = calc()
print((dp[0][n - 1]))
| false | 16.666667 | [
"-import sys",
"+n = int(eval(input()))",
"+a = list(map(int, input().split()))",
"-def input():",
"- return sys.stdin.readline()[:-1]",
"+def calc():",
"+ dp = [[0] * n for _ in range(n)]",
"+ for i in range(n):",
"+ dp[i][i] = a[i]",
"+ for i in range(n - 2, -1, -1):",
"+ for j in range(i + 1, n):",
"+ dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])",
"+ return dp",
"-n = int(eval(input()))",
"-a = [int(x) for x in input().split()]",
"-dp = []",
"-for i in range(n):",
"- dp.append([0] * n)",
"-for i in range(n):",
"- dp[i][i] = a[i]",
"-for i in range(n - 2, -1, -1):",
"- for j in range(i + 1, n):",
"- dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])",
"+dp = calc()"
] | false | 0.044197 | 0.047789 | 0.924836 | [
"s959811389",
"s635842340"
] |
u492049124 | p03475 | python | s887940912 | s010114553 | 112 | 86 | 3,188 | 3,188 | Accepted | Accepted | 23.21 | N = int(eval(input()))
lines = []
for i in range(N-1):
lines.append(eval(input()))
C = []
S = []
F = []
for line in lines:
c, s, f = line.split()
C.append(int(c))
S.append(int(s))
F.append(int(f))
A = []
for i in range(N-1):
a = C[i] + S[i]
for j in range(i + 1, N - 1):
n = S[j] - a if a <= S[j] else (a - S[j]) % F[j]
n = F[j] - n if a > S[j] and n != 0 else n
# n = S[j] - a if a <= S[j] else a % F[j]
a = a + C[j] + n
A.append(a)
for a in A:
print(a)
print((0))
| N = int(eval(input()))
lines = []
for i in range(N-1):
lines.append(eval(input()))
C = []
S = []
F = []
for line in lines:
c, s, f = line.split()
C.append(int(c))
S.append(int(s))
F.append(int(f))
A = []
for i in range(N-1):
a = C[i] + S[i]
for j in range(i + 1, N - 1):
if a <= S[j]:
n = S[j] - a
else:
mod = a % F[j]
n = F[j] - mod if mod != 0 else 0
a = a + C[j] + n
A.append(a)
for a in A:
print(a)
print((0))
| 31 | 33 | 509 | 467 | N = int(eval(input()))
lines = []
for i in range(N - 1):
lines.append(eval(input()))
C = []
S = []
F = []
for line in lines:
c, s, f = line.split()
C.append(int(c))
S.append(int(s))
F.append(int(f))
A = []
for i in range(N - 1):
a = C[i] + S[i]
for j in range(i + 1, N - 1):
n = S[j] - a if a <= S[j] else (a - S[j]) % F[j]
n = F[j] - n if a > S[j] and n != 0 else n
# n = S[j] - a if a <= S[j] else a % F[j]
a = a + C[j] + n
A.append(a)
for a in A:
print(a)
print((0))
| N = int(eval(input()))
lines = []
for i in range(N - 1):
lines.append(eval(input()))
C = []
S = []
F = []
for line in lines:
c, s, f = line.split()
C.append(int(c))
S.append(int(s))
F.append(int(f))
A = []
for i in range(N - 1):
a = C[i] + S[i]
for j in range(i + 1, N - 1):
if a <= S[j]:
n = S[j] - a
else:
mod = a % F[j]
n = F[j] - mod if mod != 0 else 0
a = a + C[j] + n
A.append(a)
for a in A:
print(a)
print((0))
| false | 6.060606 | [
"- n = S[j] - a if a <= S[j] else (a - S[j]) % F[j]",
"- n = F[j] - n if a > S[j] and n != 0 else n",
"- # n = S[j] - a if a <= S[j] else a % F[j]",
"+ if a <= S[j]:",
"+ n = S[j] - a",
"+ else:",
"+ mod = a % F[j]",
"+ n = F[j] - mod if mod != 0 else 0"
] | false | 0.036709 | 0.044195 | 0.830624 | [
"s887940912",
"s010114553"
] |
u471684875 | p03745 | python | s828382956 | s674202025 | 116 | 90 | 14,436 | 14,252 | Accepted | Accepted | 22.41 | n=int(eval(input()))
a=list(map(int,input().split()))
b=[]
c=[]
if n==1:
print((1))
else:
for i in range(n-1):
if a[i]!=a[i+1]:
b.append(a[i])
b.append(a[n-1])
ans=1
for i in range(len(b)-1):
c.append(b[i+1]-b[i])
d=c[0]
for i in range(1,len(b)-1):
if d*c[i]>=0:
d=c[i]
else:
ans+=1
d=0
print(ans)
| #参考(傾きの捉え方)
N = int(eval(input()))
A = list(map(int, input().split()))
f = 0
c = 1
i = 0
while i < N-1:
if f == 0:
if A[i] < A[i+1]:
f = 1
elif A[i] > A[i+1]:
f = -1
elif f == 1:
if A[i] > A[i+1]:
c += 1
f = 0
elif f == -1:
if A[i] < A[i+1]:
c += 1
f = 0
i += 1
print(c) | 28 | 22 | 487 | 405 | n = int(eval(input()))
a = list(map(int, input().split()))
b = []
c = []
if n == 1:
print((1))
else:
for i in range(n - 1):
if a[i] != a[i + 1]:
b.append(a[i])
b.append(a[n - 1])
ans = 1
for i in range(len(b) - 1):
c.append(b[i + 1] - b[i])
d = c[0]
for i in range(1, len(b) - 1):
if d * c[i] >= 0:
d = c[i]
else:
ans += 1
d = 0
print(ans)
| # 参考(傾きの捉え方)
N = int(eval(input()))
A = list(map(int, input().split()))
f = 0
c = 1
i = 0
while i < N - 1:
if f == 0:
if A[i] < A[i + 1]:
f = 1
elif A[i] > A[i + 1]:
f = -1
elif f == 1:
if A[i] > A[i + 1]:
c += 1
f = 0
elif f == -1:
if A[i] < A[i + 1]:
c += 1
f = 0
i += 1
print(c)
| false | 21.428571 | [
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-b = []",
"-c = []",
"-if n == 1:",
"- print((1))",
"-else:",
"- for i in range(n - 1):",
"- if a[i] != a[i + 1]:",
"- b.append(a[i])",
"- b.append(a[n - 1])",
"- ans = 1",
"- for i in range(len(b) - 1):",
"- c.append(b[i + 1] - b[i])",
"- d = c[0]",
"- for i in range(1, len(b) - 1):",
"- if d * c[i] >= 0:",
"- d = c[i]",
"- else:",
"- ans += 1",
"- d = 0",
"- print(ans)",
"+# 参考(傾きの捉え方)",
"+N = int(eval(input()))",
"+A = list(map(int, input().split()))",
"+f = 0",
"+c = 1",
"+i = 0",
"+while i < N - 1:",
"+ if f == 0:",
"+ if A[i] < A[i + 1]:",
"+ f = 1",
"+ elif A[i] > A[i + 1]:",
"+ f = -1",
"+ elif f == 1:",
"+ if A[i] > A[i + 1]:",
"+ c += 1",
"+ f = 0",
"+ elif f == -1:",
"+ if A[i] < A[i + 1]:",
"+ c += 1",
"+ f = 0",
"+ i += 1",
"+print(c)"
] | false | 0.042423 | 0.04255 | 0.997025 | [
"s828382956",
"s674202025"
] |
u750651325 | p03486 | python | s980325535 | s267487192 | 39 | 35 | 10,028 | 9,988 | Accepted | Accepted | 10.26 | import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return eval(input())
def i(): return int(eval(input()))
def S(): return input().split()
def I(): return list(map(int,input().split()))
def X(): return list(eval(input()))
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
s = X()
t = X()
s.sort()
t.sort()
t.reverse()
a = "".join(s)
b = "".join(t)
if a < b:
print("Yes")
else:
print("No")
| import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
from functools import reduce
def s(): return eval(input())
def i(): return int(eval(input()))
def S(): return input().split()
def I(): return list(map(int,input().split()))
def X(): return list(eval(input()))
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
a = s()
t = s()
a = sorted(a)
y = "".join(a)
t = sorted(t,reverse = True)
x = "".join(t)
if y < x:
print("Yes")
else:
print("No")
| 32 | 32 | 628 | 702 | import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque, Counter
from decimal import Decimal
def s():
return eval(input())
def i():
return int(eval(input()))
def S():
return input().split()
def I():
return list(map(int, input().split()))
def X():
return list(eval(input()))
def L():
return list(input().split())
def l():
return list(map(int, input().split()))
def lcm(a, b):
return a * b // math.gcd(a, b)
sys.setrecursionlimit(10**9)
mod = 10**9 + 7
s = X()
t = X()
s.sort()
t.sort()
t.reverse()
a = "".join(s)
b = "".join(t)
if a < b:
print("Yes")
else:
print("No")
| import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque, Counter
from decimal import Decimal
from functools import reduce
def s():
return eval(input())
def i():
return int(eval(input()))
def S():
return input().split()
def I():
return list(map(int, input().split()))
def X():
return list(eval(input()))
def L():
return list(input().split())
def l():
return list(map(int, input().split()))
def lcm(a, b):
return a * b // math.gcd(a, b)
def gcd(*numbers):
reduce(math.gcd, numbers)
sys.setrecursionlimit(10**9)
mod = 10**9 + 7
count = 0
ans = 0
a = s()
t = s()
a = sorted(a)
y = "".join(a)
t = sorted(t, reverse=True)
x = "".join(t)
if y < x:
print("Yes")
else:
print("No")
| false | 0 | [
"+from functools import reduce",
"+def gcd(*numbers):",
"+ reduce(math.gcd, numbers)",
"+",
"+",
"-s = X()",
"-t = X()",
"-s.sort()",
"-t.sort()",
"-t.reverse()",
"-a = \"\".join(s)",
"-b = \"\".join(t)",
"-if a < b:",
"+count = 0",
"+ans = 0",
"+a = s()",
"+t = s()",
"+a = sorted(a)",
"+y = \"\".join(a)",
"+t = sorted(t, reverse=True)",
"+x = \"\".join(t)",
"+if y < x:"
] | false | 0.041968 | 0.047086 | 0.891294 | [
"s980325535",
"s267487192"
] |
u191874006 | p03730 | python | s271484823 | s032540253 | 175 | 74 | 38,512 | 65,400 | Accepted | Accepted | 57.71 | #!/usr/bin/env python3
#ABC60 B
a,b,c = list(map(int,input().split()))
s = a
for i in range(a*b):
x = s % b
if x == c:
print('YES')
quit()
s += a
print('NO')
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
a, b, c = LI()
for i in range(a, a*b+1, a):
if i % b == c:
print('YES')
break
else:
print('NO') | 13 | 26 | 194 | 685 | #!/usr/bin/env python3
# ABC60 B
a, b, c = list(map(int, input().split()))
s = a
for i in range(a * b):
x = s % b
if x == c:
print("YES")
quit()
s += a
print("NO")
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
a, b, c = LI()
for i in range(a, a * b + 1, a):
if i % b == c:
print("YES")
break
else:
print("NO")
| false | 50 | [
"-# ABC60 B",
"-a, b, c = list(map(int, input().split()))",
"-s = a",
"-for i in range(a * b):",
"- x = s % b",
"- if x == c:",
"+import sys",
"+import math",
"+from bisect import bisect_right as br",
"+from bisect import bisect_left as bl",
"+",
"+sys.setrecursionlimit(2147483647)",
"+from heapq import heappush, heappop, heappushpop",
"+from collections import defaultdict",
"+from itertools import accumulate",
"+from collections import Counter",
"+from collections import deque",
"+from operator import itemgetter",
"+from itertools import permutations",
"+",
"+mod = 10**9 + 7",
"+inf = float(\"inf\")",
"+",
"+",
"+def I():",
"+ return int(sys.stdin.readline())",
"+",
"+",
"+def LI():",
"+ return list(map(int, sys.stdin.readline().split()))",
"+",
"+",
"+a, b, c = LI()",
"+for i in range(a, a * b + 1, a):",
"+ if i % b == c:",
"- quit()",
"- s += a",
"-print(\"NO\")",
"+ break",
"+else:",
"+ print(\"NO\")"
] | false | 0.055602 | 0.088807 | 0.626094 | [
"s271484823",
"s032540253"
] |
u934442292 | p02844 | python | s563035599 | s411816707 | 22 | 20 | 3,316 | 3,064 | Accepted | Accepted | 9.09 | import re
N = int(eval(input()))
S = eval(input())
res = 0
fmt = "[0-9]*{}[0-9]*{}[0-9]*{}[0-9]*"
for i in range(10):
idx_1 = S.find(str(i))
if (idx_1 == -1) or (idx_1 > N-3):
continue
for j in range(10):
idx_2 = S[idx_1+1:].find(str(j))
if (idx_2 == -1) or (idx_2 > N-2):
continue
for k in range(10):
idx_3 = S[idx_1+1+idx_2+1:].find(str(k))
if idx_3 != -1:
res += 1
print(res)
| N = int(eval(input()))
S = eval(input())
res = 0
for i in range(10):
idx_1 = S.find(str(i))
if (idx_1 == -1) or (idx_1 > N-3):
continue
for j in range(10):
idx_2 = S[idx_1+1:].find(str(j))
if (idx_2 == -1) or (idx_2 > N-2):
continue
for k in range(10):
idx_3 = S[idx_1+1+idx_2+1:].find(str(k))
if idx_3 != -1:
res += 1
print(res)
| 21 | 18 | 438 | 385 | import re
N = int(eval(input()))
S = eval(input())
res = 0
fmt = "[0-9]*{}[0-9]*{}[0-9]*{}[0-9]*"
for i in range(10):
idx_1 = S.find(str(i))
if (idx_1 == -1) or (idx_1 > N - 3):
continue
for j in range(10):
idx_2 = S[idx_1 + 1 :].find(str(j))
if (idx_2 == -1) or (idx_2 > N - 2):
continue
for k in range(10):
idx_3 = S[idx_1 + 1 + idx_2 + 1 :].find(str(k))
if idx_3 != -1:
res += 1
print(res)
| N = int(eval(input()))
S = eval(input())
res = 0
for i in range(10):
idx_1 = S.find(str(i))
if (idx_1 == -1) or (idx_1 > N - 3):
continue
for j in range(10):
idx_2 = S[idx_1 + 1 :].find(str(j))
if (idx_2 == -1) or (idx_2 > N - 2):
continue
for k in range(10):
idx_3 = S[idx_1 + 1 + idx_2 + 1 :].find(str(k))
if idx_3 != -1:
res += 1
print(res)
| false | 14.285714 | [
"-import re",
"-",
"-fmt = \"[0-9]*{}[0-9]*{}[0-9]*{}[0-9]*\""
] | false | 0.081602 | 0.034497 | 2.365495 | [
"s563035599",
"s411816707"
] |
u017415492 | p02820 | python | s425987683 | s516344157 | 84 | 74 | 4,084 | 4,084 | Accepted | Accepted | 11.9 | n,k=list(map(int,input().split()))
r,s,p=list(map(int,input().split()))
t=list(eval(input()))
ans=0
for i in range(0,n):
if t[i]=="r":
ans+=p
elif t[i]=="s":
ans+=r
elif t[i]=="p":
ans+=s
for i in range(0,n-k):
if t[i]==t[i+k]:
t[i+k]="M"
if t[i]=="r":
ans-=p
elif t[i]=="s":
ans-=r
elif t[i]=="p":
ans-=s
print(ans) | n,k=list(map(int,input().split()))
r,s,p=list(map(int,input().split()))
t=list(eval(input()))
ans=0
for i in range(n):
if i<k:
if t[i]=="r":
ans+=p
elif t[i]=="s":
ans+=r
elif t[i]=="p":
ans+=s
else:
if t[i]=="r" and t[i-k]!=t[i]:
ans+=p
elif t[i]=="s" and t[i-k]!=t[i]:
ans+=r
elif t[i]=="p" and t[i-k]!=t[i]:
ans+=s
else:
t[i]="X"
print(ans) | 23 | 24 | 379 | 428 | n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = list(eval(input()))
ans = 0
for i in range(0, n):
if t[i] == "r":
ans += p
elif t[i] == "s":
ans += r
elif t[i] == "p":
ans += s
for i in range(0, n - k):
if t[i] == t[i + k]:
t[i + k] = "M"
if t[i] == "r":
ans -= p
elif t[i] == "s":
ans -= r
elif t[i] == "p":
ans -= s
print(ans)
| n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = list(eval(input()))
ans = 0
for i in range(n):
if i < k:
if t[i] == "r":
ans += p
elif t[i] == "s":
ans += r
elif t[i] == "p":
ans += s
else:
if t[i] == "r" and t[i - k] != t[i]:
ans += p
elif t[i] == "s" and t[i - k] != t[i]:
ans += r
elif t[i] == "p" and t[i - k] != t[i]:
ans += s
else:
t[i] = "X"
print(ans)
| false | 4.166667 | [
"-for i in range(0, n):",
"- if t[i] == \"r\":",
"- ans += p",
"- elif t[i] == \"s\":",
"- ans += r",
"- elif t[i] == \"p\":",
"- ans += s",
"-for i in range(0, n - k):",
"- if t[i] == t[i + k]:",
"- t[i + k] = \"M\"",
"+for i in range(n):",
"+ if i < k:",
"- ans -= p",
"+ ans += p",
"- ans -= r",
"+ ans += r",
"- ans -= s",
"+ ans += s",
"+ else:",
"+ if t[i] == \"r\" and t[i - k] != t[i]:",
"+ ans += p",
"+ elif t[i] == \"s\" and t[i - k] != t[i]:",
"+ ans += r",
"+ elif t[i] == \"p\" and t[i - k] != t[i]:",
"+ ans += s",
"+ else:",
"+ t[i] = \"X\""
] | false | 0.036145 | 0.043734 | 0.826461 | [
"s425987683",
"s516344157"
] |
u489959379 | p02953 | python | s591660915 | s388971695 | 96 | 66 | 14,396 | 14,480 | Accepted | Accepted | 31.25 | n = int(eval(input()))
h = list(map(int, input().split()))
ans = "Yes"
for i in range(1, n):
if h[i] > h[i-1]:
h[i] -= 1
if h == sorted(h):
print("Yes")
else:
print("No")
| import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(eval(input()))
H = list(map(int, input().split()))
for i in range(1, n):
if H[i - 1] < H[i]:
H[i] -= 1
for j in range(1, n):
if H[j - 1] > H[j]:
print("No")
break
else:
print("Yes")
if __name__ == '__main__':
resolve()
| 12 | 25 | 198 | 432 | n = int(eval(input()))
h = list(map(int, input().split()))
ans = "Yes"
for i in range(1, n):
if h[i] > h[i - 1]:
h[i] -= 1
if h == sorted(h):
print("Yes")
else:
print("No")
| import sys
sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n = int(eval(input()))
H = list(map(int, input().split()))
for i in range(1, n):
if H[i - 1] < H[i]:
H[i] -= 1
for j in range(1, n):
if H[j - 1] > H[j]:
print("No")
break
else:
print("Yes")
if __name__ == "__main__":
resolve()
| false | 52 | [
"-n = int(eval(input()))",
"-h = list(map(int, input().split()))",
"-ans = \"Yes\"",
"-for i in range(1, n):",
"- if h[i] > h[i - 1]:",
"- h[i] -= 1",
"-if h == sorted(h):",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+import sys",
"+",
"+sys.setrecursionlimit(10**7)",
"+f_inf = float(\"inf\")",
"+mod = 10**9 + 7",
"+",
"+",
"+def resolve():",
"+ n = int(eval(input()))",
"+ H = list(map(int, input().split()))",
"+ for i in range(1, n):",
"+ if H[i - 1] < H[i]:",
"+ H[i] -= 1",
"+ for j in range(1, n):",
"+ if H[j - 1] > H[j]:",
"+ print(\"No\")",
"+ break",
"+ else:",
"+ print(\"Yes\")",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ resolve()"
] | false | 0.037706 | 0.035976 | 1.04809 | [
"s591660915",
"s388971695"
] |
u222668979 | p02803 | python | s672032867 | s918789879 | 553 | 138 | 3,316 | 74,920 | Accepted | Accepted | 75.05 | from collections import deque
h, w = list(map(int, input().split()))
s = [list(str(eval(input()))) for _ in range(h)]
def bfs(h, w, s, s_h, s_w):
if s[s_h][s_w] == '#':
return 0
d_max = 0
pas = [[-1 for _ in range(w)] for _ in range(h)]
dist = [[-1 for _ in range(w)] for _ in range(h)]
dist[s_h][s_w], pas[s_h][s_w] = 0, 's'
que = deque()
que.append((s_h, s_w))
while len(que) > 0:
q = que.popleft()
near = [(q[0]+1, q[1]), (q[0], q[1]+1), (q[0]-1, q[1]), (q[0], q[1]-1)]
for i in near:
if (i[0] < 0) | (i[0] >= h) | (i[1] < 0) | (i[1] >= w):
continue
if (dist[i[0]][i[1]] == -1) & (s[i[0]][i[1]] == '.'):
dist[i[0]][i[1]] = dist[q[0]][q[1]] + 1
pas[i[0]][i[1]] = q
que.append(i)
d_max = max(dist[q[0]][q[1]] + 1, d_max)
return d_max
dmax = 0
for i in range(h):
for j in range(w):
dist = bfs(h, w, s, i, j)
dmax = max(dmax, dist)
print(dmax)
| from collections import deque
def bfs(y, x):
dist = [[-1] * w for _ in range(h)]
dist[y][x] = 0
que, frag = deque([(x, y)]), set([(x, y)])
while que:
qx, qy = que.popleft()
near = [(qx - 1, qy), (qx, qy - 1), (qx + 1, qy), (qx, qy + 1)]
for i, j in near:
if (i, j) in frag:
continue
if 0 <= i < w and 0 <= j < h and s[j][i] == '.':
dist[j][i] = dist[qy][qx] + 1
que.append((i, j)), frag.add((i, j))
return dist[qy][qx]
h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
ans = 0
for i, si in enumerate(s):
for j, sij in enumerate(si):
if sij == '.':
ans = max(ans, bfs(i, j))
print(ans)
| 35 | 29 | 1,062 | 774 | from collections import deque
h, w = list(map(int, input().split()))
s = [list(str(eval(input()))) for _ in range(h)]
def bfs(h, w, s, s_h, s_w):
if s[s_h][s_w] == "#":
return 0
d_max = 0
pas = [[-1 for _ in range(w)] for _ in range(h)]
dist = [[-1 for _ in range(w)] for _ in range(h)]
dist[s_h][s_w], pas[s_h][s_w] = 0, "s"
que = deque()
que.append((s_h, s_w))
while len(que) > 0:
q = que.popleft()
near = [(q[0] + 1, q[1]), (q[0], q[1] + 1), (q[0] - 1, q[1]), (q[0], q[1] - 1)]
for i in near:
if (i[0] < 0) | (i[0] >= h) | (i[1] < 0) | (i[1] >= w):
continue
if (dist[i[0]][i[1]] == -1) & (s[i[0]][i[1]] == "."):
dist[i[0]][i[1]] = dist[q[0]][q[1]] + 1
pas[i[0]][i[1]] = q
que.append(i)
d_max = max(dist[q[0]][q[1]] + 1, d_max)
return d_max
dmax = 0
for i in range(h):
for j in range(w):
dist = bfs(h, w, s, i, j)
dmax = max(dmax, dist)
print(dmax)
| from collections import deque
def bfs(y, x):
dist = [[-1] * w for _ in range(h)]
dist[y][x] = 0
que, frag = deque([(x, y)]), set([(x, y)])
while que:
qx, qy = que.popleft()
near = [(qx - 1, qy), (qx, qy - 1), (qx + 1, qy), (qx, qy + 1)]
for i, j in near:
if (i, j) in frag:
continue
if 0 <= i < w and 0 <= j < h and s[j][i] == ".":
dist[j][i] = dist[qy][qx] + 1
que.append((i, j)), frag.add((i, j))
return dist[qy][qx]
h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
ans = 0
for i, si in enumerate(s):
for j, sij in enumerate(si):
if sij == ".":
ans = max(ans, bfs(i, j))
print(ans)
| false | 17.142857 | [
"-h, w = list(map(int, input().split()))",
"-s = [list(str(eval(input()))) for _ in range(h)]",
"+",
"+def bfs(y, x):",
"+ dist = [[-1] * w for _ in range(h)]",
"+ dist[y][x] = 0",
"+ que, frag = deque([(x, y)]), set([(x, y)])",
"+ while que:",
"+ qx, qy = que.popleft()",
"+ near = [(qx - 1, qy), (qx, qy - 1), (qx + 1, qy), (qx, qy + 1)]",
"+ for i, j in near:",
"+ if (i, j) in frag:",
"+ continue",
"+ if 0 <= i < w and 0 <= j < h and s[j][i] == \".\":",
"+ dist[j][i] = dist[qy][qx] + 1",
"+ que.append((i, j)), frag.add((i, j))",
"+ return dist[qy][qx]",
"-def bfs(h, w, s, s_h, s_w):",
"- if s[s_h][s_w] == \"#\":",
"- return 0",
"- d_max = 0",
"- pas = [[-1 for _ in range(w)] for _ in range(h)]",
"- dist = [[-1 for _ in range(w)] for _ in range(h)]",
"- dist[s_h][s_w], pas[s_h][s_w] = 0, \"s\"",
"- que = deque()",
"- que.append((s_h, s_w))",
"- while len(que) > 0:",
"- q = que.popleft()",
"- near = [(q[0] + 1, q[1]), (q[0], q[1] + 1), (q[0] - 1, q[1]), (q[0], q[1] - 1)]",
"- for i in near:",
"- if (i[0] < 0) | (i[0] >= h) | (i[1] < 0) | (i[1] >= w):",
"- continue",
"- if (dist[i[0]][i[1]] == -1) & (s[i[0]][i[1]] == \".\"):",
"- dist[i[0]][i[1]] = dist[q[0]][q[1]] + 1",
"- pas[i[0]][i[1]] = q",
"- que.append(i)",
"- d_max = max(dist[q[0]][q[1]] + 1, d_max)",
"- return d_max",
"-",
"-",
"-dmax = 0",
"-for i in range(h):",
"- for j in range(w):",
"- dist = bfs(h, w, s, i, j)",
"- dmax = max(dmax, dist)",
"-print(dmax)",
"+h, w = list(map(int, input().split()))",
"+s = [eval(input()) for _ in range(h)]",
"+ans = 0",
"+for i, si in enumerate(s):",
"+ for j, sij in enumerate(si):",
"+ if sij == \".\":",
"+ ans = max(ans, bfs(i, j))",
"+print(ans)"
] | false | 0.0574 | 0.117784 | 0.487336 | [
"s672032867",
"s918789879"
] |
u285891772 | p02819 | python | s649029969 | s804520010 | 133 | 38 | 5,192 | 5,200 | Accepted | Accepted | 71.43 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
X = INT()
i = 0
C = True
while C:
for j in range(1,X+i):
if gcd(j, X+i) != 1:
i += 1
break
else:
C = False
print((X+i)) | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
X = INT()
ans = 0
def DFS(X):
for i in range(2, int(sqrt(X))+1):
#print(i, X)
if X%i == 0:
return DFS(X+1)
break
else:
return X
print((DFS(X)))
| 32 | 32 | 883 | 1,020 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
X = INT()
i = 0
C = True
while C:
for j in range(1, X + i):
if gcd(j, X + i) != 1:
i += 1
break
else:
C = False
print((X + i))
| import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
X = INT()
ans = 0
def DFS(X):
for i in range(2, int(sqrt(X)) + 1):
# print(i, X)
if X % i == 0:
return DFS(X + 1)
break
else:
return X
print((DFS(X)))
| false | 0 | [
"-from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians",
"-from itertools import accumulate, permutations, combinations, product",
"+from math import (",
"+ ceil,",
"+ sqrt,",
"+ hypot,",
"+ factorial,",
"+ pi,",
"+ sin,",
"+ cos,",
"+ tan,",
"+ asin,",
"+ acos,",
"+ atan,",
"+ radians,",
"+ degrees,",
"+ log2,",
"+)",
"+from itertools import (",
"+ accumulate,",
"+ permutations,",
"+ combinations,",
"+ combinations_with_replacement,",
"+ product,",
"+ groupby,",
"+)",
"+def ZIP(n):",
"+ return list(zip(*(MAP() for _ in range(n))))",
"+",
"+",
"-i = 0",
"-C = True",
"-while C:",
"- for j in range(1, X + i):",
"- if gcd(j, X + i) != 1:",
"- i += 1",
"+ans = 0",
"+",
"+",
"+def DFS(X):",
"+ for i in range(2, int(sqrt(X)) + 1):",
"+ # print(i, X)",
"+ if X % i == 0:",
"+ return DFS(X + 1)",
"- C = False",
"-print((X + i))",
"+ return X",
"+",
"+",
"+print((DFS(X)))"
] | false | 0.252432 | 0.062157 | 4.061203 | [
"s649029969",
"s804520010"
] |
u066413086 | p02888 | python | s062836034 | s460755940 | 1,835 | 1,240 | 3,188 | 9,288 | Accepted | Accepted | 32.43 | from bisect import bisect
from bisect import bisect_right
from bisect import bisect_left
from bisect import insort
from bisect import insort_right
from bisect import insort_left
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
#print(L)
cnt = 0
for i in range(N):
for j in range(i+1, N):
s = L[i] + L[j]
x = bisect_left(L, s)
#print((L[i], L[j]), s, x)
cnt += max(x - j - 1, 0)
print(cnt) | from bisect import bisect
from bisect import bisect_right
from bisect import bisect_left
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
#print(L)
cnt = 0
for i in range(N):
for j in range(i+1, N):
s = L[i] + L[j]
x = bisect_left(L, s)
#print((L[i], L[j]), s, x)
cnt += max(x - j - 1, 0)
print(cnt) | 20 | 17 | 440 | 350 | from bisect import bisect
from bisect import bisect_right
from bisect import bisect_left
from bisect import insort
from bisect import insort_right
from bisect import insort_left
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
# print(L)
cnt = 0
for i in range(N):
for j in range(i + 1, N):
s = L[i] + L[j]
x = bisect_left(L, s)
# print((L[i], L[j]), s, x)
cnt += max(x - j - 1, 0)
print(cnt)
| from bisect import bisect
from bisect import bisect_right
from bisect import bisect_left
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
# print(L)
cnt = 0
for i in range(N):
for j in range(i + 1, N):
s = L[i] + L[j]
x = bisect_left(L, s)
# print((L[i], L[j]), s, x)
cnt += max(x - j - 1, 0)
print(cnt)
| false | 15 | [
"-from bisect import insort",
"-from bisect import insort_right",
"-from bisect import insort_left"
] | false | 0.046111 | 0.078596 | 0.586689 | [
"s062836034",
"s460755940"
] |
u077291787 | p03006 | python | s770849957 | s944009754 | 24 | 20 | 3,572 | 3,444 | Accepted | Accepted | 16.67 | # div2019-2B - Picking Up
from collections import defaultdict
n = int(eval(input()))
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
cnt = defaultdict(int)
for i in range(n):
for j in range(i + 1, n):
dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
cnt[dif] += 1
print((n - max(list(cnt.values()), default=0))) | n = int(eval(input()))
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
cnt = {}
for i, j in arr:
for k, l in arr:
if (i, j) == (k, l):
continue
dif = (k - i, l - j)
cnt.setdefault(dif, 0)
cnt[dif] += 1
print((n - max(list(cnt.values()), default=0))) | 11 | 11 | 359 | 320 | # div2019-2B - Picking Up
from collections import defaultdict
n = int(eval(input()))
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
cnt = defaultdict(int)
for i in range(n):
for j in range(i + 1, n):
dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
cnt[dif] += 1
print((n - max(list(cnt.values()), default=0)))
| n = int(eval(input()))
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
cnt = {}
for i, j in arr:
for k, l in arr:
if (i, j) == (k, l):
continue
dif = (k - i, l - j)
cnt.setdefault(dif, 0)
cnt[dif] += 1
print((n - max(list(cnt.values()), default=0)))
| false | 0 | [
"-# div2019-2B - Picking Up",
"-from collections import defaultdict",
"-",
"-cnt = defaultdict(int)",
"-for i in range(n):",
"- for j in range(i + 1, n):",
"- dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])",
"+cnt = {}",
"+for i, j in arr:",
"+ for k, l in arr:",
"+ if (i, j) == (k, l):",
"+ continue",
"+ dif = (k - i, l - j)",
"+ cnt.setdefault(dif, 0)"
] | false | 0.049816 | 0.048751 | 1.021831 | [
"s770849957",
"s944009754"
] |
u186838327 | p03361 | python | s593269986 | s734455030 | 190 | 68 | 39,664 | 66,584 | Accepted | Accepted | 64.21 | h, w = list(map(int, input().split()))
S = [str(eval(input())) for i in range(h)]
for i in range(h):
for j in range(w):
if S[i][j] == '#':
flag = False
for di,dj in (-1, 0), (1, 0), (0, 1), (0, -1):
ni, nj = i+di, j+dj
if 0 <= ni < h and 0 <= nj < w:
if S[ni][nj] == '#':
flag = True
if not flag:
print('No')
exit()
else:
print('Yes')
| h, w = list(map(int, input().split()))
S = [list(str(eval(input()))) for _ in range(h)]
for i in range(h):
for j in range(w):
if S[i][j] == '#':
flag = False
for di, dj in (-1, 0), (1, 0), (0, 1), (0, -1):
ni, nj = i+di, j+dj
if 0 <= ni < h and 0 <= nj < w:
if S[ni][nj] == '#':
flag = True
break
if not flag:
print('No')
exit()
else:
print('Yes')
| 17 | 18 | 500 | 538 | h, w = list(map(int, input().split()))
S = [str(eval(input())) for i in range(h)]
for i in range(h):
for j in range(w):
if S[i][j] == "#":
flag = False
for di, dj in (-1, 0), (1, 0), (0, 1), (0, -1):
ni, nj = i + di, j + dj
if 0 <= ni < h and 0 <= nj < w:
if S[ni][nj] == "#":
flag = True
if not flag:
print("No")
exit()
else:
print("Yes")
| h, w = list(map(int, input().split()))
S = [list(str(eval(input()))) for _ in range(h)]
for i in range(h):
for j in range(w):
if S[i][j] == "#":
flag = False
for di, dj in (-1, 0), (1, 0), (0, 1), (0, -1):
ni, nj = i + di, j + dj
if 0 <= ni < h and 0 <= nj < w:
if S[ni][nj] == "#":
flag = True
break
if not flag:
print("No")
exit()
else:
print("Yes")
| false | 5.555556 | [
"-S = [str(eval(input())) for i in range(h)]",
"+S = [list(str(eval(input()))) for _ in range(h)]",
"+ break"
] | false | 0.036907 | 0.034171 | 1.080045 | [
"s593269986",
"s734455030"
] |
u623231048 | p03608 | python | s118015079 | s774367085 | 605 | 392 | 63,964 | 52,700 | Accepted | Accepted | 35.21 | import heapq
import itertools
import sys
input = sys.stdin.readline
def main():
n,m,r = list(map(int,input().split()))
R = list(map(int,input().split()))
for i in range(r):
R[i] -= 1
roots = [[] for _ in range(n)]
for _ in range(m):
a,b,c = list(map(int,input().split()))
roots[a-1].append((b-1, c))
roots[b-1].append((a-1, c))
def dijkstra(edges, s):
hq = []
d = [-1] * n
d[s] = 0
heapq.heappush(hq, (0, s))
while hq:
d1, p = heapq.heappop(hq)
for p2, d2 in edges[p]:
if d[p2] == -1 or d[p2] > d1 + d2:
d[p2] = d1 + d2
heapq.heappush(hq, (d1+d2, p2))
return d
ans = 10**10
d = []
for i in range(n):
d1 = dijkstra(roots, i)
d.append(d1)
ptr = list(itertools.permutations(R, len(R))) # 順列列挙 5P3
for i in ptr:
tmp = 0
for j in range(len(i) - 1):
tmp += d[i[j]][i[j+1]]
ans = min(ans, tmp)
print(ans)
if __name__ == '__main__':
main()
| import sys, itertools
input = sys.stdin.readline
def main():
# d[i][j]は2頂点間i, j間の移動コストを格納, Vは頂点数
def warshall_floyd(d, V):
for k in range(V):
for i in range(V):
for j in range(V):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
return d # d[i][j]に頂点i, j間の最短距離を格納
n,m,r = list(map(int,input().split()))
R = list(map(int,input().split()))
for i in range(r):
R[i] -= 1
d = [[10**10] * n for _ in range(n)]
for _ in range(m):
a,b,c = list(map(int,input().split()))
d[a-1][b-1] = c
d[b-1][a-1] = c
d = warshall_floyd(d, n)
ans = 10**10
ptr = list(itertools.permutations(R, len(R))) # 順列列挙 5P3
for i in ptr:
tmp = 0
for j in range(len(i)-1):
tmp += d[i[j]][i[j+1]]
ans = min(ans, tmp)
print(ans)
if __name__ == '__main__':
main()
| 51 | 39 | 1,145 | 937 | import heapq
import itertools
import sys
input = sys.stdin.readline
def main():
n, m, r = list(map(int, input().split()))
R = list(map(int, input().split()))
for i in range(r):
R[i] -= 1
roots = [[] for _ in range(n)]
for _ in range(m):
a, b, c = list(map(int, input().split()))
roots[a - 1].append((b - 1, c))
roots[b - 1].append((a - 1, c))
def dijkstra(edges, s):
hq = []
d = [-1] * n
d[s] = 0
heapq.heappush(hq, (0, s))
while hq:
d1, p = heapq.heappop(hq)
for p2, d2 in edges[p]:
if d[p2] == -1 or d[p2] > d1 + d2:
d[p2] = d1 + d2
heapq.heappush(hq, (d1 + d2, p2))
return d
ans = 10**10
d = []
for i in range(n):
d1 = dijkstra(roots, i)
d.append(d1)
ptr = list(itertools.permutations(R, len(R))) # 順列列挙 5P3
for i in ptr:
tmp = 0
for j in range(len(i) - 1):
tmp += d[i[j]][i[j + 1]]
ans = min(ans, tmp)
print(ans)
if __name__ == "__main__":
main()
| import sys, itertools
input = sys.stdin.readline
def main():
# d[i][j]は2頂点間i, j間の移動コストを格納, Vは頂点数
def warshall_floyd(d, V):
for k in range(V):
for i in range(V):
for j in range(V):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
return d # d[i][j]に頂点i, j間の最短距離を格納
n, m, r = list(map(int, input().split()))
R = list(map(int, input().split()))
for i in range(r):
R[i] -= 1
d = [[10**10] * n for _ in range(n)]
for _ in range(m):
a, b, c = list(map(int, input().split()))
d[a - 1][b - 1] = c
d[b - 1][a - 1] = c
d = warshall_floyd(d, n)
ans = 10**10
ptr = list(itertools.permutations(R, len(R))) # 順列列挙 5P3
for i in ptr:
tmp = 0
for j in range(len(i) - 1):
tmp += d[i[j]][i[j + 1]]
ans = min(ans, tmp)
print(ans)
if __name__ == "__main__":
main()
| false | 23.529412 | [
"-import heapq",
"-import itertools",
"-import sys",
"+import sys, itertools",
"+ # d[i][j]は2頂点間i, j間の移動コストを格納, Vは頂点数",
"+ def warshall_floyd(d, V):",
"+ for k in range(V):",
"+ for i in range(V):",
"+ for j in range(V):",
"+ d[i][j] = min(d[i][j], d[i][k] + d[k][j])",
"+ return d # d[i][j]に頂点i, j間の最短距離を格納",
"+",
"- roots = [[] for _ in range(n)]",
"+ d = [[10**10] * n for _ in range(n)]",
"- roots[a - 1].append((b - 1, c))",
"- roots[b - 1].append((a - 1, c))",
"-",
"- def dijkstra(edges, s):",
"- hq = []",
"- d = [-1] * n",
"- d[s] = 0",
"- heapq.heappush(hq, (0, s))",
"- while hq:",
"- d1, p = heapq.heappop(hq)",
"- for p2, d2 in edges[p]:",
"- if d[p2] == -1 or d[p2] > d1 + d2:",
"- d[p2] = d1 + d2",
"- heapq.heappush(hq, (d1 + d2, p2))",
"- return d",
"-",
"+ d[a - 1][b - 1] = c",
"+ d[b - 1][a - 1] = c",
"+ d = warshall_floyd(d, n)",
"- d = []",
"- for i in range(n):",
"- d1 = dijkstra(roots, i)",
"- d.append(d1)"
] | false | 0.006731 | 0.058493 | 0.115067 | [
"s118015079",
"s774367085"
] |
u594859393 | p03330 | python | s335502723 | s480620636 | 1,098 | 194 | 21,216 | 6,132 | Accepted | Accepted | 82.33 | from itertools import product
n, c = list(map(int, input().split()))
color_costs = [list(map(int, input().split())) for _ in range(c)]
matrix = [list(map(int, input().split())) for _ in range(n)]
colord = {(i+1, j+1):cost for i, row in enumerate(color_costs)
for j, cost in enumerate(row)}
cellgroups = [[] for _ in range(3)]
for i, row in enumerate(matrix):
for j, color in enumerate(row):
cellgroups[(i+1+j+1)%3].append(color)
cc = [[(color, sum(colord[cellcolor, color] for cellcolor in cells))
for color in range(1,c+1)]
for cells in cellgroups]
dd = [sorted(xs, key=lambda x:x[1])[:3] for xs in cc]
ee = (a[1]+b[1]+c[1] for a, b, c in product(*dd) if len(set((a[0], b[0], c[0]))) == 3)
print((min(ee))) | from itertools import product
from collections import Counter
n, c = list(map(int, input().split()))
color_costs = [list(map(int, input().split())) for _ in range(c)]
matrix = [list(map(int, input().split())) for _ in range(n)]
colord = {(i, j):cost
for i, row in enumerate(color_costs)
for j, cost in enumerate(row)}
color_counts = []
for n in range(3):
counter = Counter(c-1 for i, row in enumerate(matrix)
for j, c in enumerate(row)
if (i+j)%3==n)
color_counts.append(counter)
cc = [[(color, sum(colord[cellcolor, color]*n for cellcolor, n in list(color_count.items())))
for color in range(c)]
for color_count in color_counts]
dd = [sorted(xs, key=lambda x:x[1])[:3] for xs in cc]
ee = (a[1]+b[1]+c[1] for a, b, c in product(*dd) if len(set((a[0], b[0], c[0]))) == 3)
print((min(ee))) | 19 | 25 | 776 | 1,052 | from itertools import product
n, c = list(map(int, input().split()))
color_costs = [list(map(int, input().split())) for _ in range(c)]
matrix = [list(map(int, input().split())) for _ in range(n)]
colord = {
(i + 1, j + 1): cost
for i, row in enumerate(color_costs)
for j, cost in enumerate(row)
}
cellgroups = [[] for _ in range(3)]
for i, row in enumerate(matrix):
for j, color in enumerate(row):
cellgroups[(i + 1 + j + 1) % 3].append(color)
cc = [
[
(color, sum(colord[cellcolor, color] for cellcolor in cells))
for color in range(1, c + 1)
]
for cells in cellgroups
]
dd = [sorted(xs, key=lambda x: x[1])[:3] for xs in cc]
ee = (
a[1] + b[1] + c[1] for a, b, c in product(*dd) if len(set((a[0], b[0], c[0]))) == 3
)
print((min(ee)))
| from itertools import product
from collections import Counter
n, c = list(map(int, input().split()))
color_costs = [list(map(int, input().split())) for _ in range(c)]
matrix = [list(map(int, input().split())) for _ in range(n)]
colord = {
(i, j): cost for i, row in enumerate(color_costs) for j, cost in enumerate(row)
}
color_counts = []
for n in range(3):
counter = Counter(
c - 1
for i, row in enumerate(matrix)
for j, c in enumerate(row)
if (i + j) % 3 == n
)
color_counts.append(counter)
cc = [
[
(
color,
sum(
colord[cellcolor, color] * n
for cellcolor, n in list(color_count.items())
),
)
for color in range(c)
]
for color_count in color_counts
]
dd = [sorted(xs, key=lambda x: x[1])[:3] for xs in cc]
ee = (
a[1] + b[1] + c[1] for a, b, c in product(*dd) if len(set((a[0], b[0], c[0]))) == 3
)
print((min(ee)))
| false | 24 | [
"+from collections import Counter",
"- (i + 1, j + 1): cost",
"- for i, row in enumerate(color_costs)",
"- for j, cost in enumerate(row)",
"+ (i, j): cost for i, row in enumerate(color_costs) for j, cost in enumerate(row)",
"-cellgroups = [[] for _ in range(3)]",
"-for i, row in enumerate(matrix):",
"- for j, color in enumerate(row):",
"- cellgroups[(i + 1 + j + 1) % 3].append(color)",
"+color_counts = []",
"+for n in range(3):",
"+ counter = Counter(",
"+ c - 1",
"+ for i, row in enumerate(matrix)",
"+ for j, c in enumerate(row)",
"+ if (i + j) % 3 == n",
"+ )",
"+ color_counts.append(counter)",
"- (color, sum(colord[cellcolor, color] for cellcolor in cells))",
"- for color in range(1, c + 1)",
"+ (",
"+ color,",
"+ sum(",
"+ colord[cellcolor, color] * n",
"+ for cellcolor, n in list(color_count.items())",
"+ ),",
"+ )",
"+ for color in range(c)",
"- for cells in cellgroups",
"+ for color_count in color_counts"
] | false | 0.036072 | 0.049609 | 0.727126 | [
"s335502723",
"s480620636"
] |
u046187684 | p03379 | python | s024396186 | s617946905 | 410 | 340 | 53,532 | 125,268 | Accepted | Accepted | 17.07 | def solve(string):
n, *x = list(map(int, string.split()))
mid = n // 2
x = [(i, _x) for i, _x in enumerate(x)]
x = sorted(x, key=lambda x: x[1])
ans = [[] for _ in range(n)]
for i, _x in enumerate(x):
ans[_x[0]] = str(x[mid][1]) if i < mid else str(x[mid - 1][1])
return "\n".join(ans)
if __name__ == '__main__':
print((solve('\n'.join([eval(input()), eval(input())]))))
| def solve(string):
n, *x = list(map(int, string.split()))
mid = n // 2
l, r = sorted(x)[mid - 1:mid + 1]
return "\n".join([str(r) if _x < r else str(l) for _x in x])
if __name__ == '__main__':
print((solve('\n'.join([eval(input()), eval(input())]))))
| 13 | 9 | 405 | 261 | def solve(string):
n, *x = list(map(int, string.split()))
mid = n // 2
x = [(i, _x) for i, _x in enumerate(x)]
x = sorted(x, key=lambda x: x[1])
ans = [[] for _ in range(n)]
for i, _x in enumerate(x):
ans[_x[0]] = str(x[mid][1]) if i < mid else str(x[mid - 1][1])
return "\n".join(ans)
if __name__ == "__main__":
print((solve("\n".join([eval(input()), eval(input())]))))
| def solve(string):
n, *x = list(map(int, string.split()))
mid = n // 2
l, r = sorted(x)[mid - 1 : mid + 1]
return "\n".join([str(r) if _x < r else str(l) for _x in x])
if __name__ == "__main__":
print((solve("\n".join([eval(input()), eval(input())]))))
| false | 30.769231 | [
"- x = [(i, _x) for i, _x in enumerate(x)]",
"- x = sorted(x, key=lambda x: x[1])",
"- ans = [[] for _ in range(n)]",
"- for i, _x in enumerate(x):",
"- ans[_x[0]] = str(x[mid][1]) if i < mid else str(x[mid - 1][1])",
"- return \"\\n\".join(ans)",
"+ l, r = sorted(x)[mid - 1 : mid + 1]",
"+ return \"\\n\".join([str(r) if _x < r else str(l) for _x in x])"
] | false | 0.112771 | 0.077735 | 1.45072 | [
"s024396186",
"s617946905"
] |
u271469978 | p03164 | python | s750955322 | s329759864 | 227 | 175 | 44,912 | 14,000 | Accepted | Accepted | 22.91 | def main():
N, W = list(map(int, input().split()))
#dp[v] vとなる最小のW
dp = [10**9+1 for _ in range(10**5+1)]
for _ in range(N):
w,v = list(map(int, input().split()))
for val in range(10**5, 1, -1):
if val - v < 1:
break
dp[val] = min(dp[val], dp[val - v] + w)
if dp[v] > w:
dp[v] = w
ans = 0
for v, w in enumerate(dp):
if w <= W:
ans = max(ans, v)
print(ans)
if __name__ == '__main__':
main() | import numpy as np
N, W = list(map(int, input().split()))
dp = np.ones(10**5+1, dtype=np.int64) * np.inf
dp[0] = 0
for _ in range(N):
w,v = list(map(int, input().split()))
np.minimum(dp[v:], dp[:-v] + w , dp[v:])
print((max(np.where(dp <= W)[0]))) | 19 | 8 | 523 | 248 | def main():
N, W = list(map(int, input().split()))
# dp[v] vとなる最小のW
dp = [10**9 + 1 for _ in range(10**5 + 1)]
for _ in range(N):
w, v = list(map(int, input().split()))
for val in range(10**5, 1, -1):
if val - v < 1:
break
dp[val] = min(dp[val], dp[val - v] + w)
if dp[v] > w:
dp[v] = w
ans = 0
for v, w in enumerate(dp):
if w <= W:
ans = max(ans, v)
print(ans)
if __name__ == "__main__":
main()
| import numpy as np
N, W = list(map(int, input().split()))
dp = np.ones(10**5 + 1, dtype=np.int64) * np.inf
dp[0] = 0
for _ in range(N):
w, v = list(map(int, input().split()))
np.minimum(dp[v:], dp[:-v] + w, dp[v:])
print((max(np.where(dp <= W)[0])))
| false | 57.894737 | [
"-def main():",
"- N, W = list(map(int, input().split()))",
"- # dp[v] vとなる最小のW",
"- dp = [10**9 + 1 for _ in range(10**5 + 1)]",
"- for _ in range(N):",
"- w, v = list(map(int, input().split()))",
"- for val in range(10**5, 1, -1):",
"- if val - v < 1:",
"- break",
"- dp[val] = min(dp[val], dp[val - v] + w)",
"- if dp[v] > w:",
"- dp[v] = w",
"- ans = 0",
"- for v, w in enumerate(dp):",
"- if w <= W:",
"- ans = max(ans, v)",
"- print(ans)",
"+import numpy as np",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+N, W = list(map(int, input().split()))",
"+dp = np.ones(10**5 + 1, dtype=np.int64) * np.inf",
"+dp[0] = 0",
"+for _ in range(N):",
"+ w, v = list(map(int, input().split()))",
"+ np.minimum(dp[v:], dp[:-v] + w, dp[v:])",
"+print((max(np.where(dp <= W)[0])))"
] | false | 0.390024 | 0.35831 | 1.088511 | [
"s750955322",
"s329759864"
] |
u197300773 | p03488 | python | s981892435 | s846020252 | 1,391 | 920 | 3,936 | 3,952 | Accepted | Accepted | 33.86 | def cul(x,X):
dic={0:1}
for i in range(len(x)):
tmp={}
for j in dic:
tmp[j+x[i]]=1
tmp[j-x[i]]=1
dic=tmp
if X in dic: return True
else: return False
S=eval(input())
s=list(S.split("T"))
X,Y=list(map(int,input().split()))
x,y=[len(i) for i in s[::2]],[len(i) for i in s[1::2]]
if S[0]=="F": X=abs(X-x.pop(0))
Y=abs(Y)
dx=sorted(x,reverse=True)
dy=sorted(y,reverse=True)
print(("Yes" if cul(dx,X) and cul(dy,Y) else "No")) | import sys
import math
from itertools import accumulate as acc
def cul(x,X):
dic={0:1}
for i in range(len(x)):
tmp={}
for j in dic:
tmp[j+x[i]]=1
tmp[j-x[i]]=1
dic=tmp
if X in dic: return True
else: return False
S=eval(input())
s=list(S.split("T"))
X,Y=list(map(int,input().split()))
x,y=[len(i) for i in s[::2]],[len(i) for i in s[1::2]]
if S[0]=="F": X=abs(X-x.pop(0))
Y=abs(Y)
print(("Yes" if cul(x,X) and cul(y,Y) else "No"))
| 22 | 24 | 494 | 507 | def cul(x, X):
dic = {0: 1}
for i in range(len(x)):
tmp = {}
for j in dic:
tmp[j + x[i]] = 1
tmp[j - x[i]] = 1
dic = tmp
if X in dic:
return True
else:
return False
S = eval(input())
s = list(S.split("T"))
X, Y = list(map(int, input().split()))
x, y = [len(i) for i in s[::2]], [len(i) for i in s[1::2]]
if S[0] == "F":
X = abs(X - x.pop(0))
Y = abs(Y)
dx = sorted(x, reverse=True)
dy = sorted(y, reverse=True)
print(("Yes" if cul(dx, X) and cul(dy, Y) else "No"))
| import sys
import math
from itertools import accumulate as acc
def cul(x, X):
dic = {0: 1}
for i in range(len(x)):
tmp = {}
for j in dic:
tmp[j + x[i]] = 1
tmp[j - x[i]] = 1
dic = tmp
if X in dic:
return True
else:
return False
S = eval(input())
s = list(S.split("T"))
X, Y = list(map(int, input().split()))
x, y = [len(i) for i in s[::2]], [len(i) for i in s[1::2]]
if S[0] == "F":
X = abs(X - x.pop(0))
Y = abs(Y)
print(("Yes" if cul(x, X) and cul(y, Y) else "No"))
| false | 8.333333 | [
"+import sys",
"+import math",
"+from itertools import accumulate as acc",
"+",
"+",
"-dx = sorted(x, reverse=True)",
"-dy = sorted(y, reverse=True)",
"-print((\"Yes\" if cul(dx, X) and cul(dy, Y) else \"No\"))",
"+print((\"Yes\" if cul(x, X) and cul(y, Y) else \"No\"))"
] | false | 0.053634 | 0.037405 | 1.433857 | [
"s981892435",
"s846020252"
] |
u418197217 | p02597 | python | s727233817 | s869072449 | 43 | 27 | 12,068 | 9,308 | Accepted | Accepted | 37.21 | n = int(eval(input()))
ls = list(eval(input()))
r = ls.count('R')
w = ls.count('W')
if r == 0 or w == 0:
print((0))
else:
r_in_half = ls[:r].count('R')
ans = r - r_in_half
print(ans)
| import sys
input = sys.stdin.readline
n = eval(input())
s = eval(input())
r = s.count('R')
print((s[:r].count('W')))
| 10 | 8 | 194 | 112 | n = int(eval(input()))
ls = list(eval(input()))
r = ls.count("R")
w = ls.count("W")
if r == 0 or w == 0:
print((0))
else:
r_in_half = ls[:r].count("R")
ans = r - r_in_half
print(ans)
| import sys
input = sys.stdin.readline
n = eval(input())
s = eval(input())
r = s.count("R")
print((s[:r].count("W")))
| false | 20 | [
"-n = int(eval(input()))",
"-ls = list(eval(input()))",
"-r = ls.count(\"R\")",
"-w = ls.count(\"W\")",
"-if r == 0 or w == 0:",
"- print((0))",
"-else:",
"- r_in_half = ls[:r].count(\"R\")",
"- ans = r - r_in_half",
"- print(ans)",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+n = eval(input())",
"+s = eval(input())",
"+r = s.count(\"R\")",
"+print((s[:r].count(\"W\")))"
] | false | 0.045944 | 0.083335 | 0.551315 | [
"s727233817",
"s869072449"
] |
u241159583 | p03607 | python | s216595331 | s297496909 | 171 | 155 | 20,568 | 23,880 | Accepted | Accepted | 9.36 | n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
p = {}
for a in A:
if a in p:
if p[a] == 1:
p[a] = 0
continue
p[a] = 1
ans = 0
for i in list(p.values()):ans += i
print(ans) | from collections import Counter
n = int(eval(input()))
a = Counter([eval(input()) for _ in range(n)])
ans = 0
for x in list(a.values()):
if x%2!=0: ans += 1
print(ans) | 13 | 7 | 225 | 159 | n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
p = {}
for a in A:
if a in p:
if p[a] == 1:
p[a] = 0
continue
p[a] = 1
ans = 0
for i in list(p.values()):
ans += i
print(ans)
| from collections import Counter
n = int(eval(input()))
a = Counter([eval(input()) for _ in range(n)])
ans = 0
for x in list(a.values()):
if x % 2 != 0:
ans += 1
print(ans)
| false | 46.153846 | [
"+from collections import Counter",
"+",
"-A = [int(eval(input())) for _ in range(n)]",
"-p = {}",
"-for a in A:",
"- if a in p:",
"- if p[a] == 1:",
"- p[a] = 0",
"- continue",
"- p[a] = 1",
"+a = Counter([eval(input()) for _ in range(n)])",
"-for i in list(p.values()):",
"- ans += i",
"+for x in list(a.values()):",
"+ if x % 2 != 0:",
"+ ans += 1"
] | false | 0.035663 | 0.040194 | 0.887266 | [
"s216595331",
"s297496909"
] |
u794173881 | p03040 | python | s964279465 | s328050289 | 1,790 | 1,311 | 124,752 | 109,528 | Accepted | Accepted | 26.76 | # Binary Indexed Tree (Fenwick Tree)
class BIT():
def __init__(self, n):
'''
n = 要素数
添字は i = 0 ~ n-1 となる
'''
self.n = n
self.bit = [0] * (n + 1)
def add(self, i, x):
'''i番目の要素にxを加算する'''
i = i + 1
while i <= self.n:
self.bit[i] += x
i += i & -i
def _sum(self, i):
s = 0
while i > 0:
s += self.bit[i]
i -= i & -i
return s
def get(self, i, j):
'''[i, j)の和を求める'''
return self._sum(j) - self._sum(i)
def solve():
ok = len_memo
ng = 0
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if 2 * bit1.get(mid, len_memo) <= cnt :
ok = mid
else:
ng = mid
return memo_inv[ng]
def compress(list1):
list2 = sorted(set(list1))
memo = {value : index for index, value in enumerate(list2)}
#for i in range(len(list1)):
# list1[i] = memo[list1[i]]
return memo, len(list2)
q = int(eval(input()))
info = [list(map(int, input().split())) for i in range(q)]
#座圧する
li1 = []
for i in range(q):
if info[i][0] == 1:
li1.append(info[i][1])
memo, len_memo = compress(li1)
memo_inv = dict([(v,k) for k,v in list(memo.items())])
#print(memo)
#print(memo_inv)
#値を管理するBIT
bit = BIT(len_memo)
#要素数を管理するBITに
bit1 = BIT(len_memo)
x = []
b = 0
cnt = 0
for i in range(q):
if info[i][0] == 1:
bit.add(memo[info[i][1]], info[i][1])
bit1.add(memo[info[i][1]], 1)
b += info[i][2]
cnt += 1
if info[i][0] == 2:
median_x = solve()
sum1 = bit.get(0, memo[median_x])
num1 = bit1.get(0, memo[median_x])
sum2 = bit.get(memo[median_x], len_memo)
num2 = bit1.get(memo[median_x], len_memo)
#print(median_x, sum1,num1, sum2, num2)
print((median_x, abs(num1*median_x - sum1) + abs(num2*median_x - sum2) + b))
| import heapq
class DynamicMedian():
"""値をO(logN)で追加し、中央値クエリにO(1)で応える
add(val): valを追加する
median_low(): 小さい方の中央値(low median)を返す
median_high(): 大きい方の中央値(high median)を返す
"""
def __init__(self):
self.left_q = [] # 小さい値を降順で格納する
self.right_q = [] # 大きい値を昇順で格納する
self.left_sum = 0
self.right_sum = 0
def add(self, val):
"""valを追加する"""
if len(self.left_q) == len(self.right_q):
self.left_sum += val
val = -heapq.heappushpop(self.left_q, -val)
self.left_sum -= val
heapq.heappush(self.right_q, val)
self.right_sum += val
else:
self.right_sum += val
val = heapq.heappushpop(self.right_q, val)
self.right_sum -= val
heapq.heappush(self.left_q, -val)
self.left_sum += val
def median_low(self):
"""小さい方のmedianを返す"""
if len(self.left_q) + 1 == len(self.right_q):
return self.right_q[0]
else:
return -self.left_q[0]
def median_high(self):
"""大きい方のmedianを返す"""
return self.right_q[0]
q = int(eval(input()))
info = [list(map(int, input().split())) for i in range(q)]
dm = DynamicMedian()
b = 0
for i in range(q):
if info[i][0] == 1:
_, tmp_a, tmp_b = info[i]
dm.add(tmp_a)
b += tmp_b
else:
med = dm.median_high()
lsum = dm.left_sum
rsum = dm.right_sum
lnum = len(dm.left_q)
rnum = len(dm.right_q)
tmp = (lnum*med - lsum) + (rsum - rnum*med)
print((dm.median_low(), tmp + b)) | 85 | 59 | 2,013 | 1,700 | # Binary Indexed Tree (Fenwick Tree)
class BIT:
def __init__(self, n):
"""
n = 要素数
添字は i = 0 ~ n-1 となる
"""
self.n = n
self.bit = [0] * (n + 1)
def add(self, i, x):
"""i番目の要素にxを加算する"""
i = i + 1
while i <= self.n:
self.bit[i] += x
i += i & -i
def _sum(self, i):
s = 0
while i > 0:
s += self.bit[i]
i -= i & -i
return s
def get(self, i, j):
"""[i, j)の和を求める"""
return self._sum(j) - self._sum(i)
def solve():
ok = len_memo
ng = 0
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if 2 * bit1.get(mid, len_memo) <= cnt:
ok = mid
else:
ng = mid
return memo_inv[ng]
def compress(list1):
list2 = sorted(set(list1))
memo = {value: index for index, value in enumerate(list2)}
# for i in range(len(list1)):
# list1[i] = memo[list1[i]]
return memo, len(list2)
q = int(eval(input()))
info = [list(map(int, input().split())) for i in range(q)]
# 座圧する
li1 = []
for i in range(q):
if info[i][0] == 1:
li1.append(info[i][1])
memo, len_memo = compress(li1)
memo_inv = dict([(v, k) for k, v in list(memo.items())])
# print(memo)
# print(memo_inv)
# 値を管理するBIT
bit = BIT(len_memo)
# 要素数を管理するBITに
bit1 = BIT(len_memo)
x = []
b = 0
cnt = 0
for i in range(q):
if info[i][0] == 1:
bit.add(memo[info[i][1]], info[i][1])
bit1.add(memo[info[i][1]], 1)
b += info[i][2]
cnt += 1
if info[i][0] == 2:
median_x = solve()
sum1 = bit.get(0, memo[median_x])
num1 = bit1.get(0, memo[median_x])
sum2 = bit.get(memo[median_x], len_memo)
num2 = bit1.get(memo[median_x], len_memo)
# print(median_x, sum1,num1, sum2, num2)
print((median_x, abs(num1 * median_x - sum1) + abs(num2 * median_x - sum2) + b))
| import heapq
class DynamicMedian:
"""値をO(logN)で追加し、中央値クエリにO(1)で応える
add(val): valを追加する
median_low(): 小さい方の中央値(low median)を返す
median_high(): 大きい方の中央値(high median)を返す
"""
def __init__(self):
self.left_q = [] # 小さい値を降順で格納する
self.right_q = [] # 大きい値を昇順で格納する
self.left_sum = 0
self.right_sum = 0
def add(self, val):
"""valを追加する"""
if len(self.left_q) == len(self.right_q):
self.left_sum += val
val = -heapq.heappushpop(self.left_q, -val)
self.left_sum -= val
heapq.heappush(self.right_q, val)
self.right_sum += val
else:
self.right_sum += val
val = heapq.heappushpop(self.right_q, val)
self.right_sum -= val
heapq.heappush(self.left_q, -val)
self.left_sum += val
def median_low(self):
"""小さい方のmedianを返す"""
if len(self.left_q) + 1 == len(self.right_q):
return self.right_q[0]
else:
return -self.left_q[0]
def median_high(self):
"""大きい方のmedianを返す"""
return self.right_q[0]
q = int(eval(input()))
info = [list(map(int, input().split())) for i in range(q)]
dm = DynamicMedian()
b = 0
for i in range(q):
if info[i][0] == 1:
_, tmp_a, tmp_b = info[i]
dm.add(tmp_a)
b += tmp_b
else:
med = dm.median_high()
lsum = dm.left_sum
rsum = dm.right_sum
lnum = len(dm.left_q)
rnum = len(dm.right_q)
tmp = (lnum * med - lsum) + (rsum - rnum * med)
print((dm.median_low(), tmp + b))
| false | 30.588235 | [
"-# Binary Indexed Tree (Fenwick Tree)",
"-class BIT:",
"- def __init__(self, n):",
"- \"\"\"",
"- n = 要素数",
"- 添字は i = 0 ~ n-1 となる",
"- \"\"\"",
"- self.n = n",
"- self.bit = [0] * (n + 1)",
"-",
"- def add(self, i, x):",
"- \"\"\"i番目の要素にxを加算する\"\"\"",
"- i = i + 1",
"- while i <= self.n:",
"- self.bit[i] += x",
"- i += i & -i",
"-",
"- def _sum(self, i):",
"- s = 0",
"- while i > 0:",
"- s += self.bit[i]",
"- i -= i & -i",
"- return s",
"-",
"- def get(self, i, j):",
"- \"\"\"[i, j)の和を求める\"\"\"",
"- return self._sum(j) - self._sum(i)",
"+import heapq",
"-def solve():",
"- ok = len_memo",
"- ng = 0",
"- while abs(ok - ng) > 1:",
"- mid = (ok + ng) // 2",
"- if 2 * bit1.get(mid, len_memo) <= cnt:",
"- ok = mid",
"+class DynamicMedian:",
"+ \"\"\"値をO(logN)で追加し、中央値クエリにO(1)で応える",
"+ add(val): valを追加する",
"+ median_low(): 小さい方の中央値(low median)を返す",
"+ median_high(): 大きい方の中央値(high median)を返す",
"+ \"\"\"",
"+",
"+ def __init__(self):",
"+ self.left_q = [] # 小さい値を降順で格納する",
"+ self.right_q = [] # 大きい値を昇順で格納する",
"+ self.left_sum = 0",
"+ self.right_sum = 0",
"+",
"+ def add(self, val):",
"+ \"\"\"valを追加する\"\"\"",
"+ if len(self.left_q) == len(self.right_q):",
"+ self.left_sum += val",
"+ val = -heapq.heappushpop(self.left_q, -val)",
"+ self.left_sum -= val",
"+ heapq.heappush(self.right_q, val)",
"+ self.right_sum += val",
"- ng = mid",
"- return memo_inv[ng]",
"+ self.right_sum += val",
"+ val = heapq.heappushpop(self.right_q, val)",
"+ self.right_sum -= val",
"+ heapq.heappush(self.left_q, -val)",
"+ self.left_sum += val",
"+ def median_low(self):",
"+ \"\"\"小さい方のmedianを返す\"\"\"",
"+ if len(self.left_q) + 1 == len(self.right_q):",
"+ return self.right_q[0]",
"+ else:",
"+ return -self.left_q[0]",
"-def compress(list1):",
"- list2 = sorted(set(list1))",
"- memo = {value: index for index, value in enumerate(list2)}",
"- # for i in range(len(list1)):",
"- # list1[i] = memo[list1[i]]",
"- return memo, len(list2)",
"+ def median_high(self):",
"+ \"\"\"大きい方のmedianを返す\"\"\"",
"+ return self.right_q[0]",
"-# 座圧する",
"-li1 = []",
"+dm = DynamicMedian()",
"+b = 0",
"- li1.append(info[i][1])",
"-memo, len_memo = compress(li1)",
"-memo_inv = dict([(v, k) for k, v in list(memo.items())])",
"-# print(memo)",
"-# print(memo_inv)",
"-# 値を管理するBIT",
"-bit = BIT(len_memo)",
"-# 要素数を管理するBITに",
"-bit1 = BIT(len_memo)",
"-x = []",
"-b = 0",
"-cnt = 0",
"-for i in range(q):",
"- if info[i][0] == 1:",
"- bit.add(memo[info[i][1]], info[i][1])",
"- bit1.add(memo[info[i][1]], 1)",
"- b += info[i][2]",
"- cnt += 1",
"- if info[i][0] == 2:",
"- median_x = solve()",
"- sum1 = bit.get(0, memo[median_x])",
"- num1 = bit1.get(0, memo[median_x])",
"- sum2 = bit.get(memo[median_x], len_memo)",
"- num2 = bit1.get(memo[median_x], len_memo)",
"- # print(median_x, sum1,num1, sum2, num2)",
"- print((median_x, abs(num1 * median_x - sum1) + abs(num2 * median_x - sum2) + b))",
"+ _, tmp_a, tmp_b = info[i]",
"+ dm.add(tmp_a)",
"+ b += tmp_b",
"+ else:",
"+ med = dm.median_high()",
"+ lsum = dm.left_sum",
"+ rsum = dm.right_sum",
"+ lnum = len(dm.left_q)",
"+ rnum = len(dm.right_q)",
"+ tmp = (lnum * med - lsum) + (rsum - rnum * med)",
"+ print((dm.median_low(), tmp + b))"
] | false | 0.076308 | 0.039059 | 1.953656 | [
"s964279465",
"s328050289"
] |
u408260374 | p02373 | python | s782555454 | s426917104 | 2,750 | 2,320 | 74,212 | 41,016 | Accepted | Accepted | 15.64 | class Edge:
def __init__(self, dst, weight):
self.dst, self.weight = dst, weight
def __lt__(self, e):
return self.weight > e.weight
class Graph:
def __init__(self, V):
self.V = V
self.E = [[] for _ in range(V)]
def add_edge(self, src, dst, weight):
self.E[src].append(Edge(dst, weight))
class HeavyLightDecomposition:
def __init__(self, g, root=0):
self.g = g
self.vid, self.head, self.heavy, self.parent = [0] * g.V, [-1] * g.V, [-1] * g.V, [-1] * g.V
self.dfs(root)
self.bfs(root)
def dfs(self, root):
stack = [(root, -1)]
sub, max_sub = [1] * self.g.V, [(0, -1)] * self.g.V
used = [False] * self.g.V
while stack:
v, par = stack.pop()
if not used[v]:
used[v] = True
self.parent[v] = par
stack.append((v, par))
stack.extend((e.dst, v) for e in self.g.E[v] if e.dst != par)
else:
if par != -1:
sub[par] += sub[v]
max_sub[par] = max(max_sub[par], (sub[v], v))
self.heavy[v] = max_sub[v][1]
def bfs(self, root=0):
from collections import deque
k, que = 0, deque([root])
while que:
r = v = que.popleft()
while v != -1:
self.vid[v], self.head[v] = k, r
for e in self.g.E[v]:
if e.dst != self.parent[v] and e.dst != self.heavy[v]:
que.append(e.dst)
k += 1
v = self.heavy[v]
def lca(self, u, v):
while self.head[u] != self.head[v]:
if self.vid[u] > self.vid[v]:
u, v = v, u
v = self.parent[self.head[v]]
else:
if self.vid[u] > self.vid[v]:
u, v = v, u
return u
N = int(eval(input()))
g = Graph(N)
for i in range(N):
for c in map(int, input().split()[1:]):
g.add_edge(i, c, 1)
g.add_edge(c, i, 1)
hld = HeavyLightDecomposition(g)
Q = int(eval(input()))
for _ in range(Q):
u, v = list(map(int, input().split()))
print((hld.lca(u, v))) | class HeavyLightDecomposition:
def __init__(self, g, root=0):
self.g = g
self.vid, self.head, self.heavy, self.parent = [0] * len(g), [-1] * len(g), [-1] * len(g), [-1] * len(g)
self.dfs(root)
self.bfs(root)
def dfs(self, root):
stack = [(root, -1)]
sub, max_sub = [1] * len(self.g), [(0, -1)] * len(self.g)
used = [False] * len(self.g)
while stack:
v, par = stack.pop()
if not used[v]:
used[v] = True
self.parent[v] = par
stack.append((v, par))
stack.extend((c, v) for c in self.g[v] if c != par)
else:
if par != -1:
sub[par] += sub[v]
max_sub[par] = max(max_sub[par], (sub[v], v))
self.heavy[v] = max_sub[v][1]
def bfs(self, root=0):
from collections import deque
k, que = 0, deque([root])
while que:
r = v = que.popleft()
while v != -1:
self.vid[v], self.head[v] = k, r
for c in self.g[v]:
if c != self.parent[v] and c != self.heavy[v]:
que.append(c)
k += 1
v = self.heavy[v]
def lca(self, u, v):
while self.head[u] != self.head[v]:
if self.vid[u] > self.vid[v]:
u, v = v, u
v = self.parent[self.head[v]]
else:
if self.vid[u] > self.vid[v]:
u, v = v, u
return u
N = int(eval(input()))
g = [[] for _ in range(N)]
for i in range(N):
for c in map(int, input().split()[1:]):
g[i].append(c)
g[c].append(i)
hld = HeavyLightDecomposition(g)
Q = int(eval(input()))
for _ in range(Q):
u, v = list(map(int, input().split()))
print((hld.lca(u, v))) | 76 | 59 | 2,276 | 1,911 | class Edge:
def __init__(self, dst, weight):
self.dst, self.weight = dst, weight
def __lt__(self, e):
return self.weight > e.weight
class Graph:
def __init__(self, V):
self.V = V
self.E = [[] for _ in range(V)]
def add_edge(self, src, dst, weight):
self.E[src].append(Edge(dst, weight))
class HeavyLightDecomposition:
def __init__(self, g, root=0):
self.g = g
self.vid, self.head, self.heavy, self.parent = (
[0] * g.V,
[-1] * g.V,
[-1] * g.V,
[-1] * g.V,
)
self.dfs(root)
self.bfs(root)
def dfs(self, root):
stack = [(root, -1)]
sub, max_sub = [1] * self.g.V, [(0, -1)] * self.g.V
used = [False] * self.g.V
while stack:
v, par = stack.pop()
if not used[v]:
used[v] = True
self.parent[v] = par
stack.append((v, par))
stack.extend((e.dst, v) for e in self.g.E[v] if e.dst != par)
else:
if par != -1:
sub[par] += sub[v]
max_sub[par] = max(max_sub[par], (sub[v], v))
self.heavy[v] = max_sub[v][1]
def bfs(self, root=0):
from collections import deque
k, que = 0, deque([root])
while que:
r = v = que.popleft()
while v != -1:
self.vid[v], self.head[v] = k, r
for e in self.g.E[v]:
if e.dst != self.parent[v] and e.dst != self.heavy[v]:
que.append(e.dst)
k += 1
v = self.heavy[v]
def lca(self, u, v):
while self.head[u] != self.head[v]:
if self.vid[u] > self.vid[v]:
u, v = v, u
v = self.parent[self.head[v]]
else:
if self.vid[u] > self.vid[v]:
u, v = v, u
return u
N = int(eval(input()))
g = Graph(N)
for i in range(N):
for c in map(int, input().split()[1:]):
g.add_edge(i, c, 1)
g.add_edge(c, i, 1)
hld = HeavyLightDecomposition(g)
Q = int(eval(input()))
for _ in range(Q):
u, v = list(map(int, input().split()))
print((hld.lca(u, v)))
| class HeavyLightDecomposition:
def __init__(self, g, root=0):
self.g = g
self.vid, self.head, self.heavy, self.parent = (
[0] * len(g),
[-1] * len(g),
[-1] * len(g),
[-1] * len(g),
)
self.dfs(root)
self.bfs(root)
def dfs(self, root):
stack = [(root, -1)]
sub, max_sub = [1] * len(self.g), [(0, -1)] * len(self.g)
used = [False] * len(self.g)
while stack:
v, par = stack.pop()
if not used[v]:
used[v] = True
self.parent[v] = par
stack.append((v, par))
stack.extend((c, v) for c in self.g[v] if c != par)
else:
if par != -1:
sub[par] += sub[v]
max_sub[par] = max(max_sub[par], (sub[v], v))
self.heavy[v] = max_sub[v][1]
def bfs(self, root=0):
from collections import deque
k, que = 0, deque([root])
while que:
r = v = que.popleft()
while v != -1:
self.vid[v], self.head[v] = k, r
for c in self.g[v]:
if c != self.parent[v] and c != self.heavy[v]:
que.append(c)
k += 1
v = self.heavy[v]
def lca(self, u, v):
while self.head[u] != self.head[v]:
if self.vid[u] > self.vid[v]:
u, v = v, u
v = self.parent[self.head[v]]
else:
if self.vid[u] > self.vid[v]:
u, v = v, u
return u
N = int(eval(input()))
g = [[] for _ in range(N)]
for i in range(N):
for c in map(int, input().split()[1:]):
g[i].append(c)
g[c].append(i)
hld = HeavyLightDecomposition(g)
Q = int(eval(input()))
for _ in range(Q):
u, v = list(map(int, input().split()))
print((hld.lca(u, v)))
| false | 22.368421 | [
"-class Edge:",
"- def __init__(self, dst, weight):",
"- self.dst, self.weight = dst, weight",
"-",
"- def __lt__(self, e):",
"- return self.weight > e.weight",
"-",
"-",
"-class Graph:",
"- def __init__(self, V):",
"- self.V = V",
"- self.E = [[] for _ in range(V)]",
"-",
"- def add_edge(self, src, dst, weight):",
"- self.E[src].append(Edge(dst, weight))",
"-",
"-",
"- [0] * g.V,",
"- [-1] * g.V,",
"- [-1] * g.V,",
"- [-1] * g.V,",
"+ [0] * len(g),",
"+ [-1] * len(g),",
"+ [-1] * len(g),",
"+ [-1] * len(g),",
"- sub, max_sub = [1] * self.g.V, [(0, -1)] * self.g.V",
"- used = [False] * self.g.V",
"+ sub, max_sub = [1] * len(self.g), [(0, -1)] * len(self.g)",
"+ used = [False] * len(self.g)",
"- stack.extend((e.dst, v) for e in self.g.E[v] if e.dst != par)",
"+ stack.extend((c, v) for c in self.g[v] if c != par)",
"- for e in self.g.E[v]:",
"- if e.dst != self.parent[v] and e.dst != self.heavy[v]:",
"- que.append(e.dst)",
"+ for c in self.g[v]:",
"+ if c != self.parent[v] and c != self.heavy[v]:",
"+ que.append(c)",
"-g = Graph(N)",
"+g = [[] for _ in range(N)]",
"- g.add_edge(i, c, 1)",
"- g.add_edge(c, i, 1)",
"+ g[i].append(c)",
"+ g[c].append(i)"
] | false | 0.036043 | 0.086226 | 0.418007 | [
"s782555454",
"s426917104"
] |
u152331265 | p02720 | python | s741423279 | s691469963 | 98 | 69 | 15,768 | 7,200 | Accepted | Accepted | 29.59 | k = int(eval(input()))
lunlun = list(range(1, 10))
for i in range(k - 1):
a = lunlun[i]
b = a * 10 + a % 10
if a % 10 != 0:
lunlun.append(b - 1)
lunlun.append(b)
if a % 10 != 9:
lunlun.append(b + 1)
print((lunlun[k - 1])) | k = int(eval(input()))
li = [i + 1 for i in range(9)]
c = 0
while len(li) < k:
if li[c] % 10 != 0:
li.append(li[c] * 10 + li[c] % 10 - 1)
li.append(li[c] * 10 + li[c] % 10)
if li[c] % 10 != 9:
li.append(li[c] * 10 + li[c] % 10 + 1)
c += 1
print((li[k - 1])) | 12 | 12 | 261 | 293 | k = int(eval(input()))
lunlun = list(range(1, 10))
for i in range(k - 1):
a = lunlun[i]
b = a * 10 + a % 10
if a % 10 != 0:
lunlun.append(b - 1)
lunlun.append(b)
if a % 10 != 9:
lunlun.append(b + 1)
print((lunlun[k - 1]))
| k = int(eval(input()))
li = [i + 1 for i in range(9)]
c = 0
while len(li) < k:
if li[c] % 10 != 0:
li.append(li[c] * 10 + li[c] % 10 - 1)
li.append(li[c] * 10 + li[c] % 10)
if li[c] % 10 != 9:
li.append(li[c] * 10 + li[c] % 10 + 1)
c += 1
print((li[k - 1]))
| false | 0 | [
"-lunlun = list(range(1, 10))",
"-for i in range(k - 1):",
"- a = lunlun[i]",
"- b = a * 10 + a % 10",
"- if a % 10 != 0:",
"- lunlun.append(b - 1)",
"- lunlun.append(b)",
"- if a % 10 != 9:",
"- lunlun.append(b + 1)",
"-print((lunlun[k - 1]))",
"+li = [i + 1 for i in range(9)]",
"+c = 0",
"+while len(li) < k:",
"+ if li[c] % 10 != 0:",
"+ li.append(li[c] * 10 + li[c] % 10 - 1)",
"+ li.append(li[c] * 10 + li[c] % 10)",
"+ if li[c] % 10 != 9:",
"+ li.append(li[c] * 10 + li[c] % 10 + 1)",
"+ c += 1",
"+print((li[k - 1]))"
] | false | 0.057218 | 0.06891 | 0.83033 | [
"s741423279",
"s691469963"
] |
u017435045 | p02263 | python | s651574210 | s244079996 | 30 | 20 | 6,004 | 5,608 | Accepted | Accepted | 33.33 | from collections import deque as D
line, stack = D(input().split()), D()
while line:
hoge = line.popleft()
if hoge.isdigit():
stack.append(hoge)
else:
a, b = int(stack.pop()),int(stack.pop())
if hoge =="*":
stack.append(a*b)
elif hoge == "+":
stack.append(a+b)
elif hoge == "-":
stack.append(b-a)
else:
stack.append(b//a)
print((stack.popleft()))
| s = list(input().split())
a = []
for x in s:
if x in ['+', '-', '*']:
c, b = str(a.pop()), str(a.pop())
b+= x+c
a+=[int(eval(b))]
else:
a+= [int(x)]
print((a.pop()))
| 17 | 13 | 469 | 237 | from collections import deque as D
line, stack = D(input().split()), D()
while line:
hoge = line.popleft()
if hoge.isdigit():
stack.append(hoge)
else:
a, b = int(stack.pop()), int(stack.pop())
if hoge == "*":
stack.append(a * b)
elif hoge == "+":
stack.append(a + b)
elif hoge == "-":
stack.append(b - a)
else:
stack.append(b // a)
print((stack.popleft()))
| s = list(input().split())
a = []
for x in s:
if x in ["+", "-", "*"]:
c, b = str(a.pop()), str(a.pop())
b += x + c
a += [int(eval(b))]
else:
a += [int(x)]
print((a.pop()))
| false | 23.529412 | [
"-from collections import deque as D",
"-",
"-line, stack = D(input().split()), D()",
"-while line:",
"- hoge = line.popleft()",
"- if hoge.isdigit():",
"- stack.append(hoge)",
"+s = list(input().split())",
"+a = []",
"+for x in s:",
"+ if x in [\"+\", \"-\", \"*\"]:",
"+ c, b = str(a.pop()), str(a.pop())",
"+ b += x + c",
"+ a += [int(eval(b))]",
"- a, b = int(stack.pop()), int(stack.pop())",
"- if hoge == \"*\":",
"- stack.append(a * b)",
"- elif hoge == \"+\":",
"- stack.append(a + b)",
"- elif hoge == \"-\":",
"- stack.append(b - a)",
"- else:",
"- stack.append(b // a)",
"-print((stack.popleft()))",
"+ a += [int(x)]",
"+print((a.pop()))"
] | false | 0.052269 | 0.050184 | 1.04156 | [
"s651574210",
"s244079996"
] |
u835482198 | p03951 | python | s904810811 | s726190272 | 22 | 17 | 3,064 | 3,060 | Accepted | Accepted | 22.73 | N = int(eval(input()))
s = eval(input())
t = eval(input())
ans = 2 * N
for i in range(1, N+1):
# print(s[-i:], t[:i])
if s[-i:] == t[:i]:
ans = min(ans, 2 * N - i)
print(ans)
| N = int(eval(input()))
prefix = eval(input())
suffix = eval(input())
if len(prefix) + len(suffix) < N:
d = N - len(prefix) + len(suffix)
print((len(prefix + 'a' * d + suffix)))
else:
s = ""
for i in range(1, N):
# print(prefix[-i:], suffix[:i])
if prefix[-i:] == suffix[:i]:
s = prefix[:-i] + suffix
if suffix == prefix:
s = suffix
if len(s) == 0:
s = prefix + suffix
print((len(s)))
| 10 | 20 | 183 | 456 | N = int(eval(input()))
s = eval(input())
t = eval(input())
ans = 2 * N
for i in range(1, N + 1):
# print(s[-i:], t[:i])
if s[-i:] == t[:i]:
ans = min(ans, 2 * N - i)
print(ans)
| N = int(eval(input()))
prefix = eval(input())
suffix = eval(input())
if len(prefix) + len(suffix) < N:
d = N - len(prefix) + len(suffix)
print((len(prefix + "a" * d + suffix)))
else:
s = ""
for i in range(1, N):
# print(prefix[-i:], suffix[:i])
if prefix[-i:] == suffix[:i]:
s = prefix[:-i] + suffix
if suffix == prefix:
s = suffix
if len(s) == 0:
s = prefix + suffix
print((len(s)))
| false | 50 | [
"-s = eval(input())",
"-t = eval(input())",
"-ans = 2 * N",
"-for i in range(1, N + 1):",
"- # print(s[-i:], t[:i])",
"- if s[-i:] == t[:i]:",
"- ans = min(ans, 2 * N - i)",
"-print(ans)",
"+prefix = eval(input())",
"+suffix = eval(input())",
"+if len(prefix) + len(suffix) < N:",
"+ d = N - len(prefix) + len(suffix)",
"+ print((len(prefix + \"a\" * d + suffix)))",
"+else:",
"+ s = \"\"",
"+ for i in range(1, N):",
"+ # print(prefix[-i:], suffix[:i])",
"+ if prefix[-i:] == suffix[:i]:",
"+ s = prefix[:-i] + suffix",
"+ if suffix == prefix:",
"+ s = suffix",
"+ if len(s) == 0:",
"+ s = prefix + suffix",
"+ print((len(s)))"
] | false | 0.036263 | 0.036879 | 0.983312 | [
"s904810811",
"s726190272"
] |
u997641430 | p03161 | python | s266175269 | s198554348 | 423 | 367 | 61,024 | 61,024 | Accepted | Accepted | 13.24 | n, k = list(map(int, input().split()))
*H, = list(map(int, input().split()))
X = [0]
for i in range(1, n):
x = 1 << 30
for j in range(1, k+1):
if i-j >= 0:
x = min(x, X[i-j]+abs(H[i]-H[i-j]))
X.append(x)
print((X[n-1]))
| n, k = list(map(int, input().split()))
*H, = list(map(int, input().split()))
X = [0]
for i in range(1, n):
x = 1 << 30
for j in range(1, min(i, k)+1):
x = min(x, X[i-j]+abs(H[i]-H[i-j]))
X.append(x)
print((X[n-1]))
| 10 | 9 | 247 | 229 | n, k = list(map(int, input().split()))
(*H,) = list(map(int, input().split()))
X = [0]
for i in range(1, n):
x = 1 << 30
for j in range(1, k + 1):
if i - j >= 0:
x = min(x, X[i - j] + abs(H[i] - H[i - j]))
X.append(x)
print((X[n - 1]))
| n, k = list(map(int, input().split()))
(*H,) = list(map(int, input().split()))
X = [0]
for i in range(1, n):
x = 1 << 30
for j in range(1, min(i, k) + 1):
x = min(x, X[i - j] + abs(H[i] - H[i - j]))
X.append(x)
print((X[n - 1]))
| false | 10 | [
"- for j in range(1, k + 1):",
"- if i - j >= 0:",
"- x = min(x, X[i - j] + abs(H[i] - H[i - j]))",
"+ for j in range(1, min(i, k) + 1):",
"+ x = min(x, X[i - j] + abs(H[i] - H[i - j]))"
] | false | 0.036302 | 0.031287 | 1.160311 | [
"s266175269",
"s198554348"
] |
u340781749 | p03357 | python | s400916093 | s704901984 | 1,530 | 991 | 167,812 | 165,124 | Accepted | Accepted | 35.23 | from itertools import accumulate
def solve(n, rev):
def existence_right(rev_c):
n2 = n * 2
acc = [[0] * n2]
row = [0] * n2
for x in rev_c:
row[n2 - x - 1] += 1
acc.append(list(reversed(list(accumulate(row)))))
return acc
# How many white/black ball lower than 'k' righter than index x? (0<=x<=2N-1)
# cost[color][k][x]
cost = list(map(existence_right, rev))
dp = [0] + list(accumulate(c[y] for y, c in zip(rev[1], cost[1])))
for x, cw0, cw1 in zip(rev[0], cost[0], cost[0][1:]):
ndp = [0] * (n + 1)
cw0x = cw0[x]
ndp[0] = prev = dp[0] + cw0x
for b, (y, cb0, cb1) in enumerate(zip(rev[1], cost[1], cost[1][1:])):
ndp[b + 1] = prev = min(dp[b + 1] + cw0x + cb1[x], prev + cw1[y] + cb0[y])
dp = ndp
return dp[n]
n = int(eval(input()))
# White/Black 'k' ball is what-th in whole row?
rev = [[0] * n, [0] * n]
for i in range(n * 2):
c, a = input().split()
a = int(a) - 1
rev[int(c == 'B')][a] = i
print((solve(n, rev)))
| from itertools import accumulate
def solve(n, rev):
def existence_right(rev_c):
n2 = n * 2
acc = [[0] * n2]
row = [0] * n2
for x in rev_c:
row[n2 - x - 1] += 1
acc.append(list(reversed(list(accumulate(row)))))
return acc
# How many white/black ball lower than 'k' righter than index x? (0<=x<=2N-1)
# cost[color][k][x]
cost_w, cost_b = list(map(existence_right, rev))
dp = [0] + list(accumulate(c[y] for y, c in zip(rev[1], cost_b)))
for w, x in enumerate(rev[0]):
ndp = [0] * (n + 1)
cwx = cost_w[w][x]
ndp[0] = prev = dp[0] + cwx
for b, y in enumerate(rev[1]):
ndp[b + 1] = prev = min(dp[b + 1] + cwx + cost_b[b + 1][x],
prev + cost_w[w + 1][y] + cost_b[b][y])
dp = ndp
return dp[n]
n = int(eval(input()))
# White/Black 'k' ball is what-th in whole row?
rev = [[0] * n, [0] * n]
for i in range(n * 2):
c, a = input().split()
a = int(a) - 1
rev[int(c == 'B')][a] = i
print((solve(n, rev)))
| 36 | 37 | 1,104 | 1,117 | from itertools import accumulate
def solve(n, rev):
def existence_right(rev_c):
n2 = n * 2
acc = [[0] * n2]
row = [0] * n2
for x in rev_c:
row[n2 - x - 1] += 1
acc.append(list(reversed(list(accumulate(row)))))
return acc
# How many white/black ball lower than 'k' righter than index x? (0<=x<=2N-1)
# cost[color][k][x]
cost = list(map(existence_right, rev))
dp = [0] + list(accumulate(c[y] for y, c in zip(rev[1], cost[1])))
for x, cw0, cw1 in zip(rev[0], cost[0], cost[0][1:]):
ndp = [0] * (n + 1)
cw0x = cw0[x]
ndp[0] = prev = dp[0] + cw0x
for b, (y, cb0, cb1) in enumerate(zip(rev[1], cost[1], cost[1][1:])):
ndp[b + 1] = prev = min(dp[b + 1] + cw0x + cb1[x], prev + cw1[y] + cb0[y])
dp = ndp
return dp[n]
n = int(eval(input()))
# White/Black 'k' ball is what-th in whole row?
rev = [[0] * n, [0] * n]
for i in range(n * 2):
c, a = input().split()
a = int(a) - 1
rev[int(c == "B")][a] = i
print((solve(n, rev)))
| from itertools import accumulate
def solve(n, rev):
def existence_right(rev_c):
n2 = n * 2
acc = [[0] * n2]
row = [0] * n2
for x in rev_c:
row[n2 - x - 1] += 1
acc.append(list(reversed(list(accumulate(row)))))
return acc
# How many white/black ball lower than 'k' righter than index x? (0<=x<=2N-1)
# cost[color][k][x]
cost_w, cost_b = list(map(existence_right, rev))
dp = [0] + list(accumulate(c[y] for y, c in zip(rev[1], cost_b)))
for w, x in enumerate(rev[0]):
ndp = [0] * (n + 1)
cwx = cost_w[w][x]
ndp[0] = prev = dp[0] + cwx
for b, y in enumerate(rev[1]):
ndp[b + 1] = prev = min(
dp[b + 1] + cwx + cost_b[b + 1][x],
prev + cost_w[w + 1][y] + cost_b[b][y],
)
dp = ndp
return dp[n]
n = int(eval(input()))
# White/Black 'k' ball is what-th in whole row?
rev = [[0] * n, [0] * n]
for i in range(n * 2):
c, a = input().split()
a = int(a) - 1
rev[int(c == "B")][a] = i
print((solve(n, rev)))
| false | 2.702703 | [
"- cost = list(map(existence_right, rev))",
"- dp = [0] + list(accumulate(c[y] for y, c in zip(rev[1], cost[1])))",
"- for x, cw0, cw1 in zip(rev[0], cost[0], cost[0][1:]):",
"+ cost_w, cost_b = list(map(existence_right, rev))",
"+ dp = [0] + list(accumulate(c[y] for y, c in zip(rev[1], cost_b)))",
"+ for w, x in enumerate(rev[0]):",
"- cw0x = cw0[x]",
"- ndp[0] = prev = dp[0] + cw0x",
"- for b, (y, cb0, cb1) in enumerate(zip(rev[1], cost[1], cost[1][1:])):",
"- ndp[b + 1] = prev = min(dp[b + 1] + cw0x + cb1[x], prev + cw1[y] + cb0[y])",
"+ cwx = cost_w[w][x]",
"+ ndp[0] = prev = dp[0] + cwx",
"+ for b, y in enumerate(rev[1]):",
"+ ndp[b + 1] = prev = min(",
"+ dp[b + 1] + cwx + cost_b[b + 1][x],",
"+ prev + cost_w[w + 1][y] + cost_b[b][y],",
"+ )"
] | false | 0.071513 | 0.069234 | 1.032916 | [
"s400916093",
"s704901984"
] |
u488127128 | p03401 | python | s820122203 | s939435428 | 227 | 176 | 14,172 | 14,176 | Accepted | Accepted | 22.47 | N = int(eval(input()))
A = list(map(int, input().split()))
total = 0
p = 0
for a in A:
total += abs(p-a)
p = a
total += abs(p)
print((total - abs(A[0]) - abs(A[0]-A[1]) + abs(A[1])))
for n in range(1,N-1):
print((total - abs(A[n-1]-A[n]) - abs(A[n]-A[n+1]) + abs(A[n-1]-A[n+1])))
print((total - abs(A[N-2]-A[N-1]) - abs(A[N-1]) + abs(A[N-2]))) | def solve():
N = int(eval(input()))
A = list(map(int, input().split()))
total = 0
p = 0
for a in A:
total += abs(p-a)
p = a
total += abs(p)
print((total - abs(A[0]) - abs(A[0]-A[1]) + abs(A[1])))
for n in range(1,N-1):
print((total - abs(A[n-1]-A[n]) - abs(A[n]-A[n+1]) + abs(A[n-1]-A[n+1])))
print((total - abs(A[N-2]-A[N-1]) - abs(A[N-1]) + abs(A[N-2])))
if __name__ == '__main__':
solve() | 13 | 18 | 356 | 467 | N = int(eval(input()))
A = list(map(int, input().split()))
total = 0
p = 0
for a in A:
total += abs(p - a)
p = a
total += abs(p)
print((total - abs(A[0]) - abs(A[0] - A[1]) + abs(A[1])))
for n in range(1, N - 1):
print(
(total - abs(A[n - 1] - A[n]) - abs(A[n] - A[n + 1]) + abs(A[n - 1] - A[n + 1]))
)
print((total - abs(A[N - 2] - A[N - 1]) - abs(A[N - 1]) + abs(A[N - 2])))
| def solve():
N = int(eval(input()))
A = list(map(int, input().split()))
total = 0
p = 0
for a in A:
total += abs(p - a)
p = a
total += abs(p)
print((total - abs(A[0]) - abs(A[0] - A[1]) + abs(A[1])))
for n in range(1, N - 1):
print(
(
total
- abs(A[n - 1] - A[n])
- abs(A[n] - A[n + 1])
+ abs(A[n - 1] - A[n + 1])
)
)
print((total - abs(A[N - 2] - A[N - 1]) - abs(A[N - 1]) + abs(A[N - 2])))
if __name__ == "__main__":
solve()
| false | 27.777778 | [
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-total = 0",
"-p = 0",
"-for a in A:",
"- total += abs(p - a)",
"- p = a",
"-total += abs(p)",
"-print((total - abs(A[0]) - abs(A[0] - A[1]) + abs(A[1])))",
"-for n in range(1, N - 1):",
"- print(",
"- (total - abs(A[n - 1] - A[n]) - abs(A[n] - A[n + 1]) + abs(A[n - 1] - A[n + 1]))",
"- )",
"-print((total - abs(A[N - 2] - A[N - 1]) - abs(A[N - 1]) + abs(A[N - 2])))",
"+def solve():",
"+ N = int(eval(input()))",
"+ A = list(map(int, input().split()))",
"+ total = 0",
"+ p = 0",
"+ for a in A:",
"+ total += abs(p - a)",
"+ p = a",
"+ total += abs(p)",
"+ print((total - abs(A[0]) - abs(A[0] - A[1]) + abs(A[1])))",
"+ for n in range(1, N - 1):",
"+ print(",
"+ (",
"+ total",
"+ - abs(A[n - 1] - A[n])",
"+ - abs(A[n] - A[n + 1])",
"+ + abs(A[n - 1] - A[n + 1])",
"+ )",
"+ )",
"+ print((total - abs(A[N - 2] - A[N - 1]) - abs(A[N - 1]) + abs(A[N - 2])))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
] | false | 0.048709 | 0.04812 | 1.012232 | [
"s820122203",
"s939435428"
] |
u597374218 | p02743 | python | s043461483 | s842847563 | 36 | 30 | 9,936 | 8,996 | Accepted | Accepted | 16.67 | from decimal import Decimal
a,b,c=list(map(int,input().split()))
print(("Yes" if Decimal(a).sqrt()+Decimal(b).sqrt()<Decimal(c).sqrt() else "No")) | a,b,c=list(map(int,input().split()))
print(("Yes" if c-a-b>0 and 4*a*b<(c-a-b)**2 else "No")) | 3 | 2 | 140 | 86 | from decimal import Decimal
a, b, c = list(map(int, input().split()))
print(("Yes" if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt() else "No"))
| a, b, c = list(map(int, input().split()))
print(("Yes" if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2 else "No"))
| false | 33.333333 | [
"-from decimal import Decimal",
"-",
"-print((\"Yes\" if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt() else \"No\"))",
"+print((\"Yes\" if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2 else \"No\"))"
] | false | 0.046067 | 0.035689 | 1.290781 | [
"s043461483",
"s842847563"
] |
u591016708 | p02983 | python | s197898200 | s266071795 | 1,569 | 98 | 2,940 | 3,060 | Accepted | Accepted | 93.75 | L, R = list(map(int, input().split()))
ans = 2018
for x in range(L, min(R, L+2019)):
for y in range(L+1, min(R+1, L+2019)):
ans = min(ans, (x*y)%2019)
print(ans)
| L, R = list(map(int, input().split()))
ans = 2018
for x in range(L, min(R, L+2019)):
for y in range(L+1, min(R+1, L+2019)):
ans = min(ans, (x*y)%2019)
if ans == 0:
print((0))
quit()
print(ans) | 6 | 9 | 173 | 236 | L, R = list(map(int, input().split()))
ans = 2018
for x in range(L, min(R, L + 2019)):
for y in range(L + 1, min(R + 1, L + 2019)):
ans = min(ans, (x * y) % 2019)
print(ans)
| L, R = list(map(int, input().split()))
ans = 2018
for x in range(L, min(R, L + 2019)):
for y in range(L + 1, min(R + 1, L + 2019)):
ans = min(ans, (x * y) % 2019)
if ans == 0:
print((0))
quit()
print(ans)
| false | 33.333333 | [
"+ if ans == 0:",
"+ print((0))",
"+ quit()"
] | false | 0.11715 | 0.036434 | 3.215391 | [
"s197898200",
"s266071795"
] |
u296518383 | p03448 | python | s480693259 | s718064967 | 49 | 37 | 3,060 | 3,060 | Accepted | Accepted | 24.49 | A, B, C, X = int(eval(input())), int(eval(input())), int(eval(input())), int(eval(input()))
answer = 0
for a in range(A + 1):
for b in range(B + 1):
for c in range(C + 1):
if a * 500 + b * 100 + c * 50 == X:
answer += 1
print(answer) | A, B, C, X = int(eval(input())), int(eval(input())), int(eval(input())), int(eval(input()))
X //= 50
answer = 0
for a in range(A + 1):
if a * 10 > X:
continue
for b in range(B + 1):
for c in range(C + 1):
if a * 10 + b * 2 + c == X:
answer += 1
print(answer) | 10 | 13 | 240 | 274 | A, B, C, X = (
int(eval(input())),
int(eval(input())),
int(eval(input())),
int(eval(input())),
)
answer = 0
for a in range(A + 1):
for b in range(B + 1):
for c in range(C + 1):
if a * 500 + b * 100 + c * 50 == X:
answer += 1
print(answer)
| A, B, C, X = (
int(eval(input())),
int(eval(input())),
int(eval(input())),
int(eval(input())),
)
X //= 50
answer = 0
for a in range(A + 1):
if a * 10 > X:
continue
for b in range(B + 1):
for c in range(C + 1):
if a * 10 + b * 2 + c == X:
answer += 1
print(answer)
| false | 23.076923 | [
"+X //= 50",
"+ if a * 10 > X:",
"+ continue",
"- if a * 500 + b * 100 + c * 50 == X:",
"+ if a * 10 + b * 2 + c == X:"
] | false | 0.095459 | 0.057126 | 1.671037 | [
"s480693259",
"s718064967"
] |
u644907318 | p03545 | python | s459275004 | s446163129 | 172 | 68 | 38,384 | 61,888 | Accepted | Accepted | 60.47 | from itertools import product
A,B,C,D =list(eval(input()))
for z in product(("+","-"),repeat=3):
if eval(A+z[0]+B+z[1]+C+z[2]+D)==7:
print((A+z[0]+B+z[1]+C+z[2]+D+"=7"))
break | from itertools import product
A,B,C,D = list(input().strip())
for x in product(("+","-"),repeat=3):
if eval(A+x[0]+B+x[1]+C+x[2]+D)==7:
print((A+x[0]+B+x[1]+C+x[2]+D+"=7"))
break | 6 | 6 | 192 | 201 | from itertools import product
A, B, C, D = list(eval(input()))
for z in product(("+", "-"), repeat=3):
if eval(A + z[0] + B + z[1] + C + z[2] + D) == 7:
print((A + z[0] + B + z[1] + C + z[2] + D + "=7"))
break
| from itertools import product
A, B, C, D = list(input().strip())
for x in product(("+", "-"), repeat=3):
if eval(A + x[0] + B + x[1] + C + x[2] + D) == 7:
print((A + x[0] + B + x[1] + C + x[2] + D + "=7"))
break
| false | 0 | [
"-A, B, C, D = list(eval(input()))",
"-for z in product((\"+\", \"-\"), repeat=3):",
"- if eval(A + z[0] + B + z[1] + C + z[2] + D) == 7:",
"- print((A + z[0] + B + z[1] + C + z[2] + D + \"=7\"))",
"+A, B, C, D = list(input().strip())",
"+for x in product((\"+\", \"-\"), repeat=3):",
"+ if eval(A + x[0] + B + x[1] + C + x[2] + D) == 7:",
"+ print((A + x[0] + B + x[1] + C + x[2] + D + \"=7\"))"
] | false | 0.037718 | 0.042837 | 0.880504 | [
"s459275004",
"s446163129"
] |
u927534107 | p03339 | python | s787174754 | s940332099 | 230 | 168 | 20,556 | 15,520 | Accepted | Accepted | 26.96 | n=int(eval(input()))
s=list(eval(input()))
n_W,n_E=0,0
l_W,l_E=[0],[0]
for i in s:
if i=="W":n_W+=1
else:n_E+=1
l_W.append(n_W)
l_E.append(n_E)
ans=10**9+7
for i in range(n):
tmp=l_W[i]+l_E[-1]-l_E[i+1]
if tmp<ans:ans=tmp
print(ans) | n = int(eval(input()))
s = str(eval(input()))
lst_ans=[]
num_e= s.count("E")
ans = num_e
for i in range(n):
if s[i] == "E":ans -= 1
if i != 0:
if s[i-1]=="W":ans += 1
lst_ans.append(ans)
print((min(lst_ans))) | 14 | 12 | 257 | 226 | n = int(eval(input()))
s = list(eval(input()))
n_W, n_E = 0, 0
l_W, l_E = [0], [0]
for i in s:
if i == "W":
n_W += 1
else:
n_E += 1
l_W.append(n_W)
l_E.append(n_E)
ans = 10**9 + 7
for i in range(n):
tmp = l_W[i] + l_E[-1] - l_E[i + 1]
if tmp < ans:
ans = tmp
print(ans)
| n = int(eval(input()))
s = str(eval(input()))
lst_ans = []
num_e = s.count("E")
ans = num_e
for i in range(n):
if s[i] == "E":
ans -= 1
if i != 0:
if s[i - 1] == "W":
ans += 1
lst_ans.append(ans)
print((min(lst_ans)))
| false | 14.285714 | [
"-s = list(eval(input()))",
"-n_W, n_E = 0, 0",
"-l_W, l_E = [0], [0]",
"-for i in s:",
"- if i == \"W\":",
"- n_W += 1",
"- else:",
"- n_E += 1",
"- l_W.append(n_W)",
"- l_E.append(n_E)",
"-ans = 10**9 + 7",
"+s = str(eval(input()))",
"+lst_ans = []",
"+num_e = s.count(\"E\")",
"+ans = num_e",
"- tmp = l_W[i] + l_E[-1] - l_E[i + 1]",
"- if tmp < ans:",
"- ans = tmp",
"-print(ans)",
"+ if s[i] == \"E\":",
"+ ans -= 1",
"+ if i != 0:",
"+ if s[i - 1] == \"W\":",
"+ ans += 1",
"+ lst_ans.append(ans)",
"+print((min(lst_ans)))"
] | false | 0.141743 | 0.037903 | 3.739596 | [
"s787174754",
"s940332099"
] |
u127499732 | p03435 | python | s247200265 | s753774868 | 148 | 18 | 12,424 | 3,060 | Accepted | Accepted | 87.84 | def main():
import numpy as np
c = [list(map(int, input().split())) for _ in range(3)]
f = [[x[0] - x[1], x[1] - x[2], x[2] - x[0]] for x in c]
g = f[0] == f[1] == f[2]
print(('Yes' if g else 'No'))
if __name__ == '__main__':
main()
| def main():
c = [list(map(int, input().split())) for _ in range(3)]
f = [[x[0] - x[1], x[1] - x[2], x[2] - x[0]] for x in c]
g = f[0] == f[1] == f[2]
print(('Yes' if g else 'No'))
if __name__ == '__main__':
main()
| 10 | 9 | 266 | 242 | def main():
import numpy as np
c = [list(map(int, input().split())) for _ in range(3)]
f = [[x[0] - x[1], x[1] - x[2], x[2] - x[0]] for x in c]
g = f[0] == f[1] == f[2]
print(("Yes" if g else "No"))
if __name__ == "__main__":
main()
| def main():
c = [list(map(int, input().split())) for _ in range(3)]
f = [[x[0] - x[1], x[1] - x[2], x[2] - x[0]] for x in c]
g = f[0] == f[1] == f[2]
print(("Yes" if g else "No"))
if __name__ == "__main__":
main()
| false | 10 | [
"- import numpy as np",
"-"
] | false | 0.064536 | 0.036443 | 1.770866 | [
"s247200265",
"s753774868"
] |
u472065247 | p02878 | python | s666170527 | s897929566 | 2,543 | 1,843 | 192,136 | 190,616 | Accepted | Accepted | 27.53 | N,A,B=list(map(int,input().split()));M=998244353;P=N+1;f=1;F=[1]*P;I=[1]*P;z=0;R=range
for n in R(1,P):F[n]=f=f*n%M
I[N]=i=pow(f,M-2,M)
for n in R(N,1,-1):I[n-1]=i=i*n%M
for k in R(min(A+1,N-B)if N-B-A else A+1):Q=N-B-k-1;z=(z+(B-k)*F[B+k-1]*I[B]*I[k]*F[Q+A-k]*I[Q]*I[A-k])%M
print((z if B else 1)) | N,A,B=list(map(int,input().split()));M=998244353;P=N+1;f=1;F=[1]*P;I=[1]*P;z=0;R=range
for n in R(1,P):F[n]=f=f*n%M
I[N]=i=pow(f,M-2,M)
for n in R(N,1,-1):I[n-1]=i=i*n%M
for k in R(min(A+1,N-B)if N-B-A else A+1):Q=N-B-k-1;z+=(B-k)*F[B+k-1]*I[B]*I[k]*F[Q+A-k]*I[Q]*I[A-k]
print((z%M if B else 1)) | 6 | 6 | 295 | 292 | N, A, B = list(map(int, input().split()))
M = 998244353
P = N + 1
f = 1
F = [1] * P
I = [1] * P
z = 0
R = range
for n in R(1, P):
F[n] = f = f * n % M
I[N] = i = pow(f, M - 2, M)
for n in R(N, 1, -1):
I[n - 1] = i = i * n % M
for k in R(min(A + 1, N - B) if N - B - A else A + 1):
Q = N - B - k - 1
z = (z + (B - k) * F[B + k - 1] * I[B] * I[k] * F[Q + A - k] * I[Q] * I[A - k]) % M
print((z if B else 1))
| N, A, B = list(map(int, input().split()))
M = 998244353
P = N + 1
f = 1
F = [1] * P
I = [1] * P
z = 0
R = range
for n in R(1, P):
F[n] = f = f * n % M
I[N] = i = pow(f, M - 2, M)
for n in R(N, 1, -1):
I[n - 1] = i = i * n % M
for k in R(min(A + 1, N - B) if N - B - A else A + 1):
Q = N - B - k - 1
z += (B - k) * F[B + k - 1] * I[B] * I[k] * F[Q + A - k] * I[Q] * I[A - k]
print((z % M if B else 1))
| false | 0 | [
"- z = (z + (B - k) * F[B + k - 1] * I[B] * I[k] * F[Q + A - k] * I[Q] * I[A - k]) % M",
"-print((z if B else 1))",
"+ z += (B - k) * F[B + k - 1] * I[B] * I[k] * F[Q + A - k] * I[Q] * I[A - k]",
"+print((z % M if B else 1))"
] | false | 0.60445 | 0.495188 | 1.220647 | [
"s666170527",
"s897929566"
] |
u652081898 | p03284 | python | s488928401 | s462388268 | 19 | 17 | 3,316 | 2,940 | Accepted | Accepted | 10.53 | N, K = list(map(int, input().split() ))
if N%K == 0:
print((0))
else:
print((1)) | n, k = list(map(int, input().split()))
if n%k == 0:
print("0")
else:
print("1") | 5 | 6 | 78 | 87 | N, K = list(map(int, input().split()))
if N % K == 0:
print((0))
else:
print((1))
| n, k = list(map(int, input().split()))
if n % k == 0:
print("0")
else:
print("1")
| false | 16.666667 | [
"-N, K = list(map(int, input().split()))",
"-if N % K == 0:",
"- print((0))",
"+n, k = list(map(int, input().split()))",
"+if n % k == 0:",
"+ print(\"0\")",
"- print((1))",
"+ print(\"1\")"
] | false | 0.041831 | 0.03959 | 1.056614 | [
"s488928401",
"s462388268"
] |
u009961299 | p02392 | python | s222617454 | s196368170 | 30 | 20 | 6,720 | 5,600 | Accepted | Accepted | 33.33 | [ a, b, c ] = list(map ( int, input ( ).split ( ) ));
if a < b < c:
print ( "Yes" )
else:
print ( "No" ) | x = input().split()
a, b, c = int(x[0]), int(x[1]), int(x[2])
if a < b < c:
print("Yes")
else:
print("No")
| 6 | 8 | 108 | 124 | [a, b, c] = list(map(int, input().split()))
if a < b < c:
print("Yes")
else:
print("No")
| x = input().split()
a, b, c = int(x[0]), int(x[1]), int(x[2])
if a < b < c:
print("Yes")
else:
print("No")
| false | 25 | [
"-[a, b, c] = list(map(int, input().split()))",
"+x = input().split()",
"+a, b, c = int(x[0]), int(x[1]), int(x[2])"
] | false | 0.039093 | 0.038159 | 1.024481 | [
"s222617454",
"s196368170"
] |
u729133443 | p02691 | python | s990321197 | s795233306 | 184 | 124 | 142,024 | 98,856 | Accepted | Accepted | 32.61 | from collections import*
n,*a=list(map(int,open(0).read().split()))
s=0
d=defaultdict(int)
for i,a in enumerate(a):
s+=d[i-a]
d[i+a]+=1
print(s) | n,*a=list(map(int,open(0).read().split()))
i=s=0
d=[0]*n
for a in a:
if i>=a:s+=d[i-a]
if i+a<n:d[i+a]+=1
i+=1
print(s) | 8 | 8 | 149 | 126 | from collections import *
n, *a = list(map(int, open(0).read().split()))
s = 0
d = defaultdict(int)
for i, a in enumerate(a):
s += d[i - a]
d[i + a] += 1
print(s)
| n, *a = list(map(int, open(0).read().split()))
i = s = 0
d = [0] * n
for a in a:
if i >= a:
s += d[i - a]
if i + a < n:
d[i + a] += 1
i += 1
print(s)
| false | 0 | [
"-from collections import *",
"-",
"-s = 0",
"-d = defaultdict(int)",
"-for i, a in enumerate(a):",
"- s += d[i - a]",
"- d[i + a] += 1",
"+i = s = 0",
"+d = [0] * n",
"+for a in a:",
"+ if i >= a:",
"+ s += d[i - a]",
"+ if i + a < n:",
"+ d[i + a] += 1",
"+ i += 1"
] | false | 0.061167 | 0.07718 | 0.792519 | [
"s990321197",
"s795233306"
] |
u298297089 | p03737 | python | s319804129 | s830806771 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | a,b,c = input().split()
ans = a[0]+b[0]+c[0]
print((ans.upper())) | a,b,c = input().split()
print(((a[0] + b[0] + c[0]).upper()))
| 3 | 2 | 65 | 61 | a, b, c = input().split()
ans = a[0] + b[0] + c[0]
print((ans.upper()))
| a, b, c = input().split()
print(((a[0] + b[0] + c[0]).upper()))
| false | 33.333333 | [
"-ans = a[0] + b[0] + c[0]",
"-print((ans.upper()))",
"+print(((a[0] + b[0] + c[0]).upper()))"
] | false | 0.038369 | 0.038126 | 1.006385 | [
"s319804129",
"s830806771"
] |
u634046173 | p02843 | python | s835279631 | s118100115 | 163 | 28 | 9,084 | 9,140 | Accepted | Accepted | 82.82 | N=int(eval(input()))
b=0
for x in range(1,N//100+1):
for y in range(100*x,105*x+1):
if N==y:
print((1))
exit()
print((0)) | N=int(eval(input()))
b=0
x = N //100
for y in range(100*x,105*x+1):
if N==y:
print((1))
exit()
print((0))
| 8 | 8 | 136 | 113 | N = int(eval(input()))
b = 0
for x in range(1, N // 100 + 1):
for y in range(100 * x, 105 * x + 1):
if N == y:
print((1))
exit()
print((0))
| N = int(eval(input()))
b = 0
x = N // 100
for y in range(100 * x, 105 * x + 1):
if N == y:
print((1))
exit()
print((0))
| false | 0 | [
"-for x in range(1, N // 100 + 1):",
"- for y in range(100 * x, 105 * x + 1):",
"- if N == y:",
"- print((1))",
"- exit()",
"+x = N // 100",
"+for y in range(100 * x, 105 * x + 1):",
"+ if N == y:",
"+ print((1))",
"+ exit()"
] | false | 0.036953 | 0.036378 | 1.015795 | [
"s835279631",
"s118100115"
] |
u761320129 | p03722 | python | s141294741 | s051959743 | 1,481 | 877 | 3,388 | 9,344 | Accepted | Accepted | 40.78 | N,M = list(map(int,input().split()))
es = [tuple(map(int,input().split())) for i in range(M)]
INF = float('inf')
d = [INF] * N
d[0] = 0
for i in range(N):
for fr,to,cost in es:
fr,to = fr-1,to-1
cost *= -1
if d[fr] != INF and d[to] > d[fr]+cost:
d[to] = d[fr] + cost
if i == N-1 and to == N-1:
print('inf')
exit()
print((-d[-1])) | N,M = list(map(int,input().split()))
ABC = [tuple(map(int,input().split())) for i in range(M)]
INF = float('inf')
dist = [INF] * N
dist[0] = 0
for i in range(N):
for a,b,c in ABC:
a,b,c = a-1,b-1,-c
if dist[b] > dist[a] + c:
dist[b] = dist[a] + c
if i==N-1 and b == N-1:
print('inf')
exit()
print((-dist[-1])) | 16 | 15 | 421 | 392 | N, M = list(map(int, input().split()))
es = [tuple(map(int, input().split())) for i in range(M)]
INF = float("inf")
d = [INF] * N
d[0] = 0
for i in range(N):
for fr, to, cost in es:
fr, to = fr - 1, to - 1
cost *= -1
if d[fr] != INF and d[to] > d[fr] + cost:
d[to] = d[fr] + cost
if i == N - 1 and to == N - 1:
print("inf")
exit()
print((-d[-1]))
| N, M = list(map(int, input().split()))
ABC = [tuple(map(int, input().split())) for i in range(M)]
INF = float("inf")
dist = [INF] * N
dist[0] = 0
for i in range(N):
for a, b, c in ABC:
a, b, c = a - 1, b - 1, -c
if dist[b] > dist[a] + c:
dist[b] = dist[a] + c
if i == N - 1 and b == N - 1:
print("inf")
exit()
print((-dist[-1]))
| false | 6.25 | [
"-es = [tuple(map(int, input().split())) for i in range(M)]",
"+ABC = [tuple(map(int, input().split())) for i in range(M)]",
"-d = [INF] * N",
"-d[0] = 0",
"+dist = [INF] * N",
"+dist[0] = 0",
"- for fr, to, cost in es:",
"- fr, to = fr - 1, to - 1",
"- cost *= -1",
"- if d[fr] != INF and d[to] > d[fr] + cost:",
"- d[to] = d[fr] + cost",
"- if i == N - 1 and to == N - 1:",
"+ for a, b, c in ABC:",
"+ a, b, c = a - 1, b - 1, -c",
"+ if dist[b] > dist[a] + c:",
"+ dist[b] = dist[a] + c",
"+ if i == N - 1 and b == N - 1:",
"-print((-d[-1]))",
"+print((-dist[-1]))"
] | false | 0.046682 | 0.087462 | 0.533742 | [
"s141294741",
"s051959743"
] |
u261103969 | p02659 | python | s801741654 | s292922122 | 63 | 23 | 61,784 | 9,168 | Accepted | Accepted | 63.49 | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
a, b = input().split()
c, d = int(a), int(b[0] + b[-2:])
print((c * d // 100))
if __name__ == '__main__':
main()
| a, b = input().split() # まず文字列で受け取ります
p = int(a) # aはそのままint型にします
q = int(b[0] + b[2] + b[3]) # b[0] + b[2] + b[3]を整数に変換すれば、bの100倍を正確に得られます
print((p * q // 100)) # 2つを掛けて100で整数の割り算をすれば終わりです | 17 | 5 | 270 | 195 | import sys
readline = sys.stdin.readline
MOD = 10**9 + 7
INF = float("INF")
sys.setrecursionlimit(10**5)
def main():
a, b = input().split()
c, d = int(a), int(b[0] + b[-2:])
print((c * d // 100))
if __name__ == "__main__":
main()
| a, b = input().split() # まず文字列で受け取ります
p = int(a) # aはそのままint型にします
q = int(b[0] + b[2] + b[3]) # b[0] + b[2] + b[3]を整数に変換すれば、bの100倍を正確に得られます
print((p * q // 100)) # 2つを掛けて100で整数の割り算をすれば終わりです
| false | 70.588235 | [
"-import sys",
"-",
"-readline = sys.stdin.readline",
"-MOD = 10**9 + 7",
"-INF = float(\"INF\")",
"-sys.setrecursionlimit(10**5)",
"-",
"-",
"-def main():",
"- a, b = input().split()",
"- c, d = int(a), int(b[0] + b[-2:])",
"- print((c * d // 100))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+a, b = input().split() # まず文字列で受け取ります",
"+p = int(a) # aはそのままint型にします",
"+q = int(b[0] + b[2] + b[3]) # b[0] + b[2] + b[3]を整数に変換すれば、bの100倍を正確に得られます",
"+print((p * q // 100)) # 2つを掛けて100で整数の割り算をすれば終わりです"
] | false | 0.04084 | 0.04544 | 0.898771 | [
"s801741654",
"s292922122"
] |
u792078574 | p02610 | python | s109543653 | s251575173 | 972 | 727 | 111,544 | 42,532 | Accepted | Accepted | 25.21 | from heapq import heappush, heappop
T = int(eval(input()))
for _ in range(T):
N = int(eval(input()))
arr1 = []
arr2 = []
for _ in range(N):
K, L, R = list(map(int, input().split()))
if L > R:
arr1.append((K, L, R))
else:
arr2.append((N-K, R, L))
arr1.sort()
baseS = 0
diffS = 0
q = []
length = 0
for K, L, R in arr1:
baseS += R
diff = L - R
heappush(q, diff)
diffS += diff
length += 1
while length > K:
d = heappop(q)
diffS -= d
length -= 1
ans = baseS + diffS
arr2.sort()
baseS = 0
diffS = 0
q = []
length = 0
for K, L, R in arr2:
baseS += R
diff = L - R
heappush(q, diff)
diffS += diff
length += 1
while length > K:
d = heappop(q)
diffS -= d
length -= 1
ans += baseS + diffS
print(ans)
| from heapq import heappush, heappop
T = int(eval(input()))
def process(arr):
arr.sort()
baseS = 0
diffS = 0
q = []
length = 0
for K, L, R in arr:
baseS += R
diff = L - R
heappush(q, diff)
diffS += diff
length += 1
while length > K:
d = heappop(q)
diffS -= d
length -= 1
return baseS + diffS
for _ in range(T):
N = int(eval(input()))
arr1 = []
arr2 = []
for _ in range(N):
K, L, R = list(map(int, input().split()))
if L > R:
arr1.append((K, L, R))
else:
arr2.append((N-K, R, L))
print((process(arr1) + process(arr2)))
| 48 | 32 | 1,018 | 716 | from heapq import heappush, heappop
T = int(eval(input()))
for _ in range(T):
N = int(eval(input()))
arr1 = []
arr2 = []
for _ in range(N):
K, L, R = list(map(int, input().split()))
if L > R:
arr1.append((K, L, R))
else:
arr2.append((N - K, R, L))
arr1.sort()
baseS = 0
diffS = 0
q = []
length = 0
for K, L, R in arr1:
baseS += R
diff = L - R
heappush(q, diff)
diffS += diff
length += 1
while length > K:
d = heappop(q)
diffS -= d
length -= 1
ans = baseS + diffS
arr2.sort()
baseS = 0
diffS = 0
q = []
length = 0
for K, L, R in arr2:
baseS += R
diff = L - R
heappush(q, diff)
diffS += diff
length += 1
while length > K:
d = heappop(q)
diffS -= d
length -= 1
ans += baseS + diffS
print(ans)
| from heapq import heappush, heappop
T = int(eval(input()))
def process(arr):
arr.sort()
baseS = 0
diffS = 0
q = []
length = 0
for K, L, R in arr:
baseS += R
diff = L - R
heappush(q, diff)
diffS += diff
length += 1
while length > K:
d = heappop(q)
diffS -= d
length -= 1
return baseS + diffS
for _ in range(T):
N = int(eval(input()))
arr1 = []
arr2 = []
for _ in range(N):
K, L, R = list(map(int, input().split()))
if L > R:
arr1.append((K, L, R))
else:
arr2.append((N - K, R, L))
print((process(arr1) + process(arr2)))
| false | 33.333333 | [
"+",
"+",
"+def process(arr):",
"+ arr.sort()",
"+ baseS = 0",
"+ diffS = 0",
"+ q = []",
"+ length = 0",
"+ for K, L, R in arr:",
"+ baseS += R",
"+ diff = L - R",
"+ heappush(q, diff)",
"+ diffS += diff",
"+ length += 1",
"+ while length > K:",
"+ d = heappop(q)",
"+ diffS -= d",
"+ length -= 1",
"+ return baseS + diffS",
"+",
"+",
"- arr1.sort()",
"- baseS = 0",
"- diffS = 0",
"- q = []",
"- length = 0",
"- for K, L, R in arr1:",
"- baseS += R",
"- diff = L - R",
"- heappush(q, diff)",
"- diffS += diff",
"- length += 1",
"- while length > K:",
"- d = heappop(q)",
"- diffS -= d",
"- length -= 1",
"- ans = baseS + diffS",
"- arr2.sort()",
"- baseS = 0",
"- diffS = 0",
"- q = []",
"- length = 0",
"- for K, L, R in arr2:",
"- baseS += R",
"- diff = L - R",
"- heappush(q, diff)",
"- diffS += diff",
"- length += 1",
"- while length > K:",
"- d = heappop(q)",
"- diffS -= d",
"- length -= 1",
"- ans += baseS + diffS",
"- print(ans)",
"+ print((process(arr1) + process(arr2)))"
] | false | 0.034382 | 0.032505 | 1.057724 | [
"s109543653",
"s251575173"
] |
u367965715 | p02735 | python | s210195932 | s458589664 | 207 | 189 | 12,500 | 12,752 | Accepted | Accepted | 8.7 | import numpy as np
h, w = list(map(int, input().split()))
grid = np.array(['*'*(w+2)] + ['*'+eval(input())+'*' for _ in range(h)] + ['*'*(w+2)])
cnt = np.full((h+3, w+3), h+w, dtype=np.int)
MAX = h + w
for i in range(1, h+2):
for k in range(1, w+2):
if i == k == 1:
cnt[i+1][k+1] = 1 if grid[i][k] == '#' else 0
else:
if grid[i][k] == '#':
if grid[i-1][k] == '#':
a = cnt[i][k+1]
elif grid[i-1][k] == '.':
a = cnt[i][k+1] + 1
else:
a = MAX
if grid[i][k-1] == '#':
b = cnt[i+1][k]
elif grid[i][k-1] == '.':
b = cnt[i+1][k] + 1
else:
b = MAX
cnt[i+1][k+1] = min(a, b)
else:
cnt[i+1][k+1] = min(cnt[i][k+1], cnt[i+1][k])
print((cnt[h+1][w+1]))
| import numpy as np
h, w = list(map(int, input().split()))
grid = np.array([list(eval(input())) for _ in range(h)])
dp = np.full((h+1, w+1), h+w, dtype=np.int)
for i in range(h):
for k in range(w):
if i == k == 0:
dp[i+1, k+1] = 1 if grid[i, k] == '#' else 0
else:
if grid[i, k] == '#':
a = dp[i, k+1] if grid[i-1, k] == '#' else dp[i, k+1] + 1
b = dp[i+1, k] if grid[i, k-1] == '#' else dp[i+1, k] + 1
dp[i+1, k+1] = min(a, b)
else:
dp[i+1, k+1] = min(dp[i, k+1], dp[i+1, k])
print((dp[h, w]))
| 30 | 20 | 963 | 623 | import numpy as np
h, w = list(map(int, input().split()))
grid = np.array(
["*" * (w + 2)] + ["*" + eval(input()) + "*" for _ in range(h)] + ["*" * (w + 2)]
)
cnt = np.full((h + 3, w + 3), h + w, dtype=np.int)
MAX = h + w
for i in range(1, h + 2):
for k in range(1, w + 2):
if i == k == 1:
cnt[i + 1][k + 1] = 1 if grid[i][k] == "#" else 0
else:
if grid[i][k] == "#":
if grid[i - 1][k] == "#":
a = cnt[i][k + 1]
elif grid[i - 1][k] == ".":
a = cnt[i][k + 1] + 1
else:
a = MAX
if grid[i][k - 1] == "#":
b = cnt[i + 1][k]
elif grid[i][k - 1] == ".":
b = cnt[i + 1][k] + 1
else:
b = MAX
cnt[i + 1][k + 1] = min(a, b)
else:
cnt[i + 1][k + 1] = min(cnt[i][k + 1], cnt[i + 1][k])
print((cnt[h + 1][w + 1]))
| import numpy as np
h, w = list(map(int, input().split()))
grid = np.array([list(eval(input())) for _ in range(h)])
dp = np.full((h + 1, w + 1), h + w, dtype=np.int)
for i in range(h):
for k in range(w):
if i == k == 0:
dp[i + 1, k + 1] = 1 if grid[i, k] == "#" else 0
else:
if grid[i, k] == "#":
a = dp[i, k + 1] if grid[i - 1, k] == "#" else dp[i, k + 1] + 1
b = dp[i + 1, k] if grid[i, k - 1] == "#" else dp[i + 1, k] + 1
dp[i + 1, k + 1] = min(a, b)
else:
dp[i + 1, k + 1] = min(dp[i, k + 1], dp[i + 1, k])
print((dp[h, w]))
| false | 33.333333 | [
"-grid = np.array(",
"- [\"*\" * (w + 2)] + [\"*\" + eval(input()) + \"*\" for _ in range(h)] + [\"*\" * (w + 2)]",
"-)",
"-cnt = np.full((h + 3, w + 3), h + w, dtype=np.int)",
"-MAX = h + w",
"-for i in range(1, h + 2):",
"- for k in range(1, w + 2):",
"- if i == k == 1:",
"- cnt[i + 1][k + 1] = 1 if grid[i][k] == \"#\" else 0",
"+grid = np.array([list(eval(input())) for _ in range(h)])",
"+dp = np.full((h + 1, w + 1), h + w, dtype=np.int)",
"+for i in range(h):",
"+ for k in range(w):",
"+ if i == k == 0:",
"+ dp[i + 1, k + 1] = 1 if grid[i, k] == \"#\" else 0",
"- if grid[i][k] == \"#\":",
"- if grid[i - 1][k] == \"#\":",
"- a = cnt[i][k + 1]",
"- elif grid[i - 1][k] == \".\":",
"- a = cnt[i][k + 1] + 1",
"- else:",
"- a = MAX",
"- if grid[i][k - 1] == \"#\":",
"- b = cnt[i + 1][k]",
"- elif grid[i][k - 1] == \".\":",
"- b = cnt[i + 1][k] + 1",
"- else:",
"- b = MAX",
"- cnt[i + 1][k + 1] = min(a, b)",
"+ if grid[i, k] == \"#\":",
"+ a = dp[i, k + 1] if grid[i - 1, k] == \"#\" else dp[i, k + 1] + 1",
"+ b = dp[i + 1, k] if grid[i, k - 1] == \"#\" else dp[i + 1, k] + 1",
"+ dp[i + 1, k + 1] = min(a, b)",
"- cnt[i + 1][k + 1] = min(cnt[i][k + 1], cnt[i + 1][k])",
"-print((cnt[h + 1][w + 1]))",
"+ dp[i + 1, k + 1] = min(dp[i, k + 1], dp[i + 1, k])",
"+print((dp[h, w]))"
] | false | 0.186813 | 0.191469 | 0.975682 | [
"s210195932",
"s458589664"
] |
u511824539 | p02803 | python | s197976342 | s877663273 | 458 | 282 | 3,316 | 3,316 | Accepted | Accepted | 38.43 | from collections import deque
def shortestpath(y0, x0):
step_cnt = [[-1] * w for _ in range(h)]
step_cnt[y0-1][x0-1] = 0
q.append((y0, x0))
while q:
y, x = q.popleft()
for i in range(4):
y_next = y + dy[i]
x_next = x + dx[i]
if 1 <= y_next < h+1 and 1 <= x_next < w+1\
and maze[y_next][x_next] == '.'\
and step_cnt[y_next-1][x_next-1] == -1:
q.append((y_next, x_next))
step_cnt[y_next-1][x_next-1] = step_cnt[y-1][x-1] + 1
return step_cnt[y-1][x-1]
h, w = map(int, input().split())
maze = [['#'] * (w+2)]
maze += [['#']+[x for x in input()]+['#'] for _ in range(h)]
maze += [['#'] * (w+2)]
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]
q = deque()
max_steps = -1
for y0 in range(1, h+1):
for x0 in range(1, w+1):
if maze[y0][x0] != '#':
max_steps = max(max_steps, shortestpath(y0, x0))
print(max_steps)
| from collections import deque
def shortestpath(y0, x0):
step_cnt = [[-1] * (w+2) for _ in range(h+2)]
step_cnt[y0][x0] = 0
q.append((y0, x0))
while q:
y, x = q.popleft()
for i in range(4):
y_next = y + dy[i]
x_next = x + dx[i]
if maze[y_next][x_next] == '.'\
and step_cnt[y_next][x_next] == -1:
q.append((y_next, x_next))
step_cnt[y_next][x_next] = step_cnt[y][x] + 1
return step_cnt[y][x]
h, w = map(int, input().split())
maze = [['#'] * (w+2)]
maze += [['#']+[x for x in input()]+['#'] for _ in range(h)]
maze += [['#'] * (w+2)]
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]
q = deque()
max_steps = -1
for y0 in range(1, h+1):
for x0 in range(1, w+1):
if maze[y0][x0] != '#':
max_steps = max(max_steps, shortestpath(y0, x0))
print(max_steps)
| 34 | 34 | 984 | 918 | from collections import deque
def shortestpath(y0, x0):
step_cnt = [[-1] * w for _ in range(h)]
step_cnt[y0 - 1][x0 - 1] = 0
q.append((y0, x0))
while q:
y, x = q.popleft()
for i in range(4):
y_next = y + dy[i]
x_next = x + dx[i]
if (
1 <= y_next < h + 1
and 1 <= x_next < w + 1
and maze[y_next][x_next] == "."
and step_cnt[y_next - 1][x_next - 1] == -1
):
q.append((y_next, x_next))
step_cnt[y_next - 1][x_next - 1] = step_cnt[y - 1][x - 1] + 1
return step_cnt[y - 1][x - 1]
h, w = map(int, input().split())
maze = [["#"] * (w + 2)]
maze += [["#"] + [x for x in input()] + ["#"] for _ in range(h)]
maze += [["#"] * (w + 2)]
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]
q = deque()
max_steps = -1
for y0 in range(1, h + 1):
for x0 in range(1, w + 1):
if maze[y0][x0] != "#":
max_steps = max(max_steps, shortestpath(y0, x0))
print(max_steps)
| from collections import deque
def shortestpath(y0, x0):
step_cnt = [[-1] * (w + 2) for _ in range(h + 2)]
step_cnt[y0][x0] = 0
q.append((y0, x0))
while q:
y, x = q.popleft()
for i in range(4):
y_next = y + dy[i]
x_next = x + dx[i]
if maze[y_next][x_next] == "." and step_cnt[y_next][x_next] == -1:
q.append((y_next, x_next))
step_cnt[y_next][x_next] = step_cnt[y][x] + 1
return step_cnt[y][x]
h, w = map(int, input().split())
maze = [["#"] * (w + 2)]
maze += [["#"] + [x for x in input()] + ["#"] for _ in range(h)]
maze += [["#"] * (w + 2)]
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]
q = deque()
max_steps = -1
for y0 in range(1, h + 1):
for x0 in range(1, w + 1):
if maze[y0][x0] != "#":
max_steps = max(max_steps, shortestpath(y0, x0))
print(max_steps)
| false | 0 | [
"- step_cnt = [[-1] * w for _ in range(h)]",
"- step_cnt[y0 - 1][x0 - 1] = 0",
"+ step_cnt = [[-1] * (w + 2) for _ in range(h + 2)]",
"+ step_cnt[y0][x0] = 0",
"- if (",
"- 1 <= y_next < h + 1",
"- and 1 <= x_next < w + 1",
"- and maze[y_next][x_next] == \".\"",
"- and step_cnt[y_next - 1][x_next - 1] == -1",
"- ):",
"+ if maze[y_next][x_next] == \".\" and step_cnt[y_next][x_next] == -1:",
"- step_cnt[y_next - 1][x_next - 1] = step_cnt[y - 1][x - 1] + 1",
"- return step_cnt[y - 1][x - 1]",
"+ step_cnt[y_next][x_next] = step_cnt[y][x] + 1",
"+ return step_cnt[y][x]"
] | false | 0.184471 | 0.206926 | 0.891484 | [
"s197976342",
"s877663273"
] |
u070561949 | p03215 | python | s118246419 | s819757878 | 936 | 671 | 29,152 | 28,700 | Accepted | Accepted | 28.31 | n,k=list(map(int,input().split()))
d=list(map(int,input().split()))
ds = []
for i in range(0,n):
sum = 0
for j in range(i,n):
sum += d[j]
ds.append(sum)
ds.sort(reverse=True)
for i in range(40,-1,-1):
count = 0
o = []
for dss in ds:
if dss & (1 << i) > 0 :
count += 1
o.append(dss)
if count >= k :
ds = list(o)
sum = ds[0]
for i in range(1,k):
sum = sum & ds[i]
print(sum) | line = str(eval(input()))
lines = line.split(' ')
n = int(lines[0])
k = int(lines[1])
d = list()
line = str(eval(input()))
lines = line.split(' ')
for l in lines:
d.append(int(l))
ds = list()
for i in range(0,n):
sum = 0
for j in range(i,n):
sum += d[j]
ds.append(sum)
for i in range(40,-1,-1):
count = 0
o = []
for dss in ds:
if dss & (1 << i) > 0 :
count += 1
o.append(dss)
if count >= k :
ds = list(o)
sum = ds[0]
for i in range(1,k):
sum = sum & ds[i]
print(sum) | 29 | 39 | 491 | 602 | n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
ds = []
for i in range(0, n):
sum = 0
for j in range(i, n):
sum += d[j]
ds.append(sum)
ds.sort(reverse=True)
for i in range(40, -1, -1):
count = 0
o = []
for dss in ds:
if dss & (1 << i) > 0:
count += 1
o.append(dss)
if count >= k:
ds = list(o)
sum = ds[0]
for i in range(1, k):
sum = sum & ds[i]
print(sum)
| line = str(eval(input()))
lines = line.split(" ")
n = int(lines[0])
k = int(lines[1])
d = list()
line = str(eval(input()))
lines = line.split(" ")
for l in lines:
d.append(int(l))
ds = list()
for i in range(0, n):
sum = 0
for j in range(i, n):
sum += d[j]
ds.append(sum)
for i in range(40, -1, -1):
count = 0
o = []
for dss in ds:
if dss & (1 << i) > 0:
count += 1
o.append(dss)
if count >= k:
ds = list(o)
sum = ds[0]
for i in range(1, k):
sum = sum & ds[i]
print(sum)
| false | 25.641026 | [
"-n, k = list(map(int, input().split()))",
"-d = list(map(int, input().split()))",
"-ds = []",
"+line = str(eval(input()))",
"+lines = line.split(\" \")",
"+n = int(lines[0])",
"+k = int(lines[1])",
"+d = list()",
"+line = str(eval(input()))",
"+lines = line.split(\" \")",
"+for l in lines:",
"+ d.append(int(l))",
"+ds = list()",
"-ds.sort(reverse=True)"
] | false | 0.060976 | 0.060148 | 1.013757 | [
"s118246419",
"s819757878"
] |
u644907318 | p03361 | python | s703721415 | s303918849 | 170 | 66 | 38,768 | 65,220 | Accepted | Accepted | 61.18 | H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
flag = 0
for i in range(H):
for j in range(W):
if S[i][j]=="#":
if j+1<W and S[i][j+1]=="." and i-1>=0 and S[i-1][j]=="." and j-1>=0 and S[i][j-1]=="." \
and i+1<H and S[i+1][j]==".":
flag = 1
break
if flag==1:break
if flag==0:
print("Yes")
else:
print("No")
| H,W = list(map(int,input().split()))
S = [input().strip() for _ in range(H)]
for i in range(H):
S[i] = "."+S[i]+"."
S.insert(0,"."*(W+2))
S.append("."*(W+2))
flag = 0
for i in range(1,H+1):
for j in range(1,W+1):
if S[i][j]=="#" and S[i][j+1]=="." and S[i-1][j]=="." and S[i][j-1]=="." and S[i+1][j]==".":
flag = 1
break
if flag==1:break
if flag==0:
print("Yes")
else:
print("No") | 15 | 17 | 423 | 442 | H, W = map(int, input().split())
S = [input().strip() for _ in range(H)]
flag = 0
for i in range(H):
for j in range(W):
if S[i][j] == "#":
if (
j + 1 < W
and S[i][j + 1] == "."
and i - 1 >= 0
and S[i - 1][j] == "."
and j - 1 >= 0
and S[i][j - 1] == "."
and i + 1 < H
and S[i + 1][j] == "."
):
flag = 1
break
if flag == 1:
break
if flag == 0:
print("Yes")
else:
print("No")
| H, W = list(map(int, input().split()))
S = [input().strip() for _ in range(H)]
for i in range(H):
S[i] = "." + S[i] + "."
S.insert(0, "." * (W + 2))
S.append("." * (W + 2))
flag = 0
for i in range(1, H + 1):
for j in range(1, W + 1):
if (
S[i][j] == "#"
and S[i][j + 1] == "."
and S[i - 1][j] == "."
and S[i][j - 1] == "."
and S[i + 1][j] == "."
):
flag = 1
break
if flag == 1:
break
if flag == 0:
print("Yes")
else:
print("No")
| false | 11.764706 | [
"-H, W = map(int, input().split())",
"+H, W = list(map(int, input().split()))",
"+for i in range(H):",
"+ S[i] = \".\" + S[i] + \".\"",
"+S.insert(0, \".\" * (W + 2))",
"+S.append(\".\" * (W + 2))",
"-for i in range(H):",
"- for j in range(W):",
"- if S[i][j] == \"#\":",
"- if (",
"- j + 1 < W",
"- and S[i][j + 1] == \".\"",
"- and i - 1 >= 0",
"- and S[i - 1][j] == \".\"",
"- and j - 1 >= 0",
"- and S[i][j - 1] == \".\"",
"- and i + 1 < H",
"- and S[i + 1][j] == \".\"",
"- ):",
"- flag = 1",
"- break",
"+for i in range(1, H + 1):",
"+ for j in range(1, W + 1):",
"+ if (",
"+ S[i][j] == \"#\"",
"+ and S[i][j + 1] == \".\"",
"+ and S[i - 1][j] == \".\"",
"+ and S[i][j - 1] == \".\"",
"+ and S[i + 1][j] == \".\"",
"+ ):",
"+ flag = 1",
"+ break"
] | false | 0.035565 | 0.069136 | 0.514416 | [
"s703721415",
"s303918849"
] |
u222841610 | p03543 | python | s063099416 | s840677089 | 20 | 17 | 3,060 | 2,940 | Accepted | Accepted | 15 | a = list(map(int,list(eval(input()))))
count = 1
check = False
for i in range(len(a)-1):
if a[i] == a[i+1]:
count += 1
if count==3:
check = True
else:
count = 1
print(('Yes' if check==True else 'No')) | a = list(map(int,list(eval(input()))))
check = False
if a[0] == a[1] == a[2] or a[1]==a[2]==a[3]:
check = True
print(('Yes' if check==True else 'No')) | 11 | 6 | 247 | 153 | a = list(map(int, list(eval(input()))))
count = 1
check = False
for i in range(len(a) - 1):
if a[i] == a[i + 1]:
count += 1
if count == 3:
check = True
else:
count = 1
print(("Yes" if check == True else "No"))
| a = list(map(int, list(eval(input()))))
check = False
if a[0] == a[1] == a[2] or a[1] == a[2] == a[3]:
check = True
print(("Yes" if check == True else "No"))
| false | 45.454545 | [
"-count = 1",
"-for i in range(len(a) - 1):",
"- if a[i] == a[i + 1]:",
"- count += 1",
"- if count == 3:",
"- check = True",
"- else:",
"- count = 1",
"+if a[0] == a[1] == a[2] or a[1] == a[2] == a[3]:",
"+ check = True"
] | false | 0.066477 | 0.035754 | 1.859316 | [
"s063099416",
"s840677089"
] |
u717626627 | p02933 | python | s395857362 | s608423030 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | a = int(eval(input()))
s = str(eval(input()))
if a >= 3200:
print(s)
else:
print('red') | a = int(eval(input()))
s = eval(input())
if a < 3200:
print('red')
else:
print(s) | 7 | 7 | 86 | 80 | a = int(eval(input()))
s = str(eval(input()))
if a >= 3200:
print(s)
else:
print("red")
| a = int(eval(input()))
s = eval(input())
if a < 3200:
print("red")
else:
print(s)
| false | 0 | [
"-s = str(eval(input()))",
"-if a >= 3200:",
"+s = eval(input())",
"+if a < 3200:",
"+ print(\"red\")",
"+else:",
"-else:",
"- print(\"red\")"
] | false | 0.044741 | 0.038925 | 1.14941 | [
"s395857362",
"s608423030"
] |
u022979415 | p02881 | python | s548688012 | s780750030 | 391 | 185 | 2,940 | 3,272 | Accepted | Accepted | 52.69 | def main():
N = int(eval(input()))
i = 2
ans = N + 1
while i ** 2 <= N:
if N % i == 0:
ans = min(i + N / i, ans)
i += 1
print((int(ans - 2)))
if __name__ == '__main__':
main() | def main():
n = int(eval(input()))
f = []
i = 2
while i * i <= n:
if n % i == 0:
f.append(i)
if i * i != n:
f.append(n // i)
i += 1
if n != 1:
f.append(n)
f.sort()
answer = float("inf")
for ff in f:
answer = min(answer, ff + n // ff - 2)
print(answer)
if __name__ == '__main__':
main()
| 13 | 22 | 233 | 416 | def main():
N = int(eval(input()))
i = 2
ans = N + 1
while i**2 <= N:
if N % i == 0:
ans = min(i + N / i, ans)
i += 1
print((int(ans - 2)))
if __name__ == "__main__":
main()
| def main():
n = int(eval(input()))
f = []
i = 2
while i * i <= n:
if n % i == 0:
f.append(i)
if i * i != n:
f.append(n // i)
i += 1
if n != 1:
f.append(n)
f.sort()
answer = float("inf")
for ff in f:
answer = min(answer, ff + n // ff - 2)
print(answer)
if __name__ == "__main__":
main()
| false | 40.909091 | [
"- N = int(eval(input()))",
"+ n = int(eval(input()))",
"+ f = []",
"- ans = N + 1",
"- while i**2 <= N:",
"- if N % i == 0:",
"- ans = min(i + N / i, ans)",
"+ while i * i <= n:",
"+ if n % i == 0:",
"+ f.append(i)",
"+ if i * i != n:",
"+ f.append(n // i)",
"- print((int(ans - 2)))",
"+ if n != 1:",
"+ f.append(n)",
"+ f.sort()",
"+ answer = float(\"inf\")",
"+ for ff in f:",
"+ answer = min(answer, ff + n // ff - 2)",
"+ print(answer)"
] | false | 0.055469 | 0.044425 | 1.248607 | [
"s548688012",
"s780750030"
] |
u463655976 | p03107 | python | s675600836 | s516433063 | 109 | 54 | 3,188 | 3,188 | Accepted | Accepted | 50.46 | s = 0
p = 0
for c in eval(input()):
n = int(c) * 2 - 1
p += max(abs(s) - abs(s+n), 0) * 2
s += n
print(p) | s = 0
S = eval(input())
for c in S:
n = int(c) * 2 - 1
s += n
print((len(S) - abs(s)))
| 7 | 6 | 111 | 88 | s = 0
p = 0
for c in eval(input()):
n = int(c) * 2 - 1
p += max(abs(s) - abs(s + n), 0) * 2
s += n
print(p)
| s = 0
S = eval(input())
for c in S:
n = int(c) * 2 - 1
s += n
print((len(S) - abs(s)))
| false | 14.285714 | [
"-p = 0",
"-for c in eval(input()):",
"+S = eval(input())",
"+for c in S:",
"- p += max(abs(s) - abs(s + n), 0) * 2",
"-print(p)",
"+print((len(S) - abs(s)))"
] | false | 0.082253 | 0.045229 | 1.818595 | [
"s675600836",
"s516433063"
] |
u416758623 | p03469 | python | s957062362 | s207437767 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | n = eval(input())
print((n.replace("2017","2018",1))) | s = eval(input())
print((s.replace("7","8",1))) | 2 | 2 | 46 | 40 | n = eval(input())
print((n.replace("2017", "2018", 1)))
| s = eval(input())
print((s.replace("7", "8", 1)))
| false | 0 | [
"-n = eval(input())",
"-print((n.replace(\"2017\", \"2018\", 1)))",
"+s = eval(input())",
"+print((s.replace(\"7\", \"8\", 1)))"
] | false | 0.043938 | 0.068615 | 0.640356 | [
"s957062362",
"s207437767"
] |
u560867850 | p03274 | python | s968044826 | s835442399 | 74 | 63 | 14,596 | 14,172 | Accepted | Accepted | 14.86 | import sys
input = sys.stdin.readline
def main():
N, K = list(map(int, input().split()))
X = [int(c) for c in input().split()]
def fullsearch():
for i in range(N-K+1):
l = X[i]
r = X[i+K-1]
distance = abs(r - l)
yield min(distance + abs(r), distance + abs(l))
print((min(fullsearch())))
main() | import sys
input = sys.stdin.readline
def main():
_, K = list(map(int, input().split()))
X = [int(c) for c in input().split()]
def fullsearch():
for l, r in zip(X, X[K-1:]):
distance = abs(r - l)
yield distance + abs(r)
yield distance + abs(l)
print((min(fullsearch())))
main() | 18 | 17 | 379 | 350 | import sys
input = sys.stdin.readline
def main():
N, K = list(map(int, input().split()))
X = [int(c) for c in input().split()]
def fullsearch():
for i in range(N - K + 1):
l = X[i]
r = X[i + K - 1]
distance = abs(r - l)
yield min(distance + abs(r), distance + abs(l))
print((min(fullsearch())))
main()
| import sys
input = sys.stdin.readline
def main():
_, K = list(map(int, input().split()))
X = [int(c) for c in input().split()]
def fullsearch():
for l, r in zip(X, X[K - 1 :]):
distance = abs(r - l)
yield distance + abs(r)
yield distance + abs(l)
print((min(fullsearch())))
main()
| false | 5.555556 | [
"- N, K = list(map(int, input().split()))",
"+ _, K = list(map(int, input().split()))",
"- for i in range(N - K + 1):",
"- l = X[i]",
"- r = X[i + K - 1]",
"+ for l, r in zip(X, X[K - 1 :]):",
"- yield min(distance + abs(r), distance + abs(l))",
"+ yield distance + abs(r)",
"+ yield distance + abs(l)"
] | false | 0.095358 | 0.041019 | 2.324698 | [
"s968044826",
"s835442399"
] |
u282228874 | p03573 | python | s260598187 | s449736745 | 24 | 17 | 3,316 | 2,940 | Accepted | Accepted | 29.17 | a,b,c = list(map(int,input().split()))
print((a^b^c)) | a,b,c = list(map(int,input().split()))
if a==b:
print(c)
elif a == c:
print(b)
else:
print(a) | 2 | 7 | 46 | 105 | a, b, c = list(map(int, input().split()))
print((a ^ b ^ c))
| a, b, c = list(map(int, input().split()))
if a == b:
print(c)
elif a == c:
print(b)
else:
print(a)
| false | 71.428571 | [
"-print((a ^ b ^ c))",
"+if a == b:",
"+ print(c)",
"+elif a == c:",
"+ print(b)",
"+else:",
"+ print(a)"
] | false | 0.037077 | 0.079833 | 0.464428 | [
"s260598187",
"s449736745"
] |
u195912432 | p03194 | python | s220370688 | s791427742 | 203 | 78 | 3,064 | 3,064 | Accepted | Accepted | 61.58 | # -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))
import math
N, P = list(map(int, input().split()))
ans = 1
target = 2
sum = {}
while True:
if P % target == 0:
if target in sum:
sum[target] += 1
else:
sum[target] = 1
P /= target
target = 2
else:
target += 1
if math.sqrt(P) < target:
P = int(P)
if P in sum:
sum[P] += 1
else:
sum[P] = 1
break
for fact in sum:
# print("{} {}".format(fact, sum[fact]))
while sum[fact] >= N:
sum[fact] -= N
ans *= fact
print(("{}".format(ans)))
| # -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))
import math
N, P = list(map(int, input().split()))
ans = 1
target = 2
sum = {}
if N == 1:
ans = P
else:
while True:
if P % target == 0:
if target in sum:
sum[target] += 1
else:
sum[target] = 1
P /= target
target = 2
else:
target += 1
if math.sqrt(P) < target:
P = int(P)
if P in sum:
sum[P] += 1
else:
sum[P] = 1
break
for fact in sum:
# print("{} {}".format(fact, sum[fact]))
while sum[fact] >= N:
sum[fact] -= N
ans *= fact
print(("{}".format(ans)))
| 42 | 44 | 781 | 833 | # -*- coding: utf-8 -*-
# 整数の入力
# a = int(input())
# スペース区切りの整数の入力
# b, c = map(int, input().split())
# 文字列の入力
# s = input()
# 出力
# print("{} {}".format(a+b+c, s))
import math
N, P = list(map(int, input().split()))
ans = 1
target = 2
sum = {}
while True:
if P % target == 0:
if target in sum:
sum[target] += 1
else:
sum[target] = 1
P /= target
target = 2
else:
target += 1
if math.sqrt(P) < target:
P = int(P)
if P in sum:
sum[P] += 1
else:
sum[P] = 1
break
for fact in sum:
# print("{} {}".format(fact, sum[fact]))
while sum[fact] >= N:
sum[fact] -= N
ans *= fact
print(("{}".format(ans)))
| # -*- coding: utf-8 -*-
# 整数の入力
# a = int(input())
# スペース区切りの整数の入力
# b, c = map(int, input().split())
# 文字列の入力
# s = input()
# 出力
# print("{} {}".format(a+b+c, s))
import math
N, P = list(map(int, input().split()))
ans = 1
target = 2
sum = {}
if N == 1:
ans = P
else:
while True:
if P % target == 0:
if target in sum:
sum[target] += 1
else:
sum[target] = 1
P /= target
target = 2
else:
target += 1
if math.sqrt(P) < target:
P = int(P)
if P in sum:
sum[P] += 1
else:
sum[P] = 1
break
for fact in sum:
# print("{} {}".format(fact, sum[fact]))
while sum[fact] >= N:
sum[fact] -= N
ans *= fact
print(("{}".format(ans)))
| false | 4.545455 | [
"-while True:",
"- if P % target == 0:",
"- if target in sum:",
"- sum[target] += 1",
"+if N == 1:",
"+ ans = P",
"+else:",
"+ while True:",
"+ if P % target == 0:",
"+ if target in sum:",
"+ sum[target] += 1",
"+ else:",
"+ sum[target] = 1",
"+ P /= target",
"+ target = 2",
"- sum[target] = 1",
"- P /= target",
"- target = 2",
"- else:",
"- target += 1",
"- if math.sqrt(P) < target:",
"- P = int(P)",
"- if P in sum:",
"- sum[P] += 1",
"- else:",
"- sum[P] = 1",
"- break",
"-for fact in sum:",
"- # print(\"{} {}\".format(fact, sum[fact]))",
"- while sum[fact] >= N:",
"- sum[fact] -= N",
"- ans *= fact",
"+ target += 1",
"+ if math.sqrt(P) < target:",
"+ P = int(P)",
"+ if P in sum:",
"+ sum[P] += 1",
"+ else:",
"+ sum[P] = 1",
"+ break",
"+ for fact in sum:",
"+ # print(\"{} {}\".format(fact, sum[fact]))",
"+ while sum[fact] >= N:",
"+ sum[fact] -= N",
"+ ans *= fact"
] | false | 0.043737 | 0.036261 | 1.206187 | [
"s220370688",
"s791427742"
] |
u065446124 | p03682 | python | s360328315 | s050379247 | 1,644 | 1,283 | 132,052 | 50,448 | Accepted | Accepted | 21.96 | class unionfind:
def __init__(self, n):
self.n = n
self.root = [-1]*(n+1)
self.rnk = [0]*(n+1)
def find(self, x):
if(self.root[x] < 0):
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if(x == y):
return
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
if(self.rnk[x] == self.rnk[y]):
self.rnk[y] += 1
def same(self, x, y):
return self.find(x) == self.find(y)
def count(self, x):
return -self.root[self.find(x)]
import sys
input=sys.stdin.readline
n=int(eval(input()))
l=[tuple(map(int,input().split())) for i in range(n)]
l.sort()
import collections
d=collections.defaultdict(int)
j=1
for i in l:
if d[i]==0:
d[i]=j
j+=1
pq=[]
for i in range(n-1):
pq.append((l[i+1][0]-l[i][0],d[l[i]],d[l[i+1]]))
l.sort(key=lambda x:x[1])
for i in range(n-1):
pq.append((l[i+1][1]-l[i][1],d[l[i]],d[l[i+1]]))
ans=0
pq.sort(key=lambda x:x[0])
uf=unionfind(n)
for c,x,y in pq:
if not uf.same(x,y):
ans+=c
uf.unite(x,y)
print(ans) | class unionfind:
def __init__(self, n):
self.n = n
self.root = [-1]*(n+1)
self.rnk = [0]*(n+1)
def find(self, x):
if(self.root[x] < 0):
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if(x == y):
return
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
if(self.rnk[x] == self.rnk[y]):
self.rnk[y] += 1
def same(self, x, y):
return self.find(x) == self.find(y)
def count(self, x):
return -self.root[self.find(x)]
import sys
input=sys.stdin.readline
n=int(eval(input()))
l=[tuple(map(int,input().split())) for i in range(n)]
l.sort()
import collections
d=collections.defaultdict(int)
j=1
for i in l:
if d[i]==0:
d[i]=j
j+=1
pq=[]
for i in range(n-1):
pq.append((l[i+1][0]-l[i][0],d[l[i]],d[l[i+1]]))
l.sort(key=lambda x:x[1])
for i in range(n-1):
pq.append((l[i+1][1]-l[i][1],d[l[i]],d[l[i+1]]))
ans=0
pq.sort()
uf=unionfind(n)
for c,x,y in pq:
if not uf.same(x,y):
ans+=c
uf.unite(x,y)
print(ans) | 54 | 54 | 1,412 | 1,395 | class unionfind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def find(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
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
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def same(self, x, y):
return self.find(x) == self.find(y)
def count(self, x):
return -self.root[self.find(x)]
import sys
input = sys.stdin.readline
n = int(eval(input()))
l = [tuple(map(int, input().split())) for i in range(n)]
l.sort()
import collections
d = collections.defaultdict(int)
j = 1
for i in l:
if d[i] == 0:
d[i] = j
j += 1
pq = []
for i in range(n - 1):
pq.append((l[i + 1][0] - l[i][0], d[l[i]], d[l[i + 1]]))
l.sort(key=lambda x: x[1])
for i in range(n - 1):
pq.append((l[i + 1][1] - l[i][1], d[l[i]], d[l[i + 1]]))
ans = 0
pq.sort(key=lambda x: x[0])
uf = unionfind(n)
for c, x, y in pq:
if not uf.same(x, y):
ans += c
uf.unite(x, y)
print(ans)
| class unionfind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def find(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
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
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def same(self, x, y):
return self.find(x) == self.find(y)
def count(self, x):
return -self.root[self.find(x)]
import sys
input = sys.stdin.readline
n = int(eval(input()))
l = [tuple(map(int, input().split())) for i in range(n)]
l.sort()
import collections
d = collections.defaultdict(int)
j = 1
for i in l:
if d[i] == 0:
d[i] = j
j += 1
pq = []
for i in range(n - 1):
pq.append((l[i + 1][0] - l[i][0], d[l[i]], d[l[i + 1]]))
l.sort(key=lambda x: x[1])
for i in range(n - 1):
pq.append((l[i + 1][1] - l[i][1], d[l[i]], d[l[i + 1]]))
ans = 0
pq.sort()
uf = unionfind(n)
for c, x, y in pq:
if not uf.same(x, y):
ans += c
uf.unite(x, y)
print(ans)
| false | 0 | [
"-pq.sort(key=lambda x: x[0])",
"+pq.sort()"
] | false | 0.085985 | 0.07731 | 1.1122 | [
"s360328315",
"s050379247"
] |
u564589929 | p02935 | python | s017268420 | s215910821 | 22 | 20 | 3,316 | 3,316 | Accepted | Accepted | 9.09 | # import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
from collections import deque
def solve():
n = II()
V = LI()
V = deque(sorted(V))
vi = V.popleft()
while 1:
vj = V.popleft()
avg = (vi + vj) / 2
V.append(avg)
V = deque(sorted(V))
vi = V.popleft()
if len(V) == 0:
break
print(vi)
if __name__ == '__main__':
solve()
| # import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
from collections import deque
def solve():
n = II()
V = sorted(LI())
ans = V[0]
for i in range(1, n):
ans = (ans + V[i]) / 2
print(ans)
if __name__ == '__main__':
solve()
| 33 | 23 | 697 | 535 | # import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
from collections import deque
def solve():
n = II()
V = LI()
V = deque(sorted(V))
vi = V.popleft()
while 1:
vj = V.popleft()
avg = (vi + vj) / 2
V.append(avg)
V = deque(sorted(V))
vi = V.popleft()
if len(V) == 0:
break
print(vi)
if __name__ == "__main__":
solve()
| # import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
from collections import deque
def solve():
n = II()
V = sorted(LI())
ans = V[0]
for i in range(1, n):
ans = (ans + V[i]) / 2
print(ans)
if __name__ == "__main__":
solve()
| false | 30.30303 | [
"- V = LI()",
"- V = deque(sorted(V))",
"- vi = V.popleft()",
"- while 1:",
"- vj = V.popleft()",
"- avg = (vi + vj) / 2",
"- V.append(avg)",
"- V = deque(sorted(V))",
"- vi = V.popleft()",
"- if len(V) == 0:",
"- break",
"- print(vi)",
"+ V = sorted(LI())",
"+ ans = V[0]",
"+ for i in range(1, n):",
"+ ans = (ans + V[i]) / 2",
"+ print(ans)"
] | false | 0.042675 | 0.081705 | 0.522308 | [
"s017268420",
"s215910821"
] |
u459798349 | p03043 | python | s521999902 | s159671159 | 125 | 51 | 3,188 | 8,980 | Accepted | Accepted | 59.2 | n, k = list(map(int, input().split()))
import math
def get_p(nums,k):
p=1/(2**math.ceil(max(math.log(k/nums,2),0)))
return p
ans=0
for nums in range(n):
ans+=get_p(nums+1,k)
print(("{0:.20f}".format(ans/n))) | import math
n,k=list(map(int,input().split()))
ans=0
for i in range(1,n+1):
cnt=0
now=i
while now<k:
now*=2
cnt+=1
ans+=1/pow(2,cnt)
print((ans/n))
| 12 | 14 | 229 | 195 | n, k = list(map(int, input().split()))
import math
def get_p(nums, k):
p = 1 / (2 ** math.ceil(max(math.log(k / nums, 2), 0)))
return p
ans = 0
for nums in range(n):
ans += get_p(nums + 1, k)
print(("{0:.20f}".format(ans / n)))
| import math
n, k = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
cnt = 0
now = i
while now < k:
now *= 2
cnt += 1
ans += 1 / pow(2, cnt)
print((ans / n))
| false | 14.285714 | [
"-n, k = list(map(int, input().split()))",
"-",
"-def get_p(nums, k):",
"- p = 1 / (2 ** math.ceil(max(math.log(k / nums, 2), 0)))",
"- return p",
"-",
"-",
"+n, k = list(map(int, input().split()))",
"-for nums in range(n):",
"- ans += get_p(nums + 1, k)",
"-print((\"{0:.20f}\".format(ans / n)))",
"+for i in range(1, n + 1):",
"+ cnt = 0",
"+ now = i",
"+ while now < k:",
"+ now *= 2",
"+ cnt += 1",
"+ ans += 1 / pow(2, cnt)",
"+print((ans / n))"
] | false | 0.079267 | 0.05209 | 1.521749 | [
"s521999902",
"s159671159"
] |
u062147869 | p03276 | python | s750887887 | s125097170 | 128 | 104 | 14,224 | 14,252 | Accepted | Accepted | 18.75 | import sys
N,K=list(map(int,input().split()))
X=[int(i) for i in input().split()]
A=[]
B=[]
for x in X:
if x<0:
A.append(x)
else:
B.append(x)
ans=10**18
a=len(A)
b=len(B)
if a==0:
print((B[K-1]))
sys.exit()
if b==0:
print((abs(A[-K])))
sys.exit()
for i in range(max(1,K-b),a+1):
if i>=K:
ans=min(ans,abs(A[-i]))
continue
ans = min(ans,2*abs(A[-i])+B[K-i-1])
for i in range(max(0,K-a-1),b):
if i>=K-1:
ans=min(ans,abs(B[i]))
continue
ans=min(ans,2*abs(B[i])+abs(A[-K+i+1]))
print(ans) | N,K=list(map(int,input().split()))
X=[int(i) for i in input().split()]
ans=10**18
for i in range(N-K+1):
ans=min(ans,abs(X[i])+abs(X[i+K-1]-X[i]))
ans=min(ans,abs(X[i+K-1])+abs(X[i+K-1]-X[i]))
print(ans) | 30 | 7 | 590 | 211 | import sys
N, K = list(map(int, input().split()))
X = [int(i) for i in input().split()]
A = []
B = []
for x in X:
if x < 0:
A.append(x)
else:
B.append(x)
ans = 10**18
a = len(A)
b = len(B)
if a == 0:
print((B[K - 1]))
sys.exit()
if b == 0:
print((abs(A[-K])))
sys.exit()
for i in range(max(1, K - b), a + 1):
if i >= K:
ans = min(ans, abs(A[-i]))
continue
ans = min(ans, 2 * abs(A[-i]) + B[K - i - 1])
for i in range(max(0, K - a - 1), b):
if i >= K - 1:
ans = min(ans, abs(B[i]))
continue
ans = min(ans, 2 * abs(B[i]) + abs(A[-K + i + 1]))
print(ans)
| N, K = list(map(int, input().split()))
X = [int(i) for i in input().split()]
ans = 10**18
for i in range(N - K + 1):
ans = min(ans, abs(X[i]) + abs(X[i + K - 1] - X[i]))
ans = min(ans, abs(X[i + K - 1]) + abs(X[i + K - 1] - X[i]))
print(ans)
| false | 76.666667 | [
"-import sys",
"-",
"-A = []",
"-B = []",
"-for x in X:",
"- if x < 0:",
"- A.append(x)",
"- else:",
"- B.append(x)",
"-a = len(A)",
"-b = len(B)",
"-if a == 0:",
"- print((B[K - 1]))",
"- sys.exit()",
"-if b == 0:",
"- print((abs(A[-K])))",
"- sys.exit()",
"-for i in range(max(1, K - b), a + 1):",
"- if i >= K:",
"- ans = min(ans, abs(A[-i]))",
"- continue",
"- ans = min(ans, 2 * abs(A[-i]) + B[K - i - 1])",
"-for i in range(max(0, K - a - 1), b):",
"- if i >= K - 1:",
"- ans = min(ans, abs(B[i]))",
"- continue",
"- ans = min(ans, 2 * abs(B[i]) + abs(A[-K + i + 1]))",
"+for i in range(N - K + 1):",
"+ ans = min(ans, abs(X[i]) + abs(X[i + K - 1] - X[i]))",
"+ ans = min(ans, abs(X[i + K - 1]) + abs(X[i + K - 1] - X[i]))"
] | false | 0.046671 | 0.046353 | 1.006849 | [
"s750887887",
"s125097170"
] |
u252828980 | p02803 | python | s667049068 | s585509287 | 570 | 305 | 4,716 | 9,488 | Accepted | Accepted | 46.49 | import collections
H,W = list(map(int,input().split()))
if H == W == 1:
print((0))
exit()
if (H == 1 and W == 2) or (H == 2 and W == 1):
print((1))
exit()
LL=[]
for i in range(H):
LL.append(eval(input()))
L = ((1,0),(0,1),(-1,0),(0,-1))
q = collections.deque()
max_L = []
for i in range(H):
for j in range(W):
d = [[0]*W for i in range(H)]
if LL[i][j] ==".":
q.append((i,j))
d[i][j] = 0
max1 = 0
while q:
x,y = q.popleft()
for dx,dy in L:
if 0>x+dx or x+dx>H-1 or 0>y+dy or y+dy>W-1 or d[x+dx][y+dy] !=0:
continue
if LL[x+dx][y+dy] == ".":
d[x+dx][y+dy] = d[x][y] +1
q.append((x+dx,y+dy))
max1 = max(max1,d[x+dx][y+dy])
max_L.append(max1)
#print(q,d ,max1)
print((max(max_L))) | h,w = list(map(int,input().split()))
L = [[]*w for i in range(h)]
for i in range(h):
L[i] = list("#" + eval(input()) + "#")
L = [["#" for i in range(w+2)]] + L + [["#" for i in range(w+2)]]
#print(L)
from collections import deque
ans = 0
q = deque([])
for j in range(1,h+1):
for i in range(1,w+1):
cost = [[-1]*(w+2) for i in range(h+2)]
li = ((1,0),(0,1),(-1,0),(0,-1))
#print(j,i)
if L[j][i] == ".":
cost[j][i] = 0
cost_max = 0
q.append((j,i))
while q:
#print(q)
r,s = q.popleft()
for dh,dw in li:
nh,nw = r+dh,s+dw
#print(L[nh][nw],)
if L[nh][nw] =="." and cost[nh][nw] == -1 :
cost[nh][nw] = cost[r][s] + 1
#print(cost[nh][nw],cost[j][i])
#print(cost)
cost_max = max(cost_max,cost[nh][nw])
q.append((nh,nw))
ans = max(ans,cost_max)
print(ans) | 34 | 35 | 998 | 1,051 | import collections
H, W = list(map(int, input().split()))
if H == W == 1:
print((0))
exit()
if (H == 1 and W == 2) or (H == 2 and W == 1):
print((1))
exit()
LL = []
for i in range(H):
LL.append(eval(input()))
L = ((1, 0), (0, 1), (-1, 0), (0, -1))
q = collections.deque()
max_L = []
for i in range(H):
for j in range(W):
d = [[0] * W for i in range(H)]
if LL[i][j] == ".":
q.append((i, j))
d[i][j] = 0
max1 = 0
while q:
x, y = q.popleft()
for dx, dy in L:
if (
0 > x + dx
or x + dx > H - 1
or 0 > y + dy
or y + dy > W - 1
or d[x + dx][y + dy] != 0
):
continue
if LL[x + dx][y + dy] == ".":
d[x + dx][y + dy] = d[x][y] + 1
q.append((x + dx, y + dy))
max1 = max(max1, d[x + dx][y + dy])
max_L.append(max1)
# print(q,d ,max1)
print((max(max_L)))
| h, w = list(map(int, input().split()))
L = [[] * w for i in range(h)]
for i in range(h):
L[i] = list("#" + eval(input()) + "#")
L = [["#" for i in range(w + 2)]] + L + [["#" for i in range(w + 2)]]
# print(L)
from collections import deque
ans = 0
q = deque([])
for j in range(1, h + 1):
for i in range(1, w + 1):
cost = [[-1] * (w + 2) for i in range(h + 2)]
li = ((1, 0), (0, 1), (-1, 0), (0, -1))
# print(j,i)
if L[j][i] == ".":
cost[j][i] = 0
cost_max = 0
q.append((j, i))
while q:
# print(q)
r, s = q.popleft()
for dh, dw in li:
nh, nw = r + dh, s + dw
# print(L[nh][nw],)
if L[nh][nw] == "." and cost[nh][nw] == -1:
cost[nh][nw] = cost[r][s] + 1
# print(cost[nh][nw],cost[j][i])
# print(cost)
cost_max = max(cost_max, cost[nh][nw])
q.append((nh, nw))
ans = max(ans, cost_max)
print(ans)
| false | 2.857143 | [
"-import collections",
"+h, w = list(map(int, input().split()))",
"+L = [[] * w for i in range(h)]",
"+for i in range(h):",
"+ L[i] = list(\"#\" + eval(input()) + \"#\")",
"+L = [[\"#\" for i in range(w + 2)]] + L + [[\"#\" for i in range(w + 2)]]",
"+# print(L)",
"+from collections import deque",
"-H, W = list(map(int, input().split()))",
"-if H == W == 1:",
"- print((0))",
"- exit()",
"-if (H == 1 and W == 2) or (H == 2 and W == 1):",
"- print((1))",
"- exit()",
"-LL = []",
"-for i in range(H):",
"- LL.append(eval(input()))",
"-L = ((1, 0), (0, 1), (-1, 0), (0, -1))",
"-q = collections.deque()",
"-max_L = []",
"-for i in range(H):",
"- for j in range(W):",
"- d = [[0] * W for i in range(H)]",
"- if LL[i][j] == \".\":",
"- q.append((i, j))",
"- d[i][j] = 0",
"- max1 = 0",
"- while q:",
"- x, y = q.popleft()",
"- for dx, dy in L:",
"- if (",
"- 0 > x + dx",
"- or x + dx > H - 1",
"- or 0 > y + dy",
"- or y + dy > W - 1",
"- or d[x + dx][y + dy] != 0",
"- ):",
"- continue",
"- if LL[x + dx][y + dy] == \".\":",
"- d[x + dx][y + dy] = d[x][y] + 1",
"- q.append((x + dx, y + dy))",
"- max1 = max(max1, d[x + dx][y + dy])",
"- max_L.append(max1)",
"- # print(q,d ,max1)",
"-print((max(max_L)))",
"+ans = 0",
"+q = deque([])",
"+for j in range(1, h + 1):",
"+ for i in range(1, w + 1):",
"+ cost = [[-1] * (w + 2) for i in range(h + 2)]",
"+ li = ((1, 0), (0, 1), (-1, 0), (0, -1))",
"+ # print(j,i)",
"+ if L[j][i] == \".\":",
"+ cost[j][i] = 0",
"+ cost_max = 0",
"+ q.append((j, i))",
"+ while q:",
"+ # print(q)",
"+ r, s = q.popleft()",
"+ for dh, dw in li:",
"+ nh, nw = r + dh, s + dw",
"+ # print(L[nh][nw],)",
"+ if L[nh][nw] == \".\" and cost[nh][nw] == -1:",
"+ cost[nh][nw] = cost[r][s] + 1",
"+ # print(cost[nh][nw],cost[j][i])",
"+ # print(cost)",
"+ cost_max = max(cost_max, cost[nh][nw])",
"+ q.append((nh, nw))",
"+ ans = max(ans, cost_max)",
"+print(ans)"
] | false | 0.045845 | 0.039264 | 1.167615 | [
"s667049068",
"s585509287"
] |
u062147869 | p03807 | python | s276489225 | s095703706 | 249 | 215 | 63,216 | 62,448 | Accepted | Accepted | 13.65 | N=int(eval(input()))
A=[int(i) for i in input().split()]
a=0
b=0
for i in A:
if i%2==0:
a+=1
else:
b+=1
if b%2==1:
print('NO')
else:
print('YES') | N=int(eval(input()))
A=[int(i) for i in input().split()]
L=[0,0]
for a in A:
L[a%2]+=1
if L[1]%2==1:
print('NO')
else:
print('YES') | 13 | 9 | 183 | 145 | N = int(eval(input()))
A = [int(i) for i in input().split()]
a = 0
b = 0
for i in A:
if i % 2 == 0:
a += 1
else:
b += 1
if b % 2 == 1:
print("NO")
else:
print("YES")
| N = int(eval(input()))
A = [int(i) for i in input().split()]
L = [0, 0]
for a in A:
L[a % 2] += 1
if L[1] % 2 == 1:
print("NO")
else:
print("YES")
| false | 30.769231 | [
"-a = 0",
"-b = 0",
"-for i in A:",
"- if i % 2 == 0:",
"- a += 1",
"- else:",
"- b += 1",
"-if b % 2 == 1:",
"+L = [0, 0]",
"+for a in A:",
"+ L[a % 2] += 1",
"+if L[1] % 2 == 1:"
] | false | 0.155986 | 0.04733 | 3.295728 | [
"s276489225",
"s095703706"
] |
u576432509 | p03108 | python | s119686334 | s321529951 | 1,979 | 1,819 | 86,592 | 91,012 | Accepted | Accepted | 8.08 | import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict
input = sys.stdin.readline
icase=0
if icase==0:
n,m=list(map(int,input().split()))
a=[0]*m
b=[0]*m
for i in range(m):
ai,bi=list(map(int,input().split()))
a[i]=ai-1
b[i]=bi-1
pair=[i for i in range(n)]
def root(x):
if x==pair[x]:
return x
else:
tmp=root(pair[x])
pair[x]=tmp
return tmp
def unite(x,y):
x=root(x)
y=root(y)
if x==y:
return
elif x>y:
pair[x]=y
else:
pair[y]=x
def q087():
cc=[]
c1=[1]*n
c2=defaultdict(int)
c2[1]=n
c=n
for i in range(m-1):
rta=root(a[m-i-1])
rtb=root(b[m-i-1])
if c1[rta]>=n or c1[rtb]>=n:
cc.append(0)
continue
if rta<rtb:
d2=c1[rta]
d3=c1[rtb]
c1[rta]+=c1[rtb]
c1[rtb]=0
d1=c1[rta]
pair[rtb]=rta
# unite(a[m-i-1],b[m-i-1])
elif rta>rtb:
d2=c1[rta]
d3=c1[rtb]
c1[rtb]+=c1[rta]
c1[rta]=0
d1=c1[rtb]
pair[rta]=rtb
# unite(a[m-i-1],b[m-i-1])
else:
cc.append(c)
continue
c2[d1]+=1
if c2[d2]>0:
c2[d2]-=1
if c2[d3]>0:
c2[d3]-=1
q=[]
for c2k,c2v in list(c2.items()):
if c2v==0:
q.append(c2k)
while q:
del c2[q.pop()]
c3=[]
for c2k,c2v in list(c2.items()):
c3.append((c2k,c2k*c2v))
c=0
for i,c3i in enumerate(c3):
c+=c3i[1]*(c3i[1]-c3i[0])//2
for j,c3j in enumerate(c3[0:i]):
c+=c3i[1]*c3j[1]
cc.append(c)
for i in range(m-2,-1,-1):
print((cc[i]))
print((n*(n-1)//2))
#-------------------------------
q087()
#-------------------------------
| import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict
input = sys.stdin.readline
icase=0
if icase==0:
n,m=list(map(int,input().split()))
a=[0]*m
b=[0]*m
for i in range(m):
ai,bi=list(map(int,input().split()))
a[i]=ai-1
b[i]=bi-1
pair=[i for i in range(n)]
def root(x):
if x==pair[x]:
return x
else:
tmp=root(pair[x])
pair[x]=tmp
return tmp
def unite(x,y):
x=root(x)
y=root(y)
if x==y:
return
elif x>y:
pair[x]=y
else:
pair[y]=x
def q087():
cc=[]
c1=[1]*n
c2=defaultdict(int)
c2[1]=n
c=n
for i in range(m-1):
rta=root(a[m-i-1])
rtb=root(b[m-i-1])
if c1[rta]>=n or c1[rtb]>=n:
cc.append(0)
continue
if rta<rtb:
d2=c1[rta]
d3=c1[rtb]
c1[rta]+=c1[rtb]
c1[rtb]=0
d1=c1[rta]
# pair[rtb]=rta
unite(a[m-i-1],b[m-i-1])
elif rta>rtb:
d2=c1[rta]
d3=c1[rtb]
c1[rtb]+=c1[rta]
c1[rta]=0
d1=c1[rtb]
# pair[rta]=rtb
unite(a[m-i-1],b[m-i-1])
else:
cc.append(c)
continue
c2[d1]+=1
if c2[d2]>0:
c2[d2]-=1
if c2[d3]>0:
c2[d3]-=1
q=[]
for c2k,c2v in list(c2.items()):
if c2v==0:
q.append(c2k)
while q:
del c2[q.pop()]
c3=[]
for c2k,c2v in list(c2.items()):
c3.append((c2k,c2k*c2v))
c=0
for i,c3i in enumerate(c3):
c+=c3i[1]*(c3i[1]-c3i[0])//2
for j,c3j in enumerate(c3[0:i]):
c+=c3i[1]*c3j[1]
cc.append(c)
for i in range(m-2,-1,-1):
print((cc[i]))
print((n*(n-1)//2))
#-------------------------------
q087()
#-------------------------------
| 96 | 96 | 2,072 | 2,072 | import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict
input = sys.stdin.readline
icase = 0
if icase == 0:
n, m = list(map(int, input().split()))
a = [0] * m
b = [0] * m
for i in range(m):
ai, bi = list(map(int, input().split()))
a[i] = ai - 1
b[i] = bi - 1
pair = [i for i in range(n)]
def root(x):
if x == pair[x]:
return x
else:
tmp = root(pair[x])
pair[x] = tmp
return tmp
def unite(x, y):
x = root(x)
y = root(y)
if x == y:
return
elif x > y:
pair[x] = y
else:
pair[y] = x
def q087():
cc = []
c1 = [1] * n
c2 = defaultdict(int)
c2[1] = n
c = n
for i in range(m - 1):
rta = root(a[m - i - 1])
rtb = root(b[m - i - 1])
if c1[rta] >= n or c1[rtb] >= n:
cc.append(0)
continue
if rta < rtb:
d2 = c1[rta]
d3 = c1[rtb]
c1[rta] += c1[rtb]
c1[rtb] = 0
d1 = c1[rta]
pair[rtb] = rta
# unite(a[m-i-1],b[m-i-1])
elif rta > rtb:
d2 = c1[rta]
d3 = c1[rtb]
c1[rtb] += c1[rta]
c1[rta] = 0
d1 = c1[rtb]
pair[rta] = rtb
# unite(a[m-i-1],b[m-i-1])
else:
cc.append(c)
continue
c2[d1] += 1
if c2[d2] > 0:
c2[d2] -= 1
if c2[d3] > 0:
c2[d3] -= 1
q = []
for c2k, c2v in list(c2.items()):
if c2v == 0:
q.append(c2k)
while q:
del c2[q.pop()]
c3 = []
for c2k, c2v in list(c2.items()):
c3.append((c2k, c2k * c2v))
c = 0
for i, c3i in enumerate(c3):
c += c3i[1] * (c3i[1] - c3i[0]) // 2
for j, c3j in enumerate(c3[0:i]):
c += c3i[1] * c3j[1]
cc.append(c)
for i in range(m - 2, -1, -1):
print((cc[i]))
print((n * (n - 1) // 2))
# -------------------------------
q087()
# -------------------------------
| import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict
input = sys.stdin.readline
icase = 0
if icase == 0:
n, m = list(map(int, input().split()))
a = [0] * m
b = [0] * m
for i in range(m):
ai, bi = list(map(int, input().split()))
a[i] = ai - 1
b[i] = bi - 1
pair = [i for i in range(n)]
def root(x):
if x == pair[x]:
return x
else:
tmp = root(pair[x])
pair[x] = tmp
return tmp
def unite(x, y):
x = root(x)
y = root(y)
if x == y:
return
elif x > y:
pair[x] = y
else:
pair[y] = x
def q087():
cc = []
c1 = [1] * n
c2 = defaultdict(int)
c2[1] = n
c = n
for i in range(m - 1):
rta = root(a[m - i - 1])
rtb = root(b[m - i - 1])
if c1[rta] >= n or c1[rtb] >= n:
cc.append(0)
continue
if rta < rtb:
d2 = c1[rta]
d3 = c1[rtb]
c1[rta] += c1[rtb]
c1[rtb] = 0
d1 = c1[rta]
# pair[rtb]=rta
unite(a[m - i - 1], b[m - i - 1])
elif rta > rtb:
d2 = c1[rta]
d3 = c1[rtb]
c1[rtb] += c1[rta]
c1[rta] = 0
d1 = c1[rtb]
# pair[rta]=rtb
unite(a[m - i - 1], b[m - i - 1])
else:
cc.append(c)
continue
c2[d1] += 1
if c2[d2] > 0:
c2[d2] -= 1
if c2[d3] > 0:
c2[d3] -= 1
q = []
for c2k, c2v in list(c2.items()):
if c2v == 0:
q.append(c2k)
while q:
del c2[q.pop()]
c3 = []
for c2k, c2v in list(c2.items()):
c3.append((c2k, c2k * c2v))
c = 0
for i, c3i in enumerate(c3):
c += c3i[1] * (c3i[1] - c3i[0]) // 2
for j, c3j in enumerate(c3[0:i]):
c += c3i[1] * c3j[1]
cc.append(c)
for i in range(m - 2, -1, -1):
print((cc[i]))
print((n * (n - 1) // 2))
# -------------------------------
q087()
# -------------------------------
| false | 0 | [
"- pair[rtb] = rta",
"- # unite(a[m-i-1],b[m-i-1])",
"+ # pair[rtb]=rta",
"+ unite(a[m - i - 1], b[m - i - 1])",
"- pair[rta] = rtb",
"- # unite(a[m-i-1],b[m-i-1])",
"+ # pair[rta]=rtb",
"+ unite(a[m - i - 1], b[m - i - 1])"
] | false | 0.03812 | 0.039441 | 0.966513 | [
"s119686334",
"s321529951"
] |
u075012704 | p03700 | python | s060235472 | s324268521 | 1,330 | 1,230 | 15,024 | 15,076 | Accepted | Accepted | 7.52 | from math import ceil
N, A, B = list(map(int, input().split()))
H = [int(eval(input())) for i in range(N)]
A -= B # 爆発は追加ダメージ扱いとする
# にぶたん
ok, ng = 10 ** 9, 0
while abs(ok - ng) > 1:
X = (ok + ng) // 2
h = [max(hi - B * X, 0) for hi in H]
h = [ceil(hi / A) for hi in h]
if sum(h) <= X:
ok = X
else:
ng = X
print(ok)
| from math import ceil
N, A, B = list(map(int, input().split()))
H = [int(eval(input())) for i in range(N)]
A -= B # Aを追加ダメージ扱いにする
ok, ng = 10 ** 9, 0
while abs(ok - ng) > 1:
X = (ok + ng) // 2
H_damaged = [h - (B * X) for h in H if h - (B * X) > 0]
Need = sum([ceil(h / A) for h in H_damaged])
if X >= Need:
ok = X
else:
ng = X
print(ok)
| 21 | 18 | 366 | 384 | from math import ceil
N, A, B = list(map(int, input().split()))
H = [int(eval(input())) for i in range(N)]
A -= B # 爆発は追加ダメージ扱いとする
# にぶたん
ok, ng = 10**9, 0
while abs(ok - ng) > 1:
X = (ok + ng) // 2
h = [max(hi - B * X, 0) for hi in H]
h = [ceil(hi / A) for hi in h]
if sum(h) <= X:
ok = X
else:
ng = X
print(ok)
| from math import ceil
N, A, B = list(map(int, input().split()))
H = [int(eval(input())) for i in range(N)]
A -= B # Aを追加ダメージ扱いにする
ok, ng = 10**9, 0
while abs(ok - ng) > 1:
X = (ok + ng) // 2
H_damaged = [h - (B * X) for h in H if h - (B * X) > 0]
Need = sum([ceil(h / A) for h in H_damaged])
if X >= Need:
ok = X
else:
ng = X
print(ok)
| false | 14.285714 | [
"-A -= B # 爆発は追加ダメージ扱いとする",
"-# にぶたん",
"+A -= B # Aを追加ダメージ扱いにする",
"- h = [max(hi - B * X, 0) for hi in H]",
"- h = [ceil(hi / A) for hi in h]",
"- if sum(h) <= X:",
"+ H_damaged = [h - (B * X) for h in H if h - (B * X) > 0]",
"+ Need = sum([ceil(h / A) for h in H_damaged])",
"+ if X >= Need:"
] | false | 0.108426 | 0.088238 | 1.228789 | [
"s060235472",
"s324268521"
] |
u461513098 | p02861 | python | s249983406 | s977828527 | 457 | 344 | 4,400 | 3,188 | Accepted | Accepted | 24.73 | import itertools
import math
N = int(eval(input()))
crd_list = []
for _ in range(N):
crd_list.append([int(xy) for xy in input().split()])
cost_list = []
for way in itertools.permutations([n for n in range(N)]):
cost = 0
for index in range(1, N):
cost += ((crd_list[way[index]][0]-crd_list[way[index-1]][0])**2 + (crd_list[way[index]][1]-crd_list[way[index-1]][1])**2)**0.5
cost_list.append(cost)
print((sum(cost_list)/math.factorial(N))) | import sys
import itertools
input = sys.stdin.readline
def fact(n):
res = 1
for i in range(n):
res *= n - i
return res
def main():
dst_sum = 0
for p in itertools.permutations(T):
for i in range(1, N):
px, py = p[i-1]
cx, cy = p[i]
dst_sum += ((cx-px)**2 + (cy-py)**2)**0.5
print((dst_sum/fact(N)))
if __name__ == "__main__":
N = int(eval(input()))
T = [tuple(map(int, input().split())) for _ in range(N)]
main()
| 16 | 28 | 471 | 527 | import itertools
import math
N = int(eval(input()))
crd_list = []
for _ in range(N):
crd_list.append([int(xy) for xy in input().split()])
cost_list = []
for way in itertools.permutations([n for n in range(N)]):
cost = 0
for index in range(1, N):
cost += (
(crd_list[way[index]][0] - crd_list[way[index - 1]][0]) ** 2
+ (crd_list[way[index]][1] - crd_list[way[index - 1]][1]) ** 2
) ** 0.5
cost_list.append(cost)
print((sum(cost_list) / math.factorial(N)))
| import sys
import itertools
input = sys.stdin.readline
def fact(n):
res = 1
for i in range(n):
res *= n - i
return res
def main():
dst_sum = 0
for p in itertools.permutations(T):
for i in range(1, N):
px, py = p[i - 1]
cx, cy = p[i]
dst_sum += ((cx - px) ** 2 + (cy - py) ** 2) ** 0.5
print((dst_sum / fact(N)))
if __name__ == "__main__":
N = int(eval(input()))
T = [tuple(map(int, input().split())) for _ in range(N)]
main()
| false | 42.857143 | [
"+import sys",
"-import math",
"-N = int(eval(input()))",
"-crd_list = []",
"-for _ in range(N):",
"- crd_list.append([int(xy) for xy in input().split()])",
"-cost_list = []",
"-for way in itertools.permutations([n for n in range(N)]):",
"- cost = 0",
"- for index in range(1, N):",
"- cost += (",
"- (crd_list[way[index]][0] - crd_list[way[index - 1]][0]) ** 2",
"- + (crd_list[way[index]][1] - crd_list[way[index - 1]][1]) ** 2",
"- ) ** 0.5",
"- cost_list.append(cost)",
"-print((sum(cost_list) / math.factorial(N)))",
"+input = sys.stdin.readline",
"+",
"+",
"+def fact(n):",
"+ res = 1",
"+ for i in range(n):",
"+ res *= n - i",
"+ return res",
"+",
"+",
"+def main():",
"+ dst_sum = 0",
"+ for p in itertools.permutations(T):",
"+ for i in range(1, N):",
"+ px, py = p[i - 1]",
"+ cx, cy = p[i]",
"+ dst_sum += ((cx - px) ** 2 + (cy - py) ** 2) ** 0.5",
"+ print((dst_sum / fact(N)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ N = int(eval(input()))",
"+ T = [tuple(map(int, input().split())) for _ in range(N)]",
"+ main()"
] | false | 0.121245 | 0.048611 | 2.494189 | [
"s249983406",
"s977828527"
] |
u079022693 | p02787 | python | s474688876 | s898333931 | 563 | 432 | 121,196 | 12,608 | Accepted | Accepted | 23.27 | H,N=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)
DP=[[0]*(H+1) for i in range(N)]
DP.insert(0,[float("inf")]*(H+max(A)))
DP[0][0]=0
for i in range(1,N+1):
for j in range(1,H+1):
if j-A[i-1]>0:
DP[i][j]=min(DP[i-1][j],DP[i][j-A[i-1]]+B[i-1])
else:
DP[i][j]=min(DP[i-1][j],B[i-1])
print((DP[N][H])) | from sys import stdin
import numpy as np
def main():
#入力
readline=stdin.readline
h,n=list(map(int,readline().split()))
ab=np.array([list(map(int,readline().split())) for _ in range(n)],dtype=np.int64)
a=ab[:,0]
b=ab[:,1]
dp=np.zeros(h+1,dtype=np.int64)
for i in range(1,h+1):
dp[i]=(dp[np.maximum(0,i-a)]+b).min()
print((dp[h]))
if __name__=="__main__":
main() | 20 | 18 | 420 | 420 | H, N = 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)
DP = [[0] * (H + 1) for i in range(N)]
DP.insert(0, [float("inf")] * (H + max(A)))
DP[0][0] = 0
for i in range(1, N + 1):
for j in range(1, H + 1):
if j - A[i - 1] > 0:
DP[i][j] = min(DP[i - 1][j], DP[i][j - A[i - 1]] + B[i - 1])
else:
DP[i][j] = min(DP[i - 1][j], B[i - 1])
print((DP[N][H]))
| from sys import stdin
import numpy as np
def main():
# 入力
readline = stdin.readline
h, n = list(map(int, readline().split()))
ab = np.array(
[list(map(int, readline().split())) for _ in range(n)], dtype=np.int64
)
a = ab[:, 0]
b = ab[:, 1]
dp = np.zeros(h + 1, dtype=np.int64)
for i in range(1, h + 1):
dp[i] = (dp[np.maximum(0, i - a)] + b).min()
print((dp[h]))
if __name__ == "__main__":
main()
| false | 10 | [
"-H, N = 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)",
"-DP = [[0] * (H + 1) for i in range(N)]",
"-DP.insert(0, [float(\"inf\")] * (H + max(A)))",
"-DP[0][0] = 0",
"-for i in range(1, N + 1):",
"- for j in range(1, H + 1):",
"- if j - A[i - 1] > 0:",
"- DP[i][j] = min(DP[i - 1][j], DP[i][j - A[i - 1]] + B[i - 1])",
"- else:",
"- DP[i][j] = min(DP[i - 1][j], B[i - 1])",
"-print((DP[N][H]))",
"+from sys import stdin",
"+import numpy as np",
"+",
"+",
"+def main():",
"+ # 入力",
"+ readline = stdin.readline",
"+ h, n = list(map(int, readline().split()))",
"+ ab = np.array(",
"+ [list(map(int, readline().split())) for _ in range(n)], dtype=np.int64",
"+ )",
"+ a = ab[:, 0]",
"+ b = ab[:, 1]",
"+ dp = np.zeros(h + 1, dtype=np.int64)",
"+ for i in range(1, h + 1):",
"+ dp[i] = (dp[np.maximum(0, i - a)] + b).min()",
"+ print((dp[h]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.126961 | 0.437789 | 0.290006 | [
"s474688876",
"s898333931"
] |
u021548497 | p02793 | python | s865518878 | s454923622 | 1,836 | 435 | 4,844 | 114,796 | Accepted | Accepted | 76.31 | import sys
from collections import Counter
def prime_factorize(n):
ans = []
while not n%2:
ans.append(2)
n //= 2
mod = 3
while mod**2 <= n:
if n%mod == 0:
ans.append(mod)
n //= mod
else:
mod += 2
if n != 1:
ans.append(n)
counter = Counter(ans)
return counter
def main():
input = sys.stdin.readline
mod = pow(10,9)+7
n = int(eval(input()))
a = [int(x) for x in input().split()]
prime_list = dict()
for i in range(n):
primes = prime_factorize(a[i])
for key, value in list(primes.items()):
if key in prime_list:
if prime_list[key] < value:
prime_list[key] = value
else:
prime_list[key] = value
L = 1
for key, value in list(prime_list.items()):
L *= pow(key, value, mod)
L %= mod
ans = 0
for i in range(n):
ans += (L*pow(a[i], mod-2, mod))%mod
ans %= mod
print(ans)
if __name__ == "__main__":
main() | import sys
from collections import Counter
import time
class Osa_k:
def __init__(self, n):
self.n = n
self.min_factor = [int(x) for x in range(n+1)]
self.is_prime = [True] * (self.n + 1)
self.is_prime[0] = False
self.is_prime[1] = False
for j in range(4, self.n+1, 2):
self.is_prime[j] = False
self.min_factor[j] = 2
for i in range(3, int(self.n**0.5) + 1, 2):
if not self.is_prime[i]:
continue
for j in range(i * 2, self.n + 1, i):
self.is_prime[j] = False
if self.min_factor[j] >= i:
self.min_factor[j] = i
def calculate(self, x):
ans = []
while x > 1:
key = self.min_factor[x]
while x%key == 0:
ans.append(key)
x //= key
counter = Counter(ans)
return counter
def main():
input = sys.stdin.readline
mod = pow(10,9)+7
n = int(eval(input()))
a = [int(x) for x in input().split()]
prime_list = dict()
osa_k = Osa_k(max(a))
for i in range(n):
primes = osa_k.calculate(a[i])
for key, value in list(primes.items()):
if key in prime_list:
if prime_list[key] < value:
prime_list[key] = value
else:
prime_list[key] = value
L = 1
for key, value in list(prime_list.items()):
L *= pow(key, value, mod)
L %= mod
ans = 0
for i in range(n):
ans += (L*pow(a[i], mod-2, mod))%mod
ans %= mod
print(ans)
if __name__ == "__main__":
main() | 50 | 66 | 1,129 | 1,769 | import sys
from collections import Counter
def prime_factorize(n):
ans = []
while not n % 2:
ans.append(2)
n //= 2
mod = 3
while mod**2 <= n:
if n % mod == 0:
ans.append(mod)
n //= mod
else:
mod += 2
if n != 1:
ans.append(n)
counter = Counter(ans)
return counter
def main():
input = sys.stdin.readline
mod = pow(10, 9) + 7
n = int(eval(input()))
a = [int(x) for x in input().split()]
prime_list = dict()
for i in range(n):
primes = prime_factorize(a[i])
for key, value in list(primes.items()):
if key in prime_list:
if prime_list[key] < value:
prime_list[key] = value
else:
prime_list[key] = value
L = 1
for key, value in list(prime_list.items()):
L *= pow(key, value, mod)
L %= mod
ans = 0
for i in range(n):
ans += (L * pow(a[i], mod - 2, mod)) % mod
ans %= mod
print(ans)
if __name__ == "__main__":
main()
| import sys
from collections import Counter
import time
class Osa_k:
def __init__(self, n):
self.n = n
self.min_factor = [int(x) for x in range(n + 1)]
self.is_prime = [True] * (self.n + 1)
self.is_prime[0] = False
self.is_prime[1] = False
for j in range(4, self.n + 1, 2):
self.is_prime[j] = False
self.min_factor[j] = 2
for i in range(3, int(self.n**0.5) + 1, 2):
if not self.is_prime[i]:
continue
for j in range(i * 2, self.n + 1, i):
self.is_prime[j] = False
if self.min_factor[j] >= i:
self.min_factor[j] = i
def calculate(self, x):
ans = []
while x > 1:
key = self.min_factor[x]
while x % key == 0:
ans.append(key)
x //= key
counter = Counter(ans)
return counter
def main():
input = sys.stdin.readline
mod = pow(10, 9) + 7
n = int(eval(input()))
a = [int(x) for x in input().split()]
prime_list = dict()
osa_k = Osa_k(max(a))
for i in range(n):
primes = osa_k.calculate(a[i])
for key, value in list(primes.items()):
if key in prime_list:
if prime_list[key] < value:
prime_list[key] = value
else:
prime_list[key] = value
L = 1
for key, value in list(prime_list.items()):
L *= pow(key, value, mod)
L %= mod
ans = 0
for i in range(n):
ans += (L * pow(a[i], mod - 2, mod)) % mod
ans %= mod
print(ans)
if __name__ == "__main__":
main()
| false | 24.242424 | [
"+import time",
"-def prime_factorize(n):",
"- ans = []",
"- while not n % 2:",
"- ans.append(2)",
"- n //= 2",
"- mod = 3",
"- while mod**2 <= n:",
"- if n % mod == 0:",
"- ans.append(mod)",
"- n //= mod",
"- else:",
"- mod += 2",
"- if n != 1:",
"- ans.append(n)",
"- counter = Counter(ans)",
"- return counter",
"+class Osa_k:",
"+ def __init__(self, n):",
"+ self.n = n",
"+ self.min_factor = [int(x) for x in range(n + 1)]",
"+ self.is_prime = [True] * (self.n + 1)",
"+ self.is_prime[0] = False",
"+ self.is_prime[1] = False",
"+ for j in range(4, self.n + 1, 2):",
"+ self.is_prime[j] = False",
"+ self.min_factor[j] = 2",
"+ for i in range(3, int(self.n**0.5) + 1, 2):",
"+ if not self.is_prime[i]:",
"+ continue",
"+ for j in range(i * 2, self.n + 1, i):",
"+ self.is_prime[j] = False",
"+ if self.min_factor[j] >= i:",
"+ self.min_factor[j] = i",
"+",
"+ def calculate(self, x):",
"+ ans = []",
"+ while x > 1:",
"+ key = self.min_factor[x]",
"+ while x % key == 0:",
"+ ans.append(key)",
"+ x //= key",
"+ counter = Counter(ans)",
"+ return counter",
"+ osa_k = Osa_k(max(a))",
"- primes = prime_factorize(a[i])",
"+ primes = osa_k.calculate(a[i])"
] | false | 0.038927 | 0.629528 | 0.061835 | [
"s865518878",
"s454923622"
] |
u140480594 | p03399 | python | s177566395 | s539816514 | 20 | 17 | 3,060 | 2,940 | Accepted | Accepted | 15 | A, B, C, D = int(eval(input())), int(eval(input())), int(eval(input())), int(eval(input()))
fare = 0
if A <= B : fare += A
else : fare += B
if C <= D : fare += C
else : fare += D
print(fare) | Train = [int(eval(input())), int(eval(input()))]
Bus = [int(eval(input())), int(eval(input()))]
print((min(Train) + min(Bus))) | 7 | 3 | 172 | 102 | A, B, C, D = (
int(eval(input())),
int(eval(input())),
int(eval(input())),
int(eval(input())),
)
fare = 0
if A <= B:
fare += A
else:
fare += B
if C <= D:
fare += C
else:
fare += D
print(fare)
| Train = [int(eval(input())), int(eval(input()))]
Bus = [int(eval(input())), int(eval(input()))]
print((min(Train) + min(Bus)))
| false | 57.142857 | [
"-A, B, C, D = (",
"- int(eval(input())),",
"- int(eval(input())),",
"- int(eval(input())),",
"- int(eval(input())),",
"-)",
"-fare = 0",
"-if A <= B:",
"- fare += A",
"-else:",
"- fare += B",
"-if C <= D:",
"- fare += C",
"-else:",
"- fare += D",
"-print(fare)",
"+Train = [int(eval(input())), int(eval(input()))]",
"+Bus = [int(eval(input())), int(eval(input()))]",
"+print((min(Train) + min(Bus)))"
] | false | 0.040931 | 0.042873 | 0.954706 | [
"s177566395",
"s539816514"
] |
u296518383 | p02936 | python | s398152210 | s759457429 | 1,993 | 1,440 | 128,160 | 130,216 | Accepted | Accepted | 27.75 | N, Q = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N - 1)]
PX = [list(map(int, input().split())) for _ in range(Q)]
graph = [[] for _ in range(N + 1)]
for A, B in AB:
graph[A].append(B)
graph[B].append(A)
graph = tuple(graph)
#print("graph:", graph)
X = [0] * (N + 1)
for p, x in PX:
X[p] += x
#print("X:", X)
stack = [1]
check = [0] * (N + 1)
check[1] = 1
cnt = [0] * (N + 1)
cnt[1] = X[1]
while stack:
s = stack.pop()
for g in graph[s]:
if check[g] == 0:
check[g] = 1
cnt[g] = cnt[s] + X[g]
stack.append(g)
print((*cnt[1::])) | import sys
input = sys.stdin.buffer.readline
N, Q = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N - 1)]
PX = [list(map(int, input().split())) for _ in range(Q)]
graph = [[] for _ in range(N + 1)]
for a, b in AB:
graph[a].append(b)
graph[b].append(a)
cost = [0] * (N + 1)
for p, x in PX:
cost[p] += x
check = [0] * (N + 1)
stack = [1]
check[1] = 1
while stack:
s = stack.pop()
for g in graph[s]:
if check[g] == 0:
check[g] = 1
cost[g] += cost[s]
stack.append(g)
print((*cost[1:])) | 30 | 29 | 627 | 588 | N, Q = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N - 1)]
PX = [list(map(int, input().split())) for _ in range(Q)]
graph = [[] for _ in range(N + 1)]
for A, B in AB:
graph[A].append(B)
graph[B].append(A)
graph = tuple(graph)
# print("graph:", graph)
X = [0] * (N + 1)
for p, x in PX:
X[p] += x
# print("X:", X)
stack = [1]
check = [0] * (N + 1)
check[1] = 1
cnt = [0] * (N + 1)
cnt[1] = X[1]
while stack:
s = stack.pop()
for g in graph[s]:
if check[g] == 0:
check[g] = 1
cnt[g] = cnt[s] + X[g]
stack.append(g)
print((*cnt[1::]))
| import sys
input = sys.stdin.buffer.readline
N, Q = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N - 1)]
PX = [list(map(int, input().split())) for _ in range(Q)]
graph = [[] for _ in range(N + 1)]
for a, b in AB:
graph[a].append(b)
graph[b].append(a)
cost = [0] * (N + 1)
for p, x in PX:
cost[p] += x
check = [0] * (N + 1)
stack = [1]
check[1] = 1
while stack:
s = stack.pop()
for g in graph[s]:
if check[g] == 0:
check[g] = 1
cost[g] += cost[s]
stack.append(g)
print((*cost[1:]))
| false | 3.333333 | [
"+import sys",
"+",
"+input = sys.stdin.buffer.readline",
"-for A, B in AB:",
"- graph[A].append(B)",
"- graph[B].append(A)",
"-graph = tuple(graph)",
"-# print(\"graph:\", graph)",
"-X = [0] * (N + 1)",
"+for a, b in AB:",
"+ graph[a].append(b)",
"+ graph[b].append(a)",
"+cost = [0] * (N + 1)",
"- X[p] += x",
"-# print(\"X:\", X)",
"+ cost[p] += x",
"+check = [0] * (N + 1)",
"-check = [0] * (N + 1)",
"-cnt = [0] * (N + 1)",
"-cnt[1] = X[1]",
"- cnt[g] = cnt[s] + X[g]",
"+ cost[g] += cost[s]",
"-print((*cnt[1::]))",
"+print((*cost[1:]))"
] | false | 0.092726 | 0.043455 | 2.133832 | [
"s398152210",
"s759457429"
] |
u855775311 | p02370 | python | s356193603 | s911024234 | 210 | 170 | 10,940 | 11,044 | Accepted | Accepted | 19.05 | def main():
nvertices, nedges = list(map(int, input().split()))
indegrees = [0 for i in range(nvertices)]
adj = [[] for i in range(nvertices)]
for i in range(nedges):
s, t = list(map(int, input().split()))
adj[s].append(t)
indegrees[t] += 1
S = []
for i in range(nvertices):
if indegrees[i] == 0:
S.append(i)
ordering = []
while S:
u = S.pop(0)
ordering.append(u)
for v in adj[u]:
indegrees[v] -= 1
if indegrees[v] == 0:
S.append(v)
for v in ordering:
print(v)
main() | def main():
nvertices, nedges = list(map(int, input().split()))
Adj = [[] for i in range(nvertices)]
for i in range(nedges):
s, t = list(map(int, input().split()))
Adj[s].append(t)
visited = [False] * nvertices
ordering = []
for u in range(nvertices):
if not visited[u]:
dfs(u, Adj, visited, ordering)
for v in reversed(ordering):
print(v)
def dfs(u, Adj, visited, ordering):
visited[u] = True
for v in Adj[u]:
if not visited[v]:
dfs(v, Adj, visited, ordering)
ordering.append(u)
main() | 27 | 26 | 637 | 609 | def main():
nvertices, nedges = list(map(int, input().split()))
indegrees = [0 for i in range(nvertices)]
adj = [[] for i in range(nvertices)]
for i in range(nedges):
s, t = list(map(int, input().split()))
adj[s].append(t)
indegrees[t] += 1
S = []
for i in range(nvertices):
if indegrees[i] == 0:
S.append(i)
ordering = []
while S:
u = S.pop(0)
ordering.append(u)
for v in adj[u]:
indegrees[v] -= 1
if indegrees[v] == 0:
S.append(v)
for v in ordering:
print(v)
main()
| def main():
nvertices, nedges = list(map(int, input().split()))
Adj = [[] for i in range(nvertices)]
for i in range(nedges):
s, t = list(map(int, input().split()))
Adj[s].append(t)
visited = [False] * nvertices
ordering = []
for u in range(nvertices):
if not visited[u]:
dfs(u, Adj, visited, ordering)
for v in reversed(ordering):
print(v)
def dfs(u, Adj, visited, ordering):
visited[u] = True
for v in Adj[u]:
if not visited[v]:
dfs(v, Adj, visited, ordering)
ordering.append(u)
main()
| false | 3.703704 | [
"- indegrees = [0 for i in range(nvertices)]",
"- adj = [[] for i in range(nvertices)]",
"+ Adj = [[] for i in range(nvertices)]",
"- adj[s].append(t)",
"- indegrees[t] += 1",
"- S = []",
"- for i in range(nvertices):",
"- if indegrees[i] == 0:",
"- S.append(i)",
"+ Adj[s].append(t)",
"+ visited = [False] * nvertices",
"- while S:",
"- u = S.pop(0)",
"- ordering.append(u)",
"- for v in adj[u]:",
"- indegrees[v] -= 1",
"- if indegrees[v] == 0:",
"- S.append(v)",
"- for v in ordering:",
"+ for u in range(nvertices):",
"+ if not visited[u]:",
"+ dfs(u, Adj, visited, ordering)",
"+ for v in reversed(ordering):",
"+def dfs(u, Adj, visited, ordering):",
"+ visited[u] = True",
"+ for v in Adj[u]:",
"+ if not visited[v]:",
"+ dfs(v, Adj, visited, ordering)",
"+ ordering.append(u)",
"+",
"+"
] | false | 0.046525 | 0.039446 | 1.179452 | [
"s356193603",
"s911024234"
] |
u944886577 | p02628 | python | s361403440 | s630434633 | 33 | 28 | 8,972 | 9,160 | Accepted | Accepted | 15.15 | a,b=list(map(int,input().split()))
c=list(map(int,input().split()))
d=sorted(c)
ans=0
for i in range(0,b):
ans+=d[i]
print(ans) | a,b=list(map(int,input().split()))
c=[]
c=list(map(int,input().split()))
d=list(c)
d2=sorted(d)
ans=0
for i in range(b):
ans+=d2[i]
print(ans) | 7 | 9 | 128 | 140 | a, b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = sorted(c)
ans = 0
for i in range(0, b):
ans += d[i]
print(ans)
| a, b = list(map(int, input().split()))
c = []
c = list(map(int, input().split()))
d = list(c)
d2 = sorted(d)
ans = 0
for i in range(b):
ans += d2[i]
print(ans)
| false | 22.222222 | [
"+c = []",
"-d = sorted(c)",
"+d = list(c)",
"+d2 = sorted(d)",
"-for i in range(0, b):",
"- ans += d[i]",
"+for i in range(b):",
"+ ans += d2[i]"
] | false | 0.04268 | 0.129384 | 0.329873 | [
"s361403440",
"s630434633"
] |
u063052907 | p02953 | python | s733047509 | s729280766 | 79 | 72 | 14,252 | 14,252 | Accepted | Accepted | 8.86 | N = int(eval(input()))
lst_H = list(map(int, input().split()))
lst_H = lst_H[::-1]
ans = "Yes"
for i in range(N - 1):
if lst_H[i] + 1 == lst_H[i + 1]:
lst_H[i + 1] -= 1
elif lst_H[i] >= lst_H[i + 1]:
continue
else:
ans = "No"
break
print(ans)
| N = int(eval(input()))
lst_H = list(map(int, input().split()))
ans = "Yes"
lst_H[0] -= 1
for i in range(1, N):
if lst_H[i - 1] < lst_H[i]:
lst_H[i] -= 1
elif lst_H[i - 1] == lst_H[i]:
continue
else:
ans = "No"
break
print(ans) | 14 | 15 | 295 | 280 | N = int(eval(input()))
lst_H = list(map(int, input().split()))
lst_H = lst_H[::-1]
ans = "Yes"
for i in range(N - 1):
if lst_H[i] + 1 == lst_H[i + 1]:
lst_H[i + 1] -= 1
elif lst_H[i] >= lst_H[i + 1]:
continue
else:
ans = "No"
break
print(ans)
| N = int(eval(input()))
lst_H = list(map(int, input().split()))
ans = "Yes"
lst_H[0] -= 1
for i in range(1, N):
if lst_H[i - 1] < lst_H[i]:
lst_H[i] -= 1
elif lst_H[i - 1] == lst_H[i]:
continue
else:
ans = "No"
break
print(ans)
| false | 6.666667 | [
"-lst_H = lst_H[::-1]",
"-for i in range(N - 1):",
"- if lst_H[i] + 1 == lst_H[i + 1]:",
"- lst_H[i + 1] -= 1",
"- elif lst_H[i] >= lst_H[i + 1]:",
"+lst_H[0] -= 1",
"+for i in range(1, N):",
"+ if lst_H[i - 1] < lst_H[i]:",
"+ lst_H[i] -= 1",
"+ elif lst_H[i - 1] == lst_H[i]:"
] | false | 0.088071 | 0.0383 | 2.29951 | [
"s733047509",
"s729280766"
] |
u543954314 | p03575 | python | s031544107 | s516357845 | 27 | 17 | 3,316 | 3,064 | Accepted | Accepted | 37.04 | from collections import defaultdict as dd
n,m = list(map(int, input().split()))
dic = dd(list)
l = []
cnt = 0
for _ in range(m):
a,b = list(map(int, input().split()))
l.append((a,b))
dic[a].append(b)
dic[b].append(a)
def con(x):
visit.add(x)
for i in dic[x]:
if i in visit:
continue
con(i)
return visit == set(range(1,n+1))
for x,y in l:
dic[x].remove(y)
dic[y].remove(x)
visit = set()
if not con(x):
cnt += 1
dic[x].append(y)
dic[y].append(x)
print(cnt) | int1 = lambda x: int(x) - 1
N, M = list(map(int, input().split()))
G = [list() for _ in range(N)]
edges = [tuple(map(int1, input().split())) for _ in range(M)]
for u,v in edges:
G[u].append(v)
G[v].append(u)
pre = [-1]*N
low = [-1]*N
def detect_bridge(v, p=None, c=0):
ret = list()
pre[v] = low[v] = c
c += 1
for x in G[v]:
if x == p: continue
if pre[x] < 0:
br, c = detect_bridge(x, v, c)
ret.extend(br)
if low[v] > low[x]: low[v] = low[x]
if pre[v] == low[v] > 0:
ret.append((p, v))
return ret, c
bridges, _ = detect_bridge(0)
print((len(bridges))) | 26 | 29 | 511 | 676 | from collections import defaultdict as dd
n, m = list(map(int, input().split()))
dic = dd(list)
l = []
cnt = 0
for _ in range(m):
a, b = list(map(int, input().split()))
l.append((a, b))
dic[a].append(b)
dic[b].append(a)
def con(x):
visit.add(x)
for i in dic[x]:
if i in visit:
continue
con(i)
return visit == set(range(1, n + 1))
for x, y in l:
dic[x].remove(y)
dic[y].remove(x)
visit = set()
if not con(x):
cnt += 1
dic[x].append(y)
dic[y].append(x)
print(cnt)
| int1 = lambda x: int(x) - 1
N, M = list(map(int, input().split()))
G = [list() for _ in range(N)]
edges = [tuple(map(int1, input().split())) for _ in range(M)]
for u, v in edges:
G[u].append(v)
G[v].append(u)
pre = [-1] * N
low = [-1] * N
def detect_bridge(v, p=None, c=0):
ret = list()
pre[v] = low[v] = c
c += 1
for x in G[v]:
if x == p:
continue
if pre[x] < 0:
br, c = detect_bridge(x, v, c)
ret.extend(br)
if low[v] > low[x]:
low[v] = low[x]
if pre[v] == low[v] > 0:
ret.append((p, v))
return ret, c
bridges, _ = detect_bridge(0)
print((len(bridges)))
| false | 10.344828 | [
"-from collections import defaultdict as dd",
"-",
"-n, m = list(map(int, input().split()))",
"-dic = dd(list)",
"-l = []",
"-cnt = 0",
"-for _ in range(m):",
"- a, b = list(map(int, input().split()))",
"- l.append((a, b))",
"- dic[a].append(b)",
"- dic[b].append(a)",
"+int1 = lambda x: int(x) - 1",
"+N, M = list(map(int, input().split()))",
"+G = [list() for _ in range(N)]",
"+edges = [tuple(map(int1, input().split())) for _ in range(M)]",
"+for u, v in edges:",
"+ G[u].append(v)",
"+ G[v].append(u)",
"+pre = [-1] * N",
"+low = [-1] * N",
"-def con(x):",
"- visit.add(x)",
"- for i in dic[x]:",
"- if i in visit:",
"+def detect_bridge(v, p=None, c=0):",
"+ ret = list()",
"+ pre[v] = low[v] = c",
"+ c += 1",
"+ for x in G[v]:",
"+ if x == p:",
"- con(i)",
"- return visit == set(range(1, n + 1))",
"+ if pre[x] < 0:",
"+ br, c = detect_bridge(x, v, c)",
"+ ret.extend(br)",
"+ if low[v] > low[x]:",
"+ low[v] = low[x]",
"+ if pre[v] == low[v] > 0:",
"+ ret.append((p, v))",
"+ return ret, c",
"-for x, y in l:",
"- dic[x].remove(y)",
"- dic[y].remove(x)",
"- visit = set()",
"- if not con(x):",
"- cnt += 1",
"- dic[x].append(y)",
"- dic[y].append(x)",
"-print(cnt)",
"+bridges, _ = detect_bridge(0)",
"+print((len(bridges)))"
] | false | 0.043847 | 0.047162 | 0.929721 | [
"s031544107",
"s516357845"
] |
u968166680 | p03266 | python | s206456689 | s241790478 | 104 | 61 | 9,136 | 10,328 | Accepted | Accepted | 41.35 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, K = list(map(int, readline().split()))
ans = 0
step = K if K % 2 else K // 2
for a in range(step, N + 1, step):
l = a // K + 1
r = (N + a) // K
if r >= l:
ans += (r - l + 1) ** 2
print(ans)
return
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, K = list(map(int, readline().split()))
R = [0] * K
for n in range(1, N + 1):
R[n % K] += 1
ans = 0
for a in range(K):
b = (K - a) % K
if 2 * b % K == 0:
ans += R[a] * R[b] * R[b]
print(ans)
return
if __name__ == '__main__':
main()
| 28 | 29 | 496 | 501 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, K = list(map(int, readline().split()))
ans = 0
step = K if K % 2 else K // 2
for a in range(step, N + 1, step):
l = a // K + 1
r = (N + a) // K
if r >= l:
ans += (r - l + 1) ** 2
print(ans)
return
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, K = list(map(int, readline().split()))
R = [0] * K
for n in range(1, N + 1):
R[n % K] += 1
ans = 0
for a in range(K):
b = (K - a) % K
if 2 * b % K == 0:
ans += R[a] * R[b] * R[b]
print(ans)
return
if __name__ == "__main__":
main()
| false | 3.448276 | [
"+ R = [0] * K",
"+ for n in range(1, N + 1):",
"+ R[n % K] += 1",
"- step = K if K % 2 else K // 2",
"- for a in range(step, N + 1, step):",
"- l = a // K + 1",
"- r = (N + a) // K",
"- if r >= l:",
"- ans += (r - l + 1) ** 2",
"+ for a in range(K):",
"+ b = (K - a) % K",
"+ if 2 * b % K == 0:",
"+ ans += R[a] * R[b] * R[b]"
] | false | 0.044676 | 0.039318 | 1.136257 | [
"s206456689",
"s241790478"
] |
u047796752 | p02727 | python | s398479082 | s720731090 | 521 | 159 | 101,672 | 103,048 | Accepted | Accepted | 69.48 | import sys
input = sys.stdin.readline
from heapq import *
X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
pq = []
ans = 0
for i in range(X):
heappush(pq, p[i])
ans += p[i]
for i in range(Y):
heappush(pq, q[i])
ans += q[i]
r.sort(reverse=True)
now = ans
for i in range(C):
now -= heappop(pq)
heappush(pq, r[i])
now += r[i]
ans = max(ans, now)
print(ans) | import sys
input = sys.stdin.readline
X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
l = p[:X]+q[:Y]
l.sort()
s = sum(l)
ans = s
pre = s
for i in range(min(len(l), C)):
ans = max(ans, pre-l[i]+r[i])
pre = pre-l[i]+r[i]
print(ans) | 31 | 21 | 564 | 426 | import sys
input = sys.stdin.readline
from heapq import *
X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
pq = []
ans = 0
for i in range(X):
heappush(pq, p[i])
ans += p[i]
for i in range(Y):
heappush(pq, q[i])
ans += q[i]
r.sort(reverse=True)
now = ans
for i in range(C):
now -= heappop(pq)
heappush(pq, r[i])
now += r[i]
ans = max(ans, now)
print(ans)
| import sys
input = sys.stdin.readline
X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
l = p[:X] + q[:Y]
l.sort()
s = sum(l)
ans = s
pre = s
for i in range(min(len(l), C)):
ans = max(ans, pre - l[i] + r[i])
pre = pre - l[i] + r[i]
print(ans)
| false | 32.258065 | [
"-from heapq import *",
"-",
"-pq = []",
"-ans = 0",
"-for i in range(X):",
"- heappush(pq, p[i])",
"- ans += p[i]",
"-for i in range(Y):",
"- heappush(pq, q[i])",
"- ans += q[i]",
"-now = ans",
"-for i in range(C):",
"- now -= heappop(pq)",
"- heappush(pq, r[i])",
"- now += r[i]",
"- ans = max(ans, now)",
"+l = p[:X] + q[:Y]",
"+l.sort()",
"+s = sum(l)",
"+ans = s",
"+pre = s",
"+for i in range(min(len(l), C)):",
"+ ans = max(ans, pre - l[i] + r[i])",
"+ pre = pre - l[i] + r[i]"
] | false | 0.112747 | 0.071791 | 1.570488 | [
"s398479082",
"s720731090"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.