import sys,heapq

#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, plus a long series of 0's

    print((n-1)*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

    remain=n-1

    ans=0

    possible=[[a+b,1]]    # [c,count]

    while 1:

        # cost u, v leaves

        u,v=heapq.heappop(possible)

        while possible and possible[0][0]==u:

            v+=possible[0][1]

            heapq.heappop(possible)

        if remain<=v:

            ans+=u*remain

            break

        ans+=u*v

        remain-=v

        heapq.heappush(possible,[u+a,v])

        heapq.heappush(possible,[u+b,v])

    print(ans)

# Made By Mostafa_Khaled


MAX = 101
NINF = -22222222222
base = [-1]*MAX
dp = [ [ base[:] for i in range(MAX)] for j in range(MAX)]
s1 = ""
s2 = ""
s3 = ""
rev_s3 = ""
l1 = ""
l2 = ""
l3 = ""

def foo(i, j, k):
	if k == l3 :
		return "", NINF
	if i == l1:
		return "", 0
	if j == l2:
		return "", 0
	if dp[i][j][k] != -1:
		return dp[i][j][k]
	ans1, len1 = foo( i + 1, j, k )
	ans2, len2 = foo( i , j + 1, k )
	len3 = NINF
	ans3 = ""
	if s1[i] == s2[j]:
		if s1[i] == s3[k]:
			ans3, len3 = foo(i+1, j + 1, k+1 )
			ans3 += s1[i]
			len3 += 1
		else:
			if s1[i] == s3[0]:
				ans3, len3 = foo(i+1, j + 1, 1 )
			else:
				ans3, len3 = foo(i+1, j + 1, 0 )
			ans3 += s1[i]
			len3 += 1

	if rev_s3 in ans1:
		len1 = NINF
	if rev_s3 in ans2:
		len2 = NINF
	if rev_s3 in ans3:
		len3 = NINF

	if len1 > len2:
		if len1 > len3:
			dp[i][j][k] = ans1, len1
		else:
			dp[i][j][k] = ans3, len3
	else:
		if len2 > len3:
			dp[i][j][k] = ans2, len2

		else:
			dp[i][j][k] = ans3, len3
	return dp[i][j][k]

s1 = raw_input()
s2 = raw_input()
s3 = raw_input()
rev_s3 = s3[::-1]
l1 = len(s1)
l2 = len(s2)
l3 = len(s3)

ans = foo(0,0,0)
if ans[1] <= 0 :
	print(0)
else:
	print(ans[0][::-1]	)


mod = 1000000007
def sum(x,y,k,add) :
    if k<add:
    	return 0
    up=x+add
    if up>k:
    	up=k
    add=add+1
    return y*(((add+up)*(up-add+1)//2)%mod)%mod
def solve(x,y,k,add=0) :
    if x==0 or y==0:
    	return 0
    if x>y:
    	x,y=y,x
    pw = 1
    while (pw*2)<=y:
    	pw*=2
    if pw<=x:
    	return (sum(pw,pw,k,add)+sum(pw,x+y-pw-pw,k,add+pw)+solve(x-pw,y-pw,k,add))%mod
    else:
    	return (sum(pw,x,k,add)+solve(x,y-pw,k,add+pw))%mod
q=input()
for i in range(0,q):
    x1,y1,x2,y2,k=map(int,raw_input().split())
    ans=(solve(x2, y2, k)-solve(x1 - 1, y2, k)-solve(x2, y1 - 1, k)+solve(x1-1,y1-1,k))%mod
    if ans<0:
    	ans+=mod
    print ans


n=int(input())
s=[c=='1' for c in input()]
m=len(s)
z=[[0,0]]
for c in s:
 ind = z[-1][c]
 z[-1][c] = len(z)
 z.append(z[ind][:])
assert(len(z) == m+1)
z[m][0] = z[m][1] = m # make it sticky

# how many things match directly
dp = [0 for _ in range(m+1)]
dp[0] = 1
for i in range(n):
 ndp = [0 for _ in range(m+1)]
 for i in range(m+1):
  ndp[z[i][0]] += dp[i]
  ndp[z[i][1]] += dp[i]
 dp = ndp
res = dp[m]

for k in range(1, m):
 s0 = 0
 for c in s[-k:]:
  s0 = z[s0][c]
 dp = [0 for _ in range(m+1)]
 dp[s0] = 1
 for i in range(n - k):
  ndp = [0 for _ in range(m+1)]
  for i in range(m+1):
   ndp[z[i][0]] += dp[i]
   ndp[z[i][1]] += dp[i]
  dp = ndp
 for s1 in range(m): # skip m
  v = dp[s1]
  for c in s[-k:]:
   if s1 == m: v = 0
   s1 = z[s1][c]
  if s1 == m: res += v
print(res)


from collections import defaultdict
letters = 'ACGT'
P = 10**9 + 9
n,m = map(int,raw_input().split())
v = [raw_input() for _ in xrange(m)]
d = {(0,''):0}
di = {0:(0,'')}
c = 1
a = defaultdict(dict)
t = set(v)
def f(k,s):
    global c
    if (k,s) not in d:
        d[k,s]=c
        di[c]=k,s
        c+=1
    return d[k,s]
def add(f,l,t):
    global a
    if l not in a[f] or di[a[f][l]][0]<di[t][0]:
        #print di[f], '->', di[t]
        a[f][l]=t
for s in v:
    for j in xrange(len(s)):
        for k in xrange(j+1):
            if j==len(s)-1: add(f(k,s[:j]),s[j],f(len(s),s[:j+1]))
            else: add(f(k,s[:j]),s[j],f(k,s[:j+1]))

for p,s in d.keys():
    for x in letters:
        z = s+x
        fm = False
        for j in v:
            if z.endswith(j) and p+len(j)>=len(z):
                fm = True
                break
        for j in xrange(len(z)):
            f = p-j,z[j:]
            if fm: f = len(z[j:]),z[j:]
            if f in d:
                add(d[p,s],x,d[f])
                break
#print d
#print a
d0,v0 = d,v
d = defaultdict(int)
d[0] = 1
for i in xrange(n):
    dn = defaultdict(int)
    for j in xrange(c):
        for x,v in a[j].iteritems():
            dn[v]+=d[j]
            dn[v]%=P
    #print ' '.join('%s=%d'%(di[k],v) for k,v in dn.iteritems() if v)
    d = dn

#print [di[k] for k,v in d.iteritems() if di[k][0]==len(di[k][1])]
print sum(v for k,v in d.iteritems() if di[k][0]==len(di[k][1]))%P


from sys import exit

n = int(input())
P = []

if n >= 38:
    print("0")
    exit()

for i in range(n):
    tmp = input().split()
    tmp = [int(k) for k in tmp]
    P.append(tuple(tmp))

isGood = [True for i in range(n)]
for i in range(n):
    for j in range(n):
        for k in range(j):
            dp = 0
            for d in range(5):
                dp += (P[j][d] - P[i][d])*(P[k][d] - P[i][d])
            if dp > 0:
                isGood[i] = False

print(isGood.count(True))
for i in range(n):
    if isGood[i]:
        print(i + 1)


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

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


def Solve(x,B):
    if((X,x,B) in Mem):
        return Mem[(X,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(sorted(A)))):
                Mem[(X,x,B)]=True
                return True
            A[e]=r
        A+=[L[x]]
        if(Solve(x+1,tuple(sorted(A)))):
            Mem[(X,x,B)]=True
            return True
    Mem[(X,x,B)]=False
    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
Mem={}
for X in range(1,n+1):
    if(Solve(1,(L[0],))):
        print(X)
        done=True
        break
if(not done):
    print(-1)


from math import gcd
def powmod(a,b,m):
 a%=m
 r=1
 while b:
  if b&1:r=r*a%m
  a=a*a%m
  b>>=1
 return r

def f(n):
 r=[]
 if (n&1)==0:
  e=0
  while (n&1)==0:n>>=1;e+=1
  yield (2,e)
 p=3
 while n>1:
  if p*p>n:p=n
  if n%p:
   p+=2
   continue
  e=1;n//=p
  while n%p==0:n//=p;e+=1
  yield (p,e)
  p+=2
 return r
m,x=map(int,input().split())
p=2
r=[(1,1)]
for p,e in f(m):
 assert e>=1
 ord=p-1
 assert powmod(x,ord,p)==1
 for pi,ei in f(p-1):
  while ord % pi == 0 and powmod(x,ord//pi,p)==1: ord//=pi
 ords=[(1,1),(ord,p-1)]
 q=p
 for v in range(2,e+1):
  q*=p
  if powmod(x,ord,q)!=1:ord*=p
  assert powmod(x,ord,q)==1
  ords.append((ord,q//p*(p-1)))
 r=[(a//gcd(a,c)*c,b*d) for a,b in r for c,d in ords]
print(sum(y//x for x,y in r))


import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

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

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

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

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

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

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

class FFT:
    def __init__(self, MOD=998244353):
        FFT.MOD = MOD
        g = self.primitive_root_constexpr()
        ig = pow(g, FFT.MOD - 2, FFT.MOD)
        FFT.W = [pow(g, (FFT.MOD - 1) >> i, FFT.MOD) for i in range(30)]
        FFT.iW = [pow(ig, (FFT.MOD - 1) >> i, FFT.MOD) for i in range(30)]

    def primitive_root_constexpr(self):
        if FFT.MOD == 998244353:
            return 3
        elif FFT.MOD == 200003:
            return 2
        elif FFT.MOD == 167772161:
            return 3
        elif FFT.MOD == 469762049:
            return 3
        elif FFT.MOD == 754974721:
            return 11
        divs = [0] * 20
        divs[0] = 2
        cnt = 1
        x = (FFT.MOD - 1) // 2
        while x % 2 == 0:
            x //= 2
        i = 3
        while i * i <= x:
            if x % i == 0:
                divs[cnt] = i
                cnt += 1
                while x % i == 0:
                    x //= i
            i += 2
        if x > 1:
            divs[cnt] = x
            cnt += 1
        g = 2
        while 1:
            ok = True
            for i in range(cnt):
                if pow(g, (FFT.MOD - 1) // divs[i], FFT.MOD) == 1:
                    ok = False
                    break
            if ok:
                return g
            g += 1

    def fft(self, k, f):
        for l in range(k, 0, -1):
            d = 1 << l - 1
            U = [1]
            for i in range(d):
                U.append(U[-1] * FFT.W[l] % FFT.MOD)

            for i in range(1 << k - l):
                for j in range(d):
                    s = i * 2 * d + j
                    f[s], f[s + d] = (f[s] + f[s + d]) % FFT.MOD, U[j] * (f[s] - f[s + d]) % FFT.MOD

    def ifft(self, k, f):
        for l in range(1, k + 1):
            d = 1 << l - 1
            for i in range(1 << k - l):
                u = 1
                for j in range(i * 2 * d, (i * 2 + 1) * d):
                    f[j+d] *= u
                    f[j], f[j + d] = (f[j] + f[j + d]) % FFT.MOD, (f[j] - f[j + d]) % FFT.MOD
                    u = u * FFT.iW[l] % FFT.MOD

    def convolve(self, A, B):
        n0 = len(A) + len(B) - 1
        k = (n0).bit_length()
        n = 1 << k
        A += [0] * (n - len(A))
        B += [0] * (n - len(B))
        self.fft(k, A)
        self.fft(k, B)
        A = [a * b % FFT.MOD for a, b in zip(A, B)]
        self.ifft(k, A)
        inv = pow(n, FFT.MOD - 2, FFT.MOD)
        A = [a * inv % FFT.MOD for a in A]
        del A[n0:]
        return A

MOD = 998244353
def solve():
    n, k, f = map(int, input().split())
    if f > 2 * k:
        print(0)
        return

    fft = FFT()
    A = [1] * (k + 1)
    for i in range(n):
        B = fft.convolve(A[:], A[:])
        if i == n - 1:
            break
        tot = sum(B[k+1:]) % MOD
        A = [0] * (k + 1)
        cum = 0
        for i in range(k, -1, -1):
            A[i] += tot + B[i] * (k + 1 - i)
            A[i] %= MOD
            tot += B[i]
            if tot >= 0:
                tot -= MOD
    print(B[f])

for _ in range(1):
    solve()


mod = int(1e9 + 7)
n, m = map(int, input().split())
f = [ [0 for i in range(60)] for j in range(60) ]
g = [ [0 for i in range(60)] for j in range(60) ]
s = [ [0 for i in range(60)] for j in range(60) ]
inv = [ 1 ]
f[0][0] = s[0][0] = 1

def pow(x, exp) :
    res = 1
    for i in range(0, 31) :
        if exp & 1 : res = res * x % mod
        exp >>= 1
        if exp == 0 : break
        x = x * x % mod
    return res

for i in range(1, n + 1) :
    inv.append( pow(i, mod - 2) )

for node in range(1, n + 1) :
    for cut in range(1, n + 1) :
        tmp = 0
        for ln in range(node) :
            for lc in range(cut - 1, n + 1) :
                if f[ln][lc] == 0 : continue
                if lc == cut - 1 :
                    tmp = ( tmp + f[ln][lc] * s[node - ln - 1][cut - 1] ) % mod
                else :
                    tmp = ( tmp + f[ln][lc] * f[node - ln - 1][cut - 1] ) % mod
        cnt = 1
        if tmp != 0 :
            cn, cc = 0, 0
            for i in range(1, n + 1) :
                cn += node
                cc += cut
                cnt = cnt * (tmp + i - 1) % mod * inv[i] % mod
                if cn > n or cc > n : break
                for j in range(n - cn, -1, -1) :
                    for k in range(n - cc, -1, -1) :
                        if f[j][k] == 0 : continue
                        g[j + cn][k + cc] += f[j][k] * cnt
                        g[j + cn][k + cc] %= mod
            for i in range(n + 1) :
                for j in range(n + 1) :
                    f[i][j] = (f[i][j] + g[i][j]) % mod
                    g[i][j] = 0

    for cut in range(n, -1, -1) :
        s[node][cut] = ( s[node][cut + 1] + f[node][cut] ) % mod
print(f[n][m - 1])


import sys
#sys.stdin = open('game.in', 'r')
#sys.stdout = open('game.out', 'w')

line = raw_input().split(' ')
A, B, N = int(line[0]), int(line[1]), int(line[2])
N -= 1

nl = 0
list = [0]*100
while 1 == 1:
	curb = nl + 1
	le, ri = 1, N
	while le < ri:
		cura = (le+ri+1)//2
		if (cura**curb <=N):
			le = cura
		else:
			ri = cura-1;
	if (le > 1):
		nl += 1
		list[nl] = le
	else:
		break

win = [[-1]]
cb = nl
for i in range(1, 50000):
	win.append([])
	while (cb > 0) and (i > list[cb]):
		cb -= 1
	for j in range(cb+5):
		win[i].append(-1);

def get(win, list, nl, a, b, n):
	if (a == 1) and (b > nl):
		return 3
	if (a > list[b]):
		return 1
	if (b == 1) and (a > list[2]):
		if ((a&1) != (n&1)):
			return 1
		else:
			return 2
	if (win[a][b] != -1):
		return win[a][b]
	x, y = get(win, list, nl, a+1, b, n), get(win, list, nl, a, b+1, n)
	if (x == 2) or (y == 2):
		win[a][b] = 1
		return 1
	if (x == 3) or (y == 3):
		win[a][b] = 3
		return 3
	win[a][b] = 2
	return 2

j = nl
while j > 0:
	if j == 1:
		i = list[2]
	else:
		i = list[j]
	while i > 0:
		get(win, list, nl, i, j, N)
		i -= 1
	j -= 1

ret = get(win, list, nl, A, B, N)
if (ret == 1):
	print "Masha"
if (ret == 2):
	print "Stas"
if (ret == 3):
	print "Missing"


import sys
#sys.stdin = open('game.in', 'r')
#sys.stdout = open('game.out', 'w')

line = raw_input().split(' ')
A, B, N = int(line[0]), int(line[1]), int(line[2])
N -= 1

nl = 0
list = [0]*100
while 1 == 1:
	curb = nl + 1
	le, ri = 1, N
	while le < ri:
		cura = (le+ri+1)//2
		if (cura**curb <=N):
			le = cura
		else:
			ri = cura-1;
	if (le > 1):
		nl += 1
		list[nl] = le
	else:
		break

win = []
for i in range(50000):
	win.append([-1])
	for j in range(50):
		win[i].append(-1);

def get(win, list, nl, a, b, n):
	if (a == 1) and (b > nl):
		return 3
	if (a > list[b]):
		return 1
	if (b == 1) and (a > list[2]):
		if ((a&1) != (n&1)):
			return 1
		else:
			return 2
	if (win[a][b] != -1):
		return win[a][b]
	x, y = get(win, list, nl, a+1, b, n), get(win, list, nl, a, b+1, n)
	if (x == 2) or (y == 2):
		win[a][b] = 1
		return 1
	if (x == 3) or (y == 3):
		win[a][b] = 3
		return 3
	win[a][b] = 2
	return 2

j = nl
while j > 0:
	if j == 1:
		i = list[2]
	else:
		i = list[j]
	while i > 0:
		get(win, list, nl, i, j, N)
		i -= 1
	j -= 1

ret = get(win, list, nl, A, B, N)
if (ret == 1):
	print "Masha"
if (ret == 2):
	print "Stas"
if (ret == 3):
	print "Missing"


mod = 1000000007
def power(a, p):
    res = 1
    while p > 0:
        if p % 2 == 1:
            res = (res * a) % mod
        a = (a * a) % mod
        p //= 2
    return res
n, m = map(int, input().split())
n += 1
res = (power(n * 2, m - 1)) * (n - m) * 2
print((res % mod))


mod = 10 ** 9 + 7
n , m = map(int , raw_input().split())
print (pow(2 * (n + 1) , m - 1 , mod) * (n + 1 - m) * 2) % mod


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

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

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

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

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

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

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

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

PreProcess(n)

q = nCr(n, w)
p = 0

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

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

print ans


def build_fac():
   global mod
   fac = [1] * int(3e5 + 1)
   for i in range(1, int(3e5)):
      fac[i] = i*fac[i-1] % mod
   return fac

def inv(x):
   global mod
   return pow(x, mod-2, mod)

def ncr(n, r):
   global fac
   if n < 0 or n < r: return 0
   return fac[n]*inv(fac[r])*inv(fac[n-r]) % mod

def cf(f, w, h):
   global mod
   if w == 0: return 1
   rs = 0
   for k in range(1, min(w//(h+1),f+1)+1):
      rs += ncr(f+1, k) * ncr(w-k*h-1, k-1) % mod
      rs %= mod
   return rs

f, w, h = map(int,input().split(' '))
mod = int(1e9 + 7)

fac = build_fac()
cnt = cf(f, w, h)
rs = cnt*inv(ncr(f+w, w)) % mod

print(rs)


a,b= map(int,input().split())
ans,l,n=0,1,a+b
while l<=n:
    g= n//l
    if a<g or b<g:
        l= (n//g) +1
        continue
    r= n//g
    al = (a+g)//(g+1)
    ah = a//g
    bl=(b+g)//(g+1)
    bh = b//g
    if (al <= ah and bl <= bh):
        ans += max(0,min(r,ah+bh)- max(l,al +bl)+1)
    l=r+1
print(ans)


import math
a,b= map(int,input().split())
n=a+b
ans,l=0,1
while l<=n:
    g= n//l
    if a<g or b<g:
        l= (n//g) +1
        continue
    r= n//g
    a_low = (a+g)//(g+1)
    a_high = a//g
    b_low=(b+g)//(g+1)
    b_high = b//g
    if (a_low <= a_high and b_low <= b_high):
        ans += max(0,min(r,a_high+b_high)- max(l,a_low +b_low)+1)

    l=r+1
print(ans)


import sys
debug = False
def solve(a, b, c, d):
    for i in c:
        if i not in a:
            return 0
    #w=[a,b]
    #q=[c,d]
    #[q,p] in w
    #p?
    ind1 = 0
    ind2 = 0
    cnt1 = 1
    cnt2 = 0
    phases = []
    phases2 = []

    while True:
        if a[ind1] == c[ind2]:
            ind2 += 1
            if ind2 == len(c):
                #word finished!
                cnt2 += 1
                ind2 = 0
                #check phase
                if ind1 in phases:
                    #period!
                    cnt1_, cnt2_ = phases2[phases.index(ind1)]
                    step1 = cnt1 - cnt1_
                    step2 = cnt2 - cnt2_
                    cnt = (b-cnt1)/step1
                    cnt1 += step1 * cnt
                    cnt2 += step2 * cnt
                    phases = []
                    phases2 = []
                #save phase
                phases.append(ind1)
                phases2.append([cnt1, cnt2])

        ind1 += 1
        if ind1 == len(a):
            cnt1 += 1
            ind1 = 0
            if cnt1 > b:
                return cnt2 / d
    #answ
    val2 = phases2[-1]
    val1 = phases2[phases.index(ind1)]

    step1 = val2[0] - val1[0]
    step2 = val2[1] - val1[1]

    if debug:
        print str(val1[0]) + " -- > " + str(val1[1])
        print str(val2[0]) + " -- > " + str(val2[1])

    res = step2 * b / (step1 * d)
    res = (b - val2[0]) * step2 / (step1 * d) + val2[1]
    if res < 0:
        return 0
    else:
        return res

if not debug:
    b, d = map(int, sys.stdin.readline().split())

    a = sys.stdin.readline().split()[0]
    c = sys.stdin.readline().split()[0]
    print str(solve(a, b, c, d))
else:
    vals = []
    vals.append([841, 7, 'qjqhrksmvedtqldrqgchhsofokfcovut' ,'qhtmothoulodshrfejterjlguvooccsvqrrdfqfvkqhtecuhhuqhshthrkusrc', 5])
    vals.append([933, 5, 'abaabdcbbabacbdddadbbb', 'babbadbaaadbbbbaabbaabccbbdbadbbbbbbdbcbdbaaadbdbdbbbbdcbbdcbdaadbd', 15])
    vals.append([875, 10, 'hjeaiemqfliohlicmhndhbfdmlmcnjjgbg', 'hojqhmbgjlfmlliimlhahfeihgmhhhnbmebhgnfhgmhfjqhmlnnddgmqldelnhebi', 4])
    vals.append([320672, 1, 'wyyojuothwmlvrglfzdzdbtubxuoffvncrswsaznmoijoi', 'ttvlvzxcvczuagwzgbfuwmmt', 40084])
    vals.append([5608475, 1, 'gbagadghfaedhddefgbehbbdedefbaaeddachgebhbcgahfdchffhbhfahhdegdhdfbccgefhcdhhcdfgdgfhcdffaacch', 'fgfadaaecdgabeahcacadcbfhhe', 1869491])
    vals.append([1263204, 1, 'dcbabceabbaebddaaecbddaceaedacddadadcbbadbdccdecdacdcaadbceeddccbceaade', 'abddbccbdca', 1894805])
    vals.append([100, 1, 'bca', 'abc', 99])
    vals.append([541, 9, 'bxhwcmunbdxcatppdsw', 'shbppncwbnsxxnxunwsbncpdchcbcspdcppdchmbbcuapphpdxbpcswcxpxpdscxpddbcppdxhpxbuxxdbpdpuudb', 1])
    vals.append([9447267, 1, 'cbdcbdbcdacbcabddbaabcbacbabcaacbabaccddcbbdbbaddcbcbaaadc', 'bbbbdbcbbbdbdbcdcacccbdcadadbacbcccc', 4723633])
    vals.append([1181362, 3, 'fckmaalkicfakhcbiglkekajmadjkj', 'zfkjkjgkmjhfkackkhhjalgkkclcklabggk', 0])
    for val in vals:
        b, d, a, c, answer = val
        res = solve(a, b, c, d)
        if res == answer:
            print '++++++++++++++++++++++++++++'
            pass
        else:
            print '----------------------------'
            print val
            print res
            print '----------------------------'
            sys.stdin.readline()


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

maxe = max(a)
cnt = []
cur = 1
k = 0
i = 0
while i < n:
    cnt.append(0)
    while i < n and a[i] < cur:
        cnt[2 * k] += 1
        i += 1
    cnt.append(0)
    while i < n and a[i] == cur:
        cnt[2 * k + 1] += 1
        i += 1
    k += 1
    cur *= 2
cnt.append(0)
cnt.append(0)
maxe = len(cnt) - 1

maxk = cnt[1]
was = False
for l in range(maxk):
    cur = 1
    while cnt[cur] > 0:
        cnt[cur] -= 1
        cur += 2
    cnt[cur] -= 1
    cursum = 0
    ok = True
    for t in range(maxe, 0, -1):
        cursum += cnt[t]
        if cursum > 0:
            ok = False
            break
    if ok:
        print(l + 1, end=" ")
        was = True

if not was:
    print(-1)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))

def get(cnt):
    c = Counter(a)
    last = []
    while c[1] and (cnt is None or len(last) < cnt):
        x = 1
        while c[x]:
            c[x] -= 1
            x *= 2
        last.append(x >> 1)
    rem = sorted(c.elements())
    i = 0
    for x in last[::-1]:
        if i < len(rem) and rem[i] < 2 * x:
            i += 1
    return len(last) if i == len(rem) else 0

mx = get(None)
lo, hi = 0, mx
while lo < hi:
    mid = (lo + hi) >> 1
    if get(mid):
        hi = mid
    else:
        lo = mid + 1
if mx:
    print(*range(lo, mx + 1))
else:
    print(-1)


K = [0]*1000

K[0] = 1
for i in range(1, 1000):
    K[i] = i*K[i-1]

M = {}

def F(a,b):
    if a == 0 and b == 0:
        return 1
    if b == 0:
        return K[a]
    if (a,b) in M:
        return M[(a,b)]
    t = 0
    if a > 0:
        t += a*F(a-1,b)
    t += F(a,b-1)
    if b > 1:
        k = b-1
        for i in range(0,a+1):
            t += k*F(a-i,b-2)
            k *= (a-i)
    M[(a,b)] = t
    return t

n = int(raw_input())

d = [int(x) for x in raw_input().split(" ")]

x = 0
y = 0

for i in range(n):
    if d[i] == 1:
        x += 1
    if d[i] == 2:
        y += 1

print F(y,x)


import sys
range = xrange
input = raw_input

MOD = 998244353

import __pypy__
modmul = __pypy__.intop.int_mulmod
mo = lambda a,b: modmul(a,b,MOD)
po = lambda a,b: pow(a,b,MOD)

big = 10**6 + 10
modinv = [1]*big
for i in range(2,big):
    modinv[i] = mo(-(MOD//i), modinv[MOD%i])

fac = [1]
for i in range(1,big):
    fac.append(mo(fac[-1], i))

invfac = [1]
for i in range(1,big):
    invfac.append(mo(invfac[-1], modinv[i]))

def choose(n,k):
    return mo(mo(fac[n], invfac[k]), invfac[n-k])

def par(x):
    return -1 if x & 1 else 1

n = int(input())

ans = 0
extra = 0
for i in range(1, n + 1):
    base = po(3, n - i)
    tmp = po(-base + 1, n) - po(-base, n)
    ans = (ans + par(i + 1 + n) * mo(choose(n, i), tmp)) % MOD

    exp = modmul(n, n - i, MOD - 1) + i
    extra = (extra + par(i + 1) * mo(choose(n, i), po(3, exp))) % MOD

print (3 * ans + 2 * extra) % MOD


MOD = 998244353;import __pypy__;int_add = __pypy__.intop.int_add;int_sub = __pypy__.intop.int_sub;int_mul = __pypy__.intop.int_mul
def make_mod_mul(mod=MOD):
    fmod_inv = 1.0 / mod
    def mod_mul(a, b, c=0):
        res = int_sub(int_add(int_mul(a, b), c), int_mul(mod, int(fmod_inv * a * b + fmod_inv * c)))
        if res >= mod:            return res - mod
        elif res < 0:            return res + mod
        else:            return res
    return mod_mul
mod_mul = make_mod_mul()
def mod_pow(x, y):
    if y == 0:        return 1
    res = 1
    while y > 1:
        if y & 1 == 1:            res = mod_mul(res, x)
        x = mod_mul(x, x);        y >>= 1
    return mod_mul(res, x)
n, m = map(int, input().split());pascal = [[1]]
for _ in range(n + m + 5):
    nl = [1]
    for i in range(_):        nl.append((pascal[-1][i] + pascal[-1][i+1]) % MOD)
    nl.append(1);    pascal.append(nl)
def s1(n,m):
    out = 0
    for row in range(1, n):
        above = row;    below = n - row;     bottom = [];top = []
        for i in range(m):  a = below - 1;     b = i;    a2 = below;    b2 = m-i-1;  bottom.append(mod_mul(pascal[a+b][a] , pascal[a2+b2][a2]))
        for i in range(m):  a = above - 1;  b = i;   a2 = above;    b2 = m-i-1;   top.append(mod_mul(pascal[a+b][a] , pascal[a2+b2][a2]))
        top.reverse();        curr = 0
        for i in range(m):  out += mod_mul(curr,bottom[i]);  curr += top[i];  curr %= MOD;   out %= MOD
    return out * 2
def s2(n,m):
    o = 0
    for i in range(1,n):
        for j in range(1,m):  a = pascal[i+j-1][i-1];       b = pascal[n-i+j-1][n-i]; c = pascal[n-i-1+m-j][m-j];  d = pascal[i+m-j-1][i];   o += mod_mul(mod_mul(a,b),mod_mul(c,d))
    return o
c1 = s1(n,m);c2 = s1(m,n);c3 = s2(n,m);out = (c1 + c2 - 2*c3) % MOD;print(out)


M=998244353;N=4042
try:
    import __pypy__
    int_add=__pypy__.intop.int_add
    int_sub=__pypy__.intop.int_sub
    int_mul=__pypy__.intop.int_mul
    def make_mod_mul(mod=M):
        fmod_inv=1.0/mod
        def mod_mul(a,b,c=0):
            res=int_sub(
                int_add(int_mul(a,b),c),
                int_mul(mod,int(fmod_inv*a*b+fmod_inv*c)),
            )
            if res>=mod:return res-mod
            elif res<0:return res+mod
            else:return res
        return mod_mul
    mod_mul=make_mod_mul()
except:
    def mod_mul(a,b):return(a*b)%M
def mod_add(a,b):
    v=a+b
    if v>=M:v-=M
    if v<0:v+=M
    return v
def mod_sum(a):
    v=0
    for i in a:v=mod_add(v,i)
    return v
f1=[1]
for i in range(N):f1.append(mod_mul(f1[-1],i+1))
f2=[pow(f1[-1],M-2,M)]
for i in range(N):f2.append(mod_mul(f2[-1],N-i))
f2=f2[::-1]
C=lambda a,b:mod_mul(mod_mul(f1[a],f2[b]),f2[a-b])
A=lambda a,b,w:mod_mul(C(a+b,a),C(w+b-a-2,b-1))
def V(h,W,H):
    s=p=0
    for i in range(W-1):
        p=mod_add(p,A(i,H-h,W));s=mod_add(s,mod_mul(p,A(W-2-i,h,W)))
    return s
H,W=map(int,input().split())
Y=mod_sum(mod_mul(A(s,h,W),A(W-2-s,H-h,W))for s in range(W-1)for h in range(1,H))
X=mod_add(mod_sum(V(h,W,H)for h in range(1,H)),mod_sum(V(w,H,W)for w in range(1,W)))
print((X+X-Y-Y)%M)


def bits(i):
    tmp = i
    ans = 0
    while tmp != 0:
        if (tmp & 1) == 1:
            ans += 1
        tmp >>= 1
    return ans

def get(i, j):
    k = 0
    while ((1<<k) & j) == 0:
        k += 1

    tj = j - (1<<k);
    ti = i - (1<<k);
    for p in xrange(N):
        if g[k][p] == 0 or ((1<<p) & ti) == 0 or ((1<<p) & tj):
            continue;
        dp[i][j] += dp[ti][tj] + dp[ti][tj + (1<<p)];

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

np = 1 << N
dp = [[0 for i in xrange(np)] for j in xrange(np)]
g = [[0 for i in xrange(N)] for j in xrange(N)]
for i in xrange(M):
    v, u = map(int, raw_input().split())
    v -= 1
    u -= 1
    g[u][v] = 1
    g[v][u] = 1
    s = (1 << v) + (1 << u)
    dp[s][s] = 1

for i in xrange(np):
    bs = bits(i)
    if bs <= 2:
        continue
    j = i
    while j != 0:
        get(i, j)
        j = (j - 1) & i

ans = 0
for i in xrange(np):
    if bits(i) == K:
        ans += dp[np - 1][i]

print ans


n = int(input())
sz = len(str(n))
def get(x):
    ans = 0
    nw = 1
    x1 = x
    for i in range(sz):
        x = x1
        if x < nw:
            while x < nw: x *= 10
            x -= 1 #тк сука [1;x)
        else:
            while x >= nw * 10: x //= 10
        x = min(x, n)
        ans += x - nw + 1
        nw *= 10
    return ans

MOD = 998244353

ans = 0
i = 1
while i <= n:
    l = i
    r = min(n, 10 ** (len(str(i))) - 1) + 1
    nw = (get(i) - i) // MOD
    while r - l > 1:
        mid = (l + r) // 2
        x = (get(mid) - mid) // MOD
        if nw == x:
            l = mid
        else:
            r = mid
    ans += nw * (r - i)
    # i += 1
    i = r
print((ans * -MOD) % (int)(1e9 + 7))


def prefix(s):
    v = [0]*len(s)
    for i in range(1,len(s)):
        k = v[i-1]
        while k > 0 and s[k] != s[i]:
            k = v[k-1]
        if s[k] == s[i]:
            k = k + 1
        v[i] = k
    return v

n = int(input())
n-=1
s1 = input()
s2 = input()
opos = {'W':'E', 'E':'W', 'N':'S', 'S':'N'}
s3 = ''
for elem in s2:
    s3 += opos[elem]

s3  = s3[::-1]
s = s3 + '$' + s1

a = prefix(s)[2 * n]
if a == 0: print('YES')
else: print('NO')