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 | n, s = map(int, input().split())
def get_max(n, s):
s_nine = s // 9
s_r = s % 9
if s_r != 0:
s_n = "9" * s_nine + str(s_r)
else:
s_n = "9" * s_nine
s_l = n - len(s_n)
return s_n + "0" * s_l
def get_min(n, s):
s_nine = (s - 1) // 9
s_r = (s - 1) % 9
s_n = "9" * s_nine + str(s_r)
s_l = n - len(s_n)
k = s_n + "0" * s_l
k_r = k[::-1]
p = str(int(k_r[0]) + 1) + k_r[1:]
return p
if s > 9 * n:
print("-1 -1")
elif s == 0 and n > 1:
print("-1 -1")
elif s == 0 and n == 1:
print("0 0")
else:
print("{} {}".format(get_min(n, s), get_max(n, s))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR BIN_OP STRING VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER RETURN VAR 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 EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
sr = ""
if s == 0 and m > 1:
print("-1 -1")
exit()
if s == 0 and m == 1:
print("0 0")
exit()
while s >= 9:
s -= 9
sr += "9"
if s == 8:
s -= 8
sr += "8"
if s == 7:
s -= 7
sr += "7"
if s == 6:
s -= 6
sr += "6"
if s == 5:
s -= 5
sr += "5"
if s == 4:
s -= 4
sr += "4"
if s == 3:
s -= 3
sr += "3"
if s == 2:
s -= 2
sr += "2"
if s == 1:
s -= 1
sr += "1"
k = len(sr)
if k > m:
print("-1 -1")
exit()
elif k == m:
print(sr[::-1], sr)
exit()
zeroes = 0
while zeroes < len(sr) and sr[zeroes] != "0":
zeroes += 1
temp = sr[zeroes - 1 :: -1]
digit = int(temp[0]) - 1
print("1" + "0" * (m - len(temp) - 1) + str(digit) + temp[1:], end=" ")
sr += "0" * (m - k)
print(sr) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER VAR STRING IF VAR NUMBER VAR NUMBER VAR STRING IF VAR NUMBER VAR NUMBER VAR STRING IF VAR NUMBER VAR NUMBER VAR STRING IF VAR NUMBER VAR NUMBER VAR STRING IF VAR NUMBER VAR NUMBER VAR STRING IF VAR NUMBER VAR NUMBER VAR STRING IF VAR NUMBER VAR NUMBER VAR STRING IF VAR NUMBER VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER STRING VAR BIN_OP STRING 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())
temp = s
large = []
i = 0
while i < m:
if s > 9:
s -= 9
large.append("9")
else:
large.append(str(s))
s -= s
i += 1
large = "".join(large)
if large[0] == "0" and m > 1 or s > 0:
large = -1
small = []
i = m - 1
s = temp
while i > 0:
if s > 9:
small.append("9")
s -= 9
elif s > 1:
small.append(str(s - 1))
s = 1
else:
small.append("0")
i -= 1
if s < 10:
small.append(str(s))
s = 0
small = small[::-1]
small = "".join(small)
if m > 1 and small[0] == "0" or s > 0:
small = -1
print(small, large) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR IF VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR IF VAR NUMBER VAR NUMBER STRING 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
n, s = map(int, input().split())
max_n = [0] * n
min_n = [0] * n
min_n[0] = 1
if s is 0 and n > 1:
print(-1, -1)
sys.exit(0)
if s is 0 and n is 1:
print(0, 0)
sys.exit(0)
if s > 9 * n:
print(-1, -1)
sys.exit(0)
s1 = s - 1
for i in range(n):
if s >= 9:
max_n[i] = 9
s = s - 9
elif s < 9 and s is not 0:
max_n[i] = s
s = 0
for i in range(n):
if s1 >= 9:
min_n[n - i - 1] = 9
s1 = s1 - 9
elif s1 < 9 and s1 > 0:
if n - i - 1 is 0:
min_n[n - i - 1] = s1 + 1
else:
min_n[n - i - 1] = s1
s1 = 0
max_n = map(str, max_n)
max_n = "".join(max_n)
min_n = map(str, min_n)
min_n = "".join(min_n)
print(min_n, max_n) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN 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())
maxi = ""
mini = ""
if s == 0:
if m == 1:
print("0 0")
else:
print("-1 -1")
else:
for i in range(m):
k = min(9, s)
maxi += str(k)
s -= k
if s > 0:
print("-1 -1")
else:
mini = maxi[::-1]
while mini[0] == "0":
mini = list(maxi[::-1])
mini = mini[1:]
for i in range(len(mini)):
if int(mini[i]) > 0:
u = int(mini[i]) - 1
mini[i] = u
break
d = str(1) + "".join(map(str, mini))
mini = d
print(mini, end=" ")
print(maxi) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER WHILE VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN 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 | x, y = map(int, input().split())
def big(x, y):
if y >= 9 and y <= x * 9:
a = [9] * (y // 9)
c1 = y - sum(a)
if c1 != 0:
a.append(c1)
if len(a) != x:
a1 = [0] * (x - len(a))
a = a + a1
return "".join(str(i) for i in a)
elif 0 < y < 9:
a = [y]
if len(a) != x:
a1 = [0] * (x - len(a))
a = a + a1
return "".join(str(i) for i in a)
elif y == 0 and x == 1:
return "0"
else:
return "-1"
def small(x, y):
if y >= 9 and y <= x * 9:
a = [9] * (y // 9)
c1 = y - sum(a)
if c1 != 0:
a.insert(0, c1)
if len(a) != x:
c2 = a.pop(0)
if len(a) != 0:
a1 = [0] * (x - (len(a) + 2))
else:
a1 = [0] * (x - 2)
if c2 - 1 != 0:
a1.append(c2 - 1)
else:
a1.append(0)
a1.insert(0, 1)
a = a1 + a
return "".join(str(i) for i in a)
elif 0 < y < 9:
if x != 1:
a = [0] * (x - 2)
a.insert(0, 1)
a.append(y - 1)
return "".join(str(i) for i in a)
else:
return y
elif y == 0 and x == 1:
return "0"
else:
return "-1"
print(small(x, y), big(x, y)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR IF NUMBER VAR NUMBER ASSIGN VAR LIST VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER RETURN STRING RETURN STRING FUNC_DEF IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR IF NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR RETURN VAR IF VAR NUMBER VAR NUMBER RETURN STRING RETURN 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 | import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def rinput():
return map(int, sys.stdin.readline().strip().split())
def get_list():
return list(map(int, sys.stdin.readline().strip().split()))
def sumofdigits(n):
return sum([int(i) for i in str(n)])
m, s = rinput()
if s == 0 and m == 1:
print(0, 0)
elif s == 0 or s > m * 9:
print(-1, -1)
else:
cnt_9 = s // 9
b = s - cnt_9 * 9
if b != 0:
high = "9" * cnt_9 + str(b) + "0" * (m - cnt_9 - 1)
temp = ["9"] * cnt_9 + [str(b)] + ["0"] * (m - cnt_9 - 1)
temp.reverse()
if temp[0] == "0":
temp[0] = "1"
for i in range(1, len(temp)):
if temp[i] > "0":
temp[i] = str(int(temp[i]) - 1)
break
low = "".join(temp)
else:
high = "9" * cnt_9 + "0" * (m - cnt_9)
temp = ["9"] * cnt_9 + ["0"] * (m - cnt_9)
temp.reverse()
if temp[0] == "0":
temp[0] = "1"
for i in range(1, len(temp)):
if temp[i] > "0":
temp[i] = str(int(temp[i]) - 1)
break
low = "".join(temp)
print(int(low), int(high)) | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST STRING VAR LIST FUNC_CALL VAR VAR BIN_OP LIST STRING BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST STRING VAR BIN_OP LIST STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def func():
tokens = input().split()
length = int(tokens[0])
sum = int(tokens[1])
sum1 = sum
if sum == 0 and length == 1:
print("0 0")
return
start = []
for i in range(length):
start.append(0)
sum = sum - 1
digit = len(start) - 1
while 1:
if digit < 0:
if sum > 0:
print("-1 -1")
return
if sum > 9:
sum = sum - 9
start[digit] = 9
digit -= 1
elif sum >= 0:
start[digit] = sum
break
elif sum < 0:
print("-1 -1")
return
if start[0] < 9:
start[0] += 1
else:
print("-1 -1")
return
reverse = []
for i in range(length):
reverse.append(0)
dig = 0
while 1:
if sum1 > 9:
sum1 = sum1 - 9
reverse[dig] = 9
dig += 1
elif sum1 >= 0:
reverse[dig] = sum1
break
print("".join(str(x) for x in start) + " " + "".join(str(y) for y in reverse))
func() | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR 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, b = [int(i) for i in input().split()]
if a * 9 < b or b < 0:
print("-1 -1")
elif a == 1 and b == 0:
print("0", "0")
elif a > 1 and b == 0:
print("-1 -1")
else:
da = b // 9
e = b % 9
ma = ""
mi = ""
if e == 0:
da = da - 1
e = 9
i = 0
while i < da:
ma = ma + str(9)
i += 1
mi = mi + str(9)
ma = ma + str(e)
i += 1
while i < a:
ma = ma + str(0)
i += 1
if da + 1 == a:
mi = str(e) + mi
else:
mi = str(1) + "0" * (a - da - 2) + str(e - 1) + mi
print(int(mi), int(ma)) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def process(cnt, sm):
if sm == 0:
if cnt == 1:
return 0, 0
return -1, -1
if sm > cnt * 9:
return -1, -1
revno, smol = [0] * cnt, [0] * cnt
t = sm
smol[-1] = 1
t -= 1
i = 0
while t > 0:
try:
if smol[i] + t > 9:
smol[i] += 9 - smol[i]
t -= smol[i]
else:
smol[i] += t
t = 0
i += 1
except:
return -1, -1
smol.reverse()
i = 0
t = sm
while t > 0:
try:
if t > 9:
revno[i] += 9
t -= 9
else:
revno[i] += t
t = 0
i += 1
except:
return -1, -1
return "".join(map(str, smol)), "".join(map(str, revno))
cnt, sm = map(int, input().split())
print(*process(cnt, sm)) | FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER NUMBER RETURN NUMBER NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR 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 | m, s = map(int, input().split())
if s == 0 and m == 1:
print("0 0")
exit()
if s > 9 * m or s < 1:
print("-1 -1")
exit()
ans = ""
for _ in range(0, m):
x = min(9, s)
ans += str(x)
s -= x
ans1 = list(ans)
ans1.reverse()
for x in range(0, m):
if ans1[x] != "0":
ans1[0] = str(int(ans1[0]) + 1)
ans1[x] = str(int(ans1[x]) - 1)
break
print("".join(ans1) + " " + ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING 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())
sn = ""
ln = ""
a = s
t = 0
k = s
for i in range(1, m):
if s >= 10:
sn = sn + str(9)
ln = str(9) + ln
s = s - 9
k = s
elif t != 1:
sn = str(s - 1) + sn
ln = ln + str(k)
k = 0
t = 1
s = 1
else:
sn = "0" + sn
ln = ln + "0"
sn = str(s) + sn
ln = ln + str(k)
if a == 0:
sn = "0"
ln = "0"
if len(sn) != m:
print(-1, end=" ")
else:
print(sn, end=" ")
if len(ln) != m:
print(-1, end=" ")
else:
print(ln, end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = str(input()).split()
m = int(m)
s = int(s)
if m > 1 and s == 0 or s > 9 * m:
print("-1 -1")
elif m == 1:
print(str(s) + " " + str(s))
else:
num_9 = s // 9
miss = s - 9 * num_9
if miss > 0:
count = m - num_9 - 1
if num_9 > 0:
max_v = "9" * num_9 + str(miss) + "0" * count
else:
max_v = str(miss) + "0" * count
if count > 0:
min_v = "1" + "0" * (count - 1) + str(miss - 1) + "9" * num_9
else:
min_v = str(miss) + "9" * num_9
else:
count = m - num_9
max_v = "9" * num_9 + "0" * count
if count > 0:
min_v = "1" + "0" * (count - 1) + "8" + "9" * (num_9 - 1)
else:
min_v = max_v
print(str(min_v) + " " + str(max_v)) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR IF 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 ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(i) for i in input().split()]
if m == 1 and s <= 9:
print(s, s)
elif m == 1:
print(-1, -1)
elif s >= 1 and s <= m * 9:
min_val = [0] * m
max_val = [0] * m
min_val[0] = 1
s_ = s - 1
for i in range(1, m):
if s_ <= 0:
break
else:
min_val[m - i] = min(9, s_)
s_ -= min_val[m - i]
if s_ >= 1:
min_val[0] = s_ + 1
s_ = s
for i in range(m):
if s_ <= 0:
break
else:
max_val[i] = min(9, s_)
s_ -= max_val[i]
print(
int("".join([str(j) for j in min_val])), int("".join([str(j) for j in max_val]))
)
else:
print(-1, -1) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR 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 | def check(s, m):
if m == 1 and s == 0:
return 0, 0
elif s > m * 9 or s == 0:
return -1, -1
else:
Low = 10 ** (m - 1)
for i in range(s - 1):
Low += 10 ** (i // 9)
High = 0
for i in range(s):
High += 10 ** (m - 1 - i // 9)
return Low, High
m, s = map(int, input().split())
print(*check(s, m)) | FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR 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 | n, m = map(int, input().split())
if m == 0:
if n == 1:
print(0, 0)
else:
print(-1, -1)
else:
mx = ""
x = m
for i in range(n):
if x >= 9:
mx += "9"
x -= 9
else:
mx += str(x)
x = 0
if x > 0:
mx = -1
mi = ""
x = m - 1
for i in range(n - 1, -1, -1):
if x >= 9:
mi += "9"
x -= 9
else:
mi += str(x)
x = 0
mi = list(mi[::-1])
if mi[0] != "9":
mi[0] = str(int(mi[0]) + 1)
else:
mi = [-1]
if x > 0:
mi = [-1]
print("".join(str(e) for e in mi), mx) | 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 FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL 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 | from sys import stdin, stdout
def main():
def can(m, s):
return s >= 0 and s <= 9 * m
def f(m, s):
_sum = s
minn = 0
for i in range(m):
for d in range(0, 10):
if (i > 0 or d > 0 or m == 1 and d == 0) and can(m - i - 1, _sum - d):
minn += d
minn *= 10
_sum -= d
break
maxx = 0
_sum = s
for i in range(m):
for d in range(9, -1, -1):
if (i > 0 or d > 0 or m == 1 and d == 0) and can(m - i - 1, _sum - d):
maxx += d
maxx *= 10
_sum -= d
break
if len(str(minn // 10)) != m or len(str(maxx // 10)) != m:
return "-1 -1"
if sum(list(map(int, list(str(minn // 10))))) != s:
return "-1 -1"
if sum(list(map(int, list(str(maxx // 10))))) != s:
return "-1 -1"
return "{} {}".format(minn // 10, maxx // 10)
m, s = map(int, stdin.readline().strip().split(" "))
print(f(m, s))
main() | FUNC_DEF FUNC_DEF RETURN VAR NUMBER VAR BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR 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 NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR 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 VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN STRING IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN STRING IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN STRING RETURN FUNC_CALL STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda: list(map(int, cin().split()))
m, s = mp()
rem = s % 9
maxi = "9" * (s // 9)
if rem > 0:
maxi += str(rem)
if len(maxi) > m or len(maxi) == 0 and m > 1:
cout("-1 -1")
exit(0)
maxi += "0" * (m - len(maxi))
mini = maxi[::-1]
if len(maxi) == 1:
cout(mini + " " + maxi)
else:
k = 0
for i in range(len(mini)):
if mini[i] == "0" and not k:
k = 1
cout("1")
elif "0" < mini[i] <= "9" and k == 1:
cout(str(int(mini[i]) - 1))
k = 2
else:
cout(mini[i])
cout(" " + maxi) | ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR 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 | m, s = map(int, input().split())
t = s
a, b = [], []
if s > 0 and s <= m * 9:
for i in range(m):
if s - 9 > 0:
p = 9
s = s - 9
else:
p = s
s = 0
a.append(str(p))
max = "".join(a)
a.sort()
for i in a:
b.append(int(i))
if b[0] == 0:
b[0] = 1
for i in range(1, len(b)):
if b[i] != 0:
b[i] -= 1
break
min = ""
for i in b:
min += str(i)
print(int(min), int(max))
elif m == 1 and s == 0:
print(0, 0)
else:
print(-1, -1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR LIST LIST IF VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, n = [int(x) for x in input().strip().split()]
if n == 0 and m > 1:
res = "-1 -1"
print(res)
elif n == 0 and m == 1:
res = "0 0"
print(res)
else:
result = [None for i in range(m)]
s_result = [None for i in range(m)]
p = n
for i in range(m):
if n >= 9:
result[i] = 9
n -= 9
else:
result[i] = n
n -= n
if n != 0:
res = "-1 -1"
print(res)
else:
smallest = sorted(result)
for x in smallest:
if x > 0:
nz = x
break
ind = smallest.index(nz)
new_smallest = [None for i in range(m)]
if ind > 0:
new_smallest[0] = 1
for i in range(1, m):
new_smallest[i] = smallest[i]
new_smallest[ind] -= 1
else:
new_smallest = [x for x in smallest]
s_a = "".join(str(x) for x in new_smallest)
l_a = "".join(str(x) for x in result)
print(s_a, l_a) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR 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 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())
strings = []
count = s
n = 0
if s == 0 and m > 1 or s > m * 9:
print("-1 -1")
elif s == 0 and m == 1:
print("0 0")
else:
for i in range(m):
strings.append(0)
while count > 0:
if count >= 9:
strings[n] = 9
count -= 9
else:
strings[n] = count
count = 0
n += 1
string = [str(i) for i in strings]
max_num = int("".join(string))
nstrings = []
for i in range(m):
nstrings.append(0)
n = 0
count = s
while count > 0:
n -= 1
if count >= 9:
nstrings[n] = 9
count -= 9
else:
nstrings[n] = count
count = 0
if nstrings[0] == 0:
nstrings[0] = 1
nstrings[n] -= 1
nstring = [str(i) for i in nstrings]
min_num = int("".join(nstring))
print(min_num, max_num) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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 | m, s = [int(i) for i in input().split()]
if s > 9 * m or s == 0 and m > 1:
max = min = -1
else:
s_max = s_min = s
max_lst = []
min_lst = []
while s_max >= 9:
max_lst.append("9")
s_max -= 9
if s_max > 0:
max_lst.append(str(s_max))
max_lst.extend((m - len(max_lst)) * ["0"])
while s_min >= 10:
min_lst.append("9")
s_min -= 9
t = m - len(min_lst)
if t == 1:
min_lst.append(str(s_min))
elif t == 0:
pass
else:
min_lst.extend([str(s_min - 1)] + ["0"] * (t - 2) + ["1"])
min_lst.reverse()
max = "".join(max_lst)
min = "".join(min_lst)
print(min, max) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR LIST STRING WHILE VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP LIST FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP LIST STRING BIN_OP VAR NUMBER LIST STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING 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 | n, m = map(int, input().split())
a = m
z = [(0) for i in range(n)]
x = [(0) for i in range(n)]
if n == 1 and m == 0:
print(0, 0)
exit()
if m == 0:
print(-1, -1)
exit()
if m > n * 9:
print(-1, -1)
exit()
for i in range(n):
z[i] += min(9, m)
m -= z[i]
if m == 0:
break
m = a
for i in range(n - 1, -1, -1):
x[i] += min(9, m)
m -= x[i]
if m == 0:
x[i] -= 1
x[0] += 1
break
print(*x, sep="", end=" ")
print(*z, sep="") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
n = m
s1 = s
if s == 0 and m > 1 or s > 9 * m:
print(-1, -1)
else:
max = [0] * m
min = [0] * m
i = 0
while s:
if s > 9:
max[i] = 9
s -= 9
i += 1
else:
max[i] = s
s = 0
while s1:
if s1 > 9:
min[m - 1] = 9
m -= 1
s1 -= 9
elif m - 1 == 0:
min[0] = s1
s1 = 0
else:
min[m - 1] = s1 - 1
min[0] = 1
s1 = 0
for j in range(n):
print(min[j], end="")
print(end=" ")
for j in range(n):
print(max[j], end="") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN 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 | m, s = map(int, input().split())
if (s == 0 or s > 9 * m) and not (m == 1 and s == 0):
print(-1, -1)
elif m == 1 and s == 0:
print(0, 0)
else:
r = s % 9
q = int((s - r) / 9)
if q == m:
keys = 0
else:
keys = 1
ma = [9] * q + [r] * keys + [0] * (m - q - 1)
ma = str(ma)
ma = ma.replace(", ", "")
ma = ma.replace("[", "")
ma = ma.replace("]", "")
ma = int(ma)
if s - 9 * (m - 1) > 1:
mi = [s - 9 * (m - 1)] + [9] * (m - 1)
mi = str(mi)
mi = mi.replace(", ", "")
mi = mi.replace("[", "")
mi = mi.replace("]", "")
mi = int(mi)
else:
r = (s - 1) % 9
q = int((s - 1 - r) / 9)
if q == m - 1:
keys = 0
else:
keys = 1
mi = [1] + [0] * (m - 2 - q) + [r] * keys + [9] * q
mi = str(mi)
mi = mi.replace(", ", "")
mi = mi.replace("[", "")
mi = mi.replace("]", "")
mi = int(mi)
print(mi, ma) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER 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 VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST VAR VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP LIST VAR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING 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 = map(int, input().split())
if s == 1:
res = "1" + "0" * (m - 1)
print(res, res)
exit(0)
arr = [0] * m
if 1 > s:
if m == 1:
print(0, 0)
else:
print(-1, -1)
exit(0)
itr = 0
while s > 0 and itr < m:
choice = min(9, s)
arr[itr] += choice
s -= choice
itr += 1
if s > 0:
print(-1, -1)
exit(0)
for i in range(m - 1):
for j in range(i + 1, m):
if arr[i] == 9:
break
if arr[j] >= 0:
needed = 9 - arr[i]
extracted = min(needed, arr[j])
arr[i] += extracted
arr[j] -= extracted
res_max = "".join(map(str, arr))
if arr[-1] == 0:
for i in range(m - 2, -1, -1):
if arr[i] > 0:
arr[i] -= 1
arr[-1] = 1
break
res_min = "".join(map(str, arr[::-1]))
print(res_min, res_max) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL 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 | m, i_s = map(int, input().split())
min_num = [1] + [0] * (m - 1)
s = i_s - 1
for i in range(len(min_num) - 1, -1, -1):
val_inc = min(9 - min_num[i], s)
min_num[i] += val_inc
s -= val_inc
if s > 0 or sum(min_num) != i_s or any(map(lambda x: x < 0, min_num)):
print(-1, -1)
else:
max_num = [1] + [0] * (m - 1)
s = i_s - 1
for i in range(len(max_num)):
val_inc = min(9 - max_num[i], s)
max_num[i] += val_inc
s -= val_inc
print(*min_num, " ", *max_num, sep="") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | arr = [int(i) for i in filter(None, input().split(" "))]
k = arr[0]
sum = arr[1]
num = ""
if sum == 0 or sum > k * 9:
if k == 1 and sum == 0:
print(0, 0)
else:
print("-1 -1")
else:
while sum >= 9:
num += "9"
sum -= 9
k -= 1
if k >= 1:
num += str(sum)
k -= 1
while k >= 1:
num += "0"
k -= 1
ans = []
min_num = num[::-1]
if int(min_num[0]) > 0:
print(min_num, num)
else:
for i in min_num:
ans.append(int(i))
for i in range(len(ans)):
if ans[i] > 0:
ans[i] -= 1
ans[0] = 1
break
min_num = ""
for i in ans:
min_num += str(i)
print(min_num, num) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NONE FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING WHILE VAR NUMBER VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR NUMBER VAR STRING VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER 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 | import time
I = lambda: list(map(int, input().split(" ")))
N, s = I()
mem = {}
def maxDigits(n, s):
if (n, s) in mem:
return mem[n, s]
elif n == 1 and s <= 9 and s > 0 or n == N == 1 and s <= 9:
return str(s), True
elif n < N and s == 0:
return "0" * n, True
elif n == 1 and s > 9 or n == N and s == 0 or n <= 0:
return "", False
else:
if n == N:
start = 0
else:
start = -1
for j in range(9, start, -1):
if s - j >= 0:
t = maxDigits(n - 1, s - j)
if t[1] == True:
mem[n, s] = str(j) + t[0], True
return str(j) + t[0], True
mem[n, s] = "", False
return "", False
mem1 = {}
def minDigits(n, s):
if (n, s) in mem1:
return mem1[n, s]
elif n == 1 and s <= 9 and s > 0 or n == N == 1 and s <= 9:
return str(s), True
elif n < N and s == 0:
return "0" * n, True
elif n == 1 and s > 9 or n == N and s == 0 or n <= 0:
return "", False
else:
if n == N:
start = 1
else:
start = 0
for j in range(start, 10, 1):
if s - j >= 0:
t = minDigits(n - 1, s - j)
if t[1] == True:
mem1[n, s] = str(j) + t[0], True
return str(j) + t[0], True
mem1[n, s] = "", False
return "", False
t1 = minDigits(N, s)
t2 = maxDigits(N, s)
print(str(t1[0] if t1[1] else -1) + " " + str(t2[0] if t2[1] else -1)) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN BIN_OP STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN STRING NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR STRING NUMBER RETURN STRING NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN BIN_OP STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN STRING NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR STRING NUMBER RETURN STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER STRING FUNC_CALL VAR VAR NUMBER 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(" ", 1)
m, s = int(m), int(s)
def rev(a):
return a[::-1]
if 9 * m < s or s == 0 and m > 1:
print("-1 -1")
elif s == 0 and m == 1:
print("0 0")
else:
max1, min1 = "", ""
i = 1
while i <= m:
if s >= 9:
s = s - 9
max1 = max1 + "9"
i = i + 1
continue
elif 0 < s < 9:
max1 = max1 + str(s)
s = 0
i = i + 1
continue
elif s == 0:
max1 = max1 + "0"
i = i + 1
continue
min1 = rev(max1)
if min1[0] == "0":
mimi = "1"
for i in range(len(min1)):
if min1[i] != "0":
mark = i
mark1 = int(min1[i])
break
mimi = mimi + min1[1:mark] + str(mark1 - 1) + min1[mark + 1 :]
min1 = mimi
print(min1, max1) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR NUMBER 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 VAR STRING STRING ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP 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 | n, s = map(int, input().split())
s_save = s
if s == 0 and n == 1:
ansmax, ansmin = 0, 0
elif s == 0 and n > 1:
ansmax, ansmin = -1, -1
elif s > n * 9:
ansmax, ansmin = -1, -1
else:
ansmax, ansmin = 0, 0
d, t = 0, 0
for i in range(n):
if s > 0:
d = min(9, s)
else:
d = 0
ansmax += d * 10 ** (n - 1 - i)
s -= d
s = s_save
d, t = 0, 0
if 1 + 9 * (n - 1) >= s:
for i in range(n):
if s - 1 > 0:
d = min(9, s - 1)
else:
d = 0
ansmin += d * 10**i
s -= d
ansmin += 10 ** (n - 1)
else:
for i in range(n):
d = min(9, s)
ansmin += d * 10**i
s -= d
print(ansmin, ansmax) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
z = s
maxn = ""
minn = ""
if s == 0:
if m == 1:
print(0, 0)
else:
print("-1 -1")
elif s > 9 * m:
print("-1 -1")
else:
for i in range(m):
if s >= 9:
maxn += str(9)
s -= 9
elif s == 0:
maxn += str(0)
else:
maxn += str(s)
s = 0
s = z
for i in range(m):
if s >= 10:
minn = "9" + minn
s -= 9
elif s == 1:
if i == m - 1:
minn = "1" + minn
else:
minn = "0" + minn
else:
y = s - 1
if i == m - 1:
minn = str(s) + minn
else:
minn = str(y) + minn
s = 1
print(minn, maxn) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR 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 | test = lambda m, s: s >= 0 and s <= 9 * m
m, s = map(int, input().split())
if m == 1 and s == 0:
print(0, 0)
else:
m1, s1 = m, s
mn, mx = "", ""
fo = True
while test(m1, s1) and m1 > 0:
i = 1 if m1 == m else 0
f = True
while i <= 9 and f:
if test(m1 - 1, s1 - i):
mn = mn + str(i)
m1 -= 1
s1 -= i
f = False
i += 1
if f:
fo = False
break
if not fo or mn == "":
print(-1, -1)
else:
m1, s1 = m, s
while test(m1, s1) and m1 > 0:
i = 9
f = True
while i >= (1 if m1 == m else 0) and f:
if test(m1 - 1, s1 - i):
mx = mx + str(i)
m1 -= 1
s1 -= i
f = False
i -= 1
print(mn, mx) | ASSIGN VAR VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER VAR 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 | def det(m, s):
return s < 0 or m * 9 < s
m, s = map(int, input().split())
if det(m, s):
print(-1, -1)
elif s == 0 and m == 1:
print(0, 0)
elif s == 0:
print(-1, -1)
else:
s2 = s
m2 = m
for i in range(m):
if i == 0:
for j in range(1, 10):
if not det(m - 1, s - j):
print(j, end="")
m -= 1
s -= j
break
else:
for j in range(10):
if not det(m - 1, s - j):
print(j, end="")
m -= 1
s -= j
break
s, m = s2, m2
print(" ", end="")
for i in range(m):
for j in range(9, -1, -1):
if not det(m - 1, s - j):
print(j, end="")
m -= 1
s -= j
break | FUNC_DEF RETURN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR NUMBER 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_lrg(leng, num_l, req):
if leng == 0 or req < 0:
if req == 0:
return "".join(list(map(str, num_l)))
else:
return []
if req < 10:
num_l.append(req)
req = 0
else:
num_l.append(9)
req -= 9
return solve_lrg(leng - 1, num_l, req)
def solve_sm(leng, num_l, req):
if leng == 0 or req < 0:
if req == 0:
num_l.reverse()
return "".join(list(map(str, num_l)))
else:
return []
if req < 10 and leng == 1:
num_l.append(req)
req = 0
elif req == 1 and leng > 1:
num_l.append(0)
elif req < 10 and leng > 1:
num_l.append(req - 1)
req = 1
else:
num_l.append(9)
req -= 9
return solve_sm(leng - 1, num_l, req)
leng, su = list(map(int, input().split()))
small = solve_sm(leng, [], su)
big = solve_lrg(leng, [], su)
if leng * 9 < su or su == 0 and leng > 1:
print("-1 -1")
else:
print(small, big) | FUNC_DEF IF VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN LIST IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR RETURN FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN LIST IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR LIST VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL 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 | maxnum = [(0) for i in range(110)]
minnum = [(0) for i in range(110)]
m, s = list(map(int, input().split()))
length = m
sum_num = s
if m * 9 < s:
print("-1 -1")
else:
m = m - 1
while s > 9:
minnum[m] = 9
m = m - 1
s = s - 9
if m == 0:
minnum[m] = s
else:
minnum[m] = s - 1
minnum[0] = 1
if minnum[m] < 0:
print("-1", end="")
else:
for i in range(0, length):
print(minnum[i], end="")
print(" ", end="")
m = 0
s = sum_num
while s > 9:
maxnum[m] = 9
s = s - 9
m = m + 1
maxnum[m] = s
if maxnum[0] == 0 and length > 1:
print("-1", end="")
else:
for j in range(0, length):
print(maxnum[j], end="") | ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR NUMBER 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 | length, n_sum = [int(x) for x in input().split()]
if length > 1 and n_sum == 0:
print("-1 -1")
exit()
if n_sum == 0:
print("0 0")
exit()
maxes = []
zeros_count = 0
for i in range(0, length):
max_value = min(n_sum, 9)
n_sum -= max_value
maxes.append(str(max_value))
if max_value == 0:
zeros_count += 1
if n_sum > 0:
print("-1 -1")
exit()
max_str = "".join(maxes)
mins = [max_str[length - zeros_count - 1]]
mins.extend(["0"] * zeros_count)
for i in range(length - zeros_count - 2, -1, -1):
mins.append(max_str[i])
if zeros_count > 0:
a = int(mins[0]) - 1
mins[0] = "1"
for i in range(length - 1, -1, -1):
b = int(mins[i])
if b + a < 10:
mins[i] = str(b + a)
break
min_str = "".join(mins)
print(min_str, max_str) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP 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 > m * 9:
print(-1, -1)
elif s == 0:
if m == 1:
print(0, 0)
else:
print(-1, -1)
else:
pos = 0
lost = s
minAns = ""
while (m - pos - 1) * 9 > lost:
if pos == 0:
minAns += "1"
lost -= 1
else:
minAns += "0"
pos += 1
if 9 * (m - pos) == lost:
minAns += "9" * (m - pos)
else:
minAns += str(lost % 9) + "9" * (m - pos - 1)
print(minAns, end=" ")
maxAns = ""
lost = s
pos = 0
while lost - 9 >= 0:
maxAns += "9"
pos += 1
lost -= 9
if m - pos > 0:
maxAns += str(lost)
maxAns += "0" * (m - pos - 1)
print(maxAns) | ASSIGN VAR 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING WHILE BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING VAR NUMBER IF BIN_OP NUMBER BIN_OP VAR VAR VAR VAR BIN_OP STRING BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER 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 = [int(i) for i in input().split()]
output = [-1, -1]
mini = []
maxi = []
if s == 0 and m == 1:
output = [0, 0]
if s >= 1 and s <= 9:
mini.extend([(0) for i in range(m)])
maxi.extend([(0) for i in range(m)])
if m > 1:
mini[0] = 1
mini[m - 1] = s - 1
maxi[0] = s
elif m == 1:
mini[0] = s
maxi[0] = s
if s > 9 and s <= 9 * m:
stop = False
i = 0
while not stop:
if s > 9:
mini.append(9)
maxi.append(9)
s -= 9
i += 1
else:
mini.append(s)
maxi.append(s)
stop = True
mini.sort()
if len(mini) < m:
if mini[0] > 1:
mini[0] -= 1
mini.reverse()
mini.append(1)
mini.reverse()
mini = mini[:1] + [(0) for i in range(m - len(mini))] + mini[1:]
if len(maxi) < m:
maxi = maxi + [(0) for i in range(m - len(maxi))]
if len(mini) != 0:
output[0] = "".join([str(i) for i in mini])
output[1] = "".join([str(i) for i in maxi])
print(output[0], output[1]) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | I = lambda: list(map(int, input().split()))
m, s = I()
s1 = s
if s == 0:
if m == 1:
print(0, 0)
else:
print(-1, -1)
elif s > 9 * m:
print(-1, -1)
else:
arr = [0] * m
for i in range(0, m):
if s > 9:
arr[i] = 9
s = s - 9
else:
arr[i] = s
s = 0
arr1 = [0] * m
s1 = s1 - 1
for i in range(m - 1, 0, -1):
if s1 > 9:
arr1[i] = 9
s1 = s1 - 9
else:
arr1[i] = s1
s1 = 0
arr1[0] = s1 + 1
for i in range(0, m):
print(arr1[i], end="")
print("")
for i in range(0, m):
print(arr[i], end="") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR 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 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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER 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 | import sys
m, s = map(int, sys.stdin.readline().strip().split(" "))
upp = 9 * m
bot = 1
if m == 1 and s == 0:
print(0, 0)
elif s < bot or s > upp or m == 0:
print(-1, -1)
else:
A = [0] * m
A[0] = 1
for x in range(m):
for y in range(10):
if sum(A) == s:
break
else:
A[m - x - 1] = y
for x in range(m):
print(A[x], end="")
print(" ", end="")
A = [9] * m
for x in range(m):
for y in range(9, -1, -1):
if sum(A) == s:
break
else:
A[m - x - 1] = y
for x in range(m):
print(A[x], end="")
print(" ", end="")
print() | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING 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 | def genmn():
co9 = s // 9
prefix = s % 9
if prefix == 0:
prefix = 9
co9 -= 1
if m == co9 + 1:
return str(prefix) + "9" * co9
prefix -= 1
return "1" + "0" * (m - co9 - 2) + str(prefix) + "9" * co9
def genmx():
co9 = s // 9
appendix = s % 9
if m == co9:
return "9" * co9
return "9" * co9 + str(appendix) + "0" * (m - co9 - 1)
m, s = list(map(int, input().split()))
if s <= 0 or s > m * 9:
if s == 0 and m == 1:
print("0 0")
exit(0)
print("-1 -1")
else:
print("%s %s" % (genmn(), genmx())) | FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR VAR NUMBER RETURN 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 FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN BIN_OP STRING VAR RETURN BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def main():
m, n = [int(v) for v in input().split()]
s = m
digits1 = []
digits2 = []
total1 = n - 1
total2 = n
if n == 0 and m == 1:
print(0, 0)
return
if total1 < 0:
print(-1, -1)
return
if m * 9 < n:
print(-1, -1)
return
s1 = [(0) for i in range(m)]
s1[0] = 1
while total1 > 0:
val = total1 % 9
if val == 0:
val = 9
digits1.append(val)
total1 -= val
while total2 > 0:
val = total2 % 9
if val == 0:
val = 9
digits2.append(val)
total2 -= val
val1 = 0
digits1.sort()
for i in range(len(digits1), m):
digits1.insert(0, 0)
digits2.sort(reverse=True)
for i in range(len(digits2), m):
digits2.append(0)
for i in range(0, m):
val1 = val1 * 10 + s1[i] + digits1[i]
if digits1[m - 1] == 0:
val2 = 0
for i in range(0, m):
val2 = val2 * 10 + s1[i] + digits1[m - i - 1]
else:
val2 = 0
for i in range(0, m):
val2 = val2 * 10 + digits2[i]
print(val1, val2)
main() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER RETURN ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def main():
m, s = map(int, input().split())
if s == 0:
if m == 1:
print(0, 0)
else:
print(-1, -1)
exit()
for i in range(1, 10):
if 0 <= s - i <= (m - 1) * 9:
k = s - i
a = []
for j in range(m - 1):
a.append(min(9, k))
k -= min(9, k)
print("".join(map(str, [i] + a[::-1])))
break
else:
print(-1)
k = s
a = []
for j in range(m):
a.append(min(9, k))
k -= min(9, k)
if k:
print(-1)
else:
print("".join(map(str, a)))
main() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR BIN_OP LIST VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n = [int(j) for j in input().split()]
if n[1] == 0 and n[0] == 1:
print("0 0")
elif n[1] == 0 or n[1] > 9 * n[0]:
print("-1 -1")
elif n[1] == 9 * n[0]:
m = ""
for k in range(n[0]):
m = m + "9"
print(m, m)
else:
x = n[1] % 9
y = int((n[1] - x) / 9)
m = ""
for k in range(y):
m = m + "9"
m = m + str(x)
for k in range(n[0] - y - 1):
m = m + "0"
if n[1] > 9 * (n[0] - 1):
t = n[1] % 9
w = str(t)
for k in range(n[0] - 1):
w = w + "9"
else:
t = (n[1] - 1) % 9
y = int((n[1] - 1 - t) / 9)
w = "1"
for k in range(n[0] - 2 - y):
w = w + "0"
w = w + str(t)
for k in range(y):
w = w + "9"
print(w, m) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER VAR NUMBER BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP 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 = input().split()
m = int(m)
s = int(s)
if s / m == 0:
if s + m == 1:
a = b = 0
else:
a = b = -1
elif 0 < s / m <= 1:
sy = s - 1
n = sy // 9
if n != 0:
sy = sy - n * 9
a = 10 ** (m - 1) + 10**n - 1 + sy * 10**n
else:
a = 10 ** (m - 1) + sy
sy1 = s - 9
if sy1 <= 0:
b = s * 10 ** (m - 1)
else:
n1 = s // 9
s = s - n1 * 9
b = (10**n1 - 1) * 10 ** (m - n1) + s * 10 ** (m - n1 - 1)
elif s / m > 1:
if s / 9 > m:
a = b = -1
else:
n = s // 9
if n == m - 1:
if s % 9 == 0:
a = 9 * 10 ** (n - 1) - 1 + 10 ** (m - 1)
b = (10**n - 1) * 10 + s - n * 9
else:
a = (s - n * 9) * 10 ** (m - 1) + 10**n - 1
b = (10**n - 1) * 10 + s - n * 9
elif n == m:
a = 10**n - 1
b = 10**n - 1
elif n == 0:
a = 10 ** (m - 1) + s - 1
b = s * 10 ** (m - 1)
elif s % 9 != 0:
a = 10 ** (m - 1) + 10**n - 1 + (s - n * 9 - 1) * 10**n
b = (10**n - 1) * 10 ** (m - n) + (s - n * 9) * 10 ** (m - n - 1)
else:
b = (10**n - 1) * 10 ** (m - n) + (s - n * 9) * 10 ** (m - n - 1)
a = 10 ** (m - 1) + 9 * 10 ** (n - 1) - 1
print(a, b) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = list(map(int, input().split()))
if s == 0:
if m != 1:
print(-1, -1)
else:
print(0, 0)
elif s > 9 * m:
print(-1, -1)
else:
A = [0] * m
a = [0] * m
s1 = s
for i in range(m):
if s1 > 9:
A[i] = 9
s1 -= 9
else:
A[i] = s1
s1 = 0
s2 = s - 1
a[0] = 1
for i in range(m - 1, -1, -1):
if s2 > 9:
a[i] = 9
s2 -= 9
else:
a[i] += s2
s2 = 0
for i in range(m):
print(a[i], end="")
print(" ", end="")
for i in range(m):
print(A[i], end="") | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING 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 | m, s = map(int, input().split())
def max_recur(m, s, a):
if m == 0:
return a
if not a and s == 0:
if m == 1:
return 0
else:
return -1
if 9 * m < s:
return -1
digit = min(9, s)
a += str(digit)
return max_recur(m - 1, s - digit, a)
def min_recur(m, s, a):
if m == 0:
return a
if not a and s == 0:
if m == 1:
return 0
else:
return -1
if 9 * m < s:
return -1
if not a:
digit = max(1, s - (m - 1) * 9)
else:
digit = max(0, s - (m - 1) * 9)
a += str(digit)
return min_recur(m - 1, s - digit, a)
mx = max_recur(m, s, "")
mn = min_recur(m, s, "")
print(mn, mx) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF BIN_OP NUMBER VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF BIN_OP NUMBER VAR VAR RETURN NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR FUNC_CALL 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:
print(0, 0)
elif s < 1 or s > 9 * m:
print(-1, -1)
else:
x = (s - 1) // 9
y = (s - 1) % 9
if x + 1 == m:
print("%s" % (y + 1) + "9" * x)
else:
num = [1] + [0] * (m - x - 2) + [y] + [9] * x
print("".join(list(map(str, num))), end=" ")
x = s // 9
y = s % 9
num = [9] * x + [y] * (y != 0) + [0] * (m - x - 1 + (y == 0))
print("".join(list(map(str, num)))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER LIST VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST VAR VAR NUMBER BIN_OP LIST NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def can(spots, sum):
return 9 * spots >= sum
def biggest(m, s):
if m == 1 and s <= 9:
return str(s)
if m == 1 and s >= 10:
return "x"
if m > 1:
mx = min(9, s)
return str(mx) + biggest(m - 1, s - mx)
return "x"
def smallest(m, s):
res = ""
for i in range(m):
for digit in range(0, 11):
if (i > 0 or digit > 0 or m == 1 and digit == 0) and can(
m - i - 1, s - digit
):
res += str(digit)
s = s - digit
break
return res
def main():
m, s = [int(i) for i in input().split()]
big = biggest(m, s)
if big[-1] == "x" or len(big) > 1 and big[0] == "0":
print("-1 -1")
else:
small = smallest(m, s)
print(small + " " + big)
main() | FUNC_DEF RETURN BIN_OP NUMBER VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR RETURN STRING FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING 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 | l = input().split()
d = int(l[0])
s = int(l[1])
if d == 1 and s == 0:
print("0 0")
elif s <= 0 or s > d * 9:
print("-1 -1")
else:
b1 = (9 * d - s) // 9
b2 = (9 * d - s) % 9
s1 = (s - 1) // 9
s2 = (s - 1) % 9
big = 10**d - (1 + b2) * 10**b1
small = 10 ** (d - 1) + (1 + s2) * 10**s1 - 1
print(str(small), str(big)) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, n = (int(i) for i in input().split())
if n == 0 and m != 1 or m * 9 < n:
print(-1, -1)
elif n // 9 == m:
print("9" * m, "9" * m)
else:
m1 = m
m1 -= n // 9
m1 -= 1
maxim = "9" * (n // 9) + str(n % 9) + "0" * m1
if m1 == 0:
minim = str(n % 9) + "9" * (n // 9)
else:
n -= 1
m1 = m
m1 -= n // 9
m1 -= 2
minim = "1" + "0" * m1 + str(n % 9) + "9" * (n // 9)
print(minim, maxim) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP 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 FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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 | put = input().split()
l = int(put[0])
s = int(put[1])
if s == 0 and l == 1:
print(0, 0)
exit()
if s < 1 or s > 9 * l:
print(-1, -1)
exit()
a = [0] * l
b = [0] * l
i = 0
k = -1
if l > 1:
a[0] = 1
b[0] = 1
while True:
if sum(a) == s:
break
if a[k] < 9:
a[k] += 1
else:
k -= 1
while True:
if sum(b) == s:
break
if b[i] < 9:
b[i] += 1
else:
i += 1
for i in range(l):
a[i] = str(a[i])
b[i] = str(b[i])
a = "".join(a)
b = "".join(b)
print(a, b) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING 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 | data = list(map(int, input().split()))
ndigits = data[0]
d_sum = data[1]
if d_sum == 0:
if ndigits > 1:
print("-1 -1")
else:
print("0 0")
elif 9 * ndigits < d_sum:
print("-1 -1")
else:
to_minimal = d_sum
minimal = ""
for x in range(ndigits - 1):
for number in range(9, -1, -1):
if to_minimal - number > 0:
to_minimal -= number
minimal += str(number)
break
minimal += str(to_minimal)
maximal = ""
for x in range(ndigits - 1):
for number in range(9, -1, -1):
if d_sum - number > -1:
d_sum -= number
maximal += str(number)
break
maximal += str(d_sum)
for index in range(ndigits - 1, -1, -1):
print(minimal[index], end="")
print(" " + str(maximal)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING 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, k = map(int, input().split())
if k == 1:
print("1" + "0" * (n - 1), "1" + "0" * (n - 1))
elif n == 1:
if 0 <= k <= 9:
print(k, k)
else:
print("-1 -1")
else:
ANS = ["1"] + ["0"] * (n - 2) + ["1"]
k -= 2
if k < 0:
print("-1 -1")
else:
ANS[0] = str(min(8, k) + 1)
k -= min(8, k)
i = 1
while k > 0 and i < n - 1:
ANS[i] = str(min(9, k))
k -= min(9, k)
i += 1
ANS[-1] = str(min(8, k) + 1)
k -= min(8, k)
if k > 0:
print("-1 -1")
else:
a = "".join(ANS)
a = a[::-1]
if i == n - 1:
if ANS[-2] != "9":
ANS[-2] = str(1 + int(ANS[-2]))
ANS[-1] = "0"
b = "".join(ANS)
else:
if ANS[i - 1] == "9":
ANS[-1] = "0"
ANS[i] = "1"
else:
ANS[i - 1] = str(1 + int(ANS[i - 1]))
ANS[-1] = "0"
b = "".join(ANS)
print(a, b) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER IF VAR NUMBER IF NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP LIST STRING BIN_OP LIST STRING BIN_OP VAR NUMBER LIST STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR FUNC_CALL STRING VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER STRING 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 | length, total = list(map(int, input().split()))
adad_min = []
adad_max = []
nine_counter = 0
ans = [-1, -1]
for i in range(length):
adad_max.append(0)
adad_min.append(0)
temp = total
while temp > 9:
temp -= 9
nine_counter += 1
reminder = temp
if nine_counter < length and total != 0:
for i in range(nine_counter):
adad_min[length - 1 - i] += 9
adad_min[0] += 1
adad_min[length - nine_counter - 1] += reminder - 1
string = ""
for j in range(length):
string += str(adad_min[j])
ans[0] = string
for i in range(nine_counter):
adad_max[i] += 9
adad_max[nine_counter] += reminder
string = ""
for j in range(length):
string += str(adad_max[j])
ans[1] = string
elif reminder != 0:
adad_min[0] += reminder
elif reminder == 0 and length == 1:
ans = [0, 0]
print(int(ans[0]), int(ans[1])) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def get_pairs(summ, m):
def char(arr):
return int("".join(map(str, arr)))
if summ == 0 and m == 1:
print(0, 0)
return
if summ > 9 * m or summ < 1:
print(-1, -1)
return
min_array = [0] * m
min_array[0] = 1
for i in range(m):
diff = summ - sum(min_array)
index = m - i - 1
if diff == 0:
break
elif diff >= 9:
min_array[index] = 9
else:
min_array[index] += diff
max_array = [0] * m
for i in range(m):
diff = summ - sum(max_array)
index = i
if diff == 0:
break
elif diff >= 9:
max_array[index] = 9
else:
max_array[index] += diff
print(char(min_array), char(max_array))
m = input("")
m, summ = m.split(" ")
get_pairs(int(summ), int(m)) | FUNC_DEF FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def solve(m, s):
if s == 0 and m > 1:
print(*[-1, -1])
return 0
elif s == 0 and m == 1:
print(*[0, 0])
return 0
elif 9 * m < s:
print(*[-1, -1])
return 0
else:
to = s
max1 = []
while sum(max1) != s:
if to >= 9:
max1.append(9)
to -= 9
elif to < 9:
max1.append(to)
max1 += [0] * (m - len(max1))
if s >= 9 * (m - 1) + 1:
min1 = max1[::-1]
print(*min1, sep="")
print(*max1, sep="")
elif s < 9 * (m - 1) + 1:
min1 = [1]
to = s - 1
baki = []
while sum(baki) != s - 1:
if to >= 9:
baki.append(9)
to -= 9
else:
baki.append(to)
min1 = min1 + [0] * (m - 1 - len(baki)) + baki[::-1]
print(*min1, sep="")
print(*max1, sep="")
m, s = map(int, input().split())
solve(m, s) | FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER RETURN NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING IF VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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
def main():
import sys
a, b = map(int, sys.stdin.readline().split())
if not a:
maxim = "-1"
minim = "-1"
elif not b:
if a == 1:
maxim = "0"
minim = "0"
else:
maxim = "-1"
minim = "-1"
else:
maxim = 0
n = b
while n:
if 9 > n:
maxim = maxim * 10 + n
n = 0
else:
n -= 9
maxim = maxim * 10 + 9
s = str(maxim)
diff = a - len(s)
if diff < 0:
maxim = "-1"
elif diff > 0:
maxim = s + "0" * diff
else:
maxim = s
if diff:
if diff < 0:
minim = "-1"
else:
s = maxim[::-1]
for i in range(len(s)):
if int(s[i]):
break
minim = "1" + "0" * (i - 1) + str(int(s[i]) - 1) + s[i + 1 :]
else:
minim = maxim[::-1]
sys.stdout.write(minim + " " + maxim + "\n")
main() | IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR IF NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP STRING VAR ASSIGN VAR VAR IF VAR IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR STRING 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, sum = [int(i) for i in input().split()]
q = sum % 9
w = sum // 9
if sum == 0:
if n == 1:
print("0 0")
else:
print("-1 -1")
elif w < n - 1:
if q != 0:
print(
"1",
"0" * (n - w - 2),
q - 1,
"9" * w,
" ",
"9" * w,
q,
"0" * (n - w - 1),
sep="",
)
else:
print(
"1",
"0" * (n - w - 1),
"8",
"9" * (w - 1),
" ",
"9" * w,
"0" * (n - w),
sep="",
)
elif w == n - 1:
print(q, "9" * w, " ", "9" * w, q, sep="")
elif q == 0 and w == n:
print("9" * n, " ", "9" * n, sep="")
else:
print("-1 -1") | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP STRING VAR STRING BIN_OP STRING VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP STRING BIN_OP VAR NUMBER STRING BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP STRING VAR STRING BIN_OP STRING VAR VAR STRING IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING BIN_OP STRING 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 | import sys
m, s = [int(x) for x in input().split()]
if m == 1 and s == 0:
print("0 0")
sys.exit()
if s == 0:
print("-1 -1")
sys.exit()
UPPER_BORDER = 10
LOWER_BORDER = -1
dp1 = [([UPPER_BORDER] * (s + 1)) for x in range(m + 1)]
dp2 = [([LOWER_BORDER] * (s + 1)) for x in range(m + 1)]
dp1[0][0] = 0
dp2[0][0] = 0
for mi in range(1, m + 1):
for si in range(1, s + 1):
for i in range(10):
if si - i >= 0 and dp1[mi - 1][si - i] != UPPER_BORDER:
dp1[mi][si] = i
break
for i in range(10):
if si - 9 + i >= 0 and dp2[mi - 1][si - 9 + i] != LOWER_BORDER:
dp2[mi][si] = 9 - i
break
if dp1[m][s] == UPPER_BORDER:
print("-1 -1")
else:
s1, s2 = "", ""
mi, si = m, s
while mi > 0:
s1 = str(dp1[mi][si]) + s1
si -= dp1[mi][si]
mi -= 1
mi, si = m, s
while mi > 0:
s2 = str(dp2[mi][si]) + s2
si -= dp2[mi][si]
mi -= 1
print(s2, end=" ")
print(s1) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR 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())
small = [9] * n
big = [9] * n
tmp = 9 * n
i = 0
if m == 0 and n == 1:
print("0 0")
exit()
canB = False
while i < n:
if tmp == m:
canB = True
break
elif tmp > m:
if tmp - m >= 9:
big[i] -= 9
tmp -= 9
else:
big[i] -= tmp - m
tmp = m
canB = True
break
i += 1
i = 0
tmp = 9 * n
canS = False
while i < n:
if tmp == m:
canS = True
break
if i == 0 and tmp - m >= 8:
small[i] -= 8
tmp -= 8
elif tmp > m:
if tmp - m >= 9:
small[i] -= 9
tmp -= 9
else:
small[i] -= tmp - m
canS = True
break
i += 1
if tmp == m:
canS = True
if canS:
for i in small:
print(i, end="")
else:
print("-1", end="")
print(end=" ")
if canB:
for i in range(n):
print(big[n - i - 1], end="")
else:
print("-1", end="")
print() | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING IF VAR 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 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 = [int(x) for x in input().split()]
if m > 1 and s < 1 or s > 9 * m:
print(-1, -1)
elif m == 1:
print(s, s)
elif s <= 9:
min_num = [s, 10 + s - 1]
max_num = [s, 10 * s]
for i in range(2, m):
min_num.append(min_num[i - 1] - 10 ** (i - 1) + 10**i)
max_num.append(max_num[i - 1] * 10)
print("%d %d" % (min_num[m - 1], max_num[m - 1]))
elif s > 9:
start_m = int(s / 9)
nines = sum([(9 * 10**i) for i in range(start_m)])
min_num = [nines + (s - 9 * start_m) * 10**start_m]
if s % 9 != 0:
delta = min(1, m - start_m)
max_num = [nines * 10**delta + s - 9 * start_m]
for i in range(start_m + 1, m):
min_num.append(min_num[i - start_m - 1] - 10 ** (i - 1) + 10**i)
max_num.append(max_num[i - start_m - 1] * 10)
print("%d %d" % (min_num[-1], max_num[-1]))
else:
max_num = [nines]
for i in range(start_m + 1, m + 1):
min_num.append(min_num[i - start_m - 1] - 10 ** (i - 2) + 10 ** (i - 1))
max_num.append(nines * 10 ** (m - start_m))
print("%d %d" % (min_num[-1], max_num[-1])) | 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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR LIST VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR LIST BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING 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 | def printListNum(arr):
for i in arr:
print(i, end="")
print(" ", end="")
def magic():
m, s = [int(x) for x in input().split()]
if m > 1 and s == 0 or m * 9 < s:
print("-1 -1")
return
lsMax = [0] * m
for i in range(m):
if s > 9:
lsMax[i] = 9
s -= 9
else:
lsMax[i] = s
s = 0
lsMin = [x for x in lsMax[::-1]]
if lsMin[0] == 0:
for i in range(1, m):
if lsMin[i] > 0:
lsMin[0] = 1
lsMin[i] -= 1
break
printListNum(lsMin)
printListNum(lsMax)
magic() | FUNC_DEF FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if s > m * 9 or s == 0 and m != 1:
print(-1, -1, sep=" ")
else:
mx = []
m_ = m
while m:
temp = min(9, s)
s -= temp
m -= 1
mx.append(str(temp))
mn = list(reversed(mx))
if mn[0] == "0" and m_ != 1:
i = 1
while i <= m_:
if int(mn[i]) > 0:
mn[i] = str(int(mn[i]) - 1)
mn[0] = "1"
break
else:
i += 1
mn = int("".join(mn))
mx = int("".join(mx))
print(mn, mx, sep=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER STRING ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING 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 | def p(a):
if a <= 0:
return 0
else:
return a
output = ""
l, s = map(int, input().split(" "))
if s / l > 9 or s == 0 and l > 1:
print("-1 -1")
elif s == 0 and l == 1:
print("0 0")
else:
n = str(s % 9)
if s % 9 == 0:
n = ""
output = n + "9" * p(s // 9)
if len(output) < l:
output = (
"1"
+ "0" * p(l - 2 - (s - 1) // 9)
+ str((s - 1) % 9)
+ "9" * p((s - 1) // 9)
)
output = output + " " + "9" * p(s // 9) + n + "0" * (l - s // 9 - len(n))
print(output) | FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN VAR ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER 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 IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR STRING BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | import sys
input = sys.stdin.readline
def inp():
return int(input())
def insr():
s = input()
return list(s[: len(s) - 1])
def invr():
return map(int, input().split())
def can(m, s):
return 0 <= s <= 9 * m
m, s = invr()
minn = ""
sum = s
for i in range(m):
min_failed = True
for d in range(10):
if (i > 0 or d > 0 or m == 1 and d == 0) and can(m - i - 1, sum - d):
minn += chr(ord("0") + d)
sum -= d
min_failed = False
break
if min_failed:
minn = "-1"
break
maxn = ""
sum = s
for i in range(m):
max_failed = True
for d in range(9, -1, -1):
if (i > 0 or d > 0 or m == 1 and d == 0) and can(m - i - 1, sum - d):
maxn += chr(ord("0") + d)
sum -= d
max_failed = False
break
if max_failed:
maxn = "-1"
break
print("{} {}".format(minn, maxn)) | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER 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 BIN_OP FUNC_CALL VAR STRING VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR STRING 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 | def sumDigits(S):
return sum(int(ch) for ch in S)
def soln(m, s):
sOrig = s
maxStr = []
for _ in range(m):
curr = min(s, 9)
s -= curr
maxStr.append(str(curr))
maxVal = int("".join(maxStr))
if len(str(maxVal)) != m or s != 0:
return "-1 -1"
minStr = maxStr[::-1]
if minStr[0] == "0":
for i, ch in enumerate(minStr):
if ch != "0":
minStr[0] = "1"
minStr[i] = str(int(ch) - 1)
break
minVal = int("".join(minStr))
if len(str(minVal)) != m or sumDigits(minStr) != sOrig:
return "-1 -1"
return f"{minVal} {maxVal}"
def main():
m, s = [int(x) for x in input().split(" ")]
result = soln(m, s)
print(result)
def randomTest():
for m in range(1, 101):
for s in range(901):
soln(m, s)
main() | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN STRING ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN STRING RETURN VAR STRING VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if s == 0 and m > 1 or m * 9 < s:
print(-1, -1)
elif s == 0:
print(s, s)
else:
mn = [0] * m
mn[0] = 1
i = m - 1
sp = s - 1
while sp:
if mn[i] == 9:
i -= 1
else:
sp -= 1
mn[i] += 1
mx = [0] * m
i = 0
sp = s
while sp:
if mx[i] == 9:
i += 1
else:
sp -= 1
mx[i] += 1
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 IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR 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 | def findLargest(m, s):
if s == 0:
if m == 1:
return 0
else:
return -1
if s > 9 * m:
return -1
res = [0] * m
for i in range(0, m):
if s >= 9:
res[i] = 9
s = s - 9
else:
res[i] = s
s = 0
st = ""
for i in range(0, m):
st = st + str(res[i])
st = int(st)
return st
def findSmallest(m, s):
if s == 0:
if m == 1:
return 0
else:
return -1
if s > 9 * m:
return -1
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
st = ""
for i in range(m):
st = st + str(res[i])
st = int(st)
return st
def main():
inp = list(map(int, input().split()))
ans = [-1, -1]
ans[0] = findSmallest(inp[0], inp[1])
ans[1] = findLargest(inp[0], inp[1])
if ans[1] == -1 and ans[0] != -1:
ans[1] = ans[0]
for i in range(len(ans) - 1):
print(ans[i], end=" ")
i += 1
print(ans[i])
main() | FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR BIN_OP NUMBER VAR RETURN NUMBER 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 ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR BIN_OP NUMBER VAR RETURN NUMBER 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 ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(i) for i in input().split()]
if s > 9 * m or s == 0 and m > 1:
print(-1, -1)
elif m == 1:
print(s, s)
else:
m1 = ""
m2 = ""
bit = s // 9
m1 = "9" * bit
if m != bit:
m1 += str(s % 9) + (m - 1 - bit) * "0"
if m == bit:
m2 = m1
elif m - bit == 1:
if m1[m - 1] == "0":
m2 = "1" + "8" + "9" * (bit - 1)
else:
m2 = m1[m - 1] + m1[: m - 1]
elif s % 9 == 0:
m2 = "1" + (m - bit - 1) * "0" + "8" + "9" * (bit - 1)
else:
m2 = "1" + (m - bit - 2) * "0" + str(s % 9 - 1) + bit * "9"
print(m2, m1) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR STRING IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP STRING STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING STRING BIN_OP STRING 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 BIN_OP VAR NUMBER NUMBER BIN_OP 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 = [int(a) for a in input().split()]
maxx = ""
minn = ""
s1 = s
s2 = s - 1
if s == 0 and m == 1:
print(0, 0)
elif s > 9 * m or s < 1:
print(-1, -1)
elif m == 1:
print(s, s)
else:
for a in range(m):
if s1 > 9:
maxx += str(9)
s1 -= 9
elif s1 == 0:
maxx += str(0)
else:
maxx += str(s1)
s1 = 0
for a in range(m - 1):
if s2 > 9:
minn = str(9) + minn
s2 -= 9
elif s2 == 0:
minn = str(0) + minn
else:
minn = str(s2) + minn
s2 = 0
minn = str(s2 + 1) + minn
print(minn, maxx) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER 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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR 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 s > 9 * m:
print("-1", "-1")
elif s == 0 and m != 1:
print("-1", "-1")
else:
M = [0] * m
Mmax = [0] * m
Mmin = [0] * m
a9 = int(s / 9)
for i in range(a9):
M[i] = 9
b = s - 9 * a9
if b != 0:
M[a9] = b
for i in range(m):
Mmax[i] = str(M[i])
Nmax = "".join(Mmax)
M.sort()
if M[0] == 0:
for i in range(m):
if M[i] != 0:
M[0] = 1
M[i] -= 1
break
for i in range(m):
Mmin[i] = str(M[i])
Nmin = "".join(Mmin)
print(Nmin, Nmax) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 | s = input().split(" ")
m = int(s[0])
s = int(s[1])
s1 = s
if s > m * 9 or m > 1 and s < 1:
print("-1 -1")
else:
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="")
res = [(0) for i in range(m + 1)]
for i in range(m):
if s1 > 9:
res[i] = 9
s1 -= 9
else:
res[i] = s1
s1 = 0
for i in range(m):
print(res[i], end="") | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING 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 STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
a, b = 0, 0
if s > 9 * m or s < 1 != m:
print(-1, -1)
else:
for i in range(m):
if m > s // 9 + 1:
c = 1
if (s - 1 - 9 * i) // 9 >= 1:
b += 9 * 10**i
elif s - 1 - 9 * i > 0:
b += (s - 1 - 9 * i) * 10**i
else:
c = 0
if (s - 9 * i) // 9 >= 1:
b += 9 * 10**i
else:
b += (s - 9 * i) * 10**i
print(b + 10 ** (m - 1) if c == 1 else b)
for i in range(m):
if i + 1 > m - s // 9:
a += 9 * 10**i
elif i + 1 == m - s // 9:
a += s % 9 * 10**i
print(a, end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR IF BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER 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 m == 1 and s == 0:
print("0 0")
elif 9 * m < s or s == 0:
print("-1 -1")
else:
k = (s - 1) // 9
r = s - k * 9
l = "9" * k
z = m - len(l)
a = ("1" if z > 1 else "") + "0" * (z - 2) + (str(r - 1) if z > 1 else str(r)) + l
b = l + str(r) + "0" * (z - 1)
print(a, b) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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 BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER STRING STRING BIN_OP STRING BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR 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 f(m, s):
if m == 1 and s < 10:
return str(s)
if m == 1 and s > 9:
return "F"
if s > 9:
return "9" + f(m - 1, s - 9)
else:
return str(s) + f(m - 1, 0)
def g(m, s):
s1 = s
L = list()
if m == 1 and s < 10:
return s
if m == 1 and s > 9:
return -1
if s == 0:
return -1
while s1 > 9:
L.append("9")
s1 = s1 - 9
if len(L) == m - 1:
L.append(str(s1))
else:
L.append(str(s1 - 1))
while len(L) < m - 1:
L.append(str(0))
L.append("1")
L = L[::-1]
ch = ""
for c in L:
ch += c
return int(ch)
chaine = str(input())
liste = chaine.split()
m = int(liste[0])
s = int(liste[1])
mini = -1
maxi = -1
if f(m, s)[len(f(m, s)) - 1] != "F" and s != 0:
maxi = int(f(m, s))
mini = g(m, s)
if m == 1 and s == 0:
mini, maxi = 0, 0
if mini == -1 or maxi == -1:
mini, maxi = -1, -1
print(str(mini) + " " + str(maxi)) | FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER RETURN BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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 NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if m == 1 and s == 0:
print(0, 0)
elif s < 1 or s > 9 * m:
print(-1, -1)
else:
mi = [0] * m
mi[0] = 1
s -= 1
c = s // 9
c1 = s % 9
ma = [0] * m
for i in range(c):
mi[m - 1 - i] = 9
mi[m - 1 - c] += c1
s += 1
q = s // 9
q1 = s % 9
for i in range(q):
ma[i] = 9
if q1 > 0:
ma[q] += q1
aa = 0
bb = 0
for i in range(m):
aa += mi[i] * 10 ** (m - i - 1)
bb += ma[i] * 10 ** (m - i - 1)
print(aa, bb) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR ASSIGN 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 VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP 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 calcSum(nums):
s = 0
for i in nums:
s += i
return s
def findMin(nums, m, s):
nums[0] = 1
for i in range(1, m):
nums[i] = 0
sum = calcSum(nums)
i = 0
diff = s - sum
while True:
if diff > 9:
nums[-i - 1] = 9
i += 1
if i >= m:
break
diff -= 9
else:
nums[-i - 1] += diff
if nums[-i - 1] > 9:
nums[-i - 1] = 9
break
if diff <= 0:
break
out = "-1"
if calcSum(nums) != s:
return out
out = ""
for i in nums:
out += str(i)
return out
def findMax(nums, m, s):
for i in range(0, m):
nums[i] = 9
sum = calcSum(nums)
i = 0
diff = sum - s
while True:
if diff <= 0:
break
if diff > 9:
nums[-i - 1] = 0
i += 1
if i >= m:
break
else:
nums[-i - 1] -= diff
if nums[-i - 1] < 0:
nums[-i - 1] = 0
break
diff -= 9
if calcSum(nums) != s:
return "-1"
out = ""
for i in nums:
out += str(i)
return out
m, s = input("").split()
m, s = int(m), int(s)
if m == 1 and s == 0:
print("0 0")
elif m == 0 or s == 0:
print("-1 -1")
else:
nums = [(0) for i in range(m)]
out = findMin(nums, m, s) + " "
out += findMax(nums, m, s)
print(out) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN STRING ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR STRING VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def GivenLengthAndSumOfDigits(m, s):
isPossible = NumberExists(m, s)
if s == 0 and m == 1:
return str(0), str(0)
if isPossible:
smallest = FindSmallestNumber(m, s)
largest = FindLargestNumber(m, s)
return smallest, largest
else:
return str(-1), str(-1)
def NumberExists(m, s):
if s > 0 and s <= 9 * m:
return True
else:
return False
def FindSmallestNumber(m, s):
smallest = [0] * m
while s > 0:
i = 9
while i >= 1:
if s >= i:
smallest[m - 1] = i
s -= i
m -= 1
if m != 0 and s == 0:
smallest[0] = 1
smallest[m] -= 1
break
i -= 1
result = "".join(str(x) for x in smallest)
return result
def FindLargestNumber(m, s):
largest = [0] * m
d = 0
while s > 0 and d < m:
i = 9
while i >= 1:
if s >= i:
largest[d] = i
s -= i
d += 1
break
i -= 1
result = "".join(str(x) for x in largest)
return result
m, s = [int(x) for x in input().split()]
smallest, largest = GivenLengthAndSumOfDigits(m, s)
print(smallest + " " + largest) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR RETURN FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR 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 | l, s = [int(v) for v in input().strip().split()]
tempSum = s
max_ = 0
if s == 0:
if l == 1:
print("0 0")
else:
print("-1 -1")
else:
for i in range(l):
max_ *= 10
temp = min(tempSum, 9)
tempSum -= temp
max_ += temp
if tempSum > 0:
print("-1 -1")
else:
min_ = str(max_)[::-1]
index = 0
for i in range(len(min_)):
if min_[i] != "0":
break
index = i
if min_[0] == "0":
min_ = str(int(min_[0]) + 1) + min_[1:]
min_ = (
min_[0 : index + 1] + str(int(min_[index + 1]) - 1) + min_[index + 2 :]
)
print(min_, max_) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER 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 | m, s = [int(i) for i in input().split()]
st = s
if s <= 0 and m > 1 or s > m * 9:
print("-1", "-1")
exit()
else:
for i in range(m - 1, -1, -1):
last = max(0, s - 9 * i)
if last <= 0 and i == m - 1 and s != 0:
last = 1
print(last, end="")
s -= last
print(" ", end="")
for i in range(m - 1, -1, -1):
first = min(9, st)
print(first, end="")
st -= first | ASSIGN VAR VAR FUNC_CALL VAR 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 STRING EXPR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR VAR STRING VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR STRING VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | a, b = map(int, input().split())
if b > a * 9 or b == 0 and a > 1:
print("-1 -1")
else:
max = ""
while a > 0:
x = 9 if b > 9 else b
b -= x
max += str(x)
a -= 1
min = max[::-1]
if min[0] == "0":
for i in range(len(min)):
if min[i] != "0":
min = "1" + min[1:i] + str(ord(min[i]) - 48 - 1) + min[i + 1 :]
break
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 EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER 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 | m, s = map(int, input().split())
c = s // 9 * "9"
if s % 9:
c += str(s % 9)
c += "0" * (m - len(c))
c2 = c[::-1]
if c.count("0") and s != 0:
c2 = list(c)
i = c2.index("0") - 1
c2[i] = str(int(c2[i]) - 1)
c2[-1] = "1"
c2 = "".join(c2[::-1])
if int(m) * 9 < s or s == 0 and m > 1:
print("-1", "-1")
else:
print(c2, c) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR FUNC_CALL STRING VAR NUMBER IF BIN_OP FUNC_CALL VAR 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 | n, s = map(int, input().split(" "))
c = []
d = []
f = 0
t = s
for i in range(n):
if s > 9 * (n - i):
f = 1
break
b = max(0, s - 9 * (n - i - 1))
if i == 0 and i < n - 1:
b = max(1, b)
c.append(str(b))
s -= b
if t > 9:
d.append("9")
t -= 9
else:
d.append(str(t))
t = 0
if s < 0:
f = 1
break
if f == 0:
print("".join(c))
print("".join(d))
else:
print(-1, -1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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 = input().split()
m = int(m)
s = int(s)
if s > 9 * m:
print("-1 -1")
elif s < 1 and m > 1:
print("-1 -1")
elif s == 0 and m == 1:
print("0 0")
else:
a = s // 9
b = s % 9
max = ""
max += a * "9"
if a < m:
max += str(b)
while len(max) < m:
max += "0"
a = (s - 1) // 9
b = (s - 1) % 9
min = ""
min += a * "9"
min += str(b)
while len(min) < m:
min += "0"
min = list(str(int(min) + 1))
if s - 1 == 0:
min2 = max
else:
min2 = ""
for i in range(m):
min2 += min[m - i - 1]
print(min2, max) | 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 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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING VAR BIN_OP VAR STRING IF VAR VAR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING VAR BIN_OP VAR STRING VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP 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 | m, s = map(int, input().split())
a = [0] * m
a[0] = 1
sum = 1
if s == 0 and m == 1:
print(0, 0)
elif s - sum < 0:
print("-1 -1")
elif s - sum == 0:
for _ in range(len(a)):
print(a[_], end="")
print(" ", end="")
for _ in range(len(a)):
print(a[_], end="")
else:
k = (s - sum) // 9
j = (s - sum) % 9
if k >= m:
print("-1 -1")
else:
for _ in range(k):
a[len(a) - _ - 1] = 9
a[len(a) - k - 1] += j
b = [0] * m
b[0] = 1
sum = 1
if 9 < s:
b[0] = 9
k = (s - 9) // 9
j = (s - 9) % 9
if k > m - 1:
print("-1 -1")
elif k == m - 1:
for _ in range(len(a)):
print(a[_], end="")
print(" ", end="")
for _ in range(len(a)):
print(a[_], end="")
else:
for _ in range(k):
b[_ + 1] = 9
b[1 + k] += j
for _ in range(len(a)):
print(a[_], end="")
print(" ", end="")
for _ in range(len(b)):
print(b[_], end="")
elif 9 == s:
for _ in range(len(a)):
print(a[_], end="")
print(" ", end="")
print("9" + "0" * (m - 1))
else:
b[0] = s
for _ in range(len(a)):
print(a[_], end="")
print(" ", end="")
for _ in range(len(b)):
print(b[_], end="") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER IF NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING IF NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL 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 | m, s = map(int, input().split())
if s == 0 and m >= 2 or s > 9 * m:
print("-1 -1")
elif s == 0 and m == 1:
print("0 0")
else:
tmp1 = s
tmp2 = s
flag1 = 0
flag2 = 0
for i in range(m):
if i == 0:
if (m - i) * 9 >= tmp1:
if (m - i - 1) * 9 < tmp1 - 1:
print(tmp1 - (m - i - 1) * 9, end="")
flag1 = 1
else:
tmp1 -= 1
print(1, end="")
elif flag1 == 1:
print(9, end="")
elif (m - i) * 9 >= tmp1:
if (m - i - 1) * 9 < tmp1:
print(tmp1 - (m - i - 1) * 9, end="")
flag1 = 1
else:
print(0, end="")
print("", end=" ")
for i in range(m):
if tmp2 >= 9:
print(9, end="")
tmp2 -= 9
else:
print(tmp2, end="")
tmp2 -= tmp2 | 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 STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | import sys
s = list(map(int, input().split()))
n = s[0]
m = s[1]
if (n == 1) & (m == 0):
print("0 0")
sys.exit()
if (m == 0) | (m > 9 * n):
print("-1 -1")
sys.exit()
r = m - 1
d = 0
st1 = ""
d0 = 0
while d < n:
d = d + 1
d0 = min(r, 9)
r = r - d0
if d < n:
st1 = str(d0) + st1
else:
st1 = str(d0 + 1) + st1
r = m
d = 0
st2 = ""
d0 = 0
while d < n:
d = d + 1
d0 = min(r, 9)
r = r - d0
if d < n:
st2 = st2 + str(d0)
else:
st2 = st2 + str(d0)
print(st1 + " " + st2) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL 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 | m, s = map(int, input().split())
if s == 0 and m > 1 or m * 9 < s:
print("-1 -1")
exit()
def find_max(m, s):
ans = [0] * m
i = 0
while s > 9:
ans[i] = 9
s -= 9
i += 1
if i == m and s > 0:
print("-1 -1")
exit()
ans[i] += s
ans_1 = "".join([str(x) for x in ans])
return ans_1
def find_min(m, s):
ans = [1] + [0] * (m - 1)
i = m - 1
s -= 1
while s > 9:
ans[i] = 9
s -= 9
i -= 1
if i == 0 and s > 8:
print("-1 -1")
exit()
ans[i] += s
ans_2 = "".join([str(x) for x in ans])
return ans_2
print(find_min(m, s), find_max(m, s)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR RETURN 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 | l, s = map(int, input().split())
ma = ""
k = 0
for i in range(l):
if k + 9 <= s:
ma += "9"
elif k < s:
ma += str(s - k)
else:
ma += "0"
k = sum([int(i) for i in ma])
mi = ""
k = 0
for i in range(l):
if k + 10 <= s:
mi += "9"
elif k + 1 < s:
mi += str(s - k - 1) if i != l - 1 else str(s - k)
else:
mi += "0" if i != l - 1 else "1"
k = sum([int(i) for i in mi])
if l * 9 < s:
print(-1, -1)
elif s != 0:
print(mi[::-1], ma)
elif l == 1 and s == 0:
print(0, 0)
else:
print(-1, -1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR STRING IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | a, b = map(int, input().split())
c = [0] * a
n = [0] * a
n[0] = 1
c[0] = 1
e = 0
f = a - 1
while 1:
d = 0
for i in range(len(n)):
d += n[i]
if d == b:
break
n[f] += 1
if n[f] == 9:
f -= 1
if f == -1:
break
while 1:
d = 0
for i in range(len(c)):
d += c[i]
if d == b:
l = 1
break
c[e] += 1
if c[e] == 9:
e += 1
if e == a:
break
if b / a == 9:
s = "9" * a
print(s, s)
elif a == 1 and b == 0:
print("0 0")
elif b > a * 9 or b == 0:
print("-1 -1")
else:
print(*n, " ", *c, sep="") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if m * 9 < s:
print("-1 -1")
exit()
if s == 0 and m != 1:
print("-1 -1")
exit()
k = s
max = []
for i in range(m):
if s < 10:
max.append(s)
s = 0
else:
max.append(9)
s -= 9
min = []
for i in range(m):
if m == 1:
min.append(k)
break
if 9 * (m - i - 1) < k:
temp = 9 * (m - i - 1)
min.append(k - temp)
k = temp
elif i == 0:
min.append(1)
k -= 1
else:
min.append(0)
print("".join(map(str, min)), end=" ")
print("".join(map(str, max))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR STRING 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 | def min_and_max(m, s):
if s == 0:
if m == 1:
return 0, 0
return -1, -1
max_num = 0
s_max = s
for i in range(m):
if s_max >= 9:
max_num = max_num * 10 + 9
s_max -= 9
else:
max_num = max_num * 10 + s_max
s_max = 0
if s_max != 0:
return -1, -1
def reverse(n):
ans = 0
while n > 0:
ans = ans * 10 + n % 10
n = n // 10
return ans
if max_num % 10 != 0:
min_num = reverse(max_num)
else:
order = 10
while max_num % (order * 10) == 0:
order *= 10
if order < max_num:
min_num = reverse(max_num - order + 1)
else:
min_num = max_num
return min_num, max_num
m, s = map(int, input().strip().split())
print(*min_and_max(m, s)) | FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER NUMBER RETURN NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 | m, s = [int(x) for x in input().split()]
if s == 0 and m > 1 or s > 9 * m:
print("-1 -1")
exit(0)
elif m == 1:
mi = ma = s
elif s % 9 == 0:
if m == s // 9:
mi = ma = "9" * m
else:
mi = "1" + "0" * max(0, m - s // 9 - 1) + "8" + "9" * (s // 9 - 1)
ma = "9" * (s // 9) + "0" * max(0, m - s // 9)
elif s % 9 == 1:
mi = "1" + "0" * max(0, m - s // 9 - 1) + "9" * (s // 9)
ma = "9" * (s // 9) + "1" + "0" * max(0, m - s // 9 - 1)
elif m - s // 9 - 1 > 0:
p = str(s % 9 - 1)
q = str(s % 9)
mi = "1" + "0" * max(0, m - s // 9 - 2) + p + "9" * (s // 9)
ma = "9" * (s // 9) + q + "0" * max(0, m - s // 9 - 1)
else:
t = str(s % 9)
mi = t + "9" * (s // 9)
ma = "9" * (s // 9) + t
print(mi, ma) | 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 NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER STRING BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER STRING BIN_OP STRING FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER VAR BIN_OP STRING FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, m = [int(i) for i in input().split()]
m2 = m
if n == 1 and m == 0:
print(0, 0)
elif m == 0 or n * 9 < m:
print(-1, -1)
else:
max = 0
for i in range(n):
if m >= 9:
max = max * 10 + 9
m = m - 9
else:
max = max * 10 + m
m = 0
min = 0
for i in range(n):
if m2 > 9:
min = min + 10**i * 9
m2 = m2 - 9
else:
if m2 > 1:
min = min + 10**i * (m2 - 1)
m2 = 1
if m2 == 1 and i == n - 1:
min = min + 10**i * 1
print(min, max) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP 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 | import sys
import time
def read_line(cast=None):
if cast is not None:
return cast(input().strip())
else:
return input().strip()
def read_list(cast=int):
return list(map(cast, read_line().split()))
def solve(m, s):
if s == 0 and m == 1:
print("0 0")
return
if s == 0 and m > 1:
print("-1 -1")
return
mem_s = s
r = [0] * m
r[0] = 1
s -= 1
if s == 0:
t = "".join(map(str, r))
print(t + " " + t)
return
i = 0
while i < m and s > 0:
ov = r[m - 1 - i]
r[m - 1 - i] += min(9 - ov, s)
s -= r[m - 1 - i] - ov
i += 1
if s > 0:
print("-1 -1")
return
t = "".join(map(str, r))
s = mem_s
r = [0] * m
i = 0
while i < m and s > 0:
ov = r[i]
r[i] += min(9 - ov, s)
s -= r[i] - ov
i += 1
if s > 0:
print("-1 -1")
return
t2 = "".join(map(str, r))
print(t + " " + t2)
return
m, s = read_list()
solve(m, s) | IMPORT IMPORT FUNC_DEF NONE IF VAR NONE RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR RETURN ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR RETURN ASSIGN VAR VAR FUNC_CALL 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 | b = list(map(int, input().split(" ")))
le = b[0]
su = b[1]
sol = list()
if le == 1 and su == 0:
print("0 0")
elif 9 * le >= su and su > 0:
for a in range(le):
if su - 9 > 0:
sol.append("9")
su -= 9
else:
sol.append("{}".format(su))
su -= su
su = b[1]
sol2 = list()
for a in range(le):
sol2.append(
"{}".format(su - 9 * (le - a - 1)) if 9 * (le - a - 1) < su else "0"
)
if a == 0 and sol2[a] == "0":
sol2[a] = "1"
su -= int(sol2[a])
print("".join(sol2), "".join(sol))
else:
print("-1 -1") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL STRING BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER STRING IF VAR NUMBER VAR VAR STRING ASSIGN VAR VAR STRING VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n = input().split()
m, s = int(n[0]), int(n[1])
k = 0
o = 0
if s < 1 and m != 1 or s > 9 * m:
print("-1 -1")
else:
for i in range(1, m + 1):
if s >= 9:
k += 9 * 10 ** (m - i)
s -= 9
else:
k += s * 10 ** (m - i)
s = 0
s = int(n[1])
for i in range(m):
if s > 9:
o += 9 * 10**i
s -= 9
else:
o += 10 ** (m - 1) + (s - 1) * 10**i
break
print(o, k) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER 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 | i = 0
m, s = map(int, input().split())
k = s
if s == 0 and m == 1:
print(0, 0)
elif s == 0 or m * 9 < s:
print(-1, -1)
elif s == 1:
x = "1" + (m - 1) * "0"
print(x, x)
else:
s = k
ans = 0
i = 0
while i < m:
if s >= 9:
ans += 9
ans *= 10
else:
ans += s
ans *= 10
s = max(s - 9, 0)
i += 1
ans //= 10
a, b = -1, m
for i in range(len(str(ans)) - 1):
if str(ans)[i + 1] == "0":
a = i
break
g = ""
if a != -1:
g = str(ans)[a - 1 :: -1]
if a != 0:
g = str(ans)[a:b] + g
else:
g = str(ans)[::-1]
g = list(map(int, list(g)))
for i in range(m - 1):
if g[i] > 0 and not (g[i] == 1 and g[i + 1] == 0):
if g[i] + g[i + 1] > 9:
g[i] -= 9 - g[i + 1]
g[i + 1] = 9
else:
g[i + 1] += g[i]
g[i] = 0
if g[0] == 0:
for i in range(m):
if g[i] > 0:
g[i] -= 1
g[0] = 1
break
k = ""
for i in g:
k += str(i)
k = int(k)
print(k, ans) | ASSIGN VAR NUMBER 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 BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.