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
m, s = [int(i) for i in input().split()] num = [(9) for i in range(m)] def max_number(num, s): total_sum = sum(num) i = 1 while total_sum > s: num[-i] -= 1 total_sum -= 1 if num[-i] == 0: i += 1 return num def min_number(num, s): aux_num = num[::-1] if aux_num[0] == 0: for i in range(len(num)): if aux_num[i] != 0: aux_num[i] -= 1 aux_num[0] += 1 break return aux_num if s == 0 and m > 1 or 9 * m < s: print("-1 -1") else: max_num = max_number(num, s) min_num = min_number(num, s) for i in min_num: print(i, end="") print(" ", end="") for k in max_num: print(k, end="")
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER RETURN VAR IF VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN 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
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(0, 0) else: print(-1, -1) else: txt = "" mm = m while m > 0: m -= 1 if s >= 9: s -= 9 txt += "9" else: txt += str(s) s -= s mintxt = txt[-1::-1] if mintxt[0] == "0": for i in range(mm): if mintxt[i] != "0": index = i break mintxt = ( "1" + mintxt[1:index] + str(int(mintxt[index]) - 1) + mintxt[index + 1 :] ) if s == 0: print(mintxt, txt) else: print(-1, -1)
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 STRING ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR STRING VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF 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
mp = map(int, input().split(" ")) s, m = list(mp) ans = [(0) for i in range(s)] if s * 9 < m or m < 1 and s > 1: print("-1 -1") else: big = 0 n = m for i in range(s - 1, -1, -1): if m > 9: ans[i] = 9 else: ans[i] = m m -= ans[i] big = "".join(map(str, ans[::-1])) ans = [(0) for i in range(s)] ans[0] = 1 n -= 1 for i in range(s - 1, -1, -1): if n > 9: ans[i] = 9 else: ans[i] += n n -= ans[i] sml = "".join(map(str, ans)) print(sml, big)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING 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()) min = [(0) for x in range(101)] max = [(0) for x in range(101)] if s == 0 and m != 1: print("-1 -1") elif 9 * m < s: print("-1 -1") else: temp = s pos = m while s > 0: if s > 9: min[pos] = 9 s -= 9 else: min[pos] = s - 1 min[1] += 1 s = 0 pos -= 1 s = temp pos = 1 while s > 0: if s > 9: max[pos] = 9 s -= 9 pos += 1 else: max[pos] = s s = 0 for i in range(1, m + 1): print(min[i], end="") print(" ", end="") for i in range(1, m + 1): print(max[i], end="")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER 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
def get_max_number(m, s): max_number = 0 for i in range(m): new_digit = min(9, s) max_number = 10 * max_number + new_digit s -= new_digit if s or len(str(max_number)) != m: max_number = -1 return max_number def get_min_number(m, s): if s == 0: return 0 if m == 1 else -1 min_number = 0 multiplier = 1 for i in range(m - 1): new_digit = min(9, s - 1) min_number += multiplier * new_digit multiplier *= 10 s -= new_digit if 1 <= s <= 9: min_number += multiplier * s else: min_number = -1 return min_number m, s = map(int, input().split()) print(" ".join(map(str, [get_min_number(m, s), get_max_number(m, s)])))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR VAR IF NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR LIST 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 least(n, m, s): if m == 0 and s == 0: return n if n == "": beg = 1 else: beg = 0 if m * 9 < s: return "" for i in range(beg, 10): ans = least(n + str(i), m - 1, s - i) if ans != "": return ans def most(n, m, s): if m == 0 and s == 0: return n if s < 0: return "" for i in range(9, -1, -1): ans = most(n + str(i), m - 1, s - i) if ans != "": return ans m, s = map(int, input().split()) if m * 9 < s: print("-1 -1") elif s == 0: if m == 1: print("0 0") else: print("-1 -1") else: print(least("", m, s), most("", m, s))
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR RETURN STRING FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR STRING RETURN VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR STRING RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING VAR VAR FUNC_CALL 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
m, S = map(int, input().split()) s = S if m == 1 and 0 <= S <= 9: print(S, S) elif s == 0 or s > 9 * m: print(-1, -1) else: mn = [0] * m mn[0] = 1 s -= 1 for i in range(m - 1, -1, -1): if s > 0: if mn[i] + s > 9: mn[i] = 9 s -= 9 else: mn[i] = mn[i] + s s = 0 break mx = [0] * m mx[0] = 1 s = S - 1 for i in range(m): if mx[i] + s > 9: s -= 9 - mx[i] mx[i] = 9 else: mx[i] += s s = 0 break for i in mn: print(i, end="") print(" ", end="") for i in mx: print(i, end="")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR ASSIGN 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
ms = input().split(" ") m = int(ms[0]) s = int(ms[1]) if s == 0 and m > 1 or m == 0 or s > 9 * m: print("-1 -1") elif s == 0 and m == 1: print("0 0") else: nums1, nums2 = [], [] min_s, max_s = s, s for i in range(m, 0, -1): k = 1 if i != m: k = 0 if min_s > k + 9 * (i - 1): k = min_s - 9 * (i - 1) nums1.append(str(k)) min_s -= k k = 9 if k > max_s: k = max_s nums2.append(str(k)) max_s -= k print("".join(nums1), "".join(nums2))
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 NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL 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
m, s = list(map(int, input().split())) if m == 1 and s == 0: print(0, 0) elif m == 1 and s == 1: print(1, 1) elif m * 9 < s: print(-1, -1) elif s == 0: print(-1, -1) else: arr = [1] + [0] * (m - 1) arr2 = [0] * m k = arr[::-1] n = -1 while sum(k) < s: n += 1 k[n] = 9 while sum(k) != s: if k[n] > 0: k[n] -= 1 else: n -= 1 min_numb = k[::-1] min_numb = "".join(map(str, min_numb)) arr2 = [0] * m z = -1 while sum(arr2) < s: z += 1 arr2[z] = 9 if sum(arr2) > s: while sum(arr2) != s: arr2[z] -= 1 max_numb = "".join(map(str, arr2)) print(min_numb, max_numb)
ASSIGN VAR VAR FUNC_CALL 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 IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING 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()) if 9 * m < s: print(*[-1, -1]) elif s == 0 and m > 1: print(*[-1, -1]) elif s == 0: print(0, 0) else: a, b = [0] * m, [0] * m a[0] = 1 r = s s -= 1 for i in range(0, m): for j in range(1, 10): if r != 0: b[i] += 1 r -= 1 if s != 0: a[m - 1 - i] += 1 s -= 1 if r == 0: break b = int("".join(map(str, b))) a = int("".join(map(str, a))) print(a, b)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF 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 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
qhy = input() a, b = [int(i) for i in qhy.split()] maxn = [] minn = [] if b == 0 and a != 1: print("-1 -1") elif 9 * a < b: print("-1 -1") else: t = 0 m = b for i in range(a): if m > 9: t = 9 m = m - t maxn.append(t) else: t = m m = 0 maxn.append(t) t = 0 m = b if m == 0: minn.append(0) elif m <= (a - 1) * 9: minn.append(1) m -= 1 else: t = m - (a - 1) * 9 minn.append(t) m = m - t for i in range(1, a): if m < 9 * (a - i - 1): t = 0 minn.append(0) else: t = m - 9 * (a - i - 1) m -= t minn.append(t) minn.append(" ") for i in range(a + 1): print(minn[i], end="") for i in range(a): print(maxn[i], end="")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING 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
n, s = [int(i) for i in input().split()] def pos(n, s): if s >= 0 and s <= 9 * n: return True return False if n == 1: if s > 9: print(-1, -1) else: print(s, s) elif s == 0: if n == 1: print(0, 0) else: print(-1, -1) else: temp = s minn = "" for i in range(n): for j in range(10): if (i > 0 or j > 0 or n == 1 and j == 0) and pos(n - i - 1, s - j): minn += str(j) s -= j break maxx = "" for i in range(n): for j in range(9, -1, -1): if (i > 0 or j > 0 or n == 1 and j == 0) and pos(n - i - 1, temp - j): maxx += str(j) temp -= j break if minn and maxx: print(minn, maxx) else: print(-1, -1)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN 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 VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER 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 VAR VAR VAR 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()) if s == 0 and m != 1: print("-1", "-1") elif s > 9 * m: print("-1", "-1") else: a = s // 9 b = s % 9 if a == 0: if m == 1: print(b, end=" ") print(b) else: print("1", end="") for i in range(m - 2): print("0", end="") print(b - 1, end="") print("", end=" ") print(b, end="") for i in range(m - 1): print("0", end="") elif b != 0 and m != a + 1: print(1, end="") for i in range(m - a - 2): print("0", end="") print(b - 1, end="") for i in range(a): print("9", end="") print("", end=" ") for i in range(a): print("9", end="") print(b, end="") for i in range(m - a - 1): print("0", end="") elif b != 0 and m == a + 1: print(b, end="") for i in range(a): print("9", end="") print("", end=" ") for i in range(a): print("9", end="") print(b, end="") for i in range(m - a - 1): print("0", end="") elif a != m: print("1", end="") for i in range(m - a - 1): print("0", end="") print("8", end="") for i in range(a - 1): print("9", end="") print("", end=" ") for i in range(a): print("9", end="") for i in range(m - a - 1): print("0", end="") print(b, end="") else: for i in range(m): print("9", end="") print("", end=" ") for i in range(m): print("9", end="")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING 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(x) for x in input().split()] if s == 0 and m != 1 or s > 9 * m: print(-1, -1) else: big = "" bs = s small = "" ss = s for i in range(m): if bs >= 9: big += "9" bs -= 9 else: big += str(bs) bs = 0 if i <= m - 2: if ss > 9: small = "9" + small ss -= 9 elif ss > 1: small = str(ss - 1) + small ss = 1 else: small = "0" + small else: small = str(ss) + small print(int(small), int(big))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR 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
m, s = map(int, input().split(" ")) s0 = s list1 = [] list2 = [] if s == 0: if m == 1: print("0 0") else: print("-1 -1") elif s > 9 * m: print("-1 -1") elif m == 1: print(s, s, sep=" ") else: for i in range(m): if s >= 9: list1.append("9") s -= 9 else: list1.append(str(s)) s = 0 for i in range(m): if i != m - 1: if s0 >= 10: list2.append("9") s0 -= 9 else: list2.append(str(s0 - 1)) s0 = 1 else: list2.append(str(s0)) list2.reverse() print("".join(list2), "".join(list1), sep=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST 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 VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL 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
a = input().split() m = int(a[0]) s = int(a[1]) nein = s // 9 r = s % 9 if s == 0 and m == 1: print(0, 0) elif s == 0 and m > 1: print(-1, -1) elif nein > m: print(-1, -1) elif nein == m and r > 0: print(-1, -1) elif nein == m and r == 0: b = 0 for i in range(m): b += 9 * 10**i print(b, b) else: bmin = 0 bmax = 0 if r > 0 and nein == m - 1: for i in range(nein): bmax += 9 * 10 ** (m - i - 1) bmin += 9 * 10**i print(bmin + r * 10**nein, bmax + r * 10 ** (m - nein - 1)) elif r > 0 and nein < m - 1: for i in range(nein): bmax += 9 * 10 ** (m - i - 1) bmin += 9 * 10**i print( bmin + (r - 1) * 10**nein + 10 ** (m - 1), bmax + r * 10 ** (m - nein - 1) ) else: for i in range(nein): bmax += 9 * 10 ** (m - i - 1) for i in range(nein - 1): bmin += 9 * 10**i bmin += 8 * 10 ** (nein - 1) bmin += 10 ** (m - 1) print(bmin, bmax)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP 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 VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP 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] = list(map(int, input().split())) mlist = [0] * m mlist[0] = s if s == 0 and m > 1 or s > m * 9: smallest = str(-1) biggest = str(-1) else: first0 = m for i in range(1, m): if mlist[i - 1] > 9: mlist[i - 1], mlist[i] = 9, mlist[i - 1] - 9 if mlist[i] == 0: first0 = i break firstn = m - first0 biggest = "".join([str(c) for c in mlist]) mlist.reverse() if mlist[0] == 0: mlist[0] = 1 mlist[firstn] -= 1 smallest = "".join([str(c) for c in mlist]) print(smallest + " " + biggest)
ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING 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
def f0(m, s): n = [(0) for x in range(m)] n[0] = 1 s -= 1 for i in range(m - 1, -1, -1): if s == 0: break if s < 10: n[i] += s break else: n[i] = 9 s -= 9 n = [str(x) for x in n] return "".join(n) def f1(m, s): n = [(0) for x in range(m)] for i in range(m): if s == 0: break if s < 10: n[i] = s break else: n[i] = 9 s -= 9 n = [str(x) for x in n] return "".join(n) m, s = (int(x) for x in input().split()) if m == 1 and s == 0: print("0 0") elif s < 1 or s > m * 9: print("-1 -1") else: print(f0(m, s), f1(m, s))
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL STRING VAR 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 VAR NUMBER EXPR FUNC_CALL VAR STRING 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
m, s = map(int, input().split()) zuida = 0 zuixiao = 0 weishu = m qiuhe = s if s == 0 and m > 1: print("-1 -1") elif m == 1 and s == 0: print("0 0") elif s > 9 * m: print("-1 -1") else: while s > 9: zuida = zuida + 9 * 10 ** (m - 1) s = s - 9 m = m - 1 zuida = zuida + s * 10 ** (m - 1) m = weishu s = qiuhe s = s - 1 b = 0 while s >= 9: zuixiao = zuixiao + 9 * 10**b s = s - 9 b = b + 1 zuixiao = zuixiao + s * 10**b + 10 ** (m - 1) print(str(int(zuixiao)), str(int(zuida)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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()) mx, mn = "", "" if m == 1 and not s: print(0, 0) exit() if not s or 9 * m < s: print(-1, -1) exit() curs = s for i in range(m): l = curs - (m - i - 1) * 9 if l <= 0: if i == 0: mn += "1" curs -= 1 else: mn += "0" elif l >= 0: mn += str(l) curs -= l print(mn, end=" ") curs = s for i in range(m): if curs - 9 >= 0: mx += "9" curs -= 9 elif curs > 0: mx += str(curs) curs = 0 else: mx += "0" print(mx)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR STRING STRING IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR STRING VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR STRING 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
n, s = map(int, input().split()) s1 = s s2 = s maxs = "" mins = "" maxcount = 0 mincount = 0 if s < 1 or n * 9 < s: if n == 1 and s == 0: print("0 0") else: print("-1 -1") else: while s1 > 0: if s1 >= 9: s1 -= 9 maxcount += 1 maxs = maxs + "9" else: maxs = maxs + str(s1) s1 = 0 maxcount += 1 if maxcount < n: maxs = maxs + "0" * (n - maxcount) while s2 > 1 and mincount < n - 1: if s2 > 9: s2 -= 9 mincount += 1 mins = "9" + mins else: mins = str(s2 - 1) + mins mincount += 1 s2 = 1 if mincount < n - 1: mins = "1" + "0" * (n - 1 - mincount) + mins elif mincount == n - 1: mins = str(s2) + mins print(mins + " " + maxs)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING WHILE VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL 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
data = input().split() m, s = int(data[0]), int(data[1]) if m == 1 and 0 <= s <= 9: print(s, s) elif m >= 2 and 1 <= s <= m * 9: num1 = "" s1 = s for i in range(1, 10): if 0 <= s1 - i <= (m - 1) * 9: num1 += str(i) s1 -= i break for j in range(2, m): for k in range(10): if 0 <= s1 - k <= (m - j) * 9: num1 += str(k) s1 -= k break num1 += str(s1) num2 = "" s2 = s for i in range(9, 0, -1): if 0 <= s2 - i <= (m - 1) * 9: num2 += str(i) s2 -= i break for j in range(2, m): for k in range(9, -1, -1): if 0 <= s2 - k <= (m - j) * 9: num2 += str(k) s2 -= k break num2 += str(s2) print(num1, num2) else: print(-1, -1)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER IF NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL 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()) nine = int(s / 9) shengyu = s - nine * 9 Max = "" Min = "" if s > 9 * m: Max = -1 Min = -1 print(Min, Max) elif s == 9 * m: while m > 0: Max = Max + str(9) Min = Min + str(9) m = m - 1 print(Min, Max) elif s == 0 and m == 1: Max = 0 Min = 0 print(Min, Max) elif s == 0 and m > 1: Max = -1 Min = -1 print(Min, Max) elif m == 1: Min = s Max = s print(Min, Max) elif m == 2 and nine == 0: Min = str(1) + str(shengyu - 1) Max = str(shengyu) + str(0) print(Min, Max) elif m == 2 and nine != 0: Min = str(s - 9) + str(9) Max = str(9) + str(s - 9) print(Min, Max) elif m > 2: weizhui = "" while nine > 0: weizhui = weizhui + str(9) nine = nine - 1 qianzhui = weizhui if shengyu > 0: weizhui = str(shengyu - 1) + str(weizhui) weishu = len(weizhui) if weishu == m: Min = str(shengyu) + str(qianzhui) Max = str(qianzhui) + str(shengyu) else: a = m - len(str(qianzhui) + str(shengyu)) zzero = "" while a > 0: zzero = zzero + str(0) a = a - 1 if weishu < m - 1: Min = str(10 ** (m - weishu - 1)) + str(weizhui) Max = str(qianzhui) + str(shengyu) + str(zzero) elif weishu == m - 1: Min = str(10 ** (m - weishu - 1)) + str(weizhui) Max = str(qianzhui) + str(shengyu) + str(0) else: Min = weizhui Max = str(qianzhui) + str(shengyu) else: zero = m - len(weizhui) x = zero houchuo = "" chuochuo = "" while zero > 0: houchuo = str(houchuo) + str(0) zero = zero - 1 while x > 1: chuochuo = str(chuochuo) + str(0) x = x - 1 if s == 9: zhongjian = "" while m - 2 > 0: zhongjian = zhongjian + str(0) m = m - 1 Min = str(1) + str(zhongjian) + str(8) Max = weizhui + houchuo else: Max = weizhui + houchuo hou = "" b = len(weizhui) - 1 while b > 0: hou = hou + str(9) b = b - 1 Min = str(1) + str(chuochuo) + str(8) + str(hou) print(Min, Max)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP NUMBER VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER 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 > m * 9 or s == 0 and m > 1: max = str(-1) min = str(-1) else: a = 0 while s > 9 * (a + 1): a += 1 max = "9" * a + str(s - 9 * a) + "0" * (m - a - 1) if "0" in max: if "1" in max: min = "1" + "0" * (m - a - 1) + "9" * a else: min = "1" + "0" * (m - a - 2) + str(s - 9 * a - 1) + "9" * a else: min = str(s - 9 * a) + "9" * (m - 1) if "-" in min: min = 0 print(min, max)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER IF STRING VAR IF STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP STRING BIN_OP VAR NUMBER IF STRING VAR 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
n, m = map(int, input().split()) max = 0 min = 0 if m == 0 and n != 1 or m > 9 * n: print(-1, -1) elif n == 1 and m == 0: print(0, 0) else: min = 10 ** (n - 1) for i in range(m - 1): a = i // 9 min += 10**a max = 0 for i in range(m): b = n - 1 - i // 9 max += 10**b print(min, max)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER 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
__author__ = "user" m, s = map(int, input().split()) if s == 0 and m > 1 or s > 9 * m: min_num = max_num = -1 elif m == 1: min_num = max_num = s else: nns1 = s // 9 d = s % 9 max_num = "9" * nns1 if nns1 != m: max_num += str(d) + "0" * (m - nns1 - 1) if s <= (m - 1) * 9: nns2 = (s - 1) // 9 d = (s - 1) % 9 min_num = "1" + "0" * (m - nns2 - 1 - 1) if nns2 != m: min_num += str(d) + "9" * nns2 else: min_num = "" if s // 9 != m: min_num = str(s % 9) min_num += "9" * (s // 9) print(min_num, max_num)
ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP 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
def main(): m, s = map(int, input().split()) s1 = s if s == 0 and m == 1: print(0, 0) elif s < 1 or s > 9 * m: print("-1 -1") else: probmax = [0] * m for i in range(m - 1): if s1 > 9: probmax[i] = 9 s1 -= 9 probmax[-1] = s - sum(probmax) probmax.sort(reverse=True) probmin = [0] * m if s < 9 * (m - 1) + 2: probmin[0] = 1 for i in range(m - 1): if s <= 9 * (m - i - 2): probmin[i + 1] = 0 elif s <= 9 * (m - i - 1): probmin[i + 1] = s - 1 - 9 * (m - i - 2) else: probmin[i + 1] = 9 else: probmin[0] = s - 9 * (m - 1) for i in range(m - 1): probmin[i + 1] = 9 print( "".join([str(number) for number in probmin]), "".join([str(number) for number in probmax]), ) main()
FUNC_DEF 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 BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR 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 = input().split() m = int(m) s = int(s) zx = -1 min = a = aa = "" if s > 9 * m: print("-1 -1") if s <= 0 and m != 1: print("-1 -1") if m == 1 and s == 0: print("0 0") elif s <= 9 * m and (s > 0 or m == 1): c = int(s / 9) for i in range(c): a += "9" max = a + str(s - 9 * c) while len(max) < m: max = max + "0" max = max[:m] for k in max: min = k + min if int(min[0]) == 0: for h in min: zx += 1 if int(h) != 0: hh = str(int(h) - 1) break min = "1" + min[1:zx] + hh + min[zx + 1 :] print(min, max)
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 VAR VAR STRING IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL 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 VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR NUMBER VAR VAR VAR BIN_OP 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
n, s = map(int, input().split()) minR = (s + 8) // 9 if minR > n or s == 0 and n > 1: print(-1, -1, end=" ") else: minZnac = int(str(s % 9) + "9" * (s // 9)) lenMin = len(str(minZnac)) if lenMin < n: minZnac -= 10 ** (lenMin - 1) lenMin = len(str(minZnac)) print(1, "0" * (n - 1 - lenMin), minZnac, sep="", end=" ") else: print(minZnac, end=" ") print("9" * (s // 9), end="") n -= s // 9 s %= 9 if n > 0: print(str(s) + "0" * (n - 1))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP 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
l = input().split() n, s = int(l[0]), int(l[1]) a = b = [] if 1 <= s <= 9 * n: a = [9] * (s // 9) if s % 9: a += [s % 9] d = n - len(a) if d: a += [0] * d b = a[::-1] b[0] = 1 b[d] -= 1 else: b = a[::-1] a = "".join(map(str, a)) b = "".join(map(str, b)) print(b, a) elif s == 0 and n == 1: print("0 0") else: print("-1 -1")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR LIST IF NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR LIST BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER 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
def ss(n, m): if m > n * 9: return "-1 -1" if m < n: if m == 0: if n == 1: return "0 0" else: return "-1 -1" slist = ["9"] * ((m - 1) // 9) + [str((m - 1) % 9)] if len(slist) == n: k = int(slist.pop()) slist.append(str(k + 1)) small = "".join(sorted(slist)) else: while True: if len(slist) >= n - 1: break slist.append("0") small = "1" + "".join(sorted(slist)) blist = ["9"] * (m // 9) + [str(m % 9)] if m % 9 == 0: del blist[-1] while True: if len(blist) >= n: break blist.append("0") big = "".join(sorted(blist, reverse=True)) return small + " " + big s = input() k = list(map(int, s.split())) n = k[0] m = k[1] print(ss(n, m))
FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN STRING IF VAR VAR IF VAR NUMBER IF VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR BIN_OP BIN_OP LIST STRING BIN_OP BIN_OP VAR NUMBER NUMBER LIST FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR WHILE NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP STRING FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST STRING BIN_OP VAR NUMBER LIST FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR STRING VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER 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
m, s = [int(i) for i in input().split()] output1 = "" output2 = "" if s == 0: if m != 1: print("-1 -1") elif m == 1: print("0 0") elif m * 9 < s: print("-1 -1") elif s <= 9: if m == 1: output1 += str(s) output2 += str(s) print(output2, output1) elif m != 1: output1 += str(s) output2 += "1" while len(output1) < m: output1 += "0" while len(output2) < m - 1: output2 += "0" q = s - 1 output2 += str(q) print(output2, output1) elif s > 9: output1 += "9" w = s - 9 while w > 9: output1 += "9" w += -9 output1 += str(w) if len(output1) == m: output2 = output1[::-1] elif len(output1) < m: shengyu = m - len(output1) output2 += "1" while len(output2) < shengyu: output2 += "0" if w == 0: output2 += "08" elif w != 0: output2 += str(w - 1) while len(output2) < m: output2 += "9" while len(output1) < m: output1 += "0" print(output2, output1)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR STRING WHILE FUNC_CALL VAR VAR VAR VAR STRING WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR STRING WHILE FUNC_CALL VAR VAR VAR VAR STRING IF VAR NUMBER VAR STRING IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR 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 m > 1 and s == 0 or m == 1 and s > 9 or s > m * 9: print(-1, -1) else: s1 = s st = ["0"] * m i = m - 1 while s1 > 9: st[i] = "9" i -= 1 s1 -= 9 st[0] = "1" s1 -= 1 st[i] = str(int(st[i]) + s1) ans1 = int("".join(st)) s2 = s st = ["0"] * m i = 0 while s2 > 9: st[i] = "9" i += 1 s2 -= 9 st[i] = str(s2) ans2 = int("".join(st)) print(ans1, ans2)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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
a, b = input().split() a = int(a) b = int(b) if b > 9 * a or b == 0 and a > 1: print(-1, -1) elif b == 0 and a == 1: print(0, 0) else: x = 10 ** (a - 1) y = 0 i = 0 k = b - 1 while k > 0: if k > 9: k -= 9 x += 9 * 10**i i += 1 else: x += k * 10**i k = 0 i += 1 i = a - 1 k = b while k > 0: if k > 9: k -= 9 y += 9 * 10**i i -= 1 else: y += k * 10**i k = 0 i -= 1 print(x, y)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR 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 NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER 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
a = input().split() if int(a[0]) * 9 < int(a[1]): print("%d %d" % (-1, -1)) elif int(a[1]) == 0 and int(a[0]) != 1: print("%d %d" % (-1, -1)) elif int(a[1]) == 0 and int(a[0]) == 1: print("%d %d" % (0, 0)) else: d = ["0" for i in range(int(a[0]))] b = int(a[1]) // 9 c = int(a[1]) % 9 for i in range(0, b): d[i] = str(9) if c != 0: d[b] = str(c) f = "".join(d) g = ["0" for i in range(int(a[0]))] j = int(a[1]) - 1 k = j // 9 l = j % 9 if k < int(a[0]) - 1: for i in range(int(a[0]) - k, int(a[0])): g[i] = str(9) g[0] = str(1) g[int(a[0]) - k - 1] = str(l) else: for i in range(int(a[0]) - k, int(a[0])): g[i] = str(9) g[0] = str(l + 1) m = "".join(g) print("%s %s" % (m, f))
ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP STRING NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP STRING NUMBER NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR 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 = map(int, input().split()) a = [[]] * (m + 1) b = [[]] * (m + 1) for i in range(m + 1): a[i] = ["-1"] * (s + 1) b[i] = ["-1"] * (s + 1) for j in range(1, min(s, 9) + 1): a[1][j] = str(j) b[1][j] = str(j) for i in range(2, m + 1): a1 = a[i - 1] b1 = b[i - 1] for j1 in range(s + 1): if a1[j1] != "-1": for d in range(10): j = j1 + d if j > s: break new_val = a1[j1] + str(d) if a[i][j] == "-1" or new_val < a[i][j]: a[i][j] = new_val if b1[j1] != "-1": for d in range(10): j = j1 + d if j > s: break new_val = b1[j1] + str(d) if b[i][j] == "-1" or new_val > b[i][j]: b[i][j] = new_val a[1][0] = "0" b[1][0] = "0" print(a[m][s], b[m][s])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST LIST BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST LIST BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP LIST STRING BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP LIST STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR VAR VAR 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
while True: try: def solution(m, s): if s == 0 and m == 1: print(0, 0) elif s == 0 or s > 9 * m: print("-1 -1") else: indx = [0] * 100 indx[0] = 1 ts = s - 1 tlc = m - 1 while ts > 0: while ts > 0 and indx[tlc] < 9: indx[tlc] += 1 ts -= 1 tlc -= 1 ind = [0] * 100 ind[0] = 1 ts = s - 1 tlc = 0 while ts > 0: while ts > 0 and ind[tlc] < 9: ind[tlc] += 1 ts -= 1 tlc += 1 snum = "" lnum = "" for i in range(m): snum += str(indx[i]) lnum += str(ind[i]) print(snum, lnum) def read(): m, s = map(int, input().split()) solution(m, s) if __name__ == "__main__": read() except EOFError: break
WHILE NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER 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 FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR STRING 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
[m, s] = list(map(int, input().strip().split())) if s == 0 and m > 1 or s > 9 * m: print("-1 -1") elif s == 0 and m == 1: print("0 0") else: largest, smallest = ["0"] * m, ["0"] * m s1, s2 = s, s for idx in range(m): largest[idx] = str(min(s1, 9)) s1 -= int(largest[idx]) smallest[0] = str(max(1, s2 - 9 * (m - 1))) s2 -= int(smallest[0]) for idx in range(1, m): smallest[idx] = str(max(0, s2 - 9 * (m - idx - 1))) s2 -= int(smallest[idx]) print("".join(smallest) + " " + "".join(largest))
ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP LIST STRING VAR BIN_OP LIST STRING VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING VAR STRING 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 get(m, s): lis_1 = ["0" for i in range(m)] lis_2 = ["0" for i in range(m)] s_1 = s for i in range(m): if s >= 9: lis_1[i] = "9" s -= 9 else: lis_1[i] = str(s) break s = s_1 if s > (m - 1) * 9: lis_2 = [str(s - (m - 1) * 9)] + ["9" for j in range(m - 1)] else: lis_2[0] = "1" b = s - 1 for i in range(1, m): if b >= 9: lis_2[-i] = "9" b -= 9 else: lis_2[-i] = str(b) break result_1 = "".join(lis_1) result_2 = "".join(lis_2) return result_2, result_1 m, s = map(int, input().split()) if m == 1 and s == 0: print(0, 0) elif s == 0 or s > m * 9: print(-1, -1) else: a, b = get(m, s) print(a, b)
FUNC_DEF ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR RETURN VAR VAR 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 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
a = input().split() num = int(a[0]) s = int(a[1]) def getmin(x, y): c = [(0) for j in range(0, x)] su = y for i in range(0, x): if su > 9: c[x - i - 1] = 9 su = su - 9 else: if i == x - 1: c[0] = su else: c[0] = 1 c[x - i - 1] = su - 1 break return c def getmax(x, y): c = [(0) for j in range(0, x)] su = y for i in range(0, x): if su > 9: c[i] = 9 su = su - 9 else: c[i] = su break return c if s >= 1 and s <= 9 * num: c = getmin(num, s) d = getmax(num, s) e = "".join(str(i) for i in c) f = "".join(str(i) for i in d) print(int(e), int(f)) elif s == 0 and num == 1: print("0 0") else: print("-1 -1")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER 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
a, b = list(map(int, input().split())) if b > a * 9: print("-1 -1") elif b == 0: if a == 1: print("0 0") else: print("-1 -1") elif a == 1: print(b, b) elif b <= 9: print(1, end="") print("0" * (a - 2), end="") print(b - 1, b, end="") print("0" * (a - 1)) elif a * 9 == b: print("9" * a, end=" ") print("9" * a) else: if (a - 1) * 9 < b: print(b - (a - 1) * 9, end="") print("9" * (a - 1), end=" ") else: print(1, end="") c = (b - 1) // 9 + 2 print("0" * (a - c), end="") print((b - 1) % 9, end="") print("9" * (c - 2), end=" ") print("9" * (b // 9), end="") print(b % 9, end="") print("0" * (a - b // 9 - 1))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF 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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP STRING 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 = input().split() m, s = int(m), int(s) if 9 * m < s or m > 1 and s == 0: print("-1 -1") elif m == 1 and s == 0: print("0 0") else: x = int(s / 9) y = s % 9 if y == 0: if x == m: print(str(9) * m, str(9) * m) else: print( "1" + str(0) * (m - 1 - x) + "8" + str(9) * (x - 1), str(9) * x + str(0) * (m - x), ) elif x == m - 1: print(str(y) + str(9) * x, str(9) * x + str(y)) else: print( "1" + str(0) * (m - 2 - x) + str(y - 1) + str(9) * x, str(9) * x + str(y) + str(0) * (m - 1 - x), )
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR STRING BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR 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
n, m = map(int, input().split()) mx = "" mn = [0] * 109 o = 0 def f(x, sz): for i in range(sz): x += "0" return x if m == 0 and n == 1: print("0 0") exit() if m == 0 or m > n * 9: print("-1 -1") exit() k = m for i in range(9, 0, -1): while k - i >= 0: k -= i mx += chr(i + 48) sz = szmn = n - 1 k = m for i in range(1, 10): if sz == 0: break while k - i >= 0 and o == 0: if sz == 0: break j = (k - i) // sz + ((k - i) % sz != 0) if j <= 9: mn[0] = i k -= i sz -= 1 o = 1 else: break for i in range(9, 0, -1): while k - i >= 0: k -= i mn[szmn] = i szmn -= 1 mx = f(mx, n - len(mx)) for i in range(n): print(mn[i], end="", sep="") print(" " + mx)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR STRING RETURN VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP 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
a, b = input().split() a = int(a) b = int(b) f = b if a == 1 and b <= 9: print(b, end=" ") print(b) exit() if a > 1 and b == 0: print(-1, end=" ") print(-1) exit() if 9 * a < b: print(-1, end=" ") print(-1) exit() if 9 * (a - 1) > b: c = 1 else: c = b - 9 * (a - 1) b = b - c d = str(c) for i in range(1, a): if b < 9 and i != a - 1: d = d + "0" elif 9 * (a - 1 - i) > b: d = d + "0" elif 9 * (a - 1 - i) <= b: c = b - 9 * (a - 1 - i) b = b - c d = d + str(c) e = "" for i in range(1, a + 1): if f >= 9: e = e + "9" f = f - 9 else: e = e + str(f) f = 0 print(d, end=" ") print(e)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR STRING IF BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING 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
n, m = map(int, input().split()) if n == 1 and m <= 9 * n: print(str(m) + " " + str(m)) elif m == 0 or m > 9 * n: print("-1 " + "-1") else: a = m // 9 b = m % 9 if a == 0: x = str(b) + (n - 1) * "0" elif m == 9 * n: x = n * "9" else: x = a * "9" + str(b) + (n - 1 - a) * "0" if m >= 9 * n - 8: y = str(m + 9 - 9 * n) + (n - 1) * "9" else: m = m - 1 n = n - 1 c = m // 9 d = m % 9 if c == 0: y = "1" + (n - 1) * "0" + str(d) elif m == 9 * n: y = "1" + n * "9" else: y = "1" + (n - 1 - c) * "0" + str(d) + c * "9" print(y + " " + x)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER STRING IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR STRING IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP STRING BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR NUMBER VAR STRING FUNC_CALL VAR VAR BIN_OP VAR STRING 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 = list(map(int, input().split())) cs = s if s == 0 and m > 1 or s > m * 9: print("-1 -1") else: largest = [0] * m i = 0 while i < m: x = min(9, s) largest[i] = x s = s - x i = i + 1 smallest = largest[::-1] s = cs if s > 0 and smallest[0] == 0: i = 0 while i < m: if smallest[i] != 0: break i = i + 1 smallest[0] = 1 smallest[i] -= 1 largest = "".join(map(str, largest)) smallest = "".join(map(str, smallest)) print(smallest, largest)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING 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
q = input().split() le = int(q[0]) su = int(q[1]) i = 10 ** (le - 1) ma = 0 mi = 0 ri = 0 if su == 0 and le != 1: print("-1 -1") elif su > 9 * le: print("-1 -1") elif le == 1 and su == 0: print("0 0") elif su <= 9: print(i + su - 1, i * su) else: q = int(su / 9) p = su % 9 if q == le: mi = ma = 10**le - 1 elif q == le - 1: mi = i * p + i - 1 ma = 10**le - 10 + p elif p == 0: for j in range(q): mi += 10**j * 9 ma += 10 ** (le - 1 - j) * 9 mi += i - 10 ** (q - 1) ma += 10 ** (le - 1 - q) * p else: for j in range(q): mi += 10**j * 9 ma += 10 ** (le - 1 - j) * 9 mi += i + 10**q * ((p + 8) % 9) ma += 10 ** (le - 1 - q) * p print(mi, ma)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER 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
x = input() y = x.split() n = int(y[0]) summ = int(y[1]) maxlist = list() if summ > n * 9: print("-1 -1") elif n > 1 and summ == 0: print("-1 -1") elif n == 1 and summ == 0: print("0 0") else: for i in range(9): nn = 9 - i while summ >= int(nn): summ -= int(nn) maxlist.append(str(nn)) leng = len(maxlist) rest = int(n - leng) if rest == 0: maxm = int("".join(maxlist)) maxlist.reverse() mini = int("".join(maxlist)) print("%d %d" % (mini, maxm)) else: numb = "".join(maxlist) numbs = str(int(numb) - 1) maxm = int(numb + str(0) * rest) sb = list(numbs) sb.reverse() sbb = "".join(sb) mini = int(str(1) + str(0) * (rest - 1) + sbb) print("%d %d" % (mini, maxm))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR 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 = map(int, input().strip().split()) s1, s2 = s, s l = [(0) for x in range(m)] l1 = [(0) for x in range(m)] for i in range(m): if s <= 0: break for j in range(9, 0, -1): if s >= j: l[i] = j s -= j break for i in range(m): if s1 <= 0: break if i == 0: for j in range(1, 10): if s1 >= j and s1 - j <= 9 * (m - i - 1): l1[i] = j s1 -= j break else: for j in range(10): if s1 >= j and s1 - j <= 9 * (m - i - 1): l1[i] = j s1 -= j break if s2 == 0 and m == 1 or sum(l) == s2 and s2 > 0: lr = "".join(map(str, l)) sm = "".join(map(str, l1)) else: lr, sm = -1, -1 print(sm, lr)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR 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 = map(int, input().split()) def maximum(m, s): a = s // 9 if s - 9 * a > 0: max_num = "9" * a + str(s - 9 * a) + "0" * (m - a - 1) else: max_num = "9" * a + "0" * (m - a) return max_num if m == 1 and s == 0: print("0", "0") elif 1 <= s <= 9 * m: c = maximum(m, s) d = c[::-1] if d[0] != "0": print(d, c) else: e = maximum(m - 1, s - 1) print("1" + e[::-1], c) else: print(-1, -1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR VAR RETURN VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER 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
line = input() m = int(line.split(" ")[0]) s = int(line.split(" ")[1]) max = 0 min = 0 if m > 1: if s != 0: if s < 9 * m: a = s // 9 b = s % 9 for i in range(1, a + 1): max = max + 9 * 10**i max = max + b max = max * 10 ** (m - a - 1) if a == m - 1: if b != 0: min = b * 10 ** (m - 1) for i in range(a): min = min + 9 * 10**i if b == 0: min = 18 * 10 ** (m - 2) min = min + 99 if a < m - 1: if b != 0: for i in range(a): min = min + 9 * 10**i while b > 1: min = min + 10**a b = b - 1 min = min + 10 ** (m - 1) if b == 0: for i in range(a - 1): min = min + 9 * 10**i min = min + 8 * 10 ** (a - 1) min = min + 10 ** (m - 1) if s == 9 * m: for i in range(m): max = max + 9 * 10**i min = max if s > 9 * m: max = -1 min = -1 else: max = -1 min = -1 if m == 1: if s <= 9: min = s max = s else: min = -1 max = -1 print(min, max)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR 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
import sys input = sys.stdin.readline def inlt(): return list(map(int, input().split())) min_map = {} max_map = {} def sum_of_digits(digit): digit_sum = 0 while digit: rem = digit % 10 digit_sum += rem digit //= 10 return digit_sum def min_helper(l, s): if l == 0: return -1 if l == 1: if len(str(s)) == 1: return str(s) else: return str(-1) if (l, s) in min_map: return min_map[l, s] start = 10 ** int(l - 1) increment = 10 ** int(l - 1) for i in range(9): end = start + increment - 1 if sum_of_digits(start) <= s <= sum_of_digits(end): if -1 < s - end // 10 ** (l - 1) < 10: res = "" if l > 2: res = "0" * (l - 2) res += str(s - end // 10 ** (l - 1)) else: res = min_helper(l - 1, s - end // 10 ** (l - 1)) if res != "-1": min_map[l, s] = str(end // 10 ** (l - 1)) + res return min_map[l, s] start += increment min_map[l, s] = str(-1) return str(-1) def max_helper(l, s): if l == 0: return -1 if l == 1: if len(str(s)) == 1: return str(s) else: return str(-1) if (l, s) in max_map: return max_map[l, s] decrement = 10 ** int(l - 1) end = 10 ** int(l) - 1 for i in range(9): start = end - decrement + 1 if sum_of_digits(start) <= s <= sum_of_digits(end): if s - end // 10 ** (l - 1) == 0: res = "0" * (l - 1) else: res = max_helper(l - 1, s - end // 10 ** (l - 1)) if res != "-1": max_map[l, s] = str(end // 10 ** (l - 1)) + res return max_map[l, s] end -= decrement max_map[l, s] = str(-1) return str(-1) def solve(m, s): stack = [] rem = s if s > 9 * m or s == 0 and m > 1: print("-1 -1") return if s == 0 and m == 1: print("0 0") return for i in range(m): stack.append(min(9, rem)) rem -= min(9, rem) _max = "".join(map(str, stack)) stack = stack[::-1] if stack[0] != 0: _min = "".join(map(str, stack)) else: stack[0] += 1 for i, num in enumerate(stack[1:]): if stack[i + 1] != 0: stack[i + 1] -= 1 break _min = "".join(map(str, stack)) print("%s %s" % (_min, _max)) ms = inlt() solve(ms[0], ms[1])
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR RETURN FUNC_CALL VAR NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF NUMBER BIN_OP VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR RETURN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER RETURN FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR RETURN FUNC_CALL VAR NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR RETURN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER RETURN FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR ASSIGN VAR FUNC_CALL 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
shuru = input() pieces = shuru.split() a = int(pieces[0]) b = int(pieces[1]) minn = "" yiyong = 0 if b < 0 or b > 9 * a: print("-1 -1") elif b == 0 and a == 1: print("0 0") elif b == 0 and a != 1: print("-1 -1") elif b >= 9 * (a - 1) + 1: minn = str(b - 9 * (a - 1)) for i in range(0, a - 1): minn = minn + str(9) print(minn, end=" ") else: minn = str(1) howmany9 = (b - 1) // 9 jiuzhiqian = b - 1 - howmany9 * 9 sjzq = str(jiuzhiqian) howmany0 = a - 1 - howmany9 - 1 for i in range(1, howmany0 + 1): minn = minn + str(0) minn = minn + sjzq for i in range(1, howmany9 + 1): minn = minn + str(9) print(minn, end=" ") yiyong = 0 maxx = "" if b < 0 or b > 9 * a: t = 1 elif b == 0 and a == 1: t = 1 elif b == 0 and a != 1: t = 1 else: for i in range(a): shengxia = b - yiyong zheciyong = min(9, shengxia) szcy = str(zheciyong) maxx = maxx + szcy yiyong = yiyong + zheciyong print(maxx)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL 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 BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP 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
m, s = map(int, input().split()) if m > 1 and s == 0 or s > 9 * m or m == 1 and s > 9: print(-1, -1) elif s == 9 * m: print("9" * m, "9" * m) elif m == 1: print(s, s) else: r = s i = 0 a = [0] * m b = [0] * m while i < m: for j in range(9, 0, -1): l = s - j if l >= 0: b[i] = j s -= j break i += 1 s = round(r % 9) k = round((r - r % 9) / 9) for j in range(m - 1, m - k - 1, -1): a[j] = 9 a[m - k - 1] = s if a[0] == 0: a[0] = 1 for i in range(m - k - 1, m): if a[i]: a[i] -= 1 break for i in range(m): print(a[i], end="") print(end=" ") for i in range(m): print(b[i], end="")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING 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
st = input() st = [int(i) for i in st.strip().split()] ln, sm = st[0], st[1] summa = sm mn = [] while len(mn) < ln: if summa - 9 >= 0: mn.append(9) summa = summa - 9 else: mn.append(summa) summa = 0 if sum(mn) == sm and len(mn) == ln: big = [str(j) for j in mn] if mn[0] != 0 or len(mn) == 1 else ["-1"] if big[0] == "-1": little = ["-1"] else: little = mn[::-1] if little[0] == 0: for i in range(1, len(little)): if little[i] != 0: little[0] = 1 little[i] = little[i] - 1 break little = [str(j) for j in little] print("{0} {1}".format("".join(little), "".join(big))) else: print("-1 -1")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR LIST STRING IF VAR NUMBER STRING ASSIGN VAR LIST STRING ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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().split()) minres = [] maxres = [] if s == 0 and m > 1: maxres = ["-1"] minres = ["-1"] if m and s: if s <= 9: maxres = [str(s)] + (m - 1) * ["0"] elif 9 * m > s: maxres = ["9"] * (s // 9) + [str(s % 9)] + (m - (s // 9 + 1)) * ["0"] elif 9 * m == s: maxres = ["9"] * (s // 9) else: maxres = ["-1"] currentsum = 0 if m and s: minres = ["0"] * m for i in range(m): if s - currentsum <= 9 and i == m - 1: minres[i] = str(s - currentsum) elif s - currentsum <= 9 and i != m - 1: minres[i] = str(s - currentsum - 1) minres[m - 1] = "1" break elif s - currentsum > 9: minres[i] = "9" currentsum += 9 minres.reverse() if 9 * m < s: minres = ["-1"] if s == 0 and m == 1: maxres = ["0"] minres = ["0"] print("".join(minres), end=" ") print("".join(maxres))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR LIST STRING IF VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER LIST STRING IF BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST STRING BIN_OP VAR NUMBER LIST FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER LIST STRING IF BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR ASSIGN VAR LIST STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR LIST STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR STRING 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
m, s = map(int, input().split()) if m == 1 and s == 0: print("0 0") elif m > 1 and s == 0: print("-1 -1") elif s > 9 * m: print("-1 -1") else: sum_min = s - 1 k = 0 Min_suff = [] while sum_min > 0 or k < m: if sum_min > 9: Min_suff = [9] + Min_suff sum_min -= 9 else: Min_suff = [sum_min] + Min_suff sum_min = 0 k += 1 Min_suff[0] += 1 Min_suff = list(map(str, Min_suff)) min_str = "".join(Min_suff) sum_max = s k1 = 0 Max_suff = [] while sum_max > 0 or k1 < m: if sum_max > 9: Max_suff = Max_suff + [9] sum_max -= 9 else: Max_suff = Max_suff + [sum_max] sum_max -= sum_max k1 += 1 Max_suff = list(map(str, Max_suff)) max_str = "".join(Max_suff) print(min_str, max_str)
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 VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR LIST VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR 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
m, s = map(int, input().split()) if s == 0 and m == 1: print(0, 0) exit() if m * 9 < s or s == 0: print(-1, -1) exit() l = [9] * m i = 0 f = 0 x = 9 * m while i < len(l) and f == 0 and x != s: if l[i] == 1 and i == 0: i = i + 1 elif l[i] == 0: i = i + 1 else: l[i] = l[i] - 1 x = x - 1 if x == s: f = 1 e = "" p = 0 for i in l: u = str(i) e = e + u p = p + i o = [0] * m i = 0 while i < len(l) and p != 0: if o[i] == 9: i = i + 1 else: o[i] = o[i] + 1 p = p - 1 r = "" for i in o: r = r + str(i) print(e, r)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING 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
x, y = map(int, input().split()) if 9 * x < y: print(-1, -1) exit(0) if y == 0: if x != 1: print(-1, -1) else: print(0, 0) exit(0) mx = [0] * x v = y for n in range(x): p = 9 if v > 9: v -= p else: p = v v = 0 mx[n] += p mx.sort(reverse=True) mn = mx[::-1] n = 0 while not mn[n]: n += 1 mn[n] -= 1 mn[0] += 1 a = "" b = "" for n in mn: a += str(n) for n in mx: b += str(n) print(a, b)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR FOR 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()) maxi = [] mini = [] line = [] if s > 9 * m: print("-1", "-1") elif m > 1 and s == 0: print("-1", "-1") elif m == 1: print(s, s) else: s_ = s while s > 9: maxi.append(str(9)) s -= 9 else: maxi.append(str(s)) if len(maxi) == m: pass else: x = m - len(maxi) for i in range(x): maxi.append(str(0)) if s_ <= 9: mini.append(str(1)) for j in range(m - 2): mini.append(str(0)) mini.append(str(s_ - 1)) elif s_ > (m - 1) * 9: mini.append(str(s_ - (m - 1) * 9)) for t in range(m - 1): mini.append(str(9)) else: s_ -= 10 while s_ > 9: line.append(str(9)) s_ -= 9 else: line.append(str(s_)) if len(line) == m - 2: pass else: y = m - 2 - len(line) for i in range(y): line.append(str(0)) mini.append(str(1)) for k in range(m - 2 - 1, -1, -1): mini.append(str(line[k])) mini.append(str(9)) print("".join(mini), end=" ") print("".join(maxi))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR STRING 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
m, s = input().split() m = int(m) s = int(s) if s == 0: if m == 1: print("0 0") else: print("-1 -1") exit() sumdigits = int(s - 1) arr = [1] for i in range(m - 1): arr.append(0) for i in reversed(range(m)): tmp = min(9 - arr[i], sumdigits) arr[i] += tmp sumdigits -= tmp if sumdigits != 0: print(-1, end="") else: for i in range(m): print(arr[i], end="") print(" ", end="") sumdigits = int(s - 1) arr = [1] for i in range(m - 1): arr.append(0) for i in range(m): tmp = min(9 - arr[i], sumdigits) arr[i] += tmp sumdigits -= tmp if sumdigits != 0: print(-1, end="") else: for i in range(m): print(arr[i], end="") print("")
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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, n = [int(x) for x in input().split(" ")] if n < 1 and m == 1: print(0, 0) elif n > 9 * m or n < 1: print(-1, -1) else: n2 = n biggest = "" while n > 0: biggest += str(min(9, n)) n -= 9 biggest += "0" * (m - len(biggest)) smallest = "" while n2 > 0: smallest = str(min(9, n2)) + smallest n2 -= min(9, n2) if len(smallest) < m: if len(smallest) > 1: smallest = ( "1" + "0" * (m - len(smallest) - 1) + str(int(smallest[0]) - 1) + smallest[1:] ) else: smallest = "1" + "0" * (m - 2) + str(int(smallest[0]) - 1) print(smallest, biggest)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING 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 ASSIGN VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR 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
def isPossible(s, m): return s >= 0 and s <= 9 * m def findMinimun(m, s): num = 0 for index in range(m, 0, -1): flag = True for digit in range(10): if index == m and digit == 0 and m > 1: continue if isPossible(s - digit, index - 1): flag = False num = num * 10 + digit s -= digit break if flag: return -1 return num def findMaximum(m, s): num = 0 for index in range(m, 0, -1): flag = True for digit in range(9, -1, -1): if index == m and digit == 0 and m > 1: continue if isPossible(s - digit, index - 1): flag = False num = num * 10 + digit s -= digit break if flag: return -1 return num m, s = tuple(map(int, input().split())) print(findMinimun(m, s), findMaximum(m, s))
FUNC_DEF RETURN VAR NUMBER VAR BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR RETURN NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR RETURN NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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
a = [int(x) for x in input().split(" ")] x = a[0] y = a[1] if y > 9 * x: print("-1 -1") elif y == 0: if x == 1: print("0 0") else: print("-1 -1") else: larg = [] for i in range(x): if 9 <= y: larg.append(9) y -= 9 else: larg.append(y) y -= y largnum = "".join(str(i) for i in larg) smal = list(reversed(larg)) if smal[0] != 0: smalnum = "".join(str(i) for i in smal) else: for i in range(x): if smal[i] != 0: smal[i] -= 1 smal[0] = 1 smalnum = "".join(str(i) for i in smal) break print(smalnum, largnum)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING 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()) if s == 0: if m == 1: print("0 0\n") else: print("-1 -1\n") exit() temp = "9" * (s // 9) if s % 9: temp += f"{s % 9}" if len(temp) > m: print("-1 -1\n") exit() maximum = temp while len(maximum) < m: maximum += "0" while len(temp) < m: temp = temp[:-1] + f"{int(temp[-1]) - 1}" while len(temp) < m - 1: temp += "0" temp += "1" minimum = temp[::-1] print(f"{minimum} {maximum}")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR STRING WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR STRING VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR 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()) if s == 0: if m == 1: print(0, 0) else: print(-1, -1) elif s > 9 * m: print(-1, -1) else: nines, mod = divmod(s - 1, 9) min_number = "" if nines < m - 1: min_number = "1" + "0" * (m - nines - 2) + str(mod) + "9" * nines else: min_number = str(mod + 1) + "9" * nines nines, mod = divmod(s, 9) max_number = "" if mod: max_number = "9" * nines + str(mod) + "0" * (m - nines - 1) else: max_number = "9" * nines + "0" * (m - nines) print(min_number, max_number)
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 IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING IF VAR 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 VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP 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
length, total = map(int, input().strip().split(" ")) if total > 9 * length or total == 0: if length == 1 and total == 0: print(0, 0) else: print(-1, -1) else: l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ans = "" i = len(l) - 1 tota = 0 while i >= 0: if total >= total - i >= 0: total -= i tota += i ans += str(l[i]) else: i -= 1 if total == 0: break result = "" rr = list(ans) i = length - len(ans) ans += "0" * (length - len(ans)) if i > 0: rr[len(rr) - 1] = chr(ord(rr[-1]) - 1) while i > 1: rr.append(0) i -= 1 rr.append("1") asn = "" i = length - 1 while i >= 0: asn += str(rr[i]) i -= 1 print(asn, ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR 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
r = input().split() length = int(r[0]) digit = int(r[1]) digitc = int(r[1]) le = 0 m = [] ans1 = 0 ans2 = 0 if length == 1 and digit <= 9 * length: print(digit, digit) elif digit == 0 or digit > 9 * length: print("-1 -1") else: while le != length: if digitc >= 9: m.append(9) digitc -= 9 le += 1 else: m.append(digitc) le += 1 digitc = 0 for i in range(length): ans1 += m[i] * 10 ** (length - i - 1) if digit > 9 and 9 * length - 8 < digit: for i in range(length): if m[i] != 0: ans2 += m[i] * 10**i else: mid = int(ans2 / 10 ** (i - 1)) midd = ans2 % 10 ** (i - 1) ans2 = int(10**i * mid + midd) elif digit <= 9: ans2 = 10 ** (length - 1) + digit - 1 elif digit > 9 and 9 * length - 8 >= digit: u = digit - 1 k = 0 l = [] while k != length: if u >= 9: l.append(9) u -= 9 le += 1 else: l.append(u) k += 1 u = 0 for i in range(length): ans2 += l[i] * 10**i ans2 += 10 ** (length - 1) print(ans2, ans1)
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING WHILE VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP 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, k = map(int, input().split()) A = list(str(k // m) * m) A = list(map(int, A)) A[-1] += k % m B = A[:] if 9 * m < k or sum(A) == 0 and len(A) > 1: print(-1, -1) else: c = m - 1 a = 0 while a != c and a < m and c >= 0 and a < c: if a == 0: if A[0] - 1 == 0: a += 1 elif A[c] + (A[0] - 1) > 9: s = A[c] A[c] += 9 - A[c] A[a] -= 9 - s c -= 1 else: A[c] += A[0] - 1 A[0] = 1 if A[c] == 9: c -= 1 a += 1 elif A[a] == 0: a += 1 elif A[c] + A[a] > 9: s = A[c] A[c] += 9 - A[c] A[a] -= 9 - s c -= 1 else: A[c] += A[a] A[a] = 0 if A[c] == 9: c -= 1 a += 1 for i in range(m): if i == 0: for j in range(i, m): if A[j] < A[i] and A[j] != 0: A[i], A[j] = A[j], A[i] else: for j in range(i, m): if A[j] < A[i]: A[i], A[j] = A[j], A[i] for i in A: print(i, end="") print(end=" ") M = sum(A) L = M // 9 A = [] for i in range(L): A.append(9) for i in range(m - L): A.append(0) A[-1] += M % 9 A.sort(reverse=True) for i in A[:]: print(i, end="")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR IF BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST 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 VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER 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 = map(int, input().split()) def validate(m, s): if m == 1 and s < 10: return s elif s == 0: return -1 elif 9 * m < s: return -1 return None def prep_max(m, s): r = validate(m, s) if r is not None: return r len_9 = s // 9 len_0 = m - len_9 return "9" * len_9 + str(s % 9) * bool(len_0) + "0" * (len_0 - 1) def prep_min(m, s): r = validate(m, s) if r is not None: return r head = "1" if (m - 1) * 9 >= s - 1 else str(s - (m - 1) * 9) s_tail = s - int(head) return head + (str(prep_max(m - 1, s_tail))[::-1] if s_tail else "0" * (m - 1)) print(prep_min(m, s), prep_max(m, s))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF BIN_OP NUMBER VAR VAR RETURN NUMBER RETURN NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP STRING BIN_OP VAR 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
L = input().split() m = int(L[0]) n = int(L[1]) def mi(a, b): c = [(0) for j in range(0, a)] for i in range(0, a): if b > 9: c[a - 1 - i] = 9 b = b - 9 else: if i == a - 1: c[0] = b else: c[0] = 1 c[a - 1 - i] = b - 1 break return c def ma(a, b): c = [(0) for j in range(0, a)] for i in range(0, a): if b > 9: c[i] = 9 b = b - 9 else: c[i] = b b = 0 break return c if m == 1 and n == 0: print("0 0") elif 9 * m < n or n <= 0: print("-1 -1") else: s = "".join(str(i) for i in mi(m, n)) t = "".join(str(i) for i in ma(m, n)) print(int(s), int(t))
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR 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 smallest(m, s): if m == 1 and s == 0: return 0 x = 10 ** (m - 1) y = str(x) z = [] for i in y: z.append(int(i)) i = m - 1 while i >= 0: if z[i] == 9: i -= 1 if sum(z) == s: a = "" for i in range(len(z)): a += str(z[i]) return a z[i] += 1 return -1 def largest(m, s): if m == 1 and s == 0: return 0 x = 10 ** (m - 1) y = str(x) z = [] for i in y: z.append(int(i)) i = 0 while i < m: if sum(z) == s: a = "" for i in range(len(z)): a += str(z[i]) return a z[i] += 1 if z[i] == 9: i += 1 if sum(z) == s: a = "" for i in range(len(z)): a += str(z[i]) return a return -1 m, s = map(int, input().split()) print(smallest(m, s), largest(m, s))
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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
[m, s] = [int(_) for _ in input().split()] if m == 1: if s == 0: ans = ["0", "0"] elif s > 9: ans = ["-1", "-1"] else: ans = [str(s), str(s)] elif s > m * 9 or s == 0: ans = ["-1", "-1"] else: lis = [] lis.extend([9] * (s // 9)) if s % 9 != 0: lis.append(s % 9) zeros = [0] * (m - len(lis)) maxnum = "".join([str(_) for _ in lis + zeros]) if s <= (m - 1) * 9 + 1: lis = [1] s -= 1 else: lis = [] if s % 9 > 0: lis.append(s % 9) lis.extend([9] * (s // 9)) zeros = [0] * (m - len(lis)) minnum = "".join([str(_) for _ in lis[:1] + zeros + lis[1:]]) ans = [minnum, maxnum] print(" ".join(ans))
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR LIST STRING STRING IF VAR NUMBER ASSIGN VAR LIST STRING STRING ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST STRING STRING ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER VAR NUMBER ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER 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
m, n = (int(i) for i in input().split()) if n == 0 and m != 1 or n > 9 * m: print(-1, -1) else: maxnum = "" n1 = n for i in range(m): maxnum += str(min(n1, 9)) n1 -= min(n1, 9) minnum = "" if n >= m: for i in range(m - 1): minnum += str(min(n - 1, 9)) n -= min(n - 1, 9) minnum += str(n) print(minnum[::-1], maxnum) else: a = "" for i in range(m - 1): a += str(min(n - 1, 9)) n -= min(n - 1, 9) print(str(n) + a[::-1], maxnum)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR 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
n, m = map(int, input().split()) if n == 1 and m == 0: print(0, 0) elif 1 <= m <= 9 * n: su = m ma = "" for i in range(n): if su > 9: ma += "9" su -= 9 else: ma += str(su) su = 0 su = m - 1 mi = "" for i in range(n - 1): if su > 9: mi = "9" + mi su -= 9 else: mi = str(su) + mi su = 0 if su == 0: mi = "1" + mi else: mi = str(su + 1) + mi print(mi, ma) else: print(-1, -1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP 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 IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER 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
a = map(int, input().split()) b = list(a) m = b[0] s = b[1] c = [] d = [] x = "" n = "" if s == 0 and m != 1 or s > 9 * m: print(-1, -1) else: for i in range(m): if s >= 9: c.append(9) s -= 9 else: c.append(s) s = 0 for i in range(m): x += str(c[i]) s = b[1] for i in range(m): if s > 9: d.append(9) s -= 9 elif s <= 9 and i == m - 1: d.append(s) elif s <= 9 and s > 1: d.append(s - 1) s = 1 elif s == 1 and i != m - 1: d.append(0) else: d.append(0) for i in range(m): n += str(d[m - 1 - i]) print(n, x)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR 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
import sys m, s = list(map(lambda x: int(x), input().split())) temp_s = s if m == 1 and s == 0: print(0, 0) sys.exit(0) def can(m, s): return s >= 0 and m * 9 >= s def can_max(m, s): return s >= 0 answer = "" for i in range(0, m): for d in range(0, 10): if (i > 0 or d > 0 or m == 1 and d == 0) and can(m - i - 1, temp_s - d): temp_s -= d answer += str(d) break answer_min = 0 if len(answer) != m or answer[0] == "0" or temp_s != 0: answer_min = -1 else: answer_min = answer answer = "" for i in range(0, m): for d in range(9, -1, -1): if can_max(m - i - 1, s - d): s -= d answer += str(d) break answer_max = 0 if len(answer) != m or answer[0] == "0" or s != 0: answer_max = -1 else: answer_max = answer print(answer_min, answer_max)
IMPORT ASSIGN VAR VAR FUNC_CALL 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 NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_DEF RETURN VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF RETURN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER 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 VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER 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 VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER 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, c = [int(i) for i in input().split()] if c / m > 9: print(-1, -1) elif c == 0 and m > 1: print(-1, -1) elif c == 0 and m == 1: print(0, 0) else: l = [(0) for i in range(m)] l[0] = 1 s = c s -= 1 j = m - 1 while s != 0 and j >= 0: if l[j] < 9 and s != 0: l[j] += 1 s -= 1 continue j -= 1 s1 = "" for i in l: s1 += str(i) l1 = [(0) for i in range(m)] k = 0 s = c while s != 0 and k < m: if l1[k] < 9 and s != 0: l1[k] += 1 s -= 1 continue k += 1 s2 = "" for i in l1: s2 += str(i) print(s1, s2)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR 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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR 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
n, m = list(map(int, input().split())) if m > n * 9: print(-1, -1) elif m == 0 and n > 1: print(-1, -1) elif n == 1 and m == 0: print(0, 0) else: m1 = m large = [0] * n for i in range(n): if m >= 9: m -= 9 large[i] = 9 else: large[i] = m m = 0 small = [0] * n m = m1 for i in range(n - 1, -1, -1): if m > 9: small[i] = 9 m -= 9 elif m > 1: if i == 0: small[i] = m else: small[i] = m - 1 small[0] = 1 break elif m == 1: small[0] = 1 break small = "".join(str(e) for e in small) large = "".join(str(e) for e in large) print(small, large)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP 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 ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING 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, sys.stdin.readline().split()) s2 = s if m == 1 and s == 0: max = min = 0 elif s > m * 9 or m != 1 and s == 0: max = min = -1 else: l = [str(0)] * m for i in range(m): if s > 9: l[i] = str(9) s -= 9 else: l[i] = str(s) s -= s max = "".join(l) l2 = [str(0)] * m for i in range(m - 1, -1, -1): if s2 > 9: l2[i] = str(9) s2 -= 9 elif i == 0: l2[0] = str(s2) min = "".join(l2) break else: l2[i] = str(s2 - 1) l2[0] = str(1) min = "".join(l2) break print(min, max)
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL 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
m, s = map(int, input().split()) if s > 9 * m: print(-1, -1) elif s == 0 and m > 1: print(-1, -1) elif s == 0 and m == 1: print(0, 0) else: maxn = [] for i in range(m): if s > 9: maxn.append(9) s = s - 9 elif s != 0: maxn.append(s) s = 0 else: maxn.append(0) minn = [] for i in range(m): minn.append(maxn[m - i - 1]) i = 0 while minn[i] == 0: i += 1 if i != 0: minn[0] = 1 minn[i] -= 1 minn = map(str, minn) maxn = map(str, maxn) print("".join(minn), "".join(maxn))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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 VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER 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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER 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
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 b == 0: print("0 0") elif b > a * 9 or b == 0: print("-1 -1") else: x = [0] * a x[0] += 1 c = b c -= 1 counter = -1 while c: add = min(c, 9) x[counter] += add c -= add counter -= 1 print("".join(map(str, x)), end=" ") x = [0] * a c = b counter = 0 while c: add = min(c, 9) x[counter] += add c -= add counter += 1 print("".join(map(str, x)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL 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 = list(map(int, input().split())) mini = [] maxi = [] for i in range(m): mini.append(0) maxi.append(9) mini[0] = 1 min_sum = 1 max_sum = 9 * m if m == 1 and s == 0: print("0 0") elif s < min_sum or s > max_sum: print("-1 -1") else: for i in range(m - 1, -1, -1): maxi[i] -= min(max_sum - s, 9) mini[i] += min(s - min_sum, 9) max_sum -= min(max_sum - s, 9) min_sum += min(s - min_sum, 9) ans1 = ans2 = "" for i, j in zip(maxi, mini): ans1 += str(i) ans2 += str(j) print(ans2, ans1)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR STRING FOR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL 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
d, s = list(map(int, input().split())) maxsum = 9 * d minsum = 1 flag = 1 maxl = list() minl = list() if d <= 0 or 9 * d < s or d > 1 and s == 0: flag = 0 elif d == 1: maxl.append(s) minl.append(s) else: nine = s // 9 for _ in range(nine): maxl.append(9) minl.append(9) if nine < d: maxl.append(s % 9) for _ in range(d - nine - 1): maxl.append(0) if s % 9 == 0: minl[nine - 1] = 8 for i in range(nine, d): if i == d - 1: minl.append(1) else: minl.append(0) elif nine == d - 1 and s % 9 != 0 and s > 9: minl.append(s % 9) else: minl.append(s % 9 - 1) for i in range(nine + 1, d): if i == d - 1: minl.append(1) else: minl.append(0) if flag != 0: for i in range(d): print(minl[d - i - 1], end="") print(" ", end="") for i in range(d): print(maxl[i], end="") else: print("-1 -1")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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
a, s = map(int, input().split()) if s == 0 and a > 1 or s > 9 * a: print(-1, -1) else: maxx = "" s1 = s for i in range(a): if s1 >= 9: s1 -= 9 maxx += "9" else: maxx += str(s1) s1 -= s1 minn = "" if s == 0: minn = 0 else: s -= 1 for i in range(a - 1, 0, -1): if s >= 9: s -= 9 minn = "9" + minn else: minn = str(s) + minn s -= s minn = str(1 + s) + minn print(minn, maxx)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR STRING VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER 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
n = 0 m, s = map(int, input().split()) if m * 9 - 8 >= s and m > 2 and s >= 10: s -= 10 m -= 2 while m * 9 - 9 >= s and m > 2 and s > 8: s -= 9 m -= 2 n += 1 if m * 9 - 9 < s: mini = "1" + "0" * n + str(s - m * 9 + 9) + (m + n) * "9" maxi = "9" * (m + n) + str(s - m * 9 + 10) + (n + 1) * "0" elif m == 2: mini = "1" + "0" * (n + 1) + str(n) + (n + 1) * "9" maxi = "9" + str(n + 1) + "0" * (n + 2) else: mini = "1" + "0" * (n + m - 1) + str(s) + (n + 1) * "9" maxi = "9" * (n + 1) + str(s + 1) + "0" * (n + m) elif m * 9 < s or s < 1 and m != 1: maxi = "-1" mini = "-1" elif m == 1: maxi = mini = s elif s >= 10: maxi = "9" * (m - 1) + str(s - 9 * m + 9) mini = maxi[::-1] elif s < 10: maxi = str(s) + "0" * (m - 1) mini = "1" + "0" * (m - 2) + str(s - 1) print(mini, maxi, sep=" ")
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER WHILE BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER 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 VAR BIN_OP BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER 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
m, s = map(int, input().split()) num_min = [1] num_max = [9] for i in range(m - 1): num_min.append(0) num_max.append(9) if s > 0: i = 0 while i < m: if sum(num_min) < s: while sum(num_min) < s and i < m: if s - sum(num_min) >= 9: num_min[-1 - i] = 9 i += 1 else: num_min[-1 - i] = num_min[-1 - i] + (s - sum(num_min)) i += 1 elif sum(num_min) == s: break i = 0 while i < m: if sum(num_max) > s: while sum(num_max) > s and i < m: if abs(s - sum(num_max)) >= 9: num_max[-1 - i] = 0 i += 1 else: num_max[-1 - i] = num_max[-1 - i] - abs(s - sum(num_max)) i += 1 elif sum(num_max) == s: break if i < m: i += 1 if s - sum(num_min) == 0 and s - sum(num_max) == 0: print(*num_min, " ", *num_max, sep="") elif s == 0 and m == 1: print("0 0") else: print("-1 -1")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR STRING IF VAR NUMBER 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 = [int(i) for i in input().split()] if s <= 0 or s > 9 * m: if s == 0 and m == 1: print(0, 0) else: print(-1, -1) else: if s % 9 != 0: rem = s // 9 positions_available = m - rem if positions_available >= 2: tot_remain = s % 9 s = "1" + "0" * (positions_available - 2) + str(tot_remain - 1) + "9" * rem if tot_remain == 1: s1 = "9" * rem + "1" + "0" * (positions_available - 1) else: s1 = "9" * rem + str(tot_remain) + "0" * (positions_available - 1) else: tot_remain = s % 9 s = str(tot_remain) + "9" * rem s1 = "9" * rem + str(tot_remain) else: rem = s // 9 rem -= 1 positions_available = m - rem if positions_available >= 2: tot_remain = 9 s = "1" + "0" * (positions_available - 2) + str(tot_remain - 1) + "9" * rem if tot_remain == 1: s1 = "9" * rem + "1" + "0" * (positions_available - 2) else: s1 = "9" * rem + str(tot_remain) + "0" * (positions_available - 1) else: tot_remain = 9 s = str(tot_remain) + "9" * rem s1 = "9" * rem + str(tot_remain) a = int(s) b = int(s1) print(a, b)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN 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 = (int(i) for i in input().split()) if m > 1 and s < 1 or s > 9 * m: print("-1 -1") exit() else: k = s ns = "" for i in range(m - 1, -1, -1): n = max(0, k - 9 * i) if n == 0 and i == m - 1 and k != 0: n = 1 ns += str(n) k -= n k = s nd = "" for i in range(m - 1, -1, -1): n = min(9, k) nd += str(n) k -= n print(ns, end=" ") print(nd)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING 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 STRING 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
def Biggest(m, s): ans = 0 if m == 1 and s == 0: return 0 for i in range(m): ans = ans * 10 + min(9, s) if s > 9: s -= 9 else: s = 0 if ans == 0 or s != 0: return -1 else: return ans def Smallest(m, s): ans = "" if m == 1 and s == 0: return "0" if s == 0: return -1 for i in range(m): if s > 9: ans = "9" + ans s -= 9 elif i != m - 1: if s != 0: ans = str(s - 1) + ans s = 0 else: ans = "0" + ans elif i == m - 1: if s == 0: s = 1 if s > 9: return -1 ans = str(s) + ans return ans return -1 m, s = input().split() m, s = int(m), int(s) print(str(Smallest(m, s)) + " " + str(Biggest(m, s)))
FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN VAR FUNC_DEF ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP STRING VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR 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
m, s = map(int, input().split()) keeps = s keepm = m if s > 9 * m: print("-1 -1") elif m == 1 and s < 10: print(s, s) elif m == 1 and s > 9: print("-1 -1") elif m > 1 and s == 0: print("-1 -1") elif m > 1 and s < 10: maxnum = s * 10 ** (m - 1) minnum = 1 * 10 ** (m - 1) + (s - 1) print(minnum, maxnum) elif m > 1 and s >= 10: geshu = s // 9 if s % 9 == 0: maxnum = int("9" * geshu) * 10 ** (m - geshu) else: first = int("9" * geshu) * 10 + s % 9 maxnum = first * 10 ** (m - (geshu + 1)) if s % 9 == 0: minnum = 1 * 10 ** (m - 1) + int("8" + "9" * (geshu - 1)) elif m == geshu + 1: minnum = s % 9 * 10 ** (m - 1) + int("9" * geshu) else: minnum = 1 * 10 ** (m - 1) + (s % 9 - 1) * 10**geshu + int("9" * geshu) print(minnum, maxnum)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP STRING VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP STRING VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR FUNC_CALL 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
def solve(m, s): if (m, s) == (1, 0): ret = "0 0" elif s > 9 * m or s == 0: ret = "-1 -1" else: mxs = [1] + [0] * (m - 1) mns = [1] + [0] * (m - 1) i, j = -1, 0 while s > 1: if mns[i] >= 9: i -= 1 if mxs[j] >= 9: j += 1 mns[i] += 1 mxs[j] += 1 s -= 1 ret = "".join(map(str, mns + [" "] + mxs)) return ret m, s = map(int, input().split()) print(solve(m, s))
FUNC_DEF IF VAR VAR NUMBER NUMBER ASSIGN VAR STRING IF VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR BIN_OP BIN_OP VAR LIST STRING VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL 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
line = input().split() m = int(line[0]) S = int(line[1]) if S == m * 9: print("9" * m + " " + "9" * m) elif int(line[1]) <= 0 or int(line[1]) > 9 * m: if m == 1 and S == 0: print("0 0") else: print("-1 -1") elif m == 1: print("{} {}".format(S, S)) elif S <= 9: x = "{}".format(S) + "0" * (m - 1) y = "1" + "0" * (m - 2) + "{}".format(S - 1) print("{} {}".format(y, x)) else: xx = int(S / 9) yu = S % 9 x = "9" * xx + "%.d" % yu + "0" * (m - xx - 1) yu = S % 9 if yu >= 1 and xx == m - 1: y = "%.d" % yu + "9" * xx else: y = "1" + "0" * (m - xx - 2) + "%.d" % (yu - 1) + "9" * xx if yu == 0: y = "1" + "0" * (m - xx - 1) + "8" + "9" * (xx - 1) print("{} {}".format(y, x))
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR STRING BIN_OP STRING VAR IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL STRING VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR IF 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 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
n, k = map(int, input().split()) if n == 1 and k == 0: print(0, 0) elif k > n * 9 or n < 1 or k < 1: print("-1 -1") else: a = k // 9 b = k % 9 biggest = str(9) * a + str(b) + str(0) * (n - a - 1) smallest = str(1) + str(0) * (n - a - 2) + str(b - 1) + str(9) * a if b == 0: biggest = str(9) * a + str(0) * (n - a) smallest = str(1) + str(0) * (n - a - 1) + str(8) + str(9) * (a - 1) if biggest.count("0") == 0: smallest = biggest[::-1] print(smallest, biggest)
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 VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR 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
def findSmallest(m, s): if s == 0: if m == 1: print("0", end=" ") else: print("-1", end=" ") return if s > 9 * m: print("-1", end=" ") return res = [(0) for i in range(m + 1)] s -= 1 for i in range(m - 1, 0, -1): if s > 9: res[i] = 9 s -= 9 else: res[i] = s s = 0 res[0] = s + 1 for i in range(m): print(res[i], end="") print(end=" ") def findLargest(m, s): if s == 0: if m == 1: print("0") else: print("-1") return if s > 9 * m: print("-1") return res = [0] * m for i in range(0, m): if s >= 9: res[i] = 9 s = s - 9 else: res[i] = s s = 0 for i in range(0, m): print(res[i], end="") m, s = map(int, input().split()) findSmallest(m, s) findLargest(m, s)
FUNC_DEF IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING RETURN IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING STRING RETURN ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING FUNC_DEF IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR 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
n, m = map(int, input().split()) s = s1 = "" c = m - 1 d = n - 1 while d > 0: if c >= 9: s = "9" + s d -= 1 c -= 9 else: s = str(c) + s d -= 1 c -= c if c == 0: s = "1" + s else: s = str(c + 1) + s c = m d = n while n > 0: if c >= 9: s1 += "9" c -= 9 n -= 1 else: s1 += str(c) c -= c n -= 1 if d * 9 < m or d != 1 and m == 0: print("-1", "-1") else: print(s, s1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING 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
lnums = input() nums = [] nums = lnums.split() ln = int(nums[0]) sum = int(nums[1]) flag = True if sum > 9 * ln: flag = False elif sum == 0: if ln == 1: min = sum max = sum else: flag = False elif sum < 10: if ln == 1: min = sum max = sum else: max = int(str(sum) + (ln - 1) * "0") min = int("1" + (ln - 2) * "0" + str(sum - 1)) else: a = sum // 9 b = sum % 9 max = int(a * "9" + str(b) + (ln - a - 1) * "0") if b != 0: max = int(a * "9" + str(b) + (ln - a - 1) * "0") if ln == a + 1: min = int(str(b) + a * "9") else: min = int("1" + (ln - a - 2) * "0" + str(b - 1) + a * "9") else: max = int(a * "9" + (ln - a) * "0") if ln == a + 1: min = int("90" + (a - 1) * "9") elif ln == a: min = int(a * "9") else: min = int("1" + (ln - a - 1) * "0" + "8" + (a - 1) * "9") if flag == False: print(-1, -1) else: print(min, max)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING BIN_OP BIN_OP VAR VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING STRING BIN_OP BIN_OP VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL 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 = list(map(int, input().split())) if M == 1 and S == 0: print("0 0") exit(0) if M > 1 and S == 0 or S > 9 * M: print(-1, end=" ") else: s = S res = "" for i in range(M - 1): next = min(9, s - 1) s -= next res = str(next) + res res = str(max(s, 1)) + res print(res, end=" ") if M > 1 and S == 0 or S > 9 * M: print(-1) else: s = S for i in range(M): next = min(9, s) s -= next print(next, end="") print()
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 NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR 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
n, sumi = [i for i in list(map(int, input().split()))] sdf = [(9) for i in range(n)] if sumi == 0 and n != 1: print(str(-1) + " " + str(-1)) elif sumi == 0 and n == 1: print(str(0) + " " + str(0)) elif sumi > n * 9: print(str(-1) + " " + str(-1)) else: i = 0 curr = 9 * n while sumi < curr: if i == 0: sdf[i] -= min(curr - sumi, 8) curr -= min(curr - sumi, 8) else: sdf[i] -= min(curr - sumi, 9) curr -= min(curr - sumi, 9) i += 1 for i in range(n): print(sdf[i], end="") print(end=" ") i = n - 1 curr = 9 * n sdf = [(9) for i in range(n)] while sumi < curr: if i == 0: sdf[i] -= min(curr - sumi, 8) curr -= min(curr - sumi, 8) else: sdf[i] -= min(curr - sumi, 9) curr -= min(curr - sumi, 9) i -= 1 for i in range(n): print(sdf[i], end="") print()
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR IF VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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
a = [int(i) for i in input().split()] l = a[0] s = a[1] if l == 1 and s < 10: x = str(s) y = str(s) elif s == 0 or s > 9 * l: x = "-1" y = "-1" else: m = int(s / 9) n = s % 9 if l == m: x = m * "9" y = m * "9" if l == m + 1: if n == 0: x = "18" + (l - 2) * "9" y = (l - 1) * "9" + "0" else: y = m * "9" + str(n) x = str(n) + m * "9" if l > m + 1: if n == 0: x = "1" + (l - m - 1) * "0" + "8" + (m - 1) * "9" y = m * "9" + (l - m) * "0" elif m != 0 and l == m + 2: x = str(n) + (l - m - 1) * "0" + m * "9" y = m * "9" + str(n) + (l - m - 1) * "0" elif m != 0 and l > m + 2: x = "1" + (l - m - 2) * "0" + str(n - 1) + m * "9" y = m * "9" + str(n) + (l - m - 1) * "0" elif m == 0: x = "1" + (l - 2) * "0" + str(n - 1) y = m * "9" + str(n) + (l - m - 1) * "0" print(x + " " + y)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER STRING STRING ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR STRING IF VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING STRING BIN_OP BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR STRING BIN_OP BIN_OP VAR VAR STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR