Input:
def era(num):

    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]

    input_list[0] = input_list[1] = False

    input_list[2] = input_list[3] = input_list[5] = True

    sqrt = num**0.5

    for serial in range(3, num, 2):

        if serial >= sqrt:

            return input_list

        for s in range(serial ** 2, num, serial):

            input_list[s] = False

N=int(eval(input()))

if N<25:

    Prime=[2,3,5]

else:

    input_list=era(int(N**0.5)+1)

    Prime=[i for i, b in enumerate(input_list) if b == True]

Fac={}

for p in Prime:

    while N%p==0:

        N//=p

        if p in Fac:

            Fac[p]+=1

        else:

            Fac[p]=1

    if N==1:

        break

if N!=1:

    Fac[N]=1

ans=0

for k in Fac:

    nec=1

    while True:

        if Fac[k]>=nec:

            ans+=1

            Fac[k]-=nec

            nec+=1

        else:

            break

print(ans)

N=int(eval(input()))

F={}

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

    if N%i==0:

        F[i]=1

        N//=i

    while N%i==0:

        N//=i

        F[i]+=1

if N>1:

    F[N]=1

ans=0

for f in F:

    j=1

    while True:

        F[f]-=j

        j+=1

        if F[f]>=0:

            ans+=1

        else:

            break

print(ans)

def era(num):
    input_list = [
        False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)
    ]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = num**0.5
    for serial in range(3, num, 2):
        if serial >= sqrt:
            return input_list
        for s in range(serial**2, num, serial):
            input_list[s] = False

N = int(eval(input()))
if N < 25:
    Prime = [2, 3, 5]
else:
    input_list = era(int(N**0.5) + 1)
    Prime = [i for i, b in enumerate(input_list) if b == True]
Fac = {}
for p in Prime:
    while N % p == 0:
        N //= p
        if p in Fac:
            Fac[p] += 1
        else:
            Fac[p] = 1
    if N == 1:
        break
if N != 1:
    Fac[N] = 1
ans = 0
for k in Fac:
    nec = 1
    while True:
        if Fac[k] >= nec:
            ans += 1
            Fac[k] -= nec
            nec += 1
        else:
            break
print(ans)

N = int(eval(input()))
F = {}
for i in range(2, int(N**0.5) + 1):
    if N % i == 0:
        F[i] = 1
        N //= i
    while N % i == 0:
        N //= i
        F[i] += 1
if N > 1:
    F[N] = 1
ans = 0
for f in F:
    j = 1
    while True:
        F[f] -= j
        j += 1
        if F[f] >= 0:
            ans += 1
        else:
            break
print(ans)

-        False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)

-    input_list[0] = input_list[1] = False

-    input_list[2] = input_list[3] = input_list[5] = True

-        for s in range(serial**2, num, serial):

-    Prime = [i for i, b in enumerate(input_list) if b == True]


Input:
# coding: utf-8

# Your code here!

# import math

# from decimal import Decimal

# from collections import deque, Counter

# from itertools import product

def LI():

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

def OPEN():

    return list(map(int,open(0).read().split()))

n,*a=OPEN()

now=a[0]

ans=[]

for i in range(n):

    if a[i]<now:

        ans+=(now-a[i]),

        a[i]=now

    now=a[i]

print((sum(ans)))

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

now=a[0]

ans=0

for i in range(n):

  if a[i]<now:

    ans+=(now-a[i])

  now=max(a[i],now)

print(ans)

# coding: utf-8
# Your code here!
# import math
# from decimal import Decimal
# from collections import deque, Counter
# from itertools import product
def LI():
    return list(map(int, input().split()))

def OPEN():
    return list(map(int, open(0).read().split()))

n, *a = OPEN()
now = a[0]
ans = []
for i in range(n):
    if a[i] < now:
        ans += ((now - a[i]),)
        a[i] = now
    now = a[i]
print((sum(ans)))

n, *a = list(map(int, open(0).read().split()))
now = a[0]
ans = 0
for i in range(n):
    if a[i] < now:
        ans += now - a[i]
    now = max(a[i], now)
print(ans)

-# from collections import deque, Counter

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

-    return list(map(int, open(0).read().split()))

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


Input:
from itertools import product

from collections import defaultdict

MOD = 10**9 + 7

N = int(eval(input()))

# XAGC, XGAC, AXGC, AGXC, XACG: prohibited

A=0; C=1; G=2; T=3

cur = defaultdict(lambda: 1)

cur[(A,G,C)] = cur[(G,A,C)] = cur[(A,C,G)] = 0

for _ in range(3,N):

    prev = cur

    cur = defaultdict(int)

    for (i,j,k,l) in product(list(range(4)),repeat=4):

        if ((j,k,l)==(A,G,C) or (j,k,l)==(G,A,C) or (i,k,l)==(A,G,C) or

            (i,j,l)==(A,G,C) or (j,k,l)==(A,C,G)):

            continue

        else:

            cur[(j,k,l)] += prev[(i,j,k)]

    for ijk in product(list(range(4)),repeat=3):

        cur[ijk] %= MOD

ans = sum(cur.values()) % MOD

if N <= 3:

    print(([1,4,16,61][N]))

else:

    print(ans)

from itertools import product

from collections import defaultdict

MOD = 10**9 + 7

N = int(eval(input()))

D, L = 4, 3

AGC = list(range(L))

ATGC = list(range(D))

cur = defaultdict(lambda: 1)

# XAGC, XGAC, AXGC, AGXC, XACG: prohibited

flip = lambda x, n: x[:n] + [x[n+1],x[n]] + x[n+2:]

prohibited1 = [tuple(AGC)] + [tuple(flip(AGC,i)) for i in range(L-1)]

prohibited2 = ({(X,) + p for p in prohibited1 for X in ATGC} |

             {tuple(flip([X]+AGC,0)) for X in ATGC} |

             {tuple(flip(AGC+[X],L-1)) for X in ATGC})

for p in prohibited1:

    cur[p] = 0

for _ in range(L,N):

    prev = cur

    cur = defaultdict(int)

    for recent in product(ATGC, repeat=L+1):

        if recent in prohibited2:

            continue

        else:

            cur[recent[1:]] += prev[recent[:-1]]

    for latest in product(ATGC, repeat=L):

        cur[latest] %= MOD

ans = sum(cur.values()) % MOD

if N < L:

    print((D**N))

elif N == L:

    print((D**L - len(prohibited1)))

else:

    print(ans)

from itertools import product
from collections import defaultdict

MOD = 10**9 + 7
N = int(eval(input()))
# XAGC, XGAC, AXGC, AGXC, XACG: prohibited
A = 0
C = 1
G = 2
T = 3
cur = defaultdict(lambda: 1)
cur[(A, G, C)] = cur[(G, A, C)] = cur[(A, C, G)] = 0
for _ in range(3, N):
    prev = cur
    cur = defaultdict(int)
    for (i, j, k, l) in product(list(range(4)), repeat=4):
        if (
            (j, k, l) == (A, G, C)
            or (j, k, l) == (G, A, C)
            or (i, k, l) == (A, G, C)
            or (i, j, l) == (A, G, C)
            or (j, k, l) == (A, C, G)
        ):
            continue
        else:
            cur[(j, k, l)] += prev[(i, j, k)]
    for ijk in product(list(range(4)), repeat=3):
        cur[ijk] %= MOD
ans = sum(cur.values()) % MOD
if N <= 3:
    print(([1, 4, 16, 61][N]))
else:
    print(ans)

from itertools import product
from collections import defaultdict

MOD = 10**9 + 7
N = int(eval(input()))
D, L = 4, 3
AGC = list(range(L))
ATGC = list(range(D))
cur = defaultdict(lambda: 1)
# XAGC, XGAC, AXGC, AGXC, XACG: prohibited
flip = lambda x, n: x[:n] + [x[n + 1], x[n]] + x[n + 2 :]
prohibited1 = [tuple(AGC)] + [tuple(flip(AGC, i)) for i in range(L - 1)]
prohibited2 = (
    {(X,) + p for p in prohibited1 for X in ATGC}
    | {tuple(flip([X] + AGC, 0)) for X in ATGC}
    | {tuple(flip(AGC + [X], L - 1)) for X in ATGC}
)
for p in prohibited1:
    cur[p] = 0
for _ in range(L, N):
    prev = cur
    cur = defaultdict(int)
    for recent in product(ATGC, repeat=L + 1):
        if recent in prohibited2:
            continue
        else:
            cur[recent[1:]] += prev[recent[:-1]]
    for latest in product(ATGC, repeat=L):
        cur[latest] %= MOD
ans = sum(cur.values()) % MOD
if N < L:
    print((D**N))
elif N == L:
    print((D**L - len(prohibited1)))
else:
    print(ans)

+prohibited1 = [tuple(AGC)] + [tuple(flip(AGC, i)) for i in range(L - 1)]

+    {(X,) + p for p in prohibited1 for X in ATGC}

+    | {tuple(flip([X] + AGC, 0)) for X in ATGC}

+    | {tuple(flip(AGC + [X], L - 1)) for X in ATGC}

-    for (i, j, k, l) in product(list(range(4)), repeat=4):

+    for recent in product(ATGC, repeat=L + 1):

-    for ijk in product(list(range(4)), repeat=3):

+            cur[recent[1:]] += prev[recent[:-1]]

+    for latest in product(ATGC, repeat=L):


Input:
import sys; sys.setrecursionlimit(50000)

input = sys.stdin.readline

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

A = sorted(map(int, input().split()), reverse=True)

B = sorted(map(int, input().split()), reverse=True)

C = sorted(map(int, input().split()), reverse=True)

result = []

for x in range(X):

    for y in range(Y):

        if x * y > K: break

        for z in range(Z):

            if x * y * z > K: break

            result.append(A[x]+B[y]+C[z])

for i in sorted(result, reverse=True)[:K]:

    print(i)

import sys; sys.setrecursionlimit(50000)

input = sys.stdin.readline

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

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

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

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

A.sort(reverse=True)

B.sort(reverse=True)

C.sort(reverse=True)

import heapq

q = []

S = set()

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

S.add((0, 0, 0))

for _ in range(K):

    p, i, j, k = heapq.heappop(q)

    print((-p))

    if i + 1 < X and not (i+1, j, k) in S:

        heapq.heappush(q, (-(A[i+1]+B[j]+C[k]), i+1, j, k))

        S.add((i+1,j,k))

    if j + 1 < Y and not (i, j+1, k) in S:

        heapq.heappush(q, (-(A[i]+B[j+1]+C[k]), i, j+1, k))

        S.add((i,j+1,k))

    if k + 1 < Z and not (i, j, k+1) in S:

        heapq.heappush(q, (-(A[i]+B[j]+C[k+1]), i, j, k+1))

        S.add((i,j,k+1))

import sys

sys.setrecursionlimit(50000)
input = sys.stdin.readline
X, Y, Z, K = list(map(int, input().split()))
A = sorted(map(int, input().split()), reverse=True)
B = sorted(map(int, input().split()), reverse=True)
C = sorted(map(int, input().split()), reverse=True)
result = []
for x in range(X):
    for y in range(Y):
        if x * y > K:
            break
        for z in range(Z):
            if x * y * z > K:
                break
            result.append(A[x] + B[y] + C[z])
for i in sorted(result, reverse=True)[:K]:
    print(i)

import sys

sys.setrecursionlimit(50000)
input = sys.stdin.readline
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
import heapq

q = []
S = set()
heapq.heappush(q, (-(A[0] + B[0] + C[0]), 0, 0, 0))
S.add((0, 0, 0))
for _ in range(K):
    p, i, j, k = heapq.heappop(q)
    print((-p))
    if i + 1 < X and not (i + 1, j, k) in S:
        heapq.heappush(q, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k))
        S.add((i + 1, j, k))
    if j + 1 < Y and not (i, j + 1, k) in S:
        heapq.heappush(q, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k))
        S.add((i, j + 1, k))
    if k + 1 < Z and not (i, j, k + 1) in S:
        heapq.heappush(q, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1))
        S.add((i, j, k + 1))

-A = sorted(map(int, input().split()), reverse=True)

-B = sorted(map(int, input().split()), reverse=True)

-C = sorted(map(int, input().split()), reverse=True)

-            result.append(A[x] + B[y] + C[z])

-for i in sorted(result, reverse=True)[:K]:

+    if i + 1 < X and not (i + 1, j, k) in S:

+    if j + 1 < Y and not (i, j + 1, k) in S:

+    if k + 1 < Z and not (i, j, k + 1) in S:


Input:
from collections import Counter

def resolve():

  N = int(eval(input()))

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

  collection = Counter(A)

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

    print((collection[i]))

  # results = [str(A.count(i))+'\n' for i in range(1, N+1)]

  # print('\n'.join(results))

