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.

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.

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).

import java.io.*
import java.util.*

class ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {
    companion object {
        fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))
    }

    var tok = StringTokenizer("")

    fun close() { rd.close(); wr.close() }
    fun <T> print(v: T) = wr.print(v)
    fun <T> println(v: T) = wr.println(v)
    fun readToken(): String {
        while (!tok.hasMoreTokens()) tok = StringTokenizer(rd.readLine())
        return tok.nextToken()
    }
    fun readInt() = readToken().toInt()
    fun readLong() = readToken().toLong()
    fun readLine() : String {
        tok = StringTokenizer("")
        return rd.readLine()
    }
}

fun main(args: Array<String>) {
    Thread({ val io = ProblemIO.console(); solve(io) ; io.close() }).start()
}

fun solve(io: ProblemIO) {
    val m = io.readInt()
    val s = io.readInt()

    if (s == 0) {
        if (m == 1) {
            io.println("0 0")
        } else {
            io.println("-1 -1")
        }
    } else {
        if (s > m * 9) {
            io.println("-1 -1")
        } else {
            var rs = s
            for (i in 1 .. m) {
                val d = Math.max(if (i == 1) 1 else 0, rs - (m - i) * 9)
                io.print(d)
                rs -= d
            }
            io.print(" ")
            rs = s
            for (i in 1 .. m) {
                val d = Math.min(9, rs)
                io.print(d)
                rs -= d
            }
            io.println("")
        }
    }
}

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val (len, sum) = r.readLine()!!.split(" ").map { it.toInt() }
    when {
        (len > 1 && sum == 0) || len * 9 < sum -> {
            println("-1 -1")
        }
        else -> {
            var maxSum = sum
            var minSum = sum
            val max = MutableList(len) { 0 }
            for (i in 0..len-1){
                if (maxSum>=9){
                    max[i] = 9
                    maxSum -= 9
                } else {
                    max[i] = maxSum
                    maxSum -= maxSum
                }
            }
            val min = MutableList(len) { 0 }
            min[0] = 1
            minSum -= 1
            //println(len)
            for (i in len-1 downTo 0){
                min[i] += minOf(9, minSum)
                minSum -= minOf(9, minSum)
            }
            println("${min.joinToString("")} ${max.joinToString("")}")
        }
    }
}

import java.io.PrintWriter
import kotlin.math.min

fun main() {
    io.apply {

        val (m, s) = int to int

        if (s == 0 && m == 1) {
            cout .. 0 .. 0 .. nl
        } else if (s <= 0 || s > m * 9)
            cout .. -1 .. -1 .. nl
        else {
            val str = CharArray(m) { '0' }
            str[0] = '1'
            var q = s - 1
            for (i in m - 1 downTo 0) {
                var d = min(9, q)
                str[i] = (str[i] + d)
                q -= d
            }
            cout .. String(str) .. " "
            str.fill('0')
            q = s
            for (i in 0 until m) {
                var d = min(9, q)
                str[i] = (str[i] + d)
                q -= d
            }
            cout .. String(str) .. nl
        }

    }.cout.flush()
}

// @formatter:off
private val io = object {
    private val `in` = System.`in`
    private fun ll(): Long {
        var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }
        do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n
    }
    val int get() = ll().toInt(); val long get() = ll()
    fun ints(n: Int = int): IntArray { return IntArray(n) { int } }
    fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }
    val cout = PrintWriter(System.out); val nl = "\n"
    private var buf = CharArray(32)
    private var bufSize = 32
    fun str(expect: Int = 32): String {
        var ix = 0
        var x: Int
        if (bufSize < expect)
            buf = CharArray(expect)
        do x = `in`.read() while (x < 33)
        do {
            if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }
            buf[ix++] = x.toChar()
            x = `in`.read()
        } while (x > 32)
        return java.lang.String.copyValueOf(buf, 0, ix)
    }
    operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(" ") }; return this }
    operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }
} // @formatter:on

/* ----------- */

import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val ms = br.readLine().split(" ").map { it.toInt() }
    val m = ms[0]
    val s = ms[1]

    if (s == 0){
        println(if (m == 1) "0 0" else "-1 -1")
    }else{

        if (s < 10){
            if (m == 1){
                println("$s $s")
            }else{
                val maxNum = s.toString() + "0".repeat(m - 1)
                val minNum = "1" + "0".repeat(m - 2) + (s - 1).toString()
                println("$minNum $maxNum")
            }

        } else if (s == 0 || m*9 < s){
            println("-1 -1")
        } else{

            val ans = getMinAndMax(m, s)

            println("${ans.first} ${ans.second}")

        }

    }

}

fun getMinAndMax(m: Int, s: Int): Pair<String, String>{
    val num9s = s / 9
    val missing = m - num9s
    val nines = if (missing >= 2 && s % 9 == 0) "9".repeat(num9s - 1) else "9".repeat(num9s)
    val minNum: String
    val maxNum: String

    val d = if (s - 9*num9s == 0) 9 else s - 9*num9s

    if (missing == 0){
        minNum = nines
        maxNum = nines
    } else if (missing <= 1){
        minNum = d.toString() + nines
        maxNum = nines + d.toString()
    }else{
        val l = 1
        val h = (d - 1)
        val zeroes = "0".repeat(if (s % 9 == 0) missing - 1 else missing - 2)

        minNum = l.toString() + zeroes + h + nines
        maxNum = nines + d.toString() + zeroes + "0"
    }
    return Pair(minNum, maxNum)
}

fun main() {
    val (m, s) = readLine()!!.split(" ").map { it.toInt() }
    var ansLittle = ""
    var ansBig = ""

    if (9 * m >= s && (s == 0 && m == 1 || s > 0)) {
        var t = m
        var k = s
        while (t > 0) {
            if (k > 9) {
                ansBig += "9"
                k -= 9
            } else {
                ansBig += k.toString()
                k = 0
            }
            t--
        }

        t = m
        k = s
        if ((t - 1) * 9 > k) {
            ansLittle += "1"
            k -= 1
            t--
        }
        while (t > 0) {
            if (t * 9 == k) {
                ansLittle += "9"
                k -= 9
            } else if ((t - 1) * 9 > k) {
                ansLittle += "0"
            } else {
                val q = k - ((t - 1) * 9)
                ansLittle += q.toString()
                k -= q
            }
            t--
        }
    } else {
        ansLittle = "-1"
        ansBig = "-1"
    }

    print("$ansLittle $ansBig")
}

import java.util.*

val noSolution = Pair(intArrayOf(-1), intArrayOf(-1))

fun main(args: Array<String>) {
    cf()
}

private fun cf() = with(Scanner(System.`in`)) {
    val m = nextInt()
    val s = nextInt()
    val (mi, ma) = run(m, s)

    print(mi.joinToString(""))
    print(" ")
    println(ma.joinToString(""))
}

private fun run(m: Int, s: Int): Pair<IntArray, IntArray> {
    if (m == 1 && s > 9) return noSolution
    if (m == 1) return Pair(intArrayOf(s), intArrayOf(s))
    if (s == 0) return noSolution

    var numOfNines = s / 9
    var rem = s % 9
    if (rem == 0) {
        rem = 9
        numOfNines--
    }

    if (numOfNines + 1 > m) return noSolution

    val ma = IntArray(m)
    for (i in 0 until numOfNines)
        ma[i] = 9
    ma[numOfNines] = rem

    val mi = ma.clone()
    if (numOfNines + 1 == m) {
        mi.reverse()
    } else {
        mi[mi.size - 1] = 1
        mi[numOfNines]--
        mi.reverse()
    }

    return Pair(mi, ma)
}

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    val (length, sum) = readInts()
    val quotient = sum / 9
    val rest = sum % 9
    if (length == 1 && sum == 0) {
        print("0 0")
        return
    }
    if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {
        print("-1 -1")
        return
    }
    val a = mutableListOf<Int>()
    for (i in 0 until quotient) a.add(9)
    if (rest != 0) a.add(rest)

    val sb1 = StringBuilder()
    for (element in a) sb1.append(element)
    for (i in 0 until length - a.size)
        sb1.append('0')
    val sb2 = StringBuilder()
    if (length > a.size) {
        a[a.lastIndex]--
        sb2.append('1')
        for (i in 0 until length - a.size - 1) sb2.append('0')
    }
    for (i in a.lastIndex downTo 0) sb2.append(a[i])
    print("$sb2 $sb1")
}

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    val (length, sum) = readInts()
    var quotient = sum / 9
    var rest = sum % 9
    if (length == 1 && sum == 0) {
        print("0 0")
        return
    }
    if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {
        print("-1 -1")
        return
    }
    val sb1 = StringBuilder()
    for (i in 0 until quotient) sb1.append('9')
    if (quotient < length) sb1.append(rest)
    for (i in 0 until length - quotient - 1)
        sb1.append('0')
    val sb2 = StringBuilder()
    var oneEight = false
    if (length > quotient + 1) {
        rest--
        if (rest < 0) {
            rest = 0
            oneEight = true
        }
        sb2.append('1')
        for (i in 0 until length - quotient - 2) sb2.append('0')
    }
    if (quotient < length) sb2.append(rest)
    if(oneEight) {
        sb2.append('8')
        quotient--
    }
    for (i in 0 until quotient) sb2.append('9')
    print("$sb2 $sb1")
}

// Shorter Python solution: https://codeforces.com/contest/489/submission/41588741

// 7/7/2020 11:13 AM

//package p489

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val (m, s) = readInts()
//    findSumToN(m, s)
    printResult(findSmallest(m, s))
    print(" ")
    printResult(findLargest(m, s))
    println()
}

fun findLargest(m: Int, s: Int) : List<Int> {
    if (s <= 0 && m > 1) return listOf<Int>()
    else if (s == 0 && m == 1) return listOf(0)

    var sumLeft = s
    val outputList = MutableList(m) {0}
    var idx = 0
    while (sumLeft > 0 && idx < m) {
        outputList[idx] = if (sumLeft >= 9) 9 else sumLeft
        sumLeft -= outputList[idx++]
    }
    if (sumLeft > 0)
        return listOf<Int>()
    else
        return outputList.toList()
}

fun findSmallest(m: Int, s: Int) : List<Int> {
    if (s <= 0 && m > 1) return listOf<Int>()
    else if (s == 0 && m == 1) return listOf(0)

    var sumLeft = s
    val outputList = MutableList(m) {0}

    val minFirst = s - 9 * (m - 1)

    if (minFirst <= 1)
        outputList[0] = 1
    else if (minFirst > 9)
        return listOf<Int>()
    else
        outputList[0] = minFirst

    sumLeft -= outputList[0]

    var idx = m - 1
    while (sumLeft > 0 && idx > 0) {
        outputList[idx] = if (sumLeft >= 9) 9 else sumLeft
        sumLeft -= outputList[idx--]
    }
    if (sumLeft > 0)
        return listOf<Int>()
    else
        return outputList.toList()
}

fun printResult(l: List<Int>) {
    if (l.isEmpty())
        print("-1")
    else
        print(l.fold("", {acc, cur -> acc + cur.toString()}))
}

