Input:
mod = 2019

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

if r//mod - l//mod > 0:

  print((0))

else:

  l %= mod

  r %= mod

  ans = mod

  for i in range(l+1, r+1):

    for j in range(l, i):

      ans = min(i*j%mod, ans)

    if ans == 0:

      break

  print(ans)

mod = 2019

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

if r//mod - l//mod > 0:

  print((0))

else:

  l %= mod

  r %= mod

  ans = mod

  for i in range(l, r):

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

      ans = min(i*j%mod, ans)

    if ans == 0:

      break

  print(ans)

mod = 2019
l, r = list(map(int, input().split()))
if r // mod - l // mod > 0:
    print((0))
else:
    l %= mod
    r %= mod
    ans = mod
    for i in range(l + 1, r + 1):
        for j in range(l, i):
            ans = min(i * j % mod, ans)
        if ans == 0:
            break
    print(ans)

mod = 2019
l, r = list(map(int, input().split()))
if r // mod - l // mod > 0:
    print((0))
else:
    l %= mod
    r %= mod
    ans = mod
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            ans = min(i * j % mod, ans)
        if ans == 0:
            break
    print(ans)

-    for i in range(l + 1, r + 1):
-        for j in range(l, i):
+    for i in range(l, r):
+        for j in range(i + 1, r + 1):


Input:
#!/usr/bin/env python3

n = int(input())

s = [input() for _ in range(n)]

c = [0 for _ in range(5)]

t = 'MARCH'

for i in range(n):

    for j in range(5):

        if s[i][0] == t[j]:

            c[j] += 1

ans = 0

for i in range(5):

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

        for k in range(j+1, 5):

            ans += c[i]*c[k]*c[j]

print(ans)

#!/usr/bin/env python3

n = int(input())

s = [input() for _ in range(n)]

d = {}

for c in s:

    if c[0] not in d:

        d[c[0]] = 1

    else:

        d[c[0]] += 1

tmp = d.copy()

t = ['M', 'A', 'R', 'C', 'H']

for c in tmp:

    if c not in t:

        d.pop(c)

ans = 0

dlist = list(d.items())

for i in range(len(dlist)):

    for j in range(i+1, len(dlist)):

        for k in range(j+1, len(dlist)):

            ans += dlist[i][1]*dlist[j][1]*dlist[k][1]

print(ans)

#!/usr/bin/env python3
n = int(input())
s = [input() for _ in range(n)]
c = [0 for _ in range(5)]
t = "MARCH"
for i in range(n):
    for j in range(5):
        if s[i][0] == t[j]:
            c[j] += 1