if __name__ == "__main__":

  resolve()

def resolve():

  N = int(eval(input()))

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

  results = [0] * N

  for a in A:

    results[a-1] += 1

  for r in results:

    print(r)

if __name__ == "__main__":

  resolve()

def resolve():
    N = int(eval(input()))
    A = [int(x) for x in input().split(" ")]
    results = [0] * N
    for a in A:
        results[a - 1] += 1
    for r in results:
        print(r)

if __name__ == "__main__":
    resolve()

-    # results = [str(A.count(i))+'\n' for i in range(1, N+1)]


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

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

x = 0

for i in range(NM[1]):

    x += a[i]

if x > NM[0]:

    print((-1))

else:

    print((NM[0] - x))

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

N, M = NM[0],NM[1]

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

if  sum(a)> N:

    print((-1))

else:

    print((N - sum(a)))

NM = list(map(int, input().split()))
N, M = NM[0], NM[1]
a = list(map(int, input().split()))
if sum(a) > N:
    print((-1))
else:
    print((N - sum(a)))

+N, M = NM[0], NM[1]
-x = 0
-for i in range(NM[1]):
-    x += a[i]
-if x > NM[0]:
+if sum(a) > N:
-    print((NM[0] - x))
+    print((N - sum(a)))


Input:
#dpでできないかな？

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)

from collections import Counter, deque

from collections import defaultdict

from itertools import combinations, permutations, accumulate, groupby, product

from bisect import bisect_left,bisect_right

from heapq import heapify, heappop, heappush

from math import floor, ceil,pi

from operator import itemgetter

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

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

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

def LI2(): return [int(eval(input())) for i in range(n)]

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

def SI(): return input().rstrip()

def printns(x): print(('\n'.join(x)))

def printni(x): print(('\n'.join(list(map(str,x)))))

inf = 10**17

mod = 10**9 + 7

n=I()

lis=LI()

lis=sorted(lis)

#print(lis)

for i in range(1,n):

    lis[i]=lis[i]%lis[0]

lis.append(0)

lis=sorted(list(set(lis)))

while len(lis)>2:

    for i in range(2,len(lis)):

        lis[i]=lis[i]%lis[1]

    lis.append(0)

    lis=sorted(list(set(lis)))

#print(lis)

print((lis[-1]))

#print(lis[0])

#float型を許すな

#numpyはpythonで

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)

from collections import Counter, deque

from collections import defaultdict

from itertools import combinations, permutations, accumulate, groupby, product

from bisect import bisect_left,bisect_right

from heapq import heapify, heappop, heappush

from math import floor, ceil,pi,factorial

from operator import itemgetter

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

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

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

def LI2(): return [int(eval(input())) for i in range(n)]

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

def SI(): return input().rstrip()

def printns(x): print(('\n'.join(x)))

def printni(x): print(('\n'.join(list(map(str,x)))))

inf = 10**17

mod = 10**9 + 7

def gcd(a, b):

    while b:

        a, b = b, a % b

    return a

n=I()

lis=LI()

p=lis[0]

for i in range(n-1):

    p=gcd(p,lis[i+1])

print(p)

# dpでできないかな？
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil, pi
from operator import itemgetter

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

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

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

def LI2():
    return [int(eval(input())) for i in range(n)]

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

def SI():
    return input().rstrip()

def printns(x):
    print(("\n".join(x)))

def printni(x):
    print(("\n".join(list(map(str, x)))))

inf = 10**17
mod = 10**9 + 7
n = I()
lis = LI()
lis = sorted(lis)
# print(lis)
for i in range(1, n):
    lis[i] = lis[i] % lis[0]
lis.append(0)
lis = sorted(list(set(lis)))
while len(lis) > 2:
    for i in range(2, len(lis)):
        lis[i] = lis[i] % lis[1]
    lis.append(0)
    lis = sorted(list(set(lis)))
# print(lis)
print((lis[-1]))
# print(lis[0])

# float型を許すな
# numpyはpythonで
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil, pi, factorial
from operator import itemgetter

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

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

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

def LI2():
    return [int(eval(input())) for i in range(n)]

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

def SI():
    return input().rstrip()

def printns(x):
    print(("\n".join(x)))

def printni(x):
    print(("\n".join(list(map(str, x)))))

inf = 10**17
mod = 10**9 + 7

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

n = I()
lis = LI()
p = lis[0]
for i in range(n - 1):
    p = gcd(p, lis[i + 1])
print(p)

-# dpでできないかな？

+from math import floor, ceil, pi, factorial


Input:
import copy

H, W, K = list(map(int, input().split()))

tiles = [list(eval(input())) for _ in range(H)]

count  = 0

for num in range(2**(H+W)):

  copied_tiles = copy.deepcopy(tiles)

  for i in range(H+W):

    if num>>i&1:

      if i < H:

        for j in range(W):

          copied_tiles[i][j] = 'R'

      else:

        for j in range(H):

          copied_tiles[j][i-H] = 'R'

  black_c = 0

  for i in range(H):

    for j in range(W):

      if copied_tiles[i][j] == '#':

        black_c += 1

  if black_c == K:

    count += 1

print(count)

import copy

H, W, K = list(map(int, input().split()))

tiles = [list(eval(input())) for _ in range(H)]

answer  = 0

for h in range(2**H):

  for w in range(2**W):

    b_cnt = 0

    for i in range(H):

      for j in range(W):

        if not (h>>i&1 or w>>j&1) and tiles[i][j] == '#':

          b_cnt += 1

    if b_cnt == K:

      answer += 1

print(answer)

import copy

H, W, K = list(map(int, input().split()))
tiles = [list(eval(input())) for _ in range(H)]
count = 0
for num in range(2 ** (H + W)):
    copied_tiles = copy.deepcopy(tiles)
    for i in range(H + W):
        if num >> i & 1:
            if i < H:
                for j in range(W):
                    copied_tiles[i][j] = "R"
            else:
                for j in range(H):
                    copied_tiles[j][i - H] = "R"
    black_c = 0
    for i in range(H):
        for j in range(W):
            if copied_tiles[i][j] == "#":
                black_c += 1
    if black_c == K:
        count += 1
print(count)

import copy

H, W, K = list(map(int, input().split()))
tiles = [list(eval(input())) for _ in range(H)]
answer = 0
for h in range(2**H):
    for w in range(2**W):
        b_cnt = 0
        for i in range(H):
            for j in range(W):
                if not (h >> i & 1 or w >> j & 1) and tiles[i][j] == "#":
                    b_cnt += 1
        if b_cnt == K:
            answer += 1
print(answer)

-    copied_tiles = copy.deepcopy(tiles)

-                    copied_tiles[i][j] = "R"

-                    copied_tiles[j][i - H] = "R"

-            if copied_tiles[i][j] == "#":

+                if not (h >> i & 1 or w >> j & 1) and tiles[i][j] == "#":


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

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

ans = 0

for l in range(0, k + 1):

    for r in range(0, k + 1 - l):

        if l == r == 0 or l + r > n:

            continue

        a = sorted(v[:l] + v[n - r:])

        m = min(k - l - r, len(a) - 1)

        ans = max(ans, sum(a[m:] if a[m] <

                           0 else [x for x in a if x > 0]))

print(ans)

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

ans = 0

for l in range(0, k + 1):

    for r in range(0, k + 1 - l):

        if l == r == 0 or l + r > n:

            continue

        b = sorted(a[:l] + a[n - r:])

        c = min(k - l - r, len(b) - 1)

        ans = max(ans, sum(b[c:] if b[c] < 0 else [x for x in b if x > 0]))

print(ans)

n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
ans = 0
for l in range(0, k + 1):
    for r in range(0, k + 1 - l):
        if l == r == 0 or l + r > n:
            continue
        a = sorted(v[:l] + v[n - r :])
        m = min(k - l - r, len(a) - 1)
        ans = max(ans, sum(a[m:] if a[m] < 0 else [x for x in a if x > 0]))
print(ans)

n, k, *a = list(map(int, open(0).read().split()))
ans = 0
for l in range(0, k + 1):
    for r in range(0, k + 1 - l):
        if l == r == 0 or l + r > n:
            continue
        b = sorted(a[:l] + a[n - r :])
        c = min(k - l - r, len(b) - 1)
        ans = max(ans, sum(b[c:] if b[c] < 0 else [x for x in b if x > 0]))
print(ans)

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

-        ans = max(ans, sum(a[m:] if a[m] < 0 else [x for x in a if x > 0]))

+        ans = max(ans, sum(b[c:] if b[c] < 0 else [x for x in b if x > 0]))


Input:
N = int(eval(input()))

multiple_4 = [x*4 for x in range(101) if x >= 1 and x <= 25]

multiple_7 = [x*7 for x in range(101) if x >= 1 and x <= 14]

multiple_4_7 = [x*4+7 for x in range(101) if x >= 1 and x <= 23]

multiple_7_4 = [x*7+4 for x in range(101) if x >= 1 and x <= 23]

tmp = []

for i in range(10):

  for j in range(10):

    solve = (4*(i+1))+(7*(j+1))

    if solve <= 100:

      tmp.append(solve)

multiple_other = sorted(list(set(tmp)))

if N in multiple_4 or N in multiple_7 or N in multiple_4_7 or N in multiple_7_4 or N in multiple_other:

  print("Yes")

else:

  print("No")

N = int(eval(input()))

tmp = []

for i in range(10):

  for j in range(10):

    solve = (4*(i+1))+(7*(j+1))

    if solve <= 100:

      tmp.append(solve)

multiples = sorted(list(set(tmp)))

if N % 4 == 0 or N % 7 == 0 or N in multiples:

  print("Yes")

else:

  print("No")

N = int(eval(input()))
multiple_4 = [x * 4 for x in range(101) if x >= 1 and x <= 25]
multiple_7 = [x * 7 for x in range(101) if x >= 1 and x <= 14]
multiple_4_7 = [x * 4 + 7 for x in range(101) if x >= 1 and x <= 23]
multiple_7_4 = [x * 7 + 4 for x in range(101) if x >= 1 and x <= 23]
tmp = []
for i in range(10):
    for j in range(10):
        solve = (4 * (i + 1)) + (7 * (j + 1))
        if solve <= 100:
            tmp.append(solve)
multiple_other = sorted(list(set(tmp)))
if (
    N in multiple_4
    or N in multiple_7
    or N in multiple_4_7
    or N in multiple_7_4
    or N in multiple_other
):
    print("Yes")
else:
    print("No")

N = int(eval(input()))
tmp = []
for i in range(10):
    for j in range(10):
        solve = (4 * (i + 1)) + (7 * (j + 1))
        if solve <= 100:
            tmp.append(solve)
multiples = sorted(list(set(tmp)))
if N % 4 == 0 or N % 7 == 0 or N in multiples:
    print("Yes")
else:
    print("No")

-multiple_4 = [x * 4 for x in range(101) if x >= 1 and x <= 25]

-multiple_7 = [x * 7 for x in range(101) if x >= 1 and x <= 14]

-multiple_4_7 = [x * 4 + 7 for x in range(101) if x >= 1 and x <= 23]

-multiple_7_4 = [x * 7 + 4 for x in range(101) if x >= 1 and x <= 23]

+if N % 4 == 0 or N % 7 == 0 or N in multiples:


Input:
s=eval(input())

ans=10*100

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

    if abs(753-int(s[i:i+3]))<=ans:

        ans=abs(753-int(s[i:i+3]))

print(ans)

S = eval(input())

ans = []

for i in range(len(S)-2):

    ans.append(abs(int(S[i:i+3]) - 753))

print((min(ans)))

s = eval(input())
ans = 10 * 100
for i in range(len(s) - 2):
    if abs(753 - int(s[i : i + 3])) <= ans:
        ans = abs(753 - int(s[i : i + 3]))
print(ans)

S = eval(input())
ans = []
for i in range(len(S) - 2):
    ans.append(abs(int(S[i : i + 3]) - 753))
print((min(ans)))

+    ans.append(abs(int(S[i : i + 3]) - 753))


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

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

d=sorted(j-i for i,j in zip(X,X[1:]))[::-1]

print((sum(d[N-1:])))

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

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

s=[]

for i in range(M-1):s.append(X[i+1]-X[i])

s=sorted(s)[::-1]

print((sum(s[N-1:])))

N, M = list(map(int, input().split()))
X = sorted(map(int, input().split()))
d = sorted(j - i for i, j in zip(X, X[1:]))[::-1]
print((sum(d[N - 1 :])))

N, M = list(map(int, input().split()))
X = sorted(set(list(map(int, input().split()))))
s = []
for i in range(M - 1):
    s.append(X[i + 1] - X[i])