//fun findSumToN(m: Int, s: Int) {
////    findSumToN_recursive(m, s, listOf<Int>())
//    printLeastAndGreatest(findSumToN_iterative(m, s))
//}
//
//fun printLeastAndGreatest(l: List<Int>) {
//    if (l.isEmpty()) {
//        println("-1 -1")
//        return
//    }
//
//    val theGreatest = l.toMutableList()
//    val theLeast = l.toMutableList()
//
//    for (i in theLeast.size-1 downTo 1) {
//        if (theLeast[i] > 0) {
//            val v = theLeast.removeAt(i)
//            theLeast.add(0, v)
//            break
//        }
//    }
//
//    var pos = 1
//    for (i in theLeast.size - 1 downTo 1) {
//        val v = theLeast.removeAt(theLeast.size - 1)
//        theLeast.add(pos, v)
//        pos++
//    }
//
//    print(theLeast.fold("", { acc, cur -> acc + cur.toString()}))
//    print(" ")
//    println(theGreatest.fold("", { acc, cur -> acc + cur.toString()}))
//
//
//}
//
//fun findSumToN_iterative(m: Int, s: Int) : List<Int> {
//    var currentList = mutableListOf<Int>()
//    if (s <= 0 && m > 1) return currentList
//
//    while (currentList.sum() < s) {
//        val totalLeft = s - currentList.sum()
//        currentList.add(
//            when{
//                totalLeft > 9 -> 9
//                else -> totalLeft
//            }
//        )
//    }
//    if (currentList.size > m) return emptyList<Int>()
//
//    while (currentList.size < m) {
//        currentList.add(0)
//    }
//    return currentList
//}

import kotlin.math.min

fun main() {
    val (m, s) = readLine()!!.split(' ').map(String::toInt)
    if (m == 1 && s == 0) {
        println("0 0")
        return
    }
    if (s == 0 || s > m * 9) {
        println("-1 -1")
        return
    }
    var sum = s
    val maxX = List(m) {
        val x = min(sum, 9)
        sum -= x
        x
    }
    sum = s
    val minX = List(m) {index ->
        val x = if (index == m - 1) {
            sum
        } else {
            min(sum - 1, 9)
        }
        sum -= x
        x
    }.reversed()
    println("${minX.joinToString("")} ${maxX.joinToString("")}")
}

fun main(args: Array<String>) {
    val (m, s) = readLine()!!.split(' ').map { it.toInt() }

    if ((s==0 && m>1) || (m * 9 < s) ){
        println("-1 -1")
        return
    }

    val arr = IntArray(m, {if (it == 0 && s > 0) 1 else 0})
    val arr2 = IntArray(m)

    for (i in 0 until m){
        var delta = s - 9 * i - 1
        if (delta <= 0) break
        arr[m - i - 1] = minOf(9, delta + if (i == m-1) 1 else 0)
    }

    for (i in 0 until m){
        var delta = s - 9 * i
        if (delta <= 0) break
        arr2[i] = minOf(9, delta)
    }

    println("${arr.joinToString(separator = "")} ${arr2.joinToString (separator = "")}")
}

fun fill(array: Array<Int>, totalSum: Int): Int {
    var rem = totalSum
    for (i in 0 until array.size) {
        if (rem >= 9) {
            array[i] = 9
            rem -= 9
        }
        else {
            array[i] = rem
            return 0
        }
    }

    return rem
}

fun main(args: Array<String>) {
    val (m, s) = readLine()!!.split(' ').map { it.toInt() }
    val max = Array(m, { 0 })

    if ((s == 0 && m > 1) || fill(max, s) != 0) {
        println("-1 -1")
        return
    }

    val min = Array(m, { 0 })
    fill(min, s - 1)
    min[min.size - 1] += 1

    return println("${min.reversed().joinToString(separator = "")} ${max.joinToString(separator = "")}")
}

import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.pow

fun main(){
    var scanner = Scanner(System.`in`)
    var m = scanner.nextInt()
    var s = scanner.nextInt()
    var min:String = ""
    var max:String = ""
    var lastNumberMax:Char
    if(m==1 && s==0) println("0 0")
    else if(s==0 || m*9<s) println("-1 -1")
    else {
        while(s!=0){
            for(i in 9 downTo 1){
                if(i<=s){
                    max += i
                    s-=i
                    break;
                }
            }
        }
        lastNumberMax = max[max.lastIndex]
        while(max.length != m) max+='0'
        if(max[max.length-1] != '0') min = max.reversed()
        else{
            min = max.reversed()
            min = "1${min.substring(1,min.length)}"
            var minChar = min.toCharArray()
            for(i in 1 until minChar.size){
                if(minChar[i] == lastNumberMax){
                    minChar[i] = (lastNumberMax.toInt() -1).toChar()
                   break
                }
            }
            min = String(minChar)
        }
        println("$min $max")
    }
}

import kotlin.math.max

fun readInts(): List<Int> = readLine()!!.split(" ").map{ it.toInt() }
fun findMin(m: Int, s: Int): String{
    val digits = (m-2 downTo 0).toMutableList()
    if (s > m * 9) return "-1"
    if(digits.size == 0) return "$s"
    val result = mutableListOf(max(1, s - 9*(m-1)))
    var auxS = s - result[0]
    var auxM = m - 1
    var index = 0
    while(auxM != 0 || auxS != 0){
        val value = max(0, auxS - 9 * digits[index])
        result.add(value)
        index ++
        auxS -= value
        auxM --
        if(auxM == 0) break
    }
    if(result.isEmpty() || auxM + auxS != 0){
        return "-1"
    }
    return result.joinToString(separator = "")
}
fun findMax(m: Int, s: Int): String{
    val digits = (9 downTo 0).toMutableList()
    var auxS = s
    var auxM = m
    val result = mutableListOf<Int>()
    var index = 0
    if( m == 1 && s <= 9)
    {
        return "$s"
    }
    while(auxM != 0 || auxS != 0){
        if(auxS - digits[index] >= 0){
            result.add(digits[index])
            auxS -= digits[index]
            auxM --
        }
        if(auxS < digits[index]){
            index ++
        }
        if(auxM == 0) break
    }
    if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0 || auxM + auxS != 0){
        return "-1"
    }
    return result.joinToString(separator = "")
}

fun main(){
    val (m, s) = readInts()

    println("${findMin(m, s)} ${findMax(m,s)}")
}

fun main(){
    var input = readLine()!!.split(' ')
    val m = input[0].toInt()
    val s = input[1].toInt()
    if (m == 1 && s == 0){
        println("0 0")
        return
    }

    if ((1 > s)  || (s > 9 * m)){
        println("-1 -1")
        return
    }

    var smallestNumberWithMDigits = CharArray(m){'0'}
    var greatestNumberWithMDigits = CharArray(m){'9'}
    smallestNumberWithMDigits[0] = '1'

    var startingIndex = m-1
    var digitSumVar = smallestNumberWithMDigits.sumBy { (it-'0') }
    while (digitSumVar + 9 <= s){
        digitSumVar += 9
        smallestNumberWithMDigits[startingIndex] = '9'
        startingIndex -= 1
    }

    while (digitSumVar < s){
        val current_digit = smallestNumberWithMDigits[startingIndex]
        smallestNumberWithMDigits[startingIndex] = current_digit + 1
        digitSumVar += 1
        if (current_digit == '8'){
            startingIndex -= 1
        }
    }

    startingIndex = m-1
    digitSumVar = greatestNumberWithMDigits.sumBy { (it-'0') }
    while (digitSumVar - 9 >= s){
        digitSumVar -= 9
        greatestNumberWithMDigits[startingIndex] = '0'
        startingIndex -= 1
    }

    while (digitSumVar > s){
        val currentDigit = greatestNumberWithMDigits[startingIndex]
        greatestNumberWithMDigits[startingIndex] = currentDigit - 1
        digitSumVar -= 1
        if (currentDigit == '1'){
            startingIndex -= 1
        }
    }

    println("${smallestNumberWithMDigits.joinToString("")} ${greatestNumberWithMDigits.joinToString("")}");
}

import java.util.*

fun findMin(n: Int, sum: Int): String {

	if ( sum == 0 ) return if ( n == 1 ) "0" else "-1"
	if ( sum > 9*n ) return "-1"

	val firstDigit = Math.max(1, sum - 9*(n-1))
	var left = sum - firstDigit

	val r = StringBuilder()
	r.append ( firstDigit )
	for ( i in n-2 downTo 0 ) {
		val d = Math.max ( 0, left - 9*i )
		r.append(d)
		left -= d
	}

	return r.toString()
}

fun findMax(n: Int, sum: Int): String {

	if ( sum == 0 ) return if ( n == 1 ) "0" else "-1"
	if ( sum > 9*n ) return "-1"

	val firstDigit = Math.min(9, sum)
	var left = sum - firstDigit

	val r = StringBuilder()
	r.append(firstDigit)
	for ( i in n-2 downTo 0 ) {
		val d = Math.min( 9, left )
		r.append(d)
		left -= d
	}

	return r.toString()
}

fun main(args : Array<String>) {
	val scan = Scanner (System.`in`)
	val n = scan.nextInt()
	val sum = scan.nextInt()

	println ( findMin(n,sum) + " " + findMax(n, sum) )
}

import kotlin.math.min

/* template start */
// input
private fun readString() = readLine()!!
private fun readStrings() = readString().split(" ")
private fun readInt() = readString().toInt()
private fun readDigits() = readString().map { it - '0' }
private fun readInts() = readStrings().map { it.toInt() }
private fun readLongs() = readStrings().map { it.toLong() }

// output
private fun <T> T.print(map: (T) -> String = { it.toString() }) = println(map(this))
private fun <T> Iterable<T>.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)
private fun <T> Array<T>.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)
private fun IntArray.print(sep: String? = null, map: ((Int) -> String)? = null) = asSequence().print(sep, map)
private fun <T> Sequence<T>.print(sep: String? = null, map: ((T) -> String)? = null) =
    println(joinToString(sep ?: "", transform = map ?: { it.toString() }))

// others
private val Int.isEven: Boolean get() = this % 2 == 0
private val Int.isOdd: Boolean get() = !this.isEven
private fun queries(block: (Int) -> Unit) = repeat(readInt(), block)

/* template end */

fun main() {
    val (len, sum) = readInts()
    if (sum == 0) {
        if (len != 1) println("-1 -1")
        else println("0 0")
    } else if (len * 9 < sum) {
        println("-1 -1")
    } else {
        val maxNum = buildString {
            var rem = sum
            repeat(len) {
                val next = min(rem, 9)
                append(next)
                rem -= next
            }
        }
        val minNum = mutableListOf<Int>()
        var rem = sum
        for (i in 0 until len) {
            if (rem > 1) {
                var next = min(rem - 1, 9)
                if (i == len - 1) {
                    next++
                }
                minNum.add(0, next)
                rem -= next
            } else {
                if (i != len - 1)
                    minNum.add(0, 0)
                else minNum.add(0, 1)
            }
        }

        println("${minNum.joinToString("")} $maxNum")
    }

}