ans = 0
for i in range(5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            ans += c[i] * c[k] * c[j]
print(ans)

#!/usr/bin/env python3
n = int(input())
s = [input() for _ in range(n)]
d = {}
for c in s:
    if c[0] not in d:
        d[c[0]] = 1
    else:
        d[c[0]] += 1
tmp = d.copy()
t = ["M", "A", "R", "C", "H"]
for c in tmp:
    if c not in t:
        d.pop(c)
ans = 0
dlist = list(d.items())
for i in range(len(dlist)):
    for j in range(i + 1, len(dlist)):
        for k in range(j + 1, len(dlist)):
            ans += dlist[i][1] * dlist[j][1] * dlist[k][1]
print(ans)

+        for k in range(j + 1, len(dlist)):

+            ans += dlist[i][1] * dlist[j][1] * dlist[k][1]


Input:
prim=[True]*1000000

prim[0],prim[1]=False,False

for i in range(2,1000):

    if prim[i]:

        for j in range(i*2,1000000,i):

            prim[j]=False

prime=[i for i,j in enumerate(prim) if j==True]

while True:

    n=int(input())

    if n==0:

        break

    print((sum(prime[:n])))

prim=[True]*1000000

prim[0]=prim[1]=False

for i in range(2,350):

    if prim[i]:

        for j in range(i*2,110000,i):

            prim[j]=False

prime=[i for i,j in enumerate(prim) if j==True]

while True:

    n=int(input())

    if n==0:

        break

    print((sum(prime[:n])))

prim = [True] * 1000000
prim[0], prim[1] = False, False
for i in range(2, 1000):
    if prim[i]:
        for j in range(i * 2, 1000000, i):
            prim[j] = False
prime = [i for i, j in enumerate(prim) if j == True]
while True:
    n = int(input())
    if n == 0:
        break
    print((sum(prime[:n])))

prim = [True] * 1000000
prim[0] = prim[1] = False
for i in range(2, 350):
    if prim[i]:
        for j in range(i * 2, 110000, i):
            prim[j] = False
prime = [i for i, j in enumerate(prim) if j == True]
while True:
    n = int(input())
    if n == 0:
        break
    print((sum(prime[:n])))


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

gate = []

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

for i in range(1, m):

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

    if l < m:

        l = m

    if s < r:

        r = s

print((len([i for i in range(l, r + 1)])))

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

l, r = [0] * m, [0] * m

for i in range(m):

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

print((max(min(r) - max(l) + 1, 0)))

-    m, s = list(map(int, input().split()))

-print((len([i for i in range(l, r + 1)])))

+    l[i], r[i] = list(map(int, input().split()))


Input:
K=int(input())

if K%2==0:

    print((-1))

    exit(0)

ans=[0]*(pow(10,6)+1)

ans[0]=0

for i in range(1,pow(10,6)):

    ans[i]=(ans[i-1]*10+7)%K

    if ans[i]==0:

        print(i)

        exit(0)

print((-1))

import functools

K=int(input())

if K%2==0:

    print((-1))

    exit(0)

mod=0

for i in range(1,pow(10,6)):

    mod=(mod*10+7)%K

    if mod==0:

        print(i)

        exit(0)

print((-1))

import functools

K = int(input())
if K % 2 == 0:
    print((-1))
    exit(0)
mod = 0
for i in range(1, pow(10, 6)):
    mod = (mod * 10 + 7) % K
    if mod == 0:
        print(i)
        exit(0)
print((-1))


Input:
def segfunc(x, y): return max(x, y)

class SegmentTree:

    def __init__(self, arr):

        size = len(arr)

        n = 2 ** (size - 1).bit_length()

        self.n = n

        self.node = [0] * (2*n)

        for i in range(size):

            self.node[i+n-1] = arr[i]

        for i in reversed(list(range(n-2))):

            self.node[i] = segfunc(self.node[2*i+1], self.node[2*i+2])

    def update(self, i, x):

        i += self.n - 1

        self.node[i] = x

        while i > 0:

            i = (i - 1) // 2

            self.node[i] = segfunc(self.node[i * 2 + 1], self.node[i * 2 + 2])

    def update(self, x, val):

        x += (self.n - 1)

        self.node[x] = val

        while x > 0:

            x = (x - 1) // 2

            self.node[x] = segfunc(self.node[2 * x + 1], self.node[2 * x + 2])

    def query(self, a, b):

        res = 0

        l = self.n - 1 + a

        r = self.n - 1 + (b - 1)

        while l <= r:

            if l == r:

                res = segfunc(res, self.node[l])

                break

            if l % 2 == 0:

                res = segfunc(res, self.node[l])

            if r % 2 == 1:

                res = segfunc(res, self.node[r])

            l = l // 2

            r = r // 2 - 1

        return res

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

INF = 0

seg = SegmentTree([0] * 300000)

for i in range(N):

    a = int(input())

    tmp = seg.query(max(a - K, 0), min(a + K, 300000) + 1) + 1

    seg.update(a, tmp)

print((seg.query(0, 300000)))

def segfunc(x, y): return max(x, y)

def update(i, x):

    i += MAX_N-1

    node[i] = x

    while i:

        i = (i-1)//2

        node[i] = segfunc(node[i*2+1], node[i*2+2])

def query(l, r):

    L = l + MAX_N

    R = r + MAX_N

    s = INF

    while L < R:

        if R & 1:

            R -= 1

            s = segfunc(s, node[R - 1])

        if L & 1:

            s = segfunc(s, node[L - 1])

            L += 1

        L >>= 1

        R >>= 1

    return s

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

MAX_N = 2**(300005).bit_length()

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

node = [0] * (2 * MAX_N)

INF = 0

ans = 0

#for i in range(N):

#    update(i, a[i])

for i in a:

    tmp = query(max(i - K, 0), min(300005, i + K) + 1)

    update(i, tmp + 1)

    ans = max(ans, tmp + 1)

print(ans)

def segfunc(x, y):
    return max(x, y)

class SegmentTree:
    def __init__(self, arr):
        size = len(arr)
        n = 2 ** (size - 1).bit_length()
        self.n = n
        self.node = [0] * (2 * n)
        for i in range(size):
            self.node[i + n - 1] = arr[i]
        for i in reversed(list(range(n - 2))):
            self.node[i] = segfunc(self.node[2 * i + 1], self.node[2 * i + 2])

    def update(self, i, x):
        i += self.n - 1
        self.node[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.node[i] = segfunc(self.node[i * 2 + 1], self.node[i * 2 + 2])

    def update(self, x, val):
        x += self.n - 1
        self.node[x] = val
        while x > 0:
            x = (x - 1) // 2
            self.node[x] = segfunc(self.node[2 * x + 1], self.node[2 * x + 2])

    def query(self, a, b):
        res = 0
        l = self.n - 1 + a
        r = self.n - 1 + (b - 1)
        while l <= r:
            if l == r:
                res = segfunc(res, self.node[l])
                break
            if l % 2 == 0:
                res = segfunc(res, self.node[l])
            if r % 2 == 1:
                res = segfunc(res, self.node[r])
            l = l // 2
            r = r // 2 - 1
        return res

N, K = list(map(int, input().split()))
INF = 0
seg = SegmentTree([0] * 300000)
for i in range(N):
    a = int(input())
    tmp = seg.query(max(a - K, 0), min(a + K, 300000) + 1) + 1
    seg.update(a, tmp)
print((seg.query(0, 300000)))

def segfunc(x, y):
    return max(x, y)

def update(i, x):
    i += MAX_N - 1
    node[i] = x
    while i:
        i = (i - 1) // 2
        node[i] = segfunc(node[i * 2 + 1], node[i * 2 + 2])

def query(l, r):
    L = l + MAX_N
    R = r + MAX_N
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = segfunc(s, node[R - 1])
        if L & 1:
            s = segfunc(s, node[L - 1])
            L += 1
        L >>= 1
        R >>= 1
    return s

N, K = list(map(int, input().split()))
MAX_N = 2 ** (300005).bit_length()
a = [int(input()) for _ in range(N)]
node = [0] * (2 * MAX_N)
INF = 0
ans = 0
# for i in range(N):
#    update(i, a[i])
for i in a:
    tmp = query(max(i - K, 0), min(300005, i + K) + 1)
    update(i, tmp + 1)
    ans = max(ans, tmp + 1)
print(ans)

-        n = 2 ** (size - 1).bit_length()

-            self.node[i + n - 1] = arr[i]

-        for i in reversed(list(range(n - 2))):

-            self.node[i] = segfunc(self.node[2 * i + 1], self.node[2 * i + 2])

+        node[i] = segfunc(node[i * 2 + 1], node[i * 2 + 2])

-            self.node[i] = segfunc(self.node[i * 2 + 1], self.node[i * 2 + 2])

-            self.node[x] = segfunc(self.node[2 * x + 1], self.node[2 * x + 2])

-                res = segfunc(res, self.node[l])

-                res = segfunc(res, self.node[l])

-                res = segfunc(res, self.node[r])

+            s = segfunc(s, node[R - 1])

+            s = segfunc(s, node[L - 1])


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

L = []

R = []

for _ in range(M):

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

  L.append(l)

  R.append(r)

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

if ans < 0:

  print((0))

else:

  print(ans)

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

max_l = float("-inf")

min_r = float("inf")

for _ in range(m):

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

  max_l = max(max_l, l)

  min_r = min(min_r, r)

ans = min_r - max_l + 1

if ans > 0:

  print(ans)

else:

  print((0))

N, M = list(map(int, input().split()))
L = []
R = []
for _ in range(M):
    l, r = list(map(int, input().split()))
    L.append(l)
    R.append(r)
ans = min(R) - max(L) + 1
if ans < 0:
    print((0))
else:
    print(ans)

n, m = list(map(int, input().split()))
max_l = float("-inf")
min_r = float("inf")
for _ in range(m):
    l, r = list(map(int, input().split()))
    max_l = max(max_l, l)
    min_r = min(min_r, r)
ans = min_r - max_l + 1
if ans > 0:
    print(ans)
else:
    print((0))

-N, M = list(map(int, input().split()))
-L = []
-R = []
-for _ in range(M):
+n, m = list(map(int, input().split()))
+max_l = float("-inf")
+min_r = float("inf")
+for _ in range(m):
-    L.append(l)
-    R.append(r)
-ans = min(R) - max(L) + 1
-if ans < 0:
+    max_l = max(max_l, l)
+    min_r = min(min_r, r)
+ans = min_r - max_l + 1
+if ans > 0:
+    print(ans)
+else:
-else:
-    print(ans)


Input:
N = int(input())

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

cnt = 0

for num in seq:

    while num % 2 == 0:

        cnt += 1

        num /= 2

print(cnt)

n = int(input())

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

ans = 0

for num in a:

    ans += format(num, 'b')[::-1].find('1')

print(ans)

n = int(input())
a = list(map(int, input().split()))
ans = 0
for num in a:
    ans += format(num, "b")[::-1].find("1")
print(ans)


Input:
import sys

sys.setrecursionlimit(10 ** 6)

# input = sys.stdin.readline    ####

int1 = lambda x: int(x) - 1

def II(): return int(input())

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

def MI1(): return list(map(int1, input().split()))

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

def LI1(): return list(map(int1, input().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print((k.join(list(map(str, lst)))))

INF = float('inf')

def solve():

    a, b, c, x, y = MI()

    ans = INF

    for k in range(100001):

        yen = 2 * c * k + max(0, x-k) * a + max(0, y-k) * b

        ans = min(ans, yen)

    print(ans)

if __name__ == '__main__':

    solve()

import sys

sys.setrecursionlimit(10 ** 6)

# input = sys.stdin.readline    ####

int1 = lambda x: int(x) - 1

def II(): return int(input())

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

def MI1(): return list(map(int1, input().split()))

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

def LI1(): return list(map(int1, input().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print((k.join(list(map(str, lst)))))

INF = float('inf')

def solve():

    a, b, c, x, y = MI()

    ans = 0

    if a + b <= 2 * c:

        mn = min(x, y)

        ans = a * mn + b * mn + max(0, x-mn) * min(a, 2*c) + max(0, y-mn) * min(b, 2*c)

    else:

        mn = min(x, y)

        ans = mn * 2 * c + max(0, x-mn) * min(a, 2*c) + max(0, y-mn) * min(b, 2*c)

    print(ans)

if __name__ == '__main__':

    solve()

import sys

sys.setrecursionlimit(10**6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1

def II():
    return int(input())

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

def MI1():
    return list(map(int1, input().split()))

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

def LI1():
    return list(map(int1, input().split()))

def LLI(rows_number):
    return [LI() for _ in range(rows_number)]

def printlist(lst, k="\n"):
    print((k.join(list(map(str, lst)))))

INF = float("inf")

def solve():
    a, b, c, x, y = MI()
    ans = INF
    for k in range(100001):
        yen = 2 * c * k + max(0, x - k) * a + max(0, y - k) * b
        ans = min(ans, yen)
    print(ans)

if __name__ == "__main__":
    solve()

import sys

sys.setrecursionlimit(10**6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1

def II():
    return int(input())

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

def MI1():
    return list(map(int1, input().split()))

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

def LI1():
    return list(map(int1, input().split()))

def LLI(rows_number):
    return [LI() for _ in range(rows_number)]

def printlist(lst, k="\n"):
    print((k.join(list(map(str, lst)))))

INF = float("inf")

def solve():
    a, b, c, x, y = MI()
    ans = 0
    if a + b <= 2 * c:
        mn = min(x, y)
        ans = (
            a * mn
            + b * mn
            + max(0, x - mn) * min(a, 2 * c)
            + max(0, y - mn) * min(b, 2 * c)
        )
    else:
        mn = min(x, y)
        ans = (
            mn * 2 * c + max(0, x - mn) * min(a, 2 * c) + max(0, y - mn) * min(b, 2 * c)
        )
    print(ans)

if __name__ == "__main__":
    solve()


Input:
import math

n = int(input())

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

n = int(input())

ans = 1

mod = 10**9+7

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

    ans *= i

    ans %= mod

ans %= mod

print(ans)

import math

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

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

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


Input:
n,t=int(input()),list(map(int,input().split()));T=sum(t)

print(*[T-t[i-1]+j for i,j in [list(map(int,input().split())) for _ in range(int(input()))]],sep='\n')

input();t=list(map(int,input().split()));T=sum(t)

print(*[T-t[i-1]+j for i,j in [list(map(int,input().split())) for _ in range(int(input()))]],sep='\n')

n, t = int(input()), list(map(int, input().split()))
T = sum(t)
print(
    *[
        T - t[i - 1] + j
        for i, j in [list(map(int, input().split())) for _ in range(int(input()))]
    ],
    sep="\n"
)

input()
t = list(map(int, input().split()))
T = sum(t)
print(
    *[
        T - t[i - 1] + j
        for i, j in [list(map(int, input().split())) for _ in range(int(input()))]
    ],
    sep="\n"
)

-n, t = int(input()), list(map(int, input().split()))


Input:
n = int(input())

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

S = [0]*(n+1)

num={}

for i in range(n):

    S[i+1] = S[i] + A[i]

for i in S:

    if str(i) in list(num.keys()):

        num[str(i)] += 1

    else:

        num[str(i)] = 1

out = [i*(i-1)//2 for i in list(num.values()) if i>1]

print((sum(out)))

n = int(input())

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

S = [0]*(n+1)

num = {}

for i in range(n):

    S[i+1] = S[i] + A[i]

for i in S:

    s = str(i)

    num[s] = 1 if s not in list(num.keys()) else num[s]+1

out = [i*(i-1)//2 for i in list(num.values()) if i > 1]

print((sum(out)))

n = int(input())
A = [int(i) for i in input().split()]
S = [0] * (n + 1)
num = {}
for i in range(n):
    S[i + 1] = S[i] + A[i]
for i in S:
    if str(i) in list(num.keys()):
        num[str(i)] += 1
    else:
        num[str(i)] = 1
out = [i * (i - 1) // 2 for i in list(num.values()) if i > 1]
print((sum(out)))

n = int(input())
A = [int(i) for i in input().split()]
S = [0] * (n + 1)
num = {}
for i in range(n):
    S[i + 1] = S[i] + A[i]
for i in S:
    s = str(i)
    num[s] = 1 if s not in list(num.keys()) else num[s] + 1
out = [i * (i - 1) // 2 for i in list(num.values()) if i > 1]
print((sum(out)))

+    num[s] = 1 if s not in list(num.keys()) else num[s] + 1


Input:
def resolve():

  base = 10**9+7

  S = int(input())

  dp = [0] * (S+1)

  dp[0] = 1

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

    for u in range(i-2):

      dp[i] += dp[u]

      dp[i] %= base

  # print(dp)

  print((dp[S]%base))

if __name__ == "__main__":

  resolve()

def resolve():

  base = 10**9+7

  S = int(input())

  dp = [0] * (S+1)

  dp[0] = 1

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

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

  # print(dp)

  print((dp[S]%base))

if __name__ == "__main__":

  resolve()

def resolve():
    base = 10**9 + 7
    S = int(input())
    dp = [0] * (S + 1)
    dp[0] = 1
    for i in range(1, S + 1):
        for u in range(i - 2):
            dp[i] += dp[u]
            dp[i] %= base
    # print(dp)
    print((dp[S] % base))

if __name__ == "__main__":
    resolve()

def resolve():
    base = 10**9 + 7
    S = int(input())
    dp = [0] * (S + 1)
    dp[0] = 1
    for i in range(3, S + 1):
        dp[i] = dp[i - 1] + dp[i - 3]
    # print(dp)
    print((dp[S] % base))

if __name__ == "__main__":
    resolve()

-    for i in range(1, S + 1):
-        for u in range(i - 2):
-            dp[i] += dp[u]
-            dp[i] %= base
+    for i in range(3, S + 1):
+        dp[i] = dp[i - 1] + dp[i - 3]


Input:
N = int(input())

table = [[0]*10 for i in range(10)]

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

  s = str(i)

  id1 = int(s[0])

  id2 = int(s[-1])

  table[id1][id2] += 1

ans = 0

for i in range(10):

  for j in range(10):

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

print(ans)

N = int(input())
table = [[0] * 10 for i in range(10)]
for i in range(1, N + 1):
    s = str(i)
    id1 = int(s[0])
    id2 = int(s[-1])
    table[id1][id2] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += table[i][j] * table[j][i]
print(ans)

-        ans += table[i][j] * table[j][i]


Input:
n = int(input())

res = 1

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

  res = res * num

  res = res % (pow(10,9) + 7)

print(res)

n = int(input())

res = 1

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

    res = res * num

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

print(res)

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

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


Input:
#!/usr/bin/env python3

import sys, math, math, itertools

def solve(A: int, B: int, C: int, X: int, Y: int):

    mn = 1e9

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

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

    print((int(mn)))

    return

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

def main():

    def iterate_tokens():

        for line in sys.stdin:

            for word in line.split():

                yield word

    tokens = iterate_tokens()

    A = int(next(tokens))  # type: int

    B = int(next(tokens))  # type: int

    C = int(next(tokens))  # type: int

    X = int(next(tokens))  # type: int

    Y = int(next(tokens))  # type: int

    solve(A, B, C, X, Y)

if __name__ == '__main__':

    main()

#!/usr/bin/env python3

import sys

def solve(A: int, B: int, C: int, X: int, Y: int):

    c = 0

    if (A + B < 2 * C):

        c += min(X, Y) * (A + B)

    else:

        c += min(X, Y) * 2 * C

    if X > Y:

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

    else:

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

    print(c)

    return

# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

def main():

    def iterate_tokens():

        for line in sys.stdin:

            for word in line.split():

                yield word

    tokens = iterate_tokens()

    A = int(next(tokens))  # type: int

    B = int(next(tokens))  # type: int

    C = int(next(tokens))  # type: int

    X = int(next(tokens))  # type: int

    Y = int(next(tokens))  # type: int

    solve(A, B, C, X, Y)

if __name__ == '__main__':

    main()

#!/usr/bin/env python3
import sys, math, math, itertools

def solve(A: int, B: int, C: int, X: int, Y: int):
    mn = 1e9
    for i in range(0, 2 * (max(X, Y) + 1), 2):
        mn = min(mn, C * i + A * max(X - i // 2, 0) + B * max(Y - i // 2, 0))
    print((int(mn)))
    return

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(A, B, C, X, Y)

if __name__ == "__main__":
    main()

#!/usr/bin/env python3
import sys

def solve(A: int, B: int, C: int, X: int, Y: int):
    c = 0
    if A + B < 2 * C:
        c += min(X, Y) * (A + B)
    else:
        c += min(X, Y) * 2 * C
    if X > Y:
        c += (X - Y) * min(A, 2 * C)
    else:
        c += (Y - X) * min(B, 2 * C)
    print(c)
    return

# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(A, B, C, X, Y)

if __name__ == "__main__":
    main()

-# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

+# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)


Input:
N = int(input())

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

A=[0]*N

A[0]=B[0]

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

    A[i]=min(B[i],B[i-1])

A[-1]=B[-1]

print((sum(A)))

import sys

input = sys.stdin.readline

def I(): return int(input())

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

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

def main():

    mod=10**9+7

    N=I()

    B=LI()

    A=[0]*N

    A[0]=B[0]

    A[-1]=B[-1]

    for i in range(N-2):

        A[i+1]=min(B[i],B[i+1])

    print((sum(A)))

main()

N = int(input())
B = list(map(int, input().split()))
A = [0] * N
A[0] = B[0]
for i in range(1, N - 1):
    A[i] = min(B[i], B[i - 1])
A[-1] = B[-1]
print((sum(A)))

import sys

input = sys.stdin.readline

def I():
    return int(input())

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

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

def main():
    mod = 10**9 + 7
    N = I()
    B = LI()
    A = [0] * N
    A[0] = B[0]
    A[-1] = B[-1]
    for i in range(N - 2):
        A[i + 1] = min(B[i], B[i + 1])
    print((sum(A)))

main()

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


Input:
import sys

input = sys.stdin.readline

from collections import *

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

while True:

    C -= B

    if C<=0:

        print('Yes')

        exit()

    A -= D

    if A<=0:

        print('No')

        exit()

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

c1 = (C+B-1)//B

c2 = (A+D-1)//D

if c1<=c2:

    print('Yes')

else:

    print('No')

import sys

input = sys.stdin.readline
from collections import *

A, B, C, D = list(map(int, input().split()))
while True:
    C -= B
    if C <= 0:
        print("Yes")
        exit()
    A -= D
    if A <= 0:
        print("No")
        exit()

A, B, C, D = list(map(int, input().split()))
c1 = (C + B - 1) // B
c2 = (A + D - 1) // D
if c1 <= c2:
    print("Yes")
else:
    print("No")

-import sys
-input = sys.stdin.readline
-from collections import *
-while True:
-    C -= B
-    if C <= 0:
-        print("Yes")
-        exit()
-    A -= D
-    if A <= 0:
-        print("No")
-        exit()
+c1 = (C + B - 1) // B
+c2 = (A + D - 1) // D
+if c1 <= c2:
+    print("Yes")
+else:
+    print("No")


Input:
icase=0

if icase==0:

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

    a=[]

    b=[]

    for i in range(m):

        ai,bi=list(map(int, input().split()))

        a.append(ai)

        b.append(bi)

elif icase==1:

    n=6

    m=5

#    a=[[1],[2],[3],[4],[5]]

#    b=[[2],[3],[4],[5],[6]]

    a=[1,2,3,4,5]

    b=[2,3,4,5,6]

elif icase==2:

    n=7

    m=7

    a=[1,2,3,4,4,5,6]

    b=[3,7,4,5,6,6,7]

vtx=[]

for i in range(n):

    vtx.append([i+1])

icnt=0

for j in range(m):

    vtx1=vtx.copy()

    a1=a.copy()

    b1=b.copy()

    del a1[j]

    del b1[j]

    for i in range(m-1):

        for v1 in vtx1:

            if a1[i] in v1:

                if not b1[i] in v1:

                    for v2 in vtx1:

                        if v1!=v2:

                            if b1[i] in v2:

                                break

                    vtx1.remove(v1)

                    vtx1.remove(v2)

                    v3=v1+v2

                    vtx1.append(v3)

#        print(a[i],b[i],len(vtx1),vtx1)

#    print(len(vtx1),vtx1)

    if len(vtx1)!=1:

        icnt=icnt+1

print(icnt)

limit=50

graph=[[False]*limit for i in range(limit)]

visited=[]*limit

def dfs(v,n,graph,visited):

    visited[v]=True

    for v2 in range(n):

        if graph[v][v2]==False:

            continue

        if visited[v2]==True:

            continue

        dfs(v2,n,graph,visited)

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

a=[0]*m

b=[0]*m

for i in range(m):

    ai,bi=list(map(int,input().split()))

    a[i]=ai-1

    b[i]=bi-1

    graph[a[i]][b[i]]=True

    graph[b[i]][a[i]]=True

ans=0

for i in range(m):

    graph[a[i]][b[i]]=False

    graph[b[i]][a[i]]=False

    visited=[False]*n

    dfs(0,n,graph,visited)

    bridge=False

    for j in range(n):

        if visited[j]==False:

            bridge=True

    if bridge:

        ans+=1

    graph[a[i]][b[i]]=True

    graph[b[i]][a[i]]=True

print(ans)

icase = 0
if icase == 0:
    n, m = list(map(int, input().split()))
    a = []
    b = []
    for i in range(m):
        ai, bi = list(map(int, input().split()))
        a.append(ai)
        b.append(bi)
elif icase == 1:
    n = 6
    m = 5
    #    a=[[1],[2],[3],[4],[5]]
    #    b=[[2],[3],[4],[5],[6]]
    a = [1, 2, 3, 4, 5]
    b = [2, 3, 4, 5, 6]
elif icase == 2:
    n = 7
    m = 7
    a = [1, 2, 3, 4, 4, 5, 6]
    b = [3, 7, 4, 5, 6, 6, 7]
vtx = []
for i in range(n):
    vtx.append([i + 1])
icnt = 0
for j in range(m):
    vtx1 = vtx.copy()
    a1 = a.copy()
    b1 = b.copy()
    del a1[j]
    del b1[j]
    for i in range(m - 1):
        for v1 in vtx1:
            if a1[i] in v1:
                if not b1[i] in v1:
                    for v2 in vtx1:
                        if v1 != v2:
                            if b1[i] in v2:
                                break
                    vtx1.remove(v1)
                    vtx1.remove(v2)
                    v3 = v1 + v2
                    vtx1.append(v3)
    #        print(a[i],b[i],len(vtx1),vtx1)
    #    print(len(vtx1),vtx1)
    if len(vtx1) != 1:
        icnt = icnt + 1
print(icnt)

limit = 50
graph = [[False] * limit for i in range(limit)]
visited = [] * limit

def dfs(v, n, graph, visited):
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:
            continue
        if visited[v2] == True:
            continue
        dfs(v2, n, graph, visited)

n, m = list(map(int, input().split()))
a = [0] * m
b = [0] * m
for i in range(m):
    ai, bi = list(map(int, input().split()))
    a[i] = ai - 1
    b[i] = bi - 1
    graph[a[i]][b[i]] = True
    graph[b[i]][a[i]] = True
ans = 0
for i in range(m):
    graph[a[i]][b[i]] = False
    graph[b[i]][a[i]] = False
    visited = [False] * n
    dfs(0, n, graph, visited)
    bridge = False
    for j in range(n):
        if visited[j] == False:
            bridge = True
    if bridge:
        ans += 1
    graph[a[i]][b[i]] = True
    graph[b[i]][a[i]] = True
print(ans)

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

-        ai, bi = list(map(int, input().split()))

-                            if b1[i] in v2:

-    #        print(a[i],b[i],len(vtx1),vtx1)

+graph = [[False] * limit for i in range(limit)]

+    ai, bi = list(map(int, input().split()))


Input:
#!/usr/bin/env python3

import sys

from math import gcd

import math

def main():

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

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

    tmp = 1

    count = None

    for i in range(N):

      tmp = (tmp * a[i]//2) // gcd(tmp,a[i]//2)

      c = 0

      n = a[i]//2

      while n % 2 == 0:

        c += 1

        n //= 2

      if i == 0:

        count = c

      elif count != c:

        print((0))

        exit()

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

if __name__ == '__main__':

    main()

from math import gcd

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

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

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

LCM = 1

for i in range(N):

    LCM = LCM * B[i] // gcd(LCM, B[i])

for i in range(N):

    if LCM // B[i] % 2 == 0:

        print((0))

        exit()

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

#!/usr/bin/env python3
import sys
from math import gcd
import math

def main():
    N, M = list(map(int, input().split()))
    a = list(map(int, input().split()))
    tmp = 1
    count = None
    for i in range(N):
        tmp = (tmp * a[i] // 2) // gcd(tmp, a[i] // 2)
        c = 0
        n = a[i] // 2
        while n % 2 == 0:
            c += 1
            n //= 2
        if i == 0:
            count = c
        elif count != c:
            print((0))
            exit()
    print(((M // tmp + 1) // 2))

if __name__ == "__main__":
    main()

from math import gcd

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [a // 2 for a in A]
LCM = 1
for i in range(N):
    LCM = LCM * B[i] // gcd(LCM, B[i])
for i in range(N):
    if LCM // B[i] % 2 == 0:
        print((0))
        exit()
print(((M // LCM + 1) // 2))

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

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


Input:
a=input().split()

b=list(map(int,a))

W=b[0]

H=b[1]

x=b[2]

y=b[3]

r=b[4]

if (r <= x <= (W - r)) and (r <= y <= (H - r)):

  print('Yes')

else:

  print('No')

W,H,x,y,r = [int(i) for i in input().split()]

if (r <= x <= (W - r)) and (r <= y <= (H - r)):

  print('Yes')

else:

  print('No')

a = input().split()
b = list(map(int, a))
W = b[0]
H = b[1]
x = b[2]
y = b[3]
r = b[4]
if (r <= x <= (W - r)) and (r <= y <= (H - r)):
    print("Yes")
else:
    print("No")

W, H, x, y, r = [int(i) for i in input().split()]
if (r <= x <= (W - r)) and (r <= y <= (H - r)):
    print("Yes")
else:
    print("No")

+W, H, x, y, r = [int(i) for i in input().split()]


Input:
ia = [int(i) for i in input().split(" ")]

W=ia[0]

H=ia[1]

x=ia[2]

y=ia[3]

r=ia[4]

print(("Yes" if 0<=x-r and x+r<=W and 0<=y-r and y+r<=H else "No"))

# encoding:utf-8

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

W, H, x, y, r = input

if x - r < 0 or x + r > W:

	print("No")

elif y - r < 0 or y + r > H:

	print("No")

else:

	print("Yes")

ia = [int(i) for i in input().split(" ")]
W = ia[0]
H = ia[1]
x = ia[2]
y = ia[3]
r = ia[4]
print(("Yes" if 0 <= x - r and x + r <= W and 0 <= y - r and y + r <= H else "No"))

-ia = [int(i) for i in input().split(" ")]

-print(("Yes" if 0 <= x - r and x + r <= W and 0 <= y - r and y + r <= H else "No"))

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


Input:
N=input()

a=[]

t=True

for _ in range(int(N)):

    a+=[list(map(int,input().split()))]

for i in range(int(N)):

    if a[i][0]%2==0:

        if abs(a[i][1]+a[i][2])<=a[i][0] and (a[i][1]+a[i][2])%2==0:

            continue

        else:

            print('No')

            t=False

            break

    else:

        if abs(a[i][1]+a[i][2]<=a[i][0]) and (a[i][1]+a[i][2])%2==1:

            continue

        else:

            print('No')

            t=False

            break

if t:

    print('Yes')

import sys

n=int(input())

t=[]

for i in range(n):

    t.append(list(map(int,input().split())))

for i,d in enumerate(t):

    if i>0:

        b=d[0]-a

        c=abs(d[1]+d[2]-aa)

    a=d[0]

    aa=d[1]+d[2]

    if i==0:

        if not (a >= aa and a % 2 == aa % 2):

            print('No')

            sys.exit()

        else:

            continue

    if not (b>=c and b%2==c%2):

        print('No')

        sys.exit()

print('Yes')

N = input()
a = []
t = True
for _ in range(int(N)):
    a += [list(map(int, input().split()))]
for i in range(int(N)):
    if a[i][0] % 2 == 0:
        if abs(a[i][1] + a[i][2]) <= a[i][0] and (a[i][1] + a[i][2]) % 2 == 0:
            continue
        else:
            print("No")
            t = False
            break
    else:
        if abs(a[i][1] + a[i][2] <= a[i][0]) and (a[i][1] + a[i][2]) % 2 == 1:
            continue
        else:
            print("No")
            t = False
            break
if t:
    print("Yes")

import sys

n = int(input())
t = []
for i in range(n):
    t.append(list(map(int, input().split())))
for i, d in enumerate(t):
    if i > 0:
        b = d[0] - a
        c = abs(d[1] + d[2] - aa)
    a = d[0]
    aa = d[1] + d[2]
    if i == 0:
        if not (a >= aa and a % 2 == aa % 2):
            print("No")
            sys.exit()
        else:
            continue
    if not (b >= c and b % 2 == c % 2):
        print("No")
        sys.exit()
print("Yes")

-    a += [list(map(int, input().split()))]

+    t.append(list(map(int, input().split())))

+        if not (a >= aa and a % 2 == aa % 2):

+    if not (b >= c and b % 2 == c % 2):


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

yenmin=a*x+b*y

for zz in range(2*10**5+1):

    xx=max(x-zz//2,0)

    yy=max(y-zz//2,0)

    yen=a*xx+b*yy+c*zz

    if yen<yenmin:

        yenmin=yen

print(yenmin)

#print(xx,yy,zz)

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

cmax=max(x,y)*2

zmin=(a+b)*10**5

for nc in range(0,cmax+1,2):

    na=max(x-nc//2,0)

    nb=max(y-nc//2,0)

    z=a*na+b*nb+c*nc

    zmin=min(zmin,z)

print(zmin)

a, b, c, x, y = list(map(int, input().split()))
yenmin = a * x + b * y
for zz in range(2 * 10**5 + 1):
    xx = max(x - zz // 2, 0)
    yy = max(y - zz // 2, 0)
    yen = a * xx + b * yy + c * zz
    if yen < yenmin:
        yenmin = yen
print(yenmin)
# print(xx,yy,zz)

a, b, c, x, y = list(map(int, input().split()))
cmax = max(x, y) * 2
zmin = (a + b) * 10**5
for nc in range(0, cmax + 1, 2):
    na = max(x - nc // 2, 0)
    nb = max(y - nc // 2, 0)
    z = a * na + b * nb + c * nc
    zmin = min(zmin, z)
print(zmin)

-yenmin = a * x + b * y
-for zz in range(2 * 10**5 + 1):
-    xx = max(x - zz // 2, 0)
-    yy = max(y - zz // 2, 0)
-    yen = a * xx + b * yy + c * zz
-    if yen < yenmin:
-        yenmin = yen
-print(yenmin)
-# print(xx,yy,zz)
+cmax = max(x, y) * 2
+zmin = (a + b) * 10**5
+for nc in range(0, cmax + 1, 2):
+    na = max(x - nc // 2, 0)
+    nb = max(y - nc // 2, 0)
+    z = a * na + b * nb + c * nc
+    zmin = min(zmin, z)
+print(zmin)


Input:
import queue

INF = 123456789

def main():

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

    G = [[] for _ in range(n)]

    for _ in range(m):

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

        a -= 1

        b -= 1

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

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

    used = set()

    for i in range(n):

        d = [INF for _ in range(n)]

        par = [-1 for _ in range(n)]

        # dijkstra

        que = queue.PriorityQueue()

        d[i] = 0

        que.put((0,i))

        while not que.empty():

            p = que.get()

            v = p[1]

            if d[v] < p[0]:

                continue

            for (to,cost) in G[v]:

                if d[to] > d[v]+cost:

                    d[to] = d[v]+cost

                    par[to] = v

                    que.put((d[to],to))

        for j in range(n):

            if i != j:

                a,b = j,par[j]

                if a>b:

                    a,b = b,a

                used.add((a,b))

    print((m - len(used)))

if __name__ == '__main__':

    main()

INF = 123456789

def main():

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

    d = [ [INF for i in range(n)] for j in range(n) ]

    for i in range(n):

        d[i][i] = 0

    a = [0 for _ in range(m)]

    b = [0 for _ in range(m)]

    c = [0 for _ in range(m)]

    for i in range(m):

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

        a[i] -= 1

        b[i] -= 1

        d[a[i]][b[i]] = min(d[a[i]][b[i]], c[i])

        d[b[i]][a[i]] = min(d[b[i]][a[i]], c[i])

    # Warshall-Floyd

    for k in range(n):

        for i in range(n):

            for j in range(n):

                d[i][j] = min(d[i][j], d[i][k]+d[k][j])

    ans = 0

    for i in range(m):

        found = 1

        for j in range(n):

            if d[j][a[i]] + c[i] == d[j][b[i]]:

                found = 0

                break

        ans += found

    print(ans)

if __name__ == '__main__':

    main()

import queue

INF = 123456789

def main():
    n, m = list(map(int, input().split()))
    G = [[] for _ in range(n)]
    for _ in range(m):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        G[a].append((b, c))
        G[b].append((a, c))
    used = set()
    for i in range(n):
        d = [INF for _ in range(n)]
        par = [-1 for _ in range(n)]
        # dijkstra
        que = queue.PriorityQueue()
        d[i] = 0
        que.put((0, i))
        while not que.empty():
            p = que.get()
            v = p[1]
            if d[v] < p[0]:
                continue
            for (to, cost) in G[v]:
                if d[to] > d[v] + cost:
                    d[to] = d[v] + cost
                    par[to] = v
                    que.put((d[to], to))
        for j in range(n):
            if i != j:
                a, b = j, par[j]
                if a > b:
                    a, b = b, a
                used.add((a, b))
    print((m - len(used)))

if __name__ == "__main__":
    main()

INF = 123456789

def main():
    n, m = list(map(int, input().split()))
    d = [[INF for i in range(n)] for j in range(n)]
    for i in range(n):
        d[i][i] = 0
    a = [0 for _ in range(m)]
    b = [0 for _ in range(m)]
    c = [0 for _ in range(m)]
    for i in range(m):
        a[i], b[i], c[i] = list(map(int, input().split()))
        a[i] -= 1
        b[i] -= 1
        d[a[i]][b[i]] = min(d[a[i]][b[i]], c[i])
        d[b[i]][a[i]] = min(d[b[i]][a[i]], c[i])
    # Warshall-Floyd
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    ans = 0
    for i in range(m):
        found = 1
        for j in range(n):
            if d[j][a[i]] + c[i] == d[j][b[i]]:
                found = 0
                break
        ans += found
    print(ans)

if __name__ == "__main__":
    main()

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

+    d = [[INF for i in range(n)] for j in range(n)]

-                if d[to] > d[v] + cost:

-                    d[to] = d[v] + cost

-                    que.put((d[to], to))

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


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

count = 0

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

    s = str(i)

    l = len(s)

    if all(s[j] == s[l-j-1] for j in range(l)):

            count += 1

print(count)

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

count = 0

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

    s = str(i)

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

         count += 1

print(count)

a, b = list(map(int, input().split()))
count = 0
for i in range(a, b + 1):
    s = str(i)
    l = len(s)
    if all(s[j] == s[l - j - 1] for j in range(l)):
        count += 1
print(count)

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

-    if all(s[j] == s[l - j - 1] for j in range(l)):


Input:
import itertools

import math

def main():

  s = input()

  t = input()

  cnt = 0

  for i in range(3):

    if s[i] == t[i]:

      cnt += 1

  print(cnt)

if __name__ == '__main__':

  main()

s = input()

t = input()

ans = 0

for i in range(3):

    if s[i] == t[i]:

        ans += 1

print(ans)

import itertools
import math

def main():
    s = input()
    t = input()
    cnt = 0
    for i in range(3):
        if s[i] == t[i]:
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

-import itertools
-import math
-def main():
-    s = input()
-    t = input()
-    cnt = 0
-    for i in range(3):
-        if s[i] == t[i]:
-            cnt += 1
-    print(cnt)
-if __name__ == "__main__":
-    main()
+s = input()
+t = input()
+ans = 0
+for i in range(3):
+    if s[i] == t[i]:
+        ans += 1
+print(ans)


Input:
import sys

sys.setrecursionlimit(100000)

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

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

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

for x, y in edges:

    graph[x - 1].append(y - 1)

    graph[y - 1].append(x - 1)

def dfs(v, c):

    # c: color = 1 or -1

    node[v] = c

    for i in graph[v]:

        if node[i] == c:

            return False

        if node[i] == 0 and not dfs(i, -c):

            return False

    return True

node = [0] * N

if dfs(0, 1):

    x = sum(v + 1 for v in node) // 2

    print((x * (N - x) - M))

else:

    print((N * (N - 1) // 2 - M))

from collections import deque

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

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

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

for x, y in edges:

    graph[x - 1].append(y - 1)

    graph[y - 1].append(x - 1)

def dfs(s, c):

    q = deque()

    q.append(s)

    visited[s] = True

    color[s] = c

    while len(q) > 0:

        v = q.pop()

        for i in graph[v]:

            if visited[i] and color[i] == color[v]:

                return False

            if not visited[i]:

                visited[i] = True

                color[i] = -color[v]

                q.append(i)

    return True

visited = [False] * N

color = [0] * N

if dfs(0, 1):

    x = sum(v + 1 for v in color) // 2

    print((x * (N - x) - M))

else:

    print((N * (N - 1) // 2 - M))

-        if node[i] == 0 and not dfs(i, -c):

+            if visited[i] and color[i] == color[v]:


Input:
def kmpTable(w):

    lw = len(w)

    nx = [-1] * (lw + 1)

    j = -1

    for i in range(lw):

        while j >= 0 and w[i] != w[j]:

            j = nx[j]

        j += 1

        nx[i + 1] = j

    return nx

def kmpSearch(s, w):

    ls = len(s)

    start = 0

    w_idx = 0

    ret = []

    nx = kmpTable(w)

    while start + w_idx < ls:

        if s[start + w_idx] == w[w_idx]:

            w_idx += 1

            if w_idx == len(w):

                ret.append(start)

                start = start + w_idx - nx[w_idx]

                w_idx = nx[w_idx]

        else:

            if w_idx == 0:

                start += 1

            else:

                start = start + w_idx - nx[w_idx]

                w_idx = nx[w_idx]

    return ret

T = input()

P = input()

ans = kmpSearch(T, P)

if ans:

    print(("\n".join(map(str, ans))))

def kmpTable(w):

    lw = len(w)

    nx = [-1] * (lw + 1)

    j = -1

    for i in range(lw):

        while j >= 0 and w[i] != w[j]:

            j = nx[j]

        j += 1

        nx[i + 1] = j

    return tuple(nx)

def kmpSearch(s, w):

    ls = len(s)

    start = 0

    w_idx = 0

    ret = []

    nx = kmpTable(w)

    while start + w_idx < ls:

        if s[start + w_idx] == w[w_idx]:

            w_idx += 1

            if w_idx == len(w):

                ret.append(start)

                start = start + w_idx - nx[w_idx]

                w_idx = nx[w_idx]

        else:

            if w_idx == 0:

                start += 1

            else:

                start = start + w_idx - nx[w_idx]

                w_idx = nx[w_idx]

    return ret

T = input()

P = input()

ans = kmpSearch(T, P)

if ans:

    print(("\n".join(map(str, ans))))


Input:
def main():

    import sys

    input = sys.stdin.buffer.readline

    N = int(input())

    TXY = [[int(i) for i in input().split()] for j in range(N)]

    time, px, py = 0, 0, 0

    for t, x, y in TXY:

        move = abs(x-px) + abs(y-py)

        # print(move, t-time)

        if (t - time) % 2 != move % 2 or t - time < move:

            return print("No")

        time, px, py = t, x, y

    print("Yes")

if __name__ == '__main__':

    main()

def main():

    import sys

    input = sys.stdin.buffer.readline

    N = int(input())

    TXY = [[int(i) for i in input().split()] for j in range(N)]

    time = 0

    px = 0

    py = 0

    for t, x, y in TXY:

        move = abs(py-y) + abs(px - x)

        if (t-time) < move or (t - time) % 2 != move % 2:

            return print("No")

        time = t

        px = x

        py = y

    print("Yes")

if __name__ == '__main__':

    main()

def main():
    import sys

    input = sys.stdin.buffer.readline
    N = int(input())
    TXY = [[int(i) for i in input().split()] for j in range(N)]
    time, px, py = 0, 0, 0
    for t, x, y in TXY:
        move = abs(x - px) + abs(y - py)
        # print(move, t-time)
        if (t - time) % 2 != move % 2 or t - time < move:
            return print("No")
        time, px, py = t, x, y
    print("Yes")

if __name__ == "__main__":
    main()

def main():
    import sys

    input = sys.stdin.buffer.readline
    N = int(input())
    TXY = [[int(i) for i in input().split()] for j in range(N)]
    time = 0
    px = 0
    py = 0
    for t, x, y in TXY:
        move = abs(py - y) + abs(px - x)
        if (t - time) < move or (t - time) % 2 != move % 2:
            return print("No")
        time = t
        px = x
        py = y
    print("Yes")

if __name__ == "__main__":
    main()

-        move = abs(x - px) + abs(y - py)

-        if (t - time) % 2 != move % 2 or t - time < move:

+        move = abs(py - y) + abs(px - x)

+        if (t - time) < move or (t - time) % 2 != move % 2:


Input:
import math,string,itertools,math,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)

inf = 10**20

eps = 1.0 / 10**15

mod = 10**9+7

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

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

def LF(): return [float(x) for x in sys.stdin.readline().split()]

def LS(): return sys.stdin.readline().split()

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

def F(): return float(sys.stdin.readline())

def S(): return input()

def pf(s): return print(s, flush=True)

def divisions(n):

    sq = int(math.sqrt(n)+1)

    d = collections.defaultdict(int)

    while n % 2 == 0:

        n //= 2

        d[2] += 1

    i = 3

    while n > 1 and sq >= i:

        if n % i == 0:

            n //= i

            d[i] += 1

        else:

            i += 2

    if n > 1:

        d[n] += 1

    r = [1]

    for k, v in d.items():

        for c in r[:]:

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

                r.append(c*(k**i))

    return sorted(r)

def main():

    n = I()

    a = LI()

    s = set()

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

        d = divisions(i)

        ld = len(d)

        for j in range(1,2**ld):

            c = []

            ff = True

            for k in range(ld):

                if j & (1<<k):

                    f = True

                    for e in c:

                        if d[k] % e == 0:

                            f = False

                            ff = False

                            break

                    if f:

                        c.append(d[k])

                if not ff:

                    break

            if ff:

                s.add(tuple(c + [n+1]))

    b = sorted(list(s), reverse=True)

    for c in b:

        t = 0

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

            f = False

            for e in c:

                if j%e == 0:

                    f = True

                    break

            if f:

                t += a[j-1]

        if t < 0:

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

                f = False

                for e in c:

                    if j%e == 0:

                        f = True

                        break

                if f:

                    a[j-1] = 0

    return sum(a)

print(main())

import math,string,itertools,math,heapq,collections,re,array,bisect,sys,copy,functools

import time,random

sys.setrecursionlimit(10**7)

inf = 10**20

eps = 1.0 / 10**10

mod = 10**9+7

mod2 = 998244353

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

ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

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

def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]

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

def LF(): return [float(x) for x in sys.stdin.readline().split()]

def LS(): return sys.stdin.readline().split()

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

def F(): return float(sys.stdin.readline())

def S(): return input()

def pf(s): return print(s, flush=True)

def pe(s): return print(str(s), file=sys.stderr)

def JA(a, sep): return sep.join(map(str, a))

def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

class Flow():

    def __init__(self, e, N):

        self.E = e

        self.N = N

    def max_flow(self, s, t):

        r = 0

        e = self.E

        def f(c, cap):

            v = self.v

            v[c] = 1

            if c == t:

                return cap

            for i in range(self.N):

                if v[i] or e[c][i] <= 0:

                    continue

                cp = min(cap, e[c][i])

                k = f(i, cp)

                if k > 0:

                    e[c][i] -= k

                    e[i][c] += k

                    return k

            return 0

        while True:

            self.v = [None] * self.N

            fs = f(s, inf)

            if fs == 0:

                break

            r += fs

        return r

def main():

    n = I()

    a = LI()

    s = n

    t = n + 1

    e = [[0] * (n+2) for _ in range(n+2)]

    for i in range(n):

        c = a[i]

        if c < 0:

            e[s][i] = -c

            ii = i + 1

            for j in range(ii*2, n+1, ii):

                e[i][j-1] = inf

        else:

            e[i][t] = c

    fl = Flow(e, n+2)

    r = fl.max_flow(s,t)

    return sum(map(lambda x: max(0,x), a)) - r

# start = time.time()

print(main())

# pe(time.time() - start)

import math, string, itertools, math, heapq, collections, re, array, bisect, sys, random, time, copy, functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9 + 7

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

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

def LF():
    return [float(x) for x in sys.stdin.readline().split()]

def LS():
    return sys.stdin.readline().split()

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

def F():
    return float(sys.stdin.readline())

def S():
    return input()

def pf(s):
    return print(s, flush=True)

def divisions(n):
    sq = int(math.sqrt(n) + 1)
    d = collections.defaultdict(int)
    while n % 2 == 0:
        n //= 2
        d[2] += 1
    i = 3
    while n > 1 and sq >= i:
        if n % i == 0:
            n //= i
            d[i] += 1
        else:
            i += 2
    if n > 1:
        d[n] += 1
    r = [1]
    for k, v in d.items():
        for c in r[:]:
            for i in range(1, v + 1):
                r.append(c * (k**i))
    return sorted(r)

def main():
    n = I()
    a = LI()
    s = set()
    for i in range(n, 0, -1):
        d = divisions(i)
        ld = len(d)
        for j in range(1, 2**ld):
            c = []
            ff = True
            for k in range(ld):
                if j & (1 << k):
                    f = True
                    for e in c:
                        if d[k] % e == 0:
                            f = False
                            ff = False
                            break
                    if f:
                        c.append(d[k])
                if not ff:
                    break
            if ff:
                s.add(tuple(c + [n + 1]))
    b = sorted(list(s), reverse=True)
    for c in b:
        t = 0
        for j in range(1, n + 1):
            f = False
            for e in c:
                if j % e == 0:
                    f = True
                    break
            if f:
                t += a[j - 1]
        if t < 0:
            for j in range(1, n + 1):
                f = False
                for e in c:
                    if j % e == 0:
                        f = True
                        break
                if f:
                    a[j - 1] = 0
    return sum(a)

print(main())

import math, string, itertools, math, heapq, collections, re, array, bisect, sys, copy, functools
import time, random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
    return [list(map(int, l.split())) for l in sys.stdin.readlines()]

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

def LF():
    return [float(x) for x in sys.stdin.readline().split()]

def LS():
    return sys.stdin.readline().split()

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

def F():
    return float(sys.stdin.readline())

def S():
    return input()

def pf(s):
    return print(s, flush=True)

def pe(s):
    return print(str(s), file=sys.stderr)

def JA(a, sep):
    return sep.join(map(str, a))

def JAA(a, s, t):
    return s.join(t.join(map(str, b)) for b in a)

class Flow:
    def __init__(self, e, N):
        self.E = e
        self.N = N

    def max_flow(self, s, t):
        r = 0
        e = self.E

        def f(c, cap):
            v = self.v
            v[c] = 1
            if c == t:
                return cap
            for i in range(self.N):
                if v[i] or e[c][i] <= 0:
                    continue
                cp = min(cap, e[c][i])
                k = f(i, cp)
                if k > 0:
                    e[c][i] -= k
                    e[i][c] += k
                    return k
            return 0

        while True:
            self.v = [None] * self.N
            fs = f(s, inf)
            if fs == 0:
                break
            r += fs
        return r

def main():
    n = I()
    a = LI()
    s = n
    t = n + 1
    e = [[0] * (n + 2) for _ in range(n + 2)]
    for i in range(n):
        c = a[i]
        if c < 0:
            e[s][i] = -c
            ii = i + 1
            for j in range(ii * 2, n + 1, ii):
                e[i][j - 1] = inf
        else:
            e[i][t] = c
    fl = Flow(e, n + 2)
    r = fl.max_flow(s, t)
    return sum(map(lambda x: max(0, x), a)) - r

# start = time.time()
print(main())
# pe(time.time() - start)

-import math, string, itertools, math, heapq, collections, re, array, bisect, sys, random, time, copy, functools

+import math, string, itertools, math, heapq, collections, re, array, bisect, sys, copy, functools

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

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

+    return [list(map(int, l.split())) for l in sys.stdin.readlines()]

+    return print(str(s), file=sys.stderr)

+    return s.join(t.join(map(str, b)) for b in a)

-                s.add(tuple(c + [n + 1]))

+            for j in range(ii * 2, n + 1, ii):

+    return sum(map(lambda x: max(0, x), a)) - r


Input:
N = int(input())

ans = N - 1

p = 1

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

    if p % 2 == 1 and i > (N ** 0.5):

        break

    if N % i == 0:

        p = i

        j = N // i

        m = i + j - 2

        if m < ans:

            ans = m

        else:

            continue

    else:

        continue

print(ans)

N = int(input())

ans = N - 1

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

    if N % i == 0:

        j = N // i

        m = i + j - 2

        ans = min(ans, m)

print(ans)

N = int(input())
ans = N - 1
p = 1
for i in range(2, int((N**0.5) + 1)):
    if p % 2 == 1 and i > (N**0.5):
        break
    if N % i == 0:
        p = i
        j = N // i
        m = i + j - 2
        if m < ans:
            ans = m
        else:
            continue
    else:
        continue
print(ans)

N = int(input())
ans = N - 1
for i in range(2, int((N**0.5) + 1)):
    if N % i == 0:
        j = N // i
        m = i + j - 2
        ans = min(ans, m)
print(ans)

-p = 1
-    if p % 2 == 1 and i > (N**0.5):
-        break
-        p = i
-        if m < ans:
-            ans = m
-        else:
-            continue
-    else:
-        continue
+        ans = min(ans, m)


Input:
import sys

import heapq

# \n

def input():

    return sys.stdin.readline().rstrip()

def main():

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

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

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

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

    A.sort(reverse=True)

    B.sort(reverse=True)

    C.sort(reverse=True)

    Q = []

    S = set()

    heapq.heapify(Q)

    heapq.heappush(Q, (-A[0] - B[0] - C[0], 0, 0, 0))

    for i in range(K):

        m, a, b, c = heapq.heappop(Q)

        print((-m))

        if (a + 1, b, c) not in S and a + 1 < X:

            heapq.heappush(Q, (-A[a + 1] - B[b] - C[c], a + 1, b, c))

            S.add((a + 1, b, c))

        if (a, b + 1, c) not in S and b + 1 < Y:

            heapq.heappush(Q, (-A[a] - B[b + 1] - C[c], a, b + 1, c))

            S.add((a, b + 1, c))

        if (a, b, c + 1) not in S and c + 1 < Z:

            heapq.heappush(Q, (-A[a ] - B[b] - C[c+1], a, b, c + 1))

            S.add((a, b, c + 1))

if __name__ == "__main__":

    main()

import sys

# \n

def input():

    return sys.stdin.readline().rstrip()

def main():

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

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

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

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

    A.sort(reverse=True)

    B.sort(reverse=True)

    C.sort(reverse=True)

    L = []

    for i in range(X):

        for j in range(min(Y, K // (i + 1) + 1)):

            for k in range(min(Z, K // (i + 1) // (j + 1) + 1)):

                L.append(A[i] + B[j] + C[k])

    L.sort(reverse=True)

    for i in range(K):

        print((L[i]))

if __name__ == "__main__":

    main()

import sys
import heapq

# \n
def input():
    return sys.stdin.readline().rstrip()

def main():
    X, Y, Z, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)
    Q = []
    S = set()
    heapq.heapify(Q)
    heapq.heappush(Q, (-A[0] - B[0] - C[0], 0, 0, 0))
    for i in range(K):
        m, a, b, c = heapq.heappop(Q)
        print((-m))
        if (a + 1, b, c) not in S and a + 1 < X:
            heapq.heappush(Q, (-A[a + 1] - B[b] - C[c], a + 1, b, c))
            S.add((a + 1, b, c))
        if (a, b + 1, c) not in S and b + 1 < Y:
            heapq.heappush(Q, (-A[a] - B[b + 1] - C[c], a, b + 1, c))
            S.add((a, b + 1, c))
        if (a, b, c + 1) not in S and c + 1 < Z:
            heapq.heappush(Q, (-A[a] - B[b] - C[c + 1], a, b, c + 1))
            S.add((a, b, c + 1))

if __name__ == "__main__":
    main()

+        for j in range(min(Y, K // (i + 1) + 1)):

+                L.append(A[i] + B[j] + C[k])

-        if (a + 1, b, c) not in S and a + 1 < X:

-            heapq.heappush(Q, (-A[a + 1] - B[b] - C[c], a + 1, b, c))

-        if (a, b + 1, c) not in S and b + 1 < Y:

-            heapq.heappush(Q, (-A[a] - B[b + 1] - C[c], a, b + 1, c))

-        if (a, b, c + 1) not in S and c + 1 < Z:

-            heapq.heappush(Q, (-A[a] - B[b] - C[c + 1], a, b, c + 1))


Input:
def two_count(x):

	if int(str(x)[-1]) % 2 == 0:

		return 1 + two_count(x//2)

	else:

		return 0

n = int(input())

n_list = [int(n) for n in input().split(" ")]

n_two_count_list = [two_count(n) for n in n_list]

print((min(n_two_count_list)))

def two_count(x):

	if x % 2 == 0:

		return 1 + two_count(x//2)

	else:

		return 0

n = int(input())

n_list = [int(n) for n in input().split(" ")]

n_two_count_list = [two_count(n) for n in n_list]

print((min(n_two_count_list)))

def two_count(x):
    if int(str(x)[-1]) % 2 == 0:
        return 1 + two_count(x // 2)
    else:
        return 0

n = int(input())
n_list = [int(n) for n in input().split(" ")]
n_two_count_list = [two_count(n) for n in n_list]
print((min(n_two_count_list)))

def two_count(x):
    if x % 2 == 0:
        return 1 + two_count(x // 2)
    else:
        return 0

n = int(input())
n_list = [int(n) for n in input().split(" ")]
n_two_count_list = [two_count(n) for n in n_list]
print((min(n_two_count_list)))


Input:
n=int(input())

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

def f():

 for i in range(n-1):

  d=a[i][:];d[3],d[4]=d[4],d[3]

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

   e=a[j][:];e[3],e[4]=e[4],e[3]

   for p in('012345','152043','215304','302541','410352','514320'):

    f=[d[int(k)]for k in p]

    g=f[1:5]*2

    for k in range(4):

     if(g[k:k+4]==e[1:5])*(f[0]==e[0])*(f[5]==e[5]):return 'No'

 return 'Yes'

print((f()))

+                                return "No"


Input:
from math import gcd

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

a = [int(i) // 2 for i in input().split()]

x = 1

for i in range(n):

    x *= a[i] // gcd(x, a[i])

for i in a:

    if x // i % 2 == 0:

        print((0))

        exit()

print(((m // x + 1) // 2))

from math import gcd, ceil

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

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

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

l = 1

for i in a:

    l *= i // gcd(l, i)

for i in a:

    if l // i % 2 == 0:

        print((0))

        exit()

print((ceil((m // l) / 2)))

-a = [int(i) // 2 for i in input().split()]


Input:
import sys

input = lambda: sys.stdin.readline()[:-1]

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

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

data=[list(map(int,input().split())) for i in range(m)]

for i in a0:

	data.append([1,i])

data.sort(key=lambda tup:-tup[1])

ans=0

for num,val in data:

	if n>=num:

		n-=num

		ans+=val*num

	else:

		ans+=val*n

		break

print(ans)

#!/usr/bin/env python3

import sys

from collections import Counter

input = lambda: sys.stdin.readline()[:-1]

sys.setrecursionlimit(10**8)

ans=0

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

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

bc=[]

for i in range(m):

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

    bc.append((c,b))

C=Counter(A)

bc+=list(C.items())

bc.sort(key=lambda tup:-tup[0])

# print(bc)

for c,b in bc:

    if n>=b:

        n-=b

        ans+=c*b

    else:

        ans+=c*n

        break

print(ans)

import sys

input = lambda: sys.stdin.readline()[:-1]
n, m = list(map(int, input().split()))
a0 = list(map(int, input().split()))
data = [list(map(int, input().split())) for i in range(m)]
for i in a0:
    data.append([1, i])
data.sort(key=lambda tup: -tup[1])
ans = 0
for num, val in data:
    if n >= num:
        n -= num
        ans += val * num
    else:
        ans += val * n
        break
print(ans)

#!/usr/bin/env python3
import sys
from collections import Counter

input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
ans = 0
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
bc = []
for i in range(m):
    b, c = list(map(int, input().split()))
    bc.append((c, b))
C = Counter(A)
bc += list(C.items())
bc.sort(key=lambda tup: -tup[0])
# print(bc)
for c, b in bc:
    if n >= b:
        n -= b
        ans += c * b
    else:
        ans += c * n
        break
print(ans)

-data = [list(map(int, input().split())) for i in range(m)]

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


Input:
import sys

sys.setrecursionlimit(10**6)

if sys.platform in (['ios','darwin','win32']):

	sys.stdin=open('Untitled.txt')

input = sys.stdin.readline

def INT(): return int(input())

def MAP(): return [int(s) for s in input().split()]

def main():

	S = input().rstrip()

	bcnt = 0

	A = []

	for i in range(len(S)):

		if S[i] == 'B': bcnt += 1

		if S[i] == 'W': A.append(bcnt)

	print((sum(A)))

if __name__ == '__main__':

	main()

import sys

sys.setrecursionlimit(10**6)

if sys.platform in (['ios','darwin','win32']):

	sys.stdin=open('Untitled.txt')

input = sys.stdin.readline

def INT(): return int(input())

def MAP(): return [int(s) for s in input().split()]

def main():

	S = input().rstrip()

	bcnt = 0

	ans = 0

	for i in range(len(S)):

		if S[i] == 'B': bcnt += 1

		if S[i] == 'W': ans += bcnt

	print(ans)

if __name__ == '__main__':

	main()

import sys

sys.setrecursionlimit(10**6)
if sys.platform in (["ios", "darwin", "win32"]):
    sys.stdin = open("Untitled.txt")
input = sys.stdin.readline

def INT():
    return int(input())

def MAP():
    return [int(s) for s in input().split()]

def main():
    S = input().rstrip()
    bcnt = 0
    A = []
    for i in range(len(S)):
        if S[i] == "B":
            bcnt += 1
        if S[i] == "W":
            A.append(bcnt)
    print((sum(A)))

if __name__ == "__main__":
    main()

import sys

sys.setrecursionlimit(10**6)
if sys.platform in (["ios", "darwin", "win32"]):
    sys.stdin = open("Untitled.txt")
input = sys.stdin.readline

def INT():
    return int(input())

def MAP():
    return [int(s) for s in input().split()]

def main():
    S = input().rstrip()
    bcnt = 0
    ans = 0
    for i in range(len(S)):
        if S[i] == "B":
            bcnt += 1
        if S[i] == "W":
            ans += bcnt
    print(ans)

if __name__ == "__main__":
    main()

-    A = []
+    ans = 0
-            A.append(bcnt)
-    print((sum(A)))
+            ans += bcnt
+    print(ans)


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

n = 0

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

    f = True

    s = str(i)

    l = len(s)

    for j in range(l//2 + 1):

        if s[j] != s[- j - 1]:

            f = False

            break

    if f:

        n += 1

print(n)

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

n = 0

for i in range(1, 10):

    for j in range(10):

        for k in range(10):

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

            if a <= s <= b:

                n += 1

print(n)

a, b = list(map(int, input().split()))
n = 0
for i in range(a, b + 1):
    f = True
    s = str(i)
    l = len(s)
    for j in range(l // 2 + 1):
        if s[j] != s[-j - 1]:
            f = False
            break
    if f:
        n += 1
print(n)

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


Input:
import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

def main():

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

    ans = INF

    for bit in range(1 << N):

        if (not (bit & 1)) or bin(bit).count('1') != K:

            continue

        total = 0

        max_height = A[0]

        for i, a in enumerate(A[1:], 1):

            if a <= max_height:

                if bit & (1 << i):

                    total += max_height - a + 1

                    max_height += 1

            else:

                max_height = a

        if ans > total:

            ans = total

    print(ans)

    return

if __name__ == '__main__':

    main()

import sys

from itertools import combinations

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

def main():

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

    ans = INF

    for comb in combinations(list(range(1, N)), K - 1):

        included = [False] * N

        for i in comb:

            included[i] = True

        total = 0

        max_height = A[0]

        for i, a in enumerate(A[1:], 1):

            if a <= max_height:

                if included[i]:

                    total += max_height - a + 1

                    max_height += 1

            else:

                max_height = a

        if ans > total:

            ans = total

    print(ans)

    return

if __name__ == '__main__':

    main()

import sys

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

def main():
    N, K, *A = list(map(int, read().split()))
    ans = INF
    for bit in range(1 << N):
        if (not (bit & 1)) or bin(bit).count("1") != K:
            continue
        total = 0
        max_height = A[0]
        for i, a in enumerate(A[1:], 1):
            if a <= max_height:
                if bit & (1 << i):
                    total += max_height - a + 1
                    max_height += 1
            else:
                max_height = a
        if ans > total:
            ans = total
    print(ans)
    return

if __name__ == "__main__":
    main()

import sys
from itertools import combinations

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

def main():
    N, K, *A = list(map(int, read().split()))
    ans = INF
    for comb in combinations(list(range(1, N)), K - 1):
        included = [False] * N
        for i in comb:
            included[i] = True
        total = 0
        max_height = A[0]
        for i, a in enumerate(A[1:], 1):
            if a <= max_height:
                if included[i]:
                    total += max_height - a + 1
                    max_height += 1
            else:
                max_height = a
        if ans > total:
            ans = total
    print(ans)
    return

if __name__ == "__main__":
    main()

-        if (not (bit & 1)) or bin(bit).count("1") != K:

+    for comb in combinations(list(range(1, N)), K - 1):


Input:
import math

n = int(input())

cnt = 0

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

    if math.floor(math.log10(i) + 1) % 2:

        cnt += 1

print(cnt)

n = int(input())

cnt = 0

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

    if len(str(i)) % 2:

        cnt += 1

print(cnt)

-    if math.floor(math.log10(i) + 1) % 2:


Input:
from collections import defaultdict

n = int(input())

d = defaultdict(int)

for _ in range(n):

    key = input()

    d[key] += 1

dict = sorted(list(d.items()), key=lambda x:x[1], reverse=True)

max_v = max(d.values())

dict_li = []

for a in dict:

    if a[1]==max_v:

        dict_li.append(a[0])

dict_li.sort()

for s in dict_li:

    print(s)

from collections import defaultdict

n = int(input())

d = defaultdict(int)

for _ in range(n):

    key = input()

    d[key] += 1

dict = sorted(d.items(), key=lambda x:x[1], reverse=True)

max_v = max(d.values())

dict_li = []

for a in dict:

    if a[1]==max_v:

        dict_li.append(a[0])

dict_li.sort()

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

from collections import defaultdict

n = int(input())
d = defaultdict(int)
for _ in range(n):
    key = input()
    d[key] += 1
dict = sorted(list(d.items()), key=lambda x: x[1], reverse=True)
max_v = max(d.values())
dict_li = []
for a in dict:
    if a[1] == max_v:
        dict_li.append(a[0])
dict_li.sort()
for s in dict_li:
    print(s)

from collections import defaultdict

n = int(input())
d = defaultdict(int)
for _ in range(n):
    key = input()
    d[key] += 1
dict = sorted(d.items(), key=lambda x: x[1], reverse=True)
max_v = max(d.values())
dict_li = []
for a in dict:
    if a[1] == max_v:
        dict_li.append(a[0])
dict_li.sort()
print(*dict_li, sep="\n")

-dict = sorted(list(d.items()), key=lambda x: x[1], reverse=True)

+dict = sorted(d.items(), key=lambda x: x[1], reverse=True)


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

l = [0]*(10**5+1)

for i in range(n):

    ai,bi = list(map(int,input().split()))

    l[ai]+=bi

for index,i in enumerate(l):

    if i:

        k-=i

        if k<=0:

            break

print(index)

from collections import defaultdict

from sys import stdin

input = stdin.readline

d = defaultdict(int)

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

for _ in range(n):

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

    d[a]+=b

for key in sorted(d.keys()):

    v = d[key]

    k-=v

    if k <= 0:

        break

print(key)

n, k = list(map(int, input().split()))
l = [0] * (10**5 + 1)
for i in range(n):
    ai, bi = list(map(int, input().split()))
    l[ai] += bi
for index, i in enumerate(l):
    if i:
        k -= i
        if k <= 0:
            break
print(index)

from collections import defaultdict
from sys import stdin

input = stdin.readline
d = defaultdict(int)
n, k = list(map(int, input().split()))
for _ in range(n):
    a, b = list(map(int, input().split()))
    d[a] += b
for key in sorted(d.keys()):
    v = d[key]
    k -= v
    if k <= 0:
        break
print(key)

-    ai, bi = list(map(int, input().split()))

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


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

cnt = 0

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

    l = list(str(i))

    if l == list(reversed(l)):

        cnt += 1

print(cnt)

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

cnt = 0

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

    l = str(i)

    if l == l[::-1]:

        cnt += 1

print(cnt)

A, B = list(map(int, input().split()))
cnt = 0
for i in range(A, B + 1):
    l = list(str(i))
    if l == list(reversed(l)):
        cnt += 1
print(cnt)

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

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


Input:
n = int(input())

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

#print(n,ary)

ary_2 = [ary[0]]

for i in range(1, n):

    ary_2.append(ary[i] + ary_2[i-1])

ary_2 = [0] + ary_2

#print(ary_2)

from collections import Counter

c = Counter(ary_2)

v = (list(c.values()))

#print(v)

from math import factorial

def combinations_count(n, r):

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

ans = 0

for j in v:

    if j >1:

        ans += combinations_count(j,2)

print(ans)

n = int(input())

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

#print(n,ary)

ary_2 = [ary[0]]

for i in range(1, n):

    ary_2.append(ary[i] + ary_2[i-1])

ary_2 = [0] + ary_2

#print(ary_2)

from collections import Counter

c = Counter(ary_2)

v = (list(c.values()))

#print(v)

ans = 0

for j in v:

    if j >1:

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

print(ans)

n = int(input())
ary = list(map(int, input().split()))
# print(n,ary)
ary_2 = [ary[0]]
for i in range(1, n):
    ary_2.append(ary[i] + ary_2[i - 1])
ary_2 = [0] + ary_2
# print(ary_2)
from collections import Counter

c = Counter(ary_2)
v = list(c.values())
# print(v)
from math import factorial

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

ans = 0
for j in v:
    if j > 1:
        ans += combinations_count(j, 2)
print(ans)

n = int(input())
ary = list(map(int, input().split()))
# print(n,ary)
ary_2 = [ary[0]]
for i in range(1, n):
    ary_2.append(ary[i] + ary_2[i - 1])
ary_2 = [0] + ary_2
# print(ary_2)
from collections import Counter

c = Counter(ary_2)
v = list(c.values())
# print(v)
ans = 0
for j in v:
    if j > 1:
        ans += j * (j - 1) // 2
print(ans)

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

-        ans += combinations_count(j, 2)


Input:
N = int(input())

mem = [[0]*10 for i in range(10)]

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

    a = int(str(i)[0])

    b = int(str(i)[-1])

    mem[a][b] += 1

ans = 0

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

    a = int(str(i)[0])

    b = int(str(i)[-1])

    ans += mem[b][a]

print(ans)

N = int(input())

d = [[0]*10 for i in range(10)]

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

    s = str(n)

    d[int(s[0])][int(s[-1])] += 1

ans = 0

for i in range(10):

    for j in range(10):

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

print(ans)

N = int(input())
mem = [[0] * 10 for i in range(10)]
for i in range(1, N + 1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    mem[a][b] += 1
ans = 0
for i in range(1, N + 1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    ans += mem[b][a]
print(ans)

N = int(input())
d = [[0] * 10 for i in range(10)]
for n in range(1, N + 1):
    s = str(n)
    d[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += d[i][j] * d[j][i]
print(ans)

-mem = [[0] * 10 for i in range(10)]
-for i in range(1, N + 1):
-    a = int(str(i)[0])
-    b = int(str(i)[-1])
-    mem[a][b] += 1
+d = [[0] * 10 for i in range(10)]
+for n in range(1, N + 1):
+    s = str(n)
+    d[int(s[0])][int(s[-1])] += 1
-for i in range(1, N + 1):
-    a = int(str(i)[0])
-    b = int(str(i)[-1])
-    ans += mem[b][a]
+for i in range(10):
+    for j in range(10):
+        ans += d[i][j] * d[j][i]


Input:
N = int(input())

p = 1

for i in range(N):

    p *= (i + 1)

    p %= (1e9 + 7)

print((int(p)))

N = int(input())

p = 1

for i in range(N):

    p = p * (i + 1) % (1e9 + 7)

print((int(p)))

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


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

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

diff = []

for i in range(n - 1):

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

diff.append(k - a[-1] + a[0])

print((k - max(diff)))

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

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

a.append(k + a[0])

diff = [a1 - a0 for a0, a1 in zip(a, a[1:])]

print((k - max(diff)))

+diff = [a1 - a0 for a0, a1 in zip(a, a[1:])]


Input:
class Calc:

    def __init__(self, max_value, mod):

        """combination(max_value, all)"""

        fact = [-1] * (max_value + 1)

        fact[0] = 1

        fact[1] = 1

        for x in range(2, max_value + 1):

            fact[x] = x * fact[x - 1] % mod

        invs = [1] * (max_value + 1)

        invs[max_value] = pow(fact[max_value], mod - 2, mod)

        for x in range(max_value - 1, 0, -1):

            invs[x] = invs[x + 1] * (x + 1) % mod

        self.fact = fact

        self.invs = invs

        self.mod = mod

    def combination(self, n, r):

        if n - r < r:

            return self.combination(n, n - r)

        if r < 0:

            return 0

        if r == 0:

            return 1

        if r == 1:

            return n

        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod

def gen(n):

    x = n

    d = 2

    cnt = 0

    while x % d == 0:

        x //= d

        cnt += 1

    yield cnt

    d = 3

    ma = d * d

    while ma <= n:

        cnt = 0

        while x % d == 0:

            x //= d

            cnt += 1

        yield cnt

        ma += d * 4 + 4

        d += 2

    if x > 1:

        yield 1

def main():

    MOD = 10 ** 9 + 7

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

    cal = Calc(max_value=N + 30, mod=MOD)

    ans = 1

    for cnt in gen(M):

        ans = (ans * cal.combination(N + cnt - 1, cnt)) % MOD

    print(ans)

if __name__ == '__main__':

    main()

def gen(n):

    x = n

    d = 2

    cnt = 0

    while x % d == 0:

        x //= d

        cnt += 1

    yield cnt

    d = 3

    while d * d <= n:

        cnt = 0

        while x % d == 0:

            x //= d

            cnt += 1

        yield cnt

        d += 2

    if x > 1:

        yield 1

def main():

    MOD = 10 ** 9 + 7

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

    ans = 1

    for cnt in gen(M):

        for d in range(cnt):

            ans = (ans * (N - 1 + cnt - d) % MOD) * pow(d + 1, MOD - 2, MOD) % MOD

    print(ans)

if __name__ == '__main__':

    main()

class Calc:
    def __init__(self, max_value, mod):
        """combination(max_value, all)"""
        fact = [-1] * (max_value + 1)
        fact[0] = 1
        fact[1] = 1
        for x in range(2, max_value + 1):
            fact[x] = x * fact[x - 1] % mod
        invs = [1] * (max_value + 1)
        invs[max_value] = pow(fact[max_value], mod - 2, mod)
        for x in range(max_value - 1, 0, -1):
            invs[x] = invs[x + 1] * (x + 1) % mod
        self.fact = fact
        self.invs = invs
        self.mod = mod

    def combination(self, n, r):
        if n - r < r:
            return self.combination(n, n - r)
        if r < 0:
            return 0
        if r == 0:
            return 1
        if r == 1:
            return n
        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod

def gen(n):
    x = n
    d = 2
    cnt = 0
    while x % d == 0:
        x //= d
        cnt += 1
    yield cnt
    d = 3
    ma = d * d
    while ma <= n:
        cnt = 0
        while x % d == 0:
            x //= d
            cnt += 1
        yield cnt
        ma += d * 4 + 4
        d += 2
    if x > 1:
        yield 1

def main():
    MOD = 10**9 + 7
    N, M = list(map(int, input().split()))
    cal = Calc(max_value=N + 30, mod=MOD)
    ans = 1
    for cnt in gen(M):
        ans = (ans * cal.combination(N + cnt - 1, cnt)) % MOD
    print(ans)

if __name__ == "__main__":
    main()

def gen(n):
    x = n
    d = 2
    cnt = 0
    while x % d == 0:
        x //= d
        cnt += 1
    yield cnt
    d = 3
    while d * d <= n:
        cnt = 0
        while x % d == 0:
            x //= d
            cnt += 1
        yield cnt
        d += 2
    if x > 1:
        yield 1

def main():
    MOD = 10**9 + 7
    N, M = list(map(int, input().split()))
    ans = 1
    for cnt in gen(M):
        for d in range(cnt):
            ans = (ans * (N - 1 + cnt - d) % MOD) * pow(d + 1, MOD - 2, MOD) % MOD
    print(ans)

if __name__ == "__main__":
    main()

-    def __init__(self, max_value, mod):

-        """combination(max_value, all)"""

-        for x in range(2, max_value + 1):

-            fact[x] = x * fact[x - 1] % mod

-        invs[max_value] = pow(fact[max_value], mod - 2, mod)

-        for x in range(max_value - 1, 0, -1):

-            invs[x] = invs[x + 1] * (x + 1) % mod

-            return self.combination(n, n - r)

-        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod

-    cal = Calc(max_value=N + 30, mod=MOD)

-        ans = (ans * cal.combination(N + cnt - 1, cnt)) % MOD

+            ans = (ans * (N - 1 + cnt - d) % MOD) * pow(d + 1, MOD - 2, MOD) % MOD


Input:
def c_remainder_minimization_2019(L, R):

    ans = float('inf')

    for i in range(L, min(R, L + 2019)):

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

            ans = min(ans, (i * j) % 2019)

    return ans

L, R = [int(i) for i in input().split()]

print((c_remainder_minimization_2019(L, R)))

def c_remainder_minimization_2019(L, R):

    ans = float('inf')

    for i in range(L, min(R, L + 2019)):

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

            ans = min(ans, (i * j) % 2019)

            if ans == 0:

                return 0

    return ans

L, R = [int(i) for i in input().split()]

print((c_remainder_minimization_2019(L, R)))

def c_remainder_minimization_2019(L, R):
    ans = float("inf")
    for i in range(L, min(R, L + 2019)):
        for j in range(i + 1, min(R + 1, L + 2020)):
            ans = min(ans, (i * j) % 2019)
    return ans

L, R = [int(i) for i in input().split()]
print((c_remainder_minimization_2019(L, R)))

def c_remainder_minimization_2019(L, R):
    ans = float("inf")
    for i in range(L, min(R, L + 2019)):
        for j in range(i + 1, min(R + 1, L + 2020)):
            ans = min(ans, (i * j) % 2019)
            if ans == 0:
                return 0
    return ans

L, R = [int(i) for i in input().split()]
print((c_remainder_minimization_2019(L, R)))

+            if ans == 0:
+                return 0


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

val = float('inf')

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

    val = min(val, 2 * c * k + max(x - k, 0) * a + max(y - k, 0) * b)

print(val)

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

ans = 0

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

if X > Y:

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

elif X < Y:

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

print(ans)

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

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

-    val = min(val, 2 * c * k + max(x - k, 0) * a + max(y - k, 0) * b)

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


Input:
from math import factorial as f

n = int(input())

print((f(n) % (10 ** 9 + 7)))

n = int(input())

p = 1

for i in range(n):

    p = (p * (i+1)) % (10 ** 9 + 7)

print(p)

from math import factorial as f

n = int(input())
print((f(n) % (10**9 + 7)))

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

-from math import factorial as f
-print((f(n) % (10**9 + 7)))
+p = 1
+for i in range(n):
+    p = (p * (i + 1)) % (10**9 + 7)
+print(p)


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

mod=10**9+7

f=[1]

for i in range(2*10**5+7):f+=[f[-1]*(i+1)%mod]

def comb(a,b):return f[a]*pow(f[b],mod-2,mod)*pow(f[a-b],mod-2,mod)%mod

ans=0

for i in range(1,n):

  ans+=(i*(n-i)*m**2)*(comb(n*m-2,k-2))

  ans%=mod

for i in range(1,m):

  ans+=(i*(m-i)*n**2)*(comb(n*m-2,k-2))

  ans%=mod

print(ans)

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

mod = 10**9+7

f = [1]

for i in range(n*m):

  f += [f[-1]*(i+1) % mod]

def comb(a, b):

  return f[a]*pow(f[b], mod-2, mod)*pow(f[a-b], mod-2, mod) % mod

ans=0

for dist in range(1,n):

  c=n-dist

  p=(c*m*m)%mod

  ans+=p*dist

for dist in range(1,m):

  c=m-dist

  p=(c*n*n)%mod

  ans+=p*dist

ans%=mod

print((ans*comb(n*m-2,k-2)%mod))

n, m, k = list(map(int, input().split()))
mod = 10**9 + 7
f = [1]
for i in range(2 * 10**5 + 7):
    f += [f[-1] * (i + 1) % mod]

def comb(a, b):
    return f[a] * pow(f[b], mod - 2, mod) * pow(f[a - b], mod - 2, mod) % mod

ans = 0
for i in range(1, n):
    ans += (i * (n - i) * m**2) * (comb(n * m - 2, k - 2))
    ans %= mod
for i in range(1, m):
    ans += (i * (m - i) * n**2) * (comb(n * m - 2, k - 2))
    ans %= mod
print(ans)

n, m, k = list(map(int, input().split()))
mod = 10**9 + 7
f = [1]
for i in range(n * m):
    f += [f[-1] * (i + 1) % mod]

def comb(a, b):
    return f[a] * pow(f[b], mod - 2, mod) * pow(f[a - b], mod - 2, mod) % mod

ans = 0
for dist in range(1, n):
    c = n - dist
    p = (c * m * m) % mod
    ans += p * dist
for dist in range(1, m):
    c = m - dist
    p = (c * n * n) % mod
    ans += p * dist
ans %= mod
print((ans * comb(n * m - 2, k - 2) % mod))

+print((ans * comb(n * m - 2, k - 2) % mod))


Input:
import math

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

ans=1

n=int(input())

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

  ans*=i

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

print(ans)

import math

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

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

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


Input:
A, B, C, X, Y = [int(_) for _ in input().split()]

ans = A * X + B * Y

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

    cost = 2 * C * i

    if X > i:

        cost += A * (X - i)

    if Y > i:

        cost += B * (Y - i)

    ans = min(ans, cost)

print(ans)

A, B, C, X, Y = [int(_) for _ in input().split()]

M = max(X, Y)

print((min(2 * C * M, 2 * C * (X + Y - M) + A *

          (M - Y) + B * (M - X), A * X + B * Y)))


Input:
s = input()

len_s = len(s)

cnt = [0, 0]

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

    memo_0 = s[i - 1]

    memo_1 = s[len_s - i]

    if s[i] != memo_0:

        cnt[0] += 1

    if s[len_s - i - 1] != memo_1:

        cnt[1] += 1

print((min(cnt)))

s = input()

len_s = len(s)

cnt = 0

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

    memo_0 = s[i - 1]

    if s[i] != memo_0:

        cnt += 1

print(cnt)


Input:
import heapq

K=int(input())

dist=[10**15 for i in range(K)]

dist[1]=1

q=[]

heapq.heappush(q,(0,1))

while (len(q)!=0):

    prc,src=heapq.heappop(q)

    if dist[src]<prc:

        continue

    if dist[(src+1)%K]>dist[src]+1:

        dist[(src+1)%K]=dist[src]+1

        heapq.heappush(q,(dist[(src+1)%K],(src+1)%K))

    if dist[(10*src)%K]>dist[src]:

        dist[(10*src)%K]=dist[src]

        heapq.heappush(q,(dist[(src*10)%K],(src*10)%K))

print((dist[0]))

from collections import deque

K=int(input())

dist=[10**15 for i in range(K)]

dist[1]=1

q=deque([1])

while(len(q)>0):

    r=q.popleft()

    s=(r+1)%K

    if dist[r]+1<dist[s]:

        dist[s]=dist[r]+1

        q.append(s)

    t=(r*10)%K

    if dist[r]<dist[t]:

        dist[t]=dist[r]

        q.appendleft(t)

print((dist[0]))

import heapq

K = int(input())
dist = [10**15 for i in range(K)]
dist[1] = 1
q = []
heapq.heappush(q, (0, 1))
while len(q) != 0:
    prc, src = heapq.heappop(q)
    if dist[src] < prc:
        continue
    if dist[(src + 1) % K] > dist[src] + 1:
        dist[(src + 1) % K] = dist[src] + 1
        heapq.heappush(q, (dist[(src + 1) % K], (src + 1) % K))
    if dist[(10 * src) % K] > dist[src]:
        dist[(10 * src) % K] = dist[src]
        heapq.heappush(q, (dist[(src * 10) % K], (src * 10) % K))
print((dist[0]))

from collections import deque

K = int(input())
dist = [10**15 for i in range(K)]
dist[1] = 1
q = deque([1])
while len(q) > 0:
    r = q.popleft()
    s = (r + 1) % K
    if dist[r] + 1 < dist[s]:
        dist[s] = dist[r] + 1
        q.append(s)
    t = (r * 10) % K
    if dist[r] < dist[t]:
        dist[t] = dist[r]
        q.appendleft(t)
print((dist[0]))

-    if dist[(src + 1) % K] > dist[src] + 1:

-        dist[(src + 1) % K] = dist[src] + 1

-        heapq.heappush(q, (dist[(src + 1) % K], (src + 1) % K))

-    if dist[(10 * src) % K] > dist[src]:

-        dist[(10 * src) % K] = dist[src]

-        heapq.heappush(q, (dist[(src * 10) % K], (src * 10) % K))


Input:
n = int(input())

cnt = 0

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

    i_str = str(i)

    if len(i_str) == 1:

        cnt += 1

        continue

    if len(i_str) == 2:

        if int(i_str[0]) == int(i_str[1]):

            cnt += 3

        elif int(i_str[1]) != 0 and int(i_str[0]) > int(i_str[1]):

            cnt += 2

        continue

    if len(i_str) == 3:

        if int(i_str[0]) == int(i_str[2]):

            cnt += 4 + (2 * (int(i_str[1])+1) - 1)

        elif int(i_str[2]) != 0 and int(i_str[0]) > int(i_str[2]):

            cnt += 22

        elif int(i_str[0]) < int(i_str[2]):

            cnt += 2

        continue

    if len(i_str) == 4:

        if int(i_str[0]) == int(i_str[3]):

            cnt += 24 + 20 * int(i_str[1]) + 2 * (int(i_str[2])+1) - 1

        elif int(i_str[3]) != 0 and int(i_str[0]) > int(i_str[3]):

            cnt += 222

        elif int(i_str[0]) < int(i_str[3]):

            cnt += 22

        continue

    if len(i_str) == 5:

        if int(i_str[0]) == int(i_str[4]):

            cnt += 224 + 200 * int(i_str[1]) + 20 * int(i_str[2]) + 2 * (int(i_str[3])+1) - 1

        elif int(i_str[4]) != 0 and int(i_str[0]) > int(i_str[4]):

            cnt += 2222

        elif int(i_str[0]) < int(i_str[4]):

            cnt += 222

        continue

    if len(i_str) == 6:

        if int(i_str[0]) == int(i_str[5]):

            cnt += 2224 + 2000 * int(i_str[1]) + 200 * int(i_str[2]) + 20 * int(i_str[3]) + 2 * (int(i_str[4])+1) - 1

        elif int(i_str[5]) != 0 and int(i_str[0]) > int(i_str[5]):

            cnt += 22222

        elif int(i_str[0]) < int(i_str[5]):

            cnt += 2222

        continue

print(cnt)

n = int(input())

c = [[0 for _ in range(10)] for __ in range(10)]

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

    str_i = str(i)

    head = int(str_i[0])

    tail = int(str_i[-1])

    c[head][tail] += 1

cnt = 0

for i in range(10):

    for j in range(10):

        cnt += c[i][j] * c[j][i]

print(cnt)

n = int(input())
cnt = 0
for i in range(1, n + 1):
    i_str = str(i)
    if len(i_str) == 1:
        cnt += 1
        continue
    if len(i_str) == 2:
        if int(i_str[0]) == int(i_str[1]):
            cnt += 3
        elif int(i_str[1]) != 0 and int(i_str[0]) > int(i_str[1]):
            cnt += 2
        continue
    if len(i_str) == 3:
        if int(i_str[0]) == int(i_str[2]):
            cnt += 4 + (2 * (int(i_str[1]) + 1) - 1)
        elif int(i_str[2]) != 0 and int(i_str[0]) > int(i_str[2]):
            cnt += 22
        elif int(i_str[0]) < int(i_str[2]):
            cnt += 2
        continue
    if len(i_str) == 4:
        if int(i_str[0]) == int(i_str[3]):
            cnt += 24 + 20 * int(i_str[1]) + 2 * (int(i_str[2]) + 1) - 1
        elif int(i_str[3]) != 0 and int(i_str[0]) > int(i_str[3]):
            cnt += 222
        elif int(i_str[0]) < int(i_str[3]):
            cnt += 22
        continue
    if len(i_str) == 5:
        if int(i_str[0]) == int(i_str[4]):
            cnt += (
                224
                + 200 * int(i_str[1])
                + 20 * int(i_str[2])
                + 2 * (int(i_str[3]) + 1)
                - 1
            )
        elif int(i_str[4]) != 0 and int(i_str[0]) > int(i_str[4]):
            cnt += 2222
        elif int(i_str[0]) < int(i_str[4]):
            cnt += 222
        continue
    if len(i_str) == 6:
        if int(i_str[0]) == int(i_str[5]):
            cnt += (
                2224
                + 2000 * int(i_str[1])
                + 200 * int(i_str[2])
                + 20 * int(i_str[3])
                + 2 * (int(i_str[4]) + 1)
                - 1
            )
        elif int(i_str[5]) != 0 and int(i_str[0]) > int(i_str[5]):
            cnt += 22222
        elif int(i_str[0]) < int(i_str[5]):
            cnt += 2222
        continue
print(cnt)

n = int(input())
c = [[0 for _ in range(10)] for __ in range(10)]
for i in range(1, n + 1):
    str_i = str(i)
    head = int(str_i[0])
    tail = int(str_i[-1])
    c[head][tail] += 1
cnt = 0
for i in range(10):
    for j in range(10):
        cnt += c[i][j] * c[j][i]
print(cnt)

+c = [[0 for _ in range(10)] for __ in range(10)]

-        if int(i_str[0]) == int(i_str[1]):

-        elif int(i_str[1]) != 0 and int(i_str[0]) > int(i_str[1]):

-        if int(i_str[0]) == int(i_str[2]):

-        elif int(i_str[2]) != 0 and int(i_str[0]) > int(i_str[2]):

-        elif int(i_str[0]) < int(i_str[2]):

-        if int(i_str[0]) == int(i_str[3]):

-        elif int(i_str[3]) != 0 and int(i_str[0]) > int(i_str[3]):

-        elif int(i_str[0]) < int(i_str[3]):

-        if int(i_str[0]) == int(i_str[4]):

-        elif int(i_str[4]) != 0 and int(i_str[0]) > int(i_str[4]):

-        elif int(i_str[0]) < int(i_str[4]):

-        if int(i_str[0]) == int(i_str[5]):

-        elif int(i_str[5]) != 0 and int(i_str[0]) > int(i_str[5]):

-        elif int(i_str[0]) < int(i_str[5]):


Input:
import math

N = int(input())

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

print(ans)

N = int(input())

mod = 10**9 + 7

ans = 1

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

    ans *= i

    ans %= mod

print(ans)

-import math
-ans = math.factorial(N) % (10**9 + 7)
+mod = 10**9 + 7
+ans = 1
+for i in range(1, N + 1):
+    ans *= i
+    ans %= mod