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

ans=chk=0

for i in range(k+1):

    for j in range(k+1):

        if (0<=s-i-j<=k): ans+=1

print(ans)

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

ans=0

x=min(k+1,s+1)

y=max(0,s-k-k)

for i in range(y,x):

    for j in range(y,x):

        if i+j>s: break

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

            ans+=1

print(ans)

k, s = list(map(int, input().split()))
ans = chk = 0
for i in range(k + 1):
    for j in range(k + 1):
        if 0 <= s - i - j <= k:
            ans += 1
print(ans)

k, s = list(map(int, input().split()))
ans = 0
x = min(k + 1, s + 1)
y = max(0, s - k - k)
for i in range(y, x):
    for j in range(y, x):
        if i + j > s:
            break
        if 0 <= s - i - j <= k:
            ans += 1
print(ans)

-ans = chk = 0
-for i in range(k + 1):
-    for j in range(k + 1):
+ans = 0
+x = min(k + 1, s + 1)
+y = max(0, s - k - k)
+for i in range(y, x):
+    for j in range(y, x):
+        if i + j > s:
+            break


Input:
N,K = int(input()), int(input())

now = 1

for i in range(N):

    if now*2 < now + K:

        now *= 2

    else:

        now += K

print(now)

N = int(input())

K = int(input())

ans = 1

for i in range(N):

    if ans < K:

        ans *= 2

    else:

        ans += K

print(ans)

N, K = int(input()), int(input())
now = 1
for i in range(N):
    if now * 2 < now + K:
        now *= 2
    else:
        now += K
print(now)

-N, K = int(input()), int(input())
-now = 1
+N = int(input())
+K = int(input())
+ans = 1
-    if now * 2 < now + K:
-        now *= 2
+    if ans < K:
+        ans *= 2
-        now += K
-print(now)
+        ans += K
+print(ans)


Input:
import math

n=int(input())

ans=n

i=1

while(i<=math.sqrt(n)):

    if n%i==0:

        d=i+n/i-2

        ans=min(ans,d)

    i+=1

print((int(ans)))

from math import floor

from math import sqrt

n=int(input())

nn=floor(sqrt(n))

rest=n%nn

while rest!=0:

    nn-=1

    rest=n%nn

nnn=n/nn

print((int(nn+nnn-2)))

import math

n = int(input())
ans = n
i = 1
while i <= math.sqrt(n):
    if n % i == 0:
        d = i + n / i - 2
        ans = min(ans, d)
    i += 1
print((int(ans)))

from math import floor
from math import sqrt

n = int(input())
nn = floor(sqrt(n))
rest = n % nn
while rest != 0:
    nn -= 1
    rest = n % nn
nnn = n / nn
print((int(nn + nnn - 2)))

-import math
+from math import floor
+from math import sqrt
-ans = n
-i = 1
-while i <= math.sqrt(n):
-    if n % i == 0:
-        d = i + n / i - 2
-        ans = min(ans, d)
-    i += 1
-print((int(ans)))
+nn = floor(sqrt(n))
+rest = n % nn
+while rest != 0:
+    nn -= 1
+    rest = n % nn
+nnn = n / nn
+print((int(nn + nnn - 2)))


Input:
import math

N = int(input())

power = math.factorial(N)

print((power % 1000000007))

n=int(input())

ans=1

for i in range(n):

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

print(ans)

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


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

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

dp = ["Second"] * (k + 1)

for i in range(k + 1):

    if dp[i] == "Second":

        for a in a_s:

            ii = i + a

            if ii <= k:

                dp[ii] = "First"

print((dp[-1]))

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

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

dp = ["Second"] * (k + 1)

for i in range(k + 1):

    if dp[i] == "Second":

        for a in a_s:

            ii = i + a

            if ii > k:break

            dp[ii] = "First"

print((dp[-1]))

n, k = list(map(int, input().split()))
a_s = list(map(int, input().split()))
dp = ["Second"] * (k + 1)
for i in range(k + 1):
    if dp[i] == "Second":
        for a in a_s:
            ii = i + a
            if ii > k:
                break
            dp[ii] = "First"
print((dp[-1]))

-            if ii <= k:
-                dp[ii] = "First"
+            if ii > k:
+                break
+            dp[ii] = "First"


Input:
S, T = [list(input()) for _ in range(2)]

cnt = 0

for i in range(len(S)):

    if S[i] != T[i]:

        cnt += 1

print(cnt)

s, t = [input() for i in range(2)]

ans = 0

for i in range(len(s)):

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

    ans += 1

print(ans)

-S, T = [list(input()) for _ in range(2)]


Input:
N = int(input())

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

cnt = 0

for i in range(N-1):

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

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

print(cnt)

N = int(input())

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

cnt = 0

for i in range(N):

    cnt += D[i]**2

tot = 0

for i in range(N):

    tot += D[i]

tot = tot**2

tot -= cnt