import java.io.BufferedReader
import java.io.InputStreamReader

fun main() {
    val reader = BufferedReader(InputStreamReader(System.`in`))
    val (m, s) = reader.readLine().split(' ').map { it.toInt() }

    if (s == 0) {
        val answer = if (m == 1) 0 else -1
        println("$answer $answer")
        return
    }

    val maxN = Array<Int>(m) { if (it == 0) 1 else 0 }
    val minN = Array<Int>(m) { if (it == 0) 1 else 0 }

    var maxNPtr = 0
    var minNPtr = minN.lastIndex

    try {
        repeat(s-1) {
            if (maxN[maxNPtr] == 9) { maxNPtr++ }
            if (minN[minNPtr] == 9) { minNPtr-- }

            maxN[maxNPtr]++
            minN[minNPtr]++
        }
    } catch (e: IndexOutOfBoundsException) {
        println("-1 -1")
        return
    }

    println("${minN.joinToString("")} ${maxN.joinToString("")}")
}

import java.io.PrintWriter
import kotlin.math.min

fun main() {
    io.apply {

        val (m, s) = int to int

        if (s <= 0 || s > m * 9)
            cout .. -1 .. -1 .. nl
        else {
            val str = CharArray(m) { '0' }
            str[0] = '1'
            var q = s - 1
            for (i in m - 1 downTo 0) {
                var d = min(9, q)
                str[i] = (str[i] + d)
                q -= d
            }
            cout .. String(str) .. " "
            str.fill('0')
            q = s
            for (i in 0 until m) {
                var d = min(9, q)
                str[i] = (str[i] + d)
                q -= d
            }
            cout .. String(str) .. nl
        }

    }.cout.flush()
}

// @formatter:off
private val io = object {
    private val `in` = System.`in`
    private fun ll(): Long {
        var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }
        do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n
    }
    val int get() = ll().toInt(); val long get() = ll()
    fun ints(n: Int = int): IntArray { return IntArray(n) { int } }
    fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }
    val cout = PrintWriter(System.out); val nl = "\n"
    private var buf = CharArray(32)
    private var bufSize = 32
    fun str(expect: Int = 32): String {
        var ix = 0
        var x: Int
        if (bufSize < expect)
            buf = CharArray(expect)
        do x = `in`.read() while (x < 33)
        do {
            if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }
            buf[ix++] = x.toChar()
            x = `in`.read()
        } while (x > 32)
        return java.lang.String.copyValueOf(buf, 0, ix)
    }
    operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(" ") }; return this }
    operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }
} // @formatter:on

/* ----------- */

import java.io.PrintWriter
import kotlin.math.min

fun main() {
    io.apply {

        val (m, s) = int to int

        if (s == 0 && m == 1) {
            cout .. 0 .. 1 .. nl
        } else if (s <= 0 || s > m * 9)
            cout .. -1 .. -1 .. nl
        else {
            val str = CharArray(m) { '0' }
            str[0] = '1'
            var q = s - 1
            for (i in m - 1 downTo 0) {
                var d = min(9, q)
                str[i] = (str[i] + d)
                q -= d
            }
            cout .. String(str) .. " "
            str.fill('0')
            q = s
            for (i in 0 until m) {
                var d = min(9, q)
                str[i] = (str[i] + d)
                q -= d
            }
            cout .. String(str) .. nl
        }

    }.cout.flush()
}

// @formatter:off
private val io = object {
    private val `in` = System.`in`
    private fun ll(): Long {
        var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }
        do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n
    }
    val int get() = ll().toInt(); val long get() = ll()
    fun ints(n: Int = int): IntArray { return IntArray(n) { int } }
    fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }
    val cout = PrintWriter(System.out); val nl = "\n"
    private var buf = CharArray(32)
    private var bufSize = 32
    fun str(expect: Int = 32): String {
        var ix = 0
        var x: Int
        if (bufSize < expect)
            buf = CharArray(expect)
        do x = `in`.read() while (x < 33)
        do {
            if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }
            buf[ix++] = x.toChar()
            x = `in`.read()
        } while (x > 32)
        return java.lang.String.copyValueOf(buf, 0, ix)
    }
    operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(" ") }; return this }
    operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }
} // @formatter:on

/* ----------- */

import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val ms = br.readLine().split(" ").map { it.toInt() }
    val m = ms[0]
    val s = ms[1]

    if (s == 0){
        println("-1 -1")
    }else{

        if (s < 10){
            val num = s.toString() + "0".repeat(m - 1)
            println("$num $num")
        } else if (s == 0 || m*9 < s){
            println("-1 -1")
        } else{

            val d = 9 - (m*9 - s)
            val base = "9".repeat(m - 1)

            println("${d.toString() + base} ${base + d.toString()}")

        }

    }

}

import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val ms = br.readLine().split(" ").map { it.toInt() }
    val m = ms[0]
    val s = ms[1]

    if (s == 0){
        println(if (m == 1) "0 0" else "-1 -1")
    }else{

        if (s < 10){
            if (m == 1){
                println("$s $s")
            }else{
                val maxNum = s.toString() + "0".repeat(m - 1)
                val minNum = "1" + "0".repeat(m - 2) + (s - 1).toString()
                println("$minNum $maxNum")
            }

        } else if (s == 0 || m*9 < s){
            println("-1 -1")
        } else{

            val ans = getMinAndMax(m, s)

            println("${ans.first} ${ans.second}")

        }

    }

}

fun getMinAndMax(m: Int, s: Int): Pair<String, String>{
    val num9s = s / 9
    val missing = m - num9s
    val nines = "9".repeat(num9s)
    val minNum: String
    val maxNum: String

    val d = s - 9*num9s

    if (missing <= 1){
        minNum = d.toString() + nines
        maxNum = nines + d.toString()
    }else{
        val l = 1
        val h = (d - 1)
        val zeroes = "0".repeat(missing - 2)

        minNum = l.toString() + zeroes + h + nines
        maxNum = nines + max(l, h) + min(l, h) + zeroes
    }
    return Pair(minNum, maxNum)
}

import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val ms = br.readLine().split(" ").map { it.toInt() }
    val m = ms[0]
    val s = ms[1]

    if (s == 0){
        println(if (m == 1) "0 0" else "-1 -1")
    }else{

        if (s < 10){
            val num = s.toString() + "0".repeat(m - 1)
            println("$num $num")
        } else if (s == 0 || m*9 < s){
            println("-1 -1")
        } else{

            val ans = getMinAndMax(m, s)

            println("${ans.first} ${ans.second}")

        }

    }

}

fun getMinAndMax(m: Int, s: Int): Pair<String, String>{
    val num9s = s / 9
    val missing = m - num9s
    val nines = "9".repeat(num9s)
    val minNum: String
    val maxNum: String

    val d = s - 9*num9s

    if (missing <= 1){
        minNum = d.toString() + nines
        maxNum = nines + d.toString()
    }else{
        val l = 1
        val h = (d - 1)
        val zeroes = "0".repeat(missing - 2)

        minNum = l.toString() + zeroes + h + nines
        maxNum = nines + max(l, h) + min(l, h) + zeroes
    }
    return Pair(minNum, maxNum)
}

import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val ms = br.readLine().split(" ").map { it.toInt() }
    val m = ms[0]
    val s = ms[1]

    if (s == 0){
        println("-1 -1")
    }else{

        if (s < 10){
            val num = s.toString() + "0".repeat(m - 1)
            println("$num $num")
        } else if (s == 0 || m*9 < s){
            println("-1 -1")
        } else{

            val ans = getMinAndMax(m, s)

            println("${ans.first} ${ans.second}")

        }

    }

}

fun getMinAndMax(m: Int, s: Int): Pair<String, String>{
    val num9s = s / 9
    val missing = m - num9s
    val nines = "9".repeat(num9s)
    val minNum: String
    val maxNum: String

    val d = s - 9*num9s

    if (missing <= 1){
        minNum = d.toString() + nines
        maxNum = nines + d.toString()
    }else{
        val l = 1
        val h = (d - 1)
        val zeroes = "0".repeat(missing - 2)

        minNum = l.toString() + zeroes + h + nines
        maxNum = nines + max(l, h) + min(l, h) + zeroes
    }
    return Pair(minNum, maxNum)
}

import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val ms = br.readLine().split(" ").map { it.toInt() }
    val m = ms[0]
    val s = ms[1]

    if (s == 0){
        println(if (m == 1) "0 0" else "-1 -1")
    }else{

        if (s < 10){
            if (m == 1){
                println("$s $s")
            }else{
                val maxNum = s.toString() + "0".repeat(m - 1)
                val minNum = "1" + "0".repeat(m - 2) + (s - 1).toString()
                println("$minNum $maxNum")
            }

        } else if (s == 0 || m*9 < s){
            println("-1 -1")
        } else{

            val ans = getMinAndMax(m, s)

            println("${ans.first} ${ans.second}")

        }

    }

}

fun getMinAndMax(m: Int, s: Int): Pair<String, String>{
    val num9s = s / 9
    val missing = m - num9s
    val nines = "9".repeat(num9s)
    val minNum: String
    val maxNum: String

    val d = s - 9*num9s

    if (missing == 0){
        minNum = nines
        maxNum = nines
    } else if (missing <= 1){
        minNum = d.toString() + nines
        maxNum = nines + d.toString()
    }else{
        val l = 1
        val h = (d - 1)
        val zeroes = "0".repeat(missing - 2)

        minNum = l.toString() + zeroes + h + nines
        maxNum = nines + d.toString() + zeroes + "0"
    }
    return Pair(minNum, maxNum)
}

import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val ms = br.readLine().split(" ").map { it.toInt() }
    val m = ms[0]
    val s = ms[1]

    if (s == 0){
        println(if (m == 1) "0 0" else "-1 -1")
    }else{

        if (s < 10){
            if (m == 1){
                println("$s $s")
            }else{
                val maxNum = s.toString() + "0".repeat(m - 1)
                val minNum = "1" + "0".repeat(m - 2) + (s - 1).toString()
                println("$minNum $maxNum")
            }

        } else if (s == 0 || m*9 < s){
            println("-1 -1")
        } else{

            val ans = getMinAndMax(m, s)

            println("${ans.first} ${ans.second}")

        }

    }

}

fun getMinAndMax(m: Int, s: Int): Pair<String, String>{
    val num9s = s / 9
    val missing = m - num9s
    val nines = "9".repeat(num9s)
    val minNum: String
    val maxNum: String

    val d = if (s - 9*num9s == 0) 9 else s - 9*num9s

    if (missing == 0){
        minNum = nines
        maxNum = nines
    } else if (missing <= 1){
        minNum = d.toString() + nines
        maxNum = nines + d.toString()
    }else{
        val l = 1
        val h = (d - 1)
        val zeroes = "0".repeat(missing - 2)

        minNum = l.toString() + zeroes + h + nines
        maxNum = nines + d.toString() + zeroes + "0"
    }
    return Pair(minNum, maxNum)
}

