user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
list | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
list |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u517910772 | p02813 | python | s903909332 | s031171971 | 109 | 17 | 8,948 | 3,064 | Accepted | Accepted | 84.4 | def abc150_c_count_order():
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
def solve(items, current):
if items == []:
permutations.append(current)
return
for item in items:
next = current + [item]
new_items = [i for i in items if i != item]
solve(new_items, next)
permutations = []
items = list(range(1, N+1))
current = []
solve(items, current)
a = permutations.index(P)
b = permutations.index(Q)
print((abs(a - b)))
##########
if __name__ == "__main__":
abc150_c_count_order()
| def abc150_c_count_order_2():
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
factorial = [1]
for i in range(1, N+1):
factorial.append(factorial[i-1] * i)
def find_index(permutation, lst):
indices = []
for p in permutation:
i = lst.index(p)
indices.append(i)
lst.pop(i)
# print(indices)
idx = 0
for i in range(N):
idx += factorial[N - i - 1] * (indices[i])
# print(idx)
return idx
a = find_index(P, list(range(1, N+1)))
b = find_index(Q, list(range(1, N+1)))
print((abs(a-b)))
##########
if __name__ == "__main__":
abc150_c_count_order_2()
| 27 | 29 | 673 | 763 | def abc150_c_count_order():
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
def solve(items, current):
if items == []:
permutations.append(current)
return
for item in items:
next = current + [item]
new_items = [i for i in items if i != item]
solve(new_items, next)
permutations = []
items = list(range(1, N + 1))
current = []
solve(items, current)
a = permutations.index(P)
b = permutations.index(Q)
print((abs(a - b)))
##########
if __name__ == "__main__":
abc150_c_count_order()
| def abc150_c_count_order_2():
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
factorial = [1]
for i in range(1, N + 1):
factorial.append(factorial[i - 1] * i)
def find_index(permutation, lst):
indices = []
for p in permutation:
i = lst.index(p)
indices.append(i)
lst.pop(i)
# print(indices)
idx = 0
for i in range(N):
idx += factorial[N - i - 1] * (indices[i])
# print(idx)
return idx
a = find_index(P, list(range(1, N + 1)))
b = find_index(Q, list(range(1, N + 1)))
print((abs(a - b)))
##########
if __name__ == "__main__":
abc150_c_count_order_2()
| false | 6.896552 | [
"-def abc150_c_count_order():",
"+def abc150_c_count_order_2():",
"+ factorial = [1]",
"+ for i in range(1, N + 1):",
"+ factorial.append(factorial[i - 1] * i)",
"- def solve(items, current):",
"- if items == []:",
"- permutations.append(current)",
"- return",
"- for item in items:",
"- next = current + [item]",
"- new_items = [i for i in items if i != item]",
"- solve(new_items, next)",
"+ def find_index(permutation, lst):",
"+ indices = []",
"+ for p in permutation:",
"+ i = lst.index(p)",
"+ indices.append(i)",
"+ lst.pop(i)",
"+ # print(indices)",
"+ idx = 0",
"+ for i in range(N):",
"+ idx += factorial[N - i - 1] * (indices[i])",
"+ # print(idx)",
"+ return idx",
"- permutations = []",
"- items = list(range(1, N + 1))",
"- current = []",
"- solve(items, current)",
"- a = permutations.index(P)",
"- b = permutations.index(Q)",
"+ a = find_index(P, list(range(1, N + 1)))",
"+ b = find_index(Q, list(range(1, N + 1)))",
"- abc150_c_count_order()",
"+ abc150_c_count_order_2()"
]
| false | 0.038413 | 0.042406 | 0.905843 | [
"s903909332",
"s031171971"
]
|
u263830634 | p02720 | python | s700097790 | s326941431 | 170 | 17 | 11,796 | 3,064 | Accepted | Accepted | 90 | import heapq
K =int(eval(input()))
pque = []
for i in range(1, 10):
heapq.heappush(pque, i)
for i in range(K):
tmp = heapq.heappop(pque)
if tmp % 10 == 0:
heapq.heappush(pque, tmp * 10)
heapq.heappush(pque, tmp * 10 + 1)
elif tmp % 10 == 9:
heapq.heappush(pque, tmp * 10 + 9)
heapq.heappush(pque, tmp * 10 + 8)
else:
next_ = tmp % 10
heapq.heappush(pque, tmp * 10 + next_ - 1)
heapq.heappush(pque, tmp * 10 + next_)
heapq.heappush(pque, tmp * 10 + next_ + 1)
print (tmp)
| K = int(eval(input()))
if K <= 9:
print (K)
exit()
lst = [[1] * 11 for _ in range(2)]
lst_append = lst.append
lst[0][10] = 0
lst[1][0] = 0
lst[1][10] = 0
now = 9
p = 0
flag = 0
while True:
if p == 0:
lst[flag + 1][0] = lst[flag][0] + lst[flag][1]
p += 1
continue
tmp = lst[flag][p - 1] + lst[flag][p] + lst[flag][p + 1]
lst[flag + 1][p] = tmp
if now + tmp >= K:
break
now += tmp
p += 1
if p == 10:
p = 0
flag += 1
lst_append([0] * 11)
# print ('now', now)
# print ('p', p)
# print ('flag', flag)
# print (lst[0])
# print (lst[1])
#ๅ
้ ญใpใงใใค็พๅจๅฐใnow
ans = str(p)
flag += 1
while True:
if flag == 0:
break
# print (p)
if p >= 1 and K <= now + lst[flag - 1][p - 1]:
flag -= 1
ans += str(p - 1)
p -= 1
elif K <= now + lst[flag - 1][p - 1] + lst[flag - 1][p]:
now += lst[flag - 1][p - 1]
flag -= 1
ans += str(p)
else:
now += lst[flag - 1][p - 1] + lst[flag - 1][p]
flag -= 1
ans += str(p + 1)
p += 1
print (ans)
# for tmp in lst:
# print (tmp)
| 26 | 64 | 605 | 1,209 | import heapq
K = int(eval(input()))
pque = []
for i in range(1, 10):
heapq.heappush(pque, i)
for i in range(K):
tmp = heapq.heappop(pque)
if tmp % 10 == 0:
heapq.heappush(pque, tmp * 10)
heapq.heappush(pque, tmp * 10 + 1)
elif tmp % 10 == 9:
heapq.heappush(pque, tmp * 10 + 9)
heapq.heappush(pque, tmp * 10 + 8)
else:
next_ = tmp % 10
heapq.heappush(pque, tmp * 10 + next_ - 1)
heapq.heappush(pque, tmp * 10 + next_)
heapq.heappush(pque, tmp * 10 + next_ + 1)
print(tmp)
| K = int(eval(input()))
if K <= 9:
print(K)
exit()
lst = [[1] * 11 for _ in range(2)]
lst_append = lst.append
lst[0][10] = 0
lst[1][0] = 0
lst[1][10] = 0
now = 9
p = 0
flag = 0
while True:
if p == 0:
lst[flag + 1][0] = lst[flag][0] + lst[flag][1]
p += 1
continue
tmp = lst[flag][p - 1] + lst[flag][p] + lst[flag][p + 1]
lst[flag + 1][p] = tmp
if now + tmp >= K:
break
now += tmp
p += 1
if p == 10:
p = 0
flag += 1
lst_append([0] * 11)
# print ('now', now)
# print ('p', p)
# print ('flag', flag)
# print (lst[0])
# print (lst[1])
# ๅ
้ ญใpใงใใค็พๅจๅฐใnow
ans = str(p)
flag += 1
while True:
if flag == 0:
break
# print (p)
if p >= 1 and K <= now + lst[flag - 1][p - 1]:
flag -= 1
ans += str(p - 1)
p -= 1
elif K <= now + lst[flag - 1][p - 1] + lst[flag - 1][p]:
now += lst[flag - 1][p - 1]
flag -= 1
ans += str(p)
else:
now += lst[flag - 1][p - 1] + lst[flag - 1][p]
flag -= 1
ans += str(p + 1)
p += 1
print(ans)
# for tmp in lst:
# print (tmp)
| false | 59.375 | [
"-import heapq",
"-",
"-pque = []",
"-for i in range(1, 10):",
"- heapq.heappush(pque, i)",
"-for i in range(K):",
"- tmp = heapq.heappop(pque)",
"- if tmp % 10 == 0:",
"- heapq.heappush(pque, tmp * 10)",
"- heapq.heappush(pque, tmp * 10 + 1)",
"- elif tmp % 10 == 9:",
"- heapq.heappush(pque, tmp * 10 + 9)",
"- heapq.heappush(pque, tmp * 10 + 8)",
"+if K <= 9:",
"+ print(K)",
"+ exit()",
"+lst = [[1] * 11 for _ in range(2)]",
"+lst_append = lst.append",
"+lst[0][10] = 0",
"+lst[1][0] = 0",
"+lst[1][10] = 0",
"+now = 9",
"+p = 0",
"+flag = 0",
"+while True:",
"+ if p == 0:",
"+ lst[flag + 1][0] = lst[flag][0] + lst[flag][1]",
"+ p += 1",
"+ continue",
"+ tmp = lst[flag][p - 1] + lst[flag][p] + lst[flag][p + 1]",
"+ lst[flag + 1][p] = tmp",
"+ if now + tmp >= K:",
"+ break",
"+ now += tmp",
"+ p += 1",
"+ if p == 10:",
"+ p = 0",
"+ flag += 1",
"+ lst_append([0] * 11)",
"+# print ('now', now)",
"+# print ('p', p)",
"+# print ('flag', flag)",
"+# print (lst[0])",
"+# print (lst[1])",
"+# ๅ
้ ญใpใงใใค็พๅจๅฐใnow",
"+ans = str(p)",
"+flag += 1",
"+while True:",
"+ if flag == 0:",
"+ break",
"+ # print (p)",
"+ if p >= 1 and K <= now + lst[flag - 1][p - 1]:",
"+ flag -= 1",
"+ ans += str(p - 1)",
"+ p -= 1",
"+ elif K <= now + lst[flag - 1][p - 1] + lst[flag - 1][p]:",
"+ now += lst[flag - 1][p - 1]",
"+ flag -= 1",
"+ ans += str(p)",
"- next_ = tmp % 10",
"- heapq.heappush(pque, tmp * 10 + next_ - 1)",
"- heapq.heappush(pque, tmp * 10 + next_)",
"- heapq.heappush(pque, tmp * 10 + next_ + 1)",
"-print(tmp)",
"+ now += lst[flag - 1][p - 1] + lst[flag - 1][p]",
"+ flag -= 1",
"+ ans += str(p + 1)",
"+ p += 1",
"+print(ans)",
"+# for tmp in lst:",
"+# print (tmp)"
]
| false | 0.215369 | 0.043684 | 4.93014 | [
"s700097790",
"s326941431"
]
|
u417365712 | p02574 | python | s328205883 | s739810940 | 1,441 | 431 | 366,452 | 232,224 | Accepted | Accepted | 70.09 | from math import gcd, sqrt
from functools import reduce
n, *A = list(map(int, open(0).read().split()))
def f(A):
sup = max(A)+1
table = [set() for i in range(sup)]
for i in range(2, sup):
if not table[i]:
for j in range(i, sup, i):
table[j].add(i)
D = set()
for a in A:
for b in table[a]:
if b not in D:
D.add(b)
else:
return False
return True
if reduce(gcd, A) == 1:
if f(A):
print('pairwise coprime')
else:
print('setwise coprime')
else:
print('not coprime') | from math import gcd, sqrt
from functools import reduce
n, *A = list(map(int, open(0).read().split()))
def f(A):
sup = max(A)+1
table = [i for i in range(sup)]
for i in range(2, int(sqrt(sup))+1):
if table[i] == i:
for j in range(i**2, sup, i):
table[j] = i
D = set()
for a in A:
while a != 1:
if a not in D:
D.add(a)
a //= table[a]
else:
return False
return True
if reduce(gcd, A) == 1:
if f(A):
print('pairwise coprime')
else:
print('setwise coprime')
else:
print('not coprime') | 27 | 29 | 634 | 673 | from math import gcd, sqrt
from functools import reduce
n, *A = list(map(int, open(0).read().split()))
def f(A):
sup = max(A) + 1
table = [set() for i in range(sup)]
for i in range(2, sup):
if not table[i]:
for j in range(i, sup, i):
table[j].add(i)
D = set()
for a in A:
for b in table[a]:
if b not in D:
D.add(b)
else:
return False
return True
if reduce(gcd, A) == 1:
if f(A):
print("pairwise coprime")
else:
print("setwise coprime")
else:
print("not coprime")
| from math import gcd, sqrt
from functools import reduce
n, *A = list(map(int, open(0).read().split()))
def f(A):
sup = max(A) + 1
table = [i for i in range(sup)]
for i in range(2, int(sqrt(sup)) + 1):
if table[i] == i:
for j in range(i**2, sup, i):
table[j] = i
D = set()
for a in A:
while a != 1:
if a not in D:
D.add(a)
a //= table[a]
else:
return False
return True
if reduce(gcd, A) == 1:
if f(A):
print("pairwise coprime")
else:
print("setwise coprime")
else:
print("not coprime")
| false | 6.896552 | [
"- table = [set() for i in range(sup)]",
"- for i in range(2, sup):",
"- if not table[i]:",
"- for j in range(i, sup, i):",
"- table[j].add(i)",
"+ table = [i for i in range(sup)]",
"+ for i in range(2, int(sqrt(sup)) + 1):",
"+ if table[i] == i:",
"+ for j in range(i**2, sup, i):",
"+ table[j] = i",
"- for b in table[a]:",
"- if b not in D:",
"- D.add(b)",
"+ while a != 1:",
"+ if a not in D:",
"+ D.add(a)",
"+ a //= table[a]"
]
| false | 0.087765 | 0.085392 | 1.027791 | [
"s328205883",
"s739810940"
]
|
u200571527 | p02859 | python | s149988782 | s960453703 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | x = eval(input())
sum = int(x) * int(x)
print(sum) | x = eval(input())
y = 2
print((int(x) ** y)) | 4 | 4 | 48 | 40 | x = eval(input())
sum = int(x) * int(x)
print(sum)
| x = eval(input())
y = 2
print((int(x) ** y))
| false | 0 | [
"-sum = int(x) * int(x)",
"-print(sum)",
"+y = 2",
"+print((int(x) ** y))"
]
| false | 0.088067 | 0.07711 | 1.142091 | [
"s149988782",
"s960453703"
]
|
u349091349 | p02659 | python | s315770547 | s784615021 | 134 | 61 | 71,016 | 61,856 | Accepted | Accepted | 54.48 | from decimal import *
a,b=input().split()
a = Decimal(a)
b = Decimal(b)
c = a*b
n = 0
ans =c.quantize(Decimal(str(10**(n*-1))), rounding = ROUND_DOWN)
print(ans) | a,b=input().split()
a=int(a)
b=int(b.replace(".",""))
print((a*b//100)) | 11 | 4 | 174 | 72 | from decimal import *
a, b = input().split()
a = Decimal(a)
b = Decimal(b)
c = a * b
n = 0
ans = c.quantize(Decimal(str(10 ** (n * -1))), rounding=ROUND_DOWN)
print(ans)
| a, b = input().split()
a = int(a)
b = int(b.replace(".", ""))
print((a * b // 100))
| false | 63.636364 | [
"-from decimal import *",
"-",
"-a = Decimal(a)",
"-b = Decimal(b)",
"-c = a * b",
"-n = 0",
"-ans = c.quantize(Decimal(str(10 ** (n * -1))), rounding=ROUND_DOWN)",
"-print(ans)",
"+a = int(a)",
"+b = int(b.replace(\".\", \"\"))",
"+print((a * b // 100))"
]
| false | 0.038474 | 0.056665 | 0.678977 | [
"s315770547",
"s784615021"
]
|
u796942881 | p03252 | python | s747427960 | s672188273 | 114 | 44 | 3,632 | 3,632 | Accepted | Accepted | 61.4 | def main():
S = eval(input())
T = eval(input())
lst = [""] * (ord("z") - ord("a") + 1)
flg = True
for s, t in zip(S, T):
# ๅใขใซใใกใใใใ้ใขใซใใกใใใๅคๆใใงใใฏ
if lst[ord(s) - ord("a")] and lst[ord(s) - ord("a")] != t:
flg = False
break
lst[ord(s) - ord("a")] = t
lst = [i for i in lst if i != ""]
# ๅคๆๅ
ใฎ้่คใใงใใฏ
if len(lst) != len(set(lst)):
flg = False
print(("Yes" if flg else "No"))
return
main()
| def main():
S = eval(input())
T = eval(input())
d = dict()
flg = True
for s, t in zip(S, T):
# ๅใขใซใใกใใใใ้ใขใซใใกใใใๅคๆใใงใใฏ
if s in d and d[s] != t:
flg = False
break
d[s] = t
# ๅคๆๅ
ใฎ้่คใใงใใฏ
if len(list(d.values())) != len(set(d.values())):
flg = False
print(("Yes" if flg else "No"))
return
main()
| 20 | 19 | 489 | 384 | def main():
S = eval(input())
T = eval(input())
lst = [""] * (ord("z") - ord("a") + 1)
flg = True
for s, t in zip(S, T):
# ๅใขใซใใกใใใใ้ใขใซใใกใใใๅคๆใใงใใฏ
if lst[ord(s) - ord("a")] and lst[ord(s) - ord("a")] != t:
flg = False
break
lst[ord(s) - ord("a")] = t
lst = [i for i in lst if i != ""]
# ๅคๆๅ
ใฎ้่คใใงใใฏ
if len(lst) != len(set(lst)):
flg = False
print(("Yes" if flg else "No"))
return
main()
| def main():
S = eval(input())
T = eval(input())
d = dict()
flg = True
for s, t in zip(S, T):
# ๅใขใซใใกใใใใ้ใขใซใใกใใใๅคๆใใงใใฏ
if s in d and d[s] != t:
flg = False
break
d[s] = t
# ๅคๆๅ
ใฎ้่คใใงใใฏ
if len(list(d.values())) != len(set(d.values())):
flg = False
print(("Yes" if flg else "No"))
return
main()
| false | 5 | [
"- lst = [\"\"] * (ord(\"z\") - ord(\"a\") + 1)",
"+ d = dict()",
"- if lst[ord(s) - ord(\"a\")] and lst[ord(s) - ord(\"a\")] != t:",
"+ if s in d and d[s] != t:",
"- lst[ord(s) - ord(\"a\")] = t",
"- lst = [i for i in lst if i != \"\"]",
"+ d[s] = t",
"- if len(lst) != len(set(lst)):",
"+ if len(list(d.values())) != len(set(d.values())):"
]
| false | 0.035315 | 0.089178 | 0.396008 | [
"s747427960",
"s672188273"
]
|
u562935282 | p03111 | python | s819729921 | s584807233 | 515 | 363 | 3,064 | 3,064 | Accepted | Accepted | 29.51 | inf = float('inf')
n, *goal = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
ans = inf
for q in range(4 ** n):
cost = -30
t = [0] * 3
for j in range(n):
idx = (q // (4 ** j)) % 4
if idx == 3: continue
t[idx] += l[j]
cost += 10
if any(tt == 0 for tt in t):
continue
for idx in range(3):
cost += abs(t[idx] - goal[idx])
ans = min(ans, cost)
print(ans)
| inf = float('inf')
def calc(mask):
cost = -30
t = [0] * 3
for j in range(n):
idx = (mask >> (2 * j)) & 3
if idx == 3: continue
t[idx] += l[j]
cost += 10
if 0 in t[:3]:
return inf
cost += sum(abs(tt - gg) for tt, gg in zip(t, goal))
return cost
def dfs(cur, mask):
# l[cur]ใa,b,c,ๆชไฝฟ็จใฎใใใใใซใใฆใใ
# base case
if cur == n:
return calc(mask)
res = inf
for i in range(4):
# i == 0,1,2 : a,b,cใซใใฆใใ / i == 3 : ๆชไฝฟ็จ
res = min(res, dfs(cur + 1, mask | i << (2 * cur)))
return res
n, *goal = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
print((dfs(0, 0)))
| 24 | 37 | 467 | 719 | inf = float("inf")
n, *goal = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
ans = inf
for q in range(4**n):
cost = -30
t = [0] * 3
for j in range(n):
idx = (q // (4**j)) % 4
if idx == 3:
continue
t[idx] += l[j]
cost += 10
if any(tt == 0 for tt in t):
continue
for idx in range(3):
cost += abs(t[idx] - goal[idx])
ans = min(ans, cost)
print(ans)
| inf = float("inf")
def calc(mask):
cost = -30
t = [0] * 3
for j in range(n):
idx = (mask >> (2 * j)) & 3
if idx == 3:
continue
t[idx] += l[j]
cost += 10
if 0 in t[:3]:
return inf
cost += sum(abs(tt - gg) for tt, gg in zip(t, goal))
return cost
def dfs(cur, mask):
# l[cur]ใa,b,c,ๆชไฝฟ็จใฎใใใใใซใใฆใใ
# base case
if cur == n:
return calc(mask)
res = inf
for i in range(4):
# i == 0,1,2 : a,b,cใซใใฆใใ / i == 3 : ๆชไฝฟ็จ
res = min(res, dfs(cur + 1, mask | i << (2 * cur)))
return res
n, *goal = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
print((dfs(0, 0)))
| false | 35.135135 | [
"-n, *goal = list(map(int, input().split()))",
"-l = [int(eval(input())) for _ in range(n)]",
"-ans = inf",
"-for q in range(4**n):",
"+",
"+",
"+def calc(mask):",
"- idx = (q // (4**j)) % 4",
"+ idx = (mask >> (2 * j)) & 3",
"- if any(tt == 0 for tt in t):",
"- continue",
"- for idx in range(3):",
"- cost += abs(t[idx] - goal[idx])",
"- ans = min(ans, cost)",
"-print(ans)",
"+ if 0 in t[:3]:",
"+ return inf",
"+ cost += sum(abs(tt - gg) for tt, gg in zip(t, goal))",
"+ return cost",
"+",
"+",
"+def dfs(cur, mask):",
"+ # l[cur]ใa,b,c,ๆชไฝฟ็จใฎใใใใใซใใฆใใ",
"+ # base case",
"+ if cur == n:",
"+ return calc(mask)",
"+ res = inf",
"+ for i in range(4):",
"+ # i == 0,1,2 : a,b,cใซใใฆใใ / i == 3 : ๆชไฝฟ็จ",
"+ res = min(res, dfs(cur + 1, mask | i << (2 * cur)))",
"+ return res",
"+",
"+",
"+n, *goal = list(map(int, input().split()))",
"+l = [int(eval(input())) for _ in range(n)]",
"+print((dfs(0, 0)))"
]
| false | 0.47908 | 0.192256 | 2.49189 | [
"s819729921",
"s584807233"
]
|
u864197622 | p02763 | python | s402848268 | s894360331 | 1,126 | 830 | 152,224 | 79,768 | Accepted | Accepted | 26.29 | N = int(eval(input()))
A = [ord(a) - 97 for a in eval(input())]
NN = 19
BIT=[[0]*(2**NN+1) for _ in range(26)]
def addbit(t, i, x):
while i <= 2**NN:
BIT[t][i] += x
i += i & (-i)
def getsum(t, i):
ret = 0
while i != 0:
ret += BIT[t][i]
i -= i&(-i)
return ret
for i, a in enumerate(A):
addbit(a, i+2, 1)
Q = int(eval(input()))
for _ in range(Q):
a, b, c = input().rstrip().split()
if a == "1":
b = int(b)
c = ord(c) - 97
t = A[b-1]
addbit(t, b+1, -1)
addbit(c, b+1, 1)
A[b-1] = c
else:
b, c = int(b), int(c)
s = 0
for t in range(26):
s += 1 if getsum(t, c+1) - getsum(t, b) else 0
print(s)
| NN = 19
X = [0] * ((1<<NN+1)-1)
def popcount(x):
x -= (x >> 1) & 0x55555555
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
x += x >> 8
x += x >> 16
return x & 0x3f
def update(a, x):
i = (1<<NN) - 1 + a
X[i] = x
while True:
i = (i-1) // 2
X[i] = X[2*i+1] | X[2*i+2]
if i == 0:
break
def rangeor(a, b):
l = a + (1<<NN)
r = b + (1<<NN)
x = 0
while l < r:
if l%2:
x |= X[l-1]
l += 1
if r%2:
r -= 1
x |= X[r-1]
l >>= 1
r >>= 1
return x
N = int(eval(input()))
A = [ord(a) - 97 for a in eval(input())]
for i, a in enumerate(A):
update(i+1, 1<<a)
Q = int(eval(input()))
for _ in range(Q):
a, b, c = input().rstrip().split()
if a == "1":
b = int(b)
c = ord(c) - 97
update(b, 1<<c)
else:
b, c = int(b), int(c)
print((popcount(rangeor(b, c+1)))) | 36 | 50 | 767 | 1,029 | N = int(eval(input()))
A = [ord(a) - 97 for a in eval(input())]
NN = 19
BIT = [[0] * (2**NN + 1) for _ in range(26)]
def addbit(t, i, x):
while i <= 2**NN:
BIT[t][i] += x
i += i & (-i)
def getsum(t, i):
ret = 0
while i != 0:
ret += BIT[t][i]
i -= i & (-i)
return ret
for i, a in enumerate(A):
addbit(a, i + 2, 1)
Q = int(eval(input()))
for _ in range(Q):
a, b, c = input().rstrip().split()
if a == "1":
b = int(b)
c = ord(c) - 97
t = A[b - 1]
addbit(t, b + 1, -1)
addbit(c, b + 1, 1)
A[b - 1] = c
else:
b, c = int(b), int(c)
s = 0
for t in range(26):
s += 1 if getsum(t, c + 1) - getsum(t, b) else 0
print(s)
| NN = 19
X = [0] * ((1 << NN + 1) - 1)
def popcount(x):
x -= (x >> 1) & 0x55555555
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0F0F0F0F
x += x >> 8
x += x >> 16
return x & 0x3F
def update(a, x):
i = (1 << NN) - 1 + a
X[i] = x
while True:
i = (i - 1) // 2
X[i] = X[2 * i + 1] | X[2 * i + 2]
if i == 0:
break
def rangeor(a, b):
l = a + (1 << NN)
r = b + (1 << NN)
x = 0
while l < r:
if l % 2:
x |= X[l - 1]
l += 1
if r % 2:
r -= 1
x |= X[r - 1]
l >>= 1
r >>= 1
return x
N = int(eval(input()))
A = [ord(a) - 97 for a in eval(input())]
for i, a in enumerate(A):
update(i + 1, 1 << a)
Q = int(eval(input()))
for _ in range(Q):
a, b, c = input().rstrip().split()
if a == "1":
b = int(b)
c = ord(c) - 97
update(b, 1 << c)
else:
b, c = int(b), int(c)
print((popcount(rangeor(b, c + 1))))
| false | 28 | [
"+NN = 19",
"+X = [0] * ((1 << NN + 1) - 1)",
"+",
"+",
"+def popcount(x):",
"+ x -= (x >> 1) & 0x55555555",
"+ x = (x & 0x33333333) + ((x >> 2) & 0x33333333)",
"+ x = (x + (x >> 4)) & 0x0F0F0F0F",
"+ x += x >> 8",
"+ x += x >> 16",
"+ return x & 0x3F",
"+",
"+",
"+def update(a, x):",
"+ i = (1 << NN) - 1 + a",
"+ X[i] = x",
"+ while True:",
"+ i = (i - 1) // 2",
"+ X[i] = X[2 * i + 1] | X[2 * i + 2]",
"+ if i == 0:",
"+ break",
"+",
"+",
"+def rangeor(a, b):",
"+ l = a + (1 << NN)",
"+ r = b + (1 << NN)",
"+ x = 0",
"+ while l < r:",
"+ if l % 2:",
"+ x |= X[l - 1]",
"+ l += 1",
"+ if r % 2:",
"+ r -= 1",
"+ x |= X[r - 1]",
"+ l >>= 1",
"+ r >>= 1",
"+ return x",
"+",
"+",
"-NN = 19",
"-BIT = [[0] * (2**NN + 1) for _ in range(26)]",
"-",
"-",
"-def addbit(t, i, x):",
"- while i <= 2**NN:",
"- BIT[t][i] += x",
"- i += i & (-i)",
"-",
"-",
"-def getsum(t, i):",
"- ret = 0",
"- while i != 0:",
"- ret += BIT[t][i]",
"- i -= i & (-i)",
"- return ret",
"-",
"-",
"- addbit(a, i + 2, 1)",
"+ update(i + 1, 1 << a)",
"- t = A[b - 1]",
"- addbit(t, b + 1, -1)",
"- addbit(c, b + 1, 1)",
"- A[b - 1] = c",
"+ update(b, 1 << c)",
"- s = 0",
"- for t in range(26):",
"- s += 1 if getsum(t, c + 1) - getsum(t, b) else 0",
"- print(s)",
"+ print((popcount(rangeor(b, c + 1))))"
]
| false | 0.040514 | 0.058924 | 0.687571 | [
"s402848268",
"s894360331"
]
|
u627803856 | p03993 | python | s669800287 | s071917947 | 248 | 208 | 62,316 | 53,292 | Accepted | Accepted | 16.13 | n = int(eval(input()))
a = [0] + list(map(int, input().split()))
G = [[] for _ in range(n + 1)]
for i in range(1, n + 1):
G[a[i]].append(i)
cnt = 0
for i in range(1, n + 1):
if a[i] in G[i] and i in G[a[i]]:
cnt += 1
print((cnt // 2)) | n = int(eval(input()))
a = [0] + list(map(int, input().split()))
cnt = 0
for i in range(1, n + 1):
if a[a[i]] == i:
cnt += 1
print((cnt // 2)) | 13 | 9 | 245 | 147 | n = int(eval(input()))
a = [0] + list(map(int, input().split()))
G = [[] for _ in range(n + 1)]
for i in range(1, n + 1):
G[a[i]].append(i)
cnt = 0
for i in range(1, n + 1):
if a[i] in G[i] and i in G[a[i]]:
cnt += 1
print((cnt // 2))
| n = int(eval(input()))
a = [0] + list(map(int, input().split()))
cnt = 0
for i in range(1, n + 1):
if a[a[i]] == i:
cnt += 1
print((cnt // 2))
| false | 30.769231 | [
"-G = [[] for _ in range(n + 1)]",
"-for i in range(1, n + 1):",
"- G[a[i]].append(i)",
"- if a[i] in G[i] and i in G[a[i]]:",
"+ if a[a[i]] == i:"
]
| false | 0.038702 | 0.038196 | 1.01325 | [
"s669800287",
"s071917947"
]
|
u764860452 | p02837 | python | s595792664 | s097947176 | 89 | 81 | 9,076 | 9,216 | Accepted | Accepted | 8.99 | from itertools import product
N=int(eval(input()))
datas=[]
for i in range(N):
A=int(eval(input()))
for j in range(A):
x,y=list(map(int,input().split()))
datas.append((i,x-1,y))
#print(datas)
ans=0
for i in product([0,1],repeat=N):
ok=True
for j in datas:
if (i[j[0]]==1 and i[j[1]]!=j[2]):
ok=False
break
if ok:
ans=sum(i)
print(ans) | from itertools import product
N=int(eval(input()))
datas=[]
for i in range(N):
A=int(eval(input()))
for j in range(A):
x,y=list(map(int,input().split()))
datas.append((i,x-1,y)) #่ชฐใใ่ชฐใซใใฉใๅคๆญใใ๏ผ
#print(datas)
ans=0
for i in product([0,1],repeat=N):
ok=True
for j in datas:
if i[j[0]]==1 and i[j[1]]!=j[2]:
ok=False
break
if ok:
ans=max(ans,sum(i))
print(ans) | 22 | 22 | 416 | 438 | from itertools import product
N = int(eval(input()))
datas = []
for i in range(N):
A = int(eval(input()))
for j in range(A):
x, y = list(map(int, input().split()))
datas.append((i, x - 1, y))
# print(datas)
ans = 0
for i in product([0, 1], repeat=N):
ok = True
for j in datas:
if i[j[0]] == 1 and i[j[1]] != j[2]:
ok = False
break
if ok:
ans = sum(i)
print(ans)
| from itertools import product
N = int(eval(input()))
datas = []
for i in range(N):
A = int(eval(input()))
for j in range(A):
x, y = list(map(int, input().split()))
datas.append((i, x - 1, y)) # ่ชฐใใ่ชฐใซใใฉใๅคๆญใใ๏ผ
# print(datas)
ans = 0
for i in product([0, 1], repeat=N):
ok = True
for j in datas:
if i[j[0]] == 1 and i[j[1]] != j[2]:
ok = False
break
if ok:
ans = max(ans, sum(i))
print(ans)
| false | 0 | [
"- datas.append((i, x - 1, y))",
"+ datas.append((i, x - 1, y)) # ่ชฐใใ่ชฐใซใใฉใๅคๆญใใ๏ผ",
"- ans = sum(i)",
"+ ans = max(ans, sum(i))"
]
| false | 0.047148 | 0.046866 | 1.006014 | [
"s595792664",
"s097947176"
]
|
u353855427 | p03048 | python | s306336692 | s657845508 | 1,865 | 278 | 3,060 | 40,940 | Accepted | Accepted | 85.09 | import math
R,G,B,N = list(map(int,input().split()))
cnt = 0
for i in range(math.ceil(N/G)+1):
for j in range(math.ceil(N/R)+1):
tmp = N - i * G - j * R
if tmp < 0:
break
if tmp % B == 0:
cnt += 1
print(cnt) | import math
R,G,B,N = list(map(int,input().split()))
cnt = 0
for i in range(math.ceil(N/G)+1):
for j in range(math.ceil(N/R)+1):
tmp = N - i * G - j * R
if tmp >=0 and tmp % B == 0:
cnt += 1
print(cnt) | 11 | 9 | 229 | 215 | import math
R, G, B, N = list(map(int, input().split()))
cnt = 0
for i in range(math.ceil(N / G) + 1):
for j in range(math.ceil(N / R) + 1):
tmp = N - i * G - j * R
if tmp < 0:
break
if tmp % B == 0:
cnt += 1
print(cnt)
| import math
R, G, B, N = list(map(int, input().split()))
cnt = 0
for i in range(math.ceil(N / G) + 1):
for j in range(math.ceil(N / R) + 1):
tmp = N - i * G - j * R
if tmp >= 0 and tmp % B == 0:
cnt += 1
print(cnt)
| false | 18.181818 | [
"- if tmp < 0:",
"- break",
"- if tmp % B == 0:",
"+ if tmp >= 0 and tmp % B == 0:"
]
| false | 0.067546 | 0.088245 | 0.765434 | [
"s306336692",
"s657845508"
]
|
u153665391 | p02277 | python | s672330183 | s330667112 | 1,580 | 1,300 | 39,444 | 19,228 | Accepted | Accepted | 17.72 | import copy
def partition(p, r):
i = p
for j in range(p, r):
if A[r][1] >= A[j][1]:
A[i], A[j] = A[j], A[i]
i += 1
A[r], A[i] = A[i], A[r]
return i
def quick_sort(p, r):
if p < r:
q = partition(p, r)
quick_sort(p, q-1)
quick_sort(q+1, r)
def correct_same_num_suits(l, num, first):
suits = []
for i in range(first, N):
if num == l[i][1]:
suits.append(l[i][0])
return suits
def is_stable():
idx = 0
while idx < N-1:
idx_incr_flg = True
if A[idx][1] == A[idx+1][1]:
num = A[idx][1]
sorted_suits = correct_same_num_suits(A, num, idx)
orig_suits = correct_same_num_suits(orig_list, num, 0)
if sorted_suits != orig_suits:
return False
idx += len(sorted_suits)
idx_incr_flg = False
if idx_incr_flg:
idx += 1
return True
N = int(eval(input()))
A = []
for _ in range(N):
suit, num = input().split()
num = int(num)
A.append([suit, num])
orig_list = copy.deepcopy(A)
quick_sort(0, N-1)
is_stable = is_stable()
if is_stable:
print("Stable")
else:
print("Not stable")
for card in A:
print(("%s %d" % (card[0], card[1])))
| import copy
def partition(p, r):
i = p
for j in range(p, r):
if A[r][1] >= A[j][1]:
A[i], A[j] = A[j], A[i]
i += 1
A[r], A[i] = A[i], A[r]
return i
def quick_sort(p, r):
if p < r:
q = partition(p, r)
quick_sort(p, q-1)
quick_sort(q+1, r)
def is_stable():
for i in range(N-1):
if A[i][1] == A[i+1][1]:
small_idx, large_idx = 0, 0
for j in range(N):
if A[i] == orig_list[j]:
small_idx = j
elif A[i+1] == orig_list[j]:
large_idx = j
if small_idx > large_idx:
return False
return True
N = int(eval(input()))
A = []
for _ in range(N):
suit, num = input().split()
num = int(num)
A.append([suit, num])
orig_list = copy.copy(A)
quick_sort(0, N-1)
is_stable = is_stable()
if is_stable:
print("Stable")
else:
print("Not stable")
for card in A:
print(("%s %d" % (card[0], card[1])))
| 59 | 49 | 1,335 | 1,060 | import copy
def partition(p, r):
i = p
for j in range(p, r):
if A[r][1] >= A[j][1]:
A[i], A[j] = A[j], A[i]
i += 1
A[r], A[i] = A[i], A[r]
return i
def quick_sort(p, r):
if p < r:
q = partition(p, r)
quick_sort(p, q - 1)
quick_sort(q + 1, r)
def correct_same_num_suits(l, num, first):
suits = []
for i in range(first, N):
if num == l[i][1]:
suits.append(l[i][0])
return suits
def is_stable():
idx = 0
while idx < N - 1:
idx_incr_flg = True
if A[idx][1] == A[idx + 1][1]:
num = A[idx][1]
sorted_suits = correct_same_num_suits(A, num, idx)
orig_suits = correct_same_num_suits(orig_list, num, 0)
if sorted_suits != orig_suits:
return False
idx += len(sorted_suits)
idx_incr_flg = False
if idx_incr_flg:
idx += 1
return True
N = int(eval(input()))
A = []
for _ in range(N):
suit, num = input().split()
num = int(num)
A.append([suit, num])
orig_list = copy.deepcopy(A)
quick_sort(0, N - 1)
is_stable = is_stable()
if is_stable:
print("Stable")
else:
print("Not stable")
for card in A:
print(("%s %d" % (card[0], card[1])))
| import copy
def partition(p, r):
i = p
for j in range(p, r):
if A[r][1] >= A[j][1]:
A[i], A[j] = A[j], A[i]
i += 1
A[r], A[i] = A[i], A[r]
return i
def quick_sort(p, r):
if p < r:
q = partition(p, r)
quick_sort(p, q - 1)
quick_sort(q + 1, r)
def is_stable():
for i in range(N - 1):
if A[i][1] == A[i + 1][1]:
small_idx, large_idx = 0, 0
for j in range(N):
if A[i] == orig_list[j]:
small_idx = j
elif A[i + 1] == orig_list[j]:
large_idx = j
if small_idx > large_idx:
return False
return True
N = int(eval(input()))
A = []
for _ in range(N):
suit, num = input().split()
num = int(num)
A.append([suit, num])
orig_list = copy.copy(A)
quick_sort(0, N - 1)
is_stable = is_stable()
if is_stable:
print("Stable")
else:
print("Not stable")
for card in A:
print(("%s %d" % (card[0], card[1])))
| false | 16.949153 | [
"-def correct_same_num_suits(l, num, first):",
"- suits = []",
"- for i in range(first, N):",
"- if num == l[i][1]:",
"- suits.append(l[i][0])",
"- return suits",
"-",
"-",
"- idx = 0",
"- while idx < N - 1:",
"- idx_incr_flg = True",
"- if A[idx][1] == A[idx + 1][1]:",
"- num = A[idx][1]",
"- sorted_suits = correct_same_num_suits(A, num, idx)",
"- orig_suits = correct_same_num_suits(orig_list, num, 0)",
"- if sorted_suits != orig_suits:",
"+ for i in range(N - 1):",
"+ if A[i][1] == A[i + 1][1]:",
"+ small_idx, large_idx = 0, 0",
"+ for j in range(N):",
"+ if A[i] == orig_list[j]:",
"+ small_idx = j",
"+ elif A[i + 1] == orig_list[j]:",
"+ large_idx = j",
"+ if small_idx > large_idx:",
"- idx += len(sorted_suits)",
"- idx_incr_flg = False",
"- if idx_incr_flg:",
"- idx += 1",
"-orig_list = copy.deepcopy(A)",
"+orig_list = copy.copy(A)"
]
| false | 0.039637 | 0.04101 | 0.966514 | [
"s672330183",
"s330667112"
]
|
u651109406 | p02678 | python | s014925351 | s694091672 | 766 | 557 | 104,492 | 99,288 | Accepted | Accepted | 27.28 | from collections import deque
class UnionFind:
def __init__(self, N):
self.parents = [-1 for i in range(N)]
self.unit = [0 for i in range(N)]
def find(self, x):
if self.parents[x] < 0:
return x
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x, y = self.find(x), self.find(y)
if x == y:
return
if x > y:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
N, M = list(map(int, input().split()))
uf = UnionFind(N)
lists = [False for i in range(N)]
lists[0] = True
a = N - 1
dicts = {i:[] for i in range(N)}
d = deque([0])
for i in range(M):
tmpa, tmpb = [int(x) - 1 for x in input().split()]
dicts[tmpa] += [tmpb]
dicts[tmpb] += [tmpa]
uf.union(tmpa, tmpb)
if -uf.parents[0] == N:
print('Yes')
while a > 0:
tmp = d.popleft()
for i in dicts[tmp]:
if not lists[i]:
if tmp != 0:
lists[i] = tmp
else:
lists[i] = -1
d.append(i)
a -= 1
for i in range(1, N):
print((lists[i] + 1 if lists[i] != -1 else 1))
else:
print('No')
| from collections import deque
N, M = list(map(int, input().split()))
lists = [False for i in range(N)]
lists[0] = True
a = N - 1
dicts = {i:[] for i in range(N)}
d = deque([0])
for i in range(M):
tmpa, tmpb = [int(x) - 1 for x in input().split()]
dicts[tmpa] += [tmpb]
dicts[tmpb] += [tmpa]
print('Yes')
while a > 0:
tmp = d.popleft()
for i in dicts[tmp]:
if not lists[i]:
if tmp != 0:
lists[i] = tmp
else:
lists[i] = -1
d.append(i)
a -= 1
for i in range(1, N):
print((lists[i] + 1 if lists[i] != -1 else 1))
| 55 | 28 | 1,359 | 654 | from collections import deque
class UnionFind:
def __init__(self, N):
self.parents = [-1 for i in range(N)]
self.unit = [0 for i in range(N)]
def find(self, x):
if self.parents[x] < 0:
return x
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x, y = self.find(x), self.find(y)
if x == y:
return
if x > y:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
N, M = list(map(int, input().split()))
uf = UnionFind(N)
lists = [False for i in range(N)]
lists[0] = True
a = N - 1
dicts = {i: [] for i in range(N)}
d = deque([0])
for i in range(M):
tmpa, tmpb = [int(x) - 1 for x in input().split()]
dicts[tmpa] += [tmpb]
dicts[tmpb] += [tmpa]
uf.union(tmpa, tmpb)
if -uf.parents[0] == N:
print("Yes")
while a > 0:
tmp = d.popleft()
for i in dicts[tmp]:
if not lists[i]:
if tmp != 0:
lists[i] = tmp
else:
lists[i] = -1
d.append(i)
a -= 1
for i in range(1, N):
print((lists[i] + 1 if lists[i] != -1 else 1))
else:
print("No")
| from collections import deque
N, M = list(map(int, input().split()))
lists = [False for i in range(N)]
lists[0] = True
a = N - 1
dicts = {i: [] for i in range(N)}
d = deque([0])
for i in range(M):
tmpa, tmpb = [int(x) - 1 for x in input().split()]
dicts[tmpa] += [tmpb]
dicts[tmpb] += [tmpa]
print("Yes")
while a > 0:
tmp = d.popleft()
for i in dicts[tmp]:
if not lists[i]:
if tmp != 0:
lists[i] = tmp
else:
lists[i] = -1
d.append(i)
a -= 1
for i in range(1, N):
print((lists[i] + 1 if lists[i] != -1 else 1))
| false | 49.090909 | [
"-",
"-class UnionFind:",
"- def __init__(self, N):",
"- self.parents = [-1 for i in range(N)]",
"- self.unit = [0 for i in range(N)]",
"-",
"- def find(self, x):",
"- if self.parents[x] < 0:",
"- return x",
"- self.parents[x] = self.find(self.parents[x])",
"- return self.parents[x]",
"-",
"- def union(self, x, y):",
"- x, y = self.find(x), self.find(y)",
"- if x == y:",
"- return",
"- if x > y:",
"- x, y = y, x",
"- self.parents[x] += self.parents[y]",
"- self.parents[y] = x",
"-",
"-",
"-uf = UnionFind(N)",
"- uf.union(tmpa, tmpb)",
"-if -uf.parents[0] == N:",
"- print(\"Yes\")",
"- while a > 0:",
"- tmp = d.popleft()",
"- for i in dicts[tmp]:",
"- if not lists[i]:",
"- if tmp != 0:",
"- lists[i] = tmp",
"- else:",
"- lists[i] = -1",
"- d.append(i)",
"- a -= 1",
"- for i in range(1, N):",
"- print((lists[i] + 1 if lists[i] != -1 else 1))",
"-else:",
"- print(\"No\")",
"+print(\"Yes\")",
"+while a > 0:",
"+ tmp = d.popleft()",
"+ for i in dicts[tmp]:",
"+ if not lists[i]:",
"+ if tmp != 0:",
"+ lists[i] = tmp",
"+ else:",
"+ lists[i] = -1",
"+ d.append(i)",
"+ a -= 1",
"+for i in range(1, N):",
"+ print((lists[i] + 1 if lists[i] != -1 else 1))"
]
| false | 0.041655 | 0.078011 | 0.533956 | [
"s014925351",
"s694091672"
]
|
u546338822 | p02848 | python | s495985515 | s059535044 | 24 | 20 | 3,060 | 3,188 | Accepted | Accepted | 16.67 | N = int(eval(input()))
S = eval(input())
s=[]
for i in range(len(S)):
if ord(S[i])+N >= 91:
j = (ord(S[i])+N -65)%26+65
s.append(chr(j))
else:
s.append(chr(ord(S[i])+N))
print((''.join(s))) | n = int(eval(input()))
S = eval(input())
ol = [(ord(s)+n-65)%26+65 for s in S]
st = [chr(o) for o in ol]
print((''.join(st))) | 11 | 6 | 202 | 117 | N = int(eval(input()))
S = eval(input())
s = []
for i in range(len(S)):
if ord(S[i]) + N >= 91:
j = (ord(S[i]) + N - 65) % 26 + 65
s.append(chr(j))
else:
s.append(chr(ord(S[i]) + N))
print(("".join(s)))
| n = int(eval(input()))
S = eval(input())
ol = [(ord(s) + n - 65) % 26 + 65 for s in S]
st = [chr(o) for o in ol]
print(("".join(st)))
| false | 45.454545 | [
"-N = int(eval(input()))",
"+n = int(eval(input()))",
"-s = []",
"-for i in range(len(S)):",
"- if ord(S[i]) + N >= 91:",
"- j = (ord(S[i]) + N - 65) % 26 + 65",
"- s.append(chr(j))",
"- else:",
"- s.append(chr(ord(S[i]) + N))",
"-print((\"\".join(s)))",
"+ol = [(ord(s) + n - 65) % 26 + 65 for s in S]",
"+st = [chr(o) for o in ol]",
"+print((\"\".join(st)))"
]
| false | 0.038484 | 0.076687 | 0.501827 | [
"s495985515",
"s059535044"
]
|
u426534722 | p02317 | python | s518865439 | s338472606 | 320 | 280 | 12,304 | 13,316 | Accepted | Accepted | 12.5 | import bisect
n = int(eval(input()))
A = [int(eval(input())) for j in range(n)]
dp = [A[0]]
for i in range(1, n):
if dp[-1] < A[i]:
dp.append(A[i])
else:
dp[bisect.bisect_left(dp, A[i])] = A[i]
print((len(dp))) | import bisect
n = int(eval(input()))
A = [int(eval(input())) for j in range(n)]
dp = A[:1]
for a_i in A[1:]:
if dp[-1] < a_i:
dp.append(a_i)
else:
dp[bisect.bisect_left(dp, a_i)] = a_i
print((len(dp))) | 10 | 10 | 229 | 220 | import bisect
n = int(eval(input()))
A = [int(eval(input())) for j in range(n)]
dp = [A[0]]
for i in range(1, n):
if dp[-1] < A[i]:
dp.append(A[i])
else:
dp[bisect.bisect_left(dp, A[i])] = A[i]
print((len(dp)))
| import bisect
n = int(eval(input()))
A = [int(eval(input())) for j in range(n)]
dp = A[:1]
for a_i in A[1:]:
if dp[-1] < a_i:
dp.append(a_i)
else:
dp[bisect.bisect_left(dp, a_i)] = a_i
print((len(dp)))
| false | 0 | [
"-dp = [A[0]]",
"-for i in range(1, n):",
"- if dp[-1] < A[i]:",
"- dp.append(A[i])",
"+dp = A[:1]",
"+for a_i in A[1:]:",
"+ if dp[-1] < a_i:",
"+ dp.append(a_i)",
"- dp[bisect.bisect_left(dp, A[i])] = A[i]",
"+ dp[bisect.bisect_left(dp, a_i)] = a_i"
]
| false | 0.042672 | 0.007544 | 5.656296 | [
"s518865439",
"s338472606"
]
|
u380524497 | p02716 | python | s767544901 | s725613817 | 558 | 481 | 31,492 | 31,632 | Accepted | Accepted | 13.8 | n = int(eval(input()))
A = list(map(int, input().split()))
pick_DP = [-float('INF')] * n
unpick_DP = [-float('INF')] * n
pick_DP[0] = 0
unpick_DP[0] = 0
for i, a in enumerate(A, 1):
mini = (i-1)//2 - 1
if mini <= 0:
mini = 1
maxi = (i+1)//2
temp = []
for num in range(mini, maxi+1):
temp.append(pick_DP[num])
pick_DP[num] = max(unpick_DP[num-1] + a, pick_DP[num])
for num, pre_pick in enumerate(temp, mini):
if unpick_DP[num] < pre_pick:
unpick_DP[num] = pre_pick
print((max(pick_DP[n//2], unpick_DP[n//2]))) | n = int(eval(input()))
A = list(map(int, input().split()))
pick_DP = [-float('INF')] * (n//2 + 2)
unpick_DP = [-float('INF')] * (n//2 + 2)
pick_DP[0] = 0
unpick_DP[0] = 0
for i, a in enumerate(A, 1):
mini = (i-1)//2 - 1
if mini <= 0:
mini = 1
maxi = (i+1)//2
for num in range(maxi, mini-1, -1):
if unpick_DP[num] < pick_DP[num]:
unpick_DP[num] = pick_DP[num]
pick_DP[num] = max(unpick_DP[num-1] + a, pick_DP[num])
print((max(pick_DP[n//2], unpick_DP[n//2]))) | 24 | 20 | 596 | 525 | n = int(eval(input()))
A = list(map(int, input().split()))
pick_DP = [-float("INF")] * n
unpick_DP = [-float("INF")] * n
pick_DP[0] = 0
unpick_DP[0] = 0
for i, a in enumerate(A, 1):
mini = (i - 1) // 2 - 1
if mini <= 0:
mini = 1
maxi = (i + 1) // 2
temp = []
for num in range(mini, maxi + 1):
temp.append(pick_DP[num])
pick_DP[num] = max(unpick_DP[num - 1] + a, pick_DP[num])
for num, pre_pick in enumerate(temp, mini):
if unpick_DP[num] < pre_pick:
unpick_DP[num] = pre_pick
print((max(pick_DP[n // 2], unpick_DP[n // 2])))
| n = int(eval(input()))
A = list(map(int, input().split()))
pick_DP = [-float("INF")] * (n // 2 + 2)
unpick_DP = [-float("INF")] * (n // 2 + 2)
pick_DP[0] = 0
unpick_DP[0] = 0
for i, a in enumerate(A, 1):
mini = (i - 1) // 2 - 1
if mini <= 0:
mini = 1
maxi = (i + 1) // 2
for num in range(maxi, mini - 1, -1):
if unpick_DP[num] < pick_DP[num]:
unpick_DP[num] = pick_DP[num]
pick_DP[num] = max(unpick_DP[num - 1] + a, pick_DP[num])
print((max(pick_DP[n // 2], unpick_DP[n // 2])))
| false | 16.666667 | [
"-pick_DP = [-float(\"INF\")] * n",
"-unpick_DP = [-float(\"INF\")] * n",
"+pick_DP = [-float(\"INF\")] * (n // 2 + 2)",
"+unpick_DP = [-float(\"INF\")] * (n // 2 + 2)",
"- temp = []",
"- for num in range(mini, maxi + 1):",
"- temp.append(pick_DP[num])",
"+ for num in range(maxi, mini - 1, -1):",
"+ if unpick_DP[num] < pick_DP[num]:",
"+ unpick_DP[num] = pick_DP[num]",
"- for num, pre_pick in enumerate(temp, mini):",
"- if unpick_DP[num] < pre_pick:",
"- unpick_DP[num] = pre_pick"
]
| false | 0.035459 | 0.042271 | 0.838858 | [
"s767544901",
"s725613817"
]
|
u606045429 | p03725 | python | s547672308 | s846704357 | 1,954 | 1,782 | 9,332 | 9,204 | Accepted | Accepted | 8.8 | from collections import deque
INF = float("inf")
H, W, K = list(map(int, input().split()))
A = [list(eval(input())) for _ in range(H)]
Si, Sj = (0, 0)
for i, a in enumerate(A):
if "S" in a:
Si, Sj = (i, a.index("S"))
break
distance = INF
Q = deque([(0, Si, Sj)])
while Q:
dist, i, j = Q.popleft()
if dist > K:
break
distance = min(distance, i, j, H - i - 1, W - j - 1)
for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
ni, nj = i + di, j + dj
if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":
A[ni][nj] = "#"
Q.append((dist + 1, ni, nj))
print((-(-distance // K) + 1))
| from collections import deque
INF = float("inf")
H, W, K = list(map(int, input().split()))
A = [list(eval(input())) for _ in range(H)]
Si, Sj = (0, 0)
for i, a in enumerate(A):
if "S" in a:
Si, Sj = (i, a.index("S"))
break
distance = INF
Q = deque([(0, Si, Sj)])
while Q:
cnt, i, j = Q.popleft()
distance = min(distance, i, j, H - i - 1, W - j - 1)
if cnt >= K:
continue
for ni, nj in ((i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)):
if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":
A[ni][nj] = "#"
Q.append((cnt + 1, ni, nj))
print((-(-distance // K) + 1))
| 30 | 30 | 679 | 663 | from collections import deque
INF = float("inf")
H, W, K = list(map(int, input().split()))
A = [list(eval(input())) for _ in range(H)]
Si, Sj = (0, 0)
for i, a in enumerate(A):
if "S" in a:
Si, Sj = (i, a.index("S"))
break
distance = INF
Q = deque([(0, Si, Sj)])
while Q:
dist, i, j = Q.popleft()
if dist > K:
break
distance = min(distance, i, j, H - i - 1, W - j - 1)
for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
ni, nj = i + di, j + dj
if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":
A[ni][nj] = "#"
Q.append((dist + 1, ni, nj))
print((-(-distance // K) + 1))
| from collections import deque
INF = float("inf")
H, W, K = list(map(int, input().split()))
A = [list(eval(input())) for _ in range(H)]
Si, Sj = (0, 0)
for i, a in enumerate(A):
if "S" in a:
Si, Sj = (i, a.index("S"))
break
distance = INF
Q = deque([(0, Si, Sj)])
while Q:
cnt, i, j = Q.popleft()
distance = min(distance, i, j, H - i - 1, W - j - 1)
if cnt >= K:
continue
for ni, nj in ((i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)):
if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":
A[ni][nj] = "#"
Q.append((cnt + 1, ni, nj))
print((-(-distance // K) + 1))
| false | 0 | [
"- dist, i, j = Q.popleft()",
"- if dist > K:",
"- break",
"+ cnt, i, j = Q.popleft()",
"- for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):",
"- ni, nj = i + di, j + dj",
"+ if cnt >= K:",
"+ continue",
"+ for ni, nj in ((i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)):",
"- Q.append((dist + 1, ni, nj))",
"+ Q.append((cnt + 1, ni, nj))"
]
| false | 0.088717 | 0.035786 | 2.479135 | [
"s547672308",
"s846704357"
]
|
u263737105 | p02595 | python | s479170385 | s111558385 | 391 | 194 | 9,124 | 9,120 | Accepted | Accepted | 50.38 | N, D = list(map(int, input().split()))
count = 0
for i in range(N):
a, b = list(map(int, input().split()))
if (a*a + b*b) <= D*D:
count += 1
print(count)
| import sys
input = sys.stdin.readline
N, D = list(map(int, input().split()))
count = 0
for i in range(N):
a, b = list(map(int, input().split()))
if (a*a + b*b) <= D*D:
count += 1
print(count)
| 7 | 9 | 164 | 204 | N, D = list(map(int, input().split()))
count = 0
for i in range(N):
a, b = list(map(int, input().split()))
if (a * a + b * b) <= D * D:
count += 1
print(count)
| import sys
input = sys.stdin.readline
N, D = list(map(int, input().split()))
count = 0
for i in range(N):
a, b = list(map(int, input().split()))
if (a * a + b * b) <= D * D:
count += 1
print(count)
| false | 22.222222 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
]
| false | 0.086904 | 0.094841 | 0.916316 | [
"s479170385",
"s111558385"
]
|
u077291787 | p03721 | python | s209946964 | s377508719 | 196 | 147 | 30,172 | 5,740 | Accepted | Accepted | 25 | # ABC061C - Big Array
import sys
input = sys.stdin.readline
def main():
n, k = list(map(int, input().rstrip().split()))
arr = [list(map(int, input().rstrip().split())) for _ in range(n)]
memo = [0] * (10 ** 5 + 1)
for i, j in arr:
memo[i] += j
cnt = 0
for i, j in enumerate(memo):
cnt += j
if cnt >= k:
print(i)
break
if __name__ == "__main__":
main() | # ABC061C - Big Array
import sys
input = sys.stdin.readline
def main():
n, k = list(map(int, input().rstrip().split()))
memo = [0] * (10 ** 5 + 1)
for _ in range(n):
i, j = list(map(int, input().rstrip().split()))
memo[i] += j
cnt = 0
for i, j in enumerate(memo):
cnt += j
if cnt >= k:
print(i)
break
if __name__ == "__main__":
main() | 20 | 20 | 449 | 430 | # ABC061C - Big Array
import sys
input = sys.stdin.readline
def main():
n, k = list(map(int, input().rstrip().split()))
arr = [list(map(int, input().rstrip().split())) for _ in range(n)]
memo = [0] * (10**5 + 1)
for i, j in arr:
memo[i] += j
cnt = 0
for i, j in enumerate(memo):
cnt += j
if cnt >= k:
print(i)
break
if __name__ == "__main__":
main()
| # ABC061C - Big Array
import sys
input = sys.stdin.readline
def main():
n, k = list(map(int, input().rstrip().split()))
memo = [0] * (10**5 + 1)
for _ in range(n):
i, j = list(map(int, input().rstrip().split()))
memo[i] += j
cnt = 0
for i, j in enumerate(memo):
cnt += j
if cnt >= k:
print(i)
break
if __name__ == "__main__":
main()
| false | 0 | [
"- arr = [list(map(int, input().rstrip().split())) for _ in range(n)]",
"- for i, j in arr:",
"+ for _ in range(n):",
"+ i, j = list(map(int, input().rstrip().split()))"
]
| false | 0.055935 | 0.038356 | 1.458288 | [
"s209946964",
"s377508719"
]
|
u764569828 | p02936 | python | s094493415 | s432432323 | 1,895 | 1,234 | 66,996 | 66,996 | Accepted | Accepted | 34.88 | I0 = lambda :list(map(int,input().split()))
I1 = lambda :int(eval(input()))
I2 = lambda :list(map(int,input().split()))
#####################################################
n ,q = I0()
counter = [0]*n
tree = [[] for i in range(n)]
for i in range(n-1):
a,b=I0()
tree[a-1].append(b-1)
tree[b-1].append(a-1)
for i in range(q):
p,x = I0()
counter[p-1]+=x
stack = [0]
seen = dict()
seen[0] = 1
while stack:
yy = stack.pop()
for i in tree[yy]:
if seen.get(i,-1) == -1:
seen[i] = 1
counter[i]+=counter[yy]
stack.append(i)
print((*counter)) | I0 = lambda :list(map(int,input().split()))
I1 = lambda :int(eval(input()))
I2 = lambda :list(map(int,input().split()))
#####################################################
import sys
input=sys.stdin.readline
n ,q = I0()
counter = [0]*n
tree = [[] for i in range(n)]
for i in range(n-1):
a,b=I0()
tree[a-1].append(b-1)
tree[b-1].append(a-1)
for i in range(q):
p,x = I0()
counter[p-1]+=x
stack = [0]
seen = dict()
seen[0] = 1
while stack:
yy = stack.pop()
for i in tree[yy]:
if seen.get(i,-1) == -1:
seen[i] = 1
counter[i]+=counter[yy]
stack.append(i)
print((*counter))
| 28 | 31 | 634 | 678 | I0 = lambda: list(map(int, input().split()))
I1 = lambda: int(eval(input()))
I2 = lambda: list(map(int, input().split()))
#####################################################
n, q = I0()
counter = [0] * n
tree = [[] for i in range(n)]
for i in range(n - 1):
a, b = I0()
tree[a - 1].append(b - 1)
tree[b - 1].append(a - 1)
for i in range(q):
p, x = I0()
counter[p - 1] += x
stack = [0]
seen = dict()
seen[0] = 1
while stack:
yy = stack.pop()
for i in tree[yy]:
if seen.get(i, -1) == -1:
seen[i] = 1
counter[i] += counter[yy]
stack.append(i)
print((*counter))
| I0 = lambda: list(map(int, input().split()))
I1 = lambda: int(eval(input()))
I2 = lambda: list(map(int, input().split()))
#####################################################
import sys
input = sys.stdin.readline
n, q = I0()
counter = [0] * n
tree = [[] for i in range(n)]
for i in range(n - 1):
a, b = I0()
tree[a - 1].append(b - 1)
tree[b - 1].append(a - 1)
for i in range(q):
p, x = I0()
counter[p - 1] += x
stack = [0]
seen = dict()
seen[0] = 1
while stack:
yy = stack.pop()
for i in tree[yy]:
if seen.get(i, -1) == -1:
seen[i] = 1
counter[i] += counter[yy]
stack.append(i)
print((*counter))
| false | 9.677419 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
]
| false | 0.05256 | 0.035784 | 1.468815 | [
"s094493415",
"s432432323"
]
|
u216888678 | p02778 | python | s998666516 | s297348402 | 19 | 17 | 3,188 | 2,940 | Accepted | Accepted | 10.53 | import re
S=list(eval(input()))
A,X="","x"
for i in range(len(S)):
A=A+X
print(A) | S=list(eval(input()))
A,X="","x"
for i in range(len(S)):
A=A+X
print(A) | 6 | 5 | 84 | 73 | import re
S = list(eval(input()))
A, X = "", "x"
for i in range(len(S)):
A = A + X
print(A)
| S = list(eval(input()))
A, X = "", "x"
for i in range(len(S)):
A = A + X
print(A)
| false | 16.666667 | [
"-import re",
"-"
]
| false | 0.101205 | 0.042066 | 2.405856 | [
"s998666516",
"s297348402"
]
|
u645250356 | p03767 | python | s369402240 | s130854317 | 340 | 281 | 107,548 | 40,168 | Accepted | Accepted | 17.35 | from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
a = inpl()
a.sort()
res = 0
ind = n
for i in range(n):
if i == 0:
res += a[ind]
continue
ind += 2
res += a[ind]
print(res) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
a.sort(reverse = True)
cnt = n
ind = 0
res = 0
while cnt:
if ind % 2:
res += a[ind]
cnt -= 1
ind += 1
print(res) | 22 | 21 | 594 | 491 | from collections import Counter, defaultdict, deque
import sys, bisect, math, itertools, string, queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpl_str():
return list(sys.stdin.readline().split())
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
a = inpl()
a.sort()
res = 0
ind = n
for i in range(n):
if i == 0:
res += a[ind]
continue
ind += 2
res += a[ind]
print(res)
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
a.sort(reverse=True)
cnt = n
ind = 0
res = 0
while cnt:
if ind % 2:
res += a[ind]
cnt -= 1
ind += 1
print(res)
| false | 4.545455 | [
"-import sys, bisect, math, itertools, string, queue",
"-from heapq import heappop, heappush",
"+from heapq import heappop, heappush, heapify",
"+import sys, bisect, math, itertools, fractions, pprint",
"+INF = float(\"inf\")",
"-def inpl_str():",
"- return list(sys.stdin.readline().split())",
"-",
"-",
"-def inpln(n):",
"- return list(int(sys.stdin.readline()) for i in range(n))",
"-",
"-",
"-a.sort()",
"+a.sort(reverse=True)",
"+cnt = n",
"+ind = 0",
"-ind = n",
"-for i in range(n):",
"- if i == 0:",
"+while cnt:",
"+ if ind % 2:",
"- continue",
"- ind += 2",
"- res += a[ind]",
"+ cnt -= 1",
"+ ind += 1"
]
| false | 0.111057 | 0.044593 | 2.490434 | [
"s369402240",
"s130854317"
]
|
u463864151 | p03721 | python | s093305076 | s509808757 | 499 | 320 | 27,872 | 5,920 | Accepted | Accepted | 35.87 | N, K = list(map(int, input().split()))
a_b_list_list = []
for i in range(N):
a_b_list_list.append(list(map(int, input().split())))
a_b_list_list.sort()
counter = 0
answer = None
for a_b_list in a_b_list_list:
counter += a_b_list[1]
if counter >= K:
answer = a_b_list[0]
break
print(answer)
| """
่งฃ่ชฌใ่ชญใใงใใใใใฑใใใฝใผใใงๆธใ็ดใใใ
ๅ็ดใซใชในใใฎใชในใใใฝใผใใใใจใO(NlogN)ใใใใ
NใฎๆๅคงๅคN_maxๅใฎใใฑใใใ็จๆใใฆใใใใฑใใใฝใผใใใใจใO(N_max+A_max)ใซใชใใ
A_max<=N_maxใ ใใใ่ฆใใใซO(N_max)ใซใชใใ
"""
N_max = 10**5+1
N, K = list(map(int, input().split()))
bucket_list = [0 for i in range(N_max)]
for i in range(N):
a, b = list(map(int, input().split()))
bucket_list[a] += b
counter = 0
answer = None
for i in range(1, N_max):
counter += bucket_list[i]
if counter >= K:
answer = i
break
print(answer)
| 16 | 24 | 330 | 497 | N, K = list(map(int, input().split()))
a_b_list_list = []
for i in range(N):
a_b_list_list.append(list(map(int, input().split())))
a_b_list_list.sort()
counter = 0
answer = None
for a_b_list in a_b_list_list:
counter += a_b_list[1]
if counter >= K:
answer = a_b_list[0]
break
print(answer)
| """
่งฃ่ชฌใ่ชญใใงใใใใใฑใใใฝใผใใงๆธใ็ดใใใ
ๅ็ดใซใชในใใฎใชในใใใฝใผใใใใจใO(NlogN)ใใใใ
NใฎๆๅคงๅคN_maxๅใฎใใฑใใใ็จๆใใฆใใใใฑใใใฝใผใใใใจใO(N_max+A_max)ใซใชใใ
A_max<=N_maxใ ใใใ่ฆใใใซO(N_max)ใซใชใใ
"""
N_max = 10**5 + 1
N, K = list(map(int, input().split()))
bucket_list = [0 for i in range(N_max)]
for i in range(N):
a, b = list(map(int, input().split()))
bucket_list[a] += b
counter = 0
answer = None
for i in range(1, N_max):
counter += bucket_list[i]
if counter >= K:
answer = i
break
print(answer)
| false | 33.333333 | [
"+\"\"\"",
"+่งฃ่ชฌใ่ชญใใงใใใใใฑใใใฝใผใใงๆธใ็ดใใใ",
"+ๅ็ดใซใชในใใฎใชในใใใฝใผใใใใจใO(NlogN)ใใใใ",
"+NใฎๆๅคงๅคN_maxๅใฎใใฑใใใ็จๆใใฆใใใใฑใใใฝใผใใใใจใO(N_max+A_max)ใซใชใใ",
"+A_max<=N_maxใ ใใใ่ฆใใใซO(N_max)ใซใชใใ",
"+\"\"\"",
"+N_max = 10**5 + 1",
"-a_b_list_list = []",
"+bucket_list = [0 for i in range(N_max)]",
"- a_b_list_list.append(list(map(int, input().split())))",
"-a_b_list_list.sort()",
"+ a, b = list(map(int, input().split()))",
"+ bucket_list[a] += b",
"-for a_b_list in a_b_list_list:",
"- counter += a_b_list[1]",
"+for i in range(1, N_max):",
"+ counter += bucket_list[i]",
"- answer = a_b_list[0]",
"+ answer = i"
]
| false | 0.045565 | 0.058461 | 0.779409 | [
"s093305076",
"s509808757"
]
|
u298297089 | p03061 | python | s965028480 | s103794158 | 235 | 217 | 16,124 | 16,612 | Accepted | Accepted | 7.66 | from fractions import gcd
N = int(eval(input()))
A = list(map(int, input().split()))
L = []
R = []
tl = A[0]
tr = A[-1]
for i in range(N):
tl = gcd(tl, A[i])
L.append(tl)
tr = gcd(tr, A[N-1-i])
R.append(tr)
mx = 1
R.reverse()
for i in range(N):
tl = L[i-1] if i else R[i+1]
tr = R[i+1] if i+1 < N else L[i-1]
mx = max(mx, gcd(tl, tr))
print(mx) | from fractions import gcd
n = int(eval(input()))
a = list(map(int, input().split()))
b,c = [], []
bb,cc = a[0], a[-1]
for i in range(n):
bb, cc = gcd(bb, a[i]), gcd(cc, a[-i-1])
b.append(bb)
c.append(cc)
ans = 1
c = c[::-1]
for i in range(1,n-1):
ans = max(ans, gcd(b[i-1], c[i+1]))
print((max([ans, b[-2], c[1]])))
| 20 | 17 | 374 | 335 | from fractions import gcd
N = int(eval(input()))
A = list(map(int, input().split()))
L = []
R = []
tl = A[0]
tr = A[-1]
for i in range(N):
tl = gcd(tl, A[i])
L.append(tl)
tr = gcd(tr, A[N - 1 - i])
R.append(tr)
mx = 1
R.reverse()
for i in range(N):
tl = L[i - 1] if i else R[i + 1]
tr = R[i + 1] if i + 1 < N else L[i - 1]
mx = max(mx, gcd(tl, tr))
print(mx)
| from fractions import gcd
n = int(eval(input()))
a = list(map(int, input().split()))
b, c = [], []
bb, cc = a[0], a[-1]
for i in range(n):
bb, cc = gcd(bb, a[i]), gcd(cc, a[-i - 1])
b.append(bb)
c.append(cc)
ans = 1
c = c[::-1]
for i in range(1, n - 1):
ans = max(ans, gcd(b[i - 1], c[i + 1]))
print((max([ans, b[-2], c[1]])))
| false | 15 | [
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-L = []",
"-R = []",
"-tl = A[0]",
"-tr = A[-1]",
"-for i in range(N):",
"- tl = gcd(tl, A[i])",
"- L.append(tl)",
"- tr = gcd(tr, A[N - 1 - i])",
"- R.append(tr)",
"-mx = 1",
"-R.reverse()",
"-for i in range(N):",
"- tl = L[i - 1] if i else R[i + 1]",
"- tr = R[i + 1] if i + 1 < N else L[i - 1]",
"- mx = max(mx, gcd(tl, tr))",
"-print(mx)",
"+n = int(eval(input()))",
"+a = list(map(int, input().split()))",
"+b, c = [], []",
"+bb, cc = a[0], a[-1]",
"+for i in range(n):",
"+ bb, cc = gcd(bb, a[i]), gcd(cc, a[-i - 1])",
"+ b.append(bb)",
"+ c.append(cc)",
"+ans = 1",
"+c = c[::-1]",
"+for i in range(1, n - 1):",
"+ ans = max(ans, gcd(b[i - 1], c[i + 1]))",
"+print((max([ans, b[-2], c[1]])))"
]
| false | 0.061535 | 0.061554 | 0.999685 | [
"s965028480",
"s103794158"
]
|
u835924161 | p03337 | python | s889753499 | s609924592 | 32 | 25 | 8,976 | 8,912 | Accepted | Accepted | 21.88 | a,b=list(map(int,input().split()))
A=[a+b,a-b,a*b]
print((max(A))) | a,b=list(map(int,input().split()))
print((max([a+b,a-b,a*b]))) | 5 | 3 | 64 | 57 | a, b = list(map(int, input().split()))
A = [a + b, a - b, a * b]
print((max(A)))
| a, b = list(map(int, input().split()))
print((max([a + b, a - b, a * b])))
| false | 40 | [
"-A = [a + b, a - b, a * b]",
"-print((max(A)))",
"+print((max([a + b, a - b, a * b])))"
]
| false | 0.122589 | 0.087704 | 1.397755 | [
"s889753499",
"s609924592"
]
|
u952708174 | p02707 | python | s010079579 | s893020752 | 226 | 167 | 60,096 | 44,304 | Accepted | Accepted | 26.11 | def c_management():
N = int(eval(input()))
A = [int(i) for i in input().split()]
tree = [[] for _ in range(N)]
for k, a in enumerate(A, 2):
tree[a - 1].append(k - 1)
ans = [len(t) for t in tree]
return '\n'.join(map(str, ans))
print((c_management())) | def c_management():
from collections import Counter
N = int(eval(input()))
A = [int(i) for i in input().split()]
count = Counter(A)
ans = [count[i] for i in range(1, N + 1)]
return ' '.join(map(str, ans))
print((c_management())) | 12 | 10 | 288 | 255 | def c_management():
N = int(eval(input()))
A = [int(i) for i in input().split()]
tree = [[] for _ in range(N)]
for k, a in enumerate(A, 2):
tree[a - 1].append(k - 1)
ans = [len(t) for t in tree]
return "\n".join(map(str, ans))
print((c_management()))
| def c_management():
from collections import Counter
N = int(eval(input()))
A = [int(i) for i in input().split()]
count = Counter(A)
ans = [count[i] for i in range(1, N + 1)]
return " ".join(map(str, ans))
print((c_management()))
| false | 16.666667 | [
"+ from collections import Counter",
"+",
"- tree = [[] for _ in range(N)]",
"- for k, a in enumerate(A, 2):",
"- tree[a - 1].append(k - 1)",
"- ans = [len(t) for t in tree]",
"- return \"\\n\".join(map(str, ans))",
"+ count = Counter(A)",
"+ ans = [count[i] for i in range(1, N + 1)]",
"+ return \" \".join(map(str, ans))"
]
| false | 0.037255 | 0.037795 | 0.98571 | [
"s010079579",
"s893020752"
]
|
u201856486 | p03835 | python | s008964064 | s687032561 | 1,101 | 923 | 2,940 | 2,940 | Accepted | Accepted | 16.17 | k,s=list(map(int,input().split()));r=range;print((sum(1 for x in r(k+1) for y in r(k+1)if x+y<=s and s-x-y<=k))) | k,s=list(map(int,input().split()));r=range;print((sum(1for x in r(k+1)for y in r(k+1)if 0<=s-x-y<=k))) | 1 | 1 | 104 | 94 | k, s = list(map(int, input().split()))
r = range
print((sum(1 for x in r(k + 1) for y in r(k + 1) if x + y <= s and s - x - y <= k)))
| k, s = list(map(int, input().split()))
r = range
print((sum(1 for x in r(k + 1) for y in r(k + 1) if 0 <= s - x - y <= k)))
| false | 0 | [
"-print((sum(1 for x in r(k + 1) for y in r(k + 1) if x + y <= s and s - x - y <= k)))",
"+print((sum(1 for x in r(k + 1) for y in r(k + 1) if 0 <= s - x - y <= k)))"
]
| false | 0.048896 | 0.008321 | 5.876199 | [
"s008964064",
"s687032561"
]
|
u585482323 | p03137 | python | s573126822 | s641428144 | 278 | 107 | 57,384 | 14,332 | Accepted | Accepted | 61.51 | #!usr/bin/env python3
from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(eval(input()))
def LS(): return input().split()
def S(): return eval(input())
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007
#A
"""
t,x = LI()
print(t/x)
"""
#B
"""
n= II()
a = LI()
m = max(a)
if m >= sum(a)-m:
print("No")
else:
print("Yes")
"""
#C
n,m = LI()
x = LI()
x.sort()
l = [x[i+1]-x[i] for i in range(m-1)]
l.sort()
l = l[::-1]
ans = sum(l[max(n-1,0):])
print(ans)
#D
"""
n,k = LI()
a = LI()
l = 0
b = [0 for i in range(n)]
for i in range(n):
b[i] = list(bin(a[i]))[2:]
l = max(l,len(b[i]))
s = [0 for i in range(l)]
for i in range(n):
for j in range(l-len(b[i])):
b[i].insert(0,"0")
for i in range(n):
for j in range(l):
s[j] += 1-int(b[i][j])
ke = 1
for i in range(l)[::-1]:
if s[i] <= n//2:
s[i] = [(n-s[i])*ke,0,float("inf")]
else:
s[i] = [(n-s[i])*ke,s[i]*ke,ke]
ke *= 2
s.sort(key = lambda x:x[0])
d = 0
ans = 0
key = len(list(bin(k)))-2
key -= l
ke = 2**l
print(s)
for i in range(key):
d += ke
ans += n*ke
ke *= 2
for i in range(l):
r,q,p = s[i]
if d+p <= k:
d += p
ans += q
else:
ans += r
print(ans)
"""
#E
#F
#G
#H
#I
#J
#K
#L
#M
#N
#O
#P
#Q
#R
#S
#T
| #!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = SR()
return l
mod = 1000000007
#A
def A():
t,x = LI()
print((t/x))
#B
def B():
n = I()
a = LI()
m = max(a)
if m >= sum(a)-m:
print("No")
else:
print("Yes")
#C
def C():
n,m = LI()
x = LI()
x.sort()
l = [x[i+1]-x[i] for i in range(m-1)]
l.sort()
l = l[::-1]
ans = sum(l[max(n-1,0):])
print(ans)
#D
def D():
n,k = LI()
a = LI()
k = list(map(int,list(bin(k)[2:])))
l = len(k)
for i in range(n):
a[i] = list(map(int,list(bin(a[i])[2:])))
l = max(l,len(a[i]))
for i in range(n):
for j in range(l-len(a[i])):
a[i].insert(0,0)
for j in range(l-len(k)):
k.insert(0,0)
s = [[0,0] for i in range(l)]
pow2 = [1 for i in range(l)]
for i in range(l-1)[::-1]:
pow2[i] = pow2[i+1]*2
for i in a:
for j in range(l):
s[j][0] += pow2[j]*i[j]
s[j][1] += pow2[j]*(not i[j])
dp = [0 for i in range(l+1)]
small = False
for i in range(l):
if not small:
if not k[i]:
dp[i+1] += dp[i]+s[i][0]
else:
if s[i][0] >= s[i][1]:
dp[i+1] += dp[i]+s[i][0]
small = True
else:
dp[i+1] += dp[i]+s[i][1]
else:
dp[i+1] += dp[i]+max(s[i])
print((dp[l]))
#E
if __name__ == "__main__":
C()
#F
#G
#H
#I
#J
#K
#L
#M
#N
#O
#P
#Q
#R
#S
#T
| 112 | 126 | 1,542 | 2,325 | #!usr/bin/env python3
from collections import defaultdict
import math
def LI():
return list(map(int, input().split()))
def II():
return int(eval(input()))
def LS():
return input().split()
def S():
return eval(input())
def IIR(n):
return [II() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
mod = 1000000007
# A
"""
t,x = LI()
print(t/x)
"""
# B
"""
n= II()
a = LI()
m = max(a)
if m >= sum(a)-m:
print("No")
else:
print("Yes")
"""
# C
n, m = LI()
x = LI()
x.sort()
l = [x[i + 1] - x[i] for i in range(m - 1)]
l.sort()
l = l[::-1]
ans = sum(l[max(n - 1, 0) :])
print(ans)
# D
"""
n,k = LI()
a = LI()
l = 0
b = [0 for i in range(n)]
for i in range(n):
b[i] = list(bin(a[i]))[2:]
l = max(l,len(b[i]))
s = [0 for i in range(l)]
for i in range(n):
for j in range(l-len(b[i])):
b[i].insert(0,"0")
for i in range(n):
for j in range(l):
s[j] += 1-int(b[i][j])
ke = 1
for i in range(l)[::-1]:
if s[i] <= n//2:
s[i] = [(n-s[i])*ke,0,float("inf")]
else:
s[i] = [(n-s[i])*ke,s[i]*ke,ke]
ke *= 2
s.sort(key = lambda x:x[0])
d = 0
ans = 0
key = len(list(bin(k)))-2
key -= l
ke = 2**l
print(s)
for i in range(key):
d += ke
ans += n*ke
ke *= 2
for i in range(l):
r,q,p = s[i]
if d+p <= k:
d += p
ans += q
else:
ans += r
print(ans)
"""
# E
# F
# G
# H
# I
# J
# K
# L
# M
# N
# O
# P
# Q
# R
# S
# T
| #!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return list(map(list, sys.stdin.readline().split()))
def S():
return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = SR()
return l
mod = 1000000007
# A
def A():
t, x = LI()
print((t / x))
# B
def B():
n = I()
a = LI()
m = max(a)
if m >= sum(a) - m:
print("No")
else:
print("Yes")
# C
def C():
n, m = LI()
x = LI()
x.sort()
l = [x[i + 1] - x[i] for i in range(m - 1)]
l.sort()
l = l[::-1]
ans = sum(l[max(n - 1, 0) :])
print(ans)
# D
def D():
n, k = LI()
a = LI()
k = list(map(int, list(bin(k)[2:])))
l = len(k)
for i in range(n):
a[i] = list(map(int, list(bin(a[i])[2:])))
l = max(l, len(a[i]))
for i in range(n):
for j in range(l - len(a[i])):
a[i].insert(0, 0)
for j in range(l - len(k)):
k.insert(0, 0)
s = [[0, 0] for i in range(l)]
pow2 = [1 for i in range(l)]
for i in range(l - 1)[::-1]:
pow2[i] = pow2[i + 1] * 2
for i in a:
for j in range(l):
s[j][0] += pow2[j] * i[j]
s[j][1] += pow2[j] * (not i[j])
dp = [0 for i in range(l + 1)]
small = False
for i in range(l):
if not small:
if not k[i]:
dp[i + 1] += dp[i] + s[i][0]
else:
if s[i][0] >= s[i][1]:
dp[i + 1] += dp[i] + s[i][0]
small = True
else:
dp[i + 1] += dp[i] + s[i][1]
else:
dp[i + 1] += dp[i] + max(s[i])
print((dp[l]))
# E
if __name__ == "__main__":
C()
# F
# G
# H
# I
# J
# K
# L
# M
# N
# O
# P
# Q
# R
# S
# T
| false | 11.111111 | [
"+from heapq import heappush, heappop",
"+import sys",
"+import bisect",
"+import random",
"- return list(map(int, input().split()))",
"+ return list(map(int, sys.stdin.readline().split()))",
"-def II():",
"- return int(eval(input()))",
"+def I():",
"+ return int(sys.stdin.readline())",
"- return input().split()",
"+ return list(map(list, sys.stdin.readline().split()))",
"- return eval(input())",
"+ return list(sys.stdin.readline())[:-1]",
"-def IIR(n):",
"- return [II() for i in range(n)]",
"+def IR(n):",
"+ l = [None for i in range(n)]",
"+ for i in range(n):",
"+ l[i] = I()",
"+ return l",
"- return [LI() for i in range(n)]",
"+ l = [None for i in range(n)]",
"+ for i in range(n):",
"+ l[i] = LI()",
"+ return l",
"- return [S() for i in range(n)]",
"+ l = [None for i in range(n)]",
"+ for i in range(n):",
"+ l[i] = S()",
"+ return l",
"+",
"+",
"+def LSR(n):",
"+ l = [None for i in range(n)]",
"+ for i in range(n):",
"+ l[i] = SR()",
"+ return l",
"-\"\"\"",
"-t,x = LI()",
"-print(t/x)",
"-\"\"\"",
"+def A():",
"+ t, x = LI()",
"+ print((t / x))",
"+",
"+",
"-\"\"\"",
"-n= II()",
"-a = LI()",
"-m = max(a)",
"-if m >= sum(a)-m:",
"- print(\"No\")",
"-else:",
"- print(\"Yes\")",
"-\"\"\"",
"+def B():",
"+ n = I()",
"+ a = LI()",
"+ m = max(a)",
"+ if m >= sum(a) - m:",
"+ print(\"No\")",
"+ else:",
"+ print(\"Yes\")",
"+",
"+",
"-n, m = LI()",
"-x = LI()",
"-x.sort()",
"-l = [x[i + 1] - x[i] for i in range(m - 1)]",
"-l.sort()",
"-l = l[::-1]",
"-ans = sum(l[max(n - 1, 0) :])",
"-print(ans)",
"+def C():",
"+ n, m = LI()",
"+ x = LI()",
"+ x.sort()",
"+ l = [x[i + 1] - x[i] for i in range(m - 1)]",
"+ l.sort()",
"+ l = l[::-1]",
"+ ans = sum(l[max(n - 1, 0) :])",
"+ print(ans)",
"+",
"+",
"-\"\"\"",
"-n,k = LI()",
"-a = LI()",
"-l = 0",
"-b = [0 for i in range(n)]",
"-for i in range(n):",
"- b[i] = list(bin(a[i]))[2:]",
"- l = max(l,len(b[i]))",
"-s = [0 for i in range(l)]",
"-for i in range(n):",
"- for j in range(l-len(b[i])):",
"- b[i].insert(0,\"0\")",
"-for i in range(n):",
"- for j in range(l):",
"- s[j] += 1-int(b[i][j])",
"-ke = 1",
"-for i in range(l)[::-1]:",
"- if s[i] <= n//2:",
"- s[i] = [(n-s[i])*ke,0,float(\"inf\")]",
"- else:",
"- s[i] = [(n-s[i])*ke,s[i]*ke,ke]",
"- ke *= 2",
"-s.sort(key = lambda x:x[0])",
"-d = 0",
"-ans = 0",
"-key = len(list(bin(k)))-2",
"-key -= l",
"-ke = 2**l",
"-print(s)",
"-for i in range(key):",
"- d += ke",
"- ans += n*ke",
"- ke *= 2",
"-for i in range(l):",
"- r,q,p = s[i]",
"- if d+p <= k:",
"- d += p",
"- ans += q",
"- else:",
"- ans += r",
"-print(ans)",
"-\"\"\"",
"+def D():",
"+ n, k = LI()",
"+ a = LI()",
"+ k = list(map(int, list(bin(k)[2:])))",
"+ l = len(k)",
"+ for i in range(n):",
"+ a[i] = list(map(int, list(bin(a[i])[2:])))",
"+ l = max(l, len(a[i]))",
"+ for i in range(n):",
"+ for j in range(l - len(a[i])):",
"+ a[i].insert(0, 0)",
"+ for j in range(l - len(k)):",
"+ k.insert(0, 0)",
"+ s = [[0, 0] for i in range(l)]",
"+ pow2 = [1 for i in range(l)]",
"+ for i in range(l - 1)[::-1]:",
"+ pow2[i] = pow2[i + 1] * 2",
"+ for i in a:",
"+ for j in range(l):",
"+ s[j][0] += pow2[j] * i[j]",
"+ s[j][1] += pow2[j] * (not i[j])",
"+ dp = [0 for i in range(l + 1)]",
"+ small = False",
"+ for i in range(l):",
"+ if not small:",
"+ if not k[i]:",
"+ dp[i + 1] += dp[i] + s[i][0]",
"+ else:",
"+ if s[i][0] >= s[i][1]:",
"+ dp[i + 1] += dp[i] + s[i][0]",
"+ small = True",
"+ else:",
"+ dp[i + 1] += dp[i] + s[i][1]",
"+ else:",
"+ dp[i + 1] += dp[i] + max(s[i])",
"+ print((dp[l]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ C()"
]
| false | 0.079787 | 0.044251 | 1.80304 | [
"s573126822",
"s641428144"
]
|
u969850098 | p03088 | python | s850569560 | s265849679 | 41 | 34 | 4,080 | 3,420 | Accepted | Accepted | 17.07 | import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 6)
import math
from collections import Counter
from collections import deque
from operator import itemgetter
import time, random
MOD = 10 ** 9 + 7
from itertools import permutations
def dfs(s):
if len(s) == N:
return 1
if (s[-2] == 'A' and s[-1] == 'G') or (s[-2] == 'G' and s[-1] == 'A'):
return dfs(s+'A') % MOD + dfs(s+'G') % MOD + dfs(s+'T') % MOD
elif s[-2] == 'A' and s[-1] == 'C':
return dfs(s+'A') % MOD + dfs(s+'C') % MOD + dfs(s+'T') % MOD
else:
return dfs(s+'A') % MOD + dfs(s+'C') % MOD + dfs(s+'G') % MOD + dfs(s+'T') % MOD
def main():
N = int(readline())
A, G, C, T = 0, 1, 2, 3
dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(N+1)]
for j in range(4): # i - 2 ๆๅญ็ฎ
for k in range(4): # i - 1 ๆๅญ็ฎ
for l in range(4): # i ๆๅญ็ฎ
if j == A and k == G and l == C: continue
if j == A and k == C and l == G: continue
if j == G and k == A and l == C: continue
dp[3][j][k][l] = 1
for i in range(4, N+1):
for j in range(4):
for k in range(4):
for l in range(4):
for m in range(4):
if j == A and k == G and l == C: continue
if j == A and k == C and l == G: continue
if j == G and k == A and l == C: continue
if m == A and k == G and l == C: continue
if m == A and j == G and l == C: continue
dp[i][j][k][l] += dp[i-1][m][j][k]
dp[i][j][k][l] %= MOD
res = 0
for j in range(4):
for k in range(4):
for l in range(4):
res += dp[N][j][k][l]
res %= MOD
print(res)
if __name__ == '__main__':
main() | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
def main():
N = int(readline())
A, G, C, T = 0, 1, 2, 3
dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(N+1)]
for j in range(4): # i - 2 ๆๅญ็ฎ
for k in range(4): # i - 1 ๆๅญ็ฎ
for l in range(4): # i ๆๅญ็ฎ
if j == A and k == G and l == C: continue
if j == A and k == C and l == G: continue
if j == G and k == A and l == C: continue
dp[3][j][k][l] = 1
for i in range(4, N+1):
for j in range(4):
for k in range(4):
for l in range(4):
for m in range(4):
if j == A and k == G and l == C: continue
if j == A and k == C and l == G: continue
if j == G and k == A and l == C: continue
if m == A and k == G and l == C: continue
if m == A and j == G and l == C: continue
dp[i][j][k][l] += dp[i-1][m][j][k]
dp[i][j][k][l] %= MOD
res = 0
for j in range(4):
for k in range(4):
for l in range(4):
res += dp[N][j][k][l]
res %= MOD
print(res)
if __name__ == '__main__':
main() | 58 | 40 | 2,042 | 1,396 | import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**6)
import math
from collections import Counter
from collections import deque
from operator import itemgetter
import time, random
MOD = 10**9 + 7
from itertools import permutations
def dfs(s):
if len(s) == N:
return 1
if (s[-2] == "A" and s[-1] == "G") or (s[-2] == "G" and s[-1] == "A"):
return dfs(s + "A") % MOD + dfs(s + "G") % MOD + dfs(s + "T") % MOD
elif s[-2] == "A" and s[-1] == "C":
return dfs(s + "A") % MOD + dfs(s + "C") % MOD + dfs(s + "T") % MOD
else:
return (
dfs(s + "A") % MOD
+ dfs(s + "C") % MOD
+ dfs(s + "G") % MOD
+ dfs(s + "T") % MOD
)
def main():
N = int(readline())
A, G, C, T = 0, 1, 2, 3
dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(N + 1)]
for j in range(4): # i - 2 ๆๅญ็ฎ
for k in range(4): # i - 1 ๆๅญ็ฎ
for l in range(4): # i ๆๅญ็ฎ
if j == A and k == G and l == C:
continue
if j == A and k == C and l == G:
continue
if j == G and k == A and l == C:
continue
dp[3][j][k][l] = 1
for i in range(4, N + 1):
for j in range(4):
for k in range(4):
for l in range(4):
for m in range(4):
if j == A and k == G and l == C:
continue
if j == A and k == C and l == G:
continue
if j == G and k == A and l == C:
continue
if m == A and k == G and l == C:
continue
if m == A and j == G and l == C:
continue
dp[i][j][k][l] += dp[i - 1][m][j][k]
dp[i][j][k][l] %= MOD
res = 0
for j in range(4):
for k in range(4):
for l in range(4):
res += dp[N][j][k][l]
res %= MOD
print(res)
if __name__ == "__main__":
main()
| import sys
readline = sys.stdin.readline
MOD = 10**9 + 7
def main():
N = int(readline())
A, G, C, T = 0, 1, 2, 3
dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(N + 1)]
for j in range(4): # i - 2 ๆๅญ็ฎ
for k in range(4): # i - 1 ๆๅญ็ฎ
for l in range(4): # i ๆๅญ็ฎ
if j == A and k == G and l == C:
continue
if j == A and k == C and l == G:
continue
if j == G and k == A and l == C:
continue
dp[3][j][k][l] = 1
for i in range(4, N + 1):
for j in range(4):
for k in range(4):
for l in range(4):
for m in range(4):
if j == A and k == G and l == C:
continue
if j == A and k == C and l == G:
continue
if j == G and k == A and l == C:
continue
if m == A and k == G and l == C:
continue
if m == A and j == G and l == C:
continue
dp[i][j][k][l] += dp[i - 1][m][j][k]
dp[i][j][k][l] %= MOD
res = 0
for j in range(4):
for k in range(4):
for l in range(4):
res += dp[N][j][k][l]
res %= MOD
print(res)
if __name__ == "__main__":
main()
| false | 31.034483 | [
"-readlines = sys.stdin.readlines",
"-sys.setrecursionlimit(10**6)",
"-import math",
"-from collections import Counter",
"-from collections import deque",
"-from operator import itemgetter",
"-import time, random",
"-",
"-from itertools import permutations",
"-",
"-",
"-def dfs(s):",
"- if len(s) == N:",
"- return 1",
"- if (s[-2] == \"A\" and s[-1] == \"G\") or (s[-2] == \"G\" and s[-1] == \"A\"):",
"- return dfs(s + \"A\") % MOD + dfs(s + \"G\") % MOD + dfs(s + \"T\") % MOD",
"- elif s[-2] == \"A\" and s[-1] == \"C\":",
"- return dfs(s + \"A\") % MOD + dfs(s + \"C\") % MOD + dfs(s + \"T\") % MOD",
"- else:",
"- return (",
"- dfs(s + \"A\") % MOD",
"- + dfs(s + \"C\") % MOD",
"- + dfs(s + \"G\") % MOD",
"- + dfs(s + \"T\") % MOD",
"- )"
]
| false | 0.135951 | 0.007273 | 18.692238 | [
"s850569560",
"s265849679"
]
|
u893063840 | p03805 | python | s772343045 | s254167111 | 139 | 31 | 3,444 | 3,064 | Accepted | Accepted | 77.7 | from copy import deepcopy
cnt = 0
depth = 0
def main():
n, m = list(map(int, input().split()))
adj = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
adj[a].append(b)
adj[b].append(a)
def f(u, d):
global cnt, depth
cp = deepcopy(d)
cp[u] = depth
if cp.count(-1) == 0:
cnt += 1
else:
vs = adj[u]
depth += 1
for v in vs:
if cp[v] == -1:
f(v, cp)
depth -= 1
f(0, [-1] * n)
print(cnt)
if __name__ == "__main__":
main()
| class Graph:
def __init__(self, n, adj):
self.adj = adj
self.cnt = 0
self.depth = 0
self.ds = [-1] * n
def solve(self, u):
self.ds[u] = self.depth
if self.ds.count(-1) == 0:
self.cnt += 1
return
self.depth += 1
for v in self.adj[u]:
if self.ds[v] == -1:
self.solve(v)
self.ds[v] = -1
self.depth -= 1
def main():
n, m = list(map(int, input().split()))
adj = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
adj[a].append(b)
adj[b].append(a)
graph = Graph(n, adj)
graph.solve(0)
print((graph.cnt))
if __name__ == "__main__":
main()
| 37 | 38 | 697 | 822 | from copy import deepcopy
cnt = 0
depth = 0
def main():
n, m = list(map(int, input().split()))
adj = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
adj[a].append(b)
adj[b].append(a)
def f(u, d):
global cnt, depth
cp = deepcopy(d)
cp[u] = depth
if cp.count(-1) == 0:
cnt += 1
else:
vs = adj[u]
depth += 1
for v in vs:
if cp[v] == -1:
f(v, cp)
depth -= 1
f(0, [-1] * n)
print(cnt)
if __name__ == "__main__":
main()
| class Graph:
def __init__(self, n, adj):
self.adj = adj
self.cnt = 0
self.depth = 0
self.ds = [-1] * n
def solve(self, u):
self.ds[u] = self.depth
if self.ds.count(-1) == 0:
self.cnt += 1
return
self.depth += 1
for v in self.adj[u]:
if self.ds[v] == -1:
self.solve(v)
self.ds[v] = -1
self.depth -= 1
def main():
n, m = list(map(int, input().split()))
adj = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
adj[a].append(b)
adj[b].append(a)
graph = Graph(n, adj)
graph.solve(0)
print((graph.cnt))
if __name__ == "__main__":
main()
| false | 2.631579 | [
"-from copy import deepcopy",
"+class Graph:",
"+ def __init__(self, n, adj):",
"+ self.adj = adj",
"+ self.cnt = 0",
"+ self.depth = 0",
"+ self.ds = [-1] * n",
"-cnt = 0",
"-depth = 0",
"+ def solve(self, u):",
"+ self.ds[u] = self.depth",
"+ if self.ds.count(-1) == 0:",
"+ self.cnt += 1",
"+ return",
"+ self.depth += 1",
"+ for v in self.adj[u]:",
"+ if self.ds[v] == -1:",
"+ self.solve(v)",
"+ self.ds[v] = -1",
"+ self.depth -= 1",
"-",
"- def f(u, d):",
"- global cnt, depth",
"- cp = deepcopy(d)",
"- cp[u] = depth",
"- if cp.count(-1) == 0:",
"- cnt += 1",
"- else:",
"- vs = adj[u]",
"- depth += 1",
"- for v in vs:",
"- if cp[v] == -1:",
"- f(v, cp)",
"- depth -= 1",
"-",
"- f(0, [-1] * n)",
"- print(cnt)",
"+ graph = Graph(n, adj)",
"+ graph.solve(0)",
"+ print((graph.cnt))"
]
| false | 0.124857 | 0.042391 | 2.945371 | [
"s772343045",
"s254167111"
]
|
u344065503 | p02706 | python | s367882466 | s269437195 | 61 | 56 | 68,084 | 68,116 | Accepted | Accepted | 8.2 | n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
if n-sum(a)<0:
print((-1))
else:
print((n-sum(a)))
| n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
if n-sum(a) >= 0:
print((n-sum(a)))
else:
print((-1))
| 8 | 6 | 126 | 125 | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
if n - sum(a) < 0:
print((-1))
else:
print((n - sum(a)))
| n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
if n - sum(a) >= 0:
print((n - sum(a)))
else:
print((-1))
| false | 25 | [
"-if n - sum(a) < 0:",
"+if n - sum(a) >= 0:",
"+ print((n - sum(a)))",
"+else:",
"-else:",
"- print((n - sum(a)))"
]
| false | 0.047912 | 0.048523 | 0.987406 | [
"s367882466",
"s269437195"
]
|
u761320129 | p03363 | python | s687743613 | s299874064 | 198 | 162 | 41,364 | 44,032 | Accepted | Accepted | 18.18 | N = int(eval(input()))
A = list(map(int,input().split()))
cums = [0]
for a in A:
cums.append(cums[-1] + a)
from collections import Counter
ctr = Counter(cums)
ans = 0
for v in list(ctr.values()):
ans += v*(v-1)//2
print(ans) | N = int(eval(input()))
A = list(map(int,input().split()))
C = [0]
for a in A:
C.append(C[-1] + a)
from collections import Counter
ctr = Counter(C)
ans = 0
for v in list(ctr.values()):
ans += v*(v-1)//2
print(ans) | 11 | 11 | 230 | 218 | N = int(eval(input()))
A = list(map(int, input().split()))
cums = [0]
for a in A:
cums.append(cums[-1] + a)
from collections import Counter
ctr = Counter(cums)
ans = 0
for v in list(ctr.values()):
ans += v * (v - 1) // 2
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
C = [0]
for a in A:
C.append(C[-1] + a)
from collections import Counter
ctr = Counter(C)
ans = 0
for v in list(ctr.values()):
ans += v * (v - 1) // 2
print(ans)
| false | 0 | [
"-cums = [0]",
"+C = [0]",
"- cums.append(cums[-1] + a)",
"+ C.append(C[-1] + a)",
"-ctr = Counter(cums)",
"+ctr = Counter(C)"
]
| false | 0.098486 | 0.032517 | 3.028708 | [
"s687743613",
"s299874064"
]
|
u148378522 | p02990 | python | s696087774 | s548865995 | 1,756 | 882 | 217,588 | 3,316 | Accepted | Accepted | 49.77 | from math import factorial
import sys
sys.setrecursionlimit(2000)
mod = 10**9+7
n, k = list(map(int, input().split()))
memo = {}
def combination(n,k):
if n < k:
return 0
if n / 2 < k:
k = n - k
if n in memo and k in memo[n]:
return memo[n][k]
v = 0
if k == 0:
v = 1
elif k == 1:
v = n
else:
v = combination(n-1,k) + combination(n-1,k-1)
return memo.setdefault(n, {}).setdefault(k, v)
for i in range(1, k + 1):
print((combination(n-k+1,i)*combination(k-1,i-1)%mod))
| from math import factorial
mod = 10**9+7
n, k = list(map(int, input().split()))
def combination(n,k):
if n < k:
return 0
if k == 0 or k == n:
return 1
if k == 1:
return n
return factorial(n)//factorial(k)//factorial(n-k)
for i in range(1, k + 1):
print((combination(n-k+1,i)*combination(k-1,i-1)%mod))
| 26 | 16 | 527 | 334 | from math import factorial
import sys
sys.setrecursionlimit(2000)
mod = 10**9 + 7
n, k = list(map(int, input().split()))
memo = {}
def combination(n, k):
if n < k:
return 0
if n / 2 < k:
k = n - k
if n in memo and k in memo[n]:
return memo[n][k]
v = 0
if k == 0:
v = 1
elif k == 1:
v = n
else:
v = combination(n - 1, k) + combination(n - 1, k - 1)
return memo.setdefault(n, {}).setdefault(k, v)
for i in range(1, k + 1):
print((combination(n - k + 1, i) * combination(k - 1, i - 1) % mod))
| from math import factorial
mod = 10**9 + 7
n, k = list(map(int, input().split()))
def combination(n, k):
if n < k:
return 0
if k == 0 or k == n:
return 1
if k == 1:
return n
return factorial(n) // factorial(k) // factorial(n - k)
for i in range(1, k + 1):
print((combination(n - k + 1, i) * combination(k - 1, i - 1) % mod))
| false | 38.461538 | [
"-import sys",
"-sys.setrecursionlimit(2000)",
"-memo = {}",
"- if n / 2 < k:",
"- k = n - k",
"- if n in memo and k in memo[n]:",
"- return memo[n][k]",
"- v = 0",
"- if k == 0:",
"- v = 1",
"- elif k == 1:",
"- v = n",
"- else:",
"- v = combination(n - 1, k) + combination(n - 1, k - 1)",
"- return memo.setdefault(n, {}).setdefault(k, v)",
"+ if k == 0 or k == n:",
"+ return 1",
"+ if k == 1:",
"+ return n",
"+ return factorial(n) // factorial(k) // factorial(n - k)"
]
| false | 0.044926 | 0.043829 | 1.025044 | [
"s696087774",
"s548865995"
]
|
u187205913 | p03560 | python | s349542634 | s255252617 | 1,610 | 1,451 | 21,692 | 20,736 | Accepted | Accepted | 9.88 | k = int(eval(input()))
from collections import deque
dic = {1:1}
queue = deque([[1,1]])
while queue:
v,cost = queue.popleft()
if not (v+1)%k in dic or cost+1<dic[(v+1)%k]:
dic[(v+1)%k] = cost+1
queue.appendleft([(v+1)%k,cost+1])
if not v*10%k in dic or cost<dic[v*10%k]:
dic[v*10%k] = cost
queue.append([v*10%k,cost])
print((dic[0])) | k = int(eval(input()))
from collections import deque
dic = {1:1}
queue = deque([[1,1]])
while queue:
v,cost = queue.popleft()
v_ = (v+1)%k
if not v_ in dic or cost+1<dic[v_]:
dic[v_] = cost+1
queue.appendleft([v_,cost+1])
v_ = v*10%k
if not v_ in dic or cost<dic[v_]:
dic[v_] = cost
queue.append([v_,cost])
print((dic[0])) | 14 | 16 | 383 | 382 | k = int(eval(input()))
from collections import deque
dic = {1: 1}
queue = deque([[1, 1]])
while queue:
v, cost = queue.popleft()
if not (v + 1) % k in dic or cost + 1 < dic[(v + 1) % k]:
dic[(v + 1) % k] = cost + 1
queue.appendleft([(v + 1) % k, cost + 1])
if not v * 10 % k in dic or cost < dic[v * 10 % k]:
dic[v * 10 % k] = cost
queue.append([v * 10 % k, cost])
print((dic[0]))
| k = int(eval(input()))
from collections import deque
dic = {1: 1}
queue = deque([[1, 1]])
while queue:
v, cost = queue.popleft()
v_ = (v + 1) % k
if not v_ in dic or cost + 1 < dic[v_]:
dic[v_] = cost + 1
queue.appendleft([v_, cost + 1])
v_ = v * 10 % k
if not v_ in dic or cost < dic[v_]:
dic[v_] = cost
queue.append([v_, cost])
print((dic[0]))
| false | 12.5 | [
"- if not (v + 1) % k in dic or cost + 1 < dic[(v + 1) % k]:",
"- dic[(v + 1) % k] = cost + 1",
"- queue.appendleft([(v + 1) % k, cost + 1])",
"- if not v * 10 % k in dic or cost < dic[v * 10 % k]:",
"- dic[v * 10 % k] = cost",
"- queue.append([v * 10 % k, cost])",
"+ v_ = (v + 1) % k",
"+ if not v_ in dic or cost + 1 < dic[v_]:",
"+ dic[v_] = cost + 1",
"+ queue.appendleft([v_, cost + 1])",
"+ v_ = v * 10 % k",
"+ if not v_ in dic or cost < dic[v_]:",
"+ dic[v_] = cost",
"+ queue.append([v_, cost])"
]
| false | 0.221015 | 0.112064 | 1.972234 | [
"s349542634",
"s255252617"
]
|
u136090046 | p03815 | python | s477522980 | s464595686 | 21 | 18 | 3,316 | 2,940 | Accepted | Accepted | 14.29 | X=int(eval(input()))
ans=X//11*2
if (X%11==0):
print(ans)
elif (X%11<=6):
print((ans+1))
else:
print((ans+2))
| x = int(eval(input()))
if x % 11 == 0:
print((x // 11 * 2))
elif x % 11 <= 6:
print((x // 11 * 2 + 1))
else:
print((x // 11 * 2 + 2))
| 8 | 8 | 110 | 142 | X = int(eval(input()))
ans = X // 11 * 2
if X % 11 == 0:
print(ans)
elif X % 11 <= 6:
print((ans + 1))
else:
print((ans + 2))
| x = int(eval(input()))
if x % 11 == 0:
print((x // 11 * 2))
elif x % 11 <= 6:
print((x // 11 * 2 + 1))
else:
print((x // 11 * 2 + 2))
| false | 0 | [
"-X = int(eval(input()))",
"-ans = X // 11 * 2",
"-if X % 11 == 0:",
"- print(ans)",
"-elif X % 11 <= 6:",
"- print((ans + 1))",
"+x = int(eval(input()))",
"+if x % 11 == 0:",
"+ print((x // 11 * 2))",
"+elif x % 11 <= 6:",
"+ print((x // 11 * 2 + 1))",
"- print((ans + 2))",
"+ print((x // 11 * 2 + 2))"
]
| false | 0.047979 | 0.045373 | 1.057442 | [
"s477522980",
"s464595686"
]
|
u243572357 | p03814 | python | s536028880 | s068856934 | 25 | 18 | 6,180 | 3,500 | Accepted | Accepted | 28 | s = list(eval(input()))
print((len(s) - s.index('A') - s[::-1].index('Z'))) | a = eval(input())
l = len(a) - a.index('A') - a[::-1].index('Z')
print(l) | 2 | 3 | 68 | 69 | s = list(eval(input()))
print((len(s) - s.index("A") - s[::-1].index("Z")))
| a = eval(input())
l = len(a) - a.index("A") - a[::-1].index("Z")
print(l)
| false | 33.333333 | [
"-s = list(eval(input()))",
"-print((len(s) - s.index(\"A\") - s[::-1].index(\"Z\")))",
"+a = eval(input())",
"+l = len(a) - a.index(\"A\") - a[::-1].index(\"Z\")",
"+print(l)"
]
| false | 0.120807 | 0.081111 | 1.489395 | [
"s536028880",
"s068856934"
]
|
u525065967 | p02631 | python | s961340510 | s997990744 | 159 | 147 | 31,608 | 31,440 | Accepted | Accepted | 7.55 | n = int(input())
A = [*map(int, input().split())]
# print(n)
# print(A)
all_xor = 0
for a in A: all_xor ^= a
# print(all_xor)
ans = []
for a in A: ans.append(all_xor ^ a)
print(*ans,sep=' ')
| n = int(eval(input()))
A = [*list(map(int, input().split()))]
all_xor = 0
for a in A: all_xor ^= a
print((*[all_xor ^ a for a in A]))
| 10 | 5 | 200 | 124 | n = int(input())
A = [*map(int, input().split())]
# print(n)
# print(A)
all_xor = 0
for a in A:
all_xor ^= a
# print(all_xor)
ans = []
for a in A:
ans.append(all_xor ^ a)
print(*ans, sep=" ")
| n = int(eval(input()))
A = [*list(map(int, input().split()))]
all_xor = 0
for a in A:
all_xor ^= a
print((*[all_xor ^ a for a in A]))
| false | 50 | [
"-n = int(input())",
"-A = [*map(int, input().split())]",
"-# print(n)",
"-# print(A)",
"+n = int(eval(input()))",
"+A = [*list(map(int, input().split()))]",
"-# print(all_xor)",
"-ans = []",
"-for a in A:",
"- ans.append(all_xor ^ a)",
"-print(*ans, sep=\" \")",
"+print((*[all_xor ^ a for a in A]))"
]
| false | 0.047384 | 0.041046 | 1.154409 | [
"s961340510",
"s997990744"
]
|
u893063840 | p02727 | python | s197714216 | s993199938 | 1,530 | 241 | 126,308 | 22,720 | Accepted | Accepted | 84.25 | from heapq import heappush, heappop
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()))
hp = []
for e in p:
heappush(hp, [-e, 0])
for e in q:
heappush(hp, [-e, 1])
for e in r:
heappush(hp, [-e, 2])
ans = 0
cnt = [0] * 3
sm = 0
mx = [x, y, c]
while hp:
yum, col = heappop(hp)
yum = -yum
if cnt[col] >= mx[col]:
continue
ans += yum
cnt[col] += 1
sm += 1
if sm == x + y:
break
print(ans)
| 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)
apples = p[:x] + q[:y] + r
apples.sort(reverse=True)
ans = sum(apples[:x+y])
print(ans)
| 34 | 13 | 579 | 295 | from heapq import heappush, heappop
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()))
hp = []
for e in p:
heappush(hp, [-e, 0])
for e in q:
heappush(hp, [-e, 1])
for e in r:
heappush(hp, [-e, 2])
ans = 0
cnt = [0] * 3
sm = 0
mx = [x, y, c]
while hp:
yum, col = heappop(hp)
yum = -yum
if cnt[col] >= mx[col]:
continue
ans += yum
cnt[col] += 1
sm += 1
if sm == x + y:
break
print(ans)
| 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)
apples = p[:x] + q[:y] + r
apples.sort(reverse=True)
ans = sum(apples[: x + y])
print(ans)
| false | 61.764706 | [
"-from heapq import heappush, heappop",
"-",
"-hp = []",
"-for e in p:",
"- heappush(hp, [-e, 0])",
"-for e in q:",
"- heappush(hp, [-e, 1])",
"-for e in r:",
"- heappush(hp, [-e, 2])",
"-ans = 0",
"-cnt = [0] * 3",
"-sm = 0",
"-mx = [x, y, c]",
"-while hp:",
"- yum, col = heappop(hp)",
"- yum = -yum",
"- if cnt[col] >= mx[col]:",
"- continue",
"- ans += yum",
"- cnt[col] += 1",
"- sm += 1",
"- if sm == x + y:",
"- break",
"+p.sort(reverse=True)",
"+q.sort(reverse=True)",
"+apples = p[:x] + q[:y] + r",
"+apples.sort(reverse=True)",
"+ans = sum(apples[: x + y])"
]
| false | 0.0852 | 0.107849 | 0.789989 | [
"s197714216",
"s993199938"
]
|
u242031676 | p02898 | python | s165211651 | s782669101 | 53 | 45 | 9,988 | 10,384 | Accepted | Accepted | 15.09 | n, k = list(map(int, input().split()))
ans = 0
for i in map(int, input().split()): ans+=(i>=k)
print(ans) | n,k=list(map(int,input().split()));print((sum([h>=k for h in map(int,input().split())]))) | 4 | 1 | 102 | 81 | n, k = list(map(int, input().split()))
ans = 0
for i in map(int, input().split()):
ans += i >= k
print(ans)
| n, k = list(map(int, input().split()))
print((sum([h >= k for h in map(int, input().split())])))
| false | 75 | [
"-ans = 0",
"-for i in map(int, input().split()):",
"- ans += i >= k",
"-print(ans)",
"+print((sum([h >= k for h in map(int, input().split())])))"
]
| false | 0.032386 | 0.066326 | 0.488289 | [
"s165211651",
"s782669101"
]
|
u098968285 | p03948 | python | s185252835 | s535728621 | 302 | 251 | 63,600 | 63,728 | Accepted | Accepted | 16.89 | # def makelist(n, m):
# return [[0 for i in range(m)] for j in range(n)]
# n = int(input())
# a, b = map(int, input().split())
# s = input()
N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
diff = [0]*N
mini = A[0]
for i in range(1, N):
now = A[i]
if now <= mini:
mini = now
else:
diff[i] = now - mini
sa = max(diff)
ans = 0
mini = A[0]
l = 1
r = 0
for i in range(1, N):
now = A[i]
if mini == now:
l += 1
elif now < mini:
if r > 0:
ans += min(l, r)
r = 0
mini = now
l = 1
else: # now > mini
if now - mini == sa:
r += 1
if r > 0:
ans += min(l, r)
print(ans)
| N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
diff = -1
mini = A[0]
cnt = 0
ans = 0
for i in range(1, N):
now = A[i]
if mini > now:
mini = now
else:
if now - mini == diff:
cnt += 1
elif now - mini > diff:
diff = now - mini
ans = max(ans, cnt)
cnt = 1
ans = max(ans, cnt)
print(ans)
| 44 | 22 | 660 | 350 | # def makelist(n, m):
# return [[0 for i in range(m)] for j in range(n)]
# n = int(input())
# a, b = map(int, input().split())
# s = input()
N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
diff = [0] * N
mini = A[0]
for i in range(1, N):
now = A[i]
if now <= mini:
mini = now
else:
diff[i] = now - mini
sa = max(diff)
ans = 0
mini = A[0]
l = 1
r = 0
for i in range(1, N):
now = A[i]
if mini == now:
l += 1
elif now < mini:
if r > 0:
ans += min(l, r)
r = 0
mini = now
l = 1
else: # now > mini
if now - mini == sa:
r += 1
if r > 0:
ans += min(l, r)
print(ans)
| N, T = list(map(int, input().split()))
A = list(map(int, input().split()))
diff = -1
mini = A[0]
cnt = 0
ans = 0
for i in range(1, N):
now = A[i]
if mini > now:
mini = now
else:
if now - mini == diff:
cnt += 1
elif now - mini > diff:
diff = now - mini
ans = max(ans, cnt)
cnt = 1
ans = max(ans, cnt)
print(ans)
| false | 50 | [
"-# def makelist(n, m):",
"-# \treturn [[0 for i in range(m)] for j in range(n)]",
"-# n = int(input())",
"-# a, b = map(int, input().split())",
"-# s = input()",
"-diff = [0] * N",
"+diff = -1",
"+cnt = 0",
"+ans = 0",
"- if now <= mini:",
"+ if mini > now:",
"- diff[i] = now - mini",
"-sa = max(diff)",
"-ans = 0",
"-mini = A[0]",
"-l = 1",
"-r = 0",
"-for i in range(1, N):",
"- now = A[i]",
"- if mini == now:",
"- l += 1",
"- elif now < mini:",
"- if r > 0:",
"- ans += min(l, r)",
"- r = 0",
"- mini = now",
"- l = 1",
"- else: # now > mini",
"- if now - mini == sa:",
"- r += 1",
"-if r > 0:",
"- ans += min(l, r)",
"+ if now - mini == diff:",
"+ cnt += 1",
"+ elif now - mini > diff:",
"+ diff = now - mini",
"+ ans = max(ans, cnt)",
"+ cnt = 1",
"+ans = max(ans, cnt)"
]
| false | 0.043329 | 0.03834 | 1.13014 | [
"s185252835",
"s535728621"
]
|
u094191970 | p02579 | python | s109292644 | s196477575 | 1,110 | 738 | 135,784 | 134,888 | Accepted | Accepted | 33.51 | from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque
h,w=nii()
ch,cw=nii()
ch-=1
cw-=1
dh,dw=nii()
dh-=1
dw-=1
s=[list(eval(input())) for i in range(h)]
dist=[[-1]*w for i in range(h)]
def BFS(que):
while que:
y,x=que.popleft()
if y==dh and x==dw:
print((dist[y][x]))
exit()
for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
ny=y+dy
nx=x+dx
if 0<=ny<h and 0<=nx<w and s[ny][nx]!='#':
que.appendleft((ny,nx))
s[ny][nx]='#'
dist[ny][nx]=dist[y][x]
for dy,dx in [[-2,-2],[-2,-1],[-2,0],[-2,1],[-2,2],\
[-1,-2],[-1,-1],[-1,1],[-1,2],\
[0,-2],[0,2],\
[1,-2],[1,-1],[1,1],[1,2],\
[2,-2],[2,-1],[2,0],[2,1],[2,2]]:
ny=y+dy
nx=x+dx
if 0<=ny<h and 0<=nx<w and s[ny][nx]!='#' and dist[ny][nx]==-1:
que.append((ny,nx))
dist[ny][nx]=dist[y][x]+1
dist[ch][cw]=0
que=deque()
que.append((ch,cw))
BFS(que)
print((-1)) | from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque
h,w=nii()
ch,cw=nii()
ch-=1
cw-=1
dh,dw=nii()
dh-=1
dw-=1
s=[list(eval(input())) for i in range(h)]
dist=[[-1]*w for i in range(h)]
def BFS(que):
while que:
y,x=que.popleft()
if y==dh and x==dw:
print((dist[y][x]))
exit()
for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
ny=y+dy
nx=x+dx
if 0<=ny<h and 0<=nx<w and s[ny][nx]!='#':
que.appendleft((ny,nx))
s[ny][nx]='#'
dist[ny][nx]=dist[y][x]
for i in range(-2,3):
for j in range(-2,3):
ny=y+i
nx=x+j
if 0<=ny<h and 0<=nx<w and s[ny][nx]!='#' and dist[ny][nx]==-1:
que.append((ny,nx))
dist[ny][nx]=dist[y][x]+1
dist[ch][cw]=0
que=deque()
que.append((ch,cw))
BFS(que)
print((-1)) | 50 | 48 | 1,115 | 938 | from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
from collections import deque
h, w = nii()
ch, cw = nii()
ch -= 1
cw -= 1
dh, dw = nii()
dh -= 1
dw -= 1
s = [list(eval(input())) for i in range(h)]
dist = [[-1] * w for i in range(h)]
def BFS(que):
while que:
y, x = que.popleft()
if y == dh and x == dw:
print((dist[y][x]))
exit()
for dy, dx in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
ny = y + dy
nx = x + dx
if 0 <= ny < h and 0 <= nx < w and s[ny][nx] != "#":
que.appendleft((ny, nx))
s[ny][nx] = "#"
dist[ny][nx] = dist[y][x]
for dy, dx in [
[-2, -2],
[-2, -1],
[-2, 0],
[-2, 1],
[-2, 2],
[-1, -2],
[-1, -1],
[-1, 1],
[-1, 2],
[0, -2],
[0, 2],
[1, -2],
[1, -1],
[1, 1],
[1, 2],
[2, -2],
[2, -1],
[2, 0],
[2, 1],
[2, 2],
]:
ny = y + dy
nx = x + dx
if 0 <= ny < h and 0 <= nx < w and s[ny][nx] != "#" and dist[ny][nx] == -1:
que.append((ny, nx))
dist[ny][nx] = dist[y][x] + 1
dist[ch][cw] = 0
que = deque()
que.append((ch, cw))
BFS(que)
print((-1))
| from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
from collections import deque
h, w = nii()
ch, cw = nii()
ch -= 1
cw -= 1
dh, dw = nii()
dh -= 1
dw -= 1
s = [list(eval(input())) for i in range(h)]
dist = [[-1] * w for i in range(h)]
def BFS(que):
while que:
y, x = que.popleft()
if y == dh and x == dw:
print((dist[y][x]))
exit()
for dy, dx in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
ny = y + dy
nx = x + dx
if 0 <= ny < h and 0 <= nx < w and s[ny][nx] != "#":
que.appendleft((ny, nx))
s[ny][nx] = "#"
dist[ny][nx] = dist[y][x]
for i in range(-2, 3):
for j in range(-2, 3):
ny = y + i
nx = x + j
if (
0 <= ny < h
and 0 <= nx < w
and s[ny][nx] != "#"
and dist[ny][nx] == -1
):
que.append((ny, nx))
dist[ny][nx] = dist[y][x] + 1
dist[ch][cw] = 0
que = deque()
que.append((ch, cw))
BFS(que)
print((-1))
| false | 4 | [
"- for dy, dx in [",
"- [-2, -2],",
"- [-2, -1],",
"- [-2, 0],",
"- [-2, 1],",
"- [-2, 2],",
"- [-1, -2],",
"- [-1, -1],",
"- [-1, 1],",
"- [-1, 2],",
"- [0, -2],",
"- [0, 2],",
"- [1, -2],",
"- [1, -1],",
"- [1, 1],",
"- [1, 2],",
"- [2, -2],",
"- [2, -1],",
"- [2, 0],",
"- [2, 1],",
"- [2, 2],",
"- ]:",
"- ny = y + dy",
"- nx = x + dx",
"- if 0 <= ny < h and 0 <= nx < w and s[ny][nx] != \"#\" and dist[ny][nx] == -1:",
"- que.append((ny, nx))",
"- dist[ny][nx] = dist[y][x] + 1",
"+ for i in range(-2, 3):",
"+ for j in range(-2, 3):",
"+ ny = y + i",
"+ nx = x + j",
"+ if (",
"+ 0 <= ny < h",
"+ and 0 <= nx < w",
"+ and s[ny][nx] != \"#\"",
"+ and dist[ny][nx] == -1",
"+ ):",
"+ que.append((ny, nx))",
"+ dist[ny][nx] = dist[y][x] + 1"
]
| false | 0.040247 | 0.040795 | 0.986563 | [
"s109292644",
"s196477575"
]
|
u802963389 | p03037 | python | s053123140 | s363806571 | 306 | 248 | 11,024 | 27,144 | Accepted | Accepted | 18.95 | n, m = list(map(int, input().split()))
L = []
R = []
for _ in range(m):
l, r = list(map(int, input().split()))
L.append(l)
R.append(r)
ans = max(0, min(R) - max(L) + 1)
print(ans)
| n, m = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(m)]
l = 1
r = n
for i, j in LR:
l = max(l, i)
r = min(r, j)
print((max(0, r - l + 1))) | 12 | 11 | 190 | 189 | n, m = list(map(int, input().split()))
L = []
R = []
for _ in range(m):
l, r = list(map(int, input().split()))
L.append(l)
R.append(r)
ans = max(0, min(R) - max(L) + 1)
print(ans)
| n, m = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(m)]
l = 1
r = n
for i, j in LR:
l = max(l, i)
r = min(r, j)
print((max(0, r - l + 1)))
| false | 8.333333 | [
"-L = []",
"-R = []",
"-for _ in range(m):",
"- l, r = list(map(int, input().split()))",
"- L.append(l)",
"- R.append(r)",
"-ans = max(0, min(R) - max(L) + 1)",
"-print(ans)",
"+LR = [list(map(int, input().split())) for _ in range(m)]",
"+l = 1",
"+r = n",
"+for i, j in LR:",
"+ l = max(l, i)",
"+ r = min(r, j)",
"+print((max(0, r - l + 1)))"
]
| false | 0.041251 | 0.094616 | 0.435986 | [
"s053123140",
"s363806571"
]
|
u296518383 | p03206 | python | s356213859 | s635181994 | 20 | 17 | 2,940 | 3,064 | Accepted | Accepted | 15 | D = int(eval(input()))
print(("Christmas"+" Eve"*(25-D))) | import sys
input = sys.stdin.buffer.readline
D = int(eval(input()))
print(("Christmas" + " Eve" * (25 - D))) | 2 | 6 | 50 | 107 | D = int(eval(input()))
print(("Christmas" + " Eve" * (25 - D)))
| import sys
input = sys.stdin.buffer.readline
D = int(eval(input()))
print(("Christmas" + " Eve" * (25 - D)))
| false | 66.666667 | [
"+import sys",
"+",
"+input = sys.stdin.buffer.readline"
]
| false | 0.051999 | 0.048304 | 1.076481 | [
"s356213859",
"s635181994"
]
|
u145145077 | p02983 | python | s391893542 | s144599883 | 653 | 71 | 9,100 | 9,196 | Accepted | Accepted | 89.13 | l,r=list(map(int,input().split()))
sho_l = l // 2019
sho_r = r // 2019
if sho_r-sho_l >= 1:
print((0))
else:
ans = 2018
for i in range(l,r):
for j in range(i+1,r+1):
ans = min((i*j)%2019,ans)
print(ans)
| l,r=list(map(int,input().split()))
sho_l = l // 2019
sho_r = r // 2019
if sho_r-sho_l >= 1:
print((0))
else:
ans = 2018
flg_end = 0
for i in range(l,r):
for j in range(i+1,r+1):
ans = min((i*j)%2019,ans)
if ans == 0:
flg_end = 1
if flg_end == 1:
break
print(ans)
| 13 | 18 | 227 | 318 | l, r = list(map(int, input().split()))
sho_l = l // 2019
sho_r = r // 2019
if sho_r - sho_l >= 1:
print((0))
else:
ans = 2018
for i in range(l, r):
for j in range(i + 1, r + 1):
ans = min((i * j) % 2019, ans)
print(ans)
| l, r = list(map(int, input().split()))
sho_l = l // 2019
sho_r = r // 2019
if sho_r - sho_l >= 1:
print((0))
else:
ans = 2018
flg_end = 0
for i in range(l, r):
for j in range(i + 1, r + 1):
ans = min((i * j) % 2019, ans)
if ans == 0:
flg_end = 1
if flg_end == 1:
break
print(ans)
| false | 27.777778 | [
"+ flg_end = 0",
"+ if ans == 0:",
"+ flg_end = 1",
"+ if flg_end == 1:",
"+ break"
]
| false | 0.105803 | 0.00745 | 14.202151 | [
"s391893542",
"s144599883"
]
|
u672475305 | p03546 | python | s118370391 | s044715429 | 38 | 34 | 3,444 | 3,188 | Accepted | Accepted | 10.53 | inf = 1000
h,w = list(map(int,input().split()))
dp = []
for i in range(10):
c = list(map(int,input().split()))
dp.append(c)
for k in range(10):
for i in range(10):
for j in range(10):
dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
ans = 0
A = [list(map(int, input().split())) for _ in range(h)]
for i in range(h):
for j in range(w):
if A[i][j] not in [-1,1]:
ans += dp[A[i][j]][1]
print(ans) | h,w = list(map(int,input().split()))
C = []
for i in range(10):
C.append(list(map(int,input().split())))
def warshall_floyd(d):
for k in range(10):
for i in range(10):
for j in range(10):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
return d
trans_map = warshall_floyd(C)
ans = 0
for i in range(h):
line = list(map(int,input().split()))
for j in range(w):
num = line[j]
if num == -1:
continue
ans += trans_map[num][1]
print(ans) | 22 | 25 | 463 | 540 | inf = 1000
h, w = list(map(int, input().split()))
dp = []
for i in range(10):
c = list(map(int, input().split()))
dp.append(c)
for k in range(10):
for i in range(10):
for j in range(10):
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
ans = 0
A = [list(map(int, input().split())) for _ in range(h)]
for i in range(h):
for j in range(w):
if A[i][j] not in [-1, 1]:
ans += dp[A[i][j]][1]
print(ans)
| h, w = list(map(int, input().split()))
C = []
for i in range(10):
C.append(list(map(int, input().split())))
def warshall_floyd(d):
for k in range(10):
for i in range(10):
for j in range(10):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
return d
trans_map = warshall_floyd(C)
ans = 0
for i in range(h):
line = list(map(int, input().split()))
for j in range(w):
num = line[j]
if num == -1:
continue
ans += trans_map[num][1]
print(ans)
| false | 12 | [
"-inf = 1000",
"-dp = []",
"+C = []",
"- c = list(map(int, input().split()))",
"- dp.append(c)",
"-for k in range(10):",
"- for i in range(10):",
"- for j in range(10):",
"- dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])",
"+ C.append(list(map(int, input().split())))",
"+",
"+",
"+def warshall_floyd(d):",
"+ for k in range(10):",
"+ for i in range(10):",
"+ for j in range(10):",
"+ d[i][j] = min(d[i][j], d[i][k] + d[k][j])",
"+ return d",
"+",
"+",
"+trans_map = warshall_floyd(C)",
"-A = [list(map(int, input().split())) for _ in range(h)]",
"+ line = list(map(int, input().split()))",
"- if A[i][j] not in [-1, 1]:",
"- ans += dp[A[i][j]][1]",
"+ num = line[j]",
"+ if num == -1:",
"+ continue",
"+ ans += trans_map[num][1]"
]
| false | 0.139469 | 0.046968 | 2.969424 | [
"s118370391",
"s044715429"
]
|
u588341295 | p02821 | python | s940143174 | s611608542 | 1,500 | 908 | 58,872 | 23,484 | Accepted | Accepted | 39.47 | # -*- coding: utf-8 -*-
import sys
from bisect import bisect_left
from itertools import accumulate
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def bisearch_max(mn, mx, func):
""" ๆกไปถใๆบใใๆๅคงๅคใ่ฆใคใใไบๅๆข็ดข """
ok = mn
ng = mx
while ok+1 < ng:
mid = (ok+ng) // 2
if func(mid):
# ไธใๆขใใซ่กใ
ok = mid
else:
# ไธใๆขใใซ่กใ
ng = mid
return ok
# ๅณๆใจๅทฆๆ(a,b)ใฎๅใxไปฅไธใจใชใ็ตใฎๆฐ
def calc(x):
# ๅaใซใคใใฆใๆกไปถใๆบใใๆฐใๆฐใใ
ans = 0
for a in A:
# ๅผๅคๅฝข๏ผ a + b >= x โ b >= x - a
ans += N - bisect_left(A, x - a)
return ans >= M
N, M = MAP()
A = LIST()
A.sort()
res = bisearch_max(0, 10**10+1, calc)
ans = m = 0
acc = [0] + list(accumulate(A))
for a in A:
idx = bisect_left(A, res - a)
cnt = N - idx
# ๅนธ็ฆๅบฆ
ans += a * cnt + (acc[N] - acc[idx])
# ๆกๆใฎๅๆฐ
m += cnt
# ๅๅคใงMใ่ถ
ใใๅใฎ่ชฟๆด
ans -= res * (m - M)
print(ans)
| # -*- coding: utf-8 -*-
import sys
from bisect import bisect_left
from itertools import accumulate
import numpy as np
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def bisearch_max(mn, mx, func):
""" ๆกไปถใๆบใใๆๅคงๅคใ่ฆใคใใไบๅๆข็ดข """
ok = mn
ng = mx
while ok+1 < ng:
mid = (ok+ng) // 2
if func(mid):
# ไธใๆขใใซ่กใ
ok = mid
else:
# ไธใๆขใใซ่กใ
ng = mid
return ok
# ๅณๆใจๅทฆๆ(a,b)ใฎๅใxไปฅไธใจใชใ็ตใฎๆฐใMไปฅไธใใใ
def calc(x):
# ๆฐๅAใฎไบๅๆข็ดขใใพใจใใฆๅฆ็
res = N - np.searchsorted(A, x - A)
return res.sum() >= M
N, M = MAP()
A = np.array(LIST(), dtype=np.int64)
A.sort()
res = bisearch_max(0, 10**10 + 1, calc)
ans = m = 0
acc = [0] + list(A.cumsum())
for a in A:
idx = bisect_left(A, res - a)
cnt = N - idx
# ๅนธ็ฆๅบฆ
ans += a * cnt + (acc[N] - acc[idx])
# ๆกๆใฎๅๆฐ
m += cnt
# ๅๅคใงMใ่ถ
ใใๅใฎ่ชฟๆด
ans -= res * (m - M)
print(ans)
| 65 | 64 | 1,575 | 1,561 | # -*- coding: utf-8 -*-
import sys
from bisect import bisect_left
from itertools import accumulate
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
def bisearch_max(mn, mx, func):
"""ๆกไปถใๆบใใๆๅคงๅคใ่ฆใคใใไบๅๆข็ดข"""
ok = mn
ng = mx
while ok + 1 < ng:
mid = (ok + ng) // 2
if func(mid):
# ไธใๆขใใซ่กใ
ok = mid
else:
# ไธใๆขใใซ่กใ
ng = mid
return ok
# ๅณๆใจๅทฆๆ(a,b)ใฎๅใxไปฅไธใจใชใ็ตใฎๆฐ
def calc(x):
# ๅaใซใคใใฆใๆกไปถใๆบใใๆฐใๆฐใใ
ans = 0
for a in A:
# ๅผๅคๅฝข๏ผ a + b >= x โ b >= x - a
ans += N - bisect_left(A, x - a)
return ans >= M
N, M = MAP()
A = LIST()
A.sort()
res = bisearch_max(0, 10**10 + 1, calc)
ans = m = 0
acc = [0] + list(accumulate(A))
for a in A:
idx = bisect_left(A, res - a)
cnt = N - idx
# ๅนธ็ฆๅบฆ
ans += a * cnt + (acc[N] - acc[idx])
# ๆกๆใฎๅๆฐ
m += cnt
# ๅๅคใงMใ่ถ
ใใๅใฎ่ชฟๆด
ans -= res * (m - M)
print(ans)
| # -*- coding: utf-8 -*-
import sys
from bisect import bisect_left
from itertools import accumulate
import numpy as np
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
def bisearch_max(mn, mx, func):
"""ๆกไปถใๆบใใๆๅคงๅคใ่ฆใคใใไบๅๆข็ดข"""
ok = mn
ng = mx
while ok + 1 < ng:
mid = (ok + ng) // 2
if func(mid):
# ไธใๆขใใซ่กใ
ok = mid
else:
# ไธใๆขใใซ่กใ
ng = mid
return ok
# ๅณๆใจๅทฆๆ(a,b)ใฎๅใxไปฅไธใจใชใ็ตใฎๆฐใMไปฅไธใใใ
def calc(x):
# ๆฐๅAใฎไบๅๆข็ดขใใพใจใใฆๅฆ็
res = N - np.searchsorted(A, x - A)
return res.sum() >= M
N, M = MAP()
A = np.array(LIST(), dtype=np.int64)
A.sort()
res = bisearch_max(0, 10**10 + 1, calc)
ans = m = 0
acc = [0] + list(A.cumsum())
for a in A:
idx = bisect_left(A, res - a)
cnt = N - idx
# ๅนธ็ฆๅบฆ
ans += a * cnt + (acc[N] - acc[idx])
# ๆกๆใฎๅๆฐ
m += cnt
# ๅๅคใงMใ่ถ
ใใๅใฎ่ชฟๆด
ans -= res * (m - M)
print(ans)
| false | 1.538462 | [
"+import numpy as np",
"-# ๅณๆใจๅทฆๆ(a,b)ใฎๅใxไปฅไธใจใชใ็ตใฎๆฐ",
"+# ๅณๆใจๅทฆๆ(a,b)ใฎๅใxไปฅไธใจใชใ็ตใฎๆฐใMไปฅไธใใใ",
"- # ๅaใซใคใใฆใๆกไปถใๆบใใๆฐใๆฐใใ",
"- ans = 0",
"- for a in A:",
"- # ๅผๅคๅฝข๏ผ a + b >= x โ b >= x - a",
"- ans += N - bisect_left(A, x - a)",
"- return ans >= M",
"+ # ๆฐๅAใฎไบๅๆข็ดขใใพใจใใฆๅฆ็",
"+ res = N - np.searchsorted(A, x - A)",
"+ return res.sum() >= M",
"-A = LIST()",
"+A = np.array(LIST(), dtype=np.int64)",
"-acc = [0] + list(accumulate(A))",
"+acc = [0] + list(A.cumsum())"
]
| false | 0.045351 | 0.233147 | 0.194518 | [
"s940143174",
"s611608542"
]
|
u488401358 | p02763 | python | s075127927 | s346917594 | 456 | 209 | 183,652 | 119,228 | Accepted | Accepted | 54.17 | from collections import deque
class SegmentTree():
def __init__(self,n,ide_ele,merge_func,init_val):
self.n=n
self.ide_ele=ide_ele
self.merge_func=merge_func
self.val=[0 for i in range(1<<n)]
self.merge=[0 for i in range(1<<n)]
self.parent=[-1 for i in range(1<<n)]
deq=deque([1<<(n-1)])
res=[]
while deq:
v=deq.popleft()
res.append(v)
if not v&1:
gap=(v&-v)//2
self.parent[v-gap]=v
deq.append(v-gap)
self.parent[v+gap]=v
deq.append(v+gap)
for v in res[::-1]:
if v-1<len(init_val):
self.val[v-1]=init_val[v-1]
self.merge[v-1]=self.val[v-1]
if not v&1:
gap=(v&-v)//2
self.merge[v-1]=self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1])
def update(self,id,x):
self.val[id]=x
pos=id+1
while pos!=-1:
if pos&1:
self.merge[pos-1]=self.val[pos-1]
else:
gap=(pos&-pos)//2
self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1])
pos=self.parent[pos]
def cnt(self,k):
lsb=(k)&(-k)
return (lsb<<1)-1
def lower_kth_merge(self,nd,k):
res=self.ide_ele
id=nd
if k==-1:
return res
while True:
if not id%2:
gap=((id)&(-id))//2
l=id-gap
r=id+gap
cnt=self.cnt(l)
if cnt<k:
k-=cnt+1
res=self.merge_func(res,self.val[id-1],self.merge[l-1])
id=r
elif cnt==k:
res=self.merge_func(res,self.val[id-1],self.merge[l-1])
return res
else:
id=l
else:
res=self.merge_func(res,self.val[id-1])
return res
def upper_kth_merge(self,nd,k):
res=self.ide_ele
id=nd
if k==-1:
return res
while True:
if not id%2:
gap=((id)&(-id))//2
l=id-gap
r=id+gap
cnt=self.cnt(r)
if cnt<k:
k-=cnt+1
res=self.merge_func(res,self.val[id-1],self.merge[r-1])
id=l
elif cnt==k:
res=self.merge_func(res,self.val[id-1],self.merge[r-1])
return res
else:
id=r
else:
res=self.merge_func(res,self.val[id-1])
return res
def query(self,l,r):
id=1<<(self.n-1)
while True:
if id-1<l:
id+=((id)&(-id))//2
elif id-1>r:
id-=((id)&(-id))//2
else:
res=self.val[id-1]
if id%2:
return res
gap=((id)&(-id))//2
L,R=id-gap,id+gap
#print(l,r,id,L,R)
left=self.upper_kth_merge(L,id-1-l-1)
right=self.lower_kth_merge(R,r-id)
return self.merge_func(res,left,right)
ide_ele=0
def seg_func(*args):
res=ide_ele
for val in args:
res|=val
return res
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
return x & 0x0000007f
import sys
input=sys.stdin.readline
N=int(eval(input()))
S=input().rstrip()
init_val=[1<<(ord(S[i])-97) for i in range(N)]
test=SegmentTree(19,ide_ele,seg_func,init_val)
for _ in range(int(eval(input()))):
t,l,r=input().split()
t,l=int(t),int(l)
if t==1:
val=ord(r)-97
test.update(l-1,1<<val)
else:
r=int(r)
res=test.query(l-1,r-1)
print((popcount(res))) | class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.tree = [ide_ele] * 2 * self.num
# ้
ๅใฎๅคใ่ใซใปใใ
for i in range(n):
self.tree[self.num + i] = init_val[i]
# ๆง็ฏใใฆใใ
for i in range(self.num - 1, 0, -1):
self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, k, x):
k += self.num
self.tree[k] = x
while k > 1:
self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
k >>= 1
def query(self, l, r):
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.tree[l])
l += 1
if r & 1:
res = self.segfunc(res, self.tree[r - 1])
l >>= 1
r >>= 1
return res
ide_ele=0
def segfunc(x,y):
return x|y
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
return x & 0x0000007f
import sys
input=sys.stdin.readline
N=int(eval(input()))
S=input().rstrip()
init_val=[1<<(ord(S[i])-97) for i in range(N)]
test=SegTree(init_val,segfunc,ide_ele)
for _ in range(int(eval(input()))):
t,l,r=input().split()
t,l=int(t),int(l)
if t==1:
val=ord(r)-97
test.update(l-1,1<<val)
else:
r=int(r)
res=test.query(l-1,r)
print((popcount(res)))
| 146 | 69 | 4,231 | 1,753 | from collections import deque
class SegmentTree:
def __init__(self, n, ide_ele, merge_func, init_val):
self.n = n
self.ide_ele = ide_ele
self.merge_func = merge_func
self.val = [0 for i in range(1 << n)]
self.merge = [0 for i in range(1 << n)]
self.parent = [-1 for i in range(1 << n)]
deq = deque([1 << (n - 1)])
res = []
while deq:
v = deq.popleft()
res.append(v)
if not v & 1:
gap = (v & -v) // 2
self.parent[v - gap] = v
deq.append(v - gap)
self.parent[v + gap] = v
deq.append(v + gap)
for v in res[::-1]:
if v - 1 < len(init_val):
self.val[v - 1] = init_val[v - 1]
self.merge[v - 1] = self.val[v - 1]
if not v & 1:
gap = (v & -v) // 2
self.merge[v - 1] = self.merge_func(
self.merge[v - 1], self.merge[v - gap - 1], self.merge[v + gap - 1]
)
def update(self, id, x):
self.val[id] = x
pos = id + 1
while pos != -1:
if pos & 1:
self.merge[pos - 1] = self.val[pos - 1]
else:
gap = (pos & -pos) // 2
self.merge[pos - 1] = self.merge_func(
self.val[pos - 1],
self.merge[pos + gap - 1],
self.merge[pos - gap - 1],
)
pos = self.parent[pos]
def cnt(self, k):
lsb = (k) & (-k)
return (lsb << 1) - 1
def lower_kth_merge(self, nd, k):
res = self.ide_ele
id = nd
if k == -1:
return res
while True:
if not id % 2:
gap = ((id) & (-id)) // 2
l = id - gap
r = id + gap
cnt = self.cnt(l)
if cnt < k:
k -= cnt + 1
res = self.merge_func(res, self.val[id - 1], self.merge[l - 1])
id = r
elif cnt == k:
res = self.merge_func(res, self.val[id - 1], self.merge[l - 1])
return res
else:
id = l
else:
res = self.merge_func(res, self.val[id - 1])
return res
def upper_kth_merge(self, nd, k):
res = self.ide_ele
id = nd
if k == -1:
return res
while True:
if not id % 2:
gap = ((id) & (-id)) // 2
l = id - gap
r = id + gap
cnt = self.cnt(r)
if cnt < k:
k -= cnt + 1
res = self.merge_func(res, self.val[id - 1], self.merge[r - 1])
id = l
elif cnt == k:
res = self.merge_func(res, self.val[id - 1], self.merge[r - 1])
return res
else:
id = r
else:
res = self.merge_func(res, self.val[id - 1])
return res
def query(self, l, r):
id = 1 << (self.n - 1)
while True:
if id - 1 < l:
id += ((id) & (-id)) // 2
elif id - 1 > r:
id -= ((id) & (-id)) // 2
else:
res = self.val[id - 1]
if id % 2:
return res
gap = ((id) & (-id)) // 2
L, R = id - gap, id + gap
# print(l,r,id,L,R)
left = self.upper_kth_merge(L, id - 1 - l - 1)
right = self.lower_kth_merge(R, r - id)
return self.merge_func(res, left, right)
ide_ele = 0
def seg_func(*args):
res = ide_ele
for val in args:
res |= val
return res
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0F0F0F0F
x = x + (x >> 8)
x = x + (x >> 16)
return x & 0x0000007F
import sys
input = sys.stdin.readline
N = int(eval(input()))
S = input().rstrip()
init_val = [1 << (ord(S[i]) - 97) for i in range(N)]
test = SegmentTree(19, ide_ele, seg_func, init_val)
for _ in range(int(eval(input()))):
t, l, r = input().split()
t, l = int(t), int(l)
if t == 1:
val = ord(r) - 97
test.update(l - 1, 1 << val)
else:
r = int(r)
res = test.query(l - 1, r - 1)
print((popcount(res)))
| class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.tree = [ide_ele] * 2 * self.num
# ้
ๅใฎๅคใ่ใซใปใใ
for i in range(n):
self.tree[self.num + i] = init_val[i]
# ๆง็ฏใใฆใใ
for i in range(self.num - 1, 0, -1):
self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, k, x):
k += self.num
self.tree[k] = x
while k > 1:
self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
k >>= 1
def query(self, l, r):
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.tree[l])
l += 1
if r & 1:
res = self.segfunc(res, self.tree[r - 1])
l >>= 1
r >>= 1
return res
ide_ele = 0
def segfunc(x, y):
return x | y
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0F0F0F0F
x = x + (x >> 8)
x = x + (x >> 16)
return x & 0x0000007F
import sys
input = sys.stdin.readline
N = int(eval(input()))
S = input().rstrip()
init_val = [1 << (ord(S[i]) - 97) for i in range(N)]
test = SegTree(init_val, segfunc, ide_ele)
for _ in range(int(eval(input()))):
t, l, r = input().split()
t, l = int(t), int(l)
if t == 1:
val = ord(r) - 97
test.update(l - 1, 1 << val)
else:
r = int(r)
res = test.query(l - 1, r)
print((popcount(res)))
| false | 52.739726 | [
"-from collections import deque",
"+class SegTree:",
"+ def __init__(self, init_val, segfunc, ide_ele):",
"+ n = len(init_val)",
"+ self.segfunc = segfunc",
"+ self.ide_ele = ide_ele",
"+ self.num = 1 << (n - 1).bit_length()",
"+ self.tree = [ide_ele] * 2 * self.num",
"+ # ้
ๅใฎๅคใ่ใซใปใใ",
"+ for i in range(n):",
"+ self.tree[self.num + i] = init_val[i]",
"+ # ๆง็ฏใใฆใใ",
"+ for i in range(self.num - 1, 0, -1):",
"+ self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])",
"-",
"-class SegmentTree:",
"- def __init__(self, n, ide_ele, merge_func, init_val):",
"- self.n = n",
"- self.ide_ele = ide_ele",
"- self.merge_func = merge_func",
"- self.val = [0 for i in range(1 << n)]",
"- self.merge = [0 for i in range(1 << n)]",
"- self.parent = [-1 for i in range(1 << n)]",
"- deq = deque([1 << (n - 1)])",
"- res = []",
"- while deq:",
"- v = deq.popleft()",
"- res.append(v)",
"- if not v & 1:",
"- gap = (v & -v) // 2",
"- self.parent[v - gap] = v",
"- deq.append(v - gap)",
"- self.parent[v + gap] = v",
"- deq.append(v + gap)",
"- for v in res[::-1]:",
"- if v - 1 < len(init_val):",
"- self.val[v - 1] = init_val[v - 1]",
"- self.merge[v - 1] = self.val[v - 1]",
"- if not v & 1:",
"- gap = (v & -v) // 2",
"- self.merge[v - 1] = self.merge_func(",
"- self.merge[v - 1], self.merge[v - gap - 1], self.merge[v + gap - 1]",
"- )",
"-",
"- def update(self, id, x):",
"- self.val[id] = x",
"- pos = id + 1",
"- while pos != -1:",
"- if pos & 1:",
"- self.merge[pos - 1] = self.val[pos - 1]",
"- else:",
"- gap = (pos & -pos) // 2",
"- self.merge[pos - 1] = self.merge_func(",
"- self.val[pos - 1],",
"- self.merge[pos + gap - 1],",
"- self.merge[pos - gap - 1],",
"- )",
"- pos = self.parent[pos]",
"-",
"- def cnt(self, k):",
"- lsb = (k) & (-k)",
"- return (lsb << 1) - 1",
"-",
"- def lower_kth_merge(self, nd, k):",
"- res = self.ide_ele",
"- id = nd",
"- if k == -1:",
"- return res",
"- while True:",
"- if not id % 2:",
"- gap = ((id) & (-id)) // 2",
"- l = id - gap",
"- r = id + gap",
"- cnt = self.cnt(l)",
"- if cnt < k:",
"- k -= cnt + 1",
"- res = self.merge_func(res, self.val[id - 1], self.merge[l - 1])",
"- id = r",
"- elif cnt == k:",
"- res = self.merge_func(res, self.val[id - 1], self.merge[l - 1])",
"- return res",
"- else:",
"- id = l",
"- else:",
"- res = self.merge_func(res, self.val[id - 1])",
"- return res",
"-",
"- def upper_kth_merge(self, nd, k):",
"- res = self.ide_ele",
"- id = nd",
"- if k == -1:",
"- return res",
"- while True:",
"- if not id % 2:",
"- gap = ((id) & (-id)) // 2",
"- l = id - gap",
"- r = id + gap",
"- cnt = self.cnt(r)",
"- if cnt < k:",
"- k -= cnt + 1",
"- res = self.merge_func(res, self.val[id - 1], self.merge[r - 1])",
"- id = l",
"- elif cnt == k:",
"- res = self.merge_func(res, self.val[id - 1], self.merge[r - 1])",
"- return res",
"- else:",
"- id = r",
"- else:",
"- res = self.merge_func(res, self.val[id - 1])",
"- return res",
"+ def update(self, k, x):",
"+ k += self.num",
"+ self.tree[k] = x",
"+ while k > 1:",
"+ self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])",
"+ k >>= 1",
"- id = 1 << (self.n - 1)",
"- while True:",
"- if id - 1 < l:",
"- id += ((id) & (-id)) // 2",
"- elif id - 1 > r:",
"- id -= ((id) & (-id)) // 2",
"- else:",
"- res = self.val[id - 1]",
"- if id % 2:",
"- return res",
"- gap = ((id) & (-id)) // 2",
"- L, R = id - gap, id + gap",
"- # print(l,r,id,L,R)",
"- left = self.upper_kth_merge(L, id - 1 - l - 1)",
"- right = self.lower_kth_merge(R, r - id)",
"- return self.merge_func(res, left, right)",
"+ res = self.ide_ele",
"+ l += self.num",
"+ r += self.num",
"+ while l < r:",
"+ if l & 1:",
"+ res = self.segfunc(res, self.tree[l])",
"+ l += 1",
"+ if r & 1:",
"+ res = self.segfunc(res, self.tree[r - 1])",
"+ l >>= 1",
"+ r >>= 1",
"+ return res",
"-def seg_func(*args):",
"- res = ide_ele",
"- for val in args:",
"- res |= val",
"- return res",
"+def segfunc(x, y):",
"+ return x | y",
"-test = SegmentTree(19, ide_ele, seg_func, init_val)",
"+test = SegTree(init_val, segfunc, ide_ele)",
"- res = test.query(l - 1, r - 1)",
"+ res = test.query(l - 1, r)"
]
| false | 0.706513 | 0.080624 | 8.763111 | [
"s075127927",
"s346917594"
]
|
u207799478 | p03564 | python | s515688653 | s564626679 | 286 | 41 | 60,140 | 10,560 | Accepted | Accepted | 85.66 | import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
def readints():
return list(map(int, input().split()))
def nCr(n, r):
return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
def has_duplicates2(seq):
seen = []
for item in seq:
if not(item in seen):
seen.append(item)
return len(seq) != len(seen)
def divisor(n):
divisor = []
for i in range(1, n+1):
if n % i == 0:
divisor.append(i)
return divisor
# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(eval(input()))
k = int(eval(input()))
ans = 1
for i in range(n):
if ans+k < ans*2:
ans = ans+k
else:
ans = ans*2
print(ans)
| from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy
def readints():
return list(map(int, input().split()))
def nCr(n, r):
return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
def has_duplicates2(seq):
seen = []
for item in seq:
if not(item in seen):
seen.append(item)
return len(seq) != len(seen)
def divisor(n):
divisor = []
for i in range(1, n+1):
if n % i == 0:
divisor.append(i)
return divisor
def gcd(a, b):
while(b != 0):
a, b = b, a % b
return a
# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(eval(input()))
k = int(eval(input()))
ans = 1
for i in range(n):
ans = min(ans*2, ans+k)
print(ans)
| 44 | 54 | 843 | 998 | import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
def readints():
return list(map(int, input().split()))
def nCr(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def has_duplicates2(seq):
seen = []
for item in seq:
if not (item in seen):
seen.append(item)
return len(seq) != len(seen)
def divisor(n):
divisor = []
for i in range(1, n + 1):
if n % i == 0:
divisor.append(i)
return divisor
# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(eval(input()))
k = int(eval(input()))
ans = 1
for i in range(n):
if ans + k < ans * 2:
ans = ans + k
else:
ans = ans * 2
print(ans)
| from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy
def readints():
return list(map(int, input().split()))
def nCr(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def has_duplicates2(seq):
seen = []
for item in seq:
if not (item in seen):
seen.append(item)
return len(seq) != len(seen)
def divisor(n):
divisor = []
for i in range(1, n + 1):
if n % i == 0:
divisor.append(i)
return divisor
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(eval(input()))
k = int(eval(input()))
ans = 1
for i in range(n):
ans = min(ans * 2, ans + k)
print(ans)
| false | 18.518519 | [
"+from copy import deepcopy",
"+import sys",
"+import fractions",
"+from operator import itemgetter",
"+import itertools",
"+import copy",
"+def gcd(a, b):",
"+ while b != 0:",
"+ a, b = b, a % b",
"+ return a",
"+",
"+",
"- if ans + k < ans * 2:",
"- ans = ans + k",
"- else:",
"- ans = ans * 2",
"+ ans = min(ans * 2, ans + k)"
]
| false | 0.036462 | 0.04234 | 0.861161 | [
"s515688653",
"s564626679"
]
|
u562935282 | p02658 | python | s560217554 | s743420366 | 1,606 | 55 | 22,036 | 21,760 | Accepted | Accepted | 96.58 | # https://atcoder.jp/contests/abc169/submissions/13893064
def main():
from itertools import zip_longest
LIMIT = 10 ** 18
N = int(eval(input()))
*A, = list(map(int, input().split()))
while len(A) > 1:
A = [x * y for x, y in zip_longest(A[::2], A[1::2], fillvalue=1)]
if A[0] > LIMIT:
print((-1))
else:
print((A[0]))
if __name__ == '__main__':
main()
| def main():
N = int(eval(input()))
*A, = list(map(int, input().split()))
if 0 in A:
print((0))
return
t = 1
for x in A:
t *= x
if t > 10 ** 18:
print((-1))
return
print(t)
if __name__ == '__main__':
main()
| 21 | 19 | 416 | 296 | # https://atcoder.jp/contests/abc169/submissions/13893064
def main():
from itertools import zip_longest
LIMIT = 10**18
N = int(eval(input()))
(*A,) = list(map(int, input().split()))
while len(A) > 1:
A = [x * y for x, y in zip_longest(A[::2], A[1::2], fillvalue=1)]
if A[0] > LIMIT:
print((-1))
else:
print((A[0]))
if __name__ == "__main__":
main()
| def main():
N = int(eval(input()))
(*A,) = list(map(int, input().split()))
if 0 in A:
print((0))
return
t = 1
for x in A:
t *= x
if t > 10**18:
print((-1))
return
print(t)
if __name__ == "__main__":
main()
| false | 9.52381 | [
"-# https://atcoder.jp/contests/abc169/submissions/13893064",
"- from itertools import zip_longest",
"-",
"- LIMIT = 10**18",
"- while len(A) > 1:",
"- A = [x * y for x, y in zip_longest(A[::2], A[1::2], fillvalue=1)]",
"- if A[0] > LIMIT:",
"- print((-1))",
"- else:",
"- print((A[0]))",
"+ if 0 in A:",
"+ print((0))",
"+ return",
"+ t = 1",
"+ for x in A:",
"+ t *= x",
"+ if t > 10**18:",
"+ print((-1))",
"+ return",
"+ print(t)"
]
| false | 0.125223 | 0.034613 | 3.617803 | [
"s560217554",
"s743420366"
]
|
u678167152 | p02939 | python | s895595878 | s944078722 | 84 | 63 | 14,264 | 9,284 | Accepted | Accepted | 25 | S = eval(input())
lis = [S[0]]
i = 1
while i<len(S)-1:
if S[i]==lis[-1]:
lis.append(S[i:i+2])
i += 2
else:
lis.append(S[i])
i += 1
ans = len(lis)
if i==len(S)-1 and S[i]!=lis[-1]:
ans += 1
print(ans) | def solve():
S = eval(input())
ans = 0
now = ''
i = 0
while i<len(S)-1:
if S[i]==now:
now += S[i+1]
i += 1
else:
now = S[i]
i += 1
ans += 1
if i==len(S)-1 and now!=S[i]:
ans += 1
return ans
print((solve())) | 14 | 17 | 228 | 266 | S = eval(input())
lis = [S[0]]
i = 1
while i < len(S) - 1:
if S[i] == lis[-1]:
lis.append(S[i : i + 2])
i += 2
else:
lis.append(S[i])
i += 1
ans = len(lis)
if i == len(S) - 1 and S[i] != lis[-1]:
ans += 1
print(ans)
| def solve():
S = eval(input())
ans = 0
now = ""
i = 0
while i < len(S) - 1:
if S[i] == now:
now += S[i + 1]
i += 1
else:
now = S[i]
i += 1
ans += 1
if i == len(S) - 1 and now != S[i]:
ans += 1
return ans
print((solve()))
| false | 17.647059 | [
"-S = eval(input())",
"-lis = [S[0]]",
"-i = 1",
"-while i < len(S) - 1:",
"- if S[i] == lis[-1]:",
"- lis.append(S[i : i + 2])",
"- i += 2",
"- else:",
"- lis.append(S[i])",
"+def solve():",
"+ S = eval(input())",
"+ ans = 0",
"+ now = \"\"",
"+ i = 0",
"+ while i < len(S) - 1:",
"+ if S[i] == now:",
"+ now += S[i + 1]",
"+ i += 1",
"+ else:",
"+ now = S[i]",
"-ans = len(lis)",
"-if i == len(S) - 1 and S[i] != lis[-1]:",
"- ans += 1",
"-print(ans)",
"+ ans += 1",
"+ if i == len(S) - 1 and now != S[i]:",
"+ ans += 1",
"+ return ans",
"+",
"+",
"+print((solve()))"
]
| false | 0.11881 | 0.068096 | 1.744745 | [
"s895595878",
"s944078722"
]
|
u952708174 | p03060 | python | s666997617 | s220175924 | 496 | 17 | 42,220 | 2,940 | Accepted | Accepted | 96.57 | N = int(eval(input()))
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ans = -float('inf')
d = len(V)
for b in range(2 ** d):
tmp = 0
for j in range(d):
if ((b >> j) & 1):
tmp += V[j] - C[j]
ans = max(ans, tmp)
print(ans)
| N = int(eval(input()))
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print((sum([v - c for v, c in zip(V, C) if v - c >= 0]))) | 13 | 5 | 289 | 153 | N = int(eval(input()))
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ans = -float("inf")
d = len(V)
for b in range(2**d):
tmp = 0
for j in range(d):
if (b >> j) & 1:
tmp += V[j] - C[j]
ans = max(ans, tmp)
print(ans)
| N = int(eval(input()))
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print((sum([v - c for v, c in zip(V, C) if v - c >= 0])))
| false | 61.538462 | [
"-ans = -float(\"inf\")",
"-d = len(V)",
"-for b in range(2**d):",
"- tmp = 0",
"- for j in range(d):",
"- if (b >> j) & 1:",
"- tmp += V[j] - C[j]",
"- ans = max(ans, tmp)",
"-print(ans)",
"+print((sum([v - c for v, c in zip(V, C) if v - c >= 0])))"
]
| false | 0.10719 | 0.036177 | 2.96289 | [
"s666997617",
"s220175924"
]
|
u859897687 | p02981 | python | s163696849 | s008918264 | 178 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90.45 | n,a,b=list(map(int,input().split()))
print((n*a if n*a<b else b)) | n,a,b=list(map(int,input().split()))
print((min(n*a,b))) | 2 | 2 | 58 | 49 | n, a, b = list(map(int, input().split()))
print((n * a if n * a < b else b))
| n, a, b = list(map(int, input().split()))
print((min(n * a, b)))
| false | 0 | [
"-print((n * a if n * a < b else b))",
"+print((min(n * a, b)))"
]
| false | 0.068067 | 0.038 | 1.791233 | [
"s163696849",
"s008918264"
]
|
u771917453 | p02412 | python | s556171972 | s827071187 | 360 | 320 | 6,368 | 6,452 | Accepted | Accepted | 11.11 | while True:
n,x= list(map(int,input().split()))
if n == x == 0:
break
count = 0
for i in range(1,n-1):
for j in range(i+1,n):
for k in range(j+1,n+1):
if i + j + k == x:
count = count + 1
break
print(count) | while True:
n,x= list(map(int,input().split()))
if n == x == 0:
break
count = 0
for i in range(1,n-1):
for j in range(i+1,n):
for k in range(j+1,n+1):
s = i + j + k
if s == x:
count = count + 1
break
elif s > x:
break
print(count) | 14 | 17 | 324 | 404 | while True:
n, x = list(map(int, input().split()))
if n == x == 0:
break
count = 0
for i in range(1, n - 1):
for j in range(i + 1, n):
for k in range(j + 1, n + 1):
if i + j + k == x:
count = count + 1
break
print(count)
| while True:
n, x = list(map(int, input().split()))
if n == x == 0:
break
count = 0
for i in range(1, n - 1):
for j in range(i + 1, n):
for k in range(j + 1, n + 1):
s = i + j + k
if s == x:
count = count + 1
break
elif s > x:
break
print(count)
| false | 17.647059 | [
"- if i + j + k == x:",
"+ s = i + j + k",
"+ if s == x:",
"+ elif s > x:",
"+ break"
]
| false | 0.035913 | 0.037338 | 0.961832 | [
"s556171972",
"s827071187"
]
|
u536034761 | p02833 | python | s936930551 | s296886312 | 27 | 24 | 9,084 | 9,064 | Accepted | Accepted | 11.11 | n = int(eval(input()))
if n & 1:
print((0))
else:
ans = 0
x = 10
while n >= x:
ans += n // x
x *= 5
print(ans)
| n = int(eval(input()))
i = 10
ans = 0
while i <= n:
ans += (n // i)
i *= 5
print((ans if n & 1 == 0 else 0))
| 10 | 9 | 148 | 120 | n = int(eval(input()))
if n & 1:
print((0))
else:
ans = 0
x = 10
while n >= x:
ans += n // x
x *= 5
print(ans)
| n = int(eval(input()))
i = 10
ans = 0
while i <= n:
ans += n // i
i *= 5
print((ans if n & 1 == 0 else 0))
| false | 10 | [
"-if n & 1:",
"- print((0))",
"-else:",
"- ans = 0",
"- x = 10",
"- while n >= x:",
"- ans += n // x",
"- x *= 5",
"- print(ans)",
"+i = 10",
"+ans = 0",
"+while i <= n:",
"+ ans += n // i",
"+ i *= 5",
"+print((ans if n & 1 == 0 else 0))"
]
| false | 0.038719 | 0.037582 | 1.030244 | [
"s936930551",
"s296886312"
]
|
u886921509 | p02700 | python | s177046538 | s061038998 | 65 | 29 | 61,864 | 9,164 | Accepted | Accepted | 55.38 | import sys
A, B, C, D = list(map(int, input().split()))
while A > 0 or B > 0:
C = C - B
if C <= 0:
print("Yes")
sys.exit()
A = A - D
if A <= 0:
print("No")
sys.exit() | A, B, C, D = list(map(int, input().split()))
while A > 0 or B > 0:
C = C - B
if C <= 0:
print("Yes")
break
A = A - D
if A <= 0:
print("No")
break | 12 | 10 | 220 | 196 | import sys
A, B, C, D = list(map(int, input().split()))
while A > 0 or B > 0:
C = C - B
if C <= 0:
print("Yes")
sys.exit()
A = A - D
if A <= 0:
print("No")
sys.exit()
| A, B, C, D = list(map(int, input().split()))
while A > 0 or B > 0:
C = C - B
if C <= 0:
print("Yes")
break
A = A - D
if A <= 0:
print("No")
break
| false | 16.666667 | [
"-import sys",
"-",
"- sys.exit()",
"+ break",
"- sys.exit()",
"+ break"
]
| false | 0.03565 | 0.061766 | 0.577181 | [
"s177046538",
"s061038998"
]
|
u808427016 | p03112 | python | s985161255 | s770186670 | 1,275 | 1,140 | 24,876 | 25,196 | Accepted | Accepted | 10.59 | A, B, Q = [int(_) for _ in input().split()]
S = [int(eval(input())) for i in range(A)]
T = [int(eval(input())) for i in range(B)]
Q = [int(eval(input())) for i in range(Q)]
#print(S, T, Q)
def calc_m(xs):
return [(a + b) / 2 for a, b in zip(xs, xs[1:])]
sm = calc_m(S)
tm = calc_m(T)
#print(sm)
#print(tm)
import bisect
def calc_nearest_0(xs, y, ym):
result = []
i = 0
for x in xs:
while i < len(ym) and x >= ym[i]:
i += 1
result.append(y[i])
return result
def calc_nearest(xs, y, ym):
result = []
for x in xs:
i = bisect.bisect(ym, x)
result.append(y[i])
return result
sn = calc_nearest(S, T, tm)
tn = calc_nearest(T, S, sm)
#print(sn)
#print(tn)
def solve(q, S, T, sn, tn):
nsp = bisect.bisect(S, q)
ntp = bisect.bisect(T, q)
rs = []
if 0 <= nsp < len(S):
rs.append(abs(S[nsp] - q) + abs(S[nsp] - sn[nsp]))
nsp -= 1
if 0 <= nsp < len(S):
rs.append(abs(S[nsp] - q) + abs(S[nsp] - sn[nsp]))
if 0 <= ntp < len(T):
rs.append(abs(T[ntp] - q) + abs(T[ntp] - tn[ntp]))
ntp -= 1
if 0 <= ntp < len(T):
rs.append(abs(T[ntp] - q) + abs(T[ntp] - tn[ntp]))
# print("Q", q, S, T, sn, tn, r1, r2)
return min(rs)
for q in Q:
print((solve(q, S, T, sn, tn)))
| A, B, Q = [int(_) for _ in input().split()]
S = [int(eval(input())) for i in range(A)]
T = [int(eval(input())) for i in range(B)]
Q = [int(eval(input())) for i in range(Q)]
import bisect
def calc_nearest_distance(xs, ys):
result = []
for x in xs:
i = bisect.bisect(ys, x)
if i == 0:
d = abs(ys[i] - x)
elif i < len(ys):
d = min(abs(ys[i - 1] - x), abs(ys[i] - x))
else:
d = abs(ys[i - 1] - x)
result.append(d)
return result
sn = calc_nearest_distance(S, T)
tn = calc_nearest_distance(T, S)
def solve(q, S, T, sn, tn):
nsp = bisect.bisect(S, q)
ntp = bisect.bisect(T, q)
rs = []
if 0 <= nsp < len(S):
rs.append(abs(S[nsp] - q) + sn[nsp])
if 0 <= nsp - 1 < len(S):
rs.append(abs(S[nsp - 1] - q) + sn[nsp - 1])
if 0 <= ntp < len(T):
rs.append(abs(T[ntp] - q) + tn[ntp])
if 0 <= ntp - 1 < len(T):
rs.append(abs(T[ntp - 1] - q) + tn[ntp - 1])
return min(rs)
for q in Q:
print((solve(q, S, T, sn, tn)))
| 63 | 43 | 1,356 | 1,084 | A, B, Q = [int(_) for _ in input().split()]
S = [int(eval(input())) for i in range(A)]
T = [int(eval(input())) for i in range(B)]
Q = [int(eval(input())) for i in range(Q)]
# print(S, T, Q)
def calc_m(xs):
return [(a + b) / 2 for a, b in zip(xs, xs[1:])]
sm = calc_m(S)
tm = calc_m(T)
# print(sm)
# print(tm)
import bisect
def calc_nearest_0(xs, y, ym):
result = []
i = 0
for x in xs:
while i < len(ym) and x >= ym[i]:
i += 1
result.append(y[i])
return result
def calc_nearest(xs, y, ym):
result = []
for x in xs:
i = bisect.bisect(ym, x)
result.append(y[i])
return result
sn = calc_nearest(S, T, tm)
tn = calc_nearest(T, S, sm)
# print(sn)
# print(tn)
def solve(q, S, T, sn, tn):
nsp = bisect.bisect(S, q)
ntp = bisect.bisect(T, q)
rs = []
if 0 <= nsp < len(S):
rs.append(abs(S[nsp] - q) + abs(S[nsp] - sn[nsp]))
nsp -= 1
if 0 <= nsp < len(S):
rs.append(abs(S[nsp] - q) + abs(S[nsp] - sn[nsp]))
if 0 <= ntp < len(T):
rs.append(abs(T[ntp] - q) + abs(T[ntp] - tn[ntp]))
ntp -= 1
if 0 <= ntp < len(T):
rs.append(abs(T[ntp] - q) + abs(T[ntp] - tn[ntp]))
# print("Q", q, S, T, sn, tn, r1, r2)
return min(rs)
for q in Q:
print((solve(q, S, T, sn, tn)))
| A, B, Q = [int(_) for _ in input().split()]
S = [int(eval(input())) for i in range(A)]
T = [int(eval(input())) for i in range(B)]
Q = [int(eval(input())) for i in range(Q)]
import bisect
def calc_nearest_distance(xs, ys):
result = []
for x in xs:
i = bisect.bisect(ys, x)
if i == 0:
d = abs(ys[i] - x)
elif i < len(ys):
d = min(abs(ys[i - 1] - x), abs(ys[i] - x))
else:
d = abs(ys[i - 1] - x)
result.append(d)
return result
sn = calc_nearest_distance(S, T)
tn = calc_nearest_distance(T, S)
def solve(q, S, T, sn, tn):
nsp = bisect.bisect(S, q)
ntp = bisect.bisect(T, q)
rs = []
if 0 <= nsp < len(S):
rs.append(abs(S[nsp] - q) + sn[nsp])
if 0 <= nsp - 1 < len(S):
rs.append(abs(S[nsp - 1] - q) + sn[nsp - 1])
if 0 <= ntp < len(T):
rs.append(abs(T[ntp] - q) + tn[ntp])
if 0 <= ntp - 1 < len(T):
rs.append(abs(T[ntp - 1] - q) + tn[ntp - 1])
return min(rs)
for q in Q:
print((solve(q, S, T, sn, tn)))
| false | 31.746032 | [
"-# print(S, T, Q)",
"-def calc_m(xs):",
"- return [(a + b) / 2 for a, b in zip(xs, xs[1:])]",
"-",
"-",
"-sm = calc_m(S)",
"-tm = calc_m(T)",
"-# print(sm)",
"-# print(tm)",
"-def calc_nearest_0(xs, y, ym):",
"+def calc_nearest_distance(xs, ys):",
"- i = 0",
"- while i < len(ym) and x >= ym[i]:",
"- i += 1",
"- result.append(y[i])",
"+ i = bisect.bisect(ys, x)",
"+ if i == 0:",
"+ d = abs(ys[i] - x)",
"+ elif i < len(ys):",
"+ d = min(abs(ys[i - 1] - x), abs(ys[i] - x))",
"+ else:",
"+ d = abs(ys[i - 1] - x)",
"+ result.append(d)",
"-def calc_nearest(xs, y, ym):",
"- result = []",
"- for x in xs:",
"- i = bisect.bisect(ym, x)",
"- result.append(y[i])",
"- return result",
"+sn = calc_nearest_distance(S, T)",
"+tn = calc_nearest_distance(T, S)",
"-sn = calc_nearest(S, T, tm)",
"-tn = calc_nearest(T, S, sm)",
"-# print(sn)",
"-# print(tn)",
"- rs.append(abs(S[nsp] - q) + abs(S[nsp] - sn[nsp]))",
"- nsp -= 1",
"- if 0 <= nsp < len(S):",
"- rs.append(abs(S[nsp] - q) + abs(S[nsp] - sn[nsp]))",
"+ rs.append(abs(S[nsp] - q) + sn[nsp])",
"+ if 0 <= nsp - 1 < len(S):",
"+ rs.append(abs(S[nsp - 1] - q) + sn[nsp - 1])",
"- rs.append(abs(T[ntp] - q) + abs(T[ntp] - tn[ntp]))",
"- ntp -= 1",
"- if 0 <= ntp < len(T):",
"- rs.append(abs(T[ntp] - q) + abs(T[ntp] - tn[ntp]))",
"- # print(\"Q\", q, S, T, sn, tn, r1, r2)",
"+ rs.append(abs(T[ntp] - q) + tn[ntp])",
"+ if 0 <= ntp - 1 < len(T):",
"+ rs.append(abs(T[ntp - 1] - q) + tn[ntp - 1])"
]
| false | 0.047774 | 0.047255 | 1.010984 | [
"s985161255",
"s770186670"
]
|
u759412327 | p03739 | python | s593403528 | s318089927 | 121 | 107 | 14,332 | 19,920 | Accepted | Accepted | 11.57 | n = int(eval(input()))
A = list(map(int,input().split()))
ans = 10**15
for i in [-1,1]:
ansi,sum=0,0
for a in A:
sum+=a
if sum*i<=0:
ansi+=abs(sum-i)
sum=i
i*=-1
ans=min(ans,ansi)
print(ans) | N = int(eval(input()))
A = list(map(int,input().split()))
ans = 10**15
for s in [1,-1]:
cos = 0
tot = 0
for a in A:
tot+=a
if s*tot<=0:
cos+=abs(tot-s)
tot=s
s*=-1
ans=min(ans,cos)
print(ans) | 14 | 18 | 254 | 242 | n = int(eval(input()))
A = list(map(int, input().split()))
ans = 10**15
for i in [-1, 1]:
ansi, sum = 0, 0
for a in A:
sum += a
if sum * i <= 0:
ansi += abs(sum - i)
sum = i
i *= -1
ans = min(ans, ansi)
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
ans = 10**15
for s in [1, -1]:
cos = 0
tot = 0
for a in A:
tot += a
if s * tot <= 0:
cos += abs(tot - s)
tot = s
s *= -1
ans = min(ans, cos)
print(ans)
| false | 22.222222 | [
"-n = int(eval(input()))",
"+N = int(eval(input()))",
"-for i in [-1, 1]:",
"- ansi, sum = 0, 0",
"+for s in [1, -1]:",
"+ cos = 0",
"+ tot = 0",
"- sum += a",
"- if sum * i <= 0:",
"- ansi += abs(sum - i)",
"- sum = i",
"- i *= -1",
"- ans = min(ans, ansi)",
"+ tot += a",
"+ if s * tot <= 0:",
"+ cos += abs(tot - s)",
"+ tot = s",
"+ s *= -1",
"+ ans = min(ans, cos)"
]
| false | 0.034748 | 0.036319 | 0.95676 | [
"s593403528",
"s318089927"
]
|
u537905693 | p02887 | python | s900422828 | s978599235 | 33 | 25 | 3,316 | 3,316 | Accepted | Accepted | 24.24 | #!/usr/bin/env python
# coding: utf-8
def ri():
return int(eval(input()))
def rl():
return list(input().split())
def rli():
return list(map(int, input().split()))
def main():
n = ri()
s = eval(input())
ans = 1
for i in range(1, len(s)):
if s[i] == s[i-1]:
continue
ans += 1
print(ans)
if __name__ == '__main__':
main()
| #!/usr/bin/env python
# coding: utf-8
def ri():
return int(eval(input()))
def rl():
return list(input().split())
def rli():
return list(map(int, input().split()))
def main():
n = ri()
s = eval(input())
bc = '!'
ans = 0
for c in s:
if c != bc:
ans += 1
bc = c
print(ans)
if __name__ == '__main__':
main()
| 25 | 26 | 401 | 391 | #!/usr/bin/env python
# coding: utf-8
def ri():
return int(eval(input()))
def rl():
return list(input().split())
def rli():
return list(map(int, input().split()))
def main():
n = ri()
s = eval(input())
ans = 1
for i in range(1, len(s)):
if s[i] == s[i - 1]:
continue
ans += 1
print(ans)
if __name__ == "__main__":
main()
| #!/usr/bin/env python
# coding: utf-8
def ri():
return int(eval(input()))
def rl():
return list(input().split())
def rli():
return list(map(int, input().split()))
def main():
n = ri()
s = eval(input())
bc = "!"
ans = 0
for c in s:
if c != bc:
ans += 1
bc = c
print(ans)
if __name__ == "__main__":
main()
| false | 3.846154 | [
"- ans = 1",
"- for i in range(1, len(s)):",
"- if s[i] == s[i - 1]:",
"- continue",
"- ans += 1",
"+ bc = \"!\"",
"+ ans = 0",
"+ for c in s:",
"+ if c != bc:",
"+ ans += 1",
"+ bc = c"
]
| false | 0.043073 | 0.044379 | 0.970574 | [
"s900422828",
"s978599235"
]
|
u977141657 | p02802 | python | s031039868 | s376310539 | 445 | 295 | 35,804 | 4,596 | Accepted | Accepted | 33.71 | import sys
N, M = list(map(int, input().split()))
if M == 0:
print((0, 0))
sys.exit()
p_S = []
for _ in range(M):
p_S.append(input().split())
p = []
S = []
for i in range(M):
p_S[i][0] = int(p_S[i][0])
p_S[i][1] = int(p_S[i][1] =='AC')
p_S.sort(key=lambda x: x[0])
for i in range(M):
p.append(p_S[i][0])
S.append(p_S[i][1])
p = list(map(int, p))
S = list(map(int, S))
flag_p = p[0]
flag_ac = 0
AC_sum = 0
WA_sum = 0
WA = 0
for i in range(M):
if flag_p == p[i]:
if S[i] == 0 and flag_ac == 0:
WA += 1
elif S[i] == 1 and flag_ac == 0:
AC_sum += 1
WA_sum += WA
flag_ac = 1
else:
flag_p = p[i]
flag_ac = 0
WA = 0
if S[i] == 0 and flag_ac == 0:
WA += 1
elif S[i] == 1 and flag_ac == 0:
AC_sum += 1
WA_sum += WA
flag_ac = 1
print((AC_sum, WA_sum)) | n,m=list(map(int,input().split()))
ac=[0]*n
wa=[0]*n
for i in range(m):
p,s=input().split()
p=int(p)
if ac[p-1] == 1:#ใใฎใในใใใฏใชใขใใฆใใใ้ฃใฐใใ
continue
if s=='AC':#ใในใใใฏใชใขใใใใใฉใฐใใคใใ
ac[p-1] = 1
else:#ใในใใใฏใชใขใใใพใงใฏๅคฑๆใ็นฐใ่ฟใใ
wa[p-1] += 1
# ๆ็ต็ใซๅบๅใใใใฎใๆฑบใใ
AC=0
WA=0
for i in range(n):
AC += ac[i]#ใฏใชใขใใๅๆฐ
if ac[i] == 1:
WA += wa[i]#ใฏใชใขใงใใชใใฃใๅๆฐ
print(("{} {}".format(AC,WA))) | 55 | 22 | 993 | 448 | import sys
N, M = list(map(int, input().split()))
if M == 0:
print((0, 0))
sys.exit()
p_S = []
for _ in range(M):
p_S.append(input().split())
p = []
S = []
for i in range(M):
p_S[i][0] = int(p_S[i][0])
p_S[i][1] = int(p_S[i][1] == "AC")
p_S.sort(key=lambda x: x[0])
for i in range(M):
p.append(p_S[i][0])
S.append(p_S[i][1])
p = list(map(int, p))
S = list(map(int, S))
flag_p = p[0]
flag_ac = 0
AC_sum = 0
WA_sum = 0
WA = 0
for i in range(M):
if flag_p == p[i]:
if S[i] == 0 and flag_ac == 0:
WA += 1
elif S[i] == 1 and flag_ac == 0:
AC_sum += 1
WA_sum += WA
flag_ac = 1
else:
flag_p = p[i]
flag_ac = 0
WA = 0
if S[i] == 0 and flag_ac == 0:
WA += 1
elif S[i] == 1 and flag_ac == 0:
AC_sum += 1
WA_sum += WA
flag_ac = 1
print((AC_sum, WA_sum))
| n, m = list(map(int, input().split()))
ac = [0] * n
wa = [0] * n
for i in range(m):
p, s = input().split()
p = int(p)
if ac[p - 1] == 1: # ใใฎใในใใใฏใชใขใใฆใใใ้ฃใฐใใ
continue
if s == "AC": # ใในใใใฏใชใขใใใใใฉใฐใใคใใ
ac[p - 1] = 1
else: # ใในใใใฏใชใขใใใพใงใฏๅคฑๆใ็นฐใ่ฟใใ
wa[p - 1] += 1
# ๆ็ต็ใซๅบๅใใใใฎใๆฑบใใ
AC = 0
WA = 0
for i in range(n):
AC += ac[i] # ใฏใชใขใใๅๆฐ
if ac[i] == 1:
WA += wa[i] # ใฏใชใขใงใใชใใฃใๅๆฐ
print(("{} {}".format(AC, WA)))
| false | 60 | [
"-import sys",
"-",
"-N, M = list(map(int, input().split()))",
"-if M == 0:",
"- print((0, 0))",
"- sys.exit()",
"-p_S = []",
"-for _ in range(M):",
"- p_S.append(input().split())",
"-p = []",
"-S = []",
"-for i in range(M):",
"- p_S[i][0] = int(p_S[i][0])",
"- p_S[i][1] = int(p_S[i][1] == \"AC\")",
"-p_S.sort(key=lambda x: x[0])",
"-for i in range(M):",
"- p.append(p_S[i][0])",
"- S.append(p_S[i][1])",
"-p = list(map(int, p))",
"-S = list(map(int, S))",
"-flag_p = p[0]",
"-flag_ac = 0",
"-AC_sum = 0",
"-WA_sum = 0",
"+n, m = list(map(int, input().split()))",
"+ac = [0] * n",
"+wa = [0] * n",
"+for i in range(m):",
"+ p, s = input().split()",
"+ p = int(p)",
"+ if ac[p - 1] == 1: # ใใฎใในใใใฏใชใขใใฆใใใ้ฃใฐใใ",
"+ continue",
"+ if s == \"AC\": # ใในใใใฏใชใขใใใใใฉใฐใใคใใ",
"+ ac[p - 1] = 1",
"+ else: # ใในใใใฏใชใขใใใพใงใฏๅคฑๆใ็นฐใ่ฟใใ",
"+ wa[p - 1] += 1",
"+# ๆ็ต็ใซๅบๅใใใใฎใๆฑบใใ",
"+AC = 0",
"-for i in range(M):",
"- if flag_p == p[i]:",
"- if S[i] == 0 and flag_ac == 0:",
"- WA += 1",
"- elif S[i] == 1 and flag_ac == 0:",
"- AC_sum += 1",
"- WA_sum += WA",
"- flag_ac = 1",
"- else:",
"- flag_p = p[i]",
"- flag_ac = 0",
"- WA = 0",
"- if S[i] == 0 and flag_ac == 0:",
"- WA += 1",
"- elif S[i] == 1 and flag_ac == 0:",
"- AC_sum += 1",
"- WA_sum += WA",
"- flag_ac = 1",
"-print((AC_sum, WA_sum))",
"+for i in range(n):",
"+ AC += ac[i] # ใฏใชใขใใๅๆฐ",
"+ if ac[i] == 1:",
"+ WA += wa[i] # ใฏใชใขใงใใชใใฃใๅๆฐ",
"+print((\"{} {}\".format(AC, WA)))"
]
| false | 0.064643 | 0.073052 | 0.884887 | [
"s031039868",
"s376310539"
]
|
u044459372 | p03283 | python | s254918553 | s726200107 | 1,213 | 588 | 59,316 | 57,948 | Accepted | Accepted | 51.53 | import sys
input = lambda :sys.stdin.readline().rstrip()
def main():
n, m, Q = list(map(int, input().split()))
Train= [[0 for _ in range(n)] for _ in range(n)]
for i in range(m):
l, r = list(map(int, input().split()))
l, r = l - 1, r - 1
Train[l][r] += 1
P_Train = [[0 for _ in range(n + 1)] for _ in range(n)]
for i in range(n):
tmp = 0
for j in range (n):
tmp += Train[i][j]
P_Train[i][j + 1] = tmp
for i in range(Q):
p, q = list(map(int, input().split()))
p, q = p - 1, q - 1
ans = solve(P_Train, n, p, q)
print(ans)
def solve(P_Train, n, p, q):
ans = 0
for i in range(p, q + 1):
ans += P_Train[i][q + 1] - P_Train[i][p]
return ans
if __name__ == '__main__':
main() | import sys
input = lambda :sys.stdin.readline().rstrip()
def main():
n, m, Q = list(map(int, input().split()))
Train= [[0 for _ in range(n)] for _ in range(n)]
for i in range(m):
l, r = list(map(int, input().split()))
l, r = l - 1, r - 1
Train[l][r] += 1
P_Train = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(n):
for j in range(n):
P_Train[i + 1][j + 1] = P_Train[i][j + 1] + P_Train[i + 1][j] + Train[i][j] - P_Train[i][j]
#print(*P_Train, sep = '\n')
for i in range(Q):
p, q = list(map(int, input().split()))
p, q = p - 1, q - 1
ans = solve(P_Train, p, q)
print(ans)
def solve(P_Train, p, q):
ans = 0
ans = P_Train[q + 1][q + 1] -P_Train[p][q + 1] - P_Train[q + 1][p] + P_Train[p][p]
return ans
if __name__ == '__main__':
main() | 35 | 34 | 844 | 907 | import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
n, m, Q = list(map(int, input().split()))
Train = [[0 for _ in range(n)] for _ in range(n)]
for i in range(m):
l, r = list(map(int, input().split()))
l, r = l - 1, r - 1
Train[l][r] += 1
P_Train = [[0 for _ in range(n + 1)] for _ in range(n)]
for i in range(n):
tmp = 0
for j in range(n):
tmp += Train[i][j]
P_Train[i][j + 1] = tmp
for i in range(Q):
p, q = list(map(int, input().split()))
p, q = p - 1, q - 1
ans = solve(P_Train, n, p, q)
print(ans)
def solve(P_Train, n, p, q):
ans = 0
for i in range(p, q + 1):
ans += P_Train[i][q + 1] - P_Train[i][p]
return ans
if __name__ == "__main__":
main()
| import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
n, m, Q = list(map(int, input().split()))
Train = [[0 for _ in range(n)] for _ in range(n)]
for i in range(m):
l, r = list(map(int, input().split()))
l, r = l - 1, r - 1
Train[l][r] += 1
P_Train = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(n):
for j in range(n):
P_Train[i + 1][j + 1] = (
P_Train[i][j + 1] + P_Train[i + 1][j] + Train[i][j] - P_Train[i][j]
)
# print(*P_Train, sep = '\n')
for i in range(Q):
p, q = list(map(int, input().split()))
p, q = p - 1, q - 1
ans = solve(P_Train, p, q)
print(ans)
def solve(P_Train, p, q):
ans = 0
ans = P_Train[q + 1][q + 1] - P_Train[p][q + 1] - P_Train[q + 1][p] + P_Train[p][p]
return ans
if __name__ == "__main__":
main()
| false | 2.857143 | [
"- P_Train = [[0 for _ in range(n + 1)] for _ in range(n)]",
"+ P_Train = [[0 for _ in range(n + 1)] for _ in range(n + 1)]",
"- tmp = 0",
"- tmp += Train[i][j]",
"- P_Train[i][j + 1] = tmp",
"+ P_Train[i + 1][j + 1] = (",
"+ P_Train[i][j + 1] + P_Train[i + 1][j] + Train[i][j] - P_Train[i][j]",
"+ )",
"+ # print(*P_Train, sep = '\\n')",
"- ans = solve(P_Train, n, p, q)",
"+ ans = solve(P_Train, p, q)",
"-def solve(P_Train, n, p, q):",
"+def solve(P_Train, p, q):",
"- for i in range(p, q + 1):",
"- ans += P_Train[i][q + 1] - P_Train[i][p]",
"+ ans = P_Train[q + 1][q + 1] - P_Train[p][q + 1] - P_Train[q + 1][p] + P_Train[p][p]"
]
| false | 0.037734 | 0.061672 | 0.611859 | [
"s254918553",
"s726200107"
]
|
u796942881 | p03673 | python | s170627561 | s842747629 | 97 | 45 | 26,588 | 22,620 | Accepted | Accepted | 53.61 | from collections import deque
def main():
n, *a = open(0).read().split()
dq = deque()
n = int(n) - 1
for i, ai in enumerate(a):
if i % 2 == n % 2:
dq.appendleft(ai)
else:
dq.append(ai)
print((" ".join(dq)))
return
main()
| def main():
n, *a = open(0).read().split()
if int(n) % 2:
print(" ".join(reversed(a[0::2])), end=" ")
print(" ".join(a[1::2]))
else:
print(" ".join(reversed(a[1::2])), end=" ")
print(" ".join(a[0::2]))
return
main()
| 17 | 12 | 303 | 277 | from collections import deque
def main():
n, *a = open(0).read().split()
dq = deque()
n = int(n) - 1
for i, ai in enumerate(a):
if i % 2 == n % 2:
dq.appendleft(ai)
else:
dq.append(ai)
print((" ".join(dq)))
return
main()
| def main():
n, *a = open(0).read().split()
if int(n) % 2:
print(" ".join(reversed(a[0::2])), end=" ")
print(" ".join(a[1::2]))
else:
print(" ".join(reversed(a[1::2])), end=" ")
print(" ".join(a[0::2]))
return
main()
| false | 29.411765 | [
"-from collections import deque",
"-",
"-",
"- dq = deque()",
"- n = int(n) - 1",
"- for i, ai in enumerate(a):",
"- if i % 2 == n % 2:",
"- dq.appendleft(ai)",
"- else:",
"- dq.append(ai)",
"- print((\" \".join(dq)))",
"+ if int(n) % 2:",
"+ print(\" \".join(reversed(a[0::2])), end=\" \")",
"+ print(\" \".join(a[1::2]))",
"+ else:",
"+ print(\" \".join(reversed(a[1::2])), end=\" \")",
"+ print(\" \".join(a[0::2]))"
]
| false | 0.040416 | 0.074516 | 0.542384 | [
"s170627561",
"s842747629"
]
|
u467736898 | p03321 | python | s623237659 | s644887339 | 880 | 714 | 22,364 | 20,980 | Accepted | Accepted | 18.86 | N, M = list(map(int, input().split()))
E = [[] for _ in range(N+1)]
E_mat = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
a, b = list(map(int, input().split()))
E[a].append(b)
E[b].append(a)
E_mat[a][b] = 1
E_mat[b][a] = 1
E_inv = [[] for _ in range(N+1)]
for v, e_mat in enumerate(E_mat[1:], 1):
for u, e in enumerate(e_mat[1:], 1):
if e==0 and v!=u:
E_inv[v].append(u)
colors = [0] * (N+1)
def dfs(v, c):
colors[v] = c
cnts[c] += 1
for u in E_inv[v]:
if colors[u] == c:
print((-1))
exit()
if colors[u] != 0:
continue
dfs(u, -c)
K = []
for v in range(1, N+1):
cnts = [0, 0, 0]
if colors[v] == 0:
dfs(v, 1)
K.append(cnts[1:])
dp = 1
for a, b in K:
dp = dp<<a | dp<<b
dp = bin(dp)[:1:-1]
ans = 0
mi = float("inf")
for i, c in enumerate(dp):
if c=="1":
if mi > abs(N/2-i):
mi = abs(N/2-i)
ans = i
print((ans*(ans-1)//2 + (N-ans)*(N-ans-1)//2))
| def main():
N, M = list(map(int, input().split()))
E_mat = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
a, b = list(map(int, input().split()))
E_mat[a][b] = 1
E_mat[b][a] = 1
E_inv = [[] for _ in range(N+1)]
for v, e_mat in enumerate(E_mat[1:], 1):
for u, e in enumerate(e_mat[1:], 1):
if e==0 and v!=u:
E_inv[v].append(u)
colors = [0] * (N+1)
def dfs(v, c):
colors[v] = c
cnts[c] += 1
for u in E_inv[v]:
if colors[u] == c:
print((-1))
exit()
if colors[u] != 0:
continue
dfs(u, -c)
K = []
for v in range(1, N+1):
cnts = [0, 0, 0]
if colors[v] == 0:
dfs(v, 1)
K.append(cnts[1:])
dp = 1
for a, b in K:
dp = dp<<a | dp<<b
dp = bin(dp)[:1:-1]
ans = 0
mi = float("inf")
for i, c in enumerate(dp):
if c=="1":
if mi > abs(N/2-i):
mi = abs(N/2-i)
ans = i
print((ans*(ans-1)//2 + (N-ans)*(N-ans-1)//2))
main()
| 46 | 48 | 1,055 | 1,200 | N, M = list(map(int, input().split()))
E = [[] for _ in range(N + 1)]
E_mat = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
a, b = list(map(int, input().split()))
E[a].append(b)
E[b].append(a)
E_mat[a][b] = 1
E_mat[b][a] = 1
E_inv = [[] for _ in range(N + 1)]
for v, e_mat in enumerate(E_mat[1:], 1):
for u, e in enumerate(e_mat[1:], 1):
if e == 0 and v != u:
E_inv[v].append(u)
colors = [0] * (N + 1)
def dfs(v, c):
colors[v] = c
cnts[c] += 1
for u in E_inv[v]:
if colors[u] == c:
print((-1))
exit()
if colors[u] != 0:
continue
dfs(u, -c)
K = []
for v in range(1, N + 1):
cnts = [0, 0, 0]
if colors[v] == 0:
dfs(v, 1)
K.append(cnts[1:])
dp = 1
for a, b in K:
dp = dp << a | dp << b
dp = bin(dp)[:1:-1]
ans = 0
mi = float("inf")
for i, c in enumerate(dp):
if c == "1":
if mi > abs(N / 2 - i):
mi = abs(N / 2 - i)
ans = i
print((ans * (ans - 1) // 2 + (N - ans) * (N - ans - 1) // 2))
| def main():
N, M = list(map(int, input().split()))
E_mat = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
a, b = list(map(int, input().split()))
E_mat[a][b] = 1
E_mat[b][a] = 1
E_inv = [[] for _ in range(N + 1)]
for v, e_mat in enumerate(E_mat[1:], 1):
for u, e in enumerate(e_mat[1:], 1):
if e == 0 and v != u:
E_inv[v].append(u)
colors = [0] * (N + 1)
def dfs(v, c):
colors[v] = c
cnts[c] += 1
for u in E_inv[v]:
if colors[u] == c:
print((-1))
exit()
if colors[u] != 0:
continue
dfs(u, -c)
K = []
for v in range(1, N + 1):
cnts = [0, 0, 0]
if colors[v] == 0:
dfs(v, 1)
K.append(cnts[1:])
dp = 1
for a, b in K:
dp = dp << a | dp << b
dp = bin(dp)[:1:-1]
ans = 0
mi = float("inf")
for i, c in enumerate(dp):
if c == "1":
if mi > abs(N / 2 - i):
mi = abs(N / 2 - i)
ans = i
print((ans * (ans - 1) // 2 + (N - ans) * (N - ans - 1) // 2))
main()
| false | 4.166667 | [
"-N, M = list(map(int, input().split()))",
"-E = [[] for _ in range(N + 1)]",
"-E_mat = [[0] * (N + 1) for _ in range(N + 1)]",
"-for _ in range(M):",
"- a, b = list(map(int, input().split()))",
"- E[a].append(b)",
"- E[b].append(a)",
"- E_mat[a][b] = 1",
"- E_mat[b][a] = 1",
"-E_inv = [[] for _ in range(N + 1)]",
"-for v, e_mat in enumerate(E_mat[1:], 1):",
"- for u, e in enumerate(e_mat[1:], 1):",
"- if e == 0 and v != u:",
"- E_inv[v].append(u)",
"-colors = [0] * (N + 1)",
"+def main():",
"+ N, M = list(map(int, input().split()))",
"+ E_mat = [[0] * (N + 1) for _ in range(N + 1)]",
"+ for _ in range(M):",
"+ a, b = list(map(int, input().split()))",
"+ E_mat[a][b] = 1",
"+ E_mat[b][a] = 1",
"+ E_inv = [[] for _ in range(N + 1)]",
"+ for v, e_mat in enumerate(E_mat[1:], 1):",
"+ for u, e in enumerate(e_mat[1:], 1):",
"+ if e == 0 and v != u:",
"+ E_inv[v].append(u)",
"+ colors = [0] * (N + 1)",
"+",
"+ def dfs(v, c):",
"+ colors[v] = c",
"+ cnts[c] += 1",
"+ for u in E_inv[v]:",
"+ if colors[u] == c:",
"+ print((-1))",
"+ exit()",
"+ if colors[u] != 0:",
"+ continue",
"+ dfs(u, -c)",
"+",
"+ K = []",
"+ for v in range(1, N + 1):",
"+ cnts = [0, 0, 0]",
"+ if colors[v] == 0:",
"+ dfs(v, 1)",
"+ K.append(cnts[1:])",
"+ dp = 1",
"+ for a, b in K:",
"+ dp = dp << a | dp << b",
"+ dp = bin(dp)[:1:-1]",
"+ ans = 0",
"+ mi = float(\"inf\")",
"+ for i, c in enumerate(dp):",
"+ if c == \"1\":",
"+ if mi > abs(N / 2 - i):",
"+ mi = abs(N / 2 - i)",
"+ ans = i",
"+ print((ans * (ans - 1) // 2 + (N - ans) * (N - ans - 1) // 2))",
"-def dfs(v, c):",
"- colors[v] = c",
"- cnts[c] += 1",
"- for u in E_inv[v]:",
"- if colors[u] == c:",
"- print((-1))",
"- exit()",
"- if colors[u] != 0:",
"- continue",
"- dfs(u, -c)",
"-",
"-",
"-K = []",
"-for v in range(1, N + 1):",
"- cnts = [0, 0, 0]",
"- if colors[v] == 0:",
"- dfs(v, 1)",
"- K.append(cnts[1:])",
"-dp = 1",
"-for a, b in K:",
"- dp = dp << a | dp << b",
"-dp = bin(dp)[:1:-1]",
"-ans = 0",
"-mi = float(\"inf\")",
"-for i, c in enumerate(dp):",
"- if c == \"1\":",
"- if mi > abs(N / 2 - i):",
"- mi = abs(N / 2 - i)",
"- ans = i",
"-print((ans * (ans - 1) // 2 + (N - ans) * (N - ans - 1) // 2))",
"+main()"
]
| false | 0.106855 | 0.043483 | 2.457388 | [
"s623237659",
"s644887339"
]
|
u073549161 | p03241 | python | s600087221 | s259157479 | 190 | 171 | 38,640 | 38,640 | Accepted | Accepted | 10 | def make_divisors(n):
divisors = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
# divisors.sort()
return divisors
a,b = list(map(int, input().split()))
l = make_divisors(b)
l.sort(reverse=False)
res = 1
#print(l)
for x in l:
if x <= b//a:
res = max(x, res)
print(res)
| # ็ดๆฐใฎใชในใใๅพใ
def make_divisors(n):
divisors = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
N, M = list(map(int, input().split()))
l = make_divisors(M)
# mใฎ็ดๆฐ
res = 1
# ๅ
จใฆใฎ็ดๆฐใซใใใฆใkใจไปฎๅฎใใ
for k in l:
x = M // k
# ใใฎ้ใMใkใง้คใใๆฐๅbใNไปฅไธใงใใใใๅคๅฎใใ
if x >= N:
res = max(res, k)
print(res) | 19 | 21 | 425 | 457 | def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
# divisors.sort()
return divisors
a, b = list(map(int, input().split()))
l = make_divisors(b)
l.sort(reverse=False)
res = 1
# print(l)
for x in l:
if x <= b // a:
res = max(x, res)
print(res)
| # ็ดๆฐใฎใชในใใๅพใ
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
N, M = list(map(int, input().split()))
l = make_divisors(M)
# mใฎ็ดๆฐ
res = 1
# ๅ
จใฆใฎ็ดๆฐใซใใใฆใkใจไปฎๅฎใใ
for k in l:
x = M // k
# ใใฎ้ใMใkใง้คใใๆฐๅbใNไปฅไธใงใใใใๅคๅฎใใ
if x >= N:
res = max(res, k)
print(res)
| false | 9.52381 | [
"+# ็ดๆฐใฎใชในใใๅพใ",
"- # divisors.sort()",
"-a, b = list(map(int, input().split()))",
"-l = make_divisors(b)",
"-l.sort(reverse=False)",
"+N, M = list(map(int, input().split()))",
"+l = make_divisors(M)",
"+# mใฎ็ดๆฐ",
"-# print(l)",
"-for x in l:",
"- if x <= b // a:",
"- res = max(x, res)",
"+# ๅ
จใฆใฎ็ดๆฐใซใใใฆใkใจไปฎๅฎใใ",
"+for k in l:",
"+ x = M // k",
"+ # ใใฎ้ใMใkใง้คใใๆฐๅbใNไปฅไธใงใใใใๅคๅฎใใ",
"+ if x >= N:",
"+ res = max(res, k)"
]
| false | 0.045226 | 0.123585 | 0.365952 | [
"s600087221",
"s259157479"
]
|
u003309334 | p02270 | python | s936754947 | s273482315 | 1,130 | 400 | 9,464 | 9,420 | Accepted | Accepted | 64.6 | '''
Search - Allocation
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_D
Algorythm
Referenced #1670532 Solution for ALDS1_4_D: Allocation by Chris_Kobayashi
1. Decide the searching point -> (top of the range + bottom of the range) / 2
2. Check whether it is possible to load all of the luggage to the trugs
in the weight limit of the searching point
3. If it is possible, then move the top to the searching point
If it is impossible, then move the bottom to the searching point + 1
4. Continue 1~4 as long as the top is greater than bottom
Range
Serching the maximum loading capacity(MLC) number
between the maximam weight item num and the total weight num
top: total weight num
.
.
. <- search the num point
.
.
bottom: maximam weight item num
Why?
A1. Why not "bot = sp" but "bot = sp + 1"?
Q1. for example
top = 5
bot = 3
sp = (5 + 3) / 2 = 4
...
bot = sp
sp = (5 + 4) / 2 = 4
...
bot = sp
...for inf
A2. Why the top is total weight and bot is max weight?
Q2. Sure it is ok "top = 99999999, bot = 0".
But, MLC never pass the total weight
and the limit never be lower than the max.
So, it is the most effective range.
'''
# input
n, k = list(map(int,input().split()))
w = []
for i in range(n):
w.append(eval(input()))
# initial searching range
top = sum(w) # the top of the searching range
bot = max(w) # the bottom of the searching range
# searching until there is no serching range
while top > bot:
sp = (top + bot) / 2 # the searching point
tk = 0 # temp index of the trugs
weight = 0 # temp total weight of a trug
# check whether it is possible to load all of the luggage
# to the trugs in the weight limit of the searching point
for tw in w:
if weight + tw <= sp:
weight += tw
else:
tk += 1
if tk >= k:
# when impossible, then raise the bottom
bot = sp + 1
break
weight = tw
else:
# when possible, then lowering the top
top = sp
# output MLC
print(top) | '''
Search - Allocation
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_D
Algorythm
Referenced #1670532 Solution for ALDS1_4_D: Allocation by Chris_Kobayashi
1. Decide the searching point -> (top of the range + bottom of the range) / 2
2. Check whether it is possible to load all of the luggage to the trugs
in the weight limit of the searching point
3. If it is possible, then move the top to the searching point
If it is impossible, then move the bottom to the searching point + 1
4. Continue 1~4 as long as the top is greater than bottom
Range
Serching the maximum loading capacity(MLC) number
between the maximam weight item num and the total weight num
top: total weight num
.
.
. <- search the num point
.
.
bottom: maximam weight item num
Why?
A1. Why not "bot = sp" but "bot = sp + 1"?
Q1. for example
top = 5
bot = 3
sp = (5 + 3) / 2 = 4
...
bot = sp
sp = (5 + 4) / 2 = 4
...
bot = sp
...for inf
A2. Why the top is total weight and bot is max weight?
Q2. Sure it is ok "top = 99999999, bot = 0".
But, MLC never pass the total weight
and the limit never be lower than the max.
So, it is the most effective range.
Note
1. This program contains the idea below
- Using "binary search" idea
- The appropriate range
2. To be the python program more fast
- Using int(raw_input()) instead of input()
- To rewrite the processings for the function is more fast
'''
# input
n, k = list(map(int,input().split()))
w = []
for i in range(n):
w.append(int(input()))
def tempf(sp):
tk = 0 # temp index of the trugs
weight = 0 # temp total weight of a trug
# check whether it is possible to load all of the luggage
# to the trugs in the weight limit of the searching point
for tw in w:
if weight + tw <= sp:
weight += tw
else:
tk += 1
if tk >= k:
# when impossible, then raise the bottom
return False
weight = tw
else:
# when possible, then lowering the top
return True
# initial searching range
top = sum(w) # the top of the searching range
bot = max(w) # the bottom of the searching range
# searching until there is no serching range
while top > bot:
sp = (top + bot) / 2 # the searching point
if tempf(sp):
top = sp
else:
bot = sp + 1
# output MLC
print(top) | 81 | 94 | 2,184 | 2,526 | """
Search - Allocation
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_D
Algorythm
Referenced #1670532 Solution for ALDS1_4_D: Allocation by Chris_Kobayashi
1. Decide the searching point -> (top of the range + bottom of the range) / 2
2. Check whether it is possible to load all of the luggage to the trugs
in the weight limit of the searching point
3. If it is possible, then move the top to the searching point
If it is impossible, then move the bottom to the searching point + 1
4. Continue 1~4 as long as the top is greater than bottom
Range
Serching the maximum loading capacity(MLC) number
between the maximam weight item num and the total weight num
top: total weight num
.
.
. <- search the num point
.
.
bottom: maximam weight item num
Why?
A1. Why not "bot = sp" but "bot = sp + 1"?
Q1. for example
top = 5
bot = 3
sp = (5 + 3) / 2 = 4
...
bot = sp
sp = (5 + 4) / 2 = 4
...
bot = sp
...for inf
A2. Why the top is total weight and bot is max weight?
Q2. Sure it is ok "top = 99999999, bot = 0".
But, MLC never pass the total weight
and the limit never be lower than the max.
So, it is the most effective range.
"""
# input
n, k = list(map(int, input().split()))
w = []
for i in range(n):
w.append(eval(input()))
# initial searching range
top = sum(w) # the top of the searching range
bot = max(w) # the bottom of the searching range
# searching until there is no serching range
while top > bot:
sp = (top + bot) / 2 # the searching point
tk = 0 # temp index of the trugs
weight = 0 # temp total weight of a trug
# check whether it is possible to load all of the luggage
# to the trugs in the weight limit of the searching point
for tw in w:
if weight + tw <= sp:
weight += tw
else:
tk += 1
if tk >= k:
# when impossible, then raise the bottom
bot = sp + 1
break
weight = tw
else:
# when possible, then lowering the top
top = sp
# output MLC
print(top)
| """
Search - Allocation
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_D
Algorythm
Referenced #1670532 Solution for ALDS1_4_D: Allocation by Chris_Kobayashi
1. Decide the searching point -> (top of the range + bottom of the range) / 2
2. Check whether it is possible to load all of the luggage to the trugs
in the weight limit of the searching point
3. If it is possible, then move the top to the searching point
If it is impossible, then move the bottom to the searching point + 1
4. Continue 1~4 as long as the top is greater than bottom
Range
Serching the maximum loading capacity(MLC) number
between the maximam weight item num and the total weight num
top: total weight num
.
.
. <- search the num point
.
.
bottom: maximam weight item num
Why?
A1. Why not "bot = sp" but "bot = sp + 1"?
Q1. for example
top = 5
bot = 3
sp = (5 + 3) / 2 = 4
...
bot = sp
sp = (5 + 4) / 2 = 4
...
bot = sp
...for inf
A2. Why the top is total weight and bot is max weight?
Q2. Sure it is ok "top = 99999999, bot = 0".
But, MLC never pass the total weight
and the limit never be lower than the max.
So, it is the most effective range.
Note
1. This program contains the idea below
- Using "binary search" idea
- The appropriate range
2. To be the python program more fast
- Using int(raw_input()) instead of input()
- To rewrite the processings for the function is more fast
"""
# input
n, k = list(map(int, input().split()))
w = []
for i in range(n):
w.append(int(input()))
def tempf(sp):
tk = 0 # temp index of the trugs
weight = 0 # temp total weight of a trug
# check whether it is possible to load all of the luggage
# to the trugs in the weight limit of the searching point
for tw in w:
if weight + tw <= sp:
weight += tw
else:
tk += 1
if tk >= k:
# when impossible, then raise the bottom
return False
weight = tw
else:
# when possible, then lowering the top
return True
# initial searching range
top = sum(w) # the top of the searching range
bot = max(w) # the bottom of the searching range
# searching until there is no serching range
while top > bot:
sp = (top + bot) / 2 # the searching point
if tempf(sp):
top = sp
else:
bot = sp + 1
# output MLC
print(top)
| false | 13.829787 | [
"+Note",
"+1. This program contains the idea below",
"+ - Using \"binary search\" idea",
"+ - The appropriate range",
"+2. To be the python program more fast",
"+ - Using int(raw_input()) instead of input()",
"+ - To rewrite the processings for the function is more fast",
"- w.append(eval(input()))",
"-# initial searching range",
"-top = sum(w) # the top of the searching range",
"-bot = max(w) # the bottom of the searching range",
"-# searching until there is no serching range",
"-while top > bot:",
"- sp = (top + bot) / 2 # the searching point",
"+ w.append(int(input()))",
"+",
"+",
"+def tempf(sp):",
"- bot = sp + 1",
"- break",
"+ return False",
"+ return True",
"+",
"+",
"+# initial searching range",
"+top = sum(w) # the top of the searching range",
"+bot = max(w) # the bottom of the searching range",
"+# searching until there is no serching range",
"+while top > bot:",
"+ sp = (top + bot) / 2 # the searching point",
"+ if tempf(sp):",
"+ else:",
"+ bot = sp + 1"
]
| false | 0.041593 | 0.036801 | 1.130222 | [
"s936754947",
"s273482315"
]
|
u285443936 | p03290 | python | s491642452 | s790508785 | 243 | 46 | 3,064 | 3,064 | Accepted | Accepted | 81.07 | D, G = list(map(int, input().split()))
pc = [list(map(int, input().split())) for i in range(D)]
ans = 10**5
for i in range(2**D):
score = 0
tmp = 0
solved = [False]*D
for j in range(D):
if (i>>j) & 1:
score += (j+1) * 100 * pc[j][0] + pc[j][1]
tmp += pc[j][0]
solved[j] = True
if score >= G:
ans = min(ans, tmp)
else:
for k in range(D-1,-1,-1):
if solved[k] == False:
l = 0
while score < G and l < pc[k][0]:
score += (k+1)*100
tmp += 1
l += 1
if score >= G:
ans = min(ans, tmp)
break
print(ans) | D, G = list(map(int, input().split()))
table = []
for i in range(D):
p,c = list(map(int, input().split()))
table.append((i+1,p,c))
ans = 10**3
for i in range(1<<D):
score = 0
count = 0
remain = []
for j in range(D):
a,p,c = table[j]
if i & (1<<j):
score += a*100*p+c
count += p
else:
remain.append((a,p,c))
if score >= G:
ans = min(count,ans)
else:
remain.sort(reverse=True)
a,p,c = remain[0]
for k in range(p):
score += a*100
count += 1
if score >= G:
ans = min(count,ans)
print(ans) | 27 | 29 | 637 | 677 | D, G = list(map(int, input().split()))
pc = [list(map(int, input().split())) for i in range(D)]
ans = 10**5
for i in range(2**D):
score = 0
tmp = 0
solved = [False] * D
for j in range(D):
if (i >> j) & 1:
score += (j + 1) * 100 * pc[j][0] + pc[j][1]
tmp += pc[j][0]
solved[j] = True
if score >= G:
ans = min(ans, tmp)
else:
for k in range(D - 1, -1, -1):
if solved[k] == False:
l = 0
while score < G and l < pc[k][0]:
score += (k + 1) * 100
tmp += 1
l += 1
if score >= G:
ans = min(ans, tmp)
break
print(ans)
| D, G = list(map(int, input().split()))
table = []
for i in range(D):
p, c = list(map(int, input().split()))
table.append((i + 1, p, c))
ans = 10**3
for i in range(1 << D):
score = 0
count = 0
remain = []
for j in range(D):
a, p, c = table[j]
if i & (1 << j):
score += a * 100 * p + c
count += p
else:
remain.append((a, p, c))
if score >= G:
ans = min(count, ans)
else:
remain.sort(reverse=True)
a, p, c = remain[0]
for k in range(p):
score += a * 100
count += 1
if score >= G:
ans = min(count, ans)
print(ans)
| false | 6.896552 | [
"-pc = [list(map(int, input().split())) for i in range(D)]",
"-ans = 10**5",
"-for i in range(2**D):",
"+table = []",
"+for i in range(D):",
"+ p, c = list(map(int, input().split()))",
"+ table.append((i + 1, p, c))",
"+ans = 10**3",
"+for i in range(1 << D):",
"- tmp = 0",
"- solved = [False] * D",
"+ count = 0",
"+ remain = []",
"- if (i >> j) & 1:",
"- score += (j + 1) * 100 * pc[j][0] + pc[j][1]",
"- tmp += pc[j][0]",
"- solved[j] = True",
"+ a, p, c = table[j]",
"+ if i & (1 << j):",
"+ score += a * 100 * p + c",
"+ count += p",
"+ else:",
"+ remain.append((a, p, c))",
"- ans = min(ans, tmp)",
"+ ans = min(count, ans)",
"- for k in range(D - 1, -1, -1):",
"- if solved[k] == False:",
"- l = 0",
"- while score < G and l < pc[k][0]:",
"- score += (k + 1) * 100",
"- tmp += 1",
"- l += 1",
"- if score >= G:",
"- ans = min(ans, tmp)",
"- break",
"+ remain.sort(reverse=True)",
"+ a, p, c = remain[0]",
"+ for k in range(p):",
"+ score += a * 100",
"+ count += 1",
"+ if score >= G:",
"+ ans = min(count, ans)"
]
| false | 0.04797 | 0.038262 | 1.253729 | [
"s491642452",
"s790508785"
]
|
u472065247 | p03576 | python | s225672333 | s677384887 | 34 | 29 | 3,064 | 3,064 | Accepted | Accepted | 14.71 | N, K = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(N)]
XY.sort()
r = 10**20
for xi0 in range(N - K + 1):
for xi1 in range(K + xi0 - 1, N):
x = XY[xi1][0] - XY[xi0][0]
XY_ys = sorted(XY[xi0:xi1 + 1], key=lambda a: a[1])
for yi0 in range(len(XY_ys) - K + 1):
y = XY_ys[yi0 + K - 1][1] - XY_ys[yi0][1]
r = min(r, x * y)
print(r) | N, K = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(N)]
XY.sort()
X, Y = list(zip(*XY))
r = 10**20
for x0 in range(N - K + 1):
for x1 in range(K + x0 - 1, N):
x = X[x1] - X[x0]
Y_s = sorted(Y[x0:x1 + 1])
for y0 in range(len(Y_s) - K + 1):
y = Y_s[y0 + K - 1] - Y_s[y0]
r = min(r, x * y)
print(r) | 12 | 13 | 397 | 361 | N, K = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(N)]
XY.sort()
r = 10**20
for xi0 in range(N - K + 1):
for xi1 in range(K + xi0 - 1, N):
x = XY[xi1][0] - XY[xi0][0]
XY_ys = sorted(XY[xi0 : xi1 + 1], key=lambda a: a[1])
for yi0 in range(len(XY_ys) - K + 1):
y = XY_ys[yi0 + K - 1][1] - XY_ys[yi0][1]
r = min(r, x * y)
print(r)
| N, K = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(N)]
XY.sort()
X, Y = list(zip(*XY))
r = 10**20
for x0 in range(N - K + 1):
for x1 in range(K + x0 - 1, N):
x = X[x1] - X[x0]
Y_s = sorted(Y[x0 : x1 + 1])
for y0 in range(len(Y_s) - K + 1):
y = Y_s[y0 + K - 1] - Y_s[y0]
r = min(r, x * y)
print(r)
| false | 7.692308 | [
"+X, Y = list(zip(*XY))",
"-for xi0 in range(N - K + 1):",
"- for xi1 in range(K + xi0 - 1, N):",
"- x = XY[xi1][0] - XY[xi0][0]",
"- XY_ys = sorted(XY[xi0 : xi1 + 1], key=lambda a: a[1])",
"- for yi0 in range(len(XY_ys) - K + 1):",
"- y = XY_ys[yi0 + K - 1][1] - XY_ys[yi0][1]",
"+for x0 in range(N - K + 1):",
"+ for x1 in range(K + x0 - 1, N):",
"+ x = X[x1] - X[x0]",
"+ Y_s = sorted(Y[x0 : x1 + 1])",
"+ for y0 in range(len(Y_s) - K + 1):",
"+ y = Y_s[y0 + K - 1] - Y_s[y0]"
]
| false | 0.039264 | 0.087647 | 0.44798 | [
"s225672333",
"s677384887"
]
|
u102461423 | p03040 | python | s884702816 | s179424057 | 933 | 596 | 28,020 | 28,080 | Accepted | Accepted | 36.12 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappush, heappop
Q = int(readline())
query = (tuple(map(int,line.split())) for line in readlines())
# ้ฉๅฝใซ็ชๅ
ตใๅ
ฅใใฆใใ
INF = 10**12
L = [INF] # -1ๅใใฆใใใ
R = [INF]
sumL = 0; sumR = 0 # ๅ
lenL = 0; lenR = 0 # ้ทใ
add = 0 # ๅ
จไฝใซๅ
ฑ้ใซๅ ใใฃใฆใใใฎ
answer = []
for q in query:
if len(q) == 1:
# ๅคใๆฑใใ
x = -L[0]
f = sumR - sumL + x * (lenL - lenR)
answer.append('{} {}'.format(x,f+add))
continue
# ๆดๆฐ
a,b = q[1:]
add += b
b = -heappop(L); sumL -= b
c = heappop(R); sumR -= c
a,b,c = sorted([a,b,c])
heappush(L,-a); sumL += a
heappush(R,c); sumR += c
if lenL > lenR:
heappush(R,b); sumR += b; lenR += 1
else:
heappush(L,-b); sumL += b; lenL += 1
print(('\n'.join(answer))) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappush, heappop, heappushpop
Q = int(readline())
query = (tuple(map(int,line.split())) for line in readlines())
# ้ฉๅฝใซ็ชๅ
ตใๅ
ฅใใฆใใ
INF = 10**12
L = [INF] # -1ๅใใฆใใใ
R = [INF]
sumL = 0; sumR = 0 # ๅ
lenL = 0; lenR = 0 # ้ทใ
add = 0 # ๅ
จไฝใซๅ
ฑ้ใซๅ ใใฃใฆใใใฎ
answer = []
for q in query:
if len(q) == 1:
# ๅคใๆฑใใ
x = -L[0]
f = sumR - sumL + x * (lenL - lenR)
answer.append('{} {}'.format(x,f+add))
continue
# ๆดๆฐ
a,b = q[1:]
add += b
if lenL > lenR:
sumL += a; a = -heappushpop(L,-a); sumL -= a
heappush(R,a); sumR += a; lenR += 1
else:
sumR += a; a = heappushpop(R,a); sumR -= a
heappush(L,-a); sumL += a; lenL += 1
print(('\n'.join(answer))) | 42 | 38 | 935 | 895 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappush, heappop
Q = int(readline())
query = (tuple(map(int, line.split())) for line in readlines())
# ้ฉๅฝใซ็ชๅ
ตใๅ
ฅใใฆใใ
INF = 10**12
L = [INF] # -1ๅใใฆใใใ
R = [INF]
sumL = 0
sumR = 0 # ๅ
lenL = 0
lenR = 0 # ้ทใ
add = 0 # ๅ
จไฝใซๅ
ฑ้ใซๅ ใใฃใฆใใใฎ
answer = []
for q in query:
if len(q) == 1:
# ๅคใๆฑใใ
x = -L[0]
f = sumR - sumL + x * (lenL - lenR)
answer.append("{} {}".format(x, f + add))
continue
# ๆดๆฐ
a, b = q[1:]
add += b
b = -heappop(L)
sumL -= b
c = heappop(R)
sumR -= c
a, b, c = sorted([a, b, c])
heappush(L, -a)
sumL += a
heappush(R, c)
sumR += c
if lenL > lenR:
heappush(R, b)
sumR += b
lenR += 1
else:
heappush(L, -b)
sumL += b
lenL += 1
print(("\n".join(answer)))
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappush, heappop, heappushpop
Q = int(readline())
query = (tuple(map(int, line.split())) for line in readlines())
# ้ฉๅฝใซ็ชๅ
ตใๅ
ฅใใฆใใ
INF = 10**12
L = [INF] # -1ๅใใฆใใใ
R = [INF]
sumL = 0
sumR = 0 # ๅ
lenL = 0
lenR = 0 # ้ทใ
add = 0 # ๅ
จไฝใซๅ
ฑ้ใซๅ ใใฃใฆใใใฎ
answer = []
for q in query:
if len(q) == 1:
# ๅคใๆฑใใ
x = -L[0]
f = sumR - sumL + x * (lenL - lenR)
answer.append("{} {}".format(x, f + add))
continue
# ๆดๆฐ
a, b = q[1:]
add += b
if lenL > lenR:
sumL += a
a = -heappushpop(L, -a)
sumL -= a
heappush(R, a)
sumR += a
lenR += 1
else:
sumR += a
a = heappushpop(R, a)
sumR -= a
heappush(L, -a)
sumL += a
lenL += 1
print(("\n".join(answer)))
| false | 9.52381 | [
"-from heapq import heappush, heappop",
"+from heapq import heappush, heappop, heappushpop",
"- b = -heappop(L)",
"- sumL -= b",
"- c = heappop(R)",
"- sumR -= c",
"- a, b, c = sorted([a, b, c])",
"- heappush(L, -a)",
"- sumL += a",
"- heappush(R, c)",
"- sumR += c",
"- heappush(R, b)",
"- sumR += b",
"+ sumL += a",
"+ a = -heappushpop(L, -a)",
"+ sumL -= a",
"+ heappush(R, a)",
"+ sumR += a",
"- heappush(L, -b)",
"- sumL += b",
"+ sumR += a",
"+ a = heappushpop(R, a)",
"+ sumR -= a",
"+ heappush(L, -a)",
"+ sumL += a"
]
| false | 0.03781 | 0.045041 | 0.839456 | [
"s884702816",
"s179424057"
]
|
u392029857 | p03805 | python | s179569131 | s134028919 | 1,049 | 37 | 195,692 | 3,064 | Accepted | Accepted | 96.47 | from collections import deque
from copy import copy as dc
import sys
def main():
input = sys.stdin.readline
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]
g = [[] for i in range(n+1)]
for i in ab:
g[i[0]].append(i[1])
g[i[1]].append(i[0])
que = deque()
que.append([1,-1,0,set([1])])
ans = 0
while que:
v, p, cnt, check = que.popleft()
if cnt >= n - 1:
if len(check) == n:
ans += 1
continue
for nv in g[v]:
if nv == p:
continue
a = dc(check)
a.add(nv)
que.append([nv, v, cnt+1, a])
print(ans)
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(4100000)
def Dfs(G, v, n, visited):
all_visited = True
for i in range(n):
if visited[i] == False:
all_visited = False
if all_visited:
return 1
ret = 0
for i in range(n):
if not G[v][i]:
continue
if visited[i]:
continue
visited[i] = True
ret += Dfs(G, i, n, visited)
visited[i] = False
return ret
def main():
input = sys.stdin.readline
n, m = list(map(int, input().split()))
e = [list(map(int, input().split())) for i in range(m)]
g = [[False for j in range(n)] for i in range(n)]
for i, j in e:
g[i-1][j-1] = True
g[j-1][i-1] = True
visited = [False for i in range(n)]
visited[0] = True
print((Dfs(g, 0, n, visited)))
if __name__ == "__main__":
main()
| 31 | 42 | 789 | 902 | from collections import deque
from copy import copy as dc
import sys
def main():
input = sys.stdin.readline
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]
g = [[] for i in range(n + 1)]
for i in ab:
g[i[0]].append(i[1])
g[i[1]].append(i[0])
que = deque()
que.append([1, -1, 0, set([1])])
ans = 0
while que:
v, p, cnt, check = que.popleft()
if cnt >= n - 1:
if len(check) == n:
ans += 1
continue
for nv in g[v]:
if nv == p:
continue
a = dc(check)
a.add(nv)
que.append([nv, v, cnt + 1, a])
print(ans)
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(4100000)
def Dfs(G, v, n, visited):
all_visited = True
for i in range(n):
if visited[i] == False:
all_visited = False
if all_visited:
return 1
ret = 0
for i in range(n):
if not G[v][i]:
continue
if visited[i]:
continue
visited[i] = True
ret += Dfs(G, i, n, visited)
visited[i] = False
return ret
def main():
input = sys.stdin.readline
n, m = list(map(int, input().split()))
e = [list(map(int, input().split())) for i in range(m)]
g = [[False for j in range(n)] for i in range(n)]
for i, j in e:
g[i - 1][j - 1] = True
g[j - 1][i - 1] = True
visited = [False for i in range(n)]
visited[0] = True
print((Dfs(g, 0, n, visited)))
if __name__ == "__main__":
main()
| false | 26.190476 | [
"-from collections import deque",
"-from copy import copy as dc",
"+",
"+sys.setrecursionlimit(4100000)",
"+",
"+",
"+def Dfs(G, v, n, visited):",
"+ all_visited = True",
"+ for i in range(n):",
"+ if visited[i] == False:",
"+ all_visited = False",
"+ if all_visited:",
"+ return 1",
"+ ret = 0",
"+ for i in range(n):",
"+ if not G[v][i]:",
"+ continue",
"+ if visited[i]:",
"+ continue",
"+ visited[i] = True",
"+ ret += Dfs(G, i, n, visited)",
"+ visited[i] = False",
"+ return ret",
"- ab = [list(map(int, input().split())) for i in range(m)]",
"- g = [[] for i in range(n + 1)]",
"- for i in ab:",
"- g[i[0]].append(i[1])",
"- g[i[1]].append(i[0])",
"- que = deque()",
"- que.append([1, -1, 0, set([1])])",
"- ans = 0",
"- while que:",
"- v, p, cnt, check = que.popleft()",
"- if cnt >= n - 1:",
"- if len(check) == n:",
"- ans += 1",
"- continue",
"- for nv in g[v]:",
"- if nv == p:",
"- continue",
"- a = dc(check)",
"- a.add(nv)",
"- que.append([nv, v, cnt + 1, a])",
"- print(ans)",
"+ e = [list(map(int, input().split())) for i in range(m)]",
"+ g = [[False for j in range(n)] for i in range(n)]",
"+ for i, j in e:",
"+ g[i - 1][j - 1] = True",
"+ g[j - 1][i - 1] = True",
"+ visited = [False for i in range(n)]",
"+ visited[0] = True",
"+ print((Dfs(g, 0, n, visited)))"
]
| false | 0.073029 | 0.037722 | 1.935959 | [
"s179569131",
"s134028919"
]
|
u145231176 | p03014 | python | s287430628 | s544457662 | 996 | 563 | 92,380 | 152,664 | Accepted | Accepted | 43.47 | def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
h,w = [int(i) for i in input().split()]
b = [eval(input()) for i in range(h)]
ans = [[0]*w for i in range(h)]
for i in range(h):
res = 0
for j in range(w):
if b[i][j] == ".":
ans[i][j] += res
if b[i][j] == ".":
res += 1
else:
res = 0
for i in range(h):
res = 0
for j in range(w-1,-1,-1):
if b[i][j] == ".":
ans[i][j] += res
if b[i][j] == ".":
res += 1
else:
res = 0
for j in range(w):
res = 0
for i in range(h):
if b[i][j] == ".":
ans[i][j] += res
if b[i][j] == ".":
res += 1
else:
res = 0
for j in range(w):
res = 0
for i in range(h-1,-1,-1):
if b[i][j] == ".":
ans[i][j] += res
if b[i][j] == ".":
res += 1
else:
res = 0
print((max(max(row) for row in ans) + 1)) | def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
H, W = getNM()
S = [eval(input()) for i in range(H)]
score_w = [[0] * W for i in range(H)]
score_h = [[0] * W for i in range(H)]
for i in range(H):
now = -1
for j in range(W):
if now == -1:
# ๅๆๅ
if S[i][j] == '.':
now = 1
score_w[i][j] = now
else:
# ๆฌกใ.ใฎๆ
if S[i][j] == '.':
now += 1
score_w[i][j] = now
# ๆฌกใ#ใฎๆ
else:
now = -1
for j in range(1, W):
if score_w[i][-j - 1] > 0:
score_w[i][-j - 1] = max(score_w[i][-j - 1], score_w[i][-j])
for j in range(W):
now = -1
for i in range(H):
if now == -1:
# ๅๆๅ
if S[i][j] == '.':
now = 1
score_h[i][j] = now
else:
# ๆฌกใ.ใฎๆ
if S[i][j] == '.':
now += 1
score_h[i][j] = now
# ๆฌกใ#ใฎๆ
else:
now = -1
for i in range(1, H):
if score_h[-i - 1][j] > 0:
score_h[-i - 1][j] = max(score_h[-i - 1][j], score_h[-i][j])
ans = 0
for i in range(H):
for j in range(W):
if S[i][j] == ".":
ans = max(ans, score_w[i][j] + score_h[i][j] - 1)
print(ans) | 70 | 105 | 1,542 | 2,655 | def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
h, w = [int(i) for i in input().split()]
b = [eval(input()) for i in range(h)]
ans = [[0] * w for i in range(h)]
for i in range(h):
res = 0
for j in range(w):
if b[i][j] == ".":
ans[i][j] += res
if b[i][j] == ".":
res += 1
else:
res = 0
for i in range(h):
res = 0
for j in range(w - 1, -1, -1):
if b[i][j] == ".":
ans[i][j] += res
if b[i][j] == ".":
res += 1
else:
res = 0
for j in range(w):
res = 0
for i in range(h):
if b[i][j] == ".":
ans[i][j] += res
if b[i][j] == ".":
res += 1
else:
res = 0
for j in range(w):
res = 0
for i in range(h - 1, -1, -1):
if b[i][j] == ".":
ans[i][j] += res
if b[i][j] == ".":
res += 1
else:
res = 0
print((max(max(row) for row in ans) + 1))
| def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
H, W = getNM()
S = [eval(input()) for i in range(H)]
score_w = [[0] * W for i in range(H)]
score_h = [[0] * W for i in range(H)]
for i in range(H):
now = -1
for j in range(W):
if now == -1:
# ๅๆๅ
if S[i][j] == ".":
now = 1
score_w[i][j] = now
else:
# ๆฌกใ.ใฎๆ
if S[i][j] == ".":
now += 1
score_w[i][j] = now
# ๆฌกใ#ใฎๆ
else:
now = -1
for j in range(1, W):
if score_w[i][-j - 1] > 0:
score_w[i][-j - 1] = max(score_w[i][-j - 1], score_w[i][-j])
for j in range(W):
now = -1
for i in range(H):
if now == -1:
# ๅๆๅ
if S[i][j] == ".":
now = 1
score_h[i][j] = now
else:
# ๆฌกใ.ใฎๆ
if S[i][j] == ".":
now += 1
score_h[i][j] = now
# ๆฌกใ#ใฎๆ
else:
now = -1
for i in range(1, H):
if score_h[-i - 1][j] > 0:
score_h[-i - 1][j] = max(score_h[-i - 1][j], score_h[-i][j])
ans = 0
for i in range(H):
for j in range(W):
if S[i][j] == ".":
ans = max(ans, score_w[i][j] + score_h[i][j] - 1)
print(ans)
| false | 33.333333 | [
"+def rand_N(ran1, ran2):",
"+ return random.randint(ran1, ran2)",
"+",
"+",
"+def rand_List(ran1, ran2, rantime):",
"+ return [random.randint(ran1, ran2) for i in range(rantime)]",
"+",
"+",
"+def rand_ints_nodup(ran1, ran2, rantime):",
"+ ns = []",
"+ while len(ns) < rantime:",
"+ n = random.randint(ran1, ran2)",
"+ if not n in ns:",
"+ ns.append(n)",
"+ return sorted(ns)",
"+",
"+",
"+def rand_query(ran1, ran2, rantime):",
"+ r_query = []",
"+ while len(r_query) < rantime:",
"+ n_q = rand_ints_nodup(ran1, ran2, 2)",
"+ if not n_q in r_query:",
"+ r_query.append(n_q)",
"+ return sorted(r_query)",
"+",
"+",
"+from decimal import *",
"+from fractions import gcd",
"+import random",
"+import string",
"+from itertools import combinations, permutations, product",
"-h, w = [int(i) for i in input().split()]",
"-b = [eval(input()) for i in range(h)]",
"-ans = [[0] * w for i in range(h)]",
"-for i in range(h):",
"- res = 0",
"- for j in range(w):",
"- if b[i][j] == \".\":",
"- ans[i][j] += res",
"- if b[i][j] == \".\":",
"- res += 1",
"+#############",
"+# Main Code #",
"+#############",
"+H, W = getNM()",
"+S = [eval(input()) for i in range(H)]",
"+score_w = [[0] * W for i in range(H)]",
"+score_h = [[0] * W for i in range(H)]",
"+for i in range(H):",
"+ now = -1",
"+ for j in range(W):",
"+ if now == -1:",
"+ # ๅๆๅ",
"+ if S[i][j] == \".\":",
"+ now = 1",
"+ score_w[i][j] = now",
"- res = 0",
"-for i in range(h):",
"- res = 0",
"- for j in range(w - 1, -1, -1):",
"- if b[i][j] == \".\":",
"- ans[i][j] += res",
"- if b[i][j] == \".\":",
"- res += 1",
"+ # ๆฌกใ.ใฎๆ",
"+ if S[i][j] == \".\":",
"+ now += 1",
"+ score_w[i][j] = now",
"+ # ๆฌกใ#ใฎๆ",
"+ else:",
"+ now = -1",
"+ for j in range(1, W):",
"+ if score_w[i][-j - 1] > 0:",
"+ score_w[i][-j - 1] = max(score_w[i][-j - 1], score_w[i][-j])",
"+for j in range(W):",
"+ now = -1",
"+ for i in range(H):",
"+ if now == -1:",
"+ # ๅๆๅ",
"+ if S[i][j] == \".\":",
"+ now = 1",
"+ score_h[i][j] = now",
"- res = 0",
"-for j in range(w):",
"- res = 0",
"- for i in range(h):",
"- if b[i][j] == \".\":",
"- ans[i][j] += res",
"- if b[i][j] == \".\":",
"- res += 1",
"- else:",
"- res = 0",
"-for j in range(w):",
"- res = 0",
"- for i in range(h - 1, -1, -1):",
"- if b[i][j] == \".\":",
"- ans[i][j] += res",
"- if b[i][j] == \".\":",
"- res += 1",
"- else:",
"- res = 0",
"-print((max(max(row) for row in ans) + 1))",
"+ # ๆฌกใ.ใฎๆ",
"+ if S[i][j] == \".\":",
"+ now += 1",
"+ score_h[i][j] = now",
"+ # ๆฌกใ#ใฎๆ",
"+ else:",
"+ now = -1",
"+ for i in range(1, H):",
"+ if score_h[-i - 1][j] > 0:",
"+ score_h[-i - 1][j] = max(score_h[-i - 1][j], score_h[-i][j])",
"+ans = 0",
"+for i in range(H):",
"+ for j in range(W):",
"+ if S[i][j] == \".\":",
"+ ans = max(ans, score_w[i][j] + score_h[i][j] - 1)",
"+print(ans)"
]
| false | 0.038562 | 0.03874 | 0.995404 | [
"s287430628",
"s544457662"
]
|
u608088992 | p03035 | python | s611315350 | s663205648 | 56 | 18 | 3,824 | 2,940 | Accepted | Accepted | 67.86 | import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
a, b = max(a, b), min(a, b)
while a % b > 0: a, b = b, a % b
return b
def solve():
A, B = list(map(int, line_input()))
if A >= 13: print(B)
elif A >= 6: print((B//2))
else: print((0))
return 0
if __name__ == "__main__":
solve() | import sys
def solve():
input = sys.stdin.readline
A, B = list(map(int, input().split()))
if A <= 5: B = 0
elif A <= 12: B //= 2
print(B)
return 0
if __name__ == "__main__":
solve() | 18 | 13 | 463 | 218 | import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input():
return F.readline().strip("\n")
def line_input():
return F.readline().strip("\n").split()
def gcd(a, b):
a, b = max(a, b), min(a, b)
while a % b > 0:
a, b = b, a % b
return b
def solve():
A, B = list(map(int, line_input()))
if A >= 13:
print(B)
elif A >= 6:
print((B // 2))
else:
print((0))
return 0
if __name__ == "__main__":
solve()
| import sys
def solve():
input = sys.stdin.readline
A, B = list(map(int, input().split()))
if A <= 5:
B = 0
elif A <= 12:
B //= 2
print(B)
return 0
if __name__ == "__main__":
solve()
| false | 27.777778 | [
"-import sys, math, collections, heapq, itertools",
"-",
"-F = sys.stdin",
"-",
"-",
"-def single_input():",
"- return F.readline().strip(\"\\n\")",
"-",
"-",
"-def line_input():",
"- return F.readline().strip(\"\\n\").split()",
"-",
"-",
"-def gcd(a, b):",
"- a, b = max(a, b), min(a, b)",
"- while a % b > 0:",
"- a, b = b, a % b",
"- return b",
"+import sys",
"- A, B = list(map(int, line_input()))",
"- if A >= 13:",
"- print(B)",
"- elif A >= 6:",
"- print((B // 2))",
"- else:",
"- print((0))",
"+ input = sys.stdin.readline",
"+ A, B = list(map(int, input().split()))",
"+ if A <= 5:",
"+ B = 0",
"+ elif A <= 12:",
"+ B //= 2",
"+ print(B)"
]
| false | 0.160661 | 0.15128 | 1.06201 | [
"s611315350",
"s663205648"
]
|
u803848678 | p03182 | python | s866119890 | s354656936 | 1,652 | 1,460 | 107,468 | 105,292 | Accepted | Accepted | 11.62 | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
class RAQ_RMQ:
def __init__(self, n, a=None, F=min, e=float("inf")):
self.n = n
self.n0 = 2**(n-1).bit_length()
self.e = e
self.F = F
self.lazy = [0]*(2*self.n0)
if a is None:
self.data = [e]*(2*self.n0)
else:
self.data = [0]*(2*self.n0)
self.construct(a)
def construct(self, a):
for i, x in enumerate(a):
self.data[i+self.n0] = x
for i in range(self.n0-1, 0, -1):
self.data[i] = self.F(self.data[2*i], self.data[2*i+1])
def bottomup(self, i):
i += self.n0
k = i//(i & -i)
c = k.bit_length()
for j in range(c-1):
k >>= 1
self.data[k] = self.F(self.data[2*k], self.data[2*k+1]) + self.lazy[k]
def topdown(self, i):
i += self.n0
k = i//(i & -i)
c = k.bit_length()
for j in range(c-1):
idx = k >> (c - j - 1)
ax = self.lazy[idx]
if not ax:
continue
self.lazy[idx] = 0
self.data[2*idx] += ax
self.data[2*idx+1] += ax
self.lazy[2*idx] += ax
self.lazy[2*idx+1] += ax
def query(self, l, r):
self.topdown(l)
self.topdown(r)
L = l+self.n0
R = r+self.n0
s = self.e
while L < R:
if R & 1:
R -= 1
s = self.F(s, self.data[R])
if L & 1:
s = self.F(s, self.data[L])
L += 1
L >>= 1
R >>= 1
return s
def add(self, l, r, x):
L = l+self.n0
R = r+self.n0
while L < R :
if R & 1:
R -= 1
self.data[R] += x
self.lazy[R] += x
if L & 1:
self.data[L] += x
self.lazy[L] += x
L += 1
L >>= 1
R >>= 1
self.bottomup(l)
self.bottomup(r)
n,m = list(map(int, input().split()))
memo = [[] for i in range(n+2)]
for i in range(m):
l,r,a = list(map(int, input().split()))
memo[l].append((l,a))
memo[r+1].append((l,-a))
seg = RAQ_RMQ(n+2, a=[0]*(n+2), F=max, e=-float("inf"))
for i in range(1, n+2):
for j, a in memo[i]:
seg.add(0, j, a)
tmp = seg.query(0, i)
seg.add(i, i+1, tmp)
ans = seg.query(0, n+1)
print(ans) | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
class RAQ_RMQ:
def __init__(self, n, F=min, e=float("inf"), fill=None):
self.n = n
self.n0 = 2**(n-1).bit_length()
self.e = e
self.F = F
self.lazy = [0]*(2*self.n0)
if fill is None:
fill = e
self.data = [fill]*(2*self.n0)
def construct(self, a):
for i, x in enumerate(a):
self.data[i+self.n0] = x
for i in range(self.n0-1, 0, -1):
self.data[i] = self.F(self.data[2*i], self.data[2*i+1])
def bottomup(self, i):
i += self.n0
k = i//(i & -i)
c = k.bit_length()
for j in range(c-1):
k >>= 1
self.data[k] = self.F(self.data[2*k], self.data[2*k+1]) + self.lazy[k]
def topdown(self, i):
i += self.n0
k = i//(i & -i)
c = k.bit_length()
for j in range(c-1):
idx = k >> (c - j - 1)
ax = self.lazy[idx]
if not ax:
continue
self.lazy[idx] = 0
self.data[2*idx] += ax
self.data[2*idx+1] += ax
self.lazy[2*idx] += ax
self.lazy[2*idx+1] += ax
def query(self, l, r):
self.topdown(l)
self.topdown(r)
L = l+self.n0
R = r+self.n0
s = self.e
while L < R:
if R & 1:
R -= 1
s = self.F(s, self.data[R])
if L & 1:
s = self.F(s, self.data[L])
L += 1
L >>= 1
R >>= 1
return s
def add(self, l, r, x):
L = l+self.n0
R = r+self.n0
while L < R :
if R & 1:
R -= 1
self.data[R] += x
self.lazy[R] += x
if L & 1:
self.data[L] += x
self.lazy[L] += x
L += 1
L >>= 1
R >>= 1
self.bottomup(l)
self.bottomup(r)
n,m = list(map(int, input().split()))
memo = [[] for i in range(n+2)]
for i in range(m):
l,r,a = list(map(int, input().split()))
memo[l].append((l,a))
memo[r+1].append((l,-a))
seg = RAQ_RMQ(n+2, F=max, e=-float("inf"), fill=0)
for i in range(1, n+2):
for j, a in memo[i]:
seg.add(0, j, a)
tmp = seg.query(0, i)
seg.add(i, i+1, tmp)
ans = seg.query(0, n+1)
print(ans) | 101 | 99 | 2,594 | 2,529 | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
class RAQ_RMQ:
def __init__(self, n, a=None, F=min, e=float("inf")):
self.n = n
self.n0 = 2 ** (n - 1).bit_length()
self.e = e
self.F = F
self.lazy = [0] * (2 * self.n0)
if a is None:
self.data = [e] * (2 * self.n0)
else:
self.data = [0] * (2 * self.n0)
self.construct(a)
def construct(self, a):
for i, x in enumerate(a):
self.data[i + self.n0] = x
for i in range(self.n0 - 1, 0, -1):
self.data[i] = self.F(self.data[2 * i], self.data[2 * i + 1])
def bottomup(self, i):
i += self.n0
k = i // (i & -i)
c = k.bit_length()
for j in range(c - 1):
k >>= 1
self.data[k] = self.F(self.data[2 * k], self.data[2 * k + 1]) + self.lazy[k]
def topdown(self, i):
i += self.n0
k = i // (i & -i)
c = k.bit_length()
for j in range(c - 1):
idx = k >> (c - j - 1)
ax = self.lazy[idx]
if not ax:
continue
self.lazy[idx] = 0
self.data[2 * idx] += ax
self.data[2 * idx + 1] += ax
self.lazy[2 * idx] += ax
self.lazy[2 * idx + 1] += ax
def query(self, l, r):
self.topdown(l)
self.topdown(r)
L = l + self.n0
R = r + self.n0
s = self.e
while L < R:
if R & 1:
R -= 1
s = self.F(s, self.data[R])
if L & 1:
s = self.F(s, self.data[L])
L += 1
L >>= 1
R >>= 1
return s
def add(self, l, r, x):
L = l + self.n0
R = r + self.n0
while L < R:
if R & 1:
R -= 1
self.data[R] += x
self.lazy[R] += x
if L & 1:
self.data[L] += x
self.lazy[L] += x
L += 1
L >>= 1
R >>= 1
self.bottomup(l)
self.bottomup(r)
n, m = list(map(int, input().split()))
memo = [[] for i in range(n + 2)]
for i in range(m):
l, r, a = list(map(int, input().split()))
memo[l].append((l, a))
memo[r + 1].append((l, -a))
seg = RAQ_RMQ(n + 2, a=[0] * (n + 2), F=max, e=-float("inf"))
for i in range(1, n + 2):
for j, a in memo[i]:
seg.add(0, j, a)
tmp = seg.query(0, i)
seg.add(i, i + 1, tmp)
ans = seg.query(0, n + 1)
print(ans)
| import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
class RAQ_RMQ:
def __init__(self, n, F=min, e=float("inf"), fill=None):
self.n = n
self.n0 = 2 ** (n - 1).bit_length()
self.e = e
self.F = F
self.lazy = [0] * (2 * self.n0)
if fill is None:
fill = e
self.data = [fill] * (2 * self.n0)
def construct(self, a):
for i, x in enumerate(a):
self.data[i + self.n0] = x
for i in range(self.n0 - 1, 0, -1):
self.data[i] = self.F(self.data[2 * i], self.data[2 * i + 1])
def bottomup(self, i):
i += self.n0
k = i // (i & -i)
c = k.bit_length()
for j in range(c - 1):
k >>= 1
self.data[k] = self.F(self.data[2 * k], self.data[2 * k + 1]) + self.lazy[k]
def topdown(self, i):
i += self.n0
k = i // (i & -i)
c = k.bit_length()
for j in range(c - 1):
idx = k >> (c - j - 1)
ax = self.lazy[idx]
if not ax:
continue
self.lazy[idx] = 0
self.data[2 * idx] += ax
self.data[2 * idx + 1] += ax
self.lazy[2 * idx] += ax
self.lazy[2 * idx + 1] += ax
def query(self, l, r):
self.topdown(l)
self.topdown(r)
L = l + self.n0
R = r + self.n0
s = self.e
while L < R:
if R & 1:
R -= 1
s = self.F(s, self.data[R])
if L & 1:
s = self.F(s, self.data[L])
L += 1
L >>= 1
R >>= 1
return s
def add(self, l, r, x):
L = l + self.n0
R = r + self.n0
while L < R:
if R & 1:
R -= 1
self.data[R] += x
self.lazy[R] += x
if L & 1:
self.data[L] += x
self.lazy[L] += x
L += 1
L >>= 1
R >>= 1
self.bottomup(l)
self.bottomup(r)
n, m = list(map(int, input().split()))
memo = [[] for i in range(n + 2)]
for i in range(m):
l, r, a = list(map(int, input().split()))
memo[l].append((l, a))
memo[r + 1].append((l, -a))
seg = RAQ_RMQ(n + 2, F=max, e=-float("inf"), fill=0)
for i in range(1, n + 2):
for j, a in memo[i]:
seg.add(0, j, a)
tmp = seg.query(0, i)
seg.add(i, i + 1, tmp)
ans = seg.query(0, n + 1)
print(ans)
| false | 1.980198 | [
"- def __init__(self, n, a=None, F=min, e=float(\"inf\")):",
"+ def __init__(self, n, F=min, e=float(\"inf\"), fill=None):",
"- if a is None:",
"- self.data = [e] * (2 * self.n0)",
"- else:",
"- self.data = [0] * (2 * self.n0)",
"- self.construct(a)",
"+ if fill is None:",
"+ fill = e",
"+ self.data = [fill] * (2 * self.n0)",
"-seg = RAQ_RMQ(n + 2, a=[0] * (n + 2), F=max, e=-float(\"inf\"))",
"+seg = RAQ_RMQ(n + 2, F=max, e=-float(\"inf\"), fill=0)"
]
| false | 0.03976 | 0.125389 | 0.317091 | [
"s866119890",
"s354656936"
]
|
u155024797 | p03409 | python | s750084978 | s870720240 | 201 | 178 | 39,024 | 38,768 | Accepted | Accepted | 11.44 | def main():
N = int(eval(input()))
points = []
for _ in range(N):
x, y = list(map(int, input().split()))
points.append((x, y, "r"))
for _ in range(N):
x, y = list(map(int, input().split()))
points.append((x, y, "b"))
points.sort(lambda x: x[0])
singles = []
retval = 0
for p in points:
x, y, c = p
if c == "r":
singles.append(y)
if c == "b":
maximum = (-1, -1)
for i, v in enumerate(singles):
if v < y and v > maximum[1]:
maximum = (i, v)
if maximum[0] != -1:
retval += 1
singles.pop(maximum[0])
print(retval)
if __name__ == "__main__":
main()
| import heapq
def main():
N = int(eval(input()))
R = [list(map(int, input().split())) + ['R'] for _ in range(N)]
B = [list(map(int, input().split())) + ['B'] for _ in range(N)]
P = R + B
P.sort(key=lambda x: (x[0], x[1]))
solo = []
ans = 0
for p in P:
x, y, c = p
if c == 'R':
solo.append((x, y))
else:
tmp = (-1, -1)
for s in solo:
if s[0] < x and tmp[1] < s[1] < y:
tmp = s
if tmp != (-1, -1):
solo.remove(tmp)
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 29 | 28 | 768 | 671 | def main():
N = int(eval(input()))
points = []
for _ in range(N):
x, y = list(map(int, input().split()))
points.append((x, y, "r"))
for _ in range(N):
x, y = list(map(int, input().split()))
points.append((x, y, "b"))
points.sort(lambda x: x[0])
singles = []
retval = 0
for p in points:
x, y, c = p
if c == "r":
singles.append(y)
if c == "b":
maximum = (-1, -1)
for i, v in enumerate(singles):
if v < y and v > maximum[1]:
maximum = (i, v)
if maximum[0] != -1:
retval += 1
singles.pop(maximum[0])
print(retval)
if __name__ == "__main__":
main()
| import heapq
def main():
N = int(eval(input()))
R = [list(map(int, input().split())) + ["R"] for _ in range(N)]
B = [list(map(int, input().split())) + ["B"] for _ in range(N)]
P = R + B
P.sort(key=lambda x: (x[0], x[1]))
solo = []
ans = 0
for p in P:
x, y, c = p
if c == "R":
solo.append((x, y))
else:
tmp = (-1, -1)
for s in solo:
if s[0] < x and tmp[1] < s[1] < y:
tmp = s
if tmp != (-1, -1):
solo.remove(tmp)
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 3.448276 | [
"+import heapq",
"+",
"+",
"- points = []",
"- for _ in range(N):",
"- x, y = list(map(int, input().split()))",
"- points.append((x, y, \"r\"))",
"- for _ in range(N):",
"- x, y = list(map(int, input().split()))",
"- points.append((x, y, \"b\"))",
"- points.sort(lambda x: x[0])",
"- singles = []",
"- retval = 0",
"- for p in points:",
"+ R = [list(map(int, input().split())) + [\"R\"] for _ in range(N)]",
"+ B = [list(map(int, input().split())) + [\"B\"] for _ in range(N)]",
"+ P = R + B",
"+ P.sort(key=lambda x: (x[0], x[1]))",
"+ solo = []",
"+ ans = 0",
"+ for p in P:",
"- if c == \"r\":",
"- singles.append(y)",
"- if c == \"b\":",
"- maximum = (-1, -1)",
"- for i, v in enumerate(singles):",
"- if v < y and v > maximum[1]:",
"- maximum = (i, v)",
"- if maximum[0] != -1:",
"- retval += 1",
"- singles.pop(maximum[0])",
"- print(retval)",
"+ if c == \"R\":",
"+ solo.append((x, y))",
"+ else:",
"+ tmp = (-1, -1)",
"+ for s in solo:",
"+ if s[0] < x and tmp[1] < s[1] < y:",
"+ tmp = s",
"+ if tmp != (-1, -1):",
"+ solo.remove(tmp)",
"+ ans += 1",
"+ print(ans)"
]
| false | 0.036166 | 0.035351 | 1.023044 | [
"s750084978",
"s870720240"
]
|
u076917070 | p02845 | python | s470438295 | s061463663 | 209 | 96 | 20,792 | 13,972 | Accepted | Accepted | 54.07 | import sys
input = sys.stdin.readline
def main():
mod = 1000000007
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = [[0, 0, 0] for i in range(N+1)]
ans = 1
for i in range(N):
a = A[i]
ans = ans * cnt[i].count(a) % mod
for j in range(3):
cnt[i+1][j] = cnt[i][j]
for j in range(3):
if cnt[i][j] == a:
cnt[i+1][j] = a+1
break
print(ans)
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
def main():
mod = 1000000007
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = [0, 0, 0]
ans = 1
for a in A:
ans = ans * cnt.count(a) % mod
for j in range(3):
if cnt[j] == a:
cnt[j] = a+1
break
print(ans)
if __name__ == '__main__':
main()
| 24 | 21 | 525 | 402 | import sys
input = sys.stdin.readline
def main():
mod = 1000000007
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = [[0, 0, 0] for i in range(N + 1)]
ans = 1
for i in range(N):
a = A[i]
ans = ans * cnt[i].count(a) % mod
for j in range(3):
cnt[i + 1][j] = cnt[i][j]
for j in range(3):
if cnt[i][j] == a:
cnt[i + 1][j] = a + 1
break
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
mod = 1000000007
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = [0, 0, 0]
ans = 1
for a in A:
ans = ans * cnt.count(a) % mod
for j in range(3):
if cnt[j] == a:
cnt[j] = a + 1
break
print(ans)
if __name__ == "__main__":
main()
| false | 12.5 | [
"- cnt = [[0, 0, 0] for i in range(N + 1)]",
"+ cnt = [0, 0, 0]",
"- for i in range(N):",
"- a = A[i]",
"- ans = ans * cnt[i].count(a) % mod",
"+ for a in A:",
"+ ans = ans * cnt.count(a) % mod",
"- cnt[i + 1][j] = cnt[i][j]",
"- for j in range(3):",
"- if cnt[i][j] == a:",
"- cnt[i + 1][j] = a + 1",
"+ if cnt[j] == a:",
"+ cnt[j] = a + 1"
]
| false | 0.036035 | 0.041375 | 0.870922 | [
"s470438295",
"s061463663"
]
|
u780342333 | p02259 | python | s639991209 | s666331247 | 30 | 20 | 7,732 | 5,608 | Accepted | Accepted | 33.33 | N = int(eval(input()))
A = [int(x) for x in input().split(" ")]
flag = True
swap_count = 0
i = 0
while flag:
flag = False
for j in range(N-1, i, -1):
if A[j] < A[j-1]:
A[j], A[j-1] = A[j-1], A[j]
flag = True
swap_count += 1
i += 1
print((*A))
print(swap_count) | 1# bubbleSort(A, N) // N ๅใฎ่ฆ็ด ใๅซใ 0-ใชใชใธใณใฎ้
ๅ A
2# flag = 1 // ้ใฎ้ฃๆฅ่ฆ็ด ใๅญๅจใใ
3# while flag
4# flag = 0
5# for j ใ N-1 ใใ 1 ใพใง
6# if A[j] < A[j-1]
7# A[j] ใจ A[j-1] ใไบคๆ
8# flag = 1
n = int(eval(input()))
nums = list(map(int, input().split()))
count = 0
flag = True
while flag:
flag = False
for j in range(n-1, 0, -1):
if nums[j] < nums[j-1]:
nums[j], nums[j-1] = nums[j-1], nums[j]
count += 1
flag = True
print((*nums))
print(count)
| 16 | 23 | 324 | 528 | N = int(eval(input()))
A = [int(x) for x in input().split(" ")]
flag = True
swap_count = 0
i = 0
while flag:
flag = False
for j in range(N - 1, i, -1):
if A[j] < A[j - 1]:
A[j], A[j - 1] = A[j - 1], A[j]
flag = True
swap_count += 1
i += 1
print((*A))
print(swap_count)
| 1 # bubbleSort(A, N) // N ๅใฎ่ฆ็ด ใๅซใ 0-ใชใชใธใณใฎ้
ๅ A
2 # flag = 1 // ้ใฎ้ฃๆฅ่ฆ็ด ใๅญๅจใใ
3 # while flag
4 # flag = 0
5 # for j ใ N-1 ใใ 1 ใพใง
6 # if A[j] < A[j-1]
7 # A[j] ใจ A[j-1] ใไบคๆ
8 # flag = 1
n = int(eval(input()))
nums = list(map(int, input().split()))
count = 0
flag = True
while flag:
flag = False
for j in range(n - 1, 0, -1):
if nums[j] < nums[j - 1]:
nums[j], nums[j - 1] = nums[j - 1], nums[j]
count += 1
flag = True
print((*nums))
print(count)
| false | 30.434783 | [
"-N = int(eval(input()))",
"-A = [int(x) for x in input().split(\" \")]",
"+1 # bubbleSort(A, N) // N ๅใฎ่ฆ็ด ใๅซใ 0-ใชใชใธใณใฎ้
ๅ A",
"+2 # flag = 1 // ้ใฎ้ฃๆฅ่ฆ็ด ใๅญๅจใใ",
"+3 # while flag",
"+4 # flag = 0",
"+5 # for j ใ N-1 ใใ 1 ใพใง",
"+6 # if A[j] < A[j-1]",
"+7 # A[j] ใจ A[j-1] ใไบคๆ",
"+8 # flag = 1",
"+n = int(eval(input()))",
"+nums = list(map(int, input().split()))",
"+count = 0",
"-swap_count = 0",
"-i = 0",
"- for j in range(N - 1, i, -1):",
"- if A[j] < A[j - 1]:",
"- A[j], A[j - 1] = A[j - 1], A[j]",
"+ for j in range(n - 1, 0, -1):",
"+ if nums[j] < nums[j - 1]:",
"+ nums[j], nums[j - 1] = nums[j - 1], nums[j]",
"+ count += 1",
"- swap_count += 1",
"- i += 1",
"-print((*A))",
"-print(swap_count)",
"+print((*nums))",
"+print(count)"
]
| false | 0.043407 | 0.046315 | 0.937205 | [
"s639991209",
"s666331247"
]
|
u296518383 | p02803 | python | s894373068 | s978955538 | 557 | 302 | 3,316 | 48,492 | Accepted | Accepted | 45.78 | from collections import deque
H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
INF = 10**15
answer = 0
for i in range(H):
for j in range(W):
if S[i][j] == "#":
continue
else:
dist = [[INF for _ in range(W)] for _ in range(H)] # ๅง็นใใใฎ่ท้ข
dist[i][j] = 0 # ๅง็นใๅฎ็พฉ
stack = deque([(i, j)]) # ๅง็นใ"ๅ
ๅ
ฅใๅ
ๅบใ"ใฎ้
ๅใซๅ
ฅใใ
while stack:
# BFS
# * ่จ็ฎ้ O(4HW:่พบใฎๆฐ)
si, sj = stack.popleft()
# "ๅ
ๅ
ฅใๅ
ๅบใ"
# * โๅพๅ
ฅใๅพๅบใใDFS
# si, sj = stack.pop()
for ni, nj in [(si + 1, sj), (si - 1, sj), (si, sj + 1), (si, sj - 1)]:
# ็ต่ทฏใซ้ใฟใใชใๅ ดๅใBFSใงใฏๅ
ใซๅ
ฅใใๆนใใใฎใในใซๅฏพใใๆ็ญ็ต่ทฏใซใชใ...โ
# * DFSใไฝฟ็จใใใจๆดๆฐใฎๅฟ
่ฆใใใใ
# ่จ็ฎ้ใ(4HW*HW:่พบใฎๆฐรใฐใชใใใฎๆฐ)->TLE
# ** ๆจใ ใจ็ต่ทฏใฏ1ใคใใใชใใใใBFSใDFSใ่จ็ฎ้ใฏๅใ
# ใฐใฉใใงใฏๅบๆฌ็ใซBFSๆจๅฅจ[่ฆๅบๅ
ธ]
# * ็ต่ทฏใซ้ใฟใใใๅ ดๅใๆดๆฐใฎๅฟ
่ฆใใใใ่จ็ฎ้ใฏO(4HW*HW)
# ** Dijkstraๆณใไฝฟใใฐใ่จ็ฎ้ใฏO(4HW+HWlogHW)
# O(E + VlogV): E -> Edge, V -> Vertex
if 0 <= ni <= H - 1 and 0 <= nj <= W - 1 and S[ni][nj] != "#":
if dist[ni][nj] > dist[si][sj] + 1:
dist[ni][nj] = dist[si][sj] + 1
stack.append((ni, nj))
# โใใใๆ็ญ็ต่ทฏใใจใใในใใใฎ้ฃๆฅใๆฌกใฎๆ็ญ็ต่ทฏใฎๅ่ฃใจใชใ
# ใใงใซๆ็ญ็ต่ทฏใๅใฃใฆใใใใฎใฏๆ้ค
max_dist = 0
for ii in range(H):
for jj in range(W):
if dist[ii][jj] != INF:
max_dist = max(max_dist, dist[ii][jj])
answer = max(max_dist, answer)
# * ๆทปใๅญ่ขซใใซๆณจๆ
print(answer) | from collections import deque
H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
INF = 10**15
answer = 0
for i in range(H):
for j in range(W):
if S[i][j] == "#":
continue
else:
dist = [[INF for _ in range(W)] for _ in range(H)] # ๅง็นใใใฎ่ท้ข
dist[i][j] = 0 # ๅง็นใๅฎ็พฉ
queue = deque([(i, j)]) # ๅง็นใ"ๅ
ๅ
ฅใๅ
ๅบใ"ใฎ้
ๅใซๅ
ฅใใ
while queue:
# BFS
# * ่จ็ฎ้ O(4HW:่พบใฎๆฐ)
si, sj = queue.popleft()
# "ๅ
ๅ
ฅใๅ
ๅบใ"
# * โๅพๅ
ฅใๅ
ๅบใใDFS
# si, sj = stack.pop()
for ni, nj in [(si + 1, sj), (si - 1, sj), (si, sj + 1), (si, sj - 1)]:
# ็ต่ทฏใซ้ใฟใใชใๅ ดๅใBFSใงใฏๅ
ใซๅ
ฅใใๆนใใใฎใในใซๅฏพใใๆ็ญ็ต่ทฏใซใชใ...โ
# * DFSใไฝฟ็จใใใจๆดๆฐใฎๅฟ
่ฆใใใใ
# ่จ็ฎ้ใ(4HW*HW:่พบใฎๆฐรใฐใชใใใฎๆฐ) -> TLE
# ** ๆจใ ใจ็ต่ทฏใฏ1ใคใใใชใใใใBFSใDFSใ่จ็ฎ้ใฏๅใ
# ใฐใฉใใงใฏๅบๆฌ็ใซBFSๆจๅฅจ[่ฆๅบๅ
ธ]
# * ็ต่ทฏใซ้ใฟใใใๅ ดๅใๆดๆฐใฎๅฟ
่ฆใใใใ่จ็ฎ้ใฏO(4HW*HW)
# ** Dijkstraๆณใไฝฟใใฐใ่จ็ฎ้ใฏO(4HW+HWlogHW)
# O(E + VlogV): E -> Edge, V -> Vertex
if 0 <= ni <= H - 1 and 0 <= nj <= W - 1 and S[ni][nj] != "#":
if dist[ni][nj] > dist[si][sj] + 1:
dist[ni][nj] = dist[si][sj] + 1
queue.append((ni, nj))
# โใใใๆ็ญ็ต่ทฏใใจใใในใใใฎ้ฃๆฅใๆฌกใฎๆ็ญ็ต่ทฏใฎๅ่ฃใจใชใ
# ใใงใซๆ็ญ็ต่ทฏใๅใฃใฆใใใใฎใฏๆ้ค
max_dist = 0
for ii in range(H):
for jj in range(W):
if dist[ii][jj] != INF:
max_dist = max(max_dist, dist[ii][jj])
answer = max(max_dist, answer)
# ๆทปใๅญ่ขซใใซๆณจๆ
print(answer)
| 50 | 51 | 1,557 | 1,543 | from collections import deque
H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
INF = 10**15
answer = 0
for i in range(H):
for j in range(W):
if S[i][j] == "#":
continue
else:
dist = [[INF for _ in range(W)] for _ in range(H)] # ๅง็นใใใฎ่ท้ข
dist[i][j] = 0 # ๅง็นใๅฎ็พฉ
stack = deque([(i, j)]) # ๅง็นใ"ๅ
ๅ
ฅใๅ
ๅบใ"ใฎ้
ๅใซๅ
ฅใใ
while stack:
# BFS
# * ่จ็ฎ้ O(4HW:่พบใฎๆฐ)
si, sj = stack.popleft()
# "ๅ
ๅ
ฅใๅ
ๅบใ"
# * โๅพๅ
ฅใๅพๅบใใDFS
# si, sj = stack.pop()
for ni, nj in [(si + 1, sj), (si - 1, sj), (si, sj + 1), (si, sj - 1)]:
# ็ต่ทฏใซ้ใฟใใชใๅ ดๅใBFSใงใฏๅ
ใซๅ
ฅใใๆนใใใฎใในใซๅฏพใใๆ็ญ็ต่ทฏใซใชใ...โ
# * DFSใไฝฟ็จใใใจๆดๆฐใฎๅฟ
่ฆใใใใ
# ่จ็ฎ้ใ(4HW*HW:่พบใฎๆฐรใฐใชใใใฎๆฐ)->TLE
# ** ๆจใ ใจ็ต่ทฏใฏ1ใคใใใชใใใใBFSใDFSใ่จ็ฎ้ใฏๅใ
# ใฐใฉใใงใฏๅบๆฌ็ใซBFSๆจๅฅจ[่ฆๅบๅ
ธ]
# * ็ต่ทฏใซ้ใฟใใใๅ ดๅใๆดๆฐใฎๅฟ
่ฆใใใใ่จ็ฎ้ใฏO(4HW*HW)
# ** Dijkstraๆณใไฝฟใใฐใ่จ็ฎ้ใฏO(4HW+HWlogHW)
# O(E + VlogV): E -> Edge, V -> Vertex
if 0 <= ni <= H - 1 and 0 <= nj <= W - 1 and S[ni][nj] != "#":
if dist[ni][nj] > dist[si][sj] + 1:
dist[ni][nj] = dist[si][sj] + 1
stack.append((ni, nj))
# โใใใๆ็ญ็ต่ทฏใใจใใในใใใฎ้ฃๆฅใๆฌกใฎๆ็ญ็ต่ทฏใฎๅ่ฃใจใชใ
# ใใงใซๆ็ญ็ต่ทฏใๅใฃใฆใใใใฎใฏๆ้ค
max_dist = 0
for ii in range(H):
for jj in range(W):
if dist[ii][jj] != INF:
max_dist = max(max_dist, dist[ii][jj])
answer = max(max_dist, answer)
# * ๆทปใๅญ่ขซใใซๆณจๆ
print(answer)
| from collections import deque
H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
INF = 10**15
answer = 0
for i in range(H):
for j in range(W):
if S[i][j] == "#":
continue
else:
dist = [[INF for _ in range(W)] for _ in range(H)] # ๅง็นใใใฎ่ท้ข
dist[i][j] = 0 # ๅง็นใๅฎ็พฉ
queue = deque([(i, j)]) # ๅง็นใ"ๅ
ๅ
ฅใๅ
ๅบใ"ใฎ้
ๅใซๅ
ฅใใ
while queue:
# BFS
# * ่จ็ฎ้ O(4HW:่พบใฎๆฐ)
si, sj = queue.popleft()
# "ๅ
ๅ
ฅใๅ
ๅบใ"
# * โๅพๅ
ฅใๅ
ๅบใใDFS
# si, sj = stack.pop()
for ni, nj in [(si + 1, sj), (si - 1, sj), (si, sj + 1), (si, sj - 1)]:
# ็ต่ทฏใซ้ใฟใใชใๅ ดๅใBFSใงใฏๅ
ใซๅ
ฅใใๆนใใใฎใในใซๅฏพใใๆ็ญ็ต่ทฏใซใชใ...โ
# * DFSใไฝฟ็จใใใจๆดๆฐใฎๅฟ
่ฆใใใใ
# ่จ็ฎ้ใ(4HW*HW:่พบใฎๆฐรใฐใชใใใฎๆฐ) -> TLE
# ** ๆจใ ใจ็ต่ทฏใฏ1ใคใใใชใใใใBFSใDFSใ่จ็ฎ้ใฏๅใ
# ใฐใฉใใงใฏๅบๆฌ็ใซBFSๆจๅฅจ[่ฆๅบๅ
ธ]
# * ็ต่ทฏใซ้ใฟใใใๅ ดๅใๆดๆฐใฎๅฟ
่ฆใใใใ่จ็ฎ้ใฏO(4HW*HW)
# ** Dijkstraๆณใไฝฟใใฐใ่จ็ฎ้ใฏO(4HW+HWlogHW)
# O(E + VlogV): E -> Edge, V -> Vertex
if 0 <= ni <= H - 1 and 0 <= nj <= W - 1 and S[ni][nj] != "#":
if dist[ni][nj] > dist[si][sj] + 1:
dist[ni][nj] = dist[si][sj] + 1
queue.append((ni, nj))
# โใใใๆ็ญ็ต่ทฏใใจใใในใใใฎ้ฃๆฅใๆฌกใฎๆ็ญ็ต่ทฏใฎๅ่ฃใจใชใ
# ใใงใซๆ็ญ็ต่ทฏใๅใฃใฆใใใใฎใฏๆ้ค
max_dist = 0
for ii in range(H):
for jj in range(W):
if dist[ii][jj] != INF:
max_dist = max(max_dist, dist[ii][jj])
answer = max(max_dist, answer)
# ๆทปใๅญ่ขซใใซๆณจๆ
print(answer)
| false | 1.960784 | [
"- stack = deque([(i, j)]) # ๅง็นใ\"ๅ
ๅ
ฅใๅ
ๅบใ\"ใฎ้
ๅใซๅ
ฅใใ",
"- while stack:",
"+ queue = deque([(i, j)]) # ๅง็นใ\"ๅ
ๅ
ฅใๅ
ๅบใ\"ใฎ้
ๅใซๅ
ฅใใ",
"+ while queue:",
"- si, sj = stack.popleft()",
"+ si, sj = queue.popleft()",
"- # * โๅพๅ
ฅใๅพๅบใใDFS",
"+ # * โๅพๅ
ฅใๅ
ๅบใใDFS",
"- # ่จ็ฎ้ใ(4HW*HW:่พบใฎๆฐรใฐใชใใใฎๆฐ)->TLE",
"+ # ่จ็ฎ้ใ(4HW*HW:่พบใฎๆฐรใฐใชใใใฎๆฐ) -> TLE",
"- # ใฐใฉใใงใฏๅบๆฌ็ใซBFSๆจๅฅจ[่ฆๅบๅ
ธ]",
"+ # ใฐใฉใใงใฏๅบๆฌ็ใซBFSๆจๅฅจ[่ฆๅบๅ
ธ]",
"- # O(E + VlogV): E -> Edge, V -> Vertex",
"+ # O(E + VlogV): E -> Edge, V -> Vertex",
"- stack.append((ni, nj))",
"+ queue.append((ni, nj))",
"- # * ๆทปใๅญ่ขซใใซๆณจๆ",
"+ # ๆทปใๅญ่ขซใใซๆณจๆ"
]
| false | 0.050956 | 0.10339 | 0.492855 | [
"s894373068",
"s978955538"
]
|
u124605948 | p02578 | python | s493920779 | s195306907 | 150 | 136 | 32,344 | 32,244 | Accepted | Accepted | 9.33 | n = int(eval(input()))
a = list(map(int, input().split()))
base = a[0]
ans = 0
for i in range(1, n):
base = max(base, a[i])
ans += base - a[i]
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
fllor = a[0]
ans = 0
for i in range(n):
if fllor > a[i]:
ans += fllor - a[i]
else:
fllor = max(fllor, a[i])
print(ans) | 9 | 11 | 164 | 206 | n = int(eval(input()))
a = list(map(int, input().split()))
base = a[0]
ans = 0
for i in range(1, n):
base = max(base, a[i])
ans += base - a[i]
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
fllor = a[0]
ans = 0
for i in range(n):
if fllor > a[i]:
ans += fllor - a[i]
else:
fllor = max(fllor, a[i])
print(ans)
| false | 18.181818 | [
"-base = a[0]",
"+fllor = a[0]",
"-for i in range(1, n):",
"- base = max(base, a[i])",
"- ans += base - a[i]",
"+for i in range(n):",
"+ if fllor > a[i]:",
"+ ans += fllor - a[i]",
"+ else:",
"+ fllor = max(fllor, a[i])"
]
| false | 0.091908 | 0.038708 | 2.374416 | [
"s493920779",
"s195306907"
]
|
u928784113 | p03556 | python | s064617389 | s497116666 | 56 | 51 | 3,188 | 3,060 | Accepted | Accepted | 8.93 | N = int(eval(input()))
import math
for i in range(N):
if int(math.sqrt(N-i)) == math.sqrt(N-i):
print((N-i))
exit()
else:
continue | N = int(eval(input()))
import math
for i in range(N,0,-1):
if int(math.sqrt(i)) == math.sqrt(i):
print(i)
exit() | 8 | 6 | 166 | 131 | N = int(eval(input()))
import math
for i in range(N):
if int(math.sqrt(N - i)) == math.sqrt(N - i):
print((N - i))
exit()
else:
continue
| N = int(eval(input()))
import math
for i in range(N, 0, -1):
if int(math.sqrt(i)) == math.sqrt(i):
print(i)
exit()
| false | 25 | [
"-for i in range(N):",
"- if int(math.sqrt(N - i)) == math.sqrt(N - i):",
"- print((N - i))",
"+for i in range(N, 0, -1):",
"+ if int(math.sqrt(i)) == math.sqrt(i):",
"+ print(i)",
"- else:",
"- continue"
]
| false | 0.047967 | 0.05242 | 0.915053 | [
"s064617389",
"s497116666"
]
|
u597455618 | p03363 | python | s409257667 | s060865113 | 265 | 141 | 41,148 | 38,932 | Accepted | Accepted | 46.79 | n = int(eval(input()))
a = list(map(int, input().split()))
acc = [0 for i in range(n+1)]
for i in range(n):
acc[i+1] = a[i] + acc[i]
ans = {}
for x in acc:
ans.setdefault(x, 0)
ans[x] += 1
cnt = 0
for i in ans:
cnt += ans[i]*(ans[i]-1)//2
print(cnt) | from itertools import accumulate
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
acc = accumulate(a)
counter = Counter(acc)
def cal():
yield counter[0]
for v in list(counter.values()):
if v > 1:
yield v*(v-1)//2
print((sum(cal()))) | 16 | 15 | 277 | 306 | n = int(eval(input()))
a = list(map(int, input().split()))
acc = [0 for i in range(n + 1)]
for i in range(n):
acc[i + 1] = a[i] + acc[i]
ans = {}
for x in acc:
ans.setdefault(x, 0)
ans[x] += 1
cnt = 0
for i in ans:
cnt += ans[i] * (ans[i] - 1) // 2
print(cnt)
| from itertools import accumulate
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
acc = accumulate(a)
counter = Counter(acc)
def cal():
yield counter[0]
for v in list(counter.values()):
if v > 1:
yield v * (v - 1) // 2
print((sum(cal())))
| false | 6.25 | [
"+from itertools import accumulate",
"+from collections import Counter",
"+",
"-acc = [0 for i in range(n + 1)]",
"-for i in range(n):",
"- acc[i + 1] = a[i] + acc[i]",
"-ans = {}",
"-for x in acc:",
"- ans.setdefault(x, 0)",
"- ans[x] += 1",
"-cnt = 0",
"-for i in ans:",
"- cnt += ans[i] * (ans[i] - 1) // 2",
"-print(cnt)",
"+acc = accumulate(a)",
"+counter = Counter(acc)",
"+",
"+",
"+def cal():",
"+ yield counter[0]",
"+ for v in list(counter.values()):",
"+ if v > 1:",
"+ yield v * (v - 1) // 2",
"+",
"+",
"+print((sum(cal())))"
]
| false | 0.052624 | 0.047794 | 1.101069 | [
"s409257667",
"s060865113"
]
|
u729008627 | p03078 | python | s845162162 | s376127734 | 832 | 37 | 4,592 | 4,976 | Accepted | Accepted | 95.55 | # solution 3
import heapq
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q = []
s = []
heapq.heappush(Q, (-A[0]-B[0]-C[0], 0, 0, 0))
for n in range(K):
q, i, j, k = heapq.heappop(Q)
print((-q))
if i < X-1 and [i+1, j, k] not in s:
heapq.heappush(Q, (- A[i+1] - B[j] - C[k], i+1, j, k))
s.append([i + 1, j, k])
if j < Y-1 and [i, j+1, k] not in s:
heapq.heappush(Q, (- A[i] - B[j+1] - C[k], i, j+1, k))
s.append([i, j + 1, k])
if k < Z-1 and [i, j, k+1] not in s:
heapq.heappush(Q, (- A[i] - B[j] - C[k+1], i, j, k+1))
s.append([i, j, k + 1]) | # solution 3
import heapq
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q = []
s = set()
heapq.heappush(Q, (-A[0]-B[0]-C[0], 0, 0, 0))
for n in range(K):
q, i, j, k = heapq.heappop(Q)
print((-q))
if i < X-1 and (i+1, j, k) not in s:
heapq.heappush(Q, (- A[i+1] - B[j] - C[k], i+1, j, k))
s.add((i + 1, j, k))
if j < Y-1 and (i, j+1, k) not in s:
heapq.heappush(Q, (- A[i] - B[j+1] - C[k], i, j+1, k))
s.add((i, j + 1, k))
if k < Z-1 and (i, j, k+1) not in s:
heapq.heappush(Q, (- A[i] - B[j] - C[k+1], i, j, k+1))
s.add((i, j, k + 1)) | 24 | 24 | 817 | 811 | # solution 3
import heapq
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q = []
s = []
heapq.heappush(Q, (-A[0] - B[0] - C[0], 0, 0, 0))
for n in range(K):
q, i, j, k = heapq.heappop(Q)
print((-q))
if i < X - 1 and [i + 1, j, k] not in s:
heapq.heappush(Q, (-A[i + 1] - B[j] - C[k], i + 1, j, k))
s.append([i + 1, j, k])
if j < Y - 1 and [i, j + 1, k] not in s:
heapq.heappush(Q, (-A[i] - B[j + 1] - C[k], i, j + 1, k))
s.append([i, j + 1, k])
if k < Z - 1 and [i, j, k + 1] not in s:
heapq.heappush(Q, (-A[i] - B[j] - C[k + 1], i, j, k + 1))
s.append([i, j, k + 1])
| # solution 3
import heapq
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q = []
s = set()
heapq.heappush(Q, (-A[0] - B[0] - C[0], 0, 0, 0))
for n in range(K):
q, i, j, k = heapq.heappop(Q)
print((-q))
if i < X - 1 and (i + 1, j, k) not in s:
heapq.heappush(Q, (-A[i + 1] - B[j] - C[k], i + 1, j, k))
s.add((i + 1, j, k))
if j < Y - 1 and (i, j + 1, k) not in s:
heapq.heappush(Q, (-A[i] - B[j + 1] - C[k], i, j + 1, k))
s.add((i, j + 1, k))
if k < Z - 1 and (i, j, k + 1) not in s:
heapq.heappush(Q, (-A[i] - B[j] - C[k + 1], i, j, k + 1))
s.add((i, j, k + 1))
| false | 0 | [
"-s = []",
"+s = set()",
"- if i < X - 1 and [i + 1, j, k] not in s:",
"+ if i < X - 1 and (i + 1, j, k) not in s:",
"- s.append([i + 1, j, k])",
"- if j < Y - 1 and [i, j + 1, k] not in s:",
"+ s.add((i + 1, j, k))",
"+ if j < Y - 1 and (i, j + 1, k) not in s:",
"- s.append([i, j + 1, k])",
"- if k < Z - 1 and [i, j, k + 1] not in s:",
"+ s.add((i, j + 1, k))",
"+ if k < Z - 1 and (i, j, k + 1) not in s:",
"- s.append([i, j, k + 1])",
"+ s.add((i, j, k + 1))"
]
| false | 0.053928 | 0.035324 | 1.52668 | [
"s845162162",
"s376127734"
]
|
u266014018 | p02703 | python | s106524691 | s201818707 | 827 | 734 | 38,572 | 39,028 | Accepted | Accepted | 11.25 | import sys
from heapq import heappush, heappop
import numpy as np
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())
def main():
def dijkstra(s):
def push(v, s, x):
if s < 0:
return
if dist[v, s] <= x:
return
dist[v, s] = x
heappush(que, (x, v, s))
inf = 10**18
dist = np.full((n, MAX_S+1), inf, dtype=int)
# time, remain, node
que = []
push(0, s, 0)
while que:
x, v, s = heappop(que)
if dist[v, s] < x:
continue
ns = min(s+c[v], MAX_S)
push(v, ns, x+d[v])
for nv, a, b in adj[v]:
push(nv, s-a, x+b)
return np.min(dist, axis=1)
n, m, s = mi()
adj = [[] for i in range(n)]
MAX_S = 0
for i in range(m):
u, v, a, b = mi()
u -= 1
v -= 1
adj[u].append((v, a, b))
adj[v].append((u, a, b))
MAX_S = max(MAX_S, a)
MAX_S *= n-1
s = min(s, MAX_S)
c, d = [0]*n, [0]*n
for i in range(n):
c[i], d[i] = mi()
ans = dijkstra(s)
print(*ans[1:], sep='\n')
if __name__ == '__main__':
main()
| import sys
from heapq import heappush, heappop
import numpy as np
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())
def main():
def dijkstra(xs, ss):
def push(v, s, x):
if s < 0:
return
if dist[v, s] <= x:
return
dist[v, s] = x
heappush(que, (x, v, s))
inf = 10**18
dist = np.full((n, MAX_S+1), inf, dtype=int)
# time, remain, node
que = []
push(xs, ss, 0)
while que:
x, v, s = heappop(que)
if dist[v, s] < x:
continue
ns = min(s+c[v], MAX_S)
push(v, ns, x+d[v])
for nv, a, b in adj[v]:
push(nv, s-a, x+b)
return np.min(dist, axis=1)
n, m, s = mi()
adj = [[] for i in range(n)]
MAX_S = 0
for i in range(m):
u, v, a, b = mi()
u -= 1
v -= 1
adj[u].append((v, a, b))
adj[v].append((u, a, b))
MAX_S = max(MAX_S, a)
MAX_S *= n-1
s = min(s, MAX_S)
c, d = [0]*n, [0]*n
for i in range(n):
c[i], d[i] = mi()
ans = dijkstra(0, s)
print(*ans[1:], sep='\n')
if __name__ == '__main__':
main()
| 57 | 57 | 1,383 | 1,393 | import sys
from heapq import heappush, heappop
import numpy as np
def input():
return sys.stdin.readline().rstrip()
def ii():
return int(input())
def mi():
return map(int, input().split())
def li():
return list(mi())
def main():
def dijkstra(s):
def push(v, s, x):
if s < 0:
return
if dist[v, s] <= x:
return
dist[v, s] = x
heappush(que, (x, v, s))
inf = 10**18
dist = np.full((n, MAX_S + 1), inf, dtype=int)
# time, remain, node
que = []
push(0, s, 0)
while que:
x, v, s = heappop(que)
if dist[v, s] < x:
continue
ns = min(s + c[v], MAX_S)
push(v, ns, x + d[v])
for nv, a, b in adj[v]:
push(nv, s - a, x + b)
return np.min(dist, axis=1)
n, m, s = mi()
adj = [[] for i in range(n)]
MAX_S = 0
for i in range(m):
u, v, a, b = mi()
u -= 1
v -= 1
adj[u].append((v, a, b))
adj[v].append((u, a, b))
MAX_S = max(MAX_S, a)
MAX_S *= n - 1
s = min(s, MAX_S)
c, d = [0] * n, [0] * n
for i in range(n):
c[i], d[i] = mi()
ans = dijkstra(s)
print(*ans[1:], sep="\n")
if __name__ == "__main__":
main()
| import sys
from heapq import heappush, heappop
import numpy as np
def input():
return sys.stdin.readline().rstrip()
def ii():
return int(input())
def mi():
return map(int, input().split())
def li():
return list(mi())
def main():
def dijkstra(xs, ss):
def push(v, s, x):
if s < 0:
return
if dist[v, s] <= x:
return
dist[v, s] = x
heappush(que, (x, v, s))
inf = 10**18
dist = np.full((n, MAX_S + 1), inf, dtype=int)
# time, remain, node
que = []
push(xs, ss, 0)
while que:
x, v, s = heappop(que)
if dist[v, s] < x:
continue
ns = min(s + c[v], MAX_S)
push(v, ns, x + d[v])
for nv, a, b in adj[v]:
push(nv, s - a, x + b)
return np.min(dist, axis=1)
n, m, s = mi()
adj = [[] for i in range(n)]
MAX_S = 0
for i in range(m):
u, v, a, b = mi()
u -= 1
v -= 1
adj[u].append((v, a, b))
adj[v].append((u, a, b))
MAX_S = max(MAX_S, a)
MAX_S *= n - 1
s = min(s, MAX_S)
c, d = [0] * n, [0] * n
for i in range(n):
c[i], d[i] = mi()
ans = dijkstra(0, s)
print(*ans[1:], sep="\n")
if __name__ == "__main__":
main()
| false | 0 | [
"- def dijkstra(s):",
"+ def dijkstra(xs, ss):",
"- push(0, s, 0)",
"+ push(xs, ss, 0)",
"- ans = dijkstra(s)",
"+ ans = dijkstra(0, s)"
]
| false | 0.196051 | 0.231107 | 0.848313 | [
"s106524691",
"s201818707"
]
|
u093492951 | p03424 | python | s439626366 | s153494171 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | num = int(eval(input()))
InA = [i for i in input().split()]
flgYel = 0
for cnt in range(num):
if InA[cnt] == "Y":
flgYel = 1
break
if flgYel > 0 :
print ("Four")
else :
print ("Three")
| #ๅ
ฅๅๅใๅใ
arare_kazu = int(eval(input()))
arare_color = [i for i in input().split()]
#print(arare_color)
#ๅคๅฎ
if 'Y' in arare_color:
print('Four')
else:
print('Three') | 16 | 10 | 227 | 176 | num = int(eval(input()))
InA = [i for i in input().split()]
flgYel = 0
for cnt in range(num):
if InA[cnt] == "Y":
flgYel = 1
break
if flgYel > 0:
print("Four")
else:
print("Three")
| # ๅ
ฅๅๅใๅใ
arare_kazu = int(eval(input()))
arare_color = [i for i in input().split()]
# print(arare_color)
# ๅคๅฎ
if "Y" in arare_color:
print("Four")
else:
print("Three")
| false | 37.5 | [
"-num = int(eval(input()))",
"-InA = [i for i in input().split()]",
"-flgYel = 0",
"-for cnt in range(num):",
"- if InA[cnt] == \"Y\":",
"- flgYel = 1",
"- break",
"-if flgYel > 0:",
"+# ๅ
ฅๅๅใๅใ",
"+arare_kazu = int(eval(input()))",
"+arare_color = [i for i in input().split()]",
"+# print(arare_color)",
"+# ๅคๅฎ",
"+if \"Y\" in arare_color:"
]
| false | 0.039149 | 0.037347 | 1.04825 | [
"s439626366",
"s153494171"
]
|
u476225888 | p03168 | python | s060302479 | s175000292 | 1,996 | 1,542 | 3,700 | 3,692 | Accepted | Accepted | 22.75 | from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
# from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline()
def mdata(): return list(map(float, data().split()))
out = sys.stdout.write
# sys.setrecursionlimit(100000)
INF = int(1e9)
mod = int(1e9) + 7
n = int(data())
P = list(mdata())
dp = [0.0] * (n // 2 + 2)
dp[1] = float(1)
for i in range(n):
p=P[i]
for j in range(len(dp) - 1, 0, -1):
dp[j] = dp[j - 1] * (1 - p) + dp[j] * (p)
print((sum(dp)))
| def main():
from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
# from math import *
from collections import defaultdict as dd, deque
def data(): return eval(input())
def mdata(): return list(map(float, data().split()))
out = sys.stdout.write
# sys.setrecursionlimit(100000)
INF = int(1e9)
mod = int(1e9) + 7
n = int(data())
P = list(mdata())
dp = [0.0] * (n // 2 + 2)
dp[1] = float(1)
for i in range(n):
p=P[i]
for j in range(len(dp) - 1, 0, -1):
dp[j] = dp[j - 1] * (1 - p) + dp[j] * (p)
print((sum(dp)))
if __name__ == '__main__':
main() | 21 | 25 | 568 | 689 | from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
# from math import *
from collections import defaultdict as dd, deque
def data():
return sys.stdin.readline()
def mdata():
return list(map(float, data().split()))
out = sys.stdout.write
# sys.setrecursionlimit(100000)
INF = int(1e9)
mod = int(1e9) + 7
n = int(data())
P = list(mdata())
dp = [0.0] * (n // 2 + 2)
dp[1] = float(1)
for i in range(n):
p = P[i]
for j in range(len(dp) - 1, 0, -1):
dp[j] = dp[j - 1] * (1 - p) + dp[j] * (p)
print((sum(dp)))
| def main():
from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
# from math import *
from collections import defaultdict as dd, deque
def data():
return eval(input())
def mdata():
return list(map(float, data().split()))
out = sys.stdout.write
# sys.setrecursionlimit(100000)
INF = int(1e9)
mod = int(1e9) + 7
n = int(data())
P = list(mdata())
dp = [0.0] * (n // 2 + 2)
dp[1] = float(1)
for i in range(n):
p = P[i]
for j in range(len(dp) - 1, 0, -1):
dp[j] = dp[j - 1] * (1 - p) + dp[j] * (p)
print((sum(dp)))
if __name__ == "__main__":
main()
| false | 16 | [
"-from bisect import bisect_left as bl, bisect_right as br, insort",
"-import sys",
"-import heapq",
"+def main():",
"+ from bisect import bisect_left as bl, bisect_right as br, insort",
"+ import sys",
"+ import heapq",
"-# from math import *",
"-from collections import defaultdict as dd, deque",
"+ # from math import *",
"+ from collections import defaultdict as dd, deque",
"+",
"+ def data():",
"+ return eval(input())",
"+",
"+ def mdata():",
"+ return list(map(float, data().split()))",
"+",
"+ out = sys.stdout.write",
"+ # sys.setrecursionlimit(100000)",
"+ INF = int(1e9)",
"+ mod = int(1e9) + 7",
"+ n = int(data())",
"+ P = list(mdata())",
"+ dp = [0.0] * (n // 2 + 2)",
"+ dp[1] = float(1)",
"+ for i in range(n):",
"+ p = P[i]",
"+ for j in range(len(dp) - 1, 0, -1):",
"+ dp[j] = dp[j - 1] * (1 - p) + dp[j] * (p)",
"+ print((sum(dp)))",
"-def data():",
"- return sys.stdin.readline()",
"-",
"-",
"-def mdata():",
"- return list(map(float, data().split()))",
"-",
"-",
"-out = sys.stdout.write",
"-# sys.setrecursionlimit(100000)",
"-INF = int(1e9)",
"-mod = int(1e9) + 7",
"-n = int(data())",
"-P = list(mdata())",
"-dp = [0.0] * (n // 2 + 2)",
"-dp[1] = float(1)",
"-for i in range(n):",
"- p = P[i]",
"- for j in range(len(dp) - 1, 0, -1):",
"- dp[j] = dp[j - 1] * (1 - p) + dp[j] * (p)",
"-print((sum(dp)))",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.041064 | 0.049246 | 0.83385 | [
"s060302479",
"s175000292"
]
|
u098012509 | p03546 | python | s111887343 | s497361987 | 276 | 210 | 17,768 | 37,808 | Accepted | Accepted | 23.91 | import sys
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, csgraph_from_dense
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, csgraph_from_dense
# [[10 ** 9, 1, 2],
# [3, 10 ** 9, 2]
# [10 ** 9, 4, 7]]
input = sys.stdin.readline
def main():
H, W = [int(x) for x in input().split()]
edge = [[int(x) for x in input().split()] for _ in range(10)]
A = [[int(x) for x in input().split()] for _ in range(H)]
G = csgraph_from_dense(edge, null_value=0)
d = floyd_warshall(G)
ans = 0
for a in A:
for v in a:
if v == -1:
continue
ans += d[v][1]
print((int(ans)))
if __name__ == '__main__':
main()
| from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, csgraph_from_dense
H, W = [int(x) for x in input().split()]
C = [[int(x) for x in input().split()] for _ in range(10)]
A = [[int(x) for x in input().split()] for _ in range(H)]
G = csgraph_from_dense(C, null_value=0)
d = floyd_warshall(G)
ans = 0
for i in range(H):
for j in range(W):
if A[i][j] == 1 or A[i][j] == -1:
continue
ans += d[A[i][j]][1]
print((int(ans)))
| 33 | 23 | 812 | 526 | import sys
from scipy.sparse.csgraph import (
shortest_path,
floyd_warshall,
dijkstra,
bellman_ford,
johnson,
csgraph_from_dense,
)
from scipy.sparse.csgraph import (
shortest_path,
floyd_warshall,
dijkstra,
bellman_ford,
johnson,
csgraph_from_dense,
)
# [[10 ** 9, 1, 2],
# [3, 10 ** 9, 2]
# [10 ** 9, 4, 7]]
input = sys.stdin.readline
def main():
H, W = [int(x) for x in input().split()]
edge = [[int(x) for x in input().split()] for _ in range(10)]
A = [[int(x) for x in input().split()] for _ in range(H)]
G = csgraph_from_dense(edge, null_value=0)
d = floyd_warshall(G)
ans = 0
for a in A:
for v in a:
if v == -1:
continue
ans += d[v][1]
print((int(ans)))
if __name__ == "__main__":
main()
| from scipy.sparse.csgraph import (
shortest_path,
floyd_warshall,
dijkstra,
bellman_ford,
johnson,
csgraph_from_dense,
)
H, W = [int(x) for x in input().split()]
C = [[int(x) for x in input().split()] for _ in range(10)]
A = [[int(x) for x in input().split()] for _ in range(H)]
G = csgraph_from_dense(C, null_value=0)
d = floyd_warshall(G)
ans = 0
for i in range(H):
for j in range(W):
if A[i][j] == 1 or A[i][j] == -1:
continue
ans += d[A[i][j]][1]
print((int(ans)))
| false | 30.30303 | [
"-import sys",
"-from scipy.sparse.csgraph import (",
"- shortest_path,",
"- floyd_warshall,",
"- dijkstra,",
"- bellman_ford,",
"- johnson,",
"- csgraph_from_dense,",
"-)",
"-# [[10 ** 9, 1, 2],",
"-# [3, 10 ** 9, 2]",
"-# [10 ** 9, 4, 7]]",
"-input = sys.stdin.readline",
"-",
"-",
"-def main():",
"- H, W = [int(x) for x in input().split()]",
"- edge = [[int(x) for x in input().split()] for _ in range(10)]",
"- A = [[int(x) for x in input().split()] for _ in range(H)]",
"- G = csgraph_from_dense(edge, null_value=0)",
"- d = floyd_warshall(G)",
"- ans = 0",
"- for a in A:",
"- for v in a:",
"- if v == -1:",
"- continue",
"- ans += d[v][1]",
"- print((int(ans)))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+H, W = [int(x) for x in input().split()]",
"+C = [[int(x) for x in input().split()] for _ in range(10)]",
"+A = [[int(x) for x in input().split()] for _ in range(H)]",
"+G = csgraph_from_dense(C, null_value=0)",
"+d = floyd_warshall(G)",
"+ans = 0",
"+for i in range(H):",
"+ for j in range(W):",
"+ if A[i][j] == 1 or A[i][j] == -1:",
"+ continue",
"+ ans += d[A[i][j]][1]",
"+print((int(ans)))"
]
| false | 0.33223 | 0.319199 | 1.040823 | [
"s111887343",
"s497361987"
]
|
u712822150 | p03848 | python | s310916549 | s841437055 | 249 | 221 | 56,556 | 56,556 | Accepted | Accepted | 11.24 | from sys import stdin
def resolve():
n = int(stdin.readline().rstrip())
# s = stdin.readline().rstrip()
# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
a = sorted(a)
predict = [n - (((n - i + 1) // 2) * 2) + 1 for i in range(0, n)]
if a != predict:
return 0
ret = 1
for i in range(0, n // 2):
ret = (ret * 2) % 1000000007
return ret
print((resolve(), '\n'))
# print(*data, sep='\n')
| import sys
from sys import stdin
mod = 1000000007
n = int(stdin.readline().rstrip())
# s = stdin.readline().rstrip()
# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
a = sorted(a)
predict = [n - (((n - i + 1) // 2) * 2) + 1 for i in range(0, n)]
if a != predict:
print((0))
sys.exit()
print((pow(2, (n // 2), mod)))
# print(*data, sep='\n')
| 22 | 17 | 536 | 435 | from sys import stdin
def resolve():
n = int(stdin.readline().rstrip())
# s = stdin.readline().rstrip()
# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
a = sorted(a)
predict = [n - (((n - i + 1) // 2) * 2) + 1 for i in range(0, n)]
if a != predict:
return 0
ret = 1
for i in range(0, n // 2):
ret = (ret * 2) % 1000000007
return ret
print((resolve(), "\n"))
# print(*data, sep='\n')
| import sys
from sys import stdin
mod = 1000000007
n = int(stdin.readline().rstrip())
# s = stdin.readline().rstrip()
# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
a = sorted(a)
predict = [n - (((n - i + 1) // 2) * 2) + 1 for i in range(0, n)]
if a != predict:
print((0))
sys.exit()
print((pow(2, (n // 2), mod)))
# print(*data, sep='\n')
| false | 22.727273 | [
"+import sys",
"-",
"-def resolve():",
"- n = int(stdin.readline().rstrip())",
"- # s = stdin.readline().rstrip()",
"- # A, B, C = [int(x) for x in stdin.readline().rstrip().split()]",
"- a = [int(x) for x in stdin.readline().rstrip().split()]",
"- a = sorted(a)",
"- predict = [n - (((n - i + 1) // 2) * 2) + 1 for i in range(0, n)]",
"- if a != predict:",
"- return 0",
"- ret = 1",
"- for i in range(0, n // 2):",
"- ret = (ret * 2) % 1000000007",
"- return ret",
"-",
"-",
"-print((resolve(), \"\\n\"))",
"+mod = 1000000007",
"+n = int(stdin.readline().rstrip())",
"+# s = stdin.readline().rstrip()",
"+# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]",
"+a = [int(x) for x in stdin.readline().rstrip().split()]",
"+a = sorted(a)",
"+predict = [n - (((n - i + 1) // 2) * 2) + 1 for i in range(0, n)]",
"+if a != predict:",
"+ print((0))",
"+ sys.exit()",
"+print((pow(2, (n // 2), mod)))"
]
| false | 0.125001 | 0.038465 | 3.249735 | [
"s310916549",
"s841437055"
]
|
u493520238 | p03525 | python | s143605233 | s747654195 | 122 | 65 | 83,368 | 62,048 | Accepted | Accepted | 46.72 | from itertools import product
import random
def solve(n,dl):
# n = int(input())
# dl = list(map(int, input().split()))
if 0 in dl:
return 0
doubles = []
dl1 = []
dl2 = []
for i in range(1,13):
i_cnt = dl.count(i)
if i_cnt > 2:
return 0
elif i_cnt == 2:
dl2.append(24-i)
dl2.append(i)
elif i_cnt == 1:
dl1.append(i)
ans = 0
ite = list(product(list(range(2)),repeat=len(dl1)))
for pattern in ite:
dl24 = [0,24]
for i, v in enumerate(pattern):
if v == 1:
dl24.append(24-dl1[i])
else:
dl24.append(dl1[i])
dl24 = dl24 + dl2
dl24.sort()
diff_min = 24
# print(dl24)
if len(dl24) == 1:
ans = max(ans, min(dl24[0], 24-dl24[0]))
else:
for a,b in zip(dl24[:-1],dl24[1:]):
diff = b-a
if diff != 24:
diff_min = min(diff_min,diff)
ans = max(diff_min,ans)
return ans
def solve2(n,dl):
ite = list(product(list(range(2)),repeat=len(dl)))
ans = 0
for pattern in ite:
dl_new = [0]
for i, v in enumerate(pattern):
if v == 1:
dl_new.append(24-dl[i])
else:
dl_new.append(dl[i])
dl_new.sort()
diff_min = 24
for a,b in zip(dl_new[:-1], dl_new[1:]):
diff = b-a
diff_min = min(diff_min, diff)
ans = max(ans,diff_min)
return ans
if __name__ == "__main__":
n = int(eval(input()))
dl = list(map(int, input().split()))
ans = solve(n,dl)
print(ans)
# for _ in range(10):
# n = random.randint(1,10)
# dl = [random.randint(1,12) for _ in range(n)]
# ans1 = solve(n, dl[:])
# ans2 = solve2(n,dl[:])
# if ans1 != ans2:
# print(n)
# print(dl)
# print(ans1)
# print(ans2)
# print('----') | n = int(eval(input()))
dl = list(map(int, input().split()))
if 0 in dl:
print((0))
exit()
dl.sort()
dl1 = [0,24]
dl2 = [0,24]
for i, d in enumerate(dl):
if i%2 == 0:
dl1.append(d)
dl2.append(24-d)
else:
dl1.append(24-d)
dl2.append(d)
dl1.sort()
dl2.sort()
min_1 = 24
for a,b in zip(dl1[1:],dl1[:-1]):
diff = a-b
min_1 = min(min_1,diff)
min_2 = 24
for a,b in zip(dl2[1:],dl2[:-1]):
diff = a-b
min_2 = min(min_2,diff)
ans = max(min_1,min_2)
print(ans)
| 82 | 33 | 2,133 | 544 | from itertools import product
import random
def solve(n, dl):
# n = int(input())
# dl = list(map(int, input().split()))
if 0 in dl:
return 0
doubles = []
dl1 = []
dl2 = []
for i in range(1, 13):
i_cnt = dl.count(i)
if i_cnt > 2:
return 0
elif i_cnt == 2:
dl2.append(24 - i)
dl2.append(i)
elif i_cnt == 1:
dl1.append(i)
ans = 0
ite = list(product(list(range(2)), repeat=len(dl1)))
for pattern in ite:
dl24 = [0, 24]
for i, v in enumerate(pattern):
if v == 1:
dl24.append(24 - dl1[i])
else:
dl24.append(dl1[i])
dl24 = dl24 + dl2
dl24.sort()
diff_min = 24
# print(dl24)
if len(dl24) == 1:
ans = max(ans, min(dl24[0], 24 - dl24[0]))
else:
for a, b in zip(dl24[:-1], dl24[1:]):
diff = b - a
if diff != 24:
diff_min = min(diff_min, diff)
ans = max(diff_min, ans)
return ans
def solve2(n, dl):
ite = list(product(list(range(2)), repeat=len(dl)))
ans = 0
for pattern in ite:
dl_new = [0]
for i, v in enumerate(pattern):
if v == 1:
dl_new.append(24 - dl[i])
else:
dl_new.append(dl[i])
dl_new.sort()
diff_min = 24
for a, b in zip(dl_new[:-1], dl_new[1:]):
diff = b - a
diff_min = min(diff_min, diff)
ans = max(ans, diff_min)
return ans
if __name__ == "__main__":
n = int(eval(input()))
dl = list(map(int, input().split()))
ans = solve(n, dl)
print(ans)
# for _ in range(10):
# n = random.randint(1,10)
# dl = [random.randint(1,12) for _ in range(n)]
# ans1 = solve(n, dl[:])
# ans2 = solve2(n,dl[:])
# if ans1 != ans2:
# print(n)
# print(dl)
# print(ans1)
# print(ans2)
# print('----')
| n = int(eval(input()))
dl = list(map(int, input().split()))
if 0 in dl:
print((0))
exit()
dl.sort()
dl1 = [0, 24]
dl2 = [0, 24]
for i, d in enumerate(dl):
if i % 2 == 0:
dl1.append(d)
dl2.append(24 - d)
else:
dl1.append(24 - d)
dl2.append(d)
dl1.sort()
dl2.sort()
min_1 = 24
for a, b in zip(dl1[1:], dl1[:-1]):
diff = a - b
min_1 = min(min_1, diff)
min_2 = 24
for a, b in zip(dl2[1:], dl2[:-1]):
diff = a - b
min_2 = min(min_2, diff)
ans = max(min_1, min_2)
print(ans)
| false | 59.756098 | [
"-from itertools import product",
"-import random",
"-",
"-",
"-def solve(n, dl):",
"- # n = int(input())",
"- # dl = list(map(int, input().split()))",
"- if 0 in dl:",
"- return 0",
"- doubles = []",
"- dl1 = []",
"- dl2 = []",
"- for i in range(1, 13):",
"- i_cnt = dl.count(i)",
"- if i_cnt > 2:",
"- return 0",
"- elif i_cnt == 2:",
"- dl2.append(24 - i)",
"- dl2.append(i)",
"- elif i_cnt == 1:",
"- dl1.append(i)",
"- ans = 0",
"- ite = list(product(list(range(2)), repeat=len(dl1)))",
"- for pattern in ite:",
"- dl24 = [0, 24]",
"- for i, v in enumerate(pattern):",
"- if v == 1:",
"- dl24.append(24 - dl1[i])",
"- else:",
"- dl24.append(dl1[i])",
"- dl24 = dl24 + dl2",
"- dl24.sort()",
"- diff_min = 24",
"- # print(dl24)",
"- if len(dl24) == 1:",
"- ans = max(ans, min(dl24[0], 24 - dl24[0]))",
"- else:",
"- for a, b in zip(dl24[:-1], dl24[1:]):",
"- diff = b - a",
"- if diff != 24:",
"- diff_min = min(diff_min, diff)",
"- ans = max(diff_min, ans)",
"- return ans",
"-",
"-",
"-def solve2(n, dl):",
"- ite = list(product(list(range(2)), repeat=len(dl)))",
"- ans = 0",
"- for pattern in ite:",
"- dl_new = [0]",
"- for i, v in enumerate(pattern):",
"- if v == 1:",
"- dl_new.append(24 - dl[i])",
"- else:",
"- dl_new.append(dl[i])",
"- dl_new.sort()",
"- diff_min = 24",
"- for a, b in zip(dl_new[:-1], dl_new[1:]):",
"- diff = b - a",
"- diff_min = min(diff_min, diff)",
"- ans = max(ans, diff_min)",
"- return ans",
"-",
"-",
"-if __name__ == \"__main__\":",
"- n = int(eval(input()))",
"- dl = list(map(int, input().split()))",
"- ans = solve(n, dl)",
"- print(ans)",
"- # for _ in range(10):",
"- # n = random.randint(1,10)",
"- # dl = [random.randint(1,12) for _ in range(n)]",
"- # ans1 = solve(n, dl[:])",
"- # ans2 = solve2(n,dl[:])",
"- # if ans1 != ans2:",
"- # print(n)",
"- # print(dl)",
"- # print(ans1)",
"- # print(ans2)",
"+n = int(eval(input()))",
"+dl = list(map(int, input().split()))",
"+if 0 in dl:",
"+ print((0))",
"+ exit()",
"+dl.sort()",
"+dl1 = [0, 24]",
"+dl2 = [0, 24]",
"+for i, d in enumerate(dl):",
"+ if i % 2 == 0:",
"+ dl1.append(d)",
"+ dl2.append(24 - d)",
"+ else:",
"+ dl1.append(24 - d)",
"+ dl2.append(d)",
"+dl1.sort()",
"+dl2.sort()",
"+min_1 = 24",
"+for a, b in zip(dl1[1:], dl1[:-1]):",
"+ diff = a - b",
"+ min_1 = min(min_1, diff)",
"+min_2 = 24",
"+for a, b in zip(dl2[1:], dl2[:-1]):",
"+ diff = a - b",
"+ min_2 = min(min_2, diff)",
"+ans = max(min_1, min_2)",
"+print(ans)"
]
| false | 0.038502 | 0.038548 | 0.998806 | [
"s143605233",
"s747654195"
]
|
u417096287 | p02899 | python | s160193488 | s230114832 | 364 | 220 | 74,540 | 100,860 | Accepted | Accepted | 39.56 | from collections import deque
N = int(eval(input()))
A = list(map(int, input().split()))
A = list(enumerate(A))
A.sort(key = lambda x: x[1])
ans = deque()
for a in A:
ans.append(a[0] + 1)
print((" ".join(map(str, ans)))) | def INT():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
N = INT()
A = LI()
for i in range(N):
A[i] = [i + 1, A[i]]
A.sort(key = lambda x : x[1])
ans = []
for i in range(N):
ans.append(A[i][0])
print((*ans)) | 13 | 23 | 232 | 329 | from collections import deque
N = int(eval(input()))
A = list(map(int, input().split()))
A = list(enumerate(A))
A.sort(key=lambda x: x[1])
ans = deque()
for a in A:
ans.append(a[0] + 1)
print((" ".join(map(str, ans))))
| def INT():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
N = INT()
A = LI()
for i in range(N):
A[i] = [i + 1, A[i]]
A.sort(key=lambda x: x[1])
ans = []
for i in range(N):
ans.append(A[i][0])
print((*ans))
| false | 43.478261 | [
"-from collections import deque",
"+def INT():",
"+ return int(eval(input()))",
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-A = list(enumerate(A))",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+N = INT()",
"+A = LI()",
"+for i in range(N):",
"+ A[i] = [i + 1, A[i]]",
"-ans = deque()",
"-for a in A:",
"- ans.append(a[0] + 1)",
"-print((\" \".join(map(str, ans))))",
"+ans = []",
"+for i in range(N):",
"+ ans.append(A[i][0])",
"+print((*ans))"
]
| false | 0.041987 | 0.045763 | 0.917482 | [
"s160193488",
"s230114832"
]
|
u581187895 | p02572 | python | s258573847 | s407166238 | 133 | 92 | 31,528 | 31,412 | Accepted | Accepted | 30.83 |
from itertools import accumulate
def resolve():
MOD = 10**9+7
N = int(eval(input()))
A = list(map(int, input().split()))
Acc = [0] + list(accumulate(A))
ans = 0
for i in range(N):
ans += A[i] * (Acc[N] - Acc[i+1])
ans %= MOD
print(ans)
if __name__ == "__main__":
resolve()
|
def resolve():
MOD = 10 ** 9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
# ้ข็ฉใจใใฆ่ฆใ: ็ธฆ*ๆจช
square = sum(A) ** 2
# ๅฏพ่ง็ท
diag = sum([a * a for a in A])
ans = (square - diag) // 2
print((ans % MOD))
if __name__ == "__main__":
resolve() | 19 | 18 | 339 | 302 | from itertools import accumulate
def resolve():
MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
Acc = [0] + list(accumulate(A))
ans = 0
for i in range(N):
ans += A[i] * (Acc[N] - Acc[i + 1])
ans %= MOD
print(ans)
if __name__ == "__main__":
resolve()
| def resolve():
MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
# ้ข็ฉใจใใฆ่ฆใ: ็ธฆ*ๆจช
square = sum(A) ** 2
# ๅฏพ่ง็ท
diag = sum([a * a for a in A])
ans = (square - diag) // 2
print((ans % MOD))
if __name__ == "__main__":
resolve()
| false | 5.263158 | [
"-from itertools import accumulate",
"-",
"-",
"- Acc = [0] + list(accumulate(A))",
"- ans = 0",
"- for i in range(N):",
"- ans += A[i] * (Acc[N] - Acc[i + 1])",
"- ans %= MOD",
"- print(ans)",
"+ # ้ข็ฉใจใใฆ่ฆใ: ็ธฆ*ๆจช",
"+ square = sum(A) ** 2",
"+ # ๅฏพ่ง็ท",
"+ diag = sum([a * a for a in A])",
"+ ans = (square - diag) // 2",
"+ print((ans % MOD))"
]
| false | 0.037267 | 0.040727 | 0.91503 | [
"s258573847",
"s407166238"
]
|
u400336986 | p02370 | python | s585745698 | s545120332 | 230 | 210 | 11,420 | 11,360 | Accepted | Accepted | 8.7 | nv, ne = map(int, input().split(' '))
in_degs = [0] * nv
q = []
outs = {}
o = []
for _ in range(ne):
s, t = map(int, input().split(' '))
if s in outs: outs[s].append(t)
else: outs[s] = [t]
in_degs[t] += 1
for i in range(nv):
if in_degs[i] == 0: q.append(i)
while len(q) > 0:
v = q.pop(0)
o.append(v)
if v in outs:
for out in outs[v]:
in_degs[out] -= 1
if in_degs[out] == 0: q.append(out)
[print(v) for v in o]
| nv, ne = map(int, input().split(' '))
in_degs = [0] * nv
q = []
outs = {}
o = []
for _ in range(ne):
s, t = map(int, input().split(' '))
if s in outs: outs[s].append(t)
else: outs[s] = [t]
in_degs[t] += 1
for i in range(nv):
if in_degs[i] == 0: q.append(i)
while q:
v = q.pop(0)
o.append(v)
if v in outs:
for out in outs[v]:
in_degs[out] -= 1
if in_degs[out] == 0: q.append(out)
[print(v) for v in o]
| 27 | 27 | 506 | 497 | nv, ne = map(int, input().split(" "))
in_degs = [0] * nv
q = []
outs = {}
o = []
for _ in range(ne):
s, t = map(int, input().split(" "))
if s in outs:
outs[s].append(t)
else:
outs[s] = [t]
in_degs[t] += 1
for i in range(nv):
if in_degs[i] == 0:
q.append(i)
while len(q) > 0:
v = q.pop(0)
o.append(v)
if v in outs:
for out in outs[v]:
in_degs[out] -= 1
if in_degs[out] == 0:
q.append(out)
[print(v) for v in o]
| nv, ne = map(int, input().split(" "))
in_degs = [0] * nv
q = []
outs = {}
o = []
for _ in range(ne):
s, t = map(int, input().split(" "))
if s in outs:
outs[s].append(t)
else:
outs[s] = [t]
in_degs[t] += 1
for i in range(nv):
if in_degs[i] == 0:
q.append(i)
while q:
v = q.pop(0)
o.append(v)
if v in outs:
for out in outs[v]:
in_degs[out] -= 1
if in_degs[out] == 0:
q.append(out)
[print(v) for v in o]
| false | 0 | [
"-while len(q) > 0:",
"+while q:"
]
| false | 0.037152 | 0.037052 | 1.00272 | [
"s585745698",
"s545120332"
]
|
u389910364 | p03266 | python | s971410783 | s979256910 | 344 | 17 | 21,364 | 3,060 | Accepted | Accepted | 95.06 | import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
N, K = list(map(int, sys.stdin.readline().split()))
if K % 2 == 1:
# K ใฎๅๆฐใฎใใฟใผใณใฎใฟ
m = N // K
print((m ** 3))
else:
m = N // K
a1 = m ** 3
m = (N + K // 2) // K
a2 = m ** 3
print((a1 + a2))
| import math
import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
N, K = list(map(int, sys.stdin.buffer.readline().split()))
# ๅ
จ้จ K ใฎๅๆฐ
ans = (N // K) ** 3
# ๅถๆฐใชใKใฎๅๅใงใOK
if K % 2 == 0:
ans += math.ceil((N // (K // 2)) / 2) ** 3
print((int(ans)))
| 36 | 21 | 727 | 402 | import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
N, K = list(map(int, sys.stdin.readline().split()))
if K % 2 == 1:
# K ใฎๅๆฐใฎใใฟใผใณใฎใฟ
m = N // K
print((m**3))
else:
m = N // K
a1 = m**3
m = (N + K // 2) // K
a2 = m**3
print((a1 + a2))
| import math
import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
N, K = list(map(int, sys.stdin.buffer.readline().split()))
# ๅ
จ้จ K ใฎๅๆฐ
ans = (N // K) ** 3
# ๅถๆฐใชใKใฎๅๅใงใOK
if K % 2 == 0:
ans += math.ceil((N // (K // 2)) / 2) ** 3
print((int(ans)))
| false | 41.666667 | [
"-import bisect",
"-import heapq",
"-import itertools",
"-import re",
"-import string",
"-from collections import Counter, deque, defaultdict",
"-from copy import deepcopy",
"-from decimal import Decimal",
"-from fractions import gcd",
"-from functools import lru_cache, reduce",
"-from operator import itemgetter",
"-import numpy as np",
"-sys.setrecursionlimit(2147483647)",
"+sys.setrecursionlimit(10**9)",
"-N, K = list(map(int, sys.stdin.readline().split()))",
"-if K % 2 == 1:",
"- # K ใฎๅๆฐใฎใใฟใผใณใฎใฟ",
"- m = N // K",
"- print((m**3))",
"-else:",
"- m = N // K",
"- a1 = m**3",
"- m = (N + K // 2) // K",
"- a2 = m**3",
"- print((a1 + a2))",
"+# MOD = 998244353",
"+N, K = list(map(int, sys.stdin.buffer.readline().split()))",
"+# ๅ
จ้จ K ใฎๅๆฐ",
"+ans = (N // K) ** 3",
"+# ๅถๆฐใชใKใฎๅๅใงใOK",
"+if K % 2 == 0:",
"+ ans += math.ceil((N // (K // 2)) / 2) ** 3",
"+print((int(ans)))"
]
| false | 0.040562 | 0.038844 | 1.044214 | [
"s971410783",
"s979256910"
]
|
u131464432 | p02975 | python | s861963655 | s043545989 | 75 | 61 | 20,660 | 20,972 | Accepted | Accepted | 18.67 | N = int(eval(input()))
a = list(map(int,input().split()))
if len(set(a)) == 1 and a[0] == 0:
print("Yes")
exit()
if N%3 != 0:
print("No")
exit()
import collections
sa = list(set(a))
sa.sort()
B = collections.Counter(a)
if len(sa) == 2 and 0 in sa:
if B[0] == N//3 and B[sa[1]] == N*2//3:
print("Yes")
else: print("No")
exit()
if len(sa) != 3:
print("No")
exit()
if B[sa[0]] == B[sa[1]] == B[sa[2]]:
print(("Yes" if sa[0] ^ sa[1] == sa[2] else "No"))
else:
print("No") | import collections
N = int(eval(input()))
a = list(map(int,input().split()))
B = collections.Counter(a)
k = list(B.keys())
v = list(B.values())
if len(B) == 3 and k[0]^k[1]^k[2] == 0 and v[0] == v[1] == v[2]:
print("Yes")
elif len(B) == 2 and 0 in k and (v[0] == 2*v[1] or v[1] == 2*v[0]):
print("Yes")
elif len(B) == 1 and 0 in k:
print("Yes")
else: print("No") | 27 | 14 | 540 | 382 | N = int(eval(input()))
a = list(map(int, input().split()))
if len(set(a)) == 1 and a[0] == 0:
print("Yes")
exit()
if N % 3 != 0:
print("No")
exit()
import collections
sa = list(set(a))
sa.sort()
B = collections.Counter(a)
if len(sa) == 2 and 0 in sa:
if B[0] == N // 3 and B[sa[1]] == N * 2 // 3:
print("Yes")
else:
print("No")
exit()
if len(sa) != 3:
print("No")
exit()
if B[sa[0]] == B[sa[1]] == B[sa[2]]:
print(("Yes" if sa[0] ^ sa[1] == sa[2] else "No"))
else:
print("No")
| import collections
N = int(eval(input()))
a = list(map(int, input().split()))
B = collections.Counter(a)
k = list(B.keys())
v = list(B.values())
if len(B) == 3 and k[0] ^ k[1] ^ k[2] == 0 and v[0] == v[1] == v[2]:
print("Yes")
elif len(B) == 2 and 0 in k and (v[0] == 2 * v[1] or v[1] == 2 * v[0]):
print("Yes")
elif len(B) == 1 and 0 in k:
print("Yes")
else:
print("No")
| false | 48.148148 | [
"+import collections",
"+",
"-if len(set(a)) == 1 and a[0] == 0:",
"+B = collections.Counter(a)",
"+k = list(B.keys())",
"+v = list(B.values())",
"+if len(B) == 3 and k[0] ^ k[1] ^ k[2] == 0 and v[0] == v[1] == v[2]:",
"- exit()",
"-if N % 3 != 0:",
"- print(\"No\")",
"- exit()",
"-import collections",
"-",
"-sa = list(set(a))",
"-sa.sort()",
"-B = collections.Counter(a)",
"-if len(sa) == 2 and 0 in sa:",
"- if B[0] == N // 3 and B[sa[1]] == N * 2 // 3:",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"- exit()",
"-if len(sa) != 3:",
"- print(\"No\")",
"- exit()",
"-if B[sa[0]] == B[sa[1]] == B[sa[2]]:",
"- print((\"Yes\" if sa[0] ^ sa[1] == sa[2] else \"No\"))",
"+elif len(B) == 2 and 0 in k and (v[0] == 2 * v[1] or v[1] == 2 * v[0]):",
"+ print(\"Yes\")",
"+elif len(B) == 1 and 0 in k:",
"+ print(\"Yes\")"
]
| false | 0.044588 | 0.038854 | 1.147593 | [
"s861963655",
"s043545989"
]
|
u562935282 | p02996 | python | s561851001 | s666767031 | 897 | 748 | 29,456 | 31,884 | Accepted | Accepted | 16.61 | n = int(eval(input()))
e = []
for _ in range(n):
a, b = list(map(int, input().split()))
e.append((b, a))
e.sort()
cur = 0
can = True
for b, a in e:
cur += a
if cur > b:
can = False
break
print(('Yes' if can else 'No'))
| n = int(eval(input()))
tlm = [tuple(map(int, input().split())) for _ in range(n)]
# time/limit
tlm.sort(key=lambda x: x[1])
flg = True
cur = 0
for t, lm in tlm:
cur += t
if cur > lm:
flg = False
break
print(('Yes' if flg else 'No'))
| 16 | 15 | 254 | 266 | n = int(eval(input()))
e = []
for _ in range(n):
a, b = list(map(int, input().split()))
e.append((b, a))
e.sort()
cur = 0
can = True
for b, a in e:
cur += a
if cur > b:
can = False
break
print(("Yes" if can else "No"))
| n = int(eval(input()))
tlm = [tuple(map(int, input().split())) for _ in range(n)]
# time/limit
tlm.sort(key=lambda x: x[1])
flg = True
cur = 0
for t, lm in tlm:
cur += t
if cur > lm:
flg = False
break
print(("Yes" if flg else "No"))
| false | 6.25 | [
"-e = []",
"-for _ in range(n):",
"- a, b = list(map(int, input().split()))",
"- e.append((b, a))",
"-e.sort()",
"+tlm = [tuple(map(int, input().split())) for _ in range(n)]",
"+# time/limit",
"+tlm.sort(key=lambda x: x[1])",
"+flg = True",
"-can = True",
"-for b, a in e:",
"- cur += a",
"- if cur > b:",
"- can = False",
"+for t, lm in tlm:",
"+ cur += t",
"+ if cur > lm:",
"+ flg = False",
"-print((\"Yes\" if can else \"No\"))",
"+print((\"Yes\" if flg else \"No\"))"
]
| false | 0.038466 | 0.049158 | 0.782488 | [
"s561851001",
"s666767031"
]
|
u175034939 | p02537 | python | s180918547 | s838904732 | 635 | 452 | 106,640 | 92,168 | Accepted | Accepted | 28.82 | import sys
sys.setrecursionlimit(10**8)
class SegTree:
def __init__(self, N, ele):
self.num = 2**(N-1).bit_length()
self.el = ele
self.data = [ele]*(2*self.num)
def calc(self, x, y):
return max(x, y)
def update(self, idx, x):
idx += (self.num - 1)
self.data[idx] = x
while idx > 0:
idx = (idx-1)//2
self.data[idx] = self.calc(self.data[2*idx+1], self.data[2*idx+2])
def query(self, l, r):
L = l + self.num
R = r + self.num
res = self.el
while L < R:
if L & 1:
res = self.calc(res, self.data[L-1])
L += 1
if R & 1:
R -= 1
res = self.calc(res, self.data[R-1])
L >>= 1
R >>= 1
return res
def get(self, idx):
idx += (self.num - 1)
return self.data[idx]
n, k = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(n)]
seg = SegTree(330000, 0)
max_a = 300010
for a in A:
l = max(0, a-k)
r = min(max_a, a+k+1)
now = seg.query(l, r)
seg.update(a, now+1)
print((seg.query(0, max_a)))
| import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
class SegTree:
def __init__(self, N, ele):
self.num = 2**(N-1).bit_length()
self.el = ele
self.data = [ele]*(2*self.num)
def calc(self, x, y):
return max(x, y)
def update(self, idx, x):
idx += (self.num - 1)
self.data[idx] = x
while idx > 0:
idx = (idx-1)//2
self.data[idx] = self.calc(self.data[2*idx+1], self.data[2*idx+2])
def query(self, l, r):
L = l + self.num
R = r + self.num
res = self.el
while L < R:
if L & 1:
res = self.calc(res, self.data[L-1])
L += 1
if R & 1:
R -= 1
res = self.calc(res, self.data[R-1])
L >>= 1
R >>= 1
return res
def get(self, idx):
idx += (self.num - 1)
return self.data[idx]
n, k = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(n)]
seg = SegTree(330000, 0)
max_a = 300010
for a in A:
l = max(0, a-k)
r = min(max_a, a+k+1)
now = seg.query(l, r)
seg.update(a, now+1)
print((seg.query(0, max_a)))
| 49 | 50 | 1,223 | 1,251 | import sys
sys.setrecursionlimit(10**8)
class SegTree:
def __init__(self, N, ele):
self.num = 2 ** (N - 1).bit_length()
self.el = ele
self.data = [ele] * (2 * self.num)
def calc(self, x, y):
return max(x, y)
def update(self, idx, x):
idx += self.num - 1
self.data[idx] = x
while idx > 0:
idx = (idx - 1) // 2
self.data[idx] = self.calc(self.data[2 * idx + 1], self.data[2 * idx + 2])
def query(self, l, r):
L = l + self.num
R = r + self.num
res = self.el
while L < R:
if L & 1:
res = self.calc(res, self.data[L - 1])
L += 1
if R & 1:
R -= 1
res = self.calc(res, self.data[R - 1])
L >>= 1
R >>= 1
return res
def get(self, idx):
idx += self.num - 1
return self.data[idx]
n, k = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(n)]
seg = SegTree(330000, 0)
max_a = 300010
for a in A:
l = max(0, a - k)
r = min(max_a, a + k + 1)
now = seg.query(l, r)
seg.update(a, now + 1)
print((seg.query(0, max_a)))
| import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
class SegTree:
def __init__(self, N, ele):
self.num = 2 ** (N - 1).bit_length()
self.el = ele
self.data = [ele] * (2 * self.num)
def calc(self, x, y):
return max(x, y)
def update(self, idx, x):
idx += self.num - 1
self.data[idx] = x
while idx > 0:
idx = (idx - 1) // 2
self.data[idx] = self.calc(self.data[2 * idx + 1], self.data[2 * idx + 2])
def query(self, l, r):
L = l + self.num
R = r + self.num
res = self.el
while L < R:
if L & 1:
res = self.calc(res, self.data[L - 1])
L += 1
if R & 1:
R -= 1
res = self.calc(res, self.data[R - 1])
L >>= 1
R >>= 1
return res
def get(self, idx):
idx += self.num - 1
return self.data[idx]
n, k = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(n)]
seg = SegTree(330000, 0)
max_a = 300010
for a in A:
l = max(0, a - k)
r = min(max_a, a + k + 1)
now = seg.query(l, r)
seg.update(a, now + 1)
print((seg.query(0, max_a)))
| false | 2 | [
"+input = sys.stdin.readline"
]
| false | 0.184595 | 0.059328 | 3.111423 | [
"s180918547",
"s838904732"
]
|
u981931040 | p02873 | python | s488708646 | s273663010 | 399 | 250 | 23,336 | 29,112 | Accepted | Accepted | 37.34 | S = eval(input())
ans = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == '<':
ans[i + 1] = ans[i] + 1
for i in range(len(S) - 1, -1, -1):
if S[i] == '>':
ans[i] = max(ans[i + 1] + 1, ans[i])
print((sum(ans)))
| S = eval(input())
ans = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == '<':
ans[i + 1] = ans[i] + 1
for i in range(len(S) - 1, -1, -1):
if S[i] == '>':
ans[i] = max(ans[i], ans[i + 1] + 1)
print((sum(ans))) | 11 | 9 | 242 | 237 | S = eval(input())
ans = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == "<":
ans[i + 1] = ans[i] + 1
for i in range(len(S) - 1, -1, -1):
if S[i] == ">":
ans[i] = max(ans[i + 1] + 1, ans[i])
print((sum(ans)))
| S = eval(input())
ans = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == "<":
ans[i + 1] = ans[i] + 1
for i in range(len(S) - 1, -1, -1):
if S[i] == ">":
ans[i] = max(ans[i], ans[i + 1] + 1)
print((sum(ans)))
| false | 18.181818 | [
"- ans[i] = max(ans[i + 1] + 1, ans[i])",
"+ ans[i] = max(ans[i], ans[i + 1] + 1)"
]
| false | 0.037066 | 0.068542 | 0.540776 | [
"s488708646",
"s273663010"
]
|
u889550481 | p03105 | python | s672885110 | s192628055 | 20 | 18 | 3,316 | 2,940 | Accepted | Accepted | 10 | A,B,C=list(map(int,input().split()))
print((min(C,B//A))) | A,B,C=list(map(int,input().split()))
n=B//A
if n<C:
print(n)
else:
print(C) | 2 | 8 | 50 | 86 | A, B, C = list(map(int, input().split()))
print((min(C, B // A)))
| A, B, C = list(map(int, input().split()))
n = B // A
if n < C:
print(n)
else:
print(C)
| false | 75 | [
"-print((min(C, B // A)))",
"+n = B // A",
"+if n < C:",
"+ print(n)",
"+else:",
"+ print(C)"
]
| false | 0.047751 | 0.162518 | 0.293816 | [
"s672885110",
"s192628055"
]
|
u837673618 | p02728 | python | s128788162 | s042121387 | 1,547 | 1,430 | 89,464 | 80,336 | Accepted | Accepted | 7.56 | from functools import *
from collections import *
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
M = 10**9+7
N = int(eval(input()))
@lru_cache(maxsize=None)
def mod_inv(x):
if x == 1:
return 1
return M // x * -mod_inv(M%x) % M
weight = [0]*(N+1)
size = [0]*(N+1)
def calc_subtree(v):
W = 1
S = 1
for child in Edge[v]:
Edge[child].remove(v)
w, s = calc_subtree(child)
W = W * w % M
S += s
weight[v] = W * S % M
size[v] = S
return weight[v], size[v]
ans = [0]*(N+1)
def set_ans(v, a):
ans[v] = a
for child in Edge[v]:
n = size[child]
set_ans(child, ans[v] * n * mod_inv(N-n) % M)
Edge = defaultdict(set)
fact = N
for i in range(1, N):
fact = fact * i % M
a, b = list(map(int, input().split()))
Edge[a].add(b)
Edge[b].add(a)
calc_subtree(1)
set_ans(1, mod_inv(weight[1]) * fact % M)
for i in range(1, N+1):
print((ans[i]))
| from functools import *
from itertools import *
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
M = 10**9+7
N = int(eval(input()))
@lru_cache(maxsize=None)
def mod_inv(x):
return 1 if x == 1 else M // x * -mod_inv(M%x) % M
Weight = [0]*(N+1)
Size = [0]*(N+1)
def calc_subtree(v):
W, S = 1, 1
for child in Edge[v]:
Edge[child].remove(v)
w, s = calc_subtree(child)
W = W * w % M
S += s
Weight[v] = W * S % M
Size[v] = S
return Weight[v], Size[v]
Ans = [0]*(N+1)
def calc_ans(v, a):
Ans[v] = a
for child in Edge[v]:
n = Size[child]
calc_ans(child, Ans[v] * n * mod_inv(N-n) % M)
Edge = [set() for i in range(N+1)]
fact = N
for i in range(1, N):
fact = fact * i % M
a, b = list(map(int, input().split()))
Edge[a].add(b)
Edge[b].add(a)
calc_subtree(1)
calc_ans(1, mod_inv(Weight[1]) * fact % M)
for a in islice(Ans, 1, None):
print(a)
| 49 | 47 | 949 | 951 | from functools import *
from collections import *
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
M = 10**9 + 7
N = int(eval(input()))
@lru_cache(maxsize=None)
def mod_inv(x):
if x == 1:
return 1
return M // x * -mod_inv(M % x) % M
weight = [0] * (N + 1)
size = [0] * (N + 1)
def calc_subtree(v):
W = 1
S = 1
for child in Edge[v]:
Edge[child].remove(v)
w, s = calc_subtree(child)
W = W * w % M
S += s
weight[v] = W * S % M
size[v] = S
return weight[v], size[v]
ans = [0] * (N + 1)
def set_ans(v, a):
ans[v] = a
for child in Edge[v]:
n = size[child]
set_ans(child, ans[v] * n * mod_inv(N - n) % M)
Edge = defaultdict(set)
fact = N
for i in range(1, N):
fact = fact * i % M
a, b = list(map(int, input().split()))
Edge[a].add(b)
Edge[b].add(a)
calc_subtree(1)
set_ans(1, mod_inv(weight[1]) * fact % M)
for i in range(1, N + 1):
print((ans[i]))
| from functools import *
from itertools import *
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
M = 10**9 + 7
N = int(eval(input()))
@lru_cache(maxsize=None)
def mod_inv(x):
return 1 if x == 1 else M // x * -mod_inv(M % x) % M
Weight = [0] * (N + 1)
Size = [0] * (N + 1)
def calc_subtree(v):
W, S = 1, 1
for child in Edge[v]:
Edge[child].remove(v)
w, s = calc_subtree(child)
W = W * w % M
S += s
Weight[v] = W * S % M
Size[v] = S
return Weight[v], Size[v]
Ans = [0] * (N + 1)
def calc_ans(v, a):
Ans[v] = a
for child in Edge[v]:
n = Size[child]
calc_ans(child, Ans[v] * n * mod_inv(N - n) % M)
Edge = [set() for i in range(N + 1)]
fact = N
for i in range(1, N):
fact = fact * i % M
a, b = list(map(int, input().split()))
Edge[a].add(b)
Edge[b].add(a)
calc_subtree(1)
calc_ans(1, mod_inv(Weight[1]) * fact % M)
for a in islice(Ans, 1, None):
print(a)
| false | 4.081633 | [
"-from collections import *",
"+from itertools import *",
"- if x == 1:",
"- return 1",
"- return M // x * -mod_inv(M % x) % M",
"+ return 1 if x == 1 else M // x * -mod_inv(M % x) % M",
"-weight = [0] * (N + 1)",
"-size = [0] * (N + 1)",
"+Weight = [0] * (N + 1)",
"+Size = [0] * (N + 1)",
"- W = 1",
"- S = 1",
"+ W, S = 1, 1",
"- weight[v] = W * S % M",
"- size[v] = S",
"- return weight[v], size[v]",
"+ Weight[v] = W * S % M",
"+ Size[v] = S",
"+ return Weight[v], Size[v]",
"-ans = [0] * (N + 1)",
"+Ans = [0] * (N + 1)",
"-def set_ans(v, a):",
"- ans[v] = a",
"+def calc_ans(v, a):",
"+ Ans[v] = a",
"- n = size[child]",
"- set_ans(child, ans[v] * n * mod_inv(N - n) % M)",
"+ n = Size[child]",
"+ calc_ans(child, Ans[v] * n * mod_inv(N - n) % M)",
"-Edge = defaultdict(set)",
"+Edge = [set() for i in range(N + 1)]",
"-set_ans(1, mod_inv(weight[1]) * fact % M)",
"-for i in range(1, N + 1):",
"- print((ans[i]))",
"+calc_ans(1, mod_inv(Weight[1]) * fact % M)",
"+for a in islice(Ans, 1, None):",
"+ print(a)"
]
| false | 0.111415 | 0.085478 | 1.303437 | [
"s128788162",
"s042121387"
]
|
u987164499 | p03240 | python | s854883004 | s364038775 | 583 | 33 | 3,064 | 3,064 | Accepted | Accepted | 94.34 | from sys import stdin
n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
point = 0
for i in range(101):
for j in range(101):
flag = True
kizyun = False
count = 0
for a,b,c in li:
if c != 0:
count += 1
if kizyun == False:
h = c+abs(a-i)+abs(b-j)
ha = a
hb = b
hc = c
kizyun = True
else:
k = c+abs(a-i)+abs(b-j)
if h != k:
flag = False
if count == 1:
print((ha,hb,hc))
exit()
if flag == True:
point += 1
print((i,j,h)) | n = int(eval(input()))
low = 0
hi = 10**9
li = []
lin = []
for _ in range(n):
x,y,h = list(map(int,input().split()))
if h != 0:
li.append((x,y,h))
lin.append((x,y,h))
for i in range(101):
for j in range(101):
flag = True
h = li[0][2]+abs(i-li[0][0])+abs(j-li[0][1])
for a,b,c in lin:
if max(h-abs(i-a)-abs(j-b),0) != c:
flag = False
break
if flag:
print((i,j,h))
exit() | 28 | 24 | 821 | 505 | from sys import stdin
n = int(stdin.readline().rstrip())
li = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n)]
point = 0
for i in range(101):
for j in range(101):
flag = True
kizyun = False
count = 0
for a, b, c in li:
if c != 0:
count += 1
if kizyun == False:
h = c + abs(a - i) + abs(b - j)
ha = a
hb = b
hc = c
kizyun = True
else:
k = c + abs(a - i) + abs(b - j)
if h != k:
flag = False
if count == 1:
print((ha, hb, hc))
exit()
if flag == True:
point += 1
print((i, j, h))
| n = int(eval(input()))
low = 0
hi = 10**9
li = []
lin = []
for _ in range(n):
x, y, h = list(map(int, input().split()))
if h != 0:
li.append((x, y, h))
lin.append((x, y, h))
for i in range(101):
for j in range(101):
flag = True
h = li[0][2] + abs(i - li[0][0]) + abs(j - li[0][1])
for a, b, c in lin:
if max(h - abs(i - a) - abs(j - b), 0) != c:
flag = False
break
if flag:
print((i, j, h))
exit()
| false | 14.285714 | [
"-from sys import stdin",
"-",
"-n = int(stdin.readline().rstrip())",
"-li = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n)]",
"-point = 0",
"+n = int(eval(input()))",
"+low = 0",
"+hi = 10**9",
"+li = []",
"+lin = []",
"+for _ in range(n):",
"+ x, y, h = list(map(int, input().split()))",
"+ if h != 0:",
"+ li.append((x, y, h))",
"+ lin.append((x, y, h))",
"- kizyun = False",
"- count = 0",
"- for a, b, c in li:",
"- if c != 0:",
"- count += 1",
"- if kizyun == False:",
"- h = c + abs(a - i) + abs(b - j)",
"- ha = a",
"- hb = b",
"- hc = c",
"- kizyun = True",
"- else:",
"- k = c + abs(a - i) + abs(b - j)",
"- if h != k:",
"- flag = False",
"- if count == 1:",
"- print((ha, hb, hc))",
"+ h = li[0][2] + abs(i - li[0][0]) + abs(j - li[0][1])",
"+ for a, b, c in lin:",
"+ if max(h - abs(i - a) - abs(j - b), 0) != c:",
"+ flag = False",
"+ break",
"+ if flag:",
"+ print((i, j, h))",
"- if flag == True:",
"- point += 1",
"- print((i, j, h))"
]
| false | 0.148855 | 0.03776 | 3.942167 | [
"s854883004",
"s364038775"
]
|
u387774811 | p02996 | python | s368031988 | s757744626 | 979 | 699 | 119,644 | 85,156 | Accepted | Accepted | 28.6 | def merge_sort(arr):
if len(arr) <= 1:
return arr
mid = len(arr) // 2
# ใใใงๅๅฒใ่กใ
left = arr[:mid]
right = arr[mid:]
# ๅๅธฐ็ใซๅๅฒใ่กใ
left = merge_sort(left)
right = merge_sort(right)
# returnใ่ฟใฃใฆใใใใ็ตๅใ่กใใ็ตๅใใใใฎใๆฌกใซๆธกใ
return merge(left, right)
def merge(left, right):
merged = []
l_i, r_i = 0, 0
# ใฝใผใๆธใฟ้
ๅใใใผใธใใใใใใใใใๅทฆใใ่ฆใฆใใใ ใใง่ฏใ
while l_i < len(left) and r_i < len(right):
# ใใใง=ใใคใใใใจใงๅฎๅฎๆงใไฟใฃใฆใใ
if left[l_i][1] <= right[r_i][1]:
merged.append(left[l_i])
l_i += 1
else:
merged.append(right[r_i])
r_i += 1
# ไธใฎwhileๆใฎใฉใกใใใFalseใซใชใฃใๅ ดๅ็ตไบใใใใใใใพใใextendใใ
if l_i < len(left):
merged.extend(left[l_i:])
if r_i < len(right):
merged.extend(right[r_i:])
return merged
import sys
input = sys.stdin.readline
N=int(eval(input()))
lst=[0]*N
lst=[list(map(int,input().split())) for i in range(N)]
lsta=merge_sort(lst)
ans=0
t=0
for i in range(N):
t+=lsta[i][0]
if t>lsta[i][1]:
ans+=1
if ans==0:
print("Yes")
else:
print("No")
| import sys
input = sys.stdin.readline
N=int(eval(input()))
lst=[0]*N
lst=[list(map(int,input().split())) for i in range(N)]
lst.sort(key=lambda x: x[1])
ans=0
t=0
for i in range(N):
t+=lst[i][0]
if t>lst[i][1]:
ans+=1
if ans==0:
print("Yes")
else:
print("No") | 47 | 16 | 996 | 274 | def merge_sort(arr):
if len(arr) <= 1:
return arr
mid = len(arr) // 2
# ใใใงๅๅฒใ่กใ
left = arr[:mid]
right = arr[mid:]
# ๅๅธฐ็ใซๅๅฒใ่กใ
left = merge_sort(left)
right = merge_sort(right)
# returnใ่ฟใฃใฆใใใใ็ตๅใ่กใใ็ตๅใใใใฎใๆฌกใซๆธกใ
return merge(left, right)
def merge(left, right):
merged = []
l_i, r_i = 0, 0
# ใฝใผใๆธใฟ้
ๅใใใผใธใใใใใใใใใๅทฆใใ่ฆใฆใใใ ใใง่ฏใ
while l_i < len(left) and r_i < len(right):
# ใใใง=ใใคใใใใจใงๅฎๅฎๆงใไฟใฃใฆใใ
if left[l_i][1] <= right[r_i][1]:
merged.append(left[l_i])
l_i += 1
else:
merged.append(right[r_i])
r_i += 1
# ไธใฎwhileๆใฎใฉใกใใใFalseใซใชใฃใๅ ดๅ็ตไบใใใใใใใพใใextendใใ
if l_i < len(left):
merged.extend(left[l_i:])
if r_i < len(right):
merged.extend(right[r_i:])
return merged
import sys
input = sys.stdin.readline
N = int(eval(input()))
lst = [0] * N
lst = [list(map(int, input().split())) for i in range(N)]
lsta = merge_sort(lst)
ans = 0
t = 0
for i in range(N):
t += lsta[i][0]
if t > lsta[i][1]:
ans += 1
if ans == 0:
print("Yes")
else:
print("No")
| import sys
input = sys.stdin.readline
N = int(eval(input()))
lst = [0] * N
lst = [list(map(int, input().split())) for i in range(N)]
lst.sort(key=lambda x: x[1])
ans = 0
t = 0
for i in range(N):
t += lst[i][0]
if t > lst[i][1]:
ans += 1
if ans == 0:
print("Yes")
else:
print("No")
| false | 65.957447 | [
"-def merge_sort(arr):",
"- if len(arr) <= 1:",
"- return arr",
"- mid = len(arr) // 2",
"- # ใใใงๅๅฒใ่กใ",
"- left = arr[:mid]",
"- right = arr[mid:]",
"- # ๅๅธฐ็ใซๅๅฒใ่กใ",
"- left = merge_sort(left)",
"- right = merge_sort(right)",
"- # returnใ่ฟใฃใฆใใใใ็ตๅใ่กใใ็ตๅใใใใฎใๆฌกใซๆธกใ",
"- return merge(left, right)",
"-",
"-",
"-def merge(left, right):",
"- merged = []",
"- l_i, r_i = 0, 0",
"- # ใฝใผใๆธใฟ้
ๅใใใผใธใใใใใใใใใๅทฆใใ่ฆใฆใใใ ใใง่ฏใ",
"- while l_i < len(left) and r_i < len(right):",
"- # ใใใง=ใใคใใใใจใงๅฎๅฎๆงใไฟใฃใฆใใ",
"- if left[l_i][1] <= right[r_i][1]:",
"- merged.append(left[l_i])",
"- l_i += 1",
"- else:",
"- merged.append(right[r_i])",
"- r_i += 1",
"- # ไธใฎwhileๆใฎใฉใกใใใFalseใซใชใฃใๅ ดๅ็ตไบใใใใใใใพใใextendใใ",
"- if l_i < len(left):",
"- merged.extend(left[l_i:])",
"- if r_i < len(right):",
"- merged.extend(right[r_i:])",
"- return merged",
"-",
"-",
"-lsta = merge_sort(lst)",
"+lst.sort(key=lambda x: x[1])",
"- t += lsta[i][0]",
"- if t > lsta[i][1]:",
"+ t += lst[i][0]",
"+ if t > lst[i][1]:"
]
| false | 0.061019 | 0.037407 | 1.631212 | [
"s368031988",
"s757744626"
]
|
u021906447 | p02701 | python | s117134163 | s094733858 | 315 | 289 | 35,724 | 35,656 | Accepted | Accepted | 8.25 | N = int(eval(input()))
a = []
for i in range(N):
S = str(eval(input()))
a.append(S)
count = len(list(set(a)))
print(count) | N = int(eval(input()))
a = []
for i in range(N):
f = eval(input())
a.append(f)
a=list(set(a))
print((len(a))) | 9 | 9 | 128 | 111 | N = int(eval(input()))
a = []
for i in range(N):
S = str(eval(input()))
a.append(S)
count = len(list(set(a)))
print(count)
| N = int(eval(input()))
a = []
for i in range(N):
f = eval(input())
a.append(f)
a = list(set(a))
print((len(a)))
| false | 0 | [
"- S = str(eval(input()))",
"- a.append(S)",
"-count = len(list(set(a)))",
"-print(count)",
"+ f = eval(input())",
"+ a.append(f)",
"+a = list(set(a))",
"+print((len(a)))"
]
| false | 0.049607 | 0.049848 | 0.99515 | [
"s117134163",
"s094733858"
]
|
u408071652 | p02883 | python | s210241571 | s646242907 | 362 | 314 | 113,692 | 113,856 | Accepted | Accepted | 13.26 | import sys
# \n
def input():
return sys.stdin.readline().rstrip()
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True) # 0(NlogN)
F.sort() # O(NlogN)
def train(X, Y, T): # O(N) ans: ๅๆฐ
ans = 0
for i in range(len(X)):
ans += max(0, X[i] - T // Y[i])
return ans
ok = 10**18+1 #ๆ้
ng = -1
while ok - ng > 1:
mid = (ok + ng) // 2 #ๆ้
ans = train(A,F,mid) #kaisuu
if ans >K:
ng =mid
else:
ok =mid
print(ok)
if __name__ == "__main__":
main()
| import sys
# \n
def input():
return sys.stdin.readline().rstrip()
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True) # 0(NlogN)
F.sort() # O(NlogN)
def train(X, Y, T): # O(N) ans: ๅๆฐ
ans = 0
for i in range(len(X)):
ans += max(0, X[i] - T // Y[i])
return ans
if K>=10**12:
print((0))
exit()
ok = 10**12+1 #ๆ้
ng = -1
# O(Nlog(maxK)?)
while ok - ng > 1:
mid = (ok + ng) // 2 #ๆ้
ans = train(A,F,mid) #kaisuu
if ans >K:
ng =mid
else:
ok =mid
print(ok)
if __name__ == "__main__":
main()
| 37 | 42 | 714 | 791 | import sys
# \n
def input():
return sys.stdin.readline().rstrip()
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True) # 0(NlogN)
F.sort() # O(NlogN)
def train(X, Y, T): # O(N) ans: ๅๆฐ
ans = 0
for i in range(len(X)):
ans += max(0, X[i] - T // Y[i])
return ans
ok = 10**18 + 1 # ๆ้
ng = -1
while ok - ng > 1:
mid = (ok + ng) // 2 # ๆ้
ans = train(A, F, mid) # kaisuu
if ans > K:
ng = mid
else:
ok = mid
print(ok)
if __name__ == "__main__":
main()
| import sys
# \n
def input():
return sys.stdin.readline().rstrip()
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True) # 0(NlogN)
F.sort() # O(NlogN)
def train(X, Y, T): # O(N) ans: ๅๆฐ
ans = 0
for i in range(len(X)):
ans += max(0, X[i] - T // Y[i])
return ans
if K >= 10**12:
print((0))
exit()
ok = 10**12 + 1 # ๆ้
ng = -1
# O(Nlog(maxK)?)
while ok - ng > 1:
mid = (ok + ng) // 2 # ๆ้
ans = train(A, F, mid) # kaisuu
if ans > K:
ng = mid
else:
ok = mid
print(ok)
if __name__ == "__main__":
main()
| false | 11.904762 | [
"- ok = 10**18 + 1 # ๆ้",
"+ if K >= 10**12:",
"+ print((0))",
"+ exit()",
"+ ok = 10**12 + 1 # ๆ้",
"+ # O(Nlog(maxK)?)"
]
| false | 0.046881 | 0.126263 | 0.371298 | [
"s210241571",
"s646242907"
]
|
u989345508 | p02697 | python | s027225354 | s565874757 | 64 | 48 | 75,636 | 17,372 | Accepted | Accepted | 25 | n,m=list(map(int,input().split()))
if n%2==1:
x=[f"{i+1} {n-i}" for i in range(m)]
print((" ".join(x)))
else:
x=[f"{i+1} {n-i}" if i<m/2 else f"{i+1} {n-i-1}" for i in range(m)]
print((" ".join(x)))
| def main():
n,m=list(map(int,input().split()))
if n%2==1:
x=[f"{i+1} {n-i}" for i in range(m)]
print((" ".join(x)))
else:
x=[f"{i+1} {n-i}" if i<m/2 else f"{i+1} {n-i-1}" for i in range(m)]
print((" ".join(x)))
if __name__ == "__main__":
main() | 7 | 11 | 211 | 293 | n, m = list(map(int, input().split()))
if n % 2 == 1:
x = [f"{i+1} {n-i}" for i in range(m)]
print((" ".join(x)))
else:
x = [f"{i+1} {n-i}" if i < m / 2 else f"{i+1} {n-i-1}" for i in range(m)]
print((" ".join(x)))
| def main():
n, m = list(map(int, input().split()))
if n % 2 == 1:
x = [f"{i+1} {n-i}" for i in range(m)]
print((" ".join(x)))
else:
x = [f"{i+1} {n-i}" if i < m / 2 else f"{i+1} {n-i-1}" for i in range(m)]
print((" ".join(x)))
if __name__ == "__main__":
main()
| false | 36.363636 | [
"-n, m = list(map(int, input().split()))",
"-if n % 2 == 1:",
"- x = [f\"{i+1} {n-i}\" for i in range(m)]",
"- print((\" \".join(x)))",
"-else:",
"- x = [f\"{i+1} {n-i}\" if i < m / 2 else f\"{i+1} {n-i-1}\" for i in range(m)]",
"- print((\" \".join(x)))",
"+def main():",
"+ n, m = list(map(int, input().split()))",
"+ if n % 2 == 1:",
"+ x = [f\"{i+1} {n-i}\" for i in range(m)]",
"+ print((\" \".join(x)))",
"+ else:",
"+ x = [f\"{i+1} {n-i}\" if i < m / 2 else f\"{i+1} {n-i-1}\" for i in range(m)]",
"+ print((\" \".join(x)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.102339 | 0.040022 | 2.557028 | [
"s027225354",
"s565874757"
]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.