# This is simple recurrence that we had learnt that is
# let S(n) be the number of bills for getting the money out
# then recurrence is
# s(n)=1+min(S(n-1),S(n-5),S(n-10),S(n-20),S(n-100))
# memoization
# lst conatins list where for each index we have its min bill stores

#  we do this problem iterative
import sys

def hitLotery(n):
	lst=[-1 for i in range (n+1)]
	# base case
	lst[0]=0
	i=1
	while(i<len(lst)):
		# induction hypothesis

		b1=lst[i-1]
		if(i-5>=0):
			b2=lst[i-5]
		else:
			b2=sys.maxsize

		if(i-10>=0):
			b3=lst[i-10]
		else:
			b3=sys.maxsize
		if(i-20>=0):
			b4=lst[i-20]
		else:
			b4=sys.maxsize
		if(i-100>=0):
			b5=lst[i-100]
		else:
			b5=sys.maxsize

		# now we have got the previous valuies thus
		# induction step
		lst[i]=1+min(b1,b2,b3,b4,b5)
		i=i+1

	return(lst[n])

n=int(input())
print(hitLotery(n))


from math import inf

n = int(input())

bills = [1, 5, 10, 20, 100]
dp = [0]

for i in range(1, n+1):
    dp.append(inf)

for i in range(1, n+1):
    for bill in bills:
        if i - bill >= 0:
            dp[i] = min(dp[i], dp[i-bill]) + 1

print(dp[n])


n = int(input())

coins = [1, 5, 10, 20, 100]

dp = [float("inf") for _ in range(n + 1)]
dp[0] = 0

for i in range(1, n + 1):
    candidates = [dp[i - k] + 1 for k in coins if i >= k]
    dp[i] = min(
        candidates
    )
print(dp[n])


f = list(map(int, input().split()))
w = f[0]
h = f[1]
n = f[2]
s = 0
d = 2
for i in range(n):
s = s + (w + h - d)*2
d = d + 8
print(s)


x, y = map(int, input().split())
n = int(input())
m = 1000000007
if n == 1:
    print(x % m)
    quit()
if n == 2:
    print(y % m)
    quit()
f = [x, y]
for i in range(2, n+1):
    k = (f[i-1] % m-f[i-2] % m) % m
    f.append(k)
print(f[n-1])


x,y=map(int,input().split())
n=int(input())
l=[]
l.append(0)
l.append(x)
l.append(y)
i=3
while(i<=n):
    x=l[i-1]-l[i-2]
    l.append(x)
    i=i+1
print(l[len(l)-1]%1000000007)


# n = int(input())
# arr = list(map(int, input().split()))
# n,m=map(int,input().split())
# n, m, k = map(int, input().split())
# arr = list(map(int, input().split()))
# ls = list(map(int, input().split()))
x,y=map(int,input().split())
n = int(input())
ls=[x,y]
if n>=3:
    for i in range(2, n):
        val = ls[i - 1] + ls[i - 2] * -1
        ls.append(val)
    print(ls[n - 1] % 1000000007)
else:
    print(ls[n-1]%1000000007)


string = input().split(' ')
n = int(string[0])
pos = int(string[1])
a = int(string[2])
b = int(string[3])

if b==n and a==1:
	print(0)
elif b==n and a!=1:
	if pos>=a:
		print(pos-a+1)
	else:
		print(a-pos+1)
elif a==1 and b!=n:
	if pos<=b:
		print(b-pos+1)
	else:
		print(pos-b+1)
else:
	if pos<=a:
		print(b-pos+2)
	elif pos>=2
		print(pos+2-a)
	else:
		res_left=pos-2*a+2+b
		res_right=2*b-pos+2-a
		print(min(res_left, res_right))


import math

n = int(input())

def prime_factors(n):
    factors = set()
    d = 2
    while d * d <= n:
        while (n % d) == 0:
            factors.add(d)  # supposing you want multiple factors repeated
            n //= d
        d += 1
    if n > 1:
       factors.add(n)
    return factors

factors = prime_factors(n)

if len(factors) > 1:
    print(1)
else:
    print(factors.pop())


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


def func(x,limit):
    while True:
        if(x < 0):
            x = -x
        elif (x > limit):
            x = 2.0*limit - x
        else:
            return x
text = raw_input()
a,b,m = map(int,text.split())
text = raw_input()
vx,vy,vz = map(int,text.split())
dx = a/2.0 + (m*1.0/-vy)*vx
dz = (m*1.0/-vy)*vz
print dx,dz
dx = func(dx,a)
dz = func(dz,b)
print "%.6f %.6f" % (dx,dz)


v = None
def draka(v):
  global v1, v2, v3, v4
  v1, v2, v3, v4 = v[0], v[1], v[2], v[3]
  for i in v:
    if i < 0:
      return 'NEGATIVE'
    if v3 == 0:
      return 'POINT'
  if v1 + v2 > v3 or v2 + v3 > v4:
    return 'TRIANGLE'
  elif v1 + v2 == v3 or v2 + v3 == v4:
    return 'SEGMENT'
  else:
    return 'IMPOSSIBLE'
while v = None:
  v = input().split(' ')
  v = sorted(v)
  v = [int(v) for v in v]
  print(draka(v))


n,k=map(int,raw_input().split(" "))
l1=[]
l1=list(map(int,raw_input().split(" ")))[:n]
b=l1[k-1]
c=0
for j in range(len(l1)):
    if l1[j]>=b and l[j]>0:
        c=c+1
print(c)


a='1000'
b='0101'
a=raw_input()
b=raw_input()
for s in range(len(a)):
    if a[s]==b[s]:
        sys.stdout.write(0)
    if a[s]<>b[s]:
        sys.stdout.write(1)
#sbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb


n, d = map(int, raw_input().split())
t = map(int, raw_input().split())

print -1 if (d-sum(t))/(len(t)-1)<10 else (d-sum(t))/5


n = input()
k = input()
i = 1
res = 240 - int(k)
sum = 0
c = 0
while (i <= int(n)):
    sum += 5 * i
    if sum > res:
        break
    c += 1
    i += 1
print(c)


def ret_input():
    n_k = [int(x) for x in raw_input().split()]
    return n_k

def primes_sieve(limit):
    limitn = limit+1
    primes = range(2, limitn)

    for i in primes:
        factors = range(i, limitn, i)
        for f in factors[1:]:
            if f in primes:
                primes.remove(f)
    return primes

def gen_factor_list(data):
    n = data[0]
    k = data[1]
    ans = []
    for x in xrange(k-1):
        first = primes_sieve(n)[0]
        ans.append(first)
        n = n / first
    ans.append(n)
    return ans

def product(faclist):
    p = 1
    for item in faclist:
        p *= item
    return p

def return_prod(prod, n, fac):
    if prod <> n:
        return '-1'
    else:
        return strlist(fac)

def strlist(fac):
    ansfin = []
    for item in fac:
        ansfin.append(str(item))
    return " ".join(ansfin)

def main():
    data = ret_input()
    #data = [5,1]
    fac = gen_factor_list(data)
    prod = product(fac)
    print return_prod(prod, data[0],fac)

if __name__ == '__main__':
    main()


import sys
from math import *

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

n = int(minp())
m = [None]*n
k = [None]*3
dp = [None]*3
dp[0] = [None]*(n*n)
dp[1] = [None]*(n*n)
dp[2] = [None]*(n*n)
path = [None]*(n*n)
for i in range(n):
	m[i] = list(map(int, minp().split()))
	for j in range(n):
		path[m[i][j]-1] = (i,j)
for z in range(3):
	k_ = [None]*n
	for i in range(n):
		kk = [None]*n
		for j in range(n):
			kkk_ = [None]*3
			for zz in range(3):
				kkk = [None]*n
				for w in range(n):
					kkk[w] = [(1000000,0)]*n
				kkk_[zz] = kkk
			kk[j] = kkk_
		k_[i] = kk
	k[z] = k_

q = [0]*(10*n*n)
qr = 0
km = [(1,2),(1,-2),(-1,2),(-1,-2),(2,1),(2,-1),(-2,1),(-2,-1)]
sm = [(1,1),(1,-1),(-1,1),(-1,-1)]
lm = [(0,1),(0,-1),(-1,0),(1,0)]
mm = [km,sm,lm]
for z in range(3):
	for i in range(n):
		for j in range(n):
			#print('========')
			ql = 0
			qr = 1
			q[0] = (z, i, j, (0,0))
			kc = k[z][i][j]
			kc[z][i][j] = (0, 0)
			while ql < qr:
				t, x, y, dd = q[ql]
				#print(t,x,y,dd)
				d = kc[t][x][y]
				ql += 1
				if d != dd:
					continue
				dd = (d[0]+1, d[1]+1)
				for tt in range(3):
					if t != tt and kc[tt][x][y] > dd:
						kc[tt][x][y] = dd
						q[qr] = (tt,x,y,dd)
						qr += 1
				dd = (d[0]+1,d[1])
				if t == 0:
					for w in mm[t]:
						xx,yy = w[0]+x,w[1]+y
						if xx >= 0 and xx < n and yy >= 0 and yy < n:
							if kc[t][xx][yy] > dd:
								kc[t][xx][yy] = dd
								q[qr] = (t,xx,yy,dd)
								qr += 1
				else:
					for w in mm[t]:
						for hm in range(n*2):
							xx,yy = w[0]*hm+x,w[1]*hm+y
							if xx >= 0 and xx < n and yy >= 0 and yy < n:
								if kc[t][xx][yy] > dd:
									kc[t][xx][yy] = dd
									q[qr] = (t,xx,yy,dd)
									qr += 1
							else:
								break
dp[0][0] = (0,0)
dp[1][0] = (0,0)
dp[2][0] = (0,0)
for i in range(0,n*n-1):
	x,y = path[i]
	xx,yy = path[i+1]
	for z in range(3):
		for j in range(3):
			dist = k[z][x][y][j][xx][yy]
			if dp[j][i] != None:
				nd = (dp[j][i][0]+dist[0],dp[j][i][1]+dist[1])
				if dp[z][i+1] == None:
					dp[z][i+1] = nd
				else:
					dp[z][i+1] = min(dp[z][i+1],nd)
for j in range(n*n-1,n*n):
	qq = [dp[i][j] if dp[i][j] != None else (1000000,0) for i in range(3)]
	qm = min(qq)
	#print(j,qm)
	print(qm[0], qm[1])


n=int(input())
lookup={}
for i in range(n):
    x=list(map(int,input().split()))
    for j in range(n):
        lookup[x[j]]=(i,j)
bestrook=[0,0]
bestbish=[0,0]
bestknight=[0,0]
for i in range(1,n**2):
    x=abs(lookup[i][0]-lookup[i+1][0])
    y=abs(lookup[i][1]-lookup[i+1][1])
    if x==0 or y==0:
        bestrook[0]+=1
    else:
        bestrook[0]+=2
    if x==y:
        bestbish[0]+=1
    elif (x-y)%2==0:
        bestbish[0]+=2
    else:
        bestbish[0]+=1000
    if {x,y}=={1,2}:
        bestknight[0]+=1
    elif x**2+y**2 in [4,16,20,10,18]:
        bestknight[0]+=2
    elif x**2+y**2==2 and lookup[i] not in [(0,0),(n-1,0),(0,n-1),(n-1,n-1)] and lookup[i+1] not in [(0,0),(n-1,0),(0,n-1),(n-1,n-1)]:
        bestknight[0]+=2
    elif {x,y} in [{5,0},{3,0},{1,0},{6,1},{4,1},{5,2},{3,2},{6,3},{4,3},{5,4}]:
        bestknight[0]+=3
    else:
        bestknight[0]+=1000
    bestrook[0]=min(bestrook[0],bestbish[0]+1,bestknight[0]+1)
    bestbish[0]=min(bestrook[0]+1,bestbish[0],bestknight[0]+1)
    bestknight[0]=min(bestrook[0]+1,bestbish[0]+1,bestknight[0])
best=(bestrook[0],bestbish[0],bestknight[0])
if min(best)==best[0]:
    print(bestrook[0],bestrook[1])
elif min(best)==best[1]:
    print(bestbish[0],bestbish[1])
else:
    print(bestknight[0],bestknight[1])


import collections
mem = {}

def f(s,t,i,a,k):

	if t[0] == t[1]:
		cc = collections.Counter(s)
		p = cc[t[0]]
		p += min(k,len(s) - p)
		return p * (p-1)/2
	ans = 0
	if (i,k,a) in mem:return mem[(i,k,a)]
	if i == len(s):
		return 0
	c = (1 if s[i] != t[0] else 0)
	if k - c >= 0:
		ans = max(ans, f(s,t,i + 1, a + 1, k - c))
	c = (1 if s[i] != t[1] else 0)
	if k - c  >= 0:
		ans = max(ans, f(s,t,i + 1, a, k - c) + a)
	ans = max(ans, f(s,t,i+1,a,k))
	mem[(i,k,a)] = ans
	return ans
n,k = map(int, raw_input().split())
print f(raw_input(),raw_input(),0,0,k)


l=[]
for i in range(11):
      l.append(input())
      if "x" in l[i]:
x,y=map(int,input().split())
if x>=4 and x<=6:
      x-=3
elif x>=7:
      x-=6
if y>=4 and y<=6:
      y-=3
elif y>=7:
      y-=6
if x==1:
      p=0
elif x==2:
      p=4
elif x==3:
      p=8
if y==1:
      p2=0
elif y==2:
      p2=4
elif y==3:
      p2=8
com=0
for i in range(p,p+3):
      for j in range(p2,p2+3):
            if l[i][j]=='.':
                  com+=1