import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val ms = br.readLine().split(" ").map { it.toInt() }
    val m = ms[0]
    val s = ms[1]

    if (s == 0){
        println(if (m == 1) "0 0" else "-1 -1")
    }else{

        if (s < 10){
            if (m == 1){
                println("$s $s")
            }else{
                val maxNum = s.toString() + "0".repeat(m - 1)
                val minNum = "1" + "0".repeat(m - 2) + (s - 1).toString()
                println("$minNum $maxNum")
            }

        } else if (s == 0 || m*9 < s){
            println("-1 -1")
        } else{

            val ans = getMinAndMax(m, s)

            println("${ans.first} ${ans.second}")

        }

    }

}

fun getMinAndMax(m: Int, s: Int): Pair<String, String>{
    val num9s = s / 9
    val missing = m - num9s
    val nines = "9".repeat(num9s)
    val minNum: String
    val maxNum: String

    val d = s - 9*num9s

    if (missing == 0){
        minNum = nines
        maxNum = nines
    } else if (missing <= 1){
        minNum = d.toString() + nines
        maxNum = nines + d.toString()
    }else{
        val l = 1
        val h = (d - 1)
        val zeroes = "0".repeat(missing - 2)

        minNum = l.toString() + zeroes + h + nines
        maxNum = nines + max(l, h) + min(l, h) + zeroes
    }
    return Pair(minNum, maxNum)
}

import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val ms = br.readLine().split(" ").map { it.toInt() }
    val m = ms[0]
    val s = ms[1]

    if (s == 0 || m*9 < s){
        println("-1 -1")
    }else{

        val d = 9 - (m*9 - s)
        var min = d.toString()
        var max = ""

        for (i in 1 until m){
            min += '9'

        }

        for (i in 0 until m){
            if (i == m - 1) max += d.toString()
            else max += '9'
        }

        println("$min $max")

    }
}

import java.util.*

val noSolution = Pair(intArrayOf(-1), intArrayOf(-1))

fun main(args: Array<String>) {
    cf()
}

private fun cf() = with(Scanner(System.`in`)) {
    val m = nextInt()
    val s = nextInt()
    val (mi, ma) = run(m, s)

    print(mi.joinToString(""))
    print(" ")
    println(ma.joinToString(""))
}

private fun run(m: Int, s: Int): Pair<IntArray, IntArray> {
    if (m == 1 && s > 10) return noSolution
    if (m == 1) return Pair(intArrayOf(s), intArrayOf(s))
    if (s == 0) return noSolution

    var numOfNines = s / 9
    var rem = s % 9
    if (rem == 0) {
        rem = 9
        numOfNines--
    }

    if (numOfNines + 1 > m) return noSolution

    val ma = IntArray(m)
    for (i in 0 until numOfNines)
        ma[i] = 9
    ma[numOfNines] = rem

    val mi = ma.clone()
    if (numOfNines + 1 == m) {
        mi.reverse()
    } else {
        mi[mi.size - 1] = 1
        mi[numOfNines]--
        mi.reverse()
    }

    return Pair(mi, ma)
}

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    val (length, sum) = readInts()
    val quotient = sum / 9
    var rest = sum % 9
    if (length == 1 && sum == 0) {
        print("0 0")
        return
    }
    if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {
        print("-1 -1")
        return
    }
    val sb1 = StringBuilder()
    for (i in 0 until quotient) sb1.append('9')
    sb1.append(rest)
    for (i in 0 until length - quotient - 1)
        sb1.append('0')
    val sb2 = StringBuilder()
    if (length > quotient + 1) {
        rest--
        sb2.append('1')
        for (i in 0 until length - quotient - 2) sb2.append('0')
    }
    sb2.append(rest)
    for (i in 0 until quotient) sb2.append('9')
    print("$sb2 $sb1")
}

// Shorter Python solution: https://codeforces.com/contest/489/submission/41588741

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    val (length, sum) = readInts()
    val quotient = sum / 9
    var rest = sum % 9
    if (length == 1 && sum == 0) {
        print("0 0")
        return
    }
    if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {
        print("-1 -1")
        return
    }
    val sb1 = StringBuilder()
    for (i in 0 until quotient) sb1.append('9')
    if (quotient < length) sb1.append(rest)
    for (i in 0 until length - quotient - 1)
        sb1.append('0')
    val sb2 = StringBuilder()
    if (length > quotient + 1) {
        rest--
        sb2.append('1')
        for (i in 0 until length - quotient - 2) sb2.append('0')
    }
    if (quotient < rest) sb2.append(rest)
    for (i in 0 until quotient) sb2.append('9')
    print("$sb2 $sb1")
}

// Shorter Python solution: https://codeforces.com/contest/489/submission/41588741

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    val (length, sum) = readInts()
    val quotient = sum / 9
    var rest = sum % 9
    if (length == 1 && sum == 0) {
        print("0 0")
        return
    }
    if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {
        print("-1 -1")
        return
    }
    val sb1 = StringBuilder()
    for (i in 0 until quotient) sb1.append('9')
    if (quotient < length) sb1.append(rest)
    for (i in 0 until length - quotient - 1)
        sb1.append('0')
    val sb2 = StringBuilder()
    if (length > quotient + 1) {
        rest--
        sb2.append('1')
        for (i in 0 until length - quotient - 2) sb2.append('0')
    }
    if (quotient < length) sb2.append(rest)
    for (i in 0 until quotient) sb2.append('9')
    print("$sb2 $sb1")
}

// Shorter Python solution: https://codeforces.com/contest/489/submission/41588741

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    val (length, sum) = readInts()
    val quotient = sum / 9
    val rest = sum % 9
    if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {
        print("-1 -1")
        return
    }
    val a = mutableListOf<Int>()
    for (i in 0 until quotient) a.add(9)
    if (rest != 0) a.add(rest)

    val sb1 = StringBuilder()
    for(element in a) sb1.append(element)
    for (i in 0 until length - a.size)
        sb1.append('0')
    val sb2 = StringBuilder()
    if(length > a.size) {
        a[a.lastIndex]--
        sb2.append('1')
        for(i in 0 until length - a.size - 1) sb2.append('0')
    }
    for(i in a.lastIndex downTo 0) sb2.append(a[i])
    print("$sb2 $sb1")
}

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    val (length, sum) = readInts()
    val quotient = sum / 9
    val rest = sum % 9
    if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {
        print("-1 -1")
        return
    }
    val a = mutableListOf<Int>()
    for (i in 0 until quotient) a.add(9)
    if (rest != 0) a.add(rest)

    val sb = StringBuilder()
    for(element in a) sb.append(element)
    for (i in 0 until length - a.size)
        sb.append('0')
    sb.append(' ')
    if(length > a.size) {
        a[a.lastIndex]--
        sb.append('1')
        for(i in 0 until length - a.size - 1) sb.append('0')
    }
    for(i in a.lastIndex downTo 0) sb.append(a[i])
    print(sb)
}

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    val (length, sum) = readInts()
    val quotient = sum / 9
    var rest = sum % 9
    if (length == 1 && sum == 0) {
        print("0 0")
        return
    }
    if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {
        print("-1 -1")
        return
    }
    val sb1 = StringBuilder()
    for (i in 0 until quotient) sb1.append('9')
    if (quotient < length) sb1.append(rest)
    for (i in 0 until length - quotient - 1)
        sb1.append('0')
    val sb2 = StringBuilder()
    if (length > quotient + 1) {
        rest--
        if (rest < 0) rest = 8
        sb2.append('1')
        for (i in 0 until length - quotient - 2) sb2.append('0')
    }
    if (quotient < length) sb2.append(rest)
    for (i in 0 until quotient) sb2.append('9')
    print("$sb2 $sb1")
}

// Shorter Python solution: https://codeforces.com/contest/489/submission/41588741

// 7/7/2020 11:13 AM

//package p489

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    findSumToN(403, 105)
}

fun findSumToN(m: Int, s: Int) {
//    findSumToN_recursive(m, s, listOf<Int>())
    printLeastAndGreatest(findSumToN_iterative(m, s))
}

fun printLeastAndGreatest(l: List<Int>) {
    if (l.isEmpty()) {
        println("-1 -1")
        return
    }

    val theGreatest = l.toMutableList()
    val theLeast = l.toMutableList()

    for (i in theLeast.size-1 downTo 1) {
        if (theLeast[i] > 0) {
            val v = theLeast.removeAt(i)
            theLeast.add(0, v)
            break
        }
    }

    var pos = 1
    for (i in theLeast.size - 1 downTo 1) {
        val v = theLeast.removeAt(theLeast.size - 1)
        theLeast.add(pos, v)
        pos++
    }

    print(theLeast.fold("", { acc, cur -> acc + cur.toString()}))
    print(" ")
    println(theGreatest.fold("", { acc, cur -> acc + cur.toString()}))

}

fun findSumToN_iterative(m: Int, s: Int) : List<Int> {
    var currentList = mutableListOf<Int>()
    while (currentList.sum() < s) {
        val totalLeft = s - currentList.sum()
        currentList.add(
            when{
                totalLeft > 9 -> 9
                else -> totalLeft
            }
        )
    }
    if (currentList.size > m) return emptyList<Int>()

    while (currentList.size < m) {
        currentList.add(0)
    }
    return currentList
}

fun findSumToN_recursive(m: Int, s: Int, numbersSoFar: List<Int>) : Unit {
    val currentTotal = numbersSoFar.sum()
    val nNumbers = numbersSoFar.size
    if (currentTotal > s || nNumbers > m)
        return
    else if (currentTotal == s) {
        var newNumbersSoFar = numbersSoFar.toMutableList()
        while (newNumbersSoFar.size < m) {
            newNumbersSoFar.add(0)
        }
        println(newNumbersSoFar)
    } else {
        val lastNum = if (numbersSoFar.isEmpty()) 9 else numbersSoFar.last()
        for (i in lastNum downTo 1) {
            val newNumbersSoFar = numbersSoFar.toMutableList()
            newNumbersSoFar.add(i)
            findSumToN_recursive(s, m, newNumbersSoFar)
        }
    }
}

// 7/7/2020 11:13 AM

//package p489

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val (m, s) = readInts()
    findSumToN(m, s)
}

fun findSumToN(m: Int, s: Int) {
//    findSumToN_recursive(m, s, listOf<Int>())
    printLeastAndGreatest(findSumToN_iterative(m, s))
}

fun printLeastAndGreatest(l: List<Int>) {
    if (l.isEmpty()) {
        println("-1 -1")
        return
    }

    val theGreatest = l.toMutableList()
    val theLeast = l.toMutableList()

    for (i in theLeast.size-1 downTo 1) {
        if (theLeast[i] > 0) {
            val v = theLeast.removeAt(i)
            theLeast.add(0, v)
            break
        }
    }

    var pos = 1
    for (i in theLeast.size - 1 downTo 1) {
        val v = theLeast.removeAt(theLeast.size - 1)
        theLeast.add(pos, v)
        pos++
    }

    print(theLeast.fold("", { acc, cur -> acc + cur.toString()}))
    print(" ")
    println(theGreatest.fold("", { acc, cur -> acc + cur.toString()}))

}

