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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u947883560 | p02792 | python | s821514943 | s225833845 | 307 | 222 | 44,524 | 40,556 | Accepted | Accepted | 27.69 | #!/usr/bin/env python3
import sys
import math
INF = float("inf")
def solve(N: int):
debug = False
SN = str(N)
keta = int(math.log10(N)+1)
count = 0
for i in range(1, N+1):
first = str(i)[0]
last = str(i)[-1]
if last == "0": # 考えない
continue
# ひとけた
if first == last:
count += 1
# ふたけた
if int(last+first) <= N:
count += 1
if keta < 3:
continue
# 3桁以上keta桁未満
for j in range(3, keta):
count += 10**(j-2)
# keta桁
# Nを超えない数
if last < SN[0]:
count += 10**(keta-2)
elif last == SN[0]:
# 間の桁について、i桁までまで考える。
DP = [[0]*2 for _ in range(keta-1)]
DP[0][False] = 1
for j in range(1, keta-1):
DP[j][False] = DP[j-1][False]*1
DP[j][True] = DP[j-1][True]*10 + DP[j-1][False]*int(SN[j])
count += DP[-1][True]
if SN[-1] >= first:
count += 1
print(count)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
solve(N)
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys
import math
INF = float("inf")
def solve(N: int):
table = [[0]*10 for _ in range(10)]
for i in range(1, N+1):
first = int(str(i)[0])
last = int(str(i)[-1])
table[first][last] += 1
count = 0
for i in range(10):
for j in range(10):
count += table[i][j]*table[j][i]
print(count)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
solve(N)
if __name__ == '__main__':
main()
| 59 | 35 | 1,401 | 682 | #!/usr/bin/env python3
import sys
import math
INF = float("inf")
def solve(N: int):
debug = False
SN = str(N)
keta = int(math.log10(N) + 1)
count = 0
for i in range(1, N + 1):
first = str(i)[0]
last = str(i)[-1]
if last == "0": # 考えない
continue
# ひとけた
if first == last:
count += 1
# ふたけた
if int(last + first) <= N:
count += 1
if keta < 3:
continue
# 3桁以上keta桁未満
for j in range(3, keta):
count += 10 ** (j - 2)
# keta桁
# Nを超えない数
if last < SN[0]:
count += 10 ** (keta - 2)
elif last == SN[0]:
# 間の桁について、i桁までまで考える。
DP = [[0] * 2 for _ in range(keta - 1)]
DP[0][False] = 1
for j in range(1, keta - 1):
DP[j][False] = DP[j - 1][False] * 1
DP[j][True] = DP[j - 1][True] * 10 + DP[j - 1][False] * int(SN[j])
count += DP[-1][True]
if SN[-1] >= first:
count += 1
print(count)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
solve(N)
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
import math
INF = float("inf")
def solve(N: int):
table = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
first = int(str(i)[0])
last = int(str(i)[-1])
table[first][last] += 1
count = 0
for i in range(10):
for j in range(10):
count += table[i][j] * table[j][i]
print(count)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
solve(N)
if __name__ == "__main__":
main()
| false | 40.677966 | [
"- debug = False",
"- SN = str(N)",
"- keta = int(math.log10(N) + 1)",
"+ table = [[0] * 10 for _ in range(10)]",
"+ for i in range(1, N + 1):",
"+ first = int(str(i)[0])",
"+ last = int(str(i)[-1])",
"+ table[first][last] += 1",
"- for i in range(1, N + 1):",
... | false | 0.215198 | 0.074959 | 2.870859 | [
"s821514943",
"s225833845"
] |
u509739538 | p02678 | python | s109524851 | s809250540 | 1,101 | 1,014 | 35,308 | 35,236 | Accepted | Accepted | 7.9 | import queue
n,m = list(map(int, input().split()))
puted = [0]*(n+1)
ab = [[] for i in range(n+1)]
for i in range(m):
a,b = list(map(int, input().split()))
ab[a].append(b)
ab[b].append(a)
q = queue.Queue()
flg = [-1]*n
flg[0] = 0
q.put(1)
while not q.empty():
item = q.get()
for i in ab[item]:
if puted[i]==0:
flg[i-1]=item
q.put(i)
puted[i]=1
if -1 in flg:
print("No")
exit()
print("Yes")
for i in range(1,len(flg)):
print((flg[i]))
| import queue
n,m = list(map(int, input().split()))
puted = [1]*(n+1)
ab = [[] for i in range(n+1)]
for i in range(m):
a,b = list(map(int, input().split()))
ab[a].append(b)
ab[b].append(a)
q = queue.Queue()
flg = [-1]*n
flg[0] = 0
q.put(1)
while not q.empty():
item = q.get()
for i in ab[item]:
if puted[i]:
flg[i-1]=item
q.put(i)
puted[i]=0
if -1 in flg:
print("No")
exit()
print("Yes")
for i in range(1,len(flg)):
print((flg[i]))
| 31 | 31 | 487 | 484 | import queue
n, m = list(map(int, input().split()))
puted = [0] * (n + 1)
ab = [[] for i in range(n + 1)]
for i in range(m):
a, b = list(map(int, input().split()))
ab[a].append(b)
ab[b].append(a)
q = queue.Queue()
flg = [-1] * n
flg[0] = 0
q.put(1)
while not q.empty():
item = q.get()
for i in ab[item]:
if puted[i] == 0:
flg[i - 1] = item
q.put(i)
puted[i] = 1
if -1 in flg:
print("No")
exit()
print("Yes")
for i in range(1, len(flg)):
print((flg[i]))
| import queue
n, m = list(map(int, input().split()))
puted = [1] * (n + 1)
ab = [[] for i in range(n + 1)]
for i in range(m):
a, b = list(map(int, input().split()))
ab[a].append(b)
ab[b].append(a)
q = queue.Queue()
flg = [-1] * n
flg[0] = 0
q.put(1)
while not q.empty():
item = q.get()
for i in ab[item]:
if puted[i]:
flg[i - 1] = item
q.put(i)
puted[i] = 0
if -1 in flg:
print("No")
exit()
print("Yes")
for i in range(1, len(flg)):
print((flg[i]))
| false | 0 | [
"-puted = [0] * (n + 1)",
"+puted = [1] * (n + 1)",
"- if puted[i] == 0:",
"+ if puted[i]:",
"- puted[i] = 1",
"+ puted[i] = 0"
] | false | 0.040145 | 0.040193 | 0.998799 | [
"s109524851",
"s809250540"
] |
u562935282 | p03714 | python | s254960053 | s932241989 | 453 | 371 | 37,468 | 37,212 | Accepted | Accepted | 18.1 | from heapq import heapify, heappop, heappush
from collections import deque
n = int(eval(input()))
a = list(map(int, input().split()))
L = a[:n]
sum_l = [sum(L)]
heapify(L)
ML = a[n:2 * n]
ML = deque(ML)
R = list([(-1) * x for x in a[2 * n:]])
sum_r = [sum(R)] # あとでReverseする
heapify(R)
MR = list([(-1) * x for x in a[n:2 * n]])
MR = deque(MR)
for i in range(n):
add_to_l = ML.popleft()
heappush(L, add_to_l)
subtract_to_l = heappop(L)
t = sum_l[-1] + add_to_l - subtract_to_l
sum_l.append(t)
# print(sum_l)
for i in range(n):
add_to_r = MR.pop()
heappush(R, add_to_r)
subtract_to_r = heappop(R)
t = sum_r[-1] + add_to_r - subtract_to_r
sum_r.append(t)
# print(sum_r)
sum_r = sum_r[::-1]
ans = sum_l[0] + sum_r[0]
for i in range(1, n + 1):
t = sum_l[i] + sum_r[i]
ans = max(ans, t)
print(ans) | def main():
from heapq import heappush, heappushpop
n = int(eval(input()))
*a, = list(map(int, input().split())) # [0,n),[n,2n),[2n,3n)
to_rm = [0] * (n * 3)
h = []
for x in a[:n]:
heappush(h, x)
mid = tuple(enumerate(a[n:n * 2], n))
t = 0
for i, x in mid:
mi = heappushpop(h, x)
t += mi
to_rm[i] = -t
h = []
for x in a[n * 2:n * 3]:
heappush(h, -x)
t = 0
for i, x in reversed(mid):
ma = -heappushpop(h, -x)
t += ma
to_rm[i - 1] += t
tot = sum(a)
ret = -10 ** 30
s = sum(a[:n - 1])
for tail in range(n - 1, n * 2):
s += a[tail]
ret = max(ret, s - (tot - s) + to_rm[tail]) # [0,tail]=前半
print(ret)
if __name__ == '__main__':
main()
| 48 | 41 | 905 | 827 | from heapq import heapify, heappop, heappush
from collections import deque
n = int(eval(input()))
a = list(map(int, input().split()))
L = a[:n]
sum_l = [sum(L)]
heapify(L)
ML = a[n : 2 * n]
ML = deque(ML)
R = list([(-1) * x for x in a[2 * n :]])
sum_r = [sum(R)] # あとでReverseする
heapify(R)
MR = list([(-1) * x for x in a[n : 2 * n]])
MR = deque(MR)
for i in range(n):
add_to_l = ML.popleft()
heappush(L, add_to_l)
subtract_to_l = heappop(L)
t = sum_l[-1] + add_to_l - subtract_to_l
sum_l.append(t)
# print(sum_l)
for i in range(n):
add_to_r = MR.pop()
heappush(R, add_to_r)
subtract_to_r = heappop(R)
t = sum_r[-1] + add_to_r - subtract_to_r
sum_r.append(t)
# print(sum_r)
sum_r = sum_r[::-1]
ans = sum_l[0] + sum_r[0]
for i in range(1, n + 1):
t = sum_l[i] + sum_r[i]
ans = max(ans, t)
print(ans)
| def main():
from heapq import heappush, heappushpop
n = int(eval(input()))
(*a,) = list(map(int, input().split())) # [0,n),[n,2n),[2n,3n)
to_rm = [0] * (n * 3)
h = []
for x in a[:n]:
heappush(h, x)
mid = tuple(enumerate(a[n : n * 2], n))
t = 0
for i, x in mid:
mi = heappushpop(h, x)
t += mi
to_rm[i] = -t
h = []
for x in a[n * 2 : n * 3]:
heappush(h, -x)
t = 0
for i, x in reversed(mid):
ma = -heappushpop(h, -x)
t += ma
to_rm[i - 1] += t
tot = sum(a)
ret = -(10**30)
s = sum(a[: n - 1])
for tail in range(n - 1, n * 2):
s += a[tail]
ret = max(ret, s - (tot - s) + to_rm[tail]) # [0,tail]=前半
print(ret)
if __name__ == "__main__":
main()
| false | 14.583333 | [
"-from heapq import heapify, heappop, heappush",
"-from collections import deque",
"+def main():",
"+ from heapq import heappush, heappushpop",
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-L = a[:n]",
"-sum_l = [sum(L)]",
"-heapify(L)",
"-ML = a[n : 2 * n]",
"-ML = deq... | false | 0.036024 | 0.037711 | 0.955273 | [
"s254960053",
"s932241989"
] |
u693953100 | p03612 | python | s623627092 | s465244914 | 87 | 57 | 14,008 | 14,008 | Accepted | Accepted | 34.48 | n = int(eval(input()))
cnt = 0
p = list(map(int,input().split()))
for i in range(n):
if p[i]==i+1:
if i==0:
p[i+1],p[i] = p[i],p[i+1]
cnt+=1
elif i==n-1:
cnt+=1
break
elif p[i]==i+2:
p[i-1],p[i] = p[i],p[i-1]
cnt+=1
else:
p[i],p[i+1] = p[i+1],p[i]
cnt+=1
print(cnt) | def solve():
n = int(eval(input()))
l = list(map(int,input().split()))
res = 0
for i in range(n-1):
if l[i]==i+1:
l[i],l[i+1]=l[i+1],l[i]
res+=1
if l[n-1]==n:
res+=1
print(res)
if __name__=='__main__':
solve() | 18 | 13 | 408 | 283 | n = int(eval(input()))
cnt = 0
p = list(map(int, input().split()))
for i in range(n):
if p[i] == i + 1:
if i == 0:
p[i + 1], p[i] = p[i], p[i + 1]
cnt += 1
elif i == n - 1:
cnt += 1
break
elif p[i] == i + 2:
p[i - 1], p[i] = p[i], p[i - 1]
cnt += 1
else:
p[i], p[i + 1] = p[i + 1], p[i]
cnt += 1
print(cnt)
| def solve():
n = int(eval(input()))
l = list(map(int, input().split()))
res = 0
for i in range(n - 1):
if l[i] == i + 1:
l[i], l[i + 1] = l[i + 1], l[i]
res += 1
if l[n - 1] == n:
res += 1
print(res)
if __name__ == "__main__":
solve()
| false | 27.777778 | [
"-n = int(eval(input()))",
"-cnt = 0",
"-p = list(map(int, input().split()))",
"-for i in range(n):",
"- if p[i] == i + 1:",
"- if i == 0:",
"- p[i + 1], p[i] = p[i], p[i + 1]",
"- cnt += 1",
"- elif i == n - 1:",
"- cnt += 1",
"- brea... | false | 0.074446 | 0.043337 | 1.717834 | [
"s623627092",
"s465244914"
] |
u188827677 | p02802 | python | s729156517 | s591653232 | 282 | 189 | 4,596 | 10,284 | Accepted | Accepted | 32.98 | n,m = list(map(int, input().split()))
result = [False]*n
count = [0]*n
for _ in range(m):
p,s = input().split()
p = int(p)-1
if not result[p]:
if s == "AC": result[p] = True
else: count[p] += 1
ng = 0
for i in range(n):
if result[i]:
ng += count[i]
print((result.count(True),ng)) | n,m = list(map(int, input().split()))
flag = [False]*n
wa = [0]*n
for _ in range(m):
p,s = input().split()
p = int(p)-1
if not flag[p]:
if s == "WA":
wa[p] += 1
else: flag[p] = True
count = 0
for i in range(n):
if flag[i]: count += wa[i]
print((flag.count(True), count)) | 16 | 17 | 314 | 303 | n, m = list(map(int, input().split()))
result = [False] * n
count = [0] * n
for _ in range(m):
p, s = input().split()
p = int(p) - 1
if not result[p]:
if s == "AC":
result[p] = True
else:
count[p] += 1
ng = 0
for i in range(n):
if result[i]:
ng += count[i]
print((result.count(True), ng))
| n, m = list(map(int, input().split()))
flag = [False] * n
wa = [0] * n
for _ in range(m):
p, s = input().split()
p = int(p) - 1
if not flag[p]:
if s == "WA":
wa[p] += 1
else:
flag[p] = True
count = 0
for i in range(n):
if flag[i]:
count += wa[i]
print((flag.count(True), count))
| false | 5.882353 | [
"-result = [False] * n",
"-count = [0] * n",
"+flag = [False] * n",
"+wa = [0] * n",
"- if not result[p]:",
"- if s == \"AC\":",
"- result[p] = True",
"+ if not flag[p]:",
"+ if s == \"WA\":",
"+ wa[p] += 1",
"- count[p] += 1",
"-ng = 0",
... | false | 0.040214 | 0.040687 | 0.98836 | [
"s729156517",
"s591653232"
] |
u562935282 | p03209 | python | s681403384 | s666362472 | 22 | 18 | 3,444 | 3,064 | Accepted | Accepted | 18.18 | from collections import defaultdict
def burger(lv, x):
if d[(lv, x)] >= 0:
return d[(lv, x)]
if x < 1 or x > cnt[lv]:
d[(lv, x)] = 0
return d[(lv, x)]
# base case
if (lv, x) == (0, 1):
d[(lv, x)] = 1
return d[(lv, x)]
half = (cnt[lv] - 1) // 2
if x <= half:
d[(lv, x)] = burger(lv - 1, x - 1)
return d[(lv, x)]
else:
d[(lv, x)] = burger(lv - 1, half - 1) + 1 + burger(lv - 1, min(x - 1 - half, half - 1))
return d[(lv, x)]
n, x = list(map(int, input().split()))
cnt = [1]
for lv in range(1, 50 + 1):
cnt.append(cnt[-1] * 2 + 3)
d = defaultdict(lambda: -1)
print((burger(n, x)))
# print(d)
| def burger(n, x):
if x < 1:
return 0
# base case
if (n, x) == (0, 1):
return 1
if x <= 1 + size[n - 1]:
return burger(n - 1, x - 1)
else:
return p_num[n - 1] + 1 + burger(n - 1, min(x - 2 - size[n - 1], size[n - 1]))
# x-2-sizeだと前lvバーガー+バンのことがあり、バンを外す
n, x = list(map(int, input().split()))
size, p_num = [1], [1]
for i in range(1, 50 + 1):
size.append(size[-1] * 2 + 3)
p_num.append(p_num[-1] * 2 + 1)
print((burger(n, x)))
| 33 | 22 | 725 | 507 | from collections import defaultdict
def burger(lv, x):
if d[(lv, x)] >= 0:
return d[(lv, x)]
if x < 1 or x > cnt[lv]:
d[(lv, x)] = 0
return d[(lv, x)]
# base case
if (lv, x) == (0, 1):
d[(lv, x)] = 1
return d[(lv, x)]
half = (cnt[lv] - 1) // 2
if x <= half:
d[(lv, x)] = burger(lv - 1, x - 1)
return d[(lv, x)]
else:
d[(lv, x)] = (
burger(lv - 1, half - 1) + 1 + burger(lv - 1, min(x - 1 - half, half - 1))
)
return d[(lv, x)]
n, x = list(map(int, input().split()))
cnt = [1]
for lv in range(1, 50 + 1):
cnt.append(cnt[-1] * 2 + 3)
d = defaultdict(lambda: -1)
print((burger(n, x)))
# print(d)
| def burger(n, x):
if x < 1:
return 0
# base case
if (n, x) == (0, 1):
return 1
if x <= 1 + size[n - 1]:
return burger(n - 1, x - 1)
else:
return p_num[n - 1] + 1 + burger(n - 1, min(x - 2 - size[n - 1], size[n - 1]))
# x-2-sizeだと前lvバーガー+バンのことがあり、バンを外す
n, x = list(map(int, input().split()))
size, p_num = [1], [1]
for i in range(1, 50 + 1):
size.append(size[-1] * 2 + 3)
p_num.append(p_num[-1] * 2 + 1)
print((burger(n, x)))
| false | 33.333333 | [
"-from collections import defaultdict",
"-",
"-",
"-def burger(lv, x):",
"- if d[(lv, x)] >= 0:",
"- return d[(lv, x)]",
"- if x < 1 or x > cnt[lv]:",
"- d[(lv, x)] = 0",
"- return d[(lv, x)]",
"+def burger(n, x):",
"+ if x < 1:",
"+ return 0",
"- if (... | false | 0.046526 | 0.047396 | 0.981642 | [
"s681403384",
"s666362472"
] |
u780342333 | p02400 | python | s478310197 | s747908439 | 30 | 20 | 7,604 | 5,584 | Accepted | Accepted | 33.33 | import math
n = float(eval(input()))
area = "%.6f" % float(n **2 * math.pi)
circ = "%.6f" % float(n * 2 * math.pi)
print((area, circ)) | pi = 3.14159265359
r = float(eval(input()))
print(f"{r*r*pi:.6f} {2*r*pi:.6f}")
| 5 | 4 | 131 | 78 | import math
n = float(eval(input()))
area = "%.6f" % float(n**2 * math.pi)
circ = "%.6f" % float(n * 2 * math.pi)
print((area, circ))
| pi = 3.14159265359
r = float(eval(input()))
print(f"{r*r*pi:.6f} {2*r*pi:.6f}")
| false | 20 | [
"-import math",
"-",
"-n = float(eval(input()))",
"-area = \"%.6f\" % float(n**2 * math.pi)",
"-circ = \"%.6f\" % float(n * 2 * math.pi)",
"-print((area, circ))",
"+pi = 3.14159265359",
"+r = float(eval(input()))",
"+print(f\"{r*r*pi:.6f} {2*r*pi:.6f}\")"
] | false | 0.035914 | 0.0364 | 0.986664 | [
"s478310197",
"s747908439"
] |
u463068683 | p03478 | python | s037490493 | s695148664 | 42 | 35 | 9,056 | 9,084 | Accepted | Accepted | 16.67 | n,a,b = list(map(int, input().split()))
ans = 0
for i in range(n):
s = str(i+1)
tmp = 0
for j in s:
tmp += int(j)
ans += i+1 if a <= tmp <= b else 0
print(ans) | n,a,b = list(map(int, input().split()))
ans = 0
for i in range(n):
s = i+1
tmp = 0
while s > 0:
tmp += s%10
s = s//10
ans += i+1 if a <= tmp <= b else 0
print(ans) | 9 | 10 | 173 | 182 | n, a, b = list(map(int, input().split()))
ans = 0
for i in range(n):
s = str(i + 1)
tmp = 0
for j in s:
tmp += int(j)
ans += i + 1 if a <= tmp <= b else 0
print(ans)
| n, a, b = list(map(int, input().split()))
ans = 0
for i in range(n):
s = i + 1
tmp = 0
while s > 0:
tmp += s % 10
s = s // 10
ans += i + 1 if a <= tmp <= b else 0
print(ans)
| false | 10 | [
"- s = str(i + 1)",
"+ s = i + 1",
"- for j in s:",
"- tmp += int(j)",
"+ while s > 0:",
"+ tmp += s % 10",
"+ s = s // 10"
] | false | 0.049048 | 0.114515 | 0.428317 | [
"s037490493",
"s695148664"
] |
u580607517 | p02258 | python | s610904854 | s653169748 | 1,590 | 1,470 | 10,404 | 16,768 | Accepted | Accepted | 7.55 | R = [0 for i in range(0,200000)]
n = int(input())
for i in range(n):
R[i] = int(eval(input()))
maxv = -2000000000
minv = R[0]
for j in range(1, n):
maxv = max(maxv, R[j]-minv)
minv = min(minv, R[j])
print(maxv) | n = int(input())
R = [eval(input()) for i in range(n)]
maxv = -2000000000
minv = R[0]
for j in range(1, n):
maxv = max(maxv, R[j]-minv)
minv = min(minv, R[j])
print(maxv) | 10 | 8 | 224 | 178 | R = [0 for i in range(0, 200000)]
n = int(input())
for i in range(n):
R[i] = int(eval(input()))
maxv = -2000000000
minv = R[0]
for j in range(1, n):
maxv = max(maxv, R[j] - minv)
minv = min(minv, R[j])
print(maxv)
| n = int(input())
R = [eval(input()) for i in range(n)]
maxv = -2000000000
minv = R[0]
for j in range(1, n):
maxv = max(maxv, R[j] - minv)
minv = min(minv, R[j])
print(maxv)
| false | 20 | [
"-R = [0 for i in range(0, 200000)]",
"-for i in range(n):",
"- R[i] = int(eval(input()))",
"+R = [eval(input()) for i in range(n)]"
] | false | 0.049601 | 0.045917 | 1.08025 | [
"s610904854",
"s653169748"
] |
u644516473 | p02762 | python | s587630781 | s023809765 | 807 | 724 | 79,824 | 90,716 | Accepted | Accepted | 10.29 | import sys
from collections import deque
readline = sys.stdin.readline
n, m, k = list(map(int, readline().split()))
friend = [set() for i in range(n)]
not_friend = [set() for i in range(n)]
for i in range(m):
a, b = list(map(int, readline().split()))
a -= 1
b -= 1
friend[a].add(b)
friend[b].add(a)
for i in range(k):
c, d = list(map(int, readline().split()))
c -= 1
d -= 1
not_friend[c].add(d)
not_friend[d].add(c)
suggest_friends = [-1] * n
for i in range(n):
if suggest_friends[i] != -1:
continue
q = deque(friend[i])
friend_group = set(friend[i])
while q:
p = q.popleft()
for f in friend[p]:
if not(f in friend_group):
q.append(f)
friend_group.add(f)
num = len(friend_group)
for f in friend_group:
suggest_friends[f] = num - 1 - len(friend[f] | not_friend[f] & friend_group)
for i in range(n):
if suggest_friends[i] == -1:
suggest_friends[i] = 0
print((*suggest_friends))
| import sys
class UnionFind():
def __init__(self, n):
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
return True
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
readline = sys.stdin.readline
n, m, k = list(map(int, readline().split()))
ab = tuple(tuple(map(int, readline().split())) for i in range(m))
cd = (list(map(int, readline().split())) for i in range(k))
friend_group = UnionFind(n)
for a, b in ab:
friend_group.union(a-1, b-1)
ans = [friend_group.size(i) - 1 for i in range(n)]
for a, b in ab:
ans[a-1] -= 1
ans[b-1] -= 1
for c, d in cd:
if friend_group.same(c-1, d-1):
ans[c-1] -= 1
ans[d-1] -= 1
print((*ans))
| 41 | 53 | 1,052 | 1,231 | import sys
from collections import deque
readline = sys.stdin.readline
n, m, k = list(map(int, readline().split()))
friend = [set() for i in range(n)]
not_friend = [set() for i in range(n)]
for i in range(m):
a, b = list(map(int, readline().split()))
a -= 1
b -= 1
friend[a].add(b)
friend[b].add(a)
for i in range(k):
c, d = list(map(int, readline().split()))
c -= 1
d -= 1
not_friend[c].add(d)
not_friend[d].add(c)
suggest_friends = [-1] * n
for i in range(n):
if suggest_friends[i] != -1:
continue
q = deque(friend[i])
friend_group = set(friend[i])
while q:
p = q.popleft()
for f in friend[p]:
if not (f in friend_group):
q.append(f)
friend_group.add(f)
num = len(friend_group)
for f in friend_group:
suggest_friends[f] = num - 1 - len(friend[f] | not_friend[f] & friend_group)
for i in range(n):
if suggest_friends[i] == -1:
suggest_friends[i] = 0
print((*suggest_friends))
| import sys
class UnionFind:
def __init__(self, n):
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
return True
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
readline = sys.stdin.readline
n, m, k = list(map(int, readline().split()))
ab = tuple(tuple(map(int, readline().split())) for i in range(m))
cd = (list(map(int, readline().split())) for i in range(k))
friend_group = UnionFind(n)
for a, b in ab:
friend_group.union(a - 1, b - 1)
ans = [friend_group.size(i) - 1 for i in range(n)]
for a, b in ab:
ans[a - 1] -= 1
ans[b - 1] -= 1
for c, d in cd:
if friend_group.same(c - 1, d - 1):
ans[c - 1] -= 1
ans[d - 1] -= 1
print((*ans))
| false | 22.641509 | [
"-from collections import deque",
"+",
"+",
"+class UnionFind:",
"+ def __init__(self, n):",
"+ self.parents = [-1] * n",
"+",
"+ def find(self, x):",
"+ if self.parents[x] < 0:",
"+ return x",
"+ else:",
"+ self.parents[x] = self.find(self.pare... | false | 0.048501 | 0.048639 | 0.997166 | [
"s587630781",
"s023809765"
] |
u404678206 | p02711 | python | s211843564 | s895175423 | 23 | 20 | 9,096 | 8,952 | Accepted | Accepted | 13.04 | n=eval(input())
print(('Yes' if '7' in n else 'No')) | print(('Yes' if '7' in eval(input()) else 'No')) | 2 | 1 | 45 | 40 | n = eval(input())
print(("Yes" if "7" in n else "No"))
| print(("Yes" if "7" in eval(input()) else "No"))
| false | 50 | [
"-n = eval(input())",
"-print((\"Yes\" if \"7\" in n else \"No\"))",
"+print((\"Yes\" if \"7\" in eval(input()) else \"No\"))"
] | false | 0.044377 | 0.093788 | 0.473158 | [
"s211843564",
"s895175423"
] |
u729133443 | p03987 | python | s373096848 | s421452763 | 1,259 | 980 | 25,884 | 101,564 | Accepted | Accepted | 22.16 | import bisect
class BTreeNode:
def __init__(self):
self.key = []
self.child = []
class BTree:
def __init__(self):
self.root = BTreeNode()
def search_higher(self, key):
ptr = self.root
ret = None
while ptr.child:
i = bisect.bisect_right(ptr.key, key)
if i != len(ptr.key):
ret = ptr.key[i]
ptr = ptr.child[i]
i = bisect.bisect_right(ptr.key, key)
if i != len(ptr.key):
ret = ptr.key[i]
return ret
def search_lower(self, key):
ptr = self.root
ret = None
while ptr.child:
i = bisect.bisect_left(ptr.key, key)
if i != 0:
ret = ptr.key[i - 1]
ptr = ptr.child[i]
i = bisect.bisect_left(ptr.key, key)
if i != 0:
ret = ptr.key[i - 1]
return ret
def insert(self, key):
def insert_rec(ptr):
b_size = 512
if not ptr.child:
bisect.insort(ptr.key, key)
if len(ptr.key) == b_size * 2 - 1:
ret = BTreeNode()
ret.key = ptr.key[:b_size]
ptr.key = ptr.key[b_size:]
return ret
else:
i = bisect.bisect(ptr.key, key)
temp = insert_rec(ptr.child[i])
if temp is not None:
ptr.key.insert(i, temp.key.pop(-1))
ptr.child.insert(i, temp)
if len(ptr.child) == b_size * 2:
ret = BTreeNode()
ret.child = ptr.child[:b_size]
ptr.child = ptr.child[b_size:]
ret.key = ptr.key[:b_size]
ptr.key = ptr.key[b_size:]
return ret
return None
temp = insert_rec(self.root)
if temp is not None:
root = BTreeNode()
root.key = [temp.key.pop(-1)]
root.child = [temp, self.root]
self.root = root
def dump(self):
def dump_rec(ptr, dep):
for _ in range(0, dep):
print(" ", end="")
print(ptr.key)
for c in ptr.child:
dump_rec(c, dep + 1)
dump_rec(self.root, 0)
print("")
def main():
n,*a=map(int,open(0).read().split())
l=[0]*n
for i,v in enumerate(a,1):l[v-1]=i
t=BTree()
t.insert(0)
t.insert(n+1)
c=0
for i,v in enumerate(l,1):
c+=(t.search_higher(v)-v)*(v-t.search_lower(v))*i
t.insert(v)
print(c)
main()
| from bisect import*
class BTreeNode:
def __init__(self):self.key,self.child=[],[]
class BTree:
def __init__(self):self.root=BTreeNode()
def search_higher(self,key):
ptr=self.root
ret=None
while ptr.child:
i=bisect(ptr.key,key)
if i!=len(ptr.key):ret=ptr.key[i]
ptr=ptr.child[i]
i=bisect(ptr.key,key)
if i!=len(ptr.key):ret=ptr.key[i]
return ret
def search_lower(self,key):
ptr=self.root
ret=None
while ptr.child:
i=bisect_left(ptr.key,key)
if i:ret=ptr.key[i-1]
ptr=ptr.child[i]
i=bisect_left(ptr.key,key)
if i:ret=ptr.key[i-1]
return ret
def insert(self,key):
def insert_rec(ptr,key):
b_size=512
if not ptr.child:
insort(ptr.key,key)
if len(ptr.key)==b_size*2-1:
ret=BTreeNode()
ret.key=ptr.key[:b_size]
ptr.key=ptr.key[b_size:]
return ret
else:
i=bisect(ptr.key,key)
tmp=insert_rec(ptr.child[i],key)
if tmp:
ptr.key.insert(i,tmp.key.pop())
ptr.child.insert(i,tmp)
if len(ptr.child)==b_size*2:
ret=BTreeNode()
ret.child=ptr.child[:b_size]
ptr.child=ptr.child[b_size:]
ret.key=ptr.key[:b_size]
ptr.key=ptr.key[b_size:]
return ret
return None
tmp=insert_rec(self.root,key)
if tmp:
root=BTreeNode()
root.key=[tmp.key.pop()]
root.child=[tmp,self.root]
self.root=root
def main():
n,*a=list(map(int,open(0).read().split()))
l=[0]*n
for i,v in enumerate(a,1):l[v-1]=i
t=BTree()
t.insert(0)
t.insert(n+1)
c=0
for i,v in enumerate(l,1):
c+=(t.search_higher(v)-v)*(v-t.search_lower(v))*i
t.insert(v)
print(c)
main() | 94 | 68 | 2,776 | 2,195 | import bisect
class BTreeNode:
def __init__(self):
self.key = []
self.child = []
class BTree:
def __init__(self):
self.root = BTreeNode()
def search_higher(self, key):
ptr = self.root
ret = None
while ptr.child:
i = bisect.bisect_right(ptr.key, key)
if i != len(ptr.key):
ret = ptr.key[i]
ptr = ptr.child[i]
i = bisect.bisect_right(ptr.key, key)
if i != len(ptr.key):
ret = ptr.key[i]
return ret
def search_lower(self, key):
ptr = self.root
ret = None
while ptr.child:
i = bisect.bisect_left(ptr.key, key)
if i != 0:
ret = ptr.key[i - 1]
ptr = ptr.child[i]
i = bisect.bisect_left(ptr.key, key)
if i != 0:
ret = ptr.key[i - 1]
return ret
def insert(self, key):
def insert_rec(ptr):
b_size = 512
if not ptr.child:
bisect.insort(ptr.key, key)
if len(ptr.key) == b_size * 2 - 1:
ret = BTreeNode()
ret.key = ptr.key[:b_size]
ptr.key = ptr.key[b_size:]
return ret
else:
i = bisect.bisect(ptr.key, key)
temp = insert_rec(ptr.child[i])
if temp is not None:
ptr.key.insert(i, temp.key.pop(-1))
ptr.child.insert(i, temp)
if len(ptr.child) == b_size * 2:
ret = BTreeNode()
ret.child = ptr.child[:b_size]
ptr.child = ptr.child[b_size:]
ret.key = ptr.key[:b_size]
ptr.key = ptr.key[b_size:]
return ret
return None
temp = insert_rec(self.root)
if temp is not None:
root = BTreeNode()
root.key = [temp.key.pop(-1)]
root.child = [temp, self.root]
self.root = root
def dump(self):
def dump_rec(ptr, dep):
for _ in range(0, dep):
print(" ", end="")
print(ptr.key)
for c in ptr.child:
dump_rec(c, dep + 1)
dump_rec(self.root, 0)
print("")
def main():
n, *a = map(int, open(0).read().split())
l = [0] * n
for i, v in enumerate(a, 1):
l[v - 1] = i
t = BTree()
t.insert(0)
t.insert(n + 1)
c = 0
for i, v in enumerate(l, 1):
c += (t.search_higher(v) - v) * (v - t.search_lower(v)) * i
t.insert(v)
print(c)
main()
| from bisect import *
class BTreeNode:
def __init__(self):
self.key, self.child = [], []
class BTree:
def __init__(self):
self.root = BTreeNode()
def search_higher(self, key):
ptr = self.root
ret = None
while ptr.child:
i = bisect(ptr.key, key)
if i != len(ptr.key):
ret = ptr.key[i]
ptr = ptr.child[i]
i = bisect(ptr.key, key)
if i != len(ptr.key):
ret = ptr.key[i]
return ret
def search_lower(self, key):
ptr = self.root
ret = None
while ptr.child:
i = bisect_left(ptr.key, key)
if i:
ret = ptr.key[i - 1]
ptr = ptr.child[i]
i = bisect_left(ptr.key, key)
if i:
ret = ptr.key[i - 1]
return ret
def insert(self, key):
def insert_rec(ptr, key):
b_size = 512
if not ptr.child:
insort(ptr.key, key)
if len(ptr.key) == b_size * 2 - 1:
ret = BTreeNode()
ret.key = ptr.key[:b_size]
ptr.key = ptr.key[b_size:]
return ret
else:
i = bisect(ptr.key, key)
tmp = insert_rec(ptr.child[i], key)
if tmp:
ptr.key.insert(i, tmp.key.pop())
ptr.child.insert(i, tmp)
if len(ptr.child) == b_size * 2:
ret = BTreeNode()
ret.child = ptr.child[:b_size]
ptr.child = ptr.child[b_size:]
ret.key = ptr.key[:b_size]
ptr.key = ptr.key[b_size:]
return ret
return None
tmp = insert_rec(self.root, key)
if tmp:
root = BTreeNode()
root.key = [tmp.key.pop()]
root.child = [tmp, self.root]
self.root = root
def main():
n, *a = list(map(int, open(0).read().split()))
l = [0] * n
for i, v in enumerate(a, 1):
l[v - 1] = i
t = BTree()
t.insert(0)
t.insert(n + 1)
c = 0
for i, v in enumerate(l, 1):
c += (t.search_higher(v) - v) * (v - t.search_lower(v)) * i
t.insert(v)
print(c)
main()
| false | 27.659574 | [
"-import bisect",
"+from bisect import *",
"- self.key = []",
"- self.child = []",
"+ self.key, self.child = [], []",
"- i = bisect.bisect_right(ptr.key, key)",
"+ i = bisect(ptr.key, key)",
"- i = bisect.bisect_right(ptr.key, key)",
"+ i = bi... | false | 0.036944 | 0.037905 | 0.974633 | [
"s373096848",
"s421452763"
] |
u222668979 | p03593 | python | s455937380 | s394536508 | 33 | 30 | 9,396 | 9,464 | Accepted | Accepted | 9.09 | from collections import Counter
h, w = list(map(int, input().split()))
a = Counter(''.join(eval(input()) for _ in range(h)))
center = h * w % 2
side = (h // 2) * (w % 2) + (w // 2) * (h % 2)
cnt = 0
for i in a:
if a[i] % 2 == 1:
a[i] -= 1
cnt += 1
if cnt != center:
print('No')
exit()
cnt = 0
for i in a:
if a[i] % 4 == 2:
a[i] -= 2
cnt += 1
if cnt > side:
print('No')
exit()
print(('Yes' if sum(a[i] % 4 for i in a) == 0 else 'No'))
| from collections import Counter
h, w = list(map(int, input().split()))
a = Counter(''.join(eval(input()) for _ in range(h)))
center = h * w % 2
side = (h // 2) * (w % 2) + (w // 2) * (h % 2)
cnt = 0
for i in a:
if a[i] % 2 == 1:
a[i] -= 1
cnt += 1
if cnt != center:
print('No')
exit()
print(('Yes' if sum(a[i] % 4 == 2 for i in a) <= side else 'No'))
| 27 | 18 | 507 | 386 | from collections import Counter
h, w = list(map(int, input().split()))
a = Counter("".join(eval(input()) for _ in range(h)))
center = h * w % 2
side = (h // 2) * (w % 2) + (w // 2) * (h % 2)
cnt = 0
for i in a:
if a[i] % 2 == 1:
a[i] -= 1
cnt += 1
if cnt != center:
print("No")
exit()
cnt = 0
for i in a:
if a[i] % 4 == 2:
a[i] -= 2
cnt += 1
if cnt > side:
print("No")
exit()
print(("Yes" if sum(a[i] % 4 for i in a) == 0 else "No"))
| from collections import Counter
h, w = list(map(int, input().split()))
a = Counter("".join(eval(input()) for _ in range(h)))
center = h * w % 2
side = (h // 2) * (w % 2) + (w // 2) * (h % 2)
cnt = 0
for i in a:
if a[i] % 2 == 1:
a[i] -= 1
cnt += 1
if cnt != center:
print("No")
exit()
print(("Yes" if sum(a[i] % 4 == 2 for i in a) <= side else "No"))
| false | 33.333333 | [
"-cnt = 0",
"-for i in a:",
"- if a[i] % 4 == 2:",
"- a[i] -= 2",
"- cnt += 1",
"-if cnt > side:",
"- print(\"No\")",
"- exit()",
"-print((\"Yes\" if sum(a[i] % 4 for i in a) == 0 else \"No\"))",
"+print((\"Yes\" if sum(a[i] % 4 == 2 for i in a) <= side else \"No\"))"
] | false | 0.046109 | 0.045791 | 1.00694 | [
"s455937380",
"s394536508"
] |
u467736898 | p02822 | python | s273071945 | s709377118 | 1,390 | 556 | 87,672 | 79,712 | Accepted | Accepted | 60 | import os
import sys
import numpy as np
def solve(N, AB):
mod = 10**9+7
half = mod // 2 + 1
G = [[0]*0 for _ in range(N+1)]
for i in range(len(AB)):
a, b = AB[i]
G[a].append(b)
G[b].append(a)
P = [0] * (N+1)
Size = [0] * (N+1)
def dfs(v):
# siz = 1
# p = P[v]
# for u in G[v]:
# if u != p:
# P[u] = v
# dfs(u)
# siz += Size[u]
# Size[v] = siz
st = [(v, 0)]
while st:
v, state = st.pop()
p = P[v]
if state == 0:
st.append((v, 1))
Size[v] = 1
for u in G[v]:
if u != p:
P[u] = v
st.append((u, 0))
else:
Size[p] += Size[v]
dfs(1)
ans = 0
Prob = [0]
h = 1
for i in range(202020):
h = h * half % mod
Prob.append(1-h)
for v in range(1, len(G)):
siz_v = Size[v]
Gv = G[v]
if v == 1:
ps = [0]*0
else:
ps = [Prob[N-siz_v]]
par = P[v]
for u in Gv:
if par != u:
siz_u = Size[u]
ps.append(Prob[siz_u])
if len(ps)<=1:
continue
cumprod1_ps = [1, 1]
cumprod2_ps = [1, 1]
cp = 1
for p in ps:
cp = cp * (1-p) % mod
cumprod1_ps.append(cp)
cp = 1
for p in ps[::-1]:
cp = cp * (1-p) % mod
cumprod2_ps.append(cp)
cumprod2_ps.reverse()
an = 1 - cumprod1_ps[-1]
for j in range(1, len(cumprod1_ps)-1):
cp1 = cumprod1_ps[j]
cp2 = cumprod2_ps[j]
p = ps[j-1]
an -= cp1 * cp2 % mod * p
ans += an
ans = ans % mod * half % mod
return ans
def main():
sys.setrecursionlimit(505050)
input = sys.stdin.buffer.readline
N = int(eval(input()))
AB = np.array(sys.stdin.buffer.read().split(), dtype=np.int64).reshape(N - 1, 2)
ans = solve(N, AB)
print(ans)
main()
| import os
import sys
import numpy as np
def solve(N, AB):
mod = 10**9+7
half = mod // 2 + 1
G = [[0]*0 for _ in range(N+1)]
for i in range(len(AB)):
a, b = AB[i]
G[a].append(b)
G[b].append(a)
P = np.zeros(N+1, dtype=np.int64)
Size = np.zeros(N+1, dtype=np.int64)
def dfs(v):
# siz = 1
# p = P[v]
# for u in G[v]:
# if u != p:
# P[u] = v
# dfs(u)
# siz += Size[u]
# Size[v] = siz
st = [(v, 0)]
while st:
v, state = st.pop()
p = P[v]
if state == 0:
st.append((v, 1))
Size[v] = 1
for u in G[v]:
if u != p:
P[u] = v
st.append((u, 0))
else:
Size[p] += Size[v]
dfs(1)
ans = 0
Prob = np.empty(202020, dtype=np.int64)
h = 1
for i in range(202020):
Prob[i] = 1-h+mod
h = h * half % mod
for v in range(1, len(G)):
siz_v = Size[v]
Gv = G[v]
if v == 1:
ps = [0]*0
else:
ps = [Prob[N-siz_v]]
par = P[v]
for u in Gv:
if par != u:
siz_u = Size[u]
ps.append(Prob[siz_u])
if len(ps)<=1:
continue
cumprod1_ps = [1, 1]
cumprod2_ps = [1, 1]
cp = 1
for p in ps:
cp = cp * (1-p+mod) % mod
cumprod1_ps.append(cp)
cp = 1
for p in ps[::-1]:
cp = cp * (1-p+mod) % mod
cumprod2_ps.append(cp)
cumprod2_ps.reverse()
an = 1 - cumprod1_ps[-1]
for j in range(1, len(cumprod1_ps)-1):
cp1 = cumprod1_ps[j]
cp2 = cumprod2_ps[j]
p = ps[j-1]
an -= cp1 * cp2 % mod * p % mod
ans += an
ans = ans % mod * half % mod
return ans
# >>> numba compile >>>
numba_config = [
[solve, "i8(i8,i8[:,:])"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
vars()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
from numba import njit
for func, signature in numba_config:
vars()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
# <<< numba compile <<<
def main():
sys.setrecursionlimit(505050)
input = sys.stdin.buffer.readline
N = int(input())
AB = np.array(sys.stdin.buffer.read().split(), dtype=np.int64).reshape(N - 1, 2)
ans = solve(N, AB)
print(ans)
main()
| 88 | 111 | 2,233 | 3,020 | import os
import sys
import numpy as np
def solve(N, AB):
mod = 10**9 + 7
half = mod // 2 + 1
G = [[0] * 0 for _ in range(N + 1)]
for i in range(len(AB)):
a, b = AB[i]
G[a].append(b)
G[b].append(a)
P = [0] * (N + 1)
Size = [0] * (N + 1)
def dfs(v):
# siz = 1
# p = P[v]
# for u in G[v]:
# if u != p:
# P[u] = v
# dfs(u)
# siz += Size[u]
# Size[v] = siz
st = [(v, 0)]
while st:
v, state = st.pop()
p = P[v]
if state == 0:
st.append((v, 1))
Size[v] = 1
for u in G[v]:
if u != p:
P[u] = v
st.append((u, 0))
else:
Size[p] += Size[v]
dfs(1)
ans = 0
Prob = [0]
h = 1
for i in range(202020):
h = h * half % mod
Prob.append(1 - h)
for v in range(1, len(G)):
siz_v = Size[v]
Gv = G[v]
if v == 1:
ps = [0] * 0
else:
ps = [Prob[N - siz_v]]
par = P[v]
for u in Gv:
if par != u:
siz_u = Size[u]
ps.append(Prob[siz_u])
if len(ps) <= 1:
continue
cumprod1_ps = [1, 1]
cumprod2_ps = [1, 1]
cp = 1
for p in ps:
cp = cp * (1 - p) % mod
cumprod1_ps.append(cp)
cp = 1
for p in ps[::-1]:
cp = cp * (1 - p) % mod
cumprod2_ps.append(cp)
cumprod2_ps.reverse()
an = 1 - cumprod1_ps[-1]
for j in range(1, len(cumprod1_ps) - 1):
cp1 = cumprod1_ps[j]
cp2 = cumprod2_ps[j]
p = ps[j - 1]
an -= cp1 * cp2 % mod * p
ans += an
ans = ans % mod * half % mod
return ans
def main():
sys.setrecursionlimit(505050)
input = sys.stdin.buffer.readline
N = int(eval(input()))
AB = np.array(sys.stdin.buffer.read().split(), dtype=np.int64).reshape(N - 1, 2)
ans = solve(N, AB)
print(ans)
main()
| import os
import sys
import numpy as np
def solve(N, AB):
mod = 10**9 + 7
half = mod // 2 + 1
G = [[0] * 0 for _ in range(N + 1)]
for i in range(len(AB)):
a, b = AB[i]
G[a].append(b)
G[b].append(a)
P = np.zeros(N + 1, dtype=np.int64)
Size = np.zeros(N + 1, dtype=np.int64)
def dfs(v):
# siz = 1
# p = P[v]
# for u in G[v]:
# if u != p:
# P[u] = v
# dfs(u)
# siz += Size[u]
# Size[v] = siz
st = [(v, 0)]
while st:
v, state = st.pop()
p = P[v]
if state == 0:
st.append((v, 1))
Size[v] = 1
for u in G[v]:
if u != p:
P[u] = v
st.append((u, 0))
else:
Size[p] += Size[v]
dfs(1)
ans = 0
Prob = np.empty(202020, dtype=np.int64)
h = 1
for i in range(202020):
Prob[i] = 1 - h + mod
h = h * half % mod
for v in range(1, len(G)):
siz_v = Size[v]
Gv = G[v]
if v == 1:
ps = [0] * 0
else:
ps = [Prob[N - siz_v]]
par = P[v]
for u in Gv:
if par != u:
siz_u = Size[u]
ps.append(Prob[siz_u])
if len(ps) <= 1:
continue
cumprod1_ps = [1, 1]
cumprod2_ps = [1, 1]
cp = 1
for p in ps:
cp = cp * (1 - p + mod) % mod
cumprod1_ps.append(cp)
cp = 1
for p in ps[::-1]:
cp = cp * (1 - p + mod) % mod
cumprod2_ps.append(cp)
cumprod2_ps.reverse()
an = 1 - cumprod1_ps[-1]
for j in range(1, len(cumprod1_ps) - 1):
cp1 = cumprod1_ps[j]
cp2 = cumprod2_ps[j]
p = ps[j - 1]
an -= cp1 * cp2 % mod * p % mod
ans += an
ans = ans % mod * half % mod
return ans
# >>> numba compile >>>
numba_config = [
[solve, "i8(i8,i8[:,:])"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
vars()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
from numba import njit
for func, signature in numba_config:
vars()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
# <<< numba compile <<<
def main():
sys.setrecursionlimit(505050)
input = sys.stdin.buffer.readline
N = int(input())
AB = np.array(sys.stdin.buffer.read().split(), dtype=np.int64).reshape(N - 1, 2)
ans = solve(N, AB)
print(ans)
main()
| false | 20.720721 | [
"- P = [0] * (N + 1)",
"- Size = [0] * (N + 1)",
"+ P = np.zeros(N + 1, dtype=np.int64)",
"+ Size = np.zeros(N + 1, dtype=np.int64)",
"- Prob = [0]",
"+ Prob = np.empty(202020, dtype=np.int64)",
"+ Prob[i] = 1 - h + mod",
"- Prob.append(1 - h)",
"- cp = cp ... | false | 0.293171 | 0.226008 | 1.29717 | [
"s273071945",
"s709377118"
] |
u367130284 | p03775 | python | s820638415 | s504137258 | 186 | 31 | 39,024 | 3,064 | Accepted | Accepted | 83.33 | import math
n=int(eval(input()))
l=[]
for i in range(1,int(math.sqrt(n))+2):
if n%i==0:
l+=[max(len(str(i)),len(str(n//i)))]
print((min(l))) | n=int(eval(input()))
l=[]
for i in range(1,int(n**0.5)+3):
if n%i==0:
l.append(max(len(str(i)),len(str(n//i))))
print((min(l))) | 7 | 6 | 150 | 136 | import math
n = int(eval(input()))
l = []
for i in range(1, int(math.sqrt(n)) + 2):
if n % i == 0:
l += [max(len(str(i)), len(str(n // i)))]
print((min(l)))
| n = int(eval(input()))
l = []
for i in range(1, int(n**0.5) + 3):
if n % i == 0:
l.append(max(len(str(i)), len(str(n // i))))
print((min(l)))
| false | 14.285714 | [
"-import math",
"-",
"-for i in range(1, int(math.sqrt(n)) + 2):",
"+for i in range(1, int(n**0.5) + 3):",
"- l += [max(len(str(i)), len(str(n // i)))]",
"+ l.append(max(len(str(i)), len(str(n // i))))"
] | false | 0.122639 | 0.040889 | 2.999333 | [
"s820638415",
"s504137258"
] |
u933096856 | p02418 | python | s219148017 | s432193246 | 50 | 20 | 7,556 | 7,580 | Accepted | Accepted | 60 | s,p=[eval(input()) for i in range(2)]
s=s*3
if p in s:
print('Yes')
else:
print('No') | s,p=[eval(input()) for i in range(2)]
s=s*2
if p in s:
print('Yes')
else:
print('No') | 6 | 6 | 92 | 92 | s, p = [eval(input()) for i in range(2)]
s = s * 3
if p in s:
print("Yes")
else:
print("No")
| s, p = [eval(input()) for i in range(2)]
s = s * 2
if p in s:
print("Yes")
else:
print("No")
| false | 0 | [
"-s = s * 3",
"+s = s * 2"
] | false | 0.110831 | 0.043207 | 2.565094 | [
"s219148017",
"s432193246"
] |
u046187684 | p03045 | python | s694772408 | s718072844 | 398 | 327 | 44,704 | 34,872 | Accepted | Accepted | 17.84 | from scipy.sparse import csr_matrix as csr
from scipy.sparse.csgraph import connected_components as cc
def solve(string):
n, m, *xyz = list(map(int, string.split()))
return str(cc(csr(([1] * m, (xyz[::3], xyz[1::3])), shape=(n + 1, n + 1)))[0] - 1)
if __name__ == '__main__':
n, m = list(map(int, input().split()))
print((solve('{} {}\n'.format(n, m) + '\n'.join([eval(input()) for _ in range(m)])))) | def solve(string):
n, m, *xyz = list(map(int, string.split()))
t = [-1] * (n + 1)
for x, y, z in zip(*[iter(xyz)] * 3):
def union(r1, r2):
new_root = min(r1, r2)
if r1 != r2:
t[max(r1, r2)] = new_root
def find(x):
if t[x] < 0:
return x
t[x] = find(t[x])
return t[x]
union(find(x), find(y))
return str(t[1:].count(-1))
if __name__ == '__main__':
n, m = list(map(int, input().split()))
print((solve('{} {}\n'.format(n, m) + '\n'.join([eval(input()) for _ in range(m)]))))
| 12 | 23 | 411 | 617 | from scipy.sparse import csr_matrix as csr
from scipy.sparse.csgraph import connected_components as cc
def solve(string):
n, m, *xyz = list(map(int, string.split()))
return str(cc(csr(([1] * m, (xyz[::3], xyz[1::3])), shape=(n + 1, n + 1)))[0] - 1)
if __name__ == "__main__":
n, m = list(map(int, input().split()))
print(
(solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(m)])))
)
| def solve(string):
n, m, *xyz = list(map(int, string.split()))
t = [-1] * (n + 1)
for x, y, z in zip(*[iter(xyz)] * 3):
def union(r1, r2):
new_root = min(r1, r2)
if r1 != r2:
t[max(r1, r2)] = new_root
def find(x):
if t[x] < 0:
return x
t[x] = find(t[x])
return t[x]
union(find(x), find(y))
return str(t[1:].count(-1))
if __name__ == "__main__":
n, m = list(map(int, input().split()))
print(
(solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(m)])))
)
| false | 47.826087 | [
"-from scipy.sparse import csr_matrix as csr",
"-from scipy.sparse.csgraph import connected_components as cc",
"-",
"-",
"- return str(cc(csr(([1] * m, (xyz[::3], xyz[1::3])), shape=(n + 1, n + 1)))[0] - 1)",
"+ t = [-1] * (n + 1)",
"+ for x, y, z in zip(*[iter(xyz)] * 3):",
"+",
"+ ... | false | 0.257289 | 0.037107 | 6.933738 | [
"s694772408",
"s718072844"
] |
u888092736 | p02716 | python | s233953995 | s237649854 | 690 | 599 | 58,312 | 58,476 | Accepted | Accepted | 13.19 | n = int(eval(input()))
A = list(map(int, input().split()))
inf = 10 ** 18
dp = [[-inf] * 3 for _ in range(n + 1)]
k = 1 + n % 2
dp[0][0] = 0
for i in range(n):
for j in range(k + 1):
if j < k:
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j])
now = dp[i][j]
if (i + j) % 2 == 0:
now += A[i]
dp[i + 1][j] = max(dp[i + 1][j], now)
print((dp[n][k]))
| from math import inf
n = int(eval(input()))
A = list(map(int, input().split()))
dp = [[-inf] * 3 for _ in range(n + 1)]
k = 1 + n % 2
dp[0][0] = 0
for i in range(n):
for j in range(k + 1):
if j < k:
dp[i + 1][j + 1] = dp[i][j]
now = dp[i][j]
if (i + j) % 2 == 0:
now += A[i]
dp[i + 1][j] = max(dp[i + 1][j], now)
print((dp[n][k]))
| 17 | 18 | 419 | 404 | n = int(eval(input()))
A = list(map(int, input().split()))
inf = 10**18
dp = [[-inf] * 3 for _ in range(n + 1)]
k = 1 + n % 2
dp[0][0] = 0
for i in range(n):
for j in range(k + 1):
if j < k:
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j])
now = dp[i][j]
if (i + j) % 2 == 0:
now += A[i]
dp[i + 1][j] = max(dp[i + 1][j], now)
print((dp[n][k]))
| from math import inf
n = int(eval(input()))
A = list(map(int, input().split()))
dp = [[-inf] * 3 for _ in range(n + 1)]
k = 1 + n % 2
dp[0][0] = 0
for i in range(n):
for j in range(k + 1):
if j < k:
dp[i + 1][j + 1] = dp[i][j]
now = dp[i][j]
if (i + j) % 2 == 0:
now += A[i]
dp[i + 1][j] = max(dp[i + 1][j], now)
print((dp[n][k]))
| false | 5.555556 | [
"+from math import inf",
"+",
"-inf = 10**18",
"- dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j])",
"+ dp[i + 1][j + 1] = dp[i][j]"
] | false | 0.046454 | 0.04719 | 0.984394 | [
"s233953995",
"s237649854"
] |
u227550284 | p02688 | python | s710979962 | s288745709 | 23 | 21 | 9,096 | 9,208 | Accepted | Accepted | 8.7 | import sys
input = sys.stdin.readline
def main():
n, k = list(map(int, input().split()))
li = []
for i in range(k):
d = int(eval(input()))
a_li = list(map(int, input().split()))
li += a_li
print((n - len(set(li))))
if __name__ == '__main__':
main()
| n, k = list(map(int, input().split()))
li = []
for i in range(k):
d = int(eval(input()))
a_li = list(map(int, input().split()))
li += a_li
print((n - len(set(li))))
| 18 | 10 | 302 | 175 | import sys
input = sys.stdin.readline
def main():
n, k = list(map(int, input().split()))
li = []
for i in range(k):
d = int(eval(input()))
a_li = list(map(int, input().split()))
li += a_li
print((n - len(set(li))))
if __name__ == "__main__":
main()
| n, k = list(map(int, input().split()))
li = []
for i in range(k):
d = int(eval(input()))
a_li = list(map(int, input().split()))
li += a_li
print((n - len(set(li))))
| false | 44.444444 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-",
"-",
"-def main():",
"- n, k = list(map(int, input().split()))",
"- li = []",
"- for i in range(k):",
"- d = int(eval(input()))",
"- a_li = list(map(int, input().split()))",
"- li += a_li",
"- print((n -... | false | 0.041918 | 0.113928 | 0.36794 | [
"s710979962",
"s288745709"
] |
u119148115 | p03747 | python | s319647330 | s594937694 | 176 | 146 | 92,388 | 94,772 | Accepted | Accepted | 17.05 | import sys
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,L,T = MI()
q,r = T//L,T % L
A = []
a = 0 # 開始時点で、(時計回りの蟻の数)-(半時計まわりの蟻)
for i in range(N):
x,w = MI()
if w == 1:
a += 1
for j in range(-1,2):
A.append(x+r+j*L)
else:
a -= 1
for j in range(-1,2):
A.append(x-r+j*L)
A.sort()
ANS = [A[i] % L for i in range(N,2*N)]
for i in range(N):
print((ANS[(i+q*a) % N]))
| import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
N,L,T = MI()
q,r = T//L,T % L
A = []
a = 0 # 開始時点で、(時計回りの蟻の数)-(半時計まわりの蟻)
for i in range(N):
x,w = MI()
a += (-2)*w+3
for j in range(-1,2):
A.append(x+r*((-2)*w+3)+j*L)
A.sort()
print(*[A[N+(i+q*a)%N] % L for i in range(N)],sep='\n')
| 22 | 16 | 476 | 347 | import sys
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
N, L, T = MI()
q, r = T // L, T % L
A = []
a = 0 # 開始時点で、(時計回りの蟻の数)-(半時計まわりの蟻)
for i in range(N):
x, w = MI()
if w == 1:
a += 1
for j in range(-1, 2):
A.append(x + r + j * L)
else:
a -= 1
for j in range(-1, 2):
A.append(x - r + j * L)
A.sort()
ANS = [A[i] % L for i in range(N, 2 * N)]
for i in range(N):
print((ANS[(i + q * a) % N]))
| import sys
def MI():
return map(int, sys.stdin.readline().rstrip().split())
N, L, T = MI()
q, r = T // L, T % L
A = []
a = 0 # 開始時点で、(時計回りの蟻の数)-(半時計まわりの蟻)
for i in range(N):
x, w = MI()
a += (-2) * w + 3
for j in range(-1, 2):
A.append(x + r * ((-2) * w + 3) + j * L)
A.sort()
print(*[A[N + (i + q * a) % N] % L for i in range(N)], sep="\n")
| false | 27.272727 | [
"- return list(map(int, sys.stdin.readline().rstrip().split()))",
"+ return map(int, sys.stdin.readline().rstrip().split())",
"- if w == 1:",
"- a += 1",
"- for j in range(-1, 2):",
"- A.append(x + r + j * L)",
"- else:",
"- a -= 1",
"- for j in ran... | false | 0.071858 | 0.043688 | 1.64479 | [
"s319647330",
"s594937694"
] |
u380772254 | p03142 | python | s881359382 | s941831819 | 544 | 492 | 79,920 | 69,552 | Accepted | Accepted | 9.56 | import sys
def I(): return int(sys.stdin.readline())
def MI(): return list(map(int, sys.stdin.readline().split()))
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
N, M = MI()
nl = [list() for _ in range(N + 1)]
rev = [list() for _ in range(N + 1)]
deg = [0 for _ in range(N + 1)]
for _ in range(N - 1 + M):
A, B = MI()
nl[A].append(B)
rev[B].append(A)
deg[B] += 1
for i, l in enumerate(deg):
if i > 0 and l == 0:
root = i
break
stack = [root]
tsorted = list()
while len(stack) > 0:
v = stack.pop()
tsorted.append(v)
for next_v in nl[v]:
deg[next_v] -= 1
if deg[next_v] == 0:
stack.append(next_v)
ans = [0] * (N + 1)
p = {root: 0}
for v in tsorted:
ans[v] = p[v]
for next_v in nl[v]:
p[next_v] = v
for a in ans[1:]:
print(a) | import sys
def I(): return int(sys.stdin.readline())
def MI(): return list(map(int, sys.stdin.readline().split()))
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
# トポロジカルソート
# deg[i] := 頂点iの入次数
# returns := トポロジカルソートされた頂点番号のリスト
def tsort(deg, nl):
tsorted = list()
stack = [i for i, x in enumerate(deg) if x == 0]
while len(stack) > 0:
v = stack.pop()
tsorted.append(v)
for next_v in nl[v]:
deg[next_v] -= 1
if deg[next_v] == 0:
stack.append(next_v)
return tsorted
N, M = MI()
nl = [list() for _ in range(N)]
deg = [0 for _ in range(N)]
for _ in range(N - 1 + M):
A, B = MI()
A, B = A - 1, B - 1
nl[A].append(B)
deg[B] += 1
tsorted = tsort(deg, nl)
ans = [0] * N
p = {tsorted[0]: -1}
for v in tsorted:
ans[v] = p[v]
for next_v in nl[v]:
p[next_v] = v
for a in ans:
print((a + 1)) | 43 | 45 | 914 | 992 | import sys
def I():
return int(sys.stdin.readline())
def MI():
return list(map(int, sys.stdin.readline().split()))
def LMI():
return list(map(int, sys.stdin.readline().split()))
MOD = 10**9 + 7
INF = float("inf")
N, M = MI()
nl = [list() for _ in range(N + 1)]
rev = [list() for _ in range(N + 1)]
deg = [0 for _ in range(N + 1)]
for _ in range(N - 1 + M):
A, B = MI()
nl[A].append(B)
rev[B].append(A)
deg[B] += 1
for i, l in enumerate(deg):
if i > 0 and l == 0:
root = i
break
stack = [root]
tsorted = list()
while len(stack) > 0:
v = stack.pop()
tsorted.append(v)
for next_v in nl[v]:
deg[next_v] -= 1
if deg[next_v] == 0:
stack.append(next_v)
ans = [0] * (N + 1)
p = {root: 0}
for v in tsorted:
ans[v] = p[v]
for next_v in nl[v]:
p[next_v] = v
for a in ans[1:]:
print(a)
| import sys
def I():
return int(sys.stdin.readline())
def MI():
return list(map(int, sys.stdin.readline().split()))
def LMI():
return list(map(int, sys.stdin.readline().split()))
MOD = 10**9 + 7
INF = float("inf")
# トポロジカルソート
# deg[i] := 頂点iの入次数
# returns := トポロジカルソートされた頂点番号のリスト
def tsort(deg, nl):
tsorted = list()
stack = [i for i, x in enumerate(deg) if x == 0]
while len(stack) > 0:
v = stack.pop()
tsorted.append(v)
for next_v in nl[v]:
deg[next_v] -= 1
if deg[next_v] == 0:
stack.append(next_v)
return tsorted
N, M = MI()
nl = [list() for _ in range(N)]
deg = [0 for _ in range(N)]
for _ in range(N - 1 + M):
A, B = MI()
A, B = A - 1, B - 1
nl[A].append(B)
deg[B] += 1
tsorted = tsort(deg, nl)
ans = [0] * N
p = {tsorted[0]: -1}
for v in tsorted:
ans[v] = p[v]
for next_v in nl[v]:
p[next_v] = v
for a in ans:
print((a + 1))
| false | 4.444444 | [
"+# トポロジカルソート",
"+# deg[i] := 頂点iの入次数",
"+# returns := トポロジカルソートされた頂点番号のリスト",
"+def tsort(deg, nl):",
"+ tsorted = list()",
"+ stack = [i for i, x in enumerate(deg) if x == 0]",
"+ while len(stack) > 0:",
"+ v = stack.pop()",
"+ tsorted.append(v)",
"+ for next_v in nl... | false | 0.036924 | 0.037355 | 0.988474 | [
"s881359382",
"s941831819"
] |
u691018832 | p03031 | python | s919141965 | s308420946 | 47 | 31 | 3,188 | 3,064 | Accepted | Accepted | 34.04 | import sys
import itertools
input = sys.stdin.readline
n, m = list(map(int, input().split()))
s = []
p = [0] * m
cnt_k = 0
cnt_j = 0
ans = 0
for i in range(m):
s_k = list(map(int, input().split()))
s.append(s_k)
p = list(map(int, input().split()))
memo = list(itertools.product([0, 1], repeat=n))
for i in range(2 ** n):
for j in range(m):
for k in range(1, s[j][0] + 1):
if memo[i][s[j][k] - 1] == 1:
cnt_k += 1
if cnt_k % 2 == p[j]:
cnt_j += 1
cnt_k = 0
if cnt_j == m:
ans += 1
cnt_j = 0
print(ans)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from itertools import product
n, m = list(map(int, readline().split()))
ks = [list(map(int, readline().split()))[1:] for _ in range(m)]
p = list(map(int, readline().split()))
ans = 0
for bit in product([0, 1], repeat=n):
for pp, ksi in zip(p, ks):
cnt = 0
for j in range(n):
if bit[j] == 1 and (j + 1) in ksi:
cnt += 1
if cnt % 2 != pp:
break
else:
ans += 1
print(ans)
| 33 | 24 | 630 | 616 | import sys
import itertools
input = sys.stdin.readline
n, m = list(map(int, input().split()))
s = []
p = [0] * m
cnt_k = 0
cnt_j = 0
ans = 0
for i in range(m):
s_k = list(map(int, input().split()))
s.append(s_k)
p = list(map(int, input().split()))
memo = list(itertools.product([0, 1], repeat=n))
for i in range(2**n):
for j in range(m):
for k in range(1, s[j][0] + 1):
if memo[i][s[j][k] - 1] == 1:
cnt_k += 1
if cnt_k % 2 == p[j]:
cnt_j += 1
cnt_k = 0
if cnt_j == m:
ans += 1
cnt_j = 0
print(ans)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from itertools import product
n, m = list(map(int, readline().split()))
ks = [list(map(int, readline().split()))[1:] for _ in range(m)]
p = list(map(int, readline().split()))
ans = 0
for bit in product([0, 1], repeat=n):
for pp, ksi in zip(p, ks):
cnt = 0
for j in range(n):
if bit[j] == 1 and (j + 1) in ksi:
cnt += 1
if cnt % 2 != pp:
break
else:
ans += 1
print(ans)
| false | 27.272727 | [
"-import itertools",
"-input = sys.stdin.readline",
"-n, m = list(map(int, input().split()))",
"-s = []",
"-p = [0] * m",
"-cnt_k = 0",
"-cnt_j = 0",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+sys.setrecursionlimit(10**7... | false | 0.034464 | 0.037361 | 0.922478 | [
"s919141965",
"s308420946"
] |
u624689667 | p03164 | python | s994404373 | s883211853 | 1,140 | 712 | 312,648 | 176,708 | Accepted | Accepted | 37.54 | import collections
MAX_N = 110
MAX_V = 100100
Item = collections.namedtuple("Item", ("weight", "value"))
def main():
N, W = [int(i) for i in input().split()]
items = [Item(int(i), int(j)) for (i, j) in [input().split() for _ in range(N)]]
dp = [[float('inf')] * MAX_V for _ in range(MAX_N)]
dp[0][0] = 0
for i in range(N):
item = items[i]
for sum_v in range(MAX_V):
# i番目の品物を選ぶ
if sum_v - item.value >= 0:
dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v - item.value] + item.weight)
dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v])
ans = 0
for sum_v in range(MAX_V):
if dp[N][sum_v] <= W:
ans = sum_v
print(ans)
if __name__ == '__main__':
main() | import sys
import numpy as np
input = sys.stdin.readline
def main():
N, W = [int(i) for i in input().strip().split()]
MAX_V = 10**3 * N
dp = np.full([N + 1, MAX_V + 1], np.inf)
dp[0][0] = 0
for n in range(N):
w, v = [int(i) for i in input().strip().split()]
dp[n + 1] = dp[n]
dp[n + 1][v:] = np.minimum(dp[n][v:], dp[n][:-v] + w)
ans = np.max(np.where(dp <= W))
print(ans)
if __name__ == '__main__':
main() | 33 | 23 | 822 | 491 | import collections
MAX_N = 110
MAX_V = 100100
Item = collections.namedtuple("Item", ("weight", "value"))
def main():
N, W = [int(i) for i in input().split()]
items = [Item(int(i), int(j)) for (i, j) in [input().split() for _ in range(N)]]
dp = [[float("inf")] * MAX_V for _ in range(MAX_N)]
dp[0][0] = 0
for i in range(N):
item = items[i]
for sum_v in range(MAX_V):
# i番目の品物を選ぶ
if sum_v - item.value >= 0:
dp[i + 1][sum_v] = min(
dp[i + 1][sum_v], dp[i][sum_v - item.value] + item.weight
)
dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v])
ans = 0
for sum_v in range(MAX_V):
if dp[N][sum_v] <= W:
ans = sum_v
print(ans)
if __name__ == "__main__":
main()
| import sys
import numpy as np
input = sys.stdin.readline
def main():
N, W = [int(i) for i in input().strip().split()]
MAX_V = 10**3 * N
dp = np.full([N + 1, MAX_V + 1], np.inf)
dp[0][0] = 0
for n in range(N):
w, v = [int(i) for i in input().strip().split()]
dp[n + 1] = dp[n]
dp[n + 1][v:] = np.minimum(dp[n][v:], dp[n][:-v] + w)
ans = np.max(np.where(dp <= W))
print(ans)
if __name__ == "__main__":
main()
| false | 30.30303 | [
"-import collections",
"+import sys",
"+import numpy as np",
"-MAX_N = 110",
"-MAX_V = 100100",
"-Item = collections.namedtuple(\"Item\", (\"weight\", \"value\"))",
"+input = sys.stdin.readline",
"- N, W = [int(i) for i in input().split()]",
"- items = [Item(int(i), int(j)) for (i, j) in [inpu... | false | 1.063825 | 0.278589 | 3.818614 | [
"s994404373",
"s883211853"
] |
u796942881 | p03087 | python | s649602491 | s364579935 | 194 | 169 | 23,648 | 23,648 | Accepted | Accepted | 12.89 | from sys import stdin
def main():
readline = stdin.readline
read = stdin.read
N, Q = list(map(int, readline().split()))
S = readline().strip()
* LR, = [int(x) - 1 for x in read().split()]
AC = []
pre = None
cnt = 0
for c in S:
if c == "A":
pre = "A"
elif pre == "A" and c == "C":
cnt += 1
pre = None
elif pre == "A":
pre = None
AC.append(cnt)
for l, r in zip(*[iter(LR)] * 2):
print((AC[r] - AC[l]))
return
main()
| from sys import stdin
def main():
readline = stdin.readline
read = stdin.read
N, Q = list(map(int, readline().split()))
S = readline().strip()
LR = [int(x) - 1 for x in read().split()]
AC = []
pre = None
cnt = 0
for c in S:
if c == "A":
pre = "A"
elif pre == "A" and c == "C":
cnt += 1
pre = None
elif pre == "A":
pre = None
AC.append(cnt)
for l, r in zip(*[iter(LR)] * 2):
print((AC[r] - AC[l]))
return
main()
| 27 | 27 | 573 | 566 | from sys import stdin
def main():
readline = stdin.readline
read = stdin.read
N, Q = list(map(int, readline().split()))
S = readline().strip()
(*LR,) = [int(x) - 1 for x in read().split()]
AC = []
pre = None
cnt = 0
for c in S:
if c == "A":
pre = "A"
elif pre == "A" and c == "C":
cnt += 1
pre = None
elif pre == "A":
pre = None
AC.append(cnt)
for l, r in zip(*[iter(LR)] * 2):
print((AC[r] - AC[l]))
return
main()
| from sys import stdin
def main():
readline = stdin.readline
read = stdin.read
N, Q = list(map(int, readline().split()))
S = readline().strip()
LR = [int(x) - 1 for x in read().split()]
AC = []
pre = None
cnt = 0
for c in S:
if c == "A":
pre = "A"
elif pre == "A" and c == "C":
cnt += 1
pre = None
elif pre == "A":
pre = None
AC.append(cnt)
for l, r in zip(*[iter(LR)] * 2):
print((AC[r] - AC[l]))
return
main()
| false | 0 | [
"- (*LR,) = [int(x) - 1 for x in read().split()]",
"+ LR = [int(x) - 1 for x in read().split()]"
] | false | 0.046882 | 0.047692 | 0.983022 | [
"s649602491",
"s364579935"
] |
u631277801 | p03964 | python | s576010605 | s143931181 | 23 | 21 | 3,316 | 3,188 | Accepted | Accepted | 8.7 | N = int(eval(input()))
TA = []
for i in range(N):
TA.append(list(map(int, input().split())))
t_real = [TA[0][0]]
a_real = [TA[0][1]]
for i in range(1,N):
t_cand = (t_real[i-1]//TA[i][0] + bool(t_real[i-1]%TA[i][0])) * TA[i][0]
a_cand = (a_real[i-1]//TA[i][1] + bool(a_real[i-1]%TA[i][1])) * TA[i][1]
if t_cand//TA[i][0] * TA[i][1] >= a_real[i-1]:
t_real.append(t_cand)
a_real.append(t_cand//TA[i][0] * TA[i][1])
elif a_cand//TA[i][1] * TA[i][0] >= t_real[i-1]:
a_real.append(a_cand)
t_real.append(a_cand//TA[i][1] * TA[i][0])
else:
print("error")
print((t_real[-1]+a_real[-1])) | import sys
sdin = sys.stdin.readline
INF = float("inf")
n = int(sdin())
ta = []
for _ in range(n):
ta.append(tuple(map(int, sdin().split())))
t_real = [ta[0][0]]
a_real = [ta[0][1]]
for i in range(1,n):
t_k = t_real[i-1]//ta[i][0] + bool(t_real[i-1]%ta[i][0])
a_k = a_real[i-1]//ta[i][1] + bool(a_real[i-1]%ta[i][1])
# t_realとa_realの次の候補
if t_k * ta[i][1] < a_real[i-1]:
t_real_t = INF
a_real_t = INF
else:
t_real_t = t_k * ta[i][0]
a_real_t = t_k * ta[i][1]
if a_k * ta[i][0] < t_real[i-1]:
t_real_a = INF
a_real_a = INF
else:
t_real_a = a_k * ta[i][0]
a_real_a = a_k * ta[i][1]
# 選択
if (t_real_t + a_real_t) <= (t_real_a + a_real_a):
t_real.append(t_real_t)
a_real.append(a_real_t)
else:
t_real.append(t_real_a)
a_real.append(a_real_a)
print((t_real[-1] + a_real[-1])) | 24 | 41 | 690 | 992 | N = int(eval(input()))
TA = []
for i in range(N):
TA.append(list(map(int, input().split())))
t_real = [TA[0][0]]
a_real = [TA[0][1]]
for i in range(1, N):
t_cand = (t_real[i - 1] // TA[i][0] + bool(t_real[i - 1] % TA[i][0])) * TA[i][0]
a_cand = (a_real[i - 1] // TA[i][1] + bool(a_real[i - 1] % TA[i][1])) * TA[i][1]
if t_cand // TA[i][0] * TA[i][1] >= a_real[i - 1]:
t_real.append(t_cand)
a_real.append(t_cand // TA[i][0] * TA[i][1])
elif a_cand // TA[i][1] * TA[i][0] >= t_real[i - 1]:
a_real.append(a_cand)
t_real.append(a_cand // TA[i][1] * TA[i][0])
else:
print("error")
print((t_real[-1] + a_real[-1]))
| import sys
sdin = sys.stdin.readline
INF = float("inf")
n = int(sdin())
ta = []
for _ in range(n):
ta.append(tuple(map(int, sdin().split())))
t_real = [ta[0][0]]
a_real = [ta[0][1]]
for i in range(1, n):
t_k = t_real[i - 1] // ta[i][0] + bool(t_real[i - 1] % ta[i][0])
a_k = a_real[i - 1] // ta[i][1] + bool(a_real[i - 1] % ta[i][1])
# t_realとa_realの次の候補
if t_k * ta[i][1] < a_real[i - 1]:
t_real_t = INF
a_real_t = INF
else:
t_real_t = t_k * ta[i][0]
a_real_t = t_k * ta[i][1]
if a_k * ta[i][0] < t_real[i - 1]:
t_real_a = INF
a_real_a = INF
else:
t_real_a = a_k * ta[i][0]
a_real_a = a_k * ta[i][1]
# 選択
if (t_real_t + a_real_t) <= (t_real_a + a_real_a):
t_real.append(t_real_t)
a_real.append(a_real_t)
else:
t_real.append(t_real_a)
a_real.append(a_real_a)
print((t_real[-1] + a_real[-1]))
| false | 41.463415 | [
"-N = int(eval(input()))",
"-TA = []",
"-for i in range(N):",
"- TA.append(list(map(int, input().split())))",
"-t_real = [TA[0][0]]",
"-a_real = [TA[0][1]]",
"-for i in range(1, N):",
"- t_cand = (t_real[i - 1] // TA[i][0] + bool(t_real[i - 1] % TA[i][0])) * TA[i][0]",
"- a_cand = (a_real[i... | false | 0.089895 | 0.098274 | 0.914742 | [
"s576010605",
"s143931181"
] |
u633068244 | p00121 | python | s820701826 | s773210683 | 120 | 110 | 6,076 | 6,160 | Accepted | Accepted | 8.33 | move = [[1,4],[0,2,5],[1,3,6],[2,7],[0,5],[4,1,6],[5,2,7],[6,3]]
def swap(ls,p,q):
res = list(ls)
res[p],res[q] = res[q],res[p]
return "".join(res)
ans = {"01234567":0}
que = [["01234567",0]]
while que:
pzl,count = que.pop(0)
p = pzl.find("0")
for q in move[p]:
tmp = swap(pzl,p,q)
if tmp not in ans:
ans[tmp] = count+1
que.append([tmp,count+1])
while 1:
try:
print(ans[input().replace(" ","")])
except:
break | move = [[1,4],[0,2,5],[1,3,6],[2,7],[0,5],[4,1,6],[5,2,7],[6,3]]
ans = {"01234567":0}
que = [["01234567",0]]
while que:
pzl,count = que.pop(0)
p = pzl.find("0")
for q in move[p]:
a,b = min(p,q),max(p,q)
tmp = pzl[:a]+pzl[b]+pzl[a+1:b]+pzl[a]+pzl[b+1:]
if tmp not in ans:
ans[tmp] = count+1
que.append([tmp,count+1])
while 1:
try:
print(ans[input().replace(" ","")])
except:
break | 23 | 19 | 525 | 486 | move = [[1, 4], [0, 2, 5], [1, 3, 6], [2, 7], [0, 5], [4, 1, 6], [5, 2, 7], [6, 3]]
def swap(ls, p, q):
res = list(ls)
res[p], res[q] = res[q], res[p]
return "".join(res)
ans = {"01234567": 0}
que = [["01234567", 0]]
while que:
pzl, count = que.pop(0)
p = pzl.find("0")
for q in move[p]:
tmp = swap(pzl, p, q)
if tmp not in ans:
ans[tmp] = count + 1
que.append([tmp, count + 1])
while 1:
try:
print(ans[input().replace(" ", "")])
except:
break
| move = [[1, 4], [0, 2, 5], [1, 3, 6], [2, 7], [0, 5], [4, 1, 6], [5, 2, 7], [6, 3]]
ans = {"01234567": 0}
que = [["01234567", 0]]
while que:
pzl, count = que.pop(0)
p = pzl.find("0")
for q in move[p]:
a, b = min(p, q), max(p, q)
tmp = pzl[:a] + pzl[b] + pzl[a + 1 : b] + pzl[a] + pzl[b + 1 :]
if tmp not in ans:
ans[tmp] = count + 1
que.append([tmp, count + 1])
while 1:
try:
print(ans[input().replace(" ", "")])
except:
break
| false | 17.391304 | [
"-",
"-",
"-def swap(ls, p, q):",
"- res = list(ls)",
"- res[p], res[q] = res[q], res[p]",
"- return \"\".join(res)",
"-",
"-",
"- tmp = swap(pzl, p, q)",
"+ a, b = min(p, q), max(p, q)",
"+ tmp = pzl[:a] + pzl[b] + pzl[a + 1 : b] + pzl[a] + pzl[b + 1 :]"
] | false | 0.253509 | 0.318528 | 0.795878 | [
"s820701826",
"s773210683"
] |
u724563664 | p02720 | python | s852954855 | s268212523 | 247 | 223 | 3,188 | 3,064 | Accepted | Accepted | 9.72 | #coding:utf-8
def up(nums):
if len(nums) == nums.count(9):
nums = [1] + [0] * len(nums)
return nums
for i in list(reversed(list(range(len(nums))))):
if nums[i] > nums[i-1] or nums[i] == 9:
continue
else:
nums[i] += 1
for j in range(i+1, len(nums)):
if j == len(nums) - 1:
nums[j] = max(nums[j-1]-1, 0)
else:
nums[j] = max(nums[j-1] - 1, 0)
return nums
def main():
k = int(eval(input()))
if k < 10:
print(k)
return
cnt = 11
nums = [1, 0]
while cnt <= k:
cnt += 1
nums = up(nums)
#print(nums)
print((''.join([str(num) for num in nums])))
if __name__ == '__main__':
main() | #coding:utf-8
def up(nums):
if len(nums) == nums.count(9):
nums = [1] + [0] * len(nums)
return nums
for i in list(reversed(list(range(len(nums))))):
if nums[i] > nums[i-1] or nums[i] == 9:
continue
else:
nums[i] += 1
for j in range(i+1, len(nums)):
nums[j] = max(nums[j-1]-1, 0)
return nums
def main():
k = int(eval(input()))
nums = [0]
for _ in range(k):
nums = up(nums)
print((''.join([str(num) for num in nums])))
if __name__ == '__main__':
main() | 39 | 30 | 876 | 652 | # coding:utf-8
def up(nums):
if len(nums) == nums.count(9):
nums = [1] + [0] * len(nums)
return nums
for i in list(reversed(list(range(len(nums))))):
if nums[i] > nums[i - 1] or nums[i] == 9:
continue
else:
nums[i] += 1
for j in range(i + 1, len(nums)):
if j == len(nums) - 1:
nums[j] = max(nums[j - 1] - 1, 0)
else:
nums[j] = max(nums[j - 1] - 1, 0)
return nums
def main():
k = int(eval(input()))
if k < 10:
print(k)
return
cnt = 11
nums = [1, 0]
while cnt <= k:
cnt += 1
nums = up(nums)
# print(nums)
print(("".join([str(num) for num in nums])))
if __name__ == "__main__":
main()
| # coding:utf-8
def up(nums):
if len(nums) == nums.count(9):
nums = [1] + [0] * len(nums)
return nums
for i in list(reversed(list(range(len(nums))))):
if nums[i] > nums[i - 1] or nums[i] == 9:
continue
else:
nums[i] += 1
for j in range(i + 1, len(nums)):
nums[j] = max(nums[j - 1] - 1, 0)
return nums
def main():
k = int(eval(input()))
nums = [0]
for _ in range(k):
nums = up(nums)
print(("".join([str(num) for num in nums])))
if __name__ == "__main__":
main()
| false | 23.076923 | [
"- if j == len(nums) - 1:",
"- nums[j] = max(nums[j - 1] - 1, 0)",
"- else:",
"- nums[j] = max(nums[j - 1] - 1, 0)",
"+ nums[j] = max(nums[j - 1] - 1, 0)",
"- if k < 10:",
"- print(k)",
"- return",
"-... | false | 0.072225 | 0.069847 | 1.034053 | [
"s852954855",
"s268212523"
] |
u185896732 | p02927 | python | s093433603 | s037084206 | 27 | 24 | 3,064 | 3,060 | Accepted | Accepted | 11.11 | #import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6)
input=stdin.readline
m,d=list(map(int,input().split()))
ans=0
for i in range(1,m+1):
for j in range(1,d+1):
s=str(j)
if len(s)>=2:
o,t=int(s[0]),int(s[1])
if o>=2 and t>=2 and o*t==i:
#print(i,j)
ans+=1
print(ans) | m,d=list(map(int,input().split()))
ans=0
for month in range(1,m+1):
for day in range(1,d+1):
day=str(day)
if len(day)!=2:
continue
if int(day[0])*int(day[1])!=month:
continue
if int(day[0])<2 or int(day[1])<2:
continue
#print(month,day)
ans+=1
print(ans) | 31 | 14 | 862 | 349 | # import pysnooper
# import numpy
# import os,re,sys,operator
# from collections import Counter,deque
# from operator import itemgetter,mul
# from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin, setrecursionlimit
# from bisect import bisect_left,bisect_right
# from copy import deepcopy
# import heapq
# import math
# import string
# from time import time
# from functools import lru_cache,reduce
# from math import factorial,hypot
# import sys
# from fractions import gcd
setrecursionlimit(10**6)
input = stdin.readline
m, d = list(map(int, input().split()))
ans = 0
for i in range(1, m + 1):
for j in range(1, d + 1):
s = str(j)
if len(s) >= 2:
o, t = int(s[0]), int(s[1])
if o >= 2 and t >= 2 and o * t == i:
# print(i,j)
ans += 1
print(ans)
| m, d = list(map(int, input().split()))
ans = 0
for month in range(1, m + 1):
for day in range(1, d + 1):
day = str(day)
if len(day) != 2:
continue
if int(day[0]) * int(day[1]) != month:
continue
if int(day[0]) < 2 or int(day[1]) < 2:
continue
# print(month,day)
ans += 1
print(ans)
| false | 54.83871 | [
"-# import pysnooper",
"-# import numpy",
"-# import os,re,sys,operator",
"-# from collections import Counter,deque",
"-# from operator import itemgetter,mul",
"-# from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations",
"-from sys import stdin, setrecursionlimi... | false | 0.040187 | 0.047544 | 0.845257 | [
"s093433603",
"s037084206"
] |
u796942881 | p02819 | python | s618465518 | s075379586 | 40 | 17 | 3,060 | 2,940 | Accepted | Accepted | 57.5 | def isPrime(n):
# 素数判定
if n < 2:
return False
for i in range(2, n + 1):
if n < i ** 2:
break
if n % i == 0:
return False
return True
def main():
X = int(eval(input()))
while True:
if isPrime(X):
print(X)
break
X += 1
return
main()
| def isPrime(n):
# 素数判定
if n == 2:
return True
if n < 2 or n % 2 == 0:
return False
m = 3
while m * m <= n:
if n % m == 0:
return False
m += 2
return True
def main():
X = int(eval(input()))
while True:
if isPrime(X):
print(X)
break
X += 1
return
main()
| 23 | 25 | 367 | 394 | def isPrime(n):
# 素数判定
if n < 2:
return False
for i in range(2, n + 1):
if n < i**2:
break
if n % i == 0:
return False
return True
def main():
X = int(eval(input()))
while True:
if isPrime(X):
print(X)
break
X += 1
return
main()
| def isPrime(n):
# 素数判定
if n == 2:
return True
if n < 2 or n % 2 == 0:
return False
m = 3
while m * m <= n:
if n % m == 0:
return False
m += 2
return True
def main():
X = int(eval(input()))
while True:
if isPrime(X):
print(X)
break
X += 1
return
main()
| false | 8 | [
"- if n < 2:",
"+ if n == 2:",
"+ return True",
"+ if n < 2 or n % 2 == 0:",
"- for i in range(2, n + 1):",
"- if n < i**2:",
"- break",
"- if n % i == 0:",
"+ m = 3",
"+ while m * m <= n:",
"+ if n % m == 0:",
"+ m += 2"
] | false | 0.067435 | 0.036873 | 1.828855 | [
"s618465518",
"s075379586"
] |
u047796752 | p03298 | python | s589813252 | s263459420 | 1,873 | 663 | 245,628 | 235,856 | Accepted | Accepted | 64.6 | from collections import *
N = int(eval(input()))
s = list(eval(input()))
cnt = defaultdict(lambda : defaultdict(int))
for S in range(2**N):
red, blue = [], []
for i in range(N):
if (S>>i)&1:
red.append(s[i])
else:
blue.append(s[i])
cnt[''.join(red)][''.join(blue)] += 1
s.reverse()
ans = 0
for S in range(2**N):
red, blue = [], []
for i in range(N):
if (S>>i)&1:
red.append(s[i])
else:
blue.append(s[i])
ans += cnt[''.join(blue)][''.join(red)]
print(ans) | import sys
input = sys.stdin.readline
from collections import *
N = int(eval(input()))
s = input()[:-1]
cnt = defaultdict(int)
for S in range(1<<N):
red, blue = [], []
for i in range(N):
if (S>>i)&1:
red.append(s[i])
else:
blue.append(s[i])
cnt[(''.join(red), ''.join(blue))] += 1
s = s[::-1]
ans = 0
for S in range(1<<N):
red, blue = [], []
for i in range(N):
if (S>>i)&1:
red.append(s[i])
else:
blue.append(s[i])
ans += cnt[(''.join(blue), ''.join(red))]
print(ans) | 32 | 34 | 602 | 623 | from collections import *
N = int(eval(input()))
s = list(eval(input()))
cnt = defaultdict(lambda: defaultdict(int))
for S in range(2**N):
red, blue = [], []
for i in range(N):
if (S >> i) & 1:
red.append(s[i])
else:
blue.append(s[i])
cnt["".join(red)]["".join(blue)] += 1
s.reverse()
ans = 0
for S in range(2**N):
red, blue = [], []
for i in range(N):
if (S >> i) & 1:
red.append(s[i])
else:
blue.append(s[i])
ans += cnt["".join(blue)]["".join(red)]
print(ans)
| import sys
input = sys.stdin.readline
from collections import *
N = int(eval(input()))
s = input()[:-1]
cnt = defaultdict(int)
for S in range(1 << N):
red, blue = [], []
for i in range(N):
if (S >> i) & 1:
red.append(s[i])
else:
blue.append(s[i])
cnt[("".join(red), "".join(blue))] += 1
s = s[::-1]
ans = 0
for S in range(1 << N):
red, blue = [], []
for i in range(N):
if (S >> i) & 1:
red.append(s[i])
else:
blue.append(s[i])
ans += cnt[("".join(blue), "".join(red))]
print(ans)
| false | 5.882353 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"-s = list(eval(input()))",
"-cnt = defaultdict(lambda: defaultdict(int))",
"-for S in range(2**N):",
"+s = input()[:-1]",
"+cnt = defaultdict(int)",
"+for S in range(1 << N):",
"- cnt[\"\".join(red)][\"\".join(blue)] += 1",
"-s.reverse()",
... | false | 0.037646 | 0.672768 | 0.055956 | [
"s589813252",
"s263459420"
] |
u285891772 | p03556 | python | s422458650 | s047114533 | 68 | 48 | 5,576 | 5,324 | Accepted | Accepted | 29.41 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
for i in range(N, 0, -1):
if sqrt(i) == int(sqrt(i)):
print(i)
exit() | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
print((int(sqrt(N))**2))
| 25 | 23 | 871 | 819 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
for i in range(N, 0, -1):
if sqrt(i) == int(sqrt(i)):
print(i)
exit()
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
print((int(sqrt(N)) ** 2))
| false | 8 | [
"-for i in range(N, 0, -1):",
"- if sqrt(i) == int(sqrt(i)):",
"- print(i)",
"- exit()",
"+print((int(sqrt(N)) ** 2))"
] | false | 0.039527 | 0.037969 | 1.041027 | [
"s422458650",
"s047114533"
] |
u327466606 | p03329 | python | s630134336 | s702691097 | 322 | 281 | 3,828 | 2,940 | Accepted | Accepted | 12.73 | from itertools import count
n = int(eval(input()))
dp = [0]*(n+1)
def it(n):
yield 1
m = 6
while m <= n:
yield m
m *= 6
m = 9
while m <= n:
yield m
m *= 9
for i in range(1,n+1):
dp[i] = min(dp[i-t] for t in it(i))+1
print((dp[n]))
| def it(n,p):
while n > 0:
yield n%p
n //= p
cost = lambda *a: sum(it(*a))
n = int(eval(input()))
print((min(cost(x,6)+cost(n-x,9) for x in range(n+1)))) | 22 | 8 | 278 | 162 | from itertools import count
n = int(eval(input()))
dp = [0] * (n + 1)
def it(n):
yield 1
m = 6
while m <= n:
yield m
m *= 6
m = 9
while m <= n:
yield m
m *= 9
for i in range(1, n + 1):
dp[i] = min(dp[i - t] for t in it(i)) + 1
print((dp[n]))
| def it(n, p):
while n > 0:
yield n % p
n //= p
cost = lambda *a: sum(it(*a))
n = int(eval(input()))
print((min(cost(x, 6) + cost(n - x, 9) for x in range(n + 1))))
| false | 63.636364 | [
"-from itertools import count",
"-",
"-n = int(eval(input()))",
"-dp = [0] * (n + 1)",
"+def it(n, p):",
"+ while n > 0:",
"+ yield n % p",
"+ n //= p",
"-def it(n):",
"- yield 1",
"- m = 6",
"- while m <= n:",
"- yield m",
"- m *= 6",
"- m = 9"... | false | 0.221882 | 0.070371 | 3.153014 | [
"s630134336",
"s702691097"
] |
u143492911 | p03945 | python | s567114674 | s374505118 | 54 | 47 | 3,188 | 3,956 | Accepted | Accepted | 12.96 | s=eval(input())
count=1
for i in range(len(s)-1):
if s[i]=="B":
if s[i+1]=="W":
count+=1
elif s[i]=="W":
if s[i+1]=="B":
count+=1
print((count-1)) | s=list(eval(input()))
count=0
for i in range(len(s)-1):
if s[i]!=s[i+1]:
count+=1
print(count) | 10 | 6 | 195 | 105 | s = eval(input())
count = 1
for i in range(len(s) - 1):
if s[i] == "B":
if s[i + 1] == "W":
count += 1
elif s[i] == "W":
if s[i + 1] == "B":
count += 1
print((count - 1))
| s = list(eval(input()))
count = 0
for i in range(len(s) - 1):
if s[i] != s[i + 1]:
count += 1
print(count)
| false | 40 | [
"-s = eval(input())",
"-count = 1",
"+s = list(eval(input()))",
"+count = 0",
"- if s[i] == \"B\":",
"- if s[i + 1] == \"W\":",
"- count += 1",
"- elif s[i] == \"W\":",
"- if s[i + 1] == \"B\":",
"- count += 1",
"-print((count - 1))",
"+ if s[i] != ... | false | 0.035467 | 0.035574 | 0.996992 | [
"s567114674",
"s374505118"
] |
u285443936 | p03240 | python | s594270759 | s410013800 | 386 | 39 | 12,564 | 3,064 | Accepted | Accepted | 89.9 | import numpy as np
N = int(eval(input()))
point = [[int(item) for item in input().split()] for _ in range(N)]
point.sort(key=lambda x:x[2], reverse=True)
ans = np.zeros((101,101))
for i,p in enumerate(point):
if i == 0:
for j in range(101):
for k in range(101):
H = p[2] + abs(j - p[0]) + abs(k - p[1])
ans[j,k] = H
# print(ans[j,k])
else:
for j in range(101):
for k in range(101):
if not ans[j,k] == 0:
if ans[j,k] != p[2] + abs(j - p[0]) + abs(k - p[1]):
ans[j,k] = 0
if len(ans[ans!=0]) <= 1:
break
x,y = np.where(ans!=0)
print((x[0],y[0],int(ans[x[0],y[0]]))) | N = int(eval(input()))
P = [list(map(int, input().split())) for i in range(N)]
C = [[0]*101 for i in range(101)]
P.sort(key=lambda x:x[2], reverse=True)
for X in range(101):
for Y in range(101):
tmp1 = -1
flg = 0
for i in range(N):
x,y,h = P[i]
if h != 0 and tmp1 == -1:
tmp1 = abs(X-x)+abs(Y-y)+h
elif tmp1 != -1:
tmp2 = abs(X-x)+abs(Y-y)+h
if h != 0:
if tmp1 != tmp2:
flg = 1
break
if h == 0:
if tmp1 > tmp2:
flg = 1
break
if flg == 0:
print((X, Y, tmp1))
exit() | 26 | 25 | 667 | 637 | import numpy as np
N = int(eval(input()))
point = [[int(item) for item in input().split()] for _ in range(N)]
point.sort(key=lambda x: x[2], reverse=True)
ans = np.zeros((101, 101))
for i, p in enumerate(point):
if i == 0:
for j in range(101):
for k in range(101):
H = p[2] + abs(j - p[0]) + abs(k - p[1])
ans[j, k] = H
# print(ans[j,k])
else:
for j in range(101):
for k in range(101):
if not ans[j, k] == 0:
if ans[j, k] != p[2] + abs(j - p[0]) + abs(k - p[1]):
ans[j, k] = 0
if len(ans[ans != 0]) <= 1:
break
x, y = np.where(ans != 0)
print((x[0], y[0], int(ans[x[0], y[0]])))
| N = int(eval(input()))
P = [list(map(int, input().split())) for i in range(N)]
C = [[0] * 101 for i in range(101)]
P.sort(key=lambda x: x[2], reverse=True)
for X in range(101):
for Y in range(101):
tmp1 = -1
flg = 0
for i in range(N):
x, y, h = P[i]
if h != 0 and tmp1 == -1:
tmp1 = abs(X - x) + abs(Y - y) + h
elif tmp1 != -1:
tmp2 = abs(X - x) + abs(Y - y) + h
if h != 0:
if tmp1 != tmp2:
flg = 1
break
if h == 0:
if tmp1 > tmp2:
flg = 1
break
if flg == 0:
print((X, Y, tmp1))
exit()
| false | 3.846154 | [
"-import numpy as np",
"-",
"-point = [[int(item) for item in input().split()] for _ in range(N)]",
"-point.sort(key=lambda x: x[2], reverse=True)",
"-ans = np.zeros((101, 101))",
"-for i, p in enumerate(point):",
"- if i == 0:",
"- for j in range(101):",
"- for k in range(101):... | false | 0.496145 | 0.044235 | 11.216104 | [
"s594270759",
"s410013800"
] |
u698849142 | p03048 | python | s506794289 | s129510099 | 380 | 293 | 40,684 | 40,684 | Accepted | Accepted | 22.89 | r,g,b,n = list(map(int, input().split(" ")))
l = sorted([r,g,b])
count=0
for i in range(int(n/l[2])+1):
for j in range(int(n/l[1])+1):
x = l[2]*i
y = l[1]*j
if (n-x-y) >= 0 and (n-x-y)%l[0] == 0:
count = count + 1
print(count) | r,g,b,n = list(map(int, input().split(" ")))
l = sorted([r,g,b])
count=0
for i in range(int(n/l[2])+1):
for j in range(int(n/l[1])+1):
x = l[2]*i
y = l[1]*j
if (n-x-y) < 0:
break
if (n-x-y) >= 0 and (n-x-y)%l[0] == 0:
count = count + 1
print(count) | 10 | 12 | 269 | 313 | r, g, b, n = list(map(int, input().split(" ")))
l = sorted([r, g, b])
count = 0
for i in range(int(n / l[2]) + 1):
for j in range(int(n / l[1]) + 1):
x = l[2] * i
y = l[1] * j
if (n - x - y) >= 0 and (n - x - y) % l[0] == 0:
count = count + 1
print(count)
| r, g, b, n = list(map(int, input().split(" ")))
l = sorted([r, g, b])
count = 0
for i in range(int(n / l[2]) + 1):
for j in range(int(n / l[1]) + 1):
x = l[2] * i
y = l[1] * j
if (n - x - y) < 0:
break
if (n - x - y) >= 0 and (n - x - y) % l[0] == 0:
count = count + 1
print(count)
| false | 16.666667 | [
"+ if (n - x - y) < 0:",
"+ break"
] | false | 0.200624 | 0.054526 | 3.679403 | [
"s506794289",
"s129510099"
] |
u691018832 | p03831 | python | s540899360 | s141974399 | 91 | 82 | 14,252 | 12,496 | Accepted | Accepted | 9.89 | import sys
import math
input = sys.stdin.readline
n, a, b = list(map(int, input().split()))
x = list(map(int, input().split()))
k = math.floor(b / a)
ans = 0
for i in range(1, n):
if k >= x[i] - x[i - 1]:
ans += (x[i] - x[i - 1]) * a
else:
ans += b
print(ans)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n, a, b = list(map(int, readline().split()))
x = list(map(int, readline().split()))
ans = 0
for bf, af in zip(x, x[1:]):
ans += min((af - bf) * a, b)
print(ans)
| 14 | 12 | 292 | 318 | import sys
import math
input = sys.stdin.readline
n, a, b = list(map(int, input().split()))
x = list(map(int, input().split()))
k = math.floor(b / a)
ans = 0
for i in range(1, n):
if k >= x[i] - x[i - 1]:
ans += (x[i] - x[i - 1]) * a
else:
ans += b
print(ans)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
n, a, b = list(map(int, readline().split()))
x = list(map(int, readline().split()))
ans = 0
for bf, af in zip(x, x[1:]):
ans += min((af - bf) * a, b)
print(ans)
| false | 14.285714 | [
"-import math",
"-input = sys.stdin.readline",
"-n, a, b = list(map(int, input().split()))",
"-x = list(map(int, input().split()))",
"-k = math.floor(b / a)",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+sys.setrecursionlimit(... | false | 0.043589 | 0.112253 | 0.388309 | [
"s540899360",
"s141974399"
] |
u072717685 | p03845 | python | s820344868 | s623847995 | 30 | 22 | 3,444 | 3,444 | Accepted | Accepted | 26.67 | import copy
n = int(eval(input()))
t = [int(i) for i in input().split()]
m = int(eval(input()))
for _ in range(m):
p, x = list(map(int, input().split()))
t_copy = copy.deepcopy(t)
t_copy[p-1] = x
print((sum(t_copy))) | import copy
n = int(eval(input()))
t = [int(i) for i in input().split()]
m = int(eval(input()))
sum_t = sum(t)
for _ in range(m):
p, x = list(map(int, input().split()))
print((sum_t - (t[p-1] - x))) | 9 | 8 | 212 | 191 | import copy
n = int(eval(input()))
t = [int(i) for i in input().split()]
m = int(eval(input()))
for _ in range(m):
p, x = list(map(int, input().split()))
t_copy = copy.deepcopy(t)
t_copy[p - 1] = x
print((sum(t_copy)))
| import copy
n = int(eval(input()))
t = [int(i) for i in input().split()]
m = int(eval(input()))
sum_t = sum(t)
for _ in range(m):
p, x = list(map(int, input().split()))
print((sum_t - (t[p - 1] - x)))
| false | 11.111111 | [
"+sum_t = sum(t)",
"- t_copy = copy.deepcopy(t)",
"- t_copy[p - 1] = x",
"- print((sum(t_copy)))",
"+ print((sum_t - (t[p - 1] - x)))"
] | false | 0.038476 | 0.099771 | 0.385645 | [
"s820344868",
"s623847995"
] |
u896741788 | p03298 | python | s335710047 | s830654882 | 2,703 | 1,409 | 129,496 | 150,056 | Accepted | Accepted | 47.87 | def t():
n=int(eval(input()))
s=eval(input())
from collections import defaultdict
l,r=s[:n],s[-1:-n-1:-1]
d=defaultdict(int)
for i in range(2**n):
a={j for j in range(n)if (i>>j)%2}
d[("".join(l[p] for p in sorted(list(a))),"".join(l[o] for o in range(n)if o not in a))]+=1
ans=0
for i in range(2**n):
a={j for j in range(n)if (i>>j)%2}
ans+=d[("".join(r[p] for p in sorted(list(a))),"".join(r[o] for o in range(n)if o not in a))]
print(ans)
if __name__ == "__main__":
t() | def f():
n,s=int(eval(input())),eval(input())
a,b=s[n-1::-1],s[n:]
from collections import defaultdict
ad=defaultdict(int)
bd=defaultdict(int)
for i in range(2**n):
sa,ta,sb,tb="","","",""
for j in range(n):
if i%2:
sa+=a[j]
sb+=b[j]
else:
ta+=a[j]
tb+=b[j]
i//=2
ad[(sa,ta)]+=1
bd[(sb,tb)]+=1
ans=0
for k in ad:
ans+=bd[k]*ad[k]
print(ans)
if __name__ == "__main__":
f()
| 17 | 24 | 549 | 563 | def t():
n = int(eval(input()))
s = eval(input())
from collections import defaultdict
l, r = s[:n], s[-1 : -n - 1 : -1]
d = defaultdict(int)
for i in range(2**n):
a = {j for j in range(n) if (i >> j) % 2}
d[
(
"".join(l[p] for p in sorted(list(a))),
"".join(l[o] for o in range(n) if o not in a),
)
] += 1
ans = 0
for i in range(2**n):
a = {j for j in range(n) if (i >> j) % 2}
ans += d[
(
"".join(r[p] for p in sorted(list(a))),
"".join(r[o] for o in range(n) if o not in a),
)
]
print(ans)
if __name__ == "__main__":
t()
| def f():
n, s = int(eval(input())), eval(input())
a, b = s[n - 1 :: -1], s[n:]
from collections import defaultdict
ad = defaultdict(int)
bd = defaultdict(int)
for i in range(2**n):
sa, ta, sb, tb = "", "", "", ""
for j in range(n):
if i % 2:
sa += a[j]
sb += b[j]
else:
ta += a[j]
tb += b[j]
i //= 2
ad[(sa, ta)] += 1
bd[(sb, tb)] += 1
ans = 0
for k in ad:
ans += bd[k] * ad[k]
print(ans)
if __name__ == "__main__":
f()
| false | 29.166667 | [
"-def t():",
"- n = int(eval(input()))",
"- s = eval(input())",
"+def f():",
"+ n, s = int(eval(input())), eval(input())",
"+ a, b = s[n - 1 :: -1], s[n:]",
"- l, r = s[:n], s[-1 : -n - 1 : -1]",
"- d = defaultdict(int)",
"+ ad = defaultdict(int)",
"+ bd = defaultdict(int)"... | false | 0.041529 | 0.06346 | 0.654412 | [
"s335710047",
"s830654882"
] |
u608088992 | p03044 | python | s868811286 | s694368973 | 461 | 390 | 43,216 | 44,920 | Accepted | Accepted | 15.4 | 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 solve():
N = int(single_input())
edge = [[] for i in range(N)]
for i in range(N-1):
u, v, w = list(map(int, line_input()))
edge[u-1].append((v-1, w))
edge[v-1].append((u-1, w))
col = [-1] * N
que = collections.deque()
que.append((0, 0))
while que:
nownode, nowdist = que.popleft()
if col[nownode] == -1:
col[nownode] = nowdist
for nextnode, weight in edge[nownode]:
if col[nextnode] == -1:
que.append((nextnode, nowdist + weight))
for i in range(N):
print((col[i] % 2))
return 0
if __name__ == "__main__":
solve() | import sys
from collections import deque
def solve():
input = sys.stdin.readline
N = int(eval(input()))
Edge = [[] for _ in range(N)]
for _ in range(N - 1):
u, v, w = list(map(int, input().split()))
Edge[u-1].append((v-1, w))
Edge[v-1].append((u-1, w))
Col = [-1] * N
q = deque()
q.append((0, 0, 0)) #now, pre, dist
while q:
nn, pn, dist = q.pop()
if Col[nn] == -1:
Col[nn] = dist % 2
for nextN, addW in Edge[nn]:
if pn != nextN:
q.append((nextN, nn, dist + addW))
print(("\n".join(map(str, Col))))
return 0
if __name__ == "__main__":
solve() | 30 | 28 | 868 | 703 | 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 solve():
N = int(single_input())
edge = [[] for i in range(N)]
for i in range(N - 1):
u, v, w = list(map(int, line_input()))
edge[u - 1].append((v - 1, w))
edge[v - 1].append((u - 1, w))
col = [-1] * N
que = collections.deque()
que.append((0, 0))
while que:
nownode, nowdist = que.popleft()
if col[nownode] == -1:
col[nownode] = nowdist
for nextnode, weight in edge[nownode]:
if col[nextnode] == -1:
que.append((nextnode, nowdist + weight))
for i in range(N):
print((col[i] % 2))
return 0
if __name__ == "__main__":
solve()
| import sys
from collections import deque
def solve():
input = sys.stdin.readline
N = int(eval(input()))
Edge = [[] for _ in range(N)]
for _ in range(N - 1):
u, v, w = list(map(int, input().split()))
Edge[u - 1].append((v - 1, w))
Edge[v - 1].append((u - 1, w))
Col = [-1] * N
q = deque()
q.append((0, 0, 0)) # now, pre, dist
while q:
nn, pn, dist = q.pop()
if Col[nn] == -1:
Col[nn] = dist % 2
for nextN, addW in Edge[nn]:
if pn != nextN:
q.append((nextN, nn, dist + addW))
print(("\n".join(map(str, Col))))
return 0
if __name__ == "__main__":
solve()
| false | 6.666667 | [
"-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()",
"+import sys",
"+from collections import deque",
"- ... | false | 0.085393 | 0.042488 | 2.009823 | [
"s868811286",
"s694368973"
] |
u960080897 | p02659 | python | s650402305 | s591248880 | 28 | 21 | 10,056 | 9,096 | Accepted | Accepted | 25 | from decimal import *
a, b = list(map(Decimal, input().split()))
print((int(a * b))) | a, b = input().split()
a = int(a)
b = int(b.replace('.',''))
print((a * b // 100))
| 3 | 4 | 78 | 84 | from decimal import *
a, b = list(map(Decimal, input().split()))
print((int(a * b)))
| a, b = input().split()
a = int(a)
b = int(b.replace(".", ""))
print((a * b // 100))
| false | 25 | [
"-from decimal import *",
"-",
"-a, b = list(map(Decimal, input().split()))",
"-print((int(a * b)))",
"+a, b = input().split()",
"+a = int(a)",
"+b = int(b.replace(\".\", \"\"))",
"+print((a * b // 100))"
] | false | 0.116283 | 0.036701 | 3.168343 | [
"s650402305",
"s591248880"
] |
u203843959 | p03476 | python | s509387317 | s419537347 | 1,084 | 861 | 4,980 | 7,924 | Accepted | Accepted | 20.57 | Q=int(eval(input()))
def isPrime(x):
for i in range(2,int(x**0.5)+1):
if x%i==0:
return False
else:
return True
plist=[False]*(10**5+3)
for i in range(3,10**5+3,2):
if isPrime(i) and isPrime((i+1)//2):
plist[i]=True
#print(plist[:10])
slist=[0]*(10**5+3)
for i in range(3,10**5+3):
if plist[i]:
slist[i]=slist[i-1]+1
else:
slist[i]=slist[i-1]
#print(slist[:10])
for i in range(Q):
l,r=list(map(int,input().split()))
print((slist[r]-slist[l-1])) | Q=int(eval(input()))
def prime_sieve(n):
prime_list=[True]*n
prime_list[0]=False
prime_list[1]=False
for i in range(2,int(n**0.5)+1):
if not prime_list[i]:
continue
else:
for j in range(i**2,n,i):
prime_list[j]=False
return prime_list
#return [i for i in range(n) if is_prime_list[i]]
prime_list=prime_sieve(10**5+1)
#print(prime_list[:10])
plist=[0]*(10**5+1)
for i in range(3,10**5+1,2):
if prime_list[i] and prime_list[(i+1)//2]:
plist[i]=1
#print(plist[:10])
slist=[0]*(10**5+1)
for i in range(3,10**5+1):
slist[i]=plist[i]+slist[i-1]
#print(slist[:10])
for i in range(Q):
l,r=list(map(int,input().split()))
print((slist[r]-slist[l-1])) | 26 | 33 | 501 | 722 | Q = int(eval(input()))
def isPrime(x):
for i in range(2, int(x**0.5) + 1):
if x % i == 0:
return False
else:
return True
plist = [False] * (10**5 + 3)
for i in range(3, 10**5 + 3, 2):
if isPrime(i) and isPrime((i + 1) // 2):
plist[i] = True
# print(plist[:10])
slist = [0] * (10**5 + 3)
for i in range(3, 10**5 + 3):
if plist[i]:
slist[i] = slist[i - 1] + 1
else:
slist[i] = slist[i - 1]
# print(slist[:10])
for i in range(Q):
l, r = list(map(int, input().split()))
print((slist[r] - slist[l - 1]))
| Q = int(eval(input()))
def prime_sieve(n):
prime_list = [True] * n
prime_list[0] = False
prime_list[1] = False
for i in range(2, int(n**0.5) + 1):
if not prime_list[i]:
continue
else:
for j in range(i**2, n, i):
prime_list[j] = False
return prime_list
# return [i for i in range(n) if is_prime_list[i]]
prime_list = prime_sieve(10**5 + 1)
# print(prime_list[:10])
plist = [0] * (10**5 + 1)
for i in range(3, 10**5 + 1, 2):
if prime_list[i] and prime_list[(i + 1) // 2]:
plist[i] = 1
# print(plist[:10])
slist = [0] * (10**5 + 1)
for i in range(3, 10**5 + 1):
slist[i] = plist[i] + slist[i - 1]
# print(slist[:10])
for i in range(Q):
l, r = list(map(int, input().split()))
print((slist[r] - slist[l - 1]))
| false | 21.212121 | [
"-def isPrime(x):",
"- for i in range(2, int(x**0.5) + 1):",
"- if x % i == 0:",
"- return False",
"- else:",
"- return True",
"+def prime_sieve(n):",
"+ prime_list = [True] * n",
"+ prime_list[0] = False",
"+ prime_list[1] = False",
"+ for i in range(2... | false | 0.479231 | 0.080041 | 5.987317 | [
"s509387317",
"s419537347"
] |
u499381410 | p02614 | python | s928994053 | s506272761 | 328 | 144 | 77,796 | 83,580 | Accepted | Accepted | 56.1 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
h, w, k = LI()
ans = 0
C = SR(h)
for hbit in range(2 ** h):
for wbit in range(2 ** w):
ret = 0
for hi in range(h):
for wi in range(w):
if (hbit >> hi & 1) and (wbit >> wi & 1) and C[hi][wi] == "#":
ret += 1
if ret == k:
ans += 1
print(ans)
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
h, w, k = LI()
C = SR(h)
ans = 0
for i in range(2 ** (h + w)):
ret = 0
for y in range(h):
for x in range(w):
if i >> y & 1 and i >> (h + x) & 1 and C[y][x] == "#":
ret += 1
if ret == k:
ans += 1
print(ans) | 48 | 42 | 1,356 | 1,278 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(10**7)
INF = 10**20
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return sys.stdin.readline().split()
def S():
return sys.stdin.readline().strip()
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 10**9 + 7
h, w, k = LI()
ans = 0
C = SR(h)
for hbit in range(2**h):
for wbit in range(2**w):
ret = 0
for hi in range(h):
for wi in range(w):
if (hbit >> hi & 1) and (wbit >> wi & 1) and C[hi][wi] == "#":
ret += 1
if ret == k:
ans += 1
print(ans)
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(10**7)
INF = 10**20
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return sys.stdin.readline().split()
def S():
return sys.stdin.readline().strip()
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 10**9 + 7
h, w, k = LI()
C = SR(h)
ans = 0
for i in range(2 ** (h + w)):
ret = 0
for y in range(h):
for x in range(w):
if i >> y & 1 and i >> (h + x) & 1 and C[y][x] == "#":
ret += 1
if ret == k:
ans += 1
print(ans)
| false | 12.5 | [
"+C = SR(h)",
"-C = SR(h)",
"-for hbit in range(2**h):",
"- for wbit in range(2**w):",
"- ret = 0",
"- for hi in range(h):",
"- for wi in range(w):",
"- if (hbit >> hi & 1) and (wbit >> wi & 1) and C[hi][wi] == \"#\":",
"- ret += 1",
"-... | false | 0.037532 | 0.036864 | 1.018124 | [
"s928994053",
"s506272761"
] |
u608088992 | p02844 | python | s269334987 | s878702053 | 1,815 | 893 | 48,732 | 25,716 | Accepted | Accepted | 50.8 | import sys
from itertools import combinations, permutations
def solve():
input = sys.stdin.readline
N = int(eval(input()))
S = eval(input())
left = [set() for _ in range(N)]
right = [set() for _ in range(N)]
for i in range(N - 1):
left[i+1] |= left[i] | {int(S[i])}
right[N - i - 2] |= right[N - i - 1] | {int(S[N - i - 1])}
canuse = set()
for i in range(1, N - 1):
for l in left[i]:
for r in right[i]:
canuse |= {str(l) + S[i] + str(r)}
print((len(canuse)))
return 0
if __name__ == "__main__":
solve() | def solve():
N = int(eval(input()))
S = list(eval(input()))
right = [set() for _ in range(N)]
for i in reversed(list(range(N - 1))): right[i] = right[i + 1] | {S[i + 1]}
left = {S[0]}
PIN = set()
for i in range(1, N - 1):
for ln in left:
for rn in right[i]:
p = ln + S[i] + rn
PIN |= {p}
left |= {S[i]}
print((len(PIN)))
return 0
if __name__ == "__main__":
solve() | 23 | 19 | 609 | 464 | import sys
from itertools import combinations, permutations
def solve():
input = sys.stdin.readline
N = int(eval(input()))
S = eval(input())
left = [set() for _ in range(N)]
right = [set() for _ in range(N)]
for i in range(N - 1):
left[i + 1] |= left[i] | {int(S[i])}
right[N - i - 2] |= right[N - i - 1] | {int(S[N - i - 1])}
canuse = set()
for i in range(1, N - 1):
for l in left[i]:
for r in right[i]:
canuse |= {str(l) + S[i] + str(r)}
print((len(canuse)))
return 0
if __name__ == "__main__":
solve()
| def solve():
N = int(eval(input()))
S = list(eval(input()))
right = [set() for _ in range(N)]
for i in reversed(list(range(N - 1))):
right[i] = right[i + 1] | {S[i + 1]}
left = {S[0]}
PIN = set()
for i in range(1, N - 1):
for ln in left:
for rn in right[i]:
p = ln + S[i] + rn
PIN |= {p}
left |= {S[i]}
print((len(PIN)))
return 0
if __name__ == "__main__":
solve()
| false | 17.391304 | [
"-import sys",
"-from itertools import combinations, permutations",
"-",
"-",
"- input = sys.stdin.readline",
"- S = eval(input())",
"- left = [set() for _ in range(N)]",
"+ S = list(eval(input()))",
"- for i in range(N - 1):",
"- left[i + 1] |= left[i] | {int(S[i])}",
"- ... | false | 0.038628 | 0.06677 | 0.578527 | [
"s269334987",
"s878702053"
] |
u188827677 | p02995 | python | s958892512 | s969276294 | 26 | 23 | 9,080 | 9,052 | Accepted | Accepted | 11.54 | from math import gcd
a,b,c,d = list(map(int, input().split()))
t = c*d//gcd(c,d)
x = (a-1) - ((a-1)//c + (a-1)//d) + (a-1)//t
y = b - (b//c + b//d) + b//t
print((y-x)) | from math import gcd
a,b,c,d = list(map(int, input().split()))
s = b - ((b//c)+(b//d)) + b//((c*d)//gcd(c,d))
t = (a-1) - (((a-1)//c)+((a-1)//d)) + (a-1)//((c*d)//gcd(c,d))
print((s-t)) | 8 | 6 | 168 | 183 | from math import gcd
a, b, c, d = list(map(int, input().split()))
t = c * d // gcd(c, d)
x = (a - 1) - ((a - 1) // c + (a - 1) // d) + (a - 1) // t
y = b - (b // c + b // d) + b // t
print((y - x))
| from math import gcd
a, b, c, d = list(map(int, input().split()))
s = b - ((b // c) + (b // d)) + b // ((c * d) // gcd(c, d))
t = (a - 1) - (((a - 1) // c) + ((a - 1) // d)) + (a - 1) // ((c * d) // gcd(c, d))
print((s - t))
| false | 25 | [
"-t = c * d // gcd(c, d)",
"-x = (a - 1) - ((a - 1) // c + (a - 1) // d) + (a - 1) // t",
"-y = b - (b // c + b // d) + b // t",
"-print((y - x))",
"+s = b - ((b // c) + (b // d)) + b // ((c * d) // gcd(c, d))",
"+t = (a - 1) - (((a - 1) // c) + ((a - 1) // d)) + (a - 1) // ((c * d) // gcd(c, d))",
"+pr... | false | 0.057622 | 0.10306 | 0.55911 | [
"s958892512",
"s969276294"
] |
u179169725 | p03838 | python | s847838835 | s694322226 | 68 | 61 | 61,640 | 61,960 | Accepted | Accepted | 10.29 | # https://atcoder.jp/contests/agc008/tasks/agc008_a
# どう見ても符号反転は1回するのが最適
# ひたすら場合分け
x, y = list(map(int, input().split()))
if x * y < 0: # 異符号ならば答えは一つ
print((abs(abs(x) - abs(y)) + 1))
exit()
elif 0 <= x < y:
print((y - x))
exit()
elif 0 < y < x:
print((2 + x - y))
exit()
elif y == 0 and y < x:
print((1 + x))
exit()
elif x < y <= 0:
print((y - x))
exit()
elif y < x < 0:
print((2 + x - y))
exit()
elif x == 0 and y < x:
print((1 - y))
exit()
raise ValueError()
| # https://atcoder.jp/contests/agc008/tasks/agc008_a
# どう見ても符号反転は1回するのが最適
# ひたすら場合分け
x, y = list(map(int, input().split()))
if x * y < 0: # 異符号ならば答えは一つ
print((abs(abs(x) - abs(y)) + 1))
elif 0 <= x < y:
print((y - x))
elif 0 < y < x:
print((2 + x - y))
elif y == 0 and y < x:
print((1 + x))
elif x < y <= 0:
print((y - x))
elif y < x < 0:
print((2 + x - y))
elif x == 0 and y < x:
print((1 - y))
| 28 | 20 | 529 | 425 | # https://atcoder.jp/contests/agc008/tasks/agc008_a
# どう見ても符号反転は1回するのが最適
# ひたすら場合分け
x, y = list(map(int, input().split()))
if x * y < 0: # 異符号ならば答えは一つ
print((abs(abs(x) - abs(y)) + 1))
exit()
elif 0 <= x < y:
print((y - x))
exit()
elif 0 < y < x:
print((2 + x - y))
exit()
elif y == 0 and y < x:
print((1 + x))
exit()
elif x < y <= 0:
print((y - x))
exit()
elif y < x < 0:
print((2 + x - y))
exit()
elif x == 0 and y < x:
print((1 - y))
exit()
raise ValueError()
| # https://atcoder.jp/contests/agc008/tasks/agc008_a
# どう見ても符号反転は1回するのが最適
# ひたすら場合分け
x, y = list(map(int, input().split()))
if x * y < 0: # 異符号ならば答えは一つ
print((abs(abs(x) - abs(y)) + 1))
elif 0 <= x < y:
print((y - x))
elif 0 < y < x:
print((2 + x - y))
elif y == 0 and y < x:
print((1 + x))
elif x < y <= 0:
print((y - x))
elif y < x < 0:
print((2 + x - y))
elif x == 0 and y < x:
print((1 - y))
| false | 28.571429 | [
"- exit()",
"- exit()",
"- exit()",
"- exit()",
"- exit()",
"- exit()",
"- exit()",
"-raise ValueError()"
] | false | 0.039652 | 0.084016 | 0.471961 | [
"s847838835",
"s694322226"
] |
u353919145 | p02879 | python | s583071387 | s427020781 | 348 | 28 | 84,932 | 9,048 | Accepted | Accepted | 91.95 | s = input()
a,b = s.split(' ')
a,b = int(a),int(b)
def mul(a,b):
if a <= 9 and a >=1 and (1 <= b <= 9):
return a * b
else:
return -1
print(mul(a,b)) | a,b = input().split()
a=int(a)
b=int(b)
if a>=1 and a<=9 and b>=1 and b<=9:
print((a*b))
else: print("-1") | 11 | 8 | 187 | 117 | s = input()
a, b = s.split(" ")
a, b = int(a), int(b)
def mul(a, b):
if a <= 9 and a >= 1 and (1 <= b <= 9):
return a * b
else:
return -1
print(mul(a, b))
| a, b = input().split()
a = int(a)
b = int(b)
if a >= 1 and a <= 9 and b >= 1 and b <= 9:
print((a * b))
else:
print("-1")
| false | 27.272727 | [
"-s = input()",
"-a, b = s.split(\" \")",
"-a, b = int(a), int(b)",
"-",
"-",
"-def mul(a, b):",
"- if a <= 9 and a >= 1 and (1 <= b <= 9):",
"- return a * b",
"- else:",
"- return -1",
"-",
"-",
"-print(mul(a, b))",
"+a, b = input().split()",
"+a = int(a)",
"+b = i... | false | 0.037567 | 0.037281 | 1.007677 | [
"s583071387",
"s427020781"
] |
u119148115 | p02606 | python | s306569044 | s697927240 | 77 | 65 | 61,740 | 61,832 | Accepted | Accepted | 15.58 | import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
L,R,d = LI()
print((R//d-(L-1)//d))
| import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
L,R,d = LI()
print((R//d-(L-1)//d)) | 13 | 6 | 462 | 128 | import sys
sys.setrecursionlimit(10**7)
def I():
return int(sys.stdin.readline().rstrip())
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
def LI2():
return list(map(int, sys.stdin.readline().rstrip())) # 空白なし
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split()) # 空白あり
def LS2():
return list(sys.stdin.readline().rstrip()) # 空白なし
L, R, d = LI()
print((R // d - (L - 1) // d))
| import sys
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
L, R, d = LI()
print((R // d - (L - 1) // d))
| false | 53.846154 | [
"-",
"-sys.setrecursionlimit(10**7)",
"-",
"-",
"-def I():",
"- return int(sys.stdin.readline().rstrip())",
"-def LI2():",
"- return list(map(int, sys.stdin.readline().rstrip())) # 空白なし",
"-",
"-",
"-def S():",
"- return sys.stdin.readline().rstrip()",
"-",
"-",
"-def LS():",
... | false | 0.036201 | 0.035591 | 1.017161 | [
"s306569044",
"s697927240"
] |
u563722393 | p03067 | python | s151681934 | s381937086 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | A, B, C = ( int(i) for i in input().split() )
if A <= C <= B:
print('Yes')
elif B <= C <= A:
print('Yes')
else:
print('No') | A, B, C = ( int(i) for i in input().split() )
if A < C < B:
print('Yes')
elif B < C < A:
print('Yes')
else:
print('No') | 8 | 8 | 137 | 133 | A, B, C = (int(i) for i in input().split())
if A <= C <= B:
print("Yes")
elif B <= C <= A:
print("Yes")
else:
print("No")
| A, B, C = (int(i) for i in input().split())
if A < C < B:
print("Yes")
elif B < C < A:
print("Yes")
else:
print("No")
| false | 0 | [
"-if A <= C <= B:",
"+if A < C < B:",
"-elif B <= C <= A:",
"+elif B < C < A:"
] | false | 0.16366 | 0.094964 | 1.723386 | [
"s151681934",
"s381937086"
] |
u573754721 | p02916 | python | s354398092 | s656251402 | 177 | 17 | 38,384 | 3,064 | Accepted | Accepted | 90.4 | N = int(eval(input()))
li_a =list(map(int, input().split()))
li_b =list(map(int, input().split()))
li_c =list(map(int, input().split()))
before = -99
points = 0
for i in li_a:
points += li_b[i - 1]
if before + 1 == i:
points += li_c[i - 2]
before = i
print(points) | n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
s=sum(b)
add_s=0
for i in range(n-1):
if a[i]==a[i+1]-1:
add_s += c[a[i]-1]
print((s+add_s)) | 13 | 11 | 301 | 233 | N = int(eval(input()))
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))
before = -99
points = 0
for i in li_a:
points += li_b[i - 1]
if before + 1 == i:
points += li_c[i - 2]
before = i
print(points)
| n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
s = sum(b)
add_s = 0
for i in range(n - 1):
if a[i] == a[i + 1] - 1:
add_s += c[a[i] - 1]
print((s + add_s))
| false | 15.384615 | [
"-N = int(eval(input()))",
"-li_a = list(map(int, input().split()))",
"-li_b = list(map(int, input().split()))",
"-li_c = list(map(int, input().split()))",
"-before = -99",
"-points = 0",
"-for i in li_a:",
"- points += li_b[i - 1]",
"- if before + 1 == i:",
"- points += li_c[i - 2]",... | false | 0.095129 | 0.045709 | 2.081173 | [
"s354398092",
"s656251402"
] |
u588093355 | p03371 | python | s336631257 | s554721032 | 65 | 17 | 3,060 | 2,940 | Accepted | Accepted | 73.85 | #!/usr/bin/env python3
def main():
(A,B,C,X,Y) = list(map(int,input().split()))
lim = max(X, Y)
vmin = min(X, Y)
minCost = 5000 * 10**5 * 2
for t in range(lim+1):
if t <= vmin:
cost = (X - t) * A + (Y - t) * B + t * 2 * C
elif X <= Y:
cost = (Y - t) * B + t * 2 * C
else:
cost = (X - t) * A + t * 2 * C
minCost = min(minCost, cost)
print(minCost)
main()
| def main():
(A,B,C,X,Y) = list(map(int,input().split()))
if X < Y:
X, Y = Y, X
A, B = B, A
print((min(A + B, 2 * C) * Y + min(A, 2*C) * (X - Y)))
main()
| 19 | 8 | 465 | 181 | #!/usr/bin/env python3
def main():
(A, B, C, X, Y) = list(map(int, input().split()))
lim = max(X, Y)
vmin = min(X, Y)
minCost = 5000 * 10**5 * 2
for t in range(lim + 1):
if t <= vmin:
cost = (X - t) * A + (Y - t) * B + t * 2 * C
elif X <= Y:
cost = (Y - t) * B + t * 2 * C
else:
cost = (X - t) * A + t * 2 * C
minCost = min(minCost, cost)
print(minCost)
main()
| def main():
(A, B, C, X, Y) = list(map(int, input().split()))
if X < Y:
X, Y = Y, X
A, B = B, A
print((min(A + B, 2 * C) * Y + min(A, 2 * C) * (X - Y)))
main()
| false | 57.894737 | [
"-#!/usr/bin/env python3",
"- lim = max(X, Y)",
"- vmin = min(X, Y)",
"- minCost = 5000 * 10**5 * 2",
"- for t in range(lim + 1):",
"- if t <= vmin:",
"- cost = (X - t) * A + (Y - t) * B + t * 2 * C",
"- elif X <= Y:",
"- cost = (Y - t) * B + t * 2 * C... | false | 0.119247 | 0.137557 | 0.866891 | [
"s336631257",
"s554721032"
] |
u340040203 | p02773 | python | s067019954 | s749861752 | 551 | 446 | 59,496 | 35,896 | Accepted | Accepted | 19.06 | import sys
import collections
input = lambda: sys.stdin.readline().rstrip()
def main():
n = int(input())
s = [input() for _ in range(n)]
cnt = collections.Counter(s)
values, counts = zip(*cnt.most_common())
d = sorted(values[:counts.count(counts[0])])
print(*d, sep='\n')
if __name__ == '__main__':
main()
| import sys
import collections
input = lambda: sys.stdin.readline().rstrip()
def main():
n = int(input())
s = [input() for _ in range(n)]
cnt = collections.Counter(s)
cnt_max = max(cnt.values())
d = [k for k, v in cnt.items() if v == cnt_max]
d = sorted(d)
print(*d, sep='\n')
if __name__ == '__main__':
main()
| 14 | 15 | 348 | 357 | import sys
import collections
input = lambda: sys.stdin.readline().rstrip()
def main():
n = int(input())
s = [input() for _ in range(n)]
cnt = collections.Counter(s)
values, counts = zip(*cnt.most_common())
d = sorted(values[: counts.count(counts[0])])
print(*d, sep="\n")
if __name__ == "__main__":
main()
| import sys
import collections
input = lambda: sys.stdin.readline().rstrip()
def main():
n = int(input())
s = [input() for _ in range(n)]
cnt = collections.Counter(s)
cnt_max = max(cnt.values())
d = [k for k, v in cnt.items() if v == cnt_max]
d = sorted(d)
print(*d, sep="\n")
if __name__ == "__main__":
main()
| false | 6.666667 | [
"- values, counts = zip(*cnt.most_common())",
"- d = sorted(values[: counts.count(counts[0])])",
"+ cnt_max = max(cnt.values())",
"+ d = [k for k, v in cnt.items() if v == cnt_max]",
"+ d = sorted(d)"
] | false | 0.082543 | 0.066678 | 1.237936 | [
"s067019954",
"s749861752"
] |
u773265208 | p03545 | python | s826556825 | s197492778 | 168 | 17 | 38,384 | 3,060 | Accepted | Accepted | 89.88 | import sys
s = eval(input())
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
ans = a
for i in range(2):
if i == 0:
ans += b
s1 = '+'
else:
ans -= b
s1 = '-'
for j in range(2):
if j == 0:
ans += c
s2 = '+'
else:
ans -= c
s2 = '-'
for k in range(2):
if k == 0:
ans += d
s3 = '+'
else:
ans -= d
s3 = '-'
if ans == 7:
print((s[0]+s1+s[1]+s2+s[2]+s3+s[3]+"=7"))
sys.exit()
else:
if k == 0:
ans -= d
else:
ans += d
if j == 0:
ans -= c
else:
ans += c
if i == 0:
ans -= b
else:
ans += b
| import sys
s = eval(input())
n = 3
for i in range(2**(n)):
op = ["-"]*3
for j in range(n):
if i & (1<<j):
op[j] = "+"
res = ""
for a,b in zip(s,op+[""]):
res += a+b
if eval(res) == 7:
print((res+'=7'))
sys.exit()
| 49 | 17 | 631 | 240 | import sys
s = eval(input())
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
ans = a
for i in range(2):
if i == 0:
ans += b
s1 = "+"
else:
ans -= b
s1 = "-"
for j in range(2):
if j == 0:
ans += c
s2 = "+"
else:
ans -= c
s2 = "-"
for k in range(2):
if k == 0:
ans += d
s3 = "+"
else:
ans -= d
s3 = "-"
if ans == 7:
print((s[0] + s1 + s[1] + s2 + s[2] + s3 + s[3] + "=7"))
sys.exit()
else:
if k == 0:
ans -= d
else:
ans += d
if j == 0:
ans -= c
else:
ans += c
if i == 0:
ans -= b
else:
ans += b
| import sys
s = eval(input())
n = 3
for i in range(2 ** (n)):
op = ["-"] * 3
for j in range(n):
if i & (1 << j):
op[j] = "+"
res = ""
for a, b in zip(s, op + [""]):
res += a + b
if eval(res) == 7:
print((res + "=7"))
sys.exit()
| false | 65.306122 | [
"-a = int(s[0])",
"-b = int(s[1])",
"-c = int(s[2])",
"-d = int(s[3])",
"-ans = a",
"-for i in range(2):",
"- if i == 0:",
"- ans += b",
"- s1 = \"+\"",
"- else:",
"- ans -= b",
"- s1 = \"-\"",
"- for j in range(2):",
"- if j == 0:",
"- ... | false | 0.112082 | 0.040709 | 2.753217 | [
"s826556825",
"s197492778"
] |
u867826040 | p02779 | python | s484140285 | s206341950 | 170 | 101 | 38,836 | 27,968 | Accepted | Accepted | 40.59 | s = int(eval(input()))
a = list(map(str, input().split()))
n = {}
for i in a:
n.setdefault(i, 0)
for i in a:
n[i] += 1
x = 0
for i in list(n.values()):
if x <= i:
x = i
if x == 1:
print("YES")
else:
print("NO") | n = eval(input())
a = list(map(int,input().split()))
if len(set(a)) == len(a):
print("YES")
elif len(set(a)) != len(a):
print("NO") | 15 | 6 | 226 | 134 | s = int(eval(input()))
a = list(map(str, input().split()))
n = {}
for i in a:
n.setdefault(i, 0)
for i in a:
n[i] += 1
x = 0
for i in list(n.values()):
if x <= i:
x = i
if x == 1:
print("YES")
else:
print("NO")
| n = eval(input())
a = list(map(int, input().split()))
if len(set(a)) == len(a):
print("YES")
elif len(set(a)) != len(a):
print("NO")
| false | 60 | [
"-s = int(eval(input()))",
"-a = list(map(str, input().split()))",
"-n = {}",
"-for i in a:",
"- n.setdefault(i, 0)",
"-for i in a:",
"- n[i] += 1",
"-x = 0",
"-for i in list(n.values()):",
"- if x <= i:",
"- x = i",
"-if x == 1:",
"+n = eval(input())",
"+a = list(map(int, ... | false | 0.037025 | 0.036709 | 1.008623 | [
"s484140285",
"s206341950"
] |
u585482323 | p02881 | python | s303955015 | s473473699 | 197 | 180 | 39,664 | 38,512 | Accepted | Accepted | 8.63 | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
def f(n):
if n < 4:
return [1,n]
res = [1]
i = 2
while i*i <= n:
if n%i == 0:
res.append(i)
m = n//i
if m != i:
res.append(m)
i += 1
res.append(n)
return res
n = I()
l = f(n)
ans = float("inf")
for x in l:
m = x+n//x-2
if m < ans:
ans = m
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
for i in range(int(n**0.5)+2)[::-1]:
if not n%i:
print((n//i+i-2))
return
return
#Solve
if __name__ == "__main__":
solve()
| 56 | 38 | 1,249 | 944 | #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
def f(n):
if n < 4:
return [1, n]
res = [1]
i = 2
while i * i <= n:
if n % i == 0:
res.append(i)
m = n // i
if m != i:
res.append(m)
i += 1
res.append(n)
return res
n = I()
l = f(n)
ans = float("inf")
for x in l:
m = x + n // x - 2
if m < ans:
ans = m
print(ans)
return
# Solve
if __name__ == "__main__":
solve()
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI():
return [int(x) for x in sys.stdin.buffer.readline().split()]
def I():
return int(sys.stdin.buffer.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
for i in range(int(n**0.5) + 2)[::-1]:
if not n % i:
print((n // i + i - 2))
return
return
# Solve
if __name__ == "__main__":
solve()
| false | 32.142857 | [
"+from itertools import permutations, accumulate",
"-import random",
"- return [int(x) for x in sys.stdin.readline().split()]",
"+ return [int(x) for x in sys.stdin.buffer.readline().split()]",
"- return int(sys.stdin.readline())",
"+ return int(sys.stdin.buffer.readline())",
"- def f(n):... | false | 0.039361 | 0.041394 | 0.950888 | [
"s303955015",
"s473473699"
] |
u475065881 | p03283 | python | s429719626 | s698825334 | 584 | 528 | 8,676 | 8,668 | Accepted | Accepted | 9.59 | import sys
from itertools import accumulate
N, M, Q = list(map(int, sys.stdin.readline().split()))
LR = [[0 for _ in range(N-i)] for i in range(N)]
for i in range(M):
L, R = list(map(int, sys.stdin.readline().split()))
LR[L-1][R-L] += 1
for i in range(N-2,-1,-1):
for j, (acc, pre) in enumerate(zip(accumulate(LR[i]), [0]+LR[i+1])):
LR[i][j] = acc + pre
for i in range(Q):
p, q = list(map(int, sys.stdin.readline().split()))
sys.stdout.write(str(LR[p-1][q-p])+"\n") | import sys
from itertools import accumulate
N, M, Q = list(map(int, sys.stdin.readline().split()))
LR = [[0 for _ in range(N-i)] for i in range(N)]
for i in range(M):
L, R = list(map(int, sys.stdin.readline().split()))
LR[L-1][R-L] += 1
for i in range(N-2,-1,-1):
acc = accumulate(LR[i])
next(acc)
for j in range(1, N-i):
LR[i][j] = next(acc) + LR[i+1][j-1]
for i in range(Q):
p, q = list(map(int, sys.stdin.readline().split()))
sys.stdout.write(str(LR[p-1][q-p])+"\n") | 16 | 18 | 479 | 492 | import sys
from itertools import accumulate
N, M, Q = list(map(int, sys.stdin.readline().split()))
LR = [[0 for _ in range(N - i)] for i in range(N)]
for i in range(M):
L, R = list(map(int, sys.stdin.readline().split()))
LR[L - 1][R - L] += 1
for i in range(N - 2, -1, -1):
for j, (acc, pre) in enumerate(zip(accumulate(LR[i]), [0] + LR[i + 1])):
LR[i][j] = acc + pre
for i in range(Q):
p, q = list(map(int, sys.stdin.readline().split()))
sys.stdout.write(str(LR[p - 1][q - p]) + "\n")
| import sys
from itertools import accumulate
N, M, Q = list(map(int, sys.stdin.readline().split()))
LR = [[0 for _ in range(N - i)] for i in range(N)]
for i in range(M):
L, R = list(map(int, sys.stdin.readline().split()))
LR[L - 1][R - L] += 1
for i in range(N - 2, -1, -1):
acc = accumulate(LR[i])
next(acc)
for j in range(1, N - i):
LR[i][j] = next(acc) + LR[i + 1][j - 1]
for i in range(Q):
p, q = list(map(int, sys.stdin.readline().split()))
sys.stdout.write(str(LR[p - 1][q - p]) + "\n")
| false | 11.111111 | [
"- for j, (acc, pre) in enumerate(zip(accumulate(LR[i]), [0] + LR[i + 1])):",
"- LR[i][j] = acc + pre",
"+ acc = accumulate(LR[i])",
"+ next(acc)",
"+ for j in range(1, N - i):",
"+ LR[i][j] = next(acc) + LR[i + 1][j - 1]"
] | false | 0.046814 | 0.04835 | 0.968237 | [
"s429719626",
"s698825334"
] |
u817760251 | p02983 | python | s457457617 | s376391570 | 886 | 774 | 2,940 | 2,940 | Accepted | Accepted | 12.64 | l, r = list(map(int, input().split()))
mod = 2019
if r - l > 3000:
print((0))
else:
ans = mod
for i in range(l, r + 1):
for j in range(r, l, -1):
#print(str(i) + ' ' + str(j))
if j <= i: break
ans = min(ans, (i * j) % mod)
print(ans)
| l, r = list(map(int, input().split()))
if r - l > 3000:
print((0))
else:
ans = 3000
for i in range(l, r + 1):
for j in range(i + 1, r + 1):
ans = min(ans, i * j % 2019)
print(ans)
| 13 | 10 | 274 | 202 | l, r = list(map(int, input().split()))
mod = 2019
if r - l > 3000:
print((0))
else:
ans = mod
for i in range(l, r + 1):
for j in range(r, l, -1):
# print(str(i) + ' ' + str(j))
if j <= i:
break
ans = min(ans, (i * j) % mod)
print(ans)
| l, r = list(map(int, input().split()))
if r - l > 3000:
print((0))
else:
ans = 3000
for i in range(l, r + 1):
for j in range(i + 1, r + 1):
ans = min(ans, i * j % 2019)
print(ans)
| false | 23.076923 | [
"-mod = 2019",
"- ans = mod",
"+ ans = 3000",
"- for j in range(r, l, -1):",
"- # print(str(i) + ' ' + str(j))",
"- if j <= i:",
"- break",
"- ans = min(ans, (i * j) % mod)",
"+ for j in range(i + 1, r + 1):",
"+ ans = ... | false | 0.124502 | 0.107316 | 1.160146 | [
"s457457617",
"s376391570"
] |
u003475507 | p03037 | python | s054848442 | s939962239 | 359 | 124 | 16,628 | 9,076 | Accepted | Accepted | 65.46 | n,a = list(map(int,input().split()))
m = [tuple(map(int,input().split())) for _ in range(a)]
l,r=m[0][0],m[0][1]
for i in range(1,a):
l = max(m[i][0],l)
r = min(m[i][1],r)
print((max(r-l+1,0)))
| import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline
n,m = list(map(int,input().split()))
ansl=-1
ansr=10**6
for _ in range(m):
l,r=list(map(int,input().split()))
ansl=max(ansl,l)
ansr=min(ansr,r)
print((max(ansr-ansl+1,0))) | 10 | 15 | 206 | 255 | n, a = list(map(int, input().split()))
m = [tuple(map(int, input().split())) for _ in range(a)]
l, r = m[0][0], m[0][1]
for i in range(1, a):
l = max(m[i][0], l)
r = min(m[i][1], r)
print((max(r - l + 1, 0)))
| import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
ansl = -1
ansr = 10**6
for _ in range(m):
l, r = list(map(int, input().split()))
ansl = max(ansl, l)
ansr = min(ansr, r)
print((max(ansr - ansl + 1, 0)))
| false | 33.333333 | [
"-n, a = list(map(int, input().split()))",
"-m = [tuple(map(int, input().split())) for _ in range(a)]",
"-l, r = m[0][0], m[0][1]",
"-for i in range(1, a):",
"- l = max(m[i][0], l)",
"- r = min(m[i][1], r)",
"-print((max(r - l + 1, 0)))",
"+import sys",
"+",
"+sys.setrecursionlimit(10000000)... | false | 0.03676 | 0.03752 | 0.979748 | [
"s054848442",
"s939962239"
] |
u498487134 | p03780 | python | s311433104 | s104954443 | 1,079 | 197 | 39,536 | 39,408 | Accepted | Accepted | 81.74 | def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
N,K=MI()
a=LI()#下位の連続するn枚が不要なはず
a.sort()
for i in range(N):#K以上ならば必要
if a[i]>=K:
a=a[:i]
break
N=len(a)
#x番目の数が必要かどうかの判定
#必要なものだけで構成された集合をもとに考えれば良いわけではない,不必要な分も考えなければならない
def ch(x):
#使い回す,i番目まででjが作れるか
dp=[0]*K
dp[0]=1
for i in range(N):
if i==x:
continue
else:
for j in range(K-1,a[i]-1,-1):
dp[j]|=dp[j-a[i]]
#K未満K-a[x]以上が作れれば良い
for j in range(K-a[x],K):
if dp[j]:
return True
return False
ng=-1
ok=N
while abs(ok-ng)>1:
med=(ok+ng)//2
if ch(med):
ok=med
else:
ng=med
print((ng+1))
main()
| def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
N,K=MI()
a=LI()#下位の連続するn枚が不要なはず
a.sort(reverse=True)
#大きい方から順に足していき,K未満の最大の和を作っておく.これに対して,足してK以上になるのならそれは必要.K未満なら端しておく.
#最終的に必要なもののうち最も小さいものがわかるはず
temp=0
ans=N
for i in range(N):
if temp+a[i]<K:
temp+=a[i]
else:
ans=min(ans,N-i-1)
print(ans)
main()
| 61 | 27 | 1,201 | 521 | def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def main():
N, K = MI()
a = LI() # 下位の連続するn枚が不要なはず
a.sort()
for i in range(N): # K以上ならば必要
if a[i] >= K:
a = a[:i]
break
N = len(a)
# x番目の数が必要かどうかの判定
# 必要なものだけで構成された集合をもとに考えれば良いわけではない,不必要な分も考えなければならない
def ch(x):
# 使い回す,i番目まででjが作れるか
dp = [0] * K
dp[0] = 1
for i in range(N):
if i == x:
continue
else:
for j in range(K - 1, a[i] - 1, -1):
dp[j] |= dp[j - a[i]]
# K未満K-a[x]以上が作れれば良い
for j in range(K - a[x], K):
if dp[j]:
return True
return False
ng = -1
ok = N
while abs(ok - ng) > 1:
med = (ok + ng) // 2
if ch(med):
ok = med
else:
ng = med
print((ng + 1))
main()
| def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def main():
N, K = MI()
a = LI() # 下位の連続するn枚が不要なはず
a.sort(reverse=True)
# 大きい方から順に足していき,K未満の最大の和を作っておく.これに対して,足してK以上になるのならそれは必要.K未満なら端しておく.
# 最終的に必要なもののうち最も小さいものがわかるはず
temp = 0
ans = N
for i in range(N):
if temp + a[i] < K:
temp += a[i]
else:
ans = min(ans, N - i - 1)
print(ans)
main()
| false | 55.737705 | [
"- a.sort()",
"- for i in range(N): # K以上ならば必要",
"- if a[i] >= K:",
"- a = a[:i]",
"- break",
"- N = len(a)",
"- # x番目の数が必要かどうかの判定",
"- # 必要なものだけで構成された集合をもとに考えれば良いわけではない,不必要な分も考えなければならない",
"- def ch(x):",
"- # 使い回す,i番目まででjが作れるか",
"- d... | false | 0.038636 | 0.038869 | 0.994004 | [
"s311433104",
"s104954443"
] |
u046187684 | p02714 | python | s888595580 | s733868360 | 1,456 | 480 | 9,292 | 9,480 | Accepted | Accepted | 67.03 | def count_bigger(a, b):
i = j = 0
c = []
while i < len(a) and j < len(b):
if a[i] >= b[j]:
j += 1
continue
c.append(len(b) - j)
i += 1
if len(c) < len(a):
c += [0] * (len(a) - len(c))
for i in range(len(c) - 1, 0, -1):
c[i - 1] += c[i]
return c
def f(a, b, c):
bc = count_bigger(b, c)
i = j = ans = 0
while i < len(a) and j < len(b):
if a[i] >= b[j]:
j += 1
continue
ans += bc[j] - len(set(c) & set(2 * _b - a[i] for _b in b[j:]))
i += 1
return ans
def solve(string):
n, s = string.split()
r, g, b = [], [], []
for i, _s in enumerate(s):
if _s == "R":
r.append(i)
if _s == "G":
g.append(i)
if _s == "B":
b.append(i)
return str(f(r, g, b) + f(r, b, g) + f(b, r, g) + f(b, g, r) + f(g, r, b) + f(g, b, r))
if __name__ == '__main__':
import sys
print((solve(sys.stdin.read().strip())))
| from itertools import product
def solve(string):
n, s = string.split()
r, g, b = [], [], []
r2, g2, b2 = set([]), set([]), set([])
for i, _s in enumerate(s):
if _s == "R":
r.append(i)
r2.add(2 * i)
if _s == "G":
g.append(i)
g2.add(2 * i)
if _s == "B":
b.append(i)
b2.add(2 * i)
ans = len(r) * len(g) * len(b)
for i, j in product(r, g):
ans -= 1 if i + j in b2 else 0
for i, j in product(g, b):
ans -= 1 if i + j in r2 else 0
for i, j in product(b, r):
ans -= 1 if i + j in g2 else 0
return str(ans)
if __name__ == '__main__':
import sys
print((solve(sys.stdin.read().strip())))
| 44 | 30 | 1,066 | 773 | def count_bigger(a, b):
i = j = 0
c = []
while i < len(a) and j < len(b):
if a[i] >= b[j]:
j += 1
continue
c.append(len(b) - j)
i += 1
if len(c) < len(a):
c += [0] * (len(a) - len(c))
for i in range(len(c) - 1, 0, -1):
c[i - 1] += c[i]
return c
def f(a, b, c):
bc = count_bigger(b, c)
i = j = ans = 0
while i < len(a) and j < len(b):
if a[i] >= b[j]:
j += 1
continue
ans += bc[j] - len(set(c) & set(2 * _b - a[i] for _b in b[j:]))
i += 1
return ans
def solve(string):
n, s = string.split()
r, g, b = [], [], []
for i, _s in enumerate(s):
if _s == "R":
r.append(i)
if _s == "G":
g.append(i)
if _s == "B":
b.append(i)
return str(
f(r, g, b) + f(r, b, g) + f(b, r, g) + f(b, g, r) + f(g, r, b) + f(g, b, r)
)
if __name__ == "__main__":
import sys
print((solve(sys.stdin.read().strip())))
| from itertools import product
def solve(string):
n, s = string.split()
r, g, b = [], [], []
r2, g2, b2 = set([]), set([]), set([])
for i, _s in enumerate(s):
if _s == "R":
r.append(i)
r2.add(2 * i)
if _s == "G":
g.append(i)
g2.add(2 * i)
if _s == "B":
b.append(i)
b2.add(2 * i)
ans = len(r) * len(g) * len(b)
for i, j in product(r, g):
ans -= 1 if i + j in b2 else 0
for i, j in product(g, b):
ans -= 1 if i + j in r2 else 0
for i, j in product(b, r):
ans -= 1 if i + j in g2 else 0
return str(ans)
if __name__ == "__main__":
import sys
print((solve(sys.stdin.read().strip())))
| false | 31.818182 | [
"-def count_bigger(a, b):",
"- i = j = 0",
"- c = []",
"- while i < len(a) and j < len(b):",
"- if a[i] >= b[j]:",
"- j += 1",
"- continue",
"- c.append(len(b) - j)",
"- i += 1",
"- if len(c) < len(a):",
"- c += [0] * (len(a) - len(c)... | false | 0.033543 | 0.036625 | 0.915859 | [
"s888595580",
"s733868360"
] |
u475503988 | p03090 | python | s281686292 | s842994103 | 32 | 26 | 3,996 | 3,956 | Accepted | Accepted | 18.75 | n = int(eval(input()))
ans = []
if n % 2 == 0:
temp = n + 1
else:
temp = n
for i in range(1, n):
for j in range(i+1, n+1):
if i + j != temp:
ans.append((i, j))
print((len(ans)))
for a in ans:
print((a[0], a[1])) | n = int(eval(input()))
ans = []
if n % 2 == 0:
temp = n + 1
else:
temp = n
for i in range(1, n):
for j in range(i+1, n+1):
if i + j == temp:
continue
else:
ans.append((i, j))
print((len(ans)))
for a in ans:
print((a[0], a[1]))
| 16 | 18 | 255 | 293 | n = int(eval(input()))
ans = []
if n % 2 == 0:
temp = n + 1
else:
temp = n
for i in range(1, n):
for j in range(i + 1, n + 1):
if i + j != temp:
ans.append((i, j))
print((len(ans)))
for a in ans:
print((a[0], a[1]))
| n = int(eval(input()))
ans = []
if n % 2 == 0:
temp = n + 1
else:
temp = n
for i in range(1, n):
for j in range(i + 1, n + 1):
if i + j == temp:
continue
else:
ans.append((i, j))
print((len(ans)))
for a in ans:
print((a[0], a[1]))
| false | 11.111111 | [
"- if i + j != temp:",
"+ if i + j == temp:",
"+ continue",
"+ else:"
] | false | 0.035311 | 0.038653 | 0.913539 | [
"s281686292",
"s842994103"
] |
u540761833 | p02873 | python | s633650625 | s032876886 | 241 | 133 | 6,300 | 12,336 | Accepted | Accepted | 44.81 | S = eval(input())
ans = 0
a = []
up = True
count = 0
for i in S:
if up:
if i == '>':
a.append(count)
count = 1
up = False
else:
count += 1
else:
if i == '<':
a.append(count)
count = 1
up = True
else:
count += 1
a.append(count)
if len(a)%2 == 1:
a.append(0)
for i in range(0,len(a),2):
u,d = max(a[i],a[i+1]), min(a[i],a[i+1])-1
ans += u*(u+1)//2 + d*(d+1)//2
print(ans)
| S = input().replace('><','> <').split()
ans = 0
for s in S:
up = s.count('<')
down = len(s)-up
if up < down:
up -= 1
ans += up*(up+1)//2 + down*(down+1)//2
else:
down -= 1
ans += up*(up+1)//2 + down*(down+1)//2
print(ans) | 28 | 12 | 543 | 288 | S = eval(input())
ans = 0
a = []
up = True
count = 0
for i in S:
if up:
if i == ">":
a.append(count)
count = 1
up = False
else:
count += 1
else:
if i == "<":
a.append(count)
count = 1
up = True
else:
count += 1
a.append(count)
if len(a) % 2 == 1:
a.append(0)
for i in range(0, len(a), 2):
u, d = max(a[i], a[i + 1]), min(a[i], a[i + 1]) - 1
ans += u * (u + 1) // 2 + d * (d + 1) // 2
print(ans)
| S = input().replace("><", "> <").split()
ans = 0
for s in S:
up = s.count("<")
down = len(s) - up
if up < down:
up -= 1
ans += up * (up + 1) // 2 + down * (down + 1) // 2
else:
down -= 1
ans += up * (up + 1) // 2 + down * (down + 1) // 2
print(ans)
| false | 57.142857 | [
"-S = eval(input())",
"+S = input().replace(\"><\", \"> <\").split()",
"-a = []",
"-up = True",
"-count = 0",
"-for i in S:",
"- if up:",
"- if i == \">\":",
"- a.append(count)",
"- count = 1",
"- up = False",
"- else:",
"- count +... | false | 0.03666 | 0.042438 | 0.863848 | [
"s633650625",
"s032876886"
] |
u888337853 | p02574 | python | s726892318 | s259370557 | 1,467 | 1,345 | 303,840 | 305,520 | Accepted | Accepted | 8.32 | import sys
import math
import collections
import bisect
import itertools
import decimal
# import numpy as np
# sys.setrecursionlimit(10 ** 6)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().rstrip().split()])
# ===CODE===
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
n = ni()
a = na()
tmp = len(a)
# 素数列挙
def Eratosthenes(n): # N以下のすべての値に対して素数を返す
a = [[] for _ in range(n + 1)]
if n >= 2:
for i in range(2, n + 1):
if len(a[i]) == 0:
for j in range(i, n + 1, i):
a[j].append(i)
return a
l = max(a)
p = Eratosthenes(l)
cnt = [0 for _ in range(l + 1)]
pc = True
tc = True
for ai in a:
for pi in p[ai]:
cnt[pi] += 1
if cnt[pi] >1:
pc = False
if cnt[pi] == n:
tc = False
break
if pc:
print("pairwise coprime")
elif tc:
print("setwise coprime")
else:
print("not coprime")
if __name__ == '__main__':
main()
| import sys
import math
import collections
import bisect
import itertools
import decimal
# import numpy as np
# sys.setrecursionlimit(10 ** 6)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().rstrip().split()])
# ===CODE===
def main():
n = ni()
a = na()
tmp = len(a)
# 素数列挙
def Eratosthenes(n): # N以下のすべての値に対して素数を返す
a = [[] for _ in range(n + 1)]
if n >= 2:
for i in range(2, n + 1):
if len(a[i]) == 0:
for j in range(i, n + 1, i):
a[j].append(i)
return a
l = max(a)
p = Eratosthenes(l)
cnt = [0 for _ in range(l + 1)]
pc = True
tc = True
for ai in a:
for pi in p[ai]:
cnt[pi] += 1
if cnt[pi] >1:
pc = False
if cnt[pi] == n:
tc = False
break
if pc:
print("pairwise coprime")
elif tc:
print("setwise coprime")
else:
print("not coprime")
if __name__ == '__main__':
main()
| 113 | 64 | 2,561 | 1,363 | import sys
import math
import collections
import bisect
import itertools
import decimal
# import numpy as np
# sys.setrecursionlimit(10 ** 6)
INF = 10**20
MOD = 10**9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().rstrip().split()])
# ===CODE===
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
def main():
n = ni()
a = na()
tmp = len(a)
# 素数列挙
def Eratosthenes(n): # N以下のすべての値に対して素数を返す
a = [[] for _ in range(n + 1)]
if n >= 2:
for i in range(2, n + 1):
if len(a[i]) == 0:
for j in range(i, n + 1, i):
a[j].append(i)
return a
l = max(a)
p = Eratosthenes(l)
cnt = [0 for _ in range(l + 1)]
pc = True
tc = True
for ai in a:
for pi in p[ai]:
cnt[pi] += 1
if cnt[pi] > 1:
pc = False
if cnt[pi] == n:
tc = False
break
if pc:
print("pairwise coprime")
elif tc:
print("setwise coprime")
else:
print("not coprime")
if __name__ == "__main__":
main()
| import sys
import math
import collections
import bisect
import itertools
import decimal
# import numpy as np
# sys.setrecursionlimit(10 ** 6)
INF = 10**20
MOD = 10**9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().rstrip().split()])
# ===CODE===
def main():
n = ni()
a = na()
tmp = len(a)
# 素数列挙
def Eratosthenes(n): # N以下のすべての値に対して素数を返す
a = [[] for _ in range(n + 1)]
if n >= 2:
for i in range(2, n + 1):
if len(a[i]) == 0:
for j in range(i, n + 1, i):
a[j].append(i)
return a
l = max(a)
p = Eratosthenes(l)
cnt = [0 for _ in range(l + 1)]
pc = True
tc = True
for ai in a:
for pi in p[ai]:
cnt[pi] += 1
if cnt[pi] > 1:
pc = False
if cnt[pi] == n:
tc = False
break
if pc:
print("pairwise coprime")
elif tc:
print("setwise coprime")
else:
print("not coprime")
if __name__ == "__main__":
main()
| false | 43.362832 | [
"-class UnionFind:",
"- def __init__(self, n):",
"- self.n = n",
"- self.parents = [-1] * n",
"-",
"- def find(self, x):",
"- if self.parents[x] < 0:",
"- return x",
"- else:",
"- self.parents[x] = self.find(self.parents[x])",
"- ... | false | 0.051487 | 0.048819 | 1.054666 | [
"s726892318",
"s259370557"
] |
u558242240 | p02695 | python | s049764615 | s519366853 | 938 | 727 | 9,200 | 9,248 | Accepted | Accepted | 22.49 | n, m, q = list(map(int, input().split()))
abcd = [tuple(map(int, input().split())) for _ in range(q)]
ans = 0
import itertools
for i in itertools.combinations_with_replacement(list(range(1, m+1)), n):
sumd = 0
for j in abcd:
if i[j[1]-1] - i[j[0]-1] == j[2]:
sumd += j[3]
ans = max(ans, sumd)
print(ans) | n, m, q = list(map(int, input().split()))
abcd = [tuple(map(int, input().split())) for _ in range(q)]
import sys
sys.setrecursionlimit(10**6)
ans = [0]
def dfs(idx, now):
if idx == n:
#print(now)
sumd = 0
for j in abcd:
if now[j[1]-1] - now[j[0]-1] == j[2]:
sumd += j[3]
ans[0] = max(ans[0], sumd)
return
if len(now) > 0:
start = now[-1]
else:
start = 1
for i in range(start, m+1):
now.append(i)
dfs(idx + 1, now)
now.pop()
dfs(0, [])
print((ans[0])) | 12 | 26 | 335 | 593 | n, m, q = list(map(int, input().split()))
abcd = [tuple(map(int, input().split())) for _ in range(q)]
ans = 0
import itertools
for i in itertools.combinations_with_replacement(list(range(1, m + 1)), n):
sumd = 0
for j in abcd:
if i[j[1] - 1] - i[j[0] - 1] == j[2]:
sumd += j[3]
ans = max(ans, sumd)
print(ans)
| n, m, q = list(map(int, input().split()))
abcd = [tuple(map(int, input().split())) for _ in range(q)]
import sys
sys.setrecursionlimit(10**6)
ans = [0]
def dfs(idx, now):
if idx == n:
# print(now)
sumd = 0
for j in abcd:
if now[j[1] - 1] - now[j[0] - 1] == j[2]:
sumd += j[3]
ans[0] = max(ans[0], sumd)
return
if len(now) > 0:
start = now[-1]
else:
start = 1
for i in range(start, m + 1):
now.append(i)
dfs(idx + 1, now)
now.pop()
dfs(0, [])
print((ans[0]))
| false | 53.846154 | [
"-ans = 0",
"-import itertools",
"+import sys",
"-for i in itertools.combinations_with_replacement(list(range(1, m + 1)), n):",
"- sumd = 0",
"- for j in abcd:",
"- if i[j[1] - 1] - i[j[0] - 1] == j[2]:",
"- sumd += j[3]",
"- ans = max(ans, sumd)",
"-print(ans)",
"+sys... | false | 0.042776 | 0.051303 | 0.833789 | [
"s049764615",
"s519366853"
] |
u724687935 | p03780 | python | s330886358 | s796536708 | 1,974 | 815 | 42,068 | 39,792 | Accepted | Accepted | 58.71 | def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
n = mid
dp = [0] * (K + 1)
dp[0] = 1
for i in range(N):
a = A[i]
if i == n or a >= K:
continue
for j in range(K, -1, -1):
dp[min(K, j + a)] |= dp[j]
rst = any(dp[k] for k in range(max(0, K - A[n]), K))
if rst:
ok = mid
else:
ng = mid
print(ok)
main()
| def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
n = mid
dp = [0] * (K + 1)
dp[0] = 1
for i in range(N):
a = A[i]
if i == n or a >= K:
continue
for j in range(K, a - 1, -1):
dp[j] |= dp[j - a]
rst = any(dp[k] for k in range(max(0, K - A[n]), K))
if rst:
ok = mid
else:
ng = mid
print(ok)
main()
| 31 | 31 | 687 | 682 | def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
n = mid
dp = [0] * (K + 1)
dp[0] = 1
for i in range(N):
a = A[i]
if i == n or a >= K:
continue
for j in range(K, -1, -1):
dp[min(K, j + a)] |= dp[j]
rst = any(dp[k] for k in range(max(0, K - A[n]), K))
if rst:
ok = mid
else:
ng = mid
print(ok)
main()
| def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
n = mid
dp = [0] * (K + 1)
dp[0] = 1
for i in range(N):
a = A[i]
if i == n or a >= K:
continue
for j in range(K, a - 1, -1):
dp[j] |= dp[j - a]
rst = any(dp[k] for k in range(max(0, K - A[n]), K))
if rst:
ok = mid
else:
ng = mid
print(ok)
main()
| false | 0 | [
"- for j in range(K, -1, -1):",
"- dp[min(K, j + a)] |= dp[j]",
"+ for j in range(K, a - 1, -1):",
"+ dp[j] |= dp[j - a]"
] | false | 0.040824 | 0.034811 | 1.172737 | [
"s330886358",
"s796536708"
] |
u596536048 | p04011 | python | s130896526 | s477760990 | 31 | 28 | 9,016 | 9,024 | Accepted | Accepted | 9.68 | N, K, X, Y = (int(eval(input())) for i in range(4))
print((K * X + (N - K) * Y if N > K else N * X)) | N = int(eval(input()))
K = int(eval(input()))
X = int(eval(input()))
Y = int(eval(input()))
if N > K:
print((K * X + (N - K) * Y))
else:
print((N * X)) | 2 | 8 | 93 | 132 | N, K, X, Y = (int(eval(input())) for i in range(4))
print((K * X + (N - K) * Y if N > K else N * X))
| N = int(eval(input()))
K = int(eval(input()))
X = int(eval(input()))
Y = int(eval(input()))
if N > K:
print((K * X + (N - K) * Y))
else:
print((N * X))
| false | 75 | [
"-N, K, X, Y = (int(eval(input())) for i in range(4))",
"-print((K * X + (N - K) * Y if N > K else N * X))",
"+N = int(eval(input()))",
"+K = int(eval(input()))",
"+X = int(eval(input()))",
"+Y = int(eval(input()))",
"+if N > K:",
"+ print((K * X + (N - K) * Y))",
"+else:",
"+ print((N * X))... | false | 0.037092 | 0.03818 | 0.971517 | [
"s130896526",
"s477760990"
] |
u357751375 | p03370 | python | s796366171 | s175824441 | 42 | 28 | 9,040 | 9,032 | Accepted | Accepted | 33.33 | n,x = list(map(int,input().split()))
m = list(int(eval(input())) for i in range(n))
m.sort()
z = sum(m)
s = n
while x > z:
z += m[0]
if x >= z:
s += 1
print(s) | n,x = list(map(int,input().split()))
m = list(int(eval(input())) for i in range(n))
m.sort()
z = sum(m)
print((n+(x-z)//m[0])) | 13 | 5 | 178 | 116 | n, x = list(map(int, input().split()))
m = list(int(eval(input())) for i in range(n))
m.sort()
z = sum(m)
s = n
while x > z:
z += m[0]
if x >= z:
s += 1
print(s)
| n, x = list(map(int, input().split()))
m = list(int(eval(input())) for i in range(n))
m.sort()
z = sum(m)
print((n + (x - z) // m[0]))
| false | 61.538462 | [
"-s = n",
"-while x > z:",
"- z += m[0]",
"- if x >= z:",
"- s += 1",
"-print(s)",
"+print((n + (x - z) // m[0]))"
] | false | 0.049095 | 0.048457 | 1.013171 | [
"s796366171",
"s175824441"
] |
u325282913 | p02900 | python | s954197094 | s275315771 | 219 | 198 | 3,060 | 38,512 | Accepted | Accepted | 9.59 | import math
def trial_division(n):
a = [1]
for i in range(2,int(math.sqrt(n)) + 1):
while n % i == 0:
n //= i
a.append(i)
a.append(n)
return a
A, B = list(map(int, input().split()))
ans = set(trial_division(A)) & set(trial_division(B))
print((len(ans))) | import math
def trial_division(n):
a = [1]
for i in range(2,int(math.sqrt(n)) + 1):
while n % i == 0:
n //= i
a.append(i)
a.append(n)
return a
A, B = list(map(int, input().split()))
print((len(set(trial_division(A))&set(trial_division(B))))) | 12 | 12 | 304 | 293 | import math
def trial_division(n):
a = [1]
for i in range(2, int(math.sqrt(n)) + 1):
while n % i == 0:
n //= i
a.append(i)
a.append(n)
return a
A, B = list(map(int, input().split()))
ans = set(trial_division(A)) & set(trial_division(B))
print((len(ans)))
| import math
def trial_division(n):
a = [1]
for i in range(2, int(math.sqrt(n)) + 1):
while n % i == 0:
n //= i
a.append(i)
a.append(n)
return a
A, B = list(map(int, input().split()))
print((len(set(trial_division(A)) & set(trial_division(B)))))
| false | 0 | [
"-ans = set(trial_division(A)) & set(trial_division(B))",
"-print((len(ans)))",
"+print((len(set(trial_division(A)) & set(trial_division(B)))))"
] | false | 0.036044 | 0.048522 | 0.742835 | [
"s954197094",
"s275315771"
] |
u905203728 | p03127 | python | s320882791 | s998016214 | 137 | 121 | 14,252 | 16,280 | Accepted | Accepted | 11.68 | n=int(eval(input()))
A=sorted(list(map(int,input().split())))
minA=min(A)
while len(A)!=1:
B=[]
for i in range(len(A)):
if A[i]%minA!=0:
B.append(A[i]%minA)
B.append(minA)
A=B
minA=min(A)
print(minA) | from fractions import gcd
from functools import reduce
def lcm_list(numbers):
return reduce(gcd,numbers)
n=int(eval(input()))
A=sorted(list(map(int,input().split())))
print((lcm_list(A))) | 13 | 11 | 246 | 197 | n = int(eval(input()))
A = sorted(list(map(int, input().split())))
minA = min(A)
while len(A) != 1:
B = []
for i in range(len(A)):
if A[i] % minA != 0:
B.append(A[i] % minA)
B.append(minA)
A = B
minA = min(A)
print(minA)
| from fractions import gcd
from functools import reduce
def lcm_list(numbers):
return reduce(gcd, numbers)
n = int(eval(input()))
A = sorted(list(map(int, input().split())))
print((lcm_list(A)))
| false | 15.384615 | [
"+from fractions import gcd",
"+from functools import reduce",
"+",
"+",
"+def lcm_list(numbers):",
"+ return reduce(gcd, numbers)",
"+",
"+",
"-minA = min(A)",
"-while len(A) != 1:",
"- B = []",
"- for i in range(len(A)):",
"- if A[i] % minA != 0:",
"- B.append(... | false | 0.039222 | 0.054267 | 0.722754 | [
"s320882791",
"s998016214"
] |
u340064601 | p02556 | python | s051551656 | s626842150 | 992 | 515 | 62,856 | 58,088 | Accepted | Accepted | 48.08 | input=__import__('sys').stdin.readline
def getdist(a,b):return abs(a[0]-b[0])+abs(a[1]-b[1])
n=int(eval(input()))
s=[]
for _ in range(n):s.append([*list(map(int,input().split()))])
ans=0
sx=sorted(s)
sy=sorted(s,key=lambda x:x[1])
ans=max(ans,getdist(sx[-1],sx[-2]))
ans=max(ans,getdist(sx[0],sx[1]))
ans=max(ans,getdist(sy[-1],sy[-2]))
ans=max(ans,getdist(sy[0],sy[1]))
def ff1(x):return x[0]+x[1]
def ff2(x):return x[0]-x[1]
f1=sorted(s,key=ff1)
f2=sorted(s,key=ff2)
ans=max(ans,getdist(f1[0],f1[-1]))
ans=max(ans,getdist(f1[0],f1[1]))
ans=max(ans,getdist(f1[-1],f1[-2]))
ans=max(ans,getdist(f2[0],f2[-1]))
ans=max(ans,getdist(f2[0],f2[1]))
ans=max(ans,getdist(f2[-1],f2[-2]))
def ff1(x):return abs(x[0]+x[1])
def ff2(x):return abs(x[0]-x[1])
f1=sorted(s,key=ff1)
f2=sorted(s,key=ff2)
ans=max(ans,getdist(f1[0],f1[-1]))
ans=max(ans,getdist(f1[0],f1[1]))
ans=max(ans,getdist(f1[-1],f1[-2]))
ans=max(ans,getdist(f2[0],f2[-1]))
ans=max(ans,getdist(f2[0],f2[1]))
ans=max(ans,getdist(f2[-1],f2[-2]))
print(ans) | input=__import__('sys').stdin.readline
def getdist(a,b):return abs(a[0]-b[0])+abs(a[1]-b[1])
n=int(eval(input()))
s=[]
for _ in range(n):s.append([*list(map(int,input().split()))])
ans=0
def ff1(x):return x[0]+x[1]
def ff2(x):return x[0]-x[1]
f1=sorted(s,key=ff1)
f2=sorted(s,key=ff2)
ans=max(ans,getdist(f1[0],f1[-1]))
ans=max(ans,getdist(f1[0],f1[1]))
ans=max(ans,getdist(f1[-1],f1[-2]))
ans=max(ans,getdist(f2[0],f2[-1]))
ans=max(ans,getdist(f2[0],f2[1]))
ans=max(ans,getdist(f2[-1],f2[-2]))
print(ans) | 33 | 17 | 1,027 | 509 | input = __import__("sys").stdin.readline
def getdist(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])
n = int(eval(input()))
s = []
for _ in range(n):
s.append([*list(map(int, input().split()))])
ans = 0
sx = sorted(s)
sy = sorted(s, key=lambda x: x[1])
ans = max(ans, getdist(sx[-1], sx[-2]))
ans = max(ans, getdist(sx[0], sx[1]))
ans = max(ans, getdist(sy[-1], sy[-2]))
ans = max(ans, getdist(sy[0], sy[1]))
def ff1(x):
return x[0] + x[1]
def ff2(x):
return x[0] - x[1]
f1 = sorted(s, key=ff1)
f2 = sorted(s, key=ff2)
ans = max(ans, getdist(f1[0], f1[-1]))
ans = max(ans, getdist(f1[0], f1[1]))
ans = max(ans, getdist(f1[-1], f1[-2]))
ans = max(ans, getdist(f2[0], f2[-1]))
ans = max(ans, getdist(f2[0], f2[1]))
ans = max(ans, getdist(f2[-1], f2[-2]))
def ff1(x):
return abs(x[0] + x[1])
def ff2(x):
return abs(x[0] - x[1])
f1 = sorted(s, key=ff1)
f2 = sorted(s, key=ff2)
ans = max(ans, getdist(f1[0], f1[-1]))
ans = max(ans, getdist(f1[0], f1[1]))
ans = max(ans, getdist(f1[-1], f1[-2]))
ans = max(ans, getdist(f2[0], f2[-1]))
ans = max(ans, getdist(f2[0], f2[1]))
ans = max(ans, getdist(f2[-1], f2[-2]))
print(ans)
| input = __import__("sys").stdin.readline
def getdist(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])
n = int(eval(input()))
s = []
for _ in range(n):
s.append([*list(map(int, input().split()))])
ans = 0
def ff1(x):
return x[0] + x[1]
def ff2(x):
return x[0] - x[1]
f1 = sorted(s, key=ff1)
f2 = sorted(s, key=ff2)
ans = max(ans, getdist(f1[0], f1[-1]))
ans = max(ans, getdist(f1[0], f1[1]))
ans = max(ans, getdist(f1[-1], f1[-2]))
ans = max(ans, getdist(f2[0], f2[-1]))
ans = max(ans, getdist(f2[0], f2[1]))
ans = max(ans, getdist(f2[-1], f2[-2]))
print(ans)
| false | 48.484848 | [
"-sx = sorted(s)",
"-sy = sorted(s, key=lambda x: x[1])",
"-ans = max(ans, getdist(sx[-1], sx[-2]))",
"-ans = max(ans, getdist(sx[0], sx[1]))",
"-ans = max(ans, getdist(sy[-1], sy[-2]))",
"-ans = max(ans, getdist(sy[0], sy[1]))",
"-",
"-",
"-def ff1(x):",
"- return abs(x[0] + x[1])",
"-",
"... | false | 0.044778 | 0.044682 | 1.002133 | [
"s051551656",
"s626842150"
] |
u671252250 | p03733 | python | s921578438 | s474086981 | 278 | 161 | 86,608 | 26,836 | Accepted | Accepted | 42.09 | # coding: utf-8
# Your code here!
N, T = list(map(int, input().split()))
a = list(map(int, input().split()))
total_t, crrnt_t, a_len = 0, 0, len(a)
for i in range(a_len - 1):
if a[i] + T > a[i + 1]:
total_t += a[i + 1] - a[i]
else:
total_t += T
crrnt_t = a[i + 1]
print((total_t + T)) | # coding: utf-8
# Your code here!
N, T = list(map(int, input().split()))
a = list(map(int, input().split()))
total_t, a_len = 0, len(a)
for i in range(a_len - 1):
if a[i] + T > a[i + 1]:
total_t += a[i + 1] - a[i]
else:
total_t += T
print((total_t + T)) | 15 | 14 | 323 | 287 | # coding: utf-8
# Your code here!
N, T = list(map(int, input().split()))
a = list(map(int, input().split()))
total_t, crrnt_t, a_len = 0, 0, len(a)
for i in range(a_len - 1):
if a[i] + T > a[i + 1]:
total_t += a[i + 1] - a[i]
else:
total_t += T
crrnt_t = a[i + 1]
print((total_t + T))
| # coding: utf-8
# Your code here!
N, T = list(map(int, input().split()))
a = list(map(int, input().split()))
total_t, a_len = 0, len(a)
for i in range(a_len - 1):
if a[i] + T > a[i + 1]:
total_t += a[i + 1] - a[i]
else:
total_t += T
print((total_t + T))
| false | 6.666667 | [
"-total_t, crrnt_t, a_len = 0, 0, len(a)",
"+total_t, a_len = 0, len(a)",
"- crrnt_t = a[i + 1]"
] | false | 0.057323 | 0.057478 | 0.997307 | [
"s921578438",
"s474086981"
] |
u197300773 | p03039 | python | s908313838 | s832320472 | 802 | 84 | 3,064 | 3,064 | Accepted | Accepted | 89.53 | def modinv(a):
b=MOD
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
return lastx%MOD
MOD=10**9+7
N,M,K=list(map(int,input().split()))
b=1
for i in range(1,K-1):
b=(b*(N*M-1-i)*modinv(i))%MOD
x=0
for i in range(1,N):
x=x+i*(N-i)
x=(x*M*M)%MOD
y=0
for j in range(1,M):
y=y+j*(M-j)
y=(y*N*N)%MOD
ans=b*(x+y)%MOD
print(ans) | def comb(n, k):
x, y = 1, 1
k = min(k, n-k)
for i in range(k):
x *= n - i
x %= MOD
y *= i + 1
y %= MOD
return x*pow(y, MOD-2, MOD) % MOD
def modinv(a):
b=MOD
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
return lastx%MOD
MOD=10**9+7
N,M,K=list(map(int,input().split()))
x=0
for i in range(1,N):
x=x+i*(N-i)
x=(x*M*M)%MOD
y=0
for j in range(1,M):
y=y+j*(M-j)
y=(y*N*N)%MOD
ans=comb(N*M-2,K-2)*(x+y)%MOD
print(ans) | 30 | 37 | 516 | 662 | def modinv(a):
b = MOD
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
return lastx % MOD
MOD = 10**9 + 7
N, M, K = list(map(int, input().split()))
b = 1
for i in range(1, K - 1):
b = (b * (N * M - 1 - i) * modinv(i)) % MOD
x = 0
for i in range(1, N):
x = x + i * (N - i)
x = (x * M * M) % MOD
y = 0
for j in range(1, M):
y = y + j * (M - j)
y = (y * N * N) % MOD
ans = b * (x + y) % MOD
print(ans)
| def comb(n, k):
x, y = 1, 1
k = min(k, n - k)
for i in range(k):
x *= n - i
x %= MOD
y *= i + 1
y %= MOD
return x * pow(y, MOD - 2, MOD) % MOD
def modinv(a):
b = MOD
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
return lastx % MOD
MOD = 10**9 + 7
N, M, K = list(map(int, input().split()))
x = 0
for i in range(1, N):
x = x + i * (N - i)
x = (x * M * M) % MOD
y = 0
for j in range(1, M):
y = y + j * (M - j)
y = (y * N * N) % MOD
ans = comb(N * M - 2, K - 2) * (x + y) % MOD
print(ans)
| false | 18.918919 | [
"+def comb(n, k):",
"+ x, y = 1, 1",
"+ k = min(k, n - k)",
"+ for i in range(k):",
"+ x *= n - i",
"+ x %= MOD",
"+ y *= i + 1",
"+ y %= MOD",
"+ return x * pow(y, MOD - 2, MOD) % MOD",
"+",
"+",
"-b = 1",
"-for i in range(1, K - 1):",
"- b = (b ... | false | 0.078488 | 0.032571 | 2.409769 | [
"s908313838",
"s832320472"
] |
u191874006 | p03323 | python | s761511932 | s608191884 | 150 | 17 | 12,508 | 2,940 | Accepted | Accepted | 88.67 | #!/usr/bin/env python3
import numpy as np
import math
import re
import functools
n = eval(input())
n = re.split(" ",n)
a = int(n[0])
b = int(n[1])
if(a > 8 or b > 8):
print(":(")
else:
print("Yay!") | #!/usr/bin/env python3
#ABC100 A
A,B = list(map(int,input().split()))
f = 1
if A > 8:
f = 0
if B > 8:
f = 0
if f:
print('Yay!')
else:
print(':(')
| 16 | 14 | 218 | 171 | #!/usr/bin/env python3
import numpy as np
import math
import re
import functools
n = eval(input())
n = re.split(" ", n)
a = int(n[0])
b = int(n[1])
if a > 8 or b > 8:
print(":(")
else:
print("Yay!")
| #!/usr/bin/env python3
# ABC100 A
A, B = list(map(int, input().split()))
f = 1
if A > 8:
f = 0
if B > 8:
f = 0
if f:
print("Yay!")
else:
print(":(")
| false | 12.5 | [
"-import numpy as np",
"-import math",
"-import re",
"-import functools",
"-",
"-n = eval(input())",
"-n = re.split(\" \", n)",
"-a = int(n[0])",
"-b = int(n[1])",
"-if a > 8 or b > 8:",
"+# ABC100 A",
"+A, B = list(map(int, input().split()))",
"+f = 1",
"+if A > 8:",
"+ f = 0",
"+i... | false | 0.093269 | 0.037777 | 2.468897 | [
"s761511932",
"s608191884"
] |
u767797498 | p03785 | python | s705453743 | s415781314 | 1,004 | 223 | 13,344 | 13,308 | Accepted | Accepted | 77.79 | n,c,k=list(map(int,input().split()))
t=[int(eval(input())) for x in range(n)]
t.sort()
i=0
cnt=0
while i<n:
departure=t[i]+k
p=0
for j in range(i,n):
if t[j] > departure:
break
p+=1
i+=min(c,p)
cnt+=1
print(cnt)
| n,c,k=list(map(int,input().split()))
t=[int(eval(input())) for x in range(n)]
t.sort()
i=0
cnt=0
while i<n:
departure=t[i]+k
p=0
for j in range(i,n):
if t[j] > departure or p==c:
break
p+=1
i+=p
cnt+=1
print(cnt) | 17 | 16 | 242 | 240 | n, c, k = list(map(int, input().split()))
t = [int(eval(input())) for x in range(n)]
t.sort()
i = 0
cnt = 0
while i < n:
departure = t[i] + k
p = 0
for j in range(i, n):
if t[j] > departure:
break
p += 1
i += min(c, p)
cnt += 1
print(cnt)
| n, c, k = list(map(int, input().split()))
t = [int(eval(input())) for x in range(n)]
t.sort()
i = 0
cnt = 0
while i < n:
departure = t[i] + k
p = 0
for j in range(i, n):
if t[j] > departure or p == c:
break
p += 1
i += p
cnt += 1
print(cnt)
| false | 5.882353 | [
"- if t[j] > departure:",
"+ if t[j] > departure or p == c:",
"- i += min(c, p)",
"+ i += p"
] | false | 0.067087 | 0.0762 | 0.880398 | [
"s705453743",
"s415781314"
] |
u820685137 | p02573 | python | s587070612 | s351311461 | 732 | 582 | 16,788 | 16,688 | Accepted | Accepted | 20.49 | """D."""
import sys
#def input() -> str: # noqa: A001
# """Input."""
# return sys.stdin.readline()[:-1]
class UnionFindTree:
"""Union-find."""
def __init__(self, n: int) -> None:
"""Init."""
self.n = n
self.rank = [-1] * n
def find_root(self, x: int) -> int:
"""Find root."""
if self.rank[x] < 0:
return x
self.rank[x] = self.find_root(self.rank[x])
return self.rank[x]
def union(self, x: int, y: int) -> None:
"""Unite two trees."""
x_root = self.find_root(x)
y_root = self.find_root(y)
if x_root == y_root:
return
if x_root > y_root:
x_root, y_root = y_root, x_root
self.rank[x_root] += self.rank[y_root]
self.rank[y_root] = x_root
def get_size(self, x: int) -> int:
"""Get size."""
return self.rank[self.find_root(x)] * -1
def is_same(self, x: int, y: int) -> bool:
"""Is same group."""
return self.find_root(x) == self.find_root(y)
n, m = list(map(int, input().split(' ')))
tree = UnionFindTree(n)
for _ in range(m):
a, b = list(map(int, input().split(' ')))
tree.union(a - 1, b - 1)
ans = 0
for i in range(n):
ans = max(ans, tree.get_size(i))
print(ans)
| """D."""
import sys
def input() -> str: # noqa: A001
"""Input."""
return sys.stdin.readline()[:-1]
class UnionFindTree:
"""Union-find."""
def __init__(self, n: int) -> None:
"""Init."""
self.n = n
self.rank = [-1] * n
def find_root(self, x: int) -> int:
"""Find root."""
if self.rank[x] < 0:
return x
self.rank[x] = self.find_root(self.rank[x])
return self.rank[x]
def union(self, x: int, y: int) -> None:
"""Unite two trees."""
x_root = self.find_root(x)
y_root = self.find_root(y)
if x_root == y_root:
return
if x_root > y_root:
x_root, y_root = y_root, x_root
self.rank[x_root] += self.rank[y_root]
self.rank[y_root] = x_root
def get_size(self, x: int) -> int:
"""Get size."""
return self.rank[self.find_root(x)] * -1
def is_same(self, x: int, y: int) -> bool:
"""Is same group."""
return self.find_root(x) == self.find_root(y)
n, m = list(map(int, input().split(' ')))
tree = UnionFindTree(n)
for _ in range(m):
a, b = list(map(int, input().split(' ')))
tree.union(a - 1, b - 1)
ans = 0
for i in range(n):
ans = max(ans, tree.get_size(i))
print(ans)
| 63 | 64 | 1,353 | 1,352 | """D."""
import sys
# def input() -> str: # noqa: A001
# """Input."""
# return sys.stdin.readline()[:-1]
class UnionFindTree:
"""Union-find."""
def __init__(self, n: int) -> None:
"""Init."""
self.n = n
self.rank = [-1] * n
def find_root(self, x: int) -> int:
"""Find root."""
if self.rank[x] < 0:
return x
self.rank[x] = self.find_root(self.rank[x])
return self.rank[x]
def union(self, x: int, y: int) -> None:
"""Unite two trees."""
x_root = self.find_root(x)
y_root = self.find_root(y)
if x_root == y_root:
return
if x_root > y_root:
x_root, y_root = y_root, x_root
self.rank[x_root] += self.rank[y_root]
self.rank[y_root] = x_root
def get_size(self, x: int) -> int:
"""Get size."""
return self.rank[self.find_root(x)] * -1
def is_same(self, x: int, y: int) -> bool:
"""Is same group."""
return self.find_root(x) == self.find_root(y)
n, m = list(map(int, input().split(" ")))
tree = UnionFindTree(n)
for _ in range(m):
a, b = list(map(int, input().split(" ")))
tree.union(a - 1, b - 1)
ans = 0
for i in range(n):
ans = max(ans, tree.get_size(i))
print(ans)
| """D."""
import sys
def input() -> str: # noqa: A001
"""Input."""
return sys.stdin.readline()[:-1]
class UnionFindTree:
"""Union-find."""
def __init__(self, n: int) -> None:
"""Init."""
self.n = n
self.rank = [-1] * n
def find_root(self, x: int) -> int:
"""Find root."""
if self.rank[x] < 0:
return x
self.rank[x] = self.find_root(self.rank[x])
return self.rank[x]
def union(self, x: int, y: int) -> None:
"""Unite two trees."""
x_root = self.find_root(x)
y_root = self.find_root(y)
if x_root == y_root:
return
if x_root > y_root:
x_root, y_root = y_root, x_root
self.rank[x_root] += self.rank[y_root]
self.rank[y_root] = x_root
def get_size(self, x: int) -> int:
"""Get size."""
return self.rank[self.find_root(x)] * -1
def is_same(self, x: int, y: int) -> bool:
"""Is same group."""
return self.find_root(x) == self.find_root(y)
n, m = list(map(int, input().split(" ")))
tree = UnionFindTree(n)
for _ in range(m):
a, b = list(map(int, input().split(" ")))
tree.union(a - 1, b - 1)
ans = 0
for i in range(n):
ans = max(ans, tree.get_size(i))
print(ans)
| false | 1.5625 | [
"-# def input() -> str: # noqa: A001",
"-# \"\"\"Input.\"\"\"",
"-# return sys.stdin.readline()[:-1]",
"+",
"+def input() -> str: # noqa: A001",
"+ \"\"\"Input.\"\"\"",
"+ return sys.stdin.readline()[:-1]",
"+",
"+"
] | false | 0.037818 | 0.039129 | 0.966494 | [
"s587070612",
"s351311461"
] |
u970197315 | p03672 | python | s199818212 | s266385803 | 64 | 17 | 3,064 | 2,940 | Accepted | Accepted | 73.44 | # ABC066 B - ss
S = eval(input())
N = len(S)
ans = 0
for i in range(1,N):
ss = S[0:N-i]
if len(ss)%2 == 1:
continue
n = len(ss)//2
sf = ss[0:n]
st = ss[n:N+1]
if sf == st:
ans = max(ans,len(ss))
print(ans) | s=eval(input())
n=len(s)
for i in range(n-1,1,-1):
t=s[:i]
nt=len(t)
if nt%2==1:
continue
if t[nt//2:]==t[:nt//2]:
print(nt)
exit() | 15 | 10 | 254 | 174 | # ABC066 B - ss
S = eval(input())
N = len(S)
ans = 0
for i in range(1, N):
ss = S[0 : N - i]
if len(ss) % 2 == 1:
continue
n = len(ss) // 2
sf = ss[0:n]
st = ss[n : N + 1]
if sf == st:
ans = max(ans, len(ss))
print(ans)
| s = eval(input())
n = len(s)
for i in range(n - 1, 1, -1):
t = s[:i]
nt = len(t)
if nt % 2 == 1:
continue
if t[nt // 2 :] == t[: nt // 2]:
print(nt)
exit()
| false | 33.333333 | [
"-# ABC066 B - ss",
"-S = eval(input())",
"-N = len(S)",
"-ans = 0",
"-for i in range(1, N):",
"- ss = S[0 : N - i]",
"- if len(ss) % 2 == 1:",
"+s = eval(input())",
"+n = len(s)",
"+for i in range(n - 1, 1, -1):",
"+ t = s[:i]",
"+ nt = len(t)",
"+ if nt % 2 == 1:",
"- n... | false | 0.038349 | 0.037775 | 1.015193 | [
"s199818212",
"s266385803"
] |
u070201429 | p03425 | python | s559744611 | s551792877 | 147 | 68 | 9,204 | 9,216 | Accepted | Accepted | 53.74 | n = int(eval(input()))
m, a, r, c, h = 0, 0, 0, 0, 0
for _ in range(n):
i = eval(input())
i = i[0]
if i == 'M':
m += 1
elif i == 'A':
a += 1
elif i == 'R':
r += 1
elif i == 'C':
c += 1
elif i == 'H':
h += 1
ans = 0
from itertools import combinations
for i in combinations([m, a, r, c, h], 3):
i, j, k = i
ans += i * j * k
print(ans) | from sys import stdin
def input():
return stdin.readline().strip()
n = int(eval(input()))
m, a, r, c, h = 0, 0, 0, 0, 0
for _ in range(n):
i = eval(input())
i = i[0]
if i == 'M':
m += 1
elif i == 'A':
a += 1
elif i == 'R':
r += 1
elif i == 'C':
c += 1
elif i == 'H':
h += 1
ans = 0
from itertools import combinations
for i in combinations([m, a, r, c, h], 3):
i, j, k = i
ans += i * j * k
print(ans) | 22 | 26 | 418 | 494 | n = int(eval(input()))
m, a, r, c, h = 0, 0, 0, 0, 0
for _ in range(n):
i = eval(input())
i = i[0]
if i == "M":
m += 1
elif i == "A":
a += 1
elif i == "R":
r += 1
elif i == "C":
c += 1
elif i == "H":
h += 1
ans = 0
from itertools import combinations
for i in combinations([m, a, r, c, h], 3):
i, j, k = i
ans += i * j * k
print(ans)
| from sys import stdin
def input():
return stdin.readline().strip()
n = int(eval(input()))
m, a, r, c, h = 0, 0, 0, 0, 0
for _ in range(n):
i = eval(input())
i = i[0]
if i == "M":
m += 1
elif i == "A":
a += 1
elif i == "R":
r += 1
elif i == "C":
c += 1
elif i == "H":
h += 1
ans = 0
from itertools import combinations
for i in combinations([m, a, r, c, h], 3):
i, j, k = i
ans += i * j * k
print(ans)
| false | 15.384615 | [
"+from sys import stdin",
"+",
"+",
"+def input():",
"+ return stdin.readline().strip()",
"+",
"+"
] | false | 0.211736 | 0.045613 | 4.641996 | [
"s559744611",
"s551792877"
] |
u512342660 | p02469 | python | s823284888 | s883182838 | 4,230 | 10 | 6,420 | 6,448 | Accepted | Accepted | 99.76 | n = eval(input())
nums = list(map(int,input().split()))
nums = sorted(nums)
i=n-2
x=1
while True:
if i<0:
break
tmp =nums[n-1]*x
if tmp%nums[i]==0:
i-=1
else:
x+=1
i=n-2
print(tmp) | n = eval(input())
nums = list(map(int,input().split()))
x = 2
checklist = [0 for i in range(n)]
table = []
while x<=max(nums):
i=0
while i<n:
if nums[i]%x==0:
checklist[i]=0
nums[i] = nums[i]/x
else:
checklist[i]=1
i+=1
if 0 in checklist:
table.append(x)
else:
x+=1
ans = 1
# print nums
# print table
if len(table)==0:
for num in nums:
ans *= num
else:
for num in nums:
ans *= num
for y in table:
ans *= y
print(ans) | 15 | 30 | 234 | 565 | n = eval(input())
nums = list(map(int, input().split()))
nums = sorted(nums)
i = n - 2
x = 1
while True:
if i < 0:
break
tmp = nums[n - 1] * x
if tmp % nums[i] == 0:
i -= 1
else:
x += 1
i = n - 2
print(tmp)
| n = eval(input())
nums = list(map(int, input().split()))
x = 2
checklist = [0 for i in range(n)]
table = []
while x <= max(nums):
i = 0
while i < n:
if nums[i] % x == 0:
checklist[i] = 0
nums[i] = nums[i] / x
else:
checklist[i] = 1
i += 1
if 0 in checklist:
table.append(x)
else:
x += 1
ans = 1
# print nums
# print table
if len(table) == 0:
for num in nums:
ans *= num
else:
for num in nums:
ans *= num
for y in table:
ans *= y
print(ans)
| false | 50 | [
"-nums = sorted(nums)",
"-i = n - 2",
"-x = 1",
"-while True:",
"- if i < 0:",
"- break",
"- tmp = nums[n - 1] * x",
"- if tmp % nums[i] == 0:",
"- i -= 1",
"+x = 2",
"+checklist = [0 for i in range(n)]",
"+table = []",
"+while x <= max(nums):",
"+ i = 0",
"+ ... | false | 0.052099 | 0.052042 | 1.001105 | [
"s823284888",
"s883182838"
] |
u226108478 | p03331 | python | s849745630 | s406898853 | 437 | 17 | 3,060 | 2,940 | Accepted | Accepted | 96.11 | # -*- coding: utf-8 -*-
# AtCoder Grand Contest
# Problem A
def sum_digit(number):
string = str(number)
array = list(map(int, list(string)))
return sum(array)
if __name__ == '__main__':
n = int(eval(input()))
a = 0
digit_sum_min = 1000000
for i in range(1, n):
a = i
b = n - a
sum_a = sum_digit(a)
sum_b = sum_digit(b)
digit_sum_min = min(digit_sum_min, sum_a + sum_b)
print(digit_sum_min)
| # -*- coding: utf-8 -*-
# AtCoder Grand Contest
# Problem A
if __name__ == '__main__':
n = int(eval(input()))
# See:
# https://www.youtube.com/watch?v=Ommfmx2wtuY
if (n == 10) or (n == 100) or (n == 1000) or (n == 10000) or (n == 100000):
print((10))
else:
print((sum(list(map(int, list(str(n)))))))
| 26 | 15 | 489 | 344 | # -*- coding: utf-8 -*-
# AtCoder Grand Contest
# Problem A
def sum_digit(number):
string = str(number)
array = list(map(int, list(string)))
return sum(array)
if __name__ == "__main__":
n = int(eval(input()))
a = 0
digit_sum_min = 1000000
for i in range(1, n):
a = i
b = n - a
sum_a = sum_digit(a)
sum_b = sum_digit(b)
digit_sum_min = min(digit_sum_min, sum_a + sum_b)
print(digit_sum_min)
| # -*- coding: utf-8 -*-
# AtCoder Grand Contest
# Problem A
if __name__ == "__main__":
n = int(eval(input()))
# See:
# https://www.youtube.com/watch?v=Ommfmx2wtuY
if (n == 10) or (n == 100) or (n == 1000) or (n == 10000) or (n == 100000):
print((10))
else:
print((sum(list(map(int, list(str(n)))))))
| false | 42.307692 | [
"-def sum_digit(number):",
"- string = str(number)",
"- array = list(map(int, list(string)))",
"- return sum(array)",
"-",
"-",
"- a = 0",
"- digit_sum_min = 1000000",
"- for i in range(1, n):",
"- a = i",
"- b = n - a",
"- sum_a = sum_digit(a)",
"- ... | false | 0.294769 | 0.037483 | 7.864144 | [
"s849745630",
"s406898853"
] |
u803617136 | p02923 | python | s397262241 | s049361125 | 216 | 95 | 63,984 | 14,252 | Accepted | Accepted | 56.02 | N = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
cnt = 0
for i in range(1, N):
if h[i] <= h[i - 1]:
cnt += 1
else:
ans = max(ans, cnt)
cnt = 0
ans = max(ans, cnt)
print(ans)
| n = int(eval(input()))
height = list(map(int, input().split()))
ans = 0
cnt = 0
for i in range(1, n):
if height[i] > height[i - 1]:
cnt = 0
else:
cnt += 1
ans = max(ans, cnt)
print(ans) | 13 | 12 | 231 | 219 | N = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
cnt = 0
for i in range(1, N):
if h[i] <= h[i - 1]:
cnt += 1
else:
ans = max(ans, cnt)
cnt = 0
ans = max(ans, cnt)
print(ans)
| n = int(eval(input()))
height = list(map(int, input().split()))
ans = 0
cnt = 0
for i in range(1, n):
if height[i] > height[i - 1]:
cnt = 0
else:
cnt += 1
ans = max(ans, cnt)
print(ans)
| false | 7.692308 | [
"-N = int(eval(input()))",
"-h = list(map(int, input().split()))",
"+n = int(eval(input()))",
"+height = list(map(int, input().split()))",
"-for i in range(1, N):",
"- if h[i] <= h[i - 1]:",
"+for i in range(1, n):",
"+ if height[i] > height[i - 1]:",
"+ cnt = 0",
"+ else:",
"- ... | false | 0.043938 | 0.037501 | 1.171649 | [
"s397262241",
"s049361125"
] |
u965436898 | p03266 | python | s039444554 | s619296924 | 93 | 20 | 4,596 | 3,060 | Accepted | Accepted | 78.49 | n,k = list(map(int,input().split()))
num = [0] * k
ans = 0
for i in range(1,n + 1):
num[i%k] += 1
for a in range(k):
b = (k - a) % k
c = (k - a) % k
if (b + c) % k != 0:
continue
ans += num[a] * num[b] * num[c]
print(ans) | n,k = list(map(int,input().split()))
def gcd(a,b):
if b == 0:
return a
return gcd(b,a % b)
def lcm(a,b):
return a * b // gcd(a,b)
if k % 2 != 0:
elements = n // k
print((elements**3))
else:
a = n // k
b = (n + (k//2)) // k
print((a**3 + b ** 3)) | 12 | 14 | 240 | 268 | n, k = list(map(int, input().split()))
num = [0] * k
ans = 0
for i in range(1, n + 1):
num[i % k] += 1
for a in range(k):
b = (k - a) % k
c = (k - a) % k
if (b + c) % k != 0:
continue
ans += num[a] * num[b] * num[c]
print(ans)
| n, k = list(map(int, input().split()))
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
return a * b // gcd(a, b)
if k % 2 != 0:
elements = n // k
print((elements**3))
else:
a = n // k
b = (n + (k // 2)) // k
print((a**3 + b**3))
| false | 14.285714 | [
"-num = [0] * k",
"-ans = 0",
"-for i in range(1, n + 1):",
"- num[i % k] += 1",
"-for a in range(k):",
"- b = (k - a) % k",
"- c = (k - a) % k",
"- if (b + c) % k != 0:",
"- continue",
"- ans += num[a] * num[b] * num[c]",
"-print(ans)",
"+",
"+",
"+def gcd(a, b):",
... | false | 0.039785 | 0.123799 | 0.321367 | [
"s039444554",
"s619296924"
] |
u506705885 | p02394 | python | s358999731 | s834141460 | 60 | 30 | 7,724 | 5,596 | Accepted | Accepted | 50 | All=input().split()
W=int(All[0])
H=int(All[1])
x=int(All[2])
y=int(All[3])
r=int(All[4])
if x+r<=W and x-r>=0 and y+r<=H and y-r>=0:
print('Yes')
else:
print('No') | W,H,x,y,r=list(map(int,input().split()))
if x+r>W or y+r>H or x-r<0 or y-r<0:
print("No")
else:
print("Yes") | 10 | 5 | 181 | 114 | All = input().split()
W = int(All[0])
H = int(All[1])
x = int(All[2])
y = int(All[3])
r = int(All[4])
if x + r <= W and x - r >= 0 and y + r <= H and y - r >= 0:
print("Yes")
else:
print("No")
| W, H, x, y, r = list(map(int, input().split()))
if x + r > W or y + r > H or x - r < 0 or y - r < 0:
print("No")
else:
print("Yes")
| false | 50 | [
"-All = input().split()",
"-W = int(All[0])",
"-H = int(All[1])",
"-x = int(All[2])",
"-y = int(All[3])",
"-r = int(All[4])",
"-if x + r <= W and x - r >= 0 and y + r <= H and y - r >= 0:",
"+W, H, x, y, r = list(map(int, input().split()))",
"+if x + r > W or y + r > H or x - r < 0 or y - r < 0:",
... | false | 0.046728 | 0.04701 | 0.993998 | [
"s358999731",
"s834141460"
] |
u987164499 | p03574 | python | s668421136 | s729571784 | 33 | 25 | 3,188 | 3,064 | Accepted | Accepted | 24.24 | from sys import stdin,setrecursionlimit
setrecursionlimit(10 ** 7)
h,w = list(map(int,stdin.readline().rstrip().split()))
s = [stdin.readline().rstrip() for _ in range(h)]
li = [[0 for i in range(w)]for j in range(h)]
x = [-1,0,1]
y = [-1,0,1]
for i in range(h):
for j in range(w):
count = 0
for xx in x:
for yy in y:
if xx == 0 and yy == 0:
continue
if j+xx < 0 or j+xx > w-1:
continue
if i+yy < 0 or i+yy > h-1:
continue
if s[i+yy][j+xx] == "#":
count += 1
if s[i][j] == "#":
li[i][j] = "#"
else:li[i][j] = str(count)
for i in li:
print(("".join(i))) | h,w = list(map(int,input().split()))
s = ["."*(w+2)]
for _ in range(h):
s.append("."+eval(input())+".")
s.append("."*(w+2))
li = [[0 for j in range(w)]for i in range(h)]
h += 2
w += 2
for i in range(1,h-1):
for j in range(1,w-1):
if s[i][j] == "#":
li[i-1][j-1] = "#"
continue
point = 0
x = [-1,0,1]
y = [-1,0,1]
for nx in x:
for ny in y:
if nx == 0 and ny == 0:
continue
if s[i+nx][j+ny] == "#":
point += 1
li[i-1][j-1] = point
for i in li:
print((''.join(map(str,i)))) | 30 | 30 | 786 | 658 | from sys import stdin, setrecursionlimit
setrecursionlimit(10**7)
h, w = list(map(int, stdin.readline().rstrip().split()))
s = [stdin.readline().rstrip() for _ in range(h)]
li = [[0 for i in range(w)] for j in range(h)]
x = [-1, 0, 1]
y = [-1, 0, 1]
for i in range(h):
for j in range(w):
count = 0
for xx in x:
for yy in y:
if xx == 0 and yy == 0:
continue
if j + xx < 0 or j + xx > w - 1:
continue
if i + yy < 0 or i + yy > h - 1:
continue
if s[i + yy][j + xx] == "#":
count += 1
if s[i][j] == "#":
li[i][j] = "#"
else:
li[i][j] = str(count)
for i in li:
print(("".join(i)))
| h, w = list(map(int, input().split()))
s = ["." * (w + 2)]
for _ in range(h):
s.append("." + eval(input()) + ".")
s.append("." * (w + 2))
li = [[0 for j in range(w)] for i in range(h)]
h += 2
w += 2
for i in range(1, h - 1):
for j in range(1, w - 1):
if s[i][j] == "#":
li[i - 1][j - 1] = "#"
continue
point = 0
x = [-1, 0, 1]
y = [-1, 0, 1]
for nx in x:
for ny in y:
if nx == 0 and ny == 0:
continue
if s[i + nx][j + ny] == "#":
point += 1
li[i - 1][j - 1] = point
for i in li:
print(("".join(map(str, i))))
| false | 0 | [
"-from sys import stdin, setrecursionlimit",
"-",
"-setrecursionlimit(10**7)",
"-h, w = list(map(int, stdin.readline().rstrip().split()))",
"-s = [stdin.readline().rstrip() for _ in range(h)]",
"-li = [[0 for i in range(w)] for j in range(h)]",
"-x = [-1, 0, 1]",
"-y = [-1, 0, 1]",
"-for i in range(... | false | 0.066684 | 0.046602 | 1.430913 | [
"s668421136",
"s729571784"
] |
u753803401 | p03221 | python | s280405097 | s156329952 | 961 | 813 | 66,780 | 64,988 | Accepted | Accepted | 15.4 | def slove():
import sys
input = sys.stdin.readline
n, m = list(map(int, input().rstrip('\n').split()))
py = []
ls = [1] * (n + 1)
for i in range(m):
p, y = list(map(int, input().rstrip('\n').split()))
py.append([p, y, 0, i])
py.sort()
for i in range(m):
py[i][2] = ls[py[i][0]]
ls[py[i][0]] += 1
py.sort(key=lambda x: x[3])
for i in range(len(py)):
a = ["0"] * 6
a = a + list(str(py[i][0]))
a = a[-6:]
b = ["0"] * 6
b = b + list(str(py[i][2]))
b = b[-6:]
print(("".join(a + b)))
if __name__ == '__main__':
slove()
| def slove():
import sys
input = sys.stdin.readline
n, m = list(map(int, input().rstrip('\n').split()))
py = []
pyn = [1] * n
for i in range(m):
p, y = list(map(int, input().rstrip('\n').split()))
py.append([p, y, i])
py.sort()
for i in range(len(py)):
py[i][1] = pyn[py[i][0]-1]
pyn[py[i][0] - 1] += 1
py.sort(key=lambda x: x[2])
for p, y, i in py:
l = ["0"] * (6 - len(str(p)))
l.append(str(p))
l.append("0" * (6 - len(str(y))))
l.append(str(y))
print(("".join(l)))
if __name__ == '__main__':
slove()
| 26 | 25 | 671 | 643 | def slove():
import sys
input = sys.stdin.readline
n, m = list(map(int, input().rstrip("\n").split()))
py = []
ls = [1] * (n + 1)
for i in range(m):
p, y = list(map(int, input().rstrip("\n").split()))
py.append([p, y, 0, i])
py.sort()
for i in range(m):
py[i][2] = ls[py[i][0]]
ls[py[i][0]] += 1
py.sort(key=lambda x: x[3])
for i in range(len(py)):
a = ["0"] * 6
a = a + list(str(py[i][0]))
a = a[-6:]
b = ["0"] * 6
b = b + list(str(py[i][2]))
b = b[-6:]
print(("".join(a + b)))
if __name__ == "__main__":
slove()
| def slove():
import sys
input = sys.stdin.readline
n, m = list(map(int, input().rstrip("\n").split()))
py = []
pyn = [1] * n
for i in range(m):
p, y = list(map(int, input().rstrip("\n").split()))
py.append([p, y, i])
py.sort()
for i in range(len(py)):
py[i][1] = pyn[py[i][0] - 1]
pyn[py[i][0] - 1] += 1
py.sort(key=lambda x: x[2])
for p, y, i in py:
l = ["0"] * (6 - len(str(p)))
l.append(str(p))
l.append("0" * (6 - len(str(y))))
l.append(str(y))
print(("".join(l)))
if __name__ == "__main__":
slove()
| false | 3.846154 | [
"- ls = [1] * (n + 1)",
"+ pyn = [1] * n",
"- py.append([p, y, 0, i])",
"+ py.append([p, y, i])",
"- for i in range(m):",
"- py[i][2] = ls[py[i][0]]",
"- ls[py[i][0]] += 1",
"- py.sort(key=lambda x: x[3])",
"- a = [\"0\"] * 6",
"- a = a + list(... | false | 0.044992 | 0.043913 | 1.024569 | [
"s280405097",
"s156329952"
] |
u030726788 | p03325 | python | s888361749 | s593859025 | 153 | 98 | 4,148 | 4,148 | Accepted | Accepted | 35.95 | N=int(eval(input()))
a=list(map(int,input().split()))
c=0
for i in range(N):
while(a[i]%2==0):
a[i]=a[i]/2
c+=1
print(c) | n = int(eval(input()))
a = list(map(int,input().split()))
c = 0
for i in range(n):
while(a[i] % 2 == 0):
c += 1
a[i] //= 2
print(c) | 8 | 11 | 141 | 158 | N = int(eval(input()))
a = list(map(int, input().split()))
c = 0
for i in range(N):
while a[i] % 2 == 0:
a[i] = a[i] / 2
c += 1
print(c)
| n = int(eval(input()))
a = list(map(int, input().split()))
c = 0
for i in range(n):
while a[i] % 2 == 0:
c += 1
a[i] //= 2
print(c)
| false | 27.272727 | [
"-N = int(eval(input()))",
"+n = int(eval(input()))",
"-for i in range(N):",
"+for i in range(n):",
"- a[i] = a[i] / 2",
"+ a[i] //= 2"
] | false | 0.03712 | 0.03736 | 0.993554 | [
"s888361749",
"s593859025"
] |
u832039789 | p03569 | python | s348083381 | s485346259 | 67 | 57 | 3,316 | 3,316 | Accepted | Accepted | 14.93 | s = eval(input())
s_x = s.replace('x', '')
if s_x != s_x[::-1]:
print((-1))
exit()
res = 0
l, r = 0, len(s) - 1
while l < r:
if s[l] == s[r]:
l += 1
r -= 1
elif s[l] == 'x':
l += 1
res += 1
elif s[r] == 'x':
r -= 1
res += 1
else:
print((-1))
exit()
print(res)
| s = eval(input())
s_x = s.replace('x', '')
if s_x != s_x[::-1]:
print((-1))
exit()
res = 0
l, r = 0, len(s) - 1
while l < r:
if s[l] == s[r]:
l += 1
r -= 1
elif s[l] == 'x':
l += 1
res += 1
else:
r -= 1
res += 1
print(res)
| 23 | 20 | 362 | 304 | s = eval(input())
s_x = s.replace("x", "")
if s_x != s_x[::-1]:
print((-1))
exit()
res = 0
l, r = 0, len(s) - 1
while l < r:
if s[l] == s[r]:
l += 1
r -= 1
elif s[l] == "x":
l += 1
res += 1
elif s[r] == "x":
r -= 1
res += 1
else:
print((-1))
exit()
print(res)
| s = eval(input())
s_x = s.replace("x", "")
if s_x != s_x[::-1]:
print((-1))
exit()
res = 0
l, r = 0, len(s) - 1
while l < r:
if s[l] == s[r]:
l += 1
r -= 1
elif s[l] == "x":
l += 1
res += 1
else:
r -= 1
res += 1
print(res)
| false | 13.043478 | [
"- elif s[r] == \"x\":",
"+ else:",
"- else:",
"- print((-1))",
"- exit()"
] | false | 0.075002 | 0.075456 | 0.993983 | [
"s348083381",
"s485346259"
] |
u345966487 | p04034 | python | s883685817 | s680004977 | 126 | 114 | 18,080 | 10,212 | Accepted | Accepted | 9.52 | import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
N, M = inm()
def solve():
pos = {0}
count = [1] * N
for i in range(M):
x, y = inm()
x -= 1
y -= 1
if x in pos:
if count[x] == 1:
pos.remove(x)
pos.add(y)
count[x] -= 1
count[y] += 1
return len(pos)
print(solve())
| import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
N, M = inm()
def solve():
r = [False] * N
r[0] = True
cnt = [1] * N
for i in range(M):
x, y = inm()
x -= 1
y -= 1
if r[x]:
r[y] = True
cnt[x] -= 1
cnt[y] += 1
if cnt[x] == 0:
r[x] = False
return sum(r)
print(solve())
| 29 | 31 | 645 | 648 | import sys
sys.setrecursionlimit(10**8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
N, M = inm()
def solve():
pos = {0}
count = [1] * N
for i in range(M):
x, y = inm()
x -= 1
y -= 1
if x in pos:
if count[x] == 1:
pos.remove(x)
pos.add(y)
count[x] -= 1
count[y] += 1
return len(pos)
print(solve())
| import sys
sys.setrecursionlimit(10**8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
N, M = inm()
def solve():
r = [False] * N
r[0] = True
cnt = [1] * N
for i in range(M):
x, y = inm()
x -= 1
y -= 1
if r[x]:
r[y] = True
cnt[x] -= 1
cnt[y] += 1
if cnt[x] == 0:
r[x] = False
return sum(r)
print(solve())
| false | 6.451613 | [
"- pos = {0}",
"- count = [1] * N",
"+ r = [False] * N",
"+ r[0] = True",
"+ cnt = [1] * N",
"- if x in pos:",
"- if count[x] == 1:",
"- pos.remove(x)",
"- pos.add(y)",
"- count[x] -= 1",
"- count[y] += 1",
"- return l... | false | 0.03578 | 0.056779 | 0.630161 | [
"s883685817",
"s680004977"
] |
u462831976 | p00111 | python | s646936406 | s616689910 | 70 | 60 | 11,756 | 11,708 | Accepted | Accepted | 14.29 | # -*- coding: utf-8 -*-
import sys
import os
import math
import re
import random
tableA = {
"A": "00000",
"B": "00001",
"C": "00010",
"D": "00011",
"E": "00100",
"F": "00101",
"G": "00110",
"H": "00111",
"I": "01000",
"J": "01001",
"K": "01010",
"L": "01011",
"M": "01100",
"N": "01101",
"O": "01110",
"P": "01111",
"Q": "10000",
"R": "10001",
"S": "10010",
"T": "10011",
"U": "10100",
"V": "10101",
"W": "10110",
"X": "10111",
"Y": "11000",
"Z": "11001",
" ": "11010",
".": "11011",
",": "11100",
"-": "11101",
"'": "11110",
"?": "11111"}
tableB = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z"}
def my_solve(s):
lst = []
for c in s:
lst.append(tableA[c])
s = ''.join(lst)
tmp, ans = '', ''
for c in s:
tmp += c
if tmp in tableB:
ans += tableB[tmp]
tmp = ''
return ans
while True:
try:
s = eval(input())
except:
break
print((my_solve(s))) | # -*- coding: utf-8 -*-
import sys
import os
import math
import re
import random
tableA = {
"A": "00000",
"B": "00001",
"C": "00010",
"D": "00011",
"E": "00100",
"F": "00101",
"G": "00110",
"H": "00111",
"I": "01000",
"J": "01001",
"K": "01010",
"L": "01011",
"M": "01100",
"N": "01101",
"O": "01110",
"P": "01111",
"Q": "10000",
"R": "10001",
"S": "10010",
"T": "10011",
"U": "10100",
"V": "10101",
"W": "10110",
"X": "10111",
"Y": "11000",
"Z": "11001",
" ": "11010",
".": "11011",
",": "11100",
"-": "11101",
"'": "11110",
"?": "11111"}
tableB = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z"}
def my_solve(s):
s = s.strip('\n')
lst = []
for c in s:
lst.append(tableA[c])
s = ''.join(lst)
tmp, ans = '', ''
for c in s:
tmp += c
if tmp in tableB:
ans += tableB[tmp]
tmp = ''
return ans
while True:
try:
s = eval(input())
except:
break
print((my_solve(s))) | 97 | 98 | 1,724 | 1,747 | # -*- coding: utf-8 -*-
import sys
import os
import math
import re
import random
tableA = {
"A": "00000",
"B": "00001",
"C": "00010",
"D": "00011",
"E": "00100",
"F": "00101",
"G": "00110",
"H": "00111",
"I": "01000",
"J": "01001",
"K": "01010",
"L": "01011",
"M": "01100",
"N": "01101",
"O": "01110",
"P": "01111",
"Q": "10000",
"R": "10001",
"S": "10010",
"T": "10011",
"U": "10100",
"V": "10101",
"W": "10110",
"X": "10111",
"Y": "11000",
"Z": "11001",
" ": "11010",
".": "11011",
",": "11100",
"-": "11101",
"'": "11110",
"?": "11111",
}
tableB = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z",
}
def my_solve(s):
lst = []
for c in s:
lst.append(tableA[c])
s = "".join(lst)
tmp, ans = "", ""
for c in s:
tmp += c
if tmp in tableB:
ans += tableB[tmp]
tmp = ""
return ans
while True:
try:
s = eval(input())
except:
break
print((my_solve(s)))
| # -*- coding: utf-8 -*-
import sys
import os
import math
import re
import random
tableA = {
"A": "00000",
"B": "00001",
"C": "00010",
"D": "00011",
"E": "00100",
"F": "00101",
"G": "00110",
"H": "00111",
"I": "01000",
"J": "01001",
"K": "01010",
"L": "01011",
"M": "01100",
"N": "01101",
"O": "01110",
"P": "01111",
"Q": "10000",
"R": "10001",
"S": "10010",
"T": "10011",
"U": "10100",
"V": "10101",
"W": "10110",
"X": "10111",
"Y": "11000",
"Z": "11001",
" ": "11010",
".": "11011",
",": "11100",
"-": "11101",
"'": "11110",
"?": "11111",
}
tableB = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z",
}
def my_solve(s):
s = s.strip("\n")
lst = []
for c in s:
lst.append(tableA[c])
s = "".join(lst)
tmp, ans = "", ""
for c in s:
tmp += c
if tmp in tableB:
ans += tableB[tmp]
tmp = ""
return ans
while True:
try:
s = eval(input())
except:
break
print((my_solve(s)))
| false | 1.020408 | [
"+ s = s.strip(\"\\n\")"
] | false | 0.044066 | 0.097436 | 0.452256 | [
"s646936406",
"s616689910"
] |
u497046426 | p03609 | python | s782050424 | s406697335 | 20 | 17 | 3,316 | 2,940 | Accepted | Accepted | 15 | X, t = list(map(int, input().split()))
print((max(X - t, 0))) | X, t = list(map(int, input().split()))
print((max(0, X - t))) | 2 | 2 | 54 | 54 | X, t = list(map(int, input().split()))
print((max(X - t, 0)))
| X, t = list(map(int, input().split()))
print((max(0, X - t)))
| false | 0 | [
"-print((max(X - t, 0)))",
"+print((max(0, X - t)))"
] | false | 0.073815 | 0.069975 | 1.054888 | [
"s782050424",
"s406697335"
] |
u525065967 | p02608 | python | s304718754 | s127625940 | 833 | 549 | 10,756 | 9,436 | Accepted | Accepted | 34.09 | from logging import *
basicConfig(level=DEBUG, format='%(levelname)s: %(message)s')
disable(CRITICAL)
n = int(eval(input()))
f = [0]*(n+1)
x = 1
while x*x < n:
y = 1
while y*y < n:
if x*y >= n: continue
z = 1
while z*z < n:
k = x*x + y*y + z*z + x*y + y*z + z*x
if 1<=k<=n:
debug('x {} y {} z {} k {}'.format(x,y,z,k))
f[k] += 1
z += 1
y += 1
x += 1
for i in range(1,n+1):
debug('f[{}] {}'.format(i,f[i]))
print((f[i]))
| n = int(eval(input()))
f = [0]*(n+1)
x = 1
while x*x < n:
y = 1
while y*y < n:
if x*y >= n: continue
z = 1
while z*z < n:
k = x*x + y*y + z*z + x*y + y*z + z*x
if 1 <= k <= n: f[k] += 1
z += 1
y += 1
x += 1
for i in range(1, n+1): print((f[i]))
| 24 | 15 | 557 | 331 | from logging import *
basicConfig(level=DEBUG, format="%(levelname)s: %(message)s")
disable(CRITICAL)
n = int(eval(input()))
f = [0] * (n + 1)
x = 1
while x * x < n:
y = 1
while y * y < n:
if x * y >= n:
continue
z = 1
while z * z < n:
k = x * x + y * y + z * z + x * y + y * z + z * x
if 1 <= k <= n:
debug("x {} y {} z {} k {}".format(x, y, z, k))
f[k] += 1
z += 1
y += 1
x += 1
for i in range(1, n + 1):
debug("f[{}] {}".format(i, f[i]))
print((f[i]))
| n = int(eval(input()))
f = [0] * (n + 1)
x = 1
while x * x < n:
y = 1
while y * y < n:
if x * y >= n:
continue
z = 1
while z * z < n:
k = x * x + y * y + z * z + x * y + y * z + z * x
if 1 <= k <= n:
f[k] += 1
z += 1
y += 1
x += 1
for i in range(1, n + 1):
print((f[i]))
| false | 37.5 | [
"-from logging import *",
"-",
"-basicConfig(level=DEBUG, format=\"%(levelname)s: %(message)s\")",
"-disable(CRITICAL)",
"- debug(\"x {} y {} z {} k {}\".format(x, y, z, k))",
"- debug(\"f[{}] {}\".format(i, f[i]))"
] | false | 0.058818 | 0.04186 | 1.405097 | [
"s304718754",
"s127625940"
] |
u690536347 | p03128 | python | s062542296 | s979620808 | 198 | 86 | 42,476 | 4,316 | Accepted | Accepted | 56.57 | from collections import defaultdict as dd
n,m=list(map(int,input().split()))
*a,=list(map(int,input().split()))
dp=[-1]*(n+1)
ans = [0] * (n + 1)
cost={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
d={i:cost[i] for i in a}
dp[0] = 0
for i in range(1,n+1):
for j in range(10)[::-1]:
if not j in d:
continue
if cost[j] > i:
continue
if dp[i] < dp[i - cost[j]] + 1:
dp[i] = dp[i - cost[j]] + 1
ans[i] = j
S = ""
pos = n
while pos != 0:
S += str(ans[pos])
pos -= cost[ans[pos]]
print(S)
| n,m=map(int,input().split())
*a,=map(int,input().split())
cost={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
dp=[-1]*(n+1)
v=[0]*(n+1)
dp[0]=0
for i in range(1,n+1):
for j in range(10)[::-1]:
if not j in a or i<cost[j]:continue
if dp[i]<dp[i-cost[j]]+1:
dp[i]=dp[i-cost[j]]+1
v[i]=j
p=n
while p!=0:
print(v[p],end="")
p-=cost[v[p]]
print()
| 30 | 20 | 582 | 405 | from collections import defaultdict as dd
n, m = list(map(int, input().split()))
(*a,) = list(map(int, input().split()))
dp = [-1] * (n + 1)
ans = [0] * (n + 1)
cost = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
d = {i: cost[i] for i in a}
dp[0] = 0
for i in range(1, n + 1):
for j in range(10)[::-1]:
if not j in d:
continue
if cost[j] > i:
continue
if dp[i] < dp[i - cost[j]] + 1:
dp[i] = dp[i - cost[j]] + 1
ans[i] = j
S = ""
pos = n
while pos != 0:
S += str(ans[pos])
pos -= cost[ans[pos]]
print(S)
| n, m = map(int, input().split())
(*a,) = map(int, input().split())
cost = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
dp = [-1] * (n + 1)
v = [0] * (n + 1)
dp[0] = 0
for i in range(1, n + 1):
for j in range(10)[::-1]:
if not j in a or i < cost[j]:
continue
if dp[i] < dp[i - cost[j]] + 1:
dp[i] = dp[i - cost[j]] + 1
v[i] = j
p = n
while p != 0:
print(v[p], end="")
p -= cost[v[p]]
print()
| false | 33.333333 | [
"-from collections import defaultdict as dd",
"-",
"-n, m = list(map(int, input().split()))",
"-(*a,) = list(map(int, input().split()))",
"+n, m = map(int, input().split())",
"+(*a,) = map(int, input().split())",
"+cost = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}",
"-ans = [0] * (n + 1)",... | false | 0.145493 | 0.007104 | 20.481325 | [
"s062542296",
"s979620808"
] |
u150984829 | p00448 | python | s334181697 | s404166810 | 5,290 | 3,660 | 6,916 | 6,912 | Accepted | Accepted | 30.81 | for e in iter(input,'0 0'):
r=int(e.split()[0])
d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
a=0
for m in range(1<<~-r):
t=0
for s in d:
c=bin(m^s).count('1')
t+=c if c>r//2 else r-c
if a<t:a=t
print(a)
| def v():
for e in iter(input,'0 0'):
r=int(e.split()[0])
d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
a=0
for m in range(1<<~-r):
t=0
for s in d:
c=bin(m^s).count('1')
t+=c if c>r//2 else r-c
if a<t:a=t
print(a)
if'__main__'==__name__:v()
| 11 | 13 | 252 | 301 | for e in iter(input, "0 0"):
r = int(e.split()[0])
d = [int("".join(x), 2) for x in zip(*[input().split() for _ in [0] * r])]
a = 0
for m in range(1 << ~-r):
t = 0
for s in d:
c = bin(m ^ s).count("1")
t += c if c > r // 2 else r - c
if a < t:
a = t
print(a)
| def v():
for e in iter(input, "0 0"):
r = int(e.split()[0])
d = [int("".join(x), 2) for x in zip(*[input().split() for _ in [0] * r])]
a = 0
for m in range(1 << ~-r):
t = 0
for s in d:
c = bin(m ^ s).count("1")
t += c if c > r // 2 else r - c
if a < t:
a = t
print(a)
if "__main__" == __name__:
v()
| false | 15.384615 | [
"-for e in iter(input, \"0 0\"):",
"- r = int(e.split()[0])",
"- d = [int(\"\".join(x), 2) for x in zip(*[input().split() for _ in [0] * r])]",
"- a = 0",
"- for m in range(1 << ~-r):",
"- t = 0",
"- for s in d:",
"- c = bin(m ^ s).count(\"1\")",
"- t ... | false | 0.035708 | 0.036981 | 0.965573 | [
"s334181697",
"s404166810"
] |
u451017206 | p03128 | python | s057979525 | s334439448 | 150 | 138 | 14,516 | 28,120 | Accepted | Accepted | 8 | N, M = list(map(int, input().split()))
A = [int(i) for i in input().split()]
# dp[i] = i本使ってできる最大の数
# xを作るために使うマッチの本数
h = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
dp = [-1] * (N + 1)
dp[0] = 0
for i in range(N + 1):
for a in A:
if i - h[a] < 0: continue
dp[i] = max(10*dp[i-h[a]] + a, dp[i])
print((dp[N])) | N, M = list(map(int, input().split()))
A = [i for i in input().split()]
# dp[i] = i本使ってできる最大の数
def mx(a, b):
if a is not None and b is None:
return a
elif a is None and b is not None:
return b
if len(a) != len(b):
if len(a) > len(b):
return a
else:
return b
return max(a, b)
# xを作るために使うマッチの本数
h = {'1':2, '2':5, '3':5, '4':4, '5':5, '6':6, '7':3, '8':7, '9':6}
dp = [None] * (N + 1)
dp[0] = ''
for i in range(N + 1):
for a in A:
if i - h[a] < 0: continue
if dp[i-h[a]] is None and dp[i] is None:
continue
try:
dp[i] = mx(dp[i-h[a]] + a, dp[i])
except:
continue
print((dp[N])) | 17 | 34 | 344 | 750 | N, M = list(map(int, input().split()))
A = [int(i) for i in input().split()]
# dp[i] = i本使ってできる最大の数
# xを作るために使うマッチの本数
h = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
dp = [-1] * (N + 1)
dp[0] = 0
for i in range(N + 1):
for a in A:
if i - h[a] < 0:
continue
dp[i] = max(10 * dp[i - h[a]] + a, dp[i])
print((dp[N]))
| N, M = list(map(int, input().split()))
A = [i for i in input().split()]
# dp[i] = i本使ってできる最大の数
def mx(a, b):
if a is not None and b is None:
return a
elif a is None and b is not None:
return b
if len(a) != len(b):
if len(a) > len(b):
return a
else:
return b
return max(a, b)
# xを作るために使うマッチの本数
h = {"1": 2, "2": 5, "3": 5, "4": 4, "5": 5, "6": 6, "7": 3, "8": 7, "9": 6}
dp = [None] * (N + 1)
dp[0] = ""
for i in range(N + 1):
for a in A:
if i - h[a] < 0:
continue
if dp[i - h[a]] is None and dp[i] is None:
continue
try:
dp[i] = mx(dp[i - h[a]] + a, dp[i])
except:
continue
print((dp[N]))
| false | 50 | [
"-A = [int(i) for i in input().split()]",
"+A = [i for i in input().split()]",
"+def mx(a, b):",
"+ if a is not None and b is None:",
"+ return a",
"+ elif a is None and b is not None:",
"+ return b",
"+ if len(a) != len(b):",
"+ if len(a) > len(b):",
"+ re... | false | 0.04039 | 0.042898 | 0.94155 | [
"s057979525",
"s334439448"
] |
u564589929 | p02947 | python | s142703621 | s823041447 | 1,685 | 355 | 40,016 | 19,880 | Accepted | Accepted | 78.93 | # import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
from collections import Counter
def c2s(c):
s = ''
for key, val in c:
# print(key, val)
# s = f'{s}{key}{val}'
s = '{}{}{}'.format(s, key, val)
# print(s)
return s
def choose2(n):
if n == 1:
return 0
return n * (n - 1) // 2
def solve():
n = II()
S = [list(eval(input())) for _ in range(n)]
jisho = {}
for s in S:
c = sorted(list(Counter(s).items()), key=lambda x: x[0])
# print(c)
key = c2s(c)
jisho[key] = jisho.setdefault(key, 0) + 1
# print(jisho)
ans = 0
for val in list(jisho.values()):
ans = ans + choose2(val)
print(ans)
if __name__ == '__main__':
solve()
| # import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
from collections import Counter
def c2s(c):
s = ''
for key, val in c:
# print(key, val)
# s = f'{s}{key}{val}'
s = '{}{}{}'.format(s, key, val)
# print(s)
return s
def choose2(n):
if n == 1:
return 0
return n * (n - 1) // 2
def solve():
n = II()
S = ["".join(sorted(eval(input()))) for _ in range(n)]
# print(S)
jisho = {}
for s in S:
# c = sorted(Counter(s).items(), key=lambda x: x[0])
# print(c)
# key = c2s(c)
jisho[s] = jisho.setdefault(s, 0) + 1
# print(jisho)
ans = 0
for val in list(jisho.values()):
ans = ans + choose2(val)
print(ans)
if __name__ == '__main__':
solve()
| 46 | 47 | 1,036 | 1,063 | # import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
from collections import Counter
def c2s(c):
s = ""
for key, val in c:
# print(key, val)
# s = f'{s}{key}{val}'
s = "{}{}{}".format(s, key, val)
# print(s)
return s
def choose2(n):
if n == 1:
return 0
return n * (n - 1) // 2
def solve():
n = II()
S = [list(eval(input())) for _ in range(n)]
jisho = {}
for s in S:
c = sorted(list(Counter(s).items()), key=lambda x: x[0])
# print(c)
key = c2s(c)
jisho[key] = jisho.setdefault(key, 0) + 1
# print(jisho)
ans = 0
for val in list(jisho.values()):
ans = ans + choose2(val)
print(ans)
if __name__ == "__main__":
solve()
| # import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
from collections import Counter
def c2s(c):
s = ""
for key, val in c:
# print(key, val)
# s = f'{s}{key}{val}'
s = "{}{}{}".format(s, key, val)
# print(s)
return s
def choose2(n):
if n == 1:
return 0
return n * (n - 1) // 2
def solve():
n = II()
S = ["".join(sorted(eval(input()))) for _ in range(n)]
# print(S)
jisho = {}
for s in S:
# c = sorted(Counter(s).items(), key=lambda x: x[0])
# print(c)
# key = c2s(c)
jisho[s] = jisho.setdefault(s, 0) + 1
# print(jisho)
ans = 0
for val in list(jisho.values()):
ans = ans + choose2(val)
print(ans)
if __name__ == "__main__":
solve()
| false | 2.12766 | [
"- S = [list(eval(input())) for _ in range(n)]",
"+ S = [\"\".join(sorted(eval(input()))) for _ in range(n)]",
"+ # print(S)",
"- c = sorted(list(Counter(s).items()), key=lambda x: x[0])",
"+ # c = sorted(Counter(s).items(), key=lambda x: x[0])",
"- key = c2s(c)",
"- ... | false | 0.046511 | 0.045765 | 1.016306 | [
"s142703621",
"s823041447"
] |
u929569377 | p03162 | python | s604340321 | s634823652 | 950 | 634 | 47,280 | 47,380 | Accepted | Accepted | 33.26 | N = int(eval(input()))
abc = [list([int(x) for x in input().split()]) for _ in range(N)]
happy = [[0] * 3 for _ in range(N)]
for i in range(3):
happy[0][i] = abc[0][i]
for i in range(1, N):
for j in range(3):
for k in range(3):
if j != k and happy[i][j] < happy[i - 1][k]:
happy[i][j] = happy[i - 1][k]
happy[i][j] += abc[i][j]
print((max(happy[N - 1][0], happy[N - 1][1], happy[N - 1][2]))) | N = int(eval(input()))
abc = [list([int(x) for x in input().split()]) for _ in range(N)]
happy = [[0] * 3 for _ in range(N)]
for i in range(3):
happy[0][i] = abc[0][i]
for i in range(1, N):
happy[i][0] = max(happy[i - 1][1], happy[i - 1][2]) + abc[i][0]
happy[i][1] = max(happy[i - 1][0], happy[i - 1][2]) + abc[i][1]
happy[i][2] = max(happy[i - 1][0], happy[i - 1][1]) + abc[i][2]
print((max(happy[N - 1][0], happy[N - 1][1], happy[N - 1][2]))) | 16 | 14 | 420 | 463 | N = int(eval(input()))
abc = [list([int(x) for x in input().split()]) for _ in range(N)]
happy = [[0] * 3 for _ in range(N)]
for i in range(3):
happy[0][i] = abc[0][i]
for i in range(1, N):
for j in range(3):
for k in range(3):
if j != k and happy[i][j] < happy[i - 1][k]:
happy[i][j] = happy[i - 1][k]
happy[i][j] += abc[i][j]
print((max(happy[N - 1][0], happy[N - 1][1], happy[N - 1][2])))
| N = int(eval(input()))
abc = [list([int(x) for x in input().split()]) for _ in range(N)]
happy = [[0] * 3 for _ in range(N)]
for i in range(3):
happy[0][i] = abc[0][i]
for i in range(1, N):
happy[i][0] = max(happy[i - 1][1], happy[i - 1][2]) + abc[i][0]
happy[i][1] = max(happy[i - 1][0], happy[i - 1][2]) + abc[i][1]
happy[i][2] = max(happy[i - 1][0], happy[i - 1][1]) + abc[i][2]
print((max(happy[N - 1][0], happy[N - 1][1], happy[N - 1][2])))
| false | 12.5 | [
"- for j in range(3):",
"- for k in range(3):",
"- if j != k and happy[i][j] < happy[i - 1][k]:",
"- happy[i][j] = happy[i - 1][k]",
"- happy[i][j] += abc[i][j]",
"+ happy[i][0] = max(happy[i - 1][1], happy[i - 1][2]) + abc[i][0]",
"+ happy[i][1] = max(ha... | false | 0.042678 | 0.050888 | 0.83866 | [
"s604340321",
"s634823652"
] |
u679325651 | p03031 | python | s895113762 | s879641863 | 32 | 21 | 3,064 | 3,064 | Accepted | Accepted | 34.38 | N,M = [int(i) for i in input().split()] #Nがスイッチの数、Mは電球の数
sss = []
for i in range(M):
buff = [int(i)-1 for i in input().split()][1:]
onoff = [0 for i in range(N)]
for j in buff:
onoff[j]=1
sss.append(onoff)
ppp = [int(i) for i in input().split()]
ct=0
for i in range(1<<N):
bitcode = [int(i) for i in list(bin(i)[2:].zfill(N))]
for s,p in zip(sss,ppp):
if sum(j*k for j,k in zip(s,bitcode))%2!=p:
break
else:
ct+=1
print(ct) | N,M = [int(i) for i in input().split()]
switches = []
for i in range(M):
buff = 0
k,*sss = [int(i) for i in input().split()]
for s in sss:
buff += 1 << (s-1)
switches.append(buff)
ppp = [int(i) for i in input().split()]
ans = 0
for i in range(1<<N):
for p,s in zip(ppp,switches):
buff = s&i
buff = bin(buff).count("1")%2
if buff != p:
break
else:
ans += 1
print(ans) | 21 | 21 | 510 | 464 | N, M = [int(i) for i in input().split()] # Nがスイッチの数、Mは電球の数
sss = []
for i in range(M):
buff = [int(i) - 1 for i in input().split()][1:]
onoff = [0 for i in range(N)]
for j in buff:
onoff[j] = 1
sss.append(onoff)
ppp = [int(i) for i in input().split()]
ct = 0
for i in range(1 << N):
bitcode = [int(i) for i in list(bin(i)[2:].zfill(N))]
for s, p in zip(sss, ppp):
if sum(j * k for j, k in zip(s, bitcode)) % 2 != p:
break
else:
ct += 1
print(ct)
| N, M = [int(i) for i in input().split()]
switches = []
for i in range(M):
buff = 0
k, *sss = [int(i) for i in input().split()]
for s in sss:
buff += 1 << (s - 1)
switches.append(buff)
ppp = [int(i) for i in input().split()]
ans = 0
for i in range(1 << N):
for p, s in zip(ppp, switches):
buff = s & i
buff = bin(buff).count("1") % 2
if buff != p:
break
else:
ans += 1
print(ans)
| false | 0 | [
"-N, M = [int(i) for i in input().split()] # Nがスイッチの数、Mは電球の数",
"-sss = []",
"+N, M = [int(i) for i in input().split()]",
"+switches = []",
"- buff = [int(i) - 1 for i in input().split()][1:]",
"- onoff = [0 for i in range(N)]",
"- for j in buff:",
"- onoff[j] = 1",
"- sss.append(... | false | 0.078997 | 0.03743 | 2.110513 | [
"s895113762",
"s879641863"
] |
u761529120 | p03599 | python | s318945372 | s685146190 | 234 | 104 | 42,348 | 73,612 | Accepted | Accepted | 55.56 | A, B, C, D, E, F = list(map(int, input().split()))
ans = -1
sugar = 0
sugar_water = 0
for a in range(F // (A * 100) + 1):
for b in range((F - 100 * A * a) // (B * 100) + 1):
for c in range((F - 100 * A * a - 100 * B * b) // C + 1):
for d in range((F - 100 * A * a - 100 * B * b - C * c) // D + 1):
x = a * A + b * B
y = c * C + d * D
if x == 0:
continue
if x * E >= y and ans < (100 * y)/(x*100+y):
ans = (100 * y)/(x*100+y)
sugar = y
sugar_water = 100 * x + y
print((sugar_water,sugar))
| def main():
A, B, C, D, E, F = list(map(int, input().split()))
ans = -1
sugar = 0
sugar_water = 0
for a in range(F // (A * 100) + 1):
for b in range((F - 100 * A * a) // (B * 100) + 1):
for c in range((F - 100 * A * a - 100 * B * b) // C + 1):
for d in range((F - 100 * A * a - 100 * B * b - C * c) // D + 1):
x = a * A + b * B
y = c * C + d * D
if x == 0:
continue
if x * E >= y and ans < (100 * y)/(x*100+y):
ans = (100 * y)/(x*100+y)
sugar = y
sugar_water = 100 * x + y
print((sugar_water,sugar))
if __name__ == "__main__":
main() | 18 | 21 | 666 | 786 | A, B, C, D, E, F = list(map(int, input().split()))
ans = -1
sugar = 0
sugar_water = 0
for a in range(F // (A * 100) + 1):
for b in range((F - 100 * A * a) // (B * 100) + 1):
for c in range((F - 100 * A * a - 100 * B * b) // C + 1):
for d in range((F - 100 * A * a - 100 * B * b - C * c) // D + 1):
x = a * A + b * B
y = c * C + d * D
if x == 0:
continue
if x * E >= y and ans < (100 * y) / (x * 100 + y):
ans = (100 * y) / (x * 100 + y)
sugar = y
sugar_water = 100 * x + y
print((sugar_water, sugar))
| def main():
A, B, C, D, E, F = list(map(int, input().split()))
ans = -1
sugar = 0
sugar_water = 0
for a in range(F // (A * 100) + 1):
for b in range((F - 100 * A * a) // (B * 100) + 1):
for c in range((F - 100 * A * a - 100 * B * b) // C + 1):
for d in range((F - 100 * A * a - 100 * B * b - C * c) // D + 1):
x = a * A + b * B
y = c * C + d * D
if x == 0:
continue
if x * E >= y and ans < (100 * y) / (x * 100 + y):
ans = (100 * y) / (x * 100 + y)
sugar = y
sugar_water = 100 * x + y
print((sugar_water, sugar))
if __name__ == "__main__":
main()
| false | 14.285714 | [
"-A, B, C, D, E, F = list(map(int, input().split()))",
"-ans = -1",
"-sugar = 0",
"-sugar_water = 0",
"-for a in range(F // (A * 100) + 1):",
"- for b in range((F - 100 * A * a) // (B * 100) + 1):",
"- for c in range((F - 100 * A * a - 100 * B * b) // C + 1):",
"- for d in range((... | false | 0.150107 | 0.101488 | 1.479057 | [
"s318945372",
"s685146190"
] |
u983647429 | p03449 | python | s952087029 | s759146874 | 23 | 17 | 3,064 | 2,940 | Accepted | Accepted | 26.09 | def main(input):
N = int(eval(input()))
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
ans = [0] * N
for i in range(N):
ans[i] = sum(A1[:i+1]) + sum(A2[i:])
print((max(ans)))
import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "local":
with open("stdin.txt") as stdin:
main(stdin.readline)
else:
main(sys.stdin.readline)
| N = int(eval(input()))
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
ans = [sum(A1[:i+1]) + sum(A2[i:]) for i in range(N)]
print((max(ans)))
| 16 | 5 | 480 | 165 | def main(input):
N = int(eval(input()))
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
ans = [0] * N
for i in range(N):
ans[i] = sum(A1[: i + 1]) + sum(A2[i:])
print((max(ans)))
import sys
sys.setrecursionlimit(50000)
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "local":
with open("stdin.txt") as stdin:
main(stdin.readline)
else:
main(sys.stdin.readline)
| N = int(eval(input()))
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
ans = [sum(A1[: i + 1]) + sum(A2[i:]) for i in range(N)]
print((max(ans)))
| false | 68.75 | [
"-def main(input):",
"- N = int(eval(input()))",
"- A1 = list(map(int, input().split()))",
"- A2 = list(map(int, input().split()))",
"- ans = [0] * N",
"- for i in range(N):",
"- ans[i] = sum(A1[: i + 1]) + sum(A2[i:])",
"- print((max(ans)))",
"-",
"-",
"-import sys",
... | false | 0.038471 | 0.036991 | 1.040015 | [
"s952087029",
"s759146874"
] |
u879870653 | p03162 | python | s023158525 | s623240101 | 670 | 618 | 78,296 | 47,368 | Accepted | Accepted | 7.76 | N = int(eval(input()))
L = list(list(map(int,input().split())) for i in range(N))
dp = [[0,0,0] for i in range(N+1)]
for i in range(N) :
dp[i+1][0] = max(dp[i][1], dp[i][2]) + L[i][0]
dp[i+1][1] = max(dp[i][2], dp[i][0]) + L[i][1]
dp[i+1][2] = max(dp[i][0], dp[i][1]) + L[i][2]
ans = max(dp[N][0], dp[N][1], dp[N][2])
print(ans)
| N = int(eval(input()))
L = [list(map(int,input().split())) for i in range(N)]
dp = [[0,0,0] for i in range(N)]
dp[0] = L[0]
for i in range(1,N) :
dp[i][0] = max(dp[i-1][1] + L[i][0],dp[i-1][2] + L[i][0])
dp[i][1] = max(dp[i-1][2] + L[i][1],dp[i-1][0] + L[i][1])
dp[i][2] = max(dp[i-1][0] + L[i][2],dp[i-1][1] + L[i][2])
ans = max(dp[N-1])
print(ans)
| 12 | 14 | 349 | 373 | N = int(eval(input()))
L = list(list(map(int, input().split())) for i in range(N))
dp = [[0, 0, 0] for i in range(N + 1)]
for i in range(N):
dp[i + 1][0] = max(dp[i][1], dp[i][2]) + L[i][0]
dp[i + 1][1] = max(dp[i][2], dp[i][0]) + L[i][1]
dp[i + 1][2] = max(dp[i][0], dp[i][1]) + L[i][2]
ans = max(dp[N][0], dp[N][1], dp[N][2])
print(ans)
| N = int(eval(input()))
L = [list(map(int, input().split())) for i in range(N)]
dp = [[0, 0, 0] for i in range(N)]
dp[0] = L[0]
for i in range(1, N):
dp[i][0] = max(dp[i - 1][1] + L[i][0], dp[i - 1][2] + L[i][0])
dp[i][1] = max(dp[i - 1][2] + L[i][1], dp[i - 1][0] + L[i][1])
dp[i][2] = max(dp[i - 1][0] + L[i][2], dp[i - 1][1] + L[i][2])
ans = max(dp[N - 1])
print(ans)
| false | 14.285714 | [
"-L = list(list(map(int, input().split())) for i in range(N))",
"-dp = [[0, 0, 0] for i in range(N + 1)]",
"-for i in range(N):",
"- dp[i + 1][0] = max(dp[i][1], dp[i][2]) + L[i][0]",
"- dp[i + 1][1] = max(dp[i][2], dp[i][0]) + L[i][1]",
"- dp[i + 1][2] = max(dp[i][0], dp[i][1]) + L[i][2]",
"-a... | false | 0.036732 | 0.040839 | 0.899431 | [
"s023158525",
"s623240101"
] |
u421674761 | p02725 | python | s988705460 | s593721296 | 121 | 107 | 32,276 | 32,216 | Accepted | Accepted | 11.57 | k,n = list(map(int,input().split()))
a = list(map(int,input().split()))
b = []
for i in range(n-1):
kyori = a[i+1] - a[i]
b.append(kyori)
b.append(abs(a[0]+(k-a[-1])))
print((sum(b)-max(b)))
| k,n = list(map(int,input().split()))
a = list(map(int,input().split()))
b = []
for i in range(n-1):
b.append(a[i+1]-a[i])
b.append(a[0]+(k-a[-1]))
print((sum(b)-max(b)))
| 10 | 10 | 202 | 178 | k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
b = []
for i in range(n - 1):
kyori = a[i + 1] - a[i]
b.append(kyori)
b.append(abs(a[0] + (k - a[-1])))
print((sum(b) - max(b)))
| k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
b = []
for i in range(n - 1):
b.append(a[i + 1] - a[i])
b.append(a[0] + (k - a[-1]))
print((sum(b) - max(b)))
| false | 0 | [
"- kyori = a[i + 1] - a[i]",
"- b.append(kyori)",
"-b.append(abs(a[0] + (k - a[-1])))",
"+ b.append(a[i + 1] - a[i])",
"+b.append(a[0] + (k - a[-1]))"
] | false | 0.036245 | 0.036921 | 0.981691 | [
"s988705460",
"s593721296"
] |
u826263061 | p04031 | python | s572582291 | s668835983 | 23 | 18 | 3,064 | 3,060 | Accepted | Accepted | 21.74 | n = int(eval(input()))
a=list(map(int,input().split()))
#print(a)
amin = min(a)
amax = max(a)
min_sum=10**8
for x in range(amin,amax+1):
sum_for_x = sum([(y-x)**2 for y in a])
if sum_for_x < min_sum:
min_sum = sum_for_x
print(min_sum) | # -*- coding: utf-8 -*-
"""
Created on Sat Aug 4 18:19:03 2018
@author: maezawa
"""
n = int(eval(input()))
a = list(map(int, input().split()))
mean_a = round(sum(a)/n)
ans = 0
for i in a:
ans += (i-mean_a)**2
print(ans) | 14 | 17 | 263 | 239 | n = int(eval(input()))
a = list(map(int, input().split()))
# print(a)
amin = min(a)
amax = max(a)
min_sum = 10**8
for x in range(amin, amax + 1):
sum_for_x = sum([(y - x) ** 2 for y in a])
if sum_for_x < min_sum:
min_sum = sum_for_x
print(min_sum)
| # -*- coding: utf-8 -*-
"""
Created on Sat Aug 4 18:19:03 2018
@author: maezawa
"""
n = int(eval(input()))
a = list(map(int, input().split()))
mean_a = round(sum(a) / n)
ans = 0
for i in a:
ans += (i - mean_a) ** 2
print(ans)
| false | 17.647059 | [
"+# -*- coding: utf-8 -*-",
"+\"\"\"",
"+Created on Sat Aug 4 18:19:03 2018",
"+@author: maezawa",
"+\"\"\"",
"-# print(a)",
"-amin = min(a)",
"-amax = max(a)",
"-min_sum = 10**8",
"-for x in range(amin, amax + 1):",
"- sum_for_x = sum([(y - x) ** 2 for y in a])",
"- if sum_for_x < min_... | false | 0.038519 | 0.04468 | 0.862109 | [
"s572582291",
"s668835983"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.