n,m,k=map(int,input().split())
ns=list(map(lambda x:int(x),input().split()))
ns.sort()
ns.reverse()
if m<=k:
    print(0)
else:
    m=m-k+1
    i=0
    while i<len(ns):
        m-=ns[i]
        if m<1:
            print(i+1)
            break
        i+=1
        m+=1
    else:
        print(-1)


def poorDragons():
    k = int(input())
    l = int(input())
    m = int(input())
    n = int(input())
    d = int(input())
    cnt = 0
    for i in range(1, d + 1):
        if i % k == 0:
            cnt += 1
        elif i % l == 0:
            cnt += 1
        elif i % m == 0:
            cnt += 1
        elif i % n == 0:
            cnt += 1
    return cnt
if __name__ == '__main__':
	print(poorDragons())


n=int(input())
a=int(input())
b=int(input())
c=int(input())

d=b-c

if a<=d:
    print(n//a)

else:
    lb=0
    ub=n

    while ub-lb>1 :
        mid=(ub+lb)//2
        tmp=n-d*(mid-1)
        if tmp>=b :
            lb=mid
        else :
            ub=mid

    ans=lb
    n-=d*lb
    ans+=n//a
    print(ans)


from collections import Counter

r = lambda: map(int, input().split())

def main():
	n, = r()
	s = input()
	cost = list(r())

	ans = 0

	cnt = Counter()

	for i in range(n // 2):
		if s[i] == s[n - 1 - i]:
			ans += min(cost[i], cost[n - 1 - i])
			cnt[s[i]] += 1
	total = sum(cnt.values())
	if total > 0:
		ch, occ = cnt.most_common(1)[0]
		avail = []
		if occ > total - occ:
			for i in range(n // 2):
				if s[i] != s[n - 1 - i] and s[i] != ch and s[n - 1 - i] != ch:
					avail.append(min(cost[i], cost[n - 1 - i]))
			avail.sort()
			ans += sum(avail[:2 * occ - total])

	print(sum(cost) - ans)

main()


c1=c2=c3=0
a,b=map(int,input().split())
for i in range(1,7):
    if abs(a-i) > abs(b-i):
        c1+=1
    if abs(a-i) == abs(b-i):
        c2+=1
    if abs(a-i) < abs(b-i):
        c3+=1
print(c3,c2,c1)


w, m = map(int, raw_input().split())

ans = True
for i in xrange(101):
    k = m % w
    if k == 1:
        m -= 1
    elif k == w-1:
        m += 1
    elif k == 0:
        pass
    else:
        ans = False
    m /= w
print "YES" if ans else "NO"


r1,c1,r2,c2 = [int(x) for x in input().split(" ")]

# rook
rook = 2
if(r1==r2 or c1==c2): rook = 1

# bishop
bishop = 2
if (r1+c1)%2 != (r2+c2)%2: bishop = 0
elif abs(r2-r1)==abs(c2-c1): bishop=1

# king
king = max([abs(r2-r1),abs(c2-c1)])

print(rook,bishop,king)


import math

n, m = map(int, input().split())
a = [math.ceil(int(i) / m) for i in input().split()]
i = n - 1
while a[i] != max(a):
    i -= 1
print(i + 1)


l,r,a=input().split()
l=int(l)
r=int(r)
a=int(a)
if l<r and a>r-l:
    print(2*(l+(r-l)+(a-(r-l))//2))
elif l<r and a<=r-l:
    print(2*(l+(a)))
elif l>r and a>l-r:
    print(2*(r+(l-r)+(a-(l-r))//2))
elif l>r and a<=l-r:
    print(2*(r+(a)))
elif l==r:
    print(2*(r+(a//2)))


a,b,c = int(input()),int(input()),int(input())
print(min(a,b//2,c//4)*7)


n , m , k = map(int , input().split())
if k >= n and m >= n:
    print("Yes")
else:
    print('No')


def ncr(n, r, p):
    if(r>n):
        return 0
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den, p - 2, p)) % p

def fac(n, p):
    if n >= p:
        return 0
    result = 1
    for i in range(1, n + 1):
        result = (result * i) % p
    return result

n,x,pos=list(map(int,input().split(" ")))
s=g=0

a=0
b=n
while(a<b):
    mid=(a+b)//2
    if(mid<=pos):
        s+=1
        a=mid+1
    else:
        g+=1
        b=mid
p=1000
p=p*p*p+7

print( (ncr(x-1,s-1,p)*fac(s-1,p) * ncr(n-x,g,p)*fac(g,p)* fac(n-s-g,p))%p )


import sys
import math

n = int(input())

x = [0]*n
y = [0]*n

for i in range(n):
    x[i], y[i] = map(int, input().split())

sx = sum(x)
sy = sum(y)

for i in range(n):
    x[i] = n * x[i] - sx
    y[i] = n * y[i] - sy

m = int(input())

d = [0]*n
e = [0]*n

HD = 0

def check(a, b):
    global HD
    HE = 0
    for i in range(n):
        HE ^= hash((a-x[i])*(a-x[i])+(b-y[i])*(b-y[i]))
    return HD == HE

def sqrt(x):
    nn = int(x)
    if nn == 0:
        return 0
    fa, fb = divmod(nn.bit_length(), 2)
    x = 2**(fa+fb)
    while True:
        y = (x + nn//x)//2
        if y >= x:
            return x
        x = y

def hash(x):
    return x * 9991 + 43

pans = []

def solve():
    global d
    d = list(map(int, input().split()))
    c = 0
    d = [p * n * n for p in d]
    for i in range(n):
        c += d[i] - x[i] * x[i] - y[i] * y[i]

    assert(c % n == 0)
    c //= n
    ans = []
    ax = x[0]
    ay = y[0]
    if ax is 0 and ay is 0:
        ax = x[1]
        ay = y[1]
    rev = 0
    if ay == 0:
        ay = ax
        ax = 0
        rev = 1
    d.sort()
    global HD
    HD = 0
    for p in d:
        HD ^= hash(p)
    old = -1
    for p in d:
        if (p == old):
            continue
        old = p
        a = c + ax * ax + ay * ay - p
        if (a % 2 != 0):
            continue
        a //= 2
        A = ax * ax + ay * ay
        B = a * ax
        C = a * a - ay * ay * c
        D = B * B - A * C
        if (D < 0):
            continue
        sD = sqrt(D)
        if D != sD * sD:
            continue
        if (B + sD) % A == 0:
            qx = (B + sD) // A
            qy = (a - ax * qx) // ay
            if rev:
                t = qx
                qx = qy
                qy = t
            if ((qx + sx) % n == 0 and (qy + sy) % n == 0 and check(qx, qy)):
                qx = (qx + sx) // n
                qy = (qy + sy) // n
                ans.append([qx, qy])
        if sD == 0:
            continue
        if (B - sD) % A == 0:
            qx = (B - sD) // A
            qy = (a - ax * qx) // ay
            if rev:
                t = qx
                qx = qy
                qy = t
            if ((qx + sx) % n == 0 and (qy + sy) % n == 0 and check(qx, qy)):
                qx = (qx + sx) // n
                qy = (qy + sy) // n
                ans.append([qx, qy])

    ans.sort()
    buf=[]
    buf.append(len(ans))
    for p in ans:
            buf.append(p[0])
            buf.append(p[1])
    global pans
    pans.append(" ".join(map(str,buf)))

while m > 0:
    m -= 1
    solve()

sys.stdout.write("\n".join(pans))


a=list(map(int,input().split()))
n=a[0]
l=a[1]
r=a[-1]
s=pow(2,r)-1
s1=pow(2,r-1)
sum_c=s+s1*(n-r)
max1=sum_c
s=pow(2,l)-1
sum_b1=s+n-l
min1=sum_b1
print(min1,max1)


from fractions import Fraction as F

a, b, n = map(int, raw_input().split())
frac = F(a, b).limit_denominator(n)
print("{0}/{1}".format(frac.numerator, frac.denominator))


n = int(input())
if n % 2 == 0:
    print('Mahmoud')
elif n % 2 != 0:
    print('Ehab')


a1 = int(input())
a2 = int(input())
k1 = int(input())
k2 = int(input())

n = int(input())

min_players = max(0, n - (a2*(k2-1)+a1*(k1-1)))

max_players = 0

cards_left = n

if k1 > k2:
    t = k1
    k1 = k2
    k2 = t

    t = a1
    a1 = a2
    a2 = t

while a1 > 0 and cards_left - k1 >= 0:

    max_players += 1
    a1 -= 1
    cards_left -= k1
    # print(cards_left, a1, max_players)
while a2 > 0 and cards_left - k2 >= 0:
    max_players += 1
    a2 -= 1
    cards_left -= k2
    # print(cards_left, a2, max_players)

print(min_players, max_players)


# -*- coding: UTF-8 -*-

# from itertools import *
# from collections import defaultdict

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

# def baseN(num,b,numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
#     return ((num == 0) and  "0" ) or ( baseN(num // b, b).lstrip("0") + numerals[num % b])

# T = input()
# St = raw_input()

vags, pos, cont = map(int, raw_input().split())
where = raw_input()
if where == "to tail":
    where = 1
else:
    where = -1

def make_move(pos, where):
    pos = pos + where
    if pos > vags:
        pos = vags-1;
        where = -1
    if pos < 1:
        pos = 2
        where = 1
    return pos, where

stop = raw_input()
for i in xrange(len(stop)):
    if stop[i] == "1":
        cont, where = make_move(cont, where)
        if where == 1:
            pos = 1
        else:
            pos = vags
    else:
        if where == 1:
            if pos>cont:
                if pos != vags:
                    pos += 1
            else:
                if pos != 1:
                    pos -= 1
        else:
            if pos<cont:
                if pos != 1:
                    pos -= 1
            else:
                if pos != vags:
                    pos += 1
        cont, where = make_move(cont, where)
    if pos == cont:
        print "Controller ", i+1
        exit()
print "Stowaway"


def sumInBase(n, base):
    ans = 0
    while n > 0:
        ans += n % base
        n //= base

    return ans

def GCD(a, b):
    if b == 0:
        return a
    return GCD(b, a % b)

# end of our function

n, sumOfAllBase = int(input()), 0

for i in range(2, n):
    sumOfAllBase += sumInBase(n, i)

temp = GCD(sumOfAllBase, n - 2)
print('{}/{}'.format(sumOfAllBase // temp, (n - 2) // temp))


from statistics import mean
from math import factorial, log, ceil

_lf = []
def logfact(n):
    global _lf
    CALCLEN = 2200
    if not _lf:
        _lf = [0]*CALCLEN
        for i in range(2, CALCLEN):
            _lf[i] = _lf[i-1] + log(i)
    return _lf[n]

def unif_ml(xs):
    #p1 = mean(xs)
    p2 = max(xs) / 2
    pmle = p2 #max(p1, p2) # probably actually not mle and biased towards 0
    loglh = len(xs) * log(2*pmle + 1)
    return loglh, pmle

def poiss_ml(xs):
    pml = mean(xs)
    loglh = len(xs)*pml + sum([-x*log(pml) + logfact(x) for x in xs])
    return loglh, pml

def solve(xs):
    ul, Pu = unif_ml(xs)
    pl, Pp = poiss_ml(xs)
    #print('dbg:', ul, pl)
    if ul < pl:
        p = 1.01*Pu
    else:
        p = Pp
    print(ceil(p))

if __name__ == '__main__':
    v = int(input())
    for i in range(v):
        xs = [int(x) for x in input().split()]
        solve(xs)


n,v,e=map(int,raw_input().split())
a=[0]*(n+10)
b=[0]*(n+10)
E=[[] for i in xrange(n)]
f=[i for i in xrange(n)]
vis=[0]*(n+10)
ans=[]
rem=0
def fd(x):
	if f[x]==x: return x
	else:
		f[x]=fd(f[x])
		return f[x]
def dfs2(u,f,ty):
	global rem
	if rem<=a[u] and rem>0:
		if ty==0: ans.append([u,f,rem])
		else: ans.append([f,u,rem])
		a[u]-=rem
		a[f]+=rem
		rem=0
	else:
		rem-=a[u]
		for v in E[u]:
			if v==f or vis[v]: continue
			dfs2(v,u,ty)
			if rem==0: break
		if f!=-1:
			if ty==0: ans.append([u,f,a[u]])
			else: ans.append([f,u,a[u]])
			a[f]+=a[u]
			a[u]=0
def solve(c):
	if a[c]==b[c]: return
	global rem
	if a[c]<b[c]:
		rem=b[c]
		dfs2(c,-1,0)
	else:
		for i in xrange(n): a[i],b[i]=v-a[i],v-b[i]
		rem=b[c]
		dfs2(c,-1,1)
		for i in xrange(n): a[i],b[i]=v-a[i],v-b[i]
def dfs(u,f):
	for v in E[u]:
		if v==f: continue
		dfs(v,u)
	solve(u)
	vis[u]=1
a=map(int,raw_input().split())
b=map(int,raw_input().split())
for i in xrange(e):
	x,y=map(lambda x:int(x)-1,raw_input().split())
	if fd(x)!=fd(y):
		E[x].append(y)
		E[y].append(x)
		f[fd(x)]=fd(y)
for i in xrange(n):
	if fd(i)!=i: continue
	sa=sum(a[j] for j in xrange(n) if (fd(j)==i))
	sb=sum(b[j] for j in xrange(n) if (fd(j)==i))
	if sa!=sb:
		print "NO"
		exit()
	dfs(i,-1)
print len(ans)
for c in ans:
	print c[0]+1,c[1]+1,c[2]


n,m=map(int,raw_input().split())
s=list(raw_input())

for _ in range(m):
    i=0
    while i<n-1:
        if(s[i]=='B' and s[i+1]=='G'):
            s[i],s[i+1]=s[i+1],s[i]
            i+=1
        i+=1
print "".join(s)


def solve(interesting):

	if interesting[0] > 15:
		return 15

	ans = interesting[0]

	for e in interesting[1:]:

		if e - ans > 15:
			return ans + 15
		else:
			ans = e

	return min(ans + 15, 90)

n = input()
interesting = map(int, raw_input().split())
print solve(interesting)


S = 'CODEFORCES'
n = len(S)
s = str(input())
a = False

for i in range(n):
    k = s.find(S[:n - i])
    if k != -1:
        p = k
        while p != -1:
            p = s.find(S[n - i:], p + 1)
            v1 = (k, k + n - i)
            v2 = (p, p + i)
            #print('{} {}'.format(v1, v2))
            if v1[0] == 0 and v2[1] == len(s):
                a = True
            elif (v1[0] == 0 or v2[1] == len(s)) and v2[1] - v1[0] == 10:
                a = True

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


import collections
s = []
def solve(a):
	if a[1]=='>':
		return a[0]
	else:
		return a[2]
s.append(solve(raw_input()))
s.append(solve(raw_input()))
s.append(solve(raw_input()))
s = collections.Counter(s)
r = ['','','']
if len(s)==2:
	for k,v in s.items():
		if v==2:
			r[2]=k
		if v==1:
			r[1]=k
	for i in 'ABC':
		if i not in r:
			r[0]=i
	print ''.join(r)

else:
	print 'Impossible'


line = raw_input()
n=int(line.split()[0])
a=int(line.split()[1])
b=int(line.split()[2])

if (b<0) : condition = 0
else : condition = 1

b = abs(b)
b = b%n
if condition==1:
    print (a+b)%(n+1) + (a+b)/(n+1)
else:
    if (a>b):
        print a-b
    else:
        print n-(b-a)


from itertools import combinations
def out1(a,b,c):
    if a<0 or b<0 or c<0:
        return 0
    if a==1 and b==0 and c==0:
        return 1
    return a*(out2(a-1,b,c)+out3(a-1,b,c))
def out2(a,b,c):
    if a<0 or b<0 or c<0:
        return 0
    if a==0 and b==1 and c==0:
        return 1
    return b*(out1(a,b-1,c)+out3(a,b-1,c))
def out3(a,b,c):
    if a<0 or b<0 or c<0:
        return 0
    if a==0 and b==0 and c==1:
        return 1
    return c*(out2(a,b,c-1)+out1(a,b,c-1))
def column(matrix, i):
    return [row[i] for row in matrix]

N, T = [int(x) for x in input().split()]
A = []
s = 0
for i in range(N):
    A.append([int(x) for x in input().split()])
for i in range(1,N+1):
    comb = list(combinations(A, i))
    for x in comb:
        if sum(column(x,0))==T:
            a = column(x,1).count(1)
            b = column(x,1).count(2)
            c = column(x,1).count(3)
            s+=(out1(a,b,c)+out2(a,b,c)+out3(a,b,c))
print(s%1000000007)


a=input()
def diff(a,b):
    return sum(i!=j for i,j in zip(a,b))
print(a.lower() if diff(a,a.lower())<=diff(a,a.upper()) else a.upper())


a, b = [int(x) for x in input().split()]
ans = 0
while (a != 1 and b != 1):
  if (a > b):
    ans += a // b
    a %= b
  a, b = b, a
ans += a+b-1
print(ans)


import sys

if sys.version_info < (3,0):
    input = raw_input

w, h, k = [ int(x) for x in input().split()]

def num_cells(n, m):
    return 2*n + 2*m - 4

res = 0

for i in range(k):
    res += num_cells(w-4*i, h-4*i)
print(res)


b,a=map(int,raw_input().split())
res=0
dig=1
while(a!=0 or b!=0):
	res+=dig*(((a%3)+3-b%3)%3)
	dig*=3
	a/=3
	b/=3
print res


import math
import operator as op

from functools import reduce

from operator import mul    # or mul=lambda x,y:x*y
from fractions import Fraction

def nCk(n,k):
  return int( reduce(mul, (Fraction(n-i, i+1) for i in range(k)), 1) )

def ncr(n, r):
    r = min(r, n-r)
    if r == 0: return 1
    numer = reduce(op.mul, range(n, n-r, -1))
    denom = reduce(op.mul, range(1, r+1))
    return numer//denom

def modPow(a, x, p):
    #calculates a^x mod p in logarithmic time.
    res = 1
    while(x > 0):
        if( x % 2 != 0):
            res = (res * a) % p

        a = (a * a) % p
        x = int(x/2)
    return res

def modInverse(a, p):
    #calculates the modular multiplicative of a mod m.
    #(assuming p is prime).
    return modPow(a, p-2, p)

def modBinomial(n, k, p):
    #calculates C(n,k) mod p (assuming p is prime).

    # n * (n-1) * ... * (n-k+1)
    numerator = 1
    for i in range(k):
        numerator = (numerator * (n-i) ) % p

    denominator = 1
    for i in range(1, k+1):
        denominator = (denominator * i) % p

    # numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p

n, c = input().split()
n = int(n)
c = int(c)

#test = [0 for x in range (n+1)]
#test[1] = c

#for i in range(2, n+1):
#    test[i] = (test[i-1] + modBinomial((i+c-1),i, 1000003))%1000003

#ans = solve(n, c)
#ans =test[n]
ans = modBinomial((c+n),c,1000003) - 1
print(int(ans))


def Prov(val):
    val=str(val)

    return val==val[::-1]
p,q= map(int,input().split(' '))
pmas = [1 for i in range(2000000)]
pmas[0]=0
pmas[1]=0

for i in range(2,2000000):
    if  pmas[i]==1:
        for j in range(i+i,2000000,i):
            pmas[j]=0

palmas=[1 if Prov(i) else 0
        for i in range(2000000)]
su=0
for i in range(1,2000000):
    if palmas[i]:
        su+=p
    palmas[i]=su
su=0
for i in range(1,2000000):
    if pmas[i]:
        su+=q
    pmas[i]=su
su=0
for i in range(1,2000000):
    if pmas[i]<=palmas[i]:
        su=i
print(su)


x,y,z=map(int,input().split())
a,b,c=map(int,input().split())
fg=0
if a>=x:
    a-=x
    b+=a
    if b>=y:
        b-=y
        c+=b
        if c>=z:print("YES")
        else:print("NO")
    else:print("NO")
else:print("NO")


import sys

n = input()

x = 1
r = 1
D = []
while True:

    r = int(bin(x)[2:])
    x += 1

    if r>n:
        break
    D.append(r)

dp = [[0,0] for i in range(n+1)]

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

    lopt = 10000000

    for j in D:
        if j <= i:

            l = 1+dp[i-j][0]
            r = i-j

            if l < lopt:
                lopt = l
                ropt = r

    dp[i] = [lopt, ropt]

print dp[n][0]

while n != 0:
    print n - dp[n][1],
    n = dp[n][1]


chns='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';

nums=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]

mp={}

for ind, i in enumerate(chns):
    mp[i]=nums[ind]

ans=[]
h, m = input().split(':')
minsys=max([mp[i] for i in (h+m)])+1
for sys in range(minsys,101):
    h10=0
    for pw, i in enumerate(reversed(h)):
        h10+=sys**pw*mp[i]
    m10=0
    for pw, i in enumerate(reversed(m)):
        m10+=sys**pw*mp[i]
    if(h10<=23 and h10>=0 and m10<=59 and m10>=0):
        ans.append(sys)

if 100 in ans:
    print(-1)
    quit()
if len(ans) == 0:
    print(0)
    quit()
for i in ans:
    print(i, end=' ')


n = int(input())
x = input()
normyear = "31 28 31 30 31 30 31 31 30 31 30 31 "
leapyear = "31 29 31 30 31 30 31 31 30 31 30 31 "
ans = 3*normyear + leapyear + 3*normyear
print("Yes" if ans.count(x) else "No")


n, a, b = map(int, raw_input().split())

def get_new_xy(n, a, b):
    A = 6*n
    a1 = a
    b1 = b
    if A <= a * b:
        return a1, b1

    if a<=b:
        a1 = a
        b1 = b
    else:
        a1 = b
        b1 = a

    i = a1
    prev_s = 10000000000000000
    a2 = a1
    b2 = b1
    while i*i <= A:
        tmpb = A / i

        if tmpb < b1:
            i += 1
            continue

        if i*tmpb < A:
            tmpb += 1

        if i*tmpb <= prev_s:
            a2 = i
            b2 = tmpb
            prev_s = a2 * b2
        i += 1

    return (a2, b2) if a <= b else (b2, a2)

a1, b1 = get_new_xy(n, a, b)

print a1*b1
print a1, b1


#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import sys, io
import re, math
start = time.clock()
m=raw_input()
chk=re.compile(r'^\w{1,16}\@\w{1,16}(\.\w{1,16})*(\/\w{1,16})?$')
i=chk.match(m)
#print 'YES' if i else 'NO'
print 'YES' if i else 'NO'


n,k=map(int,raw_input().split())
a=(map(int,raw_input().split()))
b=sorted(a)
x=0
while x<len(b) and k-b[x]>=0:
    k-=b[x]
    x+=1
print x
for i in range(0,x):
    x = a.index(b[i])+1
    print x,
    a[x-1]=-1


def generate_substring(s):
    list = []
    ll = len(string)
    for i in range(ll):
        for j in range(i, ll):
            list.append(s[i:j + 1])
    return list

n = input()
string = raw_input()
ans = 0
sumH = 0
sumW = 0

for x in generate_substring(string):
    sumH = 0
    sumW = 0
    for char in x:
        if char == "U":
            sumH += 1
        if char == "D":
            sumH -= 1
        if char == "L":
            sumW -= 1
        if char == "R":
            sumW += 1
    if sumH == 0 and sumW == 0:
        ans += 1

print ans


def factorize(n):
    m = n
    i = 2
    v = []

    while(i * i <= m):
        while(n % i == 0):
            v.append(i)
            n /= i
        i += 1

    if (n != 1):
        v.append(n)

    return v

if __name__ == "__main__":
    primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
    n = int(raw_input())
    v = factorize(n)
    v.sort(reverse = True)

    m = len(v)
    ans = 10 ** 18 + 1
    for i in range(0, 1 << m):
        b = []
        temp = 1

        for j in range(m):
            if (i & (1 << j)):
                temp *= v[j]
            else:
                b.append(v[j])

        b.append(temp)
        b.sort(reverse = True)

        x = 1
        for j in range(len(b)):
            x *= primes[j] ** (b[j] - 1)

        ans = min(ans, x)

    print ans


k, p = map(int, raw_input().split())
_sum = 0
for i in xrange(1, k+1):
	_sum += int(str(i)+str(i)[::-1])
print _sum%p


p = int(input())
n = list(map(int, input().split()))
f = n.index(p)
s = p - 1 - f
t = n.index(1)
c = p - 1 - t
print(max(f, s, t, c))


import math
def panduan(x1,y1,x2,y2,x3,y3):
    a=(x1-x2)**2+(y1-y2)**2
    b=(x1-x3)**2+(y1-y3)**2
    c=(x3-x2)**2+(y3-y2)**2
    #print a,b,c
    if a==0 or b==0 or c==0:return False;
    if b<c:d=b;b=c;c=d;
    if a<b:d=a;a=b;b=d;
    #print a,b,c
    if a==b+c:return True;
    else: return False;
def fun():
    x1,y1,x2,y2,x3,y3=map(int,raw_input().split())

    if panduan(x1,y1,x2,y2,x3,y3):print "RIGHT";
    elif panduan(x1+1,y1,x2,y2,x3,y3) or panduan(x1,y1+1,x2,y2,x3,y3) or panduan(x1,y1,x2+1,y2,x3,y3) or panduan(x1,y1,x2,y2+1,x3,y3) or panduan(x1,y1,x2,y2,x3+1,y3) or panduan(x1,y1,x2,y2,x3,y3+1) or panduan(x1-1,y1,x2,y2,x3,y3) or panduan(x1,y1-1,x2,y2,x3,y3) or panduan(x1,y1,x2-1,y2,x3,y3) or panduan(x1,y1,x2,y2-1,x3,y3) or panduan(x1,y1,x2,y2,x3-1,y3) or panduan(x1,y1,x2,y2,x3,y3-1):
        print "ALMOST";
    else:print "NEITHER"

if __name__=="__main__":
    fun()


s = input()
val = eval(s)
for i in range(len(s)):
    if s[i] ==  '+':
        j = i + 1
        c = -5
        while j < len(s) and s[j] != '+' and s[j] != '-':
            c *= 10
            j += 1
        val += c
    elif s[i] == '-':
        j = i + 1
        c = 3
        while j < len(s) and s[j] != '+' and s[j] != '-':
            c *= 10
            j += 1
        val += c
print(val)


r, c, n, k = map(int, input().split())
d = [[0 for j in range(c+1)] for i in range(r+1)]
for i in range(n):
    x, y = map(int, input().split())
    d[x][y] = 1
for i in range(1,r+1):
    for j in range(1,c+1):
        d[i][j] = d[i][j] + d[i-1][j] + d[i][j-1] - d[i-1][j-1]
a = 0
for i in range(1,r+1):
    for j in range(1,c+1):
        for x in range(i,r+1):
            for y in range(j,c+1):
                if d[x][y] - d[x][j-1] - d[i-1][y] + d[i-1][j-1] >= k:
                    a += 1

print(a)


#!/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
'''
Created on 13/09/2018

@author: ernesto
'''

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

posibles_jefes = set(range(1, n + 1))
anteriores = set()
posteriores = set()
continuos = [True] * (n + 1)
mencionados = set()
posibles_jefes_mencionados = set()
ultimo_en_salir = [True] * (n + 1)
ultima_salida_inesperada = None

ops = []

if(m > 1):
    for _ in range(0, m):
        s, n_s = [x for x in input().strip().split(" ")]
        n = int(n_s)
        ops.append((s, n))
    for i in range(0, m):
        op, num = ops[i]
        cont = False
        if op == '+':
            cont = not i or (ops[i - 1][0] == '-' and ops[i - 1][1] == num)
            posteriores.add(num)
        if op == '-':
            cont = i == m - 1 or (ops[i + 1][0] == '+' and ops[i + 1][1] == num)
            if num not in mencionados:
                anteriores.add(num)
                ultima_salida_inesperada = num
            posteriores.discard(num)
            ultimo_en_salir[num] &= not posteriores
        continuos[num] &= cont
        mencionados.add(num)
#    print("anteriores {} posteriores {} continuos {} ops {}".format(anteriores, posteriores, continuos, ops))
    if not anteriores and not posteriores:
        assert ultima_salida_inesperada is None
        if ops[0][0] == '+' and ops[-1][0] == '-' and ops[0][1] == ops[-1][1] and continuos[ops[0][1]] and ultimo_en_salir[ops[0][1]]:
            posibles_jefes_mencionados.add(ops[0][1])
    else:
        if not posteriores:
            assert ultima_salida_inesperada is not None
            posibles_jefes_filtrados = list(filter(lambda x:continuos[x] and ultimo_en_salir[x] and ultima_salida_inesperada == x, anteriores))
            assert len(posibles_jefes_filtrados) <= 1
            if(posibles_jefes_filtrados):
                assert posibles_jefes_filtrados[0] == ops[-1][1]
                posibles_jefes_mencionados.add(ops[-1][1])
        else:
            if not anteriores:
                assert ultima_salida_inesperada is None
                posibles_jefes_filtrados = list(filter(lambda x:continuos[x] and ultimo_en_salir[x], posteriores))
#                print("posibles {}".format(posibles_jefes_filtrados))
                assert len(posibles_jefes_filtrados) <= 1
                if(posibles_jefes_filtrados):
                    assert posibles_jefes_filtrados[0] == ops[0][1]
                    posibles_jefes_mencionados.add(ops[0][1])
            else:
                assert ultima_salida_inesperada is not None
#                print("continuos {}".format(continuos))
                posibles_jefes_mencionados = set(filter(lambda x:ultimo_en_salir[x] and continuos[x] and ultima_salida_inesperada == x, anteriores & posteriores))

#    print("posibles jefes menc {}".format(posibles_jefes_mencionados))
    posibles_jefes -= (mencionados - posibles_jefes_mencionados)

print(len(posibles_jefes))
if(len(posibles_jefes)):
    print(" ".join(map(str, sorted(posibles_jefes))))


n = input()
s = raw_input()
ds = s.split(' ')
d = []
sm = 0
for i in xrange(n):
    d.append(int(ds[i]))
    sm += int(ds[i])

#print n, d, sm
div = n + 1

nn = 0
for i in xrange(5):
    tst = sm + i
    if (tst % div)!=0:
        nn+=1

print nn


k = int(input())
q = input()
a = []
result = []
for i in range(97, 123):
    a.append(chr(i))
for (j, t) in enumerate(q):
    if len(result) == k:
        result[len(result) - 1] += q[j:]
        break
    if t in a:
        a.remove(t)
        result.append(q[j])
    else:
        result[len(result) - 1] += t
if len(result) == k:
    print('YES')
    for row in result:
        print(row)
else:
    print('NO')


import bisect
n,m=map(int,input().split())
a=[]
b=[]
for i in range(m):
    s,d,c=map(int,input().split())
    if c>d-s+1:
        print(-1)
        quit()
    l=bisect.bisect_left(b,d)
    a.insert(l,[s,d,c,i+1])
    b.insert(l,d)
ds=list('0' for i in range(n))
for i in range(m):
    s,d,c,mi=a[i]
    c0=0
    for j in range(s,d):
        if ds[j-1]=='0':
            ds[j-1]=str(mi)
            c0+=1
        if c0>=c:
            break
    if c0<c:
        print(-1)
        quit()
    ds[d-1]=str(m+1)
print(' '.join(ds))


n = input()
log = len(n)-1
large = 10**log
luck = (int(n)//large) * large + large
print(luck - int(n))


n = input()
x = input().split()
set_x = set(x)
list_x = list(set_x)
length = len(list_x)
for x in range(length):
    list_x[x] = int(list_x[x])
list_x.sort()
if length > 1:
    diff = abs(list_x[0] - list_x[1])
#print(diff)
#print (list_x)
if length > 2:
    for i in range(length - 1):
        new_diff = abs(list_x[i] - list_x[i+1])
        #print (new_diff)
        if diff == new_diff:
            val = 1
        else:
            val = 0
if length == 2:
    if diff % 2 == 0:
        diff = diff//2
        val = 1
    else:
        val = 1
if length == 1:
    val = -1
if length > 3:
    val = 0
if val == 1:
    print(diff)
elif val == 0:
    print (-1)
else:
    print(0)


n, k = map(int, input().split(" "))
r = 2 * n
g = 5 * n
b = 8 * n
answer = 0
if r > 0:
    answer += r//k
    if r % k != 0:
        answer += 1
if g > 0:
    answer += g//k
    if g % k != 0:
        answer += 1

if b > 0:
    answer += b//k
    if b % k != 0:
        answer += 1

print(answer)


#! /usr/bin/python

def R(v, x, y, c1, c2):
    c1 = max(0, c1 - v/y + v/(x*y))
    c2 = max(0, c2 - v/x + v/(x*y))
    return c1 + c2 <= v - v/x - v/y + v/(x*y)

if __name__ == "__main__":
    debug = False
    c1, c2, x, y = map(int, raw_input().split())
    l = 1
    r = (c1/(x-1) + 1) * x + (c2/(x-1) + 1) * y
    if debug:
        print l, r

    m = 0
    while l<r:
        m = (l+r)/2
        rm = R(m, x, y, c1, c2)
        rm1 = R(m-1, x, y, c1, c2)

        if debug and r - l < 10:
            print l, r, m, rm1, rm

        if not rm1 and rm:
            break
        elif not rm:
            l = m + 1
        else:
            r = m

    print m


N,M = map(int,raw_input().split())

P = {}
Q = {}
for i in range(10001):
    for j in range(1,5):
        P[(i,j)] = set()
        Q[(i,j)] = set()

for i in range(10):
    P[(i,1)].add(i)
    Q[(i,1)].add(i)
for i in range(100):
    P[(i,2)].add(i)
    Q[(i,2)].add(i)
    a,b = i/10,i%10
    next = [a+b,abs(a-b),a*b]
    for j in next:
        P[(j,2)].add(i)
        Q[(i,2)].add(j)
for i in range(1000):
    P[(i,3)].add(i)
    Q[(i,3)].add(i)
    candidate = [((i/100,1),(i%100,2)),((i/10,2),(i%10,1))]
    next = []
    for p,q in candidate:
        for a in Q[p]:
            for b in Q[q]:
                next.append(a+b)
                next.append(abs(a-b))
                next.append(a*b)
    next = set(next)
    for j in next:
        P[(j,3)].add(i)
        Q[(i,3)].add(j)
for i in range(10000):
    P[(i,4)].add(i)
    Q[(i,4)].add(i)
    candidate = [((i/1000,1),(i%1000,3)),((i/100,2),(i%100,2)),((i/10,3),(i%10,1))]
    next = []
    for p,q in candidate:
        for a in Q[p]:
            for b in Q[q]:
                next.append(a+b)
                next.append(abs(a-b))
                next.append(a*b)
    next = set(next)
    for j in next:
        P[(j,4)].add(i)
        Q[(i,4)].add(j)

def f(n,m,p):
    for i in range(10000):
        for j in p[(abs(n-i),4)]:
            print '%04d%04d'%(i,j)
            m -= 1
            if m == 0:
                return

f(N,M,P)


N = 200001
MOD = 1000000007
fact = [1] * N
inv_fact = [1] * N

def ModExp(a, n):
    ans = 1
    while n:
        if n % 2:
            ans = (ans * a) % MOD
        a = (a * a) % MOD
        n /= 2
    return ans

def ModInverse(a):
    return ModExp(a, MOD - 2)

def PreProcess(n):
    for i in range(1, n + 1):
        fact[i] = (i * fact[i - 1]) % MOD

    inv_fact[n] = ModInverse(fact[n])
    for i in range(n - 1, 0, -1):
        inv_fact[i] = ((i + 1) * inv_fact[i + 1]) % MOD

def nCr(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    else:
        return (fact[n] * (inv_fact[r] * inv_fact[n - r]) % MOD) % MOD

def Beggar(m, n):
    if m < 0 or n < 0 or (n == 0 and m != 0):
        return 0
    else:
        if m + n == 0:
            return 1
        else:
            return nCr(m + n - 1, m)

f, w, h = map(int, raw_input().split())
n = f + w

PreProcess(n)

q = nCr(n, w)
p = 0

for n in range(0, w + 1):
    if n * (h + 1) > w:
        break
    else:
        p += (Beggar(w - n * (h + 1), n) * ((Beggar(f - n - 1, n + 1) + Beggar(f - n + 1, n - 1) + 2 * Beggar(f - n, n)) % MOD)) % MOD

q = ModInverse(q)
ans = (p * q) % MOD

print ans


s=[]
response='NO'
for _ in range(4):
    s=s+[input()]
wins=['xx.','x.x','.xx','xxx']
for i in range(4):
    if s[i][1:] in wins or s[i][:3] in wins:
        response='YES'
    if i>1:
        for j in range(4):
            if s[i-2][j]+s[i-1][j]+s[i][j] in wins:
                response='YES'
for i in range(1,3):
    for j in range(1,3):
        if s[i-1][j-1]+s[i][j]+s[i+1][j+1] in wins or s[i-1][j+1]+s[i][j]+s[i+1][j-1] in wins or s[i-1][j+1]+s[i][j]+s[i+1][j-1] in wins:
            response='YES'
print(response)


from sys import stdin, stdout

def solution():

    reference = stdin.readline()

    cards = [str(x) for x in stdin.readline().rstrip().split()]

    for i in cards:

    	if i[0]==reference[0] or i[1]==reference[1]:
    		return 'YES'

    return 'NO'

print(solution())


n=int(input())
s=input()
num=0
color=s[0]
for i in range(1,n):
    if s[i]==color:
        num+=1
    else:
        color=s[i]
print(num)


import io,os
#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def nextstep(i,j,m,n,grid,ans):
    if grid[i][j]=='*':  ans[0] += 1

    if i==m-1:   return i,j+1
    if j==n-1:   return i+1,j
    if grid[i+1][j] == '*' and grid[i][j+1]=='.':  return i+1,j
    return i,j+1

def main(t):

    m,n = map(int,input().split())
    grid = []
    for i in range(m):
        grid.append(input())

#    print(grid)

    x,y = 0,0
    ans = [0]
    while x<=m-1 and y <= n-1:
#        print(x,y)
        x,y = nextstep(x,y,m,n,grid,ans)

#        print(x,y)

    print(ans[0])

T = 1 #int(input())
t = 1
while t<=T:
    main(t)
    t += 1


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---####################################

n=int(z())

if n%2==0:
    print(n//2+1)
else:
    print((n+1)//2)


st = raw_input()
ans = 'YES'
s = {'a'}
if st[0] != 'a':
	ans = 'NO'
for i in st:
	if (i not in s) and (ord(i)-ord(max(s))>1):
		ans = 'NO'
		break
	s |= {i}
print ans


a=str(input())
i=1
c=str()
if len(a)==1:
    print(a)
else:
    if len(a)%2 == 1:
        for i in range(0,(len(a)//2)):
            c=a[-i-1]+a[i]+c
        print(a[len(a)//2]+c)
    else:
        for i in range(0,(len(a)//2)):
            c=a[i]+a[-i-1]+c
        print(c)


def f(n):
    if n < 4: return '1\n0'
    k, j = int(n ** 0.5), 0
    if n % 2 == 0:
        if n % 4 == 0: return '1\n4' if n > 4 else '2'
        j = 2
    if n % 3 == 0:
        if j: return '1\n6' if n > 6 else '2'
        if n % 9 == 0: return '1\n9' if n > 9 else '2'
        j = 3
    for i in range(5, k, 6):
        if n % i == 0:
            if j: return '1\n' + str(i * j)
            if n % (i * i) == 0: return '1\n' + str(i * i)
            j = i
    for i in range(7, k, 6):
        if n % i == 0:
            if j: return '1\n' + str(i * j)
            if n % (i * i) == 0: return '1\n' + str(i * i)
            j = i
    return '2' if j or k * k == n else '1\n0'
print(f(int(input())))


#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import sys
import io
import re
import math
import itertools
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.141592653589
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
#start = time.clock()
chk=[2,7,2,3,3,4,2,5,1,2]
n=raw_input()
if len(n)<2:
    print 10*chk[int(n)]
else:
    print chk[int(n[0])]*chk[int(n[1])]


def gcd(x,y):
    if y==0:return x
    else:return gcd(y,x%y)
A,H,W=map(int,input().split())
G=gcd(A+H,A+W)
S=(A+W)//G
T=((W//A+1)//S)*S-1
if T<=0:print(-1)
else:print("%.10lf"%((W-T*A)/(T+1)))


def raw():
    return raw_input().strip()

def ints():
    return map(int, raw().split())

n = ints()[0]

if n == 1:
    print 1
    exit(0)

r = n

for i in xrange(2, n):
    r += i * (n - (i - 1)) - (i - 1)
r += 1

print r


n=int(input())
dic={}
for i in range(1,n+1):
    dic[i*i]=0
ans=0
for i in range(1,n+1):
    for j in range(i,n+1):
        if (i*i)+(j*j) in dic:
            ans+=1
print(ans)


def ceildiv(a, b):
    return -(-a // b)

def test_ceildiv():
    assert ceildiv(6, 3) == 2
    assert ceildiv(7, 3) == 3
    assert ceildiv(5, 3) == 2

def brute_force(n, m):
    """Count numbers in range [0; m] equal to 4a + 9b + 49c

    ...for some non-negative a, b and c such that (a + b + c) <= n
    """
    numbers = set()

    max_c = min(n, m // 49)
    for c in range(max_c + 1):
        _49c = 49 * c
        max_b = min(n - c, (m - _49c) // 9, 48)
        for b in range(max_b + 1):
            _9b_49c = 9 * b + _49c
            max_a = min(n - b - c, (m - _9b_49c) // 4, 8)
            for a in range(max_a + 1):
                numbers.add(4 * a + _9b_49c)

    assert 0 in numbers
    for x in (4, 9, 49):
        if m // x <= n:
            assert m - (m % 49) in numbers
    return len(numbers)

def brute_force_range(n, l, u):
    """Count numbers in range [l; u] equal to 4a + 9b + 49c

    ...for some non-negative a, b and c such that (a + b + c) <= n
    """
    numbers = set()

    min_c = max(0, ceildiv(l - 9 * n, 40))
    max_c = min(n, u // 49)
    for c in range(min_c, max_c + 1):
        _49c = 49 * c
        min_b = max(0, ceildiv(l - 4 * n - 45 * c, 5))
        max_b = min(n - c, (u - _49c) // 9, 48)
        for b in range(min_b, max_b + 1):
            _9b_49c = 9 * b + _49c
            min_a = max(0, ceildiv(l - _9b_49c, 4))
            max_a = min(n - b - c, (u - _9b_49c) // 4, 8)
            for a in range(min_a, max_a + 1):
                numbers.add(4 * a + _9b_49c)

    if numbers:
        assert min(numbers) >= l
        assert max(numbers) <= u
    return len(numbers)

def test_brute_force_range():
    for (u, l) in ((60, 80), (104, 599), (200, 777)):
        for n in (10, 13, 15, 17, 20):
            assert brute_force_range(n, u, l) == brute_force(n, l) - brute_force(n, u - 1)

# For each m in rage [Y, Y + 49) exist integer a >= 0 and b >= 0
# such that 4a + 9b = m and a + b <= X
X = 12
Y = 24

def solid_interval(n):
    assert n >= X
    return Y, 49 * (n - X) + Y + 49

def test_solid_interval():
    for n in X, X + 1, 100, 200, 300, 1000, 5000:
        begin, end = solid_interval(n)
        assert brute_force_range(n, begin, end - 1) == end - begin

def main():
    n = int(input())

    if n < X:
        result = brute_force(n, 49 * n)  # naïve solution
    else:
        begin, end = solid_interval(n)
        assert begin < end < 49 * n
        result = sum((
            brute_force_range(n, 0, begin - 1),
            end - begin,  # == brute_force_range(n, begin, end - 1)
            brute_force_range(n, end, 49 * n)
        ))

    print(result)

if __name__ == '__main__':
    main()


M, N = 998244353, 720720
I = lambda: [int(x) for x in input().split()]
p = [0]*(N+1)
res = 0

n, a, x, y, k, U = I()
for i in range(1, n+1):
    p[a%N] += 1
    res += a//N * N
    a = (a * x + y) % U

res = (res * pow(n, k-1, M) * k) % M
for i in range(1, k+1):
    tot = sum(p[j]*j for j in range(1, N+1)) % M
    for j in range(1, N + 1):
        t1 = p[j]
        p[j] *= (n-1)
        p[j] %= M
        p[j - j%i] += t1
    res += (tot * pow(n, k-i)) % M

print(res % M)


if __name__ == '__main__':
    for _ in range(int(input())):
        n=int(input())
        x=len(str(n))
        y=int(str(n)[0])
        print(int(10*y-10+(x*x+x)/2))


"""inf = open("in.txt", "r")
outf = open("out.txt", "w")
#---------------------------#
"""
lst = []
k = 0

n = input()
for i in range(n):
    lst.append(raw_input().split())

for i in range(n):
    for j in range(i + 1,n):
        if lst[i][0] == lst[j][1]:
            k += 1
        if lst[i][1] == lst[j][0]:
            k += 1

print k

#-----------#
#outf.close()


l, r, x, y, k = map(int, input().split())
L = x - 1
R = y + 1
while (R - L > 1):
    M = (L + R) // 2
    if (M * k <= r):
        L = M
    else:
        R = M
if (L * k >= l and L != x - 1):
    print("YES")
else:
    print("NO")


R=lambda:list(map(int,input().split()))
k,l=R(); n=R(); m=sorted(R())
n[n.index(0)]=m[0]
print(['YES','NO'][l==1 and n==sorted(n)])


numbers = input()
a, b = numbers.split(" ")
if((int(b)-int(a))>=10):  print(0)
else :
    res = 1
    for i in range(int(a)+1,int(b)+1): res*=i
    print(str(res)[len(str(res))-1])


from fractions import gcd
import math
x,y=map(int,raw_input().split())
temp=x
p=1
res=[]
def solve(n):
    res = []
    if n % 2 == 0: res.append(2)
    while n % 2 == 0: n=n/2
    for i in range(3, int(math.sqrt(n) + 1), 2):
        if n % i == 0:
            res.append(i)
        while n % i == 0: n //= i
    if n > 2: res.append(n)
    return res

res=solve(x)

ans=0
while y!=0:
    r=gcd(x,y)
    x//=r
    y//=r
    m=0
    for i in res:
        if x%i==0: m=max(m,y-y%i)
    ans+=y-m
    y=m
print ans


n=int(input())
a=int(input())
b=int(input())
c=int(input())

pos = 1
steps=0
for i in range(n-1):
    if pos == 1:
        if a>b:
            pos=2
            steps+=b
        else:
            pos=3
            steps+=a
    elif pos == 2:
        if b>c:
            pos=3
            steps+=c
        else:
            post=1
            steps+=b
    elif pos == 3:
        if a>c:
            pos=2
            steps+=c
        else:
            pos=1
            steps+=a
print(steps)


import sys,math

if __name__ == '__main__':
	value = int(raw_input())
	walk = 0
	while walk <= 20:
		if '8' in str(value) and walk > 0:
			print walk
			break
		else:
			value += 1
			walk += 1


class Solver:
    def __init__(self):
        pass

    def solve(self):
        n, k = map(int, input().split())
        s = input()
        dp = [[[False for _ in range(n+1)] for _ in range(n+1)] for _ in range(n+1)]
        dp[0][0][0] = True
        for pos in range(n):
            for streak in range(n+1):
                for mx in range(n+1):
                    if not dp[pos][streak][mx]:
                        continue
                    #print(pos, streak, mx)
                    if s[pos] == 'N' or s[pos] == '?':
                        dp[pos+1][streak+1][max(mx, streak+1)] = True
                    if s[pos] == 'Y' or s[pos] == '?':
                        dp[pos+1][0][mx] = True
        for streak in range(n+1):
            if dp[n][streak][k]:
                print('YES')
                return
        print('NO')

if __name__ == '__main__':
    s = Solver()
    s.solve()


#507B

from math import ceil
r,x,y,x1,y1=map(int,raw_input().split())
dis=(((x1-x)**2)+((y1-y)**2))**0.5
print int(ceil(dis/(2*r)))


n = int(raw_input())
s = raw_input()
d = [[[-1] * (n + 1) for i in range(n + 1)] for j in range(n + 1)]
def f(a, b, c):
    if a < 0 or b < 0 or c < 0:
        return 0
    if (a, b, c) == (1, 0, 0):
        return 1
    if (a, b, c) == (0, 1, 0):
        return 2
    if (a, b, c) == (0, 0, 1):
        return 4
    if d[a][b][c] == -1:
        res = 0
        if a > 1:
            res |= f(a - 1, b, c)
        if b > 1:
            res |= f(a, b - 1, c)
        if c > 1:
            res |= f(a, b, c - 1)
        res |= f(a - 1, b - 1, c + 1) | f(a + 1, b - 1, c - 1) | f(a - 1, b + 1, c - 1)
        d[a][b][c] = res
    return d[a][b][c]

p = [s.count('B'), s.count('G'), s.count('R')]
for i in range(3):
    if p[i] > 10:
        p[i] = 3
z = f(*p)
RGB = 'BGR'
print ''.join([RGB[i:i+1] for i in range(3) if ((1 << i) & z)])


import math
a,b = list(map(int,input().split()))
print(math.factorial(min(a,b)))


m = int(raw_input())

def num_zeroes(n):
    z = 0
    d = 5
    while n >= d:
        z += n / d
        d *= 5
    return z

def get_elem(i):
    return 5 * i

def inv_bin(get_elem, get_val, start, end, target):
    while start <= end:
        mid = (start + end) / 2
        elem_mid = get_elem(mid)
        val_mid = get_val(elem_mid)
        if val_mid == target:
            return elem_mid, mid
        if val_mid > target:
            end = mid - 1
        else:
            start = mid + 1
    return -1, -1

result, _ = inv_bin(get_elem, num_zeroes, 0, m, m)
if result == -1:
    print 0
else:
    print 5
    print " ".join(map(str, range(result, result + 5)))


# cf 177 A2 700
n = int(input())
A = []
for _ in range(n):
    A.append(list(map(int, input().split())))
sum_ = 0
for i in range(len(A)):
    sum_ += A[i][i]      # main diag
    sum_ += A[(n - 1) - i][i]  # sec diag
    sum_ += A[(n - 1) // 2][i] # middle row
    sum_ += A[i][(n - 1) // 2] # middle col
sum_ -= 3 * A[(n - 1) // 2][(n - 1) // 2]

print(sum_)


n,a,b=map(int,input().split())
l=list(map(int,input().split()))
c=min(a,b)
ans=0
for i in range(len(l)):
    if l[i]==0 and l[len(l)-i-1]==1:
        ans=-1
        break
    elif l[i]==2:
        if l[len(l)-i-1]==0:
            ans+=a
        elif l[len(l)-i-1]==1:
            ans+=b
        else :
            ans+=c
print(ans)


a,b=map(int,input().split())
c,d=map(int,input().split())
e,f=map(int,input().split())

x1,y1=(c+e)-a,(d+f)-b
x2,y2=(e+a)-c,(b+f)-d
x3,y3=(a+c)-e,(b+d)-f
print(3)
print(x1,y1)
print(x2,y2)
print(x3,y3)


def getPower(a, b):
    if (b == 0):
        return 1
    if (b == 1):
        return a
    result = 1
    while(b > 0):
        if (b % 2 != 0):
            result *= a
            result = result%1000000007
        a *= a
        a = a%1000000007
        b /=2
    return result

n = int(raw_input())
k = getPower(2, n)
x = ((k * (1 + k)) / 2)%1000000007
print x


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

def solve(n, num):
    ans = 0
    keta_num = num.bit_length()
    keta_n = n.bit_length()
    keta_diff = keta_n - keta_num
    if keta_diff < 0:
        return ans
    ans += (1 << keta_diff) - 1
    if (n >> keta_diff) > num:
        ans += 1 << keta_diff
    elif (n >> keta_diff) == num:
        ans += n & (((1 << keta_diff) - 1))
        ans += 1
    return ans

ok = 0
ng = n + 10
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    val = mid * 2 + 1
    if solve(n, val) >= k:
        ok = mid
    else:
        ng = mid
ans1 = ok*2 + 1

ok = 0
ng = n + 10
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    val = mid * 2
    if solve(n, val) + solve(n, val + 1) >= k:
        ok = mid
    else:
        ng = mid
ans2 = ok*2

print(max(ans1, ans2))


n = input()
# t = [int(x) for x in input().split()]

if("H" in n or "Q" in n or "9" in n):
  print("YES")
else:
  print("NO")


n, a, b = map(int, input().split())
la = list(map(int, input().split()))
lb = list(map(int, input().split()))
ans = []
for i in range(1, n + 1):
    if i in la:
        print(1, end=' ')
    else:
        print(2, end=' ')


U=1
D=-1
x,y=map(int,input().split())
k=A=B=0
while 1:
	a,b=U,B;k+=1
	if (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break
	A=a;b=U;k+=1
	if (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break
	B=b;a=D;k+=1
	if (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break
	A=a;b=D;k+=1
	if (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break
	A,B=a,b
	U+=1;D-=1
if k<1:k=1
print(k-1)


from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter

def read():
    return int(input())

def readmap():
    return map(int, input().split())

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

def is_valid(field, i, j):
    for k in range(3):
        for l in range(3):
            if k == 1 and l == 1:
                continue
            if field[i+k][j+l] == ".":
                return False
    return True

def fill_sgn(i, j):
    for k in range(3):
        for l in range(3):
            if k == 1 and l == 1:
                continue
            sgn[i+k][j+l] = "#"

n, m = readmap()
arr = []
sgn = []
for _ in range(n):
    arr.append(list(input()))
    sgn.append(["."] * m)

for i in range(n-2):
    for j in range(m-2):
        if is_valid(arr, i, j):
            fill_sgn(i, j)

if arr == sgn:
    print("yes")
else:
    print("no")


def solve(s):
    if len(str(s)) == 1:
        return s
    ans1 = solve(s // 10)
    ans2 = solve(s // 10 - 1)
    return max(ans1 * (s % 10), ans2 * 9, 9)

n = int(input())

print(solve(n))


n,k=map(int,input().split())
if k%2==1:
    print(1)
else:
    mid=2**(n-1)
    if k==mid:
        print(n)
    else:
        if k<mid:
            t=k
        else:
            t=2**(n-1)-k
        p=0
        while t%2==0:
            p+=1
            t=t//2
        print(p+1)


n, d = map(int, input().split())
a = list(map(int, input().split()))
ans = n - 1
a.sort()
for l in range(n):
    for r in range(l, n):
        if a[r] - a[l] <= d:
            ans = min(ans, l - 1 + (n - r))
print(ans)


n = int(input())
print("0 0 {}".format(n))


def power(number, pow):
    if (pow == 0): return 1
    if (pow%2 == 0): return power((number*number)%1000000007,(pow/2)%1000000007)
    else: return (number%1000000007)*(power(number,pow-1))%1000000007

n = int(raw_input())
print (power(3,3*n)-power(7,n))%1000000007


input()
r = []
for x in list(map(int, input().split()))[::-1]:
    if not x in r:
        r.append(x)
print(len(r))
print(*r[::-1])


n=int(input())
a1,a2,a3=map(int,input().split())
b1,b2,b3=map(int,input().split())
minwin=n-(min(a1,b1+b3))-(min(a2,b1+b2))-(min(a3,b2+b3))
maxwin=min(a1,b2)+min(a3,b1)+min(a2,b3)
print(minwin,maxwin)


from sys import exit

def transpose(field):
	result = ["" for i in xrange(10)]

	for i in xrange(10):
		for j in xrange(10):
			result[j] += field[i][j]

	return result

def skew_diagonally_NWSE(field):
	result = []

	for i in xrange(-10, 10):
		result.append("")

		for j in xrange(20):
			x = j
			y = i + j

			if x >= 0 and x < 10 and y >= 0 and y < 10:
				result[-1] += field[x][y]

	return result

def skew_diagonally_SWNE(field):
	result = []

	for i in xrange(20):
		result.append("")

		for j in xrange(-10, 10):
			x = j
			y = i - j

			if x >= 0 and x < 10 and y >= 0 and y < 10:
				result[-1] += field[x][y]

	return result

original_field = []

for i in xrange(10):
	original_field.append(raw_input())

transposed_field = transpose(original_field)

skewed_field_1 = skew_diagonally_NWSE(original_field)

skewed_field_2 = skew_diagonally_SWNE(original_field)

for field in (original_field, transposed_field, skewed_field_1, skewed_field_2, ):
	for row in field:
		if 'XXXX.' in row or 'XXX.X' in row or 'XX.XX' in row or 'X.XXX' in row or '.XXXX' in row:
			print "YES"
			exit(0)

print "NO"


import sys
input = sys.stdin.readline

n, a, x, b, y = map(int, input().split())
while a != x and b != y:
    a += 1
    b -= 1
    if a > n:
        a = 1
    if b < 1:
        b = n
    if a == b:
        print('YES')
        sys.exit()
print('NO')


from collections import defaultdict
from collections import deque

def buildG(n):
    adj = defaultdict(set)
    for i in xrange(len(n)):
        for j in xrange(i + 1, len(n)):
            if abs(ord(n[i]) - ord(n[j])) != 1:
                adj[n[i]].add(n[j])
                adj[n[j]].add(n[i])
    return adj

def ff(s):

    n = list(set(s))

    adj = buildG(n)
    q = deque([n[0]])
    res = []
    visited = set()
    while len(q) > 0:
        nn = q.popleft()
        if nn in visited:
            continue
        visited.add(nn)
        res.append(nn)
        for nnn in adj[nn]:
            q.append(nnn)
    if len(res) < len(n):
        return "No answer"
    CC = defaultdict(int)
    for c in s:
        CC[c] += 1
    aa = []
    for r in res:
        aa.append(r * CC[r])

    return "".join(aa)

# print ff("abcd")
#
#
# T = input()
# for t in xrange(T):
#     s = raw_input()
#     print ff(s)

N = input()
arr = map(int, raw_input().split(" "))

def haha(A):
    t = 0
    for i in xrange(len(A) - 1):
        f, s = A[i], A[i + 1]
        # 1 - circle
        # 2 - triangle
        # 3 - square
        if f == 2 and s == 3:
            return "Infinite"
        if s == 2 and f == 3:
            return "Infinite"

        if f == 1:
            if s == 2:
                if i - 1 >= 0 and A[i - 1] == 3:
                    t += 2
                else:
                    t += 3
            if s == 3:
                t += 4
        if f == 2:
            if s == 1:
                t += 3
        if f == 3:
            if s == 1:
                t += 4
    return t

r = haha(arr)
if type(r) == int:
    print "Finite"
    print r
else:
    print r


n = int(input())
s = input()
print( int(((s[::-1].replace('R', '0')).replace('B', '1')), base = 2))


#rock pair scissor
f = input();
m = input();
s = input();
if f=='rock' and m=='scissors' and s=='scissors':
    print('F')
elif m=='rock' and f=='scissors' and s=='scissors':
    print('M')
elif s=='rock' and f=='scissors' and m=='scissors':
    print('S')
elif f=='scissors' and m=='paper' and s=='paper':
    print('F')
elif m=='scissors' and f=='paper' and s=='paper':
    print('M')
elif s=='scissors' and f=='paper' and m=='paper':
    print('S')
elif f=='paper' and m=='rock' and s=='rock':
    print('F')
elif m=='paper' and f=='rock' and s=='rock':
    print('M')
elif s=='paper' and f=='rock' and m=='rock':
    print('S')
else:
    print('?')


def gcd(m,n):
    if(n==0):
        return m
    return gcd(n,m%n)

n=int(input())
if(n%2==0):
    t=int(n/2)
    i=1
    while(i<t):
        if(gcd(t-i,t+i)==1):
            print(t-i,t+i)
            break
        i+=1
else:
    t=int(n/2)
    i=1
    j=0
    while(t+i<n):
        if(gcd(t-j,t+i)==1):
            print(t+1-i,t+i)
            break
        i+=1
        j+=1


def main():
    n1,b1 = map(int,input().split())
    x = [int(i) for i in input().split()][::-1]
    n2, b2 = map(int, input().split())
    y = [int(i) for i in input().split()][::-1]
    xan,yan = 0,0
    for i , ii in enumerate(x):
        xan += ii*b1**i
    for i, ii in enumerate(y):
        yan += ii*b2** i
    if xan > yan:
        print(">")
    else:
        print("=" if yan == xan else "<")
if __name__ == '__main__':
    main()


x,y,z=map(int,raw_input().split())
x1,y1,z1=map(int,raw_input().split())
a=map(int,raw_input().split())
res=0
if z>z1:
    res+=a[3]
if y>y1:
    res+=a[1]
if x>x1:
    res+=a[5]
if z<0:
    res+=a[2]
if y<0:
    res+=a[0]
if x<0:
    res+=a[4]
print res


from sys import stdin,stdout
for _ in range(1):#int(stdin.readline())):
    # n=int(stdin.readline())
    moves,left=list(map(int,stdin.readline().split()))
    # ATE=?
    l=1;r=10**9+1
    while l<=r:
        mid=(l+r)>>1
        fx=(mid*(mid+1))//2-left+mid
        # print(l,r,mid)
        if fx<=moves:l=mid+1
        else:r=mid-1
    print(moves-r)


from collections import deque
def readarray(foo): return [foo(x) for x in raw_input().split()]

stairs = []
to = []
color = []
totalcolors = 0
deg = []
priority = []

extrastairs = []
extrastair = None

def doit():
	usedstairs = set()
	visited = set([0])
	stack = []
	res = []
	nextcolor = 1

	s = 0
	if extrastair is not None:
		(s, stair) = extrastair
		visited.add(s)
		usedstairs.add(stair)
		nextcolor += 1
		res.append([0])
		res.append([stair, 0, s])

	hasnextcolor = totalcolors > nextcolor
	layer = [s]
	stack.append([s, -1, -1, 0])

	while stack:
		(u, source, parent, start) = state = stack[-1]

		nexti = None
		nexts = None
		nextv = None
		for i in xrange(start, len(to[u])):
			s = to[u][i]
			if s == source: continue
			if s in usedstairs: continue
			(v1, v2) = stairs[s]
			v = v1 if v2 == u else v2
			if not hasnextcolor and v in visited: continue
			nexti = i
			nexts = s
			nextv = v
			break

		if nexti is None:
			if parent != -1:
				layer.append(parent)
			stack.pop()
			continue

		if nextv not in visited:
			visited.add(nextv)
			layer.append(nextv)
			state[3] = nexti
			stack.append([nextv, nexts, u, 0])
			continue

		usedstairs.add(nexts)
		nextv = priority[nextcolor]
		nextcolor += 1
		hasnextcolor = totalcolors > nextcolor

		res.append(layer)
		res.append([nexts, u, nextv])
		layer = [nextv]
		visited.add(nextv)

		state[3] = nexti + 1
		stack.append([nextv, nexts, u, 0])

	res.append(layer)
	return res if not hasnextcolor else None

def colorize(s, c):
	if color[s] != -1: return
	global totalcolors
	totalcolors += 1
	color[s] = c
	deg[c] = 1
	q = deque()
	q.append(s)
	source = {s : -1}
	while q:
		u = q.popleft()
		for stair in to[u]:
			if extrastair is not None and extrastair[1] == stair: continue
			(v1, v2) = stairs[stair]
			v = v1 if v2 == u else v2
			if color[v] != -1:
				if v != source[u]:
					extrastairs.append(stair)
				continue
			color[v] = c
			source[v] = u
			deg[c] += 1
			q.append(v)

def findextrastair():
	if extrastairs: return (stairs[extrastairs[0]][0], extrastairs[0])
	for u in xrange(len(to)):
		if len(to[u]) < 2: continue
		return (u, to[u][0])
	return None

def run():
	global to, color, deg, priority, extrastair, totalcolors
	n, m = readarray(int)
	to = [[] for i in xrange(n)]
	color = [-1] * n
	deg = [0] * n
	for i in xrange(m):
		u, v = sorted(readarray(lambda x: int(x) - 1))
		stairs.append((u, v))
		to[u].append(i)
		to[v].append(i)
	for i in xrange(n):
		colorize(i, i)

	if deg[0] == 1 and n > 1:
		extrastair = findextrastair()
		if extrastair is None:
			print "NO"
			return
		color = [-1] * n
		deg = [0] * n
		totalcolors = 0
		for i in xrange(n):
			colorize(i, i)
		deg[color[extrastair[0]]] = 100500

	deg[0] = 100500
	priority = sorted(range(n), lambda x, y: deg[y] - deg[x])[:totalcolors]
	res = doit()
	if res is None:
		print "NO"
		return

	print "YES"
	print len(res) / 2
	for i, line in enumerate(res):
		if i % 2 == 0:
			print len(line),
		print " ".join(map(lambda x: str(x + 1), line))

run()


mod, sx, sy, dx, dy, t = map(int, input().split())
class Matrix():
    def __init__(self, n):
        self.n = n
        self.a = [[0] * n for _ in range(n)]

    def __mul__(self, b):
        res = Matrix(self.n)
        for i in range(self.n):
            for j in range(self.n):
                for k in range(self.n):
                    res.a[i][j] += self.a[i][k] * b.a[k][j] % mod
                    res.a[i][j] %= mod
        return res

    def __pow__(self, e):
        res = Matrix(self.n)
        for i in range(self.n):
            res.a[i][i] = 1
        tmp = self
        while e:
            if e & 1:
                res = res * tmp
            e >>= 1
            tmp = tmp * tmp
        return res
M = Matrix(6)
M.a = [[2, 1, 1, 0, 1, 2],
       [1, 2, 0, 1, 1, 2],
       [1, 1, 1, 0, 1, 2],
       [1, 1, 0, 1, 1, 2],
       [0, 0, 0, 0, 1, 1],
       [0, 0, 0, 0, 0, 1]]
sx -= 1
sy -= 1
r = M ** t
f = lambda i: (r.a[i][0] * sx + r.a[i][1] * sy + r.a[i][2] * dx + r.a[i][3] * dy + r.a[i][5]) % mod + 1
print(f(0), f(1))


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def bit(xx):return [format(x,"b") for x in xx]
popcnt=lambda x:bin(x).count("1")
def ask(m):
    print("?",m,flush=True)
    return II()
for _ in range(II()):
    n=II();l=0;r=n;pc=0;d=1;mx=0
    while l+1<r:m=(l+r)//2;c=pc+m*d;mx=max(mx,c);l=m;pc=c;d*=-1
    pc=n-mx;ask(pc);l=0;r=n;d=1
    while l+1<r:
        m=(l+r)//2;c=pc+m*d
        if ask(c):r=m
        else:l=m
        pc=c;d*=-1
    print("=",r,flush=True)


class Solution:
    def resolve(self, p, k):
        re = []

        while p < 0 or p >= k:
            p, rem = p // -k, p % -k
            if rem < 0:
                rem += k
                p += 1
            re.append(rem)

        re.append(p)

        return re

if __name__ == '__main__':
    s = Solution()

    p, k = map(int, input().split())

    re = s.resolve(p, k)
    if len(re) == 0:
        print("-1")
    else:
        print(len(re))
        for i in re:
            print(i, end=' ')
        print()


a,b,c=map(int,raw_input().split())
exec"a,b=b,a+b;"*c
print a


m = 301000
ns = [0] * m
es = [0] * m
c = [0] * m
b = [0] * m
t = [0] * m
P = 0

def add(b, k):
    k = t[k]
    while k:
        e = es[k]
        if b[-1] > e: b[-1] = e
        b[e] += 1
        k = ns[k]

def delete(b):
   for i in range(b[m - 1], m + 1):
       if b[i]:
           b[i] -= 1
           b[-1] = i
           return i

def calc(k):
    global b
    q = 0
    b = [0] * m
    b[-1] = m
    take = rank - dn
    if take < 0: take = 0
    add(b, k)
    add(b, k - 1)
    for i in range(1, take + 1): q += delete(b)
    for i in range(k - 1): add(b, i)
    for i in range(k + 1, P + 1): add(b, i)
    for i in range(1, k - take + 1): q += delete(b)
    return q

n, k = map(int, input().split())
rank = n - k + 1

if rank == 0:
    print('0')
    exit(0)

for i in range(1, n + 1):
    p, e = map(int, input().split())
    if p > P: P = p
    c[p] += 1
    es[i], ns[i] = e, t[p]
    t[p] = i

dn = 0
for i in range(1, n + 1):
    if i > 1: dn += c[i - 2]
    if c[i] + c[i - 1] + dn >= rank and rank <= i + dn:
        u = calc(i)
        if i < n:
            dn += c[i - 1]
            v = calc(i + 1)
            if u > v: u = v
        if i < n - 1:
            dn += c[i]
            v = calc(i + 2)
            if u > v: u = v
        print(u)
        exit(0)

print('-1')


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


s=map(int, raw_input().split())
l=s.pop()
ans=((l+1)*(l+2)*(l+3))/6
for i in range(l+1):
    for j in s:
        x = min(j+j-sum(s)+i, l-i)
        if x>=0: ans -= ((x+1)*(x+2))/2
print ans


def main():
    n,m = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    count = [0]*101
    for i in a:
        count[i] += 1
    b = [(count[i],i) for i in range(1,101) if count[i]]
    b.sort(reverse=True)
    b = b[:n]
    flag = 0
    for i in b:
        flag += i[0]
    if m < n or flag < n:
        print(0)
    else:
        for day in range(1,102):
            people = 0
            for food,foodtype in b:
                people += food//day
            if people < n:
                break
        print(day-1)

if __name__ == '__main__':
    main()


import re
input()
print(sum(len(f)-2 for f in re.findall('x{3,}',input())))


#!/usr/bin/python3

# BEGIN template
import sys
import re
import pprint

def dbg(x,y=''):
  if len(y) > 0: y += ' = '
  sys.stderr.write('\n>>> '+y+pprint.pformat(x)+'\n')
  sys.stderr.flush()

oo = 0x3f3f3f3f3f3f3f3f
# END template

def minn(x,y):
  if x[0] < y[0]: return x
  if x[0] > y[0]: return y
  if x[1] < y[1]: return x
  if x[1] > y[1]: return y
  return x

def main():
  n = int(input())
  s = input()
  m = len(s)
  s = '0'+s
  power = [1]
  for i in range(1,61):
    power.append(power[i-1]*n)
  dp = [(int(1e70),int(1e70))]*65
  dp[m+1] = (0,0)
  for i in range(m,0,-1):
    if s[i] == '0':
      tmp = dp[i+1]
      dp[i] = (1+tmp[0],tmp[1])
      continue
    for j in range(i,min(m+1,i+9)):
      d = int(s[i:j+1])
      if d >= n: break
      tmp = dp[j+1]
      dp[i] = minn(dp[i],(1+tmp[0],d*power[tmp[0]]+tmp[1]))
  print(dp[1][1])

main()


c, v0, v1, a, l = map(int, input().split())
ans = 0
cur = 0
v = v0
while cur < c:
  if ans > 0:
    cur -= l
  cur += v
  v = min(v + a, v1)
  ans += 1
print(ans)


r=raw_input
s=[r(),r(),r()]
m=[0,1,2]
print "YNEOS"[any([ s[2-i][2-j]!=s[i][j] for i in m for j in m ])::2]


def find(i, A, n, storage):
	if i>n-1:
		return 0
	if storage[i] != -1:
		return storage[i]

	if i == n-1:
		storage[i] = 1
	elif (A[i] == "U" and A[i + 1] == "R") or (A[i] == "R" and A[i + 1] == "U"):
		storage[i] = min(1 + find(i+2, A, n, storage), 1 + find(i+1, A, n, storage))
	else:
		storage[i] = 1 + find(i+1, A, n, storage)
	return storage[i]

n = int(raw_input().strip())
string = raw_input().strip()
storage = [-1]*n
print(find(0, string, n, storage))


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

weeks = min (a[0]//3, a[1]//2, a[2]//2)

a[0] -= weeks*3
a[1] -= weeks*2
a[2] -= weeks*2
extra = 0
food = [0,1,2,0,2,1,0]
for i in range(7):
	rest = a[::]
	extdays = 0
	day = i
	while rest[ food[day] ] > 0:
		extdays +=1
		rest[food[day]] -= 1
		day = (day+1)%7

	extra = max(extra,extdays)

print(weeks*7 + extra)


r, h = map(int, raw_input().split())
p = h / r
q = h % r
if 2 * q > (3. ** 0.5) * r: print 2 * p + 3
elif 2 * q < r: print 2 * p + 1
else: print 2 * p + 2


n,l,r,x=map(int,input().split())
c=input().split()
for i in range(n):
    c[i]=int(c[i])
ans=0
for i in range(1,2**n):
    s=bin(i)
    s=s[2:]
    s="0"*(n-len(s))+s
    if(s.count("1")>=2):
        total=0
        maxi=0
        mini=10**6+1
        for j in range(n):
            if(s[j]=="1"):
                total+=c[j]
                maxi=max(maxi,c[j])
                mini=min(mini,c[j])
        if(l<=total<=r and maxi-mini>=x):
            ans+=1
print(ans)


n=input()
l=list(n)
while(l.count(' ')!=0):
    l.remove(' ')
n=len(l)
j=l[n-2]
if j=='a' or j=='e' or j=='i' or j=='o' or j=='u' or j=='y' or j=='A' or j=='E' or j=='I' or j=='O' or j=='U' or j=='Y':
    print('YES')
else:
    print('NO')
#print(l,n)


n = input()
s = raw_input()
c = s.count('1')
if c*2 == n:
	print 2
	print s[0], s[1:]
else:
	print 1
	print s


n=input()
k=input()
A=input()
B=input()
ans=0
x=n
while x!=1:
	if k!=1:
		if x%k == 0:
			if A*(x - x/k) > B:
				x/=k
				ans+=B
			else:
				ans+=A*(x - x/k)
				x=x/k
		else:
			if x < k:
				ans+=A*(x-1)
				x=1
			else:
				ans+=A*(x%k)
				x=x-(x%k)
	else:
		ans=A*(x-1)
		x=1
		# print ans
print ans


n = int(input())
a=[]
for i in range (n):
    a.append(int(input()))

def ideal(a):
    a.sort()
    mean = sum(a)/4
    median = (a[1]+a[2] )/ 2
    r = max(a)-min(a)

    if( mean == median  == r ):
        print("YES")
    else:
        print("NO")

if( len(a) == 4 ):
    ideal(a)

elif(len(a) == 0 ):
    print("YES")
    print(1)
    print(1)
    print(3)
    print(3)

elif(len(a)==1) :
    print("YES")
    print(2*a[0])
    print(2*a[0])
    print(3*a[0])

elif(len(a)==2):
     if((4*min(a) - max(a) )>0):
        print("YES")
        print(4*min(a) - max(a))
        print(3*min(a))
     else:
         print("NO")

elif(len(a) == 3 ):
    if( sum(a)-min(a) == 4*min(a)):
        print("YES")
        print(3 * min(a) )
    elif( max(a) ==  3*min(a)):
        print("YES")
        print(8*min(a) -  sum(a) )
    elif( 3*sum(a) == 7*max(a) ) :
        print("YES")
        print( max(a) // 3 )
    else:
        print("NO")


l = list(input().split())
m = int(l[0])
n = int(l[1])
board = []
l1 =[]
if m>=1 and m <=n and n<=16:
    for i in range(n):
        for j in range(m):
            l1.append(0)
        board.append(l1)
        l1 = []

    sum = 0
    k = 0
    for i in range(len(board)):
        sum+= (len(board[i])//2)
        k = 0
        for j in range(0,(len(board[i])//2)):
            board[i][k] = 1
            board[i][k+1] = 1
            k+=2

    for i in range(0,len(board),2):
        if i == len(board)-1:
            break
        elif board[i][len(board[i])-1] == 0 and board[i+1][len(board[i])-1] == 0:
            sum+=1

print(sum)
#print(board)


def solve(N, M):
    ans = 0
    while M > 1:
        ans += N // M
        N, M = M, N % M
    if M == 0: return 1000000
    return N - 1 + ans

N = int(input())
ans = 1000000
for M in range(1, N + 1):
    ans = min([ans, solve(N, M)])
print(ans)


import math
M, A, B = map(int, input().split())
bound = [10**9 + 7]*(A + B)
l, r = 0, 0
while True:
    bound[l] = r
    if l >= B:
        l -= B
    else:
        l += A
    r = max(r, l)
    if l == 0:
        break

ans = 0
for i in range(0, A + B):
    if bound[i] <= M:
        ans += M - bound[i] + 1

rem = M - (A + B) + 1
if M >= (A + B):
    g = math.gcd(A, B)
    up = (rem // g) * g
    lo = rem - up
    cnt = up // g + 1
    ans += (lo + rem) * cnt // 2
print(ans)


import math
def primeFactors(n,dict1):
    while n % 2 == 0:
        try:
            dict1[2]+=1
        except:
            KeyError
            dict1[2]=1
        n = n//2

    for i in range(3,int(math.sqrt(n))+1,2):
        while n % i== 0:
            try:
                dict1[i]+=1
            except:
                KeyError
                dict1[i]=1
            n = n //i
    if(n>2):
        dict1[n]=1

n,b=map(int,input().split())
dict1={}
primeFactors(b,dict1)
#print(dict1)
dict2={}
for i in dict1.keys():
    j=i
    while(j<=n):
        count=n//j
        try:
            dict2[i]+=count
        except:
            KeyError
            dict2[i]=count
        j=j*i
#print(dict2)
minval=10**18
for i in dict1.keys():
    try:
        minval=min(minval,dict2[i]//dict1[i])
    except:
        KeyError
        minval=0
if(minval==10**18):
    minval=0
print(minval)


def sum_dig(n):
    return sum(map(int, str(n)))
n = int(input())
a = 9
while a < n:
    a = 10*a + 9
a //= 10
print(sum_dig(a) + sum_dig(n-a))


def berlanese():
    if s[-1] not in vog and s[-1] != 'n':
        return "NO"
    for i in range(len(s)-1):
        if s[i] != 'n':
            if s[i] not in vog and s[i+1] not in vog:
                return "NO"

    return "YES"

s = list(raw_input())
vog = ['a', 'e', 'i', 'o', 'u']

print berlanese()


w,m,k=map(int,raw_input().split())
t=m;
c=0;
while(t):
    c=c+1
    t=t//10;
p=10**c-m;
if(p*c*k==w):
    print(p)
elif(p*c*k>w):
    print(w//(c*k))
else:
    s=p;
    w=w-p*c*k;
    for i in range(c+1,18):
        x=9*(10**(i-1));
        q=x*(i*k)
        if(q<w):
            w=w-q;
            s=s+x;
        else:
            s=s+w//(i*k)
            print(s)
            exit(0)


def f(x):
  return any(i * 3 <= x and (x - i * 3) % 7 == 0 for i in range(x))
print "\n".join([f(int(raw_input())) * "YES" or "NO" for __ in xrange(int(raw_input()))])


#!/usr/bin/env python3

import re

def main():
    input()
    p = re.compile(input())

    pokemons = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
    pokemons = sorted(pokemons, key=len)

    for x in pokemons:
        if p.match(x):
            print(x)
            break

if __name__ == '__main__':
    main()


rr=raw_input
rrI = lambda: int(rr())
rrM = lambda: map(int,rr().split())
debug=0
if debug:
    fi = open('t.txt','r')
    rr=lambda: fi.readline().replace('\n','')

def good_mask(x):
    if x == 0: return False
    return (x+1) & x == 0

N = rrI()
S = rr()
#N = 75
#from time import time
#S  = '100000111111101000100001011100010111110011111011100011001111101111100011110'
#tt = time()
#print tt

lenbin = [ len(bin(n)) - 2 for n in xrange(32) ]

def solve():
    MOD = 10**9 + 7
    number = [ [0]*(N+1) for _ in xrange(N) ]
    for i in xrange(N):
        for j in xrange(i+1, N+1):
            number[i][j] = min(22, int(S[i:j],2))
    #UPPER = 22
    UPPER = 22
    memo = [ {} for _ in xrange(N+1)]
    def dp(i, mask, sum_to_make = 0, cur_max = 0):
        #Having made a cut already before position i,
        #and having a set of mask taken
        #how many ways?
        if i == N:
            return 1 if sum_to_make == 0 != mask else 0
        if mask in memo[i]: return memo[i][mask]
        ans = 1 if sum_to_make == 0 != mask else 0 #good_mask(mask) else 0
        for j in xrange(i+1, N+1):
            num = number[i][j]
            if num == 0: continue
            if num >= UPPER: break
            if sum_to_make > N-j+5: break
            if (mask >> (num-1))&1:
                ans += dp(j, mask, sum_to_make, cur_max)
            elif num <= cur_max:
                ans += dp(j, mask|(1<<(num-1)), sum_to_make - lenbin[num], cur_max)
            else:
                ans += dp(j, mask|(1<<(num-1)), sum_to_make + sum(lenbin[x] for x in xrange(cur_max + 1, num)), num)

            if ans >= MOD:
                ans %= MOD
        memo[i][mask] = ans
        return ans
    fans = i = 0
    while i < N:
        fans += dp(i, 0)
        fans %= MOD
        i += 1

    print fans
#print time()-tt

if __name__ == "__main__": solve()

"""
def good_mask(x):
    if x == 0: return False
    return (x+1) & x == 0

N = rrI()
S = rr()
##print '.'
#N = 75
#import random
#S = "".join(str(random.randint(0,1)) for _ in xrange(N))
MOD = 10**9 + 7
UPPER = 22

memoslide = {N : 0, N-1:0}
def slide(j):
    if j in memoslide:
        return memoslide[j]
    if S[j] == '1':
        memoslide[j] = 0
        return 0
    else:
        k = j
        while k < len(S) and S[k] == '0':
            k += 1
        memoslide[j] = k - j
        return k - j

memo = {}
def dp(i, mask):
    #Having made a cut already before position i,
    #and having a set of mask taken
    #how many ways?
    if i == N:
        return 1 if good_mask(mask) else 0
    if (i,mask) in memo:
        return memo[i,mask]
    ans = 1 if good_mask(mask) else 0
    for j in xrange(i+1, N+1):
        num = int(S[i:j], 2)
        if num == 0: continue
        if num >= UPPER: break
        if num > 8:
            #prune
            newmask = mask
            ii = excess = 0
            while newmask:
                if newmask%2 == 0:
                    excess += len(bin(ii)) - 2
                ii += 1
                newmask /= 2
            if excess > N-j+1:
                break
        k = slide(j)
        newmask = mask | (1<<(num-1))
        bns = dp(j + k, newmask)
        for kk in xrange(k):
            memo[(j + kk, newmask)] = bns
        ans += (1+k) * bns

        if ans >= MOD:
            ans %= MOD
    memo[i, mask] = ans
    return ans

fans = 0
for i in xrange(N):
    fans += dp(i, 0)
    if fans >= MOD:
        fans %= MOD
print fans
"""


f=lambda:map(int,input().split())
n,a=f()
t=[0]+list(f())
ans=t[a]
for i in range(1,n):
 if a-i>0 and a+i<=n:
  if t[a-i]==t[a+i]: ans+=t[a-i]+t[a+i]
 elif a-i>0: ans+=t[a-i]
 elif a+i<=n: ans+=t[a+i]
print(ans)


n,l=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
b1=False
b2=False
i=-1
while i<l-1 and b1==False:
    i+=1
    for j in range(len(b)):
        b[j]+=1
        if b[j]>=l: b[j]-=l
    b.sort()
    b2 = False
    for j in range(n):
        if b[j]!=a[j]: b2=True
    if b2==False:
        b1=True
if b1==False: print("NO")
else: print("YES")


'''
usage:
    python prob1.py inputfile
'''

import sys
import os

def main(argv=None):
    i=0
    nSquares=int(raw_input())
    line=raw_input()
    line=line.strip()
    flag=0
    length=0
    ans=[]
    for i in range(0,nSquares):
        if flag==0 and line[i]=="B":
            flag=1
            length=1
        elif line[i]=="B":
            length=length+1
        else:
            flag=0
            if length>0: ans.append(length)
            length=0

    if flag==1: ans.append(length)

    print len(ans)
    out=""
    for i in range(0,len(ans)):
        out=out+str(ans[i])+" "
    print out

    return 0

if __name__ == "__main__":
    sys.exit(main())


import math

def getC(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)

n = int(input())
print(getC(n, 5) * math.factorial(n) // math.factorial(n - 5))


import re
result = re.match('((ftp)|(http))([a-z]+)ru([a-z]*)', raw_input())
url = result.group(1) + '://' + result.group(4) + '.ru'
if result.group(5) != "": url = url + '/' + result.group(5)
print url


# submit
def dist_from_0(x, y, n):
    if x == 0:
        return y
    else:
        if y == 0:
            return 4 * n - x
        else:
            if x == n:
                return 3 * n - y
            else:
                return n + x

def main():
    n, x1, y1, x2, y2 = [int(i) for i in raw_input().split()]
    d1 = dist_from_0(x1, y1, n)
    d2 = dist_from_0(x2, y2, n)
    d = abs(d2 - d1)
    print min(d, 4 * n - d)

if __name__ == '__main__':
    main()


def prime(x) :
    if x == 2 : return 1
    if ~ x & 1 : return 0
    i = 3
    while i * i <= x :
        if x % i == 0 : return 0
        i += 1
    return 1
n = int(input())
cnt = 0
for i in range (2, int(1e9), 1) :
    if not prime(i) : continue
    if i == int(str(i)[::-1]) : continue
    if not prime(int(str(i)[::-1])) : continue
    cnt += 1
    if cnt == n : exit(print(i))


n = int(raw_input())
s = raw_input()
listo = s.split()
listo = map(int, listo)
if listo[-1] == 15:
    print 'DOWN'
elif listo[-1] == 0:
    print 'UP'
else:
    if n <= 1:
        print -1
    elif listo[-1] > listo[-2]:
        print 'UP'
    else:
        print 'DOWN'


d = [list(str(i)) for i in range(1000) if i % 8 == 0]
s = list(raw_input())

res = 'NO'
#print ['3', '4', '4'] in d

for i in range(len(d)):
    c = 0
    for j in s:
        if d[i][c] == j:
            c += 1
            if c == len(d[i]):
                res = ''.join(d[i])
                break
    if c == len(d[i]):
        print "YES"
        break
print res


n = int(input())
w = 0

for i in range(4):
    l = list(map(int,input().split()))
    k = i+1
    if l[0]+l[2] <= n:
        w = 1
        print(k,l[0],n-l[0])
        break
    elif l[0]+l[3] <= n:
        w = 1
        print(k,l[0],n-l[0])
        break
    elif l[1]+l[2] <= n:
        w = 1
        print(k,l[1],n-l[1])
        break
    elif l[1]+l[3] <= n:
        w = 1
        print(k,l[1],n-l[1])
        break

for j in range(k,4):
    list(map(int,input().split()))

if not w:
    print(-1)


from fractions import *
n,m,z=map(int,raw_input().split())
print (z*gcd(n,m))/(n*m)


from sys import stdin
l=[]
for i in range(4):
    s=stdin.readline().rstrip()
    l.append(s)
ans=0
for i in range(3):
    for j in range(3):
        c=0
        if l[i][j]=="#":
            c+=1
        if l[i+1][j]=="#":
            c+=1
        if l[i][j+1]=="#":
            c+=1
        if l[i+1][j+1]=="#":
            c+=1
        if c!=2:
            ans=1
print("YES" if ans==1 else "NO")


C=lambda s:s.count('+')-s.count('-')
a=raw_input()
b=raw_input()
n=0
d=0
for i in range(2**b.count('?')):
    B=b
    for j in range(b.count('?')):
        B=B.replace('?',"+" if i & 2**j else '-',1)
    d+=1
    n+=C(a) == C(B)
print n*1./d


import collections
c = collections.Counter()
n = int(input())
nums = []
for _ in range(n):
    c[int(input().strip())]+=1
if len(c)!=2:
    print('NO')
else:
    a, b = [c[d] for d in c]
    if a==b:
        print('YES')
        for d in c:
            print(d, end=' ')
    else:
        print('NO')


q=int(input())
for u in range(q):
    a,b,m=map(int,input().split())
    ranges=[(a,a)]
    bigsum=a
    smlsum=a
    while ranges[-1][1]<b:
        ranges.append((smlsum+1,bigsum+m))
        smlsum=2*smlsum+1
        bigsum=2*bigsum+m
    if b<ranges[-1][0]:
        print(-1)
    else:
        seq=[a]
        leng=len(ranges)
        power=2**(leng-3)
        curr=(a+1)*(2**(leng-2))
        sumi=a
        for i in range(leng-2):
            seq.append(sumi+max(min((b-curr)//power+1,m),1))
            power//=2
            sumi+=seq[-1]
            curr=(sumi+1)*(2**(leng-i-3))
        if b!=seq[-1]:
            seq.append(b)
        out=[leng]+seq
        out=[str(guy) for guy in out]
        print(" ".join(out))


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

print(*[x+1]*y+[x]*(m-y))


a,b=map(int,input().split())
if b%a==0:
    print(b//a)
else:
    print(b//a+1)


n = int(raw_input().strip())
spectator = 3
flag = False
for i in range(n):
    winner = int(raw_input().strip())
    if(winner == spectator):
        flag = True
    else:
        if(spectator == 1):
            if(winner == 2):
                spectator = 3
            else:
                spectator = 2
        elif(spectator == 2):
            if(winner == 1):
                spectator = 3
            else:
                spectator = 1
        else:
            if(winner == 1):
                spectator = 2
            else:
                spectator = 1

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


def checkPrime(x):
    import math
    for i in range(2,int(math.sqrt(x))+1):
        if x%i == 0:
            return False
    return True

a = {}
for i in range(2,1000):
    n = i
    if checkPrime(n):
        a[n] = [n]
    else:
        for k in range(2,n/2):
            l = n-k
            if checkPrime(k) and checkPrime(l):
                a[n] = [k,l]
import sys
inp = sys.stdin
n = int(inp.readline())
if n<1000 and n in a:
    print len(a[n])
    for it in a[n]:
        print it,
    exit()
else:
    m = n-1
    while True:
        m-=1
        if checkPrime(m):
            k = n-m
            if k in a:
                print len(a[k])+1
                print m,
                for it in a[k]:
                    print it,
                exit()


k = int(input())

a = []
sum = []
for i in range(1, 10):
    a.append(i)
    sum.append(i)
ans = -1
while ans == -1:
    A = []
    S = []
    for i in range(len(a)):
        for j in range(10):
            if sum[i] + j <= 10:
                A.append(a[i] * 10 + j)
                S.append(sum[i] + j)
    a = A
    sum = S
    for i in range(len(a)):
        if sum[i] == 10:
            k -= 1
            if k == 0:
                ans = a[i]
                break
print(ans)


n,k = map(int,raw_input().split())
s = map(int,raw_input().split())
a = []
b = sum(s)
for _ in xrange(k):
    a.append(abs(b-sum(s[_::k])))
print max(a)


D, K, A, B, T = map(int, input().split())

def nStops(N):
  if (N == 0):
    return 0
  else:
    return (N - 1)//K

case1 = D * B
case2 = A * D + T * nStops(D)
ans = min(case1, case2)

# Ignorance is the key
for i in range(max(0, D - 1000000), D + 1):
  ans = min(ans, A * i + B * (D - i) + T * nStops(i))

print(ans)


def main():
  a, b = map(int, input().split());
  count=0;
  for two_fact in range(0,40):
    for three_fact in range(0,40):
        if(a<=(2**two_fact)*(3**three_fact) and b>=(2**two_fact)*(3**three_fact)):
            count+=1;
  print(count);
main();


n = int(input())
s = input()
r = 0
l = n-1
root = []
buf = []
to_the_right = True

for count in range(n):
    if to_the_right:
        i = r
        r += 1
    else:
        i = l
        l -= 1
    b = s[i]

    if b == '(':
        if len(buf) == 0 or buf[-1][0] != -1:
            buf.append([-1,-1,[]])
        buf[-1][0] = i
    else:
        if len(buf) == 0 or buf[-1][1] != -1:
            buf.append([-1,-1,root])
            root = []
            to_the_right = False
        buf[-1][1] = i

    if buf[-1][0] != -1 and buf[-1][1] != -1:
        tmp = buf.pop()
        if len(buf):
            buf[-1][2].append(tmp)
        else:
            root.append(tmp)
            to_the_right = True

sol = [[0,1,1]]
if len(buf) == 0:
    sol.append([len(root), 1, 1])
    for child in root:
        sol.append([len(child[2])+1, child[0]+1, child[1]+1])
        for gr_child in child[2]:
            sol.append([len(root)+len(gr_child[2])+1, gr_child[0]+1, gr_child[1]+1])

print('%d\n%d %d'%tuple(max(sol)))


a = raw_input().split()
b = raw_input().split()
c = raw_input().split()
xa = int(a[0])
ya = int(a[1])
xb = int(b[0])
yb = int(b[1])
xc = int(c[0])
yc = int(c[1])
x1 = xb - xa
x2 = xb - xc
y1 = yb - ya
y2 = yb - yc
res = x1 * y2 - x2 * y1
if res > 0:
    print "RIGHT"
elif res < 0:
    print "LEFT"
else:
    print "TOWARDS"


from math import *
a, b = input().split()
c, d = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
e = abs(a-c)
f = abs(b-d)
g = 0
if e >= f:
	print(e)
elif f >= e:
	print(f)

# 1481129670451


p=10**9+7
def S(x):
	if x==0:
		return 0
	elif x==1:
		return 4
	elif x&1:
		return 11*pow(3,x/2,p)-7
	else:
		return 19*pow(3,x/2-1,p)-7
def G(x):
	return (S(x)+S(x+1>>1))*pow(2,p-2,p)%p;
l,r=map(int,raw_input().split())
print (G(r)-G(l-1))%p;


s = {0: 0, 1: 0}
for i in range(4):
    a, b, c, d = input().split()
    if a == c and b != d: s[0] += 1
    if b == d and a != c: s[1] += 1
    for q in [(a, b), (c, d)]: s[q] = s.get(q, 0) + 1
print('YES' if all(i == 2 for i in s.values()) else 'NO')


F = ['', 'a', 'b', 'ba', 'bab', 'babba', 'babbabab', 'babbababbabba', 'babbababbabbababbabab', 'babbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbabab', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabab', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabab']
while len(F[-3]) < 100000: F.append(F[-1] + F[-2])
d = 1000000007

def sqr(t):
    return [[sum(t[i][k] * t[k][j] for k in range(4)) % d for j in range(4)] for i in range(4)]

def mul(a, b):
    return [[sum(a[i][k] * b[k][j] for k in range(4)) % d for j in range(4)] for i in range(4)]

def fib(k):
    s, p = format(k, 'b')[:: -1], [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
    t = [[[0, 1, 0, 0], [1, 1, 1, 0], [0, 0, 0, 1], [0, 0, 1, 0]]] + [0] * (len(s) - 1)
    for i in range(1, len(s)):
        t[i] = sqr(t[i - 1])
    for i, k in enumerate(s):
        if k == '1': p = mul(p, t[i])
    return p

def cnt(t, p):
    s, i = 0, p.find(t) + 1
    while i > 0:
        i = p.find(t, i) + 1
        s += 1
    return s

def f(t, p, k):
    l = len(t) - 1
    if l: x, y = cnt(t, F[k - 1][- l: ] + F[k][:l ]), cnt(t, F[k][- l: ] + F[k + 1][:l ])
    else: x, y = 0, 0
    a, b = cnt(t, F[k - 1]), cnt(t, F[k])
    return (p[0] * a + p[1] * b + p[2] * y + p[3] * x) % d

k, m = map(int, input().split())
if k > 15:
    x, y, z = len(F[7]), len(F[17]), len(F) - 4
    a, b, c = fib(k - 7)[0], fib(k - 17)[0], fib(k - z)[0]
    for i in range(m):
        t = input()
        if len(t) < x: print(f(t, a, 8))
        elif len(t) < y: print(f(t, b, 18))
        else: print(f(t, c, z + 1))
else:
    p = F[k]
    for i in range(m):
        print(cnt(input(), p))


n = int(raw_input())
A = list(map(int, raw_input().split()))
A = list(set(A))
A = sorted(A)

for i in range(1, len(A)):
	if (A[i - 1] * 2 > A[i]):
		print "YES"
		exit(0)
print "NO"


n,a,b = map(int, raw_input().split())
print str((2*a+1)*(n-1)) + " " + str(n*b)


seg = [6,2,5,5,4,5,6,3,7,6]

def calval(num):
	if num<0:
		return 0
	a = [0 for i in range(10)]
	t = 1

	while num/t>0:
		tail = num%t
		le = num/t/10
		last = num/t%10

		for _i in range(10):
			a[_i]+=le*t
		if le>0:
			a[0]-=t

		for _i in range(last):
			if le==0 and _i==0:
				continue
			a[_i]+=t
		if le==0 and last==0:
			pass
		else:
			a[last]+=tail+1

		t*=10

	res = 0
	for _i in range(10):
		res+=a[_i]*seg[_i]
	#print a
	return res

a,b = raw_input().split()
a = (int)(a)
b = (int)(b)
print calval(b)-calval(a-1)


mugCount, cupVolume = map(int, raw_input().split())
mugVolumes = [int(i) for i in raw_input().split()]

if sum(mugVolumes) - max(mugVolumes) <= cupVolume:
    print 'YES'
else:
    print 'NO'


def main():
    M=998244353
    n,k,*h=map(int,open(0).read().split())
    m=sum(i!=j for i,j in zip(h,h[1:]+h[:1]))
    f=[0]*(m+1)
    f[0]=b=1
    for i in range(1,m+1):f[i]=b=b*i%M
    inv=[0]*(m+1)
    inv[m]=b=pow(f[m],M-2,M)
    for i in range(m,0,-1):inv[i-1]=b=b*i%M
    comb=lambda n,k:f[n]*inv[n-k]*inv[k]%M
    print((pow(k,m,M)-sum(comb(m,i)*comb(m-i,i)*pow(k-2,m-i-i,M)for i in range(m//2+1)))*pow(k,n-m,M)*pow(2,M-2,M)%M)
main()


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

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

Team1=False
Team2=False
if(a>w and a>y and d>x and d>z):
    Team1=True

if(c>w and c>y and b>x and b>z):
    Team1=True

if(((x>b and w>c) or (z>b and y>c)) and ((x>d and w>a) or (z>d and y>a))):
    Team2=True

if(Team1):
    print("Team 1")
elif(Team2):
    print("Team 2")
else:
    print("Draw")


n, d=map(int,input().split())
l=list(map(int,input().split()))
m=int(input())
b=m-n
count=0
if b>0:
  for i in range(n):
     count=count+l[i]

  count=count-b*d

else:
  l.sort()
  for i in range(m):
    count=count+l[i]

print(count)


from collections import defaultdict
from sys import exit
class Graph:
    def __init__(self):
        self.adj=defaultdict(list)
    def add_edge(self,x,y):
        self.adj[x].append(y)
        self.adj[y].append(x)
    def check(self):
        for i in range(1,6):
            for j in range(i+1,6):
                for k in range(j+1,6):
                    if j not in self.adj[i] and k not in self.adj[j] and i not in self.adj[k]:
                        print("WIN")
                        exit(0)
                    if j in self.adj[i] and k in self.adj[j] and i in self.adj[k]:
                        print("WIN")
                        exit(0)
        print("FAIL")
g=Graph()
n=int(input())
for _ in range(n):
    x,y=map(int,input().split())
    g.add_edge(x,y)
g.check()


s = list(raw_input())
t = list(raw_input())

leq = (len(s) == len(t))
sChars = {}
tChars = {}
for i in s:
	sChars[i] = sChars.get(i, 0) + 1
for i in t:
	tChars[i] = tChars.get(i, 0) + 1
x = 0
haschars = True
for i in tChars:
	if sChars.get(i, 0) < tChars[i]:
		haschars = False

if not haschars:
	print 'need tree'
elif leq:
	print 'array'
else:
	sind = 0
	tind = 0
	while tind < len(t):
		if sind >= len(s):
			print 'both'
			x = 1
			break
		if s[sind] == t[tind]:
			sind += 1
			tind += 1
		else:
			sind += 1

	if x == 0:
		print 'automaton'


#input
w1, h1, w2, h2 = list(map(int,input().split(" ")))
ans = (h1+h2)*2 + max(w1,w2)*2+ 4
print (ans)


from fractions import gcd
x, y, a, b = map(int, raw_input().split())

lcm = x*y/gcd(x, y)
print b/lcm-(a-1)/lcm


# import sys
# input=sys.stdin.readline

a=input()
dp=[]
for i in range(len(a)):
    dp.append([0]*10)
for i in range(10):
    dp[0][i]=1

for i in range(len(a)-1):
    for j in range(10):
        if dp[i][j]!=0:
            c=(int(a[i+1])+j)//2
            d=(int(a[i+1])+j+1)//2
            if c!=d:
                dp[i+1][c]+=dp[i][j]
                dp[i+1][d]+=dp[i][j]
            else:
                dp[i+1][c]+=dp[i][j]
s=0
for i in range(10):
    s+=dp[-1][i]
t=0
c=int(a[0])
f=[a[0]]
for i in range(1,len(a)):
    d=(c+int(a[i]))//2
    e=(c+int(a[i])+1)//2
    if int(a[i])==d:
        f.append(a[i])
        c=d
    elif int(a[i])==e:
        f.append(a[i])
        c=e
    else:
        break
if "".join(f)==a:
    t=1
print(s-t)


import sys

def genForLen(n):
    res = []
    for i in xrange(1 << n):
        s = 0
        for j in xrange(n):
            s = s * 10 + (4 if ((i >> j) & 1) != 0 else 7)
        res.append(s)
    return res

def genLucky(n):
    res = []
    for i in xrange(n):
        res += genForLen(i + 1)
    return res

def calcStrong(pl, pr, vl, vr, preFirst, first, last, postLast, equalIsGood):
    preFirst = max(preFirst, pl)
    first = min(first, pr)
    last = max(last, vl)
    postLast = min(postLast, vr)
    a = first - preFirst + 1
    b = postLast - last + 1
    if a <= 0 or b <= 0:
        return 0
    res = a * b
    if not equalIsGood and first == last:
        res -= 1

    return res

def countGood(pl, pr, vl, vr, k):
    nums = genLucky(9)
    nums.sort()
    res = 0L

    for i in xrange(len(nums) - k + 1):
        first, last = nums[i], nums[i + k - 1]
        preFirst = (0 if i == 0 else nums[i - 1]) + 1
        postLast = (1000000001 if i + k == len(nums) else nums[i + k]) - 1
        res += calcStrong(pl, pr, vl, vr, preFirst, first, last, postLast, True)
        res += calcStrong(vl, vr, pl, pr, preFirst, first, last, postLast, False)

    return res

pl, pr, vl, vr, k = map(int, sys.stdin.readline().split())

res = countGood(pl, pr, vl, vr, k) / (float(pr - pl + 1) * (vr - vl + 1))
print "%.10f" % res


t = list(map(int, input().split()))
f0 = 3
while t[f0] != 0:
    f0 = (f0 + 5) % 6
    if f0 == 3:
        break
if f0 % 2 == 0:
    print('Ron')
    exit()
num = t[1] * t[3] * t[5]
den = t[0] * t[2] * t[4]
if num > den:
    print('Ron')
else:
    print('Hermione')


import math
#------------------------------warmup----------------------------
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")

#-------------------game starts now----------------------------------------------------
def doi(it,l,t):
    for i in range(len(l)):
        if l[i][t]==it:
            print(l[i][0],l[i][1])
            return
n=int(input())
d=dict()
d1=dict()
m=0
m1=0
mi=99999999999999999999
mi1=99999999999999999999
l=[]
for i in range(4*n+1):
    a,b=map(int,input().split())
    l.append([a,b])
    m=max(a,m)
    mi=min(mi,a)
    m1=max(b,m1)
    mi1=min(mi1,b)
    if a in d:
        d[a]+=1
    else:
        d.update({a:1})
    if b in d1:
        d1[b]+=1
    else:
        d1.update({b:1})
if d[m]==1:
    doi(m,l,0)
elif d[mi]==1:
    doi(mi,l,0)
elif d1[mi1]==1:
    doi(mi1,l,1)
elif d1[m1]==1:
    doi(m1,l,1)
else:
    x1=m
    x2=mi
    y1=m1
    y2=mi1
    for i in range(len(l)):
        if l[i][0]==x1 and y2<=l[i][1]<=y1:
            continue
        elif l[i][0]==x2 and y2<=l[i][1]<=y1:
            continue
        elif l[i][1]==y1 and x2<=l[i][0]<=x1:
            continue
        elif l[i][1]==y2 and x2<=l[i][0]<=x1:
            continue
        else:
            print(l[i][0],l[i][1])
            break


import math

def isprime(n):
    if n == 2:
        return True

    sq = math.ceil(n ** 0.5) + 1
    for i in range(2, sq):
        if n % i == 0:
            return False
    return True

def solve(n):
    if isprime(n):
        return 1
    if n%2 == 0:
        return 2
    if isprime(n - 2):
        return 2
    return 3

n = int(input())
print(solve(n))


cases = int(input())

for i in range(cases):
    numbers = {1}
    variable = 2
    number = int(input())
    while True and number != 1:
        if variable**2 <= number:
            numbers.add(variable**2)
        else:
            break
        if variable**3 <= number:
            numbers.add((variable**3))
        variable += 1
    print(len(numbers))


def cifera(x,y):
    cont=0
    h=x
    solucion=[]
    while True:
        if (h<y):
            h*=x
            cont+=1
        elif (h>y):
            solucion=[False,cont]
            break
        else:
            solucion=[True,cont]
            break
    return solucion

k=input()
l=input()

resultado=cifera(k,l)

if (resultado[0]==True):
    print "YES\n",resultado[1]
else:
    print "NO\n"


def nextc(m):
    m2 = {}
    for n, c in m.iteritems():
        h = n-1 >> 1
        m2[h] = m2.get(h, 0) + c
        m2[n-1 - h] = m2.get(n-1 - h, 0) + c
    return m2

def countseg(l, s, cache={}):
    if s > l: return 0
    if s == l: return 1
    if (l, s) in cache:
        return cache[l, s]
    h = l-1 >> 1
    out = countseg(h, s) + countseg(l-1 - h, s)
    cache[l, s] = out
    return out

def findx(l, q, ss):
    if l <= max(ss):
        return (l-1 >> 1) + q
    h = l-1 >> 1
    ns = sum(countseg(h, s) for s in ss)
    if q >= ns:
        return h + 1 + findx(l-1 - h, q - ns, ss)
    else:
        return findx(h, q, ss)

def f(l, r):
    m = {l: 1, l-1: 0}
    q = 1
    while r >= q and min(m) > 2:
        r -= q
        q <<= 1
        m = nextc(m)
    mn, mx = min(m), max(m)
    if mx & 1:
        if r >= m[mx]:
            if mx == 3:
                return findx(l, r - m[mx], [1,2])
            return findx(l, r - m[mx], [mn])
        else:
            return findx(l, r, [mx])
    else:
        return findx(l, r, [mn, mx])

def ans(n, k):
    if k == 1: return 1
    if k == 2: return n
    return 2 + f(n - 2, k - 3)

def brute_ans(n, k):
    if k == 1: return 1
    if k == 2: return n
    return 2 + brute_f(n - 2, k - 2)

def brute_f(l, r):
    s = [(0, l)]
    for _ in xrange(r):
        i = max(xrange(len(s)), key=lambda j: s[j][1]-1 >> 1)
        x, d = s[i]
        h = d-1 >> 1
        s = s[:i] + [(x, h), (x+h+1, d-1-h)] + s[i+1:]
    return x+h

def test_n(n):
    for i in xrange(1, n + 1):
        assert brute_ans(n, i) == ans(n, i)

if __name__ == '__main__':
    n, k = map(int, raw_input().split())
    print ans(n, k)


for i in range(int(input())):
    t = input()[4:]
    q, d = int(t), 10 ** len(t)
    while q < 1988 + d // 9: q += d
    print(q)


__author__ = 'Devesh Bajpai'

'''
https://codeforces.com/problemset/problem/988/A

Solution: Using a brute-force approach, where a visited boolean array checks the presence of a number being seen or not.
This insures distinctness constraint. A result list maintains the final indices but indexed at 1.
As soon as the result list since reaches k, we return the decision YES and result list. If the loop that traverses on the
numbers exhausts and the result list hasn't reached k, the decision NO and null is returned.
'''

def solve(n, k, nums):
    visited = [False for _ in range(101)]
    result = []
    currResultSize = 0

    for i in xrange(0, n):

        num = nums[i]
        if not visited[num]:

            visited[num] = True
            result.append(i+1) #since the index referred in this problem starts at 1 instead of 0
            currResultSize += 1

            if currResultSize == k:
                return "YES", result

    return "NO", None

if __name__ == "__main__":
    n, k = map(int,raw_input().split(" "))
    nums = map(int,raw_input().split(" "))
    decision, results = solve(n, k, nums)

    print decision
    if decision == "YES":
        print ' '.join([str(result) for result in results])


n, m = map(int, input().split())
d = 0
i = 1
while n > 0:
    n -= 1
    d += 1
    if d == m * i:
       n += 1
       i += 1
print(d)