You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.


-----Input-----

The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers.


-----Output-----

In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).


-----Examples-----
Input
2 15

Output
69 96

Input
3 0

Output
-1 -1

Difficulty: interview

Starter code:

Solutions:
M,S=list(map(int,input().split()))

if S==0 and M==1:
  print('0 0')
  return
elif S==0 or M*9 < S:
  print('-1 -1')
  return

m,s=M,S
l=[]
if s<=(m-1)*9+1:
  l.append(1)
  s-=1
while len(l)<m:
  r = (m-len(l)-1)*9
  if s<=r:
    l.append(0)
  else:
    l.append(s-r)
    s-=s-r

m,s=M,S
h=[]
while s>=9:
  h.append(9)
  s-=9
while len(h)<m:
  h.append(s)
  s=0

print(''.join(repr(x) for x in l), ''.join(repr(x) for x in h))



m, s = list(map(int, str.split(input())))
if s == 0 and m == 1:

    print(0, 0)

elif s == 0 or s > 9 * m:

    print(-1, -1)

else:

    num = [0] * (m - 1) + [1]
    for i in range(m):

        num[i] += min(9, s - sum(num))

    a = str.join("", list(map(str, num[::-1])))

    num = [0] * m
    for i in range(m):

        num[i] = min(9, s - sum(num))

    b = str.join("", list(map(str, num)))
    print(a, b)


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

# first we check if it is possible to build the numbers
mindsum = 1
maxdsum = 9*m

if (m == 1 and s == 0):
    print(0, 0)

elif s < mindsum or s > maxdsum:
    print(-1, -1)
else:
    mncount = s // 9
    mrest = s % 9
    # now there are three possibilities:
    if mncount == m:
        mnum = '9'*m
    elif mncount == m-1:
        if mrest == 0:
            mnum = '1' + '8' + '9'*(mncount-1)
        else:
            mnum = str(mrest) + '9'*mncount
    else:
        if mrest == 0:
            # format 1 000000 8 999999
            # 2 + zerocount + ninecount-1 = m
            zerocount = m - 2 - mncount + 1
            mnum = '1' + '0'*zerocount + '8' + '9'*(mncount-1)
        elif mrest == 1:
            # format 1 000000 9999999
            # 1 + zerocount + ninecount = m
            zerocount = m - 1 - mncount
            mnum = '1' + '0'*zerocount + '9'*mncount
        else:
            # format 1 000000 # 999999
            zerocount = m - 2 - mncount
            mnum = '1' + '0'*zerocount + str(mrest-1) + '9'*mncount

    # now we generate maximum number:
    # it will be full of nines in the beginning and then the rest filled with the largest numbers in the front
    # that's actually easy
    maxnum = ''
    t = s
    while (t >= 9):
        maxnum += '9'
        t -= 9
    if (mncount != m):
        maxnum += str(t)
        while (len(maxnum) != m):
            maxnum += '0'
    print(mnum, maxnum)


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


if a == 1 and b == 0:
    print("0 0")
    return
if b==0 or b>a*9:
    print("-1 -1")
    return

ob = b
ans = ""
for x in range(a):
    if ob >9:
        ob -= 9
        ans += "9"
    else:
        ans += str(ob)
        ob = 0
big = ans
ans = ""

ob = b
ob -= 1
for x in range(a):
    if ob >9:
        ob -= 9
        ans = "9" + ans
    else:
        ans = str(ob) + ans
        ob = 0

ans = chr( ord(ans[0]) + 1) + ans[1:]
print(ans, big)




n, s = map(int, input().split())
if(n==1 and s==0):
	print('0 0')
elif(9*n < s or s == 0):
	print('-1 -1')