fun findSumToN_iterative(m: Int, s: Int) : List<Int> {
    var currentList = mutableListOf<Int>()
    if (s <= 0 && m > 1) return currentList

    while (currentList.sum() < s) {
        val totalLeft = s - currentList.sum()
        currentList.add(
            when{
                totalLeft > 9 -> 9
                else -> totalLeft
            }
        )
    }
    if (currentList.size > m) return emptyList<Int>()

    while (currentList.size < m) {
        currentList.add(0)
    }
    return currentList
}

fun findSumToN_recursive(m: Int, s: Int, numbersSoFar: List<Int>) : Unit {
    val currentTotal = numbersSoFar.sum()
    val nNumbers = numbersSoFar.size
    if (currentTotal > s || nNumbers > m)
        return
    else if (currentTotal == s) {
        var newNumbersSoFar = numbersSoFar.toMutableList()
        while (newNumbersSoFar.size < m) {
            newNumbersSoFar.add(0)
        }
        println(newNumbersSoFar)
    } else {
        val lastNum = if (numbersSoFar.isEmpty()) 9 else numbersSoFar.last()
        for (i in lastNum downTo 1) {
            val newNumbersSoFar = numbersSoFar.toMutableList()
            newNumbersSoFar.add(i)
            findSumToN_recursive(s, m, newNumbersSoFar)
        }
    }
}

// 7/7/2020 11:13 AM

//package p489

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val (m, s) = readInts()
    findSumToN(m, s)
}

fun findSumToN(m: Int, s: Int) {
//    findSumToN_recursive(m, s, listOf<Int>())
    printLeastAndGreatest(findSumToN_iterative(m, s))
}

fun printLeastAndGreatest(l: List<Int>) {
    if (l.isEmpty()) {
        println("-1 -1")
        return
    }

    val theGreatest = l.toMutableList()
    val theLeast = l.toMutableList()

    for (i in theLeast.size-1 downTo 1) {
        if (theLeast[i] > 0) {
            val v = theLeast.removeAt(i)
            theLeast.add(0, v)
            break
        }
    }

    var pos = 1
    for (i in theLeast.size - 1 downTo 1) {
        val v = theLeast.removeAt(theLeast.size - 1)
        theLeast.add(pos, v)
        pos++
    }

    print(theLeast.fold("", { acc, cur -> acc + cur.toString()}))
    print(" ")
    println(theGreatest.fold("", { acc, cur -> acc + cur.toString()}))

}

fun findSumToN_iterative(m: Int, s: Int) : List<Int> {
    var currentList = mutableListOf<Int>()
    if (s <= 0) return currentList

    while (currentList.sum() < s) {
        val totalLeft = s - currentList.sum()
        currentList.add(
            when{
                totalLeft > 9 -> 9
                else -> totalLeft
            }
        )
    }
    if (currentList.size > m) return emptyList<Int>()

    while (currentList.size < m) {
        currentList.add(0)
    }
    return currentList
}

fun findSumToN_recursive(m: Int, s: Int, numbersSoFar: List<Int>) : Unit {
    val currentTotal = numbersSoFar.sum()
    val nNumbers = numbersSoFar.size
    if (currentTotal > s || nNumbers > m)
        return
    else if (currentTotal == s) {
        var newNumbersSoFar = numbersSoFar.toMutableList()
        while (newNumbersSoFar.size < m) {
            newNumbersSoFar.add(0)
        }
        println(newNumbersSoFar)
    } else {
        val lastNum = if (numbersSoFar.isEmpty()) 9 else numbersSoFar.last()
        for (i in lastNum downTo 1) {
            val newNumbersSoFar = numbersSoFar.toMutableList()
            newNumbersSoFar.add(i)
            findSumToN_recursive(s, m, newNumbersSoFar)
        }
    }
}

// 7/7/2020 11:13 AM

//package p489

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val (m, s) = readInts()
//    findSumToN(m, s)
    printResult(findSmallest(m, s))
    print(" ")
    printResult(findLargest(m, s))
    println()
}

fun findLargest(m: Int, s: Int) : List<Int> {
    if (s <= 0) return listOf<Int>()

    var sumLeft = s
    val outputList = MutableList(m) {0}
    var idx = 0
    while (sumLeft > 0 && idx < m) {
        outputList[idx] = if (sumLeft >= 9) 9 else sumLeft
        sumLeft -= outputList[idx++]
    }
    if (sumLeft > 0)
        return listOf<Int>()
    else
        return outputList.toList()
}

fun findSmallest(m: Int, s: Int) : List<Int> {
    if (s <= 0) return listOf<Int>()

    var sumLeft = s
    val outputList = MutableList(m) {0}

    val minFirst = s - 9 * (m - 1)

    if (minFirst <= 1)
        outputList[0] = 1
    else if (minFirst > 9)
        return listOf<Int>()
    else
        outputList[0] = minFirst

    sumLeft -= outputList[0]

    var idx = m - 1
    while (sumLeft > 0 && idx > 0) {
        outputList[idx] = if (sumLeft >= 9) 9 else sumLeft
        sumLeft -= outputList[idx--]
    }
    if (sumLeft > 0)
        return listOf<Int>()
    else
        return outputList.toList()
}

fun printResult(l: List<Int>) {
    if (l.isEmpty())
        print("-1")
    else
        print(l.fold("", {acc, cur -> acc + cur.toString()}))
}

//fun findSumToN(m: Int, s: Int) {
////    findSumToN_recursive(m, s, listOf<Int>())
//    printLeastAndGreatest(findSumToN_iterative(m, s))
//}
//
//fun printLeastAndGreatest(l: List<Int>) {
//    if (l.isEmpty()) {
//        println("-1 -1")
//        return
//    }
//
//    val theGreatest = l.toMutableList()
//    val theLeast = l.toMutableList()
//
//    for (i in theLeast.size-1 downTo 1) {
//        if (theLeast[i] > 0) {
//            val v = theLeast.removeAt(i)
//            theLeast.add(0, v)
//            break
//        }
//    }
//
//    var pos = 1
//    for (i in theLeast.size - 1 downTo 1) {
//        val v = theLeast.removeAt(theLeast.size - 1)
//        theLeast.add(pos, v)
//        pos++
//    }
//
//    print(theLeast.fold("", { acc, cur -> acc + cur.toString()}))
//    print(" ")
//    println(theGreatest.fold("", { acc, cur -> acc + cur.toString()}))
//
//
//}
//
//fun findSumToN_iterative(m: Int, s: Int) : List<Int> {
//    var currentList = mutableListOf<Int>()
//    if (s <= 0 && m > 1) return currentList
//
//    while (currentList.sum() < s) {
//        val totalLeft = s - currentList.sum()
//        currentList.add(
//            when{
//                totalLeft > 9 -> 9
//                else -> totalLeft
//            }
//        )
//    }
//    if (currentList.size > m) return emptyList<Int>()
//
//    while (currentList.size < m) {
//        currentList.add(0)
//    }
//    return currentList
//}

import kotlin.math.min

fun main() {
    val (m, s) = readLine()!!.split(' ').map(String::toInt)
    if (s == 0 || s > m * 9) {
        println("-1 -1")
        return
    }
    var sum = s
    val maxX = List(m) {
        val x = min(sum, 9)
        sum -= x
        x
    }
    sum = s
    val minX = List(m) {index ->
        val x = if (index == m - 1) {
            sum
        } else {
            min(sum - 1, 9)
        }
        sum -= x
        x
    }.reversed()
    println("${minX.joinToString("")} ${maxX.joinToString("")}")
}

fun main(args: Array<String>) {
    val (m, s) = readLine()!!.split(' ').map { it.toInt() }
    (1 .. 900)
            .map { it.toString() }
            .filter { it.length == m && it.map { it - '0' }.sum() == s }
            .let { println(if (it.isEmpty()) "-1 -1" else "${it.first()} ${it.last()}") }
}

fun main(args: Array<String>) {
    val (m, s) = readLine()!!.split(' ').map { it.toInt() }

    if ((s==0 && m>1) || (m * 9 < s) ){
        println("-1 -1")
        return
    }

    val arr = IntArray(m, {if (it == 0) 1 else 0})
    val arr2 = IntArray(m)

    for (i in 0 until m){
        var delta = s - 9 * i - 1
        if (delta <= 0) break
        arr[m - i - 1] = minOf(9, delta + if (i == m-1) 1 else 0)
    }

    for (i in 0 until m){
        var delta = s - 9 * i
        if (delta <= 0) break
        arr2[i] = minOf(9, delta)
    }

    println("${arr.joinToString(separator = "")} ${arr2.joinToString (separator = "")}")
}

fun main(args: Array<String>) {
    val (m, s) = readLine()!!.split(' ').map { it.toInt() }
    val arr = IntArray(m, {if (it == 0) 1 else 0})
    val arr2 = IntArray(m)

    for (i in 0 until m){
        var delta = s - 9 * i - 1
        if (delta <= 0) break
        arr[m - i - 1] = minOf(9, delta + if (i == m-1) 1 else 0)

        delta ++
        arr2[i] = minOf(9, delta)
    }

    println("${arr.joinToString(separator = "")} ${arr2.joinToString (separator = "")}")
}

fun main(args: Array<String>) {
    val (m, s) = readLine()!!.split(' ').map { it.toInt() }

    if ( s == 0 || 18 * m < s) {
        println("-1 -1")
        return
    }

    (1..s * 10).map { "$it" }
            .first { it.sumBy { it - '0' } == s }
            .let {
                print("$it${"0".repeat(m - it.length)} ")
                for (i in 0 until m) {
                    print(maxOf(minOf(s - 9 * i, 9), 0))
                }
            }
}

fun main(args: Array<String>) {
    val (m, s) = readLine()!!.split(' ').map { it.toInt() }

    if ( s == 0 || 9 * m < s) {
        println("-1 -1")
    }else{
        with(StringBuilder()){
            (0 until m)
                    .takeWhile { s - 9 * it > 0 }
                    .forEach {  this.append(minOf(9,s-9 * it))}

            val res = this.toString().reversed()
            val z = "0".repeat(m - res.length)
            print("${res.first()}$z${res.removeRange(0,1)} ")
            print("${res.reversed()}$z")
        }
    }
}

fun main(args: Array<String>) {
    val (m, s) = readLine()!!.split(' ').map { it.toInt() }

    if ( (s == 0 && m > 1) || 9 * m < s) {
        println("-1 -1")
    }else{
        with(StringBuilder()){
            (0 until m)
                    .takeWhile { s - 9 * it > 0 }
                    .forEach {  this.append(minOf(9,s-9 * it))}

            if (this.isEmpty()) this.append(0)

            val res = this.toString().reversed()
            val z = "0".repeat(m - res.length)
            print("${res.first()}$z${res.removeRange(0,1)} ")
            print("${res.reversed()}$z")
        }
    }
}

