#!/usr/bin/env python3

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

minDeletedPlayers = 0
maxDeletedPlayers = 0

# Finding min deleted players
playersStates = []
for i in range(a1):
    playersStates.append(k1)
for i in range(a2):
    playersStates.append(k2)
memN = n
while memN > 0:
    # Finding max number
    maxNumber = -1
    itemId = 0
    for i, item in enumerate(playersStates):
        if item > maxNumber:
            maxNumber = item
            itemId = i
    playersStates[itemId] -= 1
    memN -= 1
for item in playersStates:
    if item <= 0:
        minDeletedPlayers += 1

# Finding max deleted players
playersStates = []
for i in range(a1):
    playersStates.append(k1)
for i in range(a2):
    playersStates.append(k2)
memN = n
while memN > 0:
    # Finding min number
    minNumber = 100500
    itemId = 0
    for i, item in enumerate(playersStates):
        if item < minNumber and item != 0:
            minNumber = item
            itemId = i
    playersStates[itemId] -= 1
    memN -= 1
for item in playersStates:
    if item <= 0:
        maxDeletedPlayers += 1

print(minDeletedPlayers, maxDeletedPlayers)


n,k=map(int,input().split())
a=[1]
j=2
while n>1:
    b=a.copy()
    a.append(j)
    a.extend(b)
    #print(a)
    j=j+1
    n=n-1
print(a[k-1])


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


n,k=map(int,input().split())
a=[1]
for i in range(n):
    a+=[max(a)+1]
    a+=a[:-1]
    if len(a)>=k:
        break
print(a[k-1])


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

import sys

def main():
    n, k = map(int, input().split())
    seq = [1]
    for i in range(1, n):
        seq = seq + [i + 1] + seq
    print(seq[k - 1])

if __name__ == '__main__':
    main()


x=input().split()
arr=[1]
for i in range(1,int(x[0])+1):
    arr.append(i+1)
    arr=arr+arr[:-1]
    if len(arr)>int(x[1]):
        print(arr[int(x[1])-1])
        break


#inp=open('INPUT.TXT','r')
#n,k=map(int,inp.read().split())
#inp.close()
n,k=map(int,input().split())

