user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
sequence | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
sequence |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u498467969 | p04044 | python | s956790736 | s013124789 | 318 | 37 | 3,448 | 3,064 | Accepted | Accepted | 88.36 | N, L = list(map(int, input().split()))
S = []
s = ""
for _ in range(N):
S.append(eval(input()))
S.sort()
for i in range(N):
s += S[i]
print(s)
| N, L = list(map(int, input().split()))
S = [eval(input()) for _ in range(N)]
s = ""
S.sort()
for i in range(N):
s += S[i]
print(s)
| 13 | 11 | 170 | 150 | N, L = list(map(int, input().split()))
S = []
s = ""
for _ in range(N):
S.append(eval(input()))
S.sort()
for i in range(N):
s += S[i]
print(s)
| N, L = list(map(int, input().split()))
S = [eval(input()) for _ in range(N)]
s = ""
S.sort()
for i in range(N):
s += S[i]
print(s)
| false | 15.384615 | [
"-S = []",
"+S = [eval(input()) for _ in range(N)]",
"-for _ in range(N):",
"- S.append(eval(input()))"
] | false | 0.037572 | 0.042276 | 0.888742 | [
"s956790736",
"s013124789"
] |
u788703383 | p03472 | python | s999555444 | s615282241 | 297 | 255 | 27,836 | 18,188 | Accepted | Accepted | 14.14 | import math
n,h = list(map(int,input().split()))
l = []; x,y = 0,0
for _ in range(n):
a,b = list(map(int,input().split()))
if a > x or a == x and b < y:
x,y = a,b
if b < x:continue
l.append((a,b))
l.remove((x,y))
l = sorted(l,key=lambda x:-x[1])
ans = 0
for a,b in l:
if b <= x:break
if b < y and y >= h:
print((ans+1));exit()
h -= max(b,x)
ans += 1
if h <= 0:
print(ans);exit()
d = math.ceil((max(0,h-y))/x)
print((ans + d + 1))
| import math
n,h = list(map(int,input().split()))
A = 0; b = []; ans = 0
for _ in range(n):
u,v = list(map(int,input().split()))
A = max(A,u); b.append(v)
for B in sorted(b,key=lambda x:-x):
if h <= 0 or B <= A:break
h -= B
ans += 1
print((max(0,math.ceil(h/A)) + ans)) | 22 | 12 | 495 | 286 | import math
n, h = list(map(int, input().split()))
l = []
x, y = 0, 0
for _ in range(n):
a, b = list(map(int, input().split()))
if a > x or a == x and b < y:
x, y = a, b
if b < x:
continue
l.append((a, b))
l.remove((x, y))
l = sorted(l, key=lambda x: -x[1])
ans = 0
for a, b in l:
if b <= x:
break
if b < y and y >= h:
print((ans + 1))
exit()
h -= max(b, x)
ans += 1
if h <= 0:
print(ans)
exit()
d = math.ceil((max(0, h - y)) / x)
print((ans + d + 1))
| import math
n, h = list(map(int, input().split()))
A = 0
b = []
ans = 0
for _ in range(n):
u, v = list(map(int, input().split()))
A = max(A, u)
b.append(v)
for B in sorted(b, key=lambda x: -x):
if h <= 0 or B <= A:
break
h -= B
ans += 1
print((max(0, math.ceil(h / A)) + ans))
| false | 45.454545 | [
"-l = []",
"-x, y = 0, 0",
"+A = 0",
"+b = []",
"+ans = 0",
"- a, b = list(map(int, input().split()))",
"- if a > x or a == x and b < y:",
"- x, y = a, b",
"- if b < x:",
"- continue",
"- l.append((a, b))",
"-l.remove((x, y))",
"-l = sorted(l, key=lambda x: -x[1])",
"-ans = 0",
"-for a, b in l:",
"- if b <= x:",
"+ u, v = list(map(int, input().split()))",
"+ A = max(A, u)",
"+ b.append(v)",
"+for B in sorted(b, key=lambda x: -x):",
"+ if h <= 0 or B <= A:",
"- if b < y and y >= h:",
"- print((ans + 1))",
"- exit()",
"- h -= max(b, x)",
"+ h -= B",
"- if h <= 0:",
"- print(ans)",
"- exit()",
"-d = math.ceil((max(0, h - y)) / x)",
"-print((ans + d + 1))",
"+print((max(0, math.ceil(h / A)) + ans))"
] | false | 0.048691 | 0.044467 | 1.095005 | [
"s999555444",
"s615282241"
] |
u508732591 | p02257 | python | s795730102 | s320365619 | 70 | 60 | 7,704 | 7,736 | Accepted | Accepted | 14.29 | def maybe_prime(d,s,n):
for a in (2,3,5,7):
x = pow(a,d,n)
if x==1 or x==n-1:
continue
for i in range(1,s):
x = pow(x,2,n)
if x==1: return False
elif x == n-1:
break
else:
return False
return True
def is_prime(n):
if n in (2,3,5,7): return True
elif 0 in (n%2,n%3,n%5,n%7): return False
elif 0 in [ n%i for i in range(11,min(n-1,50),2) ]:return False
else:
d,s = n-1, 0
while not d%2:
d,s = d>>1,s+1
return maybe_prime(d,s,n)
cnt = 0
n = int(eval(input()))
for i in range(n):
n = int(eval(input()))
if is_prime(n): cnt+=1
print(cnt) | def maybe_prime(d,s,n):
for a in (2,3,5,7):
x = pow(a,d,n)
if x==1 or x==n-1:
continue
for i in range(1,s):
x = x*x%n
if x==1: return False
elif x == n-1:
break
else:
return False
return True
def is_prime(n):
if n in (2,3,5,7): return True
elif 0 in (n%2,n%3,n%5,n%7): return False
else:
d,s = n-1, 0
while not d%2:
d,s = d>>1,s+1
return maybe_prime(d,s,n)
cnt = 0
n = int(eval(input()))
for i in range(n):
n = int(eval(input()))
if is_prime(n): cnt+=1
print(cnt) | 30 | 29 | 723 | 655 | def maybe_prime(d, s, n):
for a in (2, 3, 5, 7):
x = pow(a, d, n)
if x == 1 or x == n - 1:
continue
for i in range(1, s):
x = pow(x, 2, n)
if x == 1:
return False
elif x == n - 1:
break
else:
return False
return True
def is_prime(n):
if n in (2, 3, 5, 7):
return True
elif 0 in (n % 2, n % 3, n % 5, n % 7):
return False
elif 0 in [n % i for i in range(11, min(n - 1, 50), 2)]:
return False
else:
d, s = n - 1, 0
while not d % 2:
d, s = d >> 1, s + 1
return maybe_prime(d, s, n)
cnt = 0
n = int(eval(input()))
for i in range(n):
n = int(eval(input()))
if is_prime(n):
cnt += 1
print(cnt)
| def maybe_prime(d, s, n):
for a in (2, 3, 5, 7):
x = pow(a, d, n)
if x == 1 or x == n - 1:
continue
for i in range(1, s):
x = x * x % n
if x == 1:
return False
elif x == n - 1:
break
else:
return False
return True
def is_prime(n):
if n in (2, 3, 5, 7):
return True
elif 0 in (n % 2, n % 3, n % 5, n % 7):
return False
else:
d, s = n - 1, 0
while not d % 2:
d, s = d >> 1, s + 1
return maybe_prime(d, s, n)
cnt = 0
n = int(eval(input()))
for i in range(n):
n = int(eval(input()))
if is_prime(n):
cnt += 1
print(cnt)
| false | 3.333333 | [
"- x = pow(x, 2, n)",
"+ x = x * x % n",
"- return False",
"- elif 0 in [n % i for i in range(11, min(n - 1, 50), 2)]:"
] | false | 0.043129 | 0.044854 | 0.961554 | [
"s795730102",
"s320365619"
] |
u562935282 | p03111 | python | s375411341 | s872909518 | 325 | 228 | 3,064 | 9,220 | Accepted | Accepted | 29.85 | def main():
from itertools import product
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
ans = 3000
for prod in product([0, 1, 2, 3], repeat=N):
t = [[] for _ in range(3)]
for i, x in enumerate(prod):
if x == 3: continue
t[x].append(i)
if (not t[0]) or (not t[1]) or (not t[2]): continue
cost = sum(len(t[i]) - 1 for i in range(3)) * 10
a = sum(L[i] for i in t[0])
b = sum(L[i] for i in t[1])
c = sum(L[i] for i in t[2])
cost += abs(A - a) + abs(B - b) + abs(C - c)
if ans > cost:
ans = cost
print(ans)
if __name__ == '__main__':
main()
| from itertools import product
INF = 10 ** 9
N, *A = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
def estimate(lst):
if any(not p for p in lst):
return INF
ret = 0
for p, g in zip(lst, A):
ret += abs(g - sum(p)) + (len(p) - 1) * 10
return ret
ans = INF
for prd in product(list(range(4)), repeat=N):
pieces = [[] for _ in range(3)]
for bamboo_ind, target_kadomatsu in enumerate(prd):
if target_kadomatsu == 3: continue
pieces[target_kadomatsu].append(L[bamboo_ind])
if ans > (res := estimate(pieces)):
ans = res
print(ans)
| 27 | 27 | 734 | 634 | def main():
from itertools import product
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
ans = 3000
for prod in product([0, 1, 2, 3], repeat=N):
t = [[] for _ in range(3)]
for i, x in enumerate(prod):
if x == 3:
continue
t[x].append(i)
if (not t[0]) or (not t[1]) or (not t[2]):
continue
cost = sum(len(t[i]) - 1 for i in range(3)) * 10
a = sum(L[i] for i in t[0])
b = sum(L[i] for i in t[1])
c = sum(L[i] for i in t[2])
cost += abs(A - a) + abs(B - b) + abs(C - c)
if ans > cost:
ans = cost
print(ans)
if __name__ == "__main__":
main()
| from itertools import product
INF = 10**9
N, *A = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
def estimate(lst):
if any(not p for p in lst):
return INF
ret = 0
for p, g in zip(lst, A):
ret += abs(g - sum(p)) + (len(p) - 1) * 10
return ret
ans = INF
for prd in product(list(range(4)), repeat=N):
pieces = [[] for _ in range(3)]
for bamboo_ind, target_kadomatsu in enumerate(prd):
if target_kadomatsu == 3:
continue
pieces[target_kadomatsu].append(L[bamboo_ind])
if ans > (res := estimate(pieces)):
ans = res
print(ans)
| false | 0 | [
"-def main():",
"- from itertools import product",
"+from itertools import product",
"- N, A, B, C = list(map(int, input().split()))",
"- L = [int(eval(input())) for _ in range(N)]",
"- ans = 3000",
"- for prod in product([0, 1, 2, 3], repeat=N):",
"- t = [[] for _ in range(3)]",
"- for i, x in enumerate(prod):",
"- if x == 3:",
"- continue",
"- t[x].append(i)",
"- if (not t[0]) or (not t[1]) or (not t[2]):",
"- continue",
"- cost = sum(len(t[i]) - 1 for i in range(3)) * 10",
"- a = sum(L[i] for i in t[0])",
"- b = sum(L[i] for i in t[1])",
"- c = sum(L[i] for i in t[2])",
"- cost += abs(A - a) + abs(B - b) + abs(C - c)",
"- if ans > cost:",
"- ans = cost",
"- print(ans)",
"+INF = 10**9",
"+N, *A = list(map(int, input().split()))",
"+L = [int(eval(input())) for _ in range(N)]",
"-if __name__ == \"__main__\":",
"- main()",
"+def estimate(lst):",
"+ if any(not p for p in lst):",
"+ return INF",
"+ ret = 0",
"+ for p, g in zip(lst, A):",
"+ ret += abs(g - sum(p)) + (len(p) - 1) * 10",
"+ return ret",
"+",
"+",
"+ans = INF",
"+for prd in product(list(range(4)), repeat=N):",
"+ pieces = [[] for _ in range(3)]",
"+ for bamboo_ind, target_kadomatsu in enumerate(prd):",
"+ if target_kadomatsu == 3:",
"+ continue",
"+ pieces[target_kadomatsu].append(L[bamboo_ind])",
"+ if ans > (res := estimate(pieces)):",
"+ ans = res",
"+print(ans)"
] | false | 0.230447 | 0.280595 | 0.82128 | [
"s375411341",
"s872909518"
] |
u724687935 | p04000 | python | s465994793 | s983154322 | 1,567 | 848 | 155,896 | 169,080 | Accepted | Accepted | 45.88 | def main():
import sys
# readline = sys.stdin.readline
readlines = sys.stdin.readlines
H, W, N = map(int, input().split())
grid = {}
P = set()
for s in readlines():
a, b = map(int, s.split())
a -= 1; b -= 1
if a in grid:
grid[a].add(b)
else:
grid[a] = set([b])
P.add((a, b))
ans = [0] * 10
done = set()
for a, b in P:
for oa in range(a - 2, a + 1):
for ob in range(b - 2, b + 1):
if 0 <= oa <= H - 3 and 0 <= ob <= W - 3 and (oa, ob) not in done:
tmp = 0
for i in range(3):
for j in range(3):
na = oa + i
nb = ob + j
if (na, nb) in P:
tmp += 1
ans[tmp] += 1
done.add((oa, ob))
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
print(*ans, sep='\n')
if __name__ == "__main__":
main()
| def main():
import sys
from collections import Counter
# readline = sys.stdin.readline
readlines = sys.stdin.readlines
H, W, N = list(map(int, input().split()))
P = set()
for s in readlines():
a, b = list(map(int, s.split()))
a -= 1; b -= 1
P.add((a, b))
cnt = Counter()
for a, b in P:
for oa in range(a - 2, a + 1):
for ob in range(b - 2, b + 1):
if 0 <= oa <= H - 3 and 0 <= ob <= W - 3:
cnt[(oa, ob)] += 1
ans = Counter(list(cnt.values()))
ans[0] = (H - 2) * (W - 2) - sum(ans.values())
for i in range(10):
print((ans[i]))
if __name__ == "__main__":
main()
| 39 | 27 | 1,094 | 710 | def main():
import sys
# readline = sys.stdin.readline
readlines = sys.stdin.readlines
H, W, N = map(int, input().split())
grid = {}
P = set()
for s in readlines():
a, b = map(int, s.split())
a -= 1
b -= 1
if a in grid:
grid[a].add(b)
else:
grid[a] = set([b])
P.add((a, b))
ans = [0] * 10
done = set()
for a, b in P:
for oa in range(a - 2, a + 1):
for ob in range(b - 2, b + 1):
if 0 <= oa <= H - 3 and 0 <= ob <= W - 3 and (oa, ob) not in done:
tmp = 0
for i in range(3):
for j in range(3):
na = oa + i
nb = ob + j
if (na, nb) in P:
tmp += 1
ans[tmp] += 1
done.add((oa, ob))
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
print(*ans, sep="\n")
if __name__ == "__main__":
main()
| def main():
import sys
from collections import Counter
# readline = sys.stdin.readline
readlines = sys.stdin.readlines
H, W, N = list(map(int, input().split()))
P = set()
for s in readlines():
a, b = list(map(int, s.split()))
a -= 1
b -= 1
P.add((a, b))
cnt = Counter()
for a, b in P:
for oa in range(a - 2, a + 1):
for ob in range(b - 2, b + 1):
if 0 <= oa <= H - 3 and 0 <= ob <= W - 3:
cnt[(oa, ob)] += 1
ans = Counter(list(cnt.values()))
ans[0] = (H - 2) * (W - 2) - sum(ans.values())
for i in range(10):
print((ans[i]))
if __name__ == "__main__":
main()
| false | 30.769231 | [
"+ from collections import Counter",
"- H, W, N = map(int, input().split())",
"- grid = {}",
"+ H, W, N = list(map(int, input().split()))",
"- a, b = map(int, s.split())",
"+ a, b = list(map(int, s.split()))",
"- if a in grid:",
"- grid[a].add(b)",
"- else:",
"- grid[a] = set([b])",
"- ans = [0] * 10",
"- done = set()",
"+ cnt = Counter()",
"- if 0 <= oa <= H - 3 and 0 <= ob <= W - 3 and (oa, ob) not in done:",
"- tmp = 0",
"- for i in range(3):",
"- for j in range(3):",
"- na = oa + i",
"- nb = ob + j",
"- if (na, nb) in P:",
"- tmp += 1",
"- ans[tmp] += 1",
"- done.add((oa, ob))",
"- ans[0] = (H - 2) * (W - 2) - sum(ans[1:])",
"- print(*ans, sep=\"\\n\")",
"+ if 0 <= oa <= H - 3 and 0 <= ob <= W - 3:",
"+ cnt[(oa, ob)] += 1",
"+ ans = Counter(list(cnt.values()))",
"+ ans[0] = (H - 2) * (W - 2) - sum(ans.values())",
"+ for i in range(10):",
"+ print((ans[i]))"
] | false | 0.037845 | 0.065137 | 0.581006 | [
"s465994793",
"s983154322"
] |
u735335967 | p03680 | python | s304709426 | s230943695 | 329 | 206 | 25,136 | 7,084 | Accepted | Accepted | 37.39 | n = int(eval(input()))
a = [list(map(int, input().split())) for i in range(n)]
a = [e for row in a for e in row]
ans = 0
i = 0
while n > 0:
ans += 1
if a[i] == 2:
print(ans)
quit()
else:
i = a[i]-1
n -= 1
print((-1))
| n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
ans = 0
i = 0
while n > 0:
ans += 1
if a[i] == 2:
print(ans)
quit()
else:
i = a[i]-1
n -= 1
print((-1))
| 14 | 14 | 262 | 210 | n = int(eval(input()))
a = [list(map(int, input().split())) for i in range(n)]
a = [e for row in a for e in row]
ans = 0
i = 0
while n > 0:
ans += 1
if a[i] == 2:
print(ans)
quit()
else:
i = a[i] - 1
n -= 1
print((-1))
| n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
ans = 0
i = 0
while n > 0:
ans += 1
if a[i] == 2:
print(ans)
quit()
else:
i = a[i] - 1
n -= 1
print((-1))
| false | 0 | [
"-a = [list(map(int, input().split())) for i in range(n)]",
"-a = [e for row in a for e in row]",
"+a = [int(eval(input())) for i in range(n)]"
] | false | 0.03794 | 0.08931 | 0.424814 | [
"s304709426",
"s230943695"
] |
u627803856 | p02819 | python | s553710850 | s909890852 | 177 | 71 | 38,384 | 64,428 | Accepted | Accepted | 59.89 | x = int(eval(input()))
def is_prime(n):
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return n != 1 # 1のときは例外
while True:
if is_prime(x):
print(x)
break
x += 1 | x = int(eval(input()))
# 素数
n = 10 ** 5 + 1000
primes = [True] * (n + 1)
p = 2
while p * p <= n:
if primes[p]:
for i in range(p * p, n + 1, p): # p*pスタートでいいのか
primes[i] = False
p += 1
primes[0], primes[1] = False, False
while True:
if primes[x]:
print(x)
exit()
x += 1 | 14 | 19 | 202 | 335 | x = int(eval(input()))
def is_prime(n):
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return n != 1 # 1のときは例外
while True:
if is_prime(x):
print(x)
break
x += 1
| x = int(eval(input()))
# 素数
n = 10**5 + 1000
primes = [True] * (n + 1)
p = 2
while p * p <= n:
if primes[p]:
for i in range(p * p, n + 1, p): # p*pスタートでいいのか
primes[i] = False
p += 1
primes[0], primes[1] = False, False
while True:
if primes[x]:
print(x)
exit()
x += 1
| false | 26.315789 | [
"-",
"-",
"-def is_prime(n):",
"- for i in range(2, int(n**0.5) + 1):",
"- if n % i == 0:",
"- return False",
"- return n != 1 # 1のときは例外",
"-",
"-",
"+# 素数",
"+n = 10**5 + 1000",
"+primes = [True] * (n + 1)",
"+p = 2",
"+while p * p <= n:",
"+ if primes[p]:",
"+ for i in range(p * p, n + 1, p): # p*pスタートでいいのか",
"+ primes[i] = False",
"+ p += 1",
"+primes[0], primes[1] = False, False",
"- if is_prime(x):",
"+ if primes[x]:",
"- break",
"+ exit()"
] | false | 0.045016 | 0.07889 | 0.570615 | [
"s553710850",
"s909890852"
] |
u421781073 | p03807 | python | s951506350 | s222848144 | 60 | 47 | 11,104 | 11,104 | Accepted | Accepted | 21.67 | # -*- coding: utf-8 -*-
import sys
n = sys.stdin.readline().rstrip()
nums = (int(i) for i in sys.stdin.readline().rstrip().split())
odds = 0
for a in nums:
if a % 2 != 0:
odds += a
if odds % 2 == 0:
print('YES')
else:
print('NO') | # -*- coding: utf-8 -*-
import sys
n = sys.stdin.readline().rstrip()
nums = (int(i) for i in sys.stdin.readline().rstrip().split())
if sum(nums) % 2 == 0:
print('YES')
else:
print('NO') | 15 | 10 | 256 | 200 | # -*- coding: utf-8 -*-
import sys
n = sys.stdin.readline().rstrip()
nums = (int(i) for i in sys.stdin.readline().rstrip().split())
odds = 0
for a in nums:
if a % 2 != 0:
odds += a
if odds % 2 == 0:
print("YES")
else:
print("NO")
| # -*- coding: utf-8 -*-
import sys
n = sys.stdin.readline().rstrip()
nums = (int(i) for i in sys.stdin.readline().rstrip().split())
if sum(nums) % 2 == 0:
print("YES")
else:
print("NO")
| false | 33.333333 | [
"-odds = 0",
"-for a in nums:",
"- if a % 2 != 0:",
"- odds += a",
"-if odds % 2 == 0:",
"+if sum(nums) % 2 == 0:"
] | false | 0.084907 | 0.109089 | 0.778329 | [
"s951506350",
"s222848144"
] |
u703214333 | p03317 | python | s884353473 | s858191981 | 47 | 40 | 13,880 | 14,008 | Accepted | Accepted | 14.89 | n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
if n==k:
print((1))
exit()
i=n-k
ans=1
while i>0:
i=i-k+1
ans+=1
print(ans) | n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
print((-(-(n-k)//(k-1))+1))
| 11 | 3 | 161 | 90 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
if n == k:
print((1))
exit()
i = n - k
ans = 1
while i > 0:
i = i - k + 1
ans += 1
print(ans)
| n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
print((-(-(n - k) // (k - 1)) + 1))
| false | 72.727273 | [
"-if n == k:",
"- print((1))",
"- exit()",
"-i = n - k",
"-ans = 1",
"-while i > 0:",
"- i = i - k + 1",
"- ans += 1",
"-print(ans)",
"+print((-(-(n - k) // (k - 1)) + 1))"
] | false | 0.03747 | 0.036695 | 1.021115 | [
"s884353473",
"s858191981"
] |
u802963389 | p03564 | python | s357103258 | s294030363 | 164 | 17 | 38,384 | 2,940 | Accepted | Accepted | 89.63 | n = int(eval(input()))
k = int(eval(input()))
val = 1
for i in range(n):
val = min(val + k, val * 2)
print(val) | n = int(eval(input()))
k = int(eval(input()))
p = 1
for _ in range(n):
if p * 2 < p + k:
p *= 2
else:
p += k
print(p) | 7 | 9 | 108 | 125 | n = int(eval(input()))
k = int(eval(input()))
val = 1
for i in range(n):
val = min(val + k, val * 2)
print(val)
| n = int(eval(input()))
k = int(eval(input()))
p = 1
for _ in range(n):
if p * 2 < p + k:
p *= 2
else:
p += k
print(p)
| false | 22.222222 | [
"-val = 1",
"-for i in range(n):",
"- val = min(val + k, val * 2)",
"-print(val)",
"+p = 1",
"+for _ in range(n):",
"+ if p * 2 < p + k:",
"+ p *= 2",
"+ else:",
"+ p += k",
"+print(p)"
] | false | 0.04707 | 0.046418 | 1.014045 | [
"s357103258",
"s294030363"
] |
u796942881 | p03557 | python | s163392655 | s779646171 | 820 | 321 | 26,528 | 29,708 | Accepted | Accepted | 60.85 | N = int(eval(input()))
An = sorted([int(i) for i in input().split()])
Bn = list(map(int, input().split()))
Cn = sorted([int(i) for i in input().split()])
def lowerBound(a, v):
# 以上
return lb(a, 0, len(a), v)
def upperBound(a, v):
# より大きい
# 値をプラス1
return lb(a, 0, len(a), v + 1)
def lb(a, l, r, v):
low = l - 1
high = r
while high - low > 1:
mid = low + high >> 1
if a[mid] >= v:
high = mid
else:
low = mid
return high
def main():
print((sum([lowerBound(An, Bi)
* (N - upperBound(Cn, Bi)) for Bi in Bn])))
return
main()
| def main():
from bisect import bisect_left
from bisect import bisect_right
N = int(eval(input()))
An = list(map(int, input().split()))
Bn = list(map(int, input().split()))
Cn = list(map(int, input().split()))
A = sorted(An)
C = sorted(Cn)
print((sum(bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in Bn)))
return
main()
| 40 | 18 | 665 | 364 | N = int(eval(input()))
An = sorted([int(i) for i in input().split()])
Bn = list(map(int, input().split()))
Cn = sorted([int(i) for i in input().split()])
def lowerBound(a, v):
# 以上
return lb(a, 0, len(a), v)
def upperBound(a, v):
# より大きい
# 値をプラス1
return lb(a, 0, len(a), v + 1)
def lb(a, l, r, v):
low = l - 1
high = r
while high - low > 1:
mid = low + high >> 1
if a[mid] >= v:
high = mid
else:
low = mid
return high
def main():
print((sum([lowerBound(An, Bi) * (N - upperBound(Cn, Bi)) for Bi in Bn])))
return
main()
| def main():
from bisect import bisect_left
from bisect import bisect_right
N = int(eval(input()))
An = list(map(int, input().split()))
Bn = list(map(int, input().split()))
Cn = list(map(int, input().split()))
A = sorted(An)
C = sorted(Cn)
print((sum(bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in Bn)))
return
main()
| false | 55 | [
"-N = int(eval(input()))",
"-An = sorted([int(i) for i in input().split()])",
"-Bn = list(map(int, input().split()))",
"-Cn = sorted([int(i) for i in input().split()])",
"+def main():",
"+ from bisect import bisect_left",
"+ from bisect import bisect_right",
"-",
"-def lowerBound(a, v):",
"- # 以上",
"- return lb(a, 0, len(a), v)",
"-",
"-",
"-def upperBound(a, v):",
"- # より大きい",
"- # 値をプラス1",
"- return lb(a, 0, len(a), v + 1)",
"-",
"-",
"-def lb(a, l, r, v):",
"- low = l - 1",
"- high = r",
"- while high - low > 1:",
"- mid = low + high >> 1",
"- if a[mid] >= v:",
"- high = mid",
"- else:",
"- low = mid",
"- return high",
"-",
"-",
"-def main():",
"- print((sum([lowerBound(An, Bi) * (N - upperBound(Cn, Bi)) for Bi in Bn])))",
"+ N = int(eval(input()))",
"+ An = list(map(int, input().split()))",
"+ Bn = list(map(int, input().split()))",
"+ Cn = list(map(int, input().split()))",
"+ A = sorted(An)",
"+ C = sorted(Cn)",
"+ print((sum(bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in Bn)))"
] | false | 0.126151 | 0.045918 | 2.747318 | [
"s163392655",
"s779646171"
] |
u490642448 | p03782 | python | s783655211 | s503359293 | 174 | 69 | 71,912 | 73,700 | Accepted | Accepted | 60.34 | n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort(reverse=True)
dp = [False] * (k)
dp[0] = True
min_n = 10**10
for i in a:
for j in range(k-1,-1,-1):
if(dp[j]):
if(j+i >= k):
min_n = i
else:
dp[j+i] = True
ans = 0
for i in a:
ans += (i < min_n)
print(ans) | n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort(reverse=True)
mask = (1<<k)-1
dp = 1
min_n = 10**10
for i in a:
if(i >= k):
min_n = i
continue
dp |= (dp<<i)
if(dp > mask):
min_n = i
dp &= mask
ans = 0
for i in a:
ans += (i < min_n)
print(ans) | 20 | 21 | 372 | 347 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
dp = [False] * (k)
dp[0] = True
min_n = 10**10
for i in a:
for j in range(k - 1, -1, -1):
if dp[j]:
if j + i >= k:
min_n = i
else:
dp[j + i] = True
ans = 0
for i in a:
ans += i < min_n
print(ans)
| n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
mask = (1 << k) - 1
dp = 1
min_n = 10**10
for i in a:
if i >= k:
min_n = i
continue
dp |= dp << i
if dp > mask:
min_n = i
dp &= mask
ans = 0
for i in a:
ans += i < min_n
print(ans)
| false | 4.761905 | [
"-dp = [False] * (k)",
"-dp[0] = True",
"+mask = (1 << k) - 1",
"+dp = 1",
"- for j in range(k - 1, -1, -1):",
"- if dp[j]:",
"- if j + i >= k:",
"- min_n = i",
"- else:",
"- dp[j + i] = True",
"+ if i >= k:",
"+ min_n = i",
"+ continue",
"+ dp |= dp << i",
"+ if dp > mask:",
"+ min_n = i",
"+ dp &= mask"
] | false | 0.040862 | 0.054567 | 0.748845 | [
"s783655211",
"s503359293"
] |
u137226361 | p02935 | python | s613101636 | s437357557 | 27 | 24 | 9,152 | 9,132 | Accepted | Accepted | 11.11 | n = int(eval(input()))
v =list(map(int, input().split()))
v.sort()
a = v[0]
for i in range(1, n):
a = (a+v[i])/2
print(a) | n = int(eval(input()))
v = list(map(int, input().split()))
v.sort()
ans = v[0]
for i in range(1, n):
ans = (ans + v[i]) / 2
print(ans) | 12 | 7 | 135 | 138 | n = int(eval(input()))
v = list(map(int, input().split()))
v.sort()
a = v[0]
for i in range(1, n):
a = (a + v[i]) / 2
print(a)
| n = int(eval(input()))
v = list(map(int, input().split()))
v.sort()
ans = v[0]
for i in range(1, n):
ans = (ans + v[i]) / 2
print(ans)
| false | 41.666667 | [
"-a = v[0]",
"+ans = v[0]",
"- a = (a + v[i]) / 2",
"-print(a)",
"+ ans = (ans + v[i]) / 2",
"+print(ans)"
] | false | 0.036302 | 0.035838 | 1.012955 | [
"s613101636",
"s437357557"
] |
u143492911 | p03854 | python | s528040390 | s068609716 | 22 | 19 | 3,188 | 3,188 | Accepted | Accepted | 13.64 | s=input().replace("eraser",",").replace("erase",",").replace("dreamer",",").replace("dream",",").replace(",","")
print(("YES" if s=="" else "NO")) | s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
print(("YES" if s=="" else "NO")) | 2 | 2 | 145 | 125 | s = (
input()
.replace("eraser", ",")
.replace("erase", ",")
.replace("dreamer", ",")
.replace("dream", ",")
.replace(",", "")
)
print(("YES" if s == "" else "NO"))
| s = (
input()
.replace("eraser", "")
.replace("erase", "")
.replace("dreamer", "")
.replace("dream", "")
)
print(("YES" if s == "" else "NO"))
| false | 0 | [
"- .replace(\"eraser\", \",\")",
"- .replace(\"erase\", \",\")",
"- .replace(\"dreamer\", \",\")",
"- .replace(\"dream\", \",\")",
"- .replace(\",\", \"\")",
"+ .replace(\"eraser\", \"\")",
"+ .replace(\"erase\", \"\")",
"+ .replace(\"dreamer\", \"\")",
"+ .replace(\"dream\", \"\")"
] | false | 0.047298 | 0.038652 | 1.223673 | [
"s528040390",
"s068609716"
] |
u919633157 | p02911 | python | s964715581 | s887826647 | 166 | 130 | 13,548 | 6,580 | Accepted | Accepted | 21.69 | import sys
from collections import Counter
input=sys.stdin.readline
n,k,q=list(map(int,input().split()))
a=Counter([int(eval(input())) for _ in range(q)])
ans=[False]*n
for key,v in list(a.items()):
if k-(q-v)>0:
ans[key-1]=True
ss=set(a.keys())
for i in range(n):
if i+1 in ss:continue
if k-q>0:
ans[i]=True
for e in ans:
if e:
print('Yes')
else:
print('No') | # 2019/09/16
# 解説のやつ
import sys
input=sys.stdin.readline
n,k,q=list(map(int,input().split()))
res=[k-q]*n
for i in range(q):
res[int(eval(input()))-1]+=1
for e in res:
print(('Yes' if e>0 else 'No')) | 26 | 13 | 429 | 208 | import sys
from collections import Counter
input = sys.stdin.readline
n, k, q = list(map(int, input().split()))
a = Counter([int(eval(input())) for _ in range(q)])
ans = [False] * n
for key, v in list(a.items()):
if k - (q - v) > 0:
ans[key - 1] = True
ss = set(a.keys())
for i in range(n):
if i + 1 in ss:
continue
if k - q > 0:
ans[i] = True
for e in ans:
if e:
print("Yes")
else:
print("No")
| # 2019/09/16
# 解説のやつ
import sys
input = sys.stdin.readline
n, k, q = list(map(int, input().split()))
res = [k - q] * n
for i in range(q):
res[int(eval(input())) - 1] += 1
for e in res:
print(("Yes" if e > 0 else "No"))
| false | 50 | [
"+# 2019/09/16",
"+# 解説のやつ",
"-from collections import Counter",
"-a = Counter([int(eval(input())) for _ in range(q)])",
"-ans = [False] * n",
"-for key, v in list(a.items()):",
"- if k - (q - v) > 0:",
"- ans[key - 1] = True",
"-ss = set(a.keys())",
"-for i in range(n):",
"- if i + 1 in ss:",
"- continue",
"- if k - q > 0:",
"- ans[i] = True",
"-for e in ans:",
"- if e:",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"+res = [k - q] * n",
"+for i in range(q):",
"+ res[int(eval(input())) - 1] += 1",
"+for e in res:",
"+ print((\"Yes\" if e > 0 else \"No\"))"
] | false | 0.12779 | 0.10232 | 1.24892 | [
"s964715581",
"s887826647"
] |
u841568901 | p03835 | python | s870268306 | s528971159 | 1,418 | 843 | 9,164 | 9,064 | Accepted | Accepted | 40.55 | K, S = list(map(int, input().split()))
print((sum(0<=S-x-y<=min(K,S) for x in range(K+1) for y in range(K+1)))) | K, S = list(map(int, input().split()))
s = 0
for x in range(min(S,K)+1):
for y in range(min(S-x,K)+1):
if S-x-y<=K:
s += 1
print(s) | 2 | 7 | 104 | 143 | K, S = list(map(int, input().split()))
print((sum(0 <= S - x - y <= min(K, S) for x in range(K + 1) for y in range(K + 1))))
| K, S = list(map(int, input().split()))
s = 0
for x in range(min(S, K) + 1):
for y in range(min(S - x, K) + 1):
if S - x - y <= K:
s += 1
print(s)
| false | 71.428571 | [
"-print((sum(0 <= S - x - y <= min(K, S) for x in range(K + 1) for y in range(K + 1))))",
"+s = 0",
"+for x in range(min(S, K) + 1):",
"+ for y in range(min(S - x, K) + 1):",
"+ if S - x - y <= K:",
"+ s += 1",
"+print(s)"
] | false | 0.038254 | 0.007275 | 5.258194 | [
"s870268306",
"s528971159"
] |
u847467233 | p00208 | python | s517315788 | s429558692 | 380 | 310 | 5,628 | 5,624 | Accepted | Accepted | 18.42 | # AOJ 0208 Room Numbers of a Hospital
# Python3 2018.6.23 bal4u
# 8進数に変換して、01234567を01235789に置き換える
dic = {'0':'0','1':'1','2':'2','3':'3','4':'5','5':'7','6':'8','7':'9'}
while 1:
n = int(input())
if n == 0: break
s = list(format(n, 'o'))
for i in range(len(s)): s[i] = dic[s[i]]
print(*s, sep='')
| # AOJ 0208 Room Numbers of a Hospital
# Python3 2018.6.23 bal4u
# 8進数に変換して、01234567を01235789に置き換える
dic = {'0':'0','1':'1','2':'2','3':'3','4':'5','5':'7','6':'8','7':'9'}
while 1:
n = int(eval(input()))
if n == 0: break
s = format(n, 'o')
ans = ''
for i in range(len(s)): ans += dic[s[i]]
print(ans)
| 12 | 13 | 317 | 315 | # AOJ 0208 Room Numbers of a Hospital
# Python3 2018.6.23 bal4u
# 8進数に変換して、01234567を01235789に置き換える
dic = {"0": "0", "1": "1", "2": "2", "3": "3", "4": "5", "5": "7", "6": "8", "7": "9"}
while 1:
n = int(input())
if n == 0:
break
s = list(format(n, "o"))
for i in range(len(s)):
s[i] = dic[s[i]]
print(*s, sep="")
| # AOJ 0208 Room Numbers of a Hospital
# Python3 2018.6.23 bal4u
# 8進数に変換して、01234567を01235789に置き換える
dic = {"0": "0", "1": "1", "2": "2", "3": "3", "4": "5", "5": "7", "6": "8", "7": "9"}
while 1:
n = int(eval(input()))
if n == 0:
break
s = format(n, "o")
ans = ""
for i in range(len(s)):
ans += dic[s[i]]
print(ans)
| false | 7.692308 | [
"- n = int(input())",
"+ n = int(eval(input()))",
"- s = list(format(n, \"o\"))",
"+ s = format(n, \"o\")",
"+ ans = \"\"",
"- s[i] = dic[s[i]]",
"- print(*s, sep=\"\")",
"+ ans += dic[s[i]]",
"+ print(ans)"
] | false | 0.070533 | 0.061975 | 1.138076 | [
"s517315788",
"s429558692"
] |
u162911959 | p02952 | python | s614562878 | s898513321 | 66 | 58 | 3,060 | 3,060 | Accepted | Accepted | 12.12 | #!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)
import math
n = int(readline())
count = 0
for i in range(1, n + 1):
if int(math.log10(i)) % 2 == 0:
count +=1
print(count) | #!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)
n = int(readline())
count = 0
for i in range(1, n + 1):
if len(str(i)) % 2 == 1:
count += 1
print(count) | 14 | 13 | 299 | 278 | #!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**7)
import math
n = int(readline())
count = 0
for i in range(1, n + 1):
if int(math.log10(i)) % 2 == 0:
count += 1
print(count)
| #!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**7)
n = int(readline())
count = 0
for i in range(1, n + 1):
if len(str(i)) % 2 == 1:
count += 1
print(count)
| false | 7.142857 | [
"-import math",
"-",
"- if int(math.log10(i)) % 2 == 0:",
"+ if len(str(i)) % 2 == 1:"
] | false | 0.055836 | 0.04502 | 1.240253 | [
"s614562878",
"s898513321"
] |
u644516473 | p02665 | python | s600564033 | s988280384 | 1,049 | 906 | 668,704 | 668,704 | Accepted | Accepted | 13.63 | N = int(eval(input()))
A = list(map(int, input().split()))
d = [1] * (N+1)
d[0] -= A[0]
for i in range(N):
d[i+1] = d[i] * 2 - A[i+1]
if d[-1] < 0:
print((-1))
exit()
else:
d[-1] = A[-1]
for i in range(N, 0, -1):
x = d[i]
x += A[i-1]
if d[i-1] * 2 < x:
y = x - A[i-1]
if (y+1) // 2 + A[i-1] <= d[i-1] * 2:
x = d[i-1] * 2
d[i-1] = min(x, d[i-1]+A[i-1])
print((sum(d)))
| N = int(eval(input()))
A = list(map(int, input().split()))
d = [1] * (N+1)
d[0] -= A[0]
for i in range(N):
d[i+1] = d[i] * 2 - A[i+1]
if d[-1] < 0:
print((-1))
exit()
else:
d[-1] = A[-1]
for i in range(N, 0, -1):
x = d[i]
x += A[i-1]
d[i-1] = min(x, d[i-1]+A[i-1])
print((sum(d)))
| 22 | 18 | 441 | 318 | N = int(eval(input()))
A = list(map(int, input().split()))
d = [1] * (N + 1)
d[0] -= A[0]
for i in range(N):
d[i + 1] = d[i] * 2 - A[i + 1]
if d[-1] < 0:
print((-1))
exit()
else:
d[-1] = A[-1]
for i in range(N, 0, -1):
x = d[i]
x += A[i - 1]
if d[i - 1] * 2 < x:
y = x - A[i - 1]
if (y + 1) // 2 + A[i - 1] <= d[i - 1] * 2:
x = d[i - 1] * 2
d[i - 1] = min(x, d[i - 1] + A[i - 1])
print((sum(d)))
| N = int(eval(input()))
A = list(map(int, input().split()))
d = [1] * (N + 1)
d[0] -= A[0]
for i in range(N):
d[i + 1] = d[i] * 2 - A[i + 1]
if d[-1] < 0:
print((-1))
exit()
else:
d[-1] = A[-1]
for i in range(N, 0, -1):
x = d[i]
x += A[i - 1]
d[i - 1] = min(x, d[i - 1] + A[i - 1])
print((sum(d)))
| false | 18.181818 | [
"- if d[i - 1] * 2 < x:",
"- y = x - A[i - 1]",
"- if (y + 1) // 2 + A[i - 1] <= d[i - 1] * 2:",
"- x = d[i - 1] * 2"
] | false | 0.113022 | 0.046173 | 2.447822 | [
"s600564033",
"s988280384"
] |
u002459665 | p02842 | python | s106249039 | s734495603 | 32 | 29 | 3,060 | 2,940 | Accepted | Accepted | 9.38 | import math
def main():
N = int(eval(input()))
ans = False
for i in range(N+1):
x = math.floor(i * 1.08)
if x == N:
print(i)
ans = True
break
if not ans:
print(':(')
if __name__ == "__main__":
main() | import math
def main():
N = int(eval(input()))
ans = ':('
for i in range(N+1):
x = int(i * 1.08)
if x == N:
ans = i
print(ans)
if __name__ == "__main__":
main() | 16 | 13 | 290 | 216 | import math
def main():
N = int(eval(input()))
ans = False
for i in range(N + 1):
x = math.floor(i * 1.08)
if x == N:
print(i)
ans = True
break
if not ans:
print(":(")
if __name__ == "__main__":
main()
| import math
def main():
N = int(eval(input()))
ans = ":("
for i in range(N + 1):
x = int(i * 1.08)
if x == N:
ans = i
print(ans)
if __name__ == "__main__":
main()
| false | 18.75 | [
"- ans = False",
"+ ans = \":(\"",
"- x = math.floor(i * 1.08)",
"+ x = int(i * 1.08)",
"- print(i)",
"- ans = True",
"- break",
"- if not ans:",
"- print(\":(\")",
"+ ans = i",
"+ print(ans)"
] | false | 0.038366 | 0.035812 | 1.0713 | [
"s106249039",
"s734495603"
] |
u077291787 | p03425 | python | s727798192 | s552323487 | 141 | 50 | 3,888 | 3,884 | Accepted | Accepted | 64.54 | # ABC089C - March
from itertools import combinations
def main():
n = int(eval(input()))
lst = [input().rstrip()[0] for _ in range(n)]
cand = [lst.count(s) for s in "MARCH"]
ans = sum(x * y * z for x, y, z in combinations(cand, 3))
print(ans)
if __name__ == "__main__":
main() | # ABC089C - March
import sys
input = sys.stdin.readline
from itertools import combinations
def main():
n = int(eval(input()))
lst = [input().rstrip()[0] for _ in range(n)]
cand = [lst.count(s) for s in "MARCH"]
ans = sum(x * y * z for x, y, z in combinations(cand, 3))
print(ans)
if __name__ == "__main__":
main() | 14 | 17 | 310 | 352 | # ABC089C - March
from itertools import combinations
def main():
n = int(eval(input()))
lst = [input().rstrip()[0] for _ in range(n)]
cand = [lst.count(s) for s in "MARCH"]
ans = sum(x * y * z for x, y, z in combinations(cand, 3))
print(ans)
if __name__ == "__main__":
main()
| # ABC089C - March
import sys
input = sys.stdin.readline
from itertools import combinations
def main():
n = int(eval(input()))
lst = [input().rstrip()[0] for _ in range(n)]
cand = [lst.count(s) for s in "MARCH"]
ans = sum(x * y * z for x, y, z in combinations(cand, 3))
print(ans)
if __name__ == "__main__":
main()
| false | 17.647059 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.034953 | 0.037325 | 0.936445 | [
"s727798192",
"s552323487"
] |
u603958124 | p03363 | python | s576251666 | s267752803 | 219 | 186 | 43,304 | 46,044 | Accepted | Accepted | 15.07 | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
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())
n = INT()
a = LIST()
s = accumulate(a)
d = defaultdict(int)
for x in s:
d[x] += 1
ans = d[0]
for x in d:
ans += d[x]*(d[x]-1)//2
print(ans) | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
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())
n = INT()
a = LIST()
b = Counter(list(accumulate(a))+[0])
ans = 0
for x in b:
ans += b[x] * ( b[x] - 1 ) // 2
print(ans) | 30 | 26 | 871 | 843 | from math import (
ceil,
floor,
factorial,
gcd,
sqrt,
log2,
cos,
sin,
tan,
acos,
asin,
atan,
degrees,
radians,
pi,
inf,
)
from itertools import (
accumulate,
groupby,
permutations,
combinations,
product,
combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10**7)
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())
n = INT()
a = LIST()
s = accumulate(a)
d = defaultdict(int)
for x in s:
d[x] += 1
ans = d[0]
for x in d:
ans += d[x] * (d[x] - 1) // 2
print(ans)
| from math import (
ceil,
floor,
factorial,
gcd,
sqrt,
log2,
cos,
sin,
tan,
acos,
asin,
atan,
degrees,
radians,
pi,
inf,
)
from itertools import (
accumulate,
groupby,
permutations,
combinations,
product,
combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10**7)
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())
n = INT()
a = LIST()
b = Counter(list(accumulate(a)) + [0])
ans = 0
for x in b:
ans += b[x] * (b[x] - 1) // 2
print(ans)
| false | 13.333333 | [
"-s = accumulate(a)",
"-d = defaultdict(int)",
"-for x in s:",
"- d[x] += 1",
"-ans = d[0]",
"-for x in d:",
"- ans += d[x] * (d[x] - 1) // 2",
"+b = Counter(list(accumulate(a)) + [0])",
"+ans = 0",
"+for x in b:",
"+ ans += b[x] * (b[x] - 1) // 2"
] | false | 0.037256 | 0.098267 | 0.379129 | [
"s576251666",
"s267752803"
] |
u845573105 | p02623 | python | s110278729 | s107990801 | 1,058 | 282 | 41,972 | 47,464 | Accepted | Accepted | 73.35 | N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [0] + A
B = [0] + B
for i in range(1, N+1):
A[i] += A[i-1]
for i in range(1, M+1):
B[i] += B[i-1]
start = 0
end = N+1
while end-start > 1:
sep = (start+end)//2
if A[sep] <= K:
start = sep
else:
end = sep
if start==N:
alim = start
elif A[end]>K:
alim = start
else:
alim = end
blim = 0
start = blim
end = M+1
ans = alim
ansalim = -1
ansblim = -1
for _ in range(alim+1):
Bmax = K-A[alim]
#print("Bmax" , Bmax)
while end-start > 1:
sep = (start+end)//2
#print(blim,start, end, sep)
if B[sep] <= Bmax:
start = sep
else:
end = sep
if start==M:
blim = start
elif B[end]>Bmax:
blim = start
else:
blim = end
ans = max(blim + alim, ans)
start = sep-1
end = M+1
alim -= 1
print(ans) | N,M,K=list(map(int,input().split()))
A=list(map(int, input().split()))
B=list(map(int, input().split()))
#入力終わり
#累積和とる
A_wa = [0]
for i in range(N) :
A_wa.append(A_wa[i]+A[i])
B_wa = [0]
for i in range(M) :
B_wa.append(B_wa[i]+B[i])
a = N
ans = 0
for b in range(M+1):
A_lim = K - B_wa[b]
if A_lim < 0:
break
while A_wa[a] > A_lim and a > 0:
a -= 1
ans = max(a + b, ans)
print(ans)
| 52 | 28 | 922 | 435 | N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [0] + A
B = [0] + B
for i in range(1, N + 1):
A[i] += A[i - 1]
for i in range(1, M + 1):
B[i] += B[i - 1]
start = 0
end = N + 1
while end - start > 1:
sep = (start + end) // 2
if A[sep] <= K:
start = sep
else:
end = sep
if start == N:
alim = start
elif A[end] > K:
alim = start
else:
alim = end
blim = 0
start = blim
end = M + 1
ans = alim
ansalim = -1
ansblim = -1
for _ in range(alim + 1):
Bmax = K - A[alim]
# print("Bmax" , Bmax)
while end - start > 1:
sep = (start + end) // 2
# print(blim,start, end, sep)
if B[sep] <= Bmax:
start = sep
else:
end = sep
if start == M:
blim = start
elif B[end] > Bmax:
blim = start
else:
blim = end
ans = max(blim + alim, ans)
start = sep - 1
end = M + 1
alim -= 1
print(ans)
| N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# 入力終わり
# 累積和とる
A_wa = [0]
for i in range(N):
A_wa.append(A_wa[i] + A[i])
B_wa = [0]
for i in range(M):
B_wa.append(B_wa[i] + B[i])
a = N
ans = 0
for b in range(M + 1):
A_lim = K - B_wa[b]
if A_lim < 0:
break
while A_wa[a] > A_lim and a > 0:
a -= 1
ans = max(a + b, ans)
print(ans)
| false | 46.153846 | [
"-A = [0] + A",
"-B = [0] + B",
"-for i in range(1, N + 1):",
"- A[i] += A[i - 1]",
"-for i in range(1, M + 1):",
"- B[i] += B[i - 1]",
"-start = 0",
"-end = N + 1",
"-while end - start > 1:",
"- sep = (start + end) // 2",
"- if A[sep] <= K:",
"- start = sep",
"- else:",
"- end = sep",
"-if start == N:",
"- alim = start",
"-elif A[end] > K:",
"- alim = start",
"-else:",
"- alim = end",
"-blim = 0",
"-start = blim",
"-end = M + 1",
"-ans = alim",
"-ansalim = -1",
"-ansblim = -1",
"-for _ in range(alim + 1):",
"- Bmax = K - A[alim]",
"- # print(\"Bmax\" , Bmax)",
"- while end - start > 1:",
"- sep = (start + end) // 2",
"- # print(blim,start, end, sep)",
"- if B[sep] <= Bmax:",
"- start = sep",
"- else:",
"- end = sep",
"- if start == M:",
"- blim = start",
"- elif B[end] > Bmax:",
"- blim = start",
"- else:",
"- blim = end",
"- ans = max(blim + alim, ans)",
"- start = sep - 1",
"- end = M + 1",
"- alim -= 1",
"+# 入力終わり",
"+# 累積和とる",
"+A_wa = [0]",
"+for i in range(N):",
"+ A_wa.append(A_wa[i] + A[i])",
"+B_wa = [0]",
"+for i in range(M):",
"+ B_wa.append(B_wa[i] + B[i])",
"+a = N",
"+ans = 0",
"+for b in range(M + 1):",
"+ A_lim = K - B_wa[b]",
"+ if A_lim < 0:",
"+ break",
"+ while A_wa[a] > A_lim and a > 0:",
"+ a -= 1",
"+ ans = max(a + b, ans)"
] | false | 0.061123 | 0.061672 | 0.991097 | [
"s110278729",
"s107990801"
] |
u634079249 | p02612 | python | s861282906 | s039751257 | 40 | 36 | 10,220 | 10,152 | Accepted | Accepted | 10 | import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
n = 1
while True:
if n * 1000 >= N:
print(((n * 1000) - N))
exit()
else:
n += 1
if __name__ == '__main__':
main()
| import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
print(((1000 - N % 1000) % 1000))
if __name__ == '__main__':
main()
| 38 | 32 | 1,121 | 1,013 | import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10**9 + 7
MAX = float("inf")
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
n = 1
while True:
if n * 1000 >= N:
print(((n * 1000) - N))
exit()
else:
n += 1
if __name__ == "__main__":
main()
| import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10**9 + 7
MAX = float("inf")
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
print(((1000 - N % 1000) % 1000))
if __name__ == "__main__":
main()
| false | 15.789474 | [
"- n = 1",
"- while True:",
"- if n * 1000 >= N:",
"- print(((n * 1000) - N))",
"- exit()",
"- else:",
"- n += 1",
"+ print(((1000 - N % 1000) % 1000))"
] | false | 0.037348 | 0.037192 | 1.004183 | [
"s861282906",
"s039751257"
] |
u991542950 | p02577 | python | s186429925 | s342397816 | 96 | 84 | 86,620 | 94,956 | Accepted | Accepted | 12.5 | N = eval(input())
N = list(N)
N = list(map(int, N))
if sum(N)%9 == 0:
print("Yes")
else:
print("No") | N = list(map(int, list(eval(input()))))
if sum(N) % 9 == 0:
print("Yes")
else:
print("No")
| 7 | 5 | 104 | 93 | N = eval(input())
N = list(N)
N = list(map(int, N))
if sum(N) % 9 == 0:
print("Yes")
else:
print("No")
| N = list(map(int, list(eval(input()))))
if sum(N) % 9 == 0:
print("Yes")
else:
print("No")
| false | 28.571429 | [
"-N = eval(input())",
"-N = list(N)",
"-N = list(map(int, N))",
"+N = list(map(int, list(eval(input()))))"
] | false | 0.044218 | 0.044958 | 0.983526 | [
"s186429925",
"s342397816"
] |
u515740713 | p02660 | python | s557003612 | s222239898 | 194 | 112 | 27,312 | 9,164 | Accepted | Accepted | 42.27 | import sys
import numpy as np
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 1~1000の累計和
a = [i for i in range(1,1000)]
s = np.cumsum(a)
s_list=list(s)
N = int(read())
if N ==1:
print((0))
sys.exit()
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
arr = factorization(N)
ans = 0
for p in arr:
index = bisect.bisect_right(s_list, p[1])
ans += index
print(ans) | import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def factorization(n):
arr = []
for i in range(2,int(math.sqrt(n))+1):
cnt = 0
if n % i == 0:
while n % i ==0:
n //= i
cnt +=1
#arr.append([i,cnt])
arr.append(cnt)
if n != 1:
#arr.append([n,1])
arr.append(1)
return arr
N = int(read())
arr = factorization(N)
ans = 0
for a in arr:
for i in range(1,50):
if a-i>=0:
a -=i
ans +=1
else:
break
print(ans)
| 39 | 32 | 780 | 661 | import sys
import numpy as np
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 1~1000の累計和
a = [i for i in range(1, 1000)]
s = np.cumsum(a)
s_list = list(s)
N = int(read())
if N == 1:
print((0))
sys.exit()
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
arr = factorization(N)
ans = 0
for p in arr:
index = bisect.bisect_right(s_list, p[1])
ans += index
print(ans)
| import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def factorization(n):
arr = []
for i in range(2, int(math.sqrt(n)) + 1):
cnt = 0
if n % i == 0:
while n % i == 0:
n //= i
cnt += 1
# arr.append([i,cnt])
arr.append(cnt)
if n != 1:
# arr.append([n,1])
arr.append(1)
return arr
N = int(read())
arr = factorization(N)
ans = 0
for a in arr:
for i in range(1, 50):
if a - i >= 0:
a -= i
ans += 1
else:
break
print(ans)
| false | 17.948718 | [
"+import math",
"-import numpy as np",
"-import bisect",
"-# 1~1000の累計和",
"-a = [i for i in range(1, 1000)]",
"-s = np.cumsum(a)",
"-s_list = list(s)",
"-N = int(read())",
"-if N == 1:",
"- print((0))",
"- sys.exit()",
"- temp = n",
"- for i in range(2, int(-(-(n**0.5) // 1)) + 1):",
"- if temp % i == 0:",
"- cnt = 0",
"- while temp % i == 0:",
"+ for i in range(2, int(math.sqrt(n)) + 1):",
"+ cnt = 0",
"+ if n % i == 0:",
"+ while n % i == 0:",
"+ n //= i",
"- temp //= i",
"- arr.append([i, cnt])",
"- if temp != 1:",
"- arr.append([temp, 1])",
"- if arr == []:",
"- arr.append([n, 1])",
"+ # arr.append([i,cnt])",
"+ arr.append(cnt)",
"+ if n != 1:",
"+ # arr.append([n,1])",
"+ arr.append(1)",
"+N = int(read())",
"-for p in arr:",
"- index = bisect.bisect_right(s_list, p[1])",
"- ans += index",
"+for a in arr:",
"+ for i in range(1, 50):",
"+ if a - i >= 0:",
"+ a -= i",
"+ ans += 1",
"+ else:",
"+ break"
] | false | 0.483923 | 0.132859 | 3.642371 | [
"s557003612",
"s222239898"
] |
u102242691 | p03720 | python | s982503846 | s216698407 | 19 | 17 | 3,060 | 3,060 | Accepted | Accepted | 10.53 |
n,m = list(map(int,input().split()))
city = []
for i in range(n):
city.append([i,0])
for i in range(m):
a,b = list(map(int,input().split()))
city[a-1][1] += 1
city[b-1][1] += 1
for j in range(n):
print((city[j][1]))
|
n,m = list(map(int,input().split()))
s = [[0]*n for _ in range(n)]
for _ in range(m):
a,b = list(map(int,input().split()))
# print(a,b)
s[a-1][b-1] += 1
s[b-1][a-1] += 1
# print(s)
for i in range(n):
print((sum(s[i])))
"""
以下の指定では、一度の値変更で、全ての要素の該当部分の数値が一斉に変わる。
http://delta114514.hatenablog.jp/entry/2018/01/02/233002
n,m = map(int,input().split())
s = [[0]*n]*n
"""
| 13 | 20 | 237 | 398 | n, m = list(map(int, input().split()))
city = []
for i in range(n):
city.append([i, 0])
for i in range(m):
a, b = list(map(int, input().split()))
city[a - 1][1] += 1
city[b - 1][1] += 1
for j in range(n):
print((city[j][1]))
| n, m = list(map(int, input().split()))
s = [[0] * n for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
# print(a,b)
s[a - 1][b - 1] += 1
s[b - 1][a - 1] += 1
# print(s)
for i in range(n):
print((sum(s[i])))
"""
以下の指定では、一度の値変更で、全ての要素の該当部分の数値が一斉に変わる。
http://delta114514.hatenablog.jp/entry/2018/01/02/233002
n,m = map(int,input().split())
s = [[0]*n]*n
"""
| false | 35 | [
"-city = []",
"+s = [[0] * n for _ in range(n)]",
"+for _ in range(m):",
"+ a, b = list(map(int, input().split()))",
"+ # print(a,b)",
"+ s[a - 1][b - 1] += 1",
"+ s[b - 1][a - 1] += 1",
"+# print(s)",
"- city.append([i, 0])",
"-for i in range(m):",
"- a, b = list(map(int, input().split()))",
"- city[a - 1][1] += 1",
"- city[b - 1][1] += 1",
"-for j in range(n):",
"- print((city[j][1]))",
"+ print((sum(s[i])))",
"+\"\"\"",
"+以下の指定では、一度の値変更で、全ての要素の該当部分の数値が一斉に変わる。",
"+http://delta114514.hatenablog.jp/entry/2018/01/02/233002",
"+n,m = map(int,input().split())",
"+s = [[0]*n]*n",
"+\"\"\""
] | false | 0.049331 | 0.068308 | 0.722191 | [
"s982503846",
"s216698407"
] |
u112364985 | p03545 | python | s535052922 | s243360291 | 28 | 25 | 9,112 | 9,068 | Accepted | Accepted | 10.71 | a,b,c,d=eval(input())
for i in range(2**3):
l=["-","-","-"]
for j in range(3):
if (i>>j&1):
l[j]="+"
if eval(a+l[0]+b+l[1]+c+l[2]+d)==7:
print((a+l[0]+b+l[1]+c+l[2]+d+"=7"))
exit() | a,b,c,d=eval(input())
for i in range(2**3):
op=["-","-","-"]
for j in range(3):
if (i>>j&1):
op[j]="+"
if eval(a+op[0]+b+op[1]+c+op[2]+d)==7:
print((a+op[0]+b+op[1]+c+op[2]+d+"=7"))
exit() | 9 | 9 | 228 | 236 | a, b, c, d = eval(input())
for i in range(2**3):
l = ["-", "-", "-"]
for j in range(3):
if i >> j & 1:
l[j] = "+"
if eval(a + l[0] + b + l[1] + c + l[2] + d) == 7:
print((a + l[0] + b + l[1] + c + l[2] + d + "=7"))
exit()
| a, b, c, d = eval(input())
for i in range(2**3):
op = ["-", "-", "-"]
for j in range(3):
if i >> j & 1:
op[j] = "+"
if eval(a + op[0] + b + op[1] + c + op[2] + d) == 7:
print((a + op[0] + b + op[1] + c + op[2] + d + "=7"))
exit()
| false | 0 | [
"- l = [\"-\", \"-\", \"-\"]",
"+ op = [\"-\", \"-\", \"-\"]",
"- l[j] = \"+\"",
"- if eval(a + l[0] + b + l[1] + c + l[2] + d) == 7:",
"- print((a + l[0] + b + l[1] + c + l[2] + d + \"=7\"))",
"+ op[j] = \"+\"",
"+ if eval(a + op[0] + b + op[1] + c + op[2] + d) == 7:",
"+ print((a + op[0] + b + op[1] + c + op[2] + d + \"=7\"))"
] | false | 0.035996 | 0.037788 | 0.95257 | [
"s535052922",
"s243360291"
] |
u285443936 | p02796 | python | s405982408 | s264816116 | 412 | 284 | 21,400 | 24,684 | Accepted | Accepted | 31.07 | N = int(eval(input()))
XL = [tuple(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0]+x[1])
right = -float('inf')
ans = 0
for x,l in XL:
s,t = x-l, x+l
if s >= right:
right = t
ans += 1
print(ans)
| N = int(eval(input()))
table = []
for i in range(N):
X,L = list(map(int,input().split()))
table.append((X-L,X+L))
table = sorted(table, key=lambda x:x[1])
cur = 0
l_cur, r_cur = table[0]
ans = N
for i in range(1,N):
l,r = table[i]
if r_cur > l:
ans -= 1
else:
l_cur, r_cur = l,r
print(ans) | 11 | 17 | 246 | 330 | N = int(eval(input()))
XL = [tuple(map(int, input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0] + x[1])
right = -float("inf")
ans = 0
for x, l in XL:
s, t = x - l, x + l
if s >= right:
right = t
ans += 1
print(ans)
| N = int(eval(input()))
table = []
for i in range(N):
X, L = list(map(int, input().split()))
table.append((X - L, X + L))
table = sorted(table, key=lambda x: x[1])
cur = 0
l_cur, r_cur = table[0]
ans = N
for i in range(1, N):
l, r = table[i]
if r_cur > l:
ans -= 1
else:
l_cur, r_cur = l, r
print(ans)
| false | 35.294118 | [
"-XL = [tuple(map(int, input().split())) for i in range(N)]",
"-XL.sort(key=lambda x: x[0] + x[1])",
"-right = -float(\"inf\")",
"-ans = 0",
"-for x, l in XL:",
"- s, t = x - l, x + l",
"- if s >= right:",
"- right = t",
"- ans += 1",
"+table = []",
"+for i in range(N):",
"+ X, L = list(map(int, input().split()))",
"+ table.append((X - L, X + L))",
"+table = sorted(table, key=lambda x: x[1])",
"+cur = 0",
"+l_cur, r_cur = table[0]",
"+ans = N",
"+for i in range(1, N):",
"+ l, r = table[i]",
"+ if r_cur > l:",
"+ ans -= 1",
"+ else:",
"+ l_cur, r_cur = l, r"
] | false | 0.036504 | 0.035665 | 1.023534 | [
"s405982408",
"s264816116"
] |
u692632484 | p03329 | python | s134478625 | s524793299 | 1,308 | 242 | 3,864 | 3,060 | Accepted | Accepted | 81.5 | INF=9999999
n=int(eval(input()))
dp=[INF for i in range(n+1)]
dp[-1]=0
for i in range(n,0,-1):
e6=1
while 6**e6<=i:
dp[i-6**e6]=min(dp[i]+1,dp[i-6**e6])
e6+=1
e9=1
while 9**e9<=i:
dp[i-9**e9]=min(dp[i]+1,dp[i-9**e9])
e9+=1
ans=INF
for i in range(n):
if dp[i]==0:
continue
ans=min(ans,i+dp[i])
if ans==INF:
ans=n
print(ans)
| #補助関数
def convert(num,radix):
res = 0
while num > 0:
res += num % radix
num //= radix
return res
#入力
INF = (1 << 31)
N = int(eval(input()))
ans = INF
#計算
for i in range(N + 1):
dec6 = i
dec9 = N - i
ans = min(ans , convert(dec6,6) + convert(dec9,9))
#出力
print(ans)
| 22 | 21 | 407 | 325 | INF = 9999999
n = int(eval(input()))
dp = [INF for i in range(n + 1)]
dp[-1] = 0
for i in range(n, 0, -1):
e6 = 1
while 6**e6 <= i:
dp[i - 6**e6] = min(dp[i] + 1, dp[i - 6**e6])
e6 += 1
e9 = 1
while 9**e9 <= i:
dp[i - 9**e9] = min(dp[i] + 1, dp[i - 9**e9])
e9 += 1
ans = INF
for i in range(n):
if dp[i] == 0:
continue
ans = min(ans, i + dp[i])
if ans == INF:
ans = n
print(ans)
| # 補助関数
def convert(num, radix):
res = 0
while num > 0:
res += num % radix
num //= radix
return res
# 入力
INF = 1 << 31
N = int(eval(input()))
ans = INF
# 計算
for i in range(N + 1):
dec6 = i
dec9 = N - i
ans = min(ans, convert(dec6, 6) + convert(dec9, 9))
# 出力
print(ans)
| false | 4.545455 | [
"-INF = 9999999",
"-n = int(eval(input()))",
"-dp = [INF for i in range(n + 1)]",
"-dp[-1] = 0",
"-for i in range(n, 0, -1):",
"- e6 = 1",
"- while 6**e6 <= i:",
"- dp[i - 6**e6] = min(dp[i] + 1, dp[i - 6**e6])",
"- e6 += 1",
"- e9 = 1",
"- while 9**e9 <= i:",
"- dp[i - 9**e9] = min(dp[i] + 1, dp[i - 9**e9])",
"- e9 += 1",
"+# 補助関数",
"+def convert(num, radix):",
"+ res = 0",
"+ while num > 0:",
"+ res += num % radix",
"+ num //= radix",
"+ return res",
"+",
"+",
"+# 入力",
"+INF = 1 << 31",
"+N = int(eval(input()))",
"-for i in range(n):",
"- if dp[i] == 0:",
"- continue",
"- ans = min(ans, i + dp[i])",
"-if ans == INF:",
"- ans = n",
"+# 計算",
"+for i in range(N + 1):",
"+ dec6 = i",
"+ dec9 = N - i",
"+ ans = min(ans, convert(dec6, 6) + convert(dec9, 9))",
"+# 出力"
] | false | 0.244187 | 0.056562 | 4.317114 | [
"s134478625",
"s524793299"
] |
u667084803 | p04046 | python | s370159088 | s468564545 | 360 | 274 | 26,864 | 18,964 | Accepted | Accepted | 23.89 | from math import factorial
H,W,A,B=list(map(int, input().split()))
p=10**9+7
ans=0
X=[1,1] #階乗テーブル
Y=[1,1] #階乗の逆元テーブル
calc=[0,1] #逆元計算用テーブル
for i in range( 2, H+W-2 ):
X.append( ( X[-1] * i ) % p )
calc.append( ( -calc[p % i] * (p//i) ) % p )
Y.append( (Y[-1] * calc[-1]) % p )
for i in range(B,W):
ans+=(X[H-A-1+i]*X[A+W-2-i]*Y[H-A-1]*Y[i]*Y[A-1]*Y[W-1-i])%p
print((ans%p)) | def power_func(a,b,p):
"""a^b mod p を求める"""
if b==0: return 1
if b%2==0:
d=power_func(a,b//2,p)
return d*d %p
if b%2==1:
return (a*power_func(a,b-1,p ))%p
H,W,A,B=list(map(int, input().split()))
p=10**9+7
ans=0
X=[1] #階乗テーブル
for i in range(1,H+W-1):
X+=[ (X[-1]*i) %p ]
Y=[1]*(H+W-1) #階乗の逆元テーブル
Y[H+W-2]=power_func(X[H+W-2],p-2,p)
for i in range(H+W-3,-1,-1):
Y[i]=Y[i+1]*(i+1) %p
for i in range(B,W):
ans+=(X[H-A-1+i]*X[A+W-2-i]*Y[H-A-1]*Y[i]*Y[A-1]*Y[W-1-i])%p
print((ans%p)) | 15 | 23 | 398 | 521 | from math import factorial
H, W, A, B = list(map(int, input().split()))
p = 10**9 + 7
ans = 0
X = [1, 1] # 階乗テーブル
Y = [1, 1] # 階乗の逆元テーブル
calc = [0, 1] # 逆元計算用テーブル
for i in range(2, H + W - 2):
X.append((X[-1] * i) % p)
calc.append((-calc[p % i] * (p // i)) % p)
Y.append((Y[-1] * calc[-1]) % p)
for i in range(B, W):
ans += (
X[H - A - 1 + i]
* X[A + W - 2 - i]
* Y[H - A - 1]
* Y[i]
* Y[A - 1]
* Y[W - 1 - i]
) % p
print((ans % p))
| def power_func(a, b, p):
"""a^b mod p を求める"""
if b == 0:
return 1
if b % 2 == 0:
d = power_func(a, b // 2, p)
return d * d % p
if b % 2 == 1:
return (a * power_func(a, b - 1, p)) % p
H, W, A, B = list(map(int, input().split()))
p = 10**9 + 7
ans = 0
X = [1] # 階乗テーブル
for i in range(1, H + W - 1):
X += [(X[-1] * i) % p]
Y = [1] * (H + W - 1) # 階乗の逆元テーブル
Y[H + W - 2] = power_func(X[H + W - 2], p - 2, p)
for i in range(H + W - 3, -1, -1):
Y[i] = Y[i + 1] * (i + 1) % p
for i in range(B, W):
ans += (
X[H - A - 1 + i]
* X[A + W - 2 - i]
* Y[H - A - 1]
* Y[i]
* Y[A - 1]
* Y[W - 1 - i]
) % p
print((ans % p))
| false | 34.782609 | [
"-from math import factorial",
"+def power_func(a, b, p):",
"+ \"\"\"a^b mod p を求める\"\"\"",
"+ if b == 0:",
"+ return 1",
"+ if b % 2 == 0:",
"+ d = power_func(a, b // 2, p)",
"+ return d * d % p",
"+ if b % 2 == 1:",
"+ return (a * power_func(a, b - 1, p)) % p",
"+",
"-X = [1, 1] # 階乗テーブル",
"-Y = [1, 1] # 階乗の逆元テーブル",
"-calc = [0, 1] # 逆元計算用テーブル",
"-for i in range(2, H + W - 2):",
"- X.append((X[-1] * i) % p)",
"- calc.append((-calc[p % i] * (p // i)) % p)",
"- Y.append((Y[-1] * calc[-1]) % p)",
"+X = [1] # 階乗テーブル",
"+for i in range(1, H + W - 1):",
"+ X += [(X[-1] * i) % p]",
"+Y = [1] * (H + W - 1) # 階乗の逆元テーブル",
"+Y[H + W - 2] = power_func(X[H + W - 2], p - 2, p)",
"+for i in range(H + W - 3, -1, -1):",
"+ Y[i] = Y[i + 1] * (i + 1) % p"
] | false | 0.041939 | 0.045787 | 0.915955 | [
"s370159088",
"s468564545"
] |
u440566786 | p03409 | python | s316793786 | s432040252 | 207 | 175 | 45,036 | 39,280 | Accepted | Accepted | 15.46 | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from collections import deque
class HopcroftKarp:
def __init__(self, N0, N1):
self.N0 = N0
self.N1 = N1
self.N = N = 2+N0+N1
self.G = [[] for i in range(N)]
for i in range(N0):
forward = [2+i, 1, None]
forward[2] = backward = [0, 0, forward]
self.G[0].append(forward)
self.G[2+i].append(backward)
self.backwards = bs = []
for i in range(N1):
forward = [1, 1, None]
forward[2] = backward = [2+N0+i, 0, forward]
bs.append(backward)
self.G[2+N0+i].append(forward)
self.G[1].append(backward)
def add_edge(self, fr, to):
#assert 0 <= fr < self.N0
#assert 0 <= to < self.N1
v0 = 2 + fr
v1 = 2 + self.N0 + to
forward = [v1, 1, None]
forward[2] = backward = [v0, 0, forward]
self.G[v0].append(forward)
self.G[v1].append(backward)
def bfs(self):
G = self.G
level = [None]*self.N
deq = deque([0])
level[0] = 0
while deq:
v = deq.popleft()
lv = level[v] + 1
for w, cap, _ in G[v]:
if cap and level[w] is None:
level[w] = lv
deq.append(w)
self.level = level
return level[1] is not None
def dfs(self, v, t):
if v == t:
return 1
level = self.level
for e in self.it[v]:
w, cap, rev = e
if cap and level[v] < level[w] and self.dfs(w, t):
e[1] = 0
rev[1] = 1
return 1
return 0
def flow(self):
flow = 0
G = self.G
bfs = self.bfs; dfs = self.dfs
while bfs():
*self.it, = list(map(iter, G))
while dfs(0, 1):
flow += 1
return flow
def matching(self):
return [cap for _, cap, _ in self.backwards]
def resolve():
n=int(eval(input()))
AB=[tuple(map(int,input().split())) for _ in range(n)]
CD=[tuple(map(int,input().split())) for _ in range(n)]
mm=HopcroftKarp(n,n)
for i in range(n):
a,b=AB[i]
for j in range(n):
c,d=CD[j]
if(a<c and b<d):
mm.add_edge(i,j)
print((mm.flow()))
resolve() | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
n=int(eval(input()))
AB=[list(map(int,input().split())) for _ in range(n)]
CD=[list(map(int,input().split())) for _ in range(n)]
AB.sort(lambda x:x[1],reverse=1)
CD.sort()
ans=0
for i in range(n):
c,d=CD[i]
for j in range(n):
a,b=AB[j]
if(a<c and b<d):
AB[j]=[INF,INF]
CD[i]=[-INF,-INF]
ans+=1
break
print(ans)
resolve() | 90 | 24 | 2,547 | 606 | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
class HopcroftKarp:
def __init__(self, N0, N1):
self.N0 = N0
self.N1 = N1
self.N = N = 2 + N0 + N1
self.G = [[] for i in range(N)]
for i in range(N0):
forward = [2 + i, 1, None]
forward[2] = backward = [0, 0, forward]
self.G[0].append(forward)
self.G[2 + i].append(backward)
self.backwards = bs = []
for i in range(N1):
forward = [1, 1, None]
forward[2] = backward = [2 + N0 + i, 0, forward]
bs.append(backward)
self.G[2 + N0 + i].append(forward)
self.G[1].append(backward)
def add_edge(self, fr, to):
# assert 0 <= fr < self.N0
# assert 0 <= to < self.N1
v0 = 2 + fr
v1 = 2 + self.N0 + to
forward = [v1, 1, None]
forward[2] = backward = [v0, 0, forward]
self.G[v0].append(forward)
self.G[v1].append(backward)
def bfs(self):
G = self.G
level = [None] * self.N
deq = deque([0])
level[0] = 0
while deq:
v = deq.popleft()
lv = level[v] + 1
for w, cap, _ in G[v]:
if cap and level[w] is None:
level[w] = lv
deq.append(w)
self.level = level
return level[1] is not None
def dfs(self, v, t):
if v == t:
return 1
level = self.level
for e in self.it[v]:
w, cap, rev = e
if cap and level[v] < level[w] and self.dfs(w, t):
e[1] = 0
rev[1] = 1
return 1
return 0
def flow(self):
flow = 0
G = self.G
bfs = self.bfs
dfs = self.dfs
while bfs():
(*self.it,) = list(map(iter, G))
while dfs(0, 1):
flow += 1
return flow
def matching(self):
return [cap for _, cap, _ in self.backwards]
def resolve():
n = int(eval(input()))
AB = [tuple(map(int, input().split())) for _ in range(n)]
CD = [tuple(map(int, input().split())) for _ in range(n)]
mm = HopcroftKarp(n, n)
for i in range(n):
a, b = AB[i]
for j in range(n):
c, d = CD[j]
if a < c and b < d:
mm.add_edge(i, j)
print((mm.flow()))
resolve()
| import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def resolve():
n = int(eval(input()))
AB = [list(map(int, input().split())) for _ in range(n)]
CD = [list(map(int, input().split())) for _ in range(n)]
AB.sort(lambda x: x[1], reverse=1)
CD.sort()
ans = 0
for i in range(n):
c, d = CD[i]
for j in range(n):
a, b = AB[j]
if a < c and b < d:
AB[j] = [INF, INF]
CD[i] = [-INF, -INF]
ans += 1
break
print(ans)
resolve()
| false | 73.333333 | [
"-from collections import deque",
"-",
"-",
"-class HopcroftKarp:",
"- def __init__(self, N0, N1):",
"- self.N0 = N0",
"- self.N1 = N1",
"- self.N = N = 2 + N0 + N1",
"- self.G = [[] for i in range(N)]",
"- for i in range(N0):",
"- forward = [2 + i, 1, None]",
"- forward[2] = backward = [0, 0, forward]",
"- self.G[0].append(forward)",
"- self.G[2 + i].append(backward)",
"- self.backwards = bs = []",
"- for i in range(N1):",
"- forward = [1, 1, None]",
"- forward[2] = backward = [2 + N0 + i, 0, forward]",
"- bs.append(backward)",
"- self.G[2 + N0 + i].append(forward)",
"- self.G[1].append(backward)",
"-",
"- def add_edge(self, fr, to):",
"- # assert 0 <= fr < self.N0",
"- # assert 0 <= to < self.N1",
"- v0 = 2 + fr",
"- v1 = 2 + self.N0 + to",
"- forward = [v1, 1, None]",
"- forward[2] = backward = [v0, 0, forward]",
"- self.G[v0].append(forward)",
"- self.G[v1].append(backward)",
"-",
"- def bfs(self):",
"- G = self.G",
"- level = [None] * self.N",
"- deq = deque([0])",
"- level[0] = 0",
"- while deq:",
"- v = deq.popleft()",
"- lv = level[v] + 1",
"- for w, cap, _ in G[v]:",
"- if cap and level[w] is None:",
"- level[w] = lv",
"- deq.append(w)",
"- self.level = level",
"- return level[1] is not None",
"-",
"- def dfs(self, v, t):",
"- if v == t:",
"- return 1",
"- level = self.level",
"- for e in self.it[v]:",
"- w, cap, rev = e",
"- if cap and level[v] < level[w] and self.dfs(w, t):",
"- e[1] = 0",
"- rev[1] = 1",
"- return 1",
"- return 0",
"-",
"- def flow(self):",
"- flow = 0",
"- G = self.G",
"- bfs = self.bfs",
"- dfs = self.dfs",
"- while bfs():",
"- (*self.it,) = list(map(iter, G))",
"- while dfs(0, 1):",
"- flow += 1",
"- return flow",
"-",
"- def matching(self):",
"- return [cap for _, cap, _ in self.backwards]",
"- AB = [tuple(map(int, input().split())) for _ in range(n)]",
"- CD = [tuple(map(int, input().split())) for _ in range(n)]",
"- mm = HopcroftKarp(n, n)",
"+ AB = [list(map(int, input().split())) for _ in range(n)]",
"+ CD = [list(map(int, input().split())) for _ in range(n)]",
"+ AB.sort(lambda x: x[1], reverse=1)",
"+ CD.sort()",
"+ ans = 0",
"- a, b = AB[i]",
"+ c, d = CD[i]",
"- c, d = CD[j]",
"+ a, b = AB[j]",
"- mm.add_edge(i, j)",
"- print((mm.flow()))",
"+ AB[j] = [INF, INF]",
"+ CD[i] = [-INF, -INF]",
"+ ans += 1",
"+ break",
"+ print(ans)"
] | false | 0.038119 | 0.037053 | 1.028771 | [
"s316793786",
"s432040252"
] |
u790710233 | p02572 | python | s136718831 | s479178611 | 167 | 120 | 31,252 | 31,448 | Accepted | Accepted | 28.14 | from itertools import accumulate
n = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9+7
Acum = list(accumulate(A))
ans = 0
for i, a in enumerate(reversed(A[1:])):
ans += Acum[n-i-2]*a
ans %= MOD
print(ans)
| n = int(eval(input()))
A = list(map(int, input().split()))
S = sum(A)
T = sum([x**2 for x in A])
print(((S**2-T)//2 % (10**9+7)))
| 13 | 5 | 241 | 131 | from itertools import accumulate
n = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
Acum = list(accumulate(A))
ans = 0
for i, a in enumerate(reversed(A[1:])):
ans += Acum[n - i - 2] * a
ans %= MOD
print(ans)
| n = int(eval(input()))
A = list(map(int, input().split()))
S = sum(A)
T = sum([x**2 for x in A])
print(((S**2 - T) // 2 % (10**9 + 7)))
| false | 61.538462 | [
"-from itertools import accumulate",
"-",
"-MOD = 10**9 + 7",
"-Acum = list(accumulate(A))",
"-ans = 0",
"-for i, a in enumerate(reversed(A[1:])):",
"- ans += Acum[n - i - 2] * a",
"- ans %= MOD",
"-print(ans)",
"+S = sum(A)",
"+T = sum([x**2 for x in A])",
"+print(((S**2 - T) // 2 % (10**9 + 7)))"
] | false | 0.048024 | 0.043379 | 1.107072 | [
"s136718831",
"s479178611"
] |
u934442292 | p03523 | python | s564080825 | s495557986 | 31 | 26 | 9,100 | 9,044 | Accepted | Accepted | 16.13 | import sys
input = sys.stdin.readline
def main():
S = input().rstrip()
for s in "KIHBR":
if S.count(s) != 1:
print("NO")
exit()
A = S.count("A")
if len(S) - A != 5:
print("NO")
exit()
K = S.find("K")
I = S.find("I")
H = S.find("H")
B = S.find("B")
R = S.find("R")
if not (K < I < H < B < R):
print("NO")
exit()
if K > 1:
print("NO")
exit()
if I - K != 1:
print("NO")
exit()
if H - I != 1:
print("NO")
exit()
if B - H > 2:
print("NO")
exit()
if R - B > 2:
print("NO")
exit()
if len(S) - 1 - R > 1:
print("NO")
exit()
print("YES")
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
S = input().rstrip()
# AKIHABARA
correct_list = [
"AKIHABARA",
"KIHABARA",
"AKIHBARA",
"AKIHABRA",
"AKIHABAR",
"KIHBARA",
"KIHABRA",
"KIHABAR",
"AKIHBRA",
"AKIHBAR",
"AKIHABR",
"KIHBRA",
"KIHBAR",
"KIHABR",
"AKIHBR",
"KIHBR",
]
is_correct = False
for correct in correct_list:
if S == correct:
is_correct = True
break
if is_correct:
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
| 50 | 42 | 853 | 708 | import sys
input = sys.stdin.readline
def main():
S = input().rstrip()
for s in "KIHBR":
if S.count(s) != 1:
print("NO")
exit()
A = S.count("A")
if len(S) - A != 5:
print("NO")
exit()
K = S.find("K")
I = S.find("I")
H = S.find("H")
B = S.find("B")
R = S.find("R")
if not (K < I < H < B < R):
print("NO")
exit()
if K > 1:
print("NO")
exit()
if I - K != 1:
print("NO")
exit()
if H - I != 1:
print("NO")
exit()
if B - H > 2:
print("NO")
exit()
if R - B > 2:
print("NO")
exit()
if len(S) - 1 - R > 1:
print("NO")
exit()
print("YES")
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
S = input().rstrip()
# AKIHABARA
correct_list = [
"AKIHABARA",
"KIHABARA",
"AKIHBARA",
"AKIHABRA",
"AKIHABAR",
"KIHBARA",
"KIHABRA",
"KIHABAR",
"AKIHBRA",
"AKIHBAR",
"AKIHABR",
"KIHBRA",
"KIHBAR",
"KIHABR",
"AKIHBR",
"KIHBR",
]
is_correct = False
for correct in correct_list:
if S == correct:
is_correct = True
break
if is_correct:
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
| false | 16 | [
"- for s in \"KIHBR\":",
"- if S.count(s) != 1:",
"- print(\"NO\")",
"- exit()",
"- A = S.count(\"A\")",
"- if len(S) - A != 5:",
"+ # AKIHABARA",
"+ correct_list = [",
"+ \"AKIHABARA\",",
"+ \"KIHABARA\",",
"+ \"AKIHBARA\",",
"+ \"AKIHABRA\",",
"+ \"AKIHABAR\",",
"+ \"KIHBARA\",",
"+ \"KIHABRA\",",
"+ \"KIHABAR\",",
"+ \"AKIHBRA\",",
"+ \"AKIHBAR\",",
"+ \"AKIHABR\",",
"+ \"KIHBRA\",",
"+ \"KIHBAR\",",
"+ \"KIHABR\",",
"+ \"AKIHBR\",",
"+ \"KIHBR\",",
"+ ]",
"+ is_correct = False",
"+ for correct in correct_list:",
"+ if S == correct:",
"+ is_correct = True",
"+ break",
"+ if is_correct:",
"+ print(\"YES\")",
"+ else:",
"- exit()",
"- K = S.find(\"K\")",
"- I = S.find(\"I\")",
"- H = S.find(\"H\")",
"- B = S.find(\"B\")",
"- R = S.find(\"R\")",
"- if not (K < I < H < B < R):",
"- print(\"NO\")",
"- exit()",
"- if K > 1:",
"- print(\"NO\")",
"- exit()",
"- if I - K != 1:",
"- print(\"NO\")",
"- exit()",
"- if H - I != 1:",
"- print(\"NO\")",
"- exit()",
"- if B - H > 2:",
"- print(\"NO\")",
"- exit()",
"- if R - B > 2:",
"- print(\"NO\")",
"- exit()",
"- if len(S) - 1 - R > 1:",
"- print(\"NO\")",
"- exit()",
"- print(\"YES\")"
] | false | 0.039377 | 0.038708 | 1.017276 | [
"s564080825",
"s495557986"
] |
u177398299 | p03326 | python | s740472392 | s042194347 | 797 | 217 | 167,388 | 40,816 | Accepted | Accepted | 72.77 | N, M = list(map(int, input().split()))
cake = [list(map(int, input().split())) for _ in range(N)]
INF = 10 ** 18
dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(N + 1):
for msk in range(8):
dp[i][0][msk] = 0
for i in range(1, N + 1):
x, y, z = cake[i - 1]
for j in range(1, M + 1):
for msk in range(8):
mx = x * (1 - 2 * (msk >> 2 & 1))
my = y * (1 - 2 * (msk >> 1 & 1))
mz = z * (1 - 2 * (msk >> 0 & 1))
dp[i][j][msk] = max(dp[i - 1][j][msk],
dp[i - 1][j - 1][msk] + mx + my + mz)
print((max(dp[N][M][i] for i in range(8)))) | N, M = list(map(int, input().split()))
cake = [list(map(int, input().split())) for _ in range(N)]
ans = [[] for _ in range(8)]
for x, y, z in cake:
for msk in range(8):
mx = x * (1 - 2 * (msk >> 2 & 1))
my = y * (1 - 2 * (msk >> 1 & 1))
mz = z * (1 - 2 * (msk >> 0 & 1))
ans[msk].append(mx + my + mz)
print((max(sum(sorted(x, reverse=True)[:M]) for x in ans))) | 20 | 12 | 678 | 401 | N, M = list(map(int, input().split()))
cake = [list(map(int, input().split())) for _ in range(N)]
INF = 10**18
dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(N + 1):
for msk in range(8):
dp[i][0][msk] = 0
for i in range(1, N + 1):
x, y, z = cake[i - 1]
for j in range(1, M + 1):
for msk in range(8):
mx = x * (1 - 2 * (msk >> 2 & 1))
my = y * (1 - 2 * (msk >> 1 & 1))
mz = z * (1 - 2 * (msk >> 0 & 1))
dp[i][j][msk] = max(dp[i - 1][j][msk], dp[i - 1][j - 1][msk] + mx + my + mz)
print((max(dp[N][M][i] for i in range(8))))
| N, M = list(map(int, input().split()))
cake = [list(map(int, input().split())) for _ in range(N)]
ans = [[] for _ in range(8)]
for x, y, z in cake:
for msk in range(8):
mx = x * (1 - 2 * (msk >> 2 & 1))
my = y * (1 - 2 * (msk >> 1 & 1))
mz = z * (1 - 2 * (msk >> 0 & 1))
ans[msk].append(mx + my + mz)
print((max(sum(sorted(x, reverse=True)[:M]) for x in ans)))
| false | 40 | [
"-INF = 10**18",
"-dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)]",
"-for i in range(N + 1):",
"+ans = [[] for _ in range(8)]",
"+for x, y, z in cake:",
"- dp[i][0][msk] = 0",
"-for i in range(1, N + 1):",
"- x, y, z = cake[i - 1]",
"- for j in range(1, M + 1):",
"- for msk in range(8):",
"- mx = x * (1 - 2 * (msk >> 2 & 1))",
"- my = y * (1 - 2 * (msk >> 1 & 1))",
"- mz = z * (1 - 2 * (msk >> 0 & 1))",
"- dp[i][j][msk] = max(dp[i - 1][j][msk], dp[i - 1][j - 1][msk] + mx + my + mz)",
"-print((max(dp[N][M][i] for i in range(8))))",
"+ mx = x * (1 - 2 * (msk >> 2 & 1))",
"+ my = y * (1 - 2 * (msk >> 1 & 1))",
"+ mz = z * (1 - 2 * (msk >> 0 & 1))",
"+ ans[msk].append(mx + my + mz)",
"+print((max(sum(sorted(x, reverse=True)[:M]) for x in ans)))"
] | false | 0.037217 | 0.036406 | 1.022277 | [
"s740472392",
"s042194347"
] |
u368796742 | p02735 | python | s373851747 | s975488457 | 815 | 204 | 816,648 | 43,120 | Accepted | Accepted | 74.97 | def main():
from collections import deque
h,w = list(map(int,input().split()))
l = [list(eval(input())) for i in range(h)]
dp = [[[-1]*(h*w) for i in range(w)] for i in range(h)]
q = deque([])
if l[0][0] == ".":
q.append((0,0,0,"."))
else:
q.append((0,0,1,"#"))
dx = [0,1]
dy = [1,0]
while q:
bx,by,num,bef = q.popleft()
for j in range(2):
nx = bx+dx[j]
ny = by+dy[j]
if nx < h and ny < w:
if bef == "." and l[nx][ny] == "#":
if dp[nx][ny][num+1] == -1:
dp[nx][ny][num+1] = 1
q.append((nx,ny,num+1,l[nx][ny]))
elif dp[nx][ny][num] == -1:
dp[nx][ny][num] = 1
q.append((nx,ny,num,l[nx][ny]))
print((dp[-1][-1].index(1)))
if __name__ == "__main__":
main()
| h,w = list(map(int,input().split()))
l = [list(eval(input())) for i in range(h)]
dp = [[-1]*w for i in range(h)]
if l[0][0] == ".":
dp[0][0] = 0
else:
dp[0][0] = 1
for i in range(h):
for j in range(w):
if i == 0 and j == 0:
continue
if i == 0:
if l[i][j-1] == "." and l[i][j] == "#":
dp[i][j] = dp[i][j-1]+1
else:
dp[i][j] = dp[i][j-1]
elif j == 0:
if l[i-1][j] == "." and l[i][j] == "#":
dp[i][j] = dp[i-1][j]+1
else:
dp[i][j] = dp[i-1][j]
else:
a = dp[i-1][j]
b = dp[i][j-1]
if l[i-1][j] == "." and l[i][j] == "#":
a += 1
if l[i][j-1] == "." and l[i][j] == "#":
b += 1
dp[i][j] = min(a,b)
print((dp[-1][-1]))
| 33 | 35 | 960 | 917 | def main():
from collections import deque
h, w = list(map(int, input().split()))
l = [list(eval(input())) for i in range(h)]
dp = [[[-1] * (h * w) for i in range(w)] for i in range(h)]
q = deque([])
if l[0][0] == ".":
q.append((0, 0, 0, "."))
else:
q.append((0, 0, 1, "#"))
dx = [0, 1]
dy = [1, 0]
while q:
bx, by, num, bef = q.popleft()
for j in range(2):
nx = bx + dx[j]
ny = by + dy[j]
if nx < h and ny < w:
if bef == "." and l[nx][ny] == "#":
if dp[nx][ny][num + 1] == -1:
dp[nx][ny][num + 1] = 1
q.append((nx, ny, num + 1, l[nx][ny]))
elif dp[nx][ny][num] == -1:
dp[nx][ny][num] = 1
q.append((nx, ny, num, l[nx][ny]))
print((dp[-1][-1].index(1)))
if __name__ == "__main__":
main()
| h, w = list(map(int, input().split()))
l = [list(eval(input())) for i in range(h)]
dp = [[-1] * w for i in range(h)]
if l[0][0] == ".":
dp[0][0] = 0
else:
dp[0][0] = 1
for i in range(h):
for j in range(w):
if i == 0 and j == 0:
continue
if i == 0:
if l[i][j - 1] == "." and l[i][j] == "#":
dp[i][j] = dp[i][j - 1] + 1
else:
dp[i][j] = dp[i][j - 1]
elif j == 0:
if l[i - 1][j] == "." and l[i][j] == "#":
dp[i][j] = dp[i - 1][j] + 1
else:
dp[i][j] = dp[i - 1][j]
else:
a = dp[i - 1][j]
b = dp[i][j - 1]
if l[i - 1][j] == "." and l[i][j] == "#":
a += 1
if l[i][j - 1] == "." and l[i][j] == "#":
b += 1
dp[i][j] = min(a, b)
print((dp[-1][-1]))
| false | 5.714286 | [
"-def main():",
"- from collections import deque",
"-",
"- h, w = list(map(int, input().split()))",
"- l = [list(eval(input())) for i in range(h)]",
"- dp = [[[-1] * (h * w) for i in range(w)] for i in range(h)]",
"- q = deque([])",
"- if l[0][0] == \".\":",
"- q.append((0, 0, 0, \".\"))",
"- else:",
"- q.append((0, 0, 1, \"#\"))",
"- dx = [0, 1]",
"- dy = [1, 0]",
"- while q:",
"- bx, by, num, bef = q.popleft()",
"- for j in range(2):",
"- nx = bx + dx[j]",
"- ny = by + dy[j]",
"- if nx < h and ny < w:",
"- if bef == \".\" and l[nx][ny] == \"#\":",
"- if dp[nx][ny][num + 1] == -1:",
"- dp[nx][ny][num + 1] = 1",
"- q.append((nx, ny, num + 1, l[nx][ny]))",
"- elif dp[nx][ny][num] == -1:",
"- dp[nx][ny][num] = 1",
"- q.append((nx, ny, num, l[nx][ny]))",
"- print((dp[-1][-1].index(1)))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+h, w = list(map(int, input().split()))",
"+l = [list(eval(input())) for i in range(h)]",
"+dp = [[-1] * w for i in range(h)]",
"+if l[0][0] == \".\":",
"+ dp[0][0] = 0",
"+else:",
"+ dp[0][0] = 1",
"+for i in range(h):",
"+ for j in range(w):",
"+ if i == 0 and j == 0:",
"+ continue",
"+ if i == 0:",
"+ if l[i][j - 1] == \".\" and l[i][j] == \"#\":",
"+ dp[i][j] = dp[i][j - 1] + 1",
"+ else:",
"+ dp[i][j] = dp[i][j - 1]",
"+ elif j == 0:",
"+ if l[i - 1][j] == \".\" and l[i][j] == \"#\":",
"+ dp[i][j] = dp[i - 1][j] + 1",
"+ else:",
"+ dp[i][j] = dp[i - 1][j]",
"+ else:",
"+ a = dp[i - 1][j]",
"+ b = dp[i][j - 1]",
"+ if l[i - 1][j] == \".\" and l[i][j] == \"#\":",
"+ a += 1",
"+ if l[i][j - 1] == \".\" and l[i][j] == \"#\":",
"+ b += 1",
"+ dp[i][j] = min(a, b)",
"+print((dp[-1][-1]))"
] | false | 0.067235 | 0.071712 | 0.937569 | [
"s373851747",
"s975488457"
] |
u777283665 | p03017 | python | s649488991 | s943890032 | 51 | 37 | 3,572 | 3,636 | Accepted | Accepted | 27.45 | n, a, b, c, d = list(map(int, input().split()))
a, b, c, d = a-1, b-1, c-1, d-1
s = eval(input())
if c < d:
for i in range(b, d):
if s[i] == "#" and s[i+1] == "#":
print("No")
exit()
for i in range(a, c):
if s[i] == "#" and s[i+1] == "#":
print("No")
exit()
print("Yes")
else:
for i in range(b, d+1):
if s[i] != "#" and s[i-1] == "." and s[i+1] == ".":
print("Yes")
exit()
print("No") | n, a, b, c, d = list(map(int, input().split()))
a, b, c, d = a-1, b-1, c-1, d-1
s = eval(input())
if "##" in s[a:d]:
print("No")
exit()
if c < d:
for i in range(b, d):
if s[i] == "#" and s[i+1] == "#":
print("No")
exit()
print("Yes")
else:
for i in range(b, d+1):
if s[i] != "#" and s[i-1] == "." and s[i+1] == ".":
print("Yes")
exit()
print("No") | 23 | 23 | 514 | 450 | n, a, b, c, d = list(map(int, input().split()))
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = eval(input())
if c < d:
for i in range(b, d):
if s[i] == "#" and s[i + 1] == "#":
print("No")
exit()
for i in range(a, c):
if s[i] == "#" and s[i + 1] == "#":
print("No")
exit()
print("Yes")
else:
for i in range(b, d + 1):
if s[i] != "#" and s[i - 1] == "." and s[i + 1] == ".":
print("Yes")
exit()
print("No")
| n, a, b, c, d = list(map(int, input().split()))
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = eval(input())
if "##" in s[a:d]:
print("No")
exit()
if c < d:
for i in range(b, d):
if s[i] == "#" and s[i + 1] == "#":
print("No")
exit()
print("Yes")
else:
for i in range(b, d + 1):
if s[i] != "#" and s[i - 1] == "." and s[i + 1] == ".":
print("Yes")
exit()
print("No")
| false | 0 | [
"+if \"##\" in s[a:d]:",
"+ print(\"No\")",
"+ exit()",
"- if s[i] == \"#\" and s[i + 1] == \"#\":",
"- print(\"No\")",
"- exit()",
"- for i in range(a, c):"
] | false | 0.037478 | 0.043215 | 0.867248 | [
"s649488991",
"s943890032"
] |
u273010357 | p02802 | python | s194485668 | s293925606 | 312 | 267 | 4,596 | 44,464 | Accepted | Accepted | 14.42 | def solve():
N, M = list(map(int, input().split()))
WAnum = 0
ACnum = 0
WA = [0]*(N+1)
AC = [False]*(N+1)
for _ in range(M):
p, S = list(map(str, input().split()))
p = int(p)
if AC[p] == True:
continue
if S == 'AC':
AC[p] = True
ACnum += 1
WAnum += WA[p]
elif S == 'WA':
WA[p] += 1
#print(AC, WA)
#print(AC,WA)
print((ACnum, WAnum))
solve() | import sys, heapq
from collections import defaultdict
from itertools import product, permutations, combinations
from bisect import bisect_left # bisect(list, value) -> index
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
N, M = list(map(int, input().split()))
pS = [list(input().split()) for _ in range(M)]
ac_num = defaultdict(int) # number of AC : dict
wa_num = defaultdict(int) # number of WA : dict
wass = 0 # number of WA : int
for ps in pS:
p, S = int(ps[0]), ps[1]
# 一度問題pがACなら飛ばす
if ac_num[p] == 1:
continue
else:
if S == 'AC':
ac_num[p] = 1
# ACになるまでにWAになった数を記録
wass += wa_num[p]
elif S == 'WA':
wa_num[p] += 1
#print(ac_num, wa_num)
print((sum(list(ac_num.values())), wass)) | 23 | 30 | 490 | 833 | def solve():
N, M = list(map(int, input().split()))
WAnum = 0
ACnum = 0
WA = [0] * (N + 1)
AC = [False] * (N + 1)
for _ in range(M):
p, S = list(map(str, input().split()))
p = int(p)
if AC[p] == True:
continue
if S == "AC":
AC[p] = True
ACnum += 1
WAnum += WA[p]
elif S == "WA":
WA[p] += 1
# print(AC, WA)
# print(AC,WA)
print((ACnum, WAnum))
solve()
| import sys, heapq
from collections import defaultdict
from itertools import product, permutations, combinations
from bisect import bisect_left # bisect(list, value) -> index
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
N, M = list(map(int, input().split()))
pS = [list(input().split()) for _ in range(M)]
ac_num = defaultdict(int) # number of AC : dict
wa_num = defaultdict(int) # number of WA : dict
wass = 0 # number of WA : int
for ps in pS:
p, S = int(ps[0]), ps[1]
# 一度問題pがACなら飛ばす
if ac_num[p] == 1:
continue
else:
if S == "AC":
ac_num[p] = 1
# ACになるまでにWAになった数を記録
wass += wa_num[p]
elif S == "WA":
wa_num[p] += 1
# print(ac_num, wa_num)
print((sum(list(ac_num.values())), wass))
| false | 23.333333 | [
"-def solve():",
"- N, M = list(map(int, input().split()))",
"- WAnum = 0",
"- ACnum = 0",
"- WA = [0] * (N + 1)",
"- AC = [False] * (N + 1)",
"- for _ in range(M):",
"- p, S = list(map(str, input().split()))",
"- p = int(p)",
"- if AC[p] == True:",
"- continue",
"- if S == \"AC\":",
"- AC[p] = True",
"- ACnum += 1",
"- WAnum += WA[p]",
"- elif S == \"WA\":",
"- WA[p] += 1",
"- # print(AC, WA)",
"- # print(AC,WA)",
"- print((ACnum, WAnum))",
"+import sys, heapq",
"+from collections import defaultdict",
"+from itertools import product, permutations, combinations",
"+from bisect import bisect_left # bisect(list, value) -> index",
"+",
"+sys.setrecursionlimit(10**7)",
"-solve()",
"+def input():",
"+ return sys.stdin.readline()[:-1]",
"+",
"+",
"+N, M = list(map(int, input().split()))",
"+pS = [list(input().split()) for _ in range(M)]",
"+ac_num = defaultdict(int) # number of AC : dict",
"+wa_num = defaultdict(int) # number of WA : dict",
"+wass = 0 # number of WA : int",
"+for ps in pS:",
"+ p, S = int(ps[0]), ps[1]",
"+ # 一度問題pがACなら飛ばす",
"+ if ac_num[p] == 1:",
"+ continue",
"+ else:",
"+ if S == \"AC\":",
"+ ac_num[p] = 1",
"+ # ACになるまでにWAになった数を記録",
"+ wass += wa_num[p]",
"+ elif S == \"WA\":",
"+ wa_num[p] += 1",
"+ # print(ac_num, wa_num)",
"+print((sum(list(ac_num.values())), wass))"
] | false | 0.03775 | 0.036404 | 1.036964 | [
"s194485668",
"s293925606"
] |
u038021590 | p03167 | python | s044319736 | s212084841 | 405 | 159 | 129,368 | 119,732 | Accepted | Accepted | 60.74 | mod = 10**9 + 7
H, W = list(map(int, input().split()))
Maze = [[0]*(W+1) for _ in range(H+1)]
Memo = [[0]*(W+1) for _ in range(H+1)]
Memo[H-1][W-1] = 1
for i in range(H):
S = eval(input())
for j in range(W):
Maze[i][j] = S[j]
for a in range(H-1, -1, -1):
for b in range(W-1, -1, -1):
if Maze[a][b] == '#':
Memo[a][b] = 0
elif (a == H-1) and (b == W-1):
continue
else:
Memo[a][b] = Memo[a+1][b] + Memo[a][b+1]
Memo[a][b] %= mod
print((Memo[0][0]))
| H, W = list(map(int, input().split()))
S = [[a for a in eval(input())] for _ in range(H)]
mod = 10 ** 9 + 7
DP = [[0] * (W + 1) for _ in range(H+1)]
DP[1][1] = 1
for i in range(1, H+1):
for j in range(1, W+1):
if S[i-1][j-1] == '#':
continue
if i == 1 and j == 1:
continue
DP[i][j] = DP[i - 1][j] + DP[i][j - 1]
DP[i][j] %= mod
print((DP[-1][-1]))
| 20 | 15 | 545 | 409 | mod = 10**9 + 7
H, W = list(map(int, input().split()))
Maze = [[0] * (W + 1) for _ in range(H + 1)]
Memo = [[0] * (W + 1) for _ in range(H + 1)]
Memo[H - 1][W - 1] = 1
for i in range(H):
S = eval(input())
for j in range(W):
Maze[i][j] = S[j]
for a in range(H - 1, -1, -1):
for b in range(W - 1, -1, -1):
if Maze[a][b] == "#":
Memo[a][b] = 0
elif (a == H - 1) and (b == W - 1):
continue
else:
Memo[a][b] = Memo[a + 1][b] + Memo[a][b + 1]
Memo[a][b] %= mod
print((Memo[0][0]))
| H, W = list(map(int, input().split()))
S = [[a for a in eval(input())] for _ in range(H)]
mod = 10**9 + 7
DP = [[0] * (W + 1) for _ in range(H + 1)]
DP[1][1] = 1
for i in range(1, H + 1):
for j in range(1, W + 1):
if S[i - 1][j - 1] == "#":
continue
if i == 1 and j == 1:
continue
DP[i][j] = DP[i - 1][j] + DP[i][j - 1]
DP[i][j] %= mod
print((DP[-1][-1]))
| false | 25 | [
"+H, W = list(map(int, input().split()))",
"+S = [[a for a in eval(input())] for _ in range(H)]",
"-H, W = list(map(int, input().split()))",
"-Maze = [[0] * (W + 1) for _ in range(H + 1)]",
"-Memo = [[0] * (W + 1) for _ in range(H + 1)]",
"-Memo[H - 1][W - 1] = 1",
"-for i in range(H):",
"- S = eval(input())",
"- for j in range(W):",
"- Maze[i][j] = S[j]",
"-for a in range(H - 1, -1, -1):",
"- for b in range(W - 1, -1, -1):",
"- if Maze[a][b] == \"#\":",
"- Memo[a][b] = 0",
"- elif (a == H - 1) and (b == W - 1):",
"+DP = [[0] * (W + 1) for _ in range(H + 1)]",
"+DP[1][1] = 1",
"+for i in range(1, H + 1):",
"+ for j in range(1, W + 1):",
"+ if S[i - 1][j - 1] == \"#\":",
"- else:",
"- Memo[a][b] = Memo[a + 1][b] + Memo[a][b + 1]",
"- Memo[a][b] %= mod",
"-print((Memo[0][0]))",
"+ if i == 1 and j == 1:",
"+ continue",
"+ DP[i][j] = DP[i - 1][j] + DP[i][j - 1]",
"+ DP[i][j] %= mod",
"+print((DP[-1][-1]))"
] | false | 0.085071 | 0.043938 | 1.936161 | [
"s044319736",
"s212084841"
] |
u074220993 | p03835 | python | s809890998 | s347019040 | 1,175 | 1,076 | 9,112 | 9,088 | Accepted | Accepted | 8.43 | K, S = list(map(int, input().split()))
cnt = 0
for x in range(K+1):
for y in range(K+1):
z = S - x - y
if 0 <= z <= K:
cnt += 1
print(cnt) | K, S = list(map(int, input().split()))
cnt = 0
from itertools import product as prd
for x, y in prd(list(range(K+1)),list(range(K+1))):
if 0 <= S-x-y <= K:
cnt += 1
print(cnt) | 8 | 7 | 171 | 175 | K, S = list(map(int, input().split()))
cnt = 0
for x in range(K + 1):
for y in range(K + 1):
z = S - x - y
if 0 <= z <= K:
cnt += 1
print(cnt)
| K, S = list(map(int, input().split()))
cnt = 0
from itertools import product as prd
for x, y in prd(list(range(K + 1)), list(range(K + 1))):
if 0 <= S - x - y <= K:
cnt += 1
print(cnt)
| false | 12.5 | [
"-for x in range(K + 1):",
"- for y in range(K + 1):",
"- z = S - x - y",
"- if 0 <= z <= K:",
"- cnt += 1",
"+from itertools import product as prd",
"+",
"+for x, y in prd(list(range(K + 1)), list(range(K + 1))):",
"+ if 0 <= S - x - y <= K:",
"+ cnt += 1"
] | false | 0.05831 | 0.039734 | 1.467495 | [
"s809890998",
"s347019040"
] |
u156815136 | p02642 | python | s454886602 | s822795712 | 393 | 338 | 45,220 | 50,616 | Accepted | Accepted | 13.99 | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
n = I()
A = sorted(readInts())
dic = defaultdict(int)
cnt = 0
for i in A:
dic[i] += 1
A = list(set(A))
# ------------
is_prime = [True] * (10**6+1)
#print('a')
for i in range(len(A)):
#ll += 1
#print(i)
#print(A[i])
if is_prime[A[i]] == True:
for j in range(2*A[i], 10**6+1,A[i]):
is_prime[j] = False # その素数の倍数のやつ
# -----------
cnt = 0
if A[0] == 1:
if dic[1] >= 2:
print((0))
exit()
else:
print((1))
exit()
for a in A:
if is_prime[a] and not dic[a] >= 2:
#print(a)
cnt += 1
print(cnt)
| #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
N = I()
A = readInts()
import collections
dic = collections.Counter(A)
A = set(A)
is_prime = [True] * (10**6+1)
for a in A:
if is_prime[a]:
for v in range(a*2,10**6+1,a):
is_prime[v] = False
cnt = 0
for a in A:
if is_prime[a]:
cnt += 1
for k,v in list(dic.items()):
if v >= 2 and is_prime[k]:
cnt -= 1
print(cnt)
| 58 | 44 | 1,224 | 993 | # from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
# from fractions import gcd
# from itertools import combinations # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
n = I()
A = sorted(readInts())
dic = defaultdict(int)
cnt = 0
for i in A:
dic[i] += 1
A = list(set(A))
# ------------
is_prime = [True] * (10**6 + 1)
# print('a')
for i in range(len(A)):
# ll += 1
# print(i)
# print(A[i])
if is_prime[A[i]] == True:
for j in range(2 * A[i], 10**6 + 1, A[i]):
is_prime[j] = False # その素数の倍数のやつ
# -----------
cnt = 0
if A[0] == 1:
if dic[1] >= 2:
print((0))
exit()
else:
print((1))
exit()
for a in A:
if is_prime[a] and not dic[a] >= 2:
# print(a)
cnt += 1
print(cnt)
| # from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
N = I()
A = readInts()
import collections
dic = collections.Counter(A)
A = set(A)
is_prime = [True] * (10**6 + 1)
for a in A:
if is_prime[a]:
for v in range(a * 2, 10**6 + 1, a):
is_prime[v] = False
cnt = 0
for a in A:
if is_prime[a]:
cnt += 1
for k, v in list(dic.items()):
if v >= 2 and is_prime[k]:
cnt -= 1
print(cnt)
| false | 24.137931 | [
"-# from fractions import gcd",
"-# from itertools import combinations # (string,3) 3回",
"+from fractions import gcd",
"+from itertools import combinations, permutations # (string,3) 3回",
"+",
"-n = I()",
"-A = sorted(readInts())",
"-dic = defaultdict(int)",
"+N = I()",
"+A = readInts()",
"+import collections",
"+",
"+dic = collections.Counter(A)",
"+A = set(A)",
"+is_prime = [True] * (10**6 + 1)",
"+for a in A:",
"+ if is_prime[a]:",
"+ for v in range(a * 2, 10**6 + 1, a):",
"+ is_prime[v] = False",
"-for i in A:",
"- dic[i] += 1",
"-A = list(set(A))",
"-is_prime = [True] * (10**6 + 1)",
"-# print('a')",
"-for i in range(len(A)):",
"- # ll += 1",
"- # print(i)",
"- # print(A[i])",
"- if is_prime[A[i]] == True:",
"- for j in range(2 * A[i], 10**6 + 1, A[i]):",
"- is_prime[j] = False # その素数の倍数のやつ",
"-cnt = 0",
"-if A[0] == 1:",
"- if dic[1] >= 2:",
"- print((0))",
"- exit()",
"- else:",
"- print((1))",
"- exit()",
"- if is_prime[a] and not dic[a] >= 2:",
"- # print(a)",
"+ if is_prime[a]:",
"+for k, v in list(dic.items()):",
"+ if v >= 2 and is_prime[k]:",
"+ cnt -= 1"
] | false | 0.154277 | 0.148878 | 1.036269 | [
"s454886602",
"s822795712"
] |
u488401358 | p02816 | python | s581442773 | s330998755 | 1,505 | 583 | 138,624 | 128,080 | Accepted | Accepted | 61.26 | def divisors(M):#Mの約数列 O(n^(0.5+e))
import math
d=[]
i=1
while math.sqrt(M)>=i:
if M%i==0:
d.append(i)
if i**2!=M:
d.append(M//i)
i=i+1
d.sort()
return d
N=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[a[i]^a[i-1] for i in range(0,N)]
B=[b[i]^b[i-1] for i in range(0,N)]
d=divisors(N)
perioda=N
for i in range(0,len(d)):
test=[A[(j+d[i])%N] for j in range(0,N)]
if test==A:
perioda=min(perioda,d[i])
periodb=N
for i in range(0,len(d)):
test=[B[(j+d[i])%N] for j in range(0,N)]
if test==B:
periodb=min(periodb,d[i])
if perioda==periodb:
A=A[:perioda]
B=B[:periodb]
kouho=[]
for i in range(0,len(B)):
if A[i]==B[0]:
kouho.append(i)
ans=-1
for i in range(0,len(kouho)):
test=[A[(j+kouho[i])%perioda] for j in range(0,perioda)]
if test==B:
ans=kouho[i]
break
if ans!=-1:
for i in range(0,N//perioda):
print((ans+perioda*i,a[ans+perioda*i]^b[0])) | #Z[i]:length of the longest list starting from S[i] which is also a prefix of S
#O(|S|)
def Z_algorithm(s):
N = len(s)
Z_alg = [0]*N
Z_alg[0] = N
i = 1
j = 0
while i < N:
while i+j < N and s[j] == s[i+j]:
j += 1
Z_alg[i] = j
if j == 0:
i += 1
continue
k = 1
while i+k < N and k + Z_alg[k]<j:
Z_alg[i+k] = Z_alg[k]
k += 1
i += k
j -= k
return Z_alg
N=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[a[i]^a[i-1] for i in range(0,N)]
B=[b[i]^b[i-1] for i in range(0,N)]
data=B+['?']+A+A
s=Z_algorithm(data)
for i in range(N+1,2*N+1):
if s[i]>=N:
print((i-N-1,a[i-N-1]^b[0])) | 47 | 35 | 1,144 | 796 | def divisors(M): # Mの約数列 O(n^(0.5+e))
import math
d = []
i = 1
while math.sqrt(M) >= i:
if M % i == 0:
d.append(i)
if i**2 != M:
d.append(M // i)
i = i + 1
d.sort()
return d
N = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [a[i] ^ a[i - 1] for i in range(0, N)]
B = [b[i] ^ b[i - 1] for i in range(0, N)]
d = divisors(N)
perioda = N
for i in range(0, len(d)):
test = [A[(j + d[i]) % N] for j in range(0, N)]
if test == A:
perioda = min(perioda, d[i])
periodb = N
for i in range(0, len(d)):
test = [B[(j + d[i]) % N] for j in range(0, N)]
if test == B:
periodb = min(periodb, d[i])
if perioda == periodb:
A = A[:perioda]
B = B[:periodb]
kouho = []
for i in range(0, len(B)):
if A[i] == B[0]:
kouho.append(i)
ans = -1
for i in range(0, len(kouho)):
test = [A[(j + kouho[i]) % perioda] for j in range(0, perioda)]
if test == B:
ans = kouho[i]
break
if ans != -1:
for i in range(0, N // perioda):
print((ans + perioda * i, a[ans + perioda * i] ^ b[0]))
| # Z[i]:length of the longest list starting from S[i] which is also a prefix of S
# O(|S|)
def Z_algorithm(s):
N = len(s)
Z_alg = [0] * N
Z_alg[0] = N
i = 1
j = 0
while i < N:
while i + j < N and s[j] == s[i + j]:
j += 1
Z_alg[i] = j
if j == 0:
i += 1
continue
k = 1
while i + k < N and k + Z_alg[k] < j:
Z_alg[i + k] = Z_alg[k]
k += 1
i += k
j -= k
return Z_alg
N = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [a[i] ^ a[i - 1] for i in range(0, N)]
B = [b[i] ^ b[i - 1] for i in range(0, N)]
data = B + ["?"] + A + A
s = Z_algorithm(data)
for i in range(N + 1, 2 * N + 1):
if s[i] >= N:
print((i - N - 1, a[i - N - 1] ^ b[0]))
| false | 25.531915 | [
"-def divisors(M): # Mの約数列 O(n^(0.5+e))",
"- import math",
"-",
"- d = []",
"+# Z[i]:length of the longest list starting from S[i] which is also a prefix of S",
"+# O(|S|)",
"+def Z_algorithm(s):",
"+ N = len(s)",
"+ Z_alg = [0] * N",
"+ Z_alg[0] = N",
"- while math.sqrt(M) >= i:",
"- if M % i == 0:",
"- d.append(i)",
"- if i**2 != M:",
"- d.append(M // i)",
"- i = i + 1",
"- d.sort()",
"- return d",
"+ j = 0",
"+ while i < N:",
"+ while i + j < N and s[j] == s[i + j]:",
"+ j += 1",
"+ Z_alg[i] = j",
"+ if j == 0:",
"+ i += 1",
"+ continue",
"+ k = 1",
"+ while i + k < N and k + Z_alg[k] < j:",
"+ Z_alg[i + k] = Z_alg[k]",
"+ k += 1",
"+ i += k",
"+ j -= k",
"+ return Z_alg",
"-d = divisors(N)",
"-perioda = N",
"-for i in range(0, len(d)):",
"- test = [A[(j + d[i]) % N] for j in range(0, N)]",
"- if test == A:",
"- perioda = min(perioda, d[i])",
"-periodb = N",
"-for i in range(0, len(d)):",
"- test = [B[(j + d[i]) % N] for j in range(0, N)]",
"- if test == B:",
"- periodb = min(periodb, d[i])",
"-if perioda == periodb:",
"- A = A[:perioda]",
"- B = B[:periodb]",
"- kouho = []",
"- for i in range(0, len(B)):",
"- if A[i] == B[0]:",
"- kouho.append(i)",
"- ans = -1",
"- for i in range(0, len(kouho)):",
"- test = [A[(j + kouho[i]) % perioda] for j in range(0, perioda)]",
"- if test == B:",
"- ans = kouho[i]",
"- break",
"- if ans != -1:",
"- for i in range(0, N // perioda):",
"- print((ans + perioda * i, a[ans + perioda * i] ^ b[0]))",
"+data = B + [\"?\"] + A + A",
"+s = Z_algorithm(data)",
"+for i in range(N + 1, 2 * N + 1):",
"+ if s[i] >= N:",
"+ print((i - N - 1, a[i - N - 1] ^ b[0]))"
] | false | 0.037518 | 0.059776 | 0.627648 | [
"s581442773",
"s330998755"
] |
u366959492 | p03835 | python | s773347265 | s908563231 | 1,794 | 271 | 2,940 | 41,948 | Accepted | Accepted | 84.89 | k,s=list(map(int,input().split()))
m=0
for x in range(k+1):
for y in range(k+1):
z=s-x-y
if z>=0 and z<=k:
m+=1
print(m)
| k,s=list(map(int,input().split()))
ans=0
for x in range(k+1):
for y in range(k+1):
z=s-x-y
if z<0:
break
if 0<=z<=k:
ans+=1
print(ans)
| 9 | 10 | 156 | 190 | k, s = list(map(int, input().split()))
m = 0
for x in range(k + 1):
for y in range(k + 1):
z = s - x - y
if z >= 0 and z <= k:
m += 1
print(m)
| k, s = list(map(int, input().split()))
ans = 0
for x in range(k + 1):
for y in range(k + 1):
z = s - x - y
if z < 0:
break
if 0 <= z <= k:
ans += 1
print(ans)
| false | 10 | [
"-m = 0",
"+ans = 0",
"- if z >= 0 and z <= k:",
"- m += 1",
"-print(m)",
"+ if z < 0:",
"+ break",
"+ if 0 <= z <= k:",
"+ ans += 1",
"+print(ans)"
] | false | 0.041678 | 0.041296 | 1.009261 | [
"s773347265",
"s908563231"
] |
u753589982 | p02994 | python | s058088627 | s895658581 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | N, L = [int(i) for i in input().split(' ')]
min_ = L
max_ = L + N -1
def eat_apple(N, L):
if L < 0:
if max_<0:
return max_
return 0
return L
print((int((min_+max_)*(max_-min_+1)/2 - eat_apple(N, L)))) | N, L = [int(i) for i in input().split()]
min_ = L
max_ = L + N -1
def eat_apple(N, L):
if max_<0:
return max_
if L < 0:
return 0
return L
print(((min_+max_)*(max_-min_+1)//2 - eat_apple(N, L))) | 13 | 13 | 250 | 235 | N, L = [int(i) for i in input().split(" ")]
min_ = L
max_ = L + N - 1
def eat_apple(N, L):
if L < 0:
if max_ < 0:
return max_
return 0
return L
print((int((min_ + max_) * (max_ - min_ + 1) / 2 - eat_apple(N, L))))
| N, L = [int(i) for i in input().split()]
min_ = L
max_ = L + N - 1
def eat_apple(N, L):
if max_ < 0:
return max_
if L < 0:
return 0
return L
print(((min_ + max_) * (max_ - min_ + 1) // 2 - eat_apple(N, L)))
| false | 0 | [
"-N, L = [int(i) for i in input().split(\" \")]",
"+N, L = [int(i) for i in input().split()]",
"+ if max_ < 0:",
"+ return max_",
"- if max_ < 0:",
"- return max_",
"-print((int((min_ + max_) * (max_ - min_ + 1) / 2 - eat_apple(N, L))))",
"+print(((min_ + max_) * (max_ - min_ + 1) // 2 - eat_apple(N, L)))"
] | false | 0.041875 | 0.04098 | 1.021841 | [
"s058088627",
"s895658581"
] |
u815763296 | p02603 | python | s530243329 | s999817085 | 93 | 30 | 9,232 | 9,196 | Accepted | Accepted | 67.74 | N = int(eval(input()))
money = 1000
M = N//2
prices = list(map(int, input().split()))
prices.append(0)
dp = [[0 for j in range(M+1)]for i in range(N+1)]
dp[0][0] = money
max_p = money
for i in range(1, N+1):
for j in range(M+1):
dp[i][j] = dp[i-1][j]
if j > 0:
for l in range(i):
x = dp[l][j-1] % prices[l] + dp[l][j-1]//prices[l]*prices[i]
if dp[i][j] < x:
dp[i][j] = x
if max_p < dp[i][j]:
max_p = dp[i][j]
print(max_p)
| N = int(eval(input()))
money = 1000
A = list(map(int, input().split()))
A.append(0)
kabu = 0
for i in range(N):
if A[i] <= A[i+1]:
buy = money//A[i]
money -= buy*A[i]
kabu += buy
if A[i] >= A[i+1]:
money += kabu*A[i]
kabu = 0
print(money) | 20 | 14 | 548 | 293 | N = int(eval(input()))
money = 1000
M = N // 2
prices = list(map(int, input().split()))
prices.append(0)
dp = [[0 for j in range(M + 1)] for i in range(N + 1)]
dp[0][0] = money
max_p = money
for i in range(1, N + 1):
for j in range(M + 1):
dp[i][j] = dp[i - 1][j]
if j > 0:
for l in range(i):
x = dp[l][j - 1] % prices[l] + dp[l][j - 1] // prices[l] * prices[i]
if dp[i][j] < x:
dp[i][j] = x
if max_p < dp[i][j]:
max_p = dp[i][j]
print(max_p)
| N = int(eval(input()))
money = 1000
A = list(map(int, input().split()))
A.append(0)
kabu = 0
for i in range(N):
if A[i] <= A[i + 1]:
buy = money // A[i]
money -= buy * A[i]
kabu += buy
if A[i] >= A[i + 1]:
money += kabu * A[i]
kabu = 0
print(money)
| false | 30 | [
"-M = N // 2",
"-prices = list(map(int, input().split()))",
"-prices.append(0)",
"-dp = [[0 for j in range(M + 1)] for i in range(N + 1)]",
"-dp[0][0] = money",
"-max_p = money",
"-for i in range(1, N + 1):",
"- for j in range(M + 1):",
"- dp[i][j] = dp[i - 1][j]",
"- if j > 0:",
"- for l in range(i):",
"- x = dp[l][j - 1] % prices[l] + dp[l][j - 1] // prices[l] * prices[i]",
"- if dp[i][j] < x:",
"- dp[i][j] = x",
"- if max_p < dp[i][j]:",
"- max_p = dp[i][j]",
"-print(max_p)",
"+A = list(map(int, input().split()))",
"+A.append(0)",
"+kabu = 0",
"+for i in range(N):",
"+ if A[i] <= A[i + 1]:",
"+ buy = money // A[i]",
"+ money -= buy * A[i]",
"+ kabu += buy",
"+ if A[i] >= A[i + 1]:",
"+ money += kabu * A[i]",
"+ kabu = 0",
"+print(money)"
] | false | 0.037071 | 0.046029 | 0.805389 | [
"s530243329",
"s999817085"
] |
u440566786 | p02913 | python | s349674305 | s648540674 | 1,038 | 955 | 51,164 | 53,636 | Accepted | Accepted | 8 | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
class SuffixArray:
"""
construct:
suffix array: O(N(logN)^2)
lcp array: O(N)
sparse table: O(NlogN)
query:
get_lcp: O(1)
"""
def __init__(self, s):
"""
s: str
"""
self.__s=s
self.__n=len(s)
self.__suffix_array()
self.__lcp_array()
self.__sparse_table()
# suffix array
def __suffix_array(self):
s=self.__s; n=self.__n
# initialize
sa=list(range(n))
rank=[ord(s[i]) for i in range(n)]
tmp=[0]*n
k=1
cmp_key=lambda i:(rank[i],rank[i+k] if i+k<n else -1)
# iterate
while(k<=n):
sa.sort(key=cmp_key)
tmp[sa[0]]=0
for i in range(1,n):
tmp[sa[i]]=tmp[sa[i-1]]+(cmp_key(sa[i-1])<cmp_key(sa[i]))
rank=tmp[:]
k<<=1
self.__sa=sa
self.__rank=rank
# LCP array
def __lcp_array(self):
n=self.__n; s=self.__s;
sa=self.__sa; rank=self.__rank
lcp=[0]*n
h=0
for i in range(n):
j=sa[rank[i]-1]
if h > 0: h -= 1
while j+h<n and i+h<n and s[j+h]==s[i+h]: h+=1
lcp[rank[i]]=h
self.__lcp=lcp
# sparse table (LCPのminをとるindexを持つ)
def __sparse_table(self):
n=self.__n
logn=max(0,(n-1).bit_length())
table=[[0]*n for _ in range(logn)]
table[0]=list(range(n))
# construct
for i in range(1,logn):
for k in range(n):
if k+(1<<(i-1))>=n:
table[i][k]=table[i-1][k]
continue
if self.__lcp[table[i-1][k]]<=self.__lcp[table[i-1][k+(1<<(i-1))]]:
table[i][k]=table[i-1][k]
else:
table[i][k]=table[i-1][k+(1<<(i-1))]
self.__table=table
def get_lcp(self,a,b):
"""
a,b: int 0<=a,b<n
return LCP length between s[a:] and s[b:]
"""
if a==b: return self.__n-a
l,r=self.__rank[a],self.__rank[b]
l,r=min(l,r)+1,max(l,r)+1
if r-l==1: return self.__lcp[l]
i=(r-l-1).bit_length()-1
if self.__lcp[self.__table[i][l]]<=self.__lcp[self.__table[i][r-(1<<i)]]:
return self.__lcp[self.__table[i][l]]
else:
return self.__lcp[self.__table[i][r-(1<<i)]]
def resolve():
n=int(eval(input()))
s=eval(input())
sa=SuffixArray(s)
ans=0
for i in range(n):
for j in range(i+1,n):
ans=max(ans,min(sa.get_lcp(i,j),j-i))
print(ans)
resolve() | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
class SuffixArray(object):
"""
construct:
suffix array: O(N(logN)^2)
lcp array: O(N)
sparse table: O(NlogN)
query:
lcp: O(1)
"""
def __init__(self,s):
"""
s: str
"""
self.__s=s
self.__n=len(s)
self.__suffix_array()
self.__lcp_array()
self.__sparse_table()
# suffix array
def __suffix_array(self):
s=self.__s; n=self.__n
# initialize
sa=list(range(n))
rank=[ord(s[i]) for i in range(n)]
tmp=[0]*n
k=1
cmp_key=lambda i:(rank[i],rank[i+k] if i+k<n else -1)
# iterate
while(k<=n):
sa.sort(key=cmp_key)
tmp[sa[0]]=0
for i in range(1,n):
tmp[sa[i]]=tmp[sa[i-1]]+(cmp_key(sa[i-1])<cmp_key(sa[i]))
rank=tmp[:]
k<<=1
self.__sa=sa
self.__rank=rank
# LCP array
def __lcp_array(self):
s=self.__s; n=self.__n
sa=self.__sa; rank=self.__rank
lcp=[0]*n
h=0
for i in range(n):
j=sa[rank[i]-1]
if h>0: h-=1
while j+h<n and i+h<n and s[j+h]==s[i+h]: h+=1
lcp[rank[i]]=h
self.__lcp=lcp
# sparse table
def __sparse_table(self):
n=self.__n
logn=max(0,(n-1).bit_length())
table=[[0]*n for _ in range(logn)]
table[0]=self.__lcp[:]
# construct
from itertools import product
for i,k in product(list(range(1,logn)),list(range(n))):
if k+(1<<(i-1))>=n:
table[i][k]=table[i-1][k]
else:
table[i][k]=min(table[i-1][k],table[i-1][k+(1<<(i-1))])
self.__table=table
def lcp(self,a,b):
"""
a,b: int 0<=a,b<n
return LCP length between s[a:] and s[b:]
"""
if a==b: return self.__n-a
l,r=self.__rank[a],self.__rank[b]
l,r=min(l,r)+1,max(l,r)+1
i=max(0,(r-l-1).bit_length()-1)
table=self.__table
return min(table[i][l],table[i][r-(1<<i)])
def resolve():
n=int(eval(input()))
s=eval(input())
sa=SuffixArray(s)
ans=0
for i in range(n):
for j in range(i+1,n):
ans=max(ans,min(sa.lcp(i,j),j-i))
print(ans)
resolve() | 99 | 93 | 2,835 | 2,510 | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
class SuffixArray:
"""
construct:
suffix array: O(N(logN)^2)
lcp array: O(N)
sparse table: O(NlogN)
query:
get_lcp: O(1)
"""
def __init__(self, s):
"""
s: str
"""
self.__s = s
self.__n = len(s)
self.__suffix_array()
self.__lcp_array()
self.__sparse_table()
# suffix array
def __suffix_array(self):
s = self.__s
n = self.__n
# initialize
sa = list(range(n))
rank = [ord(s[i]) for i in range(n)]
tmp = [0] * n
k = 1
cmp_key = lambda i: (rank[i], rank[i + k] if i + k < n else -1)
# iterate
while k <= n:
sa.sort(key=cmp_key)
tmp[sa[0]] = 0
for i in range(1, n):
tmp[sa[i]] = tmp[sa[i - 1]] + (cmp_key(sa[i - 1]) < cmp_key(sa[i]))
rank = tmp[:]
k <<= 1
self.__sa = sa
self.__rank = rank
# LCP array
def __lcp_array(self):
n = self.__n
s = self.__s
sa = self.__sa
rank = self.__rank
lcp = [0] * n
h = 0
for i in range(n):
j = sa[rank[i] - 1]
if h > 0:
h -= 1
while j + h < n and i + h < n and s[j + h] == s[i + h]:
h += 1
lcp[rank[i]] = h
self.__lcp = lcp
# sparse table (LCPのminをとるindexを持つ)
def __sparse_table(self):
n = self.__n
logn = max(0, (n - 1).bit_length())
table = [[0] * n for _ in range(logn)]
table[0] = list(range(n))
# construct
for i in range(1, logn):
for k in range(n):
if k + (1 << (i - 1)) >= n:
table[i][k] = table[i - 1][k]
continue
if (
self.__lcp[table[i - 1][k]]
<= self.__lcp[table[i - 1][k + (1 << (i - 1))]]
):
table[i][k] = table[i - 1][k]
else:
table[i][k] = table[i - 1][k + (1 << (i - 1))]
self.__table = table
def get_lcp(self, a, b):
"""
a,b: int 0<=a,b<n
return LCP length between s[a:] and s[b:]
"""
if a == b:
return self.__n - a
l, r = self.__rank[a], self.__rank[b]
l, r = min(l, r) + 1, max(l, r) + 1
if r - l == 1:
return self.__lcp[l]
i = (r - l - 1).bit_length() - 1
if self.__lcp[self.__table[i][l]] <= self.__lcp[self.__table[i][r - (1 << i)]]:
return self.__lcp[self.__table[i][l]]
else:
return self.__lcp[self.__table[i][r - (1 << i)]]
def resolve():
n = int(eval(input()))
s = eval(input())
sa = SuffixArray(s)
ans = 0
for i in range(n):
for j in range(i + 1, n):
ans = max(ans, min(sa.get_lcp(i, j), j - i))
print(ans)
resolve()
| import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
class SuffixArray(object):
"""
construct:
suffix array: O(N(logN)^2)
lcp array: O(N)
sparse table: O(NlogN)
query:
lcp: O(1)
"""
def __init__(self, s):
"""
s: str
"""
self.__s = s
self.__n = len(s)
self.__suffix_array()
self.__lcp_array()
self.__sparse_table()
# suffix array
def __suffix_array(self):
s = self.__s
n = self.__n
# initialize
sa = list(range(n))
rank = [ord(s[i]) for i in range(n)]
tmp = [0] * n
k = 1
cmp_key = lambda i: (rank[i], rank[i + k] if i + k < n else -1)
# iterate
while k <= n:
sa.sort(key=cmp_key)
tmp[sa[0]] = 0
for i in range(1, n):
tmp[sa[i]] = tmp[sa[i - 1]] + (cmp_key(sa[i - 1]) < cmp_key(sa[i]))
rank = tmp[:]
k <<= 1
self.__sa = sa
self.__rank = rank
# LCP array
def __lcp_array(self):
s = self.__s
n = self.__n
sa = self.__sa
rank = self.__rank
lcp = [0] * n
h = 0
for i in range(n):
j = sa[rank[i] - 1]
if h > 0:
h -= 1
while j + h < n and i + h < n and s[j + h] == s[i + h]:
h += 1
lcp[rank[i]] = h
self.__lcp = lcp
# sparse table
def __sparse_table(self):
n = self.__n
logn = max(0, (n - 1).bit_length())
table = [[0] * n for _ in range(logn)]
table[0] = self.__lcp[:]
# construct
from itertools import product
for i, k in product(list(range(1, logn)), list(range(n))):
if k + (1 << (i - 1)) >= n:
table[i][k] = table[i - 1][k]
else:
table[i][k] = min(table[i - 1][k], table[i - 1][k + (1 << (i - 1))])
self.__table = table
def lcp(self, a, b):
"""
a,b: int 0<=a,b<n
return LCP length between s[a:] and s[b:]
"""
if a == b:
return self.__n - a
l, r = self.__rank[a], self.__rank[b]
l, r = min(l, r) + 1, max(l, r) + 1
i = max(0, (r - l - 1).bit_length() - 1)
table = self.__table
return min(table[i][l], table[i][r - (1 << i)])
def resolve():
n = int(eval(input()))
s = eval(input())
sa = SuffixArray(s)
ans = 0
for i in range(n):
for j in range(i + 1, n):
ans = max(ans, min(sa.lcp(i, j), j - i))
print(ans)
resolve()
| false | 6.060606 | [
"-class SuffixArray:",
"+class SuffixArray(object):",
"- get_lcp: O(1)",
"+ lcp: O(1)",
"+ s = self.__s",
"- s = self.__s",
"- # sparse table (LCPのminをとるindexを持つ)",
"+ # sparse table",
"- table[0] = list(range(n))",
"+ table[0] = self.__lcp[:]",
"- for i in range(1, logn):",
"- for k in range(n):",
"- if k + (1 << (i - 1)) >= n:",
"- table[i][k] = table[i - 1][k]",
"- continue",
"- if (",
"- self.__lcp[table[i - 1][k]]",
"- <= self.__lcp[table[i - 1][k + (1 << (i - 1))]]",
"- ):",
"- table[i][k] = table[i - 1][k]",
"- else:",
"- table[i][k] = table[i - 1][k + (1 << (i - 1))]",
"+ from itertools import product",
"+",
"+ for i, k in product(list(range(1, logn)), list(range(n))):",
"+ if k + (1 << (i - 1)) >= n:",
"+ table[i][k] = table[i - 1][k]",
"+ else:",
"+ table[i][k] = min(table[i - 1][k], table[i - 1][k + (1 << (i - 1))])",
"- def get_lcp(self, a, b):",
"+ def lcp(self, a, b):",
"- if r - l == 1:",
"- return self.__lcp[l]",
"- i = (r - l - 1).bit_length() - 1",
"- if self.__lcp[self.__table[i][l]] <= self.__lcp[self.__table[i][r - (1 << i)]]:",
"- return self.__lcp[self.__table[i][l]]",
"- else:",
"- return self.__lcp[self.__table[i][r - (1 << i)]]",
"+ i = max(0, (r - l - 1).bit_length() - 1)",
"+ table = self.__table",
"+ return min(table[i][l], table[i][r - (1 << i)])",
"- ans = max(ans, min(sa.get_lcp(i, j), j - i))",
"+ ans = max(ans, min(sa.lcp(i, j), j - i))"
] | false | 0.049884 | 0.047361 | 1.053258 | [
"s349674305",
"s648540674"
] |
u459215900 | p03723 | python | s104188706 | s700830100 | 1,440 | 713 | 3,188 | 2,940 | Accepted | Accepted | 50.49 | a, b, c = list(map(int, input().split()))
ans = 0
while True:
if ans > 999999:
print((-1))
break
elif a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
print(ans)
break
n_a = b/2 + c/2
n_b = a/2 + c/2
n_c = a/2 + b/2
a = n_a
b = n_b
c = n_c
ans += 1
| a, b, c = list(map(int, input().split()))
ans = 0
while True:
if ans > 999999:
print((-1))
break
elif a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
print(ans)
break
a, b, c = (b+c) // 2, (a+c) // 2, (a+b) // 2
ans += 1
| 18 | 13 | 323 | 268 | a, b, c = list(map(int, input().split()))
ans = 0
while True:
if ans > 999999:
print((-1))
break
elif a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
print(ans)
break
n_a = b / 2 + c / 2
n_b = a / 2 + c / 2
n_c = a / 2 + b / 2
a = n_a
b = n_b
c = n_c
ans += 1
| a, b, c = list(map(int, input().split()))
ans = 0
while True:
if ans > 999999:
print((-1))
break
elif a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
print(ans)
break
a, b, c = (b + c) // 2, (a + c) // 2, (a + b) // 2
ans += 1
| false | 27.777778 | [
"- n_a = b / 2 + c / 2",
"- n_b = a / 2 + c / 2",
"- n_c = a / 2 + b / 2",
"- a = n_a",
"- b = n_b",
"- c = n_c",
"+ a, b, c = (b + c) // 2, (a + c) // 2, (a + b) // 2"
] | false | 0.245058 | 0.161578 | 1.516658 | [
"s104188706",
"s700830100"
] |
u762955009 | p03013 | python | s986471018 | s868459397 | 495 | 201 | 56,664 | 11,884 | Accepted | Accepted | 59.39 | MOD = 10**9 + 7
N, M = [int(x) for x in input().split()]
a = set([int(eval(input())) for i in range(M)])
dp = [0]*(N + 1)
dp[0] = 1
for step in range(N):
if step in a:
continue
for width in [1, 2]:
to = step + width
if to <= N and not to in a:
dp[to] = (dp[to] + dp[step]) % MOD
print((dp[N])) | MOD = 10**9 + 7
N, M = [int(x) for x in input().split()]
a = set()
for i in range(M):
a.add(int(eval(input())))
dp = [0]*(N + 1)
dp[0] = 1
for step in range(N):
if not step in a:
for width in [1, 2]:
to = step + width
if to <= N and not to in a:
dp[to] = (dp[to] + dp[step]) % MOD
print((dp[N])) | 15 | 16 | 345 | 360 | MOD = 10**9 + 7
N, M = [int(x) for x in input().split()]
a = set([int(eval(input())) for i in range(M)])
dp = [0] * (N + 1)
dp[0] = 1
for step in range(N):
if step in a:
continue
for width in [1, 2]:
to = step + width
if to <= N and not to in a:
dp[to] = (dp[to] + dp[step]) % MOD
print((dp[N]))
| MOD = 10**9 + 7
N, M = [int(x) for x in input().split()]
a = set()
for i in range(M):
a.add(int(eval(input())))
dp = [0] * (N + 1)
dp[0] = 1
for step in range(N):
if not step in a:
for width in [1, 2]:
to = step + width
if to <= N and not to in a:
dp[to] = (dp[to] + dp[step]) % MOD
print((dp[N]))
| false | 6.25 | [
"-a = set([int(eval(input())) for i in range(M)])",
"+a = set()",
"+for i in range(M):",
"+ a.add(int(eval(input())))",
"- if step in a:",
"- continue",
"- for width in [1, 2]:",
"- to = step + width",
"- if to <= N and not to in a:",
"- dp[to] = (dp[to] + dp[step]) % MOD",
"+ if not step in a:",
"+ for width in [1, 2]:",
"+ to = step + width",
"+ if to <= N and not to in a:",
"+ dp[to] = (dp[to] + dp[step]) % MOD"
] | false | 0.04355 | 0.04792 | 0.908817 | [
"s986471018",
"s868459397"
] |
u345966487 | p03165 | python | s820229362 | s079357821 | 1,693 | 336 | 120,540 | 153,604 | Accepted | Accepted | 80.15 | import bisect
import collections
import sys
sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().rstrip()
T = readline().rstrip()
if len(S) < len(T):
S, T = T, S
def pretty(ss):
buf = []
while ss is not None:
s, ss = ss
buf.append(s)
buf.reverse()
return "".join(buf)
def solve():
index = collections.defaultdict(list)
for i, sc in enumerate(S):
index[sc].append(i)
dp = [None] * len(T)
for i, tc in enumerate(T):
if tc not in index:
continue
dn = list(dp)
ii = index[tc]
if dn[0] is None or dn[0][0] > ii[0]:
dn[0] = (ii[0], [chr(tc), None])
for j in range(1, len(T)):
if dp[j - 1] is None:
break
k = bisect.bisect_right(ii, dp[j - 1][0])
if k < len(ii) and (dn[j] is None or dn[j][0] > ii[k]):
dn[j] = (ii[k], [chr(tc), dp[j - 1][1]])
dp = dn
for i in range(len(T) - 1, -1, -1):
if dp[i] is not None:
return pretty(dp[i][1])
return ""
if __name__ == "__main__":
print((solve()))
| import numpy as np
S = np.array([ord(i) for i in eval(input())], dtype=int)
T = np.array([ord(i) for i in eval(input())], dtype=int)
NS = len(S)
NT = len(T)
equal = np.equal.outer(S, T).astype(int)
dp = [np.zeros(NT + 1, dtype=int)]
for i in range(NS):
x = dp[-1].copy()
ndp = x.copy()
ndp[1:] = np.maximum(x[:-1] + equal[i], ndp[1:])
np.maximum.accumulate(ndp, out=ndp)
dp.append(ndp)
ans = []
i, j = NS, NT
while i > 0 and j > 0:
if S[i - 1] == T[j - 1]:
ans.append(chr(S[i - 1]))
i -= 1
j -= 1
continue
if dp[i][j] == dp[i - 1][j]:
i -= 1
else:
j -= 1
ans.reverse()
print(("".join(ans)))
| 51 | 31 | 1,267 | 691 | import bisect
import collections
import sys
sys.setrecursionlimit(10**8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().rstrip()
T = readline().rstrip()
if len(S) < len(T):
S, T = T, S
def pretty(ss):
buf = []
while ss is not None:
s, ss = ss
buf.append(s)
buf.reverse()
return "".join(buf)
def solve():
index = collections.defaultdict(list)
for i, sc in enumerate(S):
index[sc].append(i)
dp = [None] * len(T)
for i, tc in enumerate(T):
if tc not in index:
continue
dn = list(dp)
ii = index[tc]
if dn[0] is None or dn[0][0] > ii[0]:
dn[0] = (ii[0], [chr(tc), None])
for j in range(1, len(T)):
if dp[j - 1] is None:
break
k = bisect.bisect_right(ii, dp[j - 1][0])
if k < len(ii) and (dn[j] is None or dn[j][0] > ii[k]):
dn[j] = (ii[k], [chr(tc), dp[j - 1][1]])
dp = dn
for i in range(len(T) - 1, -1, -1):
if dp[i] is not None:
return pretty(dp[i][1])
return ""
if __name__ == "__main__":
print((solve()))
| import numpy as np
S = np.array([ord(i) for i in eval(input())], dtype=int)
T = np.array([ord(i) for i in eval(input())], dtype=int)
NS = len(S)
NT = len(T)
equal = np.equal.outer(S, T).astype(int)
dp = [np.zeros(NT + 1, dtype=int)]
for i in range(NS):
x = dp[-1].copy()
ndp = x.copy()
ndp[1:] = np.maximum(x[:-1] + equal[i], ndp[1:])
np.maximum.accumulate(ndp, out=ndp)
dp.append(ndp)
ans = []
i, j = NS, NT
while i > 0 and j > 0:
if S[i - 1] == T[j - 1]:
ans.append(chr(S[i - 1]))
i -= 1
j -= 1
continue
if dp[i][j] == dp[i - 1][j]:
i -= 1
else:
j -= 1
ans.reverse()
print(("".join(ans)))
| false | 39.215686 | [
"-import bisect",
"-import collections",
"-import sys",
"+import numpy as np",
"-sys.setrecursionlimit(10**8)",
"-read = sys.stdin.buffer.read",
"-readline = sys.stdin.buffer.readline",
"-readlines = sys.stdin.buffer.readlines",
"-S = readline().rstrip()",
"-T = readline().rstrip()",
"-if len(S) < len(T):",
"- S, T = T, S",
"-",
"-",
"-def pretty(ss):",
"- buf = []",
"- while ss is not None:",
"- s, ss = ss",
"- buf.append(s)",
"- buf.reverse()",
"- return \"\".join(buf)",
"-",
"-",
"-def solve():",
"- index = collections.defaultdict(list)",
"- for i, sc in enumerate(S):",
"- index[sc].append(i)",
"- dp = [None] * len(T)",
"- for i, tc in enumerate(T):",
"- if tc not in index:",
"- continue",
"- dn = list(dp)",
"- ii = index[tc]",
"- if dn[0] is None or dn[0][0] > ii[0]:",
"- dn[0] = (ii[0], [chr(tc), None])",
"- for j in range(1, len(T)):",
"- if dp[j - 1] is None:",
"- break",
"- k = bisect.bisect_right(ii, dp[j - 1][0])",
"- if k < len(ii) and (dn[j] is None or dn[j][0] > ii[k]):",
"- dn[j] = (ii[k], [chr(tc), dp[j - 1][1]])",
"- dp = dn",
"- for i in range(len(T) - 1, -1, -1):",
"- if dp[i] is not None:",
"- return pretty(dp[i][1])",
"- return \"\"",
"-",
"-",
"-if __name__ == \"__main__\":",
"- print((solve()))",
"+S = np.array([ord(i) for i in eval(input())], dtype=int)",
"+T = np.array([ord(i) for i in eval(input())], dtype=int)",
"+NS = len(S)",
"+NT = len(T)",
"+equal = np.equal.outer(S, T).astype(int)",
"+dp = [np.zeros(NT + 1, dtype=int)]",
"+for i in range(NS):",
"+ x = dp[-1].copy()",
"+ ndp = x.copy()",
"+ ndp[1:] = np.maximum(x[:-1] + equal[i], ndp[1:])",
"+ np.maximum.accumulate(ndp, out=ndp)",
"+ dp.append(ndp)",
"+ans = []",
"+i, j = NS, NT",
"+while i > 0 and j > 0:",
"+ if S[i - 1] == T[j - 1]:",
"+ ans.append(chr(S[i - 1]))",
"+ i -= 1",
"+ j -= 1",
"+ continue",
"+ if dp[i][j] == dp[i - 1][j]:",
"+ i -= 1",
"+ else:",
"+ j -= 1",
"+ans.reverse()",
"+print((\"\".join(ans)))"
] | false | 0.037353 | 0.219284 | 0.170341 | [
"s820229362",
"s079357821"
] |
u263830634 | p03310 | python | s222956637 | s935787493 | 867 | 257 | 27,468 | 41,416 | Accepted | Accepted | 70.36 | N = int(eval(input()))
#累積和で受け取る
A = [0] * N
S = 0
for i, a in enumerate(input().split()):
S += int(a)
A[i] = S
answer = S
#indexは最後に回収する番号
B = 0
D = 0
for C in range(1, N - 2):
D = max(D, C + 1)
SB = A[B]
SC = A[C] - A[B]
SD = A[D] - A[C]
SE = S - A[D]
left_score = abs(SB - SC)
#BCの境界の調整
while True:
B_ = B + 1
SB_ = A[B_]
SC_ = A[C] - SB_
x = abs(SB_ - SC_)
if left_score > x:
B, SB, SC, left_score = B_, SB_, SC_, x
continue
break
right_score = abs(SE - SD)
while True:
D_ = D + 1
SD_ = A[D_] - A[C]
SE_ = S - A[D_]
x = abs(SD_ - SE_)
if right_score > x:
D, SD, SE, right_score = D_, SD_, SE_, x
continue
break
score = max(SB, SC, SD, SE) - min(SB, SC, SD, SE)
answer = min(score, answer)
print (answer)
| import numpy as np
N = int(eval(input()))
A = np.zeros(N + 2, dtype = np.int64)
A[1:-1] = input().split()
np.cumsum(A, out = A)
total = A[-1]
A[-1] = 10 ** 18
left = np.searchsorted(A, A/2)
P1 = A[left - 1]
P2 = A[left]
Q1, Q2 = A - P1, A - P2
np.maximum(P1, Q2, out = P1)
np.minimum(P2, Q1, out = P2)
P, Q = P1, P2
right = np.searchsorted(A, (total + A)/2)
R1 = A[right - 1] - A
R2 = A[right] - A
S1 = total - A[right - 1]
S2 = total - A[right]
np.maximum(R1, S2, out = R1)
np.minimum(R2, S1, out = R2)
R, S = R1, R2
PQRS = np.vstack([P, Q, R, S])
x = np.max(PQRS, axis = 0) - np.min(PQRS, axis = 0)
answer = (x[1: -1].min())
print (answer) | 47 | 31 | 955 | 670 | N = int(eval(input()))
# 累積和で受け取る
A = [0] * N
S = 0
for i, a in enumerate(input().split()):
S += int(a)
A[i] = S
answer = S
# indexは最後に回収する番号
B = 0
D = 0
for C in range(1, N - 2):
D = max(D, C + 1)
SB = A[B]
SC = A[C] - A[B]
SD = A[D] - A[C]
SE = S - A[D]
left_score = abs(SB - SC)
# BCの境界の調整
while True:
B_ = B + 1
SB_ = A[B_]
SC_ = A[C] - SB_
x = abs(SB_ - SC_)
if left_score > x:
B, SB, SC, left_score = B_, SB_, SC_, x
continue
break
right_score = abs(SE - SD)
while True:
D_ = D + 1
SD_ = A[D_] - A[C]
SE_ = S - A[D_]
x = abs(SD_ - SE_)
if right_score > x:
D, SD, SE, right_score = D_, SD_, SE_, x
continue
break
score = max(SB, SC, SD, SE) - min(SB, SC, SD, SE)
answer = min(score, answer)
print(answer)
| import numpy as np
N = int(eval(input()))
A = np.zeros(N + 2, dtype=np.int64)
A[1:-1] = input().split()
np.cumsum(A, out=A)
total = A[-1]
A[-1] = 10**18
left = np.searchsorted(A, A / 2)
P1 = A[left - 1]
P2 = A[left]
Q1, Q2 = A - P1, A - P2
np.maximum(P1, Q2, out=P1)
np.minimum(P2, Q1, out=P2)
P, Q = P1, P2
right = np.searchsorted(A, (total + A) / 2)
R1 = A[right - 1] - A
R2 = A[right] - A
S1 = total - A[right - 1]
S2 = total - A[right]
np.maximum(R1, S2, out=R1)
np.minimum(R2, S1, out=R2)
R, S = R1, R2
PQRS = np.vstack([P, Q, R, S])
x = np.max(PQRS, axis=0) - np.min(PQRS, axis=0)
answer = x[1:-1].min()
print(answer)
| false | 34.042553 | [
"+import numpy as np",
"+",
"-# 累積和で受け取る",
"-A = [0] * N",
"-S = 0",
"-for i, a in enumerate(input().split()):",
"- S += int(a)",
"- A[i] = S",
"-answer = S",
"-# indexは最後に回収する番号",
"-B = 0",
"-D = 0",
"-for C in range(1, N - 2):",
"- D = max(D, C + 1)",
"- SB = A[B]",
"- SC = A[C] - A[B]",
"- SD = A[D] - A[C]",
"- SE = S - A[D]",
"- left_score = abs(SB - SC)",
"- # BCの境界の調整",
"- while True:",
"- B_ = B + 1",
"- SB_ = A[B_]",
"- SC_ = A[C] - SB_",
"- x = abs(SB_ - SC_)",
"- if left_score > x:",
"- B, SB, SC, left_score = B_, SB_, SC_, x",
"- continue",
"- break",
"- right_score = abs(SE - SD)",
"- while True:",
"- D_ = D + 1",
"- SD_ = A[D_] - A[C]",
"- SE_ = S - A[D_]",
"- x = abs(SD_ - SE_)",
"- if right_score > x:",
"- D, SD, SE, right_score = D_, SD_, SE_, x",
"- continue",
"- break",
"- score = max(SB, SC, SD, SE) - min(SB, SC, SD, SE)",
"- answer = min(score, answer)",
"+A = np.zeros(N + 2, dtype=np.int64)",
"+A[1:-1] = input().split()",
"+np.cumsum(A, out=A)",
"+total = A[-1]",
"+A[-1] = 10**18",
"+left = np.searchsorted(A, A / 2)",
"+P1 = A[left - 1]",
"+P2 = A[left]",
"+Q1, Q2 = A - P1, A - P2",
"+np.maximum(P1, Q2, out=P1)",
"+np.minimum(P2, Q1, out=P2)",
"+P, Q = P1, P2",
"+right = np.searchsorted(A, (total + A) / 2)",
"+R1 = A[right - 1] - A",
"+R2 = A[right] - A",
"+S1 = total - A[right - 1]",
"+S2 = total - A[right]",
"+np.maximum(R1, S2, out=R1)",
"+np.minimum(R2, S1, out=R2)",
"+R, S = R1, R2",
"+PQRS = np.vstack([P, Q, R, S])",
"+x = np.max(PQRS, axis=0) - np.min(PQRS, axis=0)",
"+answer = x[1:-1].min()"
] | false | 0.041562 | 0.201595 | 0.206164 | [
"s222956637",
"s935787493"
] |
u537782349 | p04001 | python | s326406544 | s947995854 | 21 | 18 | 3,316 | 3,064 | Accepted | Accepted | 14.29 | def f(a, b, le, tf):
b[le] = tf
if le == len(b)-1:
t = ""
s1 = 0
for i in range(len(b)):
t += a[i]
if b[i] == 1:
s1 += int(t)
t = ""
t += a[len(b)]
s1 += int(t)
return s1
else:
return f(a, b, le+1, 0) + f(a, b, le+1, 1)
aa = eval(input())
bb = [0] * (len(aa)-1)
if len(aa) == 1:
print(aa)
else:
print((f(aa, bb, 0, 0) + f(aa, bb, 0, 1))) | def clc(a, b, c, p, t):
if c == 0:
b = a[0]
return clc(a, b, c + 1, True, t) + clc(a, b, c + 1, False, t)
elif c == len(a)-1:
if p:
return t + int(b) + int(a[c])
else:
return t + int(b + a[c])
else:
if p:
t += int(b)
b = a[c]
else:
b += a[c]
return clc(a, b, c + 1, True, t) + clc(a, b, c + 1, False, t)
s = eval(input())
print((clc(s, "", 0, True, 0) if len(s) != 1 else s))
| 23 | 20 | 485 | 517 | def f(a, b, le, tf):
b[le] = tf
if le == len(b) - 1:
t = ""
s1 = 0
for i in range(len(b)):
t += a[i]
if b[i] == 1:
s1 += int(t)
t = ""
t += a[len(b)]
s1 += int(t)
return s1
else:
return f(a, b, le + 1, 0) + f(a, b, le + 1, 1)
aa = eval(input())
bb = [0] * (len(aa) - 1)
if len(aa) == 1:
print(aa)
else:
print((f(aa, bb, 0, 0) + f(aa, bb, 0, 1)))
| def clc(a, b, c, p, t):
if c == 0:
b = a[0]
return clc(a, b, c + 1, True, t) + clc(a, b, c + 1, False, t)
elif c == len(a) - 1:
if p:
return t + int(b) + int(a[c])
else:
return t + int(b + a[c])
else:
if p:
t += int(b)
b = a[c]
else:
b += a[c]
return clc(a, b, c + 1, True, t) + clc(a, b, c + 1, False, t)
s = eval(input())
print((clc(s, "", 0, True, 0) if len(s) != 1 else s))
| false | 13.043478 | [
"-def f(a, b, le, tf):",
"- b[le] = tf",
"- if le == len(b) - 1:",
"- t = \"\"",
"- s1 = 0",
"- for i in range(len(b)):",
"- t += a[i]",
"- if b[i] == 1:",
"- s1 += int(t)",
"- t = \"\"",
"- t += a[len(b)]",
"- s1 += int(t)",
"- return s1",
"+def clc(a, b, c, p, t):",
"+ if c == 0:",
"+ b = a[0]",
"+ return clc(a, b, c + 1, True, t) + clc(a, b, c + 1, False, t)",
"+ elif c == len(a) - 1:",
"+ if p:",
"+ return t + int(b) + int(a[c])",
"+ else:",
"+ return t + int(b + a[c])",
"- return f(a, b, le + 1, 0) + f(a, b, le + 1, 1)",
"+ if p:",
"+ t += int(b)",
"+ b = a[c]",
"+ else:",
"+ b += a[c]",
"+ return clc(a, b, c + 1, True, t) + clc(a, b, c + 1, False, t)",
"-aa = eval(input())",
"-bb = [0] * (len(aa) - 1)",
"-if len(aa) == 1:",
"- print(aa)",
"-else:",
"- print((f(aa, bb, 0, 0) + f(aa, bb, 0, 1)))",
"+s = eval(input())",
"+print((clc(s, \"\", 0, True, 0) if len(s) != 1 else s))"
] | false | 0.048221 | 0.039616 | 1.217232 | [
"s326406544",
"s947995854"
] |
u310678820 | p02692 | python | s167346733 | s629009011 | 293 | 206 | 92,664 | 95,984 | Accepted | Accepted | 29.69 | def solve():
ans = []
for i, (x, y) in enumerate(s):
if num[x]>num[y]: x, y = y, x
if num[x]==num[y] and i < n-1:
if y == s[i+1][0] or y == s[i+1][1]:
x, y = y, x
num[x]+=1
num[y]-=1
ans.append(x)
if num[y]<0: return False
return ans
from collections import defaultdict
import sys
n, a, b, c = map(int, input().split())
num = defaultdict(int)
s = [input() for _ in range(n)]
num['A'] = a
num['B'] = b
num['C'] = c
id = ['A', 'B', 'C']
ans = solve()
if ans:
print('Yes')
print(*ans, sep = '\n')
else:
print('No')
| def solve():
ans = []
for i, (x, y) in enumerate(s):
if num[x]>num[y]: x, y = y, x
if num[x]==num[y] and i < n-1:
if y == s[i+1][0] or y == s[i+1][1]:
x, y = y, x
num[x]+=1
num[y]-=1
ans.append(x)
if num[y]<0: return False
return ans
from collections import defaultdict
n, a, b, c = map(int, input().split())
s = [input() for _ in range(n)]
num = defaultdict(int)
num['A'] = a
num['B'] = b
num['C'] = c
ans = solve()
if ans:
print('Yes')
print(*ans, sep = '\n')
else:
print('No')
| 27 | 25 | 637 | 603 | def solve():
ans = []
for i, (x, y) in enumerate(s):
if num[x] > num[y]:
x, y = y, x
if num[x] == num[y] and i < n - 1:
if y == s[i + 1][0] or y == s[i + 1][1]:
x, y = y, x
num[x] += 1
num[y] -= 1
ans.append(x)
if num[y] < 0:
return False
return ans
from collections import defaultdict
import sys
n, a, b, c = map(int, input().split())
num = defaultdict(int)
s = [input() for _ in range(n)]
num["A"] = a
num["B"] = b
num["C"] = c
id = ["A", "B", "C"]
ans = solve()
if ans:
print("Yes")
print(*ans, sep="\n")
else:
print("No")
| def solve():
ans = []
for i, (x, y) in enumerate(s):
if num[x] > num[y]:
x, y = y, x
if num[x] == num[y] and i < n - 1:
if y == s[i + 1][0] or y == s[i + 1][1]:
x, y = y, x
num[x] += 1
num[y] -= 1
ans.append(x)
if num[y] < 0:
return False
return ans
from collections import defaultdict
n, a, b, c = map(int, input().split())
s = [input() for _ in range(n)]
num = defaultdict(int)
num["A"] = a
num["B"] = b
num["C"] = c
ans = solve()
if ans:
print("Yes")
print(*ans, sep="\n")
else:
print("No")
| false | 7.407407 | [
"-import sys",
"+s = [input() for _ in range(n)]",
"-s = [input() for _ in range(n)]",
"-id = [\"A\", \"B\", \"C\"]"
] | false | 0.046638 | 0.007665 | 6.084299 | [
"s167346733",
"s629009011"
] |
u667458133 | p03625 | python | s583404371 | s694725878 | 1,536 | 96 | 14,252 | 18,600 | Accepted | Accepted | 93.75 | N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
A.reverse()
flag = 0
result = [0, 0]
while len(A) >= 2 and flag < 2:
N = A.pop(0)
if N == A[0]:
result[flag] = N
del A[0]
flag += 1
print((result[0]*result[1]))
| import collections
N = int(eval(input()))
A = list(map(int, input().split()))
a = collections.Counter(A)
array = [0, 0]
for i in a:
if a[i] >= 4:
array += [i, i]
elif a[i] >= 2:
array.append(i)
array.sort()
array.reverse()
print((array[0]*array[1]))
| 15 | 16 | 269 | 284 | N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
A.reverse()
flag = 0
result = [0, 0]
while len(A) >= 2 and flag < 2:
N = A.pop(0)
if N == A[0]:
result[flag] = N
del A[0]
flag += 1
print((result[0] * result[1]))
| import collections
N = int(eval(input()))
A = list(map(int, input().split()))
a = collections.Counter(A)
array = [0, 0]
for i in a:
if a[i] >= 4:
array += [i, i]
elif a[i] >= 2:
array.append(i)
array.sort()
array.reverse()
print((array[0] * array[1]))
| false | 6.25 | [
"+import collections",
"+",
"-A.sort()",
"-A.reverse()",
"-flag = 0",
"-result = [0, 0]",
"-while len(A) >= 2 and flag < 2:",
"- N = A.pop(0)",
"- if N == A[0]:",
"- result[flag] = N",
"- del A[0]",
"- flag += 1",
"-print((result[0] * result[1]))",
"+a = collections.Counter(A)",
"+array = [0, 0]",
"+for i in a:",
"+ if a[i] >= 4:",
"+ array += [i, i]",
"+ elif a[i] >= 2:",
"+ array.append(i)",
"+array.sort()",
"+array.reverse()",
"+print((array[0] * array[1]))"
] | false | 0.082242 | 0.036828 | 2.233128 | [
"s583404371",
"s694725878"
] |
u879870653 | p03017 | python | s372267677 | s660764630 | 49 | 19 | 3,572 | 3,572 | Accepted | Accepted | 61.22 | N,a,b,c,d = list(map(int,input().split()))
S = eval(input())
a -= 1
b -= 1
c -= 1
d -= 1
if c < d :
if (S[b:d+1].count("##") == 0) and (S[a:c+1].count("##") == 0) :
ans = "Yes"
else :
ans = "No"
else :
if (S[b:d+1].count("##") == 0) and (S[a:c+1].count("##") == 0) :
flg1 = 1
else :
flg1 = 0
if S[a:d+1].count("...") >= 1 :
flg2 = 1
else :
flg2 = 0
for i in range(b,d+1) :
if (S[i-1]+S[i]+S[i+1] == "...") :
flg3 = 1
break
else :
flg3 = 0
if flg1*flg3 :
ans = "Yes"
else :
ans = "No"
print(ans)
| N,a,b,c,d = list(map(int,input().split()))
S = eval(input())
a -= 1
b -= 1
c -= 1
d -= 1
flg1 = S[a:c+1].count("##")
flg2 = S[b:d+1].count("##")
flg3 = S[b-1:d+2].count("...")
if c < d :
if flg1 + flg2 == 0 :
ans = "Yes"
else :
ans = "No"
else :
if (flg1 + flg2 == 0) and flg3 :
ans = "Yes"
else :
ans = "No"
print(ans) | 39 | 24 | 700 | 382 | N, a, b, c, d = list(map(int, input().split()))
S = eval(input())
a -= 1
b -= 1
c -= 1
d -= 1
if c < d:
if (S[b : d + 1].count("##") == 0) and (S[a : c + 1].count("##") == 0):
ans = "Yes"
else:
ans = "No"
else:
if (S[b : d + 1].count("##") == 0) and (S[a : c + 1].count("##") == 0):
flg1 = 1
else:
flg1 = 0
if S[a : d + 1].count("...") >= 1:
flg2 = 1
else:
flg2 = 0
for i in range(b, d + 1):
if S[i - 1] + S[i] + S[i + 1] == "...":
flg3 = 1
break
else:
flg3 = 0
if flg1 * flg3:
ans = "Yes"
else:
ans = "No"
print(ans)
| N, a, b, c, d = list(map(int, input().split()))
S = eval(input())
a -= 1
b -= 1
c -= 1
d -= 1
flg1 = S[a : c + 1].count("##")
flg2 = S[b : d + 1].count("##")
flg3 = S[b - 1 : d + 2].count("...")
if c < d:
if flg1 + flg2 == 0:
ans = "Yes"
else:
ans = "No"
else:
if (flg1 + flg2 == 0) and flg3:
ans = "Yes"
else:
ans = "No"
print(ans)
| false | 38.461538 | [
"+flg1 = S[a : c + 1].count(\"##\")",
"+flg2 = S[b : d + 1].count(\"##\")",
"+flg3 = S[b - 1 : d + 2].count(\"...\")",
"- if (S[b : d + 1].count(\"##\") == 0) and (S[a : c + 1].count(\"##\") == 0):",
"+ if flg1 + flg2 == 0:",
"- if (S[b : d + 1].count(\"##\") == 0) and (S[a : c + 1].count(\"##\") == 0):",
"- flg1 = 1",
"- else:",
"- flg1 = 0",
"- if S[a : d + 1].count(\"...\") >= 1:",
"- flg2 = 1",
"- else:",
"- flg2 = 0",
"- for i in range(b, d + 1):",
"- if S[i - 1] + S[i] + S[i + 1] == \"...\":",
"- flg3 = 1",
"- break",
"- else:",
"- flg3 = 0",
"- if flg1 * flg3:",
"+ if (flg1 + flg2 == 0) and flg3:"
] | false | 0.132956 | 0.040351 | 3.295036 | [
"s372267677",
"s660764630"
] |
u670180528 | p04000 | python | s987177343 | s135784553 | 1,077 | 821 | 131,432 | 111,136 | Accepted | Accepted | 23.77 | from collections import Counter as C;H,W,N,*L=list(map(int,open(0).read().split()));K=[];M=[(H-2)*(W-2)]+[0]*9
for a,b in zip(*[iter(L)]*2):
for c in range(9):
x=b-c//3;y=a-c%3
if H-1>y>0<x<W-1:K+=[y*W+x]
for k,v in list(C(list(C(K).values())).items()):M[0]-=v;M[k]+=v
print((*M)) | from collections import Counter as C;r=list(range(3))
def s():
H,W,N,*L=list(map(int,open(0).read().split()));D={};M=[(H-2)*(W-2)]+[0]*9
for a,b in zip(*[iter(L)]*2):
for x in r:
for y in r:
if H-1>a-y>0<b-x<W-1:
t=(a-y)*W+b-x
D[t]=D.get(t,0)+1
for k,v in list(C(list(D.values())).items()):M[0]-=v;M[k]+=v
print((*M))
if __name__=="__main__":s() | 7 | 12 | 271 | 353 | from collections import Counter as C
H, W, N, *L = list(map(int, open(0).read().split()))
K = []
M = [(H - 2) * (W - 2)] + [0] * 9
for a, b in zip(*[iter(L)] * 2):
for c in range(9):
x = b - c // 3
y = a - c % 3
if H - 1 > y > 0 < x < W - 1:
K += [y * W + x]
for k, v in list(C(list(C(K).values())).items()):
M[0] -= v
M[k] += v
print((*M))
| from collections import Counter as C
r = list(range(3))
def s():
H, W, N, *L = list(map(int, open(0).read().split()))
D = {}
M = [(H - 2) * (W - 2)] + [0] * 9
for a, b in zip(*[iter(L)] * 2):
for x in r:
for y in r:
if H - 1 > a - y > 0 < b - x < W - 1:
t = (a - y) * W + b - x
D[t] = D.get(t, 0) + 1
for k, v in list(C(list(D.values())).items()):
M[0] -= v
M[k] += v
print((*M))
if __name__ == "__main__":
s()
| false | 41.666667 | [
"-H, W, N, *L = list(map(int, open(0).read().split()))",
"-K = []",
"-M = [(H - 2) * (W - 2)] + [0] * 9",
"-for a, b in zip(*[iter(L)] * 2):",
"- for c in range(9):",
"- x = b - c // 3",
"- y = a - c % 3",
"- if H - 1 > y > 0 < x < W - 1:",
"- K += [y * W + x]",
"-for k, v in list(C(list(C(K).values())).items()):",
"- M[0] -= v",
"- M[k] += v",
"-print((*M))",
"+r = list(range(3))",
"+",
"+",
"+def s():",
"+ H, W, N, *L = list(map(int, open(0).read().split()))",
"+ D = {}",
"+ M = [(H - 2) * (W - 2)] + [0] * 9",
"+ for a, b in zip(*[iter(L)] * 2):",
"+ for x in r:",
"+ for y in r:",
"+ if H - 1 > a - y > 0 < b - x < W - 1:",
"+ t = (a - y) * W + b - x",
"+ D[t] = D.get(t, 0) + 1",
"+ for k, v in list(C(list(D.values())).items()):",
"+ M[0] -= v",
"+ M[k] += v",
"+ print((*M))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ s()"
] | false | 0.036574 | 0.038406 | 0.952315 | [
"s987177343",
"s135784553"
] |
u782930273 | p02708 | python | s821876063 | s428102616 | 119 | 25 | 9,132 | 9,172 | Accepted | Accepted | 78.99 | N, K = list(map(int, input().split()))
ans = 0
for i in range(K, N + 2):
max_num = i * (N + N + 1 - i) // 2
min_num = i * (0 + i - 1) // 2
ans += max_num - min_num + 1
print((ans % (10**9 + 7))) | N, K = list(map(int, input().split()))
ans = (K - N - 2) * (2 * K * K - K * (N + 2) - N * N - N - 6) // 6
print((ans % (10**9 + 7))) | 9 | 3 | 208 | 126 | N, K = list(map(int, input().split()))
ans = 0
for i in range(K, N + 2):
max_num = i * (N + N + 1 - i) // 2
min_num = i * (0 + i - 1) // 2
ans += max_num - min_num + 1
print((ans % (10**9 + 7)))
| N, K = list(map(int, input().split()))
ans = (K - N - 2) * (2 * K * K - K * (N + 2) - N * N - N - 6) // 6
print((ans % (10**9 + 7)))
| false | 66.666667 | [
"-ans = 0",
"-for i in range(K, N + 2):",
"- max_num = i * (N + N + 1 - i) // 2",
"- min_num = i * (0 + i - 1) // 2",
"- ans += max_num - min_num + 1",
"+ans = (K - N - 2) * (2 * K * K - K * (N + 2) - N * N - N - 6) // 6"
] | false | 0.07397 | 0.052312 | 1.414033 | [
"s821876063",
"s428102616"
] |
u380524497 | p03045 | python | s824223498 | s990663776 | 344 | 247 | 5,936 | 32,428 | Accepted | Accepted | 28.2 | import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, size):
self.parent = [-1] * size
self.rank = [1] * size
self.groups = size
def get_root(self, node):
parent = self.parent[node]
if parent == -1:
root = node
else:
root = self.get_root(parent)
self.parent[node] = root # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく
return root
def unite(self, node1, node2):
main_root = self.get_root(node1)
sub_root = self.get_root(node2)
if main_root == sub_root:
return
if self.rank[main_root] < self.rank[sub_root]: # rankの大きい方をmain_rootにする
main_root, sub_root = sub_root, main_root
self.parent[sub_root] = main_root
self.rank[main_root] += self.rank[sub_root]
self.groups -= 1
n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
x, y, z = list(map(int, input().split()))
x -= 1
y -= 1
uf.unite(x, y)
print((uf.groups))
| class UnionFind:
def __init__(self, size):
self.parent = [-1] * size
self.rank = [1] * size
self.groups = size
def get_root(self, node):
parent = self.parent[node]
if parent == -1:
root = node
else:
root = self.get_root(parent)
self.parent[node] = root
return root
def unite(self, node1, node2):
main_root = self.get_root(node1)
sub_root = self.get_root(node2)
if main_root == sub_root:
return
if self.rank[main_root] < self.rank[sub_root]:
main_root, sub_root = sub_root, main_root
self.parent[sub_root] = main_root
self.rank[main_root] += self.rank[sub_root]
self.groups -= 1
n, m, *t = list(map(int,open(0).read().split()))
uf = UnionFind(n)
X = t[::3]
Y = t[1::3]
for x, y in zip(X, Y):
uf.unite(x-1, y-1)
print((uf.groups)) | 42 | 36 | 1,092 | 949 | import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, size):
self.parent = [-1] * size
self.rank = [1] * size
self.groups = size
def get_root(self, node):
parent = self.parent[node]
if parent == -1:
root = node
else:
root = self.get_root(parent)
self.parent[node] = root # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく
return root
def unite(self, node1, node2):
main_root = self.get_root(node1)
sub_root = self.get_root(node2)
if main_root == sub_root:
return
if self.rank[main_root] < self.rank[sub_root]: # rankの大きい方をmain_rootにする
main_root, sub_root = sub_root, main_root
self.parent[sub_root] = main_root
self.rank[main_root] += self.rank[sub_root]
self.groups -= 1
n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
x, y, z = list(map(int, input().split()))
x -= 1
y -= 1
uf.unite(x, y)
print((uf.groups))
| class UnionFind:
def __init__(self, size):
self.parent = [-1] * size
self.rank = [1] * size
self.groups = size
def get_root(self, node):
parent = self.parent[node]
if parent == -1:
root = node
else:
root = self.get_root(parent)
self.parent[node] = root
return root
def unite(self, node1, node2):
main_root = self.get_root(node1)
sub_root = self.get_root(node2)
if main_root == sub_root:
return
if self.rank[main_root] < self.rank[sub_root]:
main_root, sub_root = sub_root, main_root
self.parent[sub_root] = main_root
self.rank[main_root] += self.rank[sub_root]
self.groups -= 1
n, m, *t = list(map(int, open(0).read().split()))
uf = UnionFind(n)
X = t[::3]
Y = t[1::3]
for x, y in zip(X, Y):
uf.unite(x - 1, y - 1)
print((uf.groups))
| false | 14.285714 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-",
"-",
"- self.parent[node] = root # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく",
"+ self.parent[node] = root",
"- if self.rank[main_root] < self.rank[sub_root]: # rankの大きい方をmain_rootにする",
"+ if self.rank[main_root] < self.rank[sub_root]:",
"-n, m = list(map(int, input().split()))",
"+n, m, *t = list(map(int, open(0).read().split()))",
"-for i in range(m):",
"- x, y, z = list(map(int, input().split()))",
"- x -= 1",
"- y -= 1",
"- uf.unite(x, y)",
"+X = t[::3]",
"+Y = t[1::3]",
"+for x, y in zip(X, Y):",
"+ uf.unite(x - 1, y - 1)"
] | false | 0.047298 | 0.045661 | 1.035835 | [
"s824223498",
"s990663776"
] |
u094999522 | p03341 | python | s175020002 | s532345742 | 225 | 143 | 33,296 | 9,748 | Accepted | Accepted | 36.44 | #!/usr/bin/env python3
n = int(eval(input()))
s = eval(input())
e = [0]
w = [0]
for i in s:
e.append(e[-1] + (i == "E"))
w.append(w[-1] + (i == "W"))
ans = 10**6
for i in range(n):
ans = min(ans, w[i] + e[-1] - e[i + 1])
print(ans)
| #!/usr/bin/env python3
n = int(eval(input()))
s = eval(input())
w = 0
e = s.count("E")
ans = 10**6
for i in s:
e -= i == "E"
ans = min(ans, e + w)
w += i == "W"
print(ans)
| 12 | 11 | 243 | 182 | #!/usr/bin/env python3
n = int(eval(input()))
s = eval(input())
e = [0]
w = [0]
for i in s:
e.append(e[-1] + (i == "E"))
w.append(w[-1] + (i == "W"))
ans = 10**6
for i in range(n):
ans = min(ans, w[i] + e[-1] - e[i + 1])
print(ans)
| #!/usr/bin/env python3
n = int(eval(input()))
s = eval(input())
w = 0
e = s.count("E")
ans = 10**6
for i in s:
e -= i == "E"
ans = min(ans, e + w)
w += i == "W"
print(ans)
| false | 8.333333 | [
"-e = [0]",
"-w = [0]",
"+w = 0",
"+e = s.count(\"E\")",
"+ans = 10**6",
"- e.append(e[-1] + (i == \"E\"))",
"- w.append(w[-1] + (i == \"W\"))",
"-ans = 10**6",
"-for i in range(n):",
"- ans = min(ans, w[i] + e[-1] - e[i + 1])",
"+ e -= i == \"E\"",
"+ ans = min(ans, e + w)",
"+ w += i == \"W\""
] | false | 0.06968 | 0.062563 | 1.113754 | [
"s175020002",
"s532345742"
] |
u489959379 | p03266 | python | s820994727 | s751008007 | 104 | 55 | 4,632 | 2,940 | Accepted | Accepted | 47.12 | n, k = list(map(int, input().split()))
# num[x]:kで割ってxあまる数が1以上N以下に何個あるか
num = [0 for _ in range(k)]
for i in range(1, n + 1):
num[i % k] += 1
res = 0
for a in range(k):
b = (k - a) % k
c = (k - a) % k
if (b + c) % k != 0:
continue
res += num[a] * num[b] * num[c]
print(res)
| n, k = list(map(int, input().split()))
if k % 2 != 0:
x = n // k
print((x ** 3))
else:
x = n // k
y = 0
for i in range(1, n + 1):
if i % k == k // 2:
y += 1
print((x ** 3 + y ** 3))
| 16 | 12 | 314 | 228 | n, k = list(map(int, input().split()))
# num[x]:kで割ってxあまる数が1以上N以下に何個あるか
num = [0 for _ in range(k)]
for i in range(1, n + 1):
num[i % k] += 1
res = 0
for a in range(k):
b = (k - a) % k
c = (k - a) % k
if (b + c) % k != 0:
continue
res += num[a] * num[b] * num[c]
print(res)
| n, k = list(map(int, input().split()))
if k % 2 != 0:
x = n // k
print((x**3))
else:
x = n // k
y = 0
for i in range(1, n + 1):
if i % k == k // 2:
y += 1
print((x**3 + y**3))
| false | 25 | [
"-# num[x]:kで割ってxあまる数が1以上N以下に何個あるか",
"-num = [0 for _ in range(k)]",
"-for i in range(1, n + 1):",
"- num[i % k] += 1",
"-res = 0",
"-for a in range(k):",
"- b = (k - a) % k",
"- c = (k - a) % k",
"- if (b + c) % k != 0:",
"- continue",
"- res += num[a] * num[b] * num[c]",
"-print(res)",
"+if k % 2 != 0:",
"+ x = n // k",
"+ print((x**3))",
"+else:",
"+ x = n // k",
"+ y = 0",
"+ for i in range(1, n + 1):",
"+ if i % k == k // 2:",
"+ y += 1",
"+ print((x**3 + y**3))"
] | false | 0.042326 | 0.03998 | 1.058685 | [
"s820994727",
"s751008007"
] |
u677267454 | p03074 | python | s860747815 | s369728041 | 202 | 158 | 4,092 | 7,932 | Accepted | Accepted | 21.78 | # -*- coding: utf-8 -*-
n, k = list(map(int, input().split()))
s = eval(input())
nums = []
now = 1
cnt = 0
for i in range(n):
if s[i] == str(int('0') + now):
cnt += 1
else:
nums.append(cnt)
now = 1 - now
cnt = 1
if cnt != 0:
nums.append(cnt)
ans = 0
left = 0
right = 0
tmp = 0
for i in range(0, len(nums), 2):
next_left = i
next_right = min(i + 2 * k + 1, len(nums))
while (left < next_left):
tmp -= nums[left]
left += 1
while (right < next_right):
tmp += nums[right]
right += 1
ans = max(ans, tmp)
print(ans)
| # -*- coding: utf-8 -*-
n, k = list(map(int, input().split()))
s = eval(input())
nums = []
now = 1
cnt = 0
for i in range(n):
if s[i] == str(int('0') + now):
cnt += 1
else:
nums.append(cnt)
now = 1 - now
cnt = 1
if cnt != 0:
nums.append(cnt)
t = [0]
for i in range(len(nums)):
t.append(t[i] + nums[i])
ans = 0
for i in range(0, len(nums), 2):
left = i
right = min(i + 2 * k + 1, len(nums))
ans = max(ans, t[right] - t[left])
print(ans)
| 38 | 30 | 639 | 519 | # -*- coding: utf-8 -*-
n, k = list(map(int, input().split()))
s = eval(input())
nums = []
now = 1
cnt = 0
for i in range(n):
if s[i] == str(int("0") + now):
cnt += 1
else:
nums.append(cnt)
now = 1 - now
cnt = 1
if cnt != 0:
nums.append(cnt)
ans = 0
left = 0
right = 0
tmp = 0
for i in range(0, len(nums), 2):
next_left = i
next_right = min(i + 2 * k + 1, len(nums))
while left < next_left:
tmp -= nums[left]
left += 1
while right < next_right:
tmp += nums[right]
right += 1
ans = max(ans, tmp)
print(ans)
| # -*- coding: utf-8 -*-
n, k = list(map(int, input().split()))
s = eval(input())
nums = []
now = 1
cnt = 0
for i in range(n):
if s[i] == str(int("0") + now):
cnt += 1
else:
nums.append(cnt)
now = 1 - now
cnt = 1
if cnt != 0:
nums.append(cnt)
t = [0]
for i in range(len(nums)):
t.append(t[i] + nums[i])
ans = 0
for i in range(0, len(nums), 2):
left = i
right = min(i + 2 * k + 1, len(nums))
ans = max(ans, t[right] - t[left])
print(ans)
| false | 21.052632 | [
"+t = [0]",
"+for i in range(len(nums)):",
"+ t.append(t[i] + nums[i])",
"-left = 0",
"-right = 0",
"-tmp = 0",
"- next_left = i",
"- next_right = min(i + 2 * k + 1, len(nums))",
"- while left < next_left:",
"- tmp -= nums[left]",
"- left += 1",
"- while right < next_right:",
"- tmp += nums[right]",
"- right += 1",
"- ans = max(ans, tmp)",
"+ left = i",
"+ right = min(i + 2 * k + 1, len(nums))",
"+ ans = max(ans, t[right] - t[left])"
] | false | 0.048228 | 0.086807 | 0.555575 | [
"s860747815",
"s369728041"
] |
u281610856 | p03575 | python | s793347029 | s384280326 | 156 | 20 | 12,360 | 3,064 | Accepted | Accepted | 87.18 | from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
INF = float("inf")
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n # 各要素の親要素の番号を格納するリスト
def find(self, x): # 要素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が属するグループと要素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): # 要素xが属するグループのサイズ(要素数)を返す
return -self.parents[self.find(x)]
def same(self, x, y): # 要素x, yが同じグループに属するかどうかを返す
return self.find(x) == self.find(y)
def members(self, x): # 要素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, M = list(map(int, input().split()))
uf = UnionFind(N)
edge = []
for _ in range(M):
a, b = [int(i) - 1 for i in input().split()]
edge.append((a, b))
uf.union(a, b)
ans = 0
for i in range(M):
new_uf = UnionFind(N)
for j in range(M):
a, b = edge[j]
if i != j:
new_uf.union(a, b)
if new_uf.group_count() > 1:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| import sys
sys.setrecursionlimit(10**6)
N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]
edge = []
for _ in range(M):
u, v = list(map(int, input().split()))
G[u-1].append(v-1)
G[v-1].append(u-1)
edge.append((u-1, v-1))
# 連結かどうかの判定->DFS, BFS, Dijkstra, UnionFindなどで解ける
def dfs(s, check, a, b):
for t in G[s]:
if (s, t) == (a, b) or (s, t) == (b, a):
continue
if check[t]:
continue
check[t] = 1
dfs(t, check, a, b)
if 0 in check:
return 1
else:
return 0
cnt = 0
for a, b in edge:
check = [1] + [0] * (N-1)
cnt += dfs(0, check, a, b)
print(cnt)
| 84 | 32 | 2,260 | 690 | from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
# MOD = 10 ** 9 + 7
INF = float("inf")
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n # 各要素の親要素の番号を格納するリスト
def find(self, x): # 要素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が属するグループと要素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): # 要素xが属するグループのサイズ(要素数)を返す
return -self.parents[self.find(x)]
def same(self, x, y): # 要素x, yが同じグループに属するかどうかを返す
return self.find(x) == self.find(y)
def members(self, x): # 要素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, M = list(map(int, input().split()))
uf = UnionFind(N)
edge = []
for _ in range(M):
a, b = [int(i) - 1 for i in input().split()]
edge.append((a, b))
uf.union(a, b)
ans = 0
for i in range(M):
new_uf = UnionFind(N)
for j in range(M):
a, b = edge[j]
if i != j:
new_uf.union(a, b)
if new_uf.group_count() > 1:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10**6)
N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]
edge = []
for _ in range(M):
u, v = list(map(int, input().split()))
G[u - 1].append(v - 1)
G[v - 1].append(u - 1)
edge.append((u - 1, v - 1))
# 連結かどうかの判定->DFS, BFS, Dijkstra, UnionFindなどで解ける
def dfs(s, check, a, b):
for t in G[s]:
if (s, t) == (a, b) or (s, t) == (b, a):
continue
if check[t]:
continue
check[t] = 1
dfs(t, check, a, b)
if 0 in check:
return 1
else:
return 0
cnt = 0
for a, b in edge:
check = [1] + [0] * (N - 1)
cnt += dfs(0, check, a, b)
print(cnt)
| false | 61.904762 | [
"-from heapq import heappush, heappop",
"-from itertools import permutations, accumulate, combinations",
"-import math",
"-import bisect",
"-import numpy as np",
"-from collections import defaultdict, deque",
"-input = sys.stdin.readline",
"-# MOD = 10 ** 9 + 7",
"-INF = float(\"inf\")",
"+N, M = list(map(int, input().split()))",
"+G = [[] for _ in range(N)]",
"+edge = []",
"+for _ in range(M):",
"+ u, v = list(map(int, input().split()))",
"+ G[u - 1].append(v - 1)",
"+ G[v - 1].append(u - 1)",
"+ edge.append((u - 1, v - 1))",
"+# 連結かどうかの判定->DFS, BFS, Dijkstra, UnionFindなどで解ける",
"+def dfs(s, check, a, b):",
"+ for t in G[s]:",
"+ if (s, t) == (a, b) or (s, t) == (b, a):",
"+ continue",
"+ if check[t]:",
"+ continue",
"+ check[t] = 1",
"+ dfs(t, check, a, b)",
"+ if 0 in check:",
"+ return 1",
"+ else:",
"+ return 0",
"-class UnionFind:",
"- def __init__(self, n):",
"- self.n = n",
"- self.parents = [-1] * n # 各要素の親要素の番号を格納するリスト",
"-",
"- def find(self, x): # 要素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が属するグループと要素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): # 要素xが属するグループのサイズ(要素数)を返す",
"- return -self.parents[self.find(x)]",
"-",
"- def same(self, x, y): # 要素x, yが同じグループに属するかどうかを返す",
"- return self.find(x) == self.find(y)",
"-",
"- def members(self, x): # 要素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, M = list(map(int, input().split()))",
"- uf = UnionFind(N)",
"- edge = []",
"- for _ in range(M):",
"- a, b = [int(i) - 1 for i in input().split()]",
"- edge.append((a, b))",
"- uf.union(a, b)",
"- ans = 0",
"- for i in range(M):",
"- new_uf = UnionFind(N)",
"- for j in range(M):",
"- a, b = edge[j]",
"- if i != j:",
"- new_uf.union(a, b)",
"- if new_uf.group_count() > 1:",
"- ans += 1",
"- print(ans)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+cnt = 0",
"+for a, b in edge:",
"+ check = [1] + [0] * (N - 1)",
"+ cnt += dfs(0, check, a, b)",
"+print(cnt)"
] | false | 0.036603 | 0.037399 | 0.978709 | [
"s793347029",
"s384280326"
] |
u371132735 | p02748 | python | s526572328 | s811654175 | 731 | 473 | 70,124 | 24,804 | Accepted | Accepted | 35.29 | A,B,M = list(map(int,input().split()))
Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
amin = min(Ai)
bmin= min(Bi)
min = amin+bmin
for i in range(M):
xi,yi,ci = list(map(int,input().split()))
if Ai[xi-1] + Bi[yi-1] - ci < min:
min = Ai[xi-1] + Bi[yi-1] - ci
print(min)
| # hitachi2020_b.py
_, _, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = []
Y = []
C = []
amin = min(A)
bmin = min(B)
for i in range(M):
x, y, c = list(map(int, input().split()))
X.append(x)
Y.append(y)
C.append(c)
ans = amin+bmin
for i in range(M):
if ans >= A[X[i]-1]+B[Y[i]-1]-C[i]:
ans = A[X[i]-1]+B[Y[i]-1]-C[i]
print(ans)
| 11 | 20 | 296 | 428 | A, B, M = list(map(int, input().split()))
Ai = list(map(int, input().split()))
Bi = list(map(int, input().split()))
amin = min(Ai)
bmin = min(Bi)
min = amin + bmin
for i in range(M):
xi, yi, ci = list(map(int, input().split()))
if Ai[xi - 1] + Bi[yi - 1] - ci < min:
min = Ai[xi - 1] + Bi[yi - 1] - ci
print(min)
| # hitachi2020_b.py
_, _, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = []
Y = []
C = []
amin = min(A)
bmin = min(B)
for i in range(M):
x, y, c = list(map(int, input().split()))
X.append(x)
Y.append(y)
C.append(c)
ans = amin + bmin
for i in range(M):
if ans >= A[X[i] - 1] + B[Y[i] - 1] - C[i]:
ans = A[X[i] - 1] + B[Y[i] - 1] - C[i]
print(ans)
| false | 45 | [
"-A, B, M = list(map(int, input().split()))",
"-Ai = list(map(int, input().split()))",
"-Bi = list(map(int, input().split()))",
"-amin = min(Ai)",
"-bmin = min(Bi)",
"-min = amin + bmin",
"+# hitachi2020_b.py",
"+_, _, M = list(map(int, input().split()))",
"+A = list(map(int, input().split()))",
"+B = list(map(int, input().split()))",
"+X = []",
"+Y = []",
"+C = []",
"+amin = min(A)",
"+bmin = min(B)",
"- xi, yi, ci = list(map(int, input().split()))",
"- if Ai[xi - 1] + Bi[yi - 1] - ci < min:",
"- min = Ai[xi - 1] + Bi[yi - 1] - ci",
"-print(min)",
"+ x, y, c = list(map(int, input().split()))",
"+ X.append(x)",
"+ Y.append(y)",
"+ C.append(c)",
"+ans = amin + bmin",
"+for i in range(M):",
"+ if ans >= A[X[i] - 1] + B[Y[i] - 1] - C[i]:",
"+ ans = A[X[i] - 1] + B[Y[i] - 1] - C[i]",
"+print(ans)"
] | false | 0.042069 | 0.040657 | 1.034737 | [
"s526572328",
"s811654175"
] |
u225388820 | p02719 | python | s828765823 | s015450863 | 22 | 17 | 2,940 | 2,940 | Accepted | Accepted | 22.73 | n,k=list(map(int,input().split()))
if n>k:
n=n-n//k*k
ans=10**18+10
for i in range(10000):
ans=min(ans,n)
n=abs(n-k)
print(ans) | n,k=list(map(int,input().split()))
print((min(n%k,k-n%k))) | 8 | 2 | 140 | 51 | n, k = list(map(int, input().split()))
if n > k:
n = n - n // k * k
ans = 10**18 + 10
for i in range(10000):
ans = min(ans, n)
n = abs(n - k)
print(ans)
| n, k = list(map(int, input().split()))
print((min(n % k, k - n % k)))
| false | 75 | [
"-if n > k:",
"- n = n - n // k * k",
"-ans = 10**18 + 10",
"-for i in range(10000):",
"- ans = min(ans, n)",
"- n = abs(n - k)",
"-print(ans)",
"+print((min(n % k, k - n % k)))"
] | false | 0.039162 | 0.036047 | 1.08639 | [
"s828765823",
"s015450863"
] |
u780962115 | p02632 | python | s611681132 | s811057398 | 1,241 | 809 | 313,532 | 187,260 | Accepted | Accepted | 34.81 | #標準入力 テスト
import sys
input = lambda: sys.stdin.readline().rstrip()
K=int(eval(input()))
S=eval(input())
M=len(S)
N=K+M
mod=10**9+7
ans=pow(26,N,mod)
class Data():
def __init__(self):
self.power=1
self.rev=1
class Combi():
def __init__(self,N,mod):
self.lists=[Data() for _ in range(N+1)]
self.mod=mod
for i in range(2,N+1):
self.lists[i].power=((self.lists[i-1].power)*i)%self.mod
self.lists[N].rev=pow(self.lists[N].power,self.mod-2,self.mod)
for j in range(N,0,-1):
self.lists[j-1].rev=((self.lists[j].rev)*j)%self.mod
def combi(self,K,R):
if K<R:
return 0
else:
return ((self.lists[K].power)*(self.lists[K-R].rev)*(self.lists[R].rev))%self.mod
c=Combi(2*10**6,mod)
for i in range(M):
ans-=c.combi(N,i)*pow(25,N-i,mod)
ans%=mod
print(ans)
| # ライブラリ高速化実験テスト
import sys
class Combi():
def __init__(self, N, mod):
self.power = [1 for _ in range(N+1)]
self.rev = [1 for _ in range(N+1)]
self.mod = mod
for i in range(2, N+1):
self.power[i] = (self.power[i-1]*i) % self.mod
self.rev[N] = pow(self.power[N], self.mod-2, self.mod)
for j in range(N, 0, -1):
self.rev[j-1] = (self.rev[j]*j) % self.mod
def com(self, K, R):
if K < R:
return 0
else:
return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod
def pom(self, K, R):
if K < R:
return 0
else:
return (self.power[K])*(self.rev[K-R]) % self.mod
def input(): return sys.stdin.readline().rstrip()
K = int(eval(input()))
S = eval(input())
M = len(S)
N = K+M
mod = 10**9+7
ans = pow(26, N, mod)
c = Combi(2*10**6, mod)
for i in range(M):
ans -= c.com(N, i)*pow(25, N-i, mod)
ans %= mod
print(ans) | 34 | 44 | 919 | 1,020 | # 標準入力 テスト
import sys
input = lambda: sys.stdin.readline().rstrip()
K = int(eval(input()))
S = eval(input())
M = len(S)
N = K + M
mod = 10**9 + 7
ans = pow(26, N, mod)
class Data:
def __init__(self):
self.power = 1
self.rev = 1
class Combi:
def __init__(self, N, mod):
self.lists = [Data() for _ in range(N + 1)]
self.mod = mod
for i in range(2, N + 1):
self.lists[i].power = ((self.lists[i - 1].power) * i) % self.mod
self.lists[N].rev = pow(self.lists[N].power, self.mod - 2, self.mod)
for j in range(N, 0, -1):
self.lists[j - 1].rev = ((self.lists[j].rev) * j) % self.mod
def combi(self, K, R):
if K < R:
return 0
else:
return (
(self.lists[K].power) * (self.lists[K - R].rev) * (self.lists[R].rev)
) % self.mod
c = Combi(2 * 10**6, mod)
for i in range(M):
ans -= c.combi(N, i) * pow(25, N - i, mod)
ans %= mod
print(ans)
| # ライブラリ高速化実験テスト
import sys
class Combi:
def __init__(self, N, mod):
self.power = [1 for _ in range(N + 1)]
self.rev = [1 for _ in range(N + 1)]
self.mod = mod
for i in range(2, N + 1):
self.power[i] = (self.power[i - 1] * i) % self.mod
self.rev[N] = pow(self.power[N], self.mod - 2, self.mod)
for j in range(N, 0, -1):
self.rev[j - 1] = (self.rev[j] * j) % self.mod
def com(self, K, R):
if K < R:
return 0
else:
return ((self.power[K]) * (self.rev[K - R]) * (self.rev[R])) % self.mod
def pom(self, K, R):
if K < R:
return 0
else:
return (self.power[K]) * (self.rev[K - R]) % self.mod
def input():
return sys.stdin.readline().rstrip()
K = int(eval(input()))
S = eval(input())
M = len(S)
N = K + M
mod = 10**9 + 7
ans = pow(26, N, mod)
c = Combi(2 * 10**6, mod)
for i in range(M):
ans -= c.com(N, i) * pow(25, N - i, mod)
ans %= mod
print(ans)
| false | 22.727273 | [
"-# 標準入力 テスト",
"+# ライブラリ高速化実験テスト",
"-input = lambda: sys.stdin.readline().rstrip()",
"+",
"+class Combi:",
"+ def __init__(self, N, mod):",
"+ self.power = [1 for _ in range(N + 1)]",
"+ self.rev = [1 for _ in range(N + 1)]",
"+ self.mod = mod",
"+ for i in range(2, N + 1):",
"+ self.power[i] = (self.power[i - 1] * i) % self.mod",
"+ self.rev[N] = pow(self.power[N], self.mod - 2, self.mod)",
"+ for j in range(N, 0, -1):",
"+ self.rev[j - 1] = (self.rev[j] * j) % self.mod",
"+",
"+ def com(self, K, R):",
"+ if K < R:",
"+ return 0",
"+ else:",
"+ return ((self.power[K]) * (self.rev[K - R]) * (self.rev[R])) % self.mod",
"+",
"+ def pom(self, K, R):",
"+ if K < R:",
"+ return 0",
"+ else:",
"+ return (self.power[K]) * (self.rev[K - R]) % self.mod",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().rstrip()",
"+",
"+",
"-",
"-",
"-class Data:",
"- def __init__(self):",
"- self.power = 1",
"- self.rev = 1",
"-",
"-",
"-class Combi:",
"- def __init__(self, N, mod):",
"- self.lists = [Data() for _ in range(N + 1)]",
"- self.mod = mod",
"- for i in range(2, N + 1):",
"- self.lists[i].power = ((self.lists[i - 1].power) * i) % self.mod",
"- self.lists[N].rev = pow(self.lists[N].power, self.mod - 2, self.mod)",
"- for j in range(N, 0, -1):",
"- self.lists[j - 1].rev = ((self.lists[j].rev) * j) % self.mod",
"-",
"- def combi(self, K, R):",
"- if K < R:",
"- return 0",
"- else:",
"- return (",
"- (self.lists[K].power) * (self.lists[K - R].rev) * (self.lists[R].rev)",
"- ) % self.mod",
"-",
"-",
"- ans -= c.combi(N, i) * pow(25, N - i, mod)",
"+ ans -= c.com(N, i) * pow(25, N - i, mod)"
] | false | 0.041522 | 0.059046 | 0.70322 | [
"s611681132",
"s811057398"
] |
u279493135 | p03305 | python | s857767413 | s603205587 | 1,614 | 1,382 | 115,544 | 115,328 | Accepted | Accepted | 14.37 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
from heapq import heappush, heappop
from scipy.sparse.csgraph import dijkstra
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
def dijkstra(E, start):
N_d = len(E)
dist = [INF] * N_d
dist[start] = 0
q = [(0, start)]
while q:
dist_v, v = heappop(q)
if dist[v] != dist_v:
continue
for u, dist_vu in E[v]:
dist_u = dist_v + dist_vu
if dist_u < dist[u]:
dist[u] = dist_u
heappush(q, (dist_u, u))
return dist
n, m, s, t = MAP()
uvab = [LIST() for _ in range(m)]
A = [[] for _ in range(n+1)]
B = [[] for _ in range(n+1)]
for u, v, a, b in uvab:
A[u].append((v, a))
A[v].append((u, a))
B[u].append((v, b))
B[v].append((u, b))
distA = dijkstra(A, s) # 円での移動(s->i)
distB = dijkstra(B, t) # スヌークでの移動(t->i)
Ans = []
init = 10**15
ans = INF
for a, b in zip(distA[:0:-1], distB[:0:-1]):
ans = min(ans, a+b)
Ans.append(init-ans)
Ans = Ans[::-1]
print(("\n".join(map(str, Ans))))
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
from heapq import heappush, heappop
from scipy.sparse.csgraph import dijkstra
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
def main():
def dijkstra(E, start):
N_d = len(E)
dist = [INF] * N_d
dist[start] = 0
q = [(0, start)]
while q:
dist_v, v = heappop(q)
if dist[v] != dist_v:
continue
for u, dist_vu in E[v]:
dist_u = dist_v + dist_vu
if dist_u < dist[u]:
dist[u] = dist_u
heappush(q, (dist_u, u))
return dist
n, m, s, t = MAP()
uvab = [LIST() for _ in range(m)]
A = [[] for _ in range(n+1)]
B = [[] for _ in range(n+1)]
for u, v, a, b in uvab:
A[u].append((v, a))
A[v].append((u, a))
B[u].append((v, b))
B[v].append((u, b))
distA = dijkstra(A, s) # 円での移動(s->i)
distB = dijkstra(B, t) # スヌークでの移動(t->i)
Ans = []
init = 10**15
ans = INF
for a, b in zip(distA[:0:-1], distB[:0:-1]):
ans = min(ans, a+b)
Ans.append(init-ans)
Ans = Ans[::-1]
print(("\n".join(map(str, Ans))))
main()
| 60 | 63 | 1,622 | 1,679 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
from heapq import heappush, heappop
from scipy.sparse.csgraph import dijkstra
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
def dijkstra(E, start):
N_d = len(E)
dist = [INF] * N_d
dist[start] = 0
q = [(0, start)]
while q:
dist_v, v = heappop(q)
if dist[v] != dist_v:
continue
for u, dist_vu in E[v]:
dist_u = dist_v + dist_vu
if dist_u < dist[u]:
dist[u] = dist_u
heappush(q, (dist_u, u))
return dist
n, m, s, t = MAP()
uvab = [LIST() for _ in range(m)]
A = [[] for _ in range(n + 1)]
B = [[] for _ in range(n + 1)]
for u, v, a, b in uvab:
A[u].append((v, a))
A[v].append((u, a))
B[u].append((v, b))
B[v].append((u, b))
distA = dijkstra(A, s) # 円での移動(s->i)
distB = dijkstra(B, t) # スヌークでの移動(t->i)
Ans = []
init = 10**15
ans = INF
for a, b in zip(distA[:0:-1], distB[:0:-1]):
ans = min(ans, a + b)
Ans.append(init - ans)
Ans = Ans[::-1]
print(("\n".join(map(str, Ans))))
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
from heapq import heappush, heappop
from scipy.sparse.csgraph import dijkstra
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
def main():
def dijkstra(E, start):
N_d = len(E)
dist = [INF] * N_d
dist[start] = 0
q = [(0, start)]
while q:
dist_v, v = heappop(q)
if dist[v] != dist_v:
continue
for u, dist_vu in E[v]:
dist_u = dist_v + dist_vu
if dist_u < dist[u]:
dist[u] = dist_u
heappush(q, (dist_u, u))
return dist
n, m, s, t = MAP()
uvab = [LIST() for _ in range(m)]
A = [[] for _ in range(n + 1)]
B = [[] for _ in range(n + 1)]
for u, v, a, b in uvab:
A[u].append((v, a))
A[v].append((u, a))
B[u].append((v, b))
B[v].append((u, b))
distA = dijkstra(A, s) # 円での移動(s->i)
distB = dijkstra(B, t) # スヌークでの移動(t->i)
Ans = []
init = 10**15
ans = INF
for a, b in zip(distA[:0:-1], distB[:0:-1]):
ans = min(ans, a + b)
Ans.append(init - ans)
Ans = Ans[::-1]
print(("\n".join(map(str, Ans))))
main()
| false | 4.761905 | [
"-def dijkstra(E, start):",
"- N_d = len(E)",
"- dist = [INF] * N_d",
"- dist[start] = 0",
"- q = [(0, start)]",
"- while q:",
"- dist_v, v = heappop(q)",
"- if dist[v] != dist_v:",
"- continue",
"- for u, dist_vu in E[v]:",
"- dist_u = dist_v + dist_vu",
"- if dist_u < dist[u]:",
"- dist[u] = dist_u",
"- heappush(q, (dist_u, u))",
"- return dist",
"+def main():",
"+ def dijkstra(E, start):",
"+ N_d = len(E)",
"+ dist = [INF] * N_d",
"+ dist[start] = 0",
"+ q = [(0, start)]",
"+ while q:",
"+ dist_v, v = heappop(q)",
"+ if dist[v] != dist_v:",
"+ continue",
"+ for u, dist_vu in E[v]:",
"+ dist_u = dist_v + dist_vu",
"+ if dist_u < dist[u]:",
"+ dist[u] = dist_u",
"+ heappush(q, (dist_u, u))",
"+ return dist",
"+",
"+ n, m, s, t = MAP()",
"+ uvab = [LIST() for _ in range(m)]",
"+ A = [[] for _ in range(n + 1)]",
"+ B = [[] for _ in range(n + 1)]",
"+ for u, v, a, b in uvab:",
"+ A[u].append((v, a))",
"+ A[v].append((u, a))",
"+ B[u].append((v, b))",
"+ B[v].append((u, b))",
"+ distA = dijkstra(A, s) # 円での移動(s->i)",
"+ distB = dijkstra(B, t) # スヌークでの移動(t->i)",
"+ Ans = []",
"+ init = 10**15",
"+ ans = INF",
"+ for a, b in zip(distA[:0:-1], distB[:0:-1]):",
"+ ans = min(ans, a + b)",
"+ Ans.append(init - ans)",
"+ Ans = Ans[::-1]",
"+ print((\"\\n\".join(map(str, Ans))))",
"-n, m, s, t = MAP()",
"-uvab = [LIST() for _ in range(m)]",
"-A = [[] for _ in range(n + 1)]",
"-B = [[] for _ in range(n + 1)]",
"-for u, v, a, b in uvab:",
"- A[u].append((v, a))",
"- A[v].append((u, a))",
"- B[u].append((v, b))",
"- B[v].append((u, b))",
"-distA = dijkstra(A, s) # 円での移動(s->i)",
"-distB = dijkstra(B, t) # スヌークでの移動(t->i)",
"-Ans = []",
"-init = 10**15",
"-ans = INF",
"-for a, b in zip(distA[:0:-1], distB[:0:-1]):",
"- ans = min(ans, a + b)",
"- Ans.append(init - ans)",
"-Ans = Ans[::-1]",
"-print((\"\\n\".join(map(str, Ans))))",
"+main()"
] | false | 0.491396 | 0.04549 | 10.802317 | [
"s857767413",
"s603205587"
] |
u822353071 | p03943 | python | s151956699 | s487474373 | 24 | 21 | 3,316 | 3,064 | Accepted | Accepted | 12.5 | # import time
# starttime=time.clock()
A,B,C =input().split()
a=int(A)
b=int(B)
c=int(C)
# print(a+c)
if a>b:
temp = a
a = b
b = temp
if b>c:
temp = b
b = c
c = temp
if (a+b)==c:
print("Yes")
# endtime = time.clock()
# print(endtime-starttime)
else:
print("No")
# endtime = time.clock()
# print(endtime-starttime)
#
| a,b,c = list(map(int,input().split()))
if a>b:
temp = a
a = b
b = temp
if b>c:
temp = b
b = c
c = temp
if (a+b)==c:
print("Yes")
else:
print("No")
| 27 | 15 | 400 | 190 | # import time
# starttime=time.clock()
A, B, C = input().split()
a = int(A)
b = int(B)
c = int(C)
# print(a+c)
if a > b:
temp = a
a = b
b = temp
if b > c:
temp = b
b = c
c = temp
if (a + b) == c:
print("Yes")
# endtime = time.clock()
# print(endtime-starttime)
else:
print("No")
# endtime = time.clock()
# print(endtime-starttime)
#
| a, b, c = list(map(int, input().split()))
if a > b:
temp = a
a = b
b = temp
if b > c:
temp = b
b = c
c = temp
if (a + b) == c:
print("Yes")
else:
print("No")
| false | 44.444444 | [
"-# import time",
"-# starttime=time.clock()",
"-A, B, C = input().split()",
"-a = int(A)",
"-b = int(B)",
"-c = int(C)",
"-# print(a+c)",
"+a, b, c = list(map(int, input().split()))",
"-# endtime = time.clock()",
"-# print(endtime-starttime)",
"-# endtime = time.clock()",
"-# print(endtime-starttime)",
"-#"
] | false | 0.038401 | 0.042428 | 0.905103 | [
"s151956699",
"s487474373"
] |
u761320129 | p03799 | python | s629889729 | s652249328 | 29 | 26 | 8,912 | 8,952 | Accepted | Accepted | 10.34 | s,c = list(map(int,input().split()))
ans = min(s,c//2)
c -= ans*2
ans += c//4
print(ans) | S,C = list(map(int,input().split()))
p = min(S,C//2)
C -= p*2
ans = p + C//4
print(ans) | 5 | 6 | 86 | 87 | s, c = list(map(int, input().split()))
ans = min(s, c // 2)
c -= ans * 2
ans += c // 4
print(ans)
| S, C = list(map(int, input().split()))
p = min(S, C // 2)
C -= p * 2
ans = p + C // 4
print(ans)
| false | 16.666667 | [
"-s, c = list(map(int, input().split()))",
"-ans = min(s, c // 2)",
"-c -= ans * 2",
"-ans += c // 4",
"+S, C = list(map(int, input().split()))",
"+p = min(S, C // 2)",
"+C -= p * 2",
"+ans = p + C // 4"
] | false | 0.04829 | 0.057176 | 0.844573 | [
"s629889729",
"s652249328"
] |
u896588506 | p02713 | python | s623035891 | s506843779 | 1,817 | 989 | 9,116 | 9,124 | Accepted | Accepted | 45.57 | from math import gcd
k = int(eval(input()))
ans = 0
for l in range(1,k+1):
for m in range(1,k+1):
for n in range(1,k+1):
ans += gcd(gcd(l,m),n)
print(ans) | import math
import itertools
k = int(eval(input()))
lst = [i for i in range(1,k+1)]
itr = itertools.combinations_with_replacement(lst, 3)
ans = 0
for i in itr:
st = set(i)
num = len(st)
if num == 1:
ans += i[0]
elif num == 2:
a,b = st
ans += math.gcd(a,b) * 3
else:
ans += math.gcd(math.gcd(i[0],i[1]), i[2]) * 6
print(ans) | 10 | 20 | 171 | 365 | from math import gcd
k = int(eval(input()))
ans = 0
for l in range(1, k + 1):
for m in range(1, k + 1):
for n in range(1, k + 1):
ans += gcd(gcd(l, m), n)
print(ans)
| import math
import itertools
k = int(eval(input()))
lst = [i for i in range(1, k + 1)]
itr = itertools.combinations_with_replacement(lst, 3)
ans = 0
for i in itr:
st = set(i)
num = len(st)
if num == 1:
ans += i[0]
elif num == 2:
a, b = st
ans += math.gcd(a, b) * 3
else:
ans += math.gcd(math.gcd(i[0], i[1]), i[2]) * 6
print(ans)
| false | 50 | [
"-from math import gcd",
"+import math",
"+import itertools",
"+lst = [i for i in range(1, k + 1)]",
"+itr = itertools.combinations_with_replacement(lst, 3)",
"-for l in range(1, k + 1):",
"- for m in range(1, k + 1):",
"- for n in range(1, k + 1):",
"- ans += gcd(gcd(l, m), n)",
"+for i in itr:",
"+ st = set(i)",
"+ num = len(st)",
"+ if num == 1:",
"+ ans += i[0]",
"+ elif num == 2:",
"+ a, b = st",
"+ ans += math.gcd(a, b) * 3",
"+ else:",
"+ ans += math.gcd(math.gcd(i[0], i[1]), i[2]) * 6"
] | false | 0.155354 | 0.082617 | 1.880409 | [
"s623035891",
"s506843779"
] |
u955251526 | p03714 | python | s402795869 | s044979062 | 776 | 470 | 68,700 | 37,212 | Accepted | Accepted | 39.43 | n = int(eval(input()))
a = list(map(int, input().split()))
b = list(enumerate(a))
l = sorted(b[:2*n], key=lambda x: x[1], reverse=True)
r = sorted(b[n:], key=lambda x: x[1])
big = [0] * (3*n)
small = [0] * (3*n)
for i, (pos, z) in enumerate(l):
big[pos] = i
for i, (pos, z) in enumerate(r):
small[pos] = i
first = sum(a[:n])
second = 0
for pos, z in r[:n]:
second += z
i = 2 * n
j = n-1
ans = first - second
for split in range(n, 2*n):
if big[split] < i:
first += a[split]
i -= 1
while l[i][0] > split:
i -= 1
first -= l[i][1]
if small[split] <= j:
second -= a[split]
j += 1
while r[j][0] < split:
j += 1
second += r[j][1]
ans = max(ans, first - second)
print(ans) | import heapq
n = int(eval(input()))
a = list(map(int, input().split()))
h = a[:n]
heapq.heapify(h)
first = [0] * (n+1)
s = sum(a[:n])
first[0] = s
for i in range(n):
s += a[n+i]
heapq.heappush(h, a[n+i])
s -= heapq.heappop(h)
first[i+1] = s
h = list([-x for x in a[2*n:]])
heapq.heapify(h)
second = [0] * (n+1)
s = - sum(a[2*n:])
second[0] = s
for i in range(n):
s -= a[2*n - i - 1]
heapq.heappush(h, -a[2*n - i - 1])
s -= heapq.heappop(h)
second[i+1] = s
ans = - 10 ** 18
for i in range(n+1):
ans = max(ans, first[i] + second[n-i])
print(ans) | 38 | 30 | 812 | 610 | n = int(eval(input()))
a = list(map(int, input().split()))
b = list(enumerate(a))
l = sorted(b[: 2 * n], key=lambda x: x[1], reverse=True)
r = sorted(b[n:], key=lambda x: x[1])
big = [0] * (3 * n)
small = [0] * (3 * n)
for i, (pos, z) in enumerate(l):
big[pos] = i
for i, (pos, z) in enumerate(r):
small[pos] = i
first = sum(a[:n])
second = 0
for pos, z in r[:n]:
second += z
i = 2 * n
j = n - 1
ans = first - second
for split in range(n, 2 * n):
if big[split] < i:
first += a[split]
i -= 1
while l[i][0] > split:
i -= 1
first -= l[i][1]
if small[split] <= j:
second -= a[split]
j += 1
while r[j][0] < split:
j += 1
second += r[j][1]
ans = max(ans, first - second)
print(ans)
| import heapq
n = int(eval(input()))
a = list(map(int, input().split()))
h = a[:n]
heapq.heapify(h)
first = [0] * (n + 1)
s = sum(a[:n])
first[0] = s
for i in range(n):
s += a[n + i]
heapq.heappush(h, a[n + i])
s -= heapq.heappop(h)
first[i + 1] = s
h = list([-x for x in a[2 * n :]])
heapq.heapify(h)
second = [0] * (n + 1)
s = -sum(a[2 * n :])
second[0] = s
for i in range(n):
s -= a[2 * n - i - 1]
heapq.heappush(h, -a[2 * n - i - 1])
s -= heapq.heappop(h)
second[i + 1] = s
ans = -(10**18)
for i in range(n + 1):
ans = max(ans, first[i] + second[n - i])
print(ans)
| false | 21.052632 | [
"+import heapq",
"+",
"-b = list(enumerate(a))",
"-l = sorted(b[: 2 * n], key=lambda x: x[1], reverse=True)",
"-r = sorted(b[n:], key=lambda x: x[1])",
"-big = [0] * (3 * n)",
"-small = [0] * (3 * n)",
"-for i, (pos, z) in enumerate(l):",
"- big[pos] = i",
"-for i, (pos, z) in enumerate(r):",
"- small[pos] = i",
"-first = sum(a[:n])",
"-second = 0",
"-for pos, z in r[:n]:",
"- second += z",
"-i = 2 * n",
"-j = n - 1",
"-ans = first - second",
"-for split in range(n, 2 * n):",
"- if big[split] < i:",
"- first += a[split]",
"- i -= 1",
"- while l[i][0] > split:",
"- i -= 1",
"- first -= l[i][1]",
"- if small[split] <= j:",
"- second -= a[split]",
"- j += 1",
"- while r[j][0] < split:",
"- j += 1",
"- second += r[j][1]",
"- ans = max(ans, first - second)",
"+h = a[:n]",
"+heapq.heapify(h)",
"+first = [0] * (n + 1)",
"+s = sum(a[:n])",
"+first[0] = s",
"+for i in range(n):",
"+ s += a[n + i]",
"+ heapq.heappush(h, a[n + i])",
"+ s -= heapq.heappop(h)",
"+ first[i + 1] = s",
"+h = list([-x for x in a[2 * n :]])",
"+heapq.heapify(h)",
"+second = [0] * (n + 1)",
"+s = -sum(a[2 * n :])",
"+second[0] = s",
"+for i in range(n):",
"+ s -= a[2 * n - i - 1]",
"+ heapq.heappush(h, -a[2 * n - i - 1])",
"+ s -= heapq.heappop(h)",
"+ second[i + 1] = s",
"+ans = -(10**18)",
"+for i in range(n + 1):",
"+ ans = max(ans, first[i] + second[n - i])"
] | false | 0.047419 | 0.107574 | 0.440801 | [
"s402795869",
"s044979062"
] |
u837673618 | p02736 | python | s340242180 | s112489005 | 645 | 566 | 3,060 | 3,060 | Accepted | Accepted | 12.25 | import sys
N = int(eval(input())) - 1
two = False
S = 0
for i in range(N+1):
a = int(sys.stdin.read(1))
two |= (a == 2)
if i & N == i:
S ^= a-1
if two:
S &= ~2
print(S)
| import sys
N = int(eval(input())) - 1
two = False
S = 0
for i in range(N+1):
a = int(sys.stdin.read(1))
if not two:
two = a == 2
if i & N == i:
S ^= a-1
if two:
S &= ~2
print(S)
| 15 | 16 | 192 | 206 | import sys
N = int(eval(input())) - 1
two = False
S = 0
for i in range(N + 1):
a = int(sys.stdin.read(1))
two |= a == 2
if i & N == i:
S ^= a - 1
if two:
S &= ~2
print(S)
| import sys
N = int(eval(input())) - 1
two = False
S = 0
for i in range(N + 1):
a = int(sys.stdin.read(1))
if not two:
two = a == 2
if i & N == i:
S ^= a - 1
if two:
S &= ~2
print(S)
| false | 6.25 | [
"- two |= a == 2",
"+ if not two:",
"+ two = a == 2"
] | false | 0.042975 | 0.04196 | 1.024194 | [
"s340242180",
"s112489005"
] |
u078214750 | p03281 | python | s385548341 | s487860149 | 30 | 27 | 9,064 | 9,104 | Accepted | Accepted | 10 | import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(eval(input()))
ans = 0
for i in range(1, N+1, 2):
yaku = 0
for j in range(1, i+1):
if i%j==0:
yaku += 1
if yaku == 8:
ans += 1
print(ans)
| import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(eval(input()))
ans = 0
for n in range(1, N+1, 2):
yaku = 0
for i in range(1, n+1):
if n%i==0:
yaku += 1
if yaku == 8:
ans += 1
print(ans)
| 12 | 12 | 248 | 248 | import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(eval(input()))
ans = 0
for i in range(1, N + 1, 2):
yaku = 0
for j in range(1, i + 1):
if i % j == 0:
yaku += 1
if yaku == 8:
ans += 1
print(ans)
| import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(eval(input()))
ans = 0
for n in range(1, N + 1, 2):
yaku = 0
for i in range(1, n + 1):
if n % i == 0:
yaku += 1
if yaku == 8:
ans += 1
print(ans)
| false | 0 | [
"-for i in range(1, N + 1, 2):",
"+for n in range(1, N + 1, 2):",
"- for j in range(1, i + 1):",
"- if i % j == 0:",
"+ for i in range(1, n + 1):",
"+ if n % i == 0:"
] | false | 0.04625 | 0.040993 | 1.12824 | [
"s385548341",
"s487860149"
] |
u761320129 | p03566 | python | s523391179 | s984383030 | 81 | 71 | 3,500 | 4,624 | Accepted | Accepted | 12.35 | N = int(eval(input()))
ts = list(map(int,input().split()))
vs = list(map(int,input().split()))
maxv = [0]
for v,t in zip(vs,ts):
maxv[-1] = min(maxv[-1], v)
for ti in range(t*2):
maxv.append(v)
T = len(maxv)
for i in range(T-1):
maxv[i+1] = min(maxv[i+1], maxv[i] + 0.5)
maxv[-1] = 0
for i in reversed(list(range(T-1))):
maxv[i] = min(maxv[i], maxv[i+1] + 0.5)
ans = 0.0
for i in range(T-1):
ans += (maxv[i] + maxv[i+1]) * 0.25
print(ans)
| N = int(eval(input()))
T = list([int(x)*2 for x in input().split()])
V = list([int(x)*2 for x in input().split()])
sumt = sum(T)
maxv = [min(i, sumt-i) for i in range(sumt+1)]
ct = 0
for t,v in zip(T,V):
for i in range(ct,ct+t+1):
maxv[i] = min(maxv[i], v)
ct += t
for i in range(sumt):
maxv[i+1] = min(maxv[i+1], maxv[i] + 1)
for i in reversed(list(range(sumt))):
maxv[i] = min(maxv[i], maxv[i+1] + 1)
print((sum(maxv) / 4)) | 22 | 19 | 480 | 463 | N = int(eval(input()))
ts = list(map(int, input().split()))
vs = list(map(int, input().split()))
maxv = [0]
for v, t in zip(vs, ts):
maxv[-1] = min(maxv[-1], v)
for ti in range(t * 2):
maxv.append(v)
T = len(maxv)
for i in range(T - 1):
maxv[i + 1] = min(maxv[i + 1], maxv[i] + 0.5)
maxv[-1] = 0
for i in reversed(list(range(T - 1))):
maxv[i] = min(maxv[i], maxv[i + 1] + 0.5)
ans = 0.0
for i in range(T - 1):
ans += (maxv[i] + maxv[i + 1]) * 0.25
print(ans)
| N = int(eval(input()))
T = list([int(x) * 2 for x in input().split()])
V = list([int(x) * 2 for x in input().split()])
sumt = sum(T)
maxv = [min(i, sumt - i) for i in range(sumt + 1)]
ct = 0
for t, v in zip(T, V):
for i in range(ct, ct + t + 1):
maxv[i] = min(maxv[i], v)
ct += t
for i in range(sumt):
maxv[i + 1] = min(maxv[i + 1], maxv[i] + 1)
for i in reversed(list(range(sumt))):
maxv[i] = min(maxv[i], maxv[i + 1] + 1)
print((sum(maxv) / 4))
| false | 13.636364 | [
"-ts = list(map(int, input().split()))",
"-vs = list(map(int, input().split()))",
"-maxv = [0]",
"-for v, t in zip(vs, ts):",
"- maxv[-1] = min(maxv[-1], v)",
"- for ti in range(t * 2):",
"- maxv.append(v)",
"-T = len(maxv)",
"-for i in range(T - 1):",
"- maxv[i + 1] = min(maxv[i + 1], maxv[i] + 0.5)",
"-maxv[-1] = 0",
"-for i in reversed(list(range(T - 1))):",
"- maxv[i] = min(maxv[i], maxv[i + 1] + 0.5)",
"-ans = 0.0",
"-for i in range(T - 1):",
"- ans += (maxv[i] + maxv[i + 1]) * 0.25",
"-print(ans)",
"+T = list([int(x) * 2 for x in input().split()])",
"+V = list([int(x) * 2 for x in input().split()])",
"+sumt = sum(T)",
"+maxv = [min(i, sumt - i) for i in range(sumt + 1)]",
"+ct = 0",
"+for t, v in zip(T, V):",
"+ for i in range(ct, ct + t + 1):",
"+ maxv[i] = min(maxv[i], v)",
"+ ct += t",
"+for i in range(sumt):",
"+ maxv[i + 1] = min(maxv[i + 1], maxv[i] + 1)",
"+for i in reversed(list(range(sumt))):",
"+ maxv[i] = min(maxv[i], maxv[i + 1] + 1)",
"+print((sum(maxv) / 4))"
] | false | 0.038154 | 0.039568 | 0.964249 | [
"s523391179",
"s984383030"
] |
u057109575 | p02962 | python | s339106213 | s338355466 | 408 | 330 | 151,400 | 87,372 | Accepted | Accepted | 19.12 | s = eval(input())
t = eval(input())
def z_algorithm(s):
n = len(s)
res = [0] * n
i = 1
j = 0
while i < n:
# i番目以降の一致文字数
while i + j < n and s[j] == s[i + j]:
j += 1
res[i] = j
# 一文字も一致しない場合,次の文字へ
if j == 0:
i += 1
continue
# 一致したところまでを埋める
k = 1
while i + k < n and k + res[k] < j:
res[i + k] = res[k]
k += 1
i += k
j -= k
return res
n = len(t)
if n > len(s):
ss = s * (n // len(s) + 1)
else:
ss = s * 2
z = z_algorithm(t + ss * 2)
z = [min(z[i], n) for i in range(n, len(z))]
ans = 0
for i in range(n):
c = 0
for v in z[i::n]:
if v == n:
c += 1
else:
c = 0
ans = max(ans, c)
if ans <= len(ss) // n:
print(ans)
else:
print((-1))
| s = eval(input())
t = eval(input())
def z_algorithm(s):
n = len(s)
res = [0] * n
i = 1
j = 0
while i < n:
# i番目以降の一致文字数
while i + j < n and s[j] == s[i + j]:
j += 1
res[i] = j
# 一文字も一致しない場合,次の文字へ
if j == 0:
i += 1
continue
# 一致したところまでを埋める
k = 1
while i + k < n and k + res[k] < j:
res[i + k] = res[k]
k += 1
i += k
j -= k
return res
n = len(t)
if n > len(s):
ss = s * (n // len(s) + 1)
else:
ss = s * 2
z = z_algorithm(t + ss * 2)
ans = 0
for i in range(n):
c = 0
for v in z[n + i::n]:
if v >= n:
c += 1
else:
c = 0
ans = max(ans, c)
if ans <= len(ss) // n:
print(ans)
else:
print((-1))
| 54 | 52 | 937 | 893 | s = eval(input())
t = eval(input())
def z_algorithm(s):
n = len(s)
res = [0] * n
i = 1
j = 0
while i < n:
# i番目以降の一致文字数
while i + j < n and s[j] == s[i + j]:
j += 1
res[i] = j
# 一文字も一致しない場合,次の文字へ
if j == 0:
i += 1
continue
# 一致したところまでを埋める
k = 1
while i + k < n and k + res[k] < j:
res[i + k] = res[k]
k += 1
i += k
j -= k
return res
n = len(t)
if n > len(s):
ss = s * (n // len(s) + 1)
else:
ss = s * 2
z = z_algorithm(t + ss * 2)
z = [min(z[i], n) for i in range(n, len(z))]
ans = 0
for i in range(n):
c = 0
for v in z[i::n]:
if v == n:
c += 1
else:
c = 0
ans = max(ans, c)
if ans <= len(ss) // n:
print(ans)
else:
print((-1))
| s = eval(input())
t = eval(input())
def z_algorithm(s):
n = len(s)
res = [0] * n
i = 1
j = 0
while i < n:
# i番目以降の一致文字数
while i + j < n and s[j] == s[i + j]:
j += 1
res[i] = j
# 一文字も一致しない場合,次の文字へ
if j == 0:
i += 1
continue
# 一致したところまでを埋める
k = 1
while i + k < n and k + res[k] < j:
res[i + k] = res[k]
k += 1
i += k
j -= k
return res
n = len(t)
if n > len(s):
ss = s * (n // len(s) + 1)
else:
ss = s * 2
z = z_algorithm(t + ss * 2)
ans = 0
for i in range(n):
c = 0
for v in z[n + i :: n]:
if v >= n:
c += 1
else:
c = 0
ans = max(ans, c)
if ans <= len(ss) // n:
print(ans)
else:
print((-1))
| false | 3.703704 | [
"-z = [min(z[i], n) for i in range(n, len(z))]",
"- for v in z[i::n]:",
"- if v == n:",
"+ for v in z[n + i :: n]:",
"+ if v >= n:"
] | false | 0.036607 | 0.063614 | 0.575445 | [
"s339106213",
"s338355466"
] |
u759412327 | p03835 | python | s775725551 | s023378311 | 1,021 | 805 | 9,104 | 57,776 | Accepted | Accepted | 21.16 | K,S = list(map(int,input().split()))
a = 0
for X in range(K+1):
for Y in range(K+1):
if 0<=S-X-Y<=K:
a+=1
print(a) | K,S = list(map(int,input().split()))
print((sum([0<=S-X-Y<=K for X in range(K+1) for Y in range(K+1)]))) | 9 | 2 | 130 | 97 | K, S = list(map(int, input().split()))
a = 0
for X in range(K + 1):
for Y in range(K + 1):
if 0 <= S - X - Y <= K:
a += 1
print(a)
| K, S = list(map(int, input().split()))
print((sum([0 <= S - X - Y <= K for X in range(K + 1) for Y in range(K + 1)])))
| false | 77.777778 | [
"-a = 0",
"-for X in range(K + 1):",
"- for Y in range(K + 1):",
"- if 0 <= S - X - Y <= K:",
"- a += 1",
"-print(a)",
"+print((sum([0 <= S - X - Y <= K for X in range(K + 1) for Y in range(K + 1)])))"
] | false | 0.041767 | 0.080216 | 0.520674 | [
"s775725551",
"s023378311"
] |
u469254913 | p02624 | python | s555630302 | s307244503 | 783 | 562 | 108,856 | 108,988 | Accepted | Accepted | 28.22 | # import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit
@njit
def sum_g(N):
res = 0
for i in range(1,N+1):
end = N // i
res += end * (end + 1) * i // 2
return res
def main():
N = int(eval(input()))
res = sum_g(N)
print(res)
main()
| # import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit,i8
@njit(i8(i8))
def sum_g(N):
res = 0
for i in range(1,N+1):
end = N // i
res += end * (end + 1) * i // 2
return res
def main():
N = int(eval(input()))
res = sum_g(N)
print(res)
main()
| 28 | 28 | 418 | 428 | # import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit
@njit
def sum_g(N):
res = 0
for i in range(1, N + 1):
end = N // i
res += end * (end + 1) * i // 2
return res
def main():
N = int(eval(input()))
res = sum_g(N)
print(res)
main()
| # import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit, i8
@njit(i8(i8))
def sum_g(N):
res = 0
for i in range(1, N + 1):
end = N // i
res += end * (end + 1) * i // 2
return res
def main():
N = int(eval(input()))
res = sum_g(N)
print(res)
main()
| false | 0 | [
"-from numba import njit",
"+from numba import njit, i8",
"-@njit",
"+@njit(i8(i8))"
] | false | 0.038373 | 0.048556 | 0.790289 | [
"s555630302",
"s307244503"
] |
u816631826 | p03986 | python | s713371882 | s644712879 | 53 | 45 | 4,456 | 2,948 | Accepted | Accepted | 15.09 | #!/usr/bin/env python
s = input()
s1 = []
for x in s:
if not s1:
s1.append(x)
continue
if x == 'T' and s1[-1] == 'S':
# s1 = s1[:-1]
del s1[-1]
else:
s1.append(x)
print(len(s1))
| s = input()
sn = 0
tn = 0
for i in s:
if i == "S":
sn += 1
elif i == "T":
tn += 1
if sn > 0:
sn -= 1
tn -= 1
print(sn + tn) | 16 | 12 | 212 | 151 | #!/usr/bin/env python
s = input()
s1 = []
for x in s:
if not s1:
s1.append(x)
continue
if x == "T" and s1[-1] == "S":
# s1 = s1[:-1]
del s1[-1]
else:
s1.append(x)
print(len(s1))
| s = input()
sn = 0
tn = 0
for i in s:
if i == "S":
sn += 1
elif i == "T":
tn += 1
if sn > 0:
sn -= 1
tn -= 1
print(sn + tn)
| false | 25 | [
"-#!/usr/bin/env python",
"-s1 = []",
"-for x in s:",
"- if not s1:",
"- s1.append(x)",
"- continue",
"- if x == \"T\" and s1[-1] == \"S\":",
"- # s1 = s1[:-1]",
"- del s1[-1]",
"- else:",
"- s1.append(x)",
"-print(len(s1))",
"+sn = 0",
"+tn = 0",
"+for i in s:",
"+ if i == \"S\":",
"+ sn += 1",
"+ elif i == \"T\":",
"+ tn += 1",
"+ if sn > 0:",
"+ sn -= 1",
"+ tn -= 1",
"+print(sn + tn)"
] | false | 0.04347 | 0.134009 | 0.324382 | [
"s713371882",
"s644712879"
] |
u017810624 | p02901 | python | s286768198 | s789544637 | 516 | 470 | 82,632 | 81,880 | Accepted | Accepted | 8.91 | from operator import itemgetter
n,m=list(map(int,input().split()))
l=[]
for i in range(m):
l2=[]
a,b=list(map(int,input().split()))
l2.append(a)
x=list(map(int,input().split()))
ct=0
for i in range(n):
if i+1 in x:
ct+=2**i
l2.append(ct)
l.append(l2)
dp=[[999999999999 for i in range(2**n)] for j in range(m+1)]
dp[0][0]=0
for i in range(1,m+1):
for j in range(2**n):
dp[i][j|l[i-1][1]]=min(dp[i-1][j|l[i-1][1]],dp[i-1][j]+l[i-1][0],dp[i][j|l[i-1][1]])
for j in range(2**n):
dp[i][j]=min(dp[i][j],dp[i-1][j])
if dp[m][2**n-1]<10**11:
print((dp[m][2**n-1]))
else:
print((-1)) | from operator import itemgetter
n,m=list(map(int,input().split()))
l=[]
for i in range(m):
l2=[]
a,b=list(map(int,input().split()))
l2.append(a)
x=list(map(int,input().split()))
ct=0
for i in range(n):
if i+1 in x:
ct+=2**i
l2.append(ct)
l.append(l2)
dp=[[999999999999 for i in range(2**n)] for j in range(m+1)]
dp[0][0]=0
for i in range(1,m+1):
for j in range(2**n):
dp[i][j|l[i-1][1]]=min(dp[i-1][j]+l[i-1][0],dp[i][j|l[i-1][1]])
for j in range(2**n):
dp[i][j]=min(dp[i][j],dp[i-1][j])
if dp[m][2**n-1]<10**11:
print((dp[m][2**n-1]))
else:
print((-1))
| 27 | 27 | 628 | 608 | from operator import itemgetter
n, m = list(map(int, input().split()))
l = []
for i in range(m):
l2 = []
a, b = list(map(int, input().split()))
l2.append(a)
x = list(map(int, input().split()))
ct = 0
for i in range(n):
if i + 1 in x:
ct += 2**i
l2.append(ct)
l.append(l2)
dp = [[999999999999 for i in range(2**n)] for j in range(m + 1)]
dp[0][0] = 0
for i in range(1, m + 1):
for j in range(2**n):
dp[i][j | l[i - 1][1]] = min(
dp[i - 1][j | l[i - 1][1]],
dp[i - 1][j] + l[i - 1][0],
dp[i][j | l[i - 1][1]],
)
for j in range(2**n):
dp[i][j] = min(dp[i][j], dp[i - 1][j])
if dp[m][2**n - 1] < 10**11:
print((dp[m][2**n - 1]))
else:
print((-1))
| from operator import itemgetter
n, m = list(map(int, input().split()))
l = []
for i in range(m):
l2 = []
a, b = list(map(int, input().split()))
l2.append(a)
x = list(map(int, input().split()))
ct = 0
for i in range(n):
if i + 1 in x:
ct += 2**i
l2.append(ct)
l.append(l2)
dp = [[999999999999 for i in range(2**n)] for j in range(m + 1)]
dp[0][0] = 0
for i in range(1, m + 1):
for j in range(2**n):
dp[i][j | l[i - 1][1]] = min(dp[i - 1][j] + l[i - 1][0], dp[i][j | l[i - 1][1]])
for j in range(2**n):
dp[i][j] = min(dp[i][j], dp[i - 1][j])
if dp[m][2**n - 1] < 10**11:
print((dp[m][2**n - 1]))
else:
print((-1))
| false | 0 | [
"- dp[i][j | l[i - 1][1]] = min(",
"- dp[i - 1][j | l[i - 1][1]],",
"- dp[i - 1][j] + l[i - 1][0],",
"- dp[i][j | l[i - 1][1]],",
"- )",
"+ dp[i][j | l[i - 1][1]] = min(dp[i - 1][j] + l[i - 1][0], dp[i][j | l[i - 1][1]])"
] | false | 0.044341 | 0.044751 | 0.990837 | [
"s286768198",
"s789544637"
] |
u864197622 | p03246 | python | s782933560 | s070103270 | 183 | 87 | 17,116 | 18,656 | Accepted | Accepted | 52.46 | from collections import Counter as C
n = int(eval(input()))
v = [int(a) for a in input().split()]
k1 = C(v[::2]).most_common()[0][0]
v1 = C(v[::2]).most_common()[0][1]
if v1 == n/2:
k2 = 0
v2 = 0
else:
k2 = C(v[::2]).most_common()[1][0]
v2 = C(v[::2]).most_common()[1][1]
k3 = C(v[1::2]).most_common()[0][0]
v3 = C(v[1::2]).most_common()[0][1]
if v3 == n/2:
k4 = 0
v4 = 0
else:
k4 = C(v[1::2]).most_common()[1][0]
v4 = C(v[1::2]).most_common()[1][1]
if k1 != k3:
print((n - v1 - v3))
else:
print((min(n - v1 - v4, n - v2 - v3))) | from collections import Counter as C
n = int(eval(input()))
v = [int(a) for a in input().split()]
a=C(v[::2])
b=C(v[1::2])
a[0]=b[0]=0
a=a.most_common()
b=b.most_common()
if a[0][0] != b[0][0]:
print((n-a[0][1]-b[0][1]))
else:
print((min(n-a[1][1]-b[0][1],n-a[0][1]-b[1][1])))
| 28 | 13 | 592 | 290 | from collections import Counter as C
n = int(eval(input()))
v = [int(a) for a in input().split()]
k1 = C(v[::2]).most_common()[0][0]
v1 = C(v[::2]).most_common()[0][1]
if v1 == n / 2:
k2 = 0
v2 = 0
else:
k2 = C(v[::2]).most_common()[1][0]
v2 = C(v[::2]).most_common()[1][1]
k3 = C(v[1::2]).most_common()[0][0]
v3 = C(v[1::2]).most_common()[0][1]
if v3 == n / 2:
k4 = 0
v4 = 0
else:
k4 = C(v[1::2]).most_common()[1][0]
v4 = C(v[1::2]).most_common()[1][1]
if k1 != k3:
print((n - v1 - v3))
else:
print((min(n - v1 - v4, n - v2 - v3)))
| from collections import Counter as C
n = int(eval(input()))
v = [int(a) for a in input().split()]
a = C(v[::2])
b = C(v[1::2])
a[0] = b[0] = 0
a = a.most_common()
b = b.most_common()
if a[0][0] != b[0][0]:
print((n - a[0][1] - b[0][1]))
else:
print((min(n - a[1][1] - b[0][1], n - a[0][1] - b[1][1])))
| false | 53.571429 | [
"-k1 = C(v[::2]).most_common()[0][0]",
"-v1 = C(v[::2]).most_common()[0][1]",
"-if v1 == n / 2:",
"- k2 = 0",
"- v2 = 0",
"+a = C(v[::2])",
"+b = C(v[1::2])",
"+a[0] = b[0] = 0",
"+a = a.most_common()",
"+b = b.most_common()",
"+if a[0][0] != b[0][0]:",
"+ print((n - a[0][1] - b[0][1]))",
"- k2 = C(v[::2]).most_common()[1][0]",
"- v2 = C(v[::2]).most_common()[1][1]",
"-k3 = C(v[1::2]).most_common()[0][0]",
"-v3 = C(v[1::2]).most_common()[0][1]",
"-if v3 == n / 2:",
"- k4 = 0",
"- v4 = 0",
"-else:",
"- k4 = C(v[1::2]).most_common()[1][0]",
"- v4 = C(v[1::2]).most_common()[1][1]",
"-if k1 != k3:",
"- print((n - v1 - v3))",
"-else:",
"- print((min(n - v1 - v4, n - v2 - v3)))",
"+ print((min(n - a[1][1] - b[0][1], n - a[0][1] - b[1][1])))"
] | false | 0.047028 | 0.125716 | 0.374083 | [
"s782933560",
"s070103270"
] |
u410118019 | p03038 | python | s386769840 | s284200974 | 680 | 431 | 52,244 | 24,776 | Accepted | Accepted | 36.62 | n,m = list(map(int,input().split()))
bc = {}
a = list(input().split())
for i in a:
if i in bc:
bc[i] += 1
else:
bc[i] = 1
for i in range(m):
b,c = input().split()
b = int(b)
if c in bc:
bc[c] += b
else:
bc.update({c:b})
key = sorted(bc)
for k in range(len(key)):
key[k] = int(key[k])
key.sort()
key.reverse()
for k in range(len(key)):
key[k] = str(key[k])
c = 0
s = 0
for i in key:
if i in bc:
s += int(i) * bc[i]
c += bc[i]
if c > n:
s -= int(i) * (c-n)
c -= c-n
if c == n:
break
print(s) | n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = []
for i in range(m):
b,c = list(map(int,input().split()))
bc.append((b,c))
bc = sorted(bc,key=lambda x:x[1])
bc.reverse()
count = 0
for b,c in bc:
count += b
a += [c] * b
if count >= n:
break
a.sort()
a.reverse()
print((sum(a[:n]))) | 34 | 17 | 580 | 326 | n, m = list(map(int, input().split()))
bc = {}
a = list(input().split())
for i in a:
if i in bc:
bc[i] += 1
else:
bc[i] = 1
for i in range(m):
b, c = input().split()
b = int(b)
if c in bc:
bc[c] += b
else:
bc.update({c: b})
key = sorted(bc)
for k in range(len(key)):
key[k] = int(key[k])
key.sort()
key.reverse()
for k in range(len(key)):
key[k] = str(key[k])
c = 0
s = 0
for i in key:
if i in bc:
s += int(i) * bc[i]
c += bc[i]
if c > n:
s -= int(i) * (c - n)
c -= c - n
if c == n:
break
print(s)
| n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = []
for i in range(m):
b, c = list(map(int, input().split()))
bc.append((b, c))
bc = sorted(bc, key=lambda x: x[1])
bc.reverse()
count = 0
for b, c in bc:
count += b
a += [c] * b
if count >= n:
break
a.sort()
a.reverse()
print((sum(a[:n])))
| false | 50 | [
"-bc = {}",
"-a = list(input().split())",
"-for i in a:",
"- if i in bc:",
"- bc[i] += 1",
"- else:",
"- bc[i] = 1",
"+a = list(map(int, input().split()))",
"+bc = []",
"- b, c = input().split()",
"- b = int(b)",
"- if c in bc:",
"- bc[c] += b",
"- else:",
"- bc.update({c: b})",
"-key = sorted(bc)",
"-for k in range(len(key)):",
"- key[k] = int(key[k])",
"-key.sort()",
"-key.reverse()",
"-for k in range(len(key)):",
"- key[k] = str(key[k])",
"-c = 0",
"-s = 0",
"-for i in key:",
"- if i in bc:",
"- s += int(i) * bc[i]",
"- c += bc[i]",
"- if c > n:",
"- s -= int(i) * (c - n)",
"- c -= c - n",
"- if c == n:",
"+ b, c = list(map(int, input().split()))",
"+ bc.append((b, c))",
"+bc = sorted(bc, key=lambda x: x[1])",
"+bc.reverse()",
"+count = 0",
"+for b, c in bc:",
"+ count += b",
"+ a += [c] * b",
"+ if count >= n:",
"-print(s)",
"+a.sort()",
"+a.reverse()",
"+print((sum(a[:n])))"
] | false | 0.046191 | 0.046579 | 0.991672 | [
"s386769840",
"s284200974"
] |
u255943004 | p02936 | python | s093644768 | s636509512 | 1,977 | 492 | 133,036 | 124,116 | Accepted | Accepted | 75.11 | N,Q = list(map(int,input().split()))
AB = [[] for _ in range(N-1)]
for n in range(N-1):
AB[n] = list(map(int,input().split()))
PX = [[] for _ in range(Q)]
for q in range(Q):
PX[q] = list(map(int,input().split()))
graph = [[] for _ in range(N+1)]
for ab in AB:
graph[ab[0]].append(ab[1])
graph[ab[1]].append(ab[0])
val = [0] * (N+1)
for px in PX:
val[px[0]] += px[1]
parent = [0] * (N+1)
from collections import deque
Q = deque([1])
while Q:
q = Q.popleft()
for c in graph[q]:
if c == parent[q]:
continue
parent[c] = q
Q.append(c)
val[c] += val[q]
print((*val[1:]))
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,Q = list(map(int,readline().split()))
ABPX = list(map(int,read().split()))
AB = iter(ABPX[:N+N-2])
PX = iter(ABPX[N+N-2:])
graph = [[] for _ in range(N+1)]
for a,b in zip(AB,AB):
graph[a].append(b)
graph[b].append(a)
val = [0] * (N+1)
for p,x in zip(PX,PX):
val[p] += x
stack = [1]
parent = [0] * (N+1)
while stack:
x = stack.pop()
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
val[y] += val[x]
print((' '.join(map(str,val[1:]))))
| 26 | 32 | 655 | 673 | N, Q = list(map(int, input().split()))
AB = [[] for _ in range(N - 1)]
for n in range(N - 1):
AB[n] = list(map(int, input().split()))
PX = [[] for _ in range(Q)]
for q in range(Q):
PX[q] = list(map(int, input().split()))
graph = [[] for _ in range(N + 1)]
for ab in AB:
graph[ab[0]].append(ab[1])
graph[ab[1]].append(ab[0])
val = [0] * (N + 1)
for px in PX:
val[px[0]] += px[1]
parent = [0] * (N + 1)
from collections import deque
Q = deque([1])
while Q:
q = Q.popleft()
for c in graph[q]:
if c == parent[q]:
continue
parent[c] = q
Q.append(c)
val[c] += val[q]
print((*val[1:]))
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, Q = list(map(int, readline().split()))
ABPX = list(map(int, read().split()))
AB = iter(ABPX[: N + N - 2])
PX = iter(ABPX[N + N - 2 :])
graph = [[] for _ in range(N + 1)]
for a, b in zip(AB, AB):
graph[a].append(b)
graph[b].append(a)
val = [0] * (N + 1)
for p, x in zip(PX, PX):
val[p] += x
stack = [1]
parent = [0] * (N + 1)
while stack:
x = stack.pop()
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
val[y] += val[x]
print((" ".join(map(str, val[1:]))))
| false | 18.75 | [
"-N, Q = list(map(int, input().split()))",
"-AB = [[] for _ in range(N - 1)]",
"-for n in range(N - 1):",
"- AB[n] = list(map(int, input().split()))",
"-PX = [[] for _ in range(Q)]",
"-for q in range(Q):",
"- PX[q] = list(map(int, input().split()))",
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+N, Q = list(map(int, readline().split()))",
"+ABPX = list(map(int, read().split()))",
"+AB = iter(ABPX[: N + N - 2])",
"+PX = iter(ABPX[N + N - 2 :])",
"-for ab in AB:",
"- graph[ab[0]].append(ab[1])",
"- graph[ab[1]].append(ab[0])",
"+for a, b in zip(AB, AB):",
"+ graph[a].append(b)",
"+ graph[b].append(a)",
"-for px in PX:",
"- val[px[0]] += px[1]",
"+for p, x in zip(PX, PX):",
"+ val[p] += x",
"+stack = [1]",
"-from collections import deque",
"-",
"-Q = deque([1])",
"-while Q:",
"- q = Q.popleft()",
"- for c in graph[q]:",
"- if c == parent[q]:",
"+while stack:",
"+ x = stack.pop()",
"+ for y in graph[x]:",
"+ if y == parent[x]:",
"- parent[c] = q",
"- Q.append(c)",
"- val[c] += val[q]",
"-print((*val[1:]))",
"+ parent[y] = x",
"+ stack.append(y)",
"+ val[y] += val[x]",
"+print((\" \".join(map(str, val[1:]))))"
] | false | 0.046999 | 0.067808 | 0.693114 | [
"s093644768",
"s636509512"
] |
u680851063 | p03779 | python | s053562329 | s037078276 | 42 | 37 | 10,600 | 9,088 | Accepted | Accepted | 11.9 | x = int(eval(input()))
i=1
cum=[0]
while cum[-1] < 10**9:
cum+=[cum[-1]+i]
i+=1
import bisect
index = bisect.bisect_left(cum, x)
print(index) | x = int(eval(input()))
i=1
while i*(i+1)//2 < x:
i+=1
print(i) | 12 | 7 | 157 | 68 | x = int(eval(input()))
i = 1
cum = [0]
while cum[-1] < 10**9:
cum += [cum[-1] + i]
i += 1
import bisect
index = bisect.bisect_left(cum, x)
print(index)
| x = int(eval(input()))
i = 1
while i * (i + 1) // 2 < x:
i += 1
print(i)
| false | 41.666667 | [
"-cum = [0]",
"-while cum[-1] < 10**9:",
"- cum += [cum[-1] + i]",
"+while i * (i + 1) // 2 < x:",
"-import bisect",
"-",
"-index = bisect.bisect_left(cum, x)",
"-print(index)",
"+print(i)"
] | false | 0.071979 | 0.046585 | 1.545093 | [
"s053562329",
"s037078276"
] |
u310678820 | p02788 | python | s673385800 | s926250954 | 1,577 | 1,237 | 88,428 | 96,348 | Accepted | Accepted | 21.56 | import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]
XH.sort()
X = [XH[i][0] for i in range(N)]
ans = 0
res = 0
from bisect import bisect_left
cnt = [0]*(N+1)
for i in range(N):
x, h = XH[i]
res-=cnt[i]
h-=res
if h<=0:
continue
n = ((h-1)//A+1)
j = bisect_left(XH, [x+D*2+1, -1])
cnt[j] += n*A
res += n*A
ans+=n
print(ans)
| import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]
XH.sort(key = lambda x:x[0])
X = [XH[i][0] for i in range(N)]
ans = 0
res = 0
from bisect import bisect_left
cnt = [0]*(N+1)
for i in range(N):
x, h = XH[i]
res-=cnt[i]
h-=res
if h<=0:
continue
n = ((h-1)//A+1)
j = bisect_left(XH, [x+D*2+1, -1])
cnt[j] += n*A
res += n*A
ans+=n
print(ans)
| 26 | 26 | 478 | 497 | import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]
XH.sort()
X = [XH[i][0] for i in range(N)]
ans = 0
res = 0
from bisect import bisect_left
cnt = [0] * (N + 1)
for i in range(N):
x, h = XH[i]
res -= cnt[i]
h -= res
if h <= 0:
continue
n = (h - 1) // A + 1
j = bisect_left(XH, [x + D * 2 + 1, -1])
cnt[j] += n * A
res += n * A
ans += n
print(ans)
| import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]
XH.sort(key=lambda x: x[0])
X = [XH[i][0] for i in range(N)]
ans = 0
res = 0
from bisect import bisect_left
cnt = [0] * (N + 1)
for i in range(N):
x, h = XH[i]
res -= cnt[i]
h -= res
if h <= 0:
continue
n = (h - 1) // A + 1
j = bisect_left(XH, [x + D * 2 + 1, -1])
cnt[j] += n * A
res += n * A
ans += n
print(ans)
| false | 0 | [
"-XH.sort()",
"+XH.sort(key=lambda x: x[0])"
] | false | 0.03871 | 0.066612 | 0.581126 | [
"s673385800",
"s926250954"
] |
u021019433 | p02873 | python | s089451709 | s841768397 | 270 | 206 | 4,104 | 4,104 | Accepted | Accepted | 23.7 | r = p = 0
l = [0, 0]
for c in eval(input()):
f = c == '<'
if c != p:
p = c
if f:
r -= min(l)
l = [0, 0]
l[f] += 1
r += l[f]
if not f:
r -= min(l)
print(r)
| r = l = p = lp = 0
for c in eval(input()):
if c != p:
if c == '<':
r -= min(l, lp)
p = c
lp = l
l = 0
l += 1
r += l
if p == '>':
r -= min(l, lp)
print(r)
| 14 | 13 | 222 | 223 | r = p = 0
l = [0, 0]
for c in eval(input()):
f = c == "<"
if c != p:
p = c
if f:
r -= min(l)
l = [0, 0]
l[f] += 1
r += l[f]
if not f:
r -= min(l)
print(r)
| r = l = p = lp = 0
for c in eval(input()):
if c != p:
if c == "<":
r -= min(l, lp)
p = c
lp = l
l = 0
l += 1
r += l
if p == ">":
r -= min(l, lp)
print(r)
| false | 7.142857 | [
"-r = p = 0",
"-l = [0, 0]",
"+r = l = p = lp = 0",
"- f = c == \"<\"",
"+ if c == \"<\":",
"+ r -= min(l, lp)",
"- if f:",
"- r -= min(l)",
"- l = [0, 0]",
"- l[f] += 1",
"- r += l[f]",
"-if not f:",
"- r -= min(l)",
"+ lp = l",
"+ l = 0",
"+ l += 1",
"+ r += l",
"+if p == \">\":",
"+ r -= min(l, lp)"
] | false | 0.037103 | 0.036956 | 1.00397 | [
"s089451709",
"s841768397"
] |
u554781254 | p02971 | python | s400754218 | s058977231 | 411 | 355 | 62,428 | 14,720 | Accepted | Accepted | 13.63 | import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations, combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop
INF = float('inf')
NIL = - 1
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
max_a = max(A)
max_idx = [i for i, x in enumerate(A) if x == max_a]
if len(max_idx) > 1:
for i in range(N):
print(max_a)
exit()
else:
for i in max_idx:
A[i] = NIL
second_max = max(A)
for i in range(N):
if i in max_idx:
print(second_max)
else:
print(max_a)
| import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations, combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop
INF = float('inf')
NIL = - 1
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
sort_a = sorted(A, reverse=True)
for a in A:
print((sort_a[0] if a != sort_a[0] else sort_a[1]))
# max_a = max(A)
# max_idx = [i for i, x in enumerate(A) if x == max_a]
#
# if len(max_idx) > 1:
# for i in range(N):
# print(max_a)
# exit()
# else:
# for i in max_idx:
# A[i] = NIL
# second_max = max(A)
#
# for i in range(N):
# if i in max_idx:
# print(second_max)
# else:
# print(max_a)
| 32 | 36 | 717 | 853 | import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
from itertools import permutations, combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop
INF = float("inf")
NIL = -1
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
max_a = max(A)
max_idx = [i for i, x in enumerate(A) if x == max_a]
if len(max_idx) > 1:
for i in range(N):
print(max_a)
exit()
else:
for i in max_idx:
A[i] = NIL
second_max = max(A)
for i in range(N):
if i in max_idx:
print(second_max)
else:
print(max_a)
| import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
from itertools import permutations, combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop
INF = float("inf")
NIL = -1
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
sort_a = sorted(A, reverse=True)
for a in A:
print((sort_a[0] if a != sort_a[0] else sort_a[1]))
# max_a = max(A)
# max_idx = [i for i, x in enumerate(A) if x == max_a]
#
# if len(max_idx) > 1:
# for i in range(N):
# print(max_a)
# exit()
# else:
# for i in max_idx:
# A[i] = NIL
# second_max = max(A)
#
# for i in range(N):
# if i in max_idx:
# print(second_max)
# else:
# print(max_a)
| false | 11.111111 | [
"-max_a = max(A)",
"-max_idx = [i for i, x in enumerate(A) if x == max_a]",
"-if len(max_idx) > 1:",
"- for i in range(N):",
"- print(max_a)",
"- exit()",
"-else:",
"- for i in max_idx:",
"- A[i] = NIL",
"- second_max = max(A)",
"- for i in range(N):",
"- if i in max_idx:",
"- print(second_max)",
"- else:",
"- print(max_a)",
"+sort_a = sorted(A, reverse=True)",
"+for a in A:",
"+ print((sort_a[0] if a != sort_a[0] else sort_a[1]))",
"+# max_a = max(A)",
"+# max_idx = [i for i, x in enumerate(A) if x == max_a]",
"+#",
"+# if len(max_idx) > 1:",
"+# for i in range(N):",
"+# print(max_a)",
"+# exit()",
"+# else:",
"+# for i in max_idx:",
"+# A[i] = NIL",
"+# second_max = max(A)",
"+#",
"+# for i in range(N):",
"+# if i in max_idx:",
"+# print(second_max)",
"+# else:",
"+# print(max_a)"
] | false | 0.040287 | 0.039668 | 1.01559 | [
"s400754218",
"s058977231"
] |
u517152997 | p02928 | python | s726837137 | s282764194 | 1,266 | 779 | 14,456 | 3,188 | Accepted | Accepted | 38.47 | # -*- coding: utf-8 -*-
#
import math
import sys
import itertools
import numpy as np
DIV_NUM = 1000000000 + 7
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
A = [int(x) for x in input().split()]
AA = np.array(A)
if N==1:
print((0))
exit()
# https://kira000.hatenadiary.jp/entry/2019/02/23/053917
def bubble_sort(A):
cnt = 0
for i in range(len(A)):
for j in range(len(A)-1, i, -1):
if A[j] < A[j-1]:
A[j], A[j-1] = A[j-1], A[j]
cnt += 1
return cnt
answer = bubble_sort(AA)
B = sorted(A)
q=0
p=B[0]
r=0
for i in range(1,N):
if B[i]>p:
p=B[i]
r=i
q += r
# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)
| # -*- coding: utf-8 -*-
#
import math
import sys
import itertools
DIV_NUM = 1000000000 + 7
N,K = list(map(int, input().split()))
A = [int(x) for x in input().split()]
if N==1:
print((0))
exit()
answer = 0
for i in range(len(A)):
for j in range(len(A)-1,i,-1):
if A[j]<A[j-1]:
A[j],A[j-1] = A[j-1],A[j]
answer += 1
q=0
p=A[0]
r=0
for i in range(1,N):
if A[i]>p:
p=A[i]
r=i
q += r
answer = answer % DIV_NUM
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)
| 50 | 37 | 933 | 633 | # -*- coding: utf-8 -*-
#
import math
import sys
import itertools
import numpy as np
DIV_NUM = 1000000000 + 7
INPUT_NUMS = list(map(int, input().split()))
N = int(INPUT_NUMS[0])
K = int(INPUT_NUMS[1])
A = [int(x) for x in input().split()]
AA = np.array(A)
if N == 1:
print((0))
exit()
# https://kira000.hatenadiary.jp/entry/2019/02/23/053917
def bubble_sort(A):
cnt = 0
for i in range(len(A)):
for j in range(len(A) - 1, i, -1):
if A[j] < A[j - 1]:
A[j], A[j - 1] = A[j - 1], A[j]
cnt += 1
return cnt
answer = bubble_sort(AA)
B = sorted(A)
q = 0
p = B[0]
r = 0
for i in range(1, N):
if B[i] > p:
p = B[i]
r = i
q += r
# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K - 1) // 2
answer = answer % DIV_NUM
print(answer)
| # -*- coding: utf-8 -*-
#
import math
import sys
import itertools
DIV_NUM = 1000000000 + 7
N, K = list(map(int, input().split()))
A = [int(x) for x in input().split()]
if N == 1:
print((0))
exit()
answer = 0
for i in range(len(A)):
for j in range(len(A) - 1, i, -1):
if A[j] < A[j - 1]:
A[j], A[j - 1] = A[j - 1], A[j]
answer += 1
q = 0
p = A[0]
r = 0
for i in range(1, N):
if A[i] > p:
p = A[i]
r = i
q += r
answer = answer % DIV_NUM
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K - 1) // 2
answer = answer % DIV_NUM
print(answer)
| false | 26 | [
"-import numpy as np",
"-INPUT_NUMS = list(map(int, input().split()))",
"-N = int(INPUT_NUMS[0])",
"-K = int(INPUT_NUMS[1])",
"+N, K = list(map(int, input().split()))",
"-AA = np.array(A)",
"-# https://kira000.hatenadiary.jp/entry/2019/02/23/053917",
"-def bubble_sort(A):",
"- cnt = 0",
"- for i in range(len(A)):",
"- for j in range(len(A) - 1, i, -1):",
"- if A[j] < A[j - 1]:",
"- A[j], A[j - 1] = A[j - 1], A[j]",
"- cnt += 1",
"- return cnt",
"-",
"-",
"-answer = bubble_sort(AA)",
"-B = sorted(A)",
"+answer = 0",
"+for i in range(len(A)):",
"+ for j in range(len(A) - 1, i, -1):",
"+ if A[j] < A[j - 1]:",
"+ A[j], A[j - 1] = A[j - 1], A[j]",
"+ answer += 1",
"-p = B[0]",
"+p = A[0]",
"- if B[i] > p:",
"- p = B[i]",
"+ if A[i] > p:",
"+ p = A[i]",
"-# print(answer,K)",
"-answer = int(answer)"
] | false | 0.223365 | 0.039558 | 5.646499 | [
"s726837137",
"s282764194"
] |
u581187895 | p02923 | python | s468745585 | s361866381 | 177 | 81 | 24,232 | 15,020 | Accepted | Accepted | 54.24 | import numpy as np
N = int(eval(input()))
H = np.array(input().split(), dtype=np.int32)
"""
A = [10,4,8,7,3]
left_idx = [0,0,2,2,2]
というものを作る
"""
left_idx = np.arange(N)
left_idx[1:][H[:-1] >= H[1:]] = 0
np.maximum.accumulate(left_idx, out=left_idx)
ans = (np.arange(N) - left_idx).max()
print(ans) | N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
count = 0
for h1, h2 in zip(A, A[1:]):
count += 1
if h1 < h2:
count = 0
ans = max(ans, count)
print(ans) | 16 | 12 | 309 | 192 | import numpy as np
N = int(eval(input()))
H = np.array(input().split(), dtype=np.int32)
"""
A = [10,4,8,7,3]
left_idx = [0,0,2,2,2]
というものを作る
"""
left_idx = np.arange(N)
left_idx[1:][H[:-1] >= H[1:]] = 0
np.maximum.accumulate(left_idx, out=left_idx)
ans = (np.arange(N) - left_idx).max()
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
count = 0
for h1, h2 in zip(A, A[1:]):
count += 1
if h1 < h2:
count = 0
ans = max(ans, count)
print(ans)
| false | 25 | [
"-import numpy as np",
"-",
"-H = np.array(input().split(), dtype=np.int32)",
"-\"\"\"",
"-A = [10,4,8,7,3]",
"-left_idx = [0,0,2,2,2]",
"-というものを作る",
"-\"\"\"",
"-left_idx = np.arange(N)",
"-left_idx[1:][H[:-1] >= H[1:]] = 0",
"-np.maximum.accumulate(left_idx, out=left_idx)",
"-ans = (np.arange(N) - left_idx).max()",
"+A = list(map(int, input().split()))",
"+ans = 0",
"+count = 0",
"+for h1, h2 in zip(A, A[1:]):",
"+ count += 1",
"+ if h1 < h2:",
"+ count = 0",
"+ ans = max(ans, count)"
] | false | 0.234166 | 0.076881 | 3.045824 | [
"s468745585",
"s361866381"
] |
u581187895 | p03126 | python | s702975956 | s726634887 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | from collections import Counter
n, m = list(map(int, input().split()))
food_arr = []
total = 0
for i in range(n):
food_arr += list(map(int, input().split()[1:]))
counter = Counter(food_arr)
for key, value in list(counter.items()):
if value == n:
total += 1
print(total) | N, M = list(map(int, input().split()))
se = set(range(1,M+1))
for _ in range(N):
k, *A = list(map(int, input().split()))
se &= set(A)
print((len(se))) | 12 | 7 | 287 | 151 | from collections import Counter
n, m = list(map(int, input().split()))
food_arr = []
total = 0
for i in range(n):
food_arr += list(map(int, input().split()[1:]))
counter = Counter(food_arr)
for key, value in list(counter.items()):
if value == n:
total += 1
print(total)
| N, M = list(map(int, input().split()))
se = set(range(1, M + 1))
for _ in range(N):
k, *A = list(map(int, input().split()))
se &= set(A)
print((len(se)))
| false | 41.666667 | [
"-from collections import Counter",
"-",
"-n, m = list(map(int, input().split()))",
"-food_arr = []",
"-total = 0",
"-for i in range(n):",
"- food_arr += list(map(int, input().split()[1:]))",
"-counter = Counter(food_arr)",
"-for key, value in list(counter.items()):",
"- if value == n:",
"- total += 1",
"-print(total)",
"+N, M = list(map(int, input().split()))",
"+se = set(range(1, M + 1))",
"+for _ in range(N):",
"+ k, *A = list(map(int, input().split()))",
"+ se &= set(A)",
"+print((len(se)))"
] | false | 0.17194 | 0.161364 | 1.065538 | [
"s702975956",
"s726634887"
] |
u217303170 | p02915 | python | s040293165 | s884560794 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | n = int(eval(input()))
print((n*n*n))
| n = int(eval(input()))
print((n**3))
| 2 | 2 | 31 | 30 | n = int(eval(input()))
print((n * n * n))
| n = int(eval(input()))
print((n**3))
| false | 0 | [
"-print((n * n * n))",
"+print((n**3))"
] | false | 0.03585 | 0.035259 | 1.016741 | [
"s040293165",
"s884560794"
] |
u600402037 | p03416 | python | s278850556 | s748267746 | 59 | 48 | 2,940 | 2,940 | Accepted | Accepted | 18.64 | A, B = list(map(int, input().split()))
count = 0
for n in range(A, B+1):
n = str(n)
if n == n[::-1]:
count += 1
print(count)
| A, B = list(map(int, input().split()))
print((sum(n == n[::-1] for n in map(str, list(range(A, B+1)))))) | 7 | 2 | 141 | 91 | A, B = list(map(int, input().split()))
count = 0
for n in range(A, B + 1):
n = str(n)
if n == n[::-1]:
count += 1
print(count)
| A, B = list(map(int, input().split()))
print((sum(n == n[::-1] for n in map(str, list(range(A, B + 1))))))
| false | 71.428571 | [
"-count = 0",
"-for n in range(A, B + 1):",
"- n = str(n)",
"- if n == n[::-1]:",
"- count += 1",
"-print(count)",
"+print((sum(n == n[::-1] for n in map(str, list(range(A, B + 1))))))"
] | false | 0.062074 | 0.061232 | 1.013764 | [
"s278850556",
"s748267746"
] |
u396495667 | p03573 | python | s487111171 | s481384456 | 170 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90 | a,b,c = list(map(int, input().split()))
if a == b:
print(c)
elif a == c:
print(b)
else:
print(a) | a = [int(_) for _ in input().split()]
a.sort()
if a[0] == a[1]:
print((a[2]))
elif a[0] == a[2]:
print((a[1]))
else:
print((a[0])) | 8 | 8 | 104 | 137 | a, b, c = list(map(int, input().split()))
if a == b:
print(c)
elif a == c:
print(b)
else:
print(a)
| a = [int(_) for _ in input().split()]
a.sort()
if a[0] == a[1]:
print((a[2]))
elif a[0] == a[2]:
print((a[1]))
else:
print((a[0]))
| false | 0 | [
"-a, b, c = list(map(int, input().split()))",
"-if a == b:",
"- print(c)",
"-elif a == c:",
"- print(b)",
"+a = [int(_) for _ in input().split()]",
"+a.sort()",
"+if a[0] == a[1]:",
"+ print((a[2]))",
"+elif a[0] == a[2]:",
"+ print((a[1]))",
"- print(a)",
"+ print((a[0]))"
] | false | 0.032444 | 0.031741 | 1.022144 | [
"s487111171",
"s481384456"
] |
u222668979 | p03111 | python | s761623122 | s870640710 | 353 | 208 | 92,484 | 78,016 | Accepted | Accepted | 41.08 | from itertools import product
def solve(NUM, LIST):
lst = [l[i] for i, li in enumerate(LIST) if li == NUM]
if len(lst) == 0:
return 10 ** 5
ANS = (len(lst) - 1) * 10
ANS += abs(sum(lst) - target[NUM])
return ANS
target = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(target[0])]
ans = 10 ** 5
for pat in product([0, 1, 2, 3], repeat=target[0]):
tmp = sum(solve(i + 1, pat) for i in range(3))
ans = min(ans, tmp)
print(ans)
| from itertools import product
def solve(NUM, LIST):
lst = [l[i] for i, t in enumerate(LIST) if t == NUM]
if len(lst) == 0:
return 10 ** 5
ANS = (len(lst) - 1) * 10
ANS += abs(sum(lst) - tgt[NUM])
return ANS
tgt = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(tgt[0])]
ans = 10 ** 5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
tmp = sum(solve(i + 1, pttn) for i in range(3))
ans = min(ans, tmp)
print(ans)
| 18 | 18 | 498 | 486 | from itertools import product
def solve(NUM, LIST):
lst = [l[i] for i, li in enumerate(LIST) if li == NUM]
if len(lst) == 0:
return 10**5
ANS = (len(lst) - 1) * 10
ANS += abs(sum(lst) - target[NUM])
return ANS
target = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(target[0])]
ans = 10**5
for pat in product([0, 1, 2, 3], repeat=target[0]):
tmp = sum(solve(i + 1, pat) for i in range(3))
ans = min(ans, tmp)
print(ans)
| from itertools import product
def solve(NUM, LIST):
lst = [l[i] for i, t in enumerate(LIST) if t == NUM]
if len(lst) == 0:
return 10**5
ANS = (len(lst) - 1) * 10
ANS += abs(sum(lst) - tgt[NUM])
return ANS
tgt = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(tgt[0])]
ans = 10**5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
tmp = sum(solve(i + 1, pttn) for i in range(3))
ans = min(ans, tmp)
print(ans)
| false | 0 | [
"- lst = [l[i] for i, li in enumerate(LIST) if li == NUM]",
"+ lst = [l[i] for i, t in enumerate(LIST) if t == NUM]",
"- ANS += abs(sum(lst) - target[NUM])",
"+ ANS += abs(sum(lst) - tgt[NUM])",
"-target = list(map(int, input().split()))",
"-l = [int(eval(input())) for _ in range(target[0])]",
"+tgt = list(map(int, input().split()))",
"+l = [int(eval(input())) for _ in range(tgt[0])]",
"-for pat in product([0, 1, 2, 3], repeat=target[0]):",
"- tmp = sum(solve(i + 1, pat) for i in range(3))",
"+for pttn in product([0, 1, 2, 3], repeat=tgt[0]):",
"+ tmp = sum(solve(i + 1, pttn) for i in range(3))"
] | false | 0.333059 | 0.287914 | 1.156802 | [
"s761623122",
"s870640710"
] |
u111365362 | p02617 | python | s469702948 | s404490707 | 337 | 303 | 94,324 | 74,540 | Accepted | Accepted | 10.09 | n = int(eval(input()))
a = [i+1 for i in range(n)]
b = [1]
for i in range(1,n):
b.append(b[-1] + a[i])
c = [0]
for i in range(n-1):
c.append(c[-1]+b[i])
#print(a)
#print(b)
#print(c)
ans = b[-1] + c[-1]
for _ in range(n-1):
xy = list(map(int,input().split()))
xy.sort()
x,y = xy
ans -= x * (n+1-y)
print(ans) | n = int(eval(input()))
ans = n*(n+1)*(n+2)//6
for i in range(n-1):
xy = list(map(int,input().split()))
ans -= min(xy) * (n+1-max(xy))
print(ans) | 18 | 6 | 331 | 147 | n = int(eval(input()))
a = [i + 1 for i in range(n)]
b = [1]
for i in range(1, n):
b.append(b[-1] + a[i])
c = [0]
for i in range(n - 1):
c.append(c[-1] + b[i])
# print(a)
# print(b)
# print(c)
ans = b[-1] + c[-1]
for _ in range(n - 1):
xy = list(map(int, input().split()))
xy.sort()
x, y = xy
ans -= x * (n + 1 - y)
print(ans)
| n = int(eval(input()))
ans = n * (n + 1) * (n + 2) // 6
for i in range(n - 1):
xy = list(map(int, input().split()))
ans -= min(xy) * (n + 1 - max(xy))
print(ans)
| false | 66.666667 | [
"-a = [i + 1 for i in range(n)]",
"-b = [1]",
"-for i in range(1, n):",
"- b.append(b[-1] + a[i])",
"-c = [0]",
"+ans = n * (n + 1) * (n + 2) // 6",
"- c.append(c[-1] + b[i])",
"-# print(a)",
"-# print(b)",
"-# print(c)",
"-ans = b[-1] + c[-1]",
"-for _ in range(n - 1):",
"- xy.sort()",
"- x, y = xy",
"- ans -= x * (n + 1 - y)",
"+ ans -= min(xy) * (n + 1 - max(xy))"
] | false | 0.045787 | 0.084886 | 0.539389 | [
"s469702948",
"s404490707"
] |
u148551245 | p03469 | python | s057198773 | s166566641 | 173 | 17 | 38,384 | 2,940 | Accepted | Accepted | 90.17 | s = eval(input())
s = s.replace("7", "8", 1)
print(s) | s = eval(input())
print(("2018" + s[4:])) | 3 | 2 | 49 | 34 | s = eval(input())
s = s.replace("7", "8", 1)
print(s)
| s = eval(input())
print(("2018" + s[4:]))
| false | 33.333333 | [
"-s = s.replace(\"7\", \"8\", 1)",
"-print(s)",
"+print((\"2018\" + s[4:]))"
] | false | 0.079423 | 0.038957 | 2.038722 | [
"s057198773",
"s166566641"
] |
u522945737 | p02641 | python | s184982949 | s034577678 | 117 | 28 | 27,076 | 9,204 | Accepted | Accepted | 76.07 | import sys
import numpy as np
X, N = list(map(int, input().split()))
if N == 0:
print(X)
sys.exit()
p = list(map(int, input().split()))
forbid = [True]*102
for i in range(len(p)):
if forbid[p[i]]:
forbid[p[i]] = False
pp = []
for i in range(len(forbid)):
if forbid[i]:
pp.append(i-X)
# num = pp[len(pp)-1]
# for i in range(len(pp)-1,0,-1):
# if abs(num) >= abs(pp[i]):
# num = pp[i]
print((pp[np.argmin(np.abs(pp))]+X))
| import sys
X, N = list(map(int, input().split()))
if N == 0:
print(X)
sys.exit()
p = list(map(int, input().split()))
forbid = [True]*102
for i in range(len(p)):
if forbid[p[i]]:
forbid[p[i]] = False
pp = []
for i in range(len(forbid)):
if forbid[i]:
pp.append(i-X)
num = pp[len(pp)-1]
for i in range(len(pp)-1,-1,-1):
if abs(num) >= abs(pp[i]):
num = pp[i]
print((num+X))
| 26 | 25 | 511 | 462 | import sys
import numpy as np
X, N = list(map(int, input().split()))
if N == 0:
print(X)
sys.exit()
p = list(map(int, input().split()))
forbid = [True] * 102
for i in range(len(p)):
if forbid[p[i]]:
forbid[p[i]] = False
pp = []
for i in range(len(forbid)):
if forbid[i]:
pp.append(i - X)
# num = pp[len(pp)-1]
# for i in range(len(pp)-1,0,-1):
# if abs(num) >= abs(pp[i]):
# num = pp[i]
print((pp[np.argmin(np.abs(pp))] + X))
| import sys
X, N = list(map(int, input().split()))
if N == 0:
print(X)
sys.exit()
p = list(map(int, input().split()))
forbid = [True] * 102
for i in range(len(p)):
if forbid[p[i]]:
forbid[p[i]] = False
pp = []
for i in range(len(forbid)):
if forbid[i]:
pp.append(i - X)
num = pp[len(pp) - 1]
for i in range(len(pp) - 1, -1, -1):
if abs(num) >= abs(pp[i]):
num = pp[i]
print((num + X))
| false | 3.846154 | [
"-import numpy as np",
"-# num = pp[len(pp)-1]",
"-# for i in range(len(pp)-1,0,-1):",
"-# if abs(num) >= abs(pp[i]):",
"-# num = pp[i]",
"-print((pp[np.argmin(np.abs(pp))] + X))",
"+num = pp[len(pp) - 1]",
"+for i in range(len(pp) - 1, -1, -1):",
"+ if abs(num) >= abs(pp[i]):",
"+ num = pp[i]",
"+print((num + X))"
] | false | 0.197065 | 0.103016 | 1.912948 | [
"s184982949",
"s034577678"
] |
u941407962 | p02846 | python | s741060137 | s416986297 | 180 | 166 | 38,384 | 38,384 | Accepted | Accepted | 7.78 | t1,t2 = list(map(int, input().split()))
a1,a2 = list(map(int, input().split()))
b1,b2 = list(map(int, input().split()))
x,y=(a1-b1)*t1 + (a2-b2)*t2, (a1-b1)*t1
if x == 0:
print("infinity")
elif x*y > 0:
print((0))
else:
s,t = divmod(abs(y), abs(x))
print((s*2+(1 if t else 0)))
| t,T,a,A,b,B=list(map(int, open(0).read().split()))
x,y=(a-b)*t,(A-B)*T
if x+y==0:
r="infinity"
else:
s,t=divmod(-x, x+y)
r=0 if s<0 else s*2+(1 if t else 0)
print(r) | 11 | 8 | 282 | 169 | t1, t2 = list(map(int, input().split()))
a1, a2 = list(map(int, input().split()))
b1, b2 = list(map(int, input().split()))
x, y = (a1 - b1) * t1 + (a2 - b2) * t2, (a1 - b1) * t1
if x == 0:
print("infinity")
elif x * y > 0:
print((0))
else:
s, t = divmod(abs(y), abs(x))
print((s * 2 + (1 if t else 0)))
| t, T, a, A, b, B = list(map(int, open(0).read().split()))
x, y = (a - b) * t, (A - B) * T
if x + y == 0:
r = "infinity"
else:
s, t = divmod(-x, x + y)
r = 0 if s < 0 else s * 2 + (1 if t else 0)
print(r)
| false | 27.272727 | [
"-t1, t2 = list(map(int, input().split()))",
"-a1, a2 = list(map(int, input().split()))",
"-b1, b2 = list(map(int, input().split()))",
"-x, y = (a1 - b1) * t1 + (a2 - b2) * t2, (a1 - b1) * t1",
"-if x == 0:",
"- print(\"infinity\")",
"-elif x * y > 0:",
"- print((0))",
"+t, T, a, A, b, B = list(map(int, open(0).read().split()))",
"+x, y = (a - b) * t, (A - B) * T",
"+if x + y == 0:",
"+ r = \"infinity\"",
"- s, t = divmod(abs(y), abs(x))",
"- print((s * 2 + (1 if t else 0)))",
"+ s, t = divmod(-x, x + y)",
"+ r = 0 if s < 0 else s * 2 + (1 if t else 0)",
"+print(r)"
] | false | 0.043311 | 0.046417 | 0.933098 | [
"s741060137",
"s416986297"
] |
u597374218 | p02983 | python | s263952911 | s488264739 | 333 | 308 | 75,416 | 2,940 | Accepted | Accepted | 7.51 | L,R=list(map(int,input().split()))
left,right=L%2019,R%2019
print((0 if R-L>=2019 else min([i*j%2019 for i in range(left,right+1) for j in range(i+1,right+1)]))) | L,R=list(map(int,input().split()))
left,right=L%2019,R%2019
print((0 if R-L>=2019 else min(i*j%2019 for i in range(left,right+1) for j in range(i+1,right+1)))) | 3 | 3 | 155 | 153 | L, R = list(map(int, input().split()))
left, right = L % 2019, R % 2019
print(
(
0
if R - L >= 2019
else min(
[
i * j % 2019
for i in range(left, right + 1)
for j in range(i + 1, right + 1)
]
)
)
)
| L, R = list(map(int, input().split()))
left, right = L % 2019, R % 2019
print(
(
0
if R - L >= 2019
else min(
i * j % 2019
for i in range(left, right + 1)
for j in range(i + 1, right + 1)
)
)
)
| false | 0 | [
"- [",
"- i * j % 2019",
"- for i in range(left, right + 1)",
"- for j in range(i + 1, right + 1)",
"- ]",
"+ i * j % 2019",
"+ for i in range(left, right + 1)",
"+ for j in range(i + 1, right + 1)"
] | false | 0.170703 | 0.049605 | 3.441212 | [
"s263952911",
"s488264739"
] |
u801512570 | p03289 | python | s654980327 | s156579016 | 20 | 17 | 3,064 | 2,940 | Accepted | Accepted | 15 | S = eval(input())
if S[0]=='A' and S[2:-1].count('C')==1:
S=S.replace("A", "a")
S=S.replace("C", "c")
if S.islower()==True:
print('AC')
else:
print('WA')
else:
print('WA') | S = eval(input())
if S[0]=='A' and S[2:-1].count('C')==1:
S=S[1:].replace("C", "c")
if S.islower()==True:
print('AC')
else:
print('WA')
else:
print('WA') | 11 | 10 | 212 | 189 | S = eval(input())
if S[0] == "A" and S[2:-1].count("C") == 1:
S = S.replace("A", "a")
S = S.replace("C", "c")
if S.islower() == True:
print("AC")
else:
print("WA")
else:
print("WA")
| S = eval(input())
if S[0] == "A" and S[2:-1].count("C") == 1:
S = S[1:].replace("C", "c")
if S.islower() == True:
print("AC")
else:
print("WA")
else:
print("WA")
| false | 9.090909 | [
"- S = S.replace(\"A\", \"a\")",
"- S = S.replace(\"C\", \"c\")",
"+ S = S[1:].replace(\"C\", \"c\")"
] | false | 0.046155 | 0.063329 | 0.728822 | [
"s654980327",
"s156579016"
] |
u888337853 | p02588 | python | s810136454 | s778290074 | 1,687 | 1,446 | 276,920 | 289,552 | Accepted | Accepted | 14.29 | import sys
import math
import collections
import bisect
import itertools
import decimal
# import numpy as np
sys.setrecursionlimit(10 ** 7)
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 prime_factorize(n):
two = 0
five = 0
while n % 2 == 0:
two += 1
n //= 2
while n % 5 == 0:
five += 1
n //= 5
return two, five
def main():
n = ni()
a = [int(decimal.Decimal(eval(input())) * (10 ** 9)) for _ in range(n)]
res = {}
border = 18
twoflg = False
fiveflg = False
for ai in a:
two, five = prime_factorize(ai)
if two >= 9:
twoflg = True
if five >= 9:
fiveflg = True
if (two, five) not in list(res.keys()):
res[(two, five)] = 1
else:
res[(two, five)] += 1
ans = 0
if twoflg and fiveflg:
for k, v in list(res.items()):
two, five = k
for tk, tv in list(res.items()):
t_two, t_five = tk
if two + t_two >= border and five + t_five >= border:
if two == t_two and five == t_five:
ans += v * (tv - 1)
else:
ans += v * tv
print((ans // 2))
if __name__ == '__main__':
main()
| import sys
import math
import collections
import bisect
import itertools
import decimal
# import numpy as np
sys.setrecursionlimit(10 ** 7)
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 prime_factorize(n):
two = 0
five = 0
while n % 2 == 0:
two += 1
n //= 2
while n % 5 == 0:
five += 1
n //= 5
return two, five
def main():
n = ni()
a = [int(decimal.Decimal(sys.stdin.readline().rstrip()) * (10 ** 9)) for _ in range(n)]
res = {}
border = 18
twoflg = False
fiveflg = False
for ai in a:
two, five = prime_factorize(ai)
if two >= 9:
twoflg = True
if five >= 9:
fiveflg = True
if (two, five) not in list(res.keys()):
res[(two, five)] = 1
else:
res[(two, five)] += 1
ans = 0
if twoflg and fiveflg:
for k, v in list(res.items()):
two, five = k
for tk, tv in list(res.items()):
t_two, t_five = tk
if two + t_two >= border and five + t_five >= border:
if two == t_two and five == t_five:
ans += v * (tv - 1)
else:
ans += v * tv
print((ans // 2))
if __name__ == '__main__':
main()
| 73 | 73 | 1,637 | 1,659 | import sys
import math
import collections
import bisect
import itertools
import decimal
# import numpy as np
sys.setrecursionlimit(10**7)
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 prime_factorize(n):
two = 0
five = 0
while n % 2 == 0:
two += 1
n //= 2
while n % 5 == 0:
five += 1
n //= 5
return two, five
def main():
n = ni()
a = [int(decimal.Decimal(eval(input())) * (10**9)) for _ in range(n)]
res = {}
border = 18
twoflg = False
fiveflg = False
for ai in a:
two, five = prime_factorize(ai)
if two >= 9:
twoflg = True
if five >= 9:
fiveflg = True
if (two, five) not in list(res.keys()):
res[(two, five)] = 1
else:
res[(two, five)] += 1
ans = 0
if twoflg and fiveflg:
for k, v in list(res.items()):
two, five = k
for tk, tv in list(res.items()):
t_two, t_five = tk
if two + t_two >= border and five + t_five >= border:
if two == t_two and five == t_five:
ans += v * (tv - 1)
else:
ans += v * tv
print((ans // 2))
if __name__ == "__main__":
main()
| import sys
import math
import collections
import bisect
import itertools
import decimal
# import numpy as np
sys.setrecursionlimit(10**7)
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 prime_factorize(n):
two = 0
five = 0
while n % 2 == 0:
two += 1
n //= 2
while n % 5 == 0:
five += 1
n //= 5
return two, five
def main():
n = ni()
a = [
int(decimal.Decimal(sys.stdin.readline().rstrip()) * (10**9))
for _ in range(n)
]
res = {}
border = 18
twoflg = False
fiveflg = False
for ai in a:
two, five = prime_factorize(ai)
if two >= 9:
twoflg = True
if five >= 9:
fiveflg = True
if (two, five) not in list(res.keys()):
res[(two, five)] = 1
else:
res[(two, five)] += 1
ans = 0
if twoflg and fiveflg:
for k, v in list(res.items()):
two, five = k
for tk, tv in list(res.items()):
t_two, t_five = tk
if two + t_two >= border and five + t_five >= border:
if two == t_two and five == t_five:
ans += v * (tv - 1)
else:
ans += v * tv
print((ans // 2))
if __name__ == "__main__":
main()
| false | 0 | [
"- a = [int(decimal.Decimal(eval(input())) * (10**9)) for _ in range(n)]",
"+ a = [",
"+ int(decimal.Decimal(sys.stdin.readline().rstrip()) * (10**9))",
"+ for _ in range(n)",
"+ ]"
] | false | 0.039329 | 0.039844 | 0.987087 | [
"s810136454",
"s778290074"
] |
u562935282 | p03326 | python | s124711901 | s178672976 | 36 | 28 | 3,316 | 3,260 | Accepted | Accepted | 22.22 | N, M = list(map(int, input().split()))
XYZs = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for op in range(1 << 3):
lst = []
for xyz in XYZs:
v = 0
for j in range(3):
v += xyz[j] * ((-1) ** ((op >> j) & 1))
lst.append(v)
ans = max(ans, sum(sorted(lst, reverse=True)[:M]))
print(ans) | N, M = list(map(int, input().split()))
XYZs = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(1 << 3):
signs = []
for j in range(3):
if i >> j & 1:
signs.append(1)
else:
signs.append(-1)
t = []
for xyz in XYZs:
x, y, z = xyz
t.append(x * signs[0] + y * signs[1] + z * signs[2])
ans = max(ans, sum(sorted(t, reverse=True)[:M]))
print(ans) | 14 | 17 | 354 | 452 | N, M = list(map(int, input().split()))
XYZs = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for op in range(1 << 3):
lst = []
for xyz in XYZs:
v = 0
for j in range(3):
v += xyz[j] * ((-1) ** ((op >> j) & 1))
lst.append(v)
ans = max(ans, sum(sorted(lst, reverse=True)[:M]))
print(ans)
| N, M = list(map(int, input().split()))
XYZs = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(1 << 3):
signs = []
for j in range(3):
if i >> j & 1:
signs.append(1)
else:
signs.append(-1)
t = []
for xyz in XYZs:
x, y, z = xyz
t.append(x * signs[0] + y * signs[1] + z * signs[2])
ans = max(ans, sum(sorted(t, reverse=True)[:M]))
print(ans)
| false | 17.647059 | [
"-XYZs = [list(map(int, input().split())) for _ in range(N)]",
"+XYZs = [tuple(map(int, input().split())) for _ in range(N)]",
"-for op in range(1 << 3):",
"- lst = []",
"+for i in range(1 << 3):",
"+ signs = []",
"+ for j in range(3):",
"+ if i >> j & 1:",
"+ signs.append(1)",
"+ else:",
"+ signs.append(-1)",
"+ t = []",
"- v = 0",
"- for j in range(3):",
"- v += xyz[j] * ((-1) ** ((op >> j) & 1))",
"- lst.append(v)",
"- ans = max(ans, sum(sorted(lst, reverse=True)[:M]))",
"+ x, y, z = xyz",
"+ t.append(x * signs[0] + y * signs[1] + z * signs[2])",
"+ ans = max(ans, sum(sorted(t, reverse=True)[:M]))"
] | false | 0.040014 | 0.04039 | 0.990698 | [
"s124711901",
"s178672976"
] |
u345966487 | p02918 | python | s189976751 | s239228944 | 36 | 29 | 3,956 | 3,188 | Accepted | Accepted | 19.44 | N,K=list(map(int,input().split()));S=eval(input());u=[S[0]]
for c in S:c==u[-1]or u.append(c)
print((len(S)-max(len(u)-2*K,1))) | n,s=open(0);n,k=list(map(int,n.split()));print((n-max(sum(i!=j for i,j in zip(s,s[1:]))-2*k,1))) | 3 | 1 | 115 | 88 | N, K = list(map(int, input().split()))
S = eval(input())
u = [S[0]]
for c in S:
c == u[-1] or u.append(c)
print((len(S) - max(len(u) - 2 * K, 1)))
| n, s = open(0)
n, k = list(map(int, n.split()))
print((n - max(sum(i != j for i, j in zip(s, s[1:])) - 2 * k, 1)))
| false | 66.666667 | [
"-N, K = list(map(int, input().split()))",
"-S = eval(input())",
"-u = [S[0]]",
"-for c in S:",
"- c == u[-1] or u.append(c)",
"-print((len(S) - max(len(u) - 2 * K, 1)))",
"+n, s = open(0)",
"+n, k = list(map(int, n.split()))",
"+print((n - max(sum(i != j for i, j in zip(s, s[1:])) - 2 * k, 1)))"
] | false | 0.071492 | 0.042629 | 1.677074 | [
"s189976751",
"s239228944"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.