Input:
import sys

from collections import Counter, deque, defaultdict

from itertools import accumulate, permutations, combinations, takewhile, compress, cycle

from functools import reduce

from math import ceil, floor, log10, log2, factorial

from pprint import pprint

sys.setrecursionlimit(1000000)

# MOD = 10 ** 9 + 7

# N = int(input())

# A = [int(x) for x in input().split()]

# V = [[0] * 100 for _ in range(100)]

# A = [int(input()) for _ in range(N)]

N, W = [int(x) for x in input().split()]

dp = [float('inf')] * 1000 * 100*10

vs = set()

vs.add(0)

dp[0] = 0

for i in range(N):

    w, v = [int(x) for x in input().split()]

    tmpDP = dp.copy()

    for vv in list(vs):

        if dp[vv + v] > dp[vv] + w:

            tmpDP[vv + v] = dp[vv] + w

            vs.add(vv + v)

    dp = tmpDP

ans = 0

for v in list(vs):

    if dp[v] <= W:

        ans = max(ans, v)

print(ans)

import sys

from collections import Counter, deque, defaultdict

from itertools import accumulate, permutations, combinations, takewhile, compress, cycle

from functools import reduce

from math import ceil, floor, log10, log2, factorial

from pprint import pprint

sys.setrecursionlimit(1000000)

# MOD = 10 ** 9 + 7

# N = int(input())

# A = [int(x) for x in input().split()]

# V = [[0] * 100 for _ in range(100)]

# A = [int(input()) for _ in range(N)]

N, W = [int(x) for x in input().split()]

dp = defaultdict(lambda: float('inf'))

dp[0] = 0

for i in range(N):

    w, v = [int(x) for x in input().split()]

    add = defaultdict(lambda: float('inf'))

    for vv in list(dp.keys()):

        if dp[vv + v] > dp[vv] + w:

            add[vv + v] = dp[vv] + w

    dp.update(add)

print((max([i for i in list(dp.items()) if i[1] <= W], key=lambda x:x[0])[0]))

import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
N, W = [int(x) for x in input().split()]
dp = [float("inf")] * 1000 * 100 * 10
vs = set()
vs.add(0)
dp[0] = 0
for i in range(N):
    w, v = [int(x) for x in input().split()]
    tmpDP = dp.copy()
    for vv in list(vs):
        if dp[vv + v] > dp[vv] + w:
            tmpDP[vv + v] = dp[vv] + w
            vs.add(vv + v)
    dp = tmpDP
ans = 0
for v in list(vs):
    if dp[v] <= W:
        ans = max(ans, v)
print(ans)

import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
N, W = [int(x) for x in input().split()]
dp = defaultdict(lambda: float("inf"))
dp[0] = 0
for i in range(N):
    w, v = [int(x) for x in input().split()]
    add = defaultdict(lambda: float("inf"))
    for vv in list(dp.keys()):
        if dp[vv + v] > dp[vv] + w:
            add[vv + v] = dp[vv] + w
    dp.update(add)
print((max([i for i in list(dp.items()) if i[1] <= W], key=lambda x: x[0])[0]))

+    add = defaultdict(lambda: float("inf"))

+print((max([i for i in list(dp.items()) if i[1] <= W], key=lambda x: x[0])[0]))


Input:
from math import factorial

N = int(input())

print((factorial(N) % (10**9 + 7)))

from math import factorial

N = int(input())

ans = 1

for i in range(1,N+1):

    ans *= i % (10**9 + 7)

    ans %= 10**9 + 7

print(ans)

from math import factorial

N = int(input())
ans = 1
for i in range(1, N + 1):
    ans *= i % (10**9 + 7)
    ans %= 10**9 + 7
print(ans)


Input:
import math

while True:

	try:

		x,y = list(map(int,input().split()))

		print('%d %d' % (math.gcd(x,y),x/math.gcd(x,y)*y))

	except EOFError:

		break

def gcd(x, y):

    if y == 0:

        return x

    else:

        return gcd(y, x%y)

def lcm(x,y):

    return x/gcd(x, y)*y

while True:

    try:

        x, y = list(map(int, input().split()))

    except EOFError:

        break

    print("%d %d" % (gcd(x, y), lcm(x, y)))

import math

while True:
    try:
        x, y = list(map(int, input().split()))
        print("%d %d" % (math.gcd(x, y), x / math.gcd(x, y) * y))
    except EOFError:
        break

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def lcm(x, y):
    return x / gcd(x, y) * y

while True:
    try:
        x, y = list(map(int, input().split()))
    except EOFError:
        break
    print("%d %d" % (gcd(x, y), lcm(x, y)))

-        print("%d %d" % (math.gcd(x, y), x / math.gcd(x, y) * y))

+    print("%d %d" % (gcd(x, y), lcm(x, y)))


Input:
n = int(input())

r = int(n**.5)