s = sorted(s)[::-1]
print((sum(s[N - 1 :])))

-d = sorted(j - i for i, j in zip(X, X[1:]))[::-1]

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


Input:
n=int(eval(input()))

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

ans_l=[0]*(n+1)

ans=0

def con(a):

    return int(a*(a-1)*0.5)

for i in range(n):

    ans_l[l[i]]+=1

#print("ans_l",ans_l)

#print("l",l)

for j in ans_l:

    ans+=con(j)

# print(ans)

for i in range(n):

    ans_2=ans

    # print("ans_2_0:",ans_2)

    #print("ans_l[l[i]]",ans_l[l[i]])

    ans_2-=con(ans_l[l[i]])

    #print("ans_2_1:",ans_2)

    #print("ans_l[l[i]]:",ans_l[l[i]]-1)

    ans_2+=con(ans_l[l[i]]-1)

    print(ans_2)

n=int(eval(input()))

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

ans_l=[0]*(n+1)

ans=0

def con(a):

    return int(a*(a-1)*0.5)

for i in l:

    ans_l[i]+=1

#print("ans_l",ans_l)

#print("l",l)

for j in ans_l:

    ans+=con(j)

# print(ans)

for i in l:

    ans_2=ans

    # print("ans_2_0:",ans_2)

    #print("ans_l[i]",ans_l[i])

    ans_2-=con(ans_l[i])

    #print("ans_2_1:",ans_2)

    #print("ans_l[i]:",ans_l[i]-1)

    ans_2+=con(ans_l[i]-1)

    print(ans_2)

n = int(eval(input()))
l = list(map(int, input().split()))
ans_l = [0] * (n + 1)
ans = 0

def con(a):
    return int(a * (a - 1) * 0.5)

for i in range(n):
    ans_l[l[i]] += 1
# print("ans_l",ans_l)
# print("l",l)
for j in ans_l:
    ans += con(j)
# print(ans)
for i in range(n):
    ans_2 = ans
    # print("ans_2_0:",ans_2)
    # print("ans_l[l[i]]",ans_l[l[i]])
    ans_2 -= con(ans_l[l[i]])
    # print("ans_2_1:",ans_2)
    # print("ans_l[l[i]]:",ans_l[l[i]]-1)
    ans_2 += con(ans_l[l[i]] - 1)
    print(ans_2)

n = int(eval(input()))
l = list(map(int, input().split()))
ans_l = [0] * (n + 1)
ans = 0

def con(a):
    return int(a * (a - 1) * 0.5)

for i in l:
    ans_l[i] += 1
# print("ans_l",ans_l)
# print("l",l)
for j in ans_l:
    ans += con(j)
# print(ans)
for i in l:
    ans_2 = ans
    # print("ans_2_0:",ans_2)
    # print("ans_l[i]",ans_l[i])
    ans_2 -= con(ans_l[i])
    # print("ans_2_1:",ans_2)
    # print("ans_l[i]:",ans_l[i]-1)
    ans_2 += con(ans_l[i] - 1)
    print(ans_2)


Input:
import numpy as np

N = int(eval(input()))

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

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

ans = 0

for i,j in zip(V,C):

    if i-j>0:

        ans += i-j

print(ans)

import numpy as np

N = int(eval(input()))
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
for i, j in zip(V, C):
    if i - j > 0:
        ans += i - j
print(ans)


Input:
N = int(eval(input()))

from collections import deque

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

color = [-1]*N

for i in range(N-1):

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

    tree[u-1][v-1] = w

    tree[v-1][u-1] = w

queue = deque()

queue.append((0, 0))

while queue:

    v, w = queue.pop()

    color[v] = w%2

    for i in list(tree[v].keys()):

        if color[i]==-1:

            queue.append((i, w+tree[v][i]))

for c in color:

    print(c)

import sys

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

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

sys.setrecursionlimit(10**9)

N = int(eval(input()))

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

for _ in range(N-1):

    u, v, w = mapint()

    graph[u-1][v-1] = w%2

    graph[v-1][u-1] = w%2

from collections import deque

stack = deque([0])

colors = [-1]*N

colors[0] = 0

while stack:

    v = stack.pop()

    for nx in list(graph[v].keys()):

        if colors[nx]==-1:

            w = graph[v][nx]

            colors[nx] = (colors[v]+w)%2

            stack.append(nx)

for a in colors:

    print(a)

N = int(eval(input()))
from collections import deque

tree = [{} for _ in range(N)]
color = [-1] * N
for i in range(N - 1):
    u, v, w = list(map(int, input().split()))
    tree[u - 1][v - 1] = w
    tree[v - 1][u - 1] = w
queue = deque()
queue.append((0, 0))
while queue:
    v, w = queue.pop()
    color[v] = w % 2
    for i in list(tree[v].keys()):
        if color[i] == -1:
            queue.append((i, w + tree[v][i]))
for c in color:
    print(c)

import sys

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

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

sys.setrecursionlimit(10**9)
N = int(eval(input()))
graph = [{} for _ in range(N)]
for _ in range(N - 1):
    u, v, w = mapint()
    graph[u - 1][v - 1] = w % 2
    graph[v - 1][u - 1] = w % 2
from collections import deque

stack = deque([0])
colors = [-1] * N
colors[0] = 0
while stack:
    v = stack.pop()
    for nx in list(graph[v].keys()):
        if colors[nx] == -1:
            w = graph[v][nx]
            colors[nx] = (colors[v] + w) % 2
            stack.append(nx)
for a in colors:
    print(a)

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

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

-    u, v, w = list(map(int, input().split()))

-            queue.append((i, w + tree[v][i]))

+            colors[nx] = (colors[v] + w) % 2


Input:
import datetime

s = eval(input())

inputDate = datetime.datetime.strptime(s, '%Y/%m/%d')

lastDate = datetime.datetime.strptime('2019/04/30', '%Y/%m/%d')

if inputDate > lastDate:

    print('TBD')

else:

    print('Heisei')

s = eval(input())

if s <= '2019/04/30':

    print('Heisei')

else:

    print('TBD')

import datetime

s = eval(input())
inputDate = datetime.datetime.strptime(s, "%Y/%m/%d")
lastDate = datetime.datetime.strptime("2019/04/30", "%Y/%m/%d")
if inputDate > lastDate:
    print("TBD")
else:
    print("Heisei")

s = eval(input())
if s <= "2019/04/30":
    print("Heisei")
else:
    print("TBD")

-inputDate = datetime.datetime.strptime(s, "%Y/%m/%d")

-lastDate = datetime.datetime.strptime("2019/04/30", "%Y/%m/%d")


Input:
import bisect

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

fct = []

fct2 = []

sq = int(m**(1/2))

if sq + 1 ==m:

    sq += 1

for f in range(1, sq + 1):

    if m%f == 0:

        fct.append(f)

        fct2.append(m//f)

if fct2[-1] == fct[-1]:

    fct2.pop()

fct2.reverse()

fct += fct2

k = m//n

ind = bisect.bisect_left(fct,k)

print((fct[ind-1] if k<fct[ind] else fct[ind]))

import bisect

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

t = m//n

fct_sup = int(m**(1/2)) + 1

fct = []

fct2 = []

for f in range(1,fct_sup+1):

    if m%f == 0:

        fct.append(f)

        fct2.append(m//f)

if fct[-1] == fct2[-1]:

    fct.pop()

fct2.reverse()

fct += fct2

i = bisect.bisect_right(fct,t)

print((fct[i-1]))

import bisect

n, m = list(map(int, input().split()))
fct = []
fct2 = []
sq = int(m ** (1 / 2))
if sq + 1 == m:
    sq += 1
for f in range(1, sq + 1):
    if m % f == 0:
        fct.append(f)
        fct2.append(m // f)
if fct2[-1] == fct[-1]:
    fct2.pop()
fct2.reverse()
fct += fct2
k = m // n
ind = bisect.bisect_left(fct, k)
print((fct[ind - 1] if k < fct[ind] else fct[ind]))

import bisect

n, m = list(map(int, input().split()))
t = m // n
fct_sup = int(m ** (1 / 2)) + 1
fct = []
fct2 = []
for f in range(1, fct_sup + 1):
    if m % f == 0:
        fct.append(f)
        fct2.append(m // f)
if fct[-1] == fct2[-1]:
    fct.pop()
fct2.reverse()
fct += fct2
i = bisect.bisect_right(fct, t)
print((fct[i - 1]))

-print((fct[ind - 1] if k < fct[ind] else fct[ind]))


Input:
x=int(eval(input()))

f=0

if x == 2:

	print((2))

else:

	for i in range(x,10**6):

		for j in range(2,i//2+2):

			if i%j == 0:

				break

		else:

			f=i

			break

	print(f)

from math import sqrt

n=int(eval(input()))

def is_prime(n):

    if n<2:

        return False

    for k in range(2,int(sqrt(n))+1):

        if n%k==0:

            return False

    return True

while not is_prime(n):

    n+=1

print(n)

x = int(eval(input()))
f = 0
if x == 2:
    print((2))
else:
    for i in range(x, 10**6):
        for j in range(2, i // 2 + 2):
            if i % j == 0:
                break
        else:
            f = i
            break
    print(f)

from math import sqrt

n = int(eval(input()))

def is_prime(n):
    if n < 2:
        return False
    for k in range(2, int(sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

while not is_prime(n):
    n += 1
print(n)

+    for k in range(2, int(sqrt(n)) + 1):


Input:
n = int(eval(input()))

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

dp = [0]*(n)

for i in range(1,n):

    if i>1:

        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))

    else:

        dp[i] = dp[i-1] + abs(h[i]-h[i-1])

print((dp[-1]))

n = int(eval(input()))

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

dp = [0]*n

dp[1] = abs(h[0]-h[1])

for i in range(2,n):

    dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]))

print((dp[-1]))

n = int(eval(input()))
h = list(map(int, input().split()))
dp = [0] * (n)
for i in range(1, n):
    if i > 1:
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
    else:
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])
print((dp[-1]))

n = int(eval(input()))
h = list(map(int, input().split()))
dp = [0] * n
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
    dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]))
print((dp[-1]))


Input:
import sys

n, k = list(map(int, sys.stdin.readline().split()))

def main():

    res = 0

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

        q, r = divmod(n, b)

        res += q * (b - k) + max(0, r - (max(k, 1) - 1))

    return res

if __name__ == '__main__':

    ans = main()

    print(ans)

import sys

n, k = list(map(int, sys.stdin.readline().split()))

def main():

    res = 0

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

        q, r = divmod(n, b)

        res += q * (b - k) + max(0, r - (k - 1))

    if k == 0:

        res -= n - k

    return res

if __name__ == '__main__':

    ans = main()

    print(ans)

import sys

n, k = list(map(int, sys.stdin.readline().split()))

def main():
    res = 0
    for b in range(k + 1, n + 1):
        q, r = divmod(n, b)
        res += q * (b - k) + max(0, r - (max(k, 1) - 1))
    return res

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

import sys

n, k = list(map(int, sys.stdin.readline().split()))

def main():
    res = 0
    for b in range(k + 1, n + 1):
        q, r = divmod(n, b)
        res += q * (b - k) + max(0, r - (k - 1))
    if k == 0:
        res -= n - k
    return res

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


Input:
N=int(eval(input()))

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

b=[0]*N