else:
	res1 = 10**(n-1)
	for i in range(s-1):
		res1 += 10**(i//9)
	res2 = 0
	for i in range(s):
		res2 += 10**(n-1-i//9)
	print(res1, res2)


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

a = [0 for i in range(m)]
b = [0 for i in range(m)]

sa = s
i = m-1
while i>=0:
    if sa>9:
        a[i]=9
        sa = sa-9
    else:
        a[i]=sa
        sa = 0
    i -= 1

fail = sa>0    

if not fail:
    if m>1 and a[0]==0:
        a[0] = 1
        found = False
        for i in range(1,m):
            if a[i]>0:
                a[i] -= 1
                found = True
                break
        fail = not found

if fail:
    print(-1,-1)
else:
    sb = s
    for i in range(m):
        if sb>9:
            b[i]=9
            sb = sb-9
        else:
            b[i]=sb
            sb = 0    

    print('{0} {1}'.format(''.join(map(str,a)),''.join(map(str,b))))


    
##        print(' '.join(map(str,A[i])))
    


def find(step):
    if m ==1 and s == 0:
        return 0
    ss = s
    res = ''
    for i in range(m):
        j = 1 if i == 0 else 0
        ok = False       
        c = list(range(j, 10)) if step == -1 else reversed(list(range(j, 10)))        
        for v in c:
            if 0 <= ss-v <= (m-i-1)*9:
                ok = True
                ss -= v
                res += str(v)
                break
        if not ok:
            return -1        
    return res

m, s = list(map(int, input().split()))
print(find(-1), find(1))


__author__ = 'alexandrun'

import sys

#sys.stdin = open("p3.in", "r")

def process(m, s):
    if s == 0:
        if m == 1:
            return (0, 0)
        return (-1, -1)

    q = s // 9
    r = s % 9
    if r == 0:
        cifMin = q
    else:
        cifMin = q + 1

    #print(q, r, cifMin)
    if cifMin > m:
        return(-1, -1)

    if cifMin == m:
        if r == 0:
            return ("9" * q, "9" * q)

        min = str(r) + "9" * q
        max = "9" * q + str(r)
        return (min, max)

    if cifMin < m:
        #min
        min = "1"
        qmin = (s-1) // 9
        rmin = (s-1) % 9

        if rmin == 0:
            cifMin2 = qmin
        else:
            cifMin2 = qmin + 1
        #print(qmin, rmin, cifMin2)

        if cifMin2 == m - 1:
            if rmin > 0:
                min += str(rmin) + "9" * qmin
            else:
                min += "9" * qmin
        elif cifMin2 < m - 1:
            #print(qmin, rmin)
            if rmin > 0:
                min += "0" * (-cifMin2 + m - 1) + str(rmin) + "9" * qmin
            else:
                min += "0" * (-cifMin2 + m - 1) + "9" * qmin

        max = "9" * q + str(r) + (m - q - 1) * "0"
        return(min, max)

words = input().split()
m = int(words[0])
s = int(words[1])

res = process(m, s)
print(res[0], res[1])


m, s = map(int, input().split())
if s > m * 9:
    print(-1, -1)
elif s == 0:
    if m == 1:
        print(0, 0)
    else:
        print(-1, -1)
else:
    pos = 0
    lost = s
    minAns = ''
    while (m - pos - 1) * 9 > lost:
        if pos == 0:
            minAns += '1'
            lost -= 1
        else:
            minAns += '0'
        pos += 1
    if 9 * (m - pos) == lost:
        minAns += '9' * (m - pos)
    else:
        minAns += str(lost % 9) + '9' * (m - pos - 1)
    
    print(minAns, end = ' ')
    
    maxAns = ''
    lost = s
    pos = 0
    while lost - 9 >= 0:
        maxAns += '9'
        pos += 1
        lost -= 9
    if m - pos > 0:
        maxAns += str(lost)
        maxAns += '0' * (m - pos - 1)
    
    print(maxAns)


m, s = map(int, input().split())
#for m in range(1, 100):
#    for s in range(1, 100):
       # print(";;;;;;", s, m)
ar = [0] * m
ar[0] = 1
sum1 = 1
if m == 1:
    if s > 9:
        print('-1 -1')
    else:
        print(s, s)
else:
    dd = 0
    for i in range(m - 1, 0, -1):
        if sum1 <= s:
            ar[i] += 9
            sum1 += 9
        if sum1 > s:
            ar[i] -= sum1 - s
            sum1 -= sum1 - s
    if sum1 < s:
        ar[0] += s - sum1
    if ar[0] > 9:
        dd = 1
    min1 = ar[:]
    sum1 = 0
    ar = [0] * m
    ar[0] = 0
    for i in range(m):
        if sum1 <= s:
            sum1 += 9
            ar[i] += 9
        if sum1 > s:
            ar[i] -= sum1 - s
            sum1 -= sum1 - s
    if sum1 < s or dd == 1 or ar[0] == 0 or min(min1) < 0:
        print('-1 -1')
    else:
        print(''.join(map(str, min1)), ''.join(map(str, ar)))

from sys import stdin

lines = list([_f for _f in stdin.read().split('\n') if _f])

def parseline(line):
	return list(map(int, line.split()))

lines = list(map(parseline, lines))

m, s = lines[0]

if 9 * m < s or (m > 1 and s == 0):
	print("-1 -1")
	return

if m == 1 and s == 0:
	minimum = [0]
else:
	minimum = []
	s1 = s
	while s1 > 0:
		digit = min(9, s1)
		minimum.append(digit)
		s1 -= digit
	if len(minimum) < m:
		minimum[-1] -= 1
		minimum += [0] * (m - len(minimum) - 1)
		minimum.append(1)

minimum = "".join(map(str, reversed(minimum)))

maximum = []
s2 = s
while s2 > 0:
	digit = min(9, s2)
	maximum.append(digit)
	s2 -= digit
maximum += [0] * (m - len(maximum))

maximum = "".join(map(str, maximum))

print(minimum, maximum)


m,s=input().split()
m,s=int(m),int(s)
if 9*m<s or (s==0 and m!=1):
   print(-1,-1)
else:
   lis=[0 for i in range(m)]
   q=int(s//9)
   r=int(s%9)
   if s==0:
      print(0,0)
   elif m==1 and s==9:
      print(9,9)
   elif m==2 and s==18:
      print(99,99)
   elif q==m-1:
      for i in range(q):
         lis[i]='9'
      lis[m-1]=str(r)
      lis1=lis[:]
      if r!=0:
         print(int(''.join(lis[::-1])),int(''.join(lis)))
      else:
         print(int(''.join(['1','8']+lis[::-1][2:m])),int(''.join(lis1)))
   elif q<m-1:
      for i in range(q):
         lis[i]='9'
      lis[q]=str(r)
      for i in range(q+1,m):
         lis[i]='0'
      lis1=lis[:]
      if r!=0:
         lis[m-1]='1'
         lis[q]=str(r-1)
         print(int(''.join(lis[::-1])),int(''.join(lis1)))
      else:
         lis[m-1]='1'
         lis[q-1]='8'
         print(int(''.join(lis[::-1])),int(''.join(lis1)))
   else:
      for i in range(m):
         lis[i]='9'
      print(int(''.join(lis)),int(''.join(lis)))
                     
      


m, s = map(int, input().split())
if m == 1 and s == 0:
    print(0, 0)
    return
if (s == 0 and m > 1) or (s > m * 9):
    print(-1, -1)
else:
    n = (s - 1) // 9
    if n == m - 1:
        print(s - n * 9, '9' * n, sep = '', end = ' ')
        print('9' * n, s - n * 9, sep = '')
    else:
        print('1', '0' * (m - n - 2), s - n * 9 - 1, '9' * n, sep = '', end = ' ')
        print('9' * n, s - n * 9, '0' * (m - n - 1), sep = '')


'''
Created on 17-Nov-2014

@author: akash
'''
m, s = list(map(int, input().split()))
smin = s
lstmax = [0 for i in range(m)]
lstmin = [0 for i in range(m)]
for i in range(m):
    if s == 0:
        lstmax[i] = 0
    elif s >= 9:
        lstmax[i] = 9
        s -= 9
    else:
        lstmax[i] = s
        s = 0
if m == 1 and smin == 0:
    print(0, 0)
elif s == 0 and smin != 0:
    lstmin = lstmax[::-1]
    if lstmin[0] == 0:
        lstmin[0] = 1
        j = 1
        while lstmin[j] == 0:
            j += 1
        lstmin[j] -= 1
    for i in range(len(lstmin)):
        print(lstmin[i], end="")
    print(" ", end="")
    for i in range(len(lstmax)):
        print(lstmax[i], end="")
else:
    print(-1, -1)


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

min_num = [0] * m
if s == 0 and m == 1:
    print('0 0')
    return
if s == 0 or s > m * 9:
    print("-1 -1")
    return

ci = len(min_num) - 1
s1 = s
while s > 0:
    a = min(9, s)
    s -= a
    min_num[ci] = a

    ci -= 1


if min_num[0] == 0:
    min_num[0] = 1
    for i in range(1, len(min_num)):
        if min_num[i] > 0:
            min_num[i] -= 1
            break

max_num = [0] * m
ci = 0

while s1 > 0:
    a = 9 if s1 >= 9 else s1
    s1 -= a

    max_num[ci] = a

    ci += 1

print("".join(map(str, min_num)), "".join(map(str, max_num)))




__author__ = 'user'

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

if s == 0 and m > 1 or s > 9 * m:
    min_num = max_num = -1
elif m == 1:
    min_num = max_num = s
else:
    nns1 = s // 9
    d = s % 9
    max_num = '9' * nns1
    if nns1 != m:
        max_num += str(d) + '0' * (m - nns1 - 1)

    if s <= (m - 1) * 9:
        nns2 = (s - 1) // 9
        d = (s - 1) % 9
        min_num = '1' + '0' * (m - nns2 - 1 - 1)
        if nns2 != m:
            min_num += str(d) + '9' * nns2
    else:
        min_num = ''
        if s // 9 != m:
            min_num = str(s % 9)
        min_num += '9' * (s // 9)


print(min_num, max_num)

__author__ = 'Rakshak.R.Hegde'
m, s = map(int, input().split())
if m == 1 and s == 0:
    print('0 0')
else:
    if s / m > 9 or s == 0:
        print('-1 -1')
    else:
        # Smallest Number
        num = [9] * m
        psum = 9 * m
        minDiff = min(8, psum - s)
        num[0] -= minDiff
        psum -= minDiff
        for i in range(1, m):
            minDiff = min(9, psum - s)
            num[i] -= minDiff
            psum -= minDiff
            if psum == s:
                break
        n1 = ''
        for i in num:
            n1 += str(i)
        # Biggest Number
        num = [9] * m
        psum = 9 * m
        for i in range(-1, -m - 1, -1):
            minDiff = min(9, psum - s)
            num[i] -= minDiff
            psum -= minDiff
            if psum == s:
                break
        n2 = ''
        for i in num:
            n2 += str(i)
        print(n1 + ' ' + n2)

def solve(m, s):
    if (m, s) == (1,0):
        ret = "0 0"
    elif s > 9*m or s == 0:
        ret = "-1 -1"
    else:
        mxs = [1]+[0]*(m-1)
        mns = [1]+[0]*(m-1)
        i, j = -1, 0
        while s > 1:
            if mns[i] >= 9:
                i -= 1
            if mxs[j] >= 9:
                j += 1
            mns[i]+=1
            mxs[j]+=1
            s-=1
        ret = "".join(map(str, mns+[" "]+mxs))
    return ret

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

print(solve(m, s))

__author__ = '1'
def minimize(m, s):
    if m == 1 and s == 0:
        return 0
    if s == 0:
        return -1
    array = [0 for i in range(m)]
    array[0] = 1

    currentFiller = m-1
    val = s-1
    for i in range(s-1):
        if array[currentFiller]<9:
            array[currentFiller]+=1;
            val-=1
        else:
            currentFiller-=1
            if currentFiller>=0:
                array[currentFiller]+=1
                val-=1
            else:
                break
    if val == 0:
        s = ""
        for i in range(len(array)):
            s+=str(array[i])
        return s
    else:
        return -1


def maximizeS(m, s):
    array = []
    for i in range(10**m):
        summ = 0
        st = str(i)
        for j in range(len(st)):
            summ+=ord(str(st[j])[0])-ord('0')
        if summ == s:
            array.append(i)
    array = sorted(array)
    if len(array)==0:
        return -1
    else:
        return array[-1]

def minimizeS(m, s):
    array = []
    for i in range(10**m):
        if len(str(i)) == m:
            summ = 0
            st = str(i)
            for j in range(len(st)):
                summ+=ord(str(st[j])[0])-ord('0')
            if summ == s:
                array.append(i)
    array = sorted(array)
    if len(array)==0:
        return -1
    else:
        return array[0]

def maximize(m, s):
    if m == 1 and s == 0:
        return 0
    if s == 0:
        return -1
    array = [0 for i in range(m)]
    array[0] = 1
    currentFiller = 0
    val = s-1
    for i in range(s-1):
        if array[currentFiller]<9:
            array[currentFiller]+=1;
            val-=1
        else:
            currentFiller+=1
            if currentFiller<m:
                array[currentFiller]+=1
                val-=1
            else:
                break
    if val == 0:
        s = ""
        for i in range(len(array)):
            s+=str(array[i])
        return s
    else:
        return -1


for m in range(1, 6):
    for s in range(6):
        """
        if int(minimize(m, s)) != int(minimizeS(m, s)):
             print(m, s, minimize(m, s), minimizeS(m, s))
        if int(maximize(m, s)) != int(maximizeS(m, s)):
             print(m, s, maximize(m, s), maximizeS(m, s))
        """
        pass

m, s = list(map(int, input().split(' ')))
a = minimize(m, s)
b = maximize(m, s)
print(a, b)


a, b = list(map(int, input().split(' ')))
if [a, b] == [1, 0]:
    print("0 0")
else:
    if 1 <= b <= 9*a:
        haloe = []
        max9 = b // 9
        other = b % 9
        if other != 0:
            strx = '9' * max9 + str(other) + (a-max9-1) * '0'
        else:
            strx = '9' * max9 + (a-max9) * '0'
        haloe.append(strx)
        strx = strx[::-1]
        if strx[0] != '0':
            haloe.append(strx)
        else:
            bad = False
            newstr = '1'
            for i in range(1, len(strx)):
                if strx[i] != '0' and not bad:
                    newstr += str(int(strx[i])-1)
                    bad = not bad
                else:
                    newstr += strx[i]
            haloe.append(newstr)
        print(haloe[1] + ' ' + haloe[0])
        
    else:
        print(-1, -1)


a, b = map(int, input().split(' '))
if [a, b] == [1, 0]:
    print("0 0")
else:
    if 1 <= b <= 9*a:
        haloe = []
        max9 = b // 9
        other = b % 9
        if other != 0:
            strx = '9' * max9 + str(other) + (a-max9-1) * '0'
        else:
            strx = '9' * max9 + (a-max9) * '0'
        haloe.append(strx)
        strx = strx[::-1]
        if strx[0] != '0':
            haloe.append(strx)
        else:
            bad = False
            newstr = '1'
            for i in range(1, len(strx)):
                if strx[i] != '0' and not bad:
                    newstr += str(int(strx[i])-1)
                    bad = not bad
                else:
                    newstr += strx[i]
            haloe.append(newstr)
        print(haloe[1] + ' ' + haloe[0])
        
    else:
        print(-1, -1)

m, s = (int(x) for x in input().split())
if s == 0:
    print('0 0' if m == 1 else '-1 -1')
elif s > m * 9:
    print('-1 -1')
else:
    maxs = '9' * (s // 9) + (str(s % 9) if s % 9 else '') + '0' * (m - (s + 8) // 9)
    mins = maxs[::-1]
    if mins[0] == '0':
        nzi = mins.index(next(ch for ch in mins if ch != '0'))
        mins = '1' + mins[1:nzi] + str(int(mins[nzi]) - 1) + mins[nzi + 1:]
    print(mins, maxs)


n,Sum=list(map(int,input().split()))
if n==1 and Sum==0:
    print(0,0)
elif Sum==0 or Sum>9*n:
    print(-1,-1)
else:
    l=[0]*n
    r=[0]*n
    b,p="",""
    s=Sum
    for i in range(n):
        if s>=9:
            r[i]=9
            s-=9
        else:
            r[i]=s
            s=0
        l[n-i-1]=r[i]
    if l[0]!=0:
        for i in range(n):
            b=b+str(l[i])
            p=p+str(r[i])
        print(b,p)
    else:
        for i in range(n):
            if l[i]!=0:
                break
        l[0]='1'
        l[i]=l[i]-1
        for i in range(n):
            b=b+str(l[i])
            p=p+str(r[i])
        print(b,p)