for i in range(r):

  if n % (r-i) == 0:

    print(( (r-i) + n//(r-i) - 2 ))

    break

n = int(input())

s = int(n**.5)

for i in range(s):

  if n % (s-i) == 0:

    print(((s-i) + n // (s-i) - 2))

    break

n = int(input())
r = int(n**0.5)
for i in range(r):
    if n % (r - i) == 0:
        print(((r - i) + n // (r - i) - 2))
        break

n = int(input())
s = int(n**0.5)
for i in range(s):
    if n % (s - i) == 0:
        print(((s - i) + n // (s - i) - 2))
        break


Input:
from collections import Counter

def factorization(n) -> list:

	if n==1:

		return [1]

	ret = []

	i = 2

	while i*i<=n:

		while n%i==0:

			n //= i

			ret.append(i)

		i += 1

	if n!=1:

		ret.append(n)

	return ret

n,m = list(map(int,input().split()))

mod = 10**9+7

if m==1:

	print((1));exit()

factors = Counter(factorization(m))

mx = n+max(factors.values())

fac = [1]*(mx+1)

inv = [1]*(mx+1)

for i in range(1,mx+1):

	fac[i] = fac[i-1] * i % mod

inv[-1] = pow(fac[-1], mod - 2, mod)

for i in range(mx-1, -1, -1):

	inv[i] = inv[i+1] * (i+1) % mod

def cmb(n,r):

	assert n >= r >= 0

	return fac[n] * inv[n-r] * inv[r] % mod

ans=1

for v in list(factors.values()):

	ans*=cmb(n+v-1,v)

	ans%=mod

print(ans)

from collections import Counter

def factorization(n) -> list:

	if n==1:return [1]

	ret = []

	i = 2

	while i*i<=n:

		while n%i==0:

			n //= i

			ret.append(i)

		i += 1

	if n!=1:ret.append(n)

	return ret

from operator import mul

from functools import reduce

def cmb(n,r):

	if n < r:return 0

	r = min(n-r,r)

	if r==0:return 1

	u = reduce(mul, list(range(n, n-r, -1)))

	d = reduce(mul, list(range(1,r+1)))

	return u//d

def main():

	n,m = list(map(int,input().split()))

	mod = 10**9+7

	if m==1:

		print((1))

		exit()

	ans=1

	for v in list(Counter(factorization(m)).values()):

		ans*=cmb(n+v-1,v)

		ans%=mod

	print(ans)

if __name__=="__main__":main()

from collections import Counter

def factorization(n) -> list:
    if n == 1:
        return [1]
    ret = []
    i = 2
    while i * i <= n:
        while n % i == 0:
            n //= i
            ret.append(i)
        i += 1
    if n != 1:
        ret.append(n)
    return ret

n, m = list(map(int, input().split()))
mod = 10**9 + 7
if m == 1:
    print((1))
    exit()
factors = Counter(factorization(m))
mx = n + max(factors.values())
fac = [1] * (mx + 1)
inv = [1] * (mx + 1)
for i in range(1, mx + 1):
    fac[i] = fac[i - 1] * i % mod
inv[-1] = pow(fac[-1], mod - 2, mod)
for i in range(mx - 1, -1, -1):
    inv[i] = inv[i + 1] * (i + 1) % mod

def cmb(n, r):
    assert n >= r >= 0
    return fac[n] * inv[n - r] * inv[r] % mod

ans = 1
for v in list(factors.values()):
    ans *= cmb(n + v - 1, v)
    ans %= mod
print(ans)

from collections import Counter

def factorization(n) -> list:
    if n == 1:
        return [1]
    ret = []
    i = 2
    while i * i <= n:
        while n % i == 0:
            n //= i
            ret.append(i)
        i += 1
    if n != 1:
        ret.append(n)
    return ret

from operator import mul
from functools import reduce

def cmb(n, r):
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    u = reduce(mul, list(range(n, n - r, -1)))
    d = reduce(mul, list(range(1, r + 1)))
    return u // d

def main():
    n, m = list(map(int, input().split()))
    mod = 10**9 + 7
    if m == 1:
        print((1))
        exit()
    ans = 1
    for v in list(Counter(factorization(m)).values()):
        ans *= cmb(n + v - 1, v)
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

-    return fac[n] * inv[n - r] * inv[r] % mod

+    u = reduce(mul, list(range(n, n - r, -1)))

+    d = reduce(mul, list(range(1, r + 1)))

+    n, m = list(map(int, input().split()))

+    for v in list(Counter(factorization(m)).values()):


Input:
K, N = list(map(int, input().split()))

A = list(map(int, input().split()))

diff = A[0] + K - A[-1]

ans = A[-1] - A[0]

for i in range(1, N):

    dist = K - A[i] + A[i - 1]

    if dist < ans:

        ans = dist

print(ans)

import sys

def input():

    return sys.stdin.readline().strip()

def main():

    K, N = list(map(int, input().split()))

    A = list(map(int, input().split()))

    ans = [K - A[i] + A[i - 1] for i in range(1, N)]

    print((min(min(ans), A[-1] - A[0])))

main()

+    return sys.stdin.readline().strip()

+    K, N = list(map(int, input().split()))

+    A = list(map(int, input().split()))

+    ans = [K - A[i] + A[i - 1] for i in range(1, N)]


Input:
import sys

input = lambda: sys.stdin.readline().rstrip()

def resolve():

    A, B, C, X, Y = list(map(int, input().split()))

    ans = float('inf')

    for i in range(0, max(X, Y)*2+1, 2):

        ans = min(A*max(X-i//2, 0)+B*max(Y-i//2, 0)+C*i, ans)

    print(ans)

if __name__ == '__main__':

    resolve()

import sys

input = lambda: sys.stdin.readline().rstrip()

def resolve():

    A, B, C, X, Y = list(map(int, input().split()))

    ans = 0

    if A+B > 2*C:

        ans = 2*C*min(X, Y)+min((A if X>Y else B)*abs(X-Y), 2*C*abs(X-Y))

    else:

        ans = A*X+B*Y

    print(ans)

if __name__ == '__main__':

    resolve()

import sys

input = lambda: sys.stdin.readline().rstrip()

def resolve():
    A, B, C, X, Y = list(map(int, input().split()))
    ans = float("inf")
    for i in range(0, max(X, Y) * 2 + 1, 2):
        ans = min(A * max(X - i // 2, 0) + B * max(Y - i // 2, 0) + C * i, ans)
    print(ans)

if __name__ == "__main__":
    resolve()

import sys

input = lambda: sys.stdin.readline().rstrip()

def resolve():
    A, B, C, X, Y = list(map(int, input().split()))
    ans = 0
    if A + B > 2 * C:
        ans = 2 * C * min(X, Y) + min(
            (A if X > Y else B) * abs(X - Y), 2 * C * abs(X - Y)
        )
    else:
        ans = A * X + B * Y
    print(ans)

if __name__ == "__main__":
    resolve()

-    for i in range(0, max(X, Y) * 2 + 1, 2):

+            (A if X > Y else B) * abs(X - Y), 2 * C * abs(X - Y)


Input:
A,B = list(map(int,input().split()))

ans = 0

for i in range(A,B+1):

    i = str(i)

    if i[0] == i[4]:

        if i[1] == i[3]:

            ans += 1

        else:

            ans += 0

    else:

        ans += 0

print(ans)

A,B = list(map(int,input().split()))

ans = 0

for i in range(A,B+1):

    k = str(i)

    if k[0] == k[4] and k[1] == k[3]:

        ans += 1

print(ans)

A, B = list(map(int, input().split()))
ans = 0
for i in range(A, B + 1):
    i = str(i)
    if i[0] == i[4]:
        if i[1] == i[3]:
            ans += 1
        else:
            ans += 0
    else:
        ans += 0
print(ans)

A, B = list(map(int, input().split()))
ans = 0
for i in range(A, B + 1):
    k = str(i)
    if k[0] == k[4] and k[1] == k[3]:
        ans += 1
print(ans)


Input:
def main():

    N = int(input())

    A = [int(i) for i in input().split()]

    if N == 1:

        return print(1 if A[0] % 2 == 0 else 2)

    ans = 0

    d = (-1, 0, 1)

    from itertools import product

    for i in product(range(3), repeat=N):

        cur = 1

        for j in range(N):

            cur *= (A[j] + d[i[j]])

        if cur % 2 == 0:

            ans += 1

    print(ans)

if __name__ == '__main__':

    main()

def main():

    N = int(input())

    A = [int(i) for i in input().split()]

    ans = 3**N

    cnt = len([a for a in A if a % 2 == 0])

    ans -= 2**cnt

    print(ans)

if __name__ == '__main__':

    main()

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    if N == 1:
        return print(1 if A[0] % 2 == 0 else 2)
    ans = 0
    d = (-1, 0, 1)
    from itertools import product

    for i in product(range(3), repeat=N):
        cur = 1
        for j in range(N):
            cur *= A[j] + d[i[j]]
        if cur % 2 == 0:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = 3**N
    cnt = len([a for a in A if a % 2 == 0])
    ans -= 2**cnt
    print(ans)

if __name__ == "__main__":
    main()

-        return print(1 if A[0] % 2 == 0 else 2)

-    for i in product(range(3), repeat=N):

+    cnt = len([a for a in A if a % 2 == 0])


Input:
# -*- coding: utf-8 -*-

from collections import defaultdict

from itertools import combinations

N = int(input())

C = [0, 0, 0, 0, 0, 0]

D = defaultdict(int)

for i, m in enumerate("MARCH", start=1):

    D[m] = i

for _ in range(N):

    C[D[input()[0]]] += 1

ans = 0

for a, b, c in combinations(list(range(1, 6)), r=3):

    ans += C[a]*C[b]*C[c]

print(ans)

from collections import defaultdict

from itertools import combinations

def inpl(): return list(map(int, input().split()))

C = defaultdict(int)

N = int(input())

for _ in range(N):

    C[input()[0]] += 1

res = 0

for H in combinations("MARCH", r=3):

    res += C[H[0]] * C[H[1]] * C[H[2]]

print(res)

# -*- coding: utf-8 -*-
from collections import defaultdict
from itertools import combinations

N = int(input())
C = [0, 0, 0, 0, 0, 0]
D = defaultdict(int)
for i, m in enumerate("MARCH", start=1):
    D[m] = i
for _ in range(N):
    C[D[input()[0]]] += 1
ans = 0
for a, b, c in combinations(list(range(1, 6)), r=3):
    ans += C[a] * C[b] * C[c]
print(ans)

+    return list(map(int, input().split()))

-for i, m in enumerate("MARCH", start=1):

-for a, b, c in combinations(list(range(1, 6)), r=3):


Input:
import math

N = int(input())

print((math.factorial(N) % (1000000000 + 7)))

import math

N = int(input())

p = 1

for i in range(2, N+1):

  p *= i

  p = p % (1000000000 + 7)

print(p)

import math

N = int(input())
p = 1
for i in range(2, N + 1):
    p *= i
    p = p % (1000000000 + 7)
print(p)


Input:
def main():

    from statistics import median

    n, *a, = list(map(int, open(0).read().split()))

    a = [x - i for i, x in enumerate(a, 1)]

    a.sort()

    m = int(median(a))

    ans = sum([abs(x - m) for x in a])

    print(ans)

if __name__ == '__main__':

    main()

def main():

    n, *a, = list(map(int, open(0).read().split()))

    a = [x - i for i, x in enumerate(a, 1)]

    a.sort()

    if n % 2 == 0:

        ans = sum(a[n // 2:]) - sum(a[:n // 2])

    else:

        ans = sum(a[n // 2 + 1:]) - sum(a[:n // 2])

    print(ans)

if __name__ == '__main__':

    main()

def main():
    from statistics import median

    (
        n,
        *a,
    ) = list(map(int, open(0).read().split()))
    a = [x - i for i, x in enumerate(a, 1)]
    a.sort()
    m = int(median(a))
    ans = sum([abs(x - m) for x in a])
    print(ans)

if __name__ == "__main__":
    main()

def main():
    (
        n,
        *a,
    ) = list(map(int, open(0).read().split()))
    a = [x - i for i, x in enumerate(a, 1)]
    a.sort()
    if n % 2 == 0:
        ans = sum(a[n // 2 :]) - sum(a[: n // 2])
    else:
        ans = sum(a[n // 2 + 1 :]) - sum(a[: n // 2])
    print(ans)

if __name__ == "__main__":
    main()


Input:
N, M = list(map(int, input().split()))

L, R = [], []

low = -float('INF')

high = float('INF')

for i in range(M):

    l, r = list(map(int, input().split()))

    L.append(l)

    R.append(r)

    if l > low:

        low = l

    if r < high:

        high = r

print((max(0, high - low + 1)))

N, M = list(map(int, input().split()))

low = -float('INF')

high = float('INF')

for i in range(M):

    l, r = list(map(int, input().split()))

    if l > low:

        low = l

    if r < high:

        high = r

print((max(0, high - low + 1)))

N, M = list(map(int, input().split()))
L, R = [], []
low = -float("INF")
high = float("INF")
for i in range(M):
    l, r = list(map(int, input().split()))
    L.append(l)
    R.append(r)
    if l > low:
        low = l
    if r < high:
        high = r
print((max(0, high - low + 1)))

N, M = list(map(int, input().split()))
low = -float("INF")
high = float("INF")
for i in range(M):
    l, r = list(map(int, input().split()))
    if l > low:
        low = l
    if r < high:
        high = r
print((max(0, high - low + 1)))

-L, R = [], []
-    L.append(l)
-    R.append(r)


Input:
a,b,c=1,0,0

exec('a,b,c=b,c,(a+c)%(10**9+7);'*(int(input())-2))

print(c)


Input:
a, b, c, x, y = list(map(int, input().split()))

z = max(x,y) * 2

min_sum = c * z

for i in range(z):

    r = max(0, y - i) * b

    t = max(0, x - i) * a

    sum = c * i * 2 + r + t

    if sum < min_sum:

        min_sum = sum

print(min_sum)

a,b,c,x,y = list(map(int, input().split()))

plan_a = c * (2*x) + max(0, y-x) * b

plan_b = c * (2*y) + max(0, x-y) * a

plan_c = a * x + b * y

print((min(plan_a, plan_b, plan_c)))

a, b, c, x, y = list(map(int, input().split()))
z = max(x, y) * 2
min_sum = c * z
for i in range(z):
    r = max(0, y - i) * b
    t = max(0, x - i) * a
    sum = c * i * 2 + r + t
    if sum < min_sum:
        min_sum = sum
print(min_sum)

a, b, c, x, y = list(map(int, input().split()))
plan_a = c * (2 * x) + max(0, y - x) * b
plan_b = c * (2 * y) + max(0, x - y) * a
plan_c = a * x + b * y
print((min(plan_a, plan_b, plan_c)))


Input:
N = int(input())

a = 1

for n in range(2,N+1):

    a = a*n % (10**9+7)

print(a)

def factorial(N):

    a = 1

    for n in range(2,N+1):

        a = a*n % (10**9 + 7)

    return a

if __name__ == '__main__':

    N = int(input())

    print((factorial(N)))

N = int(input())
a = 1
for n in range(2, N + 1):
    a = a * n % (10**9 + 7)
print(a)

def factorial(N):
    a = 1
    for n in range(2, N + 1):
        a = a * n % (10**9 + 7)
    return a

if __name__ == "__main__":
    N = int(input())
    print((factorial(N)))

-N = int(input())
-a = 1
-for n in range(2, N + 1):
-    a = a * n % (10**9 + 7)
-print(a)
+def factorial(N):
+    a = 1
+    for n in range(2, N + 1):
+        a = a * n % (10**9 + 7)
+    return a
+
+
+if __name__ == "__main__":
+    N = int(input())
+    print((factorial(N)))


Input:
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from operator import xor

from functools import reduce

N,K,*A = list(map(int,read().split()))

a = reduce(xor,(1<<a for a in A))

dp = 0 # bitset

for n in range(K):

    if not(dp&(1<<n)):

        dp |= (a<<n)

answer = 'First' if dp&(1<<K) else 'Second'

print(answer)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

N,K,*A = list(map(int,read().split()))

dp = [0]*(K+1) # bitset

for n in range(K):

    if not dp[n]:

        for a in A:

            if n+a>K:

                break

            dp[n+a]=1

answer = 'First' if dp[-1] else 'Second'

print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from operator import xor
from functools import reduce

N, K, *A = list(map(int, read().split()))
a = reduce(xor, (1 << a for a in A))
dp = 0  # bitset
for n in range(K):
    if not (dp & (1 << n)):
        dp |= a << n
answer = "First" if dp & (1 << K) else "Second"
print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K, *A = list(map(int, read().split()))
dp = [0] * (K + 1)  # bitset
for n in range(K):
    if not dp[n]:
        for a in A:
            if n + a > K:
                break
            dp[n + a] = 1
answer = "First" if dp[-1] else "Second"
print(answer)

-answer = "First" if dp & (1 << K) else "Second"

+answer = "First" if dp[-1] else "Second"


Input:
n = int(input())

ans = 0

SQRT = int(n ** 0.5)

for m in range(1,SQRT + 1):

    b = int(n/m)

    ans += m * (m + b) * (b + 1 - m)

ans -= SQRT * (SQRT+1) * (2*SQRT+1) // 6

print(ans)

def main():

  n = int(input())

  ans = 0

  SQRT = int(n ** 0.5)

  for m in range(1,SQRT + 1):

    b = int(n/m)

    ans += m * (m + b) * (b + 1 - m)

  ans -= SQRT * (SQRT+1) * (2*SQRT+1) // 6

  print(ans)

main()

def main():
    n = int(input())
    ans = 0
    SQRT = int(n**0.5)
    for m in range(1, SQRT + 1):
        b = int(n / m)
        ans += m * (m + b) * (b + 1 - m)
    ans -= SQRT * (SQRT + 1) * (2 * SQRT + 1) // 6
    print(ans)

main()


Input:
import math

import collections

N = int(input())

a = math.factorial(N)

check = []

ans = 1

i = 2

while a != 1:

    if a % i == 0:

        a //= i

        check.append(i)

    else:

        i += 1

check = list(collections.Counter(check).values())

for i in check:

    ans *= (i+1)

    ans %= 10**9+7

print(ans)

from math import factorial

N = factorial(int(input()))

i = 2

check = 1

ans = 1

while N != 1:

    if N % i == 0:

        N //= i

        check += 1

    else:

        ans *= check

        check = 1

        i += 1

print(((ans*check)%(10**9+7)))

import math
import collections

N = int(input())
a = math.factorial(N)
check = []
ans = 1
i = 2
while a != 1:
    if a % i == 0:
        a //= i
        check.append(i)
    else:
        i += 1
check = list(collections.Counter(check).values())
for i in check:
    ans *= i + 1
    ans %= 10**9 + 7
print(ans)

from math import factorial

N = factorial(int(input()))
i = 2
check = 1
ans = 1
while N != 1:
    if N % i == 0:
        N //= i
        check += 1
    else:
        ans *= check
        check = 1
        i += 1
print(((ans * check) % (10**9 + 7)))


Input:
A,B,C,X,Y=list(map(int,input().split()))

K=10**9

for i in range(10**5+1):

    S=i*2*C+max(0,X-i)*A+max(0,Y-i)*B

    K=min(K,S)

print(K)

A,B,C,X,Y=list(map(int,input().split()))

a=min(X,Y)*min(A+B,2*C)

a+=max(0,X-Y)*min(A,2*C)

a+=max(0,Y-X)*min(B,2*C)

print(a)

A, B, C, X, Y = list(map(int, input().split()))
K = 10**9
for i in range(10**5 + 1):
    S = i * 2 * C + max(0, X - i) * A + max(0, Y - i) * B
    K = min(K, S)
print(K)

A, B, C, X, Y = list(map(int, input().split()))
a = min(X, Y) * min(A + B, 2 * C)
a += max(0, X - Y) * min(A, 2 * C)
a += max(0, Y - X) * min(B, 2 * C)
print(a)


Input:
S = int(input())

if S >= 3600:

    h=S//3600

    m=S%3600//60

    s=S%60

elif 3600 > S >= 60:

    h=0

    m=S//60

    s=S%60

else:

    h=m=0

    s=S

print(h, m, s, sep=":")


Input:
def main():

	n, ma, mb, *L = list(map(int, open(0).read().split()))

	M = 1<<30

	dp = [[M] * 420 for _ in range(420)]

	dp[0][0] = 0

	for a, b, c in zip(*[iter(L)] * 3):

		for i in range(400, -1, -1):

			for j in range(400, -1, -1):

				t = dp[i][j] + c

				if dp[i + a][j + b] > t:

					dp[i + a][j + b] = t

	ans = M

	_ma, _mb = ma, mb

	while _ma < 410 > _mb:

		ans = min(ans, dp[_ma][_mb])

		_ma += ma

		_mb += mb

	print((ans if ans < M else -1))

if __name__=="__main__":

	main()

def main():

	n, ma, mb, *L = list(map(int, open(0).read().split()))

	M = 1 << 30

	dp = [[M] * 420 for _ in range(420)]

	dp[0][0] = 0

	ua = ub = 15

	for a, b, c in zip(*[iter(L)] * 3):

		for i in range(ua, -1, -1):

			for j in range(ub, -1, -1):

				t = dp[i][j] + c

				if dp[i + a][j + b] > t:

					dp[i + a][j + b] = t

					if ua < i + a:

						ua = i + a

					if ub < j + b:

						ub = j + b

	ans = M

	_ma, _mb = ma, mb

	while _ma < 410 > _mb:

		ans = min(ans, dp[_ma][_mb])

		_ma += ma

		_mb += mb

	print((ans if ans < M else -1))

if __name__ == "__main__":

	main()

def main():
    n, ma, mb, *L = list(map(int, open(0).read().split()))
    M = 1 << 30
    dp = [[M] * 420 for _ in range(420)]
    dp[0][0] = 0
    for a, b, c in zip(*[iter(L)] * 3):
        for i in range(400, -1, -1):
            for j in range(400, -1, -1):
                t = dp[i][j] + c
                if dp[i + a][j + b] > t:
                    dp[i + a][j + b] = t
    ans = M
    _ma, _mb = ma, mb
    while _ma < 410 > _mb:
        ans = min(ans, dp[_ma][_mb])
        _ma += ma
        _mb += mb
    print((ans if ans < M else -1))

if __name__ == "__main__":
    main()

+            for j in range(ub, -1, -1):


Input:
_,s=open(c:=0)

for a in sorted(map(int,s.split())):c=a-c

print(c)

for a in sorted(map(int,[*open(c:=0)][1].split())):c=a-c

print(c)

_, s = open(c := 0)
for a in sorted(map(int, s.split())):
    c = a - c
print(c)

for a in sorted(map(int, [*open(c := 0)][1].split())):
    c = a - c
print(c)

+for a in sorted(map(int, [*open(c := 0)][1].split())):


Input:
s = input()

t = ""

while len(t) < len(s):

    target_len = len(s) - len(t)

    if s[len(t)] == 'd':

        if target_len == 5:

            t += "dream"

        elif target_len == 7:

            t += "dreamer"

        elif target_len > 7:

            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 7 + 1] != "era":

                t += "dreamer"

            else:

                t += "dream"

        else:

            break

    else:

        if target_len == 5:

            t += "erase"

        elif target_len == 6:

            t += "eraser"

        elif target_len > 6:

            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 6 + 2] != "era":

                t += "eraser"

            else:

                t += "erase"

        else:

            break

    if s[0:len(t)] != t:

        break

print(("YES" if s == t else "NO"))

s = input()

div = ["dream", "dreamer", "erase", "eraser"]

rev = []

t = ""

s_rev = s[::-1]

for d in div:

    rev.append(d[::-1])

result = True

i = 0

while i < len(s):

    can_divide = False

    for d in rev:

        if len(s_rev) - i >= len(d) and s_rev[i:i + len(d)] == d:

            can_divide = True

            i += len(d)

            break

    if not can_divide:

        result = False

        break

print(("YES" if result else "NO"))

s = input()
t = ""
while len(t) < len(s):
    target_len = len(s) - len(t)
    if s[len(t)] == "d":
        if target_len == 5:
            t += "dream"
        elif target_len == 7:
            t += "dreamer"
        elif target_len > 7:
            if s[len(t) + 5] != "d" and s[len(t) + 5 : len(t) + 7 + 1] != "era":
                t += "dreamer"
            else:
                t += "dream"
        else:
            break
    else:
        if target_len == 5:
            t += "erase"
        elif target_len == 6:
            t += "eraser"
        elif target_len > 6:
            if s[len(t) + 5] != "d" and s[len(t) + 5 : len(t) + 6 + 2] != "era":
                t += "eraser"
            else:
                t += "erase"
        else:
            break
    if s[0 : len(t)] != t:
        break
print(("YES" if s == t else "NO"))

s = input()
div = ["dream", "dreamer", "erase", "eraser"]
rev = []
t = ""
s_rev = s[::-1]
for d in div:
    rev.append(d[::-1])
result = True
i = 0
while i < len(s):
    can_divide = False
    for d in rev:
        if len(s_rev) - i >= len(d) and s_rev[i : i + len(d)] == d:
            can_divide = True
            i += len(d)
            break
    if not can_divide:
        result = False
        break
print(("YES" if result else "NO"))

+div = ["dream", "dreamer", "erase", "eraser"]

+        if len(s_rev) - i >= len(d) and s_rev[i : i + len(d)] == d:


Input:
from statistics import mean

inputCount = int(input())

prices = [int(input()) for lp in range(inputCount)]

average = mean(prices)

print((int(average)))

inputCount = int(input())

prices = [int(input()) for lp in range(inputCount)]

average = sum(prices) // inputCount

print(average)

-from statistics import mean
-average = mean(prices)
-print((int(average)))
+average = sum(prices) // inputCount
+print(average)


Input:
from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,math,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()

A = sorted(inpl())

B = sorted(inpl())

C = sorted(inpl())

cnt = [0] * n

res = 0

for i,b in enumerate(B):

    c = bisect.bisect_left(C,b+1)

    cnt[i] = n-c

acc = [0]

for x in cnt:

    acc += [acc[-1] + x]

su = sum(cnt)

for i,a in enumerate(A):

    c = bisect.bisect_left(B,a+1)

    res += su - acc[c]

print(res)

from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,math,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()

a = inpl()

b = inpl()

c = inpl()

a.sort()

b.sort()

c.sort()

lb = [0] * n

res = 0

for i in range(n):

    tmp = bisect.bisect_right(b,a[i])

    if tmp == n: continue

    lb[tmp] += 1

llb = list(itertools.accumulate(lb))

# print(lb,llb)

rr = [0] * n

for i in range(n):

    tmp = bisect.bisect_right(c,b[i])

    if tmp == n: continue

    rr[tmp] += llb[i]

print((sum(list(itertools.accumulate(rr)))))

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, math, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")

def inp():
    return int(sys.stdin.readline())

def inpl():
    return list(map(int, sys.stdin.readline().split()))

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())
cnt = [0] * n
res = 0
for i, b in enumerate(B):
    c = bisect.bisect_left(C, b + 1)
    cnt[i] = n - c
acc = [0]
for x in cnt:
    acc += [acc[-1] + x]
su = sum(cnt)
for i, a in enumerate(A):
    c = bisect.bisect_left(B, a + 1)
    res += su - acc[c]
print(res)

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, math, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")

def inp():
    return int(sys.stdin.readline())

def inpl():
    return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
b = inpl()
c = inpl()
a.sort()
b.sort()
c.sort()
lb = [0] * n
res = 0
for i in range(n):
    tmp = bisect.bisect_right(b, a[i])
    if tmp == n:
        continue
    lb[tmp] += 1
llb = list(itertools.accumulate(lb))
# print(lb,llb)
rr = [0] * n
for i in range(n):
    tmp = bisect.bisect_right(c, b[i])
    if tmp == n:
        continue
    rr[tmp] += llb[i]
print((sum(list(itertools.accumulate(rr)))))


Input:
x = int(input())

print((0 if x==1 else 1))

s = input()

if s == '0':

  print((1))

else:

  print((0))

x = int(input())
print((0 if x == 1 else 1))

s = input()
if s == "0":
    print((1))
else:
    print((0))

-x = int(input())
-print((0 if x == 1 else 1))
+s = input()
+if s == "0":
+    print((1))
+else:
+    print((0))


Input:
def binarySearch():

    n = int(input())

    S = set(map(int, input().split()))

    q = int(input())

    T = set(map(int, input().split()))

    print((len(S.intersection(T))))

binarySearch()

def binarySearch():

    n = int(input())

    S = set(input().split())

    q = int(input())

    T = set(input().split())

    print((len(S.intersection(T))))

binarySearch()

-    S = set(map(int, input().split()))
+    S = set(input().split())
-    T = set(map(int, input().split()))
+    T = set(input().split())


Input:
a,b=list(map(int,input().split()))

ans=0

for i in range(a,b+1):

    buf=str(i)

    #print(buf[0:int(len(buf)/2)],buf[int(len(buf)/2+1):])

    str1=buf[0:int(len(buf)/2)]

    str2=buf[int(len(buf)/2+1):]

    if str1[0]==str2[1] and str1[1]==str2[0]:

        ans+=1

print(ans)

a,b=list(map(int,input().split()))

ans=0

for i in range(a,b+1):

    buf=str(i)

    str1=buf[::-1]

    if buf==str1:

        ans+=1

print(ans)

a, b = list(map(int, input().split()))
ans = 0
for i in range(a, b + 1):
    buf = str(i)
    # print(buf[0:int(len(buf)/2)],buf[int(len(buf)/2+1):])
    str1 = buf[0 : int(len(buf) / 2)]
    str2 = buf[int(len(buf) / 2 + 1) :]
    if str1[0] == str2[1] and str1[1] == str2[0]:
        ans += 1
print(ans)

a, b = list(map(int, input().split()))
ans = 0
for i in range(a, b + 1):
    buf = str(i)
    str1 = buf[::-1]
    if buf == str1:
        ans += 1
print(ans)

-    # print(buf[0:int(len(buf)/2)],buf[int(len(buf)/2+1):])

-    str2 = buf[int(len(buf) / 2 + 1) :]


Input:
n, m = list(map(int, input().split()))

RD = list(list(map(int, input().split())) for _ in range(m))

for i in range(1, n + 1):

    ans = 0

    for j in RD:

        ans += j.count(i)

    print(ans)

n, m = list(map(int, input().split()))

NRD = list(0 for i in range(n))

for i in range(m):

    r1, r2 = list(map(int, input().split()))

    NRD[r1 - 1] += 1

    NRD[r2 - 1] += 1

for i in range(n):

    print((NRD[i]))

-RD = list(list(map(int, input().split())) for _ in range(m))

+    r1, r2 = list(map(int, input().split()))


Input:
N = int(input())

x = list(map(int, input().split()))

cnt = 0

for i in x:

  while i % 2 == 0:

    cnt += 1

    i /= 2

print(cnt)

n = int(input())

ans = 0

for i in map(int, input().split()):

    cnt = 0

    while i % 2 == 0:

        i >>= 1

        cnt += 1

    ans += cnt

print(ans)

-N = int(input())
-x = list(map(int, input().split()))
-cnt = 0
-for i in x:
+n = int(input())
+ans = 0
+for i in map(int, input().split()):
+    cnt = 0
+        i >>= 1
-        i /= 2
-print(cnt)
+    ans += cnt
+print(ans)


Input:
def popcount(x):

    x = x - ((x >> 1) & 0x55555555)

    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f

    x = x + (x >> 8)

    x = x + (x >> 16)

    return x & 0x0000007f

cmb=[[0 for i in range(51)] for j in range(51)]

cmb[0][0]=1

for i in range(51):

    for j in range(51):

        if i!=50 and j!=50:

            cmb[i+1][j+1]+=cmb[i][j]

        if i!=50:

            cmb[i+1][j]+=cmb[i][j]

for i in range(1,51):

    for j in range(2,51):

        cmb[i][j]+=cmb[i][j-1]

N,K,T,S=list(map(int,input().split()))

a=list(map(int,input().split()))

must0=[i for i in range(18) if S>>i &1==0]

must1=[i for i in range(18) if T>>i &1==1]

A=[]

for val in a:

    check=True

    for j in must0:

        check=check&(val>>j &1==0)

    for j in must1:

        check=check&(val>>j &1==1)

    if check:

        A.append(val)

if not A:

    print((0))

    exit()

bit=[]

for i in range(18):

    if i not in must0 and i not in must1:

        bit.append(i)

for i in range(len(A)):

    temp=0

    for j in range(len(bit)):

        temp+=(A[i]>>bit[j] &1==1)*2**j

    A[i]=temp

ans=0

n=len(bit)

data=[0]*(2**n)

for i in range(2**n):

    t=set([])

    for a in A:

        data[a&i]+=1

        t.add(a&i)

    temp=0

    for val in t:

        temp+=cmb[data[val]][min(K,data[val])]

    ans+=temp*(-1)**popcount(i)

    for val in t:

        data[val]=0

print(ans)

def popcount(x):

    x = x - ((x >> 1) & 0x55555555)

    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f

    x = x + (x >> 8)

    x = x + (x >> 16)

    return x & 0x0000007f

cmb=[[0 for i in range(51)] for j in range(51)]

cmb[0][0]=1

for i in range(51):

    for j in range(51):

        if i!=50:

            cmb[i+1][j]+=cmb[i][j]

        if j!=50 and i!=50:

            cmb[i+1][j+1]+=cmb[i][j]

for i in range(1,51):

    for j in range(2,51):

        cmb[i][j]+=cmb[i][j-1]

import random

N,K,T,S=list(map(int,input().split()))

a=list(map(int,input().split()))

must0=[i for i in range(18) if S>>i &1==0]

must1=[i for i in range(18) if T>>i &1==1]

A=[]

for val in a:

    check=True

    for j in must0:

        check=check&(val>>j &1==0)

    for j in must1:

        check=check&(val>>j &1==1)

    if check:

        A.append(val)

if not A:

    print((0))

    exit()

bit=[]

for i in range(18):

    if i not in must0 and i not in must1:

        bit.append(i)

for i in range(len(A)):

    temp=0

    for j in range(len(bit)):

        temp+=(A[i]>>bit[j] &1==1)*2**j

    A[i]=temp

ans=0

n=len(bit)

data=[0]*(2**n)

pc=[popcount(i) for i in range(2**n)]

for i in range(2**n):

    for a in A:

        data[a&i]+=1

    for a in A:

        if data[a&i]:

            ans+=cmb[data[a&i]][min(K,data[a&i])]*(-1)**pc[i]

            data[a&i]=0

print(ans)

def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0F0F0F0F
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007F

cmb = [[0 for i in range(51)] for j in range(51)]
cmb[0][0] = 1
for i in range(51):
    for j in range(51):
        if i != 50 and j != 50:
            cmb[i + 1][j + 1] += cmb[i][j]
        if i != 50:
            cmb[i + 1][j] += cmb[i][j]
for i in range(1, 51):
    for j in range(2, 51):
        cmb[i][j] += cmb[i][j - 1]
N, K, T, S = list(map(int, input().split()))
a = list(map(int, input().split()))
must0 = [i for i in range(18) if S >> i & 1 == 0]
must1 = [i for i in range(18) if T >> i & 1 == 1]
A = []
for val in a:
    check = True
    for j in must0:
        check = check & (val >> j & 1 == 0)
    for j in must1:
        check = check & (val >> j & 1 == 1)
    if check:
        A.append(val)
if not A:
    print((0))
    exit()
bit = []
for i in range(18):
    if i not in must0 and i not in must1:
        bit.append(i)
for i in range(len(A)):
    temp = 0
    for j in range(len(bit)):
        temp += (A[i] >> bit[j] & 1 == 1) * 2**j
    A[i] = temp
ans = 0
n = len(bit)
data = [0] * (2**n)
for i in range(2**n):
    t = set([])
    for a in A:
        data[a & i] += 1
        t.add(a & i)
    temp = 0
    for val in t:
        temp += cmb[data[val]][min(K, data[val])]
    ans += temp * (-1) ** popcount(i)
    for val in t:
        data[val] = 0
print(ans)

def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0F0F0F0F
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007F

cmb = [[0 for i in range(51)] for j in range(51)]
cmb[0][0] = 1
for i in range(51):
    for j in range(51):
        if i != 50:
            cmb[i + 1][j] += cmb[i][j]
        if j != 50 and i != 50:
            cmb[i + 1][j + 1] += cmb[i][j]
for i in range(1, 51):
    for j in range(2, 51):
        cmb[i][j] += cmb[i][j - 1]
import random

N, K, T, S = list(map(int, input().split()))
a = list(map(int, input().split()))
must0 = [i for i in range(18) if S >> i & 1 == 0]
must1 = [i for i in range(18) if T >> i & 1 == 1]
A = []
for val in a:
    check = True
    for j in must0:
        check = check & (val >> j & 1 == 0)
    for j in must1:
        check = check & (val >> j & 1 == 1)
    if check:
        A.append(val)
if not A:
    print((0))
    exit()
bit = []
for i in range(18):
    if i not in must0 and i not in must1:
        bit.append(i)
for i in range(len(A)):
    temp = 0
    for j in range(len(bit)):
        temp += (A[i] >> bit[j] & 1 == 1) * 2**j
    A[i] = temp
ans = 0
n = len(bit)
data = [0] * (2**n)
pc = [popcount(i) for i in range(2**n)]
for i in range(2**n):
    for a in A:
        data[a & i] += 1
    for a in A:
        if data[a & i]:
            ans += cmb[data[a & i]][min(K, data[a & i])] * (-1) ** pc[i]
            data[a & i] = 0
print(ans)

+pc = [popcount(i) for i in range(2**n)]

-        temp += cmb[data[val]][min(K, data[val])]

+            ans += cmb[data[a & i]][min(K, data[a & i])] * (-1) ** pc[i]


Input:
import sys

from math import gcd

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

def lcm(x, y):

    return x * y // gcd(x, y)

def main():

    N, M = list(map(int, input().split()))

    A = list(set(map(int, input().split(" "))))

    A = [a // 2 for a in A]

    semi_lcm = 1

    for a in A:

        semi_lcm = lcm(semi_lcm, a)

        if semi_lcm > M:

            print((0))

            return

    for a in A:

        if semi_lcm // a % 2 == 0:

            print((0))

            return

    print(((M // semi_lcm + 1) // 2))

    return

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

def gcd(a, b):

    while b:

        a, b = b, a % b

    return a

def lcm(a, b):

    return a * b // gcd(a, b)

def main():

    N, M, *A = list(map(int, read().split()))

    A = list(set(A))

    B = A.copy()

    while not any(b % 2 for b in B):

        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):

        print((0))

        return

    semi_lcm = 1

    for a in A:

        semi_lcm = lcm(semi_lcm, a // 2)

    print(((M // semi_lcm + 1) // 2))

    return

if __name__ == '__main__':

    main()

import sys
from math import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60

def lcm(x, y):
    return x * y // gcd(x, y)

def main():
    N, M = list(map(int, input().split()))
    A = list(set(map(int, input().split(" "))))
    A = [a // 2 for a in A]
    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a)
        if semi_lcm > M:
            print((0))
            return
    for a in A:
        if semi_lcm // a % 2 == 0:
            print((0))
            return
    print(((M // semi_lcm + 1) // 2))
    return

if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

def main():
    N, M, *A = list(map(int, read().split()))
    A = list(set(A))
    B = A.copy()
    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]
    if not all(b % 2 for b in B):
        print((0))
        return
    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a // 2)
    print(((M // semi_lcm + 1) // 2))
    return

if __name__ == "__main__":
    main()

-    N, M = list(map(int, input().split()))

-    A = list(set(map(int, input().split(" "))))

+    N, M, *A = list(map(int, read().split()))

+        semi_lcm = lcm(semi_lcm, a // 2)


Input:
import sys

sys.setrecursionlimit(10**6)

def dfs(v,p,d):

    for i, j in tree[v]:

        if i != p:

            depth[i] = d + j

            dfs(i,v,d+j)

N = int(input())

tree = [[] for _ in range(N)]

for i in range(N-1):

    a, b, c = list(map(int, input().split()))

    a -= 1

    b -= 1

    tree[a].append((b,c))

    tree[b].append((a,c))

Q, K = list(map(int, input().split()))

depth = [0 for i in range(N)]

depth[K-1] = 0

dfs(K-1,-1,0)

for _ in range(Q):

    x, y = list(map(int, input().split()))

    print((depth[x-1] + depth[y-1]))

import heapq

import sys

input = sys.stdin.readline

def dijkstra(s, edge, N):

    d = [float('inf')] * N

    used = [True] * N

    d[s] = 0

    used[s] = False

    edgelist = []

    for a, b in edge[s]:

        heapq.heappush(edgelist, a * (10 ** 6) + b)

    while len(edgelist):

        minedge = heapq.heappop(edgelist)

        if not used[minedge%(10 ** 6)]:

            continue

        v = minedge % (10 ** 6)

        d[v] = minedge // (10 ** 6)

        used[v] = False

        for e in edge[v]:

            if used[e[1]]:

                heapq.heappush(edgelist, (e[0] + d[v]) * (10 ** 6) + e[1])

    return d

def main():

    N = int(input())

    edge = [[] for _ in range(N)]

    for _ in range(N-1):

        a, b, c = list(map(int, input().split()))

        a -= 1

        b -= 1

        edge[a].append([c,b])

        edge[b].append([c,a])

    Q, K = list(map(int, input().split()))

    K -= 1

    d = dijkstra(K, edge, N)

    for _ in range(Q):

        x, y = list(map(int, input().split()))

        x -= 1

        y -= 1

        print((d[x] + d[y]))

if __name__ == "__main__":

    main()

import sys

sys.setrecursionlimit(10**6)

def dfs(v, p, d):
    for i, j in tree[v]:
        if i != p:
            depth[i] = d + j
            dfs(i, v, d + j)

N = int(input())
tree = [[] for _ in range(N)]
for i in range(N - 1):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    tree[a].append((b, c))
    tree[b].append((a, c))
Q, K = list(map(int, input().split()))
depth = [0 for i in range(N)]
depth[K - 1] = 0
dfs(K - 1, -1, 0)
for _ in range(Q):
    x, y = list(map(int, input().split()))
    print((depth[x - 1] + depth[y - 1]))

import heapq
import sys

input = sys.stdin.readline

def dijkstra(s, edge, N):
    d = [float("inf")] * N
    used = [True] * N
    d[s] = 0
    used[s] = False
    edgelist = []
    for a, b in edge[s]:
        heapq.heappush(edgelist, a * (10**6) + b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge % (10**6)]:
            continue
        v = minedge % (10**6)
        d[v] = minedge // (10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1])
    return d

def main():
    N = int(input())
    edge = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        edge[a].append([c, b])
        edge[b].append([c, a])
    Q, K = list(map(int, input().split()))
    K -= 1
    d = dijkstra(K, edge, N)
    for _ in range(Q):
        x, y = list(map(int, input().split()))
        x -= 1
        y -= 1
        print((d[x] + d[y]))

if __name__ == "__main__":
    main()

+        heapq.heappush(edgelist, a * (10**6) + b)

+        minedge = heapq.heappop(edgelist)

+        if not used[minedge % (10**6)]:

+                heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1])

-    a, b, c = list(map(int, input().split()))

-    x, y = list(map(int, input().split()))

-    print((depth[x - 1] + depth[y - 1]))

+        a, b, c = list(map(int, input().split()))

+    Q, K = list(map(int, input().split()))

+        x, y = list(map(int, input().split()))


Input:
import math

n = int(input())

power = math.factorial(n)

print((power % (10**9 + 7)))

import math

n = int(input())

power = 1

for i in range(1, n+1):

    power = i * power % (10**9 + 7)

print(power)

import math

n = int(input())
power = 1
for i in range(1, n + 1):
    power = i * power % (10**9 + 7)
print(power)

-power = math.factorial(n)
-print((power % (10**9 + 7)))
+power = 1
+for i in range(1, n + 1):
+    power = i * power % (10**9 + 7)
+print(power)


Input:
import math

n = int(input())

print((math.factorial(n)%(10**9+7)))

n = int(input())

pw = 1

for i in range(n):

  pw *= (i+1)

  pw %= 10**9+7

print(pw)

import math

n = int(input())
print((math.factorial(n) % (10**9 + 7)))

n = int(input())
pw = 1
for i in range(n):
    pw *= i + 1
    pw %= 10**9 + 7
print(pw)

-print((math.factorial(n) % (10**9 + 7)))


Input:
import heapq

N = int(input())

abc = [list(map(int,input().split())) for _ in range(N-1)]

Q,K = list(map(int,input().split()))

xy = [list(map(int,input().split())) for _ in range(Q)]

connect = [[] for _ in range(N)]

INFTY = 10**15

for a,b,c in abc:

    connect[a-1].append([b-1,c])

    connect[b-1].append([a-1,c])

cost = [[INFTY,False] for _  in range(N)]

cost[K-1][0] = 0

q = [(0,K-1)]

while q:

    _,i = heapq.heappop(q)

    if cost[i][1]:

        continue

    cost[i][1] = True

    ci0 = cost[i][0]

    for j,c in connect[i]:

        if cost[j][1]:

            continue

        tmp_cost = ci0+c

        if tmp_cost < cost[j][0]:

            cost[j][0] = tmp_cost

            heapq.heappush(q,(tmp_cost,j))

for x,y in xy:

    print((cost[x-1][0] + cost[y-1][0]))

N = int(input())

ABC = [list(map(int,input().split())) for _ in [0]*(N-1)]

Q,K = list(map(int,input().split()))

XY = [list(map(int,input().split())) for _ in [0]*Q]

E = [{} for _ in [0]*N]

for a,b,c in ABC:

    E[a-1][b-1] = c

    E[b-1][a-1] = c

def dist_dfs_tree(N,E,start):

    d = [-1]*N

    d[start] = 0

    q = [start]

    while q:

        i = q.pop()

        ci = d[i]

        for j,cj in list(E[i].items()):

            if d[j] !=-1:continue

            d[j] = ci+cj

            q.append(j)

    return d

d = dist_dfs_tree(N,E,K-1)

for x,y in XY:

    print((d[x-1]+d[y-1]))

import heapq

N = int(input())
abc = [list(map(int, input().split())) for _ in range(N - 1)]
Q, K = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(Q)]
connect = [[] for _ in range(N)]
INFTY = 10**15
for a, b, c in abc:
    connect[a - 1].append([b - 1, c])
    connect[b - 1].append([a - 1, c])
cost = [[INFTY, False] for _ in range(N)]
cost[K - 1][0] = 0
q = [(0, K - 1)]
while q:
    _, i = heapq.heappop(q)
    if cost[i][1]:
        continue
    cost[i][1] = True
    ci0 = cost[i][0]
    for j, c in connect[i]:
        if cost[j][1]:
            continue
        tmp_cost = ci0 + c
        if tmp_cost < cost[j][0]:
            cost[j][0] = tmp_cost
            heapq.heappush(q, (tmp_cost, j))
for x, y in xy:
    print((cost[x - 1][0] + cost[y - 1][0]))

N = int(input())
ABC = [list(map(int, input().split())) for _ in [0] * (N - 1)]
Q, K = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in [0] * Q]
E = [{} for _ in [0] * N]
for a, b, c in ABC:
    E[a - 1][b - 1] = c
    E[b - 1][a - 1] = c

def dist_dfs_tree(N, E, start):
    d = [-1] * N
    d[start] = 0
    q = [start]
    while q:
        i = q.pop()
        ci = d[i]
        for j, cj in list(E[i].items()):
            if d[j] != -1:
                continue
            d[j] = ci + cj
            q.append(j)
    return d

d = dist_dfs_tree(N, E, K - 1)
for x, y in XY:
    print((d[x - 1] + d[y - 1]))

+ABC = [list(map(int, input().split())) for _ in [0] * (N - 1)]

+XY = [list(map(int, input().split())) for _ in [0] * Q]

-abc = [list(map(int, input().split())) for _ in range(N - 1)]

-xy = [list(map(int, input().split())) for _ in range(Q)]

-cost = [[INFTY, False] for _ in range(N)]

-            heapq.heappush(q, (tmp_cost, j))

+        for j, cj in list(E[i].items()):


Input:
A,B = list(map(int,input().split()))

def kaibun(n):

	key = 0

	for i in range(1,n+1):

		if str(i) == str(i)[::-1]:

			key += 1

	return key

print((kaibun(B)-kaibun(A-1)))

A,B = list(map(int,input().split()))

def kaibun(m, n):

	key = 0

	for i in range(m,n+1):

		if str(i) == str(i)[::-1]:

			key += 1

	return key

print((kaibun(A,B)))

A, B = list(map(int, input().split()))

def kaibun(n):
    key = 0
    for i in range(1, n + 1):
        if str(i) == str(i)[::-1]:
            key += 1
    return key

print((kaibun(B) - kaibun(A - 1)))

A, B = list(map(int, input().split()))

def kaibun(m, n):
    key = 0
    for i in range(m, n + 1):
        if str(i) == str(i)[::-1]:
            key += 1
    return key

print((kaibun(A, B)))

-def kaibun(n):
+def kaibun(m, n):
-    for i in range(1, n + 1):
+    for i in range(m, n + 1):
-print((kaibun(B) - kaibun(A - 1)))
+print((kaibun(A, B)))


Input:
from sys import stdin

def solve():

    s = int(stdin.readline())

    mod = 10**9+7

    if s < 3: return 0

    dp = [0]*(s+1)

    dp[0] = 1

    for i in range(3,s+1):

        for x in range(3,i+1):

            if x in [i-1,i-2]:

                continue

            dp[i] += dp[i-x]

    return dp[s]%mod

print((solve()))

from sys import stdin

def solve():

    s = int(stdin.readline())

    mod = 10**9+7

    if s < 3: return 0

    dp = [0]*(s+1)

    dp[0] = 1

    for i in range(3,s+1):

        dp[i] = dp[i-1] + dp[i-3]

    return dp[s]%mod

print((solve()))

from sys import stdin

def solve():
    s = int(stdin.readline())
    mod = 10**9 + 7
    if s < 3:
        return 0
    dp = [0] * (s + 1)
    dp[0] = 1
    for i in range(3, s + 1):
        for x in range(3, i + 1):
            if x in [i - 1, i - 2]:
                continue
            dp[i] += dp[i - x]
    return dp[s] % mod

print((solve()))

from sys import stdin

def solve():
    s = int(stdin.readline())
    mod = 10**9 + 7
    if s < 3:
        return 0
    dp = [0] * (s + 1)
    dp[0] = 1
    for i in range(3, s + 1):
        dp[i] = dp[i - 1] + dp[i - 3]
    return dp[s] % mod

print((solve()))

-        for x in range(3, i + 1):
-            if x in [i - 1, i - 2]:
-                continue
-            dp[i] += dp[i - x]
+        dp[i] = dp[i - 1] + dp[i - 3]


Input:
N = int(input())

s_list = {}

for i in range(N):

  S = input()

  if S in list(s_list.keys()):

    s_list[S] += 1

  else:

    s_list[S] = 0

max = 0

maxs = []

for s,c in list(s_list.items()):

  if c > max:

    maxs = [s]

    max = c

  elif c == max:

    maxs.append(s)

maxs.sort()

for m in maxs:

  print(m)

from collections import Counter

def solve():

  N = int(input())

  S = [input() for _ in range(N)]

  c = Counter(S)

  M = max(c.values())

  ans = []

  for k,v in c.items():

    if v==M:

      ans.append(k)

  ans.sort()

  return ans

print(*solve(),sep='\n')

N = int(input())
s_list = {}
for i in range(N):
    S = input()
    if S in list(s_list.keys()):
        s_list[S] += 1
    else:
        s_list[S] = 0
max = 0
maxs = []
for s, c in list(s_list.items()):
    if c > max:
        maxs = [s]
        max = c
    elif c == max:
        maxs.append(s)
maxs.sort()
for m in maxs:
    print(m)

from collections import Counter

def solve():
    N = int(input())
    S = [input() for _ in range(N)]
    c = Counter(S)
    M = max(c.values())
    ans = []
    for k, v in c.items():
        if v == M:
            ans.append(k)
    ans.sort()
    return ans

print(*solve(), sep="\n")

-N = int(input())
-s_list = {}
-for i in range(N):
-    S = input()
-    if S in list(s_list.keys()):
-        s_list[S] += 1
-    else:
-        s_list[S] = 0
-max = 0
-maxs = []
-for s, c in list(s_list.items()):
-    if c > max:
-        maxs = [s]
-        max = c
-    elif c == max:
-        maxs.append(s)
-maxs.sort()
-for m in maxs:
-    print(m)
+from collections import Counter
+
+
+def solve():
+    N = int(input())
+    S = [input() for _ in range(N)]
+    c = Counter(S)
+    M = max(c.values())
+    ans = []
+    for k, v in c.items():
+        if v == M:
+            ans.append(k)
+    ans.sort()
+    return ans
+
+
+print(*solve(), sep="\n")


Input:
import math

x = int(input())

print((math.factorial(x) % (10**9 + 7)))

M = 1000000007

n=int(input())

f = 1

for i in range(1, n + 1):

    f = (f * i) % M

print(f)

M = 1000000007
n = int(input())
f = 1
for i in range(1, n + 1):
    f = (f * i) % M
print(f)

-print((math.factorial(x) % (10**9 + 7)))


Input:
S = input()

N = len(S)

left = S[:int(N/2)]

right = S[int((N+2)/2):]

S_reversed = "".join(reversed(list(S)))

left_reversed = "".join(reversed(list(left)))

right_reversed = "".join(reversed(list(right)))

if S == S_reversed and left == left_reversed and right == right_reversed:

    print("Yes")

else:

    print("No")

S = input()

N = len(S)

left = S[:int(N/2)]

right = S[int((N+2)/2):]

if S == S[::-1] and left == left[::-1] and right == right[::-1]:

    print("Yes")

else:

    print("No")

S = input()
N = len(S)
left = S[: int(N / 2)]
right = S[int((N + 2) / 2) :]
S_reversed = "".join(reversed(list(S)))
left_reversed = "".join(reversed(list(left)))
right_reversed = "".join(reversed(list(right)))
if S == S_reversed and left == left_reversed and right == right_reversed:
    print("Yes")
else:
    print("No")

S = input()
N = len(S)
left = S[: int(N / 2)]
right = S[int((N + 2) / 2) :]
if S == S[::-1] and left == left[::-1] and right == right[::-1]:
    print("Yes")
else:
    print("No")

-if S == S_reversed and left == left_reversed and right == right_reversed:

+if S == S[::-1] and left == left[::-1] and right == right[::-1]:


Input:
a,b=list(map(int,input().split()))

ans=0

for i in range(b+1)[a:]:

  if len(str(i))%2==0:

    p=list(str(i))[:len(str(i))//2]

    q=list(reversed(list(str(i))[len(str(i))//2:]))

    if p==q:

      ans+=1

  else:

    s=list(str(i))[:len(str(i))//2+1]

    d=list(reversed(list(str(i))[len(str(i))//2:]))

    if s==d:

      ans += 1

print(ans)

a,s=list(map(int,input().split()))

ad=0

for i in range(a,s+1):

  if str(i)==str(i)[::-1]:ad+=1

print(ad)

a, b = list(map(int, input().split()))
ans = 0
for i in range(b + 1)[a:]:
    if len(str(i)) % 2 == 0:
        p = list(str(i))[: len(str(i)) // 2]
        q = list(reversed(list(str(i))[len(str(i)) // 2 :]))
        if p == q:
            ans += 1
    else:
        s = list(str(i))[: len(str(i)) // 2 + 1]
        d = list(reversed(list(str(i))[len(str(i)) // 2 :]))
        if s == d:
            ans += 1
print(ans)

a, s = list(map(int, input().split()))
ad = 0
for i in range(a, s + 1):
    if str(i) == str(i)[::-1]:
        ad += 1
print(ad)

-        p = list(str(i))[: len(str(i)) // 2]

-        q = list(reversed(list(str(i))[len(str(i)) // 2 :]))

-        d = list(reversed(list(str(i))[len(str(i)) // 2 :]))


Input:
import sys

import itertools

# import numpy as np

import time

import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from functools import reduce

# from math import *

from math import *

N, M = list(map(int, readline().split()))

A = list(sorted([int(x) // 2 for x in readline().split()]))

min_cm = reduce(lambda a, b: (a * b) // gcd(a, b), A)

# print(all(map(lambda x: (min_cm // x) % 2 == 1, A)))

if not all([(min_cm // x) % 2 == 1 for x in A]):

    print((0))

    exit(0)

if min_cm > M:

    print((0))

    exit(0)

ans = (M // min_cm + 1) // 2

print(ans)

import sys

import itertools

# import numpy as np

import time

import math

import heapq

from collections import defaultdict

sys.setrecursionlimit(10 ** 7)

INF = 10 ** 9 + 7

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N, M = list(map(int, input().split()))

A = list([int(x) // 2 for x in input().split()])

def f(n):

    res = 0

    while n % 2 == 0:

        n //= 2

        res += 1

    return res

def gcd(a, b):

    if b == 0:

        return a

    return gcd(b, a % b)

x = f(A[0])

for a in A:

    y = f(a)

    if y != x:

        print((0))

        exit()

lcm = A[0]

for i in range(1, N):

    lcm = lcm * A[i] //  gcd(lcm, A[i])

print(((M // lcm + 1) // 2))

import sys
import itertools

# import numpy as np
import time
import math

sys.setrecursionlimit(10**7)
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import reduce

# from math import *
from math import *

N, M = list(map(int, readline().split()))
A = list(sorted([int(x) // 2 for x in readline().split()]))
min_cm = reduce(lambda a, b: (a * b) // gcd(a, b), A)
# print(all(map(lambda x: (min_cm // x) % 2 == 1, A)))
if not all([(min_cm // x) % 2 == 1 for x in A]):
    print((0))
    exit(0)
if min_cm > M:
    print((0))
    exit(0)
ans = (M // min_cm + 1) // 2
print(ans)

import sys
import itertools

# import numpy as np
import time
import math
import heapq
from collections import defaultdict

sys.setrecursionlimit(10**7)
INF = 10**9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, M = list(map(int, input().split()))
A = list([int(x) // 2 for x in input().split()])

def f(n):
    res = 0
    while n % 2 == 0:
        n //= 2
        res += 1
    return res

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

x = f(A[0])
for a in A:
    y = f(a)
    if y != x:
        print((0))
        exit()
lcm = A[0]
for i in range(1, N):
    lcm = lcm * A[i] // gcd(lcm, A[i])
print(((M // lcm + 1) // 2))

+A = list([int(x) // 2 for x in input().split()])

-N, M = list(map(int, readline().split()))

-A = list(sorted([int(x) // 2 for x in readline().split()]))

-min_cm = reduce(lambda a, b: (a * b) // gcd(a, b), A)

-# print(all(map(lambda x: (min_cm // x) % 2 == 1, A)))

-if not all([(min_cm // x) % 2 == 1 for x in A]):


Input:
while int(input()) > 0:

    s = sorted(map(int, input().split()))

    print((min(abs(a - b) for (a, b) in zip(s, s[1:]))))

while True:

    if int(input()) == 0:

        break

    s = sorted(map(int, input().split()))

    r = min(abs(x - y) for (x, y) in zip(s, s[1:]))

    print(r)

-    print((min(abs(a - b) for (a, b) in zip(s, s[1:]))))

+    r = min(abs(x - y) for (x, y) in zip(s, s[1:]))


Input:
# ABC150 D

si = lambda: input()

ni = lambda: int(input())

nm = lambda: list(map(int, input().split()))

nl = lambda: list(map(int, input().split()))

from math import gcd

from math import ceil

def lcm(x, y):

    return (x * y) // gcd(x, y)

n,m=nm()

a=nl()

ans=0

a=[x//2 for x in a]

lcm_v=a[0]

for i in range(n):

    lcm_v=lcm(lcm_v,a[i])

ok_flg=[(lcm_v//i)%2==1 for i in a]

if all(ok_flg):

    ans=((m//lcm_v)+1)//2

print(ans)

from math import gcd, ceil

def lcm(a, b):

    return (a*b)//gcd(a, b)

n, m = list(map(int, input().split()))

a = list(map(int, input().split()))

for i in range(n):

    a[i] = a[i]//2

lcm_v = a[0]

for i in range(1, n):

    lcm_v = lcm(lcm_v, a[i])

ok = True

for aa in a:

    if (lcm_v//aa) % 2 != 1:

        ok = False

        break

ans = 0

if ok:

    ans = ((m//lcm_v)+1)//2

print(ans)

# ABC150 D
si = lambda: input()
ni = lambda: int(input())
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
from math import gcd
from math import ceil

def lcm(x, y):
    return (x * y) // gcd(x, y)

n, m = nm()
a = nl()
ans = 0
a = [x // 2 for x in a]
lcm_v = a[0]
for i in range(n):
    lcm_v = lcm(lcm_v, a[i])
ok_flg = [(lcm_v // i) % 2 == 1 for i in a]
if all(ok_flg):
    ans = ((m // lcm_v) + 1) // 2
print(ans)

from math import gcd, ceil

def lcm(a, b):
    return (a * b) // gcd(a, b)

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
    a[i] = a[i] // 2
lcm_v = a[0]
for i in range(1, n):
    lcm_v = lcm(lcm_v, a[i])
ok = True
for aa in a:
    if (lcm_v // aa) % 2 != 1:
        ok = False
        break
ans = 0
if ok:
    ans = ((m // lcm_v) + 1) // 2
print(ans)

-nm = lambda: list(map(int, input().split()))

-nl = lambda: list(map(int, input().split()))

-ok_flg = [(lcm_v // i) % 2 == 1 for i in a]


Input:
def main():

    while True:

        n, x = tuple(map(int, input().split()))

        pattern = 0

        if n == x == 0:

            break

        else:

            for a in range(1, n+1):

                for b in range(1, a):

                    for c in range(1, b):

                        pattern += 1 if a + b + c == x and a > b > c else 0

            print(pattern)

if __name__ == '__main__':

    main()

def divide_two(c, z):

    min_b = z // 2 + 1

    max_b = min(c-1, z-1)

    return max(max_b-min_b+1, 0)

num_set = []

cnt = 0

while True:

    n, x = list(map(int, input().split()))

    if (n, x) == (0, 0):

        break

    else:

        num_set.append((n, x))

        cnt += 1

for i in range(cnt):

    num_count = 0

    (n, x) = num_set[i]

    for c in range(x//3, n+1):

        num_count += divide_two(c, x-c)

    print(num_count)

def main():
    while True:
        n, x = tuple(map(int, input().split()))
        pattern = 0
        if n == x == 0:
            break
        else:
            for a in range(1, n + 1):
                for b in range(1, a):
                    for c in range(1, b):
                        pattern += 1 if a + b + c == x and a > b > c else 0
            print(pattern)

if __name__ == "__main__":
    main()

def divide_two(c, z):
    min_b = z // 2 + 1
    max_b = min(c - 1, z - 1)
    return max(max_b - min_b + 1, 0)

num_set = []
cnt = 0
while True:
    n, x = list(map(int, input().split()))
    if (n, x) == (0, 0):
        break
    else:
        num_set.append((n, x))
        cnt += 1
for i in range(cnt):
    num_count = 0
    (n, x) = num_set[i]
    for c in range(x // 3, n + 1):
        num_count += divide_two(c, x - c)
    print(num_count)

-        n, x = tuple(map(int, input().split()))

-                    for c in range(1, b):

-                        pattern += 1 if a + b + c == x and a > b > c else 0

+    n, x = list(map(int, input().split()))

+        num_count += divide_two(c, x - c)


Input:
A, B = list(map(int, input().split()))

numbers = list(range(A, B+1))

count = 0

for i in numbers:

    m = str(i)

    rm = ''.join(list(reversed(m)))

    if m == rm:

        count += 1

print(count)

A, B = list(map(int, input().split()))

x = list(range(1,10))

y = list(range(10))

count = 0

for p in x:

    for q in y:

        for r in y:

            sakasama = int(str(p)+str(q)+str(r)+str(q)+str(p))

            if A <= sakasama <= B:

                count += 1

print(count)

A, B = list(map(int, input().split()))
numbers = list(range(A, B + 1))
count = 0
for i in numbers:
    m = str(i)
    rm = "".join(list(reversed(m)))
    if m == rm:
        count += 1
print(count)

A, B = list(map(int, input().split()))
x = list(range(1, 10))
y = list(range(10))
count = 0
for p in x:
    for q in y:
        for r in y:
            sakasama = int(str(p) + str(q) + str(r) + str(q) + str(p))
            if A <= sakasama <= B:
                count += 1
print(count)

+            sakasama = int(str(p) + str(q) + str(r) + str(q) + str(p))


Input:
import sys

from operator import itemgetter

from heapq import heapify, heappop, heappush

MAX_INT = int(10e15)

MIN_INT = -MAX_INT

mod = 1000000007

sys.setrecursionlimit(1000000)

def IL(): return list(map(int,input().split()))

def SL(): return input().split()

def I(): return int(sys.stdin.readline())

def S(): return input()

N, T = IL()

ab = [IL() for i in range(N)]

ab.sort(key=itemgetter(0))

#print(ab)

dp = [[0]*(T+1+3000+1) for _ in range(N+1)]

ans = 0

for i in range(N):

  for j in range(T+1+3000+1):

    time, deli = ab[i]

    if 0 <= j-time < T:

      dp[i + 1][j] = max(dp[i][j], dp[i][j - time] + deli)

    else:

      dp[i + 1][j] = dp[i][j]

    ans = max(ans, dp[i + 1][j])

print(ans)

#print(dp)

import sys

from collections import deque

MAX_INT = int(10e10)

MIN_INT = -MAX_INT

mod = 1000000007

sys.setrecursionlimit(1000000)

def IL(): return list(map(int,input().split()))

def SL(): return input().split()

def I(): return int(sys.stdin.readline())

def S(): return input()

N,T = IL()

ab = [IL() for i in range(N)]

ab.sort()

ans = 0

dp = [[0]*T for i in range(N+1)]

for i in range(1,N+1):

  a,b = ab[i-1]

  for j in range(T):

    if 0 <= j-a < T:

      dp[i][j] = max(dp[i-1][j], dp[i-1][j-a] + b)

    else:

      dp[i][j] = dp[i-1][j]

  else:

    ans = max(ans, dp[i-1][-1] + b)

print(ans)

import sys
from operator import itemgetter
from heapq import heapify, heappop, heappush

MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)

def IL():
    return list(map(int, input().split()))

def SL():
    return input().split()

def I():
    return int(sys.stdin.readline())

def S():
    return input()

N, T = IL()
ab = [IL() for i in range(N)]
ab.sort(key=itemgetter(0))
# print(ab)
dp = [[0] * (T + 1 + 3000 + 1) for _ in range(N + 1)]
ans = 0
for i in range(N):
    for j in range(T + 1 + 3000 + 1):
        time, deli = ab[i]
        if 0 <= j - time < T:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - time] + deli)
        else:
            dp[i + 1][j] = dp[i][j]
        ans = max(ans, dp[i + 1][j])
print(ans)
# print(dp)

import sys
from collections import deque

MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)

def IL():
    return list(map(int, input().split()))

def SL():
    return input().split()

def I():
    return int(sys.stdin.readline())

def S():
    return input()

N, T = IL()
ab = [IL() for i in range(N)]
ab.sort()
ans = 0
dp = [[0] * T for i in range(N + 1)]
for i in range(1, N + 1):
    a, b = ab[i - 1]
    for j in range(T):
        if 0 <= j - a < T:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a] + b)
        else:
            dp[i][j] = dp[i - 1][j]
    else:
        ans = max(ans, dp[i - 1][-1] + b)
print(ans)

-from heapq import heapify, heappop, heappush

-            dp[i + 1][j] = max(dp[i][j], dp[i][j - time] + deli)


Input:
import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007

# Reference: https://www.geeksforgeeks.org/queries-number-distinct-elements-subarray/

# Python3 code to find number of

# distinct numbers in a subarray

MAX = 1000001

# structure to store queries

class Query:

    def __init__(self, l, r, idx):

        self.l = l

        self.r = r

        self.idx = idx

# updating the bit array

def update(idx, val, bit, n):

    while idx <= n:

        bit[idx] += val

        idx += idx & -idx

# querying the bit array

def query(idx, bit, n):

    summ = 0

    while idx:

        summ += bit[idx]

        idx -= idx & -idx

    return summ

def answeringQueries(arr, n, queries, q):

    # initialising bit array

    bit = [0] * (n + 1)

    # holds the rightmost index of

    # any number as numbers of a[i]

    # are less than or equal to 10^6

    last_visit = [-1] * MAX

    # answer for each query

    ans = [0] * q

    query_counter = 0

    for i in range(n):

        # If last visit is not -1 update -1 at the

        # idx equal to last_visit[arr[i]]

        if last_visit[arr[i]] != -1:

            update(last_visit[arr[i]] + 1, -1, bit, n)

        # Setting last_visit[arr[i]] as i and

        # updating the bit array accordingly

        last_visit[arr[i]] = i

        update(i + 1, 1, bit, n)

        # If i is equal to r of any query store answer

        # for that query in ans[]

        while query_counter < q and queries[query_counter].r == i:

            ans[queries[query_counter].idx] = query(queries[query_counter].r + 1, bit, n) - query(

                queries[query_counter].l, bit, n

            )

            query_counter += 1

    # print answer for each query

    for i in range(q):

        print((ans[i]))

# This code is contributed by

# sanjeev2552

def main():

    N, Q = list(map(int, readline().split()))

    C = list(map(int, readline().split()))

    (*LR,) = list(map(int, read().split()))

    queries = [0] * Q

    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):

        queries[i] = Query(l - 1, r - 1, i)

    queries.sort(key=lambda x: x.r)

    answeringQueries(C, N, queries, Q)

    return

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007

class BIT:

    def __init__(self, n):

        self.n = n

        self.data = [0] * (n + 1)

    def add(self, i, x=1):

        i += 1

        while i <= self.n:

            self.data[i] += x

            i += i & -i

    def get_sum(self, i):

        i += 1

        x = 0

        while i > 0:

            x += self.data[i]

            i -= i & -i

        return x

    # Return sum for [l, r)

    def get_sum_range(self, l, r):

        return self.get_sum(r - 1) - self.get_sum(l - 1)

def main():

    N, Q = map(int, readline().split())

    C = list(map(int, readline().split()))

    LR = map(int, read().split())

    prev = [-1] * (N + 1)

    ps = [[] for _ in range(N)]

    for i, c in enumerate(C):

        if prev[c] != -1:

            ps[prev[c]].append(i)

        prev[c] = i

    qs = [[] for _ in range(N + 1)]

    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):

        l -= 1

        r -= 1

        qs[l].append((r, i))

    ans = [0] * Q

    bit = BIT(N)

    for l in range(N - 1, -1, -1):

        for r in ps[l]:

            bit.add(r)

        for r, i in qs[l]:

            ans[i] = (r - l + 1) - bit.get_sum(r)

    print(*ans, sep='\n')

    return

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
# Reference: https://www.geeksforgeeks.org/queries-number-distinct-elements-subarray/
# Python3 code to find number of
# distinct numbers in a subarray
MAX = 1000001
# structure to store queries
class Query:
    def __init__(self, l, r, idx):
        self.l = l
        self.r = r
        self.idx = idx

# updating the bit array
def update(idx, val, bit, n):
    while idx <= n:
        bit[idx] += val
        idx += idx & -idx

# querying the bit array
def query(idx, bit, n):
    summ = 0
    while idx:
        summ += bit[idx]
        idx -= idx & -idx
    return summ

def answeringQueries(arr, n, queries, q):
    # initialising bit array
    bit = [0] * (n + 1)
    # holds the rightmost index of
    # any number as numbers of a[i]
    # are less than or equal to 10^6
    last_visit = [-1] * MAX
    # answer for each query
    ans = [0] * q
    query_counter = 0
    for i in range(n):
        # If last visit is not -1 update -1 at the
        # idx equal to last_visit[arr[i]]
        if last_visit[arr[i]] != -1:
            update(last_visit[arr[i]] + 1, -1, bit, n)
        # Setting last_visit[arr[i]] as i and
        # updating the bit array accordingly
        last_visit[arr[i]] = i
        update(i + 1, 1, bit, n)
        # If i is equal to r of any query store answer
        # for that query in ans[]
        while query_counter < q and queries[query_counter].r == i:
            ans[queries[query_counter].idx] = query(
                queries[query_counter].r + 1, bit, n
            ) - query(queries[query_counter].l, bit, n)
            query_counter += 1
    # print answer for each query
    for i in range(q):
        print((ans[i]))

# This code is contributed by
# sanjeev2552
def main():
    N, Q = list(map(int, readline().split()))
    C = list(map(int, readline().split()))
    (*LR,) = list(map(int, read().split()))
    queries = [0] * Q
    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):
        queries[i] = Query(l - 1, r - 1, i)
    queries.sort(key=lambda x: x.r)
    answeringQueries(C, N, queries, Q)
    return

if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007

class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get_sum(self, i):
        i += 1
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i & -i
        return x

    # Return sum for [l, r)
    def get_sum_range(self, l, r):
        return self.get_sum(r - 1) - self.get_sum(l - 1)

def main():
    N, Q = map(int, readline().split())
    C = list(map(int, readline().split()))
    LR = map(int, read().split())
    prev = [-1] * (N + 1)
    ps = [[] for _ in range(N)]
    for i, c in enumerate(C):
        if prev[c] != -1:
            ps[prev[c]].append(i)
        prev[c] = i
    qs = [[] for _ in range(N + 1)]
    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):
        l -= 1
        r -= 1
        qs[l].append((r, i))
    ans = [0] * Q
    bit = BIT(N)
    for l in range(N - 1, -1, -1):
        for r in ps[l]:
            bit.add(r)
        for r, i in qs[l]:
            ans[i] = (r - l + 1) - bit.get_sum(r)
    print(*ans, sep="\n")
    return

if __name__ == "__main__":
    main()

+        return self.get_sum(r - 1) - self.get_sum(l - 1)

-def answeringQueries(arr, n, queries, q):

-        # If last visit is not -1 update -1 at the

-        # idx equal to last_visit[arr[i]]

-            update(last_visit[arr[i]] + 1, -1, bit, n)

-        # Setting last_visit[arr[i]] as i and

-        # updating the bit array accordingly

-        # If i is equal to r of any query store answer

-        while query_counter < q and queries[query_counter].r == i:

-            ans[queries[query_counter].idx] = query(

-                queries[query_counter].r + 1, bit, n

-            ) - query(queries[query_counter].l, bit, n)

-    N, Q = list(map(int, readline().split()))

+    N, Q = map(int, readline().split())

-    (*LR,) = list(map(int, read().split()))

-        queries[i] = Query(l - 1, r - 1, i)

+            ans[i] = (r - l + 1) - bit.get_sum(r)


Input:
k = int(input())

num = 0

if not k%2:

    print((-1))

else:

    for i in range(k):

        num = (num*10+7)%k

        if num == 0:

            print((i+1))

            break

    else:

        print((-1))

K = int(input())

ans = 1

num = 0

seven = 7

if not K%2:

    print((-1))

else:

    for i in range(K):

        num = num + seven

        seven = seven*10%K

        num = num%K

        if num == 0:

            print(ans)

            break

        ans += 1

    else:

        print((-1))

k = int(input())
num = 0
if not k % 2:
    print((-1))
else:
    for i in range(k):
        num = (num * 10 + 7) % k
        if num == 0:
            print((i + 1))
            break
    else:
        print((-1))

K = int(input())
ans = 1
num = 0
seven = 7
if not K % 2:
    print((-1))
else:
    for i in range(K):
        num = num + seven
        seven = seven * 10 % K
        num = num % K
        if num == 0:
            print(ans)
            break
        ans += 1
    else:
        print((-1))

-k = int(input())
+K = int(input())
+ans = 1
-if not k % 2:
+seven = 7
+if not K % 2:
-    for i in range(k):
-        num = (num * 10 + 7) % k
+    for i in range(K):
+        num = num + seven
+        seven = seven * 10 % K
+        num = num % K
-            print((i + 1))
+            print(ans)
+        ans += 1


Input:
k = int(input())

count = 1

n = 0

if k % 2 == 0 or k % 5 == 0:

    print((-1))

else:

  while 1:

      n = (n * 10 + 7) % k

      if n == 0:

        break

      count += 1

  print(count)

def main(h):

  count = 1

  n = 0

  for i in range (k):

    n = (n * 10 + 7) % k

    if n == 0:

      print(count)

      return 0

    count += 1

  print((-1))

if __name__ == '__main__':

  k = int(input())

  main(k)

def main(h):
    count = 1
    n = 0
    for i in range(k):
        n = (n * 10 + 7) % k
        if n == 0:
            print(count)
            return 0
        count += 1
    print((-1))

if __name__ == "__main__":
    k = int(input())
    main(k)

-k = int(input())
-count = 1
-n = 0
-if k % 2 == 0 or k % 5 == 0:
-    print((-1))
-else:
-    while 1:
+def main(h):
+    count = 1
+    n = 0
+    for i in range(k):
-            break
+            print(count)
+            return 0
-    print(count)
+    print((-1))
+
+
+if __name__ == "__main__":
+    k = int(input())
+    main(k)


Input:
a, b, c = sorted(map(int, input().split()))

print((c*10 + b + a))

a, b, c = list(map(int, input().split()))

print((max(a, b, c)*9 + (a + b + c)))

a, b, c = sorted(map(int, input().split()))
print((c * 10 + b + a))

a, b, c = list(map(int, input().split()))
print((max(a, b, c) * 9 + (a + b + c)))

-a, b, c = sorted(map(int, input().split()))

+a, b, c = list(map(int, input().split()))


Input:
a, b, c, x, y = list(map(int, input().split()))

ans = float('inf')

for i in range(200005):

    tmp = i * 2 * c

    tmp += max(0, x-i) * a

    tmp += max(0, y-i) * b

    ans = min(ans, tmp)

print(ans)

a, b, c, x, y = list(map(int, input().split()))

ans = float('inf')

for i in range(100005):

    tmp = i * 2 * c

    tmp += max(0, x-i) * a

    tmp += max(0, y-i) * b

    ans = min(ans, tmp)

print(ans)

a, b, c, x, y = list(map(int, input().split()))
ans = float("inf")
for i in range(200005):
    tmp = i * 2 * c
    tmp += max(0, x - i) * a
    tmp += max(0, y - i) * b
    ans = min(ans, tmp)
print(ans)

a, b, c, x, y = list(map(int, input().split()))
ans = float("inf")
for i in range(100005):
    tmp = i * 2 * c
    tmp += max(0, x - i) * a
    tmp += max(0, y - i) * b
    ans = min(ans, tmp)
print(ans)

-for i in range(200005):
+for i in range(100005):


Input:
N = int(input())

As = list(map(int,input().split()))

def dfs(A_s, index,Bss):

    if index == N:

        tmp = 1

        for b in Bss:

            tmp *= b

        return 1 if tmp % 2 == 0 else 0

    b_mi = Bss.copy()

    b_mi.append(A_s[index] - 1)

    b = Bss.copy()

    b.append(A_s[index])

    b_pl = Bss.copy()

    b_pl.append(A_s[index] + 1)

    return dfs(A_s,index + 1, b_mi) + dfs(A_s,index + 1,b) + dfs(A_s,index + 1,b_pl)

print((dfs(As,0,[])))

N = int(input())

As = list(map(int,input().split()))

tmp = 1

for i in range(N):

    if As[i] % 2 == 0:

       tmp *= 2

print((3 ** N - tmp))

N = int(input())
As = list(map(int, input().split()))

def dfs(A_s, index, Bss):
    if index == N:
        tmp = 1
        for b in Bss:
            tmp *= b
        return 1 if tmp % 2 == 0 else 0
    b_mi = Bss.copy()
    b_mi.append(A_s[index] - 1)
    b = Bss.copy()
    b.append(A_s[index])
    b_pl = Bss.copy()
    b_pl.append(A_s[index] + 1)
    return (
        dfs(A_s, index + 1, b_mi) + dfs(A_s, index + 1, b) + dfs(A_s, index + 1, b_pl)
    )

print((dfs(As, 0, [])))

N = int(input())
As = list(map(int, input().split()))
tmp = 1
for i in range(N):
    if As[i] % 2 == 0:
        tmp *= 2
print((3**N - tmp))

-        return 1 if tmp % 2 == 0 else 0

-        dfs(A_s, index + 1, b_mi) + dfs(A_s, index + 1, b) + dfs(A_s, index + 1, b_pl)


Input:
import math

n=int(input())

print((math.factorial(n)%(10**9+7)))

N=int(input())

def fact(n):

    val=1

    for i in range(2,n+1):

        val*=i

        val%=1000000007

    return val

print((fact(N)))

import math

n = int(input())
print((math.factorial(n) % (10**9 + 7)))

N = int(input())

def fact(n):
    val = 1
    for i in range(2, n + 1):
        val *= i
        val %= 1000000007
    return val

print((fact(N)))

-print((math.factorial(n) % (10**9 + 7)))


Input:
n = int(input())

a = list(map(int, input().split()))

tmp = [[e, n - i] for i, e in enumerate(a)]

tmp.sort(reverse=True)

aa = [[e, n - i] for e, i in tmp] + [[0, -1]]

v_prev, i_prev = aa[0]

i = 0

ans = [0] * n

sm = 0

while i < n:

    while aa[i][1] >= i_prev:

        sm += aa[i][0]

        i += 1

    ans[i_prev] += sm - aa[i][0] * i

    sm = aa[i][0] * i

    v_prev, i_prev = aa[i]

print(*ans, sep="\n")

from bisect import bisect_right

n = int(input())

a = list(map(int, input().split()))

li = [[0, -1]]

for i, e in enumerate(a):

    if e > li[-1][0]:

        li.append([e, i])

li = li[::-1]

a.sort()

acc = [0] * (n + 1)

for i in range(n - 1, -1, -1):

    acc[i] = acc[i+1] + a[i]

ans = [0] * n

sub = 0

ans_prev = 0

for (ep, ip), (e, i) in zip(li, li[1:]):

    j = bisect_right(a, e)

    ans[ip] = acc[j] - e * (n - j)

i_prev = 0

for i in range(1, n):

    if ans[i]:

        ans[i_prev] -= ans[i]

        i_prev = i

print(*ans, sep="\n")

from bisect import bisect_right

n = int(input())
a = list(map(int, input().split()))
li = [[0, -1]]
for i, e in enumerate(a):
    if e > li[-1][0]:
        li.append([e, i])
li = li[::-1]
a.sort()
acc = [0] * (n + 1)
for i in range(n - 1, -1, -1):
    acc[i] = acc[i + 1] + a[i]
ans = [0] * n
sub = 0
ans_prev = 0
for (ep, ip), (e, i) in zip(li, li[1:]):
    j = bisect_right(a, e)
    ans[ip] = acc[j] - e * (n - j)
i_prev = 0
for i in range(1, n):
    if ans[i]:
        ans[i_prev] -= ans[i]
        i_prev = i
print(*ans, sep="\n")

-tmp = [[e, n - i] for i, e in enumerate(a)]

+for (ep, ip), (e, i) in zip(li, li[1:]):


Input:
N, M = list(map(int, input().split()))

A_ = [int(input()) for _ in range(M)]

A = [0] * (N+3)

for a in A_:

    A[a] = 1

dp = [0] * (N+3)

dp[0] = 1

mod = 10**9+7

for i in range(1, N+1):

    if A[i-1] == 0:

        dp[i] += dp[i-1]

    if A[i-2] == 0:

        dp[i] += dp[i-2]

    dp[i] %= mod

print((dp[N]))

n,m=list(map(int,input().split()))

dp=[0]*(n+3)

a=[int(input()) for i in range(m)]

mod=10**9+7

for i in range(m):

    dp[a[i]]=-1

dp[0]=1

if dp[1]!=-1:

    dp[1]+=dp[0]

for i in range(n+1):

    if dp[i+2]==-1:

        continue

    if dp[i]!=-1:

        dp[i+2]+=dp[i]

    if dp[i+1]!=-1:

        dp[i+2]+=dp[i+1]

    dp[i+2]%=mod

print((dp[n]%mod))

n, m = list(map(int, input().split()))
dp = [0] * (n + 3)
a = [int(input()) for i in range(m)]
mod = 10**9 + 7
for i in range(m):
    dp[a[i]] = -1
dp[0] = 1
if dp[1] != -1:
    dp[1] += dp[0]
for i in range(n + 1):
    if dp[i + 2] == -1:
        continue
    if dp[i] != -1:
        dp[i + 2] += dp[i]
    if dp[i + 1] != -1:
        dp[i + 2] += dp[i + 1]
    dp[i + 2] %= mod
print((dp[n] % mod))


Input:
n=int(input())

D={}

DD={}

for i in range(1,n+1):

   s=(str(i)[0],str(i)[-1])

   t=(str(i)[-1],str(i)[0])

   if s not in D:

      D[s]=1

   else:

      D[s]+=1

   if t not in DD:

      DD[t]=1

   else:

      DD[t]+=1

ans=0

for i in D:

   if i in DD:

      ans+=D[i]*DD[i]

print(ans)

n=int(input())

D={}

for i in range(1,n+1):

   s=(str(i)[0],str(i)[-1])

   if s in D:

      D[s]+=1

   else:

      D[s]=1

ans=0

for aj,bj in D:

   if (bj,aj) in D:

      ans+=D[(aj,bj)]*D[(bj,aj)]

print(ans)

n = int(input())
D = {}
DD = {}
for i in range(1, n + 1):
    s = (str(i)[0], str(i)[-1])
    t = (str(i)[-1], str(i)[0])
    if s not in D:
        D[s] = 1
    else:
        D[s] += 1
    if t not in DD:
        DD[t] = 1
    else:
        DD[t] += 1
ans = 0
for i in D:
    if i in DD:
        ans += D[i] * DD[i]
print(ans)

n = int(input())
D = {}
for i in range(1, n + 1):
    s = (str(i)[0], str(i)[-1])
    if s in D:
        D[s] += 1
    else:
        D[s] = 1
ans = 0
for aj, bj in D:
    if (bj, aj) in D:
        ans += D[(aj, bj)] * D[(bj, aj)]
print(ans)


Input:
import math

N = int(input())

ans = 0

ans =math.factorial(N) % (10**9 +7)

print(ans)

N = int(input())

power = 1

for i in range(N):

    power = ((i+1) * power) % 1000000007

print(power)

import math

N = int(input())
ans = 0
ans = math.factorial(N) % (10**9 + 7)
print(ans)

N = int(input())
power = 1
for i in range(N):
    power = ((i + 1) * power) % 1000000007
print(power)


Input:
X,Y,Z,K = list(map(int,input().split()))

A = list(map(int,input().split()))

B = list(map(int,input().split()))

C = list(map(int,input().split()))

asort,bsort,csort = sorted(A,reverse=True),sorted(B,reverse=True),sorted(C,reverse=True)

print((asort[0] + bsort[0] + csort[0]))

already = [[0,0,0]]

x,y,z = 0,0,0

place_sum = []

check = []

for k in range(K - 1):

    if [x + 1,y,z] not in already and x + 1 < X:

        already.append([x + 1,y,z])

        place_sum.append([x + 1,y,z])

        check.append(asort[x + 1] + bsort[y] + csort[z])

    if [x,y + 1,z] not in already and y + 1 < Y:

        already.append([x,y + 1,z])

        place_sum.append([x,y + 1,z])

        check.append(asort[x] + bsort[y + 1] + csort[z])

    if [x,y,z + 1] not in already and z + 1 < Z:

        already.append([x,y,z + 1])

        place_sum.append([x,y,z + 1])

        check.append(asort[x] + bsort[y] + csort[z + 1])

    print((max(check)))

    x,y,z = place_sum[check.index(max(check))][0],place_sum[check.index(max(check))][1],place_sum[check.index(max(check))][2]

    place_sum.pop(check.index(max(check)))

    check.remove(max(check))

import heapq

X,Y,Z,K = list(map(int,input().split()))

A = list(map(int,input().split()))

B = list(map(int,input().split()))

C = list(map(int,input().split()))

asort,bsort,csort = sorted(A,reverse=True),sorted(B,reverse=True),sorted(C,reverse=True)

already = [[0,0,0]]

print((asort[0] + bsort[0] + csort[0]))

x,y,z = 0,0,0

check = []

for k in range(K - 1):

    if [x + 1,y,z] not in already and x + 1 < X:

        already.append([x + 1,y,z])

        heapq.heappush(check,(-(asort[x + 1] + bsort[y] + csort[z]),x + 1,y,z))

    if [x,y + 1,z] not in already and y + 1 < Y:

        already.append([x,y + 1,z])

        heapq.heappush(check,(-(asort[x] + bsort[y + 1] + csort[z]),x,y + 1,z))

    if [x,y,z + 1] not in already and z + 1 < Z:

        already.append([x,y,z + 1])

        heapq.heappush(check,(-(asort[x] + bsort[y] + csort[z + 1]),x,y,z + 1))

    maxsum = heapq.heappop(check)

    print((-maxsum[0]))

    x,y,z = maxsum[1],maxsum[2],maxsum[3]

X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
asort, bsort, csort = (
    sorted(A, reverse=True),
    sorted(B, reverse=True),
    sorted(C, reverse=True),
)
print((asort[0] + bsort[0] + csort[0]))
already = [[0, 0, 0]]
x, y, z = 0, 0, 0
place_sum = []
check = []
for k in range(K - 1):
    if [x + 1, y, z] not in already and x + 1 < X:
        already.append([x + 1, y, z])
        place_sum.append([x + 1, y, z])
        check.append(asort[x + 1] + bsort[y] + csort[z])
    if [x, y + 1, z] not in already and y + 1 < Y:
        already.append([x, y + 1, z])
        place_sum.append([x, y + 1, z])
        check.append(asort[x] + bsort[y + 1] + csort[z])
    if [x, y, z + 1] not in already and z + 1 < Z:
        already.append([x, y, z + 1])
        place_sum.append([x, y, z + 1])
        check.append(asort[x] + bsort[y] + csort[z + 1])
    print((max(check)))
    x, y, z = (
        place_sum[check.index(max(check))][0],
        place_sum[check.index(max(check))][1],
        place_sum[check.index(max(check))][2],
    )
    place_sum.pop(check.index(max(check)))
    check.remove(max(check))

import heapq

X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
asort, bsort, csort = (
    sorted(A, reverse=True),
    sorted(B, reverse=True),
    sorted(C, reverse=True),
)
already = [[0, 0, 0]]
print((asort[0] + bsort[0] + csort[0]))
x, y, z = 0, 0, 0
check = []
for k in range(K - 1):
    if [x + 1, y, z] not in already and x + 1 < X:
        already.append([x + 1, y, z])
        heapq.heappush(check, (-(asort[x + 1] + bsort[y] + csort[z]), x + 1, y, z))
    if [x, y + 1, z] not in already and y + 1 < Y:
        already.append([x, y + 1, z])
        heapq.heappush(check, (-(asort[x] + bsort[y + 1] + csort[z]), x, y + 1, z))
    if [x, y, z + 1] not in already and z + 1 < Z:
        already.append([x, y, z + 1])
        heapq.heappush(check, (-(asort[x] + bsort[y] + csort[z + 1]), x, y, z + 1))
    maxsum = heapq.heappop(check)
    print((-maxsum[0]))
    x, y, z = maxsum[1], maxsum[2], maxsum[3]

-        place_sum.append([x + 1, y, z])

-        check.append(asort[x + 1] + bsort[y] + csort[z])

+        heapq.heappush(check, (-(asort[x + 1] + bsort[y] + csort[z]), x + 1, y, z))

-        place_sum.append([x, y + 1, z])

-        check.append(asort[x] + bsort[y + 1] + csort[z])

+        heapq.heappush(check, (-(asort[x] + bsort[y + 1] + csort[z]), x, y + 1, z))

-        place_sum.append([x, y, z + 1])

-        check.append(asort[x] + bsort[y] + csort[z + 1])

-        place_sum[check.index(max(check))][0],

-        place_sum[check.index(max(check))][1],

-        place_sum[check.index(max(check))][2],

-    place_sum.pop(check.index(max(check)))

+        heapq.heappush(check, (-(asort[x] + bsort[y] + csort[z + 1]), x, y, z + 1))

+    x, y, z = maxsum[1], maxsum[2], maxsum[3]


Input:
a,b,c,x,y=list(map(int,input().split()))

ans=a*x+b*y

n=max(x,y)

for i in range(1,n+1):

  ans=min(ans,2*i*c+a*max(0,x-i)+b*max(0,y-i))

print(ans)

a,b,c,x,y=list(map(int,input().split()))

ans1=a*x+b*y

ans2=2*c*max(x,y)

ans3=2*c*min(x,y)+a*(x-min(x,y))+b*(y-min(x,y))

print((min(ans1,ans2,ans3)))

a, b, c, x, y = list(map(int, input().split()))
ans = a * x + b * y
n = max(x, y)
for i in range(1, n + 1):
    ans = min(ans, 2 * i * c + a * max(0, x - i) + b * max(0, y - i))
print(ans)

a, b, c, x, y = list(map(int, input().split()))
ans1 = a * x + b * y
ans2 = 2 * c * max(x, y)
ans3 = 2 * c * min(x, y) + a * (x - min(x, y)) + b * (y - min(x, y))
print((min(ans1, ans2, ans3)))

-    ans = min(ans, 2 * i * c + a * max(0, x - i) + b * max(0, y - i))


Input:
answer = 0

N = int(input())

A = list(map(int,input().split()))

for i in range(N) :

    while A[i] % 2 == 0 :

        A[i] = A[i] / 2

        answer += 1

print(answer)

N = int(input())

L = list(map(int,input().split()))

ans = 0

for i in range(N) :

    flag = 0

    while flag == 0 :

        if (L[i] % 2) == 0 :

            ans += 1

            L[i] = L[i]//2

        else :

            flag = 1

print(ans)

answer = 0
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    while A[i] % 2 == 0:
        A[i] = A[i] / 2
        answer += 1
print(answer)

N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(N):
    flag = 0
    while flag == 0:
        if (L[i] % 2) == 0:
            ans += 1
            L[i] = L[i] // 2
        else:
            flag = 1
print(ans)

-answer = 0
-A = list(map(int, input().split()))
+L = list(map(int, input().split()))
+ans = 0
-    while A[i] % 2 == 0:
-        A[i] = A[i] / 2
-        answer += 1
-print(answer)
+    flag = 0
+    while flag == 0:
+        if (L[i] % 2) == 0:
+            ans += 1
+            L[i] = L[i] // 2
+        else:
+            flag = 1
+print(ans)


Input:
import sys

def main():

    input = sys.stdin.readline

    N = int(input())

    S = list(map(int, input().split()))

    ans = 0

    for C in range(1, N//2):

        n = N // C

        point = 0

        used = set([0])

        for k in range(1, n):

            A = N - 1 - k*C

            if A in used or k*C in used or A == k*C:

                break

            used.add(A)

            used.add(k*C)

            point += S[A] + S[k*C]

            ans = max(ans, point)

    return ans

if __name__ == '__main__':

    print((main()))

import sys

def main():

    input = sys.stdin.readline

    N = int(input())

    S = list(map(int, input().split()))

    ans = 0

    # C = A - B

    for C in range(1, N//2):

        n = (N-1) // C

        point = 0

        for k in range(1, n):

            A = N-1 - k*C

            # Check A and B are positive integer, and S_i is not used twice.

            #

            # B = A - C and B >= 0, so A must be over C (A > C).

            #

            # If C is aliquot of N-1 (N-1 % C = 0), A is also aliquot of N-1

            # (N-1 % A = 0) because A + kC = N-1. Therefore when A is less than

            # or equal kC, the A's value is already used by kC.

            if A < C or ((N-1) % C == 0 and A <= k*C):

                break

            point += S[A] + S[k*C]

            ans = max(ans, point)

    return ans

if __name__ == '__main__':

    print((main()))

import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = list(map(int, input().split()))
    ans = 0
    for C in range(1, N // 2):
        n = N // C
        point = 0
        used = set([0])
        for k in range(1, n):
            A = N - 1 - k * C
            if A in used or k * C in used or A == k * C:
                break
            used.add(A)
            used.add(k * C)
            point += S[A] + S[k * C]
            ans = max(ans, point)
    return ans

if __name__ == "__main__":
    print((main()))

import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = list(map(int, input().split()))
    ans = 0
    # C = A - B
    for C in range(1, N // 2):
        n = (N - 1) // C
        point = 0
        for k in range(1, n):
            A = N - 1 - k * C
            # Check A and B are positive integer, and S_i is not used twice.
            #
            # B = A - C and B >= 0, so A must be over C (A > C).
            #
            # If C is aliquot of N-1 (N-1 % C = 0), A is also aliquot of N-1
            # (N-1 % A = 0) because A + kC = N-1. Therefore when A is less than
            # or equal kC, the A's value is already used by kC.
            if A < C or ((N - 1) % C == 0 and A <= k * C):
                break
            point += S[A] + S[k * C]
            ans = max(ans, point)
    return ans

if __name__ == "__main__":
    print((main()))

-            if A in used or k * C in used or A == k * C:

+            # Check A and B are positive integer, and S_i is not used twice.

+            # B = A - C and B >= 0, so A must be over C (A > C).

+            # If C is aliquot of N-1 (N-1 % C = 0), A is also aliquot of N-1

+            # (N-1 % A = 0) because A + kC = N-1. Therefore when A is less than

+            # or equal kC, the A's value is already used by kC.