fun main(args: Array<String>) {
    val (m, s) = readLine()!!.split(' ').map { it.toInt() }

    (1..100).map { it.toString() }
            .filter { it.length == m && it.sumBy { it - '0' } == s }
            .let {
                println(if (it.isEmpty()) -1 else "${it.first()} ${it.last()}")
            }
}

fun main(args: Array<String>) {
    val (m, s) = readLine()!!.split(' ').map { it.toInt() }

    if ( s == 0 || 9 * m < s) {
        println("-1 -1")
    }else{
        with(StringBuilder()){
            (0 until m)
                    .takeWhile { m - 9 * it > 0 }
                    .forEach {  this.append(minOf(9,m-9 * it))}
            val res = this.toString().reversed()
            val z = "0".repeat(m - res.length)
            print("${res.first()}$z${res.removeRange(0,1)} ")
            print("${res.reversed()}$z")
        }
    }
}

fun main(args: Array<String>) {
    val (m, s) = readLine()!!.split(' ').map { it.toInt() }

    (1..100).map { it.toString() }
            .filter { it.length == m && it.sumBy { it - '0' } == s }
            .let {
                println(if (it.isEmpty()) "-1 -1" else "${it.first()} ${it.last()}")
            }
}

fun main(args: Array<String>) {
    val (m, s) = readLine()!!.split(' ').map { it.toInt() }

    if ((s==0 && m>1) || (m * 9 < s) ){
        println("-1 -1")
        return
    }

    val arr = IntArray(m, {if (it == 0) 1 else 0})
    val arr2 = IntArray(m)

    for (i in 0 until m){
        var delta = s - 9 * i - 1
        if (delta <= 0) break
        arr[m - i - 1] = minOf(9, delta + if (i == m-1) 1 else 0)

        delta ++
        arr2[i] = minOf(9, delta)
    }

    println("${arr.joinToString(separator = "")} ${arr2.joinToString (separator = "")}")
}

fun fill(array: Array<Int>, totalSum: Int): Int {
    var rem = totalSum
    for (i in 0 until array.size) {
        if (rem >= 9) {
            array[i] = 9
            rem -= 9
        }
        else {
            array[i] = rem
            return 0
        }
    }

    return rem
}

fun main(args: Array<String>) {
    val (m, s) = readLine()!!.split(' ').map { it.toInt() }
    val max = Array(m, { 0 })

    if (s == 0 || fill(max, s) != 0) {
        println("-1 -1")
        return
    }

    val min = Array(m, { 0 })
    fill(min, s - 1)
    min[min.size - 1] += 1

    return println("${min.reversed().joinToString(separator = "")} ${max.joinToString(separator = "")}")
}

import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.pow

fun main(){
    var scanner = Scanner(System.`in`)
    var m = scanner.nextInt()
    var s = scanner.nextInt()
    var min:String = ""
    var max:String = ""
    var lastNumberMax:Char
    if(s==0) println("-1 -1")
    else {
        while(s!=0){
            for(i in 9 downTo 1){
                if(i<=s){
                    max += i
                    s-=i
                    break;
                }
            }
        }
        lastNumberMax = max[max.lastIndex]
        while(max.length != m) max+='0'
        if(max[max.length-1] != '0') min = max.reversed()
        else{
            min = max.reversed()
            min = "1${min.substring(1,min.length)}"
            var minChar = min.toCharArray()
            for(i in 1 until minChar.size){
                if(minChar[i] == lastNumberMax){
                    println(minChar[i])
                    minChar[i] = (lastNumberMax.toInt() -1).toChar()
                   break
                }
            }
            min = String(minChar)
        }
        println("$min $max")
    }
}

import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.pow

fun main(){
    var scanner = Scanner(System.`in`)
    var m = scanner.nextInt()
    var s = scanner.nextInt()
    var min:String = ""
    var max:String = ""
    var lastNumberMax:Char
    if(s==0 || m*9<s) println("-1 -1")
    else {
        while(s!=0){
            for(i in 9 downTo 1){
                if(i<=s){
                    max += i
                    s-=i
                    break;
                }
            }
        }
        lastNumberMax = max[max.lastIndex]
        while(max.length != m) max+='0'
        if(max[max.length-1] != '0') min = max.reversed()
        else{
            min = max.reversed()
            min = "1${min.substring(1,min.length)}"
            var minChar = min.toCharArray()
            for(i in 1 until minChar.size){
                if(minChar[i] == lastNumberMax){
                    minChar[i] = (lastNumberMax.toInt() -1).toChar()
                   break
                }
            }
            min = String(minChar)
        }
        println("$min $max")
    }
}

import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.pow

fun main(){
    var scanner = Scanner(System.`in`)
    var m = scanner.nextInt()
    var s = scanner.nextInt()
    var min:String = ""
    var max:String = ""
    if(s==0) println("-1 -1")
    else {
        while(s!=0){
            for(i in 9 downTo 1){
                if(i<=s){
                    max += i
                    s-=i
                    break;
                }
            }
        }
        while(max.length != m) max+='0'
        if(max[max.length-1] != '0') min = max.reversed()
        else{
            min = max.reversed()
            min = "1${min.substring(1,min.length-1)}${min[min.lastIndex].toString().toInt() -1}"
        }
        println("$min $max")
    }
}

fun readInts(): List<Int> = readLine()!!.split(" ").map{ it.toInt() }

fun main(){
    var (m, s) = readInts()
    val digits = (9 downTo 0).toMutableList()
    val result = mutableListOf<Int>()
    var index = 0
    if( m == 1 && s <= 9)
    {
        println("$s $s")
        return
    }
    while(m != 0 || s != 0){
        if(s - digits[index] >= 0){
            result.add(digits[index])
            s -= digits[index]
            m --
        }
        if(s < digits[index]){
            index ++
        }
        if(m == 0) break
    }
    if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0 || m + s != 0){
        println("-1 -1")
        return
    }
    val resultStringHigh = result.joinToString(separator = "")
    val resultStringLow = if(resultStringHigh[resultStringHigh.lastIndex]!='0'){
        resultStringHigh.reversed()
    }
    else{
        val aux = StringBuilder()
        aux.append(resultStringHigh.reversed())
        aux[0] = aux.first { it != '0' }.also { aux[aux.indexOfFirst { it != '0' }]= aux[0] }
        aux.toString()
    }
    println("$resultStringLow $resultStringHigh")
}

fun readInts(): List<Int> = readLine()!!.split(" ").map{ it.toInt() }

fun main(){
    var (m, s) = readInts()
    val digits = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9).sortedDescending().toMutableList()
    val result = mutableListOf<Int>()
    while(m != 0 || s != 0){
        for(it in digits) {
            if( s - it >= 0){
                s -= it
                result.add(it)
                digits.remove(it)
                break
            }
        }
        m --
    }
    if(result.isEmpty()){
        println("-1 -1")
        return
    }
    val resultString = result.joinToString(separator = "")
    print(resultString.reversed() + " " + resultString)
}

fun readInts(): List<Int> = readLine()!!.split(" ").map{ it.toInt() }

fun main(){
    var (m, s) = readInts()
    val digits = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).sortedDescending().toMutableList()
    val result = mutableListOf<Int>()
    while(m != 0 || s != 0){
        for(it in digits) {
            if( s - it >= 0){
                s -= it
                result.add(it)
                digits.remove(it)
                break
            }
        }
        m --
    }
    if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0){
        println("-1 -1")
        return
    }
    val resultString = result.joinToString(separator = "")
    print(if(resultString[0]!='0') "${resultString.reversed()} $resultString"
    else "$resultString $resultString")
}

fun main(){
    var input = readLine()!!.split(' ')
    val m = input[0].toInt()
    val s = input[1].toInt()
    if (m == 1 && s == 0){
        println("0 0")
        return
    }

    if ((1 > s)  || (s > 9 * m)){
        println("-1 1")
        return
    }

    var smallestNumberWithMDigits = CharArray(m){'0'}
    var greatestNumberWithMDigits = CharArray(m){'9'}
    smallestNumberWithMDigits[0] = '1'

    var startingIndex = m-1
    var digitSumVar = smallestNumberWithMDigits.sumBy { (it-'0') }
    while (digitSumVar + 9 <= s){
        digitSumVar += 9
        smallestNumberWithMDigits[startingIndex] = '9'
        startingIndex -= 1
    }

    while (digitSumVar < s){
        val current_digit = smallestNumberWithMDigits[startingIndex]
        smallestNumberWithMDigits[startingIndex] = current_digit + 1
        digitSumVar += 1
        if (current_digit == '8'){
            startingIndex -= 1
        }
    }

    startingIndex = m-1
    digitSumVar = greatestNumberWithMDigits.sumBy { (it-'0') }
    while (digitSumVar - 9 >= s){
        digitSumVar -= 9
        greatestNumberWithMDigits[startingIndex] = '0'
        startingIndex -= 1
    }

    while (digitSumVar > s){
        val current_digit = greatestNumberWithMDigits[startingIndex]
        greatestNumberWithMDigits[startingIndex] = current_digit - 1
        digitSumVar -= 1
        if (current_digit == '1'){
            startingIndex -= 1
        }
    }

    println("${smallestNumberWithMDigits.joinToString("")} ${greatestNumberWithMDigits.joinToString("")}");
}

fun readInts(): List<Int> = readLine()!!.split(" ").map{ it.toInt() }

fun main(){
    var (m, s) = readInts()
    val digits = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).sortedDescending().toMutableList()
    val result = mutableListOf<Int>()
    while(m != 0 || s != 0){
        for(it in digits) {
            if( s - it >= 0){
                s -= it
                result.add(it)
                digits.remove(it)
                break
            }
        }
        m --
    }
    if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0){
        println("-1 -1")
        return
    }
    val resultString = result.joinToString(separator = "")
    println(if(resultString[resultString.lastIndex]!='0') "${resultString.reversed()} $resultString"
    else "$resultString $resultString")
}

import kotlin.math.max

fun readInts(): List<Int> = readLine()!!.split(" ").map{ it.toInt() }
fun findMin(m: Int, s: Int): String{
    val digits = (m-2 downTo 0).toMutableList()
    val result = mutableListOf(max(1, s - 9*(m-1)))
    var auxS = s - result[0]
    var auxM = m - 1
    var index = 0
    while(auxM != 0 || auxS != 0){
        val value = max(0, auxS - 9 * digits[index])
        result.add(value)
        index ++
        auxS -= value
        auxM --
        if(auxM == 0) break
    }
    if(result.isEmpty() || auxM + auxS != 0){
        return "-1"
    }
    return result.joinToString(separator = "")
}
fun findMax(m: Int, s: Int): String{
    val digits = (9 downTo 0).toMutableList()
    var auxS = s
    var auxM = m
    val result = mutableListOf<Int>()
    var index = 0
    if( m == 1 && s <= 9)
    {
        return "$s"
    }
    while(auxM != 0 || auxS != 0){
        if(auxS - digits[index] >= 0){
            result.add(digits[index])
            auxS -= digits[index]
            auxM --
        }
        if(auxS < digits[index]){
            index ++
        }
        if(auxM == 0) break
    }
    if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0 || auxM + auxS != 0){
        return "-1"
    }
    return result.joinToString(separator = "")
}