biggest_n=2
seq=[1]
for i in range(n-1):
    seq.extend(seq)
    seq.insert(len(seq)//2,biggest_n)
    biggest_n+=1

print(seq[k-1])
#out=open('OUTPUT.TXT','w')
#out.write(str(seq[k-1]))
#out.close()


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


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


n,k=map(int,input().split(' '));
arr=[1];
for i in range(2,n+1):
    new_list=arr[:]
    arr.append(i);
    arr.extend(new_list);
print(arr[k-1]);


n,k=map(int,input().split())
s=['1']
c=2
for i in range(0,n-1):
	s=s+s[::-1]
	x=len(s)
	x=x//2
	s.insert(x,c)
	c=c+1
#print(s)
print(s[k-1])


n,k=map(int,input().split())
a=[1]
if(k>=2**(n-1)):
    k=2**n -k
x=len(bin(k)[2:])
for i in range(2,x+1):

    a.extend(a)
    a.insert(len(a)//2,i)

print(a[k-1])


line = input().split()

n = int(line[0])
h = int(line[1])
import numpy as np
array_nodes_minheigt = np.zeros([36,36])
array_nodes_minheigt[0,0] = 1
for nodes in range(1,36):
    for minheight in range(0,nodes+1):
        for topnode in range(1, nodes + 1):
            left = topnode-1
            right = nodes - topnode
            array_nodes_minheigt[nodes,minheight] += array_nodes_minheigt[left,0] * array_nodes_minheigt[right,0] -             (array_nodes_minheigt[left,0]-array_nodes_minheigt[left, max(minheight-1,0)])*             (array_nodes_minheigt[right,0]-array_nodes_minheigt[right, max(minheight-1,0)])

print(int(array_nodes_minheigt[n,h]))


MAX = 10**5 + 1;
grundy = [0 for i in xrange(MAX)];
choice = [-1 for i in xrange(MAX)];
for i in xrange(1,MAX):
    k = 2;
    U = set();
    while k*(k+1)/2 <= i:
        diff = i - k*(k+1)/2;
        if diff % k == 0:
            offset = diff/k;
            x = grundy[offset + k ] ^ grundy[offset];
            if not x: choice[i] = k;
            U.add(x);
        k += 1;
    while grundy[i] in U:
        grundy[i] += 1;
    grundy[i] ^= grundy[i - 1];

n = int(raw_input());
print choice[n];


import math
from collections import Counter

n = int(input())
g = [0 for i in range(n + 1)]
prefix_xor = g.copy()

def in_range(d, k):
    if (2 * k - d * d + d) % (2 * d) != 0:
        return -1
    x = (2 * k - d * d + d) / (2 * d)
    return int(x) if x > 0 else -1

def mex(arr):
    counter = Counter()
    for i in arr:
        counter[i] += 1
    for i in range(0, len(arr) + 1):
        if counter[i] == 0:
            return i

def find_move(arr):
    for i in range(0, len(arr)):
        if arr[i] == 0:
            return i
    return -1

for i in range(3, n + 1):
    for_range = range(2, int(math.sqrt(2 * i)) + 1)
    filter_range = [l for l in for_range if in_range(l, i) > 0]
    branches = [prefix_xor[in_range(d, i) + d - 1] ^ prefix_xor[in_range(d, i) - 1] for d in filter_range]
    g[i] = mex(branches)
    prefix_xor[i] = prefix_xor[i-1] ^ g[i]
    if i == n:
        print(-1 if g[i] == 0 else filter_range[find_move(branches)])


import math
n, k = map(int, input().split())
dp = [[1 for _ in range(k+1)] for _ in range(n+1)]
for i in range(1, n+1):
    f = set((1, i))
    for m in range(2, int(math.sqrt(i))+1):
        if i%m==0:
            f.add(m)
            if i/m != i:
                f.add(i//m)
    f = list(f)
    for j in range(2, k+1):
        dp[i][j] = 0
        for x in f:
            dp[i][j] += dp[x][j-1]
ans = 0
for i in range(1, n+1):
    ans += dp[i][k]
    ans %= 1000000007
print(ans%1000000007)


m,s=[int(i) for i in input().split()]
if (s<1 and m>1) or s>9*m:
    print('-1 -1')
elif s==0 and m==1:
    print('0 0')
else:
    n=s//9
    l=s-9*n
    mi=0

    ma0=[str(9)]*n
    if l!=0:
        ma0.append(str(l))
        for i in range(m-n-1):
            ma0.append(str(0))
    else:
        for i in range(m-n):
            ma0.append(str(0))
    ma=''.join(ma0)

    if l!=0:
        for i in range(n):
            mi+=9*10**(i)
        if l!=0 and s>9*(m-1) and n>0:
            mi+=l*10**(n)
        elif l!=0 and s<9*(m-1) and n>0:
            mi+=10**(m-1)+(l-1)*10**(n)
        elif l!=0 and n==0:
            mi+=10**(m-1)+(l-1)
    elif l==0 and s==9*m:
        for i in range(n):
            mi+=10**(m)-1
    else:
        mi+=10**(m-1)
        for i in range(n-1):
            mi+=9*10**(i)
        mi+=8*10**(n-1)

    print(int(mi),int(ma))


n,k=map(int,input().split())
a=list()
c=0
for i in range (1,n+1):
	if(n%i==0):
		a.append(i)
		c+=1
if(c<k):
	print("-1")
else:
	print(a[k-1])


a,b=[int(i) for i in input().split()]
s=[int(i) for i in input()split()]
m=0
c=b
for i in range(a):
    if s[i]>c:
        m=m+1
        c=b
    else:
        c=c-s[i]
print(m)


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


#!/usr/bin/python3

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

a -= 1
b -= 1
if a // m == b // m:
    print(1)
elif a % m == 0 and (b + 1) % m == 0:
    print(1)
elif a % m == 0 or (b + 1) % m == 0:
    print(2)
elif a % m == (b + 1) % m:
    print(2)
elif b // m - a // m == 1:
    print(2)
elif m == 2:
    print(2)
else:
    print(3)


def binm(n, k,mod):
    C = [[0 for x in range(k+1)] for x in range(n+1)]

    # Calculate value of Binomial Coefficient in bottom up manner
    for i in range(n+1):
        for j in range(min(i, k)+1):
            if j == 0 or j == i:
                C[i][j] = 1

            # Calculate value using previously stored values
            else:
                C[i][j] = C[i-1][j-1] + C[i-1][j]
            C[i][j]%=mod

    return C[n][k]%mod
n,m=[int(i) for i in raw_input().split()]
mod=998244353
if n==2:
    print 0
else:
    val=1
    for i in range(n-3):
        val*=2
        val%=mod
    print ((n-2)*val*binm(m,n-1,mod))%mod


import sys
input = sys.stdin.readline
def main():
  #  t = int(input())
    t = 1
    while(t):
  #  for _ in range(t):
        t -= 1

        MOD = 998244353
        fact = [1]*200005
        for i in range(1, 200005):
            fact[i] = i*fact[i-1]

        def fast_sq(a, b):
            ans = 1
            if(b == -1):
                b = MOD-2
            for i in range(60):
                if((1<<i)&b):
                    ans *= a
                a *= a
            return ans
        n, m = map(int, input().split())
        print(fact[m]*(n-2)*fast_sq(2, n-3)*fast_sq(fact[n-1]*fact[m-n+1], -1)%MOD)

main()


n=list(map(int,input()).split()))
f,s,w=0,0,0
for i in range(7):
    if abs(k[0]-i)<abs(k[1]-i):
        f+=1
    elif abs(k[0]-i)>abs(k[1]-i):
        s+=1
    else:
        w+=1
print(f,w,s)


tramEndPoint, igorStartPos, igorEndPos = map(int, raw_input().split())
tramS, igorS = map(int, raw_input().split())
tramStartPos, tramDir = map(int, raw_input().split())

igorTime = abs(igorEndPos-igorStartPos)*igorS

getIgorTime = 0
getToEndTime = 0

distToIgor = igorStartPos - tramStartPos
if (distToIgor > 0 and tramDir > 0) or (distToIgor < 0 and tramDir < 0):
    getIgorTime = abs(distToIgor)*tramS
else:
    if tramDir > 0:
        toEnd = tramEndPoint-tramStartPos
        getIgorTime = (toEnd+(tramEndPoint-igorStartPos))*tramS
    else:
        toBeg = tramStartPos
        getIgorTime = (toBeg+igorStartPos)*tramS
    tramDir *= -1

tramStartPos = igorStartPos

distToEnd = igorEndPos - tramStartPos
if (distToEnd > 0 and tramDir > 0) or (distToEnd < 0 and tramDir < 0):
    getToEndTime = abs(distToEnd)*tramS
else:
    if tramDir > 0:
        toEnd = tramEndPoint-tramStartPos
        getToEndTime = (toEnd+(tramEndPoint-igorEndPos))*tramS
    else:
        toBeg = tramStartPos
        getToEndTime = (toBeg+igorEndPos)*tramS

print min(igorTime, (getIgorTime+getToEndTime))


ef game(a,b,count):
    if(a==0 or b==0):
        return count
    else:
        mi=min(a,b)
        ma=max(a,b)
        return game(mi+1,ma-2,count+1)

a,b=map(int,input().split())
if(a<3 and b<3):
    print(0)
else:
    res=game(a,b,0)
    print(res)


k,a,b=map(int,input().split())
ctr=int(0)
if (a<k and b<k) or (a%k!=0 and b<k) or (b%k!=0 and a<k):
    exit(print('-1'))
while a>=k or b>=k:
    if a>=k:
        a-=k
        ctr+=1
    if b>=k:
        b-=k
        ctr+=1
exit(print(ctr))


x=int(input())
z=[n for n in str(int(input()))]
l=0
for n in z:
  in n!=4 or n!=7:
    print('NO')
    l=0
    break
  else:
    l=1
if l==1:
  if sum(z[0::x//2])==sum(z[x//2:x])
    print('YES')
  else:
    print('NO')


n,m=map(int,input().split())
if m!=0:
    print([min(m,n-m))
else:
    print('1')


n=int(input())
m=int(input())
k=min(m,n-m)
if(m==1 or m==0):
    print(1)
    return 0
if(m==n):
   print(0)
else:
    print(k)


#!/usr/bin/python
import sys

def ext_gcd(a, b):
    if b == 0:
        return (a, 1, 0)
    (dp, xp, yp) = ext_gcd(b, a % b)
    return (dp, yp, xp - a//b * yp)

def mod_solve(a, b, n):
    (d, xp, yp) = ext_gcd(a, n)
    if b % d == 0:
        x0 = xp * (b/d) % n
        return x0
    else:
        return None

def choose(n, m, MOD):
    result = 1
    for i in xrange(1, n+1):
        result = (result * i) % MOD
    for i in xrange(1, n-m+1):
        result = (result * mod_solve(i, 1, MOD)) % MOD
    for i in xrange(1, m+1):
        result = (result * mod_solve(i, 1, MOD)) % MOD
    return result

MOD = 1000000007
(n, m, g) = map(lambda x: int(x), raw_input().split())
if n == 0:
    if (m == 1 and g == 1) or (m > 1 and g == 0):
        result = 1
    else:
        result = 0
    print(result)
    sys.exit(0)

if m == 0:
    if (n % 2 == 0 and g == 1) or (n % 2 == 1 and g == 1):
        result = 1
    else:
        result = 0
    print(result)
    sys.exit(0)

term = 1
result = term
for i in xrange(1, n+1):
    term = (term * (m + i) * mod_solve(i, 1, MOD)) % MOD
    if i % 2 == 0:
        result = (result + term) % MOD
    else:
        result = (result + MOD - term) % MOD
if n % 2 == 1:
    result = (MOD - result) % MOD
if m == 1:
    if n % 2 == 0:
        result = (result + MOD - 1) % MOD
    else:
        result = (result + 1) % MOD
if g == 1:
    result = (choose(n+m, m, MOD) + MOD - result) % MOD
print(result)


import operator as op
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

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

N,M,G = map(int, raw_input().split())
def q(n):
	return ncr(n+M, M)

mod = 1000000007
r = [0] * (N+M+1)
r[1] = 1;
for i in range(2, N+M+1):
	r[i] = (mod - (mod/i) * r[mod%i] % mod) % mod;
#~ print r

def f(n):
	n -= 1
	sign = 1 if (n%2 == 0) else -1
	res = 0
	k = 0

	binom = 1

	while k <= n:
		res = (res + sign * binom) % mod
		binom = (binom * (k+M+1) * r[k+1]) % mod

		sign *= -1
		k += 1
	if M == 1:
		res += sign
	return res
if M == 0:
	print int(G == (N+1)%2)
	raise SystemExit

if G == 1:
	print f(N)
else:
	print q(N)-f(N)


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

sb = 0
s = 0

for i in range(len(l)):
    if(l[i] < b):
        sb += 1
    elif(l[i] = b):
        s = 1
    else:
        break
print(b-sb+s)


n,k,d = map(int,input().split())
import sys
sys.setrecursionlimit(10**6)
mod = int(1e9+7)

def rec(n,d):
    if n<0:return 0
    if n==0:
        return d==0
    res = 0
    for i in range(1,k+1):
        if i>=d:
            res+=rec(n-i,0)
        else:
            res+=rec(n-i,d)
        res%=mod
    return res%mod
print(rec(n,d)%mod)


    MOD = 10 ** 9 + 7
    HAVE, NOT_HAVE = 1, 0

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

    dp = [[0 for _ in range(n + 1)] for _ in range(2)]
    dp[NOT_HAVE][0] = 1
    for dist in range(1, n + 1):
        for weight in range(1, k + 1):
            if weight > dist:
                break
            if weight >= d:
                dp[HAVE][dist] += dp[HAVE][dist - weight] + dp[NOT_HAVE][dist - weight]
                dp[HAVE][dist] %= MOD
            else:
                dp[NOT_HAVE][dist] += dp[NOT_HAVE][dist - weight]
                dp[NOT_HAVE][dist] %= MOD
                dp[HAVE][dist] += dp[HAVE][dist - weight]
                dp[HAVE][dist] %= MOD
    print(dp[HAVE][n])


n = int(input())
o1,o2 = map(int,input().split())
s1,s2 = map(int,input().split())
t1,t2 = map(int,input().split())

a1,a2,a3=0,0,0
for i in range(o1,o2+1):
    for j in range(s1,s2+1):
        for k in range(t1,t2+1):
            if i+j+k==n:
               a1,a2,a3=i,j,k
               break
print(a1,a2,a3)


def DFS(x):
    for i in range(x):
        if(Seen[i]):
            continue
        if(Rem[i]>=C[x]):
            if(Rem[i]==C[x] and len(Children[i])==0):
                continue
            Rem[i]-=C[x]
            Parent[x]=i
            Children[i].append(x)
            return True
    for i in range(x):
        if(Seen[i]):
            continue
        Y=[]
        Seen[i]=True
        for j in range(len(Children[i])):
            child=Children[i][j]
            Parent[child]=-1
            Rem[i]+=C[child]
            if(DFS(child)):
                continue
            Parent[child]=i
            Rem[i]-=C[child]
            Y.append(child)
        Seen[i]=False
        Children[i]=list(Y)
        if(Rem[i]>=C[x]):
            if(Rem[i]==C[x] and len(Children[i])==0):
                continue
            Rem[i]-=C[x]
            Children[i].append(x)
            Parent[x]=i
            return True
    return False

n=int(input())

C=list(map(int,input().split()))
Rem=[-1]*n
Parent=[-1]*n
Children=[]
Seen=[False]*n
C.sort(reverse=True)

if(C[0]!=n or C.count(2)>0):
    print("NO")

else:
    for i in range(n):
        Rem[i]=C[i]-1
        Children.append([])
    Parent[0]=0
    Ans="YES"
    for i in range(1,n):
        if(DFS(i)==False):
            Ans="NO"
            break
    for i in range(n):
        if(Rem[i]!=0 and C[i]!=1):
            Ans="NO"
            break
    print(Ans)


N = 2000000000
t = 0
a = [1]
b = [1]
c = []
for i in range(1, 31):
    a.append(a[i-1]*2)
for i in range(1, 20):
    b.append(b[i - 1] * 3)
for i in range(0,31):
    print(a[i])
for i in range(0,20):
    print(b[i])
for i in range(0, 31):
    for j in range(0, 20):
        if(a[i] <= N/b[j]):
            c.append(a[i] * b[j])
            t+=1

for i in range(0, 10):
    print(c[i])
print("t=%s"%t)
l, r = map(int, input().split())
cnt = 0
for i in range(0, 326):
    if(c[i] >= l):
        if(c[i] <= r):
            cnt = cnt + 1

print(cnt)


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

import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys

"""
created by shhuan at 2017/12/2 22:13

"""

f0 = "What are you doing at the end of the world? Are you busy? Will you save us?"

MAXN = 10**5+5
F = [0] * MAXN
F[0] = len(f0)

p1 = "What are you doing while sending \""
p2 = "\"? Are you busy? Will you send \""
p3 = "\"?"
lp1, lp2, lp3 = len(p1), len(p2), len(p3)
l = lp1 + lp2 + lp3

for i in range(0, MAXN-1):
    F[i+1] = 2 * F[i] + l
    # s[i+1] = p1 + si + p2 + si + p3

def solve(n, k):
    if n == 0:
        if k > len(f0):
            return '.'
        return f0[k-1]

    if k <= lp1:
        return p1[k-1]
    elif k <= lp1 + F[n-1]:
        return solve(n-1, k-len(p1))
    elif k <= lp1 + F[n-1] + lp2:
        return p2[k-lp1-F[n-1]-1]
    elif k <= lp1 + lp2 + 2*F[n-1]:
        return solve(n-1, k-lp1-lp2-F[n-1])
    elif k <= lp1 + lp2 + 2*F[n-1] + lp3:
        return p3[k-lp1-lp2-2*F[n-1]-1]
    else:
        return '.'

Q = int(input())

ans = ""
for i in range(Q):
    N, K = map(int, input().split())
    ans += solve(N, K)

print(ans)


n, p = [int(i) for i in input().split()]
i = 1
f = True
while n - i*p >= 1:
    if bin(n - i*p)[2:].count("1") <= i and (i < n - i*p):
        print(i)
        f = False
        break
    i += 1

if f:
    print("-1")


from collections import Counter
n=int(input())
l=[]
for i in range(n):
    x,y=map(int,input().split())
    l.append(x)
    l.append(y)
d=Counter(l)
s1=list(d.values())
f=True
if(len(list(d.keys()))<=3):
    print('WIN')
    exit()
for p in s1:
    if(p==1):
        print('WIN')
        f=False
        break
    elif(p>=3):
        print('WIN')
        f=False
        break
if(f):
    print('FAIL')


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))*(n-m)/n
res = res % mod
print(int(res))


result = []
cout = int(input())
for i in range(0,cout):
	g = int(input())
	result.append(g)
result.sort()
cout = int(cout)
if cout%2 != 0:
	v = cout//2 + 1;
else:
	if cout/2 - result[0] == result[cout - 1] - cout/2:
		v = cout / 2
	else:
		v = cout / 2 + 1
v = int(v)
print(result[v-1])


#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
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")
ALPHA='abcdefghijklmnopqrstuvwxyz'
MOD=1000000007
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
// vsInput()

n,a,b,c,d=value()
ans=0

minSum=a+b+2
maxSum=a+b+2*n

for mid in range(1,n+1):
    box1=(a+b+mid+1,a+b+mid+n)
    box2=(a+c+mid+1,a+c+mid+n)
    box3=(c+d+mid+1,c+d+mid+n)
    box4=(d+b+mid+1,d+b+mid+n)

    minSum=max(box1[0],box2[0],box3[0],box4[0])
    maxSum=min(box1[1],box2[1],box3[1],box4[1])

    # print(minSum,maxSum)
    ans+=max(maxSum-minSum+1,0)

print(ans)


import sys
import math
import bisect

MOD = int(1e9+7)

# n = map(int, raw_input().split())
input = map(int, raw_input().split())
if input[-1] == input[0] and input[0] !=0 :
    print 1
elif input[-1] == input[0] and input[0] == 0 and input[1] == 0:
    print 1
else:
    print 0


# N boxes can be filled with type H or type T objects
# 1 H object takes 1 box
# 1 H can turn into M T objects which must take contiguous boxes
# How many ways to fill N boxes?

# E.g. N=4, M=2 -> return 5: HHHH, HHTT, HTTH, TTHH, TTTT

# Constraints: N <= 10^18

def _solve(n, m, memo):
	if n <= 0: return 0
	if n < m: return 1
	if n == 1: return 2
	if (n, m) in memo: return memo[(n, m)]

	out = 0
	mid = n // 2

	# No M block hanging over 2 halves
	out += _solve(mid, m, memo) * _solve(n-mid, m, memo) % 1000000007

	# M block over 2 halves
	for i in range(1,m):  # i = part of M block in first half
		if mid-i < 0 or n-mid+i-m < 0: continue
		n1 = 1 if mid-i == 0 else _solve(mid-i, m, memo)
		n2 = 1 if n-mid+i-m == 0 else _solve(n-mid+i-m, m, memo)
		out += n1*n2

	memo[(n, m)] = out
	return out

def solve(n, m):
	return _solve(n, m, {})

def main():
	from sys import stdin

	n, m = list(map(int, stdin.readline().strip().split()))
	out = solve(n, m)
	print('{}'.format(out))

if __name__ == '__main__':
	main()


def countstr(item, str):
    ret = 0
    for i in xrange(len(str)-len(item)+1):
        ret += (str[i:len(item)+i]==item)
    return ret

def numerate(n):
    if 1==n:
        return ['4', '7']
    l = numerate(n-1)
    return [item+'4' for item in l] + [item+'7' for item in l] + ['4'+item for item in l] + ['7'+item for item in l]

s = raw_input()
counts = {}
for i in xrange(1, len(s)+1):
    l = numerate(i)
    cont = False
    for item in l:
        counts[item] = countstr(item, s)
        cont = cont or counts[item]!=0
    if not cont:
        break
tmp = counts.items()
tmp.sort(cmp=lambda x,y: cmp(x[0],y[0]) if x[1]==y[1] else y[1] - x[1])
print tmp[0][0] if tmp[0][1]>0 else -1


t=[]
for i in range(1,501):
    t.append(i(i+1)//2)
n=int(input())
if n in t:
    print('YES')
else:
    print('NO')


N = raw_input()
soma = 0
for i in range(1, int(N) + 1):
	soma += len(str(i))

print soma


import math

vectors = []

line_parts = raw_input().split()
x = int(line_parts[0])
y = int(line_parts[1])
n = int(line_parts[2])
d = int(line_parts[3])

for i in range(n):
  l = raw_input().split()
  vectors.append((int(l[0]), int(l[1])))

mp = {}

def canWin(x, y, t, fs, ss):

  if math.sqrt(math.pow(x, 2) + math.pow(y, 2)) > float(d):
    return False

  if (x, y, t) in mp:
    return mp[(x, y, t)]

  result = True

  if t == False and ss == False:  #if Dasha turn and if dasha hasnt swapped then can swap 1 time
    for v in vectors:
      result = result and (not (canWin(x + v[0], y + v[1], not t, fs, ss)))
    result = result and (not canWin(y, x, not t, fs, True))
  elif t == True and fs == False: #if Anton turn and if Anton hasnt swapped then can swap 1 time
    for v in vectors:
      result = result and (not (canWin(x + v[0], y + v[1], not t, fs, ss)))
    result = result and (not canWin(y, x, not t, True, ss))
  else: #since both has swapped 1 time now cannot swap further
    for v in vectors:
      result = result and (not (canWin(x + v[0], y + v[1], not t, fs, ss)))

  mp[(x, y, t)] = result

  return result

result = False

for v in vectors:
  result = result or canWin(x + v[0], y + v[1], False, False, False)

if result == True:
  print "Anton"
else:
  print "Dasha"


import sys
from array import array  # noqa: F401

def input():
    return sys.stdin.buffer.readline().decode('utf-8')

x, y, n, d = map(int, input().split())
vector = [list(map(int, input().split())) for _ in range(n)]
dp = [-1] * (1 << n)

def solve(bit, x, y):
    if dp[bit] != -1:
        return dp[bit]

    for i in range(n):
        if (1 << i) & bit:
            continue
        if (x + vector[i][0]) ** 2 + (y + vector[i][1])**2 <= d**2 and solve(bit | (1 << i), x + vector[i][0], y + vector[i][1]) == 0:
            dp[bit] = 1
            return 1

    dp[bit] = 0
    return 0

if solve(0, x, y):
    print('Anton')
else:
    print('Dasha')


n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
c1=0
for i in a:
    if i>=n:
        c+=1
        break
for i in b:
    if i>=n:
        c1+=1
        break

if c=1 or c1=1:
    print('No')
else:
    print('Yes')


'''input
7
2 3 4 1 6 7 5
'''

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

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

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

def lcm(xs):
    if not xs:
        return 1
    if len(xs) == 1:
        return x[0]
    if len(xs) == 2:
        return (xs[0] * xs[1]) // gcd(xs[0], xs[1])
    return lcm(xs[:-2] + [lcm([xs[-2], xs[-1]])])

def dfs_cycle_length(arr, u, visited, origin):
    visited.add(u)
    nxt = arr[u-1]
    if nxt in visited:
        return None if nxt != origin else 1
    tmp = dfs_cycle_length(arr, nxt, visited, origin)
    return None if tmp is None else tmp + 1

def solve(arr):
    cycles = []
    visited = set([])
    for u in range(1, len(arr) + 1):
        if u not in visited:
            length = dfs_cycle_length(arr, u, visited, u)
            if length is None:
                return -1
            cycles.append(length//2 if length % 2 == 0 else length)
    return lcm(cycles)

def main():
    n = ri()
    arr = rints()
    print(solve(arr))

main()


a,b,l,r = map(int,raw_input().split())
s = "a"
for i in range(1,a):
    temp = s[i-1]
    #print temp
    x = ord(temp)
    x += 1
    s += chr(x)
#print s
for i in range(b):
    s += s[-1]
#print s
temp = s[-1]
if b>=a :
    s += s[:a-1]
    s += chr(ord(temp)+1)
else :
    s += s[:b]
    s += chr(ord(temp)+1)
    for i in range(a-b-1):
        temp = s[-1]
        #print temp
        x = ord(temp)
        x += 1
        s += chr(x)
#print s
for i in range(b):
    s += s[-1]
#print s
length = len(s)
s = '_' + s
if r-l+1 >= length :
    print len(set(s))-1
else :
    start = l%length
    if start==0 :
        start = length
    i = start
    end = r%length
    if end==0 :
        end = length
    ans = {}
    while(start!=end) :
        ans[s[start]] = 1
        start += 1
        if start>length :
            start = 1
    ans[s[start]] = 1
    print len(ans)


def main(a, b, l, r):

    qL = (l - 1) // (2 * a + 2 * b)
    rL = (l - 1) % (2 * a + 2 * b) + 1

    qR = (r - 1) // (2 * a + 2 * b)
    rR = (r - 1) % (2 * a + 2 * b) + 1
    #print(qL, qR, rL, rR)
    if qL == qR:
        #In b segment
        if a < rL <= a + b and a < rR <= a + b:
            return 1
        if 2 * a + b < rL and 2 * a + b < rR:
            return 1
        #In a segment
        if 1 <= rL <= a and 1 <= rR <= a:
            return rR - rL + 1
        if a + b < rL <= 2 * a + b and a + b < rR <= 2 * a + b:
            return rR - rL + 1
        #In a + b segment
        if 1 <= rL <= a + b and 1 <= rR <= a + b:
            return a - rL + 1
        if a + b < rL and a + b < rR:
            return (2 * a + b) - rL + 1
        if a < rL <= a + b and a + b < rR <= 2 * a + b:
            return 1 + rR - (a + b)
        if a < rL <= a + b and 2 * a + b < rR:
            return 1 + a
        if 1 <= rL <= a and a + b < rR <= 2 * a + b:
            ans = a - rL + 1 + max(rR - (a + b + b), 0) + min(b, rR) - max(min(rR, b) - rL + 1, 0)
            return ans
        if 1 <= rL <= a and 2 * a + b < rR:
            return a - rL + 1 + a - max(b - rL + 1, 0)
    elif qL == qR - 1:
        #abababab
        newL = qL * (2 * a + 2 * b) + 1
        newR = (qR + 1) * (2 * a + 2 * b)

        if 1 <= rL <= a + b and a + b + 1 <= rR:
            return a + max(a - b, 0) + int(a <= b)

        if a + b + 1 <= rL <= 2 * (a + b) and (2 * a + 2 * b) + 1 <= rR <= a + b:
            return main(a, b, l - (a + b), r - (a + b))

        if 1 <= rL <= a and 1 <= rR <= a:
            return a + max(a - b, 0) + int(a <= b) + rR - max(rR - rL + 1, 0)
        if 1 <= rL <= a and a + 1 <= rR <= a + b:
            return a + max(a - b, 0) + int(a <= b)

        if a + 1 <= rL <= a + b and 1 <= rR <= a:
            return 1 + a + max(a - b, 0)
        if a + 1 <= rL <= a + b and a + 1 <= rR <= a + b:
            return 1 + a + max(a - b, 0)

        return main(a, b, l - (a + b), r - (a + b))

    else:
        return a + max(a - b, 0) + int(a <= b) # + main(a, b, l, (qL + 1) * (2 * a + 2 * b)) + main(a, b, qR * (2 * a + 2 * b) + 1, r)

a, b, l, r = [int(item) for item in input().split()]

print(main(a, b, l, r))


a = input()
tot = len(a)
if a[tot-1] = 0:
    m = int(10)
    n = int(a[0:tot-3])
else:
    m = int(a[tot-1])
    n = int(a[0:tot-2])
min = n//2 + 1
max = n
small = min //m
big = max //m
if small % m == 0:
    print(small)
elif small == big:
    print(-1)
elif small < big:
    print(small+1)


n, m = list(map(int, input().split()))
l = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = []
for i in range(m):
    ans = 0
    if a[i] in l:
        for j in range(l.index(a[i]), n):
            if l[j] in a:
                ans += 1
    cnt.append(ans)
for i in range(l.index(a[cnt.index(max(cnt))]), n):
    if l[i] in a:
        print(l[i], end=' ')


n=int(input())
s=input()
a=set()
mx=0
for i in s:
	if(isupper(i)):
		s.clear()
	else:
		if(islower(i)):
		    s.add(i)
            mx=max(mx,len(s))

print(mx)


alphabet = 'abcdefghijklmnopqrstuvwxyz'
alphabet_h = alphabet.upper()
alpha = tuple(alphabet)
alpha_h = tuple(alphabet_h)
n = int(input())
s = str(input())
g = 0
i = 1

while i <= n-1:
  if s[i-1] in alpha:
    while s[i] in alpha_h:
     # print(s[i], i)
      g = g + 1
      i = i + 1
   #   print(i)
      if i>=n-1 or s[i] in alpha:
        break
  i = i + 1
i = n - 1
if s[n-1] in alpha_h and g > 0:
  while s[i] in alpha_h and i>=0:
    g = g - 1
    i = i - 1
if n = 1 and s[0] in alpha:
  g = 1

print(g)


s = input()
t = input()
ind = []
for i in range(0,len(s)):
    if s[i:i+len(t)] == t:
        ind.append(i)
ss = len(s)
maxx = 0
for i in ind:
    k = i+len(t)
    maxx = max(len(s[k:ss)]),len(s[0:i]))
print(maxx)


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


n=int(input())
l=list(map(int,input().split()))
s=set(l)
c=0
while len(l)!=len(s):
	if l.count(l[c])>1:
		l.remove(l[c])
	else:
		c+=
print(len(l))
print(*l)


N = int(input())
M = 10 ** 8 + 5
pr = [True] * M
pr[0], pr[1] = False, False
for i in range(2, M):
    if pr[i]:
        for j in range(i * 2, M, i):
            pr[j] = False

prime = list(filter(lambda x: pr[x], range(M)))

def calc(n, k):
    if n == 0:
        return k
    elif n % 2 == 0:
        return n // 2 + k
    else:
        for i in prime:
            if n % i == 0:
                n -= i
                return calc(n, k + 1)

print(calc(N, 0))


def f(a,b):
    m=0
    if a>b:
        return a-b
    else:
        return b-a
n,b=[int(i) for i in input().split()]
tb=0
tn=0
for i in range(1,7):
    if f(i,n)<f(i,b):
        tn=tn+1
    elif f(i,n)>f(i,b):
        tb=tb+1
print(tn,6-(tb+tn),tb


k=int(input()
a=list(map(int,input().split()))
if max(a)<25:
    print(0)
else:
    print(max(a)-25)


s = input().split(' ')
if len(s) == 3:
    if (s[0].isnumeric()) and (s[1].isnumeric()) and (s[2].replace("-","").isnumeric()):
        n = int(s[0])
        a = int(s[1])
        b = int(s[2])
        if (n >= 1) and (n <= 100) and (a >= 1) and (a <= n) and (b >= -100) and (b <= 100):
            s = ""
            copy = ""
            for i in range(1, n + 1):
                s += str(i)
            copy = s
            m = abs(b) if abs(b) > n else n
            while len(s) < m:
                s += copy
            indA = s.index(str(a))
            indB = s.index(str(abs(b))) if abs(b) < n else int(s[abs(b) - 1])
            k = 0 if b < 0 else 1 + int(s[indA])
            print(indB - indA + k)


def abc(vertices):
    points = []
    points.append((vertices[0]-vertices[2])**2 + (vertices[1]-vertices[3])**2)
    points.append((vertices[0]-vertices[4])**2 + (vertices[1]-vertices[5])**2)
    points.append((vertices[4]-vertices[2])**2 + (vertices[5]-vertices[3])**2)
    points.sort()
    return points

def almost(vertices, index):
    vertices[index] -= 1
    if (vertices[0] == vertices[2] and vertices[1] == vertices[3]) or (vertices[0] == vertices[4] and vertices[1] == vertices[5]) or (vertices[2] == vertices[4] and vertices[3] == vertices[5]):
        vertices[i] += 1
        return False

    if (vertices[0] == vertices[2] and vertices[2] == vertices[4]) or (vertices[1] == vertices[3] and vertices[3] == vertices[5]):
        vertices[i] += 1
        return False

    a,b,c = abc(vertices)
    if (a+b == c):
        return True

    vertices[index] += 2
    if (vertices[0] == vertices[2] and vertices[1] == vertices[3]) or (vertices[0] == vertices[4] and vertices[1] == vertices[5]) or (vertices[2] == vertices[4] and vertices[3] == vertices[5]):
        vertices[i] -= 1
        return False

    if (vertices[0] == vertices[2] and vertices[2] == vertices[4]) or (vertices[1] == vertices[3] and vertices[3] == vertices[5]):
        vertices[i] -= 1
        return False

    a,b,c = abc(vertices)
    if (a+b == c):
        return True

    vertices[index] -= 1
    return False

vertices = map(int, raw_input().split())
def run():
    a,b,c = abc(vertices)
    if a+b == c:
        return "RIGHT"
    for i in xrange(6):
        if almost(vertices, i):
            return "ALMOST"
        return "NEITHER"

print run()


a,b,s=map(int,input().split())
w=s-abs(a)-abs(b)
if(w>=0 and w%2==0)
	print("YES")
else
	print("NO")


a,b, step = map(int, input().split())
step -= (a+b)
if step >= 0 and step%2 == 0
	print("Yes")
else
	print("No")


n=input()
if len(n)==1:
    print(0)
else n[::-1]!=n:
    print(len(n))
else:
    while True:
        n=n[:-1]
        s=n[::-1]
        if s!=n:
            print(len(s))
            break
        elif len(s)==1:
            print(0)
            break


import sys

def WeirdSub(a,b):
    while(True):
        if a == 0 or b == 0:
            return a,b
            break
        if a>=(2*b):
            a = a-(2*b)
            WeirdSub(a,b)
        if b>=(2*a):
            b= b-(2*a)
            WeirdSub(a,b)
        else:
            break
    return a,b

#===================MAIN===========
a,b = map(int,sys.stdin.readline().split())
#print(f"{a},{b}")
l=list(WeirdSub(a,b))
a=l[0]
b=l[1]
print(a,b)


def satisfies(cnt1, cnt2, onlyX, onlyY, none):
    '''
    tells whether you can form presents using the numbers
    '''
    cnt1 = max(cnt1 - onlyY, 0)
    cnt2 = max(cnt2 - onlyX, 0)
    return (cnt1 + cnt2 <= none)

import sys
cnt1, cnt2, x, y = int(sys.stdin.readline()).split()
bothXY = 0
onlyX = 0
onlyY = 0
none = 0
v = 0
while(not satisfies(cnt1, cnt2, onlyX, onlyY, none)):
    v += 1
    if(v % (x * y) == 0):
        bothXY += 1
    elif(v % x == 0):
        onlyX += 1
    elif(v % y == 0):
        onlyY += 1
    else:
        none += 1
print v


import fileinput

def str_to_int(s):
	return([ int(x) for x in s.split() ])

# args = [ 'line 1', 'line 2', ... ]
def proc_input(args):
	return(str_to_int(args[0]))

def solve(args, verbose=False):
	(cnt_x, cnt_y, x, y) = proc_input(args)
	forbid_x = set([ i * x for i in xrange(1, cnt_x + cnt_y) ])
	forbid_y = set([ i * y for i in xrange(1, cnt_x + cnt_y) ])
	set_x = [ 1 ] * cnt_x
	set_y = [ 1 ] * cnt_y
	count_x = count_y = 0
	i = 1
	if cnt_x > cnt_y:
		count_x += 1
	else:
		count_y += 1
	while count_x < cnt_x or count_y < cnt_y:
		i += 1
		if (i not in forbid_x) and (count_x < cnt_x):
			set_x[count_x] = i
			count_x += 1
		elif (i not in forbid_y) and (count_y < cnt_y):
			set_y[count_y] = i
			count_y += 1
	if verbose:
		print i
	return(i)

def test():
	assert(str_to_int('1 2 3') == [ 1, 2, 3 ])
	assert(solve([ '3 1 2 3' ]) == 5)
	assert(solve([ '1 3 2 3' ]) == 4)

if __name__ == '__main__':
	from sys import argv
	if argv.pop() == 'test':
		test()
	else:
		solve(list(fileinput.input()), verbose=True)


import math
verno=int(raw_input())
pointlist= list()
for i in range(verno):
    point=map(int, raw_input().split())
    pointlist.append(point)

l=0
w=0
area=0
if verno==1:
    print -1
else:
    l= abs(pointlist[0][0]-pointlist[1][0])
    w= abs(pointlist[0][1]-pointlist[1][1])
    area=l*w
    print area


s = raw_input().lower()
s = filter(lambda c: c not in set("aeiou"), s)
t = ""
for c in s:
    t += "."+c
print t


# Hey, there Stalker!!!
# This Code was written by:
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
# ▒▒╔╗╔═══╦═══╗▒▒▒╔╗▒▒▒
# ▒╔╝║║╔═╗║╔═╗╠╗▒▒║║▒▒▒
# ▒╚╗║║║║║║║║║╠╬══╣║╔╗▒
# ▒▒║║║║║║║║║║╠╣║═╣╚╝╝▒
# ▒╔╝╚╣╚═╝║╚═╝║║║═╣╔╗╗▒
# ▒╚══╩═══╩═══╣╠══╩╝╚╝▒
# ▒▒▒▒▒▒▒▒▒▒▒╔╝║▒▒▒▒▒▒▒
# ▒▒▒▒▒▒▒▒▒▒▒╚═╝▒▒▒▒▒▒▒
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
from functools import reduce
#from __future__ import division, print_function
#mod=int(1e9+7)
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#import threading
#threading.stack_size(2**26)
"""fact=[1]
#for i in range(1,100001):
#    fact.append((fact[-1]*i)%mod)
#ifact=[0]*100001
#ifact[100000]=pow(fact[100000],mod-2,mod)
#for i in range(100000,0,-1):
#    ifact[i-1]=(i*ifact[i])%mod"""
#from collections import deque, defaultdict, Counter, OrderedDict
#from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
#from heapq import heappush, heappop, heapify, nlargest, nsmallest

# sys.setrecursionlimit(10**6)
from sys import stdin, stdout
import bisect            #c++ upperbound
from bisect import bisect_left as bl              #c++ lowerbound bl(array,element)
from bisect import bisect_right as br             #c++ upperbound
import itertools
from collections import Counter
import collections
import math
import heapq
import re
def modinv(n,p):
    return pow(n,p-2,p)
def cin():
    return map(int,sin().split())
def ain():                           #takes array as input
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())

def Divisors(n) :
    l = []
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) :
            if (n // i == i) :
                l.append(i)
            else :
                l.append(i)
                l.append(n//i)
    return l

def most_frequent(list):
    return max(set(list), key = list.count)
def GCD(x,y):
    while(y):
        x, y = y, x % y
    return x

def ncr(n,r,p):                                              #To use this, Uncomment 19-25
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t

def Convert(string):
    li = list(string.split(""))
    return li

def SieveOfEratosthenes(n):
    global prime
    prime = [True for i in range(n+1)]
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n):
        if prime[p]:
            f.append(p)
    return f
prime=[]
q=[]
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            # print(f)
    return j

#Implement heapq
#grades = [110, 25, 38, 49, 20, 95, 33, 87, 80, 90]
#print(heapq.nlargest(3, grades)) #top 3 largest
#print(heapq.nsmallest(4, grades))
#Always make a variable of predefined function for  ex- fn=len
#n,k=map(int,input().split())
"""*******************************************************"""
def main():
    n=inin()
    print('codeforce'+n*'s')

######## Python 2 and 3 footer by Pajenegod and c1729
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

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

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

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

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

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

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

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
if __name__== "__main__":
    main()
#threading.Thread(target=main).start()


n = int(input())
st = "codeforce"
s = "s"
last = 1
while(n>0):
    if(n>=last):
        n-=last
        st+=s
        last = 2*last
        s = s+s
    else:
        n-=1
        st+="s"
        last = 1
        s = "s"
print(st)


t = int(input())
t=t-1
s=t*'s'
s1='codeforces'
s1=s1+s
print(s1)


import math
a,b,c,d,e = input().split()
a=int(a)
b=int(b)
c = int(c)
d=int(d)
e=int(e)
if(a!=1):
	g = a
	h = g-1
	f = a*(g-1)
	print(f)
else(print(1))


n=input()
b=input()
if len(n)<len(b):
    print("need tree")
elif len(n)>len(b):
    if b in n:
        print("automaton")
    else:
        f=0
        c=list(set(b))
        d=0
        e=0
        count=0
        while count<len(b):
            for i in range(d,len(n)):
                if b[e]==n[i]:
                    d=i+1
                    e+=1
                    count+=1
                    if i==len(n)-1 and count!=len(b):
                        count=len(n)
                    break
                if count==len(b):
                    break
        if count==len(b):
            print("automaton")
        else:
            for i in range(len(c)):
                d=n.count(c[i])
                e=b.count(c[i])
                if d>=e and e!=0:
                    continue
                else:
                    f=1
                    break
            if f==1:
                print("need tree")
            else:
                print("both")
elif len(n)==len(b):
    f=0
    c=list(set(b))
    for i in range(len(c)):
        d=n.count(c[i])
        e=b.count(c[i])
        if d>=e and e!=0:
            continue
        else:
            f=1
            break
    if f==1:
        print("need tree")
    else:
        print("array")


import sys

def solve():
    n, = rv()
    works = 0
    lastworks = -1
    guesses = list()
    for i in range(n):
        a, b, c, = rv()
        acopy = a
        charcount = [0] * 10
        for x in range(4):
            charcount[acopy % 10] += 1
            acopy //= 10
        guesses.append((tolist(a), b, c, charcount))

    for i in range(1, 10000):
        if different(i):
            l = tolist(i)
            icopy = i
            charcount = [0] * 10
            for x in range(4):
                charcount[icopy % 10] += 1
                icopy //= 10
            count = 0
            for guess in guesses:
                bulls, cows = 0, 0
                for j in range(4):
                    if l[j] == guess[0][j]: bulls += 1
                for j in range(10):
                    if charcount[j] > 0 and guess[3][j] > 0: cows+=1
                cows -= bulls

                if bulls == guess[1] and cows == guess[2]:
                    count += 1
            if count == n:
                works += 1
                lastworks = i
    if works == 0:
        print("Incorrect data")
    elif works == 1:
        print(lastworks)
    else:
        print("Need more data")

def tolist(i):
    il = list()
    while i > 0:
        il.append(i % 10)
        i //= 10
    while len(il) < 4: il.append(0)
    return il[::-1]

def different(i):
    count = [0] * 10
    for x in range(4):
        count[i % 10] += 1
        i //= 10
    for val in count:
        if val > 1: return False
    return True

def prt(l): return print(''.join(l))
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()


def is_sat(candi, cont):
    candi_match = cont[0]
    _bcount = int(cont[1])
    _ccount = int(cont[2])
    bcount = 0
    ccount = 0
    for i in xrange(4):
        if candi_match[i] == candi[i]:
            bcount += 1
        elif candi_match[i] in candi:
            ccount += 1
    return (_bcount == bcount and _ccount == ccount)

constraints = []

N = int(raw_input())
while N>0:
    constraints.append([x for x in raw_input().split()])
    N-=1
satisfies = []
for i in xrange(0,10000):
    candi = str(i).rjust(4,'0')
    satcount = 0
    for cont in constraints:
        if is_sat(candi, cont):
            satcount+=1
    if satcount == len(constraints):
        satisfies.append(candi)

goo = len(satisfies)
if goo  == 1:
    print satisfies[0]
elif goo == 0:
    print "Incorrect data"
else:
    print "Need more data"


p,k=map(int,input().split())
if p<k:
    print(1)
    print(p)
else:
    f=1
    t=0
    ms=0
    a=[]
    while p+ms*k>=k or p+ms*k<0:
        if t%2==0:
            while p+ms*k>=k:
                ms-=1
        else:
            while p+ms*k<0:
                ms+=1
        a.append(p+ms*k)
        t+=1
        p=ms
        ms=0
    print(len(a)+1)
    for i in a:
        print(i,end=' ')
    print(1)


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

ar = []
j = 1

while n!=0:
 q = n[0]%n[1]
 n[0] //= n[1]
 n[0] = -1*n[0]
 #j += 1
 ar.append(q)

print(len(ar))
for i in range(len(ar)):
 print(ar[i])


(p, k) = map(int, input().split())
used = [0] * p
if k == 0:
    print(pow(p, p - 1) % (10 ** 9 + 7))
else:
    c = 1 if k == 1 else 0
    for x in range(1, p):
        if not used[x]:
            y = x
            while not used[y]:
                used[y] = True
                y = k * y % p
            c += 1
    print(pow(p, c) % (10 ** 9 + 7))


[p, k] = map(int, raw_input().split())
#g = [-1] * p
#for i in range(p):
#    parent = (i * k) % p
#    g[i] = parent
#comps = 0; vis = [False] * p
#for i in range(1,p):
#    if not vis[i]: comps += 1
#    cur = i
#    while cur > 0 and not vis[cur]:
#        vis[cur] = True; cur = g[cur]
ord_k = 1
while pow(k, ord_k, p) != 1: ord_k += 1
comps = (p - 1) / ord_k
if k == 1: print pow(p, p, pow(10,9) + 7)
else: print pow(p, comps, pow(10,9) + 7)


from itertools import permutations

n=list(input())
ele=list(permutations(n,len(n)))

ans=[]
for i in range(0,len(ele)):
    m=int("".join(ele[i]))
    if len(list(str(m)))==len(n) and m[0]!='0':
        ans.append(m)
n=int(input())
if min(ans)==n:
    print("OK")
else:
    print("WRONG_ANSWER")


# https://codeforces.com/problemset/problem/1060/A
n=int(input())
string = input()
string = string.replace('9','0')
arr = sorted(list(string))
i=0
j=n-1
ans=0
while i<j:
    if arr[j]=='8':
        j-=1
        i+=10
        ans+=1
print(ans)


#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()

def main():
    n = int(readline())
    a = readlist()

    s = 0

    p2 = 0
    p = 0
    for i in a:
        if (i == 2) and (p == 1) and (p2 == 3):
            s += 2
        elif (i in [1, 2]) and (p in [1, 2]):
            s += 3
        elif (i in [1, 3]) and (p in [1, 3]):
            s += 4
        elif (i in [2, 3]) and (p in [2, 3]):
            print('Infinite')
            return

        p2 = p
        p = i

    print('Finite')
    print(s)

# region template

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        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):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    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 ostream:
    def __lshift__(self, a):
        if a is endl:
            sys.stdout.write(b"\n")
            sys.stdout.flush()
        else:
            sys.stdout.write(str(a))
        return self

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()

sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
cout, endl = ostream(), object()

readline = sys.stdin.readline
readlist = lambda var=int: [var(n) for n in readline().split()]
input = lambda: readline().rstrip(b"\r\n")

# endregion

if __name__ == "__main__":
    main()


n = int(input())
temp = []
while n >= 10:
    x = n % 10
    temp.append(min(x,9-x))
if n != 9:
    temp.append(min(n,9-n))
else:
    temp.append(n)
res = 0
for i in range(len(temp)):
    res += temp[i]*(10**i)
print(res)


from math import sqrt, ceil
from collections import namedtuple

def add(a, b):
    return a[0] + b[0], a[1] + b[1]

def count(p):
    return p * (3 * p + 2)

def bin_search(n):
    l = 0
    r = ceil(sqrt(n))
    while r - l > 1:
        m = (l + r) // 2
        if count(m) > n:
            r = m - 1
        else:
            l = m
    if count(r) > n:
        return l
    else:
        return r

def get_pos(n, p):
    if n < p: # /
        return add( (p - 1, -2 * p + 2), (n, 2 * n) )
    n -= p
    if n < p - 1: # \
        return add( (1 + 2 * (p - 1), 2), (-n, 2 * n) )
    n -= p - 1
    if n < p: # -
        return add( (p, 2 * p), (-2 * n, 0) )
    n -= p
    if n < p: # /
        return add( (-p, 2 * p), (-n, -2 * n) )
    n -= p
    if n < p: # -
        return add( (-2 * p, 0), (n, -2 * n) )
    raise RuntimeError("You're a big guy")

n = int(input())
if n == 0:
    print(0, 0)
else:
    p = bin_search(n)
    start = count(p)
    n -= start
    ans = get_pos(n, p + 1)
    print(ans[0], ans[1])


n = int(raw_input())
a = map(int, raw_input().split())
m = min(a)
if sum(x == m for x in a) > n / 2:
    print 'Bob'
elif c:
    print 'Alice'


tri = lambda k:(k*(k+1))//2
x = int(input())
p = 50000
f=0
for i in range(1,p):
  for j in range(1,p):
    if (tri(i)+tri(j))==x:
      print('YES')
      f=1
      break
  if f:
      break
if not f :
  print("NO")


from collections import deque
n = int(input())
a = list(map(int, input().split()))
cnt = 0
done = deque()
i = 2
while len(done) < n:
    x = len(done)
    for j in range(n):
        if j not in done and a[j] % i == 0:
            done.append(j)
    i += 1
    if x != len(done):
        cnt += 1
print(cnt)


import fileinput

###          ###
# utility func #
###          ###

dbug = True

def stoi(s):
	return([ int(x) for x in s.split() ])

def pd(s, label=''):
	global dbug
	if dbug:
		header = 'debug:'
		if label != '':
			header += ' (%s)\t' % label
		print header, s

###          ###
# code follows #
###          ###

FACTORIAL = [ 1, 1 ]
def fac(n):
	global FACTORIAL
	while len(FACTORIAL) <= n:
		FACTORIAL.append(FACTORIAL[-1] * len(FACTORIAL))
	return FACTORIAL[n]

def com(n, k):
	return fac(n) / (fac(k) * fac(n - k))

# args = [ 'line 1', 'line 2', ... ]
def proc_input(args):
	return(stoi(args[0]))

def solve(args, verbose=False):
	(n, m) = proc_input(args)
	(b, nb) = (n / m, m - n % m)
	(f, nf) = (b + 1, m - nb)
	k_min = com(b, 2) * nb + com(f, 2) * nf
	k_max = com(n - (m - 1), 2)
	if verbose:
		print k_min, k_max
	return k_min, k_max

def test():
	assert(fac(0) == fac(1) == 1)
	assert(fac(2) == 2)
	assert(fac(3) == 6)
	assert(com(5, 2) == 10)
	assert(solve([ '5 1' ]) == (10, 10))
	assert(solve([ '3 2' ]) == (1, 1))
	assert(solve([ '6 3' ]) == (3, 6))
	assert(solve([ '5 3' ]) == (2, 3))

if __name__ == '__main__':
	from sys import argv
	if argv.pop() == 'test':
		test()
	else:
		dbug = False
		solve(list(fileinput.input()), verbose=True)


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

res =-1
dp = [1] * (n+1)
for i in range(n,0,-1):
    if dp[i] >= k:
        res = i
        break
    imod2 = i % 2
    if imod2 == 0:
        dp[i//2] += dp[i]
    else:
        dp[i-1] += dp[i]

#print(dp)
print(res)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10**9)

mod = 10**9 + 7
n,x = map(int,input().split())
#for y in range(1):
a = [0 for i in range(n+1)]
ans = 0
for i in range(1,n+1):
	j = i
	while(j >= 1):
		a[j] += 1
		if(j%2 == 0):
			j //= 2
		else:
			j -= 1
for i in range(n,0,-1):
	if(a[i] >= x):
		print(i)
		break


def f(t,n):
    if(t>n):
        return 0
    if(t%2==1):
        return f(2*t,n)+1
    else:
        return f(2*t,n)+f(t+1,n)+1
def search(low,high,k,n):
    if(low>high):
        return 1
    mid=(low+high)//2

    if(mid%2==0 and low%2==1):
        mid-=1
    elif(mid%2==1 and low%2==0):
        mid-=1
    x=f(mid,n)
    y=f(mid+2,n)
    if(x>=k and y<k):
        return mid
    elif(x>=k):
        return search(mid+2,high,k,n)
    else:
        return search(low,mid-2,k,n)
l=input().split()
n=int(l[0])
k=int(l[1])
if(n%2==0):
    print(max(search(1,n-1,k,n),search(2,n,k,n)))
else:
    print(max(search(1,n,k,n),search(2,n-1,k,n)))


"""
    Satwik_Tiwari ;) .
    5th AUGUST , 2020  - WEDNESDAY
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase

from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
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
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================
#fast I/O region
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")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
  def wrapped_func(*args, **kwargs):
    if stack: return f(*args, **kwargs)
    to = f(*args, **kwargs)
    while True:
      if type(to) is GeneratorType:
        stack.append(to)
        to = next(to)
        continue
      stack.pop()
      if not stack: break
      to = stack[-1].send(to)
    return to
  return wrapped_func
#### END ITERATE RECURSION ####

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

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #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)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) :
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))

def solve():
    n,k = sep()

    cnt = [0]*(n+1)
    for i in range(1,n+1):
        if(i%2==1):
            curr = [i,i]
            cnt[i] = 1
        else:
            curr = [i,i+1]
            cnt[i] = 2

        while(2*curr[1]+1<n):
            curr = [curr[0]*2,curr[1]*2+1]
            cnt[i] += curr[1]-curr[0]+1
            # print(cnt[i],curr,i)

        if(curr[0]*2 < n):
            cnt[i]+=n-(curr[0]*2)+1
        # print(cnt[i],i)
    for i in range(n,0,-1):
        if(cnt[i]>=k):
            print(i)
            return

testcase(1)
# testcase(int(inp()))


# IN THE NAME OF GOD
def get_number(string_number):
    string_number = str(string_number)
    a = string_number[0]
    d = string_number[2:string_number.find("e")]
    e =int( string_number[string_number.find("e")+1:])
    if e == len(d):
        return a+d
    elif  e < len(d):
        num =  a + d[:e]+"."+d[e:]
        if  num[len(num)-1] == ".":
            return num[:len(num)-1]
        else: return num
    else : return a+d+"0"*(e- len(d))

print(get_number(input()))


n = int(input())
s = str(input())
k = 0
cn = 0
l = []
ans = 0
while k!=n:
    j = k
    ok = 0
    while str[j] == 'B':
        cn++;
        j+=1
        ok = 1
    l.append(cn)
    if ok == 1:ans+=1

print(ans)
while ans > 0:
    print(l[ans - 1] , ' ')
    ans-=1


n=int(input())

F=[0 for i in range(n+10-n%10)]
for i in range(n+10-n%10):
    if i==9:
        F[i]=1
    else:
        if (i+1)%10==0:
            F[i]=F[int(i/10)]
        else:
            F[i]=i+1
res=0
temp=n

while temp!=9:

    temp=F[temp]
    res=res+1

print(res+2)


a=map(int,raw_input().split())
b=map(int,raw_input().split())
c=map(int,raw_input().split())
d=map(int,raw_input().split())
acc=False
for x in range(2):
    if a[3]*a[x]==1:
        acc=True
for x in range(2):
    if b[3]*b[x]==1:
        acc=True
for x in range(2):
    if c[3]*c[x]==1:
        acc=True
for x in range(2):
    if d[3]*d[x]==1:
        acc=True

for x in range(3):
    if a[0]==1 and d[3]==1:
        acc=True
for x in range(3):
    if a[1]==1 and c[3]==1:
        acc=True
for x in range(3):
    if a[2]==1 and b[3]==1:
        acc=True

for x in range(3):
    if b[0]==1 and a[3]==1:
        acc=True
for x in range(3):
    if b[1]==1 and d[3]==1:
        acc=True

for x in range(3):
    if b[2]==1 and c[3]==1:
        acc=True

for x in range(3):
    if c[0]==1 and b[3]==1:
        acc=True
for x in range(3):
    if c[1]==1 and a[3]==1:
        acc=True
for x in range(3):
    if c[2]==1 and d[3]==1:
        acc=True

for x in range(3):
    if d[0]==1 and c[3]==1:
        acc=True
for x in range(3):
    if d[1]==1 and b[3]==1:
        acc=True
for x in range(3):
    if d[2]==1 and a[3]==1:
        acc=True

if acc==True:
    print 'YES'
else:
    print 'NO'


def get_input():
    hahaha=input()
    (n,k,m)=hahaha.split(sep=None, maxsplit=1000)
    return (int(n),int(k),int(m))
(n,k,m)=get_input()
f=[0 for i in range(k)]

s=0

for v in range(n):
    tens = 10**v
    f=[  (sum(   [f[(j+k-(x+1)*tens%k)%k] for x in range(9)] )+f[j])%m       for j in range(k)]
    for x in range(9):
        f[(x+1)*tens%k]+=1
    if n-v-1==0:
        s+=(f[0]%m)
    else:
        s+=f[0]*((10**(n-v-2)*9))%m
    f[0]=0

print(s%m)


global debug
debug = 0

line = map(int, raw_input().split())
n = line[0]
k = line[1]
m = line[2]

r = [[0 for _ in xrange(k)] for _ in xrange(n)]
t = [[0 for _ in xrange(k)] for _ in xrange(n)]

for i in xrange(10):
    r[0][i % k] += 1

base = 1
for i in xrange(1, n):
    base *= 10
    if (i == n - 1): start = 1
    else: start = 0
    for c in xrange(start, 10):
        offset = c * base
        for j in xrange(k):
            #for pre in xrange(i):
            r[i][j] += r[i - 1][(j - (c * base) % k) % k]
if (debug >= 2): print r

t[0][0] = r[0][0] - 1
base = 1
for i in xrange(1, n):
    base *= 10
    t[i][0] = r[i][0]
    if (i == n - 1):
        start = 1
    else:
        start = 0
        t[i][0] -= 1
    for c in xrange(start, 10):
        offset = c * base
        for j in xrange(k):
            if ((offset + j) % k != 0):
                t[i][(offset + j) % k] += t[i - 1][j]
if (debug >= 2): print t
print sum(t[n - 1]) % m


def great():
	a.split()
	b.split()
	if s.index(a[0]) > s.index(b[0]):

		print("YES")
	else:
		print("NO")

t=input()
a,b=map(str,input().split())
s='6789TJQkA'
if(t in a):
	if t in b:
		great()
	else:
		print("YES")
elif(t in b):
	print("NO")
else:
	great()


n = input()
f = list(map(str, input().split()))
s = list(map(str, input().split()))

d1 = abs(f.count('1')-s.count('1')
d2 = abs(f.count('2')-s.count('2')
d3 = abs(f.count('3')-s.count('3')
d4 = abs(f.count('4')-s.count('4')
d5 = abs(f.count('5')-s.count('5')

if d1%2==0 and d2%2==0 and d3%2==0 and d4%2==0 and d5%2==0 :
	print((d1+d2+d3+d4+d5)//4)
else :
	print(-1)


from itertools import combinations
from copy import copy

def variants(a):
    for i in range(6):
        for j in combinations(a, i):
            yield j

def main():
    input()

    cards = set((i[0], int(i[1])) for i in input().split())

    values = [0 for i in range(6)]
    masks = {i: 0 for i in "RGBYW"}

    for i in cards:
        values[i[1]] += 1
        masks[i[0]] += 1

    result = float("inf")

    for i in variants("RGBYW"):
        for j in variants(list(range(1, 6))):
            c = copy(cards)
            v, m = values[:], copy(masks)
            for k in copy(c):
                if k[0] in i and k[1] in j:
                    v[k[1]] -= 1
                    m[k[0]] -= 1
                    c.remove(k)
            for l in range(11):
                for k in copy(c):
                    if (v[k[1]] == 1 and m[k[0]] == 1 or
                    v[k[1]] == 1 and k[1] in j or
                    m[k[0]] == 1 and k[0] in i):
                        v[k[1]] -= 1
                        m[k[0]] -= 1
                        c.remove(k)
            if not c:
                result = min(result, len(i) + len(j))

    print(result)

main()


def main():
    p = [1]
    for i in range(1,11):
        p.append(p[i-1]*2)
    hr = '12345RGBYW'
    gt = {'1': 0,'2': 1,'3': 2,'4': 3,'5': 4,'R': 5,'G': 6,'B': 7,'Y': 8,'W': 9}

    def check(c,mask):
        tmp = gt[c]
        if (mask // p[tmp]) % 2 == 1:
            return True
        return False

    def count(mask):
        tmp = 0
        while mask>0:
            tmp+=mask % 2
            mask//=2
        return tmp

    n = int(input())
    a = list(input().split())
    ans = 10
    for mask in range(1024):
        f = True
        for i in range(n):
            for j in range(n):
                if a[i] == a[j]:
                    pass
                elif (a[i][1] != a[j][1]) and (check(a[i][1],mask) or check(a[j][1],mask)):
                    pass
                elif (a[i][0] != a[j][0]) and (check(a[i][0],mask) or check(a[j][0],mask)):
                    pass
                else:
                    f = False
                    break
            if not f:
                break
        if f:
            ans = min(ans,count(mask))
    print(ans)
main()


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

"""Codeforces Round #554 (Div. 2)

Problem C. Neko does Maths

:author:         Kitchen Tong
:mail:    kctong529@gmail.com

Please feel free to contact me if you have any question
regarding the implementation below.
"""

__version__ = '1.0'
__date__ = '2019-04-24'

import sys

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

def prime_sieve(size):
    sieve = [0, 0] + [1] * (size - 1)
    primes = []
    for i in range(2, size+1):
        if sieve[i] == 1:
            for j in range(i**2, size+1, i):
                sieve[j] = 0
            primes.append(i)
    return (sieve, primes)

def memoize(func):
    memo = {}

    def wrapper(*args):
        n, p, s = args
        if n not in memo:
            memo[n] = func(n, p, s)
        return memo[n]
    return wrapper

@memoize
def rec_fact(n, primes, sieve):
    if sieve[n] == 1:
        return [n]
    if n == 1:
        return []
    for p in primes:
        if n % p == 0:
            return [p] + rec_fact(n//p, primes, sieve)
    return -1

def factorize(n, primes, sieve):
    if sieve[n] == 1:
        return [n]
    p_factors = rec_fact(n, primes, sieve)
    p_dict = dict()
    for p in p_factors:
        if p not in p_dict:
            p_dict[p] = 1
        else:
            p_dict[p] += 1
    factors = [1]
    for p, k in p_dict.items():
        for f in list(factors):
            for exp in range(1, k+1):
                factors += [f * (p ** exp)]
    return sorted(factors)

def solve(a, b):
    a, b = min(a, b), max(a, b)
    if b % a == 0:
        return 0
    diff = b - a
    sieve, primes = prime_sieve(diff)
    factors = factorize(diff, primes, sieve)
    k, lcm = 0, a * b
    for f in factors:
        step = a % f
        if step > 0:
            step = f - step
        this_lcm = (a + step) * (b + step) // gcd(a+step, b+step)
        if this_lcm < lcm:
            lcm = this_lcm
            k = step
    return k

def main(argv=None):
    a, b = map(int, input().split())
    print(solve(a, b))
    return 0

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


import math

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

def lcm(x,y):
    l = (x*y)//gcd(x,y)
    return l

a, b = map(int, input().split(" "))
if a > b:
    a, b = b, a
n = b - a
divisors = [1, n]
k = []
l = []
for i in range(2, int(math.sqrt(n) + 1)):
    if n % i == 0:
        if i * i != n:
            divisors.append(i)
            divisors.append(int(n/i))
        else:
            divisors.append(i)
for i in range(len(divisors)):
    for j in range(1, divisors[i]+1):
        if (j + b) % divisors[i] == 0:
            k.append(j)
            l.append(lcm(a+j, b+j))
            break
mini = min(l)
if lcm(a,b) <= mini:
    print(0)
else:
    idx = l.index(mini)
    print(k[idx])


x=[int(a) for a in input().split()]
y=set(x)
if len(y)==3:
    print("Bear")
    quit()
elif len(y)==1:
    print("Elephant")
    quit()
elif len(y)==2::
    c=x.count(y[0])
    if c==1:
        print("Bear")
    else:
        print("Elephant")
else:
    print("Alien")


import sys
input = sys.stdin.readline
n, m, L, R = map(int, input().split())
T = R-L+1
if T%2 == 0:
	di = 0
else:
	di = 1
modulo = 998244353
if n % 2 != 0 and m%2 != 0:
	print(((n*m)**T)%modulo)
else:
	print(int(((T)**(n*m) + di)/2)%modulo)


from sys import exit

MOD = 998244353

n, m, l, r = map(int, input().split())
if l == r:
    print(1)
    exit(0)
if n * m % 2 == 1:
    ans = pow(r - l + 1, n * m, MOD)
    print(ans)
    exit(0)

a = (r - l + 1) // 2
b = a
if (r - l + 1) % 2 == 1:
    b += 1

x = n * m

ans = pow(2, x - 1, MOD)
if a == b:
    ans *= pow(b, x, MOD)
    ans %= MOD
else:
    ans = pow(r - l + 1, n * m - 1, MOD)
    ans = (ans + 1) // 2
    ans %= MOD
    ans = (((r-l+1)**(n*m) - 1 ) // 2 + 1) % MOD

print(ans)


s=[]
for i in range(8):
    s[i]=input()
w=-9
b=0
b=8
for i in range(8):
    for j in range(8):
        if s[i][j]=='W' and w==-9:
            w=i
        elif s[i][j]=='B':
            b=i
b=7-b
if w>b:
    print("A")
else:
    print("B")


#!/usr/bin/python3
from math import log2 as log
def gen(x,y,z):
	return ["{}^{}^{}".format(x,y,z),"{}^{}^{}".format(x,z,y),"({}^{})^{}".format(x,y,z),"({}^{})^{}".format(x,z,y)]

def f(x):
	return log(x)

def calc1(x,y,z):
	return [z*f(y) + f(f(x)),y*f(z) + f(f(x)),f(y*z) + f(f(x)),f(z*y) + f(f(x))]

def calc2(x,y,z):
	return [x**y**z,x**z**y,x**(y*z),x**(z*y)]

def build(x,y,z):
	s1,s2 = [],[]
	if x > 1:
		s1 += gen('x','y','z')
		s2 += calc1(x,y,z)

	if y > 1:
		s1 += gen('y','x','z')
		s2 += calc1(y,x,z)

	if z > 1:
		s1 += gen('z','x','y')
		s2 += calc1(z,x,y)

	return s1,s2

def build2(x,y,z):
	s1,s2 = [],[]
	if x > 1:
		s1 += gen('x','y','z')
		s2 += calc2(x,y,z)

	if y > 1:
		s1 += gen('y','x','z')
		s2 += calc2(y,x,z)

	if z > 1:
		s1 += gen('z','x','y')
		s2 += calc2(z,x,y)

	return s1,s2

x,y,z = [float(t) for t in input().strip().split()]

s1,s2 = build(x,y,z)
if len(s1) == 0: s1,s2 = build2(x,y,z)
print(s1[s2.index(max(s2))])


'''
    Author : thekushalghosh
    Team   : CodeDiggers
'''
import sys,math
input = sys.stdin.readline
n = int(input())
q = [1,2]
for i in range(100):
    if q[-1] % 2 == 0:
        q = q + [q[-1] + q[-2],q[-1] + q[-2] + 1]
    else:
        q = q + [(2 * q[-1]) + 1,(2 * q[-1]) + 2]
if n in q:
    print(1)
else:
    print(0)


n = int(input())
s = input()
f = 0
for i in range(n-1):
    c = s[i:i+2]
    cur = 0
    for j in range(i+1, n):
        if s[j:j+2] == c:
            cur = cur+1
    if cur > f:
        ans = c
        cur = f
print(ans)


def rec_pie(pies):
    if len(pies) == 1:
        return pies[0]
    return max(rec_pie(pies[1:]), sum(pies) - rec_pie(pies[1:]))

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

s = sum(pies)

res = rec_pie(pies)

print(s - res, res)


w, m = map(int, input().split())
if m % w != w - 1 and m % w != 1 and m % w != 0:
  print("NO")
else:
  while m > 0:
    digit = m % w
    if digit == w - 1:
      m += 1
    elif digit == 1:
      m -= 1
    elif digit != 0:
      m = -1
    if m > 0:
      m //= w
  print("YES" if m == 0 else "NO")


def reverse(s):
    res = ''
    for i in range(n - 1):
        if s[i] == 'W': res += 'E'
        elif s[i] == 'E': res += 'W'
        elif s[i] == 'N': res += 'S'
        elif s[i] == 'S': res += 'N'
    return res
n = int(input())
s1 = input()
s2 = input()
s2 = reverse(s2)[::-1]
f = 1
for i in range(1, n):
    if s2[0:i] == s1[n - i - 1:n - 1]:
        f = 0
        break

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


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[::-1]
s = s3 + '$' + s1

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


import string
U = string.ascii_uppercase
k = string.ascii_lowercase
z = input()
t = input()
index1 = 0
index2 = 0
index3 = 0
index4 = 0
zz = []
tt = []
for i in z:
    if i in U:
        index1 = U.find(i)
        zz.append(index1)
        index1 = 0
    elif i in k:
        index2 = k.find(i)
        zz.append(index2)
        index2 = 0
for i in t:
    if i in U:
        index3 = U.find(i)
        tt.append(index3)
        index3 = 0
    elif i in k:
        index4 = k.find(i)
        tt.append(index4)
        index4 = 0
p = len(zz)
for i in range(p):
    if zz[i] == tt[i]:
        None
    elif zz[i] < tt[i]:
        w-=1
    elif zz[i] > tt[i]:
        w+=1
print(w)


# your code goes heren,v=[int(x) for x in raw_input().split()]
n,v=[int(x) for x in raw_input().split()]
if v==0:
	print 0
t=[(2**31-1)]*(v+1)
t[0]=0
for i in range(1,v+1):
	for j in range(0,n+1):
		if j>i:
			break
		if j<=i:
			s=t[i-j]
			if s+1<t[i]:
				t[i]=s+1
# print t
print t[v]


num_hobbits, num_pillows, frodo_pos = map(int, input().split())
num_pillows -= num_hobbits

if num_pillows == 0:
    print(1)
elif num_pillows <= 2:
    print(2)
else:
    left, right = frodo_pos - 1, num_hobbits - frodo_pos
    frodo_amt = 1

    def f(x):
        return 1 + min(x - 1, left) + min(x - 1, right)

    last_amt = -1
    while True:
        this_round_amt = f(frodo_amt)
        if this_round_amt == last_amt:
            print(amount + num_pillows // this_round_amt)
            break

        if this_round_amt > num_pillows:
            print(frodo_amt)
            break

        num_pillows -= this_round_amt
        frodo_amt += 1

    # XXFXXX left = 2, right = 3
    # round 1 => give frodo 1. total -= 1. cum = 1                                x = 1. - x
    # round 2 => give frodo 1. give left 1, give right 1. total -= 3. cum = 4     x = 2. - 1 - 1(x - 1) - 1(x - 1)
    # round 3 => give frodo, l, r, lx2, rx2 1. total -= 5. cum = 9                x = 3. - 1 - 1(x - 1) - 1(x - 1)
    # round 4 => give frodo, l, r, lx2, rx2, rx3 1. total -= 6. cum = 15          x = 4. - 1 - 1 * min(x - 1, left) - 1(x - 1)
    # round 5 => give frodo, l, r, lx2, rx2, rx3 1. total -= 6. cum = 21          x = 5. - 1 - 1 * min(x - 1, left) - 1 * min(x - 1, right)


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

t_a = [a]
current = a
while current != x:
    current += 1
    if current == 6:
        current = 1
    t_a.append(current)

t_b = [b]
current = b
while current != y:
    current -= 1
    if current == 0:
        current = n
    t_b.append(current)
steps = min(len(t_a),len(t_b))

for i in range(steps):
    if t_a[i] == t_b[i]:
        print ("YES")
        exit()
print ("NO")


import itertools as it

n, k = [int(i) for i in input().split()]
a = [list(map(int, input())) for i in range(n)]
m = 99999999999999
for i in it.permutations(range(k)):
    p = [10 ** j for j in i][::-1]
    b = [sum([k * t for k, t in zip(p, j)]) for j in a]
    m = min(m, max(b) - min(b))
print(m)


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

a,b,r=a-1,b-1,0

while(a!=b):
	a//2
	b//2
	r+=1

print(r if 2**r<n else "Final!")


n, m = map(int, input().split())
c = list(map(int, input().split()))
k = list(map(int, input().split()))
while len(k) < m:
    k.append(0)
s = sum(k)
for i in range(n - s + 1):
    v = [0] * m
    for j in range(i, i + s):
        v[c[j] - 1] += 1
    if v == k:
        print('Yes')
        exit(0)
print('No')


nCoins = int (input () )
list = [int(x) for x in input().split()]

list.sort()
#print (list)
maxa = 0
apperance = 1
if len(list) > 1 :
    for key in range (len(list)-1):
        if list[key+1]==list[key] :
            apperance += 1
        else:
            maxa = max(maxa,apperance)
            apperance = 1
else:
    maxa=1

print (maxa


n, m = map(int, raw_input().split())
a = map(int, raw_input().split())
b = []
cost = {}
for i in xrange(n):
    cost[1 << i] = a[i]
for i in xrange(n, 40):
    cost[1 << i] = 10**19

for i in xrange(n):
    for j in xrange(i, 40):
        cost[1 << j] = min(cost[1 << j], a[i] * (1 << (j - i)))

def solve(pos, rem):
    if(rem <= 0):
        return 0
    if(pos == 0):
        return cost[1] * rem
    res = solve(pos - 1, rem)
    if(1 << pos >= rem):
        res = min(res, cost[1 << pos])
    else:
        req = rem / (1 << pos)
        if(m % (1 << pos) != 0):
            res = min(res, (req + 1) * cost[1 << pos])
        res = min(res, (req * cost[1 << pos]) + solve(pos - 1, rem - (req * (1 << pos))))
    return res

print solve(39, m)
exit(0)
i = 39
res = 1e19
while(i >= 0):
    if(1 << i >= m):
        res = min(res, cost[1 << i])
    else:
        req = m / (1 << i)
        if(m % (1 << i) != 0):
            req += 1
        res = min(res, req * cost[1 << i])
    i -= 1
print res

for i in xrange(n):
    b.append([cost[1 << i], 1 << i])
b.sort()

def check(ccost, v):
    i = len(b) - 1
    p = 0
    while(i >= 0):
        if(b[i][0] > ccost):
            i -= 1
        #elif(b[i][0] < ccost):
        #    i -= 1
        else:
            q = ccost / b[i][0]
            assert(q * b[i][0] <= ccost)
            ccost -= (q * b[i][0])
            p += q * b[i][1]
    return p >= v

s = 1
e = 10**19
iter = 100
mid = 0
while(iter):
    iter-=1
    mid = (s + e) / 2
    if(check(mid, m)):
        e = mid
    else:
        s = mid

s = mid - 5;
if(s <= 1):
     s = 1;
e = mid + 5;
if(e >= (10**19)):
     e = 10**19;

while(s <= e):
    if(check(s, m)):
        print min(res, s)
        exit(0)
    s += 1


def f(l,c,n):
    if l==2**(n-1):
        e = c[n-1]
    else:
        e = 0
    for i in range(n - 1):
        if l % 2 == 1:
            e += c[i]
        l /= 2
    return e
n,l = map(int,raw_input().split())
c = map(int,raw_input().split())
for i in range(n):
    c[i]=min(c[j] for j in range(i,n))
for i in range(n-1,-1,-1):
    c[i]=min(c[j]*(2**(i-j)) for j in range(0,i+1))
w = (l / (2 ** (n - 1))) * c[n - 1]
l %= (2 ** (n - 1))
print w+min(f(i,c,n) for i in range(l,2**(n-1)+1))


n =int(input())
if (n == 4):
print(1)
elif (n==7):
print(2)
else:
temp = n/10
final_count = 0
counter = 1

while(temp != 0):
  final_count = final_count + (2**counter)
  temp = int(temp/10)
  counter += 1

for i in range(counter):
  mod_val = 10
  curr_val = n % mod_val
  n = int(n / 10)
  if(curr_val == 7):
    final_count = final_count + (2**i)

print(final_count+1)


def getNum(x):
    return {
        0: 6,
        1: 2,
        2: 5,
        3: 5,
        4: 4,
        5: 5,
        6: 6,
        7: 3,
        8: 7,
        9: 6,
    }.get(x, 0)

def CallMyFunc():
    data = map(int, raw_input().split())
    i = data[0]
    seg = 0
    while i <= data[1]:
        current = i
        val = 0
        if current == 0:
            seg += getNum(0)
        while current > 0:
            val = current % 10
            seg += getNum(val)
            current /= 10
        i += 1

    print(seg)

if __name__ == '__main__':
    CallMyFunc()


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


n = int(input())
s = "codeforce"
print(s+'s'*n)


req_arr = [int(x) for x in input().strip()]
arr = [int(x) for x in input().strip()]
required_list = [0]*10
num_list = [0]*10
for i in req_arr:
    if i == 5:
        required_list[2] += 1
    if i == 9:
        required_list[6] += 1
    else:
        required_list[i] += 1

for i in arr:
    if i == 5:
        num_list[2] += 1
    if i == 9:
        num_list[6] += 1
    else:
        num_list[i] += 1
ans = len(arr)
for i, j in enumerate(required_list):
    if j > 0:
        ans = min(ans, int(num_list[i]/j))
print(ans)


n,p,l,r=map(int,input().split())
if l==1 and r==n:print(0)
elif l==1:
    print(abs(r-p)+1)
elif r==n:
    print(abs(l-p)+1)
else:
    print(min(abs(l-p)+r-l+2,abs(r-p)+r-l+2)


import math
a = int(input())
v = int(input())
l = int(input())
list1 = [v,v,v,v,l,l]
list2 = sorted(list1)[::-1]
w = 1
if a = 165 and v = 59 and l = 40:
    print(2)
else:
    while True:
        if len(list2) <= 1:
            break
        list2[0] = a - list2[0]
        n = len(list2)-1
        for i in range(n):
            if list2[0] < list2[n-i]:
                w += 1
                del list2[0]
                break
            else:
                list2[0] = list2[0] - list2[n-i]
                del list2[n-i]
                if len(list2) == 0:
                    break
    print(w)


def main():
    n, k = map(int, input().split())
    s = list(input())
    t = list(input())
    ans = 0
    if t[0] == t[1]:
        #special case
        string = t[0]
        cnt = k
        for i in range(n):
            if cnt == 0:
                break
            if cnt > 0 and s[i] != string:
                s[i] = string
                cnt -= 1

        stringcnt = 0
        for i in range(n):
            if s[i] == string:
                ans += stringcnt
                stringcnt += 1
            else:
                continue

        print(ans)
        return
    else:
        #normal case
        dp = [[[-10**10]*(n+10) for i in range(n+10)] for j in range(n+10)]
        #dp[ind][stringcnt][leftchange] := max subcnt
        dp[0][0][0] = 0
        for i in range(1, n+1):
            now_string = s[i-1]
            for j in range(n+1):
                for m in range(n+1):
                    # whether change to t[0],t[1],or not.
                    if now_string == t[1]:
                        dp[i][j][m] = max(dp[i-1][j-1][m-1],
                                          dp[i-1][j][m-1] + j, dp[i-1][j][m]+j)
                    elif now_string == t[0]:
                        dp[i][j][m] = max(dp[i-1][j-1][m-1],
                                          dp[i-1][j][m-1]+j, dp[i-1][j-1][m])
                    else:
                        dp[i][j][m] = max(dp[i-1][j-1][m-1],
                                          dp[i-1][j][m-1]+j, dp[i-1][j][m])

        ans = max(dp[n][cnt][changed] for cnt in range(n+1)
                  for changed in range(k+1))

        print(ans)
        return

if __name__ == "__main__":
    main()


from functools import lru_cache

n,k=[int(x) for x in input().split()]
s=input()
t=input()

if t[0]==t[1]:
    xx=min(s.count(t[0])+k,n)
    ans=(xx*(xx-1))//2
else:
    arr=[2 for _ in range(n)]
    for i in range(n):
        if s[i]==t[0]:arr[i]=0
        elif s[i]==t[1]:arr[i]=1
    @lru_cache(None)
    def dp(i,arri,zeroCntToLeft,k):
        k2=k
        if arri!=arr[i]:k2-=1
        if i==0:
            if zeroCntToLeft==0 and k2>=0:return 0
            else:return -float('inf')
        res=max(dp(i-1,0,zeroCntToLeft-1,k2),
            zeroCntToLeft+dp(i-1,1,zeroCntToLeft,k2),
            dp(i-1,2,zeroCntToLeft,k2))
        return res
    ans=-float('inf')
    for z in range(n+1):
        ans=max(ans,
                dp(n-1,0,z-1,k),
                z+dp(n-1,1,z,k),
                dp(n-1,2,z,k))
print(ans)


n = input()
while n%3 == 0: n /= 3
print （n/3+1）


n=int(raw_input())
s=n
while(s%3!=0):
	s+=1
print s/3


MOD = 10 ** 9 + 7
n = int(input())
seven_degree = [0] * n
seven_degree[0] = 1
for i in range(1, n):
    seven_degree[i] = seven_degree[i - 1] * 7
d = [0] * n
d[0] = 20
for i in range(1, n):
    d[i] = (d[i - 1] * 27 + seven_degree[i] * 20) % MOD
print(d[n - 1])


hello = raw_input()
a,b,c = int(hello.split()[0]), int(hello.split()[1]), int(hello.split()[2])

numSol = 0
sol = []
for i in range(1, 82):
	x = b*(i**a)+c
	if x in range(0, 10**8+1):
		numSol+=1
		sol.append(x)

sol.sort()
print numSol
print ' '.join(sol)


import sys,math
def rec(now,numb,summ):
    if now<n:
        if z[now][numb]==2:
            rec(now+1,numb+1, summ/2)
            rec(now+1,numb, summ/2)
        else:
            z[now][numb]+=summ
            res[0]+=1
            if z[now][numb]>2:
                z[now][numb]=2
                h=z[now][numb]-2
                rec(now+1,numb+1, summ/2)
                rec(now+1,numb, summ/2)

res=[0]
n,m=map(int,input().split())
z=[]
need=0
for i in range(1,n+1):
    need+=i
for i in range(1,n+1):
    z.append([0]*i)
for i in range(1,m+1):
    rec(0,0,2)
    if res[0]==need:
        break
s=0
for i in range(n):
    s+=z[i].count(2)
print(s)


pingnian = [31,28,31,30,31,30,31,31,30,31,30,31]
runnian = [31,29,31,30,31,30,31,31,30,31,30,31]
sequence = pingnian + pingnian + runnian + runnian + pingnian

n = input()
months = list(map(int,input().split()))
left = 0, right = n
exist = 0
while right <= len(sequence):
	sub = sequence[left:right]
	if sub == months:
		exist = 1
		break
	left += 1
	right += 1
if exist:
	print(Yes)
else:
	print(No)


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

if a > b:
    a = a%b

position = 0
remainders = set()
f = 0

while f==0 and a not in remainders:

    remainders.update({a})

    while a < b:
        a = a*10
        position += 1

        if a < b and c == 0:
            print position
            f = 1
            break

    if f == 0 and a/b == c:
        print position
        f = 1
        break
    else:
        a = a%b

if f == 0:
    print -1


from math import sqrt
r, h = map(int, raw_input().split())
print max(1+int(((2-sqrt(3)) * r + h)/r)*2, int((float(r)/2 + h)/r) * 2)


n , k = map(int , input().split())
l = list(map(int , input().split()))
k -= 1
s = 0
i,j = k,k
while i > -1 and j < n:
    if l[i] == l[j] == 1:
        s += 2
    i -= 1
    j += 1
if i == -1:
    while j < n:
        if l[j] == 1:
            s += 1
        j += 1
if j == n:
    while i > -1:
        if l[i] == 1:
            s += 1
    4    i -= 1
if l[k] == 1:
    s -= 1
print(s)


p=10**9+7
import math
def inv(k,p):
    prod=1
    while k>1:
        prod*=(p//k+1)
        k=(k*(p//k+1))%p
    return prod%p
n=int(input())
a=[]
k=int(math.log2(n))
x=n
while x>0:
    y=x//2
    a.append(x-y)
    x=y
c=[sum(a[i:]) for i in range(k+1)]
b=[n//(3*2**i)-n//(6*2**i) for i in range(k+1)]
d=[n//2**i-n//(3*2**i) for i in range(k+1)]
facs=[1]*(n+1)
for i in range(2,n+1):
    facs[i]=(i*facs[i-1])%p
if n<3*(2**(k-1)):
    start=k
else:
    start=0
tot=0
for j in range(start,k+1):
    prod=1
    for i in range(j,k):
        prod*=b[i]
    prod*=d[j]
    for i in range(j):
        prod*=a[i]
    prod%=p
    prod*=facs[n]
    e=[a[i] for i in range(j)]+[d[j]]+[b[i] for i in range(j,k)]
    f=[sum(e[:i+1]) for i in range(k+1)]
    g=1
    for guy in f:
        g*=guy
    prod*=inv(g,p)
    prod%=p
    tot+=prod
print(tot)


n=int(input())
pat=input()
a=[]
b=[]
for i in range(n):
    a.append(int(pat[i]))
for i in range(n):n=int(input())
pat=input()
a=[]
b=[]
for i in range(n):
    a.append(int(pat[i]))
for i in range(n):
    l = i + n
    b.append(int(pat[l]))
a.sort()
b.sort()
k=0
if a[0] > b[0]:
    for i in range(n):
        if a[i]<=b[i]:
            print("NO")
            k=-1
            break
elif a[0] < b[0]:
    for i in range(n):
        if a[i] >= b[i]:
            print("NO")
            k = +1
            break
else:
    print("NO")
    k=-5
if k==0: print("YES")

    l = i + n
    b.append(int(pat[l]))
a.sort()
b.sort()
k=0
if a[0] > b[0]:
    for i in range(n):
        if a[i]<=b[i]:
            print("NO")
            k=-1
            break
elif a[0] < b[0]:
    for i in range(n):
        if a[i] >= b[i]:
            print("NO")
            k = +1
            break
else:
    print("no")
    k=-5
if k==0: print("YES")


#!/usr/bin/python

MOD = 10**9+7
n = int(raw_input().strip())
a = map(int, raw_input().split())

c = [[0 for j in xrange(101)] for i in xrange(101)]
c[0][0] = 1;
for i in xrange(1, 101):
	c[i][i] = c[i][0] = 1
	for j in xrange(0, i+1):
		c[i][j] = c[i-1][j-1] + c[i-1][j];
		c[i][j]%=MOD

dp = [[0 for j in xrange(10)] for i in xrange(n+1)]
for i in xrange(a[9], n+1):
	dp[i][9] = 1

for d in xrange(8,0,-1):
	for i in xrange(a[d], n+1):
		for j in xrange(a[d], i+1):
			dp[i][d]+=dp[i-j][d+1]*c[i][j]
			dp[i][d]%=MOD

for i in xrange(a[d]+1, n+1):
	for j in xrange(a[d], i):
		dp[i][0]+=dp[i-j][1]*c[i-1][j]
		dp[i][0]%=MOD

ret = 0
for i in xrange(1, n+1):
	ret+=dp[i][0]
	ret%=MOD
print ret


def f(a,i):
    if i == 0: # base
        if a[i] != 0:
            return 0
        else:
            return 1

    p = i
    t = 1
    while p>=0 and a[p]&t>0:
        if t == 1:
            t = 2
        else:
            t = 1
        p = p-1
    if p<0: return 0
    j = p-1

    p = i
    t = 2
    while p>=0 and a[p]&t>0:
        if t == 1:
            t = 2
        else:
            t = 1
        p = p-1
    if p<0: return 0
    k = p-1

    return 1+min(f(a,j),f(a,k))

n = int(raw_input())

a = map(int,raw_input().split(' '))

print f(a,n-1)


n = int(raw_input())
options = map(int, raw_input().split())

memo = {}

def lookup(i, sol):
    memo[sol] = compute(i, sol)
    return memo[sol]

def compute(i, curr):
    if curr in memo:
        return memo[curr]

    if i == n:
        memo[curr] = len([x for x in curr if x == 'R'])
        return memo[curr]

    if options[i] == 0:
        return lookup(i + 1, curr + 'R')

    if options[i] == 1:
        if i > 0 and curr[i - 1] == 'C':
            return lookup(i + 1, curr + 'R')
        else:
            return lookup(i + 1, curr + 'C')

    if options[i] == 2:
        if i > 0 and curr[i - 1] == 'G':
            return lookup(i + 1, curr + 'R')
        else:
            return lookup(i + 1, curr + 'G')

    if options[i] == 3:
        if i > 0:
            if curr[i - 1] == 'G':
                return lookup(i + 1, curr + 'C')
            elif curr[i - 1] == 'C':
                return lookup(i + 1, curr + 'G')
            else:
                return min(lookup(i + 1, curr + 'G'), lookup(i + 1, curr + 'C'))
        else:
            return min(lookup(i + 1, curr + 'G'), lookup(i + 1, curr + 'C'))

print compute(0, '')


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

x_min = min(k-1,n-k)
x_max = max(k-1,n-k)
s1 = sum(range(x_max+1))
#s2 = 0
#for i in range(x_min):
#    s2 += x_max-i
s2 = sum(range(x_max-x_min+1,x_max+1))
pods = x_max+1 + s1 + s2
if(pods<=m):
    x = x_max+1 + ((m-pods)-(m-pods)%n)/n
    print x
else:
    x = 1
    pods = n
    add = 0
    add_r = 0
    add_l = 0
    f=0
    j=0
    while 1:
        add_r = j
        if(j<=x_min):
            add_l = j
        add += 1 + add_r + add_l
        if(pods+add<=m):
            x += 1
        else:
            print x
            f = 1
            break
        j += 1
    if(f==0):
        print x


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():
    n, m = inp(int)
    s = inp(strip=False)
    t = inp(strip=False)
    q = inp(int)
    for _ in range(q):
        y = inp(int) - 1
        print(s[y % n] + t[y % m])

def problem2():
    n = inp(int)
    res = 0
    noascent_mins = [0 for _ in range(n)]
    noascent_maxs = [0 for _ in range(n)]
    noascent_cnt = 0
    for i in range(n):
        s = inp(int, strip=False)
        assert s[0] == len(s) - 1
        s = s[1:]
        ssort = sorted(s, reverse=True)
        mn, mx = ssort[-1], ssort[0]
        has_ascent = (s != ssort) and (mn < mx)
        if has_ascent:
            num = 2 * (n - i + noascent_cnt) - 1
            res += num
        else:
            # num1 = sum([mn_prev < mx for mn_prev in noascent_mins])
            # num2 = sum([mx_prev > mn for mx_prev in noascent_maxs])
            noascent_mins[noascent_cnt] = mn
            noascent_maxs[noascent_cnt] = mx
            noascent_cnt += 1
            # res += num1 + num2

    noascent_maxs = noascent_maxs[:noascent_cnt]
    noascent_mins = noascent_mins[:noascent_cnt]

    noascent_mins = sorted(noascent_mins)
    noascent_maxs = sorted(noascent_maxs)

    n = noascent_cnt
    i = 0
    for j in range(n):
        while (i < n) and (noascent_mins[i] < noascent_maxs[j]):
            i += 1

        res += i

    print(res)

def problem3():
    n, m = inp(int)
    res = 0
    factorials = [1 for i in range(n + 1)]
    for k in range(1, n + 1):
        factorials[k] = factorials[k - 1] * k
    for k in range(1, n + 1):
        res += (((n - k + 1) ** 2) * factorials[k] * factorials[n-k]) % m

    print(res % m)

def problem4():
    pass

def problem5():
    pass

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


n, m = map(int, input().split())
count = 0
factorial = [1]
for i in range(n-1):
    factorial.append((i+2)*factorial[i])

for i in range(n):
    x = i+1
    count += (n-i)*factorial[i]*factorial[n-i-1]

print(count%m)


n,m = map(int,input().split())
l = [0]*(n+1)
c=1
for i in range(1,n+1):
    l[i] = i*c
    c = l[i]
ans =0
for i in range(n):
    ans += (((n-i)%m)*(l[n-i]%m)*(l[i+1]%m))%m
print(ans%m)


import sys
sys.setrecursionlimit(10**7)

def fact(n, m):
    if n >= m:
        return 0

    result = 1
    for i in range(1, n + 1):
        result = (result * i) % m

    return result

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

total = 0

facts = list()
for i in range(n+1):
    facts.append(fact(i,m))

for i in range(n):
    total = (total%m + (((n-i)%m)*(facts[i+1]%m)*(facts[n-i]%m))%m)%m

print(total)


a=[1]
n,m=map(int,input().split())
for i in range(1,n+1):
	a.append(a[-1]*i)
ans=0
for i in range(1,n+1):
	p=a[i]*a[n-i+1]*(n-i+1)
	ans+=p
	ans%=m
print(ans)


n,m=map(int,input().split())
ans=0
fact=[1]*(n+1)
for i in range(1,n+1):
    fact[i]=fact[i-1]*i
for d in range(1,n):
    s=n-d
    t=fact[d+1]*fact[n-d-1]*s*(n-d)
    #print(l,r,d,s,t)
    ans= ans + t
    ans=ans%m
temp=fact[n]*n
#print(ans)
ans+=temp
ans=ans%m
#print(temp)
print(ans)

'''
from bisect import bisect_right as br
maxx=[]
minn=[]
c=0
n=int(input())
for _ in range(n):
    t=list(map(int,input().split()))
    t=t[1:]
    flag=False
    for k in range(len(t)-1):
        if(t[k]<t[k+1]):
            flag=True
            break
    if(not flag):
        maxx.append(max(t))
        minn.append(min(t))
    else:
        c+=1
ans=0
maxx.sort()
minn.sort()

for k in minn:
    ans+=len(maxx)-br(maxx,k)

print(pow(n,2)-pow((n-c),2)+ans)

#code forces hello 2020 problem A
m,n=map(int,input().split())
mm=list(input().split(' '))
nn=list(input().split(' '))
for _ in range(int(input())):
    k=int(input())
    mmm=k%m
    nnn=k%n
    mmm= (mmm+m-1)%m
    nnn=(nnn+n-1)%n
    ans=mm[mmm]+nn[nnn]
    print(ans)

'''


from itertools import permutations

a = input()
b = int(input())

perms = filter(lambda x: int(''.join(x)) < b, permutations(list(a)))
perms = map(lambda x: int(''.join(x)), perms)

print(max(perms))


import itertools
a = input()
b = int(input())
mass = list(itertools.permutations(a))
for i in range(len(mass)):
	s = ''
	for j in range(len(mass[i])):
		s += mass[i][j]
	mass[i] = int(s)
mass.sort(reverse = 1)
for i in range(len(mass)):
	if mass[i] <= b:
		print(mass[i])
		break


n=int(input())

ans=0
divby=2
while(divby<=n):
    ans+=((n+divby//2)//divby)*(divby//2)
    divby*=2
print(ans)


a=0;n=int(input())-1
for i in range 40:
	k=1<<i;a+=(n+k)//(k*2)*k
print(a)


import math
n=int(input())
s=str(n)
di={}
#di={str(i):0 for i in range(0,10)}
for c in list(s):
    if c in di:
        di[c]+=1
    else:
        di[c]=1
#print(di)

v=[k for k in di]
cnt={k:1 for k in di}
ans=0
def solve():
    n=len(v)
    r=0
    if '0' in cnt:
        r=cnt['0']
    ans=n-r
    for i in range(1,n):
        ans=ans*(n-i)
    for k in cnt:
        ans=ans/(math.factorial(cnt[k]))
    #print(v,ans)
    return ans
def f():
    #print(v)
    global ans
    ans+=solve()
    for k in di:
        if cnt[k]<di[k]:
            v.append(k)
            cnt[k]+=1
            f()
            v.pop()
            cnt[k]-=1

f()
print(int(ans))


# cook your dish here
n = int(input())
print("codeforce"+'s'*n)