if com==0:
      for i in (0,1,2,4,5,6,8,9,10):
            if i ==4 or i==8:
                  print()
            for j in range(11):
                  if l[i][j]=='.':
                        print("!",end="")
                  else:
                        print(l[i][j],end="")
            print()
else:
      for i in (0,1,2,4,5,6,8,9,10):
            if i==4  or i==8:
                  print()
            for j in range(11):
                  if i>=p and i < p+3 and j >= p2 and j < p2+3:
                        if l[i][j]=='.':
                              print("!",end="")
                        else:
                              print(l[i][j],end="")
                  else:
                        print(l[i][j],end="")
            print()


def get_day_number(s):
	if s == 'monday':
		return 1
	elif s == 'tuesday':
		return 2
	elif s == 'wednesday':
		return 3
	elif s == 'thursday':
		return 4
	elif s == 'friday:
		return 5
	elif s == 'saturday':
		return 6
	elif s == 'sunday':
		return 7

first_day = get_day_number(input())
second_day = get_day_number(input())
if (second_day - first_day) % 7 in {0, 3, 2}:
	print('YES')
else:
	print('NO')


from sys import stdin, stdout
from collections import Counter, defaultdict
pr=stdout.write
import heapq
raw_input  = stdin.readline
def ni():
    return int(raw_input())

def li():
    return list(map(int,raw_input().split()))

def pn(n):
    stdout.write(str(n)+'\n')

def pa(arr):
    pr(' '.join(map(str,arr))+'\n')

# fast read function for total integer input

def inp():
    # this function returns whole input of
    # space/line seperated integers
    # Use Ctrl+D to flush stdin.
    return (map(int,stdin.read().split()))

range = xrange # not for python 3.0+

# main code

fac=[1]*1005
mx=1005
mod=998244353
for  i in range(1,mx):
    fac[i]=(fac[i-1]*i)%mod
def inv(x):
    return pow(x,mod-2,mod)
def ncr(n,r):
    num=fac[n]
    den=(fac[r]*fac[n-r])%mod
    return (num*inv(den))%mod
def fun(x,y):
    ans=0
    for i in range(min(x,y)+1):
        ans=(ans+(fac[i]*ncr(x,i)*ncr(y,i))%mod)%mod
    return ans
a,b,c=li()
pn((fun(a,b)*fun(b,c)*fun(a,c))%mod)