fun main(){
    val (m, s) = readInts()

    println("${findMin(m, s)} ${findMax(m,s)}")
}

fun readInts(): List<Int> = readLine()!!.split(" ").map{ it.toInt() }

fun main(){
    var (m, s) = readInts()
    val digits = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).sortedDescending().toMutableList()
    val result = mutableListOf<Int>()
    while(m != 0 || s != 0){
        for(it in digits) {
            if( s - it >= 0){
                s -= it
                result.add(it)
                digits.remove(it)
                break
            }
        }
        m --
    }
    if(result.isEmpty()){
        println("-1 -1")
        return
    }
    val resultString = result.joinToString(separator = "")
    print(if(resultString[0]!='0') "${resultString.reversed()} $resultString"
    else "$resultString $resultString")
}

fun readInts(): List<Int> = readLine()!!.split(" ").map{ it.toInt() }

fun main(){
    var (m, s) = readInts()
    val digits = (9 downTo 0).toMutableList()
    val result = mutableListOf<Int>()
    var index = 0
    while(m != 0 || s != 0){
        if(s - digits[index] >= 0){
            if (digits[index] == 0 && result.isEmpty()) break
            result.add(digits[index])
            s -= digits[index]
            m --
        }
        if(s < digits[index]){
            index ++
        }
        if(m == 0) break
    }
    if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0 || m + s != 0){
        println("-1 -1")
        return
    }
    val resultStringHigh = result.joinToString(separator = "")
    val resultStringLow = if(resultStringHigh[resultStringHigh.lastIndex]!='0'){
        resultStringHigh.reversed()
    }
    else{
        val aux = StringBuilder()
        aux.append(resultStringHigh.reversed())
        aux[0] = aux.first { it != '0' }.also { aux[aux.indexOfFirst { it != '0' }]= aux[0] }
        aux.toString()
    }
    println("$resultStringLow $resultStringHigh")
}

fun readInts(): List<Int> = readLine()!!.split(" ").map{ it.toInt() }

fun main(){
    var (m, s) = readInts()
    val digits = (9 downTo 0).toMutableList()
    val result = mutableListOf<Int>()
    var index = 0
    while(m != 0 || s != 0){
        if(s - digits[index] >= 0){
            result.add(digits[index])
            s -= digits[index]
            m --
        }
        if(s < digits[index]){
            index ++
        }
        if(m == 0) break
    }
    if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0 || m + s != 0){
        println("-1 -1")
        return
    }
    val resultStringHigh = result.joinToString(separator = "")
    val resultStringLow = if(resultStringHigh[resultStringHigh.lastIndex]!='0'){
        resultStringHigh.reversed()
    }
    else{
        val aux = StringBuilder()
        aux.append(resultStringHigh.reversed())
        aux[0] = aux.first { it != '0' }.also { aux[aux.indexOfFirst { it != '0' }]= aux[0] }
        aux.toString()
    }
    println("$resultStringLow $resultStringHigh")
}

fun readInts(): List<Int> = readLine()!!.split(" ").map{ it.toInt() }

fun main(){
    var (m, s) = readInts()
    val digits = (9 downTo 0).toMutableList()
    val result = mutableListOf<Int>()
    var index = 0
    while(m != 0 && s != 0){
        if(s - digits[index] >= 0){
            if (digits[index] == 0 && digits.isEmpty()) break
            result.add(digits[index])
            s -= digits[index]
            m --
        }
        if(s < digits[index]){
            index ++
        }
    }
    if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0 || m + s != 0){
        println("-1 -1")
        return
    }
    val resultStringHigh = result.joinToString(separator = "")
    val resultStringLow = if(resultStringHigh[resultStringHigh.lastIndex]!='0'){
        resultStringHigh.reversed()
    }
    else{
        val aux = StringBuilder()
        aux.append(resultStringHigh.reversed())
        aux[0] = aux.first { it != '0' }.also { aux[aux.indexOfFirst { it != '0' }]= aux[0] }
        aux.toString()
    }
    println("$resultStringLow $resultStringHigh")
}

fun readInts(): List<Int> = readLine()!!.split(" ").map{ it.toInt() }

fun main(){
    var (m, s) = readInts()
    val digits = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).sortedDescending().toMutableList()
    val result = mutableListOf<Int>()
    while(m != 0 || s != 0){
        for(it in digits) {
            if( s - it >= 0){
                s -= it
                result.add(it)
                digits.remove(it)
                break
            }
        }
        m --
    }
    if(result.isEmpty()){
        println("-1 -1")
        return
    }
    val resultString = result.joinToString(separator = "")
    print(if(resultString[resultString.lastIndex]!='0') "${resultString.reversed()} $resultString"
    else "$resultString $resultString")
}

import java.util.*

fun findMin(n: Int, sum: Int): String {

	if ( sum == 0 ) return if ( n == 1 ) "0" else "-1"
	if ( sum > 9*n ) return "-1"

	val firstDigit = Math.max(1, sum - 9*(n-1))
	var left = sum - firstDigit

	val r = StringBuilder()
	r.append ( firstDigit )
	for ( i in n-2 downTo 0 ) {
		val d = Math.max ( 0, left - 9*i )
		r.append(d)
		left -= d
	}

	return r.toString()
}

fun findMax(n: Int, sum: Int): String {

	if ( sum == 0 ) return if ( n == 1 ) "0" else "-1"
	if ( sum > 9*n ) return "-1"

	val firstDigit = Math.min(9, sum)
	var left = sum - firstDigit

	val r = StringBuilder()
	r.append(firstDigit)
	for ( i in n-2 downTo 0 ) {
		val d = Math.min( 9, left )
		r.append(d)
		left -= d
	}

	return r.toString()
}

fun main(args : Array<String>) {
	val scan = Scanner (System.`in`)
	val n = scan.nextInt()
	val sum = scan.nextInt()

	val minSum = if ( n == 1 ) 0 else n
	val maxSum = n*9

	if ( sum < minSum || sum > maxSum ) {
		println("-1 -1")
		return
	}

	println ( findMin(n,sum) + " " + findMax(n, sum) )
}

import java.util.*

fun findMin(n: Int, sum: Int): String {

	if ( sum == 0 ) return if ( n == 1 ) "0" else "-1"
	if ( sum > 9*n ) return "-1"

	val firstDigit = Math.max(1, sum - 9*(n-1))
	var left = sum - firstDigit

	val r = StringBuilder()
	r.append ( firstDigit )
	for ( i in n-2 downTo 0 ) {
		val d = Math.max ( 0, left - 9*i )
		r.append(d)
		left -= d
	}

	return r.toString()
}

fun findMax(n: Int, sum: Int): String {

	if ( sum == 0 ) return if ( n == 1 ) "0" else "-1"
	if ( sum > 9*n ) return "-1"

	val firstDigit = Math.min(9, sum)
	var left = sum - firstDigit

	val r = StringBuilder()
	r.append(firstDigit)
	for ( i in n-2 downTo 0 ) {
		val d = Math.min( 9, sum )
		r.append(d)
		left -= d
	}

	return r.toString()
}

fun main(args : Array<String>) {
	val scan = Scanner (System.`in`)
	val n = scan.nextInt()
	val sum = scan.nextInt()

	val minSum = if ( n == 1 ) 0 else n
	val maxSum = n*9

	if ( sum < minSum || sum > maxSum ) {
		println("-1 -1")
		return
	}

	println ( findMin(n,sum) + " " + findMax(n, sum) )
}

import kotlin.math.min

/* template start */
// input
private fun readString() = readLine()!!
private fun readStrings() = readString().split(" ")
private fun readInt() = readString().toInt()
private fun readDigits() = readString().map { it - '0' }
private fun readInts() = readStrings().map { it.toInt() }
private fun readLongs() = readStrings().map { it.toLong() }

// output
private fun <T> T.print(map: (T) -> String = { it.toString() }) = println(map(this))
private fun <T> Iterable<T>.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)
private fun <T> Array<T>.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)
private fun IntArray.print(sep: String? = null, map: ((Int) -> String)? = null) = asSequence().print(sep, map)
private fun <T> Sequence<T>.print(sep: String? = null, map: ((T) -> String)? = null) =
    println(joinToString(sep ?: "", transform = map ?: { it.toString() }))

// others
private val Int.isEven: Boolean get() = this % 2 == 0
private val Int.isOdd: Boolean get() = !this.isEven
private fun queries(block: (Int) -> Unit) = repeat(readInt(), block)

/* template end */

fun main() {
    val (len, sum) = readInts()
    if (sum == 0) {
        if (len != 1) println("-1 -1")
        else println("0 0")
    } else if (len * 9 < sum) {
        println("-1 -1")
    } else {
        val maxNum = buildString {
            var rem = sum
            repeat(len) {
                val next = min(rem, 9)
                append(next)
                rem -= next
            }
        }
        var minNum = 0
        var factor = 1
        var rem = sum
        for (i in 0 until len) {
            if (rem > 1) {
                var next = min(rem - 1, 9)
                if (i == len - 1 && next < 9) {
                    next++
                }
                minNum += next * factor
                factor *= 10
                rem -= next
            } else {
                if (i == len - 1)
                    minNum += factor
                factor *= 10
            }
        }

        println("$minNum $maxNum")
    }

}


You have $$$n$$$ coins, each of the same value of $$$1$$$.Distribute them into packets such that any amount $$$x$$$ ($$$1 \leq x \leq n$$$) can be formed using some (possibly one or all) number of these packets.Each packet may only be used entirely or not used at all. No packet may be used more than once in the formation of the single $$$x$$$, however it may be reused for the formation of other $$$x$$$'s.Find the minimum number of packets in such a distribution.

The only line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$) — the number of coins you have.

Output a single integer — the minimum possible number of packets, satisfying the condition above.

NoteIn the first example, three packets with $$$1$$$, $$$2$$$ and $$$3$$$ coins can be made to get any amount $$$x$$$ ($$$1\leq x\leq 6$$$).  To get $$$1$$$ use the packet with $$$1$$$ coin.  To get $$$2$$$ use the packet with $$$2$$$ coins.  To get $$$3$$$ use the packet with $$$3$$$ coins.  To get $$$4$$$ use packets with $$$1$$$ and $$$3$$$ coins.  To get $$$5$$$ use packets with $$$2$$$ and $$$3$$$ coins  To get $$$6$$$ use all packets. In the second example, two packets with $$$1$$$ and $$$1$$$ coins can be made to get any amount $$$x$$$ ($$$1\leq x\leq 2$$$).

import java.io.*
import java.lang.Math.abs
import java.util.*
import kotlin.math.log2
import kotlin.math.max
import kotlin.math.sqrt

fun main(args : Array<String>) = Thread { run() }.start()
val scanner = Scanner(System.`in`)

