description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
ma = [] mi = [] def max_find_digit(nod, sum): global ma if nod > 1: t = sum - (nod - 1) * 9 if t > 9 or sum == 0: return if t < 0: t = 0 ma.append(t) if sum - t >= 0: max_find_digit(nod - 1, sum - t) return else: if sum >= 0 and sum < 10: ma.append(sum) return def min_find_digit(nod, sum): global mi if nod > 1: t = sum - (nod - 1) * 9 if t > 9 or sum == 0: return if t < 1: t = 1 mi.append(t) def max_find_digit(nod, sum): if nod > 1: t = sum - (nod - 1) * 9 if t < 0: t = 0 mi.append(t) if sum - t >= 0: max_find_digit(nod - 1, sum - t) return else: if sum >= 0 and sum < 10: mi.append(sum) return max_find_digit(nod - 1, sum - t) return else: if sum >= 0 and sum < 10: mi.append(sum) return x = [] x = input().split() x[0] = int(x[0]) x[1] = int(x[1]) max_find_digit(x[0], x[1]) min_find_digit(x[0], x[1]) ma = ma[::-1] m = [] if len(mi) < x[0]: m.append(-1) else: min = "" for i in range(x[0]): min = min + str(mi[i]) m.append(int(min)) if len(ma) < x[0]: m.append(-1) else: max = "" for i in range(x[0]): max = max + str(ma[i]) m.append(int(max)) print(m[0], m[1])
ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_DEF IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if 9 * m < s or s == 0 and m > 1: print("-1 -1") elif s == 0 and m == 1: print("0 0") else: mx = ( s // 9 * "9" + (str(s % 9) if s % 9 else "") + (m - s // 9 - (s % 9 != 0)) * "0" ) mn = "" for i in range(m): for j in range(i == 0, 10): if 9 * (m - i - 1) >= s - j: mn += str(j) s -= j break print(mn, mx)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
import sys m, s = map(int, input().split()) if s == 0: if m == 1: print(0, 0) else: print(-1, -1) sys.exit() tas = s a = [0] * m a[0] = 1 tas -= 1 index = m - 1 while tas > 0: if index == -1: break a[index] += 1 if a[index] == 9: index -= 1 tas -= 1 res = [-1, -1] if tas == 0: res[0] = 0 for i in a: res[0] = res[0] * 10 + i tbs = s b = [0] * m b[0] = 1 tbs -= 1 index = 0 while tbs > 0: if index == m: break b[index] += 1 if b[index] == 9: index += 1 tbs -= 1 if tbs == 0: res[1] = 0 for i in b: res[1] = res[1] * 10 + i print(res[0], res[1])
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
n, m = map(int, input().split()) l = m if n != 1 and m == 0: print(-1, -1) elif n == 1 and m == 0: print(0, 0) elif m > n * 9: print(-1, -1) else: i = 0 s = [0] * n a = [0] * n while i < n and m != 0: s[i] += min(9, m) m -= s[i] i += 1 i = n - 1 while i > -1: a[i] += min(9, l) l -= a[i] if l == 0: a[i] -= 1 a[0] += 1 break i -= 1 print(*a, sep="", end=" ") print(*s, sep="")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) min_num = [0] * m if s == 0 and m == 1: print("0 0") exit(0) if s == 0 or s > m * 9: print("-1 -1") exit(0) ci = len(min_num) - 1 s1 = s while s > 0: a = min(9, s) s -= a min_num[ci] = a ci -= 1 if min_num[0] == 0: min_num[0] = 1 for i in range(1, len(min_num)): if min_num[i] > 0: min_num[i] -= 1 break max_num = [0] * m ci = 0 while s1 > 0: a = 9 if s1 >= 9 else s1 s1 -= a max_num[ci] = a ci += 1 print("".join(map(str, min_num)), "".join(map(str, max_num)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
reader = input().split() s, m = map(int, reader) n = m - 1 s1 = s if m == 0 and s == 1: print(0, 0) elif m == 0 and s > 1: print(-1, -1) elif m > s * 9: print(-1, -1) else: result = "" while s1 - 1: s1 -= 1 if n > 9: result = "9" + result n -= 9 else: result = str(n) + result n = 0 result = str(n + 1) + result print(result) while m: s -= 1 if m > 9: print(9, end="") m -= 9 else: print(m, end="") m = 0 for _ in range(s): print(0, end="")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING WHILE BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
from sys import exit m, s = map(int, input().split()) if m == 1 and s == 0: print(0, 0) elif m > 1 and s == 0: print(-1, -1) else: e = s // 9 r = s % 9 q = e if r > 0: q += 1 if q > m: print(-1, -1) from sys import exit exit() mi, ma = "", "" if r == 0: r = 9 e -= 1 for i in range(e): mi += "9" ma += "9" if m - e == 1: mi = str(r) + mi ma += str(r) print(mi, ma) else: ma += str(r) mi = str(r - 1) + mi for i in range(m - e - 2): mi = "0" + mi ma += "0" mi = "1" + mi ma += "0" print(mi, ma)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR STRING ASSIGN VAR BIN_OP STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
import sys input = sys.stdin.readline m, s = map(int, input().split()) big, samll = [], [] if 1 <= s <= 9 * m: ss = s for i in range(m): v = min(9, ss) ss -= v big.append(v) samll = [*big] if samll[-1] == 0: last = -1 for i in range(len(samll) - 1, -1, -1): if samll[i] != 0: last = i break samll[-1] = 1 samll[last] -= 1 print(*samll[::-1], sep="", end=" ") print(*big, sep="") elif s == 0 and m == 1: print(0, 0) else: print(-1, -1)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST IF NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING STRING EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = [int(x) for x in input().split()] a = "" b = "" na = s nb = s if 9 * m < s or s == 0 and m != 1: print("-1 -1") elif s == 0 and m == 1: print("0 0") else: for i in reversed(range(m)): x = na if x <= 9 and i != 0: x -= 1 y = nb if x >= 10: x = 9 elif x < 0: x = 0 if y >= 10: y = 9 elif y < 0: y = 0 a = str(x) + a na -= x b += str(y) nb -= y print(a + " " + b)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
solutions = [] dp = {} firstCall = True def sumFromLength(s, l, sum=0): global solutions global dp global firstCall if l == 1: num = sum * 10 + s solutions.append(num) return else: till = -1 if firstCall: till = 0 firstCall = False for i in range(9, till, -1): if s - i >= 0 and s - i <= 9 * (l - 1): num = sum * 10 + i sumFromLength(s - i, l - 1, num) break arr = [int(x) for x in input().split()] l = arr[0] s = arr[1] if s <= 9 * l: sumFromLength(s, l) if len(solutions) > 0: num = str(solutions[0]) if s > 1: arr = [int(x) for x in num] arr.reverse() if arr[0] == 0: arr[0] = 1 for i in range(1, len(arr)): if arr[i] > 0: arr[i] -= 1 break num = "".join(map(str, arr)) print(str(num) + " " + str(solutions[0])) else: print("-1 -1") else: print("-1 -1")
ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = input().split(" ") m = int(m) s = int(s) m1 = m s1 = s l = [] sm = [] def large(m, s): if s >= 9 and 9 * m >= s: l.append(9) m = m - 1 s = s - 9 while m > 0: if s > 9: l.append(9) s = s - 9 m = m - 1 else: l.append(s) s = 0 m = m - 1 elif s > 0 and s < 9 and m != 0: l.append(s) m = m - 1 while m > 0: l.append(0) m = m - 1 elif s == 0 and m > 1: print(-1, -1) elif s == 0 and m == 0: print(-1, -1) elif s == 0 and m == 1: print(0, 0) elif s > 0 and m == 0: print(-1, -1) elif 9 * m < s: print(-1, -1) large(m, s) def small(m, s): if s >= 9 and 9 * m >= s: while m > 0: if s > 9: sm.append(9) s = s - 9 m = m - 1 elif m != 1: sm.append(s - 1) m = m - 1 s = 1 else: sm.append(s) m = m - 1 s = 0 sm.sort() if sm[0] == 0: for i in range(0, m1): if sm[i] != 0: temp = sm[0] sm[0] = sm[i] sm[i] = temp break if s < 9 and 9 * m >= s: while m > 0: if m != 1: sm.append(s - 1) m = m - 1 s = 1 else: sm.append(s) m = m - 1 s = 0 sm.sort() if sm[0] == 0: for i in range(0, m1): if sm[i] != 0: temp = sm[0] sm[0] = sm[i] sm[i] = temp break small(m1, s1) if s1 != 0 and m1 > 0: s = "" for i in sm: s = s + str(i) print(s, end=" ") if s1 != 0 and m1 > 0: s = "" for i in l: s = s + str(i) print(s)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER BIN_OP NUMBER VAR VAR WHILE VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER BIN_OP NUMBER VAR VAR WHILE VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
L = input().split() Len = int(L[0]) sum = int(L[1]) if sum == 0: if Len == 1: print("0 0") else: print("-1 -1") elif sum > 9 * Len: print("-1 -1") elif int(Len) == 1: print(str(sum), str(sum)) else: s = 0 out = "" for i in range(Len): if 9 * (s + 1) < sum: s += 1 left = sum - 9 * s for i in range(s): out += "9" out += str(left) a = Len - len(out) if a == 0: largest = out if a > 0: for i in range(a): out += "0" largest = out a = sum - 9 * (Len - 1) if a > 0: out = str(a) for i in range(Len - 1): out += "9" smallest = out else: n = 0 for i in range(Len): if sum > 9 * (n + 1): n += 1 b = sum - 9 * n if b == 1: zero = Len - n - 1 out = "1" for i in range(zero): out += "0" for i in range(n): out += "9" smallest = out else: if Len - n - 1 == 0: out = str(b) for i in range(n): out += "9" smallest = out if Len - n - 1 == 1: out = "1" + str(b - 1) for i in range(n): out += "9" smallest = out if Len - n - 1 > 1: zero = Len - n - 2 out = "1" for i in range(zero): out += "0" out += str(b - 1) for i in range(n): out += "9" smallest = out print(smallest, largest)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
[m, s] = list(map(int, input().split())) if s == 0: if m > 1: print(-1, -1) else: print(0, 0) elif s > 9 * m: print(-1, -1) else: boro = "" choto = "" inc1 = 0 inc2 = 0 for i in range(m): for dig in range(10): if i == 0 and dig == 0: continue if inc1 + dig <= s and s <= inc1 + dig + 9 * (m - i - 1): inc1 += dig choto += str(dig) break inc1 = 0 for i in range(m): for dig in range(9, -1, -1): if inc1 + dig <= s and s <= inc1 + dig + 9 * (m - i - 1): inc1 += dig boro += str(dig) break print(int(choto), int(boro))
ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
from sys import stdin, stdout read = lambda: map(int, stdin.readline().split()) I = lambda: stdin.readline() m, s = read() if s == 0 and m > 1 or s > 9 * m: print(-1, -1) exit() ans1 = ["0" for i in range(m)] ans2 = ["0" for i in range(m)] s1, s2 = s - 1, s for i in range(m - 1, 0, -1): if s1 > 9: s1 -= 9 ans1[i] = "9" elif s1 > 0: ans1[i] = str(s1) s1 = 0 ans1[0] = str(s1 + 1) i = 0 while s2 > 0 and i < m: if s2 > 9: ans2[i] = "9" s2 -= 9 else: ans2[i] = str(s2) s2 = 0 i += 1 f1 = lambda l: "".join(l) print(f1(ans1), f1(ans2))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR STRING IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if m == 1 and s == 0: print("0" + " " + "0") exit(0) if m == 0 or s > 9 * m or s == 0 and m != 1: print("-1" + " " + "-1") exit(0) sumV = 0 for i in range(m): temp = 1 if i == 0 else 0 while s - sumV - temp > 9 * (m - (i + 1)) and temp < 9: temp += 1 sumV += temp print(temp, end="") sumV = 0 print(" ", end="") for i in range(m): temp = 9 while sumV + temp > s and temp > 0: temp -= 1 sumV += temp print(temp, end="")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING STRING STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING STRING STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER WHILE BIN_OP BIN_OP VAR VAR VAR BIN_OP NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
line = input() m = int(line.split()[0]) s = int(line.split()[1]) l = [] p = [] if s == 0 and m == 1: print("0 0") elif s == 0 or s > 9 * m: print("-1 -1") elif m == 1: print(s, s) else: if s < 10: x = s * 10 ** (m - 1) y = 10 ** (m - 1) + s - 1 print(y, x) if s >= 10: if s > 9 * (m - 1): p.append(s - 9 * (m - 1)) for i in range(m - 1): l.append(9) p.append(9) l.append(s - 9 * (m - 1)) else: yu1 = s // 9 yu2 = s % 9 if yu2 != 0: p.append(1) for i in range(yu1): l.append(9) l.append(yu2) for i in range(m - yu1 - 1): l.append(0) for i in range(m - yu1 - 2): p.append(0) p.append(yu2 - 1) for i in range(yu1): p.append(9) if yu2 == 0: p.append(1) for i in range(yu1): l.append(9) for i in range(m - yu1): l.append(0) for i in range(m - yu1 - 1): p.append(0) p.append(8) for i in range(yu1 - 1): p.append(9) q = [str(k) for k in p] qq = [str(i) for i in l] print("".join(q), "".join(qq))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
[n, s] = [int(k) for k in input().split()] def dp(n, s): if s <= 9: mini = "1" if n >= 2: for k in range(n - 2): mini = mini + "0" mini = mini + str(s - 1) else: mini = str(s) maxi = str(s) for i in range(n - 1): maxi = maxi + "0" return [mini, maxi] else: L = dp(n - 1, s - 9) return [L[0] + "9", "9" + L[1]] if s == 0 and n > 1 or s > 9 * n: print("-1 -1") else: print(dp(n, s)[0], dp(n, s)[1])
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING RETURN LIST VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN LIST BIN_OP VAR NUMBER STRING BIN_OP STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
n, s = map(int, input().split()) s2 = s if s == 0 and n == 1: print(0, 0) exit(0) if s == 0 and n > 1: print(-1, -1) exit(0) if n * 9 < s: print(-1, -1) exit(0) big = [] while s != 0: if s - 9 < 0: big.append(str(s)) break else: big.append("9") s -= 9 size = n - len(big) if size == 0: print("".join(big[::-1]), "".join(big)) else: big += ["0"] * size small = big[::-1] small[0] = "1" small[size] = str(int(small[size]) - 1) print("".join(small), "".join(big))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER FUNC_CALL STRING VAR VAR BIN_OP LIST STRING VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def fail(): print(-1, -1) exit() read = lambda: map(int, input().split()) m, s = read() cnt = s // 9 x = s % 9 if cnt + (x > 0) > m: fail() if s == 0 and m > 1: fail() Max = "9" * cnt if x: Max += str(x) Max += "0" * (m - len(Max)) Min = list(Max[::-1]) if Min[0] == "0" and s: Min[0] = "1" for i in range(1, m): if Min[i] != "0": Min[i] = str(int(Min[i]) - 1) break Min = "".join(Min) print(Min, Max)
FUNC_DEF EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING VAR IF VAR VAR FUNC_CALL VAR VAR VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
line = input() ll = line.split() n = int(ll[0]) m = int(ll[1]) if n != 1 and m == 0 or 9 * n < m: print("-1 -1") else: h = "" for i in range(n): if m - 9 <= 0: break m -= 9 h += "9" h1 = h + str(m) H = len(h) for i in range(n - H - 1): h1 += "0" if n - H == 1: h2 = str(m) + h if n - H > 1: h2 = str(m - 1) + h for i in range(n - H - 2): h2 = "0" + h2 h2 = "1" + h2 print(h2, h1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
import sys m, s = map(int, sys.stdin.readline().split()) if s == 0 and m == 1: print(0, 0) elif s >= 1 and s <= 9 * m: if s == 9 * m: print("9" * m, "9" * m) elif s >= 9 * m - 8: print(str(s % 9) + "9" * (m - 1), "9" * (m - 1) + str(s % 9)) else: t = (s - 1) // 9 i = s - 9 * t - 1 s_min = "1" + "0" * (m - t - 2) + str(i) + "9" * t t2 = s // 9 i2 = s % 9 s_max = "9" * t2 + str(i2) + "0" * (m - t2 - 1) print(s_min, s_max) else: print(-1, -1)
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP STRING VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER BIN_OP BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if s == 0 and m == 1: mn = 0 mx = 0 elif s == 0 and m != 1 or s > m * 9: mn = -1 mx = -1 elif s < 10 and m == 1: mn = s mx = s elif s < 10 and m > 1: mn = "1" + "0" * (m - 2) + str(s - 1) mx = str(s) + "0" * (m - 1) elif s // m == 9: mn = "9" * m mx = "9" * m else: nine = s // 9 ost = s % 9 mx = "9" * nine + str(ost) + "0" * (m - nine - 1) if m - nine == 1 and ost == 0: mn = "18" + "9" * (nine - 1) elif m - nine == 1 and ost != 0: mn = str(ost) + "9" * nine elif m - nine > 1 and ost == 0: mn = "1" + "0" * (m - nine - 1) + "8" + "9" * (nine - 1) else: mn = "1" + "0" * (m - nine - 2) + str(ost - 1) + "9" * nine print(mn, mx)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = [int(i) for i in input().split()] if m == 1 and s == 0: print(0, 0, sep=" ") elif m > 1 and s == 0: print(-1, -1, sep=" ") elif m > s: min_ = "" len_ = s len_ -= 1 curr = 0 while curr < m - 1: k = min(9, len_) min_ = str(k) + min_ curr += 1 len_ -= k min_ = str(max(len_ + 1, 1)) + min_ max_ = "" while s: k = min(9, s) max_ += str(k) s -= k max_ += "0" * (m - len(max_)) print(min_, max_) elif s > 9 * m: print(-1, -1) else: max_ = "" len_ = s while len_: k = min(9, len_) max_ += str(k) len_ -= k if len(max_) < m: max_ += "0" * (m - len(max_)) min_ = "" s -= 1 curr = 0 while curr < m - 1: k = min(9, s) min_ = str(k) + min_ s -= k curr += 1 min_ = str(max(s + 1, 1)) + min_ print(min_, max_)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER STRING IF VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR STRING WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if m == 1 and s == 0: print("0 0") elif s == 0 or m * 9 < s: print("-1 -1") else: smallest = ( "1" + "0" * (m - s // 9 - 1) + "9" * (s // 9) if s % 9 == 1 and s // 9 + 1 < m else ( str(s % 9) + "9" * (s // 9) if s // 9 + 1 == m else ( "9" * (s // 9) if s // 9 == m else "1" + "0" * (m - 2 - (s - 1) // 9) + str((s - 1) % 9) + "9" * ((s - 1) // 9) ) ) ) largest = ( "9" * (s // 9) + "0" * (m - s // 9) if s % 9 == 0 else "9" * (s // 9) + str(s % 9) + "0" * (m - s // 9 - 1) ) print(smallest, largest)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = input().split() m = int(m) s = int(s) l1 = 0 l2 = 0 if s == 0: if m > 1: l1 -= 1 l2 -= 1 elif m == 1: l1 = 0 l2 = 0 elif 9 * m < s: l1 -= 1 l2 -= 1 elif s == 9 * m: l1 = l2 = 10**m - 1 elif s > 9: t = int(s / 9) if m <= 2: l1 += (s - 9 * t) * 10 ** (m - 1) for i in range(1, t + 1): l1 += 9 * 10 ** (i - 1) else: l1 += 10 ** (m - 1) l1 += 10**t - 1 if s > 9 * t: l1 += (s - 9 * t - 1) * 10**t else: l1 -= 10 ** (t - 1) l2 += (s - 9 * t) * 10 ** (m - t - 1) for i in range(1, t + 1): l2 += 9 * 10 ** (m - i) else: l1 = 10 ** (m - 1) + s - 1 l2 = s * 10 ** (m - 1) print("%s %d" % (l1, l2))
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = (int(t) for t in input().split()) if (m, s) == (1, 0): print(0, 0) elif s > 9 * m or s < 1: print(-1, -1) elif s == 1: print("1" + "0" * (m - 1) + " " + "1" + "0" * (m - 1)) elif s == 9 * m: print("9" * m + " " + "9" * m) else: minim = [1] + [0] * (m - 1) tmp = s - 1 index = m - 1 while tmp != 0: if tmp < 9: minim[index] += tmp tmp = 0 else: minim[index] += 9 tmp -= 9 index -= 1 for i in range(m): print(minim[i], end="") print(" ", end="") maxim = [0] * m tmp = s index = 0 while tmp != 0: if tmp < 9: maxim[index] += tmp tmp = 0 else: maxim[index] += 9 tmp -= 9 index += 1 for i in range(m): print(maxim[i], end="")
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER STRING STRING BIN_OP STRING BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR STRING BIN_OP STRING VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
s = input() s = s.split() l = int(s[0]) su = int(s[1]) if su < 1 or su > 9 * l: if su == 0 and l == 1: print(0, 0) else: print("-1 -1") else: list1 = l * ["0"] list2 = l * ["0"] su1 = su su2 = su i = 0 while su1 > 9: list1[i] = str(9) i = i + 1 su1 -= 9 list1[i] = str(su1) k = l - 1 list2[0] = "1" su2 -= 1 while su2 > 9: list2[k] = str(9) k -= 1 su2 -= 9 list2[k] = str(int(list2[k]) + su2) print("".join(list2), "".join(list1))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR LIST STRING ASSIGN VAR BIN_OP VAR LIST STRING ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER STRING VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
n, m = map(int, input().split()) mm = m if m == 0 and n > 1: print("-1 -1") elif m == 0 and n == 1: print(0, 0) elif m > 9 * n: print("-1 -1") else: l = [0] * n maxi = "" mini = "" for i in range(n): l[i] = min(9, m) m = m - l[i] maxi += str(l[i]) if min(l) != 0: l.reverse() for i in range(n): mini += str(l[i]) else: l = [0] * (n - 1) mm = mm - 1 mini = "1" for i in range(n - 1): l[i] = min(9, mm) mm = mm - l[i] l.reverse() for i in range(n - 1): mini += str(l[i]) print(mini, maxi)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
p, q = map(int, input().strip().split()) memo = {} arr = [] def dp(m, s, o): if s <= m * 9 and s >= 0: if o == 0: for i in range(1, 10): if dp(m - 1, s - i, o + 1) == 1: arr.append(i) break else: for i in range(10): if dp(m - 1, s - i, o + 1) == 1: arr.append(i) break return 1 else: return 0 arrl = [] def dpl(m, s, o): if s <= m * 9 and s >= 0: if o == 0: for i in range(9, 0, -1): if dpl(m - 1, s - i, o + 1) == 1: arrl.append(i) break else: for i in range(9, -1, -1): if dpl(m - 1, s - i, o + 1) == 1: arrl.append(i) break return 1 else: return 0 dp(p, q, 0) dpl(p, q, 0) arr.reverse() arrl.reverse() if len(arr) == 0: if p == 1 and q == 0: print("0 0") else: print("-1 -1") else: print("".join(map(str, arr)) + " " + "".join(map(str, arrl)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
import sys def find_largest(m, s): ts = s ds = [(0) for i in range(m)] for i in range(m): ds[i] = str(min(ts, 9)) ts -= min(ts, 9) if ts > 0: return -1 else: d = "".join(ds) return int(d) def find_smallest(m, s): ts = s - 1 ds = [(0) for i in range(m)] ds[0] = "1" for i in range(m): ds[i] = str(min(ts, 9)) ts -= min(ts, 9) if ts > 0 or int(ds[-1]) > 8: return -1 else: ds[-1] = str(int(ds[-1]) + 1) d = "".join(ds[::-1]) return int(d) def solve(m, s): if s == 0 and m == 1: return 0, 0 if s == 0 and m > 1: return -1, -1 largest = find_largest(m, s) smallest = find_smallest(m, s) return smallest, largest inputs = [] for line in sys.stdin: inputs.append(line.strip()) m, s = map(int, inputs[0].split()) x, y = solve(m, s) sys.stdout.write("{} {}\n".format(x, y))
IMPORT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL STRING VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = [int(i) for i in input().split()] if m == 1 and s == 0: print(0, 0) elif 9 * m < s or 1 > s: print("-1 -1") else: mx = "" while len(mx) < m and sum([int(i) for i in mx]) + 9 <= s: mx += "9" if sum([int(i) for i in mx]) != s: mx += str(s - sum([int(i) for i in mx])) while len(mx) < m: mx += "0" mn = list(mx[::-1]) if mn[0] == "0": mn[0] = "1" for i in range(1, len(mn)): if mn[i] != "0": mn[i] = str(int(mn[i]) - 1) break print("".join(mn), mx)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR STRING IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = input().split() m = int(m) s = int(s) ls = [] if s == 0 and m == 1: print("0 0") else: while s > 9: ls.append(9) s = s - 9 else: ls.append(s) ls1 = [str(i) for i in ls] a = "".join(ls1) if len(a) > m or a == "0": print("-1 -1") elif len(a) == m: print(a[::-1], a) else: b = "1" + (m - len(a) - 1) * "0" + str(int(a) - 1)[::-1] a = a + (m - len(a)) * "0" print(b, a)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
number1 = [] number2 = [] m, s = (int(x) for x in input().split()) y = s for i in range(m): for j in range(1, 11): if s - 10 + j >= 0: number1.append(10 - j) s = s - 10 + j break s = y for l in range(1, 10): if s - l <= 9 * (m - 1) and s - l >= 0: number2.append(l) s = s - l break for k in range(m - 1): for c in range(10): if s - c <= 9 * (m - k - 2): number2.append(c) s = s - c break if len(number2) == m and len(number1) == m: for v in range(len(number1)): number1[v] = str(number1[v]) number2[v] = str(number2[v]) print("".join(number2), "".join(number1)) elif m == 1 and s == 0: print(0, 0) else: print(-1, -1)
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = [int(x) for x in input().split()] if s == 0 and m == 1: print("0 0") elif s < 1 or s > 9 * m: print("-1 -1") else: a = [1] + [0] * (m - 1) a_cnt = s - 1 for i in range(m - 1, -1, -1): if a_cnt > 9: a_cnt -= 9 a[i] += 9 else: a[i] += a_cnt break b = [0] * m b_cnt = s for i in range(0, m): if b_cnt > 9: b_cnt -= 9 b[i] += 9 else: b[i] += b_cnt break print("".join([str(x) for x in a]) + " " + "".join([str(x) for x in b]))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
s, m = [int(i) for i in input().split()] if m == 0 and s != 1 or 9 * s < m: print(-1, -1) elif m == 0 and s == 1: print(0, 0) else: a = m // 9 b = m % 9 if b == 0: nmax = "".join(["9" * a, "0" * (s - a)]) nmin = "".join( [ "1" * bool(s - a > 0), "0" * max(s - a - 1, 0), "8" * bool(s - a > 0), "9" * (a - 1) * bool(s - a > 0), "9" * a * bool(s - a == 0), ] ) else: nmax = "".join(["9" * a, str(b), "0" * (s - a - 1)]) nmin = "".join( [ "1" * bool(s - a - 1 > 0), "0" * max(s - a - 2, 0), str((b - 1) * bool(s - a - 1 > 0) + b * bool(s - a - 1 == 0)), "9" * a, ] ) print(nmin, nmax)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL STRING LIST BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR FUNC_CALL STRING LIST BIN_OP STRING FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP STRING FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP STRING FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP STRING VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING LIST BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING LIST BIN_OP STRING FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP STRING FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
import sys m, s = [int(x) for x in input().split()] if m > 1 and s == 0: print("-1 -1") sys.exit() f = [[([0] * (s + 1)) for j in range(10)] for i in range(0, m + 1)] for j in range(min(10, s + 1)): f[1][j][j] = 1 for i in range(2, m + 1): for j in range(min(10, s + 1)): for k in range(s + 1): if k >= j: for t in range(min(10, s + 1)): f[i][j][k] = f[i][j][k] | f[i - 1][t][k - j] max_value = [] tmp = s for i in range(m, 0, -1): flag = 0 for j in range(9, -1, -1): if f[i][j][tmp] == 1: flag = j break max_value.append(flag) tmp -= flag if i == m and flag == 0: break if tmp > 0: print("-1 -1") sys.exit() min_value = [] tmp = s for i in range(m, 0, -1): flag = 0 t = 0 if i == m: t = 1 for j in range(t, 10): if f[i][j][tmp] == 1: flag = j break min_value.append(flag) tmp -= flag if i == m and flag == 0: break if tmp > 0: print("-1 -1") sys.exit() for i in min_value: print(i, end="") print(" ", end="") for i in max_value: print(i, end="")
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
t = tuple(map(int, input().split())) a = t[1] // t[0] if t[0] == 1 and t[1] == 0: print("0 0") elif a > 9 or a == 9 and t[1] % t[0] != 0 or t[1] == 0: print("-1 -1") else: s = [a] * t[0] c = t[1] % t[0] for i in range(c): p = min(c, 9 - s[-1 - i]) c -= p s[-1 - i] += p i, j = 0, t[0] - 1 while i < j: if min(9 - s[j], s[i] - int(i == 0)) == 9 - s[j]: s[i] -= 9 - s[j] s[j] = 9 j -= 1 else: s[j] += s[i] - int(i == 0) s[i] = int(i == 0) i += 1 for i in s: print(i, end="") print(" ", end="") i, j = 0, t[0] - 1 while i < j: if min(9 - s[j], s[i]) == 9 - s[j]: s[i] -= 9 - s[j] s[j] = 9 j -= 1 else: s[j] += s[i] s[i] = 0 i += 1 for i in s[::-1]: print(i, end="") print("")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF FUNC_CALL VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def stringify(l): s = "" for i in l: s += str(i) return s m, s = map(int, input().split()) mc = m sc = s ans = [] rans = [] if sc > mc * 9 or sc == 0 and mc > 1: ans = [-1] rans = [-1] elif mc == 1 and sc == 0: ans = [0] rans = [0] else: while m: if s >= 9: s -= 9 rans.append(9) elif s < 9 and s > 0: rans.append(s) s = 0 else: rans.append(0) m -= 1 ans = rans.copy() if mc > 2 and sc > 1: fl = 0 for i in range(mc - 1): if ans[i] < 9: ans[i] -= 1 fl = 1 if ans[i] == -1: ans[i] = 0 ans[i - 1] = 8 break if fl: ans[mc - 1] = 1 ans = ans[::-1] elif mc == 2 and sc > 9: ans = ans[::-1] elif mc == 2 and sc <= 9: ans[0] -= 1 ans[1] = 1 ans = ans[::-1] print(stringify(ans), stringify(rans))
FUNC_DEF ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER WHILE VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def solve(m, s): if s == 0 and m > 1: return -1, -1 if s == 0 and m == 1: return 0, 0 g = "" nines = "9" * (s // 9) remaining = str(s % 9) rest = remaining if remaining != "0" else "" cur_size = len(nines) + len(rest) if cur_size > m: return -1, -1 g = nines + rest + "0" * (m - cur_size) l = g[::-1] if l[0] == "0": l = "1" + l[1:] for i, v in enumerate(l[1:], 1): if v != "0": l = l[:i] + str(int(v) - 1) + l[i + 1 :] break return l, g def main(): m, s = list(map(int, input().split())) print(*solve(m, s)) main()
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR BIN_OP STRING VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
x, y = [int(t) for t in input().split()] num = y if y == 0 and x != 1 or y > 9 * x: print("-1 -1") exit() else: mini = 0 maxi = 0 n = 0 while y > 9: mini += 10**n * 9 y -= 9 n += 1 mini = mini + (y - 1) * 10**n + 10 ** (x - 1) n = x - 1 y = num while y > 9: maxi += 10**n * 9 y -= 9 n -= 1 maxi = maxi + y * 10**n print(mini, maxi)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) op1 = [] op2 = [] def ismax(m, s): if s == 0 or s > 9 * m: return "-1" else: for i in range(m): if s > 9: op2.append("9") s -= 9 elif 1 <= s <= 9: op2.append(str(s)) s = 0 else: op2.append("0") return int("".join(op2)) def ismin(m, s): if s == 0 or s > 9 * m: return "-1" elif m > int((s - 1) / 9) + 1: s = s - 1 for i in range(m - 1): if s > 9: op1.append("9") s -= 9 elif 1 <= s <= 9: op1.append(str(s)) s = 0 else: op1.append("0") op1.reverse() newop1 = ["1"] + op1 return int("".join(newop1)) elif s % 9 == 0: return int(10**m - 1) else: return int(10**m - 1 - (9 - s % 9) * 10 ** (m - 1)) if m == 1 and s == 0: print("0 0") else: print("{0} {1}".format(ismin(m, s), ismax(m, s)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_DEF IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN STRING IF VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR RETURN FUNC_CALL VAR FUNC_CALL STRING VAR IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def sum2(n, s): if s == 0 and n == 1: return "0 0" elif s == 0 and n != 1: return "-1 -1" numL = "" if s > 9 * n: return "-1 -1" numL += "9" * (s // 9) if len(numL) < n: numL += str(s - s // 9 * 9) numL += "0" * (n - len(numL)) numS = numL[::-1] zeros = 0 for i in range(len(numS)): if numS[i] != "0": numS = numS[i:] break zeros += 1 if zeros == 0: return str(numS) + " " + str(numL) numS = "1" + "0" * (zeros - 1) + str(int(numS[0]) - 1) + numS[1:] return str(numS) + " " + str(numL) n, s = [int(x) for x in input().split()] print(sum2(n, s))
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER RETURN STRING ASSIGN VAR STRING IF VAR BIN_OP NUMBER VAR RETURN STRING VAR BIN_OP STRING BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
a, b = list(map(int, input().split())) bb = b if a == 1 and b == 0: print("0 0") elif b == 0 or a == 0 or b > a * 9: print("-1 -1") else: ma = "" for i in range(a): if b > 9: ma = ma + str(9) b = b - 9 else: ma = ma + str(b) b = 0 b = bb mi = "" for i in range(a): remaining = a - i - 1 if i == 0: if b <= 9 * remaining: mi = mi + str(1) b = b - 1 else: toAdd = b - 9 * remaining mi = mi + str(toAdd) b = b - toAdd elif b <= 9 * remaining: mi = mi + str(0) else: toAdd = b - 9 * remaining mi = mi + str(toAdd) b = b - toAdd print(int(mi), int(ma))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def min_num(m, s): unit = 1 acum = 0 num = 0 for i in range(m): dig = 9 if i + 1 < m: while dig + acum >= s and dig >= 0: dig -= 1 else: while dig + acum > s and dig >= 0: dig -= 1 acum += dig num += dig * unit unit *= 10 if acum != s or s == 0 and m > 1: return -1 else: return num def max_num(m, s): num = "" for i in range(m): low = min(9, s) num += str(low) s -= low return num def main(): m, s = [int(i) for i in input().split()] min = str(min_num(m, s)) if min == "-1": print("-1 -1") else: print(str(min) + " " + max_num(m, s)) main()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER RETURN VAR FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def get_min(l, s): if s == 0 and l > 1 or s > 9 * l: print("-1 -1", end="") return nb_9 = min_nb_9 = s // 9 rest = min_rest = s % 9 if rest == 0 and nb_9 > 0: min_rest = 9 min_nb_9 -= 1 remaining_digits = l - min_nb_9 if remaining_digits < 0: print("-1 -1", end="") return if remaining_digits == 1: print(min_rest, "9" * min_nb_9, sep="", end=" ") else: print( 1, "0" * (remaining_digits - 2), min_rest - 1, "9" * min_nb_9, sep="", end=" ", ) print("9" * nb_9, rest or "", "0" * (l - nb_9 - (1 if rest else 0)), sep="", end="") def main(): m, s = map(int, input().split()) get_min(m, s) main()
FUNC_DEF IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING STRING RETURN ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP STRING VAR STRING STRING EXPR FUNC_CALL VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP STRING VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER STRING STRING FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if m == 1 and s == 0: print(0, 0) elif s > 9 * m or s == 0: print(-1, -1) else: print( 10 ** (m - 1) + sum(10 ** (i // 9) for i in range(s - 1)), sum(10 ** (m - 1 - i // 9) for i in range(s)), )
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
l, s = map(int, input().split()) x = "" if s == 0: if l == 1: print(0, 0) exit() else: print(-1, -1) exit() while s >= 1: if s <= 9: x = x + str(s) s = 0 else: x = x + "9" s = s - 9 if l < len(x): print("-1 -1") else: a = x[::-1] t = len(a) if l > t: a = "1" + a.replace(a[0], str(int(a[0]) - 1), 1) a = a[:1] + "0" * (l - len(a)) + a[1:] print(a, x + "0" * (l - len(x)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = [int(x) for x in input().split()] a = s b = s if s < 0 or s > 9 * m: li = [str(-1), str(-1)] print(" ".join(li)) elif s == 0 and m > 1: li = [str(-1), str(-1)] print(" ".join(li)) elif m == 1: li = [str(s), str(s)] print(" ".join(li)) else: lstmin = [0] * m lstmax = [0] * m for i in range(m - 1, 0, -1): if a - 1 > 9: lstmin[i] = 9 a -= 9 else: lstmin[i] = a - 1 a = 1 break lstmin[0] = max(1, a) for i in range(len(lstmin)): lstmin[i] = str(lstmin[i]) min = "".join(lstmin) for i in range(m): if b - 9 >= 0: lstmax[i] = 9 b -= 9 else: lstmax[i] = b break for i in range(len(lstmax)): lstmax[i] = str(lstmax[i]) max = "".join(lstmax) li = [min, max] print(" ".join(li))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def valid(l, c): return l * 9 >= c m, s = map(int, input().split()) if not valid(m, s) or s == 0 and m > 1: print(-1, -1) exit() t, min_res = s, "" for i in range(m): for d in range(10): if (i > 0 or d > 0 or m == 1 and d == 0) and valid(m - i - 1, t - d): min_res += chr(ord("0") + d) t -= d break k = s // 9 max_res = k * "9" if k < m: max_res += chr(s % 9 + ord("0")) k += 1 if k < m: max_res += (m - k) * "0" print(min_res, max_res)
FUNC_DEF RETURN BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR STRING VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) def max_(m, s): number_find = "" for j in range(m): i = 9 if s == 0: number_find += str(0) while i > 0: if s // i > 0: number_find += str(i) break i -= 1 s -= i return int(number_find) def min_(m, s): number_find = "" s = s - 1 for j in range(m): if j == m - 1: s = s + 1 i = 9 if s == 0: number_find += str(0) while i > 0: if s // i > 0: number_find += str(i) break i -= 1 s -= i return int(number_find[::-1]) if m == 0 or s > 9 * m or m > 1 and s == 0: print(-1, -1) else: print(min_(m, s), max_(m, s))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def possible(m, sum1): if sum1 >= 0 and sum1 <= 9 * m: return True m, s = [int(k) for k in input().split()] Found = True sum1 = s low = list() for i in range(m): if Found: for d in range(10): if i == 0 and d == 0: d = 1 if m == 1 and sum1 == 0: d = 0 if possible(m - i - 1, sum1 - d): sum1 -= d low.append(d) break if d == 9: Found = False print("-1 -1") break if Found: sum1 = s high = list() for i in range(m): for d in range(9, -1, -1): if possible(m - i - 1, sum1 - d): sum1 -= d high.append(d) break l = "" h = "" for i in range(m): l += str(low[i]) h += str(high[i]) print(l, h)
FUNC_DEF IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) a = 0 ch = s ans1 = 0 ans2 = 0 fl = 0 fl2 = 0 if s == 0 and m != 1 or 9 * m < s: print(-1, -1) elif s == 0 and m == 1: print(0, 0) else: while a < m: if ch >= 9: ch -= 9 ans1 = ans1 * 10 + 9 else: ans1 = ans1 * 10 + ch ch = 0 if ch == 0: fl = 1 a += 1 a = 0 ch = s p = 1 while a < m: if ch > 9: ch -= 9 ans2 = ans2 + 9 * p else: if ch == 0: break if a == m - 1: ans2 = ans2 + ch * p ch = 0 else: ans2 = ans2 + (ch - 1) * p ch = 1 if ch == 0: fl2 = 1 a += 1 p *= 10 if fl and fl2: print(ans2, ans1) else: print(-1, -1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER WHILE VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) max_res = "" min_res = "" if s == 0 and m == 1: print(0, 0) elif s == 0 or 9 * m < s: print(-1, -1) else: max_res = "9" * (s // 9) if s % 9 > 0: max_res += str(s % 9) min_res = max_res[::-1] max_res = max_res.ljust(m, "0") if len(min_res) < m: min_res = str(int(min_res[0]) - 1) + min_res[1:] min_res = min_res.rjust(m - 1, "0") min_res = "1" + min_res print(min_res, max_res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
import sys __author__ = "alexandrun" def process(m, s): if s == 0: if m == 1: return 0, 0 return -1, -1 q = s // 9 r = s % 9 if r == 0: cifMin = q else: cifMin = q + 1 if cifMin > m: return -1, -1 if cifMin == m: if r == 0: return "9" * q, "9" * q min = str(r) + "9" * q max = "9" * q + str(r) return min, max if cifMin < m: min = "1" qmin = (s - 1) // 9 rmin = (s - 1) % 9 if rmin == 0: cifMin2 = qmin else: cifMin2 = qmin + 1 if cifMin2 == m - 1: if rmin > 0: min += str(rmin) + "9" * qmin else: min += "9" * qmin elif cifMin2 < m - 1: if rmin > 0: min += "0" * (-cifMin2 + m - 1) + str(rmin) + "9" * qmin else: min += "0" * (-cifMin2 + m - 1) + "9" * qmin max = "9" * q + str(r) + (m - q - 1) * "0" return min, max words = input().split() m = int(words[0]) s = int(words[1]) res = process(m, s) print(res[0], res[1])
IMPORT ASSIGN VAR STRING FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER NUMBER RETURN NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER NUMBER IF VAR VAR IF VAR NUMBER RETURN BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR RETURN VAR VAR IF VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR VAR BIN_OP STRING VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP STRING VAR VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING RETURN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if 0 < s and s <= m * 9: mins = [0] * m mins[0] = 1 t = s - 1 it = m - 1 while it >= 0 and t > 0: if t > 9: mins[it] = 9 t -= 9 it -= 1 else: mins[it] += t it -= 1 t -= t maxs = [0] * m t = s it = 0 while it < m and t > 0: if t > 9: maxs[it] = 9 t -= 9 it += 1 else: maxs[it] = t t -= t it += 1 for el in mins: print(el, end="") print(end=" ") for el in maxs: print(el, end="") elif m == 1 and 0 <= s <= 9: print(s, s) else: print(-1, -1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) min_num = "" max_num = "" if s == 0 and m > 1: print("-1 -1") elif s == 0 and m == 1: print("0 0") elif s > m * 9: print("-1 -1") else: if s // 9 >= m - 1: max_num = "9" * (s // 9) + str(s % 9) * (m - s // 9) min_num = max_num[::-1] else: min_num = ( "1" + "0" * max(0, m - 2 - (s - 1) // 9) + str((s - 1) % 9) + "9" * ((s - 1) // 9) ) max_num = "9" * (s // 9) + str(s % 9) + "0" * max(0, m - 1 - s // 9) print(min_num + " " + max_num)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) min = [] max = [] d = 1 t = 1 s1 = s s2 = s if m >= 2 and s == 0: print("-1 -1") elif m == 1 and s == 0: print("0 0") elif s > 9 * m: print("-1 -1") else: while d <= m: if s1 - 9 * (m - d) > 0: w = s1 - 9 * (m - d) min.append(str(w)) s1 = s1 - w elif d == 1: min.append("1") s1 = s1 - 1 else: min.append("0") s1 = s1 d += 1 while t <= m: if s2 - 9 < 0: max.append(str(s2)) s2 = 0 else: max.append("9") s2 = s2 - 9 t += 1 print("".join(min), "".join(max))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING WHILE VAR VAR IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
length, sum_nums = list(map(int, input().split())) result = [] res_max = [] sum_nums2 = int(sum_nums) i = -1 Done = False if (length - 1) * 9 + 1 <= sum_nums and length * 9 >= sum_nums: for numeral in range(length - 1): result.append(9) a = list(result) result.append(sum_nums - sum(a)) print("".join(map(str, reversed(result))), "".join(map(str, result))) if sum_nums == 0: if length == 1: print("0 0") else: print("-1 -1") Done = True if length * 9 < sum_nums: Done = True print("-1 -1") if (length - 1) * 9 >= sum_nums and length * 9 >= sum_nums and Done is False: while sum_nums2 >= 9: res_max.append(9) sum_nums2 -= 9 res_max.append(sum_nums2) x = length - len(res_max) for num in range(x): res_max.append(0) for num in range(length): result.append(0) sum_nums -= 1 result.insert(0, 1) while sum_nums >= 9: result.remove(0) result.insert(i, 9) i -= 1 sum_nums -= 9 result.remove(0) result.insert(i, sum_nums) del result[-1] print("".join(map(str, result)), "".join(map(str, res_max)))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
a, b = map(int, input().split()) if a > 1 and not b: print("-1 -1") elif a == 1 and b == 0: print("0 0") else: b -= 1 i = a - 1 j = 0 s1 = list("1" + "0" * (a - 1)) s2 = list("1" + "0" * (a - 1)) while b: if s1[i] == "9": i -= 1 if s2[j] == "9": j += 1 if i < 0 or j >= a: print(-1, -1) exit(0) s1[i] = chr(ord(s1[i]) + 1) s2[j] = chr(ord(s2[j]) + 1) b -= 1 print("".join(s1), "".join(s2))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER WHILE VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def solve(m, s): if m == 1 and s == 0: return 0, 0 if s < 1 or s > 9 * m: return -1, -1 s1, s2 = s, s min_v, max_v = 0, 0 for i in range(1, m): for v in range(0 + (i == 1), 10): if 0 <= s1 - v and s1 - v <= 9 * (m - i): min_v = min_v * 10 + v s1 -= v break else: print("error") for v in range(9, 0 - (i != 1), -1): if 0 <= s2 - v and s2 - v <= 9 * (m - i): max_v = max_v * 10 + v s2 -= v break else: print("error") return min_v * 10 + s1, max_v * 10 + s2 m, s = [int(x) for x in input().split()] print(*solve(m, s))
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER NUMBER IF NUMBER BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR NUMBER NUMBER IF NUMBER BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
a, b = map(int, input().split()) z = [0] * a z1 = [0] * a o = b - 1 if a == 1 and b == 0: print(0, 0) exit() for i in range(a): for j in range(9, -1, -1): if j <= b: z[i] = j break b -= z[i] for i in range(a - 1): for j in range(9, -1, -1): if j <= o: z1[i] = j break o -= z1[i] z1 = z1[::-1] z1[0] = o + 1 print( *(z1 if z1[0] != 0 and o < 9 else [-1]), " ", *(z if not b and z[0] != 0 else [-1]), sep="" )
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR LIST NUMBER STRING VAR VAR NUMBER NUMBER VAR LIST NUMBER STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
l, suma = map(int, input().split()) smallest = [0] * l largest = [0] * l temp = suma if suma > 9 * l: print(-1, -1) elif suma == 0 and l == 1: print(0, 0) elif suma == 0: print(-1, -1) else: smallest[0] = 1 temp -= 1 for i in range(l - 1, -1, -1): if temp > 0 and temp <= 9: smallest[i] += temp break elif temp > 9: smallest[i] = 9 temp -= 9 elif temp == 0: break temp = suma for i in range(0, l): if temp > 0 and temp <= 9: largest[i] = temp break else: largest[i] = 9 temp -= 9 print(*smallest, sep="", end=" ") print(*largest, sep="")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def main(): m, s = map(int, input().split()) if not s: print(("0 0", "-1 -1")[m > 1]) elif s > 9 * m: print("-1 -1") else: l = ["9"] * (s // 9) if s % 9: l.append(str(s % 9)) l += ["0"] * (m - len(l)) ma = "".join(l) l.reverse() if l[0] == "0": for i, c in enumerate(l): if c != "0": l[i] = chr(ord(c) - 1) break l[0] = "1" print("".join(l), ma) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR STRING STRING VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP LIST STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR IF VAR NUMBER STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = list(map(int, input().split())) if s == 0: if m != 1: print(-1, -1) else: print("0" * m, "0" * m) elif s <= 9: if m == 1: print(s, s) else: maxs = [s] + [0] * (m - 1) mins = [1] + [0] * (m - 2) + [s - 1] print("".join(list(map(str, mins))), "".join(list(map(str, maxs)))) elif m == 1: print(-1, -1) else: maxs, minl = [9] * (s // 9) + [s % 9] * (s % 9 > 0), [s % 9] * (s % 9 > 0) + [9] * ( s // 9 ) if len(maxs) > m: print(-1, -1) exit() maxs += [0] * (m - len(maxs)) minl = [0] * (m - len(minl)) + minl p = m - len(minl) for i in range(len(minl)): if minl[i] > 0 and minl[0] == 0: minl[0], minl[i] = 1, minl[i] - 1 break print("".join(list(map(str, minl))), "".join(list(map(str, maxs))))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP STRING VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
inp = input() chars = inp.split() m = int(chars[0]) s = int(chars[1]) if s == 0 and m == 1: print("0 0") exit() if s < 1 or s > 9 * m: print("-1 -1") exit() if s > 9 * (m - 1): x = s - 9 * (m - 1) a = x for i in range(m - 1): a = a * 10 + 9 else: a = 10 ** (m - 1) s1 = s - 1 pow1 = 1 for i in range(m - 1): if s1 >= 9: x = 9 s1 = s1 - x else: x = s1 s1 = 0 a = a + x * pow1 pow1 = pow1 * 10 s1 = s if s1 <= 9: b = s1 * 10 ** (m - 1) else: b = 9 s1 = s1 - 9 for i in range(m - 1): if s1 <= 9: x = s1 s1 = 0 else: x = 9 s1 = s1 - x b = b * 10 + x print(a, b)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
n, sm = map(int, input().split()) if sm == 0 and n == 1: print(0, 0) elif sm == 0 or sm > n * 9: print(-1, -1) else: big = "9" * (sm // 9) if sm % 9 > 0: big += str(sm % 9) zeroes = n - len(big) big += "0" * zeroes if zeroes == 0: small = big[::-1] else: sm -= 1 n -= 1 biggy = "9" * (sm // 9) if sm % 9 > 0: biggy += str(sm % 9) zero = n - len(biggy) biggy += "0" * zero small = "1" + biggy[::-1] print(small, big)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP STRING VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if s > 9 * m or s == 0 and m != 1: print(-1, -1) else: print( int(10 ** (m - 1) + ((s - 1) % 9 + 1) * 10 ** ((s - 1) // 9) - 1), int(10**m - int((10 - s % 9) * 10 ** (m - s // 9 - 1))), )
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) print( [ f"{int(10 ** (m - 1) + ((s - 1) % 9 + 1) * 10 ** ((s - 1) // 9) - 1)} {int(10 ** m - 10 ** (m - (s - 1) // 9 - 1) * (9 - (s - 1) % 9))}", "-1 -1", ][s > 9 * m or s < 1 and m != 1] )
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER STRING FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER STRING VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(lambda i: int(i), input().split()) if m == 1 and s == 0: print("0 0") elif s == 0 or s > 9 * m: print("-1 -1") else: a = [0] * m a[0], remain, idx = 1, s - 1, m - 1 while remain > 0: maxinc = 9 - (idx == 0) a[idx] += min(maxinc, remain) remain = remain - a[idx] + (idx == 0) idx -= 1 b = [0] * m b[0], remain, idx = 1, s - 1, 0 while remain > 0: maxinc = 9 - (idx == 0) b[idx] += min(maxinc, remain) remain = remain - b[idx] + (idx == 0) idx += 1 for i in a: print(i, end="") print(" ", end="") for i in b: print(i, end="")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = [int(i) for i in input().split()] max_num = [0] * m if m == 1 and s == 0: print(0, 0) elif s < 1 or m * 9 < s: print(-1, -1) else: s1 = s for i in range(m): if s - 9 > 0: max_num[i] += 9 s -= 9 else: max_num[i] += s s -= s break min_num = [0] * m for i in range(m - 1, -1, -1): if s1 - 9 > 0: min_num[i] = 9 s1 -= 9 elif s1 > 0: min_num[i] = s1 s1 = 0 else: for j in range(i + 1, m): if min_num[j] > 0: min_num[j] -= 1 min_num[i] += 1 break min_num_value = "" max_num_value = "" for i in max_num: max_num_value += str(i) for i in min_num: if min_num_value or i: min_num_value += str(i) print(min_num_value, max_num_value)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if s < 1: print(-(m > 1), -(m > 1)), exit() if 9 * m < s: print(-1, -1), exit() def g(s): for i in range(m): v = min(9, s) yield str(v) s -= v a = "".join(g(s)) print(a[::-1] if a[-1] > "0" else "1" + "".join(g(s - 1))[-2::-1], a)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING VAR NUMBER BIN_OP STRING FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, const_s = map(int, input().split()) a = [] s = const_s for i in range(m - 1, -1, -1): k = min(s - i * 9, 9) if len(a) > 0: k = max(0, k) else: k = max(1, k) s -= k if s < 0: break a.append(k) if len(a) == m and s == 0: a = "".join([str(i) for i in a]) else: a = -1 b = [] s = const_s for _ in range(m): d = min(s, 9) if len(b) == 0: d = max(1, d) s -= d if s < 0: break b.append(d) if len(b) == m and s == 0: b = "".join([str(i) for i in b]) else: b = -1 if m == 1 and const_s == 0: a = 0 b = 0 print(a, b)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) def f(m, s): if s > m * 9: return "-1 -1" elif s == 0 and m == 1: return "0 0" elif s * m == 0: return "-1 -1" else: high = [] while s > 0: r = min(s, 9) high.append(r) s -= r high += [(0) for i in range(m - len(high))] low = high[::-1] if low[0] == 0: j = 1 while low[j] == 0: j += 1 low[j] -= 1 low[0] += 1 low = "".join(map(str, low + [" "] + high)) return low print(f(m, s))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER RETURN STRING IF BIN_OP VAR VAR NUMBER RETURN STRING ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR BIN_OP BIN_OP VAR LIST STRING VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
l = list(map(int, input().split(" "))) m = l[0] s = l[1] a = list() b = list() S = 0 n = 0 while n < m: if 9 + S <= s: a.append(9) S = S + 9 n = n + 1 elif 8 + S <= s: a.append(8) S = S + 8 n = n + 1 elif 7 + S <= s: a.append(7) S = S + 7 n = n + 1 elif 6 + S <= s: a.append(6) n = n + 1 S = S + 6 elif 5 + S <= s: a.append(5) n = n + 1 S = S + 5 elif 4 + S <= s: a.append(4) n = n + 1 S = S + 4 elif 3 + S <= s: a.append(3) S = S + 3 n = n + 1 elif 2 + S <= s: a.append(2) n = n + 1 S = S + 2 elif 1 + S <= s: a.append(1) n = n + 1 S = S + 1 elif 0 + S <= s: a.append(0) n = n + 1 S = S + 0 n = 0 S = 0 k = 0 while n < m and m > 1: if 0 + S <= s and n >= 1 and S + 0 + (m - (n + 1)) * 9 >= s: b.append(0) S = S + 0 n = n + 1 elif 1 + S <= s and S + 1 + (m - (n + 1)) * 9 >= s: b.append(1) S = S + 1 n = n + 1 elif 2 + S <= s and S + 2 + (m - (n + 1)) * 9 >= s: b.append(2) S = S + 2 n = n + 1 elif 3 + S <= s and S + 3 + (m - (n + 1)) * 9 >= s: b.append(3) n = n + 1 S = S + 3 elif 4 + S <= s and S + 4 + (m - (n + 1)) * 9 >= s: b.append(4) n = n + 1 S = S + 4 elif 5 + S <= s and S + 5 + (m - (n + 1)) * 9 >= s: b.append(5) n = n + 1 S = S + 5 elif 6 + S <= s and S + 6 + (m - (n + 1)) * 9 >= s: b.append(6) n = n + 1 S = S + 6 elif 7 + S <= s and S + 7 + (m - (n + 1)) * 9 >= s: b.append(7) n = n + 1 S = S + 7 elif 8 + S <= s and S + 8 + (m - (n + 1)) * 9 >= s: b.append(8) n = n + 1 S = S + 8 elif 9 + S <= s and S + 9 + (m - (n + 1)) * 9 >= s: b.append(9) n = n + 1 S = S + 9 k = k + 1 if k == m: break if m == 1 and s < 10: b.append(s) if m > 1 and s == 0: print("-1 -1") elif sum(a) == s and sum(b) == s: a = map(str, a) b = map(str, b) print("".join(b), "".join(a)) else: print("-1 -1")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF BIN_OP NUMBER VAR VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().rstrip().split(" ")) if m == 1 and s == 0: print("0 0") elif s == 0 or s / m > 9: print("-1 -1") else: sum1 = s - 1 minimum = "" maximum = "" for i in range(m): x = min(9, s) s -= x maximum += str(x) for i in range(m - 1): x = min(9, sum1) sum1 -= x minimum = str(x) + minimum minimum = str(sum1 + 1) + minimum print(minimum, maximum)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
length, sum_digits = [int(a) for a in input().strip().split()] l_num = 1 * 10 ** (length - 1) lnum_list = [int(a) for a in str(l_num)] if sum_digits > length * 9 or sum_digits == 0: if sum_digits == 0 and length == 1: print("0 0") else: print("-1 -1") elif sum_digits == 1: num = 1 * 10 ** (length - 1) print(f"{num} {num}") else: for i in range(len(lnum_list)): while lnum_list[i] < 9: if sum(lnum_list) == sum_digits: break lnum_list[i] += 1 else: continue snum_list = lnum_list[::-1] if snum_list[0] != 0: print("".join([str(d) for d in snum_list]), end="") print(" ", end="") else: snum_list[0] += 1 for i in range(1, len(snum_list)): if snum_list[i] != 0: snum_list[i] -= 1 break print("".join([str(d) for d in snum_list])) print("".join([str(d) for d in lnum_list]))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) ar = [0] * m ar[0] = 1 sum1 = 1 if m == 1: if s > 9: print("-1 -1") else: print(s, s) else: dd = 0 for i in range(m - 1, 0, -1): if sum1 <= s: ar[i] += 9 sum1 += 9 if sum1 > s: ar[i] -= sum1 - s sum1 -= sum1 - s if sum1 < s: ar[0] += s - sum1 if ar[0] > 9: dd = 1 min1 = ar[:] sum1 = 0 ar = [0] * m ar[0] = 0 for i in range(m): if sum1 <= s: sum1 += 9 ar[i] += 9 if sum1 > s: ar[i] -= sum1 - s sum1 -= sum1 - s if sum1 < s or dd == 1 or ar[0] == 0 or min(min1) < 0: print("-1 -1") else: print("".join(map(str, min1)), "".join(map(str, ar)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER BIN_OP VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if s < 1 < m or s > 9 * m: print("-1 -1") elif m == 1 and s == 0: print("0 0") else: q, r = divmod(s, 9) p = "9" * q + (str(r) if r != 0 else "") p += "0" * (m - len(p)) q = p[::-1] i = q.rindex("0") if "0" in q else -1 q = list(map(int, q)) q[i + 1] -= 1 q[0] += 1 print("".join(map(str, q)), p)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR VAR NUMBER FUNC_CALL VAR VAR STRING VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if s == 0 and m == 1: print(0, 0) elif s < 1 or 9 * m < s: print(-1, -1) else: tot = s mini = "" maxi = "" add = 0 for i in range(m): if s > 9: mini += "9" s -= 9 else: mini += str(s - 1) s = 1 add = 1 mini = mini[::-1] mini = str(int(mini[0]) + add) + mini[1:] s = tot for i in range(m - 1, -1, -1): x = min(9, s) maxi += str(x) s -= x print(mini, maxi)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) a = s if s == 0 and m != 1 or s / m > 9: print(-1, -1) elif m == 1: if s > 9: print(-1, -1) else: x, y = s, s print(x, y) else: mx = [] for i in range(m): if s > 9: mx.append(9) s = s - 9 elif s >= 1: mx.append(s) s = 0 else: mx.append(0) if a == 1 and m == 2: mn = mx else: temp = mx[::-1] if temp == mx: mn = mx elif m == 2 and s > 9: mn = mx[::-1] else: mn = [] for j in range(m): if a > 9: mn.append(9) a -= 9 elif a > 0: mn.append(a) a = 0 else: mn.append(0) if mn[j] == 0: ind = mn.index(0) mn[ind - 1] = mn[ind - 1] - 1 mn[j] = 1 mn = mn[::-1] x, y = "", "" for l in mn: x = x + str(l) for m in mx: y = y + str(m) print(x, y)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR STRING STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if m == 1 and s == 0: print(0, 0) elif s == 0 or s > 9 * m: print(-1, -1) else: e = s // m amax = [] for i in range(m): amax.append(e) l = s % m for i in range(m): if l > 0: amax[i] += 1 l -= 1 else: break for i in range(m): j = i + 1 while amax[i] < 9: if j >= m: break else: temp = amax[i] amax[i] += min(9 - amax[i], amax[j]) amax[j] -= min(9 - temp, amax[j]) j += 1 amin = amax[::-1] if amin[0] == 0: for i in range(m): if amin[i] > 0: amin[i] -= 1 amin[0] = 1 break for i in amin: print(i, end="") print(end=" ") for i in amax: print(i, end="") print()
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
import sys m, s = list(map(int, input().split())) if m is 1 and s is 0: print("0 0") sys.exit() if m * 9 < s or s is 0: print("-1 -1") sys.exit() max_val = [] max_n = 9 temp_s = s temp_m = m sum_ = 0 while temp_m is not 0: if temp_s >= max_n: temp_s = temp_s - max_n max_val.append(str(max_n)) temp_m = temp_m - 1 sum_ = sum_ + max_n elif temp_s is 0: max_val.append(str(0)) temp_m = temp_m - 1 else: max_n = max_n - 1 min_val = [(0) for i in range(0, m)] last = m - 1 for i in range(0, s): if i is 0: min_val[i] = 1 elif min_val[last] < 9: min_val[last] = min_val[last] + 1 else: last = last - 1 if last < 0: print("-1 -1") sys.exit() min_val[last] = min_val[last] + 1 min_val.sort() if min_val[0] is 0: for i in range(1, len(min_val)): if min_val[i] is not 0: tmp = min_val[i] min_val[i] = 0 min_val[0] = tmp break print("%s %s" % ("".join(str(x) for x in min_val), "".join(max_val)))
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) total = s k = m - 1 w = [] for i in range(m): if total >= 9: total -= 9 w.append(9) elif total <= 0: w.append(0) else: w.append(total) total -= total hh = w W = hh[::-1] if m == 1 and s == 0: print("0 0") elif s != sum(w) or s == 0 or len(str(s)) > m or s > m * 9: print("-1 -1") elif W[0] == 0: dd = min(i for i in W if i > 0) W[W.index(dd)] = dd - 1 W[0] = 1 print("".join([str(i) for i in W])) print("".join([str(mm) for mm in hh])) else: print("".join([str(i) for i in W])) print("".join([str(mm) for mm in hh]))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def recur(m1, s1): global ans if m1 == 1: ans.insert(0, s1) return elif s1 > 9: ans.insert(0, 9) recur(m1 - 1, s1 - 9) else: ans.insert(0, s1 - 1) recur(m1 - 1, 1) def grecur(m1, s1): global gans if m1 == 1: gans.append(s1) return elif s1 > 9: gans.append(9) grecur(m1 - 1, s1 - 9) else: gans.append(s1) grecur(m1 - 1, 0) m, s = map(int, input().split()) if s == 0 and m > 1 or s > m * 9: print("-1 -1") else: ans, gans = list(), list() recur(m, s) grecur(m, s) print(*ans, " ", *gans, sep="")
FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
x, y = [int(i) for i in input().split()] if x > 1 and y < 1 or x * 9 < y: print("-1 -1") else: k = y for i in range(x): s = max(0, k - (x - i - 1) * 9) if s == 0 and i == 0 and k != 0: s = 1 k = k - s print(s, end="") print(" ", end="") k = y for i in range(x): s = min(9, k) k = k - s print(s, end="")
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
A = input().split() m = int(A[0]) s = int(A[1]) if s == 0 and m == 1: print(0, 0) elif s < 1 or s > 9 * m: print(-1, -1) else: current = s big = [0] * m for i in range(0, m): if current <= 9: big[i] = current break else: big[i] = 9 current = current - 9 second = 0 for i in range(0, m): second = 10 * second + big[i] current = s if s > 9 * (m - 1): small = [9] * m small[0] = s - 9 * (m - 1) else: small = [0] * m small[0] = 1 current = current - 1 for i in range(m - 1, 0, -1): if current <= 9: small[i] = current break else: small[i] = 9 current = current - 9 first = 0 for i in range(0, m): first = 10 * first + small[i] print(first, second)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) def solve(m, s): if m > 1 and s == 0: return -1, -1 if m == 1 and s == 0: return 0, 0 if m == 0 and s == 0: return -1, -1 if s > m * 9: return -1, -1 sorted_nums = [9] * (s // 9) if s % 9: sorted_nums.append(s % 9) max_val = sorted_nums + [0] * (m - len(sorted_nums)) if len(sorted_nums) == m: min_val = sorted_nums[::-1] else: sorted_nums[-1] = sorted_nums[-1] - 1 min_val = [1] + [0] * (m - len(sorted_nums) - 1) + sorted_nums[::-1] max_val = int("".join(map(str, max_val))) min_val = int("".join(map(str, min_val))) return min_val, max_val print(*solve(m, s))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR RETURN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def main(): line = input().split() m = int(line[0]) s = int(line[1]) digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] mini = [0] * m out1 = "" maxi = [0] * m out2 = "" if s == 0 and m > 1: print("-1 -1") elif s == 0 and m == 1: print("0 0") elif s > 9 * m: print("-1 -1") else: for j in range(m): if j == 0: i = 1 else: i = 0 while s - digits[i] > 9 * (m - j - 1): i += 1 mini[j] = digits[i] out1 += str(digits[i]) s -= digits[i] s = int(line[1]) for k in range(m): t = len(digits) - 1 while s < digits[t]: t -= 1 maxi[k] = digits[t] s -= digits[t] out2 += str(digits[t]) print(out1) print(out2) main()
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = input().split() m, s = int(m), int(s) largest = "" smallest = "" p = m q = s if s == 0 and m == 1: print("0 0") elif s == 0 or 9 * m < s: print("-1 -1") else: while m > 0: if s >= 9: largest = "9" + largest s = s - 9 elif s > 0 and s < 9: largest = largest + str(s) s = 0 elif s == 0: largest = largest + "0" m = m - 1 while p > 0: if q > 9: smallest = smallest + "9" q = q - 9 elif q > 1 and q <= 9 and p != 1: smallest = str(q - 1) + smallest q = 1 elif q > 1 and q <= 9 and p == 1: smallest = str(q) + smallest elif q == 1 and p > 1: smallest = "0" + smallest elif q == 1 and p == 1: smallest = "1" + smallest p = p - 1 print(smallest + " " + largest)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP STRING VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) n = s // 9 mod = s % 9 if mod == 0: digits = n else: digits = n + 1 if s == 0 and m == 1: print(0, 0) elif digits > m or s == 0: print(-1, -1) elif mod == 0: temp = 0 ma = "" ma += "9" * digits temp += digits ma += "0" * (m - digits) mi = "" if digits == m: mi = ma else: mi += "9" * (digits - 1) mi = "8" + mi mi = "1" + "0" * (m - digits - 1) + mi print(mi, ma) else: temp = 0 ma = "9" * n ma += str(mod) temp += digits ma += "0" * (m - digits) mi = "9" * n if digits == m: mi = str(mod) + mi else: mi = str(mod - 1) + mi mi = "1" + "0" * (m - digits - 1) + mi print(mi, ma)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING VAR BIN_OP STRING VAR VAR VAR VAR BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR STRING IF VAR VAR ASSIGN VAR VAR VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR BIN_OP STRING VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) mi = -1 ma = -1 a = s // 9 b = s % 9 if m == 1 and s == 0: mi = ma = 0 elif 1 <= s <= 9 * m: if a == m and b == 0: ma = 10**m - 1 else: ma = 10**m - 10 ** (m - a) + s % 9 * 10 ** (m - a - 1) if b == 0: if a == m: mi = 10**m - 1 else: mi = 10 ** (m - 1) + 9 * 10 ** (a - 1) - 1 elif b == 1: mi = 10 ** (m - 1) + 10**a - 1 elif m - a == 1: mi = (b + 1) * 10 ** (m - 1) - 1 else: mi = 10 ** (m - 1) + b * 10**a - 1 print(int(mi), int(ma))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = [int(i) for i in input().split()] k = ["1"] + ["0"] * (m - 1) k1 = ["0"] * m s1 = s flag = 0 if m == 1 and s == 0: flag = 1 print("0 0") if (m * 9 < s or s == 0) and flag == 0: flag = 1 print("-1 -1") else: for i in range(m - 1): ind = m - 1 - i j = 9 while s1 > 1: if s1 - j >= 1: s1 = s1 - j k[ind] = str(j) break j = j - 1 if s1 > 1: k[0] = str(s1) for i in range(m): j = 9 while s > 0: if s - j >= 0: s = s - j k1[i] = str(j) break j = j - 1 if flag == 0: print("".join(k), "".join(k1))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP LIST STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) minimum = m * [0] maximum = m * [0] minimum[0] = 1 for num in range(1, s): for value in range(1, m + 1): if minimum[-value] != 9: minimum[-value] += 1 break for num in range(s): for value in range(0, m): if maximum[value] != 9: maximum[value] += 1 break if (m, s) == (1, 0): print(0, 0) exit(0) if sum(minimum) == s and sum(maximum) == s: for num in minimum: print(num, end="") print(" ", end="") for num in maximum: print(num, end="") else: print("-1 -1")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if s == 0: if m != 1: print(-1, -1) else: print(0, 0) else: min = [] max = 0 r = s c = 0 f = m - 1 if m * 9 < s: print(-1, -1) else: while r > 0: c += 1 if r >= 9: min.append(9) max += 9 * 10**f r -= 9 else: min.append(r) max += r * 10**f break f -= 1 for i in range(c, m): min[-1] -= 1 min.append(1) min1 = 0 for i in range(m): min1 += min[i] * 10**i print(int(min1), int(max))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = [int(i) for i in input().split()] s_1, m_1 = s, m min_list = [] max_list = [] min_str = "" max_str = "" if m == 1 and s == 0: print(0, 0) elif s == 0 or s > m * 9: print(-1, -1) else: while s > 9: max_list.append(9) s -= 9 m -= 1 if s > 0: max_list.append(s) m -= 1 for i in range(m): max_list.append(0) else: for i in range(m): max_list.append(0) if s_1 < (m_1 - 1) * 9 + 2: min_list.append(1) m_1 -= 1 s_1 -= 1 while True: if m_1 * 9 == s_1: while s_1 > 0: min_list.append(9) m_1 -= 1 s_1 -= 9 break elif m_1 * 9 < s_1 + 9: min_list.append(s_1 - (m_1 - 1) * 9) m_1 -= 1 s_1 -= s_1 - m_1 * 9 while s_1 > 0: min_list.append(9) m_1 -= 1 s_1 -= 9 break else: min_list.append(0) m_1 -= 1 min_str = int("".join(str(i) for i in min_list)) print(min_str) max_str = int("".join(str(i) for i in max_list)) print(max_str)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER WHILE NUMBER IF BIN_OP VAR NUMBER VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
import sys m, s = map(int, sys.stdin.readline().split()) def get_max(m, s, digits=range(9, -1, -1)): if not 0 <= s <= 9 * m: return None if m == 1: return s for digit in digits: candidate = get_max(m - 1, s - digit) if candidate is not None: return f"{digit}{candidate}" return None def get_min(m, s, digits=range(10)): if not 0 <= s <= 9 * m: return None if m == 1: return s for digit in digits: candidate = get_min(m - 1, s - digit) if candidate is not None: return f"{digit}{candidate}" return None max_candidate, min_candidate = get_max(m, s, digits=range(9, 0, -1)), get_min( m, s, digits=range(1, 10) ) if max_candidate is not None and min_candidate is not None: sys.stdout.write(f"{min_candidate} {max_candidate}") else: sys.stdout.write("-1 -1")
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FUNC_CALL VAR NUMBER NUMBER NUMBER IF NUMBER VAR BIN_OP NUMBER VAR RETURN NONE IF VAR NUMBER RETURN VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR NONE RETURN VAR VAR RETURN NONE FUNC_DEF FUNC_CALL VAR NUMBER IF NUMBER VAR BIN_OP NUMBER VAR RETURN NONE IF VAR NUMBER RETURN VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR NONE RETURN VAR VAR RETURN NONE ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NONE VAR NONE EXPR FUNC_CALL VAR VAR STRING VAR EXPR FUNC_CALL VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, og_s = list(map(int, input().split())) maxn = "" if m == 1 and og_s == 0: print(0, 0) exit() s = og_s while s > 0: for i in range(9, 0, -1): if s - i >= 0: s -= i maxn += str(i) break if maxn == "" or len(maxn) > m: print(-1, -1) exit() num_zeroes = m - len(maxn) minn = "1" if num_zeroes >= 1 else "" addon = str(int(maxn) - 1)[::-1] if minn == "1" else maxn[::-1] minn += "0" * (num_zeroes - 1) + addon maxn += "0" * num_zeroes print(minn, maxn)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR WHILE VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR IF VAR STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER STRING STRING ASSIGN VAR VAR STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER VAR VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
import sys ms = input() m, s = map(int, ms.split()) if s == 0 and m != 1 or s > m * 9: print("-1 -1") sys.exit(0) sum = s for i in range(m): x = max(sum - (m - 1 - i) * 9, 0) if x == 0 and i == 0 and m != 1: x = 1 print(x, end="") sum -= x print(" ", end="") sum = s for i in range(m): x = min(sum, 9) print(x, end="") sum -= x
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
ls = input().split(" ") l = int(ls[0]) n = int(ls[1]) if n < 0 or n > l * 9: print("-1 -1") elif n == 0: if l == 1: print("0 0") else: print("-1 -1") else: m = "" n1 = n while n >= 9: m += "9" n -= 9 if len(m) != l: m += "%d" % n while len(m) != l: m += "0" m1 = "" if n1 <= 9 * (l - 1) + 1: m1 += "1" n1 -= 1 while n1 <= 9 * (l - len(m1) - 1) and len(m1) != l: m1 += "0" if len(m1) != l: if n1 % 9: m1 += "%d" % (n1 % 9) n1 -= n1 % 9 else: m1 += "9" while len(m1) != l: m1 += "9" print(m1, m)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR WHILE VAR NUMBER VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP STRING VAR WHILE FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR STRING IF VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR STRING VAR NUMBER WHILE VAR BIN_OP NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR STRING IF FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING WHILE FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if s == 1: print("1" + "0" * (m - 1), "1" + "0" * (m - 1)) exit() if s == 0 and m == 1: print("0 0") exit() if s == 0 or s > 9 * m: print("-1 -1") exit() dev = s // 9 s -= dev * 9 if dev == m: print("9" * dev, "9" * dev) exit() if dev + 1 == m: if s == 0: dev -= 1 print("18" + "9" * dev, "9" * dev + "81") else: print(str(s) + "9" * dev, "9" * dev + str(s)) exit() countn = m - dev - 2 if s != 0: vtr = s - 1 s = 1 else: dev -= 1 vtr = 8 s = 1 s, vtr = min(s, vtr), max(s, vtr) x = s + vtr if x >= 10: x = "9" + str(x - 9) x = str(x) if s == 0 and vtr == 1: print( str(vtr) + "0" * countn + str(s) + "9" * dev, "9" * dev + str(vtr) + str(s) + "0" * countn, ) else: x = s + vtr count = 1 if x >= 10: x = "9" + str(x - 9) count = 2 x = str(x) print( str(s) + "0" * (m - 2 - dev) + str(vtr) + "9" * dev, "9" * dev + str(x) + "0" * (m - count - dev), )
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR BIN_OP BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP STRING VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR VAR