#!/usr/bin/env python

def main():
    k, b, n, t = [int(x) for x in raw_input().split()]

    z = 1
    for i in xrange(0, n):
        z = z*k + b

    m = 0
    while (t <= z):
        t = t*k + b
        m = m + 1

    print m

    return 0

if __name__ == '__main__':
    main()


import sys
def bp(a, n):
	res = 1
	while n:
		if (n & 1):
			res *= a
		a *= a
		n >>= 1
	return res

k,b,n,t=sys.stdin.readline().split(' ')
k,b,n,t=int(k),int(b),int(n),int(t)
if t==1:
	print n
	sys.exit(0)
kn=bp(k,n)
kxt=kn*t
knn=kn
x=n
while x>=0:
	if (kxt < knn): break
	knn+=(kn/k)*b
	kn/=k
	kxt/=k
	x-=1
print x+1


import math
n=int(input())
while(n>=2):
    print("25")


from collections import defaultdict
def isPrime(N):
    return (False if any([not N % i for i in range(2, N)]) else True)
MyDict, X , Number = defaultdict(int) , list(map(int, input().split())), 2
while X[0] != 1:
    if isPrime(Number):
        while X[0] % Number == 0:
            MyDict[Number] += 1
            X[0] /= Number
    Number += 1
if sum(MyDict.values()) < X[1]:print(-1);exit()
X[1],SUM = X[1] - 1, 1
for Key in MyDict.keys():
    Min = min(X[1], MyDict[Key])
    print((str(Key)+' ') * Min , end="")
    X[1], MyDict[Key] = X[1] - Min , MyDict[Key] - Min
    SUM *= max(1 , Key ** MyDict[Key])
print(SUM)

# Caption: God bless you General Soleimani

#         ---------Hard Revenge---------
#         ---------Hard Revenge---------

#          ****** Rest in Peace ******


import time
import random
W = int(input())
M = [int(a) for a in input().split()]
A = [0] * 8
sTime = time.time()

s = 0
mi = 10**10
for i in range(8):
    if s + M[i]*(i+1) <= W:
        s += M[i]*(i+1)
        A[i] = M[i]
    else:
        t = (W-s)//(i+1)
        s += t*(i+1)
        A[i] += t

    if s <= W:
        mi = min(mi, W-s)

while time.time() - sTime < 1.75:
    i = random.randrange(8)
    a = random.randrange(2)
    if W-s >= 20 or (s-W < 10 and a == 0):
        if A[i] < M[i]:
            A[i] += 1
            s += (i+1)
    else:
        if A[i] > 0:
            A[i] -= 1
            s -= (i+1)

    if s <= W:
        mi = min(mi, W-s)

print(W-mi)


import sys,math
from collections import defaultdict
from io import BytesIO