fun run() {

    var n = scanner.nextInt()
    var q = 0
    while (n > 0) {
        q++
        n /= 2
    }
    println(q)

}

class Parser(`in`: InputStream) {
    private val BUFFER_SIZE = 1 shl 16
    private val din: DataInputStream
    private val buffer: ByteArray
    private var bufferPointer: Int = 0
    private var bytesRead: Int = 0

    init {
        din = DataInputStream(`in`)
        buffer = ByteArray(BUFFER_SIZE)
        bytesRead = 0
        bufferPointer = bytesRead
    }

    fun nextString(maxSize: Int): String {
        val ch = ByteArray(maxSize)
        var point = 0
        try {
            var c = read()
            while (c == ' '.toByte() || c == '\n'.toByte() || c == '\r'.toByte())
                c = read()
            while (c != ' '.toByte() && c != '\n'.toByte() && c != '\r'.toByte()) {
                ch[point++] = c
                c = read()
            }
        } catch (e: Exception) {}

        return String(ch, 0, point)
    }

    fun nextInt(): Int {
        var ret = 0
        val neg: Boolean
        try {
            var c = read()
            while (c <= ' '.toByte())
                c = read()
            neg = c == '-'.toByte()
            if (neg)
                c = read()
            do {
                ret = ret * 10 + c - '0'.toInt()
                c = read()
            } while (c > ' '.toByte())

            if (neg) return -ret
        } catch (e: Exception) {}
        return ret
    }

    fun nextLong(): Long {
        var ret: Long = 0
        val neg: Boolean
        try {
            var c = read()
            while (c <= ' '.toByte())
                c = read()
            neg = c == '-'.toByte()
            if (neg)
                c = read()
            do {
                ret = ret * 10 + c - '0'.toLong()
                c = read()
            } while (c > ' '.toByte())

            if (neg) return -ret
        } catch (e: Exception) {}

        return ret
    }

    fun nextDouble(): Double
            = nextString(10000).toDouble()

    private fun fillBuffer() {
        try {
            bytesRead = din.read(buffer, 0, BUFFER_SIZE)
        } catch (e: Exception) {}
        if (bytesRead == -1) buffer[0] = -1
    }

    private fun read(): Byte {
        if (bufferPointer == bytesRead) fillBuffer()
        return buffer[bufferPointer++]
    }
}
class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    var br: BufferedReader = BufferedReader(InputStreamReader(s))
    @Throws(IOException::class)
    operator fun next(): String {
        while (st == null || !st!!.hasMoreTokens())
            st = StringTokenizer(br.readLine())
        return st!!.nextToken()
    }
    @Throws(IOException::class)
    fun nextInt(): Int {
        return Integer.parseInt(next())
    }
    @Throws(IOException::class)
    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }
    @Throws(IOException::class)
    fun nextLine(): String {
        return br.readLine()
    }
    @Throws(IOException::class)
    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }
    @Throws(IOException::class)
    fun ready(): Boolean {
        return br.ready()
    }
}
fun IntArray.print() {
    println(Arrays.toString(this))
}
fun Array<IntArray>.print() {
    for (i in this)
        i.print()
}
fun LongArray.print() {
    println(Arrays.toString(this))
}
fun Array<LongArray>.print() {
    for (i in this)
        i.print()
}
fun BooleanArray.print() {
    println(Arrays.toString(this))
}
fun nod(a: Long, b: Long): Long {
    var a1 = a
    var b1 = b
    while (a1 != 0L && b1 != 0L) {
        if (a1 < b1)
            b1 %= a1
        else
            a1 %= b1
    }
    return a1 + b1
}
fun nok(a: Long, b: Long): Long = a * b / nod(a, b)
fun min(a: Char, b: Char): Int {
    if (a < b)
        return a.toInt()
    return b.toInt()
}
fun max(a: Char, b: Char): Int {
    if (a > b)
        return a.toInt()
    return b.toInt()
}

import java.io.*
import java.util.*

fun solve() {

    var n = nextInt()
    var ans = 0
    while (n > 0) {
        n /= 2
        ans++
    }

    println(ans)
}

fun hasNext() : Boolean {
    while (!st.hasMoreTokens()) {
        st = StringTokenizer(input.readLine() ?: return false)
    }
    return true
}

fun next() = if (hasNext()) st.nextToken()!! else throw RuntimeException("No tokens")

fun nextInt() = next().toInt()

fun nextLong() = next().toLong()

fun nextDouble() = next().toDouble()

fun nextLine() = if (hasNext()) st.nextToken("\n")!! else throw RuntimeException("No tokens")

fun nextArray(n : Int) = IntArray(n, { nextInt() })

val ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null

var input = when(ONLINE_JUDGE) {
    true -> BufferedReader(InputStreamReader(System.`in`), 32768)
    else -> BufferedReader(FileReader("in.txt"))
}

var output = when(ONLINE_JUDGE) {
    true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))
    else -> PrintWriter(BufferedWriter(FileWriter("out.txt")))
}

var st = StringTokenizer("")

fun main(args: Array<String>) {
    val start = System.currentTimeMillis()
    solve()

    output.close()
    input.close()

    if (!ONLINE_JUDGE) {
        //System.err.println("${System.currentTimeMillis() - start} ms")
    }
}

import kotlin.math.log2

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    println(log2(n.toDouble()).toInt() + 1)
}

import kotlin.math.*

fun main() {
    val n = readInt()

    val ans = n.toBigInteger().bitLength()

    println(ans)
}

fun readLn() = readLine()!!
fun readInt() = readLn().toInt()
fun readDouble() = readLn().toDouble()
fun readLong() = readLn().toLong()
fun readStrings() = readLn().split(' ')
fun readStringSeq() = readLn().splitToSequence(' ')
fun readInts() = readStrings().map { it.toInt() }
fun readIntSeq() = readStringSeq().map { it.toInt() }
fun readDoubles() = readStrings().map { it.toDouble() }
fun readDoubleSeq() = readStringSeq().map { it.toDouble() }
fun readLongs() = readStrings().map { it.toLong() }
fun readLongSeq() = readStringSeq().map { it.toLong() }

class Output {
    val outputSb = StringBuilder()
    fun print(o: Any?) { outputSb.append(o) }
    fun println() { outputSb.append('\n') }
    fun println(o: Any?) { outputSb.append(o).append('\n') }
    @JvmName("_print") fun Any?.print() = print(this)
    @JvmName("_println") fun Any?.println() = println(this)
    fun nowPrint() { kotlin.io.print(outputSb) }
}
inline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }

import java.util.*

fun main(args: Array<String> ) {
    val sc = Scanner( System.`in` )
    var n = sc.nextInt()
    var s = 1
    var r = 0
    while ( n > 0 ) {
        n -= s
        s *= 2
        r ++
    }
    println( r )
}

fun main() {
    val n = readLine()!!.toInt()
    var s = 0L
    var i = 1
    var x = 0
    while(s < n) {
        s+=i
        i*=2
        x++
    }
    println(x)
}

fun main() {
    val n = readLine()!!.toInt()
    var s = 0L
    var i = 1
    while(s < n) {
        s+=i
        i++
    }
    println(i-1)
}


Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.Limak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month.Limak chose one particular plan. He isn't sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him.

The only line of the input is in one of the following two formats:    "x of week" where x (1 ≤ x ≤ 7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday.  "x of month" where x (1 ≤ x ≤ 31) denotes the day of the month.

Print one integer — the number of candies Limak will save in the year 2016.

NotePolar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – https://en.wikipedia.org/wiki/Gregorian_calendar. The week starts with Monday.In the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total.In the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 — all months but February. It means that Limak will save 11 candies in total.

import java.time.LocalDate

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }
fun readDouble() = readString().toDouble()
fun readDoubles() = readStrings().map { it.toDouble() }

fun runTestCases(times: Int, block: () -> Unit) {
    for (i in 1..times)
        block()
}

fun main() {
    val s = readStrings()
    if (s[2] == "month") {
        if (s[0].toInt() <= 29)
            println(12)
        else if (s[0].toInt() <= 30)
            println(11)
        else
            println(7)
    }
    else {
        if (s[0].toInt() == 5 || s[0].toInt() == 6)
            println(53)
        else
            println(52)
    }
}

private fun toDecimal(str: String): Int {
    return str.toInt(2)
}

fun reverse(num: Int) =
    num.toString().reversed().toInt()

private operator fun String.times(n: Int): String {
    val sb = StringBuilder()
    for (i in 1..n)
        sb.append(this)
    return sb.toString()
}

import java.lang.StringBuilder
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.max

fun main() {
    var (num, i, key) = readLine()!!.split(' ')
    var number = num.toInt()
    if (!key.equals("week")) {
        if (1 <= number && number <= 29) {
            println(12)
        } else if ((number == 30 || number == 29)) {
            println(11)
        } else if (number == 31) {
            println(7)
        }
    } else {
        if (number == 6 || number == 5) {
            println(53)
        } else {
            println(52)
        }

    }
}

fun main() {
    val text = readLine()!!
    print(
        when {
            text == "30 of month" ->  11
            text == "31 of month" -> 7
            text.endsWith("month") -> 12
            text[0] == '5' -> 53
            text[0] == '6' -> 53
            else -> 52
        }
    )
}

import java.time.LocalDate

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }
fun readDouble() = readString().toDouble()
fun readDoubles() = readStrings().map { it.toDouble() }

fun runTestCases(times: Int, block: () -> Unit) {
    for (i in 1..times)
        block()
}

fun main() {
    val s = readStrings()
    if (s[2] == "month") {
        if (s[0].toInt() >= 30)
            println(11)
        else
            println(12)
    }
    else {
        if (s[0].toInt() == 5 || s[0].toInt() == 6)
            println(53)
        else
            println(52)
    }
}

private fun toDecimal(str: String): Int {
    return str.toInt(2)
}

fun reverse(num: Int) =
    num.toString().reversed().toInt()

private operator fun String.times(n: Int): String {
    val sb = StringBuilder()
    for (i in 1..n)
        sb.append(this)
    return sb.toString()
}


The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (https://en.wikipedia.org/wiki/Leap_year).

The only line contains integer y (1000 ≤ y < 100'000) — the year of the calendar.

Print the only integer y' — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.

NoteToday is Monday, the 13th of June, 2016.

import java.util.*
import kotlin.collections.*
import kotlin.math.*

private fun readLn() = readLine()!! // string
private fun readInt() = readLn().toInt() // int
private fun readStrings() = readLn().split(" ") // string string
private fun readInts() = readStrings().map { it.toInt() } // int int

fun isLeapYear(y: Int) = ((y%400 == 0) || (y%4 == 0 && y%100 != 0))

fun main() {
    var n = readInt()
    val isl = isLeapYear(n)
    var nextfake = 0
    var ans = n
    do {
        ans++
        nextfake = if (isLeapYear(ans) == true) (nextfake + 2)%7  else (nextfake + 1)%7
        //println(nextfake)
    } while (nextfake != 0 || isLeapYear(ans) != isl)
    print(ans)
}