print((tot//2))

N = int(input())
D = list(map(int, input().split()))
cnt = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        cnt += D[i] * D[j]
print(cnt)

N = int(input())
D = list(map(int, input().split()))
cnt = 0
for i in range(N):
    cnt += D[i] ** 2
tot = 0
for i in range(N):
    tot += D[i]
tot = tot**2
tot -= cnt
print((tot // 2))

-for i in range(N - 1):
-    for j in range(i + 1, N):
-        cnt += D[i] * D[j]
-print(cnt)
+for i in range(N):
+    cnt += D[i] ** 2
+tot = 0
+for i in range(N):
+    tot += D[i]
+tot = tot**2
+tot -= cnt
+print((tot // 2))


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

mn = [0]*N

for i in range(N):

  mn[i] = int(input())

ans = N

x = X - sum(mn)

while(x >= min(mn)):

  if x // min(mn) == 0:

    mn[mn.index(min(mn))] = 1000000

  else:

    if x >= min(mn):

      x -= min(mn)

      ans += 1

print(ans)

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

mn = [0]*N

for i in range(N):

  mn[i] = int(input())

ans = N

x = X - sum(mn)

while(x >= min(mn)):

  if x // min(mn) == 0:

    mn[mn.index(min(mn))] = 1000000

  else:

    x -= min(mn)

    ans += 1

print(ans)

N, X = list(map(int, input().split()))
mn = [0] * N
for i in range(N):
    mn[i] = int(input())
ans = N
x = X - sum(mn)
while x >= min(mn):
    if x // min(mn) == 0:
        mn[mn.index(min(mn))] = 1000000
    else:
        if x >= min(mn):
            x -= min(mn)
            ans += 1
print(ans)

N, X = list(map(int, input().split()))
mn = [0] * N
for i in range(N):
    mn[i] = int(input())
ans = N
x = X - sum(mn)
while x >= min(mn):
    if x // min(mn) == 0:
        mn[mn.index(min(mn))] = 1000000
    else:
        x -= min(mn)
        ans += 1
print(ans)

-        if x >= min(mn):
-            x -= min(mn)
-            ans += 1
+        x -= min(mn)
+        ans += 1


Input:
#! /usr/bin/env python3

import sys

int1 = lambda x: int(x) - 1

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(500000)

def isMultiple(s, m):

    tmp = 0

    for i in range(len(s)):

        tmp = (tmp * 10 + int(s[i])) % m

        if tmp == 0:

            return i

    return -1

k = int(readline())

acc = "7" * 50000000

if k % 2 == 0:

    ans = -1

else:

    ans = isMultiple(acc, k)

    if ans != -1:

        ans += 1

print(ans)

#! /usr/bin/env python3

import sys

int1 = lambda x: int(x) - 1

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(500000)

k = int(readline())

ans = -1

acc = 7 % k

for n in range(1, k + 10):

    if acc == 0:

        ans = n

        break

    acc = (10 * acc + 7) % k

print(ans)


Input: n,*l=list(map(int,open(0).read().split()));print((sum(sorted(l*2)[-2:~n:-1])))

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

l.sort(reverse=1)

print((sum(l[i//2] for i in range(1,n))))

n, *l = list(map(int, open(0).read().split()))
print((sum(sorted(l * 2)[-2:~n:-1])))

n, *l = list(map(int, open(0).read().split()))
l.sort(reverse=1)
print((sum(l[i // 2] for i in range(1, n))))

+print((sum(l[i // 2] for i in range(1, n))))


Input:
import math

N = int(input())

for i in range(int(math.sqrt(N))):

    if N % (int(math.sqrt(N))-i) == 0:

        print((int(N/(int(math.sqrt(N))-i)+int(math.sqrt(N))-i-2)))

        break

import math

N = int(input())

M = int(math.sqrt(N))

for i in range(M):

    if N % (M-i) == 0:

        print((int(N/(M-i)+M-i-2)))

        break

import math

N = int(input())
for i in range(int(math.sqrt(N))):
    if N % (int(math.sqrt(N)) - i) == 0:
        print((int(N / (int(math.sqrt(N)) - i) + int(math.sqrt(N)) - i - 2)))
        break

import math

N = int(input())
M = int(math.sqrt(N))
for i in range(M):
    if N % (M - i) == 0:
        print((int(N / (M - i) + M - i - 2)))
        break

-    if N % (int(math.sqrt(N)) - i) == 0:

-        print((int(N / (int(math.sqrt(N)) - i) + int(math.sqrt(N)) - i - 2)))


Input:
N, L = [int(i) for i in input().split()]

min_ = L

max_ = L + N -1

def eat_apple():

    if max_<0:

        return max_

    if L < 0:

        return 0

    return L

print(((min_+max_)*(max_-min_+1)//2 - eat_apple()))

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

min_ = L

max_ = L + N -1

def eat_apple(N, L, max_):

    if max_<0:

        return max_

    if L < 0:

        return 0

    return L

print(((min_+max_)*(max_-min_+1)//2 - eat_apple(N, L, max_)))

N, L = [int(i) for i in input().split()]
min_ = L
max_ = L + N - 1

def eat_apple():
    if max_ < 0:
        return max_
    if L < 0:
        return 0
    return L

print(((min_ + max_) * (max_ - min_ + 1) // 2 - eat_apple()))

N, L = [int(i) for i in input().split()]
min_ = L
max_ = L + N - 1

def eat_apple(N, L, max_):
    if max_ < 0:
        return max_
    if L < 0:
        return 0
    return L

print(((min_ + max_) * (max_ - min_ + 1) // 2 - eat_apple(N, L, max_)))

-print(((min_ + max_) * (max_ - min_ + 1) // 2 - eat_apple()))

+print(((min_ + max_) * (max_ - min_ + 1) // 2 - eat_apple(N, L, max_)))


Input:
S = [int(_) for _ in input()]

length = len(S)

temp = [S[0]]

for x in S[1:]:

    if(len(temp) == 0):

        temp.append(x)

    elif( temp[-1] == x):

        temp.append(x)

    else:

        temp.pop(-1)

print((length-len(temp)))

def main():

    A = input()

    print((2*min(A.count("0"),A.count("1"))))

if __name__ == "__main__":

    main()

S = [int(_) for _ in input()]
length = len(S)
temp = [S[0]]
for x in S[1:]:
    if len(temp) == 0:
        temp.append(x)
    elif temp[-1] == x:
        temp.append(x)
    else:
        temp.pop(-1)
print((length - len(temp)))

def main():
    A = input()
    print((2 * min(A.count("0"), A.count("1"))))

if __name__ == "__main__":
    main()


Input:
K = int(input())

flg = [False]*K

tmp = 7 % K

cnt = 1

if tmp == 0:

    print(cnt)

    exit()

while True:

    tmp = (tmp*10+7)%K

    if flg[tmp]:

        print((-1))

        break

    else:

        cnt += 1

        if tmp == 0:

            print(cnt)

            break

        flg[tmp] = True

K = int(input())

t = 7

t %= K

for i in range(K+1):

    if t == 0:

        print((i+1))

        exit()

    t = (t*10+7)%K

print((-1))

K = int(input())
flg = [False] * K
tmp = 7 % K
cnt = 1
if tmp == 0:
    print(cnt)
    exit()
while True:
    tmp = (tmp * 10 + 7) % K
    if flg[tmp]:
        print((-1))
        break
    else:
        cnt += 1
        if tmp == 0:
            print(cnt)
            break
        flg[tmp] = True

K = int(input())
t = 7
t %= K
for i in range(K + 1):
    if t == 0:
        print((i + 1))
        exit()
    t = (t * 10 + 7) % K
print((-1))

-flg = [False] * K
-tmp = 7 % K
-cnt = 1
-if tmp == 0:
-    print(cnt)
-    exit()
-while True:
-    tmp = (tmp * 10 + 7) % K
-    if flg[tmp]:
-        print((-1))
-        break
-    else:
-        cnt += 1
-        if tmp == 0:
-            print(cnt)
-            break
-        flg[tmp] = True
+t = 7
+t %= K
+for i in range(K + 1):
+    if t == 0:
+        print((i + 1))
+        exit()
+    t = (t * 10 + 7) % K
+print((-1))


Input:
from math import factorial

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

ans = 1

for k in range(1, int(input())+1):

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

print(ans)

from math import factorial

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

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

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


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

count = 0

for i in range(N):

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

    if (a**2 + b**2) <= D**2:

        count += 1

print(count)

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

count = 0

for i in range(N):

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

    if (a*a + b*b) <= D*D:

        count += 1

print(count)

N, D = list(map(int, input().split()))
count = 0
for i in range(N):
    a, b = list(map(int, input().split()))
    if (a * a + b * b) <= D * D:
        count += 1
print(count)


Input:
# ABC102C - Linear Approximation (ARC100C)

from statistics import median

def main():

    n = int(input())

    A = tuple(map(int, input().rstrip().split()))

    A = tuple(j - i for i, j in enumerate(A, start=1))

    b = median(A)

    ans = sum(abs(a - b) for a in A)

    print((int(ans)))

if __name__ == "__main__":

    main()

# ABC102C - Linear Approximation (ARC100C)

def main():

    n = int(input())

    A = tuple(map(int, input().rstrip().split()))

    A = sorted(j - i for i, j in enumerate(A, start=1))

    b = A[n // 2]

    ans = sum(abs(a - b) for a in A)

    print(ans)

if __name__ == "__main__":

    main()

-    A = tuple(j - i for i, j in enumerate(A, start=1))

+    A = sorted(j - i for i, j in enumerate(A, start=1))


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

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

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

bc.sort(key=lambda x: x[1], reverse=True)

a.sort()

i = 0

for b, c in bc:

    for _ in range(b):

        if i < n and a[i] < c:

            a[i] = c

            i += 1

        else:

            break

ans = sum(a)

print(ans)

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

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

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

bc.sort(reverse=True, key=lambda x: x[1])

li = []

l = 0

i = 0

while i < m and l < n:

    b, c = bc[i]

    li += [c] * b

    i += 1

    l += b

a += li

a.sort(reverse=True)

ans = sum(a[:n])

print(ans)

-bc.sort(key=lambda x: x[1], reverse=True)

+bc.sort(reverse=True, key=lambda x: x[1])


Input:
import math

n = int(input())

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

n = int(input())

mod = 10**9 + 7

pow = 1

for i in range(n):

    pow = pow*(i+1)%mod

print(pow)

import math

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

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

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


Input:
S = list(input())

num_one = S.count("1")

num_zero = S.count("0")

ans = min(num_one, num_zero) *2

print(ans)

S = input()

ans = min(S.count("0"), S.count("1")) * 2

print(ans)

S = list(input())
num_one = S.count("1")
num_zero = S.count("0")
ans = min(num_one, num_zero) * 2
print(ans)


Input:
import sys

can = True; input()

e = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]

for a, b in zip(e[1:], e):

    t = a[0] - b[0] - abs(a[1] - b[1]) - abs(a[2] - b[2])

    if t < 0 or t % 2 == 1: can = False; break

print((['No', 'Yes'][can]))

import sys

ans = 'Yes'; input()

for e in sys.stdin:

    t, x, y = list(map(int, e.split()))

    t = t - x - y

    if t < 0 or t % 2 == 1: ans = 'No'; break

print(ans)

import sys

can = True
input()
e = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]
for a, b in zip(e[1:], e):
    t = a[0] - b[0] - abs(a[1] - b[1]) - abs(a[2] - b[2])
    if t < 0 or t % 2 == 1:
        can = False
        break
print((["No", "Yes"][can]))

import sys

ans = "Yes"
input()
for e in sys.stdin:
    t, x, y = list(map(int, e.split()))
    t = t - x - y
    if t < 0 or t % 2 == 1:
        ans = "No"
        break
print(ans)

-e = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]

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


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

sunuke = [True]*N

for i in range(K):

    d = int(input())

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

    for a in A:

        sunuke[a-1] = False

ans = 0

for i in range(N):

    if sunuke[i]:

        ans += 1

print(ans)

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

flag = [True]*N

for i in range(K):

    d = int(input())

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

    for a in A:

        flag[a-1] = False

ans = 0

for i in range(N):

    if flag[i]:

        ans += 1

print(ans)

N, K = list(map(int, input().split()))
sunuke = [True] * N
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for a in A:
        sunuke[a - 1] = False
ans = 0
for i in range(N):
    if sunuke[i]:
        ans += 1
print(ans)

N, K = list(map(int, input().split()))
flag = [True] * N
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for a in A:
        flag[a - 1] = False
ans = 0
for i in range(N):
    if flag[i]:
        ans += 1
print(ans)

-sunuke = [True] * N
+flag = [True] * N
-        sunuke[a - 1] = False
+        flag[a - 1] = False
-    if sunuke[i]:
+    if flag[i]:


Input:
import sys

def input(): return sys.stdin.readline().strip()

def resolve():

    import math

    n=int(input())

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

resolve()

import sys

def input(): return sys.stdin.readline().strip()

def resolve():

    answer=1

    n=int(input())

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

        answer*=i

        answer%=10**9+7

    print(answer)

resolve()

import sys

def input():
    return sys.stdin.readline().strip()

def resolve():
    import math

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

resolve()

import sys

def input():
    return sys.stdin.readline().strip()

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

resolve()

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


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

j = 0

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

  l = list(str(i))

  l_reverse = list(reversed(l))

  if l == l_reverse:

    j += 1

print(j)

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

ans = 0

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

    n = str(n)

    if n == n[::-1]:

        ans += 1

print(ans)

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

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

-j = 0
-for i in range(A, B + 1):
-    l = list(str(i))
-    l_reverse = list(reversed(l))
-    if l == l_reverse:
-        j += 1
-print(j)
+ans = 0
+for n in range(A, B + 1):
+    n = str(n)
+    if n == n[::-1]:
+        ans += 1
+print(ans)


Input:
s = int(input())

m, s = s // 60, s % 60

h, m = m // 60, m % 60

print((':'.join(map(str, [h,m,s]))))

s = int(input())

second = s % 60

s = s // 60

min = s % 60

hour = s // 60

print(f'{hour}:{min}:{second}')

s = int(input())
second = s % 60
s = s // 60
min = s % 60
hour = s // 60
print(f"{hour}:{min}:{second}")


Input:
import math

N = int(input())

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

import math

N = int(input())

a = 1

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

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

print(a)

import math

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

import math

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

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


Input:
import functools

print((len(functools.reduce(lambda x, y: x&y,[set(input().split()[1:]) for _ in [0]*int(input().split()[0])]))))

print((len(set.intersection(*[set(input().split()[1:]) for _ in [0]*int(input().split()[0])]))))

import functools

print(
    (
        len(
            functools.reduce(
                lambda x, y: x & y,
                [set(input().split()[1:]) for _ in [0] * int(input().split()[0])],
            )
        )
    )
)

print(
    (
        len(
            set.intersection(
                *[set(input().split()[1:]) for _ in [0] * int(input().split()[0])]
            )
        )
    )
)

-                [set(input().split()[1:]) for _ in [0] * int(input().split()[0])],

+                *[set(input().split()[1:]) for _ in [0] * int(input().split()[0])]


Input:
N = int(input())

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

SUM = 0

for i in A:

    count = 0

    while i%2 == 0:

        i//=2

        count += 1

    SUM+=count

print(SUM)

N = int(input())

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

SUM = 0

for i in A:

    while i%2 == 0:

        i//=2

        SUM += 1

print(SUM)

N = int(input())
A = list(map(int, input().split()))
SUM = 0
for i in A:
    count = 0
    while i % 2 == 0:
        i //= 2
        count += 1
    SUM += count
print(SUM)

N = int(input())
A = list(map(int, input().split()))
SUM = 0
for i in A:
    while i % 2 == 0:
        i //= 2
        SUM += 1
print(SUM)

-    count = 0
-        count += 1
-    SUM += count
+        SUM += 1


Input:
n = int(input())

INF = 10**9 + 7

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

ans[0] = 1

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

    ans[i] = ans[i-1] * i % INF

print((ans[n]))

n = int(input())

mod = 10**9 + 7

ans = 1

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

    ans = ans * i % mod

print(ans)

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


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

ans = a * x + b * y

m = max(x, y)

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

  x -= 1

  y -= 1

  if x < 0:

    x = 0

  if y < 0:

    y = 0

  temp = c*(i*2) + x*a + y*b

  if temp < ans:

    ans = temp

print(ans)

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

ans = a * x + b * y

ans = min(c * max(x, y) * 2, ans)

if x < y:

    ans = min(c * x * 2 + (y - x) * b, ans)

else:

    ans = min(c * y * 2 + (x - y) * a, ans)

print(ans)

a, b, c, x, y = list(map(int, input().split()))
ans = a * x + b * y
m = max(x, y)
for i in range(1, m + 1):
    x -= 1
    y -= 1
    if x < 0:
        x = 0
    if y < 0:
        y = 0
    temp = c * (i * 2) + x * a + y * b
    if temp < ans:
        ans = temp
print(ans)

+    ans = min(c * x * 2 + (y - x) * b, ans)

+    ans = min(c * y * 2 + (x - y) * a, ans)


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

point = []

for i in range(N):

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

ct = 0

D2 = D * D

for i in point:

    if (i[0]**2 + i[1]**2) <= D2:

        ct += 1

print(ct)

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

ct = 0

D2 = D * D

for i in range(N):

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

    if (X**2 + Y**2) <= D2:

        ct += 1

print(ct)

N, D = list(map(int, input().split()))
point = []
for i in range(N):
    point.append(list(map(int, input().split())))
ct = 0
D2 = D * D
for i in point:
    if (i[0] ** 2 + i[1] ** 2) <= D2:
        ct += 1
print(ct)

-    point.append(list(map(int, input().split())))

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


Input:
from math import factorial

mod = 10**9 + 7

n = int(input())

ans = factorial(n) % mod

print(ans)

N = int(input())

MOD = 10**9 + 7

ans = 1

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

    ans *= i

    ans %= MOD

print(ans)

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

-from math import factorial
-mod = 10**9 + 7
-n = int(input())
-ans = factorial(n) % mod
+N = int(input())
+MOD = 10**9 + 7
+ans = 1
+for i in range(2, N + 1):
+    ans *= i
+    ans %= MOD


Input:
from collections import Counter

import sys

input = sys.stdin.readline

def solve():

    N = int(input())

    Sss = [input().rstrip() for _ in range(N)]

    cnt = Counter(Sss)

    #print('cnt:', cnt)

    maxNum = max(cnt.values())

    #print('maxNum:', maxNum)

    anss = []

    for key, value in list(cnt.items()):

        if value == maxNum:

            anss.append(key)

    #print('anss:', anss)

    anss.sort()

    print(('\n'.join(anss)))

solve()

from collections import Counter

import sys

input = sys.stdin.readline

N = int(input())

Sss = [input().rstrip() for _ in range(N)]

cnt = Counter(Sss)

num = max(cnt.values())

anss = []

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

    if cnt[key] == num:

        anss.append(key)

print(('\n'.join(anss)))

from collections import Counter
import sys

input = sys.stdin.readline

def solve():
    N = int(input())
    Sss = [input().rstrip() for _ in range(N)]
    cnt = Counter(Sss)
    # print('cnt:', cnt)
    maxNum = max(cnt.values())
    # print('maxNum:', maxNum)
    anss = []
    for key, value in list(cnt.items()):
        if value == maxNum:
            anss.append(key)
    # print('anss:', anss)
    anss.sort()
    print(("\n".join(anss)))

solve()

from collections import Counter
import sys

input = sys.stdin.readline
N = int(input())
Sss = [input().rstrip() for _ in range(N)]
cnt = Counter(Sss)
num = max(cnt.values())
anss = []
for key in sorted(cnt.keys()):
    if cnt[key] == num:
        anss.append(key)
print(("\n".join(anss)))

-    Sss = [input().rstrip() for _ in range(N)]

-    for key, value in list(cnt.items()):

+Sss = [input().rstrip() for _ in range(N)]


Input:
from functools import lru_cache

import sys

sys.setrecursionlimit(2000)

s = int(input())

mod = 10 ** 9 + 7

@lru_cache(maxsize=None)

def dfs(n):

    if n <= 2:

        return 0

    elif 3<=n<=5:

        return 1

    else:

        count = 1

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

            count += dfs(n - i)

            count %= mod

        return count % mod

ans = dfs(s)

print(ans)

s = int(input())

mod = 10 ** 9 + 7

dp = [0] * (s + 1)

dp[0] = 1

x = 0

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

    x += dp[i - 3]

    dp[i] = x % mod

ans = dp[s] % mod

print(ans)

from functools import lru_cache
import sys

sys.setrecursionlimit(2000)
s = int(input())
mod = 10**9 + 7

@lru_cache(maxsize=None)
def dfs(n):
    if n <= 2:
        return 0
    elif 3 <= n <= 5:
        return 1
    else:
        count = 1
        for i in range(3, n + 1):
            count += dfs(n - i)
            count %= mod
        return count % mod

ans = dfs(s)
print(ans)

s = int(input())
mod = 10**9 + 7
dp = [0] * (s + 1)
dp[0] = 1
x = 0
for i in range(3, s + 1):
    x += dp[i - 3]
    dp[i] = x % mod
ans = dp[s] % mod
print(ans)

-from functools import lru_cache
-import sys
-sys.setrecursionlimit(2000)
-@lru_cache(maxsize=None)
-def dfs(n):
-    if n <= 2:
-        return 0
-    elif 3 <= n <= 5:
-        return 1
-    else:
-        count = 1
-        for i in range(3, n + 1):
-            count += dfs(n - i)
-            count %= mod
-        return count % mod
-ans = dfs(s)
+dp = [0] * (s + 1)
+dp[0] = 1
+x = 0
+for i in range(3, s + 1):
+    x += dp[i - 3]
+    dp[i] = x % mod
+ans = dp[s] % mod


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

num = 0

q = []

for i in range(n):

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

    q.append((a,b))

q.sort()

for i in range(n):

    a, b = q[i][0], q[i][1]

    num += b

    if num >= k:

        print(a)

        exit()

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

cnt = 0

num = []

for i in range(n):

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

    num.append((a,b))

num.sort()

for i in range(n):

    cnt += num[i][1]

    if cnt >= k:

        print((num[i][0]))

        exit()

n, k = list(map(int, input().split()))
num = 0
q = []
for i in range(n):
    a, b = list(map(int, input().split()))
    q.append((a, b))
q.sort()
for i in range(n):
    a, b = q[i][0], q[i][1]
    num += b
    if num >= k:
        print(a)
        exit()

n, k = list(map(int, input().split()))
cnt = 0
num = []
for i in range(n):
    a, b = list(map(int, input().split()))
    num.append((a, b))
num.sort()
for i in range(n):
    cnt += num[i][1]
    if cnt >= k:
        print((num[i][0]))
        exit()

-num = 0
-q = []
+cnt = 0
+num = []
-    q.append((a, b))
-q.sort()
+    num.append((a, b))
+num.sort()
-    a, b = q[i][0], q[i][1]
-    num += b
-    if num >= k:
-        print(a)
+    cnt += num[i][1]
+    if cnt >= k:
+        print((num[i][0]))


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

cnt=0

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

    n=list(str(i))

    if n==list(reversed(n)):

        cnt+=1

print(cnt)

from sys import stdin

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

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

a,b=nii()

ans=0

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

  s=str(i)

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

    ans+=1

print(ans)

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

from sys import stdin

nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
a, b = nii()
ans = 0
for i in range(a, b + 1):
    s = str(i)
    if s == s[::-1]:
        ans += 1
print(ans)

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

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


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

count = 0

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

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

        count += 1

print(count)

def solve(string):

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

    count = 0

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

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

            count += 1

    return str(count)

if __name__ == '__main__':

    print((solve(input())))

def solve(string):
    a, b = list(map(int, string.split()))
    count = 0
    for i in range(a, b + 1):
        if str(i) == str(i)[::-1]:
            count += 1
    return str(count)

if __name__ == "__main__":
    print((solve(input())))

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

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


Input:
import math

N = int(input())

p = math.factorial(N)

print((p % 1000000007))

N = int(input())

p = 1

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

    p *= i

    p %= 1000000007

print(p)

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

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


Input:
N = int(input())

def dist(i, j):

    return i + j - 2

min = 10 ** 24

i = 1

while (i ** 2) <= N:

    if 0 == N % i:

        j = N // i

        d = dist(i, j)

        if min > d:

            min = d

    i += 1

print(d)

import math

n = int(input())

ans = 0

for i in range(math.ceil(math.sqrt(n) + 1))[:0:-1]:

    if 0 == n % i:

        ans = i

        break

ans_partner = n // ans

print((ans + ans_partner - 2))

N = int(input())

def dist(i, j):
    return i + j - 2

min = 10**24
i = 1
while (i**2) <= N:
    if 0 == N % i:
        j = N // i
        d = dist(i, j)
        if min > d:
            min = d
    i += 1
print(d)

+for i in range(math.ceil(math.sqrt(n) + 1))[:0:-1]:


Input:
n = int(input())

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

n = int(input())

print((0 if n else 1))

-print((1 if n == 0 else 0))
+print((0 if n else 1))


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

MOD = 10**9+7

dp = [0]*(N+1)

dp[0]=1

A = [int(input()) for i in range(M)]

ban = [1]*(N+1)

for a in A:

    ban[a]=0

for i in range(N):

    if i-1>=0:

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

    else:

        dp[i+1]=dp[i]*ban[i]

    dp[i+1] %= MOD

print((dp[N]))

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

A = [int(input()) for i in range(M)]

MOD = 10**9+7

A = set(A)

dp = [0]*(N+1)

dp[0] = 1

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

    if i in A:

        continue

    if i == 1:

        dp[1] = dp[0]

    else:

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

print((dp[N]))

N, M = list(map(int, input().split()))
MOD = 10**9 + 7
dp = [0] * (N + 1)
dp[0] = 1
A = [int(input()) for i in range(M)]
ban = [1] * (N + 1)
for a in A:
    ban[a] = 0
for i in range(N):
    if i - 1 >= 0:
        dp[i + 1] = dp[i] * ban[i] + dp[i - 1] * ban[i - 1]
    else:
        dp[i + 1] = dp[i] * ban[i]
    dp[i + 1] %= MOD
print((dp[N]))

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


Input:
def main():

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

    M = max(X, Y)

    k = 0

    ans = A * X + B * Y

    while True:

        ans = min(

            ans,

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

        )

        if k >= M: break

        k += 1

    print(ans)

if __name__ == '__main__':

    main()

def main():

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

    ans = 1 << 30

    c = 0  # even

    while True:

        j = c // 2

        t = A * max(0, X - j) + B * max(0, Y - j) + C * c

        if ans <= t: break

        ans = t

        c += 2

    print(ans)

if __name__ == '__main__':

    main()

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

if __name__ == "__main__":
    main()

def main():
    A, B, C, X, Y = list(map(int, input().split()))
    ans = 1 << 30
    c = 0  # even
    while True:
        j = c // 2
        t = A * max(0, X - j) + B * max(0, Y - j) + C * c
        if ans <= t:
            break
        ans = t
        c += 2
    print(ans)

if __name__ == "__main__":
    main()

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

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

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


Input:
def popcount(x):

  r, q = 0, x

  while x:

    r += 1

    x &= x - 1

  return r, q

n = int(input())

r = list(range(n))

a = [[0, 0] for _ in r]

for i in r:

  for _ in range(int(input())):

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

    a[i][y] |= 1 << (x - 1)

l = (1 << n) - 1

b = sorted(map(popcount, list(range(1, l + 1))))

ans = next((i for i, x in reversed(b)

           if all(a[j][0] & x == a[j][1] & l - x == 0 for j in r if x >> j & 1)), 0)

print(ans)

from itertools import combinations, count

n = int(input())

r = list(range(n))

a = [(set(), set()) for _ in r]

for i in r:

  for _ in range(int(input())):

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

    a[i][y].add(x - 1)

r = next(i for i in count(n, - 1) for x in map(set, combinations(r, i))

         if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x))

print(r)

def popcount(x):
    r, q = 0, x
    while x:
        r += 1
        x &= x - 1
    return r, q

n = int(input())
r = list(range(n))
a = [[0, 0] for _ in r]
for i in r:
    for _ in range(int(input())):
        x, y = list(map(int, input().split()))
        a[i][y] |= 1 << (x - 1)
l = (1 << n) - 1
b = sorted(map(popcount, list(range(1, l + 1))))
ans = next(
    (
        i
        for i, x in reversed(b)
        if all(a[j][0] & x == a[j][1] & l - x == 0 for j in r if x >> j & 1)
    ),
    0,
)
print(ans)

from itertools import combinations, count

n = int(input())
r = list(range(n))
a = [(set(), set()) for _ in r]
for i in r:
    for _ in range(int(input())):
        x, y = list(map(int, input().split()))
        a[i][y].add(x - 1)
r = next(
    i
    for i in count(n, -1)
    for x in map(set, combinations(r, i))
    if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x)
)
print(r)

+from itertools import combinations, count

-b = sorted(map(popcount, list(range(1, l + 1))))

+    for x in map(set, combinations(r, i))

+    if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x)


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

if x - r >= 0 and x + r <= W and y - r >= 0 and y + r <= H:

    print("Yes")

else:

    print("No")

W, H, x, y, r = list(map(int, 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()]
if x - r >= 0 and x + r <= W and y - r >= 0 and y + r <= H:
    print("Yes")
else:
    print("No")

W, H, x, y, r = list(map(int, 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()]

-if x - r >= 0 and x + r <= W and y - r >= 0 and y + r <= H:

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

+if r <= x <= W - r and r <= y <= H - r:


Input:
from math import log2

n = int(input())

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

ans = 0

for _a in a:

    if _a%2 == 0:

        cnt =0

        while _a%2 == 0:

            _a //= 2

            cnt += 1

        ans += cnt

print((int(ans)))

def f(k):

    cnt = 0

    while k%2 == 0:

        k //= 2

        cnt += 1

        # print(k)

        # print("-----")

    return cnt

n = int(input())

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

ans = 0

for a in A:

    if a%2 == 0:

        ans += f(a)

print(ans)

from math import log2

n = int(input())
a = list(map(int, input().split()))
ans = 0
for _a in a:
    if _a % 2 == 0:
        cnt = 0
        while _a % 2 == 0:
            _a //= 2
            cnt += 1
        ans += cnt
print((int(ans)))

def f(k):
    cnt = 0
    while k % 2 == 0:
        k //= 2
        cnt += 1
        # print(k)
        # print("-----")
    return cnt

n = int(input())
A = list(map(int, input().split()))
ans = 0
for a in A:
    if a % 2 == 0:
        ans += f(a)
print(ans)

-from math import log2
+def f(k):
+    cnt = 0
+    while k % 2 == 0:
+        k //= 2
+        cnt += 1
+        # print(k)
+    return cnt
+
-a = list(map(int, input().split()))
+A = list(map(int, input().split()))
-for _a in a:
-    if _a % 2 == 0:
-        cnt = 0
-        while _a % 2 == 0:
-            _a //= 2
-            cnt += 1
-        ans += cnt
-print((int(ans)))
+for a in A:
+    if a % 2 == 0:
+        ans += f(a)
+print(ans)


Input:
M=998244353

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

a=0

c=1

for i in range(k+1):

  a+=c*m*pow(m-1,n-i-1,M)

  c=c*(n-i-1)*pow(i+1,M-2,M)%M

print((a%M))


Input:
N = int(input())

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

cnt, i = 0, 0

for j in range(10 ** 6):

    cnt += 1

    if a[i] == 2:

        print(cnt)

        #break

        quit()

    else:

        i = a[i] - 1

print((-1))

N = int(input())

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

cnt, i = 0, 0

for j in range(len(a)):

    cnt += 1

    if a[i] == 2:

        print(cnt)

        #break

        quit()

    else:

        i = a[i] - 1

print((-1))

N = int(input())
a = [int(input()) for _ in range(N)]
cnt, i = 0, 0
for j in range(10**6):
    cnt += 1
    if a[i] == 2:
        print(cnt)
        # break
        quit()
    else:
        i = a[i] - 1
print((-1))

N = int(input())
a = [int(input()) for _ in range(N)]
cnt, i = 0, 0
for j in range(len(a)):
    cnt += 1
    if a[i] == 2:
        print(cnt)
        # break
        quit()
    else:
        i = a[i] - 1
print((-1))

-for j in range(10**6):
+for j in range(len(a)):


Input:
import math

def combinations_count(n, r):

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

def combinations_with_replacement_count(n, r):

    return combinations_count(n + r - 1, r)

def main():

    s = int(input())

    ans = 0

    n = s // 3

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

        ans += combinations_with_replacement_count(i, 3*(n-i)+s % 3)

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

if __name__ == '__main__':

    main()

import math

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

def combinations_with_replacement_count(n, r):
    return combinations_count(n + r - 1, r)

def main():
    s = int(input())
    ans = 0
    n = s // 3
    for i in range(1, n + 1):
        ans += combinations_with_replacement_count(i, 3 * (n - i) + s % 3)
    print((ans % (10**9 + 7)))

if __name__ == "__main__":
    main()

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

-    return combinations_count(n + r - 1, r)

-        ans += combinations_with_replacement_count(i, 3 * (n - i) + s % 3)


Input:
from itertools import product

n = int(input())

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

count = 0

for C in product((-1, 0, 1), repeat=n):

  total = 1

  for a, c in zip(A, C):

    total *= (a + c)

  if total % 2 == 0:

    count += 1

print(count)

n = int(input())

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

count = 1

for a in A:

  count *= 2 if a % 2 == 0 else 1

print((3 ** n - count))

from itertools import product

n = int(input())
A = list(map(int, input().split()))
count = 0
for C in product((-1, 0, 1), repeat=n):
    total = 1
    for a, c in zip(A, C):
        total *= a + c
    if total % 2 == 0:
        count += 1
print(count)

n = int(input())
A = list(map(int, input().split()))
count = 1
for a in A:
    count *= 2 if a % 2 == 0 else 1
print((3**n - count))

-for C in product((-1, 0, 1), repeat=n):


Input:
n = int(input())

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

ans = [i for i in range(n)]

a1 = sorted(a)

for i in range(n):

    num = a[i]

    ans[num - 1] = str(i + 1)

print((' '.join(ans)))

n = int(input())

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

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

ans = [0 for _ in range(n)]

for i in range(n):

  ans[a[i] - 1] = str(i + 1)

print((" ".join(ans)))

n = int(input())
a = list(map(int, input().split()))
ans = [i for i in range(n)]
a1 = sorted(a)
for i in range(n):
    num = a[i]
    ans[num - 1] = str(i + 1)
print((" ".join(ans)))

n = int(input())
# n,k = map(int,input().split())
a = list(map(int, input().split()))
ans = [0 for _ in range(n)]
for i in range(n):
    ans[a[i] - 1] = str(i + 1)
print((" ".join(ans)))

+# n,k = map(int,input().split())
-ans = [i for i in range(n)]
-a1 = sorted(a)
+ans = [0 for _ in range(n)]
-    num = a[i]
-    ans[num - 1] = str(i + 1)
+    ans[a[i] - 1] = str(i + 1)


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

if a < b + c:

    print((b+c-a))

else:

    print((0))

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

print((max(0, c-(a-b))))

a, b, c = list(map(int, input().split()))
if a < b + c:
    print((b + c - a))
else:
    print((0))

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

-if a < b + c:
-    print((b + c - a))
-else:
-    print((0))
+print((max(0, c - (a - b))))


Input:
from collections import Counter

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

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

X = Counter(A)

for i in range(M):

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

    X[C] += B

Z = []

for key, value in list(X.items()):

    Z.append((key, value))

Z.sort(key=lambda x: x[0], reverse=True)

ans = 0

cnt = 0

for value, key in Z:

    if cnt + key <= N:

        ans += key * value

        cnt += key

    else:

        ans += (N - cnt) * value

        break

print(ans)

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

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

query = []

for i in range(M):

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

    query.append([b, c])

query.sort(key=lambda q: q[1], reverse=True)

i = 0

for b, c in query:

    while i < N and b > 0:

        if A[i] < c:

            A[i] = c

            b -= 1

        i += 1

print((sum(A)))

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

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

-Z.sort(key=lambda x: x[0], reverse=True)

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

+query.sort(key=lambda q: q[1], reverse=True)


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

if any(i % 2 != 0 for i in [a, b, c]):

    print((0))

    exit()

if a == b and b == c:

    print((-1))

    exit()

cnt = 0

a_list = [0]*(1001001)

b_list = [0]*(1001001)

c_list = [0]*(1001001)

a_list[0] = a

b_list[0] = b

c_list[0] = c

for i in range(1, 1001001):

    a_list[i] = (b_list[i-1] + c_list[i-1]) // 2

    b_list[i] = (c_list[i-1] + a_list[i-1]) // 2

    c_list[i] = (a_list[i-1] + b_list[i-1]) // 2

    cnt += 1

    if a_list[i] % 2 != 0 or b_list[i] % 2 != 0 or c_list[i] % 2 != 0:

        break

print(cnt)

def solve(a, b, c):

    if any(i % 2 == 1 for i in [a, b, c]):

        return 0

    if a == b == c:

        return -1

    a, b, c = (b + c) // 2, (c + a) // 2, (a + b) // 2

    return solve(a, b, c) + 1

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

print((solve(a, b, c)))

+    if any(i % 2 == 1 for i in [a, b, c]):


Input:
# 2019-11-17 20:44:23(JST)

import sys

# import collections

# import math

# from string import ascii_lowercase, ascii_uppercase, digits

# from bisect import bisect_left as bi_l, bisect_right as bi_r

# import itertools

# from functools import reduce

# import operator as op

# import re

# import heapq

# import array

# from scipy.misc import comb # (default: exact=False)

# import numpy as np

def main():

    s, t = sys.stdin.read().split()

    count = 0

    for i in range(3):

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

            count += 1

    print(count)

if __name__ == "__main__":

    main()

import sys

s, t = sys.stdin.read().split()

def main():

    cnt = 0

    for i in range(3):

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

            cnt += 1

    return cnt

if __name__ == '__main__':

    ans = main()

    print(ans)

import sys

s, t = sys.stdin.read().split()

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

if __name__ == "__main__":
    ans = main()
    print(ans)

-# from string import ascii_lowercase, ascii_uppercase, digits

-# from bisect import bisect_left as bi_l, bisect_right as bi_r

-# from scipy.misc import comb # (default: exact=False)


Input:
N = int(input())

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

X = list(sorted(X))

if N == 1:

  print((0))

  exit()

ans = float('inf')

for p in range(X[0], X[N - 1] + 1):

  sum = 0

  for x in X:

    sum += (x - p) ** 2

  ans = min(sum, ans)

print(ans)

N = int(input())

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

avg = round(sum(X) / N)

print((sum([(x - avg) ** 2 for x in X])))

N = int(input())
X = list(map(int, input().split()))
X = list(sorted(X))
if N == 1:
    print((0))
    exit()
ans = float("inf")
for p in range(X[0], X[N - 1] + 1):
    sum = 0
    for x in X:
        sum += (x - p) ** 2
    ans = min(sum, ans)
print(ans)

+print((sum([(x - avg) ** 2 for x in X])))


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

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

d = [0] * n

d_max = 0

for i in range(n - 1):

    d[i] = a[i + 1] - a[i]

    d_max = max(d_max, d[i])

d[-1] = (k - a[-1]) + a[0]

d_max = max(d_max, d[-1])

print((k - d_max))

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

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

d_max = 0

for i in range(n - 1):

    d = a[i + 1] - a[i]

    d_max = max(d_max, d)

d = (k - a[-1]) + a[0]

d_max = max(d_max, d)

print((k - d_max))


Input:
from math import factorial

def myAnswer(N:int) ->int:

   ans =factorial(N)

   return ans % (10**9 + 7)

def modelAnswer():

   tmp=1

def main():

   N = int(input())

   print((myAnswer(N)))

if __name__ == '__main__':

   main()

def modelAnswer(N:int) -> int:

   ans = 1

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

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

   return ans

def main():

   N = int(input())

   print((modelAnswer(N)))

if __name__ == '__main__':

   main()

from math import factorial

def myAnswer(N: int) -> int:
    ans = factorial(N)
    return ans % (10**9 + 7)

def modelAnswer():
    tmp = 1

def main():
    N = int(input())
    print((myAnswer(N)))

if __name__ == "__main__":
    main()

def modelAnswer(N: int) -> int:
    ans = 1
    for i in range(1, N + 1):
        ans = (ans * i) % (10**9 + 7)
    return ans

def main():
    N = int(input())
    print((modelAnswer(N)))

if __name__ == "__main__":
    main()

-from math import factorial
-def myAnswer(N: int) -> int:
-    ans = factorial(N)
-    return ans % (10**9 + 7)
-def modelAnswer():
-    tmp = 1
+def modelAnswer(N: int) -> int:
+    ans = 1
+    for i in range(1, N + 1):
+        ans = (ans * i) % (10**9 + 7)
+    return ans
-    print((myAnswer(N)))
+    print((modelAnswer(N)))


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

while True:

    if len(s) == 0:

        break

    if s[:7] == "remaerd":

        s = s[7:]

    elif s[:6] == "resare":

        s = s[6:]

    elif s[:5] == "maerd" or s[:5] == "esare":

        s = s[5:]

    else:

        print("NO")

        exit()

print("YES")

import re

s = input()

if re.fullmatch(r"(dream|dreamer|erase|eraser)+", s):

    print("YES")

else:

    print("NO")

-    elif s[:5] == "maerd" or s[:5] == "esare":


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

count_target = 0

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

    str_i = str(i)

    reversed_i = ''

    for n_th_i in reversed(list(range(len(str_i)))):

        reversed_i += str_i[n_th_i]

    if str_i == reversed_i:

        count_target += 1

print(count_target)

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

count_target = 0

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

    str_i = str(i)

    reversed_i = str_i[::-1]

    if str_i == reversed_i:

        count_target += 1

print(count_target)

A, B = list(map(int, input().split()))
count_target = 0
for i in range(A, B + 1):
    str_i = str(i)
    reversed_i = ""
    for n_th_i in reversed(list(range(len(str_i)))):
        reversed_i += str_i[n_th_i]
    if str_i == reversed_i:
        count_target += 1
print(count_target)

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

-    for n_th_i in reversed(list(range(len(str_i)))):


Input:
a = int(input())

h = int(a / 3600)

m = int((a - h * 3600) / 60)

s = int(a - h * 3600 - m * 60)

print((":" .join(map(str, [h, m, s]))))


Input:
n = int(input())

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

ans = list(range(n))

for i in range(n):

    ans[a[i]-1] = i+1

print((' '.join(map(str,ans))))

def main():

    N = int(input())

    A = list(int(x) for x in input().split())

    ans = [0] * N

    for i, a in enumerate(A):

        ans[a-1] = i+1

    print((' '.join(map(str, ans))))

if __name__ == '__main__':

    main()

n = int(input())
a = [int(x) for x in input().split()]
ans = list(range(n))
for i in range(n):
    ans[a[i] - 1] = i + 1
print((" ".join(map(str, ans))))

def main():
    N = int(input())
    A = list(int(x) for x in input().split())
    ans = [0] * N
    for i, a in enumerate(A):
        ans[a - 1] = i + 1
    print((" ".join(map(str, ans))))

if __name__ == "__main__":
    main()

+    A = list(int(x) for x in input().split())


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

cnt = 0

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

    s = str(x)

    l = len(s)

    flg = True

    for i in range(l // 2):

        if s[i] != s[l - 1 - i]:

            flg = False

            break

    if flg:

        cnt += 1

print(cnt)

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

cnt = 0

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

    s = str(i)

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

        cnt += 1

print(cnt)

-for x in range(a, b + 1):
-    s = str(x)
-    l = len(s)
-    flg = True
-    for i in range(l // 2):
-        if s[i] != s[l - 1 - i]:
-            flg = False
-            break
-    if flg:
+for i in range(a, b + 1):
+    s = str(i)
+    if s[0] == s[4] and s[1] == s[3]:


Input:
N = int(input())

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

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

a.reverse()

b.reverse()

ans = 0

capacity = 0

for i in range(N):

    ans += min(b[i] + capacity, a[i])

    capacity = max(b[i] - max(a[i] - capacity, 0), 0)

ans += min(a[-1], capacity)

print(ans)

n = int(input())

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

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

a = a[::-1]

b = b[::-1]

ans = 0

for i, bi in enumerate(b):

    ans += min(a[i], b[i])

    remain = max(0, b[i] - a[i])

    ans += min(a[i + 1], remain)

    a[i + 1] = max(0, a[i + 1] - remain)

print(ans)

-    capacity = max(b[i] - max(a[i] - capacity, 0), 0)


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

S = list(input() for i in range(N))

str = ""

for i in range(N-1):

    for j in range(N-1):

        if S[j+1] + S[j] <= S[j] + S[j+1]:

            S[j], S[j+1] = S[j+1], S[j]

for i in S:

    str += i

print(str)

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

S = list(input() for i in range(N))

S.sort()

str = ""

for i in S:

    str += i

print(str)

N, L = list(map(int, input().split()))
S = list(input() for i in range(N))
str = ""
for i in range(N - 1):
    for j in range(N - 1):
        if S[j + 1] + S[j] <= S[j] + S[j + 1]:
            S[j], S[j + 1] = S[j + 1], S[j]
for i in S:
    str += i
print(str)


Input:
while True:

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

	if k[0]==k[1]==0:

		break

	ct=0

	a=0

	b=0

	c=0

	max=k[0]

	sum=k[1]

	a=max+1

	while True:

		a-=1

		b=a-1

		c=sum-a-b

		if not a>b>c:

			print(ct)

			break

		while a>b>c:

			if a>b>c>0:

				ct+=1

			b-=1

			c+=1

while True:

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

	if k[0]==k[1]==0:

		break

	ct=0

	a=0

	b=0

	c=0

	max=k[0]

	sum=k[1]

	a=max+1

	while True:

		a-=1

		b=a-1

		c=sum-a-b

		if not a>c:

			print(ct)

			break

		while b>c:

			if c>0:

				ct+=1

			b-=1

			c+=1

while True:
    k = list(map(int, input().split(" ")))
    if k[0] == k[1] == 0:
        break
    ct = 0
    a = 0
    b = 0
    c = 0
    max = k[0]
    sum = k[1]
    a = max + 1
    while True:
        a -= 1
        b = a - 1
        c = sum - a - b
        if not a > b > c:
            print(ct)
            break
        while a > b > c:
            if a > b > c > 0:
                ct += 1
            b -= 1
            c += 1

while True:
    k = list(map(int, input().split(" ")))
    if k[0] == k[1] == 0:
        break
    ct = 0
    a = 0
    b = 0
    c = 0
    max = k[0]
    sum = k[1]
    a = max + 1
    while True:
        a -= 1
        b = a - 1
        c = sum - a - b
        if not a > c:
            print(ct)
            break
        while b > c:
            if c > 0:
                ct += 1
            b -= 1
            c += 1

-        if not a > b > c:
+        if not a > c:
-        while a > b > c:
-            if a > b > c > 0:
+        while b > c:
+            if c > 0:


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

S = [input() for i in range(n)]

S.sort()

print(("".join(S)))

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

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

A.sort()

print(("".join(A)))


Input:
N = int(input())

if N < 2:

  print(N)

elif 2<=N<4:

  print((2))

elif 4<=N<8:

  print((4))

elif 8<=N<16:

  print((8))

elif 16<=N<32:

  print((16))

elif 32<=N<64:

  print((32))

elif 64<=N:

  print((64))

N = int(input())

Num = [int(2**i) for i in range(7)]

if N in Num:

  print(N)

else:

  Num.append(N)

  Num = sorted(Num)

  print((2 ** (Num.index(N) - 1)))

-if N < 2:
+Num = [int(2**i) for i in range(7)]
+if N in Num:
-elif 2 <= N < 4:
-    print((2))
-elif 4 <= N < 8:
-    print((4))
-elif 8 <= N < 16:
-    print((8))
-elif 16 <= N < 32:
-    print((16))
-elif 32 <= N < 64:
-    print((32))
-elif 64 <= N:
-    print((64))
+else:
+    Num.append(N)
+    Num = sorted(Num)
+    print((2 ** (Num.index(N) - 1)))


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

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

left = 1

right = N

for l, r in LR:

    if left < l:

        left = l

    if right > r:

        right = r

ans = right - left

print((ans + 1 if ans >= 0 else 0))

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

left = 1

right = N

for _ in range(M):

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

    if left < l:

        left = l

    if right > r:

        right = r

ans = right - left

print((ans + 1 if ans >= 0 else 0))

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

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


Input:
s = input()

t = input()

for i in range(len(s)):

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

                print('Yes')

                exit()

print('No')

s = input()

t = input()

for i in range(len(s)):

    s = s[1:] + s[0]

    if s == t:

        print("Yes")

        exit()

print("No")

s = input()
t = input()
for i in range(len(s)):
    if s[i:] + s[:i] == t:
        print("Yes")
        exit()
print("No")


Input:
n = int(input())

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

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

result = 0

for i in range(n):

  if v[i] > c[i]:

    result += v[i] - c[i]

print(result)

N = int(input())

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

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

print((sum([V[i] - C[i] for i in range(N) if V[i] > C[i]])))

+print((sum([V[i] - C[i] for i in range(N) if V[i] > C[i]])))


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

answer = 0

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

    j = str(i)

    p1 = j[4]

    p2 = j[3]

    p3 = j[2]

    p4 = j[1]

    p5 = j[0]

    k = int(p1+p2+p3+p4+p5)

    if i == k :

        answer += 1

print(answer)

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

ans = 0

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

    l = str(i)

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

        ans += 1

print(ans)

a, b = list(map(int, input().split()))
answer = 0
for i in range(a, b + 1):
    j = str(i)
    p1 = j[4]
    p2 = j[3]
    p3 = j[2]
    p4 = j[1]
    p5 = j[0]
    k = int(p1 + p2 + p3 + p4 + p5)
    if i == k:
        answer += 1
print(answer)

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

-a, b = list(map(int, input().split()))
-answer = 0
-for i in range(a, b + 1):
-    j = str(i)
-    p1 = j[4]
-    p2 = j[3]
-    p3 = j[2]
-    p4 = j[1]
-    p5 = j[0]
-    k = int(p1 + p2 + p3 + p4 + p5)
-    if i == k:
-        answer += 1
-print(answer)
+A, B = list(map(int, input().split()))
+ans = 0
+for i in range(A, B + 1):
+    l = str(i)
+    if l[0] == l[4] and l[1] == l[3]:
+        ans += 1
+print(ans)


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

dic={}

for i in range(N):

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

  if a in dic:

    dic[a]+=b

  else:

    dic[a]=b

dic=sorted(list(dic.items()),key=lambda x:x[0])

for d in range(len(dic)):

  amount=dic[d][1]

  if amount>=K:

    print((dic[d][0]))

    exit(0)

  else:

    K-=amount

import sys

readline = sys.stdin.readline

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

AB = [list(map(int,readline().split())) for i in range(N)]

AB = sorted(AB, key = lambda x:x[0])

amount = 0

for a,b in AB:

  amount += b

  if amount >= K:

    print(a)

    break

N, K = list(map(int, input().split()))
dic = {}
for i in range(N):
    a, b = list(map(int, input().split()))
    if a in dic:
        dic[a] += b
    else:
        dic[a] = b
dic = sorted(list(dic.items()), key=lambda x: x[0])
for d in range(len(dic)):
    amount = dic[d][1]
    if amount >= K:
        print((dic[d][0]))
        exit(0)
    else:
        K -= amount

import sys

readline = sys.stdin.readline
N, K = list(map(int, readline().split()))
AB = [list(map(int, readline().split())) for i in range(N)]
AB = sorted(AB, key=lambda x: x[0])
amount = 0
for a, b in AB:
    amount += b
    if amount >= K:
        print(a)
        break

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

-dic = sorted(list(dic.items()), key=lambda x: x[0])

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

+AB = [list(map(int, readline().split())) for i in range(N)]


Input:
from itertools import accumulate

from bisect import *

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

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

acc = sorted(list(accumulate(L)) + [0])

n = bisect_right(acc,X)

print(n)

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

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

List = [0]*(N+1)

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

    List[i] = List[i-1] + L[i-1]

A = [i for i in List if i <=X]

print((len(A)))

from itertools import accumulate
from bisect import *

N, X = list(map(int, input().split()))
L = list(tuple(map(int, input().split())))
acc = sorted(list(accumulate(L)) + [0])
n = bisect_right(acc, X)
print(n)

N, X = list(map(int, input().split()))
L = list(map(int, input().split()))
List = [0] * (N + 1)
for i in range(1, N + 1):
    List[i] = List[i - 1] + L[i - 1]
A = [i for i in List if i <= X]
print((len(A)))

-L = list(tuple(map(int, input().split())))

-acc = sorted(list(accumulate(L)) + [0])


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

cnt = 0

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

    n_s = str(n)

    n_s_rvs = n_s[::-1]

    if n_s == n_s_rvs:

        cnt += 1

print(cnt)

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


Input:
import math

N=int(input())

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

N=int(input())

power=1

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

    power*=i

    power%=10**9+7

print(power)

import math

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

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

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


Input:
# ABC95 C -Half and Half

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

ans = 0

if a+b > 2*c:

    while x != 0.0 and y != 0.0:

        ans += 2*c

        x -= 1.0

        y -= 1.0

        if y == 0.0:

            while x != 0.0:

                if a > 2*c:

                    ans += 2*c

                    x -= 1.0

                else:

                    ans += a

                    x -= 1.0

        if x == 0.0:

            while y != 0.0:

                if b > 2*c:

                    ans += 2*c

                    y -= 1.0

                else:

                    ans += b

                    y -= 1.0

else:

    ans += a*x + b*y

print((int(ans)))

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

ans=0

ans1=0

e=max(x,y)

ans1=e*(2*c)

if 2*c<a+b:

    d=min(x,y)

    ans+=c*(2*d)

    x-=d

    y-=d

else:

    ans=a*x+b*y

    x-=x

    y-=y

ans+=x*a

ans+=y*b

print((min(ans,ans1)))

# ABC95 C -Half and Half
a, b, c, x, y = list(map(float, input().split()))
ans = 0
if a + b > 2 * c:
    while x != 0.0 and y != 0.0:
        ans += 2 * c
        x -= 1.0
        y -= 1.0
        if y == 0.0:
            while x != 0.0:
                if a > 2 * c:
                    ans += 2 * c
                    x -= 1.0
                else:
                    ans += a
                    x -= 1.0
        if x == 0.0:
            while y != 0.0:
                if b > 2 * c:
                    ans += 2 * c
                    y -= 1.0
                else:
                    ans += b
                    y -= 1.0
else:
    ans += a * x + b * y
print((int(ans)))

a, b, c, x, y = list(map(int, input().split()))
ans = 0
ans1 = 0
e = max(x, y)
ans1 = e * (2 * c)
if 2 * c < a + b:
    d = min(x, y)
    ans += c * (2 * d)
    x -= d
    y -= d
else:
    ans = a * x + b * y
    x -= x
    y -= y
ans += x * a
ans += y * b
print((min(ans, ans1)))

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

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


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

cnt = 0

for _ in range(N):

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

    if x ** 2 + y ** 2 <= D ** 2:

        cnt += 1

print(cnt)

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

cnt = 0

for _ in range(N):

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

    if x * x + y * y <= D * D:

        cnt += 1

print(cnt)

N, D = list(map(int, input().split()))
cnt = 0
for _ in range(N):
    x, y = list(map(int, input().split()))
    if x**2 + y**2 <= D**2:
        cnt += 1
print(cnt)


Input:
S = int(input())

a = 0

count = 0

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

while count == 0:

    a += S

    if n <= a and m >= a:

        count = 1

    if a >= 1000:

        break

if count == 0:

    print("NG")

else:

    print("OK")

k = int(input())

n = 0

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

while True:

    n += k

    if n >= a and n <= b:

        print("OK")

        break

    if n > b:

        print("NG")

        break

S = int(input())
a = 0
count = 0
n, m = list(map(int, input().split()))
while count == 0:
    a += S
    if n <= a and m >= a:
        count = 1
    if a >= 1000:
        break
if count == 0:
    print("NG")
else:
    print("OK")

k = int(input())
n = 0
a, b = list(map(int, input().split()))
while True:
    n += k
    if n >= a and n <= b:
        print("OK")
        break
    if n > b:
        print("NG")
        break

-S = int(input())
-a = 0
-count = 0
-n, m = list(map(int, input().split()))
-while count == 0:
-    a += S
-    if n <= a and m >= a:
-        count = 1
-    if a >= 1000:
+k = int(input())
+n = 0
+a, b = list(map(int, input().split()))
+while True:
+    n += k
+    if n >= a and n <= b:
+        print("OK")
-if count == 0:
-    print("NG")
-else:
-    print("OK")
+    if n > b:
+        print("NG")
+        break


Input:
from math import factorial as fc

a = int(input())

print((fc(a)%(10**9+7)))

n = int(input())

m = 10**9+7

ans = 1

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

  ans *= i

  ans %= m

print(ans)

from math import factorial as fc

a = int(input())
print((fc(a) % (10**9 + 7)))

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

-from math import factorial as fc
-a = int(input())
-print((fc(a) % (10**9 + 7)))
+n = int(input())
+m = 10**9 + 7
+ans = 1
+for i in range(1, n + 1):
+    ans *= i
+    ans %= m
+print(ans)


Input:
for i in range(0, int(input())):

    sidelen = [int(j) for j in input().split(" ")]

    sidelen.sort(reverse=True)

    if(sidelen[0]**2 == sidelen[1]**2 + sidelen[2]**2):

        print("YES")

    else:

        print("NO")

import sys

for i in sys.stdin:

    try:

        sidelen = [int(j) for j in i.split(" ")]

        sidelen.sort(reverse=True)

        if(sidelen[0]**2 == sidelen[1]**2 + sidelen[2]**2):

            print("YES")

        else:

            print("NO")

    except:

        continue

for i in range(0, int(input())):
    sidelen = [int(j) for j in input().split(" ")]
    sidelen.sort(reverse=True)
    if sidelen[0] ** 2 == sidelen[1] ** 2 + sidelen[2] ** 2:
        print("YES")
    else:
        print("NO")

import sys

for i in sys.stdin:
    try:
        sidelen = [int(j) for j in i.split(" ")]
        sidelen.sort(reverse=True)
        if sidelen[0] ** 2 == sidelen[1] ** 2 + sidelen[2] ** 2:
            print("YES")
        else:
            print("NO")
    except:
        continue

-    sidelen = [int(j) for j in input().split(" ")]

-    if sidelen[0] ** 2 == sidelen[1] ** 2 + sidelen[2] ** 2:

+        sidelen = [int(j) for j in i.split(" ")]

+        if sidelen[0] ** 2 == sidelen[1] ** 2 + sidelen[2] ** 2:


Input:
n = int(input())

s = input().split()

s = set(s)

print(('Four' if len(s) == 4 else 'Three'))

n = int(input())

s = input().split()

print(('Four' if len(set(s)) == 4 else 'Three'))

n = int(input())
s = input().split()
s = set(s)
print(("Four" if len(s) == 4 else "Three"))

n = int(input())
s = input().split()
print(("Four" if len(set(s)) == 4 else "Three"))

-print(("Four" if len(s) == 4 else "Three"))

+print(("Four" if len(set(s)) == 4 else "Three"))


Input:
import sys

if __name__ == '__main__':

    import doctest

    doctest.testmod()

    S = int(sys.stdin.read())

    h = S / 3600

    m = (S % 3600) / 60

    s = S % 60

    print("%d:%d:%d" % (h, m, s))

#!/usr/bin/env python

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

# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_D

if __name__ == '__main__':

    S = int(input())

    h = S / 3600

    m = (S % 3600) / 60

    s = S % 60

    print("%d:%d:%d" % (h, m, s))

import sys

if __name__ == "__main__":
    import doctest

    doctest.testmod()
    S = int(sys.stdin.read())
    h = S / 3600
    m = (S % 3600) / 60
    s = S % 60
    print("%d:%d:%d" % (h, m, s))

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_D
if __name__ == "__main__":
    S = int(input())
    h = S / 3600
    m = (S % 3600) / 60
    s = S % 60
    print("%d:%d:%d" % (h, m, s))


Input:
n = int(input())

s = []

for i in range(1, 10):

  for j in range(1, 10):

    s.append(i*j)

if n in s:

  print("Yes")

else:

  print("No")

import sys

n = int(input())

for i in range(1, 10):

  for j in range(1, 10):

    if i*j == n:

      print("Yes")

      sys.exit()

print("No")

n = int(input())
s = []
for i in range(1, 10):
    for j in range(1, 10):
        s.append(i * j)
if n in s:
    print("Yes")
else:
    print("No")

import sys

n = int(input())
for i in range(1, 10):
    for j in range(1, 10):
        if i * j == n:
            print("Yes")
            sys.exit()
print("No")

+import sys
+
-s = []
-        s.append(i * j)
-if n in s:
-    print("Yes")
-else:
-    print("No")
+        if i * j == n:
+            print("Yes")
+            sys.exit()
+print("No")


Input:
import math

N=int(input())

ans=math.factorial(N)

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

mod=10**9+7

N=int(input())

ans=1

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

  ans*=i

  ans%=mod

print(ans)

import math

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

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

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


Input:
S = input()

T = input()

N = len(S)

cnt = 0

for i in range(N):

    cnt += (S[i] != T[i])

print(cnt)

S = input()

T = input()

cnt = 0

for i in range(len(S)):

    cnt += (S[i] != T[i])

print(cnt)

S = input()
T = input()
N = len(S)
cnt = 0
for i in range(N):
    cnt += S[i] != T[i]
print(cnt)

S = input()
T = input()
cnt = 0
for i in range(len(S)):
    cnt += S[i] != T[i]
print(cnt)

-N = len(S)
-for i in range(N):
+for i in range(len(S)):


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

a=list(range(1,N+1))

for i in range(K):

  count=int(input())

  b=input().split(' ')

  for j in range(count):

    if int(b[j]) in a:

      a.remove(int(b[j]))

print((len(a)))

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

a=list(range(1,N+1))

for i in range(K):

  count=int(input())

  b=[int(x.strip()) for x in input().split(' ')]

  for j in range(count):

    if b[j] in a:

      a.remove(b[j])

print((len(a)))

N, K = list(map(int, input().split(" ")))
a = list(range(1, N + 1))
for i in range(K):
    count = int(input())
    b = input().split(" ")
    for j in range(count):
        if int(b[j]) in a:
            a.remove(int(b[j]))
print((len(a)))

N, K = list(map(int, input().split(" ")))
a = list(range(1, N + 1))
for i in range(K):
    count = int(input())
    b = [int(x.strip()) for x in input().split(" ")]
    for j in range(count):
        if b[j] in a:
            a.remove(b[j])
print((len(a)))

+    b = [int(x.strip()) for x in input().split(" ")]


Input:
res = []

while True:

    s = input()

    if s == '0':

        break

    res.append(sum([int(x) for x in s]))

for e in res:

    print(e)

def sum_of_numbers(n):

    '''

    (* int -> int *)

    '''

    res = [int(n) for n in list(str(n))]

    return sum(res)

if __name__ == "__main__":

    while True:

        n = input()

        if n == '0':

            break

        print((sum_of_numbers(n)))

res = []
while True:
    s = input()
    if s == "0":
        break
    res.append(sum([int(x) for x in s]))
for e in res:
    print(e)

def sum_of_numbers(n):
    """
    (* int -> int *)
    """
    res = [int(n) for n in list(str(n))]
    return sum(res)

if __name__ == "__main__":
    while True:
        n = input()
        if n == "0":
            break
        print((sum_of_numbers(n)))

-    res.append(sum([int(x) for x in s]))

+    res = [int(n) for n in list(str(n))]


Input: import re;print((max(list(map(len,re.split('[^ACGT]',input()))))))

p=m=0

for c in input():p=-~p*(c in'ATGC');m=max(m,p)

print(m)

import re

print((max(list(map(len, re.split("[^ACGT]", input()))))))

p = m = 0
for c in input():
    p = -~p * (c in "ATGC")
    m = max(m, p)
print(m)


Input:
N = int(input())

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

ans = 0

check = [0]*30

for i in range(1, 31):

    check[i-1] = 2**i

for i in A:

    if i % 2 == 0:

        j = 0

        while check[j] <= i:

            if i % check[j] == 0:

                add = check[j]

            else:

                break

            j += 1

        ans += j

print(ans)

N = int(input())

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

ans = 0

for i in a:

    while i % 2 == 0:

        i //= 2

        ans += 1

print(ans)

N = int(input())
A = [int(i) for i in input().split()]
ans = 0
check = [0] * 30
for i in range(1, 31):
    check[i - 1] = 2**i
for i in A:
    if i % 2 == 0:
        j = 0
        while check[j] <= i:
            if i % check[j] == 0:
                add = check[j]
            else:
                break
            j += 1
        ans += j
print(ans)

-A = [int(i) for i in input().split()]
+a = [int(i) for i in input().split()]
-check = [0] * 30
-for i in range(1, 31):
-    check[i - 1] = 2**i
-for i in A:
-    if i % 2 == 0:
-        j = 0
-        while check[j] <= i:
-            if i % check[j] == 0:
-                add = check[j]
-            else:
-                break
-            j += 1
-        ans += j
+for i in a:
+    while i % 2 == 0:
+        i //= 2
+        ans += 1


Input:
N = int(input())

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

M = int(input())

p = []

x = []

ans = []

for i in range(M):

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

    ans.append(sum(T[:p-1])+x+sum(T[p:]))

for _ in ans:

    print(_)

N = int(input())

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

M = int(input())

P, X, ans = [0]*M, [0]*M, []

base = sum(T)

for i in range(M):

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

    ans.append(base-T[P-1]+X)

for i in ans:

    print(i)

N = int(input())
T = list(map(int, input().split()))
M = int(input())
p = []
x = []
ans = []
for i in range(M):
    p, x = list(map(int, input().split()))
    ans.append(sum(T[: p - 1]) + x + sum(T[p:]))
for _ in ans:
    print(_)

N = int(input())
T = list(map(int, input().split()))
M = int(input())
P, X, ans = [0] * M, [0] * M, []
base = sum(T)
for i in range(M):
    P, X = list(map(int, input().split()))
    ans.append(base - T[P - 1] + X)
for i in ans:
    print(i)

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

-    ans.append(sum(T[: p - 1]) + x + sum(T[p:]))

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


Input:
import math

N = int(input())

print((math.factorial(N)%(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

N = int(input())
print((math.factorial(N) % (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(N) % (10**9 + 7)))


Input:
def main():

    import math

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

    a=[]

    for i in range(M):

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

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

        c=0

        for j in range(len(tmpc)):

            c+=2**(tmpc[j]-1)

        tmp[1]=c

        a+=[tmp]

    dp=[[10**10 for j in range(2**N)] for i in range(M)]

    dp[0][0]=0

    dp[0][a[0][1]]=a[0][0]

    for i in range(1,M):

        dp[i]=dp[i-1]

        for j in range(2**N):

            z,p=a[i][0],a[i][1]

            q=j|p

            x=dp[i-1][j]+z

            if dp[i][q]>x: dp[i][q]=x

    ans=dp[M-1][2**N-1]

    print((ans if ans<10**10 else -1))

if __name__ == '__main__':

    main()

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

L=2**n

cost=[0]+[10**8 for i in range(L-1)]

for i in range(m):

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

    c=sum([2**(int(i)-1) for i in input().split()])

    for j in range(L):

        q=j|c

        x=cost[j]+a

        if cost[q]>x:

            cost[q]=x

print((cost[L-1] if cost[L-1]<10**8 else -1))

def main():
    import math

    N, M = list(map(int, input().split()))
    a = []
    for i in range(M):
        tmp = list(map(int, input().split()))
        tmpc = list(map(int, input().split()))
        c = 0
        for j in range(len(tmpc)):
            c += 2 ** (tmpc[j] - 1)
        tmp[1] = c
        a += [tmp]
    dp = [[10**10 for j in range(2**N)] for i in range(M)]
    dp[0][0] = 0
    dp[0][a[0][1]] = a[0][0]
    for i in range(1, M):
        dp[i] = dp[i - 1]
        for j in range(2**N):
            z, p = a[i][0], a[i][1]
            q = j | p
            x = dp[i - 1][j] + z
            if dp[i][q] > x:
                dp[i][q] = x
    ans = dp[M - 1][2**N - 1]
    print((ans if ans < 10**10 else -1))

if __name__ == "__main__":
    main()

n, m = list(map(int, input().split()))
L = 2**n
cost = [0] + [10**8 for i in range(L - 1)]
for i in range(m):
    a, b = list(map(int, input().split()))
    c = sum([2 ** (int(i) - 1) for i in input().split()])
    for j in range(L):
        q = j | c
        x = cost[j] + a
        if cost[q] > x:
            cost[q] = x
print((cost[L - 1] if cost[L - 1] < 10**8 else -1))

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

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

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

-    dp = [[10**10 for j in range(2**N)] for i in range(M)]

-    print((ans if ans < 10**10 else -1))

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

+    c = sum([2 ** (int(i) - 1) for i in input().split()])

+print((cost[L - 1] if cost[L - 1] < 10**8 else -1))


Input:
alph = input()

if alph.isupper():

    print("A")

else:

    print("a")

a = input()

if a.isupper():

    print("A")

else:

    print("a")

-alph = input()
-if alph.isupper():
+a = input()
+if a.isupper():


Input: a,b,c,x,y=list(map(int,input().split()));print((min(k*c*2+a*max(x-k,0)+b*max(y-k,0)for k in range(max(x,y)*3))))

a, b, c, x, y = list(map(int, input().split()))
print(
    (
        min(
            k * c * 2 + a * max(x - k, 0) + b * max(y - k, 0)
            for k in range(max(x, y) * 3)
        )
    )
)

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

-            for k in range(max(x, y) * 3)


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

d=0

while d<10**5:

    if a%2==1 or b%2==1 or c%2==1:break

    a,b,c=b/2+c/2,a/2+c/2,a/2+b/2

    d+=1

else:d=-1

print(d)


Input:
import statistics

N = int(input())

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

ans = 0

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

  a[i-1] -= i

b = statistics.median(a)

for i in range(N):

  ans += abs(a[i]-b)

print((int(ans)))

N = int(input())

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

C = [A[i]-i for i in range(N)]

C.sort()

ans = 0

med = C[N//2]

for i in range(N):

  ans += abs(C[i]-med)

print(ans)

import statistics

N = int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in range(1, N + 1):
    a[i - 1] -= i
b = statistics.median(a)
for i in range(N):
    ans += abs(a[i] - b)
print((int(ans)))

N = int(input())
A = [int(i) for i in input().split()]
C = [A[i] - i for i in range(N)]
C.sort()
ans = 0
med = C[N // 2]
for i in range(N):
    ans += abs(C[i] - med)
print(ans)

-import statistics
-a = [int(i) for i in input().split()]
+A = [int(i) for i in input().split()]
+C = [A[i] - i for i in range(N)]
+C.sort()
-for i in range(1, N + 1):
-    a[i - 1] -= i
-b = statistics.median(a)
+med = C[N // 2]
-    ans += abs(a[i] - b)
-print((int(ans)))
+    ans += abs(C[i] - med)
+print(ans)


Input:
N = int(input())

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

dp = [0] * 10 ** 7

ans = 0

for i in range(N):

    x = i + 1 - A[i]

    if x >= 0:

        ans += dp[x]

    y = i + 1 + A[i]

    if y < 10 ** 7:

        dp[y] += 1

print(ans)

N = int(input())

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

INF = 2 * 10 ** 5

dp = [0] * INF

ans = 0

for i in range(N):

    i_i_ = i + 1 - A[i]

    if 0 < i_i_ < INF:

        ans += dp[i_i_]

    i_ = i + 1 + A[i]

    if 0 < i_ < INF:

        dp[i_] += 1

print(ans)

N = int(input())
A = [int(i) for i in input().split()]
dp = [0] * 10**7
ans = 0
for i in range(N):
    x = i + 1 - A[i]
    if x >= 0:
        ans += dp[x]
    y = i + 1 + A[i]
    if y < 10**7:
        dp[y] += 1
print(ans)

N = int(input())
A = [int(i) for i in input().split()]
INF = 2 * 10**5
dp = [0] * INF
ans = 0
for i in range(N):
    i_i_ = i + 1 - A[i]
    if 0 < i_i_ < INF:
        ans += dp[i_i_]
    i_ = i + 1 + A[i]
    if 0 < i_ < INF:
        dp[i_] += 1
print(ans)


Input:
S = int(input())

mod = 10**9+7

dp = [0]*(S+1)

dp[0] = 1

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

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

        dp[i] += dp[j]

        dp[i] %= mod

print((dp[S]))

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


Input:
# ABC 120 C

import re

S = input()

l0 = 0

l1 = 0

for i in range(len(S)):

    if S[i] == '0':

        l0 += 1

    elif S[i] == '1':

        l1 += 1

print((min(l0, l1) * 2))

def resolve():

  S = input()

  arr = []

  for s in S:

    if len(arr) != 0 and arr[-1] != s:

      arr.pop()

    else:

      arr.append(s)

  print((len(S) - len(arr)))

  return

if __name__ == "__main__":

  resolve()

# ABC 120 C
import re

S = input()
l0 = 0
l1 = 0
for i in range(len(S)):
    if S[i] == "0":
        l0 += 1
    elif S[i] == "1":
        l1 += 1
print((min(l0, l1) * 2))

+        if len(arr) != 0 and arr[-1] != s:


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

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

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

def solve():

    a, b = mput()

    print((a*b))

    return 0

if __name__ == "__main__":

    solve()

import math

def solve():

    a, b = input().split()

    a = int(a)

    b = float(b)

    print((int(a*b)))

    return 0

if __name__ == "__main__":

    solve()

def iput():
    return int(input())

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

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

def solve():
    a, b = mput()
    print((a * b))
    return 0

if __name__ == "__main__":
    solve()

import math

def solve():
    a, b = input().split()
    a = int(a)
    b = float(b)
    print((int(a * b)))
    return 0

if __name__ == "__main__":
    solve()

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


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

if (b - a) == (c - b):

    print("YES")

else:

    print("NO")

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

if b - a == c - b:

    print("YES")

else:

    print("NO")


Input:
import math

print((math.factorial(int(input()))%1000000007))

num = int(input())

result = 1

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

    result = result *i % 1000000007

print(result)

import math

print((math.factorial(int(input())) % 1000000007))

num = int(input())
result = 1
for i in range(1, num + 1):
    result = result * i % 1000000007
print(result)


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

count = 0

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

    j = str(i)

    if j==''.join(reversed(j)):

        count += 1

print(count)

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

n = [i for i in map(str, list(range(a,b+1))) if i==i[::-1]]

print((len(n)))

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

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

+n = [i for i in map(str, list(range(a, b + 1))) if i == i[::-1]]


Input:
#!/usr/bin/env pypy3

import math

print((math.factorial(int(input())) % 1000000007))

n = int(input())

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

	n *= i

	n %= 10**9 + 7

print(n)


Input:
(N, K), *AB = [list(map(int, s.split())) for s in open(0)]

for a, b in sorted(AB):

    K -= b

    if K <= 0:

        print(a)

        break

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

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

li.sort()

for a, b in li:

    if K > b:

        K -= b

    else:

        print(a)

        break

-(N, K), *AB = [list(map(int, s.split())) for s in open(0)]

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

+li = [(a, b) for a, b in zip(*[iter(AB)] * 2)]


Input:
mod = int(1e9+7)

n = int(input())

power = 1

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

    power = power * i % mod

print(power)

import sys

MOD = 10 ** 9 + 7

n = int(sys.stdin.readline().rstrip())

def main():

    res = 1

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

        res *= i

        res %= MOD

    return res

if __name__ == '__main__':

    ans = main()

    print(ans)

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

import sys

MOD = 10**9 + 7
n = int(sys.stdin.readline().rstrip())

def main():
    res = 1
    for i in range(1, n + 1):
        res *= i
        res %= MOD
    return res

if __name__ == "__main__":
    ans = main()
    print(ans)

-mod = int(1e9 + 7)
-n = int(input())
-power = 1
-for i in range(1, n + 1):
-    power = power * i % mod
-print(power)
+import sys
+
+MOD = 10**9 + 7
+n = int(sys.stdin.readline().rstrip())
+
+
+def main():
+    res = 1
+    for i in range(1, n + 1):
+        res *= i
+        res %= MOD
+    return res
+
+
+if __name__ == "__main__":
+    ans = main()
+    print(ans)


Input:
s = input()

start = -1

end = 0

for i in range(len(s)):

    if s[i] == 'A' and start < 0:

        start = i

    elif s[i] == 'Z':

        end = i

print((end - start + 1))

s = input()

start = 0

for i in range(len(s)):

    if s[i] == 'A':

        start = i

        break

end = 0

for i in reversed(list(range(len(s)))):

    if s[i] == 'Z':

        end = i

        break

print((end - start + 1))

s = input()
start = -1
end = 0
for i in range(len(s)):
    if s[i] == "A" and start < 0:
        start = i
    elif s[i] == "Z":
        end = i
print((end - start + 1))

s = input()
start = 0
for i in range(len(s)):
    if s[i] == "A":
        start = i
        break
end = 0
for i in reversed(list(range(len(s)))):
    if s[i] == "Z":
        end = i
        break
print((end - start + 1))

+for i in reversed(list(range(len(s)))):


Input:
while 1:

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

 if n+x==0:break

 print((len([1 for i in range(3,n+1)for j in range(2,x-i)if x-i-j<j<i])))

while 1:

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

 if n+x==0:break

 print((len([1 for i in range(1,n-1)for j in range(i+1,n)if j<x-i-j<=n])))

while 1:
    n, x = list(map(int, input().split()))
    if n + x == 0:
        break
    print(
        (
            len(
                [
                    1
                    for i in range(3, n + 1)
                    for j in range(2, x - i)
                    if x - i - j < j < i
                ]
            )
        )
    )

while 1:
    n, x = list(map(int, input().split()))
    if n + x == 0:
        break
    print(
        (
            len(
                [
                    1
                    for i in range(1, n - 1)
                    for j in range(i + 1, n)
                    if j < x - i - j <= n
                ]
            )
        )
    )

-                    for i in range(3, n + 1)

-                    for j in range(2, x - i)

-                    if x - i - j < j < i

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

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

+                    if j < x - i - j <= n


Input:
from collections import Counter

S = input()[::-1]

memo = [0]

d = 0

mod = 2019

for s in S:

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

    tmp = memo[-1] + tmp

    memo.append(tmp % mod)

    d += 1

c = Counter(memo)

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

print(ans)

from collections import defaultdict

S = input()

N = len(S)

memo = defaultdict(int)

memo[0] += 1

mod = 2019

d = 1

val = 0

for s in S[::-1]:

    s = int(s)

    val += s * d

    val %= mod

    memo[val] += 1

    d *= 10

    d %= mod

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

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

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

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


Input:
a = input()

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

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

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

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

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


Input:
N=int(input())

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

for i in range(N):

  for j in range(1,31):

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

      a[i]=j-1

      break

print((sum(a)))

import sys

input = sys.stdin.buffer.readline

N = int(input())

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

def f(n):

  res = 0

  while n % 2 == 0:

    n //= 2

    res += 1

  return res

answer = 0

for a in A:

  answer += f(a)

print(answer)

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

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


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

cnt = 0

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

    i = str(i)

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

        cnt += 1

print(cnt)

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

cnt = 0

for i in range(10):

    for j in range(10):

        for k in range(10):

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

            if a <= c <= b:

                cnt += 1

print(cnt)

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

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


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

cnt = 0

for i in range(k + 1):

    for j in range(k + 1):

        if i + j > s:

            break

        elif s - i - j <= k:

            cnt += 1

print(cnt)

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

cnt = 0

for i in range(k + 1):

    for j in range(k + 1):

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

            cnt += 1

print(cnt)

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


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

c = int(c*2)

m = float('inf')

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

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

print(m)

import math

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

ans = float('inf')

c = c*2

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

    if i > x:

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

    elif i > y:

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

    else:

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

    if ans > price:

        ans = price

print(ans)

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

import math

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

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


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

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

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

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

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

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


Input:
s = input()

cnt = 0

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

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

        cnt += 1

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

        cnt += 1

print(cnt)

S = input()

tmp = S[0]

cnt = 0

for s in S[1:]:

    if tmp != s:

        cnt += 1

        tmp = s

print(cnt)

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


Input:
import math

mod = 10 ** 9 + 7

n = int(input())

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

mod = 10 ** 9 + 7

n = int(input())

ans = 1

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

    ans *= i

    ans %= mod

print(ans)

import math

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

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

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


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

count = 0

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

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

        count += 1

print(count)

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

count = 0

for i in range(10):

    for j in range(10):

        for k in range(10):

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

                count += 1

print(count)

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

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


Input:
import math

N = int(input())

num = math.factorial(N)

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

print(r)

N = int(input())

FACTOR = 10 ** 9 + 7

num = 1

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

    num *= i

    k, r = divmod(num, FACTOR)

    num = r

print(r)

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

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


Input:
import math

N = int(input())

C = 10**9 + 7

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

N = int(input())

C = 10**9+7

ans = 1

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

    ans *= i

    ans %= C

print(ans)

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

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


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

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

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

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

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

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

arr.sort(key=abs)

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

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


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

ans = float('inf')

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

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

    ans = min(ans,cost)

print(ans)

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

tmp = A*X + B*Y

if X >= Y:

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

else:

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

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

print(tmp)

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

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

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

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


Input:
s = input()

a = s.find('A')

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

ans = len(s)-a-z

print(ans)

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

def solve():

  S = input()

  a = S.find('A')

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

  ans = len(S)-a-z

  return ans

print((solve()))

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

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

print((solve()))

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


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

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


Input:
import statistics

N = int(input())

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

b = statistics.median_low(A)

c = statistics.median_high(A)

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

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

print((min(d,e)))

N=int(input())

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

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

import statistics

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

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

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

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

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


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

c = 0

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

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

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

    c += 1

print(c)

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

c = 0

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

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

    c += 1

print(c)

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

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

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


Input:
import math

x = int(input())

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

n = int(input())

fact = 1

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

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

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

print(res)

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

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