def num(n):
    return ('7'*((n)//2)+'4'*((n)//2))
def lucky(n):
    c4=0
    c7=0
    for i in str(n):
        if(i=='4'):
            c4+=1
        elif(i=='7'):
            c7+=1
        else:
            return False
    if(c4==c7):
        return True
    return False

s=input()
c4=0
c7=0
n=len(s)
ans=''
if(len(s)%2==1):
    print('4'*((n+1)//2)+'7'*((n+1)//2))
    exit()
if(int(s)>int(num(n))):
    print(num(n+2)[::-1])
    exit()
ans=int(s)
while(True):
    if(lucky(ans)):
        print(ans)
        break
    ans+=1


from sys import stdin, stdout
# kr,kb,ky,kg

garland = list(stdin.readline()[:-1])
disabed = garland.count('!')

kr, kb, ky, kg = 0, 0, 0, 0
control = set(['R', 'G', 'B', 'Y'])

def format_answer():
    return str(kr) + ' ' + str(kb) + ' ' + str(ky) + ' ' + str(kg) + '\n'

def get_nei(garland, index):
    nei = set()
    left_index = 0 if index < 4 else index - 3
    right_index = len(garland) - 1 if index > len(garland) - 4 else index + 3
    for nei_index in range(left_index, right_index + 1):
        if not index == nei_index and garland[nei_index] != '!':
            nei.add(garland[nei_index])
    return nei

neighbours = {}

while disabed:

    for index in range(len(garland)):
        if garland[index] == '!':
            nei = get_nei(garland, index)
            diff = control.difference(nei)
            if len(diff) == 1:
                color = diff.pop()
                if color == 'R':
                    garland[index] = 'R'
                    kr += 1
                if color == 'B':
                    garland[index] = 'B'
                    kb += 1
                if color == 'G':
                    garland[index] = 'G'
                    kg += 1
                if color == 'Y':
                    garland[index] = 'Y'
                    ky += 1
                disabed -= 1

stdout.write(format_answer())


s = list(input())
r = b = y = g = 0
while '!' in s:
    for i in range(len(s)):
        if s[i] == '!':
            t1 = s[i:i+4]
            t2 = s[i-3:i+1]
            t3 = s[i-1:i+3]
            t4 = s[i-2:i+2]

            if not t2:  t2 = s[:i+1]
            if not t3:  t3 = s[:i+3]
            if not t4:  t4 = s[:i+3]

            if t1.count('!') == 1 and len(t1) == 4:     l = t1[:]
            elif t2.count('!') == 1 and len(t2) == 4:   l = t2[:]
            elif t3.count('!') == 1 and len(t3) == 4:   l = t3[:]
            elif t4.count('!') == 1 and len(t4) == 4:   l = t4[:]
            else:   continue

            if 'R' not in l:
                s[i] = 'R'
                r+=1
            elif 'Y' not in l:
                s[i] =  'Y'
                y+=1
            elif 'B' not in l:
                s[i] =  'B'
                b+=1
            else:
                s[i] =  'G'
                g+=1

print(r,b,y,g,sep=' ')


n,m=map(int,raw_input().split())
s=1
M=10**9+9
for i in range(1,n+1):
    s*=2**m-i
    s%=M
print s


for q in range(int(input())):
    k,n,a,b = map(int,input().split())
    temp = n
    flag = True
    while n>=0:
        if (n*a)+((temp-n)*b) < k:
            print(n)
            flag = False
            break
        n -= 1
    if flag:
        print("-1")


import sys
from collections import deque

n, x, y = map(int, input().split())
ans = 0
dq_cost = deque()
dq_index = deque()

for i in range(1, n+1):
    ans += x
    while dq_index and dq_index[0] < i:
        dq_cost.popleft()
        dq_index.popleft()
    if dq_cost:
        ans = min(ans, dq_cost[0] - i*x)

    ycost = ans + y + x*(i*2)
    while dq_cost and dq_cost[-1] > ycost:
        dq_cost.pop()
        dq_index.pop()

    dq_cost.append(ycost)
    dq_index.append(i*2)

print(ans)


from math import gcd
a,b,c,d=[int(i) for i in input(),split()]
g=gcd(c,d)
c//=g
d//=g
e=min(a//c,b//d)
print(e*c,e*d)


N=raw_input()
if 7*'1' in N or 7*'0' in n:
    print 'YES'
else:
    print 'NO'


k1, k2, k3 = input().strip().split()
k1, k2, k3 = int(k1), int(k2), int(k3)

nums = list(range(20))
global_flag = False
for t1 in range(k1):
    for t2 in range(k2):
        for t3 in range(k3):
            flag = [False for x in range(max(t1, t2, t3), len(nums))]
            for n in range(max(t1, t2, t3), len(nums)):
                if (n - t1) % k1 == 0 or (n - t2) % k2 == 0 or \
                   (n - t3) % k3 == 0:
                    flag[n - max(t1, t2, t3)] = True
            if all(flag):
                global_flag = True

if global_flag:
    print ('YES')
else:
    print ('NO')


import math
def lcm(a,b):
    return (a*b//(math.gcd(a,b)));
a=int(input())
if(a==1):
    print(1)
    exit()
if(a==2):
    print(2)
    exit()
if(a==3):
    print(6)
    exit()
if(a%2==1):
    print(a*(a-1)*(a-2))
    exit()
else:
    r=lcm(lcm(n,n-1),n-2)
    m=lcm(lcm(n-1,n-2),n-3)
    print(max(r,m))


# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
import sys
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output.txt','w')
input=sys.stdin.readline
# sys.setrecursionlimit(300010)
MOD = 1000000007
MOD2 = 998244353
ii = lambda: int(input().strip('\n'))
si = lambda: input().strip('\n')
dgl = lambda: list(map(int,input().strip('\n')))
f = lambda: map(int, input().strip('\n').split())
il = lambda: list(map(int, input().strip('\n').split()))
ls = lambda: list(input().strip('\n'))
let = 'abcdefghijklmnopqrstuvwxyz'
d=dict()
sieve=[1]*(1000005)
for i in range(2,10**6+4):
    if sieve[i]:
        d[i]=[i]
        for j in range(i*2,10**6+4,i):
            if j in d:
                d[j].append(i)
            else:
                d[j]=[i]
            sieve[j]=0
n=ii()
ans=set(d[n])
cnt=[n]
for i in range(n-1,-1,-1):
    if any(i in ans for i in d[i]):
        continue
    else:
        ans=ans.union(d[i])
        cnt.append(i)
    if len(cnt)==3:
        break
prod=1
for i in cnt:
    prod*=i
print(prod)


x=int(input())
y=int(input())
if x>y:
    if (y-x)%2==0:
        print("No")
    else:
        print("Yes")
else:
    if y-x==1:
        print("Yes")
    else:
        print("No")


# cook your code here
n,k=map(int,raw_input().split(' '))
if(n<k):
    print('NO')
    exit()
if(n==k):
    print('YES')
    exit()
game=['NO' for i in xrange(n+1)]
game[k]='YES'
for i in range(k+1,n+1):
    if game[i-k]=='YES':
        game[i]='NO'
    else:
        game[i]='YES'
print(game[n])


lis = ['A','E','I','O','U','Y']
s = input(); c = []
for i in range(len(s)):
    if s[i] in lis:
        for j in range(i+1,len(s)):
            if s[j] in lis:
                c.append(j-i)
                break
print(max(c))


a,b,c,n = map(int,input().split())
d = n-(max((a-c),(c-a))+max((b-c),(c-b))+c)
if c>a or c>b or d==0 or n=0:
    print('-1')
else:
    print(d)


def getOverlap(a0, a1, b0, b1):
    return max(0, min(a1, b1) - max(a0, b0)+1)

def b():
	s1,e1,t1 = list(map(int, input().split(" ")))
	s2,e2,t2 = list(map(int, input().split(" ")))
	period = t1*t2
	maxint = 0
	maxmax = min(e1-s1, e2-s2)+1
	n = 0
	while s1 < period:
		while n*t2 < s1 - e2: n+=1
		s2 += n*t2
		e2 += n*t2
		while s2 < period:
			x = getOverlap(s1, e1, s2, e2)
			#print(">15", s1, e1, s2, e2, x)
			if x > maxint:
				maxint = x
				if maxmax == maxint:
					print(maxint)
					raise SystemExit()
			if s2 > e1: break
			s2+=t2
			e2+=t2
		s2%=t2
		e2%=t2
		s1+=t1
		e1+=t1
	print(maxint)

b()


import math

def gcd(a, b):
    """Returns the greatest common divisor of a and b.
    Should be implemented using recursion.

    >>> gcd(34, 19)
    1
    >>> gcd(39, 91)
    13
    >>> gcd(20, 30)
    10
    >>> gcd(40, 40)
    40
    """
    if b > a:
        return gcd(b, a)

    if a % b == 0:
        return b

    return gcd(b, a % b)

(la, ra, ta) = [int(s) for s in input().split(" ")]
(lb, rb, tb) = [int(s) for s in input().split(" ")]

delta = gcd(ta, tb)

def overlap(al, ar, bl, br):
    return max(0, min(ar, br) - max(al, bl) + 1)

def eval(fst_, snd_):
    result_ = 0

    pos_sndl = snd_[0]
    pos_sndr = snd_[1]
    pos_fstl = fst_[0]
    pos_fstr = fst_[1]
    intersection = overlap(pos_sndl, pos_sndr, pos_fstl, pos_fstr)
    result_ = max(result_, intersection)
    # print(delta)
    # print(intersection)
    snd_k = abs(snd_[1] - fst_[0]) // delta + 1
    fst_k = 0 if intersection != 0 else max(abs(snd_[0] - fst_[1]) // delta -1, 0)

    for k in range(fst_k, snd_k):
        pos_sndl = snd_[0]
        pos_sndr = snd_[1]
        pos_fstl = k * delta + fst_[0]
        pos_fstr = k * delta + fst_[1]
        intersection = overlap(pos_sndl, pos_sndr, pos_fstl, pos_fstr)
        # print(intersection)
        # print(pos_sndl, pos_sndr, pos_fstl, pos_fstr, intersection)
        result_ = max(result_, intersection)

    return result_

fst_ = (la, ra, ta)
snd_ = (lb, rb, tb)

result = max(eval(fst_, snd_), eval(snd_, fst_))
print(result)


import math
n,m=map(int, input().split())
packages=list(map(int, input().split()))
total = {}
for i in packages:
    if i not in total.keys():
        total[i] = 1
    else:
        total[i] += 1

dict_sort = sorted(total.items(), key=lambda kv: kv[1], reverse=True)

start, end, mid, ret = 0, len(dict_sort), 0, 0
while start < end:
    c = 0
    mid = math.floor((start + end) / 2)
    for i in range(len(dict_sort)):
        c += math.floor(dict_sort[i][1] / mid)
    if c >= n:
        start = mid + 1
        ret = mid
    else:
        end = mid-1
print(ret)


col,row = raw_input().split()
row = int(row)
count = 0
for i in range(-1,2,1):
    for j in range(-1,2,1):
        if row+i >=1 and row+i <=8 and ord(col)+j >= ord('a') and ord(col)+j <= ord('ag') and not (row+i ==row and col+i == col):
            count += 1
print count


N = int(input())
i, ans = 1, 0
while True:
	sum += (i*(i+1))/2
	if sum <= N: ans += 1
	if sum >= N: break
	i += 1
print ans


s = input()
flag = 0
for i in range (0,s.len())
    if(s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u' or s[i]=='y') :
        flag=1
    elif(s[i]=='A' or s[i]=='E' or s[i]=='I' or s[i]=='O' or s[i]=='U' or s[i]=='Y'):
        flag=1
    elif((s[i]>='a' and s[i]<='z') or(s[i]>='A' && s[i]<='Z')) :
        flag=0
if(flag):
    print("YES")
else :
    print("NO")


n,m,k=map(int,input().split())
a=list(map(int,input().split()))
m-=1
left=m-1
right=m+1
while True:
    if left>=0:
        if a[left]<k and a[left]>0:
            x=left
            break
        else:
            left-=1
    elif right<n:
        if a[right]<k and a[right]>0:
            x=right
            break
        else:
            right+=1
print((abs(m-x))*10)


z,zz=input,lambda:list(map(int,z().split()))
zzz=lambda:[int(i) for i in stdin.readline().split()]
szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac
def lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2))
def prime(x):
    p=ceil(x**.5)+1
    for i in range(2,p):
        if (x%i==0 and x!=2) or x==0:return 0

    return 1
def dfs(u,visit,graph):
    visit[u]=True
    for i in graph[u]:
        if not visit[i]:
            dfs(i,visit,graph)

###########################---Test-Case---#################################
"""

"""
###########################---START-CODING---##############################

a,b=zz()

c=b
if b>=a:
    print(a)
    exit()
for i in range(2,n-v+1):
    c+=i
print(c)


raw_input()
x = sorted(map(int,raw_input().split()))
def solve(x,rm,nx,ins):
    if nx == len(x):
        if rm == 2:
            return ins
        return float("inf")
    if nx == len(x)-1:
        if rm == 1:
            return ins
        return float("inf")
    return min(solve(x,rm+1,nx+1,ins),solve(x,rm,nx+2,ins+x[nx+1]-x[nx]))
print solve(x,0,0,0)


import bisect
n,m,k=list(map(int,input().split()))
l=[0]+list(map(int,input().split()))
l.sort()
z=k
x=m
c=0
while m>k and k>0:
    i=bisect.bisect(l,m)
    m=m-l[i-1]
    k=k-1
    c=c+1

if k==0 and m>0:
    c=0
    while z>0:
        z=z-1
        while x>z and i>1:
            i=bisect.bisect(l,x)
            x=x-l[i-1]+1
            c=c+1
    if z==0 and x>0:
        print(-1)
    else:
        print(c)

else:
    print(c)


arg = raw_input().split()

n = int(arg[0])
x = int(arg[1])

a = [0] * n
for i in range(n):
    a[i] = [0] * n
sum = 0
for i in range(n):
    for j in range(n):
        if ((i + 1) * (j + 1)) == x:
            sum += 1
print sum


n,m,k=map(int,input().split())
a,b=map(int,input().split())
p=[]
for i in range(1,n+1):
    p.append(i*m*k)
it=[[0]*n for i in range(m)]
for i in range(m):
    for j in range(n):
        it[i][j]=j*m*k+k*(i+1)
fl1=True
fl2=True
for i in range(n):
    for j in range(m):
        if it[j][i]-a>=0 and fl1:
            p1=i+1
            it1=j+1
            fl1=False
        if it[j][i]-b>=0 and fl2:
            p2=i+1
            it2=j+1
            fl2=False
        if not fl1 and not fl2:
            break
if p1!=p2:
    t1=min(it1-1+10,5*(it1-1))
    s1=p1
    t21=0
    while s1!=p2:
        s1+=1
        t21+=1
        if s1>n:
            s1//=n
    t21*=15
    t2=min(t21,(abs(p2-p1))*15)
    t3=min(it2-1+10,5*(it2-1))
    t=t1+t2+t3
    print(t)
else:
    t=min(abs(it2-it1)*5,10+abs(it2-it1))
    print(t)


n = int(raw_input())
def get_facs(n):
	n1 = n
	facs = []
	i = 2
	while i*i <= n1:
		if n1 % i == 0:
			facs.append([i, 0])
			while n1 % i == 0:
				facs[-1][1] += 1
				n1 /= i
		i += 1
	if n1 > 1:
		facs.append([n1, 1])
	return facs

def sep(x, a, i=1):
	# seperate x into 3 piece x1,x2,x3, x2 <= x3, xi >= 1
	if i==3:
		a[2] = x - a[0] - a[1]
		if a[2] >= 0 and a[2] <= x:
			yield a
		return
	for xi in xrange(0, x+1):
		a[i-1] = xi
		for y in sep(x, a, i+1):
			yield y
		a[i-1] = 0

max_n, min_n = 0, n*n*n

def extract(chs, facs):
	ans = [1] * 3
	for i,(fac,c) in enumerate(facs):
		for j in xrange(3):
			ans[j] *= fac ** chs[i][j]
	return ans

def dfs(chs, i, k):
	if i == k:
		a, b, c = extract(chs, facs)
		n0 = (a+1) * (b+2) * (c+2)
		# print a, b, c, n0
		global max_n, min_n
		max_n = max(max_n, n0)
		min_n = min(min_n, n0)
		return
	for ch in sep(facs[i][1], [0]*3):
		chs[i] = ch
		dfs(chs, i+1, k)

facs = get_facs(n)
if n == 1:
	print 17, 17
else:
	k = len(facs)
	dfs([0]*k, 0, k)
	print min_n - n, max_n - n


import itertools as it
from functools import reduce

PRIME = -1

N = 10**9

primes = [PRIME for x in range(N + 1)]

def factor(n):
    """
    >>> factor(2)
    [(2, 1)]

    >>> factor(6)
    [(3, 1), (2, 1)]

    >>> factor(98)
    [(7, 2), (2, 1)]

    >>> factor(1)
    []
    """
    if n == 1:
        return []
    if primes[n] == PRIME:
        return [(n, 1)]
    result = []
    result += [(primes[n], 1)]
    n //= primes[n]

    while primes[n] != PRIME:
        if result[-1][0] == primes[n]:
            result[-1] = (primes[n], result[-1][1] + 1)
        else:
            result += [(primes[n], 1)]
        n //= primes[n]

    if result[-1][0] == n:
        result[-1] = (n, result[-1][1] + 1)
    else:
        result += [(n, 1)]

    return result

def all_divisors(prime_factorization):
    """
    >>> all_divisors(factor(6))
    [1, 2, 3, 6]

    >>> all_divisors(factor(12))
    [1, 2, 4, 3, 6, 12]

    >>> all_divisors(factor(7))
    [1, 7]

    >>> all_divisors(factor(1))
    [1]
    """
    if len(prime_factorization) == 0:
        return [1]
    result = []
    factor_with_mult = []
    for pfactor in prime_factorization:
        factor_with_mult += [[1]]
        for _ in range(pfactor[1]):
            factor_with_mult[-1] += [factor_with_mult[-1][-1] * pfactor[0]]
    for divisor in it.product(*factor_with_mult):
        result += [reduce(lambda x, y: x * y, divisor)]
    return result

if __name__ == '__main__':
    # sieve
    for i in range(2, N + 1):
        if primes[i] == PRIME:
            j = 2
            while j * i < N + 1:
                primes[j * i] = i
                j += 1
    primes[0] = primes[1] = 0

    n = int(input())

    min_result = 10**9
    max_result = 0

    for divisor in all_divisors(factor(n)):
        for div2 in all_divisors(factor(divisor)):
            if div2 * div2 > divisor:
                break
            a = n // divisor + 1
            b = divisor // div2 + 2
            c = div2 + 2
            min_result = min([min_result,
                              c * b + (a - 1) * 2 *
                              (b + c - 2)])
            max_result = max([max_result,
                              c * b + (a - 1) * 2 *
                              (b + c - 2)])
    print(str(min_result) + " " + str(max_result))


import sys
n, k = [ int(x) for x in input().split() ]
arr = list( map( int, input().split()) )

cnt_2 = 2 * n
cnt_4 = n
cnt_1 = 0

i = 0
while(cnt_4 > 0 and i < n):
    tmp = arr[i] / 4
    if(tmp > 0 and tmp <= cnt_4):
        cnt_4 = cnt_4 - tmp
        arr[i] = arr[i] - tmp * 4
    i = i + 1

if(cnt_4 > 0):
    cnt_2 = cnt_2 + cnt_4
    cnt_1 = cnt_1 + cnt_4
    cnt_4 = 0

i = 0
while(cnt_2 > 0 and i < n):
    tmp = arr[i] / 2
    if(tmp > 0 and tmp <= cnt_2):
        cnt_2 = cnt_2 - tmp
        arr[i] = arr[i] - tmp * 2
    i = i + 1

if(cnt_2 > 0):
    cnt_1 = cnt_1 + cnt_2
    cnt_2 = 0

i = 0
while(i < n):
    tmp = arr[i]
    if(tmp > cnt_1):
        print("NO")
        sys.exit(0)
    elif(tmp > 0 and tmp <= cnt_1):
        cnt_1 = cnt_1 - tmp
        arr[i] = arr[i] - tmp
    i = i + 1

print("YES")


for i in range(5):
 s=input();if'1'in s:print(abs(i-2)+abs(s.find('1')//2-2))


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time

xy = []

for i in range(3):
    (x, y)   = (int(i) for i in input().split())
    xy.append([x, y])

start = time.time()

if (x[0] == x[1] and x[1] == x[2]) or (y[0] == y[1] and y[1] == y[2]):
    print(1)
elif x[0] == x[1] or x[1] == x[2] or y[0] = y[1] or y[1] == y[2] :
    print(2)
else:
    print(3)

finish = time.time()
#print(finish - start)


n,m=list(map(int,input().split()))
min_isolated=0;
max_isolated=0;
if n-m*2>0:
    min_isolated=n-m*2
vertices=n
while n*(n-1)/2>m:
    n--;
max_isloated=vertices-n;
print(min_isolated,max_isolated)


import sys,math
from collections import deque
import random
#input = sys.stdin.buffer.readline

# def solve():
# 	return;

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

s = input()

l = ["Danil", "Olya", "Slava", "Ann", "Nikita"]

cnt = 0
for x in l:
	if s.find(x)>=0:
		cnt+=1

if cnt==1:
	print("YES")
else:
	print("NO")


from sys import stdin, stdout
import math

n = int(stdin.readline())
ans = n
for i in range(2, int(math.sqrt(n))+1):
    t = int(math.log(n, i))
    if t!=0:
        ans -= (t-1)

if ans % 2 == 0:
    stdout.write("Petya"+'\n')
else:
    stdout.write("Vasya"+"\n")


n= int(input())
m=[]
mm=n
ans=[]
def sc(i,j,k):
   xx=0
   for t in range(5):
      xx+=(m[i][t]-m[j][t])*(m[i][t]-m[k][t])
   return xx

for i in range(n):
   ans.append(1)
   a,b,c,d,e=map(int,input().split())
   m.append([a,b,c,d,e])
for i in range(n):
   for j in range(n):
      if (i != j):
         for k in range(n):
            if (i != k) and ( j != k):
               if sc(i,j,k) <=0:
                  ans[i]=-1
for i in range(n):
   if ans[i]==1:
      mm+=-1
print(mm)
for i in range(n):
   if ans[i]==-1:
      print(i+1)


from sys import exit

from itertools import combinations

class Vector5D:
    def __init__(self, xs):
        if len(xs) != 5:
            raise Exception("pidor")

        self.xs = xs

    def __sub__(self, other):
        return Vector5D([a - b for a, b in zip(self.xs, other.xs)])

    def __abs__(self):
        return sum(x ** 2 for x in self.xs)

    def dot(self, other):
        return sum(a * b for a, b in zip(self.xs, other.xs))

    def __repr__(self):
        return '(%s)' % (' '.join(str(x) for x in self.xs), )

n = int(raw_input())

if n > 2 * 5:
    print 0

    exit(0)

vs = []

for _ in xrange(n):
    xs = map(int, raw_input().split(' '))

    vs.append(Vector5D(xs))

good_points = []

for i in xrange(len(vs)):
    for j, k in combinations(range(len(vs)), 2):
        if j == i or k == i or j > k:
            continue

        ab = vs[j] - vs[i]
        ac = vs[k] - vs[i]

        if ab.dot(ac) > 0:
            break
    else:
        good_points.append(i)

print len(good_points)

for i in good_points:
    print i + 1


n=int(raw_input());
st=str(n);
ctr=0;
for i in range(1,n+1):
	d=n%i;
	flag=0;
	if d==0:
		s=str(i);
		for j in range(len(s)):
			if s[j] in st and flag==0:
				flag=1;
				ctr=ctr+1;

print ctr;


d=input()
print sum( 1 for x in range(1, d+1) if d%x < 1 and len(set(str(d))&set(str(x)))>0 )


from sys import stdin,stdout
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
from itertools import permutations as perm

pos = []
n = 2
while n <= 10:
    cur = '4' * (n // 2) + '7' * (n // 2)
    pos.extend(sorted([int("".join(i)) for i in perm(cur)]))
    n += 2
n = ii1()
for i in pos:
    if i >= n:
        print(i)
        break


s = raw_input()
a = sorted([int(s[0]),int(s[1]),int(s[2])])
b = sorted([int(s[3]),int(s[4]),int(s[5])])
c = sum(a)-sum(b)
def solve(l1,l2):
	n = 0
	while sum(l1)<>sum(l2):
		if sum(l1)>sum(l2):
			c1 = sum(l1)-sum(l2)
			if l1[2]>=c1 or (9-l2[0])>=c1:
				n+=1
				return n
			else:
				if l1[2]>=(9-l2[0]):
					l1[2]=0
				else:
					l2[0]=9
				n+=1
	return n
if c==0:
	print 0
elif c>0:
	print solve(a,b)
else:
	print solve(b,a)


r, g, b = input().split()
r, g, b = int(r), int(g), int(b)
s = 0
s += min(r, g, b)
r, g, b = r - min(r, g, b), g - min(r, g, b), b - min(r, g, b)
while r+b+g >= 3:
    if r < b:
        t = r
        r = b
        b = t
    if r < g:
        t = r
        r = g
        g = t
    if b < g:
        t = b
        b = g
        g = t
    r = r - 2
    b = b - 1
    s += 1

print(s)


from math import factorial
MOD = 10**9+7

def binom(n, k):
    if k > n-k: return binom(n, n-k)
    res = 1
    for i in range(k): res = res*(n-i)//(i+1)
    return res

def comp_ones_vecs(k, n):
    # k ones, n vectors
    if k < n: return 0
    ans = 0
    for Z in range(n):
        ans+= (-1)**Z * binom(n,Z) * (n-Z)**k
    return ans // factorial(n)

def comp_ones_frees_vecs(k, f, n):
    # k prefixed ones, f digits of freedom, n vectors
    ans = 0
    for i in range(f+1):
        ans+= comp_ones_vecs(k+i, n) * binom(f, i)
    return ans

def comp_ones_frees(k, f):
    # k prefixed ones, f digits of freedom
    ans = 0
    for n in range(1, k+f+1):
        ans+= comp_ones_frees_vecs(k, f, n)
    return ans

k = int(input())
bink = list(map(int, bin(k)[2:]))
ans = 1 + comp_ones_frees(sum(bink), 0)
ones = 0
for i in range(len(bink)):
    if bink[i] == 0: continue
    ans+= comp_ones_frees(ones, len(bink)-i-1)
    ones+= 1
print(ans % MOD)


def is_subsequence(child, parent, i, j, c):
    if i >= len(child) or j >= len(parent):
        return c
    if child[i] == parent[j]:
        return is_subsequence(child, parent, i+1, j+1, c+1)
    else:
        return max(is_subsequence(child, parent, i+1, j, c),is_subsequence(child, parent, i, j+1, c))

s = [c for c in input()]
t = [c for c in input()]
copy_s = [c for c in s]
copy_t = [c for c in t]

if len(s) < len(t):
    print("need tree")
    exit()

for c in t:
    if c not in s:
        print("need tree")
        exit()
    else:
        s.remove(c)

# print(s)
# print(t)

if len(s) == 0:
    print("array")
else:
    k = is_subsequence(copy_t, copy_s, 0, 0, 0)
    if k == len(copy_t):
        print("automaton")
    else:
        print("both")


l = list(map(int, input().split()))
s = set(l)
if len(s) == 1:
	print('Elephant')
elif len(s) == 2:
	if l.count(l[0]) == 5 || l.count(l[0]) == 1:
		print('Bear')
	else:
		print('Elephant')
elif len(s) == 3:
	print('Bear')
else:
	print('Alien')


n,m = map(int, input().split())
l = list(map(int, input().split()))
if n == 1:
    return 1
ans = []
k = l
c = {}
for i,v in enumerate(l):
    c[v] = i

while len(l) != 0:
    if m >= l[0]:
        ans.append(k[0])
        l = l[1:]
        k = k[1:]
    else:
        l[0] -= m
        l = l[1:] + l[0:1]
        k = k[1:] + k[0:1]

print(c[ans[-1]] + 1)


x = int(input())
arr = []
for i in range(1, 300, 2):
    arr.append((i//2) * (i // 2) + (i //2+ 1) + (i // 2 + 1))
counter = 0
ind = 1
while arr[counter] >= x:
    counter+=1
    ind += 2
counter-=1
ind -=2
if (x == 3) print(5)
else:
print(ind)


x = int(input())
arr = []
for i in range(1, 10000, 2):
    arr.append((i//2) * (i // 2) + (i //2+ 1) + (i // 2 + 1))
counter = 0
ind = 1
while arr[counter] < x:
    counter += 1
    ind += 2
if (x == 2): print(3)
elif (x == 3): print(5)
else: print(ind)


p=input();
m=input();
n='qwertyuiopasdfghjkl;zxcvbnm,./'
if(p=='R'):
    i=0;
    while(i<len(m)):
        j=-1;
        while(j>(-len(n)) or j==(-len(n))):
            if(m[i]==n[j]):
                print(n[j-1],end='');
            j=j-1;
        i=i+1;
else:
    i=0;
    while(i<len(m)):
        j=0;
        while(j<len(n)):
            if(m[i]==n[j]):
                print(n[j+1],end='');
            j=j=1;
        i=i+1;


n,l,r=[int(i) for i in input().split()]
arr=[0]*n
curr=2
if n==1:
    print(1,1)
    exit(0)
else:
    arr[0]=1
    l-=1
    for i in range(1,n-l):
        arr[i]=1
    for i in range(n-l,n):
        arr[i]=curr
        curr*=2
    mi=sum(arr)
    curr=2**(r-1)
    arr[0]=1
    t=2
    i=1
    while t!=curr:
        arr[i]=t
        t*=2
        i+=1
    while i<n:
        arr[i]=curr
        i+=1
    ma=sum(arr)
    print(mi,ma)


s=input().strip()
b=False
l=False
c=False
for i in s:
    if 'a'<=i<='z': l=True
    if 'A'<=i<='Z': b=True
    if '0'<=i<='9': c=True
    if b and l and c: break
if b and l and c len(s)>=5:
    print('Correct')
else:
    print('Too weak')


a,b,co=map(int,input().split())
c=[]
for i in range(1,co+1):
    if(i==1):
        x=b*2+2*(a-2)
        c.append(x)
    else:
        if(a>0 and b>0)
            a=a-2*i
            b=b-2*i
            x=b*2+2*(a-2)
            c.append(x)
        else:
            break
print(sum(c))


from collections import defaultdict
from typing import List

class Solution:
    @classmethod
    def calculate(cls, weight_combo: List[str]) -> str:
        mapping = defaultdict(int)
        for combo in weight_combo:
            [first_op, operator, second_op] = list(combo)
            if operator == ">":
                mapping[first_op] += 1
            else:
                mapping[second_op] += 1
        if mapping["A"] == 1 and mapping["B"] == 1 and mapping["C"] == 1:
            print("Impossible")
        if mapping['A'] == 0:
            print("A", end="")
        elif mapping['B'] == 0:
            print("B", end="")
        elif mapping['C'] == 0:
            print("C", end="")

        if mapping['A'] == 1:
            print("A", end="")
        elif mapping['B'] == 1:
            print("B", end="")
        elif mapping['C'] == 1:
            print("C", end="")

        if mapping['A'] == 2:
            print("A", end="")
        elif mapping['B'] == 2:
            print("B", end="")
        elif mapping['C'] == 2:
            print("C", end="")

if __name__ == "__main__":
    combo = []
    for _ in range(3):
        combo.append(input())
    Solution.calculate(combo)


 import math
a_x, a_y, b_x, b_y, c_x, c_y = map(int, input().split())

if (b_x - a_x)*(c_y - a_y) == (c_x - a_x)*(b_y - a_y):
  print('No')
  exit()

l_ab = math.sqrt(abs(b_x - a_x)**2 + abs(b_y - a_y)**2)
l_bc = math.sqrt(abs(c_x - b_x)**2 + abs(c_y - b_y)**2)
if l_ab != l_bc:
  print('No')
  exit()

print('Yes')


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

f = x*y

if (f % 2 == 0):
	print int(f / 2)
else:
	print int((f - 1) / 2)


# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------

n,m=map(int,input().split())
print((2**m -1)**n)


import sys
input = sys.stdin.readline

'''

'''

MOD = 10**9+7

n, m = map(int, input().split())
t = 2**m-1
res = t
while n > 1:
    res *= t
    res %= MOD
    n -= 1

print(res)


# Alice and the List of Presents (593.2)

n,m=input().split()
n,m=int(n),int(m)
a=2**m
print((a-1)**n)


x=10**9+7
n,m=list(int(i) for i in input().split())
print(((2**m-1)**n)%x)


import sys

input = lambda: sys.stdin.readline().strip("\r\n")

n, m = map(int, input().split())
print((2**m - 1)**n)


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

mod = int(10e9) + 7

a1 = pow(2, m) - 1
ans = pow(a1, n, mod)

print(ans)


n,m=map(int,input().split())
def fun(x,y,m):
    res=1
    while y>0:
        if y%2==1:
            res=(res*x)%m
        y//=2
        x=(x*x)%m
    return res
tot = 2**m-1
print(fun(tot,n,10**9+7))


n,m = input().split(' ')
n = int(n)
m = int(m)
print((2**m-1)**n)


import math
n,m=map(int,input().split())
t=2**m-1
s=t**n
print(s%1000000007)


from sys import *
from math import *
n,k=map(int,stdin.readline().split())
f=[1]
for i in range(1,max(n,k)+1):
    f.append(i*f[i-1])
ans=0
for i in range(0,k):
    ans+=(f[k]//(f[k-i]*f[i]))
print(ans**n)


import sys

[n , m , k] = sys.stdin.readline().split()

n = int(n)
m = int(m)
k = int(k)

def iseven(x):

    if x % 2 == 0:

        return True

    return False

if iseven(n + m) == False and k ==-1: print(0)

else: print(2**((n-1)*(m-1)) % 1000000007)


n, d = int(input().split())
s = list(map(int, input.split())
j = [list(s.index(n) for n in s if n == 1)]
k = [list(j-i for i, j in zip(j[:-1], t[1:]) if j-i <= d)]
if not k :
    print(-1)
else :
    print(len(k))


a=int(input())
b=int(input())
print (a-1)/(b-1)+a


sn,sk = input().split(' ')
n =int(sn)
k=int(sk)
s=input()
# print(s[0])
# exit(0)
mx=0
l=0
while(l<n):
    if s[l] != 'N':
        l+=1
    else:
        r=l+1
        while((r<n) and (s[r]=='N')):
            r+=1
        mx=max(mx,r-l)
        l=r
if(mx>k):
    print('NO')
    exit(0)
ans = 'NO'
for l in range(n):
    can = 1
    if (l+k < n) and (s[l+k]=='N'):
        can =0
    if(l==0 or s[l-1]!='N'):
        if(l+k<=n):
            for i in range(k):
                if s[l+i]=='Y' :
                    can=0
    else:
        can = 0
    if can ==1:
        ans = 'YES';
print(ans)


matrix = []

for i in range(8):
    line = input()
    matrix.append(line)

total_count = 0
t = 0
for i in range(8):
    row_count = 0
    for j in range(8):
        if matrix[i][j] = 'B':
            row_count += 1
    if row_count!=8:
        total_count = row_count
        t = 1
        break
if t==0:
    print(8)
else:
    for col in range(8):
        col_count = 0
        for row in range(8):
            if matrix[row][col] == 'B':
                col_count += 1
        if col_count!=8:
            total_count += col_count
            break
    print(total_count)


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

def solve(last):
    s = 0
    for i in range(1, n, 1):
        if last == 1 :
            if arr[i] == 2:
                s += 3
            else:
                s += 4
            last = arr[i]
        elif arr[i] == 1:
            if last == 2:
                s += 3
            else:
                s += 4
            last = arr[i]
        else:
            return "Infinite"
        if i-1 >= 0 or i+1 <= n:
            if arr[i-1] == 3 and arr[i] == 1 and arr[i+1] == 2:
                s -= 1
    return s

l = arr[0]
ret = solve(l)
if ret == "Infinite":
    print(ret)
else:
    print("Finite")
    print(ret)


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-9;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */

ll gcd(ll x, ll y){
    return !y ? x : gcd(y,x%y);
}

int main(void) {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    ll n, ans = 0;
    cin >> n;
    ll to = sqrt(n+.0);
    for(ll i=1;i<=to;i++)
     for(ll j=i;j<=to;j++){
      ll c = i*i+j*j;
      if(c > n) break;
      if(gcd(i,j) != 1 || ~(j-i) & 1) continue;
      ans += n/c;
     }
    cout << ans << endl;
    return 0;
}


#!/usr/bin/env python3
import sys

(c,d) =raw_input()#sys.argv[1]
#c = sys.argv[1][0]
#d=sys.argv[1][1]
moves = [1 for i in range(8)]
#012
#7x3
#654
if c == 'a':
	moves[0] =0
	moves[7] =0
	moves[6] =0
elif c=='h':
	moves[3] =0
	moves[4] =0
	moves[5] =0
if d==1:
	moves[0] =0
	moves[1] =0
	moves[2] =0
elif d==8:
	moves[4] =0
	moves[5] =0
	moves[6] =0
contador =0
#for i in moves:
	#contdor +=i
print (sum(moves))


n = int(input())
z = 1
g = 0
r = 0
while g < n:
    g += z
    r += 1
    z = 3-z
if g > n:
    r -= 1
print(r)


def main(n, x, y):
    if (x == n and y == n):
        return "YES"
    if (x == n and y == n+1):
        return "YES"
    if (x == n+1 and y == n):
        return "YES"
    if (x == n+1 and y == n+1):
        return "YES"
    else:
        return "NO"

line = raw_input()
lst = line.split(" ")
n = int(lst[0]/2)
x = int(lst[1])
y = int(lst[2])
print main(n, x, y)


for t in range(int(input())):
    n = int(input())
    if not n % 2:
        print(f'{n // 2} {n // 2}')
    else:
        ans = [True] * ((n // 2) + 1)
        idx = 1
        for i in range(3, (n // 2) + 1):
            if not ans[i] or not i % 2:
                continue
            if n % i > 0:
                ans[i] = False
                for j in range(2, ((n // 2) + 1) // i):
                    ans[i * j] = False
            elif n % i == 0:
                idx = i
                break
        # print(ans, idx)
        if idx == 1:
            print(f'{1} {n - 1}')
        else:
            print(f'{n // idx} {n - n // idx}')

# for t in range(int(input())):
#     n = int(input())
#     a = list(map(int, input().split()))
#     cnt = 0
#     i = 0
#     while i < n:
#         while i < n and a[i] == i + 1:
#             i += 1
#         j = i
#         while i < n and a[i] != i + 1:
#             i += 1
#         cnt += 1 if j - i else 0
#     print(cnt)


def extend(l):
    for i in l[:]:
        l.append(i/2)
        l.append(i+1)
    return(l)
m,n = map(int,input().split())
s = [n]
step = 0
while m not in s:
    s = extend(s)
    step+=1
print(step)


# https://codeforces.com/problemset/problem/575/H

import sys
import math

mod = pow(10, 9) + 7

def main():
    # sys.stdin = open('E:\\Sublime\\in.txt', 'r')
    # sys.stdout = open('E:\\Sublime\\out.txt', 'w')
    # sys.stderr = open('E:\\Sublime\\err.txt', 'w')

    n = int(sys.stdin.readline().strip())
    # a, b = map(int, sys.stdin.readline().strip().split()[:2])

    # C(n+1, 2n + 2) = (2n+2)! : (n+1)! : n+1!
    # = (n+2)(n+3)...(2n+2) /

    t = 1
    m = 1
    for i in range(1, n + 2):
        t *= (n + i + 1) % mod
        m *= i % mod
    print((t // m - 1) % mod)

if __name__ == '__main__':
    main()

# hajj
#  　　　　　　 ＿＿
# 　　　　　／＞　　フ
# 　　　　　| 　_　 _ l
# 　 　　　／` ミ＿xノ
# 　　 　 /　　　 　 |
# 　　　 /　 ヽ　　 ﾉ
# 　 　 │　　|　|　|
# 　／￣|　　 |　|　|
# 　| (￣ヽ＿_ヽ_)__)
# 　＼二つ


n = int(raw_input())+1
aa=1
for i in xrange(1, 2*n):
	aa *= i
bb=1
for i in xrange(1, n+1):
	bb *= i
cc = 1
for i in xrange(1, n):
	cc *= i
print (2 * aa / (bb * cc) - 1) % (10 ** 9 + 7)


def main():
    s = input()
    ans = 26
    for c in s:
        ans +=25

    print(ans)

if __name__='__main__':
    main()


rcp = raw_input()
rcp = [rcp.count(c) for c in ['B', 'S', 'C']]
n = map(int, raw_input().split())
p = map(int, raw_input().split())
r, cnt = int(raw_input()), 0
while True:
	if all([n[i] == rcp[i] for i in range(3)]):
		cnt += 1
		break
	for i in range(3):
		if n[i] < rcp[i]:
			if p[i] * (rcp[i] - n[i]) <= r:
				r -= p[i] * (rcp[i] - n[i])
				n[i] = rcp[i]
			else:
				print cnt
				exit()
	for i in range(3):
		n[i] -= rcp[i]
	cnt += 1
cpb = 0
for i in range(3):
	cpb += rcp[i] * p[i]
cnt += r / cpb
print cnt


def getSum(n):
    sum = 0
    while (n != 0):
        sum = sum + int(n % 10)
        n = int(n/10)
    return sum

n = int(input())
if n<=9:
    print(n)
else:
    x=0
    while x*10+9<=n:
        x+=x*10+9
    print(getSum(x)+getSum(n-x))


#n , m = map(int , input().split())
n = int(input())
m = int(input())
print(pow(2 , n + m , 998244353 ))


n, front, back = [int(x) for x in input().split(' ')]
print(n - max(front + 1, n - back)+ 1)3 1 1


from math import sqrt

r,h = map (int, input().split())
count = h // r * 2
h -= h // r
elif h >= sqrt(3) / 2 * r:
  count += 3
elif h >= r / 2:
  count += 2
else:
  count += 1
print (count)


def check(a,b):
    ansa=b[0]-a[0]
    ansb=b[1]-a[1]
    return [ansa,ansb]
while True:
    try:
        n,m=map(int,input().split())
        if n!=m:
            print('No')
        else:
            a=list()
            b=list()
            for i in range(n):
                a.append(list(map(int,input().split())))
            for i in range(m):
                b.append(list(map(int,input().split())))
            flag=False
            for i in range(len(a)):
                for j in range(i+1,len(a)):
                    for k in range(len(b)):
                        for l in range(k+1,len(b)):
                            ansa=check(a[i],a[j])
                            ansb=check(a[i],b[k])
                            ansc=check(a[i],b[l])
                            if (ansa[0]==ansb[0] and ansa[0]==ansc[0] and ansa[0]==0) or (ansa[0]!=0 and ansb[0]!=0 and ansc[0]!=0 and ansa[1]/ansa[0]==ansb[1]/ansb[0] and ansa[1]/ansa[0]==ansc[1]/ansc[0]):
                                print('No')
                                flag=True
                                break
                            else:
                                continue
                        if flag==True:
                            break
                    if flag==True:
                        break
                if flag==True:
                    break
            if flag==False:
                print('Yes')
    except EOFError:
        break


n, m, l, r = map(int , input().split())
a = list(map(int , input().split()))
if max(x) > r or  min(a) < l:
    print("Incorrect")
elif n - m >= 2 :
    print("Correct")
elif:
    if l not in a and r not in a and l != r:
        print("Incorrect")
    else:
        print("Correct")


n,k=map(int, input().split())
for i in range(1,10):
    if(n*i % 10 == k || n*i%10 == 0):
        print(i)


n, m = map(int, input().split())
grid = [None for _ in range(n)]
for i in range(n):
	grid[i] = list(input())
pos = []
for i in range(n):
	for j in range(m):
		if grid[i][j] == 'W':
			pos.append((i, j))
ln = len(pos)

memo = {}
def solve(x, magic):
	if (x, magic) not in memo:
		if x >= ln:
			return 0

		res = solve(x + 1, magic)
		i, j = pos[x]

		if j > 0 and grid[i][j - 1] == 'P':
			grid[i][j - 1] = '.'
			res = max(res, 1 + solve(x + 1, magic + i * n + (j - 1) * m))
			grid[i][j - 1] = 'P'

		if i > 0 and grid[i - 1][j] == 'P':
			grid[i - 1][j] = '.'
			res = max(res, 1 + solve(x + 1, magic + (i - 1) * n + j * m))
			grid[i - 1][j] = 'P'

		if i < n - 1 and grid[i + 1][j] == 'P':
			grid[i + 1][j] = '.'
			res = max(res, 1 + solve(x + 1, magic + (i + 1) * n + j * m))
			grid[i + 1][j] = 'P'

		if j < m - 1 and grid[i][j + 1] == 'P':
			grid[i][j + 1] = '.'
			res = max(res, 1 + solve(x + 1, magic + (i + 1) * n + j * m))
			grid[i][j + 1] = 'P'

		memo[x] = res
		return res
	else:
		return memo[x]

print(solve(0, 0))


q = input()
n = int(q[0])
b = int(q[2])
p = int(q[4])
x = (n - 1) * b * b + (n - 1)
y = n * p
print(x, y)
# Thu Oct 08 2020 11:53:37 GMT+0300 (Москва, стандартное время)

# Thu Oct 08 2020 11:53:42 GMT+0300 (Москва, стандартное время)

# Thu Oct 08 2020 11:53:56 GMT+0300 (Москва, стандартное время)

# Thu Oct 08 2020 13:37:38 GMT+0300 (Москва, стандартное время)


from math import log, floor

def binarysearch(x, n, k, p):
    left = 0
    right = len(x)
    while left < right:
        middle = (left + right) // 2
        if sum([x[middle]//k**i for i in range(p+1)]) < n:
            left = middle + 1
        else:
            right = middle

    return left

n, k = [int(i) for i in input().split()]
p = floor(log(n, k))
x = list(range(n//2, n+1))
y = binarysearch(x, n, k, p)

print(x[y])


n = int(input())
ps = [int(x) for x in input().split()]
to_add = [x for x in range(1,n+1) if x not in ps]

if all(x==0 for x in ps):
    if n == 1:
        print(0):
        exit()
    print(1)
    exit()

for t in to_add:
    so = (101, None) # odd = 0, even = 2
    se = (101, None) # odd = 0, even = 2
    so2 = (101, None) # odd = 0, even = 1
    se2 = (101, None) # odd = 1, even = 0
    mixed = None #even, odd
    left = None
    zero_count = 0
    for i, p in enumerate(ps):
        if p == 0:
            zero_count += 1
        else:
            if zero_count > 0:
                if left is None:
                    if p%2==0:
                        se2 = (zero_count, i-1)
                    else:
                        so2 = (zero_count, i-1)
                else:
                    if p%2 == 0:
                        if ps[left]%2 == 0:
                            se = min(se, (zero_count, left+1))
                        else:
                            mixed = (i-1, left+1)
                    else:
                        if ps[left]%2 == 0:
                            mixed = (left+1, i-1)
                        else:
                            so = min(so, (zero_count, left+1))
                zero_count = 0
            left = i
    if zero_count > 0:
        if p%2 ==0:
            se2 = min(se2, (zero_count, left+1))
        else:
            so2 = min(so2, (zero_count, left+1))
    if t%2 == 0:
        if se[1] is not None:
            ps[se[1]] = t
        elif se2[1] is not None:
            ps[se2[1]] = t
        else:
            assert(mixed is not None)
            ps[mixed[0]] = t
    else:
        if so[1] is not None:
            ps[so[1]] = t
        elif so2[1] is not None:
            ps[so2[1]] = t
        else:
            ps[mixed[1]] = t
ans = 0
l = None
for i in range(len(ps)):
    if i == 0:
        continue
    if ps[i]%2 != ps[i-1]%2:
        ans += 1
print(ans)
# print(ps)


s=input()
s=sorted(s)
count=1
for i in range(1,len(s)):
    if(s[i]==s[i-1]):
        count+=1
    else:
        ans.append(count)
        count=1
ans.append(count)
ans.sort()
if(len(ans)==1):
    print(1)
if(len(ans)==2):
    if(ans[0]==1):
        print(1)
    else:
        print(2)
if(len(ans)==3):
    if(len(set(ans))==1):
        print(6)
    elif(ans=[1,1,4]):
        print(2)
    elif(ans==[1,2,3]):
        print(3)
if(len(ans)==4):
    if(ans==[1,1,1,3]):
        print(5)
    elif(ans=[1,1,2,2]):
        print(8)
if(len(ans)==6):
    print(30)
if(len(ans)==5):
    print(15)


#coding:utf-8

a, b = map (int, raw_input ().split ())
c = a+b
ans = c*2+2

x, y = 1, a
index = 1
i = 2
while i*i <= c:
	if c%i == 0:
		while index <= i:
			if a%index == 0:
				x, y = index, a/index
			index += 1
		if x <= i and y <= c/i:
			ans = min (ans, 2*(i+c/i))
	i += 1

print ans


from math import sqrt
import bisect
def divisors(n):
    s = [1]
    for i in range(2, int(sqrt(n)) + 5):
        if n % i == 0:
            s.append(i)
    if len(s) == 1:
        s.append(n)
    return s

bisect_right = bisect.bisect
a, b = map(int,input().split())
s = a + b
k = a
diva = divisors(a)
divb = divisors(b)
divs = divisors(s)
ansA = 0
ansB = 0
diva.sort()
divb.sort()
for i in range(len(divs)):
    s = bisect_right(diva, divs[i]) - 1
    if ((a + b) / divs[i]) >= (a / diva[s]):
        ansA = 2*(divs[i] + ((a + b)/divs[i]))
for i in range(len(divs)):
    s = bisect_right(divb, divs[i]) - 1
    if ((a + b) / divs[i]) >= (b / divb[s]):
        ansB = 2*(divs[i] + ((a + b)/divs[i]))
print(int(min(ansA,ansB)))


import sys
stderr = sys.stderr
def nums():
    return map(int, raw_input().split())
X, Y, R1, R2 = 0, 1, 2, 3
c1 = nums()
c2 = nums()
def dist(x1, y1, x2, y2):
    return ((x1-x2)**2 + (y1 - y2)**2)**.05
def cok(x, y, r, c):
    d = dist(x, y, c[X], c[Y])
    if d >= r + c[R2] or d + r <= c[R1] or d + c[R2] <= r:
        return True

candi = [(c1[X], c1[Y], c1[R1], c2),
        (c1[X], c1[Y], c1[R2], c2),
        (c2[X], c2[Y], c2[R1], c1),
        (c2[X], c2[Y], c2[R2], c1)]
ans = 0
for x, y, r, c in candi:
    if cok(x, y, r, c):
        ans += 1
print ans


x1, y1, r1, R1 = map(int, raw_input().split())
x2, y2, r2, R2 = map(int, raw_input().split())
a = [r1, R1]
b = [r2, R2]
cnt = 0
d = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
def func(c1, c2):
	if d - c1 - c2 > -1.0e-8 or abs(c1 - c2) - d > -1.0e-8:
		return 1
	return 0
for c in a:
	cnt += func(c, b[0]) & func(c, b[1])
for c in b:
	cnt += func(c, a[0]) & func(c, a[1])
print cnt


MOD = 10**8

n1,n2,k1,k2 = map(int,raw_input().strip().split())

C = {}
def solve(r1,r2,lasttype,lastnum):
    count = C.get((r1,r2,lasttype,lastnum))
    if not count:
        count = 0
        if r1>0:
            if lasttype == 1:
                count += solve(r1-1,r2,0,1)
            elif lastnum<k1:
                count += solve(r1-1,r2,0,lastnum+1)
        if r2>0:
            if lasttype == 0:
                count += solve(r1,r2-1,1,1)
            elif lastnum<k2:
                count += solve(r1,r2-1,1,lastnum+1)
        count %= MOD
        if r1 == r2 == 0:
            count = 1
        C[(r1,r2,lasttype,lastnum)] = count
    return count

print solve(n1,n2,0,0)


readints() = lambda: map(int, input().split(' '))

a,b,c=readints()
x,y,z=readints()

if a!=x and b!=y and c!=c:
  print('NO')
else:
  print('YES')


segment = [6,2,5,5,4,5,6,3,7,6]
a,b = map(int,input().split())
s = ""
for i in range(a,b+1):
    s+=str(i)
ans = 0
for i in s:
    ans+=segment[int(i)]
print(ans)


n = [x for x in range(1, int(input()) + 1)]
while len(n) > 1:
    n.sort()
    a = n[len(n) - 1] - n[0]
    n.pop(len(n) - 1)
    n.pop(0)
    n.append(a)
print(n[0])


from collections import defaultdict
#n = int(raw_input())
n,b = [int(x) for x in raw_input().split()]
#arr = [int(x) for x in raw_input().split()]

s = 0
d_osn = defaultdict(int)
while b > 1:
    for i in range(2,b):
        if b % i == 0:
            d_osn[i] += 1
            b /= i
            break
    else:
        d_osn[b] += 1
        b = 1
#print(d_osn)
izv = defaultdict(int)
for i in range(1,n+1):
    for el in d_osn:
        while i % el == 0:
            i = i / el
            izv[el] += 1
res = -1
#print(izv)
for k in d_osn:
    mlt = 0 if k not in izv else izv[k] // d_osn[k]
    if res == -1:
        res = mlt
    elif mlt < res:
        res = mlt
print(res)


def fact(n) :
	if n <= 1 :
		return 1
		return n * fact(n - 1)

		def c_n_k(k, n) :
		return fact(n) / (fact(k) * fact(n - k))

		n, k = map(int, input().split())
		ans = 1

		d = [0, 1, 3, 12, 60, 124]

		for i in range(k, 1, -1) :
			ans += c_n_k(i, n) * (d[i] - d[i] // i)

				print(ans)


import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)

n, m = [int(item) for item in input().split()]
if n > m:
    n, m = m, n
if n == 1 and m == 1:
    print(2)
    exit()
dp = [[0] * m for _ in range(4)]

dp[0][1] = 1
dp[1][1] = 1
dp[2][1] = 1
dp[3][1] = 1

for i in range(2, m):
    dp[0][i] += dp[2][i-1]
    dp[1][i] += dp[0][i-1]
    dp[1][i] += dp[2][i-1]
    dp[2][i] += dp[1][i-1]
    dp[2][i] += dp[3][i-1]
    dp[3][i] += dp[1][i-1]

# for line in dp:
#     print(line)
lr = 0
ud = 0

for i in range(4):
    lr += dp[i][m-1]
    ud += dp[i][n-1]

if n == 1:
    print(lr)
    exit()
else:
    print(lr + ud - 2)


has_time = 4*60
def findNumTask(n, time):
    i = 0
    leftTime = has_time
    while leftTime >= time and n-i >= 0:
        i+=1
        leftTime -= i*5

    return i-1

n, time = int(input()), int(input())
return findNumTask(n,time)


z,zz=input,lambda:list(map(int,z().split()));
szz,dgraphs,mod=lambda:sorted(zz()),{},10**9+7
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
def lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2))
def prime(x):
    p=ceil(x**.5)+1
    for i in range(2,p):
        if x%i==0 and x!=2:return 0
    return 1
def dfs(u,visit,graph):
    visit[u]=True
    for i in graph[u]:
        if not visit[i]:
            dfs(i,visit,graph)
################################################################################

"""

led=(6,2,5,5,4,5,6,3,7,6)

color4=["G", "GB", "YGB", "YGBI", "OYGBI" ,"OYGBIV",'ROYGBIV' ]

"""

###########################---START-CODING---####################################

l=zz()

ans=-1

for i,j in enumerate(l):
    p=l[:]

    p[i]=0
    n=j//14
    ex=j%14

    m=i+1
    for _ in range(ex):
        if m==13:
            p[m]=(p[m]+1)
            m=0
        else:
            p[m]=(p[m]+1)
            m+=1

    for k in range(14):
        p[k]=(p[k]+n)

    t=0
    for i in p:
        if i%2==0:
            t+=i

    if t>ans:
        ans=t
print(ans)


 def is_leap_year(year):
    if year % 400 == 0:
        return True
    if year % 100 == 0:
        return False
    if year % 4 == 0:
        return True
    return False

start_year = int(input())
if is_leap_year(start_year):
    print(start_year + 28)
else:
    next_year = start_year + 1
    diff = 1
    if is_leap_year(next_year - 1):
        diff += 1

    while diff % 7 != 0:
        diff += 1
        next_year += 1
        if is_leap_year(next_year - 1):
            diff += 1
    print(next_year)


def is_visok(x):
    return x % 400 == 0 or x % 4 == 0 and x % 100 != 0

y = int(input())

d, v = 0, is_visok(y)
year = y

d_ = d
v_ = not v

while not (v_ == v and d_ % 7 = 0):
    year += 1
    v_ = is_visok(year)
    d_ += (365, 366)[v_] % 7

print(year)


def main():
    n, m, k = map(int, input().split())
    if n < m:
        n, m = m, n
    lo, hi = 2, min(n * m, (k + 1) ** 2 // 2) + 1
    while lo < hi:
        a = (lo + hi) // 2
        u = sum(a // i for i in range(a // n + 1, (m if m < a else a) + 1)) + a // n * n
        if u < k:
            lo = a + 1
        elif u > k:
            hi = a
        else:
            lo = hi = a
    res = [hi // i * i for i in range(hi // n + 1, (m if m < hi else hi) + 1)] + [n] * (a // n)
    res.sort(reverse=True)
    print(res[u - k])

if __name__ == '__main__':
    main()


[n, m, k] = raw_input("").split(" ")
[n, m, k] = [int(n), int(m), int(k)]

a = [0 for i in range(0, n*m)]

for i in range(0, n):
    for j in range(m):
        a[i+n*j] = (i+1)*(j+1)
a.sort()
print a[k-1]


from math import floor
from math import sqrt
a=int(input())
sqr=floor(sqrt(a))
f2=sqr
while sqr*f2<a;
    f2+=1
print((sqr+f2)*2)


n = int(input())
ans = float("+inf")
for i in range(1, n+1):
    for j in range(i, n+1):
        if i*j >= n:
            ans = min(ans, (i+j)*2)
print(ans)


n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
ans = 0

for i in xrange(n / k):
    t1 = t2 = 0
    for j in xrange(k):
        if a[i * k + j] == 1:
            t1 += 1
        else:
            t2 += 1
    ans += min(t1, t2)
print ans


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

ans = []
flag = 0
temp = 0
if s!=0:
    while s >= 0 and s//9<m or (s//9==m and s%9==0) and temp<m:
        flag = 1
        temp += 1
        if s-9 > 0:
            ans.append(9)
            s -= 9
        else:
            ans.append(s)
            s = 0
            continue

        if s==0 and temp<m:
            ans.append(0)

if flag:
    ans1 = "".join(map(str,ans))
    if ans[-1]==0:
        for i in range(len(ans)):
            if ans[-1-i]!=0:
                ans[-1-i] -= 1
                break
        ans[-1] = 1

    ans2 = "".join(map(str,ans[::-1]))
    print(ans2, ans1)
elif flag==0 and s==0 and m==1:
    print(0,0)
else:
    print(-1, -1)


#!/usr/local/bin/python
import math
n,m = map(int,raw_input().split(" "))
if n == 2 and m == 3:
        print "YES"
        exit()
elif m % 2 == 0:
        print "NO"
        exit()
tmp = n
while True:
        tmp += 2
        for i in xrange(2,int(round(math.sqrt(tmp)))+2):
                if tmp % i == 0:
                        break
                if tmp % i != 0 and i == int(round(math.sqrt(tmp)))+1:
                        if tmp == m: print "YES"
                        else: print "NO"
                        exit()


n = int(raw_input())
tri = lambda x: x * (x + 1) / 2
rem = 10 ** 9 + 7
print tri(2 ** n) % rem


'''
Created on May 4, 2012

@author: moatasem
'''
n=int(raw_input())
if(n==0):
   print 1
elif(n==1):
   print 3
else :
   c=4**(n-1)
   u=.75*c
   print int((3*u+.25*c)) %1000000007


def gen_series(index_):
    num = int((index_*2)**(0.5)+2)
    list_series = []
    for i in range(1,num+1):
        list_series.extend(range(1,i+1))
    ans = list_series[index_ - 1]
    return ans
if __name__ == '__main__':
    x = int(input())
    print gen_series(index_=x)


s=input()
l=len(s)
if l>=5:
    A=0
    a=0
    d=0
    for i in s:
        if A>0 and a>0 and d>0:
            break
        if i>='a' and i<='z':
            a=a+1
        elif i>='A' and i<='Z':
            A+=1
        try:
            k=int(i)
            d=d+1
        else:
            pass
    if A>0 and a>0 and d>0:
        print('Correct')
    else:
        print('Too weak')
else:
    print('Too weak')


import re
s = input()
if '@' not in s:
	print('NO')
	exit()
u, h = s.split('@', 1)
r = None
if '/' in h:
	if '/' in h[h.index('/') + 1: ]:
		print('NO')
		exit()
	h, r = h.split('/')
if not re.match('^\w{1,16}$', u):
	print('NO')
elif r is not None and not re.match('^\w{1,16}$', r):
	print('NO')
elif 1 > len(h) or len(h) > 32:
	print('NO')
else:
	h = h.split('.')
	if any(not re.match('^\w{,16}$', x) for x in h):
		print('NO')
	else:
		print('YES')


n = raw_input()
l = [i for i in raw_input().split()]
count = 0
i = 0
while l[i] == '0':
    i += 1
j = i
while j < len(l):
    if l[j] == '1':
        count += 1
        j += 1
        flag = 0
    else:
        if j + 1 < len(l) and l[j + 1] == '1' and flag == 0:
            count += 1
            j += 1
            flag = 1
        else:
            j += 1
            flag = 1
print count


import math
n_and_c=raw_input().split(' ')
n=int(n_and_c[0])
c=int(n_and_c[1])
count=0
i=1
while i<=n:
    count+=math.factorial(c+i-1)/(math.factorial(c-1)*math.factorial(i))
    i+=1
print count
print count % (10**6+3)


import math
n_and_c=raw_input().split(' ')
n=int(n_and_c[0])
c=int(n_and_c[1])
count=0
i=1
while i<=n:
    count+=math.factorial(c+i-1)/(math.factorial(c-1)*math.factorial(i))
    i+=1
print count % (10**6+3)


#236B

import math

arr = list(map(int, input().split(" ")))
a = arr[0]
b = arr[1]
c = arr[2]

def numdiv(n):
	count = 0
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			count += 2
	if int(math.sqrt(n)) * int(math.sqrt(n)) == n:
		count -= 1
	return count

answer = 0
for i in range(1, a + 1):
	for j in range(1, b + 1):
		for k in range(1, c + 1):
			answer += numdiv(i * j * k)

print(answer)


n,k=[int(n) for n in input().split()]
s=set()
for i in range(1,k+1):
    s.add(n%i)
if(len(s)==k):
    print("Yes")
else:
    print("No")


n = int(input())
f = []
X = []
Y = []
for i in range(4 * n + 1):
    x, y = map(int, input().split())
    f.append((x, y))
    X.append(x)
    Y.append(y)
l = min(X)
r = max(X)
d = min(Y)
u = max(Y)
if r - l == u - d:
    for i in f:
        if X.count(i[0]) == 1 and Y.count(i[1]) == 1:
            print(i[0], i[1])
            break
    for i in f:
        if l < i[0] < r and d < i[1] < u:
            print(i[0], i[1])
            break
else:
    for i in f:
        if X.count(i[0]) == 1 and Y.count(i[1]) == 1:
            print(i[0], i[1])
            break
    for i in f:
        if X.count(i[0]) == 1 and (i[0] == l or i[0] == R):
            print(i[0], i[1])
            break
        elif Y.count(i[1]) == 1 and (i[1] == u or i[1] == d):
            print(i[0], i[1])
            break


#!usr/bin/env/python
path = raw_input()
new_path = ''
flag = 0
for i in xrange(len(path)):
	if path[i] == '/' and flag:
		pass
	elif path[i] == '/':
		flag = 1
		new_path += path[i]
	else:
		flag = 0
		new_path += path[i]
while new_path[-1] == '/':
	new_path = new_path[:-1]
if new_path:
	print new_path
else:
	print '/'


s = raw_input()
n = len(s)
st = ""
for i in range(n):
    if s[i]=='/' and  s[i+1]=='/':
        continue
    else:
        st += s[i]
print st


n ,m ,k = map(int,input().split())
l = list(map(int,input().split()))
l[m-1] = "G"
p = m-1
o = m-1
while True:
    o -= 1
    p += 1
    try:
        if l[p]!=0 and l[p]<=k:
            print((p-(m-1))*10)
            break
    except:
        pass
    try:
        if l[o]!=0 and l[o]<=k and o>0:
            print((m-1-o)*10)
            break
    except:
        pass


import math as m
k, n, s, p = map(int, input().split())
i = 1
while True:
    needed_sheets = k * m.ceil(n/s)
    if i * p >= needed_sheets:
        break
    i += 1
print(i)


k, n, s, p = map(int, input().split())
x = 0
while ((x * p) // k) * s < n:
    x += 1
print(x)


from math import *
n,m=map(int,input().split())
if m==1:print(n*(n-1)//2,n*(n-1)//2)
else:
    minim=[n//m+1 for i in range(n%m)]
    for i in range(m-(n%m)):
        minim.append(n//m)
    maxim=[1 for i in range(m-1)]
    maxim.append(n-m+1)
#     minim.append(n-sum(minim))
    sum1,sum2=0,0
    for i in minim:sum1+=i*(i-1)//2
    for i in maxim:sum2+=i*(i-1)//2
    print(sum1,sum2)


#import sys
#sys.stdin = open('in', 'r')
#n = int(input())
#a = [int(x) for x in input().split()]
class minheap:
    def __init__(self, n):
        self.a = [0 for i in range(n)]
        self.n = 0

    def __init__(self):
        self.a = []
        self.n = 0

    def load(self, initial):
        self.a = [] + initial
        self.n = len(self.a)
        for i in range((self.n-2) // 2, -1, -1):
            self.hdown(i)

    def hup(self, ind):
        if ind > 0:
            parent = (ind - 1) // 2
            if self.a[parent] > self.a[ind]:
                tmp = self.a[ind]
                self.a[ind] = self.a[parent]
                self.a[parent] = tmp
                self.hup(parent)

    def hdown(self, ind):
        l = ind*2 + 1
        r = ind*2 + 2
        newind = ind
        if l < self.n and self.a[newind] > self.a[l]:
            newind = l
        if r < self.n and self.a[newind] > self.a[r]:
            newind = r
        if newind != ind:
            tmp = self.a[ind]
            self.a[ind] = self.a[newind]
            self.a[newind] = tmp
            self.hdown(newind)

    def push(self, v):
        if self.n == len(self.a):
            self.a.append(v)
        else:
            self.a[self.n] = v
        self.hup(self.n)
        self.n += 1

    def pop(self):
        if self.n > 0:
            res = self.a[0]
            self.n -= 1
            if self.n > 0:
                self.a[0] = self.a[self.n]
                self.a[self.n] = 0
                self.hdown(0)
            return res
        else:
            raise "empty heap"

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

h = minheap()
d = {}
h.push((0, n))

r = -1
while r == -1:
    xh,nh = h.pop()
    if nh not in d:
        d[nh] = xh
        if nh == 1:
            r = xh + x
        else:
            if (nh - 1) not in d:
                h.push((xh + x, nh - 1))
            if nh & 1 == 0 and (nh // 2) not in d and y < (nh//2)*x:
                h.push((xh + y, nh // 2))
            if (nh + 1) not in d:
                h.push((xh + x, nh + 1))

print(r)


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

t-=1
k-=1

sat=[0]*100000000

for i in range(t,k+s,s):
    sat[i]=1
    if i!=t:
        sat[i+1]=1

print("YES" if sat[k]==1 else "NO")


l = [int(e) for e in input().strip()]

def lei00(l):
    result = []
    for i in range(len(l)-1, -1, -1):
        if l[i] == 0:
            result.append(i)
        if len(result) == 2:
            break
    if len(result) < 2:
        return None
    return 2 * len(l) - result[0] - result[1] - 3

def lei(l, x, y):
    assert x != y

    ix = None
    iy = None

    for i in range(len(l)-1, -1, -1):
        if l[i] == x:
            ix = i
        elif l[i] == y:
            iy = i

        if ix != None and iy != None:
            break

    if ix == None or iy == None:
        return None

    result = 2 * len(l) - ix - iy - 3

    if ix > iy:
        result += 1

    if x == 7 or x == 2:
        assert y == 5
        if iy == 0 and l[1] == 0:
            if len(l) >= 4:
                iii = 1
                while True:
                    iii += 1
                    if l[iii] != 0:
                        break
                result += iii-1
            if len(l) == 3:
                return None

    return result

l = [lei00(l), lei(l, 5, 0), lei(l, 7, 5), lei(l, 2, 5)]

result = None
for e in l:
    if e == None:
        continue
    if result == None or result > e:
        result = e

if result == None:
    print(-1)
else:
    print(result)


k, n, m = map(int, raw_input().split())
a = map(int, raw_input().split())
s = sum(a)
a.sort()
ans = 0
for i in xrange(m / s + 1):
    p = i * (n + 1)
    t = m - i * s
    for x in a:
        if t >= x * (k - i):
            t -= x * (k - i)
            p += k - i
        else:
            p += t / x
            break
    if ans < p:
        ans = p
print ans


x=int(input())
b=[str(i) for i in input().split()]
# print(b)
hh=b[0]
mm=b[1]
if hh[0]=="0":
	hh=hh[1:]
	hh=int(hh)
if mm[0]=="0":
	mm=mm[1:]
	mm=int(mm)

# print(hh,mm)

nh=hh
nm=mm
f=0
y=0
while(f==0):
	nh=str(nh)
	nm=str(nm)
	if '7' in nh or '7' in nm:
		f=1
		break
	nh=int(nh)
	nm=int(nm)
	if x>nm:
		d= x-nm
		if nm==0:
			nm=23
		else:
			nm-=1
		nm= 60-d
	else:
		nm-=x
	y+=1

print(y)

'''

'''


  n,k = map(int, input().split())
N=ceil(2*n/k)+ceil(5*n/k)+ceil(8*n/k)


n, k = map(int, input().split())
flag = True
x = 0
while flag == True:
	if (x % k) * (x // k) == n:
		print(x)
		flag = False
	x = x + 1


"""609C"""
# import math

def main():
	k ,a, b  = map(int,input().split())
	mx = max(a,b)
	mn = min(a,b)
	cnt=0
	while True:
		temp = mx
		temp2 = mn
		if temp-k<0:
			print(-1)
			return
		elif temp-k==0:
			cnt+=1
			print(cnt)
			return
		else:
			cnt+=1
			mx = max(temp,temp2)
			mn = min(temp,temp2)
	return

main()
# t= int(input())
# while t:
# 	main()
# 	t-=1


import math

import sys

sys.setrecursionlimit(10**6)
def proA(n,co):
    global a,c,b
    if(n==0):
        return co
    if(n<0):
        return -math.inf
    maxi=0
    for i in [a,b,c]:
        maxi=max(maxi,proA(n-i,co+1))
    return maxi

arr=list(map(int,input().split()))
n,a,b,c=arr
print(proA(n,0))


import sys
import math

def dist(a, b):
    return math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]))

def samep(a, b):
    EPS = 0.01
    if a - b < -EPS or a - b > EPS:
        return False
    return True

def same(a, b):
    return samep(a[0], b[0]) and samep(a[1], b[1])

def stat(a, tata):
    if tata[a] == a:
        return a
    x = stat(tata[a], tata)
    tata[a] = x
    return x

def unesc(a, b, tata):
    y = stat(b, tata)
    x = stat(a, tata)
    if x != y:
        tata[x] = y
    return

#fin = open('cerc.in', 'r')
#fout = open('cerc.out', 'w')
fin = sys.stdin
fout = sys.stdout
n = int(fin.readline())
a = []
for i in range(0, n):
    a.append(tuple([int(number) for number in fin.readline().split()]))
#find V
pnt = []
pntc = []
for i in range(0, n):
    for j in range(i + 1, n):
        if a[i][0] != a[j][0] or a[i][1] != a[j][1]:
            a0, a1, a2 = a[i]
            b0, b1, b2 = a[j]
            c0 = 2 * (b0 - a0)
            c1 = 2 * (b1 - a1)
            c2 = -a0 * a0 + -a1 * a1 + a2 * a2 + b0 * b0 + b1 * b1 - b2 * b2
            npoints = []
            if c0 == 0:
                y0 = c2 / c1
                x1 = a2 * a2 - (y0 - a1) * (y0 - a1)
                x0 = math.sqrt(x1) + a0
                npoints.append((-x0, y0), (x0, y0))
            else:
                d0 = -c1 / c0
                d1 = c2 / c0
                e0 = (d0 * d0 + 1)
                e1 = 2 * d0 * (d1 - a0) - 2 * a1
                e2 = (d1 - a0) * (d1 - a0) + a1 * a1 - a2 * a2
                dt = e1 * e1 - 4 * e2 * e0
                if dt >= 0:
                    y0 = (-e1 - math.sqrt(dt)) / (2 * e0)
                    y1 = (-e1 + math.sqrt(dt)) / (2 * e0)
                    x0 = d0 * y0 + d1
                    x1 = d0 * y1 + d1
                    npoints.append((x0, y0))
                    npoints.append((x1, y1))
            for np in npoints:
                g = 0
                for poz in range(0, len(pnt)):
                    if same(pnt[poz], np):
                        g = 1
                        pntc[poz].add(i)
                        pntc[poz].add(j)
                        break;
                if g == 0:
                    pnt.append(np)
                    pntc.append(set({i, j}))
pntc = [list(x) for x in pntc]
V = len(pnt)
#find C
tata = list(range(0, n))
C = 1
for p in range(0, V):
    for i in range(0, len(pntc[p])):
        for j in range(i + 1, len(pntc[p])):
            unesc(pntc[p][i], pntc[p][j], tata)
for p in range(0, n):
    if tata[p] == p:
        C += 1
#find E
E = 0
for p in range(0, V):
    for x in pntc[p]:
        E += 1
F = E + C - V
fout.write(repr(F))
if fin != sys.stdin:
    fin.close()
    fout.close()


c = 97
d = 0
for i in map(ord,input()):
    e = abs(c-i)
    f += min(e,26-e)
    c=i
print(f)


import itertools
import sys

def c(s):
	j = 0
	while j < len(s) / 2:
		if s[j] == s[len(s)-j-1]:
			j += 1
			continue
		else:
			return False
	return True

s = raw_input()
temp = []
for i in range(len(s)):
	temp += list(itertools.combinations(s, i+1))

su = []
for i in range(len(temp)):
	su.append(''.join(temp[i]))

for j in range(len(su)-1, -1, -1):
	if not c(su[j]):
		print len(su[j])
		sys.exit()

if c(su[len(su) - 1]):
	print 0
else:
	print len(s)


"""Template for Python Competitive Programmers prepared by pa.n.ik, kabeer seth and Mayank Chaudhary """

# to use the print and division function of Python3
from __future__ import division, print_function

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""use resource"""
# import resource
# resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])

"""for factorial"""

def prepare_factorial():
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % MOD)
    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], MOD - 2, MOD)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % MOD

    return fact, ifact

"""uncomment next 4 lines while doing recursion based question"""
# import threading
# threading.stack_size(1<<27)
import sys
# sys.setrecursionlimit(10000)

"""uncomment modules according to your need"""
from bisect import bisect_left, bisect_right, insort
# from itertools import repeat
from math import floor, ceil, sqrt, degrees, atan, pi, log, sin, radians
from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
from collections import Counter, defaultdict, deque
# from copy import deepcopy
# from decimal import *
import re
import operator

def modinv(n, p):
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):    # for using this uncomment the lines calculating fact and ifact
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def input(): return sys.stdin.readline().strip()

"""*****************************************************************************************"""

def GCD(x, y):
    while (y):
        x, y = y, x % y
    return x

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

def get_xor(n):
    return [n,1,n+1,0][n%4]

def fast_expo(a, b):
    res = 1
    while b:
        if b&1:
            res = (res * a)
            res %= MOD
            b -= 1
        else:
            a = (a* a)
            a %= MOD
            b>>=1
    res %= MOD
    return res

""" ********************************************************************************************* """

def main():

    fact, ifact = prepare_factorial()
    n, m = get_ints()

    ans = ((ncr(m, n-1, fact, ifact) * (n-2))%MOD * fast_expo(2, n-3))%MOD
    print(ans)

""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

""" main function"""

if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()


# Codeforces Beta Round #40
# Problem B -- Repaintings
n, m = map(int, raw_input().split())
x = input() - 1
print max(n + m - 4 * x) if min(n, m) > 2 * x else 0


t=input()
s=''
if len(t)%2==1:
    i = len(t) // 2
    nap = 0
    for j in range(len(t)):
        if z==1:
            i += j
            z=0
        else:
            i -= j
            z=1
        s+=t[i]
    print(s)
else:
    i = len(t) // 2 - 1
    z=0
    for j in range(len(t)):
        if z==1:
            i += j
            z=0
        else:
            i -= j
            z=1
        s+= t[i]
    print(s)


from math import factorial as fact
n,m = map(int,input().split())

if m>=3:
	print(max(0,n - 2*m),n - fact(m)//(2*fact(m-2)))
else:
	if m==0:
		print(n,n)
	elif m==1:
		print(max(0,n - 2*m),max(0, n-2)))
	elif m==2:
		print(max(0,n - 2*m),max(0, n-3)))


from collections import defaultdict

def solve(s1, s2):
    d = defaultdict(set)
    for t1, t2 in s1:
        d[t1].add(t2)
        d[t2].add(t1)

    ans = set()
    for t1, t2 in s2:
        if d[t1] - {t2} > 0 and d[t2] - {t1} == 0:
            ans.add(t1)
        elif d[t1] - {t2} == 0 and d[t2] - {t1} > 0:
            ans.add(t2)
        elif d[t1] - {t2} > 0 and d[t2] - {t1} > 0:
            return -1

    if len(ans) > 1:
        return 0
    if len(ans) == 1:
        return list(ans)[0]

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

a = set(tuple(sorted([a[i*2], a[i*2+1]])) for i in range(n) if a[i*2] != a[i*2+1])
b = set(tuple(sorted([b[i*2], b[i*2+1]])) for i in range(m) if b[i*2] != b[i*2+1])

ans = min(solve(a, b), solve(b, a))
print(ans)


s = [int(i) for i in raw_input().split()]
f = [int(i) for i in raw_input().split()]
x1 = s[0]
y1 = s[1]
x2 = f[0]
y2 = f[1]

x = abs(x1-x2)
y = abs(y1-y2)
mini = (x+y+2)*2
print max(mini,8)


R = lambda: map(int, input().split())
n = int(input())
arr = [1, 2] + [0] * n
for i in range(2, n):
    arr[i] = arr[i - 1] + arr[i - 2]
for i in range(n):
    arr[i] = (arr[i] + arr[i - 1]) % 1000000007
print(arr[n - 1])


import string
li = map(int,string.split(raw_input()))
flag = 0
if(li[2]>0):
   for i in range(li[0],1000000001,li[2]):
      if(li[1] == i):
         print("YES")
         flag =1
         break
      elif(li[1] < i):
         break
   if(flag!=1):
      print("NO")
elif(li[2]<0):
   for i in range(li[0],-1000000001,li[2]):
      if(li[1] == i):
         print("YES")
         flag =1
         break
      elif(li[1] > i):
         break
   if(flag!=1):
      print("NO")
else:
   if(li[1] == li[0]) : print("YES")
   else: print("NO")


from itertools import combinations
def solve(items,summation):
    l=[]
    for length in range(1, len(items)):
        for subset in combinations(items, length):
            l.append(sum(subset))
            if sum(subset) == summation or (sum(subset)-360) in l or (sum(subset)-720) in l:
                    boole=1
                    return(boole)
x=int(input())
l1=[]
l2=[]
boole=0
for i in range(x):
    s=int(input())
    l1.append(s)
l1.sort()
total=sum(l1)
if total%2==0:
    if total%360==0:
        boole=1
    else:
        boole=solve(l1,total/2)

if boole==1:
    print("YES")
else:
    print("NO")


import string
import math

def ii():
    ii = []
    for s in string.split(raw_input()):
        ii.append(int(s))
    return ii

ii = ii()
n = ii[0]
R = ii[1] * 1.0000001
r = ii[2]

x = 0
if n <= 2:
    x = R / n
else:
    a = math.pi / n
#    print a
    sinA = math.sin(a)
#    print sinA
    x = R * sinA / (1 + sinA)
#    x = int(x)
#print x
if x >= r: print 'YES'
else: print 'NO'


import math

n = input()
n = n.split()
s = eval(n[0])
n = eval(n[1])

alls = []

maxGcd = 1

if n == s:
    print(n)
else:
    for i in range(s,n):
        alls.append(i)

    for i in range(len(alls)):
        if alls[i] != "x":
            count = 2
            #print(n.isdigit())
            while((count * alls[i]) < n):
                #print(alls[(count * alls[i]) - alls[i]],alls[i],count)
                alls[(count * alls[i]) - s] = "x"
                count += 1

    for i in alls:
        if i != "x":
            maxGcd = math.gcd(maxGcd,i)

    #print(alls)

    print(maxGcd)


n, a, b = [int(input() for _ in range(3)]
d = [0]
c = 0

for i in (a, b, a, a, b, a):
    if max(d) >= i:
        d[d.index(max(d))] -= i
    else:
        c += 1
        d += [n - i]

print(c)


#!/usr/bin/python

import os
import sys
from math import log10, factorial
import itertools

mod = 1000000007

def fni(x):
    tmp = mod - 2
    ret = 1
    tt = x
    while (tmp):
        if (tmp & 1):
            ret = (ret * tt) % mod
        tt = (tt * tt) % mod
        tmp >>= 1
    return ret

def solve(f):
    a,b,n = f.read_int_list()
    s = set([a,b])

    c = [1] * (n+1)
    for i in xrange(1, n+1):
        c[i] = (c[i-1] * i) % mod

    ans = 0
    astr, bstr = str(a), str(b)
    lst = [int(''.join(num)) for num in itertools.product([astr,bstr], repeat=int(log10(n))+1)]
    lst += [int(''.join(num)) for num in itertools.product([astr,bstr], repeat=int(log10(n))+2)]

    for i, j in enumerate(xrange(a*n,b*n+1,b-a)):
        if not j in lst: continue
        ans = (ans + c[n] * fni(c[i]) % mod * fni(c[n-i]) % mod) % mod

    print ans

class Reader(object):
    def __init__(self):
        self.f = sys.stdin

    def read_int(self):
        return int(self.f.readline().strip())
    def read_float(self):
        return float(self.f.readline().strip())
    def read_long(self):
        return long(self.f.readline().strip())
    def read_str(self):
        return self.f.readline().strip()

    def read_int_list(self):
        return [int(item) for item in self.f.readline().split()]
    def read_float_list(self):
        return [float(item) for item in self.f.readline().split()]
    def read_long_list(self):
        return [long(item) for item in self.f.readline().split()]
    def read_str_list(self):
        return self.f.readline().split()

if __name__ == '__main__':
    f = Reader()
    solve(f)


def minTax(n, primes):
	if (n==2 or (n in primes)):
		print 1
		return
	elif (n%2==0):
		print 2
		return
	else:
		if (n-2) in primes:
			print 2
			return
		else:
			print 3
			return

n = int(raw_input())

primes = [r for r in xrange(2,n+1)]

for j in primes:
	for i in primes:
		if (i > j):
			if (i%j == 0):
				primes.remove(i)

minTax(n, primes)


a,b=map(int,input().split())
c=1
k=0
if(a==0  or b==0 ):
    print(0)
elif(a==1 and b==1):
    print(0)
else:
    while(c!=0):
        if(a>=b):
            if(a>2):
                b=b+1
                a=a-2
                k=k+1
            else:
                c=0
        elif(a<b):
            if(b>2):
                a=a+1
                b=b-2
                k=k+1
            else:
                c=0
    print(k+1


def len_n(n):
    l = 0
    while n != 0:
        n = n//10
        l += 1
    return l

def sum_n(n):
    l = len_n(n)

    summ = 0
    while n != 0:
        summ += n%10
        n = n//10

    return summ

x = int(input())
max_cifr = sum_n(x)
maxnum = x

for i in range(1, len_n(x)):
    x = x-(10**i)
    #print("x: ",x)
    sx = str(x)
    sx = sx[:len(sx)-i]+'9'+sx[len(sx)-i+1:]
    #print("sx: ", sx)
    x = int(sx)
    if(max_cifr < sum_n(x)):
        max_cifr = sum_n(x)
        maxnum = x

print(maxnum)


a=list(map(int,input().split()))
sort(a)
if a[0]+a[3]==a[2]+[1]: print('YES')
else: print("NO")


import math
from math import floor

a11 = input()
a21 = input()
b11 = input()
b21 = input()

sList = []
sList.append(a11[0])
sList.append(a11[1])
sList.append(a21[0])
sList.append(a21[1])

sList.remove('X')
sList.append(sList[0])
sList.append(sList[1])

pList = []
pList.append(b11[0])
pList.append(b11[1])
pList.append(b21[0])
pList.append(b21[1])

pList.remove("X")

pList = pList[::-1]

s1 = s2 = ""

for i in sList:
    s1+=i
for i in pList:
    s2+=i

if(s1.find(s2) == -1):
    print("NO")

else:
    print("YES")


f = lambda: 'ABC' in 2*(input()+input()[::-1]).replace('X', ' ')

print('NO' if f()^f() else 'YES')


from math import factorial
cat = [1, 1]
p = 10**9 + 7
n = int(input())
for i in range(1, 4000):
    cat.append((cat[-1]*2*(2*i + 1)//(i + 2)) % p)

ans = 0
for i in range(1, n + 1):
    ans += ((((factorial(n))//((factorial(i))*(factorial(n - i)))) % p)  *cat[n - i]) % p
print(ans)


import sys
import math
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

q = inlt()
a = q[0]
b = q[1]

def primeFactors(n):
    l = []
    i = 2
    n1 = n
    while(n1 > 1):
        while((n1 % i) == 0):
            l.append(i)
            n1 = n1 // i

        i = i + 1
    return l

p = primeFactors(a)
q = primeFactors(b)

def count(x,l):
    ct = 0
    for i in l:
        if(i == x):
            ct = ct + 1
    return ct

a1 = count(2,p)
b1 = count(3,p)
c1 = count(5,p)

a2 = count(2,q)
b2 = count(3,q)
c2 = count(5,q)

k = a // (2**a1 * 3**b1 * 5**c1)
j = b // (2**a2 * 3**b2 * 5**c2)

if(k == j):
    sum = 0
    sum = sum + abs(c1 - c2)
    sum = sum + abs(b1 - b2)
    sum = sum + abs(a1-a2)
    print(sum)

else:
    print(-1)


# Description of the problem can be found at http://codeforces.com/problemset/problem/740/A

def getMinCost(c_c, c, l_c, m):
    if (c_c + n) % 4 == 0:
        return c

    for i in range(1, 4):
        if not m or c + l_c[i] < m:
            if m:
                m = min(m, getMinCost(c_c + i, c + l_c[i], l_c, m))
            else:
                m = getMinCost(c_c + i, c + l_c[i], l_c, m)

    return m

n, c1, c2, c3 = map(int, input().split())
l_c = list([0, c1, c2, c3])

print(getMinCost(0, 0, l_c, None))


cms=int(input())
if al==1 or al==0 :
    ans=cms//3
else:
    ans=cms//3+1
feet=ans//12
print(feet,ans%12)


x = int(input())
s  = list(input().split())
k = 0
for i in range(5):
	for j in range(2):
		x[j]=s[i][j]
		k++
if(k!=0):
print("Yes")
else:
print("No")


cardOnTable = input()
myCards = input().split()
for card in myCards:
    if card[1] = cardOnTable[1] or card[0] = cardOnTable[0]:
        print("YES")
        break
else:
    print('NO')


 def solve():
    _ = map(int, input())
    m = list(map(int, input().split()))
    answer = 0
    for i in range(len(m)):
        answer += i*4*m[i]
    return answer

print(solve())


t,n,s=map(int,input().split()
for i in range(n):
    s+=i*4*t
print(s)


die1 = int(raw_input('die 1'))
die2 = int(raw_input('die 2'))
the_die = max(die1, die2)

if the_die == 6:
  print '1/6'
elif the_die == 5:
  print '1/3'
elif the_die == 4:
  print '1/2'
elif the_die == 3:
  print '2/3'
elif the_die == 2:
  print '5/6'
else:
  print '1/1'


n,k,m = list(map(int, input().split()))
t = sorted(map(int, input().split()))
st = sum(t)
res = 0
for x in range(m//st+1):
    rem = m-x*st
    m = x*(k+1)
    # for i in range(k):
        # y = min(rem//t[i], n-x)
        # rem -= t[i]*y
        # m += y
    for i in range(k):
        for _ in range(n-x):
            if rem >= t[i]:
                rem -= t[i]
                m += 1
    res = max(res, m)
print(res)


n,l,r=map(int,input().split())
li=[]
while n>0:
    li+=[n]
    n=n//2
res=[]
for i in range(1,len(li)+1):
    res=res+[li[-i]%2]+res
cnt=0
for i in range(l-1,r):
    if res[i]==1:
        cnt+=1
print(cnt)


def getOne(num):
    if num == 0 or num == 1:
        return [num]
    return getOne(int(num / 2)) + [int(num % 2)] + getOne(int(num / 2))
ip = input()
number = ip.split()
num = int(number[0])
l = int(number[1])
r = int(number[2])
sum = 0
temp = getOne(num)
for i in temp[l -1:r]:
    sum += i
print(sum)


import sys
n,l,r = map(int, input().split())
def rect(n):
    if n <= 1:
        return [n];
    ls = rect(n//2)
    ans = []
    ans.extend(ls)
    ans.extend([n % 2])
    ans.extend(list(reversed(ls)))
    return ans
print(sum(rect(n)[l-1:r]))


n = input().split(' ')
n1 = int(n[0])
m = int(n[1])
while True:
    for i in range(1, n1 + 1):
        if m > i:
            m -= i
        else:
            break
        if i == n1:
            i = 1
    if m < i:
        break
print(m)


walruses,chips=map(int,input().split())
while True:
    for i in range (walruses):
        if chips>i+1:
            chips=chips-(i+1)
        else:
            break
print (chips)


def pos(x):
    global m
    global n
    row=x/m
    column=x%m
    p=[row,column]
    return p
n,m,a,b=(int(i) for i in raw_input().split())
l=pos(a-1)
par=l[0]
pac=l[1]
l=pos(b-1)
pbr=l[0]
pbc=l[1]
if (par==pbr) or ((pac==0) and (pbc==m-1)) or (a==1 and b==n):
    print 1
elif (pac-pbc==1) or (pac==0) or (pbc==m-1) or (a==1) or (b==n) or (pbr-par==1):
    print 2
else:
    print 3
#print par,pac,pbr,pbc


a,m=map(int,input().split())
arr=[]
x=a
new=a%m
arr.append(new)
a+=new
if(new==0):
		print('Yes')
		exit(0)
while(1):
	new=a%m
	if(new==0):
		print('Yes')
		exit(0)
	elif(new==arr[0]):
		print('No')
		exit(0)
	else:
		arr.append(new)
		a+=new


import sys
input = sys.stdin.readline().strip().split(' ')
a = input[0]
b = input[1]

if (a==b): print (a)
else: print 1


def yesorno (number):
    for i in range(11)[2:]:
        if (number%i) == 0:
            return 0
    return 1

countdownload = input()
countprem = 0
for number in xrange(countdownload+1):
    countprem += yesorno(number)
print countprem