Input:
from collections import Counter

S = input()[::-1]

memo = [0]

d = 0

mod = 2019

for s in S:

    tmp = int(s) * pow(10, d, mod) % mod

    tmp = memo[-1] + tmp

    memo.append(tmp % mod)

    d += 1

c = Counter(memo)

ans = sum(v * (v - 1) // 2 for v in list(c.values()))

print(ans)

from collections import defaultdict

S = input()

N = len(S)

memo = defaultdict(int)

memo[0] += 1

mod = 2019

d = 1

val = 0

for s in S[::-1]:

    s = int(s)

    val += s * d

    val %= mod

    memo[val] += 1

    d *= 10

    d %= mod

print((sum(v * (v - 1) // 2 for v in list(memo.values()))))

-    tmp = int(s) * pow(10, d, mod) % mod

-ans = sum(v * (v - 1) // 2 for v in list(c.values()))

+print((sum(v * (v - 1) // 2 for v in list(memo.values()))))


Input:
a = input()

print(('A' if not a.islower() else 'a'))

print(('A' if input().isupper() else 'a'))

a = input()
print(("A" if not a.islower() else "a"))

-print(("A" if not a.islower() else "a"))

+print(("A" if input().isupper() else "a"))


Input:
N=int(input())

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

for i in range(N):

  for j in range(1,31):

    if a[i]%(2**j)!=0:

      a[i]=j-1

      break

print((sum(a)))

import sys

input = sys.stdin.buffer.readline

N = int(input())

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

def f(n):

  res = 0

  while n % 2 == 0:

    n //= 2

    res += 1

  return res

answer = 0

for a in A:

  answer += f(a)

print(answer)

N = int(input())
a = list(map(int, input().split()))
for i in range(N):
    for j in range(1, 31):
        if a[i] % (2**j) != 0:
            a[i] = j - 1
            break
print((sum(a)))

+import sys
+
+input = sys.stdin.buffer.readline
-a = list(map(int, input().split()))
-for i in range(N):
-    for j in range(1, 31):
-        if a[i] % (2**j) != 0:
-            a[i] = j - 1
-            break
-print((sum(a)))
+A = list(map(int, input().split()))
+
+
+def f(n):
+    res = 0
+    while n % 2 == 0:
+        n //= 2
+        res += 1
+    return res
+
+
+answer = 0
+for a in A:
+    answer += f(a)
+print(answer)


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

cnt = 0

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

    i = str(i)

    if i[0] == i[-1] and i[1] == i[-2]:

        cnt += 1

print(cnt)

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

cnt = 0

for i in range(10):

    for j in range(10):

        for k in range(10):

            c = 10000*i+1000*j+100*k+10*j+i

            if a <= c <= b:

                cnt += 1

print(cnt)

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

a, b = list(map(int, input().split()))
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            c = 10000 * i + 1000 * j + 100 * k + 10 * j + i
            if a <= c <= b:
                cnt += 1
print(cnt)


Input:
k, s = list(map(int, input().split()))

cnt = 0

for i in range(k + 1):

    for j in range(k + 1):

        if i + j > s:

            break

        elif s - i - j <= k:

            cnt += 1

print(cnt)

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

cnt = 0

for i in range(k + 1):

    for j in range(k + 1):

        if 0 <= s - i - j <= k:

            cnt += 1

print(cnt)

-        if i + j > s:
-            break
-        elif s - i - j <= k:
+        if 0 <= s - i - j <= k:


Input:
from collections import Counter

s = input()

mod1 = 673

mod2 = 3

num1 = 0

num2 = 0

li1 = []

li2 = []

pw1 = 10

pw2 = 10

for i, e in enumerate(s, 1):

    num1 *= 10

    num1 += int(e)

    num1 %= mod1

    inv = pow(pw1, mod1 - 2, mod1)

    li1.append(num1 * inv % mod1)

    num2 *= 10

    num2 += int(e)

    num2 %= mod2

    inv = pow(pw2, mod2 - 2, mod2)

    li2.append(num2 * inv % mod2)

    pw1 *= 10

    pw1 %= mod1

    pw2 *= 10

    pw2 %= mod2

li = [0] + [10 * e1 + e2 for e1, e2 in zip(li1, li2)]

c = Counter(li)

ans = 0

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

    ans += v * (v - 1) // 2

print(ans)

from collections import Counter

def f(mod):

    ret = [0]

    power = 1

    num = 0

    for i, e in enumerate(s, 1):

        num *= 10

        num += int(e)

        num %= mod

        power *= 10

        power %= mod

        inv = pow(power, mod - 2, mod)

        ret.append(num * inv % mod)

    return ret

s = input()

mod3 = f(3)

mod673 = f(673)

li = [10 * e673 + e3 for e3, e673 in zip(mod3, mod673)]

c = Counter(li)

ans = 0

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

    ans += v * (v - 1) // 2

print(ans)


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

c = int(c*2)

m = float('inf')

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

    m = min(m, a*max(0, x-i)+b*max(0,y-i)+c*i)

print(m)

import math

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

ans = float('inf')

c = c*2

for i in range(max(x, y)+1):

    if i > x:

        price = b*(y-i) + c*i

    elif i > y:

        price = a*(x-i) + c*i

    else:

        price = a*(x-i) + b*(y-i) + c*i

    if ans > price:

        ans = price

print(ans)

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

import math

a, b, c, x, y = list(map(int, input().split(" ")))
ans = float("inf")
c = c * 2
for i in range(max(x, y) + 1):
    if i > x:
        price = b * (y - i) + c * i
    elif i > y:
        price = a * (x - i) + c * i
    else:
        price = a * (x - i) + b * (y - i) + c * i
    if ans > price:
        ans = price
print(ans)

+        price = a * (x - i) + b * (y - i) + c * i


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

s=list(range(l,r+1))[:2019]

print((min(i*j%2019for i in s for j in s if i<j)))

l,r=list(map(int,input().split()));s=list(range(l,r+1))[:673];print((min(i*j%2019for i in s for j in s if i<j)))

l, r = list(map(int, input().split()))
s = list(range(l, r + 1))[:2019]
print((min(i * j % 2019 for i in s for j in s if i < j)))

l, r = list(map(int, input().split()))
s = list(range(l, r + 1))[:673]
print((min(i * j % 2019 for i in s for j in s if i < j)))


Input:
s = input()

cnt = 0

for i in range(len(s) - 1):

    if s[i] == 'W' and s[i + 1] == 'B':

        cnt += 1

    if s[i] == 'B' and s[i + 1] == 'W':

        cnt += 1

print(cnt)

S = input()

tmp = S[0]

cnt = 0

for s in S[1:]:

    if tmp != s:

        cnt += 1

        tmp = s

print(cnt)

s = input()
cnt = 0
for i in range(len(s) - 1):
    if s[i] == "W" and s[i + 1] == "B":
        cnt += 1
    if s[i] == "B" and s[i + 1] == "W":
        cnt += 1
print(cnt)


Input:
import math

mod = 10 ** 9 + 7

n = int(input())

print((math.factorial(n) % mod))

mod = 10 ** 9 + 7

n = int(input())

ans = 1

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

    ans *= i

    ans %= mod

print(ans)

import math

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

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

-import math
-print((math.factorial(n) % mod))
+ans = 1
+for i in range(1, n + 1):
+    ans *= i
+    ans %= mod
+print(ans)


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

count = 0

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

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

        count += 1

print(count)

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

count = 0

for i in range(10):

    for j in range(10):

        for k in range(10):

            if(A <= 10000*i + 1000*j + 100*k + 10*j +i <= B):

                count += 1

print(count)

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

A, B = list(map(int, input().split()))
count = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if A <= 10000 * i + 1000 * j + 100 * k + 10 * j + i <= B:
                count += 1
print(count)


Input:
import math

import string

def readints():

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

def nCr(n, r):

    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

def has_duplicates2(seq):

    seen = []

    for item in seq:

        if not(item in seen):

            seen.append(item)

    return len(seq) != len(seen)

def divisor(n):

    divisor = []

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

        if n % i == 0:

            divisor.append(i)

    return divisor

# coordinates

dx = [-1, -1, -1, 0, 0, 1, 1, 1]

dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())

a = readints()

def func(l):

    if len(l) == n:

        for i in range(len(l)):

            if l[i] % 2 == 0:

                return 1

        return 0

    return func(l+[(a[len(l)])])+func(l+[(a[len(l)]-1)])+func(l+[(a[len(l)]+1)])

print((func([])))

import math

import string

def readints():

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

def nCr(n, r):

    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

def has_duplicates2(seq):

    seen = []

    for item in seq:

        if not(item in seen):

            seen.append(item)

    return len(seq) != len(seen)

def divisor(n):

    divisor = []

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

        if n % i == 0:

            divisor.append(i)

    return divisor

# coordinates

dx = [-1, -1, -1, 0, 0, 1, 1, 1]

dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())

a = readints()

sum = 1

for i in range(len(a)):

    if a[i] % 2 == 0:

        sum *= 2

    else:

        sum *= 1

print((3**len(a)-sum))

import math
import string

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

def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not (item in seen):
            seen.append(item)
    return len(seq) != len(seen)

def divisor(n):
    divisor = []
    for i in range(1, n + 1):
        if n % i == 0:
            divisor.append(i)
    return divisor

# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()

def func(l):
    if len(l) == n:
        for i in range(len(l)):
            if l[i] % 2 == 0:
                return 1
        return 0
    return (
        func(l + [(a[len(l)])])
        + func(l + [(a[len(l)] - 1)])
        + func(l + [(a[len(l)] + 1)])
    )

print((func([])))

import math
import string

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

def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not (item in seen):
            seen.append(item)
    return len(seq) != len(seen)

def divisor(n):
    divisor = []
    for i in range(1, n + 1):
        if n % i == 0:
            divisor.append(i)
    return divisor

# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
sum = 1
for i in range(len(a)):
    if a[i] % 2 == 0:
        sum *= 2
    else:
        sum *= 1
print((3 ** len(a) - sum))

-def func(l):
-    if len(l) == n:
-        for i in range(len(l)):
-            if l[i] % 2 == 0:
-                return 1
-        return 0
-    return (
-        func(l + [(a[len(l)])])
-        + func(l + [(a[len(l)] - 1)])
-        + func(l + [(a[len(l)] + 1)])
-    )
-print((func([])))
+sum = 1
+for i in range(len(a)):
+    if a[i] % 2 == 0:
+        sum *= 2
+    else:
+        sum *= 1
+print((3 ** len(a) - sum))


Input:
import math

N = int(input())

num = math.factorial(N)

k, r = divmod(num, 10**9 + 7)

print(r)

N = int(input())

FACTOR = 10 ** 9 + 7

num = 1

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

    num *= i

    k, r = divmod(num, FACTOR)

    num = r

print(r)

N = int(input())
FACTOR = 10**9 + 7
num = 1
for i in range(1, N + 1):
    num *= i
    k, r = divmod(num, FACTOR)
    num = r
print(r)

-import math
-num = math.factorial(N)
-k, r = divmod(num, 10**9 + 7)
+FACTOR = 10**9 + 7
+num = 1
+for i in range(1, N + 1):
+    num *= i
+    k, r = divmod(num, FACTOR)
+    num = r


Input:
def main():

    N, M = (int(i) for i in input().split())

    def trial_division(n):

        divs = []

        for i in range(1, int(n**0.5)+1):

            if n % i == 0:

                divs.append(i)

                if i != n//i:

                    divs.append(n//i)

        divs.sort(reverse=True)

        return divs

    divs = trial_division(M)

    for d in divs:

        if d*N <= M:

            return print(d)

if __name__ == '__main__':

    main()

def main():

    def trial_division(n):

        divs = []

        for i in range(1, int(n**0.5)+1):

            if n % i == 0:

                divs.append(i)

                if i != n//i:

                    divs.append(n//i)

        divs.sort(reverse=True)

        return divs

    N, M = (int(i) for i in input().split())

    divs = trial_division(M)

    for d in divs:

        if N*d <= M:

            return print(d)

if __name__ == '__main__':

    main()

def main():
    N, M = (int(i) for i in input().split())

    def trial_division(n):
        divs = []
        for i in range(1, int(n**0.5) + 1):
            if n % i == 0:
                divs.append(i)
                if i != n // i:
                    divs.append(n // i)
        divs.sort(reverse=True)
        return divs

    divs = trial_division(M)
    for d in divs:
        if d * N <= M:
            return print(d)

if __name__ == "__main__":
    main()

def main():
    def trial_division(n):
        divs = []
        for i in range(1, int(n**0.5) + 1):
            if n % i == 0:
                divs.append(i)
                if i != n // i:
                    divs.append(n // i)
        divs.sort(reverse=True)
        return divs

    N, M = (int(i) for i in input().split())
    divs = trial_division(M)
    for d in divs:
        if N * d <= M:
            return print(d)

if __name__ == "__main__":
    main()

-    N, M = (int(i) for i in input().split())

+    N, M = (int(i) for i in input().split())


Input:
import math

N = int(input())

C = 10**9 + 7

print((math.factorial(N) % C))

N = int(input())

C = 10**9+7

ans = 1

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

    ans *= i

    ans %= C

print(ans)

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

-import math
-print((math.factorial(N) % C))
+ans = 1
+for i in range(1, N + 1):
+    ans *= i
+    ans %= C
+print(ans)


Input:
import sys

input = sys.stdin.readline

import bisect

n = int(input())

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

l = int(input())

U = 17

dp = [[0]*n for _ in range(U+1)]

for i, x in enumerate(X):

  t = bisect.bisect_left(X, x+l)

  dp[0][i] = bisect.bisect_right(X, x+l) - 1

for k in range(U):

  for i in range(n):

    dp[k+1][i] = dp[k][dp[k][i]]

def test(x, a, b):

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

    if x >> i & 1:

      a = dp[i][a]

  return a >= b

def solve(a, b):

  if a > b:

    a, b = b, a

  ng = 0

  ok = n-1

  while ok - ng > 1:

    mid = (ng + ok) // 2

    if test(mid, a, b):

      ok = mid

    else:

      ng = mid

  print(ok)

q = int(input())

for _ in range(q):

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

  a -= 1

  b -= 1

  solve(a, b)

import sys

input = sys.stdin.readline

import bisect

n = int(input())

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

l = int(input())

U = 17

dp = [[0]*n for _ in range(U+1)]

for i, x in enumerate(X):

  t = bisect.bisect_left(X, x+l)

  dp[0][i] = bisect.bisect_right(X, x+l) - 1

for k in range(U):

  for i in range(n):

    dp[k+1][i] = dp[k][dp[k][i]]

q = int(input())

for _ in range(q):

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

  a -= 1

  b -= 1

  if a > b:

    a, b = b, a

  res = 1

  for k in range(U, -1, -1):

    if dp[k][a] < b:

      a = dp[k][a]

      res += (1<<k)

    if a == b:

      break

  print(res)

import sys

input = sys.stdin.readline
import bisect

n = int(input())
X = list(map(int, input().split()))
l = int(input())
U = 17
dp = [[0] * n for _ in range(U + 1)]
for i, x in enumerate(X):
    t = bisect.bisect_left(X, x + l)
    dp[0][i] = bisect.bisect_right(X, x + l) - 1
for k in range(U):
    for i in range(n):
        dp[k + 1][i] = dp[k][dp[k][i]]

def test(x, a, b):
    for i in range(U, -1, -1):
        if x >> i & 1:
            a = dp[i][a]
    return a >= b

def solve(a, b):
    if a > b:
        a, b = b, a
    ng = 0
    ok = n - 1
    while ok - ng > 1:
        mid = (ng + ok) // 2
        if test(mid, a, b):
            ok = mid
        else:
            ng = mid
    print(ok)

q = int(input())
for _ in range(q):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    solve(a, b)

import sys

input = sys.stdin.readline
import bisect

n = int(input())
X = list(map(int, input().split()))
l = int(input())
U = 17
dp = [[0] * n for _ in range(U + 1)]
for i, x in enumerate(X):
    t = bisect.bisect_left(X, x + l)
    dp[0][i] = bisect.bisect_right(X, x + l) - 1
for k in range(U):
    for i in range(n):
        dp[k + 1][i] = dp[k][dp[k][i]]
q = int(input())
for _ in range(q):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    if a > b:
        a, b = b, a
    res = 1
    for k in range(U, -1, -1):
        if dp[k][a] < b:
            a = dp[k][a]
            res += 1 << k
        if a == b:
            break
    print(res)

-def test(x, a, b):
-    for i in range(U, -1, -1):
-        if x >> i & 1:
-            a = dp[i][a]
-    return a >= b
-def solve(a, b):
-    if a > b:
-        a, b = b, a
-    ng = 0
-    ok = n - 1
-    while ok - ng > 1:
-        mid = (ng + ok) // 2
-        if test(mid, a, b):
-            ok = mid
-        else:
-            ng = mid
-    print(ok)
-    solve(a, b)
+    if a > b:
+        a, b = b, a
+    res = 1
+    for k in range(U, -1, -1):
+        if dp[k][a] < b:
+            a = dp[k][a]
+            res += 1 << k
+        if a == b:
+            break
+    print(res)


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

arr = [like + i for i in range(n)]

arr.sort(key=lambda x:abs(x))

print((sum(arr[1:])))

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

arr = [like + i for i in range(n)]

arr.sort(key=abs)

print((sum(arr[1:])))

n, like = list(map(int, input().split()))
arr = [like + i for i in range(n)]
arr.sort(key=lambda x: abs(x))
print((sum(arr[1:])))


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

ans = float('inf')

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

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

    ans = min(ans,cost)

print(ans)

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

tmp = A*X + B*Y

if X >= Y:

    tmp = min(tmp,2*Y*C+(X-Y)*A)

else:

    tmp = min(tmp,2*X*C+(Y-X)*B)

tmp = min(tmp,max(X,Y)*2*C)

print(tmp)

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

A, B, C, X, Y = list(map(int, input().split()))
tmp = A * X + B * Y
if X >= Y:
    tmp = min(tmp, 2 * Y * C + (X - Y) * A)
else:
    tmp = min(tmp, 2 * X * C + (Y - X) * B)
tmp = min(tmp, max(X, Y) * 2 * C)
print(tmp)

+    tmp = min(tmp, 2 * Y * C + (X - Y) * A)

+    tmp = min(tmp, 2 * X * C + (Y - X) * B)


Input:
#coding: UTF-8

import math

N=int(input())

def prime_list(k):

    lis=[True for i in range(1,k+1)]

    lis[0]=False

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

        j=2

        while j*j<=i:

            if i%j==0:

                lis[i-1]=False

                break

            else:

                j+=1

    return lis

#    print(lis)

def p_fact(k,N):

    plist=prime_list(k)

    lis=[0]*N

    for i in range(0,k):

        n=0

        if plist[i]:

            while k%(i+1)==0:

                n+=1

                k=k/(i+1)

        lis[i]=n

    return lis

out_lis=[0]*N

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

    input_lis=p_fact(i,N)

    out_lis=[out_lis[j]+input_lis[j] for j in range(0,N)]

#print(out_lis)

out=1

for i in range(0,N):

    out=out*(out_lis[i]+1)

print((out%1000000007))

#coding: UTF-8

import math

N=int(input())

def prime_list(k):

    lis=[True for i in range(1,k+1)]

    lis[0]=False

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

        j=2

        while j*j<=i:

            if i%j==0:

                lis[i-1]=False

                break

            else:

                j+=1

    return lis

#    print(lis)

def p_fact(k,N,plist):

#    plist=prime_list(k)

    lis=[0]*N

    for i in range(0,k):

        n=0

        if plist[i]:

            while k%(i+1)==0:

                n+=1

                k=k/(i+1)

        lis[i]=n

    return lis

#    print(lis)

out_lis=[0]*N

plist=prime_list(N)

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

    input_lis=p_fact(i,N,plist)

    out_lis=[out_lis[j]+input_lis[j] for j in range(0,N)]

#print(out_lis)

out=1

for i in range(0,N):

    out=out*(out_lis[i]+1)

#print(out%1000000007)

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

# coding: UTF-8
import math

N = int(input())

def prime_list(k):
    lis = [True for i in range(1, k + 1)]
    lis[0] = False
    for i in range(2, k + 1):
        j = 2
        while j * j <= i:
            if i % j == 0:
                lis[i - 1] = False
                break
            else:
                j += 1
    return lis

#    print(lis)
def p_fact(k, N):
    plist = prime_list(k)
    lis = [0] * N
    for i in range(0, k):
        n = 0
        if plist[i]:
            while k % (i + 1) == 0:
                n += 1
                k = k / (i + 1)
        lis[i] = n
    return lis

out_lis = [0] * N
for i in range(1, N + 1):
    input_lis = p_fact(i, N)
    out_lis = [out_lis[j] + input_lis[j] for j in range(0, N)]
# print(out_lis)
out = 1
for i in range(0, N):
    out = out * (out_lis[i] + 1)
print((out % 1000000007))

# coding: UTF-8
import math

N = int(input())

def prime_list(k):
    lis = [True for i in range(1, k + 1)]
    lis[0] = False
    for i in range(2, k + 1):
        j = 2
        while j * j <= i:
            if i % j == 0:
                lis[i - 1] = False
                break
            else:
                j += 1
    return lis

#    print(lis)
def p_fact(k, N, plist):
    #    plist=prime_list(k)
    lis = [0] * N
    for i in range(0, k):
        n = 0
        if plist[i]:
            while k % (i + 1) == 0:
                n += 1
                k = k / (i + 1)
        lis[i] = n
    return lis

#    print(lis)
out_lis = [0] * N
plist = prime_list(N)
for i in range(1, N + 1):
    input_lis = p_fact(i, N, plist)
    out_lis = [out_lis[j] + input_lis[j] for j in range(0, N)]
# print(out_lis)
out = 1
for i in range(0, N):
    out = out * (out_lis[i] + 1)
# print(out%1000000007)
print((out % (10**9 + 7)))

-def p_fact(k, N):
-    plist = prime_list(k)
+def p_fact(k, N, plist):
+    #    plist=prime_list(k)
+#    print(lis)
+plist = prime_list(N)
-    input_lis = p_fact(i, N)
+    input_lis = p_fact(i, N, plist)
-print((out % 1000000007))
+# print(out%1000000007)
+print((out % (10**9 + 7)))


Input:
import sys

import queue

N = 3

f= ''.join(sys.stdin.readline().split())

f+= ''.join(sys.stdin.readline().split())

f+= ''.join(sys.stdin.readline().split())

dd = [[-1, 0], [0, -1], [1, 0], [0, 1]]

Q = queue.Queue()

V = dict()

Q.put([f,f.index('0'),0])

V[f] = True

while not Q.empty():

    u = Q.get()

    if u[0] == '123456780':  break

    sx, sy = u[1]//N, u[1]%N

    for dx, dy in dd:

        tx, ty = sx+dx, sy+dy

        if tx<0 or ty<0 or tx>=N or ty>=N: continue

        v = u[:]

        n1, n2 = u[1], tx*N+ty

        v[1] = n2

        if n1>n2: n1, n2 = n2, n1

        v[0] = v[0][0:n1]+v[0][n2]+v[0][n1+1:n2]+v[0][n1]+v[0][n2+1:]

        if not V.get(v[0], False):

            V[v[0]] = True

            v[2] += 1

            Q.put(v)

print((u[2]))

import sys

import queue

N = 3

f = ''.join(sys.stdin.readline().split())

f += ''.join(sys.stdin.readline().split())

f += ''.join(sys.stdin.readline().split())

dd = [[-1, 0], [0, -1], [1, 0], [0, 1]]

Q = [[f,f.index('0'),0]]

V = { f: True }

while len(Q)>0:

    u = Q.pop(0)

    if u[0] == '123456780':  break

    sx, sy = u[1]//N, u[1]%N

    for dx, dy in dd:

        tx, ty = sx+dx, sy+dy

        if tx<0 or ty<0 or tx>=N or ty>=N: continue

        v = u[:]

        n1, n2 = u[1], tx*N+ty

        v[1] = n2

        if n1>n2: n1, n2 = n2, n1

        v[0] = v[0][0:n1]+v[0][n2]+v[0][n1+1:n2]+v[0][n1]+v[0][n2+1:]

        if not V.get(v[0], False):

            V[v[0]] = True

            v[2] += 1 # dir[r]

            Q.append(v)

print((u[2]))

import sys
import queue

N = 3
f = "".join(sys.stdin.readline().split())
f += "".join(sys.stdin.readline().split())
f += "".join(sys.stdin.readline().split())
dd = [[-1, 0], [0, -1], [1, 0], [0, 1]]
Q = queue.Queue()
V = dict()
Q.put([f, f.index("0"), 0])
V[f] = True
while not Q.empty():
    u = Q.get()
    if u[0] == "123456780":
        break
    sx, sy = u[1] // N, u[1] % N
    for dx, dy in dd:
        tx, ty = sx + dx, sy + dy
        if tx < 0 or ty < 0 or tx >= N or ty >= N:
            continue
        v = u[:]
        n1, n2 = u[1], tx * N + ty
        v[1] = n2
        if n1 > n2:
            n1, n2 = n2, n1
        v[0] = v[0][0:n1] + v[0][n2] + v[0][n1 + 1 : n2] + v[0][n1] + v[0][n2 + 1 :]
        if not V.get(v[0], False):
            V[v[0]] = True
            v[2] += 1
            Q.put(v)
print((u[2]))

import sys
import queue

N = 3
f = "".join(sys.stdin.readline().split())
f += "".join(sys.stdin.readline().split())
f += "".join(sys.stdin.readline().split())
dd = [[-1, 0], [0, -1], [1, 0], [0, 1]]
Q = [[f, f.index("0"), 0]]
V = {f: True}
while len(Q) > 0:
    u = Q.pop(0)
    if u[0] == "123456780":
        break
    sx, sy = u[1] // N, u[1] % N
    for dx, dy in dd:
        tx, ty = sx + dx, sy + dy
        if tx < 0 or ty < 0 or tx >= N or ty >= N:
            continue
        v = u[:]
        n1, n2 = u[1], tx * N + ty
        v[1] = n2
        if n1 > n2:
            n1, n2 = n2, n1
        v[0] = v[0][0:n1] + v[0][n2] + v[0][n1 + 1 : n2] + v[0][n1] + v[0][n2 + 1 :]
        if not V.get(v[0], False):
            V[v[0]] = True
            v[2] += 1  # dir[r]
            Q.append(v)
print((u[2]))

-Q = queue.Queue()
-V = dict()
-Q.put([f, f.index("0"), 0])
-V[f] = True
-while not Q.empty():
-    u = Q.get()
+Q = [[f, f.index("0"), 0]]
+V = {f: True}
+while len(Q) > 0:
+    u = Q.pop(0)
-            v[2] += 1
-            Q.put(v)
+            v[2] += 1  # dir[r]
+            Q.append(v)


Input:
def main():

    S = input()

    w1 = 'dream'[::-1]

    w2 = 'dreamer'[::-1]

    w3 = 'erase'[::-1]

    w4 = 'eraser'[::-1]

    # print(w1,w2,w3,w4)

    S = S[::-1]

    # print(S)

    # words = ['dream', 'dreamer', 'erase', 'eraser']

    words = [w1, w2, w3, w4]

    T = ''

    while S != T:

        cand = []

        for w in words:

            new_t = T + w

            cand.append(new_t)

        # print('cand', cand)

        ans = False

        for c in cand:

            if c == S[:len(c)]:

                T = c

                ans = True

        if not ans:

            break

    if S == T:

        print('YES')

    else:

        print("NO")

if __name__ == "__main__":

    main()

def main():

    S = input()

    w1 = 'dream'[::-1]

    w2 = 'dreamer'[::-1]

    w3 = 'erase'[::-1]

    w4 = 'eraser'[::-1]

    S = S[::-1]

    words = [w1, w2, w3, w4]

    flag = False

    i = 0

    while i < len(S):

        for w in words:

            if S[i:].startswith(w):

                i += len(w)

                flag = True

                break

        if not flag:

            print("NO")

            exit()

        flag = False

    print("YES")

if __name__ == "__main__":

    main()

def main():
    S = input()
    w1 = "dream"[::-1]
    w2 = "dreamer"[::-1]
    w3 = "erase"[::-1]
    w4 = "eraser"[::-1]
    # print(w1,w2,w3,w4)
    S = S[::-1]
    # print(S)
    # words = ['dream', 'dreamer', 'erase', 'eraser']
    words = [w1, w2, w3, w4]
    T = ""
    while S != T:
        cand = []
        for w in words:
            new_t = T + w
            cand.append(new_t)
        # print('cand', cand)
        ans = False
        for c in cand:
            if c == S[: len(c)]:
                T = c
                ans = True
        if not ans:
            break
    if S == T:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main()

def main():
    S = input()
    w1 = "dream"[::-1]
    w2 = "dreamer"[::-1]
    w3 = "erase"[::-1]
    w4 = "eraser"[::-1]
    S = S[::-1]
    words = [w1, w2, w3, w4]
    flag = False
    i = 0
    while i < len(S):
        for w in words:
            if S[i:].startswith(w):
                i += len(w)
                flag = True
                break
        if not flag:
            print("NO")
            exit()
        flag = False
    print("YES")

if __name__ == "__main__":
    main()

-    # words = ['dream', 'dreamer', 'erase', 'eraser']


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

src = [tuple(map(int,input().split())) for i in range(N)]

INF = 10**9

dp = [[INF for j in range(401)] for i in range(401)]

dp[0][0] = 0

maxa = maxb = 0

for a,b,c in src:

    for ai in range(maxa,-1,-1):

        for bi in range(maxb,-1,-1):

            dp[ai+a][bi+b] = min(dp[ai+a][bi+b], dp[ai][bi] + c)

    maxa += a

    maxb += b

ans = INF

for i in range(1,401):

    if MA*i > 400 or MB*i > 400: break

    ans = min(ans, dp[MA*i][MB*i])

print((-1 if ans == INF else ans))

N,MA,MB = list(map(int,input().split()))

src = [tuple(map(int,input().split())) for i in range(N)]

INF = 10**9

MAX = 401

dp = [[INF] * MAX for i in range(MAX)]

dp[0][0] = 0

amax = bmax = 0

for a,b,n in src:

    for i in reversed(list(range(bmax+1))):

        for j in range(amax+1):

            if dp[i][j] == INF: continue

            dp[i+b][j+a] = min(dp[i+b][j+a], dp[i][j] + n)

    amax += a

    bmax += b

ans = INF

for i in range(1,MAX):

    if i*MA >= MAX or i*MB >= MAX: break

    ans = min(ans, dp[i*MB][i*MA])

print((-1 if ans == INF else ans))

N, MA, MB = list(map(int, input().split()))
src = [tuple(map(int, input().split())) for i in range(N)]
INF = 10**9
dp = [[INF for j in range(401)] for i in range(401)]
dp[0][0] = 0
maxa = maxb = 0
for a, b, c in src:
    for ai in range(maxa, -1, -1):
        for bi in range(maxb, -1, -1):
            dp[ai + a][bi + b] = min(dp[ai + a][bi + b], dp[ai][bi] + c)
    maxa += a
    maxb += b
ans = INF
for i in range(1, 401):
    if MA * i > 400 or MB * i > 400:
        break
    ans = min(ans, dp[MA * i][MB * i])
print((-1 if ans == INF else ans))

N, MA, MB = list(map(int, input().split()))
src = [tuple(map(int, input().split())) for i in range(N)]
INF = 10**9
MAX = 401
dp = [[INF] * MAX for i in range(MAX)]
dp[0][0] = 0
amax = bmax = 0
for a, b, n in src:
    for i in reversed(list(range(bmax + 1))):
        for j in range(amax + 1):
            if dp[i][j] == INF:
                continue
            dp[i + b][j + a] = min(dp[i + b][j + a], dp[i][j] + n)
    amax += a
    bmax += b
ans = INF
for i in range(1, MAX):
    if i * MA >= MAX or i * MB >= MAX:
        break
    ans = min(ans, dp[i * MB][i * MA])
print((-1 if ans == INF else ans))

-dp = [[INF for j in range(401)] for i in range(401)]

-            dp[ai + a][bi + b] = min(dp[ai + a][bi + b], dp[ai][bi] + c)

+    for i in reversed(list(range(bmax + 1))):


Input:
s = input()

a = s.find('A')

z = s[::-1].find('Z')

ans = len(s)-a-z

print(ans)

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

def solve():

  S = input()

  a = S.find('A')

  z = S[::-1].find('Z')

  ans = len(S)-a-z

  return ans

print((solve()))

s = input()
a = s.find("A")
z = s[::-1].find("Z")
ans = len(s) - a - z
print(ans)
# print(*ans, sep='\n')

def solve():
    S = input()
    a = S.find("A")
    z = S[::-1].find("Z")
    ans = len(S) - a - z
    return ans

print((solve()))

-s = input()
-a = s.find("A")
-z = s[::-1].find("Z")
-ans = len(s) - a - z
-print(ans)
-# print(*ans, sep='\n')
+def solve():
+    S = input()
+    a = S.find("A")
+    z = S[::-1].find("Z")
+    ans = len(S) - a - z
+    return ans
+
+
+print((solve()))


Input: _,t=open(0);n=eval(t.replace(' ','|'));print((len(bin(n&-n))-3))

_, t = open(0)
n = eval(t.replace(" ", "|"))
print((len(bin(n & -n)) - 3))


Input:
import statistics

N = int(input())

A = [int(a)-i-1 for i,a in enumerate(input().split(),1)]

b = statistics.median_low(A)

c = statistics.median_high(A)

d = sum([abs(x-b) for x in A])

e = sum([abs(x-c) for x in A])

print((min(d,e)))

N=int(input())

A=sorted(a-i-1 for i,a in enumerate(map(int,input().split())))

print((sum(abs(a-A[N//2]) for a in A)))

import statistics

N = int(input())
A = [int(a) - i - 1 for i, a in enumerate(input().split(), 1)]
b = statistics.median_low(A)
c = statistics.median_high(A)
d = sum([abs(x - b) for x in A])
e = sum([abs(x - c) for x in A])
print((min(d, e)))

N = int(input())
A = sorted(a - i - 1 for i, a in enumerate(map(int, input().split())))
print((sum(abs(a - A[N // 2]) for a in A)))

-A = [int(a) - i - 1 for i, a in enumerate(input().split(), 1)]

+A = sorted(a - i - 1 for i, a in enumerate(map(int, input().split())))

+print((sum(abs(a - A[N // 2]) for a in A)))


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

c = 0

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

  new = list(reversed(list(str(i))))

  if new == list(str(i)):

    c += 1

print(c)

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

c = 0

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

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

    c += 1

print(c)

a, b = list(map(int, input().split()))
c = 0
for i in range(a, b + 1):
    new = list(reversed(list(str(i))))
    if new == list(str(i)):
        c += 1
print(c)

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

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


Input:
import sys

input = sys.stdin.readline

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

hole = [0] * (N+1)

for i in range(M):

    hole[int(input())] = 1

if N == 1:

    print((1))

    exit()

if N == 2:

    if hole[1] == 1:

        print((1))

        exit()

    if hole[1] == 0:

        print((2))

        exit()

flg_one = False

flg_two = False

first = 1

second = 2

if hole[1] == 1:

    first = 0

    second = 1

    flg_one = True

if hole[2] == 1:

    first = 1

    second = 0

    flg_two = True

if flg_one and flg_two:

    print((0))

    exit()

for i in range(3,N):

    if hole[i] == 1:

        first = second

        second = 0

        continue

    tmp = first + second

    tmp %= 1000000007

    first = second

    second = tmp

tmp = first + second

tmp %= 1000000007

print(tmp)

MOD = 10**9 + 7

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

stairs = [0]*(N+1)

for _ in range(M):

    stairs[int(input())] = 1

if N == 1:

    print((1))

    exit()

ans = [0]*(N+1)

ans[1] = 1 if stairs[1] == 0 else 0

ans[2] = 1 + ans[1] if stairs[2] == 0 else 0

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

    if stairs[i] == 1:

        ans[i] = 0

        continue

    ans[i] = (ans[i-1] + ans[i-2]) % MOD

print((ans[N]))

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
hole = [0] * (N + 1)
for i in range(M):
    hole[int(input())] = 1
if N == 1:
    print((1))
    exit()
if N == 2:
    if hole[1] == 1:
        print((1))
        exit()
    if hole[1] == 0:
        print((2))
        exit()
flg_one = False
flg_two = False
first = 1
second = 2
if hole[1] == 1:
    first = 0
    second = 1
    flg_one = True
if hole[2] == 1:
    first = 1
    second = 0
    flg_two = True
if flg_one and flg_two:
    print((0))
    exit()
for i in range(3, N):
    if hole[i] == 1:
        first = second
        second = 0
        continue
    tmp = first + second
    tmp %= 1000000007
    first = second
    second = tmp
tmp = first + second
tmp %= 1000000007
print(tmp)

MOD = 10**9 + 7
N, M = list(map(int, input().split()))
stairs = [0] * (N + 1)
for _ in range(M):
    stairs[int(input())] = 1
if N == 1:
    print((1))
    exit()
ans = [0] * (N + 1)
ans[1] = 1 if stairs[1] == 0 else 0
ans[2] = 1 + ans[1] if stairs[2] == 0 else 0
for i in range(3, N + 1):
    if stairs[i] == 1:
        ans[i] = 0
        continue
    ans[i] = (ans[i - 1] + ans[i - 2]) % MOD
print((ans[N]))

+ans[2] = 1 + ans[1] if stairs[2] == 0 else 0


Input:
#!usr/bin/env python3

from collections import defaultdict

from collections import deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

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

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

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

def S(): return list(sys.stdin.readline())[:-1]

def IR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = I()

    return l

def LIR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = LI()

    return l

def SR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = S()

    return l

def LSR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = SR()

    return l

mod = 1000000007

#A

def A():

    s = S()

    t = S()

    if s+t == t[::-1]+s[::-1]:

        print("YES")

    else:

        print("NO")

#B

def B():

    n = I()

    for i in range(int(n**0.5)+2)[::-1]:

        if i*i <= n:

            print((i*i))

            quit()

#C

def C():

    n = I()

    a = LI()

    b = LI()

    c = LI()

    q = [0 for i in range(n)]

    ans = 0

    a.sort()

    b.sort()

    c.sort()

    for i in range(n):

        j = bisect.bisect_left(a,b[i])

        q[i] = j

    for i in range(n-1):

        q[i+1] += q[i]

    q.insert(0,0)

    for i in range(n):

        j = bisect.bisect_left(b,c[i])

        ans += q[j]

    print(ans)

#D

def D():

    def dijkstra():

        d = [float("inf") for i in range(k)]

        q = [[0,1]]

        d[1] = 0

        while q:

            dx,x = heappop(q)

            for y,dy in v[x]:

                if d[y] > dx+dy:

                    d[y] = dx+dy

                    heappush(q,[d[y],y])

        print((d[0]+1))

    k = I()

    if k == 1:

        print((1))

        quit()

    v = [[] for i in range(k)]

    for i in range(1,k):

        v[i].append([(i+1)%k,1])

        v[i].append([i*10%k,0])

    dijkstra()

#E

def E():

    return

#F

def F():

    return

#G

def G():

    return

#H

def H():

    return

#Solve

if __name__ == "__main__":

    D()

#!usr/bin/env python3

from collections import defaultdict,deque

from heapq import heappush, heappop

from itertools import permutations

import sys

import math

import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]

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

def LS():return [list(x) for x in sys.stdin.readline().split()]

def S():

    res = list(sys.stdin.readline())

    if res[-1] == "\n":

        return res[:-1]

    return res

def IR(n):

    return [I() for i in range(n)]

def LIR(n):

    return [LI() for i in range(n)]

def SR(n):

    return [S() for i in range(n)]

def LSR(n):

    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

mod = 1000000007

def solve():

    def v(n):

        return [n*10%k, (n+1)%k]

    k = I()

    d = [float("inf")]*k

    d[1] = 1

    q = deque([1])

    while q:

        x = q.popleft()

        vx = v(x)

        dx = d[x]

        for c in range(2):

            nd = dx+c

            y = vx[c]

            if nd < d[y]:

                d[y] = nd

                if c:

                    q.append(y)

                else:

                    q.appendleft(y)

    print((d[0]))

    return

#Solve

if __name__ == "__main__":

    solve()

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

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

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

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

def S():
    return list(sys.stdin.readline())[:-1]

def IR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = I()
    return l

def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = LI()
    return l

def SR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = S()
    return l

def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = SR()
    return l

mod = 1000000007
# A
def A():
    s = S()
    t = S()
    if s + t == t[::-1] + s[::-1]:
        print("YES")
    else:
        print("NO")

# B
def B():
    n = I()
    for i in range(int(n**0.5) + 2)[::-1]:
        if i * i <= n:
            print((i * i))
            quit()

# C
def C():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    q = [0 for i in range(n)]
    ans = 0
    a.sort()
    b.sort()
    c.sort()
    for i in range(n):
        j = bisect.bisect_left(a, b[i])
        q[i] = j
    for i in range(n - 1):
        q[i + 1] += q[i]
    q.insert(0, 0)
    for i in range(n):
        j = bisect.bisect_left(b, c[i])
        ans += q[j]
    print(ans)

# D
def D():
    def dijkstra():
        d = [float("inf") for i in range(k)]
        q = [[0, 1]]
        d[1] = 0
        while q:
            dx, x = heappop(q)
            for y, dy in v[x]:
                if d[y] > dx + dy:
                    d[y] = dx + dy
                    heappush(q, [d[y], y])
        print((d[0] + 1))

    k = I()
    if k == 1:
        print((1))
        quit()
    v = [[] for i in range(k)]
    for i in range(1, k):
        v[i].append([(i + 1) % k, 1])
        v[i].append([i * 10 % k, 0])
    dijkstra()

# E
def E():
    return

# F
def F():
    return

# G
def G():
    return

# H
def H():
    return

# Solve
if __name__ == "__main__":
    D()

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI():
    return [int(x) for x in sys.stdin.readline().split()]

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

def LS():
    return [list(x) for x in sys.stdin.readline().split()]

def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]

def LIR(n):
    return [LI() for i in range(n)]

def SR(n):
    return [S() for i in range(n)]

def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def v(n):
        return [n * 10 % k, (n + 1) % k]

    k = I()
    d = [float("inf")] * k
    d[1] = 1
    q = deque([1])
    while q:
        x = q.popleft()
        vx = v(x)
        dx = d[x]
        for c in range(2):
            nd = dx + c
            y = vx[c]
            if nd < d[y]:
                d[y] = nd
                if c:
                    q.append(y)
                else:
                    q.appendleft(y)
    print((d[0]))
    return

# Solve
if __name__ == "__main__":
    solve()

+from collections import defaultdict, deque

-    return list(map(int, sys.stdin.readline().split()))

+    return [int(x) for x in sys.stdin.readline().split()]

-    return list(map(list, sys.stdin.readline().split()))

+    return [list(x) for x in sys.stdin.readline().split()]

-    return list(sys.stdin.readline())[:-1]

-        j = bisect.bisect_left(a, b[i])

-        j = bisect.bisect_left(b, c[i])

-        d = [float("inf") for i in range(k)]

-                    heappush(q, [d[y], y])


Input:
import math

x = int(input())

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

n = int(input())

fact = 1

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

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

res = fact % (10**9 + 7)

print(res)

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

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


Input:
# coding: utf-8

def solve(*args: str) -> str:

    k = int(args[0])

    l = 9*(k//7 if k % 7 == 0 else k)

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

        return '-1'

    r = phi = l

    for i in range(2, int(-pow(l, 1/2))):

        if r % i == 0:

            phi = phi//i*(i-1)

            while r % i:

                r //= i

    a = 10 % l

    ret = 1

    while(a != 1):

        a = a*10 % l

        ret += 1

        if phi < ret:

            ret = -1

            break

    return str(ret)

if __name__ == "__main__":

    print((solve(*(open(0).read().splitlines()))))

# coding: utf-8

from math import sqrt

def solve(*args: str) -> str:

    k = int(args[0])

    l = 9*(k//7 if 0 == k % 7 else k)

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

        return '-1'

    r = phi = l

    for i in range(2, int(sqrt(l)+1)):

        if 0 == r % i:

            phi = phi*(i-1)//i

            while 0 == r % i:

                r //= i

    if 1 < r:

        phi = phi*(r-1)//r

    D = set()

    for d in range(1, int(sqrt(phi)+1)):

        if 0 == phi % d:

            D.add(d)

            D.add(phi//d)

    ret = -1

    for m in sorted(D):

        if 1 == pow(10, m, l):

            ret = m

            break

    return str(ret)

if __name__ == "__main__":

    print((solve(*(open(0).read().splitlines()))))

# coding: utf-8
def solve(*args: str) -> str:
    k = int(args[0])
    l = 9 * (k // 7 if k % 7 == 0 else k)
    if l % 2 == 0 or l % 5 == 0:
        return "-1"
    r = phi = l
    for i in range(2, int(-pow(l, 1 / 2))):
        if r % i == 0:
            phi = phi // i * (i - 1)
            while r % i:
                r //= i
    a = 10 % l
    ret = 1
    while a != 1:
        a = a * 10 % l
        ret += 1
        if phi < ret:
            ret = -1
            break
    return str(ret)

if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))

# coding: utf-8
from math import sqrt

def solve(*args: str) -> str:
    k = int(args[0])
    l = 9 * (k // 7 if 0 == k % 7 else k)
    if 0 == l % 2 or 0 == l % 5:
        return "-1"
    r = phi = l
    for i in range(2, int(sqrt(l) + 1)):
        if 0 == r % i:
            phi = phi * (i - 1) // i
            while 0 == r % i:
                r //= i
    if 1 < r:
        phi = phi * (r - 1) // r
    D = set()
    for d in range(1, int(sqrt(phi) + 1)):
        if 0 == phi % d:
            D.add(d)
            D.add(phi // d)
    ret = -1
    for m in sorted(D):
        if 1 == pow(10, m, l):
            ret = m
            break
    return str(ret)

if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))

-    for i in range(2, int(-pow(l, 1 / 2))):

+    for i in range(2, int(sqrt(l) + 1)):

+    for d in range(1, int(sqrt(phi) + 1)):


Input:
import sys

sys.setrecursionlimit(100000)

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

fib={0:0,1:1,2:1}

for i in range(3,100003):

    fib[i]=fib[i-1]+fib[i-2]

  #  fib.append(fib[i-1]+fib[i-2])

n,m=intinput()

mod=10**9+7

a=[int(sys.stdin.readline()) for _ in range(m)]

if m!=0:

    l=[a[0]]

    for i in range(len(a)-1):

        l.append(a[i+1]-a[i]-1)

    l.append(n-a[-1])

    k=1

    for i in l:

        k=fib[i]*k%mod

    print((k%mod))

else:

    print((fib[n+1]%mod))

import sys

sys.setrecursionlimit(100000)

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

n, m = intinput()

a = {int(sys.stdin.readline()) for _ in range(m)}

memo = [0 for x in range(n + 4)]

memo[0] = 1

mod = 10 ** 9 + 7

for i in range(n):

    if i + 1 not in a:

        memo[i + 1] = (memo[i + 1] + memo[i]) % mod

    if i + 2 not in a:

        memo[i + 2] = (memo[i + 2] + memo[i]) % mod

print((memo[n]))

import sys

sys.setrecursionlimit(100000)

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

fib = {0: 0, 1: 1, 2: 1}
for i in range(3, 100003):
    fib[i] = fib[i - 1] + fib[i - 2]
#  fib.append(fib[i-1]+fib[i-2])
n, m = intinput()
mod = 10**9 + 7
a = [int(sys.stdin.readline()) for _ in range(m)]
if m != 0:
    l = [a[0]]
    for i in range(len(a) - 1):
        l.append(a[i + 1] - a[i] - 1)
    l.append(n - a[-1])
    k = 1
    for i in l:
        k = fib[i] * k % mod
    print((k % mod))
else:
    print((fib[n + 1] % mod))

import sys

sys.setrecursionlimit(100000)

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

n, m = intinput()
a = {int(sys.stdin.readline()) for _ in range(m)}
memo = [0 for x in range(n + 4)]
memo[0] = 1
mod = 10**9 + 7
for i in range(n):
    if i + 1 not in a:
        memo[i + 1] = (memo[i + 1] + memo[i]) % mod
    if i + 2 not in a:
        memo[i + 2] = (memo[i + 2] + memo[i]) % mod
print((memo[n]))

+a = {int(sys.stdin.readline()) for _ in range(m)}

-a = [int(sys.stdin.readline()) for _ in range(m)]

+        memo[i + 1] = (memo[i + 1] + memo[i]) % mod

+        memo[i + 2] = (memo[i + 2] + memo[i]) % mod


Input:
N = int(input())

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

answer = 10 ** 9

for i in range(1,101):

    tmp = 0

    for a in A:

        tmp += abs(a-i) ** 2

    answer = min(answer,tmp)

print(answer)

N = int(input())

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

chushin = sum(A)//N

chushin_1 = sum(A)//N +1

answer = 0

answer_1 = 0

for a in A:

    answer += abs(a-chushin) ** 2

    answer_1 += abs(a-chushin_1) ** 2

print((min(answer,answer_1)))

N = int(input())
A = list(map(int, input().split()))
answer = 10**9
for i in range(1, 101):
    tmp = 0
    for a in A:
        tmp += abs(a - i) ** 2
    answer = min(answer, tmp)
print(answer)

N = int(input())
A = list(map(int, input().split()))
chushin = sum(A) // N
chushin_1 = sum(A) // N + 1
answer = 0
answer_1 = 0
for a in A:
    answer += abs(a - chushin) ** 2
    answer_1 += abs(a - chushin_1) ** 2
print((min(answer, answer_1)))

+    answer_1 += abs(a - chushin_1) ** 2


Input:
"""

challenge case

in:

3

1 3

2 3

out:

1

1

1

"""

from collections import deque

def main():

	N, *AB = list(map(int, open(0).read().split()))

	B = AB[1::2]

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

	for a, b in zip(*[iter(AB)] * 2):

		E[a] += b,

	Q = deque([1])

	C = [0] * (N + 1)

	while Q:

		v = Q.popleft()

		c = 0

		for u in E[v]:

			c += 1 + (c + 1 == C[v])

			C[u] = c

			Q += u,

	print((max(C)))

	for b in B:

		print((C[b]))

main()

"""

challenge case

in:

3

1 3

2 3

out:

1

1

1

"""

from collections import deque

def main():

	N, *AB = list(map(int, open(0).read().split()))

	B = AB[1::2]

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

	for a, b in zip(*[iter(AB)] * 2):

		E[a].append(b)

	Q = deque([1])

	C = [0] * (N + 1)

	while Q:

		v = Q.popleft()

		c = 0

		for u in E[v]:

			c += 1 + (c + 1 == C[v])

			C[u] = c

			Q.append(u)

	print((max(C)))

	for b in B:

		print((C[b]))

main()

"""
challenge case
in:
3
1 3
2 3
out:
1
1
1
"""
from collections import deque

def main():
    N, *AB = list(map(int, open(0).read().split()))
    B = AB[1::2]
    E = [[] for _ in range(N + 1)]
    for a, b in zip(*[iter(AB)] * 2):
        E[a] += (b,)
    Q = deque([1])
    C = [0] * (N + 1)
    while Q:
        v = Q.popleft()
        c = 0
        for u in E[v]:
            c += 1 + (c + 1 == C[v])
            C[u] = c
            Q += (u,)
    print((max(C)))
    for b in B:
        print((C[b]))

main()


Input:
import sys

input = sys.stdin.buffer.readline

from collections import defaultdict

import copy

def main():

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

    d = defaultdict(int)

    MOD = 10**9+7

    R = 10**5+100

    fac = [0 for _ in range(R+1)]

    fac[0],fac[1] = 1,1

    inv = copy.deepcopy(fac)

    invfac = copy.deepcopy(fac)

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

        fac[i] = (fac[i-1]*i)%MOD

        inv[i] = MOD-(MOD//i)*inv[MOD%i]%MOD

        invfac[i] = (invfac[i-1]*inv[i])%MOD

    def coef(x,y):

        num = (((fac[x+y]*invfac[y])%MOD)*invfac[x]%MOD)

        return num

    while M%2 == 0:

        d[2] += 1

        M //= 2

    f = 3

    while f ** 2 <= M:

        if M % f == 0:

            d[f] += 1

            M //= f

        else:

            f += 2

    if M != 1:

        d[M] += 1

    l = list(d.values())

    ans = 1

    for num in l:

        ans *= coef(num,N-1)

        ans %= MOD

    print(ans)

if __name__ == "__main__":

    main()

import sys

input = sys.stdin.buffer.readline

def main():

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

    MOD = 10**9+7

    def factorization(n):

        arr = []

        temp = n

        for i in range(2, int(-(-n**0.5//1))+1):

            if temp%i==0:

                cnt=0

                while temp%i==0:

                    cnt+=1

                    temp //= i

                arr.append([i, cnt])

        if temp!=1:

            arr.append([temp, 1])

        return arr

    cl = factorization(M)

    def combinations(x,y,N):

        fac = [0]*(N+1)

        fac[0],fac[1] = 1,1

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

            fac[i] = (fac[i-1]*i)%MOD

        return (fac[x+y]*pow(fac[x],MOD-2,MOD)*pow(fac[y],MOD-2,MOD))%MOD

    ans = 1

    for pr,num in cl:

        ans *= combinations(N-1,num,N+num)

        ans %= MOD

    print(ans)

if __name__ == "__main__":

    main()

import sys

input = sys.stdin.buffer.readline
from collections import defaultdict
import copy

def main():
    N, M = list(map(int, input().split()))
    d = defaultdict(int)
    MOD = 10**9 + 7
    R = 10**5 + 100
    fac = [0 for _ in range(R + 1)]
    fac[0], fac[1] = 1, 1
    inv = copy.deepcopy(fac)
    invfac = copy.deepcopy(fac)
    for i in range(2, R + 1):
        fac[i] = (fac[i - 1] * i) % MOD
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        invfac[i] = (invfac[i - 1] * inv[i]) % MOD

    def coef(x, y):
        num = ((fac[x + y] * invfac[y]) % MOD) * invfac[x] % MOD
        return num

    while M % 2 == 0:
        d[2] += 1
        M //= 2
    f = 3
    while f**2 <= M:
        if M % f == 0:
            d[f] += 1
            M //= f
        else:
            f += 2
    if M != 1:
        d[M] += 1
    l = list(d.values())
    ans = 1
    for num in l:
        ans *= coef(num, N - 1)
        ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.buffer.readline

def main():
    N, M = list(map(int, input().split()))
    MOD = 10**9 + 7

    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-(n**0.5) // 1)) + 1):
            if temp % i == 0:
                cnt = 0
                while temp % i == 0:
                    cnt += 1
                    temp //= i
                arr.append([i, cnt])
        if temp != 1:
            arr.append([temp, 1])
        return arr

    cl = factorization(M)

    def combinations(x, y, N):
        fac = [0] * (N + 1)
        fac[0], fac[1] = 1, 1
        for i in range(2, N + 1):
            fac[i] = (fac[i - 1] * i) % MOD
        return (
            fac[x + y] * pow(fac[x], MOD - 2, MOD) * pow(fac[y], MOD - 2, MOD)
        ) % MOD

    ans = 1
    for pr, num in cl:
        ans *= combinations(N - 1, num, N + num)
        ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()

-        fac[i] = (fac[i - 1] * i) % MOD

-        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD

-        invfac[i] = (invfac[i - 1] * inv[i]) % MOD

-        num = ((fac[x + y] * invfac[y]) % MOD) * invfac[x] % MOD

+            fac[i] = (fac[i - 1] * i) % MOD

+            fac[x + y] * pow(fac[x], MOD - 2, MOD) * pow(fac[y], MOD - 2, MOD)

+        ans *= combinations(N - 1, num, N + num)


Input:
from collections import Counter

d={chr(i):0 for i in range(2)}

s=Counter(input())

d=d.update(s)

print((min(s["0"],s["1"])*2))

from collections import Counter

d = {chr(i): 0 for i in range(2)}
s = Counter(input())
d = d.update(s)
print((min(s["0"], s["1"]) * 2))

s = input()
print((min(s.count("0"), s.count("1")) * 2))


Input:
from functools import reduce
def f(a,b): return [Card[a][0], Card[b][1]]

n = int(input())

Card = [[] for _ in [0]*n]

Cost = {}

for i in range(n):

  Card[i] = list(map(int, input().split()))

  Cost[(i, i)] = 0

for i in range(1, n):

  for j in range(0, n-i):

    a = j+i

    Cost[(j, a)] = min([reduce(lambda a,b: a*b, f(j, k) + f(k+1, a)) + Cost[(j, k)] + Cost[(k+1, a)] for k in range(j, j+i)])

print(Cost[0, n-1])

from functools import reduce
n = int(input())

Card = [[] for _ in [0]*n]

Cost = {}

for i in range(n):

  Card[i] = list(map(int, input().split()))

  Cost[(i, i)] = 0

for i in range(1, n):

  for j in range(0, n-i):

    a = j+i

    Cost[(j, a)] = min([reduce(lambda a,b: a*b, [Card[j][0],Card[k][1],Card[k+1][0],Card[a][1]]) + Cost[(j, k)] + Cost[(k+1, a)] for k in range(j, j+i)])

print(Cost[0, n-1])

from functools import reduce

def f(a, b):
    return [Card[a][0], Card[b][1]]

n = int(input())
Card = [[] for _ in [0] * n]
Cost = {}
for i in range(n):
    Card[i] = list(map(int, input().split()))
    Cost[(i, i)] = 0
for i in range(1, n):
    for j in range(0, n - i):
        a = j + i
        Cost[(j, a)] = min(
            [
                reduce(lambda a, b: a * b, f(j, k) + f(k + 1, a))
                + Cost[(j, k)]
                + Cost[(k + 1, a)]
                for k in range(j, j + i)
            ]
        )
print(Cost[0, n - 1])

from functools import reduce

n = int(input())
Card = [[] for _ in [0] * n]
Cost = {}
for i in range(n):
    Card[i] = list(map(int, input().split()))
    Cost[(i, i)] = 0
for i in range(1, n):
    for j in range(0, n - i):
        a = j + i
        Cost[(j, a)] = min(
            [
                reduce(
                    lambda a, b: a * b,
                    [Card[j][0], Card[k][1], Card[k + 1][0], Card[a][1]],
                )
                + Cost[(j, k)]
                + Cost[(k + 1, a)]
                for k in range(j, j + i)
            ]
        )
print(Cost[0, n - 1])

-                reduce(lambda a, b: a * b, f(j, k) + f(k + 1, a))

+                    lambda a, b: a * b,


Input:
def cmb(n, r, mod):

    if ( r<0 or r>n ):

        return 0

    r = min(r, n-r)

    return g1[n] * g2[r] * g2[n-r] % mod

A=2*10**5

mod = 10**9+7

g1 = [1, 1]

g2 = [1, 1]

inverse = [0, 1]

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

    g1.append( ( g1[-1] * i ) % mod )

    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )

    g2.append( (g2[-1] * inverse[-1]) % mod )

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

keisuu=cmb(N*M-2,K-2,mod)

sum_=0

for i in range(N):

    a=min(abs(i),abs(N-i-1))

    b=max(abs(i),abs(N-i-1))

    sum_+=(M**2)*((a*(a+1)//2)+(b*(b+1)//2))

for i in range(M):

    a=min(abs(i),abs(M-i-1))

    b=max(abs(i),abs(M-i-1))

    sum_+=(N**2)*((a*(a+1)//2)+(b*(b+1)//2))

print(((keisuu * (sum_//2))%mod))

def power_mod(a,b,mod=10**9+7):

    i,temp,box=0,b,[]

    while(2**i<=b):

        i+=1

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

        box=[[j,temp//2**j]]+box

        temp-=2**j*(temp//2**j)

    box[0].append(a)

    ans=box[0][1]*a%mod

    for j in range(1,i):

        box[j].append(box[j-1][2]**2%mod)

        if box[j][1]==1:

            ans=(ans*box[j][2])%mod

    return ans

def n_func(n,mod=10**9+7):

    ans=1

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

        ans=(ans*i)%mod

    return ans

def nPr(n,r,mod=10**9+7):

    ans=n_func(n-r,mod)

    ans=power_mod(ans,mod-2,mod)

    return ans*n_func(n,mod)%mod

def nCr(n,r,mod=10**9+7):

    ans=n_func(n-r,mod)*n_func(r,mod)%mod

    ans=power_mod(ans,mod-2,mod)

    return ans*n_func(n,mod)%mod

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

keisuu=nCr(N*M-2,K-2)

mod=10**9+7

sum_=0

for i in range(N):

    a=min(abs(i),abs(N-i-1))

    b=max(abs(i),abs(N-i-1))

    sum_+=(M**2)*((a*(a+1)//2)+(b*(b+1)//2))

for i in range(M):

    a=min(abs(i),abs(M-i-1))

    b=max(abs(i),abs(M-i-1))

    sum_+=(N**2)*((a*(a+1)//2)+(b*(b+1)//2))

print(((keisuu * (sum_//2))%mod))

def cmb(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod

A = 2 * 10**5
mod = 10**9 + 7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, A + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)
N, M, K = list(map(int, input().split()))
keisuu = cmb(N * M - 2, K - 2, mod)
sum_ = 0
for i in range(N):
    a = min(abs(i), abs(N - i - 1))
    b = max(abs(i), abs(N - i - 1))
    sum_ += (M**2) * ((a * (a + 1) // 2) + (b * (b + 1) // 2))
for i in range(M):
    a = min(abs(i), abs(M - i - 1))
    b = max(abs(i), abs(M - i - 1))
    sum_ += (N**2) * ((a * (a + 1) // 2) + (b * (b + 1) // 2))
print(((keisuu * (sum_ // 2)) % mod))

def power_mod(a, b, mod=10**9 + 7):
    i, temp, box = 0, b, []
    while 2**i <= b:
        i += 1
    for j in range(i - 1, -1, -1):
        box = [[j, temp // 2**j]] + box
        temp -= 2**j * (temp // 2**j)
    box[0].append(a)
    ans = box[0][1] * a % mod
    for j in range(1, i):
        box[j].append(box[j - 1][2] ** 2 % mod)
        if box[j][1] == 1:
            ans = (ans * box[j][2]) % mod
    return ans

def n_func(n, mod=10**9 + 7):
    ans = 1
    for i in range(1, n + 1):
        ans = (ans * i) % mod
    return ans

def nPr(n, r, mod=10**9 + 7):
    ans = n_func(n - r, mod)
    ans = power_mod(ans, mod - 2, mod)
    return ans * n_func(n, mod) % mod

def nCr(n, r, mod=10**9 + 7):
    ans = n_func(n - r, mod) * n_func(r, mod) % mod
    ans = power_mod(ans, mod - 2, mod)
    return ans * n_func(n, mod) % mod

N, M, K = list(map(int, input().split()))
keisuu = nCr(N * M - 2, K - 2)
mod = 10**9 + 7
sum_ = 0
for i in range(N):
    a = min(abs(i), abs(N - i - 1))
    b = max(abs(i), abs(N - i - 1))
    sum_ += (M**2) * ((a * (a + 1) // 2) + (b * (b + 1) // 2))
for i in range(M):
    a = min(abs(i), abs(M - i - 1))
    b = max(abs(i), abs(M - i - 1))
    sum_ += (N**2) * ((a * (a + 1) // 2) + (b * (b + 1) // 2))
print(((keisuu * (sum_ // 2)) % mod))

-    return g1[n] * g2[r] * g2[n - r] % mod

+        box[j].append(box[j - 1][2] ** 2 % mod)

+            ans = (ans * box[j][2]) % mod

+    ans = n_func(n - r, mod) * n_func(r, mod) % mod

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

-    inverse.append((-inverse[mod % i] * (mod // i)) % mod)

-    g2.append((g2[-1] * inverse[-1]) % mod)

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


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

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

a.append(a[0]+k)

longd=0

for i in range(n):

    tmp=abs(a[i+1]-a[i])

    longd=max(longd,tmp)

print((k-longd))

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

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

a.append(a[0]+k)

x=0

for i in range(len(a)-1):

    dis=abs(a[i+1]-a[i])

    x=max(x,dis)

print((k-x))

k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(a[0] + k)
longd = 0
for i in range(n):
    tmp = abs(a[i + 1] - a[i])
    longd = max(longd, tmp)
print((k - longd))

k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(a[0] + k)
x = 0
for i in range(len(a) - 1):
    dis = abs(a[i + 1] - a[i])
    x = max(x, dis)
print((k - x))

-longd = 0
-for i in range(n):
-    tmp = abs(a[i + 1] - a[i])
-    longd = max(longd, tmp)
-print((k - longd))
+x = 0
+for i in range(len(a) - 1):
+    dis = abs(a[i + 1] - a[i])
+    x = max(x, dis)
+print((k - x))


Input:
def ii():return int(input())

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

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

def ism():return list(map(str,input().split()))

def isl():return list(map(str,input().split()))

n = ii()

D = iil()

ans = 0

for i in range(n):

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

#        print(i,j)

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

print(ans)

def ii():return int(input())

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

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

def ism():return list(map(str,input().split()))

def isl():return list(map(str,input().split()))

n = ii()

D = iil()

sumD = sum(D)

ans = 0

for i in range(n):

    ans += D[i]*(sum(D)-D[i])

print((ans//2))

def ii():
    return int(input())

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

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

def ism():
    return list(map(str, input().split()))

def isl():
    return list(map(str, input().split()))

n = ii()
D = iil()
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        #        print(i,j)
        ans += D[i] * D[j]
print(ans)

def ii():
    return int(input())

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

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

def ism():
    return list(map(str, input().split()))

def isl():
    return list(map(str, input().split()))

n = ii()
D = iil()
sumD = sum(D)
ans = 0
for i in range(n):
    ans += D[i] * (sum(D) - D[i])
print((ans // 2))

+sumD = sum(D)
-    for j in range(i + 1, n):
-        #        print(i,j)
-        ans += D[i] * D[j]
-print(ans)
+    ans += D[i] * (sum(D) - D[i])
+print((ans // 2))


Input:
S = input()

K = int(input())

a = list(set(S))

a.sort()

k = []

l = 0

while l < len(a):

    for i in range(len(S)):

        if S[i] == a[l]:

            for j in range(1,6):

                if i+j <= len(S):

                    k.append(S[i:i+j])

                else:

                    break

    l += 1

k = list(set(k))

k.sort()

print((k[K-1]))

S = input()

K = int(input())

a = []

for i in range(len(S)+1):

    for j in range(1,6):

        if i+j <= len(S):

            a.append(S[i:i+j])

        else:

            break

a = list(set(a))

a.sort()

print((a[K-1]))

S = input()
K = int(input())
a = list(set(S))
a.sort()
k = []
l = 0
while l < len(a):
    for i in range(len(S)):
        if S[i] == a[l]:
            for j in range(1, 6):
                if i + j <= len(S):
                    k.append(S[i : i + j])
                else:
                    break
    l += 1
k = list(set(k))
k.sort()
print((k[K - 1]))

S = input()
K = int(input())
a = []
for i in range(len(S) + 1):
    for j in range(1, 6):
        if i + j <= len(S):
            a.append(S[i : i + j])
        else:
            break
a = list(set(a))
a.sort()
print((a[K - 1]))

-                    k.append(S[i : i + j])


Input:
s = input()[::-1]

l = len(s)

c = [0] * 2019

c[0] = 1

ten = 1

mod = 0

ans = 0

for i in range(l):

    mod = (mod + int(s[i]) * ten) % 2019

    ten = ten * 10 % 2019

    c[mod] += 1

for i in c:

    ans += i * (i - 1) // 2

print(ans)


Input:
S=input()

print((S.rfind('Z')-S.find('A')+1))

s=input().strip()

a = s.find('A')

z = s.rfind('Z')

print((z-a+1))

S = input()
print((S.rfind("Z") - S.find("A") + 1))

s = input().strip()
a = s.find("A")
z = s.rfind("Z")
print((z - a + 1))

-print((S.rfind("Z") - S.find("A") + 1))


Input:
#!usr/bin/env python3

from collections import defaultdict

from collections import deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

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

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

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

def S(): return list(sys.stdin.readline())[:-1]

def IR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = I()

    return l

def LIR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = LI()

    return l

def SR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = S()

    return l

def LSR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = LS()

    return l

sys.setrecursionlimit(1000000)

mod = 1000000007

#A

def A():

    return

#B

def B():

    return

#C

def C():

    return

#D

def D():

    return

#E

def E():

    return

#F

def F():

    a,b,c,X,Y = LI()

    ans = float("inf")

    for z in range(300001):

        if z%2 == 0:

            m = c*z

            x = z//2

            y = z//2

            m += a*max(0,X-x)

            m += b*max(0,Y-y)

            if m < ans:

                ans = m

    print(ans)

    return

#G

def G():

    n = I()

    x = LI()

    f = [(i,x[i]) for i in range(n)]

    f.sort(key = lambda x:x[1])

    g = [(f[i][0],i) for i in range(n)]

    g.sort(key = lambda x:x[0])

    for i in range(n):

        if g[i][1] < n//2:

            print((f[n//2][1]))

        else:

            print((f[n//2-1][1]))

    return

#H

def H():

    return

#I

def I_():

    return

#J

def J():

    return

#Solve

if __name__ == "__main__":

    F()

#!usr/bin/env python3

from collections import defaultdict,deque

from heapq import heappush, heappop

from itertools import permutations

import sys

import math

import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]

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

def LS():return [list(x) for x in sys.stdin.readline().split()]

def S():

    res = list(sys.stdin.readline())

    if res[-1] == "\n":

        return res[:-1]

    return res

def IR(n):

    return [I() for i in range(n)]

def LIR(n):

    return [LI() for i in range(n)]

def SR(n):

    return [S() for i in range(n)]

def LSR(n):

    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

mod = 1000000007

def solve():

    A,B,C,x,y = LI()

    ans = float("inf")

    for c in range(200001)[::2]:

        a = b = c >> 1

        a = max(0,x-a)

        b = max(0,y-b)

        s = A*a+B*b+C*c

        if s < ans:

            ans = s

    print(ans)

    return

#Solve

if __name__ == "__main__":

    solve()

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

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

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

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

def S():
    return list(sys.stdin.readline())[:-1]

def IR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = I()
    return l

def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = LI()
    return l

def SR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = S()
    return l

def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = LS()
    return l

sys.setrecursionlimit(1000000)
mod = 1000000007
# A
def A():
    return

# B
def B():
    return

# C
def C():
    return

# D
def D():
    return

# E
def E():
    return

# F
def F():
    a, b, c, X, Y = LI()
    ans = float("inf")
    for z in range(300001):
        if z % 2 == 0:
            m = c * z
            x = z // 2
            y = z // 2
            m += a * max(0, X - x)
            m += b * max(0, Y - y)
            if m < ans:
                ans = m
    print(ans)
    return

# G
def G():
    n = I()
    x = LI()
    f = [(i, x[i]) for i in range(n)]
    f.sort(key=lambda x: x[1])
    g = [(f[i][0], i) for i in range(n)]
    g.sort(key=lambda x: x[0])
    for i in range(n):
        if g[i][1] < n // 2:
            print((f[n // 2][1]))
        else:
            print((f[n // 2 - 1][1]))
    return

# H
def H():
    return

# I
def I_():
    return

# J
def J():
    return

# Solve
if __name__ == "__main__":
    F()

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI():
    return [int(x) for x in sys.stdin.readline().split()]

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

def LS():
    return [list(x) for x in sys.stdin.readline().split()]

def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]

def LIR(n):
    return [LI() for i in range(n)]

def SR(n):
    return [S() for i in range(n)]

def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    A, B, C, x, y = LI()
    ans = float("inf")
    for c in range(200001)[::2]:
        a = b = c >> 1
        a = max(0, x - a)
        b = max(0, y - b)
        s = A * a + B * b + C * c
        if s < ans:
            ans = s
    print(ans)
    return

# Solve
if __name__ == "__main__":
    solve()

+from collections import defaultdict, deque

-    return list(map(int, sys.stdin.readline().split()))

+    return [int(x) for x in sys.stdin.readline().split()]

-    return list(map(list, sys.stdin.readline().split()))

+    return [list(x) for x in sys.stdin.readline().split()]

-    return list(sys.stdin.readline())[:-1]

-    g = [(f[i][0], i) for i in range(n)]


Input:
n = int(input()) % 1000

if n == 0:

    print((0))

else:

    print((1000 - n))


Input:
L ,R = list(map(int,input().split()))

ans =[]

if R - L <= 2019:

    for i in range(L,R+1):

        for j in range(i+1,R+1):

            ans.append(i*j%2019)

else:

    for i in range(R-L-1010,R-L+1010):

        for j in range(i,R-L+1010):

            ans.append(i*j%2019)

print((min(ans)))

L ,R = list(map(int,input().split()))

ans =[]

for i in range(L,R+1):

    for j in range(i+1,R+1):

        ans.append(i*j%2019)

        if (i * j % 2019) == 0:

            break

    else:

        continue

    break

print((min(ans)))

L, R = list(map(int, input().split()))
ans = []
if R - L <= 2019:
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            ans.append(i * j % 2019)
else:
    for i in range(R - L - 1010, R - L + 1010):
        for j in range(i, R - L + 1010):
            ans.append(i * j % 2019)
print((min(ans)))

L, R = list(map(int, input().split()))
ans = []
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        ans.append(i * j % 2019)
        if (i * j % 2019) == 0:
            break
    else:
        continue
    break
print((min(ans)))

-        for j in range(i, R - L + 1010):


Input:
from collections import Counter

import heapq

n = int(input())

ss = []

for _ in range(n):

    ss.append(input().rstrip())

ctr = Counter(ss)

heap = [(-v, k) for k, v in list(ctr.items())]

heapq.heapify(heap)

maxv = heap[0][0]

while heap:

    c = heapq.heappop(heap)

    if c[0] != maxv:

        break

    print((c[1]))

from collections import Counter

n = int(input())

ss = []

for _ in range(n):

    ss.append(input().rstrip())

ctr = Counter(ss)

a = sorted([(-v, k) for k, v in list(ctr.items())])

maxv = a[0][0]

for i in range(len(a)):

    if a[i][0] != maxv:

        break

    print((a[i][1]))

-heap = [(-v, k) for k, v in list(ctr.items())]

+a = sorted([(-v, k) for k, v in list(ctr.items())])


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

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

L, R = [None] * M, [None] * M

for i in range(M):

    L[i], R[i] = list(map(int, input().split()))

l = max(L)

r = min(R)

ans = max(r - l + 1, 0)

print(ans)

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

import sys

input = sys.stdin.readline

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

L, R = [None] * M, [None] * M

for i in range(M):

    L[i], R[i] = list(map(int, input().split()))

ans = max(min(R) - max(L) + 1, 0)

print(ans)

+import sys
+
+input = sys.stdin.readline
-l = max(L)
-r = min(R)
-ans = max(r - l + 1, 0)
+ans = max(min(R) - max(L) + 1, 0)


Input:
import math

input_num = int(input())

num_sqrt = int(math.sqrt(input_num))

minimam = input_num

for i in range(num_sqrt+1,0,-1):

    q, mod = divmod(input_num, i)

    distance = q + i -2

    if mod == 0 and minimam > distance:

        minimam = distance

print(minimam)

import math

def main1():

    input_num = int(input())

    num_sqrt = int(math.sqrt(input_num))

    minimam = input_num

    for i in range(num_sqrt+1,0,-1):

        q, mod = divmod(input_num, i)

        if mod == 0:

            distance = q + i -2

            if minimam > distance:

                minimam = distance

    print(minimam)

main1()

import math

input_num = int(input())
num_sqrt = int(math.sqrt(input_num))
minimam = input_num
for i in range(num_sqrt + 1, 0, -1):
    q, mod = divmod(input_num, i)
    distance = q + i - 2
    if mod == 0 and minimam > distance:
        minimam = distance
print(minimam)

import math

def main1():
    input_num = int(input())
    num_sqrt = int(math.sqrt(input_num))
    minimam = input_num
    for i in range(num_sqrt + 1, 0, -1):
        q, mod = divmod(input_num, i)
        if mod == 0:
            distance = q + i - 2
            if minimam > distance:
                minimam = distance
    print(minimam)

main1()

-    if mod == 0 and minimam > distance:

+    num_sqrt = int(math.sqrt(input_num))

+    for i in range(num_sqrt + 1, 0, -1):


Input:
# C - Walk on Multiplication Table

# https://atcoder.jp/contests/abc144/tasks/abc144_c

n = int(input())

ans = 10 ** 12

for i in range(1, 10 ** 6 + 1):

  if n % i == 0:

    ans = min(ans, n // i + i)

print((ans - 2))

# C - Walk on Multiplication Table

# https://atcoder.jp/contests/abc144/tasks/abc144_c

n = int(input())

ans = n

for i in range(1, int(n**.5) + 2):

  if n % i == 0:

    ans = min(ans, n // i + i - 2)

print(ans)

# C - Walk on Multiplication Table
# https://atcoder.jp/contests/abc144/tasks/abc144_c
n = int(input())
ans = 10**12
for i in range(1, 10**6 + 1):
    if n % i == 0:
        ans = min(ans, n // i + i)
print((ans - 2))

# C - Walk on Multiplication Table
# https://atcoder.jp/contests/abc144/tasks/abc144_c
n = int(input())
ans = n
for i in range(1, int(n**0.5) + 2):
    if n % i == 0:
        ans = min(ans, n // i + i - 2)
print(ans)

-ans = 10**12
-for i in range(1, 10**6 + 1):
+ans = n
+for i in range(1, int(n**0.5) + 2):
-        ans = min(ans, n // i + i)
-print((ans - 2))
+        ans = min(ans, n // i + i - 2)
+print(ans)


Input:
# AGC003B - Simplified mahjong

import sys

input = sys.stdin.readline

def main():

    # split in subsequences when 0 appears -> sum up cur // 2

    N = int(input())

    A = list(map(int, [input() for _ in range(N)])) + [0]

    ans, cur = 0, 0

    for i in A:

        if i:

            cur += i

        else:

            ans += cur // 2

            cur = 0

    print(ans)

if __name__ == "__main__":

    main()

# AGC003B - Simplified mahjong

def main():

    # split in subsequences when 0 appears -> sum up cur // 2

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

    A.append(0)

    ans, cur = 0, 0

    for i in A:

        if i:

            cur += i

        else:

            ans += cur // 2

            cur = 0

    print(ans)

if __name__ == "__main__":

    main()

-    A = list(map(int, [input() for _ in range(N)])) + [0]

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


Input:
while True:

    (n, x) = [int(i) for i in input().split()]

    if n == x == 0:

        break

    count = 0

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

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

            for c in range(b + 1, n + 1):

                if sum([a,b,c]) == x:

                    count += 1

    print(count)

while True:

    (n, x) = [int(i) for i in input().split()]

    if n == x == 0:

        break

    count = 0

    limit = n if n < x else x

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

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

            for c in range(b + 1, limit + 1):

                if sum([a,b,c]) == x:

                    count += 1

    print(count)

while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0:
        break
    count = 0
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            for c in range(b + 1, n + 1):
                if sum([a, b, c]) == x:
                    count += 1
    print(count)

while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0:
        break
    count = 0
    limit = n if n < x else x
    for a in range(1, limit + 1):
        for b in range(a + 1, limit + 1):
            for c in range(b + 1, limit + 1):
                if sum([a, b, c]) == x:
                    count += 1
    print(count)

-            for c in range(b + 1, n + 1):

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

+            for c in range(b + 1, limit + 1):


Input:
from collections import deque

N = 3

m = {8: {7, 5}, 7: {8, 6, 4}, 6: {7, 3}, 5: {8, 4, 2}, 4: {7, 5, 3, 1}, 3: {6, 4, 0}, 2: {5, 1}, 1: {4, 2, 0},

     0: {3, 1}}

goal = 123456780

def g(i, j, a):

    t = a // (10 ** j) % 10

    return a - t * (10 ** j) + t * (10 ** i)

def solve():

    MAP = "".join(input().replace(" ", "") for _ in range(N))

    start = 8 - MAP.find("0")

    MAP = int(MAP)

    if MAP == goal:

        return 0

    dp = deque([(0, start, MAP)])

    LOG = {MAP}

    while dp:

        cnt, yx, M = dp.popleft()

        if M == goal:

            return cnt

        cnt += 1

        for nyx in m[yx]:

            CM = g(yx, nyx, M)

            if not CM in LOG:

                dp.append((cnt, nyx, CM))

                LOG.add(CM)

def MAIN():

    print((solve()))

MAIN()

from collections import deque

N = 3

m = {8: {7, 5}, 7: {8, 6, 4}, 6: {7, 3}, 5: {8, 4, 2}, 4: {7, 5, 3, 1}, 3: {6, 4, 0}, 2: {5, 1}, 1: {4, 2, 0},

     0: {3, 1}}

goal = 123456780

def g(i, j, a):

    t = a // (10 ** j) % 10

    return a - t * (10 ** j) + t * (10 ** i)

def solve():

    MAP = "".join(input().replace(" ", "") for _ in range(N))

    zero = 8 - MAP.find("0")

    start = int(MAP)

    if start == goal:

        return 0

    dp = deque([(0, start, zero, 1), (0, goal, 0, 0)])

    TABLE = {start: (1, 0), goal: (0, 0)}

    while dp:

        cnt, M, yx, flg = dp.popleft()

        cnt += 1

        for nyx in m[yx]:

            key = g(yx, nyx, M)

            if key in TABLE:

                if TABLE[key][0] != flg:

                    return TABLE[key][1] + cnt

                continue

            TABLE[key] = (flg, cnt)

            dp.append((cnt, key, nyx, flg))

def MAIN():

    print((solve()))

MAIN()

from collections import deque

N = 3
m = {
    8: {7, 5},
    7: {8, 6, 4},
    6: {7, 3},
    5: {8, 4, 2},
    4: {7, 5, 3, 1},
    3: {6, 4, 0},
    2: {5, 1},
    1: {4, 2, 0},
    0: {3, 1},
}
goal = 123456780

def g(i, j, a):
    t = a // (10**j) % 10
    return a - t * (10**j) + t * (10**i)

def solve():
    MAP = "".join(input().replace(" ", "") for _ in range(N))
    start = 8 - MAP.find("0")
    MAP = int(MAP)
    if MAP == goal:
        return 0
    dp = deque([(0, start, MAP)])
    LOG = {MAP}
    while dp:
        cnt, yx, M = dp.popleft()
        if M == goal:
            return cnt
        cnt += 1
        for nyx in m[yx]:
            CM = g(yx, nyx, M)
            if not CM in LOG:
                dp.append((cnt, nyx, CM))
                LOG.add(CM)

def MAIN():
    print((solve()))

MAIN()

from collections import deque

N = 3
m = {
    8: {7, 5},
    7: {8, 6, 4},
    6: {7, 3},
    5: {8, 4, 2},
    4: {7, 5, 3, 1},
    3: {6, 4, 0},
    2: {5, 1},
    1: {4, 2, 0},
    0: {3, 1},
}
goal = 123456780

def g(i, j, a):
    t = a // (10**j) % 10
    return a - t * (10**j) + t * (10**i)

def solve():
    MAP = "".join(input().replace(" ", "") for _ in range(N))
    zero = 8 - MAP.find("0")
    start = int(MAP)
    if start == goal:
        return 0
    dp = deque([(0, start, zero, 1), (0, goal, 0, 0)])
    TABLE = {start: (1, 0), goal: (0, 0)}
    while dp:
        cnt, M, yx, flg = dp.popleft()
        cnt += 1
        for nyx in m[yx]:
            key = g(yx, nyx, M)
            if key in TABLE:
                if TABLE[key][0] != flg:
                    return TABLE[key][1] + cnt
                continue
            TABLE[key] = (flg, cnt)
            dp.append((cnt, key, nyx, flg))

def MAIN():
    print((solve()))

MAIN()

-                dp.append((cnt, nyx, CM))

+                if TABLE[key][0] != flg:

+                    return TABLE[key][1] + cnt

+            dp.append((cnt, key, nyx, flg))


Input:
inf = (5000 * 10 ** 5) * 3

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

ret = inf

for cnt_ab in range(max(x, y) * 2 + 1):

    d = cnt_ab // 2

    cnt_a = max(0, x - d)

    cnt_b = max(0, y - d)

    t = cnt_ab * c + cnt_a * a + cnt_b * b

    ret = min(ret, t)

print(ret)

def main():

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

    M = max(X, Y)

    k = 0

    ans = A * X + B * Y

    while True:

        ans = min(

            ans,

            AB * k * 2 + max(0, X - k) * A + max(0, Y - k) * B

        )

        if k >= M: break

        k += 1

    print(ans)

if __name__ == '__main__':

    main()

inf = (5000 * 10**5) * 3
a, b, c, x, y = list(map(int, input().split()))
ret = inf
for cnt_ab in range(max(x, y) * 2 + 1):
    d = cnt_ab // 2
    cnt_a = max(0, x - d)
    cnt_b = max(0, y - d)
    t = cnt_ab * c + cnt_a * a + cnt_b * b
    ret = min(ret, t)
print(ret)

def main():
    A, B, AB, X, Y = list(map(int, input().split()))
    M = max(X, Y)
    k = 0
    ans = A * X + B * Y
    while True:
        ans = min(ans, AB * k * 2 + max(0, X - k) * A + max(0, Y - k) * B)
        if k >= M:
            break
        k += 1
    print(ans)

if __name__ == "__main__":
    main()

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

-for cnt_ab in range(max(x, y) * 2 + 1):

-    t = cnt_ab * c + cnt_a * a + cnt_b * b

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

+        ans = min(ans, AB * k * 2 + max(0, X - k) * A + max(0, Y - k) * B)


Input:
S = int(input())

f = [0]*(S+1)

f[0] = 1

if S >= 3: f[3] = 1

if S >= 4: f[4] = 1

if S >= 5: f[5] = 1

for i in range(6, S+1):

    f[i] = sum(f[i-j] for j in range(3, i+1))%(10**9+7)

print((f[S]))


Input:
import sys

input = sys.stdin.buffer.readline

N, Ma, Mb = list(map(int, input().split()))

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

INF = 10 ** 15

dp = [[INF for j in range(401)] for i in range(401)]

dp[0][0] = 0

for a, b, c in ABC:

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

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

      if dp[i][j] != INF:

        dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)

answer = INF

for i in range(1, 401):

  for j in range(1, 401):

    if dp[i][j] != INF and i / j == Ma / Mb:

      answer = min(answer, dp[i][j])

print((answer if answer != INF else -1))

import sys

input = sys.stdin.buffer.readline

N, Ma, Mb = list(map(int, input().split()))

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

sumA = sum([ABC[i][0] for i in range(N)])

sumB = sum([ABC[i][1] for i in range(N)])

INF = 10 ** 15

dp = [[INF for j in range(sumB + 1)] for i in range(sumA + 1)]

dp[0][0] = 0

for a, b, c in ABC:

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

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

      if dp[i][j] != INF:

        dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)

answer = INF

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

  for j in range(1, sumB + 1):

    if dp[i][j] != INF and i / j == Ma / Mb:

      answer = min(answer, dp[i][j])

print((answer if answer != INF else -1))

import sys

input = sys.stdin.buffer.readline
N, Ma, Mb = list(map(int, input().split()))
ABC = [list(map(int, input().split())) for _ in range(N)]
INF = 10**15
dp = [[INF for j in range(401)] for i in range(401)]
dp[0][0] = 0
for a, b, c in ABC:
    for i in range(400, -1, -1):
        for j in range(400, -1, -1):
            if dp[i][j] != INF:
                dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)
answer = INF
for i in range(1, 401):
    for j in range(1, 401):
        if dp[i][j] != INF and i / j == Ma / Mb:
            answer = min(answer, dp[i][j])
print((answer if answer != INF else -1))

import sys

input = sys.stdin.buffer.readline
N, Ma, Mb = list(map(int, input().split()))
ABC = [list(map(int, input().split())) for _ in range(N)]
sumA = sum([ABC[i][0] for i in range(N)])
sumB = sum([ABC[i][1] for i in range(N)])
INF = 10**15
dp = [[INF for j in range(sumB + 1)] for i in range(sumA + 1)]
dp[0][0] = 0
for a, b, c in ABC:
    for i in range(sumA, -1, -1):
        for j in range(sumB, -1, -1):
            if dp[i][j] != INF:
                dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)
answer = INF
for i in range(1, sumA + 1):
    for j in range(1, sumB + 1):
        if dp[i][j] != INF and i / j == Ma / Mb:
            answer = min(answer, dp[i][j])
print((answer if answer != INF else -1))

+sumA = sum([ABC[i][0] for i in range(N)])

+sumB = sum([ABC[i][1] for i in range(N)])

-dp = [[INF for j in range(401)] for i in range(401)]

+dp = [[INF for j in range(sumB + 1)] for i in range(sumA + 1)]


Input:
from sys import stdin, stdout, setrecursionlimit

from collections import deque, defaultdict, Counter

from heapq import heappush, heappop

from functools import lru_cache

import math

setrecursionlimit(10**6)

rl = lambda: stdin.readline()

rll = lambda: stdin.readline().split()

rli = lambda: list(map(int, stdin.readline().split()))

rlf = lambda: list(map(float, stdin.readline().split()))

INF, NINF = float('inf'), float('-inf')

MOD = 10**9 + 7

def main():

	s = int(rl())

	@lru_cache(None)

	def dp(currsum):

		if currsum == s: return 1

		cnt = 0

		for d in range(3, 2001):

			if currsum + d <= s:

				cnt += dp(currsum + d)

				cnt %= MOD

		return cnt

	print((dp(0)))

	stdout.close()

if __name__ == "__main__":

	main()

from sys import stdin, stdout, setrecursionlimit

from collections import deque, defaultdict, Counter

from heapq import heappush, heappop

from functools import lru_cache

import math

#setrecursionlimit(10**6)

rl = lambda: stdin.readline()

rll = lambda: stdin.readline().split()

rli = lambda: list(map(int, stdin.readline().split()))

rlf = lambda: list(map(float, stdin.readline().split()))

INF, NINF = float('inf'), float('-inf')

MOD = 10**9 + 7

def main():

	s = int(rl())

	def binom_tables(n, q):

		fact = [1 for _ in range(n + 1)]

		inv = [1 for _ in range(n + 1)]

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

			fact[i] = (fact[i-1] * i) % q

			inv[i] = pow(fact[i], q-2, q)

		return fact, inv

	F, I = binom_tables(s + 700, MOD)

	def binom(n, k, q):

		return (F[n]*((I[k]*I[n-k])%q))%q

	ans = 0

	for r in range(1, 700):

		objects = s - 3*r

		if objects + r - 1 < objects or objects < 0:

			break

		x = binom(objects + r - 1, objects, MOD)

		ans += x

		ans %= MOD

	print(ans)

	stdout.close()

if __name__ == "__main__":

	main()

from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math

setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
rlf = lambda: list(map(float, stdin.readline().split()))
INF, NINF = float("inf"), float("-inf")
MOD = 10**9 + 7

def main():
    s = int(rl())

    @lru_cache(None)
    def dp(currsum):
        if currsum == s:
            return 1
        cnt = 0
        for d in range(3, 2001):
            if currsum + d <= s:
                cnt += dp(currsum + d)
                cnt %= MOD
        return cnt

    print((dp(0)))
    stdout.close()

if __name__ == "__main__":
    main()

from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math

# setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
rlf = lambda: list(map(float, stdin.readline().split()))
INF, NINF = float("inf"), float("-inf")
MOD = 10**9 + 7

def main():
    s = int(rl())

    def binom_tables(n, q):
        fact = [1 for _ in range(n + 1)]
        inv = [1 for _ in range(n + 1)]
        for i in range(1, n + 1):
            fact[i] = (fact[i - 1] * i) % q
            inv[i] = pow(fact[i], q - 2, q)
        return fact, inv

    F, I = binom_tables(s + 700, MOD)

    def binom(n, k, q):
        return (F[n] * ((I[k] * I[n - k]) % q)) % q

    ans = 0
    for r in range(1, 700):
        objects = s - 3 * r
        if objects + r - 1 < objects or objects < 0:
            break
        x = binom(objects + r - 1, objects, MOD)
        ans += x
        ans %= MOD
    print(ans)
    stdout.close()

if __name__ == "__main__":
    main()

+        fact = [1 for _ in range(n + 1)]

+        inv = [1 for _ in range(n + 1)]

+            fact[i] = (fact[i - 1] * i) % q

+            inv[i] = pow(fact[i], q - 2, q)

+        if objects + r - 1 < objects or objects < 0:

+        x = binom(objects + r - 1, objects, MOD)


Input:
import math

n=int(input())

print(((2*n)//math.gcd(2,n)))

N=int(input());print((N if N%2==0 else N*2))

import math

n = int(input())
print(((2 * n) // math.gcd(2, n)))

N = int(input())
print((N if N % 2 == 0 else N * 2))

-import math
-n = int(input())
-print(((2 * n) // math.gcd(2, n)))
+N = int(input())
+print((N if N % 2 == 0 else N * 2))


Input:
import sys

s = input()

ts = ['']

while True:

  nts= []

  for t in ts:

    for w in ['dreamer', 'eraser', 'dream', 'erase']:

      if s == t + w:

        print('YES')

        sys.exit()

      if s.startswith(t + w):

        nts.append(t + w)

  if len(nts) == 0:

    print('NO')

    sys.exit()

  ts = nts

from sys import exit

s = input()

ts = ['']

while True:

  nts= []

  for t in ts:

    for w in ['dreamer', 'eraser', 'dream', 'erase']:

      tw = t + w

      if s == tw:

        print('YES')

        exit()

      if s.startswith(tw):

        nts.append(tw)

  if len(nts) == 0:

    print('NO')

    exit()

  ts = nts

import sys

s = input()
ts = [""]
while True:
    nts = []
    for t in ts:
        for w in ["dreamer", "eraser", "dream", "erase"]:
            if s == t + w:
                print("YES")
                sys.exit()
            if s.startswith(t + w):
                nts.append(t + w)
    if len(nts) == 0:
        print("NO")
        sys.exit()
    ts = nts

from sys import exit

s = input()
ts = [""]
while True:
    nts = []
    for t in ts:
        for w in ["dreamer", "eraser", "dream", "erase"]:
            tw = t + w
            if s == tw:
                print("YES")
                exit()
            if s.startswith(tw):
                nts.append(tw)
    if len(nts) == 0:
        print("NO")
        exit()
    ts = nts

-import sys
+from sys import exit
-s = input()
+s = input()
-            if s == t + w:
+            tw = t + w
+            if s == tw:
-                sys.exit()
-            if s.startswith(t + w):
-                nts.append(t + w)
+                exit()
+            if s.startswith(tw):
+                nts.append(tw)
-        sys.exit()
+        exit()


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

a = [[0]*N]*K

a = [[0 for n in range(N)] for k in range(K)]

for k in range(K):

    d=int(input())

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

    for h in have_k:

        a[k][h-1]=1

an=[0]*N

for k in range(K):

  for n in range(N):

    an[n] = an[n]+a[k][n]

result=0

for i in an:

  if i == 0:

    result+=1

print(result)

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

a = [[0 for n in range(N)] for k in range(K)]

for k in range(K):

    d=int(input())

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

    for h in have_k:

        a[k][h-1]=1

an=[0]*N

for k in range(K):

  for n in range(N):

    an[n] = an[n]+a[k][n]

result=0

for i in an:

  if i == 0:

    result+=1

print(result)

N, K = list(map(int, input().split()))
a = [[0] * N] * K
a = [[0 for n in range(N)] for k in range(K)]
for k in range(K):
    d = int(input())
    have_k = list(map(int, input().split()))
    for h in have_k:
        a[k][h - 1] = 1
an = [0] * N
for k in range(K):
    for n in range(N):
        an[n] = an[n] + a[k][n]
result = 0
for i in an:
    if i == 0:
        result += 1
print(result)

N, K = list(map(int, input().split()))
a = [[0 for n in range(N)] for k in range(K)]
for k in range(K):
    d = int(input())
    have_k = list(map(int, input().split()))
    for h in have_k:
        a[k][h - 1] = 1
an = [0] * N
for k in range(K):
    for n in range(N):
        an[n] = an[n] + a[k][n]
result = 0
for i in an:
    if i == 0:
        result += 1
print(result)


Input:
import sys

sys.setrecursionlimit(1000000)

S = input()

T = ['dream', 'dreamer', 'erase', 'eraser']

lenT = [len(i) for i in T]

def dayDream(pin):

    global isDream               #;print('dayDream: ', pin, S[pin:])

    for i, d in enumerate(T):

        #print('d:', d)

        if S[pin:pin+lenT[i]] == d:

            pout = pin + lenT[i] #; print(d, pout)

            if pout == len(S):

                isDream = True   #; print('YES')

                return

            else:

                dayDream(pout)

    #print('dayDream return', pin)

    return

isDream = False

dayDream(0)

if isDream:

    print('YES')

else:

    print('NO')

import sys

sys.setrecursionlimit(1000000)

S = input()

T = ['dream', 'dreamer', 'erase', 'eraser']

lenT = [len(i) for i in T]

def dayDream(pin):

    global isGoal               #;print('dayDream: ', pin, S[pin:])

    for i, d in enumerate(T):

        if isGoal:

            return

        #print('i, d:', i, d)

        if S[pin:pin+lenT[i]] == d:

            pout = pin + lenT[i] #;print(d, pout)

            if pout == len(S):

                isGoal = True    #;print('YES')

                return

            else:

                dayDream(pout)

    #print('dayDream return', pin)

    return

isGoal = False

dayDream(0)

if isGoal:

    print('YES')

else:

    print('NO')

import sys

sys.setrecursionlimit(1000000)
S = input()
T = ["dream", "dreamer", "erase", "eraser"]
lenT = [len(i) for i in T]

def dayDream(pin):
    global isDream  # ;print('dayDream: ', pin, S[pin:])
    for i, d in enumerate(T):
        # print('d:', d)
        if S[pin : pin + lenT[i]] == d:
            pout = pin + lenT[i]  # ; print(d, pout)
            if pout == len(S):
                isDream = True  # ; print('YES')
                return
            else:
                dayDream(pout)
    # print('dayDream return', pin)
    return

isDream = False
dayDream(0)
if isDream:
    print("YES")
else:
    print("NO")

import sys

sys.setrecursionlimit(1000000)
S = input()
T = ["dream", "dreamer", "erase", "eraser"]
lenT = [len(i) for i in T]

def dayDream(pin):
    global isGoal  # ;print('dayDream: ', pin, S[pin:])
    for i, d in enumerate(T):
        if isGoal:
            return
        # print('i, d:', i, d)
        if S[pin : pin + lenT[i]] == d:
            pout = pin + lenT[i]  # ;print(d, pout)
            if pout == len(S):
                isGoal = True  # ;print('YES')
                return
            else:
                dayDream(pout)
    # print('dayDream return', pin)
    return

isGoal = False
dayDream(0)
if isGoal:
    print("YES")
else:
    print("NO")

-    global isDream  # ;print('dayDream: ', pin, S[pin:])

+    global isGoal  # ;print('dayDream: ', pin, S[pin:])

-            pout = pin + lenT[i]  # ; print(d, pout)

+            pout = pin + lenT[i]  # ;print(d, pout)

-                isDream = True  # ; print('YES')

+                isGoal = True  # ;print('YES')