b[N//2]=a[0]

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

  b[N//2-i]=a[i*2-1]

  if i != N//2 or N%2==1:

    b[N//2+i]=a[i*2]

if N%2==1:

  b=b[::-1]

print((" ".join(map(str,b))))

import collections

n = int(eval(input()))

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

b = collections.deque()

flag = True

for x in a:

    if flag:

        b.append(x)

        flag = False

    else:

        b.appendleft(x)

        flag = True

if flag:

    print((*b))

else:

    print((*list(b)[::-1]))

-N = int(eval(input()))
+import collections
+
+n = int(eval(input()))
-b = [0] * N
-b[N // 2] = a[0]
-for i in range(1, N // 2 + 1):
-    b[N // 2 - i] = a[i * 2 - 1]
-    if i != N // 2 or N % 2 == 1:
-        b[N // 2 + i] = a[i * 2]
-if N % 2 == 1:
-    b = b[::-1]
-print((" ".join(map(str, b))))
+b = collections.deque()
+flag = True
+for x in a:
+    if flag:
+        b.append(x)
+        flag = False
+    else:
+        b.appendleft(x)
+        flag = True
+if flag:
+    print((*b))
+else:
+    print((*list(b)[::-1]))


Input:
n=int(eval(input()))

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

l.sort()

l.append(10**9)

cnt=0

i=0

#print(l)

while i<n-2:

    j=i+1

    while j<n-1:

        LL=j+1

        RR=n-1

        #print("#",l[i],l[j],l[LL],l[RR])

        while LL<=RR:

            k=(LL+RR)//2

            if k==n:

                break

            #print(l)

            #print(i,j,LL,RR,k)

            #print(l[i]+l[j],l[k],l[k+1])

            if l[i]+l[j]>l[k] and l[i]+l[j]<=l[k+1]:

                cnt+=k-j

                break

            elif LL==RR:

                break

            elif l[i]+l[j]<=l[k]:

                RR=k

            elif l[i]+l[j]>l[k]:

                LL=k+1

            elif l[i]+l[j]<l[k] and k==j+1:

                break

        j+=1

    i+=1

print(cnt)

n=int(eval(input()))

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

a.sort()

import bisect

ans=0

#A=[1,2,3,4,5] #ソート済み

#index = bisect.bisect_left(A, 3) #2 同じ数字があった場合、前側の挿入箇所が返ってきている

#index = bisect.bisect_right(A, 3) # 3 同じ数字があった場合、後ろ側の挿入箇所が返ってきている

#A.insert(index, 3) #挿入

#print(a)

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

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

        #a[i]<a[j]

        #a[k]<a[i]<a[j]

        #a[k]+a[i]>a[j]

        #=>a[i]> a[k] >a[j]-a[i]

        ll= bisect.bisect_right(a, a[j]-a[i])

        rr= bisect.bisect_left(a, a[i])

        if a[rr+1]==a[i]:

            rr=i

        #print(a[i],a[j],"|",ll,rr,max(0,rr-ll))

        ans+=(max(0,rr-ll))

print(ans)

n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
l.append(10**9)
cnt = 0
i = 0
# print(l)
while i < n - 2:
    j = i + 1
    while j < n - 1:
        LL = j + 1
        RR = n - 1
        # print("#",l[i],l[j],l[LL],l[RR])
        while LL <= RR:
            k = (LL + RR) // 2
            if k == n:
                break
            # print(l)
            # print(i,j,LL,RR,k)
            # print(l[i]+l[j],l[k],l[k+1])
            if l[i] + l[j] > l[k] and l[i] + l[j] <= l[k + 1]:
                cnt += k - j
                break
            elif LL == RR:
                break
            elif l[i] + l[j] <= l[k]:
                RR = k
            elif l[i] + l[j] > l[k]:
                LL = k + 1
            elif l[i] + l[j] < l[k] and k == j + 1:
                break
        j += 1
    i += 1
print(cnt)

n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
import bisect

ans = 0
# A=[1,2,3,4,5] #ソート済み
# index = bisect.bisect_left(A, 3) #2 同じ数字があった場合、前側の挿入箇所が返ってきている
# index = bisect.bisect_right(A, 3) # 3 同じ数字があった場合、後ろ側の挿入箇所が返ってきている
# A.insert(index, 3) #挿入
# print(a)
for i in range(len(a) - 1):
    for j in range(i + 1, len(a)):
        # a[i]<a[j]
        # a[k]<a[i]<a[j]
        # a[k]+a[i]>a[j]
        # =>a[i]> a[k] >a[j]-a[i]
        ll = bisect.bisect_right(a, a[j] - a[i])
        rr = bisect.bisect_left(a, a[i])
        if a[rr + 1] == a[i]:
            rr = i
        # print(a[i],a[j],"|",ll,rr,max(0,rr-ll))
        ans += max(0, rr - ll)
print(ans)

-            elif l[i] + l[j] < l[k] and k == j + 1:

+# index = bisect.bisect_left(A, 3) #2 同じ数字があった場合、前側の挿入箇所が返ってきている

+# index = bisect.bisect_right(A, 3) # 3 同じ数字があった場合、後ろ側の挿入箇所が返ってきている

+        ll = bisect.bisect_right(a, a[j] - a[i])

+        rr = bisect.bisect_left(a, a[i])


Input:
import sys

from collections import deque

sys.setrecursionlimit(10 ** 6)

input = sys.stdin.readline

n = int(eval(input()))

m = {}

np = [deque([]) for _ in range(n)]

for _ in range(n-1):

    a, b, c = [int(x) for x in input().strip().split()]

    m[(a, b)] = c

    m[(b, a)] = c

    np[a-1].append(b)

    np[b-1].append(a)

q, k = [int(x) for x in input().strip().split()]

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

master[k-1] = 0

def dfs(cur, pre, master):

    #print('cur = {}, pre = {}'.format(cur, pre))

    for p in np[cur-1]:

        if p == pre:

            continue

        master[p-1] = master[cur-1] + m[(cur, p)]

        dfs(p, cur, master)

dfs(k, -1, master)

for _ in range(q):

    x, y = [int(x) for x in input().strip().split()]

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

import sys

from collections import deque

sys.setrecursionlimit(10 ** 6)

input = sys.stdin.readline

N = int(eval(input()))

p = [deque([]) for _ in range(N)]

for i in range(N-1):

    a, b, c = [int(x) for x in input().strip().split()]

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

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

Q, K = [int(x) for x in input().strip().split()]

c = [-1] * N

f = [False] * N

def search(cp, cost):

    f[cp-1] = True

    for np, cos in p[cp-1]:

        if f[np-1]:

            continue

        c[np-1] = cost + cos

        f[np-1] = True

        search(np, cost + cos)

search(K, 0)

for q in range(Q):

    x, y = [int(x) for x in input().strip().split()]

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

import sys
from collections import deque

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
n = int(eval(input()))
m = {}
np = [deque([]) for _ in range(n)]
for _ in range(n - 1):
    a, b, c = [int(x) for x in input().strip().split()]
    m[(a, b)] = c
    m[(b, a)] = c
    np[a - 1].append(b)
    np[b - 1].append(a)
q, k = [int(x) for x in input().strip().split()]
master = [-1 for _ in range(n)]
master[k - 1] = 0

def dfs(cur, pre, master):
    # print('cur = {}, pre = {}'.format(cur, pre))
    for p in np[cur - 1]:
        if p == pre:
            continue
        master[p - 1] = master[cur - 1] + m[(cur, p)]
        dfs(p, cur, master)

dfs(k, -1, master)
for _ in range(q):
    x, y = [int(x) for x in input().strip().split()]
    print((master[x - 1] + master[y - 1]))

import sys
from collections import deque

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
N = int(eval(input()))
p = [deque([]) for _ in range(N)]
for i in range(N - 1):
    a, b, c = [int(x) for x in input().strip().split()]
    p[a - 1].append((b, c))
    p[b - 1].append((a, c))
Q, K = [int(x) for x in input().strip().split()]
c = [-1] * N
f = [False] * N

def search(cp, cost):
    f[cp - 1] = True
    for np, cos in p[cp - 1]:
        if f[np - 1]:
            continue
        c[np - 1] = cost + cos
        f[np - 1] = True
        search(np, cost + cos)

search(K, 0)
for q in range(Q):
    x, y = [int(x) for x in input().strip().split()]
    print((c[x - 1] + c[y - 1]))

-q, k = [int(x) for x in input().strip().split()]

+Q, K = [int(x) for x in input().strip().split()]

-    # print('cur = {}, pre = {}'.format(cur, pre))

-        master[p - 1] = master[cur - 1] + m[(cur, p)]

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


Input:
import sys

S = eval(input())

T = eval(input())

if len(S) > len(T):

    print('No')

    sys.exit()

T = T[:-1]

if S == T:

    print('Yes')

else:

    print('No')

S = eval(input())

T = eval(input())

if S == T[:-1]:

    print('Yes')

else:

    print('No')

import sys

S = eval(input())
T = eval(input())
if len(S) > len(T):
    print("No")
    sys.exit()
T = T[:-1]
if S == T:
    print("Yes")
else:
    print("No")

S = eval(input())
T = eval(input())
if S == T[:-1]:
    print("Yes")
else:
    print("No")

-import sys
-if len(S) > len(T):
-    print("No")
-    sys.exit()
-T = T[:-1]
-if S == T:
+if S == T[:-1]:


Input:
from  collections import defaultdict

INF=int(1e9+7)

def main():

    Sn = list(open(0).read().split()[1:])

    d = defaultdict(lambda: INF)

    for Si in Sn:

        for i in range(26):

          d[i] = min(d[i], Si.count(chr(ord("a") + i)))

    for i in range(26):

      if d[i] == INF:

          continue

      print(chr(ord("a") + i) * d[i], end="")

main()

INF=int(1e9+7)

def main():

    Sn = list(open(0).read().split()[1:])

    for i in range(26):

        cnt = INF

        for Si in Sn:

            cnt = min(cnt, Si.count(chr(ord("a") + i)))

        if cnt == INF:

            continue

        print(chr(ord("a") + i) * cnt, end="")

main()

from collections import defaultdict

INF = int(1e9 + 7)

def main():
    Sn = list(open(0).read().split()[1:])
    d = defaultdict(lambda: INF)
    for Si in Sn:
        for i in range(26):
            d[i] = min(d[i], Si.count(chr(ord("a") + i)))
    for i in range(26):
        if d[i] == INF:
            continue
        print(chr(ord("a") + i) * d[i], end="")

main()

INF = int(1e9 + 7)

def main():
    Sn = list(open(0).read().split()[1:])
    for i in range(26):
        cnt = INF
        for Si in Sn:
            cnt = min(cnt, Si.count(chr(ord("a") + i)))
        if cnt == INF:
            continue
        print(chr(ord("a") + i) * cnt, end="")

main()

-            d[i] = min(d[i], Si.count(chr(ord("a") + i)))

+            cnt = min(cnt, Si.count(chr(ord("a") + i)))

-        print(chr(ord("a") + i) * d[i], end="")

+        print(chr(ord("a") + i) * cnt, end="")


Input:
n,s = int(eval(input())),eval(input())

tmp=[]

for i in range(1,n):

  cnt = 0

  for j in list(set(s[:i])):

    if j in list(set(s[i:])):

      cnt += 1

  tmp.append(cnt)

print((max(tmp)))

n,s = int(eval(input())),eval(input())

tmp=[]

for i in range(1,n):

  tmp.append(len(list(set(s[:i])&set(s[i:]))))

print((max(tmp)))

n, s = int(eval(input())), eval(input())
tmp = []
for i in range(1, n):
    cnt = 0
    for j in list(set(s[:i])):
        if j in list(set(s[i:])):
            cnt += 1
    tmp.append(cnt)
print((max(tmp)))

n, s = int(eval(input())), eval(input())
tmp = []
for i in range(1, n):
    tmp.append(len(list(set(s[:i]) & set(s[i:]))))
print((max(tmp)))

+    tmp.append(len(list(set(s[:i]) & set(s[i:]))))


Input:
from operator import mul

from functools import reduce

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

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

even = 0

odd = 0

for a in A:

    if a % 2 == 0:

        even += 1

    else:

        odd += 1

def cmb(n, r):

    r = min(n-r, r)

    if r == 0:

        return 1

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

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

    return over // under

ans = 2**even

cnt = 0

if p == 0:

    for i in range(0, odd+1, 2):

        cnt += cmb(odd, i)

else:

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

        cnt += cmb(odd, i)

print((ans*cnt))

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

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

odd = False

for a in A:

    if a % 2 == 1:

        odd = True

        break

if odd:

    print((2**(n-1)))

elif p == 0:

    print((2**n))

else:

    print((0))

from operator import mul
from functools import reduce

n, p = list(map(int, input().split()))
A = list(map(int, input().split()))
even = 0
odd = 0
for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1

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

ans = 2**even
cnt = 0
if p == 0:
    for i in range(0, odd + 1, 2):
        cnt += cmb(odd, i)
else:
    for i in range(1, odd + 1, 2):
        cnt += cmb(odd, i)
print((ans * cnt))

n, p = list(map(int, input().split()))
A = list(map(int, input().split()))
odd = False
for a in A:
    if a % 2 == 1:
        odd = True
        break
if odd:
    print((2 ** (n - 1)))
elif p == 0:
    print((2**n))
else:
    print((0))

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

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


Input:
import math

a,b = input().split()

S = a+b

K = int(S)

if math.sqrt(K) %1 == 0:

  print("Yes")

else:

  print("No")

import math

s,t = input().split()

N = int(s+t)

if (N**0.5)%1 == 0:

    print("Yes")

else:

    print("No")

import math

a, b = input().split()
S = a + b
K = int(S)
if math.sqrt(K) % 1 == 0:
    print("Yes")
else:
    print("No")

import math

s, t = input().split()
N = int(s + t)
if (N**0.5) % 1 == 0:
    print("Yes")
else:
    print("No")

-a, b = input().split()
-S = a + b
-K = int(S)
-if math.sqrt(K) % 1 == 0:
+s, t = input().split()
+N = int(s + t)
+if (N**0.5) % 1 == 0:


Input:
n = int(eval(input()))

mn = float("inf")

for i in range(1,n):

  count = 0

  for s in str(i):

    count += int(s)

  for p in str(n-i):

    count += int(p)

  if count < mn:

    mn = count

print(mn)

n = int(eval(input()))

mn = float("inf")

for i in range(1,n):

  if sum(map(int,str(i))) + sum(map(int,str(n-i))) < mn:

    mn = sum(map(int,str(i))) + sum(map(int,str(n-i)))

print(mn)

n = int(eval(input()))
mn = float("inf")
for i in range(1, n):
    count = 0
    for s in str(i):
        count += int(s)
    for p in str(n - i):
        count += int(p)
    if count < mn:
        mn = count
print(mn)

n = int(eval(input()))
mn = float("inf")
for i in range(1, n):
    if sum(map(int, str(i))) + sum(map(int, str(n - i))) < mn:
        mn = sum(map(int, str(i))) + sum(map(int, str(n - i)))
print(mn)

+    if sum(map(int, str(i))) + sum(map(int, str(n - i))) < mn:

+        mn = sum(map(int, str(i))) + sum(map(int, str(n - i)))


Input:
# coding: utf-8

# Your code here!

a=int(eval(input()))

b=int(eval(input()))

c=int(eval(input()))

d=int(eval(input()))

e=int(eval(input()))

k=int(eval(input()))

if e-a<=k:

    print("Yay!")

else:

    print(":(")

# coding: utf-8

a=int(eval(input()))

b=int(eval(input()))

c=int(eval(input()))

d=int(eval(input()))

e=int(eval(input()))

k=int(eval(input()))

if e-a>k:

    print(":(")

else:

    print("Yay!")

# coding: utf-8
# Your code here!
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
e = int(eval(input()))
k = int(eval(input()))
if e - a <= k:
    print("Yay!")
else:
    print(":(")

# coding: utf-8
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
e = int(eval(input()))
k = int(eval(input()))
if e - a > k:
    print(":(")
else:
    print("Yay!")

-# Your code here!
-if e - a <= k:
+if e - a > k:
+    print(":(")
+else:
-else:
-    print(":(")


Input:
from collections import deque

from bisect import bisect_left

n = int(eval(input()))

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

ld = deque(l)

cnt = 0

for a in range(n - 2):

    l_a = ld.popleft()

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

        cnt += bisect_left(l, l_a + l[b]) - b - 1

print(cnt)

def main():

    from collections import deque

    from bisect import bisect_left

    n = int(eval(input()))

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

    ld = deque(l)

    cnt = 0

    for a in range(n - 2):

        l_a = ld.popleft()

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

            cnt += bisect_left(l, l_a + l[b]) - b - 1

    print(cnt)

if __name__ == "__main__":

    main()

-        cnt += bisect_left(l, l_a + l[b]) - b - 1

+    l = sorted(map(int, input().split()))

+            cnt += bisect_left(l, l_a + l[b]) - b - 1


Input:
import sys

input = sys.stdin.buffer.readline

from operator import itemgetter

class BIT:

    """一点加算、区間取得クエリをそれぞれO(logN)で答えるデータ構造"""

    def __init__(self, n):

        self.size = n

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

    def build(self, array):

        """arrayを初期値とするBinaryIndexTreeを構築する O(N)"""

        for i in range(self.size):

            self.bit[i + 1] = array[i]

        for i in range(1, self.size):

            if i + (i & -i) > self.size:

                continue

            self.bit[i + (i & -i)] += self.bit[i]

    def _sum(self, i):

        s = 0

        while i > 0:

            s += self.bit[i]

            i -= i & -i

        return s

    def add(self, i, val):

        """i番目の要素にvalを加える"""

        i += 1

        while i <= self.size:

            self.bit[i] += val

            i += i & -i

    def get_sum(self, l, r):

        """区間[l, r)の和を求める"""

        return self._sum(r) - self._sum(l)

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

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

query = [list(map(int, input().split())) + [i] for i in range(q)]

bit = BIT(n)

memo = {}

ans = [0] * q

query = sorted(query, key=itemgetter(1))

ind = 0

for l, r, i in query:

    while ind < r:

        if c[ind] in memo:

            old_ind = memo[c[ind]]

        else:

            old_ind = -1

        memo[c[ind]] = ind

        bit.add(ind, 1)

        if old_ind != -1:

            bit.add(old_ind, -1)

        ind += 1

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

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

import sys

input = sys.stdin.buffer.readline

from operator import itemgetter

class BIT:

    """一点加算、区間取得クエリをそれぞれO(logN)で答えるデータ構造"""

    def __init__(self, n):

        self.size = n

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

    def build(self, array):

        """arrayを初期値とするBinaryIndexTreeを構築する O(N)"""

        for i in range(self.size):

            self.bit[i + 1] = array[i]

        for i in range(1, self.size):

            if i + (i & -i) > self.size:

                continue

            self.bit[i + (i & -i)] += self.bit[i]

    def _sum(self, i):

        s = 0

        while i > 0:

            s += self.bit[i]

            i -= i & -i

        return s

    def add(self, i, val):

        """i番目の要素にvalを加える"""

        i += 1

        while i <= self.size:

            self.bit[i] += val

            i += i & -i

    def get_sum(self, l, r):

        """区間[l, r)の和を求める"""

        return self._sum(r) - self._sum(l)

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

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

query = []

OFFSET = 10 ** 6

for i in range(q):

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

    query.append(i + OFFSET * l + OFFSET * OFFSET * r)

bit = BIT(n)

memo = {}

ans = [0] * q

query.sort()

ind = 0

for tmp in query:

    i = tmp % OFFSET

    l = (tmp // OFFSET) % OFFSET

    r = tmp // (OFFSET * OFFSET)

    while ind < r:

        if c[ind] in memo:

            old_ind = memo[c[ind]]

        else:

            old_ind = -1

        memo[c[ind]] = ind

        bit.add(ind, 1)

        if old_ind != -1:

            bit.add(old_ind, -1)

        ind += 1

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

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

import sys

input = sys.stdin.buffer.readline
from operator import itemgetter

class BIT:
    """一点加算、区間取得クエリをそれぞれO(logN)で答えるデータ構造"""

    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)

    def build(self, array):
        """arrayを初期値とするBinaryIndexTreeを構築する O(N)"""
        for i in range(self.size):
            self.bit[i + 1] = array[i]
        for i in range(1, self.size):
            if i + (i & -i) > self.size:
                continue
            self.bit[i + (i & -i)] += self.bit[i]

    def _sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, val):
        """i番目の要素にvalを加える"""
        i += 1
        while i <= self.size:
            self.bit[i] += val
            i += i & -i

    def get_sum(self, l, r):
        """区間[l, r)の和を求める"""
        return self._sum(r) - self._sum(l)

n, q = list(map(int, input().split()))
c = list(map(int, input().split()))
query = []
OFFSET = 10**6
for i in range(q):
    l, r = list(map(int, input().split()))
    query.append(i + OFFSET * l + OFFSET * OFFSET * r)
bit = BIT(n)
memo = {}
ans = [0] * q
query.sort()
ind = 0
for tmp in query:
    i = tmp % OFFSET
    l = (tmp // OFFSET) % OFFSET
    r = tmp // (OFFSET * OFFSET)
    while ind < r:
        if c[ind] in memo:
            old_ind = memo[c[ind]]
        else:
            old_ind = -1
        memo[c[ind]] = ind
        bit.add(ind, 1)
        if old_ind != -1:
            bit.add(old_ind, -1)
        ind += 1
    ans[i] = bit.get_sum(l - 1, r)
print(("\n".join(map(str, ans))))

-query = [list(map(int, input().split())) + [i] for i in range(q)]

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

+    query.append(i + OFFSET * l + OFFSET * OFFSET * r)

-query = sorted(query, key=itemgetter(1))


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

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

for i in range(m):

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

    li[a-1].append(b-1)

    li[b-1].append(a-1)

sign = {0: 0}

step = {0: 1}

now = {0}

flg = False

while len(now) > 0:

    if flg:

        print('No')

        exit()

    flg = True

    next = set()

    for i in now:

        for j in li[i]:

            if not j in sign:

                sign[j] = i

                step[j] = step[i] + 1

                next.add(j)

                flg = False

    now.clear()

    now = next

print('Yes')

for i in range(n - 1):

    print((sign[i + 1] + 1))

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

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

for i in range(m):

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

    li[a-1].append(b-1)

    li[b-1].append(a-1)

sign = {0: 0}

step = {0: 0}

now = {0}

while len(now) > 0:

    next = set()

    for i in now:

        for j in li[i]:

            if not j in sign:

                sign[j] = i

                step[j] = step[i] + 1

                next.add(j)

    now.clear()

    now = next

print('Yes')

for i in range(n - 1):

    print((sign[i + 1] + 1))

n, m = list(map(int, input().split()))
li = [[] for i in range(n)]
for i in range(m):
    a, b = list(map(int, input().split()))
    li[a - 1].append(b - 1)
    li[b - 1].append(a - 1)
sign = {0: 0}
step = {0: 1}
now = {0}
flg = False
while len(now) > 0:
    if flg:
        print("No")
        exit()
    flg = True
    next = set()
    for i in now:
        for j in li[i]:
            if not j in sign:
                sign[j] = i
                step[j] = step[i] + 1
                next.add(j)
                flg = False
    now.clear()
    now = next
print("Yes")
for i in range(n - 1):
    print((sign[i + 1] + 1))

n, m = list(map(int, input().split()))
li = [[] for i in range(n)]
for i in range(m):
    a, b = list(map(int, input().split()))
    li[a - 1].append(b - 1)
    li[b - 1].append(a - 1)
sign = {0: 0}
step = {0: 0}
now = {0}
while len(now) > 0:
    next = set()
    for i in now:
        for j in li[i]:
            if not j in sign:
                sign[j] = i
                step[j] = step[i] + 1
                next.add(j)
    now.clear()
    now = next
print("Yes")
for i in range(n - 1):
    print((sign[i + 1] + 1))

-step = {0: 1}
+step = {0: 0}
-flg = False
-    if flg:
-        print("No")
-        exit()
-    flg = True
-                flg = False


Input:
while 1:

 n=int(eval(input()))

 if n==0:break

 d={}

 for _ in[0]*n:

  k,v=input().strip().split()

  d[k]=v

 a=''

 for _ in[0]*int(eval(input())):

  e=input().strip()

  a+=d[e]if e in d else e

 print(a)

import sys

s=sys.stdin

while 1:

 n=int(s.readline())

 if n==0:break

 d={}

 for _ in[0]*n:

  k,v=s.readline().strip().split()

  d[k]=v

 a=''

 for _ in[0]*int(s.readline()):

  e=s.readline().strip()

  a+=d[e]if e in d else e

 print(a)

while 1:
    n = int(eval(input()))
    if n == 0:
        break
    d = {}
    for _ in [0] * n:
        k, v = input().strip().split()
        d[k] = v
    a = ""
    for _ in [0] * int(eval(input())):
        e = input().strip()
        a += d[e] if e in d else e
    print(a)

import sys

s = sys.stdin
while 1:
    n = int(s.readline())
    if n == 0:
        break
    d = {}
    for _ in [0] * n:
        k, v = s.readline().strip().split()
        d[k] = v
    a = ""
    for _ in [0] * int(s.readline()):
        e = s.readline().strip()
        a += d[e] if e in d else e
    print(a)

+        k, v = s.readline().strip().split()


Input:
S = eval(input())

n = len(S)

ans = 0

for bit in range(2**(n-1)):

    cand = []

    j = 0

    for i in range(n):

        if (bit >> i) & 1:

            cand.append(S[j:i+1])

            j = i + 1

    cand.append(S[j:])

    ans += sum(map(int, cand))

    #print(cand)

print(ans)

def Recursion(S):

    list = []

    list.append(int(S))

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

        left = S[:i+1]

        right = S[i+1:]

        x = int(left)

        for y in Recursion(right):

            list.append(x + y)

    return list

S = eval(input())

print((sum(Recursion(S))))

S = eval(input())
n = len(S)
ans = 0
for bit in range(2 ** (n - 1)):
    cand = []
    j = 0
    for i in range(n):
        if (bit >> i) & 1:
            cand.append(S[j : i + 1])
            j = i + 1
    cand.append(S[j:])
    ans += sum(map(int, cand))
    # print(cand)
print(ans)

def Recursion(S):
    list = []
    list.append(int(S))
    for i in range(len(S) - 1):
        left = S[: i + 1]
        right = S[i + 1 :]
        x = int(left)
        for y in Recursion(right):
            list.append(x + y)
    return list

S = eval(input())
print((sum(Recursion(S))))

+def Recursion(S):
+    list = []
+    list.append(int(S))
+    for i in range(len(S) - 1):
+        left = S[: i + 1]
+        right = S[i + 1 :]
+        x = int(left)
+        for y in Recursion(right):
+            list.append(x + y)
+    return list
+
+
-n = len(S)
-ans = 0
-for bit in range(2 ** (n - 1)):
-    cand = []
-    j = 0
-    for i in range(n):
-        if (bit >> i) & 1:
-            cand.append(S[j : i + 1])
-            j = i + 1
-    cand.append(S[j:])
-    ans += sum(map(int, cand))
-    # print(cand)
-print(ans)
+print((sum(Recursion(S))))


Input:
while 1:

	try:

		a=input()

		cjoi=cioi=0

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

			if a[i:i+3]=="JOI":

				cjoi+=1

			if a[i:i+3]=="IOI":

				cioi+=1

		print(cjoi)

		print(cioi)

	except:

		break

while 1:

	try:

		a=input()

		cjoi=cioi=0

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

			if   a[i]=="J" and a[i+1]=="O" and a[i+2]=="I":cjoi+=1

			elif a[i]=="I" and a[i+1]=="O" and a[i+2]=="I":cioi+=1

		print(cjoi)

		print(cioi)

	except:

		break

while 1:
    try:
        a = input()
        cjoi = cioi = 0
        for i in range(len(a) - 2):
            if a[i : i + 3] == "JOI":
                cjoi += 1
            if a[i : i + 3] == "IOI":
                cioi += 1
        print(cjoi)
        print(cioi)
    except:
        break

while 1:
    try:
        a = input()
        cjoi = cioi = 0
        for i in range(len(a) - 2):
            if a[i] == "J" and a[i + 1] == "O" and a[i + 2] == "I":
                cjoi += 1
            elif a[i] == "I" and a[i + 1] == "O" and a[i + 2] == "I":
                cioi += 1
        print(cjoi)
        print(cioi)
    except:
        break


Input:
import sys

from bisect import bisect_left, bisect_right

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007

def main():

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

    L.sort()

    ans = 0

    for i in range(N):

        a = L[i]

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

            b = L[j]

            left = bisect_left(L, b, lo=j + 1)

            right = bisect_left(L, a + b, lo=j + 1)

            ans += right - left

    print(ans)

    return

if __name__ == '__main__':

    main()

import sys

from bisect import bisect_left, bisect_right

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007

def main():

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

    L.sort()

    ans = 0

    for i, a in enumerate(L):

        for j, b in enumerate(L[i + 1 :], i + 1):

            k = bisect_left(L, a + b, lo=j + 1)

            ans += k - j - 1

    print(ans)

    return

if __name__ == '__main__':

    main()

import sys
from bisect import bisect_left, bisect_right

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

def main():
    N, *L = list(map(int, read().split()))
    L.sort()
    ans = 0
    for i in range(N):
        a = L[i]
        for j in range(i + 1, N):
            b = L[j]
            left = bisect_left(L, b, lo=j + 1)
            right = bisect_left(L, a + b, lo=j + 1)
            ans += right - left
    print(ans)
    return

if __name__ == "__main__":
    main()

import sys
from bisect import bisect_left, bisect_right

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

def main():
    N, *L = list(map(int, read().split()))
    L.sort()
    ans = 0
    for i, a in enumerate(L):
        for j, b in enumerate(L[i + 1 :], i + 1):
            k = bisect_left(L, a + b, lo=j + 1)
            ans += k - j - 1
    print(ans)
    return

if __name__ == "__main__":
    main()

-            left = bisect_left(L, b, lo=j + 1)

-            right = bisect_left(L, a + b, lo=j + 1)

+        for j, b in enumerate(L[i + 1 :], i + 1):

+            k = bisect_left(L, a + b, lo=j + 1)


Input:
N = int(eval(input()))

dp = [0]*(N+100001)

for i in range(99999):

    dp[i] = 10**10

for i in range(100000,N+100001):

    dp[i] = min(dp[i-1] + 1,

                dp[i-6] + 1,

                dp[i-9] + 1,

                dp[i-36] +1,

                dp[i-81] + 1,

                dp[i-216] + 1,

                dp[i-729] + 1,

                dp[i-1296] + 1,

                dp[i-6561] + 1,

                dp[i-7776] + 1,

                dp[i-46656] + 1,

                dp[i-59049] + 1)

print((dp[N+99999]))

+# dp[99999] までを大きな数で初期化しておく

+# dp[100000] : 0円を引き出すのに必要な最小回数 = 0 で初期化済み

+# dp[100001] : 1円を引き出すのに必要な最小回数 から処理していく


Input:
from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

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

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

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

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

n = inp()

s = eval(input())

dp = [[0 for i in range(n+5)] for j in range(n+5)]

res = 0

for i in range(n)[::-1]:

    for j in range(n)[::-1]:

        if i >= j: continue

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

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

        else:

            dp[i][j] = 0

for i in range(n):

    for j in range(n):

        tmp = min(j-i, dp[i][j])

        res = max(res, tmp)

print(res)

from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,fractions

from decimal import Decimal

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

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

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

def z_algo(S):

    N = len(S)

    A = [0] * N

    i = 1; j = 0

    A[0] = l = N

    while i < l:

        while i+j < l and S[j] == S[i+j]:

            j += 1

        if not j:

            i += 1

            continue

        A[i] = j

        k = 1

        while l-i > k < j - A[k]:

            A[i+k] = A[k]

            k += 1

        i += k; j -= k

    return A

n = inp()

s = eval(input())

res = 0

for i in range(n-1):

    a = z_algo(s[i:])

    ln = n-i

    for j,x in enumerate(a):

        tmp = min(j,x)

        res = max(res, tmp)

print(res)

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

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

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

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

n = inp()
s = eval(input())
dp = [[0 for i in range(n + 5)] for j in range(n + 5)]
res = 0
for i in range(n)[::-1]:
    for j in range(n)[::-1]:
        if i >= j:
            continue
        if s[i] == s[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
        else:
            dp[i][j] = 0
for i in range(n):
    for j in range(n):
        tmp = min(j - i, dp[i][j])
        res = max(res, tmp)
print(res)

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions
from decimal import Decimal

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

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

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

def z_algo(S):
    N = len(S)
    A = [0] * N
    i = 1
    j = 0
    A[0] = l = N
    while i < l:
        while i + j < l and S[j] == S[i + j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l - i > k < j - A[k]:
            A[i + k] = A[k]
            k += 1
        i += k
        j -= k
    return A

n = inp()
s = eval(input())
res = 0
for i in range(n - 1):
    a = z_algo(s[i:])
    ln = n - i
    for j, x in enumerate(a):
        tmp = min(j, x)
        res = max(res, tmp)
print(res)

-import sys, bisect, math, itertools, pprint, fractions

+import sys, bisect, math, itertools, fractions

+        while i + j < l and S[j] == S[i + j]:

-dp = [[0 for i in range(n + 5)] for j in range(n + 5)]


Input:
import fractions

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

print((a * b // fractions.gcd(a, b)))

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

def gcd(x, y):

    x, y = max(x, y), min(x, y)

    if y == 0:

        return x

    return gcd(y, x % y)

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

-import fractions
+a, b = list(map(int, input().split()))
-a, b = list(map(int, input().split()))
-print((a * b // fractions.gcd(a, b)))
+
+def gcd(x, y):
+    x, y = max(x, y), min(x, y)
+    if y == 0:
+        return x
+    return gcd(y, x % y)
+
+
+print((a * b // gcd(a, b)))


Input:
from sys import exit

from fractions import gcd

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

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

a = A[0]

n = 1

while a % 2 == 0:

    n *= 2

    a //= 2

lcm = 1

for a in A:

    if a % n != 0 or a % (2 * n) == 0:

        print((0))

        exit()

    lcm = lcm * a // gcd(lcm, a)

    if lcm // 2 > M:

        print((0))

        exit()

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

def main():

    from fractions import gcd

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

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

    a = A[0]

    n = 1

    while a & 1 == 0:

        n <<= 1

        a >>= 1

    lcm = 1

    for a in A:

        if a % n != 0 or a % (2 * n) == 0:

            print((0))

            return

        lcm = lcm * a // gcd(lcm, a)

        if lcm > M * 2:

            print((0))

            return

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

main()

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

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


Input:
from collections import deque

S = deque(list(input().strip()))

Q = int(eval(input()))

cnt = 0

for _ in range(Q):

    q = list(input().split())

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

        cnt += 1

    else:

        if cnt%2==0:

            if int(q[1])==1:

                S.appendleft(q[2])

            else:

                S.append(q[2])

        else:

            if int(q[1])==1:

                S.append(q[2])

            else:

                S.appendleft(q[2])

if cnt%2==0:

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

else:

    S.reverse()

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

from collections import deque

S = deque(list(input().strip()))

Q = int(eval(input()))

cnt = 0

for i in range(Q):

    q = list(input().split())

    if len(q)==1:

        cnt += 1

    else:

        F = int(q[1])

        C = q[2]

        if cnt%2==0:

            if F==1:

                S.appendleft(C)

            else:

                S.append(C)

        else:

            if F==1:

                S.append(C)

            else:

                S.appendleft(C)

if cnt%2==0:

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

else:

    S = list(S)[::-1]

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

from collections import deque

S = deque(list(input().strip()))
Q = int(eval(input()))
cnt = 0
for _ in range(Q):
    q = list(input().split())
    if int(q[0]) == 1:
        cnt += 1
    else:
        if cnt % 2 == 0:
            if int(q[1]) == 1:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if int(q[1]) == 1:
                S.append(q[2])
            else:
                S.appendleft(q[2])
if cnt % 2 == 0:
    print(("".join(S)))
else:
    S.reverse()
    print(("".join(S)))

from collections import deque

S = deque(list(input().strip()))
Q = int(eval(input()))
cnt = 0
for i in range(Q):
    q = list(input().split())
    if len(q) == 1:
        cnt += 1
    else:
        F = int(q[1])
        C = q[2]
        if cnt % 2 == 0:
            if F == 1:
                S.appendleft(C)
            else:
                S.append(C)
        else:
            if F == 1:
                S.append(C)
            else:
                S.appendleft(C)
if cnt % 2 == 0:
    print(("".join(S)))
else:
    S = list(S)[::-1]
    print(("".join(S)))

-for _ in range(Q):
+for i in range(Q):
-    if int(q[0]) == 1:
+    if len(q) == 1:
+        F = int(q[1])
+        C = q[2]
-            if int(q[1]) == 1:
-                S.appendleft(q[2])
+            if F == 1:
+                S.appendleft(C)
-                S.append(q[2])
+                S.append(C)
-            if int(q[1]) == 1:
-                S.append(q[2])
+            if F == 1:
+                S.append(C)
-                S.appendleft(q[2])
+                S.appendleft(C)
-    S.reverse()
+    S = list(S)[::-1]


Input:
from fractions import gcd

MOD = 1000000000 + 7

N = int(eval(input()))

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

l = 1

ans = 0

for a in A:

    g = gcd(a, l)

    l = (l // g) * a

    ans = (ans * (a // g)) % MOD

    ans = (ans + (l // a)) % MOD

print((int(ans)))

from fractions import gcd

MOD = 1000000000 + 7

N = int(eval(input()))

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

def fact(a, n):

    r = 1

    while (n > 0):

        if (n & 1):

            r = (r * a) % MOD

        a = (a * a) % MOD

        n //= 2

    return r

def modinv(a):

    return fact(a, MOD-2)

l = 1

ans = 0

for a in A:

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

l %= MOD

ans = 0

for a in A:

    ans += (l * modinv(a)) % MOD

print((ans % MOD))

from fractions import gcd

MOD = 1000000000 + 7
N = int(eval(input()))
A = list(map(int, input().split()))

def fact(a, n):
    r = 1
    while n > 0:
        if n & 1:
            r = (r * a) % MOD
        a = (a * a) % MOD
        n //= 2
    return r

def modinv(a):
    return fact(a, MOD - 2)

l = 1
ans = 0
for a in A:
    l = l * a // gcd(a, l)
l %= MOD
ans = 0
for a in A:
    ans += (l * modinv(a)) % MOD
print((ans % MOD))

+
+
+def fact(a, n):
+    r = 1
+    while n > 0:
+        if n & 1:
+            r = (r * a) % MOD
+        a = (a * a) % MOD
+        n //= 2
+    return r
+
+
+def modinv(a):
+    return fact(a, MOD - 2)
+
+
-    g = gcd(a, l)
-    l = (l // g) * a
-    ans = (ans * (a // g)) % MOD
-    ans = (ans + (l // a)) % MOD
-print((int(ans)))
+    l = l * a // gcd(a, l)
+l %= MOD
+ans = 0
+for a in A:
+    ans += (l * modinv(a)) % MOD
+print((ans % MOD))


Input:
N, M = [int(t) for t in input().split()]

R = []

for i in range(M):

    a, b = [int(t) for t in input().split()]

    R.append((a, b))

R.sort()

inf = float('inf')

Ra = [inf for a in range(N + 1)]

for a, b in R:

    Ra[a] = min(Ra[a], b)

R = [(a, Ra[a]) for a in range(1, N+1) if Ra[a] != inf]

R.sort(key=lambda r: r[1])

bridge = [True] * (N)

last = None

for a, b in R:

    if last == None or last < a:

        bridge[b-1] = False

        last = b-1

print((sum(1 for b in bridge if not b)))

N, M = [int(t) for t in input().split()]

R = []

for i in range(M):

    a, b = [int(t) for t in input().split()]

    R.append((a, b))

R.sort(key=lambda r: r[1])

last  = -1

count = 0

for a, b in R:

    if last < a:

        last = b - 1

        count += 1

print(count)

N, M = [int(t) for t in input().split()]
R = []
for i in range(M):
    a, b = [int(t) for t in input().split()]
    R.append((a, b))
R.sort()
inf = float("inf")
Ra = [inf for a in range(N + 1)]
for a, b in R:
    Ra[a] = min(Ra[a], b)
R = [(a, Ra[a]) for a in range(1, N + 1) if Ra[a] != inf]
R.sort(key=lambda r: r[1])
bridge = [True] * (N)
last = None
for a, b in R:
    if last == None or last < a:
        bridge[b - 1] = False
        last = b - 1
print((sum(1 for b in bridge if not b)))

-R = [(a, Ra[a]) for a in range(1, N + 1) if Ra[a] != inf]

-print((sum(1 for b in bridge if not b)))


Input:
def sieve(x):

    """

    Sieve of Eratosthenes

    :param x: max value

    :return: list of bool

    """

    is_prime = [True] * (x + 1)

    is_prime[0] = is_prime[1] = False

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

        if is_prime[i]:

            for j in range(i * 2, x + 1, i):

                is_prime[j] = False

    return is_prime

n = int(eval(input()))

is_prime = sieve(10 ** 6)

primes = [i for i, e in enumerate(is_prime) if e]

ans = 0

for e in primes:

    div = e

    while n % div == 0:

        n //= div

        ans += 1

        div *= e

    while n % e == 0:

        n //= e

ans += n != 1

print(ans)

from math import sqrt

from collections import defaultdict

n = int(eval(input()))

d = defaultdict(int)

for i in range(2, int(sqrt(n)) + 10):

    while n % i == 0:

        d[i] += 1

        n //= i

if n != 1:

    d[n] += 1

ans = 0

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

    mn = 1

    while v >= mn:

        v -= mn

        ans += 1

        mn += 1

print(ans)

def sieve(x):
    """
    Sieve of Eratosthenes
    :param x: max value
    :return: list of bool
    """
    is_prime = [True] * (x + 1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, x + 1):
        if is_prime[i]:
            for j in range(i * 2, x + 1, i):
                is_prime[j] = False
    return is_prime

n = int(eval(input()))
is_prime = sieve(10**6)
primes = [i for i, e in enumerate(is_prime) if e]
ans = 0
for e in primes:
    div = e
    while n % div == 0:
        n //= div
        ans += 1
        div *= e
    while n % e == 0:
        n //= e
ans += n != 1
print(ans)

-            for j in range(i * 2, x + 1, i):

-primes = [i for i, e in enumerate(is_prime) if e]


Input:
from collections import Counter

n = int(input())

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

L = Counter(S)

m = 0

for v in L.values():

    m = max(m, v)

ans = []

for k, v in L.items():

    if v == m:

        ans.append(k)

ans.sort()

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

from collections import Counter

N = int(input())

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

C = Counter(S)

max_cnt = max(C.values())

names = [names for names, values in C.items() if values == max_cnt]

names.sort()

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

+names = [names for names, values in C.items() if values == max_cnt]


Input:
r,g,b,n=list(map(int,input().split()))

ans=0

r,g,b=max(r,g,b),r+g+b-max(r,g,b)-min(r,g,b),min(r,g,b)

for i in range(n//r+1):

  for j in range(n//g+1):

    if (n-i*r-j*g)%b or (n-i*r-j*g)<0:

      continue

    ans+=1

print(ans)

r,g,b,n=list(map(int,input().split()))

ans=0

for R in range(n//r+1):

    for B in range((n)//b+1):

        if (R*r+B*b-n)<=0 and (R*r+B*b-n)%g==0:

            ans+=1

print(ans)

r, g, b, n = list(map(int, input().split()))
ans = 0
r, g, b = max(r, g, b), r + g + b - max(r, g, b) - min(r, g, b), min(r, g, b)
for i in range(n // r + 1):
    for j in range(n // g + 1):
        if (n - i * r - j * g) % b or (n - i * r - j * g) < 0:
            continue
        ans += 1
print(ans)

r, g, b, n = list(map(int, input().split()))
ans = 0
for R in range(n // r + 1):
    for B in range((n) // b + 1):
        if (R * r + B * b - n) <= 0 and (R * r + B * b - n) % g == 0:
            ans += 1
print(ans)

-r, g, b = max(r, g, b), r + g + b - max(r, g, b) - min(r, g, b), min(r, g, b)


Input:
from queue import Queue

inf = 10 ** 20

def bfs(H, W, s):

    d = [[inf for i in range(W)] for j in range(H)]

    q = Queue()

    d[0][0] = 1

    q.put([0, 0])

    dx = (0, -1, 1, 0)

    dy = (-1, 0, 0, 1)

    while not q.empty():

        p = q.get()

        x = p[0]

        y = p[1]

        for i in range(4):

            nx = x + dx[i]

            ny = y + dy[i]

            if(nx >= 0 and nx < H and ny >= 0 and ny < W):

                if(s[nx][ny] == '.' and d[x][y] + 1 < d[nx][ny]):

                    d[nx][ny] = d[x][y] + 1

                    q.put([nx, ny])

    return d[H-1][W-1]

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

s = []

wnum = 0

for i in range(H):

    s.append(eval(input()))

    for j in range(W):

        if(s[i][j] == "."):

            wnum += 1

d = bfs(H, W, s)

if(d == inf):

    print("-1")

else:

    print((wnum - d))

# https://atcoder.jp/contests/abc088/tasks/abc088_d

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

s = [eval(input()) for _ in range(H)]

d = [[-1] * W for _ in range(H)]

# 0,0 to h-1, w-1

d[0][0] = 0

queue = []

queue.append([0, 0])

while len(queue) > 0:

    p = queue.pop(0)

    y, x = p[0], p[1]

    dx4 = [0, 0, 1, -1]

    dy4 = [1, -1, 0, 0]

    for dx, dy in zip(dx4, dy4):

        next_y = y + dy

        next_x = x + dx

        if 0 <= next_y < H and 0 <= next_x < W and s[next_y][next_x] != "#" and d[next_y][next_x] == -1:

            d[next_y][next_x] = d[y][x] + 1

            queue.append([next_y, next_x])

count = 0

for l in s:

    for c in l:

        if c == ".":

            count += 1

if d[H-1][W-1] == -1:

    print((-1))

else:

    print((count - d[H-1][W-1] - 1))

# [print(l) for l in s]

# [print(l) for l in d]

from queue import Queue

inf = 10**20

def bfs(H, W, s):
    d = [[inf for i in range(W)] for j in range(H)]
    q = Queue()
    d[0][0] = 1
    q.put([0, 0])
    dx = (0, -1, 1, 0)
    dy = (-1, 0, 0, 1)
    while not q.empty():
        p = q.get()
        x = p[0]
        y = p[1]
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if nx >= 0 and nx < H and ny >= 0 and ny < W:
                if s[nx][ny] == "." and d[x][y] + 1 < d[nx][ny]:
                    d[nx][ny] = d[x][y] + 1
                    q.put([nx, ny])
    return d[H - 1][W - 1]

H, W = list(map(int, input().split()))
s = []
wnum = 0
for i in range(H):
    s.append(eval(input()))
    for j in range(W):
        if s[i][j] == ".":
            wnum += 1
d = bfs(H, W, s)
if d == inf:
    print("-1")
else:
    print((wnum - d))

# https://atcoder.jp/contests/abc088/tasks/abc088_d
H, W = list(map(int, input().split()))
s = [eval(input()) for _ in range(H)]
d = [[-1] * W for _ in range(H)]
# 0,0 to h-1, w-1
d[0][0] = 0
queue = []
queue.append([0, 0])
while len(queue) > 0:
    p = queue.pop(0)
    y, x = p[0], p[1]
    dx4 = [0, 0, 1, -1]
    dy4 = [1, -1, 0, 0]
    for dx, dy in zip(dx4, dy4):
        next_y = y + dy
        next_x = x + dx
        if (
            0 <= next_y < H
            and 0 <= next_x < W
            and s[next_y][next_x] != "#"
            and d[next_y][next_x] == -1
        ):
            d[next_y][next_x] = d[y][x] + 1
            queue.append([next_y, next_x])
count = 0
for l in s:
    for c in l:
        if c == ".":
            count += 1
if d[H - 1][W - 1] == -1:
    print((-1))
else:
    print((count - d[H - 1][W - 1] - 1))
# [print(l) for l in s]
# [print(l) for l in d]

-    d = [[inf for i in range(W)] for j in range(H)]

-            if nx >= 0 and nx < H and ny >= 0 and ny < W:

+            and s[next_y][next_x] != "#"

+            and d[next_y][next_x] == -1

+            d[next_y][next_x] = d[y][x] + 1

+            queue.append([next_y, next_x])


Input:
import bisect

from scipy.sparse.csgraph import floyd_warshall as wf

INF = 10**20

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

s = [-INF]+[int(eval(input())) for _ in range(A)]+[INF]

t = [-INF]+[int(eval(input())) for _ in range(B)]+[INF]

for i in range(Q):

    q = int(eval(input()))

    b,d = bisect.bisect_right(s,q),bisect.bisect_right(t,q)

    ans = INF

    for S in [s[b-1],s[b]]:

        for T in [t[d-1],t[d]]:

            d1,d2 = abs(S-q)+abs(T-S),abs(T-q)+abs(S-T)

            ans = min(ans,d1,d2)

    print(ans)

import sys

import itertools

import math

from collections import deque

from collections import defaultdict

from itertools import permutations

import heapq

import bisect

from scipy.sparse.csgraph import floyd_warshall as wf

INF = 10**20

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

s = [-INF]+list(map(int, (sys.stdin.readline() for _ in [0]*A)))+[INF]

t = [-INF]+list(map(int, (sys.stdin.readline() for _ in [0]*B)))+[INF]

queries=list(map(int,sys.stdin))

for q in queries:

    b,d = bisect.bisect_right(s,q),bisect.bisect_right(t,q)

    ans = INF

    for S in [s[b-1],s[b]]:

        for T in [t[d-1],t[d]]:

            d1,d2 = abs(S-q)+abs(T-S),abs(T-q)+abs(S-T)

            ans = min(ans,d1,d2)

    print(ans)

import bisect
from scipy.sparse.csgraph import floyd_warshall as wf

INF = 10**20
A, B, Q = list(map(int, input().split()))
s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
for i in range(Q):
    q = int(eval(input()))
    b, d = bisect.bisect_right(s, q), bisect.bisect_right(t, q)
    ans = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - q) + abs(T - S), abs(T - q) + abs(S - T)
            ans = min(ans, d1, d2)
    print(ans)

import sys
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf

INF = 10**20
A, B, Q = list(map(int, input().split()))
s = [-INF] + list(map(int, (sys.stdin.readline() for _ in [0] * A))) + [INF]
t = [-INF] + list(map(int, (sys.stdin.readline() for _ in [0] * B))) + [INF]
queries = list(map(int, sys.stdin))
for q in queries:
    b, d = bisect.bisect_right(s, q), bisect.bisect_right(t, q)
    ans = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - q) + abs(T - S), abs(T - q) + abs(S - T)
            ans = min(ans, d1, d2)
    print(ans)

-s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]

-t = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]

+s = [-INF] + list(map(int, (sys.stdin.readline() for _ in [0] * A))) + [INF]

+t = [-INF] + list(map(int, (sys.stdin.readline() for _ in [0] * B))) + [INF]


Input:
from fractions import gcd

N = int(eval(input()))

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

a = sorted(A)

B = [a[0]]

C = []

for i in range(1,N):

    x = a[i]%a[0]

    if x != 0:

        B.append(x)

b =sorted(B)

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

    y = gcd(b[i],b[-1])

    C.append(y)

if len(b) == 1:

    print((b[0]))

else:

    print((min(C)))

from fractions import gcd

N = int(eval(input()))

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

mini = min(A)

ans = min(A)

for a in A:

    amari = a % mini

    if amari != 0:

        if amari < ans:

            ans = amari

if mini - ans == 0:

    print(ans)

else:

    print((gcd(mini, ans)))

from fractions import gcd

N = int(eval(input()))
A = list(map(int, input().split()))
a = sorted(A)
B = [a[0]]
C = []
for i in range(1, N):
    x = a[i] % a[0]
    if x != 0:
        B.append(x)
b = sorted(B)
for i in range(len(b) - 1):
    y = gcd(b[i], b[-1])
    C.append(y)
if len(b) == 1:
    print((b[0]))
else:
    print((min(C)))

from fractions import gcd

N = int(eval(input()))
A = list(map(int, input().split()))
mini = min(A)
ans = min(A)
for a in A:
    amari = a % mini
    if amari != 0:
        if amari < ans:
            ans = amari
if mini - ans == 0:
    print(ans)
else:
    print((gcd(mini, ans)))

-a = sorted(A)
-B = [a[0]]
-C = []
-for i in range(1, N):
-    x = a[i] % a[0]
-    if x != 0:
-        B.append(x)
-b = sorted(B)
-for i in range(len(b) - 1):
-    y = gcd(b[i], b[-1])
-    C.append(y)
-if len(b) == 1:
-    print((b[0]))
+mini = min(A)
+ans = min(A)
+for a in A:
+    amari = a % mini
+    if amari != 0:
+        if amari < ans:
+            ans = amari
+if mini - ans == 0:
+    print(ans)
-    print((min(C)))
+    print((gcd(mini, ans)))


Input:
from math import*

def solve(B):

    α=b*sin((90-B)*pi/180)/sin(B*pi/180)

    s=α*b/2

    if α>a:s-=(α-a)*(b-b*a/α)/2

    return s>=x/a

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

ok=0

ng=90

while ng-ok>1e-7:

    mid=(ok+ng)/2

    if solve(mid):ok=mid

    else:ng=mid

print(ok)

from math import*

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

print((atan(2*(b/a-x/a**3)if x>a**2*b/2else a*b**2/(2*x))/pi*180))

from math import *

def solve(B):
    α = b * sin((90 - B) * pi / 180) / sin(B * pi / 180)
    s = α * b / 2
    if α > a:
        s -= (α - a) * (b - b * a / α) / 2
    return s >= x / a

a, b, x = list(map(int, input().split()))
ok = 0
ng = 90
while ng - ok > 1e-7:
    mid = (ok + ng) / 2
    if solve(mid):
        ok = mid
    else:
        ng = mid
print(ok)

from math import *

a, b, x = list(map(int, input().split()))
print(
    (
        atan(2 * (b / a - x / a**3) if x > a**2 * b / 2 else a * b**2 / (2 * x))
        / pi
        * 180
    )
)


Input:
#素のPythonでは通りませんでしたが，PyPyを使ったら通りました

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

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

for i in range(K):

    table = [0 for _ in range(N*2)]

    # imos法 - メモ

    for j in range(N):

        ai = As[j]

        # 電球が照らす左端をメモ

        table[max((j-ai)*2-1, 0)] += 1

        # 電球が照らす右端をメモ

        table[min((j+ai)*2+1, N*2-1)] -= 1

    # imos法 - シミュレート

    for j in range(N*2):

        if j > 0:

            table[j] += table[j-1]

    # 答えになおす

    for j in range(N):

        As[j] = table[j*2]

    exit_condition = True

    for j in range(N):

        if As[j] != N:

            exit_condition = False

            break

    if exit_condition:

        print((*As))

        exit(0)

print((*As))

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

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

for i in range(K):

    #imos法(メモ)

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

    #数値がN個なのでN個の0の要素を作る

    #index0は空白、index1からx軸のランプがある位置に対応

    #1-Nまでのランプが格納されている

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

        ai = As[j-1]

        #電球jが照らす左端をメモ

        #電球jが照らす左端はj-aiなので、ここに１を足す

        table[max(j-ai, 1)] += 1

        #電球jが照らす右端をメモ

        #電球jが照らす右端はj+aiなので、この次の項に-1を加える

        if j+ai<N:

            table[min(j+ai+1, N)] -= 1

    #imos法(総和を求める)

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

        table[j] += table[j-1]

    #答えになおす

    for j in range(N):

        As[j] = table[j+1]

    exit_condition = True

    for j in range(N):

        if As[j] != N:

            exit_condition = False

            break

        #要素が全てNの時に、conditionはtrueのまま

    if exit_condition:

        print((*As))

        exit(0)#条件が正常に動作した時、ここで終了とさせる

print((*As))

# 素のPythonでは通りませんでしたが，PyPyを使ったら通りました
N, K = list(map(int, input().split()))
As = list(map(int, input().split()))
for i in range(K):
    table = [0 for _ in range(N * 2)]
    # imos法 - メモ
    for j in range(N):
        ai = As[j]
        # 電球が照らす左端をメモ
        table[max((j - ai) * 2 - 1, 0)] += 1
        # 電球が照らす右端をメモ
        table[min((j + ai) * 2 + 1, N * 2 - 1)] -= 1
    # imos法 - シミュレート
    for j in range(N * 2):
        if j > 0:
            table[j] += table[j - 1]
    # 答えになおす
    for j in range(N):
        As[j] = table[j * 2]
    exit_condition = True
    for j in range(N):
        if As[j] != N:
            exit_condition = False
            break
    if exit_condition:
        print((*As))
        exit(0)
print((*As))

N, K = list(map(int, input().split()))
As = list(map(int, input().split()))
for i in range(K):
    # imos法(メモ)
    table = [0 for _ in range(N + 1)]
    # 数値がN個なのでN個の0の要素を作る
    # index0は空白、index1からx軸のランプがある位置に対応
    # 1-Nまでのランプが格納されている
    for j in range(1, N + 1):
        ai = As[j - 1]
        # 電球jが照らす左端をメモ
        # 電球jが照らす左端はj-aiなので、ここに１を足す
        table[max(j - ai, 1)] += 1
        # 電球jが照らす右端をメモ
        # 電球jが照らす右端はj+aiなので、この次の項に-1を加える
        if j + ai < N:
            table[min(j + ai + 1, N)] -= 1
    # imos法(総和を求める)
    for j in range(1, N + 1):
        table[j] += table[j - 1]
    # 答えになおす
    for j in range(N):
        As[j] = table[j + 1]
    exit_condition = True
    for j in range(N):
        if As[j] != N:
            exit_condition = False
            break
        # 要素が全てNの時に、conditionはtrueのまま
    if exit_condition:
        print((*As))
        exit(0)  # 条件が正常に動作した時、ここで終了とさせる
print((*As))

-# 素のPythonでは通りませんでしたが，PyPyを使ったら通りました

-        # 電球が照らす左端をメモ

-        # 電球が照らす右端をメモ

-    # imos法 - シミュレート

+    # 数値がN個なのでN個の0の要素を作る

+    # index0は空白、index1からx軸のランプがある位置に対応

+    # 1-Nまでのランプが格納されている

+        # 電球jが照らす左端をメモ

+        # 電球jが照らす左端はj-aiなので、ここに１を足す

+        # 電球jが照らす右端をメモ

+        # 電球jが照らす右端はj+aiなので、この次の項に-1を加える

+            table[min(j + ai + 1, N)] -= 1

+        exit(0)  # 条件が正常に動作した時、ここで終了とさせる


Input:
MOD=10**9+7

def powmod(a,p):

  if p==0:

    return 1

  elif p==1:

    return a

  elif p%2==0:

    powsq=powmod(a,p//2)

    return (powsq**2)%MOD

  elif p%2==1:

    powsq=powmod(a,p//2)

    return (a*powsq**2)%MOD

def invmod(a):

  return powmod(a,MOD-2)

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

if (X+Y)%3!=0:

  print((0))

else:

  u=(2*X-Y)//3

  v=(-X+2*Y)//3

  if u>=0 and v>=0:

    #print(int(u),int(v))

    ui=int(u)

    vi=int(v)

    bunshi=1

    for i in range(vi):

      bunshi*=ui+vi-i

      bunshi%=MOD

    bumbo=1

    for i in range(vi):

      bumbo*=vi-i

      bumbo%=MOD

    #calculate bunshi/bumbo%MOD as bunshi*bumbo^-1%MOD

    print((bunshi*invmod(bumbo)%MOD))

  else:

    print((0))

MOD=10**9+7

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

def powmod(a,p):

  if p==0:

    return 1

  elif p==1:

    return a

  else:

    pow2=powmod(a,p//2)

    if p%2==0:

      return (pow2**2)%MOD

    else:

      return (a*pow2**2)%MOD

def invmod(a):

  return powmod(a,MOD-2)

def comb_mod(n,r):

  nPr=1

  fact_r=1

  for i in range(r):

    nPr*=n-i

    nPr%=MOD

    fact_r*=r-i

    fact_r%=MOD

  return (nPr*invmod(fact_r))%MOD

if (X+Y)%3!=0:

  print((0))

else:

  u=(2*X-Y)//3

  v=(-X+2*Y)//3

  if u>=0 and v>=0:

    #print(u,v)

    print((comb_mod(u+v,v)))

  else:

    print((0))

MOD = 10**9 + 7

def powmod(a, p):
    if p == 0:
        return 1
    elif p == 1:
        return a
    elif p % 2 == 0:
        powsq = powmod(a, p // 2)
        return (powsq**2) % MOD
    elif p % 2 == 1:
        powsq = powmod(a, p // 2)
        return (a * powsq**2) % MOD

def invmod(a):
    return powmod(a, MOD - 2)

X, Y = list(map(int, input().split()))
if (X + Y) % 3 != 0:
    print((0))
else:
    u = (2 * X - Y) // 3
    v = (-X + 2 * Y) // 3
    if u >= 0 and v >= 0:
        # print(int(u),int(v))
        ui = int(u)
        vi = int(v)
        bunshi = 1
        for i in range(vi):
            bunshi *= ui + vi - i
            bunshi %= MOD
        bumbo = 1
        for i in range(vi):
            bumbo *= vi - i
            bumbo %= MOD
        # calculate bunshi/bumbo%MOD as bunshi*bumbo^-1%MOD
        print((bunshi * invmod(bumbo) % MOD))
    else:
        print((0))

MOD = 10**9 + 7
X, Y = list(map(int, input().split()))

def powmod(a, p):
    if p == 0:
        return 1
    elif p == 1:
        return a
    else:
        pow2 = powmod(a, p // 2)
        if p % 2 == 0:
            return (pow2**2) % MOD
        else:
            return (a * pow2**2) % MOD

def invmod(a):
    return powmod(a, MOD - 2)

def comb_mod(n, r):
    nPr = 1
    fact_r = 1
    for i in range(r):
        nPr *= n - i
        nPr %= MOD
        fact_r *= r - i
        fact_r %= MOD
    return (nPr * invmod(fact_r)) % MOD

if (X + Y) % 3 != 0:
    print((0))
else:
    u = (2 * X - Y) // 3
    v = (-X + 2 * Y) // 3
    if u >= 0 and v >= 0:
        # print(u,v)
        print((comb_mod(u + v, v)))
    else:
        print((0))

+    return (nPr * invmod(fact_r)) % MOD

-        # calculate bunshi/bumbo%MOD as bunshi*bumbo^-1%MOD

-        print((bunshi * invmod(bumbo) % MOD))


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

cnt = 0

for x in range(K + 1):

    for y in range(K + 1):

        if x + y > S:

            continue

        z = S - x - y

        if z <= K:

            cnt += 1

print(cnt)

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

ans = 0

for i in range(K + 1):

    for j in range(K + 1):

        k = S - i - j

        if K >= k >= 0:

            ans += 1

print(ans)

K, S = list(map(int, input().split()))
cnt = 0
for x in range(K + 1):
    for y in range(K + 1):
        if x + y > S:
            continue
        z = S - x - y
        if z <= K:
            cnt += 1
print(cnt)

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

-cnt = 0
-for x in range(K + 1):
-    for y in range(K + 1):
-        if x + y > S:
-            continue
-        z = S - x - y
-        if z <= K:
-            cnt += 1
-print(cnt)
+ans = 0
+for i in range(K + 1):
+    for j in range(K + 1):
+        k = S - i - j
+        if K >= k >= 0:
+            ans += 1
+print(ans)