sys.stdin = BytesIO(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip('\r\n')
n = int(input())
#n,q = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
#sec = [set()] * n
basen = n
while n > 100:
    if sum(arr) == 0:
        break
    dif = n - 100
    for i in range(8,0,-1):
        if arr[i-1] > 0:
            n -= i * min(dif // i + 1, arr[i-1])
            arr[i-1] -= min(dif // i + 1, arr[i-1])
            break

cur = 0
dot8 = set()
while cur <= n and arr[-1] >= 0:
    arr[-1] -= 1
    dot8.add(cur)
    cur += 8

cur = 0
dot7 = set()
while cur <= n and arr[-2] >= 0:
    arr[-2] -= 1
    dot7.add(cur)
    cur += 7

cur = 0
dot6 = set()
while cur <= n and arr[-3] >= 0:
    arr[-3] -= 1
    dot6.add(cur)
    cur += 6

cur = 0
dot5 = set()
while cur <= n and arr[-4] >= 0:
    arr[-4] -= 1
    dot5.add(cur)
    cur += 5

cur = 0
dot4 = set()
while cur <= n and arr[-5] >= 0:
    arr[-5] -= 1
    dot4.add(cur)
    cur += 4

cur = 0
dot3 = set()
while cur <= n and arr[-6] >= 0:
    arr[-6] -= 1
    dot3.add(cur)
    cur += 3

cur = 0
dot2 = set()
while cur <= n and arr[-7] >= 0:
    arr[-7] -= 1
    dot2.add(cur)
    cur += 2
#print(n,dot8,dot7)

resdot = set()
newdot = set()
for el8 in dot8:
    for el7 in dot7:
        if el8 + el7 <= n:
            resdot.add(el8+el7)
for el6 in dot6:
    for el in resdot:
        if el6 + el <= n:
            newdot.add(el6+el)
resdot = newdot
newdot = set()
for el5 in dot5:
    for el in resdot:
        if el5 + el <= n:
            newdot.add(el5+el)
resdot = newdot
newdot = set()
for el4 in dot4:
    for el in resdot:
        if el4 + el <= n:
            newdot.add(el4+el)
resdot = newdot
#print(newdot)
newdot = set()
for el3 in dot3:
    for el in resdot:
        if el3 + el <= n:
            newdot.add(el3+el)
resdot = newdot
#print(resdot,newdot,dot2)
newdot = set()
for el2 in dot2:
    for el in resdot:
        if el2 + el <= n:
            newdot.add(el2+el)
#print(newdot)
m = max(newdot)
print(basen + m - n + (min(n-m,arr[0])))


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

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

xx=0
for i in range(2,int(x**0.5)+1):
    if x%i==0:
        xx=x//i
        break
if xx==0:
    xx=x
out=0
while y!=0:
    g=gcd(x,y)
    l=y//g
    out+=l%xx
    y-=g*(l%xx)
print(out)


from sys import stdin,stdout
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a
for _ in range(1):
    a,b=[int(i) for i in stdin.readline().split()]
    ct=0
    while b:
        c=gcd(a,b)
        a,b=a/c,b/c
        if a==1:
            ct+=b
            break
        z=10**9
        for i in range(1,int(a**(0.5))+1):
            x,y=i,a/i
            if a%x==0 and x!=1:
                z=min(z,b%x)

            if a%y==0 and y!=1:
                z=min(z,b%y)
            if z==0:
                break
        b-=z
        ct+=z
    stdout.write(str(ct)+'\n')


a, b = input().split()
for i in range(max(int(a) + 1, int(b)), 999999):
  if ''.join(c for c in str(i) if c in ('4,7')) == b:
    return print(i)


def solution(a):

    for x in a:
        if x not in "14":
            return "NO"
    i=0
    while i<len(a)-2:
        if a[i]=="4":
            if a[i+1]=="4":
                if a[i+2]=="4":
                    return "NO"
    return "YES"

def answer():
    a=input()
    print(solution(a))
answer()


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

if n == 1:
    print(a[0])
elif n == 2:
    print(a[1] + (a[1]-a[0]))
else:
    f = True
    d = a[1]-a[0]
    for i in range(1, n):
        if (a[i] - a[i-1] != d)
            f = False
    if f:
        print(a[-1]+d)
    else:
        print(a[-1])


a,b=input().split()
answer=0
while (a<=b):
    a*=3
    b*=2
    answer=answer+1
print(answer)


start = raw_input()
end = raw_input()
k = int(raw_input())

dpA = [-1 for i in xrange(k+1)]
dpB = [-1 for i in xrange(k+1)]

def calculaA(n):
    global dpA, dpB
    if n == 0:
        return 0
    if dpA[n-1] == -1:
        calculaA(n-1)

    dpA[n] = dpA[n-1]*(A-1) + dpB[n-1]*A
    dpB[n] = dpA[n-1]*B     + dpB[n-1]*(B-1)

    return dpA[n]

A = B = 0

if start != end:
    dpA[0] = 0
    dpB[0] = 1
else:
    dpA[0] = 1
    dpB[0] = 0

for i in xrange(len(start)):
    now = start[i:]+start[:i]

    if now == end:
        A += 1
    else:
        B += 1

print calculaA(k)


import sys

start = raw_input()
end = raw_input()
k = int(raw_input())

dpA = [-1 for i in xrange(k+1)]
dpB = [-1 for i in xrange(k+1)]

def calculaA(n):
    global dpA, dpB
    if n == 0:
        return 0
    if dpA[n-1] == -1:
        calculaA(n-1)

    dpA[n] = dpA[n-1]*(A-1) + dpB[n-1]*A
    dpB[n] = dpA[n-1]*B     + dpB[n-1]*(B-1)

    return dpA[n]

if start == end and k == 0:
    print 1
    exit(0)

A = B = 0

if start != end:
    dpA[0] = 0
    dpB[0] = 1
else:
    dpA[0] = 1
    dpB[0] = 0

for i in xrange(len(start)):
    now = start[i:]+start[:i]

    if now == end:
        A += 1
    else:
        B += 1

print calculaA(k)


x,y,z,tuno,tdos,ttres=map(int,input().split())
var1=abs(x-y)
stair=var1*tuno
var2=abs(x-z)
eleva=((3*ttres)+((var2)*tdos)+((var1)*tdos)
if stair>=eleva:
      print("YES")
else:
      print("NO")


[x, y, z, t1, t2, t3] = [int(n) for n in input().split()]
print('YES' if (abs(x-y)*t1 > 3*t3 + (abs(x-z)+abs(x-y))*t2) 'NO')


1#r=r
n#r=r+r/sin(pi/n)
s[n,q,r]|q+1e-5>=n#r="YES"|1>0="NO"
main=interact$s.map read.words


n, m = map(int, input().split())
i = 1
while i < 11:
if(i * n % 10 == m):
  print(i)
 if(i * n % 10 == 0):
  print(i)
 i = i + 1


n,a,b = (map(int,input().split()))
c = list (map(int,input().split()))
l = len (c)
total = l//2
t=0
cost =0
w= min (a,b)
list = [a,b,w]
for i in range (total) :
    if c[i]==2 or c[l-1-i]==2 :
        t=t+1
        if c[i]==2 and  c[l-1-i]==2 :
            cost =cost +2* list [c[l-1-i]]
        elif (c[i] == 2 ) :
            cost = cost + list [c[l-1-i]]
            #print (cost , c[i])
        else :
            cost = cost +list[ c[i]]
            #print (cost , c[i])
    elif c[i] == c[l-1-i]  :
        t=t+1
        #cost = cost +  list [c[l-1-i]]
        #print (cost , c[i])
    else :
        exit (print(-1))
if l %2 == 1 :
    if c[l//2] == 2 :
        cost = cost +  list [c[l-1-i]]
print(cost )


input()
s=input()
s+=[s-1]
ans=0
i=1
while i<len(s):
    ans+=1
    if s[i]!=s[i-1]:
        i+=2
    else:
        i+=1
print(ans)


n=int(input())
l=[]
for i in range (n):
    ch=input()
    if(ch=="*"):
        l.append(i+1)

k=[]
for j in l:
    k.append(j-l[0])
a=0
s=0
while((a<=len(k)-5)and(s<4)):
    s=1
    b=a+2
    while((b<len(k)-1)and(s<4)):
        if(k[b+1]-k[b]==k[a+1]-k[a])):
            s=s+1
        b=b+1
    if(s<4):
        s=0
        a=a+1
if(s==4):
    print("yes")
else:
    print("no")


import math

def make_digits(i,dn,s):
    l = 0
    t = set([])
    while i > 0:
        di = i % 7
        i = i / 7
        if di in s or di in t:
            return None
        else:
            t.add(di)
            l += 1
    while l < dn:
        if 0 in s or 0 in t:
            return None
        else:
            t.add(0)
            l += 1
    return t

n,m = map(int,raw_input().split(' '))

dn = int(math.log(n,7)) + 1
dm = int(math.log(m,7)) + 1

count = 0
for i in range(n):
    s = set([])
    s = make_digits(i,dn,s)
    if s == None:
        continue
    for j in range(m):
        flag = False
        t = make_digits(j,dm,s)
        if t == None:
            continue
        count += 1
print count


x, y, z = map(int, raw_input().split())
a, b, c = map(int, raw_input().split())
if (a < x) or (a + b < x + y) or (a + b + c < x + y + z):
    print "NO"
else:
    print "YES"


ars = list(map(int,input().split()))
s = []

for i in range(ars[0]+1):
	for j in range(ars[1]+1):
		for k in range(ars[2]+1):
			if i*j == ars[0] and i*k == ars[2] and j*k == ars[1]:
				print( (i+j+k)*4 )
				exit(0)


def checker(h, m):
    if int(m) == 0:
        return h == int(m)
    return h == int(m[1]+m[0])

def palindromeTime(time):
    h, m = (int(val) for val in time.split(':'))
    sleeped_minutes = 0
    while True:
        if m < 60:
            if checker(h, str(m)):
                return sleeped_minutes
            m+=1
            sleeped_minutes+=1
        else:
            m = 0
            h += 1
        if h==24:
            h = 0

sleeping_time = input()
print(palindromeTime(sleeping_time))


temp = input().split(" ")
maxLength, initialCount = [int(x) for x in temp]

resultSet = {1: [], 2: []}
dataSet = dict()
for i in range(initialCount):
    temp = input().split(" ")
    a, b = [x for x in temp]
    dataSet[a] = b
    resultSet[1] = b
    resultSet[2] = a

def populate(toValue):
    fromValues = []
    if len(toValue) == 1:
        for key, value in dataSet.items():
            if value == toValue and not key in fromValues:
                fromValues.append(key)
    else:
        process = toValue[:1]
        tail = toValue[1:]
        firstPart = populate(process)
        if len(firstPart) > 0:
            fromValues = fromValues + [x + tail for x in firstPart if (not x + tail in fromValues and (not x + tail in dataSet.keys()))]
    return fromValues
count = 0
currents = ["a"]
currentCount = 1
while currentCount < maxLength:
    buffer = []
    for current in currents:
        result = populate(current)
        for key in result:
            dataSet[key] = current
        buffer = buffer + result
    if len(buffer) > 0:
        currentCount += 1
        currents = buffer
        if currentCount == maxLength:
            count = len(buffer)
    else:
        break
print(count)


import itertools
import time
AAA, BBB = map(int, raw_input().split())
CCC = []
for i in range(BBB):
	CCC.append(map(str, raw_input().split()))
#print CCC

DDD = [i for i in range(AAA)]
GGG = list(itertools.product(CCC, repeat=(AAA-1)))
#print "GGG is " + str(GGG)

EEE = ["a", "b", "c", "d", "e", "f"]
FFF = list(itertools.product(EEE, repeat=(AAA)))
#print "FFF is " + str(FFF)
III = []
for i in range(len(FFF)):
	HHH = ""
	for j in range(len(FFF[i])):
		HHH += FFF[i][j]
	III.append(HHH)
#print "III is " + str(III)
"""
print III
print GGG[1][0][0]
print GGG[1][1][0]
"""
#for i in GGG:
#	print i
ANS = 0
for i in range(len(III)):
	for j in range(len(GGG)):
		KKK = III[i]
		for k in range(AAA-1):
			if GGG[j][k][0] == KKK[0]+KKK[1]:
				KKK = KKK[2:]
				KKK = GGG[j][k][1] + KKK
#				KKK = KKK.replace(GGG[j][k][0], GGG[j][k][1])
#				if III[i] == "eea":
#					print "hello " + str(KKK)
#					print "j is " + str(j)
#					print "GGG[" + str(j) + "] is " + str(GGG[j])
#				print KKK
#				time.sleep(3)
			else:
				break
		if KKK == "a":
			ANS += 1
#			print "ok is " + str(III[i])
#			print "ok is " + str(GGG[j])
			break
print ANS


def soe(n):
    primes=[True]*(n+1)
    primes[0]=primes[1]=False
    i=4
    while i<n:
        primes[i]=False
        i+=2
    i=3
    while i*i<=n:
        for j in range(i*i,n,2*i):
            primes[j]=False
        i+=2
    ans=[]
    for i in range(len(primes)):
        if primes[i]:
            ans.append(i)
    return ans
prim=soe(10**8)
n=int(input())
ct=0
f=-1
for i in prim:
    if n%i==0:
        ct+=1
        f=i
if ct>=2:
    print(1)
elif ct==1:
    print(f)
else:
    print(n)


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

if sum(candies) < n or 8*n < k:
    print(-1)
    return

arya=0
maxc = 0
day=0
for candy_count in candies:
    arya += candy_count
    maxc += 8
    day+=1
    if arya >=k and maxc >= 8:
        print(day)
        break


n = int(raw_input())
cpts = [int(i) for i in raw_input().split()]
tasks = [set() for i in xrange(3)]
for i in xrange(n):tasks[cpts[i]-1].add(i)
depends = [set([int(j)-1 for j in raw_input().split()][1:]) for i in xrange(n)]
finish = set()

def do_task(pos, finish, tasks, depends):
    hours = 0
    while True:
        ns = set()
        for t in tasks[pos]:
            depends[t].difference_update(finish)
            ns.update(depends[t])
        d = tasks[pos].difference(ns)
        if len(d) == 0:break
        finish.update(d)
        tasks[pos].difference_update(d)
        hours += len(d)
    return hours

hours = float('inf')
for pos in xrange(3):
    h = 0
    t = [s.copy() for s in tasks]
    d = [d.copy() for d in depends]
    f = set()
    while True:
        h += do_task(pos, f, t, d)
        if len(f) >= n:break
        h += 1
        pos = (pos + 1) % 3
    hours = min(hours, h)
print hours


def r(): return raw_input().strip()
def ri(): return int(r().strip())
def riv(): return map(int, r().split())

diff = {
    (1,1): 0,
    (2,2): 0,
    (3,3): 0,
    (1,2): 1,
    (1,3): 2,
    (2,1): 2,
    (2,3): 1,
    (3,1): 1,
    (3,2): 2
}

def main():
    n = ri()
    c = riv()

    a = []
    start, start_comp = None, 0
    down = set()
    for i in range(n):
        line = riv()[1:]
        a.append(line)
        if len(line) == 0 and start is None:
            start = i+1
            start_comp = c[i]

    hours = 1
    down.add(start)
    while len(down) < n:
        possible = {}
        for i, stage in enumerate(a):
            if i+1 not in down and all([s in down for s in stage]):
                comp = c[i]
                if comp not in possible:
                    possible[comp] = []
                possible[comp].append(i+1)

        if start_comp in possible:
            for l in possible[start_comp]:
                hours += 1
                down.add(l)
        else:
            nz = min(possible.items(), key=lambda z: diff[(start_comp, z[0])])
            hours += diff[(start_comp, nz[0])]
            start_comp = nz[0]
            for l in nz[1]:
                hours += 1
                down.add(l)

    print hours

if __name__ == "__main__":
    main()


s = input()
d = s.count("-")
o = s.count("o")
if d == 0 || o == 0:
    print("YES")
elif d % o == 0:
    print("YES")
else:
    print("NO")


def four(a, k):
    return min(abs(ord(a[k]) - ord('A')), abs(ord(a[k]) - (ord('A') + 26))) + \
           min(abs(ord(a[k + 1]) - ord('C')), abs(ord(a[k + 1]) - ord('C') - 26)) + \
           min(abs(ord(a[k + 2]) - ord('T')), abs(ord(a[k + 2]) - ord('T') - 26)) + \
           min(abs(ord(a[k + 3]) - ord('G')), abs(ord(a[k + 3]) - ord('G') - 26))

n = int(input())
s = input()
mx = 100000000
for i in range(len(s) - 3):
    m = four(s, i)
    if mx > m:
        mx = m

print(mx)


from collections import deque

n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
c50 = sum([1 for i in a if i == 50])
c100 = sum([1 for i in a if i == 100])
c = [[0] * 51 for i in range(51)]
c[0][0] = 1
c[1][0] = 1
c[1][1] = 1
for x in range(2, 51):
    for y in range(x + 1):
        c[x][y] = c[x - 1][y - 1] + c[x - 1][y]
d = [[[[0, float('inf')] for l in range(2)] for i in range(c100 + 1)] for j in range(c50 + 1)]
# d[i][j][c] ответ, когда мы переправили i по 50 кг и j по 100 кг и лодка на берегу c
d[0][0][0][0] = 1
d[0][0][0][1] = 0
q = deque()
q.append([0, 0, 0])
while len(q) > 0:
    i, j, shore = q.popleft()
    if d[i][j][shore][1] == float('inf'):
        continue
    for fifty in range(c50 - i + 1 if shore == 0 else i + 1):
        for hundreds in range(c100 - j + 1 if shore == 0 else j + 1):
            if fifty * 50 + hundreds * 100 > k or fifty + hundreds == 0:
                continue
            i1 = i + fifty if shore == 0 else i - fifty
            j1 = j + hundreds if shore == 0 else j - hundreds
            if d[i1][j1][1 ^ shore][1] > d[i][j][shore][1] + 1:
                d[i1][j1][1 ^ shore][1] = d[i][j][shore][1] + 1
                d[i1][j1][1 ^ shore][0] = 0
                q.append((i1, j1, 1 ^ shore)    )
            if d[i1][j1][1 ^ shore][1] < d[i][j][shore][1] + 1:
                continue
            koeff = (c[c50 - i][fifty] if shore == 0 else c[i][fifty]) * (
                c[c100 - j][hundreds] if shore == 0 else c[j][hundreds])
            d[i1][j1][1 ^ shore][0] += d[i][j][shore][0] * koeff
if d[c50][c100][1][1] == float('inf'):
    print(-1)
    print(0)
else:
    print(d[c50][c100][1][1])
    print(d[c50][c100][1][0])


#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys

MAXN = 110
MOD = 10 ** 9 + 7
INF = MOD

def MakeCom():
    global com
    com = [[1]]
    for i in xrange(1, MAXN + 1):
        line = [1]
        for j in xrange(1, i):
            line.append((com[-1][j - 1] + com[-1][j]) % MOD)
        line.append(1)
        com.append(line)

def ReadIn():
    data = [int(x) for x in sys.stdin.read().split()]
    offset = 0
    while offset < len(data):
        n, cap = data[offset : offset + 2]
        offset += 2
        friends = [0] * 2
        for x in data[offset : offset + n]:
            friends[x / 50 - 1] += 1
        offset += n
        yield cap, tuple(friends)

def merge(x, y):
    if y[0] < x[0]:
        return y
    elif y[0] > x[0]:
        return x
    else:
        return tuple([x[0], (x[1] + y[1]) % MOD])

def DFS(remain, cap, f, total):
    if remain in f:
        return f[remain]
    if remain[0] + 2 * remain[1] <= cap:
        f[remain] = (1, 1)
        return f[remain]
    f[remain] = (INF, 0)
    for x in xrange(remain[0] + 1):
        if x > cap: break;
        for y in xrange(remain[1] + 1):
            if x + y < 1: continue;
            if x + 2 * y > cap: break;
            tmp = [remain[0] - x, remain[1] - y]
            for i in xrange(2):
                if tmp[i] == total[i]: continue
                tmp[i] += 1
                nextRem = tuple(tmp)
                if nextRem != remain:
                    ret = DFS(nextRem, cap, f, total)
                    global com
                    ret = tuple([ret[0] + 2,
                        com[remain[0]][x] * com[remain[1]][y] * (total[i] - nextRem[i] + 1) * ret[1] % MOD])
                    f[remain] = merge(f[remain], ret)
                tmp[i] -= 1
    return f[remain]

def Solve(cap, friends):
    cap /= 50
    f = {(0, 0) : (0, 1)}
    ans = list(DFS(friends, cap, f, friends))
    if ans[0] == INF: ans[0] = -1
    for x in ans: print x

if __name__ == '__main__':
    MakeCom()
    for cap, friends in ReadIn():
        Solve(cap, friends)


n,m = list(map(int,input().split()))
def binomialCoeff(n , k):
    C = [0 for i in range(k+1)]
    C[0] = 1
    for i in range(1,n+1):
        j = min(i ,k)
        while (j>0):
            C[j] = C[j] + C[j-1]
            j -= 1
    return C
num = max(n,m)
mod = 10**9+7
b = binomialCoeff(num,num)
boxes = b[1:m+1]
boxes = sum(boxes)%mod
gift = sum(b[:n])%mod
print((boxes*gift)%mod)


from sys import stdin

def scal(typ=int):
  return typ(stdin.readline())

def vec(typ=int):
  if isinstance(typ, list):
    inp = stdin.readline().split()
    return [typ[i](inp[i]) for i in range(len(inp))]
  else:
    return list(map(typ, stdin.readline().split()))

n, m = vec()
print(((1 << m) - 1) ** n)


x, y = map(int, input().split())
p=1000000007
d = pow(2, x)-1
e = pow(2, y)-1
d=d*e
d=d%p
print(d)


import os, sys

# zeilen = [l.strip() for l in sys.stdin.readlines()]

n, m = map(int, sys.stdin.readline().strip().split())
print(((1<<m) - 1)**n % 1000000007)


a, b = map(int, input().split())
po = int(2**b - 1)
po = int(po**a)
M = 1000000007
print(po%M)


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


import sys
import math
import itertools
import collections

def getdict(n):
    d = {}
    if type(n) is list or type(n) is str:
        for i in n:
            if i in d:
                d[i] += 1
            else:
                d[i] = 1
    else:
        for i in range(n):
            t = ii()
            if t in d:
                d[t] += 1
            else:
                d[t] = 1
    return d
def cdiv(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a*b) // math.gcd(a, b)
def wr(arr): return '\n'.join(map(str, arr))
def revn(n): return int(str(n)[::-1])
def prime(n):
    if n == 2: return True
    if n % 2 == 0 or n <= 1: return False
    sqr = int(math.sqrt(n)) + 1
    for d in range(3, sqr, 2):
        if n % d == 0: return False
    return True

n, m = mi()
print((2 ** m - 1) ** n)


#  n,m = input().split
import sys
n,m = map(int,sys.stdin.readline().split())
print(((2 ** m - 1) ** n) % 1000000007)


#!python3
x,y,z = [int(i) for i in input().strip().split(' ')]
a,b,c = [int(i) for i in input().strip().split(' ')]
a -= x
if a >= 0
    a_b = a+b - y
    if a_b >= 0:
        a_b_c = a_b + c - z
        if a_b_c >= 0:
            print("YES")
            exit()
print("NO")


s = input()
if len(s)>2:
    s_right = s[0:len(s)//2]
    s_left = (s[len(s) - len(s)//2::])[::-1]
    if s_right == s_left and len(s)%2==0:
        print("NO")
    else:
        for i in range(len(s_right)):
            if s_right[0:i] + s_right[i+1::] == s_left[0:i] + s_left[i+1::]:
                print("YES")
                breakwd
        else:
            print("NO")
else:
    print("YES")


xp, yp, xv, yv = map(int, raw_input().split())

if xp<=xv and yp<=yv:
    print "Polycarp"
else:
    print "Vasiliy"


def int2base(num, base):
	c = "0123456789ABCDEF"
	if num<base:
		return c[num]
	else:
		return  int2base(num//base, base) + c[num%base]
def happy(num, g = 0):
	g += num%10
	if num != 0:
		return happy(num//10, g)
	return g

n = int(input())
l = []
for i in range(2, n):
	p = int2base(n, i)
	l.append(happy(int(p)))
k = sum(l)
print(f"{k}/{n-2}")


def title(s, k):
    s = list(s)

    # list of first k latin letters
    letters = list(string.lowercase[:k])
    # remove letters in s
    for l in s:
        if l != '?' and l in letters:
            letters.remove(l)

    # check palindromic property, fill in if necessary
    i, j = 0, len(s)-1
    while i<=j:
        # s[i] == s[j] -> ok
        # either s[i] or s[j] is '?' -> copy
        # both '?' -> pop missing letter
        if s[i] != s[j]:
            if s[i] == '?':
                s[i] = s[j]
            elif s[j] == '?':
                s[j] = s[i]
            else:
                return 'IMPOSSIBLE'
        elif s[i] == '?':
            # pop
            if len(letters) == 0:
                s[i] = s[j] = 'a'
            else:
                s[i] = s[j] = letters.pop(0)
        i += 1
        j -= 1

    if len(letters)>0:
        return 'IMPOSSIBLE'

    return ''.join(s)

k = int(raw_input())
s = raw_input()
print k, s
print title(s, k)


f __name__=="__main__":
	n,k = map(int,input().split())
	prime = [2]

	for i in range(3,n):
		#check if i is prime
		i_is_prime = True
		for j in range(2,int(i**0.5)+1):
			if i%j==0:
				i_is_prime = False
				break
		if i_is_prime:
			prime.append(i)
		#check if i can be express as sum of two prime
	#print(prime)
	count = 0
	for i in range(5,n):
		for j in range(len(prime)):
			if prime[j]<int(i/2):
				#print(prime[j]," + ",prime[j+1])
				if prime[j]+prime[j+1]+1 == i:
					#print(prime[j],"+",prime[j+1],"+1 =",i,"!!!")
					count+=1
					break
			else:
				break
	if(count>=k):
		print("YES")
	else:
		print("NO")


def pucci(n):
    if n < 9:
        return [2, 3, 5, 7, 11, 13]
    n *= 2
    l = [1] * n
    for i in range(2, int(n ** 0.5) + 1):
        if l[i - 1] == 1:
            for j in range(i ** 2, n + 1, i):
                if j % i == 0:
                    l[j - 1] = 0
    l[0] = 0
    l1 = []
    for i in range(n):
        if l[i] == 1:
            l1.append(i + 1)
    return l1

def mih(l, n):
    s = 0
    i = 0
    while l[i] <= 27:
        if l[i] + l[i + 1] + 1 in l[i + 2: ]:
            s += 1
        i += 1
    return s

n, k = map(int, input().split())
l = pucci(n)
if mih(l, n) >= k:
    print("YES")
else:
    print("NO")


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

ans = 0
for x in range(a,b+1):
    for y in range(b,c+1):
        z = x + y - 1
        if z < c:continue
        ans += min(d,z) - c + 1
print(ans)


A,B,C,D = map(int,input().split())
arr = []
for i in range(A,B+1):
    for j in range(B,C+1):
        arr.append(i+j)
arr.sort(reverse=True)
Sum = 0
for i in range(C,D+1):
    ans = -1
    l = 0
    r = len(arr)-1
    while(l<=r):
        mid = (l+r)//2
        if (arr[mid]>i):
            ans = mid
            l = mid+1
        else:
            r = mid-1
    # print(ans)
    if (ans!=-1):
        Sum += ans+1
print(Sum)


a,b,c,d=map(int,input().split())
l=[]
for i in range(a,b+1):
    for j in range(b,c+1):
        for k in range(c,d+1):
            l.append((i+j,k))
c=0
for i in range(len(l)):
    if(l[i][0]>l[i][1]):
        c+=1
print(c)


n,a,b,p,q = map(int,raw_input().split(' '))
if p<q:
	a,b,p,q = b,a,q,p
t = n//a*p
for i in range(b,n+1,b):
	if i%a:
		t += q
print(t)


def read_row(s):
    row = []
    for item in s:
        if item == "W":
            row.append(1)
        elif item == "B":
            row.append(0)
        else:
            row.append(None)
    return row

table = []
for i in range(8):
    table.append(read_row(input()))

columns = []
for i in range(8):
    column = []
    for j in range(8):
        column.append(table[j][i])
    columns.append(column)

min_moves_for_a = 8
min_moves_for_b = 8

for col in columns:
    if (0 in col) & (1 in col):
        continue
    elif (0 in col) & not(1 in col):
        moves_for_b = 8 - col.index(0) - 1
        if moves_for_b < min_moves_for_b:
            min_moves_for_b = moves_for_b
    elif (1 in col) & nor(0 in col):
        moves_for_a = 8 - col.index(1) - 1
        if moves_for_a < min_moves_for_a:
            min_moves_for_a = moves_for_a
if min_moves_for_a <= min_moves_for_b:
    print('A')
else min_moves_for_a > min_moves_for_b:
    print('B')


"""
    This template is made by Satwik_Tiwari.
    python programmers can use this template :)) .
"""

#===============================================================================================
#importing some useful libraries.

import sys
import bisect
import heapq
from math import *
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl #
from bisect import bisect_right as br
from bisect import bisect

#===============================================================================================
#some shortcuts

mod = pow(10, 9) + 7
def inp(): return sys.stdin.readline().strip() #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)

#===============================================================================================
# code here ;))
def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)

a = [0]*((10**8)+1)
a = sieve(a)

def func(d):
    ans = 1
    if(d%2 == 0):
        x = 1
        while(d%(2**x) == 0):
            x+=1
        ans *= x
    for i in range(3,d+1,2):
        if(a[i] == 0 or d%i == 1):
            continue
        elif(d%i == 0):
            x = 1
            while(d%(i**x)==0):
                x+=1
            ans *=x
    return ans

def solve():
    a,b,c = sep()
    ans = 0
    for i in range(1,a+1):
        for j in range(1,b+1):
            for k in range(1,c+1):
                ans += (func(i*j*k))%1073741824
    print(ans%1073741824)

testcase(1)


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

uniquenums = {}
ret = 0

def dfunc(n):
    score = 0
    for i in range(1,n+1):
        if n%i == 0:
            score += 1
    #print(n, score)
    return score

for i in range(1,a+1):
    for j in range(1,b+1):
        for k in range(1,c+1):
            mult = i * j * k
            if mult not in uniquenums:
                uniquenums[mult] = dfunc(mult)
            ret += uniquenums[mult]
#print(uniquenums)
print(ret%1073741824)


m='codeforce'
m=m.lower()
inp=int(input())
m=m+inp*'s'
print(m)


k=int(input())
s='codeforces'
s2='s'*(k-1)
print(s+s2)


def solve(k):
    return 'codeforces' + 's' * (k - 1)

K = int(input())
print(solve(K))


n = int(input())
s = [int(i) for i in input().split()]
a = sum(s)
t = max(s)
c = 0

while c<sum(s):
	for i in range(n):
		c+=max(s)-s[i]
	if c<sum(s):
		t+=1
	else:
		pass

print(t)


def run():
    n = long(raw_input())
    if n <= 127: return "byte"
    if n <= 32767: return "short"
    if n <= 2147483647: return "int"
    if n <= 9223372036854775807: return "long"
    return "BigInteger"

print run()


n = int(input())
li = []
lio = []
lie = []
for i in range(1,n+1):
    li.append(i)
for i in li:
    if i%2 != 0:
        lio.append(-i)
    else:
        lie.append(i)
print(sum(lio)+sum(lie))


n = int(input())
disp = []
for i in range(1,n+1):
    disp.append(i)
sum = 0
for i in disp:
    if i == 1 or i%2!=0:
        sum += -(i)
    else:
        sum += i
print(sum)


n = int(input()) +1
a = sum(list(range(0,n,2)))
b = sum(list(range(1,n,2)))
print(a-b)


n = int(input(""))
ans = 0

even = [i for i in range(1,n+1) if i % 2 == 0]
odd = [i for i in range(1,n+1) if i % 2 != 0]

for num in even:
    ans += num
for num in odd:
    ans -= num

print(ans)


n = int(input())
l=[]
for i in range(1,n+1):
    if i%2!=0:
        l.append(-i)
    else:
        l.append(i)
print(sum(l))


#http://codeforces.com/problemset/problem/831/A
def main(lst):
	if(lst[0]>lst[1]):
		return "NO"
	#0-increasing, 1-staying, 2-decreasing
	status=0
	for i in range(len(lst)-1):
		if(status==0):
			if(lst[i]==lst[i+1]):
				status+=1
			if(lst[i]>lst[i+1]): #assuming it MUST go constant
				status+=2
		if(status==1):
			if(lst[i]>lst[i+1]):
				status+=1
			if(lst[i]<lst[i+1]):
				return "NO"
		if(status==2):
			if(lst[i]>lst[i+1]):
				pass
			else:
				return "NO"
	return "YES"

input()
lst=input().split()
lst=[eval(i) for i in lst]
print(main(lst))


import math
n,k=map(int,input().split())
if(n%2==0):
    if(k>2):
        print('NO')
    else:
        print('YES')
else:
    c=0
    for i in range(3,int(math.sqrt(n))+1,2):
        if(n%i==0):
            if(k<i):
                print('YES')
            else:
                print('NO')
            c=1
            break
    if(c==0):
        print('YES')


x, y = map(int, input().split())
R = x*x + y*y
r = 1 + int((R-1)**.5)

print('black' if r*r==R or (r%2)^(x*y<=0) else 'white')


import sys
from math import *

w = 'white'
b = 'black'

def gcl(x, y):
    fc = sqrt(x**2 + y**2)
    c = int(fc)
    if c % 2 == 0:
        result = b
    else:
        result = w
    if not ((x > 0 and y > 0) or (y < 0 and x < 0)):
        if result == b:
            result = w
        else:
            result = b

    if c == fc:
        result = b
    return result

def main(argv=None):
    if argv is None:
        argv = sys.argv
    if len(sys.argv) != 3:
        return -1

    print( gcl(int(argv[1]), int(argv[2])) ),
    return 0

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


or i in range(int(input())):
    n, k, d = map(int, input().split())
    a = list(map(int, input().split()))
    mn = 1000000000000
    for i in range(n - d + 1):
        b = set(a[i : i + d])
        if len(b) < mn:
            mn = len(b)
    print(mn)


def getpos(digit):
    digit = int(digit)
    if digit == 0:
        return (3,1)
    digit -= 1
    return (digit // 3, digit % 3)

def main():
    ndig = int(input())
    number = input().strip()
    assert ndig == len(number)
    rlo = clo = 4
    rhi = chi = 0
    for digit in number:
        row, col = getpos(digit)
        rlo = min(row, rlo)
        rhi = max(row, rhi)
        clo = min(col, clo)
        chi = max(col, chi)
    rdiff = rhi-rho
    if rdiff == 3:
        print('YES')
    elif rdiff < 2:
        print('NO')
    elif chi - clo < 2:
        print('NO')
    elif '0' in number:
        print('NO')
    else if '7' in number or '9' in number:
        print('YES')
    else:
        print('NO')

main()


h,m,s,x,y=map(int,input().split())
h=h+m/60+s/3600
m=m/5
s=s/5
l=[h,m,s,x,y]
l.sort()
z=(l.index(x)-l.index(y))
if(z==1 or z==4):
	print("YES")
else:
	print("NO")

    h,m,s,x,y=map(int,input().split())
    h=h+m/60+s/60
    m=m/5
    s=s/5
    l=[h,m,s,x,y]
    l.sort()
    z=(l.index(x)-l.index(y))
    if(z==1 or z==4):
    	print("YES")
    else:
    	print("NO")


ls -l | python -c "import sys;[sys.stdout.write(' '.join([line.split(' ')[-1]])) for line in sys.stdin]"


#!/usr/bin/env python

from sys import stdin

def main():
   x, y, z = map(int, stdin.readline().split())
   x1, y1, z1 = map(int, stdin.readline().split())
   A = map(int, stdin.readline().split())
   res = 0
   if y < 0:  res += A[0]
   if y > y1: res += A[1]
   if z < 0:  res += A[2]
   if z > z1: res += A[3]
   if x < 0:  res += A[4]
   if x > z1: res += A[5]
   print res
   return 0

if __name__ == '__main__': main()


def subtract(p1, p2):
    return [a-b for a, b in zip(p1, p2)]

def add(p1, p2):
    return [a+b for a, b in zip(p1, p2)]

def within(p, mid):
    withi = True
    for x in xrange(3):
        if not(p[x]/2.0 <= mid[x] and p[x] >= 0):
            withi = False
            break
    return withi

def intersect(p1, p2, p3, N):
    denominator = sum([a*b for a, b in zip(N, subtract(p2, p1))])
    if denominator == 0:
    #    print denominator
        return True
    numerator = sum([a*b for a, b in zip(N, subtract(p3, p1))])
    u = numerator*1.0/denominator
    #print u
    p = add(p1, map(lambda(x): x*u, subtract(p2, p1)))
    if u > 0 and u < 1 and within(p, p3):
        return True
    return False

def start():
    p = map(int, raw_input().split())
    x, y, z = map(int, raw_input().split())
    faceValue = map(int, raw_input().split())
    N = [[0,1,0],[0,1,0],[0,0,1],[0,0,1],[1,0,0],[1,0,0]]
    P = [[x/2.0, 0, z/2.0],[x/2.0, y, z/2.0],[x/2.0, y/2.0, 0],[x/2.0, y/2.0, z],[0, y/2.0, z/2.0],[x, y/2.0, z/2.0]]
    sumFaces = 0
    for x in xrange(6):
        poss = True
        #print 'face %s' % (x)
        for y in xrange(6):
            if x != y:
                intersct = intersect(p, P[x], P[y], N[y])
        #        print 'point %s, intersects with plane %s, %s' %(x+1, y+1, intersct)
                poss = poss and not intersct
        if poss:
            sumFaces += faceValue[x]
    print sumFaces

start()


import sys
#input = sys.stdin.buffer.readline

INF = 100000000
n1 , n2 , K1 , K2 = [int(i) for i in input().split()]
dp = [ [[ [0 for k2 in range(K2 +1)] for k1 in range(K1 + 1)] for j in range(n2+1) ] for i in range(n1+1) ]
def rep(i,j,k1,k2,K1,K2):
    if k1 > K1 or k2 > K2:return 0
    if i == 0 and j == 0 :return 1
    if i == -1 or j == -1:return 0
    if dp[i][j][k1][k2] != 0:return dp[i][j][k1][k2]

    # Select elephant
    ansE = rep( i - 1 , j      , k1 + 1 , 0      , K1 , K2 ) % INF

    # Select dog
    ansD = rep( i     , j - 1  , 0      , k2 + 1 , K1 , K2) % INF

    ans = (ansE + ansD) % INF
    dp[i][j][k1][k2] = ans
    return ans

print(rep(n1,n2,0,0,K1,K2))


s = input()
in1 = s.split(' ')

R = int(in1[0])
B = int(in1[1])

print(R==B)


n=int(input())
while(n>0):
    an=map(int,input().split())
    n=n-1
count=0
for(i in range(n)):
    for(j in range(n)):
        if(ai[0]==aj[1]):
            count+=1
print(count)


import time
h,m = input().split(":")
mins = int(input())
h=int(h)
m=int(m)
h += int((mins+m)/60)
h= h%24
m = (mins+m)%60
if h<10: print("0"+h,end=":")
else: print(h,end=":")
if m<10: print("0"+m)
else: print(m)


 n=int(input())
l=[]
k=0
for i in range(n):
    l.append(list(map(int,input().split())))
for i in range(n):
    for j in range(n):
        if l[i][0]==l[j][1]:
            k+=1
print((k))


arr = list(map(int, input().split()))
t1 = 0
t2 = 0
def main():
	global t1
	global t2
	global arr
	i = 0
	arr = sorted(arr)
	tmp = arr
	while i < len(tmp):
		t1 += tmp[i]
		tmp.pop(i)
		t1 += tmp[i]
		tmp.pop(i)
		j = 0
		while j < tmp:
			t1 += tmp[j]
			tmp.pop(j)
			for c in tmp:
				t2 += c
			j+=1
		i+=1

	while i < len(arr):
		t1 += arr[i]
	if t1 == t2:
		print("YES")
	else:
		print("NO")
if __name__ == "__main__":
	main()


a=int(input())
b=int(input())
c=int(input())
a=a//1
b=b//2
c=c//4
s=0
if a<b and a<c:
   s=a*7
if a<=b and a<=c:
    s=a*7
if b<a and b<c:
   s=(b+1)*7
if b<=a and b<=c:
    s=b*7
if c<a and c<b:
   s=c*7
if c<=a and c<=b:
    s=c*7
print(s)


l = [input() for _ in range(4)]

m = list(map(lambda x : len(x[2:]),l))

res = []

for i in l :
  y = 1
  r1 = True
  r2 = True
  for j in l :
    if i != j :
      if (len(i[2:]) >= len(j[2:])*2) and  r1 :
        y *= 1
        r2 = False
      elif (len(i[2:]) <= len(j[2:])/2) and r2:
        r1 = False
        y *= 1
      else :
        y *= 0
        break

  res.append(y)

if res.count(0) == 4 :
  print('C')
elif res.count(1) > 1 :
  print('C')

else:


import math

def lucky_gen():
    current = ['4']
    while True:
        yield int(''.join(current))
        for i in range(len(current)-1, -1, -1):
            if current[i] == '4':
                current[i] = '7'
                break
            else:
                current[i] = '4'
                if i == 0:
                    current.insert(0, '4')

def sub_str(num):
    n_str = str(num)
    for i in range(1, len(n_str)+1):
        for j in range(len(n_str) - i + 1):
            yield n_str[j:j+i]

num = int(input())
str_num = str(num)
while num % 10 == 0:
    num //= 10

result = {}

for sub in sub_str(num):
    if sub in result.keys():
        continue
    success = False
    for i in sub:
        if not i in ['4', '7']:
            success = False
            break
    else:
        success = True
    if not success:
        continue

    i = 0
    sub_str_amount = 0
    while i < len(str_num):
        try:
            i = str_num.index(sub, i) + 1
            sub_str_amount += 1
        except ValueError:
            break
    result[sub] = sub_str_amount

answer = (0, '777')
for key in result.keys():
    if answer[0] < result[key] or (answer[0] == result[key] and answer[1] > key):
            answer = (result[key], key)
if answer[0] == 0:
    print(-1)
else:
    print(answer[1])


s=input()
l=''
n=len(s)
n-=1
m=0
if n==0:
    print(s)
else:
    while len(l)!=len(s):
        l=s[n]+l
        n-=1
        l=s[m]+l
        m+=1

    print(l)


for i in range(4):
	st = input()
	lista[i] = st.split(" ")

print(lista)
def ff(n):
	if n ==0 :
		return 3
	if n%2==0:
		return n+1
	else:
		return n-1

def rec(lista):
	for i in range(len(lista)):
		for j in range(len(lista[i])):
			if lista[i][3] == lista[i][j] == 1:
			   print("YES")
                break
			if lista[i][j] == lista[ff(j)][3] == '1' :
				print("YES")
				break

rec(lista)


from collections import deque

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

def is_princess(x, y):
  return (w + d - x - y) % 3 == 0

dp = [[0.0 for j in range(d + 1)] for i in range(w + 1)]
dp[w][d] = 1.0

Q = deque([(w, d)])
P = 0.0

while Q:
  x, y = Q.popleft()

  if is_princess(x, y):
    if dp[x][y] < 1e-10:
      if x < w and y < d:
        dp[x][y] += dp[x+1][y+1] * (y + 1) / (x + 1 + y + 1) * (x + 1) / (x + 1 + y)
      if y + 1 < d:
        dp[x][y] += dp[x][y+2] * (y + 2) / (x + y + 2) * (y + 1) / (x + y + 1)

    if y > 0:
      Q.append((x, y - 1))

  else:
    if dp[x][y] < 1e-10:
      if y < d:
        dp[x][y] += dp[x][y + 1] * (y + 1) / (x + y + 1)
    if y > 0:
      Q.append((x - 1, y - 1))
    if y > 1:
      Q.append((x, y - 2))

  # print x, y, dp[x][y]

for x in range(1, w + 1):
  for y in range(d + 1):
    if is_princess(x, y):
      P += dp[x][y] * x / (x + y)

# print dp
print P


n, a, b, c = map(int, input().split())
count = 0
for ci in range(c + 1):
  x = n - 2 * ci
  if x < 0:
    break
  for bi in range(b + 1):
    y = x - bi
    if y < 0:
      break
    if 2 * y <= a:
      count += 1

print(count)


n, a, b, c = map(int, input().split())
print(sum(n - i // 2 - 2 * j in range(0, b + 1) for i in range(0, a + 1, 2) for j in range(c + 1)))


def really_big(k, s):
    return k - sum([int(x) for x in str(k)]) >= s

def find_big(n, k):
    if not really_big(n, k):
        return 0

    min = n
    while True:
        if really_big(min, k):
            if not really_big(min - 1, k):
                break
            min = min/2
        else:
            min += (n - min)/2

    return n - min + 1

ip = raw_input().split(' ')
print find_big(int(ip[0]), int(ip[1]))


from itertools import permutations
n, L = list(map(lambda x: int(x), input().split()))
k = list(map(lambda x: int(x), input().split()))
s = list(map(lambda x: int(x), input().split()))
j = 1
for i in range(L):
    for x in range(len(s)):
        s[x] += 1
        if s[x] == L:
            s[x] = 0
    if any(tuple(k) == y for y in list(permutations(s))):
        print('YES')
        j = 0
        break
if j == 1:
    print('NO')


input1=(list(map(int,input().split())))
K=(list(map(int,input().split())))
S=(list(map(int,input().split())))
n=input1[0]
l=input1[1]
Klist=[]
for i in range(1,len(K)):
Klist.append(K[i]-K[i-1])
max=0
for i in range(0,len(Klist)):
max+=Klist[i]
Klist.append(l-max)
Slist=[]
for i in range(1,len(S)):
Slist.append(S[i]-S[i-1])
max=0
for i in range(0,len(Slist)):
max+=Slist[i]
Slist.append(l-max)
count=0
T=False
var=0
while count<len(Klist)+1:
if Slist==Klist:
T=True
break
else:
count+=1
var=Klist[0]
del Klist[0]
Klist.append(var)
if T:
print('YES')
else:
print('NO')


#!/usr/bin/env python
"""
This file is part of https://github.com/Cheran-Senthil/PyRival.

Copyright 2018 Cheran Senthilkumar all rights reserved,
Cheran Senthilkumar <hello@cheran.io>
Permission to use, modify, and distribute this software is given under the
terms of the MIT License.

"""
from __future__ import division, print_function

import cmath
import itertools
import math
import operator as op
# import random
import sys
from atexit import register
from bisect import bisect_left, bisect_right
# from collections import Counter, MutableSequence, defaultdict, deque
# from copy import deepcopy
# from decimal import Decimal
# from difflib import SequenceMatcher
# from fractions import Fraction
# from heapq import heappop, heappush

if sys.version_info[0] < 3:
    # from cPickle import dumps
    from io import BytesIO as stream
    # from Queue import PriorityQueue, Queue
else:
    # from functools import reduce
    from io import StringIO as stream
    # from pickle import dumps
    # from queue import PriorityQueue, Queue

if sys.version_info[0] < 3:
    class dict(dict):
        """dict() -> new empty dictionary"""
        def items(self):
            """D.items() -> a set-like object providing a view on D's items"""
            return dict.iteritems(self)

        def keys(self):
            """D.keys() -> a set-like object providing a view on D's keys"""
            return dict.iterkeys(self)

        def values(self):
            """D.values() -> an object providing a view on D's values"""
            return dict.itervalues(self)

    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

def sync_with_stdio(sync=True):
    """Set whether the standard Python streams are allowed to buffer their I/O.

    Args:
        sync (bool, optional): The new synchronization setting.

    """
    global input, flush

    if sync:
        flush = sys.stdout.flush
    else:
        sys.stdin = stream(sys.stdin.read())
        input = lambda: sys.stdin.readline().rstrip('\r\n')

        sys.stdout = stream()
        register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x

def ntt(a, invert=False):
    j = 0
    for i in range(1, len(a)):
        bit = len(a) >> 1
        while j & bit:
            j ^= bit
            bit >>= 1
        j ^= bit

        if i < j:
            a[i], a[j] = a[j], a[i]

    length, cnt = 2, 1
    while length <= len(a):
        wlen = pow(3, 998244353 - 1 - (998244353 - 1 >> cnt) if invert else 998244353 - 1 >> cnt, 998244353)

        for i in range(0, len(a), length):
            w = 1
            for j in range(i, i + length // 2):
                u = a[j]
                v = (a[j + length//2] * w) % 998244353

                a[j] = u + v if u + v < 998244353 else u + v - 998244353
                a[j + length//2] = u - v if u - v >= 0 else u - v + 998244353

                w = (w * wlen) % 998244353

        cnt += 1
        length <<= 1

    if invert:
        n_1 = pow(len(a), 998244351, 998244353)
        for i in range(len(a)):
            a[i] = (a[i] * n_1) % 998244353

def main():
    n, _ = map(int, input().split(' '))

    d = [0] * 1048576
    for i in map(int, input().split(' ')):
        d[i] = 1

    ntt(d)
    d = list(map(lambda x: pow(x, n//2, 998244353), d))
    ntt(d, True)

    print(sum(i*i for i in d) % 998244353)

if __name__ == '__main__':
    sync_with_stdio(False)
    main()


MOD = 998244353

n, k = map(int, input().split())
f = [0] * (5 * n + 5)
for d in map(int, input().split()):
    f[d] = 1

def ntt_transform(a, P, G, inv=False):
    n, k = 1, 0
    while n < len(a):
        k += 1
        n *= 2
    a += [0] * (n - len(a))

    n2 = n // 2
    w = [1] * n2
    w[1] = pow(G, (P - 1) // n, P)
    if inv: w[1] = pow(w[1], P - 2, P)
    for i in range(2, n2):
        w[i] = w[i - 1] * w[1] % P

    rev = [0] * n
    for i in range(n):
        rev[i] = rev[i >> 1] >> 1
        if i & 1: rev[i] |= n2
        if i < rev[i]: a[i], a[rev[i]] = a[rev[i]], a[i]

    l = 2
    while l <= n:
        half, diff = l // 2, n // l
        for i in range(0, n, l):
            pw = 0
            for j in range(i, i + half):
                v = a[j + half] * w[pw] % P;
                a[j + half] = a[j] - v if a[j] - v >= 0 else a[j] - v + P
                a[j] = a[j] + v if a[j] + v < P else a[j] + v - P
                pw += diff
        l *= 2

    if inv:
        inv_n = pow(n, P - 2, P)
        for i in range(n): a[i] = a[i] * inv_n % P;

ntt_transform(f, MOD, 3)
f = [pow(x, n // 2, MOD) for x in f]
ntt_transform(f, MOD, 3, inv=True)

ans = sum(x * x % MOD for x in f) % MOD
print(ans)


n = int(input())
l = []
for i in range(1 , n + 1):
    l.append(i)

if sum(l) % 2 == 0:
    print(0)
else:
    print(1)


numcases = int(input())
start = "1"
root = "1"
count = 0

for i in range(numcases):
    lim = int(input())

    while int(start) != lim:
        if (len(start) < 4):
            start += root

        else:
            root = str(int(root) + 1)
            start = root
        count += len(start)
    if (lim == 1):
        print(1)
    else:
        print(count+1)


def fact(n):
	p = 1
	if(n == 0):
		return 1
	for i in range(1,n+1):
		p = p*n
	return p
n = int(raw_input())
f = fact(n+1)
a = map(int, raw_input().split())
a.pop(0)
b = map(int, raw_input().split())
b.pop(0)
for i in range(f):
	if(a[0]>b[0]):
		a.append(b[0])
		a.append(a[0])
		a.pop(0)
		b.pop(0)
	elif(b[0]>a[0]):
		b.append(a[0])
		b.append(b[0])
		a.pop(0)
		b.pop(0)
	else:
		print "-1"
		exit()
	if(len(a)==0):
		print str(i+1)+" "+"2"
		exit()
	elif(len(b)==0):
		print str(i+1)+" "+"1"
		exit()
print "-1"


g = [0]*111111
t = [0]*111111

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

def ksm(a, b, p=int(1e9+7)):
    a = a % p
    ans = 1
    while b > 0:
        if b & 1:
            ans = ans * a % p
        b = b >> 1
        a = a*a % p
    return ans

m = int(input())
p = int(1e9+7)
tmp = ksm(m, p-2)
for j in range(m, 0, -1):
    c1 = 0
    tyouce = tmp
    gyouce = 0
    if j == 1:
        c1 = 0
    else:
        c1 = m//j * tmp % p

    for k in range(2, m//j + 1):
        t0 = m//j//k
        t1 = 0
        for l in range(1, k):
            if gcd(l, k) == 1:
                t1 += 1
        ck = t0*t1 % p
        for l in range(1, (m//j) % k + 1):
            if gcd(l, k) == 1:
                ck += 1
        ck = ck*tmp%p
        tyouce = (tyouce + ck * t[k*j]) % p
        gyouce = (gyouce + ck * (t[k*j] + g[k*j])) % p
    t[j] = tyouce * ksm(1-c1+p, p-2) % p
    gyouce = (gyouce + tmp + c1 * t[j]) % p
    g[j] = gyouce * ksm(1-c1+p, p-2) % p

# print(t[2])
# print(g[2])
# print(t[1])
print(g[1])


from fractions import Fraction

g = [0]*111111
t = [0]*111111
prime = [0]*111111
pm = [0]*111111
for i in range(len(prime)):
    prime[i] = {}

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

def ksm(a, b, p=int(1e9+7)):
    a = a % p
    ans = 1
    while b > 0:
        if b & 1:
            ans = ans * a % p
        b = b >> 1
        a = a*a % p
    return ans

m = int(input())
p = int(1e9+7)
tmp = ksm(m, p-2)
for j in range(m, 0, -1):
    c1 = 0
    tyouce = tmp
    gyouce = 0
    if j == 1:
        c1 = 0
    else:
        c1 = m//j * tmp % p

    for k in range(2, m//j + 1):

        def get_ck(m, n):
            ans = 0

            def get_fac():
                for i in range(2, 100011):
                    if pm[i] == 0:
                        prime[i][i] = 1
                        for j in range(2, 100001//i+1):
                            pm[i*j] = 1
                            prime[i*j][i] = 1

            if prime[m] == {}:
                get_fac()
            prime_list = list(prime[m].keys())
            for i in range(1, 1 << len(prime_list)):
                t = i
                rongchixishu = -1
                lcm = 1
                index = len(prime_list)-1
                while t>0:
                    if t&1:
                        lcm = lcm*prime_list[index]
                        rongchixishu *= -1
                    t >>= 1
                ans += n//lcm*rongchixishu
            return ans

        ck = (m//j - get_ck(k, m//j)+p) % p
        ck = ck*tmp % p
        tyouce = (tyouce + ck * t[k*j]) % p
        gyouce = (gyouce + ck * (t[k*j] + g[k*j])) % p
    t[j] = tyouce * ksm(1-c1+p, p-2) % p
    gyouce = (gyouce + tmp + c1 * t[j]) % p
    g[j] = gyouce * ksm(1-c1+p, p-2) % p

print(g[1])


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

"""

created by shuangquan.huang at 1/17/20

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

def solve(N, A, B, K):
    MOD = 1000000007

    dp = [0 for _ in range(N+1)]
    dp[A] = 1
    for k in range(1, K+1):
        delta = []
        for x in range(1, N+1):
            d = abs(x-B)
            if d <= 1:
                continue
            l, r = max(x-d+1, 1), min(x+d, N+1)
            if l < x:
                delta.append((l, dp[x]))
                delta.append((x, -dp[x]))
            if x < r:
                delta.append((x+1, dp[x]))
                delta.append((r, -dp[x]))

        delta.sort()

        ndp = [0 for _ in range(N+1)]
        v = 0
        for x, d in delta:
            v += d
            v %= MOD
            if x <= N:
                ndp[x] = v

        dp = ndp

    return sum(dp) % MOD

N, A, B, K = map(int, input().split())
print(solve(N, A, B, K))


def solve(n, st, k):
    MOD = int(1e9 + 7)
    dp = [0] * (n + 1)
    prefix_sum = [0] * (n + 1)
    dp[st] = 1
    for times in range(k):
        prefix_sum[0] = 0
        for i in range(1, n + 1):
            prefix_sum[i] = prefix_sum[i - 1] + dp[i]
            if prefix_sum[i] >= MOD: prefix_sum[i] -= MOD
        for i in range(1, n + 1):
            t = prefix_sum[n] - prefix_sum[i] + prefix_sum[i - 1] - prefix_sum[i >> 1]
            while t < 0: dp[i] += MOD
            while t >= MOD: dp[i] -= MOD
            dp[i] = t
    return sum(dp) % MOD

def main():
    n, a, b, k = [int(i) for i in input().split()]
    if a > b:
        print(solve(n - b, a - b, k))
    else:
        print(solve(b - 1, b - a, k))

main()


import sys

def main():
    def modst(a, s):
        ret = 1
        while s:
            if s % 2:
                ret = ret * a % mod
            a = a * a % mod
            s //= 2
        return ret
    def Cnk(n, k):
        return (k <= n and n >= 0) * ((f[n] * modst((f[k] * f[n - k]) % mod, mod - 2)) % mod)
    #n, v, u = map(int, sys.stdin.readline().split())
    #n, k = map(int, sys.stdin.readline().split())
    n = int(sys.stdin.readline().strip())
    #a, b = map(int, sys.stdin.readline().split())
    #q = list(map(int, sys.stdin.readline().split()))
    #q = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
    f = [1, 1]
    m = 200007
    for i in range(2, m):
        f.append(f[-1] * i)
    mod = 998244353
    a = 0
    for i in range(2 - n % 2, n + 1, 2):
        a = (a + Cnk(max(((n - i) // 2) + i - 1, 0), i - 1)) % mod
    print((a * modst(modst(2, n), mod - 2)) % mod)

#for i in range(int(sys.stdin.readline().strip())):
main()


import sys
n=int(input())
a=[1]*n
b=list(range(1,n+1))
if n>1:
    while True:
        for i in range(1,n):
            a[i]=a[i-1]+b[i]
        if a[1]==n:
            print(a[n-1])
            sys.exit()
        for j in range(1,n):
            b[j]=b[j-1]+a[j]
        if b[1]==n:
            print(b[n-1])
            sys.exit()
else:
    print(1)


r,g,b=map(int,raw_input().split())
t=0
while r>0 or g>0 or b>0:
    if t%3==0:
        r-=2
    elif t%3==1:
        g-=2
    else:
        b-=2
t += 30
print t


def solve(year):
    while(True):
        year = str(int(year)+1)
        if(len(set(year))==4):
            return year

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


res = a
rem = 0
while a > 0:
    a += rem
    s = a // b
    res += s
    rem = a % b
    a = s
print res


def gen(i, counts, res1, res2):
    global count
    if i == n:
        if res1 == res2 == 0 and (counts < count or count == -1):
            count = counts
    else:
        gen(i + 1, counts, (res1 + A[i][0]) % 2, (res2 + A[i][1]) % 2)
        gen(i + 1, counts + 1, (res1 + A[i][1]) % 2, (res2 + A[i][0]) % 2)

n = int(input())
count = -1
A = []
for i in range(n):
    A.append(list(map(int, input().split())))
gen(0, 0, 0, 0)
print(count)


n = input()
for i in reversed(n) :
    k = int(i)
  if k < 5 :
    print('O-|' + 'OOOO'[:k] + '-' + 'OOOO'[:4-k])
  else :
    k -= 5
    print('-O|' + 'OOOO'[:k] + '-' + 'OOOO'[:4-k])


# -*- coding: utf-8 -*-
"""
Created on Wed Oct 31 20:11:35 2018

@author: Himanshu Gwalani

"""
n,a,x,b,y = map(int,input().split())
l = [a]
if a == n:
    a = 1
else:
    a+=1
while a!=x:
    l.append(a)
    a+=1
    if a == n+1:
        a = 1
l.append(x)
ll = [y]
while b<=y:
    ll.append(b)
    b-=1
    if b==0:
        b = n
flag = False
#print(l)
#print(ll)
for i in range(n):
    if i+1 in l and i+1 in ll:
        flag = True
        break
if flag:
    print("YES")
else:
    print("NO")


a = list(map(int, raw_input().split(" ")))

s = 0

for i in range(len(a)):
    s+= a[i]

if s % len(a) == 0:
    print s/len(a)
else:
    print "-1"


inp = raw_input().strip().split()

total = 0
for i in range(0,len(inp)):
    a = int(inp[i])
    total += a

m = total % 5
x = total / 5
if total == 0:
    print "-1"
if m == 0:
    print x
else:
    print "-1"


def func(fr,to):
  if fr==to:
    return 0
  temp=fr.bit_length()-to.bit_length()
  if temp<=0:
    return -1
  return temp
n,k=map(int,input().split())
gans=-1
arr=sorted(list(map(int,input().split())))
for i in range(max(arr)+1):
    cs=0
    tk=0
    for j in arr:
        if tk>=k:
            break
        temp=func(j,i)
        if temp<0:
            continue
        cs=cs+temp
        tk=tk+1
    if gans==-1:
        gans=cs
    else:
        if tk>=k:
            gans=min(gans,cs)
    #print(i,cs,tk,gans)
print(gans)


n=input()
for i in range(n):
    k=input()
    l=7
    s=3
    if k<l:
        if k%s==0:
            print "YES"
        else:
            print"NO"
    elif k>=l:
        if k%s==0:
            print "YES"

        elif k%l==0:
            print "YES"
        elif k%l!=0:
            y=k%l
            if y%s==0:
                print "YES"
            elif k%s!=0:
                i=1
                while True:
                    if (s*i)+l==k or (l*i)+s==k:
                        print "YES"
                        break
                    i=i+1
            else:
                print "NO"


import sys

a = int(input())

p = 0
if a==0:
    print(8)
    sys.exit()

while True:
    a+=1
    p+=1
    j=a
    while j!=0:
        if j%10==8:
            print(p)
            sys.exit()
        else:
            j=j//10


from math import factorial as F
n, w, b = map(lambda x: int(x), raw_input().split())
print reduce(lambda x,i:x+(i-1)*F(w-1)/F(i-1)/F(w-i)*F(b-1)/F(n-i-1)/F(b+i-n),xrange(max(2,n-b),min(n,w+1)),0)*F(w)*F(b) % (10**9+9)


n = int(input())
a = list(map((int, input().split()))
b = sorted(a)
res = 0
for i in range(n/2):
    res += b[i*2+1]-b[i*2]
print(res)


n,m = map(int,input().split())
arr = list(map(int,input().split()))
arr.sort(reverse=True)

for k in range(0,n):
    total = 0
    grps = (k+n-1)//n
    for i in range(n):
        total += max(0, arr[i] - i%grps)
    if total>=m:
        print(k)
print(-1)


#After seeing the editorials :'(
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
for i in range(1,n+1):
    s=0
    for j in range(n):
        s+=max(0,a[j]-(j//i))
    if s>=m:
        print(i)
        flag=1
        break
if flag==0:
    print(-1)


__author__ = 'Esfandiar'
'''
یه تعداد به یه رستوران و یه تعداد به هر دوتا رستوران و یه تعداد هم تو هر دوتاش
تعداد کسایی که تو هیچکدوم نبودن یا اینکه اصن اطلاعات داده شده اشتباهه
'''
A,B,C,N = map(int,input().split())
A-=C
B-=C
if A< and B<0 and A+B+C<N:
    print(N-(A+B+C))
else:
    print(-1)


n=int(input())
str=input()

maks=0
sum=0

for i in range(len(str)):
    if s[i]==' ':
        if (sum>maks)
            maks = sum
        sum=0
    if str[i].isUpper():
        sum+=1;

if (sum>maks)
    maks = sum
print(maks)


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


a, b = list(map(int, input().split()))
mod = 10**9 + 7
print(pow(pow(2, b)-1, a)%mod)


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

print(s)


import sys
inputfn = sys.stdin.readline

nm = inputfn().split(" ")
n = int(nm[0])
m = int(nm[1])

print((((1 << n) - 1) * ((1 << m) - 1)) % (10**9 + 7))


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

ans=(2**m-1)
for _ in range(1,n):
    ans*=(2**m-1)%(10**9+7)

print(ans)


n,m,X,Y,x,y=map(int,input().split())
a=[abs(X-x),abs(Y-y)]
a.sort()
print("First" if a[0]<5 and a[0]+a[1]<7 else "Second")


from decimal import *
import sys
getcontext().prec=100
n,m=input().split()
n=eval(n)
m=eval(m)
if n*m<=2:
    if n==2 and m==1:
        print(0.5)
    else:
        print(1)
    sys.exit()
n=Decimal(n)
m=Decimal(m)
a=m*n
b=n-1
b=b*b
ans=(a-1+b)/(n*(a-1))
print(ans)


a=[[1,1,1],[1,1,1],[1,1,1]]
b=[]
;b.append(list(map(int,input().split())))
;b.append(list(map(int,input().split())))
;b.append(list(map(int,input().split())))
for i in range(3):
                   for j in range(3):
                                      if b[i][j]%2==1:
                                                         for k in range(3):
                                                                            if a[k][j] and k!=i:a[k][j]=0
                                                                            else:a[k][j]=1
                                                         for k in range(3):
                                                                            if a[i][k]:a[i][k]=0
                                                                            else:a[i][k]=1
for i in range(3):print(*a[i])


n,k=[int(i) for i in input().split()]
arr=list(map(int,input().split()))
x=0
y=1
e=0
while x<=y+1:
    if arr[x]<=k:
        e=e+1
        x=x+1
    if arr[-y]<=k:
        e=e+1
        y=y+1
print(e)


def inp(dtype=str, strip=True):
    s = input()
    res = [dtype(p) for p in s.split()]
    res = res[0] if len(res) == 1 and strip else res
    return res

def problem1():

    def test(cur, steps):
        if 0 < cur <= n and cur not in a:
            return steps
        else:
            return -1

    t = inp(int)
    for _ in range(t):
        n, s, k = inp(int)
        a = inp(int, strip=False)
        a = set(a)

        res = -1
        steps = 0
        while res < 0:
            res = test(s + steps, steps)
            if res < 0:
                res = test(s - steps, steps)
            steps += 1

        print(res)

def problem2():
    n = inp(int)
    res = 0
    for i in range(1, n + 1):
        res += 1 / i
    print(res)

def problem3():
    n, q = inp(int)
    conflicts = [[[0, 0, 0] for _ in range(n)] for _ in range(2)]
    state = [[0 for _ in range(n)] for _ in range(2)]
    nconflicts = 0
    for _ in range(q):
        r, c = inp(int)
        r = r - 1
        c = c - 1

        if state[r][c] == 0:
            state[r][c] = 1
            q = 1 - r
            if c - 1 >= 0 and state[q][c - 1] == 1:
                nconflicts += 1
                conflicts[r][c][-1 + 1] = 1
                conflicts[q][c - 1][1 + 1] = 1
            if state[q][c] == 1:
                nconflicts += 1
                conflicts[r][c][0 + 1] = 1
                conflicts[q][c][0 + 1] = 1
            if c + 1 < n and state[q][c + 1] == 1:
                nconflicts += 1
                conflicts[r][c][1 + 1] = 1
                conflicts[q][c + 1][-1 + 1] = 1
        else:
            state[r][c] = 0
            q = 1 - r
            if c - 1 >= 0 and state[q][c - 1] == 1:
                nconflicts -= 1
                conflicts[r][c][-1 + 1] = 0
                conflicts[q][c - 1][1 + 1] = 0
            if state[q][c] == 1:
                nconflicts -= 1
                conflicts[r][c][0 + 1] = 0
                conflicts[q][c][0 + 1] = 0
            if c + 1 < n and state[q][c + 1] == 1:
                nconflicts -= 1
                conflicts[r][c][1 + 1] = 0
                conflicts[q][c + 1][-1 + 1] = 0

        if nconflicts == 0:
            print("YES")
        else:
            print("NO")

def problem4():

    def dist(xi, yi, xj, yj):
        return abs(xi - xj)  + abs(yi - yj)

    def dist2(xi, yi, xj, yj):
        return 2 * max(abs(xi - xj), abs(yi - yj))

    x0, y0, ax, ay, bx, by = inp(int)
    xs, ys, t = inp(int)

    i = 0
    a = [(x0, y0)]
    xmin, ymin = x0, y0
    while i < 60:
        xmin = ax * xmin + bx
        ymin = ay * ymin + by
        a.append((xmin, ymin))

    i = 0
    xmin, ymin = x0, y0
    while dist2(xs, ys, xmin, ymin) > t and i < 60:
        xmin = ax * xmin + bx
        ymin = ay * ymin + by
        i += 1
    imin = i

    xmax, ymax = xmin, ymin
    while dist2(xs, ys, xmax, ymax) <= t and i < 60:
        xmax = ax * xmax + bx
        ymax = ay * ymax + by
        i += 1
    imax = i - 1

    res = 0
    for istart in range(imin, imax + 1):
        dist_start = dist(xs, ys, *a[istart])
        if dist_start > t:
            continue

        # some down and all up
        for imed in range(imin, istart + 1):
            dist_med = dist(*a[istart], *a[imed])
            if dist_start + dist_med > t:
                continue

            i = imed + 1
            while dist_start + dist_med + dist(*a[imed], *a[i]) <= t:
                i += 1

            i = max(imed, i - 1)
            res = max(res, i - imed + 1)

        # some up and all down
        for imed in range(istart, imax + 1):
            dist_med = dist(*a[istart], *a[imed])
            if dist_start + dist_med > t:
                continue

            i = imed - 1
            while dist_start + dist_med + dist(*a[imed], *a[i]) <= t:
                i -= 1

            i = min(imed, i + 1)
            res = max(res, imed - i + 1)

    print(res)

def problem5():
    pass

if __name__ == '__main__':
    # problem1()
    # problem2()
    # problem3()
    problem4()
    # problem5()


n=input()
strs=input()
if len(strs)<3:
    print(strs)
k='ogo'
if len(strs)>=3:
    while True:
        while k in strs:
            k+='go'
        k=k[:-2]
        strs=strs.replace(k,'***')
        if k=='ogo':
            print(strs)
            break
        else:
            k=='ogo'


n=input()
strs=input()
c=0
if len(strs)<3:
    print(strs)
    c=1
k='ogo'
z=0
if c!=1:
     while True:
        while k in strs:
            k+='go'
            z=1
        if z==1:
            k=k[:-2]
            z=0
        strs=strs.replace(k,'***')
        if k=='ogo':
            print(strs)
            break
        else:
            k=='ogo'


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

def cnt( x ) :
    ret = 0
    for i in range( 1, x+1 ):
        s = str(i)
        if s[0] == s[-1]:
            ret += 1
            #print(s)
    return ( ret )

def cnt2( x ):

    ret = 0
    s = str(x)
    L = len(s)

    if L >= 2 and x == 10**(L-1):
        return ( cnt2( 10**(L-1)-1 ) )

    if L <= 1:
        return ( x )
    elif L <= 2:
        while x//10 != x%10:
            x -= 1
        return ( 9 + x//10 )
    else:
        ret = int( "1" + "0"*(L-3) + "8" )
        num = list( str(x) )
        #print( num )
        if num[0] != num[-1]:
            if int(num[0]) > int( num[-1] ):
                how = int(num[-1]) + 10-int(num[0])
            else:
                how = int(num[-1]) - int(num[0])
            x -= how
        num = str(x)
        d = x % 10
        #print( 'num',num )
        #print( 'd', d )
        #print( 'num', num, 'ret before', ret )
        ret += ( int(d-1) ) * int( "9" * (L-2) ) + int( num[1:-1] ) + int(d)

    return ( ret )

#print( cnt(1024), cnt2(1024) )
#print( cnt(47), cnt2(47) )
#print( cnt(9), cnt2(9) )
#print( cnt(58), cnt2(58) )
#print( cnt(999), cnt2(999) )
#print( cnt(8987), cnt2(8987) )
#print()
#print( cnt(99999), cnt2(99999) )
#print( cnt(99899), cnt2(99899) )
#print( cnt(1000), cnt2(1000) )
#print( cnt2(1) )
#exit(0)

print( cnt2(r) - cnt(l-1) )


n,num=input(),0
for i in range(len(n)):
    if n[i]=="4":
        num+=1
    elif n[i]=="7":
        num+=1
    else:
        num+=0
print(["NO","YES"]["4" in str(num) or "7" in str(num)]


a=input().split()
if a[0]<=a[1] and a[0]<=a[2]:
    prinnt('Yes')
else:
    print('No')


def Solve(x,B):
    if(len(B)>X):
        return False
    if(x==len(L)):
        return True
    if(Form(L[x],B)):
        A=list(B)
        for e in range(len(B)):
            r=A[e]
            A[e]=L[x]
            if(Solve(x+1,tuple(A))):
                return True
            A[e]=r
        A+=[L[x]]
        if(Solve(x+1,tuple(A))):
            return True
    return False

def Form(x,B):
    for i in range(len(B)):
        for j in range(i,len(B)):
            if(B[i]+B[j]==x):
                return True
    return False

n=int(input())
L=list(map(int,input().split()))
done=False
for X in range(1,n+1):
    if(Solve(1,(L[0],))):
        print(X)
        done=True
        break
if(not done):
    print(-1)


__author__ = "runekri3"

shop_1, shop_2, between_shops = list(map(int, input().split()))

opt_1 = 2 * shop_1 + 2 * shop_2
opt_2 = shop_1 + shop_2 + between_shops

print(min(opt_1, opt_2))


def ok( s, r ):
  res = s // 50 % 475
  for i in range( 25 ):
    res = ( res * 96 + 42 ) % 475
    if 26 + res == r:
      return True
  return False

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

if any( ok( i, P ) for i in range( X, Y - 1, -50 ) ):
  exit( print( 0 ) )
else:
  ans = 1
  X += 100
  while True:
    if ok( X, P ) or ok( X - 50, P ):
      exit( print( ans ) )
  X += 100
  ans += 1


#include <bits/stdc++.h>
using namespace std;

#define boost ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main(){
    boost;
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++)
        cin >> v[i];
    sort(v.begin(), v.end());

    int t, ans = 0;
    cin >> t;

    for(int i = 0; i < n; i++){
        int k = 0;
        for(int j = i + 1; j < n; j++){
            if(v[j] - v[i] <= t) k++;
        }
        ans = max(ans, k + 1);
    }
    cout << ans << "\n";
    return 0;
}


n = int(input())
m = list(map(int, input().split()))
print(m)
t = int(input())
m.sort()
if n == 1 || len(m) == 1:
    print(1)
elif m[-1]-m[0] <= t:
    print(n)
else:
    mx = 1
    for i in range(n-1):
        ma = 1
        fr = m[i]
        for j in range(i+1, n):
            if m[j]-fr <= t:
                ma += 1
            else:
                break
        mx = max(ma, mx)
print(mx)


import collections
import sys
def recur(_list):
    idx = -1
    next_list = []
    for i,x in enumerate(_list):
        if x > 1:
            idx = i
            q = _list[idx] // 2
            r = _list[idx] % 2
            next_list += [q,r,q]
        else:
            next_list += [x]
    if idx == -1:
        return _list
    else:
        return recur(next_list)

sys.setrecursionlimit(100000)
n,s,e = list(map(int,input().split(' ')))
_list = [n]
print(collections.Counter(recur(_list[:])[s-1:e])[1])


n, l, r = map(int, input().split())
s = ''
a = []
k = n
while k > 1:
    a.append(str(k % 2))
    k = k // 2
cur = 1
k = str(k)
s = k + a[-cur] + k
cur += 1
while cur < len(a):
    s = s + a[-cur] + s
    cur += 1
s = s + a[0] + s
ans = 0
for i in range(l - 1, r):
    ans += int(s[i])
print(ans)


def construct_array(n):
  if n == 1 or n == 0:
    return [n]
  half_n = construct_array(n/2)

  return half_n + [n%2] + half_n

def count_ones(array, i, j):
  count = 0
  while(i<=j):
    count = count + array[i-1]
    i = i + 1
  return count

import sys

for line in sys.stdin:
  x = line.split(' ')
  print count_ones(construct_array(int(x[0])), int(x[1]), int(x[2]))


import sys as s

for v in s.stdin:
    if not v.isnumeric():
        s.exit(1)
    v=list(v.strip())
    pl1=pl2=0
    p=0
    ln=len(v)
    while p<len(v):
        pl1=0
        while p<ln and int(v[p])==0:
            p+=1
            pl1+=1
            if pl1>=7:
                print("YES")
                s.exit()
        pl2=0
        while p<ln and int(v[p])==1:
            p+=1
            pl2+=1
            if pl2>=7:
                print("YES")
                s.exit()
    break
print("NO")
s.exit()


def modinv(a,m):
    b=m
    u=1
    v=0
    while b:
        t=a//b
        a-=t*b
        a,b=b,a
        u-=t*v
        u,v=v,u
    u%=m
    return u
n=int(input())
MOD=998244353
dpsum=[0]*(n+1)
dp=1
for i in range(n):
    dpsum[i+1]=dp+dpsum[i]
    dp=dpsum[i]
ans=dpsum[n]
for _ in range(n):ans*=modinv(2,MOD)
ans%=MOD
print(ans)


def win(x, y, z):
    if y != z:
        return False
    if x == 'rock':
        return y == 'scissors'
    if x == 'scissors'
        return y == 'paper'
    return y == 'rock'

a = []
b = 'MFS'
for i in range(3):
    a.append(input())

for i in range(3):
    if win(a[i], a[(i+1) % 3], a[(i+2) % 3]):
        print(b[i])
else:
    print('?')


import sys
input = sys.stdin.readline

n,k=map(int,input().split())
mod=10**9+7

FACT=[1]
for i in range(1,2*10**5+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(2*10**5,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
    else:
        return 0

DP=[0]*(n+1)
DP[0]=1

for yoko in range(n):
    NDP=[0]*(n+1)
    for i in range(n+1):
        for j in range(max(1,i),n+1):
            PLUS=pow(k,i,mod)*Combi(n-i,j-i)*pow(k-1,n-j,mod)
            if i==j:
                PLUS-=pow(k-1,n,mod)

            #print(i,j,PLUS)
            NDP[j]=NDP[j]+DP[i]*PLUS

            NDP[j]%=mod

    DP=NDP
    #print(DP)

print(DP[-1])


MOD = int(1e9+7)

def mult(l, r):
	return (l*r)%MOD

def fast_exp(b, e):
	if e == 0:
		return 1
	if e%2 == 1:
		return mult(b, fast_exp(b, e-1))
	else:
		b2 = fast_exp(b, e//2)
		return mult(b2, b2)

[n, k] = [int(s) for s in input().split(" ")]
print(n, k)
fact = (n+1)*[1]
for i in range(1, n+1):
	fact[i] = mult(i, fact[i-1])

ifact = (n+1)*[1]
ifact[n] = fast_exp(fact[n], MOD-2)
for i in reversed(range(1, n)):
	ifact[i] = mult(i+1, ifact[i+1])

def binom(N, K):
	return mult(mult(fact[N], ifact[K]), ifact[N-K])

def get(i, j):
	X = i*j
	Y = (n-i)*j
	Z = (n-j)*i
	tot = X+Y+Z
	ans = 0
	if (i+j)%2 == 0:
		ans = 1
	else:
		ans = (MOD - 1)
	ans = mult(ans, binom(n, j))
	ans = mult(ans, binom(n, i))
	ans = mult(ans, fast_exp(k, n*n - tot))
	ans = mult(ans, fast_exp(k-1, tot))
	return ans

ans = 0
for i in range(0, n+1):
	for j in range(0, n+1):
		ans = (ans + get(i, j)) % MOD

print(ans)


n = int(input())
a = list(map(int, input().split()))
if a.count(1) == 0:
  print(0)
elif a.count(1) == 1:
  print(1)
else:
  ans = 1
  for i in range(1, n):
    if a[i - 1] == 1 and a[i] == 0:
      cnt = 1
    elif a[i] == 0 and cnt > 0:
      cnt += 1
    else:
      ans *= (cnt + 1)
      cnt = 0
  print(ans)


# https://codeforces.com/problemset/problem/450/B

MOD = 10**9 + 7
x, y = map(int, input().split())
n = int(input())

f = [x, y]
for i in range(2, n):
    f.append(f[-1] - f[-2])

print(f[-1] % MOD)


def main():
    (x, y) = map(int, input().split(' '))
    n = int(input())
    f = [x, y]
    for i in range(2, n):
        f.append(f[i-1] - f[i-2])
    print(f[-1] % 1000000007)

main()


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

for i in range(2, n):
    f.append(f[i - 1] - f[i - 2])
print(f[-1] % 1000000007)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt,gcd

# def time_t():
#     print("Current date and time: " , datetime.datetime.now())
#     print("Current year: ", datetime.date.today().strftime("%Y"))
#     print("Month of year: ", datetime.date.today().strftime("%B"))
#     print("Week number of the year: ", datetime.date.today().strftime("%W"))
#     print("Weekday of the week: ", datetime.date.today().strftime("%w"))
#     print("Day of year: ", datetime.date.today().strftime("%j"))
#     print("Day of the month : ", datetime.date.today().strftime("%d"))
#     print("Day of week: ", datetime.date.today().strftime("%A"))

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

def sip(): return sys.stdin.readline()

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

def mips(): return map(str,sys.stdin.readline().split())

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

def matip(n,m):
    lst=[]
    for i in range(n):
        arr = lip()
        lst.append(arr)
    return lst

def factors(n): # find the factors of a number
    return list(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))

def minJumps(arr, n): #to reach from 0 to n-1 in the array in minimum steps
    jumps = [0 for i in range(n)]
    if (n == 0) or (arr[0] == 0):
        return float('inf')
    jumps[0] = 0
    for i in range(1, n):
        jumps[i] = float('inf')
        for j in range(i):
            if (i <= j + arr[j]) and (jumps[j] != float('inf')):
                jumps[i] = min(jumps[i], jumps[j] + 1)
                break
    return jumps[n-1]

def dic(arr): # converting list into dict of count
    return Counter(arr)

def check_prime(n):
    if n<2:
        return False
    for i in range(2,int(n**(0.5))+1,2):
        if n%i==0:
            return False
    return True

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

x,y = mip()
n = ip()
if n==1:
    print(x%1000000007)
if n==2:
    print(y%1000000007)
else:
    lst = [x,y]
    for i in range(n-2):
        p = lst[-1]-lst[-2]
        lst.append(p)
    print(lst[-1]%1000000007)


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

lst = [0 for _ in range(z)]
lst[0] = x
lst[1] = y
for i in range(2, z, 1):
    lst[i] = (lst[i-1]-lst[i-2])

print(lst[z-1]%1000000007)


def b(n, k):
    v = 0
    while n:
        n, v = n // k, 10 * v + n % k
    return str(v)[::-1]
k = int(input())
for i in range(1, k):
    print(' '.join(b(i * j, k) for j in range(1, k)))


n = int(raw_input())
def rad_n(n,x):
	r =''
	while x>n:
		r=str(x%n)+r
		x = x/n
	r=str(x)+r
	return r
l = len(str(rad_n(n,(n-1)*(n-1))))
#print l
for i in xrange(1,n):
	for j in xrange(1,n):
		a = rad_n(n,i*j)
		if j==1:
			print a,
		elif j<n-1:
			print ' '*(l-len(a))+a,
		else:
			print ' '*(l-len(a))+a


#inspired by throwawayatcoder
from collections import *
import sys

# "". join(strings)

def ri():
    return int(input())

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

t=ri()
for _ in range(t):
    n,k,l=rl()
    dd=rl()
    p = list(range(k+1))+ list(range(k))[::-1]

    def get_depth(t,i):

        return dd[i] + p[t%(2*k)]

    # def getDepth2(t, i):
    #     m = t % (2 * k)
    #     tide = min(m, 2 * k - m)
    #     depth = dd[i] + tide
    #     return depth

    # for z in range(n):
    #     for T in range(2*k):
    #         print (get_depth(T,z)-getDepth2(T, z))

    def canWinFromThere(t,i):
        if i==n:
            return True
        if get_depth(t,i)>l:
            return False

        for wait in range(2*k):
            if get_depth(t+wait, i)>l:
                break

            if canWinFromThere(t+wait+1,i+1):
                return True
        return False

    for u in range(2*k):
        if canWinFromThere(u,0):
            print("Yes")
            break
    else:
        print("No")


import re, sys
from collections import Counter

def check(num, K):
    cnt = 0

    while num:
        if num%10 != 0:
            break

        cnt += 1
        num /= 10

        if cnt == K:
            return True

    return False

def main():
    N, K = map(int, raw_input().split())
    sqrt, val = 0, 1

    for i in range(K):
        val *= 10

    for i in range(val):
        if i*i < val:
            sqrt = i + 1
        else:
            break

    answer = N * val

    for i in range(1, sqrt+1):
        if val%i != 0:
            continue

        num = N * i

        if check(num, K):
            if num < answer:
                answer = num

        num = N * (val / i)

        if check(num, K):
            if num < answer:
                answer = num

    print answer

############################################################
############################################################
############################################################
if(__name__ == "__main__"):
    main()


n = int(raw_input())
s= raw_input()
li=s.split()
for i in range(len(li)):
    li[i]=int(li[i])
if 1 in li:
    print "-1"
else :
    print "1"


a1, b1 = map(int, stdin.readline().split())
a2, b2 = map(int, stdin.readline().split())
a3, b3 = map(int, stdin.readline().split())
mx, mn = max(a1, b1), min(a1, b1)
x = [0]*4
y = [0]*4
x[0], y[0] = a2+a3, max(b2, b3)
x[1], y[1] = a2+b3, max(b2, a3)
x[2], y[2] = b2+a3, max(a2, b3)
x[3], y[3] = b2+b3, max(a2, a3)

def solve():
    for i in xrange(4):
        if mx >= max(x[i], y[i]) and mn >= min(x[i], y[i]):
            print "YES"
            return
    print "NO"
    return
solve()


a=int(input())
l=[]
for i in range(a):
    l.append(int(input())
b=sum(l)
print(int(4.5*a-b)+1)


nimport sys
n = int(input())
a = list(map(int,sys.stdin.readline().strip().split()))
avg = sum(a)/n
count = 0
#print(avg)
if avg >= 4.5:
    print('0')
else:
    a.sort()
    i = 0
    while avg < 4.5:
        a[i] = 5
        count += 1
        avg = sum(a)/n
        i += 1
    print(count)


a, b = map(int, input().split())
if a == b:
    print(0)
else:
    a2 = 0
    a3 = 0
    a5 = 0
    while True:
        if a % 2 == 0:
            a = a // 2
            a2 += 1
        elif a % 3 == 0:
            a = a // 3
            a3 += 1
        elif a % 5 == 0:
            a = a // 5
            a5 += 1
        else:
            break
    b2 = 0
    b3 = 0
    b5 = 0
    while True:
        if b % 2 == 0:
            b = b // 2
            b2 += 1
        elif b % 3 == 0:
            b = b // 3
            b3 += 1
        elif b % 5 == 0:
            b = b // 5
            b5 += 1
        else:
            break
    if a != b:
        print(-1)
    else:
        print(abs(a2 - b2) + abs(a3 - b3) + abs(a5 - b5))


from math import ceil
n, m, s = map(int, raw_input().split())
arr = []
for i in xrange(min(s, n)):
    for j in xrange(min(s, m)):
        arr.append(int(ceil(1.0 * (m - j) / s) * ceil(1.0 * (n - i) / s)))
print n * m if max(arr) is 1 or max(arr) is 0 else max(arr) * arr.count(max(arr))


import string

def determinant(a11, a12, a21, a22):
	return a11 * a22 - a21 * a12

first = [int(coeff) for coeff in input().split()]
second = [int(coeff) for coeff in input().split()]

# Determine rang
rang = 2
if determinant(first[0], first[1], second[0], second[1]) == 0:
	rang = 1

# Check consistency
tilda_rang = 2
if (determinant(first[0], first[2], second[0], second[2]) == 0) and (determinant(first[1], first[2], second[1], second[2]) == 0) and (rang == 1):
	tilda_rang = 1

# Check the special case of null matrix
if rang = 1:
	if (first[0] == 0) and (first[1] == 0) and (second[0] == 0) and (second[1] == 0):
		rang = 0
		if (first[2] == 0) and (second[2] == 0):
			tilda_rang = 0
		else:
			tilda_rang = 1

if rang != tilda_rang:
	print('0')
elif rang == 2:
	print('1')
else:
	print('-1')


def plane(a, b, c):
    if a == b == 0 != c:
        return 0
    else:
        return -1

def hline(b1, c1, a2, b2, c2):
    if b1 == 0:
        if c1 == 0:
            return plane(a2, b2, c2)
        else:
            return -1
    elif a2 == 0:
        if b2 == 0 != c2:
            return 0
        elif c2 * b1 == c1 * b2:
            return -1
        else:
            return 0
    else:
        return 1

def vline(a1, c1, a2, b2, c2):
    return hline(a1, c1, b2, a2, c2)

def intersect(a1, b1, c1, a2, b2, c2):
    if a1 == b1 == 0:
        if c1 == 0:
            return plane(a2, b2, c2)
        else:
            return 0
    if a1 == 0:
        return hline(b1, c1, a2, b2, c2)
    if b1 == 0:
        return vline(a1, c1, a2, b2, c2)
    if a2 == b2 == 0:
        if c2 == 0:
            return plane(a1, b1, c1)
        else:
            return -1
    if a2 == 0:
        return hline(b2, c2, a1, b1, c1)
    if b2 == 0:
        return vline(a2, c2, a1, b1, c1)
    else:
        if a1 * b2 == a2 * b1:
            if c1 * a2 == c2 * a1:
                return -1
            else:
                return 0
        else:
            return 1

a1, b1, c1 = map(int, input().split())
a2, b2, c2 = map(int, input().split())

print(intersect(a1, b1, c1, a2, b2, c2))


C, Ha, Hb, Wa, Wb = (int(x) for x in raw_input().split())

if Ha * Wb > Hb * Wa:
    Ha, Hb, Wa, Wb = Hb, Ha, Wb, Wa

res = 0
for x in xrange(0, Wb):
    r = x * Ha + (C - x * Wa) / Wb * Hb
    res = max(r, res)

print res


C, H1, H2, W1, W2 = map(int, raw_input().split())

if H1 * W2 < H2 * W1:
    H1, H2 = H2, H1
    W1, W2 = W2, W1

r = C % W1
x0 = C // W1
best = 0
for k in xrange(min(x0 + 1, W2)):
    ans_opt = (x0 - k) * H1 + (r + k * W1) * H2 / W2
    if ans_opt < best:
        break
    ans = (x0 - k) * H1 + (r + k * W1) // W2 * H2
    best = max(ans, best)
print best


n = int(input())
i = 1
s = 0
flag = False

while (s < n):
    for j in range(1, i+1):
        s += 1

        if (s == n):
            flag = True
            val = j
            break

    i += 1

    if (flag):
        break

print(val)


from fractions import gcd

N = input()
H = dict()

def number (n,b):
    if not H.has_key((n,b)):
        if n == 1 and b == 1:       H[n,b] = 0
        elif n>b and b>0:           H[n,b] = (n-1)/b + number ((n-1)%b+1,b)
        elif b>n and n>0:           H[n,b] = (b-1)/n + number (n,(b-1)%n+1)
        else:                       H[n,b] = 10000000
    return H[n,b]

m = min (number(N,b) for b in range (N+1))
print m
#print [b for b in range (N+1) if number(N,b)==m]
# for b in range (N+1): print number(N,b),b,gcd(N,b)


from collections import deque

class CodeforcesTask134BSolution:
    def __init__(self):
        self.result = ''
        self.n = 0

    def read_input(self):
        self.n = int(input())

    def process_task(self):
        go = deque([(1, 1, 0)])
        while go:
            exploring = go.popleft()
            if exploring[0] == self.n or exploring[1] == self.n:
                self.result = str(exploring[2])
                break
            else:
                go.append((exploring[0] + exploring[1], exploring[1], exploring[2] + 1))
                go.append((exploring[0], exploring[1] + exploring[0], exploring[2] + 1))

    def get_result(self):
        return self.result

if __name__ == "__main__":
    Solution = CodeforcesTask134BSolution()
    Solution.read_input()
    Solution.process_task()
    print(Solution.get_result())


n = int(input())
c = n - 10
elif c == 10:
    print(15)
    exit()
elif c > 11 or c <= 0:
    print(0)
else:
    print(4)


n = input()
print "codeforces" + "s" * (n - 1)


k = int(input())
myStr = 'codeforce'+ 's'*k
print myStr


n, k = map(int, input().split())
s = list(input())
ans = False
for i in range(len(s) - k):
    flag = True
    for j in range(i, i + k):
        if (s[j] == 'Y'):
            flag = False
            break
    if ((i + k) < len(s)) and s[i + k] == 'N': flag = False
    if (i > 0) and (s[i - 1] == 'N'): flag = False
   # print(i, flag)
    if (flag):
        ans = True
        break
maximum = 0
i = 0
while (i < len(s)):
    now = 0
    while (s[i] != 'N'):
        i += 1
        if (i >= len(s)):
            break
    if (i >= len(s)): break
    while (i < len(s)) and (s[i] == 'N'):
        i += 1
        now += 1
    maximum = max(maximum, now)
if ans and (maximum <= k):
    print('YES')
else: print('NO')


text = input()
bracket = False
bracket_word_count = 0
max_length = 0
bracket_s = ""
non_bracket_s = ""
for ch in text:
	if bracket:
		if ch == ')':
			bracket = False
			bracket_word_count += sum(1 for s in bracket_s.split('_') if s)
			bracket_s = ""
		else:
			bracket_s += ch
	else:
		if ch == '(':
			bracket = True
			max_length = max(max_length, max(len(s) for s in non_bracket_s.split('_')))
			non_bracket_s = ""
		else:
			non_bracket_s += ch
max_length = max(max_length, max(len(s) for s in non_bracket_s.split('_'))
bracket_word_count += sum(1 for s in bracket_s.split('_') if s)
print('{} {}'.format(max_length, bracket_word_count))


n,k=map(int,input().split())
s=[1]
for i in range(n):
  s.append((max(s)+1))
  s+=s[:-1]
print(s[k-1])


a=[int(i) for i in input().split()]
b=[1]
c=[]
for i in range(a[0]):
    c=[i+2]
    b=b+c+b
    if len(b)>=a[1]:
        print(b[a[1]-1])
        break


n,k=map(int,input().split())
a=[1]
b=[]
for i in range(2,n+1):
	b=a+[i]
	a=b+a
print(a[k-1])


n,k=map(int,input().split())
a=[1]
for i in range(n):
    b=a[:]
    a.append(max(a)+1)
    a.extend(b)
print(a[k-1])


string = input()
numbers = string.split()
a = int(numbers[0])
b = int(numbers[1])
sequence = []
for x in range(a):
    sequence += [x + 1] + sequence
print(sequence[b - 1])


n, k = [int(x) for x in input().split()]
start = [1]
i = 0
digit = 2
while i != n-1 and k > len(start):
    start = start + [digit] + start
    digit = digit + 1
    i += 1
print(start[k-1])


n,k=map(int,input().split())
a,b=map(int,input().split())
r=[]
i=1
p=n*k
while i<=n*k:
    r.append(i)
    i+=k
s=1+a
c=[]
for i in r:
    c.append((i-b)%p)
    c.append((i+b)%p)
mx=0
mn=1111111111111111111111111
for i in c:
    dp=i-s
    dp%=p
    if not dp:ns=1
    else:
        j=1
        while (j*p)%dp:j+=1
        ns=(j*p)//dp
    mx=max(mx,ns)
    mn=min(mn,ns)
print(mn,mx)


def cnt_flowers(r, g, b):
    return r // 3 + g // 3 + b // 3

def main():
    r, g, b = map(int, input().split())
    n = min(r, g, b) + 1
    ans = [0] * n
    for i in range(0, n):
        rr = r - i
        gg = g - i
        bb = b - i
        ans[i] = (cnt_flowers(rr, gg, bb) + i)
    print(max(ans))

main()


x, n = map(int, input().split())
MOD = 10**9 + 7
c = 4*x
if c == 0:
    print(0)
elif n == 0:
    ans = 2 * x
else:
    ans = (((c - 2) * pow(2, n -1, MOD) + 1) + MOD) % MOD
print(ans)


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

h, m = map (float, raw_input ().split (':'))
h += m / 60.
if h not in [12, 0]:
	x = 30. * h
else:
	x = 0
if m not in [12, 0]:
	y = 6. * m
else:
	y = 0

print x, y


n,k=[int(i) for i in input().split()]
l=[]
for i in range(n):
    l.append(i+1)

import itertools
l_C_k=list(itertools.combinations(l,k))

l_xor_sum=[]
for i in l_C_k:
    xor_sum=i[0]^i[1]
    for j in i[2:]:
        xor_sum=xor_sum^j
    l_xor_sum.append(xor_sum)

print(max(l_xor_sum))


import sys
from math import *

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

n = mint()
p = [0]*n
x = dict()
y = dict()
for i in range(n):
	a = tuple(mints())
	p[i] = a
	if a[0] in x:
		x[a[0]].append(i)
	else:
		x[a[0]] = [i]
	if a[1] in y:
		y[a[1]].append(i)
	else:
		y[a[1]] = [i]

del(pow)
r = 1
q = [0]*n
w = [True]*n
ql = 0
qr = 0
for i in range(n):
	if w[i]:
		w[i] = False
		q[qr] = i
		qr += 1
		qlb = ql
		e = 0
		xs = set()
		ys = set()
		while ql < qr:
			v = q[ql]
			ql += 1
			a = p[v]
			xs.add(a[0])
			ys.add(a[1])
			for u in x[a[0]]:
				e += 1
				if w[u]:
					w[u] = False
					q[qr] = u
					qr += 1
			for u in y[a[1]]:
				e += 1
				if w[u]:
					w[u] = False
					q[qr] = u
					qr += 1
		vc = ql-qlb
		#print(vc,e,vc*3-1)
		if vc*3-1 == e:
			r = (r*(pow(2,vc+1,1000000007)-1))%1000000007
		else:
			r = (r*(pow(2,len(xs)+len(ys),1000000007)))%1000000007
print(r)


n = int(input())
disjointSet = [-1] * n
def root(x, level=200):
    if disjointSet[x] < 0:
        return x
    if level < 1:
        while disjointSet[x] >= 0:
            x = disjointSet[x]
        return x
    disjointSet[x] = root(disjointSet[x], level - 1)
    return disjointSet[x]

def join(x, y):
    r1, r2 = root(x), root(y)
    if r1 == r2:
        return
    disjointSet[r2] = r1

points = []
vertPoints = {}
horizPoints = {}
for i in range(n):
    a, b = map(int, input().split())
    points.append((a, b))
    if a in vertPoints:
        join(i, vertPoints[a])
    else:
        vertPoints[a] = i
    if b in horizPoints:
        join(i, horizPoints[b])
    else:
        horizPoints[b] = i

sets = {}
for i in range(n):
    r = root(i)
    if r in sets:
        sets[r].append(points[i])
    else:
        sets[r] = [points[i]]

ans = 1
for i in sets:
    s = sets[i]
    horiz = [x for x,y in s]
    vert = [y for x,y in s]
    tmp = len(set(horiz)) + len(set(vert))
    if tmp <= len(s):
        ans *= 2 ** tmp
    else:
        ans *= 2 ** tmp - 1
    ans %= 10 ** 9 + 7

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


key=input()
str=input()
a=['q','w','e','r','t','y','u','i','o','p']
b=['a','s','d','f','g','h','j','k','l',';']
c=['z','x','c','v','b','n','m',',','.','/']
if key=='R':
for i in str:
    if i in a:
        print(a[a.index(i)-1],end='')
    elif i in b:
        print(b[b.index(i)-1],end='')
    elif i in c:
        print(c[c.index(i)-1],end='')
    else:
        print(i,end='')
else:
    for i in str:
    if i in a:
        print(a[a.index(i)+1],end='')
    elif i in b:
        print(b[b.index(i)+1],end='')
    elif i in c:
        print(c[c.index(i)+1],end='')
    else:
        print(i,end='')


import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

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

if a<b: a,b=b,a

if b==0:
    # 1 01 001 0001 ... is optimal
    print(n*a)
else:
    # pascal's triangle thing
    pascal=[[1]*20005]
    for i in range(20004):
        newrow=[1]
        for j in range(1,20005):
            newrow.append(newrow[-1]+pascal[-1][j])
            if newrow[-1]>n: break
        pascal.append(newrow)
    def getcom(a,b):
        # return a+b choose b
        # if larger than n, return infinite
        if len(pascal[a])>b: return pascal[a][b]
        if b==0: return 1
        if b==1: return a
        return 100000005

    # start with the null node (prefix cost 0)
    # can split a node into two other nodes with added cost c+a+b
    # new nodes have prefix costs c+a, c+b
    # want n-1 splits in total
    n-=1    # now represents number of splits needed

    # binary search the last cost added
    lo=0
    hi=a*int((n**0.5)*3+3)

    while 1:
        mid=(lo+hi)//2
        mid=11
        # count stuff
        c0=0    # < mid
        c1=0    # = mid
        for i in range(mid//a+1):
            j=(mid-i*a)//b
            if (mid-i*a)%b!=0:
                # c0 += iC0 + (i+1)C1 + (i+2)C2 + ... + (i+j)Cj
                for k in range(j+1):
                    print(mid,i,k)
                    c0+=getcom(i,k)
                    if c0>n: break
            else:
                for k in range(j):
                    print(mid,i,k)
                    c0+=getcom(i,k)
                    if c0>n: break
                print(mid,i,j,"c1")
                c1+=getcom(i,j)
        print(mid,"is",c0,c1)
        if n<c0:
            hi=mid-1
        elif c0+c1<n:
            lo=mid+1
        else:
            # mid is correct cutoff
            lowcost=0   # sum of all cost, where cost < mid
            for i in range(mid//a+1):
                j=(mid-i*a)//b
                if (mid-i*a)%b!=0:
                    for k in range(j+1):
                        lowcost+=getcom(i,k)*(i*a+k*b)
                else:
                    for k in range(j):
                        lowcost+=getcom(i,k)*(i*a+k*b)
            temp=lowcost+(n-c0)*mid
            print(temp+n*(a+b))
            break


n=int(input())
numbers=[1,1,2,1,2,3,1,2,3,4,1,2,3,4,5,1,2,3,4,5,6,1,2,3,4,5,6,7]
pattern=[1,2,3,4,5,6,7]
count=8
while n>len(numbers):
    pattern.append(count)
    numbers.extend(pattern)
    count+=1
print(numbers[n-1])


while True:
    n = int(input())
    if n in [1,60]:
        break
if (n%2 ==0):
    print(n)
else:
    print(n-1)


x=int(input())
y=input()
a=[]
d1=0
d2=[]
m=0
for c in x:
    x1=0
    x2=0
    s=c=="_" or c==")" or c=="("
    if s and isalpha(x[x.index(c)+1]):
        a.append(x.index(c))

    if c==")" and x[a[len(a)-1]]=="(":
        x1=a.[len(a)-1]+1
        x2=index(c)
        b=[]
        for i in x[x1:x2]:
            if i=="_"  and isalpha(x[x.index(i)+1]):
               d1+=1
        for i in range((len(a)-1)):
            y1=a[i+1]-a[i]-1
            d2.append(y1)
        a=[]
print(max(d2),d1)


def kthDivisor(n, k):
    divisors = []
    i = 1
    while i * i < n:
        if n % i == 0:
            divisors.append(i)
        i += 1
    if i * i > n:
        i -= 1
    while i > 0:
        if n % i == 0:
            divisors.append(n/i )
        i -= 1
    if len(divisors) < k:
        return -1
    return int(divisors[k - 1])

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


from math import ceil
a,b,c = map(int,input().split())
t = max(a,b,c)
if t == c:
	print(32+3*ceil((c-2)/2))
elif t == b:
	print(31+3*ceil((b-2)/2))
elif t == a:
	print(30+3*ceil((a-2)/2))


n = int(input())
s = 0
for i in range(n):
    if (i + 1) % 2520 == 0:
        s += 1
print (s)


l=""
k=int(input())
index=0
counter=1
while True:
    for i in str(counter):
        if index<=9999:
            l+=i
            index+=1
        counter+=1
        if index>9999:
            break
if 1<=k<=10000:
    print(l[k-1])


l=''
k=int(input())
index=0
counter=1

for i in range(1,k+1):
        if index<=k-1:
          l+=str(i)
          index+=1
        else:
          break

if 1<=k <=10**12:
     print(l[k-1])


n = int(input())
a = list(map(int, input().split()))
idx = []
for i in range(1, n // 2 + 1):
    idx.append(2 * i + 1)
a.sort()
s1 = 0
s2 = 0
for i in range(0, n // 2):
    s1 += abs(a[i] - 2 * i -a 1)
    s2 += abs(a[i] - 2 * i - 2)
print(min(s1, s2))


mod=int(10e8+7)
a,b,n,x=map(int,input().split())
exp=a
ans=1
while n>0:
    if(n%2==1):
        ans=ans*exp
    exp=exp**2
    n//=2

if ans!=1:
    res=((ans-1)//(a-1))%mod
    ans=ans%mod
    print(((ans*x)%mod+(res*b)%mod)%mod)
else:
    print(((ans*x)%mod+((n+1)*b)%mod)%mod)


n, k =map(int, input().split())
for i in range(0 , k):
    last_numeral = 10*(1-(n/10-truncate(n/10)))
    if last_numeral = 0:
        n=n/10
    else
        n=n-1
    print(n)


def check(4,512):
    for i in range(x):
        if number%10 == 0:
            number = number / 10
            print(number)
        else:
            number = number -1
            print(number)

check()


import collections
n,s,e = map(int,raw_input().split())
a =  bin(n)[2:]
#print a
b = str(a[0])
for i in xrange(1,len(a)):
	b = str(b)+a[i]+str(b)
print collections.Counter(b[s-1:e])['1']


num = int(input())

count = 0
while num != 0:
    lst = [int(i) for i in str(num)]
    num -= max(lst)
    count += 1

return count