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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u025501820 | p02714 | python | s547841300 | s196359248 | 1,903 | 1,432 | 9,208 | 9,132 | Accepted | Accepted | 24.75 | N = int(eval(input()))
S = eval(input())
r_num = S.count("R")
g_num = S.count("G")
b_num = S.count("B")
cnt = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
if 2 * j - i < N and S[i] != S[j] and (S[2 * j - i] != S[i] and S[2 * j - i] != S[j]):
cnt += 1
ans = r_num * g_num * b_num - cnt
print(ans) | N = int(eval(input()))
S = eval(input())
r_num = S.count("R")
g_num = S.count("G")
b_num = S.count("B")
cnt = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
if not 2 * j - i < N:
break
if S[i] != S[j] and (S[2 * j - i] != S[i] and S[2 * j - i] != S[j]):
cnt += 1
ans = r_num * g_num * b_num - cnt
print(ans)
| 16 | 19 | 336 | 378 | N = int(eval(input()))
S = eval(input())
r_num = S.count("R")
g_num = S.count("G")
b_num = S.count("B")
cnt = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
if (
2 * j - i < N
and S[i] != S[j]
and (S[2 * j - i] != S[i] and S[2 * j - i] != S[j])
):
cnt += 1
ans = r_num * g_num * b_num - cnt
print(ans)
| N = int(eval(input()))
S = eval(input())
r_num = S.count("R")
g_num = S.count("G")
b_num = S.count("B")
cnt = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
if not 2 * j - i < N:
break
if S[i] != S[j] and (S[2 * j - i] != S[i] and S[2 * j - i] != S[j]):
cnt += 1
ans = r_num * g_num * b_num - cnt
print(ans)
| false | 15.789474 | [
"- if (",
"- 2 * j - i < N",
"- and S[i] != S[j]",
"- and (S[2 * j - i] != S[i] and S[2 * j - i] != S[j])",
"- ):",
"+ if not 2 * j - i < N:",
"+ break",
"+ if S[i] != S[j] and (S[2 * j - i] != S[i] and S[2 * j - i] != S[j]):"
] | false | 0.04845 | 0.043071 | 1.124886 | [
"s547841300",
"s196359248"
] |
u069838609 | p03221 | python | s754091892 | s700948146 | 596 | 497 | 43,184 | 43,184 | Accepted | Accepted | 16.61 | import sys
fin = sys.stdin.readline
from collections import defaultdict
N, M = [int(elem) for elem in fin().split()]
pref_years = [[int(elem) for elem in fin().split()] for _ in range(M)]
formatter = lambda x: "{:06}".format(x)
# sort by year in ascending order
sorted_pref_years = sorted(pref_years, key=lambda x: x[1])
number_cities_per_city = defaultdict(int)
identity_numbers = {}
for pref, year in sorted_pref_years:
number_cities_per_city[pref] += 1
identity_numbers[year] = formatter(pref) \
+ formatter(number_cities_per_city[pref])
for _, year in pref_years:
print(identity_numbers[year])
| import sys
fin = sys.stdin.readline
from collections import defaultdict
N, M = [int(elem) for elem in fin().split()]
cities = [[int(elem) for elem in fin().split()] for _ in range(M)]
sorted_cities = sorted(cities, key= lambda x: x[1])
num_cities_in_pref = defaultdict(int)
years_to_identification = dict()
for pref, year in sorted_cities:
num_cities_in_pref[pref] += 1
years_to_identification[year] = "{:06}{:06}".format(pref, num_cities_in_pref[pref])
for _, year in cities:
print((years_to_identification[year]))
| 20 | 17 | 660 | 546 | import sys
fin = sys.stdin.readline
from collections import defaultdict
N, M = [int(elem) for elem in fin().split()]
pref_years = [[int(elem) for elem in fin().split()] for _ in range(M)]
formatter = lambda x: "{:06}".format(x)
# sort by year in ascending order
sorted_pref_years = sorted(pref_years, key=lambda x: x[1])
number_cities_per_city = defaultdict(int)
identity_numbers = {}
for pref, year in sorted_pref_years:
number_cities_per_city[pref] += 1
identity_numbers[year] = formatter(pref) + formatter(number_cities_per_city[pref])
for _, year in pref_years:
print(identity_numbers[year])
| import sys
fin = sys.stdin.readline
from collections import defaultdict
N, M = [int(elem) for elem in fin().split()]
cities = [[int(elem) for elem in fin().split()] for _ in range(M)]
sorted_cities = sorted(cities, key=lambda x: x[1])
num_cities_in_pref = defaultdict(int)
years_to_identification = dict()
for pref, year in sorted_cities:
num_cities_in_pref[pref] += 1
years_to_identification[year] = "{:06}{:06}".format(pref, num_cities_in_pref[pref])
for _, year in cities:
print((years_to_identification[year]))
| false | 15 | [
"-pref_years = [[int(elem) for elem in fin().split()] for _ in range(M)]",
"-formatter = lambda x: \"{:06}\".format(x)",
"-# sort by year in ascending order",
"-sorted_pref_years = sorted(pref_years, key=lambda x: x[1])",
"-number_cities_per_city = defaultdict(int)",
"-identity_numbers = {}",
"-for pref, year in sorted_pref_years:",
"- number_cities_per_city[pref] += 1",
"- identity_numbers[year] = formatter(pref) + formatter(number_cities_per_city[pref])",
"-for _, year in pref_years:",
"- print(identity_numbers[year])",
"+cities = [[int(elem) for elem in fin().split()] for _ in range(M)]",
"+sorted_cities = sorted(cities, key=lambda x: x[1])",
"+num_cities_in_pref = defaultdict(int)",
"+years_to_identification = dict()",
"+for pref, year in sorted_cities:",
"+ num_cities_in_pref[pref] += 1",
"+ years_to_identification[year] = \"{:06}{:06}\".format(pref, num_cities_in_pref[pref])",
"+for _, year in cities:",
"+ print((years_to_identification[year]))"
] | false | 0.049849 | 0.049004 | 1.017247 | [
"s754091892",
"s700948146"
] |
u923279197 | p02982 | python | s218732286 | s332234744 | 169 | 18 | 39,280 | 3,188 | Accepted | Accepted | 89.35 | n,d = list(map(int,input().split()))
x = [list(map(int,input().split())) for i in range(n)]
ans = 0
def k(a,b):
dist = 0
for i in range(d):
dist +=(a[i]-b[i])**2
dist = dist**(1/2)
while dist > 0:
dist -= 1
if dist == 0:
return True
return False
for i in range(n):
for j in range(i+1,n):
if k(x[i],x[j]):
ans += 1
print(ans) | n,d = list(map(int,input().split()))
data = [list(map(int,input().split())) for i in range(n)]
def ok(x,y):
z = 0
for i in range(d):
z += (x[i]-y[i])**2
if z**(0.5) == int(z**(0.5)):
return True
else:
return False
ans = 0
for i in range(n):
for j in range(i+1,n):
if ok(data[i],data[j]):
ans += 1
print(ans) | 19 | 20 | 417 | 388 | n, d = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
def k(a, b):
dist = 0
for i in range(d):
dist += (a[i] - b[i]) ** 2
dist = dist ** (1 / 2)
while dist > 0:
dist -= 1
if dist == 0:
return True
return False
for i in range(n):
for j in range(i + 1, n):
if k(x[i], x[j]):
ans += 1
print(ans)
| n, d = list(map(int, input().split()))
data = [list(map(int, input().split())) for i in range(n)]
def ok(x, y):
z = 0
for i in range(d):
z += (x[i] - y[i]) ** 2
if z ** (0.5) == int(z ** (0.5)):
return True
else:
return False
ans = 0
for i in range(n):
for j in range(i + 1, n):
if ok(data[i], data[j]):
ans += 1
print(ans)
| false | 5 | [
"-x = [list(map(int, input().split())) for i in range(n)]",
"-ans = 0",
"+data = [list(map(int, input().split())) for i in range(n)]",
"-def k(a, b):",
"- dist = 0",
"+def ok(x, y):",
"+ z = 0",
"- dist += (a[i] - b[i]) ** 2",
"- dist = dist ** (1 / 2)",
"- while dist > 0:",
"- dist -= 1",
"- if dist == 0:",
"- return True",
"- return False",
"+ z += (x[i] - y[i]) ** 2",
"+ if z ** (0.5) == int(z ** (0.5)):",
"+ return True",
"+ else:",
"+ return False",
"+ans = 0",
"- if k(x[i], x[j]):",
"+ if ok(data[i], data[j]):"
] | false | 0.032155 | 0.035329 | 0.910162 | [
"s218732286",
"s332234744"
] |
u761529120 | p03163 | python | s719654318 | s561712119 | 459 | 251 | 118,128 | 149,460 | Accepted | Accepted | 45.32 | def main():
N, W = list(map(int, input().split()))
w = [0] * N
v = [0] * N
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
dp = [[0] * (W + 5) for _ in range(N + 5)]
for i in range(N):
for j in range(W):
print()
if j + w[i] <= W:
dp[i+1][j + w[i]] = max(dp[i+1][j + w[i]], dp[i][j] + v[i])
dp[i+1][j] = max(dp[i+1][j], dp[i][j])
print((max(dp[N])))
if __name__ == "__main__":
main() | def main():
N, Wei = list(map(int, input().split()))
W = [0] * N
V = [0] * N
for i in range(N):
W[i], V[i] = list(map(int, input().split()))
dp = [[0] * (Wei + 5) for _ in range(N + 5)]
dp[0][Wei] = 0
for i in range(N):
for w in range(Wei+1):
if w >= W[i]:
dp[i+1][w] = max(dp[i][w-W[i]] + V[i], dp[i][w])
else:
dp[i+1][w] = dp[i][w]
print((dp[N][Wei]))
if __name__ == "__main__":
main() | 21 | 20 | 515 | 503 | def main():
N, W = list(map(int, input().split()))
w = [0] * N
v = [0] * N
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
dp = [[0] * (W + 5) for _ in range(N + 5)]
for i in range(N):
for j in range(W):
print()
if j + w[i] <= W:
dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i])
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print((max(dp[N])))
if __name__ == "__main__":
main()
| def main():
N, Wei = list(map(int, input().split()))
W = [0] * N
V = [0] * N
for i in range(N):
W[i], V[i] = list(map(int, input().split()))
dp = [[0] * (Wei + 5) for _ in range(N + 5)]
dp[0][Wei] = 0
for i in range(N):
for w in range(Wei + 1):
if w >= W[i]:
dp[i + 1][w] = max(dp[i][w - W[i]] + V[i], dp[i][w])
else:
dp[i + 1][w] = dp[i][w]
print((dp[N][Wei]))
if __name__ == "__main__":
main()
| false | 4.761905 | [
"- N, W = list(map(int, input().split()))",
"- w = [0] * N",
"- v = [0] * N",
"+ N, Wei = list(map(int, input().split()))",
"+ W = [0] * N",
"+ V = [0] * N",
"- w[i], v[i] = list(map(int, input().split()))",
"- dp = [[0] * (W + 5) for _ in range(N + 5)]",
"+ W[i], V[i] = list(map(int, input().split()))",
"+ dp = [[0] * (Wei + 5) for _ in range(N + 5)]",
"+ dp[0][Wei] = 0",
"- for j in range(W):",
"- print()",
"- if j + w[i] <= W:",
"- dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i])",
"- dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])",
"- print((max(dp[N])))",
"+ for w in range(Wei + 1):",
"+ if w >= W[i]:",
"+ dp[i + 1][w] = max(dp[i][w - W[i]] + V[i], dp[i][w])",
"+ else:",
"+ dp[i + 1][w] = dp[i][w]",
"+ print((dp[N][Wei]))"
] | false | 0.04844 | 0.041421 | 1.16946 | [
"s719654318",
"s561712119"
] |
u285891772 | p02848 | python | s473247906 | s870014394 | 328 | 155 | 22,452 | 14,012 | Accepted | Accepted | 52.74 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits, ascii_letters
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
S = input()
ans = []
for s in S:
ans.append(ascii_uppercase[(ascii_uppercase.index(s)+N)%26])
print(*ans, sep="")
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits, ascii_letters
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
S = input()
ans = [ascii_uppercase[(ascii_uppercase.index(S[i])+N)%26] for i in range(len(S))]
#print(ans)
print(*ans, sep="")
| 29 | 25 | 996 | 1,000 | import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits, ascii_letters
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return zip(*(MAP() for _ in range(n)))
import numpy as np
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
S = input()
ans = []
for s in S:
ans.append(ascii_uppercase[(ascii_uppercase.index(s) + N) % 26])
print(*ans, sep="")
| import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits, ascii_letters
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return zip(*(MAP() for _ in range(n)))
import numpy as np
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
S = input()
ans = [ascii_uppercase[(ascii_uppercase.index(S[i]) + N) % 26] for i in range(len(S))]
# print(ans)
print(*ans, sep="")
| false | 13.793103 | [
"-ans = []",
"-for s in S:",
"- ans.append(ascii_uppercase[(ascii_uppercase.index(s) + N) % 26])",
"+ans = [ascii_uppercase[(ascii_uppercase.index(S[i]) + N) % 26] for i in range(len(S))]",
"+# print(ans)"
] | false | 0.0482 | 0.146851 | 0.328223 | [
"s473247906",
"s870014394"
] |
u500376440 | p04043 | python | s255810306 | s992605938 | 165 | 28 | 38,256 | 9,084 | Accepted | Accepted | 83.03 | ABC=input().split()
if ABC.count("5")==2 and ABC.count("7")==1:
print("YES")
else:
print("NO")
| ABC=list(map(int,input().split()))
if ABC.count(5)==2 and ABC.count(7)==1:
print("YES")
else:
print("NO")
| 5 | 5 | 103 | 114 | ABC = input().split()
if ABC.count("5") == 2 and ABC.count("7") == 1:
print("YES")
else:
print("NO")
| ABC = list(map(int, input().split()))
if ABC.count(5) == 2 and ABC.count(7) == 1:
print("YES")
else:
print("NO")
| false | 0 | [
"-ABC = input().split()",
"-if ABC.count(\"5\") == 2 and ABC.count(\"7\") == 1:",
"+ABC = list(map(int, input().split()))",
"+if ABC.count(5) == 2 and ABC.count(7) == 1:"
] | false | 0.061072 | 0.03735 | 1.635129 | [
"s255810306",
"s992605938"
] |
u285681431 | p02793 | python | s250352605 | s198985240 | 1,198 | 161 | 83,196 | 82,884 | Accepted | Accepted | 86.56 | from collections import Counter
MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
prime = [0] * (10**6+1)
for i in range(N):
c = Counter(prime_factorize(A[i]))
for j in list(c.items()):
prime[j[0]] = max(j[1], prime[j[0]])
lcm = 1
for i in range(10**6):
if prime[i] > 0:
lcm *= pow(i, prime[i],MOD)
ans = 0
for i in range(N):
ans += lcm * pow(A[i], MOD - 2, MOD)
ans %= MOD
print(ans)
| from collections import Counter
MOD = 10**9+7
N = int(eval(input()))
A = list(map(int,input().split()))
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
prime = [0] * (10**6+5)
for i in range(N):
c = Counter(prime_factorize(A[i]))
for j in list(c.items()):
prime[j[0]] = max(j[1],prime[j[0]])
lcm = 1
for i in range(10**6+2):
if prime[i] > 0:
lcm *= pow(i,prime[i])
lcm %= MOD
ans = 0
for i in range(N):
ans += lcm * pow(A[i],MOD-2,MOD)
ans %= MOD
print(ans)
| 38 | 35 | 749 | 750 | from collections import Counter
MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
prime = [0] * (10**6 + 1)
for i in range(N):
c = Counter(prime_factorize(A[i]))
for j in list(c.items()):
prime[j[0]] = max(j[1], prime[j[0]])
lcm = 1
for i in range(10**6):
if prime[i] > 0:
lcm *= pow(i, prime[i], MOD)
ans = 0
for i in range(N):
ans += lcm * pow(A[i], MOD - 2, MOD)
ans %= MOD
print(ans)
| from collections import Counter
MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
prime = [0] * (10**6 + 5)
for i in range(N):
c = Counter(prime_factorize(A[i]))
for j in list(c.items()):
prime[j[0]] = max(j[1], prime[j[0]])
lcm = 1
for i in range(10**6 + 2):
if prime[i] > 0:
lcm *= pow(i, prime[i])
lcm %= MOD
ans = 0
for i in range(N):
ans += lcm * pow(A[i], MOD - 2, MOD)
ans %= MOD
print(ans)
| false | 7.894737 | [
"-prime = [0] * (10**6 + 1)",
"+prime = [0] * (10**6 + 5)",
"-for i in range(10**6):",
"+for i in range(10**6 + 2):",
"- lcm *= pow(i, prime[i], MOD)",
"+ lcm *= pow(i, prime[i])",
"+ lcm %= MOD"
] | false | 0.475423 | 0.668676 | 0.710992 | [
"s250352605",
"s198985240"
] |
u945181840 | p03862 | python | s698645813 | s789420632 | 108 | 94 | 14,540 | 14,060 | Accepted | Accepted | 12.96 | N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
candy = min(a[0], x)
ans = a[0] - candy
a[0] = candy
for i in range(1, N):
candy += a[i]
if candy > x:
m = candy - x
ans += m
a[i] -= m
candy -= a[i - 1] + m
else:
candy -= a[i - 1]
print(ans) | N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
candy = min(a[0], x)
ans = a[0] - candy
a[0] = candy
for i in range(1, N):
candy = a[i - 1] + a[i]
if candy > x:
m = candy - x
ans += m
a[i] -= m
print(ans) | 17 | 14 | 331 | 272 | N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
candy = min(a[0], x)
ans = a[0] - candy
a[0] = candy
for i in range(1, N):
candy += a[i]
if candy > x:
m = candy - x
ans += m
a[i] -= m
candy -= a[i - 1] + m
else:
candy -= a[i - 1]
print(ans)
| N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
candy = min(a[0], x)
ans = a[0] - candy
a[0] = candy
for i in range(1, N):
candy = a[i - 1] + a[i]
if candy > x:
m = candy - x
ans += m
a[i] -= m
print(ans)
| false | 17.647059 | [
"- candy += a[i]",
"+ candy = a[i - 1] + a[i]",
"- candy -= a[i - 1] + m",
"- else:",
"- candy -= a[i - 1]"
] | false | 0.09954 | 0.048013 | 2.073184 | [
"s698645813",
"s789420632"
] |
u616382321 | p02861 | python | s087846785 | s735112783 | 396 | 115 | 33,680 | 27,228 | Accepted | Accepted | 70.96 | import itertools
import numpy as np
def distance(x2,x1,y2,y1):
return ((x2-x1)**2 + (y2-y1)**2)**0.5
N = int(eval(input()))
X = []
Y = []
for _ in range(N):
x, y = list(map(int, input().split()))
X.append(x)
Y.append(y)
routes = list(itertools.permutations(list(range(N)), N))
ans = []
for route in routes:
dist = 0
for i in range(1, N):
dist += distance(X[route[i]], X[route[i-1]], Y[route[i]], Y[route[i-1]])
ans.append(dist)
print((np.mean(ans)))
| import numpy as np
N = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(N)]
XY = np.array(xy).flatten()
X = XY[::2] ; Y = XY[1::2]
dx = X[:,None] - X[None, :]
dy = Y[:, None] - Y[None,:]
dist_mat = (dx*dx + dy*dy) ** .5
answer = dist_mat.sum() / N
print(answer)
| 24 | 15 | 494 | 298 | import itertools
import numpy as np
def distance(x2, x1, y2, y1):
return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
N = int(eval(input()))
X = []
Y = []
for _ in range(N):
x, y = list(map(int, input().split()))
X.append(x)
Y.append(y)
routes = list(itertools.permutations(list(range(N)), N))
ans = []
for route in routes:
dist = 0
for i in range(1, N):
dist += distance(X[route[i]], X[route[i - 1]], Y[route[i]], Y[route[i - 1]])
ans.append(dist)
print((np.mean(ans)))
| import numpy as np
N = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(N)]
XY = np.array(xy).flatten()
X = XY[::2]
Y = XY[1::2]
dx = X[:, None] - X[None, :]
dy = Y[:, None] - Y[None, :]
dist_mat = (dx * dx + dy * dy) ** 0.5
answer = dist_mat.sum() / N
print(answer)
| false | 37.5 | [
"-import itertools",
"-",
"-def distance(x2, x1, y2, y1):",
"- return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5",
"-",
"-",
"-X = []",
"-Y = []",
"-for _ in range(N):",
"- x, y = list(map(int, input().split()))",
"- X.append(x)",
"- Y.append(y)",
"-routes = list(itertools.permutations(list(range(N)), N))",
"-ans = []",
"-for route in routes:",
"- dist = 0",
"- for i in range(1, N):",
"- dist += distance(X[route[i]], X[route[i - 1]], Y[route[i]], Y[route[i - 1]])",
"- ans.append(dist)",
"-print((np.mean(ans)))",
"+xy = [list(map(int, input().split())) for _ in range(N)]",
"+XY = np.array(xy).flatten()",
"+X = XY[::2]",
"+Y = XY[1::2]",
"+dx = X[:, None] - X[None, :]",
"+dy = Y[:, None] - Y[None, :]",
"+dist_mat = (dx * dx + dy * dy) ** 0.5",
"+answer = dist_mat.sum() / N",
"+print(answer)"
] | false | 0.155101 | 0.207611 | 0.747077 | [
"s087846785",
"s735112783"
] |
u047102107 | p03665 | python | s994985543 | s661268692 | 164 | 69 | 38,256 | 65,620 | Accepted | Accepted | 57.93 | from operator import mul
from functools import reduce
N, P = list(map(int, input().split()))
A = list(map(int, input().split()))
cE, cO = 0, 0
for a in A:
if a % 2 == 0:
cE += 1
else:
cO += 1
# 全て偶数
if cO == 0:
ans = 2 ** N if P == 0 else 0
print(ans)
else:
# 偶数が含まれている
# ある奇数$k$について考える
# 残りの奇数がcO-1個,偶数がcE個残っている,この選び方は2 ** (N - 1)通り
# 選んだ合計がSとする
# - Sが奇数である: Akを選ぶと全体は偶数,選ばないと全体は奇数
# - Sが偶数である: Akを選ぶと全体は奇数,選ばないと全体は偶数
# よってそれぞれの2 ** (N - 1)通りについて,Akを選ぶ・選ばないが1通り存在する
# print(2 ** (cO - 1) * 2 ** cE)
print((2 ** (N - 1))) | from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)
INF = int(1e10)
MOD = int(1e9 + 7)
def main():
from builtins import int, map
N, P = list(map(int, input().split()))
A = list(map(int, input().split()))
count_even, count_odd = 0, 0
for a in A:
if a % 2 == 0:
count_even += 1
else:
count_odd += 1
ans = -1
# print(N, P, A)
# print(count_even, count_odd)
if count_odd == 0:
# 偶数しかない
if P == 0:
# 偶数にしたい => どれでもOK
ans = 2 ** N
else:
# 奇数枚は食べられない
ans = 0
else:
# 奇数が1以上存在するので,ある1つ以外の和Sを考える
# S is odd: 食べたらeven,食べないとodd => 2 ^ (N-1) パターン
# S is even: 食べたらodd,食べないとeven
ans = 2 ** (N - 1)
print(ans)
if __name__ == '__main__':
main()
| 28 | 44 | 612 | 1,036 | from operator import mul
from functools import reduce
N, P = list(map(int, input().split()))
A = list(map(int, input().split()))
cE, cO = 0, 0
for a in A:
if a % 2 == 0:
cE += 1
else:
cO += 1
# 全て偶数
if cO == 0:
ans = 2**N if P == 0 else 0
print(ans)
else:
# 偶数が含まれている
# ある奇数$k$について考える
# 残りの奇数がcO-1個,偶数がcE個残っている,この選び方は2 ** (N - 1)通り
# 選んだ合計がSとする
# - Sが奇数である: Akを選ぶと全体は偶数,選ばないと全体は奇数
# - Sが偶数である: Akを選ぶと全体は奇数,選ばないと全体は偶数
# よってそれぞれの2 ** (N - 1)通りについて,Akを選ぶ・選ばないが1通り存在する
# print(2 ** (cO - 1) * 2 ** cE)
print((2 ** (N - 1)))
| from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)
INF = int(1e10)
MOD = int(1e9 + 7)
def main():
from builtins import int, map
N, P = list(map(int, input().split()))
A = list(map(int, input().split()))
count_even, count_odd = 0, 0
for a in A:
if a % 2 == 0:
count_even += 1
else:
count_odd += 1
ans = -1
# print(N, P, A)
# print(count_even, count_odd)
if count_odd == 0:
# 偶数しかない
if P == 0:
# 偶数にしたい => どれでもOK
ans = 2**N
else:
# 奇数枚は食べられない
ans = 0
else:
# 奇数が1以上存在するので,ある1つ以外の和Sを考える
# S is odd: 食べたらeven,食べないとodd => 2 ^ (N-1) パターン
# S is even: 食べたらodd,食べないとeven
ans = 2 ** (N - 1)
print(ans)
if __name__ == "__main__":
main()
| false | 36.363636 | [
"-from operator import mul",
"-from functools import reduce",
"+from sys import stdin, setrecursionlimit",
"+from collections import Counter, deque, defaultdict",
"+from math import floor, ceil",
"+from bisect import bisect_left",
"+from itertools import combinations",
"-N, P = list(map(int, input().split()))",
"-A = list(map(int, input().split()))",
"-cE, cO = 0, 0",
"-for a in A:",
"- if a % 2 == 0:",
"- cE += 1",
"+setrecursionlimit(100000)",
"+INF = int(1e10)",
"+MOD = int(1e9 + 7)",
"+",
"+",
"+def main():",
"+ from builtins import int, map",
"+",
"+ N, P = list(map(int, input().split()))",
"+ A = list(map(int, input().split()))",
"+ count_even, count_odd = 0, 0",
"+ for a in A:",
"+ if a % 2 == 0:",
"+ count_even += 1",
"+ else:",
"+ count_odd += 1",
"+ ans = -1",
"+ # print(N, P, A)",
"+ # print(count_even, count_odd)",
"+ if count_odd == 0:",
"+ # 偶数しかない",
"+ if P == 0:",
"+ # 偶数にしたい => どれでもOK",
"+ ans = 2**N",
"+ else:",
"+ # 奇数枚は食べられない",
"+ ans = 0",
"- cO += 1",
"-# 全て偶数",
"-if cO == 0:",
"- ans = 2**N if P == 0 else 0",
"+ # 奇数が1以上存在するので,ある1つ以外の和Sを考える",
"+ # S is odd: 食べたらeven,食べないとodd => 2 ^ (N-1) パターン",
"+ # S is even: 食べたらodd,食べないとeven",
"+ ans = 2 ** (N - 1)",
"-else:",
"- # 偶数が含まれている",
"- # ある奇数$k$について考える",
"- # 残りの奇数がcO-1個,偶数がcE個残っている,この選び方は2 ** (N - 1)通り",
"- # 選んだ合計がSとする",
"- # - Sが奇数である: Akを選ぶと全体は偶数,選ばないと全体は奇数",
"- # - Sが偶数である: Akを選ぶと全体は奇数,選ばないと全体は偶数",
"- # よってそれぞれの2 ** (N - 1)通りについて,Akを選ぶ・選ばないが1通り存在する",
"- # print(2 ** (cO - 1) * 2 ** cE)",
"- print((2 ** (N - 1)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.074314 | 0.064427 | 1.153461 | [
"s994985543",
"s661268692"
] |
u708255304 | p03011 | python | s617687658 | s081611324 | 19 | 17 | 2,940 | 3,064 | Accepted | Accepted | 10.53 | # P, Q, R = map(int, input().split())
S = list(map(int, input().split()))
hoge = S.pop(S.index(min(S)))
fuga = S.pop(S.index(min(S)))
print((hoge + fuga))
| distances = list(map(int, input().split()))
distances.sort()
print((distances[0]+distances[1]))
| 7 | 5 | 161 | 100 | # P, Q, R = map(int, input().split())
S = list(map(int, input().split()))
hoge = S.pop(S.index(min(S)))
fuga = S.pop(S.index(min(S)))
print((hoge + fuga))
| distances = list(map(int, input().split()))
distances.sort()
print((distances[0] + distances[1]))
| false | 28.571429 | [
"-# P, Q, R = map(int, input().split())",
"-S = list(map(int, input().split()))",
"-hoge = S.pop(S.index(min(S)))",
"-fuga = S.pop(S.index(min(S)))",
"-print((hoge + fuga))",
"+distances = list(map(int, input().split()))",
"+distances.sort()",
"+print((distances[0] + distances[1]))"
] | false | 0.112674 | 0.047067 | 2.393893 | [
"s617687658",
"s081611324"
] |
u202570162 | p02885 | python | s405085000 | s710951328 | 22 | 19 | 3,316 | 2,940 | Accepted | Accepted | 13.64 | a,b= list(map(int,input().split()))
r = a-b*2
if r <= 0:
print((0))
else:
print(r) | A,B=list(map(int,input().split()))
ans=A-B*2
print((ans if ans>=0 else 0)) | 6 | 3 | 87 | 68 | a, b = list(map(int, input().split()))
r = a - b * 2
if r <= 0:
print((0))
else:
print(r)
| A, B = list(map(int, input().split()))
ans = A - B * 2
print((ans if ans >= 0 else 0))
| false | 50 | [
"-a, b = list(map(int, input().split()))",
"-r = a - b * 2",
"-if r <= 0:",
"- print((0))",
"-else:",
"- print(r)",
"+A, B = list(map(int, input().split()))",
"+ans = A - B * 2",
"+print((ans if ans >= 0 else 0))"
] | false | 0.007849 | 0.042406 | 0.185093 | [
"s405085000",
"s710951328"
] |
u645855527 | p02863 | python | s745579982 | s133149498 | 845 | 321 | 178,308 | 145,828 | Accepted | Accepted | 62.01 | n, t = list(map(int, input().split()))
a = [0]
b = [0]
for i in range(n):
a_, b_ = list(map(int, input().split()))
a.append(a_)
b.append(b_)
dp1 = [[0] * t for _ in range(n+2)]
dp2 = [[0] * t for _ in range(n+2)]
for i in range(n):
for j in range(t):
if a[i+1] > j:
dp1[i+1][j] = dp1[i][j]
else:
dp1[i+1][j] = max(dp1[i][j], dp1[i][j-a[i+1]] + b[i+1])
for i in range(n+1, 1, -1):
for j in range(t):
if a[i-1] > j:
dp2[i-1][j] = dp2[i][j]
else:
dp2[i-1][j] = max(dp2[i][j], dp2[i][j-a[i-1]] + b[i-1])
ans = 0
for i in range(1, n+1):
for j in range(t):
total = b[i] +dp1[i-1][j] + dp2[i+1][t-1-j]
ans = max(ans, total)
print(ans) | N, T = list(map(int, input().split()))
AB = sorted([list(map(int, input().split())) for _ in range(N)])
dp = [[0] * N for _ in range(T)]
for i in range(1, T):
for j in range(N-1):
if AB[j][0] <= i:
dp[i][j] = max(dp[i][j-1], dp[i-AB[j][0]][j-1] + AB[j][1])
else:
dp[i][j] = dp[i][j-1]
ans = 0
for j in range(1, N):
ans = max(ans, dp[-1][j-1] + AB[j][1])
print(ans) | 31 | 17 | 769 | 426 | n, t = list(map(int, input().split()))
a = [0]
b = [0]
for i in range(n):
a_, b_ = list(map(int, input().split()))
a.append(a_)
b.append(b_)
dp1 = [[0] * t for _ in range(n + 2)]
dp2 = [[0] * t for _ in range(n + 2)]
for i in range(n):
for j in range(t):
if a[i + 1] > j:
dp1[i + 1][j] = dp1[i][j]
else:
dp1[i + 1][j] = max(dp1[i][j], dp1[i][j - a[i + 1]] + b[i + 1])
for i in range(n + 1, 1, -1):
for j in range(t):
if a[i - 1] > j:
dp2[i - 1][j] = dp2[i][j]
else:
dp2[i - 1][j] = max(dp2[i][j], dp2[i][j - a[i - 1]] + b[i - 1])
ans = 0
for i in range(1, n + 1):
for j in range(t):
total = b[i] + dp1[i - 1][j] + dp2[i + 1][t - 1 - j]
ans = max(ans, total)
print(ans)
| N, T = list(map(int, input().split()))
AB = sorted([list(map(int, input().split())) for _ in range(N)])
dp = [[0] * N for _ in range(T)]
for i in range(1, T):
for j in range(N - 1):
if AB[j][0] <= i:
dp[i][j] = max(dp[i][j - 1], dp[i - AB[j][0]][j - 1] + AB[j][1])
else:
dp[i][j] = dp[i][j - 1]
ans = 0
for j in range(1, N):
ans = max(ans, dp[-1][j - 1] + AB[j][1])
print(ans)
| false | 45.16129 | [
"-n, t = list(map(int, input().split()))",
"-a = [0]",
"-b = [0]",
"-for i in range(n):",
"- a_, b_ = list(map(int, input().split()))",
"- a.append(a_)",
"- b.append(b_)",
"-dp1 = [[0] * t for _ in range(n + 2)]",
"-dp2 = [[0] * t for _ in range(n + 2)]",
"-for i in range(n):",
"- for j in range(t):",
"- if a[i + 1] > j:",
"- dp1[i + 1][j] = dp1[i][j]",
"+N, T = list(map(int, input().split()))",
"+AB = sorted([list(map(int, input().split())) for _ in range(N)])",
"+dp = [[0] * N for _ in range(T)]",
"+for i in range(1, T):",
"+ for j in range(N - 1):",
"+ if AB[j][0] <= i:",
"+ dp[i][j] = max(dp[i][j - 1], dp[i - AB[j][0]][j - 1] + AB[j][1])",
"- dp1[i + 1][j] = max(dp1[i][j], dp1[i][j - a[i + 1]] + b[i + 1])",
"-for i in range(n + 1, 1, -1):",
"- for j in range(t):",
"- if a[i - 1] > j:",
"- dp2[i - 1][j] = dp2[i][j]",
"- else:",
"- dp2[i - 1][j] = max(dp2[i][j], dp2[i][j - a[i - 1]] + b[i - 1])",
"+ dp[i][j] = dp[i][j - 1]",
"-for i in range(1, n + 1):",
"- for j in range(t):",
"- total = b[i] + dp1[i - 1][j] + dp2[i + 1][t - 1 - j]",
"- ans = max(ans, total)",
"+for j in range(1, N):",
"+ ans = max(ans, dp[-1][j - 1] + AB[j][1])"
] | false | 0.037192 | 0.04223 | 0.880681 | [
"s745579982",
"s133149498"
] |
u863370423 | p02792 | python | s648771506 | s753621287 | 260 | 146 | 11,636 | 9,156 | Accepted | Accepted | 43.85 | n = int(eval(input()))
letters_mapping = {num: {num2:[] for num2 in range(10)} for num in range(10)}
for num in range(1, n + 1):
first_letter = str(num)[0]
last_letter = str(num)[-1]
letters_mapping[int(first_letter)][int(last_letter)].append(num)
count = 0
for i, v in list(letters_mapping.items()):
for j, x in list(letters_mapping[i].items()):
for num in letters_mapping[i][j]:
count += len(letters_mapping[j][i])
print(count) | n = int(eval(input()))
a = [[0 for i in range(10)] for j in range(10)]
for i in range(1, n+1):
s = str(i)
if s[-1] != '0':
a[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(1, 10):
for j in range(1, 10):
ans += a[i][j] * a[j][i]
print(ans) | 15 | 11 | 477 | 274 | n = int(eval(input()))
letters_mapping = {num: {num2: [] for num2 in range(10)} for num in range(10)}
for num in range(1, n + 1):
first_letter = str(num)[0]
last_letter = str(num)[-1]
letters_mapping[int(first_letter)][int(last_letter)].append(num)
count = 0
for i, v in list(letters_mapping.items()):
for j, x in list(letters_mapping[i].items()):
for num in letters_mapping[i][j]:
count += len(letters_mapping[j][i])
print(count)
| n = int(eval(input()))
a = [[0 for i in range(10)] for j in range(10)]
for i in range(1, n + 1):
s = str(i)
if s[-1] != "0":
a[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(1, 10):
for j in range(1, 10):
ans += a[i][j] * a[j][i]
print(ans)
| false | 26.666667 | [
"-letters_mapping = {num: {num2: [] for num2 in range(10)} for num in range(10)}",
"-for num in range(1, n + 1):",
"- first_letter = str(num)[0]",
"- last_letter = str(num)[-1]",
"- letters_mapping[int(first_letter)][int(last_letter)].append(num)",
"-count = 0",
"-for i, v in list(letters_mapping.items()):",
"- for j, x in list(letters_mapping[i].items()):",
"- for num in letters_mapping[i][j]:",
"- count += len(letters_mapping[j][i])",
"-print(count)",
"+a = [[0 for i in range(10)] for j in range(10)]",
"+for i in range(1, n + 1):",
"+ s = str(i)",
"+ if s[-1] != \"0\":",
"+ a[int(s[0])][int(s[-1])] += 1",
"+ans = 0",
"+for i in range(1, 10):",
"+ for j in range(1, 10):",
"+ ans += a[i][j] * a[j][i]",
"+print(ans)"
] | false | 0.082836 | 0.065148 | 1.271497 | [
"s648771506",
"s753621287"
] |
u282228874 | p03325 | python | s677013935 | s922116244 | 102 | 79 | 4,524 | 4,148 | Accepted | Accepted | 22.55 | n = int(eval(input()))
A = list(map(int,input().split()))
cnt = 0
for a in A:
while a%2 == 0:
cnt += 1
a /= 2
print(cnt)
| N = int(eval(input()))
A = list(map(int,input().split()))
res = 0
for a in A:
while a%2 == 0:
a //= 2
res += 1
print(res) | 8 | 8 | 142 | 142 | n = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
for a in A:
while a % 2 == 0:
cnt += 1
a /= 2
print(cnt)
| N = int(eval(input()))
A = list(map(int, input().split()))
res = 0
for a in A:
while a % 2 == 0:
a //= 2
res += 1
print(res)
| false | 0 | [
"-n = int(eval(input()))",
"+N = int(eval(input()))",
"-cnt = 0",
"+res = 0",
"- cnt += 1",
"- a /= 2",
"-print(cnt)",
"+ a //= 2",
"+ res += 1",
"+print(res)"
] | false | 0.035051 | 0.040966 | 0.855613 | [
"s677013935",
"s922116244"
] |
u844005364 | p03329 | python | s069743152 | s540022218 | 194 | 168 | 42,200 | 38,384 | Accepted | Accepted | 13.4 | import bisect
six_list = [6 ** i for i in range(7)]
nine_list = [9 ** i for i in range(6)]
def six_nine(n):
if n < 6:
return n
else:
six = six_list[bisect.bisect_right(six_list, n) - 1]
nine = nine_list[bisect.bisect_right(nine_list, n) - 1]
return min(n // six + six_nine(n % six), 1 + six_nine(n - nine))
if __name__ == '__main__':
x = int(eval(input()))
print((six_nine(x))) | import bisect
from functools import lru_cache
six_list = [6 ** i for i in range(7)]
nine_list = [9 ** i for i in range(6)]
@lru_cache(maxsize=1000)
def six_nine(n):
if n < 6:
return n
else:
six = six_list[bisect.bisect_right(six_list, n) - 1]
nine = nine_list[bisect.bisect_right(nine_list, n) - 1]
return min(n // six + six_nine(n % six), 1 + six_nine(n - nine))
if __name__ == '__main__':
x = int(eval(input()))
print((six_nine(x))) | 18 | 20 | 439 | 498 | import bisect
six_list = [6**i for i in range(7)]
nine_list = [9**i for i in range(6)]
def six_nine(n):
if n < 6:
return n
else:
six = six_list[bisect.bisect_right(six_list, n) - 1]
nine = nine_list[bisect.bisect_right(nine_list, n) - 1]
return min(n // six + six_nine(n % six), 1 + six_nine(n - nine))
if __name__ == "__main__":
x = int(eval(input()))
print((six_nine(x)))
| import bisect
from functools import lru_cache
six_list = [6**i for i in range(7)]
nine_list = [9**i for i in range(6)]
@lru_cache(maxsize=1000)
def six_nine(n):
if n < 6:
return n
else:
six = six_list[bisect.bisect_right(six_list, n) - 1]
nine = nine_list[bisect.bisect_right(nine_list, n) - 1]
return min(n // six + six_nine(n % six), 1 + six_nine(n - nine))
if __name__ == "__main__":
x = int(eval(input()))
print((six_nine(x)))
| false | 10 | [
"+from functools import lru_cache",
"+@lru_cache(maxsize=1000)"
] | false | 0.082287 | 0.04259 | 1.932096 | [
"s069743152",
"s540022218"
] |
u346812984 | p03311 | python | s356351967 | s022279709 | 205 | 189 | 25,196 | 25,872 | Accepted | Accepted | 7.8 | N = int(eval(input()))
A = list(map(int, input().split()))
A_i = [A[i] - i - 1 for i in range(N)]
A_i.sort()
b = A_i[N // 2]
ans = 0
for a in A_i:
ans += abs(a - b)
print(ans)
| import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
def input():
return sys.stdin.readline().strip()
def main():
N = int(eval(input()))
A = list(map(int, input().split()))
A = [a - i - 1 for i, a in enumerate(A)]
A.sort()
i = N // 2
b = A[i]
ans = 0
for a in A:
ans += abs(a - b)
print(ans)
if __name__ == "__main__":
main()
| 11 | 26 | 186 | 430 | N = int(eval(input()))
A = list(map(int, input().split()))
A_i = [A[i] - i - 1 for i in range(N)]
A_i.sort()
b = A_i[N // 2]
ans = 0
for a in A_i:
ans += abs(a - b)
print(ans)
| import sys
sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7
def input():
return sys.stdin.readline().strip()
def main():
N = int(eval(input()))
A = list(map(int, input().split()))
A = [a - i - 1 for i, a in enumerate(A)]
A.sort()
i = N // 2
b = A[i]
ans = 0
for a in A:
ans += abs(a - b)
print(ans)
if __name__ == "__main__":
main()
| false | 57.692308 | [
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-A_i = [A[i] - i - 1 for i in range(N)]",
"-A_i.sort()",
"-b = A_i[N // 2]",
"-ans = 0",
"-for a in A_i:",
"- ans += abs(a - b)",
"-print(ans)",
"+import sys",
"+",
"+sys.setrecursionlimit(10**6)",
"+INF = float(\"inf\")",
"+MOD = 10**9 + 7",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+",
"+def main():",
"+ N = int(eval(input()))",
"+ A = list(map(int, input().split()))",
"+ A = [a - i - 1 for i, a in enumerate(A)]",
"+ A.sort()",
"+ i = N // 2",
"+ b = A[i]",
"+ ans = 0",
"+ for a in A:",
"+ ans += abs(a - b)",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.047981 | 0.043321 | 1.10757 | [
"s356351967",
"s022279709"
] |
u835924161 | p03327 | python | s519519350 | s182445230 | 26 | 24 | 9,024 | 9,092 | Accepted | Accepted | 7.69 | n=int(eval(input()))
if n<=999:
print("ABC")
else:
print("ABD") | if int(eval(input()))<=999:
print("ABC")
else:
print("ABD") | 6 | 4 | 71 | 64 | n = int(eval(input()))
if n <= 999:
print("ABC")
else:
print("ABD")
| if int(eval(input())) <= 999:
print("ABC")
else:
print("ABD")
| false | 33.333333 | [
"-n = int(eval(input()))",
"-if n <= 999:",
"+if int(eval(input())) <= 999:"
] | false | 0.047032 | 0.047736 | 0.985252 | [
"s519519350",
"s182445230"
] |
u814986259 | p02885 | python | s486935839 | s176170156 | 20 | 17 | 3,060 | 3,064 | Accepted | Accepted | 15 | A, B = list(map(int, input().split()))
print((max(0, A - 2*B)))
| a,b=list(map(int,input().split()))
print((max(0,a-b-b))) | 3 | 2 | 59 | 49 | A, B = list(map(int, input().split()))
print((max(0, A - 2 * B)))
| a, b = list(map(int, input().split()))
print((max(0, a - b - b)))
| false | 33.333333 | [
"-A, B = list(map(int, input().split()))",
"-print((max(0, A - 2 * B)))",
"+a, b = list(map(int, input().split()))",
"+print((max(0, a - b - b)))"
] | false | 0.064458 | 0.06462 | 0.997487 | [
"s486935839",
"s176170156"
] |
u263830634 | p03032 | python | s226208847 | s294465256 | 31 | 28 | 3,064 | 3,064 | Accepted | Accepted | 9.68 | N, K = list(map(int, input().split()))
lst = list(map(int, input().split()))
ans = 0
A = 0
while A <= min(K, N):
B = 0
lst2 = []
while B <= min(K, N) - A:
lst2 = lst[:A]+lst[N-B:]
lst2.sort()
count = 0
for i in range(len(lst2)):
if lst2[i] <= 0 and i+1 <= K - A - B:
pass
else:
count += lst2[i]
ans = max(ans, count)
B += 1
A += 1
print (ans)
| N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
for left in range(min(N, K) + 1):
for right in range(min(N - left, K - left) + 1):
tmp = V[:left] + V[N - right:]
tmp.sort()
score = 0
count = K - left - right
for i in tmp:
if count <= 0:
score += i
else:
if i < 0:
count -= 1
else:
score += i
# print (left, right, score, tmp)
ans = max(ans, score)
print (ans) | 22 | 22 | 480 | 583 | N, K = list(map(int, input().split()))
lst = list(map(int, input().split()))
ans = 0
A = 0
while A <= min(K, N):
B = 0
lst2 = []
while B <= min(K, N) - A:
lst2 = lst[:A] + lst[N - B :]
lst2.sort()
count = 0
for i in range(len(lst2)):
if lst2[i] <= 0 and i + 1 <= K - A - B:
pass
else:
count += lst2[i]
ans = max(ans, count)
B += 1
A += 1
print(ans)
| N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
for left in range(min(N, K) + 1):
for right in range(min(N - left, K - left) + 1):
tmp = V[:left] + V[N - right :]
tmp.sort()
score = 0
count = K - left - right
for i in tmp:
if count <= 0:
score += i
else:
if i < 0:
count -= 1
else:
score += i
# print (left, right, score, tmp)
ans = max(ans, score)
print(ans)
| false | 0 | [
"-lst = list(map(int, input().split()))",
"+V = list(map(int, input().split()))",
"-A = 0",
"-while A <= min(K, N):",
"- B = 0",
"- lst2 = []",
"- while B <= min(K, N) - A:",
"- lst2 = lst[:A] + lst[N - B :]",
"- lst2.sort()",
"- count = 0",
"- for i in range(len(lst2)):",
"- if lst2[i] <= 0 and i + 1 <= K - A - B:",
"- pass",
"+for left in range(min(N, K) + 1):",
"+ for right in range(min(N - left, K - left) + 1):",
"+ tmp = V[:left] + V[N - right :]",
"+ tmp.sort()",
"+ score = 0",
"+ count = K - left - right",
"+ for i in tmp:",
"+ if count <= 0:",
"+ score += i",
"- count += lst2[i]",
"- ans = max(ans, count)",
"- B += 1",
"- A += 1",
"+ if i < 0:",
"+ count -= 1",
"+ else:",
"+ score += i",
"+ # print (left, right, score, tmp)",
"+ ans = max(ans, score)"
] | false | 0.050043 | 0.050123 | 0.998396 | [
"s226208847",
"s294465256"
] |
u891635666 | p03380 | python | s955212009 | s914347701 | 103 | 66 | 14,056 | 14,052 | Accepted | Accepted | 35.92 | n = int(eval(input()))
ls = sorted(map(int, input().split()))
ds = [abs(x - ls[-1] / 2) for x in ls[:-1]]
print((ls[-1], ls[ds.index(min(ds))])) | n = int(eval(input()))
ls = list(map(int, input().split()))
m = max(ls)
ls.remove(m)
ds = [abs(x - m / 2) for x in ls]
print((m, ls[ds.index(min(ds))])) | 4 | 6 | 139 | 149 | n = int(eval(input()))
ls = sorted(map(int, input().split()))
ds = [abs(x - ls[-1] / 2) for x in ls[:-1]]
print((ls[-1], ls[ds.index(min(ds))]))
| n = int(eval(input()))
ls = list(map(int, input().split()))
m = max(ls)
ls.remove(m)
ds = [abs(x - m / 2) for x in ls]
print((m, ls[ds.index(min(ds))]))
| false | 33.333333 | [
"-ls = sorted(map(int, input().split()))",
"-ds = [abs(x - ls[-1] / 2) for x in ls[:-1]]",
"-print((ls[-1], ls[ds.index(min(ds))]))",
"+ls = list(map(int, input().split()))",
"+m = max(ls)",
"+ls.remove(m)",
"+ds = [abs(x - m / 2) for x in ls]",
"+print((m, ls[ds.index(min(ds))]))"
] | false | 0.036231 | 0.059268 | 0.611311 | [
"s955212009",
"s914347701"
] |
u536034761 | p02888 | python | s097885733 | s556362577 | 1,394 | 1,106 | 9,316 | 9,492 | Accepted | Accepted | 20.66 | import bisect
from itertools import combinations
def main():
N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for l in combinations(L, 2):
a = l[0]
b = l[1]
x = bisect.bisect_left(L, a + b)
y = bisect.bisect(L, b - a)
if b - a < a :
ans += x - y - 2
else:
ans += x - y - 1
print((ans // 3))
if __name__ == "__main__":
main()
| import bisect
from copy import deepcopy
N = int(eval(input()))
L = sorted(map(int, input().split()))
ans = 0
for i in range(N):
for j in range(i + 1, N - 1):
b = L[j] + L[i]
x = bisect.bisect_left(L, b) - j - 1
if x > 0:
ans += x
print(ans)
| 21 | 14 | 462 | 290 | import bisect
from itertools import combinations
def main():
N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for l in combinations(L, 2):
a = l[0]
b = l[1]
x = bisect.bisect_left(L, a + b)
y = bisect.bisect(L, b - a)
if b - a < a:
ans += x - y - 2
else:
ans += x - y - 1
print((ans // 3))
if __name__ == "__main__":
main()
| import bisect
from copy import deepcopy
N = int(eval(input()))
L = sorted(map(int, input().split()))
ans = 0
for i in range(N):
for j in range(i + 1, N - 1):
b = L[j] + L[i]
x = bisect.bisect_left(L, b) - j - 1
if x > 0:
ans += x
print(ans)
| false | 33.333333 | [
"-from itertools import combinations",
"+from copy import deepcopy",
"-",
"-def main():",
"- N = int(eval(input()))",
"- L = sorted(list(map(int, input().split())))",
"- ans = 0",
"- for l in combinations(L, 2):",
"- a = l[0]",
"- b = l[1]",
"- x = bisect.bisect_left(L, a + b)",
"- y = bisect.bisect(L, b - a)",
"- if b - a < a:",
"- ans += x - y - 2",
"- else:",
"- ans += x - y - 1",
"- print((ans // 3))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+N = int(eval(input()))",
"+L = sorted(map(int, input().split()))",
"+ans = 0",
"+for i in range(N):",
"+ for j in range(i + 1, N - 1):",
"+ b = L[j] + L[i]",
"+ x = bisect.bisect_left(L, b) - j - 1",
"+ if x > 0:",
"+ ans += x",
"+print(ans)"
] | false | 0.039282 | 0.081291 | 0.483226 | [
"s097885733",
"s556362577"
] |
u501952592 | p02866 | python | s307320972 | s146456779 | 108 | 95 | 24,248 | 24,512 | Accepted | Accepted | 12.04 | from collections import Counter
N = int(eval(input()))
D = list(map(int, input().split()))
mod = 998244353
c = Counter(D)
m = max(c.keys())
if D[0] == 0 and c[0] == 1:
ans = 1
for i in range(1, m+1):
ans *= c[i-1]**c[i]
ans %= mod
print(ans)
else:
print((0)) | from collections import Counter
N = int(eval(input()))
D = list(map(int, input().split()))
mod = 998244353
c = Counter(D)
m = max(c.keys())
if D[0] == 0 and c[0] == 1:
ans = 1
for i in D[1:]:
ans *= c[i-1]
ans %= mod
print(ans)
else:
print((0)) | 17 | 17 | 285 | 271 | from collections import Counter
N = int(eval(input()))
D = list(map(int, input().split()))
mod = 998244353
c = Counter(D)
m = max(c.keys())
if D[0] == 0 and c[0] == 1:
ans = 1
for i in range(1, m + 1):
ans *= c[i - 1] ** c[i]
ans %= mod
print(ans)
else:
print((0))
| from collections import Counter
N = int(eval(input()))
D = list(map(int, input().split()))
mod = 998244353
c = Counter(D)
m = max(c.keys())
if D[0] == 0 and c[0] == 1:
ans = 1
for i in D[1:]:
ans *= c[i - 1]
ans %= mod
print(ans)
else:
print((0))
| false | 0 | [
"- for i in range(1, m + 1):",
"- ans *= c[i - 1] ** c[i]",
"+ for i in D[1:]:",
"+ ans *= c[i - 1]"
] | false | 0.05034 | 0.092443 | 0.544555 | [
"s307320972",
"s146456779"
] |
u693953100 | p02994 | python | s534385653 | s569015787 | 22 | 17 | 3,064 | 2,940 | Accepted | Accepted | 22.73 | n,l = list(map(int,input().split()))
id = 0
ans = 0
for i in range(n):
ans+=l+i
if abs(l+id)>abs(l+i):
id = i
print((ans-l-id)) | def solve():
n,l = list(map(int,input().split()))
mn = 10**10
s = 0
for i in range(n):
s+=l+i
if abs(mn)>abs(l+i):
mn = l+i
print((s-mn))
if __name__=='__main__':
solve() | 8 | 11 | 142 | 224 | n, l = list(map(int, input().split()))
id = 0
ans = 0
for i in range(n):
ans += l + i
if abs(l + id) > abs(l + i):
id = i
print((ans - l - id))
| def solve():
n, l = list(map(int, input().split()))
mn = 10**10
s = 0
for i in range(n):
s += l + i
if abs(mn) > abs(l + i):
mn = l + i
print((s - mn))
if __name__ == "__main__":
solve()
| false | 27.272727 | [
"-n, l = list(map(int, input().split()))",
"-id = 0",
"-ans = 0",
"-for i in range(n):",
"- ans += l + i",
"- if abs(l + id) > abs(l + i):",
"- id = i",
"-print((ans - l - id))",
"+def solve():",
"+ n, l = list(map(int, input().split()))",
"+ mn = 10**10",
"+ s = 0",
"+ for i in range(n):",
"+ s += l + i",
"+ if abs(mn) > abs(l + i):",
"+ mn = l + i",
"+ print((s - mn))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
] | false | 0.048106 | 0.047059 | 1.022262 | [
"s534385653",
"s569015787"
] |
u631277801 | p04045 | python | s455986740 | s576371435 | 106 | 39 | 3,060 | 3,060 | Accepted | Accepted | 63.21 | N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
while True:
flag = 1
N_str = list(str(N))
for s in N_str:
if int(s) in D:
flag = 0
break
if flag:
print(N)
break
N += 1 | N,K = list(map(int, input().split()))
D = set(list(map(int, input().split())))
ans = 0
for i in range(N, 10*N+1):
res = i
while res > 0:
digit = res % 10
if digit in D:
break
res //= 10
if res <= 0:
ans = i
break
print(ans) | 17 | 20 | 288 | 333 | N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
while True:
flag = 1
N_str = list(str(N))
for s in N_str:
if int(s) in D:
flag = 0
break
if flag:
print(N)
break
N += 1
| N, K = list(map(int, input().split()))
D = set(list(map(int, input().split())))
ans = 0
for i in range(N, 10 * N + 1):
res = i
while res > 0:
digit = res % 10
if digit in D:
break
res //= 10
if res <= 0:
ans = i
break
print(ans)
| false | 15 | [
"-D = list(map(int, input().split()))",
"-while True:",
"- flag = 1",
"- N_str = list(str(N))",
"- for s in N_str:",
"- if int(s) in D:",
"- flag = 0",
"+D = set(list(map(int, input().split())))",
"+ans = 0",
"+for i in range(N, 10 * N + 1):",
"+ res = i",
"+ while res > 0:",
"+ digit = res % 10",
"+ if digit in D:",
"- if flag:",
"- print(N)",
"+ res //= 10",
"+ if res <= 0:",
"+ ans = i",
"- N += 1",
"+print(ans)"
] | false | 0.041783 | 0.042025 | 0.994248 | [
"s455986740",
"s576371435"
] |
u631277801 | p03215 | python | s353284840 | s474813538 | 348 | 272 | 92,084 | 66,016 | Accepted | Accepted | 21.84 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
from itertools import accumulate
n,k = li()
a = list(li())
acum = list(accumulate([0]+a))
cand = []
for i in range(n+1):
for j in range(i+1,n+1):
cand.append(acum[j] - acum[i])
ans = 0
for mask in range(40, -1, -1):
satis = sum([bool(ci&(1<<mask)) for ci in cand])
if satis >= k:
ans += (1<<mask)
nex = [ci for ci in cand if ci & (1<<mask)]
cand = nex
print(ans) | import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x) - 1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
n, k = li()
a = list(li())
cum = [0]
for ai in a:
cum.append(cum[-1] + ai)
pool = []
for i in range(n+1):
for j in range(i+1, n+1):
pool.append(cum[j] - cum[i])
MAX_BIT = 41
ans = 0
for bit in range(MAX_BIT, -1, -1):
new_pool = []
for poli in pool:
if poli & (1<<bit):
new_pool.append(poli)
if len(new_pool) >= k:
ans += (1<<bit)
pool = new_pool
print(ans) | 38 | 39 | 890 | 895 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li():
return list(map(int, stdin.readline().split()))
def li_():
return [int(x) - 1 for x in stdin.readline().split()]
def lf():
return list(map(float, stdin.readline().split()))
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
from itertools import accumulate
n, k = li()
a = list(li())
acum = list(accumulate([0] + a))
cand = []
for i in range(n + 1):
for j in range(i + 1, n + 1):
cand.append(acum[j] - acum[i])
ans = 0
for mask in range(40, -1, -1):
satis = sum([bool(ci & (1 << mask)) for ci in cand])
if satis >= k:
ans += 1 << mask
nex = [ci for ci in cand if ci & (1 << mask)]
cand = nex
print(ans)
| import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
def li():
return list(map(int, stdin.readline().split()))
def li_():
return [int(x) - 1 for x in stdin.readline().split()]
def lf():
return list(map(float, stdin.readline().split()))
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
n, k = li()
a = list(li())
cum = [0]
for ai in a:
cum.append(cum[-1] + ai)
pool = []
for i in range(n + 1):
for j in range(i + 1, n + 1):
pool.append(cum[j] - cum[i])
MAX_BIT = 41
ans = 0
for bit in range(MAX_BIT, -1, -1):
new_pool = []
for poli in pool:
if poli & (1 << bit):
new_pool.append(poli)
if len(new_pool) >= k:
ans += 1 << bit
pool = new_pool
print(ans)
| false | 2.564103 | [
"-sys.setrecursionlimit(10**5)",
"+sys.setrecursionlimit(10**7)",
"-from itertools import accumulate",
"-",
"-acum = list(accumulate([0] + a))",
"-cand = []",
"+cum = [0]",
"+for ai in a:",
"+ cum.append(cum[-1] + ai)",
"+pool = []",
"- cand.append(acum[j] - acum[i])",
"+ pool.append(cum[j] - cum[i])",
"+MAX_BIT = 41",
"-for mask in range(40, -1, -1):",
"- satis = sum([bool(ci & (1 << mask)) for ci in cand])",
"- if satis >= k:",
"- ans += 1 << mask",
"- nex = [ci for ci in cand if ci & (1 << mask)]",
"- cand = nex",
"+for bit in range(MAX_BIT, -1, -1):",
"+ new_pool = []",
"+ for poli in pool:",
"+ if poli & (1 << bit):",
"+ new_pool.append(poli)",
"+ if len(new_pool) >= k:",
"+ ans += 1 << bit",
"+ pool = new_pool"
] | false | 0.036081 | 0.098196 | 0.367438 | [
"s353284840",
"s474813538"
] |
u690536347 | p03280 | python | s782401548 | s590829736 | 25 | 17 | 3,316 | 2,940 | Accepted | Accepted | 32 | a,b=list(map(int,input().split()))
c=(a*b)-(b+a-1)
print(c) | a,b=list(map(int,input().split()))
print((a*b-a-b+1)) | 3 | 2 | 55 | 46 | a, b = list(map(int, input().split()))
c = (a * b) - (b + a - 1)
print(c)
| a, b = list(map(int, input().split()))
print((a * b - a - b + 1))
| false | 33.333333 | [
"-c = (a * b) - (b + a - 1)",
"-print(c)",
"+print((a * b - a - b + 1))"
] | false | 0.037807 | 0.007451 | 5.074354 | [
"s782401548",
"s590829736"
] |
u761529120 | p03039 | python | s524070110 | s848047100 | 391 | 203 | 129,620 | 68,336 | Accepted | Accepted | 48.08 | def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
def main():
N, M, K = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(1,N):
ans += i * (N - i) * M * M
ans %= mod
for j in range(1,M):
ans += j * (M - j) * N * N
ans %= mod
ans *= cmb(N*M-2,K-2,mod)
print((ans%mod))
if __name__ == "__main__":
main() | class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
if n < r:
return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
def main():
N, M, K = list(map(int, input().split()))
MOD = 10 ** 9 + 7
comb = Combination(N*M)
ans = 0
for i in range(M):
ans += i * (M - i) * N * N
ans %= MOD
for i in range(N):
ans += i * (N - i) * M * M
ans %= MOD
ans *= comb(N*M-2,K-2)
ans %= MOD
print(ans)
if __name__ == "__main__":
main() | 38 | 57 | 778 | 1,566 | def cmb(n, r, mod):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
mod = 10**9 + 7 # 出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
def main():
N, M, K = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
for i in range(1, N):
ans += i * (N - i) * M * M
ans %= mod
for j in range(1, M):
ans += j * (M - j) * N * N
ans %= mod
ans *= cmb(N * M - 2, K - 2, mod)
print((ans % mod))
if __name__ == "__main__":
main()
| class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9 + 7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
if n < r:
return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n + 1):
fac.append(fac[i - 1] * i % self.mod)
facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n + 1)
modinv[1] = 1
for i in range(2, n + 1):
modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
return modinv
def main():
N, M, K = list(map(int, input().split()))
MOD = 10**9 + 7
comb = Combination(N * M)
ans = 0
for i in range(M):
ans += i * (M - i) * N * N
ans %= MOD
for i in range(N):
ans += i * (N - i) * M * M
ans %= MOD
ans *= comb(N * M - 2, K - 2)
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| false | 33.333333 | [
"-def cmb(n, r, mod):",
"- if r < 0 or r > n:",
"- return 0",
"- r = min(r, n - r)",
"- return g1[n] * g2[r] * g2[n - r] % mod",
"+class Combination:",
"+ \"\"\"",
"+ O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる",
"+ n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)",
"+ 使用例:",
"+ comb = Combination(1000000)",
"+ print(comb(5, 3)) # 10",
"+ \"\"\"",
"+ def __init__(self, n_max, mod=10**9 + 7):",
"+ self.mod = mod",
"+ self.modinv = self.make_modinv_list(n_max)",
"+ self.fac, self.facinv = self.make_factorial_list(n_max)",
"-mod = 10**9 + 7 # 出力の制限",
"-N = 10**6",
"-g1 = [1, 1] # 元テーブル",
"-g2 = [1, 1] # 逆元テーブル",
"-inverse = [0, 1] # 逆元テーブル計算用テーブル",
"-for i in range(2, N + 1):",
"- g1.append((g1[-1] * i) % mod)",
"- inverse.append((-inverse[mod % i] * (mod // i)) % mod)",
"- g2.append((g2[-1] * inverse[-1]) % mod)",
"+ def __call__(self, n, r):",
"+ if n < r:",
"+ return 0",
"+ return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod",
"+",
"+ def make_factorial_list(self, n):",
"+ # 階乗のリストと階乗のmod逆元のリストを返す O(n)",
"+ # self.make_modinv_list()が先に実行されている必要がある",
"+ fac = [1]",
"+ facinv = [1]",
"+ for i in range(1, n + 1):",
"+ fac.append(fac[i - 1] * i % self.mod)",
"+ facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)",
"+ return fac, facinv",
"+",
"+ def make_modinv_list(self, n):",
"+ # 0からnまでのmod逆元のリストを返す O(n)",
"+ modinv = [0] * (n + 1)",
"+ modinv[1] = 1",
"+ for i in range(2, n + 1):",
"+ modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod",
"+ return modinv",
"- mod = 10**9 + 7",
"+ MOD = 10**9 + 7",
"+ comb = Combination(N * M)",
"- for i in range(1, N):",
"+ for i in range(M):",
"+ ans += i * (M - i) * N * N",
"+ ans %= MOD",
"+ for i in range(N):",
"- ans %= mod",
"- for j in range(1, M):",
"- ans += j * (M - j) * N * N",
"- ans %= mod",
"- ans *= cmb(N * M - 2, K - 2, mod)",
"- print((ans % mod))",
"+ ans %= MOD",
"+ ans *= comb(N * M - 2, K - 2)",
"+ ans %= MOD",
"+ print(ans)"
] | false | 1.879933 | 0.043494 | 43.222354 | [
"s524070110",
"s848047100"
] |
u729133443 | p02624 | python | s063212083 | s324355382 | 1,731 | 308 | 9,168 | 73,164 | Accepted | Accepted | 82.21 | n=int(eval(input()))
print((n+sum(n//i*(i+n-n%i)//2for i in range(1,n)))) | n=int(eval(input()))
print((n+sum(n//i*(n-n%i+i)>>1for i in range(1,n)))) | 2 | 2 | 66 | 66 | n = int(eval(input()))
print((n + sum(n // i * (i + n - n % i) // 2 for i in range(1, n))))
| n = int(eval(input()))
print((n + sum(n // i * (n - n % i + i) >> 1 for i in range(1, n))))
| false | 0 | [
"-print((n + sum(n // i * (i + n - n % i) // 2 for i in range(1, n))))",
"+print((n + sum(n // i * (n - n % i + i) >> 1 for i in range(1, n))))"
] | false | 0.00789 | 1.022675 | 0.007715 | [
"s063212083",
"s324355382"
] |
u944325914 | p03031 | python | s502978559 | s178921733 | 46 | 36 | 9,156 | 9,008 | Accepted | Accepted | 21.74 | n,m=list(map(int,input().split()))
switch_list=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
result=[0]*m
for j in range(n):
if (i>>j)&1:
for k in range(m):
if j+1 in switch_list[k][1:]:
result[k]+=1
for l in range(m):
if (result[l]%2)!=p[l]:
break
else:
ans+=1
print(ans) | from itertools import product
n,m=list(map(int,input().split()))
ks=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split()))
count=0
for i in product([0,1],repeat=n):
for j in range(m):
temp=0
for k in range(ks[j][0]):
if i[ks[j][k+1]-1]==1:
temp+=1
if temp%2!=p[j]:
break
else:
count+=1
print(count)
| 17 | 17 | 444 | 428 | n, m = list(map(int, input().split()))
switch_list = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
result = [0] * m
for j in range(n):
if (i >> j) & 1:
for k in range(m):
if j + 1 in switch_list[k][1:]:
result[k] += 1
for l in range(m):
if (result[l] % 2) != p[l]:
break
else:
ans += 1
print(ans)
| from itertools import product
n, m = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
count = 0
for i in product([0, 1], repeat=n):
for j in range(m):
temp = 0
for k in range(ks[j][0]):
if i[ks[j][k + 1] - 1] == 1:
temp += 1
if temp % 2 != p[j]:
break
else:
count += 1
print(count)
| false | 0 | [
"+from itertools import product",
"+",
"-switch_list = [list(map(int, input().split())) for _ in range(m)]",
"+ks = [list(map(int, input().split())) for _ in range(m)]",
"-ans = 0",
"-for i in range(2**n):",
"- result = [0] * m",
"- for j in range(n):",
"- if (i >> j) & 1:",
"- for k in range(m):",
"- if j + 1 in switch_list[k][1:]:",
"- result[k] += 1",
"- for l in range(m):",
"- if (result[l] % 2) != p[l]:",
"+count = 0",
"+for i in product([0, 1], repeat=n):",
"+ for j in range(m):",
"+ temp = 0",
"+ for k in range(ks[j][0]):",
"+ if i[ks[j][k + 1] - 1] == 1:",
"+ temp += 1",
"+ if temp % 2 != p[j]:",
"- ans += 1",
"-print(ans)",
"+ count += 1",
"+print(count)"
] | false | 0.084528 | 0.080658 | 1.047969 | [
"s502978559",
"s178921733"
] |
u721316601 | p02983 | python | s926918822 | s793354835 | 755 | 213 | 3,060 | 12,792 | Accepted | Accepted | 71.79 | L, R = list(map(int, input().split()))
ans = 10**20
if R-L < 2019:
ans = 10**20
for i in range(L, R):
n = i % 2019
for j in range(i+1, R+1):
ans = min(ans, n * j % 2019)
else:
ans = 0
print(ans) | import numpy as np
L, R = list(map(int, input().split()))
if R-L < 2019:
ans = 10**20
for i in range(L, R):
ans = min(ans, np.min(np.arange(i+1, R+1) * i % 2019))
else:
ans = 0
print(ans) | 13 | 12 | 242 | 215 | L, R = list(map(int, input().split()))
ans = 10**20
if R - L < 2019:
ans = 10**20
for i in range(L, R):
n = i % 2019
for j in range(i + 1, R + 1):
ans = min(ans, n * j % 2019)
else:
ans = 0
print(ans)
| import numpy as np
L, R = list(map(int, input().split()))
if R - L < 2019:
ans = 10**20
for i in range(L, R):
ans = min(ans, np.min(np.arange(i + 1, R + 1) * i % 2019))
else:
ans = 0
print(ans)
| false | 7.692308 | [
"+import numpy as np",
"+",
"-ans = 10**20",
"- n = i % 2019",
"- for j in range(i + 1, R + 1):",
"- ans = min(ans, n * j % 2019)",
"+ ans = min(ans, np.min(np.arange(i + 1, R + 1) * i % 2019))"
] | false | 0.067678 | 0.179869 | 0.376263 | [
"s926918822",
"s793354835"
] |
u930705402 | p02733 | python | s023549877 | s749506851 | 447 | 413 | 46,300 | 46,428 | Accepted | Accepted | 7.61 | H,W,K=list(map(int,input().split()))
S=[list(map(int,list(eval(input())))) for i in range(H)]
ans=H+W-2
for bit in range(2**(H-1)):
divH=[0]
for j in range(H-1):
if(bit>>j&1):
divH.append(j+1)
divH.append(H)
glen=len(divH)-1
group=[0]*(glen)
res=glen-1
go=True
w=0
while w<W:
ok=True
c=[0]*(glen)
for g in range(glen):
cum=0
for h in range(divH[g],divH[g+1]):
cum+=S[h][w]
c[g]+=cum
if cum>K:
go=False
break
if c[g]+group[g]>K:
ok=False
if not go:
break
if not ok:
res+=1
group=[0]*glen
else:
for i in range(glen):
group[i]+=c[i]
w+=1
if not go:
continue
ans=min(ans,res)
print(ans) | H,W,K=list(map(int,input().split()))
S=[list(map(int,list(eval(input())))) for i in range(H)]
ans=H+W-2
for bit in range(2**(H-1)):
divH=[0]
for j in range(H-1):
if(bit>>j&1):
divH.append(j+1)
divH.append(H)
glen=len(divH)-1
group=[0]*(glen)
res=glen-1
go=True
for w in range(W):
ok=True
c=[0]*(glen)
for g in range(glen):
cum=0
for h in range(divH[g],divH[g+1]):
cum+=S[h][w]
c[g]+=cum
if cum>K:
go=False
if cum+group[g]>K:
ok=False
if not go:
break
if not ok:
res+=1
group=[c[i] for i in range(glen)]
else:
for i in range(glen):
group[i]+=c[i]
if not go:
continue
ans=min(ans,res)
print(ans)
| 40 | 37 | 929 | 906 | H, W, K = list(map(int, input().split()))
S = [list(map(int, list(eval(input())))) for i in range(H)]
ans = H + W - 2
for bit in range(2 ** (H - 1)):
divH = [0]
for j in range(H - 1):
if bit >> j & 1:
divH.append(j + 1)
divH.append(H)
glen = len(divH) - 1
group = [0] * (glen)
res = glen - 1
go = True
w = 0
while w < W:
ok = True
c = [0] * (glen)
for g in range(glen):
cum = 0
for h in range(divH[g], divH[g + 1]):
cum += S[h][w]
c[g] += cum
if cum > K:
go = False
break
if c[g] + group[g] > K:
ok = False
if not go:
break
if not ok:
res += 1
group = [0] * glen
else:
for i in range(glen):
group[i] += c[i]
w += 1
if not go:
continue
ans = min(ans, res)
print(ans)
| H, W, K = list(map(int, input().split()))
S = [list(map(int, list(eval(input())))) for i in range(H)]
ans = H + W - 2
for bit in range(2 ** (H - 1)):
divH = [0]
for j in range(H - 1):
if bit >> j & 1:
divH.append(j + 1)
divH.append(H)
glen = len(divH) - 1
group = [0] * (glen)
res = glen - 1
go = True
for w in range(W):
ok = True
c = [0] * (glen)
for g in range(glen):
cum = 0
for h in range(divH[g], divH[g + 1]):
cum += S[h][w]
c[g] += cum
if cum > K:
go = False
if cum + group[g] > K:
ok = False
if not go:
break
if not ok:
res += 1
group = [c[i] for i in range(glen)]
else:
for i in range(glen):
group[i] += c[i]
if not go:
continue
ans = min(ans, res)
print(ans)
| false | 7.5 | [
"- w = 0",
"- while w < W:",
"+ for w in range(W):",
"- break",
"- if c[g] + group[g] > K:",
"+ if cum + group[g] > K:",
"- group = [0] * glen",
"+ group = [c[i] for i in range(glen)]",
"- w += 1"
] | false | 0.118875 | 0.112472 | 1.056934 | [
"s023549877",
"s749506851"
] |
u652656291 | p03252 | python | s613859226 | s942700004 | 128 | 81 | 6,704 | 3,632 | Accepted | Accepted | 36.72 | s=list(eval(input()))
t=list(eval(input()))
S=sorted(map(s.count,set(s)))
T=sorted(map(t.count,set(t)))
print(("Yes" if S==T else "No"))
| S,T = eval(input()),eval(input())
convert = dict()
bl = True
for s,t in zip(S,T):
if s in convert and convert[s] != t:
bl = False
break
convert[s] = t
# 変換先の重複チェック
after = list(convert.values())
if len(after) != len(set(after)):
bl = False
print(('Yes' if bl else 'No'))
| 5 | 17 | 127 | 285 | s = list(eval(input()))
t = list(eval(input()))
S = sorted(map(s.count, set(s)))
T = sorted(map(t.count, set(t)))
print(("Yes" if S == T else "No"))
| S, T = eval(input()), eval(input())
convert = dict()
bl = True
for s, t in zip(S, T):
if s in convert and convert[s] != t:
bl = False
break
convert[s] = t
# 変換先の重複チェック
after = list(convert.values())
if len(after) != len(set(after)):
bl = False
print(("Yes" if bl else "No"))
| false | 70.588235 | [
"-s = list(eval(input()))",
"-t = list(eval(input()))",
"-S = sorted(map(s.count, set(s)))",
"-T = sorted(map(t.count, set(t)))",
"-print((\"Yes\" if S == T else \"No\"))",
"+S, T = eval(input()), eval(input())",
"+convert = dict()",
"+bl = True",
"+for s, t in zip(S, T):",
"+ if s in convert and convert[s] != t:",
"+ bl = False",
"+ break",
"+ convert[s] = t",
"+# 変換先の重複チェック",
"+after = list(convert.values())",
"+if len(after) != len(set(after)):",
"+ bl = False",
"+print((\"Yes\" if bl else \"No\"))"
] | false | 0.039262 | 0.035232 | 1.114386 | [
"s613859226",
"s942700004"
] |
u073549161 | p03643 | python | s345218913 | s919667992 | 170 | 18 | 38,256 | 2,940 | Accepted | Accepted | 89.41 | print(("ABC" + eval(input()))) | n= int(eval(input()))
print(("ABC" + str(n)))
| 1 | 2 | 22 | 39 | print(("ABC" + eval(input())))
| n = int(eval(input()))
print(("ABC" + str(n)))
| false | 50 | [
"-print((\"ABC\" + eval(input())))",
"+n = int(eval(input()))",
"+print((\"ABC\" + str(n)))"
] | false | 0.092843 | 0.046823 | 1.982862 | [
"s345218913",
"s919667992"
] |
u334712262 | p03074 | python | s702174395 | s358128040 | 182 | 168 | 7,092 | 11,624 | Accepted | Accepted | 7.69 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, K, S):
s1 = list(map(lambda x: len(x), filter(lambda x: x != '', S.split('0'))))
s0 = list(map(lambda x: len(x), filter(lambda x: x != '', S.split('1'))))
if len(s0) <= K:
return N
# error_print(N, K)
# error_print(S)
# error_print(s1)
# error_print(s0)
ans = 0
s0_top = None
if S[0] == '0':
s0_top = s0.pop(0)
ans = s0_top + sum(s1[:K]) + sum(s0[:K-1])
l1o = 1
l0o = 0
l1 = sum(s1[:K+l1o])
l0 = sum(s0[:K+l0o])
k = 0
while True:
tmp = l1 + l0
# if k == 0 and S[0] == '0':
# tmp -= s1[K]
ans = max(ans, tmp)
if k+K < len(s1) and k+K < len(s0):
l1 -= s1[k]
if k+K+l1o < len(s1):
l1 += s1[k+K+l1o]
l0 -= s0[k]
if k+K+l0o < len(s0):
l0 += s0[k+K+l0o]
else:
break
k += 1
return ans
def main():
N, K = read_int_n()
S = read_str()
rS = ''.join(['0' if c == '1' else '1' for c in S])
print(max(slv(N, K, S), slv(N, K-1, rS)))
# N = 20
# K = random.randint(1, 10)
# S = ''.join(random.choices('01', k=N))
# rS = ''.join(['0' if c == '1' else '1' for c in S])
# print(max(slv(N, K, S), slv(N, K-1, rS)))
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, K, S):
s1 = list(map(lambda x: len(x), filter(lambda x: x != '', S.split('0'))))
s0 = list(map(lambda x: len(x), filter(lambda x: x != '', S.split('1'))))
if len(s0) <= K:
return N
if S[0] == '0':
s1.insert(0, 0)
if S[-1] == '0':
s1.append(0)
s = []
i = 0
for i in range(len(s0)):
s.append(s1[i])
s.append(s0[i])
s.extend(s1[i+1:])
sa = [0]
for v in s:
sa.append(sa[-1]+v)
ans = 0
for i in range(0, len(sa), 2):
if i+2*K+1 < len(sa):
ans = max(ans, sa[i+2*K+1]-sa[i])
elif i+2*K < len(sa):
ans = max(ans, sa[i+2*K]-sa[i])
else:
break
return ans
def main():
N, K = read_int_n()
S = read_str()
rS = ''.join(['0' if c == '1' else '1' for c in S])
print(max(slv(N, K, S), slv(N, K-1, rS)))
# N = 20
# K = random.randint(1, 10)
# S = ''.join(random.choices('01', k=N))
# rS = ''.join(['0' if c == '1' else '1' for c in S])
# print(max(slv(N, K, S), slv(N, K-1, rS)))
if __name__ == '__main__':
main()
| 116 | 105 | 2,460 | 2,235 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
@mt
def slv(N, K, S):
s1 = list(map(lambda x: len(x), filter(lambda x: x != "", S.split("0"))))
s0 = list(map(lambda x: len(x), filter(lambda x: x != "", S.split("1"))))
if len(s0) <= K:
return N
# error_print(N, K)
# error_print(S)
# error_print(s1)
# error_print(s0)
ans = 0
s0_top = None
if S[0] == "0":
s0_top = s0.pop(0)
ans = s0_top + sum(s1[:K]) + sum(s0[: K - 1])
l1o = 1
l0o = 0
l1 = sum(s1[: K + l1o])
l0 = sum(s0[: K + l0o])
k = 0
while True:
tmp = l1 + l0
# if k == 0 and S[0] == '0':
# tmp -= s1[K]
ans = max(ans, tmp)
if k + K < len(s1) and k + K < len(s0):
l1 -= s1[k]
if k + K + l1o < len(s1):
l1 += s1[k + K + l1o]
l0 -= s0[k]
if k + K + l0o < len(s0):
l0 += s0[k + K + l0o]
else:
break
k += 1
return ans
def main():
N, K = read_int_n()
S = read_str()
rS = "".join(["0" if c == "1" else "1" for c in S])
print(max(slv(N, K, S), slv(N, K - 1, rS)))
# N = 20
# K = random.randint(1, 10)
# S = ''.join(random.choices('01', k=N))
# rS = ''.join(['0' if c == '1' else '1' for c in S])
# print(max(slv(N, K, S), slv(N, K-1, rS)))
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
@mt
def slv(N, K, S):
s1 = list(map(lambda x: len(x), filter(lambda x: x != "", S.split("0"))))
s0 = list(map(lambda x: len(x), filter(lambda x: x != "", S.split("1"))))
if len(s0) <= K:
return N
if S[0] == "0":
s1.insert(0, 0)
if S[-1] == "0":
s1.append(0)
s = []
i = 0
for i in range(len(s0)):
s.append(s1[i])
s.append(s0[i])
s.extend(s1[i + 1 :])
sa = [0]
for v in s:
sa.append(sa[-1] + v)
ans = 0
for i in range(0, len(sa), 2):
if i + 2 * K + 1 < len(sa):
ans = max(ans, sa[i + 2 * K + 1] - sa[i])
elif i + 2 * K < len(sa):
ans = max(ans, sa[i + 2 * K] - sa[i])
else:
break
return ans
def main():
N, K = read_int_n()
S = read_str()
rS = "".join(["0" if c == "1" else "1" for c in S])
print(max(slv(N, K, S), slv(N, K - 1, rS)))
# N = 20
# K = random.randint(1, 10)
# S = ''.join(random.choices('01', k=N))
# rS = ''.join(['0' if c == '1' else '1' for c in S])
# print(max(slv(N, K, S), slv(N, K-1, rS)))
if __name__ == "__main__":
main()
| false | 9.482759 | [
"- # error_print(N, K)",
"- # error_print(S)",
"- # error_print(s1)",
"- # error_print(s0)",
"+ if S[0] == \"0\":",
"+ s1.insert(0, 0)",
"+ if S[-1] == \"0\":",
"+ s1.append(0)",
"+ s = []",
"+ i = 0",
"+ for i in range(len(s0)):",
"+ s.append(s1[i])",
"+ s.append(s0[i])",
"+ s.extend(s1[i + 1 :])",
"+ sa = [0]",
"+ for v in s:",
"+ sa.append(sa[-1] + v)",
"- s0_top = None",
"- if S[0] == \"0\":",
"- s0_top = s0.pop(0)",
"- ans = s0_top + sum(s1[:K]) + sum(s0[: K - 1])",
"- l1o = 1",
"- l0o = 0",
"- l1 = sum(s1[: K + l1o])",
"- l0 = sum(s0[: K + l0o])",
"- k = 0",
"- while True:",
"- tmp = l1 + l0",
"- # if k == 0 and S[0] == '0':",
"- # tmp -= s1[K]",
"- ans = max(ans, tmp)",
"- if k + K < len(s1) and k + K < len(s0):",
"- l1 -= s1[k]",
"- if k + K + l1o < len(s1):",
"- l1 += s1[k + K + l1o]",
"- l0 -= s0[k]",
"- if k + K + l0o < len(s0):",
"- l0 += s0[k + K + l0o]",
"+ for i in range(0, len(sa), 2):",
"+ if i + 2 * K + 1 < len(sa):",
"+ ans = max(ans, sa[i + 2 * K + 1] - sa[i])",
"+ elif i + 2 * K < len(sa):",
"+ ans = max(ans, sa[i + 2 * K] - sa[i])",
"- k += 1"
] | false | 0.037286 | 0.036403 | 1.024238 | [
"s702174395",
"s358128040"
] |
u966648240 | p02536 | python | s661425451 | s109602810 | 295 | 218 | 12,940 | 77,580 | Accepted | Accepted | 26.1 | N,M=list(map(int,input().split()))
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf=UnionFind(N+1)
for i in range(M):
a,b=list(map(int, input().split()))
uf.union(a,b)
print((uf.group_count()-2)) | import sys
def input():
return sys.stdin.readline()[:-1]
N,M=list(map(int,input().split()))
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf=UnionFind(N+1)
for i in range(M):
a,b=list(map(int, input().split()))
uf.union(a,b)
print((uf.group_count()-2)) | 56 | 60 | 1,346 | 1,412 | N, M = list(map(int, input().split()))
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
uf = UnionFind(N + 1)
for i in range(M):
a, b = list(map(int, input().split()))
uf.union(a, b)
print((uf.group_count() - 2))
| import sys
def input():
return sys.stdin.readline()[:-1]
N, M = list(map(int, input().split()))
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
uf = UnionFind(N + 1)
for i in range(M):
a, b = list(map(int, input().split()))
uf.union(a, b)
print((uf.group_count() - 2))
| false | 6.666667 | [
"+import sys",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline()[:-1]",
"+",
"+"
] | false | 0.047196 | 0.038354 | 1.230549 | [
"s661425451",
"s109602810"
] |
u497046426 | p02617 | python | s719360174 | s573139761 | 723 | 535 | 35,664 | 36,048 | Accepted | Accepted | 26 | N = int(eval(input()))
E = [[] for _ in range(N)]
for _ in range(N - 1):
u, v = sorted(list(map(int, input().split())))
E[v-1].append(u-1)
ans = 0
for u, adj in enumerate(E):
ans += (u + 1) * (u + 2) // 2
if not adj: continue
adj = sorted(adj, reverse=True)
for v in adj:
ans -= (N - u) * (v + 1)
print(ans) | N = int(eval(input()))
E = []
for _ in range(N - 1):
u, v = sorted(list(map(int, input().split())))
E.append((u, v))
ans = 0
for v in range(1, N+1):
ans += (N - v + 1) * v
for u, v in E:
ans -= (N - v + 1) * u
print(ans) | 13 | 11 | 345 | 240 | N = int(eval(input()))
E = [[] for _ in range(N)]
for _ in range(N - 1):
u, v = sorted(list(map(int, input().split())))
E[v - 1].append(u - 1)
ans = 0
for u, adj in enumerate(E):
ans += (u + 1) * (u + 2) // 2
if not adj:
continue
adj = sorted(adj, reverse=True)
for v in adj:
ans -= (N - u) * (v + 1)
print(ans)
| N = int(eval(input()))
E = []
for _ in range(N - 1):
u, v = sorted(list(map(int, input().split())))
E.append((u, v))
ans = 0
for v in range(1, N + 1):
ans += (N - v + 1) * v
for u, v in E:
ans -= (N - v + 1) * u
print(ans)
| false | 15.384615 | [
"-E = [[] for _ in range(N)]",
"+E = []",
"- E[v - 1].append(u - 1)",
"+ E.append((u, v))",
"-for u, adj in enumerate(E):",
"- ans += (u + 1) * (u + 2) // 2",
"- if not adj:",
"- continue",
"- adj = sorted(adj, reverse=True)",
"- for v in adj:",
"- ans -= (N - u) * (v + 1)",
"+for v in range(1, N + 1):",
"+ ans += (N - v + 1) * v",
"+for u, v in E:",
"+ ans -= (N - v + 1) * u"
] | false | 0.040725 | 0.039915 | 1.020277 | [
"s719360174",
"s573139761"
] |
u561231954 | p03157 | python | s684513308 | s543019734 | 639 | 570 | 12,136 | 74,144 | Accepted | Accepted | 10.8 | dy = (-1,0,1,0)
dx = (0,1,0,-1)
h,w = list(map(int,input().split()))
grid = [eval(input()) for _ in range(h)]
ans = 0
dist = [[-1] * w for _ in range(h)]
for i in range(h):
for j in range(w):
if dist[i][j] < 0:
odd = 0
even = 1
dist[i][j] = 0
stack = [(i,j)]
while stack:
a,b = stack.pop()
if grid[a][b] == '#':
for k in range(4):
y = a + dy[k]
x = b + dx[k]
if y < 0 or y >= h:
continue
if x < 0 or x >= w:
continue
if grid[y][x] == '.' and dist[y][x] < 0:
if dist[a][b] == 0:
dist[y][x] = 1
odd += 1
else:
dist[y][x] = 0
even += 1
stack.append((y,x))
else:
for k in range(4):
y = a + dy[k]
x = b + dx[k]
if y < 0 or y >= h:
continue
if x < 0 or x >= w:
continue
if grid[y][x] == '#' and dist[y][x] < 0:
if dist[a][b] == 0:
dist[y][x] = 1
odd += 1
else:
dist[y][x] = 0
even += 1
stack.append((y,x))
ans += even * odd
print(ans) | import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
Dy = (-1,0,1,0)
Dx = (0,1,0,-1)
def main():
H,W = list(map(int,input().split()))
grid = [eval(input()) for _ in range(H)]
grid = [[1 if g == '#' else 0 for g in gr] for gr in grid]
G = [[] for _ in range(H*W)]
for i in range(H):
for j in range(W):
for dy,dx in zip(Dy,Dx):
y = i + dy
x = j + dx
if y < 0 or y >= H or x < 0 or x >= W:
continue
if grid[i][j]^grid[y][x] == 1:
G[i*W + j].append(y*W + x)
G[y*W + x].append(i*W + j)
visited = [-1] * (H*W)
ans = 0
for i in range(W*H):
if visited[i] >= 0:
continue
stack = [i]
visited[i] = 0
w = 1
b = 0
while stack:
v = stack.pop()
for e in G[v]:
if visited[e] >= 0:
continue
visited[e] = visited[v]^1
if visited[e] == 1:
b += 1
else:
w += 1
stack.append(e)
ans += b*w
print(ans)
if __name__ == '__main__':
main() | 51 | 47 | 1,820 | 1,290 | dy = (-1, 0, 1, 0)
dx = (0, 1, 0, -1)
h, w = list(map(int, input().split()))
grid = [eval(input()) for _ in range(h)]
ans = 0
dist = [[-1] * w for _ in range(h)]
for i in range(h):
for j in range(w):
if dist[i][j] < 0:
odd = 0
even = 1
dist[i][j] = 0
stack = [(i, j)]
while stack:
a, b = stack.pop()
if grid[a][b] == "#":
for k in range(4):
y = a + dy[k]
x = b + dx[k]
if y < 0 or y >= h:
continue
if x < 0 or x >= w:
continue
if grid[y][x] == "." and dist[y][x] < 0:
if dist[a][b] == 0:
dist[y][x] = 1
odd += 1
else:
dist[y][x] = 0
even += 1
stack.append((y, x))
else:
for k in range(4):
y = a + dy[k]
x = b + dx[k]
if y < 0 or y >= h:
continue
if x < 0 or x >= w:
continue
if grid[y][x] == "#" and dist[y][x] < 0:
if dist[a][b] == 0:
dist[y][x] = 1
odd += 1
else:
dist[y][x] = 0
even += 1
stack.append((y, x))
ans += even * odd
print(ans)
| import sys
sys.setrecursionlimit(10000000)
MOD = 10**9 + 7
INF = 10**15
Dy = (-1, 0, 1, 0)
Dx = (0, 1, 0, -1)
def main():
H, W = list(map(int, input().split()))
grid = [eval(input()) for _ in range(H)]
grid = [[1 if g == "#" else 0 for g in gr] for gr in grid]
G = [[] for _ in range(H * W)]
for i in range(H):
for j in range(W):
for dy, dx in zip(Dy, Dx):
y = i + dy
x = j + dx
if y < 0 or y >= H or x < 0 or x >= W:
continue
if grid[i][j] ^ grid[y][x] == 1:
G[i * W + j].append(y * W + x)
G[y * W + x].append(i * W + j)
visited = [-1] * (H * W)
ans = 0
for i in range(W * H):
if visited[i] >= 0:
continue
stack = [i]
visited[i] = 0
w = 1
b = 0
while stack:
v = stack.pop()
for e in G[v]:
if visited[e] >= 0:
continue
visited[e] = visited[v] ^ 1
if visited[e] == 1:
b += 1
else:
w += 1
stack.append(e)
ans += b * w
print(ans)
if __name__ == "__main__":
main()
| false | 7.843137 | [
"-dy = (-1, 0, 1, 0)",
"-dx = (0, 1, 0, -1)",
"-h, w = list(map(int, input().split()))",
"-grid = [eval(input()) for _ in range(h)]",
"-ans = 0",
"-dist = [[-1] * w for _ in range(h)]",
"-for i in range(h):",
"- for j in range(w):",
"- if dist[i][j] < 0:",
"- odd = 0",
"- even = 1",
"- dist[i][j] = 0",
"- stack = [(i, j)]",
"- while stack:",
"- a, b = stack.pop()",
"- if grid[a][b] == \"#\":",
"- for k in range(4):",
"- y = a + dy[k]",
"- x = b + dx[k]",
"- if y < 0 or y >= h:",
"- continue",
"- if x < 0 or x >= w:",
"- continue",
"- if grid[y][x] == \".\" and dist[y][x] < 0:",
"- if dist[a][b] == 0:",
"- dist[y][x] = 1",
"- odd += 1",
"- else:",
"- dist[y][x] = 0",
"- even += 1",
"- stack.append((y, x))",
"+import sys",
"+",
"+sys.setrecursionlimit(10000000)",
"+MOD = 10**9 + 7",
"+INF = 10**15",
"+Dy = (-1, 0, 1, 0)",
"+Dx = (0, 1, 0, -1)",
"+",
"+",
"+def main():",
"+ H, W = list(map(int, input().split()))",
"+ grid = [eval(input()) for _ in range(H)]",
"+ grid = [[1 if g == \"#\" else 0 for g in gr] for gr in grid]",
"+ G = [[] for _ in range(H * W)]",
"+ for i in range(H):",
"+ for j in range(W):",
"+ for dy, dx in zip(Dy, Dx):",
"+ y = i + dy",
"+ x = j + dx",
"+ if y < 0 or y >= H or x < 0 or x >= W:",
"+ continue",
"+ if grid[i][j] ^ grid[y][x] == 1:",
"+ G[i * W + j].append(y * W + x)",
"+ G[y * W + x].append(i * W + j)",
"+ visited = [-1] * (H * W)",
"+ ans = 0",
"+ for i in range(W * H):",
"+ if visited[i] >= 0:",
"+ continue",
"+ stack = [i]",
"+ visited[i] = 0",
"+ w = 1",
"+ b = 0",
"+ while stack:",
"+ v = stack.pop()",
"+ for e in G[v]:",
"+ if visited[e] >= 0:",
"+ continue",
"+ visited[e] = visited[v] ^ 1",
"+ if visited[e] == 1:",
"+ b += 1",
"- for k in range(4):",
"- y = a + dy[k]",
"- x = b + dx[k]",
"- if y < 0 or y >= h:",
"- continue",
"- if x < 0 or x >= w:",
"- continue",
"- if grid[y][x] == \"#\" and dist[y][x] < 0:",
"- if dist[a][b] == 0:",
"- dist[y][x] = 1",
"- odd += 1",
"- else:",
"- dist[y][x] = 0",
"- even += 1",
"- stack.append((y, x))",
"- ans += even * odd",
"-print(ans)",
"+ w += 1",
"+ stack.append(e)",
"+ ans += b * w",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.045506 | 0.037163 | 1.224519 | [
"s684513308",
"s543019734"
] |
u111365362 | p03073 | python | s392765258 | s288303741 | 74 | 67 | 3,188 | 3,188 | Accepted | Accepted | 9.46 | s = eval(input())
n = len(s)
z0 = 0
z1 = 0
for i in range(n):
if int(s[i]) ^ (i%2) == 0:
z0 += 1
else:
z1 += 1
print((min(z0,z1))) | #14:35
s = eval(input())
n = len(s)
scr = 0
for i in range(n):
a = int(s[i])
if i == 0:
b = 0
else:
b = 1 - b
if a != b:
scr += 1
#print(scr)
print((min(scr,n-scr))) | 10 | 14 | 143 | 190 | s = eval(input())
n = len(s)
z0 = 0
z1 = 0
for i in range(n):
if int(s[i]) ^ (i % 2) == 0:
z0 += 1
else:
z1 += 1
print((min(z0, z1)))
| # 14:35
s = eval(input())
n = len(s)
scr = 0
for i in range(n):
a = int(s[i])
if i == 0:
b = 0
else:
b = 1 - b
if a != b:
scr += 1
# print(scr)
print((min(scr, n - scr)))
| false | 28.571429 | [
"+# 14:35",
"-z0 = 0",
"-z1 = 0",
"+scr = 0",
"- if int(s[i]) ^ (i % 2) == 0:",
"- z0 += 1",
"+ a = int(s[i])",
"+ if i == 0:",
"+ b = 0",
"- z1 += 1",
"-print((min(z0, z1)))",
"+ b = 1 - b",
"+ if a != b:",
"+ scr += 1",
"+# print(scr)",
"+print((min(scr, n - scr)))"
] | false | 0.044899 | 0.044021 | 1.019949 | [
"s392765258",
"s288303741"
] |
u033287260 | p02693 | python | s155100949 | s503820871 | 22 | 20 | 9,188 | 9,000 | Accepted | Accepted | 9.09 | K = int(eval(input()))
tmp = eval(input())
tmp = str.split(tmp,' ')
A = int(tmp[0])
B = int(tmp[1])
flag = 0
for i in list(range(A,B+1)):
if(i%K == 0):
flag = 1
break;
if(flag == 1):
print("OK")
else:
print("NG")
| K = int(eval(input()))
A,B = input().split()
A = int(A)
B = int(B)
largest = (B//K) * K
if A <= largest:
print("OK")
else:
print("NG") | 15 | 10 | 244 | 146 | K = int(eval(input()))
tmp = eval(input())
tmp = str.split(tmp, " ")
A = int(tmp[0])
B = int(tmp[1])
flag = 0
for i in list(range(A, B + 1)):
if i % K == 0:
flag = 1
break
if flag == 1:
print("OK")
else:
print("NG")
| K = int(eval(input()))
A, B = input().split()
A = int(A)
B = int(B)
largest = (B // K) * K
if A <= largest:
print("OK")
else:
print("NG")
| false | 33.333333 | [
"-tmp = eval(input())",
"-tmp = str.split(tmp, \" \")",
"-A = int(tmp[0])",
"-B = int(tmp[1])",
"-flag = 0",
"-for i in list(range(A, B + 1)):",
"- if i % K == 0:",
"- flag = 1",
"- break",
"-if flag == 1:",
"+A, B = input().split()",
"+A = int(A)",
"+B = int(B)",
"+largest = (B // K) * K",
"+if A <= largest:"
] | false | 0.036796 | 0.0372 | 0.989136 | [
"s155100949",
"s503820871"
] |
u945181840 | p03837 | python | s865482654 | s187462530 | 535 | 321 | 26,568 | 22,880 | Accepted | Accepted | 40 | import sys
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
read = sys.stdin.read
N, M, *abc = list(map(int, read().split()))
a, b, c = list(zip(*list(zip(*[iter(abc)] * 3))))
graph = csr_matrix((c, (a, b)), shape=(N + 1, N + 1))
distance = dijkstra(graph, directed=False)
answer = 0
for i, j, k in zip(a, b, c):
k = float(k)
if k == distance[i][j]:
continue
for s in range(1, N + 1):
if i == s or j == s:
continue
if k + distance[j][s] == distance[i][s]:
break
if k + distance[i][s] == distance[j][s]:
break
else:
answer += 1
print(answer) | import sys
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
read = sys.stdin.read
N, M, *abc = list(map(int, read().split()))
a, b, c = list(zip(*list(zip(*[iter(abc)] * 3))))
graph = csr_matrix((c, (a, b)), shape=(N + 1, N + 1))
distance = dijkstra(graph, directed=False)
answer = 0
for i, j, k in zip(a, b, c):
k = float(k)
if k != distance[i][j]:
answer += 1
print(answer) | 32 | 19 | 683 | 425 | import sys
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
read = sys.stdin.read
N, M, *abc = list(map(int, read().split()))
a, b, c = list(zip(*list(zip(*[iter(abc)] * 3))))
graph = csr_matrix((c, (a, b)), shape=(N + 1, N + 1))
distance = dijkstra(graph, directed=False)
answer = 0
for i, j, k in zip(a, b, c):
k = float(k)
if k == distance[i][j]:
continue
for s in range(1, N + 1):
if i == s or j == s:
continue
if k + distance[j][s] == distance[i][s]:
break
if k + distance[i][s] == distance[j][s]:
break
else:
answer += 1
print(answer)
| import sys
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
read = sys.stdin.read
N, M, *abc = list(map(int, read().split()))
a, b, c = list(zip(*list(zip(*[iter(abc)] * 3))))
graph = csr_matrix((c, (a, b)), shape=(N + 1, N + 1))
distance = dijkstra(graph, directed=False)
answer = 0
for i, j, k in zip(a, b, c):
k = float(k)
if k != distance[i][j]:
answer += 1
print(answer)
| false | 40.625 | [
"- if k == distance[i][j]:",
"- continue",
"- for s in range(1, N + 1):",
"- if i == s or j == s:",
"- continue",
"- if k + distance[j][s] == distance[i][s]:",
"- break",
"- if k + distance[i][s] == distance[j][s]:",
"- break",
"- else:",
"+ if k != distance[i][j]:"
] | false | 0.350224 | 0.543306 | 0.644616 | [
"s865482654",
"s187462530"
] |
u626337957 | p03078 | python | s650013798 | s083322876 | 970 | 36 | 151,644 | 4,780 | Accepted | Accepted | 96.29 | X, Y, Z, K = list(map(int, input().split()))
a_cakes = list(map(int, input().split()))
b_cakes = list(map(int, input().split()))
c_cakes = list(map(int, input().split()))
a_b_cakes = []
for a in a_cakes:
for b in b_cakes:
a_b_cakes.append(a+b)
a_b_cakes.sort(reverse=True)
a_b_c_cakes = []
for a_b in a_b_cakes[:K]:
for c in c_cakes:
a_b_c_cakes.append(a_b+c)
a_b_c_cakes.sort(reverse=True)
for ans in a_b_c_cakes[:K]:
print(ans)
| from heapq import heappush, heappop
X,Y,Z,K = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
a_list.sort(reverse=True)
b_list.sort(reverse=True)
c_list.sort(reverse=True)
hp = []
checked_dict = {}
max_abc = a_list[0] + b_list[0] + c_list[0]
heappush(hp, (-max_abc,0,0,0))
for _ in range(K):
ans, ai, bi, ci = heappop(hp)
print((-ans))
if ai < X-1 and not (ai+1, bi, ci) in checked_dict:
checked_dict[(ai+1,bi,ci)] = 1
heappush(hp, (-(a_list[ai+1]+b_list[bi]+c_list[ci]),ai+1,bi,ci))
if bi < Y-1 and not (ai,bi+1,ci) in checked_dict:
checked_dict[(ai,bi+1,ci)] = 1
heappush(hp, (-(a_list[ai]+b_list[bi+1]+c_list[ci]),ai,bi+1,ci))
if ci < Z-1 and not (ai,bi,ci+1) in checked_dict:
checked_dict[(ai,bi,ci+1)] = 1
heappush(hp, (-(a_list[ai]+b_list[bi]+c_list[ci+1]),ai,bi,ci+1))
| 16 | 27 | 453 | 951 | X, Y, Z, K = list(map(int, input().split()))
a_cakes = list(map(int, input().split()))
b_cakes = list(map(int, input().split()))
c_cakes = list(map(int, input().split()))
a_b_cakes = []
for a in a_cakes:
for b in b_cakes:
a_b_cakes.append(a + b)
a_b_cakes.sort(reverse=True)
a_b_c_cakes = []
for a_b in a_b_cakes[:K]:
for c in c_cakes:
a_b_c_cakes.append(a_b + c)
a_b_c_cakes.sort(reverse=True)
for ans in a_b_c_cakes[:K]:
print(ans)
| from heapq import heappush, heappop
X, Y, Z, K = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
a_list.sort(reverse=True)
b_list.sort(reverse=True)
c_list.sort(reverse=True)
hp = []
checked_dict = {}
max_abc = a_list[0] + b_list[0] + c_list[0]
heappush(hp, (-max_abc, 0, 0, 0))
for _ in range(K):
ans, ai, bi, ci = heappop(hp)
print((-ans))
if ai < X - 1 and not (ai + 1, bi, ci) in checked_dict:
checked_dict[(ai + 1, bi, ci)] = 1
heappush(hp, (-(a_list[ai + 1] + b_list[bi] + c_list[ci]), ai + 1, bi, ci))
if bi < Y - 1 and not (ai, bi + 1, ci) in checked_dict:
checked_dict[(ai, bi + 1, ci)] = 1
heappush(hp, (-(a_list[ai] + b_list[bi + 1] + c_list[ci]), ai, bi + 1, ci))
if ci < Z - 1 and not (ai, bi, ci + 1) in checked_dict:
checked_dict[(ai, bi, ci + 1)] = 1
heappush(hp, (-(a_list[ai] + b_list[bi] + c_list[ci + 1]), ai, bi, ci + 1))
| false | 40.740741 | [
"+from heapq import heappush, heappop",
"+",
"-a_cakes = list(map(int, input().split()))",
"-b_cakes = list(map(int, input().split()))",
"-c_cakes = list(map(int, input().split()))",
"-a_b_cakes = []",
"-for a in a_cakes:",
"- for b in b_cakes:",
"- a_b_cakes.append(a + b)",
"-a_b_cakes.sort(reverse=True)",
"-a_b_c_cakes = []",
"-for a_b in a_b_cakes[:K]:",
"- for c in c_cakes:",
"- a_b_c_cakes.append(a_b + c)",
"-a_b_c_cakes.sort(reverse=True)",
"-for ans in a_b_c_cakes[:K]:",
"- print(ans)",
"+a_list = list(map(int, input().split()))",
"+b_list = list(map(int, input().split()))",
"+c_list = list(map(int, input().split()))",
"+a_list.sort(reverse=True)",
"+b_list.sort(reverse=True)",
"+c_list.sort(reverse=True)",
"+hp = []",
"+checked_dict = {}",
"+max_abc = a_list[0] + b_list[0] + c_list[0]",
"+heappush(hp, (-max_abc, 0, 0, 0))",
"+for _ in range(K):",
"+ ans, ai, bi, ci = heappop(hp)",
"+ print((-ans))",
"+ if ai < X - 1 and not (ai + 1, bi, ci) in checked_dict:",
"+ checked_dict[(ai + 1, bi, ci)] = 1",
"+ heappush(hp, (-(a_list[ai + 1] + b_list[bi] + c_list[ci]), ai + 1, bi, ci))",
"+ if bi < Y - 1 and not (ai, bi + 1, ci) in checked_dict:",
"+ checked_dict[(ai, bi + 1, ci)] = 1",
"+ heappush(hp, (-(a_list[ai] + b_list[bi + 1] + c_list[ci]), ai, bi + 1, ci))",
"+ if ci < Z - 1 and not (ai, bi, ci + 1) in checked_dict:",
"+ checked_dict[(ai, bi, ci + 1)] = 1",
"+ heappush(hp, (-(a_list[ai] + b_list[bi] + c_list[ci + 1]), ai, bi, ci + 1))"
] | false | 0.076086 | 0.03591 | 2.118823 | [
"s650013798",
"s083322876"
] |
u163320134 | p02813 | python | s999307586 | s206406512 | 34 | 17 | 8,052 | 3,064 | Accepted | Accepted | 50 | import itertools
n=int(eval(input()))
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
arrs=list(itertools.permutations(list(range(1,n+1))))
cnt1=0
cnt2=0
for i in range(len(arrs)):
if arrs[i]==p:
cnt1=i
if arrs[i]==q:
cnt2=i
print((abs(cnt2-cnt1))) | def fact(n):
ret=1
for i in range(2,n+1):
ret=ret*i
return ret
n=int(eval(input()))
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
cnt1=0
cnt2=0
checked1=[0]*(n+1)
checked2=[0]*(n+1)
for i in range(n):
checked1[arr1[i]]=1
checked2[arr2[i]]=1
cnt1+=(arr1[i]-1-sum(checked1[:arr1[i]]))*fact(n-i-1)
cnt2+=(arr2[i]-1-sum(checked2[:arr2[i]]))*fact(n-i-1)
print((abs(cnt1-cnt2))) | 13 | 19 | 278 | 427 | import itertools
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
arrs = list(itertools.permutations(list(range(1, n + 1))))
cnt1 = 0
cnt2 = 0
for i in range(len(arrs)):
if arrs[i] == p:
cnt1 = i
if arrs[i] == q:
cnt2 = i
print((abs(cnt2 - cnt1)))
| def fact(n):
ret = 1
for i in range(2, n + 1):
ret = ret * i
return ret
n = int(eval(input()))
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
cnt1 = 0
cnt2 = 0
checked1 = [0] * (n + 1)
checked2 = [0] * (n + 1)
for i in range(n):
checked1[arr1[i]] = 1
checked2[arr2[i]] = 1
cnt1 += (arr1[i] - 1 - sum(checked1[: arr1[i]])) * fact(n - i - 1)
cnt2 += (arr2[i] - 1 - sum(checked2[: arr2[i]])) * fact(n - i - 1)
print((abs(cnt1 - cnt2)))
| false | 31.578947 | [
"-import itertools",
"+def fact(n):",
"+ ret = 1",
"+ for i in range(2, n + 1):",
"+ ret = ret * i",
"+ return ret",
"+",
"-p = tuple(map(int, input().split()))",
"-q = tuple(map(int, input().split()))",
"-arrs = list(itertools.permutations(list(range(1, n + 1))))",
"+arr1 = list(map(int, input().split()))",
"+arr2 = list(map(int, input().split()))",
"-for i in range(len(arrs)):",
"- if arrs[i] == p:",
"- cnt1 = i",
"- if arrs[i] == q:",
"- cnt2 = i",
"-print((abs(cnt2 - cnt1)))",
"+checked1 = [0] * (n + 1)",
"+checked2 = [0] * (n + 1)",
"+for i in range(n):",
"+ checked1[arr1[i]] = 1",
"+ checked2[arr2[i]] = 1",
"+ cnt1 += (arr1[i] - 1 - sum(checked1[: arr1[i]])) * fact(n - i - 1)",
"+ cnt2 += (arr2[i] - 1 - sum(checked2[: arr2[i]])) * fact(n - i - 1)",
"+print((abs(cnt1 - cnt2)))"
] | false | 0.040413 | 0.042133 | 0.959172 | [
"s999307586",
"s206406512"
] |
u294922877 | p02392 | python | s986743022 | s162722925 | 50 | 20 | 7,680 | 5,592 | Accepted | Accepted | 60 | a,b,c = list(map(int, input().split()))
if (a<b<c):
print('Yes')
else:
print('No') | def judge(a, b, c):
return 'Yes' if a < b < c else 'No'
if __name__ == '__main__':
a, b, c = list(map(int, input().split(' ')))
print((judge(a, b, c)))
| 5 | 7 | 84 | 164 | a, b, c = list(map(int, input().split()))
if a < b < c:
print("Yes")
else:
print("No")
| def judge(a, b, c):
return "Yes" if a < b < c else "No"
if __name__ == "__main__":
a, b, c = list(map(int, input().split(" ")))
print((judge(a, b, c)))
| false | 28.571429 | [
"-a, b, c = list(map(int, input().split()))",
"-if a < b < c:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+def judge(a, b, c):",
"+ return \"Yes\" if a < b < c else \"No\"",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ a, b, c = list(map(int, input().split(\" \")))",
"+ print((judge(a, b, c)))"
] | false | 0.046388 | 0.085414 | 0.54309 | [
"s986743022",
"s162722925"
] |
u542932305 | p03043 | python | s146571149 | s303084058 | 66 | 40 | 3,060 | 2,940 | Accepted | Accepted | 39.39 | N, K = list(map(int, input().split()))
result = 0
for i in range(1, N+1):
prob = 1
x = i
for j in range(i, K):
if K <= x:
break
prob *= 0.5
x *= 2
result += prob/N
print(('{0:.12f}'.format(result))) | N, K = list(map(int, input().split()))
result = 0
for x in range(1, N+1):
prob = 1
while x < K:
prob *= 0.5
x *= 2
result += prob/N
print(('{0:.9f}'.format(result))) | 14 | 11 | 257 | 197 | N, K = list(map(int, input().split()))
result = 0
for i in range(1, N + 1):
prob = 1
x = i
for j in range(i, K):
if K <= x:
break
prob *= 0.5
x *= 2
result += prob / N
print(("{0:.12f}".format(result)))
| N, K = list(map(int, input().split()))
result = 0
for x in range(1, N + 1):
prob = 1
while x < K:
prob *= 0.5
x *= 2
result += prob / N
print(("{0:.9f}".format(result)))
| false | 21.428571 | [
"-for i in range(1, N + 1):",
"+for x in range(1, N + 1):",
"- x = i",
"- for j in range(i, K):",
"- if K <= x:",
"- break",
"+ while x < K:",
"-print((\"{0:.12f}\".format(result)))",
"+print((\"{0:.9f}\".format(result)))"
] | false | 0.095835 | 0.096847 | 0.989545 | [
"s146571149",
"s303084058"
] |
u847467233 | p00616 | python | s580605032 | s640250379 | 280 | 170 | 10,272 | 10,276 | Accepted | Accepted | 39.29 | # AOJ 1030 Cubes Without Holes
# Python3 2018.7.6 bal4u
import sys
from sys import stdin
input = stdin.readline
while True:
n, h = list(map(int, input().split()))
if n == 0: break
ans = []
for i in range(h):
c, a, b = input().split()
a, b = int(a)-1, int(b)-1
if c == "xy":
ans += [a+b*n+z*n**2 for z in range(n)]
elif c == "xz":
ans += [a+y*n+b*n**2 for y in range(n)]
else:
ans += [x+a*n+b*n**2 for x in range(n)]
print((n**3-len(set(ans))))
| # AOJ 1030 Cubes Without Holes
# Python3 2018.7.6 bal4u
import sys
from sys import stdin
input = stdin.readline
# n <= 500, 2^9 = 512
while True:
n, h = list(map(int, input().split()))
if n == 0: break
ans = []
for i in range(h):
c, a, b = input().split()
a, b = int(a)-1, int(b)-1
if c == "xy":
ans += [a+(b<<9)+(z<<18) for z in range(n)]
elif c == "xz":
ans += [a+(y<<9)+(b<<18) for y in range(n)]
else:
ans += [x+(a<<9)+(b<<18) for x in range(n)]
print((n**3-len(set(ans))))
| 21 | 22 | 482 | 518 | # AOJ 1030 Cubes Without Holes
# Python3 2018.7.6 bal4u
import sys
from sys import stdin
input = stdin.readline
while True:
n, h = list(map(int, input().split()))
if n == 0:
break
ans = []
for i in range(h):
c, a, b = input().split()
a, b = int(a) - 1, int(b) - 1
if c == "xy":
ans += [a + b * n + z * n**2 for z in range(n)]
elif c == "xz":
ans += [a + y * n + b * n**2 for y in range(n)]
else:
ans += [x + a * n + b * n**2 for x in range(n)]
print((n**3 - len(set(ans))))
| # AOJ 1030 Cubes Without Holes
# Python3 2018.7.6 bal4u
import sys
from sys import stdin
input = stdin.readline
# n <= 500, 2^9 = 512
while True:
n, h = list(map(int, input().split()))
if n == 0:
break
ans = []
for i in range(h):
c, a, b = input().split()
a, b = int(a) - 1, int(b) - 1
if c == "xy":
ans += [a + (b << 9) + (z << 18) for z in range(n)]
elif c == "xz":
ans += [a + (y << 9) + (b << 18) for y in range(n)]
else:
ans += [x + (a << 9) + (b << 18) for x in range(n)]
print((n**3 - len(set(ans))))
| false | 4.545455 | [
"+# n <= 500, 2^9 = 512",
"- ans += [a + b * n + z * n**2 for z in range(n)]",
"+ ans += [a + (b << 9) + (z << 18) for z in range(n)]",
"- ans += [a + y * n + b * n**2 for y in range(n)]",
"+ ans += [a + (y << 9) + (b << 18) for y in range(n)]",
"- ans += [x + a * n + b * n**2 for x in range(n)]",
"+ ans += [x + (a << 9) + (b << 18) for x in range(n)]"
] | false | 0.158306 | 0.045048 | 3.514154 | [
"s580605032",
"s640250379"
] |
u171276253 | p03494 | python | s373747916 | s998112930 | 19 | 17 | 3,064 | 3,060 | Accepted | Accepted | 10.53 | num = int(eval(input()))
s = input().rstrip().split(' ')
s = [ int(x) for x in s]
count = 0
key = True
while key:
for i in range(num):
if( s[i] % 2 == 0):
s[i] = s[i] // 2
else:
key = False
if key:
count += 1
print(count)
| import math
n = eval(input())
a = list(map(int, input().split()))
ans = float("inf")
for i in a:
ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
print((round(ans))) | 17 | 7 | 291 | 170 | num = int(eval(input()))
s = input().rstrip().split(" ")
s = [int(x) for x in s]
count = 0
key = True
while key:
for i in range(num):
if s[i] % 2 == 0:
s[i] = s[i] // 2
else:
key = False
if key:
count += 1
print(count)
| import math
n = eval(input())
a = list(map(int, input().split()))
ans = float("inf")
for i in a:
ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
print((round(ans)))
| false | 58.823529 | [
"-num = int(eval(input()))",
"-s = input().rstrip().split(\" \")",
"-s = [int(x) for x in s]",
"-count = 0",
"-key = True",
"-while key:",
"- for i in range(num):",
"- if s[i] % 2 == 0:",
"- s[i] = s[i] // 2",
"- else:",
"- key = False",
"- if key:",
"- count += 1",
"-print(count)",
"+import math",
"+",
"+n = eval(input())",
"+a = list(map(int, input().split()))",
"+ans = float(\"inf\")",
"+for i in a:",
"+ ans = min(ans, len(bin(i)) - bin(i).rfind(\"1\") - 1)",
"+print((round(ans)))"
] | false | 0.066336 | 0.050029 | 1.32596 | [
"s373747916",
"s998112930"
] |
u334712262 | p04046 | python | s030789723 | s966300455 | 1,534 | 448 | 126,576 | 29,260 | Accepted | Accepted | 70.8 |
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(10000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
nCr = {}
def C(n, r):
if r == 0 or r == n:
return 1
if r == 1:
return n
if (n, r) in nCr:
return nCr[(n, r)]
nCr[(n, r)] = C(n-1, r) + C(n-1, r-1)
return nCr[(n, r)]
MOD = 10**9+7 # 出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
g1.append((g1[-1] * i) % MOD)
inverse.append((-inverse[MOD % i] * (MOD//i)) % MOD)
g2.append((g2[-1] * inverse[-1]) % MOD)
def cmb(n, r):
if (r < 0 or r > n):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % MOD
@mt
def slv(H, W, A, B):
MOD = 10**9+7
ans = 0
for i in range(W-B):
# print(ans)
w1 = cmb(i+(A-1), i)
w2 = cmb((W-i-1)+(H-A-1), (H-A-1))
ans += w1*w2
ans %= MOD
return ans % MOD
def main():
H, W, A, B = read_int_n()
print(slv(H, W, A, B))
if __name__ == '__main__':
main()
|
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(10000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
class Combination:
def __init__(self, n, mod):
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod//i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
self.MOD = mod
self.N = n
self.g1 = g1
self.g2 = g2
self.inverse = inverse
def __call__(self, n, r):
if (r < 0 or r > n):
return 0
r = min(r, n-r)
return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD
@mt
def slv(H, W, A, B):
MOD = 10**9+7
cmb = Combination(H+W, MOD)
ans = 0
for i in range(W-B):
w1 = cmb(i+(A-1), i)
w2 = cmb((W-i-1)+(H-A-1), (H-A-1))
ans += w1*w2
ans %= MOD
return ans % MOD
def main():
H, W, A, B = read_int_n()
print(slv(H, W, A, B))
if __name__ == '__main__':
main()
| 114 | 104 | 2,088 | 2,078 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(10000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
nCr = {}
def C(n, r):
if r == 0 or r == n:
return 1
if r == 1:
return n
if (n, r) in nCr:
return nCr[(n, r)]
nCr[(n, r)] = C(n - 1, r) + C(n - 1, r - 1)
return nCr[(n, r)]
MOD = 10**9 + 7 # 出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
g1.append((g1[-1] * i) % MOD)
inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
g2.append((g2[-1] * inverse[-1]) % MOD)
def cmb(n, r):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % MOD
@mt
def slv(H, W, A, B):
MOD = 10**9 + 7
ans = 0
for i in range(W - B):
# print(ans)
w1 = cmb(i + (A - 1), i)
w2 = cmb((W - i - 1) + (H - A - 1), (H - A - 1))
ans += w1 * w2
ans %= MOD
return ans % MOD
def main():
H, W, A, B = read_int_n()
print(slv(H, W, A, B))
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(10000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
class Combination:
def __init__(self, n, mod):
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
self.MOD = mod
self.N = n
self.g1 = g1
self.g2 = g2
self.inverse = inverse
def __call__(self, n, r):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD
@mt
def slv(H, W, A, B):
MOD = 10**9 + 7
cmb = Combination(H + W, MOD)
ans = 0
for i in range(W - B):
w1 = cmb(i + (A - 1), i)
w2 = cmb((W - i - 1) + (H - A - 1), (H - A - 1))
ans += w1 * w2
ans %= MOD
return ans % MOD
def main():
H, W, A, B = read_int_n()
print(slv(H, W, A, B))
if __name__ == "__main__":
main()
| false | 8.77193 | [
"-nCr = {}",
"+class Combination:",
"+ def __init__(self, n, mod):",
"+ g1 = [1, 1]",
"+ g2 = [1, 1]",
"+ inverse = [0, 1]",
"+ for i in range(2, n + 1):",
"+ g1.append((g1[-1] * i) % mod)",
"+ inverse.append((-inverse[mod % i] * (mod // i)) % mod)",
"+ g2.append((g2[-1] * inverse[-1]) % mod)",
"+ self.MOD = mod",
"+ self.N = n",
"+ self.g1 = g1",
"+ self.g2 = g2",
"+ self.inverse = inverse",
"-",
"-def C(n, r):",
"- if r == 0 or r == n:",
"- return 1",
"- if r == 1:",
"- return n",
"- if (n, r) in nCr:",
"- return nCr[(n, r)]",
"- nCr[(n, r)] = C(n - 1, r) + C(n - 1, r - 1)",
"- return nCr[(n, r)]",
"-",
"-",
"-MOD = 10**9 + 7 # 出力の制限",
"-N = 10**6",
"-g1 = [1, 1] # 元テーブル",
"-g2 = [1, 1] # 逆元テーブル",
"-inverse = [0, 1] # 逆元テーブル計算用テーブル",
"-for i in range(2, N + 1):",
"- g1.append((g1[-1] * i) % MOD)",
"- inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)",
"- g2.append((g2[-1] * inverse[-1]) % MOD)",
"-",
"-",
"-def cmb(n, r):",
"- if r < 0 or r > n:",
"- return 0",
"- r = min(r, n - r)",
"- return g1[n] * g2[r] * g2[n - r] % MOD",
"+ def __call__(self, n, r):",
"+ if r < 0 or r > n:",
"+ return 0",
"+ r = min(r, n - r)",
"+ return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD",
"+ cmb = Combination(H + W, MOD)",
"- # print(ans)"
] | false | 2.586771 | 0.045782 | 56.501922 | [
"s030789723",
"s966300455"
] |
u619458041 | p03032 | python | s425653743 | s720915560 | 36 | 33 | 3,188 | 3,188 | Accepted | Accepted | 8.33 | import sys
from heapq import heappop, heappush
def main():
input = sys.stdin.readline
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
for left in range(min(N, K) + 1):
for right in range(min(N, K) - left + 1):
heap = []
for v in V[:left]:
heappush(heap, v)
for v in V[N - right:]:
heappush(heap, v)
cnt = left + right
while cnt < K and len(heap) > 0:
v = heappop(heap)
if v > 0:
heappush(heap, v)
break
cnt += 1
ans = max(ans, sum(heap))
return ans
if __name__ == '__main__':
print((main()))
| import sys
from heapq import heappop, heappush
def main():
input = sys.stdin.readline
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
for left in range(min(N, K) + 1):
for right in range(min(N, K) - left + 1):
heap = []
for v in V[:left]:
heappush(heap, v)
for v in V[N - right:]:
heappush(heap, v)
cnt = left + right
while cnt < K and len(heap) > 0:
v = heappop(heap)
if v >= 0:
heappush(heap, v)
break
cnt += 1
ans = max(ans, sum(heap))
return ans
if __name__ == '__main__':
print((main()))
| 34 | 34 | 789 | 790 | import sys
from heapq import heappop, heappush
def main():
input = sys.stdin.readline
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
for left in range(min(N, K) + 1):
for right in range(min(N, K) - left + 1):
heap = []
for v in V[:left]:
heappush(heap, v)
for v in V[N - right :]:
heappush(heap, v)
cnt = left + right
while cnt < K and len(heap) > 0:
v = heappop(heap)
if v > 0:
heappush(heap, v)
break
cnt += 1
ans = max(ans, sum(heap))
return ans
if __name__ == "__main__":
print((main()))
| import sys
from heapq import heappop, heappush
def main():
input = sys.stdin.readline
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
for left in range(min(N, K) + 1):
for right in range(min(N, K) - left + 1):
heap = []
for v in V[:left]:
heappush(heap, v)
for v in V[N - right :]:
heappush(heap, v)
cnt = left + right
while cnt < K and len(heap) > 0:
v = heappop(heap)
if v >= 0:
heappush(heap, v)
break
cnt += 1
ans = max(ans, sum(heap))
return ans
if __name__ == "__main__":
print((main()))
| false | 0 | [
"- if v > 0:",
"+ if v >= 0:"
] | false | 0.043527 | 0.049758 | 0.874759 | [
"s425653743",
"s720915560"
] |
u102461423 | p02702 | python | s270450801 | s740022149 | 1,186 | 858 | 117,692 | 108,872 | Accepted | Accepted | 27.66 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numba import njit
@njit('(i4[:],)')
def solve(S):
dp = np.zeros(2019, np.int64)
pow10 = 1
answer = 0
for x in S[::-1]:
dp[0] += 1
x = x * pow10 % 2019
newdp = np.zeros_like(dp)
newdp[x:] += dp[:-x]
newdp[:x] += dp[-x:]
answer += newdp[0]
pow10 *= 10
pow10 %= 2019
dp = newdp
return answer
S = np.array(list(read().rstrip()), dtype=np.int32) - ord('0')
print((solve(S)))
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numba import njit
@njit('(i4[:],)', cache=True)
def solve(S):
dp = np.zeros(2019, np.int64)
pow10 = 1
answer = 0
for x in S[::-1]:
dp[0] += 1
x = x * pow10 % 2019
newdp = np.zeros_like(dp)
newdp[x:] += dp[:-x]
newdp[:x] += dp[-x:]
answer += newdp[0]
pow10 *= 10
pow10 %= 2019
dp = newdp
return answer
S = np.array(list(read().rstrip()), dtype=np.int32) - ord('0')
print((solve(S)))
| 27 | 27 | 629 | 641 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numba import njit
@njit("(i4[:],)")
def solve(S):
dp = np.zeros(2019, np.int64)
pow10 = 1
answer = 0
for x in S[::-1]:
dp[0] += 1
x = x * pow10 % 2019
newdp = np.zeros_like(dp)
newdp[x:] += dp[:-x]
newdp[:x] += dp[-x:]
answer += newdp[0]
pow10 *= 10
pow10 %= 2019
dp = newdp
return answer
S = np.array(list(read().rstrip()), dtype=np.int32) - ord("0")
print((solve(S)))
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numba import njit
@njit("(i4[:],)", cache=True)
def solve(S):
dp = np.zeros(2019, np.int64)
pow10 = 1
answer = 0
for x in S[::-1]:
dp[0] += 1
x = x * pow10 % 2019
newdp = np.zeros_like(dp)
newdp[x:] += dp[:-x]
newdp[:x] += dp[-x:]
answer += newdp[0]
pow10 *= 10
pow10 %= 2019
dp = newdp
return answer
S = np.array(list(read().rstrip()), dtype=np.int32) - ord("0")
print((solve(S)))
| false | 0 | [
"-@njit(\"(i4[:],)\")",
"+@njit(\"(i4[:],)\", cache=True)"
] | false | 0.191589 | 0.216998 | 0.882908 | [
"s270450801",
"s740022149"
] |
u909643606 | p03716 | python | s090431689 | s940391037 | 501 | 463 | 38,288 | 38,292 | Accepted | Accepted | 7.58 | import heapq
def calc(front_sum, back_sum):
heapq.heapify(a_front)
heapq.heapify(a_back)
front_sums = [front_sum]
back_sums = [back_sum]
for i in range(n):
front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i])
front_sums += [front_sum]
back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1])
back_sums += [back_sum]
return max([front_sums[i] - back_sums[-i-1] for i in range(n+1)])
if __name__ == "__main__":
n = int(eval(input()))
a = [int(i) for i in input().split()]
k = 0
a_front = []
a_center = []
a_back = []
front_sum = 0
back_sum = 0
for i in a:
k += 1
if k <= n:
a_front += [i]
front_sum += i
elif k <= 2 * n:
a_center += [i]
else:
a_back += [-i]
back_sum += i
print((calc(front_sum, back_sum)))
| import heapq
def calc(front_sum, back_sum):
heapq.heapify(a_front)
heapq.heapify(a_back)
front_sums = [front_sum]
back_sums = [back_sum]
for i in a_center:
front_sum += i - heapq.heappushpop(a_front, i)
front_sums += [front_sum]
a_center.reverse()
for i in a_center:
back_sum += i + heapq.heappushpop(a_back, -i)
back_sums += [back_sum]
return max([front_sums[i] - back_sums[-i-1] for i in range(n+1)])
if __name__ == "__main__":
n = int(eval(input()))
a = [int(i) for i in input().split()]
k = 0
a_front = []
a_center = []
a_back = []
front_sum = 0
back_sum = 0
for i in a:
k += 1
if k <= n:
a_front += [i]
front_sum += i
elif k <= 2 * n:
a_center += [i]
else:
a_back += [-i]
back_sum += i
print((calc(front_sum, back_sum)))
| 39 | 41 | 963 | 961 | import heapq
def calc(front_sum, back_sum):
heapq.heapify(a_front)
heapq.heapify(a_back)
front_sums = [front_sum]
back_sums = [back_sum]
for i in range(n):
front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i])
front_sums += [front_sum]
back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1])
back_sums += [back_sum]
return max([front_sums[i] - back_sums[-i - 1] for i in range(n + 1)])
if __name__ == "__main__":
n = int(eval(input()))
a = [int(i) for i in input().split()]
k = 0
a_front = []
a_center = []
a_back = []
front_sum = 0
back_sum = 0
for i in a:
k += 1
if k <= n:
a_front += [i]
front_sum += i
elif k <= 2 * n:
a_center += [i]
else:
a_back += [-i]
back_sum += i
print((calc(front_sum, back_sum)))
| import heapq
def calc(front_sum, back_sum):
heapq.heapify(a_front)
heapq.heapify(a_back)
front_sums = [front_sum]
back_sums = [back_sum]
for i in a_center:
front_sum += i - heapq.heappushpop(a_front, i)
front_sums += [front_sum]
a_center.reverse()
for i in a_center:
back_sum += i + heapq.heappushpop(a_back, -i)
back_sums += [back_sum]
return max([front_sums[i] - back_sums[-i - 1] for i in range(n + 1)])
if __name__ == "__main__":
n = int(eval(input()))
a = [int(i) for i in input().split()]
k = 0
a_front = []
a_center = []
a_back = []
front_sum = 0
back_sum = 0
for i in a:
k += 1
if k <= n:
a_front += [i]
front_sum += i
elif k <= 2 * n:
a_center += [i]
else:
a_back += [-i]
back_sum += i
print((calc(front_sum, back_sum)))
| false | 4.878049 | [
"- for i in range(n):",
"- front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i])",
"+ for i in a_center:",
"+ front_sum += i - heapq.heappushpop(a_front, i)",
"- back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1])",
"+ a_center.reverse()",
"+ for i in a_center:",
"+ back_sum += i + heapq.heappushpop(a_back, -i)"
] | false | 0.040747 | 0.049393 | 0.824951 | [
"s090431689",
"s940391037"
] |
u813098295 | p03658 | python | s973934199 | s314394123 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | n, k = list(map(int, input().split()))
print(( sum(sorted([ int(x) for x in input().split()], reverse = True)[:k]) )) | _, K = list(map(int, input().split()))
L = list(map(int, input().split()))
print((sum(sorted(L, reverse=True)[:K]))) | 2 | 4 | 110 | 112 | n, k = list(map(int, input().split()))
print((sum(sorted([int(x) for x in input().split()], reverse=True)[:k])))
| _, K = list(map(int, input().split()))
L = list(map(int, input().split()))
print((sum(sorted(L, reverse=True)[:K])))
| false | 50 | [
"-n, k = list(map(int, input().split()))",
"-print((sum(sorted([int(x) for x in input().split()], reverse=True)[:k])))",
"+_, K = list(map(int, input().split()))",
"+L = list(map(int, input().split()))",
"+print((sum(sorted(L, reverse=True)[:K])))"
] | false | 0.04721 | 0.047091 | 1.002536 | [
"s973934199",
"s314394123"
] |
u007270338 | p02267 | python | s363355733 | s025589587 | 50 | 20 | 6,552 | 6,556 | Accepted | Accepted | 60 | #coding:utf-8
n = int(eval(input()))
S = list(map(int, input().split()))
q = int(eval(input()))
T = list(map(int, input().split()))
def search_banpei(array, target, cnt):
tmp = array[len(array)-1]
array[len(array)-1] = target
n = 0
while array[n] != target:
n += 1
array[len(array)-1] = tmp
if n < len(array) - 1 or target == tmp:
cnt += 1
return cnt
def linear_search():
cnt = 0
for t in T:
for s in S:
if t == s:
cnt += 1
break
def linear_banpei_search():
cnt = 0
for target in T:
cnt = search_banpei(S, target, cnt)
return cnt
cnt = linear_banpei_search()
print(cnt)
| #coding:utf-8
n = int(eval(input()))
S = list(map(int, input().split()))
q = int(eval(input()))
T = list(map(int, input().split()))
def search_banpei(array, target, cnt):
tmp = array[len(array)-1]
array[len(array)-1] = target
n = 0
while array[n] != target:
n += 1
array[len(array)-1] = tmp
if n < len(array) - 1 or target == tmp:
cnt += 1
return cnt
def linear_search():
cnt = 0
for t in T:
for s in S:
if t == s:
cnt += 1
break
return cnt
def linear_banpei_search():
cnt = 0
for target in T:
cnt = search_banpei(S, target, cnt)
return cnt
cnt = linear_search()
print(cnt)
| 37 | 38 | 736 | 745 | # coding:utf-8
n = int(eval(input()))
S = list(map(int, input().split()))
q = int(eval(input()))
T = list(map(int, input().split()))
def search_banpei(array, target, cnt):
tmp = array[len(array) - 1]
array[len(array) - 1] = target
n = 0
while array[n] != target:
n += 1
array[len(array) - 1] = tmp
if n < len(array) - 1 or target == tmp:
cnt += 1
return cnt
def linear_search():
cnt = 0
for t in T:
for s in S:
if t == s:
cnt += 1
break
def linear_banpei_search():
cnt = 0
for target in T:
cnt = search_banpei(S, target, cnt)
return cnt
cnt = linear_banpei_search()
print(cnt)
| # coding:utf-8
n = int(eval(input()))
S = list(map(int, input().split()))
q = int(eval(input()))
T = list(map(int, input().split()))
def search_banpei(array, target, cnt):
tmp = array[len(array) - 1]
array[len(array) - 1] = target
n = 0
while array[n] != target:
n += 1
array[len(array) - 1] = tmp
if n < len(array) - 1 or target == tmp:
cnt += 1
return cnt
def linear_search():
cnt = 0
for t in T:
for s in S:
if t == s:
cnt += 1
break
return cnt
def linear_banpei_search():
cnt = 0
for target in T:
cnt = search_banpei(S, target, cnt)
return cnt
cnt = linear_search()
print(cnt)
| false | 2.631579 | [
"+ return cnt",
"-cnt = linear_banpei_search()",
"+cnt = linear_search()"
] | false | 0.044986 | 0.084949 | 0.529565 | [
"s363355733",
"s025589587"
] |
u899975427 | p02936 | python | s889419121 | s203662415 | 1,234 | 1,022 | 56,056 | 67,176 | Accepted | Accepted | 17.18 | import sys
from collections import deque
input = sys.stdin.readline
n,q = list(map(int,input().split()))
score = [0]*(n+1)
tree = [[] for i in range(n+1)]
check = [0]*(n+1)
check[1] = 1
for i in range(n-1):
a,b = list(map(int,input().split()))
tree[b] += [a]
tree[a] += [b]
que = deque([1])
qappend = que.append
qpop = que.pop
for i in range(q):
q,x = list(map(int,input().split()))
score[q] += x
while que:
n = qpop()
for i in tree[n]:
if check[i]:continue
check[i] = 1
score[i] += score[n]
qappend(i)
print((*score[1:])) | import sys
from collections import deque
input = sys.stdin.readline
n,q = list(map(int,input().split()))
score = [0]*(n+1)
tree = [[] for i in range(n+1)]
check = [0]*(n+1)
check[1] = 1
for i in range(n-1):
a,b = list(map(int,input().split()))
tree[b] += [a]
tree[a] += [b]
que = deque([1])
qappend = que.append
qpop = que.pop
for i in range(q):
q,x = list(map(int,input().split()))
score[q] += x
while que:
n = qpop()
for i in tree[n]:
if check[i]:continue
check[i] = 1
score[i] += score[n]
qappend(i)
print((" ".join(map(str, score[1:])))) | 32 | 32 | 569 | 588 | import sys
from collections import deque
input = sys.stdin.readline
n, q = list(map(int, input().split()))
score = [0] * (n + 1)
tree = [[] for i in range(n + 1)]
check = [0] * (n + 1)
check[1] = 1
for i in range(n - 1):
a, b = list(map(int, input().split()))
tree[b] += [a]
tree[a] += [b]
que = deque([1])
qappend = que.append
qpop = que.pop
for i in range(q):
q, x = list(map(int, input().split()))
score[q] += x
while que:
n = qpop()
for i in tree[n]:
if check[i]:
continue
check[i] = 1
score[i] += score[n]
qappend(i)
print((*score[1:]))
| import sys
from collections import deque
input = sys.stdin.readline
n, q = list(map(int, input().split()))
score = [0] * (n + 1)
tree = [[] for i in range(n + 1)]
check = [0] * (n + 1)
check[1] = 1
for i in range(n - 1):
a, b = list(map(int, input().split()))
tree[b] += [a]
tree[a] += [b]
que = deque([1])
qappend = que.append
qpop = que.pop
for i in range(q):
q, x = list(map(int, input().split()))
score[q] += x
while que:
n = qpop()
for i in tree[n]:
if check[i]:
continue
check[i] = 1
score[i] += score[n]
qappend(i)
print((" ".join(map(str, score[1:]))))
| false | 0 | [
"-print((*score[1:]))",
"+print((\" \".join(map(str, score[1:]))))"
] | false | 0.07623 | 0.06427 | 1.186102 | [
"s889419121",
"s203662415"
] |
u811733736 | p00436 | python | s535832395 | s216720359 | 80 | 30 | 7,844 | 7,824 | Accepted | Accepted | 62.5 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0513
"""
import sys
from sys import stdin
from itertools import chain
input = stdin.readline
def flatten(listOfLists):
"Flatten one level of nesting"
return chain.from_iterable(listOfLists)
def cut(k):
global cards
yellow = cards[:k]
blue = cards[k:]
cards = blue + yellow
def shuffle():
global cards
yellow = cards[:N]
blue = cards[N:]
temp = [[y, b] for y, b in zip(yellow, blue)]
cards = list(flatten(temp))
cards = []
N = 0
def main(args):
global N
global cards
n = int(eval(input()))
N = n
m = int(eval(input()))
cards = [x for x in range(1, (2*n)+1)]
for _ in range(m):
op = int(eval(input()))
if op == 0:
shuffle()
else:
cut(op)
print(('\n'.join(map(str, cards))))
if __name__ == '__main__':
main(sys.argv[1:])
| # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0513
AC
"""
import sys
from sys import stdin
from itertools import chain
input = stdin.readline
def flatten(listOfLists):
"Flatten one level of nesting"
return chain.from_iterable(listOfLists)
def cut(k):
# ????????¨l
global cards
yellow = cards[:k]
blue = cards[k:]
cards = blue + yellow
def shuffle():
# ????????¨l
global cards
yellow = cards[:N]
blue = cards[N:]
temp = [[y, b] for y, b in zip(yellow, blue)]
cards = list(flatten(temp))
cards = []
def main(args):
global cards
n = int(eval(input()))
N = n
m = int(eval(input()))
cards = [x for x in range(1, (2*n)+1)]
for _ in range(m):
op = int(eval(input()))
if op == 0:
# shuffle()
temp = [[y, b] for y, b in zip(cards[:n], cards[n:])]
cards = list(flatten(temp))
else:
# cut(k)
cards = cards[op:] + cards[:op]
print(('\n'.join(map(str, cards))))
if __name__ == '__main__':
main(sys.argv[1:])
| 54 | 57 | 981 | 1,154 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0513
"""
import sys
from sys import stdin
from itertools import chain
input = stdin.readline
def flatten(listOfLists):
"Flatten one level of nesting"
return chain.from_iterable(listOfLists)
def cut(k):
global cards
yellow = cards[:k]
blue = cards[k:]
cards = blue + yellow
def shuffle():
global cards
yellow = cards[:N]
blue = cards[N:]
temp = [[y, b] for y, b in zip(yellow, blue)]
cards = list(flatten(temp))
cards = []
N = 0
def main(args):
global N
global cards
n = int(eval(input()))
N = n
m = int(eval(input()))
cards = [x for x in range(1, (2 * n) + 1)]
for _ in range(m):
op = int(eval(input()))
if op == 0:
shuffle()
else:
cut(op)
print(("\n".join(map(str, cards))))
if __name__ == "__main__":
main(sys.argv[1:])
| # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0513
AC
"""
import sys
from sys import stdin
from itertools import chain
input = stdin.readline
def flatten(listOfLists):
"Flatten one level of nesting"
return chain.from_iterable(listOfLists)
def cut(k):
# ????????¨l
global cards
yellow = cards[:k]
blue = cards[k:]
cards = blue + yellow
def shuffle():
# ????????¨l
global cards
yellow = cards[:N]
blue = cards[N:]
temp = [[y, b] for y, b in zip(yellow, blue)]
cards = list(flatten(temp))
cards = []
def main(args):
global cards
n = int(eval(input()))
N = n
m = int(eval(input()))
cards = [x for x in range(1, (2 * n) + 1)]
for _ in range(m):
op = int(eval(input()))
if op == 0:
# shuffle()
temp = [[y, b] for y, b in zip(cards[:n], cards[n:])]
cards = list(flatten(temp))
else:
# cut(k)
cards = cards[op:] + cards[:op]
print(("\n".join(map(str, cards))))
if __name__ == "__main__":
main(sys.argv[1:])
| false | 5.263158 | [
"+AC",
"+ # ????????¨l",
"+ # ????????¨l",
"-N = 0",
"- global N",
"- shuffle()",
"+ # shuffle()",
"+ temp = [[y, b] for y, b in zip(cards[:n], cards[n:])]",
"+ cards = list(flatten(temp))",
"- cut(op)",
"+ # cut(k)",
"+ cards = cards[op:] + cards[:op]"
] | false | 0.075244 | 0.041542 | 1.811298 | [
"s535832395",
"s216720359"
] |
u579699847 | p02735 | python | s238657763 | s113706419 | 38 | 33 | 3,952 | 3,188 | Accepted | Accepted | 13.16 | import bisect,collections,copy,itertools,math,string
def I(): return int(eval(input()))
def S(): return eval(input())
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
H,W = LI()
S = [S() for _ in range(H)]
dp = [[-1]*W for _ in range(H)]
for i in range(H):
for j in range(W):
judge = 1 if S[i][j]=='#' else 0
if i==0: #0行目
if j==0:
dp[0][0] = judge
else:
dp[0][j] = dp[0][j-1]+judge*(0 if S[0][j-1]=='#' else 1)
else: #0行目以外
if j==0:
dp[i][0] = dp[i-1][0]+judge*(0 if S[i-1][j]=='#' else 1)
else:
temp1 = dp[i][j-1]+judge*(0 if S[i][j-1]=='#' else 1)
temp2 = dp[i-1][j]+judge*(0 if S[i-1][j]=='#' else 1)
dp[i][j] = min(temp1,temp2)
print((dp[-1][-1]))
| import itertools,sys
def S(): return sys.stdin.readline().rstrip()
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
H,W = LI()
S = [S() for _ in range(H)]
dp = [[float('INF')]*W for _ in range(H)]
for i,j in itertools.product(list(range(H)),list(range(W))):
if i==0:
if j==0:
dp[i][j] = 1 if S[i][j]=='#' else 0
else:
dp[i][j] = dp[i][j-1]+(1 if S[i][j]=='#' and S[i][j-1]=='.' else 0)
else:
if i==0:
dp[i][j] = dp[i-1][j]+(1 if S[i][j]=='#' and S[i-1][j]=='.' else 0)
else:
dp[i][j] = min(dp[i][j],dp[i][j-1]+(1 if S[i][j]=='#' and S[i][j-1]=='.' else 0))
dp[i][j] = min(dp[i][j],dp[i-1][j]+(1 if S[i][j]=='#' and S[i-1][j]=='.' else 0))
print((dp[-1][-1]))
| 25 | 19 | 924 | 784 | import bisect, collections, copy, itertools, math, string
def I():
return int(eval(input()))
def S():
return eval(input())
def LI():
return list(map(int, input().split()))
def LS():
return list(input().split())
##################################################
H, W = LI()
S = [S() for _ in range(H)]
dp = [[-1] * W for _ in range(H)]
for i in range(H):
for j in range(W):
judge = 1 if S[i][j] == "#" else 0
if i == 0: # 0行目
if j == 0:
dp[0][0] = judge
else:
dp[0][j] = dp[0][j - 1] + judge * (0 if S[0][j - 1] == "#" else 1)
else: # 0行目以外
if j == 0:
dp[i][0] = dp[i - 1][0] + judge * (0 if S[i - 1][j] == "#" else 1)
else:
temp1 = dp[i][j - 1] + judge * (0 if S[i][j - 1] == "#" else 1)
temp2 = dp[i - 1][j] + judge * (0 if S[i - 1][j] == "#" else 1)
dp[i][j] = min(temp1, temp2)
print((dp[-1][-1]))
| import itertools, sys
def S():
return sys.stdin.readline().rstrip()
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
H, W = LI()
S = [S() for _ in range(H)]
dp = [[float("INF")] * W for _ in range(H)]
for i, j in itertools.product(list(range(H)), list(range(W))):
if i == 0:
if j == 0:
dp[i][j] = 1 if S[i][j] == "#" else 0
else:
dp[i][j] = dp[i][j - 1] + (
1 if S[i][j] == "#" and S[i][j - 1] == "." else 0
)
else:
if i == 0:
dp[i][j] = dp[i - 1][j] + (
1 if S[i][j] == "#" and S[i - 1][j] == "." else 0
)
else:
dp[i][j] = min(
dp[i][j],
dp[i][j - 1] + (1 if S[i][j] == "#" and S[i][j - 1] == "." else 0),
)
dp[i][j] = min(
dp[i][j],
dp[i - 1][j] + (1 if S[i][j] == "#" and S[i - 1][j] == "." else 0),
)
print((dp[-1][-1]))
| false | 24 | [
"-import bisect, collections, copy, itertools, math, string",
"-",
"-",
"-def I():",
"- return int(eval(input()))",
"+import itertools, sys",
"- return eval(input())",
"+ return sys.stdin.readline().rstrip()",
"- return list(map(int, input().split()))",
"+ return list(map(int, sys.stdin.readline().rstrip().split()))",
"-def LS():",
"- return list(input().split())",
"-",
"-",
"-##################################################",
"-dp = [[-1] * W for _ in range(H)]",
"-for i in range(H):",
"- for j in range(W):",
"- judge = 1 if S[i][j] == \"#\" else 0",
"- if i == 0: # 0行目",
"- if j == 0:",
"- dp[0][0] = judge",
"- else:",
"- dp[0][j] = dp[0][j - 1] + judge * (0 if S[0][j - 1] == \"#\" else 1)",
"- else: # 0行目以外",
"- if j == 0:",
"- dp[i][0] = dp[i - 1][0] + judge * (0 if S[i - 1][j] == \"#\" else 1)",
"- else:",
"- temp1 = dp[i][j - 1] + judge * (0 if S[i][j - 1] == \"#\" else 1)",
"- temp2 = dp[i - 1][j] + judge * (0 if S[i - 1][j] == \"#\" else 1)",
"- dp[i][j] = min(temp1, temp2)",
"+dp = [[float(\"INF\")] * W for _ in range(H)]",
"+for i, j in itertools.product(list(range(H)), list(range(W))):",
"+ if i == 0:",
"+ if j == 0:",
"+ dp[i][j] = 1 if S[i][j] == \"#\" else 0",
"+ else:",
"+ dp[i][j] = dp[i][j - 1] + (",
"+ 1 if S[i][j] == \"#\" and S[i][j - 1] == \".\" else 0",
"+ )",
"+ else:",
"+ if i == 0:",
"+ dp[i][j] = dp[i - 1][j] + (",
"+ 1 if S[i][j] == \"#\" and S[i - 1][j] == \".\" else 0",
"+ )",
"+ else:",
"+ dp[i][j] = min(",
"+ dp[i][j],",
"+ dp[i][j - 1] + (1 if S[i][j] == \"#\" and S[i][j - 1] == \".\" else 0),",
"+ )",
"+ dp[i][j] = min(",
"+ dp[i][j],",
"+ dp[i - 1][j] + (1 if S[i][j] == \"#\" and S[i - 1][j] == \".\" else 0),",
"+ )"
] | false | 0.038865 | 0.037828 | 1.027408 | [
"s238657763",
"s113706419"
] |
u519939795 | p03611 | python | s303489489 | s454535708 | 160 | 77 | 30,172 | 14,092 | Accepted | Accepted | 51.88 | import collections
n=int(eval(input()))
a=list(map(int,input().split()))
for i in range(n):
a.append(a[i]+1)
a.append(a[i]-1)
c=collections.Counter(a)
print((c.most_common()[0][1])) | n=int(eval(input()))
a=list(map(int,input().split()))
ans=[0]*100002
for i in a:
ans[i]+=1
ans[i+1]+=1
ans[i+2]+=1
print((max(ans)))
| 9 | 8 | 190 | 144 | import collections
n = int(eval(input()))
a = list(map(int, input().split()))
for i in range(n):
a.append(a[i] + 1)
a.append(a[i] - 1)
c = collections.Counter(a)
print((c.most_common()[0][1]))
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = [0] * 100002
for i in a:
ans[i] += 1
ans[i + 1] += 1
ans[i + 2] += 1
print((max(ans)))
| false | 11.111111 | [
"-import collections",
"-",
"-for i in range(n):",
"- a.append(a[i] + 1)",
"- a.append(a[i] - 1)",
"-c = collections.Counter(a)",
"-print((c.most_common()[0][1]))",
"+ans = [0] * 100002",
"+for i in a:",
"+ ans[i] += 1",
"+ ans[i + 1] += 1",
"+ ans[i + 2] += 1",
"+print((max(ans)))"
] | false | 0.110752 | 0.134354 | 0.824329 | [
"s303489489",
"s454535708"
] |
u507826663 | p02781 | python | s642646960 | s746437463 | 23 | 17 | 3,064 | 3,064 | Accepted | Accepted | 26.09 | N = int(eval(input()))
K = int(eval(input()))
A = 0
if N <= 100000:
for i in range(1,N+1):
c = str(i)
d = len(c) - c.count('0')
# print(i,c,d,len(c),c.count('0'))
if d == K:
A += 1
else:
keta = len(str(N))
if K ==1:
A = 9*(keta-1)
if K ==2:
A = 9*9*(keta-1)*(keta-2)//2
if K ==3:
A = 9*9*9*(keta-1)*(keta-2)*(keta-3)//6
nc = 1
# print(N,K,keta,A)
while nc <= 3 and keta >=1:
# abcd... -> 1000000 - a0000000
T = N//(10**(keta-1))%10
# print(T,nc)
if T == 0:
keta -=1
else:
if (nc == 1 and K==1) or (nc==2 and K==2) or (nc==3 and K==3):
A = A + (T)
if ((nc == 1 and K ==2) or (nc ==2 and K==3)):
A = A + int((T-1)*9*(keta-1))
if (nc==2 and K==2) or (nc==3 and K==3):
A = A + 9*(keta-1)
if (nc==1 and K ==3):
A = A + int((T-1)*9*9*(keta-1)*(keta-2)/2)
if (nc==2 and K==3):
A = A + int(9*9*(keta-1)*(keta-2)/2)
nc +=1
keta -=1
# print(A)
print(A) | N = int(eval(input()))
K = int(eval(input()))
A = 0
keta = len(str(N))
if K ==1:
A = 9*(keta-1)
if K ==2:
A = 9*9*(keta-1)*(keta-2)//2
if K ==3:
A = 9*9*9*(keta-1)*(keta-2)*(keta-3)//6
nc = 1
# print(N,K,keta,A)
while nc <= 3 and keta >=1:
# abcd... -> 1000000 - a0000000
T = N//(10**(keta-1))%10
# print(T,nc)
if T == 0:
keta -=1
else:
if (nc == 1 and K==1) or (nc==2 and K==2) or (nc==3 and K==3):
A = A + (T)
if ((nc == 1 and K ==2) or (nc ==2 and K==3)):
A = A + int((T-1)*9*(keta-1))
if (nc==2 and K==2) or (nc==3 and K==3):
A = A + 9*(keta-1)
if (nc==1 and K ==3):
A = A + int((T-1)*9*9*(keta-1)*(keta-2)/2)
if (nc==2 and K==3):
A = A + int(9*9*(keta-1)*(keta-2)/2)
nc +=1
keta -=1
# print(A)
print(A)
| 42 | 34 | 1,194 | 911 | N = int(eval(input()))
K = int(eval(input()))
A = 0
if N <= 100000:
for i in range(1, N + 1):
c = str(i)
d = len(c) - c.count("0")
# print(i,c,d,len(c),c.count('0'))
if d == K:
A += 1
else:
keta = len(str(N))
if K == 1:
A = 9 * (keta - 1)
if K == 2:
A = 9 * 9 * (keta - 1) * (keta - 2) // 2
if K == 3:
A = 9 * 9 * 9 * (keta - 1) * (keta - 2) * (keta - 3) // 6
nc = 1
# print(N,K,keta,A)
while nc <= 3 and keta >= 1:
# abcd... -> 1000000 - a0000000
T = N // (10 ** (keta - 1)) % 10
# print(T,nc)
if T == 0:
keta -= 1
else:
if (nc == 1 and K == 1) or (nc == 2 and K == 2) or (nc == 3 and K == 3):
A = A + (T)
if (nc == 1 and K == 2) or (nc == 2 and K == 3):
A = A + int((T - 1) * 9 * (keta - 1))
if (nc == 2 and K == 2) or (nc == 3 and K == 3):
A = A + 9 * (keta - 1)
if nc == 1 and K == 3:
A = A + int((T - 1) * 9 * 9 * (keta - 1) * (keta - 2) / 2)
if nc == 2 and K == 3:
A = A + int(9 * 9 * (keta - 1) * (keta - 2) / 2)
nc += 1
keta -= 1
# print(A)
print(A)
| N = int(eval(input()))
K = int(eval(input()))
A = 0
keta = len(str(N))
if K == 1:
A = 9 * (keta - 1)
if K == 2:
A = 9 * 9 * (keta - 1) * (keta - 2) // 2
if K == 3:
A = 9 * 9 * 9 * (keta - 1) * (keta - 2) * (keta - 3) // 6
nc = 1
# print(N,K,keta,A)
while nc <= 3 and keta >= 1:
# abcd... -> 1000000 - a0000000
T = N // (10 ** (keta - 1)) % 10
# print(T,nc)
if T == 0:
keta -= 1
else:
if (nc == 1 and K == 1) or (nc == 2 and K == 2) or (nc == 3 and K == 3):
A = A + (T)
if (nc == 1 and K == 2) or (nc == 2 and K == 3):
A = A + int((T - 1) * 9 * (keta - 1))
if (nc == 2 and K == 2) or (nc == 3 and K == 3):
A = A + 9 * (keta - 1)
if nc == 1 and K == 3:
A = A + int((T - 1) * 9 * 9 * (keta - 1) * (keta - 2) / 2)
if nc == 2 and K == 3:
A = A + int(9 * 9 * (keta - 1) * (keta - 2) / 2)
nc += 1
keta -= 1
# print(A)
print(A)
| false | 19.047619 | [
"-if N <= 100000:",
"- for i in range(1, N + 1):",
"- c = str(i)",
"- d = len(c) - c.count(\"0\")",
"- # print(i,c,d,len(c),c.count('0'))",
"- if d == K:",
"- A += 1",
"-else:",
"- keta = len(str(N))",
"- if K == 1:",
"- A = 9 * (keta - 1)",
"- if K == 2:",
"- A = 9 * 9 * (keta - 1) * (keta - 2) // 2",
"- if K == 3:",
"- A = 9 * 9 * 9 * (keta - 1) * (keta - 2) * (keta - 3) // 6",
"- nc = 1",
"- # print(N,K,keta,A)",
"- while nc <= 3 and keta >= 1:",
"- # abcd... -> 1000000 - a0000000",
"- T = N // (10 ** (keta - 1)) % 10",
"- # print(T,nc)",
"- if T == 0:",
"- keta -= 1",
"- else:",
"- if (nc == 1 and K == 1) or (nc == 2 and K == 2) or (nc == 3 and K == 3):",
"- A = A + (T)",
"- if (nc == 1 and K == 2) or (nc == 2 and K == 3):",
"- A = A + int((T - 1) * 9 * (keta - 1))",
"- if (nc == 2 and K == 2) or (nc == 3 and K == 3):",
"- A = A + 9 * (keta - 1)",
"- if nc == 1 and K == 3:",
"- A = A + int((T - 1) * 9 * 9 * (keta - 1) * (keta - 2) / 2)",
"- if nc == 2 and K == 3:",
"- A = A + int(9 * 9 * (keta - 1) * (keta - 2) / 2)",
"- nc += 1",
"- keta -= 1",
"+keta = len(str(N))",
"+if K == 1:",
"+ A = 9 * (keta - 1)",
"+if K == 2:",
"+ A = 9 * 9 * (keta - 1) * (keta - 2) // 2",
"+if K == 3:",
"+ A = 9 * 9 * 9 * (keta - 1) * (keta - 2) * (keta - 3) // 6",
"+nc = 1",
"+# print(N,K,keta,A)",
"+while nc <= 3 and keta >= 1:",
"+ # abcd... -> 1000000 - a0000000",
"+ T = N // (10 ** (keta - 1)) % 10",
"+ # print(T,nc)",
"+ if T == 0:",
"+ keta -= 1",
"+ else:",
"+ if (nc == 1 and K == 1) or (nc == 2 and K == 2) or (nc == 3 and K == 3):",
"+ A = A + (T)",
"+ if (nc == 1 and K == 2) or (nc == 2 and K == 3):",
"+ A = A + int((T - 1) * 9 * (keta - 1))",
"+ if (nc == 2 and K == 2) or (nc == 3 and K == 3):",
"+ A = A + 9 * (keta - 1)",
"+ if nc == 1 and K == 3:",
"+ A = A + int((T - 1) * 9 * 9 * (keta - 1) * (keta - 2) / 2)",
"+ if nc == 2 and K == 3:",
"+ A = A + int(9 * 9 * (keta - 1) * (keta - 2) / 2)",
"+ nc += 1",
"+ keta -= 1"
] | false | 0.040597 | 0.036074 | 1.125389 | [
"s642646960",
"s746437463"
] |
u562935282 | p03713 | python | s938979579 | s447273289 | 190 | 17 | 3,064 | 3,064 | Accepted | Accepted | 91.05 | def solve(h, w):
res = float('inf')
for hh in range(h + 1):
s1 = hh * w
ww = w // 2
s2 = (h - hh) * ww
s3 = (h - hh) * (w - ww)
res = min(res, max(s1, s2, s3) - min(s1, s2, s3))
return res
H, W = list(map(int, input().split()))
ans = H * W
if H % 3 == 0 or W % 3 == 0:
ans = 0
else:
ans = min(H, W)
ans = min(ans, solve(H, W))
ans = min(ans, solve(W, H))
print(ans)
| def calc(h, w):
w_1_1 = w // 3
w_1_2 = w_1_1 + 1
ans = inf
for w_1 in w_1_1, w_1_2:
s_1 = w_1 * h
# 縦に割る
w_2 = (w - w_1) // 2
s_2 = w_2 * h
w_3 = w - w_1 - w_2
s_3 = w_3 * h
ss = [s_1, s_2, s_3]
# print(h, w, ss)
ans = min(ans, max(ss) - min(ss))
# 横に割る
h_2 = h // 2
s_2 = h_2 * (w - w_1)
h_3 = h - h_2
s_3 = h_3 * (w - w_1)
ss = [s_1, s_2, s_3]
# print(h, w, ss)
ans = min(ans, max(ss) - min(ss))
return ans
inf = float('inf')
h, w = list(map(int, input().split()))
a = calc(h, w)
b = calc(w, h)
print((min(a, b)))
| 22 | 40 | 445 | 715 | def solve(h, w):
res = float("inf")
for hh in range(h + 1):
s1 = hh * w
ww = w // 2
s2 = (h - hh) * ww
s3 = (h - hh) * (w - ww)
res = min(res, max(s1, s2, s3) - min(s1, s2, s3))
return res
H, W = list(map(int, input().split()))
ans = H * W
if H % 3 == 0 or W % 3 == 0:
ans = 0
else:
ans = min(H, W)
ans = min(ans, solve(H, W))
ans = min(ans, solve(W, H))
print(ans)
| def calc(h, w):
w_1_1 = w // 3
w_1_2 = w_1_1 + 1
ans = inf
for w_1 in w_1_1, w_1_2:
s_1 = w_1 * h
# 縦に割る
w_2 = (w - w_1) // 2
s_2 = w_2 * h
w_3 = w - w_1 - w_2
s_3 = w_3 * h
ss = [s_1, s_2, s_3]
# print(h, w, ss)
ans = min(ans, max(ss) - min(ss))
# 横に割る
h_2 = h // 2
s_2 = h_2 * (w - w_1)
h_3 = h - h_2
s_3 = h_3 * (w - w_1)
ss = [s_1, s_2, s_3]
# print(h, w, ss)
ans = min(ans, max(ss) - min(ss))
return ans
inf = float("inf")
h, w = list(map(int, input().split()))
a = calc(h, w)
b = calc(w, h)
print((min(a, b)))
| false | 45 | [
"-def solve(h, w):",
"- res = float(\"inf\")",
"- for hh in range(h + 1):",
"- s1 = hh * w",
"- ww = w // 2",
"- s2 = (h - hh) * ww",
"- s3 = (h - hh) * (w - ww)",
"- res = min(res, max(s1, s2, s3) - min(s1, s2, s3))",
"- return res",
"+def calc(h, w):",
"+ w_1_1 = w // 3",
"+ w_1_2 = w_1_1 + 1",
"+ ans = inf",
"+ for w_1 in w_1_1, w_1_2:",
"+ s_1 = w_1 * h",
"+ # 縦に割る",
"+ w_2 = (w - w_1) // 2",
"+ s_2 = w_2 * h",
"+ w_3 = w - w_1 - w_2",
"+ s_3 = w_3 * h",
"+ ss = [s_1, s_2, s_3]",
"+ # print(h, w, ss)",
"+ ans = min(ans, max(ss) - min(ss))",
"+ # 横に割る",
"+ h_2 = h // 2",
"+ s_2 = h_2 * (w - w_1)",
"+ h_3 = h - h_2",
"+ s_3 = h_3 * (w - w_1)",
"+ ss = [s_1, s_2, s_3]",
"+ # print(h, w, ss)",
"+ ans = min(ans, max(ss) - min(ss))",
"+ return ans",
"-H, W = list(map(int, input().split()))",
"-ans = H * W",
"-if H % 3 == 0 or W % 3 == 0:",
"- ans = 0",
"-else:",
"- ans = min(H, W)",
"-ans = min(ans, solve(H, W))",
"-ans = min(ans, solve(W, H))",
"-print(ans)",
"+inf = float(\"inf\")",
"+h, w = list(map(int, input().split()))",
"+a = calc(h, w)",
"+b = calc(w, h)",
"+print((min(a, b)))"
] | false | 0.184615 | 0.062716 | 2.94366 | [
"s938979579",
"s447273289"
] |
u761320129 | p02834 | python | s641233433 | s052926755 | 1,161 | 617 | 128,760 | 133,064 | Accepted | Accepted | 46.86 | import sys
sys.setrecursionlimit(10**8)
N,U,V = list(map(int,input().split()))
U,V = U-1,V-1
AB = [tuple(map(int,input().split())) for i in range(N-1)]
es = [[] for _ in range(N)]
for a,b in AB:
a,b = a-1,b-1
es[a].append(b)
es[b].append(a)
prev = [-1] * N
def dfs(v,p=-1):
for to in es[v]:
if to==p: continue
prev[to] = v
dfs(to,v)
dfs(U)
path = [V]
while prev[path[-1]] >= 0:
path.append(prev[path[-1]])
ban = set(path[:(len(path)+1)//2])
reach = [0] * N
reach[U] = 1
def dfs2(v,p=-1):
for to in es[v]:
if to==p: continue
if to in ban: continue
reach[to] = 1
dfs2(to,v)
dfs2(U)
depth = [0] * N
ans = 0
def dfs3(v,p=-1):
global ans
for to in es[v]:
if to==p: continue
depth[to] = depth[v] + 1
if reach[to]:
ans = max(ans, depth[v])
dfs3(to,v)
dfs3(V)
print(ans) | import sys
sys.setrecursionlimit(10**8)
N,U,V = list(map(int,input().split()))
U,V = U-1,V-1
AB = [tuple(map(int,input().split())) for i in range(N-1)]
es = [[] for _ in range(N)]
for a,b in AB:
a,b = a-1,b-1
es[a].append(b)
es[b].append(a)
dist1 = [N] * N
dist1[V] = 0
def dfs1(v,p=-1):
for to in es[v]:
if to==p: continue
dist1[to] = dist1[v] + 1
dfs1(to,v)
dfs1(V)
D = dist1[U]
dist2 = [N] * N
dist2[U] = 0
def dfs2(v,p=-1):
for to in es[v]:
if to==p: continue
if (D+1)//2 > dist1[to]: continue
dist2[to] = dist2[v] + 1
dfs2(to,v)
dfs2(U)
ans = 0
for a,b in zip(dist1,dist2):
if b==N: continue
ans = max(ans, a-1)
print(ans) | 47 | 37 | 939 | 745 | import sys
sys.setrecursionlimit(10**8)
N, U, V = list(map(int, input().split()))
U, V = U - 1, V - 1
AB = [tuple(map(int, input().split())) for i in range(N - 1)]
es = [[] for _ in range(N)]
for a, b in AB:
a, b = a - 1, b - 1
es[a].append(b)
es[b].append(a)
prev = [-1] * N
def dfs(v, p=-1):
for to in es[v]:
if to == p:
continue
prev[to] = v
dfs(to, v)
dfs(U)
path = [V]
while prev[path[-1]] >= 0:
path.append(prev[path[-1]])
ban = set(path[: (len(path) + 1) // 2])
reach = [0] * N
reach[U] = 1
def dfs2(v, p=-1):
for to in es[v]:
if to == p:
continue
if to in ban:
continue
reach[to] = 1
dfs2(to, v)
dfs2(U)
depth = [0] * N
ans = 0
def dfs3(v, p=-1):
global ans
for to in es[v]:
if to == p:
continue
depth[to] = depth[v] + 1
if reach[to]:
ans = max(ans, depth[v])
dfs3(to, v)
dfs3(V)
print(ans)
| import sys
sys.setrecursionlimit(10**8)
N, U, V = list(map(int, input().split()))
U, V = U - 1, V - 1
AB = [tuple(map(int, input().split())) for i in range(N - 1)]
es = [[] for _ in range(N)]
for a, b in AB:
a, b = a - 1, b - 1
es[a].append(b)
es[b].append(a)
dist1 = [N] * N
dist1[V] = 0
def dfs1(v, p=-1):
for to in es[v]:
if to == p:
continue
dist1[to] = dist1[v] + 1
dfs1(to, v)
dfs1(V)
D = dist1[U]
dist2 = [N] * N
dist2[U] = 0
def dfs2(v, p=-1):
for to in es[v]:
if to == p:
continue
if (D + 1) // 2 > dist1[to]:
continue
dist2[to] = dist2[v] + 1
dfs2(to, v)
dfs2(U)
ans = 0
for a, b in zip(dist1, dist2):
if b == N:
continue
ans = max(ans, a - 1)
print(ans)
| false | 21.276596 | [
"-prev = [-1] * N",
"+dist1 = [N] * N",
"+dist1[V] = 0",
"-def dfs(v, p=-1):",
"+def dfs1(v, p=-1):",
"- prev[to] = v",
"- dfs(to, v)",
"+ dist1[to] = dist1[v] + 1",
"+ dfs1(to, v)",
"-dfs(U)",
"-path = [V]",
"-while prev[path[-1]] >= 0:",
"- path.append(prev[path[-1]])",
"-ban = set(path[: (len(path) + 1) // 2])",
"-reach = [0] * N",
"-reach[U] = 1",
"+dfs1(V)",
"+D = dist1[U]",
"+dist2 = [N] * N",
"+dist2[U] = 0",
"- if to in ban:",
"+ if (D + 1) // 2 > dist1[to]:",
"- reach[to] = 1",
"+ dist2[to] = dist2[v] + 1",
"-depth = [0] * N",
"-",
"-",
"-def dfs3(v, p=-1):",
"- global ans",
"- for to in es[v]:",
"- if to == p:",
"- continue",
"- depth[to] = depth[v] + 1",
"- if reach[to]:",
"- ans = max(ans, depth[v])",
"- dfs3(to, v)",
"-",
"-",
"-dfs3(V)",
"+for a, b in zip(dist1, dist2):",
"+ if b == N:",
"+ continue",
"+ ans = max(ans, a - 1)"
] | false | 0.03894 | 0.038132 | 1.02119 | [
"s641233433",
"s052926755"
] |
u316386814 | p03088 | python | s619808080 | s502482013 | 220 | 52 | 12,496 | 3,188 | Accepted | Accepted | 76.36 | import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from itertools import product
import numpy as np
def main():
N = II()
A, G, C, T = 0, 1, 2, 3
dp = np.zeros((N + 1, 4, 4, 4), int)
dp[0, T, T, T] = 1
for n in range(N):
for p1, p2, p3 in product(range(4), repeat=3):
for cur in range(4):
if (p2, p1, cur) == (A, G, C):
continue
if (p2, p1, cur) == (A, C, G):
continue
if (p2, p1, cur) == (G, A, C):
continue
if (p3, p1, cur) == (A, G, C):
continue
if (p3, p2, cur) == (A, G, C):
continue
dp[n + 1, cur, p1, p2] = \
(dp[n + 1, cur, p1, p2] + dp[n, p1, p2, p3]) % MOD
ans = np.sum(dp[N])
return ans % MOD
print(main())
| import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
from itertools import product
def main():
N = II()
A, G, C, T = list(range(4))
def code(c0, c1, c2):
return c0 + 4 * c1 + 16 * c2
dp = [0] * 64
dp[code(T, T, T)] = 1
for _ in range(N):
tmp = [0] * 64
for p1, p2, p3 in product(list(range(4)), repeat=3):
for cur in range(4):
if (p2, p1, cur) == (A, G, C):
continue
if (p2, p1, cur) == (A, C, G):
continue
if (p2, p1, cur) == (G, A, C):
continue
if (p3, p1, cur) == (A, G, C):
continue
if (p3, p2, cur) == (A, G, C):
continue
tmp[code(cur, p1, p2)] += dp[code(p1, p2, p3)]
tmp[code(cur, p1, p2)] %= MOD
dp = tmp
ans = sum(dp)
return ans % MOD
print((main())) | 39 | 42 | 1,257 | 1,311 | import sys
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return input()
from itertools import product
import numpy as np
def main():
N = II()
A, G, C, T = 0, 1, 2, 3
dp = np.zeros((N + 1, 4, 4, 4), int)
dp[0, T, T, T] = 1
for n in range(N):
for p1, p2, p3 in product(range(4), repeat=3):
for cur in range(4):
if (p2, p1, cur) == (A, G, C):
continue
if (p2, p1, cur) == (A, C, G):
continue
if (p2, p1, cur) == (G, A, C):
continue
if (p3, p1, cur) == (A, G, C):
continue
if (p3, p2, cur) == (A, G, C):
continue
dp[n + 1, cur, p1, p2] = (
dp[n + 1, cur, p1, p2] + dp[n, p1, p2, p3]
) % MOD
ans = np.sum(dp[N])
return ans % MOD
print(main())
| import sys
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return eval(input())
from itertools import product
def main():
N = II()
A, G, C, T = list(range(4))
def code(c0, c1, c2):
return c0 + 4 * c1 + 16 * c2
dp = [0] * 64
dp[code(T, T, T)] = 1
for _ in range(N):
tmp = [0] * 64
for p1, p2, p3 in product(list(range(4)), repeat=3):
for cur in range(4):
if (p2, p1, cur) == (A, G, C):
continue
if (p2, p1, cur) == (A, C, G):
continue
if (p2, p1, cur) == (G, A, C):
continue
if (p3, p1, cur) == (A, G, C):
continue
if (p3, p2, cur) == (A, G, C):
continue
tmp[code(cur, p1, p2)] += dp[code(p1, p2, p3)]
tmp[code(cur, p1, p2)] %= MOD
dp = tmp
ans = sum(dp)
return ans % MOD
print((main()))
| false | 7.142857 | [
"- return input()",
"+ return eval(input())",
"-import numpy as np",
"- A, G, C, T = 0, 1, 2, 3",
"- dp = np.zeros((N + 1, 4, 4, 4), int)",
"- dp[0, T, T, T] = 1",
"- for n in range(N):",
"- for p1, p2, p3 in product(range(4), repeat=3):",
"+ A, G, C, T = list(range(4))",
"+",
"+ def code(c0, c1, c2):",
"+ return c0 + 4 * c1 + 16 * c2",
"+",
"+ dp = [0] * 64",
"+ dp[code(T, T, T)] = 1",
"+ for _ in range(N):",
"+ tmp = [0] * 64",
"+ for p1, p2, p3 in product(list(range(4)), repeat=3):",
"- dp[n + 1, cur, p1, p2] = (",
"- dp[n + 1, cur, p1, p2] + dp[n, p1, p2, p3]",
"- ) % MOD",
"- ans = np.sum(dp[N])",
"+ tmp[code(cur, p1, p2)] += dp[code(p1, p2, p3)]",
"+ tmp[code(cur, p1, p2)] %= MOD",
"+ dp = tmp",
"+ ans = sum(dp)",
"-print(main())",
"+print((main()))"
] | false | 0.037435 | 0.105877 | 0.353573 | [
"s619808080",
"s502482013"
] |
u046158516 | p04000 | python | s096508465 | s213304293 | 1,549 | 836 | 138,484 | 238,704 | Accepted | Accepted | 46.03 | a={}
h,w,n=list(map(int,input().split()))
for i in range(n):
y,x=list(map(int,input().split()))
for j in range(max(2,x-1),min(w-1,x+1)+1):
for k in range(max(2,y-1),min(h-1,y+1)+1):
if j*(10**10)+k in a:
a[j*(10**10)+k]+=1
else:
a[j*(10**10)+k]=1
ans=[0]*10
ans[0]=(h-2)*(w-2)
for key in a:
ans[0]-=1
ans[a[key]]+=1
for i in ans:
print(i) | h,w,n=list(map(int,input().split()))
dic={}
INF=10**10
for i in range(n):
y,x=list(map(int,input().split()))
for j in range(max(2,x-1),min(w-1,x+1)+1):
for k in range(max(2,y-1),min(h-1,y+1)+1):
if j*INF+k in dic:
dic[j*INF+k]+=1
else:
dic[j*INF+k]=1
ans=[0]*10
ans[0]=(h-2)*(w-2)
for i in dic:
ans[0]-=1
ans[dic[i]]+=1
for i in ans:
print(i)
| 17 | 18 | 384 | 390 | a = {}
h, w, n = list(map(int, input().split()))
for i in range(n):
y, x = list(map(int, input().split()))
for j in range(max(2, x - 1), min(w - 1, x + 1) + 1):
for k in range(max(2, y - 1), min(h - 1, y + 1) + 1):
if j * (10**10) + k in a:
a[j * (10**10) + k] += 1
else:
a[j * (10**10) + k] = 1
ans = [0] * 10
ans[0] = (h - 2) * (w - 2)
for key in a:
ans[0] -= 1
ans[a[key]] += 1
for i in ans:
print(i)
| h, w, n = list(map(int, input().split()))
dic = {}
INF = 10**10
for i in range(n):
y, x = list(map(int, input().split()))
for j in range(max(2, x - 1), min(w - 1, x + 1) + 1):
for k in range(max(2, y - 1), min(h - 1, y + 1) + 1):
if j * INF + k in dic:
dic[j * INF + k] += 1
else:
dic[j * INF + k] = 1
ans = [0] * 10
ans[0] = (h - 2) * (w - 2)
for i in dic:
ans[0] -= 1
ans[dic[i]] += 1
for i in ans:
print(i)
| false | 5.555556 | [
"-a = {}",
"+dic = {}",
"+INF = 10**10",
"- if j * (10**10) + k in a:",
"- a[j * (10**10) + k] += 1",
"+ if j * INF + k in dic:",
"+ dic[j * INF + k] += 1",
"- a[j * (10**10) + k] = 1",
"+ dic[j * INF + k] = 1",
"-for key in a:",
"+for i in dic:",
"- ans[a[key]] += 1",
"+ ans[dic[i]] += 1"
] | false | 0.038122 | 0.117481 | 0.324493 | [
"s096508465",
"s213304293"
] |
u790710233 | p02662 | python | s985091575 | s520037961 | 736 | 112 | 96,936 | 68,540 | Accepted | Accepted | 84.78 | n, s = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 998244353
dp = [0]*(s+1)
dp[0] = pow(2, n, MOD)
inv_2 = pow(2, MOD-2, MOD)
for a in A:
for j in reversed(list(range(s+1))):
if s < j+a:
continue
dp[j+a] += dp[j]*inv_2 % MOD
print((dp[-1] % MOD))
| n, s = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 998244353
dp = [0]*(s+1)
dp[0] = pow(2, n, MOD)
inv_2 = pow(2, MOD-2, MOD)
for a in A:
for j in reversed(list(range(s+1))):
if s < j+a:
continue
dp[j+a] += dp[j]*inv_2
dp[j+a] %= MOD
print((dp[-1] % MOD)) | 13 | 14 | 308 | 325 | n, s = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 998244353
dp = [0] * (s + 1)
dp[0] = pow(2, n, MOD)
inv_2 = pow(2, MOD - 2, MOD)
for a in A:
for j in reversed(list(range(s + 1))):
if s < j + a:
continue
dp[j + a] += dp[j] * inv_2 % MOD
print((dp[-1] % MOD))
| n, s = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 998244353
dp = [0] * (s + 1)
dp[0] = pow(2, n, MOD)
inv_2 = pow(2, MOD - 2, MOD)
for a in A:
for j in reversed(list(range(s + 1))):
if s < j + a:
continue
dp[j + a] += dp[j] * inv_2
dp[j + a] %= MOD
print((dp[-1] % MOD))
| false | 7.142857 | [
"- dp[j + a] += dp[j] * inv_2 % MOD",
"+ dp[j + a] += dp[j] * inv_2",
"+ dp[j + a] %= MOD"
] | false | 0.034141 | 0.037872 | 0.901492 | [
"s985091575",
"s520037961"
] |
u644907318 | p02661 | python | s312220592 | s248697589 | 447 | 400 | 136,808 | 136,624 | Accepted | Accepted | 10.51 | N = int(eval(input()))
X = [list(map(int,input().split())) for _ in range(N)]
A = sorted([X[i][0] for i in range(N)])
B = sorted([X[i][1] for i in range(N)])
if N%2==1:
k = (N+1)//2
a = A[k-1]
b = B[k-1]
print((b-a+1))
else:
a2 = A[N//2-1]+A[N//2]
b2 = B[N//2-1]+B[N//2]
print((b2-a2+1)) | N = int(eval(input()))
X = [list(map(int,input().split())) for _ in range(N)]
A = sorted([X[i][0] for i in range(N)])
B = sorted([X[i][1] for i in range(N)])
if N%2==1:
a = A[N//2]
b = B[N//2]
print((b-a+1))
else:
a = (A[(N-1)//2]+A[N//2])/2
b = (B[(N-1)//2]+B[N//2])/2
print((int((b-a)/0.5)+1))
| 13 | 12 | 317 | 321 | N = int(eval(input()))
X = [list(map(int, input().split())) for _ in range(N)]
A = sorted([X[i][0] for i in range(N)])
B = sorted([X[i][1] for i in range(N)])
if N % 2 == 1:
k = (N + 1) // 2
a = A[k - 1]
b = B[k - 1]
print((b - a + 1))
else:
a2 = A[N // 2 - 1] + A[N // 2]
b2 = B[N // 2 - 1] + B[N // 2]
print((b2 - a2 + 1))
| N = int(eval(input()))
X = [list(map(int, input().split())) for _ in range(N)]
A = sorted([X[i][0] for i in range(N)])
B = sorted([X[i][1] for i in range(N)])
if N % 2 == 1:
a = A[N // 2]
b = B[N // 2]
print((b - a + 1))
else:
a = (A[(N - 1) // 2] + A[N // 2]) / 2
b = (B[(N - 1) // 2] + B[N // 2]) / 2
print((int((b - a) / 0.5) + 1))
| false | 7.692308 | [
"- k = (N + 1) // 2",
"- a = A[k - 1]",
"- b = B[k - 1]",
"+ a = A[N // 2]",
"+ b = B[N // 2]",
"- a2 = A[N // 2 - 1] + A[N // 2]",
"- b2 = B[N // 2 - 1] + B[N // 2]",
"- print((b2 - a2 + 1))",
"+ a = (A[(N - 1) // 2] + A[N // 2]) / 2",
"+ b = (B[(N - 1) // 2] + B[N // 2]) / 2",
"+ print((int((b - a) / 0.5) + 1))"
] | false | 0.049574 | 0.067314 | 0.736453 | [
"s312220592",
"s248697589"
] |
u864197622 | p02563 | python | s881399174 | s692457859 | 2,639 | 1,311 | 220,620 | 203,256 | Accepted | Accepted | 50.32 | p, g = 998244353, 3
invg = pow(g, p-2, p)
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(invg, (p - 1) >> i, p) for i in range(24)]
def fft(k, f):
for l in range(k)[::-1]:
d = 1 << l
u = 1
for i in range(d):
for j in range(i, 1 << k, 2*d):
f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
u = u * W[l+1] % p
def ifft(k, f):
for l in range(k):
d = 1 << l
u = 1
for i in range(d):
for j in range(i, 1 << k, 2*d):
f[j+d] *= u
f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
u = u * iW[l+1] % p
def convolve(a, b):
n0 = len(a) + len(b) - 1
k = (n0).bit_length() + 1
n = 1 << k
a = a + [0] * (n - len(a))
b = b + [0] * (n - len(b))
fft(k, a), fft(k, b)
for i in range(n):
a[i] = a[i] * b[i] % p
ifft(k, a)
invn = pow(n, p - 2, p)
for i in range(n0):
a[i] = a[i] * invn % p
return a[:n0]
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print((*convolve(A, B)))
| p, g = 998244353, 3
invg = pow(g, p-2, p)
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(invg, (p - 1) >> i, p) for i in range(24)]
def fft(k, f):
for l in range(k)[::-1]:
d = 1 << l
u = 1
for i in range(d):
for j in range(i, 1 << k, 2*d):
f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
u = u * W[l+1] % p
def ifft(k, f):
for l in range(k):
d = 1 << l
u = 1
for i in range(d):
for j in range(i, 1 << k, 2*d):
f[j+d] *= u
f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
u = u * iW[l+1] % p
def convolve(a, b):
n0 = len(a) + len(b) - 1
k = (n0).bit_length()
n = 1 << k
a = a + [0] * (n - len(a))
b = b + [0] * (n - len(b))
fft(k, a), fft(k, b)
for i in range(n):
a[i] = a[i] * b[i] % p
ifft(k, a)
invn = pow(n, p - 2, p)
for i in range(n0):
a[i] = a[i] * invn % p
return a[:n0]
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print((*convolve(A, B)))
| 43 | 43 | 1,203 | 1,199 | p, g = 998244353, 3
invg = pow(g, p - 2, p)
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(invg, (p - 1) >> i, p) for i in range(24)]
def fft(k, f):
for l in range(k)[::-1]:
d = 1 << l
u = 1
for i in range(d):
for j in range(i, 1 << k, 2 * d):
f[j], f[j + d] = (f[j] + f[j + d]) % p, u * (f[j] - f[j + d]) % p
u = u * W[l + 1] % p
def ifft(k, f):
for l in range(k):
d = 1 << l
u = 1
for i in range(d):
for j in range(i, 1 << k, 2 * d):
f[j + d] *= u
f[j], f[j + d] = (f[j] + f[j + d]) % p, (f[j] - f[j + d]) % p
u = u * iW[l + 1] % p
def convolve(a, b):
n0 = len(a) + len(b) - 1
k = (n0).bit_length() + 1
n = 1 << k
a = a + [0] * (n - len(a))
b = b + [0] * (n - len(b))
fft(k, a), fft(k, b)
for i in range(n):
a[i] = a[i] * b[i] % p
ifft(k, a)
invn = pow(n, p - 2, p)
for i in range(n0):
a[i] = a[i] * invn % p
return a[:n0]
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print((*convolve(A, B)))
| p, g = 998244353, 3
invg = pow(g, p - 2, p)
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(invg, (p - 1) >> i, p) for i in range(24)]
def fft(k, f):
for l in range(k)[::-1]:
d = 1 << l
u = 1
for i in range(d):
for j in range(i, 1 << k, 2 * d):
f[j], f[j + d] = (f[j] + f[j + d]) % p, u * (f[j] - f[j + d]) % p
u = u * W[l + 1] % p
def ifft(k, f):
for l in range(k):
d = 1 << l
u = 1
for i in range(d):
for j in range(i, 1 << k, 2 * d):
f[j + d] *= u
f[j], f[j + d] = (f[j] + f[j + d]) % p, (f[j] - f[j + d]) % p
u = u * iW[l + 1] % p
def convolve(a, b):
n0 = len(a) + len(b) - 1
k = (n0).bit_length()
n = 1 << k
a = a + [0] * (n - len(a))
b = b + [0] * (n - len(b))
fft(k, a), fft(k, b)
for i in range(n):
a[i] = a[i] * b[i] % p
ifft(k, a)
invn = pow(n, p - 2, p)
for i in range(n0):
a[i] = a[i] * invn % p
return a[:n0]
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print((*convolve(A, B)))
| false | 0 | [
"- k = (n0).bit_length() + 1",
"+ k = (n0).bit_length()"
] | false | 0.036655 | 0.03946 | 0.928931 | [
"s881399174",
"s692457859"
] |
u277177960 | p03911 | python | s461175744 | s738164937 | 546 | 420 | 120,408 | 142,068 | Accepted | Accepted | 23.08 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, M, L):
l2p = defaultdict(set)
p2l = defaultdict(set)
for i, l in enumerate(L):
p2l[i+1] = set(l)
for j in l:
l2p[j].add(i+1)
q = [1]
p_done = set(q)
l_done = set()
while q:
p = q.pop()
for l in p2l[p]:
if l in l_done:
continue
l_done.add(l)
for p2 in l2p[l]:
if p2 in p_done:
continue
p_done.add(p2)
q.append(p2)
return 'YES' if set(range(1, N+1)) == p_done else 'NO'
def main():
N, M = read_int_n()
L = [read_int_n()[1:] for _ in range(N)]
print(slv(N, M, L))
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter
import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
error_print(e - s, 'sec')
return ret
return wrap
class UnionFind():
def __init__(self):
self.__table = {}
self.__size = defaultdict(lambda: 1)
self.__rank = defaultdict(lambda: 1)
def __root(self, x):
if x not in self.__table:
self.__table[x] = x
elif x != self.__table[x]:
self.__table[x] = self.__root(self.__table[x])
return self.__table[x]
def same(self, x, y):
return self.__root(x) == self.__root(y)
def union(self, x, y):
x = self.__root(x)
y = self.__root(y)
if x == y:
return False
if self.__rank[x] < self.__rank[y]:
self.__table[x] = y
self.__size[y] += self.__size[x]
else:
self.__table[y] = x
self.__size[x] += self.__size[y]
if self.__rank[x] == self.__rank[y]:
self.__rank[x] += 1
return True
def size(self, x):
return self.__size[self.__root(x)]
def num_of_group(self):
g = 0
for k, v in self.__table.items():
if k == v:
g += 1
return g
@mt
def slv(N, M, L):
lo = 10**6
uf = UnionFind()
for i, l in enumerate(L):
for j in l:
uf.union(i, j+lo)
return 'YES' if all(uf.same(0, i) for i in range(1, N)) else 'NO'
def main():
N, M = read_int_n()
L = [list(map(lambda x: x-1, read_int_n()[1:])) for _ in range(N)]
print(slv(N, M, L))
if __name__ == '__main__':
main()
| 95 | 131 | 1,866 | 2,803 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
@mt
def slv(N, M, L):
l2p = defaultdict(set)
p2l = defaultdict(set)
for i, l in enumerate(L):
p2l[i + 1] = set(l)
for j in l:
l2p[j].add(i + 1)
q = [1]
p_done = set(q)
l_done = set()
while q:
p = q.pop()
for l in p2l[p]:
if l in l_done:
continue
l_done.add(l)
for p2 in l2p[l]:
if p2 in p_done:
continue
p_done.add(p2)
q.append(p2)
return "YES" if set(range(1, N + 1)) == p_done else "NO"
def main():
N, M = read_int_n()
L = [read_int_n()[1:] for _ in range(N)]
print(slv(N, M, L))
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import (
combinations,
combinations_with_replacement,
product,
permutations,
accumulate,
)
from operator import add, mul, sub, itemgetter, attrgetter
import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
error_print(e - s, "sec")
return ret
return wrap
class UnionFind:
def __init__(self):
self.__table = {}
self.__size = defaultdict(lambda: 1)
self.__rank = defaultdict(lambda: 1)
def __root(self, x):
if x not in self.__table:
self.__table[x] = x
elif x != self.__table[x]:
self.__table[x] = self.__root(self.__table[x])
return self.__table[x]
def same(self, x, y):
return self.__root(x) == self.__root(y)
def union(self, x, y):
x = self.__root(x)
y = self.__root(y)
if x == y:
return False
if self.__rank[x] < self.__rank[y]:
self.__table[x] = y
self.__size[y] += self.__size[x]
else:
self.__table[y] = x
self.__size[x] += self.__size[y]
if self.__rank[x] == self.__rank[y]:
self.__rank[x] += 1
return True
def size(self, x):
return self.__size[self.__root(x)]
def num_of_group(self):
g = 0
for k, v in self.__table.items():
if k == v:
g += 1
return g
@mt
def slv(N, M, L):
lo = 10**6
uf = UnionFind()
for i, l in enumerate(L):
for j in l:
uf.union(i, j + lo)
return "YES" if all(uf.same(0, i) for i in range(1, N)) else "NO"
def main():
N, M = read_int_n()
L = [list(map(lambda x: x - 1, read_int_n()[1:])) for _ in range(N)]
print(slv(N, M, L))
if __name__ == "__main__":
main()
| false | 27.480916 | [
"-import sys",
"+from fractions import Fraction",
"-from itertools import combinations, combinations_with_replacement, product, permutations",
"-from operator import add, mul, sub",
"+from itertools import (",
"+ combinations,",
"+ combinations_with_replacement,",
"+ product,",
"+ permutations,",
"+ accumulate,",
"+)",
"+from operator import add, mul, sub, itemgetter, attrgetter",
"+import sys",
"-sys.setrecursionlimit(100000)",
"-input = sys.stdin.readline",
"+# sys.setrecursionlimit(10**6)",
"+# readline = sys.stdin.buffer.readline",
"+readline = sys.stdin.readline",
"- return int(input())",
"+ return int(readline())",
"- return list(map(int, input().split()))",
"+ return list(map(int, readline().split()))",
"- return float(input())",
"+ return float(readline())",
"- return list(map(float, input().split()))",
"+ return list(map(float, readline().split()))",
"- return input().strip()",
"+ return readline().strip()",
"- return list(map(str, input().split()))",
"+ return readline().strip().split()",
"- s = time.time()",
"+ s = time.perf_counter()",
"- e = time.time()",
"+ e = time.perf_counter()",
"+class UnionFind:",
"+ def __init__(self):",
"+ self.__table = {}",
"+ self.__size = defaultdict(lambda: 1)",
"+ self.__rank = defaultdict(lambda: 1)",
"+",
"+ def __root(self, x):",
"+ if x not in self.__table:",
"+ self.__table[x] = x",
"+ elif x != self.__table[x]:",
"+ self.__table[x] = self.__root(self.__table[x])",
"+ return self.__table[x]",
"+",
"+ def same(self, x, y):",
"+ return self.__root(x) == self.__root(y)",
"+",
"+ def union(self, x, y):",
"+ x = self.__root(x)",
"+ y = self.__root(y)",
"+ if x == y:",
"+ return False",
"+ if self.__rank[x] < self.__rank[y]:",
"+ self.__table[x] = y",
"+ self.__size[y] += self.__size[x]",
"+ else:",
"+ self.__table[y] = x",
"+ self.__size[x] += self.__size[y]",
"+ if self.__rank[x] == self.__rank[y]:",
"+ self.__rank[x] += 1",
"+ return True",
"+",
"+ def size(self, x):",
"+ return self.__size[self.__root(x)]",
"+",
"+ def num_of_group(self):",
"+ g = 0",
"+ for k, v in self.__table.items():",
"+ if k == v:",
"+ g += 1",
"+ return g",
"+",
"+",
"- l2p = defaultdict(set)",
"- p2l = defaultdict(set)",
"+ lo = 10**6",
"+ uf = UnionFind()",
"- p2l[i + 1] = set(l)",
"- l2p[j].add(i + 1)",
"- q = [1]",
"- p_done = set(q)",
"- l_done = set()",
"- while q:",
"- p = q.pop()",
"- for l in p2l[p]:",
"- if l in l_done:",
"- continue",
"- l_done.add(l)",
"- for p2 in l2p[l]:",
"- if p2 in p_done:",
"- continue",
"- p_done.add(p2)",
"- q.append(p2)",
"- return \"YES\" if set(range(1, N + 1)) == p_done else \"NO\"",
"+ uf.union(i, j + lo)",
"+ return \"YES\" if all(uf.same(0, i) for i in range(1, N)) else \"NO\"",
"- L = [read_int_n()[1:] for _ in range(N)]",
"+ L = [list(map(lambda x: x - 1, read_int_n()[1:])) for _ in range(N)]"
] | false | 0.076322 | 0.041671 | 1.831536 | [
"s461175744",
"s738164937"
] |
u799428760 | p02642 | python | s401596371 | s739665751 | 424 | 342 | 34,744 | 34,932 | Accepted | Accepted | 19.34 | if __name__ == "__main__":
n = int(eval(input()))
l_a = list(map(int, input().split()))
s_a = list(set(l_a))
s_a.sort()
dub_a = [0]*(max(s_a)+1)
for i in l_a:
dub_a[i] += 1
dp = [1]*(max(s_a)+1)
for i in s_a:
if 2*i > len(dp)-1:
pass
'''
elif dp[2*i] == 0:
pass
'''
else:
for j in range(2*i, len(dp), i):
dp[j] = 0
count = 0
for i in s_a:
if dp[i]==1 and dub_a[i]==1:
count += 1
print(count)
| if __name__ == "__main__":
n = int(eval(input()))
l_a = list(map(int, input().split()))
s_a = list(set(l_a))
s_a.sort()
dub_a = [0]*(max(s_a)+1)
for i in l_a:
dub_a[i] += 1
dp = [1]*(max(s_a)+1)
for i in s_a:
if dp[i] == 0:
pass
else:
for j in range(2*i, len(dp), i):
dp[j] = 0
count = 0
for i in s_a:
if dp[i]==1 and dub_a[i]==1:
count += 1
print(count) | 31 | 27 | 599 | 509 | if __name__ == "__main__":
n = int(eval(input()))
l_a = list(map(int, input().split()))
s_a = list(set(l_a))
s_a.sort()
dub_a = [0] * (max(s_a) + 1)
for i in l_a:
dub_a[i] += 1
dp = [1] * (max(s_a) + 1)
for i in s_a:
if 2 * i > len(dp) - 1:
pass
"""
elif dp[2*i] == 0:
pass
"""
else:
for j in range(2 * i, len(dp), i):
dp[j] = 0
count = 0
for i in s_a:
if dp[i] == 1 and dub_a[i] == 1:
count += 1
print(count)
| if __name__ == "__main__":
n = int(eval(input()))
l_a = list(map(int, input().split()))
s_a = list(set(l_a))
s_a.sort()
dub_a = [0] * (max(s_a) + 1)
for i in l_a:
dub_a[i] += 1
dp = [1] * (max(s_a) + 1)
for i in s_a:
if dp[i] == 0:
pass
else:
for j in range(2 * i, len(dp), i):
dp[j] = 0
count = 0
for i in s_a:
if dp[i] == 1 and dub_a[i] == 1:
count += 1
print(count)
| false | 12.903226 | [
"- if 2 * i > len(dp) - 1:",
"+ if dp[i] == 0:",
"- \"\"\"",
"- elif dp[2*i] == 0:",
"- pass",
"- \"\"\""
] | false | 0.037328 | 0.044218 | 0.844189 | [
"s401596371",
"s739665751"
] |
u600402037 | p03805 | python | s166346679 | s601803914 | 57 | 42 | 3,064 | 3,064 | Accepted | Accepted | 26.32 | import itertools
N, M = list(map(int, input().split()))
edges = [tuple(sorted(map(int, input().split()))) for _ in range(M)]
answer = 0
for i in itertools.permutations(list(range(2, N+1)), N-1):
l = [1] + list(i)
answer += sum(1 for x in zip(l, l[1:]) if tuple(sorted(x)) in edges) == N-1
print(answer) | from itertools import permutations
N, M = list(map(int, input().split()))
AB = set([tuple(sorted(map(int, input().split()))) for _ in range(M)])
answer = 0
for pattern in permutations(list(range(2, N+1)), N-1):
pattern = [1] + list(pattern)
for i in zip(pattern[:-1], pattern[1:]):
if tuple(sorted(i)) not in AB:
break
else:
answer += 1
print(answer) | 10 | 14 | 313 | 393 | import itertools
N, M = list(map(int, input().split()))
edges = [tuple(sorted(map(int, input().split()))) for _ in range(M)]
answer = 0
for i in itertools.permutations(list(range(2, N + 1)), N - 1):
l = [1] + list(i)
answer += sum(1 for x in zip(l, l[1:]) if tuple(sorted(x)) in edges) == N - 1
print(answer)
| from itertools import permutations
N, M = list(map(int, input().split()))
AB = set([tuple(sorted(map(int, input().split()))) for _ in range(M)])
answer = 0
for pattern in permutations(list(range(2, N + 1)), N - 1):
pattern = [1] + list(pattern)
for i in zip(pattern[:-1], pattern[1:]):
if tuple(sorted(i)) not in AB:
break
else:
answer += 1
print(answer)
| false | 28.571429 | [
"-import itertools",
"+from itertools import permutations",
"-edges = [tuple(sorted(map(int, input().split()))) for _ in range(M)]",
"+AB = set([tuple(sorted(map(int, input().split()))) for _ in range(M)])",
"-for i in itertools.permutations(list(range(2, N + 1)), N - 1):",
"- l = [1] + list(i)",
"- answer += sum(1 for x in zip(l, l[1:]) if tuple(sorted(x)) in edges) == N - 1",
"+for pattern in permutations(list(range(2, N + 1)), N - 1):",
"+ pattern = [1] + list(pattern)",
"+ for i in zip(pattern[:-1], pattern[1:]):",
"+ if tuple(sorted(i)) not in AB:",
"+ break",
"+ else:",
"+ answer += 1"
] | false | 0.067817 | 0.132555 | 0.511619 | [
"s166346679",
"s601803914"
] |
u545368057 | p02882 | python | s776991528 | s833086102 | 1,230 | 154 | 21,500 | 12,484 | Accepted | Accepted | 87.48 | import numpy as np
a,b,V = list(map(int, input().split()))
x = V/(a*a)
if b >= 2*x:
tan = b**2/(2*a*x)
else:
tan = 2*(b-x)/a
ans = np.arctan(tan)
print((ans*180/np.pi)) | import numpy as np
a,b,V = list(map(int, input().split()))
x = V/(a*a)
"""
算数の解
"""
# if b >= 2*x:
# tan = b**2/(2*a*x)
# else:
# tan = 2*(b-x)/a
# ans = np.arctan(tan)
# print(ans*180/np.pi)
"""
二部探索
"""
def f(theta):
if np.tan(theta) < (2*x)/a:
l = x + a*np.tan(theta)/2
else:
l = (2*a*x*np.tan(theta))**0.5
return l >= b
eps = 10**-12
def binarySearch(l,r):
while r - l > eps:
mid = (l+r)/2
if f(mid):
r = mid
else:
l = mid
return r
print((binarySearch(-1*np.pi/180,(np.pi/2-eps))*180/np.pi))
| 9 | 36 | 176 | 621 | import numpy as np
a, b, V = list(map(int, input().split()))
x = V / (a * a)
if b >= 2 * x:
tan = b**2 / (2 * a * x)
else:
tan = 2 * (b - x) / a
ans = np.arctan(tan)
print((ans * 180 / np.pi))
| import numpy as np
a, b, V = list(map(int, input().split()))
x = V / (a * a)
"""
算数の解
"""
# if b >= 2*x:
# tan = b**2/(2*a*x)
# else:
# tan = 2*(b-x)/a
# ans = np.arctan(tan)
# print(ans*180/np.pi)
"""
二部探索
"""
def f(theta):
if np.tan(theta) < (2 * x) / a:
l = x + a * np.tan(theta) / 2
else:
l = (2 * a * x * np.tan(theta)) ** 0.5
return l >= b
eps = 10**-12
def binarySearch(l, r):
while r - l > eps:
mid = (l + r) / 2
if f(mid):
r = mid
else:
l = mid
return r
print((binarySearch(-1 * np.pi / 180, (np.pi / 2 - eps)) * 180 / np.pi))
| false | 75 | [
"-if b >= 2 * x:",
"- tan = b**2 / (2 * a * x)",
"-else:",
"- tan = 2 * (b - x) / a",
"-ans = np.arctan(tan)",
"-print((ans * 180 / np.pi))",
"+\"\"\"",
"+算数の解",
"+\"\"\"",
"+# if b >= 2*x:",
"+# tan = b**2/(2*a*x)",
"+# else:",
"+# tan = 2*(b-x)/a",
"+# ans = np.arctan(tan)",
"+# print(ans*180/np.pi)",
"+\"\"\"",
"+二部探索",
"+\"\"\"",
"+",
"+",
"+def f(theta):",
"+ if np.tan(theta) < (2 * x) / a:",
"+ l = x + a * np.tan(theta) / 2",
"+ else:",
"+ l = (2 * a * x * np.tan(theta)) ** 0.5",
"+ return l >= b",
"+",
"+",
"+eps = 10**-12",
"+",
"+",
"+def binarySearch(l, r):",
"+ while r - l > eps:",
"+ mid = (l + r) / 2",
"+ if f(mid):",
"+ r = mid",
"+ else:",
"+ l = mid",
"+ return r",
"+",
"+",
"+print((binarySearch(-1 * np.pi / 180, (np.pi / 2 - eps)) * 180 / np.pi))"
] | false | 0.33957 | 0.176921 | 1.919329 | [
"s776991528",
"s833086102"
] |
u268516119 | p04031 | python | s016306937 | s279925200 | 166 | 18 | 13,060 | 3,060 | Accepted | Accepted | 89.16 | import numpy as np
M=int(eval(input()))
n=list(map(int,input().split()))
x=int(round(np.mean(n)))
ans=0
for i in n:
ans=ans+(i-x)**2
print(ans)
| M=int(eval(input()))
n=list(map(int,input().split()))
x=int(round(sum(n)/M))
ans=0
for i in n:
ans=ans+(i-x)**2
print(ans)
| 8 | 7 | 149 | 127 | import numpy as np
M = int(eval(input()))
n = list(map(int, input().split()))
x = int(round(np.mean(n)))
ans = 0
for i in n:
ans = ans + (i - x) ** 2
print(ans)
| M = int(eval(input()))
n = list(map(int, input().split()))
x = int(round(sum(n) / M))
ans = 0
for i in n:
ans = ans + (i - x) ** 2
print(ans)
| false | 12.5 | [
"-import numpy as np",
"-",
"-x = int(round(np.mean(n)))",
"+x = int(round(sum(n) / M))"
] | false | 0.244561 | 0.040363 | 6.059091 | [
"s016306937",
"s279925200"
] |
u797673668 | p00537 | python | s594442232 | s274367181 | 1,430 | 530 | 15,960 | 16,452 | Accepted | Accepted | 62.94 | class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
n, m = list(map(int, input().split()))
bit = Bit(n + 1)
cities = list(map(int, input().split()))
prev = next(cities)
for cur in cities:
if prev < cur:
bit.add(prev, 1)
bit.add(cur, -1)
else:
bit.add(cur, 1)
bit.add(prev, -1)
prev = cur
ans = 0
for i in range(1, n):
a, b, c = list(map(int, input().split()))
bep = c // (a - b)
cnt = bit.sum(i)
if cnt > bep:
ans += b * cnt + c
else:
ans += a * cnt
print(ans) | from itertools import accumulate
n, m = list(map(int, input().split()))
cnts = [0] * (n + 1)
cities = list(map(int, input().split()))
prev = next(cities)
for cur in cities:
if prev < cur:
cnts[prev] += 1
cnts[cur] -= 1
else:
cnts[cur] += 1
cnts[prev] -= 1
prev = cur
cnts = list(accumulate(cnts))
ans = 0
for i in range(1, n):
a, b, c = list(map(int, input().split()))
bep = c // (a - b)
cnt = cnts[i]
if cnt > bep:
ans += b * cnt + c
else:
ans += a * cnt
print(ans) | 41 | 25 | 846 | 553 | class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
n, m = list(map(int, input().split()))
bit = Bit(n + 1)
cities = list(map(int, input().split()))
prev = next(cities)
for cur in cities:
if prev < cur:
bit.add(prev, 1)
bit.add(cur, -1)
else:
bit.add(cur, 1)
bit.add(prev, -1)
prev = cur
ans = 0
for i in range(1, n):
a, b, c = list(map(int, input().split()))
bep = c // (a - b)
cnt = bit.sum(i)
if cnt > bep:
ans += b * cnt + c
else:
ans += a * cnt
print(ans)
| from itertools import accumulate
n, m = list(map(int, input().split()))
cnts = [0] * (n + 1)
cities = list(map(int, input().split()))
prev = next(cities)
for cur in cities:
if prev < cur:
cnts[prev] += 1
cnts[cur] -= 1
else:
cnts[cur] += 1
cnts[prev] -= 1
prev = cur
cnts = list(accumulate(cnts))
ans = 0
for i in range(1, n):
a, b, c = list(map(int, input().split()))
bep = c // (a - b)
cnt = cnts[i]
if cnt > bep:
ans += b * cnt + c
else:
ans += a * cnt
print(ans)
| false | 39.02439 | [
"-class Bit:",
"- def __init__(self, n):",
"- self.size = n",
"- self.tree = [0] * (n + 1)",
"-",
"- def sum(self, i):",
"- s = 0",
"- while i > 0:",
"- s += self.tree[i]",
"- i -= i & -i",
"- return s",
"-",
"- def add(self, i, x):",
"- while i <= self.size:",
"- self.tree[i] += x",
"- i += i & -i",
"-",
"+from itertools import accumulate",
"-bit = Bit(n + 1)",
"+cnts = [0] * (n + 1)",
"- bit.add(prev, 1)",
"- bit.add(cur, -1)",
"+ cnts[prev] += 1",
"+ cnts[cur] -= 1",
"- bit.add(cur, 1)",
"- bit.add(prev, -1)",
"+ cnts[cur] += 1",
"+ cnts[prev] -= 1",
"+cnts = list(accumulate(cnts))",
"- cnt = bit.sum(i)",
"+ cnt = cnts[i]"
] | false | 0.066162 | 0.076253 | 0.867666 | [
"s594442232",
"s274367181"
] |
u845643816 | p00510 | python | s930618150 | s060441230 | 60 | 50 | 5,612 | 5,612 | Accepted | Accepted | 16.67 | n = int(eval(input()))
m = int(eval(input()))
S_max = m
for i in range(n):
a, b = list(map(int, input().split()))
m += a - b
if m < 0:
print((0))
break
S_max = max(S_max, m)
else:
print(S_max)
| n = int(eval(input()))
m = int(eval(input()))
S_max = m
for i in range(n):
a, b = list(map(int, input().split()))
m += a - b
if m < 0:
S_max = 0
break
S_max = max(S_max, m)
print(S_max)
| 12 | 11 | 220 | 210 | n = int(eval(input()))
m = int(eval(input()))
S_max = m
for i in range(n):
a, b = list(map(int, input().split()))
m += a - b
if m < 0:
print((0))
break
S_max = max(S_max, m)
else:
print(S_max)
| n = int(eval(input()))
m = int(eval(input()))
S_max = m
for i in range(n):
a, b = list(map(int, input().split()))
m += a - b
if m < 0:
S_max = 0
break
S_max = max(S_max, m)
print(S_max)
| false | 8.333333 | [
"- print((0))",
"+ S_max = 0",
"-else:",
"- print(S_max)",
"+print(S_max)"
] | false | 0.049253 | 0.042722 | 1.152858 | [
"s930618150",
"s060441230"
] |
u021548497 | p02560 | python | s546169217 | s857787301 | 657 | 298 | 106,300 | 78,812 | Accepted | Accepted | 54.64 | import sys
import numba
from numba import njit, i8
input = sys.stdin.readline
@njit(i8(i8, i8, i8, i8), cache=True)
def floor_sum(n, m, a, b):
ans = 0
if a >= m:
ans += (n-1) * n * (a // m) // 2
a %= m
if b >= m:
ans += b * (b // m)
b %= m
y_max = (a * n + b) // m
x_max = y_max * m - b
if y_max == 0:
return ans
ans += (n - (x_max + a - 1) // a) * y_max
ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
return ans
def main():
t = int(eval(input()))
for i in range(t):
n, m, a, b = list(map(int, input().split()))
res = floor_sum(n, m, a, b)
print(res)
if __name__ == "__main__":
main() | import sys
input = sys.stdin.readline
def floor_sum(n, m, a, b):
ans = 0
if a >= m:
ans += (n-1) * n * (a // m) // 2
a %= m
if b >= m:
ans += b * (b // m)
b %= m
y_max = (a * n + b) // m
x_max = y_max * m - b
if y_max == 0:
return ans
ans += (n - (x_max + a - 1) // a) * y_max
ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
return ans
def main():
t = int(eval(input()))
for i in range(t):
n, m, a, b =list(map(int, input().split()))
res = floor_sum(n, m, a, b)
print(res)
if __name__ == "__main__":
main()
| 33 | 31 | 733 | 654 | import sys
import numba
from numba import njit, i8
input = sys.stdin.readline
@njit(i8(i8, i8, i8, i8), cache=True)
def floor_sum(n, m, a, b):
ans = 0
if a >= m:
ans += (n - 1) * n * (a // m) // 2
a %= m
if b >= m:
ans += b * (b // m)
b %= m
y_max = (a * n + b) // m
x_max = y_max * m - b
if y_max == 0:
return ans
ans += (n - (x_max + a - 1) // a) * y_max
ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
return ans
def main():
t = int(eval(input()))
for i in range(t):
n, m, a, b = list(map(int, input().split()))
res = floor_sum(n, m, a, b)
print(res)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def floor_sum(n, m, a, b):
ans = 0
if a >= m:
ans += (n - 1) * n * (a // m) // 2
a %= m
if b >= m:
ans += b * (b // m)
b %= m
y_max = (a * n + b) // m
x_max = y_max * m - b
if y_max == 0:
return ans
ans += (n - (x_max + a - 1) // a) * y_max
ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
return ans
def main():
t = int(eval(input()))
for i in range(t):
n, m, a, b = list(map(int, input().split()))
res = floor_sum(n, m, a, b)
print(res)
if __name__ == "__main__":
main()
| false | 6.060606 | [
"-import numba",
"-from numba import njit, i8",
"-@njit(i8(i8, i8, i8, i8), cache=True)"
] | false | 0.044152 | 0.138502 | 0.318783 | [
"s546169217",
"s857787301"
] |
u347640436 | p02632 | python | s650886337 | s057636651 | 1,867 | 1,302 | 91,708 | 75,460 | Accepted | Accepted | 30.26 | # フェルマーの小定理
K = int(eval(input()))
S = eval(input())
m = 1000000007
def make_factorial_table(n):
result = [0] * (n + 1)
result[0] = 1
for i in range(1, n + 1):
result[i] = result[i - 1] * i % m
return result
def mcomb(n, k):
if n == 0 and k == 0:
return 1
if n < k or k < 0:
return 0
return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m
fac = make_factorial_table(len(S) - 1 + K)
result = 0
for i in range(K + 1):
result += pow(26, i, m) * mcomb(len(S) - 1 + K - i, K - i) * pow(25, K - i, m)
result %= m
print(result)
| # フェルマーの小定理
K = int(eval(input()))
S = eval(input())
m = 1000000007
result = 0
a = 1
b = 1
for i in range(K + 1):
# result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
result += pow(26, K - i, m) * (a * pow(b, m - 2, m)) * pow(25, i, m)
result %= m
a *= len(S) - 1 + (i + 1)
a %= m
b *= i + 1
b %= m
print(result)
| 30 | 19 | 621 | 370 | # フェルマーの小定理
K = int(eval(input()))
S = eval(input())
m = 1000000007
def make_factorial_table(n):
result = [0] * (n + 1)
result[0] = 1
for i in range(1, n + 1):
result[i] = result[i - 1] * i % m
return result
def mcomb(n, k):
if n == 0 and k == 0:
return 1
if n < k or k < 0:
return 0
return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m
fac = make_factorial_table(len(S) - 1 + K)
result = 0
for i in range(K + 1):
result += pow(26, i, m) * mcomb(len(S) - 1 + K - i, K - i) * pow(25, K - i, m)
result %= m
print(result)
| # フェルマーの小定理
K = int(eval(input()))
S = eval(input())
m = 1000000007
result = 0
a = 1
b = 1
for i in range(K + 1):
# result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
result += pow(26, K - i, m) * (a * pow(b, m - 2, m)) * pow(25, i, m)
result %= m
a *= len(S) - 1 + (i + 1)
a %= m
b *= i + 1
b %= m
print(result)
| false | 36.666667 | [
"-",
"-",
"-def make_factorial_table(n):",
"- result = [0] * (n + 1)",
"- result[0] = 1",
"- for i in range(1, n + 1):",
"- result[i] = result[i - 1] * i % m",
"- return result",
"-",
"-",
"-def mcomb(n, k):",
"- if n == 0 and k == 0:",
"- return 1",
"- if n < k or k < 0:",
"- return 0",
"- return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m",
"-",
"-",
"-fac = make_factorial_table(len(S) - 1 + K)",
"+a = 1",
"+b = 1",
"- result += pow(26, i, m) * mcomb(len(S) - 1 + K - i, K - i) * pow(25, K - i, m)",
"+ # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)",
"+ result += pow(26, K - i, m) * (a * pow(b, m - 2, m)) * pow(25, i, m)",
"+ a *= len(S) - 1 + (i + 1)",
"+ a %= m",
"+ b *= i + 1",
"+ b %= m"
] | false | 0.042373 | 0.098193 | 0.431534 | [
"s650886337",
"s057636651"
] |
u768896740 | p02996 | python | s095163357 | s414092050 | 1,114 | 982 | 55,260 | 53,716 | Accepted | Accepted | 11.85 | n = int(eval(input()))
num_list = []
for _ in range(n):
nums = list(map(int, input().split()))
num_list.append(nums)
num_list = sorted(num_list, key=lambda x: x[1])
count = 0
for i in range(n):
count += num_list[i][0]
if count > num_list[i][1]:
print('No')
exit()
print('Yes') | n = int(eval(input()))
jobs = []
for i in range(n):
array = list(map(int, input().split()))
jobs.append(array)
jobs.sort(key=lambda x:x[1])
time = 0
for i, j in jobs:
time += i
if time <= j:
continue
else:
print('No')
exit()
print('Yes') | 19 | 20 | 326 | 299 | n = int(eval(input()))
num_list = []
for _ in range(n):
nums = list(map(int, input().split()))
num_list.append(nums)
num_list = sorted(num_list, key=lambda x: x[1])
count = 0
for i in range(n):
count += num_list[i][0]
if count > num_list[i][1]:
print("No")
exit()
print("Yes")
| n = int(eval(input()))
jobs = []
for i in range(n):
array = list(map(int, input().split()))
jobs.append(array)
jobs.sort(key=lambda x: x[1])
time = 0
for i, j in jobs:
time += i
if time <= j:
continue
else:
print("No")
exit()
print("Yes")
| false | 5 | [
"-num_list = []",
"-for _ in range(n):",
"- nums = list(map(int, input().split()))",
"- num_list.append(nums)",
"-num_list = sorted(num_list, key=lambda x: x[1])",
"-count = 0",
"+jobs = []",
"- count += num_list[i][0]",
"- if count > num_list[i][1]:",
"+ array = list(map(int, input().split()))",
"+ jobs.append(array)",
"+jobs.sort(key=lambda x: x[1])",
"+time = 0",
"+for i, j in jobs:",
"+ time += i",
"+ if time <= j:",
"+ continue",
"+ else:"
] | false | 0.038736 | 0.046521 | 0.832671 | [
"s095163357",
"s414092050"
] |
u241159583 | p03993 | python | s273224532 | s380716426 | 78 | 69 | 13,880 | 14,004 | Accepted | Accepted | 11.54 | N = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(N):
if a[i] != "": n = a[i] - 1
if a[n] == i + 1:
ans += 1
a[n] = ""
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
if a[a[i]-1] == i+1:
cnt += 1
a[i] = ""
print(cnt) | 10 | 9 | 177 | 149 | N = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(N):
if a[i] != "":
n = a[i] - 1
if a[n] == i + 1:
ans += 1
a[n] = ""
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
if a[a[i] - 1] == i + 1:
cnt += 1
a[i] = ""
print(cnt)
| false | 10 | [
"-N = int(eval(input()))",
"+n = int(eval(input()))",
"-ans = 0",
"-for i in range(N):",
"- if a[i] != \"\":",
"- n = a[i] - 1",
"- if a[n] == i + 1:",
"- ans += 1",
"- a[n] = \"\"",
"-print(ans)",
"+cnt = 0",
"+for i in range(n):",
"+ if a[a[i] - 1] == i + 1:",
"+ cnt += 1",
"+ a[i] = \"\"",
"+print(cnt)"
] | false | 0.038501 | 0.036751 | 1.04763 | [
"s273224532",
"s380716426"
] |
u057916330 | p03764 | python | s115120613 | s938338730 | 152 | 116 | 18,576 | 18,624 | Accepted | Accepted | 23.68 | n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = 10 ** 9 + 7
xsum, ysum = 0, 0
for i in range(n):
xsum += i * x[i] - (n - 1 - i) * x[i]
for i in range(m):
ysum += i * y[i] - (m - 1 - i) * y[i]
ans = (xsum * ysum) % mod
print(ans)
| n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = 10 ** 9 + 7
xsum = sum((i * x[i] - (n - 1 - i) * x[i]) for i in range(n))
ysum = sum((i * y[i] - (m - 1 - i) * y[i]) for i in range(m))
ans = (xsum * ysum) % mod
print(ans)
| 11 | 8 | 310 | 291 | n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = 10**9 + 7
xsum, ysum = 0, 0
for i in range(n):
xsum += i * x[i] - (n - 1 - i) * x[i]
for i in range(m):
ysum += i * y[i] - (m - 1 - i) * y[i]
ans = (xsum * ysum) % mod
print(ans)
| n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = 10**9 + 7
xsum = sum((i * x[i] - (n - 1 - i) * x[i]) for i in range(n))
ysum = sum((i * y[i] - (m - 1 - i) * y[i]) for i in range(m))
ans = (xsum * ysum) % mod
print(ans)
| false | 27.272727 | [
"-xsum, ysum = 0, 0",
"-for i in range(n):",
"- xsum += i * x[i] - (n - 1 - i) * x[i]",
"-for i in range(m):",
"- ysum += i * y[i] - (m - 1 - i) * y[i]",
"+xsum = sum((i * x[i] - (n - 1 - i) * x[i]) for i in range(n))",
"+ysum = sum((i * y[i] - (m - 1 - i) * y[i]) for i in range(m))"
] | false | 0.039536 | 0.092277 | 0.428447 | [
"s115120613",
"s938338730"
] |
u702582248 | p03504 | python | s496565427 | s780301906 | 1,527 | 723 | 18,984 | 19,016 | Accepted | Accepted | 52.65 | def func():
tvs = []
for i in range(num):
tvs.append((-1, -1))
for i in range(len(bans)):
now = bans[i][0]
can = bans[i][2]
tvs = [tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1] != can]
for j, tv in enumerate(tvs):
if tv[1] == -1 or (tv[1] == can and tv[0] <= now) or tv[0] <= now - 1:
del tvs[j]
tvs.append((bans[i][1], can))
break
else:
return False
return True
n, C = list(map(int, input().split()))
bans = []
for i in range(n):
bans.append(tuple(map(int, input().split())))
bans.sort(key=lambda x: x[0])
for num in range(1, 1024):
if func():
print(num)
break
| def func():
tvs = []
for i in range(num):
tvs.append((-1, -1))
for i in range(len(bans)):
now = bans[i][0]
can = bans[i][2]
# tvs = [tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1] != can]
for j, tv in enumerate(tvs):
if tv[1] == -1 or (tv[1] == can and tv[0] <= now) or tv[0] <= now - 1:
del tvs[j]
tvs.append((bans[i][1], can))
break
else:
return False
return True
n, C = list(map(int, input().split()))
bans = []
for i in range(n):
bans.append(tuple(map(int, input().split())))
bans.sort(key=lambda x: x[0])
for num in range(1, 1024):
if func():
print(num)
break
| 29 | 29 | 765 | 767 | def func():
tvs = []
for i in range(num):
tvs.append((-1, -1))
for i in range(len(bans)):
now = bans[i][0]
can = bans[i][2]
tvs = [tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1] != can]
for j, tv in enumerate(tvs):
if tv[1] == -1 or (tv[1] == can and tv[0] <= now) or tv[0] <= now - 1:
del tvs[j]
tvs.append((bans[i][1], can))
break
else:
return False
return True
n, C = list(map(int, input().split()))
bans = []
for i in range(n):
bans.append(tuple(map(int, input().split())))
bans.sort(key=lambda x: x[0])
for num in range(1, 1024):
if func():
print(num)
break
| def func():
tvs = []
for i in range(num):
tvs.append((-1, -1))
for i in range(len(bans)):
now = bans[i][0]
can = bans[i][2]
# tvs = [tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1] != can]
for j, tv in enumerate(tvs):
if tv[1] == -1 or (tv[1] == can and tv[0] <= now) or tv[0] <= now - 1:
del tvs[j]
tvs.append((bans[i][1], can))
break
else:
return False
return True
n, C = list(map(int, input().split()))
bans = []
for i in range(n):
bans.append(tuple(map(int, input().split())))
bans.sort(key=lambda x: x[0])
for num in range(1, 1024):
if func():
print(num)
break
| false | 0 | [
"- tvs = [tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1] != can]",
"+ # tvs = [tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1] != can]"
] | false | 0.036225 | 0.036248 | 0.99939 | [
"s496565427",
"s780301906"
] |
u620084012 | p03503 | python | s832235750 | s440456469 | 570 | 236 | 3,064 | 42,972 | Accepted | Accepted | 58.6 | N = int(eval(input()))
F = [list(map(int, input().split())) for k in range(N)]
P = [list(map(int, input().split())) for k in range(N)]
B = [format(k,'b').zfill(10) for k in range(1,1024)]
ans = -10**9
for d in B:
t = 0
E = [0 for k in range(N)]
for l in range(N):
for k in range(10):
E[l] += int(d[k])*F[l][k]
for k in range(N):
t += P[k][E[k]]
ans = max(t,ans)
print(ans) | N = int(eval(input()))
F = [list(map(int,input().split())) for k in range(N)]
P = [list(map(int,input().split())) for k in range(N)]
ans = -float("inf")
for k in range(2**10):
temp = 0
S = [0 for l in range(N)]
for s in range(N):
for d in range(10):
if (k>>d)&1 == 1:
if F[s][d] == 1:
S[s] += 1
if sum(S) > 0:
for l in range(N):
temp += P[l][S[l]]
ans = max(ans,temp)
print(ans)
| 17 | 18 | 432 | 491 | N = int(eval(input()))
F = [list(map(int, input().split())) for k in range(N)]
P = [list(map(int, input().split())) for k in range(N)]
B = [format(k, "b").zfill(10) for k in range(1, 1024)]
ans = -(10**9)
for d in B:
t = 0
E = [0 for k in range(N)]
for l in range(N):
for k in range(10):
E[l] += int(d[k]) * F[l][k]
for k in range(N):
t += P[k][E[k]]
ans = max(t, ans)
print(ans)
| N = int(eval(input()))
F = [list(map(int, input().split())) for k in range(N)]
P = [list(map(int, input().split())) for k in range(N)]
ans = -float("inf")
for k in range(2**10):
temp = 0
S = [0 for l in range(N)]
for s in range(N):
for d in range(10):
if (k >> d) & 1 == 1:
if F[s][d] == 1:
S[s] += 1
if sum(S) > 0:
for l in range(N):
temp += P[l][S[l]]
ans = max(ans, temp)
print(ans)
| false | 5.555556 | [
"-B = [format(k, \"b\").zfill(10) for k in range(1, 1024)]",
"-ans = -(10**9)",
"-for d in B:",
"- t = 0",
"- E = [0 for k in range(N)]",
"- for l in range(N):",
"- for k in range(10):",
"- E[l] += int(d[k]) * F[l][k]",
"- for k in range(N):",
"- t += P[k][E[k]]",
"- ans = max(t, ans)",
"+ans = -float(\"inf\")",
"+for k in range(2**10):",
"+ temp = 0",
"+ S = [0 for l in range(N)]",
"+ for s in range(N):",
"+ for d in range(10):",
"+ if (k >> d) & 1 == 1:",
"+ if F[s][d] == 1:",
"+ S[s] += 1",
"+ if sum(S) > 0:",
"+ for l in range(N):",
"+ temp += P[l][S[l]]",
"+ ans = max(ans, temp)"
] | false | 0.089693 | 0.080645 | 1.112189 | [
"s832235750",
"s440456469"
] |
u579699847 | p02861 | python | s394135993 | s606297415 | 1,366 | 152 | 12,452 | 12,424 | Accepted | Accepted | 88.87 | import itertools,math,numpy as np
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
N = I()
xy = np.array(sorted([LI() for _ in range(N)]))
sum_norm = 0
dict_norm = {}
for a in itertools.permutations(list(range(N))):
for i in range(len(a)-1):
vector = tuple(xy[a[i+1]]-xy[a[i]])
if not vector in dict_norm:
dict_norm[vector] = np.linalg.norm(vector)
sum_norm += dict_norm[vector]
print((sum_norm/math.factorial(N)))
| import numpy as np
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
N = I()
xy = np.array([LI() for _ in range(N)])
sum_norm = 0
for i in range(N):
for j in range(i,N):
sum_norm += np.linalg.norm(xy[j]-xy[i])
print((2*sum_norm/N))
| 14 | 10 | 488 | 278 | import itertools, math, numpy as np
def I():
return int(eval(input()))
def LI():
return list(map(int, input().split()))
N = I()
xy = np.array(sorted([LI() for _ in range(N)]))
sum_norm = 0
dict_norm = {}
for a in itertools.permutations(list(range(N))):
for i in range(len(a) - 1):
vector = tuple(xy[a[i + 1]] - xy[a[i]])
if not vector in dict_norm:
dict_norm[vector] = np.linalg.norm(vector)
sum_norm += dict_norm[vector]
print((sum_norm / math.factorial(N)))
| import numpy as np
def I():
return int(eval(input()))
def LI():
return list(map(int, input().split()))
N = I()
xy = np.array([LI() for _ in range(N)])
sum_norm = 0
for i in range(N):
for j in range(i, N):
sum_norm += np.linalg.norm(xy[j] - xy[i])
print((2 * sum_norm / N))
| false | 28.571429 | [
"-import itertools, math, numpy as np",
"+import numpy as np",
"-xy = np.array(sorted([LI() for _ in range(N)]))",
"+xy = np.array([LI() for _ in range(N)])",
"-dict_norm = {}",
"-for a in itertools.permutations(list(range(N))):",
"- for i in range(len(a) - 1):",
"- vector = tuple(xy[a[i + 1]] - xy[a[i]])",
"- if not vector in dict_norm:",
"- dict_norm[vector] = np.linalg.norm(vector)",
"- sum_norm += dict_norm[vector]",
"-print((sum_norm / math.factorial(N)))",
"+for i in range(N):",
"+ for j in range(i, N):",
"+ sum_norm += np.linalg.norm(xy[j] - xy[i])",
"+print((2 * sum_norm / N))"
] | false | 0.281638 | 0.162312 | 1.735163 | [
"s394135993",
"s606297415"
] |
u674574659 | p03290 | python | s758878977 | s314087357 | 241 | 26 | 45,292 | 3,064 | Accepted | Accepted | 89.21 | import re
d,g = list(map(int,input().split() ))
l = [list(map(int,input().split() ))+[100*(x+1)] for x in range(d) ]
mondai_num = []
for k in range(2**d):
#先に全完するカテゴリ(何百点問題を全完するか)を決め、回す
bin_str = format(k, "0{}b".format(d) )#二進数の文字列を取得
#これが全完する問題のリスト
zenkan_list = [ x.start() for x in re.finditer("1",bin_str) ]
#0~9のリストと和の初期化
d_list = [i for i in range(d)]
wa = 0
cnt = 0
#全完した点数のみ先に足す
for i in zenkan_list:
wa = wa+(l[i][0])*((i+1)*100)
wa = wa + l[i][1]
cnt = cnt + l[i][0]
#全完したやつだけで目標を超えたらそこでストップ
if wa>=g:
mondai_num.append( cnt )
#全完したやつだけでたらなかったら素点が大きいやつを全完一歩手前まで足す
else:
#全完したカテゴリを除外
for i in zenkan_list:
d_list.remove(i)
#残ったカテゴリの中で最大の点数のカテゴリを探す
max_set = l[max(d_list)]
for i in range( max_set[0] ):
wa = wa + max_set[2]
if wa >= g:
mondai_num.append(cnt + i+1 )
break
print((min(mondai_num))) | import math
D,G = list(map(int,input().split()))
p = []
c = []
for i in range(D):
P,C = list(map(int,input().split()))
p.append(P)
c.append(C)
res = float("inf")
for i in range(2**D):
bs = format(i,"0{}b".format(D))
ans = 0
cnt = 0
#コンプするやつをたす
for j in range(D):
if bs[j] == "1":
ans += (j+1)*100*p[j] + c[j]
cnt += p[j]
if ans >= G:
res = min(cnt,res)
continue
#コンプしないやつを寸止めでたす
for j in range(D-1,-1,-1):
if bs[j] == "0":
ans += (j+1)*100*(p[j]-1)
cnt += (p[j]-1)
if ans >= G:
cnt -= (ans-G)//((j+1)*100)
res = min(res,cnt)
break
print(res) | 42 | 33 | 953 | 669 | import re
d, g = list(map(int, input().split()))
l = [list(map(int, input().split())) + [100 * (x + 1)] for x in range(d)]
mondai_num = []
for k in range(2**d):
# 先に全完するカテゴリ(何百点問題を全完するか)を決め、回す
bin_str = format(k, "0{}b".format(d)) # 二進数の文字列を取得
# これが全完する問題のリスト
zenkan_list = [x.start() for x in re.finditer("1", bin_str)]
# 0~9のリストと和の初期化
d_list = [i for i in range(d)]
wa = 0
cnt = 0
# 全完した点数のみ先に足す
for i in zenkan_list:
wa = wa + (l[i][0]) * ((i + 1) * 100)
wa = wa + l[i][1]
cnt = cnt + l[i][0]
# 全完したやつだけで目標を超えたらそこでストップ
if wa >= g:
mondai_num.append(cnt)
# 全完したやつだけでたらなかったら素点が大きいやつを全完一歩手前まで足す
else:
# 全完したカテゴリを除外
for i in zenkan_list:
d_list.remove(i)
# 残ったカテゴリの中で最大の点数のカテゴリを探す
max_set = l[max(d_list)]
for i in range(max_set[0]):
wa = wa + max_set[2]
if wa >= g:
mondai_num.append(cnt + i + 1)
break
print((min(mondai_num)))
| import math
D, G = list(map(int, input().split()))
p = []
c = []
for i in range(D):
P, C = list(map(int, input().split()))
p.append(P)
c.append(C)
res = float("inf")
for i in range(2**D):
bs = format(i, "0{}b".format(D))
ans = 0
cnt = 0
# コンプするやつをたす
for j in range(D):
if bs[j] == "1":
ans += (j + 1) * 100 * p[j] + c[j]
cnt += p[j]
if ans >= G:
res = min(cnt, res)
continue
# コンプしないやつを寸止めでたす
for j in range(D - 1, -1, -1):
if bs[j] == "0":
ans += (j + 1) * 100 * (p[j] - 1)
cnt += p[j] - 1
if ans >= G:
cnt -= (ans - G) // ((j + 1) * 100)
res = min(res, cnt)
break
print(res)
| false | 21.428571 | [
"-import re",
"+import math",
"-d, g = list(map(int, input().split()))",
"-l = [list(map(int, input().split())) + [100 * (x + 1)] for x in range(d)]",
"-mondai_num = []",
"-for k in range(2**d):",
"- # 先に全完するカテゴリ(何百点問題を全完するか)を決め、回す",
"- bin_str = format(k, \"0{}b\".format(d)) # 二進数の文字列を取得",
"- # これが全完する問題のリスト",
"- zenkan_list = [x.start() for x in re.finditer(\"1\", bin_str)]",
"- # 0~9のリストと和の初期化",
"- d_list = [i for i in range(d)]",
"- wa = 0",
"+D, G = list(map(int, input().split()))",
"+p = []",
"+c = []",
"+for i in range(D):",
"+ P, C = list(map(int, input().split()))",
"+ p.append(P)",
"+ c.append(C)",
"+res = float(\"inf\")",
"+for i in range(2**D):",
"+ bs = format(i, \"0{}b\".format(D))",
"+ ans = 0",
"- # 全完した点数のみ先に足す",
"- for i in zenkan_list:",
"- wa = wa + (l[i][0]) * ((i + 1) * 100)",
"- wa = wa + l[i][1]",
"- cnt = cnt + l[i][0]",
"- # 全完したやつだけで目標を超えたらそこでストップ",
"- if wa >= g:",
"- mondai_num.append(cnt)",
"- # 全完したやつだけでたらなかったら素点が大きいやつを全完一歩手前まで足す",
"- else:",
"- # 全完したカテゴリを除外",
"- for i in zenkan_list:",
"- d_list.remove(i)",
"- # 残ったカテゴリの中で最大の点数のカテゴリを探す",
"- max_set = l[max(d_list)]",
"- for i in range(max_set[0]):",
"- wa = wa + max_set[2]",
"- if wa >= g:",
"- mondai_num.append(cnt + i + 1)",
"+ # コンプするやつをたす",
"+ for j in range(D):",
"+ if bs[j] == \"1\":",
"+ ans += (j + 1) * 100 * p[j] + c[j]",
"+ cnt += p[j]",
"+ if ans >= G:",
"+ res = min(cnt, res)",
"+ continue",
"+ # コンプしないやつを寸止めでたす",
"+ for j in range(D - 1, -1, -1):",
"+ if bs[j] == \"0\":",
"+ ans += (j + 1) * 100 * (p[j] - 1)",
"+ cnt += p[j] - 1",
"+ if ans >= G:",
"+ cnt -= (ans - G) // ((j + 1) * 100)",
"+ res = min(res, cnt)",
"-print((min(mondai_num)))",
"+print(res)"
] | false | 0.052608 | 0.060028 | 0.876382 | [
"s758878977",
"s314087357"
] |
u644907318 | p02948 | python | s655791834 | s856217861 | 1,371 | 460 | 25,536 | 103,076 | Accepted | Accepted | 66.45 | import bisect
N,M = list(map(int,input().split()))
C = []
for _ in range(N):
A,B = list(map(int,input().split()))
C.append([A,B])
C = sorted(C,key=lambda x:x[0],reverse=True)
C = sorted(C,key=lambda x:x[1],reverse=True)
rev = 0
hist = list(range(0,M+1))
for x in C:
A,B = x[0],x[1]
ind = bisect.bisect_right(hist,M-A)
if ind>0:
hist.pop(ind-1)
rev += B
print(rev) | import heapq
from collections import deque
N,M = list(map(int,input().split()))
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
A = [(-A[i][1],A[i][0]) for i in range(N)]
A = deque(A)
heap = []
cnt = 0
for i in range(M-1,-1,-1):
k = M-i
while len(A)>0 and A[0][1]<=k:
heapq.heappush(heap,A.popleft())
if len(heap)>0:
b,a = heapq.heappop(heap)
b = -b
cnt += b
print(cnt) | 17 | 17 | 403 | 456 | import bisect
N, M = list(map(int, input().split()))
C = []
for _ in range(N):
A, B = list(map(int, input().split()))
C.append([A, B])
C = sorted(C, key=lambda x: x[0], reverse=True)
C = sorted(C, key=lambda x: x[1], reverse=True)
rev = 0
hist = list(range(0, M + 1))
for x in C:
A, B = x[0], x[1]
ind = bisect.bisect_right(hist, M - A)
if ind > 0:
hist.pop(ind - 1)
rev += B
print(rev)
| import heapq
from collections import deque
N, M = list(map(int, input().split()))
A = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
A = [(-A[i][1], A[i][0]) for i in range(N)]
A = deque(A)
heap = []
cnt = 0
for i in range(M - 1, -1, -1):
k = M - i
while len(A) > 0 and A[0][1] <= k:
heapq.heappush(heap, A.popleft())
if len(heap) > 0:
b, a = heapq.heappop(heap)
b = -b
cnt += b
print(cnt)
| false | 0 | [
"-import bisect",
"+import heapq",
"+from collections import deque",
"-C = []",
"-for _ in range(N):",
"- A, B = list(map(int, input().split()))",
"- C.append([A, B])",
"-C = sorted(C, key=lambda x: x[0], reverse=True)",
"-C = sorted(C, key=lambda x: x[1], reverse=True)",
"-rev = 0",
"-hist = list(range(0, M + 1))",
"-for x in C:",
"- A, B = x[0], x[1]",
"- ind = bisect.bisect_right(hist, M - A)",
"- if ind > 0:",
"- hist.pop(ind - 1)",
"- rev += B",
"-print(rev)",
"+A = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])",
"+A = [(-A[i][1], A[i][0]) for i in range(N)]",
"+A = deque(A)",
"+heap = []",
"+cnt = 0",
"+for i in range(M - 1, -1, -1):",
"+ k = M - i",
"+ while len(A) > 0 and A[0][1] <= k:",
"+ heapq.heappush(heap, A.popleft())",
"+ if len(heap) > 0:",
"+ b, a = heapq.heappop(heap)",
"+ b = -b",
"+ cnt += b",
"+print(cnt)"
] | false | 0.032653 | 0.033752 | 0.967428 | [
"s655791834",
"s856217861"
] |
u814265211 | p02802 | python | s214759676 | s496124541 | 332 | 268 | 31,564 | 25,396 | Accepted | Accepted | 19.28 | n, m = list(map(int, input().split()))
d = {}
for i in range(m):
p, s = input().split()
d.setdefault(p, [])
d[p].append(s)
cnt = 0; correct = 0
for v in list(d.values()):
if "AC" not in v:
continue
correct += 1
cnt += v.index("AC")
print((correct, cnt)) | N, M = list(map(int, input().split()))
l = [[] for _ in range(N)]
for i in range(M):
p, s = input().split()
l[int(p) - 1].append(s)
correct = 0
penalty = 0
for ll in l:
if 'AC' not in ll:
continue
correct += 1
penalty += ll.index('AC')
print((correct, penalty)) | 15 | 16 | 288 | 299 | n, m = list(map(int, input().split()))
d = {}
for i in range(m):
p, s = input().split()
d.setdefault(p, [])
d[p].append(s)
cnt = 0
correct = 0
for v in list(d.values()):
if "AC" not in v:
continue
correct += 1
cnt += v.index("AC")
print((correct, cnt))
| N, M = list(map(int, input().split()))
l = [[] for _ in range(N)]
for i in range(M):
p, s = input().split()
l[int(p) - 1].append(s)
correct = 0
penalty = 0
for ll in l:
if "AC" not in ll:
continue
correct += 1
penalty += ll.index("AC")
print((correct, penalty))
| false | 6.25 | [
"-n, m = list(map(int, input().split()))",
"-d = {}",
"-for i in range(m):",
"+N, M = list(map(int, input().split()))",
"+l = [[] for _ in range(N)]",
"+for i in range(M):",
"- d.setdefault(p, [])",
"- d[p].append(s)",
"-cnt = 0",
"+ l[int(p) - 1].append(s)",
"-for v in list(d.values()):",
"- if \"AC\" not in v:",
"+penalty = 0",
"+for ll in l:",
"+ if \"AC\" not in ll:",
"- cnt += v.index(\"AC\")",
"-print((correct, cnt))",
"+ penalty += ll.index(\"AC\")",
"+print((correct, penalty))"
] | false | 0.036315 | 0.067894 | 0.534888 | [
"s214759676",
"s496124541"
] |
u901582103 | p02675 | python | s551387417 | s609105417 | 55 | 21 | 61,608 | 9,164 | Accepted | Accepted | 61.82 | n=int(input()[-1])
if n==2 or n==4 or n==5 or n==7 or n==9:
print('hon')
elif n==0 or n==1 or n==6 or n==8:
print('pon')
else:
print('bon') | n=int(input()[-1])
if n in [2,4,5,7,9]:
print('hon')
elif n in [0,1,6,8]:
print('pon')
else:
print('bon') | 7 | 7 | 157 | 114 | n = int(input()[-1])
if n == 2 or n == 4 or n == 5 or n == 7 or n == 9:
print("hon")
elif n == 0 or n == 1 or n == 6 or n == 8:
print("pon")
else:
print("bon")
| n = int(input()[-1])
if n in [2, 4, 5, 7, 9]:
print("hon")
elif n in [0, 1, 6, 8]:
print("pon")
else:
print("bon")
| false | 0 | [
"-if n == 2 or n == 4 or n == 5 or n == 7 or n == 9:",
"+if n in [2, 4, 5, 7, 9]:",
"-elif n == 0 or n == 1 or n == 6 or n == 8:",
"+elif n in [0, 1, 6, 8]:"
] | false | 0.035471 | 0.071067 | 0.499124 | [
"s551387417",
"s609105417"
] |
u780475861 | p03425 | python | s031975675 | s249496725 | 189 | 41 | 3,064 | 10,864 | Accepted | Accepted | 78.31 | n = int(eval(input()))
lst = [0] * 5
march = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
nf = input()[0]
if nf in march:
lst[march.index(nf)] += 1
ret = 0
for a in range(0, 3):
for b in range(a + 1, 4):
for c in range(b + 1, 5):
ret += lst[a] * lst[b] * lst[c]
print(ret) | import sys
from itertools import combinations as comb
n, *S = open(0).read().split()
s = [i[0] for i in S]
c = [s.count(i) for i in 'MARCH']
ret = sum(x * y * z for x, y, z in comb(c, 3))
print(ret) | 13 | 7 | 298 | 204 | n = int(eval(input()))
lst = [0] * 5
march = ["M", "A", "R", "C", "H"]
for i in range(n):
nf = input()[0]
if nf in march:
lst[march.index(nf)] += 1
ret = 0
for a in range(0, 3):
for b in range(a + 1, 4):
for c in range(b + 1, 5):
ret += lst[a] * lst[b] * lst[c]
print(ret)
| import sys
from itertools import combinations as comb
n, *S = open(0).read().split()
s = [i[0] for i in S]
c = [s.count(i) for i in "MARCH"]
ret = sum(x * y * z for x, y, z in comb(c, 3))
print(ret)
| false | 46.153846 | [
"-n = int(eval(input()))",
"-lst = [0] * 5",
"-march = [\"M\", \"A\", \"R\", \"C\", \"H\"]",
"-for i in range(n):",
"- nf = input()[0]",
"- if nf in march:",
"- lst[march.index(nf)] += 1",
"-ret = 0",
"-for a in range(0, 3):",
"- for b in range(a + 1, 4):",
"- for c in range(b + 1, 5):",
"- ret += lst[a] * lst[b] * lst[c]",
"+import sys",
"+from itertools import combinations as comb",
"+",
"+n, *S = open(0).read().split()",
"+s = [i[0] for i in S]",
"+c = [s.count(i) for i in \"MARCH\"]",
"+ret = sum(x * y * z for x, y, z in comb(c, 3))"
] | false | 0.057959 | 0.036231 | 1.599734 | [
"s031975675",
"s249496725"
] |
u130900604 | p02684 | python | s682841128 | s605646596 | 205 | 157 | 32,408 | 31,812 | Accepted | Accepted | 23.41 | n,k=list(map(int,input().split()))
a=[0]+list(map(int,input().split()))
MAX_N=2*10**5
b=[1]
visited=[-1]*(n+10)
for i in range(1,2*MAX_N+1):
nxt=a[b[-1]]
b.append(nxt)
if k<=n:
print((b[k]))
exit()
# print(b)
for i,bi in enumerate(b):
if visited[bi]==-1:
visited[bi]=i
else:
m=i-visited[bi]
l=visited[bi]
break
k=k%m
while k<n:
k+=m
print((b[k]))
| n,k,*a=list(map(int,open(0).read().split()))
now=1
if k<=n:
for i in range(k):
now=a[now-1]
print(now)
exit()
# 絶対ループする
visited=[False]*n
visited[now-1]=-1
for i in range(4*10**5):
now=a[now-1]
if visited[now-1]==False:
visited[now-1]=i
else:
c,d=visited[now-1],i
break
k=(k-c)%(d-c)+c
while k<n:
k+=(d-c)
now=1
for i in range(k):
now=a[now-1]
print(now) | 27 | 26 | 440 | 407 | n, k = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
MAX_N = 2 * 10**5
b = [1]
visited = [-1] * (n + 10)
for i in range(1, 2 * MAX_N + 1):
nxt = a[b[-1]]
b.append(nxt)
if k <= n:
print((b[k]))
exit()
# print(b)
for i, bi in enumerate(b):
if visited[bi] == -1:
visited[bi] = i
else:
m = i - visited[bi]
l = visited[bi]
break
k = k % m
while k < n:
k += m
print((b[k]))
| n, k, *a = list(map(int, open(0).read().split()))
now = 1
if k <= n:
for i in range(k):
now = a[now - 1]
print(now)
exit()
# 絶対ループする
visited = [False] * n
visited[now - 1] = -1
for i in range(4 * 10**5):
now = a[now - 1]
if visited[now - 1] == False:
visited[now - 1] = i
else:
c, d = visited[now - 1], i
break
k = (k - c) % (d - c) + c
while k < n:
k += d - c
now = 1
for i in range(k):
now = a[now - 1]
print(now)
| false | 3.703704 | [
"-n, k = list(map(int, input().split()))",
"-a = [0] + list(map(int, input().split()))",
"-MAX_N = 2 * 10**5",
"-b = [1]",
"-visited = [-1] * (n + 10)",
"-for i in range(1, 2 * MAX_N + 1):",
"- nxt = a[b[-1]]",
"- b.append(nxt)",
"+n, k, *a = list(map(int, open(0).read().split()))",
"+now = 1",
"- print((b[k]))",
"+ for i in range(k):",
"+ now = a[now - 1]",
"+ print(now)",
"-# print(b)",
"-for i, bi in enumerate(b):",
"- if visited[bi] == -1:",
"- visited[bi] = i",
"+# 絶対ループする",
"+visited = [False] * n",
"+visited[now - 1] = -1",
"+for i in range(4 * 10**5):",
"+ now = a[now - 1]",
"+ if visited[now - 1] == False:",
"+ visited[now - 1] = i",
"- m = i - visited[bi]",
"- l = visited[bi]",
"+ c, d = visited[now - 1], i",
"-k = k % m",
"+k = (k - c) % (d - c) + c",
"- k += m",
"-print((b[k]))",
"+ k += d - c",
"+now = 1",
"+for i in range(k):",
"+ now = a[now - 1]",
"+print(now)"
] | false | 0.25036 | 0.037814 | 6.62075 | [
"s682841128",
"s605646596"
] |
u796942881 | p03329 | python | s225724575 | s821645366 | 189 | 18 | 3,060 | 3,060 | Accepted | Accepted | 90.48 | N = int(eval(input()))
def main():
ans = N
for i in range(N + 1):
num = 0
cur = i
while 0 < cur:
num += cur % 6
cur //= 6
cur = N - i
while 0 < cur:
num += cur % 9
cur //= 9
if num < ans:
ans = num
print(ans)
return
main()
| def f(num, base):
# calc max Pth Power
ret = 1
while ret <= num:
ret *= base
return ret // base
def main():
N = int(eval(input()))
st = {N}
ans = 0
while (all(st)):
st = {x - f(x, 6) for x in st} | {x - f(x, 9) for x in st}
ans += 1
print(ans)
return
main()
| 28 | 20 | 378 | 339 | N = int(eval(input()))
def main():
ans = N
for i in range(N + 1):
num = 0
cur = i
while 0 < cur:
num += cur % 6
cur //= 6
cur = N - i
while 0 < cur:
num += cur % 9
cur //= 9
if num < ans:
ans = num
print(ans)
return
main()
| def f(num, base):
# calc max Pth Power
ret = 1
while ret <= num:
ret *= base
return ret // base
def main():
N = int(eval(input()))
st = {N}
ans = 0
while all(st):
st = {x - f(x, 6) for x in st} | {x - f(x, 9) for x in st}
ans += 1
print(ans)
return
main()
| false | 28.571429 | [
"-N = int(eval(input()))",
"+def f(num, base):",
"+ # calc max Pth Power",
"+ ret = 1",
"+ while ret <= num:",
"+ ret *= base",
"+ return ret // base",
"- ans = N",
"- for i in range(N + 1):",
"- num = 0",
"- cur = i",
"- while 0 < cur:",
"- num += cur % 6",
"- cur //= 6",
"- cur = N - i",
"- while 0 < cur:",
"- num += cur % 9",
"- cur //= 9",
"- if num < ans:",
"- ans = num",
"+ N = int(eval(input()))",
"+ st = {N}",
"+ ans = 0",
"+ while all(st):",
"+ st = {x - f(x, 6) for x in st} | {x - f(x, 9) for x in st}",
"+ ans += 1"
] | false | 0.04889 | 0.036984 | 1.321904 | [
"s225724575",
"s821645366"
] |
u075012704 | p03380 | python | s221008609 | s999173848 | 114 | 70 | 14,060 | 14,428 | Accepted | Accepted | 38.6 | N = int(eval(input()))
A = sorted(list(map(int, input().split())))
ans_n = A.pop()
target = ans_n / 2
ans_r = - 1
high_score = 0
for r in A:
min_r = min(ans_n - r, r)
if min_r >= high_score:
high_score = r
ans_r = r
print((ans_n, ans_r))
| N = int(eval(input()))
A = list(map(int, input().split()))
n, r = max(A), None
A.pop(A.index(n))
target, best_score = n / 2, float('inf')
for a in A:
score = abs(a - target)
if score < best_score:
best_score = score
r = a
print((n, r))
| 15 | 13 | 271 | 266 | N = int(eval(input()))
A = sorted(list(map(int, input().split())))
ans_n = A.pop()
target = ans_n / 2
ans_r = -1
high_score = 0
for r in A:
min_r = min(ans_n - r, r)
if min_r >= high_score:
high_score = r
ans_r = r
print((ans_n, ans_r))
| N = int(eval(input()))
A = list(map(int, input().split()))
n, r = max(A), None
A.pop(A.index(n))
target, best_score = n / 2, float("inf")
for a in A:
score = abs(a - target)
if score < best_score:
best_score = score
r = a
print((n, r))
| false | 13.333333 | [
"-A = sorted(list(map(int, input().split())))",
"-ans_n = A.pop()",
"-target = ans_n / 2",
"-ans_r = -1",
"-high_score = 0",
"-for r in A:",
"- min_r = min(ans_n - r, r)",
"- if min_r >= high_score:",
"- high_score = r",
"- ans_r = r",
"-print((ans_n, ans_r))",
"+A = list(map(int, input().split()))",
"+n, r = max(A), None",
"+A.pop(A.index(n))",
"+target, best_score = n / 2, float(\"inf\")",
"+for a in A:",
"+ score = abs(a - target)",
"+ if score < best_score:",
"+ best_score = score",
"+ r = a",
"+print((n, r))"
] | false | 0.037855 | 0.045125 | 0.8389 | [
"s221008609",
"s999173848"
] |
u028973125 | p02936 | python | s745699856 | s190898018 | 1,996 | 789 | 120,012 | 121,416 | Accepted | Accepted | 60.47 | from pprint import pprint
from collections import deque, defaultdict
n, q = list(map(int, input().strip().split(" ")))
# edges = defaultdict(set)
edges = [[] for _ in range(n)]
for _ in range(n-1):
a_i, b_i = list(map(int, input().strip().split(" ")))
edges[a_i-1].append(b_i-1)
edges[b_i-1].append(a_i-1)
# edges[a_i-1].add(b_i-1)
# edges[b_i-1].add(a_i-1)
# p = defaultdict(int)
# counter = defaultdict(int)
counter = [0] * n
p = [0] * n
for _ in range(q):
p_i, x_i = list(map(int, input().strip().split(" ")))
# p[p_i-1] += x_i
counter[p_i-1] += x_i
parents = deque()
# parents.append(0)
# parents = []
parents.append(0)
visited = set()
while parents:
parent = parents.popleft()
# parent = parents.pop()
if parent in visited:
continue
visited.add(parent)
# counter[parent] += p[parent]
# print("parent")
# print(parent, counter[parent])
for child in edges[parent]:
if child in visited:
continue
# if counter[child] != 0:
# continue
counter[child] += counter[parent]
# print("child")
# print(child, counter[child])
parents.append(child)
# parents.add(child)
#print(" ".join(list(map(str, counter.values()))))
#print(" ".join(list(map(str, counter))))
print((*counter)) | from pprint import pprint
from collections import deque
import sys
n, q = list(map(int, sys.stdin.readline().strip().split(" ")))
edges = [[] for _ in range(n)]
for _ in range(n-1):
a_i, b_i = list(map(int, sys.stdin.readline().strip().split(" ")))
edges[a_i-1].append(b_i-1)
edges[b_i-1].append(a_i-1)
counter = [0] * n
p = [0] * n
for _ in range(q):
p_i, x_i = list(map(int, sys.stdin.readline().strip().split(" ")))
counter[p_i-1] += x_i
parents = deque()
parents.append(0)
visited = set()
while parents:
parent = parents.popleft()
if parent in visited:
continue
visited.add(parent)
for child in edges[parent]:
if child in visited:
continue
counter[child] += counter[parent]
parents.append(child)
print((" ".join(list(map(str, counter))))) | 51 | 34 | 1,374 | 841 | from pprint import pprint
from collections import deque, defaultdict
n, q = list(map(int, input().strip().split(" ")))
# edges = defaultdict(set)
edges = [[] for _ in range(n)]
for _ in range(n - 1):
a_i, b_i = list(map(int, input().strip().split(" ")))
edges[a_i - 1].append(b_i - 1)
edges[b_i - 1].append(a_i - 1)
# edges[a_i-1].add(b_i-1)
# edges[b_i-1].add(a_i-1)
# p = defaultdict(int)
# counter = defaultdict(int)
counter = [0] * n
p = [0] * n
for _ in range(q):
p_i, x_i = list(map(int, input().strip().split(" ")))
# p[p_i-1] += x_i
counter[p_i - 1] += x_i
parents = deque()
# parents.append(0)
# parents = []
parents.append(0)
visited = set()
while parents:
parent = parents.popleft()
# parent = parents.pop()
if parent in visited:
continue
visited.add(parent)
# counter[parent] += p[parent]
# print("parent")
# print(parent, counter[parent])
for child in edges[parent]:
if child in visited:
continue
# if counter[child] != 0:
# continue
counter[child] += counter[parent]
# print("child")
# print(child, counter[child])
parents.append(child)
# parents.add(child)
# print(" ".join(list(map(str, counter.values()))))
# print(" ".join(list(map(str, counter))))
print((*counter))
| from pprint import pprint
from collections import deque
import sys
n, q = list(map(int, sys.stdin.readline().strip().split(" ")))
edges = [[] for _ in range(n)]
for _ in range(n - 1):
a_i, b_i = list(map(int, sys.stdin.readline().strip().split(" ")))
edges[a_i - 1].append(b_i - 1)
edges[b_i - 1].append(a_i - 1)
counter = [0] * n
p = [0] * n
for _ in range(q):
p_i, x_i = list(map(int, sys.stdin.readline().strip().split(" ")))
counter[p_i - 1] += x_i
parents = deque()
parents.append(0)
visited = set()
while parents:
parent = parents.popleft()
if parent in visited:
continue
visited.add(parent)
for child in edges[parent]:
if child in visited:
continue
counter[child] += counter[parent]
parents.append(child)
print((" ".join(list(map(str, counter)))))
| false | 33.333333 | [
"-from collections import deque, defaultdict",
"+from collections import deque",
"+import sys",
"-n, q = list(map(int, input().strip().split(\" \")))",
"-# edges = defaultdict(set)",
"+n, q = list(map(int, sys.stdin.readline().strip().split(\" \")))",
"- a_i, b_i = list(map(int, input().strip().split(\" \")))",
"+ a_i, b_i = list(map(int, sys.stdin.readline().strip().split(\" \")))",
"- # edges[a_i-1].add(b_i-1)",
"- # edges[b_i-1].add(a_i-1)",
"-# p = defaultdict(int)",
"-# counter = defaultdict(int)",
"- p_i, x_i = list(map(int, input().strip().split(\" \")))",
"- # p[p_i-1] += x_i",
"+ p_i, x_i = list(map(int, sys.stdin.readline().strip().split(\" \")))",
"-# parents.append(0)",
"-# parents = []",
"- # parent = parents.pop()",
"- # counter[parent] += p[parent]",
"- # print(\"parent\")",
"- # print(parent, counter[parent])",
"- # if counter[child] != 0:",
"- # continue",
"- # print(\"child\")",
"- # print(child, counter[child])",
"- # parents.add(child)",
"-# print(\" \".join(list(map(str, counter.values()))))",
"-# print(\" \".join(list(map(str, counter))))",
"-print((*counter))",
"+print((\" \".join(list(map(str, counter)))))"
] | false | 0.054764 | 0.054137 | 1.011573 | [
"s745699856",
"s190898018"
] |
u410118019 | p02996 | python | s706556327 | s931590344 | 709 | 449 | 53,752 | 31,872 | Accepted | Accepted | 36.67 | import sys
from operator import itemgetter
input = sys.stdin.readline
n = int(eval(input()))
l = [list(map(int,input().split())) for _ in range(n)]
l.sort(key=itemgetter(1))
a = 0
flag = 0
for _ in range(n):
a += l[_][0]
if a > l[_][1]:
print('No')
flag = 1
break
if flag == 0:
print('Yes') | import sys
from operator import itemgetter
input = sys.stdin.readline
n = int(eval(input()))
l = [tuple(map(int,input().split())) for _ in range(n)]
l.sort(key=itemgetter(1))
a = 0
flag = 0
for _ in range(n):
a += l[_][0]
if a > l[_][1]:
print('No')
flag = 1
break
if flag == 0:
print('Yes') | 16 | 16 | 317 | 318 | import sys
from operator import itemgetter
input = sys.stdin.readline
n = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(n)]
l.sort(key=itemgetter(1))
a = 0
flag = 0
for _ in range(n):
a += l[_][0]
if a > l[_][1]:
print("No")
flag = 1
break
if flag == 0:
print("Yes")
| import sys
from operator import itemgetter
input = sys.stdin.readline
n = int(eval(input()))
l = [tuple(map(int, input().split())) for _ in range(n)]
l.sort(key=itemgetter(1))
a = 0
flag = 0
for _ in range(n):
a += l[_][0]
if a > l[_][1]:
print("No")
flag = 1
break
if flag == 0:
print("Yes")
| false | 0 | [
"-l = [list(map(int, input().split())) for _ in range(n)]",
"+l = [tuple(map(int, input().split())) for _ in range(n)]"
] | false | 0.045761 | 0.046148 | 0.991624 | [
"s706556327",
"s931590344"
] |
u724687935 | p02833 | python | s955968857 | s324458863 | 165 | 17 | 38,256 | 2,940 | Accepted | Accepted | 89.7 | N = int(eval(input()))
ans = 0
if N % 2 == 0:
mod = 10
while N >= mod:
ans += N // mod
mod *= 5
print(ans)
| # def f(n):
# if n < 2:
# return 1
# else:
# return n * f(n - 2)
# for i in range(2, 150, 2):
# print(i, f(i))
N = int(eval(input()))
if N % 2 == 1:
print((0))
exit()
k = 10
cnt = 0
while k <= N:
cnt += N // k
k *= 5
print(cnt)
| 11 | 22 | 138 | 290 | N = int(eval(input()))
ans = 0
if N % 2 == 0:
mod = 10
while N >= mod:
ans += N // mod
mod *= 5
print(ans)
| # def f(n):
# if n < 2:
# return 1
# else:
# return n * f(n - 2)
# for i in range(2, 150, 2):
# print(i, f(i))
N = int(eval(input()))
if N % 2 == 1:
print((0))
exit()
k = 10
cnt = 0
while k <= N:
cnt += N // k
k *= 5
print(cnt)
| false | 50 | [
"+# def f(n):",
"+# if n < 2:",
"+# return 1",
"+# else:",
"+# return n * f(n - 2)",
"+# for i in range(2, 150, 2):",
"+# print(i, f(i))",
"-ans = 0",
"-if N % 2 == 0:",
"- mod = 10",
"- while N >= mod:",
"- ans += N // mod",
"- mod *= 5",
"-print(ans)",
"+if N % 2 == 1:",
"+ print((0))",
"+ exit()",
"+k = 10",
"+cnt = 0",
"+while k <= N:",
"+ cnt += N // k",
"+ k *= 5",
"+print(cnt)"
] | false | 0.036196 | 0.035647 | 1.015394 | [
"s955968857",
"s324458863"
] |
u809819902 | p02945 | python | s576411045 | s944696940 | 29 | 26 | 9,156 | 9,152 | Accepted | Accepted | 10.34 | a,b = list(map(int, input().split()))
li = [a+b, a-b,a*b]
print((max(li)))
| a,b=list(map(int,input().split()))
print((max(a+b,a-b,a*b))) | 3 | 2 | 69 | 53 | a, b = list(map(int, input().split()))
li = [a + b, a - b, a * b]
print((max(li)))
| a, b = list(map(int, input().split()))
print((max(a + b, a - b, a * b)))
| false | 33.333333 | [
"-li = [a + b, a - b, a * b]",
"-print((max(li)))",
"+print((max(a + b, a - b, a * b)))"
] | false | 0.047642 | 0.049309 | 0.966199 | [
"s576411045",
"s944696940"
] |
u729133443 | p03128 | python | s909498068 | s432097091 | 207 | 138 | 15,524 | 14,388 | Accepted | Accepted | 33.33 | n,m,*a=list(map(int,open(0).read().split()))
d=[0]*n*9
for i in range(n):
for j in a:c=i+(0,2,5,5,4,5,6,3,7,6)[j];d[c]=max(d[c],(d[i]*10+j)*(i<1or d[i]>0))
print((d[n])) | n,m,*a=list(map(int,open(0).read().split()))
d=[0]*n+[-1]*9
for i in range(n):d[i+1]=max(j+d[i-int('0144345265'[j])]*10for j in a)
print((d[n])) | 5 | 4 | 166 | 139 | n, m, *a = list(map(int, open(0).read().split()))
d = [0] * n * 9
for i in range(n):
for j in a:
c = i + (0, 2, 5, 5, 4, 5, 6, 3, 7, 6)[j]
d[c] = max(d[c], (d[i] * 10 + j) * (i < 1 or d[i] > 0))
print((d[n]))
| n, m, *a = list(map(int, open(0).read().split()))
d = [0] * n + [-1] * 9
for i in range(n):
d[i + 1] = max(j + d[i - int("0144345265"[j])] * 10 for j in a)
print((d[n]))
| false | 20 | [
"-d = [0] * n * 9",
"+d = [0] * n + [-1] * 9",
"- for j in a:",
"- c = i + (0, 2, 5, 5, 4, 5, 6, 3, 7, 6)[j]",
"- d[c] = max(d[c], (d[i] * 10 + j) * (i < 1 or d[i] > 0))",
"+ d[i + 1] = max(j + d[i - int(\"0144345265\"[j])] * 10 for j in a)"
] | false | 0.037228 | 0.037458 | 0.993858 | [
"s909498068",
"s432097091"
] |
u998741086 | p03861 | python | s388850428 | s734589066 | 31 | 27 | 9,124 | 9,060 | Accepted | Accepted | 12.9 | #!/usr/bin/env python
a, b, x = list(map(int, input().split()))
if a == b:
if a%x == 0:
print((1))
else:
print((0))
exit()
if a%x == 0 and b%x == 0:
ans = b//x - a//x + 1
print(ans)
exit()
if a%x != 0 and b%x != 0:
ans = b//x - a//x
print(ans)
exit()
if a%x == 0 and b%x != 0:
ans = b//x - a//x + 1
print(ans)
exit()
ans = b//x - a//x
print(ans)
| #!/usr/bin/env python
a, b, x = list(map(int, input().split()))
def f(n):
global x
if n == -1:
return 0
return n//x + 1
ans = f(b)-f(a-1)
print(ans)
| 24 | 12 | 428 | 179 | #!/usr/bin/env python
a, b, x = list(map(int, input().split()))
if a == b:
if a % x == 0:
print((1))
else:
print((0))
exit()
if a % x == 0 and b % x == 0:
ans = b // x - a // x + 1
print(ans)
exit()
if a % x != 0 and b % x != 0:
ans = b // x - a // x
print(ans)
exit()
if a % x == 0 and b % x != 0:
ans = b // x - a // x + 1
print(ans)
exit()
ans = b // x - a // x
print(ans)
| #!/usr/bin/env python
a, b, x = list(map(int, input().split()))
def f(n):
global x
if n == -1:
return 0
return n // x + 1
ans = f(b) - f(a - 1)
print(ans)
| false | 50 | [
"-if a == b:",
"- if a % x == 0:",
"- print((1))",
"- else:",
"- print((0))",
"- exit()",
"-if a % x == 0 and b % x == 0:",
"- ans = b // x - a // x + 1",
"- print(ans)",
"- exit()",
"-if a % x != 0 and b % x != 0:",
"- ans = b // x - a // x",
"- print(ans)",
"- exit()",
"-if a % x == 0 and b % x != 0:",
"- ans = b // x - a // x + 1",
"- print(ans)",
"- exit()",
"-ans = b // x - a // x",
"+",
"+",
"+def f(n):",
"+ global x",
"+ if n == -1:",
"+ return 0",
"+ return n // x + 1",
"+",
"+",
"+ans = f(b) - f(a - 1)"
] | false | 0.042802 | 0.007632 | 5.608521 | [
"s388850428",
"s734589066"
] |
u724687935 | p03855 | python | s958195296 | s723330847 | 1,583 | 933 | 47,328 | 57,480 | Accepted | Accepted | 41.06 | from collections import Counter
class WeightedUnionFind():
def __init__(self, n):
self.parents = [-1] * n
self.weight = [0] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.weight[x] += self.weight[self.parents[x]]
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y, w):
rx = self.find(x)
ry = self.find(y)
if rx == ry:
return
if self.parents[rx] > self.parents[ry]:
rx, ry = ry, rx
x, y = y, x
w = -w
self.parents[rx] += self.parents[ry]
self.parents[ry] = rx
self.weight[ry] = + self.weight[x] - w - self.weight[y]
def find_position(self, x):
if self.parents[x] < 0:
return 0
else:
return -self.weight[x] + self.find_position(self.parents[x])
def diff(self, x, y):
if self.find(x) != self.find(y):
raise Exception('"{}" belongs to a different tree from "{}"'.format(x, y))
return self.find_position(y) - self.find_position(x)
N, K, L = map(int, input().split())
uf1 = WeightedUnionFind(N)
uf2 = WeightedUnionFind(N)
for _ in range(K):
p, q = map(int, input().split())
uf1.union(p - 1, q - 1, 0)
for _ in range(L):
r, s = map(int, input().split())
uf2.union(r - 1, s - 1, 0)
path = [None] * N
for i in range(N):
path[i] = (uf1.find(i), uf2.find(i))
cnt = Counter(path)
for i in range(N - 1):
print(cnt[path[i]], end=' ')
print(cnt[path[N - 1]])
| class UnionFind():
def __init__(self, n):
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def main():
import sys
from collections import Counter
# readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, K, L = list(map(int, input().split()))
uf1 = UnionFind(N)
uf2 = UnionFind(N)
IN = readlines()
for i in range(K):
p, q = list(map(int, IN[i].split()))
p -= 1; q -= 1
uf1.union(p, q)
for j in range(K, K + L):
r, s = list(map(int, IN[j].split()))
r -= 1; s -= 1
# if uf1.find(r) == uf1.find(s):
uf2.union(r, s)
# ans = []
# for i in range(N):
# ans.append(-uf2.parents[uf2.find(i)])
# print(*ans)
path = []
C = Counter()
for i in range(N):
pair = (uf1.find(i), uf2.find(i))
path.append(pair)
C[pair] += 1
ans = []
for i in range(N):
ans.append(C[path[i]])
print((*ans))
if __name__ == "__main__":
main()
| 63 | 64 | 1,674 | 1,474 | from collections import Counter
class WeightedUnionFind:
def __init__(self, n):
self.parents = [-1] * n
self.weight = [0] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.weight[x] += self.weight[self.parents[x]]
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y, w):
rx = self.find(x)
ry = self.find(y)
if rx == ry:
return
if self.parents[rx] > self.parents[ry]:
rx, ry = ry, rx
x, y = y, x
w = -w
self.parents[rx] += self.parents[ry]
self.parents[ry] = rx
self.weight[ry] = +self.weight[x] - w - self.weight[y]
def find_position(self, x):
if self.parents[x] < 0:
return 0
else:
return -self.weight[x] + self.find_position(self.parents[x])
def diff(self, x, y):
if self.find(x) != self.find(y):
raise Exception('"{}" belongs to a different tree from "{}"'.format(x, y))
return self.find_position(y) - self.find_position(x)
N, K, L = map(int, input().split())
uf1 = WeightedUnionFind(N)
uf2 = WeightedUnionFind(N)
for _ in range(K):
p, q = map(int, input().split())
uf1.union(p - 1, q - 1, 0)
for _ in range(L):
r, s = map(int, input().split())
uf2.union(r - 1, s - 1, 0)
path = [None] * N
for i in range(N):
path[i] = (uf1.find(i), uf2.find(i))
cnt = Counter(path)
for i in range(N - 1):
print(cnt[path[i]], end=" ")
print(cnt[path[N - 1]])
| class UnionFind:
def __init__(self, n):
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def main():
import sys
from collections import Counter
# readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, K, L = list(map(int, input().split()))
uf1 = UnionFind(N)
uf2 = UnionFind(N)
IN = readlines()
for i in range(K):
p, q = list(map(int, IN[i].split()))
p -= 1
q -= 1
uf1.union(p, q)
for j in range(K, K + L):
r, s = list(map(int, IN[j].split()))
r -= 1
s -= 1
# if uf1.find(r) == uf1.find(s):
uf2.union(r, s)
# ans = []
# for i in range(N):
# ans.append(-uf2.parents[uf2.find(i)])
# print(*ans)
path = []
C = Counter()
for i in range(N):
pair = (uf1.find(i), uf2.find(i))
path.append(pair)
C[pair] += 1
ans = []
for i in range(N):
ans.append(C[path[i]])
print((*ans))
if __name__ == "__main__":
main()
| false | 1.5625 | [
"-from collections import Counter",
"-",
"-",
"-class WeightedUnionFind:",
"+class UnionFind:",
"- self.weight = [0] * n",
"- self.weight[x] += self.weight[self.parents[x]]",
"- def union(self, x, y, w):",
"- rx = self.find(x)",
"- ry = self.find(y)",
"- if rx == ry:",
"+ def union(self, x, y):",
"+ x = self.find(x)",
"+ y = self.find(y)",
"+ if x == y:",
"- if self.parents[rx] > self.parents[ry]:",
"- rx, ry = ry, rx",
"+ if self.parents[x] > self.parents[y]:",
"- w = -w",
"- self.parents[rx] += self.parents[ry]",
"- self.parents[ry] = rx",
"- self.weight[ry] = +self.weight[x] - w - self.weight[y]",
"-",
"- def find_position(self, x):",
"- if self.parents[x] < 0:",
"- return 0",
"- else:",
"- return -self.weight[x] + self.find_position(self.parents[x])",
"-",
"- def diff(self, x, y):",
"- if self.find(x) != self.find(y):",
"- raise Exception('\"{}\" belongs to a different tree from \"{}\"'.format(x, y))",
"- return self.find_position(y) - self.find_position(x)",
"+ self.parents[x] += self.parents[y]",
"+ self.parents[y] = x",
"-N, K, L = map(int, input().split())",
"-uf1 = WeightedUnionFind(N)",
"-uf2 = WeightedUnionFind(N)",
"-for _ in range(K):",
"- p, q = map(int, input().split())",
"- uf1.union(p - 1, q - 1, 0)",
"-for _ in range(L):",
"- r, s = map(int, input().split())",
"- uf2.union(r - 1, s - 1, 0)",
"-path = [None] * N",
"-for i in range(N):",
"- path[i] = (uf1.find(i), uf2.find(i))",
"-cnt = Counter(path)",
"-for i in range(N - 1):",
"- print(cnt[path[i]], end=\" \")",
"-print(cnt[path[N - 1]])",
"+def main():",
"+ import sys",
"+ from collections import Counter",
"+",
"+ # readline = sys.stdin.readline",
"+ readlines = sys.stdin.readlines",
"+ N, K, L = list(map(int, input().split()))",
"+ uf1 = UnionFind(N)",
"+ uf2 = UnionFind(N)",
"+ IN = readlines()",
"+ for i in range(K):",
"+ p, q = list(map(int, IN[i].split()))",
"+ p -= 1",
"+ q -= 1",
"+ uf1.union(p, q)",
"+ for j in range(K, K + L):",
"+ r, s = list(map(int, IN[j].split()))",
"+ r -= 1",
"+ s -= 1",
"+ # if uf1.find(r) == uf1.find(s):",
"+ uf2.union(r, s)",
"+ # ans = []",
"+ # for i in range(N):",
"+ # ans.append(-uf2.parents[uf2.find(i)])",
"+ # print(*ans)",
"+ path = []",
"+ C = Counter()",
"+ for i in range(N):",
"+ pair = (uf1.find(i), uf2.find(i))",
"+ path.append(pair)",
"+ C[pair] += 1",
"+ ans = []",
"+ for i in range(N):",
"+ ans.append(C[path[i]])",
"+ print((*ans))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.007683 | 0.0315 | 0.243912 | [
"s958195296",
"s723330847"
] |
u102461423 | p04000 | python | s626316867 | s544135143 | 1,781 | 1,533 | 166,856 | 166,892 | Accepted | Accepted | 13.92 | from collections import Counter
import sys
import itertools
input = sys.stdin.readline
c = Counter()
H,W,N = list(map(int,input().split()))
for _ in range(N):
a,b = list(map(int,input().split()))
# そのセルを含む正方形の中心を記録
for dx,dy in itertools.product([-1,0,1],repeat = 2):
aa = a + dx
bb = b + dy
if 2 <= aa <= H-1 and 2 <= bb <= W-1:
c[(aa,bb)] += 1
result = Counter(list(c.values()))
result[0] = (H-2)*(W-2) - sum(result.values())
for j in range(10):
print((result[j])) | from collections import defaultdict, Counter
import sys
import itertools
input = sys.stdin.readline
c = defaultdict(int)
H,W,N = list(map(int,input().split()))
for _ in range(N):
a,b = list(map(int,input().split()))
# そのセルを含む正方形の中心を記録
for dx,dy in itertools.product([-1,0,1],repeat = 2):
aa = a + dx
bb = b + dy
if 2 <= aa <= H-1 and 2 <= bb <= W-1:
c[(aa,bb)] += 1
result = Counter(list(c.values()))
result[0] = (H-2)*(W-2) - sum(result.values())
for j in range(10):
print((result[j]))
| 21 | 21 | 494 | 515 | from collections import Counter
import sys
import itertools
input = sys.stdin.readline
c = Counter()
H, W, N = list(map(int, input().split()))
for _ in range(N):
a, b = list(map(int, input().split()))
# そのセルを含む正方形の中心を記録
for dx, dy in itertools.product([-1, 0, 1], repeat=2):
aa = a + dx
bb = b + dy
if 2 <= aa <= H - 1 and 2 <= bb <= W - 1:
c[(aa, bb)] += 1
result = Counter(list(c.values()))
result[0] = (H - 2) * (W - 2) - sum(result.values())
for j in range(10):
print((result[j]))
| from collections import defaultdict, Counter
import sys
import itertools
input = sys.stdin.readline
c = defaultdict(int)
H, W, N = list(map(int, input().split()))
for _ in range(N):
a, b = list(map(int, input().split()))
# そのセルを含む正方形の中心を記録
for dx, dy in itertools.product([-1, 0, 1], repeat=2):
aa = a + dx
bb = b + dy
if 2 <= aa <= H - 1 and 2 <= bb <= W - 1:
c[(aa, bb)] += 1
result = Counter(list(c.values()))
result[0] = (H - 2) * (W - 2) - sum(result.values())
for j in range(10):
print((result[j]))
| false | 0 | [
"-from collections import Counter",
"+from collections import defaultdict, Counter",
"-c = Counter()",
"+c = defaultdict(int)"
] | false | 0.042609 | 0.043114 | 0.988287 | [
"s626316867",
"s544135143"
] |
u342869120 | p02625 | python | s490249574 | s028248376 | 189 | 89 | 89,772 | 102,856 | Accepted | Accepted | 52.91 |
class Combination:
def __init__(self, n, mod):
fact = [0]*(n+1)
ifact = [0]*(n+1)
fact[0] = 1
for i in range(1, n+1):
fact[i] = (fact[i-1]*i) % mod
# 1/n!を逆元で求める
ifact[n] = pow(fact[n], mod-2, mod)
for i in range(n, 0, -1):
ifact[i-1] = (ifact[i]*i) % mod
self.n = n
self.mod = mod
self.fact = fact
self.ifact = ifact
def c(self, n, r):
if r < 0 or r > n:
return 0
ret = (self.fact[n]*self.ifact[r]) % self.mod
return (ret*self.ifact[n-r]) % self.mod
def p(self, n, r):
if n < r:
return 0
return self.fact[n]*self.ifact[n-r] % self.mod
MOD = 10**9+7
N, M = list(map(int, input().split()))
c = Combination(M, MOD)
ans = 0
for i in range(N+1):
a = (-1)**i * c.c(N, i)*c.p(M, i)*(c.p(M-i, N-i)**2) % MOD
ans = (ans+a) % MOD
print(ans)
| '''
完全順列(derangement)
モンモール数(Montmort number)
'''
MOD = 10**9+7
N, M = list(map(int, input().split()))
# 片方の順列の総数を求める
ans = 1
for i in range(N):
ans *= M-i
ans %= MOD
# M枚からN枚選ぶ完全順列を計算
d = [1, M-N]
for i in range(2, N+1):
# 1がk番目にある
# 1番目にkがある
t = (i-1)*d[-2] % MOD
# 1番目にkがない
t += (M-N+i-1)*d[-1] % MOD
d.append(t)
print((ans*d[-1] % MOD))
| 38 | 25 | 965 | 393 | class Combination:
def __init__(self, n, mod):
fact = [0] * (n + 1)
ifact = [0] * (n + 1)
fact[0] = 1
for i in range(1, n + 1):
fact[i] = (fact[i - 1] * i) % mod
# 1/n!を逆元で求める
ifact[n] = pow(fact[n], mod - 2, mod)
for i in range(n, 0, -1):
ifact[i - 1] = (ifact[i] * i) % mod
self.n = n
self.mod = mod
self.fact = fact
self.ifact = ifact
def c(self, n, r):
if r < 0 or r > n:
return 0
ret = (self.fact[n] * self.ifact[r]) % self.mod
return (ret * self.ifact[n - r]) % self.mod
def p(self, n, r):
if n < r:
return 0
return self.fact[n] * self.ifact[n - r] % self.mod
MOD = 10**9 + 7
N, M = list(map(int, input().split()))
c = Combination(M, MOD)
ans = 0
for i in range(N + 1):
a = (-1) ** i * c.c(N, i) * c.p(M, i) * (c.p(M - i, N - i) ** 2) % MOD
ans = (ans + a) % MOD
print(ans)
| """
完全順列(derangement)
モンモール数(Montmort number)
"""
MOD = 10**9 + 7
N, M = list(map(int, input().split()))
# 片方の順列の総数を求める
ans = 1
for i in range(N):
ans *= M - i
ans %= MOD
# M枚からN枚選ぶ完全順列を計算
d = [1, M - N]
for i in range(2, N + 1):
# 1がk番目にある
# 1番目にkがある
t = (i - 1) * d[-2] % MOD
# 1番目にkがない
t += (M - N + i - 1) * d[-1] % MOD
d.append(t)
print((ans * d[-1] % MOD))
| false | 34.210526 | [
"-class Combination:",
"- def __init__(self, n, mod):",
"- fact = [0] * (n + 1)",
"- ifact = [0] * (n + 1)",
"- fact[0] = 1",
"- for i in range(1, n + 1):",
"- fact[i] = (fact[i - 1] * i) % mod",
"- # 1/n!を逆元で求める",
"- ifact[n] = pow(fact[n], mod - 2, mod)",
"- for i in range(n, 0, -1):",
"- ifact[i - 1] = (ifact[i] * i) % mod",
"- self.n = n",
"- self.mod = mod",
"- self.fact = fact",
"- self.ifact = ifact",
"-",
"- def c(self, n, r):",
"- if r < 0 or r > n:",
"- return 0",
"- ret = (self.fact[n] * self.ifact[r]) % self.mod",
"- return (ret * self.ifact[n - r]) % self.mod",
"-",
"- def p(self, n, r):",
"- if n < r:",
"- return 0",
"- return self.fact[n] * self.ifact[n - r] % self.mod",
"-",
"-",
"+\"\"\"",
"+完全順列(derangement)",
"+モンモール数(Montmort number)",
"+\"\"\"",
"-c = Combination(M, MOD)",
"-ans = 0",
"-for i in range(N + 1):",
"- a = (-1) ** i * c.c(N, i) * c.p(M, i) * (c.p(M - i, N - i) ** 2) % MOD",
"- ans = (ans + a) % MOD",
"-print(ans)",
"+# 片方の順列の総数を求める",
"+ans = 1",
"+for i in range(N):",
"+ ans *= M - i",
"+ ans %= MOD",
"+# M枚からN枚選ぶ完全順列を計算",
"+d = [1, M - N]",
"+for i in range(2, N + 1):",
"+ # 1がk番目にある",
"+ # 1番目にkがある",
"+ t = (i - 1) * d[-2] % MOD",
"+ # 1番目にkがない",
"+ t += (M - N + i - 1) * d[-1] % MOD",
"+ d.append(t)",
"+print((ans * d[-1] % MOD))"
] | false | 0.152375 | 0.103423 | 1.473322 | [
"s490249574",
"s028248376"
] |
u583014768 | p03073 | python | s724389986 | s748860157 | 30 | 22 | 4,268 | 4,268 | Accepted | Accepted | 26.67 | S = list(eval(input()))
c = 0
if S[0] == '0':
for i in S[::2]:
if i == '1':
c += 1
for j in S[1::2]:
if j == '0':
c += 1
d = 0
if S[0] == '1':
for i in S[::2]:
if i == '0':
d += 1
for j in S[1::2]:
if j == '1':
d += 1
print((max(c,d))) | S = list(eval(input()))
s = S[::2].count('1') + S[1::2].count('0')
u = S[::2].count('0') + S[1::2].count('1')
print((min(s, u))) | 21 | 6 | 366 | 127 | S = list(eval(input()))
c = 0
if S[0] == "0":
for i in S[::2]:
if i == "1":
c += 1
for j in S[1::2]:
if j == "0":
c += 1
d = 0
if S[0] == "1":
for i in S[::2]:
if i == "0":
d += 1
for j in S[1::2]:
if j == "1":
d += 1
print((max(c, d)))
| S = list(eval(input()))
s = S[::2].count("1") + S[1::2].count("0")
u = S[::2].count("0") + S[1::2].count("1")
print((min(s, u)))
| false | 71.428571 | [
"-c = 0",
"-if S[0] == \"0\":",
"- for i in S[::2]:",
"- if i == \"1\":",
"- c += 1",
"- for j in S[1::2]:",
"- if j == \"0\":",
"- c += 1",
"-d = 0",
"-if S[0] == \"1\":",
"- for i in S[::2]:",
"- if i == \"0\":",
"- d += 1",
"- for j in S[1::2]:",
"- if j == \"1\":",
"- d += 1",
"-print((max(c, d)))",
"+s = S[::2].count(\"1\") + S[1::2].count(\"0\")",
"+u = S[::2].count(\"0\") + S[1::2].count(\"1\")",
"+print((min(s, u)))"
] | false | 0.098621 | 0.036381 | 2.710797 | [
"s724389986",
"s748860157"
] |
u077291787 | p03781 | python | s046029329 | s703515127 | 32 | 17 | 2,940 | 2,940 | Accepted | Accepted | 46.88 | # ARC070C - Go Home (ABC056C)
x = int(eval(input()))
for i in range(1, x + 1):
if i * (i + 1) * 0.5 >= x:
print(i)
break | from math import ceil
x = int(eval(input()))
print((ceil((-1 + (8 * x + 1) ** 0.5) * 0.5))) | 6 | 3 | 139 | 85 | # ARC070C - Go Home (ABC056C)
x = int(eval(input()))
for i in range(1, x + 1):
if i * (i + 1) * 0.5 >= x:
print(i)
break
| from math import ceil
x = int(eval(input()))
print((ceil((-1 + (8 * x + 1) ** 0.5) * 0.5)))
| false | 50 | [
"-# ARC070C - Go Home (ABC056C)",
"+from math import ceil",
"+",
"-for i in range(1, x + 1):",
"- if i * (i + 1) * 0.5 >= x:",
"- print(i)",
"- break",
"+print((ceil((-1 + (8 * x + 1) ** 0.5) * 0.5)))"
] | false | 0.036461 | 0.081656 | 0.44652 | [
"s046029329",
"s703515127"
] |
u708211626 | p04012 | python | s246688975 | s477588195 | 26 | 21 | 9,000 | 9,080 | Accepted | Accepted | 19.23 | w = list(eval(input()))
s = set(w)
for i in s:
if w.count(i)%2 != 0:
print("No")
break
else:
print("Yes")
| a=eval(input());b=set(a)
for i in b:
if a.count(i) % 2 != 0:
print('No')
exit()
print('Yes')
| 9 | 9 | 122 | 113 | w = list(eval(input()))
s = set(w)
for i in s:
if w.count(i) % 2 != 0:
print("No")
break
else:
print("Yes")
| a = eval(input())
b = set(a)
for i in b:
if a.count(i) % 2 != 0:
print("No")
exit()
print("Yes")
| false | 0 | [
"-w = list(eval(input()))",
"-s = set(w)",
"-for i in s:",
"- if w.count(i) % 2 != 0:",
"+a = eval(input())",
"+b = set(a)",
"+for i in b:",
"+ if a.count(i) % 2 != 0:",
"- break",
"-else:",
"- print(\"Yes\")",
"+ exit()",
"+print(\"Yes\")"
] | false | 0.066489 | 0.037377 | 1.778881 | [
"s246688975",
"s477588195"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.